diff options
| author | Michael Save <savetheinternet@tinyboard.org> | 2012-04-21 15:42:33 +1000 |
|---|---|---|
| committer | Michael Save <savetheinternet@tinyboard.org> | 2012-04-21 15:42:33 +1000 |
| commit | c5678daa06d4a90a4686702160f8113461af5443 (patch) | |
| tree | 5563a5e218ce9f57ec0b5bcd08f316043db5d2d6 /inc/mod | |
| parent | 19ea6e3d44186544c15166aa13e4faa1b8804c99 (diff) | |
?/deletebyip
Diffstat (limited to 'inc/mod')
| -rw-r--r-- | inc/mod/pages.php | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 5bba5145..260ad94c 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -534,6 +534,68 @@ function mod_deletefile($board, $post) { header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); } +function mod_deletebyip($boardName, $post, $global = false) { + global $config, $mod, $board; + + $global = (bool)$global; + + if (!openBoard($boardName)) + error($config['error']['noboard']); + + if (!$global && !hasPermission($config['mod']['deletebyip'], $boardName)) + error($config['error']['noaccess']); + + if ($global && !hasPermission($config['mod']['deletebyip_global'], $boardName)) + error($config['error']['noaccess']); + + // Find IP address + $query = prepare(sprintf('SELECT `ip` FROM `posts_%s` WHERE `id` = :id', $boardName)); + $query->bindValue(':id', $post); + $query->execute() or error(db_error($query)); + if (!$ip = $query->fetchColumn(0)) + error($config['error']['invalidpost']); + + $boards = $global ? listBoards() : array(array('uri' => $boardName)); + + $query = ''; + foreach ($boards as $_board) { + $query .= sprintf("SELECT `id`, '%s' AS `board` FROM `posts_%s` WHERE `ip` = :ip UNION ALL ", $_board['uri'], $_board['uri']); + } + $query = preg_replace('/UNION ALL $/', '', $query); + + $query = prepare($query); + $query->bindValue(':ip', $ip); + $query->execute() or error(db_error($query)); + + if ($query->rowCount() < 1) + error($config['error']['invalidpost']); + + $boards = array(); + while ($post = $query->fetch()) { + openBoard($post['board']); + $boards[] = $post['board']; + + deletePost($post['id'], false); + } + + $boards = array_unique($boards); + + foreach ($boards as $_board) { + openBoard($_board); + buildIndex(); + } + + if ($global) { + $board = false; + } + + // Record the action + modLog("Deleted all posts by IP address: <a href=\"?/IP/$ip\">$ip</a>"); + + // Redirect + header('Location: ?/' . sprintf($config['board_path'], $boardName) . $config['file_index'], true, $config['redirect_http']); +} + function mod_user($uid) { global $config, $mod; |
