Browse Source

Improve search box

- Use new saved search module
- Use dynamic search option loop
- Use "q" instead of "search" for search query string parameter
pull/7714/head
Hypolite Petovan 1 week ago
parent
commit
22598fc7e8

+ 3
- 3
mod/search.php View File

@@ -19,7 +19,7 @@ use Friendica\Module\BaseSearchModule;
19 19
 use Friendica\Util\Strings;
20 20
 
21 21
 function search_init(App $a) {
22
-	$search = (!empty($_GET['search']) ? Strings::escapeTags(trim(rawurldecode($_GET['search']))) : '');
22
+	$search = (!empty($_GET['q']) ? Strings::escapeTags(trim(rawurldecode($_GET['q']))) : '');
23 23
 
24 24
 	if (local_user()) {
25 25
 		/// @todo Check if there is a case at all that "aside" is prefilled here
@@ -69,7 +69,7 @@ function search_content(App $a) {
69 69
 
70 70
 	Nav::setSelected('search');
71 71
 
72
-	$search = (!empty($_REQUEST['search']) ? Strings::escapeTags(trim(rawurldecode($_REQUEST['search']))) : '');
72
+	$search = (!empty($_REQUEST['q']) ? Strings::escapeTags(trim(rawurldecode($_REQUEST['q']))) : '');
73 73
 
74 74
 	$tag = false;
75 75
 	if (!empty($_GET['tag'])) {
@@ -82,7 +82,7 @@ function search_content(App $a) {
82 82
 		'name' => "search-header",
83 83
 		'$title' => L10n::t("Search"),
84 84
 		'$title_size' => 3,
85
-		'$content' => HTML::search($search,'search-box','search', false)
85
+		'$content' => HTML::search($search,'search-box',false)
86 86
 	]);
87 87
 
88 88
 	if (strpos($search,'#') === 0) {

+ 17
- 16
src/Content/Text/HTML.php View File

@@ -893,9 +893,9 @@ class HTML
893 893
 	 * @param bool   $aside Display the search widgit aside.
894 894
 	 *
895 895
 	 * @return string Formatted HTML.
896
-	 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
896
+	 * @throws \Exception
897 897
 	 */
898
-	public static function search($s, $id = 'search-box', $url = 'search', $aside = true)
898
+	public static function search($s, $id = 'search-box', $aside = true)
899 899
 	{
900 900
 		$mode = 'text';
901 901
 
@@ -905,24 +905,25 @@ class HTML
905 905
 		$save_label = $mode === 'text' ? L10n::t('Save') : L10n::t('Follow');
906 906
 
907 907
 		$values = [
908
-				'$s' => $s,
909
-				'$id' => $id,
910
-				'$action_url' => $url,
911
-				'$search_label' => L10n::t('Search'),
912
-				'$save_label' => $save_label,
913
-				'$savedsearch' => 'savedsearch',
914
-				'$search_hint' => L10n::t('@name, !forum, #tags, content'),
915
-				'$mode' => $mode
916
-			];
908
+			'$s'            => $s,
909
+			'$q'            => urlencode($s),
910
+			'$id'           => $id,
911
+			'$search_label' => L10n::t('Search'),
912
+			'$save_label'   => $save_label,
913
+			'$search_hint'  => L10n::t('@name, !forum, #tags, content'),
914
+			'$mode'         => $mode,
915
+			'$return_url'   => urlencode('search?q=' . $s),
916
+		];
917 917
 
918 918
 		if (!$aside) {
919
-			$values['$searchoption'] = [
920
-						L10n::t("Full Text"),
921
-						L10n::t("Tags"),
922
-						L10n::t("Contacts")];
919
+			$values['$search_options'] = [
920
+				'fulltext' => L10n::t('Full Text'),
921
+				'tags'     => L10n::t('Tags'),
922
+				'contacts' => L10n::t('Contacts')
923
+			];
923 924
 
924 925
 			if (Config::get('system', 'poco_local_search')) {
925
-				$values['$searchoption'][] = L10n::t("Forums");
926
+				$values['$searchoption']['forums'] = L10n::t('Forums');
926 927
 			}
927 928
 		}
928 929
 

+ 14
- 16
view/templates/searchbox.tpl View File

@@ -1,20 +1,18 @@
1 1
 <div id="{{$id}}" class="input-group">
2
-        <form action="{{$action_url}}" method="get" >
3
-                {{strip}}
4
-                <input type="text" name="search" id="search-text" placeholder="{{$search_label}}" value="{{$s}}" />
5
-                {{if $searchoption}}
2
+	<form action="search" method="get">
3
+{{strip}}
4
+		<input type="text" name="q" id="search-text" placeholder="{{$search_label}}" value="{{$s}}">
5
+    {{if $search_options}}
6 6
 		<select name="search-option" id="search-options">
7
-			<option value="fulltext">{{$searchoption.0}}</option>
8
-			<option value="tags">{{$searchoption.1}}</option>
9
-			<option value="contacts">{{$searchoption.2}}</option>
10
-			{{if $searchoption.3}}<option value="forums">{{$searchoption.3}}</option>{{/if}}
7
+		{{foreach $search_options as $value => $label}}
8
+			<option value="{{$value}}">{{$label}}</option>
9
+		{{/foreach}}
11 10
 		</select>
12
-		{{/if}}
13
-
14
-                <input type="submit" name="submit" id="search-submit" value="{{$search_label}}" />
15
-                {{if $savedsearch}}
16
-                <input type="submit" name="save" id="search-save" value="{{$save_label}}" />
17
-                {{/if}}
18
-                {{/strip}}
19
-        </form>
11
+    {{/if}}
12
+		<input type="submit" name="submit" id="search-submit" value="{{$search_label}}"/>
13
+    {{if $s}}
14
+	    <a href="search/saved/add/{{$q}}?return_url={{$return_url}}">{{$save_label}}</a>
15
+    {{/if}}
16
+{{/strip}}
17
+	</form>
20 18
 </div>

+ 1
- 1
view/theme/frio/templates/nav.tpl View File

@@ -265,7 +265,7 @@
265 265
 	<form class="navbar-form" role="search" method="get" action="{{$nav.search.0}}">
266 266
 		<!-- <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;"> -->
267 267
 		<div class="form-group form-group-search">
268
-			<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}}">
268
+			<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}}">
269 269
 			<button class="btn btn-default btn-sm form-button-search" type="submit">{{$nav.search.1}}</button>
