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.0 |
||
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 | // Log this action. |
||
121 | if (!empty($extra)) |
||
122 | foreach ($extra as $report) |
||
123 | logAction($log_report . '_report', $report); |
||
124 | |||
125 | // Time to update. |
||
126 | updateSettings(array('last_mod_report_action' => time())); |
||
127 | recountOpenReports($context['report_type']); |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * Counts how many reports are in total. Used for creating pagination. |
||
132 | * |
||
133 | * @param int $closed 1 for counting closed reports, 0 for open ones. |
||
134 | * @return integer How many reports. |
||
135 | */ |
||
136 | function countReports($closed = 0) |
||
137 | { |
||
138 | global $smcFunc, $user_info, $context; |
||
139 | |||
140 | // Skip entries with id_board = 0 if we're viewing member reports |
||
141 | if ($context['report_type'] == 'members') |
||
142 | { |
||
143 | $and = 'lr.id_board = 0'; |
||
144 | } |
||
145 | else |
||
146 | { |
||
147 | if ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1') |
||
148 | { |
||
149 | $bq = $user_info['mod_cache']['bq']; |
||
150 | } |
||
151 | else |
||
152 | { |
||
153 | $bq = 'lr.' . $user_info['mod_cache']['bq']; |
||
154 | } |
||
155 | |||
156 | $and = $bq . ' AND lr.id_board != 0'; |
||
157 | } |
||
158 | |||
159 | // How many entries are we viewing? |
||
160 | $request = $smcFunc['db_query']('', ' |
||
161 | SELECT COUNT(*) |
||
162 | FROM {db_prefix}log_reported AS lr |
||
163 | WHERE lr.closed = {int:view_closed} |
||
164 | AND ' . $and, |
||
165 | array( |
||
166 | 'view_closed' => (int) $closed, |
||
167 | ) |
||
168 | ); |
||
169 | list ($total_reports) = $smcFunc['db_fetch_row']($request); |
||
170 | $smcFunc['db_free_result']($request); |
||
171 | |||
172 | return $total_reports; |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * Get all possible reports the current user can see. |
||
177 | * |
||
178 | * @param int $closed 1 for closed reports, 0 for open ones. |
||
179 | * @return array the reports data with the report ID as key. |
||
180 | */ |
||
181 | function getReports($closed = 0) |
||
182 | { |
||
183 | global $smcFunc, $context, $user_info, $scripturl, $txt; |
||
184 | |||
185 | // Lonely, standalone var. |
||
186 | $reports = array(); |
||
187 | |||
188 | // By George, that means we are in a position to get the reports, golly good. |
||
189 | if ($context['report_type'] == 'members') |
||
190 | { |
||
191 | $request = $smcFunc['db_query']('', ' |
||
192 | SELECT lr.id_report, lr.id_member, |
||
193 | lr.time_started, lr.time_updated, lr.num_reports, lr.closed, lr.ignore_all, |
||
194 | COALESCE(mem.real_name, lr.membername) AS user_name, COALESCE(mem.id_member, 0) AS id_user |
||
195 | FROM {db_prefix}log_reported AS lr |
||
196 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member) |
||
197 | WHERE lr.closed = {int:view_closed} |
||
198 | AND lr.id_board = 0 |
||
199 | ORDER BY lr.time_updated DESC |
||
200 | LIMIT {int:start}, {int:max}', |
||
201 | array( |
||
202 | 'view_closed' => (int) $closed, |
||
203 | 'start' => $context['start'], |
||
204 | 'max' => 10, |
||
205 | ) |
||
206 | ); |
||
207 | } |
||
208 | else |
||
209 | { |
||
210 | $request = $smcFunc['db_query']('', ' |
||
211 | SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject, lr.body, |
||
212 | lr.time_started, lr.time_updated, lr.num_reports, lr.closed, lr.ignore_all, |
||
213 | COALESCE(mem.real_name, lr.membername) AS author_name, COALESCE(mem.id_member, 0) AS id_author |
||
214 | FROM {db_prefix}log_reported AS lr |
||
215 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member) |
||
216 | WHERE lr.closed = {int:view_closed} |
||
217 | AND lr.id_board != 0 |
||
218 | 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']) . ' |
||
219 | ORDER BY lr.time_updated DESC |
||
220 | LIMIT {int:start}, {int:max}', |
||
221 | array( |
||
222 | 'view_closed' => (int) $closed, |
||
223 | 'start' => $context['start'], |
||
224 | 'max' => 10, |
||
225 | ) |
||
226 | ); |
||
227 | } |
||
228 | |||
229 | $report_ids = array(); |
||
230 | $report_boards_ids = array(); |
||
231 | $i = 0; |
||
232 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
233 | { |
||
234 | $report_ids[] = $row['id_report']; |
||
235 | $reports[$row['id_report']] = array( |
||
236 | 'id' => $row['id_report'], |
||
237 | 'report_href' => $scripturl . '?action=moderate;area=reported' . $context['report_type'] . ';sa=details;rid=' . $row['id_report'], |
||
238 | 'comments' => array(), |
||
239 | 'time_started' => timeformat($row['time_started']), |
||
240 | 'last_updated' => timeformat($row['time_updated']), |
||
241 | 'num_reports' => $row['num_reports'], |
||
242 | 'closed' => $row['closed'], |
||
243 | 'ignore' => $row['ignore_all'] |
||
244 | ); |
||
245 | |||
246 | if ($context['report_type'] == 'members') |
||
247 | { |
||
248 | $extraDetails = array( |
||
249 | 'user' => array( |
||
250 | 'id' => $row['id_user'], |
||
251 | 'name' => $row['user_name'], |
||
252 | 'link' => $row['id_user'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_user'] . '">' . $row['user_name'] . '</a>' : $row['user_name'], |
||
253 | 'href' => $scripturl . '?action=profile;u=' . $row['id_user'], |
||
254 | ), |
||
255 | ); |
||
256 | } |
||
257 | else |
||
258 | { |
||
259 | $report_boards_ids[] = $row['id_board']; |
||
260 | $extraDetails = array( |
||
261 | 'topic' => array( |
||
262 | 'id' => $row['id_topic'], |
||
263 | 'id_msg' => $row['id_msg'], |
||
264 | 'id_board' => $row['id_board'], |
||
265 | 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'], |
||
266 | ), |
||
267 | 'author' => array( |
||
268 | 'id' => $row['id_author'], |
||
269 | 'name' => $row['author_name'], |
||
270 | 'link' => $row['id_author'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_author'] . '">' . $row['author_name'] . '</a>' : $row['author_name'], |
||
271 | 'href' => $scripturl . '?action=profile;u=' . $row['id_author'], |
||
272 | ), |
||
273 | 'subject' => $row['subject'], |
||
274 | 'body' => parse_bbc($row['body']), |
||
275 | ); |
||
276 | } |
||
277 | |||
278 | $reports[$row['id_report']] = array_merge($reports[$row['id_report']], $extraDetails); |
||
279 | $i++; |
||
280 | } |
||
281 | $smcFunc['db_free_result']($request); |
||
282 | |||
283 | // Get the names of boards those topics are in. Slightly faster this way. |
||
284 | if (!empty($report_boards_ids)) |
||
285 | { |
||
286 | $report_boards_ids = array_unique($report_boards_ids); |
||
287 | $board_names = array(); |
||
288 | $request = $smcFunc['db_query']('', ' |
||
289 | SELECT id_board, name |
||
290 | FROM {db_prefix}boards |
||
291 | WHERE id_board IN ({array_int:boards})', |
||
292 | array( |
||
293 | 'boards' => $report_boards_ids, |
||
294 | ) |
||
295 | ); |
||
296 | |||
297 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
298 | $board_names[$row['id_board']] = $row['name']; |
||
299 | |||
300 | $smcFunc['db_free_result']($request); |
||
301 | |||
302 | foreach ($reports as $id_report => $report) |
||
303 | if (!empty($board_names[$report['topic']['id_board']])) |
||
304 | $reports[$id_report]['topic']['board_name'] = $board_names[$report['topic']['id_board']]; |
||
305 | } |
||
306 | |||
307 | // Now get all the people who reported it. |
||
308 | if (!empty($report_ids)) |
||
309 | { |
||
310 | $request = $smcFunc['db_query']('', ' |
||
311 | SELECT lrc.id_comment, lrc.id_report, lrc.time_sent, lrc.comment, |
||
312 | COALESCE(mem.id_member, 0) AS id_member, COALESCE(mem.real_name, lrc.membername) AS reporter |
||
313 | FROM {db_prefix}log_reported_comments AS lrc |
||
314 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lrc.id_member) |
||
315 | WHERE lrc.id_report IN ({array_int:report_list})', |
||
316 | array( |
||
317 | 'report_list' => $report_ids, |
||
318 | ) |
||
319 | ); |
||
320 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
321 | { |
||
322 | $reports[$row['id_report']]['comments'][] = array( |
||
323 | 'id' => $row['id_comment'], |
||
324 | 'message' => $row['comment'], |
||
325 | 'time' => timeformat($row['time_sent']), |
||
326 | 'member' => array( |
||
327 | 'id' => $row['id_member'], |
||
328 | 'name' => empty($row['reporter']) ? $txt['guest'] : $row['reporter'], |
||
329 | 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['reporter'] . '</a>' : (empty($row['reporter']) ? $txt['guest'] : $row['reporter']), |
||
330 | 'href' => $row['id_member'] ? $scripturl . '?action=profile;u=' . $row['id_member'] : '', |
||
331 | ), |
||
332 | ); |
||
333 | } |
||
334 | $smcFunc['db_free_result']($request); |
||
335 | } |
||
336 | |||
337 | // Get the boards where the current user can remove any message. |
||
338 | $context['report_remove_any_boards'] = $user_info['is_admin'] ? $report_boards_ids : array_intersect($report_boards_ids, boardsAllowedTo('remove_any')); |
||
339 | $context['report_manage_bans'] = allowedTo('manage_bans'); |
||
340 | |||
341 | return $reports; |
||
342 | } |
||
343 | |||
344 | /** |
||
345 | * Recount all open reports. Sets a SESSION var with the updated info. |
||
346 | * |
||
347 | * @param string $type the type of reports to count |
||
348 | * @return int the update open report count. |
||
349 | */ |
||
350 | function recountOpenReports($type) |
||
351 | { |
||
352 | global $user_info, $smcFunc; |
||
353 | |||
354 | if ($type == 'members') |
||
355 | $bq = ''; |
||
356 | else |
||
357 | $bq = ' AND ' . $user_info['mod_cache']['bq']; |
||
358 | |||
359 | $request = $smcFunc['db_query']('', ' |
||
360 | SELECT COUNT(*) |
||
361 | FROM {db_prefix}log_reported |
||
362 | WHERE closed = {int:not_closed} |
||
363 | AND ignore_all = {int:not_ignored} |
||
364 | AND id_board' . ($type == 'members' ? '' : '!') . '= {int:not_a_reported_post}' |
||
365 | . $bq, |
||
366 | array( |
||
367 | 'not_closed' => 0, |
||
368 | 'not_ignored' => 0, |
||
369 | 'not_a_reported_post' => 0, |
||
370 | ) |
||
371 | ); |
||
372 | list ($open_reports) = $smcFunc['db_fetch_row']($request); |
||
373 | $smcFunc['db_free_result']($request); |
||
374 | |||
375 | $arr = ($type == 'members' ? 'member_reports' : 'reports'); |
||
376 | $_SESSION['rc'] = array_merge(!empty($_SESSION['rc']) ? $_SESSION['rc'] : array(), |
||
377 | array( |
||
378 | 'id' => $user_info['id'], |
||
379 | 'time' => time(), |
||
380 | $arr => $open_reports, |
||
381 | )); |
||
382 | |||
383 | return $open_reports; |
||
384 | } |
||
385 | |||
386 | /** |
||
387 | * Gets additional information for a specific report. |
||
388 | * |
||
389 | * @param int $report_id The report ID to get the info from. |
||
390 | * @return array|bool the report data. Boolean false if no report_id was provided. |
||
391 | */ |
||
392 | function getReportDetails($report_id) |
||
393 | { |
||
394 | global $smcFunc, $user_info, $context; |
||
395 | |||
396 | if (empty($report_id)) |
||
397 | return false; |
||
398 | |||
399 | // We don't need all this info if we're only getting user info |
||
400 | if ($context['report_type'] == 'members') |
||
401 | { |
||
402 | $request = $smcFunc['db_query']('', ' |
||
403 | SELECT lr.id_report, lr.id_member, |
||
404 | lr.time_started, lr.time_updated, lr.num_reports, lr.closed, lr.ignore_all, |
||
405 | COALESCE(mem.real_name, lr.membername) AS user_name, COALESCE(mem.id_member, 0) AS id_user |
||
406 | FROM {db_prefix}log_reported AS lr |
||
407 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member) |
||
408 | WHERE lr.id_report = {int:id_report} |
||
409 | AND lr.id_board = 0 |
||
410 | LIMIT 1', |
||
411 | array( |
||
412 | 'id_report' => $report_id, |
||
413 | ) |
||
414 | ); |
||
415 | } |
||
416 | else |
||
417 | { |
||
418 | // Get the report details, need this so we can limit access to a particular board. |
||
419 | $request = $smcFunc['db_query']('', ' |
||
420 | SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject, lr.body, |
||
421 | lr.time_started, lr.time_updated, lr.num_reports, lr.closed, lr.ignore_all, |
||
422 | COALESCE(mem.real_name, lr.membername) AS author_name, COALESCE(mem.id_member, 0) AS id_author |
||
423 | FROM {db_prefix}log_reported AS lr |
||
424 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member) |
||
425 | WHERE lr.id_report = {int:id_report} |
||
426 | 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']) . ' |
||
427 | LIMIT 1', |
||
428 | array( |
||
429 | 'id_report' => $report_id, |
||
430 | ) |
||
431 | ); |
||
432 | } |
||
433 | |||
434 | // So did we find anything? |
||
435 | if (!$smcFunc['db_num_rows']($request)) |
||
436 | return false; |
||
437 | |||
438 | // Woohoo we found a report and they can see it! |
||
439 | $row = $smcFunc['db_fetch_assoc']($request); |
||
440 | $smcFunc['db_free_result']($request); |
||
441 | |||
442 | return $row; |
||
443 | } |
||
444 | |||
445 | /** |
||
446 | * Gets both report comments as well as any moderator comment. |
||
447 | * |
||
448 | * @param int $report_id The report ID to get the info from. |
||
449 | * @return array|bool an associative array with 2 keys comments and mod_comments. Boolean false if no report_id was provided. |
||
450 | */ |
||
451 | function getReportComments($report_id) |
||
452 | { |
||
453 | global $smcFunc, $scripturl, $user_info, $txt; |
||
454 | |||
455 | if (empty($report_id)) |
||
456 | return false; |
||
457 | |||
458 | $report = array( |
||
459 | 'comments' => array(), |
||
460 | 'mod_comments' => array() |
||
461 | ); |
||
462 | |||
463 | // So what bad things do the reporters have to say about it? |
||
464 | $request = $smcFunc['db_query']('', ' |
||
465 | SELECT lrc.id_comment, lrc.id_report, lrc.time_sent, lrc.comment, lrc.member_ip, |
||
466 | COALESCE(mem.id_member, 0) AS id_member, COALESCE(mem.real_name, lrc.membername) AS reporter |
||
467 | FROM {db_prefix}log_reported_comments AS lrc |
||
468 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lrc.id_member) |
||
469 | WHERE lrc.id_report = {int:id_report}', |
||
470 | array( |
||
471 | 'id_report' => $report_id, |
||
472 | ) |
||
473 | ); |
||
474 | |||
475 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
476 | { |
||
477 | $report['comments'][] = array( |
||
478 | 'id' => $row['id_comment'], |
||
479 | 'message' => strtr($row['comment'], array("\n" => '<br>')), |
||
480 | 'time' => timeformat($row['time_sent']), |
||
481 | 'member' => array( |
||
482 | 'id' => $row['id_member'], |
||
483 | 'name' => empty($row['reporter']) ? $txt['guest'] : $row['reporter'], |
||
484 | 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['reporter'] . '</a>' : (empty($row['reporter']) ? $txt['guest'] : $row['reporter']), |
||
485 | 'href' => $row['id_member'] ? $scripturl . '?action=profile;u=' . $row['id_member'] : '', |
||
486 | '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
![]() |
|||
487 | ), |
||
488 | ); |
||
489 | } |
||
490 | $smcFunc['db_free_result']($request); |
||
491 | |||
492 | // Hang about old chap, any comments from moderators on this one? |
||
493 | $request = $smcFunc['db_query']('', ' |
||
494 | SELECT lc.id_comment, lc.id_notice, lc.log_time, lc.body, |
||
495 | COALESCE(mem.id_member, 0) AS id_member, COALESCE(mem.real_name, lc.member_name) AS moderator |
||
496 | FROM {db_prefix}log_comments AS lc |
||
497 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member) |
||
498 | WHERE lc.id_notice = {int:id_report} |
||
499 | AND lc.comment_type = {literal:reportc}', |
||
500 | array( |
||
501 | 'id_report' => $report_id, |
||
502 | ) |
||
503 | ); |
||
504 | |||
505 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
506 | { |
||
507 | $report['mod_comments'][] = array( |
||
508 | 'id' => $row['id_comment'], |
||
509 | 'message' => parse_bbc($row['body']), |
||
510 | 'time' => timeformat($row['log_time']), |
||
511 | 'can_edit' => allowedTo('admin_forum') || (($user_info['id'] == $row['id_member'])), |
||
512 | 'member' => array( |
||
513 | 'id' => $row['id_member'], |
||
514 | 'name' => $row['moderator'], |
||
515 | 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['moderator'] . '</a>' : $row['moderator'], |
||
516 | 'href' => $scripturl . '?action=profile;u=' . $row['id_member'], |
||
517 | ), |
||
518 | ); |
||
519 | } |
||
520 | |||
521 | $smcFunc['db_free_result']($request); |
||
522 | |||
523 | return $report; |
||
524 | } |
||
525 | |||
526 | /** |
||
527 | * Gets specific details about a moderator comment. It also adds a permission for editing/deleting the comment, |
||
528 | * by default only admins and the author of the comment can edit/delete it. |
||
529 | * |
||
530 | * @param int $comment_id The moderator comment ID to get the info from. |
||
531 | * @return array|bool an array with the fetched data. Boolean false if no report_id was provided. |
||
532 | */ |
||
533 | function getCommentModDetails($comment_id) |
||
534 | { |
||
535 | global $smcFunc, $user_info; |
||
536 | |||
537 | if (empty($comment_id)) |
||
538 | return false; |
||
539 | |||
540 | $request = $smcFunc['db_query']('', ' |
||
541 | SELECT id_comment, id_notice, log_time, body, id_member |
||
542 | FROM {db_prefix}log_comments |
||
543 | WHERE id_comment = {int:id_comment} |
||
544 | AND comment_type = {literal:reportc}', |
||
545 | array( |
||
546 | 'id_comment' => $comment_id, |
||
547 | ) |
||
548 | ); |
||
549 | |||
550 | $comment = $smcFunc['db_fetch_assoc']($request); |
||
551 | |||
552 | $smcFunc['db_free_result']($request); |
||
553 | |||
554 | // Add the permission |
||
555 | if (!empty($comment)) |
||
556 | $comment['can_edit'] = allowedTo('admin_forum') || (($user_info['id'] == $comment['id_member'])); |
||
557 | |||
558 | return $comment; |
||
559 | } |
||
560 | |||
561 | /** |
||
562 | * Inserts a new moderator comment to the DB. |
||
563 | * |
||
564 | * @param int $report_id The report ID is used to fire a notification about the event. |
||
565 | * @param array $data a formatted array of data to be inserted. Should be already properly sanitized. |
||
566 | * @return bool Boolean false if no data was provided. |
||
567 | */ |
||
568 | function saveModComment($report_id, $data) |
||
569 | { |
||
570 | global $smcFunc, $user_info, $context; |
||
571 | |||
572 | if (empty($data)) |
||
573 | return false; |
||
574 | |||
575 | $data = array_merge(array($user_info['id'], $user_info['name'], 'reportc', ''), $data); |
||
576 | |||
577 | $last_comment = $smcFunc['db_insert']('', |
||
578 | '{db_prefix}log_comments', |
||
579 | array( |
||
580 | 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'recipient_name' => 'string', |
||
581 | 'id_notice' => 'int', 'body' => 'string', 'log_time' => 'int', |
||
582 | ), |
||
583 | $data, |
||
584 | array('id_comment'), |
||
585 | 1 |
||
586 | ); |
||
587 | |||
588 | $report = getReportDetails($report_id); |
||
589 | |||
590 | if ($context['report_type'] == 'members') |
||
591 | { |
||
592 | $prefix = 'Member'; |
||
593 | $data = array( |
||
594 | 'report_id' => $report_id, |
||
595 | 'user_id' => $report['id_user'], |
||
596 | 'user_name' => $report['user_name'], |
||
597 | 'sender_id' => $context['user']['id'], |
||
598 | 'sender_name' => $context['user']['name'], |
||
599 | 'comment_id' => $last_comment, |
||
600 | 'time' => time(), |
||
601 | ); |
||
602 | } |
||
603 | else |
||
604 | { |
||
605 | $prefix = 'Msg'; |
||
606 | $data = array( |
||
607 | 'report_id' => $report_id, |
||
608 | 'comment_id' => $last_comment, |
||
609 | 'msg_id' => $report['id_msg'], |
||
610 | 'topic_id' => $report['id_topic'], |
||
611 | 'board_id' => $report['id_board'], |
||
612 | 'sender_id' => $user_info['id'], |
||
613 | 'sender_name' => $user_info['name'], |
||
614 | 'time' => time(), |
||
615 | ); |
||
616 | } |
||
617 | |||
618 | // And get ready to notify people. |
||
619 | if (!empty($report)) |
||
620 | $smcFunc['db_insert']('insert', |
||
621 | '{db_prefix}background_tasks', |
||
622 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
||
623 | array('$sourcedir/tasks/' . $prefix . 'ReportReply-Notify.php', $prefix . 'ReportReply_Notify_Background', $smcFunc['json_encode']($data), 0), |
||
624 | array('id_task') |
||
625 | ); |
||
626 | } |
||
627 | |||
628 | /** |
||
629 | * Saves the new information whenever a moderator comment is edited. |
||
630 | * |
||
631 | * @param int $comment_id The edited moderator comment ID. |
||
632 | * @param string $edited_comment The edited moderator comment text. |
||
633 | * @return bool Boolean false if no data or no comment ID was provided. |
||
634 | */ |
||
635 | function editModComment($comment_id, $edited_comment) |
||
636 | { |
||
637 | global $smcFunc; |
||
638 | |||
639 | if (empty($comment_id) || empty($edited_comment)) |
||
640 | return false; |
||
641 | |||
642 | $smcFunc['db_query']('', ' |
||
643 | UPDATE {db_prefix}log_comments |
||
644 | SET body = {string:body} |
||
645 | WHERE id_comment = {int:id_comment}', |
||
646 | array( |
||
647 | 'body' => $edited_comment, |
||
648 | 'id_comment' => $comment_id, |
||
649 | ) |
||
650 | ); |
||
651 | return true; |
||
652 | } |
||
653 | |||
654 | /** |
||
655 | * Deletes a moderator comment from the DB. |
||
656 | * |
||
657 | * @param int $comment_id The moderator comment ID used to identify which report will be deleted. |
||
658 | * @return bool Boolean false if no data was provided. |
||
659 | */ |
||
660 | function deleteModComment($comment_id) |
||
661 | { |
||
662 | global $smcFunc; |
||
663 | |||
664 | if (empty($comment_id)) |
||
665 | return false; |
||
666 | |||
667 | $smcFunc['db_query']('', ' |
||
668 | DELETE FROM {db_prefix}log_comments |
||
669 | WHERE id_comment = {int:comment_id}', |
||
670 | array( |
||
671 | 'comment_id' => $comment_id, |
||
672 | ) |
||
673 | ); |
||
674 | |||
675 | } |
||
676 | |||
677 | ?> |