Browse Source

+ added optional quick search drop down selection (board / topic / site / members)

Spuds 13 years ago
parent
commit
16f368999c

+ 1 - 0
Sources/ManageSearch.php

@@ -95,6 +95,7 @@ function EditSearchSettings($return_config = false)
 			array('permissions', 'search_posts'),
 			// Some simple settings.
 			array('check', 'simpleSearch'),
+			array('check', 'search_dropdown'),
 			array('int', 'search_results_per_page'),
 			array('int', 'search_max_results', 'subtext' => $txt['search_max_results_disable']),
 		'',

+ 18 - 6
Sources/Search.php

@@ -248,6 +248,10 @@ function PlushSearch2()
 	global $scripturl, $modSettings, $sourcedir, $txt, $db_connection;
 	global $user_info, $context, $options, $messages_request, $boards_can;
 	global $excludedWords, $participants, $smcFunc;
+	
+	// if comming from the quick search box, and we want to search on members, well we need to do that ;)
+	if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members')
+		redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search']));
 
 	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
 		fatal_lang_error('loadavg_search_disabled', false);
@@ -292,6 +296,7 @@ function PlushSearch2()
 
 	// Number of pages hard maximum - normally not set at all.
 	$modSettings['search_max_results'] = empty($modSettings['search_max_results']) ? 200 * $modSettings['search_results_per_page'] : (int) $modSettings['search_max_results'];
+	
 	// Maximum length of the string.
 	$context['search_string_limit'] = 100;
 
@@ -322,15 +327,17 @@ function PlushSearch2()
 	{
 		// Due to IE's 2083 character limit, we have to compress long search strings
 		$temp_params = base64_decode(str_replace(array('-', '_', '.'), array('+', '/', '='), $_REQUEST['params']));
+		
 		// Test for gzuncompress failing
 		$temp_params2 = @gzuncompress($temp_params);
 		$temp_params = explode('|"|', (!empty($temp_params2) ? $temp_params2 : $temp_params));
 
 		foreach ($temp_params as $i => $data)
 		{
-			@list ($k, $v) = explode('|\'|', $data);
+			@list($k, $v) = explode('|\'|', $data);
 			$search_params[$k] = $v;
 		}
+		
 		if (isset($search_params['brd']))
 			$search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']);
 	}
@@ -352,9 +359,9 @@ function PlushSearch2()
 		$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
 
 	// Searching a specific topic?
-	if (!empty($_REQUEST['topic']))
-	{
-		$search_params['topic'] = (int) $_REQUEST['topic'];
+	if (!empty($_REQUEST['topic']) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'topic'))
+	{	
+		$search_params['topic'] = empty($_REQUEST['search_selection']) ? (int) $_REQUEST['topic'] : (isset($_REQUEST['sd_topic']) ? (int) $_REQUEST['sd_topic'] : '');
 		$search_params['show_complete'] = true;
 	}
 	elseif (!empty($search_params['topic']))
@@ -458,8 +465,13 @@ function PlushSearch2()
 		$_REQUEST['brd'] = $search_params['brd'];
 
 	// Ensure that brd is an array.
-	if (!empty($_REQUEST['brd']) && !is_array($_REQUEST['brd']))
-		$_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']);
+	if ((!empty($_REQUEST['brd']) && !is_array($_REQUEST['brd'])) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'board'))
+	{
+		if (!empty($_REQUEST['brd']))
+			$_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']);
+		else
+			$_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array();
+	}
 
 	// Make sure all boards are integers.
 	if (!empty($_REQUEST['brd']))

+ 1 - 1
Themes/default/Admin.template.php

@@ -767,7 +767,7 @@ function template_show_settings()
 
 	if (!empty($context['settings_insert_above']))
 		echo $context['settings_insert_above'];
-
+		
 	echo '
 	<div id="admincenter">
 		<form action="', $context['post_url'], '" method="post" accept-charset="', $context['character_set'], '"', !empty($context['force_form_onsubmit']) ? ' onsubmit="' . $context['force_form_onsubmit'] . '"' : '', '>';

+ 32 - 7
Themes/default/index.template.php

@@ -294,24 +294,49 @@ function template_body_above()
 	echo '
 			</div>
 			<div class="news normaltext">';
+	
 	if ($context['allow_search'])
 	{
 		echo '
-				<form id="search_form" action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
-					<input type="text" name="search" value="" class="input_text" />&nbsp;
-					<input type="submit" name="search2" value="', $txt['search'], '" class="button_submit" />
-					<input type="hidden" name="advanced" value="0" />';
+			<form id="search_form" action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
+				<input type="text" name="search" value="" class="input_text" />&nbsp';
+		
+		// Using the quick search dropdown?
+		if (!empty($modSettings['search_dropdown']))
+		{
+			$selected = !empty($context['current_topic']) ? 'current_topic' : (!empty($context['current_board']) ? 'current_board' : 'all');
+			
+			echo '
+				<select name="search_selection">
+					<option value="all"', ($selected == 'all' ? ' selected="selected"' : ''), '>', $txt['search_entireforum'], ' </option>';
+				
+				// Can't limit it to a specific topic if we are not in one
+				if (!empty($context['current_topic']))
+					echo '
+					<option value="topic"', ($selected == 'current_topic' ? ' selected="selected"' : ''), '>', $txt['search_thistopic'], '</option>';
 
+				// Can't limit it to a specific board if we are not in one
+				if (!empty($context['current_board']))
+					echo '
+					<option value="board"', ($selected == 'current_board' ? ' selected="selected"' : ''), '>', $txt['search_thisbrd'], '</option>';
+			echo '
+					<option value="members"', ($selected == 'members' ? ' selected="selected"' : ''), '>', $txt['search_members'], ' </option>
+				</select>';
+		}
+		
 		// Search within current topic?
 		if (!empty($context['current_topic']))
 			echo '
-						<input type="hidden" name="topic" value="', $context['current_topic'], '" />';
+				<input type="hidden" name="', (!empty($modSettings['search_dropdown']) ? 'sd_topic' : 'topic'), '" value="', $context['current_topic'], '" />';
 		// If we're on a certain board, limit it to this board ;).
 		elseif (!empty($context['current_board']))
 			echo '
-						<input type="hidden" name="brd[', $context['current_board'], ']" value="', $context['current_board'], '" />';
+				<input type="hidden" name="', (!empty($modSettings['search_dropdown']) ? 'sd_brd[' : 'brd['), $context['current_board'],   ']"', 'value="', $context['current_board'], '" />';
 
-		echo '</form>';
+		echo '
+				<input type="submit" name="search2" value="', $txt['search'], '" class="button_submit" />
+				<input type="hidden" name="advanced" value="0" />
+			</form>';	
 	}
 
 	// Show a random news item? (or you could pick one from news_lines...)

+ 1 - 0
Themes/default/languages/Help.english.php

@@ -293,6 +293,7 @@ $helptxt['compactTopicPagesEnable'] = 'This will just show a selection of the nu
 $helptxt['timeLoadPageEnable'] = 'This will show the time in seconds SMF took to create that page at the bottom of the board.';
 $helptxt['removeNestedQuotes'] = 'This will strip nested quotes from a post when citing the post in question via a quote link.';
 $helptxt['simpleSearch'] = 'This will show a simple search form and a link to a more advanced form.';
+$helptxt['search_dropdown'] = 'This will show a search selection dropdown next to the quick search box.  From this you can choose to search the current site, current board (if in a board_, current topic (if in a topic) or search for members.';
 $helptxt['max_image_width'] = 'This allows you to set a maximum size for posted pictures. Pictures smaller than the maximum will not be affected.';
 $helptxt['mail_type'] = 'This setting allows you to choose either PHP\'s default settings, or to override those settings with SMTP.  PHP doesn\'t support using authentication with SMTP (which many hosts require, now) so if you want that you should select SMTP.  Please note that SMTP can be slower, and some servers will not take usernames and passwords.<br /><br />You don\'t need to fill in the SMTP settings if this is set to PHP\'s default.';
 $helptxt['attachment_manager_settings'] = 'Attachments are files that members can upload, and attach to a post.<br /><br />

+ 1 - 0
Themes/default/languages/Search.english.php

@@ -29,6 +29,7 @@ $txt['search_specific_topic'] = 'Searching only posts in the topic';
 $txt['mods_cat_search'] = 'Search';
 $txt['groups_search_posts'] = 'Membergroups with access to the search function';
 $txt['simpleSearch'] = 'Enable simple search';
+$txt['search_dropdown'] = 'Enable the Quick Search dropdown';
 $txt['search_results_per_page'] = 'Number of search results per page';
 $txt['search_weight_frequency'] = 'Relative search weight for number of matching messages within a topic';
 $txt['search_weight_age'] = 'Relative search weight for age of last matching message';

+ 4 - 0
Themes/default/languages/index.english.php

@@ -147,6 +147,10 @@ $txt['search_on'] = 'on';
 
 $txt['search'] = 'Search';
 $txt['all'] = 'All';
+$txt['search_entireforum'] = 'Entire Forum';
+$txt['search_thisbrd'] = 'This board';
+$txt['search_thistopic'] = 'This topic';
+$txt['search_members'] = 'Members';
 
 $txt['back'] = 'Back';
 $txt['password_reminder'] = 'Password reminder';