Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00015 final class RssItemWorker extends Singleton implements FeedItemWorker
00016 {
00020 public static function me()
00021 {
00022 return Singleton::getInstance(__CLASS__);
00023 }
00024
00025 public function makeItems(SimpleXMLElement $xmlFeed)
00026 {
00027 $result = array();
00028
00029 if (isset($xmlFeed->channel->item)) {
00030 foreach ($xmlFeed->channel->item as $item) {
00031 $feedItem =
00032 FeedItem::create((string) $item->title)->
00033 setContent(
00034 FeedItemContent::create()->
00035 setBody((string) $item->description)
00036 )->
00037 setPublished(
00038 Timestamp::create(
00039 strtotime((string) $item->pubDate)
00040 )
00041 )->
00042 setLink((string) $item->link);
00043
00044 if (isset($item->guid))
00045 $feedItem->setId($item->guid);
00046
00047 if (isset($item->category))
00048 $feedItem->setCategory((string) $item->category);
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("&", "&", $item->getLink())
00083 .'</link>'
00084 : null
00085 )
00086 .(
00087 $item->getSummary()
00088 ? '<description>'.$item->getSummary().'</description>'
00089 : null
00090 )
00091 .(
00092 $item->getCategory()
00093 ? '<category>'.$item->getCategory().'</category>'
00094 : null
00095 )
00096 .'</item>';
00097 }
00098 }
00099 ?>