|
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: EntryAbstract.php 22662 2010-07-24 17:37:36Z mabe $ |
|
20 */ |
|
21 |
|
22 /** |
|
23 * @category Zend |
|
24 * @package Zend_Feed_Reader |
|
25 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
26 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
27 */ |
|
28 abstract class Zend_Feed_Reader_Extension_EntryAbstract |
|
29 { |
|
30 /** |
|
31 * Feed entry data |
|
32 * |
|
33 * @var array |
|
34 */ |
|
35 protected $_data = array(); |
|
36 |
|
37 /** |
|
38 * DOM document object |
|
39 * |
|
40 * @var DOMDocument |
|
41 */ |
|
42 protected $_domDocument = null; |
|
43 |
|
44 /** |
|
45 * Entry instance |
|
46 * |
|
47 * @var Zend_Feed_Entry_Abstract |
|
48 */ |
|
49 protected $_entry = null; |
|
50 |
|
51 /** |
|
52 * Pointer to the current entry |
|
53 * |
|
54 * @var int |
|
55 */ |
|
56 protected $_entryKey = 0; |
|
57 |
|
58 /** |
|
59 * XPath object |
|
60 * |
|
61 * @var DOMXPath |
|
62 */ |
|
63 protected $_xpath = null; |
|
64 |
|
65 /** |
|
66 * XPath query |
|
67 * |
|
68 * @var string |
|
69 */ |
|
70 protected $_xpathPrefix = ''; |
|
71 |
|
72 /** |
|
73 * Constructor |
|
74 * |
|
75 * @param Zend_Feed_Entry_Abstract $entry |
|
76 * @param int $entryKey |
|
77 * @param string $type |
|
78 * @return void |
|
79 */ |
|
80 public function __construct(DOMElement $entry, $entryKey, $type = null) |
|
81 { |
|
82 $this->_entry = $entry; |
|
83 $this->_entryKey = $entryKey; |
|
84 $this->_domDocument = $entry->ownerDocument; |
|
85 |
|
86 if ($type !== null) { |
|
87 $this->_data['type'] = $type; |
|
88 } else { |
|
89 $this->_data['type'] = Zend_Feed_Reader::detectType($entry->ownerDocument, true); |
|
90 } |
|
91 // set the XPath query prefix for the entry being queried |
|
92 if ($this->getType() == Zend_Feed_Reader::TYPE_RSS_10 |
|
93 || $this->getType() == Zend_Feed_Reader::TYPE_RSS_090 |
|
94 ) { |
|
95 $this->setXpathPrefix('//rss:item[' . ($this->_entryKey+1) . ']'); |
|
96 } elseif ($this->getType() == Zend_Feed_Reader::TYPE_ATOM_10 |
|
97 || $this->getType() == Zend_Feed_Reader::TYPE_ATOM_03 |
|
98 ) { |
|
99 $this->setXpathPrefix('//atom:entry[' . ($this->_entryKey+1) . ']'); |
|
100 } else { |
|
101 $this->setXpathPrefix('//item[' . ($this->_entryKey+1) . ']'); |
|
102 } |
|
103 } |
|
104 |
|
105 /** |
|
106 * Get the DOM |
|
107 * |
|
108 * @return DOMDocument |
|
109 */ |
|
110 public function getDomDocument() |
|
111 { |
|
112 return $this->_domDocument; |
|
113 } |
|
114 |
|
115 /** |
|
116 * Get the Entry's encoding |
|
117 * |
|
118 * @return string |
|
119 */ |
|
120 public function getEncoding() |
|
121 { |
|
122 $assumed = $this->getDomDocument()->encoding; |
|
123 return $assumed; |
|
124 } |
|
125 |
|
126 /** |
|
127 * Get the entry type |
|
128 * |
|
129 * @return string |
|
130 */ |
|
131 public function getType() |
|
132 { |
|
133 return $this->_data['type']; |
|
134 } |
|
135 |
|
136 /** |
|
137 * Set the XPath query |
|
138 * |
|
139 * @param DOMXPath $xpath |
|
140 * @return Zend_Feed_Reader_Extension_EntryAbstract |
|
141 */ |
|
142 public function setXpath(DOMXPath $xpath) |
|
143 { |
|
144 $this->_xpath = $xpath; |
|
145 $this->_registerNamespaces(); |
|
146 return $this; |
|
147 } |
|
148 |
|
149 /** |
|
150 * Get the XPath query object |
|
151 * |
|
152 * @return DOMXPath |
|
153 */ |
|
154 public function getXpath() |
|
155 { |
|
156 if (!$this->_xpath) { |
|
157 $this->setXpath(new DOMXPath($this->getDomDocument())); |
|
158 } |
|
159 return $this->_xpath; |
|
160 } |
|
161 |
|
162 /** |
|
163 * Serialize the entry to an array |
|
164 * |
|
165 * @return array |
|
166 */ |
|
167 public function toArray() |
|
168 { |
|
169 return $this->_data; |
|
170 } |
|
171 |
|
172 /** |
|
173 * Get the XPath prefix |
|
174 * |
|
175 * @return string |
|
176 */ |
|
177 public function getXpathPrefix() |
|
178 { |
|
179 return $this->_xpathPrefix; |
|
180 } |
|
181 |
|
182 /** |
|
183 * Set the XPath prefix |
|
184 * |
|
185 * @param string $prefix |
|
186 * @return Zend_Feed_Reader_Extension_EntryAbstract |
|
187 */ |
|
188 public function setXpathPrefix($prefix) |
|
189 { |
|
190 $this->_xpathPrefix = $prefix; |
|
191 return $this; |
|
192 } |
|
193 |
|
194 /** |
|
195 * Register XML namespaces |
|
196 * |
|
197 * @return void |
|
198 */ |
|
199 protected abstract function _registerNamespaces(); |
|
200 } |