Passed
Push — release-2.1 ( e31624...391b74 )
by Mathias
26:03 queued 19:58
created

ViewModlog()   F

Complexity

Conditions 48
Paths > 20000

Size

Total Lines 297
Code Lines 186

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 48
eloc 186
c 0
b 0
f 0
nop 0
dl 0
loc 297
rs 0
nc 637009920

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
3
/**
4
 * The moderation log is this file's only job.
5
 * It views it, and that's about all it does.
6
 *
7
 * Simple Machines Forum (SMF)
8
 *
9
 * @package SMF
10
 * @author Simple Machines https://www.simplemachines.org
11
 * @copyright 2022 Simple Machines and individual contributors
12
 * @license https://www.simplemachines.org/about/smf/license.php BSD
13
 *
14
 * @version 2.1.0
15
 */
16
17
if (!defined('SMF'))
18
	die('No direct access...');
19
20
/**
21
 * Prepares the information from the moderation log for viewing.
22
 * Show the moderation log.
23
 * If clearing the log, leaves a message in the log to indicate it was cleared, by whom and when.
24
 * Requires the admin_forum permission.
25
 * Accessed via ?action=moderate;area=modlog.
26
 *
27
 * Uses Modlog template, main sub-template.
28
 */
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('Admin+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
	// Actions whose log entries cannot be deleted.
53
	$context['uneditable_actions'] = array('agreement_updated', 'policy_updated');
54
55
	// Handle deletion...
56
	if (isset($_POST['removeall']) && $context['can_delete'])
57
	{
58
		checkSession();
59
		validateToken('mod-ml');
60
61
		$smcFunc['db_query']('', '
62
			DELETE FROM {db_prefix}log_actions
63
			WHERE id_log = {int:moderate_log}
64
			AND action NOT IN ({array_string:uneditable})',
65
66
			array(
67
				'moderate_log' => $context['log_type'],
68
				'uneditable' => $context['uneditable_actions'],
69
			)
70
		);
71
72
		$log_type = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'adminlog' ? 'admin' : 'moderate';
73
		logAction('clearlog_' . $log_type, array(), $log_type);
74
	}
75
	elseif (!empty($_POST['remove']) && isset($_POST['delete']) && $context['can_delete'])
76
	{
77
		checkSession();
78
		validateToken('mod-ml');
79
80
		// No sneaky removing the 'cleared the log' entries.
81
		$smcFunc['db_query']('', '
82
			DELETE FROM {db_prefix}log_actions
83
			WHERE id_log = {int:moderate_log}
84
				AND id_action IN ({array_string:delete_actions})
85
				AND action NOT LIKE {string:clearlog}
86
				AND action NOT IN ({array_string:uneditable})',
87
			array(
88
				'delete_actions' => array_unique($_POST['delete']),
89
				'moderate_log' => $context['log_type'],
90
				'uneditable' => $context['uneditable_actions'],
91
				'clearlog' => 'clearlog_%',
92
			)
93
		);
94
	}
95
96
	// Do the column stuff!
97
	$sort_types = array(
98
		'action' => 'lm.action',
99
		'time' => 'lm.log_time',
100
		'member' => 'mem.real_name',
101
		'group' => 'mg.group_name',
102
		'ip' => 'lm.ip',
103
	);
104
105
	// Setup the direction stuff...
106
	$context['order'] = isset($_REQUEST['sort']) && isset($sort_types[$_REQUEST['sort']]) ? $_REQUEST['sort'] : 'time';
107
108
	// If we're coming from a search, get the variables.
109
	if (!empty($_REQUEST['params']) && empty($_REQUEST['is_search']))
110
	{
111
		$search_params = base64_decode(strtr($_REQUEST['params'], array(' ' => '+')));
112
		$search_params = $smcFunc['json_decode']($search_params, true);
113
	}
114
115
	// This array houses all the valid search types.
116
	$searchTypes = array(
117
		'action' => array('sql' => 'lm.action', 'label' => $txt['modlog_action']),
118
		'member' => array('sql' => 'mem.real_name', 'label' => $txt['modlog_member']),
119
		'group' => array('sql' => 'mg.group_name', 'label' => $txt['modlog_position']),
120
		'ip' => array('sql' => 'lm.ip', 'label' => $txt['modlog_ip'])
121
	);
122
123
	if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search']))
124
		$search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search'];
125
	else
126
		$search_params_string = $search_params['string'];
127
128
	if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']]))
129
		$search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member');
130
	else
131
		$search_params_type = $search_params['type'];
132
133
	$search_params_column = $searchTypes[$search_params_type]['sql'];
134
	$search_params = array(
135
		'string' => $search_params_string,
136
		'type' => $search_params_type,
137
	);
138
139
	// Setup the search context.
140
	$context['search_params'] = empty($search_params['string']) ? '' : base64_encode($smcFunc['json_encode']($search_params));
141
	$context['search'] = array(
142
		'string' => $search_params['string'],
143
		'type' => $search_params['type'],
144
		'label' => $searchTypes[$search_params_type]['label'],
145
	);
146
147
	// If they are searching by action, then we must do some manual intervention to search in their language!
148
	if ($search_params['type'] == 'action' && !empty($search_params['string']))
149
	{
150
		// For the moment they can only search for ONE action!
151
		foreach ($txt as $key => $text)
152
		{
153
			if (substr($key, 0, 10) == 'modlog_ac_' && strpos($text, $search_params['string']) !== false)
154
			{
155
				$search_params['string'] = substr($key, 10);
156
				break;
157
			}
158
		}
159
	}
160
161
	require_once($sourcedir . '/Subs-List.php');
162
163
	// This is all the information required for a watched user listing.
164
	$listOptions = array(
165
		'id' => 'moderation_log_list',
166
		'title' => $context['log_type'] == 3 ? $txt['admin_log'] : $txt['moderation_log'],
167
		'width' => '100%',
168
		'items_per_page' => $context['displaypage'],
169
		'no_items_label' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin_log_' : '') . 'no_entries_found'],
170
		'base_href' => $scripturl . $context['url_start'] . (!empty($context['search_params']) ? ';params=' . $context['search_params'] : ''),
171
		'default_sort_col' => 'time',
172
		'get_items' => array(
173
			'function' => 'list_getModLogEntries',
174
			'params' => array(
175
				(!empty($search_params['string']) ? ' INSTR({raw:sql_type}, {string:search_string}) > 0' : ''),
176
				array('sql_type' => $search_params_column, 'search_string' => $search_params['string']),
177
				$context['log_type'],
178
			),
179
		),
180
		'get_count' => array(
181
			'function' => 'list_getModLogEntryCount',
182
			'params' => array(
183
				(!empty($search_params['string']) ? ' INSTR({raw:sql_type}, {string:search_string}) > 0' : ''),
184
				array('sql_type' => $search_params_column, 'search_string' => $search_params['string']),
185
				$context['log_type'],
186
			),
187
		),
188
		// This assumes we are viewing by user.
189
		'columns' => array(
190
			'action' => array(
191
				'header' => array(
192
					'value' => $txt['modlog_action'],
193
					'class' => 'lefttext',
194
				),
195
				'data' => array(
196
					'db' => 'action_text',
197
					'class' => 'smalltext',
198
				),
199
				'sort' => array(
200
					'default' => 'lm.action',
201
					'reverse' => 'lm.action DESC',
202
				),
203
			),
204
			'time' => array(
205
				'header' => array(
206
					'value' => $txt['modlog_date'],
207
					'class' => 'lefttext',
208
				),
209
				'data' => array(
210
					'db' => 'time',
211
					'class' => 'smalltext',
212
				),
213
				'sort' => array(
214
					'default' => 'lm.log_time DESC',
215
					'reverse' => 'lm.log_time',
216
				),
217
			),
218
			'moderator' => array(
219
				'header' => array(
220
					'value' => $txt['modlog_member'],
221
					'class' => 'lefttext',
222
				),
223
				'data' => array(
224
					'db' => 'moderator_link',
225
					'class' => 'smalltext',
226
				),
227
				'sort' => array(
228
					'default' => 'mem.real_name',
229
					'reverse' => 'mem.real_name DESC',
230
				),
231
			),
232
			'position' => array(
233
				'header' => array(
234
					'value' => $txt['modlog_position'],
235
					'class' => 'lefttext',
236
				),
237
				'data' => array(
238
					'db' => 'position',
239
					'class' => 'smalltext',
240
				),
241
				'sort' => array(
242
					'default' => 'mg.group_name',
243
					'reverse' => 'mg.group_name DESC',
244
				),
245
			),
246
			'ip' => array(
247
				'header' => array(
248
					'value' => $txt['modlog_ip'],
249
					'class' => 'lefttext',
250
				),
251
				'data' => array(
252
					'db' => 'ip',
253
					'class' => 'smalltext',
254
				),
255
				'sort' => array(
256
					'default' => 'lm.ip',
257
					'reverse' => 'lm.ip DESC',
258
				),
259
			),
260
			'delete' => array(
261
				'header' => array(
262
					'value' => '<input type="checkbox" name="all" onclick="invertAll(this, this.form);">',
263
					'class' => 'centercol',
264
				),
265
				'data' => array(
266
					'function' => function($entry)
267
					{
268
						return '<input type="checkbox" name="delete[]" value="' . $entry['id'] . '"' . ($entry['editable'] ? '' : ' disabled') . '>';
269
					},
270
					'class' => 'centercol',
271
				),
272
			),
273
		),
274
		'form' => array(
275
			'href' => $scripturl . $context['url_start'],
276
			'include_sort' => true,
277
			'include_start' => true,
278
			'hidden_fields' => array(
279
				$context['session_var'] => $context['session_id'],
280
				'params' => $context['search_params']
281
			),
282
			'token' => 'mod-ml',
283
		),
284
		'additional_rows' => array(
285
			array(
286
				'position' => 'after_title',
287
				'value' => '
288
					' . $txt['modlog_search'] . ' (' . $txt['modlog_by'] . ': ' . $context['search']['label'] . '):
289
					<input type="text" name="search" size="18" value="' . $smcFunc['htmlspecialchars']($context['search']['string']) . '">
290
					<input type="submit" name="is_search" value="' . $txt['modlog_go'] . '" class="button" style="float:none">
291
					' . ($context['can_delete'] ? '
292
					<input type="submit" name="remove" value="' . $txt['modlog_remove'] . '" data-confirm="' . $txt['modlog_remove_selected_confirm'] . '" class="button you_sure">
293
					<input type="submit" name="removeall" value="' . $txt['modlog_removeall'] . '" data-confirm="' . $txt['modlog_remove_all_confirm'] . '" class="button you_sure">' : ''),
294
				'class' => '',
295
			),
296
			array(
297
				'position' => 'below_table_data',
298
				'value' => $context['can_delete'] ? '
299
					<input type="submit" name="remove" value="' . $txt['modlog_remove'] . '" data-confirm="' . $txt['modlog_remove_selected_confirm'] . '" class="button you_sure">
300
					<input type="submit" name="removeall" value="' . $txt['modlog_removeall'] . '" data-confirm="' . $txt['modlog_remove_all_confirm'] . '" class="button you_sure">' : '',
301
				'class' => 'floatright',
302
			),
303
		),
304
	);
305
306
	// Overriding this with a hook?
307
	$moderation_menu_name = array();
308
	call_integration_hook('integrate_viewModLog', array(&$listOptions, &$moderation_menu_name));
309
310
	createToken('mod-ml');
311
312
	// Create the watched user list.
313
	createList($listOptions);
314
315
	$context['sub_template'] = 'show_list';
316
	$context['default_list'] = 'moderation_log_list';
317
318
	// If a hook has changed this, respect it.
319
	if (!empty($moderation_menu_name))
320
		$context[$context['moderation_menu_name']]['tab_data'] = $moderation_menu_name;
321
	elseif (isset($context['moderation_menu_name']))
322
		$context[$context['moderation_menu_name']]['tab_data'] = array(
323
			'title' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin' : 'moderation') . '_log'],
324
			'help' => $context['log_type'] == 3 ? 'adminlog' : 'modlog',
325
			'description' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin' : 'moderation') . '_log_desc']
326
		);
327
}
328
329
/**
330
 * Get the number of mod log entries.
331
 * Callback for createList() in ViewModlog().
332
 *
333
 * @param string $query_string An extra string for the WHERE clause in the query to further filter results
334
 * @param array $query_params An array of parameters for the query_string
335
 * @param int $log_type The log type (1 for mod log, 3 for admin log)
336
 * @param bool $ignore_boards Whether to ignore board restrictions
337
 */
