]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Tag.php
Merge pull request #10093 from urbalazs/copyright-2021
[friendica.git] / src / Model / Tag.php
index 451ed687b3b06f41f9c75da78cd69d3d3df9d91c..796cc13f8872a6653b0c925252862b7e43b6e683 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -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,10 +545,12 @@ class Tag
         */
        public static function setGlobalTrendingHashtags(int $period, int $limit = 10)
        {
-               $tagsStmt = DBA::p("SELECT `name` AS `term`, COUNT(*) AS `score`
+               $block_sql = self::getBlockedSQL();
+
+               $tagsStmt = DBA::p("SELECT `name` AS `term`, COUNT(*) AS `score`, COUNT(DISTINCT(`author-id`)) as `authors`
                        FROM `tag-search-view`
-                       WHERE `private` = ? AND `uid` = ? AND `received` > DATE_SUB(NOW(), INTERVAL ? HOUR)
-                       GROUP BY `term` ORDER BY `score` DESC LIMIT ?",
+                       WHERE `private` = ? AND `uid` = ? AND `received` > DATE_SUB(NOW(), INTERVAL ? HOUR) $block_sql
+                       GROUP BY `term` ORDER BY `authors` DESC, `score` DESC LIMIT ?",
                        Item::PUBLIC, 0, $period, $limit);
 
                if (DBA::isResult($tagsStmt)) {
@@ -571,10 +590,12 @@ class Tag
         */
        public static function setLocalTrendingHashtags(int $period, int $limit = 10)
        {
-               $tagsStmt = DBA::p("SELECT `name` AS `term`, COUNT(*) AS `score`
+               $block_sql = self::getBlockedSQL();
+
+               $tagsStmt = DBA::p("SELECT `name` AS `term`, COUNT(*) AS `score`, COUNT(DISTINCT(`author-id`)) as `authors`
                        FROM `tag-search-view`
-                       WHERE `private` = ? AND `wall` AND `origin` AND `received` > DATE_SUB(NOW(), INTERVAL ? HOUR)
-                       GROUP BY `term` ORDER BY `score` DESC LIMIT ?",
+                       WHERE `private` = ? AND `wall` AND `origin` AND `received` > DATE_SUB(NOW(), INTERVAL ? HOUR) $block_sql
+                       GROUP BY `term` ORDER BY `authors` DESC, `score` DESC LIMIT ?",
                        Item::PUBLIC, $period, $limit);
 
                if (DBA::isResult($tagsStmt)) {