mastodonapi.php aktualisiert

This commit is contained in:
simonpipe 2025-08-13 13:36:27 +02:00
parent 6e6c2cf102
commit 99c19422db

View file

@ -2,7 +2,7 @@
// MastodonAPI extension, https://codeberg.org/simonpipe/yellow-mastodonapi // MastodonAPI extension, https://codeberg.org/simonpipe/yellow-mastodonapi
class YellowMastodonAPI { class YellowMastodonAPI {
const VERSION = "0.5.1"; const VERSION = "0.3";
public $yellow; public $yellow;
// Initialisierung // Initialisierung
@ -199,7 +199,7 @@ class YellowMastodonAPI {
return trim(preg_replace('/[^a-z0-9-]+/', '', $slug), '-'); return trim(preg_replace('/[^a-z0-9-]+/', '', $slug), '-');
} }
private function generateMarkdown($title, $slug, $dateTime, $html, $origAuthor, $origUrl, $yellowAuthor, $yellowTag, $images = [], $alts = []) { private function generateMarkdown($title, $slug, $dateTime, $html, $origAuthor, $origUrl, $yellowAuthor, $yellowTag, $images = [], $alts = []) {
$date = new DateTime($dateTime); $date = new DateTime($dateTime);
$formattedDate = $date->format('Y-m-d'); $formattedDate = $date->format('Y-m-d');
$formattedTime = $date->format('H:i:s'); $formattedTime = $date->format('H:i:s');
@ -210,13 +210,18 @@ class YellowMastodonAPI {
$imageMarkdown = ''; $imageMarkdown = '';
foreach ($images as $i => $filename) { foreach ($images as $i => $filename) {
$alt = isset($alts[$i]) ? $alts[$i] : ''; $alt = isset($alts[$i]) ? htmlspecialchars($alts[$i], ENT_QUOTES) : '';
$imageMarkdown .= "\n![" . htmlspecialchars($alt, ENT_QUOTES) . "](" . $filename . ")\n"; $imageMarkdown .= "\n<img src=\"/media/images/" . $filename . "\" alt=\"" . $alt . "\"/>\n";
} }
$featuredImage = ''; $featuredImage = '';
$featuredImageAlt = '';
if (!empty($images)) { if (!empty($images)) {
$featuredImage = "Image: " . $images[0] . "\n"; $featuredImage = "Image: " . $images[0] . "\n";
if (isset($alts[0]) && !empty($alts[0])) {
$featuredImageAlt = "ImageAlt: " . htmlspecialchars($alts[0], ENT_QUOTES) . "\n";
}
} }
$htmlSafeAuthorName = str_replace('@', '&#64;', $origAuthor); $htmlSafeAuthorName = str_replace('@', '&#64;', $origAuthor);
@ -229,14 +234,14 @@ Published: $formattedDate $formattedTime
Author: $yellowAuthor Author: $yellowAuthor
Layout: blog Layout: blog
Tag: $yellowTag Tag: $yellowTag
$featuredImage--- $featuredImage$featuredImageAlt---
$imageMarkdown $imageMarkdown
> "$content" > "$content"
> >
> <a target="_blank" href="$origUrl">$htmlSafeAuthorName</a> > <a target="_blank" href="$origUrl">$htmlSafeAuthorName</a>
MD; MD;
} }
private function getYellowConfig() { private function getYellowConfig() {
return $this->yellow ? $this->yellow->system : null; return $this->yellow ? $this->yellow->system : null;