CVS: phpweather index.php,1.37,1.38 phpweather.php,1.31,1.32 pw_utili...
Brought to you by:
iridium
From: Martin G. <gim...@us...> - 2002-09-02 18:17:58
|
Update of /cvsroot/phpweather/phpweather In directory usw-pr-cvs1:/tmp/cvs-serv26283 Modified Files: index.php phpweather.php pw_utilities.php Log Message: Move phpweather::get_languages() to pw_utilities as this doesn't really has anything to do with the phpweather class. Updated make_config.php to use get_languages() for a dynamic list of available languages. Index: index.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/index.php,v retrieving revision 1.37 retrieving revision 1.38 diff -u -3 -r1.37 -r1.38 --- index.php 28 Aug 2002 10:17:08 -0000 1.37 +++ index.php 2 Sep 2002 18:17:47 -0000 1.38 @@ -51,7 +51,7 @@ $icao = stripslashes($HTTP_GET_VARS['icao']); } -$languages = $weather->get_languages('text'); +$languages = get_languages('text'); if (empty($HTTP_GET_VARS['language']) || !in_array($HTTP_GET_VARS['language'], array_keys($languages))) { @@ -85,7 +85,7 @@ /* Show stations selection for particular country ($cc). */ $output .= '<form action="index.php" method="get">' . "\n<p>" . get_stations_select($weather, $cc, $icao) - . get_languages_select($weather, $language) + . get_languages_select($language) . '<input type="submit" value="Submit location">' . "</p>\n</form>\n"; } Index: phpweather.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/phpweather.php,v retrieving revision 1.31 retrieving revision 1.32 diff -u -3 -r1.31 -r1.32 --- phpweather.php 26 Aug 2002 13:15:23 -0000 1.31 +++ phpweather.php 2 Sep 2002 18:17:47 -0000 1.32 @@ -10,9 +10,6 @@ * @const PHPWEATHER_BASE_DIR The base directory. */ define('PHPWEATHER_BASE_DIR', dirname(__FILE__)); -/* Due to a strange bug in PHPDoc, you must quote dirname(__FILE__) - * before you run PHPDoc! PHPDoc crashes with a segmentation fault on - * my system if the value is unquoted... */ /** * Require the parent class. @@ -59,41 +56,6 @@ } - /** - * Returns a list of languages. - * - * @return array An associative array with the language codes as the - * keys and the names of the languages as the values. - * - * @param string The type of output module you're interested in, eg. - * 'text' for the text output module. - * - * @access public - */ - function get_languages($type) { - - static $output = array(); - - if (empty($output)) { - - require(PHPWEATHER_BASE_DIR . '/languages.php'); - $this->debug("Finding language for $type"); - - $dir = opendir(PHPWEATHER_BASE_DIR . '/output'); - while($file = readdir($dir)) { - if (ereg("^pw_${type}_([a-z][a-z])\.php$", $file, $regs)) { - $output[$regs[1]] = $languages[$regs[1]]; - } - } - closedir($dir); - } - - asort($output); - - return $output; - } - - /** * Helper-function used to store temperatures. * Index: pw_utilities.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/pw_utilities.php,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- pw_utilities.php 28 Aug 2002 10:10:01 -0000 1.5 +++ pw_utilities.php 2 Sep 2002 18:17:51 -0000 1.6 @@ -39,10 +39,10 @@ } -function get_languages_select($weather, $old_language) { +function get_languages_select($old_language) { $output = '<select name="language">'; - $languages = $weather->get_languages('text'); + $languages = get_languages('text'); while (list($lc, $language) = each($languages)) { if ($lc == $old_language) { @@ -52,6 +52,41 @@ } } $output .= "\n</select>\n"; + + return $output; +} + + +/** + * Returns a list of available languages. + * + * @return array An associative array with the language codes as the + * keys and the names of the languages as the values. + * + * @param string The type of output module you're interested in, eg. + * 'text' for the text output module. + */ +function get_languages($type) { + + static $output = array(); + + if (empty($output)) { + + /* I use dirname(__FILE__) here instead of PHPWEATHER_BASE_DIR + * because one might use this function without having included + * phpweather.php first. */ + require(dirname(__FILE__) . '/languages.php'); + + $dir = opendir(dirname(__FILE__) . '/output'); + while($file = readdir($dir)) { + if (ereg("^pw_${type}_([a-z][a-z])\.php$", $file, $regs)) { + $output[$regs[1]] = $languages[$regs[1]]; + } + } + closedir($dir); + } + + asort($output); return $output; } |