Axiom (v1.2.0)

A lightweight PHP framework
H:/Workspace/php-axiom/www/php-axiom/libraries/axiom/axAtomFeedWriter.class.php
Go to the documentation of this file.
00001 <?php
00019 class axAtomFeedWriter extends axFeedWriter {
00020     
00025     public function __construct (axFeed $feed) {
00026         parent::__construct($feed);
00027         
00028         $this->_atom = $this->appendChild(new DOMElement('feed'));
00029         $this->_atom->setAttribute('xmlns', 'http://www.w3.org/2005/atom');
00030         $this->_atom->setAttribute('xml:lang', $this->_feed->getLang());
00031         
00032         $this->buildFeedInfo();
00033         $this->buildItems();
00034     }
00035     
00039     protected function buildFeedInfo () {
00040         $this->_atom->appendChild(new DOMElement('id', $this->_feed->getId()));
00041         $this->_atom->appendChild(new DOMElement('title', $this->_feed->getTitle()));
00042         $this->_atom->appendChild(new DOMElement('updated', $this->_feed->getDate()));
00043         
00044         if ($link = $this->_feed->getLink()) {
00045             $link_el = $this->_atom->appendChild(new DOMElement('link'));
00046             $link_el->setAttribute('rel', 'alternate');
00047             $link_el->setAttribute('href', $url);
00048         }
00049         
00050         if ($author = $this->_feed->getAuthor()) {
00051             $author_el = $this->_atom->appendChild(new DOMElement('author'));
00052             
00053             if (!empty($author['name']))
00054                 $author_el->appendChild(new DOMElement('name', $author['name']));
00055                 
00056             if (!empty($author['mail']))
00057                 $author_el->appendChild(new DOMElement('email', $author['email']));
00058                 
00059             if (!empty($author['uri']))
00060                 $author_el->appendChild(new DOMElement('uri', $author['uri']));
00061         }
00062     }
00063     
00068     protected function buildItems () {
00069         foreach ($this->_feed->getEntries() as $entry) {
00070             $item = $this->_atom->appendChild(new DOMElement('entry'));
00071             
00072             $item->appendChild(new DOMElement('id', $entry->getId()));
00073             $item->appendChild(new DOMElement('title', $entry->getTitle()));
00074             $item->appendChild(new DOMElement('updated', date('c', strtotime($entry->getDate()))));
00075             
00076             if ($author = $entry->getAuthor()) {
00077                 $author_el = $item->appendChild(new DOMElement('author'));
00078                 
00079                 if (!empty($author['name']))
00080                     $author_el->appendChild(new DOMElement('name', $author['name']));
00081                     
00082                 if (!empty($author['mail']))
00083                     $author_el->appendChild(new DOMElement('email', $author['email']));
00084                     
00085                 if (!empty($author['uri']))
00086                     $author_el->appendChild(new DOMElement('uri', $author['uri']));
00087             }
00088             
00089             if ($content = $entry->getContent()) {
00090                 $content_el = $item->appendChild(new DOMElement('content'));
00091                 $content_el->appendChild(new DOMCdataSection($content));
00092             }
00093             
00094             if ($link = $entry->getLink()) {
00095                 $link_el = $item->appendChild(new DOMElement('link'));
00096                 $link_el->setAttribute($link);
00097             }
00098         }
00099     }
00100 }
 All Data Structures Files Functions Variables