CVS: phpweather/config make_config.php,1.6,1.7 pw_dependency.php,1.2,...
Brought to you by:
iridium
From: Martin G. <gim...@us...> - 2002-12-28 00:52:58
|
Update of /cvsroot/phpweather/phpweather/config In directory sc8-pr-cvs1:/tmp/cvs-serv2218 Modified Files: make_config.php pw_dependency.php pw_dependency_or.php pw_option.php pw_option_select.php pw_optiongroup.php reset_session.php Log Message: Updated to support PHP with register_globals turned off. Index: make_config.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/make_config.php,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- make_config.php 10 Nov 2002 23:15:41 -0000 1.6 +++ make_config.php 28 Dec 2002 00:52:54 -0000 1.7 @@ -46,7 +46,8 @@ /* If $options isn't registered, then we should make the variable and * register it: */ -if (!session_is_registered('options')) { +if (empty($HTTP_SESSION_VARS)) { + /* Common dependencies: */ $db_dep = new pw_dependency_or('db_type', array('mysql', 'pgsql', 'dba')); $sql_dep = new pw_dependency_or('db_type', array('mysql', 'pgsql')); @@ -77,7 +78,7 @@ /* Next comes all the options: */ - $options['verbosity'] = + $HTTP_SESSION_VARS['verbosity'] = new pw_option_select('verbosity', "The setting of this variable controls the amount of " . "errors, warnings, and debug-information PHP Weather " . @@ -92,13 +93,13 @@ '6' => 'Warnings + debug information', '7' => 'Everything')); - $options['icao'] = + $HTTP_SESSION_VARS['icao'] = new pw_option_text('icao', 'This will be the default station used by PHP Weather. ' . 'You should enter a valid four-letter ICAO.', array(), $icao_validator, 'EKYT'); - $options['pref_units'] = + $HTTP_SESSION_VARS['pref_units'] = new pw_option_select('pref_units', 'You may choose to display the data in several ' . 'formats. Please choose one that fits your need.', @@ -108,15 +109,16 @@ 'only_metric' => 'Only metric', 'only_imperial' => 'Only imperial')); - $options['language'] = + $HTTP_SESSION_VARS['language'] = new pw_option_select('language', 'PHP Weather can produce textual output using ' . 'in several languages - please select your default ' . 'from the list.', array(), - get_languages('text')); + get_languages('text'), + 'en'); - $options['offset'] = + $HTTP_SESSION_VARS['offset'] = new pw_option_integer('offset', "Due to a bug in PHP, on some systems the time reported may " . "be incorrect. If you experience this, you specify the " . @@ -125,7 +127,7 @@ "are), set this option to be +1.", array(), false, 0); - $options['use_proxy'] = + $HTTP_SESSION_VARS['use_proxy'] = new pw_option_boolean('use_proxy', "Set this option to 'Yes' to enable support for a " . "proxy server.", @@ -133,19 +135,19 @@ array('false' => 'No', 'true' => 'Yes')); - $options['proxy_host'] = + $HTTP_SESSION_VARS['proxy_host'] = new pw_option_text('proxy_host', "This is the hostname of the proxy server.", array($proxy_dep), $host_validator); - $options['proxy_port'] = + $HTTP_SESSION_VARS['proxy_port'] = new pw_option_integer('proxy_port', "This is the port number of the proxy server. The " . "default is what is used by the Squid proxy server. " . "Another common port number is '8080'", array($proxy_dep), $port_validator, 3128); - $options['db_type'] = + $HTTP_SESSION_VARS['db_type'] = new pw_option_select('db_type', 'PHP Weather can use several kinds of databases.', array(), @@ -155,7 +157,7 @@ 'dba' => 'A DBA database', 'adodb' => 'The ADOdb wrapper library')); - $options['db_adodb_path'] = + $HTTP_SESSION_VARS['db_adodb_path'] = new pw_option_text('db_adodb_path', "We need to know where we can find the ADOdb library. " . "The default is for a Debian GNU/Linux system, but " . @@ -164,7 +166,7 @@ false, // we could try to validate the path... '/usr/share/adodb'); - $options['db_adodb_driver'] = + $HTTP_SESSION_VARS['db_adodb_driver'] = new pw_option_text('db_adodb_driver', "Please select a driver to use with the ADOdb " . "wrapper library. You can get a list of drivers from " . @@ -173,7 +175,7 @@ array($adodb_dep), $not_empty_validator); - $options['db_adodb_ext'] = + $HTTP_SESSION_VARS['db_adodb_ext'] = new pw_option_boolean('db_adodb_ext', "If you need to load an extension for ADOdb to work, " . "then set this option to 'Yes'. PHP might have been " . @@ -182,7 +184,7 @@ array($adodb_dep), array('false' => 'No', 'true' => 'Yes')); - $options['db_adodb_ext_name'] = + $HTTP_SESSION_VARS['db_adodb_ext_name'] = new pw_option_text('db_adodb_ext_name', "If you need to load an extension go get your database " . "to work, then specify the name here. For example, if " . @@ -192,7 +194,7 @@ array($adodb_ext_dep), $not_empty_validator); - $options['db_adodb_ext_file'] = + $HTTP_SESSION_VARS['db_adodb_ext_file'] = new pw_option_text('db_adodb_ext_file', "The name of the extension isn't enough to guess the " . "filename to load. For example, if you're using the " . @@ -202,7 +204,7 @@ array($adodb_ext_dep), $not_empty_validator); - $options['db_handler'] = + $HTTP_SESSION_VARS['db_handler'] = new pw_option_select('db_handler', "If you've chosen to use a Berkeley DB style database " . "through the PHP database abstraction layer (DBA), then " . @@ -215,7 +217,7 @@ 'db2' => 'db2 - Sleepycat Softwares DB2', 'db3' => 'db3 - Sleepycat Softwares DB3')); - $options['always_use_db'] = + $HTTP_SESSION_VARS['always_use_db'] = new pw_option_boolean('always_use_db', "If you set this option to 'Yes', then PHP Weather " . "will always use the data it finds in the database, " . @@ -224,7 +226,7 @@ array($db_dep), array('false' => 'No', 'true' => 'Yes')); - $options['cache_timeout'] = + $HTTP_SESSION_VARS['cache_timeout'] = new pw_option_integer('cache_timeout', "This specifies when a METAR in the cache is " . "considered to be old. If a METAR is older than this " . @@ -236,40 +238,40 @@ array(new pw_dependency('always_use_db', 'false'), $db_dep), false, '3600'); - $options['db_pconnect'] = + $HTTP_SESSION_VARS['db_pconnect'] = new pw_option_boolean('db_pconnect', "If you want to make a persistent connection to the " . "database, then set this option to 'Yes'.", array($sql_dep), array('false' => 'No', 'true' => 'Yes')); - $options['db_port'] = + $HTTP_SESSION_VARS['db_port'] = new pw_option_integer('db_port', 'If you have to use a non-standard port when ' . 'connecting to the database, then please specify it ' . 'here. If not, then just leave this field blank.', array($sql_dep), $port_validator_empty); - $options['db_hostname'] = + $HTTP_SESSION_VARS['db_hostname'] = new pw_option_text('db_hostname', 'This is the hostname that PHP Weather will use, ' . 'if you choose to use a database-backend, that ' . 'supports network connections.', array($sql_dep), $host_validator); - $options['db_database'] = + $HTTP_SESSION_VARS['db_database'] = new pw_option_text('db_database', 'This is the name of the database that PHP Weather ' . 'should use.', array($sql_dep), $table_validator); - $options['db_username'] = + $HTTP_SESSION_VARS['db_username'] = new pw_option_text('db_username', 'This is the username that PHP Weather will use ' . 'for accessing the database.', array($sql_dep)); - $options['db_password'] = + $HTTP_SESSION_VARS['db_password'] = new pw_option_text('db_password', 'This is the password that PHP Weather will use when ' . 'trying to make a connection to the database. Please ' . @@ -277,19 +279,19 @@ "password in it.", array($sql_dep)); - $options['db_metars'] = + $HTTP_SESSION_VARS['db_metars'] = new pw_option_text('db_metars', 'This is the name of the table that is used ' . 'to cache the METARs.', array($db_dep), $table_validator, 'pw_metars'); - $options['db_stations'] = + $HTTP_SESSION_VARS['db_stations'] = new pw_option_text('db_stations', 'This is the name of the database/table that is used ' . 'to store the names of the stations.', array($db_dep), $table_validator, 'pw_stations'); - $options['db_countries'] = + $HTTP_SESSION_VARS['db_countries'] = new pw_option_text('db_countries', 'This is the name of the database that is used to ' . 'store the names of the countries together with ' . @@ -297,7 +299,7 @@ array($dba_dep), $table_validator, 'pw_countries'); - $options['mark_begin'] = + $HTTP_SESSION_VARS['mark_begin'] = new pw_option_text('mark_begin', 'This string will be placed in front of all the ' . "changable parts of the output. If you don't want " . @@ -306,14 +308,14 @@ 'color="red"></code>, etc.', array(), false, '<b>'); - $options['mark_end'] = + $HTTP_SESSION_VARS['mark_end'] = new pw_option_text('mark_end', 'This string is placed after all the changable parts. ' . 'You should make sure that it closes any tags ' . "you've opened in <code>mark_begin</code>.", array(), false, '</b>'); - $options['exclude'] = + $HTTP_SESSION_VARS['exclude'] = new pw_option_multi_select('exclude', 'You can disable some of the output produced. If ' . "you're not interested in information about " . @@ -327,7 +329,7 @@ /* Finally - we register all the options with the session. */ - session_register('options'); + //session_register('options'); } /* The options should now be ready - they might come from a restored @@ -335,10 +337,10 @@ /* We update the options with the latest information. We have to be carefull when we do this, because we have to operate directly on the - options in $options and not on a copy. */ -$keys = array_keys($options); + options in $HTTP_SESSION_VARS and not on a copy. */ +$keys = array_keys($HTTP_SESSION_VARS); foreach ($keys as $option) { - $options[$option]->update_value($HTTP_POST_VARS); + $HTTP_SESSION_VARS[$option]->update_value($HTTP_POST_VARS); } /* Grouping */ @@ -455,7 +457,7 @@ options might appear. Continue to change the options until they all say <span style="color: green">Input accepted.</span></p> -<form action="<? echo $PHP_SELF . '?' . SID ?>" method="post"> +<form action="<? echo $HTTP_SERVER_VARS['PHP_SELF'] . '?' . SID ?>" method="post"> <p>You can <input type="submit" name="download" value="Download the Configuration" /> or <input type="reset" Index: pw_dependency.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_dependency.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- pw_dependency.php 13 Apr 2002 13:12:29 -0000 1.2 +++ pw_dependency.php 28 Dec 2002 00:52:54 -0000 1.3 @@ -44,7 +44,8 @@ * otherwise. */ function check() { - return ($GLOBALS['options'][$this->option]->get_value() == $this->dep); + global $HTTP_SESSION_VARS; + return ($HTTP_SESSION_VARS[$this->option]->get_value() == $this->dep); } } ?> Index: pw_dependency_or.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_dependency_or.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- pw_dependency_or.php 13 Apr 2002 13:12:29 -0000 1.2 +++ pw_dependency_or.php 28 Dec 2002 00:52:54 -0000 1.3 @@ -28,7 +28,8 @@ } function check() { - $value = $GLOBALS['options'][$this->option]->get_value(); + global $HTTP_SESSION_VARS; + $value = $HTTP_SESSION_VARS[$this->option]->get_value(); foreach ($this->dep as $d) { if ($value == $d) return true; } Index: pw_option.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_option.php,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- pw_option.php 13 Apr 2002 13:12:29 -0000 1.3 +++ pw_option.php 28 Dec 2002 00:52:54 -0000 1.4 @@ -15,7 +15,7 @@ * * It's important that this name correspond to an object in a global * array called $options. If this option is called 'icao', then the - * object must be saved to $GLOBALS['options']['icao'] + * object must be saved to $HTTP_SESSION_VARS['icao'] * * @var string */ Index: pw_option_select.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_option_select.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- pw_option_select.php 7 Apr 2002 18:38:20 -0000 1.1 +++ pw_option_select.php 28 Dec 2002 00:52:54 -0000 1.2 @@ -4,8 +4,13 @@ var $choices = array(); - function pw_option_select($name, $description, $dependencies, $choices) { - $this->pw_option($name, $description, $dependencies, false, key($choices)); + function pw_option_select($name, $description, $dependencies, + $choices, $default = false) { + if ($default && isset($choices[$default])) { + $this->pw_option($name, $description, $dependencies, false, $default); + } else { + $this->pw_option($name, $description, $dependencies, false, key($choices)); + } $this->choices = $choices; } Index: pw_optiongroup.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_optiongroup.php,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- pw_optiongroup.php 29 May 2002 20:42:56 -0000 1.4 +++ pw_optiongroup.php 28 Dec 2002 00:52:54 -0000 1.5 @@ -75,6 +75,8 @@ * be inserted in their own description-list. */ function show() { + global $HTTP_SESSION_VARS; + if ($this->visible) { $style = 'block'; $text = 'Hide options.'; @@ -93,7 +95,7 @@ echo "<dl id=\"$this->id\" style=\"display: $style\">\n"; foreach($this->options as $option) { - $GLOBALS['options'][$option]->show(); + $HTTP_SESSION_VARS[$option]->show(); } echo "</dl>\n"; @@ -111,10 +113,11 @@ * @return string The configuration of the options in the group. */ function get_config() { + global $HTTP_SESSION_VARS; $config = ''; foreach($this->options as $option) { - $config .= $GLOBALS['options'][$option]->get_config(); + $config .= $HTTP_SESSION_VARS[$option]->get_config(); } $stars = "\n/*" . str_repeat('*', 64) . "*/\n"; Index: reset_session.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/reset_session.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- reset_session.php 7 Apr 2002 18:59:53 -0000 1.2 +++ reset_session.php 28 Dec 2002 00:52:54 -0000 1.3 @@ -6,7 +6,7 @@ session_start(); session_unset(); session_destroy(); -header('Location: http://' . $HTTP_HOST . - dirname($PHP_SELF) . '/index.php'); +header('Location: http://' . $HTTP_SERVER_VARS['HTTP_HOST'] . + dirname($HTTP_SERVER_VARS['PHP_SELF']) . '/index.php'); exit(); ?> |