]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Tag.php
Fix uddate issues and improve speed when displaying contact posts
[friendica.git] / src / Model / Tag.php
index 0e891f9c6f27870e314aa75a7b8e74329f3e94ff..45824bbc1a4567f10b0855cfef4e63260e0e4f25 100644 (file)
@@ -25,13 +25,12 @@ use Friendica\Content\Text\BBCode;
 use Friendica\Core\Cache\Enum\Duration;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
-use Friendica\Core\System;
 use Friendica\Database\Database;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Protocol\ActivityPub;
 use Friendica\Util\DateTimeFormat;
-use Friendica\Util\Network;
+use Friendica\Util\HTTPSignature;
 use Friendica\Util\Strings;
 
 /**
@@ -50,14 +49,16 @@ class Tag
         */
        const IMPLICIT_MENTION  = 8;
        /**
-        * An exclusive mention transmits the post only to the target account without transmitting it to the followers, usually a forum.
+        * An exclusive mention transmits the post only to the target account without transmitting it to the followers, usually a group.
         */
        const EXCLUSIVE_MENTION = 9;
 
-       const TO  = 10;
-       const CC  = 11;
-       const BTO = 12;
-       const BCC = 13;
+       const TO         = 10;
+       const CC         = 11;
+       const BTO        = 12;
+       const BCC        = 13;
+       const AUDIENCE   = 14;
+       const ATTRIBUTED = 15;
 
        const ACCOUNT             = 1;
        const GENERAL_COLLECTION  = 2;
@@ -103,14 +104,14 @@ class Tag
                $cid = 0;
                $tagid = 0;
 
-               if (in_array($type, [self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION, self::TO, self::CC, self::BTO, self::BCC])) {
+               if (in_array($type, [self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION, self::TO, self::CC, self::BTO, self::BCC, self::AUDIENCE, self::ATTRIBUTED])) {
                        if (empty($url)) {
                                // No mention without a contact url
                                return;
                        }
 
                        if ((substr($url, 0, 7) == 'https//') || (substr($url, 0, 6) == 'http//')) {
-                               Logger::notice('Wrong scheme in url', ['url' => $url, 'callstack' => System::callstack(20)]);
+                               Logger::notice('Wrong scheme in url', ['url' => $url]);
                        }
 
                        $cid = Contact::getIdForURL($url, 0, false);
@@ -130,7 +131,7 @@ class Tag
                }
 
                if (empty($cid)) {
-                       if (!in_array($type, [self::TO, self::CC, self::BTO, self::BCC])) {
+                       if (!in_array($type, [self::TO, self::CC, self::BTO, self::BCC, self::AUDIENCE, self::ATTRIBUTED])) {
                                if (($type != self::HASHTAG) && !empty($url) && ($url != $name)) {
                                        $url = strtolower($url);
                                } else {
@@ -157,7 +158,7 @@ class Tag
 
                DBA::insert('post-tag', $fields, Database::INSERT_IGNORE);
 
-               Logger::debug('Stored tag/mention', ['uri-id' => $uriId, 'tag-id' => $tagid, 'contact-id' => $cid, 'name' => $name, 'type' => $type, 'callstack' => System::callstack(8)]);
+               Logger::debug('Stored tag/mention', ['uri-id' => $uriId, 'tag-id' => $tagid, 'contact-id' => $cid, 'name' => $name, 'type' => $type]);
        }
 
        /**
@@ -195,7 +196,7 @@ class Tag
                                $target = self::ACCOUNT;
                                Logger::debug('URL is an account', ['url' => $url]);
                        } elseif ($fetch && ($target != self::GENERAL_COLLECTION)) {
-                               $content = ActivityPub::fetchContent($url);
+                               $content = HTTPSignature::fetch($url);
                                if (!empty($content['type']) && ($content['type'] == 'OrderedCollection')) {
                                        $target = self::GENERAL_COLLECTION;
                                        Logger::debug('URL is an ordered collection', ['url' => $url]);
@@ -314,7 +315,7 @@ class Tag
         */
        public static function storeFromArray(array $item, string $tags = null)
        {
-               Logger::info('Check for tags', ['uri-id' => $item['uri-id'], 'hash' => $tags, 'callstack' => System::callstack()]);
+               Logger::info('Check for tags', ['uri-id' => $item['uri-id'], 'hash' => $tags]);
 
                if (is_null($tags)) {
                        $tags = self::TAG_CHARACTER[self::HASHTAG] . self::TAG_CHARACTER[self::MENTION] . self::TAG_CHARACTER[self::EXCLUSIVE_MENTION];
@@ -345,7 +346,7 @@ class Tag
         */
        public static function storeRawTagsFromBody(int $uriId, string $body)
        {
-               Logger::info('Check for tags', ['uri-id' => $uriId, 'callstack' => System::callstack()]);
+               Logger::info('Check for tags', ['uri-id' => $uriId]);
 
                $result = BBCode::getTags($body);
                if (empty($result)) {
@@ -394,7 +395,7 @@ class Tag
                        return;
                }
 
-               Logger::debug('Removing tag/mention', ['uri-id' => $uriId, 'tid' => $tag['tid'], 'name' => $name, 'url' => $url, 'callstack' => System::callstack(8)]);
+               Logger::debug('Removing tag/mention', ['uri-id' => $uriId, 'tid' => $tag['tid'], 'name' => $name, 'url' => $url]);
                DBA::delete('post-tag', ['uri-id' => $uriId, 'type' => $type, 'tid' => $tag['tid'], 'cid' => $tag['cid']]);
        }
 
@@ -485,7 +486,7 @@ class Tag
         *
         * @return boolean
         */
-       public static function isMentioned(int $uriId, string $url, array $type = [self::MENTION, self::EXCLUSIVE_MENTION]): bool
+       public static function isMentioned(int $uriId, string $url, array $type = [self::MENTION, self::EXCLUSIVE_MENTION, self::AUDIENCE]): bool
        {
                $tags = self::getByURIId($uriId, $type);
                foreach ($tags as $tag) {
@@ -826,12 +827,13 @@ class Tag
        public static function getUIDListByURIId(int $uriId): array
        {
                $uids = [];
-               $tags = self::getByURIId($uriId, [self::HASHTAG]);
 
-               foreach ($tags as $tag) {
-                       $uids = array_merge($uids, self::getUIDListByTag(self::TAG_CHARACTER[self::HASHTAG] . $tag['name']));
+               foreach (self::getByURIId($uriId, [self::HASHTAG]) as $tag) {
+                       foreach (self::getUIDListByTag(self::TAG_CHARACTER[self::HASHTAG] . $tag['name']) as $uid) {
+                               $uids[$uid][] = $tag['name'];
+                       } 
                }
 
-               return array_unique($uids);
+               return $uids;
        }
 }