mastodonapi.php aktualisiert
This commit is contained in:
parent
a78a5de09e
commit
078c04af51
1 changed files with 31 additions and 16 deletions
|
|
@ -1,21 +1,36 @@
|
||||||
<?php
|
$hashtag = $this->yellow->system->get("mastodonapiHashtag"); // Filter-Hashtag
|
||||||
// MastodonAPI extension, https://codeberg.org/simonpipe/yellow-mastodonapi
|
$tag = $this->yellow->system->get("mastodonapiTag"); // Yellow-Tag
|
||||||
|
|
||||||
class YellowMastodonAPI {
|
foreach ($statuses as $status) {
|
||||||
const VERSION = "0.1";
|
// Nur Posts mit dem gewünschten Hashtag importieren
|
||||||
|
if (!empty($hashtag) && stripos($status["content"], "#$hashtag") === false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
public $yellow;
|
$content = strip_tags($status["content"]);
|
||||||
|
$createdAt = $status["created_at"];
|
||||||
|
$title = mb_substr(preg_replace("/\\s+/", " ", $content), 0, 50);
|
||||||
|
$slug = strtolower(preg_replace("/[^a-z0-9]+/", "-", $title));
|
||||||
|
$datePrefix = date("Y-m-d", strtotime($createdAt));
|
||||||
|
$fileName = "$datePrefix-$slug.md";
|
||||||
|
$path = $this->yellow->system->get("coreServerDocument") . $folder . $fileName;
|
||||||
|
|
||||||
// Handle initialisation
|
if (file_exists($path)) continue;
|
||||||
public function onLoad($yellow) {
|
|
||||||
$this->yellow = $yellow;
|
$markdown = <<<MARKDOWN
|
||||||
$this->yellow->system->setDefault("mastodonapiInstanceUrl", "https://mastodon.social"); // Deine Mastodon Instanz-URL
|
---
|
||||||
$this->yellow->system->setDefault("mastodonapiUserId", ""); // Deine Mastodon User ID (numerisch, z.B. 1234567890)
|
Title: $title
|
||||||
$this->yellow->system->setDefault("mastodonapiAccessToken", ""); // Optional: Dein persönlicher API-Token (read:statuses)
|
TitleSlug: $slug
|
||||||
$this->yellow->system->setDefault("mastodonapiHashtag", "");
|
Published: $createdAt
|
||||||
$this->yellow->system->setDefault("mastodonapiAuthor", "YellowUser");
|
Author: $author
|
||||||
$this->yellow->system->setDefault("mastodonapiTag", "Fediverse");
|
Layout: blog
|
||||||
$this->yellow->system->setDefault("mastodonapiFolder", "content/1-blog/");
|
Tag: $tag
|
||||||
$this->yellow->system->setDefault("mastodonapiTriggerPath", "/mastodonapi-webhook-CHANGE_THIS_SECRET_KEY");
|
---
|
||||||
|
> "$content"
|
||||||
|
> — [@{$status["account"]["acct"]}]({$status["account"]["url"]})
|
||||||
|
MARKDOWN;
|
||||||
|
|
||||||
|
if (file_put_contents($path, $markdown) !== false) {
|
||||||
|
$postsCreated++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue