3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Model;
24 use Friendica\Database\DBA;
26 use Friendica\Util\DateTimeFormat;
29 * Model for DB specific logic for the search entity
34 * Returns the list of user defined tags (e.g. #Friendica)
39 public static function getUserTags(): array
41 $user_condition = ["`verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired` AND `user`.`uid` > ?", 0];
43 $abandon_days = intval(DI::config()->get('system', 'account_abandon_days'));
44 if (!empty($abandon_days)) {
45 $user_condition = DBA::mergeConditions($user_condition, ["`last-activity` > ?", DateTimeFormat::utc('now - ' . $abandon_days . ' days')]);
48 $condition = $user_condition;
49 $condition[0] = "SELECT DISTINCT(`term`) FROM `search` INNER JOIN `user` ON `search`.`uid` = `user`.`uid` WHERE " . $user_condition[0];
50 $sql = array_shift($condition);
51 $termsStmt = DBA::p($sql, $condition);
54 while ($term = DBA::fetch($termsStmt)) {
55 $tags[] = trim(mb_strtolower($term['term']), '#');
57 DBA::close($termsStmt);
59 $condition = $user_condition;
60 $condition[0] = "SELECT `include-tags` FROM `channel` INNER JOIN `user` ON `channel`.`uid` = `user`.`uid` WHERE " . $user_condition[0];
61 $sql = array_shift($condition);
62 $channels = DBA::p($sql, $condition);
63 while ($channel = DBA::fetch($channels)) {
64 foreach (explode(',', $channel['include-tags']) as $tag) {
65 $tag = trim(mb_strtolower($tag));
69 if (!in_array($tag, $tags)) {
74 DBA::close($channels);