Warning, file /webapps/ocs-webserver/library/Zend/Feed/Reader/EntryAbstract.php was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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  * @category   Zend
0024  * @package    Zend_Feed_Reader
0025  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0026  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0027  */
0028 abstract class Zend_Feed_Reader_EntryAbstract
0029 {
0030     /**
0031      * Feed entry data
0032      *
0033      * @var array
0034      */
0035     protected $_data = array();
0036 
0037     /**
0038      * DOM document object
0039      *
0040      * @var DOMDocument
0041      */
0042     protected $_domDocument = null;
0043 
0044     /**
0045      * Entry instance
0046      *
0047      * @var Zend_Feed_Entry_Interface
0048      */
0049     protected $_entry = null;
0050 
0051     /**
0052      * Pointer to the current entry
0053      *
0054      * @var int
0055      */
0056     protected $_entryKey = 0;
0057 
0058     /**
0059      * XPath object
0060      *
0061      * @var DOMXPath
0062      */
0063     protected $_xpath = null;
0064 
0065     /**
0066      * Registered extensions
0067      *
0068      * @var array
0069      */
0070     protected $_extensions = array();
0071 
0072     /**
0073      * Constructor
0074      *
0075      * @param  DOMElement  $entry
0076      * @param  int         $entryKey
0077      * @param  string|null $type
0078      * @return void
0079      */
0080     public function __construct(DOMElement $entry, $entryKey, $type = null)
0081     {
0082         $this->_entry       = $entry;
0083         $this->_entryKey    = $entryKey;
0084         $this->_domDocument = $entry->ownerDocument;
0085         if ($type !== null) {
0086             $this->_data['type'] = $type;
0087         } else {
0088             $this->_data['type'] = Zend_Feed_Reader::detectType(
0089                 $this->_domDocument
0090             );
0091         }
0092         $this->_loadExtensions();
0093     }
0094 
0095     /**
0096      * Get the DOM
0097      *
0098      * @return DOMDocument
0099      */
0100     public function getDomDocument()
0101     {
0102         return $this->_domDocument;
0103     }
0104 
0105     /**
0106      * Get the entry element
0107      *
0108      * @return DOMElement
0109      */
0110     public function getElement()
0111     {
0112         return $this->_entry;
0113     }
0114 
0115     /**
0116      * Get the Entry's encoding
0117      *
0118      * @return string
0119      */
0120     public function getEncoding()
0121     {
0122         $assumed = $this->getDomDocument()->encoding;
0123         if (empty($assumed)) {
0124             $assumed = 'UTF-8';
0125         }
0126         return $assumed;
0127     }
0128 
0129     /**
0130      * Get entry as xml
0131      *
0132      * @return string
0133      */
0134     public function saveXml()
0135     {
0136         $dom = new DOMDocument('1.0', $this->getEncoding());
0137         $entry = $dom->importNode($this->getElement(), true);
0138         $dom->appendChild($entry);
0139         return $dom->saveXml();
0140     }
0141 
0142     /**
0143      * Get the entry type
0144      *
0145      * @return string
0146      */
0147     public function getType()
0148     {
0149         return $this->_data['type'];
0150     }
0151 
0152     /**
0153      * Get the XPath query object
0154      *
0155      * @return DOMXPath
0156      */
0157     public function getXpath()
0158     {
0159         if (!$this->_xpath) {
0160             $this->setXpath(new DOMXPath($this->getDomDocument()));
0161         }
0162         return $this->_xpath;
0163     }
0164 
0165     /**
0166      * Set the XPath query
0167      *
0168      * @param  DOMXPath $xpath
0169      * @return Zend_Feed_Reader_Entry_EntryAbstract
0170      */
0171     public function setXpath(DOMXPath $xpath)
0172     {
0173         $this->_xpath = $xpath;
0174         return $this;
0175     }
0176 
0177     /**
0178      * Get registered extensions
0179      *
0180      * @return array
0181      */
0182     public function getExtensions()
0183     {
0184         return $this->_extensions;
0185     }
0186 
0187     /**
0188      * Return an Extension object with the matching name (postfixed with _Entry)
0189      *
0190      * @param string $name
0191      * @return Zend_Feed_Reader_Extension_EntryAbstract
0192      */
0193     public function getExtension($name)
0194     {
0195         if (array_key_exists($name . '_Entry', $this->_extensions)) {
0196             return $this->_extensions[$name . '_Entry'];
0197         }
0198         return null;
0199     }
0200 
0201     /**
0202      * Method overloading: call given method on first extension implementing it
0203      *
0204      * @param  string $method
0205      * @param  array $args
0206      * @return mixed
0207      * @throws Zend_Feed_Exception if no extensions implements the method
0208      */
0209     public function __call($method, $args)
0210     {
0211         foreach ($this->_extensions as $extension) {
0212             if (method_exists($extension, $method)) {
0213                 return call_user_func_array(array($extension, $method), $args);
0214             }
0215         }
0216         // require_once 'Zend/Feed/Exception.php';
0217         throw new Zend_Feed_Exception(
0218             'Method: ' . $method
0219             . 'does not exist and could not be located on a registered Extension'
0220         );
0221     }
0222 
0223     /**
0224      * Load extensions from Zend_Feed_Reader
0225      *
0226      * @return void
0227      */
0228     protected function _loadExtensions()
0229     {
0230         $all = Zend_Feed_Reader::getExtensions();
0231         $feed = $all['entry'];
0232         foreach ($feed as $extension) {
0233             if (in_array($extension, $all['core'])) {
0234                 continue;
0235             }
0236             $className = Zend_Feed_Reader::getPluginLoader()->getClassName($extension);
0237             $this->_extensions[$extension] = new $className(
0238                 $this->getElement(), $this->_entryKey, $this->_data['type']
0239             );
0240         }
0241     }
0242 }