summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Save <savetheinternet@tinyboard.org>2012-04-20 21:37:48 +1000
committerMichael Save <savetheinternet@tinyboard.org>2012-04-20 21:37:48 +1000
commitde84ca6f755347b2c3fcf87165704a2d9e899d77 (patch)
treeec2a1d821a599d59bb7589086536f565348b636a
parent4fcf9c2c916140f8dc95fc975b4ff61cfb98c6cf (diff)
Multiple improvements: ?/ban/<post> & ?/ban&delete/<post>
-rw-r--r--inc/mod/pages.php47
-rw-r--r--mod.php2
-rw-r--r--templates/mod/ban_form.html36
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 @@
-<form action="?/ban" method="post">
+{% if post and board %}
+ {% set action = '?/' ~ board ~ '/ban/' ~ post %}
+{% else %}
+ {% set action = '?/ban' %}
+{% endif %}
+
+<form action="{{ action }}" method="post">
{% if redirect %}
<input type="hidden" name="redirect" value="{{ redirect|e }}">
{% endif %}
+ {% if post and board %}
+ <input type="hidden" name="delete" value="{% if delete %}1{% else %}0{% endif %}">
+ {% endif %}
<table>
+
<tr>
<th>
<label for="ip">IP <span class="unimportant">(or subnet)</span></label>
</th>
<td>
- <input type="text" name="ip" id="ip" size="30" maxlength="40" value="{{ ip }}">
+ {% if not hide_ip %}
+ <input type="text" name="ip" id="ip" size="30" maxlength="40" value="{{ ip }}">
+ {% else %}
+ <em>hidden</em>
+ {% endif %}
</td>
</tr>
<tr>
@@ -20,6 +34,24 @@
<textarea name="reason" id="reason" rows="5" cols="30">{{ reason|e }}</textarea>
</td>
</tr>
+ {% if post and board and not delete %}
+ <tr>
+ <th>
+ <label for="reason">Message</label>
+ </th>
+ <td>
+ <input type="checkbox" id="public_message" name="public_message">
+ <input type="text" name="message" id="message" size="35" maxlength="200" value="{{ config.mod.default_ban_message|e }}">
+ <span class="unimportant">(public; attached to post)</span>
+ <script type="text/javascript">
+ document.getElementById('message').disabled = true;
+ document.getElementById('public_message').onchange = function() {
+ document.getElementById('message').disabled = !this.checked;
+ }
+ </script>
+ </td>
+ </tr>
+ {% endif %}
<tr>
<th>
<label for="length">Length</label>