Beehive PHP Cross Reference Discussion Forums

Source: /threads_rss.php - 197 lines - 6803 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /*======================================================================
   4  Copyright Project Beehive Forum 2002
   5  
   6  This file is part of Beehive Forum.
   7  
   8  Beehive Forum is free software; you can redistribute it and/or modify
   9  it under the terms of the GNU General Public License as published by
  10  the Free Software Foundation; either version 3 of the License, or
  11  (at your option) any later version.
  12  
  13  Beehive Forum is distributed in the hope that it will be useful,
  14  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16  GNU General Public License for more details.
  17  
  18  You should have received a copy of the GNU General Public License
  19  along with Beehive; if not, write to the Free Software
  20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  21  USA
  22  ======================================================================*/
  23  
  24  // Bootstrap
  25  require_once  'boot.php';
  26  
  27  // Required includes
  28  require_once  BH_INCLUDE_PATH . 'cache.inc.php';
  29  require_once  BH_INCLUDE_PATH . 'constants.inc.php';
  30  require_once  BH_INCLUDE_PATH . 'folder.inc.php';
  31  require_once  BH_INCLUDE_PATH . 'format.inc.php';
  32  require_once  BH_INCLUDE_PATH . 'forum.inc.php';
  33  require_once  BH_INCLUDE_PATH . 'html.inc.php';
  34  require_once  BH_INCLUDE_PATH . 'messages.inc.php';
  35  require_once  BH_INCLUDE_PATH . 'session.inc.php';
  36  require_once  BH_INCLUDE_PATH . 'threads.inc.php';
  37  // End Required includes
  38  
  39  // Check that Guests are allowed
  40  if (!session::logged_in()) {
  41      html_guest_error();
  42  }
  43  
  44  // Arrays for our cookie data
  45  $username_array = array();
  46  $password_array = array();
  47  $passhash_array = array();
  48  
  49  // Get the forum location accounting for forward slashes, multiple slashes, etc.
  50  $forum_location = html_get_forum_uri();
  51  
  52  // Get the Forum Name
  53  $forum_name = forum_get_setting('forum_name', 'strlen', 'A Beehive Forum');
  54  
  55  // Current date
  56  $build_date = gmdate("D, d M Y H:i:s O");
  57  
  58  // Check to see if the user wants a custom number of threads.
  59  // Maximum to display is 20. Minimum is 1. Default is 20.
  60  if (isset($_GET['limit']) && is_numeric($_GET['limit'])) {
  61  
  62      if ($_GET['limit'] > 20) {
  63  
  64          $limit = 20;
  65  
  66      } else if ($_GET['limit'] < 1) {
  67  
  68          $limit = 1;
  69  
  70      } else {
  71  
  72          $limit = $_GET['limit'];
  73      }
  74  
  75  } else {
  76  
  77      $limit = 20;
  78  }
  79  
  80  // Feed title is just the forum name by default
  81  $feed_title = $forum_name;
  82  
  83  // Default to showing all available folders
  84  $fid = false;
  85  
  86  // Check to see if the user wants threads ordered by created
  87  // or modified date. Modified date bumps a thread to the top
  88  // when it receives a reply. Created threads show the threads
  89  // in the order they were created and is more useful as a
  90  // RSS news feed within your forum.
  91  if (isset($_GET['sort_created']) && $_GET['sort_created'] == 'Y') {
  92      $sort_created = 'Y';
  93  } else {
  94      $sort_created = 'N';
  95  }
  96  
  97  // Check to see if the user wants a specified list of folders
  98  // or the default to show all folders.
  99  if (isset($_GET['fid']) && is_numeric($_GET['fid'])) {
 100  
 101      if (($available_folders_array = folder_get_available_array()) !== false) {
 102  
 103          if (in_array($_GET['fid'], $available_folders_array) && ($folder_title = folder_get_title($fid))) {
 104  
 105              $fid = trim($_GET['fid']);
 106              $feed_title .= sprintf(' - %s', htmlentities_array($folder_title));
 107  
 108          } else {
 109  
 110              $fid = false;
 111          }
 112      }
 113  }
 114  
 115  // Enable caching on RSS Feed
 116  cache_check_request_throttle(300);
 117  
 118  // echo out the rss feed
 119  header('Content-type: text/xml; charset=UTF-8');
 120  
 121  echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
 122  echo "<rss xmlns:dc=\"http://purl.org/dc/elements/1.1/\" version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n";
 123  echo "<channel>\n";
 124  echo "<title>{$feed_title} - ", gettext("RSS Feed"), "</title>\n";
 125  echo "<link>{$forum_location}/</link>\n";
 126  echo "<description>{$forum_name} - {$forum_location}/</description>\n";
 127  echo "<lastBuildDate>{$build_date}</lastBuildDate>\n";
 128  echo "<generator>Project Beehive Forum - www.beehiveforum.co.uk</generator>\n";
 129  echo "<image>\n";
 130  echo "<title>{$forum_name}</title>\n";
 131  echo "<url>", html_style_image('rss_icon.png', true, true), "</url>\n";
 132  echo "<link>{$forum_location}/</link>\n";
 133  echo "</image>\n";
 134  
 135  // Get the 20 most recent threads
 136  if (($threads_array = threads_get_most_recent($limit, $fid, ($sort_created == 'Y'))) !== false) {
 137  
 138      foreach ($threads_array as $thread) {
 139  
 140          $title = $thread['TITLE'];
 141  
 142          // Make the date human readable and fetch the content of the last
 143          // post in the thread. Can easily change this if it isn't right
 144          // by making it fetch post 1.
 145          $modified_date = gmdate("D, d M Y H:i:s", $thread['MODIFIED']);
 146  
 147          // Get the post content and author
 148          if ($sort_created == 'Y') {
 149  
 150              $content = message_get_content($thread['TID'], 1);
 151              $author = message_get_author($thread['TID'], 1);
 152  
 153          } else {
 154  
 155              $content = message_get_content($thread['TID'], $thread['LENGTH']);
 156              $author = message_get_author($thread['TID'], $thread['LENGTH']);
 157          }
 158  
 159          // Strip signatures from the RSS feed
 160          $content = message_apply_formatting($content, true);
 161  
 162          // Strip HTML and trim the content back.
 163          $content = strip_tags(trim(xml_strip_invalid_chars($content)));
 164  
 165          // Convert HTML special chars (& -> &amp;, etc);
 166          $content = htmlspecialchars($content);
 167          $title = htmlspecialchars($title);
 168  
 169          // Check for double-encoded HTML chars (&amp;amp;, etc.)
 170          $content = preg_replace("/&amp;(#[0-9]+|[a-z]+);/iu", "&\\1;", $content);
 171          $title = preg_replace("/&amp;(#[0-9]+|[a-z]+);/iu", "&\\1;", $title);
 172  
 173          // Convert HTML entities to XML literals.
 174          $content = html_entity_to_decimal($content);
 175          $title = html_entity_to_decimal($title);
 176  
 177          // Output the item.
 178          echo "<item>\n";
 179          echo "  <guid isPermaLink=\"true\">{$forum_location}/index.php?webtag=$webtag&amp;msg={$thread['TID']}.1</guid>\n";
 180          echo "  <pubDate>{$modified_date} UT</pubDate>\n";
 181          echo "  <title>{$title}</title>\n";
 182          echo "  <link>{$forum_location}/index.php?webtag=$webtag&amp;msg={$thread['TID']}.1</link>\n";
 183  
 184          // Get the author of the message.
 185          if (isset($author['LOGON'])) {
 186              echo "  <dc:creator>", htmlentities_array(format_user_name($author['LOGON'], $author['NICKNAME'])), "</dc:creator>\n";
 187          }
 188  
 189          echo "  <description><![CDATA[{$content}]]></description>\n";
 190          echo "  <comments>{$forum_location}/index.php?webtag=$webtag&amp;msg={$thread['TID']}.1</comments>\n";
 191          echo "</item>\n";
 192      }
 193  }
 194  
 195  echo "<atom:link href=\"{$forum_location}/threads_rss.php?webtag=$webtag\" rel=\"self\" type=\"application/rss+xml\" />\n";
 196  echo "</channel>\n";
 197  echo "</rss>\n";

title

Description

title

Description

title

Description

title

title

Body