]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/BaseSearchModule.php
Remove superfluous includes in profile modules
[friendica.git] / src / Module / BaseSearchModule.php
index 3393b34123923fe05669a5004ca51093ae85f2b0..42bb943da0a5c54f6b31fcd40697e12bd99c261a 100644 (file)
@@ -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,17 +49,21 @@ 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);
@@ -86,12 +90,10 @@ class BaseSearchModule extends BaseModule
        protected static function printResult(ResultList $results, Pager $pager, $header = '')
        {
                if ($results->getTotal() == 0) {
-                       info(L10n::t('No matches'));
+                       info(DI::l10n()->t('No matches'));
                        return '';
                }
 
-               $a = self::getApp();
-
                $id      = 0;
                $entries = [];
                foreach ($results->getResults() as $result) {
@@ -124,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,