2019-04-30 22:14:06 +00:00
|
|
|
<?php
|
2020-02-09 14:45:36 +00:00
|
|
|
/**
|
2024-01-02 20:57:26 +00:00
|
|
|
* @copyright Copyright (C) 2010-2024, the Friendica project
|
2020-02-09 14:45:36 +00:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2019-04-30 22:14:06 +00:00
|
|
|
|
|
|
|
namespace Friendica\Model;
|
|
|
|
|
|
|
|
use Friendica\Database\DBA;
|
2023-11-15 16:19:05 +00:00
|
|
|
use Friendica\DI;
|
|
|
|
use Friendica\Util\DateTimeFormat;
|
2019-04-30 22:14:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Model for DB specific logic for the search entity
|
|
|
|
*/
|
2019-12-15 22:28:01 +00:00
|
|
|
class Search
|
2019-04-30 22:14:06 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Returns the list of user defined tags (e.g. #Friendica)
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
2022-06-23 08:56:37 +00:00
|
|
|
public static function getUserTags(): array
|
2019-04-30 22:14:06 +00:00
|
|
|
{
|
2023-11-15 16:19:05 +00:00
|
|
|
$user_condition = ["`verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired` AND `user`.`uid` > ?", 0];
|
2019-04-30 22:14:06 +00:00
|
|
|
|
2023-11-15 16:19:05 +00:00
|
|
|
$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')]);
|
|
|
|
}
|
2019-04-30 22:14:06 +00:00
|
|
|
|
2023-11-15 16:19:05 +00:00
|
|
|
$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 = [];
|
2019-04-30 22:14:06 +00:00
|
|
|
while ($term = DBA::fetch($termsStmt)) {
|
2020-09-22 15:48:44 +00:00
|
|
|
$tags[] = trim(mb_strtolower($term['term']), '#');
|
2019-04-30 22:14:06 +00:00
|
|
|
}
|
2020-04-28 07:10:18 +00:00
|
|
|
DBA::close($termsStmt);
|
2023-11-15 16:19:05 +00:00
|
|
|
|
|
|
|
$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);
|
|
|
|
|
2019-04-30 22:14:06 +00:00
|
|
|
return $tags;
|
|
|
|
}
|
|
|
|
}
|