Completed
Push — fix_xmlrpc_php7 ( ed8e6f )
by Michael
04:35
created

dokuwiki_xmlrpc_server::call()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 16
rs 9.2
cc 4
eloc 13
nc 4
nop 2
1
<?php
2
if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../');
3
4
require_once(DOKU_INC.'inc/init.php');
5
session_write_close();  //close session
6
7
if(!$conf['remote']) die('XML-RPC server not enabled.');
8
9
/**
10
 * Contains needed wrapper functions and registers all available
11
 * XMLRPC functions.
12
 */
13
class dokuwiki_xmlrpc_server extends IXR_Server {
14
    var $remote;
15
16
    /**
17
     * Constructor. Register methods and run Server
18
     */
19
    function __construct(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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
    function call($methodname, $args){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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
    function toDate($data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
53
        return new IXR_Date($data);
54
    }
55
56
    /**
57
     * @param string $data
58
     * @return IXR_Base64
59
     */
60
    function toFile($data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
61
        return new IXR_Base64($data);
62
    }
63
}
64
65
$server = new dokuwiki_xmlrpc_server();
66
67
// vim:ts=4:sw=4:et:
68