<?php
Class Rssgenerator_rss
{
var $rss _version = ' 2.0 ';
var $encoding = ';
var $stylesheet = ';
function CData ($STR)
{
Return ' <! [cdata['. $str. ']]> ';
}
function Createfeed ($channel)
{
$SELFURL = (!isset ($_server[' https ') | | | | $_server[' HTTPS ']!= ' on '? ' http://': ' HTTPS Tutorial://');
$selfUrl. = $_server[' Http_host ']. $_server[' php_self '];
$rss = ' <?xml version= ' 1.0 ';
if (!empty ($this->encoding)) {
$rss. = ' encoding= '. $this->encoding. '"';
}
$rss. = '?> '. " ";
if (!empty ($this->stylesheet)) {
$rss. = $this->stylesheet. " ";
}
$rss. = ' <!--generated on '. Date (' R '). '--> '. " ";
$rss. = ' <rss version= '. $this->rss_version. ' xmlns:atom= ', ' >http://www.w3.org/2005/atom ' > '. " ";
$rss. = ' <channel> '. " ";
$rss. = ' <atom:link href= '. ($channel->atomlinkhref $channel->atomlinkhref: $SELFURL). ' Rel= ' self ' type= ' application/rss+xml '/> '. " ";
$rss. = ' <title> '. $channel->title. ' </title> '. " ";
$rss. = ' <link> '. $channel->link. ' </link> '. " ";
$rss. = ' <description> '. $channel->description. ' </description> '. " ";
if (!empty ($channel->language)) {
$rss. = ' <language> '. $channel->language. ' </language> '. " ";
}
if (!empty ($channel->copyright)) {
$rss. = ' <copyright> '. $channel->copyright. ' </copyright> '. " ";
}
if (!empty ($channel->managingeditor)) {
$rss. = ' <managingEditor> '. $channel->managingeditor. ' </managingEditor> '. " ";
}
if (!empty ($channel->webmaster)) {
$rss. = ' <webMaster> '. $channel->webmaster. ' </webMaster> '. " ";
}
if (!empty ($channel->pubdate)) {
$rss. = ' <pubDate> '. $channel->pubdate. ' </pubDate> '. " ";
}
if (!empty ($channel->lastbuilddate)) {
$rss. = ' <lastBuildDate> '. $channel->lastbuilddate. ' </lastBuildDate> '. " ";
}
foreach ($channel->categories as $category) {
$rss. = ' <category ';
if (!empty ($category [' domain '])) {
$rss. = ' domain= '. $category [' Domain ']. '"';
}
$rss. = ' > '. $category [' name ']. ' </category> '. " ";
}
if (!empty ($channel->generator)) {
$rss. = ' <generator> '. $channel->generator. ' </generator> '. " ";
}
if (!empty ($channel->docs)) {
$rss. = ' <docs> '. $channel->docs. ' </docs> '. " ";
}
if (!empty ($channel->ttl)) {
$rss. = ' <ttl> '. $channel->ttl. ' </ttl> '. " ";
}
if (sizeof ($channel->skiphours)) {
$rss. = ' <skipHours> '. " ";
foreach ($channel->skiphours as $hour) {
$rss. = ' <hour> '. $hour. ' </hour> '. " ";
}
$rss. = ' </skipHours> '. " ";
}
if (sizeof ($channel->skipdays)) {
$rss. = ' <skipDays> '. " ";
foreach ($channel->skipdays as $day) {
$rss. = ' <day> '. $day. ' </day> '. " ";
}
$rss. = ' </skipDays> '. " ";
}
if (!empty ($channel->image)) {
$image = $channel->image;
$rss. = ' <image> '. " ";
$rss. = ' <url> '. $image->url. ' </url> '. " ";
$rss. = ' <title> '. $image->title. ' </title> '. " ";
$rss. = ' <link> '. $image->link. ' </link> '. " ";
if ($image->width) {
$rss. = ' <width> '. $image->width. ' </width> '. " ";
}
if ($image->height) {
$rss. = ' <height> '. $image->height. ' </height> '. " ";
}
if (!empty ($image->description)) {
$rss. = ' <description> '. $image->description. ' </description> '. " ";
}
$rss. = ' </image> '. " ";
}
if (!empty ($channel->textinput)) {
$textInput = $channel->textinput;
$rss. = ' <textInput> '. " ";
$rss. = ' <title> '. $textInput->title. ' </title> '. " ";
$rss. = ' <description> '. $textInput->description. ' </description> '. " ";
$rss. = ' <name> '. $textInput->name. ' </name> '. " ";
$rss. = ' <link> '. $textInput->link. ' </link> '. " ";
$rss. = ' </textInput> '. " ";
}
if (!empty ($channel->cloud_domain) | | |!empty ($channel->cloud_path) | |!empty ($channel->cloud_ Registerprocedure) | | !empty ($channel->cloud_protocol)) {
$rss. = ' <cloud domain= '. $channel->cloud_domain. '" ';
$rss. = ' port= '. $channel->cloud_port. ' "Path=". $channel->cloud_path. '" ';
$rss. = ' registerprocedure= '. $channel->cloud_registerprocedure. '" ';
$rss. = ' protocol= '. $channel->cloud_protocol. ' "/> '." ";
}
if (!empty ($channel->extraxml)) {
$rss. = $channel->extraxml. " ";
}
foreach ($channel->items as $item) {
$rss. = ' <item> '. " ";
if (!empty ($item->title)) {
$rss. = ' <title> '. $item->title. ' </title> '. " ";
}
if (!empty ($item->description)) {
$rss. = ' <description> '. $item->description. ' </description> '. " ";
}
if (!empty ($item->link)) {
$rss. = ' <link> '. $item->link. ' </link> '. " ";
}
if (!empty ($item->pubdate)) {
$rss. = ' <pubDate> '. $item->pubdate. ' </pubDate> '. " ";
}
if (!empty ($item->author)) {
$rss. = ' <author> '. $item->author. ' </author> '. " ";
}
if (!empty ($item->comments)) {
$rss. = ' <comments> '. $item->comments. ' </comments> '. " ";
}
if (!empty ($item->guid)) {
$rss. = ' <guid ispermalink= ';
$rss. = ($item->guid_ispermalink? ' True ': ' false '. ' > ';
$rss. = $item->guid. ' </guid> '. " ";
}
if (!empty ($item->source)) {
$rss. = ' <source url= '. $item->source_url. ' > ';
$rss. = $item->source. ' </source> '. " ";
}
if (!empty ($item->enclosure_url) | | |!empty ($item->enclosure_type)) {
$rss. = ' <enclosure url= '. $item->enclosure_url. '" ';
$rss. = ' length= '. $item->enclosure_length. '" ';
$rss. = ' type= '. $item->enclosure_type. ' "/> '." ";
}
foreach ($item->categories as $category) {
$rss. = ' <category ';
if (!empty ($category [' domain '])) {
$rss. = ' domain= '. $category [' Domain ']. '"';
}
$rss. = ' > '. $category [' name ']. ' </category> '. " ";
}
$rss. = ' </item> '. " ";
}
$rss. = ' </channel> '. " ";
return $rss. = ' </rss> ';
}
}
Class Rssgenerator_channel
{
var $atomLinkHref = ';
var $title = ';
var $link = ';
var $description = ';
var $language = ';
var $copyright = ';
var $managingEditor = ';
var $webMaster = ';
var $pubDate = ';
var $lastBuildDate = ';
var $categories = array ();
var $generator = ';
var $docs = ';
var $ttl = ';
var $image = ';
var $textInput = ';
var $skipHours = array ();
var $skipDays = array ();
var $cloud _domain = ';
var $cloud _port = ' 80 ';
var $cloud _path = ';
var $cloud _registerprocedure = ';
var $cloud _protocol = ';
var $items = array ();
var $extraXML = ';
}
Class Rssgenerator_image
{
var $url = ';
var $title = ';
var $link = ';
var $width = ' 88 ';
var $height = ' 31 ';
var $description = ';
}
Class Rssgenerator_textinput
{
var $title = ';
var $description = ';
var $name = ';
var $link = ';
}
Class Rssgenerator_item
{
var $title = ';
var $description = ';
var $link = ';
var $author = ';
var $pubDate = ';
var $comments = ';
var $guid = ';
var $guid _ispermalink = true;
var $source = ';
var $source _url = ';
var $enclosure _url = ';
var $enclosure _length = ' 0 ';
var $enclosure _type = ';
var $categories = array ();
}
?>
Instance
<?php
Require_once ' rss_generator.inc.php ';
$rss _channel = new Rssgenerator_channel ();
$rss _channel->atomlinkhref = ';
$rss _channel->title = ' my News ';
$rss _channel->link = ' http://111cn.net tutorial/news.php ';
$rss _channel->description = ' The latest news about Web-development. '
$rss _channel->language = ' en-US ';
$rss _channel->generator = ' PHP rss feed generator ';
$rss _channel->managingeditor = ' editor@mysite.com (Alex Jefferson) ';
$rss _channel->webmaster = ' webmaster@mysite.com (Vagharshak Tozalakyan) ';
$item = new Rssgenerator_item ();
$item->title = ' New website launched ';
$item->description = ' Today I finaly launch a new website. '
$item->link = ' http://111cn.net ';
$item->guid = ' http://111cn.net ';
$item->pubdate = ' Tue, 2006 00:00:01 GMT ';
$rss _channel->items[] = $item;
$item = new Rssgenerator_item ();
$item->title = ' Another website launched ';
$item->description = ' Just another website launched. '
$item->link = ' http://111cn.net ';
$item->guid = ' http://111cn.net ';
$item->pubdate = ' Wed, 2006 00:00:01 GMT ';
$rss _channel->items[] = $item;
$rss _feed = new Rssgenerator_rss ();
$rss _feed->encoding = ' UTF-8 ';
$rss _feed->version = ' 2.0 ';
Header (' Content-type:text/xml ');
echo $rss _feed->createfeed ($rss _channel);
?>