Passed
Pull Request — release-2.1 (#6826)
by Jon
05:11
created

list_getNumAttachments()   B

Complexity

Conditions 9

Size

Total Lines 31
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 19
c 0
b 0
f 0
nop 2
dl 0
loc 31
rs 8.0555
1
<?php
2
3
/**
4
 * Simple Machines Forum (SMF)
5
 *
6
 * @package SMF
7
 * @author Simple Machines https://www.simplemachines.org
8
 * @copyright 2021 Simple Machines and individual contributors
9
 * @license https://www.simplemachines.org/about/smf/license.php BSD
10
 *
11
 * @version 2.1 RC4
12
 */
13
14
if (!defined('SMF'))
15
	die('No direct access...');
16
17
/**
18
 * View a summary.
19
 *
20
 * @param int $memID The ID of the member
21
 */
22
function summary($memID)
23
{
24
	global $context, $memberContext, $txt, $modSettings, $user_profile, $sourcedir, $scripturl, $smcFunc;
25
26
	// Attempt to load the member's profile data.
27
	if (!loadMemberContext($memID) || !isset($memberContext[$memID]))
28
		fatal_lang_error('not_a_user', false, 404);
0 ignored issues
show
Bug introduced by
404 of type integer is incompatible with the type array expected by parameter $sprintf of fatal_lang_error(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
		fatal_lang_error('not_a_user', false, /** @scrutinizer ignore-type */ 404);
Loading history...
29
30
	// Set up the stuff and load the user.
31
	$context += array(
32
		'page_title' => sprintf($txt['profile_of_username'], $memberContext[$memID]['name']),
33
		'can_send_pm' => allowedTo('pm_send'),
34
		'can_have_buddy' => allowedTo('profile_extra_own') && !empty($modSettings['enable_buddylist']),
35
		'can_issue_warning' => allowedTo('issue_warning') && $modSettings['warning_settings'][0] == 1,
36
		'can_view_warning' => (allowedTo('moderate_forum') || allowedTo('issue_warning') || allowedTo('view_warning_any') || ($context['user']['is_owner'] && allowedTo('view_warning_own'))) && $modSettings['warning_settings'][0] === '1'
37
	);
38
39
	$context['member'] = &$memberContext[$memID];
40
41
	// Set a canonical URL for this page.
42
	$context['canonical_url'] = $scripturl . '?action=profile;u=' . $memID;
43
44
	// Are there things we don't show?
45
	$context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
46
	// Menu tab
47
	$context[$context['profile_menu_name']]['tab_data'] = array(
48
		'title' => $txt['summary'],
49
		'icon' => 'profile_hd.png'
50
	);
51
52
	// See if they have broken any warning levels...
53
	list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']);
54
	if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning'])
55
		$context['warning_status'] = $txt['profile_warning_is_muted'];
56
	elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning'])
57
		$context['warning_status'] = $txt['profile_warning_is_moderation'];
58
	elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning'])
59
		$context['warning_status'] = $txt['profile_warning_is_watch'];
60
61
	// They haven't even been registered for a full day!?
62
	$days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24));
63
	if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1)
64
		$context['member']['posts_per_day'] = $txt['not_applicable'];
65
	else
66
		$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
67
68
	// Set the age...
69
	if (empty($context['member']['birth_date']) || substr($context['member']['birth_date'], 0, 4) < 1002)
70
	{
71
		$context['member'] += array(
72
			'age' => $txt['not_applicable'],
73
			'today_is_birthday' => false
74
		);
75
	}
76
	else
77
	{
78
		list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d');
79
		$datearray = getdate(forum_time());
80
		$context['member'] += array(
81
			'age' => $birth_year <= 1004 ? $txt['not_applicable'] : $datearray['year'] - $birth_year - (($datearray['mon'] > $birth_month || ($datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day)) ? 0 : 1),
82
			'today_is_birthday' => $datearray['mon'] == $birth_month && $datearray['mday'] == $birth_day && $birth_year > 1004
83
		);
84
	}
85
86
	if (allowedTo('moderate_forum'))
87
	{
88
		// Make sure it's a valid ip address; otherwise, don't bother...
89
		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup']))
90
			$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
91
		else
92
			$context['member']['hostname'] = '';
93
94
		$context['can_see_ip'] = true;
95
	}
96
	else
97
		$context['can_see_ip'] = false;
98
99
	// Are they hidden?
100
	$context['member']['is_hidden'] = empty($user_profile[$memID]['show_online']);
101
	$context['member']['show_last_login'] = allowedTo('admin_forum') || !$context['member']['is_hidden'];
102
103
	if (!empty($modSettings['who_enabled']) && $context['member']['show_last_login'])
104
	{
105
		include_once($sourcedir . '/Who.php');
106
		$action = determineActions($user_profile[$memID]['url']);
107
108
		if ($action !== false)
0 ignored issues
show
introduced by
The condition $action !== false is always true.
Loading history...
109
			$context['member']['action'] = $action;
110
	}
111
112
	// If the user is awaiting activation, and the viewer has permission - setup some activation context messages.
113
	if ($context['member']['is_activated'] % 10 != 1 && allowedTo('moderate_forum'))
114
	{
115
		$context['activate_type'] = $context['member']['is_activated'];
116
		// What should the link text be?
117
		$context['activate_link_text'] = in_array($context['member']['is_activated'], array(3, 4, 5, 13, 14, 15)) ? $txt['account_approve'] : $txt['account_activate'];
118
119
		// Should we show a custom message?
120
		$context['activate_message'] = isset($txt['account_activate_method_' . $context['member']['is_activated'] % 10]) ? $txt['account_activate_method_' . $context['member']['is_activated'] % 10] : $txt['account_not_activated'];
121
122
		// If they can be approved, we need to set up a token for them.
123
		$context['token_check'] = 'profile-aa' . $memID;
124
		createToken($context['token_check'], 'get');
125
126
		// Puerile comment
127
		$context['activate_link'] = $scripturl . '?action=admin;area=viewmembers;sa=browse;type=approve;' . $context['session_var'] . '=' . $context['session_id'] . ';' . $context[$context['token_check'] . '_token_var'] . '=' . $context[$context['token_check'] . '_token'];
128
	}
129
130
	// Is the signature even enabled on this forum?
131
	$context['signature_enabled'] = substr($modSettings['signature_settings'], 0, 1) == 1;
132
133
	// Prevent signature images from going outside the box.
134
	if ($context['signature_enabled'])
