web/Zend/Feed/Reader/Extension/CreativeCommons/Feed.php
changeset 0 4eba9c11703f
equal deleted inserted replaced
-1:000000000000 0:4eba9c11703f
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    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.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Feed_Reader
       
    17  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    19  * @version    $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    20  */
       
    21 
       
    22 /**
       
    23  * @see Zend_Feed_Reader_Extension_FeedAbstract
       
    24  */
       
    25 require_once 'Zend/Feed/Reader/Extension/FeedAbstract.php';
       
    26 
       
    27 /**
       
    28  * @category   Zend
       
    29  * @package    Zend_Feed_Reader
       
    30  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    31  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    32  */
       
    33 class Zend_Feed_Reader_Extension_CreativeCommons_Feed
       
    34     extends Zend_Feed_Reader_Extension_FeedAbstract
       
    35 {
       
    36     /**
       
    37      * Get the entry license
       
    38      *
       
    39      * @return string|null
       
    40      */
       
    41     public function getLicense($index = 0)
       
    42     {
       
    43         $licenses = $this->getLicenses();
       
    44 
       
    45         if (isset($licenses[$index])) {
       
    46             return $licenses[$index];
       
    47         }
       
    48 
       
    49         return null;
       
    50     }
       
    51 
       
    52     /**
       
    53      * Get the entry licenses
       
    54      *
       
    55      * @return array
       
    56      */
       
    57     public function getLicenses()
       
    58     {
       
    59         $name = 'licenses';
       
    60         if (array_key_exists($name, $this->_data)) {
       
    61             return $this->_data[$name];
       
    62         }
       
    63 
       
    64         $licenses = array();
       
    65         $list = $this->_xpath->evaluate('channel/cc:license');
       
    66 
       
    67         if ($list->length) {
       
    68             foreach ($list as $license) {
       
    69                 $licenses[] = $license->nodeValue;
       
    70             }
       
    71 
       
    72             $licenses = array_unique($licenses);
       
    73         }
       
    74 
       
    75         $this->_data[$name] = $licenses;
       
    76 
       
    77         return $this->_data[$name];
       
    78     }
       
    79 
       
    80     /**
       
    81      * Register Creative Commons namespaces
       
    82      *
       
    83      * @return void
       
    84      */
       
    85     protected function _registerNamespaces()
       
    86     {
       
    87         $this->_xpath->registerNamespace('cc', 'http://backend.userland.com/creativeCommonsRssModule');
       
    88     }
       
    89 }