[dev] Horde Metar Block (patch)
Rick Emery
rick at emery.homelinux.net
Tue Dec 30 10:30:09 PST 2003
I saw on the CVS list that Jan fixed the gettext in the metar.php file (Thanks
Jan!), so I'm resubmitting these patches with that stuff removed. These
patches are to:
horde/test.php
1. Adds a check for the pear Services_Weather package, displaying an
appropriate message if it isn't installed.
horde/lib/Block/metar.php
1. There were a few instances in the remarks where the units were hard-coded
(temperature to "f", precipitation amounts to "in"). I discovered during
testing that the Services_Weather package returns these values converted based
on the block parameters. So, if the user selects metric units, the temps are
returned in celsius, but I was displaying "f" after them. This patch fixes
those instances.
2. In the remarks, I was displaying past temperatures and dew points on one
line. I had an instance where the temp for the past hour was set, but the dew
point wasn't, and an error was generated. This patch splits the temp and dew
point into seperate lines (with a check for each being set).
Thanks!
--
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: 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 30 Dec 2003 18:12:24 -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.'
)
);
-------------- next part --------------
Index: metar.php
===================================================================
RCS file: /repository/horde/lib/Block/metar.php,v
retrieving revision 1.4
diff -u -r1.4 metar.php
--- metar.php 28 Dec 2003 13:40:48 -0000 1.4
+++ metar.php 30 Dec 2003 18:09:50 -0000
@@ -241,24 +241,31 @@
}
if (isset($weather['precipitation'])) {
foreach ($weather['precipitation'] as $precip) {
- $html .= '<br />' . sprintf(
- (is_numeric($precip['amount'])) ?
- _("Precip for last %s hour(s): %s in") :
- _("Precip for last %s hour(s): %s"),
- $precip['hours'],
- $precip['amount']);
+ if (is_numeric($precip['amount'])) {
+ $html .= '<br />' . sprintf(
+ _("Precip for last %s hour(s): %s %s"),
+ $precip['hours'], $precip['amount'],
+ $units['rain']);
+ } else {
+ $html .= '<br />' . sprintf(
+ _("Precip for last %s hour(s): %s"),
+ $precip['hours'],
+ $precip['amount']);
+ }
}
unset($weather['precipitation']);
}
if (isset($weather['remark']['snowdepth'])) {
- $html .= '<br />' . sprintf(_("Snow depth: %s in"),
- $weather['remark']['snowdepth']);
+ $html .= '<br />' . sprintf(_("Snow depth: %s %s"),
+ $weather['remark']['snowdepth'],
+ $units['rain']);
unset($weather['remark']['snowdepth']);
}
if (isset($weather['remark']['snowequiv'])) {
$html .= '<br />' . sprintf(
- _("Snow equivalent in water: %s in"),
- $weather['remark']['snowequiv']);
+ _("Snow equivalent in water: %s %s"),
+ $weather['remark']['snowequiv'],
+ $units['rain']);
unset($weather['remark']['snowequiv']);
}
if (isset($weather['remark']['sunduration'])) {
@@ -268,32 +275,40 @@
}
if (isset($weather['remark']['1htemp'])) {
$html .= '<br />' . sprintf(
- _("Temp/dewpoint for last hour: %s %s/%s %s"),
+ _("Temp for last hour: %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 />' . sprintf(
+ _("Dew Point for last hour: %s %s"),
+ round($weather['remark']['1hdew']),
+ strtoupper($units['temp']));
unset($weather['remark']['1hdew']);
}
if (isset($weather['remark']['6hmaxtemp'])) {
- $html .= '<br />' . sprintf(_("Max temp last 6 hours: %s f"),
- round($weather['remark']['6hmaxtemp']));
+ $html .= '<br />' . sprintf(_("Max temp last 6 hours: %s %s"),
+ round($weather['remark']['6hmaxtemp']),
+ $units['temp']);
unset($weather['remark']['6hmaxtemp']);
}
if (isset($weather['remark']['6hmintemp'])) {
- $html .= '<br />' . sprintf(_("Min temp last 6 hours: %s f"),
- round($weather['remark']['6hmintemp']));
+ $html .= '<br />' . sprintf(_("Min temp last 6 hours: %s %s"),
+ round($weather['remark']['6hmintemp']),
+ $units['temp']);
unset($weather['remark']['6hmintemp']);
}
if (isset($weather['remark']['24hmaxtemp'])) {
- $html .= '<br />' . sprintf(_("Max temp last 24 hours: %s f"),
- round($weather['remark']['24hmaxtemp']));
+ $html .= '<br />' . sprintf(_("Max temp last 24 hours: %s %s"),
+ round($weather['remark']['24hmaxtemp']),
+ $units['temp']);
unset($weather['remark']['24hmaxtemp']);
}
if (isset($weather['remark']['24hmintemp'])) {
- $html .= '<br />' . sprintf(_("Min temp last 24 hours: %s f"),
- round($weather['remark']['24hmintemp']));
+ $html .= '<br />' . sprintf(_("Min temp last 24 hours: %s %s"),
+ round($weather['remark']['24hmintemp']),
+ $units['temp']);
unset($weather['remark']['24hmintemp']);
}
if (isset($weather['remark']['sensors'])) {
@@ -316,4 +331,4 @@
return $html;
}
-}
+}
More information about the dev
mailing list