コード例 #1
0
// | This source file is subject to version 2.0 of the PHP license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at                              |
// | http://www.php.net/license/2_02.txt.                                 |
// | If you did not receive a copy of the PHP license and are unable to   |
// | obtain it through the world-wide-web, please send a note to          |
// | license@php.net so we can mail you a copy immediately.               |
// +----------------------------------------------------------------------+
// | Authors: Alexander Wirtz <*****@*****.**>                             |
// +----------------------------------------------------------------------+
//
// $Id: metar-basic.php,v 1.10 2004/05/07 14:41:36 eru Exp $
require_once "Services/Weather.php";
// Object initialization - error checking is important, because of
// handling exceptions such as missing PEAR modules
$metar =& Services_Weather::service("METAR", array("debug" => 0));
if (Services_Weather::isError($metar)) {
    die("Error: " . $metar->getMessage() . "\n");
}
// Set parameters for DB access, needed for location searches
$metar->setMetarDB("sqlite://localhost//usr/local/lib/php/data/Services_Weather/servicesWeatherDB");
if (Services_Weather::isError($metar)) {
    echo "Error: " . $metar->getMessage() . "\n";
}
/* Erase comments to enable caching
$status = $metar->setCache("file", array("cache_dir" => "/tmp/cache/"));
if (Services_Weather::isError($status)) {
    echo "Error: ".$status->getMessage()."\n";
}
*/
$metar->setUnitsFormat("custom", array("wind" => "kt", "vis" => "km", "height" => "ft", "temp" => "c", "pres" => "hpa", "rain" => "in"));
コード例 #2
0
// | This source file is subject to version 2.0 of the PHP license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at                              |
// | http://www.php.net/license/2_02.txt.                                 |
// | If you did not receive a copy of the PHP license and are unable to   |
// | obtain it through the world-wide-web, please send a note to          |
// | license@php.net so we can mail you a copy immediately.               |
// +----------------------------------------------------------------------+
// | Authors: Alexander Wirtz <*****@*****.**>                             |
// +----------------------------------------------------------------------+
//
// $Id: ejse-basic.php,v 1.3 2004/05/07 14:41:36 eru Exp $
require_once "Services/Weather.php";
// Object initialization - error checking is important, because of
// handling exceptions such as missing PEAR modules or not being online
$ejse =& Services_Weather::service("Ejse", array("debug" => 2));
if (Services_Weather::isError($ejse)) {
    die("Error: " . $ejse->getMessage() . "\n");
}
/* Erase comments to enable caching
$status = $ejse->setCache("file", array("cache_dir" => "/tmp/cache/"));
if (Services_Weather::isError($status)) {
    echo "Error: ".$status->getMessage()."\n";
}
*/
$ejse->setUnitsFormat("metric");
$ejse->setDateTimeFormat("d.m.Y", "H:i");
$location = "81611";
// Aspen, CO
//$location = "02115"; // Boston, MA
//$location = "96799"; // Pago Pago, AS
コード例 #3
0
// | This source file is subject to version 2.0 of the PHP license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at                              |
// | http://www.php.net/license/2_02.txt.                                 |
// | If you did not receive a copy of the PHP license and are unable to   |
// | obtain it through the world-wide-web, please send a note to          |
// | license@php.net so we can mail you a copy immediately.               |
// +----------------------------------------------------------------------+
// | Authors: Alexander Wirtz <*****@*****.**>                             |
// +----------------------------------------------------------------------+
//
// $Id: globalweather-basic.php,v 1.4 2004/05/07 14:41:36 eru Exp $
require_once "Services/Weather.php";
// Object initialization - error checking is important, because of
// handling exceptions such as missing PEAR modules or not being online
$globalweather =& Services_Weather::service("GlobalWeather", array("debug" => 2));
if (Services_Weather::isError($globalweather)) {
    die("Error: " . $globalweather->getMessage() . "\n");
}
/* Erase comments to enable caching
$status = $globalweather->setCache("file", array("cache_dir" => "/tmp/cache/"));
if (Services_Weather::isError($status)) {
    echo "Error: ".$status->getMessage()."\n";
}
*/
$globalweather->setUnitsFormat("metric");
$globalweather->setDateTimeFormat("d.m.Y", "H:i");
// First get code for location
$search = $globalweather->searchLocation("Koeln / Bonn");
if (Services_Weather::isError($search)) {
    die("Error: " . $search->getMessage() . "\n");
コード例 #4
0
ファイル: Metar.php プロジェクト: DSNS-LAB/Dmail
 /**
  */
 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 = '<table width="100%" cellspacing="0">' . '<tr><td class="control"><strong>' . sprintf('%s, %s (%s)', $metarLocs['location']['values'][$this->_params['__location']][$this->_params['location']], $this->_params['__location'], $this->_params['location']) . '</strong></td></tr></table><strong>' . _("Last Updated:") . '</strong> ' . $weather['update'] . '<br /><br />';
     // Wind.
     if (isset($weather['wind'])) {
         $html .= '<strong>' . _("Wind:") . '</strong> ';
         if ($weather['windDirection'] == 'Variable') {
             if (!empty($this->_params['knots'])) {
                 $html .= sprintf(_("%s at %s %s"), $weather['windDirection'], round($metar->convertSpeed($weather['wind'], $units['wind'], 'kt')), 'kt');
             } else {
                 $html .= sprintf(_("%s at %s %s"), $weather['windDirection'], round($weather['wind']), $units['wind']);
             }
         } elseif ($weather['windDegrees'] == '000' && $weather['wind'] == '0') {
             $html .= sprintf(_("calm"));
         } else {
             $html .= sprintf(_("from the %s (%s) at %s %s"), $weather['windDirection'], $weather['windDegrees'], empty($this->_params['knots']) ? round($weather['wind']) : round($metar->convertSpeed($weather['wind'], $units['wind'], 'kt')), empty($this->_params['knots']) ? $units['wind'] : 'kt');
         }
     }
     if (isset($weather['windGust'])) {
         if ($weather['windGust']) {
             if (!empty($this->_params['knots'])) {
                 $html .= sprintf(_(", gusting %s %s"), round($metar->convertSpeed($weather['windGust'], $units['wind'], 'kt')), 'kt');
             } else {
                 $html .= sprintf(_(", gusting %s %s"), round($weather['windGust']), $units['wind']);
             }
         }
     }
     if (isset($weather['windVariability'])) {
         if ($weather['windVariability']['from']) {
             $html .= sprintf(_(", variable from %s to %s"), $weather['windVariability']['from'], $weather['windVariability']['to']);
         }
     }
     // Visibility.
     if (isset($weather['visibility'])) {
         $html .= $this->_sameRow(_("Visibility"), $weather['visibility'] . ' ' . $units['vis']);
     }
     // Temperature/DewPoint.
     if (isset($weather['temperature'])) {
         $html .= $this->_row(_("Temperature"), round($weather['temperature']) . '&deg;' . Horde_String::upper($units['temp']));
     }
     if (isset($weather['dewPoint'])) {
         $html .= $this->_sameRow(_("Dew Point"), round($weather['dewPoint']) . '&deg;' . Horde_String::upper($units['temp']));
     }
     if (isset($weather['feltTemperature'])) {
         $html .= $this->_sameRow(_("Feels Like"), round($weather['feltTemperature']) . '&deg;' . Horde_String::upper($units['temp']));
     }
     // Pressure.
     if (isset($weather['pressure'])) {
         $html .= $this->_row(_("Pressure"), $weather['pressure'] . ' ' . $units['pres']);
     }
     // Humidity.
     if (isset($weather['humidity'])) {
         $html .= $this->_sameRow(_("Humidity"), round($weather['humidity']) . '%');
     }
     // Clouds.
     if (isset($weather['clouds'])) {
         $clouds = '';
         foreach ($weather['clouds'] as $cloud) {
             $clouds .= '<br />';
             if (isset($cloud['height'])) {
                 $clouds .= sprintf(_("%s at %s %s"), $cloud['amount'], $cloud['height'], $units['height']);
             } else {
                 $clouds .= $cloud['amount'];
             }
         }
         $html .= $this->_row(_("Clouds"), $clouds);
     }
     // Conditions.
     if (isset($weather['condition'])) {
         $html .= $this->_row(_("Conditions"), $weather['condition']);
     }
     // Remarks.
     if (isset($weather['remark'])) {
         $remarks = '';
         $other = '';
         foreach ($weather['remark'] as $remark => $value) {
             switch ($remark) {
                 case 'seapressure':
                     $remarks .= '<br />' . _("Pressure at sea level: ") . $value . ' ' . $units['pres'];
                     break;
                 case 'precipitation':
                     foreach ($value as $precip) {
                         if (is_numeric($precip['amount'])) {
                             $remarks .= '<br />' . sprintf(ngettext("Precipitation for last %d hour: ", "Precipitation for last %d hours: ", $precip['hours']), $precip['hours']) . $precip['amount'] . ' ' . $units['rain'];
                         } else {
                             $remarks .= '<br />' . sprintf(ngettext("Precipitation for last %d hour: ", "Precipitation for last %d hours: ", $precip['hours']), $precip['hours']) . $precip['amount'];
                         }
                     }
                     break;
                 case 'snowdepth':
                     $remarks .= '<br />' . _("Snow depth: ") . $value . ' ' . $units['rain'];
                     break;
                 case 'snowequiv':
                     $remarks .= '<br />' . _("Snow equivalent in water: ") . $value . ' ' . $units['rain'];
                     break;
                 case 'sunduration':
                     $remarks .= '<br />' . sprintf(_("%d minutes"), $value);
                     break;
                 case '1htemp':
                     $remarks .= '<br />' . _("Temp for last hour: ") . round($value) . '&deg;' . Horde_String::upper($units['temp']);
                     break;
                 case '1hdew':
                     $remarks .= '<br />' . _("Dew Point for last hour: ") . round($value) . '&deg;' . Horde_String::upper($units['temp']);
                     break;
                 case '6hmaxtemp':
                     $remarks .= '<br />' . _("Max temp last 6 hours: ") . round($value) . '&deg;' . Horde_String::upper($units['temp']);
                     break;
                 case '6hmintemp':
                     $remarks .= '<br />' . _("Min temp last 6 hours: ") . round($value) . '&deg;' . Horde_String::upper($units['temp']);
                     break;
                 case '24hmaxtemp':
                     $remarks .= '<br />' . _("Max temp last 24 hours: ") . round($value) . '&deg;' . Horde_String::upper($units['temp']);
                     break;
                 case '24hmintemp':
                     $remarks .= '<br />' . _("Min temp last 24 hours: ") . round($value) . '&deg;' . Horde_String::upper($units['temp']);
                     break;
                 case 'sensors':
                     foreach ($value as $sensor) {
                         $remarks .= '<br />' . _("Sensor: ") . $sensor;
                     }
                     break;
                 default:
                     $other .= '<br />' . $value;
                     break;
             }
         }
         $html .= $this->_row(_("Remarks"), $remarks . $other);
     }
     // TAF
     if (!empty($this->_params['taf'])) {
         $taf = $metar->getForecast($this->_params['location']);
         if (!is_a($taf, 'PEAR_Error')) {
             $forecast = '<table width="100%" cellspacing="0">';
             $forecast .= '<tr><td class="control" colspan="2"><center><strong>' . _("Forecast (TAF)") . '</strong></td></tr></table>';
             $forecast .= '<strong>Valid: </strong>' . $taf['validFrom'] . ' - ' . $taf['validTo'] . '<br /><br />';
             $item = 0;
             foreach ($taf['time'] as $time => $entry) {
                 $item++;
                 $forecast .= '<table width="100%" cellspacing="0">';
                 $forecast .= '<tr class="item' . $item % 2 . '">';
                 $forecast .= '<td align="center" width="50">' . $time . '</td><td><strong>Wind:</strong> ';
                 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 .= '<br />';
                 }
                 if (isset($entry['temperatureLow']) || isset($entry['temperatureHigh'])) {
                     $forecast .= '<strong>Temperature</strong>';
                     if (isset($entry['temperatureLow'])) {
                         $forecast .= '<strong> Low:</strong>';
                         $forecast .= $entry['temperatureLow'];
                     }
                     if (isset($entry['temperatureHigh'])) {
                         $forecast .= '<strong> High:</strong>';
                         $forecast .= $entry['temperatureHigh'];
                     }
                     $forecast .= '<br />';
                 }
                 if (isset($entry['windshear'])) {
                     $forecast .= '<strong>Windshear:</strong>';
                     $forecast .= sprintf(_("from the %s (%s) at %s %s"), $entry['windshearDirection'], $entry['windshearDegrees'], $entry['windshearHeight'], $units['height']);
                     $forecast .= '<br />';
                 }
                 if (isset($entry['visibility'])) {
                     $forecast .= '<strong>Visibility:</strong> ';
                     $forecast .= strtolower($entry['visQualifier']) . ' ' . $entry['visibility'] . ' ' . $units['vis'];
                     $forecast .= '<br />';
                 }
                 if (isset($entry['condition'])) {
                     $forecast .= '<strong>Conditions:</strong> ';
                     $forecast .= $entry['condition'];
                     $forecast .= '<br />';
                 }
                 $forecast .= '<strong>Clouds:</strong> ';
                 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 .= '</td></tr>';
                 if (isset($entry['fmc'])) {
                     $item++;
                     foreach ($entry['fmc'] as $fmcEntry) {
                         $forecast .= '<tr class="item' . $item % 2 . '">';
                         $forecast .= '<td align="center" width="50">';
                         $forecast .= '* ' . $fmcEntry['from'] . '<br /> - ' . $fmcEntry['to'] . '</td>';
                         $forecast .= '<td>';
                         $forecast .= '<strong>Type: </strong>' . $fmcEntry['type'];
                         if (isset($fmcEntry['probability'])) {
                             $forecast .= ' <strong> Prob: </strong>' . $fmcEntry['probability'] . '%';
                         }
                         if (isset($fmcEntry['condition'])) {
                             $forecast .= ' <strong> Conditions: </strong>' . $fmcEntry['condition'];
                         }
                         if (isset($fmcEntry['clouds'])) {
                             $forecast .= ' <strong>Clouds:</strong>';
                             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 .= ' <strong>Visibility:</strong> ';
                             $forecast .= strtolower($fmcEntry['visQualifier']) . ' ';
                             $forecast .= $fmcEntry['visibility'] . ' ' . $units['vis'];
                         }
                         $forecast .= '</td></tr>';
                     }
                 }
             }
             $forecast .= '</table>';
             $html .= $forecast;
         }
     }
     return $html;
 }
