1
|
|
|
<?php |
2
|
|
|
if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../'); |
3
|
|
|
|
4
|
|
|
require_once(DOKU_INC.'inc/init.php'); |
5
|
|
|
session_write_close(); //close session |
6
|
|
|
|
7
|
|
|
if(!$conf['remote']) die('XML-RPC server not enabled.'); |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Contains needed wrapper functions and registers all available |
11
|
|
|
* XMLRPC functions. |
12
|
|
|
*/ |
13
|
|
|
class dokuwiki_xmlrpc_server extends IXR_Server { |
14
|
|
|
var $remote; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Constructor. Register methods and run Server |
18
|
|
|
*/ |
19
|
|
|
function __construct(){ |
|
|
|
|
20
|
|
|
$this->remote = new RemoteAPI(); |
21
|
|
|
$this->remote->setDateTransformation(array($this, 'toDate')); |
22
|
|
|
$this->remote->setFileTransformation(array($this, 'toFile')); |
23
|
|
|
parent::__construct(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param string $methodname |
28
|
|
|
* @param array $args |
29
|
|
|
* @return IXR_Error|mixed |
30
|
|
|
*/ |
31
|
|
|
function call($methodname, $args){ |
|
|
|
|
32
|
|
|
try { |
33
|
|
|
$result = $this->remote->call($methodname, $args); |
34
|
|
|
return $result; |
35
|
|
|
} catch (RemoteAccessDeniedException $e) { |
36
|
|
|
if (!isset($_SERVER['REMOTE_USER'])) { |
37
|
|
|
http_status(401); |
38
|
|
|
return new IXR_Error(-32603, "server error. not authorized to call method $methodname"); |
39
|
|
|
} else { |
40
|
|
|
http_status(403); |
41
|
|
|
return new IXR_Error(-32604, "server error. forbidden to call the method $methodname"); |
42
|
|
|
} |
43
|
|
|
} catch (RemoteException $e) { |
44
|
|
|
return new IXR_Error($e->getCode(), $e->getMessage()); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param string|int $data iso date(yyyy[-]mm[-]dd[ hh:mm[:ss]]) or timestamp |
50
|
|
|
* @return IXR_Date |
51
|
|
|
*/ |
52
|
|
|
function toDate($data) { |
|
|
|
|
53
|
|
|
return new IXR_Date($data); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string $data |
58
|
|
|
* @return IXR_Base64 |
59
|
|
|
*/ |
60
|
|
|
function toFile($data) { |
|
|
|
|
61
|
|
|
return new IXR_Base64($data); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$server = new dokuwiki_xmlrpc_server(); |
66
|
|
|
|
67
|
|
|
// vim:ts=4:sw=4:et: |
68
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.