Optimize R3
jdarwood007

jdarwood007 commited on 2019-12-24 19:58:40
Showing 1 changed files, with 108 additions and 38 deletions.

... ...
@@ -37,6 +37,7 @@ class SFS
37 37
 	/**
38 38
 	 * @var mixed Search area handling.
39 39
 	 */
40
+	private $search_types = array();
40 41
 	private $search_params = array();
41 42
 	private $search_params_column = '';
42 43
 	private $search_params_string = null;
... ...
@@ -461,7 +462,7 @@ class SFS
461 462
 				'include_start' => true,
462 463
 				'hidden_fields' => array(
463 464
 					$context['session_var'] => $context['session_id'],
464
-					'params' => $context['search_params']
465
+					'params' => $this->search_params
465 466
 				),
466 467
 			),
467 468
 			'additional_rows' => array(
... ...
@@ -509,8 +510,8 @@ class SFS
509 510
 		return array(
510 511
 			'function' => array($this, 'getSFSLogEntries'),
511 512
 			'params' => array(
512
-				(!empty($this->search_params['string']) ? ' INSTR({raw:sql_type}, {string:search_string})' : ''),
513
-				array('sql_type' => $this->search_params_column, 'search_string' => $this->search_params['string']),
513
+				(!empty($this->logSearch['string']) ? ' INSTR({raw:sql_type}, {string:search_string})' : ''),
514
+				array('sql_type' => $this->search_params_column, 'search_string' => $this->logSearch['string']),
514 515
 			),
515 516
 		);
516 517
 	}
... ...
@@ -529,8 +530,8 @@ class SFS
529 530
 		return array(
530 531
 			'function' => array($this, 'getSFSLogEntriesCount'),
531 532
 			'params' => array(
532
-				(!empty($this->search_params['string']) ? ' INSTR({raw:sql_type}, {string:search_string})' : ''),
533
-				array('sql_type' => $this->search_params_column, 'search_string' => $this->search_params['string']),
533
+				(!empty($this->logSearch['string']) ? ' INSTR({raw:sql_type}, {string:search_string})' : ''),
534
+				array('sql_type' => $this->search_params_column, 'search_string' => $this->logSearch['string']),
534 535
 			),
535 536
 		);
536 537
 	}
... ...
@@ -1188,6 +1189,8 @@ class SFS
1188 1189
 	 */
1189 1190
 	private function checkVerificationTestReport(): bool
