Update mastodonapi.php
This commit is contained in:
parent
4eaa3edf60
commit
217495cfcd
1 changed files with 14 additions and 4 deletions
|
|
@ -14,9 +14,11 @@ class YellowMastodonAPI {
|
||||||
$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");
|
||||||
$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("mastodonapiTriggerPath", "/mastodonapi-webhook-CHANGE_THIS_SECRET_KEY");
|
||||||
$this->yellow->system->setDefault("mastodonapiLimit", "20");
|
$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) {
|
public function onRequest($scheme, $address, $base, $location, $fileName) {
|
||||||
|
|
@ -54,6 +56,8 @@ 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");
|
||||||
|
$status = $this->yellow->system->get("mastodonapiStatus");
|
||||||
|
$maxAgeHours = intval($this->yellow->system->get("mastodonapiMaxAge"));
|
||||||
$limit = intval($this->yellow->system->get("mastodonapiLimit"));
|
$limit = intval($this->yellow->system->get("mastodonapiLimit"));
|
||||||
|
|
||||||
if (empty($instanceUrl) || empty($accountId)) {
|
if (empty($instanceUrl) || empty($accountId)) {
|
||||||
|
|
@ -98,6 +102,11 @@ class YellowMastodonAPI {
|
||||||
|
|
||||||
$contentHtml = $post['content'] ?? '';
|
$contentHtml = $post['content'] ?? '';
|
||||||
$createdAt = $post['created_at'] ?? '';
|
$createdAt = $post['created_at'] ?? '';
|
||||||
|
if ($maxAgeHours > 0) {
|
||||||
|
$postTimestamp = strtotime($createdAt);
|
||||||
|
$threshold = time() - ($maxAgeHours * 3600);
|
||||||
|
if ($postTimestamp < $threshold) continue;
|
||||||
|
}
|
||||||
$tags = array_column($post['tags'] ?? [], 'name');
|
$tags = array_column($post['tags'] ?? [], 'name');
|
||||||
|
|
||||||
if (!empty($hashtag) && !in_array(strtolower($hashtag), array_map('strtolower', $tags))) {
|
if (!empty($hashtag) && !in_array(strtolower($hashtag), array_map('strtolower', $tags))) {
|
||||||
|
|
@ -139,7 +148,8 @@ class YellowMastodonAPI {
|
||||||
$defaultAuthor,
|
$defaultAuthor,
|
||||||
$defaultTag,
|
$defaultTag,
|
||||||
$imageFilenames,
|
$imageFilenames,
|
||||||
$imageAltTexts
|
$imageAltTexts,
|
||||||
|
$status
|
||||||
);
|
);
|
||||||
|
|
||||||
file_put_contents($fullPath, $markdownContent);
|
file_put_contents($fullPath, $markdownContent);
|
||||||
|
|
@ -207,7 +217,7 @@ class YellowMastodonAPI {
|
||||||
return trim(preg_replace('/[^a-z0-9-]+/', '', $slug), '-');
|
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);
|
$date = new DateTime($dateTime);
|
||||||
$formattedDate = $date->format('Y-m-d');
|
$formattedDate = $date->format('Y-m-d');
|
||||||
$formattedTime = $date->format('H:i:s');
|
$formattedTime = $date->format('H:i:s');
|
||||||
|
|
@ -259,7 +269,7 @@ Published: $formattedDate $formattedTime
|
||||||
Author: $yellowAuthor
|
Author: $yellowAuthor
|
||||||
Layout: blog
|
Layout: blog
|
||||||
Tag: $yellowTag
|
Tag: $yellowTag
|
||||||
Status: draft
|
Status: $status
|
||||||
$featuredImage$featuredImageAlt---
|
$featuredImage$featuredImageAlt---
|
||||||
$imageMarkdown
|
$imageMarkdown
|
||||||
$blockquote
|
$blockquote
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue