forked from imabutahersiddik/CodeStore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoderation_system.php
More file actions
99 lines (87 loc) · 2.94 KB
/
moderation_system.php
File metadata and controls
99 lines (87 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
class ModerationSystem {
private $pdo;
private $currentTime = '2025-06-14 13:33:08';
private $currentUser = 'imabutahersiddik';
public function __construct($pdo) {
$this->pdo = $pdo;
}
public function reportContent($type, $contentId, $reason, $details) {
$stmt = $this->pdo->prepare("
INSERT INTO reports
(content_type, content_id, reporter_id, reason, details, status, created_at)
VALUES (?, ?, ?, ?, ?, 'pending', ?)
");
return $stmt->execute([
$type,
$contentId,
$_SESSION['user_id'],
$reason,
$details,
$this->currentTime
]);
}
public function moderateContent($reportId, $action, $notes = '') {
$stmt = $this->pdo->prepare("
UPDATE reports
SET
status = ?,
moderator_id = ?,
moderation_notes = ?,
moderated_at = ?
WHERE id = ?
");
$success = $stmt->execute([
$action,
$_SESSION['user_id'],
$notes,
$this->currentTime,
$reportId
]);
if ($success) {
$report = $this->getReport($reportId);
$this->takeAction($report, $action);
}
return $success;
}
private function takeAction($report, $action) {
switch ($action) {
case 'remove':
$this->removeContent($report['content_type'], $report['content_id']);
break;
case 'warn':
$this->warnUser($report['content_type'], $report['content_id']);
break;
case 'ban':
$this->banUser($report['content_type'], $report['content_id']);
break;
}
}
private function getReport($reportId) {
$stmt = $this->pdo->prepare("SELECT * FROM reports WHERE id = ?");
$stmt->execute([$reportId]);
return $stmt->fetch();
}
public function getPendingReports($page = 1, $perPage = 20) {
$offset = ($page - 1) * $perPage;
$stmt = $this->pdo->prepare("
SELECT
r.*,
u1.username as reporter_username,
u2.username as reported_user,
CASE
WHEN r.content_type = 'app' THEN (SELECT app_name FROM apps WHERE id = r.content_id)
WHEN r.content_type = 'comment' THEN (SELECT content FROM comments WHERE id = r.content_id)
ELSE NULL
END as content_preview
FROM reports r
JOIN users u1 ON r.reporter_id = u1.id
LEFT JOIN users u2 ON r.reported_user_id = u2.id
WHERE r.status = 'pending'
ORDER BY r.created_at ASC
LIMIT ? OFFSET ?
");
$stmt->execute([$perPage, $offset]);
return $stmt->fetchAll();
}
}