From d451f164a34f22345542551209669faf86bc7daf Mon Sep 17 00:00:00 2001 From: discomrade <83621080+discomrade@users.noreply.github.com> Date: Tue, 20 Feb 2024 03:02:43 +0000 Subject: [PATCH] [comment] fix unnecessary truncate when trimming Also makes trimming consistent across themes --- ext/comment/theme.php | 6 +++++- themes/danbooru/comment.theme.php | 6 +++++- themes/danbooru2/comment.theme.php | 6 +++++- themes/futaba/comment.theme.php | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ext/comment/theme.php b/ext/comment/theme.php index 80b9029c..9cbdc108 100644 --- a/ext/comment/theme.php +++ b/ext/comment/theme.php @@ -209,7 +209,11 @@ class CommentListTheme extends Themelet $i_uid = $comment->owner_id; $h_name = html_escape($comment->owner_name); $h_timestamp = autodate($comment->posted); - $h_comment = ($trim ? truncate($tfe->stripped, 50) : $tfe->formatted); + if ($trim) { + $h_comment = strlen($tfe->stripped) > 52 ? substr($tfe->stripped, 0, 50)."..." : $tfe->stripped; + } else { + $h_comment = $tfe->formatted; + } $i_comment_id = $comment->comment_id; $i_image_id = $comment->image_id; diff --git a/themes/danbooru/comment.theme.php b/themes/danbooru/comment.theme.php index aaa79476..8214b9d9 100644 --- a/themes/danbooru/comment.theme.php +++ b/themes/danbooru/comment.theme.php @@ -103,7 +103,11 @@ class CustomCommentListTheme extends CommentListTheme //$i_uid = $comment->owner_id; $h_name = html_escape($comment->owner_name); //$h_poster_ip = html_escape($comment->poster_ip); - $h_comment = ($trim ? substr($tfe->stripped, 0, 50)."..." : $tfe->formatted); + if ($trim) { + $h_comment = strlen($tfe->stripped) > 52 ? substr($tfe->stripped, 0, 50)."..." : $tfe->stripped; + } else { + $h_comment = $tfe->formatted; + } $i_comment_id = $comment->comment_id; $i_image_id = $comment->image_id; $h_posted = autodate($comment->posted); diff --git a/themes/danbooru2/comment.theme.php b/themes/danbooru2/comment.theme.php index 25e25897..59bd1143 100644 --- a/themes/danbooru2/comment.theme.php +++ b/themes/danbooru2/comment.theme.php @@ -103,7 +103,11 @@ class CustomCommentListTheme extends CommentListTheme //$i_uid = $comment->owner_id; $h_name = html_escape($comment->owner_name); //$h_poster_ip = html_escape($comment->poster_ip); - $h_comment = ($trim ? substr($tfe->stripped, 0, 50)."..." : $tfe->formatted); + if ($trim) { + $h_comment = strlen($tfe->stripped) > 52 ? substr($tfe->stripped, 0, 50)."..." : $tfe->stripped; + } else { + $h_comment = $tfe->formatted; + } $i_comment_id = $comment->comment_id; $i_image_id = $comment->image_id; $h_posted = autodate($comment->posted); diff --git a/themes/futaba/comment.theme.php b/themes/futaba/comment.theme.php index e6ced4d3..0335e032 100644 --- a/themes/futaba/comment.theme.php +++ b/themes/futaba/comment.theme.php @@ -77,7 +77,11 @@ class CustomCommentListTheme extends CommentListTheme //$i_uid = $comment->owner_id; $h_name = html_escape($comment->owner_name); //$h_poster_ip = html_escape($comment->poster_ip); - $h_comment = ($trim ? substr($tfe->stripped, 0, 50)."..." : $tfe->formatted); + if ($trim) { + $h_comment = strlen($tfe->stripped) > 52 ? substr($tfe->stripped, 0, 50)."..." : $tfe->stripped; + } else { + $h_comment = $tfe->formatted; + } $i_comment_id = $comment->comment_id; $i_image_id = $comment->image_id;