Failed Conditions
Branch release-2.1 (4e22cf)
by Rick
07:22
created

Subs-ReportedContent.php ➔ countReports()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 38
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 17
nc 3
nop 1
dl 0
loc 38
rs 8.5806
c 0
b 0
f 0
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 http://www.simplemachines.org
10
 * @copyright 2017 Simple Machines and individual contributors
11
 * @license http://www.simplemachines.org/about/smf/license.php BSD
12
 *
13
 * @version 2.1 Beta 4
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
 * @params integer|array $report_id The affected report(s).
25
 */
26
function updateReport($action, $value, $report_id)
27
{
28
	global $smcFunc, $user_info, $context;
29
30
	// Don't bother.
31
	if (empty($action) || empty($report_id))
32
		return false;
33
34
	// Add the "_all" thingy.
35
	if ($action == 'ignore')
36
		$action = 'ignore_all';
37
38
	// We don't need the board query for reported members
39
	if ($context['report_type'] == 'members')
40
	{
41
		$board_query = '';
42
	}
43
	else
44
	{
45
		$board_query = ' AND ' . $user_info['mod_cache']['bq'];
46
	}
47
48
	// Update the report...
49
	$smcFunc['db_query']('', '
50
		UPDATE {db_prefix}log_reported
51
		SET  {raw:action} = {string:value}
52
		'. (is_array($report_id) ? 'WHERE id_report IN ({array_int:id_report})' : 'WHERE id_report = {int:id_report}') .'
53
			' . $board_query,
54
		array(
55
			'action' => $action,
56
			'value' => $value,
57
			'id_report' => $report_id,
58
		)
59
	);
60
61
	// From now on, lets work with arrays, makes life easier.
62
	$report_id = (array) $report_id;
63
64
	// Set up the data for the log...
65
	$extra = array();
66
67
	if ($context['report_type'] == 'posts')
68
	{
69
		// Get the board, topic and message for this report
70
		$request = $smcFunc['db_query']('', '
71
			SELECT id_board, id_topic, id_msg, id_report
72
			FROM {db_prefix}log_reported
73
			WHERE id_report IN ({array_int:id_report})',
74
			array(
75
				'id_report' => $report_id,
76
			)
77
		);
78
79 View Code Duplication
		while ($row = $smcFunc['db_fetch_assoc']($request))
80
			$extra[$row['id_report']] = array(
81
				'report' => $row['id_report'],
82
				'board' => $row['id_board'],
83
				'message' => $row['id_msg'],
84
				'topic' => $row['id_topic'],
85
			);
86
87
		$smcFunc['db_free_result']($request);
88
	}
89
	else
90
	{
91
		$request = $smcFunc['db_query']('', '
92
			SELECT id_report, id_member, membername
93
			FROM {db_prefix}log_reported
94
			WHERE id_report IN ({array_int:id_report})',
95
			array(
96
				'id_report' => $report_id,
97
			)
98
		);
99
100
		while($row = $smcFunc['db_fetch_assoc']($request))
101
			$extra[$row['id_report']] = array(
102
				'report' => $row['id_report'],
103
				'member' => $row['id_member'],
104
			);
105
106
		$smcFunc['db_free_result']($request);
107
	}
108
109
	// Back to "ignore".
110
	if ($action == 'ignore_all')
111
		$action = 'ignore';
112
113
	$log_report = $action == 'ignore' ? (!empty($value) ? 'ignore' : 'unignore') : (!empty($value) ? 'close' : 'open');
114
115
	if ($context['report_type'] == 'members')
116
		$log_report .= '_user';
117
118
	// Log this action.
119
	if (!empty($extra))
120
		foreach ($extra as $report)
121
			logAction($log_report . '_report', $report);
122
123
	// Time to update.
124
	updateSettings(array('last_mod_report_action' => time()));
125
	recountOpenReports($context['report_type']);
126
}
127
128
/**
129
 * Counts how many reports are in total. Used for creating pagination.
130
 *
131
 * @param int $closed 1 for counting closed reports, 0 for open ones.
132
 * @return integer How many reports.
133
134
 */
135
function countReports($closed = 0)
136
{
137
	global $smcFunc, $user_info, $context;
138
139
	// Skip entries with id_board = 0 if we're viewing member reports
140
	if ($context['report_type'] == 'members')
141
	{
142
		$and = 'lr.id_board = 0';
143
	}
144
	else
145
	{
146
		if ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1')
147
		{
148
			$bq = $user_info['mod_cache']['bq'];
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $bq. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
149
		}
150
		else
151
		{
152
			$bq = 'lr.' . $user_info['mod_cache']['bq'];
153
		}
154
155
		$and = $bq . ' AND lr.id_board != 0';
156
	}
157
158
	// How many entries are we viewing?
159
	$request = $smcFunc['db_query']('', '
160
		SELECT COUNT(*)
161
		FROM {db_prefix}log_reported AS lr
162
		WHERE lr.closed = {int:view_closed}
163
			AND ' . $and,
164
		array(
165
			'view_closed' => (int) $closed,
166
		)
167
	);
168
	list ($total_reports) = $smcFunc['db_fetch_row']($request);
169
	$smcFunc['db_free_result']($request);
170
171
	return $total_reports;
172
}
173
174
/**
175
 * Get all possible reports the current user can see.
176
 *
177
 * @param int $closed 1 for closed reports, 0 for open ones.
178
 * @return array the reports data with the report ID as key.
179
 */
180
function getReports($closed = 0)
181
{
182
	global $smcFunc, $context, $user_info, $scripturl, $txt;
183
184
	// Lonely, standalone var.
185
	$reports = array();
186
187
	// By George, that means we are in a position to get the reports, golly good.
188
	if ($context['report_type'] == 'members')
189
	{
190
		$request = $smcFunc['db_query']('', '
191
			SELECT lr.id_report, lr.id_member,
192
				lr.time_started, lr.time_updated, lr.num_reports, lr.closed, lr.ignore_all,
193
				COALESCE(mem.real_name, lr.membername) AS user_name, COALESCE(mem.id_member, 0) AS id_user
194
			FROM {db_prefix}log_reported AS lr
195
				LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member)
196
			WHERE lr.closed = {int:view_closed}
197
				AND lr.id_board = 0
198
			ORDER BY lr.time_updated DESC
199
			LIMIT {int:start}, {int:max}',
200
			array(
201
				'view_closed' => (int) $closed,
202
				'start' => $context['start'],
203
				'max' => 10,
204
			)
205
		);
206
	}
207
	else
208
	{
209
		$request = $smcFunc['db_query']('', '
210
			SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject, lr.body,
211
				lr.time_started, lr.time_updated, lr.num_reports, lr.closed, lr.ignore_all,
212
				COALESCE(mem.real_name, lr.membername) AS author_name, COALESCE(mem.id_member, 0) AS id_author
213
			FROM {db_prefix}log_reported AS lr
214
				LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member)
215
			WHERE lr.closed = {int:view_closed}
216
				AND lr.id_board != 0
217
				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']) . '
218
			ORDER BY lr.time_updated DESC
219
			LIMIT {int:start}, {int:max}',
220
			array(
221
				'view_closed' => (int) $closed,
222
				'start' => $context['start'],
223
				'max' => 10,
224
			)
225
		);
226
	}
227
228
	$report_ids = array();
229
	$report_boards_ids = array();
230
	$i = 0;
231
	while ($row = $smcFunc['db_fetch_assoc']($request))
