/products/photocrati_nextgen/modules/ngglegacy/lib/sitemap.php

  1. <?php 
  2. /** 
  3. * Main PHP Class for XML Image Sitemaps 
  4. * 
  5. * @author Alex Rabe 
  6. * @version 1.0 
  7. * @copyright Copyright 2011 
  8. * 
  9. */ 
  10. class nggSitemaps { 
  11.  
  12. var $images = array(); 
  13.  
  14. /** 
  15. * nggSitemaps::__construct() 
  16. * 
  17. * @return 
  18. */ 
  19. function __construct() { 
  20.  
  21. add_filter('wpseo_sitemap_urlimages', array( &$this, 'add_wpseo_xml_sitemap_images'), 10, 2); 
  22.  
  23.  
  24. /** 
  25. * Filter support for WordPress SEO by Yoast 0.4.0 or higher ( http://wordpress.org/extend/plugins/wordpress-seo/ ) 
  26. * 
  27. * @since Version 1.8.0 
  28. * @param array $images 
  29. * @param int $post ID 
  30. * @return array $image list of all founded images 
  31. */ 
  32. function add_wpseo_xml_sitemap_images( $images, $post_id ) { 
  33.  
  34. $this->images = $images; 
  35.  
  36. // first get the content of the post/page 
  37. $p = get_post($post_id); 
  38.  
  39. // Backward check for older images 
  40. $p->post_content = NextGEN_Shortcodes::convert_shortcode($p->post_content); 
  41.  
  42. // Don't process the images in the normal way 
  43. remove_all_shortcodes(); 
  44.  
  45. // We cannot parse at this point a album, just galleries & single images 
  46. C_NextGen_Shortcode_Manager::add('singlepic', array(&$this, 'add_images')); 
  47. C_NextGen_Shortcode_Manager::add('thumb', array(&$this, 'add_images')); 
  48. C_NextGen_Shortcode_Manager::add('nggallery', array(&$this, 'add_gallery')); 
  49. C_NextGen_Shortcode_Manager::add('imagebrowser', array(&$this, 'add_gallery')); 
  50. C_NextGen_Shortcode_Manager::add('slideshow', array(&$this, 'add_gallery')); 
  51.  
  52. // Search now for shortcodes 
  53. do_shortcode( $p->post_content ); 
  54.  
  55. return $this->images; 
  56.  
  57. /** 
  58. * Parse the gallery/imagebrowser/slideshow shortcode and return all images into an array 
  59. * 
  60. * @param string $atts 
  61. * @return 
  62. */ 
  63. function add_gallery( $atts ) { 
  64.  
  65. global $wpdb; 
  66.  
  67. extract(shortcode_atts(array( 
  68. 'id' => 0 
  69. ), $atts )); 
  70.  
  71. $gallery_mapper = C_Gallery_Mapper::get_instance(); 
  72. if (!is_numeric($id)) { 
  73. if (($gallery = array_shift($gallery_mapper->select()->where(array('name = %s', $id))->limit(1)->run_query()))) { 
  74. $id = $gallery->{$gallery->id_field}; 
  75. else $id = NULL; 
  76.  
  77. if ($id) { 
  78. $gallery_storage = C_Gallery_Storage::get_instance(); 
  79. $image_mapper = C_Image_Mapper::get_instance(); 
  80. foreach ($image_mapper->find_all_for_gallery($id) as $image) { 
  81. $this->images[] = array( 
  82. 'src' => $gallery_storage->get_image_url($image),  
  83. 'title' => $image->title,  
  84. 'alt' => $image->alttext 
  85. ); 
  86.  
  87. return ''; 
  88.  
  89. /** 
  90. * Parse the single image shortcode and return all images into an array 
  91. * 
  92. * @param array $atts 
  93. * @return 
  94. */ 
  95. function add_images( $atts ) { 
  96.  
  97. extract(shortcode_atts(array( 
  98. 'id' => 0 
  99. ), $atts )); 
  100.  
  101. // make an array out of the ids (for thumbs shortcode)) 
  102. $pids = explode( ', ', $id ); 
  103.  
  104. // Some error checks 
  105. if ( count($pids) == 0 ) 
  106. return; 
  107.  
  108. $images = nggdb::find_images_in_list( $pids ); 
  109.  
  110. foreach ($images as $image) { 
  111. $newimage = array(); 
  112. $newimage['src'] = $newimage['sc'] = $image->imageURL; 
  113. if ( !empty($image->title) ) 
  114. $newimage['title'] = $image->title; 
  115. if ( !empty($image->alttext) ) 
  116. $newimage['alt'] = $image->alttext; 
  117. $this->images[] = $newimage; 
  118.  
  119. return ''; 
  120.  
  121. $nggSitemaps = new nggSitemaps(); 
.