135
	{
136
		list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
137
		$sig_limits = explode(',', $sig_limits);
138
139
		if (!empty($sig_limits[5]) || !empty($sig_limits[6]))
140
			addInlineCss('
141
	.signature img { ' . (!empty($sig_limits[5]) ? 'max-width: ' . (int) $sig_limits[5] . 'px; ' : '') . (!empty($sig_limits[6]) ? 'max-height: ' . (int) $sig_limits[6] . 'px; ' : '') . '}');
142
	}
143
144
	// How about, are they banned?
145
	$context['member']['bans'] = array();
146
	if (allowedTo('moderate_forum'))
147
	{
148
		// Can they edit the ban?
149
		$context['can_edit_ban'] = allowedTo('manage_bans');
150
151
		$ban_query = array();
152
		$ban_query_vars = array(
153
			'time' => time(),
154
		);
155
		$ban_query[] = 'id_member = ' . $context['member']['id'];
156
		$ban_query[] = ' {inet:ip} BETWEEN bi.ip_low and bi.ip_high';
157
		$ban_query_vars['ip'] = $memberContext[$memID]['ip'];
158
		// Do we have a hostname already?
159
		if (!empty($context['member']['hostname']))
160
		{
161
			$ban_query[] = '({string:hostname} LIKE hostname)';
162
			$ban_query_vars['hostname'] = $context['member']['hostname'];
163
		}
164
		// Check their email as well...
165
		if (strlen($context['member']['email']) != 0)
166
		{
167
			$ban_query[] = '({string:email} LIKE bi.email_address)';
168
			$ban_query_vars['email'] = $context['member']['email'];
169
		}
170
171
		// So... are they banned?  Dying to know!
172
		$request = $smcFunc['db_query']('', '
173
			SELECT bg.id_ban_group, bg.name, bg.cannot_access, bg.cannot_post,
174
				bg.cannot_login, bg.reason
175
			FROM {db_prefix}ban_items AS bi
176
				INNER JOIN {db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group AND (bg.expire_time IS NULL OR bg.expire_time > {int:time}))
177
			WHERE (' . implode(' OR ', $ban_query) . ')',
178
			$ban_query_vars
179
		);
180
		while ($row = $smcFunc['db_fetch_assoc']($request))
181
		{
182
			// Work out what restrictions we actually have.
183
			$ban_restrictions = array();
184
			foreach (array('access', 'login', 'post') as $type)
185
				if ($row['cannot_' . $type])
186
					$ban_restrictions[] = $txt['ban_type_' . $type];
187
188
			// No actual ban in place?
189
			if (empty($ban_restrictions))
190
				continue;
191
192
			// Prepare the link for context.
193
			$ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>');
194
195
			$context['member']['bans'][$row['id_ban_group']] = array(
196
				'reason' => empty($row['reason']) ? '' : '<br><br><strong>' . $txt['ban_reason'] . ':</strong> ' . $row['reason'],
197
				'cannot' => array(
198
					'access' => !empty($row['cannot_access']),
199
					'post' => !empty($row['cannot_post']),
200
					'login' => !empty($row['cannot_login']),
201
				),
202
				'explanation' => $ban_explanation,
203
			);
204
		}
205
		$smcFunc['db_free_result']($request);
206
	}
207
	loadCustomFields($memID);
208
209
	$context['print_custom_fields'] = array();
210
211
	// Any custom profile fields?
212
	if (!empty($context['custom_fields']))
213
		foreach ($context['custom_fields'] as $custom)
214
			$context['print_custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
215
216
}
217
218
/**
219
 * Fetch the alerts a member currently has.
220
 *
221
 * @param int $memID The ID of the member.
222
 * @param mixed $to_fetch Alerts to fetch: true/false for all/unread, or a list of one or more IDs.
223
 * @param array $limit Maximum number of alerts to fetch (0 for no limit).
224
 * @param array $offset Number of alerts to skip for pagination. Ignored if $to_fetch is a list of IDs.
225
 * @param bool $with_avatar Whether to load the avatar of the alert sender.
226
 * @param bool $show_links Whether to show links in the constituent parts of the alert meessage.
227
 * @return array An array of information about the fetched alerts.
228
 */
229
function fetch_alerts($memID, $to_fetch = false, $limit = 0, $offset = 0, $with_avatar = false, $show_links = false)
230
{
231
	global $smcFunc, $txt, $scripturl, $user_info, $user_profile, $modSettings, $context;
232
233
	// Are we being asked for some specific alerts?
234
	$alertIDs = is_bool($to_fetch) ? array() : array_filter(array_map('intval', (array) $to_fetch));
235
236
	// Basic sanitation.
237
	$memID = (int) $memID;
238
	$unread = $to_fetch === false;
239
	$limit = max(0, (int) $limit);
240
	$offset = !empty($alertIDs) ? 0 : max(0, (int) $offset);
241
	$with_avatar = !empty($with_avatar);
242
	$show_links = !empty($show_links);
243
244
	// Arrays we'll need.
245
	$alerts = array();
246
	$senders = array();
247
	$profiles = array();
248
	$profile_alerts = array();
249
	$possible_msgs = array();
250
	$possible_topics = array();
251
252
	// Get the basic alert info.
253
	$request = $smcFunc['db_query']('', '
254
		SELECT a.id_alert, a.alert_time, a.is_read, a.extra,
255
			a.content_type, a.content_id, a.content_action,
256
			mem.id_member AS sender_id, COALESCE(mem.real_name, a.member_name) AS sender_name' . ($with_avatar ? ',
257
			mem.email_address AS sender_email, mem.avatar AS sender_avatar, f.filename AS sender_filename' : '') . '
258
		FROM {db_prefix}user_alerts AS a
259
			LEFT JOIN {db_prefix}members AS mem ON (a.id_member_started = mem.id_member)' . ($with_avatar ? '
260
			LEFT JOIN {db_prefix}attachments AS f ON (mem.id_member = f.id_member)' : '') . '
261
		WHERE a.id_member = {int:id_member}' . ($unread ? '
262
			AND a.is_read = 0' : '') . (!empty($alertIDs) ? '
263
			AND a.id_alert IN ({array_int:alertIDs})' : '') . '
264
		ORDER BY id_alert DESC' . (!empty($limit) ? '
265
		LIMIT {int:limit}' : '') . (!empty($offset) ?'
266
		OFFSET {int:offset}' : ''),
267
		array(
268
			'id_member' => $memID,
269
			'alertIDs' => $alertIDs,
270
			'limit' => $limit,
271
			'offset' => $offset,
272
		)
273
	);
274
	while ($row = $smcFunc['db_fetch_assoc']($request))
275
	{
276
		$id_alert = array_shift($row);
277
		$row['time'] = timeformat($row['alert_time']);
278
		$row['extra'] = !empty($row['extra']) ? $smcFunc['json_decode']($row['extra'], true) : array();
279
		$alerts[$id_alert] = $row;
280
281
		if (!empty($row['sender_email']))
282
		{
283
			$senders[$row['sender_id']] = array(
284
				'email' => $row['sender_email'],
285
				'avatar' => $row['sender_avatar'],
286
				'filename' => $row['sender_filename'],
287
			);
288
		}
289
290
		if ($row['content_type'] == 'profile')
291
		{
292
			$profiles[] = $row['content_id'];
293
			$profile_alerts[] = $id_alert;
294
		}
295
296
		// For these types, we need to check whether they can actually see the content.
297
		if ($row['content_type'] == 'msg')
298
		{
299
			$alerts[$id_alert]['visible'] = false;
300
			$possible_msgs[$id_alert] = $row['content_id'];
301
		}
302
		elseif (in_array($row['content_type'], array('topic', 'board')))
303
		{
304
			$alerts[$id_alert]['visible'] = false;
305
			$possible_topics[$id_alert] = $row['content_id'];
306
		}
307
		// For the rest, they can always see it.
308
		else
309
			$alerts[$id_alert]['visible'] = true;
310
311
		// Are we showing multiple links or one big main link ?
312
		$alerts[$id_alert]['show_links'] = $show_links || (isset($row['extra']['show_links']) && $row['extra']['show_links']);
313
314
		// Set an appropriate icon.
315
		$alerts[$id_alert]['icon'] = set_alert_icon($alerts[$id_alert]);
316
	}
317
	$smcFunc['db_free_result']($request);
318
319
	// Look up member info of anyone we need it for.
320
	if (!empty($profiles))
321
		loadMemberData($profiles, false, 'minimal');
322
323
	// Get the senders' avatars.
324
	if ($with_avatar)
325
	{
326
		foreach ($senders as $sender_id => $sender)
327
			$senders[$sender_id]['avatar'] = set_avatar_data($sender);
328
329
		$context['avatar_url'] = $modSettings['avatar_url'];
330
	}
331
332
	// Now go through and actually make with the text.
333
	loadLanguage('Alerts');
334
335
	// Some sprintf formats for generating links/strings.
336
	// 'required' is an array of keys in $alert['extra'] that should be used to generate the message, ordered to match the sprintf formats.
337
	// 'link' and 'text' are the sprintf formats that will be used when $alert['show_links'] is true or false, respectively.
338
	$formats['msg_msg'] = array(
0 ignored issues
show
Comprehensibility Best Practice introduced by
$formats was never initialized. Although not strictly required by PHP, it is generally a good practice to add $formats = array(); before regardless.
Loading history...
339
		'required' => array('content_subject', 'topic', 'msg'),
340
		'link' => '<a href="{scripturl}?topic=%2$d.msg%3$d#msg%3$d">%1$s</a>',
341
		'text' => '<strong>%1$s</strong>',
342
	);
343
	$formats['topic_msg'] = array(
344
		'required' => array('content_subject', 'topic', 'topic_suffix'),
345
		'link' => '<a href="{scripturl}?topic=%2$d.%3$s">%1$s</a>',
346
		'text' => '<strong>%1$s</strong>',
347
	);
348
	$formats['board_msg'] = array(
349
		'required' => array('board_name', 'board'),
350
		'link' => '<a href="{scripturl}?board=%2$d.0">%1$s</a>',
351
		'text' => '<strong>%1$s</strong>',
352
	);
353
	$formats['profile_msg'] = array(
354
		'required' => array('user_name', 'user_id'),
355
		'link' => '<a href="{scripturl}?action=profile;u=%2$d">%1$s</a>',
356
		'text' => '<strong>%1$s</strong>',
357
	);
358
359
	// Hooks might want to do something snazzy around their own content types - including enforcing permissions if appropriate.
360
	call_integration_hook('integrate_fetch_alerts', array(&$alerts, &$formats));
361
362
	// Substitute $scripturl into the link formats. (Done here to make life easier for hooked mods.)
363
	$formats = array_map(function ($format) use ($scripturl) {
364
		$format['link'] = str_replace('{scripturl}', $scripturl, $format['link']);
365
		$format['text'] = str_replace('{scripturl}', $scripturl, $format['text']);
366
367
		return $format;
368
	}, $formats);
369
370
	// If we need to check board access, use the correct board access filter for the member in question.
371
	if ((!isset($user_info['query_see_board']) || $user_info['id'] != $memID) && (!empty($possible_msgs) || !empty($possible_topics)))
372
		$qb = build_query_board($memID);
373
	else
374
		$qb['query_see_board'] = '{query_see_board}';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$qb was never initialized. Although not strictly required by PHP, it is generally a good practice to add $qb = array(); before regardless.
Loading history...
375
376
	// For anything that needs more info and/or wants us to check board or topic access, let's do that.
377
	if (!empty($possible_msgs))
378
	{
379
		$flipped_msgs = array();
380
		foreach ($possible_msgs as $id_alert => $id_msg)
381
		{
382
			if (!isset($flipped_msgs[$id_msg]))
383
				$flipped_msgs[$id_msg] = array();
384
385
			$flipped_msgs[$id_msg][] = $id_alert;
386
		}
387
388
		$request = $smcFunc['db_query']('', '
389
			SELECT m.id_msg, m.id_topic, m.subject, b.id_board, b.name AS board_name
390
			FROM {db_prefix}messages AS m
391
				INNER JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
392
			WHERE ' . $qb['query_see_board'] . '
393
				AND m.id_msg IN ({array_int:msgs})
394
			ORDER BY m.id_msg',
395
			array(
396
				'msgs' => $possible_msgs,
397
			)
398
		);
399
		while ($row = $smcFunc['db_fetch_assoc']($request))
400
		{
401
			foreach ($flipped_msgs[$row['id_msg']] as $id_alert)
402
			{
403
				$alerts[$id_alert]['content_data'] = $row;
404
				$alerts[$id_alert]['visible'] = true;
405
			}
406
		}
407
		$smcFunc['db_free_result']($request);
408
	}
409
	if (!empty($possible_topics))
410
	{
411
		$flipped_topics = array();
412
		foreach ($possible_topics as $id_alert => $id_topic)
413
		{
414
			if (!isset($flipped_topics[$id_topic]))
415
				$flipped_topics[$id_topic] = array();
416
417
			$flipped_topics[$id_topic][] = $id_alert;
418
		}
419
420
		$request = $smcFunc['db_query']('', '
421
			SELECT m.id_msg, t.id_topic, m.subject, b.id_board, b.name AS board_name
422
			FROM {db_prefix}topics AS t
423
				INNER JOIN {db_prefix}messages AS m ON (t.id_first_msg = m.id_msg)
424
				INNER JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
425
			WHERE ' . $qb['query_see_board'] . '
426
				AND t.id_topic IN ({array_int:topics})',
427
			array(
428
				'topics' => $possible_topics,
429
			)
430
		);
431
		while ($row = $smcFunc['db_fetch_assoc']($request))
432
		{
433
			foreach ($flipped_topics[$row['id_topic']] as $id_alert)
434
			{
435
				$alerts[$id_alert]['content_data'] = $row;
436
				$alerts[$id_alert]['visible'] = true;
437
			}
438
		}
439
		$smcFunc['db_free_result']($request);
440
	}
441
442
	// Now to go back through the alerts, reattach this extra information and then try to build the string out of it (if a hook didn't already)
443
	foreach ($alerts as $id_alert => $dummy)
444
	{
445
		// There's no point showing alerts for inaccessible content.
446
		if (!$alerts[$id_alert]['visible'])
447
		{
448
			unset($alerts[$id_alert]);
449
			continue;
450
		}
451
		else
452
			unset($alerts[$id_alert]['visible']);
453
454
		// Did a mod already take care of this one?
455
		if (!empty($alerts[$id_alert]['text']))
456
			continue;
457
458
		// For developer convenience.
459
		$alert = &$alerts[$id_alert];
460
461
		// The info in extra might outdated if the topic was moved, the message's subject was changed, etc.
462
		if (!empty($alert['content_data']))
463
		{
464
			$data = $alert['content_data'];
465
466
			// Make sure msg, topic, and board info are correct.
467
			$patterns = array();
468
			$replacements = array();
469
			foreach (array('msg', 'topic', 'board') as $item)
470
			{
471
				if (isset($data['id_' . $item]))
472
				{
473
					$separator = $item == 'msg' ? '=?' : '=';
474
475
					if (isset($alert['extra']['content_link']) && strpos($alert['extra']['content_link'], $item . $separator) !== false && strpos($alert['extra']['content_link'], $item . $separator . $data['id_' . $item]) === false)
476
					{
477
						$patterns[] = '/\b' . $item . $separator . '\d+/';
478
						$replacements[] = $item . $separator . $data['id_' . $item];
479
					}
480
481
					$alert['extra'][$item] = $data['id_' . $item];
482
				}
483
			}
484
			if (!empty($patterns))
485
				$alert['extra']['content_link'] = preg_replace($patterns, $replacements, $alert['extra']['content_link']);
486
487
			// Make sure the subject is correct.
488
			if (isset($data['subject']))
489
				$alert['extra']['content_subject'] = $data['subject'];
490
491
			// Keep track of this so we can use it below.
492
			if (isset($data['board_name']))
493
				$alert['extra']['board_name'] = $data['board_name'];
494
495
			unset($alert['content_data']);
496
		}
497
498
		// Do we want to link to the topic in general or the new messages specifically?
499
		if (isset($possible_topics[$id_alert]) && in_array($alert['content_action'], array('reply', 'topic', 'unapproved_reply')))
500
				$alert['extra']['topic_suffix'] = 'new;topicseen#new';
501
		elseif (isset($alert['extra']['topic']))
502
			$alert['extra']['topic_suffix'] = '0';
503
504
		// Make sure profile alerts have what they need.
505
		if (in_array($id_alert, $profile_alerts))
506
		{
507
			if (empty($alert['extra']['user_id']))
508
				$alert['extra']['user_id'] = $alert['content_id'];
509
510
			if (isset($user_profile[$alert['extra']['user_id']]))
511
				$alert['extra']['user_name'] = $user_profile[$alert['extra']['user_id']]['real_name'];
512
		}
513
514
		// If we loaded the sender's profile, we may as well use it.
515
		$sender_id = !empty($alert['sender_id']) ? $alert['sender_id'] : 0;
516
		if (isset($user_profile[$sender_id]))
517
			$alert['sender_name'] = $user_profile[$sender_id]['real_name'];
518
519
		// If requested, include the sender's avatar data.
520
		if ($with_avatar && !empty($senders[$sender_id]))
521
			$alert['sender'] = $senders[$sender_id];
522
523
		// Next, build the message strings.
524
		foreach ($formats as $msg_type => $format_info)
525
		{
526
			// Get the values to use in the formatted string, in the right order.
527
			$msg_values = array_replace(
528
				array_fill_keys($format_info['required'], ''),
529
				array_intersect_key($alert['extra'], array_flip($format_info['required']))
530
			);
531
532
			// Assuming all required values are present, build the message.
533
			if (!in_array('', $msg_values))
534
				$alert['extra'][$msg_type] = vsprintf($formats[$msg_type][$alert['show_links'] ? 'link' : 'text'], $msg_values);
535
536
			elseif (in_array($msg_type, array('msg_msg', 'topic_msg', 'board_msg')))
537
				$alert['extra'][$msg_type] = $txt[$msg_type == 'board_msg' ? 'board_na' : 'topic_na'];
538
			else
539
				$alert['extra'][$msg_type] = '(' . $txt['not_applicable'] . ')';
540
		}
541
542
		// Show the formatted time in alerts about subscriptions.
543
		if ($alert['content_type'] == 'paidsubs' && isset($alert['extra']['end_time']))
544
		{
545
			// If the subscription already expired, say so.
546
			if ($alert['extra']['end_time'] < time())
547
				$alert['content_action'] = 'expired';
548
549
			// Present a nicely formatted date.
550
			$alert['extra']['end_time'] = timeformat($alert['extra']['end_time']);
551
		}
552
553
		// Now set the main URL that this alert should take the user to.
554
		$alert['target_href'] = '';
555
556
		// Priority goes to explicitly specified links.
557
		if (isset($alert['extra']['content_link']))
558
			$alert['target_href'] = $alert['extra']['content_link'];
559
560
		elseif (isset($alert['extra']['report_link']))
561
			$alert['target_href'] = $scripturl . $alert['extra']['report_link'];
562
563
		// Next, try determining the link based on the content action.
564
		if (empty($alert['target_href']) && in_array($alert['content_action'], array('register_approval', 'group_request', 'buddy_request')))
565
		{
566
			switch ($alert['content_action'])
567
			{
568
				case 'register_approval':
569
					$alert['target_href'] = $scripturl . '?action=admin;area=viewmembers;sa=browse;type=approve';
570
					break;
571
572
				case 'group_request':
573
					$alert['target_href'] = $scripturl . '?action=moderate;area=groups;sa=requests';
574
					break;
575
576
				case 'buddy_request':
577
					if (!empty($alert['id_member_started']))
578
						$alert['target_href'] = $scripturl . '?action=profile;u=' . $alert['id_member_started'];
579
					break;
580
581
				default:
582
					break;
583
			}
584
		}
585
586
		// Or maybe we can determine the link based on the content type.
587
		if (empty($alert['target_href']) && in_array($alert['content_type'], array('msg', 'member', 'event')))
588
		{
589
			switch ($alert['content_type'])
590
			{
591
				case 'msg':
592
					if (!empty($alert['content_id']))
593
						$alert['target_href'] = $scripturl . '?msg=' . $alert['content_id'];
594
					break;
595
596
				case 'member':
597
					if (!empty($alert['id_member_started']))
598
						$alert['target_href'] = $scripturl . '?action=profile;u=' . $alert['id_member_started'];
599
					break;
600
601
				case 'event':
602
					if (!empty($alert['extra']['event_id']))
603
						$alert['target_href'] = $scripturl . '?action=calendar;event=' . $alert['extra']['event_id'];
604
					break;
605
606
				default:
607
					break;
608
			}
609
610
		}
611
612
		// Finally, set this alert's text string.
613
		$string = 'alert_' . $alert['content_type'] . '_' . $alert['content_action'];
614
615
		// This kludge exists because the alert content_types prior to 2.1 RC3 were a bit haphazard.
616
		// This can be removed once all the translated language files have been updated.
617
		if (!isset($txt[$string]))
618
		{
619
			if (strpos($alert['content_action'], 'unapproved_') === 0)
620
				$string = 'alert_' . $alert['content_action'];
621
622
			if ($alert['content_type'] === 'member' && in_array($alert['content_action'], array('report', 'report_reply')))
623
				$string = 'alert_profile_' . $alert['content_action'];
624
625
			if ($alert['content_type'] === 'member' && $alert['content_action'] === 'buddy_request')
626
				$string = 'alert_buddy_' . $alert['content_action'];
627
		}
628
629
		if (isset($txt[$string]))
630
		{
631
			$substitutions = array(
632
				'{scripturl}' => $scripturl,
633
				'{member_link}' => !empty($sender_id) && $alert['show_links'] ? '<a href="' . $scripturl . '?action=profile;u=' . $sender_id . '">' . $alert['sender_name'] . '</a>' : '<strong>' . $alert['sender_name'] . '</strong>',
634
			);
635
636
			if (is_array($alert['extra']))
637
			{
638
				foreach ($alert['extra'] as $k => $v)
639
					$substitutions['{' . $k . '}'] = $v;
640
			}
641
642
			$alert['text'] = strtr($txt[$string], $substitutions);
643
		}
644
645
		// Unset the reference variable to avoid any surprises in subsequent loops.
646
		unset($alert);
647
	}
648
649
	return $alerts;
650
}
651
652
/**
653
 * Shows all alerts for a member
654
 *
655
 * @param int $memID The ID of the member
656
 */
657
function showAlerts($memID)
658
{
659
	global $context, $smcFunc, $txt, $sourcedir, $scripturl, $options;
660
661
	require_once($sourcedir . '/Profile-Modify.php');
662
663
	// Are we opening a specific alert? (i.e.: ?action=profile;area=showalerts;alert=12345)
664
	if (!empty($_REQUEST['alert']))
665
	{
666
		$alert_id = (int) $_REQUEST['alert'];
667
		$alerts = fetch_alerts($memID, $alert_id);
668
		$alert = array_pop($alerts);
669
670
		/*
671
		 * MOD AUTHORS:
672
		 * To control this redirect, use the 'integrate_fetch_alerts' hook to
673
		 * set the value of $alert['extra']['content_link'], which will become
674
		 * the value for $alert['target_href'].
675
		 */
676
677
		// In case it failed to determine this alert's link
678
		if (empty($alert['target_href']))
679
			redirectexit('action=profile;area=showalerts');
680
681
		// Mark the alert as read while we're at it.
682
		alert_mark($memID, $alert_id, 1);
683
684
		// Take the user to the content
685
		redirectexit($alert['target_href']);
686
	}
687
688
	// Prepare the pagination vars.
689
	$maxIndex = 10;
690
	$context['start'] = (int) isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
691
	$count = alert_count($memID);
692
693
	// Fix invalid 'start' offsets.
694
	if ($context['start'] > $count)
695
		$context['start'] = $count - ($count % $maxIndex);
696
	else
697
		$context['start'] = $context['start'] - ($context['start'] % $maxIndex);
698
699
	// Get the alerts.
700
	$context['alerts'] = fetch_alerts($memID, true, $maxIndex, $context['start'], true, true);
0 ignored issues
show
Bug introduced by
$maxIndex of type integer is incompatible with the type array expected by parameter $limit of fetch_alerts(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

700
	$context['alerts'] = fetch_alerts($memID, true, /** @scrutinizer ignore-type */ $maxIndex, $context['start'], true, true);
Loading history...
701
	$toMark = false;
702
	$action = '';
703
704
	//  Are we using checkboxes?
705
	$context['showCheckboxes'] = !empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1;
706
707
	// Create the pagination.
708
	$context['pagination'] = constructPageIndex($scripturl . '?action=profile;area=showalerts;u=' . $memID, $context['start'], $count, $maxIndex, false);
709
710
	// Set some JavaScript for checking all alerts at once.
711
	if ($context['showCheckboxes'])
712
		addInlineJavaScript('
713
		$(function(){
714
			$(\'#select_all\').on(\'change\', function() {
715
				var checkboxes = $(\'ul.quickbuttons\').find(\':checkbox\');
716
				if($(this).prop(\'checked\')) {
717
					checkboxes.prop(\'checked\', true);
718
				}
719
				else {
720
					checkboxes.prop(\'checked\', false);
721
				}
722
			});
723
		});', true);
724
725
	// The quickbuttons
726
	foreach ($context['alerts'] as $id => $alert)
727
	{
728
		$context['alerts'][$id]['quickbuttons'] = array(
729
			'delete' => array(
730
				'label' => $txt['delete'],
731
				'href' => $scripturl . '?action=profile;u=' . $context['id_member'] . ';area=showalerts;do=remove;aid=' . $id . ';' . $context['session_var'] . '=' . $context['session_id'] . (!empty($context['start']) ? ';start=' . $context['start'] : ''),
732
				'class' => 'you_sure',
733
				'icon' => 'remove_button'
734
			),
735
			'mark' => array(
736
				'label' => $alert['is_read'] != 0 ? $txt['mark_unread'] : $txt['mark_read_short'],
737
				'href' => $scripturl . '?action=profile;u=' . $context['id_member'] . ';area=showalerts;do=' . ($alert['is_read'] != 0 ? 'unread' : 'read') . ';aid=' . $id . ';' . $context['session_var'] . '=' . $context['session_id'] . (!empty($context['start']) ? ';start=' . $context['start'] : ''),
738
				'icon' => $alert['is_read'] != 0 ? 'unread_button' : 'read_button',
739
			),
740
			'view' => array(
741
				'label' => $txt['view'],
742
				'href' => $scripturl . '?action=profile;area=showalerts;alert=' . $id . ';',
743
				'icon' => 'move',
744
			),
745
			'quickmod' => array(
746
    			'class' => 'inline_mod_check',
747
				'content' => '<input type="checkbox" name="mark[' . $id . ']" value="' . $id . '">',
748
				'show' => $context['showCheckboxes']
749
			)
750
		);
751
	}
752
753
	// The Delete all unread link.
754
	$context['alert_purge_link'] = $scripturl . '?action=profile;u=' . $context['id_member'] . ';area=showalerts;do=purge;' . $context['session_var'] . '=' . $context['session_id'] . (!empty($context['start']) ? ';start=' . $context['start'] : '');
755
756
	// Set a nice message.
757
	if (!empty($_SESSION['update_message']))
758
	{
759
		$context['update_message'] = $txt['profile_updated_own'];
760
		unset($_SESSION['update_message']);
761
	}
762
763
	// Saving multiple changes?
764
	if (isset($_GET['save']) && !empty($_POST['mark']))
765
	{
766
		// Get the values.
767
		$toMark = array_map('intval', (array) $_POST['mark']);
768
769
		// Which action?
770
		$action = !empty($_POST['mark_as']) ? $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_POST['mark_as'])) : '';
771
	}
772
773
	// A single change.
774
	if (!empty($_GET['do']) && !empty($_GET['aid']))
775
	{
776
		$toMark = (int) $_GET['aid'];
777
		$action = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_GET['do']));
778
	}
779
	// Delete all read alerts.
780
	elseif (!empty($_GET['do']) && $_GET['do'] === 'purge')
781
		$action = 'purge';
782
783
	// Save the changes.
784
	if (!empty($action) && (!empty($toMark) || $action === 'purge'))
785
	{
786
		checkSession('request');
787
788
		// Call it!
789
		if ($action == 'remove')
790
			alert_delete($toMark, $memID);
791
792
		elseif ($action == 'purge')
793
			alert_purge($memID);
794
795
		else
796
			alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
797
798
		// Set a nice update message.
799
		$_SESSION['update_message'] = true;
800
801
		// Redirect.
802
		redirectexit('action=profile;area=showalerts;u=' . $memID . (!empty($context['start']) ? ';start=' . $context['start'] : ''));
803
	}
804
}
805
806
/**
807
 * Show all posts by a member
808
 *
809
 * @todo This function needs to be split up properly.
810
 *
811
 * @param int $memID The ID of the member
812
 */
813
function showPosts($memID)
814
{
815
	global $txt, $user_info, $scripturl, $modSettings, $options;
816
	global $context, $user_profile, $sourcedir, $smcFunc, $board;
817
818
	// Some initial context.
819
	$context['start'] = (int) $_REQUEST['start'];
820
	$context['current_member'] = $memID;
821
822
	// Create the tabs for the template.
823
	$context[$context['profile_menu_name']]['tab_data'] = array(
824
		'title' => $txt['showPosts'],
825
		'description' => $txt['showPosts_help'],
826
		'icon' => 'profile_hd.png',
827
		'tabs' => array(
828
			'messages' => array(
829
			),
830
			'topics' => array(
831
			),
832
			'unwatchedtopics' => array(
833
			),
834
			'attach' => array(
835
			),
836
		),
837
	);
838
839
	// Shortcut used to determine which $txt['show*'] string to use for the title, based on the SA
840
	$title = array(
841
		'attach' => 'Attachments',
842
		'topics' => 'Topics'
843
	);
844
845
	if ($context['user']['is_owner'])
846
		$title['unwatchedtopics'] = 'Unwatched';
847
848
	// Set the page title
849
	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title))
850
		$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
851
	else
852
		$context['page_title'] = $txt['showPosts'];
853
854
	$context['page_title'] .= ' - ' . $user_profile[$memID]['real_name'];
855
856
	// Is the load average too high to allow searching just now?
857
	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts'])
858
		fatal_lang_error('loadavg_show_posts_disabled', false);
859
860
	// If we're specifically dealing with attachments use that function!
861
	if (isset($_GET['sa']) && $_GET['sa'] == 'attach')
862
		return showAttachments($memID);
863
	// Instead, if we're dealing with unwatched topics (and the feature is enabled) use that other function.
864
	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics' && $context['user']['is_owner'])
865
		return showUnwatched($memID);
0 ignored issues
show
Bug introduced by
Are you sure the usage of showUnwatched($memID) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
866
867
	// Are we just viewing topics?
868
	$context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false;
869
870
	// If just deleting a message, do it and then redirect back.
871
	if (isset($_GET['delete']) && !$context['is_topics'])
872
	{
873
		checkSession('get');
874
875
		// We need msg info for logging.
876
		$request = $smcFunc['db_query']('', '
877
			SELECT subject, id_member, id_topic, id_board
878
			FROM {db_prefix}messages
879
			WHERE id_msg = {int:id_msg}',
880
			array(
881
				'id_msg' => (int) $_GET['delete'],
882
			)
883
		);
884
		$info = $smcFunc['db_fetch_row']($request);
885
		$smcFunc['db_free_result']($request);
886
887
		// Trying to remove a message that doesn't exist.
888
		if (empty($info))
889
			redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
890
891
		// We can be lazy, since removeMessage() will check the permissions for us.
892
		require_once($sourcedir . '/RemoveTopic.php');
893
		removeMessage((int) $_GET['delete']);
894
895
		// Add it to the mod log.
896
		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
897
			logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
898
899
		// Back to... where we are now ;).
900
		redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
901
	}
902
903
	// Default to 10.
904
	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
905
		$_REQUEST['viewscount'] = '10';
906
907
	if ($context['is_topics'])
908
		$request = $smcFunc['db_query']('', '
909
			SELECT COUNT(*)
910
			FROM {db_prefix}topics AS t' . '
911
			WHERE {query_see_topic_board}
912
				AND t.id_member_started = {int:current_member}' . (!empty($board) ? '
913
				AND t.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
914
				AND t.approved = {int:is_approved}'),
915
			array(
916
				'current_member' => $memID,
917
				'is_approved' => 1,
918
				'board' => $board,
919
			)
920
		);
921
	else
922
		$request = $smcFunc['db_query']('', '
923
			SELECT COUNT(*)
924
			FROM {db_prefix}messages AS m' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
925
				INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)') . '
926
			WHERE {query_see_message_board} AND m.id_member = {int:current_member}' . (!empty($board) ? '
927
				AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
928
				AND m.approved = {int:is_approved}
929
				AND t.approved = {int:is_approved}'),
930
			array(
931
				'current_member' => $memID,
932
				'is_approved' => 1,
933
				'board' => $board,
934
			)
935
		);
