From ffb0d405b41f31bbe3d53d341a70eea0d1ee6664 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 19 Feb 2024 22:29:45 +0000 Subject: [PATCH] [comment] fix comment deletion in other themes too --- ext/comment/theme.php | 15 ++++++++++----- themes/danbooru/comment.theme.php | 6 +----- themes/danbooru2/comment.theme.php | 6 +----- themes/futaba/comment.theme.php | 6 +----- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/ext/comment/theme.php b/ext/comment/theme.php index 14ad0ec8..80b9029c 100644 --- a/ext/comment/theme.php +++ b/ext/comment/theme.php @@ -254,11 +254,7 @@ class CommentListTheme extends Themelet $h_ip = $user->can(Permissions::VIEW_IP) ? "
".show_ip($comment->poster_ip, "Comment posted {$comment->posted}") : ""; $h_del = ""; if ($user->can(Permissions::DELETE_COMMENT)) { - $comment_preview = substr(html_unescape($tfe->stripped), 0, 50); - $j_delete_confirm_message = json_encode("Delete comment by {$comment->owner_name}:\n$comment_preview") ?: "Delete "; - $h_delete_script = html_escape("return confirm($j_delete_confirm_message);"); - $h_delete_link = make_link("comment/delete/$i_comment_id/$i_image_id"); - $h_del = " - Del"; + $h_del = " - " . $this->delete_link($i_comment_id, $i_image_id, $comment->owner_name, $tfe->stripped); } $html = "
@@ -273,6 +269,15 @@ class CommentListTheme extends Themelet return $html; } + protected function delete_link(int $comment_id, int $image_id, string $owner, string $text): string + { + $comment_preview = substr(html_unescape($text), 0, 50); + $j_delete_confirm_message = json_encode("Delete comment by {$owner}:\n$comment_preview") ?: "Delete "; + $h_delete_script = html_escape("return confirm($j_delete_confirm_message);"); + $h_delete_link = make_link("comment/delete/$comment_id/$image_id"); + return "Del"; + } + protected function build_postbox(int $image_id): string { global $config; diff --git a/themes/danbooru/comment.theme.php b/themes/danbooru/comment.theme.php index fdf36413..aaa79476 100644 --- a/themes/danbooru/comment.theme.php +++ b/themes/danbooru/comment.theme.php @@ -111,11 +111,7 @@ class CustomCommentListTheme extends CommentListTheme $h_userlink = "$h_name"; $h_del = ""; if ($user->can(Permissions::DELETE_COMMENT)) { - $comment_preview = substr(html_unescape($tfe->stripped), 0, 50); - $j_delete_confirm_message = json_encode_ex("Delete comment by {$comment->owner_name}:\n$comment_preview"); - $h_delete_script = html_escape("return confirm($j_delete_confirm_message);"); - $h_delete_link = make_link("comment/delete/$i_comment_id/$i_image_id"); - $h_del = " - Del"; + $h_del = " - " . $this->delete_link($i_comment_id, $i_image_id, $comment->owner_name, $tfe->stripped); } //$h_imagelink = $trim ? ">>>\n" : ""; if ($trim) { diff --git a/themes/danbooru2/comment.theme.php b/themes/danbooru2/comment.theme.php index df45e10a..25e25897 100644 --- a/themes/danbooru2/comment.theme.php +++ b/themes/danbooru2/comment.theme.php @@ -111,11 +111,7 @@ class CustomCommentListTheme extends CommentListTheme $h_userlink = "$h_name"; $h_del = ""; if ($user->can(Permissions::DELETE_COMMENT)) { - $comment_preview = substr(html_unescape($tfe->stripped), 0, 50); - $j_delete_confirm_message = json_encode_ex("Delete comment by {$comment->owner_name}:\n$comment_preview"); - $h_delete_script = html_escape("return confirm($j_delete_confirm_message);"); - $h_delete_link = make_link("comment/delete/$i_comment_id/$i_image_id"); - $h_del = " - Del"; + $h_del = " - " . $this->delete_link($i_comment_id, $i_image_id, $comment->owner_name, $tfe->stripped); } //$h_imagelink = $trim ? ">>>\n" : ""; if ($trim) { diff --git a/themes/futaba/comment.theme.php b/themes/futaba/comment.theme.php index 0f247df2..e6ced4d3 100644 --- a/themes/futaba/comment.theme.php +++ b/themes/futaba/comment.theme.php @@ -85,11 +85,7 @@ class CustomCommentListTheme extends CommentListTheme $h_date = $comment->posted; $h_del = ""; if ($user->can(Permissions::DELETE_COMMENT)) { - $comment_preview = substr(html_unescape($tfe->stripped), 0, 50); - $j_delete_confirm_message = json_encode_ex("Delete comment by {$comment->owner_name}:\n$comment_preview"); - $h_delete_script = html_escape("return confirm($j_delete_confirm_message);"); - $h_delete_link = make_link("comment/delete/$i_comment_id/$i_image_id"); - $h_del = " - Del"; + $h_del = " - " . $this->delete_link($i_comment_id, $i_image_id, $comment->owner_name, $tfe->stripped); } $h_reply = "[Reply]";