From: <jfi...@us...> - 2002-08-23 01:34:11
|
Update of /cvsroot/mantisbt/mantisbt In directory usw-pr-cvs1:/tmp/cvs-serv14950 Modified Files: constant_inc.php core_API.php core_security_API.php Added Files: core_php_API.php Log Message: Move PHP compatibility stuff to core_php_API.php and call it very first in core_API.php All compatibility checks should now use php_version_at_least() and all code designed for backwards compatibility should go in this new file. Thanks to Victor for the suggestion --- NEW FILE: core_php_API.php --- <?php # Mantis - a php based bugtracking system # Copyright (C) 2000 - 2002 Kenzaburo Ito - ke...@30... # Copyright (C) 2002 Mantis Team - man...@li... # This program is distributed under the terms and conditions of the GPL # See the files README and LICENSE for details ########################################################################### # PHP Compatibility API # # Methods to help in backwards compatibility of PHP versions, etc. # ########################################################################### # -------------------- # Returns true if the current PHP version is higher than the one # specified in the given string function php_version_at_least( $p_version_string ) { $t_curver = array_pad( explode( '.', phpversion() ), 3, 0 ); $t_minver = array_pad( explode( '.', $p_version_string ), 3, 0 ); for ($i = 0 ; $i < 3 ; $i = $i + 1 ) { if ( (int)$t_curver[$i] < (int)$t_minver[$i] ) { return false; } else if ( (int)$t_curver[$i] > (int)$t_minver[$i] ) { return true; } } # if we get here, the versions must match exactly so: return true; } # -------------------- # Enforce our minimum requirements if ( ! php_version_at_least( '4.2.2' ) ) { echo "<b>Your version of PHP is too old. Mantis requires PHP version 4.0.3 or newer to operate</b>"; ob_flush(); die(); } ini_set('magic_quotes_runtime', 0); # @@@ Experimental # deal with register_globals being Off # @@@ NOTE we want to get rid of this once we start getting all # our GPC variables with functions. In fact we may want to # turn off register_global_variables if we can if ( OFF == $g_register_globals ) { if ( php_version_at_least( '4.1.0' ) ) { extract( $_REQUEST ); extract( $_SERVER ); } else { extract( $HTTP_POST_VARS ); extract( $HTTP_GET_VARS ); extract( $HTTP_SERVER_VARS ); } } # Experimental support for $_* auto-global variables in PHP < 4.1.0 if ( ! php_version_at_least( '4.1.0' ) ) { global $_REQUEST, $_GET, $_POST, $_COOKIE, $_SERVER; $_GET = $HTTP_GET_VARS; $_POST = $HTTP_POST_VARS; $_COOKIE = $HTTP_COOKIE_VARS; $_SERVER = $HTTP_SERVER_VARS; $_REQUEST = $HTTP_COOKIE_VARS; foreach ($HTTP_POST_VARS as $key => $value) { $_REQUEST[$key] = $value; } foreach ($HTTP_GET_VARS as $key => $value) { $_REQUEST[$key] = $value; } } ######################## # PHP Constants ######################## # Directory separator was introduced in PHP 4.0.6 if ( !defined( 'DIRECTORY_SEPARATOR' ) ) { if (substr(php_uname(), 0, 7) == 'Windows') { define('DIRECTORY_SEPARATOR', '\\'); } else { define('DIRECTORY_SEPARATOR', '/'); } } ?> Index: constant_inc.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/constant_inc.php,v retrieving revision 1.37 retrieving revision 1.38 diff -u -d -r1.37 -r1.38 --- constant_inc.php 22 Aug 2002 13:53:54 -0000 1.37 +++ constant_inc.php 23 Aug 2002 01:34:08 -0000 1.38 @@ -9,18 +9,6 @@ # CONFIGURATION VARIABLES ########################################################################### - ######################## - # PHP Constants - ######################## - - # Directory separator was introduced in PHP 4.0.6 - if ( !defined( 'DIRECTORY_SEPARATOR' ) ) { - if (substr(php_uname(), 0, 7) == 'Windows') { - define('DIRECTORY_SEPARATOR', '\\'); - } else { - define('DIRECTORY_SEPARATOR', '/'); - } - } ######################## # Mantis Constants Index: core_API.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core_API.php,v retrieving revision 1.89 retrieving revision 1.90 diff -u -d -r1.89 -r1.90 --- core_API.php 22 Aug 2002 18:05:06 -0000 1.89 +++ core_API.php 23 Aug 2002 01:34:08 -0000 1.90 @@ -9,6 +9,13 @@ # INCLUDES ########################################################################### + # Before doing anything else, start output buffering so we don't prevent + # headers from being sent if there's a blank line in an included file + ob_start(); + + # Include compatibility file before anything else + include( 'core_php_API.php' ); + require( 'constant_inc.php' ); if ( file_exists( 'custom_constant_inc.php' ) ) { include( 'custom_constant_inc.php' ); @@ -39,40 +46,6 @@ obsolete_config_variable('g_notify_developers_on_new', 'g_notify_flags'); obsolete_config_variable('g_notify_on_new_threshold', 'g_notify_flags'); obsolete_config_variable('g_notify_admin_on_new', 'g_notify_flags'); - - ini_set('magic_quotes_runtime', 0); - - # @@@ Experimental - # deal with register_globals being Off - $t_phpversion = explode('.', phpversion()); - if ( OFF == $g_register_globals ) { - if ( $t_phpversion[0] == 4 && $t_phpversion[1] >= 1 ) { - extract( $_REQUEST ); - extract( $_SERVER ); - } else { - extract( $HTTP_POST_VARS ); - extract( $HTTP_GET_VARS ); - extract( $HTTP_SERVER_VARS ); - } - } - - # Experimental support for $_* variables in PHP < 4.1.0 - if ( $t_phpversion[0] < 4 || $t_phpversion[1] < 1 ) { - global $_REQUEST, $_GET, $_POST, $_COOKIE, $_SERVER; - - $_GET = $HTTP_GET_VARS; - $_POST = $HTTP_POST_VARS; - $_COOKIE = $HTTP_COOKIE_VARS; - $_SERVER = $HTTP_SERVER_VARS; - - $_REQUEST = $HTTP_COOKIE_VARS; - foreach ($HTTP_POST_VARS as $key => $value) { - $_REQUEST[$key] = $value; - } - foreach ($HTTP_GET_VARS as $key => $value) { - $_REQUEST[$key] = $value; - } - } include( 'core_timer_API.php' ); Index: core_security_API.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core_security_API.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- core_security_API.php 22 Aug 2002 18:15:10 -0000 1.2 +++ core_security_API.php 23 Aug 2002 01:34:08 -0000 1.3 @@ -22,7 +22,10 @@ # If the variable is not set, the default is returned. # If magic_quotes_gpc is on, slashes will be stripped from the value before being returned. function get_var( $p_var_name, $p_default = 'nil' ) { - global $_REQUEST; + # simulate auto-globals from PHP v4.1.0 (see also code in core_php_API.php) + if ( ! php_version_at_least( '4.1.0' ) ) { + global $_REQUEST; + } if ( isset( $_REQUEST[$p_var_name] ) ) { $t_result = $_REQUEST[$p_var_name]; |