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
|
||||
// MastodonAPI extension, https://codeberg.org/simonpipe/yellow-mastodonapi
|
||||
$hashtag = $this->yellow->system->get("mastodonapiHashtag"); // Filter-Hashtag
|
||||
$tag = $this->yellow->system->get("mastodonapiTag"); // Yellow-Tag
|
||||
|
||||
class YellowMastodonAPI {
|
||||
const VERSION = "0.1";
|
||||
foreach ($statuses as $status) {
|
||||
// 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
|
||||
public function onLoad($yellow) {
|
||||
$this->yellow = $yellow;
|
||||
$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)
|
||||
$this->yellow->system->setDefault("mastodonapiAccessToken", ""); // Optional: Dein persönlicher API-Token (read:statuses)
|
||||
$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("mastodonapiTriggerPath", "/mastodonapi-webhook-CHANGE_THIS_SECRET_KEY");
|
||||
if (file_exists($path)) continue;
|
||||
|
||||
$markdown = <<<MARKDOWN
|
||||
---
|
||||
Title: $title
|
||||
TitleSlug: $slug
|
||||
Published: $createdAt
|
||||
Author: $author
|
||||
Layout: blog
|
||||
Tag: $tag
|
||||
---
|
||||
> "$content"
|
||||
> — [@{$status["account"]["acct"]}]({$status["account"]["url"]})
|
||||
MARKDOWN;
|
||||
|
||||
if (file_put_contents($path, $markdown) !== false) {
|
||||
$postsCreated++;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue