web/lib/Zend/Feed/Abstract.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    13  * obtain it through the world-wide-web, please send an email
    13  * obtain it through the world-wide-web, please send an email
    14  * to license@zend.com so we can send you a copy immediately.
    14  * to license@zend.com so we can send you a copy immediately.
    15  *
    15  *
    16  * @category   Zend
    16  * @category   Zend
    17  * @package    Zend_Feed
    17  * @package    Zend_Feed
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @version    $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $
    20  * @version    $Id: Abstract.php 25160 2012-12-18 15:17:16Z matthew $
    21  */
    21  */
    22 
    22 
    23 
    23 
    24 /**
    24 /**
    25  * @see Zend_Feed_Element
    25  * @see Zend_Feed_Element
    35  * considered to be the entry collection, such that iterating over the
    35  * considered to be the entry collection, such that iterating over the
    36  * feed takes you through each of the feed.s entries.
    36  * feed takes you through each of the feed.s entries.
    37  *
    37  *
    38  * @category   Zend
    38  * @category   Zend
    39  * @package    Zend_Feed
    39  * @package    Zend_Feed
    40  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    40  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    41  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    41  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    42  */
    42  */
    43 abstract class Zend_Feed_Abstract extends Zend_Feed_Element implements Iterator, Countable
    43 abstract class Zend_Feed_Abstract extends Zend_Feed_Element implements Iterator, Countable
    44 {
    44 {
    45     /**
    45     /**
    79             if ($response->getStatus() !== 200) {
    79             if ($response->getStatus() !== 200) {
    80                 /**
    80                 /**
    81                  * @see Zend_Feed_Exception
    81                  * @see Zend_Feed_Exception
    82                  */
    82                  */
    83                 require_once 'Zend/Feed/Exception.php';
    83                 require_once 'Zend/Feed/Exception.php';
    84                 throw new Zend_Feed_Exception('Feed failed to load, got response code ' . $response->getStatus());
    84                 throw new Zend_Feed_Exception('Feed failed to load, got response code ' . $response->getStatus() . '; request: ' . $client->getLastRequest() . "\nresponse: " . $response->asString());
    85             }
    85             }
    86             $this->_element = $response->getBody();
    86             $this->_element = $this->_importFeedFromString($response->getBody());
    87             $this->__wakeup();
    87             $this->__wakeup();
    88         } elseif ($string !== null) {
    88         } elseif ($string !== null) {
    89             // Retrieve the feed from $string
    89             // Retrieve the feed from $string
    90             $this->_element = $string;
    90             $this->_element = $string;
    91             $this->__wakeup();
    91             $this->__wakeup();
   254      *
   254      *
   255      * @throws Zend_Feed_Exception if headers have already been sent
   255      * @throws Zend_Feed_Exception if headers have already been sent
   256      * @return void
   256      * @return void
   257      */
   257      */
   258     abstract public function send();
   258     abstract public function send();
       
   259 
       
   260     /**
       
   261      * Import a feed from a string
       
   262      *
       
   263      * Protects against XXE attack vectors.
       
   264      * 
       
   265      * @param  string $feed 
       
   266      * @return string
       
   267      * @throws Zend_Feed_Exception on detection of an XXE vector
       
   268      */
       
   269     protected function _importFeedFromString($feed)
       
   270     {
       
   271         // Load the feed as an XML DOMDocument object
       
   272         $libxml_errflag       = libxml_use_internal_errors(true);
       
   273         $libxml_entity_loader = libxml_disable_entity_loader(true);
       
   274         $doc = new DOMDocument;
       
   275         if (trim($feed) == '') {
       
   276             require_once 'Zend/Feed/Exception.php';
       
   277             throw new Zend_Feed_Exception('Remote feed being imported'
       
   278             . ' is an Empty string or comes from an empty HTTP response');
       
   279         }
       
   280         $status = $doc->loadXML($feed);
       
   281         libxml_disable_entity_loader($libxml_entity_loader);
       
   282         libxml_use_internal_errors($libxml_errflag);
       
   283 
       
   284         if (!$status) {
       
   285             // prevent the class to generate an undefined variable notice (ZF-2590)
       
   286             // Build error message
       
   287             $error = libxml_get_last_error();
       
   288             if ($error && $error->message) {
       
   289                 $errormsg = "DOMDocument cannot parse XML: {$error->message}";
       
   290             } else {
       
   291                 $errormsg = "DOMDocument cannot parse XML";
       
   292             }
       
   293 
       
   294 
       
   295             /**
       
   296              * @see Zend_Feed_Exception
       
   297              */
       
   298             require_once 'Zend/Feed/Exception.php';
       
   299             throw new Zend_Feed_Exception($errormsg);
       
   300         }
       
   301 
       
   302         return $doc->saveXML($doc->documentElement);
       
   303     }
   259 }
   304 }