338
function list_getModLogEntryCount($query_string = '', $query_params = array(), $log_type = 1, $ignore_boards = false)
339
{
340
	global $smcFunc, $user_info;
341
342
	$modlog_query = allowedTo('admin_forum') || $user_info['mod_cache']['bq'] == '1=1' ? '1=1' : (($user_info['mod_cache']['bq'] == '0=1' || $ignore_boards) ? 'lm.id_board = 0 AND lm.id_topic = 0' : (strtr($user_info['mod_cache']['bq'], array('id_board' => 'b.id_board')) . ' AND ' . strtr($user_info['mod_cache']['bq'], array('id_board' => 't.id_board'))));
343
344
	$result = $smcFunc['db_query']('', '
345
		SELECT COUNT(*)
346
		FROM {db_prefix}log_actions AS lm
347
			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lm.id_member)
348
			LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:reg_group_id} THEN mem.id_post_group ELSE mem.id_group END)
349
			LEFT JOIN {db_prefix}boards AS b ON (b.id_board = lm.id_board)
350
			LEFT JOIN {db_prefix}topics AS t ON (t.id_topic = lm.id_topic)
351
		WHERE id_log = {int:log_type}
352
			AND {raw:modlog_query}'
353
			. (!empty($query_string) ? '
354
			AND ' . $query_string : ''),
355
		array_merge($query_params, array(
356
			'reg_group_id' => 0,
357
			'log_type' => $log_type,
358
			'modlog_query' => $modlog_query,
359
		))
360
	);