936
	list ($msgCount) = $smcFunc['db_fetch_row']($request);
937
	$smcFunc['db_free_result']($request);
938
939
	$request = $smcFunc['db_query']('', '
940
		SELECT MIN(id_msg), MAX(id_msg)
941
		FROM {db_prefix}messages AS m' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
942
			INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)') . '
943
		WHERE m.id_member = {int:current_member}' . (!empty($board) ? '
944
			AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
945
			AND m.approved = {int:is_approved}
946
			AND t.approved = {int:is_approved}'),
947
		array(
948
			'current_member' => $memID,
949
			'is_approved' => 1,
950
			'board' => $board,
951
		)
952
	);
953
	list ($min_msg_member, $max_msg_member) = $smcFunc['db_fetch_row']($request);
954
	$smcFunc['db_free_result']($request);
955
956
	$range_limit = '';
957
958
	if ($context['is_topics'])
959
		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
960
	else
961
		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
962
963
	$maxIndex = $maxPerPage;
964
965
	// Make sure the starting place makes sense and construct our friend the page index.
966
	$context['page_index'] = constructPageIndex($scripturl . '?action=profile;u=' . $memID . ';area=showposts' . ($context['is_topics'] ? ';sa=topics' : '') . (!empty($board) ? ';board=' . $board : ''), $context['start'], $msgCount, $maxIndex);
967
	$context['current_page'] = $context['start'] / $maxIndex;
968
969
	// Reverse the query if we're past 50% of the pages for better performance.
970
	$start = $context['start'];
971
	$reverse = $_REQUEST['start'] > $msgCount / 2;
972
	if ($reverse)
973
	{
974
		$maxIndex = $msgCount < $context['start'] + $maxPerPage + 1 && $msgCount > $context['start'] ? $msgCount - $context['start'] : $maxPerPage;
975
		$start = $msgCount < $context['start'] + $maxPerPage + 1 || $msgCount < $context['start'] + $maxPerPage ? 0 : $msgCount - $context['start'] - $maxPerPage;
976
	}
977
978
	// Guess the range of messages to be shown.
979
	if ($msgCount > 1000)
980
	{
981
		$margin = floor(($max_msg_member - $min_msg_member) * (($start + $maxPerPage) / $msgCount) + .1 * ($max_msg_member - $min_msg_member));
982
		// Make a bigger margin for topics only.
983
		if ($context['is_topics'])
984
		{
985
			$margin *= 5;
986
			$range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin);
987
		}
988
		else
989
			$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
990
	}
991
992
	// Find this user's posts.  The left join on categories somehow makes this faster, weird as it looks.
993
	$looped = false;
994
	while (true)
995
	{
996
		if ($context['is_topics'])
997
		{
998
			$request = $smcFunc['db_query']('', '
999
				SELECT
1000
					b.id_board, b.name AS bname, c.id_cat, c.name AS cname, t.id_member_started, t.id_first_msg, t.id_last_msg,
1001
					t.approved, m.body, m.smileys_enabled, m.subject, m.poster_time, m.id_topic, m.id_msg
1002
				FROM {db_prefix}topics AS t
1003
					INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
1004
					LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
1005
					INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
1006
				WHERE t.id_member_started = {int:current_member}' . (!empty($board) ? '
1007
					AND t.id_board = {int:board}' : '') . (empty($range_limit) ? '' : '
1008
					AND ' . $range_limit) . '
1009
					AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
1010
					AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . '
1011
				ORDER BY t.id_first_msg ' . ($reverse ? 'ASC' : 'DESC') . '
1012
				LIMIT {int:start}, {int:max}',
1013
				array(
1014
					'current_member' => $memID,
1015
					'is_approved' => 1,
1016
					'board' => $board,
1017
					'start' => $start,
1018
					'max' => $maxIndex,
1019
				)
1020
			);
1021
		}
1022
		else
1023
		{
1024
			$request = $smcFunc['db_query']('', '
1025
				SELECT
1026
					b.id_board, b.name AS bname, c.id_cat, c.name AS cname, m.id_topic, m.id_msg,
1027
					t.id_member_started, t.id_first_msg, t.id_last_msg, m.body, m.smileys_enabled,
1028
					m.subject, m.poster_time, m.approved
1029
				FROM {db_prefix}messages AS m
1030
					INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
1031
					INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
1032
					LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
1033
				WHERE m.id_member = {int:current_member}' . (!empty($board) ? '
1034
					AND b.id_board = {int:board}' : '') . (empty($range_limit) ? '' : '
1035
					AND ' . $range_limit) . '
1036
					AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
1037
					AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . '
1038
				ORDER BY m.id_msg ' . ($reverse ? 'ASC' : 'DESC') . '
1039
				LIMIT {int:start}, {int:max}',
1040
				array(
1041
					'current_member' => $memID,
1042
					'is_approved' => 1,
1043
					'board' => $board,
1044
					'start' => $start,
1045
					'max' => $maxIndex,
1046
				)
1047
			);
1048
		}
1049
1050
		// Make sure we quit this loop.
1051
		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped || $range_limit == '')
1052
			break;
1053
		$looped = true;
1054
		$range_limit = '';
1055
	}
1056
1057
	// Start counting at the number of the first message displayed.
1058
	$counter = $reverse ? $context['start'] + $maxIndex + 1 : $context['start'];
1059
	$context['posts'] = array();
1060
	$board_ids = array('own' => array(), 'any' => array());
1061
	while ($row = $smcFunc['db_fetch_assoc']($request))
1062
	{
1063
		// Censor....
1064
		censorText($row['body']);
1065
		censorText($row['subject']);
1066
1067
		// Do the code.
1068
		$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
1069
1070
		// And the array...
1071
		$context['posts'][$counter += $reverse ? -1 : 1] = array(
1072
			'body' => $row['body'],
1073
			'counter' => $counter,
1074
			'category' => array(
1075
				'name' => $row['cname'],
1076
				'id' => $row['id_cat']
1077
			),
1078
			'board' => array(
1079
				'name' => $row['bname'],
1080
				'id' => $row['id_board']
1081
			),
1082
			'topic' => $row['id_topic'],
1083
			'subject' => $row['subject'],
1084
			'start' => 'msg' . $row['id_msg'],
1085
			'time' => timeformat($row['poster_time']),
1086
			'timestamp' => forum_time(true, $row['poster_time']),
1087
			'id' => $row['id_msg'],
1088
			'can_reply' => false,
1089
			'can_mark_notify' => !$context['user']['is_guest'],
1090
			'can_delete' => false,
1091
			'delete_possible' => ($row['id_first_msg'] != $row['id_msg'] || $row['id_last_msg'] == $row['id_msg']) && (empty($modSettings['edit_disable_time']) || $row['poster_time'] + $modSettings['edit_disable_time'] * 60 >= time()),
1092
			'approved' => $row['approved'],
1093
			'css_class' => $row['approved'] ? 'windowbg' : 'approvebg',
1094
		);
1095
1096
		if ($user_info['id'] == $row['id_member_started'])
1097
			$board_ids['own'][$row['id_board']][] = $counter;
1098
		$board_ids['any'][$row['id_board']][] = $counter;
1099
	}
1100
	$smcFunc['db_free_result']($request);
1101
1102
	// All posts were retrieved in reverse order, get them right again.
1103
	if ($reverse)
1104
		$context['posts'] = array_reverse($context['posts'], true);
1105
1106
	// These are all the permissions that are different from board to board..
1107
	if ($context['is_topics'])
1108
		$permissions = array(
1109
			'own' => array(
1110
				'post_reply_own' => 'can_reply',
1111
			),
1112
			'any' => array(
1113
				'post_reply_any' => 'can_reply',
1114
			)
1115
		);
1116
	else
1117
		$permissions = array(
1118
			'own' => array(
1119
				'post_reply_own' => 'can_reply',
1120
				'delete_own' => 'can_delete',
1121
			),
1122
			'any' => array(
1123
				'post_reply_any' => 'can_reply',
1124
				'delete_any' => 'can_delete',
1125
			)
1126
		);
1127
1128
	// Create an array for the permissions.
1129
	$boards_can = boardsAllowedTo(array_keys(iterator_to_array(
1130
		new RecursiveIteratorIterator(new RecursiveArrayIterator($permissions)))
1131
	), true, false);
1132
1133
	// For every permission in the own/any lists...
1134
	foreach ($permissions as $type => $list)
1135
	{
1136
		foreach ($list as $permission => $allowed)
1137
		{
1138
			// Get the boards they can do this on...
1139
			$boards = $boards_can[$permission];
1140
1141
			// Hmm, they can do it on all boards, can they?
1142
			if (!empty($boards) && $boards[0] == 0)
1143
				$boards = array_keys($board_ids[$type]);
1144
1145
			// Now go through each board they can do the permission on.
1146
			foreach ($boards as $board_id)
1147
			{
1148
				// There aren't any posts displayed from this board.
1149
				if (!isset($board_ids[$type][$board_id]))
1150
					continue;
1151
1152
				// Set the permission to true ;).
1153
				foreach ($board_ids[$type][$board_id] as $counter)
1154
					$context['posts'][$counter][$allowed] = true;
1155
			}
1156
		}
1157
	}
1158
1159
	// Clean up after posts that cannot be deleted and quoted.
1160
	$quote_enabled = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC']));
1161
	foreach ($context['posts'] as $counter => $dummy)
1162
	{
1163
		$context['posts'][$counter]['can_delete'] &= $context['posts'][$counter]['delete_possible'];
1164
		$context['posts'][$counter]['can_quote'] = $context['posts'][$counter]['can_reply'] && $quote_enabled;
1165
	}
1166
1167
	// Allow last minute changes.
1168
	call_integration_hook('integrate_profile_showPosts');
1169
1170
	foreach ($context['posts'] as $key => $post)
1171
	{
1172
		$context['posts'][$key]['quickbuttons'] = array(
1173
			'reply' => array(
1174
				'label' => $txt['reply'],
1175
				'href' => $scripturl.'?action=post;topic='.$post['topic'].'.'.$post['start'],
1176
				'icon' => 'reply_button',
1177
				'show' => $post['can_reply']
1178
			),
1179
			'quote' => array(
1180
				'label' => $txt['quote_action'],
1181
				'href' => $scripturl.'?action=post;topic='.$post['topic'].'.'.$post['start'].';quote='.$post['id'],
1182
				'icon' => 'quote',
1183
				'show' => $post['can_quote']
1184
			),
1185
			'remove' => array(
1186
				'label' => $txt['remove'],
1187
				'href' => $scripturl.'?action=deletemsg;msg='.$post['id'].';topic='.$post['topic'].';profile;u='.$context['member']['id'].';start='.$context['start'].';'.$context['session_var'].'='.$context['session_id'],
1188
				'javascript' => 'data-confirm="'.$txt['remove_message'].'"',
1189
				'class' => 'you_sure',
1190
				'icon' => 'remove_button',
1191
				'show' => $post['can_delete']
1192
			)
1193
		);
1194
	}
1195
}
1196
1197
/**
1198
 * Show all the attachments belonging to a member.
1199
 *
1200
 * @param int $memID The ID of the member
1201
 */
