File indexing completed on 2025-03-02 05:29:21

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_Reader
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_Reader_Extension_EntryAbstract
0024  */
0025 // require_once 'Zend/Feed/Reader/Extension/EntryAbstract.php';
0026 
0027 /**
0028  * @see Zend_Feed_Reader_Extension_CreativeCommons_Feed
0029  */
0030 // require_once 'Zend/Feed/Reader/Extension/CreativeCommons/Feed.php';
0031 
0032 /**
0033  * @category   Zend
0034  * @package    Zend_Feed_Reader
0035  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0036  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0037  */
0038 class Zend_Feed_Reader_Extension_CreativeCommons_Entry extends Zend_Feed_Reader_Extension_EntryAbstract
0039 {
0040     /**
0041      * Get the entry license
0042      *
0043      * @return string|null
0044      */
0045     public function getLicense($index = 0)
0046     {
0047         $licenses = $this->getLicenses();
0048 
0049         if (isset($licenses[$index])) {
0050             return $licenses[$index];
0051         }
0052 
0053         return null;
0054     }
0055 
0056     /**
0057      * Get the entry licenses
0058      *
0059      * @return array
0060      */
0061     public function getLicenses()
0062     {
0063         $name = 'licenses';
0064         if (array_key_exists($name, $this->_data)) {
0065             return $this->_data[$name];
0066         }
0067 
0068         $licenses = array();
0069         $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//cc:license');
0070 
0071         if ($list->length) {
0072             foreach ($list as $license) {
0073                     $licenses[] = $license->nodeValue;
0074             }
0075 
0076             $licenses = array_unique($licenses);
0077         } else {
0078             $cc = new Zend_Feed_Reader_Extension_CreativeCommons_Feed(
0079                 $this->_domDocument, $this->_data['type'], $this->_xpath
0080             );
0081             $licenses = $cc->getLicenses();
0082         }
0083 
0084         $this->_data[$name] = $licenses;
0085 
0086         return $this->_data[$name];
0087     }
0088 
0089     /**
0090      * Register Creative Commons namespaces
0091      *
0092      */
0093     protected function _registerNamespaces()
0094     {
0095         $this->_xpath->registerNamespace('cc', 'http://backend.userland.com/creativeCommonsRssModule');
0096     }
0097 }