plugins/RSS.php
author Dan Fuhry <dan@enanocms.org>
Thu, 08 Jul 2010 17:52:37 -0400
changeset 4 308a696fce01
parent 3 f71442e3a95f
permissions -rw-r--r--
Fixed a few bugs reported by Neal. Removed PHP 4 support.
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
   * Creates a new channel.
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 create_channel($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
    if ( empty($title) )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   104
      $title = 'Untitled feed';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   105
    else
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   106
      $title = htmlspecialchars($title);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   107
    if ( empty($desc) )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   108
      $desc = 'Test feed';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   109
    else
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   110
      $desc = htmlspecialchars($desc);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   111
    if ( empty($link) )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   112
      $link = 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://'.$_SERVER['HTTP_HOST'] . scriptPath . '/';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   113
    else
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   114
      $link = htmlspecialchars($link);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   115
    if ( !empty($gen) )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   116
      $gen = htmlspecialchars($gen);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   117
    else
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   118
      $gen = 'Enano CMS ' . enano_version();
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   119
    if ( !empty($email) )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   120
      $email = htmlspecialchars($email);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   121
    else
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   122
      $email = getConfig('contact_email');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   123
    
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   124
    $this->channels = Array();
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   125
    $guid = md5(microtime() . mt_rand());
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   126
    $this->channels[$guid] = Array(
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   127
        '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
   128
        'desc' => $desc,
0
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   129
        'link' => $link,
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   130
        'gen' => $gen,
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   131
        'email' => $email,
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   132
        'lang' => 'en-us',
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   133
        'items' => Array()
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   134
      );
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   135
    $this->this_channel =& $this->channels[$guid];
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   136
    $this->this_guid = $guid;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   137
    return $guid;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   138
  }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   139
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   140
  /**
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   141
   * Selects a specific channel to add items to
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   142
   * @param string The GUID of the channel
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   143
   */
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   144
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   145
  function select_channel($guid)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   146
  {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   147
    if ( isset($this->channels[$guid]) )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   148
    {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   149
      $this->this_channel =& $this->channels[$guid];
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   150
      $this->guid = $guid;
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
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   154
  /**
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   155
   * Adds a news item.
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   156
   * @param string Title of the feed entry
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   157
   * @param string Link to where more information can be found
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   158
   * @param string Short description or content area
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   159
   * @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
   160
   * @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
   161
   */
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   162
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   163
  function add_item($title, $link, $desc, $pubdate, $guid = false)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   164
  {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   165
    $title = htmlspecialchars($title);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   166
    $link = htmlspecialchars($link);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   167
    $desc = '<![CDATA[ ' . str_replace(']]>', ']]&gt;', $desc) . ']]>';
4
308a696fce01 Fixed a few bugs reported by Neal. Removed PHP 4 support.
Dan Fuhry <dan@enanocms.org>
parents: 3
diff changeset
   168
    if ( is_int($pubdate) || ( !is_int($pubdate) && preg_match('/^([0-9]+)$/', $pubdate) ) )
0
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   169
    {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   170
      $pubdate = date('D, d M Y H:i:s T', intval($pubdate));
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   171
    }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   172
    if ( !$guid )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   173
    {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   174
      $guid = md5 ( $title . $link . $desc . $pubdate );
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   175
      $sec1 = substr($guid, 0, 8);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   176
      $sec2 = substr($guid, 8, 4);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   177
      $sec3 = substr($guid, 12, 4);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   178
      $sec4 = substr($guid, 16, 4);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   179
      $sec5 = substr($guid, 20, 12);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   180
      $guid = sprintf('%s-%s-%s-%s-%s', $sec1, $sec2, $sec3, $sec4, $sec5);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   181
    }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   182
    $xml = "    <item>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   183
      <title>$title</title>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   184
      <link>$link</link>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   185
      <description>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   186
        $desc
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   187
      </description>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   188
      <pubDate>$pubdate</pubDate>
3
f71442e3a95f Renamed plugin file... don't ask me why
Dan
parents: 2
diff changeset
   189
      <guid>$link</guid>
0
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   190
    </item>";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   191
    $this->this_channel['items'][] = $xml;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   192
  }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   193
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   194
  /**
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   195
   * Converts everything into the final RSS feed.
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   196
   * @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
   197
   * @return string
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   198
   */
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   199
  
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   200
  function render($headers = true)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   201
  {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   202
    $xml = '';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   203
    if ( $headers )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   204
      // The weird quotes are because of a jEdit syntax highlighting bug
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   205
      $xml .= "<?xml version=".'"'."1.0".'"'." encoding=".'"'."utf-8".'"'." ?>\n";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   206
    $xml .= "<rss version=".'"'."2.0".'"'.">\n";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   207
    foreach ( $this->channels as $channel )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   208
    {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   209
      $xml .= "  <channel>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   210
    <title>{$channel['title']}</title>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   211
    <link>{$channel['link']}</link>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   212
    <description>{$channel['desc']}</description>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   213
    <generator>{$channel['gen']}</generator>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   214
    <webMaster>{$channel['email']}</webMaster>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   215
    <language>{$channel['lang']}</language>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   216
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   217
";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   218
      $content = implode("\n", $channel['items']) . "\n";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   219
      $xml .= $content;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   220
      $xml .= "  </channel>";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   221
      $xml .= "
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   222
</rss>";
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   223
    }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   224
    return $xml;
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
}
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   228
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   229
// function names are IMPORTANT!!! The name pattern is: page_<namespace ID>_<page URLname, without namespace>
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   230
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
   231
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
   232
{
0
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   233
  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
   234
  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
   235
  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
   236
  $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
   237
  $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
   238
  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
   239
    $session->auth_level = USER_LEVEL_MEMBER;
0
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   240
  $mode = $paths->getParam(0);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   241
  $n = $paths->getParam(1);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   242
  if(!preg_match('#^([0-9]+)$#', $n) || (int)$n > 50) $n = 20;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   243
  else $n = (int)$n;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   244
  switch($mode)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   245
  {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   246
    case "recent":
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   247
      $title = getConfig('site_name') . ' Recent Changes';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   248
      $desc = getConfig('site_desc');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   249
      
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   250
      $rss = new RSS($title, $desc);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   251
      
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   252
      $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
   253
      if(!$q)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   254
      {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   255
        $rss->add_item('ERROR', '', 'Error selecting log data: ' . mysql_error() . '', time());
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   256
      }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   257
      else
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   258
      {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   259
        while($row = $db->fetchrow())
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   260
        {
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
   261
          $link = makeUrlComplete($row['namespace'], $row['page_id'], "oldid={$row['time_id']}"); // makeUrlComplete($row['namespace'], $row['page_id']);
4
308a696fce01 Fixed a few bugs reported by Neal. Removed PHP 4 support.
Dan Fuhry <dan@enanocms.org>
parents: 3
diff changeset
   262
          $title = get_page_title_ns($row['page_id'], $row['namespace']); // $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
   263
          $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
   264
          $desc .= ( $row['edit_summary'] != '' ) ? $row['edit_summary'] : 'No edit summary given.';
0
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   265
          $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
   266
          $guid = false;
0
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   267
          
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   268
          $rss->add_item($title, $link, $desc, $date, $guid);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   269
        }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   270
      }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   271
      
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   272
      echo $rss->render();
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   273
      break;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   274
    case "comments":
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   275
      $title = getConfig('site_name') . ' Latest Comments';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   276
      $desc = getConfig('site_desc');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   277
      
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   278
      $rss = new RSS($title, $desc);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   279
      
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   280
      $q = $db->sql_query('SELECT * FROM '.table_prefix.'comments ORDER BY time DESC LIMIT '.$n.';');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   281
        
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   282
      if(!$q)
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   283
      {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   284
        $rss->add_item('ERROR', '', 'Error selecting log data: ' . mysql_error() . '', time());
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   285
      }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   286
      else
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   287
      {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   288
        $n = $db->numrows();
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   289
        //echo '<!-- Number of rows: '.$n.' -->'; // ."\n<!-- SQL backtrace: \n\n".$db->sql_backtrace().' -->';
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   290
        for ( $j = 0; $j < $n; $j++ )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   291
        {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   292
          $row = $db->fetchrow($q);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   293
          if(!is_array($row)) die(__FILE__.':'.__LINE__.' $row is not an array');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   294
          $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
   295
          $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
   296
          $title = $row['subject'] . ': Posted on page "'.$page.'" by user '.$row['name'];
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   297
          $desc = RenderMan::render($row['comment_data']);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   298
          $date = $row['time'];
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   299
          $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
   300
          
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   301
          $rss->add_item($title, $link, $desc, $date, $guid);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   302
        }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   303
      }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   304
      echo $rss->render();
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   305
      break;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   306
    default:
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   307
      $code = $plugins->setHook('feed_me_request');
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   308
      foreach ( $code as $cmd )
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   309
      {
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   310
        eval($cmd);
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   311
      }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   312
      break;
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   313
  }
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   314
}
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   315
cdf76b0e1aa1 Initial repository population
dan@fuhry
parents:
diff changeset
   316
?>