X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FBaseSearch.php;h=4a25b71a561d56fc641205121b63d5193b420e69;hb=8b02c285472ea28002cf9c8924e2885dd207ccd8;hp=77abae007acadc77d12cfc4ba3c37a6ef0970991;hpb=aa0b485f3dca72c5448076e913fa54d948cd7731;p=friendica.git diff --git a/src/Module/BaseSearch.php b/src/Module/BaseSearch.php index 77abae007a..4a25b71a56 100644 --- a/src/Module/BaseSearch.php +++ b/src/Module/BaseSearch.php @@ -1,6 +1,6 @@ t('People Search - %s', $search); - - if (strrpos($search, '@') > 0) { - $results = Search::getContactsFromProbe($search); - } + } elseif (strpos($search, '!') === 0) { + $search = trim(substr($search, 1)); + $type = Search::TYPE_GROUP; + $header = DI::l10n()->t('Group Search - %s', $search); } - if (strpos($search, '!') === 0) { - $search = substr($search, 1); - $type = Search::TYPE_FORUM; - $header = DI::l10n()->t('Forum Search - %s', $search); - } + $search = Network::convertToIdn($search); 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 ($localSearch && empty($results)) { - $pager->setItemsPerPage(80); - $results = Search::getContactsFromLocalDirectory($search, $type, $pager->getStart(), $pager->getItemsPerPage()); - } elseif (strlen($config->get('system', 'directory')) && empty($results)) { + if (!$results->getTotal() && !$localSearch && Search::getGlobalDirectory()) { $results = Search::getContactsFromGlobalDirectory($search, $type, $pager->getPage()); $pager->setItemsPerPage($results->getItemsPage()); } + if (!$results->getTotal()) { + $pager->setItemsPerPage(80); + $results = Search::getContactsFromLocalDirectory($search, $type, $pager->getStart(), $pager->getItemsPerPage()); + } + + if (!$results->getTotal()) { + $results = Search::getContactsFromProbe(Network::convertToIdn($search), $type == Search::TYPE_GROUP); + } + return self::printResult($results, $pager, $header); } @@ -111,28 +115,38 @@ class BaseSearch extends BaseModule * @throws HTTPException\InternalServerErrorException * @throws \ImagickException */ - protected static function printResult(ResultList $results, Pager $pager, $header = '') + protected static function printResult(ResultList $results, Pager $pager, string $header = ''): string { if ($results->getTotal() == 0) { - notice(DI::l10n()->t('No matches')); + DI::sysmsg()->addNotice(DI::l10n()->t('No matches')); return ''; } + $filtered = 0; + $entries = []; foreach ($results->getResults() as $result) { - // in case the result is a contact result, add a contact-specific entry if ($result instanceof ContactResult) { - $contact = Model\Contact::getByURLForUser($result->getUrl(), local_user()); + if (Network::isUriBlocked($result->getUrl())) { + $filtered++; + continue; + } + + $contact = Model\Contact::getByURLForUser($result->getUrl(), DI::userSession()->getLocalUserId()); if (!empty($contact)) { $entries[] = Contact::getContactTemplateVars($contact); } } } - $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl'); + $tpl = Renderer::getMarkupTemplate('contact/list.tpl'); return Renderer::replaceMacros($tpl, [ - 'title' => $header, + '$title' => $header, + '$filtered' => $filtered ? DI::l10n()->tt( + '%d result was filtered out because your node blocks the domain it is registered on. You can review the list of domains your node is currently blocking in the About page.', + '%d results were filtered out because your node blocks the domain they are registered on. You can review the list of domains your node is currently blocking in the About page.', + $filtered) : '', '$contacts' => $entries, '$paginate' => $pager->renderFull($results->getTotal()), ]);