232
	{
233
		$report_ids[] = $row['id_report'];
234
		$reports[$row['id_report']] = array(
235
			'id' => $row['id_report'],
236
			'report_href' => $scripturl . '?action=moderate;area=reported' . $context['report_type'] . ';sa=details;rid=' . $row['id_report'],
237
			'comments' => array(),
238
			'time_started' => timeformat($row['time_started']),
239
			'last_updated' => timeformat($row['time_updated']),
240
			'num_reports' => $row['num_reports'],
241
			'closed' => $row['closed'],
242
			'ignore' => $row['ignore_all']
243
		);
244
245
		if ($context['report_type'] == 'members')
246
		{
247
			$extraDetails = array(
248
				'user' => array(
249
					'id' => $row['id_user'],
250
					'name' => $row['user_name'],
251
					'link' => $row['id_user'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_user'] . '">' . $row['user_name'] . '</a>' : $row['user_name'],
252
					'href' => $scripturl . '?action=profile;u=' . $row['id_user'],
253
				),
254
			);
255
		}
256
		else
257
		{
258
			$report_boards_ids[] = $row['id_board'];
259
			$extraDetails = array(
260
				'topic' => array(
261
					'id' => $row['id_topic'],
262
					'id_msg' => $row['id_msg'],
263
					'id_board' => $row['id_board'],
264
					'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
265
				),
266
				'author' => array(
267
					'id' => $row['id_author'],
268
					'name' => $row['author_name'],
269
					'link' => $row['id_author'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_author'] . '">' . $row['author_name'] . '</a>' : $row['author_name'],
270
					'href' => $scripturl . '?action=profile;u=' . $row['id_author'],
271
				),
272
				'subject' => $row['subject'],
273
				'body' => parse_bbc($row['body']),
274
			);
275
		}
276
277
		$reports[$row['id_report']] = array_merge($reports[$row['id_report']], $extraDetails);
278
		$i++;
279
	}
280
	$smcFunc['db_free_result']($request);
281
282
	// Get the names of boards those topics are in. Slightly faster this way.
283
	if (!empty($report_boards_ids))
284
	{
285
		$report_boards_ids = array_unique($report_boards_ids);
286
		$board_names = array();
287
		$request = $smcFunc['db_query']('', '
288
			SELECT id_board, name
289
			FROM {db_prefix}boards
290
			WHERE id_board IN ({array_int:boards})',
291
			array(
292
				'boards' => $report_boards_ids,
293
			)
294
		);
295
296 View Code Duplication
		while ($row = $smcFunc['db_fetch_assoc']($request))
297
			$board_names[$row['id_board']] = $row['name'];
298
299
		$smcFunc['db_free_result']($request);
300
301
		foreach ($reports as $id_report => $report)
302
			if (!empty($board_names[$report['topic']['id_board']]))
303
				$reports[$id_report]['topic']['board_name'] = $board_names[$report['topic']['id_board']];
304
	}
305
306
	// Now get all the people who reported it.
307 View Code Duplication
	if (!empty($report_ids))
308
	{
309
		$request = $smcFunc['db_query']('', '
310
			SELECT lrc.id_comment, lrc.id_report, lrc.time_sent, lrc.comment,
311
				COALESCE(mem.id_member, 0) AS id_member, COALESCE(mem.real_name, lrc.membername) AS reporter
312
			FROM {db_prefix}log_reported_comments AS lrc
313
				LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lrc.id_member)
314
			WHERE lrc.id_report IN ({array_int:report_list})',
315
			array(
316
				'report_list' => $report_ids,
317
			)
318
		);
319
		while ($row = $smcFunc['db_fetch_assoc']($request))
320
		{
321
			$reports[$row['id_report']]['comments'][] = array(
322
				'id' => $row['id_comment'],
323
				'message' => $row['comment'],
324
				'time' => timeformat($row['time_sent']),
325
				'member' => array(
326
					'id' => $row['id_member'],
327
					'name' => empty($row['reporter']) ? $txt['guest'] : $row['reporter'],
328
					'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['reporter'] . '</a>' : (empty($row['reporter']) ? $txt['guest'] : $row['reporter']),
329
					'href' => $row['id_member'] ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
330
				),
331
			);
332
		}
333
		$smcFunc['db_free_result']($request);
334
	}
335
336
	// Get the boards where the current user can remove any message.
337
	$context['report_remove_any_boards'] = $user_info['is_admin'] ? $report_boards_ids : array_intersect($report_boards_ids, boardsAllowedTo('remove_any'));
338
	$context['report_manage_bans'] = allowedTo('manage_bans');
339
340
	return $reports;
341
}
342
343
/**
344
 * Recount all open reports. Sets a SESSION var with the updated info.
345
 *
346
 * @param string $type the type of reports to count
347
 * @return int the update open report count.
348
 */
