Update of /cvsroot/phpweather/phpweather
In directory usw-pr-cvs1:/tmp/cvs-serv3185

Modified Files:
        VERSION base_object.php data_retrieval.php db_common.php 
        db_dba.php db_layer.php index.php locale_common.php 
        locale_en.php metar_parser.php phpweather.php 
Log Message:
All the defaults that were scattered around in the files have been
moved to defaults-dist.php.

I think that's the most important change :-)


Index: VERSION
===================================================================
RCS file: /cvsroot/phpweather/phpweather/VERSION,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- VERSION     2001/04/02 19:26:06     1.1
+++ VERSION     2001/04/16 15:13:03     1.2
@@ -1 +1 @@
-CVS
+CVS-1.9.5

Index: base_object.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/base_object.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- base_object.php     2001/03/26 20:18:26     1.3
+++ base_object.php     2001/04/16 15:13:03     1.4
@@ -15,29 +15,25 @@
    * All the objects properties are stored in this array.
    *
    * @var  array
-   * @see  $defaults
    */
   var $properties = array();
   
   /**
-   * Classes that extend this one, should put their defaults into this array.
-   *
-   * @var  array
-   */
-  var $defaults   = array();
-  
-  /**
    * Sets up the properties by overriding the defaults with the actual input.
+   *
+   * First it includes the file 'defaults-dist.php'. Next it includes 'defaults.php'. 
+You should place your local customizations in that file, since it will never be 
+overridden. Finally it runs through $input and overrides the properties defined there.
    * 
    * @param  $input  array  the initial properties of the object
-   * @see    $properties, $defaults
+   * @see    $properties
    */
   function base_object($input) {
-    
-    /* This fill in the defaults */
-    while (list($key, $value) = each($this->defaults)) {
-      $this->properties[$key] = $value;
+
+    include('defaults-dist.php');
+
+    if(file_exists('defaults.php')) {
+      include('defaults.php');
     }
+
     /* Then we override the defaults with the actual properties */
     while (list($key, $value) = each($input)) {
       $this->properties[$key] = $value;

Index: data_retrieval.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/data_retrieval.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- data_retrieval.php  2001/04/02 19:34:20     1.3
+++ data_retrieval.php  2001/04/16 15:13:03     1.4
@@ -15,7 +15,7 @@
    * The property is used when-ever someone want 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...
+   * testing... :-)
    *
    * @var string
    */
@@ -24,18 +24,16 @@
   /**
    * Constructor
    *
-   * $defaults is extended with 'always_use_array' = false and 'station' = 'EKYT'.
+   * This sets the station.
    *
    * @param    array   The initial properties of the object.
    * @access   private
    */
   function data_retrieval($input) {
-    /* First we extend the defaults values. */
-    $this->defaults['always_use_db'] = false;
-    $this->defaults['station']       = 'EKYT';
-    /* Then we call the parent constructor. */
+    /* We start by calling the parent constructor. */
     $this->db_layer($input);
 
+    /* Then we set the station. */
     $this->set_station($this->properties['station']);
 
   }
@@ -66,6 +64,7 @@
     }
   }
 
+
   /**
    * Retrieves a raw METAR, either from the web or from a database.
    *
@@ -169,6 +168,11 @@
       $metar = str_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. */
+       $date[1]--;
+      }
       $timestamp = gmmktime($date[3], $date[4], 0, $date[1], $date[2], $date[0]);
       
       if (!ereg('[0-9]{6}Z', $metar)) {

Index: db_common.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/db_common.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- db_common.php       2001/04/05 15:30:42     1.3
+++ db_common.php       2001/04/16 15:13:03     1.4
@@ -15,7 +15,6 @@
    * @var     boolean
    * @access  public
    */
-
   var $is_connected;
 
   /**
@@ -37,27 +36,13 @@
   /**
    * Initializes the database-object.
    *
-   * The defaults are extended with:
-   * - 'db_hostname' = ''
-   * - 'db_database' = ''
-   * - 'db_username' = ''
-   * - 'db_password' = ''
-   * - 'db_pconnect' = false
-   * - 'db_port'     = ''
-   * After that, $is_connected, $link_id and $result_id is set to false, to indicate 
that we're not connected.
+   * $is_connected, $link_id and $result_id is set to false, to indicate that we're 
+not connected.
    * 
    * @param  array  the initial properties of the object
+   * @see    $is_connected, $link_id, $result_id
    */
   function db_common($input) {
-    /* First we extend the defaults. */
-    $this->defaults['db_hostname'] = '';
-    $this->defaults['db_database'] = '';
-    $this->defaults['db_username'] = '';
-    $this->defaults['db_password'] = '';
-    $this->defaults['db_pconnect'] = false;
-    $this->defaults['db_port']     = '';
-    
-    /* Then we call the parent constructor. */
+    /* We start by calling the parent constructor. */
     $this->base_object($input);
     
     /* We're not connected at first, so we set these variables to

Index: db_dba.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/db_dba.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- db_dba.php  2001/04/08 09:58:51     1.2
+++ db_dba.php  2001/04/16 15:13:03     1.3
@@ -8,16 +8,24 @@
  * @version  $Id$
  */
 class db_dba extends db_common {
+
+  /**
+   * Contains another link ID.
+   *
+   * We need to maintain two seperate link IDs, one for the METARs database and one 
+for the database with the names of the stations.
+   *
+   * @var     integer
+   * @access  private
+   */
+  var $link_stations_id;
   
   /**
    * Constructor
    *
-   * We extend the defaults by setting the path to the databases to 
'/tmp/phpweather.db'. You should use probably use another path, especially if you're 
running Windows.
-   *
    * @param  array  the initial properties of the object
    */
   function db_dba($input) {
-    $this->defaults['db_path'] = '/tmp/phpweather.db';
+    /* We just call the parent constructor. */
     $this->db_common($input);
   }
 
@@ -46,13 +54,27 @@
       return true;
     }
     if (!$this->properties['db_pconnect']) {
-      return $this->is_connected = $this->link_id = 
dba_open($this->properties['db_path'],
-                                                            'w',
-                                                            
$this->properties['db_handler']);
+      $this->is_connected = $this->link_id =
+       dba_open($this->properties['db_path'] . '/' .
+                $this->properties['db_metars'],
+                'w',
+                $this->properties['db_handler']);
+      $this->link_stations_id = 
+       dba_open($this->properties['db_path'] . '/' .
+                $this->properties['db_stations'],
+                'r',
+                $this->properties['db_handler']);
     } else {
-      return $this->is_connected = $this->link_id = 
dba_popen($this->properties['db_path'],
-                                                             'w',
-                                                             
$this->properties['db_handler']);
+      $this->is_connected = $this->link_id =
+       dba_popen($this->properties['db_path'] . '/' .
+                 $this->properties['db_metars'],
+                 'w',
+                 $this->properties['db_handler']);
+      $this->link_stations_id = 
+       dba_popen($this->properties['db_path'] . '/' .
+                 $this->properties['db_stations'],
+                 'r',
+                 $this->properties['db_handler']);
     }
   }
   
@@ -117,6 +139,22 @@
     }
   }
 
+  /**
+   * Translated an ICAO into a station name
+   *
+   * The boring ICAO (e.g. EKYT) is translated into something like 'Aalborg, Denmark'.
+   *
+   * @param   string  The ICAO one want's to translate.
+   * @return  string  The full name of the station, including country.
+   * @access  public
+   */
+  function lookup_station($station) {
+    if (dba_exists($station, $this->link_stations_id)) {
+      return dba_fetch($station, $this->link_stations_id);
+    } else {
+      return $station;
+    }
+  }
 }
 
 ?>