コード例 #5
0
ファイル: metar.php プロジェクト: Artea/freebeer
 /**
  * The content to go in this block.
  *
  * @return string   The content
  */
 function _content()
 {
     if (!@(include_once 'Services/Weather.php')) {
         Horde::logMessage('The metar block will not work without Services_Weather from PEAR. Run pear install Services_Weather.', __FILE__, __LINE__, PEAR_LOG_ERR);
         return _("Metar block not available. Details have been logged for the administrator.");
     }
     global $conf;
     static $metarLocs;
     if (!isset($conf['sql'])) {
         return _("A database backend is required for this block.");
     }
     if (empty($this->_params['location'])) {
         return _("No location is set.");
     }
     if (!is_array($metarLocs)) {
         $metarLocs = $this->getParams();
     }
     require_once 'Services/Weather.php';
     $metar =& Services_Weather::service('METAR', array('debug' => 0));
     $dbString = $conf['sql']['phptype'] . '://';
     $dbString .= $conf['sql']['username'] . ':';
     $dbString .= $conf['sql']['password'] . '@';
     $dbString .= $conf['sql']['hostspec'] . '/';
     $dbString .= $conf['sql']['database'];
     $metar->setMetarDB($dbString);
     $metar->setUnitsFormat($this->_params['units']);
     $metar->setDateTimeFormat('M j, Y', 'H:i');
     $metar->setMetarSource('http');
     $units = $metar->getUnits(0, $this->_params['units']);
     $weather = $metar->getWeather($this->_params['location']);
     $html = '<table width="100%" border="0" cellpadding="0" cellspacing="0">' . '<tr><td class="control"><b>' . sprintf('%s, %s (%s)', $metarLocs['location']['values'][$this->_params['__location']][$this->_params['location']], $this->_params['__location'], $this->_params['location']) . '</td></tr></table><b>' . _("Last Updated:") . '</b> ' . $weather['update'] . '<br /><br />';
     // Wind.
     if (isset($weather['wind'])) {
         $html .= '<b>' . _("Wind:") . '</b> ';
         if ($weather['windDirection'] == 'Variable') {
             if (!empty($this->_params['knots'])) {
                 $html .= sprintf(_('%s at %s %s'), $weather['windDirection'], round($metar->convertSpeed($weather['wind'], $units['wind'], 'kt')), 'kt');
             } else {
                 $html .= sprintf(_('%s at %s %s'), $weather['windDirection'], round($weather['wind']), $units['wind']);
             }
         } elseif ($weather['windDegrees'] == '000' && $weather['wind'] == '0') {
             $html .= sprintf(_("calm"));
         } else {
             $html .= sprintf(_("from the %s (%s) at %s %s"), $weather['windDirection'], $weather['windDegrees'], empty($this->_params['knots']) ? round($weather['wind']) : round($metar->convertSpeed($weather['wind'], $units['wind'], 'kt')), empty($this->_params['knots']) ? $units['wind'] : 'kt');
         }
     }
     if (isset($weather['windGust'])) {
         if ($weather['windGust']) {
             if (!empty($this->_params['knots'])) {
                 $html .= sprintf(_(", gusting %s %s"), round($metar->convertSpeed($weather['windGust'], $units['wind'], 'kt')), 'kt');
             } else {
                 $html .= sprintf(_(", gusting %s %s"), round($weather['windGust']), $units['wind']);
             }
         }
     }
     if (isset($weather['windVariability'])) {
         if ($weather['windVariability']['from']) {
             $html .= sprintf(_(", variable from %s to %s"), $weather['windVariability']['from'], $weather['windVariability']['to']);
         }
     }
     // Visibility.
     if (isset($weather['visibility'])) {
         $html .= $this->_row(_("Visibility"), $weather['visibility'] . ' ' . $units['vis']);
     }
     // Temperature/DewPoint.
     if (isset($weather['temperature'])) {
         $html .= $this->_row(_("Temperature"), round($weather['temperature']) . '&deg;' . String::upper($units['temp']));
     }
     if (isset($weather['dewPoint'])) {
         $html .= $this->_row(_("Dew Point"), round($weather['dewPoint']) . '&deg;' . String::upper($units['temp']));
     }
     if (isset($weather['feltTemperature'])) {
         $html .= $this->_row(_("Feels Like"), round($weather['feltTemperature']) . '&deg;' . String::upper($units['temp']));
     }
     // Pressure.
     if (isset($weather['pressure'])) {
         $html .= $this->_row(_("Pressure"), $weather['pressure'] . ' ' . $units['pres']);
     }
     // Humidity.
     if (isset($weather['humidity'])) {
         $html .= $this->_row(_("Humidity"), round($weather['humidity']) . '%');
     }
     // Clouds.
     if (isset($weather['clouds'])) {
         $clouds = '';
         foreach ($weather['clouds'] as $cloud) {
             $clouds .= '<br />';
             if (isset($cloud['height'])) {
                 $clouds .= sprintf(_("%s at %s ft"), $cloud['amount'], $cloud['height']);
             } else {
                 $clouds .= $cloud['amount'];
             }
         }
         $html .= $this->_row(_("Clouds"), $clouds);
     }
     // Conditions.
     if (isset($weather['condition'])) {
         $html .= $this->_row(_("Conditions"), $weather['condition']);
     }
     // Remarks.
     if (isset($weather['remark'])) {
         $remarks = '';
         $other = '';
         foreach ($weather['remark'] as $remark => $value) {
             switch ($remark) {
                 case 'seapressure':
                     $remarks .= '<br />' . _("Pressure at sea level: ") . $value . ' ' . $units['pres'];
                     break;
                 case 'precipitation':
                     foreach ($value as $precip) {
                         if (is_numeric($precip['amount'])) {
                             $remarks .= '<br />' . sprintf(_("Precipitation for last %s hour(s): "), $precip['hours']) . $precip['amount'] . ' ' . $units['rain'];
                         } else {
                             $remarks .= '<br />' . sprintf(_("Precipitation for last %s hour(s): "), $precip['hours']) . $precip['amount'];
                         }
                     }
                     break;
                 case 'snowdepth':
                     $remarks .= '<br />' . _("Snow depth: ") . $value . ' ' . $units['rain'];
                     break;
                 case 'snowequiv':
                     $remarks .= '<br />' . _("Snow equivalent in water: ") . $value . ' ' . $units['rain'];
                     break;
                 case 'sunduration':
                     $remarks .= '<br />' . sprintf(_("%s minutes"), $value);
                     break;
                 case '1htemp':
                     $remarks .= '<br />' . _("Temp for last hour: ") . round($value) . '&deg;' . String::upper($units['temp']);
                     break;
                 case '1hdew':
                     $remarks .= '<br />' . _("Dew Point for last hour: ") . round($value) . '&deg;' . String::upper($units['temp']);
                     break;
                 case '6hmaxtemp':
                     $remarks .= '<br />' . _("Max temp last 6 hours: ") . round($value) . '&deg;' . String::upper($units['temp']);
                     break;
                 case '6hmintemp':
                     $remarks .= '<br />' . _("Min temp last 6 hours: ") . round($value) . '&deg;' . String::upper($units['temp']);
                     break;
                 case '24hmaxtemp':
                     $remarks .= '<br />' . _("Max temp last 24 hours: ") . round($value) . '&deg;' . String::upper($units['temp']);
                     break;
                 case '24hmintemp':
                     $remarks .= '<br />' . _("Min temp last 24 hours: ") . round($value) . '&deg;' . String::upper($units['temp']);
                     break;
                 case 'sensors':
                     foreach ($value as $sensor) {
                         $remarks .= '<br />' . _("Sensor: ") . $sensor;
                     }
                     break;
                 default:
                     $other .= '<br />' . $value;
                     break;
             }
         }
         $html .= $this->_row(_("Remarks"), $remarks . $other);
     }
     return $html;
 }
