Passed
Push — release-2.1 ( 0c2197...207d2d )
by Jeremy
05:47
created

ViewModlog()   F

Complexity

Conditions 46
Paths > 20000

Size

Total Lines 282
Code Lines 176

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 46
eloc 176
c 0
b 0
f 0
nop 0
dl 0
loc 282
rs 0
nc 159252480

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 http://www.simplemachines.org
11
 * @copyright 2018 Simple Machines and individual contributors
12
 * @license http://www.simplemachines.org/about/smf/license.php BSD
13
 *
14
 * @version 2.1 Beta 4
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('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'] ? '&nbsp;
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
		);
312
}
313
314
/**
315
 * Get the number of mod log entries.
316
 * Callback for createList() in ViewModlog().
317
 *
318
 * @param string $query_string An extra string for the WHERE clause in the query to further filter results
319
 * @param array $query_params An array of parameters for the query_string
320
 * @param int $log_type The log type (1 for mod log, 3 for admin log)
321
 * @param bool $ignore_boards Whether to ignore board restrictions
322
 */
323
function list_getModLogEntryCount($query_string = '', $query_params = array(), $log_type = 1, $ignore_boards = false)
324
{
325
	global $smcFunc, $user_info;
326
327
	$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'))));
328
329
	$result = $smcFunc['db_query']('', '
330
		SELECT COUNT(*)
331
		FROM {db_prefix}log_actions AS lm
332
			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lm.id_member)
333
			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)
334
			LEFT JOIN {db_prefix}boards AS b ON (b.id_board = lm.id_board)
335
			LEFT JOIN {db_prefix}topics AS t ON (t.id_topic = lm.id_topic)
336
		WHERE id_log = {int:log_type}
337
			AND {raw:modlog_query}'
338
			. (!empty($query_string) ? '
339
				AND ' . $query_string : ''),
340
		array_merge($query_params, array(
341
			'reg_group_id' => 0,
342
			'log_type' => $log_type,
343
			'modlog_query' => $modlog_query,
344
		))
345
	);
346
	list ($entry_count) = $smcFunc['db_fetch_row']($result);
347
	$smcFunc['db_free_result']($result);
348
349
	return $entry_count;
350
}
351
352
/**
353
 * Gets the moderation log entries that match the specified parameters.
354
 * Callback for createList() in ViewModlog().
355
 *
356
 * @param int $start The item to start with (for pagination purposes)
357
 * @param int $items_per_page The number of items to show per page
358
 * @param string $sort A string indicating how to sort the results
359
 * @param string $query_string An extra string for the WHERE clause of the query, to further filter results
360
 * @param array $query_params An array of parameters for the query string
361
 * @param int $log_type The log type - 1 for mod log or 3 for admin log
362
 * @param bool $ignore_boards Whether to ignore board restrictions
363
 * @return array An array of info about the mod log entries
364
 */
365
function list_getModLogEntries($start, $items_per_page, $sort, $query_string = '', $query_params = array(), $log_type = 1, $ignore_boards = false)
366
{
367
	global $scripturl, $txt, $smcFunc, $user_info;
368
369
	$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'))));
370
371
	// Can they see the IP address?
372
	$seeIP = allowedTo('moderate_forum');
373
374
	// Here we have the query getting the log details.
375
	$result = $smcFunc['db_query']('', '
376
		SELECT
377
			lm.id_action, lm.id_member, lm.ip, lm.log_time, lm.action, lm.id_board, lm.id_topic, lm.id_msg, lm.extra,
378
			mem.real_name, mg.group_name
379
		FROM {db_prefix}log_actions AS lm
380
			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lm.id_member)
381
			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)
382
			LEFT JOIN {db_prefix}boards AS b ON (b.id_board = lm.id_board)
383
			LEFT JOIN {db_prefix}topics AS t ON (t.id_topic = lm.id_topic)
384
			WHERE id_log = {int:log_type}
385
				AND {raw:modlog_query}'
386
			. (!empty($query_string) ? '
387
				AND ' . $query_string : '') . '
388
		ORDER BY {raw:sort}
389
		LIMIT {int:start}, {int:max}',
390
		array_merge($query_params, array(
391
			'reg_group_id' => 0,
392
			'log_type' => $log_type,
393
			'modlog_query' => $modlog_query,
394
			'sort' => $sort,
395
			'start' => $start,
396
			'max' => $items_per_page,
397
		))
398
	);
399
400
	// Arrays for decoding objects into.
401
	$topics = array();
402
	$boards = array();
403
	$members = array();
404
	$messages = array();
405
	$entries = array();
406
	while ($row = $smcFunc['db_fetch_assoc']($result))
