This commit is contained in:
Tiger Ren 2025-01-01 21:11:11 +08:00
parent b25c6f6402
commit cd53c164c2
1 changed files with 6 additions and 6 deletions

View File

@ -26,29 +26,29 @@ class TelegramLinkFixerExtension extends Minz_Extension
try { try {
// Check if it's a telegram link // Check if it's a telegram link
$link = $entry->link(); $link = $entry->link();
error_logg('TelegramLinkFixer: Processing entry with link: ' . $link); error_log('TelegramLinkFixer: Processing entry with link: ' . $link);
if (strpos($link, 't.me') === false) { if (strpos($link, 't.me') === false) {
error_logg('TelegramLinkFixer: Skipping - not a telegram link'); error_log('TelegramLinkFixer: Skipping - not a telegram link');
return; // skip if not a telegram link return; // skip if not a telegram link
} }
// The correct method is content() not description() // The correct method is content() not description()
$description = $entry->content(); $description = $entry->content();
if (empty($description)) { if (empty($description)) {
error_logg('TelegramLinkFixer: Skipping - empty content'); error_log('TelegramLinkFixer: Skipping - empty content');
return; return;
} }
if (preg_match('/<a[^>]*?href="(https:\/\/telegra\.ph\/[^"]+)"[^>]*>Telegraph<\/a>/i', $description, $matches)) { if (preg_match('/<a[^>]*?href="(https:\/\/telegra\.ph\/[^"]+)"[^>]*>Telegraph<\/a>/i', $description, $matches)) {
$telegraphLink = $matches[1]; $telegraphLink = $matches[1];
if (!empty($telegraphLink)) { if (!empty($telegraphLink)) {
error_logg('TelegramLinkFixer: Found Telegraph link: ' . $telegraphLink); error_log('TelegramLinkFixer: Found Telegraph link: ' . $telegraphLink);
$entry->setLink($telegraphLink); $entry->setLink($telegraphLink);
error_logg('TelegramLinkFixer: Successfully updated link'); error_log('TelegramLinkFixer: Successfully updated link');
} }
} else { } else {
error_logg('TelegramLinkFixer: No Telegraph link found in content'); error_log('TelegramLinkFixer: No Telegraph link found in content');
} }
} catch (Exception $e) { } catch (Exception $e) {
Minz_Log::error('TelegramLinkFixer: Error processing entry: ' . $e->getMessage()); Minz_Log::error('TelegramLinkFixer: Error processing entry: ' . $e->getMessage());