10 defined(
'JPATH_PLATFORM') or die;
155 protected $stack = array(
'base');
163 protected $stateStore = array();
188 protected function _getStackLocation()
190 return implode(
'->', $this->stack);
200 protected function _getLastTag()
202 return $this->stack[count($this->stack) - 1];
217 public function _startElement($parser, $name, $attrs = array())
219 array_push($this->stack, $name);
220 $tag = $this->_getStackLocation();
223 if (isset($this->$tag))
225 $this->$tag->_data =
"";
232 $this->currentUpdate =
new stdClass;
241 $name = strtolower($name);
243 if (!isset($this->currentUpdate->$name))
245 $this->currentUpdate->$name =
new stdClass;
247 $this->currentUpdate->$name->_data =
'';
249 foreach ($attrs as $key => $data)
251 $key = strtolower($key);
252 $this->currentUpdate->$name->$key = $data;
269 public function _endElement($parser, $name)
271 array_pop($this->stack);
280 if (isset($this->currentUpdate->targetplatform->name)
281 && $product == $this->currentUpdate->targetplatform->name
282 && preg_match(
'/' . $this->currentUpdate->targetplatform->version .
'/', $ver->RELEASE)
283 && ((!isset($this->currentUpdate->targetplatform->min_dev_level)) || $ver->DEV_LEVEL >= $this->currentUpdate->targetplatform->min_dev_level)
284 && ((!isset($this->currentUpdate->targetplatform->max_dev_level)) || $ver->DEV_LEVEL <= $this->currentUpdate->targetplatform->max_dev_level))
286 if (isset($this->latest))
288 if (version_compare($this->currentUpdate->version->_data, $this->latest->version->_data,
'>') == 1)
290 $this->latest = $this->currentUpdate;
295 $this->latest = $this->currentUpdate;
301 if (isset($this->latest))
303 foreach (get_object_vars($this->latest) as $key => $val)
307 unset($this->latest);
308 unset($this->currentUpdate);
310 elseif (isset($this->currentUpdate))
313 unset($this->currentUpdate);
330 public function _characterData($parser, $data)
332 $tag = $this->_getLastTag();
338 $tag = strtolower($tag);
339 if (isset($this->currentUpdate->$tag))
341 $this->currentUpdate->$tag->_data .= $data;
354 public function loadFromXML($url)
357 $response = $http->get($url);
358 if (200 != $response->code)
365 $this->xmlParser = xml_parser_create(
'');
366 xml_set_object($this->xmlParser, $this);
367 xml_set_element_handler($this->xmlParser,
'_startElement',
'_endElement');
368 xml_set_character_data_handler($this->xmlParser,
'_characterData');
370 if (!xml_parse($this->xmlParser, $response->body))
374 "XML error: %s at line %d", xml_error_string(xml_get_error_code($this->xmlParser)),
375 xml_get_current_line_number($this->xmlParser)
379 xml_parser_free($this->xmlParser);