<?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
*
namespace Friendica\Module\Search;
use Friendica\App;
+use Friendica\Content\Conversation;
use Friendica\Content\Nav;
use Friendica\Content\Pager;
use Friendica\Content\Text\HTML;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\Core\Search;
-use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
{
$search = (!empty($_GET['q']) ? trim(rawurldecode($_GET['q'])) : '');
- if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
+ if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Public access denied.'));
}
- if (DI::config()->get('system', 'local_search') && !Session::isAuthenticated()) {
+ if (DI::config()->get('system', 'local_search') && !DI::userSession()->isAuthenticated()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Only logged in users are permitted to perform a search.'));
}
- if (DI::config()->get('system', 'permit_crawling') && !Session::isAuthenticated()) {
+ if (DI::config()->get('system', 'permit_crawling') && !DI::userSession()->isAuthenticated()) {
// Default values:
// 10 requests are "free", after the 11th only a call per minute is allowed
}
}
- if (local_user()) {
+ if (DI::userSession()->getLocalUserId()) {
DI::page()['aside'] .= Widget\SavedSearches::getHTML(Search::getSearchPath($search), $search);
}
$search = '#' . trim(rawurldecode($_GET['tag']));
}
- // contruct a wrapper for the search header
+ // construct a wrapper for the search header
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('content_wrapper.tpl'), [
'name' => 'search-header',
'$title' => DI::l10n()->t('Search'),
if (strpos($search, '#') === 0) {
$tag = true;
$search = substr($search, 1);
- }
-
- self::tryRedirectToProfile($search);
-
- if (strpos($search, '@') === 0 || strpos($search, '!') === 0) {
- return self::performContactSearch($search);
- }
+ } else {
+ if (strpos($search, '@') === 0 || strpos($search, '!') === 0) {
+ return self::performContactSearch($search);
+ }
- self::tryRedirectToPost($search);
-
- if (!empty($_GET['search-option'])) {
- switch ($_GET['search-option']) {
- case 'fulltext':
- break;
- case 'tags':
- $tag = true;
- break;
- case 'contacts':
- return self::performContactSearch($search, '@');
- case 'forums':
- return self::performContactSearch($search, '!');
+ self::tryRedirectToPost($search);
+
+ self::tryRedirectToProfile($search);
+
+ if (!empty($_GET['search-option'])) {
+ switch ($_GET['search-option']) {
+ case 'fulltext':
+ break;
+ case 'tags':
+ $tag = true;
+ break;
+ case 'contacts':
+ return self::performContactSearch($search, '@');
+ case 'groups':
+ return self::performContactSearch($search, '!');
+ }
}
}
// No items will be shown if the member has a blocked profile wall.
if (DI::mode()->isMobile()) {
- $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
+ $itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_mobile_network',
DI::config()->get('system', 'itemspage_network_mobile'));
} else {
- $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_network',
+ $itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_network',
DI::config()->get('system', 'itemspage_network'));
}
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage);
if ($tag) {
- Logger::info('Start tag search.', ['q' => $search]);
- $uriids = Tag::getURIIdListByTag($search, local_user(), $pager->getStart(), $pager->getItemsPerPage(), $last_uriid);
- $count = Tag::countByTag($search, local_user());
+ Logger::info('Start tag search.', ['q' => $search, 'start' => $pager->getStart(), 'items' => $pager->getItemsPerPage(), 'last' => $last_uriid]);
+ $uriids = Tag::getURIIdListByTag($search, DI::userSession()->getLocalUserId(), $pager->getStart(), $pager->getItemsPerPage(), $last_uriid);
+ $count = Tag::countByTag($search, DI::userSession()->getLocalUserId());
} else {
Logger::info('Start fulltext search.', ['q' => $search]);
- $uriids = Post\Content::getURIIdListBySearch($search, local_user(), $pager->getStart(), $pager->getItemsPerPage(), $last_uriid);
- $count = Post\Content::countBySearch($search, local_user());
+ $uriids = Post\Content::getURIIdListBySearch($search, DI::userSession()->getLocalUserId(), $pager->getStart(), $pager->getItemsPerPage(), $last_uriid);
+ $count = Post\Content::countBySearch($search, DI::userSession()->getLocalUserId());
}
if (!empty($uriids)) {
- $condition = ["(`uid` = ? OR (`uid` = ? AND NOT `global`))", 0, local_user()];
+ $condition = ["(`uid` = ? OR (`uid` = ? AND NOT `global`))", 0, DI::userSession()->getLocalUserId()];
$condition = DBA::mergeConditions($condition, ['uri-id' => $uriids]);
- $params = ['order' => ['id' => true]];
- $items = Post::toArray(Post::selectForUser(local_user(), Item::DISPLAY_FIELDLIST, $condition, $params));
+ $params = ['order' => ['uri-id' => true]];
+ $items = Post::toArray(Post::selectForUser(DI::userSession()->getLocalUserId(), Item::DISPLAY_FIELDLIST, $condition, $params));
}
if (empty($items)) {
return $o;
}
- if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
+ if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll')) {
$tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
$o .= Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
}
Logger::info('Start Conversation.', ['q' => $search]);
- $o .= DI::conversation()->create($items, 'search', false, false, 'commented', local_user());
+ $o .= DI::conversation()->render($items, Conversation::MODE_SEARCH, false, false, 'commented', DI::userSession()->getLocalUserId());
- if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
+ if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll')) {
$o .= HTML::scrollLoader();
} else {
$o .= $pager->renderMinimal($count);
$search = $matches[1];
}
- if (local_user()) {
+ if (DI::userSession()->getLocalUserId()) {
// User-specific contact URL/address search
- $contact_id = Contact::getIdForURL($search, local_user());
+ $contact_id = Contact::getIdForURL($search, DI::userSession()->getLocalUserId());
if (!$contact_id) {
// User-specific contact URL/address search and probe
$contact_id = Contact::getIdForURL($search);
$search = Network::convertToIdn($search);
- if (local_user()) {
+ if (DI::userSession()->getLocalUserId()) {
// Post URL search
- $item_id = Item::fetchByLink($search, local_user());
+ $item_id = Item::fetchByLink($search, DI::userSession()->getLocalUserId());
if (!$item_id) {
// If the user-specific search failed, we search and probe a public post
$item_id = Item::fetchByLink($search);