diff --git a/extension.php b/extension.php index bcf0f3a..26f2a6e 100644 --- a/extension.php +++ b/extension.php @@ -40,13 +40,19 @@ class TelegramLinkFixerExtension extends Minz_Extension return; } + // First try: Look for Telegraph link with "Telegraph" text if (preg_match('/]*?href="(https:\/\/telegra\.ph\/[^"]+)"[^>]*>Telegraph<\/a>/i', $description, $matches)) { $telegraphLink = $matches[1]; - if (!empty($telegraphLink)) { - error_log('TelegramLinkFixer: Found Telegraph link: ' . $telegraphLink); - $entry->_link($telegraphLink); - error_log('TelegramLinkFixer: Successfully updated link'); - } + } + // Second try: Look for any Telegraph link in the first paragraph + else if (preg_match('/

.*?]*?href="(https:\/\/telegra\.ph\/[^"]+)"[^>]*>/i', $description, $matches)) { + $telegraphLink = $matches[1]; + } + + if (!empty($telegraphLink)) { + error_log('TelegramLinkFixer: Found Telegraph link: ' . $telegraphLink); + $entry->_link($telegraphLink); + error_log('TelegramLinkFixer: Successfully updated link'); } else { error_log('TelegramLinkFixer: No Telegraph link found in content'); }