diff --git a/post.php b/post.php index 78a1bb90..642e8057 100644 --- a/post.php +++ b/post.php @@ -4,6 +4,7 @@ */ use Vichan\Context; +use Vichan\Data\ReportQueries; require_once 'inc/bootstrap.php'; @@ -318,26 +319,6 @@ function db_select_post_minimal($board, $id) return $post; } -/** - * Inserts a new report. - * - * @param string $ip Ip of the user sending the report. - * @param string $board Board of the reported thread. MUST ALREADY BE SANITIZED. - * @param int $post_id Post reported. - * @param string $reason Reason of the report. - * @return void - */ -function db_insert_report($ip, $board, $post_id, $reason) -{ - $query = prepare("INSERT INTO ``reports`` VALUES (NULL, :time, :ip, :board, :post, :reason)"); - $query->bindValue(':time', time(), PDO::PARAM_INT); - $query->bindValue(':ip', $ip, PDO::PARAM_STR); - $query->bindValue(':board', $board, PDO::PARAM_STR); - $query->bindValue(':post', $post_id, PDO::PARAM_INT); - $query->bindValue(':reason', $reason, PDO::PARAM_STR); - $query->execute() or error(db_error($query)); -} - /** * Inserts a new ban appeal into the database. * @@ -711,6 +692,8 @@ function handle_report(Context $ctx) $reason = escape_markup_modifiers($_POST['reason']); markup($reason); + $report_queries = $ctx->get(ReportQueries::class); + foreach ($report as $id) { $post = db_select_post_minimal($board['uri'], $id); if ($post === false) { @@ -739,7 +722,7 @@ function handle_report(Context $ctx) ' for "' . $reason . '"' ); - db_insert_report($_SERVER['REMOTE_ADDR'], $board['uri'], $id, $reason); + $report_queries->add($_SERVER['REMOTE_ADDR'], $board['uri'], $id, $reason); if ($config['slack']) { function slack($message, $room = "reports", $icon = ":no_entry_sign:")