summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonas Kohl2024-10-12 20:10:25 +0200
committerJonas Kohl2024-10-12 20:10:25 +0200
commitd83c43d9c9bc5cd12c9c8b3df6d249fad5b753a8 (patch)
tree5b0c985c1a6959748183a30f33a9a8f9546be8db /src
parentdc5ad376ecc0a58d9e36c7b66cca57794c8b3b88 (diff)
Remove spoilers from search results and profilesv0.5.2
Diffstat (limited to 'src')
-rw-r--r--src/application/views/view_search_results.php2
-rw-r--r--src/application/views/view_user.php2
-rw-r--r--src/index.php12
3 files changed, 12 insertions, 4 deletions
diff --git a/src/application/views/view_search_results.php b/src/application/views/view_search_results.php
index 93e36f7..660284d 100644
--- a/src/application/views/view_search_results.php
+++ b/src/application/views/view_search_results.php
@@ -16,7 +16,7 @@ use mystic\forum\utils\StringUtils;
<?php if ($hasAttachments): ?>
<span class="badge"><span class="fa fa-paperclip"></span></span>
<?php endif; ?>
- <?= htmlentities(html_entity_decode(StringUtils::truncate(strip_tags(renderPost($post->content)), 100))) ?><br>
+ <?= renderPostSummary($post->content) ?><br>
<span class="text-muted"><?= __("posted by %author% on %post_date% in %topic%", [
"author" => '<em>' . htmlentities($users[$post->authorId]?->displayName ?? __("unknown")) . '</em>',
"post_date" => '<span class="_time">' . htmlentities($post->postDate->format("c")) . '</span>',
diff --git a/src/application/views/view_user.php b/src/application/views/view_user.php
index c95b557..e7c9753 100644
--- a/src/application/views/view_user.php
+++ b/src/application/views/view_user.php
@@ -56,7 +56,7 @@ $emailPending = $isOwnProfile && $user->pendingEmail !== null;
<?php if ($hasAttachments): ?>
<span class="badge"><span class="fa fa-paperclip"></span></span>
<?php endif; ?>
- <?= htmlentities(html_entity_decode(StringUtils::truncate(strip_tags(renderPost($post->content)), 100))) ?><br>
+ <?= renderPostSummary($post->content) ?><br>
<span class="text-muted"><?= __("posted on %post_date% in %topic%", [
"post_date" => '<span class="_time">' . htmlentities($post->postDate->format("c")) . '</span>',
"topic" => '<em>' .
diff --git a/src/index.php b/src/index.php
index 156563f..11192e9 100644
--- a/src/index.php
+++ b/src/index.php
@@ -9,10 +9,11 @@ use mystic\forum\orm\Topic;
use mystic\forum\orm\TopicLogMessage;
use mystic\forum\orm\User;
use mystic\forum\utils\RequestUtils;
+use mystic\forum\utils\StringUtils;
header_remove("X-Powered-By");
-const MYSTICBB_VERSION = "0.5.1";
+const MYSTICBB_VERSION = "0.5.2";
if (($_SERVER["HTTP_USER_AGENT"] ?? "") === "") {
http_response_code(403);
@@ -175,7 +176,7 @@ function expandTags(string $contents): string {
"s" => ["<del>", "</del>" ],
"^" => ["<sup>", "</sup>" ],
"_" => ["<sub>", "</sub>" ],
- "spoiler" => [ "<div class=\"panel panel-default\"><div class=\"panel-heading\"><div class=\"panel-title\"><a role=\"button\" data-toggle=\"collapse\" href=\"#$randomId\"><i class=\"fa fa-eye\"></i> Spoiler</a></div></div><div id=\"$randomId\" class=\"panel-collapse collapse\"><div class=\"panel-body\">", "</div></div></div>" ],
+ "spoiler" => [ "<!--##SPOILER_START##--><div class=\"panel panel-default\"><div class=\"panel-heading\"><div class=\"panel-title\"><a role=\"button\" data-toggle=\"collapse\" href=\"#$randomId\"><i class=\"fa fa-eye\"></i> Spoiler</a></div></div><div id=\"$randomId\" class=\"panel-collapse collapse\"><div class=\"panel-body\">", "</div></div></div><!--##SPOILER_END##-->" ],
][$m[1]] ?? $m[1];
if (preg_match(TAGS_REGEX, $inner))
$inner = expandTags($inner);
@@ -186,6 +187,13 @@ function expandTags(string $contents): string {
}, $contents);
}
+function renderPostSummary(string $contents): string {
+ $contents = renderPost($contents);
+ // remove spoiler contents so they don't appear in summaries
+ $contents = preg_replace('/<!--##SPOILER_START##-->(.*?)<!--##SPOILER_END##-->/s', '[ ' . __("Spoiler") . ' ]', $contents);
+ return htmlentities(html_entity_decode(StringUtils::truncate(strip_tags($contents), 100)));
+}
+
function renderPost(string $contents): string {
$contents = preg_replace('~\R~u', "\n", $contents);
$contents = trim($contents);