XOOPS  2.6.0
xmlrpctag.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
22 abstract class XoopsXmlRpcDocument
23 {
27  protected $_tags = array();
28 
33  public function add(XoopsXmlRpcTag &$tagobj)
34  {
35  $this->_tags[] = $tagobj;
36  }
37 
38  abstract function render();
39 
40 }
41 
43 {
47  public function render()
48  {
49  $payload = '';
50  foreach ($this->_tags as $tag) {
51  /* @var $tag XoopsXmlRpcTag */
52  if (!$tag->isFault()) {
53  $payload .= $tag->render();
54  } else {
55  return '<?xml version="1.0"?><methodResponse>' . $tag->render() . '</methodResponse>';
56  }
57  }
58  return '<?xml version="1.0"?><methodResponse><params><param>' . $payload . '</param></params></methodResponse>';
59  }
60 }
61 
63 {
64 
68  public $methodName;
69 
73  public function __construct($methodName)
74  {
75  $this->methodName = trim($methodName);
76  }
77 
78  public function render()
79  {
80  $payload = '';
81  foreach ($this->_tags as $tag) {
82  /* @var $tag XoopsXmlRpcTag */
83  $payload .= '<param>' . $tag->render() . '</param>';
84  }
85  return '<?xml version="1.0"?><methodCall><methodName>' . $this->methodName . '</methodName><params>' . $payload . '</params></methodCall>';
86  }
87 }
88 
89 abstract class XoopsXmlRpcTag
90 {
94  protected $_fault = false;
95 
100  public function encode(&$text)
101  {
102  $text = preg_replace(array("/\&([a-z\d\#]+)\;/i", "/\&/", "/\#\|\|([a-z\d\#]+)\|\|\#/i"),
103  array("#||\\1||#", "&amp;", "&\\1;"), str_replace(array("<", ">"), array("&lt;", "&gt;"), $text));
104  return $text;
105  }
106 
111  public function setFault($fault = true)
112  {
113  $this->_fault = (bool)$fault;
114  }
115 
119  public function isFault()
120  {
121  return $this->_fault;
122  }
123 
128  abstract function render();
129 }
130 
132 {
136  protected $_code;
137 
141  protected $_extra;
142 
147  public function __construct($code, $extra = null)
148  {
149  $this->setFault(true);
150  $this->_code = intval($code);
151  $this->_extra = isset($extra) ? trim($extra) : '';
152  }
153 
157  public function render()
158  {
159  switch ($this->_code) {
160  case 101:
161  $string = 'Invalid server URI';
162  break;
163  case 102:
164  $string = 'Parser parse error';
165  break;
166  case 103:
167  $string = 'Module not found';
168  break;
169  case 104:
170  $string = 'User authentication failed';
171  break;
172  case 105:
173  $string = 'Module API not found';
174  break;
175  case 106:
176  $string = 'Method response error';
177  break;
178  case 107:
179  $string = 'Method not supported';
180  break;
181  case 108:
182  $string = 'Invalid parameter';
183  break;
184  case 109:
185  $string = 'Missing parameters';
186  break;
187  case 110:
188  $string = 'Selected blog application does not exist';
189  break;
190  case 111:
191  $string = 'Method permission denied';
192  break;
193  default:
194  $string = 'Method response error';
195  break;
196  }
197  $string .= "\n" . $this->_extra;
198  return '<fault><value><struct><member><name>faultCode</name><value>' . $this->_code . '</value></member><member><name>faultString</name><value>' . $this->encode($string) . '</value></member></struct></value></fault>';
199  }
200 }
201 
203 {
207  protected $_value;
208 
212  public function __construct($value)
213  {
214  $this->_value = intval($value);
215  }
216 
220  public function render()
221  {
222  return '<value><int>' . $this->_value . '</int></value>';
223  }
224 }
225 
227 {
231  protected $_value;
232 
236  public function __construct($value)
237  {
238  $this->_value = (float)$value;
239  }
240 
244  public function render()
245  {
246  return '<value><double>' . $this->_value . '</double></value>';
247  }
248 }
249 
251 {
255  protected $_value;
256 
260  public function __construct($value)
261  {
262  $this->_value = (!empty($value) && $value != false) ? 1 : 0;
263  }
264 
268  public function render()
269  {
270  return '<value><boolean>' . $this->_value . '</boolean></value>';
271  }
272 }
273 
275 {
279  protected $_value;
280 
284  public function __construct($value)
285  {
286  $this->_value = strval($value);
287  }
288 
292  public function render()
293  {
294  return '<value><string>' . $this->encode($this->_value) . '</string></value>';
295  }
296 }
297 
299 {
303  protected $_value;
304 
308  public function __construct($value)
309  {
310  if (!is_numeric($value)) {
311  $this->_value = strtotime($value);
312  } else {
313  $this->_value = intval($value);
314  }
315  }
316 
320  public function render()
321  {
322  return '<value><dateTime.iso8601>' . gmstrftime("%Y%m%dT%H:%M:%S", $this->_value) . '</dateTime.iso8601></value>';
323  }
324 }
325 
327 {
331  protected $_value;
332 
336  public function __construct($value)
337  {
338  $this->_value = base64_encode($value);
339  }
340 
344  public function render()
345  {
346  return '<value><base64>' . $this->_value . '</base64></value>';
347  }
348 }
349 
351 {
355  protected $_tags = array();
356 
361  public function add(XoopsXmlRpcTag &$tagobj)
362  {
363  $this->_tags[] = $tagobj;
364  }
365 
369  public function render()
370  {
371  $ret = '<value><array><data>';
372  foreach ($this->_tags as $tag) {
373  /* @var $tag XoopsXmlRpcTag */
374  $ret .= $tag->render();
375  }
376  $ret .= '</data></array></value>';
377  return $ret;
378  }
379 }
380 
382 {
386  protected $_tags = array();
387 
393  public function add($name, XoopsXmlRpcTag &$tagobj)
394  {
395  $this->_tags[] = array('name' => $name, 'value' => $tagobj);
396  }
397 
398  public function render()
399  {
400  $ret = '<value><struct>';
401  foreach ($this->_tags as $tag) {
402  /* @var $tag['value'] XoopsXmlRplTag */
403  $ret .= '<member><name>' . $this->encode($tag['name']) . '</name>' . $tag['value']->render() . '</member>';
404  }
405  $ret .= '</struct></value>';
406  return $ret;
407  }
408 }
409 
410 ?>
__construct($methodName)
Definition: xmlrpctag.php:73
encode(&$text)
Definition: xmlrpctag.php:100
$text
Definition: qrrender.php:27
__construct($value)
Definition: xmlrpctag.php:236
__construct($value)
Definition: xmlrpctag.php:212
setFault($fault=true)
Definition: xmlrpctag.php:111
add($name, XoopsXmlRpcTag &$tagobj)
Definition: xmlrpctag.php:393
__construct($value)
Definition: xmlrpctag.php:284
__construct($value)
Definition: xmlrpctag.php:336
add(XoopsXmlRpcTag &$tagobj)
Definition: xmlrpctag.php:33
add(XoopsXmlRpcTag &$tagobj)
Definition: xmlrpctag.php:361
__construct($code, $extra=null)
Definition: xmlrpctag.php:147
$code
Definition: lostpass.php:48