/** * l'URL de base du site, sans se fier a meta(adresse_site) qui * peut etre fausse (sites a plusieurs noms d'hotes, deplacements, erreurs) * Note : la globale $profondeur_url doit etre initialisee de maniere a * indiquer le nombre de sous-repertoires de l'url courante par rapport a la * racine de SPIP : par exemple, sur ecrire/ elle vaut 1, sur sedna/ 1, et a * la racine 0. Sur url/perso/ elle vaut 2 * http://code.spip.net/@url_de_base * * @param int|boo|array $profondeur * si non renseignee : retourne l'url pour la profondeur $GLOBALS['profondeur_url'] * si int : indique que l'on veut l'url pour la prondeur indiquee * si bool : retourne le tableau static complet * si array : reinitialise le tableau static complet avec la valeur fournie * @return string|array */ function url_de_base($profondeur = null) { static $url = array(); if (is_array($profondeur)) { return $url = $profondeur; } if ($profondeur === false) { return $url; } if (is_null($profondeur)) { $profondeur = $GLOBALS['profondeur_url']; } if (isset($url[$profondeur])) { return $url[$profondeur]; } $http = (isset($_SERVER["SCRIPT_URI"]) and substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https' or isset($_SERVER['HTTPS']) and test_valeur_serveur($_SERVER['HTTPS'])) ? 'https' : 'http'; if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { $host = strtr($_SERVER['HTTP_X_FORWARDED_HOST'], "<>?\"' \r\n", '________'); } else { # note : HTTP_HOST contient le :port si necessaire $host = $_SERVER['HTTP_HOST']; if (isset($_SERVER['SERVER_PORT']) and $port = $_SERVER['SERVER_PORT'] and strpos($host, ":") == false) { if (!defined('_PORT_HTTP_STANDARD')) { define('_PORT_HTTP_STANDARD', '80'); } if (!defined('_PORT_HTTPS_STANDARD')) { define('_PORT_HTTPS_STANDARD', '443'); } if ($http == "http" and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) { $host .= ":{$port}"; } if ($http == "https" and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) { $host .= ":{$port}"; } } } if (!$GLOBALS['REQUEST_URI']) { if (isset($_SERVER['REQUEST_URI'])) { $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; } else { $GLOBALS['REQUEST_URI'] = $_SERVER['PHP_SELF']; if ($_SERVER['QUERY_STRING'] and !strpos($_SERVER['REQUEST_URI'], '?')) { $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; } } } $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur); return $url[$profondeur]; }
/** * Calcule l'url de base du site * * Calcule l'URL de base du site, en priorité sans se fier à la méta (adresse_site) qui * peut être fausse (sites avec plusieurs noms d’hôtes, déplacements, erreurs). * En dernier recours, lorsqu'on ne trouve rien, on utilise adresse_site comme fallback. * * @note * La globale `$profondeur_url` doit être initialisée de manière à * indiquer le nombre de sous-répertoires de l'url courante par rapport à la * racine de SPIP : par exemple, sur ecrire/ elle vaut 1, sur sedna/ 1, et à * la racine 0. Sur url/perso/ elle vaut 2 * * @param int|boo|array $profondeur * - si non renseignée : retourne l'url pour la profondeur $GLOBALS['profondeur_url'] * - si int : indique que l'on veut l'url pour la profondeur indiquée * - si bool : retourne le tableau static complet * - si array : réinitialise le tableau static complet avec la valeur fournie * @return string|array */ function url_de_base($profondeur = null) { static $url = array(); if (is_array($profondeur)) { return $url = $profondeur; } if ($profondeur === false) { return $url; } if (is_null($profondeur)) { $profondeur = $GLOBALS['profondeur_url']; } if (isset($url[$profondeur])) { return $url[$profondeur]; } $http = (isset($_SERVER["SCRIPT_URI"]) and substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https' or isset($_SERVER['HTTPS']) and test_valeur_serveur($_SERVER['HTTPS'])) ? 'https' : 'http'; // note : HTTP_HOST contient le :port si necessaire $host = $_SERVER['HTTP_HOST']; // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) { $host = $GLOBALS['meta']['adresse_site']; if ($scheme = parse_url($host, PHP_URL_SCHEME)) { $http = $scheme; $host = str_replace("{$scheme}://", '', $host); } } if (isset($_SERVER['SERVER_PORT']) and $port = $_SERVER['SERVER_PORT'] and strpos($host, ":") == false) { if (!defined('_PORT_HTTP_STANDARD')) { define('_PORT_HTTP_STANDARD', '80'); } if (!defined('_PORT_HTTPS_STANDARD')) { define('_PORT_HTTPS_STANDARD', '443'); } if ($http == "http" and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) { $host .= ":{$port}"; } if ($http == "https" and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) { $host .= ":{$port}"; } } if (!$GLOBALS['REQUEST_URI']) { if (isset($_SERVER['REQUEST_URI'])) { $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; } else { $GLOBALS['REQUEST_URI'] = $_SERVER['PHP_SELF']; if ($_SERVER['QUERY_STRING'] and !strpos($_SERVER['REQUEST_URI'], '?')) { $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; } } } $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur); return $url[$profondeur]; }
/** * l'URL de base du site, sans se fier a meta(adresse_site) qui * peut etre fausse (sites a plusieurs noms d'hotes, deplacements, erreurs) * Note : la globale $profondeur_url doit etre initialisee de maniere a * indiquer le nombre de sous-repertoires de l'url courante par rapport a la * racine de SPIP : par exemple, sur ecrire/ elle vaut 1, sur sedna/ 1, et a * la racine 0. Sur url/perso/ elle vaut 2 * http://doc.spip.org/@url_de_base * * @param int|boo|array $profondeur * si non renseignee : retourne l'url pour la profondeur $GLOBALS['profondeur_url'] * si int : indique que l'on veut l'url pour la prondeur indiquee * si bool : retourne le tableau static complet * si array : reinitialise le tableau static complet avec la valeur fournie * @return string|array */ function url_de_base($profondeur = null) { static $url = array(); if (is_array($profondeur)) { return $url = $profondeur; } if ($profondeur === false) { return $url; } if (is_null($profondeur)) { $profondeur = $GLOBALS['profondeur_url']; } if (isset($url[$profondeur])) { return $url[$profondeur]; } $http = (isset($_SERVER["SCRIPT_URI"]) and substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https' or isset($_SERVER['HTTPS']) and test_valeur_serveur($_SERVER['HTTPS'])) ? 'https' : 'http'; # note : HTTP_HOST contient le :port si necessaire $host = $_SERVER['HTTP_HOST']; if (isset($_SERVER['SERVER_PORT']) and $port = $_SERVER['SERVER_PORT'] and strpos($host, ":") == false) { if ($http == "http" and $port != 80) { $host .= ":{$port}"; } if ($http == "https" and $port != 443) { $host .= ":{$port}"; } } if (!$GLOBALS['REQUEST_URI']) { if (isset($_SERVER['REQUEST_URI'])) { $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; } else { $GLOBALS['REQUEST_URI'] = $_SERVER['PHP_SELF']; if ($_SERVER['QUERY_STRING'] and !strpos($_SERVER['REQUEST_URI'], '?')) { $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; } } } $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur); return $url[$profondeur]; }
function url_de_base($profondeur=null) { static $url = array(); if (is_array($profondeur)) return $url = $profondeur; if ($profondeur===false) return $url; if (is_null($profondeur)) $profondeur = $GLOBALS['profondeur_url']; if (isset($url[$profondeur])) return $url[$profondeur]; $http = ( (isset($_SERVER["SCRIPT_URI"]) AND substr($_SERVER["SCRIPT_URI"],0,5) == 'https') OR (isset($_SERVER['HTTPS']) AND test_valeur_serveur($_SERVER['HTTPS'])) ) ? 'https' : 'http'; # note : HTTP_HOST contient le :port si necessaire if (!$GLOBALS['REQUEST_URI']){ if (isset($_SERVER['REQUEST_URI'])) { $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; } else { $GLOBALS['REQUEST_URI'] = $_SERVER['PHP_SELF']; if ($_SERVER['QUERY_STRING'] AND !strpos($_SERVER['REQUEST_URI'], '?')) $GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING']; } } $url[$profondeur] = url_de_($http,$_SERVER['HTTP_HOST'],$GLOBALS['REQUEST_URI'],$profondeur); return $url[$profondeur]; }