CVS: web/docs/1.x dbcaching.php,NONE,1.1 demo.php,NONE,1.1 index.php,...
Brought to you by:
iridium
From: Martin G. <gim...@us...> - 2002-03-18 17:36:43
|
Update of /cvsroot/phpweather/web/docs/1.x In directory usw-pr-cvs1:/tmp/cvs-serv21354 Added Files: dbcaching.php demo.php index.php translation.php using.php usingwap.php Log Message: This is basically the old files from gimpster.com. --- NEW FILE --- <?php /* $Id: dbcaching.php,v 1.1 2002/03/18 17:36:39 gimpster Exp $ */ require('../../include/header.php'); ?> <p>But you'll soon start to look for a way to improve the response-time of your script. To do this, you first have to decide what database you want to use. You have a number of options at this time:</p> <dl> <dt>A MySQL database</dt> <dd> <p>Set <code>$useMySQL</code> to 1, and then create a table with the following SQL statement:</p> <pre> CREATE TABLE metars ( metar VARCHAR(255) NOT NULL, timestamp TIMESTAMP(14), station VARCHAR(4) NOT NULL, PRIMARY KEY (station), UNIQUE station (station) ); </pre> </dd> <dt>A PostgreSQL database</dt> <dd> <p>Set <code>$usePSQL</code> to 1 and create a table with the following SQL statement:</p> <pre> CREATE TABLE metars ( metar VARCHAR(255) NOT NULL, timestamp TIMESTAMP, station VARCHAR(4) PRIMARY KEY NOT NULL ); </pre> </dd> <dt>An Oracle 8 database</dt> <dd> <p>Set <code>$useOCI</code> to 1 and create a table with this SQL statement:</p> <pre> create table metars ( metar varchar2(255) not null, timestamp date, station varchar2(4) ); alter table metars add primary key (station); </pre> </dd> <dt>A DBM database</dt> <dd> <p>Set <code>$useDBM</code> to 1 and make make sure that the user running the webserver has write-permission to the current directory.</p> </dd> <dt>An XML file</dt> <dd> <p>Set <code>$useXML</code> to 1 and make sure that the webserver has read/write permission to the file <code>cache.xml</code>.</p> </dd> </dl> <p>If you use a database that requires you to log on, then please remember to do so. There's already some code at the top of <code>phpweather.inc</code> that should serve as a guide.</p> <p>If you don't connect to your database, you'll recieve a lot of errors, saying things like: "<code>MySQL Connection Failed: Access denied for user: 'nobody@localhost' (Using password: NO) in phpweather.inc</code>" and "<code>Supplied argument is not a valid MySQL result resource in phpweather.inc</code>". These errors are trying to tell you, that PHP Weather couldn't store the METAR in the MySQL-database, because you didn't supply a valid username and password. The errors will be similar for other databases.</p> <p>If you've configured PHP Weather and the database correctly, PHP Weather will store the retrieved METARs in the database, and use the cached METAR if it's less that 1 hour old. If it's older, it is expected that the station has made a new observation, so we should update our data.</p> <?php require('../../include/header.php'); ?> --- NEW FILE --- <?php /* $Id: demo.php,v 1.1 2002/03/18 17:36:39 gimpster Exp $ */ require('../../include/header.php'); require('../../phpweather-1.x/phpweather.inc'); ?> <p>This is the extended demo. Here you'll be able to play with PHP Weathers ability to show the weather in several different languages.</p> <p>This piece of text is made just like the one on the <a href="index.php">frontpage</a>. The only difference is, that this one shows the current weather in Honolulu, Hawaii, and that the information is presented in Spanish. First comes the raw METAR:</p> <blockquote><code><? echo $metar = get_metar('PHNL', 1) ?></code></blockquote> <p>and then the Spanish pretty-printed output:</p> <?php require('../../phpweather-1.x/locale_es.inc'); pretty_print_metar($metar, 'Honolulu, Hawaii'); ?> <p>The only thing I changed between the two pieces of code was the identifier of the weather station, and the include-file with the strings used by PHP Weather. The identifier for Aalborg, Denmark is <code>EKYT</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 lists and you'll see the current weather for the city you selected:</p> <form action="demo.php" method="post"> <select name="city" onChange="this.form.submit()"> <? $cities = array( 'BGTL' => 'Thule A. B., Greenland', 'EGKK' => 'London / Gatwick Airport, United Kingdom', 'EKYT' => 'Aalborg, Denmark', 'EKCH' => 'Copenhagen / Kastrup, Denmark', 'ENGM' => 'Oslo / Gardermoen, Norway', 'ESSA' => 'Stockholm / Arlanda, Sweden', 'FCBB' => 'Brazzaville / Maya-Maya, Congo', 'LEMD' => 'Madrid / Barajas, Spain', 'LFPB' => 'Paris / Le Bourget, France', 'LIRA' => 'Roma / Ciampino, Italy', 'KNYC' => 'New York City, Central Park, NY, United States', 'NZCM' => 'Williams Field, Antarctic', 'UUEE' => 'Moscow / Sheremet\'Ye , Russian Federation', 'RKSS' => 'Seoul / Kimp\'O International Airport, Korea', 'YSSY' => 'Sydney Airport, Australia', 'ZBAA' => 'Beijing, China' ); while (list($icao, $location) = each($cities)) { if ($icao == $city) { echo "<option selected value=\"$icao\">$location</option>\n"; } else { echo "<option value=\"$icao\">$location</option>\n"; } } ?> </select> <select name="language"> <? $languages = array( 'po_br' => 'Brazilian Portuguese', 'cz' => 'Czech', 'da' => 'Danish', 'nl' => 'Dutch', 'en' => 'English', 'fr' => 'French', 'de' => 'German', 'it' => 'Italian', 'no' => 'Norwegian', 'es' => 'Spanish' ); while (list($lang_code, $locale) = each($languages)) { if ($lang_code == $language) { echo "<option selected value=\"$lang_code\">$locale</option>\n"; } else { echo "<option value=\"$lang_code\">$locale</option>\n"; } } ?> </select> <input type="submit"> </form> <? if (!isset($city)) { $city = 'BGTL'; $language = 'en'; } $metar = get_metar($city, 1); include("../../phpweather-1.x/locale_$language.inc"); pretty_print_metar($metar, $cities[$city]) ?> <p>The METAR for <? echo $cities[$city] ?>, presented in <? echo $languages[$language] ?>, was:</p> <blockquote><code><? echo $metar ?></code></blockquote> <?php require('../../include/footer.php'); ?> --- NEW FILE --- <?php require('../../include/header.php'); require('../../phpweather-1.x/locale_en.inc'); require('../../phpweather-1.x/phpweather.inc'); $metar = get_metar('EKYT', 0); ?> <img src="../../images/phpweather.jpg" width="103" height="128" alt="PHP Weather" align="right"> <p>This is the documentation for PHP Weather version 1.x. If you're using PHP version 4 or greather, then you should use the newer version 2 of PHP Weather instead. PHP Weather 1.x is still here for people who still use PHP version 3, as PHP Weather 1.x is known to on version of PHP all the way back to 3.0.3.</p> <p>PHP Weather is a script written in PHP, that will decode a METAR weather report. Every hour a round the clock airports make a METAR-report where they measure things like the temperature, the wind speed and direction etc. This information is available on the Internet. PHP Weather retrieves this information and can cache the METARs in a database so subsequent request for the same station will be served as fast as possible.</p> <p>But the report is not just saved in plain-text. Its coded in a special code, so it has to be decoded before you can use it. This is what PHP Weather is for, decoding a METAR into plain-text, so you can use for something useful.</p> <h2>A sample METAR-report</h2> <p>The report below is the latest from Aalborg, Denmark (this is where I live). The raw METAR looks like this:</p> <blockquote><code><? echo $metar ?></code></blockquote> <p>Not exactly a pretty sight? Well by using PHP Weather you could also present the information like this:</p> <?php pretty_print_metar($metar, 'Aalborg, Denmark') ?> <?php require('../../include/footer.php'); ?> --- NEW FILE --- <?php /* $Id: translation.php,v 1.1 2002/03/18 17:36:40 gimpster Exp $ */ require('../../include/header.php'); ?> <p>As you have no doubt noticed, PHP Weather has been translated into several different languages. I'm very grateful to all who have contribuated by doing this - see the AUTHORS-file for details.</p> <p>To use a translation, you only have to include the associated <code>locale_??.inc</code>-file. Here <code>??</code> should be substituted with the language-code of the country in question. So, to have the weather written in first in English and then in Norwegian, just execute the following code:</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">pretty_print_metar</font><font color="#007700">(</font><font color="#0000BB">get_metar</font><font color="#007700">(</font><font color="#DD0000">'EKYT'</font><font color="#007700">), </font><font color="#DD0000">'Aalborg, Denmark'</font><font color="#007700">);<br>include(</font><font color="#DD0000">'locale_no.inc'</font><font color="#007700">);<br></font><font color="#0000BB">pretty_print_metar</font><font color="#007700">(</font><font color="#0000BB">get_metar</font><font color="#007700">(</font><font color="#DD0000">'EKYT'</font><font color="#007700">), </font><font color="#DD0000">'Aalborg, Denmark'</font><font color="#007700">);<br></font><font color="#0000BB">?><br></font> </font> </code> <p>If you want to do a translation, then follow these steps:</p> <ol> <li><p>You'll need something to translate :-) You can use any of the already-made translations as a template, so pick one. The English translation is the original.</p></li> <li><p>Make a copy of your chosen template, and rename it <code>locale_??.inc</code>, where <code>??</code> is the normal abbreviation for your country, eg. <code>dk</code> for Denmark, <code>en</code> for England etc.</p></li> <li><p>Change the name of the author and email-address to you name and email-address.</p></li> <li><p>Here comes the difficult part: translate every string in the file, but leave the <code>%s</code> intact. It is these codes that will be replaced by the actual numbers and strings when the script is executed.</p> <p>Here's an example: "<code><b>%s</b> mm (<b>%s</b> inches)</code>" becomes "<code><b>12.7</b> mm (<b>0.5</b> inches)</code>". This string is then used in the next piece: "<code>There was %s of precipitation</code>", which then becomes "<code>There was <b>12.7</b> mm (<b>0.5</b> inches) of precipitation</code>". I hope you get the idea.</p></li> <li><p>Remember to translate all special characters (things like å, ü, ó etc) to their html-entities.</p></li> <li><p>When you're done, and have tested your translation, send it to the <a href="mailto:php...@li...">phpweather-devel</a> mailinglist at <a href="http://www.sourceforge.net/">SourceForge</a>. Someone will then put it into CVS and it will be included in the next release.</p></li> </ol> <p>Good luck on translating PHP Weather! Here's your chance to help me out - you don't have to know anything about the code to contribute, and it's a great way to tell me, that you like the script.</p> <?php require('../../include/footer.php'); ?> --- NEW FILE --- <?php /* $Id: using.php,v 1.1 2002/03/18 17:36:40 gimpster Exp $ */ require('../../include/header.php'); require('../../phpweather-1.x/phpweather.inc'); require('../../phpweather-1.x/locale_en.inc'); ?> <p>Using PHP Weather is very simple. First you have to include the file <code>phpweather.inc</code> in your page. Then you call the function <code>get_metar()</code> with the four-character station-identifier. This gives you the METAR, which you can then feed to <code>process_metar()</code>. This function return an array that contains the various parts of the METAR in decoded form. They are also returned in both imperial (feet, miles, degrees of Fahrenheit, etc.) and metric SI units (meters, kilometers and degrees Celsius).</p> <p>This code is all that is <i>necessary</i> to make PHP Weather work:</p> <code><font color="#000000"> <font color="#0000BB"><?php<br></font><font color="#007700">include(</font><font color="#DD0000">'phpweather.inc'</font><font color="#007700">);<br>include(</font><font color="#DD0000">'locale_en.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_c </font><font color="#007700">= </font><font color="#0000BB">$data</font><font color="#007700">[</font><font color="#DD0000">'temp_c'</font><font color="#007700">];<br></font><font color="#0000BB">$temp_f </font><font color="#007700">= </font><font color="#0000BB">$data</font><font color="#007700">[</font><font color="#DD0000">'temp_f'</font><font color="#007700">];<br>echo </font><font color="#DD0000">"<p>The temperature is $temp_c degrees Celsius ($temp_f degrees Fahrenheit).</p>"</font><font color="#007700">;<br></font><font color="#0000BB">?><br></font> </font> </code> <p>That's it! The above code will tell you what the temperature is in Aalborg, Denmark:</p> <?php $metar = get_metar('EKYT'); $data = process_metar($metar); $temp_c = $data['temp_c']; $temp_f = $data['temp_f']; echo "<p>The temperature is $temp_c degrees Celsius ($temp_f degrees Fahrenheit).</p>"; ?> <p>But you'll probably want the nice large examples you saw on the previous pages? 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>include(</font><font color="#DD0000">'locale_en.inc'</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">?></font> </font> </code> <p>This will give you an English text with the current weather in Aalborg, Denmark:</p> <?php $metar = get_metar('EKYT'); pretty_print_metar($metar, 'Aalborg, Denmark'); ?> <?php require('../../include/footer.php'); ?> --- NEW FILE --- <?php /* $Id: usingwap.php,v 1.1 2002/03/18 17:36:40 gimpster Exp $ */ require('../../include/header.php'); require('../../phpweather-1.x/phpweather.inc'); require('../../phpweather-1.x/locale_en.inc'); ?> <p>PHP Weather can also be used to serve current weather information to WAP-enables mobile phones. To do this, just put the file <code>wap.php</code> in the same directory as <code>phpweather.inc</code> and then point your WAP-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 <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> <p>The code is almost the same as when you make a normal page, you just use the <code>pretty_print_metar_wap()</code>-function instead:</p> <code><font color="#000000"> <font color="#0000BB"><?<br></font><font color="#007700">include(</font><font color="#DD0000">'phpweather.inc'</font><font color="#007700">);<br></font><font color="#0000BB">pretty_print_metar_wap</font><font color="#007700">(</font><font color="#0000BB">get_metar</font><font color="#007700">(</font><font color="#DD0000">'EKYT'</font><font color="#007700">), </font><font color="#DD0000">'Aalborg'</font><font color="#007700">);<br></font><font color="#0000BB">?><br></font> </font> </code> <?php require('../../include/footer.php'); ?> |