nggMediaRss

Class to produce Media RSS nodes.

Defined (1)

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

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