web/lib/Zend/Feed/Writer/Renderer/Entry/Rss.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    12  * obtain it through the world-wide-web, please send an email
    12  * obtain it through the world-wide-web, please send an email
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Feed_Writer
    16  * @package    Zend_Feed_Writer
    17  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    17  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @version    $Id: Rss.php 22064 2010-04-30 14:02:38Z padraic $
    19  * @version    $Id: Rss.php 24593 2012-01-05 20:35:02Z matthew $
    20  */
    20  */
    21 
    21 
    22 /**
    22 /**
    23  * @see Zend_Feed_Writer_Renderer_RendererAbstract
    23  * @see Zend_Feed_Writer_Renderer_RendererAbstract
    24  */
    24  */
    25 require_once 'Zend/Feed/Writer/Renderer/RendererAbstract.php';
    25 require_once 'Zend/Feed/Writer/Renderer/RendererAbstract.php';
    26 
    26 
    27 /**
    27 /**
    28  * @category   Zend
    28  * @category   Zend
    29  * @package    Zend_Feed_Writer
    29  * @package    Zend_Feed_Writer
    30  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    30  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    31  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    31  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    32  */
    32  */
    33 class Zend_Feed_Writer_Renderer_Entry_Rss
    33 class Zend_Feed_Writer_Renderer_Entry_Rss
    34     extends Zend_Feed_Writer_Renderer_RendererAbstract
    34     extends Zend_Feed_Writer_Renderer_RendererAbstract
    35     implements Zend_Feed_Writer_Renderer_RendererInterface
    35     implements Zend_Feed_Writer_Renderer_RendererInterface
    36 {
    36 {
    37     /**
    37     /**
    38      * Constructor
    38      * Constructor
    39      * 
    39      *
    40      * @param  Zend_Feed_Writer_Entry $container 
    40      * @param  Zend_Feed_Writer_Entry $container
    41      * @return void
    41      * @return void
    42      */
    42      */
    43     public function __construct (Zend_Feed_Writer_Entry $container)
    43     public function __construct (Zend_Feed_Writer_Entry $container)
    44     {
    44     {
    45         parent::__construct($container);
    45         parent::__construct($container);
    46     }
    46     }
    47     
    47 
    48     /**
    48     /**
    49      * Render RSS entry
    49      * Render RSS entry
    50      * 
    50      *
    51      * @return Zend_Feed_Writer_Renderer_Entry_Rss
    51      * @return Zend_Feed_Writer_Renderer_Entry_Rss
    52      */
    52      */
    53     public function render()
    53     public function render()
    54     {
    54     {
    55         $this->_dom = new DOMDocument('1.0', $this->_container->getEncoding());
    55         $this->_dom = new DOMDocument('1.0', $this->_container->getEncoding());
    56         $this->_dom->formatOutput = true;
    56         $this->_dom->formatOutput = true;
    57         $this->_dom->substituteEntities = false;
    57         $this->_dom->substituteEntities = false;
    58         $entry = $this->_dom->createElement('item');
    58         $entry = $this->_dom->createElement('item');
    59         $this->_dom->appendChild($entry);
    59         $this->_dom->appendChild($entry);
    60         
    60 
    61         $this->_setTitle($this->_dom, $entry);
    61         $this->_setTitle($this->_dom, $entry);
    62         $this->_setDescription($this->_dom, $entry);
    62         $this->_setDescription($this->_dom, $entry);
    63         $this->_setDateCreated($this->_dom, $entry);
    63         $this->_setDateCreated($this->_dom, $entry);
    64         $this->_setDateModified($this->_dom, $entry);
    64         $this->_setDateModified($this->_dom, $entry);
    65         $this->_setLink($this->_dom, $entry);
    65         $this->_setLink($this->_dom, $entry);
    75             $ext->render();
    75             $ext->render();
    76         }
    76         }
    77 
    77 
    78         return $this;
    78         return $this;
    79     }
    79     }
    80     
    80 
    81     /**
    81     /**
    82      * Set entry title
    82      * Set entry title
    83      * 
    83      *
    84      * @param  DOMDocument $dom 
    84      * @param  DOMDocument $dom
    85      * @param  DOMElement $root 
    85      * @param  DOMElement $root
    86      * @return void
    86      * @return void
    87      */
    87      */
    88     protected function _setTitle(DOMDocument $dom, DOMElement $root)
    88     protected function _setTitle(DOMDocument $dom, DOMElement $root)
    89     {
    89     {
    90         if(!$this->getDataContainer()->getDescription()
    90         if(!$this->getDataContainer()->getDescription()
   104         $title = $dom->createElement('title');
   104         $title = $dom->createElement('title');
   105         $root->appendChild($title);
   105         $root->appendChild($title);
   106         $text = $dom->createTextNode($this->getDataContainer()->getTitle());
   106         $text = $dom->createTextNode($this->getDataContainer()->getTitle());
   107         $title->appendChild($text);
   107         $title->appendChild($text);
   108     }
   108     }
   109     
   109 
   110     /**
   110     /**
   111      * Set entry description
   111      * Set entry description
   112      * 
   112      *
   113      * @param  DOMDocument $dom 
   113      * @param  DOMDocument $dom
   114      * @param  DOMElement $root 
   114      * @param  DOMElement $root
   115      * @return void
   115      * @return void
   116      */
   116      */
   117     protected function _setDescription(DOMDocument $dom, DOMElement $root)
   117     protected function _setDescription(DOMDocument $dom, DOMElement $root)
   118     {
   118     {
   119         if(!$this->getDataContainer()->getDescription()
   119         if(!$this->getDataContainer()->getDescription()
   137         $subtitle = $dom->createElement('description');
   137         $subtitle = $dom->createElement('description');
   138         $root->appendChild($subtitle);
   138         $root->appendChild($subtitle);
   139         $text = $dom->createCDATASection($this->getDataContainer()->getDescription());
   139         $text = $dom->createCDATASection($this->getDataContainer()->getDescription());
   140         $subtitle->appendChild($text);
   140         $subtitle->appendChild($text);
   141     }
   141     }
   142     
   142 
   143     /**
   143     /**
   144      * Set date entry was last modified
   144      * Set date entry was last modified
   145      * 
   145      *
   146      * @param  DOMDocument $dom 
   146      * @param  DOMDocument $dom
   147      * @param  DOMElement $root 
   147      * @param  DOMElement $root
   148      * @return void
   148      * @return void
   149      */
   149      */
   150     protected function _setDateModified(DOMDocument $dom, DOMElement $root)
   150     protected function _setDateModified(DOMDocument $dom, DOMElement $root)
   151     {
   151     {
   152         if(!$this->getDataContainer()->getDateModified()) {
   152         if(!$this->getDataContainer()->getDateModified()) {
   158         $text = $dom->createTextNode(
   158         $text = $dom->createTextNode(
   159             $this->getDataContainer()->getDateModified()->get(Zend_Date::RSS)
   159             $this->getDataContainer()->getDateModified()->get(Zend_Date::RSS)
   160         );
   160         );
   161         $updated->appendChild($text);
   161         $updated->appendChild($text);
   162     }
   162     }
   163     
   163 
   164     /**
   164     /**
   165      * Set date entry was created
   165      * Set date entry was created
   166      * 
   166      *
   167      * @param  DOMDocument $dom 
   167      * @param  DOMDocument $dom
   168      * @param  DOMElement $root 
   168      * @param  DOMElement $root
   169      * @return void
   169      * @return void
   170      */
   170      */
   171     protected function _setDateCreated(DOMDocument $dom, DOMElement $root)
   171     protected function _setDateCreated(DOMDocument $dom, DOMElement $root)
   172     {
   172     {
   173         if (!$this->getDataContainer()->getDateCreated()) {
   173         if (!$this->getDataContainer()->getDateCreated()) {
   177             $this->getDataContainer()->setDateModified(
   177             $this->getDataContainer()->setDateModified(
   178                 $this->getDataContainer()->getDateCreated()
   178                 $this->getDataContainer()->getDateCreated()
   179             );
   179             );
   180         }
   180         }
   181     }
   181     }
   182     
   182 
   183     /**
   183     /**
   184      * Set entry authors
   184      * Set entry authors
   185      * 
   185      *
   186      * @param  DOMDocument $dom 
   186      * @param  DOMDocument $dom
   187      * @param  DOMElement $root 
   187      * @param  DOMElement $root
   188      * @return void
   188      * @return void
   189      */
   189      */
   190     protected function _setAuthors(DOMDocument $dom, DOMElement $root)
   190     protected function _setAuthors(DOMDocument $dom, DOMElement $root)
   191     {
   191     {
   192         $authors = $this->_container->getAuthors();
   192         $authors = $this->_container->getAuthors();
   202             $text = $dom->createTextNode($name);
   202             $text = $dom->createTextNode($name);
   203             $author->appendChild($text);
   203             $author->appendChild($text);
   204             $root->appendChild($author);
   204             $root->appendChild($author);
   205         }
   205         }
   206     }
   206     }
   207     
   207 
   208     /**
   208     /**
   209      * Set entry enclosure
   209      * Set entry enclosure
   210      * 
   210      *
   211      * @param  DOMDocument $dom 
   211      * @param  DOMDocument $dom
   212      * @param  DOMElement $root 
   212      * @param  DOMElement $root
   213      * @return void
   213      * @return void
   214      */
   214      */
   215     protected function _setEnclosure(DOMDocument $dom, DOMElement $root)
   215     protected function _setEnclosure(DOMDocument $dom, DOMElement $root)
   216     {
   216     {
   217         $data = $this->_container->getEnclosure();
   217         $data = $this->_container->getEnclosure();
   253         $enclosure->setAttribute('type', $data['type']);
   253         $enclosure->setAttribute('type', $data['type']);
   254         $enclosure->setAttribute('length', $data['length']);
   254         $enclosure->setAttribute('length', $data['length']);
   255         $enclosure->setAttribute('url', $data['uri']);
   255         $enclosure->setAttribute('url', $data['uri']);
   256         $root->appendChild($enclosure);
   256         $root->appendChild($enclosure);
   257     }
   257     }
   258     
   258 
   259     /**
   259     /**
   260      * Set link to entry
   260      * Set link to entry
   261      * 
   261      *
   262      * @param  DOMDocument $dom 
   262      * @param  DOMDocument $dom
   263      * @param  DOMElement $root 
   263      * @param  DOMElement $root
   264      * @return void
   264      * @return void
   265      */
   265      */
   266     protected function _setLink(DOMDocument $dom, DOMElement $root)
   266     protected function _setLink(DOMDocument $dom, DOMElement $root)
   267     {
   267     {
   268         if(!$this->getDataContainer()->getLink()) {
   268         if(!$this->getDataContainer()->getLink()) {
   271         $link = $dom->createElement('link');
   271         $link = $dom->createElement('link');
   272         $root->appendChild($link);
   272         $root->appendChild($link);
   273         $text = $dom->createTextNode($this->getDataContainer()->getLink());
   273         $text = $dom->createTextNode($this->getDataContainer()->getLink());
   274         $link->appendChild($text);
   274         $link->appendChild($text);
   275     }
   275     }
   276     
   276 
   277     /**
   277     /**
   278      * Set entry identifier
   278      * Set entry identifier
   279      * 
   279      *
   280      * @param  DOMDocument $dom 
   280      * @param  DOMDocument $dom
   281      * @param  DOMElement $root 
   281      * @param  DOMElement $root
   282      * @return void
   282      * @return void
   283      */
   283      */
   284     protected function _setId(DOMDocument $dom, DOMElement $root)
   284     protected function _setId(DOMDocument $dom, DOMElement $root)
   285     {
   285     {
   286         if(!$this->getDataContainer()->getId()
   286         if(!$this->getDataContainer()->getId()
   298         $id->appendChild($text);
   298         $id->appendChild($text);
   299         if (!Zend_Uri::check($this->getDataContainer()->getId())) {
   299         if (!Zend_Uri::check($this->getDataContainer()->getId())) {
   300             $id->setAttribute('isPermaLink', 'false');
   300             $id->setAttribute('isPermaLink', 'false');
   301         }
   301         }
   302     }
   302     }
   303     
   303 
   304     /**
   304     /**
   305      * Set link to entry comments
   305      * Set link to entry comments
   306      * 
   306      *
   307      * @param  DOMDocument $dom 
   307      * @param  DOMDocument $dom
   308      * @param  DOMElement $root 
   308      * @param  DOMElement $root
   309      * @return void
   309      * @return void
   310      */
   310      */
   311     protected function _setCommentLink(DOMDocument $dom, DOMElement $root)
   311     protected function _setCommentLink(DOMDocument $dom, DOMElement $root)
   312     {
   312     {
   313         $link = $this->getDataContainer()->getCommentLink();
   313         $link = $this->getDataContainer()->getCommentLink();
   317         $clink = $this->_dom->createElement('comments');
   317         $clink = $this->_dom->createElement('comments');
   318         $text = $dom->createTextNode($link);
   318         $text = $dom->createTextNode($link);
   319         $clink->appendChild($text);
   319         $clink->appendChild($text);
   320         $root->appendChild($clink);
   320         $root->appendChild($clink);
   321     }
   321     }
   322     
   322 
   323     /**
   323     /**
   324      * Set entry categories
   324      * Set entry categories
   325      * 
   325      *
   326      * @param DOMDocument $dom 
   326      * @param DOMDocument $dom
   327      * @param DOMElement $root 
   327      * @param DOMElement $root
   328      * @return void
   328      * @return void
   329      */
   329      */
   330     protected function _setCategories(DOMDocument $dom, DOMElement $root)
   330     protected function _setCategories(DOMDocument $dom, DOMElement $root)
   331     {
   331     {
   332         $categories = $this->getDataContainer()->getCategories();
   332         $categories = $this->getDataContainer()->getCategories();