Passed
Push — release-2.1 ( 0e5bfc...908430 )
by Mathias
07:53 queued 12s
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
nop 2
dl 0
loc 31
rs 8.0555
c 0
b 0
f 0
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(
364
		function ($format) use ($scripturl)
365
		{
366
			$format['link'] = str_replace('{scripturl}', $scripturl, $format['link']);
367
			$format['text'] = str_replace('{scripturl}', $scripturl, $format['text']);
368
369
			return $format;
370
		},
371
		$formats
372
	);
373
374
	// If we need to check board access, use the correct board access filter for the member in question.
375
	if ((!isset($user_info['query_see_board']) || $user_info['id'] != $memID) && (!empty($possible_msgs) || !empty($possible_topics)))
376
		$qb = build_query_board($memID);
377
	else
378
		$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...
379
380
	// For anything that needs more info and/or wants us to check board or topic access, let's do that.
381
	if (!empty($possible_msgs))
382
	{
383
		$flipped_msgs = array();
384
		foreach ($possible_msgs as $id_alert => $id_msg)
385
		{
386
			if (!isset($flipped_msgs[$id_msg]))
387
				$flipped_msgs[$id_msg] = array();
388
389
			$flipped_msgs[$id_msg][] = $id_alert;
390
		}
391
392
		$request = $smcFunc['db_query']('', '
393
			SELECT m.id_msg, m.id_topic, m.subject, b.id_board, b.name AS board_name
394
			FROM {db_prefix}messages AS m
395
				INNER JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
396
			WHERE ' . $qb['query_see_board'] . '
397
				AND m.id_msg IN ({array_int:msgs})
398
			ORDER BY m.id_msg',
399
			array(
400
				'msgs' => $possible_msgs,
401
			)
402
		);
403
		while ($row = $smcFunc['db_fetch_assoc']($request))
404
		{
405
			foreach ($flipped_msgs[$row['id_msg']] as $id_alert)
406
			{
407
				$alerts[$id_alert]['content_data'] = $row;
408
				$alerts[$id_alert]['visible'] = true;
409
			}
410
		}
411
		$smcFunc['db_free_result']($request);
412
	}
413
	if (!empty($possible_topics))
414
	{
415
		$flipped_topics = array();
416
		foreach ($possible_topics as $id_alert => $id_topic)
417
		{
418
			if (!isset($flipped_topics[$id_topic]))
419
				$flipped_topics[$id_topic] = array();
420
421
			$flipped_topics[$id_topic][] = $id_alert;
422
		}
423
424
		$request = $smcFunc['db_query']('', '
425
			SELECT m.id_msg, t.id_topic, m.subject, b.id_board, b.name AS board_name
426
			FROM {db_prefix}topics AS t
427
				INNER JOIN {db_prefix}messages AS m ON (t.id_first_msg = m.id_msg)
428
				INNER JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
429
			WHERE ' . $qb['query_see_board'] . '
430
				AND t.id_topic IN ({array_int:topics})',
431
			array(
432
				'topics' => $possible_topics,
433
			)
434
		);
435
		while ($row = $smcFunc['db_fetch_assoc']($request))
436
		{
437
			foreach ($flipped_topics[$row['id_topic']] as $id_alert)
438
			{
439
				$alerts[$id_alert]['content_data'] = $row;
440
				$alerts[$id_alert]['visible'] = true;
441
			}
442
		}
443
		$smcFunc['db_free_result']($request);
444
	}
445
446
	// 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)
447
	foreach ($alerts as $id_alert => $dummy)
448
	{
449
		// There's no point showing alerts for inaccessible content.
450
		if (!$alerts[$id_alert]['visible'])
451
		{
452
			unset($alerts[$id_alert]);
453
			continue;
454
		}
455
		else
456
			unset($alerts[$id_alert]['visible']);
457
458
		// Did a mod already take care of this one?
459
		if (!empty($alerts[$id_alert]['text']))
460
			continue;
461
462
		// For developer convenience.
463
		$alert = &$alerts[$id_alert];
464
465
		// The info in extra might outdated if the topic was moved, the message's subject was changed, etc.
466
		if (!empty($alert['content_data']))
467
		{
468
			$data = $alert['content_data'];
469
470
			// Make sure msg, topic, and board info are correct.
471
			$patterns = array();
472
			$replacements = array();
473
			foreach (array('msg', 'topic', 'board') as $item)
474
			{
475
				if (isset($data['id_' . $item]))
476
				{
477
					$separator = $item == 'msg' ? '=?' : '=';
478
479
					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)
480
					{
481
						$patterns[] = '/\b' . $item . $separator . '\d+/';
482
						$replacements[] = $item . $separator . $data['id_' . $item];
483
					}
484
485
					$alert['extra'][$item] = $data['id_' . $item];
486
				}
487
			}
488
			if (!empty($patterns))
489
				$alert['extra']['content_link'] = preg_replace($patterns, $replacements, $alert['extra']['content_link']);
490
491
			// Make sure the subject is correct.
492
			if (isset($data['subject']))
493
				$alert['extra']['content_subject'] = $data['subject'];
494
495
			// Keep track of this so we can use it below.
496
			if (isset($data['board_name']))
497
				$alert['extra']['board_name'] = $data['board_name'];
498
499
			unset($alert['content_data']);
500
		}
