mastodonapi.php aktualisiert
This commit is contained in:
parent
6b0abd568a
commit
6e6c2cf102
1 changed files with 29 additions and 7 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.2";
|
const VERSION = "0.5.1";
|
||||||
public $yellow;
|
public $yellow;
|
||||||
|
|
||||||
// Initialisierung
|
// Initialisierung
|
||||||
|
|
@ -16,6 +16,7 @@ class YellowMastodonAPI {
|
||||||
$this->yellow->system->setDefault("mastodonapiTag", "Fediverse");
|
$this->yellow->system->setDefault("mastodonapiTag", "Fediverse");
|
||||||
$this->yellow->system->setDefault("mastodonapiFolder", "content/1-blog/");
|
$this->yellow->system->setDefault("mastodonapiFolder", "content/1-blog/");
|
||||||
$this->yellow->system->setDefault("mastodonapiTriggerPath", "/mastodonapi-webhook-CHANGE_THIS_SECRET_KEY");
|
$this->yellow->system->setDefault("mastodonapiTriggerPath", "/mastodonapi-webhook-CHANGE_THIS_SECRET_KEY");
|
||||||
|
$this->yellow->system->setDefault("mastodonapiLimit", "20"); // neu: Anzahl Posts
|
||||||
}
|
}
|
||||||
|
|
||||||
// Webhook-Request
|
// Webhook-Request
|
||||||
|
|
@ -55,24 +56,26 @@ class YellowMastodonAPI {
|
||||||
$defaultAuthor = $this->yellow->system->get("mastodonapiAuthor");
|
$defaultAuthor = $this->yellow->system->get("mastodonapiAuthor");
|
||||||
$defaultTag = $this->yellow->system->get("mastodonapiTag");
|
$defaultTag = $this->yellow->system->get("mastodonapiTag");
|
||||||
$targetFolder = $this->yellow->system->get("mastodonapiFolder");
|
$targetFolder = $this->yellow->system->get("mastodonapiFolder");
|
||||||
|
$limit = intval($this->yellow->system->get("mastodonapiLimit"));
|
||||||
|
|
||||||
if (empty($instanceUrl) || empty($accountId)) {
|
if (empty($instanceUrl) || empty($accountId)) {
|
||||||
error_log("ERROR: MastodonAPI: Missing configuration values.");
|
error_log("ERROR: MastodonAPI: Missing configuration values.");
|
||||||
return false;
|
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 = [
|
||||||
$headers = "User-Agent: YellowMastodonAPI\r\n";
|
"User-Agent: YellowMastodonAPI"
|
||||||
|
];
|
||||||
if (!empty($accessToken)) {
|
if (!empty($accessToken)) {
|
||||||
$headers .= "Authorization: Bearer " . $accessToken . "\r\n";
|
$headers[] = "Authorization: Bearer " . $accessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
$context = stream_context_create([
|
$context = stream_context_create([
|
||||||
'http' => [
|
'http' => [
|
||||||
'method' => "GET",
|
'method' => "GET",
|
||||||
'header' => $headers,
|
'header' => implode("\r\n", $headers) . "\r\n",
|
||||||
'timeout' => 30
|
'timeout' => 30
|
||||||
],
|
],
|
||||||
'ssl' => [
|
'ssl' => [
|
||||||
|
|
@ -82,6 +85,16 @@ class YellowMastodonAPI {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$json = @file_get_contents($apiUrl, false, $context);
|
$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) {
|
if ($json === false) {
|
||||||
error_log("ERROR: MastodonAPI: Could not fetch API data from $apiUrl");
|
error_log("ERROR: MastodonAPI: Could not fetch API data from $apiUrl");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -97,6 +110,15 @@ class YellowMastodonAPI {
|
||||||
$postsCreated = 0;
|
$postsCreated = 0;
|
||||||
|
|
||||||
foreach ($posts as $post) {
|
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'];
|
$contentHtml = $post['content'];
|
||||||
$createdAt = $post['created_at'];
|
$createdAt = $post['created_at'];
|
||||||
$tags = array_column($post['tags'], 'name');
|
$tags = array_column($post['tags'], 'name');
|
||||||
|
|
@ -228,4 +250,4 @@ MD;
|
||||||
echo "<h1>" . htmlspecialchars($message) . "</h1>";
|
echo "<h1>" . htmlspecialchars($message) . "</h1>";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue