l10n_update.parser.inc in Localization update 7
File
l10n_update.parser.inc
View source
<?php
module_load_include('inc', 'l10n_update');
function l10n_update_get_server($server) {
if (!empty($server['server_url']) && ($fetch = l10n_update_fetch_server($server['server_url']))) {
$server = array_merge($server, $fetch);
}
if (!empty($server['update_url'])) {
return $server;
}
else {
return FALSE;
}
}
function l10n_update_fetch_server($url) {
$xml = l10n_update_http_request($url);
if (isset($xml->data)) {
$data[] = $xml->data;
$parser = new l10n_update_xml_parser();
return $parser
->parse($xml->data);
}
else {
return FALSE;
}
}
class l10n_update_xml_parser {
var $current_language;
var $current_server;
var $current_languages;
var $servers;
function parse($data) {
$parser = xml_parser_create();
xml_set_object($parser, $this);
xml_set_element_handler($parser, 'start', 'end');
xml_set_character_data_handler($parser, "data");
xml_parse($parser, $data);
xml_parser_free($parser);
return $this->current_server;
}
function start($parser, $name, $attr) {
$this->current_tag = $name;
switch ($name) {
case 'L10N_SERVER':
unset($this->current_object);
$this->current_server = array();
$this->current_object =& $this->current_server;
break;
case 'LANGUAGES':
unset($this->current_object);
$this->current_languages = array();
$this->current_object =& $this->current_languages;
break;
case 'LANGUAGE':
unset($this->current_object);
$this->current_language = array();
$this->current_object =& $this->current_language;
break;
}
}
function end($parser, $name) {
switch ($name) {
case 'L10N_SERVER':
unset($this->current_object);
$this->servers[$this->current_server['name']] = $this->current_server;
break;
case 'LANGUAGE':
unset($this->current_object);
$this->current_languages[$this->current_language['code']] = $this->current_language;
$this->current_language = array();
break;
case 'LANGUAGES':
$this->current_server['languages'] = $this->current_languages;
break;
default:
if (isset($this->current_object[strtolower($this->current_tag)])) {
$this->current_object[strtolower($this->current_tag)] = trim($this->current_object[strtolower($this->current_tag)]);
}
$this->current_tag = '';
}
}
function data($parser, $data) {
if ($this->current_tag && !in_array($this->current_tag, array(
'L10N_SERVER',
'LANGUAGES',
'LANGUAGE',
))) {
$tag = strtolower($this->current_tag);
if (isset($this->current_object[$tag])) {
$this->current_object[$tag] .= $data;
}
else {
$this->current_object[$tag] = $data;
}
}
}
}