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

This commit is contained in:
Andreas Neustifter 2018-07-20 17:32:13 +02:00
parent 3050aef871
commit f539d055ea
2 changed files with 103 additions and 102 deletions

View file

@ -34,7 +34,10 @@ 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) {
if (!$_SESSION['curweather_notice_shown']) {
info(L10n::t('Error fetching weather data.\nError was: '.$e->getMessage())); info(L10n::t('Error fetching weather data.\nError was: '.$e->getMessage()));
$_SESSION['curweather_notice_shown'] = true;
}
return false; return false;
} }
if ((string)$res->temperature['unit']==='metric') { if ((string)$res->temperature['unit']==='metric') {
@ -98,7 +101,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 +141,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 +153,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())
@ -186,6 +185,7 @@ function curweather_addon_settings(&$a,&$s) {
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;

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>