501
502
		// Do we want to link to the topic in general or the new messages specifically?
503
		if (isset($possible_topics[$id_alert]) && in_array($alert['content_action'], array('reply', 'topic', 'unapproved_reply')))
504
				$alert['extra']['topic_suffix'] = 'new;topicseen#new';
505
		elseif (isset($alert['extra']['topic']))
506
			$alert['extra']['topic_suffix'] = '0';
507
508
		// Make sure profile alerts have what they need.
509
		if (in_array($id_alert, $profile_alerts))
510
		{
511
			if (empty($alert['extra']['user_id']))
512
				$alert['extra']['user_id'] = $alert['content_id'];
513
514
			if (isset($user_profile[$alert['extra']['user_id']]))
515
				$alert['extra']['user_name'] = $user_profile[$alert['extra']['user_id']]['real_name'];
516
		}
517
518
		// If we loaded the sender's profile, we may as well use it.
519
		$sender_id = !empty($alert['sender_id']) ? $alert['sender_id'] : 0;
520
		if (isset($user_profile[$sender_id]))
521
			$alert['sender_name'] = $user_profile[$sender_id]['real_name'];
522
523
		// If requested, include the sender's avatar data.
524
		if ($with_avatar && !empty($senders[$sender_id]))
525
			$alert['sender'] = $senders[$sender_id];
526
527
		// Next, build the message strings.
528
		foreach ($formats as $msg_type => $format_info)
529
		{
530
			// Get the values to use in the formatted string, in the right order.
531
			$msg_values = array_replace(
532
				array_fill_keys($format_info['required'], ''),
533
				array_intersect_key($alert['extra'], array_flip($format_info['required']))
534
			);
535
536
			// Assuming all required values are present, build the message.
537
			if (!in_array('', $msg_values))
538
				$alert['extra'][$msg_type] = vsprintf($formats[$msg_type][$alert['show_links'] ? 'link' : 'text'], $msg_values);
539
540
			elseif (in_array($msg_type, array('msg_msg', 'topic_msg', 'board_msg')))
541
				$alert['extra'][$msg_type] = $txt[$msg_type == 'board_msg' ? 'board_na' : 'topic_na'];
542
			else
543
				$alert['extra'][$msg_type] = '(' . $txt['not_applicable'] . ')';
544
		}
545
546
		// Show the formatted time in alerts about subscriptions.
547
		if ($alert['content_type'] == 'paidsubs' && isset($alert['extra']['end_time']))
548
		{
549
			// If the subscription already expired, say so.
550
			if ($alert['extra']['end_time'] < time())
551
				$alert['content_action'] = 'expired';
552
553
			// Present a nicely formatted date.
554
			$alert['extra']['end_time'] = timeformat($alert['extra']['end_time']);
555
		}
556
557
		// Now set the main URL that this alert should take the user to.
558
		$alert['target_href'] = '';
559
560
		// Priority goes to explicitly specified links.
561
		if (isset($alert['extra']['content_link']))
562
			$alert['target_href'] = $alert['extra']['content_link'];
563
564
		elseif (isset($alert['extra']['report_link']))
565
			$alert['target_href'] = $scripturl . $alert['extra']['report_link'];
566
567
		// Next, try determining the link based on the content action.
568
		if (empty($alert['target_href']) && in_array($alert['content_action'], array('register_approval', 'group_request', 'buddy_request')))
