clear old config values

This commit is contained in:
Sebastian Mendel
2005-12-07 08:32:21 +00:00
parent 8fb1f3ce4c
commit 50c4439d30

View File

@@ -2,8 +2,8 @@
/* $Id$ */
// vim: expandtab sw=4 ts=4 sts=4:
class PMA_Config {
class PMA_Config
{
/**
* @var string default config source
*/
@@ -56,11 +56,13 @@ class PMA_Config {
*
* @param string source to read config from
*/
function __construct( $source = NULL ) {
function __construct($source = NULL)
{
$this->settings = array();
// functions need to refresh in case of config file changed goes in
// PMA_Config::load()
$this->load( $source );
$this->load($source);
// other settings, independant from config file, comes in
$this->checkSystem();
@@ -69,16 +71,17 @@ class PMA_Config {
/**
* sets system and application settings
*/
function checkSystem() {
$this->set( 'PMA_VERSION', '2.7.1-dev' );
function checkSystem()
{
$this->set('PMA_VERSION', '2.7.1-dev');
/**
* @deprecated
*/
$this->set( 'PMA_THEME_VERSION', 2 );
$this->set('PMA_THEME_VERSION', 2);
/**
* @deprecated
*/
$this->set( 'PMA_THEME_GENERATION', 2 );
$this->set('PMA_THEME_GENERATION', 2);
$this->checkPhpVersion();
$this->checkWebServerOs();
@@ -93,21 +96,22 @@ class PMA_Config {
/**
* wether to use gzip output compression or not
*/
function checkOutputCompression() {
function checkOutputCompression()
{
// If zlib output compression is set in the php configuration file, no
// output buffering should be run
if ( @ini_get('zlib.output_compression') ) {
$this->set( 'OBGzip', false );
$this->set('OBGzip', false);
}
// disable output-buffering (if set to 'auto') for IE6, else enable it.
if ( strtolower( $this->get( 'OBGzip' ) ) == 'auto' ) {
if ( $this->get( 'PMA_USR_BROWSER_AGENT' ) == 'IE'
&& $this->get( 'PMA_USR_BROWSER_VER' ) >= 6
&& $this->get( 'PMA_USR_BROWSER_VER' ) < 7 ) {
$this->set( 'OBGzip', false );
if ( strtolower($this->get('OBGzip')) == 'auto' ) {
if ( $this->get('PMA_USR_BROWSER_AGENT') == 'IE'
&& $this->get('PMA_USR_BROWSER_VER') >= 6
&& $this->get('PMA_USR_BROWSER_VER') < 7 ) {
$this->set('OBGzip', false);
} else {
$this->set( 'OBGzip', true );
$this->set('OBGzip', true);
}
}
}
@@ -117,7 +121,8 @@ class PMA_Config {
* Based on a phpBuilder article:
* @see http://www.phpbuilder.net/columns/tim20000821.php
*/
function checkClient() {
function checkClient()
{
if (!empty($_SERVER['HTTP_USER_AGENT'])) {
$HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
} elseif (!isset($HTTP_USER_AGENT)) {
@@ -173,10 +178,11 @@ class PMA_Config {
/**
* Whether GD2 is present
*/
function checkGd2() {
if ( $this->get( 'GD2Available' ) == 'yes' ) {
function checkGd2()
{
if ( $this->get('GD2Available') == 'yes' ) {
$this->set('PMA_IS_GD2', 1);
} elseif ( $this->get( 'GD2Available' ) == 'no' ) {
} elseif ( $this->get('GD2Available') == 'no' ) {
$this->set('PMA_IS_GD2', 0);
} else {
if (!@extension_loaded('gd')) {
@@ -216,35 +222,38 @@ class PMA_Config {
/**
* Whether the Web server php is running on is IIS
*/
function checkWebServer() {
function checkWebServer()
{
if ( isset( $_SERVER['SERVER_SOFTWARE'] )
&& stristr( $_SERVER['SERVER_SOFTWARE'], 'Microsoft/IIS' ) ) {
$this->set( 'PMA_IS_IIS', 1 );
&& stristr($_SERVER['SERVER_SOFTWARE'], 'Microsoft/IIS') ) {
$this->set('PMA_IS_IIS', 1);
} else {
$this->set( 'PMA_IS_IIS', 0 );
$this->set('PMA_IS_IIS', 0);
}
}
/**
* Whether the os php is running on is windows or not
*/
function checkWebServerOs() {
if ( defined('PHP_OS') && stristr( PHP_OS, 'win' ) ) {
$this->set( 'PMA_IS_WINDOWS', 1 );
function checkWebServerOs()
{
if ( defined('PHP_OS') && stristr(PHP_OS, 'win') ) {
$this->set('PMA_IS_WINDOWS', 1);
} else {
$this->set( 'PMA_IS_WINDOWS', 0 );
$this->set('PMA_IS_WINDOWS', 0);
}
}
/**
* detects PHP version
*/
function checkPhpVersion() {
function checkPhpVersion()
{
$match = array();
if ( ! preg_match( '@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@',
phpversion(), $match ) ) {
if ( ! preg_match('@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@',
phpversion(), $match) ) {
$result = preg_match('@([0-9]{1,2}).([0-9]{1,2})@',
phpversion(), $match );
phpversion(), $match);
}
if ( isset( $match ) && ! empty( $match[1] ) ) {
if ( ! isset( $match[2] ) ) {
@@ -253,22 +262,24 @@ class PMA_Config {
if ( ! isset( $match[3] ) ) {
$match[3] = 0;
}
$this->set( 'PMA_PHP_INT_VERSION',
(int) sprintf( '%d%02d%02d', $match[1], $match[2], $match[3] ) );
$this->set('PMA_PHP_INT_VERSION',
(int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]));
} else {
$this->set( 'PMA_PHP_INT_VERSION', 0 );
$this->set('PMA_PHP_INT_VERSION', 0);
}
$this->set( 'PMA_PHP_STR_VERSION', phpversion() );
$this->set('PMA_PHP_STR_VERSION', phpversion());
}
/**
* re-init object after loadiong from session file
* checks config file for changes and relaods if neccessary
*/
function __wakeup() {
if ( $this->source_mtime !== filemtime( $this->getSource() )
function __wakeup()
{
if ( $this->source_mtime !== filemtime($this->getSource())
|| $this->error_config_file || $this->error_config_default_file ) {
$this->load( $this->getSource() );
$this->settings = array();
$this->load($this->getSource());
$this->checkSystem();
}
@@ -284,9 +295,10 @@ class PMA_Config {
* @uses $this->settings
* @return boolean success
*/
function loadDefaults() {
function loadDefaults()
{
$cfg = array();
if ( ! file_exists( $this->default_source ) ) {
if ( ! file_exists($this->default_source) ) {
$this->error_config_default_file = true;
return false;
}
@@ -295,7 +307,7 @@ class PMA_Config {
$this->default_server = $cfg['Servers'][1];
unset( $cfg['Servers'] );
$this->settings = PMA_array_merge_recursive( $this->settings, $cfg );
$this->settings = PMA_array_merge_recursive($this->settings, $cfg);
return true;
}
@@ -306,11 +318,11 @@ class PMA_Config {
*
* @param string $source config file
*/
function load( $source = NULL ) {
function load($source = NULL)
{
$this->loadDefaults();
if ( ! $source || ! $this->setSource( $source ) ) {
if ( ! $source || ! $this->setSource($source) ) {
return false;
}
@@ -319,37 +331,37 @@ class PMA_Config {
/**
* Parses the configuration file
*/
$old_error_reporting = error_reporting( 0 );
if ( function_exists( 'file_get_contents' ) ) {
$old_error_reporting = error_reporting(0);
if ( function_exists('file_get_contents') ) {
$eval_result =
eval( '?>' . file_get_contents( $this->getSource() ) );
eval( '?>' . file_get_contents($this->getSource()) );
} else {
$eval_result =
eval( '?>' . implode( '\n', file( $this->getSource() ) ) );
eval( '?>' . implode('\n', file($this->getSource())) );
}
error_reporting( $old_error_reporting );
error_reporting($old_error_reporting);
if ( $eval_result === false ) {
$this->error_config_file = true;
} else {
$this->error_config_file = false;
$this->source_mtime = filemtime( $this->getSource() );
$this->source_mtime = filemtime($this->getSource());
}
/**
* @TODO check validity of $_COOKIE['pma_collation_connection']
*/
if ( ! empty( $_COOKIE['pma_collation_connection'] ) ) {
$this->set( 'collation_connection',
strip_tags( $_COOKIE['pma_collation_connection'] ) );
$this->set('collation_connection',
strip_tags($_COOKIE['pma_collation_connection']) );
} else {
$this->set( 'collation_connection',
$this->get( 'DefaultConnectionCollation' ) );
$this->set('collation_connection',
$this->get('DefaultConnectionCollation') );
}
$this->checkCollationConnection();
//$this->checkPmaAbsoluteUri();
$this->settings = PMA_array_merge_recursive( $this->settings, $cfg );
$this->settings = PMA_array_merge_recursive($this->settings, $cfg);
return true;
}
@@ -357,18 +369,19 @@ class PMA_Config {
* set source
* @param string $source
*/
function setSource( $source ) {
if ( ! file_exists( $source ) ) {
function setSource($source)
{
if ( ! file_exists($source) ) {
// do not trigger error here
// https://sf.net/tracker/?func=detail&aid=1370269&group_id=23067&atid=377408
/*
trigger_error(
'phpMyAdmin-ERROR: unkown configuration source: ' . $source,
E_USER_WARNING );
E_USER_WARNING);
*/
return false;
}
$this->source = trim( $source );
$this->source = trim($source);
return true;
}
@@ -377,7 +390,8 @@ class PMA_Config {
* @param string $setting
* @return mixed value
*/
function get( $setting ) {
function get($setting)
{
if ( isset( $this->settings[$setting] ) ) {
return $this->settings[$setting];
}
@@ -391,7 +405,8 @@ class PMA_Config {
* @param string $setting configuration option
* @param string $value new value for configuration option
*/
function set( $setting, $value ) {
function set($setting, $value)
{
$this->settings[$setting] = $value;
}
@@ -399,7 +414,8 @@ class PMA_Config {
* returns source for current config
* @return string config source
*/
function getSource() {
function getSource()
{
return $this->source;
}
@@ -408,8 +424,9 @@ class PMA_Config {
*
* @deprecated
*/
function PMA_Config( $source ) {
$this->__construct( $source );
function PMA_Config($source)
{
$this->__construct($source);
}
/**
@@ -417,17 +434,17 @@ class PMA_Config {
* set properly and, depending on browsers, inserting or updating a
* record might fail
*/
function checkPmaAbsoluteUri() {
function checkPmaAbsoluteUri()
{
// Setup a default value to let the people and lazy syadmins work anyway,
// they'll get an error if the autodetect code doesn't work
$pma_absolute_uri = $this->get('PmaAbsoluteUri');
if ( strlen( $pma_absolute_uri ) < 1 ) {
if ( strlen($pma_absolute_uri) < 1 ) {
$url = array();
// At first we try to parse REQUEST_URI, it might contain full URI
if ( ! empty($_SERVER['REQUEST_URI'] ) ) {
$url = parse_url( $_SERVER['REQUEST_URI'] );
$url = parse_url($_SERVER['REQUEST_URI']);
}
// If we don't have scheme, we didn't have full URL so we need to
@@ -445,9 +462,9 @@ class PMA_Config {
// Host and port
if ( ! empty( $_SERVER['HTTP_HOST'] ) ) {
if ( strpos( $_SERVER['HTTP_HOST'], ':' ) !== false ) {
if ( strpos($_SERVER['HTTP_HOST'], ':') !== false ) {
list( $url['host'], $url['port'] ) =
explode( ':', $_SERVER['HTTP_HOST'] );
explode(':', $_SERVER['HTTP_HOST']);
} else {
$url['host'] = $_SERVER['HTTP_HOST'];
}
@@ -532,19 +549,20 @@ class PMA_Config {
}
}
$this->set( 'PmaAbsoluteUri', $pma_absolute_uri );
$this->set('PmaAbsoluteUri', $pma_absolute_uri);
}
/**
* check selected collation_connection
* @TODO check validity of $_REQUEST['collation_connection']
*/
function checkCollationConnection() {
function checkCollationConnection()
{
// (could be improved by executing it after the MySQL connection only if
// PMA_MYSQL_INT_VERSION >= 40100 )
if ( ! empty( $_REQUEST['collation_connection'] ) ) {
$this->set( 'collation_connection',
strip_tags( $_REQUEST['collation_connection'] ) );
$this->set('collation_connection',
strip_tags($_REQUEST['collation_connection']) );
}
}
@@ -552,11 +570,12 @@ class PMA_Config {
* checks if upload is enabled
*
*/
function checkUpload() {
$this->set( 'enbale_upload', true );
if ( strtolower( @ini_get( 'file_uploads' ) ) == 'off'
|| @ini_get( 'file_uploads' ) == 0 ) {
$this->set( 'enbale_upload', false );
function checkUpload()
{
$this->set('enbale_upload', true);
if ( strtolower(@ini_get('file_uploads')) == 'off'
|| @ini_get('file_uploads') == 0 ) {
$this->set('enbale_upload', false);
}
}
@@ -566,30 +585,33 @@ class PMA_Config {
*
* this section generates $max_upload_size in bytes
*/
function checkUploadSize() {
if ( ! $filesize = ini_get( 'upload_max_filesize' ) ) {
function checkUploadSize()
{
if ( ! $filesize = ini_get('upload_max_filesize') ) {
$filesize = "5M";
}
if ( $postsize = ini_get( 'post_max_size' ) ) {
$this->set( 'max_upload_size',
min( get_real_size( $filesize ), get_real_size( $postsize ) ) );
if ( $postsize = ini_get('post_max_size') ) {
$this->set('max_upload_size',
min(get_real_size($filesize), get_real_size($postsize)) );
} else {
$this->set( 'max_upload_size', get_real_size( $filesize ) );
$this->set('max_upload_size', get_real_size($filesize));
}
}
/**
* check for https
*/
function checkIsHttps() {
$this->set( 'is_https', PMA_Config::isHttps() );
function checkIsHttps()
{
$this->set('is_https', PMA_Config::isHttps());
}
/**
* @static
*/
function isHttps() {
function isHttps()
{
static $is_https = NULL;
if ( NULL !== $is_https ) {
@@ -600,7 +622,7 @@ class PMA_Config {
// At first we try to parse REQUEST_URI, it might contain full URI
if ( ! empty($_SERVER['REQUEST_URI'] ) ) {
$url = parse_url( $_SERVER['REQUEST_URI'] );
$url = parse_url($_SERVER['REQUEST_URI']);
}
// If we don't have scheme, we didn't have full URL so we need to
@@ -630,14 +652,16 @@ class PMA_Config {
/**
* detect correct cookie path
*/
function checkCookiePath() {
$this->set( 'cookie_path', PMA_Config::getCookiePath() );
function checkCookiePath()
{
$this->set('cookie_path', PMA_Config::getCookiePath());
}
/**
* @static
*/
function getCookiePath() {
function getCookiePath()
{
static $cookie_path = NULL;
if ( NULL !== $cookie_path ) {
@@ -645,7 +669,7 @@ class PMA_Config {
}
if ( ! empty($_SERVER['REQUEST_URI'] ) ) {
$url = parse_url( $_SERVER['REQUEST_URI'] );
$url = parse_url($_SERVER['REQUEST_URI']);
}
// If we don't have path
@@ -659,8 +683,8 @@ class PMA_Config {
}
}
$cookie_path = substr( $url['path'], 0,
strrpos( $url['path'], '/' ) ) . '/';
$cookie_path = substr($url['path'], 0,
strrpos($url['path'], '/')) . '/';
return $cookie_path;
}
@@ -668,15 +692,15 @@ class PMA_Config {
/**
* enables backward compatibility
*/
function enableBc() {
function enableBc()
{
$GLOBALS['cfg'] =& $this->settings;
$GLOBALS['default_server'] =& $this->default_server;
$GLOBALS['collation_connection'] = $this->get( 'collation_connection' );
$GLOBALS['is_upload'] = $this->get( 'enable_upload' );
$GLOBALS['max_upload_size'] = $this->get( 'max_upload_size' );
$GLOBALS['cookie_path'] = $this->get( 'cookie_path' );
$GLOBALS['is_https'] = $this->get( 'is_https' );
$GLOBALS['collation_connection'] = $this->get('collation_connection');
$GLOBALS['is_upload'] = $this->get('enable_upload');
$GLOBALS['max_upload_size'] = $this->get('max_upload_size');
$GLOBALS['cookie_path'] = $this->get('cookie_path');
$GLOBALS['is_https'] = $this->get('is_https');
$defines = array(
'PMA_VERSION',
@@ -693,8 +717,8 @@ class PMA_Config {
);
foreach ( $defines as $define ) {
if ( ! defined( $define ) ) {
define( $define, $this->get( $define ) );
if ( ! defined($define) ) {
define($define, $this->get($define));
}
}
}