Esempio n. 1
0
 /**
  * Returns tha contents in cache or false.
  *
  * @return mixed
  */
 protected function grabCache()
 {
     if (Domains::getInstance()->getDevMode() && (FilterCookie::getInstance()->getInteger('rebuild_all') || FilterGet::getInstance()->getInteger('rebuild'))) {
         return false;
     }
     $cache_key = $this->parseCache();
     // Controller does not use cache:
     if (!$cache_key) {
         return false;
     }
     $cache = new CacheDisk();
     $content = $cache->get($cache_key['name']);
     return $content ? $content : false;
 }
Esempio n. 2
0
 /**
  * Returns if current execution allows rebuilding the page.
  *
  * @return bool
  */
 public function hasRebuild()
 {
     return Domains::getInstance()->getDevMode() && (FilterGet::getInstance()->getInteger('rebuild') || FilterCookie::getInstance()->getInteger('rebuild_all'));
 }
Esempio n. 3
0
 /**
  * Dispatch the controller.
  */
 public function dispatch()
 {
     if (Domains::getInstance()->getDebugMode() && FilterGet::getInstance()->getInteger('kill_session')) {
         @Session::getInstance()->destroy();
     }
     if ($this->is_json) {
         // Set headers before cache:
         if ($json_callback = FilterGet::getInstance()->getString('json_callback')) {
             header('Content-type: text/javascript');
         } else {
             header('Content-type: application/json');
         }
     }
     $benchmark_key = 'controller_execution_time_parent';
     $this->startBench($benchmark_key);
     $this->preDispatch();
     $cached_content = $this->grabCache();
     if (false !== $cached_content) {
         $this->postDispatch();
         $cached_content = $this->_realTimeReplacement($cached_content);
         echo $cached_content;
         return;
     }
     $cache_key = $this->parseCache();
     if (false !== $cache_key) {
         $this->addToDebug('name', $cache_key['name'], 'Cache properties');
         $this->addToDebug('expiration', $cache_key['expiration'], 'Cache properties');
     }
     $return = $this->build();
     $controller_params = array_merge(array('layout' => $this->layout), $this->getParams());
     $this->addToDebug('parameters', $controller_params, 'CONTROLLER');
     $this->executeNestedModules();
     if ($this->is_json) {
         $json_callback = FilterGet::getInstance()->getString('json_callback');
         $content = $json_callback ? $json_callback . '(' . json_encode($return) . ')' : json_encode($return);
     } else {
         $content = $this->grabHtml();
     }
     if (false !== $cache_key) {
         $this->cache->set($cache_key['name'], $content, $cache_key['expiration']);
     }
     $this->postDispatch();
     $this->stopBench($benchmark_key, "----- TOTAL " . get_class($this) . " + PREVIOUS MODULES -----");
     $content = $this->_realTimeReplacement($content);
     echo $content;
 }
Esempio n. 4
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);
     }
 }