More refactoring
jdarwood007

jdarwood007 commited on 2020-01-04 11:47:14
Showing 1 changed files, with 86 additions and 25 deletions.

... ...
@@ -23,6 +23,7 @@ class SFSL
23 23
 	/**
24 24
 	 * @var mixed Search area handling.
25 25
 	 */
26
+	private $sort_order = 'time';
26 27
 	private $search_types = array();
27 28
 	private $search_params = array();
28 29
 	private $search_params_column = '';
... ...
@@ -168,8 +169,8 @@ class SFSL
168 169
 
169 170
 		loadLanguage('Modlog');
170 171
 
171
-		$context['form_url'] = $this->SFSA->get('adminLogURL');
172
-		$context['log_url'] = $this->SFSA->get('adminLogURL');
172
+		$context['form_url'] = $this->SFSAclass->get('adminLogURL');
173
+		$context['log_url'] = $this->SFSAclass->get('adminLogURL');
173 174
 		$context['page_title'] = $this->SFSclass->txt('sfs_admin_logs');
174 175
 		$this->canDeleteLogs = allowedTo('admin_forum');
175 176
 
... ...
@@ -179,14 +180,40 @@ class SFSL
179 180
 
180 181
 		$sort_types = $this->handleLogsGetSortTypes();
181 182
 
182
-		$context['order'] = isset($_REQUEST['sort']) && isset($sort_types[$_REQUEST['sort']]) ? $_REQUEST['sort'] : 'time';
183
+		$this->sort_order = isset($_REQUEST['sort']) && isset($sort_types[$_REQUEST['sort']]) ? $_REQUEST['sort'] : 'time';
183 184
 
184 185
 		// Handle searches.
185 186
 		$this->handleLogSearch($context['log_url']);
186 187
 
187 188
 		require_once($sourcedir . '/Subs-List.php');
188 189
 
189
-		$listOptions = array(
190
+		$listOptions = $this->loadLogsListOptions();
191
+
192
+		// Create the watched user list.
193
+		createList($listOptions);
194
+
195
+		$context['sub_template'] = 'show_list';
196
+		$context['default_list'] = 'sfslog_list';
197
+
198
+		return array();
199
+	}
200
+
201
+	/**
202
+	 * Builds the list options data.
203
+	 *
204
+	 * @internal
205
+	 * @CalledIn SMF2.0, SMF 2.1
206
+	 * @See SFSA::getSFSLogEntries
207
+	 * @See SFSA::getSFSLogEntriesCount
208
+	 * @version 1.2
209
+	 * @since 1.2
210
+	 * @return array The list options data
211
+	 */
212
+	public function loadLogsListOptions(): array
213
+	{
214
+		global $context;
215
+
216
+		return array(
190 217
 			'id' => 'sfslog_list',
191 218
 			'title' => $this->SFSclass->txt('sfs_admin_logs'),
192 219
 			'width' => '100%',
... ...
@@ -223,14 +250,6 @@ class SFSL
223 250
 				$this->loadLogsGetAddtionalRow(),
224 251
 			),
225 252
 		);
226
-
227
-		// Create the watched user list.
228
-		createList($listOptions);
229
-
230
-		$context['sub_template'] = 'show_list';
231
-		$context['default_list'] = 'sfslog_list';
232
-
233
-		return array();
234 253
 	}
235 254
 
