Fix pb when host on domain name starting with 'admin'

* Do str_replace only on the $dirname variable
This commit is contained in:
Olivier PEREZ 2015-03-04 23:46:42 +01:00
parent 818151fe83
commit b3bc68bbe6
2 changed files with 6 additions and 5 deletions

View File

@ -23,13 +23,14 @@ class Utils {
* @return string Server name
*/
public static function get_server_name() {
$scheme = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
$scheme = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') ? 'https' : 'http';
$port = in_array($_SERVER['SERVER_PORT'], [80, 443]) ? '' : ':' . $_SERVER['SERVER_PORT'];
$dirname = dirname($_SERVER['SCRIPT_NAME']);
$dirname = $dirname === '\\' ? '/' : $dirname . '/';
$dirname = str_replace('/admin', '', $dirname);
$server_name = $_SERVER['SERVER_NAME'] . $port . $dirname;
return $scheme . '://' . str_replace('/admin', '', str_replace('//', '/', str_replace('///', '/', $server_name)));
return $scheme . '://' . preg_replace('//+', '/', $server_name);
}
public static function is_error($cerr) {

View File

@ -27,7 +27,7 @@ function bandeau_titre($titre)
$img = ( IMAGE_TITRE ) ? '<img src="'. Utils::get_server_name(). IMAGE_TITRE. '" alt="'.NOMAPPLICATION.'">' : '';
echo '
<header role="banner">';
if(count($ALLOWED_LANGUAGES)>1){
if(count($ALLOWED_LANGUAGES) > 1){
echo '<form method="post" action="" class="hidden-print">
<div class="input-group input-group-sm pull-right col-md-2 col-xs-4">
<select name="lang" class="form-control" title="'. _("Select the language") .'" >' . liste_lang() . '</select>
@ -38,7 +38,7 @@ function bandeau_titre($titre)
</form>';
}
echo '
<h1><a href="'.str_replace('/admin','', Utils::get_server_name()).'" title="'._("Home").' - '.NOMAPPLICATION.'">'.$img.'</a></h1>
<h1><a href="' . Utils::get_server_name() . '" title="' . _('Home') . ' - ' . NOMAPPLICATION . '">' . $img . '</a></h1>
<h2 class="lead"><i>'. $titre .'</i></h2>
<hr class="trait" role="presentation" />
</header>
@ -72,7 +72,7 @@ function liste_lang()
return $str;
}
function bandeau_pied($admin=false)
function bandeau_pied()
{
echo '
</main>