From a56f58574016b7d9469c0af783d1c862c6e1a2a4 Mon Sep 17 00:00:00 2001 From: towards-a-new-leftypol Date: Tue, 8 Aug 2023 23:57:02 -0400 Subject: [PATCH] spamnoticer WIP: parse new values being posted to mod_ban_page --- inc/mod/pages.php | 52 +++++++++++++++++++++++++++++++------ inc/spamnoticer.php | 32 +++++++++++++++++++++++ templates/mod/ban_form.html | 1 + 3 files changed, 77 insertions(+), 8 deletions(-) diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 93197d6b..48d17406 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1753,6 +1753,30 @@ function mod_merge($originBoard, $postID) { mod_page(_('Merge thread'), 'mod/merge.html', array('post' => $postID, 'board' => $originBoard, 'boards' => $boards, 'token' => $security_token)); } +function parse_spamnoticer_content_fields($postData, $post): BanFormFieldsForSpamnoticer { + $files_info = array(); + + foreach ($post->files as $file) { + $filename = $file->file; + $filekey = str_replace('.', '_', $filename); // because $_POST actually does the inverse of this when no one is asking it to. php is a fucking idiotic language + + $fileSpamKey = "file_is_spam_$filekey"; + $fileIllegalKey = "file_is_illegal_$filekey"; + + $is_spam = isset($postData[$fileSpamKey]); + $is_illegal = isset($postData[$fileIllegalKey]); + + $fileInfo = new SpamNoticerBanFileInfo($filename, $is_illegal, $is_spam); + array_push($files_info, $fileInfo); + } + + $ban = isset($postData['checkbox-ban']); + $delete = isset($postData['checkbox-delete']); + $ban_content = isset($postData['checkbox-ban-content']); + + return new BanFormFieldsForSpamnoticer($ban, $delete, $ban_content, $files_info); +} + function mod_ban_post($board, $delete, $post_num, $token = false) { global $config, $mod; @@ -1774,6 +1798,21 @@ function mod_ban_post($board, $delete, $post_num, $token = false) { $thread = $post['thread']; $ip = $post['ip']; + if (!$post['thread']) { + $po = new Thread($post, '?/', false, false); + } else { + $po = new Post($post, '?/', false); + } + + require_once 'inc/spamnoticer.php'; + + if (isset($_POST['spamnoticer'])) { + $spamnoticer_info = parse_spamnoticer_content_fields($_POST, $po); + echo json_encode($spamnoticer_info); + die(); + return; + } + if (isset($_POST['new_ban'], $_POST['reason'], $_POST['length'], $_POST['board'])) { require_once 'inc/mod/ban.php'; @@ -1811,6 +1850,7 @@ function mod_ban_post($board, $delete, $post_num, $token = false) { $subject = ""; $name = ""; $body = ""; + while ($mypost = $query->fetch(PDO::FETCH_ASSOC)) { $time = $mypost["time"]; $ip = $mypost["ip"]; @@ -1824,7 +1864,8 @@ function mod_ban_post($board, $delete, $post_num, $token = false) { $filename .= $mypost['files'][$file_count]->name . "\r\n"; } } - if ($time !== ''){ + + if ($time !== '') { $dt = new DateTime("@$time"); $autotag = ""; $autotag .= $name . " " . $subject . " " . $dt->format('Y-m-d H:i:s') . " No.". $post . "\r\n"; @@ -1841,6 +1882,7 @@ function mod_ban_post($board, $delete, $post_num, $token = false) { modLog("Added a note for {$ip}"); } } + deletePost($post_num); modLog("Deleted post #{$post_num}"); // Rebuild board @@ -1858,17 +1900,11 @@ function mod_ban_post($board, $delete, $post_num, $token = false) { } } - if (!$post['thread']) { - $post = new Thread($post, '?/', false, false); - } else { - $post = new Post($post, '?/', false); - } - $args = array( 'ip' => $ip, 'hide_ip' => !hasPermission($config['mod']['show_ip'], $board), 'post_num' => $post_num, - 'post' => $post, + 'post' => $po, 'board' => $board, 'delete' => (bool) $delete, 'boards' => listBoards(), diff --git a/inc/spamnoticer.php b/inc/spamnoticer.php index eb68a02d..3eb33392 100644 --- a/inc/spamnoticer.php +++ b/inc/spamnoticer.php @@ -18,6 +18,38 @@ class SpamNoticerResult { public $client = NULL; } +class SpamNoticerBanFileInfo { + public $filename; + public $is_illegal; + public $is_spam; + + public function __construct($filename, $isIllegal, $isSpam) { + $this->filename = $filename; + $this->is_illegal = $isIllegal; + $this->is_spam = $isSpam; + } +} + +class BanFormFieldsForSpamnoticer { + public bool $ban; + public bool $delete; + public bool $ban_content; + public array $files_info; + + public function __construct( + bool $ban, + bool $delete, + bool $ban_content, + array $files_info, // Array of SpamNoticerBanFileInfo + ) { + $this->ban = $ban; + $this->delete = $delete; + $this->ban_content = $ban_content; + $this->files_info = $files_info; + } + +} + function checkWithSpamNoticer($config, $post, $boardname) { $client = _createClient($config); diff --git a/templates/mod/ban_form.html b/templates/mod/ban_form.html index 782d61b2..881d28e1 100644 --- a/templates/mod/ban_form.html +++ b/templates/mod/ban_form.html @@ -21,6 +21,7 @@ {% endif %} {% if spamnoticer %} +