diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index 86474e5e9f6..65eab5579a6 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', ) ) ); @@ -47,6 +47,7 @@ public function collectData() { $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) { @@ -68,7 +69,6 @@ public function collectData() { } public function getURI() { - if (!is_null($this->getInput('username'))) { return self::URI . '/s/' . $this->processUsername(); } @@ -77,7 +77,6 @@ public function getURI() { } public function getName() { - if (!empty($this->feedName)) { return $this->feedName . ' - Telegram'; } @@ -86,7 +85,6 @@ public function getName() { } private function processUsername() { - if (substr($this->getInput('username'), 0, 1) === '@') { return substr($this->getInput('username'), 1); } @@ -98,6 +96,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 = ''; @@ -106,7 +109,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)) { @@ -136,46 +139,62 @@ 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)) { $message .= $this->processLinkPreview($messageDiv); } + if ($messageDiv->find('a.tgme_widget_message_location_wrap', 0)) { + $message .= $this->processLocation($messageDiv); + } + return $message; } 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_text', 0)->innertext} +
{$author}
+{$text} {$reply->href}

EOD; } 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 << + } elseif (preg_match($this->backgroundImageRegex, $stickerDiv->find('i', 0)->style, $sticker)) { + $this->enclosures[] = $sticker[1]; + + return << EOD; + } } private function processPoll($messageDiv) { @@ -203,7 +222,6 @@ private function processPoll($messageDiv) { } private function processLinkPreview($messageDiv) { - $image = ''; $title = ''; $site = ''; @@ -235,13 +253,12 @@ private function processLinkPreview($messageDiv) { } return <<$image
+
{$image}
{$title} - {$site}
{$description}
EOD; } private function processVideo($messageDiv) { - if (empty($this->itemTitle)) { $this->itemTitle = '@' . $this->processUsername() . ' posted a video'; } @@ -255,14 +272,13 @@ private function processVideo($messageDiv) { $this->enclosures[] = $photo[1]; return << + EOD; } private function processPhoto($messageDiv) { - if (empty($this->itemTitle)) { $this->itemTitle = '@' . $this->processUsername() . ' posted a photo'; } @@ -282,7 +298,6 @@ private function processPhoto($messageDiv) { } private function processNotSupported($messageDiv) { - if (empty($this->itemTitle)) { $this->itemTitle = '@' . $this->processUsername() . ' posted a video'; } @@ -303,15 +318,40 @@ private function processNotSupported($messageDiv) { EOD; } - private function processDate($messageDiv) { + private function processAttachment($messageDiv) { + $attachments = 'File attachments:
'; - $messageMeta = $messageDiv->find('span.tgme_widget_message_meta', 0); - return $messageMeta->find('time', 0)->datetime; + if (empty($this->itemTitle)) { + $this->itemTitle = '@' . $this->processUsername() . ' posted an attachment'; + } + + foreach ($messageDiv->find('div.tgme_widget_message_document') as $document) { + $attachments .= <<find('div.tgme_widget_message_document_title', 0)->plaintext} - +{$document->find('div.tgme_widget_message_document_extra', 0)->plaintext}
+EOD; + } + return $attachments; } - private function ellipsisTitle($text) { + 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 ellipsisTitle($text) { $length = 100; if (strlen($text) > $length) {