X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FTag.php;h=799296dfbf6a4755b0ff3659a391ddff95f44789;hb=eae1383f48239b07741197762b68bebabc49df89;hp=538cedfb6b29b639890555816ec7dbef004dc383;hpb=fd8f4269ff6ceb80e4977c052c6d9728d7af324b;p=friendica.git diff --git a/src/Model/Tag.php b/src/Model/Tag.php index 538cedfb6b..799296dfbf 100644 --- a/src/Model/Tag.php +++ b/src/Model/Tag.php @@ -156,7 +156,7 @@ class Tag DBA::insert('post-tag', $fields, Database::INSERT_IGNORE); - Logger::info('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, 'callstack' => System::callstack(8)]); } /** @@ -243,9 +243,8 @@ class Tag return $tid; } - // Also log type and tag id + // Also log type $fields['type'] = $type; - $fields['tid'] = $tid; Logger::error('No tag id created', $fields); return 0; @@ -258,17 +257,16 @@ class Tag * @param string $hash * @param string $name * @param string $url - * @param boolean $probing Whether probing is active * @return void */ - public static function storeByHash(int $uriId, string $hash, string $name, string $url = '', bool $probing = true) + public static function storeByHash(int $uriId, string $hash, string $name, string $url = '') { $type = self::getTypeForHash($hash); if ($type == self::UNKNOWN) { return; } - self::store($uriId, $type, $name, $url, $probing); + self::store($uriId, $type, $name, $url); } /** @@ -298,34 +296,39 @@ class Tag * @param integer $uriId URI-Id * @param string $body Body of the post * @param string $tags Accepted tags - * @param boolean $probing Perform a probing for contacts, adding them if needed * @return void */ - public static function storeFromBody(int $uriId, string $body, string $tags = null, bool $probing = true) + public static function storeFromBody(int $uriId, string $body, string $tags = null) { - Logger::info('Check for tags', ['uri-id' => $uriId, 'hash' => $tags, 'callstack' => System::callstack()]); + $item = ['uri-id' => $uriId, 'body' => $body, 'quote-uri-id' => null]; + self::storeFromArray($item, $tags); + } + + /** + * Store tags and mentions from the item array + * + * @param array $item Item array + * @param string $tags Accepted tags + * @return void + */ + public static function storeFromArray(array $item, string $tags = null) + { + Logger::info('Check for tags', ['uri-id' => $item['uri-id'], 'hash' => $tags, 'callstack' => System::callstack()]); if (is_null($tags)) { $tags = self::TAG_CHARACTER[self::HASHTAG] . self::TAG_CHARACTER[self::MENTION] . self::TAG_CHARACTER[self::EXCLUSIVE_MENTION]; } - // Only remove the shared data from "real" reshares - $shared = BBCode::fetchShareAttributes($body); - if (!empty($shared['guid'])) { - if (preg_match("/\s*\[share .*?\](.*?)\[\/share\]\s*/ism", $body, $matches)) { - $share_body = $matches[1]; - } - $body = preg_replace("/\s*\[share .*?\].*?\[\/share\]\s*/ism", '', $body); + foreach (self::getFromBody($item['body'], $tags) as $tag) { + self::storeByHash($item['uri-id'], $tag[1], $tag[3], $tag[2]); } - foreach (self::getFromBody($body, $tags) as $tag) { - self::storeByHash($uriId, $tag[1], $tag[3], $tag[2], $probing); - } + $shared = DI::contentItem()->getSharedPost($item, ['uri-id']); // Search for hashtags in the shared body (but only if hashtags are wanted) - if (!empty($share_body) && (strpos($tags, self::TAG_CHARACTER[self::HASHTAG]) !== false)) { - foreach (self::getFromBody($share_body, self::TAG_CHARACTER[self::HASHTAG]) as $tag) { - self::storeByHash($uriId, $tag[1], $tag[3], $tag[2], $probing); + if (!empty($shared) && (strpos($tags, self::TAG_CHARACTER[self::HASHTAG]) !== false)) { + foreach (self::getByURIId($shared['post']['uri-id'], [self::HASHTAG]) as $tag) { + self::store($item['uri-id'], $tag['type'], $tag['name'], $tag['url']); } } } @@ -390,7 +393,7 @@ class Tag return; } - Logger::info('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, 'callstack' => System::callstack(8)]); DBA::delete('post-tag', ['uri-id' => $uriId, 'type' => $type, 'tid' => $tag['tid'], 'cid' => $tag['cid']]); } @@ -472,6 +475,26 @@ class Tag return DBA::selectToArray('tag-view', ['type', 'name', 'url', 'tag-type'], $condition); } + /** + * Checks if the given url is mentioned in the post + * + * @param integer $uriId + * @param string $url + * @param array $type + * + * @return boolean + */ + public static function isMentioned(int $uriId, string $url, array $type = [self::MENTION, self::EXCLUSIVE_MENTION]): bool + { + $tags = self::getByURIId($uriId, $type); + foreach ($tags as $tag) { + if (Strings::compareLink($url, $tag['url'])) { + return true; + } + } + return false; + } + /** * Return a string with all tags and mentions * @@ -546,7 +569,7 @@ class Tag break; default: - Logger:warning('Unknown tag type found', $tag); + Logger::warning('Unknown tag type found', $tag); } } DBA::close($taglist);