X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2FModel%2FSearch.php;h=316e41c250564f632e5d2eb85e940c3a9bd44ee7;hb=f81192b4c3838480154301ac25cbbbed58593380;hp=5829ff91d0c7dc69eb3370f882a2587f593836e2;hpb=c9cce8492e5b2607b2a092474d1de4d188b7a2c9;p=friendica.git diff --git a/src/Model/Search.php b/src/Model/Search.php index 5829ff91d0..316e41c250 100644 --- a/src/Model/Search.php +++ b/src/Model/Search.php @@ -1,31 +1,79 @@ . + * + */ namespace Friendica\Model; -use Friendica\BaseObject; use Friendica\Database\DBA; +use Friendica\DI; +use Friendica\Util\DateTimeFormat; /** * Model for DB specific logic for the search entity */ -class Search extends BaseObject +class Search { /** * Returns the list of user defined tags (e.g. #Friendica) * * @return array - * * @throws \Exception */ - public static function getUserTags() + 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($term['term'], '#'); + $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; }