nggMediaRss

Class to produce Media RSS nodes.

Defined (1)

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

/lib/media-rss.php  
  1. class nggMediaRss { 
  2.  
  3. /** 
  4. * Function called by the wp_head action to output the RSS link for medias 
  5. */ 
  6. static function add_mrss_alternate_link() { 
  7. echo "<link id='MediaRSS' rel='alternate' type='application/rss+xml' title='NextGEN Gallery RSS Feed' href='" . nggMediaRss::get_mrss_url() . "' />\n";  
  8.  
  9. /** 
  10. * Add the javascript required to enable PicLens/CoolIris support  
  11. */ 
  12. static function add_piclens_javascript() { 
  13. if (is_ssl()) 
  14. wp_enqueue_script( 'piclens', 'https://lite.piclens.com/current/piclens_optimized.js', array(), false, true); 
  15. else 
  16. wp_enqueue_script( 'piclens', 'http://lite.piclens.com/current/piclens_optimized.js', array(), false, true); 
  17.  
  18. /** 
  19. * Get the URL of the general media RSS 
  20. */ 
  21. static function get_mrss_url() { 
  22. return NGGALLERY_URLPATH . 'xml/media-rss.php'; 
  23.  
  24. /** 
  25. * Get the URL of a gallery media RSS 
  26. */ 
  27. static function get_gallery_mrss_url($gid, $prev_next = false) { 
  28. return nggMediaRss::get_mrss_url() . '?' . ('gid=' . $gid . ($prev_next ? '&prev_next=true' : '') . '&mode=gallery'); 
  29.  
  30. /** 
  31. * Get the URL of an album media RSS 
  32. */ 
  33. static function get_album_mrss_url($aid) { 
  34. return nggMediaRss::get_mrss_url() . '?' . ('aid=' . $aid . '&mode=album'); 
  35.  
  36. /** 
  37. * Get the URL of the media RSS for last pictures 
  38. */ 
  39. static function get_last_pictures_mrss_url($page = 0, $show = 30) { 
  40. return nggMediaRss::get_mrss_url() . '?' . ('show=' . $show . '&page=' . $page . '&mode=last_pictures'); 
  41.  
  42. /** 
  43. * Get the XML <rss> node corresponding to the last pictures registered 
  44. * @param page The current page (defaults to 0) 
  45. * @param show The number of pictures to include in one field (default 30)  
  46. */ 
  47. static function get_last_pictures_mrss($page = 0, $show = 30) { 
  48. $images = nggdb::find_last_images($page, $show); 
  49.  
  50. $title = stripslashes(get_option('blogname')); 
  51. $description = stripslashes(get_option('blogdescription')); 
  52. $link = site_url(); 
  53. $prev_link = ($page > 0) ? nggMediaRss::get_last_pictures_mrss_url($page-1, $show) : ''; 
  54. $next_link = count($images)!=0 ? nggMediaRss::get_last_pictures_mrss_url($page+1, $show) : ''; 
  55.  
  56. return nggMediaRss::get_mrss_root_node($title, $description, $link, $prev_link, $next_link, $images); 
  57.  
  58. /** 
  59. * Get the XML <rss> node corresponding to a gallery 
  60. * @param $gallery (object) The gallery to include in RSS 
  61. * @param $prev_gallery (object) The previous gallery to link in RSS (null if none) 
  62. * @param $next_gallery (object) The next gallery to link in RSS (null if none) 
  63. */ 
  64. static function get_gallery_mrss($gallery, $prev_gallery = null, $next_gallery = null) { 
  65. global $nggdb; 
  66.  
  67. $ngg_options = nggGallery::get_option('ngg_options'); 
  68. //Set sort order value, if not used (upgrade issue) 
  69. $ngg_options['galSort'] = ($ngg_options['galSort']) ? $ngg_options['galSort'] : 'pid'; 
  70. $ngg_options['galSortDir'] = ($ngg_options['galSortDir'] == 'DESC') ? 'DESC' : 'ASC'; 
  71.  
  72. $title = stripslashes(nggGallery::i18n($gallery->title)); 
  73. $description = stripslashes(nggGallery::i18n($gallery->galdesc)); 
  74. $link = nggMediaRss::get_permalink($gallery->pageid); 
  75. $prev_link = ( $prev_gallery != null) ? nggMediaRss::get_gallery_mrss_url($prev_gallery->gid, true) : ''; 
  76. $next_link = ( $next_gallery != null) ? nggMediaRss::get_gallery_mrss_url($next_gallery->gid, true) : ''; 
  77. //20140106:shouldn't call it statically when is not... 
  78. //$images = nggdb::get_gallery($gallery->gid, $ngg_options['galSort'], $ngg_options['galSortDir']); 
  79. $images = $nggdb->get_gallery($gallery->gid, $ngg_options['galSort'], $ngg_options['galSortDir']); 
  80.  
  81. return nggMediaRss::get_mrss_root_node($title, $description, $link, $prev_link, $next_link, $images); 
  82.  
  83. /** 
  84. * Get the XML <rss> node corresponding to an album 
  85. * @param $album The album to include in RSS 
  86. */ 
  87. static function get_album_mrss($album) { 
  88.  
  89. $title = stripslashes(nggGallery::i18n($album->name)); 
  90. $description = ''; 
  91. $link = nggMediaRss::get_permalink(0); 
  92. $prev_link = ''; 
  93. $next_link = ''; 
  94. $images = nggdb::find_images_in_album($album->id); 
  95.  
  96. return nggMediaRss::get_mrss_root_node($title, $description, $link, $prev_link, $next_link, $images); 
  97.  
  98. /** 
  99. * Get the XML <rss> node 
  100. */ 
  101. static function get_mrss_root_node($title, $description, $link, $prev_link, $next_link, $images) { 
  102.  
  103. if ($prev_link != '' || $next_link != '') 
  104. $out = "<rss version='2.0' xmlns:media='http://search.yahoo.com/mrss/' xmlns:atom='http://www.w3.org/2005/Atom'>\n" ; 
  105. else 
  106. $out = "<rss version='2.0' xmlns:media='http://search.yahoo.com/mrss/'>\n"; 
  107.  
  108. $out .= "\t<channel>\n"; 
  109.  
  110. $out .= nggMediaRss::get_generator_mrss_node(); 
  111. $out .= nggMediaRss::get_title_mrss_node($title); 
  112. $out .= nggMediaRss::get_description_mrss_node($description); 
  113. $out .= nggMediaRss::get_link_mrss_node($link); 
  114.  
  115. if ($prev_link != '' || $next_link != '') 
  116. $out .= nggMediaRss::get_self_node(nggMediaRss::get_mrss_url());  
  117. if ($prev_link!='') { 
  118. $out .= nggMediaRss::get_previous_link_mrss_node($prev_link); 
  119. if ($next_link!='') {  
  120. $out .= nggMediaRss::get_next_link_mrss_node($next_link); 
  121. }  
  122.  
  123. foreach ($images as $image) { 
  124. $out .= nggMediaRss::get_image_mrss_node($image); 
  125.  
  126. $out .= "\t</channel>\n"; 
  127. $out .= "</rss>\n"; 
  128.  
  129. return $out; 
  130. }  
  131.  
  132. /** 
  133. * Get the XML <generator> node 
  134. */ 
  135. static function get_generator_mrss_node($indent = "\t\t") { 
  136. return $indent . "<generator><![CDATA[NextGEN Gallery [http://nextgen-gallery.com]]]></generator>\n"; 
  137. }  
  138.  
  139. /** 
  140. * Get the XML <title> node 
  141. */ 
  142. static function get_title_mrss_node($title, $indent = "\t\t") { 
  143. return $indent . "<title>" . $title . "</title>\n"; 
  144. }  
  145.  
  146. /** 
  147. * Get the XML <description> node 
  148. */ 
  149. static function get_description_mrss_node($description, $indent = "\t\t") { 
  150. return $indent . "<description>" . $description . "</description>\n"; 
  151. }  
  152.  
  153. /** 
  154. * Get the XML <link> node 
  155. */ 
  156. static function get_link_mrss_node($link, $indent = "\t\t") { 
  157. return $indent . "<link><![CDATA[" . htmlspecialchars($link) . "]]></link>\n"; 
  158. }  
  159.  
  160. /** 
  161. * Get the XML <atom:link self> node 
  162. */ 
  163. static function get_self_node($link, $indent = "\t\t") { 
  164. return $indent . "<atom:link rel='self' href='" . htmlspecialchars($link) . "' type='application/rss+xml' />\n"; 
  165.  
  166. /** 
  167. * Get the XML <atom:link previous> node 
  168. */ 
  169. static function get_previous_link_mrss_node($link, $indent = "\t\t") { 
  170. return $indent . "<atom:link rel='previous' href='" . htmlspecialchars($link) . "' />\n"; 
  171. }  
  172.  
  173. /** 
  174. * Get the XML <atom:link next> node 
  175. */ 
  176. static function get_next_link_mrss_node($link, $indent = "\t\t") { 
  177. return $indent . "<atom:link rel='next' href='" . htmlspecialchars($link) . "' />\n"; 
  178. }  
  179.  
  180. /** 
  181. * Get the XML <item> node corresponding to one single image 
  182. * @param $image The image object 
  183. */ 
  184. static function get_image_mrss_node($image, $indent = "\t\t" ) { 
  185. $ngg_options = nggGallery::get_option('ngg_options'); 
  186.  
  187. $tags = $image->get_tags(); 
  188. $tag_names = ''; 
  189. foreach ($tags as $tag) { 
  190. $tag_names .= ($tag_names=='' ? $tag->name : ', ' . $tag->name); 
  191.  
  192. $title = html_entity_decode(stripslashes($image->alttext)); 
  193. $desc = html_entity_decode(stripslashes($image->description)); 
  194.  
  195. $thumbwidth = $ngg_options['thumbwidth']; 
  196. $thumbheight = ($ngg_options['thumbfix'] ? $ngg_options['thumbheight'] : $thumbwidth);  
  197.  
  198. $out = $indent . "<item>\n"; 
  199. $out .= $indent . "\t<title><![CDATA[" . nggGallery::i18n($title, 'pic_' . $image->pid . '_alttext') . "]]></title>\n"; 
  200. $out .= $indent . "\t<description><![CDATA[" . nggGallery::i18n($desc, 'pic_' . $image->pid . '_description') . "]]></description>\n"; 
  201. $out .= $indent . "\t<link><![CDATA[" . $image->get_permalink() . "]]></link>\n"; 
  202. $out .= $indent . "\t<guid>image-id:" . $image->pid . "</guid>\n"; 
  203. $out .= $indent . "\t<media:content url='" . esc_url($image->imageURL) . "' medium='image' />\n"; 
  204. $out .= $indent . "\t<media:title><![CDATA[" . nggGallery::i18n($title, 'pic_' . $image->pid . '_alttext') . "]]></media:title>\n"; 
  205. $out .= $indent . "\t<media:description><![CDATA[" . nggGallery::i18n($desc, 'pic_' . $image->pid . '_description') . "]]></media:description>\n"; 
  206. $out .= $indent . "\t<media:thumbnail url='" . esc_url($image->thumbURL) . "' width='" . $thumbwidth . "' height='" . $thumbheight . "' />\n"; 
  207. $out .= $indent . "\t<media:keywords><![CDATA[" . nggGallery::i18n($tag_names) . "]]></media:keywords>\n"; 
  208. $out .= $indent . "\t<media:copyright><![CDATA[Copyright (c) " . get_option("blogname") . " (" . site_url() . ")]]></media:copyright>\n"; 
  209. $out .= $indent . "</item>\n"; 
  210.  
  211. return $out; 
  212.  
  213. static function get_permalink($page_id) { 
  214. if ($page_id == 0)  
  215. $permalink = site_url();  
  216. else  
  217. $permalink = get_permalink($page_id); 
  218.  
  219. return $permalink;  
  220. }  
  221.