Skip to content

Commit

Permalink
Move PHP compatibility stuff to core_php_API.php and call it very fir…
Browse files Browse the repository at this point in the history
…st 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


git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@1297 f5dc347c-c33d-0410-90a0-b07cc1902cb9
  • Loading branch information
Julian Fitzell committed Aug 23, 2002
1 parent c115664 commit 18d3e4b
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 51 deletions.
12 changes: 0 additions & 12 deletions constant_inc.php
Expand Up @@ -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
Expand Down
41 changes: 7 additions & 34 deletions core_API.php
Expand Up @@ -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' );
Expand Down Expand Up @@ -40,40 +47,6 @@ function obsolete_config_variable($var, $replace) {
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' );

# initialize our timer
Expand Down
91 changes: 91 additions & 0 deletions core_php_API.php
@@ -0,0 +1,91 @@
<?php
# Mantis - a php based bugtracking system
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 Mantis Team - mantisbt-dev@lists.sourceforge.net
# 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', '/');
}
}

?>
13 changes: 8 additions & 5 deletions core_security_API.php
Expand Up @@ -6,11 +6,11 @@
# See the files README and LICENSE for details

# --------------------------------------------------------
# $Revision: 1.2 $
# $Author: jlatour $
# $Date: 2002-08-22 18:15:10 $
# $Revision: 1.3 $
# $Author: jfitzell $
# $Date: 2002-08-23 01:34:08 $
#
# $Id: core_security_API.php,v 1.2 2002-08-22 18:15:10 jlatour Exp $
# $Id: core_security_API.php,v 1.3 2002-08-23 01:34:08 jfitzell Exp $
# --------------------------------------------------------

###########################################################################
Expand All @@ -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];
Expand Down

0 comments on commit 18d3e4b

Please sign in to comment.