Index: db_layer.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/db_layer.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- db_layer.php        2001/04/02 19:32:28     1.4
+++ db_layer.php        2001/04/16 15:13:03     1.5
@@ -19,14 +19,10 @@
   /**
    * Creates the database-object based on $input['db_type'].
    *
-   * $defaults is extended by 'db_type' = 'none'.
-   *
    * @param  $input  array  initial properties for the object.
    */
   function db_layer($input) {
-    /* First we extend the defaults. */
-    $this->defaults['db_type'] = 'none';
-    /* Then we call the parent constructor. */
+    /* We call the parent constructor. */
     $this->base_object($input);
     
     /* We then create our db object */
@@ -40,8 +36,8 @@
    */
   function set_db_type($type) {
     switch ($type) {
-    case 'none':
-      $this->db = new db_none($this->properties);
+    case 'null':
+      $this->db = new db_null($this->properties);
       $this->properties['db_type'] = $type;
       break;
     case 'mysql':
@@ -57,8 +53,8 @@
       $this->properties['db_type'] = $type;
       break;
     default:
-      $this->error('db_type not recognized: <code>' . $this->properties['db_type'] . 
'</code>, using default: ' . $this->defaults['db_type'] . '</code>.');
-      $this->set_db_type($this->defaults['db_type']);
+      $this->error('db_type not recognized: <code>' . $this->properties['db_type'] . 
+'</code>, using <code>null</code>.');
+      $this->set_db_type('null');
       break;
     }
   }

Index: index.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/index.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- index.php   2001/04/08 09:59:54     1.5
+++ index.php   2001/04/16 15:13:03     1.6
@@ -27,21 +27,8 @@
 //define('DEBUG', true);
 
 
-$properties = array('db_hostname' => 'localhost',
-                   'db_database' => '',
-                   'db_username' => '',
-                   'db_password' => '',
-                   /*If you set this to 'mysql', you'll need to fill
-                      in the other 'db_*' properties. */
-                   'db_type'     => 'dba', 
-                   'db_handler'  => 'gdbm',
-                   'db_path'     => './phpweather.db',
-                   'mark_begin'  => '<font color="red">',
-                   'mark_end'    => '</font>',
-                   'pref_units'  => 'both_imperial',
-                   'station'     => 'EKYT',
-                   'language'    => 'en'
-                   );
+$properties = array('mark_begin' => '<font color="blue">',
+                   'mark_end'   => '</font>');
                    
 
 /* Checkpoint, we store the time */
@@ -51,6 +38,10 @@
 /* Here we make an object for the weather */
 $obj = new phpweather($properties);
 
+echo "<pre>\n";
+print_r($obj->properties);
+echo "</pre>\n";
+
 /* Checkpoint, we store the time */
 $time[] = array(microtime(), 'object-creation');
 
@@ -69,12 +60,15 @@
 
 /* Checkpoint, we store the time */
 $time[] = array(microtime(), 'pretty-print finished');
+
+$stations = array('FNLU', 'LOWW', 'YMML', 'TNCA',
+                 'TXKF', 'CYOD', 'FJDG', 'MWCR',
+                 'MROC', 'HECA', 'ZSAM', 'YPCC',
+                 'LFPG', 'EDDV', 'LDZA', 'LGSR',
+                 'HKNW', 'OKBK', 'VHHH', 'EPWA'
+                 );
+
 
-$stations = array('FNLU', 'LOWW',
-                 'TXKF', 'CYOD',
-                 'MROC', 'HECA',
-                 'LFPG', 'EDDV',
-                 'HKNW', 'OKBK');
 $num_stations = count($stations);
 
 for ($i = 0; $i < $num_stations; $i++) {
@@ -85,7 +79,7 @@
 }
 
 /* Checkpoint, we store the time */
-$time[] = array(microtime(), '10 stations displayed');
+$time[] = array(microtime(), '20 stations displayed');
 
 
 

Index: locale_common.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/locale_common.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- locale_common.php   2001/04/08 09:57:17     1.5
+++ locale_common.php   2001/04/16 15:13:03     1.6
@@ -2,7 +2,7 @@
 /**
  * Provides all the function needed to generate (English) output.
  *
- * This class has the capability to do an English pretty-print, if it is provided 
with the right set of strings. It's up to child-classes to provide these strings, and 
override the methods in this class, as necessary.
+ * This class has the capability to do a pretty-print, if it is provided with the 
+right set of strings. It's up to child-classes to provide these strings, and override 
+the methods in this class, as necessary. The logic in the pretty-print is built 
+around the English output, but it should still be possible to make a good 
+translation, by just translating the strings.
  *
  * @author   Martin Geisler <[EMAIL PROTECTED]>
  * @version  $Id$
@@ -19,24 +19,13 @@
   var $strings = array();
 
   /**
-   * Sets up the defaults.
+   * Constructor.
    *
-   * The defaults are extended with
-   * - 'pref_units' = 'both_metric'
-   * - 'mark_begin' = '<b>'
-   * - 'mark_end'   = '</b>'
-   * - 'exclude'    = array()
-   *
-   * @param   array  The initial properties of the object. If you omit some 
properties, the defaults should kick-in.
+   * @param   array  The initial properties of the object. If you omit some 
+properties, the defaults will kick-in.
    * @access  public
    */
   function locale_common($input) {
-    /* First we extend the defaults values. */
-    $this->defaults['pref_units'] = 'both_metric';
-    $this->defaults['mark_begin'] = '<b>';
-    $this->defaults['mark_end']   = '</b>';
-    $this->defaults['exclude']    = array();
-    /* Then we call the parent constructor. */
+    /* We call the parent constructor. */
     $this->base_object($input);
 
   }
@@ -45,7 +34,7 @@
    * Sets the marks (the strings inserted before and after every number)
    *
    * @param   string  The mark used before numbers and other data elements, for 
example '<font color="red">'
-   * @param   string  The mark used after numbers and other data elements, for 
example '</font>'. If you use HTML tags, it's your responsibility to ensure that they 
match up.
+   * @param   string  The mark used after numbers and other data elements, for 
+example '</font>'. If you use HTML tags, it's your responsibility to ensure that they 
+match up. If they don't, then you pages might not render properly.
    * @access  public
    * @see     get_marks()
    */
@@ -57,7 +46,7 @@
   /**
    * Gets the marks
    *
-   * @return   array   The first element is the string inserted before any number, 
and the second element is the string inserted after.
+   * @return   array   The first element is the string is inserted before any number, 
+and the second element is the string inserted after. The first element is also know 
+as 'mark_begin' and the second as 'mark_end'.
    * @access   public
    * @see      set_marks()
    */
@@ -73,6 +62,7 @@
    * - 'both_imperial' if one wants to produce output like this '16.1 miles (10 
kilometers)'
    * - 'only_metric' if one wants to produce output like this '10 kilometers'
    * - 'only_imperial' if one wants to produce output like this '16.1 miles'
