*/
class rss {
private $header;
private $footer;
private $item;
private $inputEncoding;
/**
* @param string $title RSS title
* @param string $link RSS link
* @param string $description RSS description
* @param string $additional optional channel additions
* @param string $inputEncoding optional encoding of input strings
*/
public function __construct($title, $link, $description, $additional = '', $inputEncoding = 'ISO-8859-1') {
$scriptURL = ($_SERVER["HTTPS"] == "on") ? "https" : "http";
$scriptURL .= "://" . $_SERVER["HTTP_HOST"] . $_SERVER["SCRIPT_NAME"];
$this->header = '<' . '?xml version="1.0" encoding="utf-8"?' . ">\n\n";
$this->header .= '' . "\n";
$this->header .= "\n";
$this->header .= "" . $title . "\n";
$this->header .= "" . $link . "\n";
$this->header .= "" . $description . "\n";
$this->header .= ($additional != "") ? $additional . "\n" : ''; # optional
$this->header .= "" . date("r") . "\n"; # optional
$this->header .= '' . "\n"; # optional
$this->footer = "\n";
$this->inputEncoding = $inputEncoding;
}
/**
* Use this function, to sanitize markup or other things that would brick xml.
*
* @param string $markup
* @return string sanitized markup
*/
public function cData($markup) {
$cd = ''; // CDATA stop
$markup = str_ireplace(array($cd, $dc), "", $markup);
return $cd . $markup . $dc;
}
/**
* Add item to RSS feed
*
* @param string $title item title
* @param string $link item link
* @param string $description item description
* @param string $date item date as unix timestamp
* @param string $additional optional item additions
*/
public function item($title, $link, $description, $date, $additional = '') {
$item = "- \n";
$item .= "" . $title . "\n"; # optional
$item .= "" . $description . "\n";
$item .= "" . $link . "\n"; # optional
$item .= "" . date("r", $date) . "\n"; # optional
$item .= "" . $link . "\n"; # optional
$item .= ($additional != "") ? $additional. "\n" : ''; # optional
$item .= "
\n";
$this->item[] = $item;
}
/**
* Get generated RSS feed
*
* @return string UTF-8 encoded RSS feed
*/
public function get() {
foreach ($this->item as $item) {
$items .= $item;
}
return iconv($this->inputEncoding, "UTF-8//IGNORE", $this->header . $items . $this->footer);
}
/**
* Output generated RSS feed
*/
public function output() {
header("Content-Type: text/xml;charset=utf-8");
echo $this->get();
}
}