author | Anthony Ly <anthonyly.com@gmail.com> |
Tue, 12 Mar 2013 18:21:39 +0100 | |
changeset 206 | 919b4ddb13fa |
parent 204 | 09a1c134465b |
permissions | -rw-r--r-- |
136 | 1 |
<?php |
2 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3 |
* IXR - The Incutio XML-RPC Library |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
5 |
* Copyright (c) 2010, Incutio Ltd. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
6 |
* All rights reserved. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
7 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
8 |
* Redistribution and use in source and binary forms, with or without |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
9 |
* modification, are permitted provided that the following conditions are met: |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
10 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
11 |
* - Redistributions of source code must retain the above copyright notice, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
12 |
* this list of conditions and the following disclaimer. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
13 |
* - Redistributions in binary form must reproduce the above copyright |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
14 |
* notice, this list of conditions and the following disclaimer in the |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
15 |
* documentation and/or other materials provided with the distribution. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
16 |
* - Neither the name of Incutio Ltd. nor the names of its contributors |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
17 |
* may be used to endorse or promote products derived from this software |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
18 |
* without specific prior written permission. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
19 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
20 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
21 |
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
22 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
23 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
24 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
25 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
26 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
27 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
28 |
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
29 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
30 |
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
136 | 31 |
* |
32 |
* @package IXR |
|
33 |
* @since 1.5 |
|
34 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
35 |
* @copyright Incutio Ltd 2010 (http://www.incutio.com) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
36 |
* @version 1.7.4 7th September 2010 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
37 |
* @author Simon Willison |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
38 |
* @link http://scripts.incutio.com/xmlrpc/ Site/manual |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
39 |
* @license http://www.opensource.org/licenses/bsd-license.php BSD |
136 | 40 |
*/ |
41 |
||
42 |
/** |
|
43 |
* IXR_Value |
|
44 |
* |
|
45 |
* @package IXR |
|
46 |
* @since 1.5 |
|
47 |
*/ |
|
48 |
class IXR_Value { |
|
49 |
var $data; |
|
50 |
var $type; |
|
51 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
52 |
function IXR_Value($data, $type = false) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
53 |
{ |
136 | 54 |
$this->data = $data; |
55 |
if (!$type) { |
|
56 |
$type = $this->calculateType(); |
|
57 |
} |
|
58 |
$this->type = $type; |
|
59 |
if ($type == 'struct') { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
60 |
// Turn all the values in the array in to new IXR_Value objects |
136 | 61 |
foreach ($this->data as $key => $value) { |
62 |
$this->data[$key] = new IXR_Value($value); |
|
63 |
} |
|
64 |
} |
|
65 |
if ($type == 'array') { |
|
66 |
for ($i = 0, $j = count($this->data); $i < $j; $i++) { |
|
67 |
$this->data[$i] = new IXR_Value($this->data[$i]); |
|
68 |
} |
|
69 |
} |
|
70 |
} |
|
71 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
72 |
function calculateType() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
73 |
{ |
136 | 74 |
if ($this->data === true || $this->data === false) { |
75 |
return 'boolean'; |
|
76 |
} |
|
77 |
if (is_integer($this->data)) { |
|
78 |
return 'int'; |
|
79 |
} |
|
80 |
if (is_double($this->data)) { |
|
81 |
return 'double'; |
|
82 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
83 |
|
136 | 84 |
// Deal with IXR object types base64 and date |
85 |
if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { |
|
86 |
return 'date'; |
|
87 |
} |
|
88 |
if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) { |
|
89 |
return 'base64'; |
|
90 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
91 |
|
136 | 92 |
// If it is a normal PHP object convert it in to a struct |
93 |
if (is_object($this->data)) { |
|
94 |
$this->data = get_object_vars($this->data); |
|
95 |
return 'struct'; |
|
96 |
} |
|
97 |
if (!is_array($this->data)) { |
|
98 |
return 'string'; |
|
99 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
100 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
101 |
// We have an array - is it an array or a struct? |
136 | 102 |
if ($this->isStruct($this->data)) { |
103 |
return 'struct'; |
|
104 |
} else { |
|
105 |
return 'array'; |
|
106 |
} |
|
107 |
} |
|
108 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
109 |
function getXml() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
110 |
{ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
111 |
// Return XML for this value |
136 | 112 |
switch ($this->type) { |
113 |
case 'boolean': |
|
114 |
return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>'; |
|
115 |
break; |
|
116 |
case 'int': |
|
117 |
return '<int>'.$this->data.'</int>'; |
|
118 |
break; |
|
119 |
case 'double': |
|
120 |
return '<double>'.$this->data.'</double>'; |
|
121 |
break; |
|
122 |
case 'string': |
|
123 |
return '<string>'.htmlspecialchars($this->data).'</string>'; |
|
124 |
break; |
|
125 |
case 'array': |
|
126 |
$return = '<array><data>'."\n"; |
|
127 |
foreach ($this->data as $item) { |
|
128 |
$return .= ' <value>'.$item->getXml()."</value>\n"; |
|
129 |
} |
|
130 |
$return .= '</data></array>'; |
|
131 |
return $return; |
|
132 |
break; |
|
133 |
case 'struct': |
|
134 |
$return = '<struct>'."\n"; |
|
135 |
foreach ($this->data as $name => $value) { |
|
136 |
$name = htmlspecialchars($name); |
|
137 |
$return .= " <member><name>$name</name><value>"; |
|
138 |
$return .= $value->getXml()."</value></member>\n"; |
|
139 |
} |
|
140 |
$return .= '</struct>'; |
|
141 |
return $return; |
|
142 |
break; |
|
143 |
case 'date': |
|
144 |
case 'base64': |
|
145 |
return $this->data->getXml(); |
|
146 |
break; |
|
147 |
} |
|
148 |
return false; |
|
149 |
} |
|
150 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
151 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
152 |
* Checks whether or not the supplied array is a struct or not |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
153 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
154 |
* @param unknown_type $array |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
155 |
* @return boolean |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
156 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
157 |
function isStruct($array) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
158 |
{ |
136 | 159 |
$expected = 0; |
160 |
foreach ($array as $key => $value) { |
|
161 |
if ((string)$key != (string)$expected) { |
|
162 |
return true; |
|
163 |
} |
|
164 |
$expected++; |
|
165 |
} |
|
166 |
return false; |
|
167 |
} |
|
168 |
} |
|
169 |
||
170 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
171 |
* IXR_MESSAGE |
136 | 172 |
* |
173 |
* @package IXR |
|
174 |
* @since 1.5 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
175 |
* |
136 | 176 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
177 |
class IXR_Message |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
178 |
{ |
136 | 179 |
var $message; |
180 |
var $messageType; // methodCall / methodResponse / fault |
|
181 |
var $faultCode; |
|
182 |
var $faultString; |
|
183 |
var $methodName; |
|
184 |
var $params; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
185 |
|
136 | 186 |
// Current variable stacks |
187 |
var $_arraystructs = array(); // The stack used to keep track of the current array/struct |
|
188 |
var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array |
|
189 |
var $_currentStructName = array(); // A stack as well |
|
190 |
var $_param; |
|
191 |
var $_value; |
|
192 |
var $_currentTag; |
|
193 |
var $_currentTagContents; |
|
194 |
// The XML parser |
|
195 |
var $_parser; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
196 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
197 |
function IXR_Message($message) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
198 |
{ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
199 |
$this->message =& $message; |
136 | 200 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
201 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
202 |
function parse() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
203 |
{ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
204 |
// first remove the XML declaration |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
205 |
// merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
206 |
$header = preg_replace( '/<\?xml.*?\?'.'>/', '', substr($this->message, 0, 100), 1); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
207 |
$this->message = substr_replace($this->message, $header, 0, 100); |
136 | 208 |
if (trim($this->message) == '') { |
209 |
return false; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
210 |
} |
136 | 211 |
$this->_parser = xml_parser_create(); |
212 |
// Set XML parser to take the case of tags in to account |
|
213 |
xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false); |
|
214 |
// Set XML parser callback functions |
|
215 |
xml_set_object($this->_parser, $this); |
|
216 |
xml_set_element_handler($this->_parser, 'tag_open', 'tag_close'); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
217 |
xml_set_character_data_handler($this->_parser, 'cdata'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
218 |
$chunk_size = 262144; // 256Kb, parse in chunks to avoid the RAM usage on very large messages |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
219 |
$final = false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
220 |
do { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
221 |
if (strlen($this->message) <= $chunk_size) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
222 |
$final = true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
223 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
224 |
$part = substr($this->message, 0, $chunk_size); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
225 |
$this->message = substr($this->message, $chunk_size); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
226 |
if (!xml_parse($this->_parser, $part, $final)) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
227 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
228 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
229 |
if ($final) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
230 |
break; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
231 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
232 |
} while (true); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
233 |
xml_parser_free($this->_parser); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
234 |
|
136 | 235 |
// Grab the error messages, if any |
236 |
if ($this->messageType == 'fault') { |
|
237 |
$this->faultCode = $this->params[0]['faultCode']; |
|
238 |
$this->faultString = $this->params[0]['faultString']; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
239 |
} |
136 | 240 |
return true; |
241 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
242 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
243 |
function tag_open($parser, $tag, $attr) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
244 |
{ |
136 | 245 |
$this->_currentTagContents = ''; |
246 |
$this->currentTag = $tag; |
|
247 |
switch($tag) { |
|
248 |
case 'methodCall': |
|
249 |
case 'methodResponse': |
|
250 |
case 'fault': |
|
251 |
$this->messageType = $tag; |
|
252 |
break; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
253 |
/* Deal with stacks of arrays and structs */ |
136 | 254 |
case 'data': // data is to all intents and puposes more interesting than array |
255 |
$this->_arraystructstypes[] = 'array'; |
|
256 |
$this->_arraystructs[] = array(); |
|
257 |
break; |
|
258 |
case 'struct': |
|
259 |
$this->_arraystructstypes[] = 'struct'; |
|
260 |
$this->_arraystructs[] = array(); |
|
261 |
break; |
|
262 |
} |
|
263 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
264 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
265 |
function cdata($parser, $cdata) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
266 |
{ |
136 | 267 |
$this->_currentTagContents .= $cdata; |
268 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
269 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
270 |
function tag_close($parser, $tag) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
271 |
{ |
136 | 272 |
$valueFlag = false; |
273 |
switch($tag) { |
|
274 |
case 'int': |
|
275 |
case 'i4': |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
276 |
$value = (int)trim($this->_currentTagContents); |
136 | 277 |
$valueFlag = true; |
278 |
break; |
|
279 |
case 'double': |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
280 |
$value = (double)trim($this->_currentTagContents); |
136 | 281 |
$valueFlag = true; |
282 |
break; |
|
283 |
case 'string': |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
284 |
$value = (string)trim($this->_currentTagContents); |
136 | 285 |
$valueFlag = true; |
286 |
break; |
|
287 |
case 'dateTime.iso8601': |
|
288 |
$value = new IXR_Date(trim($this->_currentTagContents)); |
|
289 |
$valueFlag = true; |
|
290 |
break; |
|
291 |
case 'value': |
|
292 |
// "If no type is indicated, the type is string." |
|
293 |
if (trim($this->_currentTagContents) != '') { |
|
294 |
$value = (string)$this->_currentTagContents; |
|
295 |
$valueFlag = true; |
|
296 |
} |
|
297 |
break; |
|
298 |
case 'boolean': |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
299 |
$value = (boolean)trim($this->_currentTagContents); |
136 | 300 |
$valueFlag = true; |
301 |
break; |
|
302 |
case 'base64': |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
303 |
$value = base64_decode($this->_currentTagContents); |
136 | 304 |
$valueFlag = true; |
305 |
break; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
306 |
/* Deal with stacks of arrays and structs */ |
136 | 307 |
case 'data': |
308 |
case 'struct': |
|
309 |
$value = array_pop($this->_arraystructs); |
|
310 |
array_pop($this->_arraystructstypes); |
|
311 |
$valueFlag = true; |
|
312 |
break; |
|
313 |
case 'member': |
|
314 |
array_pop($this->_currentStructName); |
|
315 |
break; |
|
316 |
case 'name': |
|
317 |
$this->_currentStructName[] = trim($this->_currentTagContents); |
|
318 |
break; |
|
319 |
case 'methodName': |
|
320 |
$this->methodName = trim($this->_currentTagContents); |
|
321 |
break; |
|
322 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
323 |
|
136 | 324 |
if ($valueFlag) { |
325 |
if (count($this->_arraystructs) > 0) { |
|
326 |
// Add value to struct or array |
|
327 |
if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') { |
|
328 |
// Add to struct |
|
329 |
$this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value; |
|
330 |
} else { |
|
331 |
// Add to array |
|
332 |
$this->_arraystructs[count($this->_arraystructs)-1][] = $value; |
|
333 |
} |
|
334 |
} else { |
|
335 |
// Just add as a paramater |
|
336 |
$this->params[] = $value; |
|
337 |
} |
|
338 |
} |
|
339 |
$this->_currentTagContents = ''; |
|
340 |
} |
|
341 |
} |
|
342 |
||
343 |
/** |
|
344 |
* IXR_Server |
|
345 |
* |
|
346 |
* @package IXR |
|
347 |
* @since 1.5 |
|
348 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
349 |
class IXR_Server |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
350 |
{ |
136 | 351 |
var $data; |
352 |
var $callbacks = array(); |
|
353 |
var $message; |
|
354 |
var $capabilities; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
355 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
356 |
function IXR_Server($callbacks = false, $data = false, $wait = false) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
357 |
{ |
136 | 358 |
$this->setCapabilities(); |
359 |
if ($callbacks) { |
|
360 |
$this->callbacks = $callbacks; |
|
361 |
} |
|
362 |
$this->setCallbacks(); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
363 |
if (!$wait) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
364 |
$this->serve($data); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
365 |
} |
136 | 366 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
367 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
368 |
function serve($data = false) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
369 |
{ |
136 | 370 |
if (!$data) { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
371 |
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
372 |
header('Content-Type: text/plain'); // merged from WP #9093 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
373 |
die('XML-RPC server accepts POST requests only.'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
374 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
375 |
|
136 | 376 |
global $HTTP_RAW_POST_DATA; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
377 |
if (empty($HTTP_RAW_POST_DATA)) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
378 |
// workaround for a bug in PHP 5.2.2 - http://bugs.php.net/bug.php?id=41293 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
379 |
$data = file_get_contents('php://input'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
380 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
381 |
$data =& $HTTP_RAW_POST_DATA; |
136 | 382 |
} |
383 |
} |
|
384 |
$this->message = new IXR_Message($data); |
|
385 |
if (!$this->message->parse()) { |
|
386 |
$this->error(-32700, 'parse error. not well formed'); |
|
387 |
} |
|
388 |
if ($this->message->messageType != 'methodCall') { |
|
389 |
$this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall'); |
|
390 |
} |
|
391 |
$result = $this->call($this->message->methodName, $this->message->params); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
392 |
|
136 | 393 |
// Is the result an error? |
394 |
if (is_a($result, 'IXR_Error')) { |
|
395 |
$this->error($result); |
|
396 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
397 |
|
136 | 398 |
// Encode the result |
399 |
$r = new IXR_Value($result); |
|
400 |
$resultxml = $r->getXml(); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
401 |
|
136 | 402 |
// Create the XML |
403 |
$xml = <<<EOD |
|
404 |
<methodResponse> |
|
405 |
<params> |
|
406 |
<param> |
|
407 |
<value> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
408 |
$resultxml |
136 | 409 |
</value> |
410 |
</param> |
|
411 |
</params> |
|
412 |
</methodResponse> |
|
413 |
||
414 |
EOD; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
415 |
// Send it |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
416 |
$this->output($xml); |
136 | 417 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
418 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
419 |
function call($methodname, $args) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
420 |
{ |
136 | 421 |
if (!$this->hasMethod($methodname)) { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
422 |
return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.'); |
136 | 423 |
} |
424 |
$method = $this->callbacks[$methodname]; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
425 |
|
136 | 426 |
// Perform the callback and send the response |
427 |
if (count($args) == 1) { |
|
428 |
// If only one paramater just send that instead of the whole array |
|
429 |
$args = $args[0]; |
|
430 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
431 |
|
136 | 432 |
// Are we dealing with a function or a method? |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
433 |
if (is_string($method) && substr($method, 0, 5) == 'this:') { |
136 | 434 |
// It's a class method - check it exists |
435 |
$method = substr($method, 5); |
|
436 |
if (!method_exists($this, $method)) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
437 |
return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.'); |
136 | 438 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
439 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
440 |
//Call the method |
136 | 441 |
$result = $this->$method($args); |
442 |
} else { |
|
443 |
// It's a function - does it exist? |
|
444 |
if (is_array($method)) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
445 |
if (!is_callable(array($method[0], $method[1]))) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
446 |
return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.'); |
136 | 447 |
} |
448 |
} else if (!function_exists($method)) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
449 |
return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.'); |
136 | 450 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
451 |
|
136 | 452 |
// Call the function |
453 |
$result = call_user_func($method, $args); |
|
454 |
} |
|
455 |
return $result; |
|
456 |
} |
|
457 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
458 |
function error($error, $message = false) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
459 |
{ |
136 | 460 |
// Accepts either an error object or an error code and message |
461 |
if ($message && !is_object($error)) { |
|
462 |
$error = new IXR_Error($error, $message); |
|
463 |
} |
|
464 |
$this->output($error->getXml()); |
|
465 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
466 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
467 |
function output($xml) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
468 |
{ |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
469 |
$charset = function_exists('get_option') ? get_option('blog_charset') : ''; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
470 |
if ($charset) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
471 |
$xml = '<?xml version="1.0" encoding="'.$charset.'"?>'."\n".$xml; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
472 |
else |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
473 |
$xml = '<?xml version="1.0"?>'."\n".$xml; |
136 | 474 |
$length = strlen($xml); |
475 |
header('Connection: close'); |
|
476 |
header('Content-Length: '.$length); |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
477 |
if ($charset) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
478 |
header('Content-Type: text/xml; charset='.$charset); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
479 |
else |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
480 |
header('Content-Type: text/xml'); |
136 | 481 |
header('Date: '.date('r')); |
482 |
echo $xml; |
|
483 |
exit; |
|
484 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
485 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
486 |
function hasMethod($method) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
487 |
{ |
136 | 488 |
return in_array($method, array_keys($this->callbacks)); |
489 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
490 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
491 |
function setCapabilities() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
492 |
{ |
136 | 493 |
// Initialises capabilities array |
494 |
$this->capabilities = array( |
|
495 |
'xmlrpc' => array( |
|
496 |
'specUrl' => 'http://www.xmlrpc.com/spec', |
|
497 |
'specVersion' => 1 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
498 |
), |
136 | 499 |
'faults_interop' => array( |
500 |
'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', |
|
501 |
'specVersion' => 20010516 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
502 |
), |
136 | 503 |
'system.multicall' => array( |
504 |
'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208', |
|
505 |
'specVersion' => 1 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
506 |
), |
136 | 507 |
); |
508 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
509 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
510 |
function getCapabilities($args) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
511 |
{ |
136 | 512 |
return $this->capabilities; |
513 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
514 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
515 |
function setCallbacks() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
516 |
{ |
136 | 517 |
$this->callbacks['system.getCapabilities'] = 'this:getCapabilities'; |
518 |
$this->callbacks['system.listMethods'] = 'this:listMethods'; |
|
519 |
$this->callbacks['system.multicall'] = 'this:multiCall'; |
|
520 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
521 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
522 |
function listMethods($args) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
523 |
{ |
136 | 524 |
// Returns a list of methods - uses array_reverse to ensure user defined |
525 |
// methods are listed before server defined methods |
|
526 |
return array_reverse(array_keys($this->callbacks)); |
|
527 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
528 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
529 |
function multiCall($methodcalls) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
530 |
{ |
136 | 531 |
// See http://www.xmlrpc.com/discuss/msgReader$1208 |
532 |
$return = array(); |
|
533 |
foreach ($methodcalls as $call) { |
|
534 |
$method = $call['methodName']; |
|
535 |
$params = $call['params']; |
|
536 |
if ($method == 'system.multicall') { |
|
537 |
$result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden'); |
|
538 |
} else { |
|
539 |
$result = $this->call($method, $params); |
|
540 |
} |
|
541 |
if (is_a($result, 'IXR_Error')) { |
|
542 |
$return[] = array( |
|
543 |
'faultCode' => $result->code, |
|
544 |
'faultString' => $result->message |
|
545 |
); |
|
546 |
} else { |
|
547 |
$return[] = array($result); |
|
548 |
} |
|
549 |
} |
|
550 |
return $return; |
|
551 |
} |
|
552 |
} |
|
553 |
||
554 |
/** |
|
555 |
* IXR_Request |
|
556 |
* |
|
557 |
* @package IXR |
|
558 |
* @since 1.5 |
|
559 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
560 |
class IXR_Request |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
561 |
{ |
136 | 562 |
var $method; |
563 |
var $args; |
|
564 |
var $xml; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
565 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
566 |
function IXR_Request($method, $args) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
567 |
{ |
136 | 568 |
$this->method = $method; |
569 |
$this->args = $args; |
|
570 |
$this->xml = <<<EOD |
|
571 |
<?xml version="1.0"?> |
|
572 |
<methodCall> |
|
573 |
<methodName>{$this->method}</methodName> |
|
574 |
<params> |
|
575 |
||
576 |
EOD; |
|
577 |
foreach ($this->args as $arg) { |
|
578 |
$this->xml .= '<param><value>'; |
|
579 |
$v = new IXR_Value($arg); |
|
580 |
$this->xml .= $v->getXml(); |
|
581 |
$this->xml .= "</value></param>\n"; |
|
582 |
} |
|
583 |
$this->xml .= '</params></methodCall>'; |
|
584 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
585 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
586 |
function getLength() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
587 |
{ |
136 | 588 |
return strlen($this->xml); |
589 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
590 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
591 |
function getXml() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
592 |
{ |
136 | 593 |
return $this->xml; |
594 |
} |
|
595 |
} |
|
596 |
||
597 |
/** |
|
598 |
* IXR_Client |
|
599 |
* |
|
600 |
* @package IXR |
|
601 |
* @since 1.5 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
602 |
* |
136 | 603 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
604 |
class IXR_Client |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
605 |
{ |
136 | 606 |
var $server; |
607 |
var $port; |
|
608 |
var $path; |
|
609 |
var $useragent; |
|
610 |
var $response; |
|
611 |
var $message = false; |
|
612 |
var $debug = false; |
|
613 |
var $timeout; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
614 |
var $headers = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
615 |
|
136 | 616 |
// Storage place for an error message |
617 |
var $error = false; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
618 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
619 |
function IXR_Client($server, $path = false, $port = 80, $timeout = 15) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
620 |
{ |
136 | 621 |
if (!$path) { |
622 |
// Assume we have been given a URL instead |
|
623 |
$bits = parse_url($server); |
|
624 |
$this->server = $bits['host']; |
|
625 |
$this->port = isset($bits['port']) ? $bits['port'] : 80; |
|
626 |
$this->path = isset($bits['path']) ? $bits['path'] : '/'; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
627 |
|
136 | 628 |
// Make absolutely sure we have a path |
629 |
if (!$this->path) { |
|
630 |
$this->path = '/'; |
|
631 |
} |
|
632 |
} else { |
|
633 |
$this->server = $server; |
|
634 |
$this->path = $path; |
|
635 |
$this->port = $port; |
|
636 |
} |
|
637 |
$this->useragent = 'The Incutio XML-RPC PHP Library'; |
|
638 |
$this->timeout = $timeout; |
|
639 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
640 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
641 |
function query() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
642 |
{ |
136 | 643 |
$args = func_get_args(); |
644 |
$method = array_shift($args); |
|
645 |
$request = new IXR_Request($method, $args); |
|
646 |
$length = $request->getLength(); |
|
647 |
$xml = $request->getXml(); |
|
648 |
$r = "\r\n"; |
|
649 |
$request = "POST {$this->path} HTTP/1.0$r"; |
|
650 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
651 |
// Merged from WP #8145 - allow custom headers |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
652 |
$this->headers['Host'] = $this->server; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
653 |
$this->headers['Content-Type'] = 'text/xml'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
654 |
$this->headers['User-Agent'] = $this->useragent; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
655 |
$this->headers['Content-Length']= $length; |
136 | 656 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
657 |
foreach( $this->headers as $header => $value ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
658 |
$request .= "{$header}: {$value}{$r}"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
659 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
660 |
$request .= $r; |
136 | 661 |
|
662 |
$request .= $xml; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
663 |
|
136 | 664 |
// Now send the request |
665 |
if ($this->debug) { |
|
666 |
echo '<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n"; |
|
667 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
668 |
|
136 | 669 |
if ($this->timeout) { |
670 |
$fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); |
|
671 |
} else { |
|
672 |
$fp = @fsockopen($this->server, $this->port, $errno, $errstr); |
|
673 |
} |
|
674 |
if (!$fp) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
675 |
$this->error = new IXR_Error(-32300, 'transport error - could not open socket'); |
136 | 676 |
return false; |
677 |
} |
|
678 |
fputs($fp, $request); |
|
679 |
$contents = ''; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
680 |
$debugContents = ''; |
136 | 681 |
$gotFirstLine = false; |
682 |
$gettingHeaders = true; |
|
683 |
while (!feof($fp)) { |
|
684 |
$line = fgets($fp, 4096); |
|
685 |
if (!$gotFirstLine) { |
|
686 |
// Check line for '200' |
|
687 |
if (strstr($line, '200') === false) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
688 |
$this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); |
136 | 689 |
return false; |
690 |
} |
|
691 |
$gotFirstLine = true; |
|
692 |
} |
|
693 |
if (trim($line) == '') { |
|
694 |
$gettingHeaders = false; |
|
695 |
} |
|
696 |
if (!$gettingHeaders) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
697 |
// merged from WP #12559 - remove trim |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
698 |
$contents .= $line; |
136 | 699 |
} |
700 |
if ($this->debug) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
701 |
$debugContents .= $line; |
136 | 702 |
} |
703 |
} |
|
704 |
if ($this->debug) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
705 |
echo '<pre class="ixr_response">'.htmlspecialchars($debugContents)."\n</pre>\n\n"; |
136 | 706 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
707 |
|
136 | 708 |
// Now parse what we've got back |
709 |
$this->message = new IXR_Message($contents); |
|
710 |
if (!$this->message->parse()) { |
|
711 |
// XML error |
|
712 |
$this->error = new IXR_Error(-32700, 'parse error. not well formed'); |
|
713 |
return false; |
|
714 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
715 |
|
136 | 716 |
// Is the message a fault? |
717 |
if ($this->message->messageType == 'fault') { |
|
718 |
$this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); |
|
719 |
return false; |
|
720 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
721 |
|
136 | 722 |
// Message must be OK |
723 |
return true; |
|
724 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
725 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
726 |
function getResponse() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
727 |
{ |
136 | 728 |
// methodResponses can only have one param - return that |
729 |
return $this->message->params[0]; |
|
730 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
731 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
732 |
function isError() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
733 |
{ |
136 | 734 |
return (is_object($this->error)); |
735 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
736 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
737 |
function getErrorCode() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
738 |
{ |
136 | 739 |
return $this->error->code; |
740 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
741 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
742 |
function getErrorMessage() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
743 |
{ |
136 | 744 |
return $this->error->message; |
745 |
} |
|
746 |
} |
|
747 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
748 |
|
136 | 749 |
/** |
750 |
* IXR_Error |
|
751 |
* |
|
752 |
* @package IXR |
|
753 |
* @since 1.5 |
|
754 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
755 |
class IXR_Error |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
756 |
{ |
136 | 757 |
var $code; |
758 |
var $message; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
759 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
760 |
function IXR_Error($code, $message) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
761 |
{ |
136 | 762 |
$this->code = $code; |
763 |
$this->message = htmlspecialchars($message); |
|
764 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
765 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
766 |
function getXml() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
767 |
{ |
136 | 768 |
$xml = <<<EOD |
769 |
<methodResponse> |
|
770 |
<fault> |
|
771 |
<value> |
|
772 |
<struct> |
|
773 |
<member> |
|
774 |
<name>faultCode</name> |
|
775 |
<value><int>{$this->code}</int></value> |
|
776 |
</member> |
|
777 |
<member> |
|
778 |
<name>faultString</name> |
|
779 |
<value><string>{$this->message}</string></value> |
|
780 |
</member> |
|
781 |
</struct> |
|
782 |
</value> |
|
783 |
</fault> |
|
784 |
</methodResponse> |
|
785 |
||
786 |
EOD; |
|
787 |
return $xml; |
|
788 |
} |
|
789 |
} |
|
790 |
||
791 |
/** |
|
792 |
* IXR_Date |
|
793 |
* |
|
794 |
* @package IXR |
|
795 |
* @since 1.5 |
|
796 |
*/ |
|
797 |
class IXR_Date { |
|
798 |
var $year; |
|
799 |
var $month; |
|
800 |
var $day; |
|
801 |
var $hour; |
|
802 |
var $minute; |
|
803 |
var $second; |
|
804 |
var $timezone; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
805 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
806 |
function IXR_Date($time) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
807 |
{ |
136 | 808 |
// $time can be a PHP timestamp or an ISO one |
809 |
if (is_numeric($time)) { |
|
810 |
$this->parseTimestamp($time); |
|
811 |
} else { |
|
812 |
$this->parseIso($time); |
|
813 |
} |
|
814 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
815 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
816 |
function parseTimestamp($timestamp) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
817 |
{ |
136 | 818 |
$this->year = date('Y', $timestamp); |
819 |
$this->month = date('m', $timestamp); |
|
820 |
$this->day = date('d', $timestamp); |
|
821 |
$this->hour = date('H', $timestamp); |
|
822 |
$this->minute = date('i', $timestamp); |
|
823 |
$this->second = date('s', $timestamp); |
|
824 |
$this->timezone = ''; |
|
825 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
826 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
827 |
function parseIso($iso) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
828 |
{ |
136 | 829 |
$this->year = substr($iso, 0, 4); |
830 |
$this->month = substr($iso, 4, 2); |
|
831 |
$this->day = substr($iso, 6, 2); |
|
832 |
$this->hour = substr($iso, 9, 2); |
|
833 |
$this->minute = substr($iso, 12, 2); |
|
834 |
$this->second = substr($iso, 15, 2); |
|
835 |
$this->timezone = substr($iso, 17); |
|
836 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
837 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
838 |
function getIso() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
839 |
{ |
136 | 840 |
return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone; |
841 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
842 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
843 |
function getXml() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
844 |
{ |
136 | 845 |
return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>'; |
846 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
847 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
848 |
function getTimestamp() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
849 |
{ |
136 | 850 |
return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); |
851 |
} |
|
852 |
} |
|
853 |
||
854 |
/** |
|
855 |
* IXR_Base64 |
|
856 |
* |
|
857 |
* @package IXR |
|
858 |
* @since 1.5 |
|
859 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
860 |
class IXR_Base64 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
861 |
{ |
136 | 862 |
var $data; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
863 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
864 |
function IXR_Base64($data) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
865 |
{ |
136 | 866 |
$this->data = $data; |
867 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
868 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
869 |
function getXml() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
870 |
{ |
136 | 871 |
return '<base64>'.base64_encode($this->data).'</base64>'; |
872 |
} |
|
873 |
} |
|
874 |
||
875 |
/** |
|
876 |
* IXR_IntrospectionServer |
|
877 |
* |
|
878 |
* @package IXR |
|
879 |
* @since 1.5 |
|
880 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
881 |
class IXR_IntrospectionServer extends IXR_Server |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
882 |
{ |
136 | 883 |
var $signatures; |
884 |
var $help; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
885 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
886 |
function IXR_IntrospectionServer() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
887 |
{ |
136 | 888 |
$this->setCallbacks(); |
889 |
$this->setCapabilities(); |
|
890 |
$this->capabilities['introspection'] = array( |
|
891 |
'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html', |
|
892 |
'specVersion' => 1 |
|
893 |
); |
|
894 |
$this->addCallback( |
|
895 |
'system.methodSignature', |
|
896 |
'this:methodSignature', |
|
897 |
array('array', 'string'), |
|
898 |
'Returns an array describing the return type and required parameters of a method' |
|
899 |
); |
|
900 |
$this->addCallback( |
|
901 |
'system.getCapabilities', |
|
902 |
'this:getCapabilities', |
|
903 |
array('struct'), |
|
904 |
'Returns a struct describing the XML-RPC specifications supported by this server' |
|
905 |
); |
|
906 |
$this->addCallback( |
|
907 |
'system.listMethods', |
|
908 |
'this:listMethods', |
|
909 |
array('array'), |
|
910 |
'Returns an array of available methods on this server' |
|
911 |
); |
|
912 |
$this->addCallback( |
|
913 |
'system.methodHelp', |
|
914 |
'this:methodHelp', |
|
915 |
array('string', 'string'), |
|
916 |
'Returns a documentation string for the specified method' |
|
917 |
); |
|
918 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
919 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
920 |
function addCallback($method, $callback, $args, $help) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
921 |
{ |
136 | 922 |
$this->callbacks[$method] = $callback; |
923 |
$this->signatures[$method] = $args; |
|
924 |
$this->help[$method] = $help; |
|
925 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
926 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
927 |
function call($methodname, $args) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
928 |
{ |
136 | 929 |
// Make sure it's in an array |
930 |
if ($args && !is_array($args)) { |
|
931 |
$args = array($args); |
|
932 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
933 |
|
136 | 934 |
// Over-rides default call method, adds signature check |
935 |
if (!$this->hasMethod($methodname)) { |
|
936 |
return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.'); |
|
937 |
} |
|
938 |
$method = $this->callbacks[$methodname]; |
|
939 |
$signature = $this->signatures[$methodname]; |
|
940 |
$returnType = array_shift($signature); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
941 |
|
136 | 942 |
// Check the number of arguments |
943 |
if (count($args) != count($signature)) { |
|
944 |
return new IXR_Error(-32602, 'server error. wrong number of method parameters'); |
|
945 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
946 |
|
136 | 947 |
// Check the argument types |
948 |
$ok = true; |
|
949 |
$argsbackup = $args; |
|
950 |
for ($i = 0, $j = count($args); $i < $j; $i++) { |
|
951 |
$arg = array_shift($args); |
|
952 |
$type = array_shift($signature); |
|
953 |
switch ($type) { |
|
954 |
case 'int': |
|
955 |
case 'i4': |
|
956 |
if (is_array($arg) || !is_int($arg)) { |
|
957 |
$ok = false; |
|
958 |
} |
|
959 |
break; |
|
960 |
case 'base64': |
|
961 |
case 'string': |
|
962 |
if (!is_string($arg)) { |
|
963 |
$ok = false; |
|
964 |
} |
|
965 |
break; |
|
966 |
case 'boolean': |
|
967 |
if ($arg !== false && $arg !== true) { |
|
968 |
$ok = false; |
|
969 |
} |
|
970 |
break; |
|
971 |
case 'float': |
|
972 |
case 'double': |
|
973 |
if (!is_float($arg)) { |
|
974 |
$ok = false; |
|
975 |
} |
|
976 |
break; |
|
977 |
case 'date': |
|
978 |
case 'dateTime.iso8601': |
|
979 |
if (!is_a($arg, 'IXR_Date')) { |
|
980 |
$ok = false; |
|
981 |
} |
|
982 |
break; |
|
983 |
} |
|
984 |
if (!$ok) { |
|
985 |
return new IXR_Error(-32602, 'server error. invalid method parameters'); |
|
986 |
} |
|
987 |
} |
|
988 |
// It passed the test - run the "real" method call |
|
989 |
return parent::call($methodname, $argsbackup); |
|
990 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
991 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
992 |
function methodSignature($method) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
993 |
{ |
136 | 994 |
if (!$this->hasMethod($method)) { |
995 |
return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.'); |
|
996 |
} |
|
997 |
// We should be returning an array of types |
|
998 |
$types = $this->signatures[$method]; |
|
999 |
$return = array(); |
|
1000 |
foreach ($types as $type) { |
|
1001 |
switch ($type) { |
|
1002 |
case 'string': |
|
1003 |
$return[] = 'string'; |
|
1004 |
break; |
|
1005 |
case 'int': |
|
1006 |
case 'i4': |
|
1007 |
$return[] = 42; |
|
1008 |
break; |
|
1009 |
case 'double': |
|
1010 |
$return[] = 3.1415; |
|
1011 |
break; |
|
1012 |
case 'dateTime.iso8601': |
|
1013 |
$return[] = new IXR_Date(time()); |
|
1014 |
break; |
|
1015 |
case 'boolean': |
|
1016 |
$return[] = true; |
|
1017 |
break; |
|
1018 |
case 'base64': |
|
1019 |
$return[] = new IXR_Base64('base64'); |
|
1020 |
break; |
|
1021 |
case 'array': |
|
1022 |
$return[] = array('array'); |
|
1023 |
break; |
|
1024 |
case 'struct': |
|
1025 |
$return[] = array('struct' => 'struct'); |
|
1026 |
break; |
|
1027 |
} |
|
1028 |
} |
|
1029 |
return $return; |
|
1030 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1031 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1032 |
function methodHelp($method) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1033 |
{ |
136 | 1034 |
return $this->help[$method]; |
1035 |
} |
|
1036 |
} |
|
1037 |
||
1038 |
/** |
|
1039 |
* IXR_ClientMulticall |
|
1040 |
* |
|
1041 |
* @package IXR |
|
1042 |
* @since 1.5 |
|
1043 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1044 |
class IXR_ClientMulticall extends IXR_Client |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1045 |
{ |
136 | 1046 |
var $calls = array(); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1047 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1048 |
function IXR_ClientMulticall($server, $path = false, $port = 80) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1049 |
{ |
136 | 1050 |
parent::IXR_Client($server, $path, $port); |
1051 |
$this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; |
|
1052 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1053 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1054 |
function addCall() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1055 |
{ |
136 | 1056 |
$args = func_get_args(); |
1057 |
$methodName = array_shift($args); |
|
1058 |
$struct = array( |
|
1059 |
'methodName' => $methodName, |
|
1060 |
'params' => $args |
|
1061 |
); |
|
1062 |
$this->calls[] = $struct; |
|
1063 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1064 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1065 |
function query() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1066 |
{ |
136 | 1067 |
// Prepare multicall, then call the parent::query() method |
1068 |
return parent::query('system.multicall', $this->calls); |
|
1069 |
} |
|
1070 |
} |