|
From: Florin C B. <ory...@us...> - 2011-04-09 16:31:00
|
Update of /cvsroot/mxbb/core/includes In directory vz-cvs-4.sog:/tmp/cvs-serv15765/core/includes Modified Files: mx_functions.php Log Message: fixex Index: mx_functions.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/mx_functions.php,v retrieving revision 1.103 retrieving revision 1.104 diff -C2 -d -r1.103 -r1.104 *** mx_functions.php 30 Mar 2011 10:03:55 -0000 1.103 --- mx_functions.php 9 Apr 2011 16:30:57 -0000 1.104 *************** *** 650,653 **** --- 650,711 ---- /** + * Generate portal url (example: http://www.example.com/phpBB) + * @param bool $without_script_path if set to true the script path gets not appended (example: http://www.example.com) + */ + function generate_portal_url($without_script_path = false) + { + global $board_config, $portal_config, $mx_user; + + $script_name = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($portal_config['script_path'])); + $server_name = $mx_user->host ? $mx_user->host : trim($portal_config['server_name']); + $server_protocol = ( $portal_config['cookie_secure'] ) ? 'https://' : 'http://'; + $server_port = (($portal_config['server_port']) && ($portal_config['server_port'] <> 80)) ? ':' . trim($portal_config['server_port']) . '/' : '/'; + $server_url = $server_protocol . str_replace("//", "/", $server_name . $server_port . $script_name . '/'); //On some server the slash is not added and this trick will fix it + $server_port = (!empty($_SERVER['SERVER_PORT'])) ? (int) $_SERVER['SERVER_PORT'] : (int) getenv('SERVER_PORT'); + + // Forcing server vars is the only way to specify/override the protocol + if ($board_config['force_server_vars'] || !$server_name) + { + $server_protocol = ($server_protocol) ? $server_protocol : (($portal_config['cookie_secure']) ? 'https://' : 'http://'); + $server_name = $portal_config['server_name']; + $server_port = (int) $config['server_port']; + $script_path = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($portal_config['script_path'])); + + $url = $server_protocol . $server_name; + $cookie_secure = $portal_config['cookie_secure']; + } + else + { + // Do not rely on cookie_secure, users seem to think that it means a secured cookie instead of an encrypted connection + $cookie_secure = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 1 : 0; + $url = (($cookie_secure) ? 'https://' : 'http://') . $server_name; + + $script_path = $mx_user->page['root_script_path']; + } + + if ($server_port && (($cookie_secure && $server_port <> 443) || (!$cookie_secure && $server_port <> 80))) + { + // HTTP HOST can carry a port number (we fetch $user->host, but for old versions this may be true) + if (strpos($server_name, ':') === false) + { + $url .= ':' . $server_port; + } + } + + if (!$without_script_path) + { + $url .= $script_path; + } + + // Strip / from the end + if (substr($url, -1, 1) == '/') + { + $url = substr($url, 0, -1); + } + + return $url; + } + + /** * Generate Pagination. * |