File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/api/class.rsscreator.php
<?php
/**
* This file contains the iwp_rsscreator class
*
* @version $Id$
*
*
* @package IWP
* @subpackage IWP_API
*/
/**
* IWP RSS Creator Class
* This class wrates the use of xml writer to make creating RSS feeds easy
*
* @package IWP
* @subpackage IWP_API
*/
class iwp_rsscreator {
/**
* Whether or not the feed should make use of the itunes namespace
*
* @var boolean
*/
private $podcast = false;
/**
* A member variable to hold the value of the instance of XML Writer for creating the feed
*
* @var iwp_xmlwriter
*/
private $xml = null;
/**
* The list of itunes namespace tags to be used and their values
*
* @var array
*/
private $podcastVars = array('author'=>'', 'summary'=>'', 'keywords'=>'', 'explicit'=>'no');
/**
* Intializes class and sets up the xml writer object
*
* @param boolean $podcast True if the RSS feed includes podcast elements and should use the itunes namespace
*
* @return void
*/
public function __construct($podcast = false){
if(is_bool($podcast)){
$this->podcast = $podcast;
}
$this->xml = new iwp_xmlwriter(false);
}
/**
* Sets a itunes namespace tag's value
*
* @param string $name The name of the tag to set
* @param string $val The value of the tag to set
*
* @return void
*/
public function SetPodcastVar($name, $val){
if(isset($this->podcastVars[$name])){
$this->podcastVars[$name] = $val;
}
}
/**
* Starts the RSS feed with the beginning elements and the root tag.
*
* @param string $title The name/title of the RSS feed/website
* @param string $link The URL to the main website
*
* @return void
*/
public function StartRSS($title, $link, $desc=''){
$this->xml->startElement('rss');
if($this->podcast){
$this->xml->writeAttribute('xmlns:itunes', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
}
$this->xml->writeAttribute('version', '2.0');
$this->xml->startElement('channel');
$this->xml->startElement('title');
$this->xml->writeCData($title);
$this->xml->endElement(); // title
$this->xml->writeElement('link', $link);
$this->xml->startElement('description');
$this->xml->writeCData(strip_tags($desc));
$this->xml->endElement(); // description
$this->xml->writeElement('language', 'en-us');
$this->xml->writeElement('copyright', $link);
$this->xml->writeElement('generator', 'Content Manager');
$this->xml->writeElement('lastBuildDate', date("D, d M Y H:i:s T"));
$this->xml->writeElement('ttl', '20');
if($this->podcast){
$this->xml->writeElement('itunes:author', $this->podcastVars['author']);
$this->xml->writeElement('itunes:summary', $this->podcastVars['summary']);
$this->xml->writeElement('itunes:keywords', $this->podcastVars['keywords']);
$this->xml->writeElement('itunes:explicit', $this->podcastVars['explicit']);
}
}
/**
* Finishes off an RSS feed by closing the channel and root tags and outputting or returning the resulting XML
*
* @param boolean $output True to output the XML directory and die, or false to return the XML as a string
*
* @return mixed Void if the output param is true, string of XML otherwise
*/
public function EndRSS($output=true){
$this->xml->endElement(); // channel
$this->xml->endElement(); // rss
ob_start();
$this->xml->outputXML(true);
$contents = ob_get_contents();
ob_end_clean();
if($output){
echo $contents;
die();
}
return $contents;
}
/**
* Adds an item to the RSS feed.
*
* @param array $data An array of elements for the item. Must include: title, link, description, author, lastBuildDate and any itunes data
*
* @return void
*/
public function AddItem($data){
$this->xml->startElement('item');
$this->xml->startElement('title');
$this->xml->writeCData($data['title']);
$this->xml->endElement(); // title
$this->xml->writeElement('link', $data['link']);
$this->xml->startElement('description');
$this->xml->writeCData($data['description']);
$this->xml->endElement(); // description
$this->xml->writeElement('author','no@spam.com ('.trim($data['author']).')');
if(!is_int($data['lastBuildDate'])){
$data['lastBuildDate'] = strtotime($data['lastBuildDate']);
}
$this->xml->writeElement('lastBuildDate', date("D, d M Y H:i:s T", $data['lastBuildDate'] ));
$this->xml->startElement('guid');
$this->xml->writeAttribute('isPermaLink', 'true');
$this->xml->text($data['link']);
$this->xml->endElement(); // guid
if($this->podcast){
$this->xml->startElement('itunes:summary');
$this->xml->writeCData($data['itunes_summary']);
$this->xml->endElement(); // description
$this->xml->writeElement('itunes:author',$data['itunes_author']);
}
if($data['enclosure']){
$this->xml->startElement('enclosure');
$this->xml->writeAttribute('url', $data['enclosure_url']);
$this->xml->writeAttribute('length', filesize($data['enclosure_path']));
if(function_exists('mime_content_type')){
$filemime = mime_content_type($data['enclosure_path']);
}else{
$filemime = "audio/mpeg";
}
$this->xml->writeAttribute('type', $filemime);
$this->xml->endElement(); // enclosure
}
$this->xml->endElement(); // item
}
}