]> git.mxchange.org Git - friendica.git/commitdiff
Split Directory Search as a base for further changes
authorPhilipp Holzer <admin+github@philipp.info>
Sun, 19 May 2019 03:06:02 +0000 (05:06 +0200)
committerPhilipp Holzer <admin+github@philipp.info>
Sun, 19 May 2019 03:06:02 +0000 (05:06 +0200)
mod/search.php
src/Module/BaseSearchModule.php
src/Module/Search/Directory.php

index 816ebf18a96a559e25548e46f7c9574a068993c6..4144e2608f91f6b9bb7a44b4e5c4fd6a4e3bb1bd 100644 (file)
@@ -14,7 +14,7 @@ use Friendica\Core\Logger;
 use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
 use Friendica\Model\Item;
-use Friendica\Module\Directory;
+use Friendica\Module\BaseSearchModule;
 use Friendica\Util\Strings;
 
 function search_saved_searches() {
@@ -148,10 +148,10 @@ function search_content(App $a) {
                $search = substr($search,1);
        }
        if (strpos($search,'@') === 0) {
-               return Directory::performSearch();
+               return BaseSearchModule::performSearch();
        }
        if (strpos($search,'!') === 0) {
-               return Directory::performSearch();
+               return BaseSearchModule::performSearch();
        }
 
        if (!empty($_GET['search-option']))
@@ -162,9 +162,9 @@ function search_content(App $a) {
                                $tag = true;
                                break;
                        case 'contacts':
-                               return Directory::performSearch('@');
+                               return BaseSearchModule::performSearch('@');
                        case 'forums':
-                               return Directory::performSearch('!');
+                               return BaseSearchModule::performSearch('!');
                }
 
        if (!$search)
index d11f7e98609728a867ad6c3d55a4b2ab2bd40284..7028208286bb6ba860798dcb751f65e073a721ff 100644 (file)
@@ -10,12 +10,65 @@ use Friendica\Core\Renderer;
 use Friendica\Object\Search\ResultList;
 use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Model;
+use Friendica\Util\Strings;
 
 /**
  * Base class for search modules
  */
-abstract class BaseSearchModule extends BaseModule
+class BaseSearchModule extends BaseModule
 {
+       /**
+        * Performs a search with an optional prefix
+        *
+        * @param string $prefix A optional prefix (e.g. @ or !) for searching
+        *
+        * @return string
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       public static function performSearch($prefix = '')
+       {
+               $a      = self::getApp();
+               $config = $a->getConfig();
+
+               $community = false;
+
+               $localSearch = $config->get('system', 'poco_local_search');
+
+               $search = $prefix . Strings::escapeTags(trim(defaults($_REQUEST, 'search', '')));
+
+               if (!$search) {
+                       return '';
+               }
+
+               $header = '';
+
+               if (strpos($search, '@') === 0) {
+                       $search  = substr($search, 1);
+                       $header  = L10n::t('People Search - %s', $search);
+                       $results = Model\Search::searchUser($search);
+               }
+
+               if (strpos($search, '!') === 0) {
+                       $search    = substr($search, 1);
+                       $community = true;
+                       $header    = L10n::t('Forum Search - %s', $search);
+               }
+
+               $pager = new Pager($a->query_string);
+
+               if ($localSearch && empty($results)) {
+                       $pager->setItemsPerPage(80);
+                       $results = Model\Search::searchLocal($search, $pager->getStart(), $pager->getItemsPerPage(), $community);
+
+               } elseif (strlen($config->get('system', 'directory')) && empty($results)) {
+                       $results = Model\Search::searchDirectory($search, $pager->getPage());
+                       $pager->setItemsPerPage($results->getItemsPage());
+               }
+
+               return self::printResult($results, $pager, $header);
+       }
+
        /**
         * Prints a human readable search result
         *
index 900bf818bc57e7cde59994e3a1e39e74564bab5a..76ada50d5925bd3d995269891812fb7ed0a913d0 100644 (file)
@@ -2,19 +2,12 @@
 
 namespace Friendica\Module\Search;
 
-use Friendica\BaseModule;
-use Friendica\Content\ContactSelector;
-use Friendica\Content\Pager;
 use Friendica\Content\Widget;
 use Friendica\Core\L10n;
-use Friendica\Core\Renderer;
 use Friendica\Module\BaseSearchModule;
-use Friendica\Util\Proxy as ProxyUtils;
-use Friendica\Util\Strings;
-use Friendica\Model;
 
 /**
- * Multi search module, which is needed for further search operations
+ * Directory search module
  */
 class Directory extends BaseSearchModule
 {
@@ -36,47 +29,4 @@ class Directory extends BaseSearchModule
 
                return self::performSearch();
        }
-
-       public static function performSearch($prefix = '')
-       {
-               $a      = self::getApp();
-               $config = $a->getConfig();
-
-               $community = false;
-
-               $localSearch = $config->get('system', 'poco_local_search');
-
-               $search = $prefix . Strings::escapeTags(trim(defaults($_REQUEST, 'search', '')));
-
-               if (!$search) {
-                       return '';
-               }
-
-               $header = '';
-
-               if (strpos($search, '@') === 0) {
-                       $search  = substr($search, 1);
-                       $header  = L10n::t('People Search - %s', $search);
-                       $results = Model\Search::searchUser($search);
-               }
-
-               if (strpos($search, '!') === 0) {
-                       $search    = substr($search, 1);
-                       $community = true;
-                       $header    = L10n::t('Forum Search - %s', $search);
-               }
-
-               $pager = new Pager($a->query_string);
-
-               if ($localSearch && empty($results)) {
-                       $pager->setItemsPerPage(80);
-                       $results = Model\Search::searchLocal($search, $pager->getStart(), $pager->getItemsPerPage(), $community);
-
-               } elseif (strlen($config->get('system', 'directory')) && empty($results)) {
-                       $results = Model\Search::searchDirectory($search, $pager->getPage());
-                       $pager->setItemsPerPage($results->getItemsPage());
-               }
-
-               return self::printResult($results, $pager, $header);
-       }
 }