diff --git a/mastodonapi.php b/mastodonapi.php index d0266a6..46cf316 100644 --- a/mastodonapi.php +++ b/mastodonapi.php @@ -2,7 +2,7 @@ // MastodonAPI extension, https://codeberg.org/simonpipe/yellow-mastodonapi class YellowMastodonAPI { - const VERSION = "0.2"; + const VERSION = "0.5.1"; public $yellow; // Initialisierung @@ -16,6 +16,7 @@ class YellowMastodonAPI { $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"); + $this->yellow->system->setDefault("mastodonapiLimit", "20"); // neu: Anzahl Posts } // Webhook-Request @@ -55,24 +56,26 @@ class YellowMastodonAPI { $defaultAuthor = $this->yellow->system->get("mastodonapiAuthor"); $defaultTag = $this->yellow->system->get("mastodonapiTag"); $targetFolder = $this->yellow->system->get("mastodonapiFolder"); + $limit = intval($this->yellow->system->get("mastodonapiLimit")); if (empty($instanceUrl) || empty($accountId)) { error_log("ERROR: MastodonAPI: Missing configuration values."); return false; } - $apiUrl = rtrim($instanceUrl, "/") . "/api/v1/accounts/" . $accountId . "/statuses?limit=20"; + $apiUrl = rtrim($instanceUrl, "/") . "/api/v1/accounts/" . $accountId . "/statuses?limit=" . $limit; - // HTTP Header dynamisch aufbauen - $headers = "User-Agent: YellowMastodonAPI\r\n"; + $headers = [ + "User-Agent: YellowMastodonAPI" + ]; if (!empty($accessToken)) { - $headers .= "Authorization: Bearer " . $accessToken . "\r\n"; + $headers[] = "Authorization: Bearer " . $accessToken; } $context = stream_context_create([ 'http' => [ 'method' => "GET", - 'header' => $headers, + 'header' => implode("\r\n", $headers) . "\r\n", 'timeout' => 30 ], 'ssl' => [ @@ -82,6 +85,16 @@ class YellowMastodonAPI { ]); $json = @file_get_contents($apiUrl, false, $context); + + // Debug-Ausgabe + if (isset($http_response_header)) { + error_log("MastodonAPI DEBUG: HTTP Response Headers:"); + foreach ($http_response_header as $header) { + error_log(" " . $header); + } + } + error_log("MastodonAPI DEBUG: Raw API Response: " . substr($json, 0, 500)); + if ($json === false) { error_log("ERROR: MastodonAPI: Could not fetch API data from $apiUrl"); return false; @@ -97,6 +110,15 @@ class YellowMastodonAPI { $postsCreated = 0; foreach ($posts as $post) { + + // Lokaler Filter: keine Boosts, keine Antworten + if (!empty($post['reblog']) || (!empty($post['reblogged']) && $post['reblogged'] === true)) { + continue; + } + if (!is_null($post['in_reply_to_id'])) { + continue; + } + $contentHtml = $post['content']; $createdAt = $post['created_at']; $tags = array_column($post['tags'], 'name'); @@ -228,4 +250,4 @@ MD; echo "

" . htmlspecialchars($message) . "

"; exit; } -} +} \ No newline at end of file