[BUGFIX] Typo in the Extension Manager
[Packages/TYPO3.CMS.git] / typo3 / sysext / em / classes / parser / class.tx_em_parser_extensionxmlpushparser.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 Marcus Krause <marcus#exp2010@t3sec.info>
6 * Steffen Kamper <info@sk-typo3.de>
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 *
18 * This script is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * This copyright notice MUST APPEAR in all copies of the script!
24 ***************************************************************/
25 /**
26 * Module: Extension manager - Extension.xml push-parser
27 */
28
29
30 /**
31 * Parser for TYPO3's extension.xml file.
32 *
33 * Depends on PHP ext/xml which should be available
34 * with PHP 4+. This is the parser used in TYPO3
35 * Core <= 4.3 (without the "collect all data in one
36 * array" behaviour).
37 * Notice: ext/xml has proven to be buggy with entities.
38 * Use at least PHP 5.2.9+ and libxml2 2.7.3+!
39 *
40 * @author Marcus Krause <marcus#exp2010@t3sec.info>
41 * @author Steffen Kamper <info@sk-typo3.de>
42 *
43 * @since 2010-02-10
44 * @package TYPO3
45 * @subpackage EM
46 */
47 class tx_em_Parser_ExtensionXmlPushParser extends tx_em_Parser_ExtensionXmlAbstractParser implements SplSubject {
48
49
50 /**
51 * Keeps current element to process.
52 *
53 * @var string
54 */
55 protected $element = NULL;
56
57 /**
58 * Keeps list of attached observers.
59 *
60 * @var SplObserver[]
61 */
62 protected $observers = array();
63
64 /**
65 * Class constructor.
66 *
67 * @return void
68 */
69 function __construct() {
70 $this->requiredPHPExt = 'xml';
71
72 if ($this->isAvailable()) {
73 $this->objXML = xml_parser_create();
74 xml_set_object($this->objXML, $this);
75 }
76 }
77
78 /**
79 * Method parses an extensions.xml file.
80 *
81 * @param string $file: GZIP stream resource
82 * @return void
83 * @throws tx_em_ExtensionXmlException in case of XML parser errors
84 */
85 public function parseXML($file) {
86
87 if (!is_resource($this->objXML)) {
88 $this->throwException('Unable to create XML parser.');
89 }
90 // keep original character case of XML document
91 xml_parser_set_option($this->objXML, XML_OPTION_CASE_FOLDING, FALSE);
92 xml_parser_set_option($this->objXML, XML_OPTION_SKIP_WHITE, FALSE);
93 xml_parser_set_option($this->objXML, XML_OPTION_TARGET_ENCODING, 'utf-8');
94 xml_set_element_handler($this->objXML, 'startElement', 'endElement');
95 xml_set_character_data_handler($this->objXML, 'characterData');
96
97 if (!($fp = fopen($file, "r"))) {
98 $this->throwException(sprintf('Unable to open file resource %s.', htmlspecialchars($file)));
99 }
100 while ($data = fread($fp, 4096)) {
101 if (!xml_parse($this->objXML, $data, feof($fp))) {
102 $this->throwException(sprintf('XML error %s in line %u of file resource %s.',
103 xml_error_string(xml_get_error_code($this->objXML)),
104 xml_get_current_line_number($this->objXML),
105 htmlspecialchars($file)));
106 }
107 }
108 xml_parser_free($this->objXML);
109 }
110
111 /**
112 * Method is invoked when parser accesses start tag of an element.
113 *
114 * @param resource $parser parser resource
115 * @param string $elementName: element name at parser's current position
116 * @param array $attrs: array of an element's attributes if available
117 * @return void
118 */
119 protected function startElement($parser, $elementName, $attrs) {
120 switch ($elementName) {
121 case 'extension':
122 $this->extensionKey = $attrs['extensionkey'];
123 break;
124 case 'version':
125 $this->version = $attrs['version'];
126 break;
127 default:
128 $this->element = $elementName;
129 }
130 }
131
132 /**
133 * Method is invoked when parser accesses end tag of an element.
134 *
135 * @param resource $parser parser resource
136 * @param string $elementName: element name at parser's current position
137 * @return void
138 */
139 protected function endElement($parser, $elementName) {
140 switch ($elementName) {
141 case 'extension':
142 $this->resetProperties(TRUE);
143 break;
144 case 'version':
145 $this->notify();
146 $this->resetProperties();
147 break;
148 default:
149 $this->element = NULL;
150 }
151 }
152
153 /**
154 * Method is invoked when parser accesses any character other than elements.
155 *
156 * @param resource $parser: parser resource
157 * @param string $data: an element's value
158 * @return void
159 */
160 protected function characterData($parser, $data) {
161 if (isset($this->element)) {
162 switch ($this->element) {
163 case 'downloadcounter':
164 // downloadcounter could be a child node of
165 // extension or version
166 if ($this->version == NULL) {
167 $this->extensionDLCounter = $data;
168 } else {
169 $this->versionDLCounter = $data;
170 }
171 break;
172 case 'title':
173 $this->title = $data;
174 break;
175 case 'description':
176 $this->description = $data;
177 break;
178 case 'state':
179 $this->state = $data;
180 break;
181 case 'reviewstate':
182 $this->reviewstate = $data;
183 break;
184 case 'category':
185 $this->category = $data;
186 break;
187 case 'lastuploaddate':
188 $this->lastuploaddate = $data;
189 break;
190 case 'uploadcomment':
191 $this->uploadcomment = $data;
192 break;
193 case 'dependencies':
194 $this->dependencies = $this->convertDependencies($data);
195 break;
196 case 'authorname':
197 $this->authorname = $data;
198 break;
199 case 'authoremail':
200 $this->authoremail = $data;
201 break;
202 case 'authorcompany':
203 $this->authorcompany = $data;
204 break;
205 case 'ownerusername':
206 $this->ownerusername = $data;
207 break;
208 case 't3xfilemd5':
209 $this->t3xfilemd5 = $data;
210 break;
211 }
212 }
213 }
214
215 /**
216 * Method attaches an observer.
217 *
218 * @param SplObserver $observer: an observer to attach
219 * @return void
220 */
221 public function attach(SplObserver $observer) {
222 $this->observers[] = $observer;
223 }
224
225 /**
226 * Method detaches an attached observer
227 *
228 * @param SplObserver $observer: an observer to detach
229 * @return void
230 */
231 public function detach(SplObserver $observer) {
232 $key = array_search($observer, $this->observers, TRUE);
233 if (!($key === FALSE)) {
234 unset($this->observers[$key]);
235 }
236 }
237
238 /**
239 * Method notifies attached observers.
240 *
241 * @return void
242 */
243 public function notify() {
244 foreach ($this->observers as $observer) {
245 $observer->update($this);
246 }
247 }
248 }
249
250 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/parser/class.tx_em_parser_extensionxmlpushparser.php'])) {
251 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/parser/class.tx_em_parser_extensionxmlpushparser.php']);
252 }
253
254 ?>