diff --git a/mastodonapi.php b/mastodonapi.php index 10399a7..6fd9d79 100644 --- a/mastodonapi.php +++ b/mastodonapi.php @@ -2,7 +2,7 @@ // Mastodonapi extension, https://codeberg.org/simonpipe/yellow-mastodonapi class YellowMastodonapi { - const VERSION = "0.9.7"; + const VERSION = "0.9.8"; public $yellow; // access to API // Initialize extension @@ -103,30 +103,46 @@ class YellowMastodonapi { echo "DEBUG: " . count($posts) . " Posts von API empfangen.\n"; $postsCreated = 0; - foreach ( $posts as $post ) { - // FIX: Reblog-Erkennung robuster für Snac - if ( !empty($post["reblog"]) || (isset($post["reblogged"]) && $post["reblogged"]===true) ) { - continue; + foreach ( $posts as $index => $post ) { + // Snac-Verschachtelung auflösen: Wenn ein echtes 'reblog'-Objekt von jemand anderem drinsteckt + if ( !empty($post["reblog"]) && is_array($post["reblog"]) ) { + // Nur überspringen, wenn es wirklich der Post eines ANDEREN Nutzers ist, den du geteilt hast + if ( !empty($post["reblog"]["account"]["id"]) && $post["reblog"]["account"]["id"] != $accountId ) { + echo "DEBUG [$index]: Übersprungen (Echter Reblog eines fremden Beitrags)\n"; + continue; + } + // Wenn es dein eigener ist, nutzen wir die inneren Daten + $post = $post["reblog"]; } - - // FIX: Snac sendet leere Strings "" statt null bei in_reply_to_id - if ( !empty($post["in_reply_to_id"]) ) { - continue; - } - + $contentHtml = $post["content"] ?? ""; $createdAt = $post["created_at"] ?? ""; + $shortText = mb_substr(strip_tags($contentHtml), 0, 40) . "..."; + // Reblogged-Flag nur werten, wenn es kein Eigen-Boost ist + if ( (isset($post["reblogged"]) && $post["reblogged"]===true) && empty($contentHtml) ) { + echo "DEBUG [$index]: Übersprungen (Leerer Boost): $shortText\n"; + continue; + } + + // REPLY CHECK (Snac sendet leere Strings oder null) + if ( !empty($post["in_reply_to_id"]) ) { + echo "DEBUG [$index]: Übersprungen (Antwort - Reply-ID: " . $post["in_reply_to_id"] . "): $shortText\n"; + continue; + } + + // ALTER CHECK if ( $maxAgeHours > 0 ) { if ( strtotime($createdAt) < ( time() - ( $maxAgeHours * 3600 ) ) ) { - echo "DEBUG: Post übersprungen (zu alt): " . mb_substr(strip_tags($contentHtml), 0, 30) . "...\n"; + echo "DEBUG [$index]: Übersprungen (Zu alt - Datum: $createdAt): $shortText\n"; continue; } } - + + // HASHTAG CHECK $tags = array_column($post["tags"] ?? array(), "name"); if ( !empty($hashtag) && !in_array(strtolower($hashtag), array_map("strtolower", $tags)) ) { - echo "DEBUG: Post übersprungen (Hashtag #$hashtag fehlt): " . mb_substr(strip_tags($contentHtml), 0, 30) . "...\n"; + echo "DEBUG [$index]: Übersprungen (Hashtag #$hashtag fehlt): $shortText\n"; continue; } @@ -135,8 +151,9 @@ class YellowMastodonapi { $fileName = date("Y-m-d", strtotime($createdAt)) . "-" . $titleSlug . ".md"; $fullPath = $this->yellow->system->get("coreServerDocument") . $targetFolder . $fileName; + // EXISTENZ CHECK if ( file_exists($fullPath) ) { - echo "DEBUG: Post übersprungen (Datei existiert bereits: $fileName)\n"; + echo "DEBUG [$index]: Übersprungen (Datei existiert bereits: $fileName): $shortText\n"; continue; } @@ -168,7 +185,7 @@ class YellowMastodonapi { file_put_contents($fullPath, $markdownContent); chmod($fullPath, 0666); - echo "-> Erstellt: $fileName\n"; + echo "-> ERSTELLT [$index]: $fileName ($shortText)\n"; $postsCreated++; } return $postsCreated;