1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Extends the update parser to work with releases
|
6
|
*
|
7
|
* The update parser uses version tag to index releases. We will use 'language' and 'tag'
|
8
|
*
|
9
|
* @todo Parse languages too
|
10
|
*
|
11
|
* @todo Update the server side and get rid of this
|
12
|
*/
|
13
|
module_load_include('inc', 'l10n_update');
|
14
|
|
15
|
/**
|
16
|
* Get server information
|
17
|
*/
|
18
|
function l10n_update_get_server($server) {
|
19
|
// Fetch up to date information if available
|
20
|
if (!empty($server['server_url']) && ($fetch = l10n_update_fetch_server($server['server_url']))) {
|
21
|
$server = array_merge($server, $fetch);
|
22
|
}
|
23
|
// If we have an update url this is ok, otherwise we return none
|
24
|
if (!empty($server['update_url'])) {
|
25
|
return $server;
|
26
|
}
|
27
|
else {
|
28
|
return FALSE;
|
29
|
}
|
30
|
}
|
31
|
|
32
|
/**
|
33
|
* Fetch remote server metadata from a server URL
|
34
|
*
|
35
|
* @param unknown_type $server_url
|
36
|
* @return unknown_type
|
37
|
*/
|
38
|
function l10n_update_fetch_server($url) {
|
39
|
$xml = l10n_update_http_request($url);
|
40
|
if (isset($xml->data)) {
|
41
|
$data[] = $xml->data;
|
42
|
$parser = new l10n_update_xml_parser;
|
43
|
return $parser->parse($xml->data);
|
44
|
}
|
45
|
else {
|
46
|
return FALSE;
|
47
|
}
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* Parser for server metadata
|
52
|
*/
|
53
|
class l10n_update_xml_parser {
|
54
|
var $current_language;
|
55
|
var $current_server;
|
56
|
var $current_languages;
|
57
|
|
58
|
var $servers;
|
59
|
|
60
|
|
61
|
/**
|
62
|
* Parse an XML data file.
|
63
|
*
|
64
|
* It can contain information for one or more l10n_servers
|
65
|
*
|
66
|
* Example data, http://ftp.drupal.org/files/translations/l10n_server.xml
|
67
|
*/
|
68
|
function parse($data) {
|
69
|
$parser = xml_parser_create();
|
70
|
xml_set_object($parser, $this);
|
71
|
xml_set_element_handler($parser, 'start', 'end');
|
72
|
xml_set_character_data_handler($parser, "data");
|
73
|
xml_parse($parser, $data);
|
74
|
xml_parser_free($parser);
|
75
|
|
76
|
//return $this->servers;
|
77
|
return $this->current_server;
|
78
|
}
|
79
|
|
80
|
function start($parser, $name, $attr) {
|
81
|
$this->current_tag = $name;
|
82
|
switch ($name) {
|
83
|
case 'L10N_SERVER':
|
84
|
unset($this->current_object);
|
85
|
$this->current_server = array();
|
86
|
$this->current_object = &$this->current_server;
|
87
|
break;
|
88
|
case 'LANGUAGES':
|
89
|
unset($this->current_object);
|
90
|
$this->current_languages = array();
|
91
|
$this->current_object = &$this->current_languages;
|
92
|
//$this->current_object = &$this->current_release;
|
93
|
break;
|
94
|
case 'LANGUAGE':
|
95
|
unset($this->current_object);
|
96
|
$this->current_language = array();
|
97
|
$this->current_object = &$this->current_language;
|
98
|
break;
|
99
|
}
|
100
|
}
|
101
|
|
102
|
function end($parser, $name) {
|
103
|
switch ($name) {
|
104
|
case 'L10N_SERVER':
|
105
|
unset($this->current_object);
|
106
|
$this->servers[$this->current_server['name']] = $this->current_server;
|
107
|
//$this->current_server = array();
|
108
|
break;
|
109
|
case 'LANGUAGE':
|
110
|
unset($this->current_object);
|
111
|
$this->current_languages[$this->current_language['code']] = $this->current_language;
|
112
|
$this->current_language = array();
|
113
|
break;
|
114
|
case 'LANGUAGES':
|
115
|
$this->current_server['languages'] = $this->current_languages;
|
116
|
break;
|
117
|
default:
|
118
|
if (isset($this->current_object[strtolower($this->current_tag)])) {
|
119
|
$this->current_object[strtolower($this->current_tag)] = trim($this->current_object[strtolower($this->current_tag)]);
|
120
|
}
|
121
|
$this->current_tag = '';
|
122
|
}
|
123
|
}
|
124
|
|
125
|
function data($parser, $data) {
|
126
|
if ($this->current_tag && !in_array($this->current_tag, array('L10N_SERVER', 'LANGUAGES', 'LANGUAGE'))) {
|
127
|
$tag = strtolower($this->current_tag);
|
128
|
if (isset($this->current_object[$tag])) {
|
129
|
$this->current_object[$tag] .= $data;
|
130
|
}
|
131
|
else {
|
132
|
$this->current_object[$tag] = $data;
|
133
|
}
|
134
|
}
|
135
|
}
|
136
|
}
|