phpweather-checkins Mailing List for PHP Weather (Page 12)
Brought to you by:
iridium
You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
(7) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(1) |
Feb
(1) |
Mar
(184) |
Apr
(31) |
May
(45) |
Jun
(15) |
Jul
(11) |
Aug
(40) |
Sep
(19) |
Oct
(8) |
Nov
(6) |
Dec
(17) |
2003 |
Jan
(5) |
Feb
|
Mar
(12) |
Apr
(5) |
May
(2) |
Jun
(3) |
Jul
(3) |
Aug
(3) |
Sep
(17) |
Oct
(10) |
Nov
|
Dec
(4) |
2004 |
Jan
(21) |
Feb
(11) |
Mar
|
Apr
|
May
(3) |
Jun
(7) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2005 |
Jan
(4) |
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2006 |
Jan
|
Feb
|
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Martin G. <gim...@us...> - 2002-04-19 18:15:52
|
Update of /cvsroot/phpweather/phpweather-1.x In directory usw-pr-cvs1:/tmp/cvs-serv6448 Modified Files: wap.php Log Message: This URL should be much better... I haven't really tested it, but it should work. Index: wap.php =================================================================== RCS file: /cvsroot/phpweather/phpweather-1.x/wap.php,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -3 -r1.1.1.1 -r1.2 --- wap.php 7 Mar 2002 09:49:11 -0000 1.1.1.1 +++ wap.php 19 Apr 2002 18:15:49 -0000 1.2 @@ -8,7 +8,7 @@ ?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> - <card id="weather" title="www.gimpster.com"> + <card id="weather" title="phpweather.net"> <? $cities = array( 'EKYT' => 'Aalborg', @@ -41,7 +41,7 @@ while (list($icao, $location) = each($cities)) { echo ' <anchor>' . $location . ' - <go href="http://www.gimpster.com/php/phpweather/wap.php" method="post"> + <go href="http://' . $HTTP_HOST . $PHP_SELF . '" method="post"> <postfield name="city" value="' . $icao . '"/> </go> </anchor> |
From: Martin G. <gim...@us...> - 2002-04-19 18:14:54
|
Update of /cvsroot/phpweather/phpweather-1.x In directory usw-pr-cvs1:/tmp/cvs-serv6045 Modified Files: images.inc Log Message: The pages at gimpster.com will be removed soon, so we shouldn't link to them any more. Index: images.inc =================================================================== RCS file: /cvsroot/phpweather/phpweather-1.x/images.inc,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- images.inc 10 Mar 2002 20:22:36 -0000 1.1 +++ images.inc 19 Apr 2002 18:14:50 -0000 1.2 @@ -7,7 +7,6 @@ Also see - http://www.gimpster.com/php/phpweather/ or http://www.sourceforge.net/projects/phpweather for updates and further instructions on how to use PHP Weather. |
From: Martin G. <gim...@us...> - 2002-04-19 18:13:47
|
Update of /cvsroot/phpweather/phpweather-1.x In directory usw-pr-cvs1:/tmp/cvs-serv4911 Modified Files: demo.php Log Message: Wow, time flies by - I've actually managed to move while developing PHP Weather... EKAH is the closest airport to where I live now. Index: demo.php =================================================================== RCS file: /cvsroot/phpweather/phpweather-1.x/demo.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- demo.php 19 Apr 2002 18:09:56 -0000 1.2 +++ demo.php 19 Apr 2002 18:13:44 -0000 1.3 @@ -195,7 +195,7 @@ work:</p> <code><font color="#000000"> -<font color="#0000BB"><?php<br></font><font color="#007700">include(</font><font color="#DD0000">'locale_en.inc'</font><font color="#007700">);<br>include(</font><font color="#DD0000">'phpweather.inc'</font><font color="#007700">);<br></font><font color="#0000BB">$metar </font><font color="#007700">= </font><font color="#0000BB">get_metar</font><font color="#007700">(</font><font color="#DD0000">'EKYT'</font><font color="#007700">);<br></font><font color="#0000BB">$data </font><font color="#007700">= </font><font color="#0000BB">process_metar</font><font color="#007700">(</font><font color="#0000BB">$metar</font><font color="#007700">);<br></font><font color="#0000BB">$temp </font><font color="#007700">= </font><font color="#0000BB">$data</font><font color="#007700">[</font><font color="#DD0000">'temp_c'</font><font color="#007700">];<br>echo </font><font color="#DD0000">"The temperature is $temp degrees Celsius."</font><font color="#007700">;<br></font><font color="#0000BB">?><br></font> +<font color="#0000BB"><?php<br></font><font color="#007700">include(</font><font color="#DD0000">'locale_en.inc'</font><font color="#007700">);<br>include(</font><font color="#DD0000">'phpweather.inc'</font><font color="#007700">);<br></font><font color="#0000BB">$metar </font><font color="#007700">= </font><font color="#0000BB">get_metar</font><font color="#007700">(</font><font color="#DD0000">'EKAH'</font><font color="#007700">);<br></font><font color="#0000BB">$data </font><font color="#007700">= </font><font color="#0000BB">process_metar</font><font color="#007700">(</font><font color="#0000BB">$metar</font><font color="#007700">);<br></font><font color="#0000BB">$temp </font><font color="#007700">= </font><font color="#0000BB">$data</font><font color="#007700">[</font><font color="#DD0000">'temp_c'</font><font color="#007700">];<br>echo </font><font color="#DD0000">"The temperature is $temp degrees Celsius."</font><font color="#007700">;<br></font><font color="#0000BB">?><br></font> </font> </code> @@ -204,14 +204,14 @@ called <code>pretty_print_metar()</code>. You use it like this:</p> <code><font color="#000000"> -<font color="#0000BB"><?php<br>$metar </font><font color="#007700">= </font><font color="#0000BB">get_metar</font><font color="#007700">(</font><font color="#DD0000">'EKYT'</font><font color="#007700">);<br></font><font color="#0000BB">pretty_print_metar</font><font color="#007700">(</font><font color="#0000BB">$metar</font><font color="#007700">, </font><font color="#DD0000">'Tirstrup, Denmark'</font><font color="#007700">);<br></font><font color="#0000BB">?><br></font> +<font color="#0000BB"><?php<br>$metar </font><font color="#007700">= </font><font color="#0000BB">get_metar</font><font color="#007700">(</font><font color="#DD0000">'EKAH'</font><font color="#007700">);<br></font><font color="#0000BB">pretty_print_metar</font><font color="#007700">(</font><font color="#0000BB">$metar</font><font color="#007700">, </font><font color="#DD0000">'Tirstrup, Denmark'</font><font color="#007700">);<br></font><font color="#0000BB">?><br></font> </font> </code> <p>If you wan't to see all the data in the METAR, then try the following code:</p> <code><font color="#000000"> -<font color="#0000CC"><?php<br>$data </font><font color="#006600">= </font><font color="#0000CC">process_metar</font><font color="#006600">(</font><font color="#0000CC">get_metar</font><font color="#006600">(</font><font color="#CC0000">'EKYT'</font><font color="#006600">));<br>echo </font><font color="#CC0000">"<pre>\n"</font><font color="#006600">;<br></font><font color="#0000CC">print_r</font><font color="#006600">(</font><font color="#0000CC">$data</font><font color="#006600">);<br>echo </font><font color="#CC0000">"</pre>\n"</font><font color="#006600">;<br></font><font color="#0000CC">?><br></font> +<font color="#0000CC"><?php<br>$data </font><font color="#006600">= </font><font color="#0000CC">process_metar</font><font color="#006600">(</font><font color="#0000CC">get_metar</font><font color="#006600">(</font><font color="#CC0000">'EKAH'</font><font color="#006600">));<br>echo </font><font color="#CC0000">"<pre>\n"</font><font color="#006600">;<br></font><font color="#0000CC">print_r</font><font color="#006600">(</font><font color="#0000CC">$data</font><font color="#006600">);<br>echo </font><font color="#CC0000">"</pre>\n"</font><font color="#006600">;<br></font><font color="#0000CC">?><br></font> </font> </code> @@ -328,7 +328,7 @@ <code>wap.php</code>-page is a smaller and more compact format than the one shown on this page. It looks like this:</p> -<pre><? pretty_print_metar_wap(get_metar('EKYT'), 'Tirstrup'); ?></pre> +<pre><? pretty_print_metar_wap(get_metar('EKAH'), 'Tirstrup'); ?></pre> <h1>Related information</h1> |
From: Martin G. <gim...@us...> - 2002-04-19 18:09:59
|
Update of /cvsroot/phpweather/phpweather-1.x In directory usw-pr-cvs1:/tmp/cvs-serv3606 Modified Files: demo.php Log Message: Various updates, nothing major... Index: demo.php =================================================================== RCS file: /cvsroot/phpweather/phpweather-1.x/demo.php,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -3 -r1.1.1.1 -r1.2 --- demo.php 7 Mar 2002 09:49:11 -0000 1.1.1.1 +++ demo.php 19 Apr 2002 18:09:56 -0000 1.2 @@ -1,6 +1,6 @@ <html> <head> - <title>PHP Weather</title> + <title>PHP Weather Demonstration</title> </head> <body> @@ -36,17 +36,17 @@ <h1>Your version: <? echo $version ?></h1> -<p>Your source was last modified at <b><? echo $last_modified ?> - UTC</b>. Click <a -href="http://sourceforge.net/projects/phpweather/">here</a> to -download the newest version from <a +<p>Your source was last modified on <b><? echo $last_modified ?></b>. +Click <a href="http://sourceforge.net/projects/phpweather/">here</a> +to download the newest version from <a href="http://www.sourceforge.net/">SourceForge</a>. I'm currently working on the next version of <a href="http://www.sourceforge.net/projects/phpweather/">PHP Weather</a>. You can try it by downloading a snapshot of CVS, but as I don't make these all the time, the best way to follow the development is to check it out of CVS. It's all explained on the <a -href="http://www.sourceforge.net/">SourceForge</a> page.</p> +href="http://www.sourceforge.net/projects/phpweather/">SourceForge</a> +page.</p> <p>If you are having problems with <a href="http://sourceforge.net/projects/phpweather/">PHP Weather</a>, @@ -57,20 +57,19 @@ href="http://lists.sourceforge.net/lists/listinfo/phpweather-devel">this page</a>.</p> -To help speed up the development, you should take a look at the -latest code from CVS. Try and see if you can figure out what is -happening in there, and then tell me what you think. Or even better: -create a user-account at <a -href="http://www.sourceforge.net/">SourceForge</a>, and mail me the -username. I'll then add you to the project, so that we can change the -code yourself.</p> +To help speed up the development, you should take a look at the latest +code from CVS. Try and see if you can figure out what is happening in +there, and then tell me what you think. Or even better: create a +user-account at <a href="http://www.sourceforge.net/">SourceForge</a>, +and mail me the username. I'll then add you to the project, so that +you can help by changing the code yourself.</p> <h1>A sample METAR-report</h1> -<p>The report below is the latest from Aalborg, Denmark (this is where -I live). The raw METAR looks this way:</p> +<p>The report below is the latest from Tirstrup, Denmark (this is +where I live). The raw METAR looks this way:</p> -<?php $metar = get_metar('EKYT'); ?> +<?php $metar = get_metar('EKAH'); ?> <blockquote><code><? echo $metar ?></code></blockquote> @@ -78,8 +77,8 @@ href="http://sourceforge.net/projects/phpweather/">PHP Weather</a> you could also present the information like this:</p> -<? -pretty_print_metar($metar, 'Aalborg, Denmark') +<?php +pretty_print_metar($metar, 'Tirstrup, Denmark') ?> <p>Here is the same piece of text with the current weather in @@ -90,7 +89,7 @@ <p>and then the pretty-printed output:</p> -<? +<?php include('locale_es.inc'); pretty_print_metar($metar, 'Honolulu, Hawaii'); ?> @@ -99,7 +98,7 @@ identifier of the weather station, and the include-file with the strings used by <a href="http://sourceforge.net/projects/phpweather/">PHP Weather</a>. -The identifier for Aalborg, Denmark is <code>EKYT</code> and the one +The identifier for Tirstrup, Denmark is <code>EKAH</code> and the one for Honolulu, Hawaii is <code>PHNL</code>.</p> <p>Try it out for yourself - choose a city and a language from the @@ -201,11 +200,11 @@ </code> <p>That's it! The above code will tell you what the temperature is in -Aalborg, Denmark. To make the examples above I've made a function +Tirstrup, Denmark. To make the examples above I've made a function called <code>pretty_print_metar()</code>. You use it like this:</p> <code><font color="#000000"> -<font color="#0000BB"><?php<br>$metar </font><font color="#007700">= </font><font color="#0000BB">get_metar</font><font color="#007700">(</font><font color="#DD0000">'EKYT'</font><font color="#007700">);<br></font><font color="#0000BB">pretty_print_metar</font><font color="#007700">(</font><font color="#0000BB">$metar</font><font color="#007700">, </font><font color="#DD0000">'Aalborg, Denmark'</font><font color="#007700">);<br></font><font color="#0000BB">?><br></font> +<font color="#0000BB"><?php<br>$metar </font><font color="#007700">= </font><font color="#0000BB">get_metar</font><font color="#007700">(</font><font color="#DD0000">'EKYT'</font><font color="#007700">);<br></font><font color="#0000BB">pretty_print_metar</font><font color="#007700">(</font><font color="#0000BB">$metar</font><font color="#007700">, </font><font color="#DD0000">'Tirstrup, Denmark'</font><font color="#007700">);<br></font><font color="#0000BB">?><br></font> </font> </code> @@ -325,11 +324,11 @@ the same directory as <code>phpweather.inc</code> and then point your <a href="http://www.wapforum.org/">WAP</a>-browser on your mobile phone to the page. It should then show you the current weather in -Aalborg, Denmark.</p> <p>The format used in the +Tirstrup, Denmark.</p> <p>The format used in the <code>wap.php</code>-page is a smaller and more compact format than the one shown on this page. It looks like this:</p> -<pre><? pretty_print_metar_wap(get_metar('EKYT'), 'Aalborg'); ?></pre> +<pre><? pretty_print_metar_wap(get_metar('EKYT'), 'Tirstrup'); ?></pre> <h1>Related information</h1> |
From: Martin G. <gim...@us...> - 2002-04-19 18:08:57
|
Update of /cvsroot/phpweather/phpweather-1.x In directory usw-pr-cvs1:/tmp/cvs-serv3315 Modified Files: INSTALL README Log Message: Small updates. Index: INSTALL =================================================================== RCS file: /cvsroot/phpweather/phpweather-1.x/INSTALL,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- INSTALL 27 Mar 2002 10:55:28 -0000 1.2 +++ INSTALL 19 Apr 2002 18:08:54 -0000 1.3 @@ -1,50 +1,51 @@ Installation instructions for PHP Weather -Copyright (C) 2000, 2001 Martin Geisler <gim...@gi...> +Copyright (C) 2000--2002 Martin Geisler <gim...@gi...> Licensed under the GNU GPL. See the file COPYING for details. -Getting the tarball -------------------- -You can always get the latest version from -http://www.sourceforge.net/projects/phpweather/ +Getting the source +------------------ +You can always get the latest version from this address: + + http://www.sourceforge.net/projects/phpweather/ Installation ------------ -To try out PHP Weather to see that it works, just untar the tarball +To try out PHP Weather to see that it works, just unpack the source into a directory on your webserver, and load the page demo.php in your favorite browser. -The page should show the current weather-conditions in Aalborg, -Denmark (that's where I live) and in Honolulu, Hawaii (that's not -where I live, but the weather is better there than in Denmark :-) -There will also be a drop-down list where you can select a city and a -language, so have the weather for that city displayed in the chosen +The page should show the current weather-conditions in Tirstrup, +Denmark (that's the airport closest to where I live) and in Honolulu, +Hawaii (that's unfortunately not where I live, but the weather is much +better there than in Denmark :-) There will also be a drop-down list +where you can select a city and a language, after which the page will +update with the weather for selected city displayed in the chosen language. -For a quick introduction to PHP Weather, see demo.php. It contains a -lot of examples and instructions on the use of PHP Weather. - -For detailed information about using PHP Weather please -see my webpages at this address: +For detailed information about using PHP Weather please see the +webpages at this address: - http://www.gimpster.com/php/phpweather/index.php + http://phpweather.net/docs/1.x/index.php -I've chosen to put the documentation there, because it's easier for me -to update. It also gives you a chance to see all the features of PHP -Weather in action. +Those pages should always be up-to-date whereas demo.php might be a +little old. Bugs? ----- If you find a bug or feature request for PHP Weather, please don't -hesitate to report it at http://sourceforge.net/projects/phpweather/ -We have a mailing list for general discussions about PHP Weather, -but before you can send mails to the list, you have to subscribe -to it - go to this page to subscribe: +hesitate to report it at this address: + + http://sourceforge.net/projects/phpweather/ + +We have a mailing list for general discussions about PHP Weather, but +before you can send mails to the list, you have to subscribe to it - +go to this page to subscribe: http://lists.sourceforge.net/lists/listinfo/phpweather-devel -If PHP Weather is decoding a METAR incorrectly, please remember to -include that METAR you're having problems with when you send a -message or submit a bug. Without it, we can't really help you. +If PHP Weather is decoding a METAR incorrectly, please remember to +include that METAR you're having problems with when you send a message +or submit a bug. Without it, we can't really help you. PHP Weather is known to work with PHP from version 3.0.12 and upward. If you find that it works with an earlier version, please write me! Index: README =================================================================== RCS file: /cvsroot/phpweather/phpweather-1.x/README,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -3 -r1.1.1.1 -r1.2 --- README 7 Mar 2002 09:49:11 -0000 1.1.1.1 +++ README 19 Apr 2002 18:08:54 -0000 1.2 @@ -1,18 +1,18 @@ README for PHP Weather -Copyright (C) 2000, 2001 Martin Geisler <gim...@gi...> +Copyright (C) 2000--2002 Martin Geisler <gim...@gi...> Licensed under the GNU GPL. See the file COPYING for details. What is PHP Weather? -------------------- -PHP Weather makes it easy to show the current weather on your webpage. -All over the world airports make a so-called METAR-report once an -hour. A METAR report is an aviation weather report to be used -primarily by airplanes. The report contains data, in a shorthand form, -about temperature, wind speed and direction, cloud-coverage and much -more. PHP Weather converts this format into both empirical and metric -units, caches the data in an XML file or a MySQL, Postgres, Oracle 8, -or DBM database for fast retrieval, and makes easy availably in PHP -scripts. +PHP Weather is designed to make it easy for you to show the current +weather on your webpage. All over the world airports make a so-called +METAR-report once an hour. A METAR report is an aviation weather +report to be used primarily by airplanes. The report contains data, in +a shorthand form, about temperature, wind speed and direction, +cloud-coverage and much more. PHP Weather converts this format into +both empirical and metric units, caches the data in an XML file or a +MySQL, Postgres, Oracle 8, or DBM database for fast retrieval, and +makes easy availably in PHP scripts. Installation ------------ @@ -24,31 +24,39 @@ Here is a list of the features PHP Weather provides: o Shows the current weather in natual language. - o Caches the result to increase performance. o Supports several languages. If you language isn't there, then please write a translation. + o Displays matching icons for the most common weather phenomena. + o Caches the result to increase performance. o Can be use with WAP-phones. Example-page included. -Please see http://www.gimpster.com/php/phpweather/index.php for full -details and examples. +Please see http://phpweather.net/docs/1.x/index.php for full details +and examples. -How to contact me ------------------ +How to report problems +---------------------- If you encounter problems with PHP Weather, or just want to suggest a -new feature, then please don't hesitate to contact me at this address: -<php...@li...>. The address is a -maillinglist - you have to be subscribed to be able to post messages -to it. To subscribe, go to this page: +new feature, then please don't hesitate to submit a new bug report or +feature request at SourceForge: + + http://sourceforge.net/tracker/?group_id=23245 + +You can also join the mailinglist and ask questions there: + + <php...@li...> + +You have to be subscribed to be able to post messages to it. To +subscribe, go to this page: http://lists.sourceforge.net/lists/listinfo/phpweather-devel -Please remember to include the METAR you're having problems with when -you send me a message. Without it, I can't really help you. +Please remember to include the METAR (the raw, coded weather report) +you're having problems with when you send a message. Without it, we +can't really help you. You can always get the newest version at http://www.sourceforge.net/projects/phpweather/ - Enjoy! - Martin Geisler <gim...@gi...> |
From: Martin G. <gim...@us...> - 2002-04-19 18:08:24
|
Update of /cvsroot/phpweather/phpweather-1.x In directory usw-pr-cvs1:/tmp/cvs-serv3010 Modified Files: phpweather.inc Log Message: We now use intval() together with round() when accessing arrays. Some versions of PHP didn't like it when we just used round() as round() returns a float and not an integer. It was Manuel Herrera <ing...@in...> tracked this bug down, thanks a lot! Index: phpweather.inc =================================================================== RCS file: /cvsroot/phpweather/phpweather-1.x/phpweather.inc,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- phpweather.inc 24 Mar 2002 19:52:32 -0000 1.2 +++ phpweather.inc 19 Apr 2002 18:08:20 -0000 1.3 @@ -695,24 +695,25 @@ /* now do ereg to get the actual values */ ereg("([0-9]{3}|VRB)([0-9]{2,3})(G([0-9]{2,3})?$windunit)", $part, $regs); if ($regs[1] == 'VRB') { - $decoded_metar['wind_deg'] = $strings['wind_vrb_long']; - $decoded_metar['wind_dir_text'] = $strings['wind_vrb_long']; - $decoded_metar['wind_dir_text_short'] = $strings['wind_vrb_short']; + $decoded_metar['wind_deg'] = $strings['wind_vrb_long']; + $decoded_metar['wind_dir_text'] = $strings['wind_vrb_long']; + $decoded_metar['wind_dir_text_short'] = $strings['wind_vrb_short']; } else { - $decoded_metar['wind_deg'] = $regs[1]; - $decoded_metar['wind_dir_text'] = $wind_dir_text_array[round($regs[1]/22.5)]; - $decoded_metar['wind_dir_text_short'] = $wind_dir_text_short_array[round($regs[1]/22.5)]; + $decoded_metar['wind_deg'] = $regs[1]; + $decoded_metar['wind_dir_text'] = + $wind_dir_text_array[intval(round($regs[1]/22.5))]; + $decoded_metar['wind_dir_text_short'] = + $wind_dir_text_short_array[intval(round($regs[1]/22.5))]; } store_speed($regs[2], - $windunit, - $decoded_metar['wind_meters_per_second'], - $decoded_metar['wind_knots'], - $decoded_metar['wind_miles_per_hour'] - ); + $windunit, + $decoded_metar['wind_meters_per_second'], + $decoded_metar['wind_knots'], + $decoded_metar['wind_miles_per_hour']); if (isset($regs[4])) { - /* We have a report with information about the gust. - First we have the gust measured in knots: */ + /* We have a report with information about the gust. First we + have the gust measured in knots: */ store_speed($regs[4],$windunit, $decoded_metar['wind_gust_meters_per_second'], $decoded_metar['wind_gust_knots'], @@ -726,43 +727,50 @@ $decoded_metar['wind_var_end'] = $regs[2]; } elseif ($part == 9999) { /* A strange value. When you look at other pages you see it - interpreted like this (where I use > to signify 'Greater - than'): */ + interpreted like this (where I use > to signify 'Greater + than'): */ $decoded_metar['visibility_miles'] = '>7'; $decoded_metar['visibility_km'] = '>11.3'; } elseif(ereg('^([0-9]{4})$', $part, $regs)) { /* * Visibility in meters (4 digits only) */ - /* The visibility measured in kilometers, rounded to one decimal place. */ $decoded_metar['visibility_km'] = number_format($regs[1]/1000, 1); - /* The visibility measured in miles, rounded to one decimal place. */ - $decoded_metar['visibility_miles'] = number_format( ($regs[1]/1000) / 1.609344, 1); + $decoded_metar['visibility_miles'] = + number_format( ($regs[1]/1000) / 1.609344, 1); } elseif (ereg('^[0-9]$', $part)) { /* * Temp Visibility Group, single digit followed by space */ $decoded_metar['temp_visibility_miles'] = $part; - } elseif (ereg('^M?(([0-9]?)[ ]?([0-9])(/?)([0-9]*))SM$', $decoded_metar['temp_visibility_miles'].' '.$parts[$i], $regs)) { + } elseif (ereg('^M?(([0-9]?)[ ]?([0-9])(/?)([0-9]*))SM$', + $decoded_metar['temp_visibility_miles'] . ' ' . + $parts[$i], $regs)) { /* * Visibility Group */ if ($regs[4] == '/') { - $vis_miles = $regs[2] + $regs[3]/$regs[5]; + $vis_miles = $regs[2] + $regs[3]/$regs[5]; } else { - $vis_miles = $regs[1]; + $vis_miles = $regs[1]; } if ($regs[0][0] == 'M') { - /* The visibility measured in miles, prefixed with < to indicate 'Less than' */ - $decoded_metar['visibility_miles'] = '<' . number_format($vis_miles, 1); - /* The visibility measured in kilometers. The value is rounded - to one decimal place, prefixed with < to indicate 'Less than' */ - $decoded_metar['visibility_km'] = '<' . number_format($vis_miles * 1.609344, 1); + /* The visibility measured in miles, prefixed with < to + indicate 'Less than' */ + $decoded_metar['visibility_miles'] = + '<' . number_format($vis_miles, 1); + /* The visibility measured in kilometers. The value is rounded + to one decimal place, prefixed with < to indicate 'Less + than' */ + $decoded_metar['visibility_km'] = + '<' . number_format($vis_miles * 1.609344, 1); } else { - /* The visibility measured in mile.s */ - $decoded_metar['visibility_miles'] = number_format($vis_miles, 1); - /* The visibility measured in kilometers, rounded to one decimal place. */ - $decoded_metar['visibility_km'] = number_format($vis_miles * 1.609344, 1); + /* The visibility measured in mile.s */ + $decoded_metar['visibility_miles'] = number_format($vis_miles, 1); + /* The visibility measured in kilometers, rounded to one + decimal place. */ + $decoded_metar['visibility_km'] = + number_format($vis_miles * 1.609344, 1); } } elseif ($part == 'CAVOK') { /* CAVOK: Used when the visibility is greather than 10 |
From: Martin G. <gim...@us...> - 2002-04-14 18:27:45
|
Update of /cvsroot/phpweather/phpweather/config In directory usw-pr-cvs1:/tmp/cvs-serv2974 Modified Files: index.php pw_optiongroup.php Log Message: Hehe - that was much easier that I thought... The optiongroups can now be toggled on and off. The state is remembered when people click the 'Update Configuration' button. I have (as usual) only tested this with Mozilla 0.9.9. Index: index.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/index.php,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- index.php 12 Apr 2002 22:04:43 -0000 1.4 +++ index.php 14 Apr 2002 18:27:38 -0000 1.5 @@ -290,13 +290,14 @@ /* Grouping */ $general_group = - new pw_optiongroup('General Options', + new pw_optiongroup('general_group', 'General Options', 'This is some general options for PHP Weather.', array('verbosity', 'icao', 'pref_units', 'language', 'offset', - 'use_proxy', 'proxy_host', 'proxy_port')); + 'use_proxy', 'proxy_host', 'proxy_port'), + !empty($HTTP_POST_VARS['general_group_visible'])); $db_group = - new pw_optiongroup('Database Options', + new pw_optiongroup('db_group', 'Database Options', 'These options deal with the database. PHP Weather ' . 'can use a database for caching the METARs it ' . 'retrieves. This is very nice, since it takes at ' . @@ -305,12 +306,14 @@ array('db_type', 'db_handler', 'db_pconnect', 'always_use_db', 'cache_timeout', 'db_hostname', 'db_port', 'db_username', 'db_password', 'db_database', - 'db_metars', 'db_stations', 'db_countries')); + 'db_metars', 'db_stations', 'db_countries'), + !empty($HTTP_POST_VARS['db_group_visible'])); $rendering_group = - new pw_optiongroup('Rendering Options', + new pw_optiongroup('rendering_group', 'Rendering Options', 'You can customize the looks of PHP Weather using these options.', - array('mark_begin', 'mark_end', 'exclude')); + array('mark_begin', 'mark_end', 'exclude'), + !empty($HTTP_POST_VARS['rendering_group_visible'])); /* We can now generate a configuration file with the options selected so far: */ @@ -382,6 +385,21 @@ (field.value >= low && field.value <= high), error, field.value, output); } + +function toggle_group(id) { + group = document.getElementById(id); + text = document.getElementById(id + "_text"); + input = document.getElementById(id + "_input"); + if (group.style.display == "none") { + text.innerHTML = "Hide options."; + group.style.display = "block"; + input.value = 1; + } else { + text.innerHTML = "Show options."; + group.style.display = "none"; + input.value = 0; + } +} </script> <img src="../icons/phpweather-long-white.gif" alt="PHP Weather" align="right"> @@ -390,7 +408,7 @@ <p>This is the Configuretor shipped with PHP Weather.</p> <p>Change the options below - when you're done, then press one of the -'Update Options' buttons. Depending on your choices, more options +'Update Configuration' buttons. Depending on your choices, more 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"> Index: pw_optiongroup.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_optiongroup.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- pw_optiongroup.php 13 Apr 2002 13:12:29 -0000 1.2 +++ pw_optiongroup.php 14 Apr 2002 18:27:40 -0000 1.3 @@ -10,6 +10,23 @@ class pw_optiongroup { /** + * A unique identifier for this group. + * + * This is used in the Javascript for collapsing and expanding the + * group. + * + * @var string The ID of this group. + */ + var $id; + + /** + * Is this group visible? + * + * @var boolean true if the group is visible, false otherwise. + */ + var $visible; + + /** * The title of this group. * * @var string The title of this group. @@ -42,10 +59,12 @@ * @param array $options The names of the options in the group. * */ - function pw_optiongroup($title, $description, $options) { + function pw_optiongroup($id, $title, $description, $options, $visible = true) { + $this->id = $id; $this->title = $title; $this->description = $description; $this->options = $options; + $this->visible = $visible; } /** @@ -56,10 +75,22 @@ * be inserted in their own description-list. */ function show() { - - echo "<dt>$this->title <input type=\"submit\" value=\"Update options\"></dt>\n"; + if ($this->visible) { + $style = 'block'; + $text = 'Hide options.'; + echo '<input id="' . $this->id . '_input" type="hidden" name="' . + $this->id . '_visible" value="1">' . "\n"; + } else { + $style = 'none'; + $text = 'Show options.'; + echo '<input id="' . $this->id . '_input" type="hidden" name="' . + $this->id . '_visible" value="0">' . "\n"; + } + echo "<dt>$this->title</dt>\n"; echo "<dd><p>$this->description</p>\n"; - echo "<dl>\n"; + echo "<p><a href=\"javascript:toggle_group('$this->id')\" id=\"" . + $this->id . "_text\">$text</a></p>\n"; + echo "<dl id=\"$this->id\" style=\"display: $style\">\n"; foreach($this->options as $option) { $GLOBALS['options'][$option]->show(); |
From: Martin G. <gim...@us...> - 2002-04-13 13:23:43
|
Update of /cvsroot/phpweather/phpweather In directory usw-pr-cvs1:/tmp/cvs-serv20409 Modified Files: phpweather.php Log Message: Updated documentation. Index: phpweather.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/phpweather.php,v retrieving revision 1.22 retrieving revision 1.23 diff -u -3 -r1.22 -r1.23 --- phpweather.php 29 Mar 2002 13:51:55 -0000 1.22 +++ phpweather.php 13 Apr 2002 13:23:41 -0000 1.23 @@ -1,8 +1,23 @@ <?php -/* The location of this file defines the base directory */ +/** + * The base directory of the PHP Weather installation. + * + * When another file needs to include a file, this constant is used as + * the base directory. The location of this file defines the base + * directory + * + * @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. + * @include The definition of data_retrieval. + */ require_once(PHPWEATHER_BASE_DIR . '/data_retrieval.php'); /** @@ -12,7 +27,9 @@ * * @author Martin Geisler <gim...@gi...> * @version $Id$ - * @see $decoded_metar + * @package PHP Weather + * @access public + * @see $decoded_metar */ class phpweather extends data_retrieval { |
From: Martin G. <gim...@us...> - 2002-04-13 13:21:14
|
Update of /cvsroot/phpweather/phpweather/docs/html In directory usw-pr-cvs1:/tmp/cvs-serv19849 Removed Files: metar_parser.html Log Message: Remove that one too... --- metar_parser.html DELETED --- |
From: Martin G. <gim...@us...> - 2002-04-13 13:19:40
|
Update of /cvsroot/phpweather/phpweather/docs/html In directory usw-pr-cvs1:/tmp/cvs-serv19209 Removed Files: db_common.html db_dba.html db_mysql.html db_null.html db_pgsql.html locale_common.html locale_en.html locale_da.html locale_hu.html Log Message: These files are no longer used - the corresponding sourcefiles have been renamed or removed. --- db_common.html DELETED --- --- db_dba.html DELETED --- --- db_mysql.html DELETED --- --- db_null.html DELETED --- --- db_pgsql.html DELETED --- --- locale_common.html DELETED --- --- locale_en.html DELETED --- --- locale_da.html DELETED --- --- locale_hu.html DELETED --- |
From: Martin G. <gim...@us...> - 2002-04-13 13:12:32
|
Update of /cvsroot/phpweather/phpweather/config In directory usw-pr-cvs1:/tmp/cvs-serv17891/config Modified Files: pw_dependency.php pw_dependency_or.php pw_option.php pw_optiongroup.php pw_validator_ereg.php pw_validator_range.php Log Message: Added documentation. Index: pw_dependency.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_dependency.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- pw_dependency.php 7 Apr 2002 18:38:20 -0000 1.1 +++ pw_dependency.php 13 Apr 2002 13:12:29 -0000 1.2 @@ -1,14 +1,48 @@ <?php + +/** + * This is the baseclass for all dependencies. + * + * @author Martin Geisler <gim...@gi...> + * @version $Id$ + * @package PHP Weather Configurator + * @abstract + */ class pw_dependency { + /** + * The name of an option. + * + * @var string The name of the option that should be checked. + */ var $option; + + /** + * The value that the option must have to satisfy this dependency. + * + * @var string The required value. + */ var $dep; - function pw_dependency($option, $d) { + /** + * Constructs a new dependency. + * + * @param string $option The name of the option that must satisfy + * the dependency. + * @param string $dep The required value of the option. + * + */ + function pw_dependency($option, $dep) { $this->option = $option; - $this->dep = $d; + $this->dep = $dep; } + /** + * Checks a dependency. + * + * @return boolean True if the dependency is satisfied, false + * otherwise. + */ function check() { return ($GLOBALS['options'][$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.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- pw_dependency_or.php 7 Apr 2002 18:38:20 -0000 1.1 +++ pw_dependency_or.php 13 Apr 2002 13:12:29 -0000 1.2 @@ -1,9 +1,30 @@ <?php +/** + * An 'or' dependency. + * + * This dependency is a collection of several dependencies, but it + * will be satisfied as long a just one of them is satisfied. + * + * @author Martin Geisler <gim...@gi...> + * @version $Id$ + * @package PHP Weather Configurator + */ class pw_dependency_or extends pw_dependency { - function pw_dependency_or($option, $d) { - $this->pw_dependency($option, $d); + /** + * Constructs a new 'or' dependency. + * + * @param string $option The name of the option that must satisfy + * one of the dependencies. + * + * @param array $dependencies This should be an array of strings. If + * the value of $option equals just one of these strings, then the + * dependency is satisfied. + * + */ + function pw_dependency_or($option, $dependencies) { + $this->pw_dependency($option, $dependencies); } function check() { Index: pw_option.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_option.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- pw_option.php 12 Apr 2002 22:08:49 -0000 1.2 +++ pw_option.php 13 Apr 2002 13:12:29 -0000 1.3 @@ -5,6 +5,8 @@ * * @author Martin Geisler <gim...@gi...> * @version $Id$ + * @package PHP Weather Configurator + * @abstract */ class pw_option { @@ -88,18 +90,43 @@ } + /** + * Get the name of this option. + * + * @return the name of the option. + */ function get_name() { return $this->name; } + /** + * Get the description of this option. + * + * @return the description of the option. + */ function get_description() { return $this->description; } + /** + * Get the value of this option. + * + * @return the value of the option. + */ function get_value() { return $this->value; } + /** + * Checks to see if this option is ready to be displayed. + * + * When this method is called, the option will go through it's + * dependencies and make sure that they're all satisfied. You + * shouldn't use an option that isn't ready. + * + * @return boolean True if the option is ready to be displayed, + * false otherwise. + */ function is_ready() { $ready = true; foreach($this->dependencies as $dependency) { @@ -111,16 +138,40 @@ return $ready; } + /** + * Checks to see if this option has a valid value. + * + * The validator that was supplied when the option was created is + * asked to validate the current value of the option. + * + * @return boolean True if the option has a valid value false + * otherwise. + */ function is_valid() { return $this->validator->validate($this->value); } + /** + * Updates the current value. + * + * @param array New values. This array should have the same + * structure as $_REQUEST which means that it should contain + * option_name_value => value pairs where option_name is the name of + * an option. + */ function update_value($values) { if (isset($values[$this->name . '_value'])) { $this->value = $values[$this->name . '_value']; } } + /** + * Returns the configuration. + * + * @return string A string suitable for inclusion in the + * defaults.php file. If the option isn't ready yet or it's invalid + * an empty string is returned. + */ function get_config() { if ($this->is_ready() && $this->is_valid() && $this->value != $this->default) { Index: pw_optiongroup.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_optiongroup.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- pw_optiongroup.php 7 Apr 2002 18:38:20 -0000 1.1 +++ pw_optiongroup.php 13 Apr 2002 13:12:29 -0000 1.2 @@ -1,17 +1,60 @@ <?php +/** + * A group of options. + * + * @author Martin Geisler <gim...@gi...> + * @version $Id$ + * @package PHP Weather Configurator + */ class pw_optiongroup { + /** + * The title of this group. + * + * @var string The title of this group. + */ var $title; + + /** + * The description of this group. + * + * @var string The description of this group. + */ var $description; + + /** + * The options which are part of this group. + * + * @var array The names of the options which are part of this group. + */ var $options; + /** + * Constructs a new group of options. + * + * Optiongroups are used to - well - group similar options. By + * grouping the options, you can provide a broad description of the + * them before the individual options presnet their own description. + * + * @param string $title The title of the group. + * @param string $description The description of the group. + * @param array $options The names of the options in the group. + * + */ function pw_optiongroup($title, $description, $options) { $this->title = $title; $this->description = $description; $this->options = $options; } + /** + * Shows the group and the options it contains. + * + * It is assumed that the call to this method is wrapped in a + * description-list (<dl>...</dl>). The options of this group will + * be inserted in their own description-list. + */ function show() { echo "<dt>$this->title <input type=\"submit\" value=\"Update options\"></dt>\n"; @@ -27,6 +70,15 @@ } + /** + * Returns the configuration. + * + * The configuration is ready to be inserted into the defaults.php + * file. It includes a header with the title of the group followed + * by the configuration of the options. + * + * @return string The configuration of the options in the group. + */ function get_config() { $config = ''; Index: pw_validator_ereg.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_validator_ereg.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- pw_validator_ereg.php 9 Apr 2002 23:21:37 -0000 1.2 +++ pw_validator_ereg.php 13 Apr 2002 13:12:29 -0000 1.3 @@ -1,19 +1,58 @@ <? - +/** + * Validates input against a regular expression. + * + * @author Martin Geisler <gim...@gi...> + * @version $Id$ + * @package PHP Weather Configurator + */ class pw_validator_ereg extends pw_validator { + /** + * The regular expression used when validating. + * + * @var string A regular expression. + */ var $regex; + /** + * Constructs a new ereg_validator. + * + * @param string $error The message displayed when the input is + * invalid. + * @param string $regex The regular expression used when validating. + */ function pw_validator_ereg($error, $regex) { $this->pw_validator($error); $this->regex = $regex; } - + + /** + * Validates input agains a regular expression. + * + * Validates some input. + * + * @param mixed $value The input that should be matched agains the + * regular expression. + * + * @return boolean True if the regular expression matched the input, + * false otherwise. + * @access public + */ function validate($value) { $this->value = $value; return ereg($this->regex, $value); } + /** + * Returns code for the keyup event in input fields. + * + * @param string $id The name that should be passed to the + * Javascript as an ID. The ID is used by the Javascript to change + * the right paragraph at runtime. + * @return string A string suitable for the keyup event on an text + * input field. + */ function get_javascript($id) { return "validate_ereg('" . addslashes($this->error) . "', '$this->regex', '$id', this)"; Index: pw_validator_range.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_validator_range.php,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- pw_validator_range.php 12 Apr 2002 22:07:11 -0000 1.3 +++ pw_validator_range.php 13 Apr 2002 13:12:29 -0000 1.4 @@ -6,6 +6,9 @@ * usefull for testing port-numbers (range 1--65536) or peoples age * (range 1--120) etc. * + * @author Martin Geisler <gim...@gi...> + * @version $Id$ + * @package PHP Weather Configurator */ class pw_validator_range extends pw_validator { @@ -44,6 +47,16 @@ $this->empty_ok = $empty_ok; } + /** + * Validate an integer. + * + * The input is validated to see if it's within the range specified + * when the validator was created. + * + * @param integer $value The new integer that should be validated. + * @return boolean Returns true if the integer is within the correct + * range, false otherwise. + */ function validate($value) { $this->value = $value; @@ -52,6 +65,15 @@ return (ereg('^[-+]?[0-9]+$', $value) && $this->low <= $value && $value <= $this->high); } + /** + * Returns code for the keyup event in input fields. + * + * @param string $id The name that should be passed to the + * Javascript as an ID. The ID is used by the Javascript to change + * the right paragraph at runtime. + * @return string A string suitable for the keyup event on an text + * input field. + */ function get_javascript($id) { $empty_ok = $this->empty_ok ? '1' : '0'; return "validate_range('" . addslashes($this->error) . |
From: Martin G. <gim...@us...> - 2002-04-13 13:11:56
|
Update of /cvsroot/phpweather/phpweather/config In directory usw-pr-cvs1:/tmp/cvs-serv17789/config Modified Files: pw_validator.php Log Message: Added documentation. Index: pw_validator.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_validator.php,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- pw_validator.php 12 Apr 2002 22:07:51 -0000 1.3 +++ pw_validator.php 13 Apr 2002 13:11:53 -0000 1.4 @@ -1,6 +1,13 @@ <?php -/** Abstract baseclass for all validators. */ +/** + * This is the baseclass for all validators. + * + * @author Martin Geisler <gim...@gi...> + * @version $Id$ + * @package PHP Weather Configurator + * @abstract + */ class pw_validator { /** @@ -60,6 +67,9 @@ /** * Returns code for the keyup event in input fields. * + * @param string $id The name that should be passed to the + * Javascript as an ID. The ID is used by the Javascript to change + * the right paragraph at runtime. * @return string A string suitable for the keyup event on an text * input field. */ |
From: Martin G. <gim...@us...> - 2002-04-12 22:10:46
|
Update of /cvsroot/phpweather/phpweather In directory usw-pr-cvs1:/tmp/cvs-serv18109 Modified Files: data_retrieval.php Log Message: We now use $this->properties['cache_timeout'] instead of the hardcoded 3600 seconds. Index: data_retrieval.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/data_retrieval.php,v retrieving revision 1.21 retrieving revision 1.22 diff -u -3 -r1.21 -r1.22 --- data_retrieval.php 22 Mar 2002 17:54:08 -0000 1.21 +++ data_retrieval.php 12 Apr 2002 22:10:43 -0000 1.22 @@ -157,7 +157,8 @@ * necessary. */ $this->metar = $metar; - if ($this->properties['always_use_db'] || $timestamp > time() - 3600) { + if ($this->properties['always_use_db'] || + $timestamp > time() - $this->properties['cache_timeout']) { /* We have asked explicit for a cached METAR, or the METAR is * still fresh. Either way - we return the METAR we found in @@ -165,13 +166,15 @@ */ $this->debug('get_metar_from_db(): Using previously cached METAR for <code>' . $this->get_location() . '</code>. The METAR expires in ' . - ($timestamp + 3600 - time()) . ' seconds.'); + ($timestamp + $this->properties['cache_timeout'] - time()) . + ' seconds.'); return $metar; } else { /* The METAR is too old, so we fetch new */ $this->debug('get_metar_from_db(): The METAR for <code>' . $this->get_location() . '</code> was ' . - (time() - 3600 - $timestamp) . ' seconds too old.'); + (time() - $this->properties['cache_timeout'] - $timestamp) . + ' seconds too old.'); return $this->get_metar_from_web(false); } } else { @@ -265,13 +268,13 @@ $metar = gmdate('dHi', $timestamp) . 'Z ' . $metar; } - if ($timestamp < (time() - 3300)) { + if ($timestamp < (time() - $this->properties['cache_timeout'] + 300)) { /* The timestamp in the METAR is more than 55 minutes old. We * adjust the timestamp, so that we won't try to fetch a new * METAR within the next 5 minutes. After 5 minutes, the * timestamp will again be more than 1 hour old. */ - $timestamp = time() - 3300; + $timestamp = time() - $this->properties['cache_timeout'] + 300; } } else { /* If we end up here, it means that there was no file. If the @@ -285,7 +288,7 @@ } else { $metar = $this->metar; } - $timestamp = time() - 3000; + $timestamp = time() - $this->properties['cache_timeout'] + 600; } /* We then cache the METAR in our database */ |
From: Martin G. <gim...@us...> - 2002-04-12 22:08:53
|
Update of /cvsroot/phpweather/phpweather/config In directory usw-pr-cvs1:/tmp/cvs-serv17587 Modified Files: pw_option.php Log Message: Documentation plus some minor bugfixes. Index: pw_option.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_option.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- pw_option.php 7 Apr 2002 18:38:20 -0000 1.1 +++ pw_option.php 12 Apr 2002 22:08:49 -0000 1.2 @@ -1,12 +1,74 @@ <?php +/** + * This is the baseclass for all options. + * + * @author Martin Geisler <gim...@gi...> + * @version $Id$ + */ class pw_option { + /** + * The name of this option. + * + * 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'] + * + * @var string + */ var $name = ''; + + /** + * A description of the option. + * + * This should be a note that explains what this option does. + * + * @var string + */ var $description = ''; + + /** + * The dependencies of this option. + * + * If this option depends on other options, then their names will be + * listed in this array. If this options doesn't have any + * dependencies, then the array will be empty. + * + * @var array + */ var $dependencies = array(); + + /** + * The current value of the option. + * + * @access private + * @var string + */ var $value = ''; + + /** + * The default value of the option. + * + * This will be used to determine if the option has changed. A call + * to get_config() will only return a non-empty string if the option + * is changed. + * + * @access private + * @var string + */ var $default = ''; + + /** + * The validator used by this option. + * + * The validator will be asked to validate the value of the option + * to determine if the input is valid. If not, then a call to + * get_config() will return an empty string. + * + * @access private + * @var pw_validator + */ var $validator; function pw_option($name, $description, $dependencies, @@ -19,7 +81,7 @@ } else { $this->validator = new pw_validator('Please correct your input'); } - if ($default) { + if ($default !== false) { $this->default = $default; $this->update_value(array($name . '_value' => $default)); } |
From: Martin G. <gim...@us...> - 2002-04-12 22:07:54
|
Update of /cvsroot/phpweather/phpweather/config In directory usw-pr-cvs1:/tmp/cvs-serv17323 Modified Files: pw_validator.php Log Message: Added documentation. Index: pw_validator.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_validator.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- pw_validator.php 9 Apr 2002 23:21:37 -0000 1.2 +++ pw_validator.php 12 Apr 2002 22:07:51 -0000 1.3 @@ -1,23 +1,68 @@ <?php +/** Abstract baseclass for all validators. */ class pw_validator { + /** + * The message displayed when the input is invalid. + * + * @var string + * @access private + */ var $error; + + /** + * The last value validated. + * + * @var string + * @access private + */ var $value; + /** + * Constructs a new validator. + * + * @param string $error The message displayed when the input is + * invalid. + */ function pw_validator($error) { $this->error = $error; } + /** + * Validate some input. + * + * This method should be overridden by the subclasses so that they + * can validate the input according to their type. + * + * @param string $value The new value that should be validated. + * @return boolean Returns true if the input it valid, false otherwise. + * + */ function validate($value) { $this->value = $value; return true; } + /** + * Returns the error message. + * + * The message is fed to sprintf() so that '%s' in the messages is + * replaced by the last value that was validated using this + * validator. + * + * @return string The error message. + */ function get_error() { return sprintf($this->error, $this->value); } + /** + * Returns code for the keyup event in input fields. + * + * @return string A string suitable for the keyup event on an text + * input field. + */ function get_javascript($id) { return ''; } |
From: Martin G. <gim...@us...> - 2002-04-12 22:07:16
|
Update of /cvsroot/phpweather/phpweather/config In directory usw-pr-cvs1:/tmp/cvs-serv17011 Modified Files: pw_validator_range.php Log Message: Documentation plus some minor bugfixes. Index: pw_validator_range.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_validator_range.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- pw_validator_range.php 9 Apr 2002 23:21:37 -0000 1.2 +++ pw_validator_range.php 12 Apr 2002 22:07:11 -0000 1.3 @@ -1,31 +1,62 @@ <? - +/** + * Validates an integer. + * + * This class checks that an interger is in a given range. This is + * usefull for testing port-numbers (range 1--65536) or peoples age + * (range 1--120) etc. + * + */ class pw_validator_range extends pw_validator { + /** + * The lower bound in the range + * @var integer + * @access private + */ var $low; + + /** + * The upper bound in the range + * @var integer + * @access private + */ var $high; - var $empty_ok; + /** You might want to allow the empty string as valid input. + * @var boolean + * @access private + */ + var $empty_ok; + + /** + * Constructs a new validator. + * + * @param string $error The message displayed when invalid input is given. + * @param integer $low The lower bound of the range. + * @param integer $high The upper bound of the range. + * @param boolean $empty_ok Is the empty string valid? + */ function pw_validator_range($error, $low, $high, $empty_ok = false) { $this->pw_validator($error); $this->low = $low; $this->high = $high; $this->empty_ok = $empty_ok; } - + function validate($value) { $this->value = $value; if ($this->empty_ok && empty($value)) return true; - return (ereg('^[0-9]+$', $value) && $this->low <= $value && $value <= $this->high); + return (ereg('^[-+]?[0-9]+$', $value) && $this->low <= $value && $value <= $this->high); } function get_javascript($id) { + $empty_ok = $this->empty_ok ? '1' : '0'; return "validate_range('" . addslashes($this->error) . - "', $this->low, $this->high, $this->empty_ok, '$id', this)"; + "', $this->low, $this->high, $empty_ok, '$id', this)"; } - } ?> |
From: Martin G. <gim...@us...> - 2002-04-12 22:04:45
|
Update of /cvsroot/phpweather/phpweather/config In directory usw-pr-cvs1:/tmp/cvs-serv16352 Modified Files: index.php Log Message: Two new options were added: cache_timeout and offset. I've also reindented the code. Index: index.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/index.php,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- index.php 9 Apr 2002 23:21:37 -0000 1.3 +++ index.php 12 Apr 2002 22:04:43 -0000 1.4 @@ -13,6 +13,7 @@ require_once('pw_option_select.php'); require_once('pw_option_multi_select.php'); require_once('pw_option_boolean.php'); +require_once('pw_option_integer.php'); /* We want to group the options: */ require_once('pw_optiongroup.php'); @@ -50,9 +51,13 @@ $dba_dep = new pw_dependency('db_type', 'dba'); $proxy_dep = new pw_dependency('use_proxy', 'true'); - $port_validator = - new pw_validator_range("Sorry, '%s' is not a valid port-number because " . - "is't outside the range 1-65536", 1, 65536, true); + $port_validator = new pw_validator_range("Sorry, '%s' is not a valid port-number " . + "because is't outside the range 1-65536", + 1, 65536); + $port_validator_empty = new pw_validator_range("Sorry, '%s' is not a valid port-number " . + "because is't outside the range 1-65536", + 1, 65536, true); + /* This just catches the most obvious errors. */ $table_validator = new pw_validator_ereg("Sorry, '%s' is not a valid name.", '^[^./]+$'); @@ -67,187 +72,206 @@ $options['verbosity'] = new pw_option_select('verbosity', - "The setting of this variable controls the amount of " . - "errors, warnings, and debug-information PHP Weather " . - "will print. It is suggested that you always include " . - "errors in the output and perhaps also warnings.", - array(), - array('1' => 'Errors only', - '2' => 'Warnings only', - '4' => 'Debug information only', - '3' => 'Errors + warnings', - '5' => 'Errors + debug information', - '6' => 'Warnings + debug information', - '7' => 'Everything') - ); - + "The setting of this variable controls the amount of " . + "errors, warnings, and debug-information PHP Weather " . + "will print. It is suggested that you always include " . + "errors in the output and perhaps also warnings.", + array(), + array('1' => 'Errors only', + '2' => 'Warnings only', + '4' => 'Debug information only', + '3' => 'Errors + warnings', + '5' => 'Errors + debug information', + '6' => 'Warnings + debug information', + '7' => 'Everything')); + $options['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' - ); - + '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'] = new pw_option_select('pref_units', - 'You may choose to display the data in several ' . - 'formats. Please choose one that fits your need.', - array(), - array('both_metric' => 'Metric first, then imperial', - 'both_imperial' => 'Imperial first, then metric', - 'only_metric' => 'Only metric', - 'only_imperial' => 'Only imperial')); + 'You may choose to display the data in several ' . + 'formats. Please choose one that fits your need.', + array(), + array('both_metric' => 'Metric first, then imperial', + 'both_imperial' => 'Imperial first, then metric', + 'only_metric' => 'Only metric', + 'only_imperial' => 'Only imperial')); $options['language'] = new pw_option_select('language', - 'PHP Weather can produce output in several languages ' . - '- please select your default from the list.', - array(), - array('en' => 'English', - 'da' => 'Danish', - 'hu' => 'Hungarian', - 'no' => 'Norwegian')); - + 'PHP Weather can produce output in several languages ' . + '- please select your default from the list.', + array(), + array('en' => 'English', + 'da' => 'Danish', + 'hu' => 'Hungarian', + 'no' => 'Norwegian')); + + $options['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 " . + "offset here. For example, if your times generated are 1 " . + "hour too early (so METARs appear an hour older than they " . + "are), set this option to be +1.", + array(), false, 0); + $options['use_proxy'] = new pw_option_boolean('use_proxy', - "Set this option to 'Yes' to enable support for a " . - "proxy server.", - array(), - array('false' => 'No', - 'true' => 'Yes')); + "Set this option to 'Yes' to enable support for a " . + "proxy server.", + array(), + array('false' => 'No', + 'true' => 'Yes')); $options['proxy_host'] = new pw_option_text('proxy_host', - "This is the hostname of the proxy server.", - array($proxy_dep), $host_validator); - + "This is the hostname of the proxy server.", + array($proxy_dep), $host_validator); + $options['proxy_port'] = - new pw_option_text('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'); - + 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'] = new pw_option_select('db_type', - 'PHP Weather can use several kinds of databases.', - array(), - array('null' => 'No database at all', - 'mysql' => 'A MySQL database', - 'pgsql' => 'A PostgreSQL database', - 'dba' => 'A DBA database')); + 'PHP Weather can use several kinds of databases.', + array(), + array('null' => 'No database at all', + 'mysql' => 'A MySQL database', + 'pgsql' => 'A PostgreSQL database', + 'dba' => 'A DBA database')); $options['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 " . - "please select the handler you would like to use.", - array($dba_dep), - array('dbm' => 'dbm - The oldest (original) type of ' . - 'Berkeley DB style databases', - 'ndbm' => 'ndbm - a newer and more flexible type.', - 'gdbm' => 'gdbm - The GNU database manager', - 'db2' => 'db2 - Sleepycat Softwares DB2', - 'db3' => 'db3 - Sleepycat Softwares DB3')); - + "If you've chosen to use a Berkeley DB style database " . + "through the PHP database abstraction layer (DBA), then " . + "please select the handler you would like to use.", + array($dba_dep), + array('dbm' => 'dbm - The oldest (original) type of ' . + 'Berkeley DB style databases', + 'ndbm' => 'ndbm - a newer and more flexible type.', + 'gdbm' => 'gdbm - The GNU database manager', + 'db2' => 'db2 - Sleepycat Softwares DB2', + 'db3' => 'db3 - Sleepycat Softwares DB3')); + $options['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, " . - "even if it's too old. But if the data isn't there, " . - "it will still fetch new data from the Internet.", - array($db_dep), - array('false' => 'No', 'true' => 'Yes')); + "If you set this option to 'Yes', then PHP Weather " . + "will always use the data it finds in the database, " . + "even if it's too old. But if the data isn't there, " . + "it will still fetch new data from the Internet.", + array($db_dep), + array('false' => 'No', 'true' => 'Yes')); + + $options['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 " . + "number of seconds, then an attempt is made to fetch " . + "a new METAR from the web. The default value is 3600 " . + "seconds (1 hour), but some stations make two " . + "reports each hour, so you might want to lower this " . + "number to perhaps 2400 or even 1800.", + array(new pw_dependency('always_use_db', 'false'), $db_dep), + false, '3600'); $options['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')); - + "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'] = - new pw_option_text('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); + 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'] = 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); + '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'] = new pw_option_text('db_database', - 'This is the name of the database that PHP Weather ' . - 'should use.', - array($sql_dep), $table_validator); + 'This is the name of the database that PHP Weather ' . + 'should use.', + array($sql_dep), $table_validator); $options['db_username'] = new pw_option_text('db_username', - 'This is the username that PHP Weather will use ' . - 'for accessing the database.', - array($sql_dep)); + 'This is the username that PHP Weather will use ' . + 'for accessing the database.', + array($sql_dep)); $options['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 ' . - "remember to protect the file after you've stored the " . - "password in it.", - array($sql_dep)); - + 'This is the password that PHP Weather will use when ' . + 'trying to make a connection to the database. Please ' . + "remember to protect the file after you've stored the " . + "password in it.", + array($sql_dep)); + $options['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'); + 'This is the name of the table that is used ' . + 'to cache the METARs.', + array($db_dep), $table_validator, 'pw_metars'); $options['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'); + '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'] = 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 ' . - 'country-codes.', - array($dba_dep), $table_validator, 'pw_countries'); - - + 'This is the name of the database that is used to ' . + 'store the names of the countries together with ' . + 'country-codes.', + array($dba_dep), $table_validator, 'pw_countries'); + + $options['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 " . - 'this to happen, then just use an empty string. ' . - "Other good choices include <code><i></code>, <code><font " . - 'color="red"></code>, etc.', - array(), false, '<b>'); - + 'This string will be placed in front of all the ' . + "changable parts of the output. If you don't want " . + 'this to happen, then just use an empty string. ' . + "Other good choices include <code><i></code>, <code><font " . + 'color="red"></code>, etc.', + array(), false, '<b>'); + $options['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>'); - + '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'] = new pw_option_multi_select('exclude', - 'You can disable some of the output produced. If ' . - "you're not interested in information about " . - 'runways-visibility, then select it in this list. ' . - 'You can select several options at once in Netscape ' . - 'by holding down Ctrl while clicking on the option.', - array(), - array('time' => 'Leave out the time part', - 'wind' => 'Leave out the wind part', - 'runway' => 'Leave out information about runways')); - + 'You can disable some of the output produced. If ' . + "you're not interested in information about " . + 'runways-visibility, then select it in this list. ' . + 'You can select several options at once in Netscape ' . + 'by holding down Ctrl while clicking on the option.', + array(), + array('time' => 'Leave out the time part', + 'wind' => 'Leave out the wind part', + 'runway' => 'Leave out information about runways')); + /* Finally - we register all the options with the session. */ session_register('options'); @@ -268,7 +292,7 @@ $general_group = new pw_optiongroup('General Options', 'This is some general options for PHP Weather.', - array('verbosity', 'icao', 'pref_units', 'language', + array('verbosity', 'icao', 'pref_units', 'language', 'offset', 'use_proxy', 'proxy_host', 'proxy_port')); $db_group = @@ -279,8 +303,8 @@ 'least a second or two to fetch a METAR from the ' . 'National Weather Service.', array('db_type', 'db_handler', 'db_pconnect', 'always_use_db', - 'db_hostname', 'db_port', 'db_database', - 'db_username', 'db_password', + 'cache_timeout', 'db_hostname', 'db_port', + 'db_username', 'db_password', 'db_database', 'db_metars', 'db_stations', 'db_countries')); $rendering_group = |
From: Martin G. <gim...@us...> - 2002-04-12 22:01:52
|
Update of /cvsroot/phpweather/phpweather/config In directory usw-pr-cvs1:/tmp/cvs-serv15292 Added Files: pw_option_integer.php Log Message: New wrapper-type: integers doesn't need to be quoted in defaults.php. --- NEW FILE --- <?php class pw_option_integer extends pw_option_text { function pw_option_integer($name, $description, $dependencies, $validator = false, $default = false) { if (!$validator) { $validator = new pw_validator_ereg("Sorry, '%s' is not an integer.", '^[-+]?[0-9]+$'); } $this->pw_option_text($name, $description, $dependencies, $validator, $default); } function get_config() { if ($this->is_ready() && $this->is_valid() && $this->value != $this->default) { return "/* $this->name */\n\$this->properties['$this->name'] = " . "$this->value;\n\n"; } else { return ''; } } } ?> |
From: Martin G. <gim...@us...> - 2002-04-12 22:00:31
|
Update of /cvsroot/phpweather/phpweather In directory usw-pr-cvs1:/tmp/cvs-serv14635 Modified Files: defaults-dist.php Log Message: Added a new option: cache_timeout. This is used to determine when a METAR is old. The default value is 3600 seconds which was the value used in data_retrieval before. Index: defaults-dist.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/defaults-dist.php,v retrieving revision 1.11 retrieving revision 1.12 diff -u -3 -r1.11 -r1.12 --- defaults-dist.php 18 Mar 2002 16:19:58 -0000 1.11 +++ defaults-dist.php 12 Apr 2002 22:00:27 -0000 1.12 @@ -8,14 +8,18 @@ * some reason, then it's also simple to edit this file manually: * * 1) save this file as 'defaults.php' - * 2) remove everything you don't need - * 3) change the options you want + * 2) change the options you want + * 3) remove everything you didn't change * - * That's it! You can keep your new file (defaults.php) when upgrading - * PHP Weather, as it will only contain new version of this file. */ + * That's it! You can keep your file (defaults.php) with your + * modifications when upgrading PHP Weather, as the tarball will only + * contain a new defaults-dist.php. + */ $this->properties['verbosity'] = 1; /* base_object.php */ + $this->properties['always_use_db'] = false; /* data_retrieval.php */ +$this->properties['cache_timeout'] = 3600; $this->properties['icao'] = 'EKYT'; $this->properties['use_proxy'] = false; $this->properties['proxy_host'] = ''; @@ -43,7 +47,6 @@ $this->properties['icons_path'] = 'icons/'; /* pw_images.php */ -// hack around PHP bug - the offset to add to a time reported -$this->properties['offset'] = 0; +$this->properties['offset'] = 0; /* phpweather.php */ ?> |
From: Martin G. <gim...@us...> - 2002-04-12 21:39:55
|
Update of /cvsroot/phpweather/phpweather In directory usw-pr-cvs1:/tmp/cvs-serv8385 Modified Files: stations.csv Log Message: New station discovered by Chris Hankinson <ch...@le...> Index: stations.csv =================================================================== RCS file: /cvsroot/phpweather/phpweather/stations.csv,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- stations.csv 9 Jul 2001 19:30:04 -0000 1.5 +++ stations.csv 12 Apr 2002 21:39:51 -0000 1.6 @@ -2913,6 +2913,7 @@ KSRR;Ruidoso Regional KRSL;Russell, Russell Municipal Airport KRUE;Russellville, Russellville Municipal Airport +KFQD;Rutherfordton, Rutherford County-Marchman Field Airport KRUT;Rutland State Automatic Weather Observing / Reporting System KRPE;Sabine Pass KSAC;Sacramento, Sacramento Executive Airport |
From: Martin G. <gim...@us...> - 2002-04-12 21:38:49
|
Update of /cvsroot/phpweather/phpweather In directory usw-pr-cvs1:/tmp/cvs-serv8094 Modified Files: VERSION Log Message: This is probably less confusing... Index: VERSION =================================================================== RCS file: /cvsroot/phpweather/phpweather/VERSION,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- VERSION 5 Jul 2001 15:53:10 -0000 1.6 +++ VERSION 12 Apr 2002 21:38:46 -0000 1.7 @@ -1 +1 @@ -1.96-CVS +2.x-CVS |
From: Martin G. <gim...@us...> - 2002-04-09 23:21:42
|
Update of /cvsroot/phpweather/phpweather/config In directory usw-pr-cvs1:/tmp/cvs-serv16422 Modified Files: index.php pw_option_text.php pw_validator.php pw_validator_ereg.php pw_validator_range.php Log Message: Hey - it turned out to be quite easy to validate the input using regular expression in Javascript... As far as I understand it, then these regular expressions only work in Javascript version 1.2 and later. But it's actually not that important, as this is simply extra functionality - you can still use a browser like lynx that doesn't do Javascript. Index: index.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/index.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- index.php 7 Apr 2002 18:53:15 -0000 1.2 +++ index.php 9 Apr 2002 23:21:37 -0000 1.3 @@ -332,6 +332,34 @@ </head> <body> +<script language="JavaScript1.2"> +function update(accepted, error, value, output) { + if (accepted) { + document.getElementById(output).innerHTML = "<font color=\"green\">Input accepted.</font>"; + } else { + while ((index = error.indexOf("%s")) > -1) { + error = error.substring(0, index) + value + error.substring(index+2); + } + document.getElementById(output).innerHTML = "<font color=\"red\">" + error + "</font>"; + } +} + +function validate(error, value, output, field) { + update(field.value == value, error, field.value, output); +} + +function validate_ereg(error, ereg, output, field) { + regex = new RegExp(ereg); + update(regex.test(field.value), error, field.value, output); +} + +function validate_range(error, low, high, empty_ok, output, field) { + update((empty_ok == 1 && field.value == "") || + (field.value >= low && field.value <= high), + error, field.value, output); +} +</script> + <img src="../icons/phpweather-long-white.gif" alt="PHP Weather" align="right"> <h1>Configuration Builder for PHP Weather</h1> @@ -341,18 +369,17 @@ 'Update Options' buttons. Depending on your choices, more 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"> <p>You can <input type="submit" name="download" value="Download the Configuration"> or <input type="reset" value="Reset Everything" onclick="document.location='reset_session.php'"></p> <dl> <?php - + $general_group->show(); $db_group->show(); $rendering_group->show(); - + ?> </dl> @@ -374,4 +401,4 @@ </form> </body> -</html> \ No newline at end of file +</html> Index: pw_option_text.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_option_text.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- pw_option_text.php 7 Apr 2002 18:38:20 -0000 1.1 +++ pw_option_text.php 9 Apr 2002 23:21:37 -0000 1.2 @@ -10,12 +10,15 @@ if ($this->is_ready()) { echo "<dt>Option <code>$this->name</code>: "; echo '<input type="text" name="' . $this->name . - '_value" value="' . htmlentities($this->value) . "\"></dt>\n"; + '_value" value="' . htmlentities($this->value) . + '" onkeyup="' . $this->validator->get_javascript($this->name) . + "\"></dt>\n"; echo '<dd><p>' . $this->description . "</p>\n"; if ($this->is_valid()) { - echo '<p style="color: green">Input accepted.</p>'; + echo '<p id="' . $this->name . '"><font color="green">Input accepted.</font></p>'; } else { - echo '<p style="color: red">' . $this->validator->get_error() . '</p>'; + echo '<p id="' . $this->name . '"><font color="red">' . + $this->validator->get_error() . '</font></p>'; } echo "\n</dd>\n"; } Index: pw_validator.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_validator.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- pw_validator.php 7 Apr 2002 18:38:20 -0000 1.1 +++ pw_validator.php 9 Apr 2002 23:21:37 -0000 1.2 @@ -18,6 +18,10 @@ return sprintf($this->error, $this->value); } + function get_javascript($id) { + return ''; + } + } Index: pw_validator_ereg.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_validator_ereg.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- pw_validator_ereg.php 7 Apr 2002 18:38:20 -0000 1.1 +++ pw_validator_ereg.php 9 Apr 2002 23:21:37 -0000 1.2 @@ -14,6 +14,11 @@ return ereg($this->regex, $value); } + function get_javascript($id) { + return "validate_ereg('" . addslashes($this->error) . + "', '$this->regex', '$id', this)"; + } + } ?> Index: pw_validator_range.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_validator_range.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- pw_validator_range.php 7 Apr 2002 18:38:20 -0000 1.1 +++ pw_validator_range.php 9 Apr 2002 23:21:37 -0000 1.2 @@ -4,21 +4,26 @@ var $low; var $high; - var $optional; + var $empty_ok; - function pw_validator_range($error, $low, $high, $optional = false) { + function pw_validator_range($error, $low, $high, $empty_ok = false) { $this->pw_validator($error); $this->low = $low; $this->high = $high; - $this->optional = $optional; + $this->empty_ok = $empty_ok; } function validate($value) { $this->value = $value; - if ($this->optional && empty($value)) return true; + if ($this->empty_ok && empty($value)) return true; return (ereg('^[0-9]+$', $value) && $this->low <= $value && $value <= $this->high); + } + + function get_javascript($id) { + return "validate_range('" . addslashes($this->error) . + "', $this->low, $this->high, $this->empty_ok, '$id', this)"; } |
From: Martin G. <gim...@us...> - 2002-04-07 19:08:07
|
Update of /cvsroot/phpweather/phpweather/config In directory usw-pr-cvs1:/tmp/cvs-serv14433 Modified Files: reset_session.php Log Message: Hmm, $_SERVER didn't work either. Index: reset_session.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/reset_session.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- reset_session.php 7 Apr 2002 18:38:20 -0000 1.1 +++ reset_session.php 7 Apr 2002 18:59:53 -0000 1.2 @@ -6,7 +6,7 @@ session_start(); session_unset(); session_destroy(); -header('Location: http://' . $_SERVER['HTTP_HOST'] . +header('Location: http://' . $HTTP_HOST . dirname($PHP_SELF) . '/index.php'); exit(); ?> |
From: Martin G. <gim...@us...> - 2002-04-07 18:53:19
|
Update of /cvsroot/phpweather/phpweather/config In directory usw-pr-cvs1:/tmp/cvs-serv12762 Modified Files: index.php Log Message: Ups - $_REQUEST was too new for SourceForge. I've also changed some include() to require_once() since that is what I mean: the script shouldn't run without these files. Index: index.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/index.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- index.php 7 Apr 2002 18:38:20 -0000 1.1 +++ index.php 7 Apr 2002 18:53:15 -0000 1.2 @@ -2,24 +2,24 @@ error_reporting(E_ALL); -/* Include a couple of validators: */ -include('pw_validator.php'); -include('pw_validator_ereg.php'); -include('pw_validator_range.php'); - -/* Include some options: */ -include('pw_option.php'); -include('pw_option_text.php'); -include('pw_option_select.php'); -include('pw_option_multi_select.php'); -include('pw_option_boolean.php'); +/* Require a couple of validators: */ +require_once('pw_validator.php'); +require_once('pw_validator_ereg.php'); +require_once('pw_validator_range.php'); + +/* Require_once some options: */ +require_once('pw_option.php'); +require_once('pw_option_text.php'); +require_once('pw_option_select.php'); +require_once('pw_option_multi_select.php'); +require_once('pw_option_boolean.php'); /* We want to group the options: */ -include('pw_optiongroup.php'); +require_once('pw_optiongroup.php'); /* A couple of dependencies: */ -include('pw_dependency.php'); -include('pw_dependency_or.php'); +require_once('pw_dependency.php'); +require_once('pw_dependency_or.php'); /* We have to strip slashes from the GPC variables. */ if (get_magic_quotes_gpc() == 1) { @@ -35,7 +35,7 @@ } } - recursive_stripslashes($_REQUEST); + recursive_stripslashes($HTTP_POST_VARS); } /* Start the session. */ @@ -261,7 +261,7 @@ options in $options and not on a copy. */ $keys = array_keys($options); foreach ($keys as $option) { - $options[$option]->update_value($_REQUEST); + $options[$option]->update_value($HTTP_POST_VARS); } /* Grouping */ @@ -299,7 +299,7 @@ $rendering_group->get_config() . "\n?>\n"; -if (!empty($_REQUEST['download'])) { +if (!empty($HTTP_POST_VARS['download'])) { header('Content-type: application/octet-stream'); header('Content-Disposition: attachment; filename="defaults.php"'); echo $config; |
From: Martin G. <gim...@us...> - 2002-04-07 18:38:23
|
Update of /cvsroot/phpweather/phpweather/config In directory usw-pr-cvs1:/tmp/cvs-serv8657 Added Files: index.php pw_dependency.php pw_dependency_or.php pw_option.php pw_option_boolean.php pw_option_multi_select.php pw_option_select.php pw_option_text.php pw_optiongroup.php pw_validator.php pw_validator_ereg.php pw_validator_range.php reset_session.php Log Message: This is a new and improved configurator - a script that can be used to generate a defaults.php file for PHP Weather. The new thing is, that the options now depend on each other - you cannot configure the database password if you're using a DBA database, because that kind of database doesn't use a password. The options are also validated so that the default ICAO really is a string of four letters or digits. I've dropped the idea about having the script save the configuration. It only worked when the webserver had write-permission to the directory (which was rare) and it caused some security-problems. There's also no code for generating the databases. I think it would be better if we made a separate script for that. Perhaps we should couple this with the code that updates the METARs from cycle-files. The classes still lack documentation... --- NEW FILE --- <?php error_reporting(E_ALL); /* Include a couple of validators: */ include('pw_validator.php'); include('pw_validator_ereg.php'); include('pw_validator_range.php'); /* Include some options: */ include('pw_option.php'); include('pw_option_text.php'); include('pw_option_select.php'); include('pw_option_multi_select.php'); include('pw_option_boolean.php'); /* We want to group the options: */ include('pw_optiongroup.php'); /* A couple of dependencies: */ include('pw_dependency.php'); include('pw_dependency_or.php'); /* We have to strip slashes from the GPC variables. */ if (get_magic_quotes_gpc() == 1) { function recursive_stripslashes(&$array) { $keys = array_keys($array); foreach($keys as $key) { if (is_array($array[$key])) { recursive_stripslashes($array[$key]); } else { $array[$key] = stripslashes($array[$key]); } } } recursive_stripslashes($_REQUEST); } /* Start the session. */ session_start(); /* If $options isn't registered, then we should make the variable and * register it: */ if (!session_is_registered('options')) { /* 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')); $dba_dep = new pw_dependency('db_type', 'dba'); $proxy_dep = new pw_dependency('use_proxy', 'true'); $port_validator = new pw_validator_range("Sorry, '%s' is not a valid port-number because " . "is't outside the range 1-65536", 1, 65536, true); /* This just catches the most obvious errors. */ $table_validator = new pw_validator_ereg("Sorry, '%s' is not a valid name.", '^[^./]+$'); $icao_validator = new pw_validator_ereg("Sorry, '%s' is not a valid ICAO.", '^[a-zA-Z0-9]{4}$'); /* This just catches the most obvious errors. */ $host_validator = new pw_validator_ereg("Sorry, '%s' is not a valid hostname.", '^[^/#?~]+$'); /* Next comes all the options: */ $options['verbosity'] = new pw_option_select('verbosity', "The setting of this variable controls the amount of " . "errors, warnings, and debug-information PHP Weather " . "will print. It is suggested that you always include " . "errors in the output and perhaps also warnings.", array(), array('1' => 'Errors only', '2' => 'Warnings only', '4' => 'Debug information only', '3' => 'Errors + warnings', '5' => 'Errors + debug information', '6' => 'Warnings + debug information', '7' => 'Everything') ); $options['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'] = new pw_option_select('pref_units', 'You may choose to display the data in several ' . 'formats. Please choose one that fits your need.', array(), array('both_metric' => 'Metric first, then imperial', 'both_imperial' => 'Imperial first, then metric', 'only_metric' => 'Only metric', 'only_imperial' => 'Only imperial')); $options['language'] = new pw_option_select('language', 'PHP Weather can produce output in several languages ' . '- please select your default from the list.', array(), array('en' => 'English', 'da' => 'Danish', 'hu' => 'Hungarian', 'no' => 'Norwegian')); $options['use_proxy'] = new pw_option_boolean('use_proxy', "Set this option to 'Yes' to enable support for a " . "proxy server.", array(), array('false' => 'No', 'true' => 'Yes')); $options['proxy_host'] = new pw_option_text('proxy_host', "This is the hostname of the proxy server.", array($proxy_dep), $host_validator); $options['proxy_port'] = new pw_option_text('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'] = new pw_option_select('db_type', 'PHP Weather can use several kinds of databases.', array(), array('null' => 'No database at all', 'mysql' => 'A MySQL database', 'pgsql' => 'A PostgreSQL database', 'dba' => 'A DBA database')); $options['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 " . "please select the handler you would like to use.", array($dba_dep), array('dbm' => 'dbm - The oldest (original) type of ' . 'Berkeley DB style databases', 'ndbm' => 'ndbm - a newer and more flexible type.', 'gdbm' => 'gdbm - The GNU database manager', 'db2' => 'db2 - Sleepycat Softwares DB2', 'db3' => 'db3 - Sleepycat Softwares DB3')); $options['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, " . "even if it's too old. But if the data isn't there, " . "it will still fetch new data from the Internet.", array($db_dep), array('false' => 'No', 'true' => 'Yes')); $options['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'] = new pw_option_text('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); $options['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'] = 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'] = 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'] = 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 ' . "remember to protect the file after you've stored the " . "password in it.", array($sql_dep)); $options['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'] = 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'] = 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 ' . 'country-codes.', array($dba_dep), $table_validator, 'pw_countries'); $options['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 " . 'this to happen, then just use an empty string. ' . "Other good choices include <code><i></code>, <code><font " . 'color="red"></code>, etc.', array(), false, '<b>'); $options['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'] = new pw_option_multi_select('exclude', 'You can disable some of the output produced. If ' . "you're not interested in information about " . 'runways-visibility, then select it in this list. ' . 'You can select several options at once in Netscape ' . 'by holding down Ctrl while clicking on the option.', array(), array('time' => 'Leave out the time part', 'wind' => 'Leave out the wind part', 'runway' => 'Leave out information about runways')); /* Finally - we register all the options with the session. */ session_register('options'); } /* The options should now be ready - they might come from a restored * session, or they might just have been created. */ /* 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); foreach ($keys as $option) { $options[$option]->update_value($_REQUEST); } /* Grouping */ $general_group = new pw_optiongroup('General Options', 'This is some general options for PHP Weather.', array('verbosity', 'icao', 'pref_units', 'language', 'use_proxy', 'proxy_host', 'proxy_port')); $db_group = new pw_optiongroup('Database Options', 'These options deal with the database. PHP Weather ' . 'can use a database for caching the METARs it ' . 'retrieves. This is very nice, since it takes at ' . 'least a second or two to fetch a METAR from the ' . 'National Weather Service.', array('db_type', 'db_handler', 'db_pconnect', 'always_use_db', 'db_hostname', 'db_port', 'db_database', 'db_username', 'db_password', 'db_metars', 'db_stations', 'db_countries')); $rendering_group = new pw_optiongroup('Rendering Options', 'You can customize the looks of PHP Weather using these options.', array('mark_begin', 'mark_end', 'exclude')); /* We can now generate a configuration file with the options selected so far: */ $timestamp = date ('dS of F, Y H:i:s'); $config = "<?php /* This is a local configuration file for PHP Weather. It was generated on the $timestamp. */\n" . $general_group->get_config() . $db_group->get_config() . $rendering_group->get_config() . "\n?>\n"; if (!empty($_REQUEST['download'])) { header('Content-type: application/octet-stream'); header('Content-Disposition: attachment; filename="defaults.php"'); echo $config; exit(); } ?> <html> <head> <title>Configuration Builder for PHP Weather</title> <style type="text/css"> <!-- BODY { font-family: Verdana, Tahoma, Geneva, Arial, Helvetica, sans-serif; font-size: small; } DT { font-weight: bold } P { margin-top: 0.5em; margin-bottom: 0.5em; } --> </style> </head> <body> <img src="../icons/phpweather-long-white.gif" alt="PHP Weather" align="right"> <h1>Configuration Builder for PHP Weather</h1> <p>This is the Configuretor shipped with PHP Weather.</p> <p>Change the options below - when you're done, then press one of the 'Update Options' buttons. Depending on your choices, more 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"> <p>You can <input type="submit" name="download" value="Download the Configuration"> or <input type="reset" value="Reset Everything" onclick="document.location='reset_session.php'"></p> <dl> <?php $general_group->show(); $db_group->show(); $rendering_group->show(); ?> </dl> <p><input type="submit" value="Update options"></p> <p>This is a configuration file bases on your answers above:</p> <?php highlight_string($config); ?> <p>You should copy the above configuration to a file called <code>defaults.php</code> in the root directory of your PHP Weather installation. It's very important that the lines with <code><font color="#0000CC"><?php</font></code> and <code><font color="#0000CC">?></font></code> are the very first and very last, respectively. There should be no blank lines outside these two tags.</p> <p>You can also <input type="submit" name="download" value="Download the Configuration"> or <input type="reset" value="Reset Everything" onclick="document.location='reset_session.php'"></p> </form> </body> </html> --- NEW FILE --- <?php class pw_dependency { var $option; var $dep; function pw_dependency($option, $d) { $this->option = $option; $this->dep = $d; } function check() { return ($GLOBALS['options'][$this->option]->get_value() == $this->dep); } } ?> --- NEW FILE --- <?php class pw_dependency_or extends pw_dependency { function pw_dependency_or($option, $d) { $this->pw_dependency($option, $d); } function check() { $value = $GLOBALS['options'][$this->option]->get_value(); foreach ($this->dep as $d) { if ($value == $d) return true; } return false; } } ?> --- NEW FILE --- <?php class pw_option { var $name = ''; var $description = ''; var $dependencies = array(); var $value = ''; var $default = ''; var $validator; function pw_option($name, $description, $dependencies, $validator = false, $default = false) { $this->name = $name; $this->description = $description; $this->dependencies = $dependencies; if ($validator) { $this->validator = $validator; } else { $this->validator = new pw_validator('Please correct your input'); } if ($default) { $this->default = $default; $this->update_value(array($name . '_value' => $default)); } } function get_name() { return $this->name; } function get_description() { return $this->description; } function get_value() { return $this->value; } function is_ready() { $ready = true; foreach($this->dependencies as $dependency) { if (!$dependency->check()) { $ready = false; break; } } return $ready; } function is_valid() { return $this->validator->validate($this->value); } function update_value($values) { if (isset($values[$this->name . '_value'])) { $this->value = $values[$this->name . '_value']; } } function get_config() { if ($this->is_ready() && $this->is_valid() && $this->value != $this->default) { return "/* $this->name */\n\$this->properties['$this->name'] = " . "'$this->value';\n\n"; } else { return ''; } } } ?> --- NEW FILE --- <?php class pw_option_boolean extends pw_option_select { function get_config() { if ($this->is_ready() && $this->value != $this->default) { return "/* $this->name */\n\$this->properties['$this->name'] = " . "$this->value;\n\n"; } else { return ''; } } } ?> --- NEW FILE --- <?php class pw_option_multi_select extends pw_option { var $choices = array(); function pw_option_multi_select($name, $description, $dependencies, $choices) { $this->pw_option($name, $description, $dependencies); $this->choices = $choices; } function is_valid() { foreach ($this->value as $value) { if (!in_array($value, array_keys($this->choices))) { return false; } } return true; } function update_value($values) { if (isset($values[$this->name . '_value'])) { $this->value = $values[$this->name . '_value']; } else { $this->value = array(); } } function show() { if ($this->is_ready()) { echo "<dt>Option <code>$this->name</code>: " . '<select name="' . $this->name . '_value[]" multiple="multiple">'; foreach ($this->choices as $choice => $label) { if (in_array($choice, $this->value)) { echo '<option selected="selected" value="' . htmlentities($choice) . "\">$label</option>\n"; } else { echo '<option value="' . htmlentities($choice) . "\">$label</option>\n"; } } echo "</select>\n</dt>\n"; echo '<dd><p>' . $this->description . "</p>\n"; if ($this->is_valid()) { echo '<p style="color: green">Input accepted.</p>'; } else { echo '<p style="color: red">Please correct your input.</p>'; } echo "</dd>\n"; } } function get_config() { if ($this->is_ready() && $this->is_valid() && !empty($this->value)) { return "/* $this->name */\n\$this->properties['$this->name'] = array(\n" . " '" . implode("',\n '", $this->value) . "'\n);\n"; } else { return ''; } } } /* class multi_select */ ?> --- NEW FILE --- <?php class pw_option_select extends pw_option { var $choices = array(); function pw_option_select($name, $description, $dependencies, $choices) { $this->pw_option($name, $description, $dependencies, false, key($choices)); $this->choices = $choices; } function is_valid() { return in_array($this->value, array_keys($this->choices)); } function show() { if ($this->is_ready()) { echo "<dt>Option <code>$this->name</code>: "; echo '<select name="' . $this->name . '_value">'; foreach ($this->choices as $choice => $label) { if ($choice == $this->value) { echo '<option selected="selected" value="' . htmlentities($choice) . "\">$label</option>\n"; } else { echo '<option value="' . htmlentities($choice) . "\">$label</option>\n"; } } echo "</select>\n</dt>\n"; echo '<dd><p>' . $this->description . "</p>\n"; if ($this->is_valid()) { echo '<p style="color: green">Input accepted.</p>'; } else { echo '<p style="color: red">Please correct your input: "' . $this->value . '" is not amount your choices.</p>'; } echo "\n</dd>\n"; } } } ?> --- NEW FILE --- <?php class pw_option_text extends pw_option { function pw_option_text($name, $description, $dependencies, $validator = false, $default = false) { $this->pw_option($name, $description, $dependencies, $validator, $default); } function show() { if ($this->is_ready()) { echo "<dt>Option <code>$this->name</code>: "; echo '<input type="text" name="' . $this->name . '_value" value="' . htmlentities($this->value) . "\"></dt>\n"; echo '<dd><p>' . $this->description . "</p>\n"; if ($this->is_valid()) { echo '<p style="color: green">Input accepted.</p>'; } else { echo '<p style="color: red">' . $this->validator->get_error() . '</p>'; } echo "\n</dd>\n"; } } } ?> --- NEW FILE --- <?php class pw_optiongroup { var $title; var $description; var $options; function pw_optiongroup($title, $description, $options) { $this->title = $title; $this->description = $description; $this->options = $options; } function show() { echo "<dt>$this->title <input type=\"submit\" value=\"Update options\"></dt>\n"; echo "<dd><p>$this->description</p>\n"; echo "<dl>\n"; foreach($this->options as $option) { $GLOBALS['options'][$option]->show(); } echo "</dl>\n"; echo "</dd>\n"; } function get_config() { $config = ''; foreach($this->options as $option) { $config .= $GLOBALS['options'][$option]->get_config(); } $stars = "\n/*" . str_repeat('*', 64) . "*/\n"; $top = $stars . '/*' . str_pad($this->title, 64, ' ', STR_PAD_BOTH) . "*/" . $stars; if ($config == '') { return $top . '/* ' . str_pad('All options are at their default values.', 63) . "*/\n"; } else { return $top . '/* ' . str_pad('The following options have been changed:', 63) . "*/\n" . "\n$config\n"; } } } ?> --- NEW FILE --- <?php class pw_validator { var $error; var $value; function pw_validator($error) { $this->error = $error; } function validate($value) { $this->value = $value; return true; } function get_error() { return sprintf($this->error, $this->value); } } ?> --- NEW FILE --- <? class pw_validator_ereg extends pw_validator { var $regex; function pw_validator_ereg($error, $regex) { $this->pw_validator($error); $this->regex = $regex; } function validate($value) { $this->value = $value; return ereg($this->regex, $value); } } ?> --- NEW FILE --- <? class pw_validator_range extends pw_validator { var $low; var $high; var $optional; function pw_validator_range($error, $low, $high, $optional = false) { $this->pw_validator($error); $this->low = $low; $this->high = $high; $this->optional = $optional; } function validate($value) { $this->value = $value; if ($this->optional && empty($value)) return true; return (ereg('^[0-9]+$', $value) && $this->low <= $value && $value <= $this->high); } } ?> --- NEW FILE --- <?php /* This script destroys a session. We start by initializing the * session, then we unset any vaiables associated with it, and then * destroy it. After that is done, we redirect to the index.php in the * current directory. */ session_start(); session_unset(); session_destroy(); header('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($PHP_SELF) . '/index.php'); exit(); ?> |