xref: /dokuwiki/lib/exe/xmlrpc.php (revision 42ea7f447f39fbc2f79eaaec31f8c10ede59c5d0)
1797c0d11SAndreas Gohr<?php
27aec69d1SGuy Brandif(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../');
3797c0d11SAndreas Gohr
4797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/init.php');
5797c0d11SAndreas Gohrsession_write_close();  //close session
6593bf8f6SMichael Klier
7b967e5fcSDominik Eckelmannif(!$conf['remote']) die('XML-RPC server not enabled.');
8593bf8f6SMichael Klier
9797c0d11SAndreas Gohr/**
10797c0d11SAndreas Gohr * Contains needed wrapper functions and registers all available
11797c0d11SAndreas Gohr * XMLRPC functions.
12797c0d11SAndreas Gohr */
133a13cfe7SDominik Eckelmannclass dokuwiki_xmlrpc_server extends IXR_Server {
143f3bb97fSDominik Eckelmann    var $remote;
153ee5b583SAndreas Gohr
163ee5b583SAndreas Gohr    /**
17797c0d11SAndreas Gohr     * Constructor. Register methods and run Server
18797c0d11SAndreas Gohr     */
19797c0d11SAndreas Gohr    function dokuwiki_xmlrpc_server(){
203f3bb97fSDominik Eckelmann        $this->remote = new RemoteAPI();
21f9501785SDominik Eckelmann        $this->remote->setDateTransformation(array($this, 'toDate'));
22f9501785SDominik Eckelmann        $this->remote->setFileTransformation(array($this, 'toFile'));
233a13cfe7SDominik Eckelmann        $this->IXR_Server();
24797c0d11SAndreas Gohr    }
25797c0d11SAndreas Gohr
263a13cfe7SDominik Eckelmann    function call($methodname, $args){
273f3bb97fSDominik Eckelmann        try {
283a13cfe7SDominik Eckelmann            $result = $this->remote->call($methodname, $args);
293a13cfe7SDominik Eckelmann            return $result;
30e61127e4SDominik Eckelmann        } catch (RemoteAccessDeniedException $e) {
313a13cfe7SDominik Eckelmann            if (!isset($_SERVER['REMOTE_USER'])) {
329d2e1be6SAndreas Gohr                http_status(401);
33b2a3342aSTim Roes                return new IXR_Error(-32603, "server error. not authorized to call method $methodname");
34f71f4f53SAndreas Gohr            } else {
359d2e1be6SAndreas Gohr                http_status(403);
36b2a3342aSTim Roes                return new IXR_Error(-32604, "server error. forbidden to call the method $methodname");
37f71f4f53SAndreas Gohr            }
383a13cfe7SDominik Eckelmann        } catch (RemoteException $e) {
393a13cfe7SDominik Eckelmann            return new IXR_Error($e->getCode(), $e->getMessage());
4026bec61eSMichael Klier        }
4126bec61eSMichael Klier    }
4226bec61eSMichael Klier
43*42ea7f44SGerrit Uitslag    /**
44*42ea7f44SGerrit Uitslag     * @param string|int $data iso date(yyyy[-]mm[-]dd[ hh:mm[:ss]]) or timestamp
45*42ea7f44SGerrit Uitslag     * @return IXR_Date
46*42ea7f44SGerrit Uitslag     */
47f9501785SDominik Eckelmann    function toDate($data) {
48f9501785SDominik Eckelmann        return new IXR_Date($data);
49f9501785SDominik Eckelmann    }
50f9501785SDominik Eckelmann
51*42ea7f44SGerrit Uitslag    /**
52*42ea7f44SGerrit Uitslag     * @param string $data
53*42ea7f44SGerrit Uitslag     * @return IXR_Base64
54*42ea7f44SGerrit Uitslag     */
55f9501785SDominik Eckelmann    function toFile($data) {
56f9501785SDominik Eckelmann        return new IXR_Base64($data);
57f9501785SDominik Eckelmann    }
58797c0d11SAndreas Gohr}
59797c0d11SAndreas Gohr
60797c0d11SAndreas Gohr$server = new dokuwiki_xmlrpc_server();
61797c0d11SAndreas Gohr
62e3776c06SMichael Hamann// vim:ts=4:sw=4:et:
63