xref: /dokuwiki/lib/exe/xmlrpc.php (revision dd87735d917b53fa3e3ac66675834419ed24f832)
1797c0d11SAndreas Gohr<?php
2*dd87735dSAndreas Gohr
3*dd87735dSAndreas Gohruse dokuwiki\Remote\AccessDeniedException;
4*dd87735dSAndreas Gohruse dokuwiki\Remote\Api;
5*dd87735dSAndreas Gohruse dokuwiki\Remote\RemoteException;
6*dd87735dSAndreas Gohr
77aec69d1SGuy Brandif(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/../../');
8797c0d11SAndreas Gohr
9797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/init.php');
10797c0d11SAndreas Gohrsession_write_close();  //close session
11593bf8f6SMichael Klier
122a9d6d65SFlorian Rathgeberif(!$conf['remote']) die((new IXR_Error(-32605, "XML-RPC server not enabled."))->getXml());
13593bf8f6SMichael Klier
14797c0d11SAndreas Gohr/**
15797c0d11SAndreas Gohr * Contains needed wrapper functions and registers all available
16797c0d11SAndreas Gohr * XMLRPC functions.
17797c0d11SAndreas Gohr */
183a13cfe7SDominik Eckelmannclass dokuwiki_xmlrpc_server extends IXR_Server {
1942a6fba0SGerrit Uitslag    protected $remote;
203ee5b583SAndreas Gohr
213ee5b583SAndreas Gohr    /**
22797c0d11SAndreas Gohr     * Constructor. Register methods and run Server
23797c0d11SAndreas Gohr     */
2442a6fba0SGerrit Uitslag    public function __construct(){
25*dd87735dSAndreas Gohr        $this->remote = new Api();
26f9501785SDominik Eckelmann        $this->remote->setDateTransformation(array($this, 'toDate'));
27f9501785SDominik Eckelmann        $this->remote->setFileTransformation(array($this, 'toFile'));
280c43e719SGerrit Uitslag        parent::__construct();
29797c0d11SAndreas Gohr    }
30797c0d11SAndreas Gohr
317e8500eeSGerrit Uitslag    /**
327e8500eeSGerrit Uitslag     * @param string $methodname
337e8500eeSGerrit Uitslag     * @param array $args
347e8500eeSGerrit Uitslag     * @return IXR_Error|mixed
357e8500eeSGerrit Uitslag     */
3642a6fba0SGerrit Uitslag    public function call($methodname, $args){
373f3bb97fSDominik Eckelmann        try {
383a13cfe7SDominik Eckelmann            $result = $this->remote->call($methodname, $args);
393a13cfe7SDominik Eckelmann            return $result;
40*dd87735dSAndreas Gohr        } catch (AccessDeniedException $e) {
413a13cfe7SDominik Eckelmann            if (!isset($_SERVER['REMOTE_USER'])) {
429d2e1be6SAndreas Gohr                http_status(401);
43b2a3342aSTim Roes                return new IXR_Error(-32603, "server error. not authorized to call method $methodname");
44f71f4f53SAndreas Gohr            } else {
459d2e1be6SAndreas Gohr                http_status(403);
46b2a3342aSTim Roes                return new IXR_Error(-32604, "server error. forbidden to call the method $methodname");
47f71f4f53SAndreas Gohr            }
483a13cfe7SDominik Eckelmann        } catch (RemoteException $e) {
493a13cfe7SDominik Eckelmann            return new IXR_Error($e->getCode(), $e->getMessage());
5026bec61eSMichael Klier        }
5126bec61eSMichael Klier    }
5226bec61eSMichael Klier
5342ea7f44SGerrit Uitslag    /**
5442ea7f44SGerrit Uitslag     * @param string|int $data iso date(yyyy[-]mm[-]dd[ hh:mm[:ss]]) or timestamp
5542ea7f44SGerrit Uitslag     * @return IXR_Date
5642ea7f44SGerrit Uitslag     */
5742a6fba0SGerrit Uitslag    public function toDate($data) {
58f9501785SDominik Eckelmann        return new IXR_Date($data);
59f9501785SDominik Eckelmann    }
60f9501785SDominik Eckelmann
6142ea7f44SGerrit Uitslag    /**
6242ea7f44SGerrit Uitslag     * @param string $data
6342ea7f44SGerrit Uitslag     * @return IXR_Base64
6442ea7f44SGerrit Uitslag     */
6542a6fba0SGerrit Uitslag    public function toFile($data) {
66f9501785SDominik Eckelmann        return new IXR_Base64($data);
67f9501785SDominik Eckelmann    }
68797c0d11SAndreas Gohr}
69797c0d11SAndreas Gohr
70797c0d11SAndreas Gohr$server = new dokuwiki_xmlrpc_server();
71797c0d11SAndreas Gohr
72e3776c06SMichael Hamann// vim:ts=4:sw=4:et:
73