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

Revision 5687, 2.2 KB checked in by niltonneto, 12 years ago (diff)

Ticket #2507 - Adicionado getImagePicture() e finalizado getUserContacts().

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