functions.php: add has_any_history function

This commit is contained in:
Zankaria 2024-11-12 14:50:39 +01:00
parent aaa725dd06
commit 2981859ac1

View file

@ -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) { function threadLocked($id) {
global $board; global $board;