From d64462b0082b77373852785eb97a396a584c9165 Mon Sep 17 00:00:00 2001 From: Tiger Ren Date: Wed, 1 Jan 2025 20:31:43 +0800 Subject: [PATCH] Init FreshRSS extension --- extension.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ metadata.json | 8 ++++++++ 2 files changed, 53 insertions(+) create mode 100644 extension.php create mode 100644 metadata.json diff --git a/extension.php b/extension.php new file mode 100644 index 0000000..3808575 --- /dev/null +++ b/extension.php @@ -0,0 +1,45 @@ + from the feed with one extracted from . + * Author: Your Name + * Version: 1.0 + */ + +class TelegramLinkFixerExtension extends Minz_Extension +{ + /** + * Called automatically at extension load-time. Set up hooks here. + */ + public function init() + { + // Hook into FreshRSS just before each entry is saved to database: + $this->registerHook('entry_before_insert', array($this, 'fixLink')); + } + + /** + * Our main function to rewrite the from . + */ + public static function fixLink($entry) + { + // Check if it's a telegram link + $link = $entry->link(); + if (strpos($link, 't.me') === false) { + return; // skip if not a telegram link + } + + $description = $entry->description(); + if (empty($description)) { + return; + } + + // Look specifically for Telegraph links + if (preg_match('/]*?href="(https:\/\/telegra\.ph\/[^"]+)"[^>]*>Telegraph<\/a>/i', $description, $matches)) { + $telegraphLink = $matches[1]; + if (!empty($telegraphLink)) { + $entry->_link($telegraphLink); + } + } + } +} diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..17e3271 --- /dev/null +++ b/metadata.json @@ -0,0 +1,8 @@ +{ + "name": "Telegram Channel Feed Link Fixer", + "author": "Tiger Ren", + "description": "Extract telegraph link from telegram channel feed and replace it with the original link.", + "version": "0.01", + "entrypoint": "TelegramLinkFixer", + "type": "user" +} \ No newline at end of file