1202
function showAttachments($memID)
1203
{
1204
	global $txt, $scripturl, $modSettings;
1205
	global $sourcedir;
1206
1207
	// OBEY permissions!
1208
	$boardsAllowed = boardsAllowedTo('view_attachments');
1209
1210
	// Make sure we can't actually see anything...
1211
	if (empty($boardsAllowed))
1212
		$boardsAllowed = array(-1);
1213
1214
	require_once($sourcedir . '/Subs-List.php');
1215
1216
	// This is all the information required to list attachments.
1217
	$listOptions = array(
1218
		'id' => 'attachments',
1219
		'width' => '100%',
1220
		'items_per_page' => $modSettings['defaultMaxListItems'],
1221
		'no_items_label' => $txt['show_attachments_none'],
1222
		'base_href' => $scripturl . '?action=profile;area=showposts;sa=attach;u=' . $memID,
1223
		'default_sort_col' => 'filename',
1224
		'get_items' => array(
1225
			'function' => 'list_getAttachments',
1226
			'params' => array(
1227
				$boardsAllowed,
1228
				$memID,
1229
			),
1230
		),
1231
		'get_count' => array(
1232
			'function' => 'list_getNumAttachments',
1233
			'params' => array(
1234
				$boardsAllowed,
1235
				$memID,
1236
			),
1237
		),
1238
		'data_check' => array(
1239
			'class' => function($data)
1240
			{
1241
				return $data['approved'] ? '' : 'approvebg';
1242
			}
1243
		),
1244
		'columns' => array(
1245
			'filename' => array(
1246
				'header' => array(
1247
					'value' => $txt['show_attach_filename'],
1248
					'class' => 'lefttext',
1249
					'style' => 'width: 25%;',
1250
				),
1251
				'data' => array(
1252
					'sprintf' => array(
1253
						'format' => '<a href="' . $scripturl . '?action=dlattach;topic=%1$d.0;attach=%2$d">%3$s</a>%4$s',
1254
						'params' => array(
1255
							'topic' => true,
1256
							'id' => true,
1257
							'filename' => false,
1258
							'awaiting_approval' => false,
1259
						),
1260
					),
1261
				),
1262
				'sort' => array(
1263
					'default' => 'a.filename',
1264
					'reverse' => 'a.filename DESC',
1265
				),
1266
			),
1267
			'downloads' => array(
1268
				'header' => array(
1269
					'value' => $txt['show_attach_downloads'],
1270
					'style' => 'width: 12%;',
1271
				),
1272
				'data' => array(
1273
					'db' => 'downloads',
1274
					'comma_format' => true,
1275
				),
1276
				'sort' => array(
1277
					'default' => 'a.downloads',
1278
					'reverse' => 'a.downloads DESC',
1279
				),
1280
			),
1281
			'subject' => array(
1282
				'header' => array(
1283
					'value' => $txt['message'],
1284
					'class' => 'lefttext',
1285
					'style' => 'width: 30%;',
1286
				),
1287
				'data' => array(
1288
					'sprintf' => array(
1289
						'format' => '<a href="' . $scripturl . '?msg=%1$d">%2$s</a>',
1290
						'params' => array(
1291
							'msg' => true,
1292
							'subject' => false,
1293
						),
1294
					),
1295
				),
1296
				'sort' => array(
1297
					'default' => 'm.subject',
1298
					'reverse' => 'm.subject DESC',
1299
				),
1300
			),
1301
			'posted' => array(
1302
				'header' => array(
1303
					'value' => $txt['show_attach_posted'],
1304
					'class' => 'lefttext',
1305
				),
1306
				'data' => array(
1307
					'db' => 'posted',
1308
					'timeformat' => true,
1309
				),
1310
				'sort' => array(
1311
					'default' => 'm.poster_time',
1312
					'reverse' => 'm.poster_time DESC',
1313
				),
1314
			),
1315
		),
1316
	);
1317
1318
	// Create the request list.
1319
	createList($listOptions);
1320
}
1321
1322
/**
1323
 * Get a list of attachments for a member. Callback for the list in showAttachments()
1324
 *
1325
 * @param int $start Which item to start with (for pagination purposes)
1326
 * @param int $items_per_page How many items to show on each page
1327
 * @param string $sort A string indicating how to sort the results
1328
 * @param array $boardsAllowed An array containing the IDs of the boards they can see
1329
 * @param int $memID The ID of the member
1330
 * @return array An array of information about the attachments
1331
 */
1332
function list_getAttachments($start, $items_per_page, $sort, $boardsAllowed, $memID)
1333
{
1334
	global $smcFunc, $board, $modSettings, $context, $txt;
1335
1336
	// Retrieve some attachments.
1337
	$request = $smcFunc['db_query']('', '
1338
		SELECT a.id_attach, a.id_msg, a.filename, a.downloads, a.approved, m.id_msg, m.id_topic,
1339
			m.id_board, m.poster_time, m.subject, b.name
1340
		FROM {db_prefix}attachments AS a
1341
			INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
1342
			INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
1343
		WHERE a.attachment_type = {int:attachment_type}
1344
			AND a.id_msg != {int:no_message}
1345
			AND m.id_member = {int:current_member}' . (!empty($board) ? '
1346
			AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? '
1347
			AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || allowedTo('approve_posts') || $context['user']['is_owner'] ? '' : '
1348
			AND a.approved = {int:is_approved}') . '
1349
		ORDER BY {raw:sort}
1350
		LIMIT {int:offset}, {int:limit}',
1351
		array(
1352
			'boards_list' => $boardsAllowed,
1353
			'attachment_type' => 0,
1354
			'no_message' => 0,
1355
			'current_member' => $memID,
1356
			'is_approved' => 1,
1357
			'board' => $board,
1358
			'sort' => $sort,
1359
			'offset' => $start,
1360
			'limit' => $items_per_page,
1361
		)
1362
	);
1363
	$attachments = array();
1364
	while ($row = $smcFunc['db_fetch_assoc']($request))
1365
		$attachments[] = array(
1366
			'id' => $row['id_attach'],
1367
			'filename' => $row['filename'],
1368
			'downloads' => $row['downloads'],
1369
			'subject' => censorText($row['subject']),
1370
			'posted' => $row['poster_time'],
1371
			'msg' => $row['id_msg'],
1372
			'topic' => $row['id_topic'],
1373
			'board' => $row['id_board'],
1374
			'board_name' => $row['name'],
1375
			'approved' => $row['approved'],
1376
			'awaiting_approval' => (empty($row['approved']) ? ' <em>(' . $txt['awaiting_approval'] . ')</em>' : ''),
1377
		);
1378
1379
	$smcFunc['db_free_result']($request);
1380
1381
	return $attachments;
1382
}
1383
1384
/**
1385
 * Gets the total number of attachments for a member
1386
 *
1387
 * @param array $boardsAllowed An array of the IDs of the boards they can see
1388
 * @param int $memID The ID of the member
1389
 * @return int The number of attachments
1390
 */
1391
function list_getNumAttachments($boardsAllowed, $memID)
1392
{
1393
	global $board, $smcFunc, $modSettings, $context;
1394
1395
	// Get the total number of attachments they have posted.
1396
	$request = $smcFunc['db_query']('', '
1397
		SELECT COUNT(*)
1398
		FROM {db_prefix}attachments AS a
1399
			INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
1400
			INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] || allowedTo('approve_posts') ? '' : '
1401
			INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)') . '
1402
		WHERE a.attachment_type = {int:attachment_type}
1403
			AND a.id_msg != {int:no_message}
1404
			AND m.id_member = {int:current_member}' . (!empty($board) ? '
1405
			AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? '
1406
			AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] || allowedTo('approve_posts') ? '' : '
1407
			AND m.approved = {int:is_approved}
1408
			AND t.approved = {int:is_approved}'),
1409
		array(
1410
			'boards_list' => $boardsAllowed,
1411
			'attachment_type' => 0,
1412
			'no_message' => 0,
1413
			'current_member' => $memID,
1414
			'is_approved' => 1,
1415
			'board' => $board,
1416
		)
1417
	);
1418
	list ($attachCount) = $smcFunc['db_fetch_row']($request);
1419
	$smcFunc['db_free_result']($request);
1420
1421
	return $attachCount;
1422
}
1423
1424
/**
1425
 * Show all the unwatched topics.
1426
 *
1427
 * @param int $memID The ID of the member
1428
 */
1429
function showUnwatched($memID)
1430
{
1431
	global $txt, $user_info, $scripturl, $modSettings, $context, $options, $sourcedir;
1432
1433
	// Only the owner can see the list (if the function is enabled of course)
1434
	if ($user_info['id'] != $memID)
1435
		return;
1436
1437
	require_once($sourcedir . '/Subs-List.php');
1438
1439
	// And here they are: the topics you don't like
1440
	$listOptions = array(
1441
		'id' => 'unwatched_topics',
1442
		'width' => '100%',
1443
		'items_per_page' => (empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page'])) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'],
1444
		'no_items_label' => $txt['unwatched_topics_none'],
1445
		'base_href' => $scripturl . '?action=profile;area=showposts;sa=unwatchedtopics;u=' . $memID,
1446
		'default_sort_col' => 'started_on',
1447
		'get_items' => array(
1448
			'function' => 'list_getUnwatched',
1449
			'params' => array(
1450
				$memID,
1451
			),
1452
		),
1453
		'get_count' => array(
1454
			'function' => 'list_getNumUnwatched',
1455
			'params' => array(
1456
				$memID,
1457
			),
1458
		),
1459
		'columns' => array(
1460
			'subject' => array(
1461
				'header' => array(
1462
					'value' => $txt['subject'],
1463
					'class' => 'lefttext',
1464
					'style' => 'width: 30%;',
1465
				),
1466
				'data' => array(
1467
					'sprintf' => array(
1468
						'format' => '<a href="' . $scripturl . '?topic=%1$d.0">%2$s</a>',
1469
						'params' => array(
1470
							'id_topic' => false,
1471
							'subject' => false,
1472
						),
1473
					),
1474
				),
1475
				'sort' => array(
1476
					'default' => 'm.subject',
1477
					'reverse' => 'm.subject DESC',
1478
				),
1479
			),
1480
			'started_by' => array(
1481
				'header' => array(
1482
					'value' => $txt['started_by'],
1483
					'style' => 'width: 15%;',
1484
				),
1485
				'data' => array(
1486
					'db' => 'started_by',
1487
				),
1488
				'sort' => array(
1489
					'default' => 'mem.real_name',
1490
					'reverse' => 'mem.real_name DESC',
1491
				),
1492
			),
1493
			'started_on' => array(
1494
				'header' => array(
1495
					'value' => $txt['on'],
1496
					'class' => 'lefttext',
1497
					'style' => 'width: 20%;',
1498
				),
1499
				'data' => array(
1500
					'db' => 'started_on',
1501
					'timeformat' => true,
1502
				),
1503
				'sort' => array(
1504
					'default' => 'm.poster_time',
1505
					'reverse' => 'm.poster_time DESC',
1506
				),
1507
			),
1508
			'last_post_by' => array(
1509
				'header' => array(
1510
					'value' => $txt['last_post'],
1511
					'style' => 'width: 15%;',
1512
				),
1513
				'data' => array(
1514
					'db' => 'last_post_by',
1515
				),
1516
				'sort' => array(
1517
					'default' => 'mem.real_name',
1518
					'reverse' => 'mem.real_name DESC',
1519
				),
1520
			),
1521
			'last_post_on' => array(
1522
				'header' => array(
1523
					'value' => $txt['on'],
1524
					'class' => 'lefttext',
1525
					'style' => 'width: 20%;',
1526
				),
1527
				'data' => array(
1528
					'db' => 'last_post_on',
1529
					'timeformat' => true,
1530
				),
1531
				'sort' => array(
1532
					'default' => 'm.poster_time',
1533
					'reverse' => 'm.poster_time DESC',
1534
				),
1535
			),
1536
		),
1537
	);
1538
1539
	// Create the request list.
1540
	createList($listOptions);
1541
1542
	$context['sub_template'] = 'show_list';
1543
	$context['default_list'] = 'unwatched_topics';
1544
}
1545
1546
/**
1547
 * Gets information about unwatched (disregarded) topics. Callback for the list in show_unwatched
1548
 *
1549
 * @param int $start The item to start with (for pagination purposes)
1550
 * @param int $items_per_page How many items to show on each page
1551
 * @param string $sort A string indicating how to sort the results
1552
 * @param int $memID The ID of the member
1553
 * @return array An array of information about the unwatched topics
1554
 */
1555
function list_getUnwatched($start, $items_per_page, $sort, $memID)
1556
{
1557
	global $smcFunc;
1558
1559
	// Get the list of topics we can see
1560
	$request = $smcFunc['db_query']('', '
1561
		SELECT lt.id_topic
1562
		FROM {db_prefix}log_topics as lt
1563
			LEFT JOIN {db_prefix}topics as t ON (lt.id_topic = t.id_topic)
1564
			LEFT JOIN {db_prefix}messages as m ON (t.id_first_msg = m.id_msg)' . (in_array($sort, array('mem.real_name', 'mem.real_name DESC', 'mem.poster_time', 'mem.poster_time DESC')) ? '
1565
			LEFT JOIN {db_prefix}members as mem ON (m.id_member = mem.id_member)' : '') . '
1566
		WHERE lt.id_member = {int:current_member}
1567
			AND unwatched = 1
1568
			AND {query_see_message_board}
1569
		ORDER BY {raw:sort}
1570
		LIMIT {int:offset}, {int:limit}',
1571
		array(
1572
			'current_member' => $memID,
1573
			'sort' => $sort,
1574
			'offset' => $start,
1575
			'limit' => $items_per_page,
1576
		)
1577
	);
1578
1579
	$topics = array();
1580
	while ($row = $smcFunc['db_fetch_assoc']($request))
1581
		$topics[] = $row['id_topic'];
1582
1583
	$smcFunc['db_free_result']($request);
1584
1585
	// Any topics found?
1586
	$topicsInfo = array();
1587
	if (!empty($topics))
1588
	{
1589
		$request = $smcFunc['db_query']('', '
1590
			SELECT mf.subject, mf.poster_time as started_on, COALESCE(memf.real_name, mf.poster_name) as started_by, ml.poster_time as last_post_on, COALESCE(meml.real_name, ml.poster_name) as last_post_by, t.id_topic
1591
			FROM {db_prefix}topics AS t
1592
				INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
1593
				INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)
1594
				LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)
1595
				LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member)
1596
			WHERE t.id_topic IN ({array_int:topics})',
1597
			array(
1598
				'topics' => $topics,
1599
			)
1600
		);
1601
		while ($row = $smcFunc['db_fetch_assoc']($request))
1602
			$topicsInfo[] = $row;
1603
		$smcFunc['db_free_result']($request);
1604
	}
1605
1606
	return $topicsInfo;
1607
}
1608
1609
/**
1610
 * Count the number of topics in the unwatched list
1611
 *
1612
 * @param int $memID The ID of the member
1613
 * @return int The number of unwatched topics
1614
 */
1615
function list_getNumUnwatched($memID)
1616
{
1617
	global $smcFunc;
1618
1619
	// Get the total number of attachments they have posted.
1620
	$request = $smcFunc['db_query']('', '
1621
		SELECT COUNT(*)
1622
		FROM {db_prefix}log_topics as lt
1623
		LEFT JOIN {db_prefix}topics as t ON (lt.id_topic = t.id_topic)
1624
		WHERE lt.id_member = {int:current_member}
1625
			AND lt.unwatched = 1
1626
			AND {query_see_topic_board}',
1627
		array(
1628
			'current_member' => $memID,
1629
		)
1630
	);
1631
	list ($unwatchedCount) = $smcFunc['db_fetch_row']($request);
1632
	$smcFunc['db_free_result']($request);
1633
1634
	return $unwatchedCount;
1635
}
1636
1637
/**
1638
 * Gets the user stats for display
1639
 *
1640
 * @param int $memID The ID of the member
1641
 */
1642
function statPanel($memID)
1643
{
1644
	global $txt, $scripturl, $context, $user_profile, $user_info, $modSettings, $smcFunc;
1645
1646
	$context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name'];
1647
1648
	// Is the load average too high to allow searching just now?
1649
	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats'])
1650
		fatal_lang_error('loadavg_userstats_disabled', false);
1651
1652
	// General user statistics.
1653
	$timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400);
1654
	$timeHours = floor(($user_profile[$memID]['total_time_logged_in'] % 86400) / 3600);
1655
	$context['time_logged_in'] = ($timeDays > 0 ? $timeDays . $txt['total_time_logged_days'] : '') . ($timeHours > 0 ? $timeHours . $txt['total_time_logged_hours'] : '') . floor(($user_profile[$memID]['total_time_logged_in'] % 3600) / 60) . $txt['total_time_logged_minutes'];
1656
	$context['num_posts'] = comma_format($user_profile[$memID]['posts']);
1657
	// Menu tab
1658
	$context[$context['profile_menu_name']]['tab_data'] = array(
1659
		'title' => $txt['statPanel_generalStats'] . ' - ' . $context['member']['name'],
1660
		'icon' => 'stats_info.png'
1661
	);
1662
1663
	// Number of topics started and Number polls started
1664
	$result = $smcFunc['db_query']('', '
1665
		SELECT COUNT(*), COUNT( CASE WHEN id_poll != {int:no_poll} THEN 1 ELSE NULL END )
1666
		FROM {db_prefix}topics
1667
		WHERE id_member_started = {int:current_member}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
1668
			AND id_board != {int:recycle_board}' : ''),
1669
		array(
1670
			'current_member' => $memID,
1671
			'recycle_board' => $modSettings['recycle_board'],
1672
			'no_poll' => 0,
1673
		)
1674
	);
