diff --git a/curweather/README.md b/curweather/README.md
new file mode 100644
index 000000000..ff43f2489
--- /dev/null
+++ b/curweather/README.md
@@ -0,0 +1,29 @@
+Current Weather
+===============
+
+If activated by your user this addon adds a widget to the users network tab
+sidebar showing current weather informations (temperature, relative humidity,
+wind conditions and preassure) from [OpenWeatherMap](http://openweathermap.org).
+The user can configure the location as e.g. *Berlin,DE* or the zip code "14476,DE".
+
+The language for the request at OpenWeatherMap is set to the UI language of
+friendica. If the string for the description of the current weather conditions
+is available in this language depends on OpenWeatherMap, fallback is english.
+
+**You should get an APPID from OpenWeatherMap if you want to use this widget.**
+You can register [here](http://openweathermap.org/register).
+
+Credits
+-------
+
+* Tony Baldwin wrote the original addon for Friendica
+* Fabio Comuni
+* Tobias Diekershoff switched the sources to OpenWeatherMap after the original
+ provider turned off support for locations outside of the USA.
+
+Known Issues
+------------
+
+* Localization does not work (Jul 15) data requested via XML are EN only but
+ have moew information available compared to data requested via JSON which is
+ available in other languages as well. Right now we use the XML dataset
diff --git a/curweather/curweather.css b/curweather/curweather.css
index 6c1279634..69574ff07 100644
--- a/curweather/curweather.css
+++ b/curweather/curweather.css
@@ -1,10 +1,11 @@
-
-#curtemp-settings-label, #curtemp-location-label, #curtemp-enable-label {
- float: left;
- width: 200px;
- margin-bottom: 25px;
+#curweather-network img {
+ float: left;
+ margin: 30px 10px;
}
-#curtemp-network {
- float: left;
+ul.curweather-details li {
+ list-type: none;
+}
+p.curweather-footer {
+ font-size: 0.8em;
}
diff --git a/curweather/curweather.php b/curweather/curweather.php
index 67d5939e7..59d7e3788 100644
--- a/curweather/curweather.php
+++ b/curweather/curweather.php
@@ -1,29 +1,78 @@
- Find the location code for the station or airport nearest you here.
- * Version: 1.0
+ * Description: Shows current weather conditions for user's location on their network page.
+ * Version: 1.1
* Author: Tony Baldwin
* Author: Fabio Comuni
+ * Author: Tobias Diekershoff
*
*/
-require_once('addon/curweather/getweather.php');
+
+require_once('include/network.php');
+require_once("mod/proxy.php");
+require_once('include/text.php');
+
+// get the weather data from OpenWeatherMap
+function getWeather( $loc, $units='metric', $lang='en', $appid='', $cachetime=0) {
+ $url = "http://api.openweathermap.org/data/2.5/weather?q=".$loc."&appid=".$appid."&lang=".$lang."&units=".$units."&mode=xml";
+ $cached = Cache::get('curweather'.md5($url));
+ $now = new DateTime();
+ if (!is_null($cached)) {
+ $cdate = get_pconfig(local_user(), 'curweather', 'last');
+ $cached = unserialize($cached);
+ if ($cdate + $cachetime > $now->getTimestamp()) {
+ return $cached;
+ }
+ }
+ try {
+ $res = new SimpleXMLElement(fetch_url($url));
+ } catch (Exception $e) {
+ info(t('Error fetching weather data.\nError was: '.$e->getMessage()));
+ return false;
+ }
+ if ((string)$res->temperature['unit']==='metric') {
+ $tunit = '°C';
+ $wunit = 'm/s';
+ } else {
+ $tunit = '°F';
+ $wunit = 'mph';
+ }
+ if ( trim((string)$res->weather['value']) == trim((string)$res->clouds['name']) ) {
+ $desc = (string)$res->clouds['name'];
+ } else {
+ $desc = (string)$res->weather['value'].', '.(string)$res->clouds['name'];
+ }
+ $r = array(
+ 'city'=> (string) $res->city['name'][0],
+ 'country' => (string) $res->city->country[0],
+ 'lat' => (string) $res->city->coord['lat'],
+ 'lon' => (string) $res->city->coord['lon'],
+ 'temperature' => (string) $res->temperature['value'][0].$tunit,
+ 'pressure' => (string) $res->pressure['value'].(string)$res->pressure['unit'],
+ 'humidity' => (string) $res->humidity['value'].(string)$res->humidity['unit'],
+ 'descripion' => $desc,
+ 'wind' => (string)$res->wind->speed['name'].' ('.(string)$res->wind->speed['value'].$wunit.')',
+ 'update' => (string)$res->lastupdate['value'],
+ 'icon' => (string)$res->weather['icon']
+ );
+ set_pconfig(local_user(), 'curweather', 'last', $now->getTimestamp());
+ Cache::set('curweather'.md5($url), serialize($r));
+ return $r;
+}
function curweather_install() {
register_hook('network_mod_init', 'addon/curweather/curweather.php', 'curweather_network_mod_init');
register_hook('plugin_settings', 'addon/curweather/curweather.php', 'curweather_plugin_settings');
register_hook('plugin_settings_post', 'addon/curweather/curweather.php', 'curweather_plugin_settings_post');
-
}
function curweather_uninstall() {
unregister_hook('network_mod_init', 'addon/curweather/curweather.php', 'curweather_network_mod_init');
unregister_hook('plugin_settings', 'addon/curweather/curweather.php', 'curweather_plugin_settings');
unregister_hook('plugin_settings_post', 'addon/curweather/curweather.php', 'curweather_plugin_settings_post');
-
}
-
function curweather_network_mod_init(&$fk_app,&$b) {
if(! intval(get_pconfig(local_user(),'curweather','curweather_enable')))
@@ -31,27 +80,56 @@ function curweather_network_mod_init(&$fk_app,&$b) {
$fk_app->page['htmlhead'] .= '' . "\r\n";
- // 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 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 = 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 = '