Abstract.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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
  17. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * @see Zend_Feed
  23. */
  24. require_once 'Zend/Feed.php';
  25. /**
  26. * @see Zend_Feed_Element
  27. */
  28. require_once 'Zend/Feed/Element.php';
  29. /**
  30. * Zend_Feed_Entry_Abstract represents a single entry in an Atom or RSS
  31. * feed.
  32. *
  33. * @category Zend
  34. * @package Zend_Feed
  35. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. */
  38. abstract class Zend_Feed_Entry_Abstract extends Zend_Feed_Element
  39. {
  40. /**
  41. * Root XML element for entries. Subclasses must define this to a
  42. * non-null value.
  43. *
  44. * @var string
  45. */
  46. protected $_rootElement;
  47. /**
  48. * Root namespace for entries. Subclasses may define this to a
  49. * non-null value.
  50. *
  51. * @var string
  52. */
  53. protected $_rootNamespace = null;
  54. /**
  55. * Zend_Feed_Entry_Abstract constructor
  56. *
  57. * The Zend_Feed_Entry_Abstract constructor takes the URI of the feed the entry
  58. * is part of, and optionally an XML construct (usually a
  59. * SimpleXMLElement, but it can be an XML string or a DOMNode as
  60. * well) that contains the contents of the entry.
  61. *
  62. * @param string $uri
  63. * @param SimpleXMLElement|DOMNode|string $element
  64. * @return void
  65. * @throws Zend_Feed_Exception
  66. */
  67. public function __construct($uri = null, $element = null)
  68. {
  69. if (!($element instanceof DOMElement)) {
  70. if ($element) {
  71. // Load the feed as an XML DOMDocument object
  72. @ini_set('track_errors', 1);
  73. $doc = new DOMDocument();
  74. $status = @$doc->loadXML($element);
  75. @ini_restore('track_errors');
  76. if (!$status) {
  77. // prevent the class to generate an undefined variable notice (ZF-2590)
  78. if (!isset($php_errormsg)) {
  79. if (function_exists('xdebug_is_enabled')) {
  80. $php_errormsg = '(error message not available, when XDebug is running)';
  81. } else {
  82. $php_errormsg = '(error message not available)';
  83. }
  84. }
  85. /**
  86. * @see Zend_Feed_Exception
  87. */
  88. require_once 'Zend/Feed/Exception.php';
  89. throw new Zend_Feed_Exception("DOMDocument cannot parse XML: $php_errormsg");
  90. }
  91. $element = $doc->getElementsByTagName($this->_rootElement)->item(0);
  92. if (!$element) {
  93. /**
  94. * @see Zend_Feed_Exception
  95. */
  96. require_once 'Zend/Feed/Exception.php';
  97. throw new Zend_Feed_Exception('No root <' . $this->_rootElement . '> element found, cannot parse feed.');
  98. }
  99. } else {
  100. $doc = new DOMDocument('1.0', 'utf-8');
  101. if ($this->_rootNamespace !== null) {
  102. $element = $doc->createElementNS(Zend_Feed::lookupNamespace($this->_rootNamespace), $this->_rootElement);
  103. } else {
  104. $element = $doc->createElement($this->_rootElement);
  105. }
  106. }
  107. }
  108. parent::__construct($element);
  109. }
  110. }