(root)/feed-creator.php - Rev 398
Rev 396 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
<?PHP
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This file is part of Travelsized CMS
* A content management system with modules, based on wiki syntax
*
* Author: Dan Jensen <admin@leinir.dk>
* Copyright 2003/2004
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License is available at: http://www.gnu.org/copyleft/
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* The Feed class describes a site syndication feed. A type can be specified to
* show which type of feed to render (RSS2 is default)
*/
class Feed
{
var $type; ///< @var The type of feed to use. Defaults to RSS2
var $items; ///< @var The items contained in the feed
var $title; ///< @var The feed's title
var $link; ///< @var Link to the page which the feed syndicates
var $description; ///< @var A short description of the page being syndicated
var $pubDate; ///< @var The date the feed was published
var $generator; ///< @var The generator for this page. Defaults to Travelsized Feeds
/**
* Constructor a new instance of the Feed class
*
* @param title The title of the page the feed syndicates
* @param link The URL of the syndicated page
* @param description A short description of the syndicated page
* @param pubDate The date this feed was last published (this should probably be the date of the most recent entry)
* @param generator The name of the feed's generator. Defaults to Travelsized Feeds
* @param type The type of feed to generate. Defaults to RSS2
*
* @return A new instance of the Feed class
*/
function Feed
( $title, $link, $description, $pubDate, $generator = null, $type = null )
{
$this->title = $title;
$this->link = $link;
$this->description = $description;
$this->pubDate = $pubDate;
$this->generator = ( $generator == null ) ?
"Travelsized Feeds" : $generator;
$this->type = ( $type == null ) ?
"RSS2" : $type;
$this->items = array();
$this->itemCount = 0;
}
/**
* Adds a new item to the feed
*
* @param feedItem The item to add to the feed (instance of FeedItem)
*/
function addItem
( $feedItem )
{
$this->items[] = $feedItem;
}
/**
* Renders the feed
*
* @param type Set a new type and render using that
*
* @return The rendered feed according to the set type
*/
function render
( $type = null )
{
if( $type != null )
$this->type = $type;
$rendererType = "FeedRenderer" . $this->type;
$renderer = new $rendererType( $this );
$renderedContent = $renderer->renderHead( $this );
foreach( $this->items as $key => $item )
$renderedContent .= $renderer->renderItem( $item );
$renderedContent .= $renderer->renderFoot( $this );
return $renderedContent;
}
}
/**
* The FeedItem class describes a single item in a syndication Feed
*/
class FeedItem
{
var $title; ///< @var The item's title
var $link; ///< @var The URL of this item
var $description; ///< @var A short description of this item
var $pubDate; ///< @var The date of this item's publishing
var $guid; ///< @var A globally identifying ID for this item (likely also a URL)
/**
* Create a new FeedItem instance
*
* @param title The item's title
* @param link The URL of this item
* @param description A short description of this item
* @param pubDate The date of this item's publishing
* @param guid A globally identifying ID for this item (likely also a URL)
*/
function FeedItem
( $title, $link, $description, $pubDate, $guid )
{
$this->title = $title;
$this->link = $link;
$this->description = $description;
$this->pubDate = $pubDate;
$this->guid = $guid;
}
}
/**
* The RSS2 renderer for the Feed class
*/
class FeedRendererRSS2
{
/**
* Creates a new instance of the FeedRendererRSS2 class
*/
function FeedRendererRSS2
() {}
/**
* Render the head of a specified Feed instance
*
* @param feed The Feed instance to render the header for
*
* @return A string containing the rendered header
*/
function renderHead
( $feed )
{
$renderedContent = "<?xml version=\"1.0\"?>
<rss version=\"2.0\">
<channel>
<title>" . $feed->title . "</title>
<link>" . $feed->link . "</link>
<description>" . $feed->description . "</description>
<pubDate>" . date( "r", $feed->pubDate ) . "</pubDate>
<generator>" . $feed->generator . "</generator>";
return $renderedContent;
}
/**
* Render a FeedItem into text
*
* @param feedItem The FeedItem instance to work with
*
* @return A string containing the rendered item
*/
function renderItem
( $feedItem )
{
$renderedContent = "
<item>
<title>" . $feedItem->title . "</title>
<link>" . $feedItem->link . "</link>
<description>" . $feedItem->description . "</description>
<pubDate>" . date( "r", $feed->pubDate ) . "</pubDate>
<guid>" . $feedItem->guid . "</guid>
</item>";
return $renderedContent;
}
/**
* Render the foot of a specified Feed instance
*
* @param feed The Feed instance to render the footer for
*
* @return A string containing the rendered footer
*/
function renderFoot
( $feed )
{
$renderedContent = "
</channel>
</rss>";
return $renderedContent;
}
}
?>