Update of /cvsroot/phpweather/phpweather
In directory usw-pr-cvs1:/tmp/cvs-serv10292
Modified Files:
data_retrieval.php
Log Message:
Rearranging comments, removing typos...
Index: data_retrieval.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/data_retrieval.php,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -3 -r1.12 -r1.13
--- data_retrieval.php 2001/07/05 16:05:11 1.12
+++ data_retrieval.php 2001/07/08 19:21:42 1.13
@@ -21,7 +21,7 @@
/**
* The METAR is stored here.
*
- * The property is used when-ever someone want access to the raw
+ * The property is used whenever someone wants access to the raw
* METAR. Although you shouldn't do it, it is possible to set this
* directly. But that is only something the developers should do for
* testing... :-)
@@ -37,20 +37,19 @@
*/
var $location;
-
/**
* Constructor
*
* This sets the station.
*
- * @param array The initial properties of the object.
* @access private
+ * @param array The initial properties of the object.
*/
function data_retrieval($input) {
- /* We start by calling the parent constructor. */
+ /* We start by calling the parent constructor. */
$this->db_layer($input);
- /* Then we set the station. */
+ /* Then we set the station. */
$this->set_icao($this->properties['icao']);
}
@@ -58,8 +57,8 @@
/**
* Returns the current ICAO.
*
- * @return string The station-ICAO
* @access public
+ * @return string The station-ICAO
*/
function get_icao() {
return $this->properties['icao'];
@@ -68,14 +67,19 @@
/**
* Sets the station or rather the ICAO.
*
- * It also clear the METAR and decoded METAR if the station is different from the
old one. If the new station is the same as the old one, nothing is changed.
+ * It also clears the METAR and decodes METAR if the station is
+ * different from the old one. If the new station is the same as
+ * the old one, nothing is changed.
*
- * @param string The ICAO of the new station.
* @access public
+ * @param string The ICAO of the new station.
*/
function set_icao($new_icao) {
- /* We start by adding slashes, since $new_icao might come directly
- from the user. */
+
+ /* We start by adding slashes, since $new_icao might come directly
+ * from the user.
+ */
+
$new_icao = addslashes($new_icao);
if ($new_icao != $this->get_icao()) {
$this->properties['icao'] = strtoupper($new_icao);
@@ -89,11 +93,13 @@
/**
* Retrieves a raw METAR, either from the web or from a database.
*
- * If the METAR is already set, then it just return that. If it's not set, then it
tries to get it from the database.
+ * If the METAR is already set, then it just return that.
+ * If it's not set, then it tries to get it from the database.
*
- * @return string The raw METAR.
* @access public
+ * @return string The raw METAR.
*/
+
function get_metar() {
if (empty($this->metar)) {
/* The METAR is not set - we try to load it */
@@ -108,19 +114,20 @@
/**
* Tries to get a METAR from the database.
*
- * It looks in the database, and fetches a new METAR is necessary.
+ * It looks in the database, and fetches a new METAR if necessary.
* You do not have to be connected to the database before you call
* this function, just make sure that you have passed the right
* properties to the object.
*
* If $this->properties['always_use_db'] is true, then it ignores
* the timestamp of the METAR and just returns it. Otherwise it will
- * try to get a new METAR from the web, if the old one is older that
+ * try to get a new METAR from the web, if the old one is older than
* one hour.
*
- * @return string The raw METAR.
* @access public
+ * @return string The raw METAR.
*/
+
function get_metar_from_db() {
if ($this->db->is_connected) {
$this->debug('get_metar_from_db(): Connected to the database,
$this->db->is_connected == true, before connect()');
@@ -133,25 +140,28 @@
if ($data = $this->db->get_metar($this->get_icao())) { /* found station */
$this->debug('get_metar_from_db(): Found the METAR in the database');
list($metar, $timestamp) = $data;
- /* We set the METAR right away, and then count on
- * get_metar_from_web() to set it to something else, if
- * necessary.
- */
+
+ /* We set the METAR right away, and then count on
+ * get_metar_from_web() to set it to something else, if
+ * necessary.
+ */
$this->metar = $metar;
if ($this->properties['always_use_db'] || $timestamp > time() - 3600) {
- /* We have asked explicit for a cached metar, or the METAR is
- * still fresh. Either way - we return the METAR we found in
- * the database.
- */
+
+ /* We have asked explicit for a cached METAR, or the METAR is
+ * still fresh. Either way - we return the METAR we found in
+ * the database.
+ */
+
$this->debug('get_metar_from_db(): Using previously cached METAR for <code>' .
$this->get_location() . '</code>. The METAR expires in ' . ($timestamp + 3600 -
time()) . ' seconds.');
return $metar;
} else {
- /* The METAR is too old, so we fetch a new */
+ /* The METAR is too old, so we fetch a new */
$this->debug('get_metar_from_db(): The METAR for <code>' .
$this->get_location() . '</code> was ' . (time() - 3600 - $timestamp) . ' seconds too
old.');
return $this->get_metar_from_web(false);
}
} else {
- /* We need to get a new METAR from the web. */
+ /* We need to get a new METAR from the web. */
$this->debug('get_metar_from_db(): New station <code>' . $this->get_location()
. '</code> - fetching a new METAR.');
return $this->get_metar_from_web(true);
}
@@ -160,32 +170,37 @@
/**
* Fetches a METAR from the Internet.
*
- * The METAR is fetched via HTTP from the National Weather Services public server
at http://weather.noaa.gov.
+ * The METAR is fetched via HTTP from the National Weather Services
+ * public server at http://weather.noaa.gov .
*
- * @param boolean Should the station be inserted into the database, or should we
update an all ready existing entry?
- * @return string The raw METAR.
+ * @param boolean Should the station be inserted into the database,
+ * or should we update an already existing entry?
* @access public
+ * @return string The raw METAR.
*/
+
function get_metar_from_web($new_station) {
$metar = '';
$icao = $this->get_icao();
- if ($this->properties['use_proxy']) { /* We use a proxy */
- /* Inspirated by code from Paul Kairis <[EMAIL PROTECTED]> */
+ if ($this->properties['use_proxy']) {
+ /* We use a proxy */
+ /* Inspirated by code from Paul Kairis <[EMAIL PROTECTED]> */
$fp = fsockopen($this->properties['proxy_host'],
$this->properties['proxy_port']);
if ($fp) {
fputs($fp, 'GET http://weather.noaa.gov/pub/data/' .
"observations/metar/stations/$icao.TXT HTTP/1.0\r\n\r\n");
- /* We check the status line */
+ /* We check the status line */
if (strpos(fgets($fp, 1024), '200 OK')) {
- /* Then we seek until we find the empty line between the
- headers and the contents. */
+ /* Then we seek until we find the empty line between the
+ * headers and the contents.
+ */
do {
$line = fgets($fp, 1024);
} while ($line != "\r\n");
- /* We now know, that the following lines are the contents. */
+ /* We know now, that the following lines are the contents. */
unset($file);
while ($line = fgets($fp, 1024)) {
$file[] = $line;
@@ -193,61 +208,62 @@
fclose($fp);
}
}
- } else { /* No proxy - we just fetch the file the normal way. */
-
- /* We use the @file notation here because it might fail. */
+ } else {
+ /* No proxy - we just fetch the file the normal way. */
+ /* We use the @file notation here because it might fail. */
$file = @file('http://weather.noaa.gov/pub/data/' .
"observations/metar/stations/$icao.TXT");
}
- /* Here we test to see if we actually got a METAR. */
+ /* Here we test to see if we actually got a METAR. */
if (is_array($file)) {
- /* The first line in the file is the date */
+ /* The first line in the file is the date */
list(, $date) = each($file);
$date = trim($date);
- /* The next lines are the METAR it self. We make sure that we
- * don't put a space infront of the first line
- */
+ /* The next lines are the METAR itself. We make sure that we
+ * don't put a space in front of the first line.
+ */
list(, $line) = each($file);
$metar = trim($line);
- /* Then the rest of the lines... */
+ /* Then the rest of the lines... */
while (list(, $line) = each($file)) {
$metar .= ' ' . trim($line);
}
- /* We don't want any double-spaces in our METAR */
+ /* We don't want any double-spaces in our METAR */
$metar = ereg_replace('[ ]+', ' ', $metar);
$date = explode(':', strtr($date, '/ ', '::'));
if ($date[2] > gmdate('j')) {
- /* The day is greather that the current day of month => the
- report is from last month. */
+ /* The day is greater that the current day of month
+ * => the report is from last month.
+ */
$date[1]--;
}
$timestamp = gmmktime($date[3], $date[4], 0, $date[1], $date[2], $date[0]);
if (!ereg('[0-9]{6}Z', $metar)) {
- /* Some reports dont even have a time-part, so we insert the
- * current time. This might not be the time of the report, but
- * it was broken anyway :-)
- */
+ /* Some reports don't even have a time-part, so we insert the
+ * current time. This might not be the time of the report, but
+ * it was broken anyway :-)
+ */
$metar = gmdate('dHi', $timestamp) . 'Z ' . $metar;
}
if ($timestamp < (time() - 3300)) {
- /* 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.
- */
+ /* 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;
}
} else {
- /* If we end up here, it means that there was no file. If the
- * station was a new station, we set the metar to an empty
- * string, else we just use the old METAR. We adjust the time
- * stored in the database in both cases, so that the server
- * isn't stressed to much.
- */
+ /* If we end up here, it means that there was no file. If the
+ * station was a new station, we set the metar to an empty
+ * string, else we just use the old METAR. We adjust the time
+ * stored in the database in both cases, so that the server
+ * isn't stressed to much.
+ */
if ($new_station) {
$metar = '';
} else {
@@ -256,7 +272,7 @@
$timestamp = time() - 3000;
}
- /* We then cache the METAR in our database */
+ /* We then cache the METAR in our database */
if ($new_station) {
$this->debug('get_metar_from_web(): Inserting new METAR for <code>' .
$this->get_location() . '</code>');
$this->db->insert_metar($icao, $metar, $timestamp);
@@ -264,7 +280,7 @@
$this->debug('get_metar_from_web(): Updating METAR for <code>' .
$this->get_location() . '</code>');
$this->db->update_metar($icao, $metar, $timestamp);
}
- /* We update and return the METAR */
+ /* We update and return the METAR */
$this->metar = $metar;
return $metar;
}
_______________________________________________
PHPWeather-checkins mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/phpweather-checkins