X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=geocoordinates%2Fgeocoordinates.php;h=89ccd88396441eabeb1c679f8d876ca11d5fee27;hb=99a7be5eb63c8e525897c9fe2486ec3d37123652;hp=116431681c5c6ee31415dec8e1448eca7c5d26a6;hpb=48dcbc6f3fc3edae74e3ea2c823011bfb7c26081;p=friendica-addons.git diff --git a/geocoordinates/geocoordinates.php b/geocoordinates/geocoordinates.php index 11643168..89ccd883 100644 --- a/geocoordinates/geocoordinates.php +++ b/geocoordinates/geocoordinates.php @@ -5,21 +5,27 @@ * Version: 0.1 * Author: Michael Vogel */ - +use Friendica\Core\Addon; +use Friendica\Core\Cache; use Friendica\Core\Config; +use Friendica\Core\L10n; +use Friendica\Util\Network; -function geocoordinates_install() { - register_hook('post_local', 'addon/geocoordinates/geocoordinates.php', 'geocoordinates_post_hook'); - register_hook('post_remote', 'addon/geocoordinates/geocoordinates.php', 'geocoordinates_post_hook'); +function geocoordinates_install() +{ + Addon::registerHook('post_local', 'addon/geocoordinates/geocoordinates.php', 'geocoordinates_post_hook'); + Addon::registerHook('post_remote', 'addon/geocoordinates/geocoordinates.php', 'geocoordinates_post_hook'); } -function geocoordinates_uninstall() { - unregister_hook('post_local', 'addon/geocoordinates/geocoordinates.php', 'geocoordinates_post_hook'); - unregister_hook('post_remote', 'addon/geocoordinates/geocoordinates.php', 'geocoordinates_post_hook'); +function geocoordinates_uninstall() +{ + Addon::unregisterHook('post_local', 'addon/geocoordinates/geocoordinates.php', 'geocoordinates_post_hook'); + Addon::unregisterHook('post_remote', 'addon/geocoordinates/geocoordinates.php', 'geocoordinates_post_hook'); } -function geocoordinates_resolve_item(&$item) { +function geocoordinates_resolve_item(&$item) +{ if((!$item["coord"]) || ($item["location"])) return; @@ -45,7 +51,7 @@ function geocoordinates_resolve_item(&$item) { return; } - $s = fetch_url("https://api.opencagedata.com/geocode/v1/json?q=".$coords[0].",".$coords[1]."&key=".$key."&language=".$language); + $s = Network::fetchUrl("https://api.opencagedata.com/geocode/v1/json?q=".$coords[0].",".$coords[1]."&key=".$key."&language=".$language); if (!$s) { logger("API could not be queried", LOGGER_DEBUG); @@ -72,26 +78,29 @@ function geocoordinates_resolve_item(&$item) { Cache::set("geocoordinates:".$language.":".$coords[0]."-".$coords[1], $item["location"]); } -function geocoordinates_post_hook($a, &$item) { +function geocoordinates_post_hook($a, &$item) +{ geocoordinates_resolve_item($item); } -function geocoordinates_plugin_admin(&$a,&$o) { +function geocoordinates_addon_admin(&$a, &$o) +{ $t = get_markup_template("admin.tpl", "addon/geocoordinates/"); - $o = replace_macros($t, array( - '$submit' => t('Save Settings'), - '$api_key' => array('api_key', t('API Key'), Config::get('geocoordinates', 'api_key' ), ''), - '$language' => array('language', t('Language code (IETF format)'), Config::get('geocoordinates', 'language' ), ''), - )); + $o = replace_macros($t, [ + '$submit' => L10n::t('Save Settings'), + '$api_key' => ['api_key', L10n::t('API Key'), Config::get('geocoordinates', 'api_key'), ''], + '$language' => ['language', L10n::t('Language code (IETF format)'), Config::get('geocoordinates', 'language'), ''], + ]); } -function geocoordinates_plugin_admin_post(&$a) { - $api_key = ((x($_POST,'api_key')) ? notags(trim($_POST['api_key'])) : ''); - Config::set('geocoordinates','api_key',$api_key); +function geocoordinates_addon_admin_post(&$a) +{ + $api_key = ((x($_POST, 'api_key')) ? notags(trim($_POST['api_key'])) : ''); + Config::set('geocoordinates', 'api_key', $api_key); - $language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : ''); - Config::set('geocoordinates','language',$language); - info(t('Settings updated.'). EOL); + $language = ((x($_POST, 'language')) ? notags(trim($_POST['language'])) : ''); + Config::set('geocoordinates', 'language', $language); + info(L10n::t('Settings updated.'). EOL); }