function wbMain()
{
    wbCore::init();
    list($module, $class, $method) = wbRequest::getController();
    // theme override
    $theme = wbRequest::getVarClean('theme');
    if (!empty($theme)) {
        wbPage::setTheme($theme);
    }
    $page = wbRequest::getVarClean('page');
    if (!empty($page)) {
        wbPage::setPage($page);
    }
    ob_start();
    $modView = wbModule::getView($module, $class, $method);
    if (ob_get_length() > 0) {
        $rawOutput = ob_get_contents();
        $modView = 'The following lines were printed in raw mode by module, however this
                      should not happen. The module is probably directly calling functions
                      like echo, print, or printf. Please modify the module to exclude direct output.
                      The module is violating Webi architecture principles.<br /><br />' . $rawOutput . '<br /><br />This is the real module output:<br /><br />' . $modView;
    }
    ob_end_clean();
    wbPage::render($modView);
}
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;
}
Esempio n. 3
0
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
    }
}