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
|
<?php /* Copyright (c) 2024 Freya Murphy */
class _comments_model extends Model {
private $profanity;
function __construct()
{
$this->profanity = $this->load_profanity();
}
private function load_profanity()
{
$path = ASSET_ROOT . '/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)
{
return preg_match($this->profanity, $text);
}
public function get_comments($page)
{
$ip = CONTEXT['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 post_comment($author, $content, $page, $vulgar)
{
$ip = CONTEXT['ip'];
return $this->db()
->insert_into('admin.comment',
'author', 'content', 'page', 'ip', 'vulgar')
->values($author, $content, $page, $ip, $vulgar)
->execute();
}
}
|