569
		{
570
			switch ($alert['content_action'])
571
			{
572
				case 'register_approval':
573
					$alert['target_href'] = $scripturl . '?action=admin;area=viewmembers;sa=browse;type=approve';
574
					break;
575
576
				case 'group_request':
577
					$alert['target_href'] = $scripturl . '?action=moderate;area=groups;sa=requests';
578
					break;
579
580
				case 'buddy_request':
581
					if (!empty($alert['id_member_started']))
582
						$alert['target_href'] = $scripturl . '?action=profile;u=' . $alert['id_member_started'];
583
					break;
584
585
				default:
586
					break;
587
			}
588
		}
589
590
		// Or maybe we can determine the link based on the content type.
591
		if (empty($alert['target_href']) && in_array($alert['content_type'], array('msg', 'member', 'event')))
592
		{
593
			switch ($alert['content_type'])
594
			{
595
				case 'msg':
596
					if (!empty($alert['content_id']))
597
						$alert['target_href'] = $scripturl . '?msg=' . $alert['content_id'];
598
					break;
599
600
				case 'member':
601
					if (!empty($alert['id_member_started']))
602
						$alert['target_href'] = $scripturl . '?action=profile;u=' . $alert['id_member_started'];
603
					break;
604
605
				case 'event':
606
					if (!empty($alert['extra']['event_id']))
607
						$alert['target_href'] = $scripturl . '?action=calendar;event=' . $alert['extra']['event_id'];
608
					break;
609
610
				default:
611
					break;
612
			}
613
614
		}
615
616
		// Finally, set this alert's text string.
617
		$string = 'alert_' . $alert['content_type'] . '_' . $alert['content_action'];
618
619
		// This kludge exists because the alert content_types prior to 2.1 RC3 were a bit haphazard.
620
		// This can be removed once all the translated language files have been updated.
621
		if (!isset($txt[$string]))
622
		{
623
			if (strpos($alert['content_action'], 'unapproved_') === 0)
624
				$string = 'alert_' . $alert['content_action'];
625
626
			if ($alert['content_type'] === 'member' && in_array($alert['content_action'], array('report', 'report_reply')))
627
				$string = 'alert_profile_' . $alert['content_action'];
628
629
			if ($alert['content_type'] === 'member' && $alert['content_action'] === 'buddy_request')
630
				$string = 'alert_buddy_' . $alert['content_action'];
631
		}
632
633
		if (isset($txt[$string]))
634
		{
635
			$substitutions = array(
636
				'{scripturl}' => $scripturl,
637
				'{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>',
638
			);
639
640
			if (is_array($alert['extra']))
641
			{
642
				foreach ($alert['extra'] as $k => $v)
643
					$substitutions['{' . $k . '}'] = $v;
644
			}
645
646
			$alert['text'] = strtr($txt[$string], $substitutions);
647
		}
648
649
		// Unset the reference variable to avoid any surprises in subsequent loops.
650
		unset($alert);
651
	}
652
653
	return $alerts;
654
}
655
656
/**
657
 * Shows all alerts for a member
658
 *
659
 * @param int $memID The ID of the member
660
 */
661
function showAlerts($memID)
662
{
663
	global $context, $smcFunc, $txt, $sourcedir, $scripturl, $options;
664
665
	require_once($sourcedir . '/Profile-Modify.php');
666
667
	// Are we opening a specific alert? (i.e.: ?action=profile;area=showalerts;alert=12345)
668
	if (!empty($_REQUEST['alert']))
669
	{
670
		$alert_id = (int) $_REQUEST['alert'];
671
		$alerts = fetch_alerts($memID, $alert_id);
672
		$alert = array_pop($alerts);
673
674
		/*
675
		 * MOD AUTHORS:
676
		 * To control this redirect, use the 'integrate_fetch_alerts' hook to
677
		 * set the value of $alert['extra']['content_link'], which will become
678
		 * the value for $alert['target_href'].
679
		 */
680
681
		// In case it failed to determine this alert's link
682
		if (empty($alert['target_href']))
683
			redirectexit('action=profile;area=showalerts');
684
685
		// Mark the alert as read while we're at it.
686
		alert_mark($memID, $alert_id, 1);
687
688
		// Take the user to the content
689
		redirectexit($alert['target_href']);
690
	}
691
692
	// Prepare the pagination vars.
693
	$maxIndex = 10;
694
	$context['start'] = (int) isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
695
	$count = alert_count($memID);
696
697
	// Fix invalid 'start' offsets.
698
	if ($context['start'] > $count)
699
		$context['start'] = $count - ($count % $maxIndex);
700
	else
701
		$context['start'] = $context['start'] - ($context['start'] % $maxIndex);
702
703
	// Get the alerts.
704
	$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

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

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