diff --git a/mastodonapi.php b/mastodonapi.php index 46cf316..cb24864 100644 --- a/mastodonapi.php +++ b/mastodonapi.php @@ -2,7 +2,7 @@ // MastodonAPI extension, https://codeberg.org/simonpipe/yellow-mastodonapi class YellowMastodonAPI { - const VERSION = "0.5.1"; + const VERSION = "0.3"; public $yellow; // Initialisierung @@ -199,29 +199,34 @@ class YellowMastodonAPI { return trim(preg_replace('/[^a-z0-9-]+/', '', $slug), '-'); } - private function generateMarkdown($title, $slug, $dateTime, $html, $origAuthor, $origUrl, $yellowAuthor, $yellowTag, $images = [], $alts = []) { - $date = new DateTime($dateTime); - $formattedDate = $date->format('Y-m-d'); - $formattedTime = $date->format('H:i:s'); +private function generateMarkdown($title, $slug, $dateTime, $html, $origAuthor, $origUrl, $yellowAuthor, $yellowTag, $images = [], $alts = []) { + $date = new DateTime($dateTime); + $formattedDate = $date->format('Y-m-d'); + $formattedTime = $date->format('H:i:s'); - $content = strip_tags($html); - $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8'); - $content = trim(preg_replace('/\s+/', ' ', $content)); + $content = strip_tags($html); + $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8'); + $content = trim(preg_replace('/\s+/', ' ', $content)); - $imageMarkdown = ''; - foreach ($images as $i => $filename) { - $alt = isset($alts[$i]) ? $alts[$i] : ''; - $imageMarkdown .= "\n![" . htmlspecialchars($alt, ENT_QUOTES) . "](" . $filename . ")\n"; + $imageMarkdown = ''; + foreach ($images as $i => $filename) { + $alt = isset($alts[$i]) ? htmlspecialchars($alts[$i], ENT_QUOTES) : ''; + $imageMarkdown .= "\n\""\n"; + } + + $featuredImage = ''; + $featuredImageAlt = ''; + + if (!empty($images)) { + $featuredImage = "Image: " . $images[0] . "\n"; + if (isset($alts[0]) && !empty($alts[0])) { + $featuredImageAlt = "ImageAlt: " . htmlspecialchars($alts[0], ENT_QUOTES) . "\n"; } + } - $featuredImage = ''; - if (!empty($images)) { - $featuredImage = "Image: " . $images[0] . "\n"; - } + $htmlSafeAuthorName = str_replace('@', '@', $origAuthor); - $htmlSafeAuthorName = str_replace('@', '@', $origAuthor); - - return << "$content" > > — $htmlSafeAuthorName MD; - } +} private function getYellowConfig() { return $this->yellow ? $this->yellow->system : null;