]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Tag.php
Merge pull request #9802 from annando/mod-include
[friendica.git] / src / Model / Tag.php
index 0ab4b3a49d439b0e87b6550298931c86a1e704fe..4371a6e46ac6d597b01e1223b674fdfb5441ef1b 100644 (file)
@@ -24,6 +24,7 @@ namespace Friendica\Model;
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\Cache\Duration;
 use Friendica\Core\Logger;
+use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Database\Database;
 use Friendica\Database\DBA;
@@ -69,8 +70,8 @@ class Tag
        public static function store(int $uriid, int $type, string $name, string $url = '', $probing = true)
        {
                if ($type == self::HASHTAG) {
-                       // Remove some common "garbarge" from tags
-                       $name = trim($name, "\x00..\x20\xFF#!@,;.:'/?!^°$%".'"');
+                       // Trim Unicode non-word characters
+                       $name = preg_replace('/(^\W+)|(\W+$)/us', '', $name);
 
                        $tags = explode(self::TAG_CHARACTER[self::HASHTAG], $name);
                        if (count($tags) > 1) {
@@ -339,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')) {
@@ -450,7 +451,9 @@ class Tag
         */
        public static function countByTag(string $search, int $uid = 0)
        {
-               $condition = ["`name` = ? AND (NOT `private` OR (`private` AND `uid` = ?))", $search, $uid];
+               $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']];
 
                return DBA::count('tag-search-view', $condition, $params);
@@ -468,7 +471,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` = ?))", $search, $uid];
+               $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];
 
                if (!empty($last_uriid)) {
                        $condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $last_uriid]);
@@ -517,7 +522,7 @@ class Tag
         * @return array
         * @throws \Exception
         */
-       public static function setGlobalTrendingHashtags(int $period, $limit = 10)
+       public static function setGlobalTrendingHashtags(int $period, int $limit = 10)
        {
                $tagsStmt = DBA::p("SELECT `name` AS `term`, COUNT(*) AS `score`
                        FROM `tag-search-view`
@@ -560,7 +565,7 @@ class Tag
         * @return array
         * @throws \Exception
         */
-       public static function setLocalTrendingHashtags(int $period, $limit = 10)
+       public static function setLocalTrendingHashtags(int $period, int $limit = 10)
        {
                $tagsStmt = DBA::p("SELECT `name` AS `term`, COUNT(*) AS `score`
                        FROM `tag-search-view`