[curweather] Only shown notice about unavailable weather once per session. (#653)

* [curweather] Only shown notice about unavailable weather once per session.

* Fix even more whitespace.

As requested by @MrPetovan.

* [curweather] Reset session's curweather_notice_shown when weather available again.
pull/600/merge
Andreas Neustifter 2018-07-20 21:58:53 +02:00 committed by Hypolite Petovan
parent aa1a542396
commit 81e57250e8
2 changed files with 120 additions and 108 deletions

View File

@ -34,9 +34,13 @@ function getWeather( $loc, $units='metric', $lang='en', $appid='', $cachetime=0)
try { try {
$res = new SimpleXMLElement(Network::fetchUrl($url)); $res = new SimpleXMLElement(Network::fetchUrl($url));
} catch (Exception $e) { } catch (Exception $e) {
info(L10n::t('Error fetching weather data.\nError was: '.$e->getMessage())); if (!$_SESSION['curweather_notice_shown']) {
info(L10n::t('Error fetching weather data. Error was: '.$e->getMessage()));
$_SESSION['curweather_notice_shown'] = true;
}
return false; return false;
} }
unset($_SESSION['curweather_notice_shown']);
if ((string)$res->temperature['unit']==='metric') { if ((string)$res->temperature['unit']==='metric') {
$tunit = '°C'; $tunit = '°C';
$wunit = 'm/s'; $wunit = 'm/s';
@ -98,7 +102,6 @@ function curweather_network_mod_init(&$fk_app,&$b) {
// linked from lat/log of the reply of OWMp // linked from lat/log of the reply of OWMp
$rpt = PConfig::get(local_user(), 'curweather', 'curweather_loc'); $rpt = PConfig::get(local_user(), 'curweather', 'curweather_loc');
// set the language to the browsers language and use metric units // set the language to the browsers language and use metric units
$lang = $_SESSION['language']; $lang = $_SESSION['language'];
$units = PConfig::get( local_user(), 'curweather', 'curweather_units'); $units = PConfig::get( local_user(), 'curweather', 'curweather_units');
@ -139,10 +142,8 @@ function curweather_network_mod_init(&$fk_app,&$b) {
} }
$fk_app->page['aside'] = $curweather.$fk_app->page['aside']; $fk_app->page['aside'] = $curweather.$fk_app->page['aside'];
} }
function curweather_addon_settings_post($a,$post) { function curweather_addon_settings_post($a,$post) {
if(! local_user() || (! x($_POST,'curweather-settings-submit'))) if(! local_user() || (! x($_POST,'curweather-settings-submit')))
return; return;
@ -153,7 +154,6 @@ function curweather_addon_settings_post($a,$post) {
info(L10n::t('Current Weather settings updated.') . EOL); info(L10n::t('Current Weather settings updated.') . EOL);
} }
function curweather_addon_settings(&$a,&$s) { function curweather_addon_settings(&$a,&$s) {
if(! local_user()) if(! local_user())
@ -184,8 +184,8 @@ function curweather_addon_settings(&$a,&$s) {
'$enabled' => [ 'curweather_enable', L10n::t('Show weather data'), $enable, ''] '$enabled' => [ 'curweather_enable', L10n::t('Show weather data'), $enable, '']
]); ]);
return; return;
} }
// Config stuff for the admin panel to let the admin of the node set a APPID // Config stuff for the admin panel to let the admin of the node set a APPID
// for accessing the API of openweathermap // for accessing the API of openweathermap
function curweather_addon_admin_post (&$a) { function curweather_addon_admin_post (&$a) {
@ -197,6 +197,7 @@ function curweather_addon_admin_post (&$a) {
info(L10n::t('Curweather settings saved.'.EOL)); info(L10n::t('Curweather settings saved.'.EOL));
} }
} }
function curweather_addon_admin (&$a, &$o) { function curweather_addon_admin (&$a, &$o) {
if(! is_site_admin()) if(! is_site_admin())
return; return;
@ -205,7 +206,18 @@ function curweather_addon_admin (&$a, &$o) {
$t = get_markup_template("admin.tpl", "addon/curweather/" ); $t = get_markup_template("admin.tpl", "addon/curweather/" );
$o = replace_macros ($t, [ $o = replace_macros ($t, [
'$submit' => L10n::t('Save Settings'), '$submit' => L10n::t('Save Settings'),
'$cachetime' => ['cachetime', L10n::t('Caching Interval'), $cachetime, L10n::t('For how long should the weather data be cached? Choose according your OpenWeatherMap account type.'), ['0'=>L10n::t('no cache'), '300'=>'5 '.L10n::t('minutes'), '900'=>'15 '.L10n::t('minutes'), '1800'=>'30 '.L10n::t('minutes'), '3600'=>'60 '.L10n::t('minutes')]], '$cachetime' => [
'cachetime',
L10n::t('Caching Interval'),
$cachetime,
L10n::t('For how long should the weather data be cached? Choose according your OpenWeatherMap account type.'), [
'0'=>L10n::t('no cache'),
'300'=>'5 '.L10n::t('minutes'),
'900'=>'15 '.L10n::t('minutes'),
'1800'=>'30 '.L10n::t('minutes'),
'3600'=>'60 '.L10n::t('minutes')
]
],
'$appid' => ['appid', L10n::t('Your APPID'), $appid, L10n::t('Your API key provided by OpenWeatherMap')] '$appid' => ['appid', L10n::t('Your APPID'), $appid, L10n::t('Your API key provided by OpenWeatherMap')]
]); ]);
} }

View File

@ -1 +1 @@
<div>{{$problem}} <a href="http://openweathermap.org/find?q={{$rpt}}">{{$atOWM}}</a>.</div> <div class="widget small">{{$problem}} <a href="http://openweathermap.org/find?q={{$rpt}}">{{$atOWM}}</a>.</div>