Update mastodonapi.php
This commit is contained in:
parent
baaa18d817
commit
1e461693ef
1 changed files with 35 additions and 9 deletions
|
|
@ -80,7 +80,6 @@ class YellowMastodonapi {
|
|||
|
||||
$apiUrl = rtrim($instanceUrl, "/") . "/api/v1/accounts/" . $accountId . "/statuses?limit=" . $limit;
|
||||
|
||||
// FIX: Browser-ähnlicher User-Agent, da Snac strikt blockiert
|
||||
$headers = array("User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) YellowMastodonapi/" . self::VERSION);
|
||||
if ( !empty($accessToken) ) $headers[] = "Authorization: Bearer " . $accessToken;
|
||||
|
||||
|
|
@ -90,7 +89,7 @@ class YellowMastodonapi {
|
|||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_HTTPHEADER => $headers,
|
||||
CURLOPT_SSL_VERIFYPEER => false, // FIX: Kompatibilität für GoToSocial/Snac erhöht
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_SSL_VERIFYHOST => 0
|
||||
));
|
||||
$json = curl_exec($ch);
|
||||
|
|
@ -101,23 +100,45 @@ class YellowMastodonapi {
|
|||
$posts = json_decode($json, true);
|
||||
if ( !is_array($posts) ) return false;
|
||||
|
||||
echo "DEBUG: " . count($posts) . " Posts von API empfangen.\n";
|
||||
|
||||
$postsCreated = 0;
|
||||
foreach ( $posts as $post ) {
|
||||
if ( !empty($post["reblog"]) || ( !empty($post["reblogged"]) && $post["reblogged"]===true ) ) continue;
|
||||
if ( !is_null($post["in_reply_to_id"]) ) continue;
|
||||
// FIX: Reblog-Erkennung robuster für Snac
|
||||
if ( !empty($post["reblog"]) || (isset($post["reblogged"]) && $post["reblogged"]===true) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 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"] ?? "";
|
||||
|
||||
if ( $maxAgeHours > 0 ) {
|
||||
if ( strtotime($createdAt) < ( time() - ( $maxAgeHours * 3600 ) ) ) continue;
|
||||
if ( strtotime($createdAt) < ( time() - ( $maxAgeHours * 3600 ) ) ) {
|
||||
echo "DEBUG: Post übersprungen (zu alt): " . mb_substr(strip_tags($contentHtml), 0, 30) . "...\n";
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$tags = array_column($post["tags"] ?? array(), "name");
|
||||
if ( !empty($hashtag) && !in_array(strtolower($hashtag), array_map("strtolower", $tags)) ) continue;
|
||||
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";
|
||||
continue;
|
||||
}
|
||||
|
||||
$title = $this->generateTitle($contentHtml);
|
||||
$titleSlug = $this->generateTitleSlug($title);
|
||||
$fileName = date("Y-m-d", strtotime($createdAt)) . "-" . $titleSlug . ".md";
|
||||
$fullPath = $this->yellow->system->get("coreServerDocument") . $targetFolder . $fileName;
|
||||
if ( file_exists($fullPath) ) continue;
|
||||
|
||||
if ( file_exists($fullPath) ) {
|
||||
echo "DEBUG: Post übersprungen (Datei existiert bereits: $fileName)\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( !is_dir(dirname($fullPath)) ) {
|
||||
mkdir(dirname($fullPath), 0777, true);
|
||||
|
|
@ -135,14 +156,19 @@ class YellowMastodonapi {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
$authorName = !empty($post["account"]["display_name"]) ? $post["account"]["display_name"] : $defaultAuthor;
|
||||
$authorUrl = !empty($post["account"]["url"]) ? $post["account"]["url"] : "#";
|
||||
|
||||
$markdownContent = $this->generateMarkdown(
|
||||
$title, $titleSlug, $createdAt, $contentHtml,
|
||||
$post["account"]["display_name"] ?: $defaultAuthor,
|
||||
$post["account"]["url"] ?: "#",
|
||||
$authorName, $authorUrl,
|
||||
$defaultAuthor, $defaultTag, $imageFilenames, $imageAltTexts, $statusSetting
|
||||
);
|
||||
|
||||
file_put_contents($fullPath, $markdownContent);
|
||||
chmod($fullPath, 0666);
|
||||
echo "-> Erstellt: $fileName\n";
|
||||
$postsCreated++;
|
||||
}
|
||||
return $postsCreated;
|
||||
|
|
|
|||
Loading…
Reference in a new issue