[curweather] CR request:

- added/removed spaces
- added missing line-feed after opening curly brace
This commit is contained in:
Roland Häder 2018-07-25 01:27:18 +02:00
parent 7b3ceb33aa
commit 4b5691707b
No known key found for this signature in database
GPG key ID: B72F8185C6C7BD78

View file

@ -35,7 +35,8 @@ function curweather_uninstall()
} }
// get the weather data from OpenWeatherMap // get the weather data from OpenWeatherMap
function getWeather($loc, $units = 'metric', $lang = 'en', $appid = '', $cachetime = 0) { 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"; $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)); $cached = Cache::get('curweather'.md5($url));
$now = new DateTime(); $now = new DateTime();
@ -61,7 +62,7 @@ function getWeather($loc, $units = 'metric', $lang = 'en', $appid = '', $cacheti
unset($_SESSION['curweather_notice_shown']); 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';
} else { } else {
@ -69,14 +70,14 @@ function getWeather($loc, $units = 'metric', $lang = 'en', $appid = '', $cacheti
$wunit = 'mph'; $wunit = 'mph';
} }
if ( trim((string) $res->weather['value']) == trim((string) $res->clouds['name']) ) { if (trim((string) $res->weather['value']) == trim((string) $res->clouds['name']) ) {
$desc = (string) $res->clouds['name']; $desc = (string) $res->clouds['name'];
} else { } else {
$desc = (string) $res->weather['value'] . ', ' . (string) $res->clouds['name']; $desc = (string) $res->weather['value'] . ', ' . (string) $res->clouds['name'];
} }
$r = [ $r = [
'city'=> (string) $res->city['name'][0], 'city' => (string) $res->city['name'][0],
'country' => (string) $res->city->country[0], 'country' => (string) $res->city->country[0],
'lat' => (string) $res->city->coord['lat'], 'lat' => (string) $res->city->coord['lat'],
'lon' => (string) $res->city->coord['lon'], 'lon' => (string) $res->city->coord['lon'],
@ -84,7 +85,7 @@ function getWeather($loc, $units = 'metric', $lang = 'en', $appid = '', $cacheti
'pressure' => (string) $res->pressure['value'] . (string) $res->pressure['unit'], 'pressure' => (string) $res->pressure['value'] . (string) $res->pressure['unit'],
'humidity' => (string) $res->humidity['value'] . (string) $res->humidity['unit'], 'humidity' => (string) $res->humidity['value'] . (string) $res->humidity['unit'],
'descripion' => $desc, 'descripion' => $desc,
'wind' => (string) $res->wind->speed['name'] . ' (' . (string) $res->wind->speed['value'].$wunit.')', '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'], 'icon' => (string) $res->weather['icon'],
]; ];
@ -97,7 +98,7 @@ function getWeather($loc, $units = 'metric', $lang = 'en', $appid = '', $cacheti
function curweather_network_mod_init(App $a, &$b) function curweather_network_mod_init(App $a, &$b)
{ {
if (! intval(PConfig::get(local_user(),'curweather','curweather_enable'))) { if (! intval(PConfig::get(local_user(), 'curweather','curweather_enable'))) {
return; return;
} }
@ -183,7 +184,7 @@ function curweather_addon_settings(App $a, &$s) {
/* Get the current state of our config variable */ /* Get the current state of our config variable */
$curweather_loc = PConfig::get(local_user(), 'curweather', 'curweather_loc'); $curweather_loc = PConfig::get(local_user(), 'curweather', 'curweather_loc');
$curweather_units = PConfig::get(local_user(), 'curweather', 'curweather_units'); $curweather_units = PConfig::get(local_user(), 'curweather', 'curweather_units');
$appid = Config::get('curweather','appid'); $appid = Config::get('curweather', 'appid');
if ($appid == "") { if ($appid == "") {
$noappidtext = L10n::t('No APPID found, please contact your admin to obtain one.'); $noappidtext = L10n::t('No APPID found, please contact your admin to obtain one.');
@ -191,7 +192,7 @@ function curweather_addon_settings(App $a, &$s) {
$noappidtext = ''; $noappidtext = '';
} }
$enable = intval(PConfig::get(local_user(),'curweather','curweather_enable')); $enable = intval(PConfig::get(local_user(), 'curweather', 'curweather_enable'));
$enable_checked = (($enable) ? ' checked="checked" ' : ''); $enable_checked = (($enable) ? ' checked="checked" ' : '');
// load template and replace the macros // load template and replace the macros
@ -212,7 +213,7 @@ function curweather_addon_settings(App $a, &$s) {
// 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 (App $a) function curweather_addon_admin_post(App $a)
{ {
if (! is_site_admin()) { if (! is_site_admin()) {
return; return;
@ -226,14 +227,14 @@ function curweather_addon_admin_post (App $a)
} }
} }
function curweather_addon_admin (App $a, &$o) function curweather_addon_admin(App $a, &$o)
{ {
if (!is_site_admin()) { if (!is_site_admin()) {
return; return;
} }
$appid = Config::get('curweather','appid'); $appid = Config::get('curweather', 'appid');
$cachetime = Config::get('curweather','cachetime'); $cachetime = Config::get('curweather', 'cachetime');
$t = get_markup_template("admin.tpl", "addon/curweather/" ); $t = get_markup_template("admin.tpl", "addon/curweather/" );