TYPO3 CMS  TYPO3_6-2
ExtensionXmlPushParser.php
Go to the documentation of this file.
1 <?php
3 
34 
40  protected $element = NULL;
41 
45  public function __construct() {
46  $this->requiredPhpExtensions = 'xml';
47  }
48 
54  protected function createParser() {
55  $this->objXml = xml_parser_create();
56  xml_set_object($this->objXml, $this);
57  }
58 
66  public function parseXml($file) {
67  $this->createParser();
68  if (!is_resource($this->objXml)) {
69  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Unable to create XML parser.', 1342640663);
70  }
71  // Disables the functionality to allow external entities to be loaded when parsing the XML, must be kept
72  $previousValueOfEntityLoader = libxml_disable_entity_loader(TRUE);
73  // keep original character case of XML document
74  xml_parser_set_option($this->objXml, XML_OPTION_CASE_FOLDING, FALSE);
75  xml_parser_set_option($this->objXml, XML_OPTION_SKIP_WHITE, FALSE);
76  xml_parser_set_option($this->objXml, XML_OPTION_TARGET_ENCODING, 'utf-8');
77  xml_set_element_handler($this->objXml, 'startElement', 'endElement');
78  xml_set_character_data_handler($this->objXml, 'characterData');
79  if (!($fp = fopen($file, 'r'))) {
80  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(sprintf('Unable to open file resource %s.', htmlspecialchars($file)), 1342640689);
81  }
82  while ($data = fread($fp, 4096)) {
83  if (!xml_parse($this->objXml, $data, feof($fp))) {
84  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(sprintf('XML error %s in line %u of file resource %s.', xml_error_string(xml_get_error_code($this->objXml)), xml_get_current_line_number($this->objXml), htmlspecialchars($file)), 1342640703);
85  }
86  }
87  libxml_disable_entity_loader($previousValueOfEntityLoader);
88  xml_parser_free($this->objXml);
89  }
90 
99  protected function startElement($parser, $elementName, $attrs) {
100  switch ($elementName) {
101  case 'extension':
102  $this->extensionKey = $attrs['extensionkey'];
103  break;
104  case 'version':
105  $this->version = $attrs['version'];
106  break;
107  default:
108  $this->element = $elementName;
109  }
110  }
111 
119  protected function endElement($parser, $elementName) {
120  switch ($elementName) {
121  case 'extension':
122  $this->resetProperties(TRUE);
123  break;
124  case 'version':
125  $this->notify();
126  $this->resetProperties();
127  break;
128  default:
129  $this->element = NULL;
130  }
131  }
132 
140  protected function characterData($parser, $data) {
141  if (isset($this->element)) {
142  switch ($this->element) {
143  case 'downloadcounter':
144  // downloadcounter could be a child node of
145  // extension or version
146  if ($this->version == NULL) {
147  $this->extensionDownloadCounter = $data;
148  } else {
149  $this->versionDownloadCounter = $data;
150  }
151  break;
152  case 'title':
153  $this->title = $data;
154  break;
155  case 'description':
156  $this->description = $data;
157  break;
158  case 'state':
159  $this->state = $data;
160  break;
161  case 'reviewstate':
162  $this->reviewstate = $data;
163  break;
164  case 'category':
165  $this->category = $data;
166  break;
167  case 'lastuploaddate':
168  $this->lastuploaddate = $data;
169  break;
170  case 'uploadcomment':
171  $this->uploadcomment = $data;
172  break;
173  case 'dependencies':
174  $this->dependencies = $this->convertDependencies($data);
175  break;
176  case 'authorname':
177  $this->authorname = $data;
178  break;
179  case 'authoremail':
180  $this->authoremail = $data;
181  break;
182  case 'authorcompany':
183  $this->authorcompany = $data;
184  break;
185  case 'ownerusername':
186  $this->ownerusername = $data;
187  break;
188  case 't3xfilemd5':
189  $this->t3xfilemd5 = $data;
190  break;
191  }
192  }
193  }
194 }