3 * $Id: rpc.php 354 2007-11-05 20:48:49Z spocke $
6 * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
9 require_once("./includes/general.php");
11 // Set RPC response headers
12 header('Content-Type: text/plain');
13 header('Content-Encoding: UTF-8');
14 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
15 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
16 header("Cache-Control: no-store, no-cache, must-revalidate");
17 header("Cache-Control: post-check=0, pre-check=0", false);
18 header("Pragma: no-cache");
23 if (isset($_POST["json_data"]))
24 $raw = getRequestParam("json_data");
27 if (!$raw && isset($_GLOBALS) && isset($_GLOBALS["HTTP_RAW_POST_DATA"]))
28 $raw = $_GLOBALS["HTTP_RAW_POST_DATA"];
30 // Try globals variable
31 if (!$raw && isset($HTTP_RAW_POST_DATA))
32 $raw = $HTTP_RAW_POST_DATA;
36 if (!function_exists('file_get_contents')) {
37 $fp = fopen("php://input", "r");
42 $raw = fread($fp, 1024);
47 $raw = "" . file_get_contents("php://input");
52 die('{"result":null,"id":null,"error":{"errstr":"Could not get raw post data.","errfile":"","errline":null,"errcontext":"","level":"FATAL"}}');
55 $json = new Moxiecode_JSON();
56 $input = $json->decode($raw);
59 if (isset($config['general.engine'])) {
60 $spellchecker = new $config['general.engine']($config);
61 $result = call_user_func_array(array($spellchecker, $input['method']), $input['params']);
63 die('{"result":null,"id":null,"error":{"errstr":"You must choose an spellchecker engine in the config.php file.","errfile":"","errline":null,"errcontext":"","level":"FATAL"}}');
65 // Request and response id should always be the same
72 // Return JSON encoded string
73 echo $json->encode($output);