plugins/SpecialRSS.php
author dan@fuhry
Wed, 13 Jun 2007 22:34:15 -0400
changeset 0 cdf76b0e1aa1
child 1 327d3c7cd3f3
permissions -rw-r--r--
Initial repository population
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
     1
<?php
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
     2
/*
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
     3
Plugin Name: RSS Backend
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
     4
Plugin URI: http://enano.homelinux.org/Feed_me
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
     5
Description: Provides the page Special:RSS, which is used to generate RSS feeds of site and page content changes.
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
     6
Author: Dan Fuhry
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
     7
Version: 1.0
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
     8
Author URI: http://enano.homelinux.org/
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
     9
*/
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    10
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    11
/*
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    12
 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    13
 * Version 1.0 release candidate 2
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    14
 * Copyright (C) 2006-2007 Dan Fuhry
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    15
 *
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    16
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    17
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    18
 *
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    19
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    20
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    21
 */
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    22
 
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    23
global $db, $session, $paths, $template, $plugins; // Common objects
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    24
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    25
$plugins->attachHook('base_classes_initted', '
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    26
  $paths->add_page(Array(
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    27
    \'name\'=>\'RSS Feed - Latest changes\',
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    28
    \'urlname\'=>\'RSS\',
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    29
    \'namespace\'=>\'Special\',
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    30
    \'special\'=>0,\'visible\'=>0,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    31
    ));
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    32
  ');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    33
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    34
$plugins->attachHook('session_started', '__enanoRSSAttachHTMLHeaders();');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    35
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    36
function __enanoRSSAttachHTMLHeaders()
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    37
{
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    38
  global $db, $session, $paths, $template, $plugins; // Common objects
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    39
  $template->add_header('<link rel="alternate" title="'.getConfig('site_name').' Changes feed" href="'.makeUrlNS('Special', 'RSS/recent', null, true).'" type="application/rss+xml" />');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    40
  $template->add_header('<link rel="alternate" title="'.getConfig('site_name').' Comments feed" href="'.makeUrlNS('Special', 'RSS/comments', null, true).'" type="application/rss+xml" />');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    41
}
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    42
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    43
define('ENANO_FEEDBURNER_INCLUDED', true);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    44
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    45
/**
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    46
 * Class for easily generating RSS feeds.
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    47
 * @package Enano
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    48
 * @subpackage Feed Me
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    49
 * @license GNU General Public License <http://www.gnu.org/licenses/gpl.html>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    50
 */
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    51
 
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    52
class RSS
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    53
{
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    54
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    55
  /**
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    56
   * List of channels contained in this feed.
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    57
   * @var array
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    58
   */
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    59
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    60
  var $channels = Array();
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    61
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    62
  /**
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    63
   * The channel that's currently being operated on
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    64
   * @var array
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    65
   */
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    66
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    67
  var $this_channel = Array();
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    68
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    69
  /**
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    70
   * GUID of the current channel
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    71
   * @var string
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    72
   */
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    73
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    74
  var $this_guid = '';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    75
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    76
  /**
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    77
   * List of fully XML-formatted feed entries.
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    78
   * @var array
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    79
   */
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    80
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    81
  var $items = Array();
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    82
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    83
  /**
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    84
   * Constructor.
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    85
   * @param string Feed title
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    86
   * @param string Feed description
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    87
   * @param string Linkback
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    88
   * @param string Generator
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    89
   * @param string E-mail of webmaster
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    90
   */
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    91
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    92
  function __construct($title = false, $desc = false, $link = false, $gen = false, $email = false)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    93
  {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    94
    $this->create_channel($title, $desc, $link, $gen, $email);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    95
  }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    96
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    97
  /**
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    98
   * PHP 4 constructor.
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
    99
   */
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   100
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   101
  function RSS($title = false, $desc = false, $link = false, $gen = false, $email = false)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   102
  {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   103
    $this->__construct($title, $desc, $link, $gen, $email);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   104
  }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   105
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   106
  /** 
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   107
   * Creates a new channel.
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   108
   */
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   109
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   110
  function create_channel($title = false, $desc = false, $link = false, $gen = false, $email = false)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   111
  {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   112
    if ( empty($title) )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   113
      $title = 'Untitled feed';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   114
    else
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   115
      $title = htmlspecialchars($title);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   116
    if ( empty($desc) )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   117
      $desc = 'Test feed';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   118
    else
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   119
      $desc = htmlspecialchars($desc);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   120
    if ( empty($link) )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   121
      $link = 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://'.$_SERVER['HTTP_HOST'] . scriptPath . '/';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   122
    else
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   123
      $link = htmlspecialchars($link);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   124
    if ( !empty($gen) )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   125
      $gen = htmlspecialchars($gen);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   126
    else
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   127
      $gen = 'Enano CMS ' . enano_version();
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   128
    if ( !empty($email) )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   129
      $email = htmlspecialchars($email);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   130
    else
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   131
      $email = getConfig('contact_email');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   132
    
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   133
    $this->channels = Array();
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   134
    $guid = md5(microtime() . mt_rand());
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   135
    $this->channels[$guid] = Array(
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   136
        'title' => $title,
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   137
        'link' => $link,
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   138
        'gen' => $gen,
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   139
        'email' => $email,
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   140
        'lang' => 'en-us',
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   141
        'items' => Array()
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   142
      );
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   143
    $this->this_channel =& $this->channels[$guid];
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   144
    $this->this_guid = $guid;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   145
    return $guid;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   146
  }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   147
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   148
  /**
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   149
   * Selects a specific channel to add items to
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   150
   * @param string The GUID of the channel
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   151
   */
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   152
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   153
  function select_channel($guid)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   154
  {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   155
    if ( isset($this->channels[$guid]) )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   156
    {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   157
      $this->this_channel =& $this->channels[$guid];
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   158
      $this->guid = $guid;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   159
    }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   160
  }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   161
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   162
  /**
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   163
   * Adds a news item.
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   164
   * @param string Title of the feed entry
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   165
   * @param string Link to where more information can be found
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   166
   * @param string Short description or content area
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   167
   * @param string Date the item was published. If this is a UNIX timestamp it will be formatted with date().
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   168
   * @param string A Globally-Unique Identifier (GUID) for this item. Doesn't have to be a 128-bit hash - usually it's a link. If one is not provided, one is generated based on the first three parameters.
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   169
   */
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   170
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   171
  function add_item($title, $link, $desc, $pubdate, $guid = false)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   172
  {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   173
    $title = htmlspecialchars($title);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   174
    $link = htmlspecialchars($link);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   175
    $desc = '<![CDATA[ ' . str_replace(']]>', ']]&gt;', $desc) . ']]>';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   176
    if ( is_int($pubdate) || ( !is_int($pub_date) && preg_match('/^([0-9]+)$/', $pubdate) ) )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   177
    {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   178
      $pubdate = date('D, d M Y H:i:s T', intval($pubdate));
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   179
    }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   180
    if ( !$guid )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   181
    {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   182
      $guid = md5 ( $title . $link . $desc . $pubdate );
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   183
      $sec1 = substr($guid, 0, 8);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   184
      $sec2 = substr($guid, 8, 4);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   185
      $sec3 = substr($guid, 12, 4);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   186
      $sec4 = substr($guid, 16, 4);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   187
      $sec5 = substr($guid, 20, 12);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   188
      $guid = sprintf('%s-%s-%s-%s-%s', $sec1, $sec2, $sec3, $sec4, $sec5);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   189
    }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   190
    $xml = "    <item>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   191
      <title>$title</title>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   192
      <link>$link</link>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   193
      <description>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   194
        $desc
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   195
      </description>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   196
      <pubDate>$pubdate</pubDate>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   197
      <guid>$guid</guid>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   198
    </item>";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   199
    $this->this_channel['items'][] = $xml;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   200
  }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   201
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   202
  /**
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   203
   * Converts everything into the final RSS feed.
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   204
   * @param bool If true, XML headers ("<?xml version="1.0" encoding="utf-8" ?>") are included. Defaults to true.
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   205
   * @return string
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   206
   */
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   207
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   208
  function render($headers = true)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   209
  {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   210
    $xml = '';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   211
    if ( $headers )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   212
      // The weird quotes are because of a jEdit syntax highlighting bug
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   213
      $xml .= "<?xml version=".'"'."1.0".'"'." encoding=".'"'."utf-8".'"'." ?>\n";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   214
    $xml .= "<rss version=".'"'."2.0".'"'.">\n";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   215
    foreach ( $this->channels as $channel )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   216
    {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   217
      $xml .= "  <channel>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   218
    <title>{$channel['title']}</title>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   219
    <link>{$channel['link']}</link>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   220
    <description>{$channel['desc']}</description>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   221
    <generator>{$channel['gen']}</generator>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   222
    <webMaster>{$channel['email']}</webMaster>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   223
    <language>{$channel['lang']}</language>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   224
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   225
";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   226
      $content = implode("\n", $channel['items']) . "\n";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   227
      $xml .= $content;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   228
      $xml .= "  </channel>";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   229
      $xml .= "
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   230
</rss>";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   231
    }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   232
    return $xml;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   233
  }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   234
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   235
}
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   236
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   237
// function names are IMPORTANT!!! The name pattern is: page_<namespace ID>_<page URLname, without namespace>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   238
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   239
function page_Special_RSS() {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   240
  global $db, $session, $paths, $template, $plugins; // Common objects
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   241
  header('Content-type: text/xml; charset=windows-1252'); //application/rss+xml');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   242
  $mode = $paths->getParam(0);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   243
  $n = $paths->getParam(1);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   244
  if(!preg_match('#^([0-9]+)$#', $n) || (int)$n > 50) $n = 20;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   245
  else $n = (int)$n;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   246
  switch($mode)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   247
  {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   248
    case "recent":
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   249
    case false:
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   250
      $title = getConfig('site_name') . ' Recent Changes';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   251
      $desc = getConfig('site_desc');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   252
      
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   253
      $rss = new RSS($title, $desc);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   254
      
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   255
      $q = $db->sql_query('SELECT * FROM '.table_prefix.'logs WHERE log_type=\'page\' ORDER BY time_id DESC LIMIT '.$n.';');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   256
      if(!$q)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   257
      {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   258
        $rss->add_item('ERROR', '', 'Error selecting log data: ' . mysql_error() . '', time());
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   259
      }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   260
      else
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   261
      {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   262
        while($row = $db->fetchrow())
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   263
        {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   264
          $link = 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://'.$_SERVER['HTTP_HOST'] . makeUrlNS($row['namespace'], $row['page_id']);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   265
          $title = $paths->pages[$paths->nslist[$row['namespace']].$row['page_id']]['name'];
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   266
          $desc = ( $row['edit_summary'] != '' ) ? $row['edit_summary'] : 'No edit summary given.';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   267
          $date = $row['time_id'];
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   268
          $guid = 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://'.$_SERVER['HTTP_HOST'] . makeUrlNS($row['namespace'], $row['page_id']).'?oldid='.$row['time_id'];
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   269
          
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   270
          $rss->add_item($title, $link, $desc, $date, $guid);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   271
        }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   272
      }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   273
      
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   274
      echo $rss->render();
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   275
      break;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   276
    case "comments":
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   277
      $title = getConfig('site_name') . ' Latest Comments';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   278
      $desc = getConfig('site_desc');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   279
      
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   280
      $rss = new RSS($title, $desc);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   281
      
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   282
      $q = $db->sql_query('SELECT * FROM '.table_prefix.'comments ORDER BY time DESC LIMIT '.$n.';');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   283
        
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   284
      if(!$q)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   285
      {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   286
        $rss->add_item('ERROR', '', 'Error selecting log data: ' . mysql_error() . '', time());
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   287
      }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   288
      else
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   289
      {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   290
        $n = $db->numrows();
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   291
        //echo '<!-- Number of rows: '.$n.' -->'; // ."\n<!-- SQL backtrace: \n\n".$db->sql_backtrace().' -->';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   292
        for ( $j = 0; $j < $n; $j++ )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   293
        {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   294
          $row = $db->fetchrow($q);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   295
          if(!is_array($row)) die(__FILE__.':'.__LINE__.' $row is not an array');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   296
          $link = 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://'.$_SERVER['HTTP_HOST'] . makeUrlNS($row['namespace'], $row['page_id']).'#comments';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   297
          $page = ( isset($paths->pages[$paths->nslist[$row['namespace']].$row['page_id']]) ) ? $paths->pages[$paths->nslist[$row['namespace']].$row['page_id']]['name'] : $paths->nslist[$row['namespace']].$row['page_id'];
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   298
          $title = $row['subject'] . ': Posted on page "'.$page.'" by user '.$row['name'];
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   299
          $desc = RenderMan::render($row['comment_data']);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   300
          $date = $row['time'];
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   301
          $guid = 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://'.$_SERVER['HTTP_HOST'] . makeUrlNS($row['namespace'], $row['page_id']).'?do=comments&amp;comment='.$row['time'];
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   302
          
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   303
          $rss->add_item($title, $link, $desc, $date, $guid);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   304
        }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   305
      }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   306
      echo $rss->render();
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   307
      break;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   308
    default:
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   309
      $code = $plugins->setHook('feed_me_request');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   310
      foreach ( $code as $cmd )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   311
      {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   312
        eval($cmd);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   313
      }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   314
      break;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   315
  }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   316
}
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   317
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   318
?>