Merge pull request 'Add function to modify and remove warn and ban messages' (#159) from edit-ban-msg into config

Reviewed-on: #159
This commit is contained in:
Zankaria 2025-11-10 15:03:11 -06:00
commit 98e0bee274
2 changed files with 50 additions and 4 deletions

View file

@ -2210,6 +2210,8 @@ function mod_edit_post(Context $ctx, $board, $edit_raw_html, $postID) {
if ($edit_raw_html && !hasPermission($config['mod']['rawhtml'], $board))
error($config['error']['noaccess']);
$ban_msg_access = hasPermission($config['mod']['unban'], $board);
$security_token = make_secure_link_token($board . '/edit' . ($edit_raw_html ? '_raw' : '') . '/' . $postID);
$query = prepare(sprintf('SELECT * FROM ``posts_%s`` WHERE `id` = :id', $board));
@ -2225,6 +2227,20 @@ function mod_edit_post(Context $ctx, $board, $edit_raw_html, $postID) {
// Add back modifiers in the original post
$modifiers = extract_modifiers($post['body_nomarkup']);
if ($ban_msg_access) {
if (empty($_POST['ban-message'])) {
unset($modifiers['ban message']);
} else {
$modifiers['ban message'] = $edit_raw_html ? $_POST['ban-message'] : \htmlspecialchars(\htmlspecialchars($_POST['ban-message']));
}
if (empty($_POST['warn-message'])) {
unset($modifiers['warning message']);
} else {
$modifiers['warning message'] = $edit_raw_html ? $_POST['warn-message'] : \htmlspecialchars(\htmlspecialchars($_POST['warn-message']));
}
}
foreach ($modifiers as $key => $value) {
$_POST['body'] .= "<tinyboard $key>$value</tinyboard>";
}
@ -2257,6 +2273,18 @@ function mod_edit_post(Context $ctx, $board, $edit_raw_html, $postID) {
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['dir']['res'] . link_for($post) . '#' . $postID, true, $config['redirect_http']);
} else {
// Extract the ban/warn messages so that we can edit them.
if ($ban_msg_access) {
$post['modifiers'] = [];
$modifiers = extract_modifiers($post['body_nomarkup']);
if (isset($modifiers['ban message'])) {
$post['modifiers']['ban message'] = $modifiers['ban message'];
}
if (isset($modifiers['warning message'])) {
$post['modifiers']['warning message'] = $modifiers['warning message'];
}
}
// Remove modifiers
$post['body_nomarkup'] = remove_modifiers($post['body_nomarkup']);
@ -2269,9 +2297,9 @@ function mod_edit_post(Context $ctx, $board, $edit_raw_html, $postID) {
$post['body'] = str_replace("\r", '', $post['body']);
$post['body_nomarkup'] = str_replace("\t", '&#09;', $post['body_nomarkup']);
$post['body'] = str_replace("\t", '&#09;', $post['body']);
}
}
mod_page(_('Edit post'), 'mod/edit_post_form.html', array('token' => $security_token, 'board' => $board, 'raw' => $edit_raw_html, 'post' => $post));
mod_page(_('Edit post'), 'mod/edit_post_form.html', array('token' => $security_token, 'board' => $board, 'raw' => $edit_raw_html, 'post' => $post, 'ban_message_access' => $ban_msg_access));
}
}

View file

@ -1,6 +1,6 @@
<form action="" method="post">
<input type="hidden" name="token" value="{{ token }}">
<table>
<tr>
<th>
@ -35,10 +35,28 @@
<textarea name="body" id="body" rows="8" cols="35">{% if raw %}{{ post.body }}{% else %}{{ post.body_nomarkup }}{% endif %}</textarea>
</td>
</tr>
{% if ban_message_access %}
<tr>
<th>
{% trans %}Ban message{% endtrans %}
</th>
<td>
<textarea name="ban-message" id="ban-message" rows="4" cols="35">{{ post.modifiers['ban message'] }}</textarea>
</td>
</tr>
<tr>
<th>
{% trans %}Warn message{% endtrans %}
</th>
<td>
<textarea name="warn-message" id="warn-message" rows="4" cols="35">{{ post.modifiers['warning message'] }}</textarea>
</td>
</tr>
{% endif %}
</table>
<p style="text-align:center">
{% if raw %}
{% trans %}Currently editing raw HTML.{% endtrans %}
{% trans %}Currently editing raw HTML.{% endtrans %}
<a href="?/{{ board }}/edit/{{ post.id }}">{% trans %}Edit markup instead?{% endtrans %}</a>
{% else %}
<a href="?/{{ board }}/edit_raw/{{ post.id }}">{% trans %}Edit raw HTML instead?{% endtrans %}</a>