From de84ca6f755347b2c3fcf87165704a2d9e899d77 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Fri, 20 Apr 2012 21:37:48 +1000 Subject: [PATCH] Multiple improvements: ?/ban/ & ?/ban&delete/ --- inc/mod/pages.php | 47 ++++++++++++++++++++++++++++++++++--- mod.php | 2 +- templates/mod/ban_form.html | 36 ++++++++++++++++++++++++++-- 3 files changed, 79 insertions(+), 6 deletions(-) diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 7bc970b0..78f560ec 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -374,13 +374,54 @@ function mod_ban_post($board, $delete, $post) { if (!hasPermission($config['mod']['delete'], $board)) error($config['error']['noaccess']); - $query = prepare(sprintf('SELECT `ip` FROM `posts_%s` WHERE `id` = :id', $board)); + $query = prepare(sprintf('SELECT `ip`, `thread` FROM `posts_%s` WHERE `id` = :id', $board)); $query->bindValue(':id', $post); $query->execute() or error(db_error($query)); - if(!$ip = $query->fetchColumn(0)) + if(!$_post = $query->fetch(PDO::FETCH_ASSOC)) error($config['error']['404']); - mod_page("New ban", 'mod/ban_form.html', array()); + $thread = $_post['thread']; + $ip = $_post['ip']; + + if (isset($_POST['new_ban'], $_POST['reason'], $_POST['length'], $_POST['board'])) { + require_once 'inc/mod/ban.php'; + + if (isset($_POST['ip'])) + $ip = $_POST['ip']; + + ban($ip, $_POST['reason'], parse_time($_POST['length']), $_POST['board'] == '*' ? false : $_POST['board']); + + if (isset($_POST['public_message'], $_POST['message'])) { + // public ban message + $query = prepare(sprintf('UPDATE `posts_%s` SET `body` = CONCAT(`body`, :body) WHERE `id` = :id', $board)); + $query->bindValue(':id', $post); + $query->bindValue(':body', sprintf($config['mod']['ban_message'], utf8tohtml($_POST['message']))); + $query->execute() or error(db_error($query)); + + modLog("Attached a public ban message to post #{$post}: " . utf8tohtml($_POST['message'])); + buildThread($thread ? $thread : $post); + buildIndex(); + } elseif (isset($_POST['delete'])) { + // Delete post + deletePost($post); + modLog("Deleted post #{$post}"); + // Rebuild board + buildIndex(); + } + + header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); + } + + $args = array( + 'ip' => $ip, + 'hide_ip' => !hasPermission($config['mod']['show_ip'], $board), + 'post' => $post, + 'board' => $board, + 'delete' => (bool)$delete, + 'boards' => listBoards() + ); + + mod_page("New ban", 'mod/ban_form.html', $args); } function mod_delete($board, $post) { diff --git a/mod.php b/mod.php index 57967da5..b5edd255 100644 --- a/mod.php +++ b/mod.php @@ -44,7 +44,7 @@ $pages = array( '!^/bans/(\d+)$!' => 'bans', // ban list '!^/(\w+)/delete/(\d+)$!' => 'delete', // delete post - '!^/(\w+)/ban/(&delete/)?(\d+)$!' => 'ban_post', // ban poster + '!^/(\w+)/ban(&delete)?/(\d+)$!' => 'ban_post', // ban poster '!^/(\w+)/(un)?lock/(\d+)$!' => 'lock', // lock thread '!^/(\w+)/(un)?sticky/(\d+)$!' => 'sticky', // sticky thread '!^/(\w+)/bump(un)?lock/(\d+)$!' => 'bumplock', // "bumplock" thread diff --git a/templates/mod/ban_form.html b/templates/mod/ban_form.html index 1b94e725..9d4d6728 100644 --- a/templates/mod/ban_form.html +++ b/templates/mod/ban_form.html @@ -1,15 +1,29 @@ -
+{% if post and board %} + {% set action = '?/' ~ board ~ '/ban/' ~ post %} +{% else %} + {% set action = '?/ban' %} +{% endif %} + + {% if redirect %} {% endif %} + {% if post and board %} + + {% endif %} + @@ -20,6 +34,24 @@ + {% if post and board and not delete %} + + + + + {% endif %}
- + {% if not hide_ip %} + + {% else %} + hidden + {% endif %}
+ + + + + (public; attached to post) + +