X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=geonames%2Fgeonames.php;h=79e268e6eeddb2d948953fa2b41d32e97636d6ca;hb=f1514063559930de791c0bff18a3f6ae4b455f7c;hp=8226fc0bf6701170ac6518bd94cf185d2a4bfeb3;hpb=858758e92c5d8c1c41e188284fea53ae50fb0855;p=friendica-addons.git diff --git a/geonames/geonames.php b/geonames/geonames.php old mode 100755 new mode 100644 index 8226fc0b..79e268e6 --- a/geonames/geonames.php +++ b/geonames/geonames.php @@ -12,36 +12,41 @@ * $a->config['geonames']['username'] = 'your_username'; * Also visit http://geonames.org/manageaccount and enable access to the free web services * - * When plugin is installed, the system calls the plugin + * When addon is installed, the system calls the addon * name_install() function, located in 'addon/name/name.php', * where 'name' is the name of the addon. * If the addon is removed from the configuration list, the * system will call the name_uninstall() function. * */ - +use Friendica\Core\Addon; +use Friendica\Core\Config; +use Friendica\Core\L10n; +use Friendica\Core\PConfig; +use Friendica\Util\Network; +use Friendica\Util\XML; function geonames_install() { /** * - * Our plugin will attach in three places. + * Our addon will attach in three places. * The first is just prior to storing a local post. * */ - register_hook('post_local', 'addon/geonames/geonames.php', 'geonames_post_hook'); + Addon::registerHook('post_local', 'addon/geonames/geonames.php', 'geonames_post_hook'); /** * - * Then we'll attach into the plugin settings page, and also the + * Then we'll attach into the addon settings page, and also the * settings post hook so that we can create and update * user preferences. * */ - register_hook('plugin_settings', 'addon/geonames/geonames.php', 'geonames_settings'); - register_hook('plugin_settings_post', 'addon/geonames/geonames.php', 'geonames_settings_post'); + Addon::registerHook('addon_settings', 'addon/geonames/geonames.php', 'geonames_addon_admin'); + Addon::registerHook('addon_settings_post', 'addon/geonames/geonames.php', 'geonames_addon_admin_post'); logger("installed geonames"); } @@ -57,9 +62,9 @@ function geonames_uninstall() { * */ - unregister_hook('post_local', 'addon/geonames/geonames.php', 'geonames_post_hook'); - unregister_hook('plugin_settings', 'addon/geonames/geonames.php', 'geonames_settings'); - unregister_hook('plugin_settings_post', 'addon/geonames/geonames.php', 'geonames_settings_post'); + Addon::unregisterHook('post_local', 'addon/geonames/geonames.php', 'geonames_post_hook'); + Addon::unregisterHook('addon_settings', 'addon/geonames/geonames.php', 'geonames_addon_admin'); + Addon::unregisterHook('addon_settings_post', 'addon/geonames/geonames.php', 'geonames_addon_admin_post'); logger("removed geonames"); @@ -74,7 +79,7 @@ function geonames_post_hook($a, &$item) { * An item was posted on the local system. * We are going to look for specific items: * - A status post by a profile owner - * - The profile owner must have allowed our plugin + * - The profile owner must have allowed our addon * */ @@ -91,8 +96,8 @@ function geonames_post_hook($a, &$item) { /* Retrieve our personal config setting */ - $geo_account = get_config('geonames', 'username'); - $active = get_pconfig(local_user(), 'geonames', 'enable'); + $geo_account = Config::get('geonames', 'username'); + $active = PConfig::get(local_user(), 'geonames', 'enable'); if((! $geo_account) || (! $active)) return; @@ -108,12 +113,12 @@ function geonames_post_hook($a, &$item) { * */ - $s = fetch_url('http://api.geonames.org/findNearbyPlaceName?lat=' . $coords[0] . '&lng=' . $coords[1] . '&username=' . $geo_account); + $s = Network::fetchUrl('http://api.geonames.org/findNearbyPlaceName?lat=' . $coords[0] . '&lng=' . $coords[1] . '&username=' . $geo_account); if(! $s) return; - $xml = parse_xml_string($s); + $xml = XML::parseString($s); if($xml->geoname->name && $xml->geoname->countryName) $item['location'] = $xml->geoname->name . ', ' . $xml->geoname->countryName; @@ -135,30 +140,30 @@ function geonames_post_hook($a, &$item) { * */ -function geonames_settings_post($a,$post) { +function geonames_addon_admin_post($a,$post) { if(! local_user() || (! x($_POST,'geonames-submit'))) return; - set_pconfig(local_user(),'geonames','enable',intval($_POST['geonames'])); + PConfig::set(local_user(),'geonames','enable',intval($_POST['geonames'])); - info( t('Geonames settings updated.') . EOL); + info(L10n::t('Geonames settings updated.') . EOL); } /** * - * Called from the Plugin Setting form. + * Called from the Addon Setting form. * Add our own settings info to the page. * */ -function geonames_settings(&$a,&$s) { +function geonames_addon_admin(&$a,&$s) { if(! local_user()) return; - $geo_account = get_config('geonames', 'username'); + $geo_account = Config::get('geonames', 'username'); if(! $geo_account) return; @@ -169,21 +174,21 @@ function geonames_settings(&$a,&$s) { /* Get the current state of our config variable */ - $enabled = get_pconfig(local_user(),'geonames','enable'); + $enabled = PConfig::get(local_user(),'geonames','enable'); $checked = (($enabled) ? ' checked="checked" ' : ''); /* Add some HTML to the existing form */ $s .= '
'; - $s .= '

' . t('Geonames Settings') . '

'; + $s .= '

' . L10n::t('Geonames Settings') . '

'; $s .= '
'; - $s .= ''; + $s .= ''; $s .= ''; $s .= '
'; /* provide a submit button */ - $s .= '
'; + $s .= '
'; }