Update mastodonapi.php

This commit is contained in:
simonpipe 2026-01-01 18:36:49 +01:00
parent b2711fe7eb
commit 5420ec8f50

View file

@ -222,7 +222,13 @@ class YellowMastodonapi {
$formattedDate = $date->format('Y-m-d'); $formattedDate = $date->format('Y-m-d');
$formattedTime = $date->format('H:i:s'); $formattedTime = $date->format('H:i:s');
$content = strip_tags($html); // 1. Schritt: HTML-Umbrüche in Newlines umwandeln
$content = str_replace(["<br>", "<br />", "<br/>", "</p>"], ["\n", "\n", "\n", "</p>\n"], $html);
// 2. Schritt: Tags entfernen
$content = strip_tags($content);
// 3. Schritt: HTML-Entities dekodieren
$content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8'); $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
$hashtagString = ''; $hashtagString = '';
@ -236,7 +242,11 @@ class YellowMastodonapi {
} }
} }
$content = trim(preg_replace('/\s+/', ' ', $content)); // WICHTIG: Nur mehrfache LEERZEICHEN kürzen, aber NEWLINES (\n) behalten!
$content = trim(preg_replace('/[ \t]+/', ' ', $content));
// Jetzt die Zeilenumbrüche für das Zitat-Layout vorbereiten
$content = str_replace("\n", "\n> ", $content);
$imageMarkdown = ''; $imageMarkdown = '';
foreach ($images as $i => $filename) { foreach ($images as $i => $filename) {
@ -247,7 +257,7 @@ class YellowMastodonapi {
$featuredImage = ''; $featuredImage = '';
$featuredImageAlt = ''; $featuredImageAlt = '';
if (!empty($images)) { if (!empty($images)) {
$featuredImage = "Image: " . $images[0] . "\n"; $featuredImage = "Image: $images[0]\n";
if (isset($alts[0]) && !empty($alts[0])) { if (isset($alts[0]) && !empty($alts[0])) {
$featuredImageAlt = "ImageAlt: " . htmlspecialchars($alts[0], ENT_QUOTES) . "\n"; $featuredImageAlt = "ImageAlt: " . htmlspecialchars($alts[0], ENT_QUOTES) . "\n";
} }
@ -255,6 +265,7 @@ class YellowMastodonapi {
$htmlSafeAuthorName = str_replace('@', '&#64;', $origAuthor); $htmlSafeAuthorName = str_replace('@', '&#64;', $origAuthor);
// Blockquote final zusammenbauen
$blockquote = "> $content"; $blockquote = "> $content";
if (!empty($hashtagString)) { if (!empty($hashtagString)) {
$blockquote .= "\n>\n> " . $hashtagString; $blockquote .= "\n>\n> " . $hashtagString;