1675
	list ($context['num_topics'], $context['num_polls']) = $smcFunc['db_fetch_row']($result);
1676
	$smcFunc['db_free_result']($result);
1677
1678
	// Number polls voted in.
1679
	$result = $smcFunc['db_query']('distinct_poll_votes', '
1680
		SELECT COUNT(DISTINCT id_poll)
1681
		FROM {db_prefix}log_polls
1682
		WHERE id_member = {int:current_member}',
1683
		array(
1684
			'current_member' => $memID,
1685
		)
1686
	);
1687
	list ($context['num_votes']) = $smcFunc['db_fetch_row']($result);
1688
	$smcFunc['db_free_result']($result);
1689
1690
	// Format the numbers...
1691
	$context['num_topics'] = comma_format($context['num_topics']);
1692
	$context['num_polls'] = comma_format($context['num_polls']);
1693
	$context['num_votes'] = comma_format($context['num_votes']);
1694
1695
	// Grab the board this member posted in most often.
1696
	$result = $smcFunc['db_query']('', '
1697
		SELECT
1698
			b.id_board, MAX(b.name) AS name, MAX(b.num_posts) AS num_posts, COUNT(*) AS message_count
1699
		FROM {db_prefix}messages AS m
1700
			INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
1701
		WHERE m.id_member = {int:current_member}
1702
			AND b.count_posts = {int:count_enabled}
1703
			AND {query_see_board}
1704
		GROUP BY b.id_board
1705
		ORDER BY message_count DESC
1706
		LIMIT 10',
1707
		array(
1708
			'current_member' => $memID,
1709
			'count_enabled' => 0,
1710
		)
1711
	);
1712
	$context['popular_boards'] = array();
1713
	while ($row = $smcFunc['db_fetch_assoc']($result))
1714
	{
1715
		$context['popular_boards'][$row['id_board']] = array(
1716
			'id' => $row['id_board'],
1717
			'posts' => $row['message_count'],
1718
			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
1719
			'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
1720
			'posts_percent' => $user_profile[$memID]['posts'] == 0 ? 0 : ($row['message_count'] * 100) / $user_profile[$memID]['posts'],
1721
			'total_posts' => $row['num_posts'],
1722
			'total_posts_member' => $user_profile[$memID]['posts'],
1723
		);
1724
	}
1725
	$smcFunc['db_free_result']($result);
1726
1727
	// Now get the 10 boards this user has most often participated in.
1728
	$result = $smcFunc['db_query']('profile_board_stats', '
1729
		SELECT
1730
			b.id_board, MAX(b.name) AS name, b.num_posts, COUNT(*) AS message_count,
1731
			CASE WHEN COUNT(*) > MAX(b.num_posts) THEN 1 ELSE COUNT(*) / MAX(b.num_posts) END * 100 AS percentage
1732
		FROM {db_prefix}messages AS m
1733
			INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
1734
		WHERE m.id_member = {int:current_member}
1735
			AND {query_see_board}
1736
		GROUP BY b.id_board, b.num_posts
1737
		ORDER BY percentage DESC
1738
		LIMIT 10',
1739
		array(
1740
			'current_member' => $memID,
1741
		)
1742
	);
1743
	$context['board_activity'] = array();
1744
	while ($row = $smcFunc['db_fetch_assoc']($result))
1745
	{
1746
		$context['board_activity'][$row['id_board']] = array(
1747
			'id' => $row['id_board'],
1748
			'posts' => $row['message_count'],
1749
			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
1750
			'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
1751
			'percent' => comma_format((float) $row['percentage'], 2),
1752
			'posts_percent' => (float) $row['percentage'],
1753
			'total_posts' => $row['num_posts'],
1754
		);
1755
	}
1756
	$smcFunc['db_free_result']($result);
1757
1758
	// Posting activity by time.
1759
	$result = $smcFunc['db_query']('user_activity_by_time', '
1760
		SELECT
1761
			HOUR(FROM_UNIXTIME(poster_time + {int:time_offset})) AS hour,
1762
			COUNT(*) AS post_count
1763
		FROM (
1764
			SELECT poster_time, id_msg
1765
			FROM {db_prefix}messages WHERE id_member = {int:current_member}
1766
			ORDER BY id_msg DESC
1767
			LIMIT {int:max_messages}
1768
		) a
1769
		GROUP BY hour',
1770
		array(
1771
			'current_member' => $memID,
1772
			'time_offset' => (($user_info['time_offset'] + $modSettings['time_offset']) * 3600),
1773
			'max_messages' => 1001,
1774
		)
1775
	);
1776
	$maxPosts = $realPosts = 0;
1777
	$context['posts_by_time'] = array();
1778
	while ($row = $smcFunc['db_fetch_assoc']($result))
1779
	{
1780
		// Cast as an integer to remove the leading 0.
1781
		$row['hour'] = (int) $row['hour'];
1782
1783
		$maxPosts = max($row['post_count'], $maxPosts);
1784
		$realPosts += $row['post_count'];
1785
1786
		$context['posts_by_time'][$row['hour']] = array(
1787
			'hour' => $row['hour'],
1788
			'hour_format' => stripos($user_info['time_format'], '%p') === false ? $row['hour'] : date('g a', mktime($row['hour'])),
1789
			'posts' => $row['post_count'],
1790
			'posts_percent' => 0,
1791
			'is_last' => $row['hour'] == 23,
1792
		);
1793
	}
1794
	$smcFunc['db_free_result']($result);
1795
1796
	if ($maxPosts > 0)
1797
		for ($hour = 0; $hour < 24; $hour++)
1798
		{
1799
			if (!isset($context['posts_by_time'][$hour]))
1800
				$context['posts_by_time'][$hour] = array(
1801
					'hour' => $hour,
1802
					'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
1803
					'posts' => 0,
1804
					'posts_percent' => 0,
1805
					'relative_percent' => 0,
1806
					'is_last' => $hour == 23,
1807
				);
1808
			else
1809
			{
1810
				$context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts);
1811
				$context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts);
1812
			}
1813
		}
1814
1815
	// Put it in the right order.
1816
	ksort($context['posts_by_time']);
1817
1818
	/**
1819
	 * Adding new entries:
1820
	 * 'key' => array(
1821
	 * 		'text' => string, // The text that will be shown next to the entry.
1822
	 * 		'url' => string, // OPTIONAL: The entry will be a url
1823
	 * ),
1824
	 *
1825
	 * 'key' will be used to look up the language string as $txt['statPanel_' . $key].
1826
	 * Make sure to add a new entry when writing your mod!
1827
	 */
1828
	$context['text_stats'] = array(
1829
		'total_time_online' => array(
1830
			'text' => $context['time_logged_in'],
1831
		),
1832
		'total_posts' => array(
1833
			'text' => $context['num_posts'] . ' ' . $txt['statPanel_posts'],
1834
			'url' => $scripturl . '?action=profile;area=showposts;sa=messages;u=' . $memID
1835
		),
1836
		'total_topics' => array(
1837
			'text' => $context['num_topics'] . ' ' . $txt['statPanel_topics'],
1838
			'url' => $scripturl . '?action=profile;area=showposts;sa=topics;u=' . $memID
1839
		),
1840
		'users_polls' => array(
1841
			'text' => $context['num_polls'] . ' ' . $txt['statPanel_polls'],
1842
		),
1843
		'users_votes' => array(
1844
			'text' => $context['num_votes'] . ' ' . $txt['statPanel_votes']
1845
		)
1846
	);
1847
1848
	// Custom stats (just add a template_layer to add it to the template!)
1849
	call_integration_hook('integrate_profile_stats', array($memID, &$context['text_stats']));
1850
}
1851
1852
/**
1853
 * Loads up the information for the "track user" section of the profile
1854
 *
1855
 * @param int $memID The ID of the member
1856
 */
1857
function tracking($memID)
1858
{
1859
	global $context, $txt, $modSettings, $user_profile;
1860
1861
	$subActions = array(
1862
		'activity' => array('trackActivity', $txt['trackActivity'], 'moderate_forum'),
1863
		'ip' => array('TrackIP', $txt['trackIP'], 'moderate_forum'),
1864
		'edits' => array('trackEdits', $txt['trackEdits'], 'moderate_forum'),
1865
		'groupreq' => array('trackGroupReq', $txt['trackGroupRequests'], 'approve_group_requests'),
1866
		'logins' => array('TrackLogins', $txt['trackLogins'], 'moderate_forum'),
1867
	);
1868
1869
	foreach ($subActions as $sa => $action)
1870
	{
1871
		if (!allowedTo($action[2]))
1872
			unset($subActions[$sa]);
1873
	}
1874
1875
	// Create the tabs for the template.
1876
	$context[$context['profile_menu_name']]['tab_data'] = array(
1877
		'title' => $txt['tracking'],
1878
		'description' => $txt['tracking_description'],
1879
		'icon' => 'profile_hd.png',
1880
		'tabs' => array(
1881
			'activity' => array(),
1882
			'ip' => array(),
1883
			'edits' => array(),
1884
			'groupreq' => array(),
1885
			'logins' => array(),
1886
		),
1887
	);
1888
1889
	// Moderation must be on to track edits.
1890
	if (empty($modSettings['userlog_enabled']))
1891
		unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1892
1893
	// Group requests must be active to show it...
1894
	if (empty($modSettings['show_group_membership']))
1895
		unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1896
1897
	if (empty($subActions))
1898
		fatal_lang_error('no_access', false);
1899
1900
	$keys = array_keys($subActions);
1901
	$default = array_shift($keys);
1902
	$context['tracking_area'] = isset($_GET['sa']) && isset($subActions[$_GET['sa']]) ? $_GET['sa'] : $default;
1903
1904
	// Set a page title.
1905
	$context['page_title'] = $txt['trackUser'] . ' - ' . $subActions[$context['tracking_area']][1] . ' - ' . $user_profile[$memID]['real_name'];
1906
1907
	// Pass on to the actual function.
1908
	$context['sub_template'] = $subActions[$context['tracking_area']][0];
1909
	$call = call_helper($subActions[$context['tracking_area']][0], true);
1910
1911
	if (!empty($call))
1912
		call_user_func($call, $memID);
0 ignored issues
show
Bug introduced by
It seems like $call can also be of type boolean; however, parameter $callback of call_user_func() does only seem to accept callable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1912
		call_user_func(/** @scrutinizer ignore-type */ $call, $memID);
Loading history...
1913
}
1914
1915
/**
1916
 * Handles tracking a user's activity
1917
 *
1918
 * @param int $memID The ID of the member
1919
 */
1920
function trackActivity($memID)
1921
{
1922
	global $scripturl, $txt, $modSettings, $sourcedir;
1923
	global $user_profile, $context, $smcFunc;
1924
1925
	// Verify if the user has sufficient permissions.
1926
	isAllowedTo('moderate_forum');
1927
1928
	$context['last_ip'] = $user_profile[$memID]['member_ip'];
1929
	if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
1930
		$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1931
	$context['member']['name'] = $user_profile[$memID]['real_name'];
1932
1933
	// Set the options for the list component.
1934
	$listOptions = array(
1935
		'id' => 'track_user_list',
1936
		'title' => $txt['errors_by'] . ' ' . $context['member']['name'],
1937
		'items_per_page' => $modSettings['defaultMaxListItems'],
1938
		'no_items_label' => $txt['no_errors_from_user'],
1939
		'base_href' => $scripturl . '?action=profile;area=tracking;sa=user;u=' . $memID,
1940
		'default_sort_col' => 'date',
1941
		'get_items' => array(
1942
			'function' => 'list_getUserErrors',
1943
			'params' => array(
1944
				'le.id_member = {int:current_member}',
1945
				array('current_member' => $memID),
1946
			),
1947
		),
1948
		'get_count' => array(
1949
			'function' => 'list_getUserErrorCount',
1950
			'params' => array(
1951
				'id_member = {int:current_member}',
1952
				array('current_member' => $memID),
1953
			),
1954
		),
1955
		'columns' => array(
1956
			'ip_address' => array(
1957
				'header' => array(
1958
					'value' => $txt['ip_address'],
1959
				),
1960
				'data' => array(
1961
					'sprintf' => array(
1962
						'format' => '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=%1$s;u=' . $memID . '">%1$s</a>',
1963
						'params' => array(
1964
							'ip' => false,
1965
						),
1966
					),
1967
				),
1968
				'sort' => array(
1969
					'default' => 'le.ip',
1970
					'reverse' => 'le.ip DESC',
1971
				),
1972
			),
1973
			'message' => array(
1974
				'header' => array(
1975
					'value' => $txt['message'],
1976
				),
1977
				'data' => array(
1978
					'sprintf' => array(
1979
						'format' => '%1$s<br><a href="%2$s">%2$s</a>',
1980
						'params' => array(
1981
							'message' => false,
1982
							'url' => false,
1983
						),
1984
					),
1985
				),
1986
			),
1987
			'date' => array(
1988
				'header' => array(
1989
					'value' => $txt['date'],
1990
				),
1991
				'data' => array(
1992
					'db' => 'time',
1993
				),
1994
				'sort' => array(
1995
					'default' => 'le.id_error DESC',
1996
					'reverse' => 'le.id_error',
1997
				),
1998
			),
1999
		),
2000
		'additional_rows' => array(
2001
			array(
2002
				'position' => 'after_title',
2003
				'value' => $txt['errors_desc'],
2004
			),
2005
		),
2006
	);
2007
2008
	// Create the list for viewing.
2009
	require_once($sourcedir . '/Subs-List.php');
2010
	createList($listOptions);
2011
2012
	// @todo cache this
2013
	// If this is a big forum, or a large posting user, let's limit the search.
2014
	if ($modSettings['totalMessages'] > 50000 && $user_profile[$memID]['posts'] > 500)
2015
	{
2016
		$request = $smcFunc['db_query']('', '
2017
			SELECT MAX(id_msg)
2018
			FROM {db_prefix}messages AS m
2019
			WHERE m.id_member = {int:current_member}',
2020
			array(
2021
				'current_member' => $memID,
2022
			)
2023
		);
2024
		list ($max_msg_member) = $smcFunc['db_fetch_row']($request);
2025
		$smcFunc['db_free_result']($request);
2026
2027
		// There's no point worrying ourselves with messages made yonks ago, just get recent ones!
2028
		$min_msg_member = max(0, $max_msg_member - $user_profile[$memID]['posts'] * 3);
2029
	}
2030
2031
	// Default to at least the ones we know about.
2032
	$ips = array(
2033
		$user_profile[$memID]['member_ip'],
2034
		$user_profile[$memID]['member_ip2'],
2035
	);
2036
2037
	// @todo cache this
2038
	// Get all IP addresses this user has used for his messages.
2039
	$request = $smcFunc['db_query']('', '
2040
		SELECT poster_ip
2041
		FROM {db_prefix}messages
2042
		WHERE id_member = {int:current_member}
2043
		' . (isset($min_msg_member) ? '
2044
			AND id_msg >= {int:min_msg_member} AND id_msg <= {int:max_msg_member}' : '') . '
2045
		GROUP BY poster_ip',
2046
		array(
2047
			'current_member' => $memID,
2048
			'min_msg_member' => !empty($min_msg_member) ? $min_msg_member : 0,
2049
			'max_msg_member' => !empty($max_msg_member) ? $max_msg_member : 0,
2050
		)
2051
	);
2052
	$context['ips'] = array();
2053
	while ($row = $smcFunc['db_fetch_assoc']($request))
2054
	{
2055
		$context['ips'][] = '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=' . inet_dtop($row['poster_ip']) . ';u=' . $memID . '">' . inet_dtop($row['poster_ip']) . '</a>';
2056
		$ips[] = inet_dtop($row['poster_ip']);
2057
	}
2058
	$smcFunc['db_free_result']($request);
2059
2060
	// Now also get the IP addresses from the error messages.
2061
	$request = $smcFunc['db_query']('', '
2062
		SELECT COUNT(*) AS error_count, ip
2063
		FROM {db_prefix}log_errors
2064
		WHERE id_member = {int:current_member}
2065
		GROUP BY ip',
2066
		array(
2067
			'current_member' => $memID,
2068
		)
2069
	);
2070
	$context['error_ips'] = array();
2071
	while ($row = $smcFunc['db_fetch_assoc']($request))
2072
	{
2073
		$row['ip'] = inet_dtop($row['ip']);
2074
		$context['error_ips'][] = '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=' . $row['ip'] . ';u=' . $memID . '">' . $row['ip'] . '</a>';
2075
		$ips[] = $row['ip'];
2076
	}
2077
	$smcFunc['db_free_result']($request);
2078
2079
	// Find other users that might use the same IP.
2080
	$ips = array_unique($ips);
2081
	$context['members_in_range'] = array();
2082
	if (!empty($ips))
2083
	{
2084
		// Get member ID's which are in messages...
2085
		$request = $smcFunc['db_query']('', '
2086
			SELECT DISTINCT mem.id_member
2087
			FROM {db_prefix}messages AS m
2088
				INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
2089
			WHERE m.poster_ip IN ({array_inet:ip_list})
2090
				AND mem.id_member != {int:current_member}',
2091
			array(
2092
				'current_member' => $memID,
2093
				'ip_list' => $ips,
2094
			)
2095
		);
2096
		$message_members = array();
2097
		while ($row = $smcFunc['db_fetch_assoc']($request))
2098
			$message_members[] = $row['id_member'];
2099
		$smcFunc['db_free_result']($request);
2100
2101
		// Fetch their names, cause of the GROUP BY doesn't like giving us that normally.
2102
		if (!empty($message_members))
2103
		{
2104
			$request = $smcFunc['db_query']('', '
2105
				SELECT id_member, real_name
2106
				FROM {db_prefix}members
2107
				WHERE id_member IN ({array_int:message_members})',
2108
				array(
2109
					'message_members' => $message_members,
2110
					'ip_list' => $ips,
2111
				)
2112
			);
2113
			while ($row = $smcFunc['db_fetch_assoc']($request))
2114
				$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
2115
			$smcFunc['db_free_result']($request);
2116
		}
2117
2118
		$request = $smcFunc['db_query']('', '
2119
			SELECT id_member, real_name
2120
			FROM {db_prefix}members
2121
			WHERE id_member != {int:current_member}
2122
				AND member_ip IN ({array_inet:ip_list})',
2123
			array(
2124
				'current_member' => $memID,
2125
				'ip_list' => $ips,
2126
			)
2127
		);
2128
		while ($row = $smcFunc['db_fetch_assoc']($request))
2129
			$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
2130
		$smcFunc['db_free_result']($request);
2131
	}
2132
}
2133
2134
/**
2135
 * Get the number of user errors
2136
 *
2137
 * @param string $where A query to limit which errors are counted
2138
 * @param array $where_vars The parameters for $where
2139
 * @return int Number of user errors
2140
 */
