Example #1
0
 public function getView(Flux_Template $template, $module, $action)
 {
     $path = "{$this->themeDir}/" . $template->getName() . "/{$module}/{$action}.php";
     if (file_exists($path)) {
         return $path;
     }
     if (!empty($template->parentTemplate)) {
         return $this->getView($template->parentTemplate, $module, $action);
     }
     return false;
 }
Example #2
0
 /**
  * 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();
 }
Example #3
0
 /**
  * Similar to the path() method, but uses the $themePath as the path from
  * which the user-specified path is relative.
  *
  * @param string $path Relative path from themePath.
  * @access public
  */
 public function themePath($path, $included = false)
 {
     if (is_array($path)) {
         $path = implode('/', $path);
     }
     // Remove frag for file checking.
     $frag = "";
     preg_match("/(\\?|\\#).*/", $path, $matches);
     if (count($matches)) {
         $frag = $matches[0];
         $path = substr($path, 0, -strlen($frag));
     }
     $uri = $this->path("{$this->themePath}/{$this->themeName}/{$path}", $included);
     // normalized basePath.
     $base = preg_replace('/(\\/+)$/', '', $this->basePath) . '/';
     $base = preg_quote($base, '/');
     $chk = FLUX_ROOT . '/' . preg_replace('/^(' . $base . ')/', '', $uri);
     // If file not found, search in parent's template.
     if (!file_exists($chk) && !empty($this->parentTemplate)) {
         $path = $this->parentTemplate->themePath($path, $included);
         $chk = FLUX_ROOT . '/' . preg_replace('/^(' . $base . ')/', '', $path);
         if (file_exists($chk)) {
             $uri = $path;
         }
     }
     return $uri . $frag;
 }