]> git.mxchange.org Git - friendica-addons.git/blobdiff - superblock/superblock.php
Woodpecker: Update PHP version
[friendica-addons.git] / superblock / superblock.php
index b5a0ea0cfc8527b9014c81a9bc88a76b8e4128db..c1a141115a7dc48719ab751406e92550a2142632 100644 (file)
@@ -6,8 +6,10 @@
  * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
  *
  */
+
+use Friendica\App;
 use Friendica\Core\Hook;
-use Friendica\Core\L10n;
+use Friendica\Core\Renderer;
 use Friendica\DI;
 use Friendica\Util\Strings;
 
@@ -20,60 +22,42 @@ function superblock_install()
        Hook::register('enotify_store', 'addon/superblock/superblock.php', 'superblock_enotify_store');
 }
 
-function superblock_uninstall()
-{
-       Hook::unregister('addon_settings', 'addon/superblock/superblock.php', 'superblock_addon_settings');
-       Hook::unregister('addon_settings_post', 'addon/superblock/superblock.php', 'superblock_addon_settings_post');
-       Hook::unregister('conversation_start', 'addon/superblock/superblock.php', 'superblock_conversation_start');
-       Hook::unregister('item_photo_menu', 'addon/superblock/superblock.php', 'superblock_item_photo_menu');
-       Hook::unregister('enotify_store', 'addon/superblock/superblock.php', 'superblock_enotify_store');
-}
-
-function superblock_addon_settings(&$a, &$s)
+function superblock_addon_settings(App &$a, array &$data)
 {
-       if (!local_user()) {
+       if (!DI::userSession()->getLocalUserId()) {
                return;
        }
 
-       /* Add our stylesheet to the page so we can make our settings look nice */
+       $blocked = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'blocked', '');
 
-       DI::page()['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . DI::baseUrl()->get() . '/addon/superblock/superblock.css' . '" media="all" />' . "\r\n";
+       $t    = Renderer::getMarkupTemplate('settings.tpl', 'addon/superblock/');
+       $html = Renderer::replaceMacros($t, [
+               '$urls' => ['superblock-words', DI::l10n()->t('Comma separated profile URLs to block'), $blocked],
+       ]);
 
-       $words = DI::pConfig()->get(local_user(), 'system', 'blocked');
-       if (!$words) {
-               $words = '';
-       }
-
-       $s .= '<span id="settings_superblock_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_superblock_expanded\'); openClose(\'settings_superblock_inflated\');">';
-       $s .= '<h3>' . L10n::t('Superblock') . '</h3>';
-       $s .= '</span>';
-       $s .= '<div id="settings_superblock_expanded" class="settings-block" style="display: none;">';
-       $s .= '<span class="fakelink" onclick="openClose(\'settings_superblock_expanded\'); openClose(\'settings_superblock_inflated\');">';
-       $s .= '<h3>' . L10n::t('Superblock') . '</h3>';
-       $s .= '</span>';
-       $s .= '<div id="superblock-wrapper">';
-       $s .= '<label id="superblock-label" for="superblock-words">' . L10n::t('Comma separated profile URLS to block') . ' </label>';
-       $s .= '<textarea id="superblock-words" type="text" name="superblock-words" >' . htmlspecialchars($words) . '</textarea>';
-       $s .= '</div><div class="clear"></div>';
-
-       $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="superblock-submit" name="superblock-submit" class="settings-submit" value="' . L10n::t('Save Settings') . '" /></div></div>';
-
-       return;
+       $data = [
+               'addon' => 'superblock',
+               'title' => DI::l10n()->t('Superblock'),
+               'html'  => $html,
+       ];
 }
 
-function superblock_addon_settings_post(&$a, &$b)
+function superblock_addon_settings_post(App $a, array &$b)
 {
-       if (!local_user()) {
+       if (!DI::userSession()->getLocalUserId()) {
                return;
        }
 
        if (!empty($_POST['superblock-submit'])) {
-               DI::pConfig()->set(local_user(), 'system', 'blocked',trim($_POST['superblock-words']));
-               info(L10n::t('SUPERBLOCK Settings saved.') . EOL);
+               DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'blocked',trim($_POST['superblock-words']));
        }
 }
 
-function superblock_enotify_store(&$a,&$b) {
+function superblock_enotify_store(App $a, array &$b)
+{
+       if (empty($b['uid'])) {
+               return;
+       }
 
        $words = DI::pConfig()->get($b['uid'], 'system', 'blocked');
        if ($words) {
@@ -95,24 +79,26 @@ function superblock_enotify_store(&$a,&$b) {
                        }
                }
        }
+
        if ($found) {
-               $b['abort'] = true;
+               // Empty out the fields
+               $b = [];
        }
 }
 
 
-function superblock_conversation_start(&$a, &$b)
+function superblock_conversation_start(App $a, array &$b)
 {
-       if (!local_user()) {
+       if (!DI::userSession()->getLocalUserId()) {
                return;
        }
 
-       $words = DI::pConfig()->get(local_user(), 'system', 'blocked');
+       $words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'blocked');
        if ($words) {
                $a->data['superblock'] = explode(',', $words);
        }
-       DI::page()['htmlhead'] .= <<< EOT
 
+       DI::page()['htmlhead'] .= <<< EOT
 <script>
 function superblockBlock(author) {
        $.get('superblock?block=' +author, function(data) {
@@ -120,14 +106,13 @@ function superblockBlock(author) {
        });
 }
 </script>
-
 EOT;
 
 }
 
-function superblock_item_photo_menu(&$a, &$b)
+function superblock_item_photo_menu(App $a, array &$b)
 {
-       if (!local_user() || $b['item']['self']) {
+       if (!DI::userSession()->getLocalUserId() || $b['item']['self']) {
                return;
        }
 
@@ -142,19 +127,23 @@ function superblock_item_photo_menu(&$a, &$b)
                }
        }
 
-       $b['menu'][L10n::t('Block Completely')] = 'javascript:superblockBlock(\'' . $author . '\'); return false;';
+       $b['menu'][DI::l10n()->t('Block Completely')] = 'javascript:superblockBlock(\'' . $author . '\'); return false;';
 }
 
+/**
+ * This is a statement rather than an actual function definition. The simple
+ * existence of this method is checked to figure out if the addon offers a
+ * module.
+ */
 function superblock_module() {}
 
-
-function superblock_init(&$a)
+function superblock_init(App $a)
 {
-       if (!local_user()) {
+       if (!DI::userSession()->getLocalUserId()) {
                return;
        }
 
-       $words = DI::pConfig()->get(local_user(), 'system', 'blocked');
+       $words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'blocked');
 
        if (array_key_exists('block', $_GET) && $_GET['block']) {
                if (strlen($words))
@@ -162,7 +151,6 @@ function superblock_init(&$a)
                $words .= trim($_GET['block']);
        }
 
-       DI::pConfig()->set(local_user(), 'system', 'blocked', $words);
-       info(L10n::t('superblock settings updated') . EOL );
+       DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'blocked', $words);
        exit();
 }