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
|
<?php /* Copyright (c) 2024 Freya Murphy */
class _comments_model extends Model {
function __construct($load) {
parent::__construct($load);
}
private function load_profanity() {
$path = $GLOBALS['assetroot'] . '/profanity.txt';
$str = file_get_contents($path);
$lines = explode("\n", $str);
$regex = '/(';
foreach ($lines as $idx => $line) {
if ($line == '') {
continue;
}
if ($idx != 0) {
$regex .= '|';
}
$regex .= $line;
}
$regex .= ')/';
return $regex;
}
public function is_vulgar($text) {
$profanity = $this->load_profanity();
return preg_match($profanity, $text);
}
public function get_comments($page) {
$ip = $this->main->info['ip'];
$query = $this->db
->select('*')
->from('admin.comment c')
->where('c.page')
->eq($page)
->query('AND (
(c.vulgar IS FALSE) OR
(c.vulgar IS TRUE and c.ip = ?)
)')
->order_by('c.id', 'DESC');
$result = $query->rows($ip);
return $result;
}
public function ban_user() {
$ip = $this->main->info['ip'];
$this->db
->insert_into('admin.banned', 'ip', 'reason')
->values($ip, 'vulgar language')
->execute();
}
public function post_comment($author, $content, $page, $vulgar) {
$ip = $this->main->info['ip'];
return $this->db
->insert_into('admin.comment',
'author', 'content', 'page', 'ip', 'vulgar')
->values($author, $content, $page, $ip, $vulgar)
->execute();
}
}
|