From 2981859ac1a89df2d415025f07fd41a61ffeb44f Mon Sep 17 00:00:00 2001 From: Zankaria Date: Tue, 12 Nov 2024 14:50:39 +0100 Subject: [PATCH] functions.php: add has_any_history function --- inc/functions.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/inc/functions.php b/inc/functions.php index 2328c1b7..0958e2cb 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -918,6 +918,26 @@ function checkBan($board = false) { } } +/** + * Checks if the given IP has any previous posts. + * + * @param string $ip The IP to check. + * @return bool True if the ip has already sent at least one post, false otherwise. + */ +function has_any_history(string $ip): bool { + foreach (listBoards(true) as $board_uri) { + $query = prepare(sprintf('SELECT `id` FROM ``posts_%s`` WHERE `ip` = :ip LIMIT 1', $board_uri)); + $query->bindValue(':ip', $ip); + $query->execute() or error(db_error()); + + if ($query->fetchColumn() !== false) { + // Found a post. + return true; + } + } + return false; +} + function threadLocked($id) { global $board;