public static function process($request, $params = array(), $post = false) { self::$_resourceTheme = 'default'; include 'static/default/resources.coorg.php'; $theme = self::$_config->get('theme'); if (!$theme) $theme = 'default'; if ($theme != 'default') { self::$_resourceTheme = $theme; if (file_exists('static/'.$theme.'/resources.coorg.php')) { include 'static/'.$theme.'/resources.coorg.php'; } } self::normalizeRequest($request); $url = $request; if ($request == '/' || $request == '') $request = 'home'; $requestParams = explode('/', $request); $controllerName = ucfirst(array_shift($requestParams)); $prefix = null; $requestWithoutPrefix = $request; if (strlen($controllerName) == 2) { $prefix = strtolower($controllerName).'/'; I18n::setLanguage(strtolower($controllerName)); $requestWithoutPrefix = implode('/', $requestParams); if (count($requestParams) > 0) { $controllerName = ucfirst(array_shift($requestParams)); } else { $controllerName = 'Home'; } } else { $found = false; //TODO: move Language DB to default install // and unittest this... (in the CoOrg tests). if (class_exists('Language')) { $preferredLanguages = Session::getPreferredLanguages(); $installedLanguages = Language::languageCodes(); // This is in the admin class, but should really be in the default instal foreach ($preferredLanguages as $lc) { if (in_array($lc, $installedLanguages)) { $found = true; I18n::setLanguage($lc); break; } else if (strpos($lc, '-')) { $slc = substr($lc, 0, strpos($lc, '-')); if (in_array($slc, $installedLanguages)) { $found = true; I18n::setLanguage($slc); break; } } } } if (!$found && self::$_config->has('defaultLanguage')) { I18n::setLanguage(self::$_config->get('defaultLanguage')); } } try { list($controllerClass, $action, $params, $request, $parentClasses) = self::findController($controllerName, $requestParams, $params, $post); $controllerClass->coorgRequest = $requestWithoutPrefix; $coorgUrl = self::config()->get('path').$prefix.$requestWithoutPrefix; self::normalizeRequest($coorgUrl); $controllerClass->coorgUrl = $coorgUrl; $controllerClass->staticPath = self::$_config->get('path').'static/'; $controllerClass->coorgLanguage = self::getLanguage(); if (!$post && $controllerClass->isPost($action)) { throw new WrongRequestMethodException(); } if ($post && strpos(Session::getReferrer(), Session::getSite()) === false) { throw new WrongRequestMethodException(); } self::$_request = $request; self::$_requestParameters = $params; $continue = true; foreach ($parentClasses as $pClassName) { $pClass = new $pClassName; $continue = $pClass->beforeFilters(null, self::$_beforeFilters, $params); if (!$continue) { break; } } if ($continue && $controllerClass->beforeFilters($action, self::$_beforeFilters, $params)) { try { call_user_func_array(array($controllerClass, $action), $params); } catch (Exception $e) { $controllerClass->systemError($request, Session::getReferrer(), $e); } } $controllerClass->done(); } catch (RequestNotFoundException $e) { $controller = new Controller(); $controller->init('.', self::$_appdir); $controller->notFound($request, Session::getReferrer(), $e); return; } catch (Exception $e) { $controller = new Controller(); $controller->init('.', self::$_appdir); $controller->systemError($request, Session::getReferrer(), $e); return; } }