361
	list ($entry_count) = $smcFunc['db_fetch_row']($result);
362
	$smcFunc['db_free_result']($result);
363
364
	return $entry_count;
365
}
366
367
/**
368
 * Gets the moderation log entries that match the specified parameters.
369
 * Callback for createList() in ViewModlog().
370
 *
371
 * @param int $start The item to start with (for pagination purposes)
372
 * @param int $items_per_page The number of items to show per page
373
 * @param string $sort A string indicating how to sort the results
374
 * @param string $query_string An extra string for the WHERE clause of the query, to further filter results
375
 * @param array $query_params An array of parameters for the query string
376
 * @param int $log_type The log type - 1 for mod log or 3 for admin log
377
 * @param bool $ignore_boards Whether to ignore board restrictions
378
 * @return array An array of info about the mod log entries
379
 */
380
function list_getModLogEntries($start, $items_per_page, $sort, $query_string = '', $query_params = array(), $log_type = 1, $ignore_boards = false)
381
{
382
	global $scripturl, $txt, $smcFunc, $user_info, $context;
383
384
	$modlog_query = allowedTo('admin_forum') || $user_info['mod_cache']['bq'] == '1=1' ? '1=1' : (($user_info['mod_cache']['bq'] == '0=1' || $ignore_boards) ? 'lm.id_board = 0 AND lm.id_topic = 0' : (strtr($user_info['mod_cache']['bq'], array('id_board' => 'b.id_board')) . ' AND ' . strtr($user_info['mod_cache']['bq'], array('id_board' => 't.id_board'))));
385
386
	if (!isset($context['uneditable_actions']))
387
		$context['uneditable_actions'] = array();
388
389
	// Can they see the IP address?
390
	$seeIP = allowedTo('moderate_forum');
391
392
	// Here we have the query getting the log details.
393
	$result = $smcFunc['db_query']('', '
394
		SELECT
395
			lm.id_action, lm.id_member, lm.ip, lm.log_time, lm.action, lm.id_board, lm.id_topic, lm.id_msg, lm.extra,
396
			mem.real_name, mg.group_name
397
		FROM {db_prefix}log_actions AS lm
398
			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lm.id_member)
399
			LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:reg_group_id} THEN mem.id_post_group ELSE mem.id_group END)
