/** * 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; }
/** * Returns a sanitized Cookie. * * @param array $cookies * @return string|false */ private static function _sanitizeCookie($cookie) { if (FilterCookie::getInstance()->isSent($cookie)) { return FilterCookie::getInstance()->getString($cookie); } return false; }
/** * 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')); }
/** * 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); } }