2141
function list_getUserErrorCount($where, $where_vars = array())
2142
{
2143
	global $smcFunc;
2144
2145
	$request = $smcFunc['db_query']('', '
2146
		SELECT COUNT(*)
2147
		FROM {db_prefix}log_errors
2148
		WHERE ' . $where,
2149
		$where_vars
2150
	);
2151
	list ($count) = $smcFunc['db_fetch_row']($request);
2152
	$smcFunc['db_free_result']($request);
2153
2154
	return (int) $count;
2155
}
2156
2157
/**
2158
 * Gets all of the errors generated by a user's actions. Callback for the list in track_activity
2159
 *
2160
 * @param int $start Which item to start with (for pagination purposes)
2161
 * @param int $items_per_page How many items to show on each page
2162
 * @param string $sort A string indicating how to sort the results
2163
 * @param string $where A query indicating how to filter the results (eg 'id_member={int:id_member}')
2164
 * @param array $where_vars An array of parameters for $where
2165
 * @return array An array of information about the error messages
2166
 */
2167
function list_getUserErrors($start, $items_per_page, $sort, $where, $where_vars = array())
2168
{
2169
	global $smcFunc, $txt, $scripturl;
2170
2171
	// Get a list of error messages from this ip (range).
2172
	$request = $smcFunc['db_query']('', '
2173
		SELECT
2174
			le.log_time, le.ip, le.url, le.message, COALESCE(mem.id_member, 0) AS id_member,
2175
			COALESCE(mem.real_name, {string:guest_title}) AS display_name, mem.member_name
2176
		FROM {db_prefix}log_errors AS le
2177
			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = le.id_member)
2178
		WHERE ' . $where . '
2179
		ORDER BY {raw:sort}
2180
		LIMIT {int:start}, {int:max}',
2181
		array_merge($where_vars, array(
2182
			'guest_title' => $txt['guest_title'],
2183
			'sort' => $sort,
2184
			'start' => $start,
2185
			'max' => $items_per_page,
2186
		))
2187
	);
2188
	$error_messages = array();
2189
	while ($row = $smcFunc['db_fetch_assoc']($request))
2190
		$error_messages[] = array(
2191
			'ip' => inet_dtop($row['ip']),
2192
			'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
2193
			'message' => strtr($row['message'], array('&lt;span class=&quot;remove&quot;&gt;' => '', '&lt;/span&gt;' => '')),
2194
			'url' => $row['url'],
2195
			'time' => timeformat($row['log_time']),
2196
			'timestamp' => forum_time(true, $row['log_time']),
2197
		);
2198
	$smcFunc['db_free_result']($request);
2199
2200
	return $error_messages;
2201
}
2202
2203
/**
2204
 * Gets the number of posts made from a particular IP
2205
 *
2206
 * @param string $where A query indicating which posts to count
2207
 * @param array $where_vars The parameters for $where
2208
 * @return int Count of messages matching the IP
2209
 */
2210
function list_getIPMessageCount($where, $where_vars = array())
2211
{
2212
	global $smcFunc, $user_info;
2213
2214
	$request = $smcFunc['db_query']('', '
2215
		SELECT COUNT(*)
2216
		FROM {db_prefix}messages AS m
2217
		WHERE {query_see_message_board} AND ' . $where,
2218
		$where_vars
2219
	);
2220
	list ($count) = $smcFunc['db_fetch_row']($request);
2221
	$smcFunc['db_free_result']($request);
2222
2223
	return (int) $count;
2224
}
2225
2226
/**
2227
 * Gets all the posts made from a particular IP
2228
 *
2229
 * @param int $start Which item to start with (for pagination purposes)
2230
 * @param int $items_per_page How many items to show on each page
2231
 * @param string $sort A string indicating how to sort the results
2232
 * @param string $where A query to filter which posts are returned
2233
 * @param array $where_vars An array of parameters for $where
2234
 * @return array An array containing information about the posts
2235
 */
2236
function list_getIPMessages($start, $items_per_page, $sort, $where, $where_vars = array())
2237
{
2238
	global $smcFunc, $scripturl, $user_info;
2239
2240
	// Get all the messages fitting this where clause.
2241
	$request = $smcFunc['db_query']('', '
2242
		SELECT
2243
			m.id_msg, m.poster_ip, COALESCE(mem.real_name, m.poster_name) AS display_name, mem.id_member,
2244
			m.subject, m.poster_time, m.id_topic, m.id_board
2245
		FROM {db_prefix}messages AS m
2246
			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
2247
		WHERE {query_see_message_board} AND ' . $where . '
2248
		ORDER BY {raw:sort}
2249
		LIMIT {int:start}, {int:max}',
2250
		array_merge($where_vars, array(
2251
			'sort' => $sort,
2252
			'start' => $start,
2253
			'max' => $items_per_page,
2254
		))
2255
	);
2256
	$messages = array();
2257
	while ($row = $smcFunc['db_fetch_assoc']($request))
2258
		$messages[] = array(
2259
			'ip' => inet_dtop($row['poster_ip']),
2260
			'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
2261
			'board' => array(
2262
				'id' => $row['id_board'],
2263
				'href' => $scripturl . '?board=' . $row['id_board']
2264
			),
2265
			'topic' => $row['id_topic'],
2266
			'id' => $row['id_msg'],
2267
			'subject' => $row['subject'],
2268
			'time' => timeformat($row['poster_time']),
2269
			'timestamp' => forum_time(true, $row['poster_time'])
2270
		);
2271
	$smcFunc['db_free_result']($request);
2272
2273
	return $messages;
2274
}
2275
2276
/**
2277
 * Handles tracking a particular IP address
2278
 *
2279
 * @param int $memID The ID of a member whose IP we want to track
2280
 */
2281
function TrackIP($memID = 0)
2282
{
2283
	global $user_profile, $scripturl, $txt, $user_info, $modSettings, $sourcedir;
2284
	global $context, $options, $smcFunc;
2285
2286
	// Can the user do this?
2287
	isAllowedTo('moderate_forum');
2288
2289
	if ($memID == 0)
2290
	{
2291
		$context['ip'] = ip2range($user_info['ip']);
2292
		loadTemplate('Profile');
2293
		loadLanguage('Profile');
2294
		$context['sub_template'] = 'trackIP';
2295
		$context['page_title'] = $txt['profile'];
2296
		$context['base_url'] = $scripturl . '?action=trackip';
2297
	}
2298
	else
2299
	{
2300
		$context['ip'] = ip2range($user_profile[$memID]['member_ip']);
2301
		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2302
	}
2303
2304
	// Searching?
2305
	if (isset($_REQUEST['searchip']))
2306
		$context['ip'] = ip2range(trim($_REQUEST['searchip']));
2307
2308
	if (count($context['ip']) !== 2)
2309
		fatal_lang_error('invalid_tracking_ip', false);
2310
2311
	$ip_string = array('{inet:ip_address_low}', '{inet:ip_address_high}');
2312
	$fields = array(
2313
		'ip_address_low' => $context['ip']['low'],
2314
		'ip_address_high' => $context['ip']['high'],
2315
	);
2316
2317
	$ip_var = $context['ip'];
2318
2319
	if ($context['ip']['low'] !== $context['ip']['high'])
2320
		$context['ip'] = $context['ip']['low'] . ' - ' . $context['ip']['high'];
2321
	else
2322
		$context['ip'] = $context['ip']['low'];
2323
2324
	if (empty($context['tracking_area']))
2325
		$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
2326
2327
	$request = $smcFunc['db_query']('', '
2328
		SELECT id_member, real_name AS display_name, member_ip
2329
		FROM {db_prefix}members
2330
		WHERE member_ip >= ' . $ip_string[0] . ' and member_ip <= ' . $ip_string[1],
2331
		$fields
2332
	);
2333
	$context['ips'] = array();
2334
	while ($row = $smcFunc['db_fetch_assoc']($request))
2335
		$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
2336
	$smcFunc['db_free_result']($request);
2337
2338
	ksort($context['ips']);
2339
2340
	// For messages we use the "messages per page" option
2341
	$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
2342
2343
	// Gonna want this for the list.
2344
	require_once($sourcedir . '/Subs-List.php');
2345
2346
	// Start with the user messages.
2347
	$listOptions = array(
2348
		'id' => 'track_message_list',
2349
		'title' => $txt['messages_from_ip'] . ' ' . $context['ip'],
2350
		'start_var_name' => 'messageStart',
2351
		'items_per_page' => $maxPerPage,
2352
		'no_items_label' => $txt['no_messages_from_ip'],
2353
		'base_href' => $context['base_url'] . ';searchip=' . $context['ip'],
2354
		'default_sort_col' => 'date',
2355
		'get_items' => array(
2356
			'function' => 'list_getIPMessages',
2357
			'params' => array(
2358
				'm.poster_ip >= ' . $ip_string[0] . ' and m.poster_ip <= ' . $ip_string[1],
2359
				$fields,
2360
			),
2361
		),
2362
		'get_count' => array(
2363
			'function' => 'list_getIPMessageCount',
2364
			'params' => array(
2365
				'm.poster_ip >= ' . $ip_string[0] . ' and m.poster_ip <= ' . $ip_string[1],
2366
				$fields,
2367
			),
2368
		),
2369
		'columns' => array(
2370
			'ip_address' => array(
2371
				'header' => array(
2372
					'value' => $txt['ip_address'],
2373
				),
2374
				'data' => array(
2375
					'sprintf' => array(
2376
						'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a>',
2377
						'params' => array(
2378
							'ip' => false,
2379
						),
2380
					),
2381
				),
2382
				'sort' => array(
2383
					'default' => 'm.poster_ip',
2384
					'reverse' => 'm.poster_ip DESC',
2385
				),
2386
			),
2387
			'poster' => array(
2388
				'header' => array(
2389
					'value' => $txt['poster'],
2390
				),
2391
				'data' => array(
2392
					'db' => 'member_link',
2393
				),
2394
			),
2395
			'subject' => array(
2396
				'header' => array(
2397
					'value' => $txt['subject'],
2398
				),
2399
				'data' => array(
2400
					'sprintf' => array(
2401
						'format' => '<a href="' . $scripturl . '?topic=%1$s.msg%2$s#msg%2$s" rel="nofollow">%3$s</a>',
2402
						'params' => array(
2403
							'topic' => false,
2404
							'id' => false,
2405
							'subject' => false,
2406
						),
2407
					),
2408
				),
2409
			),
2410
			'date' => array(
2411
				'header' => array(
2412
					'value' => $txt['date'],
2413
				),
2414
				'data' => array(
2415
					'db' => 'time',
2416
				),
2417
				'sort' => array(
2418
					'default' => 'm.id_msg DESC',
2419
					'reverse' => 'm.id_msg',
2420
				),
2421
			),
2422
		),
2423
		'additional_rows' => array(
2424
			array(
2425
				'position' => 'after_title',
2426
				'value' => $txt['messages_from_ip_desc'],
2427
			),
2428
		),
2429
	);
2430
2431
	// Create the messages list.
2432
	createList($listOptions);
2433
2434
	// Set the options for the error lists.
2435
	$listOptions = array(
2436
		'id' => 'track_user_list',
2437
		'title' => $txt['errors_from_ip'] . ' ' . $context['ip'],
2438
		'start_var_name' => 'errorStart',
2439
		'items_per_page' => $modSettings['defaultMaxListItems'],
2440
		'no_items_label' => $txt['no_errors_from_ip'],
2441
		'base_href' => $context['base_url'] . ';searchip=' . $context['ip'],
2442
		'default_sort_col' => 'date2',
2443
		'get_items' => array(
2444
			'function' => 'list_getUserErrors',
2445
			'params' => array(
2446
				'le.ip >= ' . $ip_string[0] . ' and le.ip <= ' . $ip_string[1],
2447
				$fields,
2448
			),
2449
		),
2450
		'get_count' => array(
2451
			'function' => 'list_getUserErrorCount',
2452
			'params' => array(
2453
				'ip >= ' . $ip_string[0] . ' and ip <= ' . $ip_string[1],
2454
				$fields,
2455
			),
2456
		),
2457
		'columns' => array(
2458
			'ip_address2' => array(
2459
				'header' => array(
2460
					'value' => $txt['ip_address'],
2461
				),
2462
				'data' => array(
2463
					'sprintf' => array(
2464
						'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a>',
2465
						'params' => array(
2466
							'ip' => false,
2467
						),
2468
					),
2469
				),
2470
				'sort' => array(
2471
					'default' => 'le.ip',
2472
					'reverse' => 'le.ip DESC',
2473
				),
2474
			),
2475
			'display_name' => array(
2476
				'header' => array(
2477
					'value' => $txt['display_name'],
2478
				),
2479
				'data' => array(
2480
					'db' => 'member_link',
2481
				),
2482
			),
2483
			'message' => array(
2484
				'header' => array(
2485
					'value' => $txt['message'],
2486
				),
2487
				'data' => array(
2488
					'sprintf' => array(
2489
						'format' => '%1$s<br><a href="%2$s">%2$s</a>',
2490
						'params' => array(
2491
							'message' => false,
2492
							'url' => false,
2493
						),
2494
					),
2495
					'class' => 'word_break',
2496
				),
2497
			),
2498
			'date2' => array(
2499
				'header' => array(
2500
					'value' => $txt['date'],
2501
				),
2502
				'data' => array(
2503
					'db' => 'time',
2504
				),
2505
				'sort' => array(
2506
					'default' => 'le.id_error DESC',
2507
					'reverse' => 'le.id_error',
2508
				),
2509
			),
2510
		),
2511
		'additional_rows' => array(
2512
			array(
2513
				'position' => 'after_title',
2514
				'value' => $txt['errors_from_ip_desc'],
2515
			),
2516
		),
2517
	);
2518
2519
	// Create the error list.
2520
	createList($listOptions);
2521
2522
	// Allow 3rd party integrations to add in their own lists or whatever.
2523
	$context['additional_track_lists'] = array();
2524
	call_integration_hook('integrate_profile_trackip', array($ip_string, $ip_var));
2525
2526
	$context['single_ip'] = ($ip_var['low'] === $ip_var['high']);
2527
	if ($context['single_ip'])
2528
	{
2529
		$context['whois_servers'] = array(
2530
			'apnic' => array(
2531
				'name' => $txt['whois_apnic'],
2532
				'url' => 'https://wq.apnic.net/apnic-bin/whois.pl?searchtext=' . $context['ip'],
2533
			),
2534
			'arin' => array(
2535
				'name' => $txt['whois_arin'],
2536
				'url' => 'https://whois.arin.net/rest/ip/' . $context['ip'],
2537
			),
2538
			'lacnic' => array(
2539
				'name' => $txt['whois_lacnic'],
2540
				'url' => 'https://lacnic.net/cgi-bin/lacnic/whois?query=' . $context['ip'],
2541
			),
2542
			'ripe' => array(
2543
				'name' => $txt['whois_ripe'],
2544
				'url' => 'https://apps.db.ripe.net/search/query.html?searchtext=' . $context['ip'],
2545
			),
2546
		);
2547
	}
2548
}
2549
2550
/**
2551
 * Tracks a user's logins.
2552
 *
2553
 * @param int $memID The ID of the member
2554
 */
