title=$sTitle; $this->link=$slink; $this->description=$sDescription; $this->author=''; $this->category=''; $this->comments=''; //$this->enclosure=''; not yet supported $this->guid=''; $this->pubDate=''; //$this->source=''; not yet supported } function setAuthor($sEmail,$sName) { $this->author="$sEmail ($sName)"; } function setCategory($sCategory) { $this->category=$sCategory; } function setComments($sComments) { $this->comments=$sComments; } function setGuid($sGuid) { $this->guid=$sGuid; } function setPubDate($sPubDate) { $dt=date("D, j M Y H:i:s T",strtotime($sPubDate)); $this->pubDate=$dt; } function getAsString() { $ret=''; $ret.="\n"; $ret.=''.encodexmlchars($this->title).''."\n"; $ret.=''.encodexmlchars($this->link).''."\n"; $ret.=''.encodexmlchars($this->description).''."\n"; if($this->author!='') { $ret.=''.encodexmlchars($this->author).''."\n"; } if($this->category!='') { $ret.=''.encodexmlchars($this->category).''."\n"; } if($this->comments!='') { $ret.=''.encodexmlchars($this->comments).''."\n"; } if($this->guid!='') { $ret.=''.encodexmlchars($this->guid).''."\n"; } if($this->pubDate!='') { $ret.=''.encodexmlchars($this->pubDate).''."\n"; } $ret.="\n"; return $ret; } } class RSS2Writer { // Mandatory items var $title; var $link; var $description; // Optional items var $language; var $copyright; var $managingEditor; var $webMaster; var $pubDate; var $lastBuildDate; var $category; // Partially supported var $generator; var $docs; // var $cloud var $ttl=''; var $image; // var $rating=''; // var $textinput; // var $skipHours // var $skipDays // Items list var $items; function RSS2Writer($sTitle,$sLink,$sDescription) { $this->title=$sTitle;; $this->link=$sLink; $this->description=$sDescription; // Optional items $this->language=''; $this->copyright=''; $this->managingEditor=''; $this->webMaster=''; $this->pubDate=''; $this->lastBuildDate=''; $this->category=''; $this->generator='RSS2Writer PHP class by Maurizio Giunti http://www.mauriziogiunti.it'; $this->docs=''; $this->ttl=''; // Reset image and items $this->image=array(); $this->items=array(); } function setLanguage($sLanguage) { $this->language=$sLanguage; } function setCopyright($sCopyright) { $this->copyright=$sCopyright; } function setManagingEditor($sEmail,$sName) { $this->managingEditor="$sEmail ($sName)"; } function setWebMaster($sEmail,$sName) { $this->webMaster="$sEmail ($sName)"; } function setPubDate($sPubDate) { $dt=date("D, j M Y H:i:s T",strtotime($sPubDate)); $this->pubDate=$dt; } function setLastBuildDate($sLastBuildDate) { $dt=date("D, j M Y H:i:s T",strtotime($sLastBuildDate)); $this->lastBuildDate=$dt; } function setCategory($sCategory) { $this->category=$sCategory; } function setGenerator($sGenerator) { $this->generator=$sGenerator; } function setDocs($sDocs) { $this->docs=$sDocs; } function setTtl($sTtl) { $this->ttl=$sTtl; } function setImage($url,$title,$link,$width,$height) { $img['url']=$url; $img['title']=$title; $img['link']=$link; if($width>0) { $img['width']=$width; } if($height>0) { $img['height']=$height; } $this->image=$img; } function addItem($rss2item) { $this->items[]=$rss2item; } function getHeaderAsString() { $ret=''; $ret.=''."\n"; $ret.=''."\n"; $ret.=''."\n"; $ret.=''.encodexmlchars($this->title).''."\n"; $ret.=''.encodexmlchars($this->link).''."\n"; $ret.=''.encodexmlchars($this->description).''."\n"; if($this->language!='') { $ret.=''.encodexmlchars($this->language).''."\n"; } if($this->copyright!='') { $ret.=''.encodexmlchars($this->copyright).''."\n"; } if($this->managingEditor !='') { $ret.=''.encodexmlchars($this->managingEditor).''."\n"; } if($this->webMaster !='') { $ret.=''.encodexmlchars($this->webMaster).''."\n"; } if($this->pubDate !='') { $ret.=''.encodexmlchars($this->pubDate).''."\n"; } if($this->lastBuildDate !='') { $ret.=''.encodexmlchars($this->lastBuildDate).''."\n"; } if($this->category !='') { $ret.=''.encodexmlchars($this->category).''."\n"; } if($this->generator !='') { $ret.=''.encodexmlchars($this->generator).''."\n"; } if($this->docs !='') { $ret.=''.encodexmlchars($this->docs).''."\n"; } if($this->ttl !='') { $ret.=''.encodexmlchars($this->ttl).''."\n"; } // Feed image if(count($this->image)>0) { $img=$this->image; $ret.=''."\n"; $ret.=''.encodexmlchars($img['url']).''."\n"; $ret.=''.encodexmlchars($img['title']).''."\n"; $ret.=''.encodexmlchars($img['link']).''."\n"; if($img['width']>0) { $ret.=''.encodexmlchars($img['width']).''."\n"; } if($img['height']>0) { $ret.=''.encodexmlchars($img['height']).''."\n"; } $ret.=''."\n"; } return $ret; } function getFooterAsString() { $ret=''; $ret.=''."\n"; $ret.=''."\n"; return $ret; } function getAsString() { $ret=''; $ret.=$this->getHeaderAsString(); // Items foreach($this->items as $item) { $ret.=$item->getAsString(); } $ret.=$this->getFooterAsString(); return $ret; } function doPrint() { print $this->getHeaderAsString(); // Items foreach($this->items as $item) { print $item->getAsString(); } print $this->getFooterAsString(); } } /* Common method to encode special XML chars */ function encodexmlchars($str) { $str=str_replace('&','&',$str); $str=str_replace('<','<',$str); $str=str_replace('>','>',$str); $str=str_replace('"','"',$str); $str=str_replace("'",''',$str); return $str; } ?>