Esempio n. 1
0
 /**
  *
  */
 public static function route()
 {
     $url = $_GET['url'];
     $base = ConfigManifest::get_config('BasePath');
     if ($base && $base != '/' && strpos($url, $base) === 0) {
         $url = substr($url, strlen($base));
     }
     if (empty($url)) {
         $url = '/';
     }
     $parts = explode('/', $url);
     array_shift($parts);
     $response = new View();
     $action = "index";
     if (count($parts) == 1 && $parts[0] == "") {
         $parts[0] = 'home';
     }
     if (count($parts) > 1 && $parts[1] != "") {
         $action = trim($parts[1]);
     }
     $processed = false;
     if ($parts[0] && ClassManifest::has_class($parts[0]) && ClassManifest::is_a($parts[0], 'Controller')) {
         $page = new Page();
         $page->ID = -1;
         $page->URLSegment = $parts[0];
         $page->Title = 'Default Controller';
         $controller = new $parts[0]();
         if (method_exists($controller, 'getDefaultRecord')) {
             $page = $controller->getDefaultRecord();
         }
         $controller->setRecord($page);
         $response->setController($controller);
         if (method_exists($controller, $action)) {
             $response->setContents($controller->{$action}());
             $processed = true;
         }
     } else {
         if ($page = Page::find_one("URLSegment = '" . DB::raw2sql($parts[0]) . "'")) {
             $controller = $page->getController();
             $response->setController($controller);
             if (method_exists($controller, $action)) {
                 $response->setContents($controller->{$action}());
                 $processed = true;
             }
         }
     }
     if (!$processed) {
         $controller = new NotFoundController();
         $page = $controller->getDefaultRecord();
         $controller->setRecord($page);
         $response->setController($controller);
         $response->setContents($controller->index());
     }
     if (!headers_sent()) {
         http_response_code($controller->getHTTPCode());
     }
     echo $response->render();
 }
Esempio n. 2
0
 function GET()
 {
     $not_found = new NotFoundController();
     $not_found->render();
 }
Esempio n. 3
0
 /**
  * Executes the main application and wrap it into a response for the client.
  */
 private function exec()
 {
     $route = Route::getRoute();
     $admin = $route['admin'] == 1;
     $app = !empty($route['app']) ? $route['app'] : ($admin ? Config::get('config.defaultadminapp') : Config::get('config.defaultapp'));
     // Calculates app's directory and class name
     if ($admin) {
         $app_dir = APPS_DIR . $app . DS . 'admin' . DS;
         $app_name_clear = str_replace(' ', '', ucwords(preg_replace('#[^a-zA-Z]+#', ' ', $app)));
         $app_class = $app_name_clear . 'AdminController';
     } else {
         $app_dir = APPS_DIR . $app . DS;
         $app_name_clear = str_replace(' ', '', ucwords(preg_replace('#[^a-zA-Z]+#', ' ', $app)));
         $app_class = $app_name_clear . 'Controller';
     }
     if (is_dir($app_dir) && file_exists($app_dir . 'controller.php') && !$this->is404) {
         include_once $app_dir . 'controller.php';
         if (class_exists($app_class) && get_parent_class($app_class) == 'Controller') {
             $controller = new $app_class();
             // Instantiate Model if exists
             if (file_exists($app_dir . 'model.php')) {
                 include_once $app_dir . 'model.php';
                 $model_class = str_replace('Controller', 'Model', $app_class);
                 if (class_exists($model_class)) {
                     $controller->setModel(new $model_class());
                 }
             }
             // Instantiate View if exists
             if (file_exists($app_dir . 'view.php')) {
                 include_once $app_dir . 'view.php';
                 $view_class = str_replace('Controller', 'View', $app_class);
                 if (class_exists($view_class) && get_parent_class($view_class) == 'View') {
                     $controller->setView(new $view_class());
                 }
             }
         }
     } else {
         // Set header to a 404 code
         header('HTTP/1.0 404 Not Found');
         // Load the 404 app
         include_once APPS_DIR . '404' . DS . 'controller.php';
         include_once APPS_DIR . '404' . DS . 'view.php';
         $controller = new NotFoundController();
         $view = new NotFoundView();
         $controller->setView($view);
     }
     // Render the app
     $app_rendered = $controller->render();
     // Now render it in the global template
     include_once TEMPLATES_DIR . 'template' . ($admin ? '_admin' : '') . '.php';
 }