# AtomItemWorker.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
    00015     final class AtomItemWorker 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             foreach ($xmlFeed->entry as $entry) {
    00030                 $feedItem = FeedItem::create((string) $entry->title);
    00031
    00032                 if (isset($entry->content))
    00033                     $feedItem->setContent(
    00034                         $this->makeFeedItemContent(
    00035                             $entry->content
    00036                         )
    00037                     );
    00038
    00039                 if (isset($entry->summary))
    00040                     $feedItem->setSummary(
    00041                         $this->makeFeedItemContent(
    00042                             $entry->summary
    00043                         )
    00044                     );
    00045
    00046                 if (isset($entry->id))
    00047                     $feedItem->setId(
    00048                         $entry->id
    00049                     );
    00050
    00051                 $result[] =
    00052                     $feedItem->setPublished(
    00053                         Timestamp::create(
    00054                             strtotime((string) $entry->updated)
    00055                         )
    00056                     )->
    00057                     setLink((string) $entry->link);
    00058             }
    00059
    00060             return $result;
    00061         }
    00062
    00063         public function toXml(FeedItem $item)
    00064         {
    00065             throw new UnimplementedFeatureException('implement me!');
    00066         }
    00067
    00068         private function makeFeedItemContent($content)
    00069         {
    00070             $feedItemContent = FeedItemContent::create();
    00071
    00072             if (isset($content->attributes()->type)) {
    00073                 switch ((string) $content->attributes()->type) {
    00074
    00075                     case 'text':
    00076
    00077                         $feedItemContent->
    00078                             setType(
    00079                                 new FeedItemContentType(
    00080                                     FeedItemContentType::TEXT
    00081                                 )
    00082                             );
    00083
    00084                         break;
    00085
    00086                     case 'html':
    00087
    00088                         $feedItemContent->
    00089                             setType(
    00090                                 new FeedItemContentType(
    00091                                     FeedItemContentType::HTML
    00092                                 )
    00093                             );
    00094
    00095                         break;
    00096
    00097                     case 'xhtml':
    00098
    00099                         $feedItemContent->
    00100                             setType(
    00101                                 new FeedItemContentType(
    00102                                     FeedItemContentType::XHTML
    00103                                 )
    00104                             );
    00105
    00106                         break;
    00107                 }
    00108             }
    00109
    00110             return $feedItemContent->setBody((string) $content);
    00111         }
    00112     }
    00113 ?>