+   * If $new_pref_units isn't recognized, 'both_imperial' will be used instead.
    *
    * @param   string  The new kind of units one wants to use.
    * @access  public
@@ -87,8 +77,8 @@
       $this->properties['pref_units'] = $new_pref_units;
       break;
     default:
-      $this->properties['pref_units'] = $this->defaults['pref_units'];
-      $this->error('argument to pref_units() not recognized: <code>' . 
$new_pref_units . '</code>, using default: <code>' . $this->defaults['pref_units'] . 
'</code>.');
+      $this->properties['pref_units'] = 'both_imperial';
+      $this->error('argument to pref_units() not recognized: <code>' . 
+$new_pref_units . '</code>, using <code>both_imperial</code> instead.');
       break;
     }
   }
@@ -136,6 +126,8 @@
   /**
    * Used to format strings with regard to the preferred units.
    *
+   * If 'pref_units' isn't recognized, the function will set it to 'both_imperial', 
+and try again. 
+   *
    * @param   string  This string should always contain the metric value.
    * @param   string  This string should always contain the imperial value.
    * @return  string  The two arguments in the correct order with regard to the 
preferred units.
@@ -157,9 +149,10 @@
       return $str2;
       break;
     default:
-      $this->error('argument to locale_common->pref_units() not recognized: ' .
+      $this->error('<code>pref_units</code> not recognized: ' .
                   $this->properties['pref_units']);
-      return $this->prefered_units($this->defaults['pref_units']);
+      $this->set_pref_units('both_imperial');
+      return $this->pref_units($str1, $str2);
       break;
     }
   }
@@ -172,7 +165,7 @@
    * - $strings['list_sentences_and']
    * - $strings['list_sentences_comma']
    * - $strings['list_sentences_final_and']
-   * Only non-empty arguments are used, so it's safe to call this function with empty 
strings.
+   * Only non-empty arguments are used, so it's safe to call this function with empty 
+strings. But if you try to call it with uninitialized variables, then PHP might warn 
+you about it anyway.
    *
    * @access  private
    * @return  string  The arguments put together.
@@ -242,7 +235,7 @@
   /**
    * Function used to parse a cloud-group.
    *
-   * @param    array   the cloud-group to be parsed.
+   * @param    array   the cloud-group to be parsed. This should be a group as 
+parse_metar() would return it.
    * @return   string  the string used in the pretty-print.
    * @access   private
    */
