X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FBaseSearchModule.php;h=42bb943da0a5c54f6b31fcd40697e12bd99c261a;hb=1fc1989f93ee9a8a6014f4db6b4c260443f813d2;hp=226a4da4d58661724c63ce79cd9aaf8ff89d186a;hpb=862159c712b3835a43eb2c380dde6e812f07a42b;p=friendica.git diff --git a/src/Module/BaseSearchModule.php b/src/Module/BaseSearchModule.php index 226a4da4d5..42bb943da0 100644 --- a/src/Module/BaseSearchModule.php +++ b/src/Module/BaseSearchModule.php @@ -5,15 +5,14 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Content\ContactSelector; use Friendica\Content\Pager; -use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\Search; +use Friendica\DI; use Friendica\Model; use Friendica\Network\HTTPException; use Friendica\Object\Search\ContactResult; use Friendica\Object\Search\ResultList; use Friendica\Util\Proxy as ProxyUtils; -use Friendica\Util\Strings; /** * Base class for search modules @@ -21,24 +20,25 @@ use Friendica\Util\Strings; class BaseSearchModule extends BaseModule { /** - * Performs a search with an optional prefix + * Performs a contact search with an optional prefix * + * @param string $search Search query * @param string $prefix A optional prefix (e.g. @ or !) for searching * * @return string * @throws HTTPException\InternalServerErrorException * @throws \ImagickException */ - public static function performSearch($prefix = '') + public static function performContactSearch($search, $prefix = '') { - $a = self::getApp(); - $config = $a->getConfig(); + $a = DI::app(); + $config = DI::config(); $type = Search::TYPE_ALL; $localSearch = $config->get('system', 'poco_local_search'); - $search = $prefix . Strings::escapeTags(trim(defaults($_REQUEST, 'search', ''))); + $search = $prefix . $search; if (!$search) { return ''; @@ -49,22 +49,25 @@ class BaseSearchModule extends BaseModule if (strpos($search, '@') === 0) { $search = substr($search, 1); $type = Search::TYPE_PEOPLE; - $header = L10n::t('People Search - %s', $search); - $results = Search::getContactsFromProbe($search); + $header = DI::l10n()->t('People Search - %s', $search); + + if (strrpos($search, '@') > 0) { + $results = Search::getContactsFromProbe($search); + } } if (strpos($search, '!') === 0) { $search = substr($search, 1); $type = Search::TYPE_FORUM; - $header = L10n::t('Forum Search - %s', $search); + $header = DI::l10n()->t('Forum Search - %s', $search); } - $pager = new Pager($a->query_string); + $args = DI::args(); + $pager = new Pager($args->getQueryString()); if ($localSearch && empty($results)) { $pager->setItemsPerPage(80); $results = Search::getContactsFromLocalDirectory($search, $type, $pager->getStart(), $pager->getItemsPerPage()); - } elseif (strlen($config->get('system', 'directory')) && empty($results)) { $results = Search::getContactsFromGlobalDirectory($search, $type, $pager->getPage()); $pager->setItemsPerPage($results->getItemsPage()); @@ -86,13 +89,11 @@ class BaseSearchModule extends BaseModule */ protected static function printResult(ResultList $results, Pager $pager, $header = '') { - if (empty($results) || empty($results->getResults())) { - info(L10n::t('No matches') . EOL); + if ($results->getTotal() == 0) { + info(DI::l10n()->t('No matches')); return ''; } - $a = self::getApp(); - $id = 0; $entries = []; foreach ($results->getResults() as $result) { @@ -125,14 +126,14 @@ class BaseSearchModule extends BaseModule $photo_menu = []; } } else { - $connLink = $a->getBaseURL() . '/follow/?url=' . $result->getUrl(); - $connTxt = L10n::t('Connect'); + $connLink = DI::baseUrl()->get() . '/follow/?url=' . $result->getUrl(); + $connTxt = DI::l10n()->t('Connect'); - $photo_menu['profile'] = [L10n::t("View Profile"), Model\Contact::magicLink($result->getUrl())]; - $photo_menu['follow'] = [L10n::t("Connect/Follow"), $connLink]; + $photo_menu['profile'] = [DI::l10n()->t("View Profile"), Model\Contact::magicLink($result->getUrl())]; + $photo_menu['follow'] = [DI::l10n()->t("Connect/Follow"), $connLink]; } - $photo = str_replace("http:///photo/", get_server() . "/photo/", $result->getPhoto()); + $photo = str_replace("http:///photo/", Search::getGlobalDirectory() . "/photo/", $result->getPhoto()); $entry = [ 'alt_text' => $alt_text,