PageRenderTime 164ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/wp-content/plugins/nextgen-gallery/lib/media-rss.php

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