270 270
 		</div>
271 271
 	</form>

+ 12
- 14
view/theme/frio/templates/searchbox.tpl View File

@@ -4,34 +4,32 @@ Some parts of this template will be moved by js to other places (see theme.js) -
4 4
 
5 5
 <div id="{{$id}}" {{* class="input-group" *}}>
6 6
 	<div id="search-wrapper">
7
-		<form action="{{$action_url}}" method="get" >
7
+		<form action="search" method="get">
8 8
 			<div class="row">
9 9
 				<div class="col-md-2"></div>
10 10
 				<div class="col-md-8 ">
11 11
 
12 12
 					<div class="form-group form-group-search">
13
-						<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}}" />
13
+						<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}}" />
14 14
 						<button id="search-submit" class="btn btn-default btn-sm form-button-search" type="submit">{{$search_label}}</button>
15 15
 					</div>
16 16
 
17 17
 					<div class="col-md-4"></div>
18 18
 					<div class="col-md-8">
19 19
 						{{* The button to save searches *}}
20
-						{{if $savedsearch}}
21
-						<button class="btn btn-primary btn-small pull-right" type="submit" name="save" value="{{$save_label}}">{{$save_label}}</button>
20
+						{{if $s}}
21
+						<a href="search/saved/add/{{$q}}?return_url={{$return_url}}" class="btn btn-primary btn-small pull-right">{{$save_label}}</a>
22 22
 						{{/if}}
23 23
 
24 24
 						{{* The select popup menu to select what kind of results the user would like to search for *}}
25
-						{{if $searchoption}}
25
+						{{if $search_options}}
26 26
 						<div class="col-md-6 pull-right">
27 27
 							<div class="form-group field select">
28 28
 								<select name="search-option" id="search-options" class="form-control form-control-sm">
29
-									<option value="fulltext">{{$searchoption.0}}</option>
30
-									<option value="tags">{{$searchoption.1}}</option>
31
-									<option value="contacts">{{$searchoption.2}}</option>
32
-									{{if $searchoption.3}}<option value="forums">{{$searchoption.3}}</option>{{/if}}
29
+                                {{foreach $search_options as $value => $label}}
30
+									<option value="{{$value}}">{{$label}}</option>
31
+                                {{/foreach}}
33 32
 								</select>
34
-
35 33
 							</div>
36 34
 						</div>
37 35
 						{{/if}}
@@ -47,10 +45,10 @@ Some parts of this template will be moved by js to other places (see theme.js) -
47 45
 		</form>
48 46
 	</div>
49 47
 
50
-{{if $savedsearch}}
51
-	<form id="search-save-form" action="{{$action_url}}" method="get" >
52
-		<input type="hidden" name="search" value="{{$s}}" />
53
-		<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">
48
+{{if $s}}
49
+	<form id="search-save-form" action="search/saved/add/{{$q}}" method="get">
50
+		<input type="hidden" name="return_url" value="{{$return_url}}">
51
+		<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">
54 52
 	{{if $mode == "tag"}}
55 53
 			<i class="fa fa-plus fa-2x" aria-hidden="true"></i>
56 54
 	{{else}}

+ 1
- 1
view/theme/vier/templates/nav.tpl View File

@@ -111,7 +111,7 @@
111 111
 		{{if $nav.search}}
112 112
 			<li role="search" id="nav-search-box">
113 113
 				<form method="get" action="{{$nav.search.0}}">
114
-					<input accesskey="s" id="nav-search-text" class="nav-menu-search" type="text" value="" name="search" placeholder=" {{$search_hint}}">
114
+					<input accesskey="s" id="nav-search-text" class="nav-menu-search" type="text" value="" name="q" placeholder=" {{$search_hint}}">
115 115
 					<select name="search-option">
116 116
 						<option value="fulltext">{{$nav.searchoption.0}}</option>
117 117
 						<option value="tags">{{$nav.searchoption.1}}</option>

Loading…
Cancel
Save