]> git.mxchange.org Git - friendica.git/commitdiff
Improve search box
authorHypolite Petovan <hypolite@mrpetovan.com>
Mon, 7 Oct 2019 18:19:50 +0000 (14:19 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 7 Oct 2019 18:27:46 +0000 (14:27 -0400)
- Use new saved search module
- Use dynamic search option loop
- Use "q" instead of "search" for search query string parameter

mod/search.php
src/Content/Text/HTML.php
view/templates/searchbox.tpl
view/theme/frio/templates/nav.tpl
view/theme/frio/templates/searchbox.tpl
view/theme/vier/templates/nav.tpl

index 9651d5c9b4f1c4085b66873eea81ad1038c0bc80..7cd5233bfc4cdfb137f433fb259d4b4765abfc15 100644 (file)
@@ -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) {
index eee443a8f3a9bec99226b44c64f455beb9bf7c79..ea9a4737cd5bbc3869b7319ccf6a107bf04554e8 100644 (file)
@@ -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');
                        }
                }
 
index 4b1a51f877d7ba4159b88bbb2d184dc50070a2e4..d566befba01bfd7ea73a7c316c2f286e1886cb13 100644 (file)
@@ -1,20 +1,18 @@
 <div id="{{$id}}" class="input-group">
-        <form action="{{$action_url}}" method="get" >
-                {{strip}}
-                <input type="text" name="search" id="search-text" placeholder="{{$search_label}}" value="{{$s}}" />
-                {{if $searchoption}}
+       <form action="search" method="get">
+{{strip}}
+               <input type="text" name="q" id="search-text" placeholder="{{$search_label}}" value="{{$s}}">
+    {{if $search_options}}
                <select name="search-option" id="search-options">
-                       <option value="fulltext">{{$searchoption.0}}</option>
-                       <option value="tags">{{$searchoption.1}}</option>
-                       <option value="contacts">{{$searchoption.2}}</option>
-                       {{if $searchoption.3}}<option value="forums">{{$searchoption.3}}</option>{{/if}}
+               {{foreach $search_options as $value => $label}}
+                       <option value="{{$value}}">{{$label}}</option>
+               {{/foreach}}
                </select>
-               {{/if}}
-
-                <input type="submit" name="submit" id="search-submit" value="{{$search_label}}" />
-                {{if $savedsearch}}
-                <input type="submit" name="save" id="search-save" value="{{$save_label}}" />
-                {{/if}}
-                {{/strip}}
-        </form>
+    {{/if}}
+               <input type="submit" name="submit" id="search-submit" value="{{$search_label}}"/>
+    {{if $s}}
+           <a href="search/saved/add/{{$q}}?return_url={{$return_url}}">{{$save_label}}</a>
+    {{/if}}
+{{/strip}}
+       </form>
 </div>
index a3bcdc976d1cb89d357b21a10d3dbccc793e3296..4698fb65784493afdc894190aec8f308653e8d28 100644 (file)
        <form class="navbar-form" role="search" method="get" action="{{$nav.search.0}}">
                <!-- <img class="hidden-xs" src="{{$nav.userinfo.icon}}" alt="{{$nav.userinfo.name}}" style="max-width:33px; max-height:33px; min-width:33px; min-height:33px; width:33px; height:33px;"> -->
                <div class="form-group form-group-search">
-                       <input id="nav-search-input-field-mobile" class="form-control form-search" type="text" name="search" data-toggle="tooltip" title="{{$search_hint}}" placeholder="{{$nav.search.1}}">
+                       <input id="nav-search-input-field-mobile" class="form-control form-search" type="text" name="q" data-toggle="tooltip" title="{{$search_hint}}" placeholder="{{$nav.search.1}}">
                        <button class="btn btn-default btn-sm form-button-search" type="submit">{{$nav.search.1}}</button>
                </div>
        </form>
index c7d06d10730198424ed6e9e168f070bdfd547c3d..bf2ee53040692c297faef77a264d2b39769506fd 100644 (file)
@@ -4,34 +4,32 @@ Some parts of this template will be moved by js to other places (see theme.js) -
 
 <div id="{{$id}}" {{* class="input-group" *}}>
        <div id="search-wrapper">
