[BUGFIX] Typo in the Extension Manager
[Packages/TYPO3.CMS.git] / typo3 / sysext / em / classes / parser / class.tx_em_parser_mirrorxmlpushparser.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 * class.tx_em_parser_mirrorxmlpushparser.php
27 *
28 * Module: Extension manager - mirrors.xml push-parser
29 *
30 * @author Marcus Krause <marcus#exp2010@t3sec.info>
31 * @author Steffen Kamper <info@sk-typo3.de>
32 */
33
34
35 /**
36 * Parser for TYPO3's mirrors.xml file.
37 *
38 * Depends on PHP ext/xml which should be available
39 * with PHP 4+. This is the parser used in TYPO3
40 * Core <= 4.3 (without the "collect all data in one
41 * array" behaviour).
42 * Notice: ext/xml has proven to be buggy with entities.
43 * Use at least PHP 5.2.9+ and libxml2 2.7.3+!
44 *
45 * @author Marcus Krause <marcus#exp2010@t3sec.info>
46 * @author Steffen Kamper <info@sk-typo3.de>
47 *
48 * @since 2010-11-17
49 * @package TYPO3
50 * @subpackage EM
51 */
52 class tx_em_Parser_MirrorXmlPushParser extends tx_em_Parser_MirrorXmlAbstractParser implements SplSubject {
53
54
55 /**
56 * Keeps list of attached observers.
57 *
58 * @var SplObserver[]
59 */
60 protected $observers = array();
61
62
63 /**
64 * Class constructor.
65 *
66 * @return void
67 */
68 function __construct() {
69 $this->requiredPHPExt = 'xml';
70
71 if ($this->isAvailable()) {
72 $this->objXML = xml_parser_create();
73 xml_set_object($this->objXML, $this);
74 }
75 }
76
77 /**
78 * Method parses a mirror.xml file.
79 *
80 * @param string $file: GZIP stream resource
81 * @return void
82 * @throws tx_em_MirrorXmlException in case of XML parser errors
83 */
84 public function parseXML($file) {
85
86 if (!is_resource($this->objXML)) {
87 $this->throwException('Unable to create XML parser.');
88 }
89 // keep original character case of XML document
90 xml_parser_set_option($this->objXML, XML_OPTION_CASE_FOLDING, FALSE);
91 xml_parser_set_option($this->objXML, XML_OPTION_SKIP_WHITE, FALSE);
92 xml_parser_set_option($this->objXML, XML_OPTION_TARGET_ENCODING, 'utf-8');
93 xml_set_element_handler($this->objXML, 'startElement', 'endElement');
94 xml_set_character_data_handler($this->objXML, 'characterData');
95
96 if (!($fp = fopen($file, "r"))) {
97 $this->throwException(sprintf('Unable to open file resource %s.', htmlspecialchars($file)));
98 }
99 while ($data = fread($fp, 4096)) {
100 if (!xml_parse($this->objXML, $data, feof($fp))) {
101 $this->throwException(sprintf('XML error %s in line %u of file resource %s.',
102 xml_error_string(xml_get_error_code($this->objXML)),
103 xml_get_current_line_number($this->objXML),
104 htmlspecialchars($file)));
105 }
106 }
107 xml_parser_free($this->objXML);
108 }
109
110 /**
111 * Method is invoked when parser accesses start tag of an element.
112 *
113 * @param resource $parser parser resource
114 * @param string $elementName: element name at parser's current position
115 * @param array $attrs: array of an element's attributes if available
116 * @return void
117 */
118 protected function startElement($parser, $elementName, $attrs) {
119 switch ($elementName) {
120 default:
121 $this->element = $elementName;
122 }
123 }
124
125 /**
126 * Method is invoked when parser accesses end tag of an element.
127 *
128 * @param resource $parser parser resource
129 * @param string $elementName: element name at parser's current position
130 * @return void
131 */
132 protected function endElement($parser, $elementName) {
133 switch ($elementName) {
134 case 'mirror':
135 $this->notify();
136 $this->resetProperties();
137 break;
138 default:
139 $this->element = NULL;
140 }
141 }
142
143 /**
144 * Method is invoked when parser accesses any character other than elements.
145 *
146 * @param resource $parser: parser resource
147 * @param string $data: an element's value
148 * @return void
149 */
150 protected function characterData($parser, $data) {
151 if (isset($this->element)) {
152 switch ($this->element) {
153 case 'title':
154 $this->title = $data;
155 break;
156 case 'host':
157 $this->host = $data;
158 break;
159 case 'path':
160 $this->path = $data;
161 break;
162 case 'country':
163 $this->country = $data;
164 break;
165 case 'name':
166 $this->sponsorname = $data;
167 break;
168 case 'link':
169 $this->sponsorlink = $data;
170 break;
171 case 'logo':
172 $this->sponsorlogo = $data;
173 break;
174 }
175 }
176 }
177
178 /**
179 * Method attaches an observer.
180 *
181 * @access public
182 * @param SplObserver $observer an observer to attach
183 * @return void
184 * @see $observers, detach(), notify()
185 */
186 public function attach(SplObserver $observer) {
187 $this->observers[] = $observer;
188 }
189
190 /**
191 * Method detaches an attached observer
192 *
193 * @access public
194 * @param SplObserver $observer an observer to detach
195 * @return void
196 * @see $observers, attach(), notify()
197 */
198 public function detach(SplObserver $observer) {
199 $key = array_search($observer, $this->observers, TRUE);
200 if (!($key === FALSE)) {
201 unset($this->observers[$key]);
202 }
203 }
204
205 /**
206 * Method notifies attached observers.
207 *
208 * @access public
209 * @return void
210 * @see $observers, attach(), detach()
211 */
212 public function notify() {
213 foreach ($this->observers as $observer) {
214 $observer->update($this);
215 }
216 }
217 }
218
219 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/parser/class.tx_em_parser_mirrorxmlpushparser.php'])) {
220 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/parser/class.tx_em_parser_mirrorxmlpushparser.php']);
221 }
222
223 ?>