]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/BaseSearch.php
The priority is now a class constant
[friendica.git] / src / Module / BaseSearch.php
index bccfc94de594d9c0b6d42d8a78adf5bc5272203d..276598131b6411513fef1eb3b1fae9655bf519d1 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -30,6 +30,7 @@ use Friendica\Model;
 use Friendica\Network\HTTPException;
 use Friendica\Object\Search\ContactResult;
 use Friendica\Object\Search\ResultList;
+use Friendica\Util\Network;
 
 /**
  * Base class for search modules
@@ -46,9 +47,8 @@ class BaseSearch extends BaseModule
         * @throws HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function performContactSearch($search, $prefix = '')
+       public static function performContactSearch(string $search, string $prefix = ''): string
        {
-               $a      = DI::app();
                $config = DI::config();
 
                $type = Search::TYPE_ALL;
@@ -64,21 +64,23 @@ class BaseSearch extends BaseModule
                $header = '';
 
                if (strpos($search, '@') === 0) {
-                       $search  = substr($search, 1);
+                       $search  = trim(substr($search, 1));
                        $type    = Search::TYPE_PEOPLE;
                        $header  = DI::l10n()->t('People Search - %s', $search);
 
                        if (strrpos($search, '@') > 0) {
-                               $results = Search::getContactsFromProbe($search);
+                               $results = Search::getContactsFromProbe(Network::convertToIdn($search));
                        }
                }
 
                if (strpos($search, '!') === 0) {
-                       $search = substr($search, 1);
+                       $search = trim(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',
                                DI::config()->get('system', 'itemspage_network_mobile'));
@@ -92,7 +94,7 @@ class BaseSearch extends BaseModule
                if ($localSearch && empty($results)) {
                        $pager->setItemsPerPage(80);
                        $results = Search::getContactsFromLocalDirectory($search, $type, $pager->getStart(), $pager->getItemsPerPage());
-               } elseif (strlen($config->get('system', 'directory')) && empty($results)) {
+               } elseif (Search::getGlobalDirectory() && empty($results)) {
                        $results = Search::getContactsFromGlobalDirectory($search, $type, $pager->getPage());
                        $pager->setItemsPerPage($results->getItemsPage());
                }
@@ -111,7 +113,7 @@ 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'));