From 639a781125aa4dc97b8af480130289cb15025802 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 9 Mar 2021 22:34:41 +0000 Subject: [PATCH] Block tags from the trending tags --- src/Model/Tag.php | 25 +++++++++++++++++++++++-- static/defaults.config.php | 4 ++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Model/Tag.php b/src/Model/Tag.php index 451ed687b..c7155b539 100644 --- a/src/Model/Tag.php +++ b/src/Model/Tag.php @@ -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); diff --git a/static/defaults.config.php b/static/defaults.config.php index 3e05cab2b..7578e3c55 100644 --- a/static/defaults.config.php +++ b/static/defaults.config.php @@ -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,