1190 1191
 	{
1192
+		global $user_info;
1193
+
1191 1194
 		$email = !isset($_POST['email']) ? '' : trim($_POST['email']);
1192 1195
 
1193 1196
 		return $this->sfsCheck(array(
... ...
@@ -1208,6 +1211,8 @@ class SFS
1208 1211
 	 */
1209 1212
 	private function checkVerificationTestSearch(): bool
1210 1213
 	{
1214
+		global $user_info;
1215
+
1211 1216
 		return $this->sfsCheck(array(
1212 1217
 			array('ip' => $user_info['ip']),
1213 1218
 			array('ip' => $user_info['ip2']),
... ...
@@ -1225,6 +1230,8 @@ class SFS
1225 1230
 	 */
1226 1231
 	private function checkVerificationTestExtra(array $thisVerification): bool
1227 1232
 	{
1233
+		global $user_info;
1234
+
1228 1235
 		foreach ($this->extraVerificationOptions as $option)
1229 1236
 		{
1230 1237
 			// Not a match.
... ...
@@ -1365,13 +1372,14 @@ class SFS
1365 1372
 	 * Run checks for IPs
1366 1373
 	 *
1367 1374
 	 * @param array $ips All the IPs we are checking.
1375
+	 * @param string $area If defined the area we are checking.
1368 1376
 	 * @internal
1369 1377
 	 * @CalledIn SMF 2.0, SMF 2.1
1370 1378
 	 * @version 1.1
1371 1379
 	 * @since 1.1
1372 1380
 	 * @return string Request Blocked data if any
1373 1381
 	 */
1374
-	private function sfsCheck_ips(array $ips): string
1382
+	private function sfsCheck_ips(array $ips, string $area = ''): string
1375 1383
 	{
1376 1384
 		global $modSettings, $smcFunc;
1377 1385
 
... ...
@@ -1398,14 +1406,15 @@ class SFS
1398 1406
 	/**
1399 1407
 	 * Run checks for Usernames
1400 1408
 	 *
1401
-	 * @params array $usernames All the usernames we are checking.
1409
+	 * @param array $usernames All the usernames we are checking.
1410
+	 * @param string $area If defined the area we are checking.
1402 1411
 	 * @internal
1403 1412
 	 * @CalledIn SMF 2.0, SMF 2.1
1404 1413
 	 * @version 1.1
1405 1414
 	 * @since 1.1
1406 1415
 	 * @return string Request Blocked data if any
1407 1416
 	 */
1408
-	private function sfsCheck_username(array $usernames): string
1417
+	private function sfsCheck_username(array $usernames, string $area = ''): string
1409 1418
 	{
1410 1419
 		global $modSettings, $smcFunc;
1411 1420
 
... ...
@@ -1426,7 +1435,7 @@ class SFS
1426 1435
 				{
1427 1436
 					// Incase we need to debug this.
1428 1437
 					if (!empty($modSettings['sfs_log_debug']))
1429
-						$this->logAllStats('all', $checks, 'username,' . $smcFunc['htmlspecialchars']($check['value']) . ',' . $check['confidence']);
1438
+						$this->logAllStats('all', $check, 'username,' . $smcFunc['htmlspecialchars']($check['value']) . ',' . $check['confidence']);
1430 1439
 
1431 1440
 					$shouldBlock = false;
1432 1441
 				}
... ...
@@ -1447,14 +1456,15 @@ class SFS
1447 1456
 	/**
1448 1457
 	 * Run checks for Email
1449 1458
 	 *
1450
-	 * @params array $email All the email we are checking.
1459
+	 * @param array $email All the email we are checking.
1460
+	 * @param string $area If defined the area we are checking.
1451 1461
 	 * @internal
1452 1462
 	 * @CalledIn SMF 2.0, SMF 2.1
1453 1463
 	 * @version 1.1
1454 1464
 	 * @since 1.1
1455 1465
 	 * @return string Request Blocked data if any
1456 1466
 	 */
1457
-	private function sfsCheck_email(array $email): string
1467
+	private function sfsCheck_email(array $email, string $area = ''): string
1458 1468
 	{
1459 1469
 		global $modSettings, $smcFunc;
1460 1470
 
... ...
@@ -1943,19 +1953,71 @@ class SFS
1943 1953
 	 * @since 1.0
1944 1954
 	 * @return void No return is generated here.
1945 1955
 	 */
1946
-	private function handleLogSearch(string &$string): void
1956
+	private function handleLogSearch(string &$url): void
1947 1957
 	{
1948 1958
 		global $context, $txt;
1949 1959
 
1950 1960
 		// If we have some data from a search, lets bring it back out.
1961
+		$this->search_params = $this->handleLogSearchParams();
1962
+
1963
+		// What we can search.
1964
+		$this->search_types = $this->handleLogSearchTypes();
1965
+		$this->search_params_string = $this->handleLogSearchParamsString();
1966
+		$this->search_params_type = $this->handleLogSearchParamsType();
1967
+
1968
+		$this->search_params_column = $this->search_types[$this->search_params_type]['sql'];
1969
+
1970
+		// Setup the search context.
1971
+		$this->search_params = empty($search_params_string) ? '' : base64_encode(json_encode(array(
1972
+			'string' => $this->search_params_string,
1973
+			'type' => $this->search_params_type,
1974
+		)));
1975
+		$this->logSearch = array(
1976
+			'string' => $this->search_params_string,
1977
+			'type' => $this->search_params_type,
1978
+			'label' => $this->search_types[$this->search_params_type]['label'],
1979
+		);
1980
+
1981
+		if (!empty($this->search_params))
1982
+			$url .= ';params=' . $this->search_params;
1983
+	}
1984
+
1985
+	/**
1986
+	 * Handle Search Params
1987
+	 *
1988
+	 * @internal
1989
+	 * @CalledIn SMF 2.0, SMF 2.1
1990
+	 * @version 1.1
1991
+	 * @since 1.0
1992
+	 * @return bool True upon success, false otherwise.
1993
+	 */
1994
+	private function handleLogSearchParams(): array
1995
+	{
1996
+		// If we have something to search for saved, get it back out.
1951 1997
 		if (!empty($_REQUEST['params']) && empty($_REQUEST['is_search']))
1952 1998
 		{
1953
-			$this->search_params = base64_decode(strtr($_REQUEST['params'], array(' ' => '+')));
1954
-			$this->search_params = $this->decodeJSON($this->search_params);
1999
+			$search_params = base64_decode(strtr($params, array(' ' => '+')));
2000
+			$search_params = $this->decodeJSON($this->search_params);
2001
+
2002
+			if (!empty($search_params))
2003
+				return $search_params;
1955 2004
 		}
1956 2005
 	
1957
-		// What we can search.
1958
-		$searchTypes = array(
2006
+		return array();
2007
+	}
2008
+
2009
+	/**
2010
+	 * Handle Search Types
2011
+	 *
2012
+	 * @internal
2013
+	 * @CalledIn SMF 2.0, SMF 2.1
2014
+	 * @version 1.1
2015
+	 * @since 1.0
2016
+	 * @return array The valid Search Types.
2017
+	 */
2018
+	private function handleLogSearchTypes(): array
2019
+	{
2020
+		return array(
1959 2021
 			'url' => array('sql' => 'l.url', 'label' => $this->txt('sfs_log_search_url')),
1960 2022
 			'member' => array('sql' => 'mem.real_name', 'label' => $this->txt('sfs_log_search_member')),
1961 2023
 			'username' => array('sql' => 'l.username', 'label' => $this->txt('sfs_log_search_username')),
... ...
@@ -1963,34 +2025,42 @@ class SFS
1963 2025
 			'ip' => array('sql' => 'lm.ip', 'label' => $this->txt('sfs_log_search_ip')),
1964 2026
 			'ip2' => array('sql' => 'lm.ip2', 'label' => $this->txt('sfs_log_search_ip2'))
1965 2027
 		);
2028
+	}
1966 2029
  
1967
-		// What we want to search for.
2030
+ 	/**
2031
+	 * Handle Search Params String
2032
+	 *
2033
+	 * @internal
2034
+	 * @CalledIn SMF 2.0, SMF 2.1
2035
+	 * @version 1.1
2036
+	 * @since 1.0
2037
+	 * @return string What we are searching for, validated and cleaned.
2038
+	 */
2039
+	private function handleLogSearchParamsString(): string
2040
+	{
1968 2041
 		if (!isset($this->search_params['string']) || (!empty($_REQUEST['search']) && $this->search_params['string'] != $_REQUEST['search']))
1969
-			$this->search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search'];
2042
+			return empty($_REQUEST['search']) ? '' : $_REQUEST['search'];
1970 2043
 		else
1971
-			$this->search_params_string = $this->search_params['string'];
2044
+			return $this->search_params['string'];
2045
+	}
2046
+
2047
+ 	/**
2048
+	 * Handle Search Params Type
2049
+	 *
2050
+	 * @internal
2051
+	 * @CalledIn SMF 2.0, SMF 2.1
2052
+	 * @version 1.1
2053
+	 * @since 1.0
2054
+	 * @return string What we are searching for, validated and cleaned.
2055
+	 */
2056
+	private function handleLogSearchParamsType(): string
2057
+	{
2058
+		global $context;
1972 2059
 
1973 2060
 		if (isset($_REQUEST['search_type']) || empty($this->search_params['type']) || !isset($searchTypes[$this->search_params['type']]))
1974
-			$this->search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member');
2061
+			return isset($_REQUEST['search_type']) && isset($this->search_types[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($this->search_types[$context['order']]) ? $context['order'] : 'member');
1975 2062
 		else
1976
-			$this->search_params_type = $this->search_params['type'];
1977
-
1978
-		$this->search_params_column = $searchTypes[$this->search_params_type]['sql'];
1979
-		$this->search_params = array(
1980
-			'string' => $this->search_params_string,
1981
-			'type' => $this->search_params_type,
1982
-		);
1983
-
1984
-		// Setup the search context.
1985
-		$context['search_params'] = empty($this->search_params['string']) ? '' : base64_encode(json_encode($this->search_params));
1986
-		$this->logSearch = array(
1987
-			'string' => $this->search_params['string'],
1988
-			'type' => $this->search_params['type'],
1989
-			'label' => $searchTypes[$this->search_params_type]['label'],
1990
-		);
1991
-
1992
-		if (!empty($context['search_params']))
1993
-			$url .= ';params=' . $context['search_params'];
2063
+			return $this->search_params['type'];
1994 2064
 	}
1995 2065
 
1996 2066
 	/**
1997 2067