コード例 #6
0
// | This source file is subject to version 2.0 of the PHP license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at                              |
// | http://www.php.net/license/2_02.txt.                                 |
// | If you did not receive a copy of the PHP license and are unable to   |
// | obtain it through the world-wide-web, please send a note to          |
// | license@php.net so we can mail you a copy immediately.               |
// +----------------------------------------------------------------------+
// | Authors: Alexander Wirtz <*****@*****.**>                             |
// +----------------------------------------------------------------------+
//
// $Id: weather.com-basic.php,v 1.6 2004/05/07 14:41:36 eru Exp $
require_once "Services/Weather.php";
// Object initialization - error checking is important, because of
// handling exceptions such as missing PEAR modules
$weatherDotCom =& Services_Weather::service("WeatherDotCom", array("debug" => 2, "httpTimeout" => 30));
if (Services_Weather::isError($weatherDotCom)) {
    die("Error: " . $weatherDotCom->getMessage() . "\n");
}
// Set weather.com partner data
$weatherDotCom->setAccountData("<PartnerID>", "<LicenseKey>");
/* Erase comments to enable caching
$status = $weatherDotCom->setCache("file", array("cache_dir" => "/tmp/cache/"));
if (Services_Weather::isError($status)) {
    echo "Error: ".$status->getMessage()."\n";
}
*/
$weatherDotCom->setUnitsFormat("metric");
$weatherDotCom->setDateTimeFormat("d.m.Y", "H:i");
// First get code for location
$search = $weatherDotCom->searchLocation("Bonn, Germany");
コード例 #7
0
// the Cache manual / sourcecode!
$unitsFormat = "metric";
// The format the units are displayed in -
// metric, standard or some customization.
$dateFormat = "j. M Y";
// Set the format the date is displayed in
$timeFormat = "H:i";
//                    time
//-------------------------------------------------------------------------
// Load the Weather class
require_once "Services/Weather.php";
// Load the scripts needed for sunrise/-set calculation
include_once "php_sunrise_sunset.php";
// Object initialization - error checking is important, because of
// handling exceptions such as missing PEAR modules
$metar =& Services_Weather::service("Metar");
if (Services_Weather::isError($metar)) {
    die("Error: " . $metar->getMessage() . "\n");
}
// Set parameters for DB access, needed for location searches
$metar->setMetarDB($dsn);
if (Services_Weather::isError($metar)) {
    echo "Error: " . $metar->getMessage() . "\n";
}
// Initialize caching
if (strlen($cacheType)) {
    $status = $metar->setCache($cacheType, $cacheOpt);
    if (Services_Weather::isError($status)) {
        echo "Error: " . $status->getMessage() . "\n";
    }
}
コード例 #8
0
 /**
  * serendipity_plugin_weather::generate_content()
  *
  * @param  $title
  * @return
  */
 function generate_content(&$title)
 {
     global $serendipity;
     $title = $this->get_config('title');
     $metar_site = $this->get_config('metar', 'EDDK');
     $timezone = $this->get_config('timezone', 0);
     $unitString = $this->get_config('units', 'metric');
     $caching = $this->get_config('caching', 0);
     $directory = $this->get_config('cache_directory', '/tmp');
     $pixdir = $this->get_config('pixel_directory');
     if (@(include_once 'Services/Weather.php')) {
         $metar =& Services_Weather::service('METAR', array('debug' => 0));
         if (Services_Weather::isError($metar)) {
             echo 'Weather Error: ' . $metar->getMessage();
         }
         // Set the unit format for the data
         $metar->setUnitsFormat($unitString);
         // Set the time/date format
         // Do we have the date/time format set somewhere in s9y? then we should take this here
         // $metar->setDateTimeFormat('d.m.Y', 'H:i');
         //    $metar_data->setDateTimeFormat('j M Y', 'H:i');
         if ($caching) {
             if (@(include_once "Cache.php")) {
                 $status = $metar->setCache('file', array('cache_dir' => $serendipity['serendipityPath'] . $directory));
             } else {
                 echo 'Caching is enabled but PEAR:Cache does not seem to be installed.';
             }
         }
         if (Services_Weather::isError($status)) {
             echo 'Error: ' . $status->getMessage();
         }
         switch ($unitString) {
             case "metric":
                 $units = array('wind' => 'km/h', 'vis' => 'km', 'height' => 'km', 'temp' => '&deg;C', 'pres' => 'mb', 'rain' => 'mm');
                 break;
             case "standard":
                 $units = array('wind' => 'mph', 'vis' => 'mi', 'height' => 'mi', 'temp' => '&deg;F', 'pres' => 'in', 'rain' => 'in');
                 break;
         }
         $weather_data = $metar->getWeather($metar_site);
         if (Services_Weather::isError($weather_data)) {
             echo 'Error: ' . $weather_data->getMessage();
         }
         $location_data = $metar->getLocation($metar_site);
         if (Services_Weather::isError($location_data)) {
             echo 'Error: ' . $location_data->getMessage();
         }
         $forecast_data = $metar->getForecast($metar_site);
         if (Services_Weather::isError($forecast_data)) {
             echo 'Error: ' . $forecast_data->getMessage();
         }
         // Do all that icon-stuff
         // FIXXME: URL-Prefix
         $windDir = $weather_data["windDirection"];
         switch ($windDir) {
             case 'S':
                 $windDirIcon = $pixdir . '/sss.png';
                 $windDir = PLUGIN_SIDEBAR_WEATHER_DATA_S;
                 break;
             case 'SSW':
                 $windDirIcon = $pixdir . '/ssw.png';
                 $windDir = PLUGIN_SIDEBAR_WEATHER_DATA_SSW;
                 break;
             case 'SSE':
                 $windDirIcon = $pixdir . '/sse.png';
                 $windDir = PLUGIN_SIDEBAR_WEATHER_DATA_SSE;
                 break;
             case 'SW':
                 $windDirIcon = $pixdir . '/sw.png';
                 $windDir = PLUGIN_SIDEBAR_WEATHER_DATA_SW;
                 break;
             case 'WSW':
                 $windDirIcon = $pixdir . '/sww.png';
                 $windDir = PLUGIN_SIDEBAR_WEATHER_DATA_WSW;
                 break;
             case 'E':
                 $windDirIcon = $pixdir . '/eee.png';
                 $windDir = PLUGIN_SIDEBAR_WEATHER_DATA_E;
                 break;
             case 'ESE':
                 $windDirIcon = $pixdir . '/see.png';
                 $windDir = PLUGIN_SIDEBAR_WEATHER_DATA_ESE;
                 break;
             case 'ENE':
                 $windDirIcon = $pixdir . '/nee.png';
                 $windDir = PLUGIN_SIDEBAR_WEATHER_DATA_ENE;
                 break;
             case 'N':
                 $windDirIcon = $pixdir . '/nnn.png';
                 $windDir = PLUGIN_SIDEBAR_WEATHER_DATA_N;
                 break;
             case 'NNW':
                 $windDirIcon = $pixdir . '/nnw.png';
                 $windDir = PLUGIN_SIDEBAR_WEATHER_DATA_NNW;
                 break;
             case 'NNE':
                 $windDirIcon = $pixdir . '/nne.png';
                 $windDir = PLUGIN_SIDEBAR_WEATHER_DATA_NNE;
                 break;
             case 'NW':
                 $windDirIcon = $pixdir . '/nw.png';
                 $windDir = PLUGIN_SIDEBAR_WEATHER_DATA_NW;
                 break;
             case 'NE':
                 $windDirIcon = $pixdir . '/ne.png';
                 $windDir = PLUGIN_SIDEBAR_WEATHER_DATA_NE;
                 break;
             case 'SE':
                 $windDirIcon = $pixdir . '/se.png';
                 $windDir = PLUGIN_SIDEBAR_WEATHER_DATA_SE;
                 break;
             case 'W':
                 $windDirIcon = $pixdir . '/www.png';
                 $windDir = PLUGIN_SIDEBAR_WEATHER_DATA_W;
                 break;
             case 'WNW':
                 $windDirIcon = $pixdir . '/nww.png';
                 $windDir = PLUGIN_SIDEBAR_WEATHER_DATA_WNW;
                 break;
             case 'Variable':
                 $windDirIcon = $pixdir . '/vrb.gif';
                 $windDir = PLUGIN_SIDEBAR_WEATHER_DATA_V;
                 break;
             default:
                 $windDirIcon = $pixdir . '/wind_nodata.png';
                 $windDir = "No recorded data.";
         }
         // Turn the GMT time from the update into a local time
         $localTime = date('j M Y H:i', strtotime($weather_data['updateRaw']) + 3600 * $timezone);
         // Get local hour to determing if it is night
         $hour = date('H', strtotime($weather_data['updateRaw']) + 3600 * $tz);
         if ($hour > 18 || $hour < 6) {
             $night = 'n_';
         } else {
             $night = '';
         }
         // Handle cloud data
         // We could be dealing with cloud at several levels, so find the heaviest
         // cover and go with that.
         $cloudData = $weather_data['clouds'];
         // See if we are dealing with an array of arrays or some information
         $cloudKeys = array_keys($cloudData);
         $testKey = $cloudKeys[0];
         if (!is_array($cloudData["{$testKey}"])) {
             // we have information
             $amount = $cloudData['amount'];
         } else {
             // we have information on several levels - get highest
             $key = count($cloudKeys) - 1;
             $useArray = $cloudData[$key];
             $amount = $useArray['amount'];
         }
         switch ($amount) {
             case "Clear Below":
             case "clear sky":
             case "no significant cloud":
             case "clear below 12,000 ft":
             case "vertical visibility":
                 $cloudLevel = "0cloud";
                 break;
             case "few":
             case "scattered":
                 $cloudLevel = "1cloud";
                 break;
             case "Cumulonimbus":
                 $cloudLevel = "2cloud";
                 break;
             case "Towering Cumulus":
             case "broken":
                 $cloudLevel = "3cloud";
                 break;
             case "overcast":
                 $cloudLevel = "4cloud";
                 $night = "";
                 break;
             default:
                 $cloudLevel = "0cloud";
         }
         // Determine weather conditions (rain, snow etc);
         // We need some way to translate this
         $conditions = $weather_data["condition"];
         switch ($cloudLevel) {
             case "0cloud":
                 if (strstr($conditions, "fog") !== FALSE) {
                     $condUse = "_fog";
                 } else {
                     $condUse = "";
                 }
                 break;
             case "1cloud":
                 if (strstr($conditions, "fog") !== FALSE) {
                     $condUse = "_fog";
                 } elseif (strstr($conditions, "rain") !== FALSE && strstr($conditions, "light") !== FALSE) {
                     $condUse = "_lightrain";
                 } elseif (strstr($conditions, "rain") !== FALSE && strstr($conditions, "heavy") !== FALSE) {
                     $condUse = "_heavyrain";
                 } elseif (strstr($conditions, "rain") !== FALSE) {
                     $condUse = "_modrain";
                 } else {
                     $condUse = "_norain";
                 }
                 break;
             case "2cloud":
                 if (strstr($conditions, "fog") !== FALSE) {
                     $condUse = "_fog";
                 } elseif (strstr($conditions, "rain") !== FALSE && strstr($conditions, "light") !== FALSE) {
                     $condUse = "_lightrain";
                 } elseif (strstr($conditions, "rain") !== FALSE && strstr($conditions, "heavy") !== FALSE) {
                     $condUse = "_heavyrain";
                 } elseif (strstr($conditions, "rain") !== FALSE) {
                     $condUse = "_modrain";
                 } elseif (strstr($conditions, "snow") !== FALSE) {
                     $condUse = "_snow";
                 } elseif (strstr($conditions, "thunderstorm") !== FALSE) {
                     $condUse = "_thunders";
                 } else {
                     $condUse = "_norain";
                 }
                 break;
             case "3cloud":
                 if (strstr($conditions, "fog") !== FALSE) {
                     $condUse = "_fog";
                 } elseif (strstr($conditions, "rain") !== FALSE && strstr($conditions, "light") !== FALSE) {
                     $condUse = "_lightrain";
                 } elseif (strstr($conditions, "rain") !== FALSE && strstr($conditions, "heavy") !== FALSE) {
                     $condUse = "_heavyrain";
                 } elseif (strstr($conditions, "rain") !== FALSE) {
                     $condUse = "_modrain";
                 } elseif (strstr($conditions, "snow") !== FALSE) {
                     $condUse = "_snow";
                 } elseif (strstr($conditions, "thunderstorm") !== FALSE) {
                     $condUse = "_thunders";
                 } elseif (strstr($conditions, "hail") !== FALSE) {
                     $condUse = "_hail";
                 } else {
                     $condUse = "_norain";
                 }
                 break;
             case "4cloud":
                 if (strstr($conditions, "fog") !== FALSE) {
                     $condUse = "_fog";
                 } elseif (strstr($conditions, "rain") !== FALSE && strstr($conditions, "light") !== FALSE) {
                     $condUse = "_lightrain";
                 } elseif (strstr($conditions, "rain") !== FALSE && strstr($conditions, "heavy") !== FALSE) {
                     $condUse = "_heavyrain";
                 } elseif (strstr($conditions, "rain") !== FALSE) {
                     $condUse = "_modrain";
                 } elseif (strstr($conditions, "snow") !== FALSE && strstr($conditions, "light") !== FALSE) {
                     $condUse = "_lightsnow";
                 } elseif (strstr($conditions, "snow") !== FALSE && strstr($conditions, "heavy") !== FALSE) {
                     $condUse = "_heavysnow";
                 } elseif (strstr($conditions, "snow") !== FALSE) {
                     $condUse = "_snow";
                 } elseif (strstr($conditions, "thunderstorm") !== FALSE) {
                     $condUse = "_thunders";
                 } elseif (strstr($conditions, "hail") !== FALSE && strstr($conditions, "light") !== FALSE) {
                     $condUse = "_lighthail";
                 } elseif (strstr($conditions, "hail") !== FALSE && strstr($conditions, "heavy") !== FALSE) {
                     $condUse = "_heavyhail";
                 } elseif (strstr($conditions, "hail") !== FALSE) {
                     $condUse = "_hail";
                 } else {
                     $condUse = "_norain";
                 }
                 break;
             default:
                 $condUse = "_norain";
         }
         // Construct icon name
         $conditionIcon = $pixdir . '/' . $night . $cloudLevel . $condUse . '.png';
         $content = '';
         $content .= '<img src="' . $conditionIcon . '" alt="" /><br />' . $conditions . '<br />';
         // FIXXME: Translate the Winddirection
         $content .= '<dl><dt>' . PLUGIN_SIDEBAR_WEATHER_DATA_WINDDIRECTION . '</dt><dd><img src="' . $windDirIcon . '" alt="" /><dd>' . $windDir . ' at <dd>' . $weather_data["wind"] . ' ' . $units['wind'] . '</dd></dt>';
         $content .= '<dt>' . PLUGIN_SIDEBAR_WEATHER_DATA_TEMPERATURE . '</dt><dd>' . $weather_data["temperature"] . ' ' . $units['temp'] . '</dd>';
         $content .= '<dt>' . PLUGIN_SIDEBAR_WEATHER_DATA_FELT_TEMPERATURE . '</dt><dd>' . $weather_data["feltTemperature"] . ' ' . $units['temp'] . '</dd>';
         $content .= '<dt>' . PLUGIN_SIDEBAR_WEATHER_DATA_HUMIDITY . '</dt><dd>' . $weather_data["humidity"] . ' ' . '%</dd>';
         $content .= '<dt>' . PLUGIN_SIDEBAR_WEATHER_DATA_PRESSURE . '</dt><dd>' . $weather_data['pressure'] . ' ' . $units['pres'] . '</dd>';
         $content .= '<dt>' . PLUGIN_SIDEBAR_WEATHER_DATA_VISIBILITY . '</dt><dd>' . $weather_data["visibility"] . ' ' . $units['vis'] . '</dd>';
         $content .= '<dt>' . PLUGIN_SIDEBAR_WEATHER_DATA_UPDATE . '</dt><dd>' . $localTime . '</dd></dl>';
     } else {
         $content = 'Loading the  <a href=http://pear.php.net/package/Services_Weather/>PEAR Services/Weather module</a> failed.  Please insure that the module is installed.';
     }
     echo $content;
 }
