|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Simple Machines Forum (SMF) |
|
5
|
|
|
* |
|
6
|
|
|
* @package SMF |
|
7
|
|
|
* @author Simple Machines https://www.simplemachines.org |
|
8
|
|
|
* @copyright 2020 Simple Machines and individual contributors |
|
9
|
|
|
* @license https://www.simplemachines.org/about/smf/license.php BSD |
|
10
|
|
|
* |
|
11
|
|
|
* @version 2.1 RC3 |
|
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); |
|
|
|
|
|
|
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
|
|
|
$context['member'] = &$memberContext[$memID]; |
|
39
|
|
|
|
|
40
|
|
|
// Set a canonical URL for this page. |
|
41
|
|
|
$context['canonical_url'] = $scripturl . '?action=profile;u=' . $memID; |
|
42
|
|
|
|
|
43
|
|
|
// Are there things we don't show? |
|
44
|
|
|
$context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array(); |
|
45
|
|
|
// Menu tab |
|
46
|
|
|
$context[$context['profile_menu_name']]['tab_data'] = array( |
|
47
|
|
|
'title' => $txt['summary'], |
|
48
|
|
|
'icon' => 'profile_hd.png' |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
// See if they have broken any warning levels... |
|
52
|
|
|
list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']); |
|
53
|
|
|
if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) |
|
54
|
|
|
$context['warning_status'] = $txt['profile_warning_is_muted']; |
|
55
|
|
|
elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) |
|
56
|
|
|
$context['warning_status'] = $txt['profile_warning_is_moderation']; |
|
57
|
|
|
elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) |
|
58
|
|
|
$context['warning_status'] = $txt['profile_warning_is_watch']; |
|
59
|
|
|
|
|
60
|
|
|
// They haven't even been registered for a full day!? |
|
61
|
|
|
$days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24)); |
|
62
|
|
|
if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) |
|
63
|
|
|
$context['member']['posts_per_day'] = $txt['not_applicable']; |
|
64
|
|
|
else |
|
65
|
|
|
$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3); |
|
66
|
|
|
|
|
67
|
|
|
// Set the age... |
|
68
|
|
|
if (empty($context['member']['birth_date']) || substr($context['member']['birth_date'], 0, 4) < 1002) |
|
69
|
|
|
{ |
|
70
|
|
|
$context['member'] += array( |
|
71
|
|
|
'age' => $txt['not_applicable'], |
|
72
|
|
|
'today_is_birthday' => false |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
else |
|
76
|
|
|
{ |
|
77
|
|
|
list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d'); |
|
78
|
|
|
$datearray = getdate(forum_time()); |
|
79
|
|
|
$context['member'] += array( |
|
80
|
|
|
'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), |
|
81
|
|
|
'today_is_birthday' => $datearray['mon'] == $birth_month && $datearray['mday'] == $birth_day && $birth_year > 1004 |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
if (allowedTo('moderate_forum')) |
|
86
|
|
|
{ |
|
87
|
|
|
// Make sure it's a valid ip address; otherwise, don't bother... |
|
88
|
|
|
if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) |
|
89
|
|
|
$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']); |
|
90
|
|
|
else |
|
91
|
|
|
$context['member']['hostname'] = ''; |
|
92
|
|
|
|
|
93
|
|
|
$context['can_see_ip'] = true; |
|
94
|
|
|
} |
|
95
|
|
|
else |
|
96
|
|
|
$context['can_see_ip'] = false; |
|
97
|
|
|
|
|
98
|
|
|
// Are they hidden? |
|
99
|
|
|
$context['member']['is_hidden'] = empty($user_profile[$memID]['show_online']); |
|
100
|
|
|
$context['member']['show_last_login'] = allowedTo('admin_forum') || !$context['member']['is_hidden']; |
|
101
|
|
|
|
|
102
|
|
|
if (!empty($modSettings['who_enabled']) && $context['member']['show_last_login']) |
|
103
|
|
|
{ |
|
104
|
|
|
include_once($sourcedir . '/Who.php'); |
|
105
|
|
|
$action = determineActions($user_profile[$memID]['url']); |
|
106
|
|
|
|
|
107
|
|
|
if ($action !== false) |
|
|
|
|
|
|
108
|
|
|
$context['member']['action'] = $action; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
// If the user is awaiting activation, and the viewer has permission - setup some activation context messages. |
|
112
|
|
|
if ($context['member']['is_activated'] % 10 != 1 && allowedTo('moderate_forum')) |
|
113
|
|
|
{ |
|
114
|
|
|
$context['activate_type'] = $context['member']['is_activated']; |
|
115
|
|
|
// What should the link text be? |
|
116
|
|
|
$context['activate_link_text'] = in_array($context['member']['is_activated'], array(3, 4, 5, 13, 14, 15)) ? $txt['account_approve'] : $txt['account_activate']; |
|
117
|
|
|
|
|
118
|
|
|
// Should we show a custom message? |
|
119
|
|
|
$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']; |
|
120
|
|
|
|
|
121
|
|
|
// If they can be approved, we need to set up a token for them. |
|
122
|
|
|
$context['token_check'] = 'profile-aa' . $memID; |
|
123
|
|
|
createToken($context['token_check'], 'get'); |
|
124
|
|
|
|
|
125
|
|
|
// Puerile comment |
|
126
|
|
|
$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']; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
// Is the signature even enabled on this forum? |
|
130
|
|
|
$context['signature_enabled'] = substr($modSettings['signature_settings'], 0, 1) == 1; |
|
131
|
|
|
|
|
132
|
|
|
// Prevent signature images from going outside the box. |
|
133
|
|
|
if ($context['signature_enabled']) |
|
134
|
|
|
{ |
|
135
|
|
|
list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']); |
|
136
|
|
|
$sig_limits = explode(',', $sig_limits); |
|
137
|
|
|
|
|
138
|
|
|
if (!empty($sig_limits[5]) || !empty($sig_limits[6])) |
|
139
|
|
|
addInlineCss(' |
|
140
|
|
|
.signature img { ' . (!empty($sig_limits[5]) ? 'max-width: ' . (int) $sig_limits[5] . 'px; ' : '') . (!empty($sig_limits[6]) ? 'max-height: ' . (int) $sig_limits[6] . 'px; ' : '') . '}'); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
// How about, are they banned? |
|
144
|
|
|
$context['member']['bans'] = array(); |
|
145
|
|
|
if (allowedTo('moderate_forum')) |
|
146
|
|
|
{ |
|
147
|
|
|
// Can they edit the ban? |
|
148
|
|
|
$context['can_edit_ban'] = allowedTo('manage_bans'); |
|
149
|
|
|
|
|
150
|
|
|
$ban_query = array(); |
|
151
|
|
|
$ban_query_vars = array( |
|
152
|
|
|
'time' => time(), |
|
153
|
|
|
); |
|
154
|
|
|
$ban_query[] = 'id_member = ' . $context['member']['id']; |
|
155
|
|
|
$ban_query[] = ' {inet:ip} BETWEEN bi.ip_low and bi.ip_high'; |
|
156
|
|
|
$ban_query_vars['ip'] = $memberContext[$memID]['ip']; |
|
157
|
|
|
// Do we have a hostname already? |
|
158
|
|
|
if (!empty($context['member']['hostname'])) |
|
159
|
|
|
{ |
|
160
|
|
|
$ban_query[] = '({string:hostname} LIKE hostname)'; |
|
161
|
|
|
$ban_query_vars['hostname'] = $context['member']['hostname']; |
|
162
|
|
|
} |
|
163
|
|
|
// Check their email as well... |
|
164
|
|
|
if (strlen($context['member']['email']) != 0) |
|
165
|
|
|
{ |
|
166
|
|
|
$ban_query[] = '({string:email} LIKE bi.email_address)'; |
|
167
|
|
|
$ban_query_vars['email'] = $context['member']['email']; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
// So... are they banned? Dying to know! |
|
171
|
|
|
$request = $smcFunc['db_query']('', ' |
|
172
|
|
|
SELECT bg.id_ban_group, bg.name, bg.cannot_access, bg.cannot_post, |
|
173
|
|
|
bg.cannot_login, bg.reason |
|
174
|
|
|
FROM {db_prefix}ban_items AS bi |
|
175
|
|
|
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})) |
|
176
|
|
|
WHERE (' . implode(' OR ', $ban_query) . ')', |
|
177
|
|
|
$ban_query_vars |
|
178
|
|
|
); |
|
179
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
180
|
|
|
{ |
|
181
|
|
|
// Work out what restrictions we actually have. |
|
182
|
|
|
$ban_restrictions = array(); |
|
183
|
|
|
foreach (array('access', 'login', 'post') as $type) |
|
184
|
|
|
if ($row['cannot_' . $type]) |
|
185
|
|
|
$ban_restrictions[] = $txt['ban_type_' . $type]; |
|
186
|
|
|
|
|
187
|
|
|
// No actual ban in place? |
|
188
|
|
|
if (empty($ban_restrictions)) |
|
189
|
|
|
continue; |
|
190
|
|
|
|
|
191
|
|
|
// Prepare the link for context. |
|
192
|
|
|
$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>'); |
|
193
|
|
|
|
|
194
|
|
|
$context['member']['bans'][$row['id_ban_group']] = array( |
|
195
|
|
|
'reason' => empty($row['reason']) ? '' : '<br><br><strong>' . $txt['ban_reason'] . ':</strong> ' . $row['reason'], |
|
196
|
|
|
'cannot' => array( |
|
197
|
|
|
'access' => !empty($row['cannot_access']), |
|
198
|
|
|
'post' => !empty($row['cannot_post']), |
|
199
|
|
|
'login' => !empty($row['cannot_login']), |
|
200
|
|
|
), |
|
201
|
|
|
'explanation' => $ban_explanation, |
|
202
|
|
|
); |
|
203
|
|
|
} |
|
204
|
|
|
$smcFunc['db_free_result']($request); |
|
205
|
|
|
} |
|
206
|
|
|
loadCustomFields($memID); |
|
207
|
|
|
|
|
208
|
|
|
$context['print_custom_fields'] = array(); |
|
209
|
|
|
|
|
210
|
|
|
// Any custom profile fields? |
|
211
|
|
|
if (!empty($context['custom_fields'])) |
|
212
|
|
|
foreach ($context['custom_fields'] as $custom) |
|
213
|
|
|
$context['print_custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom; |
|
214
|
|
|
|
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* Fetch the alerts a member currently has. |
|
219
|
|
|
* |
|
220
|
|
|
* @param int $memID The ID of the member. |
|
221
|
|
|
* @param mixed $to_fetch Alerts to fetch: true/false for all/unread, or a list of one or more IDs. |
|
222
|
|
|
* @param array $limit Maximum number of alerts to fetch (0 for no limit). |
|
223
|
|
|
* @param array $offset Number of alerts to skip for pagination. Ignored if $to_fetch is a list of IDs. |
|
224
|
|
|
* @param bool $with_avatar Whether to load the avatar of the alert sender. |
|
225
|
|
|
* @param bool $show_links Whether to show links in the constituent parts of the alert meessage. |
|
226
|
|
|
* @return array An array of information about the fetched alerts. |
|
227
|
|
|
*/ |
|
228
|
|
|
function fetch_alerts($memID, $to_fetch = false, $limit = 0, $offset = 0, $with_avatar = false, $show_links = false) |
|
229
|
|
|
{ |
|
230
|
|
|
global $smcFunc, $txt, $scripturl, $user_info, $user_profile, $modSettings, $context; |
|
231
|
|
|
|
|
232
|
|
|
// Are we being asked for some specific alerts? |
|
233
|
|
|
$alertIDs = is_bool($to_fetch) ? array() : array_filter(array_map('intval', (array) $to_fetch)); |
|
234
|
|
|
|
|
235
|
|
|
// Basic sanitation. |
|
236
|
|
|
$memID = (int) $memID; |
|
237
|
|
|
$unread = $to_fetch === false; |
|
238
|
|
|
$limit = max(0, (int) $limit); |
|
239
|
|
|
$offset = !empty($alertIDs) ? 0 : max(0, (int) $offset); |
|
240
|
|
|
$with_avatar = !empty($with_avatar); |
|
241
|
|
|
$show_links = !empty($show_links); |
|
242
|
|
|
|
|
243
|
|
|
// Arrays we'll need. |
|
244
|
|
|
$alerts = array(); |
|
245
|
|
|
$senders = array(); |
|
246
|
|
|
$profiles = array(); |
|
247
|
|
|
$profile_alerts = array(); |
|
248
|
|
|
$possible_msgs = array(); |
|
249
|
|
|
$possible_topics = array(); |
|
250
|
|
|
|
|
251
|
|
|
// Get the basic alert info. |
|
252
|
|
|
$request = $smcFunc['db_query']('', ' |
|
253
|
|
|
SELECT a.id_alert, a.alert_time, a.is_read, a.extra, |
|
254
|
|
|
a.content_type, a.content_id, a.content_action, |
|
255
|
|
|
mem.id_member AS sender_id, COALESCE(mem.real_name, a.member_name) AS sender_name' . ($with_avatar ? ', |
|
256
|
|
|
mem.email_address AS sender_email, mem.avatar AS sender_avatar, f.filename AS sender_filename' : '') . ' |
|
257
|
|
|
FROM {db_prefix}user_alerts AS a |
|
258
|
|
|
LEFT JOIN {db_prefix}members AS mem ON (a.id_member_started = mem.id_member)' . ($with_avatar ? ' |
|
259
|
|
|
LEFT JOIN {db_prefix}attachments AS f ON (mem.id_member = f.id_member)' : '') . ' |
|
260
|
|
|
WHERE a.id_member = {int:id_member}' . ($unread ? ' |
|
261
|
|
|
AND a.is_read = 0' : '') . (!empty($alertIDs) ? ' |
|
262
|
|
|
AND a.id_alert IN ({array_int:alertIDs})' : '') . ' |
|
263
|
|
|
ORDER BY id_alert DESC' . (!empty($limit) ? ' |
|
264
|
|
|
LIMIT {int:limit}' : '') . (!empty($offset) ?' |
|
265
|
|
|
OFFSET {int:offset}' : ''), |
|
266
|
|
|
array( |
|
267
|
|
|
'id_member' => $memID, |
|
268
|
|
|
'alertIDs' => $alertIDs, |
|
269
|
|
|
'limit' => $limit, |
|
270
|
|
|
'offset' => $offset, |
|
271
|
|
|
) |
|
272
|
|
|
); |
|
273
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
274
|
|
|
{ |
|
275
|
|
|
$id_alert = array_shift($row); |
|
276
|
|
|
$row['time'] = timeformat($row['alert_time']); |
|
277
|
|
|
$row['extra'] = !empty($row['extra']) ? $smcFunc['json_decode']($row['extra'], true) : array(); |
|
278
|
|
|
$alerts[$id_alert] = $row; |
|
279
|
|
|
|
|
280
|
|
|
if (!empty($row['sender_email'])) |
|
281
|
|
|
{ |
|
282
|
|
|
$senders[$row['sender_id']] = array( |
|
283
|
|
|
'email' => $row['sender_email'], |
|
284
|
|
|
'avatar' => $row['sender_avatar'], |
|
285
|
|
|
'filename' => $row['sender_filename'], |
|
286
|
|
|
); |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
if ($row['content_type'] == 'profile') |
|
290
|
|
|
{ |
|
291
|
|
|
$profiles[] = $row['content_id']; |
|
292
|
|
|
$profile_alerts[] = $id_alert; |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
// For these types, we need to check whether they can actually see the content. |
|
296
|
|
|
if ($row['content_type'] == 'msg') |
|
297
|
|
|
{ |
|
298
|
|
|
$alerts[$id_alert]['visible'] = false; |
|
299
|
|
|
$possible_msgs[$id_alert] = $row['content_id']; |
|
300
|
|
|
} |
|
301
|
|
|
elseif (in_array($row['content_type'], array('topic', 'board'))) |
|
302
|
|
|
{ |
|
303
|
|
|
$alerts[$id_alert]['visible'] = false; |
|
304
|
|
|
$possible_topics[$id_alert] = $row['content_id']; |
|
305
|
|
|
} |
|
306
|
|
|
// For the rest, they can always see it. |
|
307
|
|
|
else |
|
308
|
|
|
$alerts[$id_alert]['visible'] = true; |
|
309
|
|
|
|
|
310
|
|
|
// Are we showing multiple links or one big main link ? |
|
311
|
|
|
$alerts[$id_alert]['show_links'] = $show_links || (isset($row['extra']['show_links']) && $row['extra']['show_links']); |
|
312
|
|
|
|
|
313
|
|
|
// Set an appropriate icon. |
|
314
|
|
|
$alerts[$id_alert]['icon'] = set_alert_icon($alerts[$id_alert]); |
|
315
|
|
|
} |
|
316
|
|
|
$smcFunc['db_free_result']($request); |
|
317
|
|
|
|
|
318
|
|
|
// Look up member info of anyone we need it for. |
|
319
|
|
|
if (!empty($profiles)) |
|
320
|
|
|
loadMemberData($profiles, false, 'minimal'); |
|
321
|
|
|
|
|
322
|
|
|
// Get the senders' avatars. |
|
323
|
|
|
if ($with_avatar) |
|
324
|
|
|
{ |
|
325
|
|
|
foreach ($senders as $sender_id => $sender) |
|
326
|
|
|
$senders[$sender_id]['avatar'] = set_avatar_data($sender); |
|
327
|
|
|
|
|
328
|
|
|
$context['avatar_url'] = $modSettings['avatar_url']; |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
// Now go through and actually make with the text. |
|
332
|
|
|
loadLanguage('Alerts'); |
|
333
|
|
|
|
|
334
|
|
|
// Some sprintf formats for generating links/strings. |
|
335
|
|
|
// 'required' is an array of keys in $alert['extra'] that should be used to generate the message, ordered to match the sprintf formats. |
|
336
|
|
|
// 'link' and 'text' are the sprintf formats that will be used when $alert['show_links'] is true or false, respectively. |
|
337
|
|
|
$formats['msg_msg'] = array( |
|
|
|
|
|
|
338
|
|
|
'required' => array('content_subject', 'topic', 'msg'), |
|
339
|
|
|
'link' => '<a href="{scripturl}?topic=%2$d.msg%3$d#msg%3$d">%1$s</a>', |
|
340
|
|
|
'text' => '<strong>%1$s</strong>', |
|
341
|
|
|
); |
|
342
|
|
|
$formats['topic_msg'] = array( |
|
343
|
|
|
'required' => array('content_subject', 'topic', 'topic_suffix'), |
|
344
|
|
|
'link' => '<a href="{scripturl}?topic=%2$d.%3$s">%1$s</a>', |
|
345
|
|
|
'text' => '<strong>%1$s</strong>', |
|
346
|
|
|
); |
|
347
|
|
|
$formats['board_msg'] = array( |
|
348
|
|
|
'required' => array('board_name', 'board'), |
|
349
|
|
|
'link' => '<a href="{scripturl}?board=%2$d.0">%1$s</a>', |
|
350
|
|
|
'text' => '<strong>%1$s</strong>', |
|
351
|
|
|
); |
|
352
|
|
|
$formats['profile_msg'] = array( |
|
353
|
|
|
'required' => array('user_name', 'user_id'), |
|
354
|
|
|
'link' => '<a href="{scripturl}?action=profile;u=%2$d">%1$s</a>', |
|
355
|
|
|
'text' => '<strong>%1$s</strong>', |
|
356
|
|
|
); |
|
357
|
|
|
|
|
358
|
|
|
// Hooks might want to do something snazzy around their own content types - including enforcing permissions if appropriate. |
|
359
|
|
|
call_integration_hook('integrate_fetch_alerts', array(&$alerts, &$formats)); |
|
360
|
|
|
|
|
361
|
|
|
// Substitute $scripturl into the link formats. (Done here to make life easier for hooked mods.) |
|
362
|
|
|
foreach ($formats as &$format_type) |
|
363
|
|
|
$format_type = str_replace('{scripturl}', $scripturl, $format_type); |
|
364
|
|
|
|
|
365
|
|
|
// If we need to check board access, use the correct board access filter for the member in question. |
|
366
|
|
|
if ((!isset($user_info['query_see_board']) || $user_info['id'] != $memID) && (!empty($possible_msgs) || !empty($possible_topics))) |
|
367
|
|
|
$qb = build_query_board($memID); |
|
368
|
|
|
else |
|
369
|
|
|
$qb['query_see_board'] = '{query_see_board}'; |
|
|
|
|
|
|
370
|
|
|
|
|
371
|
|
|
// For anything that needs more info and/or wants us to check board or topic access, let's do that. |
|
372
|
|
|
if (!empty($possible_msgs)) |
|
373
|
|
|
{ |
|
374
|
|
|
$flipped_msgs = array(); |
|
375
|
|
|
foreach ($possible_msgs as $id_alert => $id_msg) |
|
376
|
|
|
{ |
|
377
|
|
|
if (!isset($flipped_msgs[$id_msg])) |
|
378
|
|
|
$flipped_msgs[$id_msg] = array(); |
|
379
|
|
|
|
|
380
|
|
|
$flipped_msgs[$id_msg][] = $id_alert; |
|
381
|
|
|
} |
|
382
|
|
|
|
|
383
|
|
|
$request = $smcFunc['db_query']('', ' |
|
384
|
|
|
SELECT m.id_msg, m.id_topic, m.subject, b.id_board, b.name AS board_name |
|
385
|
|
|
FROM {db_prefix}messages AS m |
|
386
|
|
|
INNER JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board) |
|
387
|
|
|
WHERE ' . $qb['query_see_board'] . ' |
|
388
|
|
|
AND m.id_msg IN ({array_int:msgs}) |
|
389
|
|
|
ORDER BY m.id_msg', |
|
390
|
|
|
array( |
|
391
|
|
|
'msgs' => $possible_msgs, |
|
392
|
|
|
) |
|
393
|
|
|
); |
|
394
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
395
|
|
|
{ |
|
396
|
|
|
foreach ($flipped_msgs[$row['id_msg']] as $id_alert) |
|
397
|
|
|
{ |
|
398
|
|
|
$alerts[$id_alert]['content_data'] = $row; |
|
399
|
|
|
$alerts[$id_alert]['visible'] = true; |
|
400
|
|
|
} |
|
401
|
|
|
} |
|
402
|
|
|
$smcFunc['db_free_result']($request); |
|
403
|
|
|
} |
|
404
|
|
|
if (!empty($possible_topics)) |
|
405
|
|
|
{ |
|
406
|
|
|
$flipped_topics = array(); |
|
407
|
|
|
foreach ($possible_topics as $id_alert => $id_topic) |
|
408
|
|
|
{ |
|
409
|
|
|
if (!isset($flipped_topics[$id_topic])) |
|
410
|
|
|
$flipped_topics[$id_topic] = array(); |
|
411
|
|
|
|
|
412
|
|
|
$flipped_topics[$id_topic][] = $id_alert; |
|
413
|
|
|
} |
|
414
|
|
|
|
|
415
|
|
|
$request = $smcFunc['db_query']('', ' |
|
416
|
|
|
SELECT m.id_msg, t.id_topic, m.subject, b.id_board, b.name AS board_name |
|
417
|
|
|
FROM {db_prefix}topics AS t |
|
418
|
|
|
INNER JOIN {db_prefix}messages AS m ON (t.id_first_msg = m.id_msg) |
|
419
|
|
|
INNER JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board) |
|
420
|
|
|
WHERE ' . $qb['query_see_board'] . ' |
|
421
|
|
|
AND t.id_topic IN ({array_int:topics})', |
|
422
|
|
|
array( |
|
423
|
|
|
'topics' => $possible_topics, |
|
424
|
|
|
) |
|
425
|
|
|
); |
|
426
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
427
|
|
|
{ |
|
428
|
|
|
foreach ($flipped_topics[$row['id_topic']] as $id_alert) |
|
429
|
|
|
{ |
|
430
|
|
|
$alerts[$id_alert]['content_data'] = $row; |
|
431
|
|
|
$alerts[$id_alert]['visible'] = true; |
|
432
|
|
|
} |
|
433
|
|
|
} |
|
434
|
|
|
$smcFunc['db_free_result']($request); |
|
435
|
|
|
} |
|
436
|
|
|
|
|
437
|
|
|
// 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) |
|
438
|
|
|
foreach ($alerts as $id_alert => $dummy) |
|
439
|
|
|
{ |
|
440
|
|
|
// There's no point showing alerts for inaccessible content. |
|
441
|
|
|
if (!$alerts[$id_alert]['visible']) |
|
442
|
|
|
{ |
|
443
|
|
|
unset($alerts[$id_alert]); |
|
444
|
|
|
continue; |
|
445
|
|
|
} |
|
446
|
|
|
else |
|
447
|
|
|
unset($alerts[$id_alert]['visible']); |
|
448
|
|
|
|
|
449
|
|
|
// Did a mod already take care of this one? |
|
450
|
|
|
if (!empty($alerts[$id_alert]['text'])) |
|
451
|
|
|
continue; |
|
452
|
|
|
|
|
453
|
|
|
// For developer convenience. |
|
454
|
|
|
$alert = &$alerts[$id_alert]; |
|
455
|
|
|
|
|
456
|
|
|
// The info in extra might outdated if the topic was moved, the message's subject was changed, etc. |
|
457
|
|
|
if (!empty($alert['content_data'])) |
|
458
|
|
|
{ |
|
459
|
|
|
$data = $alert['content_data']; |
|
460
|
|
|
|
|
461
|
|
|
// Make sure msg, topic, and board info are correct. |
|
462
|
|
|
$patterns = array(); |
|
463
|
|
|
$replacements = array(); |
|
464
|
|
|
foreach (array('msg', 'topic', 'board') as $item) |
|
465
|
|
|
{ |
|
466
|
|
|
if (isset($data['id_' . $item])) |
|
467
|
|
|
{ |
|
468
|
|
|
$separator = $item == 'msg' ? '=?' : '='; |
|
469
|
|
|
|
|
470
|
|
|
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) |
|
471
|
|
|
{ |
|
472
|
|
|
$patterns[] = '/\b' . $item . $separator . '\d+/'; |
|
473
|
|
|
$replacements[] = $item . $separator . $data['id_' . $item]; |
|
474
|
|
|
} |
|
475
|
|
|
|
|
476
|
|
|
$alert['extra'][$item] = $data['id_' . $item]; |
|
477
|
|
|
} |
|
478
|
|
|
} |
|
479
|
|
|
if (!empty($patterns)) |
|
480
|
|
|
$alert['extra']['content_link'] = preg_replace($patterns, $replacements, $alert['extra']['content_link']); |
|
481
|
|
|
|
|
482
|
|
|
// Make sure the subject is correct. |
|
483
|
|
|
if (isset($data['subject'])) |
|
484
|
|
|
$alert['extra']['content_subject'] = $data['subject']; |
|
485
|
|
|
|
|
486
|
|
|
// Keep track of this so we can use it below. |
|
487
|
|
|
if (isset($data['board_name'])) |
|
488
|
|
|
$alert['extra']['board_name'] = $data['board_name']; |
|
489
|
|
|
|
|
490
|
|
|
unset($alert['content_data']); |
|
491
|
|
|
} |
|
492
|
|
|
|
|
493
|
|
|
// Do we want to link to the topic in general or the new messages specifically? |
|
494
|
|
|
if (isset($possible_topics[$id_alert]) && in_array($alert['content_action'], array('reply', 'topic', 'unapproved_reply'))) |
|
495
|
|
|
$alert['extra']['topic_suffix'] = 'new;topicseen#new'; |
|
496
|
|
|
elseif (isset($alert['extra']['topic'])) |
|
497
|
|
|
$alert['extra']['topic_suffix'] = '0'; |
|
498
|
|
|
|
|
499
|
|
|
// Make sure profile alerts have what they need. |
|
500
|
|
|
if (in_array($id_alert, $profile_alerts)) |
|
501
|
|
|
{ |
|
502
|
|
|
if (empty($alert['extra']['user_id'])) |
|
503
|
|
|
$alert['extra']['user_id'] = $alert['content_id']; |
|
504
|
|
|
|
|
505
|
|
|
if (isset($user_profile[$alert['extra']['user_id']])) |
|
506
|
|
|
$alert['extra']['user_name'] = $user_profile[$alert['extra']['user_id']]['real_name']; |
|
507
|
|
|
} |
|
508
|
|
|
|
|
509
|
|
|
// If we loaded the sender's profile, we may as well use it. |
|
510
|
|
|
$sender_id = !empty($alert['sender_id']) ? $alert['sender_id'] : 0; |
|
511
|
|
|
if (isset($user_profile[$sender_id])) |
|
512
|
|
|
$alert['sender_name'] = $user_profile[$sender_id]['real_name']; |
|
513
|
|
|
|
|
514
|
|
|
// If requested, include the sender's avatar data. |
|
515
|
|
|
if ($with_avatar && !empty($senders[$sender_id])) |
|
516
|
|
|
$alert['sender'] = $senders[$sender_id]; |
|
517
|
|
|
|
|
518
|
|
|
// Next, build the message strings. |
|
519
|
|
|
foreach ($formats as $msg_type => $format_info) |
|
520
|
|
|
{ |
|
521
|
|
|
// Get the values to use in the formatted string, in the right order. |
|
522
|
|
|
$msg_values = array_replace( |
|
523
|
|
|
array_fill_keys($format_info['required'], ''), |
|
524
|
|
|
array_intersect_key($alert['extra'], array_flip($format_info['required'])) |
|
525
|
|
|
); |
|
526
|
|
|
|
|
527
|
|
|
// Assuming all required values are present, build the message. |
|
528
|
|
|
if (!in_array('', $msg_values)) |
|
529
|
|
|
$alert['extra'][$msg_type] = vsprintf($formats[$msg_type][$alert['show_links'] ? 'link' : 'text'], $msg_values); |
|
530
|
|
|
|
|
531
|
|
|
elseif (in_array($msg_type, array('msg_msg', 'topic_msg', 'board_msg'))) |
|
532
|
|
|
$alert['extra'][$msg_type] = $txt[$msg_type == 'board_msg' ? 'board_na' : 'topic_na']; |
|
533
|
|
|
else |
|
534
|
|
|
$alert['extra'][$msg_type] = '(' . $txt['not_applicable'] . ')'; |
|
535
|
|
|
} |
|
536
|
|
|
|
|
537
|
|
|
// Show the formatted time in alerts about subscriptions. |
|
538
|
|
|
if ($alert['content_type'] == 'paidsubs' && isset($alert['extra']['end_time'])) |
|
539
|
|
|
{ |
|
540
|
|
|
// If the subscription already expired, say so. |
|
541
|
|
|
if ($alert['extra']['end_time'] < time()) |
|
542
|
|
|
$alert['content_action'] = 'expired'; |
|
543
|
|
|
|
|
544
|
|
|
// Present a nicely formatted date. |
|
545
|
|
|
$alert['extra']['end_time'] = timeformat($alert['extra']['end_time']); |
|
546
|
|
|
} |
|
547
|
|
|
|
|
548
|
|
|
// Now set the main URL that this alert should take the user to. |
|
549
|
|
|
$alert['target_href'] = ''; |
|
550
|
|
|
|
|
551
|
|
|
// Priority goes to explicitly specified links. |
|
552
|
|
|
if (isset($alert['extra']['content_link'])) |
|
553
|
|
|
$alert['target_href'] = $alert['extra']['content_link']; |
|
554
|
|
|
|
|
555
|
|
|
elseif (isset($alert['extra']['report_link'])) |
|
556
|
|
|
$alert['target_href'] = $scripturl . $alert['extra']['report_link']; |
|
557
|
|
|
|
|
558
|
|
|
// Next, try determining the link based on the content action. |
|
559
|
|
|
if (empty($alert['target_href']) && in_array($alert['content_action'], array('register_approval', 'group_request', 'buddy_request'))) |
|
560
|
|
|
{ |
|
561
|
|
|
switch ($alert['content_action']) |
|
562
|
|
|
{ |
|
563
|
|
|
case 'register_approval': |
|
564
|
|
|
$alert['target_href'] = $scripturl . '?action=admin;area=viewmembers;sa=browse;type=approve'; |
|
565
|
|
|
break; |
|
566
|
|
|
|
|
567
|
|
|
case 'group_request': |
|
568
|
|
|
$alert['target_href'] = $scripturl . '?action=moderate;area=groups;sa=requests'; |
|
569
|
|
|
break; |
|
570
|
|
|
|
|
571
|
|
|
case 'buddy_request': |
|
572
|
|
|
if (!empty($alert['id_member_started'])) |
|
573
|
|
|
$alert['target_href'] = $scripturl . '?action=profile;u=' . $alert['id_member_started']; |
|
574
|
|
|
break; |
|
575
|
|
|
|
|
576
|
|
|
default: |
|
577
|
|
|
break; |
|
578
|
|
|
} |
|
579
|
|
|
} |
|
580
|
|
|
|
|
581
|
|
|
// Or maybe we can determine the link based on the content type. |
|
582
|
|
|
if (empty($alert['target_href']) && in_array($alert['content_type'], array('msg', 'member', 'event'))) |
|
583
|
|
|
{ |
|
584
|
|
|
switch ($alert['content_type']) |
|
585
|
|
|
{ |
|
586
|
|
|
case 'msg': |
|
587
|
|
|
if (!empty($alert['content_id'])) |
|
588
|
|
|
$alert['target_href'] = $scripturl . '?msg=' . $alert['content_id']; |
|
589
|
|
|
break; |
|
590
|
|
|
|
|
591
|
|
|
case 'member': |
|
592
|
|
|
if (!empty($alert['id_member_started'])) |
|
593
|
|
|
$alert['target_href'] = $scripturl . '?action=profile;u=' . $alert['id_member_started']; |
|
594
|
|
|
break; |
|
595
|
|
|
|
|
596
|
|
|
case 'event': |
|
597
|
|
|
if (!empty($alert['extra']['event_id'])) |
|
598
|
|
|
$alert['target_href'] = $scripturl . '?action=calendar;event=' . $alert['extra']['event_id']; |
|
599
|
|
|
break; |
|
600
|
|
|
|
|
601
|
|
|
default: |
|
602
|
|
|
break; |
|
603
|
|
|
} |
|
604
|
|
|
|
|
605
|
|
|
} |
|
606
|
|
|
|
|
607
|
|
|
// Finally, set this alert's text string. |
|
608
|
|
|
$string = 'alert_' . $alert['content_type'] . '_' . $alert['content_action']; |
|
609
|
|
|
|
|
610
|
|
|
// This kludge exists because the alert content_types prior to 2.1 RC3 were a bit haphazard. |
|
611
|
|
|
// This can be removed once all the translated language files have been updated. |
|
612
|
|
|
if (!isset($txt[$string])) |
|
613
|
|
|
{ |
|
614
|
|
|
if (strpos($alert['content_action'], 'unapproved_') === 0) |
|
615
|
|
|
$string = 'alert_' . $alert['content_action']; |
|
616
|
|
|
|
|
617
|
|
|
if ($alert['content_type'] === 'member' && in_array($alert['content_action'], array('report', 'report_reply'))) |
|
618
|
|
|
$string = 'alert_profile_' . $alert['content_action']; |
|
619
|
|
|
|
|
620
|
|
|
if ($alert['content_type'] === 'member' && $alert['content_action'] === 'buddy_request') |
|
621
|
|
|
$string = 'alert_buddy_' . $alert['content_action']; |
|
622
|
|
|
} |
|
623
|
|
|
|
|
624
|
|
|
if (isset($txt[$string])) |
|
625
|
|
|
{ |
|
626
|
|
|
$substitutions = array( |
|
627
|
|
|
'{scripturl}' => $scripturl, |
|
628
|
|
|
'{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>', |
|
629
|
|
|
); |
|
630
|
|
|
|
|
631
|
|
|
if (is_array($alert['extra'])) |
|
632
|
|
|
{ |
|
633
|
|
|
foreach ($alert['extra'] as $k => $v) |
|
634
|
|
|
$substitutions['{' . $k . '}'] = $v; |
|
635
|
|
|
} |
|
636
|
|
|
|
|
637
|
|
|
$alert['text'] = strtr($txt[$string], $substitutions); |
|
638
|
|
|
} |
|
639
|
|
|
|
|
640
|
|
|
// Unset the reference variable to avoid any surprises in subsequent loops. |
|
641
|
|
|
unset($alert); |
|
642
|
|
|
} |
|
643
|
|
|
|
|
644
|
|
|
return $alerts; |
|
645
|
|
|
} |
|
646
|
|
|
|
|
647
|
|
|
/** |
|
648
|
|
|
* Shows all alerts for a member |
|
649
|
|
|
* |
|
650
|
|
|
* @param int $memID The ID of the member |
|
651
|
|
|
*/ |
|
652
|
|
|
function showAlerts($memID) |
|
653
|
|
|
{ |
|
654
|
|
|
global $context, $smcFunc, $txt, $sourcedir, $scripturl, $options; |
|
655
|
|
|
|
|
656
|
|
|
require_once($sourcedir . '/Profile-Modify.php'); |
|
657
|
|
|
|
|
658
|
|
|
// Are we opening a specific alert? (i.e.: ?action=profile;area=showalerts;alert=12345) |
|
659
|
|
|
if (!empty($_REQUEST['alert'])) |
|
660
|
|
|
{ |
|
661
|
|
|
$alert_id = (int) $_REQUEST['alert']; |
|
662
|
|
|
$alerts = fetch_alerts($memID, $alert_id); |
|
663
|
|
|
$alert = array_pop($alerts); |
|
664
|
|
|
|
|
665
|
|
|
/* |
|
666
|
|
|
* MOD AUTHORS: |
|
667
|
|
|
* To control this redirect, use the 'integrate_fetch_alerts' hook to |
|
668
|
|
|
* set the value of $alert['extra']['content_link'], which will become |
|
669
|
|
|
* the value for $alert['target_href']. |
|
670
|
|
|
*/ |
|
671
|
|
|
|
|
672
|
|
|
// In case it failed to determine this alert's link |
|
673
|
|
|
if (empty($alert['target_href'])) |
|
674
|
|
|
redirectexit('action=profile;area=showalerts'); |
|
675
|
|
|
|
|
676
|
|
|
// Mark the alert as read while we're at it. |
|
677
|
|
|
alert_mark($memID, $alert_id, 1); |
|
678
|
|
|
|
|
679
|
|
|
// Take the user to the content |
|
680
|
|
|
redirectexit($alert['target_href']); |
|
681
|
|
|
} |
|
682
|
|
|
|
|
683
|
|
|
// Prepare the pagination vars. |
|
684
|
|
|
$maxIndex = 10; |
|
685
|
|
|
$context['start'] = (int) isset($_REQUEST['start']) ? $_REQUEST['start'] : 0; |
|
686
|
|
|
$count = alert_count($memID); |
|
687
|
|
|
|
|
688
|
|
|
// Fix invalid 'start' offsets. |
|
689
|
|
|
if ($context['start'] > $count) |
|
690
|
|
|
$context['start'] = $count - ($count % $maxIndex); |
|
691
|
|
|
else |
|
692
|
|
|
$context['start'] = $context['start'] - ($context['start'] % $maxIndex); |
|
693
|
|
|
|
|
694
|
|
|
// Get the alerts. |
|
695
|
|
|
$context['alerts'] = fetch_alerts($memID, true, $maxIndex, $context['start'], true, true); |
|
|
|
|
|
|
696
|
|
|
$toMark = false; |
|
697
|
|
|
$action = ''; |
|
698
|
|
|
|
|
699
|
|
|
// Are we using checkboxes? |
|
700
|
|
|
$context['showCheckboxes'] = !empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1; |
|
701
|
|
|
|
|
702
|
|
|
// Create the pagination. |
|
703
|
|
|
$context['pagination'] = constructPageIndex($scripturl . '?action=profile;area=showalerts;u=' . $memID, $context['start'], $count, $maxIndex, false); |
|
704
|
|
|
|
|
705
|
|
|
// Set some JavaScript for checking all alerts at once. |
|
706
|
|
|
if ($context['showCheckboxes']) |
|
707
|
|
|
addInlineJavaScript(' |
|
708
|
|
|
$(function(){ |
|
709
|
|
|
$(\'#select_all\').on(\'change\', function() { |
|
710
|
|
|
var checkboxes = $(\'ul.quickbuttons\').find(\':checkbox\'); |
|
711
|
|
|
if($(this).prop(\'checked\')) { |
|
712
|
|
|
checkboxes.prop(\'checked\', true); |
|
713
|
|
|
} |
|
714
|
|
|
else { |
|
715
|
|
|
checkboxes.prop(\'checked\', false); |
|
716
|
|
|
} |
|
717
|
|
|
}); |
|
718
|
|
|
});', true); |
|
719
|
|
|
|
|
720
|
|
|
// The quickbuttons |
|
721
|
|
|
foreach ($context['alerts'] as $id => $alert) |
|
722
|
|
|
{ |
|
723
|
|
|
$context['alerts'][$id]['quickbuttons'] = array( |
|
724
|
|
|
'delete' => array( |
|
725
|
|
|
'label' => $txt['delete'], |
|
726
|
|
|
'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'] : ''), |
|
727
|
|
|
'class' => 'you_sure', |
|
728
|
|
|
'icon' => 'remove_button' |
|
729
|
|
|
), |
|
730
|
|
|
'mark' => array( |
|
731
|
|
|
'label' => $alert['is_read'] != 0 ? $txt['mark_unread'] : $txt['mark_read_short'], |
|
732
|
|
|
'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'] : ''), |
|
733
|
|
|
'icon' => $alert['is_read'] != 0 ? 'unread_button' : 'read_button', |
|
734
|
|
|
), |
|
735
|
|
|
'view' => array( |
|
736
|
|
|
'label' => $txt['view'], |
|
737
|
|
|
'href' => $alert['target_href'], |
|
738
|
|
|
'icon' => 'move', |
|
739
|
|
|
), |
|
740
|
|
|
'quickmod' => array( |
|
741
|
|
|
'content' => '<input type="checkbox" name="mark[' . $id . ']" value="' . $id . '">', |
|
742
|
|
|
'show' => $context['showCheckboxes'] |
|
743
|
|
|
) |
|
744
|
|
|
); |
|
745
|
|
|
} |
|
746
|
|
|
|
|
747
|
|
|
// The Delete all unread link. |
|
748
|
|
|
$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'] : ''); |
|
749
|
|
|
|
|
750
|
|
|
// Set a nice message. |
|
751
|
|
|
if (!empty($_SESSION['update_message'])) |
|
752
|
|
|
{ |
|
753
|
|
|
$context['update_message'] = $txt['profile_updated_own']; |
|
754
|
|
|
unset($_SESSION['update_message']); |
|
755
|
|
|
} |
|
756
|
|
|
|
|
757
|
|
|
// Saving multiple changes? |
|
758
|
|
|
if (isset($_GET['save']) && !empty($_POST['mark'])) |
|
759
|
|
|
{ |
|
760
|
|
|
// Get the values. |
|
761
|
|
|
$toMark = array_map('intval', (array) $_POST['mark']); |
|
762
|
|
|
|
|
763
|
|
|
// Which action? |
|
764
|
|
|
$action = !empty($_POST['mark_as']) ? $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_POST['mark_as'])) : ''; |
|
765
|
|
|
} |
|
766
|
|
|
|
|
767
|
|
|
// A single change. |
|
768
|
|
|
if (!empty($_GET['do']) && !empty($_GET['aid'])) |
|
769
|
|
|
{ |
|
770
|
|
|
$toMark = (int) $_GET['aid']; |
|
771
|
|
|
$action = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_GET['do'])); |
|
772
|
|
|
} |
|
773
|
|
|
// Delete all read alerts. |
|
774
|
|
|
elseif (!empty($_GET['do']) && $_GET['do'] === 'purge') |
|
775
|
|
|
$action = 'purge'; |
|
776
|
|
|
|
|
777
|
|
|
// Save the changes. |
|
778
|
|
|
if (!empty($action) && (!empty($toMark) || $action === 'purge')) |
|
779
|
|
|
{ |
|
780
|
|
|
checkSession('request'); |
|
781
|
|
|
|
|
782
|
|
|
// Call it! |
|
783
|
|
|
if ($action == 'remove') |
|
784
|
|
|
alert_delete($toMark, $memID); |
|
785
|
|
|
|
|
786
|
|
|
elseif ($action == 'purge') |
|
787
|
|
|
alert_purge($memID); |
|
788
|
|
|
|
|
789
|
|
|
else |
|
790
|
|
|
alert_mark($memID, $toMark, $action == 'read' ? 1 : 0); |
|
791
|
|
|
|
|
792
|
|
|
// Set a nice update message. |
|
793
|
|
|
$_SESSION['update_message'] = true; |
|
794
|
|
|
|
|
795
|
|
|
// Redirect. |
|
796
|
|
|
redirectexit('action=profile;area=showalerts;u=' . $memID . (!empty($context['start']) ? ';start=' . $context['start'] : '')); |
|
797
|
|
|
} |
|
798
|
|
|
} |
|
799
|
|
|
|
|
800
|
|
|
/** |
|
801
|
|
|
* Show all posts by a member |
|
802
|
|
|
* |
|
803
|
|
|
* @todo This function needs to be split up properly. |
|
804
|
|
|
* |
|
805
|
|
|
* @param int $memID The ID of the member |
|
806
|
|
|
*/ |
|
807
|
|
|
function showPosts($memID) |
|
808
|
|
|
{ |
|
809
|
|
|
global $txt, $user_info, $scripturl, $modSettings, $options; |
|
810
|
|
|
global $context, $user_profile, $sourcedir, $smcFunc, $board; |
|
811
|
|
|
|
|
812
|
|
|
// Some initial context. |
|
813
|
|
|
$context['start'] = (int) $_REQUEST['start']; |
|
814
|
|
|
$context['current_member'] = $memID; |
|
815
|
|
|
|
|
816
|
|
|
// Create the tabs for the template. |
|
817
|
|
|
$context[$context['profile_menu_name']]['tab_data'] = array( |
|
818
|
|
|
'title' => $txt['showPosts'], |
|
819
|
|
|
'description' => $txt['showPosts_help'], |
|
820
|
|
|
'icon' => 'profile_hd.png', |
|
821
|
|
|
'tabs' => array( |
|
822
|
|
|
'messages' => array( |
|
823
|
|
|
), |
|
824
|
|
|
'topics' => array( |
|
825
|
|
|
), |
|
826
|
|
|
'unwatchedtopics' => array( |
|
827
|
|
|
), |
|
828
|
|
|
'attach' => array( |
|
829
|
|
|
), |
|
830
|
|
|
), |
|
831
|
|
|
); |
|
832
|
|
|
|
|
833
|
|
|
// Shortcut used to determine which $txt['show*'] string to use for the title, based on the SA |
|
834
|
|
|
$title = array( |
|
835
|
|
|
'attach' => 'Attachments', |
|
836
|
|
|
'unwatchedtopics' => 'Unwatched', |
|
837
|
|
|
'topics' => 'Topics' |
|
838
|
|
|
); |
|
839
|
|
|
|
|
840
|
|
|
// Set the page title |
|
841
|
|
|
if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title)) |
|
842
|
|
|
$context['page_title'] = $txt['show' . $title[$_GET['sa']]]; |
|
843
|
|
|
else |
|
844
|
|
|
$context['page_title'] = $txt['showPosts']; |
|
845
|
|
|
|
|
846
|
|
|
$context['page_title'] .= ' - ' . $user_profile[$memID]['real_name']; |
|
847
|
|
|
|
|
848
|
|
|
// Is the load average too high to allow searching just now? |
|
849
|
|
|
if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) |
|
850
|
|
|
fatal_lang_error('loadavg_show_posts_disabled', false); |
|
851
|
|
|
|
|
852
|
|
|
// If we're specifically dealing with attachments use that function! |
|
853
|
|
|
if (isset($_GET['sa']) && $_GET['sa'] == 'attach') |
|
854
|
|
|
return showAttachments($memID); |
|
855
|
|
|
// Instead, if we're dealing with unwatched topics (and the feature is enabled) use that other function. |
|
856
|
|
|
elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics') |
|
857
|
|
|
return showUnwatched($memID); |
|
|
|
|
|
|
858
|
|
|
|
|
859
|
|
|
// Are we just viewing topics? |
|
860
|
|
|
$context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false; |
|
861
|
|
|
|
|
862
|
|
|
// If just deleting a message, do it and then redirect back. |
|
863
|
|
|
if (isset($_GET['delete']) && !$context['is_topics']) |
|
864
|
|
|
{ |
|
865
|
|
|
checkSession('get'); |
|
866
|
|
|
|
|
867
|
|
|
// We need msg info for logging. |
|
868
|
|
|
$request = $smcFunc['db_query']('', ' |
|
869
|
|
|
SELECT subject, id_member, id_topic, id_board |
|
870
|
|
|
FROM {db_prefix}messages |
|
871
|
|
|
WHERE id_msg = {int:id_msg}', |
|
872
|
|
|
array( |
|
873
|
|
|
'id_msg' => (int) $_GET['delete'], |
|
874
|
|
|
) |
|
875
|
|
|
); |
|
876
|
|
|
$info = $smcFunc['db_fetch_row']($request); |
|
877
|
|
|
$smcFunc['db_free_result']($request); |
|
878
|
|
|
|
|
879
|
|
|
// Trying to remove a message that doesn't exist. |
|
880
|
|
|
if (empty($info)) |
|
881
|
|
|
redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']); |
|
882
|
|
|
|
|
883
|
|
|
// We can be lazy, since removeMessage() will check the permissions for us. |
|
884
|
|
|
require_once($sourcedir . '/RemoveTopic.php'); |
|
885
|
|
|
removeMessage((int) $_GET['delete']); |
|
886
|
|
|
|
|
887
|
|
|
// Add it to the mod log. |
|
888
|
|
|
if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) |
|
889
|
|
|
logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3])); |
|
890
|
|
|
|
|
891
|
|
|
// Back to... where we are now ;). |
|
892
|
|
|
redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']); |
|
893
|
|
|
} |
|
894
|
|
|
|
|
895
|
|
|
// Default to 10. |
|
896
|
|
|
if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) |
|
897
|
|
|
$_REQUEST['viewscount'] = '10'; |
|
898
|
|
|
|
|
899
|
|
|
if ($context['is_topics']) |
|
900
|
|
|
$request = $smcFunc['db_query']('', ' |
|
901
|
|
|
SELECT COUNT(*) |
|
902
|
|
|
FROM {db_prefix}topics AS t' . ' |
|
903
|
|
|
WHERE {query_see_topic_board} |
|
904
|
|
|
AND t.id_member_started = {int:current_member}' . (!empty($board) ? ' |
|
905
|
|
|
AND t.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' |
|
906
|
|
|
AND t.approved = {int:is_approved}'), |
|
907
|
|
|
array( |
|
908
|
|
|
'current_member' => $memID, |
|
909
|
|
|
'is_approved' => 1, |
|
910
|
|
|
'board' => $board, |
|
911
|
|
|
) |
|
912
|
|
|
); |
|
913
|
|
|
else |
|
914
|
|
|
$request = $smcFunc['db_query']('', ' |
|
915
|
|
|
SELECT COUNT(id_msg) |
|
916
|
|
|
FROM {db_prefix}messages AS m |
|
917
|
|
|
WHERE {query_see_message_board} AND m.id_member = {int:current_member}' . (!empty($board) ? ' |
|
918
|
|
|
AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' |
|
919
|
|
|
AND m.approved = {int:is_approved}'), |
|
920
|
|
|
array( |
|
921
|
|
|
'current_member' => $memID, |
|
922
|
|
|
'is_approved' => 1, |
|
923
|
|
|
'board' => $board, |
|
924
|
|
|
) |
|
925
|
|
|
); |
|
926
|
|
|
list ($msgCount) = $smcFunc['db_fetch_row']($request); |
|
927
|
|
|
$smcFunc['db_free_result']($request); |
|
928
|
|
|
|
|
929
|
|
|
$request = $smcFunc['db_query']('', ' |
|
930
|
|
|
SELECT MIN(id_msg), MAX(id_msg) |
|
931
|
|
|
FROM {db_prefix}messages AS m |
|
932
|
|
|
WHERE m.id_member = {int:current_member}' . (!empty($board) ? ' |
|
933
|
|
|
AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' |
|
934
|
|
|
AND m.approved = {int:is_approved}'), |
|
935
|
|
|
array( |
|
936
|
|
|
'current_member' => $memID, |
|
937
|
|
|
'is_approved' => 1, |
|
938
|
|
|
'board' => $board, |
|
939
|
|
|
) |
|
940
|
|
|
); |
|
941
|
|
|
list ($min_msg_member, $max_msg_member) = $smcFunc['db_fetch_row']($request); |
|
942
|
|
|
$smcFunc['db_free_result']($request); |
|
943
|
|
|
|
|
944
|
|
|
$range_limit = ''; |
|
945
|
|
|
|
|
946
|
|
|
if ($context['is_topics']) |
|
947
|
|
|
$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics']; |
|
948
|
|
|
else |
|
949
|
|
|
$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
|
950
|
|
|
|
|
951
|
|
|
$maxIndex = $maxPerPage; |
|
952
|
|
|
|
|
953
|
|
|
// Make sure the starting place makes sense and construct our friend the page index. |
|
954
|
|
|
$context['page_index'] = constructPageIndex($scripturl . '?action=profile;u=' . $memID . ';area=showposts' . ($context['is_topics'] ? ';sa=topics' : '') . (!empty($board) ? ';board=' . $board : ''), $context['start'], $msgCount, $maxIndex); |
|
955
|
|
|
$context['current_page'] = $context['start'] / $maxIndex; |
|
956
|
|
|
|
|
957
|
|
|
// Reverse the query if we're past 50% of the pages for better performance. |
|
958
|
|
|
$start = $context['start']; |
|
959
|
|
|
$reverse = $_REQUEST['start'] > $msgCount / 2; |
|
960
|
|
|
if ($reverse) |
|
961
|
|
|
{ |
|
962
|
|
|
$maxIndex = $msgCount < $context['start'] + $maxPerPage + 1 && $msgCount > $context['start'] ? $msgCount - $context['start'] : $maxPerPage; |
|
963
|
|
|
$start = $msgCount < $context['start'] + $maxPerPage + 1 || $msgCount < $context['start'] + $maxPerPage ? 0 : $msgCount - $context['start'] - $maxPerPage; |
|
964
|
|
|
} |
|
965
|
|
|
|
|
966
|
|
|
// Guess the range of messages to be shown. |
|
967
|
|
|
if ($msgCount > 1000) |
|
968
|
|
|
{ |
|
969
|
|
|
$margin = floor(($max_msg_member - $min_msg_member) * (($start + $maxPerPage) / $msgCount) + .1 * ($max_msg_member - $min_msg_member)); |
|
970
|
|
|
// Make a bigger margin for topics only. |
|
971
|
|
|
if ($context['is_topics']) |
|
972
|
|
|
{ |
|
973
|
|
|
$margin *= 5; |
|
974
|
|
|
$range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin); |
|
975
|
|
|
} |
|
976
|
|
|
else |
|
977
|
|
|
$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin); |
|
978
|
|
|
} |
|
979
|
|
|
|
|
980
|
|
|
// Find this user's posts. The left join on categories somehow makes this faster, weird as it looks. |
|
981
|
|
|
$looped = false; |
|
982
|
|
|
while (true) |
|
983
|
|
|
{ |
|
984
|
|
|
if ($context['is_topics']) |
|
985
|
|
|
{ |
|
986
|
|
|
$request = $smcFunc['db_query']('', ' |
|
987
|
|
|
SELECT |
|
988
|
|
|
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, |
|
989
|
|
|
t.approved, m.body, m.smileys_enabled, m.subject, m.poster_time, m.id_topic, m.id_msg |
|
990
|
|
|
FROM {db_prefix}topics AS t |
|
991
|
|
|
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board) |
|
992
|
|
|
LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat) |
|
993
|
|
|
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg) |
|
994
|
|
|
WHERE t.id_member_started = {int:current_member}' . (!empty($board) ? ' |
|
995
|
|
|
AND t.id_board = {int:board}' : '') . (empty($range_limit) ? '' : ' |
|
996
|
|
|
AND ' . $range_limit) . ' |
|
997
|
|
|
AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' |
|
998
|
|
|
AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . ' |
|
999
|
|
|
ORDER BY t.id_first_msg ' . ($reverse ? 'ASC' : 'DESC') . ' |
|
1000
|
|
|
LIMIT {int:start}, {int:max}', |
|
1001
|
|
|
array( |
|
1002
|
|
|
'current_member' => $memID, |
|
1003
|
|
|
'is_approved' => 1, |
|
1004
|
|
|
'board' => $board, |
|
1005
|
|
|
'start' => $start, |
|
1006
|
|
|
'max' => $maxIndex, |
|
1007
|
|
|
) |
|
1008
|
|
|
); |
|
1009
|
|
|
} |
|
1010
|
|
|
else |
|
1011
|
|
|
{ |
|
1012
|
|
|
$request = $smcFunc['db_query']('', ' |
|
1013
|
|
|
SELECT |
|
1014
|
|
|
b.id_board, b.name AS bname, c.id_cat, c.name AS cname, m.id_topic, m.id_msg, |
|
1015
|
|
|
t.id_member_started, t.id_first_msg, t.id_last_msg, m.body, m.smileys_enabled, |
|
1016
|
|
|
m.subject, m.poster_time, m.approved |
|
1017
|
|
|
FROM {db_prefix}messages AS m |
|
1018
|
|
|
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic) |
|
1019
|
|
|
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board) |
|
1020
|
|
|
LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat) |
|
1021
|
|
|
WHERE m.id_member = {int:current_member}' . (!empty($board) ? ' |
|
1022
|
|
|
AND b.id_board = {int:board}' : '') . (empty($range_limit) ? '' : ' |
|
1023
|
|
|
AND ' . $range_limit) . ' |
|
1024
|
|
|
AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' |
|
1025
|
|
|
AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . ' |
|
1026
|
|
|
ORDER BY m.id_msg ' . ($reverse ? 'ASC' : 'DESC') . ' |
|
1027
|
|
|
LIMIT {int:start}, {int:max}', |
|
1028
|
|
|
array( |
|
1029
|
|
|
'current_member' => $memID, |
|
1030
|
|
|
'is_approved' => 1, |
|
1031
|
|
|
'board' => $board, |
|
1032
|
|
|
'start' => $start, |
|
1033
|
|
|
'max' => $maxIndex, |
|
1034
|
|
|
) |
|
1035
|
|
|
); |
|
1036
|
|
|
} |
|
1037
|
|
|
|
|
1038
|
|
|
// Make sure we quit this loop. |
|
1039
|
|
|
if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped || $range_limit == '') |
|
1040
|
|
|
break; |
|
1041
|
|
|
$looped = true; |
|
1042
|
|
|
$range_limit = ''; |
|
1043
|
|
|
} |
|
1044
|
|
|
|
|
1045
|
|
|
// Start counting at the number of the first message displayed. |
|
1046
|
|
|
$counter = $reverse ? $context['start'] + $maxIndex + 1 : $context['start']; |
|
1047
|
|
|
$context['posts'] = array(); |
|
1048
|
|
|
$board_ids = array('own' => array(), 'any' => array()); |
|
1049
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1050
|
|
|
{ |
|
1051
|
|
|
// Censor.... |
|
1052
|
|
|
censorText($row['body']); |
|
1053
|
|
|
censorText($row['subject']); |
|
1054
|
|
|
|
|
1055
|
|
|
// Do the code. |
|
1056
|
|
|
$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); |
|
1057
|
|
|
|
|
1058
|
|
|
// And the array... |
|
1059
|
|
|
$context['posts'][$counter += $reverse ? -1 : 1] = array( |
|
1060
|
|
|
'body' => $row['body'], |
|
1061
|
|
|
'counter' => $counter, |
|
1062
|
|
|
'category' => array( |
|
1063
|
|
|
'name' => $row['cname'], |
|
1064
|
|
|
'id' => $row['id_cat'] |
|
1065
|
|
|
), |
|
1066
|
|
|
'board' => array( |
|
1067
|
|
|
'name' => $row['bname'], |
|
1068
|
|
|
'id' => $row['id_board'] |
|
1069
|
|
|
), |
|
1070
|
|
|
'topic' => $row['id_topic'], |
|
1071
|
|
|
'subject' => $row['subject'], |
|
1072
|
|
|
'start' => 'msg' . $row['id_msg'], |
|
1073
|
|
|
'time' => timeformat($row['poster_time']), |
|
1074
|
|
|
'timestamp' => forum_time(true, $row['poster_time']), |
|
1075
|
|
|
'id' => $row['id_msg'], |
|
1076
|
|
|
'can_reply' => false, |
|
1077
|
|
|
'can_mark_notify' => !$context['user']['is_guest'], |
|
1078
|
|
|
'can_delete' => false, |
|
1079
|
|
|
'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()), |
|
1080
|
|
|
'approved' => $row['approved'], |
|
1081
|
|
|
'css_class' => $row['approved'] ? 'windowbg' : 'approvebg', |
|
1082
|
|
|
); |
|
1083
|
|
|
|
|
1084
|
|
|
if ($user_info['id'] == $row['id_member_started']) |
|
1085
|
|
|
$board_ids['own'][$row['id_board']][] = $counter; |
|
1086
|
|
|
$board_ids['any'][$row['id_board']][] = $counter; |
|
1087
|
|
|
} |
|
1088
|
|
|
$smcFunc['db_free_result']($request); |
|
1089
|
|
|
|
|
1090
|
|
|
// All posts were retrieved in reverse order, get them right again. |
|
1091
|
|
|
if ($reverse) |
|
1092
|
|
|
$context['posts'] = array_reverse($context['posts'], true); |
|
1093
|
|
|
|
|
1094
|
|
|
// These are all the permissions that are different from board to board.. |
|
1095
|
|
|
if ($context['is_topics']) |
|
1096
|
|
|
$permissions = array( |
|
1097
|
|
|
'own' => array( |
|
1098
|
|
|
'post_reply_own' => 'can_reply', |
|
1099
|
|
|
), |
|
1100
|
|
|
'any' => array( |
|
1101
|
|
|
'post_reply_any' => 'can_reply', |
|
1102
|
|
|
) |
|
1103
|
|
|
); |
|
1104
|
|
|
else |
|
1105
|
|
|
$permissions = array( |
|
1106
|
|
|
'own' => array( |
|
1107
|
|
|
'post_reply_own' => 'can_reply', |
|
1108
|
|
|
'delete_own' => 'can_delete', |
|
1109
|
|
|
), |
|
1110
|
|
|
'any' => array( |
|
1111
|
|
|
'post_reply_any' => 'can_reply', |
|
1112
|
|
|
'delete_any' => 'can_delete', |
|
1113
|
|
|
) |
|
1114
|
|
|
); |
|
1115
|
|
|
|
|
1116
|
|
|
// Create an array for the permissions. |
|
1117
|
|
|
$boards_can = boardsAllowedTo(array_keys(iterator_to_array( |
|
1118
|
|
|
new RecursiveIteratorIterator(new RecursiveArrayIterator($permissions))) |
|
1119
|
|
|
), true, false); |
|
1120
|
|
|
|
|
1121
|
|
|
// For every permission in the own/any lists... |
|
1122
|
|
|
foreach ($permissions as $type => $list) |
|
1123
|
|
|
{ |
|
1124
|
|
|
foreach ($list as $permission => $allowed) |
|
1125
|
|
|
{ |
|
1126
|
|
|
// Get the boards they can do this on... |
|
1127
|
|
|
$boards = $boards_can[$permission]; |
|
1128
|
|
|
|
|
1129
|
|
|
// Hmm, they can do it on all boards, can they? |
|
1130
|
|
|
if (!empty($boards) && $boards[0] == 0) |
|
1131
|
|
|
$boards = array_keys($board_ids[$type]); |
|
1132
|
|
|
|
|
1133
|
|
|
// Now go through each board they can do the permission on. |
|
1134
|
|
|
foreach ($boards as $board_id) |
|
1135
|
|
|
{ |
|
1136
|
|
|
// There aren't any posts displayed from this board. |
|
1137
|
|
|
if (!isset($board_ids[$type][$board_id])) |
|
1138
|
|
|
continue; |
|
1139
|
|
|
|
|
1140
|
|
|
// Set the permission to true ;). |
|
1141
|
|
|
foreach ($board_ids[$type][$board_id] as $counter) |
|
1142
|
|
|
$context['posts'][$counter][$allowed] = true; |
|
1143
|
|
|
} |
|
1144
|
|
|
} |
|
1145
|
|
|
} |
|
1146
|
|
|
|
|
1147
|
|
|
// Clean up after posts that cannot be deleted and quoted. |
|
1148
|
|
|
$quote_enabled = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC'])); |
|
1149
|
|
|
foreach ($context['posts'] as $counter => $dummy) |
|
1150
|
|
|
{ |
|
1151
|
|
|
$context['posts'][$counter]['can_delete'] &= $context['posts'][$counter]['delete_possible']; |
|
1152
|
|
|
$context['posts'][$counter]['can_quote'] = $context['posts'][$counter]['can_reply'] && $quote_enabled; |
|
1153
|
|
|
} |
|
1154
|
|
|
|
|
1155
|
|
|
// Allow last minute changes. |
|
1156
|
|
|
call_integration_hook('integrate_profile_showPosts'); |
|
1157
|
|
|
|
|
1158
|
|
|
foreach ($context['posts'] as $key => $post) |
|
1159
|
|
|
{ |
|
1160
|
|
|
$context['posts'][$key]['quickbuttons'] = array( |
|
1161
|
|
|
'reply' => array( |
|
1162
|
|
|
'label' => $txt['reply'], |
|
1163
|
|
|
'href' => $scripturl.'?action=post;topic='.$post['topic'].'.'.$post['start'], |
|
1164
|
|
|
'icon' => 'reply_button', |
|
1165
|
|
|
'show' => $post['can_reply'] |
|
1166
|
|
|
), |
|
1167
|
|
|
'quote' => array( |
|
1168
|
|
|
'label' => $txt['quote_action'], |
|
1169
|
|
|
'href' => $scripturl.'?action=post;topic='.$post['topic'].'.'.$post['start'].';quote='.$post['id'], |
|
1170
|
|
|
'icon' => 'quote', |
|
1171
|
|
|
'show' => $post['can_quote'] |
|
1172
|
|
|
), |
|
1173
|
|
|
'remove' => array( |
|
1174
|
|
|
'label' => $txt['remove'], |
|
1175
|
|
|
'href' => $scripturl.'?action=deletemsg;msg='.$post['id'].';topic='.$post['topic'].';profile;u='.$context['member']['id'].';start='.$context['start'].';'.$context['session_var'].'='.$context['session_id'], |
|
1176
|
|
|
'javascript' => 'data-confirm="'.$txt['remove_message'].'"', |
|
1177
|
|
|
'class' => 'you_sure', |
|
1178
|
|
|
'icon' => 'remove_button', |
|
1179
|
|
|
'show' => $post['can_delete'] |
|
1180
|
|
|
) |
|
1181
|
|
|
); |
|
1182
|
|
|
} |
|
1183
|
|
|
} |
|
1184
|
|
|
|
|
1185
|
|
|
/** |
|
1186
|
|
|
* Show all the attachments belonging to a member. |
|
1187
|
|
|
* |
|
1188
|
|
|
* @param int $memID The ID of the member |
|
1189
|
|
|
*/ |
|
1190
|
|
|
function showAttachments($memID) |
|
1191
|
|
|
{ |
|
1192
|
|
|
global $txt, $scripturl, $modSettings; |
|
1193
|
|
|
global $sourcedir; |
|
1194
|
|
|
|
|
1195
|
|
|
// OBEY permissions! |
|
1196
|
|
|
$boardsAllowed = boardsAllowedTo('view_attachments'); |
|
1197
|
|
|
|
|
1198
|
|
|
// Make sure we can't actually see anything... |
|
1199
|
|
|
if (empty($boardsAllowed)) |
|
1200
|
|
|
$boardsAllowed = array(-1); |
|
1201
|
|
|
|
|
1202
|
|
|
require_once($sourcedir . '/Subs-List.php'); |
|
1203
|
|
|
|
|
1204
|
|
|
// This is all the information required to list attachments. |
|
1205
|
|
|
$listOptions = array( |
|
1206
|
|
|
'id' => 'attachments', |
|
1207
|
|
|
'width' => '100%', |
|
1208
|
|
|
'items_per_page' => $modSettings['defaultMaxListItems'], |
|
1209
|
|
|
'no_items_label' => $txt['show_attachments_none'], |
|
1210
|
|
|
'base_href' => $scripturl . '?action=profile;area=showposts;sa=attach;u=' . $memID, |
|
1211
|
|
|
'default_sort_col' => 'filename', |
|
1212
|
|
|
'get_items' => array( |
|
1213
|
|
|
'function' => 'list_getAttachments', |
|
1214
|
|
|
'params' => array( |
|
1215
|
|
|
$boardsAllowed, |
|
1216
|
|
|
$memID, |
|
1217
|
|
|
), |
|
1218
|
|
|
), |
|
1219
|
|
|
'get_count' => array( |
|
1220
|
|
|
'function' => 'list_getNumAttachments', |
|
1221
|
|
|
'params' => array( |
|
1222
|
|
|
$boardsAllowed, |
|
1223
|
|
|
$memID, |
|
1224
|
|
|
), |
|
1225
|
|
|
), |
|
1226
|
|
|
'data_check' => array( |
|
1227
|
|
|
'class' => function($data) |
|
1228
|
|
|
{ |
|
1229
|
|
|
return $data['approved'] ? '' : 'approvebg'; |
|
1230
|
|
|
} |
|
1231
|
|
|
), |
|
1232
|
|
|
'columns' => array( |
|
1233
|
|
|
'filename' => array( |
|
1234
|
|
|
'header' => array( |
|
1235
|
|
|
'value' => $txt['show_attach_filename'], |
|
1236
|
|
|
'class' => 'lefttext', |
|
1237
|
|
|
'style' => 'width: 25%;', |
|
1238
|
|
|
), |
|
1239
|
|
|
'data' => array( |
|
1240
|
|
|
'sprintf' => array( |
|
1241
|
|
|
'format' => '<a href="' . $scripturl . '?action=dlattach;topic=%1$d.0;attach=%2$d">%3$s</a>', |
|
1242
|
|
|
'params' => array( |
|
1243
|
|
|
'topic' => true, |
|
1244
|
|
|
'id' => true, |
|
1245
|
|
|
'filename' => false, |
|
1246
|
|
|
), |
|
1247
|
|
|
), |
|
1248
|
|
|
), |
|
1249
|
|
|
'sort' => array( |
|
1250
|
|
|
'default' => 'a.filename', |
|
1251
|
|
|
'reverse' => 'a.filename DESC', |
|
1252
|
|
|
), |
|
1253
|
|
|
), |
|
1254
|
|
|
'downloads' => array( |
|
1255
|
|
|
'header' => array( |
|
1256
|
|
|
'value' => $txt['show_attach_downloads'], |
|
1257
|
|
|
'style' => 'width: 12%;', |
|
1258
|
|
|
), |
|
1259
|
|
|
'data' => array( |
|
1260
|
|
|
'db' => 'downloads', |
|
1261
|
|
|
'comma_format' => true, |
|
1262
|
|
|
), |
|
1263
|
|
|
'sort' => array( |
|
1264
|
|
|
'default' => 'a.downloads', |
|
1265
|
|
|
'reverse' => 'a.downloads DESC', |
|
1266
|
|
|
), |
|
1267
|
|
|
), |
|
1268
|
|
|
'subject' => array( |
|
1269
|
|
|
'header' => array( |
|
1270
|
|
|
'value' => $txt['message'], |
|
1271
|
|
|
'class' => 'lefttext', |
|
1272
|
|
|
'style' => 'width: 30%;', |
|
1273
|
|
|
), |
|
1274
|
|
|
'data' => array( |
|
1275
|
|
|
'sprintf' => array( |
|
1276
|
|
|
'format' => '<a href="' . $scripturl . '?msg=%1$d">%2$s</a>', |
|
1277
|
|
|
'params' => array( |
|
1278
|
|
|
'msg' => true, |
|
1279
|
|
|
'subject' => false, |
|
1280
|
|
|
), |
|
1281
|
|
|
), |
|
1282
|
|
|
), |
|
1283
|
|
|
'sort' => array( |
|
1284
|
|
|
'default' => 'm.subject', |
|
1285
|
|
|
'reverse' => 'm.subject DESC', |
|
1286
|
|
|
), |
|
1287
|
|
|
), |
|
1288
|
|
|
'posted' => array( |
|
1289
|
|
|
'header' => array( |
|
1290
|
|
|
'value' => $txt['show_attach_posted'], |
|
1291
|
|
|
'class' => 'lefttext', |
|
1292
|
|
|
), |
|
1293
|
|
|
'data' => array( |
|
1294
|
|
|
'db' => 'posted', |
|
1295
|
|
|
'timeformat' => true, |
|
1296
|
|
|
), |
|
1297
|
|
|
'sort' => array( |
|
1298
|
|
|
'default' => 'm.poster_time', |
|
1299
|
|
|
'reverse' => 'm.poster_time DESC', |
|
1300
|
|
|
), |
|
1301
|
|
|
), |
|
1302
|
|
|
), |
|
1303
|
|
|
); |
|
1304
|
|
|
|
|
1305
|
|
|
// Create the request list. |
|
1306
|
|
|
createList($listOptions); |
|
1307
|
|
|
} |
|
1308
|
|
|
|
|
1309
|
|
|
/** |
|
1310
|
|
|
* Get a list of attachments for a member. Callback for the list in showAttachments() |
|
1311
|
|
|
* |
|
1312
|
|
|
* @param int $start Which item to start with (for pagination purposes) |
|
1313
|
|
|
* @param int $items_per_page How many items to show on each page |
|
1314
|
|
|
* @param string $sort A string indicating how to sort the results |
|
1315
|
|
|
* @param array $boardsAllowed An array containing the IDs of the boards they can see |
|
1316
|
|
|
* @param int $memID The ID of the member |
|
1317
|
|
|
* @return array An array of information about the attachments |
|
1318
|
|
|
*/ |
|
1319
|
|
|
function list_getAttachments($start, $items_per_page, $sort, $boardsAllowed, $memID) |
|
1320
|
|
|
{ |
|
1321
|
|
|
global $smcFunc, $board, $modSettings, $context; |
|
1322
|
|
|
|
|
1323
|
|
|
// Retrieve some attachments. |
|
1324
|
|
|
$request = $smcFunc['db_query']('', ' |
|
1325
|
|
|
SELECT a.id_attach, a.id_msg, a.filename, a.downloads, a.approved, m.id_msg, m.id_topic, |
|
1326
|
|
|
m.id_board, m.poster_time, m.subject, b.name |
|
1327
|
|
|
FROM {db_prefix}attachments AS a |
|
1328
|
|
|
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) |
|
1329
|
|
|
INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board}) |
|
1330
|
|
|
WHERE a.attachment_type = {int:attachment_type} |
|
1331
|
|
|
AND a.id_msg != {int:no_message} |
|
1332
|
|
|
AND m.id_member = {int:current_member}' . (!empty($board) ? ' |
|
1333
|
|
|
AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? ' |
|
1334
|
|
|
AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' |
|
1335
|
|
|
AND m.approved = {int:is_approved}') . ' |
|
1336
|
|
|
ORDER BY {raw:sort} |
|
1337
|
|
|
LIMIT {int:offset}, {int:limit}', |
|
1338
|
|
|
array( |
|
1339
|
|
|
'boards_list' => $boardsAllowed, |
|
1340
|
|
|
'attachment_type' => 0, |
|
1341
|
|
|
'no_message' => 0, |
|
1342
|
|
|
'current_member' => $memID, |
|
1343
|
|
|
'is_approved' => 1, |
|
1344
|
|
|
'board' => $board, |
|
1345
|
|
|
'sort' => $sort, |
|
1346
|
|
|
'offset' => $start, |
|
1347
|
|
|
'limit' => $items_per_page, |
|
1348
|
|
|
) |
|
1349
|
|
|
); |
|
1350
|
|
|
$attachments = array(); |
|
1351
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1352
|
|
|
$attachments[] = array( |
|
1353
|
|
|
'id' => $row['id_attach'], |
|
1354
|
|
|
'filename' => $row['filename'], |
|
1355
|
|
|
'downloads' => $row['downloads'], |
|
1356
|
|
|
'subject' => censorText($row['subject']), |
|
1357
|
|
|
'posted' => $row['poster_time'], |
|
1358
|
|
|
'msg' => $row['id_msg'], |
|
1359
|
|
|
'topic' => $row['id_topic'], |
|
1360
|
|
|
'board' => $row['id_board'], |
|
1361
|
|
|
'board_name' => $row['name'], |
|
1362
|
|
|
'approved' => $row['approved'], |
|
1363
|
|
|
); |
|
1364
|
|
|
|
|
1365
|
|
|
$smcFunc['db_free_result']($request); |
|
1366
|
|
|
|
|
1367
|
|
|
return $attachments; |
|
1368
|
|
|
} |
|
1369
|
|
|
|
|
1370
|
|
|
/** |
|
1371
|
|
|
* Gets the total number of attachments for a member |
|
1372
|
|
|
* |
|
1373
|
|
|
* @param array $boardsAllowed An array of the IDs of the boards they can see |
|
1374
|
|
|
* @param int $memID The ID of the member |
|
1375
|
|
|
* @return int The number of attachments |
|
1376
|
|
|
*/ |
|
1377
|
|
|
function list_getNumAttachments($boardsAllowed, $memID) |
|
1378
|
|
|
{ |
|
1379
|
|
|
global $board, $smcFunc, $modSettings, $context; |
|
1380
|
|
|
|
|
1381
|
|
|
// Get the total number of attachments they have posted. |
|
1382
|
|
|
$request = $smcFunc['db_query']('', ' |
|
1383
|
|
|
SELECT COUNT(*) |
|
1384
|
|
|
FROM {db_prefix}attachments AS a |
|
1385
|
|
|
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) |
|
1386
|
|
|
INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board}) |
|
1387
|
|
|
WHERE a.attachment_type = {int:attachment_type} |
|
1388
|
|
|
AND a.id_msg != {int:no_message} |
|
1389
|
|
|
AND m.id_member = {int:current_member}' . (!empty($board) ? ' |
|
1390
|
|
|
AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? ' |
|
1391
|
|
|
AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : ' |
|
1392
|
|
|
AND m.approved = {int:is_approved}'), |
|
1393
|
|
|
array( |
|
1394
|
|
|
'boards_list' => $boardsAllowed, |
|
1395
|
|
|
'attachment_type' => 0, |
|
1396
|
|
|
'no_message' => 0, |
|
1397
|
|
|
'current_member' => $memID, |
|
1398
|
|
|
'is_approved' => 1, |
|
1399
|
|
|
'board' => $board, |
|
1400
|
|
|
) |
|
1401
|
|
|
); |
|
1402
|
|
|
list ($attachCount) = $smcFunc['db_fetch_row']($request); |
|
1403
|
|
|
$smcFunc['db_free_result']($request); |
|
1404
|
|
|
|
|
1405
|
|
|
return $attachCount; |
|
1406
|
|
|
} |
|
1407
|
|
|
|
|
1408
|
|
|
/** |
|
1409
|
|
|
* Show all the unwatched topics. |
|
1410
|
|
|
* |
|
1411
|
|
|
* @param int $memID The ID of the member |
|
1412
|
|
|
*/ |
|
1413
|
|
|
function showUnwatched($memID) |
|
1414
|
|
|
{ |
|
1415
|
|
|
global $txt, $user_info, $scripturl, $modSettings, $context, $options, $sourcedir; |
|
1416
|
|
|
|
|
1417
|
|
|
// Only the owner can see the list (if the function is enabled of course) |
|
1418
|
|
|
if ($user_info['id'] != $memID) |
|
1419
|
|
|
return; |
|
1420
|
|
|
|
|
1421
|
|
|
require_once($sourcedir . '/Subs-List.php'); |
|
1422
|
|
|
|
|
1423
|
|
|
// And here they are: the topics you don't like |
|
1424
|
|
|
$listOptions = array( |
|
1425
|
|
|
'id' => 'unwatched_topics', |
|
1426
|
|
|
'width' => '100%', |
|
1427
|
|
|
'items_per_page' => (empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page'])) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'], |
|
1428
|
|
|
'no_items_label' => $txt['unwatched_topics_none'], |
|
1429
|
|
|
'base_href' => $scripturl . '?action=profile;area=showposts;sa=unwatchedtopics;u=' . $memID, |
|
1430
|
|
|
'default_sort_col' => 'started_on', |
|
1431
|
|
|
'get_items' => array( |
|
1432
|
|
|
'function' => 'list_getUnwatched', |
|
1433
|
|
|
'params' => array( |
|
1434
|
|
|
$memID, |
|
1435
|
|
|
), |
|
1436
|
|
|
), |
|
1437
|
|
|
'get_count' => array( |
|
1438
|
|
|
'function' => 'list_getNumUnwatched', |
|
1439
|
|
|
'params' => array( |
|
1440
|
|
|
$memID, |
|
1441
|
|
|
), |
|
1442
|
|
|
), |
|
1443
|
|
|
'columns' => array( |
|
1444
|
|
|
'subject' => array( |
|
1445
|
|
|
'header' => array( |
|
1446
|
|
|
'value' => $txt['subject'], |
|
1447
|
|
|
'class' => 'lefttext', |
|
1448
|
|
|
'style' => 'width: 30%;', |
|
1449
|
|
|
), |
|
1450
|
|
|
'data' => array( |
|
1451
|
|
|
'sprintf' => array( |
|
1452
|
|
|
'format' => '<a href="' . $scripturl . '?topic=%1$d.0">%2$s</a>', |
|
1453
|
|
|
'params' => array( |
|
1454
|
|
|
'id_topic' => false, |
|
1455
|
|
|
'subject' => false, |
|
1456
|
|
|
), |
|
1457
|
|
|
), |
|
1458
|
|
|
), |
|
1459
|
|
|
'sort' => array( |
|
1460
|
|
|
'default' => 'm.subject', |
|
1461
|
|
|
'reverse' => 'm.subject DESC', |
|
1462
|
|
|
), |
|
1463
|
|
|
), |
|
1464
|
|
|
'started_by' => array( |
|
1465
|
|
|
'header' => array( |
|
1466
|
|
|
'value' => $txt['started_by'], |
|
1467
|
|
|
'style' => 'width: 15%;', |
|
1468
|
|
|
), |
|
1469
|
|
|
'data' => array( |
|
1470
|
|
|
'db' => 'started_by', |
|
1471
|
|
|
), |
|
1472
|
|
|
'sort' => array( |
|
1473
|
|
|
'default' => 'mem.real_name', |
|
1474
|
|
|
'reverse' => 'mem.real_name DESC', |
|
1475
|
|
|
), |
|
1476
|
|
|
), |
|
1477
|
|
|
'started_on' => array( |
|
1478
|
|
|
'header' => array( |
|
1479
|
|
|
'value' => $txt['on'], |
|
1480
|
|
|
'class' => 'lefttext', |
|
1481
|
|
|
'style' => 'width: 20%;', |
|
1482
|
|
|
), |
|
1483
|
|
|
'data' => array( |
|
1484
|
|
|
'db' => 'started_on', |
|
1485
|
|
|
'timeformat' => true, |
|
1486
|
|
|
), |
|
1487
|
|
|
'sort' => array( |
|
1488
|
|
|
'default' => 'm.poster_time', |
|
1489
|
|
|
'reverse' => 'm.poster_time DESC', |
|
1490
|
|
|
), |
|
1491
|
|
|
), |
|
1492
|
|
|
'last_post_by' => array( |
|
1493
|
|
|
'header' => array( |
|
1494
|
|
|
'value' => $txt['last_post'], |
|
1495
|
|
|
'style' => 'width: 15%;', |
|
1496
|
|
|
), |
|
1497
|
|
|
'data' => array( |
|
1498
|
|
|
'db' => 'last_post_by', |
|
1499
|
|
|
), |
|
1500
|
|
|
'sort' => array( |
|
1501
|
|
|
'default' => 'mem.real_name', |
|
1502
|
|
|
'reverse' => 'mem.real_name DESC', |
|
1503
|
|
|
), |
|
1504
|
|
|
), |
|
1505
|
|
|
'last_post_on' => array( |
|
1506
|
|
|
'header' => array( |
|
1507
|
|
|
'value' => $txt['on'], |
|
1508
|
|
|
'class' => 'lefttext', |
|
1509
|
|
|
'style' => 'width: 20%;', |
|
1510
|
|
|
), |
|
1511
|
|
|
'data' => array( |
|
1512
|
|
|
'db' => 'last_post_on', |
|
1513
|
|
|
'timeformat' => true, |
|
1514
|
|
|
), |
|
1515
|
|
|
'sort' => array( |
|
1516
|
|
|
'default' => 'm.poster_time', |
|
1517
|
|
|
'reverse' => 'm.poster_time DESC', |
|
1518
|
|
|
), |
|
1519
|
|
|
), |
|
1520
|
|
|
), |
|
1521
|
|
|
); |
|
1522
|
|
|
|
|
1523
|
|
|
// Create the request list. |
|
1524
|
|
|
createList($listOptions); |
|
1525
|
|
|
|
|
1526
|
|
|
$context['sub_template'] = 'show_list'; |
|
1527
|
|
|
$context['default_list'] = 'unwatched_topics'; |
|
1528
|
|
|
} |
|
1529
|
|
|
|
|
1530
|
|
|
/** |
|
1531
|
|
|
* Gets information about unwatched (disregarded) topics. Callback for the list in show_unwatched |
|
1532
|
|
|
* |
|
1533
|
|
|
* @param int $start The item to start with (for pagination purposes) |
|
1534
|
|
|
* @param int $items_per_page How many items to show on each page |
|
1535
|
|
|
* @param string $sort A string indicating how to sort the results |
|
1536
|
|
|
* @param int $memID The ID of the member |
|
1537
|
|
|
* @return array An array of information about the unwatched topics |
|
1538
|
|
|
*/ |
|
1539
|
|
|
function list_getUnwatched($start, $items_per_page, $sort, $memID) |
|
1540
|
|
|
{ |
|
1541
|
|
|
global $smcFunc; |
|
1542
|
|
|
|
|
1543
|
|
|
// Get the list of topics we can see |
|
1544
|
|
|
$request = $smcFunc['db_query']('', ' |
|
1545
|
|
|
SELECT lt.id_topic |
|
1546
|
|
|
FROM {db_prefix}log_topics as lt |
|
1547
|
|
|
LEFT JOIN {db_prefix}topics as t ON (lt.id_topic = t.id_topic) |
|
1548
|
|
|
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')) ? ' |
|
1549
|
|
|
LEFT JOIN {db_prefix}members as mem ON (m.id_member = mem.id_member)' : '') . ' |
|
1550
|
|
|
WHERE lt.id_member = {int:current_member} |
|
1551
|
|
|
AND unwatched = 1 |
|
1552
|
|
|
AND {query_see_message_board} |
|
1553
|
|
|
ORDER BY {raw:sort} |
|
1554
|
|
|
LIMIT {int:offset}, {int:limit}', |
|
1555
|
|
|
array( |
|
1556
|
|
|
'current_member' => $memID, |
|
1557
|
|
|
'sort' => $sort, |
|
1558
|
|
|
'offset' => $start, |
|
1559
|
|
|
'limit' => $items_per_page, |
|
1560
|
|
|
) |
|
1561
|
|
|
); |
|
1562
|
|
|
|
|
1563
|
|
|
$topics = array(); |
|
1564
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1565
|
|
|
$topics[] = $row['id_topic']; |
|
1566
|
|
|
|
|
1567
|
|
|
$smcFunc['db_free_result']($request); |
|
1568
|
|
|
|
|
1569
|
|
|
// Any topics found? |
|
1570
|
|
|
$topicsInfo = array(); |
|
1571
|
|
|
if (!empty($topics)) |
|
1572
|
|
|
{ |
|
1573
|
|
|
$request = $smcFunc['db_query']('', ' |
|
1574
|
|
|
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 |
|
1575
|
|
|
FROM {db_prefix}topics AS t |
|
1576
|
|
|
INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg) |
|
1577
|
|
|
INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg) |
|
1578
|
|
|
LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member) |
|
1579
|
|
|
LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member) |
|
1580
|
|
|
WHERE t.id_topic IN ({array_int:topics})', |
|
1581
|
|
|
array( |
|
1582
|
|
|
'topics' => $topics, |
|
1583
|
|
|
) |
|
1584
|
|
|
); |
|
1585
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1586
|
|
|
$topicsInfo[] = $row; |
|
1587
|
|
|
$smcFunc['db_free_result']($request); |
|
1588
|
|
|
} |
|
1589
|
|
|
|
|
1590
|
|
|
return $topicsInfo; |
|
1591
|
|
|
} |
|
1592
|
|
|
|
|
1593
|
|
|
/** |
|
1594
|
|
|
* Count the number of topics in the unwatched list |
|
1595
|
|
|
* |
|
1596
|
|
|
* @param int $memID The ID of the member |
|
1597
|
|
|
* @return int The number of unwatched topics |
|
1598
|
|
|
*/ |
|
1599
|
|
|
function list_getNumUnwatched($memID) |
|
1600
|
|
|
{ |
|
1601
|
|
|
global $smcFunc; |
|
1602
|
|
|
|
|
1603
|
|
|
// Get the total number of attachments they have posted. |
|
1604
|
|
|
$request = $smcFunc['db_query']('', ' |
|
1605
|
|
|
SELECT COUNT(*) |
|
1606
|
|
|
FROM {db_prefix}log_topics as lt |
|
1607
|
|
|
LEFT JOIN {db_prefix}topics as t ON (lt.id_topic = t.id_topic) |
|
1608
|
|
|
WHERE lt.id_member = {int:current_member} |
|
1609
|
|
|
AND lt.unwatched = 1 |
|
1610
|
|
|
AND {query_see_topic_board}', |
|
1611
|
|
|
array( |
|
1612
|
|
|
'current_member' => $memID, |
|
1613
|
|
|
) |
|
1614
|
|
|
); |
|
1615
|
|
|
list ($unwatchedCount) = $smcFunc['db_fetch_row']($request); |
|
1616
|
|
|
$smcFunc['db_free_result']($request); |
|
1617
|
|
|
|
|
1618
|
|
|
return $unwatchedCount; |
|
1619
|
|
|
} |
|
1620
|
|
|
|
|
1621
|
|
|
/** |
|
1622
|
|
|
* Gets the user stats for display |
|
1623
|
|
|
* |
|
1624
|
|
|
* @param int $memID The ID of the member |
|
1625
|
|
|
*/ |
|
1626
|
|
|
function statPanel($memID) |
|
1627
|
|
|
{ |
|
1628
|
|
|
global $txt, $scripturl, $context, $user_profile, $user_info, $modSettings, $smcFunc; |
|
1629
|
|
|
|
|
1630
|
|
|
$context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name']; |
|
1631
|
|
|
|
|
1632
|
|
|
// Is the load average too high to allow searching just now? |
|
1633
|
|
|
if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats']) |
|
1634
|
|
|
fatal_lang_error('loadavg_userstats_disabled', false); |
|
1635
|
|
|
|
|
1636
|
|
|
// General user statistics. |
|
1637
|
|
|
$timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400); |
|
1638
|
|
|
$timeHours = floor(($user_profile[$memID]['total_time_logged_in'] % 86400) / 3600); |
|
1639
|
|
|
$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']; |
|
1640
|
|
|
$context['num_posts'] = comma_format($user_profile[$memID]['posts']); |
|
1641
|
|
|
// Menu tab |
|
1642
|
|
|
$context[$context['profile_menu_name']]['tab_data'] = array( |
|
1643
|
|
|
'title' => $txt['statPanel_generalStats'] . ' - ' . $context['member']['name'], |
|
1644
|
|
|
'icon' => 'stats_info.png' |
|
1645
|
|
|
); |
|
1646
|
|
|
|
|
1647
|
|
|
// Number of topics started and Number polls started |
|
1648
|
|
|
$result = $smcFunc['db_query']('', ' |
|
1649
|
|
|
SELECT COUNT(*), COUNT( CASE WHEN id_poll != {int:no_poll} THEN 1 ELSE NULL END ) |
|
1650
|
|
|
FROM {db_prefix}topics |
|
1651
|
|
|
WHERE id_member_started = {int:current_member}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' |
|
1652
|
|
|
AND id_board != {int:recycle_board}' : ''), |
|
1653
|
|
|
array( |
|
1654
|
|
|
'current_member' => $memID, |
|
1655
|
|
|
'recycle_board' => $modSettings['recycle_board'], |
|
1656
|
|
|
'no_poll' => 0, |
|
1657
|
|
|
) |
|
1658
|
|
|
); |
|
1659
|
|
|
list ($context['num_topics'], $context['num_polls']) = $smcFunc['db_fetch_row']($result); |
|
1660
|
|
|
$smcFunc['db_free_result']($result); |
|
1661
|
|
|
|
|
1662
|
|
|
// Number polls voted in. |
|
1663
|
|
|
$result = $smcFunc['db_query']('distinct_poll_votes', ' |
|
1664
|
|
|
SELECT COUNT(DISTINCT id_poll) |
|
1665
|
|
|
FROM {db_prefix}log_polls |
|
1666
|
|
|
WHERE id_member = {int:current_member}', |
|
1667
|
|
|
array( |
|
1668
|
|
|
'current_member' => $memID, |
|
1669
|
|
|
) |
|
1670
|
|
|
); |
|
1671
|
|
|
list ($context['num_votes']) = $smcFunc['db_fetch_row']($result); |
|
1672
|
|
|
$smcFunc['db_free_result']($result); |
|
1673
|
|
|
|
|
1674
|
|
|
// Format the numbers... |
|
1675
|
|
|
$context['num_topics'] = comma_format($context['num_topics']); |
|
1676
|
|
|
$context['num_polls'] = comma_format($context['num_polls']); |
|
1677
|
|
|
$context['num_votes'] = comma_format($context['num_votes']); |
|
1678
|
|
|
|
|
1679
|
|
|
// Grab the board this member posted in most often. |
|
1680
|
|
|
$result = $smcFunc['db_query']('', ' |
|
1681
|
|
|
SELECT |
|
1682
|
|
|
b.id_board, MAX(b.name) AS name, MAX(b.num_posts) AS num_posts, COUNT(*) AS message_count |
|
1683
|
|
|
FROM {db_prefix}messages AS m |
|
1684
|
|
|
INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board) |
|
1685
|
|
|
WHERE m.id_member = {int:current_member} |
|
1686
|
|
|
AND b.count_posts = {int:count_enabled} |
|
1687
|
|
|
AND {query_see_board} |
|
1688
|
|
|
GROUP BY b.id_board |
|
1689
|
|
|
ORDER BY message_count DESC |
|
1690
|
|
|
LIMIT 10', |
|
1691
|
|
|
array( |
|
1692
|
|
|
'current_member' => $memID, |
|
1693
|
|
|
'count_enabled' => 0, |
|
1694
|
|
|
) |
|
1695
|
|
|
); |
|
1696
|
|
|
$context['popular_boards'] = array(); |
|
1697
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
1698
|
|
|
{ |
|
1699
|
|
|
$context['popular_boards'][$row['id_board']] = array( |
|
1700
|
|
|
'id' => $row['id_board'], |
|
1701
|
|
|
'posts' => $row['message_count'], |
|
1702
|
|
|
'href' => $scripturl . '?board=' . $row['id_board'] . '.0', |
|
1703
|
|
|
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>', |
|
1704
|
|
|
'posts_percent' => $user_profile[$memID]['posts'] == 0 ? 0 : ($row['message_count'] * 100) / $user_profile[$memID]['posts'], |
|
1705
|
|
|
'total_posts' => $row['num_posts'], |
|
1706
|
|
|
'total_posts_member' => $user_profile[$memID]['posts'], |
|
1707
|
|
|
); |
|
1708
|
|
|
} |
|
1709
|
|
|
$smcFunc['db_free_result']($result); |
|
1710
|
|
|
|
|
1711
|
|
|
// Now get the 10 boards this user has most often participated in. |
|
1712
|
|
|
$result = $smcFunc['db_query']('profile_board_stats', ' |
|
1713
|
|
|
SELECT |
|
1714
|
|
|
b.id_board, MAX(b.name) AS name, b.num_posts, COUNT(*) AS message_count, |
|
1715
|
|
|
CASE WHEN COUNT(*) > MAX(b.num_posts) THEN 1 ELSE COUNT(*) / MAX(b.num_posts) END * 100 AS percentage |
|
1716
|
|
|
FROM {db_prefix}messages AS m |
|
1717
|
|
|
INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board) |
|
1718
|
|
|
WHERE m.id_member = {int:current_member} |
|
1719
|
|
|
AND {query_see_board} |
|
1720
|
|
|
GROUP BY b.id_board, b.num_posts |
|
1721
|
|
|
ORDER BY percentage DESC |
|
1722
|
|
|
LIMIT 10', |
|
1723
|
|
|
array( |
|
1724
|
|
|
'current_member' => $memID, |
|
1725
|
|
|
) |
|
1726
|
|
|
); |
|
1727
|
|
|
$context['board_activity'] = array(); |
|
1728
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
1729
|
|
|
{ |
|
1730
|
|
|
$context['board_activity'][$row['id_board']] = array( |
|
1731
|
|
|
'id' => $row['id_board'], |
|
1732
|
|
|
'posts' => $row['message_count'], |
|
1733
|
|
|
'href' => $scripturl . '?board=' . $row['id_board'] . '.0', |
|
1734
|
|
|
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>', |
|
1735
|
|
|
'percent' => comma_format((float) $row['percentage'], 2), |
|
1736
|
|
|
'posts_percent' => (float) $row['percentage'], |
|
1737
|
|
|
'total_posts' => $row['num_posts'], |
|
1738
|
|
|
); |
|
1739
|
|
|
} |
|
1740
|
|
|
$smcFunc['db_free_result']($result); |
|
1741
|
|
|
|
|
1742
|
|
|
// Posting activity by time. |
|
1743
|
|
|
$result = $smcFunc['db_query']('user_activity_by_time', ' |
|
1744
|
|
|
SELECT |
|
1745
|
|
|
HOUR(FROM_UNIXTIME(poster_time + {int:time_offset})) AS hour, |
|
1746
|
|
|
COUNT(*) AS post_count |
|
1747
|
|
|
FROM {db_prefix}messages |
|
1748
|
|
|
WHERE id_member = {int:current_member}' . ($modSettings['totalMessages'] > 100000 ? ' |
|
1749
|
|
|
AND id_topic > {int:top_ten_thousand_topics}' : '') . ' |
|
1750
|
|
|
GROUP BY hour', |
|
1751
|
|
|
array( |
|
1752
|
|
|
'current_member' => $memID, |
|
1753
|
|
|
'top_ten_thousand_topics' => $modSettings['totalTopics'] - 10000, |
|
1754
|
|
|
'time_offset' => (($user_info['time_offset'] + $modSettings['time_offset']) * 3600), |
|
1755
|
|
|
) |
|
1756
|
|
|
); |
|
1757
|
|
|
$maxPosts = $realPosts = 0; |
|
1758
|
|
|
$context['posts_by_time'] = array(); |
|
1759
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
1760
|
|
|
{ |
|
1761
|
|
|
// Cast as an integer to remove the leading 0. |
|
1762
|
|
|
$row['hour'] = (int) $row['hour']; |
|
1763
|
|
|
|
|
1764
|
|
|
$maxPosts = max($row['post_count'], $maxPosts); |
|
1765
|
|
|
$realPosts += $row['post_count']; |
|
1766
|
|
|
|
|
1767
|
|
|
$context['posts_by_time'][$row['hour']] = array( |
|
1768
|
|
|
'hour' => $row['hour'], |
|
1769
|
|
|
'hour_format' => stripos($user_info['time_format'], '%p') === false ? $row['hour'] : date('g a', mktime($row['hour'])), |
|
1770
|
|
|
'posts' => $row['post_count'], |
|
1771
|
|
|
'posts_percent' => 0, |
|
1772
|
|
|
'is_last' => $row['hour'] == 23, |
|
1773
|
|
|
); |
|
1774
|
|
|
} |
|
1775
|
|
|
$smcFunc['db_free_result']($result); |
|
1776
|
|
|
|
|
1777
|
|
|
if ($maxPosts > 0) |
|
1778
|
|
|
for ($hour = 0; $hour < 24; $hour++) |
|
1779
|
|
|
{ |
|
1780
|
|
|
if (!isset($context['posts_by_time'][$hour])) |
|
1781
|
|
|
$context['posts_by_time'][$hour] = array( |
|
1782
|
|
|
'hour' => $hour, |
|
1783
|
|
|
'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)), |
|
1784
|
|
|
'posts' => 0, |
|
1785
|
|
|
'posts_percent' => 0, |
|
1786
|
|
|
'relative_percent' => 0, |
|
1787
|
|
|
'is_last' => $hour == 23, |
|
1788
|
|
|
); |
|
1789
|
|
|
else |
|
1790
|
|
|
{ |
|
1791
|
|
|
$context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts); |
|
1792
|
|
|
$context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts); |
|
1793
|
|
|
} |
|
1794
|
|
|
} |
|
1795
|
|
|
|
|
1796
|
|
|
// Put it in the right order. |
|
1797
|
|
|
ksort($context['posts_by_time']); |
|
1798
|
|
|
|
|
1799
|
|
|
/** |
|
1800
|
|
|
* Adding new entries: |
|
1801
|
|
|
* 'key' => array( |
|
1802
|
|
|
* 'text' => string, // The text that will be shown next to the entry. |
|
1803
|
|
|
* 'url' => string, // OPTIONAL: The entry will be a url |
|
1804
|
|
|
* ), |
|
1805
|
|
|
* |
|
1806
|
|
|
* 'key' will be used to look up the language string as $txt['statPanel_' . $key]. |
|
1807
|
|
|
* Make sure to add a new entry when writing your mod! |
|
1808
|
|
|
*/ |
|
1809
|
|
|
$context['text_stats'] = array( |
|
1810
|
|
|
'total_time_online' => array( |
|
1811
|
|
|
'text' => $context['time_logged_in'], |
|
1812
|
|
|
), |
|
1813
|
|
|
'total_posts' => array( |
|
1814
|
|
|
'text' => $context['num_posts'] . ' ' . $txt['statPanel_posts'], |
|
1815
|
|
|
'url' => $scripturl . '?action=profile;area=showposts;sa=messages;u=' . $memID |
|
1816
|
|
|
), |
|
1817
|
|
|
'total_topics' => array( |
|
1818
|
|
|
'text' => $context['num_topics'] . ' ' . $txt['statPanel_topics'], |
|
1819
|
|
|
'url' => $scripturl . '?action=profile;area=showposts;sa=topics;u=' . $memID |
|
1820
|
|
|
), |
|
1821
|
|
|
'users_polls' => array( |
|
1822
|
|
|
'text' => $context['num_polls'] . ' ' . $txt['statPanel_polls'], |
|
1823
|
|
|
), |
|
1824
|
|
|
'users_votes' => array( |
|
1825
|
|
|
'text' => $context['num_votes'] . ' ' . $txt['statPanel_votes'] |
|
1826
|
|
|
) |
|
1827
|
|
|
); |
|
1828
|
|
|
|
|
1829
|
|
|
// Custom stats (just add a template_layer to add it to the template!) |
|
1830
|
|
|
call_integration_hook('integrate_profile_stats', array($memID, &$context['text_stats'])); |
|
1831
|
|
|
} |
|
1832
|
|
|
|
|
1833
|
|
|
/** |
|
1834
|
|
|
* Loads up the information for the "track user" section of the profile |
|
1835
|
|
|
* |
|
1836
|
|
|
* @param int $memID The ID of the member |
|
1837
|
|
|
*/ |
|
1838
|
|
|
function tracking($memID) |
|
1839
|
|
|
{ |
|
1840
|
|
|
global $context, $txt, $modSettings, $user_profile; |
|
1841
|
|
|
|
|
1842
|
|
|
$subActions = array( |
|
1843
|
|
|
'activity' => array('trackActivity', $txt['trackActivity'], 'moderate_forum'), |
|
1844
|
|
|
'ip' => array('TrackIP', $txt['trackIP'], 'moderate_forum'), |
|
1845
|
|
|
'edits' => array('trackEdits', $txt['trackEdits'], 'moderate_forum'), |
|
1846
|
|
|
'groupreq' => array('trackGroupReq', $txt['trackGroupRequests'], 'approve_group_requests'), |
|
1847
|
|
|
'logins' => array('TrackLogins', $txt['trackLogins'], 'moderate_forum'), |
|
1848
|
|
|
); |
|
1849
|
|
|
|
|
1850
|
|
|
foreach ($subActions as $sa => $action) |
|
1851
|
|
|
{ |
|
1852
|
|
|
if (!allowedTo($action[2])) |
|
1853
|
|
|
unset($subActions[$sa]); |
|
1854
|
|
|
} |
|
1855
|
|
|
|
|
1856
|
|
|
// Create the tabs for the template. |
|
1857
|
|
|
$context[$context['profile_menu_name']]['tab_data'] = array( |
|
1858
|
|
|
'title' => $txt['tracking'], |
|
1859
|
|
|
'description' => $txt['tracking_description'], |
|
1860
|
|
|
'icon' => 'profile_hd.png', |
|
1861
|
|
|
'tabs' => array( |
|
1862
|
|
|
'activity' => array(), |
|
1863
|
|
|
'ip' => array(), |
|
1864
|
|
|
'edits' => array(), |
|
1865
|
|
|
'groupreq' => array(), |
|
1866
|
|
|
'logins' => array(), |
|
1867
|
|
|
), |
|
1868
|
|
|
); |
|
1869
|
|
|
|
|
1870
|
|
|
// Moderation must be on to track edits. |
|
1871
|
|
|
if (empty($modSettings['userlog_enabled'])) |
|
1872
|
|
|
unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']); |
|
1873
|
|
|
|
|
1874
|
|
|
// Group requests must be active to show it... |
|
1875
|
|
|
if (empty($modSettings['show_group_membership'])) |
|
1876
|
|
|
unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']); |
|
1877
|
|
|
|
|
1878
|
|
|
if (empty($subActions)) |
|
1879
|
|
|
fatal_lang_error('no_access', false); |
|
1880
|
|
|
|
|
1881
|
|
|
$keys = array_keys($subActions); |
|
1882
|
|
|
$default = array_shift($keys); |
|
1883
|
|
|
$context['tracking_area'] = isset($_GET['sa']) && isset($subActions[$_GET['sa']]) ? $_GET['sa'] : $default; |
|
1884
|
|
|
|
|
1885
|
|
|
// Set a page title. |
|
1886
|
|
|
$context['page_title'] = $txt['trackUser'] . ' - ' . $subActions[$context['tracking_area']][1] . ' - ' . $user_profile[$memID]['real_name']; |
|
1887
|
|
|
|
|
1888
|
|
|
// Pass on to the actual function. |
|
1889
|
|
|
$context['sub_template'] = $subActions[$context['tracking_area']][0]; |
|
1890
|
|
|
$call = call_helper($subActions[$context['tracking_area']][0], true); |
|
1891
|
|
|
|
|
1892
|
|
|
if (!empty($call)) |
|
1893
|
|
|
call_user_func($call, $memID); |
|
|
|
|
|
|
1894
|
|
|
} |
|
1895
|
|
|
|
|
1896
|
|
|
/** |
|
1897
|
|
|
* Handles tracking a user's activity |
|
1898
|
|
|
* |
|
1899
|
|
|
* @param int $memID The ID of the member |
|
1900
|
|
|
*/ |
|
1901
|
|
|
function trackActivity($memID) |
|
1902
|
|
|
{ |
|
1903
|
|
|
global $scripturl, $txt, $modSettings, $sourcedir; |
|
1904
|
|
|
global $user_profile, $context, $smcFunc; |
|
1905
|
|
|
|
|
1906
|
|
|
// Verify if the user has sufficient permissions. |
|
1907
|
|
|
isAllowedTo('moderate_forum'); |
|
1908
|
|
|
|
|
1909
|
|
|
$context['last_ip'] = $user_profile[$memID]['member_ip']; |
|
1910
|
|
|
if ($context['last_ip'] != $user_profile[$memID]['member_ip2']) |
|
1911
|
|
|
$context['last_ip2'] = $user_profile[$memID]['member_ip2']; |
|
1912
|
|
|
$context['member']['name'] = $user_profile[$memID]['real_name']; |
|
1913
|
|
|
|
|
1914
|
|
|
// Set the options for the list component. |
|
1915
|
|
|
$listOptions = array( |
|
1916
|
|
|
'id' => 'track_user_list', |
|
1917
|
|
|
'title' => $txt['errors_by'] . ' ' . $context['member']['name'], |
|
1918
|
|
|
'items_per_page' => $modSettings['defaultMaxListItems'], |
|
1919
|
|
|
'no_items_label' => $txt['no_errors_from_user'], |
|
1920
|
|
|
'base_href' => $scripturl . '?action=profile;area=tracking;sa=user;u=' . $memID, |
|
1921
|
|
|
'default_sort_col' => 'date', |
|
1922
|
|
|
'get_items' => array( |
|
1923
|
|
|
'function' => 'list_getUserErrors', |
|
1924
|
|
|
'params' => array( |
|
1925
|
|
|
'le.id_member = {int:current_member}', |
|
1926
|
|
|
array('current_member' => $memID), |
|
1927
|
|
|
), |
|
1928
|
|
|
), |
|
1929
|
|
|
'get_count' => array( |
|
1930
|
|
|
'function' => 'list_getUserErrorCount', |
|
1931
|
|
|
'params' => array( |
|
1932
|
|
|
'id_member = {int:current_member}', |
|
1933
|
|
|
array('current_member' => $memID), |
|
1934
|
|
|
), |
|
1935
|
|
|
), |
|
1936
|
|
|
'columns' => array( |
|
1937
|
|
|
'ip_address' => array( |
|
1938
|
|
|
'header' => array( |
|
1939
|
|
|
'value' => $txt['ip_address'], |
|
1940
|
|
|
), |
|
1941
|
|
|
'data' => array( |
|
1942
|
|
|
'sprintf' => array( |
|
1943
|
|
|
'format' => '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=%1$s;u=' . $memID . '">%1$s</a>', |
|
1944
|
|
|
'params' => array( |
|
1945
|
|
|
'ip' => false, |
|
1946
|
|
|
), |
|
1947
|
|
|
), |
|
1948
|
|
|
), |
|
1949
|
|
|
'sort' => array( |
|
1950
|
|
|
'default' => 'le.ip', |
|
1951
|
|
|
'reverse' => 'le.ip DESC', |
|
1952
|
|
|
), |
|
1953
|
|
|
), |
|
1954
|
|
|
'message' => array( |
|
1955
|
|
|
'header' => array( |
|
1956
|
|
|
'value' => $txt['message'], |
|
1957
|
|
|
), |
|
1958
|
|
|
'data' => array( |
|
1959
|
|
|
'sprintf' => array( |
|
1960
|
|
|
'format' => '%1$s<br><a href="%2$s">%2$s</a>', |
|
1961
|
|
|
'params' => array( |
|
1962
|
|
|
'message' => false, |
|
1963
|
|
|
'url' => false, |
|
1964
|
|
|
), |
|
1965
|
|
|
), |
|
1966
|
|
|
), |
|
1967
|
|
|
), |
|
1968
|
|
|
'date' => array( |
|
1969
|
|
|
'header' => array( |
|
1970
|
|
|
'value' => $txt['date'], |
|
1971
|
|
|
), |
|
1972
|
|
|
'data' => array( |
|
1973
|
|
|
'db' => 'time', |
|
1974
|
|
|
), |
|
1975
|
|
|
'sort' => array( |
|
1976
|
|
|
'default' => 'le.id_error DESC', |
|
1977
|
|
|
'reverse' => 'le.id_error', |
|
1978
|
|
|
), |
|
1979
|
|
|
), |
|
1980
|
|
|
), |
|
1981
|
|
|
'additional_rows' => array( |
|
1982
|
|
|
array( |
|
1983
|
|
|
'position' => 'after_title', |
|
1984
|
|
|
'value' => $txt['errors_desc'], |
|
1985
|
|
|
), |
|
1986
|
|
|
), |
|
1987
|
|
|
); |
|
1988
|
|
|
|
|
1989
|
|
|
// Create the list for viewing. |
|
1990
|
|
|
require_once($sourcedir . '/Subs-List.php'); |
|
1991
|
|
|
createList($listOptions); |
|
1992
|
|
|
|
|
1993
|
|
|
// @todo cache this |
|
1994
|
|
|
// If this is a big forum, or a large posting user, let's limit the search. |
|
1995
|
|
|
if ($modSettings['totalMessages'] > 50000 && $user_profile[$memID]['posts'] > 500) |
|
1996
|
|
|
{ |
|
1997
|
|
|
$request = $smcFunc['db_query']('', ' |
|
1998
|
|
|
SELECT MAX(id_msg) |
|
1999
|
|
|
FROM {db_prefix}messages AS m |
|
2000
|
|
|
WHERE m.id_member = {int:current_member}', |
|
2001
|
|
|
array( |
|
2002
|
|
|
'current_member' => $memID, |
|
2003
|
|
|
) |
|
2004
|
|
|
); |
|
2005
|
|
|
list ($max_msg_member) = $smcFunc['db_fetch_row']($request); |
|
2006
|
|
|
$smcFunc['db_free_result']($request); |
|
2007
|
|
|
|
|
2008
|
|
|
// There's no point worrying ourselves with messages made yonks ago, just get recent ones! |
|
2009
|
|
|
$min_msg_member = max(0, $max_msg_member - $user_profile[$memID]['posts'] * 3); |
|
2010
|
|
|
} |
|
2011
|
|
|
|
|
2012
|
|
|
// Default to at least the ones we know about. |
|
2013
|
|
|
$ips = array( |
|
2014
|
|
|
$user_profile[$memID]['member_ip'], |
|
2015
|
|
|
$user_profile[$memID]['member_ip2'], |
|
2016
|
|
|
); |
|
2017
|
|
|
|
|
2018
|
|
|
// @todo cache this |
|
2019
|
|
|
// Get all IP addresses this user has used for his messages. |
|
2020
|
|
|
$request = $smcFunc['db_query']('', ' |
|
2021
|
|
|
SELECT poster_ip |
|
2022
|
|
|
FROM {db_prefix}messages |
|
2023
|
|
|
WHERE id_member = {int:current_member} |
|
2024
|
|
|
' . (isset($min_msg_member) ? ' |
|
2025
|
|
|
AND id_msg >= {int:min_msg_member} AND id_msg <= {int:max_msg_member}' : '') . ' |
|
2026
|
|
|
GROUP BY poster_ip', |
|
2027
|
|
|
array( |
|
2028
|
|
|
'current_member' => $memID, |
|
2029
|
|
|
'min_msg_member' => !empty($min_msg_member) ? $min_msg_member : 0, |
|
2030
|
|
|
'max_msg_member' => !empty($max_msg_member) ? $max_msg_member : 0, |
|
2031
|
|
|
) |
|
2032
|
|
|
); |
|
2033
|
|
|
$context['ips'] = array(); |
|
2034
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2035
|
|
|
{ |
|
2036
|
|
|
$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>'; |
|
2037
|
|
|
$ips[] = inet_dtop($row['poster_ip']); |
|
2038
|
|
|
} |
|
2039
|
|
|
$smcFunc['db_free_result']($request); |
|
2040
|
|
|
|
|
2041
|
|
|
// Now also get the IP addresses from the error messages. |
|
2042
|
|
|
$request = $smcFunc['db_query']('', ' |
|
2043
|
|
|
SELECT COUNT(*) AS error_count, ip |
|
2044
|
|
|
FROM {db_prefix}log_errors |
|
2045
|
|
|
WHERE id_member = {int:current_member} |
|
2046
|
|
|
GROUP BY ip', |
|
2047
|
|
|
array( |
|
2048
|
|
|
'current_member' => $memID, |
|
2049
|
|
|
) |
|
2050
|
|
|
); |
|
2051
|
|
|
$context['error_ips'] = array(); |
|
2052
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2053
|
|
|
{ |
|
2054
|
|
|
$row['ip'] = inet_dtop($row['ip']); |
|
2055
|
|
|
$context['error_ips'][] = '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=' . $row['ip'] . ';u=' . $memID . '">' . $row['ip'] . '</a>'; |
|
2056
|
|
|
$ips[] = $row['ip']; |
|
2057
|
|
|
} |
|
2058
|
|
|
$smcFunc['db_free_result']($request); |
|
2059
|
|
|
|
|
2060
|
|
|
// Find other users that might use the same IP. |
|
2061
|
|
|
$ips = array_unique($ips); |
|
2062
|
|
|
$context['members_in_range'] = array(); |
|
2063
|
|
|
if (!empty($ips)) |
|
2064
|
|
|
{ |
|
2065
|
|
|
// Get member ID's which are in messages... |
|
2066
|
|
|
$request = $smcFunc['db_query']('', ' |
|
2067
|
|
|
SELECT DISTINCT mem.id_member |
|
2068
|
|
|
FROM {db_prefix}messages AS m |
|
2069
|
|
|
INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) |
|
2070
|
|
|
WHERE m.poster_ip IN ({array_inet:ip_list}) |
|
2071
|
|
|
AND mem.id_member != {int:current_member}', |
|
2072
|
|
|
array( |
|
2073
|
|
|
'current_member' => $memID, |
|
2074
|
|
|
'ip_list' => $ips, |
|
2075
|
|
|
) |
|
2076
|
|
|
); |
|
2077
|
|
|
$message_members = array(); |
|
2078
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2079
|
|
|
$message_members[] = $row['id_member']; |
|
2080
|
|
|
$smcFunc['db_free_result']($request); |
|
2081
|
|
|
|
|
2082
|
|
|
// Fetch their names, cause of the GROUP BY doesn't like giving us that normally. |
|
2083
|
|
|
if (!empty($message_members)) |
|
2084
|
|
|
{ |
|
2085
|
|
|
$request = $smcFunc['db_query']('', ' |
|
2086
|
|
|
SELECT id_member, real_name |
|
2087
|
|
|
FROM {db_prefix}members |
|
2088
|
|
|
WHERE id_member IN ({array_int:message_members})', |
|
2089
|
|
|
array( |
|
2090
|
|
|
'message_members' => $message_members, |
|
2091
|
|
|
'ip_list' => $ips, |
|
2092
|
|
|
) |
|
2093
|
|
|
); |
|
2094
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2095
|
|
|
$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
2096
|
|
|
$smcFunc['db_free_result']($request); |
|
2097
|
|
|
} |
|
2098
|
|
|
|
|
2099
|
|
|
$request = $smcFunc['db_query']('', ' |
|
2100
|
|
|
SELECT id_member, real_name |
|
2101
|
|
|
FROM {db_prefix}members |
|
2102
|
|
|
WHERE id_member != {int:current_member} |
|
2103
|
|
|
AND member_ip IN ({array_inet:ip_list})', |
|
2104
|
|
|
array( |
|
2105
|
|
|
'current_member' => $memID, |
|
2106
|
|
|
'ip_list' => $ips, |
|
2107
|
|
|
) |
|
2108
|
|
|
); |
|
2109
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2110
|
|
|
$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
2111
|
|
|
$smcFunc['db_free_result']($request); |
|
2112
|
|
|
} |
|
2113
|
|
|
} |
|
2114
|
|
|
|
|
2115
|
|
|
/** |
|
2116
|
|
|
* Get the number of user errors |
|
2117
|
|
|
* |
|
2118
|
|
|
* @param string $where A query to limit which errors are counted |
|
2119
|
|
|
* @param array $where_vars The parameters for $where |
|
2120
|
|
|
* @return int Number of user errors |
|
2121
|
|
|
*/ |
|
2122
|
|
|
function list_getUserErrorCount($where, $where_vars = array()) |
|
2123
|
|
|
{ |
|
2124
|
|
|
global $smcFunc; |
|
2125
|
|
|
|
|
2126
|
|
|
$request = $smcFunc['db_query']('', ' |
|
2127
|
|
|
SELECT COUNT(id_error) |
|
2128
|
|
|
FROM {db_prefix}log_errors |
|
2129
|
|
|
WHERE ' . $where, |
|
2130
|
|
|
$where_vars |
|
2131
|
|
|
); |
|
2132
|
|
|
list ($count) = $smcFunc['db_fetch_row']($request); |
|
2133
|
|
|
$smcFunc['db_free_result']($request); |
|
2134
|
|
|
|
|
2135
|
|
|
return (int) $count; |
|
2136
|
|
|
} |
|
2137
|
|
|
|
|
2138
|
|
|
/** |
|
2139
|
|
|
* Gets all of the errors generated by a user's actions. Callback for the list in track_activity |
|
2140
|
|
|
* |
|
2141
|
|
|
* @param int $start Which item to start with (for pagination purposes) |
|
2142
|
|
|
* @param int $items_per_page How many items to show on each page |
|
2143
|
|
|
* @param string $sort A string indicating how to sort the results |
|
2144
|
|
|
* @param string $where A query indicating how to filter the results (eg 'id_member={int:id_member}') |
|
2145
|
|
|
* @param array $where_vars An array of parameters for $where |
|
2146
|
|
|
* @return array An array of information about the error messages |
|
2147
|
|
|
*/ |
|
2148
|
|
|
function list_getUserErrors($start, $items_per_page, $sort, $where, $where_vars = array()) |
|
2149
|
|
|
{ |
|
2150
|
|
|
global $smcFunc, $txt, $scripturl; |
|
2151
|
|
|
|
|
2152
|
|
|
// Get a list of error messages from this ip (range). |
|
2153
|
|
|
$request = $smcFunc['db_query']('', ' |
|
2154
|
|
|
SELECT |
|
2155
|
|
|
le.log_time, le.ip, le.url, le.message, COALESCE(mem.id_member, 0) AS id_member, |
|
2156
|
|
|
COALESCE(mem.real_name, {string:guest_title}) AS display_name, mem.member_name |
|
2157
|
|
|
FROM {db_prefix}log_errors AS le |
|
2158
|
|
|
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = le.id_member) |
|
2159
|
|
|
WHERE ' . $where . ' |
|
2160
|
|
|
ORDER BY {raw:sort} |
|
2161
|
|
|
LIMIT {int:start}, {int:max}', |
|
2162
|
|
|
array_merge($where_vars, array( |
|
2163
|
|
|
'guest_title' => $txt['guest_title'], |
|
2164
|
|
|
'sort' => $sort, |
|
2165
|
|
|
'start' => $start, |
|
2166
|
|
|
'max' => $items_per_page, |
|
2167
|
|
|
)) |
|
2168
|
|
|
); |
|
2169
|
|
|
$error_messages = array(); |
|
2170
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2171
|
|
|
$error_messages[] = array( |
|
2172
|
|
|
'ip' => inet_dtop($row['ip']), |
|
2173
|
|
|
'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'], |
|
2174
|
|
|
'message' => strtr($row['message'], array('<span class="remove">' => '', '</span>' => '')), |
|
2175
|
|
|
'url' => $row['url'], |
|
2176
|
|
|
'time' => timeformat($row['log_time']), |
|
2177
|
|
|
'timestamp' => forum_time(true, $row['log_time']), |
|
2178
|
|
|
); |
|
2179
|
|
|
$smcFunc['db_free_result']($request); |
|
2180
|
|
|
|
|
2181
|
|
|
return $error_messages; |
|
2182
|
|
|
} |
|
2183
|
|
|
|
|
2184
|
|
|
/** |
|
2185
|
|
|
* Gets the number of posts made from a particular IP |
|
2186
|
|
|
* |
|
2187
|
|
|
* @param string $where A query indicating which posts to count |
|
2188
|
|
|
* @param array $where_vars The parameters for $where |
|
2189
|
|
|
* @return int Count of messages matching the IP |
|
2190
|
|
|
*/ |
|
2191
|
|
|
function list_getIPMessageCount($where, $where_vars = array()) |
|
2192
|
|
|
{ |
|
2193
|
|
|
global $smcFunc, $user_info; |
|
2194
|
|
|
|
|
2195
|
|
|
$request = $smcFunc['db_query']('', ' |
|
2196
|
|
|
SELECT COUNT(id_msg) |
|
2197
|
|
|
FROM {db_prefix}messages AS m |
|
2198
|
|
|
WHERE {query_see_message_board} AND ' . $where, |
|
2199
|
|
|
$where_vars |
|
2200
|
|
|
); |
|
2201
|
|
|
list ($count) = $smcFunc['db_fetch_row']($request); |
|
2202
|
|
|
$smcFunc['db_free_result']($request); |
|
2203
|
|
|
|
|
2204
|
|
|
return (int) $count; |
|
2205
|
|
|
} |
|
2206
|
|
|
|
|
2207
|
|
|
/** |
|
2208
|
|
|
* Gets all the posts made from a particular IP |
|
2209
|
|
|
* |
|
2210
|
|
|
* @param int $start Which item to start with (for pagination purposes) |
|
2211
|
|
|
* @param int $items_per_page How many items to show on each page |
|
2212
|
|
|
* @param string $sort A string indicating how to sort the results |
|
2213
|
|
|
* @param string $where A query to filter which posts are returned |
|
2214
|
|
|
* @param array $where_vars An array of parameters for $where |
|
2215
|
|
|
* @return array An array containing information about the posts |
|
2216
|
|
|
*/ |
|
2217
|
|
|
function list_getIPMessages($start, $items_per_page, $sort, $where, $where_vars = array()) |
|
2218
|
|
|
{ |
|
2219
|
|
|
global $smcFunc, $scripturl, $user_info; |
|
2220
|
|
|
|
|
2221
|
|
|
// Get all the messages fitting this where clause. |
|
2222
|
|
|
$request = $smcFunc['db_query']('', ' |
|
2223
|
|
|
SELECT |
|
2224
|
|
|
m.id_msg, m.poster_ip, COALESCE(mem.real_name, m.poster_name) AS display_name, mem.id_member, |
|
2225
|
|
|
m.subject, m.poster_time, m.id_topic, m.id_board |
|
2226
|
|
|
FROM {db_prefix}messages AS m |
|
2227
|
|
|
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) |
|
2228
|
|
|
WHERE {query_see_message_board} AND ' . $where . ' |
|
2229
|
|
|
ORDER BY {raw:sort} |
|
2230
|
|
|
LIMIT {int:start}, {int:max}', |
|
2231
|
|
|
array_merge($where_vars, array( |
|
2232
|
|
|
'sort' => $sort, |
|
2233
|
|
|
'start' => $start, |
|
2234
|
|
|
'max' => $items_per_page, |
|
2235
|
|
|
)) |
|
2236
|
|
|
); |
|
2237
|
|
|
$messages = array(); |
|
2238
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2239
|
|
|
$messages[] = array( |
|
2240
|
|
|
'ip' => inet_dtop($row['poster_ip']), |
|
2241
|
|
|
'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>', |
|
2242
|
|
|
'board' => array( |
|
2243
|
|
|
'id' => $row['id_board'], |
|
2244
|
|
|
'href' => $scripturl . '?board=' . $row['id_board'] |
|
2245
|
|
|
), |
|
2246
|
|
|
'topic' => $row['id_topic'], |
|
2247
|
|
|
'id' => $row['id_msg'], |
|
2248
|
|
|
'subject' => $row['subject'], |
|
2249
|
|
|
'time' => timeformat($row['poster_time']), |
|
2250
|
|
|
'timestamp' => forum_time(true, $row['poster_time']) |
|
2251
|
|
|
); |
|
2252
|
|
|
$smcFunc['db_free_result']($request); |
|
2253
|
|
|
|
|
2254
|
|
|
return $messages; |
|
2255
|
|
|
} |
|
2256
|
|
|
|
|
2257
|
|
|
/** |
|
2258
|
|
|
* Handles tracking a particular IP address |
|
2259
|
|
|
* |
|
2260
|
|
|
* @param int $memID The ID of a member whose IP we want to track |
|
2261
|
|
|
*/ |
|
2262
|
|
|
function TrackIP($memID = 0) |
|
2263
|
|
|
{ |
|
2264
|
|
|
global $user_profile, $scripturl, $txt, $user_info, $modSettings, $sourcedir; |
|
2265
|
|
|
global $context, $options, $smcFunc; |
|
2266
|
|
|
|
|
2267
|
|
|
// Can the user do this? |
|
2268
|
|
|
isAllowedTo('moderate_forum'); |
|
2269
|
|
|
|
|
2270
|
|
|
if ($memID == 0) |
|
2271
|
|
|
{ |
|
2272
|
|
|
$context['ip'] = ip2range($user_info['ip']); |
|
2273
|
|
|
loadTemplate('Profile'); |
|
2274
|
|
|
loadLanguage('Profile'); |
|
2275
|
|
|
$context['sub_template'] = 'trackIP'; |
|
2276
|
|
|
$context['page_title'] = $txt['profile']; |
|
2277
|
|
|
$context['base_url'] = $scripturl . '?action=trackip'; |
|
2278
|
|
|
} |
|
2279
|
|
|
else |
|
2280
|
|
|
{ |
|
2281
|
|
|
$context['ip'] = ip2range($user_profile[$memID]['member_ip']); |
|
2282
|
|
|
$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID; |
|
2283
|
|
|
} |
|
2284
|
|
|
|
|
2285
|
|
|
// Searching? |
|
2286
|
|
|
if (isset($_REQUEST['searchip'])) |
|
2287
|
|
|
$context['ip'] = ip2range(trim($_REQUEST['searchip'])); |
|
2288
|
|
|
|
|
2289
|
|
|
if (count($context['ip']) !== 2) |
|
2290
|
|
|
fatal_lang_error('invalid_tracking_ip', false); |
|
2291
|
|
|
|
|
2292
|
|
|
$ip_string = array('{inet:ip_address_low}', '{inet:ip_address_high}'); |
|
2293
|
|
|
$fields = array( |
|
2294
|
|
|
'ip_address_low' => $context['ip']['low'], |
|
2295
|
|
|
'ip_address_high' => $context['ip']['high'], |
|
2296
|
|
|
); |
|
2297
|
|
|
|
|
2298
|
|
|
$ip_var = $context['ip']; |
|
2299
|
|
|
|
|
2300
|
|
|
if ($context['ip']['low'] !== $context['ip']['high']) |
|
2301
|
|
|
$context['ip'] = $context['ip']['low'] . ' - ' . $context['ip']['high']; |
|
2302
|
|
|
else |
|
2303
|
|
|
$context['ip'] = $context['ip']['low']; |
|
2304
|
|
|
|
|
2305
|
|
|
if (empty($context['tracking_area'])) |
|
2306
|
|
|
$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip']; |
|
2307
|
|
|
|
|
2308
|
|
|
$request = $smcFunc['db_query']('', ' |
|
2309
|
|
|
SELECT id_member, real_name AS display_name, member_ip |
|
2310
|
|
|
FROM {db_prefix}members |
|
2311
|
|
|
WHERE member_ip >= ' . $ip_string[0] . ' and member_ip <= ' . $ip_string[1], |
|
2312
|
|
|
$fields |
|
2313
|
|
|
); |
|
2314
|
|
|
$context['ips'] = array(); |
|
2315
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2316
|
|
|
$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>'; |
|
2317
|
|
|
$smcFunc['db_free_result']($request); |
|
2318
|
|
|
|
|
2319
|
|
|
ksort($context['ips']); |
|
2320
|
|
|
|
|
2321
|
|
|
// For messages we use the "messages per page" option |
|
2322
|
|
|
$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
|
2323
|
|
|
|
|
2324
|
|
|
// Gonna want this for the list. |
|
2325
|
|
|
require_once($sourcedir . '/Subs-List.php'); |
|
2326
|
|
|
|
|
2327
|
|
|
// Start with the user messages. |
|
2328
|
|
|
$listOptions = array( |
|
2329
|
|
|
'id' => 'track_message_list', |
|
2330
|
|
|
'title' => $txt['messages_from_ip'] . ' ' . $context['ip'], |
|
2331
|
|
|
'start_var_name' => 'messageStart', |
|
2332
|
|
|
'items_per_page' => $maxPerPage, |
|
2333
|
|
|
'no_items_label' => $txt['no_messages_from_ip'], |
|
2334
|
|
|
'base_href' => $context['base_url'] . ';searchip=' . $context['ip'], |
|
2335
|
|
|
'default_sort_col' => 'date', |
|
2336
|
|
|
'get_items' => array( |
|
2337
|
|
|
'function' => 'list_getIPMessages', |
|
2338
|
|
|
'params' => array( |
|
2339
|
|
|
'm.poster_ip >= ' . $ip_string[0] . ' and m.poster_ip <= ' . $ip_string[1], |
|
2340
|
|
|
$fields, |
|
2341
|
|
|
), |
|
2342
|
|
|
), |
|
2343
|
|
|
'get_count' => array( |
|
2344
|
|
|
'function' => 'list_getIPMessageCount', |
|
2345
|
|
|
'params' => array( |
|
2346
|
|
|
'm.poster_ip >= ' . $ip_string[0] . ' and m.poster_ip <= ' . $ip_string[1], |
|
2347
|
|
|
$fields, |
|
2348
|
|
|
), |
|
2349
|
|
|
), |
|
2350
|
|
|
'columns' => array( |
|
2351
|
|
|
'ip_address' => array( |
|
2352
|
|
|
'header' => array( |
|
2353
|
|
|
'value' => $txt['ip_address'], |
|
2354
|
|
|
), |
|
2355
|
|
|
'data' => array( |
|
2356
|
|
|
'sprintf' => array( |
|
2357
|
|
|
'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a>', |
|
2358
|
|
|
'params' => array( |
|
2359
|
|
|
'ip' => false, |
|
2360
|
|
|
), |
|
2361
|
|
|
), |
|
2362
|
|
|
), |
|
2363
|
|
|
'sort' => array( |
|
2364
|
|
|
'default' => 'm.poster_ip', |
|
2365
|
|
|
'reverse' => 'm.poster_ip DESC', |
|
2366
|
|
|
), |
|
2367
|
|
|
), |
|
2368
|
|
|
'poster' => array( |
|
2369
|
|
|
'header' => array( |
|
2370
|
|
|
'value' => $txt['poster'], |
|
2371
|
|
|
), |
|
2372
|
|
|
'data' => array( |
|
2373
|
|
|
'db' => 'member_link', |
|
2374
|
|
|
), |
|
2375
|
|
|
), |
|
2376
|
|
|
'subject' => array( |
|
2377
|
|
|
'header' => array( |
|
2378
|
|
|
'value' => $txt['subject'], |
|
2379
|
|
|
), |
|
2380
|
|
|
'data' => array( |
|
2381
|
|
|
'sprintf' => array( |
|
2382
|
|
|
'format' => '<a href="' . $scripturl . '?topic=%1$s.msg%2$s#msg%2$s" rel="nofollow">%3$s</a>', |
|
2383
|
|
|
'params' => array( |
|
2384
|
|
|
'topic' => false, |
|
2385
|
|
|
'id' => false, |
|
2386
|
|
|
'subject' => false, |
|
2387
|
|
|
), |
|
2388
|
|
|
), |
|
2389
|
|
|
), |
|
2390
|
|
|
), |
|
2391
|
|
|
'date' => array( |
|
2392
|
|
|
'header' => array( |
|
2393
|
|
|
'value' => $txt['date'], |
|
2394
|
|
|
), |
|
2395
|
|
|
'data' => array( |
|
2396
|
|
|
'db' => 'time', |
|
2397
|
|
|
), |
|
2398
|
|
|
'sort' => array( |
|
2399
|
|
|
'default' => 'm.id_msg DESC', |
|
2400
|
|
|
'reverse' => 'm.id_msg', |
|
2401
|
|
|
), |
|
2402
|
|
|
), |
|
2403
|
|
|
), |
|
2404
|
|
|
'additional_rows' => array( |
|
2405
|
|
|
array( |
|
2406
|
|
|
'position' => 'after_title', |
|
2407
|
|
|
'value' => $txt['messages_from_ip_desc'], |
|
2408
|
|
|
), |
|
2409
|
|
|
), |
|
2410
|
|
|
); |
|
2411
|
|
|
|
|
2412
|
|
|
// Create the messages list. |
|
2413
|
|
|
createList($listOptions); |
|
2414
|
|
|
|
|
2415
|
|
|
// Set the options for the error lists. |
|
2416
|
|
|
$listOptions = array( |
|
2417
|
|
|
'id' => 'track_user_list', |
|
2418
|
|
|
'title' => $txt['errors_from_ip'] . ' ' . $context['ip'], |
|
2419
|
|
|
'start_var_name' => 'errorStart', |
|
2420
|
|
|
'items_per_page' => $modSettings['defaultMaxListItems'], |
|
2421
|
|
|
'no_items_label' => $txt['no_errors_from_ip'], |
|
2422
|
|
|
'base_href' => $context['base_url'] . ';searchip=' . $context['ip'], |
|
2423
|
|
|
'default_sort_col' => 'date2', |
|
2424
|
|
|
'get_items' => array( |
|
2425
|
|
|
'function' => 'list_getUserErrors', |
|
2426
|
|
|
'params' => array( |
|
2427
|
|
|
'le.ip >= ' . $ip_string[0] . ' and le.ip <= ' . $ip_string[1], |
|
2428
|
|
|
$fields, |
|
2429
|
|
|
), |
|
2430
|
|
|
), |
|
2431
|
|
|
'get_count' => array( |
|
2432
|
|
|
'function' => 'list_getUserErrorCount', |
|
2433
|
|
|
'params' => array( |
|
2434
|
|
|
'ip >= ' . $ip_string[0] . ' and ip <= ' . $ip_string[1], |
|
2435
|
|
|
$fields, |
|
2436
|
|
|
), |
|
2437
|
|
|
), |
|
2438
|
|
|
'columns' => array( |
|
2439
|
|
|
'ip_address2' => array( |
|
2440
|
|
|
'header' => array( |
|
2441
|
|
|
'value' => $txt['ip_address'], |
|
2442
|
|
|
), |
|
2443
|
|
|
'data' => array( |
|
2444
|
|
|
'sprintf' => array( |
|
2445
|
|
|
'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a>', |
|
2446
|
|
|
'params' => array( |
|
2447
|
|
|
'ip' => false, |
|
2448
|
|
|
), |
|
2449
|
|
|
), |
|
2450
|
|
|
), |
|
2451
|
|
|
'sort' => array( |
|
2452
|
|
|
'default' => 'le.ip', |
|
2453
|
|
|
'reverse' => 'le.ip DESC', |
|
2454
|
|
|
), |
|
2455
|
|
|
), |
|
2456
|
|
|
'display_name' => array( |
|
2457
|
|
|
'header' => array( |
|
2458
|
|
|
'value' => $txt['display_name'], |
|
2459
|
|
|
), |
|
2460
|
|
|
'data' => array( |
|
2461
|
|
|
'db' => 'member_link', |
|
2462
|
|
|
), |
|
2463
|
|
|
), |
|
2464
|
|
|
'message' => array( |
|
2465
|
|
|
'header' => array( |
|
2466
|
|
|
'value' => $txt['message'], |
|
2467
|
|
|
), |
|
2468
|
|
|
'data' => array( |
|
2469
|
|
|
'sprintf' => array( |
|
2470
|
|
|
'format' => '%1$s<br><a href="%2$s">%2$s</a>', |
|
2471
|
|
|
'params' => array( |
|
2472
|
|
|
'message' => false, |
|
2473
|
|
|
'url' => false, |
|
2474
|
|
|
), |
|
2475
|
|
|
), |
|
2476
|
|
|
), |
|
2477
|
|
|
), |
|
2478
|
|
|
'date2' => array( |
|
2479
|
|
|
'header' => array( |
|
2480
|
|
|
'value' => $txt['date'], |
|
2481
|
|
|
), |
|
2482
|
|
|
'data' => array( |
|
2483
|
|
|
'db' => 'time', |
|
2484
|
|
|
), |
|
2485
|
|
|
'sort' => array( |
|
2486
|
|
|
'default' => 'le.id_error DESC', |
|
2487
|
|
|
'reverse' => 'le.id_error', |
|
2488
|
|
|
), |
|
2489
|
|
|
), |
|
2490
|
|
|
), |
|
2491
|
|
|
'additional_rows' => array( |
|
2492
|
|
|
array( |
|
2493
|
|
|
'position' => 'after_title', |
|
2494
|
|
|
'value' => $txt['errors_from_ip_desc'], |
|
2495
|
|
|
), |
|
2496
|
|
|
), |
|
2497
|
|
|
); |
|
2498
|
|
|
|
|
2499
|
|
|
// Create the error list. |
|
2500
|
|
|
createList($listOptions); |
|
2501
|
|
|
|
|
2502
|
|
|
// Allow 3rd party integrations to add in their own lists or whatever. |
|
2503
|
|
|
$context['additional_track_lists'] = array(); |
|
2504
|
|
|
call_integration_hook('integrate_profile_trackip', array($ip_string, $ip_var)); |
|
2505
|
|
|
|
|
2506
|
|
|
$context['single_ip'] = ($ip_var['low'] === $ip_var['high']); |
|
2507
|
|
|
if ($context['single_ip']) |
|
2508
|
|
|
{ |
|
2509
|
|
|
$context['whois_servers'] = array( |
|
2510
|
|
|
'apnic' => array( |
|
2511
|
|
|
'name' => $txt['whois_apnic'], |
|
2512
|
|
|
'url' => 'https://wq.apnic.net/apnic-bin/whois.pl?searchtext=' . $context['ip'], |
|
2513
|
|
|
), |
|
2514
|
|
|
'arin' => array( |
|
2515
|
|
|
'name' => $txt['whois_arin'], |
|
2516
|
|
|
'url' => 'https://whois.arin.net/rest/ip/' . $context['ip'], |
|
2517
|
|
|
), |
|
2518
|
|
|
'lacnic' => array( |
|
2519
|
|
|
'name' => $txt['whois_lacnic'], |
|
2520
|
|
|
'url' => 'https://lacnic.net/cgi-bin/lacnic/whois?query=' . $context['ip'], |
|
2521
|
|
|
), |
|
2522
|
|
|
'ripe' => array( |
|
2523
|
|
|
'name' => $txt['whois_ripe'], |
|
2524
|
|
|
'url' => 'https://apps.db.ripe.net/search/query.html?searchtext=' . $context['ip'], |
|
2525
|
|
|
), |
|
2526
|
|
|
); |
|
2527
|
|
|
} |
|
2528
|
|
|
} |
|
2529
|
|
|
|
|
2530
|
|
|
/** |
|
2531
|
|
|
* Tracks a user's logins. |
|
2532
|
|
|
* |
|
2533
|
|
|
* @param int $memID The ID of the member |
|
2534
|
|
|
*/ |
|
2535
|
|
|
function TrackLogins($memID = 0) |
|
2536
|
|
|
{ |
|
2537
|
|
|
global $scripturl, $txt, $sourcedir, $context; |
|
2538
|
|
|
|
|
2539
|
|
|
// Gonna want this for the list. |
|
2540
|
|
|
require_once($sourcedir . '/Subs-List.php'); |
|
2541
|
|
|
|
|
2542
|
|
|
if ($memID == 0) |
|
2543
|
|
|
$context['base_url'] = $scripturl . '?action=trackip'; |
|
2544
|
|
|
else |
|
2545
|
|
|
$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID; |
|
2546
|
|
|
|
|
2547
|
|
|
// Start with the user messages. |
|
2548
|
|
|
$listOptions = array( |
|
2549
|
|
|
'id' => 'track_logins_list', |
|
2550
|
|
|
'title' => $txt['trackLogins'], |
|
2551
|
|
|
'no_items_label' => $txt['trackLogins_none_found'], |
|
2552
|
|
|
'base_href' => $context['base_url'], |
|
2553
|
|
|
'get_items' => array( |
|
2554
|
|
|
'function' => 'list_getLogins', |
|
2555
|
|
|
'params' => array( |
|
2556
|
|
|
'id_member = {int:current_member}', |
|
2557
|
|
|
array('current_member' => $memID), |
|
2558
|
|
|
), |
|
2559
|
|
|
), |
|
2560
|
|
|
'get_count' => array( |
|
2561
|
|
|
'function' => 'list_getLoginCount', |
|
2562
|
|
|
'params' => array( |
|
2563
|
|
|
'id_member = {int:current_member}', |
|
2564
|
|
|
array('current_member' => $memID), |
|
2565
|
|
|
), |
|
2566
|
|
|
), |
|
2567
|
|
|
'columns' => array( |
|
2568
|
|
|
'time' => array( |
|
2569
|
|
|
'header' => array( |
|
2570
|
|
|
'value' => $txt['date'], |
|
2571
|
|
|
), |
|
2572
|
|
|
'data' => array( |
|
2573
|
|
|
'db' => 'time', |
|
2574
|
|
|
), |
|
2575
|
|
|
), |
|
2576
|
|
|
'ip' => array( |
|
2577
|
|
|
'header' => array( |
|
2578
|
|
|
'value' => $txt['ip_address'], |
|
2579
|
|
|
), |
|
2580
|
|
|
'data' => array( |
|
2581
|
|
|
'sprintf' => array( |
|
2582
|
|
|
'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a> (<a href="' . $context['base_url'] . ';searchip=%2$s">%2$s</a>) ', |
|
2583
|
|
|
'params' => array( |
|
2584
|
|
|
'ip' => false, |
|
2585
|
|
|
'ip2' => false |
|
2586
|
|
|
), |
|
2587
|
|
|
), |
|
2588
|
|
|
), |
|
2589
|
|
|
), |
|
2590
|
|
|
), |
|
2591
|
|
|
'additional_rows' => array( |
|
2592
|
|
|
array( |
|
2593
|
|
|
'position' => 'after_title', |
|
2594
|
|
|
'value' => $txt['trackLogins_desc'], |
|
2595
|
|
|
), |
|
2596
|
|
|
), |
|
2597
|
|
|
); |
|
2598
|
|
|
|
|
2599
|
|
|
// Create the messages list. |
|
2600
|
|
|
createList($listOptions); |
|
2601
|
|
|
|
|
2602
|
|
|
$context['sub_template'] = 'show_list'; |
|
2603
|
|
|
$context['default_list'] = 'track_logins_list'; |
|
2604
|
|
|
} |
|
2605
|
|
|
|
|
2606
|
|
|
/** |
|
2607
|
|
|
* Finds the total number of tracked logins for a particular user |
|
2608
|
|
|
* |
|
2609
|
|
|
* @param string $where A query to limit which logins are counted |
|
2610
|
|
|
* @param array $where_vars An array of parameters for $where |
|
2611
|
|
|
* @return int count of messages matching the IP |
|
2612
|
|
|
*/ |
|
2613
|
|
|
function list_getLoginCount($where, $where_vars = array()) |
|
2614
|
|
|
{ |
|
2615
|
|
|
global $smcFunc; |
|
2616
|
|
|
|
|
2617
|
|
|
$request = $smcFunc['db_query']('', ' |
|
2618
|
|
|
SELECT COUNT(*) AS message_count |
|
2619
|
|
|
FROM {db_prefix}member_logins |
|
2620
|
|
|
WHERE id_member = {int:id_member}', |
|
2621
|
|
|
array( |
|
2622
|
|
|
'id_member' => $where_vars['current_member'], |
|
2623
|
|
|
) |
|
2624
|
|
|
); |
|
2625
|
|
|
list ($count) = $smcFunc['db_fetch_row']($request); |
|
2626
|
|
|
$smcFunc['db_free_result']($request); |
|
2627
|
|
|
|
|
2628
|
|
|
return (int) $count; |
|
2629
|
|
|
} |
|
2630
|
|
|
|
|
2631
|
|
|
/** |
|
2632
|
|
|
* Callback for the list in trackLogins. |
|
2633
|
|
|
* |
|
2634
|
|
|
* @param int $start Which item to start with (not used here) |
|
2635
|
|
|
* @param int $items_per_page How many items to show on each page (not used here) |
|
2636
|
|
|
* @param string $sort A string indicating |
|
2637
|
|
|
* @param string $where A query to filter results (not used here) |
|
2638
|
|
|
* @param array $where_vars An array of parameters for $where. Only 'current_member' (the ID of the member) is used here |
|
2639
|
|
|
* @return array An array of information about user logins |
|
2640
|
|
|
*/ |
|
2641
|
|
|
function list_getLogins($start, $items_per_page, $sort, $where, $where_vars = array()) |
|
2642
|
|
|
{ |
|
2643
|
|
|
global $smcFunc; |
|
2644
|
|
|
|
|
2645
|
|
|
$request = $smcFunc['db_query']('', ' |
|
2646
|
|
|
SELECT time, ip, ip2 |
|
2647
|
|
|
FROM {db_prefix}member_logins |
|
2648
|
|
|
WHERE id_member = {int:id_member} |
|
2649
|
|
|
ORDER BY time DESC', |
|
2650
|
|
|
array( |
|
2651
|
|
|
'id_member' => $where_vars['current_member'], |
|
2652
|
|
|
) |
|
2653
|
|
|
); |
|
2654
|
|
|
$logins = array(); |
|
2655
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2656
|
|
|
$logins[] = array( |
|
2657
|
|
|
'time' => timeformat($row['time']), |
|
2658
|
|
|
'ip' => inet_dtop($row['ip']), |
|
2659
|
|
|
'ip2' => inet_dtop($row['ip2']), |
|
2660
|
|
|
); |
|
2661
|
|
|
$smcFunc['db_free_result']($request); |
|
2662
|
|
|
|
|
2663
|
|
|
return $logins; |
|
2664
|
|
|
} |
|
2665
|
|
|
|
|
2666
|
|
|
/** |
|
2667
|
|
|
* Tracks a user's profile edits |
|
2668
|
|
|
* |
|
2669
|
|
|
* @param int $memID The ID of the member |
|
2670
|
|
|
*/ |
|
2671
|
|
|
function trackEdits($memID) |
|
2672
|
|
|
{ |
|
2673
|
|
|
global $scripturl, $txt, $modSettings, $sourcedir, $context, $smcFunc; |
|
2674
|
|
|
|
|
2675
|
|
|
require_once($sourcedir . '/Subs-List.php'); |
|
2676
|
|
|
|
|
2677
|
|
|
// Get the names of any custom fields. |
|
2678
|
|
|
$request = $smcFunc['db_query']('', ' |
|
2679
|
|
|
SELECT col_name, field_name, bbc |
|
2680
|
|
|
FROM {db_prefix}custom_fields', |
|
2681
|
|
|
array( |
|
2682
|
|
|
) |
|
2683
|
|
|
); |
|
2684
|
|
|
$context['custom_field_titles'] = array(); |
|
2685
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2686
|
|
|
$context['custom_field_titles']['customfield_' . $row['col_name']] = array( |
|
2687
|
|
|
'title' => $row['field_name'], |
|
2688
|
|
|
'parse_bbc' => $row['bbc'], |
|
2689
|
|
|
); |
|
2690
|
|
|
$smcFunc['db_free_result']($request); |
|
2691
|
|
|
|
|
2692
|
|
|
// Set the options for the error lists. |
|
2693
|
|
|
$listOptions = array( |
|
2694
|
|
|
'id' => 'edit_list', |
|
2695
|
|
|
'title' => $txt['trackEdits'], |
|
2696
|
|
|
'items_per_page' => $modSettings['defaultMaxListItems'], |
|
2697
|
|
|
'no_items_label' => $txt['trackEdit_no_edits'], |
|
2698
|
|
|
'base_href' => $scripturl . '?action=profile;area=tracking;sa=edits;u=' . $memID, |
|
2699
|
|
|
'default_sort_col' => 'time', |
|
2700
|
|
|
'get_items' => array( |
|
2701
|
|
|
'function' => 'list_getProfileEdits', |
|
2702
|
|
|
'params' => array( |
|
2703
|
|
|
$memID, |
|
2704
|
|
|
), |
|
2705
|
|
|
), |
|
2706
|
|
|
'get_count' => array( |
|
2707
|
|
|
'function' => 'list_getProfileEditCount', |
|
2708
|
|
|
'params' => array( |
|
2709
|
|
|
$memID, |
|
2710
|
|
|
), |
|
2711
|
|
|
), |
|
2712
|
|
|
'columns' => array( |
|
2713
|
|
|
'action' => array( |
|
2714
|
|
|
'header' => array( |
|
2715
|
|
|
'value' => $txt['trackEdit_action'], |
|
2716
|
|
|
), |
|
2717
|
|
|
'data' => array( |
|
2718
|
|
|
'db' => 'action_text', |
|
2719
|
|
|
), |
|
2720
|
|
|
), |
|
2721
|
|
|
'before' => array( |
|
2722
|
|
|
'header' => array( |
|
2723
|
|
|
'value' => $txt['trackEdit_before'], |
|
2724
|
|
|
), |
|
2725
|
|
|
'data' => array( |
|
2726
|
|
|
'db' => 'before', |
|
2727
|
|
|
), |
|
2728
|
|
|
), |
|
2729
|
|
|
'after' => array( |
|
2730
|
|
|
'header' => array( |
|
2731
|
|
|
'value' => $txt['trackEdit_after'], |
|
2732
|
|
|
), |
|
2733
|
|
|
'data' => array( |
|
2734
|
|
|
'db' => 'after', |
|
2735
|
|
|
), |
|
2736
|
|
|
), |
|
2737
|
|
|
'time' => array( |
|
2738
|
|
|
'header' => array( |
|
2739
|
|
|
'value' => $txt['date'], |
|
2740
|
|
|
), |
|
2741
|
|
|
'data' => array( |
|
2742
|
|
|
'db' => 'time', |
|
2743
|
|
|
), |
|
2744
|
|
|
'sort' => array( |
|
2745
|
|
|
'default' => 'id_action DESC', |
|
2746
|
|
|
'reverse' => 'id_action', |
|
2747
|
|
|
), |
|
2748
|
|
|
), |
|
2749
|
|
|
'applicator' => array( |
|
2750
|
|
|
'header' => array( |
|
2751
|
|
|
'value' => $txt['trackEdit_applicator'], |
|
2752
|
|
|
), |
|
2753
|
|
|
'data' => array( |
|
2754
|
|
|
'db' => 'member_link', |
|
2755
|
|
|
), |
|
2756
|
|
|
), |
|
2757
|
|
|
), |
|
2758
|
|
|
); |
|
2759
|
|
|
|
|
2760
|
|
|
// Create the error list. |
|
2761
|
|
|
createList($listOptions); |
|
2762
|
|
|
|
|
2763
|
|
|
$context['sub_template'] = 'show_list'; |
|
2764
|
|
|
$context['default_list'] = 'edit_list'; |
|
2765
|
|
|
} |
|
2766
|
|
|
|
|
2767
|
|
|
/** |
|
2768
|
|
|
* How many edits? |
|
2769
|
|
|
* |
|
2770
|
|
|
* @param int $memID The ID of the member |
|
2771
|
|
|
* @return int The number of profile edits |
|
2772
|
|
|
*/ |
|
2773
|
|
|
function list_getProfileEditCount($memID) |
|
2774
|
|
|
{ |
|
2775
|
|
|
global $smcFunc; |
|
2776
|
|
|
|
|
2777
|
|
|
$request = $smcFunc['db_query']('', ' |
|
2778
|
|
|
SELECT COUNT(*) AS edit_count |
|
2779
|
|
|
FROM {db_prefix}log_actions |
|
2780
|
|
|
WHERE id_log = {int:log_type} |
|
2781
|
|
|
AND id_member = {int:owner}', |
|
2782
|
|
|
array( |
|
2783
|
|
|
'log_type' => 2, |
|
2784
|
|
|
'owner' => $memID, |
|
2785
|
|
|
) |
|
2786
|
|
|
); |
|
2787
|
|
|
list ($edit_count) = $smcFunc['db_fetch_row']($request); |
|
2788
|
|
|
$smcFunc['db_free_result']($request); |
|
2789
|
|
|
|
|
2790
|
|
|
return (int) $edit_count; |
|
2791
|
|
|
} |
|
2792
|
|
|
|
|
2793
|
|
|
/** |
|
2794
|
|
|
* Loads up information about a user's profile edits. Callback for the list in trackEdits() |
|
2795
|
|
|
* |
|
2796
|
|
|
* @param int $start Which item to start with (for pagination purposes) |
|
2797
|
|
|
* @param int $items_per_page How many items to show on each page |
|
2798
|
|
|
* @param string $sort A string indicating how to sort the results |
|
2799
|
|
|
* @param int $memID The ID of the member |
|
2800
|
|
|
* @return array An array of information about the profile edits |
|
2801
|
|
|
*/ |
|
2802
|
|
|
function list_getProfileEdits($start, $items_per_page, $sort, $memID) |
|
2803
|
|
|
{ |
|
2804
|
|
|
global $smcFunc, $txt, $scripturl, $context; |
|
2805
|
|
|
|
|
2806
|
|
|
// Get a list of error messages from this ip (range). |
|
2807
|
|
|
$request = $smcFunc['db_query']('', ' |
|
2808
|
|
|
SELECT |
|
2809
|
|
|
id_action, id_member, ip, log_time, action, extra |
|
2810
|
|
|
FROM {db_prefix}log_actions |
|
2811
|
|
|
WHERE id_log = {int:log_type} |
|
2812
|
|
|
AND id_member = {int:owner} |
|
2813
|
|
|
ORDER BY {raw:sort} |
|
2814
|
|
|
LIMIT {int:start}, {int:max}', |
|
2815
|
|
|
array( |
|
2816
|
|
|
'log_type' => 2, |
|
2817
|
|
|
'owner' => $memID, |
|
2818
|
|
|
'sort' => $sort, |
|
2819
|
|
|
'start' => $start, |
|
2820
|
|
|
'max' => $items_per_page, |
|
2821
|
|
|
) |
|
2822
|
|
|
); |
|
2823
|
|
|
$edits = array(); |
|
2824
|
|
|
$members = array(); |
|
2825
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2826
|
|
|
{ |
|
2827
|
|
|
$extra = $smcFunc['json_decode']($row['extra'], true); |
|
2828
|
|
|
if (!empty($extra['applicator'])) |
|
2829
|
|
|
$members[] = $extra['applicator']; |
|
2830
|
|
|
|
|
2831
|
|
|
// Work out what the name of the action is. |
|
2832
|
|
|
if (isset($txt['trackEdit_action_' . $row['action']])) |
|
2833
|
|
|
$action_text = $txt['trackEdit_action_' . $row['action']]; |
|
2834
|
|
|
elseif (isset($txt[$row['action']])) |
|
2835
|
|
|
$action_text = $txt[$row['action']]; |
|
2836
|
|
|
// Custom field? |
|
2837
|
|
|
elseif (isset($context['custom_field_titles'][$row['action']])) |
|
2838
|
|
|
$action_text = $context['custom_field_titles'][$row['action']]['title']; |
|
2839
|
|
|
else |
|
2840
|
|
|
$action_text = $row['action']; |
|
2841
|
|
|
|
|
2842
|
|
|
// Parse BBC? |
|
2843
|
|
|
$parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false; |
|
2844
|
|
|
|
|
2845
|
|
|
$edits[] = array( |
|
2846
|
|
|
'id' => $row['id_action'], |
|
2847
|
|
|
'ip' => inet_dtop($row['ip']), |
|
2848
|
|
|
'id_member' => !empty($extra['applicator']) ? $extra['applicator'] : 0, |
|
2849
|
|
|
'member_link' => $txt['trackEdit_deleted_member'], |
|
2850
|
|
|
'action' => $row['action'], |
|
2851
|
|
|
'action_text' => $action_text, |
|
2852
|
|
|
'before' => !empty($extra['previous']) ? ($parse_bbc ? parse_bbc($extra['previous']) : $extra['previous']) : '', |
|
2853
|
|
|
'after' => !empty($extra['new']) ? ($parse_bbc ? parse_bbc($extra['new']) : $extra['new']) : '', |
|
2854
|
|
|
'time' => timeformat($row['log_time']), |
|
2855
|
|
|
); |
|
2856
|
|
|
} |
|
2857
|
|
|
$smcFunc['db_free_result']($request); |
|
2858
|
|
|
|
|
2859
|
|
|
// Get any member names. |
|
2860
|
|
|
if (!empty($members)) |
|
2861
|
|
|
{ |
|
2862
|
|
|
$request = $smcFunc['db_query']('', ' |
|
2863
|
|
|
SELECT |
|
2864
|
|
|
id_member, real_name |
|
2865
|
|
|
FROM {db_prefix}members |
|
2866
|
|
|
WHERE id_member IN ({array_int:members})', |
|
2867
|
|
|
array( |
|
2868
|
|
|
'members' => $members, |
|
2869
|
|
|
) |
|
2870
|
|
|
); |
|
2871
|
|
|
$members = array(); |
|
2872
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2873
|
|
|
$members[$row['id_member']] = $row['real_name']; |
|
2874
|
|
|
$smcFunc['db_free_result']($request); |
|
2875
|
|
|
|
|
2876
|
|
|
foreach ($edits as $key => $value) |
|
2877
|
|
|
if (isset($members[$value['id_member']])) |
|
2878
|
|
|
$edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>'; |
|
2879
|
|
|
} |
|
2880
|
|
|
|
|
2881
|
|
|
return $edits; |
|
2882
|
|
|
} |
|
2883
|
|
|
|
|
2884
|
|
|
/** |
|
2885
|
|
|
* Display the history of group requests made by the user whose profile we are viewing. |
|
2886
|
|
|
* |
|
2887
|
|
|
* @param int $memID The ID of the member |
|
2888
|
|
|
*/ |
|
2889
|
|
|
function trackGroupReq($memID) |
|
2890
|
|
|
{ |
|
2891
|
|
|
global $scripturl, $txt, $modSettings, $sourcedir, $context; |
|
2892
|
|
|
|
|
2893
|
|
|
require_once($sourcedir . '/Subs-List.php'); |
|
2894
|
|
|
|
|
2895
|
|
|
// Set the options for the error lists. |
|
2896
|
|
|
$listOptions = array( |
|
2897
|
|
|
'id' => 'request_list', |
|
2898
|
|
|
'title' => sprintf($txt['trackGroupRequests_title'], $context['member']['name']), |
|
2899
|
|
|
'items_per_page' => $modSettings['defaultMaxListItems'], |
|
2900
|
|
|
'no_items_label' => $txt['requested_none'], |
|
2901
|
|
|
'base_href' => $scripturl . '?action=profile;area=tracking;sa=groupreq;u=' . $memID, |
|
2902
|
|
|
'default_sort_col' => 'time_applied', |
|
2903
|
|
|
'get_items' => array( |
|
2904
|
|
|
'function' => 'list_getGroupRequests', |
|
2905
|
|
|
'params' => array( |
|
2906
|
|
|
$memID, |
|
2907
|
|
|
), |
|
2908
|
|
|
), |
|
2909
|
|
|
'get_count' => array( |
|
2910
|
|
|
'function' => 'list_getGroupRequestsCount', |
|
2911
|
|
|
'params' => array( |
|
2912
|
|
|
$memID, |
|
2913
|
|
|
), |
|
2914
|
|
|
), |
|
2915
|
|
|
'columns' => array( |
|
2916
|
|
|
'group' => array( |
|
2917
|
|
|
'header' => array( |
|
2918
|
|
|
'value' => $txt['requested_group'], |
|
2919
|
|
|
), |
|
2920
|
|
|
'data' => array( |
|
2921
|
|
|
'db' => 'group_name', |
|
2922
|
|
|
), |
|
2923
|
|
|
), |
|
2924
|
|
|
'group_reason' => array( |
|
2925
|
|
|
'header' => array( |
|
2926
|
|
|
'value' => $txt['requested_group_reason'], |
|
2927
|
|
|
), |
|
2928
|
|
|
'data' => array( |
|
2929
|
|
|
'db' => 'group_reason', |
|
2930
|
|
|
), |
|
2931
|
|
|
), |
|
2932
|
|
|
'time_applied' => array( |
|
2933
|
|
|
'header' => array( |
|
2934
|
|
|
'value' => $txt['requested_group_time'], |
|
2935
|
|
|
), |
|
2936
|
|
|
'data' => array( |
|
2937
|
|
|
'db' => 'time_applied', |
|
2938
|
|
|
'timeformat' => true, |
|
2939
|
|
|
), |
|
2940
|
|
|
'sort' => array( |
|
2941
|
|
|
'default' => 'time_applied DESC', |
|
2942
|
|
|
'reverse' => 'time_applied', |
|
2943
|
|
|
), |
|
2944
|
|
|
), |
|
2945
|
|
|
'outcome' => array( |
|
2946
|
|
|
'header' => array( |
|
2947
|
|
|
'value' => $txt['requested_group_outcome'], |
|
2948
|
|
|
), |
|
2949
|
|
|
'data' => array( |
|
2950
|
|
|
'db' => 'outcome', |
|
2951
|
|
|
), |
|
2952
|
|
|
), |
|
2953
|
|
|
), |
|
2954
|
|
|
); |
|
2955
|
|
|
|
|
2956
|
|
|
// Create the error list. |
|
2957
|
|
|
createList($listOptions); |
|
2958
|
|
|
|
|
2959
|
|
|
$context['sub_template'] = 'show_list'; |
|
2960
|
|
|
$context['default_list'] = 'request_list'; |
|
2961
|
|
|
} |
|
2962
|
|
|
|
|
2963
|
|
|
/** |
|
2964
|
|
|
* How many edits? |
|
2965
|
|
|
* |
|
2966
|
|
|
* @param int $memID The ID of the member |
|
2967
|
|
|
* @return int The number of profile edits |
|
2968
|
|
|
*/ |
|
2969
|
|
|
function list_getGroupRequestsCount($memID) |
|
2970
|
|
|
{ |
|
2971
|
|
|
global $smcFunc, $user_info; |
|
2972
|
|
|
|
|
2973
|
|
|
$request = $smcFunc['db_query']('', ' |
|
2974
|
|
|
SELECT COUNT(*) AS req_count |
|
2975
|
|
|
FROM {db_prefix}log_group_requests AS lgr |
|
2976
|
|
|
WHERE id_member = {int:memID} |
|
2977
|
|
|
AND ' . ($user_info['mod_cache']['gq'] == '1=1' ? $user_info['mod_cache']['gq'] : 'lgr.' . $user_info['mod_cache']['gq']), |
|
2978
|
|
|
array( |
|
2979
|
|
|
'memID' => $memID, |
|
2980
|
|
|
) |
|
2981
|
|
|
); |
|
2982
|
|
|
list ($report_count) = $smcFunc['db_fetch_row']($request); |
|
2983
|
|
|
$smcFunc['db_free_result']($request); |
|
2984
|
|
|
|
|
2985
|
|
|
return (int) $report_count; |
|
2986
|
|
|
} |
|
2987
|
|
|
|
|
2988
|
|
|
/** |
|
2989
|
|
|
* Loads up information about a user's group requests. Callback for the list in trackGroupReq() |
|
2990
|
|
|
* |
|
2991
|
|
|
* @param int $start Which item to start with (for pagination purposes) |
|
2992
|
|
|
* @param int $items_per_page How many items to show on each page |
|
2993
|
|
|
* @param string $sort A string indicating how to sort the results |
|
2994
|
|
|
* @param int $memID The ID of the member |
|
2995
|
|
|
* @return array An array of information about the user's group requests |
|
2996
|
|
|
*/ |
|
2997
|
|
|
function list_getGroupRequests($start, $items_per_page, $sort, $memID) |
|
2998
|
|
|
{ |
|
2999
|
|
|
global $smcFunc, $txt, $scripturl, $user_info; |
|
3000
|
|
|
|
|
3001
|
|
|
$groupreq = array(); |
|
3002
|
|
|
|
|
3003
|
|
|
$request = $smcFunc['db_query']('', ' |
|
3004
|
|
|
SELECT |
|
3005
|
|
|
lgr.id_group, mg.group_name, mg.online_color, lgr.time_applied, lgr.reason, lgr.status, |
|
3006
|
|
|
ma.id_member AS id_member_acted, COALESCE(ma.member_name, lgr.member_name_acted) AS act_name, lgr.time_acted, lgr.act_reason |
|
3007
|
|
|
FROM {db_prefix}log_group_requests AS lgr |
|
3008
|
|
|
LEFT JOIN {db_prefix}members AS ma ON (lgr.id_member_acted = ma.id_member) |
|
3009
|
|
|
INNER JOIN {db_prefix}membergroups AS mg ON (lgr.id_group = mg.id_group) |
|
3010
|
|
|
WHERE lgr.id_member = {int:memID} |
|
3011
|
|
|
AND ' . ($user_info['mod_cache']['gq'] == '1=1' ? $user_info['mod_cache']['gq'] : 'lgr.' . $user_info['mod_cache']['gq']) . ' |
|
3012
|
|
|
ORDER BY {raw:sort} |
|
3013
|
|
|
LIMIT {int:start}, {int:max}', |
|
3014
|
|
|
array( |
|
3015
|
|
|
'memID' => $memID, |
|
3016
|
|
|
'sort' => $sort, |
|
3017
|
|
|
'start' => $start, |
|
3018
|
|
|
'max' => $items_per_page, |
|
3019
|
|
|
) |
|
3020
|
|
|
); |
|
3021
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
3022
|
|
|
{ |
|
3023
|
|
|
$this_req = array( |
|
3024
|
|
|
'group_name' => empty($row['online_color']) ? $row['group_name'] : '<span style="color:' . $row['online_color'] . '">' . $row['group_name'] . '</span>', |
|
3025
|
|
|
'group_reason' => $row['reason'], |
|
3026
|
|
|
'time_applied' => $row['time_applied'], |
|
3027
|
|
|
); |
|
3028
|
|
|
switch ($row['status']) |
|
3029
|
|
|
{ |
|
3030
|
|
|
case 0: |
|
3031
|
|
|
$this_req['outcome'] = $txt['outcome_pending']; |
|
3032
|
|
|
break; |
|
3033
|
|
|
case 1: |
|
3034
|
|
|
$member_link = empty($row['id_member_acted']) ? $row['act_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_acted'] . '">' . $row['act_name'] . '</a>'; |
|
3035
|
|
|
$this_req['outcome'] = sprintf($txt['outcome_approved'], $member_link, timeformat($row['time_acted'])); |
|
3036
|
|
|
break; |
|
3037
|
|
|
case 2: |
|
3038
|
|
|
$member_link = empty($row['id_member_acted']) ? $row['act_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_acted'] . '">' . $row['act_name'] . '</a>'; |
|
3039
|
|
|
$this_req['outcome'] = sprintf(!empty($row['act_reason']) ? $txt['outcome_refused_reason'] : $txt['outcome_refused'], $member_link, timeformat($row['time_acted']), $row['act_reason']); |
|
3040
|
|
|
break; |
|
3041
|
|
|
} |
|
3042
|
|
|
|
|
3043
|
|
|
$groupreq[] = $this_req; |
|
3044
|
|
|
} |
|
3045
|
|
|
$smcFunc['db_free_result']($request); |
|
3046
|
|
|
|
|
3047
|
|
|
return $groupreq; |
|
3048
|
|
|
} |
|
3049
|
|
|
|
|
3050
|
|
|
/** |
|
3051
|
|
|
* Shows which permissions a user has |
|
3052
|
|
|
* |
|
3053
|
|
|
* @param int $memID The ID of the member |
|
3054
|
|
|
*/ |
|
3055
|
|
|
function showPermissions($memID) |
|
3056
|
|
|
{ |
|
3057
|
|
|
global $txt, $board; |
|
3058
|
|
|
global $user_profile, $context, $sourcedir, $smcFunc; |
|
3059
|
|
|
|
|
3060
|
|
|
// Verify if the user has sufficient permissions. |
|
3061
|
|
|
isAllowedTo('manage_permissions'); |
|
3062
|
|
|
|
|
3063
|
|
|
loadLanguage('ManagePermissions'); |
|
3064
|
|
|
loadLanguage('Admin'); |
|
3065
|
|
|
loadTemplate('ManageMembers'); |
|
3066
|
|
|
|
|
3067
|
|
|
// Load all the permission profiles. |
|
3068
|
|
|
require_once($sourcedir . '/ManagePermissions.php'); |
|
3069
|
|
|
loadPermissionProfiles(); |
|
3070
|
|
|
|
|
3071
|
|
|
$context['member']['id'] = $memID; |
|
3072
|
|
|
$context['member']['name'] = $user_profile[$memID]['real_name']; |
|
3073
|
|
|
|
|
3074
|
|
|
$context['page_title'] = $txt['showPermissions']; |
|
3075
|
|
|
$board = empty($board) ? 0 : (int) $board; |
|
3076
|
|
|
$context['board'] = $board; |
|
3077
|
|
|
|
|
3078
|
|
|
// Determine which groups this user is in. |
|
3079
|
|
|
if (empty($user_profile[$memID]['additional_groups'])) |
|
3080
|
|
|
$curGroups = array(); |
|
3081
|
|
|
else |
|
3082
|
|
|
$curGroups = explode(',', $user_profile[$memID]['additional_groups']); |
|
3083
|
|
|
$curGroups[] = $user_profile[$memID]['id_group']; |
|
3084
|
|
|
$curGroups[] = $user_profile[$memID]['id_post_group']; |
|
3085
|
|
|
|
|
3086
|
|
|
// Load a list of boards for the jump box - except the defaults. |
|
3087
|
|
|
$request = $smcFunc['db_query']('order_by_board_order', ' |
|
3088
|
|
|
SELECT b.id_board, b.name, b.id_profile, b.member_groups, COALESCE(mods.id_member, modgs.id_group, 0) AS is_mod |
|
3089
|
|
|
FROM {db_prefix}boards AS b |
|
3090
|
|
|
LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member}) |
|
3091
|
|
|
LEFT JOIN {db_prefix}moderator_groups AS modgs ON (modgs.id_board = b.id_board AND modgs.id_group IN ({array_int:current_groups})) |
|
3092
|
|
|
WHERE {query_see_board}', |
|
3093
|
|
|
array( |
|
3094
|
|
|
'current_member' => $memID, |
|
3095
|
|
|
'current_groups' => $curGroups, |
|
3096
|
|
|
) |
|
3097
|
|
|
); |
|
3098
|
|
|
$context['boards'] = array(); |
|
3099
|
|
|
$context['no_access_boards'] = array(); |
|
3100
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
3101
|
|
|
{ |
|
3102
|
|
|
if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) |
|
3103
|
|
|
$context['no_access_boards'][] = array( |
|
3104
|
|
|
'id' => $row['id_board'], |
|
3105
|
|
|
'name' => $row['name'], |
|
3106
|
|
|
'is_last' => false, |
|
3107
|
|
|
); |
|
3108
|
|
|
elseif ($row['id_profile'] != 1 || $row['is_mod']) |
|
3109
|
|
|
$context['boards'][$row['id_board']] = array( |
|
3110
|
|
|
'id' => $row['id_board'], |
|
3111
|
|
|
'name' => $row['name'], |
|
3112
|
|
|
'selected' => $board == $row['id_board'], |
|
3113
|
|
|
'profile' => $row['id_profile'], |
|
3114
|
|
|
'profile_name' => $context['profiles'][$row['id_profile']]['name'], |
|
3115
|
|
|
); |
|
3116
|
|
|
} |
|
3117
|
|
|
$smcFunc['db_free_result']($request); |
|
3118
|
|
|
|
|
3119
|
|
|
require_once($sourcedir . '/Subs-Boards.php'); |
|
3120
|
|
|
sortBoards($context['boards']); |
|
3121
|
|
|
|
|
3122
|
|
|
if (!empty($context['no_access_boards'])) |
|
3123
|
|
|
$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true; |
|
3124
|
|
|
|
|
3125
|
|
|
$context['member']['permissions'] = array( |
|
3126
|
|
|
'general' => array(), |
|
3127
|
|
|
'board' => array() |
|
3128
|
|
|
); |
|
3129
|
|
|
|
|
3130
|
|
|
// If you're an admin we know you can do everything, we might as well leave. |
|
3131
|
|
|
$context['member']['has_all_permissions'] = in_array(1, $curGroups); |
|
3132
|
|
|
if ($context['member']['has_all_permissions']) |
|
3133
|
|
|
return; |
|
3134
|
|
|
|
|
3135
|
|
|
$denied = array(); |
|
3136
|
|
|
|
|
3137
|
|
|
// Get all general permissions. |
|
3138
|
|
|
$result = $smcFunc['db_query']('', ' |
|
3139
|
|
|
SELECT p.permission, p.add_deny, mg.group_name, p.id_group |
|
3140
|
|
|
FROM {db_prefix}permissions AS p |
|
3141
|
|
|
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = p.id_group) |
|
3142
|
|
|
WHERE p.id_group IN ({array_int:group_list}) |
|
3143
|
|
|
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', |
|
3144
|
|
|
array( |
|
3145
|
|
|
'group_list' => $curGroups, |
|
3146
|
|
|
'newbie_group' => 4, |
|
3147
|
|
|
) |
|
3148
|
|
|
); |
|
3149
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
3150
|
|
|
{ |
|
3151
|
|
|
// We don't know about this permission, it doesn't exist :P. |
|
3152
|
|
|
if (!isset($txt['permissionname_' . $row['permission']])) |
|
3153
|
|
|
continue; |
|
3154
|
|
|
|
|
3155
|
|
|
if (empty($row['add_deny'])) |
|
3156
|
|
|
$denied[] = $row['permission']; |
|
3157
|
|
|
|
|
3158
|
|
|
// Permissions that end with _own or _any consist of two parts. |
|
3159
|
|
|
if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) |
|
3160
|
|
|
$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']]; |
|
3161
|
|
|
else |
|
3162
|
|
|
$name = $txt['permissionname_' . $row['permission']]; |
|
3163
|
|
|
|
|
3164
|
|
|
// Add this permission if it doesn't exist yet. |
|
3165
|
|
|
if (!isset($context['member']['permissions']['general'][$row['permission']])) |
|
3166
|
|
|
$context['member']['permissions']['general'][$row['permission']] = array( |
|
3167
|
|
|
'id' => $row['permission'], |
|
3168
|
|
|
'groups' => array( |
|
3169
|
|
|
'allowed' => array(), |
|
3170
|
|
|
'denied' => array() |
|
3171
|
|
|
), |
|
3172
|
|
|
'name' => $name, |
|
3173
|
|
|
'is_denied' => false, |
|
3174
|
|
|
'is_global' => true, |
|
3175
|
|
|
); |
|
3176
|
|
|
|
|
3177
|
|
|
// Add the membergroup to either the denied or the allowed groups. |
|
3178
|
|
|
$context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name']; |
|
3179
|
|
|
|
|
3180
|
|
|
// Once denied is always denied. |
|
3181
|
|
|
$context['member']['permissions']['general'][$row['permission']]['is_denied'] |= empty($row['add_deny']); |
|
3182
|
|
|
} |
|
3183
|
|
|
$smcFunc['db_free_result']($result); |
|
3184
|
|
|
|
|
3185
|
|
|
$request = $smcFunc['db_query']('', ' |
|
3186
|
|
|
SELECT |
|
3187
|
|
|
bp.add_deny, bp.permission, bp.id_group, mg.group_name' . (empty($board) ? '' : ', |
|
3188
|
|
|
b.id_profile, CASE WHEN (mods.id_member IS NULL AND modgs.id_group IS NULL) THEN 0 ELSE 1 END AS is_moderator') . ' |
|
3189
|
|
|
FROM {db_prefix}board_permissions AS bp' . (empty($board) ? '' : ' |
|
3190
|
|
|
INNER JOIN {db_prefix}boards AS b ON (b.id_board = {int:current_board}) |
|
3191
|
|
|
LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member}) |
|
3192
|
|
|
LEFT JOIN {db_prefix}moderator_groups AS modgs ON (modgs.id_board = b.id_board AND modgs.id_group IN ({array_int:group_list}))') . ' |
|
3193
|
|
|
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = bp.id_group) |
|
3194
|
|
|
WHERE bp.id_profile = {raw:current_profile} |
|
3195
|
|
|
AND bp.id_group IN ({array_int:group_list}' . (empty($board) ? ')' : ', {int:moderator_group}) |
|
3196
|
|
|
AND (mods.id_member IS NOT NULL OR modgs.id_group IS NOT NULL OR bp.id_group != {int:moderator_group})'), |
|
3197
|
|
|
array( |
|
3198
|
|
|
'current_board' => $board, |
|
3199
|
|
|
'group_list' => $curGroups, |
|
3200
|
|
|
'current_member' => $memID, |
|
3201
|
|
|
'current_profile' => empty($board) ? '1' : 'b.id_profile', |
|
3202
|
|
|
'moderator_group' => 3, |
|
3203
|
|
|
) |
|
3204
|
|
|
); |
|
3205
|
|
|
|
|
3206
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
3207
|
|
|
{ |
|
3208
|
|
|
// We don't know about this permission, it doesn't exist :P. |
|
3209
|
|
|
if (!isset($txt['permissionname_' . $row['permission']])) |
|
3210
|
|
|
continue; |
|
3211
|
|
|
|
|
3212
|
|
|
// The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'. |
|
3213
|
|
|
if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) |
|
3214
|
|
|
$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']]; |
|
3215
|
|
|
else |
|
3216
|
|
|
$name = $txt['permissionname_' . $row['permission']]; |
|
3217
|
|
|
|
|
3218
|
|
|
// Create the structure for this permission. |
|
3219
|
|
|
if (!isset($context['member']['permissions']['board'][$row['permission']])) |
|
3220
|
|
|
$context['member']['permissions']['board'][$row['permission']] = array( |
|
3221
|
|
|
'id' => $row['permission'], |
|
3222
|
|
|
'groups' => array( |
|
3223
|
|
|
'allowed' => array(), |
|
3224
|
|
|
'denied' => array() |
|
3225
|
|
|
), |
|
3226
|
|
|
'name' => $name, |
|
3227
|
|
|
'is_denied' => false, |
|
3228
|
|
|
'is_global' => empty($board), |
|
3229
|
|
|
); |
|
3230
|
|
|
|
|
3231
|
|
|
$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']; |
|
3232
|
|
|
|
|
3233
|
|
|
$context['member']['permissions']['board'][$row['permission']]['is_denied'] |= empty($row['add_deny']); |
|
3234
|
|
|
} |
|
3235
|
|
|
$smcFunc['db_free_result']($request); |
|
3236
|
|
|
} |
|
3237
|
|
|
|
|
3238
|
|
|
/** |
|
3239
|
|
|
* View a member's warnings |
|
3240
|
|
|
* |
|
3241
|
|
|
* @param int $memID The ID of the member |
|
3242
|
|
|
*/ |
|
3243
|
|
|
function viewWarning($memID) |
|
3244
|
|
|
{ |
|
3245
|
|
|
global $modSettings, $context, $sourcedir, $txt, $scripturl; |
|
3246
|
|
|
|
|
3247
|
|
|
// Firstly, can we actually even be here? |
|
3248
|
|
|
if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum')) |
|
3249
|
|
|
fatal_lang_error('no_access', false); |
|
3250
|
|
|
|
|
3251
|
|
|
// Make sure things which are disabled stay disabled. |
|
3252
|
|
|
$modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110; |
|
3253
|
|
|
$modSettings['warning_moderate'] = !empty($modSettings['warning_moderate']) && !empty($modSettings['postmod_active']) ? $modSettings['warning_moderate'] : 110; |
|
3254
|
|
|
$modSettings['warning_mute'] = !empty($modSettings['warning_mute']) ? $modSettings['warning_mute'] : 110; |
|
3255
|
|
|
|
|
3256
|
|
|
// Let's use a generic list to get all the current warnings, and use the issue warnings grab-a-granny thing. |
|
3257
|
|
|
require_once($sourcedir . '/Subs-List.php'); |
|
3258
|
|
|
require_once($sourcedir . '/Profile-Actions.php'); |
|
3259
|
|
|
|
|
3260
|
|
|
$listOptions = array( |
|
3261
|
|
|
'id' => 'view_warnings', |
|
3262
|
|
|
'title' => $txt['profile_viewwarning_previous_warnings'], |
|
3263
|
|
|
'items_per_page' => $modSettings['defaultMaxListItems'], |
|
3264
|
|
|
'no_items_label' => $txt['profile_viewwarning_no_warnings'], |
|
3265
|
|
|
'base_href' => $scripturl . '?action=profile;area=viewwarning;sa=user;u=' . $memID, |
|
3266
|
|
|
'default_sort_col' => 'log_time', |
|
3267
|
|
|
'get_items' => array( |
|
3268
|
|
|
'function' => 'list_getUserWarnings', |
|
3269
|
|
|
'params' => array( |
|
3270
|
|
|
$memID, |
|
3271
|
|
|
), |
|
3272
|
|
|
), |
|
3273
|
|
|
'get_count' => array( |
|
3274
|
|
|
'function' => 'list_getUserWarningCount', |
|
3275
|
|
|
'params' => array( |
|
3276
|
|
|
$memID, |
|
3277
|
|
|
), |
|
3278
|
|
|
), |
|
3279
|
|
|
'columns' => array( |
|
3280
|
|
|
'log_time' => array( |
|
3281
|
|
|
'header' => array( |
|
3282
|
|
|
'value' => $txt['profile_warning_previous_time'], |
|
3283
|
|
|
), |
|
3284
|
|
|
'data' => array( |
|
3285
|
|
|
'db' => 'time', |
|
3286
|
|
|
), |
|
3287
|
|
|
'sort' => array( |
|
3288
|
|
|
'default' => 'lc.log_time DESC', |
|
3289
|
|
|
'reverse' => 'lc.log_time', |
|
3290
|
|
|
), |
|
3291
|
|
|
), |
|
3292
|
|
|
'reason' => array( |
|
3293
|
|
|
'header' => array( |
|
3294
|
|
|
'value' => $txt['profile_warning_previous_reason'], |
|
3295
|
|
|
'style' => 'width: 50%;', |
|
3296
|
|
|
), |
|
3297
|
|
|
'data' => array( |
|
3298
|
|
|
'db' => 'reason', |
|
3299
|
|
|
), |
|
3300
|
|
|
), |
|
3301
|
|
|
'level' => array( |
|
3302
|
|
|
'header' => array( |
|
3303
|
|
|
'value' => $txt['profile_warning_previous_level'], |
|
3304
|
|
|
), |
|
3305
|
|
|
'data' => array( |
|
3306
|
|
|
'db' => 'counter', |
|
3307
|
|
|
), |
|
3308
|
|
|
'sort' => array( |
|
3309
|
|
|
'default' => 'lc.counter DESC', |
|
3310
|
|
|
'reverse' => 'lc.counter', |
|
3311
|
|
|
), |
|
3312
|
|
|
), |
|
3313
|
|
|
), |
|
3314
|
|
|
'additional_rows' => array( |
|
3315
|
|
|
array( |
|
3316
|
|
|
'position' => 'after_title', |
|
3317
|
|
|
'value' => $txt['profile_viewwarning_desc'], |
|
3318
|
|
|
'class' => 'smalltext', |
|
3319
|
|
|
'style' => 'padding: 2ex;', |
|
3320
|
|
|
), |
|
3321
|
|
|
), |
|
3322
|
|
|
); |
|
3323
|
|
|
|
|
3324
|
|
|
// Create the list for viewing. |
|
3325
|
|
|
require_once($sourcedir . '/Subs-List.php'); |
|
3326
|
|
|
createList($listOptions); |
|
3327
|
|
|
|
|
3328
|
|
|
// Create some common text bits for the template. |
|
3329
|
|
|
$context['level_effects'] = array( |
|
3330
|
|
|
0 => '', |
|
3331
|
|
|
$modSettings['warning_watch'] => $txt['profile_warning_effect_own_watched'], |
|
3332
|
|
|
$modSettings['warning_moderate'] => $txt['profile_warning_effect_own_moderated'], |
|
3333
|
|
|
$modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'], |
|
3334
|
|
|
); |
|
3335
|
|
|
$context['current_level'] = 0; |
|
3336
|
|
|
foreach ($context['level_effects'] as $limit => $dummy) |
|
3337
|
|
|
if ($context['member']['warning'] >= $limit) |
|
3338
|
|
|
$context['current_level'] = $limit; |
|
3339
|
|
|
} |
|
3340
|
|
|
|
|
3341
|
|
|
/** |
|
3342
|
|
|
* Sets the icon for a fetched alert. |
|
3343
|
|
|
* |
|
3344
|
|
|
* @param array The alert that we want to set an icon for. |
|
|
|
|
|
|
3345
|
|
|
*/ |
|
3346
|
|
|
function set_alert_icon($alert) |
|
3347
|
|
|
{ |
|
3348
|
|
|
global $settings; |
|
3349
|
|
|
|
|
3350
|
|
|
switch ($alert['content_type']) |
|
3351
|
|
|
{ |
|
3352
|
|
|
case 'topic': |
|
3353
|
|
|
case 'board': |
|
3354
|
|
|
{ |
|
3355
|
|
|
switch ($alert['content_action']) |
|
3356
|
|
|
{ |
|
3357
|
|
|
case 'reply': |
|
3358
|
|
|
case 'topic': |
|
3359
|
|
|
$class = 'main_icons posts'; |
|
3360
|
|
|
break; |
|
3361
|
|
|
|
|
3362
|
|
|
case 'move': |
|
3363
|
|
|
$src = $settings['images_url'] . '/post/moved.png'; |
|
3364
|
|
|
break; |
|
3365
|
|
|
|
|
3366
|
|
|
case 'remove': |
|
3367
|
|
|
$class = 'main_icons delete'; |
|
3368
|
|
|
break; |
|
3369
|
|
|
|
|
3370
|
|
|
case 'lock': |
|
3371
|
|
|
case 'unlock': |
|
3372
|
|
|
$class = 'main_icons lock'; |
|
3373
|
|
|
break; |
|
3374
|
|
|
|
|
3375
|
|
|
case 'sticky': |
|
3376
|
|
|
case 'unsticky': |
|
3377
|
|
|
$class = 'main_icons sticky'; |
|
3378
|
|
|
break; |
|
3379
|
|
|
|
|
3380
|
|
|
case 'split': |
|
3381
|
|
|
$class = 'main_icons split_button'; |
|
3382
|
|
|
break; |
|
3383
|
|
|
|
|
3384
|
|
|
case 'merge': |
|
3385
|
|
|
$class = 'main_icons merge'; |
|
3386
|
|
|
break; |
|
3387
|
|
|
|
|
3388
|
|
|
case 'unapproved_topic': |
|
3389
|
|
|
case 'unapproved_post': |
|
3390
|
|
|
$class = 'main_icons post_moderation_moderate'; |
|
3391
|
|
|
break; |
|
3392
|
|
|
|
|
3393
|
|
|
default: |
|
3394
|
|
|
$class = 'main_icons posts'; |
|
3395
|
|
|
break; |
|
3396
|
|
|
} |
|
3397
|
|
|
} |
|
3398
|
|
|
break; |
|
3399
|
|
|
|
|
3400
|
|
|
case 'msg': |
|
3401
|
|
|
{ |
|
3402
|
|
|
switch ($alert['content_action']) |
|
3403
|
|
|
{ |
|
3404
|
|
|
case 'like': |
|
3405
|
|
|
$class = 'main_icons like'; |
|
3406
|
|
|
break; |
|
3407
|
|
|
|
|
3408
|
|
|
case 'mention': |
|
3409
|
|
|
$class = 'main_icons im_on'; |
|
3410
|
|
|
break; |
|
3411
|
|
|
|
|
3412
|
|
|
case 'quote': |
|
3413
|
|
|
$class = 'main_icons quote'; |
|
3414
|
|
|
break; |
|
3415
|
|
|
|
|
3416
|
|
|
case 'unapproved_attachment': |
|
3417
|
|
|
$class = 'main_icons post_moderation_attach'; |
|
3418
|
|
|
break; |
|
3419
|
|
|
|
|
3420
|
|
|
case 'report': |
|
3421
|
|
|
case 'report_reply': |
|
3422
|
|
|
$class = 'main_icons post_moderation_moderate'; |
|
3423
|
|
|
break; |
|
3424
|
|
|
|
|
3425
|
|
|
default: |
|
3426
|
|
|
$class = 'main_icons posts'; |
|
3427
|
|
|
break; |
|
3428
|
|
|
} |
|
3429
|
|
|
} |
|
3430
|
|
|
break; |
|
3431
|
|
|
|
|
3432
|
|
|
case 'member': |
|
3433
|
|
|
{ |
|
3434
|
|
|
switch ($alert['content_action']) |
|
3435
|
|
|
{ |
|
3436
|
|
|
case 'register_standard': |
|
3437
|
|
|
case 'register_approval': |
|
3438
|
|
|
case 'register_activation': |
|
3439
|
|
|
$class = 'main_icons members'; |
|
3440
|
|
|
break; |
|
3441
|
|
|
|
|
3442
|
|
|
case 'report': |
|
3443
|
|
|
case 'report_reply': |
|
3444
|
|
|
$class = 'main_icons members_watched'; |
|
3445
|
|
|
break; |
|
3446
|
|
|
|
|
3447
|
|
|
case 'buddy_request': |
|
3448
|
|
|
$class = 'main_icons people'; |
|
3449
|
|
|
break; |
|
3450
|
|
|
|
|
3451
|
|
|
case 'group_request': |
|
3452
|
|
|
$class = 'main_icons members_request'; |
|
3453
|
|
|
break; |
|
3454
|
|
|
|
|
3455
|
|
|
default: |
|
3456
|
|
|
$class = 'main_icons members'; |
|
3457
|
|
|
break; |
|
3458
|
|
|
} |
|
3459
|
|
|
} |
|
3460
|
|
|
break; |
|
3461
|
|
|
|
|
3462
|
|
|
case 'groupr': |
|
3463
|
|
|
$class = 'main_icons members_request'; |
|
3464
|
|
|
break; |
|
3465
|
|
|
|
|
3466
|
|
|
case 'event': |
|
3467
|
|
|
$class = 'main_icons calendar'; |
|
3468
|
|
|
break; |
|
3469
|
|
|
|
|
3470
|
|
|
case 'paidsubs': |
|
3471
|
|
|
$class = 'main_icons paid'; |
|
3472
|
|
|
break; |
|
3473
|
|
|
|
|
3474
|
|
|
case 'birthday': |
|
3475
|
|
|
$src = $settings['images_url'] . '/cake.png'; |
|
3476
|
|
|
break; |
|
3477
|
|
|
|
|
3478
|
|
|
default: |
|
3479
|
|
|
$class = 'main_icons alerts'; |
|
3480
|
|
|
break; |
|
3481
|
|
|
} |
|
3482
|
|
|
|
|
3483
|
|
|
if (isset($class)) |
|
3484
|
|
|
return '<span class="alert_icon ' . $class . '"></span>'; |
|
3485
|
|
|
elseif (isset($src)) |
|
3486
|
|
|
return '<img class="alert_icon" src="' . $src . '">'; |
|
3487
|
|
|
else |
|
3488
|
|
|
return ''; |
|
3489
|
|
|
} |
|
3490
|
|
|
|
|
3491
|
|
|
?> |