Conditions | 46 |
Paths | > 20000 |
Total Lines | 282 |
Code Lines | 176 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
29 | function ViewModlog() |
||
30 | { |
||
31 | global $txt, $context, $scripturl, $sourcedir, $smcFunc; |
||
32 | |||
33 | // Are we looking at the moderation log or the administration log. |
||
34 | $context['log_type'] = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'adminlog' ? 3 : 1; |
||
35 | if ($context['log_type'] == 3) |
||
36 | isAllowedTo('admin_forum'); |
||
37 | |||
38 | // These change dependant on whether we are viewing the moderation or admin log. |
||
39 | if ($context['log_type'] == 3 || $_REQUEST['action'] == 'admin') |
||
40 | $context['url_start'] = '?action=admin;area=logs;sa=' . ($context['log_type'] == 3 ? 'adminlog' : 'modlog') . ';type=' . $context['log_type']; |
||
41 | else |
||
42 | $context['url_start'] = '?action=moderate;area=modlog;type=' . $context['log_type']; |
||
43 | |||
44 | $context['can_delete'] = allowedTo('admin_forum'); |
||
45 | |||
46 | loadLanguage('Modlog'); |
||
47 | |||
48 | $context['page_title'] = $context['log_type'] == 3 ? $txt['modlog_admin_log'] : $txt['modlog_view']; |
||
49 | |||
50 | // The number of entries to show per page of log file. |
||
51 | $context['displaypage'] = 30; |
||
52 | |||
53 | // Handle deletion... |
||
54 | if (isset($_POST['removeall']) && $context['can_delete']) |
||
55 | { |
||
56 | checkSession(); |
||
57 | validateToken('mod-ml'); |
||
58 | |||
59 | $smcFunc['db_query']('', ' |
||
60 | DELETE FROM {db_prefix}log_actions |
||
61 | WHERE id_log = {int:moderate_log}', |
||
62 | array( |
||
63 | 'moderate_log' => $context['log_type'], |
||
64 | ) |
||
65 | ); |
||
66 | |||
67 | $log_type = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'adminlog' ? 'admin' : 'moderate'; |
||
68 | logAction('clearlog_' . $log_type, array(), $log_type); |
||
69 | } |
||
70 | elseif (!empty($_POST['remove']) && isset($_POST['delete']) && $context['can_delete']) |
||
71 | { |
||
72 | checkSession(); |
||
73 | validateToken('mod-ml'); |
||
74 | |||
75 | // No sneaky removing the 'cleared the log' entries. |
||
76 | $smcFunc['db_query']('', ' |
||
77 | DELETE FROM {db_prefix}log_actions |
||
78 | WHERE id_log = {int:moderate_log} |
||
79 | AND id_action IN ({array_string:delete_actions}) |
||
80 | AND action NOT LIKE {string:clearlog}', |
||
81 | array( |
||
82 | 'delete_actions' => array_unique($_POST['delete']), |
||
83 | 'moderate_log' => $context['log_type'], |
||
84 | 'clearlog' => 'clearlog_%', |
||
85 | ) |
||
86 | ); |
||
87 | } |
||
88 | |||
89 | // Do the column stuff! |
||
90 | $sort_types = array( |
||
91 | 'action' =>'lm.action', |
||
92 | 'time' => 'lm.log_time', |
||
93 | 'member' => 'mem.real_name', |
||
94 | 'group' => 'mg.group_name', |
||
95 | 'ip' => 'lm.ip', |
||
96 | ); |
||
97 | |||
98 | // Setup the direction stuff... |
||
99 | $context['order'] = isset($_REQUEST['sort']) && isset($sort_types[$_REQUEST['sort']]) ? $_REQUEST['sort'] : 'time'; |
||
100 | |||
101 | // If we're coming from a search, get the variables. |
||
102 | if (!empty($_REQUEST['params']) && empty($_REQUEST['is_search'])) |
||
103 | { |
||
104 | $search_params = base64_decode(strtr($_REQUEST['params'], array(' ' => '+'))); |
||
105 | $search_params = $smcFunc['json_decode']($search_params, true); |
||
106 | } |
||
107 | |||
108 | // This array houses all the valid search types. |
||
109 | $searchTypes = array( |
||
110 | 'action' => array('sql' => 'lm.action', 'label' => $txt['modlog_action']), |
||
111 | 'member' => array('sql' => 'mem.real_name', 'label' => $txt['modlog_member']), |
||
112 | 'group' => array('sql' => 'mg.group_name', 'label' => $txt['modlog_position']), |
||
113 | 'ip' => array('sql' => 'lm.ip', 'label' => $txt['modlog_ip']) |
||
114 | ); |
||
115 | |||
116 | if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search'])) |
||
117 | $search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search']; |
||
118 | else |
||
119 | $search_params_string = $search_params['string']; |
||
120 | |||
121 | if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']])) |
||
122 | $search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member'); |
||
123 | else |
||
124 | $search_params_type = $search_params['type']; |
||
125 | |||
126 | $search_params_column = $searchTypes[$search_params_type]['sql']; |
||
127 | $search_params = array( |
||
128 | 'string' => $search_params_string, |
||
129 | 'type' => $search_params_type, |
||
130 | ); |
||
131 | |||
132 | // Setup the search context. |
||
133 | $context['search_params'] = empty($search_params['string']) ? '' : base64_encode($smcFunc['json_encode']($search_params)); |
||
134 | $context['search'] = array( |
||
135 | 'string' => $search_params['string'], |
||
136 | 'type' => $search_params['type'], |
||
137 | 'label' => $searchTypes[$search_params_type]['label'], |
||
138 | ); |
||
139 | |||
140 | // If they are searching by action, then we must do some manual intervention to search in their language! |
||
141 | if ($search_params['type'] == 'action' && !empty($search_params['string'])) |
||
142 | { |
||
143 | // For the moment they can only search for ONE action! |
||
144 | foreach ($txt as $key => $text) |
||
145 | { |
||
146 | if (substr($key, 0, 10) == 'modlog_ac_' && strpos($text, $search_params['string']) !== false) |
||
147 | { |
||
148 | $search_params['string'] = substr($key, 10); |
||
149 | break; |
||
150 | } |
||
151 | } |
||
152 | } |
||
153 | |||
154 | require_once($sourcedir . '/Subs-List.php'); |
||
155 | |||
156 | // This is all the information required for a watched user listing. |
||
157 | $listOptions = array( |
||
158 | 'id' => 'moderation_log_list', |
||
159 | 'width' => '100%', |
||
160 | 'items_per_page' => $context['displaypage'], |
||
161 | 'no_items_label' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin_log_' : '') . 'no_entries_found'], |
||
162 | 'base_href' => $scripturl . $context['url_start'] . (!empty($context['search_params']) ? ';params=' . $context['search_params'] : ''), |
||
163 | 'default_sort_col' => 'time', |
||
164 | 'get_items' => array( |
||
165 | 'function' => 'list_getModLogEntries', |
||
166 | 'params' => array( |
||
167 | (!empty($search_params['string']) ? ' INSTR({raw:sql_type}, {string:search_string})' : ''), |
||
168 | array('sql_type' => $search_params_column, 'search_string' => $search_params['string']), |
||
169 | $context['log_type'], |
||
170 | ), |
||
171 | ), |
||
172 | 'get_count' => array( |
||
173 | 'function' => 'list_getModLogEntryCount', |
||
174 | 'params' => array( |
||
175 | (!empty($search_params['string']) ? ' INSTR({raw:sql_type}, {string:search_string})' : ''), |
||
176 | array('sql_type' => $search_params_column, 'search_string' => $search_params['string']), |
||
177 | $context['log_type'], |
||
178 | ), |
||
179 | ), |
||
180 | // This assumes we are viewing by user. |
||
181 | 'columns' => array( |
||
182 | 'action' => array( |
||
183 | 'header' => array( |
||
184 | 'value' => $txt['modlog_action'], |
||
185 | 'class' => 'lefttext', |
||
186 | ), |
||
187 | 'data' => array( |
||
188 | 'db' => 'action_text', |
||
189 | 'class' => 'smalltext', |
||
190 | ), |
||
191 | 'sort' => array( |
||
192 | 'default' => 'lm.action', |
||
193 | 'reverse' => 'lm.action DESC', |
||
194 | ), |
||
195 | ), |
||
196 | 'time' => array( |
||
197 | 'header' => array( |
||
198 | 'value' => $txt['modlog_date'], |
||
199 | 'class' => 'lefttext', |
||
200 | ), |
||
201 | 'data' => array( |
||
202 | 'db' => 'time', |
||
203 | 'class' => 'smalltext', |
||
204 | ), |
||
205 | 'sort' => array( |
||
206 | 'default' => 'lm.log_time DESC', |
||
207 | 'reverse' => 'lm.log_time', |
||
208 | ), |
||
209 | ), |
||
210 | 'moderator' => array( |
||
211 | 'header' => array( |
||
212 | 'value' => $txt['modlog_member'], |
||
213 | 'class' => 'lefttext', |
||
214 | ), |
||
215 | 'data' => array( |
||
216 | 'db' => 'moderator_link', |
||
217 | 'class' => 'smalltext', |
||
218 | ), |
||
219 | 'sort' => array( |
||
220 | 'default' => 'mem.real_name', |
||
221 | 'reverse' => 'mem.real_name DESC', |
||
222 | ), |
||
223 | ), |
||
224 | 'position' => array( |
||
225 | 'header' => array( |
||
226 | 'value' => $txt['modlog_position'], |
||
227 | 'class' => 'lefttext', |
||
228 | ), |
||
229 | 'data' => array( |
||
230 | 'db' => 'position', |
||
231 | 'class' => 'smalltext', |
||
232 | ), |
||
233 | 'sort' => array( |
||
234 | 'default' => 'mg.group_name', |
||
235 | 'reverse' => 'mg.group_name DESC', |
||
236 | ), |
||
237 | ), |
||
238 | 'ip' => array( |
||
239 | 'header' => array( |
||
240 | 'value' => $txt['modlog_ip'], |
||
241 | 'class' => 'lefttext', |
||
242 | ), |
||
243 | 'data' => array( |
||
244 | 'db' => 'ip', |
||
245 | 'class' => 'smalltext', |
||
246 | ), |
||
247 | 'sort' => array( |
||
248 | 'default' => 'lm.ip', |
||
249 | 'reverse' => 'lm.ip DESC', |
||
250 | ), |
||
251 | ), |
||
252 | 'delete' => array( |
||
253 | 'header' => array( |
||
254 | 'value' => '<input type="checkbox" name="all" onclick="invertAll(this, this.form);">', |
||
255 | 'class' => 'centercol', |
||
256 | ), |
||
257 | 'data' => array( |
||
258 | 'function' => function ($entry) |
||
259 | { |
||
260 | return '<input type="checkbox" name="delete[]" value="' . $entry['id'] . '"' . ($entry['editable'] ? '' : ' disabled') . '>'; |
||
261 | }, |
||
262 | 'class' => 'centercol', |
||
263 | ), |
||
264 | ), |
||
265 | ), |
||
266 | 'form' => array( |
||
267 | 'href' => $scripturl . $context['url_start'], |
||
268 | 'include_sort' => true, |
||
269 | 'include_start' => true, |
||
270 | 'hidden_fields' => array( |
||
271 | $context['session_var'] => $context['session_id'], |
||
272 | 'params' => $context['search_params'] |
||
273 | ), |
||
274 | 'token' => 'mod-ml', |
||
275 | ), |
||
276 | 'additional_rows' => array( |
||
277 | array( |
||
278 | 'position' => 'below_table_data', |
||
279 | 'value' => ' |
||
280 | ' . $txt['modlog_search'] . ' (' . $txt['modlog_by'] . ': ' . $context['search']['label'] . '): |
||
281 | <input type="text" name="search" size="18" value="' . $smcFunc['htmlspecialchars']($context['search']['string']) . '"> |
||
282 | <input type="submit" name="is_search" value="' . $txt['modlog_go'] . '" class="button" style="float:none"> |
||
283 | ' . ($context['can_delete'] ? ' |
||
284 | <input type="submit" name="remove" value="' . $txt['modlog_remove'] . '" data-confirm="' . $txt['modlog_remove_selected_confirm'] . '" class="button you_sure"> |
||
285 | <input type="submit" name="removeall" value="' . $txt['modlog_removeall'] . '" data-confirm="' . $txt['modlog_remove_all_confirm'] . '" class="button you_sure">' : ''), |
||
286 | 'class' => 'floatright', |
||
287 | ), |
||
288 | ), |
||
289 | ); |
||
290 | |||
291 | // Overriding this with a hook? |
||
292 | $moderation_menu_name = array(); |
||
293 | call_integration_hook('integrate_viewModLog', array(&$listOptions, &$moderation_menu_name)); |
||
294 | |||
295 | createToken('mod-ml'); |
||
296 | |||
297 | // Create the watched user list. |
||
298 | createList($listOptions); |
||
299 | |||
300 | $context['sub_template'] = 'show_list'; |
||
301 | $context['default_list'] = 'moderation_log_list'; |
||
302 | |||
303 | // If a hook has changed this, respect it. |
||
304 | if (!empty($moderation_menu_name)) |
||
305 | $context[$context['moderation_menu_name']]['tab_data'] = $moderation_menu_name; |
||
306 | elseif (isset($context['moderation_menu_name'])) |
||
307 | $context[$context['moderation_menu_name']]['tab_data'] = array( |
||
308 | 'title' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin' : 'moderation') . '_log'], |
||
309 | 'help' => $context['log_type'] == 3 ? 'adminlog' : 'modlog', |
||
310 | 'description' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin' : 'moderation') . '_log_desc'] |
||
311 | ); |
||
657 | ?> |