]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Tag.php
Merge pull request #10116 from mexon/mat/addon-console-command
[friendica.git] / src / Model / Tag.php
index 8ffb5b64f88957461c17ec32962b2352494e52c9..8f132e82f3614168b91812480bc21c16f6a17173 100644 (file)
@@ -340,7 +340,7 @@ class Tag
        public static function createImplicitMentions(int $uri_id, int $parent_uri_id)
        {
                // Always mention the direct parent author
-               $parent = Item::selectFirst(['author-link', 'author-name'], ['uri-id' => $parent_uri_id]);
+               $parent = Post::selectFirst(['author-link', 'author-name'], ['uri-id' => $parent_uri_id]);
                self::store($uri_id, self::IMPLICIT_MENTION, $parent['author-name'], $parent['author-link']);
 
                if (DI::config()->get('system', 'disable_implicit_mentions')) {
@@ -407,7 +407,7 @@ class Tag
 
                $searchpath = DI::baseUrl() . "/search?tag=";
 
-               $taglist = DBA::select('tag-view', ['type', 'name', 'url'],
+               $taglist = DBA::select('tag-view', ['type', 'name', 'url', 'cid'],
                        ['uri-id' => $item['uri-id'], 'type' => [self::HASHTAG, self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION]]);
                while ($tag = DBA::fetch($taglist)) {
                        if ($tag['url'] == '') {
@@ -428,7 +428,11 @@ class Tag
                                        break;
                                case self::MENTION:
                                case self::EXCLUSIVE_MENTION:
+                                       if (!empty($tag['cid'])) {
+                                               $tag['url'] = Contact::magicLinkById($tag['cid']);
+                                       } else {
                                                $tag['url'] = Contact::magicLink($tag['url']);
+                                       }
                                        $return['mentions'][] = $prefix . '<a href="' . $tag['url'] . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($tag['name']) . '</a>';
                                        $return['tags'][] = $prefix . '<a href="' . $tag['url'] . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($tag['name']) . '</a>';
                                        break;
@@ -451,12 +455,11 @@ class Tag
         */
        public static function countByTag(string $search, int $uid = 0)
        {
-               $condition = ["`name` = ? AND (NOT `private` OR (`private` AND `uid` = ?))
-                       AND `uri-id` IN (SELECT `uri-id` FROM `item` WHERE `network` IN (?, ?, ?, ?))",
-                       $search, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
-               $params = ['group_by' => ['uri-id']];
+               $condition = ["`name` = ? AND (`uid` = ? OR (`uid` = ? AND NOT `global`))
+                       AND (`network` IN (?, ?, ?, ?) OR (`uid` = ? AND `uid` != ?))",
+                       $search, 0, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, $uid, 0];
 
-               return DBA::count('tag-search-view', $condition, $params);
+               return DBA::count('tag-search-view', $condition);
        }
 
        /**
@@ -471,9 +474,9 @@ class Tag
         */
        public static function getURIIdListByTag(string $search, int $uid = 0, int $start = 0, int $limit = 100, int $last_uriid = 0)
        {
-               $condition = ["`name` = ? AND (NOT `private` OR (`private` AND `uid` = ?))
-                       AND `uri-id` IN (SELECT `uri-id` FROM `item` WHERE `network` IN (?, ?, ?, ?))",
-                       $search, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
+               $condition = ["`name` = ? AND (`uid` = ? OR (`uid` = ? AND NOT `global`))
+                       AND (`network` IN (?, ?, ?, ?) OR (`uid` = ? AND `uid` != ?))",
+                       $search, 0, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, $uid, 0];
 
                if (!empty($last_uriid)) {
                        $condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $last_uriid]);
@@ -481,7 +484,6 @@ class Tag
 
                $params = [
                        'order' => ['uri-id' => true],
-                       'group_by' => ['uri-id'],
                        'limit' => [$start, $limit]
                ];