/** * JSON-RPC entrance. * * @return Void */ public function apiAction() { Zend_Registry::set('CMS', true); /** * Prepare the server. Zend_Json_Server cannot work with batched requests natively, * so that's taken care of customly here. Therefore, autoEmitResponse is set to false * so the server doesn't print the response directly. */ $server = new Zend_Json_Server(); $server->setClass('Garp_Content_Manager_Proxy'); $server->setAutoEmitResponse(false); if ($this->getRequest()->isPost()) { $post = $this->_getJsonRpcRequest(); $batch = false; $responses = array(); $requests = Zend_Json::decode($post, Zend_Json::TYPE_ARRAY); /** * Check if this was a batch request. In that case the array is a plain array of * arrays. If not, there will be a 'jsonrpc' key in the root of the array. */ $batch = !array_key_exists('jsonrpc', $requests); if (!$batch) { $requests = array($requests); } foreach ($requests as $i => $request) { $request = $this->_reformJsonRpcRequest($request); $requestJson = Zend_Json::encode($request); $requestObj = new Zend_Json_Server_Request(); $requestObj->loadJson($requestJson); $server->setRequest($requestObj); /** * Note; response gets returned by reference, resulting in a $responses array * containing all the same items. * That's why clone is used here. */ $response = clone $server->handle(); $responses[] = $response; } $response = $batch ? '[' . implode(',', $responses) . ']' : $responses[0]; } else { $response = $server->getServiceMap(); } $this->_helper->layout->setLayout('json'); // filter out escaped slashes, because they're annoying and not necessary. $response = str_replace('\\/', '/', $response); $this->view->response = $response; }
require_once 'Zend/Loader/Autoloader.php'; $autoloader = Zend_Loader_Autoloader::getInstance(); /** * ================================================================== * Prepare environment and execute JSON calls * ================================================================== */ require APPLICATION_PATH . '/includes/classes/remote.class.php'; header('Access-Control-Allow-Origin: *'); $server = new Zend_Json_Server(); $server->setClass('Kimai_Remote_Api'); if ('GET' == $_SERVER['REQUEST_METHOD']) { // Indicate the URL endpoint, and the JSON-RPC version used: $server->setTarget('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2); // Grab the SMD $smd = $server->getServiceMap(); // Return the SMD to the client header('Content-Type: application/json'); echo $smd; return; } /** * http request will * - parse php://input * - json_decode it * - auto setOptions * therefore request should be a string e.g. {jsonrpc : '2.0', method: '<actionString>', params : [param1, param2], id : '<anyId>' } */ $request = new Zend_Json_Server_Request_Http(); $server->setRequest($request); $server->handle();
*/ set_include_path(get_include_path() . PATH_SEPARATOR . 'include/'); require_once 'Zend/Loader/Autoloader.php'; $loader = Zend_Loader_Autoloader::getInstance(); $loader->registerNamespace('CnCNet_'); unset($loader); $db = Zend_Db::factory('Pdo_Sqlite', array('dbname' => 'db/cncnet.db')); Zend_Db_Table::setDefaultAdapter($db); $db->query('PRAGMA foreign_keys = ON'); unset($db); $type = isset($_GET['type']) ? $_GET['type'] : 'json'; if ($type == 'json' || $type == 'jsonp') { $server = new Zend_Json_Server(); $server->setClass('CnCNet_Api'); if ($type == 'jsonp') { $server->setRequest(new CnCNet_Json_Server_Request_Http_Jsonp()); $server->setResponse(new CnCNet_Json_Server_Response_Http_Jsonp()); } else { if ($_SERVER['REQUEST_METHOD'] == 'GET') { echo $server->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2)->getServiceMap(); return; } } $server->handle(); } else { if ($type == 'xml') { header('Content-type: text/xml'); $server = new Zend_XmlRpc_Server(); $server->setClass('CnCNet_Api'); echo $server->handle(); } else {