11cdd0090SAndreas Gohr<?php 21cdd0090SAndreas Gohr 31cdd0090SAndreas Gohrnamespace dokuwiki\Remote; 41cdd0090SAndreas Gohr 5*7f8f2456SAndreas Gohruse IXR\DataType\Base64; 6*7f8f2456SAndreas Gohruse IXR\DataType\Date; 7*7f8f2456SAndreas Gohruse IXR\Exception\ServerException; 8*7f8f2456SAndreas Gohruse IXR\Server\Server; 9*7f8f2456SAndreas Gohr 101cdd0090SAndreas Gohr/** 111cdd0090SAndreas Gohr * Contains needed wrapper functions and registers all available XMLRPC functions. 121cdd0090SAndreas Gohr */ 13*7f8f2456SAndreas Gohrclass XmlRpcServer extends Server 141cdd0090SAndreas Gohr{ 151cdd0090SAndreas Gohr protected $remote; 161cdd0090SAndreas Gohr 171cdd0090SAndreas Gohr /** 181cdd0090SAndreas Gohr * Constructor. Register methods and run Server 191cdd0090SAndreas Gohr */ 20fe52a7caSMark Janssen public function __construct($wait=false) 211cdd0090SAndreas Gohr { 221cdd0090SAndreas Gohr $this->remote = new Api(); 231cdd0090SAndreas Gohr $this->remote->setDateTransformation(array($this, 'toDate')); 241cdd0090SAndreas Gohr $this->remote->setFileTransformation(array($this, 'toFile')); 25fe52a7caSMark Janssen parent::__construct(false, false, $wait); 261cdd0090SAndreas Gohr } 271cdd0090SAndreas Gohr 281cdd0090SAndreas Gohr /** 291cdd0090SAndreas Gohr * @inheritdoc 301cdd0090SAndreas Gohr */ 311cdd0090SAndreas Gohr public function call($methodname, $args) 321cdd0090SAndreas Gohr { 331cdd0090SAndreas Gohr try { 341cdd0090SAndreas Gohr $result = $this->remote->call($methodname, $args); 351cdd0090SAndreas Gohr return $result; 36*7f8f2456SAndreas Gohr } catch (AccessDeniedException $e) { 371cdd0090SAndreas Gohr if (!isset($_SERVER['REMOTE_USER'])) { 381cdd0090SAndreas Gohr http_status(401); 39*7f8f2456SAndreas Gohr return new ServerException("server error. not authorized to call method $methodname", -32603); 401cdd0090SAndreas Gohr } else { 411cdd0090SAndreas Gohr http_status(403); 42*7f8f2456SAndreas Gohr return new ServerException("server error. forbidden to call the method $methodname", -32604); 431cdd0090SAndreas Gohr } 441cdd0090SAndreas Gohr } catch (RemoteException $e) { 45*7f8f2456SAndreas Gohr return new ServerException($e->getMessage(), $e->getCode()); 461cdd0090SAndreas Gohr } 471cdd0090SAndreas Gohr } 481cdd0090SAndreas Gohr 491cdd0090SAndreas Gohr /** 501cdd0090SAndreas Gohr * @param string|int $data iso date(yyyy[-]mm[-]dd[ hh:mm[:ss]]) or timestamp 51*7f8f2456SAndreas Gohr * @return Date 521cdd0090SAndreas Gohr */ 531cdd0090SAndreas Gohr public function toDate($data) 541cdd0090SAndreas Gohr { 55*7f8f2456SAndreas Gohr return new Date($data); 561cdd0090SAndreas Gohr } 571cdd0090SAndreas Gohr 581cdd0090SAndreas Gohr /** 591cdd0090SAndreas Gohr * @param string $data 60*7f8f2456SAndreas Gohr * @return Base64 611cdd0090SAndreas Gohr */ 621cdd0090SAndreas Gohr public function toFile($data) 631cdd0090SAndreas Gohr { 64*7f8f2456SAndreas Gohr return new Base64($data); 651cdd0090SAndreas Gohr } 661cdd0090SAndreas Gohr} 67