Update mastodonapi.php

This commit is contained in:
simonpipe 2026-01-01 15:28:52 +01:00
parent 4eaa3edf60
commit 217495cfcd

View file

@ -14,9 +14,11 @@ class YellowMastodonAPI {
$this->yellow->system->setDefault("mastodonapiHashtag", "");
$this->yellow->system->setDefault("mastodonapiAuthor", "YellowUser");
$this->yellow->system->setDefault("mastodonapiTag", "Fediverse");
$this->yellow->system->setDefault("mastodonapiFolder", "content/1-blog/");
$this->yellow->system->setDefault("mastodonapiFolder", "content/2-blog/");
$this->yellow->system->setDefault("mastodonapiTriggerPath", "/mastodonapi-webhook-CHANGE_THIS_SECRET_KEY");
$this->yellow->system->setDefault("mastodonapiLimit", "20");
$this->yellow->system->setDefault("mastodonapiStatus", "public"); // public; draft = page is not visible, user needs to log in, requires draft extension; unlisted = page is not visible, but can be accessed with the correct link
$this->yellow->system->setDefault("mastodonapiMaxAge", "0"); // In Stunden. 0 = alle Toots.
}
public function onRequest($scheme, $address, $base, $location, $fileName) {
@ -54,6 +56,8 @@ class YellowMastodonAPI {
$defaultAuthor = $this->yellow->system->get("mastodonapiAuthor");
$defaultTag = $this->yellow->system->get("mastodonapiTag");
$targetFolder = $this->yellow->system->get("mastodonapiFolder");
$status = $this->yellow->system->get("mastodonapiStatus");
$maxAgeHours = intval($this->yellow->system->get("mastodonapiMaxAge"));
$limit = intval($this->yellow->system->get("mastodonapiLimit"));
if (empty($instanceUrl) || empty($accountId)) {
@ -98,6 +102,11 @@ class YellowMastodonAPI {
$contentHtml = $post['content'] ?? '';
$createdAt = $post['created_at'] ?? '';
if ($maxAgeHours > 0) {
$postTimestamp = strtotime($createdAt);
$threshold = time() - ($maxAgeHours * 3600);
if ($postTimestamp < $threshold) continue;
}
$tags = array_column($post['tags'] ?? [], 'name');
if (!empty($hashtag) && !in_array(strtolower($hashtag), array_map('strtolower', $tags))) {
@ -139,7 +148,8 @@ class YellowMastodonAPI {
$defaultAuthor,
$defaultTag,
$imageFilenames,
$imageAltTexts
$imageAltTexts,
$status
);
file_put_contents($fullPath, $markdownContent);
@ -207,7 +217,7 @@ class YellowMastodonAPI {
return trim(preg_replace('/[^a-z0-9-]+/', '', $slug), '-');
}
private function generateMarkdown($title, $slug, $dateTime, $html, $origAuthor, $origUrl, $yellowAuthor, $yellowTag, $images = [], $alts = []) {
private function generateMarkdown($title, $slug, $dateTime, $html, $origAuthor, $origUrl, $yellowAuthor, $yellowTag, $images = [], $alts = [], $status = "public") {
$date = new DateTime($dateTime);
$formattedDate = $date->format('Y-m-d');
$formattedTime = $date->format('H:i:s');
@ -259,7 +269,7 @@ Published: $formattedDate $formattedTime
Author: $yellowAuthor
Layout: blog
Tag: $yellowTag
Status: draft
Status: $status
$featuredImage$featuredImageAlt---
$imageMarkdown
$blockquote