forked from friendica/friendica-addons
[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.
This commit is contained in:
parent
aa1a542396
commit
81e57250e8
2 changed files with 120 additions and 108 deletions
|
@ -34,9 +34,13 @@ function getWeather( $loc, $units='metric', $lang='en', $appid='', $cachetime=0)
|
|||
try {
|
||||
$res = new SimpleXMLElement(Network::fetchUrl($url));
|
||||
} 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;
|
||||
}
|
||||
unset($_SESSION['curweather_notice_shown']);
|
||||
if ((string)$res->temperature['unit']==='metric') {
|
||||
$tunit = '°C';
|
||||
$wunit = 'm/s';
|
||||
|
@ -98,7 +102,6 @@ function curweather_network_mod_init(&$fk_app,&$b) {
|
|||
// 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');
|
||||
|
@ -139,10 +142,8 @@ function curweather_network_mod_init(&$fk_app,&$b) {
|
|||
}
|
||||
|
||||
$fk_app->page['aside'] = $curweather.$fk_app->page['aside'];
|
||||
|
||||
}
|
||||
|
||||
|
||||
function curweather_addon_settings_post($a,$post) {
|
||||
if(! local_user() || (! x($_POST,'curweather-settings-submit')))
|
||||
return;
|
||||
|
@ -153,7 +154,6 @@ function curweather_addon_settings_post($a,$post) {
|
|||
info(L10n::t('Current Weather settings updated.') . EOL);
|
||||
}
|
||||
|
||||
|
||||
function curweather_addon_settings(&$a,&$s) {
|
||||
|
||||
if(! local_user())
|
||||
|
@ -184,8 +184,8 @@ function curweather_addon_settings(&$a,&$s) {
|
|||
'$enabled' => [ 'curweather_enable', L10n::t('Show weather data'), $enable, '']
|
||||
]);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
// Config stuff for the admin panel to let the admin of the node set a APPID
|
||||
// for accessing the API of openweathermap
|
||||
function curweather_addon_admin_post (&$a) {
|
||||
|
@ -197,6 +197,7 @@ function curweather_addon_admin_post (&$a) {
|
|||
info(L10n::t('Curweather settings saved.'.EOL));
|
||||
}
|
||||
}
|
||||
|
||||
function curweather_addon_admin (&$a, &$o) {
|
||||
if(! is_site_admin())
|
||||
return;
|
||||
|
@ -205,7 +206,18 @@ function curweather_addon_admin (&$a, &$o) {
|
|||
$t = get_markup_template("admin.tpl", "addon/curweather/" );
|
||||
$o = replace_macros ($t, [
|
||||
'$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')]
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue