1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Perform CRUD actions for reported posts and moderation comments. |
||
5 | * |
||
6 | * Simple Machines Forum (SMF) |
||
7 | * |
||
8 | * @package SMF |
||
9 | * @author Simple Machines https://www.simplemachines.org |
||
10 | * @copyright 2022 Simple Machines and individual contributors |
||
11 | * @license https://www.simplemachines.org/about/smf/license.php BSD |
||
12 | * |
||
13 | * @version 2.1.3 |
||
14 | */ |
||
15 | |||
16 | if (!defined('SMF')) |
||
17 | die('No direct access...'); |
||
18 | |||
19 | /** |
||
20 | * Updates a report with the given parameters. Logs each action via logAction() |
||
21 | * |
||
22 | * @param string $action The action to perform. Accepts "closed" and "ignore". |
||
23 | * @param integer $value The new value to update. |
||
24 | * @param integer|array $report_id The affected report(s). |
||
25 | * |
||
26 | * @return bool |
||
27 | */ |
||
28 | function updateReport($action, $value, $report_id) |
||
29 | { |
||
30 | global $smcFunc, $user_info, $context; |
||
31 | |||
32 | // Don't bother. |
||
33 | if (empty($action) || empty($report_id)) |
||
34 | return false; |
||
35 | |||
36 | // Add the "_all" thingy. |
||
37 | if ($action == 'ignore') |
||
38 | $action = 'ignore_all'; |
||
39 | |||
40 | // We don't need the board query for reported members |
||
41 | if ($context['report_type'] == 'members') |
||
42 | { |
||
43 | $board_query = ''; |
||
44 | } |
||
45 | else |
||
46 | { |
||
47 | $board_query = ' AND ' . $user_info['mod_cache']['bq']; |
||
48 | } |
||
49 | |||
50 | // Update the report... |
||
51 | $smcFunc['db_query']('', ' |
||
52 | UPDATE {db_prefix}log_reported |
||
53 | SET {raw:action} = {string:value} |
||
54 | ' . (is_array($report_id) ? 'WHERE id_report IN ({array_int:id_report})' : 'WHERE id_report = {int:id_report}') . ' |
||
55 | ' . $board_query, |
||
56 | array( |
||
57 | 'action' => $action, |
||
58 | 'value' => $value, |
||
59 | 'id_report' => $report_id, |
||
60 | ) |
||
61 | ); |
||
62 | |||
63 | // From now on, lets work with arrays, makes life easier. |
||
64 | $report_id = (array) $report_id; |
||
65 | |||
66 | // Set up the data for the log... |
||
67 | $extra = array(); |
||
68 | |||
69 | if ($context['report_type'] == 'posts') |
||
70 | { |
||
71 | // Get the board, topic and message for this report |
||
72 | $request = $smcFunc['db_query']('', ' |
||
73 | SELECT id_board, id_topic, id_msg, id_report |
||
74 | FROM {db_prefix}log_reported |
||
75 | WHERE id_report IN ({array_int:id_report})', |
||
76 | array( |
||
77 | 'id_report' => $report_id, |
||
78 | ) |
||
79 | ); |
||
80 | |||
81 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
82 | $extra[$row['id_report']] = array( |
||
83 | 'report' => $row['id_report'], |
||
84 | 'board' => $row['id_board'], |
||
85 | 'message' => $row['id_msg'], |
||
86 | 'topic' => $row['id_topic'], |
||
87 | ); |
||
88 | |||
89 | $smcFunc['db_free_result']($request); |
||
90 | } |
||
91 | else |
||
92 | { |
||
93 | $request = $smcFunc['db_query']('', ' |
||
94 | SELECT id_report, id_member, membername |
||
95 | FROM {db_prefix}log_reported |
||
96 | WHERE id_report IN ({array_int:id_report})', |
||
97 | array( |
||
98 | 'id_report' => $report_id, |
||
99 | ) |
||
100 | ); |
||
101 | |||
102 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
103 | $extra[$row['id_report']] = array( |
||
104 | 'report' => $row['id_report'], |
||
105 | 'member' => $row['id_member'], |
||
106 | ); |
||
107 | |||
108 | $smcFunc['db_free_result']($request); |
||
109 | } |
||
110 | |||
111 | // Back to "ignore". |
||
112 | if ($action == 'ignore_all') |
||
113 | $action = 'ignore'; |
||
114 | |||
115 | $log_report = $action == 'ignore' ? (!empty($value) ? 'ignore' : 'unignore') : (!empty($value) ? 'close' : 'open'); |
||
116 | |||
117 | if ($context['report_type'] == 'members') |
||
118 | $log_report .= '_user'; |
||
119 | |||
120 | // See if any report alerts need to be cleaned up upon close/ignore |
||
121 | if (in_array($log_report, array('close', 'ignore', 'close_user', 'ignore_user'))) |
||
122 | clearReportAlerts($log_report, $extra); |
||
123 | |||
124 | // Log this action. |
||
125 | if (!empty($extra)) |
||
126 | foreach ($extra as $report) |
||
127 | logAction($log_report . '_report', $report); |
||
128 | |||
129 | // Time to update. |
||
130 | updateSettings(array('last_mod_report_action' => time())); |
||
131 | recountOpenReports($context['report_type']); |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * Upon close/ignore, mark unread alerts as read. |
||
136 | * |
||
137 | * @param string $log_report - what action is being taken |
||
138 | * @param mixed[] $extra - detailed info about the report |
||
139 | * @return void |
||
140 | */ |
||
141 | function clearReportAlerts($log_report, $extra) |
||
142 | { |
||
143 | global $smcFunc; |
||
144 | |||
145 | // Setup the query, depending on if it's a member report or a msg report. |
||
146 | // In theory, these should be unique (reports for the same things get combined), but since $extra is an array, treat as an array. |
||
147 | if (strpos($log_report, '_user') !== false) |
||
148 | { |
||
149 | $content_ids = array_unique(array_column($extra, 'member')); |
||
150 | $content_type = 'member'; |
||
151 | } |
||
152 | else |
||
153 | { |
||
154 | $content_ids = array_unique(array_column($extra, 'message')); |
||
155 | $content_type = 'msg'; |
||
156 | } |
||
157 | |||
158 | // Check to see if there are unread alerts to flag as read... |
||
159 | // Might be multiple alerts, for multiple moderators... |
||
160 | $alerts = array(); |
||
161 | $moderators = array(); |
||
162 | $result = $smcFunc['db_query']('', ' |
||
163 | SELECT id_alert, id_member FROM {db_prefix}user_alerts |
||
164 | WHERE content_id IN ({array_int:content_ids}) |
||
165 | AND content_type = {string:content_type} |
||
166 | AND content_action = {string:content_action} |
||
167 | AND is_read = {int:unread}', |
||
168 | array( |
||
169 | 'content_ids' => $content_ids, |
||
170 | 'content_type' => $content_type, |
||
171 | 'content_action' => 'report', |
||
172 | 'unread' => 0, |
||
173 | ) |
||
174 | ); |
||
175 | // Found any? |
||
176 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
||
177 | { |
||
178 | $alerts[] = $row['id_alert']; |
||
179 | $moderators[] = $row['id_member']; |
||
180 | } |
||
181 | if (!empty($alerts)) |
||
182 | { |
||
183 | // Flag 'em as read |
||
184 | $smcFunc['db_query']('', ' |
||
185 | UPDATE {db_prefix}user_alerts |
||
186 | SET is_read = {int:time} |
||
187 | WHERE id_alert IN ({array_int:alerts})', |
||
188 | array( |
||
189 | 'time' => time(), |
||
190 | 'alerts' => $alerts, |
||
191 | ) |
||
192 | ); |
||
193 | // Decrement counter for each moderator who had an unread alert |
||
194 | updateMemberData($moderators, array('alerts' => '-')); |
||
195 | } |
||
196 | } |
||
197 | |||
198 | /** |
||
199 | * Counts how many reports are in total. Used for creating pagination. |
||
200 | * |
||
201 | * @param int $closed 1 for counting closed reports, 0 for open ones. |
||
202 | * @return integer How many reports. |
||
203 | */ |
||
204 | function countReports($closed = 0) |
||
205 | { |
||
206 | global $smcFunc, $user_info, $context; |
||
207 | |||
208 | // Skip entries with id_board = 0 if we're viewing member reports |
||
209 | if ($context['report_type'] == 'members') |
||
210 | { |
||
211 | $and = 'lr.id_board = 0'; |
||
212 | } |
||
213 | else |
||
214 | { |
||
215 | if ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1') |
||
216 | { |
||
217 | $bq = $user_info['mod_cache']['bq']; |
||
218 | } |
||
219 | else |
||
220 | { |
||
221 | $bq = 'lr.' . $user_info['mod_cache']['bq']; |
||
222 | } |
||
223 | |||
224 | $and = $bq . ' AND lr.id_board != 0'; |
||
225 | } |
||
226 | |||
227 | // How many entries are we viewing? |
||
228 | $request = $smcFunc['db_query']('', ' |
||
229 | SELECT COUNT(*) |
||
230 | FROM {db_prefix}log_reported AS lr |
||
231 | WHERE lr.closed = {int:view_closed} |
||
232 | AND ' . $and, |
||
233 | array( |
||
234 | 'view_closed' => (int) $closed, |
||
235 | ) |
||
236 | ); |
||
237 | list ($total_reports) = $smcFunc['db_fetch_row']($request); |
||
238 | $smcFunc['db_free_result']($request); |
||
239 | |||
240 | return $total_reports; |
||
241 | } |
||
242 | |||
243 | /** |
||
244 | * Get all possible reports the current user can see. |
||
245 | * |
||
246 | * @param int $closed 1 for closed reports, 0 for open ones. |
||
247 | * @return array the reports data with the report ID as key. |
||
248 | */ |
||
249 | function getReports($closed = 0) |
||
250 | { |
||
251 | global $smcFunc, $context, $user_info, $scripturl, $txt; |
||
252 | |||
253 | // Lonely, standalone var. |
||
254 | $reports = array(); |
||
255 | |||
256 | // By George, that means we are in a position to get the reports, golly good. |
||
257 | if ($context['report_type'] == 'members') |
||
258 | { |
||
259 | $request = $smcFunc['db_query']('', ' |
||
260 | SELECT lr.id_report, lr.id_member, |
||
261 | lr.time_started, lr.time_updated, lr.num_reports, lr.closed, lr.ignore_all, |
||
262 | COALESCE(mem.real_name, lr.membername) AS user_name, COALESCE(mem.id_member, 0) AS id_user |
||
263 | FROM {db_prefix}log_reported AS lr |
||
264 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member) |
||
265 | WHERE lr.closed = {int:view_closed} |
||
266 | AND lr.id_board = 0 |
||
267 | ORDER BY lr.time_updated DESC |
||
268 | LIMIT {int:start}, {int:max}', |
||
269 | array( |
||
270 | 'view_closed' => (int) $closed, |
||
271 | 'start' => $context['start'], |
||
272 | 'max' => 10, |
||
273 | ) |
||
274 | ); |
||
275 | } |
||
276 | else |
||
277 | { |
||
278 | $request = $smcFunc['db_query']('', ' |
||
279 | SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject, lr.body, |
||
280 | lr.time_started, lr.time_updated, lr.num_reports, lr.closed, lr.ignore_all, |
||
281 | COALESCE(mem.real_name, lr.membername) AS author_name, COALESCE(mem.id_member, 0) AS id_author |
||
282 | FROM {db_prefix}log_reported AS lr |
||
283 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member) |
||
284 | WHERE lr.closed = {int:view_closed} |
||
285 | AND lr.id_board != 0 |
||
286 | AND ' . ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1' ? $user_info['mod_cache']['bq'] : 'lr.' . $user_info['mod_cache']['bq']) . ' |
||
287 | ORDER BY lr.time_updated DESC |
||
288 | LIMIT {int:start}, {int:max}', |
||
289 | array( |
||
290 | 'view_closed' => (int) $closed, |
||
291 | 'start' => $context['start'], |
||
292 | 'max' => 10, |
||
293 | ) |
||
294 | ); |
||
295 | } |
||
296 | |||
297 | $report_ids = array(); |
||
298 | $report_boards_ids = array(); |
||
299 | $i = 0; |
||
300 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
301 | { |
||
302 | $report_ids[] = $row['id_report']; |
||
303 | $reports[$row['id_report']] = array( |
||
304 | 'id' => $row['id_report'], |
||
305 | 'report_href' => $scripturl . '?action=moderate;area=reported' . $context['report_type'] . ';sa=details;rid=' . $row['id_report'], |
||
306 | 'comments' => array(), |
||
307 | 'time_started' => timeformat($row['time_started']), |
||
308 | 'last_updated' => timeformat($row['time_updated']), |
||
309 | 'num_reports' => $row['num_reports'], |
||
310 | 'closed' => $row['closed'], |
||
311 | 'ignore' => $row['ignore_all'] |
||
312 | ); |
||
313 | |||
314 | if ($context['report_type'] == 'members') |
||
315 | { |
||
316 | $extraDetails = array( |
||
317 | 'user' => array( |
||
318 | 'id' => $row['id_user'], |
||
319 | 'name' => $row['user_name'], |
||
320 | 'link' => $row['id_user'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_user'] . '">' . $row['user_name'] . '</a>' : $row['user_name'], |
||
321 | 'href' => $scripturl . '?action=profile;u=' . $row['id_user'], |
||
322 | ), |
||
323 | ); |
||
324 | } |
||
325 | else |
||
326 | { |
||
327 | $report_boards_ids[] = $row['id_board']; |
||
328 | $extraDetails = array( |
||
329 | 'topic' => array( |
||
330 | 'id' => $row['id_topic'], |
||
331 | 'id_msg' => $row['id_msg'], |
||
332 | 'id_board' => $row['id_board'], |
||
333 | 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'], |
||
334 | ), |
||
335 | 'author' => array( |
||
336 | 'id' => $row['id_author'], |
||
337 | 'name' => $row['author_name'], |
||
338 | 'link' => $row['id_author'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_author'] . '">' . $row['author_name'] . '</a>' : $row['author_name'], |
||
339 | 'href' => $scripturl . '?action=profile;u=' . $row['id_author'], |
||
340 | ), |
||
341 | 'subject' => $row['subject'], |
||
342 | 'body' => parse_bbc($row['body']), |
||
343 | ); |
||
344 | } |
||
345 | |||
346 | $reports[$row['id_report']] = array_merge($reports[$row['id_report']], $extraDetails); |
||
347 | $i++; |
||
348 | } |
||
349 | $smcFunc['db_free_result']($request); |
||
350 | |||
351 | // Get the names of boards those topics are in. Slightly faster this way. |
||
352 | if (!empty($report_boards_ids)) |
||
353 | { |
||
354 | $report_boards_ids = array_unique($report_boards_ids); |
||
355 | $board_names = array(); |
||
356 | $request = $smcFunc['db_query']('', ' |
||
357 | SELECT id_board, name |
||
358 | FROM {db_prefix}boards |
||
359 | WHERE id_board IN ({array_int:boards})', |
||
360 | array( |
||
361 | 'boards' => $report_boards_ids, |
||
362 | ) |
||
363 | ); |
||
364 | |||
365 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
366 | $board_names[$row['id_board']] = $row['name']; |
||
367 | |||
368 | $smcFunc['db_free_result']($request); |
||
369 | |||
370 | foreach ($reports as $id_report => $report) |
||
371 | if (!empty($board_names[$report['topic']['id_board']])) |
||
372 | $reports[$id_report]['topic']['board_name'] = $board_names[$report['topic']['id_board']]; |
||
373 | } |
||
374 | |||
375 | // Now get all the people who reported it. |
||
376 | if (!empty($report_ids)) |
||
377 | { |
||
378 | $request = $smcFunc['db_query']('', ' |
||
379 | SELECT lrc.id_comment, lrc.id_report, lrc.time_sent, lrc.comment, |
||
380 | COALESCE(mem.id_member, 0) AS id_member, COALESCE(mem.real_name, lrc.membername) AS reporter |
||
381 | FROM {db_prefix}log_reported_comments AS lrc |
||
382 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lrc.id_member) |
||
383 | WHERE lrc.id_report IN ({array_int:report_list})', |
||
384 | array( |
||
385 | 'report_list' => $report_ids, |
||
386 | ) |
||
387 | ); |
||
388 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
389 | { |
||
390 | $reports[$row['id_report']]['comments'][] = array( |
||
391 | 'id' => $row['id_comment'], |
||
392 | 'message' => $row['comment'], |
||
393 | 'time' => timeformat($row['time_sent']), |
||
394 | 'member' => array( |
||
395 | 'id' => $row['id_member'], |
||
396 | 'name' => empty($row['reporter']) ? $txt['guest'] : $row['reporter'], |
||
397 | 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['reporter'] . '</a>' : (empty($row['reporter']) ? $txt['guest'] : $row['reporter']), |
||
398 | 'href' => $row['id_member'] ? $scripturl . '?action=profile;u=' . $row['id_member'] : '', |
||
399 | ), |
||
400 | ); |
||
401 | } |
||
402 | $smcFunc['db_free_result']($request); |
||
403 | } |
||
404 | |||
405 | // Get the boards where the current user can remove any message. |
||
406 | $context['report_remove_any_boards'] = $user_info['is_admin'] ? $report_boards_ids : array_intersect($report_boards_ids, boardsAllowedTo('remove_any')); |
||
407 | $context['report_manage_bans'] = allowedTo('manage_bans'); |
||
408 | |||
409 | return $reports; |
||
410 | } |
||
411 | |||
412 | /** |
||
413 | * Recount all open reports. Sets a SESSION var with the updated info. |
||
414 | * |
||
415 | * @param string $type the type of reports to count |
||
416 | * @return int the update open report count. |
||
417 | */ |
||
418 | function recountOpenReports($type) |
||
419 | { |
||
420 | global $user_info, $smcFunc; |
||
421 | |||
422 | if ($type == 'members') |
||
423 | $bq = ''; |
||
424 | else |
||
425 | $bq = ' AND ' . $user_info['mod_cache']['bq']; |
||
426 | |||
427 | $request = $smcFunc['db_query']('', ' |
||
428 | SELECT COUNT(*) |
||
429 | FROM {db_prefix}log_reported |
||
430 | WHERE closed = {int:not_closed} |
||
431 | AND ignore_all = {int:not_ignored} |
||
432 | AND id_board' . ($type == 'members' ? '' : '!') . '= {int:not_a_reported_post}' |
||
433 | . $bq, |
||
434 | array( |
||
435 | 'not_closed' => 0, |
||
436 | 'not_ignored' => 0, |
||
437 | 'not_a_reported_post' => 0, |
||
438 | ) |
||
439 | ); |
||
440 | list ($open_reports) = $smcFunc['db_fetch_row']($request); |
||
441 | $smcFunc['db_free_result']($request); |
||
442 | |||
443 | $arr = ($type == 'members' ? 'member_reports' : 'reports'); |
||
444 | $_SESSION['rc'] = array_merge(!empty($_SESSION['rc']) ? $_SESSION['rc'] : array(), |
||
445 | array( |
||
446 | 'id' => $user_info['id'], |
||
447 | 'time' => time(), |
||
448 | $arr => $open_reports, |
||
449 | )); |
||
450 | |||
451 | return $open_reports; |
||
452 | } |
||
453 | |||
454 | /** |
||
455 | * Gets additional information for a specific report. |
||
456 | * |
||
457 | * @param int $report_id The report ID to get the info from. |
||
458 | * @return array|bool the report data. Boolean false if no report_id was provided. |
||
459 | */ |
||
460 | function getReportDetails($report_id) |
||
461 | { |
||
462 | global $smcFunc, $user_info, $context; |
||
463 | |||
464 | if (empty($report_id)) |
||
465 | return false; |
||
466 | |||
467 | // We don't need all this info if we're only getting user info |
||
468 | if ($context['report_type'] == 'members') |
||
469 | { |
||
470 | $request = $smcFunc['db_query']('', ' |
||
471 | SELECT lr.id_report, lr.id_member, |
||
472 | lr.time_started, lr.time_updated, lr.num_reports, lr.closed, lr.ignore_all, |
||
473 | COALESCE(mem.real_name, lr.membername) AS user_name, COALESCE(mem.id_member, 0) AS id_user |
||
474 | FROM {db_prefix}log_reported AS lr |
||
475 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member) |
||
476 | WHERE lr.id_report = {int:id_report} |
||
477 | AND lr.id_board = 0 |
||
478 | LIMIT 1', |
||
479 | array( |
||
480 | 'id_report' => $report_id, |
||
481 | ) |
||
482 | ); |
||
483 | } |
||
484 | else |
||
485 | { |
||
486 | // Get the report details, need this so we can limit access to a particular board. |
||
487 | $request = $smcFunc['db_query']('', ' |
||
488 | SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject, lr.body, |
||
489 | lr.time_started, lr.time_updated, lr.num_reports, lr.closed, lr.ignore_all, |
||
490 | COALESCE(mem.real_name, lr.membername) AS author_name, COALESCE(mem.id_member, 0) AS id_author |
||
491 | FROM {db_prefix}log_reported AS lr |
||
492 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member) |
||
493 | WHERE lr.id_report = {int:id_report} |
||
494 | AND ' . ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1' ? $user_info['mod_cache']['bq'] : 'lr.' . $user_info['mod_cache']['bq']) . ' |
||
495 | LIMIT 1', |
||
496 | array( |
||
497 | 'id_report' => $report_id, |
||
498 | ) |
||
499 | ); |
||
500 | } |
||
501 | |||
502 | // So did we find anything? |
||
503 | if (!$smcFunc['db_num_rows']($request)) |
||
504 | return false; |
||
505 | |||
506 | // Woohoo we found a report and they can see it! |
||
507 | $row = $smcFunc['db_fetch_assoc']($request); |
||
508 | $smcFunc['db_free_result']($request); |
||
509 | |||
510 | return $row; |
||
511 | } |
||
512 | |||
513 | /** |
||
514 | * Gets both report comments as well as any moderator comment. |
||
515 | * |
||
516 | * @param int $report_id The report ID to get the info from. |
||
517 | * @return array|bool an associative array with 2 keys comments and mod_comments. Boolean false if no report_id was provided. |
||
518 | */ |
||
519 | function getReportComments($report_id) |
||
520 | { |
||
521 | global $smcFunc, $scripturl, $user_info, $txt; |
||
522 | |||
523 | if (empty($report_id)) |
||
524 | return false; |
||
525 | |||
526 | $report = array( |
||
527 | 'comments' => array(), |
||
528 | 'mod_comments' => array() |
||
529 | ); |
||
530 | |||
531 | // So what bad things do the reporters have to say about it? |
||
532 | $request = $smcFunc['db_query']('', ' |
||
533 | SELECT lrc.id_comment, lrc.id_report, lrc.time_sent, lrc.comment, lrc.member_ip, |
||
534 | COALESCE(mem.id_member, 0) AS id_member, COALESCE(mem.real_name, lrc.membername) AS reporter |
||
535 | FROM {db_prefix}log_reported_comments AS lrc |
||
536 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lrc.id_member) |
||
537 | WHERE lrc.id_report = {int:id_report}', |
||
538 | array( |
||
539 | 'id_report' => $report_id, |
||
540 | ) |
||
541 | ); |
||
542 | |||
543 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
544 | { |
||
545 | $report['comments'][] = array( |
||
546 | 'id' => $row['id_comment'], |
||
547 | 'message' => strtr($row['comment'], array("\n" => '<br>')), |
||
548 | 'time' => timeformat($row['time_sent']), |
||
549 | 'member' => array( |
||
550 | 'id' => $row['id_member'], |
||
551 | 'name' => empty($row['reporter']) ? $txt['guest'] : $row['reporter'], |
||
552 | 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['reporter'] . '</a>' : (empty($row['reporter']) ? $txt['guest'] : $row['reporter']), |
||
553 | 'href' => $row['id_member'] ? $scripturl . '?action=profile;u=' . $row['id_member'] : '', |
||
554 | 'ip' => !empty($row['member_ip']) && allowedTo('moderate_forum') ? '<a href="' . $scripturl . '?action=trackip;searchip=' . inet_dtop($row['member_ip']) . '">' . inet_dtop($row['member_ip']) . '</a>' : '', |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
555 | ), |
||
556 | ); |
||
557 | } |
||
558 | $smcFunc['db_free_result']($request); |
||
559 | |||
560 | // Hang about old chap, any comments from moderators on this one? |
||
561 | $request = $smcFunc['db_query']('', ' |
||
562 | SELECT lc.id_comment, lc.id_notice, lc.log_time, lc.body, |
||
563 | COALESCE(mem.id_member, 0) AS id_member, COALESCE(mem.real_name, lc.member_name) AS moderator |
||
564 | FROM {db_prefix}log_comments AS lc |
||
565 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member) |
||
566 | WHERE lc.id_notice = {int:id_report} |
||
567 | AND lc.comment_type = {literal:reportc}', |
||
568 | array( |
||
569 | 'id_report' => $report_id, |
||
570 | ) |
||
571 | ); |
||
572 | |||
573 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
574 | { |
||
575 | $report['mod_comments'][] = array( |
||
576 | 'id' => $row['id_comment'], |
||
577 | 'message' => parse_bbc($row['body']), |
||
578 | 'time' => timeformat($row['log_time']), |
||
579 | 'can_edit' => allowedTo('admin_forum') || (($user_info['id'] == $row['id_member'])), |
||
580 | 'member' => array( |
||
581 | 'id' => $row['id_member'], |
||
582 | 'name' => $row['moderator'], |
||
583 | 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['moderator'] . '</a>' : $row['moderator'], |
||
584 | 'href' => $scripturl . '?action=profile;u=' . $row['id_member'], |
||
585 | ), |
||
586 | ); |
||
587 | } |
||
588 | |||
589 | $smcFunc['db_free_result']($request); |
||
590 | |||
591 | return $report; |
||
592 | } |
||
593 | |||
594 | /** |
||
595 | * Gets specific details about a moderator comment. It also adds a permission for editing/deleting the comment, |
||
596 | * by default only admins and the author of the comment can edit/delete it. |
||
597 | * |
||
598 | * @param int $comment_id The moderator comment ID to get the info from. |
||
599 | * @return array|bool an array with the fetched data. Boolean false if no report_id was provided. |
||
600 | */ |
||
601 | function getCommentModDetails($comment_id) |
||
602 | { |
||
603 | global $smcFunc, $user_info; |
||
604 | |||
605 | if (empty($comment_id)) |
||
606 | return false; |
||
607 | |||
608 | $request = $smcFunc['db_query']('', ' |
||
609 | SELECT id_comment, id_notice, log_time, body, id_member |
||
610 | FROM {db_prefix}log_comments |
||
611 | WHERE id_comment = {int:id_comment} |
||
612 | AND comment_type = {literal:reportc}', |
||
613 | array( |
||
614 | 'id_comment' => $comment_id, |
||
615 | ) |
||
616 | ); |
||
617 | |||
618 | $comment = $smcFunc['db_fetch_assoc']($request); |
||
619 | |||
620 | $smcFunc['db_free_result']($request); |
||
621 | |||
622 | // Add the permission |
||
623 | if (!empty($comment)) |
||
624 | $comment['can_edit'] = allowedTo('admin_forum') || (($user_info['id'] == $comment['id_member'])); |
||
625 | |||
626 | return $comment; |
||
627 | } |
||
628 | |||
629 | /** |
||
630 | * Inserts a new moderator comment to the DB. |
||
631 | * |
||
632 | * @param int $report_id The report ID is used to fire a notification about the event. |
||
633 | * @param array $data a formatted array of data to be inserted. Should be already properly sanitized. |
||
634 | * @return bool Boolean false if no data was provided. |
||
635 | */ |
||
636 | function saveModComment($report_id, $data) |
||
637 | { |
||
638 | global $smcFunc, $user_info, $context; |
||
639 | |||
640 | if (empty($data)) |
||
641 | return false; |
||
642 | |||
643 | $report = getReportDetails($report_id); |
||
644 | |||
645 | if (empty($report)) |
||
646 | return false; |
||
647 | |||
648 | $data = array_merge(array($user_info['id'], $user_info['name'], 'reportc', ''), $data); |
||
649 | |||
650 | $last_comment = $smcFunc['db_insert']('', |
||
651 | '{db_prefix}log_comments', |
||
652 | array( |
||
653 | 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'recipient_name' => 'string', |
||
654 | 'id_notice' => 'int', 'body' => 'string', 'log_time' => 'int', |
||
655 | ), |
||
656 | $data, |
||
657 | array('id_comment'), |
||
658 | 1 |
||
659 | ); |
||
660 | |||
661 | if ($context['report_type'] == 'members') |
||
662 | { |
||
663 | $prefix = 'Member'; |
||
664 | $data = array( |
||
665 | 'report_id' => $report_id, |
||
666 | 'user_id' => $report['id_user'], |
||
667 | 'user_name' => $report['user_name'], |
||
668 | 'sender_id' => $context['user']['id'], |
||
669 | 'sender_name' => $context['user']['name'], |
||
670 | 'comment_id' => $last_comment, |
||
671 | 'time' => time(), |
||
672 | ); |
||
673 | } |
||
674 | else |
||
675 | { |
||
676 | $prefix = 'Msg'; |
||
677 | $data = array( |
||
678 | 'report_id' => $report_id, |
||
679 | 'comment_id' => $last_comment, |
||
680 | 'msg_id' => $report['id_msg'], |
||
681 | 'topic_id' => $report['id_topic'], |
||
682 | 'board_id' => $report['id_board'], |
||
683 | 'sender_id' => $user_info['id'], |
||
684 | 'sender_name' => $user_info['name'], |
||
685 | 'time' => time(), |
||
686 | ); |
||
687 | } |
||
688 | |||
689 | // And get ready to notify people. |
||
690 | if (!empty($report)) |
||
691 | $smcFunc['db_insert']('insert', |
||
692 | '{db_prefix}background_tasks', |
||
693 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
||
694 | array('$sourcedir/tasks/' . $prefix . 'ReportReply-Notify.php', $prefix . 'ReportReply_Notify_Background', $smcFunc['json_encode']($data), 0), |
||
695 | array('id_task') |
||
696 | ); |
||
697 | } |
||
698 | |||
699 | /** |
||
700 | * Saves the new information whenever a moderator comment is edited. |
||
701 | * |
||
702 | * @param int $comment_id The edited moderator comment ID. |
||
703 | * @param string $edited_comment The edited moderator comment text. |
||
704 | * @return bool Boolean false if no data or no comment ID was provided. |
||
705 | */ |
||
706 | function editModComment($comment_id, $edited_comment) |
||
707 | { |
||
708 | global $smcFunc; |
||
709 | |||
710 | if (empty($comment_id) || empty($edited_comment)) |
||
711 | return false; |
||
712 | |||
713 | $smcFunc['db_query']('', ' |
||
714 | UPDATE {db_prefix}log_comments |
||
715 | SET body = {string:body} |
||
716 | WHERE id_comment = {int:id_comment}', |
||
717 | array( |
||
718 | 'body' => $edited_comment, |
||
719 | 'id_comment' => $comment_id, |
||
720 | ) |
||
721 | ); |
||
722 | return true; |
||
723 | } |
||
724 | |||
725 | /** |
||
726 | * Deletes a moderator comment from the DB. |
||
727 | * |
||
728 | * @param int $comment_id The moderator comment ID used to identify which report will be deleted. |
||
729 | * @return bool Boolean false if no data was provided. |
||
730 | */ |
||
731 | function deleteModComment($comment_id) |
||
732 | { |
||
733 | global $smcFunc; |
||
734 | |||
735 | if (empty($comment_id)) |
||
736 | return false; |
||
737 | |||
738 | $smcFunc['db_query']('', ' |
||
739 | DELETE FROM {db_prefix}log_comments |
||
740 | WHERE id_comment = {int:comment_id}', |
||
741 | array( |
||
742 | 'comment_id' => $comment_id, |
||
743 | ) |
||
744 | ); |
||
745 | |||
746 | } |
||
747 | |||
748 | ?> |