[dev] Horde Metar Block (patch)

Rick Emery rick at emery.homelinux.net
Sat Dec 13 06:12:45 PST 2003


OK, there should be two files attached.

1. A patch to horde/test.php to check for the pear Services_Weather package.

2. A patch to horde/lib/Block/metar.php. This patch:

- displays the tabular data the way we've discussed on the list (I think :-)

- makes the error message a little more meaningful if buildMetarDB.php hasn't
been run.

- changes the display of temp and dew point for the last hour (under
"Remarks"). I actually got data back once where the temp was set, but the dew
point wasn't, and an error was thrown. This patch treats them seperately, so
it's easier to check for each being set.

- fixes some instances where the units were hard-coded instead of using the
requested value (metric, standard, etc).

I'm still trying to figure out how to patch horde/docs/INSTALL. If a user tries
to arrange the portal page to have the metar block, and the pear
Services_Weather package isn't installed, errors will appear at the top of the
page. So, should it be a required or optional package for a horde install?

Alternatively, can we come up with a way for an administrator to turn off the
metar block so a user can't choose it? Or should we maybe comment it out in
registry.php.dist, with a note to uncomment it to activate it?

Thoughts?

--
Rick Emery

"When once you have tasted flight, you will forever walk the Earth
 with your eyes turned skyward, for there you have been, and there
 you will always long to return"
                                              -- Leonardo Da Vinci
