source: sandbox/webservice/api/webservice.php @ 5633

Revision 5633, 2.1 KB checked in by niltonneto, 12 years ago (diff)

Ticket #2507 - Adicionado método que retorna versão instalada do Expresso.

Line 
1<?php
2include_once("http_request.class.php");
3
4$public_functions = array(
5        "Expresso.login",
6        "Expresso.logout",
7        "Expresso.getExpressoVersion",
8        "Mail.getUserFolders",
9        "Mail.getUserMessages"
10);
11
12$GLOBALS['phpgw_info'] = array(
13        'flags' => array(
14                        'currentapp'            => 'login',
15                        'noheader'              => True,
16                        'disable_Template_class' => True,
17                        'public_functions'       => $public_functions
18        )
19);
20
21include_once('../header.inc.php');
22
23// NO COOKIES!!!!
24unset($_COOKIE);
25switch ($_SERVER['REQUEST_METHOD']) {
26        case 'GET':
27        case 'POST':           
28                execute($_REQUEST);
29        break;
30       
31        default:
32        exit();
33}
34
35function execute($request){     
36        if(empty($request)) {
37                $request = array();
38                $http_request = new http_request();
39                $content_type = $http_request->header('Content-Type');
40                $accept = $http_request->header('Accept');
41                $content = $http_request->body();       
42       
43                if (($content_type == 'application/x-www-form-urlencoded')
44                        && ($accept == 'application/json') && $content != null) {
45               
46                        $req_obj = json_decode($content);
47                        $request['params']      = (array)$req_obj->params;
48                        $request['method']      = $req_obj->method;
49                        $request ['format']     = "json-rpc";
50                        $request['id']          = $req_obj->id;
51                }
52        }
53               
54        list($params, $method, $format, $id) = array_values($request);
55
56        if(verifyMethod($method)){
57                $method = explode(".", $method);       
58                include_once("./".$format."/".$method[0].".php");
59                $obj = new $method[0]($id);     
60                $response = $obj->$method[1]($params); 
61        }
62        else{
63                $response = array(
64                                'result'        => null,
65                                'error'         => "Available Resources: ". implode(", ", $GLOBALS['phpgw_info']['flags']['public_functions']),
66                                'id'            => $id
67                );             
68        }
69        dispatch($response, $format);
70}
71
72function verifyMethod($method) {
73        if(array_search( $method, $GLOBALS['phpgw_info']['flags']['public_functions']) !== FALSE){
74                return true;
75        }
76        else {
77                return false;
78        }
79}
80
81function dispatch($response, $format){
82        $e_response = false;
83        switch($format){               
84                case 'json-rpc':
85                        $e_response = @json_encode($response);
86                        break;
87                case 'xml-rpc':
88                        $e_response = @xmlrpc_encode($response);
89                        break;
90                default:
91                        $e_response = false;   
92                        break;
93        }       
94        echo $e_response;       
95}
Note: See TracBrowser for help on using the repository browser.