]> git.mxchange.org Git - friendica-addons.git/blobdiff - curweather/curweather.php
Update function names
[friendica-addons.git] / curweather / curweather.php
index 2e64453e5cfc7351137f1e5c13920564334c2288..dc9f9bb833703469c15221974e67663756767fa9 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Name: Current Weather 
+ * Name: Current Weather
  * Description: Shows current weather conditions for user's location on their network page.
  * Version: 1.1
  * Author: Tony Baldwin <http://friendica.tonybaldwin.info/u/t0ny>
@@ -13,6 +13,8 @@ require_once('include/network.php');
 require_once("mod/proxy.php");
 require_once('include/text.php');
 
+use Friendica\Core\Addon;
+use Friendica\Core\Cache;
 use Friendica\Core\Config;
 use Friendica\Core\PConfig;
 
@@ -46,7 +48,7 @@ function getWeather( $loc, $units='metric', $lang='en', $appid='', $cachetime=0)
     } else {
        $desc = (string)$res->weather['value'].', '.(string)$res->clouds['name'];
     }
-    $r = array(
+    $r = [
        'city'=> (string) $res->city['name'][0],
        'country' => (string) $res->city->country[0],
        'lat' => (string) $res->city->coord['lat'],
@@ -58,22 +60,23 @@ function getWeather( $loc, $units='metric', $lang='en', $appid='', $cachetime=0)
        'wind' => (string)$res->wind->speed['name'].' ('.(string)$res->wind->speed['value'].$wunit.')',
        'update' => (string)$res->lastupdate['value'],
        'icon' => (string)$res->weather['icon']
-    );
+    ];
     PConfig::set(local_user(), 'curweather', 'last', $now->getTimestamp());
     Cache::set('curweather'.md5($url), serialize($r), CACHE_HOUR);
     return $r;
 }
 
