1: <?php
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32: class XoopsXmlRpcDocument
33: {
34:
35: var $_tags = array();
36:
37: function XoopsXmlRpcDocument()
38: {
39:
40: }
41:
42: function add(&$tagobj)
43: {
44: $this->_tags[] =& $tagobj;
45: }
46:
47: function render()
48: {
49: }
50:
51: }
52:
53: class XoopsXmlRpcResponse extends XoopsXmlRpcDocument
54: {
55: function render()
56: {
57: $count = count($this->_tags);
58: $payload = '';
59: for ($i = 0; $i < $count; $i++) {
60: if (!$this->_tags[$i]->isFault()) {
61: $payload .= $this->_tags[$i]->render();
62: } else {
63: return '<?xml version="1.0"?><methodResponse>'.$this->_tags[$i]->render().'</methodResponse>';
64: }
65: }
66: return '<?xml version="1.0"?><methodResponse><params><param>'.$payload.'</param></params></methodResponse>';
67: }
68: }
69:
70: class XoopsXmlRpcRequest extends XoopsXmlRpcDocument
71: {
72:
73: var $methodName;
74:
75: function XoopsXmlRpcRequest($methodName)
76: {
77: $this->methodName = trim($methodName);
78: }
79:
80: function render()
81: {
82: $count = count($this->_tags);
83: $payload = '';
84: for ($i = 0; $i < $count; $i++) {
85: $payload .= '<param>'.$this->_tags[$i]->render().'</param>';
86: }
87: return '<?xml version="1.0"?><methodCall><methodName>'.$this->methodName.'</methodName><params>'.$payload.'</params></methodCall>';
88: }
89: }
90:
91: class XoopsXmlRpcTag
92: {
93:
94: var $_fault = false;
95:
96: function XoopsXmlRpcTag()
97: {
98:
99: }
100:
101: function &encode(&$text)
102: {
103: $text = preg_replace(array("/\&([a-z\d\#]+)\;/i", "/\&/", "/\#\|\|([a-z\d\#]+)\|\|\#/i"), array("#||\\1||#", "&", "&\\1;"), str_replace(array("<", ">"), array("<", ">"), $text));
104: return $text;
105: }
106:
107: function setFault($fault = true){
108: $this->_fault = (intval($fault) > 0) ? true : false;
109: }
110:
111: function isFault()
112: {
113: return $this->_fault;
114: }
115:
116: function render()
117: {
118: }
119: }
120:
121: class XoopsXmlRpcFault extends XoopsXmlRpcTag
122: {
123:
124: var $_code;
125: var $_extra;
126:
127: function XoopsXmlRpcFault($code, $extra = null)
128: {
129: $this->setFault(true);
130: $this->_code = intval($code);
131: $this->_extra = isset($extra) ? trim($extra) : '';
132: }
133:
134: function render()
135: {
136: switch ($this->_code) {
137: case 101:
138: $string = 'Invalid server URI';
139: break;
140: case 102:
141: $string = 'Parser parse error';
142: break;
143: case 103:
144: $string = 'Module not found';
145: break;
146: case 104:
147: $string = 'User authentication failed';
148: break;
149: case 105:
150: $string = 'Module API not found';
151: break;
152: case 106:
153: $string = 'Method response error';
154: break;
155: case 107:
156: $string = 'Method not supported';
157: break;
158: case 108:
159: $string = 'Invalid parameter';
160: break;
161: case 109:
162: $string = 'Missing parameters';
163: break;
164: case 110:
165: $string = 'Selected blog application does not exist';
166: break;
167: case 111:
168: $string = 'Method permission denied';
169: break;
170: default:
171: $string = 'Method response error';
172: break;
173: }
174: $string .= "\n".$this->_extra;
175: 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>';
176: }
177: }
178:
179: class XoopsXmlRpcInt extends XoopsXmlRpcTag
180: {
181:
182: var $_value;
183:
184: function XoopsXmlRpcInt($value)
185: {
186: $this->_value = intval($value);
187: }
188:
189: function render()
190: {
191: return '<value><int>'.$this->_value.'</int></value>';
192: }
193: }
194:
195: class XoopsXmlRpcDouble extends XoopsXmlRpcTag
196: {
197:
198: var $_value;
199:
200: function XoopsXmlRpcDouble($value)
201: {
202: $this->_value = (float)$value;
203: }
204:
205: function render()
206: {
207: return '<value><double>'.$this->_value.'</double></value>';
208: }
209: }
210:
211: class XoopsXmlRpcBoolean extends XoopsXmlRpcTag
212: {
213:
214: var $_value;
215:
216: function XoopsXmlRpcBoolean($value)
217: {
218: $this->_value = (!empty($value) && $value != false) ? 1 : 0;
219: }
220:
221: function render()
222: {
223: return '<value><boolean>'.$this->_value.'</boolean></value>';
224: }
225: }
226:
227: class XoopsXmlRpcString extends XoopsXmlRpcTag
228: {
229:
230: var $_value;
231:
232: function XoopsXmlRpcString($value)
233: {
234: $this->_value = strval($value);
235: }
236:
237: function render()
238: {
239: return '<value><string>'.$this->encode($this->_value).'</string></value>';
240: }
241: }
242:
243: class XoopsXmlRpcDatetime extends XoopsXmlRpcTag
244: {
245:
246: var $_value;
247:
248: function XoopsXmlRpcDatetime($value)
249: {
250: if (!is_numeric($value)) {
251: $this->_value = strtotime($value);
252: } else {
253: $this->_value = intval($value);
254: }
255: }
256:
257: function render()
258: {
259: return '<value><dateTime.iso8601>'.gmstrftime("%Y%m%dT%H:%M:%S", $this->_value).'</dateTime.iso8601></value>';
260: }
261: }
262:
263: class XoopsXmlRpcBase64 extends XoopsXmlRpcTag
264: {
265:
266: var $_value;
267:
268: function XoopsXmlRpcBase64($value)
269: {
270: $this->_value = base64_encode($value);
271: }
272:
273: function render()
274: {
275: return '<value><base64>'.$this->_value.'</base64></value>';
276: }
277: }
278:
279: class XoopsXmlRpcArray extends XoopsXmlRpcTag
280: {
281:
282: var $_tags = array();
283:
284: function XoopsXmlRpcArray()
285: {
286: }
287:
288: function add(&$tagobj)
289: {
290: $this->_tags[] =& $tagobj;
291: }
292:
293: function render()
294: {
295: $count = count($this->_tags);
296: $ret = '<value><array><data>';
297: for ($i = 0; $i < $count; $i++) {
298: $ret .= $this->_tags[$i]->render();
299: }
300: $ret .= '</data></array></value>';
301: return $ret;
302: }
303: }
304:
305: class XoopsXmlRpcStruct extends XoopsXmlRpcTag{
306:
307: var $_tags = array();
308:
309: function XoopsXmlRpcStruct(){
310: }
311:
312: function add($name, &$tagobj){
313: $this->_tags[] = array('name' => $name, 'value' => $tagobj);
314: }
315:
316: function render(){
317: $count = count($this->_tags);
318: $ret = '<value><struct>';
319: for ($i = 0; $i < $count; $i++) {
320: $ret .= '<member><name>'.$this->encode($this->_tags[$i]['name']).'</name>'.$this->_tags[$i]['value']->render().'</member>';
321: }
322: $ret .= '</struct></value>';
323: return $ret;
324: }
325: }
326: ?>