enabled = (!empty($GLOBALS['conf']['sql']['phptype']) &&
class_exists('Services_Weather') &&
class_exists('DB'));
$this->_name = _("Metar Weather");
}
/**
*/
protected function _title()
{
return _("Current Weather");
}
/**
*/
protected function _params()
{
$db = $GLOBALS['injector']->getInstance('Horde_Core_Factory_DbPear')->create();
$result = $db->query('SELECT icao, name, country FROM metarAirports ORDER BY country');
if ($result instanceof PEAR_Error) {
throw new Horde_Exception($result);
}
$locations = array();
while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
$locations[$row['country']][$row['icao']] = $row['name'];
}
return array(
'location' => array(
'type' => 'mlenum',
'name' => _("Location"),
'default' => 'KSFB',
'values' => $locations,
),
'units' => array(
'type' => 'enum',
'name' => _("Units"),
'default' => 's',
'values' => array(
's' => _("Standard"),
'm' => _("Metric")
)
),
'knots' => array(
'type' => 'checkbox',
'name' => _("Wind speed in knots"),
'default' => 0
),
'taf' => array(
'type' => 'checkbox',
'name' => _("Display forecast (TAF)"),
'default' => 0
)
);
}
/**
*/
private function _row($label, $content)
{
return '
' . $label . ': ' . $content;
}
/**
*/
private function _sameRow($label, $content)
{
return ' ' . $label . ': ' . $content;
}
/**
*/
protected function _content()
{
global $conf;
static $metarLocs;
if (empty($this->_params['location'])) {
throw new Horde_Exception(_("No location is set."));
}
if (!is_array($metarLocs)) {
$metarLocs = $this->getParams();
}
$metar = Services_Weather::service('METAR', array('debug' => 0));
$metar->setMetarDB($conf['sql']);
$metar->setUnitsFormat($this->_params['units']);
$metar->setDateTimeFormat('M j, Y', 'H:i');
$metar->setMetarSource('http');
$units = $metar->getUnitsFormat($this->_params['units']);
$weather = $metar->getWeather($this->_params['location']);
if (is_a($weather, 'PEAR_Error')) {
$html = $weather->getMessage();
return $html;
}
$html = '
| ' . sprintf('%s, %s (%s)', $metarLocs['location']['values'][$this->_params['__location']][$this->_params['location']], $this->_params['__location'], $this->_params['location']) . ' |
| ' . $time . ' | Wind: ';
if (isset($entry['wind'])) {
if ($entry['windDirection'] == 'Variable') {
if (!empty($this->_params['knots'])) {
$forecast .= sprintf(_("%s at %s %s"),
strtolower($entry['windDirection']),
round($metar->convertSpeed($entry['wind'],
$units['wind'], 'kt')),
'kt');
} else {
$forecast .= sprintf(_("%s at %s %s"),
$entry['windDirection'],
round($entry['wind']),
$units['wind']);
}
} elseif (($entry['windDegrees'] == '000') &&
($entry['wind'] == '0')) {
$forecast .= sprintf(_("calm"));
} else {
$forecast .= sprintf(_("from the %s (%s) at %s %s"),
$entry['windDirection'],
$entry['windDegrees'],
empty($this->_params['knots']) ?
round($entry['wind']) :
round($metar->convertSpeed($entry['wind'], $units['wind'], 'kt')),
empty($this->_params['knots']) ?
$units['wind'] :
'kt');
}
$forecast .= ' '; } if (isset($entry['temperatureLow']) || isset($entry['temperatureHigh'])) { $forecast .= 'Temperature'; if (isset($entry['temperatureLow'])) { $forecast .= ' Low:'; $forecast .= $entry['temperatureLow']; } if (isset($entry['temperatureHigh'])) { $forecast .= ' High:'; $forecast .= $entry['temperatureHigh']; } $forecast .= ' '; } if (isset($entry['windshear'])) { $forecast .= 'Windshear:'; $forecast .= sprintf(_("from the %s (%s) at %s %s"), $entry['windshearDirection'], $entry['windshearDegrees'], $entry['windshearHeight'], $units['height']); $forecast .= ' '; } if (isset($entry['visibility'])) { $forecast .= 'Visibility: '; $forecast .= strtolower($entry['visQualifier']) . ' ' . $entry['visibility'] . ' ' . $units['vis']; $forecast .= ' '; } if (isset($entry['condition'])) { $forecast .= 'Conditions: '; $forecast .= $entry['condition']; $forecast .= ' '; } $forecast .= 'Clouds: '; foreach ($entry['clouds'] as $clouds) { if (isset($clouds['type'])) { $forecast .= ' ' . $clouds['type']; } $forecast .= ' ' . $clouds['amount']; if (isset($clouds['height'])) { $forecast .= ' at ' . $clouds['height'] . ' ' . $units['height']; } else { $forecast .= ' '; } } $forecast .= ' |
| ';
$forecast .= '* ' . $fmcEntry['from'] . ' - ' . $fmcEntry['to'] . ' | ';
$forecast .= ''; $forecast .= 'Type: ' . $fmcEntry['type']; if (isset($fmcEntry['probability'])) { $forecast .= ' Prob: ' . $fmcEntry['probability'] . '%'; } if (isset($fmcEntry['condition'])) { $forecast .= ' Conditions: ' . $fmcEntry['condition']; } if (isset($fmcEntry['clouds'])) { $forecast .= ' Clouds:'; foreach ($fmcEntry['clouds'] as $fmcClouds) { if (isset($fmcClouds['type'])) { $forecast .= ' ' . $fmcClouds['type']; } if (isset($fmcClouds['height'])) { $forecast .= ' ' . $fmcClouds['amount']; $forecast .= ' ' . $fmcClouds['height']; $forecast .= ' ' . $units['height']; } else { $forecast .= ' ' . $fmcClouds['amount']; } } } if (isset($fmcEntry['visQualifier'])) { $forecast .= ' Visibility: '; $forecast .= strtolower($fmcEntry['visQualifier']) . ' '; $forecast .= $fmcEntry['visibility'] . ' ' . $units['vis']; } $forecast .= ' |