Skip to content

Commit 999854e

Browse files
committedOct 1, 2012
Streamline $g_path definition
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 '/'.
1 parent 6579339 commit 999854e

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed
 

‎config_defaults_inc.php

+16-13
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@
9494
* MantisBT Path Settings *
9595
**************************/
9696

97+
$t_protocol = 'http';
98+
$t_host = 'localhost';
9799
if ( isset ( $_SERVER['SCRIPT_NAME'] ) ) {
98-
$t_protocol = 'http';
99100
if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) {
100101
$t_protocol= $_SERVER['HTTP_X_FORWARDED_PROTO'];
101102
} else if ( !empty( $_SERVER['HTTPS'] ) && ( strtolower( $_SERVER['HTTPS'] ) != 'off' ) ) {
@@ -122,8 +123,6 @@
122123
$t_host = $_SERVER['SERVER_NAME'] . $t_port;
123124
} else if ( isset( $_SERVER['SERVER_ADDR'] ) ) {
124125
$t_host = $_SERVER['SERVER_ADDR'] . $t_port;
125-
} else {
126-
$t_host = 'localhost';
127126
}
128127

129128
if ( !isset( $_SERVER['SCRIPT_NAME'] )) {
@@ -132,29 +131,33 @@
132131
echo ' Please try to add "fastcgi_param SCRIPT_NAME $fastcgi_script_name;" to the nginx server configuration.';
133132
die;
134133
}
135-
$t_self = $_SERVER['SCRIPT_NAME'];
136-
$t_self = filter_var($t_self, FILTER_SANITIZE_STRING);
134+
$t_self = filter_var( $_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING );
137135
$t_path = str_replace( basename( $t_self ), '', $t_self );
138-
$t_path = basename( $t_path ) == "admin" ? rtrim( dirname( $t_path ), '/\\' ) . '/' : $t_path;
139-
$t_path = basename( $t_path ) == "soap" ? rtrim( dirname( dirname( $t_path ) ), '/\\' ) . '/' : $t_path;
136+
switch( basename( $t_path ) ) {
137+
case 'admin':
138+
$t_path = rtrim( dirname( $t_path ), '/\\' ) . '/';
139+
break;
140+
case 'soap':
141+
$t_path = rtrim( dirname( dirname( $t_path ) ), '/\\' ) . '/';
142+
break;
143+
case '':
144+
$t_path = '/';
145+
break;
146+
}
140147
if( strpos( $t_path, '&#' ) ) {
141148
echo 'Can not safely determine $g_path. Please set $g_path manually in config_inc.php';
142149
die;
143150
}
144-
$t_url = $t_protocol . '://' . $t_host . $t_path;
145-
146151
} else {
147-
$t_path = '';
148-
$t_host = '';
149-
$t_protocol = '';
152+
$t_path = 'mantisbt/';
150153
}
151154

152155
/**
153156
* path to your installation as seen from the web browser
154157
* requires trailing /
155158
* @global string $g_path
156159
*/
157-
$g_path = isset( $t_url ) ? $t_url : 'http://localhost/mantisbt/';
160+
$g_path = $t_protocol . '://' . $t_host . $t_path;
158161

159162
/**
160163
* path to your images directory (for icons)

0 commit comments

Comments
 (0)
Please sign in to comment.