Add content warning / summary & in reply to

merge-requests/5/head
Terence Eden 2024-03-02 22:48:41 +00:00
rodzic ce30c1d378
commit 3d2957df71
1 zmienionych plików z 30 dodań i 8 usunięć

Wyświetl plik

@ -1198,19 +1198,25 @@ echo <<< HTML
<body>
<ul>
HTML;
// HTML is *probably* sanitised by the sender. But let's not risk it, eh?
// Using the allow-list from https://docs.joinmastodon.org/spec/activitypub/#sanitization
$allowed_elements = ["p", "span", "br", "a", "del", "pre", "code", "em", "strong", "b", "i", "u", "ul", "ol", "li", "blockquote"];
// Print the items in a list
foreach ( $inbox_ordered as $published=>$inbox_message ) {
// Set up the common components
$object = $inbox_message["object"];
if ( isset( $inbox_message["object"]["id"] ) ) {
$id = $inbox_message["object"]["id"];
} else {
$id = "";
}
$actor = $inbox_message["actor"];
$actorName = end( explode("/", $actor ) );
$actorHTML = "<a href=\"$actor\">@{$actorName}</a>";
$timeHTML = "<time datetime=\"{$published}\">{$published}</time>";
// HTML is *probably* sanitised by the sender. But let's not risk it, eh?
// Using the allow-list from https://docs.joinmastodon.org/spec/activitypub/#sanitization
$allowed_elements = ["p", "span", "br", "a", "del", "pre", "code", "em", "strong", "b", "i", "u", "ul", "ol", "li", "blockquote"];
$timeHTML = "<time datetime=\"{$published}\"><a href=\"{$id}\">{$published}</a></time>";
// What type of message is this?
$type = $inbox_message["type"];
@ -1219,7 +1225,23 @@ HTML;
if ( "Create" == $type || "Update" == $type ) {
// Get the HTML content and sanitise it.
$content = $object["content"];
$content = strip_tags($content, $allowed_elements);
$content = strip_tags( $content, $allowed_elements );
// Is this a reply to something?
if ( isset( $object["inReplyTo"] ) ) {
$replyToURl = $object["inReplyTo"];
$replyTo = " in reply to <a href=\"{$replyToURl}\">$replyToURl</a>";
} else {
$replyTo = "";
}
// Check to see if there is a Content Warning
if ( isset( $object["summary"] ) ) {
$summary = $object["summary"];
$summary = strip_tags( $summary, $allowed_elements );
$content = "<details><summary>{$summary}</summary>{$content}</details>";
}
// Add any images
if ( isset( $object["attachment"] ) ) {
@ -1249,9 +1271,9 @@ HTML;
"Create" == $type ? $verb = "wrote" : $verb = "updated";
if ( $reply ) {
// Highlight that this is a reply
echo "<li><mark>{$timeHTML} {$actorHTML} {$verb}:</mark> <blockquote>{$content}</blockquote></li>";
echo "<li><mark>{$timeHTML} {$actorHTML} {$verb}{$replyTo}:</mark> <blockquote>{$content}</blockquote></li>";
} else {
echo "<li>{$timeHTML} {$actorHTML} {$verb}: <blockquote>{$content}</blockquote></li>";
echo "<li>{$timeHTML} {$actorHTML} {$verb}{$replyTo}: <blockquote>{$content}</blockquote></li>";
}
} else if ( "Like" == $type ) {