2555
function TrackLogins($memID = 0)
2556
{
2557
	global $scripturl, $txt, $sourcedir, $context;
2558
2559
	// Gonna want this for the list.
2560
	require_once($sourcedir . '/Subs-List.php');
2561
2562
	if ($memID == 0)
2563
		$context['base_url'] = $scripturl . '?action=trackip';
2564
	else
2565
		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2566
2567
	// Start with the user messages.
2568
	$listOptions = array(
2569
		'id' => 'track_logins_list',
2570
		'title' => $txt['trackLogins'],
2571
		'no_items_label' => $txt['trackLogins_none_found'],
2572
		'base_href' => $context['base_url'],
2573
		'get_items' => array(
2574
			'function' => 'list_getLogins',
2575
			'params' => array(
2576
				'id_member = {int:current_member}',
2577
				array('current_member' => $memID),
2578
			),
2579
		),
2580
		'get_count' => array(
2581
			'function' => 'list_getLoginCount',
2582
			'params' => array(
2583
				'id_member = {int:current_member}',
2584
				array('current_member' => $memID),
2585
			),
2586
		),
2587
		'columns' => array(
2588
			'time' => array(
2589
				'header' => array(
2590
					'value' => $txt['date'],
2591
				),
2592
				'data' => array(
2593
					'db' => 'time',
2594
				),
2595
			),
2596
			'ip' => array(
2597
				'header' => array(
2598
					'value' => $txt['ip_address'],
2599
				),
2600
				'data' => array(
2601
					'sprintf' => array(
2602
						'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a> (<a href="' . $context['base_url'] . ';searchip=%2$s">%2$s</a>) ',
2603
						'params' => array(
2604
							'ip' => false,
2605
							'ip2' => false
2606
						),
2607
					),
2608
				),
2609
			),
2610
		),
2611
		'additional_rows' => array(
2612
			array(
2613
				'position' => 'after_title',
2614
				'value' => $txt['trackLogins_desc'],
2615
			),
2616
		),
2617
	);
2618
2619
	// Create the messages list.
2620
	createList($listOptions);
2621
2622
	$context['sub_template'] = 'show_list';
2623
	$context['default_list'] = 'track_logins_list';
2624
}
2625
2626
/**
2627
 * Finds the total number of tracked logins for a particular user
2628
 *
2629
 * @param string $where A query to limit which logins are counted
2630
 * @param array $where_vars An array of parameters for $where
2631
 * @return int count of messages matching the IP
2632
 */
2633
function list_getLoginCount($where, $where_vars = array())
2634
{
2635
	global $smcFunc;
2636
2637
	$request = $smcFunc['db_query']('', '
2638
		SELECT COUNT(*) AS message_count
2639
		FROM {db_prefix}member_logins
2640
		WHERE id_member = {int:id_member}',
2641
		array(
2642
			'id_member' => $where_vars['current_member'],
2643
		)
2644
	);
2645
	list ($count) = $smcFunc['db_fetch_row']($request);
2646
	$smcFunc['db_free_result']($request);
2647
2648
	return (int) $count;
2649
}
2650
2651
/**
2652
 * Callback for the list in trackLogins.
2653
 *
2654
 * @param int $start Which item to start with (not used here)
2655
 * @param int $items_per_page How many items to show on each page (not used here)
2656
 * @param string $sort A string indicating
2657
 * @param string $where A query to filter results (not used here)
2658
 * @param array $where_vars An array of parameters for $where. Only 'current_member' (the ID of the member) is used here
2659
 * @return array An array of information about user logins
2660
 */
2661
function list_getLogins($start, $items_per_page, $sort, $where, $where_vars = array())
2662
{
2663
	global $smcFunc;
2664
2665
	$request = $smcFunc['db_query']('', '
2666
		SELECT time, ip, ip2
2667
		FROM {db_prefix}member_logins
2668
		WHERE id_member = {int:id_member}
2669
		ORDER BY time DESC',
2670
		array(
2671
			'id_member' => $where_vars['current_member'],
2672
		)
2673
	);
2674
	$logins = array();
2675
	while ($row = $smcFunc['db_fetch_assoc']($request))
2676
		$logins[] = array(
2677
			'time' => timeformat($row['time']),
2678
			'ip' => inet_dtop($row['ip']),
2679
			'ip2' => inet_dtop($row['ip2']),
2680
		);
2681
	$smcFunc['db_free_result']($request);
2682
2683
	return $logins;
2684
}
2685
2686
/**
2687
 * Tracks a user's profile edits
2688
 *
2689
 * @param int $memID The ID of the member
2690
 */
2691
function trackEdits($memID)
2692
{
2693
	global $scripturl, $txt, $modSettings, $sourcedir, $context, $smcFunc;
2694
2695
	require_once($sourcedir . '/Subs-List.php');
2696
2697
	// Get the names of any custom fields.
2698
	$request = $smcFunc['db_query']('', '
2699
		SELECT col_name, field_name, bbc
2700
		FROM {db_prefix}custom_fields',
2701
		array(
2702
		)
2703
	);
2704
	$context['custom_field_titles'] = array();
2705
	while ($row = $smcFunc['db_fetch_assoc']($request))
2706
		$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2707
			'title' => $row['field_name'],
2708
			'parse_bbc' => $row['bbc'],
2709
		);
2710
	$smcFunc['db_free_result']($request);
2711
2712
	// Set the options for the error lists.
2713
	$listOptions = array(
2714
		'id' => 'edit_list',
2715
		'title' => $txt['trackEdits'],
2716
		'items_per_page' => $modSettings['defaultMaxListItems'],
2717
		'no_items_label' => $txt['trackEdit_no_edits'],
2718
		'base_href' => $scripturl . '?action=profile;area=tracking;sa=edits;u=' . $memID,
2719
		'default_sort_col' => 'time',
2720
		'get_items' => array(
2721
			'function' => 'list_getProfileEdits',
2722
			'params' => array(
2723
				$memID,
2724
			),
2725
		),
2726
		'get_count' => array(
2727
			'function' => 'list_getProfileEditCount',
2728
			'params' => array(
2729
				$memID,
2730
			),
2731
		),
2732
		'columns' => array(
2733
			'action' => array(
2734
				'header' => array(
2735
					'value' => $txt['trackEdit_action'],
2736
				),
2737
				'data' => array(
2738
					'db' => 'action_text',
2739
				),
2740
			),
2741
			'before' => array(
2742
				'header' => array(
2743
					'value' => $txt['trackEdit_before'],
2744
				),
2745
				'data' => array(
2746
					'db' => 'before',
2747
				),
2748
			),
2749
			'after' => array(
2750
				'header' => array(
2751
					'value' => $txt['trackEdit_after'],
2752
				),
2753
				'data' => array(
2754
					'db' => 'after',
2755
				),
2756
			),
2757
			'time' => array(
2758
				'header' => array(
2759
					'value' => $txt['date'],
2760
				),
2761
				'data' => array(
2762
					'db' => 'time',
2763
				),
2764
				'sort' => array(
2765
					'default' => 'id_action DESC',
2766
					'reverse' => 'id_action',
2767
				),
2768
			),
2769
			'applicator' => array(
2770
				'header' => array(
2771
					'value' => $txt['trackEdit_applicator'],
2772
				),
2773
				'data' => array(
2774
					'db' => 'member_link',
2775
				),
2776
			),
2777
		),
2778
	);
2779
2780
	// Create the error list.
2781
	createList($listOptions);
2782
2783
	$context['sub_template'] = 'show_list';
2784
	$context['default_list'] = 'edit_list';
2785
}
2786
2787
/**
2788
 * How many edits?
2789
 *
2790
 * @param int $memID The ID of the member
2791
 * @return int The number of profile edits
2792
 */
2793
function list_getProfileEditCount($memID)
2794
{
2795
	global $smcFunc;
2796
2797
	$request = $smcFunc['db_query']('', '
2798
		SELECT COUNT(*) AS edit_count
2799
		FROM {db_prefix}log_actions
2800
		WHERE id_log = {int:log_type}
2801
			AND id_member = {int:owner}',
2802
		array(
2803
			'log_type' => 2,
2804
			'owner' => $memID,
2805
		)
2806
	);
2807
	list ($edit_count) = $smcFunc['db_fetch_row']($request);
2808
	$smcFunc['db_free_result']($request);
2809
2810
	return (int) $edit_count;
2811
}
2812
2813
/**
2814
 * Loads up information about a user's profile edits. Callback for the list in trackEdits()
2815
 *
2816
 * @param int $start Which item to start with (for pagination purposes)
2817
 * @param int $items_per_page How many items to show on each page
2818
 * @param string $sort A string indicating how to sort the results
2819
 * @param int $memID The ID of the member
2820
 * @return array An array of information about the profile edits
2821
 */
2822
function list_getProfileEdits($start, $items_per_page, $sort, $memID)
2823
{
2824
	global $smcFunc, $txt, $scripturl, $context;
2825
2826
	// Get a list of error messages from this ip (range).
2827
	$request = $smcFunc['db_query']('', '
2828
		SELECT
2829
			id_action, id_member, ip, log_time, action, extra
2830
		FROM {db_prefix}log_actions
2831
		WHERE id_log = {int:log_type}
2832
			AND id_member = {int:owner}
2833
		ORDER BY {raw:sort}
2834
		LIMIT {int:start}, {int:max}',
2835
		array(
2836
			'log_type' => 2,
2837
			'owner' => $memID,
2838
			'sort' => $sort,
2839
			'start' => $start,
2840
			'max' => $items_per_page,
2841
		)
2842
	);
2843
	$edits = array();
2844
	$members = array();
2845
	while ($row = $smcFunc['db_fetch_assoc']($request))
2846
	{
2847
		$extra = $smcFunc['json_decode']($row['extra'], true);
2848
		if (!empty($extra['applicator']))
2849
			$members[] = $extra['applicator'];
2850
2851
		// Work out what the name of the action is.
2852
		if (isset($txt['trackEdit_action_' . $row['action']]))
2853
			$action_text = $txt['trackEdit_action_' . $row['action']];
2854
		elseif (isset($txt[$row['action']]))
2855
			$action_text = $txt[$row['action']];
2856
		// Custom field?
2857
		elseif (isset($context['custom_field_titles'][$row['action']]))
2858
			$action_text = $context['custom_field_titles'][$row['action']]['title'];
2859
		else
2860
			$action_text = $row['action'];
2861
2862
		// Parse BBC?
2863
		$parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;
2864
2865
		$edits[] = array(
2866
			'id' => $row['id_action'],
2867
			'ip' => inet_dtop($row['ip']),
2868
			'id_member' => !empty($extra['applicator']) ? $extra['applicator'] : 0,
2869
			'member_link' => $txt['trackEdit_deleted_member'],
2870
			'action' => $row['action'],
2871
			'action_text' => $action_text,
2872
			'before' => !empty($extra['previous']) ? ($parse_bbc ? parse_bbc($extra['previous']) : $extra['previous']) : '',
2873
			'after' => !empty($extra['new']) ? ($parse_bbc ? parse_bbc($extra['new']) : $extra['new']) : '',
2874
			'time' => timeformat($row['log_time']),
2875
		);
2876
	}
2877
	$smcFunc['db_free_result']($request);
2878
2879
	// Get any member names.
2880
	if (!empty($members))
2881
	{
2882
		$request = $smcFunc['db_query']('', '
2883
			SELECT
2884
				id_member, real_name
2885
			FROM {db_prefix}members
2886
			WHERE id_member IN ({array_int:members})',
2887
			array(
2888
				'members' => $members,
2889
			)
2890
		);
2891
		$members = array();
2892
		while ($row = $smcFunc['db_fetch_assoc']($request))
2893
			$members[$row['id_member']] = $row['real_name'];
2894
		$smcFunc['db_free_result']($request);
2895
2896
		foreach ($edits as $key => $value)
2897
			if (isset($members[$value['id_member']]))
2898
				$edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
2899
	}
2900
2901
	return $edits;
2902
}
2903
2904
/**
2905
 * Display the history of group requests made by the user whose profile we are viewing.
2906
 *
2907
 * @param int $memID The ID of the member
2908
 */
2909
function trackGroupReq($memID)
2910
{
2911
	global $scripturl, $txt, $modSettings, $sourcedir, $context;
2912
2913
	require_once($sourcedir . '/Subs-List.php');
2914
2915
	// Set the options for the error lists.
2916
	$listOptions = array(
2917
		'id' => 'request_list',
2918
		'title' => sprintf($txt['trackGroupRequests_title'], $context['member']['name']),
2919
		'items_per_page' => $modSettings['defaultMaxListItems'],
2920
		'no_items_label' => $txt['requested_none'],
2921
		'base_href' => $scripturl . '?action=profile;area=tracking;sa=groupreq;u=' . $memID,
2922
		'default_sort_col' => 'time_applied',
2923
		'get_items' => array(
2924
			'function' => 'list_getGroupRequests',
2925
			'params' => array(
2926
				$memID,
2927
			),
2928
		),
2929
		'get_count' => array(
2930
			'function' => 'list_getGroupRequestsCount',
2931
			'params' => array(
2932
				$memID,
2933
			),
2934
		),
2935
		'columns' => array(
2936
			'group' => array(
2937
				'header' => array(
2938
					'value' => $txt['requested_group'],
2939
				),
2940
				'data' => array(
2941
					'db' => 'group_name',
2942
				),
2943
			),
2944
			'group_reason' => array(
2945
				'header' => array(
2946
					'value' => $txt['requested_group_reason'],
2947
				),
2948
				'data' => array(
2949
					'db' => 'group_reason',
2950
				),
2951
			),
2952
			'time_applied' => array(
2953
				'header' => array(
2954
					'value' => $txt['requested_group_time'],
2955
				),
2956
				'data' => array(
2957
					'db' => 'time_applied',
2958
					'timeformat' => true,
2959
				),
2960
				'sort' => array(
2961
					'default' => 'time_applied DESC',
2962
					'reverse' => 'time_applied',
2963
				),
2964
			),
2965
			'outcome' => array(
2966
				'header' => array(
2967
					'value' => $txt['requested_group_outcome'],
2968
				),
2969
				'data' => array(
2970
					'db' => 'outcome',
2971
				),
2972
			),
2973
		),
2974
	);
2975
2976
	// Create the error list.
2977
	createList($listOptions);
2978
2979
	$context['sub_template'] = 'show_list';
2980
	$context['default_list'] = 'request_list';
2981
}
2982
2983
/**
2984
 * How many edits?
2985
 *
2986
 * @param int $memID The ID of the member
2987
 * @return int The number of profile edits
2988
 */
2989
function list_getGroupRequestsCount($memID)
2990
{
2991
	global $smcFunc, $user_info;
2992
2993
	$request = $smcFunc['db_query']('', '
2994
		SELECT COUNT(*) AS req_count
2995
		FROM {db_prefix}log_group_requests AS lgr
2996
		WHERE id_member = {int:memID}
2997
			AND ' . ($user_info['mod_cache']['gq'] == '1=1' ? $user_info['mod_cache']['gq'] : 'lgr.' . $user_info['mod_cache']['gq']),
2998
		array(
2999
			'memID' => $memID,
3000
		)
3001
	);
3002
	list ($report_count) = $smcFunc['db_fetch_row']($request);
3003
	$smcFunc['db_free_result']($request);
3004
3005
	return (int) $report_count;
3006
}
3007
3008
/**
3009
 * Loads up information about a user's group requests. Callback for the list in trackGroupReq()
3010
 *
3011
 * @param int $start Which item to start with (for pagination purposes)
3012
 * @param int $items_per_page How many items to show on each page
3013
 * @param string $sort A string indicating how to sort the results
3014
 * @param int $memID The ID of the member
3015
 * @return array An array of information about the user's group requests
3016
 */
