File indexing completed on 2025-05-04 05:32:29

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Feed_Writer
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  * @version    $Id$
0020  */
0021 
0022 /**
0023  * @see Zend_Feed_Writer_Extension_RendererAbstract
0024  */
0025 // require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php';
0026 
0027 /**
0028  * @category   Zend
0029  * @package    Zend_Feed_Writer
0030  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0031  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0032  */
0033 class Zend_Feed_Writer_Extension_Threading_Renderer_Entry
0034     extends Zend_Feed_Writer_Extension_RendererAbstract
0035 {
0036 
0037     /**
0038      * Set to TRUE if a rendering method actually renders something. This
0039      * is used to prevent premature appending of a XML namespace declaration
0040      * until an element which requires it is actually appended.
0041      *
0042      * @var bool
0043      */
0044     protected $_called = false;
0045 
0046     /**
0047      * Render entry
0048      *
0049      * @return void
0050      */
0051     public function render()
0052     {
0053         if (strtolower($this->getType()) == 'rss') {
0054             return; // Atom 1.0 only
0055         }
0056         $this->_setCommentLink($this->_dom, $this->_base);
0057         $this->_setCommentFeedLinks($this->_dom, $this->_base);
0058         $this->_setCommentCount($this->_dom, $this->_base);
0059         if ($this->_called) {
0060             $this->_appendNamespaces();
0061         }
0062     }
0063 
0064     /**
0065      * Append entry namespaces
0066      *
0067      * @return void
0068      */
0069     protected function _appendNamespaces()
0070     {
0071         $this->getRootElement()->setAttribute('xmlns:thr',
0072             'http://purl.org/syndication/thread/1.0');
0073     }
0074 
0075     /**
0076      * Set comment link
0077      *
0078      * @param  DOMDocument $dom
0079      * @param  DOMElement $root
0080      * @return void
0081      */
0082     protected function _setCommentLink(DOMDocument $dom, DOMElement $root)
0083     {
0084         $link = $this->getDataContainer()->getCommentLink();
0085         if (!$link) {
0086             return;
0087         }
0088         $clink = $this->_dom->createElement('link');
0089         $clink->setAttribute('rel', 'replies');
0090         $clink->setAttribute('type', 'text/html');
0091         $clink->setAttribute('href', $link);
0092         $count = $this->getDataContainer()->getCommentCount();
0093         if ($count !== null) {
0094             $clink->setAttribute('thr:count', $count);
0095         }
0096         $root->appendChild($clink);
0097         $this->_called = true;
0098     }
0099 
0100     /**
0101      * Set comment feed links
0102      *
0103      * @param  DOMDocument $dom
0104      * @param  DOMElement $root
0105      * @return void
0106      */
0107     protected function _setCommentFeedLinks(DOMDocument $dom, DOMElement $root)
0108     {
0109         $links = $this->getDataContainer()->getCommentFeedLinks();
0110         if (!$links || empty($links)) {
0111             return;
0112         }
0113         foreach ($links as $link) {
0114             $flink = $this->_dom->createElement('link');
0115             $flink->setAttribute('rel', 'replies');
0116             $flink->setAttribute('type', 'application/'. $link['type'] .'+xml');
0117             $flink->setAttribute('href', $link['uri']);
0118             $count = $this->getDataContainer()->getCommentCount();
0119             if ($count !== null) {
0120                 $flink->setAttribute('thr:count', $count);
0121             }
0122             $root->appendChild($flink);
0123             $this->_called = true;
0124         }
0125     }
0126 
0127     /**
0128      * Set entry comment count
0129      *
0130      * @param  DOMDocument $dom
0131      * @param  DOMElement $root
0132      * @return void
0133      */
0134     protected function _setCommentCount(DOMDocument $dom, DOMElement $root)
0135     {
0136         $count = $this->getDataContainer()->getCommentCount();
0137         if ($count === null) {
0138             return;
0139         }
0140         $tcount = $this->_dom->createElement('thr:total');
0141         $tcount->nodeValue = $count;
0142         $root->appendChild($tcount);
0143         $this->_called = true;
0144     }
0145 }