From 22598fc7e8a2833ecddcafe8ac052d5d9055f71f Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 7 Oct 2019 14:19:50 -0400 Subject: [PATCH] Improve search box - Use new saved search module - Use dynamic search option loop - Use "q" instead of "search" for search query string parameter --- mod/search.php | 6 ++--- src/Content/Text/HTML.php | 33 +++++++++++++------------ view/templates/searchbox.tpl | 30 +++++++++++----------- view/theme/frio/templates/nav.tpl | 2 +- view/theme/frio/templates/searchbox.tpl | 26 +++++++++---------- view/theme/vier/templates/nav.tpl | 2 +- 6 files changed, 48 insertions(+), 51 deletions(-) diff --git a/mod/search.php b/mod/search.php index 9651d5c9b4..7cd5233bfc 100644 --- a/mod/search.php +++ b/mod/search.php @@ -19,7 +19,7 @@ use Friendica\Module\BaseSearchModule; use Friendica\Util\Strings; function search_init(App $a) { - $search = (!empty($_GET['search']) ? Strings::escapeTags(trim(rawurldecode($_GET['search']))) : ''); + $search = (!empty($_GET['q']) ? Strings::escapeTags(trim(rawurldecode($_GET['q']))) : ''); if (local_user()) { /// @todo Check if there is a case at all that "aside" is prefilled here @@ -69,7 +69,7 @@ function search_content(App $a) { Nav::setSelected('search'); - $search = (!empty($_REQUEST['search']) ? Strings::escapeTags(trim(rawurldecode($_REQUEST['search']))) : ''); + $search = (!empty($_REQUEST['q']) ? Strings::escapeTags(trim(rawurldecode($_REQUEST['q']))) : ''); $tag = false; if (!empty($_GET['tag'])) { @@ -82,7 +82,7 @@ function search_content(App $a) { 'name' => "search-header", '$title' => L10n::t("Search"), '$title_size' => 3, - '$content' => HTML::search($search,'search-box','search', false) + '$content' => HTML::search($search,'search-box',false) ]); if (strpos($search,'#') === 0) { diff --git a/src/Content/Text/HTML.php b/src/Content/Text/HTML.php index eee443a8f3..ea9a4737cd 100644 --- a/src/Content/Text/HTML.php +++ b/src/Content/Text/HTML.php @@ -893,9 +893,9 @@ class HTML * @param bool $aside Display the search widgit aside. * * @return string Formatted HTML. - * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws \Exception */ - public static function search($s, $id = 'search-box', $url = 'search', $aside = true) + public static function search($s, $id = 'search-box', $aside = true) { $mode = 'text'; @@ -905,24 +905,25 @@ class HTML $save_label = $mode === 'text' ? L10n::t('Save') : L10n::t('Follow'); $values = [ - '$s' => $s, - '$id' => $id, - '$action_url' => $url, - '$search_label' => L10n::t('Search'), - '$save_label' => $save_label, - '$savedsearch' => 'savedsearch', - '$search_hint' => L10n::t('@name, !forum, #tags, content'), - '$mode' => $mode - ]; + '$s' => $s, + '$q' => urlencode($s), + '$id' => $id, + '$search_label' => L10n::t('Search'), + '$save_label' => $save_label, + '$search_hint' => L10n::t('@name, !forum, #tags, content'), + '$mode' => $mode, + '$return_url' => urlencode('search?q=' . $s), + ]; if (!$aside) { - $values['$searchoption'] = [ - L10n::t("Full Text"), - L10n::t("Tags"), - L10n::t("Contacts")]; + $values['$search_options'] = [ + 'fulltext' => L10n::t('Full Text'), + 'tags' => L10n::t('Tags'), + 'contacts' => L10n::t('Contacts') + ]; if (Config::get('system', 'poco_local_search')) { - $values['$searchoption'][] = L10n::t("Forums"); + $values['$searchoption']['forums'] = L10n::t('Forums'); } } diff --git a/view/templates/searchbox.tpl b/view/templates/searchbox.tpl index 4b1a51f877..d566befba0 100644 --- a/view/templates/searchbox.tpl +++ b/view/templates/searchbox.tpl @@ -1,20 +1,18 @@
-
- {{strip}} - - {{if $searchoption}} + +{{strip}} + + {{if $search_options}} - {{/if}} - - - {{if $savedsearch}} - - {{/if}} - {{/strip}} -
+ {{/if}} + + {{if $s}} + {{$save_label}} + {{/if}} +{{/strip}} +
diff --git a/view/theme/frio/templates/nav.tpl b/view/theme/frio/templates/nav.tpl index a3bcdc976d..4698fb6578 100644 --- a/view/theme/frio/templates/nav.tpl +++ b/view/theme/frio/templates/nav.tpl @@ -265,7 +265,7 @@ diff --git a/view/theme/frio/templates/searchbox.tpl b/view/theme/frio/templates/searchbox.tpl index c7d06d1073..bf2ee53040 100644 --- a/view/theme/frio/templates/searchbox.tpl +++ b/view/theme/frio/templates/searchbox.tpl @@ -4,34 +4,32 @@ Some parts of this template will be moved by js to other places (see theme.js) -
-
+
{{* The button to save searches *}} - {{if $savedsearch}} - + {{if $s}} + {{$save_label}} {{/if}} {{* The select popup menu to select what kind of results the user would like to search for *}} - {{if $searchoption}} + {{if $search_options}}
-
{{/if}} @@ -47,10 +45,10 @@ Some parts of this template will be moved by js to other places (see theme.js) -
-{{if $savedsearch}} -
- -