407
	{
408
		$row['extra'] = $smcFunc['json_decode']($row['extra'], true);
409
410
		// Corrupt?
411
		$row['extra'] = is_array($row['extra']) ? $row['extra'] : array();
412
413
		// Add on some of the column stuff info
414
		if (!empty($row['id_board']))
415
		{
416
			if ($row['action'] == 'move')
417
				$row['extra']['board_to'] = $row['id_board'];
418
			else
419
				$row['extra']['board'] = $row['id_board'];
420
		}
421
422
		if (!empty($row['id_topic']))
423
			$row['extra']['topic'] = $row['id_topic'];
424
		if (!empty($row['id_msg']))
425
			$row['extra']['message'] = $row['id_msg'];
426
427
		// Is this associated with a topic?
428
		if (isset($row['extra']['topic']))
429
			$topics[(int) $row['extra']['topic']][] = $row['id_action'];
430
		if (isset($row['extra']['new_topic']))
431
			$topics[(int) $row['extra']['new_topic']][] = $row['id_action'];
432
433
		// How about a member?
434
		if (isset($row['extra']['member']))
435
		{
436
			// Guests don't have names!
437
			if (empty($row['extra']['member']))
438
				$row['extra']['member'] = $txt['modlog_parameter_guest'];
439
			else
440
			{
441
				// Try to find it...
442
				$members[(int) $row['extra']['member']][] = $row['id_action'];
443
			}
444
		}
445
446
		// Associated with a board?
447
		if (isset($row['extra']['board_to']))
448
			$boards[(int) $row['extra']['board_to']][] = $row['id_action'];
449
		if (isset($row['extra']['board_from']))
450
			$boards[(int) $row['extra']['board_from']][] = $row['id_action'];
451
		if (isset($row['extra']['board']))
452
			$boards[(int) $row['extra']['board']][] = $row['id_action'];
453
454
		// A message?
455
		if (isset($row['extra']['message']))
456
			$messages[(int) $row['extra']['message']][] = $row['id_action'];
457
458
		// IP Info?
459
		if (isset($row['extra']['ip_range']))
460
			if ($seeIP)
461
				$row['extra']['ip_range'] = '<a href="' . $scripturl . '?action=trackip;searchip=' . $row['extra']['ip_range'] . '">' . $row['extra']['ip_range'] . '</a>';
462
			else
463
				$row['extra']['ip_range'] = $txt['logged'];
464
465
		// Email?
466
		if (isset($row['extra']['email']))
467
			$row['extra']['email'] = '<a href="mailto:' . $row['extra']['email'] . '">' . $row['extra']['email'] . '</a>';
468
469
		// Bans are complex.
470
		if ($row['action'] == 'ban' || $row['action'] == 'banremove')
471
		{
472
			$row['action_text'] = $txt['modlog_ac_ban' . ($row['action'] == 'banremove' ? '_remove' : '')];
473
			foreach (array('member', 'email', 'ip_range', 'hostname') as $type)
474
				if (isset($row['extra'][$type]))
475
					$row['action_text'] .= $txt['modlog_ac_ban_trigger_' . $type];
476
		}
477
478
		// 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.
479
		$entries[$row['id_action']] = array(
480
			'id' => $row['id_action'],
481
			'ip' => $seeIP ? inet_dtop($row['ip']) : $txt['logged'],
482
			'position' => empty($row['real_name']) && empty($row['group_name']) ? $txt['guest'] : $row['group_name'],
483
			'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']),
484
			'time' => timeformat($row['log_time']),
485
			'timestamp' => forum_time(true, $row['log_time']),
486
			'editable' => substr($row['action'], 0, 8) !== 'clearlog',
487
			'extra' => $row['extra'],
488
			'action' => $row['action'],
489
			'action_text' => isset($row['action_text']) ? $row['action_text'] : '',
490
		);
491
	}
492
	$smcFunc['db_free_result']($result);
493
494
	if (!empty($boards))
