private static function _initDomain() { self::$cookies = array(); // Take domain from configuration to allow multiple subdomain compatibility with cookies. self::$domain = Domains::getInstance()->getDomain(); self::$path = '/'; }
public function __construct() { $this->working_instance = Config::getInstance()->getInstanceName(); $this->instance_static_host = Domains::getInstance()->getStaticHost(); // Contents will be accessible by static server under this path: $this->generated_files_public_path = $this->media_type . '/generated'; // Packed contents will be stored under this filesystem path. You can overwrite this property: $this->generated_files_folder = ROOT_PATH . '/instances/' . $this->working_instance . '/public/static/' . $this->generated_files_public_path; }
/** * 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; }
/** * 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); }
private function __construct() { // Init session cookie domain to allow sharing session // across multiple subdomains. ini_set('session.cookie_domain', '.' . Domains::getInstance()->getDomain()); if (!isset($_SESSION)) { if (headers_sent()) { trigger_error("Session: The session was not started before the sending of the headers."); return false; } else { // Session init. session_start(); } } }
/** * Connect to redis and return a redis object to start passing commands. * * If no profile is passed, default connection stated in domains.config.php is taken. Otherwise, profile * will be searched in redis.config.php. * * @param string $profile Connection profile. * @return \Predis\Client */ public function connect($profile = null) { if (!isset(self::$connected_client[$profile])) { PredisAutoloader::register(); if (null == $profile) { try { // Load "default" profile from redis.config.php: $db_params = Config::getInstance()->getConfig('redis', 'default'); } catch (Exception_Configuration $e) { // Connection taken from domains.config.php: $db_params = Domains::getInstance()->getParam('redis'); } } else { $db_params = Config::getInstance()->getConfig('redis', $profile); } self::$connected_client[$profile] = new \Predis\Client($db_params); $this->profile = $profile; } return self::$connected_client[$profile]; }
/** * Sets the controller and view properties and executes the controller, sending the output buffer. * * @param string $controller Dispatches a specific controller. */ public static function dispatch($controller) { // Set Timezone as required by php 5.1+ date_default_timezone_set('Europe/Madrid'); try { $config = Config::getInstance(self::$instance); $domain = Domains::getInstance(); self::$language = 'en_US'; // This is the controller to use: $ctrl = self::invokeController($controller); $ctrl->build(); // Debug: if (Domains::getInstance()->getDebugMode()) { $ctrl_debug = self::invokeController('DebugCommandLineDebug'); $ctrl_debug->build(); } } catch (\Exception $e) { echo $e->getMessage() . "\n" . $e->getTraceAsString(); die; } }
/** * Magic method to retrieve table names from a configuration file. * * @param string $attribute * * @return string */ public function __get($attribute) { $tablenames = Config::getInstance()->getConfig('tablenames'); $domain = Domains::getInstance()->getDomain(); if (isset($tablenames['names'][$domain][$attribute])) { return $tablenames['names'][$domain][$attribute]; } elseif (isset($tablenames['names']['default'][$attribute])) { return $tablenames['names']['default'][$attribute]; } return $attribute; }
protected function getGeneratedHashes() { if (Domains::getInstance()->getDevMode()) { return false; } $hashes = false; include_once $this->hashes_file; if (!$this->isGeneratedFilesUpToDate($revision)) { return false; } return $hashes; }
/** * Return Domains class instance * * @return Domains */ public static function Domains() { return Domains::getInstance(); }
/** * Returns the cache string identifier after calculating all the tags and prepending the necessary attributes. * * @param array $definition Cache definition. * * @return string */ public function getCacheKeyName(array $definition) { $cache_key = array(); $cache_base_key = array(); // First of all, let's construct the cache base with domain, language and controller name. $cache_base_key[] = Domains::getInstance()->getDomain(); $cache_base_key[] = Domains::getInstance()->getLanguage(); // Now we add the rest of identifiers of the definition excluding the "expiration". unset($definition['expiration']); if (!empty($definition)) { foreach ($definition as $key => $val) { $cache_key[] = $this->getCacheTag($key, $val); } sort($cache_key); } return implode('_', array_merge($cache_base_key, $cache_key)); }
/** * Get Sphinx connection params from config files. * * @return array * @throws Exception_500|Exception_Configuration */ protected function getConnectionParams($profile) { // The domains.config file has priority, let's fetch it. $sphinx_config = \Sifo\Domains::getInstance()->getParam('sphinx'); if (empty($sphinx_config)) { try { // If the domains.config doesn't define the params, we use the sphinx.config. $sphinx_config = Config::getInstance()->getConfig('sphinx'); if (isset($sphinx_config[$profile])) { $sphinx_config = $sphinx_config[$profile]; } elseif (isset($sphinx_config['default'])) { // Is using profiles but there isn't the required one. throw new \Sifo\Exception_500("Expected sphinx settings not defined for profile {$profile} in sphinx.config."); } else { if (Domains::getInstance()->getDebugMode() === true) { trigger_error("DEPRECATED: You aren't using profiles for your sphinx.config file. Please, define at leat the 'default' one. (This message is only readable with the debug flag enabled)"); } } $sphinx_config['config_file'] = 'sphinx'; } catch (Exception_Configuration $e) { throw new \Sifo\Exception_500('You must define the connection params in sphinx.config or domains.config file'); } } else { $sphinx_config['config_file'] = 'domains'; } return $sphinx_config; }
/** * Set Query Debug. Used in '__call' method. It checks if dev mode is enabled and then stores debug data in registry. * * @param $resultset * @param $tag * @param $method * @param $read_operation * @param $error * @return void */ protected function queryDebug($resultset, $tag, $method, $read_operation, $error) { if (!Domains::getInstance()->getDebugMode()) { return false; } $query = self::$adodb[self::$destination_type]->_querySQL; $query_time = Benchmark::getInstance()->timingCurrentToRegistry('db_queries'); $debug_query = array("tag" => $tag, "sql" => in_array($method, array('Affected_Rows', 'Insert_ID')) ? $method : $query, "type" => $read_operation ? 'read' : 'write', "destination" => self::$destination_type, "host" => self::$adodb[self::$destination_type]->host, "database" => self::$adodb[self::$destination_type]->database, "user" => self::$adodb[self::$destination_type]->user, "controller" => get_class($this), "resultset" => is_integer($resultset) ? array(array($method => $resultset)) : $resultset, "time" => $query_time, "error" => isset($error) ? $error : false, "duplicated" => false); if ($debug_query['type'] == 'read') { $debug_query['rows_num'] = count($resultset); } else { $debug_query['rows_num'] = 0; if ($method != 'close') { $debug_query['rows_num'] = self::$adodb[self::$destination_type]->Affected_Rows(); } } // Check duplicated queries. $queries_executed = Debug::get('executed_queries'); if (!empty($queries_executed) && isset($queries_executed[$debug_query['sql']])) { $debug_query['duplicated'] = true; Debug::push('duplicated_queries', 1); } Debug::subSet('executed_queries', $debug_query['sql'], 1); // Save query info in debug and add query errors if it's necessary. Debug::push('queries', $debug_query); if (isset($error)) { Debug::push('queries_errors', $error); } }
/** * Dispatches an error after an exception. * * @param Exception $e * * @return output buffer */ private static function _dispatchErrorController($e) { if (!isset($e->http_code)) { $e->http_code = 503; $e->http_code_msg = 'Exception!'; $e->redirect = false; } header('HTTP/1.0 ' . $e->http_code . ' ' . $e->http_code_msg); // Execute ErrorCommonController when an exception is captured. $ctrl2 = self::invokeController('error/common'); // Set params: $ctrl2->addParams(array('code' => $e->http_code, 'code_msg' => $e->http_code_msg, 'msg' => $e->getMessage(), 'trace' => $e->getTraceAsString())); // All the SEO_Exceptions with need of redirection have this attribute: if ($e->redirect) { // Path is passed via message: $path = trim($e->getMessage(), '/'); $new_location = ''; // Check if the URL for the redirection has already a protocol, like http:// , https://, ftp://, etc.. if (false !== strpos($path, '://')) { // Absolute path passed: $new_location = $path; } else { // Relative path passed, use path as the key in url.config.php file: $new_location = Urls::getUrl($path); } if (empty($new_location) || false == $new_location) { trigger_error("Exception " . $e->http_code . " raised with an empty location " . $e->getTraceAsString()); header('HTTP/1.0 500 Internal Server Error'); exit; } if (!Domains::getInstance()->getDebugMode()) { header("Location: " . $new_location, true, $e->http_code); } else { $ctrl2->addParams(array('url_redirect' => $new_location)); $ctrl2->dispatch(); self::invokeController('debug/index')->dispatch(); return; } } $result = $ctrl2->dispatch(); // Load the debug in case you have enabled the has debug flag. if (Domains::getInstance()->getDebugMode()) { self::invokeController('debug/index')->dispatch(); } return $result; }
/** * Returns whether the debug is available or not. * * @deprecated Please use Domains::getInstance()->getDebugMode() instead. * @return boolean */ public function hasDebug() { return Domains::getInstance()->getDebugMode(); }
private function __construct($instance_name) { $domains = Domains::getInstance($instance_name); $filter_server = FilterServer::getInstance(); $language = $domains->getLanguage(); $clean_host = preg_replace('/^' . $domains->getSubdomain() . '\\./', '', $domains->getDomain()); if ($filter_server->getString('HTTPS')) { self::$scheme = 'https'; } if (true === $domains->www_mode) { self::$main_url = 'http://www.' . $clean_host; } else { self::$main_url = 'http://' . $clean_host; } // E.g: http://domain.com/folder1/subfolder1/subfolder11 self::$base_url = self::$scheme . '://' . $filter_server->getString('HTTP_HOST'); self::$url_definition = Config::getInstance($instance_name)->getConfig('url_definition'); // Default url.config for all languages. self::$url_config = Config::getInstance($instance_name)->getConfig('url'); $original_path = $filter_server->getString('REQUEST_URI'); $query_string = $filter_server->getString('QUERY_STRING'); $path = urldecode(str_replace('?' . $query_string, '', $original_path)); // E.g: http://subdomain.domain.com/folder1_param:x:value:y:value?utm_campaign=enloquecer_al_larry self::$actual_url = self::$base_url . $original_path; // If url ends in slash, remove it and redirect: if (strlen($path) > 1 && substr($path, -1) == '/') { $path = trim($path, '/'); header('HTTP/1.0 Moved Permanently 301'); header('Location: ' . $this->getBaseUrl() . "/{$path}"); } $path = ltrim($path, '/'); // Separate parameters from URL: $params_parts = explode(self::$url_definition['params_separator'], $path); // Path is the first part of the explode, rest are parameters. self::$path = array_shift($params_parts); if (count($params_parts) > 0) { self::$params = $params_parts; } else { self::$params = array(); } self::$path_parts = explode(self::$url_definition['context_separator'], self::$path); }
/** * Returns the translation of a string * * @param string $subject * @param string $var_1 * @param string $var2 * @param string $var_n * @return string */ public function translate($subject, $var_1 = '', $var2 = '', $var_n = '') { $args = func_get_args(); $variables = array(); if (1 < count($args)) { foreach ($args as $key => $value) { $variables['%' . $key] = $value; } } unset($variables['%0']); return I18N::getInstance('messages', Domains::getInstance()->getLanguage())->getTranslation($subject, $variables); }