Browse Source

Revert "Flexible is better: now calling banLoadAdditionalIPs is possible to specify the table and the column (instead of split in two functions like suggested by joshuaadickerson)"

This reverts commit 50a1974dbf84b40327d22097d263890231673e9e.
emanuele 12 years ago
parent
commit
67465baa60
1 changed files with 31 additions and 26 deletions
  1. 31 26
      Sources/ManageBans.php

+ 31 - 26
Sources/ManageBans.php

@@ -533,11 +533,7 @@ function BanEdit()
 				if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $context['ban_suggestions']['main_ip']) == 1 || isValidIPv6($context['ban_suggestions']['main_ip'])) && empty($modSettings['disableHostnameLookup']))
 					$context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']);
 
-				// Borrowing a few language strings from profile.
-				loadLanguage('Profile');
-
-				$context['ban_suggestions']['message_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id'], 'messages', 'poster_ip');
-				$context['ban_suggestions']['error_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id'], 'log_errors');
+				$context['ban_suggestions'] += banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
 			}
 		}
 	}
@@ -690,37 +686,52 @@ function list_getNumBanItems()
 }
 
 /**
- * Finds additional IPs related to a certain user from a specified table (and column)
+ * Finds additional IPs related to a certain user from the messages and the log_errors tables
  *
  * @param int $member_id
- * @param string $table table name without prefix
- * @param string $column column to search in (default 'ip')
  * @return array
  */
-function banLoadAdditionalIPs($member_id, $table, $column = 'ip')
+function banLoadAdditionalIPs($member_id)
 {
-	global $smcFunc;
+	global $context, $smcFunc;
+
+	// Borrowing a few language strings from profile.
+	loadLanguage('Profile');
 
 	// Find some additional IP's used by this member.
-	$ips = array();
+	$message_ips = array();
 	$request = $smcFunc['db_query']('ban_suggest_message_ips', '
-		SELECT DISTINCT {raw:column_name}
-		FROM {db_prefix}{raw:table_name}
+		SELECT DISTINCT poster_ip
+		FROM {db_prefix}messages
+		WHERE id_member = {int:current_user}
+			AND poster_ip RLIKE {string:poster_ip_regex}
+		ORDER BY poster_ip',
+		array(
+			'current_user' => $member_id,
+			'poster_ip_regex' => '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$',
+		)
+	);
+	while ($row = $smcFunc['db_fetch_assoc']($request))
+		$message_ips[] = $row['poster_ip'];
+	$smcFunc['db_free_result']($request);
+
+	$error_ips = array();
+	$request = $smcFunc['db_query']('ban_suggest_error_ips', '
+		SELECT DISTINCT ip
+		FROM {db_prefix}log_errors
 		WHERE id_member = {int:current_user}
-			AND {raw:column_name} RLIKE {string:poster_ip_regex}
-		ORDER BY {raw:column_name}',
+			AND ip RLIKE {string:poster_ip_regex}
+		ORDER BY ip',
 		array(
-			'table_name' => $table,
-			'column_name' => $column,
 			'current_user' => $member_id,
 			'poster_ip_regex' => '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$',
 		)
 	);
 	while ($row = $smcFunc['db_fetch_assoc']($request))
-		$ips[] = $row[$column];
+		$error_ips[] = $row['ip'];
 	$smcFunc['db_free_result']($request);
 
-	return $ips;
+	return array('message_ips' => $message_ips, 'error_ips' => $error_ips);
 }
 
 /**
@@ -782,13 +793,7 @@ function banEdit2()
 	{
 		// Not strictly necessary, but it's nice
 		if (!empty($context['ban_suggestions']['member']['id']))
-		{
-			// Borrowing a few language strings from profile.
-			loadLanguage('Profile');
-
-			$context['ban_suggestions']['message_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id'], 'messages', 'poster_ip');
-			$context['ban_suggestions']['error_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id'], 'log_errors');
-		}
+			$context['ban_suggestions'] += banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
 		return BanEdit();
 	}