spamnoticer WIP: parse new values being posted to mod_ban_page

This commit is contained in:
towards-a-new-leftypol 2023-08-08 23:57:02 -04:00
parent b634edd6e2
commit a56f585740
3 changed files with 77 additions and 8 deletions

View File

@ -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)); 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) { function mod_ban_post($board, $delete, $post_num, $token = false) {
global $config, $mod; global $config, $mod;
@ -1774,6 +1798,21 @@ function mod_ban_post($board, $delete, $post_num, $token = false) {
$thread = $post['thread']; $thread = $post['thread'];
$ip = $post['ip']; $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'])) { if (isset($_POST['new_ban'], $_POST['reason'], $_POST['length'], $_POST['board'])) {
require_once 'inc/mod/ban.php'; require_once 'inc/mod/ban.php';
@ -1811,6 +1850,7 @@ function mod_ban_post($board, $delete, $post_num, $token = false) {
$subject = ""; $subject = "";
$name = ""; $name = "";
$body = ""; $body = "";
while ($mypost = $query->fetch(PDO::FETCH_ASSOC)) { while ($mypost = $query->fetch(PDO::FETCH_ASSOC)) {
$time = $mypost["time"]; $time = $mypost["time"];
$ip = $mypost["ip"]; $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"; $filename .= $mypost['files'][$file_count]->name . "\r\n";
} }
} }
if ($time !== ''){
if ($time !== '') {
$dt = new DateTime("@$time"); $dt = new DateTime("@$time");
$autotag = ""; $autotag = "";
$autotag .= $name . " " . $subject . " " . $dt->format('Y-m-d H:i:s') . " No.". $post . "\r\n"; $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 <a href=\"?/IP/{$ip}\">{$ip}</a>"); modLog("Added a note for <a href=\"?/IP/{$ip}\">{$ip}</a>");
} }
} }
deletePost($post_num); deletePost($post_num);
modLog("Deleted post #{$post_num}"); modLog("Deleted post #{$post_num}");
// Rebuild board // 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( $args = array(
'ip' => $ip, 'ip' => $ip,
'hide_ip' => !hasPermission($config['mod']['show_ip'], $board), 'hide_ip' => !hasPermission($config['mod']['show_ip'], $board),
'post_num' => $post_num, 'post_num' => $post_num,
'post' => $post, 'post' => $po,
'board' => $board, 'board' => $board,
'delete' => (bool) $delete, 'delete' => (bool) $delete,
'boards' => listBoards(), 'boards' => listBoards(),

View File

@ -18,6 +18,38 @@ class SpamNoticerResult {
public $client = NULL; 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) { function checkWithSpamNoticer($config, $post, $boardname) {
$client = _createClient($config); $client = _createClient($config);

View File

@ -21,6 +21,7 @@
{% endif %} {% endif %}
{% if spamnoticer %} {% if spamnoticer %}
<input type="hidden" name="spamnoticer" value="true">
<input class="ban-form-action--input" type="checkbox" name="checkbox-ban" id="checkbox-ban" checked> <input class="ban-form-action--input" type="checkbox" name="checkbox-ban" id="checkbox-ban" checked>
<label class="ban-form-action--label" for="checkbox-ban">Ban</label> <label class="ban-form-action--label" for="checkbox-ban">Ban</label>