495
	{
496
		$request = $smcFunc['db_query']('', '
497
			SELECT id_board, name
498
			FROM {db_prefix}boards
499
			WHERE id_board IN ({array_int:board_list})
500
			LIMIT {int:limit}',
501
			array(
502
				'board_list' => array_keys($boards),
503
				'limit' => count(array_keys($boards)),
504
			)
505
		);
506
		while ($row = $smcFunc['db_fetch_assoc']($request))
507
		{
508
			foreach ($boards[$row['id_board']] as $action)
509
			{
510
				// Make the board number into a link - dealing with moving too.
511
				if (isset($entries[$action]['extra']['board_to']) && $entries[$action]['extra']['board_to'] == $row['id_board'])
512
					$entries[$action]['extra']['board_to'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
513
				elseif (isset($entries[$action]['extra']['board_from']) && $entries[$action]['extra']['board_from'] == $row['id_board'])
514
					$entries[$action]['extra']['board_from'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
515
				elseif (isset($entries[$action]['extra']['board']) && $entries[$action]['extra']['board'] == $row['id_board'])
516
					$entries[$action]['extra']['board'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
517
			}
518
		}
519
		$smcFunc['db_free_result']($request);
520
	}
521
522
	if (!empty($topics))
523
	{
524
		$request = $smcFunc['db_query']('', '
525
			SELECT ms.subject, t.id_topic
526
			FROM {db_prefix}topics AS t
527
				INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
528
			WHERE t.id_topic IN ({array_int:topic_list})
529
			LIMIT {int:limit}',
530
			array(
531
				'topic_list' => array_keys($topics),
532
				'limit' => count(array_keys($topics)),
533
			)
534
		);
535
		while ($row = $smcFunc['db_fetch_assoc']($request))
536
		{
537
			foreach ($topics[$row['id_topic']] as $action)
538
			{
539
				$this_action = &$entries[$action];
540
541
				// This isn't used in the current theme.
542
				$this_action['topic'] = array(
543
					'id' => $row['id_topic'],
544
					'subject' => $row['subject'],
545
					'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
546
					'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>'
547
				);
548
549
				// Make the topic number into a link - dealing with splitting too.
550
				if (isset($this_action['extra']['topic']) && $this_action['extra']['topic'] == $row['id_topic'])
551
					$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>';
552
				elseif (isset($this_action['extra']['new_topic']) && $this_action['extra']['new_topic'] == $row['id_topic'])
553
					$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>';
554
			}
555
		}
556
		$smcFunc['db_free_result']($request);
557
	}
558
559
	if (!empty($messages))
560
	{
561
		$request = $smcFunc['db_query']('', '
562
			SELECT id_msg, subject
563
			FROM {db_prefix}messages
564
			WHERE id_msg IN ({array_int:message_list})
565
			LIMIT {int:limit}',
566
			array(
567
				'message_list' => array_keys($messages),
568
				'limit' => count(array_keys($messages)),
569
			)
570
		);
571
		while ($row = $smcFunc['db_fetch_assoc']($request))
572
		{
573
			foreach ($messages[$row['id_msg']] as $action)
574
			{
575
				$this_action = &$entries[$action];
576
577
				// This isn't used in the current theme.
578
				$this_action['message'] = array(
579
					'id' => $row['id_msg'],
580
					'subject' => $row['subject'],
581
					'href' => $scripturl . '?msg=' . $row['id_msg'],
582
					'link' => '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>',
583
				);
584
585
				// Make the message number into a link.
586
				if (isset($this_action['extra']['message']) && $this_action['extra']['message'] == $row['id_msg'])
587
					$this_action['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
588
			}
589
		}
590
		$smcFunc['db_free_result']($request);
591
	}
592
593
	if (!empty($members))
594
	{
595
		$request = $smcFunc['db_query']('', '
596
			SELECT real_name, id_member
597
			FROM {db_prefix}members
598
			WHERE id_member IN ({array_int:member_list})
599
			LIMIT {int:limit}',
600
			array(
601
				'member_list' => array_keys($members),
602
				'limit' => count(array_keys($members)),
603
			)
604
		);
605
		while ($row = $smcFunc['db_fetch_assoc']($request))
606
		{
607
			foreach ($members[$row['id_member']] as $action)
608
			{
609
				// Not used currently.
610
				$entries[$action]['member'] = array(
611
					'id' => $row['id_member'],
612
					'name' => $row['real_name'],
613
					'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
614
					'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'
615
				);
616
				// Make the member number into a name.
617
				$entries[$action]['extra']['member'] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
618
			}
619
		}
620
		$smcFunc['db_free_result']($request);
621
	}
622
623
	// Do some formatting of the action string.
624
	foreach ($entries as $k => $entry)
625
	{
626
		// Make any message info links so its easier to go find that message.
627
		if (isset($entry['extra']['message']) && (empty($entry['message']) || empty($entry['message']['id'])))
628
			$entries[$k]['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $entry['extra']['message'] . '">' . $entry['extra']['message'] . '</a>';
629
630
		// Mark up any deleted members, topics and boards.
631
		foreach (array('board', 'board_from', 'board_to', 'member', 'topic', 'new_topic') as $type)
632
			if (!empty($entry['extra'][$type]) && is_numeric($entry['extra'][$type]))
633
				$entries[$k]['extra'][$type] = sprintf($txt['modlog_id'], $entry['extra'][$type]);
634
635
		if (isset($entry['extra']['report']))
636
		{
637
			// Member profile reports go in a different area
638
			if (stristr($entry['action'], 'user_report'))
639
				$entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedmembers;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>';
640
			else
641
				$entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedposts;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>';
642
		}
643
644
		if (empty($entries[$k]['action_text']))
645
			$entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action'];
646
		$entries[$k]['action_text'] = preg_replace_callback('~\{([A-Za-z\d_]+)\}~i',
647
			function ($matches) use ($entries, $k)
648
			{
649
				return isset($entries[$k]['extra'][$matches[1]]) ? $entries[$k]['extra'][$matches[1]] : '';
650
			}, $entries[$k]['action_text']);
651
	}
652
653
	// Back we go!
654
	return $entries;
655
}
656
657
?>