/[drupal]/contributions/modules/json_server/json_server.module
ViewVC logotype

Contents of /contributions/modules/json_server/json_server.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.8 - (show annotations) (download) (as text)
Sun Jan 13 16:00:59 2008 UTC (22 months, 2 weeks ago) by dmitrig01
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
Changes since 1.7: +2 -2 lines
File MIME type: text/x-php
Small fix
1 <?php
2 // $Id: json_server.module,v 1.7 2008/01/13 15:48:11 dmitrig01 Exp $
3
4 function json_server_server_info() {
5 return array(
6 '#name' => 'JSON',
7 '#path' => 'json',
8 );
9 }
10
11 function json_server_server_error($message) {
12 return array("status" => FALSE, "message" => $message);
13 }
14
15 function json_server_server() {
16 if (!isset($_POST)) {
17 return "JSON server accepts POST requests only.";
18 }
19
20 $request = $_POST['method'];
21 $methods = services_get_all();
22 $args = array();
23 foreach ($methods as $method) {
24 if ($method['#method'] == $request) {
25 unset($_POST['q']);
26 unset($_POST['method']);
27 $args = array();
28 foreach($method['#args'] as $arg) {
29 if(isset($_POST[$arg['#name']])) {
30 $args[] = $_POST[$arg['#name']];
31 }
32 elseif($arg['#optional'] == 0) {
33 return drupal_to_js(array("status" => FALSE, "data" => "Argument ". $arg['#name'] ." not recieved"));
34 }
35 else {
36 $args[] = NULL;
37 }
38 }
39 $result = services_method_call($method['#method'], $args);
40 if (is_array($result) && isset($result['#error']) && $result['#error'] === TRUE)
41 return drupal_to_js(array('status' => FALSE, 'data' => $result['#message']));
42
43 return drupal_to_js(array('status' => TRUE, 'data' => $result));
44 }
45 }
46
47 return drupal_to_js(array('status' => FALSE, 'data' => "Invalid method $request"));
48 }
49
50 function json_load() {
51 global $base_url;
52 $path = drupal_get_path("module", "json_server");
53 drupal_add_js($path ."/json_server.js");
54 }

  ViewVC Help
Powered by ViewVC 1.1.2