-function curweather_install() {
-       register_hook('network_mod_init', 'addon/curweather/curweather.php', 'curweather_network_mod_init');
-       register_hook('plugin_settings', 'addon/curweather/curweather.php', 'curweather_plugin_settings');
-       register_hook('plugin_settings_post', 'addon/curweather/curweather.php', 'curweather_plugin_settings_post');
+function curweather_install()
+{
+       Addon::registerHook('network_mod_init', 'addon/curweather/curweather.php', 'curweather_network_mod_init');
+       Addon::registerHook('addon_settings', 'addon/curweather/curweather.php', 'curweather_addon_settings');
+       Addon::registerHook('addon_settings_post', 'addon/curweather/curweather.php', 'curweather_addon_settings_post');
 }
 
 function curweather_uninstall() {
-       unregister_hook('network_mod_init', 'addon/curweather/curweather.php', 'curweather_network_mod_init');
-       unregister_hook('plugin_settings', 'addon/curweather/curweather.php', 'curweather_plugin_settings');
-       unregister_hook('plugin_settings_post', 'addon/curweather/curweather.php', 'curweather_plugin_settings_post');
+       Addon::unregisterHook('network_mod_init', 'addon/curweather/curweather.php', 'curweather_network_mod_init');
+       Addon::unregisterHook('addon_settings', 'addon/curweather/curweather.php', 'curweather_addon_settings');
+       Addon::unregisterHook('addon_settings_post', 'addon/curweather/curweather.php', 'curweather_addon_settings_post');
 }
 
 function curweather_network_mod_init(&$fk_app,&$b) {
@@ -110,7 +113,7 @@ function curweather_network_mod_init(&$fk_app,&$b) {
 
     if ($ok) {
        $t = get_markup_template("widget.tpl", "addon/curweather/" );
-       $curweather = replace_macros ($t, array(
+       $curweather = replace_macros ($t, [
            '$title' => t("Current Weather"),
            '$icon' => proxy_url('http://openweathermap.org/img/w/'.$res['icon'].'.png'),
            '$city' => $res['city'],
@@ -118,20 +121,20 @@ function curweather_network_mod_init(&$fk_app,&$b) {
            '$lat' => $res['lat'],
            '$description' => $res['descripion'],
            '$temp' => $res['temperature'],
-           '$relhumidity' => array('caption'=>t('Relative Humidity'), 'val'=>$res['humidity']),
-           '$pressure' => array('caption'=>t('Pressure'), 'val'=>$res['pressure']),
-           '$wind' => array('caption'=>t('Wind'), 'val'=> $res['wind']),
+           '$relhumidity' => ['caption'=>t('Relative Humidity'), 'val'=>$res['humidity']],
+           '$pressure' => ['caption'=>t('Pressure'), 'val'=>$res['pressure']],
+           '$wind' => ['caption'=>t('Wind'), 'val'=> $res['wind']],
            '$lastupdate' => t('Last Updated').': '.$res['update'].'UTC',
            '$databy' =>  t('Data by'),
            '$showonmap' => t('Show on map')
-       ));
+       ]);
     } else {
        $t = get_markup_template('widget-error.tpl', 'addon/curweather/');
-       $curweather = replace_macros( $t, array(
+       $curweather = replace_macros( $t, [
            '$problem' => t('There was a problem accessing the weather data. But have a look'),
            '$rpt' => $rpt,
            '$atOWM' => t('at OpenWeatherMap')
-       ));
+       ]);
     }
 
     $fk_app->page['aside'] = $curweather.$fk_app->page['aside'];
@@ -139,7 +142,7 @@ function curweather_network_mod_init(&$fk_app,&$b) {
 }
 
 
-function curweather_plugin_settings_post($a,$post) {
+function curweather_addon_settings_post($a,$post) {
        if(! local_user() || (! x($_POST,'curweather-settings-submit')))
                return;
        PConfig::set(local_user(),'curweather','curweather_loc',trim($_POST['curweather_loc']));
@@ -150,7 +153,7 @@ function curweather_plugin_settings_post($a,$post) {
 }
 
 
-function curweather_plugin_settings(&$a,&$s) {
+function curweather_addon_settings(&$a,&$s) {
 
        if(! local_user())
                return;
@@ -160,31 +163,31 @@ function curweather_plugin_settings(&$a,&$s) {
        $curweather_loc = PConfig::get(local_user(), 'curweather', 'curweather_loc');
        $curweather_units = PConfig::get(local_user(), 'curweather', 'curweather_units');
        $appid = Config::get('curweather','appid');
-       if ($appid=="") { 
+       if ($appid=="") {
                $noappidtext = t('No APPID found, please contact your admin to obtain one.');
        } else {
            $noappidtext = '';
        }
        $enable = intval(PConfig::get(local_user(),'curweather','curweather_enable'));
        $enable_checked = (($enable) ? ' checked="checked" ' : '');
-       
+
        // load template and replace the macros
        $t = get_markup_template("settings.tpl", "addon/curweather/" );
-       $s = replace_macros ($t, array(
-               '$submit' => t('Save Settings'),            
+       $s = replace_macros ($t, [
+               '$submit' => t('Save Settings'),
                '$header' => t('Current Weather').' '.t('Settings'),
                '$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 temperature should be displayed in &deg;C or &deg;F'), array('metric'=>'°C', 'imperial'=>'°F')),
-               '$enabled' => array( 'curweather_enable', t('Show weather data'), $enable, '')
-           ));
+               '$curweather_loc' => [ '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' => [ 'curweather_units', t('Units'), $curweather_units, t('select if the temperature should be displayed in &deg;C or &deg;F'), ['metric'=>'°C', 'imperial'=>'°F']],
+               '$enabled' => [ 'curweather_enable', 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_plugin_admin_post (&$a) {
+function curweather_addon_admin_post (&$a) {
        if(! is_site_admin())
            return;
        if ($_POST['curweather-submit']) {
@@ -193,15 +196,15 @@ function curweather_plugin_admin_post (&$a) {
            info( t('Curweather settings saved.'.EOL));
        }
 }
-function curweather_plugin_admin (&$a, &$o) {
+function curweather_addon_admin (&$a, &$o) {
     if(! is_site_admin())
            return;
     $appid = Config::get('curweather','appid');
     $cachetime = Config::get('curweather','cachetime');
     $t = get_markup_template("admin.tpl", "addon/curweather/" );
-    $o = replace_macros ($t, array(
+    $o = replace_macros ($t, [
        '$submit' => t('Save Settings'),
-       '$cachetime' => array('cachetime', t('Caching Interval'), $cachetime, t('For how long should the weather data be cached? Choose according your OpenWeatherMap account type.'), array('0'=>t('no cache'), '300'=>'5 '.t('minutes'), '900'=>'15 '.t('minutes'), '1800'=>'30 '.t('minutes'), '3600'=>'60 '.t('minutes'))),
-       '$appid' => array('appid', t('Your APPID'), $appid, t('Your API key provided by OpenWeatherMap'))
-    ));
+       '$cachetime' => ['cachetime', t('Caching Interval'), $cachetime, t('For how long should the weather data be cached? Choose according your OpenWeatherMap account type.'), ['0'=>t('no cache'), '300'=>'5 '.t('minutes'), '900'=>'15 '.t('minutes'), '1800'=>'30 '.t('minutes'), '3600'=>'60 '.t('minutes')]],
+       '$appid' => ['appid', t('Your APPID'), $appid, t('Your API key provided by OpenWeatherMap')]
+    ]);
 }