- // Get OpenWeatherMap object. Don't use caching (take a look into
- // Example_Cache.php to see how it works).
- //$owm = new OpenWeatherMap();
- $owm = new OpenWeatherMap(null, new CWCache(), $cachetime);
-
- try {
- $weather = $owm->getWeather($rpt, $units, $lang, $appid);
- $temp = $weather->temperature->getValue();
- if ( $units === 'metric') {
- $temp .= '°C';
- } else {
- $temp .= '°F';
- };
- $rhumid = $weather->humidity;
- $pressure = $weather->pressure;
- $wind = $weather->wind->speed->getDescription().', '.$weather->wind->speed . " " . $weather->wind->direction;
- $description = $weather->clouds->getDescription();
- $city = array(
- 'name'=>$weather->city->name,
- 'lon' =>$weather->city->lon,
- 'lat' =>$weather->city->lat
- );
- } catch(OWMException $e) {
- info ( 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').');
- } catch(\Exception $e) {
- info ('General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').');
+ $ok = true;
+
+ $res = getWeather($rpt, $units, $lang, $appid, $cachetime);
+ if ($res===false)
+ $ok = false;
+
+ if ($ok) {
+ $t = get_markup_template("widget.tpl", "addon/curweather/" );
+ $curweather = replace_macros ($t, [
+ '$title' => L10n::t("Current Weather"),
+ '$icon' => proxy_url('http://openweathermap.org/img/w/'.$res['icon'].'.png'),
+ '$city' => $res['city'],
+ '$lon' => $res['lon'],
+ '$lat' => $res['lat'],
+ '$description' => $res['descripion'],
+ '$temp' => $res['temperature'],
+ '$relhumidity' => ['caption'=>L10n::t('Relative Humidity'), 'val'=>$res['humidity']],
+ '$pressure' => ['caption'=>L10n::t('Pressure'), 'val'=>$res['pressure']],
+ '$wind' => ['caption'=>L10n::t('Wind'), 'val'=> $res['wind']],
+ '$lastupdate' => L10n::t('Last Updated').': '.$res['update'].'UTC',
+ '$databy' => L10n::t('Data by'),
+ '$showonmap' => L10n::t('Show on map')
+ ]);
+ } else {
+ $t = get_markup_template('widget-error.tpl', 'addon/curweather/');
+ $curweather = replace_macros( $t, [
+ '$problem' => L10n::t('There was a problem accessing the weather data. But have a look'),
+ '$rpt' => $rpt,
+ '$atOWM' => L10n::t('at OpenWeatherMap')
+ ]);