Compare commits

...

10 commits

Author SHA1 Message Date
simonpipe
7825565b3d url 2026-05-29 09:41:46 +02:00
simonpipe
519a4ba9b0 Formating 2026-05-28 11:33:09 +02:00
simonpipe
cbb190d51e Add URL 2026-05-28 11:29:54 +02:00
simonpipe
c31766341a Add Fediverse contact 2026-05-28 11:25:59 +02:00
simonpipe
b7507290b6 Add Fediverse Contact 2026-05-28 11:24:47 +02:00
simonpipe
adb5b28713 Update .gitattributes 2026-05-28 08:18:02 +02:00
simonpipe
c395abeef3 Update readme.md 2026-05-27 14:21:14 +02:00
simonpipe
adfa390b9d Update readme-de.md 2026-05-27 14:20:52 +02:00
simonpipe
ea065984d8 Update extension.ini 2026-05-27 14:20:31 +02:00
simonpipe
6996fd4ac6 Update mastodonapi.php 2026-05-27 14:20:04 +02:00
7 changed files with 46 additions and 27 deletions

2
.gitattributes vendored
View file

@ -1,6 +1,6 @@
.gitattributes export-ignore
LICENSE export-ignore
help-gotoso*.md export-ignore
help*.md export-ignore
readme*.md export-ignore
# Auto detect text files and perform LF normalization
* text=auto

View file

@ -1,14 +1,14 @@
# Datenstrom Yellow extension settings
Extension: Mastodonapi
Version: 0.9.7
Version: 0.9.8
Description: Import your toots into your blog.
Developer: Simon Rohr
Tag: feature
DownloadUrl: https://codeberg.org/simonpipe/yellow-mastodonapi/archive/main.zip
DocumentationUrl: https://codeberg.org/simonpipe/yellow-mastodonapi
DocumentationLanguage: en, de
Published: 2026-05-27 08:35:00
Published: 2026-05-27 14:20:00
Status: experimental
system/workers/mastodonapi.php: mastodonapi.php, create, update
system/workers/mastodonapi.status: mastodonapi.status, create, update, careful

View file

@ -6,7 +6,7 @@
1. Ersetze in diesem Link die Platzhalter und öffne ihn im Browser:
```
https://snac.thepipes.ch/oauth/x-snac-get-token
https://DEINE_INSTANZ_URL/oauth/x-snac-get-token
```
→ Anmelden, bestätigen und den **Code** kopieren.

View file

@ -6,7 +6,7 @@
1. Adjust the following link and paste it into your browser:
```
https://snac.thepipes.ch/oauth/x-snac-get-token
https://YOUR_INSTANCE_URL/oauth/x-snac-get-token
```
→ Log in, authorize, and copy the **code**.

View file

