PageRenderTime 28ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/serendipity_plugin_syndication/serendipity_plugin_syndication.php

http://github.com/s9y/Serendipity
PHP | 246 lines | 217 code | 29 blank | 0 comment | 63 complexity | 7f5393f83482a6d1b4ce78b765658fb8 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, Apache-2.0
  1. <?php
  2. if (IN_serendipity !== true) {
  3. die ("Don't hack!");
  4. }
  5. class serendipity_plugin_syndication extends serendipity_plugin {
  6. var $title = SYNDICATION;
  7. function introspect(&$propbag)
  8. {
  9. $propbag->add('name', SYNDICATION);
  10. $propbag->add('description', SHOWS_RSS_BLAHBLAH);
  11. $propbag->add('stackable', true);
  12. $propbag->add('author', 'Serendipity Team');
  13. $propbag->add('version', '2.3.0');
  14. $propbag->add('configuration', array(
  15. 'title',
  16. 'big_img',
  17. 'feed_format',
  18. 'show_comment_feed',
  19. 'separator',
  20. 'iconURL',
  21. 'feed_name',
  22. 'comment_name',
  23. 'separator2',
  24. 'fb_id',
  25. 'custom_url'
  26. )
  27. );
  28. $propbag->add('groups', array('FRONTEND_VIEWS'));
  29. $propbag->add('legal', array(
  30. 'services' => array(
  31. 'feedburner.com' => array(
  32. 'url' => 'https://www.feedburner.com',
  33. 'desc' => 'Feedburner can be used to track your feed subscription statistics. If used, a tracking pixel is loaded from FeedBurner.com servers and the IP address of the visitor will be known to the service.'
  34. ),
  35. ),
  36. 'frontend' => array(
  37. 'To allow easy subscription to feeds and optional tracking statistics, the legacy feedburner services can be used.',
  38. ),
  39. 'backend' => array(
  40. ),
  41. 'cookies' => array(
  42. ),
  43. 'stores_user_input' => false,
  44. 'stores_ip' => false,
  45. 'uses_ip' => true,
  46. 'transmits_user_input' => true
  47. ));
  48. }
  49. function introspect_config_item($name, &$propbag)
  50. {
  51. global $serendipity;
  52. switch($name) {
  53. case 'title':
  54. $propbag->add('type', 'string');
  55. $propbag->add('name', TITLE);
  56. $propbag->add('description', TITLE_FOR_NUGGET);
  57. $propbag->add('default', SYNDICATE_THIS_BLOG);
  58. break;
  59. case 'feed_format':
  60. $propbag->add('type', 'radio');
  61. $propbag->add('name', SYNDICATION_PLUGIN_FEEDFORMAT);
  62. $propbag->add('description', SYNDICATION_PLUGIN_FEEDFORMAT_DESC);
  63. $propbag->add('default', 'rss');
  64. $propbag->add('radio', array(
  65. 'value' => array('rss', 'atom', 'rssatom'),
  66. 'desc' => array(SYNDICATION_PLUGIN_20, sprintf(SYNDICATION_PLUGIN_GENERIC_FEED, 'Atom 1.0'), SYNDICATION_PLUGIN_20 .' + '. sprintf(SYNDICATION_PLUGIN_GENERIC_FEED, 'Atom 1.0'))
  67. ));
  68. $propbag->add('radio_per_row', '3');
  69. break;
  70. case 'fb_id':
  71. $propbag->add('type', 'string');
  72. $propbag->add('name', SYNDICATION_PLUGIN_FEEDBURNERID);
  73. $propbag->add('description', SYNDICATION_PLUGIN_FEEDBURNERID_DESC);
  74. $propbag->add('default', '');
  75. break;
  76. case 'show_comment_feed':
  77. $propbag->add('type', 'boolean');
  78. $propbag->add('name', SYNDICATION_PLUGIN_COMMENTFEED);
  79. $propbag->add('description', SYNDICATION_PLUGIN_COMMENTFEED_DESC);
  80. $propbag->add('default', 'false');
  81. break;
  82. case 'separator':
  83. case 'separator2':
  84. $propbag->add('type', 'separator');
  85. break;
  86. case 'iconURL':
  87. $propbag->add('type', 'string');
  88. $propbag->add('name', XML_IMAGE_TO_DISPLAY);
  89. $propbag->add('description', SYNDICATION_PLUGIN_XML_DESC);
  90. $propbag->add('default', 'img/xml.gif');
  91. break;
  92. case 'big_img':
  93. $propbag->add('type', 'string');
  94. $propbag->add('name', SYNDICATION_PLUGIN_FEEDICON);
  95. $propbag->add('description', SYNDICATION_PLUGIN_FEEDICON_DESC);
  96. $propbag->add('default', 'img/subtome.png');
  97. break;
  98. case 'feed_name':
  99. $propbag->add('type', 'string');
  100. $propbag->add('name', SYNDICATION_PLUGIN_FEEDNAME);
  101. $propbag->add('description', SYNDICATION_PLUGIN_FEEDNAME_DESC);
  102. $propbag->add('default', '');
  103. break;
  104. case 'comment_name':
  105. $propbag->add('type', 'string');
  106. $propbag->add('name', SYNDICATION_PLUGIN_COMMENTNAME);
  107. $propbag->add('description', SYNDICATION_PLUGIN_COMMENTNAME_DESC);
  108. $propbag->add('default', '');
  109. break;
  110. case 'custom_url':
  111. $propbag->add('type', 'boolean');
  112. $propbag->add('name', SYNDICATION_PLUGIN_CUSTOMURL);
  113. $propbag->add('description', SYNDICATION_PLUGIN_CUSTOMURL_DESC);
  114. $propbag->add('default', '');
  115. break;
  116. default:
  117. return false;
  118. }
  119. return true;
  120. }
  121. function generate_content(&$title)
  122. {
  123. global $serendipity;
  124. $title = $this->get_config('title');
  125. $iconURL = $this->get_config('iconURL', 'img/xml.gif');
  126. if ($iconURL != 'none') {
  127. $small_icon = serendipity_getTemplateFile($iconURL);
  128. }
  129. $custom_feed = trim($this->get_config('feed_name'));
  130. $custom_comm = trim($this->get_config('comment_name'));
  131. $custom_img = trim($this->get_config('big_img', 'img/subtome.png'));
  132. if ($custom_img != 'none' && $custom_img != "feedburner") {
  133. $custom_img = serendipity_getTemplateFile($custom_img);
  134. }
  135. $fbid = $this->get_config('fb_id');
  136. $custom_url = serendipity_db_bool($this->get_config('custom_url', false));
  137. $feed_format = $this->get_config('feed_format', 'rss');
  138. $useRss = true;
  139. if ($feed_format == 'atom') {
  140. $useRss = false;
  141. $useAtom = true;
  142. } else if ($feed_format == 'rssatom') {
  143. $useAtom = true;
  144. }
  145. $img = 'http://feeds.feedburner.com/~fc/'.$this->get_config('fb_id').'?bg=99CCFF&amp;fg=444444&amp;anim=0';
  146. $icon = $small_icon;
  147. if (!empty($custom_img) && $custom_img != 'default' && $custom_img != 'none' && $custom_img != 'empty') {
  148. $icon = $custom_img;
  149. if ($fbid != "" && $custom_img == 'feedburner') {
  150. $icon = "http://feeds.feedburner.com/~fc/$fbid?bg=99CCFF&amp;fg=444444&amp;anim=0";
  151. }
  152. if ($fbid == "" && $custom_img == 'feedburner') {
  153. $icon = serendipity_getTemplateFile('img/subtome.png');
  154. }
  155. }
  156. if (empty($custom_feed) || $custom_feed == 'default' || $custom_feed == 'none' || $custom_feed == 'empty') {
  157. $FEED = 'Feed';
  158. } else {
  159. $FEED = $custom_feed;
  160. }
  161. if (empty($custom_comm) || $custom_comm == 'default' || $custom_comm == 'none' || $custom_comm == 'empty') {
  162. $COMMENTS = COMMENTS;
  163. } else {
  164. $COMMENTS = $custom_comm;
  165. }
  166. if ($custom_url) {
  167. $mainFeed = serendipity_get_config_var('feedCustom');
  168. } else {
  169. $mainFeed = serendipity_rewriteURL(PATH_FEEDS .'/index.rss2');
  170. if ($fbid != "") {
  171. $mainFeed ='http://feeds.feedburner.com/' . $fbid;
  172. } else {
  173. if ((isset($useAtom) && $useAtom) && ! $useRss) {
  174. $mainFeed = serendipity_rewriteURL(PATH_FEEDS .'/atom10.xml');
  175. }
  176. }
  177. }
  178. echo "\n".'<ul id="serendipity_syndication_list" class="plainList">';
  179. echo $this->generateFeedButton($mainFeed, ($icon == $small_icon ? ($useRss ? "RSS $FEED" : "Atom $FEED") : ""), $icon, $icon == $small_icon);
  180. if ($useRss && (isset($useAtom) && $useAtom)) {
  181. echo $this->generateFeedButton(serendipity_rewriteURL(PATH_FEEDS .'/atom10.xml'), "Atom $FEED", $small_icon);
  182. }
  183. if (serendipity_db_bool($this->get_config('show_2.0c', false)) || serendipity_db_bool($this->get_config('show_comment_feed', false))) {
  184. if ($useRss) {
  185. echo $this->generateFeedButton( serendipity_rewriteURL(PATH_FEEDS .'/comments.rss2'),
  186. $COMMENTS . ($useAtom ? " (RSS)": ""),
  187. $small_icon);
  188. }
  189. if ($useAtom) {
  190. echo $this->generateFeedButton( serendipity_rewriteURL(PATH_FEEDS .'/comments.atom10'),
  191. $COMMENTS . ($useRss ? " (Atom)": ""),
  192. $small_icon);
  193. }
  194. }
  195. echo "</ul>\n";
  196. }
  197. function generateFeedButton($feed, $label, $icon, $small = false)
  198. {
  199. $link = 'href="'.$feed.'" ';
  200. $output = '<li>';
  201. $class = "";
  202. if ($small) {
  203. $class .= " serendipity_xml_icon";
  204. }
  205. if ($icon) {
  206. $output .= '<a class="'. $class .'" ' . $link . '><img src="' . $icon . '" alt="XML" style="border: 0px" /></a>'."\n";
  207. }
  208. if (! empty($label)) {
  209. $output .= " <a $link>$label</a>\n";
  210. }
  211. return $output .= "</li>\n";
  212. }
  213. }
  214. ?>