コード例 #9
0
ファイル: weatherdotcom.php プロジェクト: Artea/freebeer
 /**
  * The content to go in this block.
  *
  * @return string   The content
  */
 function _content()
 {
     if (!@(include_once 'Services/Weather.php')) {
         Horde::logMessage('The weather.com block will not work without Services_Weather from PEAR. Run pear install Services_Weather.', __FILE__, __LINE__, PEAR_LOG_ERR);
         return _("The weather.com block is not available.");
     }
     global $conf;
     $cacheDir = Horde::getTempDir();
     $html = '';
     if (empty($this->_params['location'])) {
         return _("No location is set.");
     }
     $weatherDotCom =& Services_Weather::service("WeatherDotCom");
     $weatherDotCom->setAccountData(isset($conf['weatherdotcom']['partner_id']) ? $conf['weatherdotcom']['partner_id'] : '', isset($conf['weatherdotcom']['license_key']) ? $conf['weatherdotcom']['license_key'] : '');
     if (!$cacheDir) {
         return PEAR::raiseError(_("No temporary directory available for cache."), 'horde.error');
     } else {
         $weatherDotCom->setCache("file", array("cache_dir" => $cacheDir . '/'));
     }
     $weatherDotCom->setDateTimeFormat("m.d.Y", "H:i");
     $weatherDotCom->setUnitsFormat($this->_params['units']);
     $units = $weatherDotCom->getUnitsFormat();
     // If the user entered a zip code for the location, no need to
     // search (weather.com accepts zip codes as location IDs).
     // The location ID should already have been validated in
     // getParams.
     $search = preg_match('/\\b(?:\\d{5}(-\\d{5})?)|(?:[A-Z]{4}\\d{4})\\b/', $this->_params['location'], $matches) ? $matches[0] : $weatherDotCom->searchLocation($this->_params['location']);
     if (is_a($search, 'PEAR_Error')) {
         return $search->getmessage();
     }
     if (is_array($search)) {
         // Several locations returned due to imprecise location parameter
         $html = _("Several locations possible with the parameter: ");
         $html .= $this->_params['location'];
         $html .= "<br/><ul>";
         foreach ($search as $id_weather => $real_location) {
             $html .= "<li>{$real_location} ({$id_weather})</li>\n";
         }
         $html .= "</ul>";
         return $html;
     }
     $location = $weatherDotCom->getLocation($search);
     if (is_a($location, 'PEAR_Error')) {
         return $location->getmessage();
     }
     $weather = $weatherDotCom->getWeather($search);
     if (is_a($weather, 'PEAR_Error')) {
         return $weather->getmessage();
     }
     $forecast = $weatherDotCom->getForecast($search, $this->_params['days']);
     if (is_a($forecast, 'PEAR_Error')) {
         return $forecast->getmessage();
     }
     // Location and local time.
     $html .= "<table width=100%><tr><td class=control>";
     $html .= '<b>' . $location['name'] . '</b>' . ' local time ' . $location['time'];
     $html .= "</b></td></tr></table>";
     // Sunrise/sunset.
     $html .= '<b>' . _("Sunrise: ") . '</b>' . Horde::img('block/sunrise/sunrise.gif', _("Sunrise")) . $location['sunrise'];
     $html .= ' <b>' . _("Sunset: ") . '</b>' . Horde::img('block/sunrise/sunset.gif', _("Sunset")) . $location['sunset'];
     // Temperature.
     $html .= '<br /><b>' . _("Temperature: ") . '</b>';
     $html .= $weather['temperature'] . '&deg;' . String::upper($units['temp']);
     // Dew point.
     $html .= ' <b>' . _("Dew point: ") . '</b>';
     $html .= $weather['dewPoint'] . '&deg;' . String::upper($units['temp']);
     // Feels like temperature.
     $html .= ' <b>' . _("Feels like: ") . '</b>';
     $html .= $weather['feltTemperature'] . '&deg;' . String::upper($units['temp']);
     // Pressure and trend.
     $html .= '<br /><b>' . _("Pressure: ") . '</b>';
     $html .= number_format($weather['pressure'], 2) . ' ' . $units['pres'];
     $html .= _(" and ") . $weather['pressureTrend'];
     // Wind.
     $html .= '<br /><b>' . _("Wind: ") . '</b>';
     if ($weather['windDirection'] == 'VAR') {
         $html .= _("Variable");
     } elseif ($weather['windDirection'] == 'CALM') {
         $html .= _("Calm");
     } else {
         $html .= _("From the ") . $weather['windDirection'];
         $html .= ' (' . $weather['windDegrees'] . ')';
     }
     $html .= _(" at ") . $weather['wind'] . ' ' . $units['wind'];
     // Humidity.
     $html .= '<br /><b>' . _("Humidity: ") . '</b>';
     $html .= $weather['humidity'] . '%';
     // Visibility.
     $html .= ' <b>' . _("Visibility: ") . '</b>';
     $html .= $weather['visibility'] . (is_numeric($weather['visibility']) ? ' ' . $units['vis'] : '');
     // UV index.
     $html .= ' <b>' . _("U.V. index: ") . '</b>';
     $html .= $weather['uvIndex'] . ' - ' . $weather['uvText'];
     // Current condition.
     $html .= '<br /><b>' . _("Current condition: ") . '</b>' . Horde::img('block/weatherdotcom/32x32/' . $weather['conditionIcon'] . '.png', _(String::lower($weather['condition'])), 'align="middle"');
     $html .= ' ' . $weather['condition'];
     // Do the forecast now.
     $html .= '<table border="0" width="100%" align="center"><tr>';
     $html .= '<tr><td class="control" colspan="' . $this->_params['days'] * 2 . '"><center><b>' . $this->_params['days'] . '-day forecast</b></center></td></tr><tr>';
     $futureDays = 0;
     foreach ($forecast['days'] as $which => $day) {
         $html .= '<td colspan="2" align="center">';
         // Day name.
         $html .= '<b>';
         if ($which == 0) {
             $html .= _("Today");
         } elseif ($which == 1) {
             $html .= _("Tomorrow");
         } else {
             $html .= strftime('%A', mktime(0, 0, 0, date('m'), date('d') + $futureDays, date('Y')));
         }
         $html .= '</b><br />';
         $futureDays++;
         // High/low temp. If after 2 p.m. local time, the "day"
         // forecast is no longer valid.
         if ($which > 0 || $which == 0 && strtotime($location['time']) < strtotime('14:00')) {
             $html .= '<span style="color:red">' . $day['tempertureHigh'] . '&deg;' . String::upper($units['temp']) . '</span>/';
         }
         $html .= '<span style="color:blue">' . $day['temperatureLow'] . '&deg;' . String::upper($units['temp']) . '</span>';
         $html .= '</td>';
     }
     $html .= '</tr><tr>';
     $elementWidth = 100 / ($this->_params['days'] * 2);
     foreach ($forecast['days'] as $which => $day) {
         // Day forecast.
         $html .= '<td align="center" valign="top" width="' . $elementWidth . '%">';
         if ($which > 0 || $which == 0 && strtotime($location['time']) < strtotime('14:00')) {
             $html .= '<b><i>Day</i></b><br />';
             $html .= Horde::img('block/weatherdotcom/23x23/' . $day['day']['conditionIcon'] . '.png', $day['day']['condition']);
             $html .= '<br />' . $day['day']['condition'];
         } else {
             $html .= '&nbsp;';
         }
         $html .= '</td>';
         // Night forecast.
         $html .= '<td align="center" valign="top" width="' . $elementWidth . '%">';
         $html .= '<b><i>Night</i></b><br />';
         $html .= Horde::img('block/weatherdotcom/23x23/' . $day['night']['conditionIcon'] . '.png', $day['night']['condition']);
         $html .= '<br />' . $day['night']['condition'];
         $html .= '</td>';
     }
     $html .= '</tr></table>';
     // Display a bar at the bottom of the block with the required
     // attribution to weather.com and the logo, both linked to
     // weather.com with the partner ID.
     $html .= '<table width=100%><tr>';
     $html .= '<td align=right class=control>';
     $html .= 'Weather data provided by ';
     $html .= Horde::link('http://www.weather.com/?prod=xoap&par=' . $weatherDotCom->_partnerID, 'weather.com', '', '_blank', '', 'weather.com');
     $html .= '<i>weather.com</i>&reg; ';
     $html .= Horde::img('block/weatherdotcom/32x32/TWClogo_32px.png', 'weather.com logo');
     $html .= '</a></td></tr></table>';
     return $html;
 }