PageRenderTime 53ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/simple-forum/feeds/sf-feeds.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 330 lines | 258 code | 47 blank | 25 comment | 46 complexity | 4920e0b904ee915eaabdd3d0a87a563e MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. /*
  3. Simple:Press
  4. Forum RSS Feeds
  5. $LastChangedDate: 2010-10-23 11:06:35 -0700 (Sat, 23 Oct 2010) $
  6. $Rev: 4806 $
  7. */
  8. if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
  9. die('Access Denied');
  10. }
  11. sf_setup_RSS_includes();
  12. global $wpdb, $current_user;
  13. # check installed version is correct
  14. if(sfg_get_system_status() != 'ok')
  15. {
  16. $out.= '<img style="vertical-align:middle" src="'.SFRESOURCES.'information.png" alt="" />'."\n";
  17. $out.= '&nbsp;&nbsp;'.__("The forum is temporarily unavailable while being upgraded to a new version", "sforum");
  18. echo $out;
  19. return;
  20. }
  21. $rssopt = sf_get_option('sfrss');
  22. $limit = $rssopt['sfrsscount'];
  23. if(!isset($limit)) $limit = 15;
  24. $feed = $_GET['xfeed'];
  25. # are we doing feed keys?
  26. if ($rssopt['sfrssfeedkey'])
  27. {
  28. # get the user requesting feed
  29. $feedkey = sf_esc_str($_GET['feedkey']);
  30. $userid = $wpdb->get_var("SELECT user_id FROM ".SFMEMBERS." WHERE feedkey='".$feedkey."'");
  31. # get user permissions
  32. wp_set_current_user($userid);
  33. }
  34. # is it a search feed?
  35. $match = '';
  36. if (isset($_GET['search']))
  37. {
  38. $search = $_GET['search'];
  39. $match = "(MATCH(".SFPOSTS.".post_content) AGAINST ('".esc_sql(like_escape($search))."' IN BOOLEAN MODE) OR MATCH(".SFTOPICS.".topic_name) AGAINST ('".esc_sql(like_escape($search))."' IN BOOLEAN MODE)) AND ";
  40. }
  41. # get the requested feed type
  42. switch($feed)
  43. {
  44. case 'group':
  45. sf_initialise_globals();
  46. # Get Data
  47. if(isset($_GET['group']))
  48. {
  49. $groupid = sf_esc_int($_GET['group']);
  50. if(sf_group_exists($groupid))
  51. {
  52. $posts = $wpdb->get_results(
  53. "SELECT ".SFPOSTS.".post_id, ".SFPOSTS.".topic_id, ".SFPOSTS.".forum_id, post_content, ".sf_zone_datetime('post_date').", ".SFPOSTS.".user_id,
  54. guest_name, display_name, group_id
  55. FROM (".SFPOSTS." LEFT JOIN ".SFMEMBERS." ON ".SFPOSTS.".user_id = ".SFMEMBERS.".user_id)
  56. JOIN ".SFFORUMS." ON ".SFPOSTS.".forum_id = ".SFFORUMS.".forum_id
  57. JOIN ".SFTOPICS." ON ".SFTOPICS.".topic_id = ".SFPOSTS.".topic_id
  58. WHERE ".$match.SFFORUMS.".group_id=".$groupid." AND ".SFFORUMS.".forum_rss_private = 0 AND ".SFPOSTS.".post_status = 0
  59. ORDER BY post_date DESC
  60. LIMIT 0, ".$limit.";");
  61. # Define Channel Elements
  62. $grouprec = sf_get_group_record($groupid);
  63. $rssTitle=get_bloginfo('name').' - '.__("Group", "sforum").': '.sf_filter_title_display($grouprec->group_name);
  64. $rssLink=sf_build_qurl('group='.$groupid);
  65. if ($rssopt['sfrssfeedkey'] && isset($sfglobals['member']['feedkey']))
  66. $atomLink=sf_build_qurl('group='.$groupid, 'xfeed=group', 'feedkey='.$sfglobals['member']['feedkey']);
  67. else
  68. $atomLink=sf_build_qurl('group='.$groupid, 'xfeed=group');
  69. $rssDescription=get_bloginfo('description');
  70. $rssGenerator=__('Simple:Press Version ', "sforum").SFVERSION;
  71. $rssItem=array();
  72. if($posts)
  73. {
  74. foreach($posts as $post)
  75. {
  76. $thisforum = sf_get_forum_record($post->forum_id);
  77. if ($post->topic_id && $thisforum && (sf_can_view_forum($post->forum_id) || !$rssopt['sfrssfeedkey']))
  78. {
  79. # Define Item Elements
  80. $item = new stdClass;
  81. $poster = sf_filter_name_display($post->display_name);
  82. if(empty($poster)) $poster = sf_filter_name_display($post->guest_name);
  83. $topic=sf_get_topic_record($post->topic_id);
  84. $item->title=$poster.' '.__('on', "sforum").' '.sf_filter_title_display($topic->topic_name);
  85. $item->link=sf_build_url($thisforum->forum_slug, $topic->topic_slug, 0, $post->post_id);
  86. $item->pubDate=mysql2date('r', $post->post_date);
  87. $item->category=sf_filter_title_display($thisforum->forum_name);
  88. $text=sf_filter_rss_display($post->post_content);
  89. $item->description=sf_rss_excerpt($text);
  90. $item->guid=sf_build_url($thisforum->forum_slug, $topic->topic_slug, 0, $post->post_id);
  91. $rssItem[]=$item;
  92. }
  93. }
  94. }
  95. }
  96. }
  97. break;
  98. case 'topic':
  99. # Get Data
  100. if(isset($_GET['topic']))
  101. {
  102. $topicid = sf_get_topic_id(sf_esc_str($_GET['topic']));
  103. if($topicid)
  104. {
  105. $topic=sf_get_topic_record($topicid);
  106. sf_initialise_globals($topic->forum_id);
  107. $posts = $wpdb->get_results(
  108. "SELECT ".SFPOSTS.".post_id, post_content, ".sf_zone_datetime('post_date').", ".SFPOSTS.".user_id, guest_name, display_name, ".SFPOSTS.".forum_id
  109. FROM (".SFPOSTS." LEFT JOIN ".SFMEMBERS." ON ".SFPOSTS.".user_id = ".SFMEMBERS.".user_id)
  110. JOIN ".SFFORUMS." ON ".SFPOSTS.".forum_id = ".SFFORUMS.".forum_id
  111. JOIN ".SFTOPICS." ON ".SFTOPICS.".topic_id = ".SFPOSTS.".topic_id
  112. WHERE ".$match.SFPOSTS.".topic_id = ".$topicid." AND ".SFPOSTS.".post_status = 0 AND ".SFFORUMS.".forum_rss_private = 0
  113. ORDER BY post_date DESC
  114. LIMIT 0, ".$limit);
  115. $forumslug = sf_esc_str($_GET['forum']);
  116. # Define Channel Elements
  117. $rssTitle=get_bloginfo('name').' - '.__("Topic", "sforum").': '.sf_filter_title_display($topic->topic_name);
  118. $rssLink=sf_build_url($forumslug, $topic->topic_slug, 0, 0);
  119. if ($rssopt['sfrssfeedkey'] && isset($sfglobals['member']['feedkey']))
  120. $atomLink=sf_build_qurl($forumslug, $topic->topic_slug, 'xfeed=topic', 'feedkey='.$sfglobals['member']['feedkey']);
  121. else
  122. $atomLink=sf_build_qurl($forumslug, $topic->topic_slug, 'xfeed=topic');
  123. $rssDescription=get_bloginfo('description');
  124. $rssGenerator=__('Simple:Press Version ', "sforum").SFVERSION;
  125. $rssItem=array();
  126. if($posts)
  127. {
  128. foreach($posts as $post)
  129. {
  130. if($post->post_id && (sf_can_view_forum($post->forum_id) || !$rssopt['sfrssfeedkey']))
  131. {
  132. # Define Item Elements
  133. $item = new stdClass;
  134. $poster = sf_filter_name_display($post->display_name);
  135. if(empty($poster)) $poster = sf_filter_name_display($post->guest_name);
  136. $item->title=$poster.' '.__('on', "sforum").' '.sf_filter_title_display($topic->topic_name);
  137. $item->link=sf_build_url($forumslug, $topic->topic_slug, 0, $post->post_id);
  138. $item->pubDate=mysql2date('r', $post->post_date);
  139. $item->category=sf_get_forum_name($forumslug);
  140. $text=sf_filter_rss_display($post->post_content);
  141. $item->description=sf_rss_excerpt($text);
  142. $item->guid=sf_build_url($forumslug, $topic->topic_slug, 0, $post->post_id);
  143. $rssItem[]=$item;
  144. }
  145. }
  146. }
  147. }
  148. }
  149. break;
  150. case 'forum':
  151. # Get Data
  152. if(isset($_GET['forum']))
  153. {
  154. $forumid = sf_get_forum_id(sf_esc_str($_GET['forum']));
  155. if($forumid)
  156. {
  157. sf_initialise_globals($forumid);
  158. $forum=sf_get_forum_record($forumid);
  159. if($forum == '') exit();
  160. $posts = $wpdb->get_results(
  161. "SELECT ".SFPOSTS.".post_id, ".SFPOSTS.".topic_id, ".SFPOSTS.".forum_id, post_content, ".sf_zone_datetime('post_date').", ".SFPOSTS.".user_id, guest_name, display_name, ".SFPOSTS.".forum_id
  162. FROM (".SFPOSTS." LEFT JOIN ".SFMEMBERS." ON ".SFPOSTS.".user_id = ".SFMEMBERS.".user_id)
  163. JOIN ".SFFORUMS." ON ".SFPOSTS.".forum_id = ".SFFORUMS.".forum_id
  164. JOIN ".SFTOPICS." ON ".SFTOPICS.".topic_id = ".SFPOSTS.".topic_id
  165. WHERE ".$match.SFPOSTS.".forum_id = ".$forumid." AND ".SFPOSTS.".post_status = 0 AND ".SFFORUMS.".forum_rss_private = 0
  166. ORDER BY post_date DESC
  167. LIMIT 0, ".$limit);
  168. # Define Channel Elements
  169. $rssTitle=get_bloginfo('name').' - '.__("Forum", "sforum").': '.sf_filter_title_display($forum->forum_name);
  170. $rssLink=sf_build_url($forum->forum_slug, '', 0, 0);
  171. if ($rssopt['sfrssfeedkey'] && isset($sfglobals['member']['feedkey']))
  172. $atomLink=sf_build_qurl($forum->forum_slug, 'xfeed=forum', 'feedkey='.$sfglobals['member']['feedkey']);
  173. else
  174. $atomLink=sf_build_qurl($forum->forum_slug, 'xfeed=forum');
  175. $rssDescription=get_bloginfo('description');
  176. $rssGenerator=__('Simple:Press Version ', "sforum").SFVERSION;
  177. $rssItem=array();
  178. if($posts)
  179. {
  180. foreach($posts as $post)
  181. {
  182. # Define Item Elements
  183. if($post->topic_id && (sf_can_view_forum($post->forum_id) || !$rssopt['sfrssfeedkey']))
  184. {
  185. $item = new stdClass;
  186. $poster = sf_filter_name_display($post->display_name);
  187. if(empty($poster)) $poster = sf_filter_name_display($post->guest_name);
  188. $topic=sf_get_topic_record($post->topic_id);
  189. $item->title=$poster.' '.__('on', "sforum").' '.sf_filter_title_display($topic->topic_name);
  190. $item->link=sf_build_url($forum->forum_slug, $topic->topic_slug, 0, $post->post_id);
  191. $item->pubDate=mysql2date('r', $post->post_date);
  192. $item->category=sf_get_forum_name($forum->forum_slug);
  193. $text=sf_filter_rss_display($post->post_content);
  194. $item->description=sf_rss_excerpt($text);
  195. $item->guid=sf_build_url($forum->forum_slug, $topic->topic_slug, 0, $post->post_id);
  196. $rssItem[]=$item;
  197. }
  198. }
  199. }
  200. }
  201. }
  202. break;
  203. case 'all':
  204. sf_initialise_globals();
  205. # Get Data
  206. $posts = $wpdb->get_results(
  207. "SELECT ".SFPOSTS.".post_id, ".SFPOSTS.".topic_id, ".SFPOSTS.".forum_id, post_content, post_date, ".SFPOSTS.".user_id, guest_name, display_name
  208. FROM (".SFPOSTS." LEFT JOIN ".SFMEMBERS." ON ".SFPOSTS.".user_id = ".SFMEMBERS.".user_id)
  209. JOIN ".SFFORUMS." ON ".SFPOSTS.".forum_id = ".SFFORUMS.".forum_id
  210. JOIN ".SFTOPICS." ON ".SFTOPICS.".topic_id = ".SFPOSTS.".topic_id
  211. WHERE ".$match.SFPOSTS.".post_status = 0 AND ".SFFORUMS.".forum_rss_private = 0
  212. ORDER BY post_date DESC
  213. LIMIT 0, ".$limit);
  214. # Define Channel Elements
  215. $rssTitle=get_bloginfo('name').' - '.__("All Forums", "sforum");
  216. $rssLink=SFURL;
  217. if ($rssopt['sfrssfeedkey'] && isset($sfglobals['member']['feedkey']))
  218. $atomLink=sf_build_qurl('xfeed=all', 'feedkey='.$sfglobals['member']['feedkey']);
  219. else
  220. $atomLink=sf_build_qurl('xfeed=all');
  221. $rssDescription=get_bloginfo('description');
  222. $rssGenerator=__('Simple:Press Version ', "sforum").SFVERSION;
  223. $rssItem=array();
  224. if($posts)
  225. {
  226. foreach($posts as $post)
  227. {
  228. $thisforum = sf_get_forum_record($post->forum_id);
  229. if($post->topic_id && $thisforum && (sf_can_view_forum($post->forum_id) || !$rssopt['sfrssfeedkey']))
  230. {
  231. # Define Item Elements
  232. $item = new stdClass;
  233. $poster = sf_filter_name_display($post->display_name);
  234. if(empty($poster)) $poster = sf_filter_name_display($post->guest_name);
  235. $topic=sf_get_topic_record($post->topic_id);
  236. $item->title=$poster.' '.__('on', "sforum").' '.sf_filter_title_display($topic->topic_name);
  237. $item->link=sf_build_url($thisforum->forum_slug, $topic->topic_slug, 0, $post->post_id);
  238. $item->pubDate=mysql2date('r', $post->post_date);
  239. $item->category=sf_get_forum_name($thisforum->forum_slug);
  240. $text=sf_filter_rss_display($post->post_content);
  241. $item->description=sf_rss_excerpt($text);
  242. $item->guid=sf_build_url($thisforum->forum_slug, $topic->topic_slug, 0, $post->post_id);
  243. $rssItem[]=$item;
  244. }
  245. }
  246. }
  247. break;
  248. }
  249. # Send headers and XML
  250. header("HTTP/1.1 200 OK");
  251. header('Content-Type: application/xml');
  252. header("Cache-control: max-age=3600");
  253. header("Expires: ".date('r', time()+3600));
  254. header("Pragma: ");
  255. echo'<?xml version="1.0" encoding="'.get_option('blog_charset').'"?>';
  256. ?>
  257. <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  258. <channel>
  259. <title><?php sf_rss_filter($rssTitle) ?></title>
  260. <link><?php sf_rss_filter($rssLink) ?></link>
  261. <description><![CDATA[<?php sf_rss_filter($rssDescription) ?>]]></description>
  262. <generator><?php sf_rss_filter($rssGenerator) ?></generator>
  263. <atom:link href="<?php sf_rss_filter($atomLink) ?>" rel="self" type="application/rss+xml" />
  264. <?php
  265. if($rssItem)
  266. {
  267. foreach($rssItem as $item)
  268. {
  269. ?>
  270. <item>
  271. <title><?php sf_rss_filter($item->title) ?></title>
  272. <link><?php sf_rss_filter($item->link) ?></link>
  273. <category><?php sf_rss_filter($item->category) ?></category>
  274. <guid isPermaLink="true"><?php sf_rss_filter($item->guid) ?></guid>
  275. <description><![CDATA[<?php sf_rss_filter($item->description) ?>]]></description>
  276. <pubDate><?php sf_rss_filter($item->pubDate) ?></pubDate>
  277. </item>
  278. <?php
  279. }
  280. }
  281. ?>
  282. </channel>
  283. </rss>