]> git.mxchange.org Git - friendica-addons.git/blobdiff - curweather/curweather.php
Diaspora - set host to empty if it doesn't exist.
[friendica-addons.git] / curweather / curweather.php
index cfc4fc183f7b4d7605ce93cfd1847104dde44fcc..6d7edc06b3dea3d1d1944ab79bf1751c95aa2555 100644 (file)
@@ -9,29 +9,28 @@
  *
  */
 
-require_once 'include/text.php';
-
 use Friendica\App;
-use Friendica\Core\Addon;
 use Friendica\Core\Cache;
 use Friendica\Core\Config;
+use Friendica\Core\Hook;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
-use Friendica\Network\Proxy;
+use Friendica\Core\Renderer;
 use Friendica\Util\Network;
+use Friendica\Util\Proxy as ProxyUtils;
 
 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');
+       Hook::register('network_mod_init'   , 'addon/curweather/curweather.php', 'curweather_network_mod_init');
+       Hook::register('addon_settings'     , 'addon/curweather/curweather.php', 'curweather_addon_settings');
+       Hook::register('addon_settings_post', 'addon/curweather/curweather.php', 'curweather_addon_settings_post');
 }
 
 function curweather_uninstall()
 {
-       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');
+       Hook::unregister('network_mod_init'   , 'addon/curweather/curweather.php', 'curweather_network_mod_init');
+       Hook::unregister('addon_settings'     , 'addon/curweather/curweather.php', 'curweather_addon_settings');
+       Hook::unregister('addon_settings_post', 'addon/curweather/curweather.php', 'curweather_addon_settings_post');
 }
 
 //  get the weather data from OpenWeatherMap
@@ -92,7 +91,7 @@ function getWeather($loc, $units = 'metric', $lang = 'en', $appid = '', $cacheti
        ];
 
        PConfig::set(local_user(), 'curweather', 'last', $now->getTimestamp());
-       Cache::set('curweather'.md5($url), serialize($r), CACHE_HOUR);
+       Cache::set('curweather'.md5($url), serialize($r), Cache::HOUR);
 
        return $r;
 }
@@ -103,7 +102,7 @@ function curweather_network_mod_init(App $a, &$b)
                return;
        }
 
-       $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/curweather/curweather.css' . '" media="all" />' . "\r\n";
+       $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->getBaseURL() . '/addon/curweather/curweather.css' . '" media="all" />' . "\r\n";
 
        // $rpt value is needed for location
        // $lang will be taken from the browser session to honour user settings
@@ -117,7 +116,7 @@ function curweather_network_mod_init(App $a, &$b)
        $rpt = PConfig::get(local_user(), 'curweather', 'curweather_loc');
 
        // Set the language to the browsers language or default and use metric units
-       $lang = (!empty($_SESSION['language']) ? $_SESSION['language'] : Config::get('system', 'language'));
+       $lang = defaults($_SESSION, 'language', Config::get('system', 'language'));
        $units = PConfig::get( local_user(), 'curweather', 'curweather_units');
        $appid = Config::get('curweather', 'appid');
        $cachetime = intval(Config::get('curweather', 'cachetime'));
@@ -135,10 +134,10 @@ function curweather_network_mod_init(App $a, &$b)
        }
 
        if ($ok) {
-               $t = get_markup_template("widget.tpl", "addon/curweather/" );
-               $curweather = replace_macros ($t, [
+               $t = Renderer::getMarkupTemplate("widget.tpl", "addon/curweather/" );
+               $curweather = Renderer::replaceMacros($t, [
                        '$title' => L10n::t("Current Weather"),
-                       '$icon' => Proxy::proxifyUrl('http://openweathermap.org/img/w/'.$res['icon'].'.png'),
+                       '$icon' => ProxyUtils::proxifyUrl('http://openweathermap.org/img/w/'.$res['icon'].'.png'),
                        '$city' => $res['city'],
                        '$lon' => $res['lon'],
                        '$lat' => $res['lat'],
@@ -152,8 +151,8 @@ function curweather_network_mod_init(App $a, &$b)
                        '$showonmap' => L10n::t('Show on map')
                ]);
        } else {
-               $t = get_markup_template('widget-error.tpl', 'addon/curweather/');
-               $curweather = replace_macros( $t, [
+               $t = Renderer::getMarkupTemplate('widget-error.tpl', 'addon/curweather/');
+               $curweather = Renderer::replaceMacros( $t, [
                        '$problem' => L10n::t('There was a problem accessing the weather data. But have a look'),
                        '$rpt' => $rpt,
                        '$atOWM' => L10n::t('at OpenWeatherMap')
@@ -197,9 +196,9 @@ function curweather_addon_settings(App $a, &$s)
        $enable_checked = (($enable) ? ' checked="checked" ' : '');
        
        // load template and replace the macros
-       $t = get_markup_template("settings.tpl", "addon/curweather/" );
+       $t = Renderer::getMarkupTemplate("settings.tpl", "addon/curweather/" );
 
-       $s = replace_macros ($t, [
+       $s = Renderer::replaceMacros($t, [
                '$submit' => L10n::t('Save Settings'),
                '$header' => L10n::t('Current Weather').' '.L10n::t('Settings'),
                '$noappidtext' => $noappidtext,
@@ -237,9 +236,9 @@ function curweather_addon_admin(App $a, &$o)
        $appid = Config::get('curweather', 'appid');
        $cachetime = Config::get('curweather', 'cachetime');
 
-       $t = get_markup_template("admin.tpl", "addon/curweather/" );
+       $t = Renderer::getMarkupTemplate("admin.tpl", "addon/curweather/" );
 
-       $o = replace_macros ($t, [
+       $o = Renderer::replaceMacros($t, [
                '$submit' => L10n::t('Save Settings'),
                '$cachetime' => [
                        'cachetime',