]> git.mxchange.org Git - friendica-addons.git/blobdiff - gnot/gnot.php
[various] Remove App dependency from hook functions
[friendica-addons.git] / gnot / gnot.php
index 26012c44187bd8688ec1eb882fb9f7914b5f7e0b..15fb4da00b8b118896f068b3da5597b11d40d933 100644 (file)
@@ -7,92 +7,68 @@
  * 
  *
  */
+
+use Friendica\App;
 use Friendica\Core\Hook;
 use Friendica\Core\Logger;
 use Friendica\Core\Renderer;
 use Friendica\DI;
-use Friendica\Model\Notify\Type;
-
-function gnot_install() {
+use Friendica\Model\Notification;
 
+function gnot_install()
+{
        Hook::register('addon_settings', 'addon/gnot/gnot.php', 'gnot_settings');
        Hook::register('addon_settings_post', 'addon/gnot/gnot.php', 'gnot_settings_post');
        Hook::register('enotify_mail', 'addon/gnot/gnot.php', 'gnot_enotify_mail');
 
-       Logger::log("installed gnot");
-}
-
-
-function gnot_uninstall() {
-
-       Hook::unregister('addon_settings', 'addon/gnot/gnot.php', 'gnot_settings');
-       Hook::unregister('addon_settings_post', 'addon/gnot/gnot.php', 'gnot_settings_post');
-       Hook::unregister('enotify_mail', 'addon/gnot/gnot.php', 'gnot_enotify_mail');
-
-
-       Logger::log("removed gnot");
+       Logger::notice("installed gnot");
 }
 
-
-
 /**
- *
  * Callback from the settings post function.
  * $post contains the $_POST array.
  * We will make sure we've got a valid user account
  * and if so set our configuration setting for this person.
- *
  */
-
-function gnot_settings_post($a,$post) {
-       if(! local_user() || empty($_POST['gnot-submit']))
+function gnot_settings_post($post) {
+       if(! DI::userSession()->getLocalUserId() || empty($_POST['gnot-submit']))
                return;
 
-       DI::pConfig()->set(local_user(),'gnot','enable',intval($_POST['gnot']));
-       info(DI::l10n()->t('Gnot settings updated.') . EOL);
+       DI::pConfig()->set(DI::userSession()->getLocalUserId(),'gnot','enable',intval($_POST['gnot']));
 }
 
-
 /**
- *
  * Called from the Addon Setting form. 
  * Add our own settings info to the page.
- *
  */
-
-
-
-function gnot_settings(&$a,&$s) {
-
-       if(! local_user())
+function gnot_settings(array &$data)
+{
+       if (!DI::userSession()->getLocalUserId()) {
                return;
+       }
 
-       /* Add our stylesheet to the page so we can make our settings look nice */
-
-       DI::page()['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . DI::baseUrl()->get() . '/addon/gnot/gnot.css' . '" media="all" />' . "\r\n";
+       $gnot = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'gnot', 'enable'));
 
-       /* Get the current state of our config variable */
-
-       $gnot = intval(DI::pConfig()->get(local_user(),'gnot','enable'));
-
-       $gnot_checked = (($gnot) ? ' checked="checked" ' : '' );
-       
-       $t = Renderer::getMarkupTemplate('settings.tpl', 'addon/gnot/');
-       /* Add some HTML to the existing form */
-
-       $s .= Renderer::replaceMacros($t, [
-               '$title' => DI::l10n()->t('Gnot Settings') ,
-               '$submit' => DI::l10n()->t('Save Settings'),
-               '$enable' => DI::l10n()->t('Enable this addon?'),
-               '$enabled' => $gnot_checked,
-               '$text' => DI::l10n()->t("Allows threading of email comment notifications on Gmail and anonymising the subject line.")
+       $t    = Renderer::getMarkupTemplate('settings.tpl', 'addon/gnot/');
+       $html = Renderer::replaceMacros($t, [
+               '$text'    => DI::l10n()->t("Allows threading of email comment notifications on Gmail and anonymising the subject line."),
+               '$enabled' => ['gnot', DI::l10n()->t('Enable this addon?'), $gnot],
        ]);
-}
 
+       $data = [
+               'addon' => 'gnot',
+               'title' => DI::l10n()->t('Gnot Settings'),
+               'html'  => $html,
+       ];
+}
 
-function gnot_enotify_mail(&$a,&$b) {
-       if((! $b['uid']) || (! intval(DI::pConfig()->get($b['uid'], 'gnot','enable'))))
+function gnot_enotify_mail(array &$b)
+{
+       if ((!$b['uid']) || (! intval(DI::pConfig()->get($b['uid'], 'gnot','enable')))) {
                return;
-       if($b['type'] == Type::COMMENT)
+       }
+
+       if ($b['type'] == Notification\Type::COMMENT) {
                $b['subject'] = DI::l10n()->t('[Friendica:Notify] Comment to conversation #%d', $b['parent']);
+       }
 }