<?php
/*
step:   $rss = new RSS($title,$link,$description);   $rss->AddItem($title, $link, $description ,$pubDate)
   .
   .
   .
   .
   $rss->SaveToFile($fname);*/
if (defined('_CLASS_RSS_PHP')) return;
define('_CLASS_RSS_PHP',1);class RSS {
   //public
   var $rss_ver = '2.0';
   var $channel_title = '';
   var $channel_link = '';
   var $channel_description = '';
   var $language = 'EN';
   var $copyright = '';
   var $webMaster = '';
   var $pubDate = '';
   var $lastBuildDate = '';
   var $generator = 'Sothink Latest Flash templates';   var $content = '';
   var $items = array();   function RSS($title, $link, $description) {
       $this->channel_title = $title;
       $this->channel_link = $link;
       $this->channel_description = $description;
       $this->pubDate = Date('Y-m-d H:i:s',time());
       $this->lastBuildDate = Date('Y-m-d H:i:s',time());
   }   function AddItem($title, $link, $description ,$pubDate) {
       $this->items[] = array('title' => $title ,
                        'link' => $link,
                        'description' => $description,
                        'pubDate' => $pubDate);
   }   function BuildRSS() {
       $s = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<rss version=\"2.0\"> \n";
       // start channel
       $s .= "<channel>\n";
       $s .= "<title>{$this->channel_title}</title>\n";
       $s .= "<link>{$this->channel_link}</link>\n";
       $s .= "<description>{$this->channel_description}</description>\n";
       $s .= "<language>{$this->language}</language>\n";
       if (!empty($this->copyright)) {
          $s .= "<copyright>{$this->copyright}</copyright>\n";
       }
       if (!empty($this->webMaster)) {
          $s .= "<webMaster>{$this->webMaster}</webMaster>\n";
       }
       if (!empty($this->pubDate)) {
          $s .= "<pubDate>{$this->pubDate}</pubDate>\n";
       }       if (!empty($this->lastBuildDate)) {
          $s .= "<lastBuildDate>{$this->lastBuildDate}</lastBuildDate>\n";
       }       if (!empty($this->generator)) {
          $s .= "<generator>{$this->generator}</generator>\n";
       }
      
       // start items
       for ($i=0;$i<count($this->items);$i++) {
           $s .= "<item>\n";
           $s .= "<title>{$this->items[$i]['title']}</title>\n";
           $s .= "<link>{$this->items[$i]['link']}</link>\n";
           $s .= "<description><![CDATA[{$this->items[$i]['description']}]]></description>\n";
           $s .= "<pubDate>{$this->items[$i]['pubDate']}</pubDate>\n";          
           $s .= "</item>\n";
       }
     
      // close channel
      $s .= "</channel>\n</rss>";
      $this->content = $s;
   }   function Show() {
       if (empty($this->content)) $this->BuildRSS();
       header('Content-type:text/xml');
       echo($this->content);
   }   function SaveToFile($fname) {
       if (empty($this->content)) $this->BuildRSS();
       $handle = fopen($fname, 'wb');
       if ($handle === false)  return false;
       fwrite($handle, $this->content);
       fclose($handle);
   }
}?>