mastodonapi.php aktualisiert
This commit is contained in:
parent
738d5c9900
commit
81fd7574b5
1 changed files with 5 additions and 8 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
// MastodonAPI extension, https://codeberg.org/simonpipe/yellow-mastodonapi
|
// MastodonAPI extension (public-only), https://codeberg.org/simonpipe/yellow-mastodonapi
|
||||||
|
|
||||||
class YellowMastodonAPI {
|
class YellowMastodonAPI {
|
||||||
const VERSION = "0.1";
|
const VERSION = "0.2";
|
||||||
public $yellow;
|
public $yellow;
|
||||||
|
|
||||||
// Initialisierung
|
// Initialisierung
|
||||||
|
|
@ -10,7 +10,6 @@ class YellowMastodonAPI {
|
||||||
$this->yellow = $yellow;
|
$this->yellow = $yellow;
|
||||||
$this->yellow->system->setDefault("mastodonapiInstanceUrl", "https://example.social");
|
$this->yellow->system->setDefault("mastodonapiInstanceUrl", "https://example.social");
|
||||||
$this->yellow->system->setDefault("mastodonapiAccountId", "");
|
$this->yellow->system->setDefault("mastodonapiAccountId", "");
|
||||||
$this->yellow->system->setDefault("mastodonapiAccessToken", "");
|
|
||||||
$this->yellow->system->setDefault("mastodonapiHashtag", "");
|
$this->yellow->system->setDefault("mastodonapiHashtag", "");
|
||||||
$this->yellow->system->setDefault("mastodonapiAuthor", "YellowUser");
|
$this->yellow->system->setDefault("mastodonapiAuthor", "YellowUser");
|
||||||
$this->yellow->system->setDefault("mastodonapiTag", "Fediverse");
|
$this->yellow->system->setDefault("mastodonapiTag", "Fediverse");
|
||||||
|
|
@ -50,13 +49,12 @@ class YellowMastodonAPI {
|
||||||
private function processMastodonFeed() {
|
private function processMastodonFeed() {
|
||||||
$instanceUrl = $this->yellow->system->get("mastodonapiInstanceUrl");
|
$instanceUrl = $this->yellow->system->get("mastodonapiInstanceUrl");
|
||||||
$accountId = $this->yellow->system->get("mastodonapiAccountId");
|
$accountId = $this->yellow->system->get("mastodonapiAccountId");
|
||||||
$accessToken = $this->yellow->system->get("mastodonapiAccessToken");
|
|
||||||
$hashtag = ltrim($this->yellow->system->get("mastodonapiHashtag"), '#');
|
$hashtag = ltrim($this->yellow->system->get("mastodonapiHashtag"), '#');
|
||||||
$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");
|
||||||
|
|
||||||
if (empty($instanceUrl) || empty($accountId) || empty($accessToken)) {
|
if (empty($instanceUrl) || empty($accountId)) {
|
||||||
error_log("ERROR: MastodonAPI: Missing configuration values.");
|
error_log("ERROR: MastodonAPI: Missing configuration values.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -65,8 +63,7 @@ class YellowMastodonAPI {
|
||||||
$context = stream_context_create([
|
$context = stream_context_create([
|
||||||
'http' => [
|
'http' => [
|
||||||
'method' => "GET",
|
'method' => "GET",
|
||||||
'header' => "Authorization: Bearer " . $accessToken . "\r\n" .
|
'header' => "User-Agent: YellowMastodonAPI\r\n",
|
||||||
"User-Agent: YellowMastodonAPI\r\n",
|
|
||||||
'timeout' => 30
|
'timeout' => 30
|
||||||
],
|
],
|
||||||
'ssl' => [
|
'ssl' => [
|
||||||
|
|
@ -95,7 +92,7 @@ class YellowMastodonAPI {
|
||||||
$createdAt = $post['created_at'];
|
$createdAt = $post['created_at'];
|
||||||
$tags = array_column($post['tags'], 'name');
|
$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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue