Skip to content

Commit

Permalink
Streamline $g_path definition
Browse files Browse the repository at this point in the history
Simplify the code by replacing uses of ternary operator with switch
statement and removing unnecessary variable assignments.

We now also cover the (admittedly unlikely) scenario where the
temporary path is empty, to ensure we always generate a valid path
that includes a trailing '/'.
  • Loading branch information
dregad committed Oct 1, 2012
1 parent 6579339 commit 999854e
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions config_defaults_inc.php
Expand Up @@ -94,8 +94,9 @@
* MantisBT Path Settings *
**************************/

$t_protocol = 'http';
$t_host = 'localhost';
if ( isset ( $_SERVER['SCRIPT_NAME'] ) ) {
$t_protocol = 'http';
if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) {
$t_protocol= $_SERVER['HTTP_X_FORWARDED_PROTO'];
} else if ( !empty( $_SERVER['HTTPS'] ) && ( strtolower( $_SERVER['HTTPS'] ) != 'off' ) ) {
Expand All @@ -122,8 +123,6 @@
$t_host = $_SERVER['SERVER_NAME'] . $t_port;
} else if ( isset( $_SERVER['SERVER_ADDR'] ) ) {
$t_host = $_SERVER['SERVER_ADDR'] . $t_port;
} else {
$t_host = 'localhost';
}

if ( !isset( $_SERVER['SCRIPT_NAME'] )) {
Expand All @@ -132,29 +131,33 @@
echo ' Please try to add "fastcgi_param SCRIPT_NAME $fastcgi_script_name;" to the nginx server configuration.';
die;
}
$t_self = $_SERVER['SCRIPT_NAME'];
$t_self = filter_var($t_self, FILTER_SANITIZE_STRING);
$t_self = filter_var( $_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING );
$t_path = str_replace( basename( $t_self ), '', $t_self );
$t_path = basename( $t_path ) == "admin" ? rtrim( dirname( $t_path ), '/\\' ) . '/' : $t_path;
$t_path = basename( $t_path ) == "soap" ? rtrim( dirname( dirname( $t_path ) ), '/\\' ) . '/' : $t_path;
switch( basename( $t_path ) ) {
case 'admin':
$t_path = rtrim( dirname( $t_path ), '/\\' ) . '/';
break;
case 'soap':
$t_path = rtrim( dirname( dirname( $t_path ) ), '/\\' ) . '/';
break;
case '':
$t_path = '/';
break;
}
if( strpos( $t_path, '&#' ) ) {
echo 'Can not safely determine $g_path. Please set $g_path manually in config_inc.php';
die;
}
$t_url = $t_protocol . '://' . $t_host . $t_path;

} else {
$t_path = '';
$t_host = '';
$t_protocol = '';
$t_path = 'mantisbt/';
}

/**
* path to your installation as seen from the web browser
* requires trailing /
* @global string $g_path
*/
$g_path = isset( $t_url ) ? $t_url : 'http://localhost/mantisbt/';
$g_path = $t_protocol . '://' . $t_host . $t_path;

/**
* path to your images directory (for icons)
Expand Down

0 comments on commit 999854e

Please sign in to comment.