-               <form action="{{$action_url}}" method="get" >
+               <form action="search" method="get">
                        <div class="row">
                                <div class="col-md-2"></div>
                                <div class="col-md-8 ">
 
                                        <div class="form-group form-group-search">
-                                               <input type="text" name="search" id="search-text" class="search-input form-control form-search" data-toggle="tooltip" title="{{$search_hint}}" placeholder="{{$search_label}}" value="{{$s}}" />
+                                               <input type="text" name="q" id="search-text" class="search-input form-control form-search" data-toggle="tooltip" title="{{$search_hint}}" placeholder="{{$search_label}}" value="{{$s}}" />
                                                <button id="search-submit" class="btn btn-default btn-sm form-button-search" type="submit">{{$search_label}}</button>
                                        </div>
 
                                        <div class="col-md-4"></div>
                                        <div class="col-md-8">
                                                {{* The button to save searches *}}
-                                               {{if $savedsearch}}
-                                               <button class="btn btn-primary btn-small pull-right" type="submit" name="save" value="{{$save_label}}">{{$save_label}}</button>
+                                               {{if $s}}
+                                               <a href="search/saved/add/{{$q}}?return_url={{$return_url}}" class="btn btn-primary btn-small pull-right">{{$save_label}}</a>
                                                {{/if}}
 
                                                {{* The select popup menu to select what kind of results the user would like to search for *}}
-                                               {{if $searchoption}}
+                                               {{if $search_options}}
                                                <div class="col-md-6 pull-right">
                                                        <div class="form-group field select">
                                                                <select name="search-option" id="search-options" class="form-control form-control-sm">
-                                                                       <option value="fulltext">{{$searchoption.0}}</option>
-                                                                       <option value="tags">{{$searchoption.1}}</option>
-                                                                       <option value="contacts">{{$searchoption.2}}</option>
-                                                                       {{if $searchoption.3}}<option value="forums">{{$searchoption.3}}</option>{{/if}}
+                                {{foreach $search_options as $value => $label}}
+                                                                       <option value="{{$value}}">{{$label}}</option>
+                                {{/foreach}}
                                                                </select>
-
                                                        </div>
                                                </div>
                                                {{/if}}
@@ -47,10 +45,10 @@ Some parts of this template will be moved by js to other places (see theme.js) -
                </form>
        </div>
 
-{{if $savedsearch}}
-       <form id="search-save-form" action="{{$action_url}}" method="get" >
-               <input type="hidden" name="search" value="{{$s}}" />
-               <button class="btn btn-sm btn-main pull-right" type="submit" name="save" id="search-save" title="{{$save_label}}" aria-label="{{$save_label}}" value="{{$save_label}}" data-toggle="tooltip">
+{{if $s}}
+       <form id="search-save-form" action="search/saved/add/{{$q}}" method="get">
+               <input type="hidden" name="return_url" value="{{$return_url}}">
+               <button class="btn btn-sm btn-main pull-right" type="submit" id="search-save" title="{{$save_label}}" aria-label="{{$save_label}}" value="{{$save_label}}" data-toggle="tooltip">
        {{if $mode == "tag"}}
                        <i class="fa fa-plus fa-2x" aria-hidden="true"></i>
        {{else}}
index f600b9f615c93cc7d00742441725198d6d67738e..efc578eb899d35fc4f07ff09c1beb7a75243131d 100644 (file)
                {{if $nav.search}}
                        <li role="search" id="nav-search-box">
                                <form method="get" action="{{$nav.search.0}}">
-                                       <input accesskey="s" id="nav-search-text" class="nav-menu-search" type="text" value="" name="search" placeholder=" {{$search_hint}}">
+                                       <input accesskey="s" id="nav-search-text" class="nav-menu-search" type="text" value="" name="q" placeholder=" {{$search_hint}}">
                                        <select name="search-option">
                                                <option value="fulltext">{{$nav.searchoption.0}}</option>
                                                <option value="tags">{{$nav.searchoption.1}}</option>