Exemple #1
0
 /**
  * Get the used url to access. This info is important to resolve defined 301 redirections.
  *
  * @return string The used url.
  */
 public static function getUsedUrl()
 {
     $server = FilterServer::getInstance();
     $used_url = 'http';
     if ($server->getString("HTTPS") == "on") {
         $used_url .= "s";
     }
     $used_url .= "://";
     if ($server->getString('HTTP_HOST')) {
         $hostname = $server->getString('HTTP_HOST');
     } else {
         $hostname = $server->getString("SERVER_NAME");
     }
     if ($server->getString('SERVER_PORT') != "80") {
         $used_url .= $hostname . ":" . $server->getString('SERVER_PORT') . $server->getString("REQUEST_URI");
     } else {
         $used_url .= $hostname . $server->getString("REQUEST_URI");
     }
     return $used_url;
 }
Exemple #2
0
 /**
  * Returns the hosts holding the multimedia content (user avatars, videos, audio, photos...)
  *
  * @return string
  */
 public function getMediaHost()
 {
     $filter_server = FilterServer::getInstance();
     if ($filter_server->getString('HTTPS')) {
         return str_replace('http://', 'https://', $this->media_host);
     }
     return $this->media_host;
 }
Exemple #3
0
 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);
 }
Exemple #4
0
 /**
  * Determines if actual client is a Mobile Device
  * based on USERAGENTS contained in Browscap library.
  */
 public static function isMobile()
 {
     if (Registry::keyExists('Client_isMobile')) {
         return Registry::get('Client_isMobile');
     } else {
         $answer = false;
         $useragent = FilterServer::getInstance()->getString('HTTP_USER_AGENT');
         // Regular expression from http://detectmobilebrowsers.com/
         // Updated on 20th June 2012
         if (preg_match('/android.+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $useragent) || preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)|hp( i|ip)|hs\\-c|ht(c(\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\-(20|go|ma)|i230|iac( |\\-|\\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\/)|klon|kpt |kwc\\-|kyo(c|k)|le(no|xi)|lg( g|\\/(k|l|u)|50|54|\\-[a-w])|libw|lynx|m1\\-w|m3ga|m50\\/|ma(te|ui|xo)|mc(01|21|ca)|m\\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\\-2|po(ck|rt|se)|prox|psio|pt\\-g|qa\\-a|qc(07|12|21|32|60|\\-[2-7]|i\\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\-|oo|p\\-)|sdk\\/|se(c(\\-|0|1)|47|mc|nd|ri)|sgh\\-|shar|sie(\\-|m)|sk\\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\-|v\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\\-|tdg\\-|tel(i|m)|tim\\-|t\\-mo|to(pl|sh)|ts(70|m\\-|m3|m5)|tx\\-9|up(\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\\-|your|zeto|zte\\-/i', substr($useragent, 0, 4))) {
             $answer = true;
         }
         Registry::set('Client_isMobile', $answer);
         return $answer;
     }
 }
Exemple #5
0
    {
        return false !== strpos($var, ".");
    }
    public static function get_available_domains()
    {
        $domain_configuration = Config::getInstance()->getConfig('domains');
        $configuration_keys = array_keys($domain_configuration);
        $available_domains = array_filter($configuration_keys, "self::is_domain");
        return $available_domains;
    }
}
// Instance name (folder under instances):
$cwd = $_SERVER['PWD'] . '/' . $_SERVER['PHP_SELF'];
preg_match("/\\/([^\\/]+)\\/([^\\/]+)\\/[^\\/]+\$/", $cwd, $matchs);
// Set the real and active instance name.
CLBootstrap::$instance = $matchs[1];
// Include required SIFO classes.
CLBootstrap::includeRequiredFiles();
if (!isset($argv[1]) || '-h' == $argv[1] || '--help' == $argv[1]) {
    // Dump help info:
    require_once ROOT_PATH . '/instances/common/controllers/shared/commandLine.ctrl.php';
    echo PHP_EOL . "Execute 'php {$argv['0']} <domain> --help' to read the help information." . PHP_EOL . PHP_EOL;
    echo "Your available domains:" . PHP_EOL;
    $available_domains = CLBootstrap::get_available_domains();
    echo implode($available_domains, PHP_EOL);
    die;
}
CLBootstrap::$command_line_params = $argv;
// Setting the domain.
FilterServer::getInstance()->setHost($argv[1]);
Exemple #6
0
    /**
     * Log mysql_errors to disk:
     *
     * @param $error
     * @return void
     */
    protected function writeDiskLog($error)
    {
        $date = date('d-m-Y H:i:s');
        $referer = FilterServer::getInstance()->getString('HTTP_REFERER');
        $current_url = FilterServer::getInstance()->getString('SCRIPT_URI');
        // Log mysql_errors to disk:
        $message = <<<MESSAGE
================================
Date: {$date}
URL: {$current_url}
Referer: {$referer}

Error: {$error}
MESSAGE;
        file_put_contents(ROOT_PATH . '/logs/errors_database.log', $message, FILE_APPEND);
    }
Exemple #7
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);
     }
 }