/bp-forums/bbpress/rss.php

  1. <?php 
  2. require('./bb-load.php'); 
  3.  
  4. // Determine the type of feed and the id of the object 
  5. if ( isset($_GET['view']) || bb_get_path() == 'view' ) { 
  6.  
  7. // View 
  8. $feed = 'view'; 
  9. $feed_id = isset($_GET['view']) ? $_GET['view'] : bb_get_path(2); 
  10.  
  11. } elseif ( isset($_GET['topic']) || bb_get_path() == 'topic' ) { 
  12.  
  13. // Topic 
  14. $feed = 'topic'; 
  15. $topic = get_topic(isset($_GET['topic']) ? $_GET['topic'] : bb_get_path(2)); 
  16. $feed_id = $topic->topic_id; 
  17.  
  18. } elseif ( isset($_GET['profile']) || bb_get_path() == 'profile' ) { 
  19.  
  20. // Profile 
  21. $feed = 'profile'; 
  22. $feed_id = isset($_GET['profile']) ? $_GET['profile'] : bb_get_path(2); 
  23.  
  24. } elseif ( isset($_GET['tag']) || bb_get_path() == 'tags' ) { 
  25.  
  26. if ( isset($_GET['topics']) || bb_get_path(3) == 'topics' ) { 
  27. // Tag recent topics 
  28. $feed = 'tag-topics'; 
  29. } else { 
  30. // Tag recent posts 
  31. $feed = 'tag-posts'; 
  32. $feed_id = isset($_GET['tag']) ? $_GET['tag'] : bb_get_path(2); 
  33.  
  34. } elseif ( isset($_GET['forum']) || bb_get_path() == 'forum' ) { 
  35.  
  36. if ( isset($_GET['topics']) || bb_get_path(3) == 'topics' ) { 
  37. // Forum recent topics 
  38. $feed = 'forum-topics'; 
  39. } else { 
  40. // Forum recent posts 
  41. $feed = 'forum-posts'; 
  42. $forum = bb_get_forum(isset($_GET['forum']) ? $_GET['forum'] : bb_get_path(2)); 
  43. $feed_id = $forum->forum_id; 
  44.  
  45. } elseif ( isset($_GET['topics']) || bb_get_path() == 'topics' ) { 
  46.  
  47. // Recent topics 
  48. $feed = 'all-topics'; 
  49.  
  50. } else { 
  51.  
  52. // Recent posts 
  53. $feed = 'all-posts'; 
  54.  
  55.  
  56. // Initialise the override variable 
  57. $bb_db_override = false; 
  58. do_action( 'bb_rss.php_pre_db' ); 
  59.  
  60. if ( !$bb_db_override ) { 
  61.  
  62. // Get the posts and the title for the given feed 
  63. switch ($feed) { 
  64. case 'view': 
  65. if ( !isset($bb_views[$feed_id]) ) 
  66. die(); 
  67. if ( !$bb_views[$feed_id]['feed'] ) 
  68. die(); 
  69. if ( !$topics_object = new BB_Query( 'topic', $bb_views[$feed_id]['query'], "bb_view_$feed_id" ) ) 
  70. die(); 
  71.  
  72. $topics = $topics_object->results; 
  73.  
  74. $posts = array(); 
  75. foreach ( (array) $topics as $topic ) { 
  76. $posts[] = bb_get_first_post($topic->topic_id); 
  77.  
  78. $title = sprintf( __( '%1$s » View: %2$s' ), bb_get_option( 'name' ), $bb_views[$feed_id]['title'] ); 
  79. $link = get_view_link($feed_id); 
  80. $link_self = bb_get_view_rss_link($feed_id); 
  81. break; 
  82.  
  83. case 'topic': 
  84. if ( !$topic = get_topic ( $feed_id ) ) 
  85. die(); 
  86. if ( !$posts = get_thread( $feed_id, 0, 1 ) ) 
  87. die(); /** Should die here, as the topic posts aren't there, so the topic is most probably deleted/empty */ 
  88. $title = sprintf( __( '%1$s » Topic: %2$s' ), bb_get_option( 'name' ), get_topic_title() ); 
  89. $link = get_topic_link($feed_id); 
  90. $link_self = get_topic_rss_link($feed_id); 
  91. break; 
  92.  
  93. case 'profile': 
  94. if ( bb_get_option( 'mod_rewrite' ) === 'slugs') { 
  95. if ( !$user = bb_get_user_by_nicename( $feed_id ) ) 
  96. $user = bb_get_user( $feed_id ); 
  97. } else { 
  98. if ( !$user = bb_get_user( $feed_id ) ) 
  99. $user = bb_get_user_by_nicename( $feed_id );  
  100. if ( !$user ) { 
  101. die(); 
  102. $posts = get_user_favorites( $user->ID ); 
  103.  
  104. $title = sprintf( __( '%1$s » User Favorites: %2$s' ), bb_get_option( 'name' ), $user->user_nicename ); 
  105. $link = get_user_profile_link($feed_id); 
  106. $link_self = get_favorites_rss_link($feed_id); 
  107. break; 
  108.  
  109. case 'tag-topics': 
  110. if ( !$tag = bb_get_tag( $feed_id ) ) 
  111. die(); 
  112. $topics = get_tagged_topics( array( 'tag_id' => $tag->tag_id, 'page' => 0 ) ); 
  113.  
  114. $posts = array(); 
  115. foreach ( (array) $topics as $topic ) { 
  116. $posts[] = bb_get_first_post($topic->topic_id); 
  117.  
  118. $title = sprintf( __( '%1$s » Tag: %2$s - Recent Topics' ), bb_get_option( 'name' ), bb_get_tag_name() ); 
  119. $link = bb_get_tag_link($feed_id); 
  120. $link_self = bb_get_tag_topics_rss_link($feed_id); 
  121. break; 
  122.  
  123. case 'tag-posts': 
  124. if ( !$tag = bb_get_tag( $feed_id ) ) 
  125. die(); 
  126. $posts = get_tagged_topic_posts( array( 'tag_id' => $tag->tag_id, 'page' => 0 ) ); 
  127. $title = sprintf( __( '%1$s » Tag: %2$s - Recent Posts' ), bb_get_option( 'name' ), bb_get_tag_name() ); 
  128. $link = bb_get_tag_link($feed_id); 
  129. $link_self = bb_get_tag_posts_rss_link($feed_id); 
  130. break; 
  131.  
  132. case 'forum-topics': 
  133. $topics = get_latest_topics( $feed_id ); 
  134.  
  135. $posts = array(); 
  136. foreach ( (array) $topics as $topic) { 
  137. $posts[] = bb_get_first_post($topic->topic_id); 
  138.  
  139. $title = sprintf( __( '%1$s » Forum: %2$s - Recent Topics' ), bb_get_option( 'name' ), get_forum_name( $feed_id ) ); 
  140. $link = get_forum_link($feed_id); 
  141. $link_self = bb_get_forum_topics_rss_link($feed_id); 
  142. break; 
  143.  
  144. case 'forum-posts': 
  145. $posts = bb_get_latest_forum_posts( $feed_id ); 
  146. $title = sprintf( __( '%1$s » Forum: %2$s - Recent Posts' ), bb_get_option( 'name' ), get_forum_name( $feed_id ) ); 
  147. $link = get_forum_link($feed_id); 
  148. $link_self = bb_get_forum_posts_rss_link($feed_id); 
  149. break; 
  150.  
  151. // Get just the first post from the latest topics 
  152. case 'all-topics': 
  153. $topics = get_latest_topics(); 
  154.  
  155. $posts = array(); 
  156. foreach ( (array) $topics as $topic ) { 
  157. $posts[] = bb_get_first_post($topic->topic_id); 
  158.  
  159. $title = sprintf( __( '%1$s » Recent Topics' ), bb_get_option( 'name' ) ); 
  160. $link = bb_get_uri(); 
  161. $link_self = bb_get_topics_rss_link(); 
  162. break; 
  163.  
  164. // Get latest posts by default 
  165. case 'all-posts': 
  166. default: 
  167. $posts = bb_get_latest_posts( 35 ); 
  168. $title = sprintf( __( '%1$s » Recent Posts' ), bb_get_option( 'name' ) ); 
  169. $link = bb_get_uri(); 
  170. $link_self = bb_get_posts_rss_link(); 
  171. break; 
  172.  
  173. if ( !$posts ) /** We do typecasting in the template, but all themes don't have that! */ 
  174. $posts = array(); 
  175. else /** Only send 304 if there are posts */ 
  176. bb_send_304( gmdate('D, d M Y H:i:s \G\M\T', strtotime( $posts[0]->post_time ) ) ); 
  177.  
  178. if (!$description = bb_get_option( 'description' ) ) { 
  179. $description = $title; 
  180. $title = apply_filters( 'bb_title_rss', $title, $feed ); 
  181. $description = apply_filters( 'bb_description_rss', $description, $feed ); 
  182. $posts = apply_filters( 'bb_posts_rss', $posts, $feed ); 
  183. $link_self = apply_filters( 'bb_link_self_rss', $link_self, $feed ); 
  184.  
  185. bb_load_template( 'rss2.php', array('bb_db_override', 'title', 'description', 'link', 'link_self'), $feed ); 
.