400
			LEFT JOIN {db_prefix}boards AS b ON (b.id_board = lm.id_board)
401
			LEFT JOIN {db_prefix}topics AS t ON (t.id_topic = lm.id_topic)
402
		WHERE id_log = {int:log_type}
403
			AND {raw:modlog_query}'
404
			. (!empty($query_string) ? '
405
			AND ' . $query_string : '') . '
406
		ORDER BY {raw:sort}
407
		LIMIT {int:start}, {int:max}',
408
		array_merge($query_params, array(
409
			'reg_group_id' => 0,
410
			'log_type' => $log_type,
411
			'modlog_query' => $modlog_query,
412
			'sort' => $sort,
413
			'start' => $start,
414
			'max' => $items_per_page,
415
		))
416
	);
417
418
	// Arrays for decoding objects into.
419
	$topics = array();
420
	$boards = array();
421
	$members = array();
422
	$messages = array();
423
	$entries = array();
424
	while ($row = $smcFunc['db_fetch_assoc']($result))
425
	{
426
		$row['extra'] = $smcFunc['json_decode']($row['extra'], true);
427
428
		// Corrupt?
429
		$row['extra'] = is_array($row['extra']) ? $row['extra'] : array();
430
431
		// Add on some of the column stuff info
432
		if (!empty($row['id_board']))
433
		{
434
			if ($row['action'] == 'move')
435
				$row['extra']['board_to'] = $row['id_board'];
436
			else
437
				$row['extra']['board'] = $row['id_board'];
438
		}
439
440
		if (!empty($row['id_topic']))
441
			$row['extra']['topic'] = $row['id_topic'];
442
		if (!empty($row['id_msg']))
443
			$row['extra']['message'] = $row['id_msg'];
444
445
		// Is this associated with a topic?
446
		if (isset($row['extra']['topic']))
447
			$topics[(int) $row['extra']['topic']][] = $row['id_action'];
448
		if (isset($row['extra']['new_topic']))
449
			$topics[(int) $row['extra']['new_topic']][] = $row['id_action'];
450
451
		// How about a member?
452
		if (isset($row['extra']['member']))
453
		{
454
			// Guests don't have names!
455
			if (empty($row['extra']['member']))
456
				$row['extra']['member'] = $txt['modlog_parameter_guest'];
457
			else
458
			{
459
				// Try to find it...
460
				$members[(int) $row['extra']['member']][] = $row['id_action'];
461
			}
462
		}
463
464
		// Associated with a board?
465
		if (isset($row['extra']['board_to']))
466
			$boards[(int) $row['extra']['board_to']][] = $row['id_action'];
467
		if (isset($row['extra']['board_from']))
468
			$boards[(int) $row['extra']['board_from']][] = $row['id_action'];
469
		if (isset($row['extra']['board']))
470
			$boards[(int) $row['extra']['board']][] = $row['id_action'];
471
472
		// A message?
473
		if (isset($row['extra']['message']))
474
			$messages[(int) $row['extra']['message']][] = $row['id_action'];
475
476
		// IP Info?
477
		if (isset($row['extra']['ip_range']))
478
			if ($seeIP)
479
				$row['extra']['ip_range'] = '<a href="' . $scripturl . '?action=trackip;searchip=' . $row['extra']['ip_range'] . '">' . $row['extra']['ip_range'] . '</a>';
480
			else
481
				$row['extra']['ip_range'] = $txt['logged'];
482
483
		// Email?
484
		if (isset($row['extra']['email']))
485
			$row['extra']['email'] = '<a href="mailto:' . $row['extra']['email'] . '">' . $row['extra']['email'] . '</a>';
486
487
		// Bans are complex.
488
		if ($row['action'] == 'ban' || $row['action'] == 'banremove')
489
		{
490
			$row['action_text'] = $txt['modlog_ac_ban' . ($row['action'] == 'banremove' ? '_remove' : '')];
491
			foreach (array('member', 'email', 'ip_range', 'hostname') as $type)
492
				if (isset($row['extra'][$type]))
493
					$row['action_text'] .= $txt['modlog_ac_ban_trigger_' . $type];
494
		}
495
496
		// The array to go to the template. Note here that action is set to a "default" value of the action doesn't match anything in the descriptions. Allows easy adding of logging events with basic details.
497
		$entries[$row['id_action']] = array(
498
			'id' => $row['id_action'],
499
			'ip' => $seeIP ? inet_dtop($row['ip']) : $txt['logged'],
500
			'position' => empty($row['real_name']) && empty($row['group_name']) ? $txt['guest'] : $row['group_name'],
501
			'moderator_link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>' : (empty($row['real_name']) ? ($txt['guest'] . (!empty($row['extra']['member_acted']) ? ' (' . $row['extra']['member_acted'] . ')' : '')) : $row['real_name']),
502
			'time' => timeformat($row['log_time']),
503
			'timestamp' => $row['log_time'],
504
			'editable' => substr($row['action'], 0, 8) !== 'clearlog' && !in_array($row['action'], $context['uneditable_actions']),
505
			'extra' => $row['extra'],
506
			'action' => $row['action'],
507
			'action_text' => isset($row['action_text']) ? $row['action_text'] : '',
508
		);
509
	}
