/** * Wrapper method for setting and getting values from the access config. * * @param string $key * @param mixed $value * @param arary $options * @access public */ public function config($key, $value = null, $options = array()) { if (!is_null($value)) { return $this->config->set($key, $value, $options); } else { return $this->config->get($key); } }
/** * Wrapper method for setting and getting values from the messagesConfig. * * @param string $key * @param mixed $value * @param arary $options * @access public */ public static function message($key, $value = null, $options = array()) { if (!is_null($value)) { return self::$messagesConfig->set($key, $value, $options); } else { return self::$messagesConfig->get($key); } }
/** * Initialize char/map pair Flux_Athena pair. * * @param Flux_Connection $connection * @param Flux_Config $charMapConfig * @param Flux_LoginServer $loginServer * @param Flux_CharServer $charServer * @param Flux_MapServer $mapServer * @access public */ public function __construct(Flux_Config $charMapConfig, Flux_LoginServer $loginServer, Flux_CharServer $charServer, Flux_MapServer $mapServer) { $this->loginServer = $loginServer; $this->charServer = $charServer; $this->mapServer = $mapServer; $this->loginDatabase = $loginServer->config->getDatabase(); $this->serverName = $charMapConfig->getServerName(); $this->maxBaseLevel = (int) $charMapConfig->getMaxBaseLevel(); $this->expRates = $charMapConfig->getExpRates()->toArray(); $this->dropRates = $charMapConfig->getDropRates()->toArray(); $this->isRenewal = (bool) $charMapConfig->getRenewal(); $this->maxCharSlots = (int) $charMapConfig->getMaxCharSlots(); $this->dateTimezone = $charMapConfig->getDateTimezone(); $this->charMapDatabase = $charMapConfig->getDatabase(); $resetDenyMaps = $charMapConfig->getResetDenyMaps(); if (!$resetDenyMaps) { $this->resetDenyMaps = array('sec_pri'); } elseif (!is_array($resetDenyMaps)) { $this->resetDenyMaps = array($resetDenyMaps); } else { $this->resetDenyMaps = $resetDenyMaps->toArray(); } // Get WoE times specific in servers config. $woeDayTimes = $charMapConfig->getWoeDayTimes(); if ($woeDayTimes instanceof Flux_Config) { $woeDayTimes = $woeDayTimes->toArray(); foreach ($woeDayTimes as $dayTime) { if (!is_array($dayTime) || count($dayTime) < 4) { continue; } list($sDay, $sTime, $eDay, $eTime) = array_slice($dayTime, 0, 4); $sTime = trim($sTime); $eTime = trim($eTime); if ($sDay < 0 || $sDay > 6 || $eDay < 0 || $eDay > 6 || !preg_match('/^\\d{2}:\\d{2}$/', $sTime) || !preg_match('/^\\d{2}:\\d{2}$/', $eTime)) { continue; } $this->woeDayTimes[] = array('startingDay' => $sDay, 'startingTime' => $sTime, 'endingDay' => $eDay, 'endingTime' => $eTime); } } // Config used for disallowing access to certain modules during WoE. $woeDisallow = $charMapConfig->getWoeDisallow(); $_tempArray = array(); $this->woeDisallow = new Flux_Config($_tempArray); if ($woeDisallow instanceof Flux_Config) { $woeDisallow = $woeDisallow->toArray(); foreach ($woeDisallow as $disallow) { if (array_key_exists('module', $disallow)) { $module = $disallow['module']; if (array_key_exists('action', $disallow)) { $action = $disallow['action']; $this->woeDisallow->set("{$module}.{$action}", true); } else { $this->woeDisallow->set($module, true); } } } } }
/** * Dispatch current request to the correct action and render the view. * * @param array $options Options for the dispatcher. * @access public */ public function dispatch($options = array()) { $config = new Flux_Config($options); $basePath = $config->get('basePath'); $paramsArr = $config->get('params'); $modulePath = $config->get('modulePath'); $themePath = $config->get('themePath'); $themeName = $config->get('themeName'); $defaultModule = $config->get('defaultModule'); $defaultAction = $config->get('defaultAction'); $missingActionModuleAction = $config->get('missingActionModuleAction'); $missingViewModuleAction = $config->get('missingViewModuleAction'); $useCleanUrls = $config->get('useCleanUrls'); if (!$defaultModule && $this->defaultModule) { $defaultModule = $this->defaultModule; } if (!$defaultAction && $this->defaultAction) { $defaultAction = $this->defaultAction; } if (!$defaultModule) { throw new Flux_Error('Please set the default module with $dispatcher->setDefaultModule()'); } elseif (!$defaultAction) { throw new Flux_Error('Please set the default action with $dispatcher->setDefaultAction()'); } if (!$paramsArr) { $paramsArr =& $_REQUEST; } // Provide easier access to parameters. $params = new Flux_Config($paramsArr); $baseURI = Flux::config('BaseURI'); if ($params->get('module')) { $safetyArr = array('..', '/', '\\'); $moduleName = str_replace($safetyArr, '', $params->get('module')); if ($params->get('action')) { $actionName = str_replace($safetyArr, '', $params->get('action')); } else { $actionName = $defaultAction; } } elseif (Flux::config('UseCleanUrls')) { $baseURI = preg_replace('&/+&', '/', rtrim($baseURI, '/')) . '/'; $requestURI = preg_replace('&/+&', '/', rtrim($_SERVER['REQUEST_URI'], '/')) . '/'; $requestURI = preg_replace('&\\?.*?$&', '', $requestURI); $components = explode('/', trim((string) substr($requestURI, strlen($baseURI)), '/')); $moduleName = empty($components[0]) ? $defaultModule : $components[0]; $actionName = empty($components[1]) ? $defaultAction : $components[1]; } elseif (!$params->get('module') && !$params->get('action')) { $moduleName = $defaultModule; $actionName = $defaultAction; } // Authorization handling. $auth = Flux_Authorization::getInstance(); if ($auth->actionAllowed($moduleName, $actionName) === false) { if (!Flux::$sessionData->isLoggedIn()) { Flux::$sessionData->setMessageData('Please log-in to continue.'); $this->loginRequired($baseURI); } else { $moduleName = 'unauthorized'; $actionName = $this->defaultAction; } } $params->set('module', $moduleName); $params->set('action', $actionName); $templateArray = array('params' => $params, 'basePath' => $basePath, 'modulePath' => $modulePath, 'moduleName' => $moduleName, 'themePath' => $themePath, 'themeName' => $themeName, 'actionName' => $actionName, 'viewName' => $actionName, 'headerName' => 'header', 'footerName' => 'footer', 'missingActionModuleAction' => $missingActionModuleAction, 'missingViewModuleAction' => $missingViewModuleAction, 'useCleanUrls' => $useCleanUrls); $templateConfig = new Flux_Config($templateArray); $template = new Flux_Template($templateConfig); // Default data available to all actions and views. $data = array('auth' => Flux_Authorization::getInstance(), 'session' => Flux::$sessionData, 'params' => $params); $template->setDefaultData($data); // Render template! :D $template->render(); }
/** * Construct new template onbject. * * @param Flux_Config $config * @access public */ public function __construct(Flux_Config $config) { $this->params = $config->get('params'); $this->basePath = $config->get('basePath'); $this->modulePath = $config->get('modulePath'); $this->moduleName = $config->get('moduleName'); $this->themePath = $config->get('themePath'); $this->themeName = $config->get('themeName'); $this->actionName = $config->get('actionName'); $this->viewName = $config->get('viewName'); $this->headerName = $config->get('headerName'); $this->footerName = $config->get('footerName'); $this->useCleanUrls = $config->get('useCleanUrls'); $this->missingActionModuleAction = $config->get('missingActionModuleAction', false); $this->missingViewModuleAction = $config->get('missingViewModuleAction', false); $this->referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; // Read manifest file if exists if (file_exists($this->themePath . '/' . $this->themeName . '/manifest.php')) { $manifest = (include $this->themePath . '/' . $this->themeName . '/manifest.php'); // Inherit views and controllers from another template if (!empty($manifest['inherit'])) { if (in_array($manifest['inherit'], self::$themeLoaded)) { throw new Flux_Error('Circular dependencies in themes : ' . implode(' -> ', self::$themeLoaded) . ' -> ' . $manifest['inherit']); } $config->set('themeName', $manifest['inherit']); self::$themeLoaded[] = $manifest['inherit']; $this->parentTemplate = new Flux_Template($config); } } }