From d958a19ed57a3300bc90df42e3351255352a7d45 Mon Sep 17 00:00:00 2001 From: rub Date: Tue, 24 Jul 2007 19:16:02 +0000 Subject: Resolved 0000726: script_basename returns bad result With specific server configuration, script_basename returns bad result. Merge BSF 2070:2071 into branch-1_7 git-svn-id: http://piwigo.org/svn/branches/branch-1_7@2072 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/functions.inc.php | 51 +++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/include/functions.inc.php b/include/functions.inc.php index becace1a4..1ced5e435 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -1283,20 +1283,6 @@ function hash_from_query($query, $keyname) return $array; } -/** - * Return is "file_name" argument is candidate to - * compute script_basename value - * - * @param string file_name - * - * @return boolean is candidate or not? - */ -function is_script_basename($file_name) -{ - $file_name = basename($file_name); - return !empty($file_name); -} - /** * Return basename of the current script * Lower case convertion is applied on return value @@ -1308,21 +1294,34 @@ function is_script_basename($file_name) */ function script_basename() { - if (is_script_basename($_SERVER['SCRIPT_NAME'])) - { - $file_name = $_SERVER['SCRIPT_NAME']; - } - else if (is_script_basename($_SERVER['SCRIPT_FILENAME'])) - { - $file_name = $_SERVER['SCRIPT_FILENAME']; - } - else + global $conf; + + foreach (array('SCRIPT_NAME', 'SCRIPT_FILENAME', 'PHP_SELF') as $value) { - $file_name = ''; + $continue = !empty($_SERVER[$value]); + if ($continue) + { + $filename = strtolower($_SERVER[$value]); + + if ($conf['php_extension_in_urls']) + { + $continue = get_extension($filename) === 'php'; + } + + if ($continue) + { + $basename = basename($filename, '.php'); + $continue = !empty($basename); + } + + if ($continue) + { + return $basename; + } + } } - // $_SERVER return lower string following var and systems - return basename(strtolower($file_name), '.php'); + return ''; } /** -- cgit v1.2.3