@ -2,7 +2,7 @@
// Mastodonapi extension, https://codeberg.org/simonpipe/yellow-mastodonapi
class YellowMastodonapi {
const VERSION = "0.9.7";
const VERSION = "0.9.8";
public $yellow; // access to API
// Initialize extension
@ -103,30 +103,46 @@ class YellowMastodonapi {
echo "DEBUG: " . count($posts) . " Posts von API empfangen.\n";
$postsCreated = 0;
foreach ( $posts as $post ) {
// FIX: Reblog-Erkennung robuster für Snac
if ( !empty($post["reblog"]) || (isset($post["reblogged"]) && $post["reblogged"]===true) ) {
continue;
}
// FIX: Snac sendet leere Strings "" statt null bei in_reply_to_id
if ( !empty($post["in_reply_to_id"]) ) {
continue;
foreach ( $posts as $index => $post ) {
// Snac-Verschachtelung auflösen: Wenn ein echtes 'reblog'-Objekt von jemand anderem drinsteckt
if ( !empty($post["reblog"]) && is_array($post["reblog"]) ) {
// Nur überspringen, wenn es wirklich der Post eines ANDEREN Nutzers ist, den du geteilt hast
if ( !empty($post["reblog"]["account"]["id"]) && $post["reblog"]["account"]["id"] != $accountId ) {
echo "DEBUG [$index]: Übersprungen (Echter Reblog eines fremden Beitrags)\n";
continue;
}
// Wenn es dein eigener ist, nutzen wir die inneren Daten
$post = $post["reblog"];
}
$contentHtml = $post["content"] ?? "";
$createdAt = $post["created_at"] ?? "";
$shortText = mb_substr(strip_tags($contentHtml), 0, 40) . "...";
// Reblogged-Flag nur werten, wenn es kein Eigen-Boost ist
if ( (isset($post["reblogged"]) && $post["reblogged"]===true) && empty($contentHtml) ) {
echo "DEBUG [$index]: Übersprungen (Leerer Boost): $shortText\n";
continue;
}
// REPLY CHECK (Snac sendet leere Strings oder null)
if ( !empty($post["in_reply_to_id"]) ) {
echo "DEBUG [$index]: Übersprungen (Antwort - Reply-ID: " . $post["in_reply_to_id"] . "): $shortText\n";
continue;
}
// ALTER CHECK
if ( $maxAgeHours > 0 ) {
if ( strtotime($createdAt) < ( time() - ( $maxAgeHours * 3600 ) ) ) {
echo "DEBUG: Post übersprungen (zu alt): " . mb_substr(strip_tags($contentHtml), 0, 30) . "...\n";
echo "DEBUG [$index]: Übersprungen (Zu alt - Datum: $createdAt): $shortText\n";
continue;
}
}
// HASHTAG CHECK
$tags = array_column($post["tags"] ?? array(), "name");
if ( !empty($hashtag) && !in_array(strtolower($hashtag), array_map("strtolower", $tags)) ) {
echo "DEBUG: Post übersprungen (Hashtag #$hashtag fehlt): " . mb_substr(strip_tags($contentHtml), 0, 30) . "...\n";
echo "DEBUG [$index]: Übersprungen (Hashtag #$hashtag fehlt): $shortText\n";
continue;
}
@ -135,8 +151,9 @@ class YellowMastodonapi {
$fileName = date("Y-m-d", strtotime($createdAt)) . "-" . $titleSlug . ".md";
$fullPath = $this->yellow->system->get("coreServerDocument") . $targetFolder . $fileName;
// EXISTENZ CHECK
if ( file_exists($fullPath) ) {
echo "DEBUG: Post übersprungen (Datei existiert bereits: $fileName)\n";
echo "DEBUG [$index]: Übersprungen (Datei existiert bereits: $fileName): $shortText\n";
continue;
}
@ -168,7 +185,7 @@ class YellowMastodonapi {
file_put_contents($fullPath, $markdownContent);
chmod($fullPath, 0666);
echo "-> Erstellt: $fileName\n";
echo "-> ERSTELLT [$index]: $fileName ($shortText)\n";
$postsCreated++;
}
return $postsCreated;

View file

@ -1,6 +1,6 @@
<p align="right"><a href="https://codeberg.org/simonpipe/yellow-mastodonapi/src/branch/main/readme-de.md">Deutsch</a> &nbsp; <a href="https://codeberg.org/simonpipe/yellow-mastodonapi/src/branch/main/readme.md">English</a></p>
# Mastodonapi 0.9.7
# Mastodonapi 0.9.8
Importiere deine Toots in deinen Blog. Getestet mit <a href="https://comam.es/what-is-snac">Snac</a>.
@ -30,7 +30,7 @@ Alle Einstellungen befinden sich in `system/extensions/yellow-system.ini`:
*Finde die ID eines Snac oder Mastodon Accounts: Gib "https://DEINE_INSTANZ_URL/api/v1/accounts/lookup?acct=PROFILNAME" in deinen Browser ein.*
*Finde die ID eines GoToSocial-Accounts <a href="https://codeberg.org/simonpipe/yellow-mastodonapi/src/branch/main/help-de.md">(siehe hier)</a>*
`MastodonapiAccessToken` = optional für einen Mastodon-Account, zwingend für einen GoToSocial-Account <a href="https://codeberg.org/simonpipe/yellow-mastodonapi/src/branch/main/help-de.md">(siehe hier)</a>
`MastodonapiAccessToken` = optional für einen Mastodon-Account, zwingend für einen GoToSocial-Account <a href="https://codeberg.org/simonpipe/yellow-mastodonapi/src/branch/main/help-de.md">(Wie komme ich zu einem Token?)</a>
`MastodonapiUpdateInterval` = Zeitintervall zwischen automatischen Updates in Minuten (Standard: 30)
`MastodonapiLimit` = Anzahl der Toots, die pro Durchgang abgerufen werden (Standard: 20)
`MastodonapiHashtag` = leer lassen für alle Beiträge; oder mit #hashtag filtern
@ -49,3 +49,4 @@ Die folgenden Status-Werte werden unterstützt:
## Entwickler
Simon Rohr
*Fediverse: <a href="https://snac.thepipes.ch/simon">@simon@snac.thepipes.ch</a>*

View file

@ -1,6 +1,6 @@
<p align="right"><a href="https://codeberg.org/simonpipe/yellow-mastodonapi/src/branch/main/readme-de.md">Deutsch</a> &nbsp; <a href="https://codeberg.org/simonpipe/yellow-mastodonapi/src/branch/main/readme.md">English</a></p>
# Mastodonapi 0.9.7
# Mastodonapi 0.9.8
Import your toots into your blog. Tested with <a href="https://comam.es/what-is-snac">Snac</a>.
@ -30,7 +30,7 @@ All settings are in `system/extensions/yellow-system.ini`:
*Find the ID of a Snac or Mastodon account: Enter "https://YOUR_INSTANCE_URL/api/v1/accounts/lookup?acct=PROFILNAME" in your browser.*
*Find the ID of a GoToSocial account <a href="https://codeberg.org/simonpipe/yellow-mastodonapi/src/branch/main/help-en.md">(see here)</a>*
`MastodonapiAccessToken` = optional for a Mastodon account, mandatory for a GoToSocial account <a href="https://codeberg.org/simonpipe/yellow-mastodonapi/src/branch/main/help-en.md">(see here)</a>
`MastodonapiAccessToken` = optional for a Mastodon account, mandatory for a GoToSocial account <a href="https://codeberg.org/simonpipe/yellow-mastodonapi/src/branch/main/help-en.md">(How do I get a token?)</a>
`MastodonapiUpdateInterval` = time interval between automatic updates in minutes (default: 30)
`MastodonapiLimit` = number of Toots retrieved per run (default: 20)
`MastodonapiHashtag` = leave blank for all posts; or filter with #hashtag
@ -49,3 +49,4 @@ The following status values are supported:
## Developer
Simon Rohr
*Fediverse: <a href="https://snac.thepipes.ch/simon">@simon@snac.thepipes.ch</a>*