Пример #1
0
 public function getUrl($relative_path, $params = null)
 {
     $url = Urls::getInstance($this->instance)->getUrl($relative_path);
     if (!$url && '' != $relative_path) {
         /*
          * The relative_path exists but the first getUrl try not found it.
          * We try with the path translations:
          */
         if (Router::getReversalRoute($relative_path)) {
             if (!($url = Urls::getInstance($this->instance)->getUrl(Router::getReversalRoute($relative_path)))) {
                 // Fixed the current_url in url like word1_word2 for url word1-word2
                 $url = Urls::getInstance($this->instance)->getUrl(Router::getReversalRoute(str_replace('-', '_', $relative_path)));
             }
         } else {
             $url = Urls::$base_url . '/' . $relative_path;
         }
     }
     if ($params) {
         $url .= $this->url_definition['params_separator'];
         if (is_array($params)) {
             $url .= implode($this->url_definition['params_separator'], $params);
         } else {
             $url .= $params;
         }
     }
     return $url;
 }
Пример #2
0
 /**
  * Get metadata. It uses the metadata key or path to return the metadata.
  *
  * @return array
  */
 public static function get()
 {
     $metadata_info = self::_getMetadataInformation();
     $metadata_raw = Config::getInstance()->getConfig('lang/metadata_' . Domains::getInstance()->getLanguage());
     $metadata = $metadata_raw['default'];
     if (isset($metadata_info['metadata_key'])) {
         $metadata = $metadata_raw[$metadata_info['metadata_key']];
     } else {
         $reversal_path = Router::getReversalRoute(Urls::getInstance(Bootstrap::$instance)->getPath());
         if ($reversal_path && isset($metadata_raw[$reversal_path])) {
             $metadata = $metadata_raw[$reversal_path];
         }
     }
     return self::_replaceVars($metadata, $metadata_info);
 }
Пример #3
0
 /**
  * Sets the controller and view properties and executes the controller, sending the output buffer.
  *
  * @param string $controller Dispatches a specific controller, or use URL to determine the controller
  */
 public static function dispatch($controller = null)
 {
     try {
         $domain = Domains::getInstance();
         $destination = $domain->getRedirect();
         if (!empty($destination)) {
             header('HTTP/1.0 301 Moved Permanently');
             header("Location: " . $destination, true, 301);
             exit;
         }
         $auth_data = $domain->getAuthData();
         if (!empty($auth_data) && FilterCookie::getInstance()->getString('domain_auth') != $auth_data['hash']) {
             $filter_server = FilterServer::getInstance();
             if ($filter_server->isEmpty('PHP_AUTH_USER') || $filter_server->isEmpty('PHP_AUTH_PW') || $filter_server->getString('PHP_AUTH_USER') != $auth_data['user'] || $filter_server->getString('PHP_AUTH_PW') != $auth_data['password']) {
                 header('WWW-Authenticate: Basic realm="Protected page"');
                 throw new Exception_401('You should enter a valid credentials.');
             }
             // If the user is authorized, we save a session cookie to prevent multiple auth under subdomains in the same session.
             setcookie('domain_auth', $auth_data['hash'], 0, '/', $domain->getDomain());
         }
         self::$language = $domain->getLanguage();
         $php_inis = $domain->getPHPInis();
         if ($php_inis) {
             self::_overWritePHPini($php_inis);
         }
         $url = Urls::getInstance(self::$instance);
         $path_parts = $url->getPathParts();
         if (!$domain->valid_domain) {
             throw new Exception_404('Unknown language in domain');
         } else {
             if (null === $controller) {
                 $router = new Router($path_parts[0], self::$instance, $domain->getSubdomain(), self::$language, $domain->www_mode);
                 $controller = $router->getController();
             }
         }
         // This is the controller to use:
         $ctrl = self::invokeController($controller);
         // Save in params for future references:
         $ctrl->addParams(array('controller_route' => $controller));
         // Active/deactive auto-rebuild option:
         if ($domain->getDevMode()) {
             $ctrl->getClass('Cookie');
             if (FilterGet::getInstance()->getInteger('rebuild_all')) {
                 Cookie::set('rebuild_all', 1);
             }
             if (FilterGet::getInstance()->getInteger('rebuild_nothing') && FilterCookie::getInstance()->getInteger('rebuild_all')) {
                 Cookie::delete('rebuild_all');
             }
             if (1 === FilterGet::getInstance()->getInteger('debug')) {
                 Cookie::set('debug', 1);
             }
             if (0 === FilterGet::getInstance()->getInteger('debug')) {
                 Cookie::set('debug', 0);
             }
             if (false !== ($debug = FilterCookie::getInstance()->getInteger('debug'))) {
                 Domains::getInstance()->setDebugMode((bool) $debug);
             }
         }
         $ctrl->dispatch();
         if (false === $ctrl->is_json && Domains::getInstance()->getDebugMode()) {
             self::invokeController('debug/index')->dispatch();
         }
     } catch (\Exception $e) {
         self::_dispatchErrorController($e);
     }
 }