349
function recountOpenReports($type)
350
{
351
	global $user_info, $smcFunc;
352
353
	if ($type == 'members')
354
		$bq = '';
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $bq. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
355
	else
356
		$bq = '	AND ' . $user_info['mod_cache']['bq'];
357
358
	$request = $smcFunc['db_query']('', '
359
		SELECT COUNT(*)
360
		FROM {db_prefix}log_reported
361
		WHERE closed = {int:not_closed}
362
			AND ignore_all = {int:not_ignored}
363
			AND id_board' . ($type == 'members' ? '' : '!') . '= {int:not_a_reported_post}'
364
		 	. $bq,
365
		array(
366
			'not_closed' => 0,
367
			'not_ignored' => 0,
368
			'not_a_reported_post' => 0,
369
		)
370
	);
371
	list ($open_reports) = $smcFunc['db_fetch_row']($request);
372
	$smcFunc['db_free_result']($request);
373
374
	$arr = ($type == 'members' ? 'member_reports' : 'reports');
375
	$_SESSION['rc'] = array_merge(!empty($_SESSION['rc']) ? $_SESSION['rc'] : array(),
376
		array(
377
			'id' => $user_info['id'],
378
			'time' => time(),
379
			$arr => $open_reports,
380
		));
381
382
	return $open_reports;
383
}
384
385
/**
386
 * Gets additional information for a specific report.
387
 *
388
 * @param int $report_id The report ID to get the info from.
389
 * @return array|bool the report data. Boolean false if no report_id was provided.
390
 */
391
function getReportDetails($report_id)
392
{
393
	global $smcFunc, $user_info, $context;
394
395
	if (empty($report_id))
396
		return false;
397
398
	// We don't need all this info if we're only getting user info
399
	if ($context['report_type'] == 'members')
400
	{
401
		$request = $smcFunc['db_query']('', '
402
			SELECT lr.id_report, lr.id_member,
403
					lr.time_started, lr.time_updated, lr.num_reports, lr.closed, lr.ignore_all,
404
					COALESCE(mem.real_name, lr.membername) AS user_name, COALESCE(mem.id_member, 0) AS id_user
405
			FROM {db_prefix}log_reported AS lr
406
				LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member)
407
			WHERE lr.id_report = {int:id_report}
408
				AND lr.id_board = 0
409
			LIMIT 1',
410
			array(
411
				'id_report' => $report_id,
412
			)
413
		);
414
	}
415
	else
416
	{
417
		// Get the report details, need this so we can limit access to a particular board.
418
		$request = $smcFunc['db_query']('', '
419
			SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject, lr.body,
420
				lr.time_started, lr.time_updated, lr.num_reports, lr.closed, lr.ignore_all,
421
				COALESCE(mem.real_name, lr.membername) AS author_name, COALESCE(mem.id_member, 0) AS id_author
422
			FROM {db_prefix}log_reported AS lr
423
				LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member)
424
			WHERE lr.id_report = {int:id_report}
425
				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']) . '
426
			LIMIT 1',
427
			array(
428
				'id_report' => $report_id,
429
			)
430
		);
431
	}
432
433
	// So did we find anything?
434
	if (!$smcFunc['db_num_rows']($request))
435
		return false;
436
437
	// Woohoo we found a report and they can see it!
438
	$row = $smcFunc['db_fetch_assoc']($request);
439
	$smcFunc['db_free_result']($request);
440
441
	return $row;
442
}
443
444
/**
445
 * Gets both report comments as well as any moderator comment.
446
 *
447
 * @param int $report_id The report ID to get the info from.
448
 * @return array|bool an associative array with 2 keys comments and mod_comments. Boolean false if no report_id was provided.
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use false|array<string,array>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
449
 */
