mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-05 00:59:35 +00:00
[TelegramBridge] Fix issues & add support for location messages (#2133)
This commit is contained in:
parent
a3b0b91dee
commit
d98add2cac
@ -9,7 +9,7 @@ class TelegramBridge extends BridgeAbstract {
|
||||
'name' => 'Username',
|
||||
'type' => 'text',
|
||||
'required' => true,
|
||||
'exampleValue' => '@telegram',
|
||||
'exampleValue' => '@rssbridge',
|
||||
)
|
||||
)
|
||||
);
|
||||
@ -47,6 +47,7 @@ class TelegramBridge extends BridgeAbstract {
|
||||
$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 @@ class TelegramBridge extends BridgeAbstract {
|
||||
}
|
||||
|
||||
public function getURI() {
|
||||
|
||||
if (!is_null($this->getInput('username'))) {
|
||||
return self::URI . '/s/' . $this->processUsername();
|
||||
}
|
||||
@ -77,7 +77,6 @@ class TelegramBridge extends BridgeAbstract {
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
|
||||
if (!empty($this->feedName)) {
|
||||
return $this->feedName . ' - Telegram';
|
||||
}
|
||||
@ -86,7 +85,6 @@ class TelegramBridge extends BridgeAbstract {
|
||||
}
|
||||
|
||||
private function processUsername() {
|
||||
|
||||
if (substr($this->getInput('username'), 0, 1) === '@') {
|
||||
return substr($this->getInput('username'), 1);
|
||||
}
|
||||
@ -98,6 +96,11 @@ class TelegramBridge extends BridgeAbstract {
|
||||
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 @@ class TelegramBridge extends BridgeAbstract {
|
||||
}
|
||||
|
||||
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 @@ class TelegramBridge extends BridgeAbstract {
|
||||
$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 <<<EOD
|
||||
<blockquote>{$reply->find('span.tgme_widget_message_author_name', 0)->plaintext}<br>
|
||||
{$reply->find('div.tgme_widget_message_text', 0)->innertext}
|
||||
<blockquote>{$author}<br>
|
||||
{$text}
|
||||
<a href="{$reply->href}">{$reply->href}</a></blockquote><hr>
|
||||
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 <<<EOD
|
||||
<a href="{$stickerDiv->children(0)->herf}"><img src="{$sticker[1]}"></a>
|
||||
} elseif (preg_match($this->backgroundImageRegex, $stickerDiv->find('i', 0)->style, $sticker)) {
|
||||
$this->enclosures[] = $sticker[1];
|
||||
|
||||
return <<<EOD
|
||||
<a href="{$stickerDiv->children(0)->herf}"><img src="{$sticker[1]}"></a>
|
||||
EOD;
|
||||
}
|
||||
}
|
||||
|
||||
private function processPoll($messageDiv) {
|
||||
@ -203,7 +222,6 @@ EOD;
|
||||
}
|
||||
|
||||
private function processLinkPreview($messageDiv) {
|
||||
|
||||
$image = '';
|
||||
$title = '';
|
||||
$site = '';
|
||||
@ -235,13 +253,12 @@ EOD;
|
||||
}
|
||||
|
||||
return <<<EOD
|
||||
<blockquote><a href="{$preview->href}">$image</a><br><a href="{$preview->href}">
|
||||
<blockquote><a href="{$preview->href}">{$image}</a><br><a href="{$preview->href}">
|
||||
{$title} - {$site}</a><br>{$description}</blockquote>
|
||||
EOD;
|
||||
}
|
||||
|
||||
private function processVideo($messageDiv) {
|
||||
|
||||
if (empty($this->itemTitle)) {
|
||||
$this->itemTitle = '@' . $this->processUsername() . ' posted a video';
|
||||
}
|
||||
@ -255,14 +272,13 @@ EOD;
|
||||
$this->enclosures[] = $photo[1];
|
||||
|
||||
return <<<EOD
|
||||
<video controls="" poster="{$photo[1]}" preload="none">
|
||||
<video controls="" poster="{$photo[1]}" style="max-width:100%;" preload="none">
|
||||
<source src="{$messageDiv->find('video', 0)->src}" type="video/mp4">
|
||||
</video>
|
||||
EOD;
|
||||
}
|
||||
|
||||
private function processPhoto($messageDiv) {
|
||||
|
||||
if (empty($this->itemTitle)) {
|
||||
$this->itemTitle = '@' . $this->processUsername() . ' posted a photo';
|
||||
}
|
||||
@ -282,7 +298,6 @@ EOD;
|
||||
}
|
||||
|
||||
private function processNotSupported($messageDiv) {
|
||||
|
||||
if (empty($this->itemTitle)) {
|
||||
$this->itemTitle = '@' . $this->processUsername() . ' posted a video';
|
||||
}
|
||||
@ -303,15 +318,40 @@ EOD;
|
||||
EOD;
|
||||
}
|
||||
|
||||
private function processDate($messageDiv) {
|
||||
private function processAttachment($messageDiv) {
|
||||
$attachments = 'File attachments:<br>';
|
||||
|
||||
$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 .= <<<EOD
|
||||
{$document->find('div.tgme_widget_message_document_title', 0)->plaintext} -
|
||||
{$document->find('div.tgme_widget_message_document_extra', 0)->plaintext}<br>
|
||||
EOD;
|
||||
}
|
||||
|
||||
return $attachments;
|
||||
}
|
||||
|
||||
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
|
||||
<a href="{$link}"><img src="{$image[1]}"></a>
|
||||
EOD;
|
||||
}
|
||||
|
||||
private function ellipsisTitle($text) {
|
||||
|
||||
$length = 100;
|
||||
|
||||
if (strlen($text) > $length) {
|
||||
|
Loading…
Reference in New Issue
Block a user