summaryrefslogtreecommitdiff
path: root/src/web/_model/_comments.php
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-05-24 09:05:42 -0400
committerFreya Murphy <freya@freyacat.org>2024-05-24 09:05:42 -0400
commitc5f39ea2cd7cf02246705ea8872d3b350526165c (patch)
tree2694f9fdc5d83b529a01f2997c1d89c271c86592 /src/web/_model/_comments.php
downloadwebsite-c5f39ea2cd7cf02246705ea8872d3b350526165c.tar.gz
website-c5f39ea2cd7cf02246705ea8872d3b350526165c.tar.bz2
website-c5f39ea2cd7cf02246705ea8872d3b350526165c.zip
initial
Diffstat (limited to 'src/web/_model/_comments.php')
-rw-r--r--src/web/_model/_comments.php66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/web/_model/_comments.php b/src/web/_model/_comments.php
new file mode 100644
index 0000000..73c1fc7
--- /dev/null
+++ b/src/web/_model/_comments.php
@@ -0,0 +1,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();
+ }
+
+}