]> git.mxchange.org Git - friendica-addons.git/blobdiff - curweather/curweather.php
FR update to the translation THX Hypolite Petovan
[friendica-addons.git] / curweather / curweather.php
index 93e9af9e2ae663a36e17d0ac13383ad1be55933b..e416ba67f832bd00b9a4898e54f326f497b2d1ab 100644 (file)
@@ -10,7 +10,8 @@
  */
 
 require_once('include/network.php');
-include_once('include/text.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) {
@@ -37,6 +38,11 @@ function getWeather( $loc, $units='metric', $lang='en', $appid='', $cachetime=0)
        $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],
@@ -45,12 +51,13 @@ function getWeather( $loc, $units='metric', $lang='en', $appid='', $cachetime=0)
        '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' => (string)$res->weather['value'].', '.(string)$res->clouds['name'],
+       'descripion' => $desc,
        'wind' => (string)$res->wind->speed['name'].' ('.(string)$res->wind->speed['value'].$wunit.')',
-       'update' => (string)$res->lastupdate['value']
+       '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));
+    Cache::set('curweather'.md5($url), serialize($r), CACHE_HOUR);
     return $r;
 }
 
@@ -73,9 +80,10 @@ function curweather_network_mod_init(&$fk_app,&$b) {
 
     $fk_app->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $fk_app->get_baseurl() . '/addon/curweather/curweather.css' . '" media="all" />' . "\r\n";
 
-    // the OpenWeatherMap-PHP-APIlib does all the work here
-    // the $rpt value is needed for location
+    // $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
@@ -101,6 +109,7 @@ function curweather_network_mod_init(&$fk_app,&$b) {
        $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'],
@@ -164,7 +173,7 @@ function curweather_plugin_settings(&$a,&$s) {
                '$noappidtext' => $noappidtext,
                '$info' => t('Enter either the name of your location or the zip code.'),
                '$curweather_loc' => array( 'curweather_loc', t('Your Location'), $curweather_loc, t('Identifier of your location (name or zip code), e.g. <em>Berlin,DE</em> or <em>14476,DE</em>.') ),
-               '$curweather_units' => array( 'curweather_units', t('Units'), $curweather_units, t('select if the temperatur should be displayed in °C or °F'), array('metric'=>'°C', 'imperial'=>'°F')),
+               '$curweather_units' => array( 'curweather_units', t('Units'), $curweather_units, t('select if the temperatur should be displayed in &deg;C or &deg;F'), array('metric'=>'°C', 'imperial'=>'°F')),
                '$enabled' => array( 'curweather_enable', t('Show weather data'), $enable, '')
            ));
        return;