xref: /dokuwiki/inc/Remote/XmlRpcServer.php (revision fe52a7ca924f3c057386946c40f1aa08f7644efe)
11cdd0090SAndreas Gohr<?php
21cdd0090SAndreas Gohr
31cdd0090SAndreas Gohrnamespace dokuwiki\Remote;
41cdd0090SAndreas Gohr
51cdd0090SAndreas Gohr/**
61cdd0090SAndreas Gohr * Contains needed wrapper functions and registers all available XMLRPC functions.
71cdd0090SAndreas Gohr */
81cdd0090SAndreas Gohrclass XmlRpcServer extends \IXR_Server
91cdd0090SAndreas Gohr{
101cdd0090SAndreas Gohr    protected $remote;
111cdd0090SAndreas Gohr
121cdd0090SAndreas Gohr    /**
131cdd0090SAndreas Gohr     * Constructor. Register methods and run Server
141cdd0090SAndreas Gohr     */
15*fe52a7caSMark Janssen    public function __construct($wait=false)
161cdd0090SAndreas Gohr    {
171cdd0090SAndreas Gohr        $this->remote = new Api();
181cdd0090SAndreas Gohr        $this->remote->setDateTransformation(array($this, 'toDate'));
191cdd0090SAndreas Gohr        $this->remote->setFileTransformation(array($this, 'toFile'));
20*fe52a7caSMark Janssen        parent::__construct(false, false, $wait);
211cdd0090SAndreas Gohr    }
221cdd0090SAndreas Gohr
231cdd0090SAndreas Gohr    /**
241cdd0090SAndreas Gohr     * @inheritdoc
251cdd0090SAndreas Gohr     */
261cdd0090SAndreas Gohr    public function call($methodname, $args)
271cdd0090SAndreas Gohr    {
281cdd0090SAndreas Gohr        try {
291cdd0090SAndreas Gohr            $result = $this->remote->call($methodname, $args);
301cdd0090SAndreas Gohr            return $result;
311cdd0090SAndreas Gohr        } /** @noinspection PhpRedundantCatchClauseInspection */ catch (AccessDeniedException $e) {
321cdd0090SAndreas Gohr            if (!isset($_SERVER['REMOTE_USER'])) {
331cdd0090SAndreas Gohr                http_status(401);
341cdd0090SAndreas Gohr                return new \IXR_Error(-32603, "server error. not authorized to call method $methodname");
351cdd0090SAndreas Gohr            } else {
361cdd0090SAndreas Gohr                http_status(403);
371cdd0090SAndreas Gohr                return new \IXR_Error(-32604, "server error. forbidden to call the method $methodname");
381cdd0090SAndreas Gohr            }
391cdd0090SAndreas Gohr        } catch (RemoteException $e) {
401cdd0090SAndreas Gohr            return new \IXR_Error($e->getCode(), $e->getMessage());
411cdd0090SAndreas Gohr        }
421cdd0090SAndreas Gohr    }
431cdd0090SAndreas Gohr
441cdd0090SAndreas Gohr    /**
451cdd0090SAndreas Gohr     * @param string|int $data iso date(yyyy[-]mm[-]dd[ hh:mm[:ss]]) or timestamp
461cdd0090SAndreas Gohr     * @return \IXR_Date
471cdd0090SAndreas Gohr     */
481cdd0090SAndreas Gohr    public function toDate($data)
491cdd0090SAndreas Gohr    {
501cdd0090SAndreas Gohr        return new \IXR_Date($data);
511cdd0090SAndreas Gohr    }
521cdd0090SAndreas Gohr
531cdd0090SAndreas Gohr    /**
541cdd0090SAndreas Gohr     * @param string $data
551cdd0090SAndreas Gohr     * @return \IXR_Base64
561cdd0090SAndreas Gohr     */
571cdd0090SAndreas Gohr    public function toFile($data)
581cdd0090SAndreas Gohr    {
591cdd0090SAndreas Gohr        return new \IXR_Base64($data);
601cdd0090SAndreas Gohr    }
611cdd0090SAndreas Gohr}
62