]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Search/Acl.php
Remove the activity
[friendica.git] / src / Module / Search / Acl.php
index d0a1d86e9955375ed6306471d6cc4ca91b7bd347..9f072b91c938df938c70ceb6047b1cda5fcea908 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
  *
@@ -27,12 +27,12 @@ use Friendica\Core\Hook;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Core\Search;
+use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Post;
 use Friendica\Network\HTTPException;
-use Friendica\Util\Strings;
 
 /**
  * ACL selector json backend
@@ -49,9 +49,9 @@ class Acl extends BaseModule
        const TYPE_PRIVATE_MESSAGE       = 'm';
        const TYPE_ANY_CONTACT           = 'a';
 
-       public static function rawContent(array $parameters = [])
+       protected function rawContent(array $request = [])
        {
-               if (!local_user()) {
+               if (!DI::userSession()->getLocalUserId()) {
                        throw new HTTPException\UnauthorizedException(DI::l10n()->t('You must be logged in to use this module.'));
                }
 
@@ -62,14 +62,13 @@ class Acl extends BaseModule
                        $o = self::regularContactSearch($type);
                }
 
-               echo json_encode($o);
-               exit;
+               System::jsonExit($o);
        }
 
-       private static function globalContactSearch()
+       private static function globalContactSearch(): array
        {
                // 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;
 
@@ -96,7 +95,7 @@ class Acl extends BaseModule
                return $o;
        }
 
-       private static function regularContactSearch(string $type)
+       private static function regularContactSearch(string $type): array
        {
                $start   = $_REQUEST['start']        ?? 0;
                $count   = $_REQUEST['count']        ?? 100;
@@ -111,11 +110,11 @@ 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()];
-               $condition_group = ["`uid` = ? AND NOT `deleted`", local_user()];
+               $condition       = ["`uid` = ? AND NOT `deleted` AND NOT `pending` AND NOT `archive`", DI::userSession()->getLocalUserId()];
+               $condition_group = ["`uid` = ? AND NOT `deleted`", DI::userSession()->getLocalUserId()];
 
                if ($search != '') {
                        $sql_extra = "AND `name` LIKE '%%" . DBA::escape($search) . "%%'";
@@ -136,13 +135,13 @@ class Acl extends BaseModule
                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
+                                       ["NOT `self` AND NOT `blocked` AND `notify` != ? AND `network` != ?", '', Protocol::OSTATUS
                                ]);
                                break;
 
                        case self::TYPE_MENTION_CONTACT:
                                $condition = DBA::mergeConditions($condition,
-                                       ["NOT `self` AND NOT `blocked` AND `notify` != ? AND `network` != ?", '', Protocol::STATUSNET
+                                       ["NOT `self` AND NOT `blocked` AND `notify` != ?", ''
                                ]);
                                break;
 
@@ -177,7 +176,7 @@ class Acl extends BaseModule
                                GROUP BY `group`.`name`, `group`.`id`
                                ORDER BY `group`.`name`
                                LIMIT ?, ?",
-                               local_user(),
+                               DI::userSession()->getLocalUserId(),
                                $start,
                                $count
                        ));
@@ -208,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'],
@@ -252,7 +251,7 @@ class Acl extends BaseModule
 
                        $condition = ["`parent` = ?", $conv_id];
                        $params = ['order' => ['author-name' => true]];
-                       $authors = Post::selectForUser(local_user(), ['author-link'], $condition, $params);
+                       $authors = Post::selectForUser(DI::userSession()->getLocalUserId(), ['author-link'], $condition, $params);
                        $item_authors = [];
                        while ($author = Post::fetch($authors)) {
                                $item_authors[$author['author-link']] = $author['author-link'];
@@ -269,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'],
@@ -305,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;
        }
 }