@@ -503,16 +496,16 @@
    */
   function print_pretty($data) {
     
-    /*    if (empty($this->metar)) {
-         We don't want to display all sorts of silly things if the
-         metar is empty. 
-         printf($this->strings['no_data'],
-         $this->properties['mark_begin'],
-         $this->properties['mark_end'],
-         $location);
-         return 1;
-         }
-    */
+    if (empty($data['metar'])) {
+      /* We don't want to display all sorts of silly things if the
+        metar is empty. */
+      printf($this->strings['no_data'],
+            $this->properties['mark_begin'],
+            $this->properties['mark_end'],
+            $data['location']);
+      return 1;
+    }
+
     
     extract($data);
     
@@ -615,7 +608,7 @@
            $this->properties['mark_end'] . ') ' . $this->strings['and'] .
            $this->properties['mark_begin'] . $dir_end_str . 
$this->properties['mark_end'] . 
            ' (' . $this->properties['mark_begin'] . $var_end . '&deg;' .
-           $this->properties['mark_end'] . ').';
+           $this->properties['mark_end'] . ')';
        }
       }
     } else {
@@ -623,7 +616,7 @@
                          $this->properties['mark_begin'],
                          $this->properties['mark_end']);
     }
-    $output['wind'] = $wind_str;
+    $output['wind'] = $wind_str . '.';
   }
 
 
@@ -654,8 +647,10 @@
   if (!in_array('altimeter', $this->properties['exclude']) && !empty($altimeter)) {
     extract($altimeter);
     $output['altimeter'] = $this->strings['altimeter'] . 
-      $this->pref_units($this->properties['mark_begin'] . $hpa . 
$this->properties['mark_end'] . ' hPa',
-                    $this->properties['mark_begin'] . $inhg . 
$this->properties['mark_end'] . ' inHg');
+      $this->pref_units($this->properties['mark_begin'] . $hpa .
+                       $this->properties['mark_end'] . ' hPa',
+                       $this->properties['mark_begin'] . $inhg .
+                       $this->properties['mark_end'] . ' inHg') . '.';
   }
 
 

