Пример #1
0
/**
 * Dissect the URL and route the request.
 */
function callHook()
{
    $controller = CShell::id();
    $action = 'home';
    $queryString = array();
    try {
        //Remove all get parameters
        $URI = preg_replace('/\\?(.*)/', '', $_SERVER['REQUEST_URI']);
        $urlArray = explode("/", str_replace('-', '_', $URI));
        //The first segment will always be empty
        if (count($urlArray) > 0) {
            array_shift($urlArray);
        }
        if (count($urlArray) > 0 && $urlArray[0] != '') {
            //Ignore the sub-folder if it exists.
            if (PageTool::getSubFolder() != '') {
                array_shift($urlArray);
            }
            /**
             * If an exception is triggered or the dc is set to false set the controller.
             */
            if (count($urlArray) > 0 && (in_array($urlArray[0], CShell::exceptions()) || in_array($urlArray[0], CShell::system()) || !CShell::default_controller())) {
                $controller = $urlArray[0];
                array_shift($urlArray);
            }
            //Set the action.
            if (count($urlArray) > 0) {
                //If GoLink skip assignment of action.
                if ($controller != CShell::GO) {
                    $action = $urlArray[0];
                    array_shift($urlArray);
                }
                //Set the arguments
                if (count($urlArray) > 0) {
                    $queryString = $urlArray;
                }
            }
        }
        $controllerName = $controller;
        $controller = ucwords($controller);
        $controller .= 'Controller';
        if (file_exists(ROOT . DS . 'app' . DS . 'controllers' . DS . $controller . '.php')) {
            require_once ROOT . DS . 'app' . DS . 'controllers' . DS . $controller . '.php';
        } elseif (file_exists(ROOT . DS . 'app' . DS . 'controllers' . DS . 'system' . DS . $controller . '.php')) {
            require_once ROOT . DS . 'app' . DS . 'controllers' . DS . 'system' . DS . $controller . '.php';
        }
        if (class_exists($controller) && method_exists($controller, $action)) {
            $dispatch = new $controller($controllerName, $action);
        } else {
            header('HTTP/1.0 404 Not Found');
            exit;
        }
        call_user_func_array(array($dispatch, $action), $queryString);
    } catch (Exception $e) {
        SystemTool::sendException($e->getFile(), $e->getMessage(), $e->getTraceAsString());
    }
}