510
	$smcFunc['db_free_result']($result);
511
512
	if (!empty($boards))
513
	{
514
		$request = $smcFunc['db_query']('', '
515
			SELECT id_board, name
516
			FROM {db_prefix}boards
517
			WHERE id_board IN ({array_int:board_list})
518
			LIMIT {int:limit}',
519
			array(
520
				'board_list' => array_keys($boards),
521
				'limit' => count(array_keys($boards)),
522
			)
523
		);
524
		while ($row = $smcFunc['db_fetch_assoc']($request))
525
		{
526
			foreach ($boards[$row['id_board']] as $action)
527
			{
528
				// Make the board number into a link - dealing with moving too.
529
				if (isset($entries[$action]['extra']['board_to']) && $entries[$action]['extra']['board_to'] == $row['id_board'])
530
					$entries[$action]['extra']['board_to'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
531
				elseif (isset($entries[$action]['extra']['board_from']) && $entries[$action]['extra']['board_from'] == $row['id_board'])
532
					$entries[$action]['extra']['board_from'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
533
				elseif (isset($entries[$action]['extra']['board']) && $entries[$action]['extra']['board'] == $row['id_board'])
534
					$entries[$action]['extra']['board'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
535
			}
536
		}
537
		$smcFunc['db_free_result']($request);
538
	}
539
540
	if (!empty($topics))
541
	{
542
		$request = $smcFunc['db_query']('', '
543
			SELECT ms.subject, t.id_topic
544
			FROM {db_prefix}topics AS t
545
				INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
546
			WHERE t.id_topic IN ({array_int:topic_list})
547
			LIMIT {int:limit}',
548
			array(
549
				'topic_list' => array_keys($topics),
550
				'limit' => count(array_keys($topics)),
551
			)
552
		);
553
		while ($row = $smcFunc['db_fetch_assoc']($request))
554
		{
555
			foreach ($topics[$row['id_topic']] as $action)
556
			{
557
				$this_action = &$entries[$action];
558
559
				// This isn't used in the current theme.
560
				$this_action['topic'] = array(
561
					'id' => $row['id_topic'],
562
					'subject' => $row['subject'],
563
					'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
564
					'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>'
565
				);
566
567
				// Make the topic number into a link - dealing with splitting too.
568
				if (isset($this_action['extra']['topic']) && $this_action['extra']['topic'] == $row['id_topic'])
569
					$this_action['extra']['topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
570
				elseif (isset($this_action['extra']['new_topic']) && $this_action['extra']['new_topic'] == $row['id_topic'])
571
					$this_action['extra']['new_topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
572
			}
573
		}
574
		$smcFunc['db_free_result']($request);
575
	}
576
577
	if (!empty($messages))
578
	{
579
		$request = $smcFunc['db_query']('', '
580
			SELECT id_msg, subject
581
			FROM {db_prefix}messages
582
			WHERE id_msg IN ({array_int:message_list})
583
			LIMIT {int:limit}',
584
			array(
585
				'message_list' => array_keys($messages),
586
				'limit' => count(array_keys($messages)),
587
			)
588
		);
589
		while ($row = $smcFunc['db_fetch_assoc']($request))
590
		{
591
			foreach ($messages[$row['id_msg']] as $action)
592
			{
593
				$this_action = &$entries[$action];
594
595
				// This isn't used in the current theme.
596
				$this_action['message'] = array(
597
					'id' => $row['id_msg'],
598
					'subject' => $row['subject'],
599
					'href' => $scripturl . '?msg=' . $row['id_msg'],
600
					'link' => '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>',
601
				);
602
603
				// Make the message number into a link.
604
				if (isset($this_action['extra']['message']) && $this_action['extra']['message'] == $row['id_msg'])
605
					$this_action['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
606
			}
607
		}
608
		$smcFunc['db_free_result']($request);
609
	}
610
611
	if (!empty($members))
612
	{
613
		$request = $smcFunc['db_query']('', '
614
			SELECT real_name, id_member
615
			FROM {db_prefix}members
616
			WHERE id_member IN ({array_int:member_list})
617
			LIMIT {int:limit}',
618
			array(
619
				'member_list' => array_keys($members),
620
				'limit' => count(array_keys($members)),
621
			)
622
		);
623
		while ($row = $smcFunc['db_fetch_assoc']($request))
624
		{
625
			foreach ($members[$row['id_member']] as $action)
626
			{
627
				// Not used currently.
628
				$entries[$action]['member'] = array(
629
					'id' => $row['id_member'],
630
					'name' => $row['real_name'],
631
					'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
632
					'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'
633
				);
634
				// Make the member number into a name.
635
				$entries[$action]['extra']['member'] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
636
			}
637
		}
638
		$smcFunc['db_free_result']($request);
639
	}
640
641
	// Do some formatting of the action string.
642
	foreach ($entries as $k => $entry)
643
	{
644
		// Make any message info links so its easier to go find that message.
645
		if (isset($entry['extra']['message']) && (empty($entry['message']) || empty($entry['message']['id'])))
646
			$entries[$k]['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $entry['extra']['message'] . '">' . $entry['extra']['message'] . '</a>';
647
648
		// Mark up any deleted members, topics and boards.
649
		foreach (array('board', 'board_from', 'board_to', 'member', 'topic', 'new_topic') as $type)
650
			if (!empty($entry['extra'][$type]) && is_numeric($entry['extra'][$type]))
651
				$entries[$k]['extra'][$type] = sprintf($txt['modlog_id'], $entry['extra'][$type]);
652
653
		if (isset($entry['extra']['report']))
654
		{
655
			// Member profile reports go in a different area
656
			if (stristr($entry['action'], 'user_report'))
657
				$entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedmembers;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>';
658
			else
659
				$entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedposts;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>';
660
		}
661
662
		if (empty($entries[$k]['action_text']))
663
			$entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action'];
664
665
		$entries[$k]['action_text'] = preg_replace_callback(
666
			'~\{([A-Za-z\d_]+)\}~i',
667
			function($matches) use ($entries, $k)
668
			{
669
				return isset($entries[$k]['extra'][$matches[1]]) ? $entries[$k]['extra'][$matches[1]] : '';
670
			},
671
			$entries[$k]['action_text']
672
		);
673
	}
674
675
	// Back we go!
676
	return $entries;
677
}
678
679
?>