xref: /dokuwiki/lib/exe/xmlrpc.php (revision 65a878f98c684b62bd8d0a4ebb6065325206d957)
1<?php
2if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../');
3
4require_once(DOKU_INC.'inc/init.php');
5session_write_close();  //close session
6
7if(!$conf['remote']) die((new IXR_Error(-32605, "XML-RPC server not enabled."))->getXml());
8
9/**
10 * Contains needed wrapper functions and registers all available
11 * XMLRPC functions.
12 */
13class dokuwiki_xmlrpc_server extends IXR_Server {
14    protected $remote;
15
16    /**
17     * Constructor. Register methods and run Server
18     */
19    public 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    public 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    public function toDate($data) {
53        return new IXR_Date($data);
54    }
55
56    /**
57     * @param string $data
58     * @return IXR_Base64
59     */
60    public 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