Update mastodonapi.php
This commit is contained in:
parent
faef38bec7
commit
6996fd4ac6
1 changed files with 33 additions and 16 deletions
|
|
@ -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.9.7";
|
const VERSION = "0.9.8";
|
||||||
public $yellow; // access to API
|
public $yellow; // access to API
|
||||||
|
|
||||||
// Initialize extension
|
// Initialize extension
|
||||||
|
|
@ -103,30 +103,46 @@ class YellowMastodonapi {
|
||||||
echo "DEBUG: " . count($posts) . " Posts von API empfangen.\n";
|
echo "DEBUG: " . count($posts) . " Posts von API empfangen.\n";
|
||||||
|
|
||||||
$postsCreated = 0;
|
$postsCreated = 0;
|
||||||
foreach ( $posts as $post ) {
|
foreach ( $posts as $index => $post ) {
|
||||||
// FIX: Reblog-Erkennung robuster für Snac
|
// Snac-Verschachtelung auflösen: Wenn ein echtes 'reblog'-Objekt von jemand anderem drinsteckt
|
||||||
if ( !empty($post["reblog"]) || (isset($post["reblogged"]) && $post["reblogged"]===true) ) {
|
if ( !empty($post["reblog"]) && is_array($post["reblog"]) ) {
|
||||||
continue;
|
// 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"] ?? "";
|
$contentHtml = $post["content"] ?? "";
|
||||||
$createdAt = $post["created_at"] ?? "";
|
$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 ( $maxAgeHours > 0 ) {
|
||||||
if ( strtotime($createdAt) < ( time() - ( $maxAgeHours * 3600 ) ) ) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HASHTAG CHECK
|
||||||
$tags = array_column($post["tags"] ?? array(), "name");
|
$tags = array_column($post["tags"] ?? array(), "name");
|
||||||
if ( !empty($hashtag) && !in_array(strtolower($hashtag), array_map("strtolower", $tags)) ) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,8 +151,9 @@ class YellowMastodonapi {
|
||||||
$fileName = date("Y-m-d", strtotime($createdAt)) . "-" . $titleSlug . ".md";
|
$fileName = date("Y-m-d", strtotime($createdAt)) . "-" . $titleSlug . ".md";
|
||||||
$fullPath = $this->yellow->system->get("coreServerDocument") . $targetFolder . $fileName;
|
$fullPath = $this->yellow->system->get("coreServerDocument") . $targetFolder . $fileName;
|
||||||
|
|
||||||
|
// EXISTENZ CHECK
|
||||||
if ( file_exists($fullPath) ) {
|
if ( file_exists($fullPath) ) {
|
||||||
echo "DEBUG: Post übersprungen (Datei existiert bereits: $fileName)\n";
|
echo "DEBUG [$index]: Übersprungen (Datei existiert bereits: $fileName): $shortText\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -168,7 +185,7 @@ class YellowMastodonapi {
|
||||||
|
|
||||||
file_put_contents($fullPath, $markdownContent);
|
file_put_contents($fullPath, $markdownContent);
|
||||||
chmod($fullPath, 0666);
|
chmod($fullPath, 0666);
|
||||||
echo "-> Erstellt: $fileName\n";
|
echo "-> ERSTELLT [$index]: $fileName ($shortText)\n";
|
||||||
$postsCreated++;
|
$postsCreated++;
|
||||||
}
|
}
|
||||||
return $postsCreated;
|
return $postsCreated;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue