In ban form, display the post so we can select which parts of it to mark as spam (for spamnoticer)

This commit is contained in:
towards-a-new-leftypol 2023-08-07 23:14:56 -04:00
parent 0f16b9bf93
commit 16286aa62b
4 changed files with 200 additions and 110 deletions

View File

@ -6,8 +6,6 @@
defined('TINYBOARD') or exit; defined('TINYBOARD') or exit;
require_once 'inc/anti-bot.php'; // DELETE ME THIS IS FOR print_err function only!
function mod_page($title, $template, $args, $subtitle = false) { function mod_page($title, $template, $args, $subtitle = false) {
global $config, $mod; global $config, $mod;
@ -1755,7 +1753,7 @@ function mod_merge($originBoard, $postID) {
mod_page(_('Merge thread'), 'mod/merge.html', array('post' => $postID, 'board' => $originBoard, 'boards' => $boards, 'token' => $security_token)); mod_page(_('Merge thread'), 'mod/merge.html', array('post' => $postID, 'board' => $originBoard, 'boards' => $boards, 'token' => $security_token));
} }
function mod_ban_post($board, $delete, $post, $token = false) { function mod_ban_post($board, $delete, $post_num, $token = false) {
global $config, $mod; global $config, $mod;
if (!openBoard($board)) if (!openBoard($board))
@ -1764,17 +1762,17 @@ function mod_ban_post($board, $delete, $post, $token = false) {
if (!hasPermission($config['mod']['delete'], $board)) if (!hasPermission($config['mod']['delete'], $board))
error($config['error']['noaccess']); error($config['error']['noaccess']);
$security_token = make_secure_link_token($board . '/ban/' . $post); $security_token = make_secure_link_token($board . '/ban/' . $post_num);
$query = prepare(sprintf('SELECT ' . ($config['ban_show_post'] ? '*' : '`ip`, `thread`') . $query = prepare(sprintf('SELECT *' .
' FROM ``posts_%s`` WHERE `id` = :id', $board)); ' FROM ``posts_%s`` WHERE `id` = :id', $board));
$query->bindValue(':id', $post); $query->bindValue(':id', $post_num);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
if (!$_post = $query->fetch(PDO::FETCH_ASSOC)) if (!$post = $query->fetch(PDO::FETCH_ASSOC))
error($config['error']['404']); error($config['error']['404']);
$thread = $_post['thread']; $thread = $post['thread'];
$ip = $_post['ip']; $ip = $post['ip'];
if (isset($_POST['new_ban'], $_POST['reason'], $_POST['length'], $_POST['board'])) { if (isset($_POST['new_ban'], $_POST['reason'], $_POST['length'], $_POST['board'])) {
require_once 'inc/mod/ban.php'; require_once 'inc/mod/ban.php';
@ -1783,7 +1781,7 @@ function mod_ban_post($board, $delete, $post, $token = false) {
$ip = $_POST['ip']; $ip = $_POST['ip'];
Bans::new_ban($_POST['ip'], $_POST['reason'], $_POST['length'], $_POST['board'] == '*' ? false : $_POST['board'], Bans::new_ban($_POST['ip'], $_POST['reason'], $_POST['length'], $_POST['board'] == '*' ? false : $_POST['board'],
false, $config['ban_show_post'] ? $_post : false); false, $config['ban_show_post'] ? $post : false);
if (isset($_POST['public_message'], $_POST['message'])) { if (isset($_POST['public_message'], $_POST['message'])) {
// public ban message // public ban message
@ -1792,19 +1790,19 @@ function mod_ban_post($board, $delete, $post, $token = false) {
$_POST['message'] = str_replace('%length%', $length_english, $_POST['message']); $_POST['message'] = str_replace('%length%', $length_english, $_POST['message']);
$_POST['message'] = str_replace('%LENGTH%', strtoupper($length_english), $_POST['message']); $_POST['message'] = str_replace('%LENGTH%', strtoupper($length_english), $_POST['message']);
$query = prepare(sprintf('UPDATE ``posts_%s`` SET `body_nomarkup` = CONCAT(`body_nomarkup`, :body_nomarkup) WHERE `id` = :id', $board)); $query = prepare(sprintf('UPDATE ``posts_%s`` SET `body_nomarkup` = CONCAT(`body_nomarkup`, :body_nomarkup) WHERE `id` = :id', $board));
$query->bindValue(':id', $post); $query->bindValue(':id', $post_num);
$query->bindValue(':body_nomarkup', sprintf("\n<tinyboard ban message>%s</tinyboard>", utf8tohtml($_POST['message']))); $query->bindValue(':body_nomarkup', sprintf("\n<tinyboard ban message>%s</tinyboard>", utf8tohtml($_POST['message'])));
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
rebuildPost($post); rebuildPost($post);
modLog("Attached a public ban message to post #{$post}: " . utf8tohtml($_POST['message'])); modLog("Attached a public ban message to post #{$post_num}: " . utf8tohtml($_POST['message']));
buildThread($thread ? $thread : $post); buildThread($thread ? $thread : $post_num);
buildIndex(); buildIndex();
} elseif (isset($_POST['delete']) && (int) $_POST['delete']) { } elseif (isset($_POST['delete']) && (int) $_POST['delete']) {
// Delete post // Delete post
if ($config['autotagging']){ if ($config['autotagging']){
$query = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE id = :id", $board)); $query = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE id = :id", $board));
$query->bindValue(':id', $post ); $query->bindValue(':id', $post_num );
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
$ip = ""; $ip = "";
$time = ""; $time = "";
@ -1843,8 +1841,8 @@ function mod_ban_post($board, $delete, $post, $token = false) {
modLog("Added a note for <a href=\"?/IP/{$ip}\">{$ip}</a>"); modLog("Added a note for <a href=\"?/IP/{$ip}\">{$ip}</a>");
} }
} }
deletePost($post); deletePost($post_num);
modLog("Deleted post #{$post}"); modLog("Deleted post #{$post_num}");
// Rebuild board // Rebuild board
buildIndex(); buildIndex();
// Rebuild themes // Rebuild themes
@ -1860,14 +1858,22 @@ function mod_ban_post($board, $delete, $post, $token = false) {
} }
} }
if (!$post['thread']) {
$post = new Thread($post, '?/', false, false);
} else {
$post = new Post($post, '?/', false);
}
$args = array( $args = array(
'ip' => $ip, 'ip' => $ip,
'hide_ip' => !hasPermission($config['mod']['show_ip'], $board), 'hide_ip' => !hasPermission($config['mod']['show_ip'], $board),
'post_num' => $post_num,
'post' => $post, 'post' => $post,
'board' => $board, 'board' => $board,
'delete' => (bool)$delete, 'delete' => (bool) $delete,
'boards' => listBoards(), 'boards' => listBoards(),
'token' => $security_token 'token' => $security_token,
'spamnoticer' => $config['spam_noticer']['enabled']
); );
if(isset($_GET['thread']) && $_GET['thread']) { if(isset($_GET['thread']) && $_GET['thread']) {
@ -2691,7 +2697,6 @@ function clearCacheFiles($cacheLocation) {
function mod_rebuild() { function mod_rebuild() {
global $config, $twig; global $config, $twig;
print_err("mod_rebuild");
if (!hasPermission($config['mod']['rebuild'])) if (!hasPermission($config['mod']['rebuild']))
error($config['error']['noaccess']); error($config['error']['noaccess']);
@ -2716,9 +2721,7 @@ function mod_rebuild() {
if (isset($_POST['rebuild_themes'])) { if (isset($_POST['rebuild_themes'])) {
$log[] = 'Regenerating theme files'; $log[] = 'Regenerating theme files';
print_err("mod_rebuild calling rebuildThemes");
rebuildThemes('all'); rebuildThemes('all');
print_err("mod_rebuild calling rebuildThemes ok");
} }
if (isset($_POST['rebuild_javascript'])) { if (isset($_POST['rebuild_javascript'])) {

32
stylesheets/ban_form.css Normal file
View File

@ -0,0 +1,32 @@
/* Show the table when "Ban" checkbox is checked */
input[type="checkbox"]#checkbox-ban:checked ~ .ban-form {
/* display: table; */
filter: grayscale(0%);
}
/* Hide the table by default */
.ban-form {
filter: grayscale(100%);
}
.ban_delete_action_form {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
.ban-form {
flex-basis: 100%;
}
.ban-form-action--input {
margin: 1em;
}
.ban-form-action--label {
margin-right: 2em;
margin-left: 0em;
margin-top: 1em;
margin-bottom: 1em;
}

View File

@ -0,0 +1,34 @@
{% apply remove_whitespace %}
{# tabs and new lines will be ignored #}
<div class="postcontainer" id="pc{{ post.id }}" data-board="{{ board.uri }}">
{% if post.thread %}
<div class="post reply" id="reply_{{ post.id }}">
{% else %}
<div class="post op" id="thread_{{ post.id }}">
{% endif %}
<p class="intro">
<label for="delete_{{ post.id }}">
{% include 'post/subject.html' %}
{% include 'post/name.html' %}
{% include 'post/ip.html' %}
{% include 'post/flag.html' %}
{% include 'post/time.html' %}
</label>
{% include 'post/poster_id.html' %}&nbsp;
<a class="post_no" id="post_no_{{ post.id }}" onclick="highlightReply({{ post.id }})" href="{% if isnoko50 %}{{ post.link('', config.file_page50) }}{% else %}{{ post.link }}{% endif %}">No.</a>
<a class="post_no" onclick="citeReply({{ post.id }})" href="{% if isnoko50 %}{{ post.link('q', config.file_page50) }}{% else %}{{ post.link('q') }}{% endif %}">{{ post.id }}</a>
</p>
{% set mod=false %}
{% include 'post/fileinfo.html' %}
<div class="body" {% if post.files|length > 1 %}style="clear:both"{% endif %}>
{% endapply %}{% if index %}{{ post.body|truncate_body(post.link) }}{% else %}{{ post.body }}{% endif %}{% apply remove_whitespace %}
{% if post.modifiers['ban message'] %}
{{ config.mod.ban_message|sprintf(post.modifiers['ban message']) }}
{% endif %}
{% if post.modifiers['warning message'] %}
{{ config.mod.warning_message|sprintf(post.modifiers['warning message']) }}
{% endif %}
</div>
</div>
</div>
{% endapply %}

View File

@ -1,23 +1,37 @@
{% if post and board %} {% if post_num and board %}
{% set action = '?/' ~ board ~ '/ban/' ~ post %} {% set action = '?/' ~ board ~ '/ban/' ~ post_num %}
{% else %} {% else %}
{% set action = '?/ban' %} {% set action = '?/ban' %}
{% endif %} {% endif %}
<form action="{{ action }}" method="post"> {% if spamnoticer %}
<link rel="stylesheet" media="screen" href="/stylesheets/ban_form.css">
{% endif %}
<form class="ban_delete_action_form" action="{{ action }}" method="post">
<input type="hidden" name="token" value="{{ token }}"> <input type="hidden" name="token" value="{{ token }}">
{% if redirect %} {% if redirect %}
<input type="hidden" name="redirect" value="{{ redirect|e }}"> <input type="hidden" name="redirect" value="{{ redirect|e }}">
{% endif %} {% endif %}
{% if post and board %} {% if post_num and board %}
<input type="hidden" name="delete" value="{% if delete %}1{% else %}0{% endif %}"> <input type="hidden" name="delete" value="{% if delete %}1{% else %}0{% endif %}">
{% endif %} {% endif %}
{% if thread %} {% if thread %}
<input type="hidden" name="thread" value="{{ thread }}"> <input type="hidden" name="thread" value="{{ thread }}">
{% endif %} {% endif %}
<table> {% if spamnoticer %}
<input class="ban-form-action--input" type="checkbox" id="checkbox-ban" checked>
<label class="ban-form-action--label" for="checkbox-ban">Ban</label>
<input class="ban-form-action--input" type="checkbox" id="checkbox-delete" checked>
<label class="ban-form-action--label" for="checkbox-delete">Delete</label>
<input class="ban-form-action--input" type="checkbox" id="checkbox-ban-content">
<label class="ban-form-action--label" for="checkbox-ban-content">Ban Content</label>
{% endif %}
<table class="ban-form">
<tr> <tr>
<th> <th>
<label for="ip">{% trans 'IP' %} <span class="unimportant">{% trans '(or subnet)' %}</span></label> <label for="ip">{% trans 'IP' %} <span class="unimportant">{% trans '(or subnet)' %}</span></label>
@ -38,7 +52,7 @@
<textarea name="reason" id="reason" rows="5" cols="30">{{ reason|e }}</textarea> <textarea name="reason" id="reason" rows="5" cols="30">{{ reason|e }}</textarea>
</td> </td>
</tr> </tr>
{% if post and board and not delete %} {% if post_num and board and not delete %}
<tr> <tr>
<th> <th>
<label for="reason">{% trans 'Message' %}</label> <label for="reason">{% trans 'Message' %}</label>
@ -85,10 +99,17 @@
{% endfor %} {% endfor %}
</ul> </ul>
</td> </td>
</tr> </table>
{% if spamnoticer %}
<p>If you selected "Ban Content" above, please select which files and whether or not the body should be considered spam:</p>
{% include 'ban_post_content_form.html' %}
{% endif %}
<table>
<tr> <tr>
<td></td> <td>
<td><input name="new_ban" type="submit" value="{% trans 'New Ban' %}"></td> <input name="new_ban" type="submit" value="{% trans 'New Ban' %}" id="new_ban">
<label class="ban-form-action--label" for="new_ban">Submit</label>
</td>
</tr> </tr>
</table> </table>
</form> </form>