mastodonapi.php aktualisiert

This commit is contained in:
simonpipe 2025-08-11 17:26:49 +02:00
parent 738d5c9900
commit 81fd7574b5

View file

@ -1,8 +1,8 @@
<?php
// MastodonAPI extension, https://codeberg.org/simonpipe/yellow-mastodonapi
// MastodonAPI extension (public-only), https://codeberg.org/simonpipe/yellow-mastodonapi
class YellowMastodonAPI {
const VERSION = "0.1";
const VERSION = "0.2";
public $yellow;
// Initialisierung
@ -10,7 +10,6 @@ class YellowMastodonAPI {
$this->yellow = $yellow;
$this->yellow->system->setDefault("mastodonapiInstanceUrl", "https://example.social");
$this->yellow->system->setDefault("mastodonapiAccountId", "");
$this->yellow->system->setDefault("mastodonapiAccessToken", "");
$this->yellow->system->setDefault("mastodonapiHashtag", "");
$this->yellow->system->setDefault("mastodonapiAuthor", "YellowUser");
$this->yellow->system->setDefault("mastodonapiTag", "Fediverse");
@ -50,13 +49,12 @@ class YellowMastodonAPI {
private function processMastodonFeed() {
$instanceUrl = $this->yellow->system->get("mastodonapiInstanceUrl");
$accountId = $this->yellow->system->get("mastodonapiAccountId");
$accessToken = $this->yellow->system->get("mastodonapiAccessToken");
$hashtag = ltrim($this->yellow->system->get("mastodonapiHashtag"), '#');
$defaultAuthor = $this->yellow->system->get("mastodonapiAuthor");
$defaultTag = $this->yellow->system->get("mastodonapiTag");
$targetFolder = $this->yellow->system->get("mastodonapiFolder");
if (empty($instanceUrl) || empty($accountId) || empty($accessToken)) {
if (empty($instanceUrl) || empty($accountId)) {
error_log("ERROR: MastodonAPI: Missing configuration values.");
return false;
}
@ -65,8 +63,7 @@ class YellowMastodonAPI {
$context = stream_context_create([
'http' => [
'method' => "GET",
'header' => "Authorization: Bearer " . $accessToken . "\r\n" .
"User-Agent: YellowMastodonAPI\r\n",
'header' => "User-Agent: YellowMastodonAPI\r\n",
'timeout' => 30
],
'ssl' => [
@ -95,7 +92,7 @@ class YellowMastodonAPI {
$createdAt = $post['created_at'];
$tags = array_column($post['tags'], 'name');
if (!empty($hashtag) && !in_array($hashtag, array_map('strtolower', $tags))) {
if (!empty($hashtag) && !in_array(strtolower($hashtag), array_map('strtolower', $tags))) {
continue;
}