post.php: use ReportQueries

This commit is contained in:
Zankaria 2024-11-27 17:33:04 +01:00
parent 18f1aff2f6
commit 0a2b1b5439

View file

@ -4,6 +4,7 @@
*/ */
use Vichan\Context; use Vichan\Context;
use Vichan\Data\ReportQueries;
require_once 'inc/bootstrap.php'; require_once 'inc/bootstrap.php';
@ -318,26 +319,6 @@ function db_select_post_minimal($board, $id)
return $post; 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. * Inserts a new ban appeal into the database.
* *
@ -711,6 +692,8 @@ function handle_report(Context $ctx)
$reason = escape_markup_modifiers($_POST['reason']); $reason = escape_markup_modifiers($_POST['reason']);
markup($reason); markup($reason);
$report_queries = $ctx->get(ReportQueries::class);
foreach ($report as $id) { foreach ($report as $id) {
$post = db_select_post_minimal($board['uri'], $id); $post = db_select_post_minimal($board['uri'], $id);
if ($post === false) { if ($post === false) {
@ -739,7 +722,7 @@ function handle_report(Context $ctx)
' for "' . $reason . '"' ' 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']) { if ($config['slack']) {
function slack($message, $room = "reports", $icon = ":no_entry_sign:") function slack($message, $room = "reports", $icon = ":no_entry_sign:")