All pastes #804122 Raw Edit

Anonymous

public php v1 · immutable
·published 2007-12-03 03:29 UTC
rendered paste body
### FeedWriter.php<?phprequire_once 'FeedWriterItem.php';require_once 'FeedWriterTitle.php';abstract class FeedWriter {    /**     * Write feed. Needs subclass to work.     *     * @param Array of FeedWriter Item instances     * @param FeedWriterTitle instance     */    public function main(&$arrItems, &$title) {        // Send headers        if (headers_sent() === false) {            header("Last-Modified: " . date("D, M j Y G:i:s O", $title->lastUpdated));            $this->sendHeader();        }          $this->printTitle($title);          foreach($arrItems as $item) {            $this->printItem($item);        }          $this->printEnd();    }      protected function sendHeader() {        header("Content-Type: text/xml");    }      abstract protected function printItem($item);      abstract protected function printTitle($title);      abstract protected function printEnd();}### FeedWriterItem.php <?php  /*** Simple Date Structure holding feed item data*/class FeedWriterItem {  public $description = '';  public $title = '';  public $link = '';  public $pubDate = ''; // this is a date, no string!  public $guid = '';  public $author = '';  public $content = '';}### FeedWriterRssWriter.php <?phprequire_once 'FeedWriter.php';class FeedWriterRssWriter extends FeedWriter {      protected function sendHeader() {        header("Content-Type: text/xml");    }      protected function printItem($item) {        ?>  <item>    <title><?php print $item->title; ?></title>    <link><?php print $item->link; ?></link>    <description><?php print $item->description; ?></description>    <content:encoded><?php print $item->content; ?></content:encoded>    <pubDate><?php print date(DATE_RFC822, $item->pubDate); ?></pubDate>    <guid isPermaLink="true"><?php print $item->guid; ?></guid>    <author><?php print $item->author; ?></author>  </item>  <?php    }      protected function printTitle($title) {        print '<?xml version="1.0" encoding="' . $title->encoding . '"?>';  ?>  <rss version="2.0"    xmlns:content="http://purl.org/rss/1.0/modules/content/"    xmlns:wfw="http://wellformedweb.org/CommentAPI/"  >  <channel>    <title><?php print $title->title; ?></title>    <link><?php print $title->link; ?></link>    <description><?php print $title->description; ?></description>    <language>de</language>    <pubDate><?php print date(DATE_RFC822, $title->lastUpdated); ?></pubDate>    <generator><?php print $title->generator; ?></generator>    <image>      <title><?php print $title->title; ?></title>      <link><?php print $title->link; ?></link>      <url><?php print $title->imageURL; ?></url>    </image>  <?php    }      protected function printEnd() {  ?>  </channel>  </rss>  <?php    }}### FeedWriterTitle.php <?php  /** * Simple Date Structure holding feed data */class FeedWriterTitle {    public $title = '';    public $lastUpdated = ''; // this is a date, no string!    public $description = '';    public $link = '';    public $imageURL = '';    public $generator = '';    public $encoding = 'Utf-8';}