- // the getweather file does all the work here
- // the $rpt value is needed for location
- // which getweather uses to fetch the weather data for weather and temp
- $rpt = get_pconfig(local_user(), 'curweather', 'curweather_loc');
- $wxdata = GetWeather::get($rpt);
- $temp = $wxdata['TEMPERATURE_STRING'];
- $weather = $wxdata['WEATHER'];
- $rhumid = $wxdata['RELATIVE_HUMIDITY'];
- $pressure = $wxdata['PRESSURE_STRING'];
- $wind = $wxdata['WIND_STRING'];
- $curweather = '<div id="curweather-network" class="widget">
- <div class="title tool">
- <h4>'.t("Current Weather").'</h4></div>';
-
- $curweather .= "Weather: $weather<br />
- Temperature: $temp<br />
- Relative Humidity: $rhumid<br />
- Pressure: $pressure<br />
- Wind: $wind";
-
- $curweather .= '</div><div class="clear"></div>';
+ // $rpt value is needed for location
+ // $lang will be taken from the browser session to honour user settings
+ // TODO $lang does not work if the default settings are used
+ // and not all response strings are translated
+ // $units can be set in the settings by the user
+ // $appid is configured by the admin in the admin panel
+ // those parameters will be used to get: cloud status, temperature, preassure
+ // and relative humidity for display, also the relevent area of the map is
+ // linked from lat/log of the reply of OWMp
+ $rpt = PConfig::get(local_user(), 'curweather', 'curweather_loc');
+
+
+ // set the language to the browsers language and use metric units
+ $lang = $_SESSION['language'];
+ $units = PConfig::get( local_user(), 'curweather', 'curweather_units');
+ $appid = Config::get('curweather','appid');
+ $cachetime = intval(Config::get('curweather','cachetime'));
+ if ($units==="")
+ $units = 'metric';
+ $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, array(
+ '$title' => 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' => array('caption'=>t('Relative Humidity'), 'val'=>$res['humidity']),
+ '$pressure' => array('caption'=>t('Pressure'), 'val'=>$res['pressure']),
+ '$wind' => array('caption'=>t('Wind'), 'val'=> $res['wind']),
+ '$lastupdate' => t('Last Updated').': '.$res['update'].'UTC',
+ '$databy' => t('Data by'),
+ '$showonmap' => t('Show on map')
+ ));
+ } else {
+ $t = get_markup_template('widget-error.tpl', 'addon/curweather/');
+ $curweather = replace_macros( $t, array(
+ '$problem' => t('There was a problem accessing the weather data. But have a look'),
+ '$rpt' => $rpt,
+ '$atOWM' => t('at OpenWeatherMap')
+ ));
+ }