450
function getReportComments($report_id)
451
{
452
	global $smcFunc, $scripturl, $user_info, $txt;
453
454
	if (empty($report_id))
455
		return false;
456
457
	$report = array(
458
		'comments' => array(),
459
		'mod_comments' => array()
460
	);
461
462
	// So what bad things do the reporters have to say about it?
463
	$request = $smcFunc['db_query']('', '
464
		SELECT lrc.id_comment, lrc.id_report, lrc.time_sent, lrc.comment, lrc.member_ip,
465
			COALESCE(mem.id_member, 0) AS id_member, COALESCE(mem.real_name, lrc.membername) AS reporter
466
		FROM {db_prefix}log_reported_comments AS lrc
467
			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lrc.id_member)
468
		WHERE lrc.id_report = {int:id_report}',
469
		array(
470
			'id_report' => $report_id,
471
		)
472
	);
473
474
	while ($row = $smcFunc['db_fetch_assoc']($request))
475
	{
476
		$report['comments'][] = array(
477
			'id' => $row['id_comment'],
478
			'message' => strtr($row['comment'], array("\n" => '<br>')),
479
			'time' => timeformat($row['time_sent']),
480
			'member' => array(
481
				'id' => $row['id_member'],
482
				'name' => empty($row['reporter']) ? $txt['guest'] : $row['reporter'],
483
				'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['reporter'] . '</a>' : (empty($row['reporter']) ? $txt['guest'] : $row['reporter']),
484
				'href' => $row['id_member'] ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
485
				'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>' : '',
486
			),
487
		);
488
	}
489
	$smcFunc['db_free_result']($request);
490
491
	// Hang about old chap, any comments from moderators on this one?
492
	$request = $smcFunc['db_query']('', '
493
		SELECT lc.id_comment, lc.id_notice, lc.log_time, lc.body,
494
			COALESCE(mem.id_member, 0) AS id_member, COALESCE(mem.real_name, lc.member_name) AS moderator
495
		FROM {db_prefix}log_comments AS lc
496
			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
497
		WHERE lc.id_notice = {int:id_report}
498
			AND lc.comment_type = {literal:reportc}',
499
		array(
500
			'id_report' => $report_id,
501
		)
502
	);
503
504
	while ($row = $smcFunc['db_fetch_assoc']($request))
505
	{
506
		$report['mod_comments'][] = array(
507
			'id' => $row['id_comment'],
508
			'message' => parse_bbc($row['body']),
509
			'time' => timeformat($row['log_time']),
510
			'can_edit' => allowedTo('admin_forum') || (($user_info['id'] == $row['id_member'])),
511
			'member' => array(
512
				'id' => $row['id_member'],
513
				'name' => $row['moderator'],
514
				'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['moderator'] . '</a>' : $row['moderator'],
515
				'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
516
			),
517
		);
518
	}
519
520
	$smcFunc['db_free_result']($request);
521
522
	return $report;
523
}
524
525
/**
526
 * Gets specific details about a moderator comment. It also adds a permission for editing/deleting the comment,
527
 * by default only admins and the author of the comment can edit/delete it.
528
 *
529
 * @param int $comment_id The moderator comment ID to get the info from.
530
 * @return array|bool an array with the fetched data. Boolean false if no report_id was provided.
531
 */
532
function getCommentModDetails($comment_id)
533
{
534
	global $smcFunc, $user_info;
535
536
	if (empty($comment_id))
537
		return false;
538
539
	$request = $smcFunc['db_query']('', '
540
		SELECT id_comment, id_notice, log_time, body, id_member
541
		FROM {db_prefix}log_comments
542
		WHERE id_comment = {int:id_comment}
543
			AND comment_type = {literal:reportc}',
544
		array(
545
			'id_comment' => $comment_id,
546
		)
547
	);
548
549
	$comment = $smcFunc['db_fetch_assoc']($request);
550
551
	$smcFunc['db_free_result']($request);
552
553
	// Add the permission
554
	if (!empty($comment))
555
		$comment['can_edit'] = allowedTo('admin_forum') || (($user_info['id'] == $comment['id_member']));
556
557
	return $comment;
558
}
559
560
/**
561
 * Inserts a new moderator comment to the DB.
562
 *
563
 * @param int $report_id The report ID is used to fire a notification about the event.
564
 * @param array $data a formatted array of data to be inserted. Should be already properly sanitized.
565
 * @return bool  Boolean false if no data was provided.
0 ignored issues
show
Documentation introduced by
Should the return type not be false|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
566
 */
