From 069ec223cb821f0f6c5e4ee547bcc8a4bc3b639f Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 26 May 2021 18:37:22 +0100 Subject: [PATCH 01/11] [TelegramBridge] Fix sticker processing --- bridges/TelegramBridge.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index 0004ce0a634..11cad328a30 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -158,20 +158,25 @@ private function processReply($messageDiv) { } private function processSticker($messageDiv) { - if (empty($this->itemTitle)) { $this->itemTitle = '@' . $this->processUsername() . ' posted a sticker'; } $stickerDiv = $messageDiv->find('div.tgme_widget_message_sticker_wrap', 0); - preg_match($this->backgroundImageRegex, $stickerDiv->find('i', 0)->style, $sticker); + if ($stickerDiv->find('picture', 0)) { + $stickerDiv->find('picture', 0)->find('div', 0)->style = ''; + $stickerDiv->find('picture', 0)->style = ''; - $this->enclosures[] = $sticker[1]; + return $stickerDiv; - return << -EOD; + } elseif (preg_match($this->backgroundImageRegex, $stickerDiv->find('i', 0)->style, $sticker)) { + $this->enclosures[] = $sticker[1]; + + return << + EOD; + } } private function processPoll($messageDiv) { From 3d6e1c0c00180dc3eed252f81037e1b91ef3b92b Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 26 May 2021 18:41:20 +0100 Subject: [PATCH 02/11] [TelegramBridge] Format file --- bridges/TelegramBridge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index 11cad328a30..16543552c09 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -175,7 +175,7 @@ private function processSticker($messageDiv) { return << - EOD; +EOD; } } From 9b72d9f87d21fe03c603b928c4dc31899414172f Mon Sep 17 00:00:00 2001 From: Joseph Date: Thu, 27 May 2021 14:29:14 +0100 Subject: [PATCH 03/11] [TelegramBridge] Fix reply processing --- bridges/TelegramBridge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index 16543552c09..5d2f3b5d211 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -152,7 +152,7 @@ private function processReply($messageDiv) { return <<{$reply->find('span.tgme_widget_message_author_name', 0)->plaintext}
-{$reply->find('div.tgme_widget_message_text', 0)->innertext} +{$reply->find('div.tgme_widget_message_metatext', 0)->innertext} {$reply->href}
EOD; } From 4de84a24c46d30ea9efbd96022478138d5064913 Mon Sep 17 00:00:00 2001 From: Joseph Date: Thu, 27 May 2021 14:44:37 +0100 Subject: [PATCH 04/11] [TelegramBridge] Fix attachment processing --- bridges/TelegramBridge.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index 5d2f3b5d211..078b1f98243 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -132,11 +132,9 @@ private function processContent($messageDiv) { $messageDiv->find('div.tgme_widget_message_text.js-message_text', 0)->plaintext ); } + if ($messageDiv->find('div.tgme_widget_message_document', 0)) { - $message .= 'Attachments:'; - foreach ($messageDiv->find('div.tgme_widget_message_document') as $attachments) { - $message .= $attachments->find('div.tgme_widget_message_document_title.accent_color', 0); - } + $message .= $this->processAttachment($messageDiv); } if ($messageDiv->find('a.tgme_widget_message_link_preview', 0)) { @@ -304,6 +302,23 @@ private function processNotSupported($messageDiv) { EOD; } + private function processAttachment($messageDiv) { + $attachments = 'Attachments:'; + + if (empty($this->itemTitle)) { + $this->itemTitle = '@' . $this->processUsername() . ' posted an attachment'; + } + + foreach ($messageDiv->find('div.tgme_widget_message_document') as $document) { + $attachments .= <<{$document->find('div.tgme_widget_message_document_title', 0)->plaintext}
+{$document->find('div.tgme_widget_message_document_extra', 0)->plaintext} +EOD; + } + + return $attachments; + } + private function processDate($messageDiv) { $messageMeta = $messageDiv->find('span.tgme_widget_message_meta', 0); From 92840963f21c0a79bd4b014fc20fe35b6b9f6bc0 Mon Sep 17 00:00:00 2001 From: Joseph Date: Thu, 27 May 2021 14:53:40 +0100 Subject: [PATCH 05/11] [TelegramBridge] Fix reply processing (again) --- bridges/TelegramBridge.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index 078b1f98243..30d4c58e9c0 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -145,12 +145,21 @@ private function processContent($messageDiv) { } private function processReply($messageDiv) { - $reply = $messageDiv->find('a.tgme_widget_message_reply', 0); + $author = $reply->find('span.tgme_widget_message_author_name', 0)->plaintext; + $text = ''; + + if ($reply->find('div.tgme_widget_message_metatext', 0)) { + $text = $reply->find('div.tgme_widget_message_metatext', 0)->innertext; + } + + if ($reply->find('div.tgme_widget_message_text', 0)) { + $text = $reply->find('div.tgme_widget_message_text', 0)->innertext; + } return <<{$reply->find('span.tgme_widget_message_author_name', 0)->plaintext}
-{$reply->find('div.tgme_widget_message_metatext', 0)->innertext} +
{$author}
+{$text} {$reply->href}

EOD; } From b904a1c897fd5165fe9ab3f87611560a95c5d72e Mon Sep 17 00:00:00 2001 From: Joseph Date: Thu, 27 May 2021 14:54:57 +0100 Subject: [PATCH 06/11] [TelegramBridge] Minor change --- bridges/TelegramBridge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index 30d4c58e9c0..e16e25f1e8d 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -102,7 +102,7 @@ private function processContent($messageDiv) { } if ($messageDiv->find('a.tgme_widget_message_reply', 0)) { - $message = $this->processReply($messageDiv); + $message .= $this->processReply($messageDiv); } if ($messageDiv->find('div.tgme_widget_message_sticker_wrap', 0)) { From 6ed9d28f58eda1938c09ab476f4348d73b63d762 Mon Sep 17 00:00:00 2001 From: Joseph Date: Tue, 5 Apr 2022 18:01:26 +0100 Subject: [PATCH 07/11] [TelegramBridge] Minor changes --- bridges/TelegramBridge.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index e16e25f1e8d..9813c4ff09d 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -243,7 +243,7 @@ private function processLinkPreview($messageDiv) { } return <<$image
+
{$image}
{$title} - {$site}
{$description}
EOD; } @@ -263,7 +263,7 @@ private function processVideo($messageDiv) { $this->enclosures[] = $photo[1]; return << + EOD; @@ -332,11 +332,9 @@ private function processDate($messageDiv) { $messageMeta = $messageDiv->find('span.tgme_widget_message_meta', 0); return $messageMeta->find('time', 0)->datetime; - } private function ellipsisTitle($text) { - $length = 100; if (strlen($text) > $length) { From 1befeb22503489fd073c1b12f47a7b4e7ab29de8 Mon Sep 17 00:00:00 2001 From: Joseph Date: Tue, 5 Apr 2022 18:12:40 +0100 Subject: [PATCH 08/11] [TelegramBridge] Change example value to rssbridge --- bridges/TelegramBridge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index 9813c4ff09d..183f91d2dfc 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -9,7 +9,7 @@ class TelegramBridge extends BridgeAbstract { 'name' => 'Username', 'type' => 'text', 'required' => true, - 'exampleValue' => '@telegram', + 'exampleValue' => '@rssbridge', ) ) ); From 9ca6d38cf439af94cc80b3ed81a1b5fa86aee640 Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 6 Apr 2022 01:02:08 +0100 Subject: [PATCH 09/11] [TelegramBridge] Add support for location messages --- bridges/TelegramBridge.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index 183f91d2dfc..df53635fe2e 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -141,6 +141,10 @@ private function processContent($messageDiv) { $message .= $this->processLinkPreview($messageDiv); } + if ($messageDiv->find('a.tgme_widget_message_location_wrap', 0)) { + $message .= $this->processLocation($messageDiv); + } + return $message; } @@ -328,8 +332,23 @@ private function processAttachment($messageDiv) { return $attachments; } - private function processDate($messageDiv) { + private function processLocation($messageDiv) { + if (empty($this->itemTitle)) { + $this->itemTitle = '@' . $this->processUsername() . ' posted a location'; + } + + preg_match($this->backgroundImageRegex, $messageDiv->find('div.tgme_widget_message_location', 0)->style, $image); + + $link = $messageDiv->find('a.tgme_widget_message_location_wrap', 0)->href; + $this->enclosures[] = $image[1]; + + return << +EOD; + } + + private function processDate($messageDiv) { $messageMeta = $messageDiv->find('span.tgme_widget_message_meta', 0); return $messageMeta->find('time', 0)->datetime; } From ea5d90e29f9ec8b6156a046cb3b433c7475c8837 Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 6 Apr 2022 01:15:20 +0100 Subject: [PATCH 10/11] [TelegramBridge] Move processDate() and other minor changes --- bridges/TelegramBridge.php | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index df53635fe2e..e69101d6a41 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -35,14 +35,13 @@ public function detectParameters($url) { } public function collectData() { - - $html = getSimpleHTMLDOM($this->getURI()) - or returnServerError('Could not request: ' . $this->getURI()); + $html = getSimpleHTMLDOM($this->getURI()); $channelTitle = htmlspecialchars_decode( $html->find('div.tgme_channel_info_header_title span', 0)->plaintext, ENT_QUOTES ); + $this->feedName = $channelTitle . ' (@' . $this->processUsername() . ')'; foreach($html->find('div.tgme_widget_message_wrap.js-widget_message_wrap') as $index => $messageDiv) { @@ -64,7 +63,6 @@ public function collectData() { } public function getURI() { - if (!is_null($this->getInput('username'))) { return self::URI . '/s/' . $this->processUsername(); } @@ -73,7 +71,6 @@ public function getURI() { } public function getName() { - if (!empty($this->feedName)) { return $this->feedName . ' - Telegram'; } @@ -82,7 +79,6 @@ public function getName() { } private function processUsername() { - if (substr($this->getInput('username'), 0, 1) === '@') { return substr($this->getInput('username'), 1); } @@ -94,6 +90,11 @@ private function processUri($messageDiv) { return $messageDiv->find('a.tgme_widget_message_date', 0)->href; } + private function processDate($messageDiv) { + $messageMeta = $messageDiv->find('span.tgme_widget_message_meta', 0); + return $messageMeta->find('time', 0)->datetime; + } + private function processContent($messageDiv) { $message = ''; @@ -215,7 +216,6 @@ private function processPoll($messageDiv) { } private function processLinkPreview($messageDiv) { - $image = ''; $title = ''; $site = ''; @@ -253,7 +253,6 @@ private function processLinkPreview($messageDiv) { } private function processVideo($messageDiv) { - if (empty($this->itemTitle)) { $this->itemTitle = '@' . $this->processUsername() . ' posted a video'; } @@ -274,7 +273,6 @@ private function processVideo($messageDiv) { } private function processPhoto($messageDiv) { - if (empty($this->itemTitle)) { $this->itemTitle = '@' . $this->processUsername() . ' posted a photo'; } @@ -294,7 +292,6 @@ private function processPhoto($messageDiv) { } private function processNotSupported($messageDiv) { - if (empty($this->itemTitle)) { $this->itemTitle = '@' . $this->processUsername() . ' posted a video'; } @@ -316,7 +313,7 @@ private function processNotSupported($messageDiv) { } private function processAttachment($messageDiv) { - $attachments = 'Attachments:'; + $attachments = 'File attachments:
'; if (empty($this->itemTitle)) { $this->itemTitle = '@' . $this->processUsername() . ' posted an attachment'; @@ -324,8 +321,8 @@ private function processAttachment($messageDiv) { foreach ($messageDiv->find('div.tgme_widget_message_document') as $document) { $attachments .= <<{$document->find('div.tgme_widget_message_document_title', 0)->plaintext}
-{$document->find('div.tgme_widget_message_document_extra', 0)->plaintext} +{$document->find('div.tgme_widget_message_document_title', 0)->plaintext} - +{$document->find('div.tgme_widget_message_document_extra', 0)->plaintext}
EOD; } @@ -348,11 +345,6 @@ private function processLocation($messageDiv) { EOD; } - private function processDate($messageDiv) { - $messageMeta = $messageDiv->find('span.tgme_widget_message_meta', 0); - return $messageMeta->find('time', 0)->datetime; - } - private function ellipsisTitle($text) { $length = 100; From f2206636254cee9fed9c3c8c9fe406148960a0cd Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 6 Apr 2022 01:16:41 +0100 Subject: [PATCH 11/11] [TelegramBridge] Fix conflict --- bridges/TelegramBridge.php | 1 + 1 file changed, 1 insertion(+) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index e69101d6a41..192c23880a9 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -35,6 +35,7 @@ public function detectParameters($url) { } public function collectData() { + $html = getSimpleHTMLDOM($this->getURI()); $channelTitle = htmlspecialchars_decode(