3017
function list_getGroupRequests($start, $items_per_page, $sort, $memID)
3018
{
3019
	global $smcFunc, $txt, $scripturl, $user_info;
3020
3021
	$groupreq = array();
3022
3023
	$request = $smcFunc['db_query']('', '
3024
		SELECT
3025
			lgr.id_group, mg.group_name, mg.online_color, lgr.time_applied, lgr.reason, lgr.status,
3026
			ma.id_member AS id_member_acted, COALESCE(ma.member_name, lgr.member_name_acted) AS act_name, lgr.time_acted, lgr.act_reason
3027
		FROM {db_prefix}log_group_requests AS lgr
3028
			LEFT JOIN {db_prefix}members AS ma ON (lgr.id_member_acted = ma.id_member)
3029
			INNER JOIN {db_prefix}membergroups AS mg ON (lgr.id_group = mg.id_group)
3030
		WHERE lgr.id_member = {int:memID}
3031
			AND ' . ($user_info['mod_cache']['gq'] == '1=1' ? $user_info['mod_cache']['gq'] : 'lgr.' . $user_info['mod_cache']['gq']) . '
3032
		ORDER BY {raw:sort}
3033
		LIMIT {int:start}, {int:max}',
3034
		array(
3035
			'memID' => $memID,
3036
			'sort' => $sort,
3037
			'start' => $start,
3038
			'max' => $items_per_page,
3039
		)
3040
	);
3041
	while ($row = $smcFunc['db_fetch_assoc']($request))
3042
	{
3043
		$this_req = array(
3044
			'group_name' => empty($row['online_color']) ? $row['group_name'] : '<span style="color:' . $row['online_color'] . '">' . $row['group_name'] . '</span>',
3045
			'group_reason' => $row['reason'],
3046
			'time_applied' => $row['time_applied'],
3047
		);
3048
		switch ($row['status'])
3049
		{
3050
			case 0:
3051
				$this_req['outcome'] = $txt['outcome_pending'];
3052
				break;
3053
			case 1:
3054
				$member_link = empty($row['id_member_acted']) ? $row['act_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_acted'] . '">' . $row['act_name'] . '</a>';
3055
				$this_req['outcome'] = sprintf($txt['outcome_approved'], $member_link, timeformat($row['time_acted']));
3056
				break;
3057
			case 2:
3058
				$member_link = empty($row['id_member_acted']) ? $row['act_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_acted'] . '">' . $row['act_name'] . '</a>';
3059
				$this_req['outcome'] = sprintf(!empty($row['act_reason']) ? $txt['outcome_refused_reason'] : $txt['outcome_refused'], $member_link, timeformat($row['time_acted']), $row['act_reason']);
3060
				break;
3061
		}
3062
3063
		$groupreq[] = $this_req;
3064
	}
3065
	$smcFunc['db_free_result']($request);
3066
3067
	return $groupreq;
3068
}
3069
3070
/**
3071
 * Shows which permissions a user has
3072
 *
3073
 * @param int $memID The ID of the member
3074
 */
3075
function showPermissions($memID)
3076
{
3077
	global $txt, $board, $modSettings;
3078
	global $user_profile, $context, $sourcedir, $smcFunc;
3079
3080
	// Verify if the user has sufficient permissions.
3081
	isAllowedTo('manage_permissions');
3082
3083
	loadLanguage('ManagePermissions');
3084
	loadLanguage('Admin');
3085
	loadTemplate('ManageMembers');
3086
3087
	// Load all the permission profiles.
3088
	require_once($sourcedir . '/ManagePermissions.php');
3089
	loadPermissionProfiles();
3090
3091
	$context['member']['id'] = $memID;
3092
	$context['member']['name'] = $user_profile[$memID]['real_name'];
3093
3094
	$context['page_title'] = $txt['showPermissions'];
3095
	$board = empty($board) ? 0 : (int) $board;
3096
	$context['board'] = $board;
3097
3098
	// Determine which groups this user is in.
3099
	if (empty($user_profile[$memID]['additional_groups']))
3100
		$curGroups = array();
3101
	else
3102
		$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
3103
	$curGroups[] = $user_profile[$memID]['id_group'];
3104
	$curGroups[] = $user_profile[$memID]['id_post_group'];
3105
3106
	// Load a list of boards for the jump box - except the defaults.
3107
	$request = $smcFunc['db_query']('order_by_board_order', '
3108
		SELECT b.id_board, b.name, b.id_profile, b.member_groups, COALESCE(mods.id_member, modgs.id_group, 0) AS is_mod
3109
		FROM {db_prefix}boards AS b
3110
			LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})
3111
			LEFT JOIN {db_prefix}moderator_groups AS modgs ON (modgs.id_board = b.id_board AND modgs.id_group IN ({array_int:current_groups}))
3112
		WHERE {query_see_board}',
3113
		array(
3114
			'current_member' => $memID,
3115
			'current_groups' => $curGroups,
3116
		)
3117
	);
3118
	$context['boards'] = array();
3119
	$context['no_access_boards'] = array();
3120
	while ($row = $smcFunc['db_fetch_assoc']($request))
3121
	{
3122
		if ((count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0) && !$row['is_mod']
3123
		&& (!empty($modSettings['board_manager_groups']) && count(array_intersect($curGroups, explode(',', $modSettings['board_manager_groups']))) === 0))
3124
			$context['no_access_boards'][] = array(
3125
				'id' => $row['id_board'],
3126
				'name' => $row['name'],
3127
				'is_last' => false,
3128
			);
3129
		elseif ($row['id_profile'] != 1 || $row['is_mod'])
3130
			$context['boards'][$row['id_board']] = array(
3131
				'id' => $row['id_board'],
3132
				'name' => $row['name'],
3133
				'selected' => $board == $row['id_board'],
3134
				'profile' => $row['id_profile'],
3135
				'profile_name' => $context['profiles'][$row['id_profile']]['name'],
3136
			);
3137
	}
3138
	$smcFunc['db_free_result']($request);
3139
3140
	require_once($sourcedir . '/Subs-Boards.php');
3141
	sortBoards($context['boards']);
3142
3143
	if (!empty($context['no_access_boards']))
3144
		$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
3145
3146
	$context['member']['permissions'] = array(
3147
		'general' => array(),
3148
		'board' => array()
3149
	);
3150
3151
	// If you're an admin we know you can do everything, we might as well leave.
3152
	$context['member']['has_all_permissions'] = in_array(1, $curGroups);
3153
	if ($context['member']['has_all_permissions'])
3154
		return;
3155
3156
	$denied = array();
3157
3158
	// Get all general permissions.
3159
	$result = $smcFunc['db_query']('', '
3160
		SELECT p.permission, p.add_deny, mg.group_name, p.id_group
3161
		FROM {db_prefix}permissions AS p
3162
			LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = p.id_group)
3163
		WHERE p.id_group IN ({array_int:group_list})
3164
		ORDER BY p.add_deny DESC, p.permission, mg.min_posts, CASE WHEN mg.id_group < {int:newbie_group} THEN mg.id_group ELSE 4 END, mg.group_name',
3165
		array(
3166
			'group_list' => $curGroups,
3167
			'newbie_group' => 4,
3168
		)
3169
	);
3170
	while ($row = $smcFunc['db_fetch_assoc']($result))
3171
	{
3172
		// We don't know about this permission, it doesn't exist :P.
3173
		if (!isset($txt['permissionname_' . $row['permission']]))
3174
			continue;
3175
3176
		if (empty($row['add_deny']))
3177
			$denied[] = $row['permission'];
3178
3179
		// Permissions that end with _own or _any consist of two parts.
3180
		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
3181
			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
3182
		else
3183
			$name = $txt['permissionname_' . $row['permission']];
3184
3185
		// Add this permission if it doesn't exist yet.
3186
		if (!isset($context['member']['permissions']['general'][$row['permission']]))
3187
			$context['member']['permissions']['general'][$row['permission']] = array(
3188
				'id' => $row['permission'],
3189
				'groups' => array(
3190
					'allowed' => array(),
3191
					'denied' => array()
3192
				),
3193
				'name' => $name,
3194
				'is_denied' => false,
3195
				'is_global' => true,
3196
			);
3197
3198
		// Add the membergroup to either the denied or the allowed groups.
3199
		$context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
3200
3201
		// Once denied is always denied.
3202
		$context['member']['permissions']['general'][$row['permission']]['is_denied'] |= empty($row['add_deny']);
3203
	}
3204
	$smcFunc['db_free_result']($result);
3205
3206
	$request = $smcFunc['db_query']('', '
3207
		SELECT
3208
			bp.add_deny, bp.permission, bp.id_group, mg.group_name' . (empty($board) ? '' : ',
3209
			b.id_profile, CASE WHEN (mods.id_member IS NULL AND modgs.id_group IS NULL) THEN 0 ELSE 1 END AS is_moderator') . '
3210
		FROM {db_prefix}board_permissions AS bp' . (empty($board) ? '' : '
3211
			INNER JOIN {db_prefix}boards AS b ON (b.id_board = {int:current_board})
3212
			LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})
3213
			LEFT JOIN {db_prefix}moderator_groups AS modgs ON (modgs.id_board = b.id_board AND modgs.id_group IN ({array_int:group_list}))') . '
3214
			LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = bp.id_group)
3215
		WHERE bp.id_profile = {raw:current_profile}
3216
			AND bp.id_group IN ({array_int:group_list}' . (empty($board) ? ')' : ', {int:moderator_group})
3217
			AND (mods.id_member IS NOT NULL OR modgs.id_group IS NOT NULL OR bp.id_group != {int:moderator_group})'),
3218
		array(
3219
			'current_board' => $board,
3220
			'group_list' => $curGroups,
3221
			'current_member' => $memID,
3222
			'current_profile' => empty($board) ? '1' : 'b.id_profile',
3223
			'moderator_group' => 3,
3224
		)
3225
	);
3226
3227
	while ($row = $smcFunc['db_fetch_assoc']($request))
3228
	{
3229
		// We don't know about this permission, it doesn't exist :P.
3230
		if (!isset($txt['permissionname_' . $row['permission']]))
3231
			continue;
3232
3233
		// The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'.
3234
		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
3235
			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
3236
		else
3237
			$name = $txt['permissionname_' . $row['permission']];
3238
3239
		// Create the structure for this permission.
3240
		if (!isset($context['member']['permissions']['board'][$row['permission']]))
3241
			$context['member']['permissions']['board'][$row['permission']] = array(
3242
				'id' => $row['permission'],
3243
				'groups' => array(
3244
					'allowed' => array(),
3245
					'denied' => array()
3246
				),
3247
				'name' => $name,
3248
				'is_denied' => false,
3249
				'is_global' => empty($board),
3250
			);
3251
3252
		$context['member']['permissions']['board'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][$row['id_group']] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
3253
3254
		$context['member']['permissions']['board'][$row['permission']]['is_denied'] |= empty($row['add_deny']);
3255
	}
3256
	$smcFunc['db_free_result']($request);
3257
}
3258
3259
/**
3260
 * View a member's warnings
3261
 *
3262
 * @param int $memID The ID of the member
3263
 */
3264
function viewWarning($memID)
3265
{
3266
	global $modSettings, $context, $sourcedir, $txt, $scripturl;
3267
3268
	// Firstly, can we actually even be here?
3269
	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum'))
3270
		fatal_lang_error('no_access', false);
3271
3272
	// Make sure things which are disabled stay disabled.
3273
	$modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
3274
	$modSettings['warning_moderate'] = !empty($modSettings['warning_moderate']) && !empty($modSettings['postmod_active']) ? $modSettings['warning_moderate'] : 110;
3275
	$modSettings['warning_mute'] = !empty($modSettings['warning_mute']) ? $modSettings['warning_mute'] : 110;
3276
3277
	// Let's use a generic list to get all the current warnings, and use the issue warnings grab-a-granny thing.
3278
	require_once($sourcedir . '/Subs-List.php');
3279
	require_once($sourcedir . '/Profile-Actions.php');
3280
3281
	$listOptions = array(
3282
		'id' => 'view_warnings',
3283
		'title' => $txt['profile_viewwarning_previous_warnings'],
3284
		'items_per_page' => $modSettings['defaultMaxListItems'],
3285
		'no_items_label' => $txt['profile_viewwarning_no_warnings'],
3286
		'base_href' => $scripturl . '?action=profile;area=viewwarning;sa=user;u=' . $memID,
3287
		'default_sort_col' => 'log_time',
3288
		'get_items' => array(
3289
			'function' => 'list_getUserWarnings',
3290
			'params' => array(
3291
				$memID,
3292
			),
3293
		),
3294
		'get_count' => array(
3295
			'function' => 'list_getUserWarningCount',
3296
			'params' => array(
3297
				$memID,
3298
			),
3299
		),
3300
		'columns' => array(
3301
			'log_time' => array(
3302
				'header' => array(
3303
					'value' => $txt['profile_warning_previous_time'],
3304
				),
3305
				'data' => array(
3306
					'db' => 'time',
3307
				),
3308
				'sort' => array(
3309
					'default' => 'lc.log_time DESC',
3310
					'reverse' => 'lc.log_time',
3311
				),
3312
			),
3313
			'reason' => array(
3314
				'header' => array(
3315
					'value' => $txt['profile_warning_previous_reason'],
3316
					'style' => 'width: 50%;',
3317
				),
3318
				'data' => array(
3319
					'db' => 'reason',
3320
				),
3321
			),
3322
			'level' => array(
3323
				'header' => array(
3324
					'value' => $txt['profile_warning_previous_level'],
3325
				),
3326
				'data' => array(
3327
					'db' => 'counter',
3328
				),
3329
				'sort' => array(
3330
					'default' => 'lc.counter DESC',
3331
					'reverse' => 'lc.counter',
3332
				),
3333
			),
3334
		),
3335
		'additional_rows' => array(
3336
			array(
3337
				'position' => 'after_title',
3338
				'value' => $txt['profile_viewwarning_desc'],
3339
				'class' => 'smalltext',
3340
				'style' => 'padding: 2ex;',
3341
			),
3342
		),
3343
	);
3344
3345
	// Create the list for viewing.
3346
	require_once($sourcedir . '/Subs-List.php');
3347
	createList($listOptions);
3348
3349
	// Create some common text bits for the template.
3350
	$context['level_effects'] = array(
3351
		0 => '',
3352
		$modSettings['warning_watch'] => $txt['profile_warning_effect_own_watched'],
3353
		$modSettings['warning_moderate'] => $txt['profile_warning_effect_own_moderated'],
3354
		$modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
3355
	);
3356
	$context['current_level'] = 0;
3357
	foreach ($context['level_effects'] as $limit => $dummy)
3358
		if ($context['member']['warning'] >= $limit)
3359
			$context['current_level'] = $limit;
3360
}
3361
3362
/**
3363
 * Sets the icon for a fetched alert.
3364
 *
3365
 * @param array The alert that we want to set an icon for.
0 ignored issues
show
Bug introduced by
The type The was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
3366
 */
3367
function set_alert_icon($alert)
3368
{
3369
	global $settings;
3370
3371
	switch ($alert['content_type'])
3372
	{
3373
		case 'topic':
3374
		case 'board':
3375
			{
3376
				switch ($alert['content_action'])
3377
				{
3378
					case 'reply':
3379
					case 'topic':
3380
						$class = 'main_icons posts';
3381
						break;
3382
3383
					case 'move':
3384
						$src = $settings['images_url'] . '/post/moved.png';
3385
						break;
3386
3387
					case 'remove':
3388
						$class = 'main_icons delete';
3389
						break;
3390
3391
					case 'lock':
3392
					case 'unlock':
3393
						$class = 'main_icons lock';
3394
						break;
3395
3396
					case 'sticky':
3397
					case 'unsticky':
3398
						$class = 'main_icons sticky';
3399
						break;
3400
3401
					case 'split':
3402
						$class = 'main_icons split_button';
3403
						break;
3404
3405
					case 'merge':
3406
						$class = 'main_icons merge';
3407
						break;
3408
3409
					case 'unapproved_topic':
3410
					case 'unapproved_post':
3411
						$class = 'main_icons post_moderation_moderate';
3412
						break;
3413
3414
					default:
3415
						$class = 'main_icons posts';
3416
						break;
3417
				}
3418
			}
3419
			break;
3420
3421
		case 'msg':
3422
			{
3423
				switch ($alert['content_action'])
3424
				{
3425
					case 'like':
3426
						$class = 'main_icons like';
3427
						break;
3428
3429
					case 'mention':
3430
						$class = 'main_icons im_on';
3431
						break;
3432
3433
					case 'quote':
3434
						$class = 'main_icons quote';
3435
						break;
3436
3437
					case 'unapproved_attachment':
3438
						$class = 'main_icons post_moderation_attach';
3439
						break;
3440
3441
					case 'report':
3442
					case 'report_reply':
3443
						$class = 'main_icons post_moderation_moderate';
3444
						break;
3445
3446
					default:
3447
						$class = 'main_icons posts';
3448
						break;
3449
				}
3450
			}
3451
			break;
3452
3453
		case 'member':
3454
			{
3455
				switch ($alert['content_action'])
3456
				{
3457
					case 'register_standard':
3458
					case 'register_approval':
3459
					case 'register_activation':
3460
						$class = 'main_icons members';
3461
						break;
3462
3463
					case 'report':
3464
					case 'report_reply':
3465
						$class = 'main_icons members_watched';
3466
						break;
3467
3468
					case 'buddy_request':
3469
						$class = 'main_icons people';
3470
						break;
3471
3472
					case 'group_request':
3473
						$class = 'main_icons members_request';
3474
						break;
3475
3476
					default:
3477
						$class = 'main_icons members';
3478
						break;
3479
				}
3480
			}
3481
			break;
3482
3483
		case 'groupr':
3484
			$class = 'main_icons members_request';
3485
			break;
3486
3487
		case 'event':
3488
			$class = 'main_icons calendar';
3489
			break;
3490
3491
		case 'paidsubs':
3492
			$class = 'main_icons paid';
3493
			break;
3494
3495
		case 'birthday':
3496
			$src = $settings['images_url'] . '/cake.png';
3497
			break;
3498
3499
		default:
3500
			$class = 'main_icons alerts';
3501
			break;
3502
	}
3503
3504
	if (isset($class))
3505
		return '<span class="alert_icon ' . $class . '"></span>';
3506
	elseif (isset($src))
3507
		return '<img class="alert_icon" src="' . $src . '">';
3508
	else
3509
		return '';
3510
}
3511
3512
?>