567
function saveModComment($report_id, $data)
568
{
569
	global $smcFunc, $user_info, $context;
570
571
	if (empty($data))
572
		return false;
573
574
	$data = array_merge(array($user_info['id'], $user_info['name'], 'reportc', ''), $data);
575
576
	$last_comment = $smcFunc['db_insert']('',
577
		'{db_prefix}log_comments',
578
		array(
579
			'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'recipient_name' => 'string',
580
			'id_notice' => 'int', 'body' => 'string', 'log_time' => 'int',
581
		),
582
		$data,
583
		array('id_comment'),
584
		1
585
	);
586
587
	$report = getReportDetails($report_id);
588
589
	if ($context['report_type'] == 'members')
590
	{
591
		$prefix = 'Member';
592
		$data = array(
593
		 	'report_id' => $report_id,
594
			'user_id' => $report['id_user'],
595
			'user_name' => $report['user_name'],
596
			'sender_id' => $context['user']['id'],
597
			'sender_name' => $context['user']['name'],
598
			'comment_id' => $last_comment,
599
			'time' => time(),
600
		);
601
	}
602
	else
603
	{
604
		$prefix = 'Msg';
605
		$data = array(
606
			'report_id' => $report_id,
607
			'comment_id' => $last_comment,
608
			'msg_id' => $report['id_msg'],
609
			'topic_id' => $report['id_topic'],
610
			'board_id' => $report['id_board'],
611
			'sender_id' => $user_info['id'],
612
			'sender_name' => $user_info['name'],
613
			'time' => time(),
614
		);
615
	}
616
617
	// And get ready to notify people.
618
	if (!empty($report))
619
		$smcFunc['db_insert']('insert',
620
			'{db_prefix}background_tasks',
621
			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
622
			array('$sourcedir/tasks/' . $prefix . 'ReportReply-Notify.php', $prefix . 'ReportReply_Notify_Background', $smcFunc['json_encode']($data), 0),
623
			array('id_task')
624
		);
625
}
626
627
/**
628
 * Saves the new information whenever a moderator comment is edited.
629
 *
630
 * @param int $comment_id The edited moderator comment ID.
631
 * @param array $data The new data to de inserted. Should be already properly sanitized.
0 ignored issues
show
Bug introduced by
There is no parameter named $data. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
632
 * @return bool  Boolean false if no data or no comment ID was provided.
0 ignored issues
show
Documentation introduced by
Should the return type not be false|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
633
 */
634
function editModComment($comment_id, $edited_comment)
635
{
636
	global $smcFunc;
637
638
	if (empty($comment_id) || empty($edited_comment))
639
		return false;
640
641
	$smcFunc['db_query']('', '
642
		UPDATE {db_prefix}log_comments
643
		SET  body = {string:body}
644
		WHERE id_comment = {int:id_comment}',
645
		array(
646
			'body' => $edited_comment,
647
			'id_comment' => $comment_id,
648
		)
649
	);
650
}
651
652
/**
653
 * Deletes a moderator comment from the DB.
654
 *
655
 * @param int $comment_id The moderator comment ID used to identify which report will be deleted.
656
 * @return bool  Boolean false if no data was provided.
0 ignored issues
show
Documentation introduced by
Should the return type not be false|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
657
 */
658
function deleteModComment($comment_id)
659
{
660
	global $smcFunc;
661
662
	if (empty($comment_id))
663
		return false;
664
665
	$smcFunc['db_query']('', '
666
		DELETE FROM {db_prefix}log_comments
667
		WHERE id_comment = {int:comment_id}',
668
		array(
669
			'comment_id' => $comment_id,
670
		)
671
	);
672
673
}
674
675
?>