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-2012 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2015 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: Feed.php 25160 2012-12-18 15:17:16Z matthew $ |
20 * @version $Id$ |
21 */ |
21 */ |
22 |
22 |
|
23 /** @see Zend_Xml_Security */ |
|
24 require_once 'Zend/Xml/Security.php'; |
23 |
25 |
24 /** |
26 /** |
25 * Feed utility class |
27 * Feed utility class |
26 * |
28 * |
27 * Base Zend_Feed class, containing constants and the Zend_Http_Client instance |
29 * Base Zend_Feed class, containing constants and the Zend_Http_Client instance |
28 * accessor. |
30 * accessor. |
29 * |
31 * |
30 * @category Zend |
32 * @category Zend |
31 * @package Zend_Feed |
33 * @package Zend_Feed |
32 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
34 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
33 * @license http://framework.zend.com/license/new-bsd New BSD License |
35 * @license http://framework.zend.com/license/new-bsd New BSD License |
34 */ |
36 */ |
35 class Zend_Feed |
37 class Zend_Feed |
36 { |
38 { |
37 |
39 |
188 * @throws Zend_Feed_Exception |
190 * @throws Zend_Feed_Exception |
189 * @return Zend_Feed_Abstract |
191 * @return Zend_Feed_Abstract |
190 */ |
192 */ |
191 public static function importString($string) |
193 public static function importString($string) |
192 { |
194 { |
193 // Load the feed as an XML DOMDocument object |
|
194 $libxml_errflag = libxml_use_internal_errors(true); |
|
195 $libxml_entity_loader = libxml_disable_entity_loader(true); |
|
196 $doc = new DOMDocument; |
|
197 if (trim($string) == '') { |
195 if (trim($string) == '') { |
198 require_once 'Zend/Feed/Exception.php'; |
196 require_once 'Zend/Feed/Exception.php'; |
199 throw new Zend_Feed_Exception('Document/string being imported' |
197 throw new Zend_Feed_Exception('Document/string being imported' |
200 . ' is an Empty string or comes from an empty HTTP response'); |
198 . ' is an Empty string or comes from an empty HTTP response'); |
201 } |
199 } |
202 $status = $doc->loadXML($string); |
200 $doc = new DOMDocument; |
203 libxml_disable_entity_loader($libxml_entity_loader); |
201 $doc = Zend_Xml_Security::scan($string, $doc); |
204 libxml_use_internal_errors($libxml_errflag); |
202 |
205 |
203 if (!$doc) { |
206 if (!$status) { |
|
207 // prevent the class to generate an undefined variable notice (ZF-2590) |
204 // prevent the class to generate an undefined variable notice (ZF-2590) |
208 // Build error message |
205 // Build error message |
209 $error = libxml_get_last_error(); |
206 $error = libxml_get_last_error(); |
210 if ($error && $error->message) { |
207 if ($error && $error->message) { |
211 $errormsg = "DOMDocument cannot parse XML: {$error->message}"; |
208 $errormsg = "DOMDocument cannot parse XML: {$error->message}"; |
318 foreach ($matches[1] as $link) { |
315 foreach ($matches[1] as $link) { |
319 // force string to be an utf-8 one |
316 // force string to be an utf-8 one |
320 if (!mb_check_encoding($link, 'UTF-8')) { |
317 if (!mb_check_encoding($link, 'UTF-8')) { |
321 $link = mb_convert_encoding($link, 'UTF-8'); |
318 $link = mb_convert_encoding($link, 'UTF-8'); |
322 } |
319 } |
323 $xml = @simplexml_load_string(rtrim($link, ' /') . ' />'); |
320 $xml = @Zend_Xml_Security::scan(rtrim($link, ' /') . ' />'); |
324 if ($xml === false) { |
321 if ($xml === false) { |
325 continue; |
322 continue; |
326 } |
323 } |
327 $attributes = $xml->attributes(); |
324 $attributes = $xml->attributes(); |
328 if (!isset($attributes['rel']) || !@preg_match('~^(?:alternate|service\.feed)~i', $attributes['rel'])) { |
325 if (!isset($attributes['rel']) || !@preg_match('~^(?:alternate|service\.feed)~i', $attributes['rel'])) { |