X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=randplace%2Frandplace.php;h=3576fef85c17aceb3b419eac1cd3fe97e0c210fc;hb=54436370f22d200c7dc4eee2e745738a7dd2eec1;hp=df713766c8902f6970d93d34dd251cec4ee82fe1;hpb=bb5588b5eb8d6c292c78ce276774c75dac2386fc;p=friendica-addons.git diff --git a/randplace/randplace.php b/randplace/randplace.php old mode 100755 new mode 100644 index df713766..3576fef8 --- a/randplace/randplace.php +++ b/randplace/randplace.php @@ -1,50 +1,50 @@ - * - * - * * - * Addons are registered with the system in the - * .htconfig.php file. * - * $a->config['system']['addon'] = 'plugin1,plugin2,etc.'; * - * When registration is detected, the system calls the plugin + * + * Addons are registered with the system through the admin + * panel. + * + * When registration is detected, 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 + * If the addon is removed from the configuration list, the * system will call the name_uninstall() function. * */ - +use Friendica\Core\Hook; +use Friendica\Core\Logger; +use Friendica\DI; function randplace_install() { /** - * - * Our demo plugin will attach in three places. + * + * Our demo addon will attach in three places. * The first is just prior to storing a local post. * */ - register_hook('post_local', 'addon/randplace/randplace.php', 'randplace_post_hook'); + Hook::register('post_local', 'addon/randplace/randplace.php', 'randplace_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/randplace/randplace.php', 'randplace_settings'); - register_hook('plugin_settings_post', 'addon/randplace/randplace.php', 'randplace_settings_post'); + Hook::register('addon_settings', 'addon/randplace/randplace.php', 'randplace_settings'); + Hook::register('addon_settings_post', 'addon/randplace/randplace.php', 'randplace_settings_post'); - logger("installed randplace"); + Logger::log("installed randplace"); } @@ -52,18 +52,13 @@ function randplace_uninstall() { /** * - * uninstall unregisters any hooks created with register_hook - * during install. It may also delete configuration settings - * and any other cleanup. + * This function should undo anything that was done in name_install() + * + * Except hooks, they are all unregistered automatically and don't need to be unregistered manually. * */ - unregister_hook('post_local', 'addon/randplace/randplace.php', 'randplace_post_hook'); - unregister_hook('plugin_settings', 'addon/randplace/randplace.php', 'randplace_settings'); - unregister_hook('plugin_settings_post', 'addon/randplace/randplace.php', 'randplace_settings_post'); - - - logger("removed randplace"); + Logger::log("removed randplace"); } @@ -75,11 +70,11 @@ function randplace_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 * */ - logger('randplace invoked'); + Logger::log('randplace invoked'); if(! local_user()) /* non-zero if this is a logged in user of this system */ return; @@ -92,7 +87,7 @@ function randplace_post_hook($a, &$item) { /* Retrieve our personal config setting */ - $active = get_pconfig(local_user(), 'randplace', 'enable'); + $active = DI::pConfig()->get(local_user(), 'randplace', 'enable'); if(! $active) return; @@ -106,7 +101,7 @@ function randplace_post_hook($a, &$item) { * */ - $cities = array(); + $cities = []; $zones = timezone_identifiers_list(); foreach($zones as $zone) { if((strpos($zone,'/')) && (! stristr($zone,'US/')) && (! stristr($zone,'Etc/'))) @@ -137,13 +132,13 @@ function randplace_settings_post($a,$post) { if(! local_user()) return; if($_POST['randplace-submit']) - set_pconfig(local_user(),'randplace','enable',intval($_POST['randplace'])); + DI::pConfig()->set(local_user(),'randplace','enable',intval($_POST['randplace'])); } /** * - * Called from the Plugin Setting form. + * Called from the Addon Setting form. * Add our own settings info to the page. * */ @@ -157,25 +152,25 @@ function randplace_settings(&$a,&$s) { /* Add our stylesheet to the page so we can make our settings look nice */ - $a->page['htmlhead'] .= '' . "\r\n"; + DI::page()['htmlhead'] .= '' . "\r\n"; /* Get the current state of our config variable */ - $enabled = get_pconfig(local_user(),'randplace','enable'); + $enabled = DI::pConfig()->get(local_user(),'randplace','enable'); $checked = (($enabled) ? ' checked="checked" ' : ''); /* Add some HTML to the existing form */ $s .= '
'; - $s .= '

' . t('Randplace Settings') . '

'; + $s .= '

' . DI::l10n()->t('Randplace Settings') . '

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