data)) { $data[] = $xml->data; $parser = new l10n_update_xml_parser; return $parser->parse($xml->data); } else { return FALSE; } } /** * Parser for server metadata */ class l10n_update_xml_parser { var $current_language; var $current_server; var $current_languages; var $servers; /** * Parse an XML data file. * * It can contain information for one or more l10n_servers * * Example data, http://ftp.drupal.org/files/translations/l10n_server.xml */ 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->servers; 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; //$this->current_object = &$this->current_release; 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; //$this->current_server = array(); 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: $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; } } } }