[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/ -> rss.php (source)

   1  <?php # $Id: rss.php 1693 2007-05-16 10:12:47Z garvinhicking $
   2  # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
   3  # All rights reserved.  See LICENSE file for licensing details
   4  
   5  header('Content-Type: text/xml; charset=utf-8');
   6  session_cache_limiter('public');
   7  
   8  @define('IN_RSS', true);
   9  include ('serendipity_config.inc.php');
  10  include (S9Y_INCLUDE_PATH . 'include/functions_rss.inc.php');
  11  
  12  $version         = $_GET['version'];
  13  $description     = $serendipity['blogDescription'];
  14  $title           = $serendipity['blogTitle'];
  15  $comments        = FALSE;
  16  
  17  if (empty($version)) {
  18      list($version) = serendipity_discover_rss($_GET['file'], $_GET['ext']);
  19  }
  20  
  21  if (isset($_GET['category'])) {
  22      $serendipity['GET']['category'] = $_GET['category'];
  23  }
  24  
  25  if (isset($_GET['viewAuthor'])) {
  26      $serendipity['GET']['viewAuthor'] = $_GET['viewAuthor'];
  27  }
  28  
  29  if (!isset($_GET['type'])) {
  30      $_GET['type'] = 'content';
  31  }
  32  
  33  if (!empty($_SERVER['HTTP_USER_AGENT']) && stristr($_SERVER['HTTP_USER_AGENT'], 'feedburner')) {
  34      $_GET['nocache'] = true;
  35  }
  36  
  37  $serendipity['view'] = 'feed';
  38  
  39  switch ($_GET['type']) {
  40      case 'comments_and_trackbacks':
  41      case 'trackbacks':
  42      case 'comments':
  43          $latest_entry = serendipity_fetchComments(isset($_GET['cid']) ? $_GET['cid'] : null, 1, 'desc', false, $_GET['type']);
  44          break;
  45      case 'content':
  46      default:
  47          $latest_entry = serendipity_fetchEntries(null, false, 1, false, false, 'last_modified DESC', '', false, true);
  48      break;
  49  }
  50  
  51  if (!isset($_GET['nocache'])) {
  52      /*
  53       * Caching logic - Do not send feed if nothing has changed
  54       * Implementation inspired by Simon Willison [http://simon.incutio.com/archive/2003/04/23/conditionalGet], Thiemo Maettig
  55       */
  56  
  57      // See if the client has provided the required headers.
  58      // Always convert the provided header into GMT timezone to allow comparing to the server-side last-modified header
  59      $modified_since = !empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])
  60                      ? gmdate('D, d M Y H:i:s \G\M\T', strtotime(stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE'])))
  61                      : false;
  62      $none_match     = !empty($_SERVER['HTTP_IF_NONE_MATCH'])
  63                      ? str_replace('"', '', stripslashes($_SERVER['HTTP_IF_NONE_MATCH']))
  64                      : false;
  65  
  66      if (is_array($latest_entry) && isset($latest_entry[0]['last_modified'])) {
  67          $last_modified = gmdate('D, d M Y H:i:s \G\M\T', serendipity_serverOffsetHour($latest_entry[0]['last_modified'], false));
  68          $etag          = '"' . $last_modified . '"';
  69  
  70          header('Last-Modified: ' . $last_modified);
  71          header('ETag: '          . $etag);
  72  
  73          if (($none_match == $last_modified && $modified_since == $last_modified) ||
  74              (!$none_match && $modified_since == $last_modified) ||
  75              (!$modified_since && $none_match == $last_modified)) {
  76              header('HTTP/1.0 304 Not Modified');
  77              return;
  78          }
  79      }
  80  }
  81  
  82  if (isset($modified_since) &&
  83          (stristr($_SERVER['HTTP_USER_AGENT'], 'planet') !== FALSE || $serendipity['enforce_RFC2616'])) {
  84      // People shall get a usual HTTP response according to RFC2616. See serendipity_config.inc.php for details
  85      $modified_since = FALSE;
  86  }
  87  
  88  switch ($_GET['type']) {
  89  case 'comments_and_trackbacks':
  90  case 'trackbacks':
  91  case 'comments':
  92      $entries     = serendipity_fetchComments(isset($_GET['cid']) ? $_GET['cid'] : null, $serendipity['RSSfetchLimit'], 'desc', false, $_GET['type']);
  93      $description = $title . ' - ' . $description;
  94      if (isset($_GET['cid'])) {
  95          $title       = $title . ' - ' . COMMENTS_FROM . ' "' . $latest_entry[0]['title'] . '"';
  96      } else {
  97          $title       = $title . ' - ' . COMMENTS;
  98      }
  99      $comments    = TRUE;
 100      break;
 101  case 'content':
 102  default:
 103      if (isset($_GET['all']) && $_GET['all']) {
 104          // Fetch all entries in reverse order for later importing. Fetch sticky entries as normal entries.
 105          $entries = serendipity_fetchEntries(null, true, '', false, false, 'id ASC', '', false, true);
 106      } else {
 107          $entries = serendipity_fetchEntries(null, true, $serendipity['RSSfetchLimit'], false, (isset($modified_since) ? $modified_since : false), 'timestamp DESC', '', false, true);
 108      }
 109      break;
 110  }
 111  
 112  if (isset($serendipity['serendipityRealname'])) {
 113      $title .= ' (' . LOGIN . ': ' . $serendipity['serendipityRealname'] . ')';
 114  }
 115  
 116  if (!empty($serendipity['GET']['category'])) {
 117      $cInfo       = serendipity_fetchCategoryInfo((int)$serendipity['GET']['category']);
 118      $title       = serendipity_utf8_encode(htmlspecialchars($title . ' - '. $cInfo['category_name']));
 119  } elseif (!empty($serendipity['GET']['viewAuthor'])) {
 120      list($aInfo) = serendipity_fetchAuthor((int)$serendipity['GET']['viewAuthor']);
 121      $title       = serendipity_utf8_encode(htmlspecialchars($aInfo['realname'] . ' - '. $title ));
 122  } else {
 123      $title       = serendipity_utf8_encode(htmlspecialchars($title));
 124  }
 125  
 126  $description = serendipity_utf8_encode(htmlspecialchars($description));
 127  
 128  $metadata = array(
 129      'title'             => $title,
 130      'description'       => $description,
 131      'language'          => $serendipity['lang'],
 132      'additional_fields' => array(),
 133      'link'              => $serendipity['baseURL'],
 134      'email'             => $serendipity['blogMail'],
 135      'fullFeed'          => false,
 136      'showMail'          => false,
 137      'version'           => $version
 138  );
 139  
 140  if (!defined('S9Y_FRAMEWORK_PLUGIN_API')) {
 141      include (S9Y_INCLUDE_PATH . 'include/plugin_api.inc.php');
 142  }
 143  $plugins = serendipity_plugin_api::enum_plugins();
 144  
 145  if (is_array($plugins)) {
 146      // load each plugin to make some introspection
 147      foreach ($plugins as $plugin_data) {
 148          if (preg_match('|@serendipity_syndication_plugin|', $plugin_data['name'])) {
 149              $plugin =& serendipity_plugin_api::load_plugin($plugin_data['name'], $plugin_data['authorid']);
 150  
 151              $metadata['additional_fields'] = $plugin->generate_rss_fields($metadata['title'], $metadata['description'], $entries);
 152              if (is_array($metadata['additional_fields'])) {
 153                  // Fix up array keys, because "." are not allowed when wanting to output using Smarty
 154                  foreach($metadata['additional_fields'] AS $_aid => $af) {
 155                      $aid = str_replace('.', '', $_aid);
 156                      $metadata['additional_fields'][$aid] = $af;
 157                  }
 158              }
 159              $metadata['fullFeed']          = $plugin->get_config('fullfeed', false);
 160              if ($metadata['fullFeed'] === 'client') {
 161                  if ($_GET['fullFeed'] || $serendipity['GET']['fullFeed']) {
 162                      $metadata['fullFeed'] = true;
 163                  } else {
 164                      $metadata['fullFeed'] = false;
 165                  }
 166              }
 167  
 168              if ($_GET['type']  == 'content' &&
 169                  !isset($_GET['category']) &&
 170                  !isset($serendipity['GET']['tag']) &&
 171                  $plugin->get_config('show_feedburner') === 'force' &&
 172                  !preg_match('@FeedBurn@i', $_SERVER['HTTP_USER_AGENT']) &&
 173                  !(serendipity_userLoggedIn() && isset($_GET['forceLocal']))
 174                 ) {
 175                  $url = 'http://feeds.feedburner.com/' . $plugin->get_config('fb_id');
 176                  header('Location: ' . $url);
 177                  exit;
 178              }
 179              $metadata['showMail']          = serendipity_db_bool($plugin->get_config('show_mail', $metadata['showMail']));
 180              break;
 181          }
 182      }
 183  }
 184  
 185  $file_version  = preg_replace('@[^0-9a-z\.-_]@i', '', $version);
 186  $metadata['template_file'] = serendipity_getTemplateFile('feed_' . $file_version . '.tpl', 'serendipityPath');
 187  
 188  serendipity_smarty_init();
 189  serendipity_plugin_api::hook_event('frontend_rss', $metadata);
 190  
 191  if (!$metadata['template_file'] || $metadata['template_file'] == 'feed_' . $file_version . '.tpl') {
 192      die("Invalid RSS version specified or RSS-template file not found\n");
 193  }
 194  
 195  $self_url = 'http://' . $_SERVER['HTTP_HOST'] . htmlspecialchars($_SERVER['REQUEST_URI']);
 196  if (!is_array($entries)) {
 197      $entries = array();
 198  }
 199  
 200  if ($entries[0]['last_modified']) {
 201      $gm_modified = gmdate('Y-m-d\TH:i:s\Z', serendipity_serverOffsetHour($entries[0]['last_modified']));
 202  } else {
 203      $gm_modified = gmdate('Y-m-d\TH:i:s\Z', serendipity_serverOffsetHour());
 204  }
 205  
 206  serendipity_printEntries_rss($entries, $version, $comments, $metadata['fullFeed'], $metadata['showMail']);
 207  
 208  $namespace_hook   = 'frontend_display:unknown:namespace';
 209  $once_display_dat = '';
 210  switch($version) {
 211      case 'opml1.0':
 212          $namespace_hook = 'frontend_display:opml-1.0:namespace';
 213          break;
 214  
 215      case '0.91':
 216          $namespace_hook = 'frontend_display:rss-0.91:namespace';
 217          break;
 218  
 219      case '1.0':
 220          $namespace_hook = 'frontend_display:rss-1.0:namespace';
 221          serendipity_plugin_api::hook_event('frontend_display:rss-1.0:once', $entries);
 222          $once_display_dat = $entries['display_dat'];
 223          unset($entries['display_dat']);
 224          break;
 225  
 226      case '2.0':
 227          $namespace_hook = 'frontend_display:rss-2.0:namespace';
 228          break;
 229  
 230      case 'atom0.3':
 231          $namespace_hook = 'frontend_display:atom-0.3:namespace';
 232          break;
 233  
 234      case 'atom1.0':
 235          // For people wanting extra RFC compliance
 236          // header('Content-Type: application/atom+xml; charset=utf-8');
 237          $namespace_hook = 'frontend_display:atom-1.0:namespace';
 238          break;
 239  }
 240  
 241  serendipity_plugin_api::hook_event($namespace_hook, $entries);
 242  $namespace_display_dat = $entries['display_dat'];
 243  unset($entries['display_dat']);
 244  
 245  $serendipity['smarty']->assign_by_ref('metadata', $metadata);
 246  $serendipity['smarty']->assign_by_ref('entries', $entries);
 247  $serendipity['smarty']->assign_by_ref('namespace_display_dat', $namespace_display_dat);
 248  $serendipity['smarty']->assign_by_ref('once_display_dat', $once_display_dat);
 249  
 250  $serendipity['smarty']->assign(
 251      array(
 252          'is_comments'           => $comments,
 253          'last_modified'         => $gm_modified,
 254          'self_url'              => $self_url,
 255      )
 256  );
 257  $serendipity['smarty']->display($metadata['template_file']);
 258  
 259  /* vim: set sts=4 ts=4 expandtab : */


Généré le : Sat Nov 24 09:00:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics