Explorar el Código

smc_AutoSuggest on ban names

Signed-off-by: emanuele <emanuele45@gmail.com>
emanuele hace 13 años
padre
commit
79234f73ba
Se han modificado 2 ficheros con 58 adiciones y 5 borrados
  1. 45 0
      Sources/Subs-Editor.php
  2. 13 5
      Themes/default/ManageBans.template.php

+ 45 - 0
Sources/Subs-Editor.php

@@ -2164,6 +2164,7 @@ function AutoSuggestHandler($checkRegistered = null)
 	// These are all registered types.
 	$searchTypes = array(
 		'member' => 'Member',
+		'ban_name' => 'BanNames',
 		'versions' => 'SMFVersions',
 	);
 
@@ -2234,6 +2235,50 @@ function AutoSuggest_Search_Member()
 	return $xml_data;
 }
 
+/**
+ * Search for a ban name.
+ * 
+ * @return string
+ */
+function AutoSuggest_Search_BanNames()
+{
+	global $user_info, $txt, $smcFunc, $context;
+
+	$_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search'])) . '*';
+	$_REQUEST['search'] = strtr($_REQUEST['search'], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&#038;' => '&amp;'));
+
+	// Find the member.
+	$request = $smcFunc['db_query']('', '
+		SELECT id_ban_group, name
+		FROM {db_prefix}ban_groups
+		WHERE name LIKE {string:search}
+		LIMIT ' . ($smcFunc['strlen']($_REQUEST['search']) <= 2 ? '100' : '800'),
+		array(
+			'search' => $_REQUEST['search'],
+		)
+	);
+	$xml_data = array(
+		'items' => array(
+			'identifier' => 'item',
+			'children' => array(),
+		),
+	);
+	while ($row = $smcFunc['db_fetch_assoc']($request))
+	{
+		$row['name'] = strtr($row['name'], array('&amp;' => '&#038;', '&lt;' => '&#060;', '&gt;' => '&#062;', '&quot;' => '&#034;'));
+
+		$xml_data['items']['children'][] = array(
+			'attributes' => array(
+				'id' => $row['id_ban_group'],
+			),
+			'value' => $row['name'],
+		);
+	}
+	$smcFunc['db_free_result']($request);
+
+	return $xml_data;
+}
+
 /**
  * Provides a list of possible SMF versions to use in emulation
  *

+ 13 - 5
Themes/default/ManageBans.template.php

@@ -84,11 +84,8 @@ function template_ban_edit()
 							<label for="main_ip_check">', $txt['ban_on_ip'], '</label>
 						</dt>
 						<dd>
-							<input type="text" name="main_ip" value="', $context['ban_suggestions']['main_ip'], '" size="44" onfocus="document.getElementById(\'main_ip_check\').checked = true;" class="input_text" />
-						</dd>';
-
-		if (empty($modSettings['disableHostnameLookup']))
-			echo '
+							<input type="text" id="ban_name" name="ban_name" value="', $context['ban']['name'], '" size="45" maxlength="60" class="input_text" />
+						</dd>
 						<dt>
 							<input type="checkbox" name="ban_suggestion[]" id="hostname_check" value="hostname" class="input_check" />
 							<label for="hostname_check">', $txt['ban_on_hostname'], '</label>
@@ -234,6 +231,17 @@ function template_ban_edit()
 	</div>
 	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
 	<script type="text/javascript"><!-- // --><![CDATA[
+			var oBanSuggest = new smc_AutoSuggest({
+			sSelf: \'oBanSuggest\',
+			sSessionId: smf_session_id,
+			sSessionVar: smf_session_var,
+			sSuggestId: \'ban_name\',
+			sControlId: \'ban_name\',
+			sSearchType: \'ban_name\',
+			iMinimumSearchChars: \'1\',
+			bItemList: false
+		});
+
 		var fUpdateStatus = function ()
 		{
 			document.getElementById("expire_date").disabled = !document.getElementById("expires_one_day").checked;