From 078c04af51c8425e54066da11fd059bedead0247 Mon Sep 17 00:00:00 2001 From: simonpipe Date: Sat, 9 Aug 2025 17:03:17 +0200 Subject: [PATCH] mastodonapi.php aktualisiert --- mastodonapi.php | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/mastodonapi.php b/mastodonapi.php index 9a8c881..f01842b 100644 --- a/mastodonapi.php +++ b/mastodonapi.php @@ -1,21 +1,36 @@ -yellow->system->get("mastodonapiHashtag"); // Filter-Hashtag +$tag = $this->yellow->system->get("mastodonapiTag"); // Yellow-Tag -class YellowMastodonAPI { - const VERSION = "0.1"; +foreach ($statuses as $status) { + // Nur Posts mit dem gewünschten Hashtag importieren + if (!empty($hashtag) && stripos($status["content"], "#$hashtag") === false) { + continue; + } - public $yellow; + $content = strip_tags($status["content"]); + $createdAt = $status["created_at"]; + $title = mb_substr(preg_replace("/\\s+/", " ", $content), 0, 50); + $slug = strtolower(preg_replace("/[^a-z0-9]+/", "-", $title)); + $datePrefix = date("Y-m-d", strtotime($createdAt)); + $fileName = "$datePrefix-$slug.md"; + $path = $this->yellow->system->get("coreServerDocument") . $folder . $fileName; - // Handle initialisation - public function onLoad($yellow) { - $this->yellow = $yellow; - $this->yellow->system->setDefault("mastodonapiInstanceUrl", "https://mastodon.social"); // Deine Mastodon Instanz-URL - $this->yellow->system->setDefault("mastodonapiUserId", ""); // Deine Mastodon User ID (numerisch, z.B. 1234567890) - $this->yellow->system->setDefault("mastodonapiAccessToken", ""); // Optional: Dein persönlicher API-Token (read:statuses) - $this->yellow->system->setDefault("mastodonapiHashtag", ""); - $this->yellow->system->setDefault("mastodonapiAuthor", "YellowUser"); - $this->yellow->system->setDefault("mastodonapiTag", "Fediverse"); - $this->yellow->system->setDefault("mastodonapiFolder", "content/1-blog/"); - $this->yellow->system->setDefault("mastodonapiTriggerPath", "/mastodonapi-webhook-CHANGE_THIS_SECRET_KEY"); + if (file_exists($path)) continue; + + $markdown = << "$content" +> — [@{$status["account"]["acct"]}]({$status["account"]["url"]}) +MARKDOWN; + + if (file_put_contents($path, $markdown) !== false) { + $postsCreated++; } } \ No newline at end of file