require_once MO_APP_DIR . '/version.php'; // required classes for this file and ConfigCache to run require_once MO_APP_DIR . '/core/MojaviObject.class.php'; require_once MO_APP_DIR . '/util/ParameterHolder.class.php'; require_once MO_APP_DIR . '/config/ConfigCache.class.php'; require_once MO_APP_DIR . '/config/ConfigHandler.class.php'; require_once MO_APP_DIR . '/config/ParameterParser.class.php'; require_once MO_APP_DIR . '/config/IniConfigHandler.class.php'; require_once MO_APP_DIR . '/config/AutoloadConfigHandler.class.php'; require_once MO_APP_DIR . '/config/RootConfigHandler.class.php'; require_once MO_APP_DIR . '/exception/MojaviException.class.php'; require_once MO_APP_DIR . '/exception/AutoloadException.class.php'; require_once MO_APP_DIR . '/exception/CacheException.class.php'; require_once MO_APP_DIR . '/exception/ConfigurationException.class.php'; require_once MO_APP_DIR . '/exception/ParseException.class.php'; require_once MO_APP_DIR . '/util/Toolkit.class.php'; // clear our cache if the conditions are right if (MO_DEBUG) { ConfigCache::clear(); } // load base settings ConfigCache::import('config/settings.ini'); // required classes for the framework ConfigCache::import('config/compile.conf'); } catch (MojaviException $e) { $e->printStackTrace(); } catch (Exception $e) { // unknown exception $e = new MojaviException($e->getMessage()); $e->printStackTrace(); }
/** * Forward the request to another action. * * @param string A module name. * @param string An action name. * * @return void * * @throws <b>ConfigurationException</b> If an invalid configuration setting * has been found. * @throws <b>ForwardException</b> If an error occurs while forwarding the * request. * @throws <b>InitializationException</b> If the action could not be * initialized. * @throws <b>SecurityException</b> If the action requires security but * the user implementation is not of type * SecurityUser. * * @author Sean Kerr (skerr@mojavi.org) * @since 1.0.0 */ public function forward($moduleName, $actionName) { // replace periods with slashes for action sub-directories $actionName = str_replace('.', '/', $actionName); // replace unwanted characters $moduleName = preg_replace('/[^a-z0-9\\-_]+/i', '', $moduleName); $actionName = preg_replace('/[^a-z0-9\\-_\\/]+/i', '', $actionName); if ($this->actionStack->getSize() >= $this->maxForwards) { // let's kill this party before it turns into cpu cycle hell $error = 'Too many forwards have been detected for this request'; throw new ForwardException($error); } if (!MO_AVAILABLE) { // application is unavailable $moduleName = MO_UNAVAILABLE_MODULE; $actionName = MO_UNAVAILABLE_ACTION; if (!$this->actionExists($moduleName, $actionName)) { // cannot find unavailable module/action $error = 'Invalid configuration settings: ' . 'MO_UNAVAILABLE_MODULE "%s", ' . 'MO_UNAVAILABLE_ACTION "%s"'; $error = sprintf($error, $moduleName, $actionName); throw new ConfigurationException($error); } } else { if (!$this->actionExists($moduleName, $actionName)) { // the requested action doesn't exist // track the requested module so we have access to the data // in the error 404 page $this->request->setAttribute('requested_action', $actionName); $this->request->setAttribute('requested_module', $moduleName); // switch to error 404 action $moduleName = MO_ERROR_404_MODULE; $actionName = MO_ERROR_404_ACTION; if (!$this->actionExists($moduleName, $actionName)) { // cannot find unavailable module/action $error = 'Invalid configuration settings: ' . 'MO_ERROR_404_MODULE "%s", ' . 'MO_ERROR_404_ACTION "%s"'; $error = sprintf($error, $moduleName, $actionName); throw new ConfigurationException($error); } } } // create an instance of the action $actionInstance = $this->getAction($moduleName, $actionName); // add a new action stack entry $this->actionStack->addEntry($moduleName, $actionName, $actionInstance); // include the module configuration ConfigCache::import('modules/' . $moduleName . '/config/module.ini'); if (constant('MOD_' . strtoupper($moduleName) . '_ENABLED')) { // module is enabled // check for a module config.php $moduleConfig = MO_MODULE_DIR . '/' . $moduleName . '/config.php'; if (is_readable($moduleConfig)) { require_once $moduleConfig; } // initialize the action if ($actionInstance->initialize($this->context)) { // create a new filter chain $filterChain = new FilterChain(); if (MO_AVAILABLE) { // the application is available so we'll register // global and module filters, otherwise skip them // does this action require security? if (MO_USE_SECURITY && $actionInstance->isSecure()) { if (!$this->user instanceof SecurityUser) { // we've got security on but the user implementation // isn't a sub-class of SecurityUser $error = 'Security is enabled, but your User ' . 'implementation isn\'t a sub-class of ' . 'SecurityUser'; throw new SecurityException($error); } // register security filter $filterChain->register($this->securityFilter); } // load filters $this->loadGlobalFilters($filterChain); $this->loadModuleFilters($filterChain); } // register the execution filter $execFilter = new ExecutionFilter(); $execFilter->initialize($this->context); $filterChain->register($execFilter); if ($moduleName == MO_ERROR_404_MODULE && $actionName == MO_ERROR_404_ACTION) { header('HTTP/1.0 404 Not Found'); header('Status: 404 Not Found'); } // process the filter chain $filterChain->execute(); } else { // action failed to initialize $error = 'Action initialization failed for module "%s", ' . 'action "%s"'; $error = sprintf($error, $moduleName, $actionName); throw new InitializationException($error); } } else { // module is disabled $moduleName = MO_MODULE_DISABLED_MODULE; $actionName = MO_MODULE_DISABLED_ACTION; if (!$this->actionExists($moduleName, $actionName)) { // cannot find mod disabled module/action $error = 'Invalid configuration settings: ' . 'MO_MODULE_DISABLED_MODULE "%s", ' . 'MO_MODULE_DISABLED_ACTION "%s"'; $error = sprintf($error, $moduleName, $actionName); throw new ConfigurationException($error); } $this->forward($moduleName, $actionName); } }