236 255
 	/**
... ...
@@ -682,41 +701,77 @@ class SFSL
682 701
 			'result_raw' => $row['result'],
683 702
 		);
684 703
 
704
+		$return['checks'] = $this->getSFSLogPrepareEntryChecks($row, $checksDecoded);
705
+		$return['result'] = $this->getSFSLogPrepareEntryResult($row);
706
+
707
+		return $return;
708
+	}
709
+
710
+	/**
711
+	 * Processes the entry for the proper checks column.
712
+	 *
713
+	 * @param array $row The raw row data.
714
+	 *
715
+	 * @api
716
+	 * @CalledIn SMF 2.0, SMF 2.1
717
+	 * @See SFSA::getSFSLogEntries
718
+	 * @version 1.2
719
+	 * @since 1.2
720
+	 * @return string The formatted checks data.
721
+	 */
722
+	public function getSFSLogPrepareEntryChecks(array $row): string
723
+	{
685 724
 		$checksDecoded = $this->SFSclass->decodeJSON($row['checks']);
686 725
 
687 726
 		// If we know what check triggered this, link it up to be searched.
688 727
 		if ($row['id_type'] == 1)
689
-			$return['checks'] = '<a href="' . sprintf($this->urlSFSsearch, $checksDecoded['value']) . '">' . $checksDecoded['value'] . '</a>';
728
+			$checks = '<a href="' . sprintf($this->urlSFSsearch, $checksDecoded['value']) . '">' . $checksDecoded['value'] . '</a>';
690 729
 		elseif ($row['id_type'] == 2)
691
-			$return['checks'] = '<a href="' . sprintf($this->urlSFSsearch, $checksDecoded['value']) . '">' . $checksDecoded['value'] . '</a>';
730
+			$checks = '<a href="' . sprintf($this->urlSFSsearch, $checksDecoded['value']) . '">' . $checksDecoded['value'] . '</a>';
692 731
 		elseif ($row['id_type'] == 3)
693
-			$return['checks'] = '<a href="' . sprintf($this->urlSFSsearch, $checksDecoded['value']) . '">' . $checksDecoded['value'] . '</a>';
732
+			$checks = '<a href="' . sprintf($this->urlSFSsearch, $checksDecoded['value']) . '">' . $checksDecoded['value'] . '</a>';
694 733
 		// No idea what triggered it, parse it out cleanly.  Could be debug data as well.
695 734
 		else
696 735
 		{
697
-			$return['checks'] = '';
698
-
736
+			$checks = '';
699 737
 			foreach ($checksDecoded as $ckey => $vkey)
700 738
 				foreach ($vkey as $key => $value)
701
-					$return['checks'] .= ucfirst($key) . ':' . $value . '<br>';					
739
+					$checks .= ucfirst($key) . ':' . $value . '<br>';
740
+		}
741
+
742
+		return $checks;
702 743
 	}
703 744
 
745
+	/**
746
+	 * Processes the entry for the proper results column.
747
+	 *
748
+	 * @param array $row The raw row data.
749
+	 *
750
+	 * @api
751
+	 * @CalledIn SMF 2.0, SMF 2.1
752
+	 * @See SFSA::getSFSLogEntries
753
+	 * @version 1.2
754
+	 * @since 1.2
755
+	 * @return string The formated results entry.
756
+	 */
757
+	public function getSFSLogPrepareEntryResult(array $row = array()): string
758
+	{
704 759
 		// This tells us what it matched on exactly.
705 760
 		if (strpos($row['result'], ',') !== false)
706 761
 		{
707 762
 			list($resultType, $resultMatch, $extra) = explode(',', $row['result'] . ',,,');
708
-			$return['result'] = sprintf($this->SFSclass->txt('sfs_log_matched_on'), $resultType, $resultMatch);
763
+			$result = sprintf($this->SFSclass->txt('sfs_log_matched_on'), $resultType, $resultMatch);
709 764
 
710 765
 			// If this was a IP ban, note it.
711 766
 			if ($resultType == 'ip' && !empty($extra))
712
-				$return['result'] .= ' ' . $this->SFSclass->txt('sfs_log_auto_banned');			
767
+				$result .= ' ' . $this->SFSclass->txt('sfs_log_auto_banned');
713 768
 			if ($resultType == 'username' && !empty($extra))
714
-				$return['result'] .= ' ' . sprintf($this->SFSclass->txt('sfs_log_confidence'), $extra);			
769
+				$result .= ' ' . sprintf($this->SFSclass->txt('sfs_log_confidence'), $extra);
770
+
771
+			return $result;
715 772
 		}
716
-		else
717
-			$return['result'] = $row['result'];
718 773
 
719
-		return $return;
774
+		return $row['result'];
720 775
 	}
721 776
 
722 777
 	/**
... ...
@@ -925,7 +980,13 @@ class SFSL
925 980
 		global $context;
926 981
 
927 982
 		if (isset($_REQUEST['search_type']) || empty($this->search_params['type']) || !isset($this->search_types[$this->search_params['type']]))
928
-			return isset($_REQUEST['search_type']) && isset($this->search_types[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($this->search_types[$context['order']]) ? $context['order'] : 'member');
983
+		{
984
+			if (isset($_REQUEST['search_type']) && isset($this->search_types[$_REQUEST['search_type']]))
985
+				return (string) $_REQUEST['search_type'];
986
+			if (isset($this->search_types[$this->sort_order]))
987
+			 	return $this->sort_order;
988
+			 return 'member';
989
+		}
929 990
 		return $this->search_params['type'];
930 991
 	}
931 992
 }
932 993
\ No newline at end of file
933 994