plugins/RSS.php
author Dan
Sat, 29 Nov 2008 01:01:54 -0500
changeset 3 f71442e3a95f
parent 2 plugins/SpecialRSS.php@882c793b0f37
child 4 308a696fce01
permissions -rw-r--r--
Renamed plugin file... don't ask me why
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
/*
1
327d3c7cd3f3 A few bugfixes and updates. The most recent fix involves $desc being undefined in the add_channel method.
Dan
parents: 0
diff changeset
     3
Plugin Name: RSS Frontend
327d3c7cd3f3 A few bugfixes and updates. The most recent fix involves $desc being undefined in the add_channel method.
Dan
parents: 0
diff changeset
     4
Plugin URI: http://enanocms.org/Feed_me
0
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
1
327d3c7cd3f3 A few bugfixes and updates. The most recent fix involves $desc being undefined in the add_channel method.
Dan
parents: 0
diff changeset
     8
Author URI: http://enanocms.org/
0
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,
1
327d3c7cd3f3 A few bugfixes and updates. The most recent fix involves $desc being undefined in the add_channel method.
Dan
parents: 0
diff changeset
   137
        'desc' => $desc,
0
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   138
        'link' => $link,
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   139
        'gen' => $gen,
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   140
        'email' => $email,
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   141
        'lang' => 'en-us',
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   142
        'items' => Array()
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   143
      );
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   144
    $this->this_channel =& $this->channels[$guid];
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   145
    $this->this_guid = $guid;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   146
    return $guid;
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
  /**
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   150
   * Selects a specific channel to add items to
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   151
   * @param string The GUID of the channel
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   152
   */
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   153
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   154
  function select_channel($guid)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   155
  {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   156
    if ( isset($this->channels[$guid]) )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   157
    {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   158
      $this->this_channel =& $this->channels[$guid];
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   159
      $this->guid = $guid;
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
  /**
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   164
   * Adds a news item.
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   165
   * @param string Title of the feed entry
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   166
   * @param string Link to where more information can be found
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   167
   * @param string Short description or content area
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   168
   * @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
   169
   * @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
   170
   */
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   171
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   172
  function add_item($title, $link, $desc, $pubdate, $guid = false)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   173
  {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   174
    $title = htmlspecialchars($title);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   175
    $link = htmlspecialchars($link);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   176
    $desc = '<![CDATA[ ' . str_replace(']]>', ']]&gt;', $desc) . ']]>';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   177
    if ( is_int($pubdate) || ( !is_int($pub_date) && preg_match('/^([0-9]+)$/', $pubdate) ) )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   178
    {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   179
      $pubdate = date('D, d M Y H:i:s T', intval($pubdate));
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   180
    }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   181
    if ( !$guid )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   182
    {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   183
      $guid = md5 ( $title . $link . $desc . $pubdate );
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   184
      $sec1 = substr($guid, 0, 8);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   185
      $sec2 = substr($guid, 8, 4);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   186
      $sec3 = substr($guid, 12, 4);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   187
      $sec4 = substr($guid, 16, 4);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   188
      $sec5 = substr($guid, 20, 12);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   189
      $guid = sprintf('%s-%s-%s-%s-%s', $sec1, $sec2, $sec3, $sec4, $sec5);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   190
    }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   191
    $xml = "    <item>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   192
      <title>$title</title>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   193
      <link>$link</link>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   194
      <description>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   195
        $desc
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   196
      </description>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   197
      <pubDate>$pubdate</pubDate>
3
f71442e3a95f Renamed plugin file... don't ask me why
Dan
parents: 2
diff changeset
   198
      <guid>$link</guid>
0
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   199
    </item>";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   200
    $this->this_channel['items'][] = $xml;
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
  /**
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   204
   * Converts everything into the final RSS feed.
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   205
   * @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
   206
   * @return string
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   207
   */
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   208
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   209
  function render($headers = true)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   210
  {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   211
    $xml = '';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   212
    if ( $headers )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   213
      // The weird quotes are because of a jEdit syntax highlighting bug
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   214
      $xml .= "<?xml version=".'"'."1.0".'"'." encoding=".'"'."utf-8".'"'." ?>\n";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   215
    $xml .= "<rss version=".'"'."2.0".'"'.">\n";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   216
    foreach ( $this->channels as $channel )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   217
    {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   218
      $xml .= "  <channel>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   219
    <title>{$channel['title']}</title>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   220
    <link>{$channel['link']}</link>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   221
    <description>{$channel['desc']}</description>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   222
    <generator>{$channel['gen']}</generator>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   223
    <webMaster>{$channel['email']}</webMaster>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   224
    <language>{$channel['lang']}</language>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   225
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   226
";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   227
      $content = implode("\n", $channel['items']) . "\n";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   228
      $xml .= $content;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   229
      $xml .= "  </channel>";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   230
      $xml .= "
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   231
</rss>";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   232
    }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   233
    return $xml;
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
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   238
// function names are IMPORTANT!!! The name pattern is: page_<namespace ID>_<page URLname, without namespace>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   239
1
327d3c7cd3f3 A few bugfixes and updates. The most recent fix involves $desc being undefined in the add_channel method.
Dan
parents: 0
diff changeset
   240
function page_Special_RSS()
327d3c7cd3f3 A few bugfixes and updates. The most recent fix involves $desc being undefined in the add_channel method.
Dan
parents: 0
diff changeset
   241
{
0
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   242
  global $db, $session, $paths, $template, $plugins; // Common objects
2
882c793b0f37 Merging a one-line change from nighthawk (wrong content-type if you're interested)
Dan
parents: 1
diff changeset
   243
  header('Content-type: text/xml; charset=utf-8'); //application/rss+xml');
1
327d3c7cd3f3 A few bugfixes and updates. The most recent fix involves $desc being undefined in the add_channel method.
Dan
parents: 0
diff changeset
   244
  global $aggressive_optimize_html;
327d3c7cd3f3 A few bugfixes and updates. The most recent fix involves $desc being undefined in the add_channel method.
Dan
parents: 0
diff changeset
   245
  $aggressive_optimize_html = false;
327d3c7cd3f3 A few bugfixes and updates. The most recent fix involves $desc being undefined in the add_channel method.
Dan
parents: 0
diff changeset
   246
  $session->sid_super = false;
327d3c7cd3f3 A few bugfixes and updates. The most recent fix involves $desc being undefined in the add_channel method.
Dan
parents: 0
diff changeset
   247
  if ( $session->auth_level > USER_LEVEL_MEMBER )
327d3c7cd3f3 A few bugfixes and updates. The most recent fix involves $desc being undefined in the add_channel method.
Dan
parents: 0
diff changeset
   248
    $session->auth_level = USER_LEVEL_MEMBER;
0
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   249
  $mode = $paths->getParam(0);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   250
  $n = $paths->getParam(1);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   251
  if(!preg_match('#^([0-9]+)$#', $n) || (int)$n > 50) $n = 20;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   252
  else $n = (int)$n;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   253
  switch($mode)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   254
  {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   255
    case "recent":
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   256
      $title = getConfig('site_name') . ' Recent Changes';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   257
      $desc = getConfig('site_desc');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   258
      
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   259
      $rss = new RSS($title, $desc);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   260
      
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   261
      $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
   262
      if(!$q)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   263
      {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   264
        $rss->add_item('ERROR', '', 'Error selecting log data: ' . mysql_error() . '', time());
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   265
      }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   266
      else
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   267
      {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   268
        while($row = $db->fetchrow())
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   269
        {
1
327d3c7cd3f3 A few bugfixes and updates. The most recent fix involves $desc being undefined in the add_channel method.
Dan
parents: 0
diff changeset
   270
          $link = makeUrlComplete($row['namespace'], $row['page_id'], "oldid={$row['time_id']}"); // makeUrlComplete($row['namespace'], $row['page_id']);
0
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   271
          $title = $paths->pages[$paths->nslist[$row['namespace']].$row['page_id']]['name'];
1
327d3c7cd3f3 A few bugfixes and updates. The most recent fix involves $desc being undefined in the add_channel method.
Dan
parents: 0
diff changeset
   272
          $desc = "Change by {$row['author']}:<br />";
327d3c7cd3f3 A few bugfixes and updates. The most recent fix involves $desc being undefined in the add_channel method.
Dan
parents: 0
diff changeset
   273
          $desc .= ( $row['edit_summary'] != '' ) ? $row['edit_summary'] : 'No edit summary given.';
0
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   274
          $date = $row['time_id'];
1
327d3c7cd3f3 A few bugfixes and updates. The most recent fix involves $desc being undefined in the add_channel method.
Dan
parents: 0
diff changeset
   275
          $guid = false;
0
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   276
          
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   277
          $rss->add_item($title, $link, $desc, $date, $guid);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   278
        }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   279
      }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   280
      
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   281
      echo $rss->render();
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   282
      break;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   283
    case "comments":
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   284
      $title = getConfig('site_name') . ' Latest Comments';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   285
      $desc = getConfig('site_desc');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   286
      
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   287
      $rss = new RSS($title, $desc);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   288
      
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   289
      $q = $db->sql_query('SELECT * FROM '.table_prefix.'comments ORDER BY time DESC LIMIT '.$n.';');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   290
        
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   291
      if(!$q)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   292
      {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   293
        $rss->add_item('ERROR', '', 'Error selecting log data: ' . mysql_error() . '', time());
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   294
      }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   295
      else
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   296
      {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   297
        $n = $db->numrows();
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   298
        //echo '<!-- Number of rows: '.$n.' -->'; // ."\n<!-- SQL backtrace: \n\n".$db->sql_backtrace().' -->';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   299
        for ( $j = 0; $j < $n; $j++ )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   300
        {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   301
          $row = $db->fetchrow($q);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   302
          if(!is_array($row)) die(__FILE__.':'.__LINE__.' $row is not an array');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   303
          $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
   304
          $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
   305
          $title = $row['subject'] . ': Posted on page "'.$page.'" by user '.$row['name'];
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   306
          $desc = RenderMan::render($row['comment_data']);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   307
          $date = $row['time'];
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   308
          $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
   309
          
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   310
          $rss->add_item($title, $link, $desc, $date, $guid);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   311
        }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   312
      }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   313
      echo $rss->render();
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   314
      break;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   315
    default:
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   316
      $code = $plugins->setHook('feed_me_request');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   317
      foreach ( $code as $cmd )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   318
      {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   319
        eval($cmd);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   320
      }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   321
      break;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   322
  }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   323
}
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   324
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   325
?>