]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Search.php
Posts per author/server on the community pages (#13764)
[friendica.git] / src / Model / Search.php
index cb518c0b17b26fc4542baaf36da7474b3b3e5f8a..316e41c250564f632e5d2eb85e940c3a9bd44ee7 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -22,6 +22,8 @@
 namespace Friendica\Model;
 
 use Friendica\Database\DBA;
+use Friendica\DI;
+use Friendica\Util\DateTimeFormat;
 
 /**
  * Model for DB specific logic for the search entity
@@ -36,14 +38,43 @@ class Search
         */
        public static function getUserTags(): array
        {
-               $termsStmt = DBA::p("SELECT DISTINCT(`term`) FROM `search`");
+               $user_condition = ["`verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired` AND `user`.`uid` > ?", 0];
 
-               $tags = [];
+               $abandon_days = intval(DI::config()->get('system', 'account_abandon_days'));
+               if (!empty($abandon_days)) {
+                       $user_condition = DBA::mergeConditions($user_condition, ["`last-activity` > ?", DateTimeFormat::utc('now - ' . $abandon_days . ' days')]);
+               }
 
+               $condition = $user_condition;
+               $condition[0] = "SELECT DISTINCT(`term`) FROM `search` INNER JOIN `user` ON `search`.`uid` = `user`.`uid` WHERE " . $user_condition[0];
+               $sql = array_shift($condition);
+               $termsStmt = DBA::p($sql, $condition);
+
+               $tags = [];
                while ($term = DBA::fetch($termsStmt)) {
                        $tags[] = trim(mb_strtolower($term['term']), '#');
                }
                DBA::close($termsStmt);
+
+               $condition = $user_condition;
+               $condition[0] = "SELECT `include-tags` FROM `channel` INNER JOIN `user` ON `channel`.`uid` = `user`.`uid` WHERE " . $user_condition[0];
+               $sql = array_shift($condition);
+               $channels = DBA::p($sql, $condition);
+               while ($channel = DBA::fetch($channels)) {
+                       foreach (explode(',', $channel['include-tags']) as $tag) {
+                               $tag = trim(mb_strtolower($tag));
+                               if (empty($tag)) {
+                                       continue;
+                               }
+                               if (!in_array($tag, $tags)) {
+                                       $tags[] = $tag;
+                               }
+                       }
+               }
+               DBA::close($channels);
+
+               sort($tags);
+
                return $tags;
        }
 }