function ws_proccess($search, $getParams, $controller, $postParams, $jsonItems, $start, $limit) { $GLOBALS["Webi_PageTime"] = microtime(true); include 'lib/bootstrap.php'; /* Load Webi Core */ sys::import('webi.core'); wbCore::init(); $_GET['jsonItems'] = $jsonItems; if (!empty($getParams)) { $getParams =& wbUtil::jsonDecode($getParams); } else { $getParams = array(); } if (json_decode($postParams) > 0) { $postParams = json_decode($postParams); } else { $postParams = array(); } $controller =& wbUtil::jsonDecode($controller); $type = $controller['type']; if (!empty($getParams)) { foreach ($getParams as $key => $value) { $_GET[$key] = $value; } } if (!empty($postParams)) { foreach ($postParams as $key => $value) { $_POST[$key] = $value; } } $_GET['module'] = $controller['module']; $_GET['class'] = $controller['class']; $_GET['method'] = $controller['method']; list($module, $class, $method) = wbRequest::getController(); $callback = wbRequest::getVarClean('callback'); if (!wbModule::isAvailable($module, $class, $type)) { header("HTTP/1.1 400 Bad Request"); return; } try { $result = wbModule::call($module, $class, $method, array(), $type); } catch (Exception $e) { $result = array('items' => array(), 'total' => 0, 'success' => false, 'message' => $e->getMessage()); } $return = array(); $return['success'] = $result['success']; $return['message'] = $result['message']; $return['total'] = (int) $result['total']; $return['data'] = $result['items']; $return['current'] = (int) $result['current']; $return['rowCount'] = (int) $result['rowCount']; $return = base64_encode(serialize($return)); return $return; }
function wbWSMain() { // TODO: don't load the whole core wbCore::init(); /* determine the server type, then create an instance of an that server and serve the request according the ther servers protocol */ $type = wbRequest::getVarClean('type'); switch ($type) { case 'json': list($module, $class, $method) = wbRequest::getController(); $callback = wbRequest::getVarClean('callback'); if (!wbModule::isAvailable($module, $class, $type)) { header("HTTP/1.1 400 Bad Request"); return; } try { $result = wbModule::call($module, $class, $method, array(), $type); } catch (Exception $e) { $result = array('items' => array(), 'total' => 0, 'success' => false, 'message' => $e->getMessage()); } if ($result || is_array($result)) { if (empty($callback)) { header('Content-Type: application/json'); echo json_encode($result); } else { header('Content-Type: text/javascript'); echo $callback . '(' . json_encode($result) . ')'; } } else { header("HTTP/1.1 500 Internal Server Error"); } break; default: // nothing todo for now } }