Index: locale_en.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/locale_en.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- locale_en.php       2001/04/08 09:57:17     1.4
+++ locale_en.php       2001/04/16 15:13:03     1.5
@@ -13,7 +13,7 @@
    * @param  array  This is just passed on to locale_common()
    */
   function locale_en($input) {
-    
+    $this->strings['charset']                  = 'ISO-8859-1';
     $this->strings['list_sentences_and']       = ' and ';
     $this->strings['list_sentences_comma']     = ', ';
     $this->strings['list_sentences_final_and'] = ', and ';
@@ -37,7 +37,7 @@
     $this->strings['wind_from']                = ' from ';
     $this->strings['wind_variable']            = ' from %svariable%s directions.';
     $this->strings['wind_varying']             = ', varying between ';
-    $this->strings['wind_calm']                = 'The wind was %scalm%s.';
+    $this->strings['wind_calm']                = 'The wind was %scalm%s';
     $this->strings['wind_dir'] = array(
       'north',
       'north/northeast',

Index: metar_parser.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/metar_parser.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- metar_parser.php    2001/04/08 09:58:15     1.3
+++ metar_parser.php    2001/04/16 15:13:03     1.4
@@ -123,6 +123,9 @@
     $decoded_metar['remarks'] = '';
     
     $decoded_metar['metar'] = $this->get_metar();
+    $decoded_metar['location'] = $this->get_station();
+      // $this->lookup_icao($this->get_station());
+
     $parts = explode(' ', $this->metar);
     $num_parts = count($parts);
     for ($i = 0; $i < $num_parts; $i++) {
@@ -148,9 +151,6 @@
         * Station Identifier
         */
        $decoded_metar['station']  = $part;
-       /* FIXME: Must implement a method called lookup_icao() that
-           returns the name of a station. */
-       $decoded_metar['location'] = $part;
       } elseif (ereg('([0-9]{2})([0-9]{2})([0-9]{2})Z', $part, $regs)) {
        /*
         * Date and Time of Report
@@ -161,7 +161,14 @@
         * add/subtract some hours to $regs[2], e.g. if all your times
         * are 960 minutes off (16 hours) then add 16 to $regs[2].
         */
-       $decoded_metar['time'] = gmmktime($regs[2], $regs[3], 0, gmdate('m'), 
$regs[1], gmdate('Y'));
+       if ($regs[1] > gmdate('j')) {
+       /* The day is greather that the current day of month => the
+           report is from last month. */
+         $month = gmdate('n') - 1;
+       } else {
+         $month = gmdate('n');
+       }
+       $decoded_metar['time'] = gmmktime($regs[2], $regs[3], 0, $month, $regs[1], 
+gmdate('Y'));
       } elseif (ereg('(AUTO|COR|RTD|CC[A-Z]|RR[A-Z])', $part, $regs)) {
        /*
         * Report Modifier: AUTO, COR, CCx or RRx

Index: phpweather.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/phpweather.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- phpweather.php      2001/04/05 15:30:42     1.3
+++ phpweather.php      2001/04/16 15:13:03     1.4
@@ -20,16 +20,11 @@
   /**
    * This constructor sets the language when the object is created.
    *
-   * It extends the defaults with 'language' = 'en'.
-   *
    * @param   array   The initial properties of the object.
    * @access  public
    */
   function phpweather($input) {
-    /* First we extend the defaults values. */
-    $this->defaults['language']   = 'en';
-
-    /* Then we call the parent constructor. */
+    /* We call the parent constructor. */
     $this->metar_parser($input);
 
     /* We also set the language. */
@@ -59,8 +54,8 @@
       $this->output = new locale_fr($this->properties);
       break;
     default:
-      $this->error('language not recognized: ' . $new_langauge);
-      $this->set_language($this->defaults['language']);
+      $this->error('language not recognized: <code>' . $new_langauge . '</code> - 
+using <code>en</code>.');
+      $this->set_language('en');
       break;
     }
   }


_______________________________________________
PHPWeather-checkins mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/phpweather-checkins

Reply via email to