nggSitemaps

Main PHP Class for XML Image Sitemaps.

Defined (1)

The class is defined in the following location(s).

/lib/sitemap.php  
  1. class nggSitemaps { 
  2.  
  3. var $images = array(); 
  4.  
  5. /** 
  6. * nggSitemaps::__construct() 
  7. * @return 
  8. */ 
  9. function __construct() { 
  10.  
  11. add_filter('wpseo_sitemap_urlimages', array( &$this, 'add_wpseo_xml_sitemap_images'), 10, 2); 
  12.  
  13.  
  14. /** 
  15. * Filter support for WordPress SEO by Yoast 0.4.0 or higher ( http://wordpress.org/extend/plugins/wordpress-seo/ ) 
  16. * @since Version 1.8.0 
  17. * @param array $images 
  18. * @param int $post ID 
  19. * @return array $image list of all founded images 
  20. */ 
  21. function add_wpseo_xml_sitemap_images( $images, $post_id ) { 
  22.  
  23. $this->images = $images; 
  24.  
  25. // first get the content of the post/page 
  26. $p = get_post($post_id); 
  27.  
  28. // Backward check for older images 
  29. $p->post_content = NextGEN_Shortcodes::convert_shortcode($p->post_content); 
  30.  
  31. // Don't process the images in the normal way 
  32. remove_all_shortcodes(); 
  33.  
  34. // We cannot parse at this point a album, just galleries & single images 
  35. add_shortcode( 'singlepic', array(&$this, 'add_images' ) ); 
  36. add_shortcode( 'thumb', array(&$this, 'add_images' ) ); 
  37. add_shortcode( 'nggallery', array(&$this, 'add_gallery') ); 
  38. add_shortcode( 'imagebrowser', array(&$this, 'add_gallery' ) ); 
  39. add_shortcode( 'slideshow', array(&$this, 'add_gallery' ) ); 
  40.  
  41. // Search now for shortcodes 
  42. do_shortcode( $p->post_content ); 
  43.  
  44. return $this->images; 
  45.  
  46. /** 
  47. * Parse the gallery/imagebrowser/slideshow shortcode and return all images into an array 
  48. * @param string $atts 
  49. * @return 
  50. */ 
  51. function add_gallery( $atts ) { 
  52.  
  53. global $wpdb, $nggdb; 
  54.  
  55. extract(shortcode_atts(array( 
  56. 'id' => 0 
  57. ), $atts )); 
  58.  
  59. // backward compat for user which uses the name instead, still deprecated 
  60. if( !is_numeric($id) ) 
  61. $id = $wpdb->get_var( $wpdb->prepare ("SELECT gid FROM $wpdb->nggallery WHERE name = '%s' ", $id) ); 
  62.  
  63. //20140106:shouldn't call it statically when is not... 
  64. //$images = nggdb::get_gallery($id, 'pid', 'ASC', true, 1000); 
  65. $images = $nggdb->get_gallery($id, 'pid', 'ASC', true, 1000); 
  66.  
  67. foreach ($images as $image) { 
  68. $newimage = array(); 
  69. $newimage['src'] = $newimage['sc'] = $image->imageURL; 
  70. if ( !empty($image->title) ) 
  71. $newimage['title'] = $image->title; 
  72. if ( !empty($image->alttext) ) 
  73. $newimage['alt'] = $image->alttext; 
  74. $this->images[] = $newimage; 
  75.  
  76. return ''; 
  77.  
  78. /** 
  79. * Parse the single image shortcode and return all images into an array 
  80. * @param array $atts 
  81. * @return 
  82. */ 
  83. function add_images( $atts ) { 
  84.  
  85. extract(shortcode_atts(array( 
  86. 'id' => 0 
  87. ), $atts )); 
  88.  
  89. // make an array out of the ids (for thumbs shortcode)) 
  90. $pids = explode( ', ', $id ); 
  91.  
  92. // Some error checks 
  93. if ( count($pids) == 0 ) 
  94. return; 
  95.  
  96. $images = nggdb::find_images_in_list( $pids ); 
  97.  
  98. foreach ($images as $image) { 
  99. $newimage = array(); 
  100. $newimage['src'] = $newimage['sc'] = $image->imageURL; 
  101. if ( !empty($image->title) ) 
  102. $newimage['title'] = $image->title; 
  103. if ( !empty($image->alttext) ) 
  104. $newimage['alt'] = $image->alttext; 
  105. $this->images[] = $newimage; 
  106.  
  107. return ''; 
  108.