Exemplo n.º 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());
    }
}
Exemplo n.º 2
0
 function __destruct()
 {
     if ($this->_return != self::PROCESS && ($this->_return == null || $this->_return == self::VIEW)) {
         if (in_array($this->_controller, CShell::system())) {
             $this->setCache(false);
             if ($this->_return == self::VIEW) {
                 $this->_template->render();
             }
         } else {
             $this->_template->render();
         }
     } elseif ($this->_return == self::JSON) {
         echo json_encode($this->_data);
     }
 }