]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Search/Acl.php
Issue 11309: improved check for wanted posts
[friendica.git] / src / Module / Search / Acl.php
index 6b1434b9cf73b23d378da69e2fe6572bfc77e120..f00c9f9ecb1c98b0f25d900d7c32d9e85728a88d 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -32,7 +32,6 @@ use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Post;
 use Friendica\Network\HTTPException;
-use Friendica\Util\Strings;
 
 /**
  * ACL selector json backend
@@ -41,15 +40,15 @@ use Friendica\Util\Strings;
  */
 class Acl extends BaseModule
 {
-       const TYPE_GLOBAL_CONTACT        = 'x'; //
-       const TYPE_MENTION_CONTACT       = 'c'; //
+       const TYPE_GLOBAL_CONTACT        = 'x';
+       const TYPE_MENTION_CONTACT       = 'c';
        const TYPE_MENTION_GROUP         = 'g';
        const TYPE_MENTION_CONTACT_GROUP = '';
-       const TYPE_MENTION_FORUM         = 'f'; //
+       const TYPE_MENTION_FORUM         = 'f';
        const TYPE_PRIVATE_MESSAGE       = 'm';
        const TYPE_ANY_CONTACT           = 'a';
 
-       public static function rawContent(array $parameters = [])
+       protected function rawContent(array $request = [])
        {
                if (!local_user()) {
                        throw new HTTPException\UnauthorizedException(DI::l10n()->t('You must be logged in to use this module.'));
@@ -69,7 +68,7 @@ class Acl extends BaseModule
        private static function globalContactSearch()
        {
                // autocomplete for global contact search (e.g. navbar search)
-               $search = Strings::escapeTags(trim($_REQUEST['search']));
+               $search = trim($_REQUEST['search']);
                $mode = $_REQUEST['smode'];
                $page = $_REQUEST['page'] ?? 1;
 
@@ -111,7 +110,7 @@ class Acl extends BaseModule
                        $search = $_REQUEST['query'];
                }
 
-               Logger::info('ACL {action} - {subaction}', ['module' => 'acl', 'action' => 'content', 'subaction' => 'search', 'search' => $search, 'type' => $type, 'conversation' => $conv_id]);
+               Logger::info('ACL {action} - {subaction} - start', ['module' => 'acl', 'action' => 'content', 'subaction' => 'search', 'search' => $search, 'type' => $type, 'conversation' => $conv_id]);
 
                $sql_extra = '';
                $condition       = ["`uid` = ? AND NOT `deleted` AND NOT `pending` AND NOT `archive`", local_user()];
@@ -130,20 +129,22 @@ class Acl extends BaseModule
                        $group_count = DBA::count('group', $condition_group);
                }
 
-               $networks = Widget::unavailableNetworksAsArray();
-               if (!empty($networks)) {
-                       $condition = DBA::mergeConditions($condition, array_merge(["NOT `network` IN (" . substr(str_repeat("?, ", count($networks)), 0, -2) . ")"], $networks));
-               }
+               $networks = Widget::unavailableNetworks();
+               $condition = DBA::mergeConditions($condition, array_merge(["NOT `network` IN (" . substr(str_repeat("?, ", count($networks)), 0, -2) . ")"], $networks));
 
                switch ($type) {
                        case self::TYPE_MENTION_CONTACT_GROUP:
                                $condition = DBA::mergeConditions($condition,
                                        ["NOT `self` AND NOT `blocked` AND `notify` != ? AND NOT `network` IN (?, ?)", '', Protocol::OSTATUS, Protocol::STATUSNET
                                ]);
+                               break;
+
                        case self::TYPE_MENTION_CONTACT:
                                $condition = DBA::mergeConditions($condition,
                                        ["NOT `self` AND NOT `blocked` AND `notify` != ? AND `network` != ?", '', Protocol::STATUSNET
                                ]);
+                               break;
+
                        case self::TYPE_MENTION_FORUM:
                                $condition = DBA::mergeConditions($condition,
                                        ["NOT `self` AND NOT `blocked` AND `notify` != ? AND `contact-type` = ?", '', Contact::TYPE_COMMUNITY
@@ -206,7 +207,7 @@ class Acl extends BaseModule
                        foreach ($r as $g) {
                                $entry = [
                                        'type'    => 'c',
-                                       'photo'   => Contact::getMicro($g),
+                                       'photo'   => Contact::getMicro($g, true),
                                        'name'    => htmlspecialchars($g['name']),
                                        'id'      => intval($g['id']),
                                        'network' => $g['network'],
@@ -267,7 +268,7 @@ class Acl extends BaseModule
                                if (count($contact) > 0) {
                                        $unknown_contacts[] = [
                                                'type'    => 'c',
-                                               'photo'   => Contact::getMicro($contact),
+                                               'photo'   => Contact::getMicro($contact, true),
                                                'name'    => htmlspecialchars($contact['name']),
                                                'id'      => intval($contact['id']),
                                                'network' => $contact['network'],
@@ -303,6 +304,7 @@ class Acl extends BaseModule
                        'items' => $results['items'],
                ];
 
+               Logger::info('ACL {action} - {subaction} - done', ['module' => 'acl', 'action' => 'content', 'subaction' => 'search', 'search' => $search, 'type' => $type, 'conversation' => $conv_id]);
                return $o;
        }
 }