Block tags from the trending tags
authorMichael <heluecht@pirati.ca>
Tue, 9 Mar 2021 22:34:41 +0000 (22:34 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 9 Mar 2021 22:34:41 +0000 (22:34 +0000)
src/Model/Tag.php
static/defaults.config.php

index 451ed68..c7155b5 100644 (file)
@@ -518,6 +518,23 @@ class Tag
                }
        }
 
+       /**
+        * Fetch the blocked tags as SQL
+        *
+        * @return string 
+        */
+       private static function getBlockedSQL()
+       {
+               $blocked_txt = DI::config()->get('system', 'blocked_tags');
+               if (empty($blocked_txt)) {
+                       return '';
+               }
+
+               $blocked = explode(',', $blocked_txt);
+               array_walk($blocked, function(&$value) { $value = "'" . DBA::escape(trim($value)) . "'";});
+               return " AND NOT `name` IN (" . implode(',', $blocked) . ")";
+       }
+
        /**
         * Creates a list of the most frequent global hashtags over the given period
         *
@@ -528,9 +545,11 @@ class Tag
         */
        public static function setGlobalTrendingHashtags(int $period, int $limit = 10)
        {
+               $block_sql = self::getBlockedSQL();
+
                $tagsStmt = DBA::p("SELECT `name` AS `term`, COUNT(*) AS `score`
                        FROM `tag-search-view`
-                       WHERE `private` = ? AND `uid` = ? AND `received` > DATE_SUB(NOW(), INTERVAL ? HOUR)
+                       WHERE `private` = ? AND `uid` = ? AND `received` > DATE_SUB(NOW(), INTERVAL ? HOUR) $block_sql
                        GROUP BY `term` ORDER BY `score` DESC LIMIT ?",
                        Item::PUBLIC, 0, $period, $limit);
 
@@ -571,9 +590,11 @@ class Tag
         */
        public static function setLocalTrendingHashtags(int $period, int $limit = 10)
        {
+               $block_sql = self::getBlockedSQL();
+
                $tagsStmt = DBA::p("SELECT `name` AS `term`, COUNT(*) AS `score`
                        FROM `tag-search-view`
-                       WHERE `private` = ? AND `wall` AND `origin` AND `received` > DATE_SUB(NOW(), INTERVAL ? HOUR)
+                       WHERE `private` = ? AND `wall` AND `origin` AND `received` > DATE_SUB(NOW(), INTERVAL ? HOUR) $block_sql
                        GROUP BY `term` ORDER BY `score` DESC LIMIT ?",
                        Item::PUBLIC, $period, $limit);
 
index 3e05cab..7578e3c 100644 (file)
@@ -121,6 +121,10 @@ return [
                // Deny public access to the local user directory.
                'block_local_dir' => false,
 
+               // blocked_tags (String)
+               // Comma separated list of hash tags that shouldn't be displayed in the trending tags
+               'blocked_tags' => '',
+
                // community_no_sharer (Boolean)
                // Don't display sharing accounts on the global community
                'community_no_sharer' => false,