CVS: phpweather index.php,1.28,1.29 pw_utilities.php,1.3,1.4
Brought to you by:
iridium
From: Martin G. <gim...@us...> - 2002-03-28 15:49:13
|
Update of /cvsroot/phpweather/phpweather In directory usw-pr-cvs1:/tmp/cvs-serv28913 Modified Files: index.php pw_utilities.php Log Message: Rewrite to accommodate for the charset header. pw_text::print_pretty() does no longer output anything, instead it returns a string with the output. Perhaps it should be renamed, since 'print' implies that it generates output? Index: index.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/index.php,v retrieving revision 1.28 retrieving revision 1.29 diff -u -3 -r1.28 -r1.29 --- index.php 27 Mar 2002 21:55:17 -0000 1.28 +++ index.php 28 Mar 2002 15:49:09 -0000 1.29 @@ -1,30 +1,8 @@ -<?php header('Content-Type: text/html; charset=UTF-8'); ?> -<!DOCTYPE html - PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "DTD/xhtml1-transitional.dtd"> -<html> -<head> - <title>PHP Weather - test</title> - <style type="text/css"> -<!-- -BODY { - font-family: Verdana, Tahoma, Geneva, Arial, Helvetica, sans-serif; - font-size: 13px; -} - --> - </style> -</head> -<body> - -<h1>PHP Weather - test</h1> -<p>This is the default test page for PHP Weather. For more information, please visit -<a href="http://www.phpweather.net">http://www.phpweather.net</a>.</p> -<p>Data is taken from the <a href="http://weather.noaa.gov">National Weather Service</a> at NOAA.</p> <?php -error_reporting(E_ERROR); +error_reporting(E_ALL); -/* Checkpoint, we store the time */ -$time[] = array(microtime(), 'start'); +/* We store the time */ +$start_time = explode(' ', microtime()); require('phpweather.php'); require('pw_utilities.php'); @@ -34,63 +12,35 @@ if (empty($action)) { /* No action - we display a form from which the user can select a country. */ - - echo ' -<form action="index.php" method="get"> -<p> -<input type="hidden" name="action" value="show_stations" /> -'; - - make_countries_select($weather, ''); - - echo ' -<input type="submit" /> -</p> -</form> -'; + + $output = '<form action="index.php" method="get">' . "\n" . + '<p><input type="hidden" name="action" value="show_stations" /> ' . + get_countries_select($weather, '') . + ' <input type="submit" />' . "</p>\n</form>\n"; } elseif ($action == 'show_stations' && !empty($cc)) { /* A country has just been selected - we make a form with all stations in that country. */ - - echo ' -<form action="index.php" method="get"> -<p> -<input type="hidden" name="action" value="show_weather" /> -'; if (empty($icao)) $icao = ''; if (empty($language)) $language = ''; - - make_countries_select($weather, $cc); - make_stations_select($weather, $cc, $icao); - make_languages_select($weather, $language); - - echo ' -<input type="submit" /> -</p> -</form> -'; + $output = '<form action="index.php" method="get">' . "\n<p>" . + '<input type="hidden" name="action" value="show_weather" /> ' . + get_countries_select($weather, $cc) . + get_stations_select($weather, $cc, $icao) . + get_languages_select($weather, $language) . + '<input type="submit" />' . "</p>\n</form>\n"; } elseif ($action == 'show_weather' && !empty($language)) { /* A station has just been selected - we print the weather. */ - echo ' -<form action="index.php" method="get"> -<p> -<input type="hidden" name="action" value="show_weather" /> -'; - - make_countries_select($weather, $cc); - make_stations_select($weather, $cc, $icao); - make_languages_select($weather, $language); - - echo ' -<input type="submit" /> -</p> -</form> -'; - + $output = '<form action="index.php" method="get">' . "\n<p>" . + '<input type="hidden" name="action" value="show_weather" /> ' . + get_countries_select($weather, $cc) . + get_stations_select($weather, $cc, $icao) . + get_languages_select($weather, $language) . + '<input type="submit" />' . "</p>\n</form>\n"; + if ($cc == $old_cc) { /* We should only display the current weather is the country isn't changed */ @@ -98,55 +48,64 @@ include(PHPWEATHER_BASE_DIR . "/output/pw_text_$language.php"); $type = 'pw_text_' . $language; $text = new $type($weather, array()); - - echo "<p>This is the current weather in " . - $weather->get_location() . ":</p>\n"; - - $text->print_pretty(); - - echo "<p>The matching icons are:</p>\n"; include(PHPWEATHER_BASE_DIR . "/output/pw_images.php"); - $icons = new pw_images($weather, array()); - - echo "<blockquote>\n"; - echo '<img src="' . $icons->get_sky_image() . + + $output .= '<p>This is the current weather in ' . + $weather->get_location() . ":</p>\n<blockquote>\n" . + $text->print_pretty() . "\n</blockquote>\n" . + "<p>The matching icons are:</p>\n<blockquote>\n" . + '<img src="' . $icons->get_sky_image() . '" height="50" width="80" border="1" alt="Current weather in ' . - $weather->get_location() . '" /> '; - echo '<img src="' . $icons->get_winddir_image() . + $weather->get_location() . '" /> ' . + '<img src="' . $icons->get_winddir_image() . '" height="40" width="40" border="1" alt="Current wind in ' . - $weather->get_location() . '" /> '; - echo '<img src="' . $icons->get_temp_image() . + $weather->get_location() . '" /> ' . + '<img src="' . $icons->get_temp_image() . '" height="50" width="20" border="1" alt="Current weather in ' . - $weather->get_location() . '" />'; - echo "</blockquote>\n"; - - - echo "<p>The raw METAR is <code>" . $weather->get_metar() . "</code></p>\n"; - + $weather->get_location() . '" />' . + "\n</blockquote>\n" . + "<p>The raw METAR is <code>" . + $weather->get_metar() . "</code></p>\n"; } } +if (empty($text)) { + header('Content-Type: text/html; charset=ISO-8859-1'); +} else { + header('Content-Type: text/html; charset=' . $text->get_charset()); +} +?> +<!DOCTYPE html + PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "DTD/xhtml1-transitional.dtd"> +<html> +<head> + <title>PHP Weather - test</title> + <style type="text/css"> +<!-- +BODY { + font-family: Verdana, Tahoma, Geneva, Arial, Helvetica, sans-serif; + font-size: 13px; +} + --> + </style> +</head> +<body> -$time[] = array(microtime(), 'end'); +<h1>PHP Weather - test</h1> +<p>This is the default test page for PHP Weather. For more information, please visit +<a href="http://www.phpweather.net">http://www.phpweather.net</a>.</p> +<p>Data is taken from the <a href="http://weather.noaa.gov">National Weather Service</a> at NOAA.</p> -$max = count($time) - 1; -/* -for ($i = 0; $i < $max; $i++) { - $start_time = explode(' ', $time[$i][0]); - $end_time = explode(' ', $time[$i+1][0]); - $diff = ($end_time[0] + $end_time[1]) - ($start_time[0] + $start_time[1]); - echo '<p>Time taken to go from "' . ($time[$i][1]) . '" to "' . ($time[$i+1][1]) . '": ' . number_format($diff * 1000, 0) . " ms.</p>\n"; -} -*/ +<?php +echo $output; + +$end_time = explode(' ', microtime()); -$start_time = explode(' ', $time[0][0]); -$end_time = explode(' ', $time[$max][0]); $diff = ($end_time[0] + $end_time[1]) - ($start_time[0] + $start_time[1]); echo '<p>Total time used to generate page: ' . number_format($diff * 1000, 0) . " ms.</p>\n"; - - ?> </body> Index: pw_utilities.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/pw_utilities.php,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- pw_utilities.php 27 Mar 2002 20:13:20 -0000 1.3 +++ pw_utilities.php 28 Mar 2002 15:49:09 -0000 1.4 @@ -3,62 +3,62 @@ /* Miscellaneous functions that can help you build an interactive site * with PHP Weather. */ -function make_countries_select($weather, $old_cc) { - echo' -<select name="cc"> -'; +function get_countries_select($weather, $old_cc) { + $output = '<select name="cc">'; $countries = $weather->db->get_countries(); while (list($cc, $country) = each($countries)) { if ($cc == $old_cc) { - echo "<option value=\"$cc\" selected=\"selected\">$country</option>\n"; + $output .= "\n<option value=\"$cc\" selected=\"selected\">$country</option>"; } else { - echo "<option value=\"$cc\">$country</option>\n"; + $output .= "\n<option value=\"$cc\">$country</option>"; } } - echo "</select>\n"; - echo '<input type="hidden" name="old_cc" value="' . $old_cc . '" />'; - + $output .= "\n</select>\n"; + $output .= '<input type="hidden" name="old_cc" value="' . $old_cc . '" />'; + return $output; } -function make_stations_select($weather, $cc, $old_icao) { +function get_stations_select($weather, $cc, $old_icao) { $country = ''; $icaos = $weather->db->get_icaos($cc, $country); - echo ' -<select name="icao"> -'; + $output = '<select name="icao">'; while (list($icao, $name) = each($icaos)) { if ($icao == $old_icao) { - echo "<option value=\"$icao\" selected=\"selected\">$name</option>\n"; + $output .= "\n<option value=\"$icao\" selected=\"selected\">$name</option>"; } else { - echo "<option value=\"$icao\">$name</option>\n"; + $output .= "\n<option value=\"$icao\">$name</option>"; } } - echo "</select>\n"; - echo '<input type="hidden" name="old_icao" value="' . $old_icao . '" />'; + $output .= "\n</select>\n"; + $output .= '<input type="hidden" name="old_icao" value="' . + $old_icao . '" />'; + + return $output; } -function make_languages_select($weather, $old_language) { +function get_languages_select($weather, $old_language) { - echo ' -<select name="language"> -'; + $output = '<select name="language">'; $languages = $weather->get_languages('text'); while (list($lc, $language) = each($languages)) { if ($lc == $old_language) { - echo "<option value=\"$lc\" selected=\"selected\">$language</option>\n"; + $output .= "\n<option value=\"$lc\" selected=\"selected\">$language</option>"; } else { - echo "<option value=\"$lc\">$language</option>\n"; + $output .= "\n<option value=\"$lc\">$language</option>"; } } - echo "</select>\n"; - echo '<input type="hidden" name="old_language" value="' . $old_language . '" />'; + $output .= "\n</select>\n"; + $output .= '<input type="hidden" name="old_language" value="' . + $old_language . '" />'; + + return $output; } ?> |