RssItemWorker.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2007 by Dmitry A. Lomash, Dmitry E. Demidov             *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: RssItemWorker.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     final class RssItemWorker extends Singleton implements FeedItemWorker
00017     {
00021         public static function me()
00022         {
00023             return Singleton::getInstance(__CLASS__);
00024         }
00025         
00026         public function makeItems(SimpleXMLElement $xmlFeed)
00027         {
00028             $result = array();
00029             
00030             if (isset($xmlFeed->channel->item)) {
00031                 foreach ($xmlFeed->channel->item as $item) {
00032                     $feedItem =
00033                         FeedItem::create((string) $item->title)->
00034                         setContent(
00035                             FeedItemContent::create()->
00036                             setBody((string) $item->description)
00037                         )->
00038                         setPublished(
00039                             Timestamp::create(
00040                                 strtotime((string) $item->pubDate)
00041                             )
00042                         )->
00043                         setLink((string) $item->link);
00044                     
00045                     if (isset($item->guid))
00046                         $feedItem->setId(
00047                             $item->guid
00048                         );                  
00049                     
00050                     $result[] = $feedItem;
00051                 }
00052             }
00053             
00054             return $result;
00055         }
00056         
00057         public function toXml(FeedItem $item)
00058         {
00059             return
00060                 '<item>'
00061                     .(
00062                         $item->getPublished()
00063                             ?
00064                                 '<pubDate>'
00065                                     .date('r', $item->getPublished()->toStamp())
00066                                 .'</pubDate>'
00067                             : null
00068                     )
00069                     .(
00070                         $item->getId()
00071                             ?
00072                                 '<guid isPermaLink="false">'
00073                                     .$item->getId()
00074                                 .'</guid>'
00075                             : null
00076                     )
00077                     .'<title>'.$item->getTitle().'</title>'
00078                     .(
00079                         $item->getLink()
00080                             ?
00081                                 '<link>'
00082                                 .str_replace("&", "&amp;", $item->getLink())
00083                                 .'</link>'
00084                             : null
00085                     )
00086                     .(
00087                         $item->getSummary()
00088                             ? '<description>'.$item->getSummary().'</description>'
00089                             : null
00090                     )
00091                 .'</item>';
00092         }
00093     }
00094 ?>

Generated on Sun Dec 9 21:56:24 2007 for onPHP by  doxygen 1.5.4