-------------- next part --------------
Index: metar.php
===================================================================
RCS file: /repository/horde/lib/Block/metar.php,v
retrieving revision 1.1
diff -u -r1.1 metar.php
--- metar.php	5 Dec 2003 22:40:14 -0000	1.1
+++ metar.php	13 Dec 2003 13:42:14 -0000
@@ -62,7 +62,8 @@
             From metarAirports order by country');
         if (DB::isError($result)) {
             return PEAR::raiseError(
-                _("Error retrieving station IDs from metarAirports"));
+                _("Error retrieving station IDs from metarAirports.
+                Does the table exist in the horde database?"));
         }
         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
             $locations[$row['country']][$row['icao']] = $row['name'];
@@ -109,19 +110,19 @@
             $metar->setDateTimeFormat("M j, Y", "H:i");
             $metar->setMetarSource("http");
             $weather = $metar->getWeather($this->_params['location']);
-            $html .= sprintf(
-                "<table width=100%%><tr><td class=control><b>%s, %s
-                     (%s)</td></tr></table>",
+            $html .= '<table width=100%><tr><td class=control><b>' .
+                sprintf(_("%s, %s (%s)"),
                 $metarLocs['location']['values'][$this->_params['__location']]
                     [$this->_params['location']],
                 $this->_params['__location'],
-                $this->_params['location']);
-            $html .= sprintf("<b>"._("Last Updated:")."</b> %s<p />",
-                $weather['update']);
+                $this->_params['location']) .
+                '</td></tr></table>';
+            $html .= '<b>' . _("Last Updated: ") . '</b>' .
+                sprintf(_("%s"), $weather['update']) . '<p />';
 
             // Wind
             if (isset($weather['wind'])) {
-                $html .= sprintf("<b>"._("Wind:")."</b> ");
+                $html .= '<b>' . _("Wind: ") . '</b> ';
                 if ($weather['windDirection'] == 'Variable') {
                     if (!empty($this->_params['knots'])) {
                         $html .= sprintf(_("%s at %s %s"),
@@ -137,7 +138,7 @@
                     }
                 } elseif (($weather['windDegrees'] == '000') &&
                             ($weather['wind'] == '0')) {
-                    $html .= sprintf(_("calm"));
+                    $html .= _("calm");
                 } else {
                     $html .= sprintf(_("from the %s (%s)"),
                         $weather['windDirection'], $weather['windDegrees']);
@@ -177,137 +178,162 @@
 
             //Visibility
             if (isset($weather['visibility'])) {
-                $html .= sprintf("<br /><b>"._("Visibility:")."</b> %s %s",
-                    $weather['visibility'], $units['vis']);
+                $html .= '<br /><b>' . _("Visibility: ") . '</b>' .
+                    sprintf(_(" %s %s"), $weather['visibility'], $units['vis']);
             }
 
             //Temperature/DewPoint
             if (isset($weather['temperature'])) {
-                $html .= sprintf("<br /><b>"._("Temperature:")."</b> %s %s",
-                                 round($weather['temperature']), 
-                                 strtoupper($units['temp']));
+                $html .= '<br /><b>' . _("Temperature: ") .'</b>' .
+                    sprintf(_("%s %s"),
+                        round($weather['temperature']),
+                        strtoupper($units['temp']));
             }
             if (isset($weather['dewPoint'])) {
-                $html .= sprintf("<br /><b>"._("DewPoint:")."</b> %s %s",
-                                 round($weather['dewPoint']),
-                                 strtoupper($units['temp']));
+                $html .= '<br /><b>' . _("Dew Point: ") . '</b>' .
+                    sprintf(_("%s %s"),
+                        round($weather['dewPoint']),
+                        strtoupper($units['temp']));
             }
             if (isset($weather['feltTemperature'])) {
-                $html .= sprintf("<br /><b>"._("Feels Like:")."</b> %s %s",
-                                 round($weather['feltTemperature']),
-                                 strtoupper($units['temp']));
+                $html .= '<br /><b>' . _("Feels Like: ") . '</b>' .
+                    sprintf(_("%s %s"),
+                        round($weather['feltTemperature']),
+                        strtoupper($units['temp']));
             }
 
             //Pressure
             if (isset($weather['pressure'])) {
-                $html .= sprintf("<br /><b>"._("Pressure:")."</b> %s %s",
-                    $weather['pressure'],
-                    $units['pres']);
+                $html .= '<br /><b>' . _("Pressure: ") . '</b>' .
+                    sprintf(_("%s %s"),
+                        $weather['pressure'],
+                        $units['pres']);
             }
 
             //Humidity
             if (isset($weather['humidity'])) {
-                $html .= sprintf("<br /><b>"._("Humidity:")."</b> %s%%",
-                    round($weather['humidity']));
+                $html .= '<br /><b>' . _("Humidity: ") . '</b>' .
+                    sprintf(_("%s%%"),
+                        round($weather['humidity']));
             }
 
             //Clouds
             if (isset($weather['clouds'])) {
-                $html .= sprintf("<br /><b>"._("Clouds:")."</b>");
+                $html .= '<br /><b>' . _("Clouds: ") . '</b>';
                 foreach ($weather['clouds'] as $cloud) {
                     if (isset($cloud['height'])) {
-                        $html .= sprintf(_("<br />%s at %s ft"),
+                        $html .= '<br />' . sprintf(_("%s at %s ft"),
                             $cloud['amount'], $cloud['height']);
                     } else {
-                        $html .= sprintf(_("<br />%s"), $cloud['amount']);
+                        $html .= '<br />' . sprintf(_("%s"), $cloud['amount']);
                     }
                 }
             }
 
             //Conditions
             if (isset($weather['condition'])) {
-                $html .= sprintf("<br /><b>"._("Conditions:")."</b> %s",
-                    $weather['condition']);
+                $html .= '<br /><b>' . _("Conditions: ") . '</b>' .
+                    sprintf(_("%s"), $weather['condition']);
             }
 
             //Remarks
             if (isset($weather['remark'])) {
-                $html .= sprintf("<br /><b>"._("Remarks:")."</b>");
+                $html .= '<br /><b>' . _("Remarks: ") . '</b>';
                 if (isset($weather['remark']['seapressure'])) {
-                    $html .= sprintf(_("<br />Pressure at sea-level: %s %s"),
-                        $weather['remark']['seapressure'],
-                        $units['pres']);
+                    $html .= '<br />' . _("Pressure at sea-level: ") .
+                        sprintf(_("%s %s"),
+                            $weather['remark']['seapressure'],
+                            $units['pres']);
                     unset($weather['remark']['seapressure']);
                 }
                 if (isset($weather['precipitation'])) {
                     foreach ($weather['precipitation'] as $precip) {
-                        $html .= sprintf(
-                            (is_numeric($precip['amount'])) ?
-                            _("<br />Precip for last %s hour(s): %s in") :
-                            _("<br />Precip for last %s hour(s): %s"),
-                            $precip['hours'],
-                            $precip['amount']);
+                        if (is_numeric($precip['amount'])) {
+                            $html .= '<br />' . _("Precip for last ") .
+                                sprintf(_("%s hour(s): %s %s"),
+                                    $precip['hours'], $precip['amount'],
+                                    $units['rain']);
+                        } else {
+                            $html .= '<br />' . _("Precip for last ") .
+                                sprintf(_("%s hour(s): %s"),
+                                    $precip['hours'],
+                                    $precip['amount']);
+                        }
                     }
                     unset($weather['precipitation']);
                 }
                 if (isset($weather['remark']['snowdepth'])) {
-                    $html .= sprintf(_("<br />Snow depth: %s in"),
-                        $weather['remark']['snowdepth']);
+                    $html .= '<br />' . _("Snow depth: ") .
+                        sprintf(_("%s %s"),
+                            $weather['remark']['snowdepth'],
+                            $units['rain']);
                     unset($weather['remark']['snowdepth']);
                 }
                 if (isset($weather['remark']['snowequiv'])) {
-                    $html .= sprintf(
-                        _("<br />Snow equivalent in water: %s in"),
-                        $weather['remark']['snowequiv']);
+                    $html .= '<br />' . _("Snow equivalent in water: ") .
+                        sprintf(_("%s %s"),
+                            $weather['remark']['snowequiv'],
+                            $units['rain']);
                     unset($weather['remark']['snowequiv']);
                 }
                 if (isset($weather['remark']['sunduration'])) {
-                    $html .= sprintf(_("<br />%s mins"),
+                    $html .= '<br />' . sprintf(_("%s mins"),
                         $weather['remark']['sunduration']);
                     unset($weather['remark']['sunduration']);
                 }
                 if (isset($weather['remark']['1htemp'])) {
-                    $html .=
-                        sprintf(
-                            _("<br />Temp/dewpoint for last hour: %s %s/%s %s"),
+                    $html .= '<br />' . _("Temp for last hour: ") .
+                        sprintf(_("%s %s"),
                             round($weather['remark']['1htemp']),
-                            strtoupper($units['temp']),
-                            round($weather['remark']['1hdew']),
                             strtoupper($units['temp']));
                     unset($weather['remark']['1htemp']);
+                }
+                if (isset($weather['remark']['1hdew'])) {
+                    $html .= '<br />' . _("Dew Point for last hour: ") .
+                        sprintf(_("%s %s"),
+                            round($weather['remark']['1hdew']),
+                            strtoupper($units['temp']));
                     unset($weather['remark']['1hdew']);
                 }
                 if (isset($weather['remark']['6hmaxtemp'])) {
-                    $html .= sprintf(_("<br />Max temp last 6 hours: %s f"),
-                        round($weather['remark']['6hmaxtemp']));
+                    $html .= '<br />' . _("Max temp last 6 hours: ") .
+                        sprintf(_("%s %s"),
+                            round($weather['remark']['6hmaxtemp']),
+                            $units['temp']);
                     unset($weather['remark']['6hmaxtemp']);
                 }
                 if (isset($weather['remark']['6hmintemp'])) {
-                    $html .= sprintf(_("<br />Min temp last 6 hours: %s f"),
-                        round($weather['remark']['6hmintemp']));
+                    $html .= '<br />' . _("Min temp last 6 hours: ") .
+                        sprintf(_("%s %s"),
+                            round($weather['remark']['6hmintemp']),
+                            $units['temp']);
                     unset($weather['remark']['6hmintemp']);
                 }
                 if (isset($weather['remark']['24hmaxtemp'])) {
-                    $html .= sprintf(_("<br />Max temp last 24 hours: %s f"),
-                        round($weather['remark']['24hmaxtemp']));
+                    $html .= '<br />' . _("Max temp last 24 hours: ") .
+                        sprintf(_("%s %s"),
+                            round($weather['remark']['24hmaxtemp']),
+                            $units['temp']);
                     unset($weather['remark']['24hmaxtemp']);
                 }
                 if (isset($weather['remark']['24hmintemp'])) {
-                    $html .= sprintf(_("<br />Min temp last 24 hours: %s f"),
-                        round($weather['remark']['24hmintemp']));
+                    $html .= '<br />' . _("Min temp last 24 hours: ") .
+                        sprintf(_("%s %s"),
+                            round($weather['remark']['24hmintemp']),
+                            $units['temp']);
                     unset($weather['remark']['24hmintemp']);
                 }
                 if (isset($weather['remark']['sensors'])) {
                     foreach ($weather['remark']['sensors'] as $sensor) {
-                        $html .= sprintf(_("<br />Sensor: %s"),
-                                $sensor);
+                        $html .= '<br />' . _("Sensor: ") .
+                            sprintf(_("%s"), $sensor);
                     }
                     unset($weather['remark']['sensors']);
                 }
 
                 // handle any remaining remarks
                 foreach ($weather['remark'] as $remark) {
-                    $html .= sprintf(_("<br />%s"), $remark);
+                    $html .= '<br />' . sprintf(_("%s"), $remark);
                 }
             }
         } else {
-------------- next part --------------
Index: test.php
===================================================================
RCS file: /repository/horde/test.php,v
retrieving revision 1.111
diff -u -r1.111 test.php
--- test.php	30 Nov 2003 01:32:45 -0000	1.111
+++ test.php	12 Dec 2003 21:56:53 -0000
@@ -160,6 +160,10 @@
     'XML_SVG' => array(
         'path' => 'XML/SVG.php',
         'error' => 'XML_SVG is used by several Horde applications to generate graphs and other SVG diagrams.'
+    ),
+    'Services_Weather' => array(
+        'path' => 'Services/Weather.php',
+        'error' => 'Services_Weather is used by the metar applet/block on the portal page.'
     )
 );
 


More information about the dev mailing list