From fe65b263b223c1e05742118c3245c25236169256 Mon Sep 17 00:00:00 2001 From: Joseph Date: Tue, 18 Jun 2019 13:29:38 +0100 Subject: [PATCH 01/16] Create TelegramBridge.php --- bridges/TelegramBridge.php | 157 +++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 bridges/TelegramBridge.php diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php new file mode 100644 index 00000000000..95efbe19401 --- /dev/null +++ b/bridges/TelegramBridge.php @@ -0,0 +1,157 @@ + array( + 'name' => 'Username', + 'type' => 'text', + 'exampleValue' => '@telegram', + ) + ) + ); + + const CACHE_TIMEOUT = 600; // 15 mins + + private $backgroundImageRegex = "/background-image:url\('(.*)'\)/"; + + public function collectData() { + + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError('Could not request: ' . $this->getURI()); + + foreach($html->find('div.tgme_widget_message_wrap.js-widget_message_wrap') as $index => $messageDiv) { + $item = array(); + + $item['uri'] = $this->processUri($messageDiv); + //$item['title'] + $item['content'] = $this->processContent($messageDiv); + $item['timestamp'] = $this->processDate($messageDiv); + //$item['enclosures'][]; + + $this->items[] = $item; + } + } + + public function getURI() { + + if (!is_null($this->getInput('username'))) { + return self::URI . '/s/' . $this->processUsername(); + } + + return parent::getURI(); + } + + /*public function getName() { + + if (!is_null($this->getInput('edition')) && !is_null($this->getInput('category'))) { + $parameters = $this->getParameters(); + + $editionValues = array_flip($parameters[0]['edition']['values']); + $categoryValues = array_flip($parameters[0]['category']['values']); + + return $categoryValues[$this->getInput('category')] . ' - ' . + $editionValues[$this->getInput('edition')] . ' - Brut.'; + } + + return parent::getName(); + }*/ + + private function processUsername() { + + if (substr($this->getInput('username'), 0, 1) === '@') { + return substr($this->getInput('username'), 1); + } + + return $this->getInput('username'); + } + + private function processUri($messageDiv) { + + return $messageDiv->find('a.tgme_widget_message_date', 0)->href; + + } + + private function processTitle($messageDiv) { + + } + + private function processContent($messageDiv) { + $message = ''; + + if ($messageDiv->find('a.tgme_widget_message_reply', 0)) { + $message = $this->processReply($messageDiv); + } + + if ($messageDiv->find('div.tgme_widget_message_poll', 0)) { + //$message .= $messageDiv->find('div.tgme_widget_message_poll', 0); + } + + if ($messageDiv->find('video', 0)) { + $message = $this->processVideo($messageDiv); + } + + if ($messageDiv->find('a.tgme_widget_message_photo_wrap', 0)) { + $message = $this->processPhoto($messageDiv); + } + + if ($messageDiv->find('div.tgme_widget_message_text.js-message_text', 0)) { + $message .= $messageDiv->find('div.tgme_widget_message_text.js-message_text', 0); + } + + return $message; + + } + + private function processReply($messageDiv) { + + $reply = $messageDiv->find('a.tgme_widget_message_reply', 0); + + return <<{$reply->find('span.tgme_widget_message_author_name', 0)->plaintext}
+{$reply->find('div.tgme_widget_message_text', 0)->innertext} {$reply->href}
+EOD; + + } + + private function processPoll($messageDiv) { + + preg_match($this->backgroundImageRegex, $messageDiv->find('i.tgme_widget_message_video_thumb', 0)->style, $photo); + + return << + + +EOD; + + } + + private function processVideo($messageDiv) { + + preg_match($this->backgroundImageRegex, $messageDiv->find('i.tgme_widget_message_video_thumb', 0)->style, $photo); + + return << + + +EOD; + + } + + private function processPhoto($messageDiv) { + + preg_match($this->backgroundImageRegex, $messageDiv->find('a.tgme_widget_message_photo_wrap', 0)->style, $photo); + + return << +EOD; + } + + private function processDate($messageDiv) { + + return $messageDiv->find('time', 0)->datetime; + + } +} From 06995221ee65d6ea08f7bb8d3f506c8afeade9d0 Mon Sep 17 00:00:00 2001 From: Joseph Date: Tue, 18 Jun 2019 14:35:57 +0100 Subject: [PATCH 02/16] Add support for link previews --- bridges/TelegramBridge.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index 95efbe19401..fc63327b7a9 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -101,6 +101,10 @@ private function processContent($messageDiv) { $message .= $messageDiv->find('div.tgme_widget_message_text.js-message_text', 0); } + if ($messageDiv->find('a.tgme_widget_message_link_preview', 0)) { + $message .= $this->processLinkPreview($messageDiv); + } + return $message; } @@ -128,6 +132,28 @@ private function processPoll($messageDiv) { } + private function processLinkPreview($messageDiv) { + + $image = ''; + $preview = $messageDiv->find('a.tgme_widget_message_link_preview', 0); + + if($preview->find('i', 0) && + preg_match($this->backgroundImageRegex, $preview->find('i', 0)->style, $photo)) { + + $image = ''; + } + + $title = $preview->find('div.link_preview_title', 0)->plaintext; + $site = $preview->find('div.link_preview_site_name', 0)->plaintext; + $description = $preview->find('div.link_preview_description', 0)->plaintext; + + return <<$image
+{$title} - {$site}
{$description} +EOD; + + } + private function processVideo($messageDiv) { preg_match($this->backgroundImageRegex, $messageDiv->find('i.tgme_widget_message_video_thumb', 0)->style, $photo); @@ -146,7 +172,8 @@ private function processPhoto($messageDiv) { return << -EOD; +EOD; + } private function processDate($messageDiv) { From f1705bccdba81593dbc6906a8d8b06f8e2b92adf Mon Sep 17 00:00:00 2001 From: Joseph Date: Tue, 18 Jun 2019 14:59:00 +0100 Subject: [PATCH 03/16] Add support for polls --- bridges/TelegramBridge.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index fc63327b7a9..536c4866956 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -86,15 +86,15 @@ private function processContent($messageDiv) { } if ($messageDiv->find('div.tgme_widget_message_poll', 0)) { - //$message .= $messageDiv->find('div.tgme_widget_message_poll', 0); + $message .= $this->processPoll($messageDiv); } if ($messageDiv->find('video', 0)) { - $message = $this->processVideo($messageDiv); + $message .= $this->processVideo($messageDiv); } if ($messageDiv->find('a.tgme_widget_message_photo_wrap', 0)) { - $message = $this->processPhoto($messageDiv); + $message .= $this->processPhoto($messageDiv); } if ($messageDiv->find('div.tgme_widget_message_text.js-message_text', 0)) { @@ -122,12 +122,21 @@ private function processReply($messageDiv) { private function processPoll($messageDiv) { - preg_match($this->backgroundImageRegex, $messageDiv->find('i.tgme_widget_message_video_thumb', 0)->style, $photo); + $poll = $messageDiv->find('div.tgme_widget_message_poll', 0); + $title = $poll->find('div.tgme_widget_message_poll_question', 0)->plaintext; + $type = $poll->find('div.tgme_widget_message_poll_type', 0)->plaintext; + + $pollOptions = '
    '; + + foreach ($poll->find('div.tgme_widget_message_poll_option') as $option) { + $pollOptions .= '
  • ' . $option->children(0)->plaintext . ' - ' . + $option->find('div.tgme_widget_message_poll_option_text', 0)->plaintext . '
  • '; + } + $pollOptions .= '
'; + return << - - + {$title}
$type
{$pollOptions} EOD; } From 5dbce8a6f4b7499b28f3579ea98c7417282bcd98 Mon Sep 17 00:00:00 2001 From: Joseph Date: Tue, 18 Jun 2019 15:22:06 +0100 Subject: [PATCH 04/16] Add support for stickers --- bridges/TelegramBridge.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index 536c4866956..4faf26f2f03 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -84,6 +84,10 @@ private function processContent($messageDiv) { if ($messageDiv->find('a.tgme_widget_message_reply', 0)) { $message = $this->processReply($messageDiv); } + + if ($messageDiv->find('div.tgme_widget_message_sticker_wrap', 0)) { + $message .= $this->processSticker($messageDiv); + } if ($messageDiv->find('div.tgme_widget_message_poll', 0)) { $message .= $this->processPoll($messageDiv); @@ -120,6 +124,18 @@ private function processReply($messageDiv) { } + private function processSticker($messageDiv) { + + $stickerDiv = $messageDiv->find('div.tgme_widget_message_sticker_wrap', 0); + + preg_match($this->backgroundImageRegex, $stickerDiv->find('i', 0)->style, $sticker); + + return << +EOD; + + } + private function processPoll($messageDiv) { $poll = $messageDiv->find('div.tgme_widget_message_poll', 0); From 0a801bb997e3a85bcf76de9ca509116b529ab5b2 Mon Sep 17 00:00:00 2001 From: Joseph Date: Tue, 18 Jun 2019 15:23:29 +0100 Subject: [PATCH 05/16] Update processPhoto() to fetch all images --- bridges/TelegramBridge.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index 4faf26f2f03..a31628b3291 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -193,11 +193,17 @@ private function processVideo($messageDiv) { private function processPhoto($messageDiv) { - preg_match($this->backgroundImageRegex, $messageDiv->find('a.tgme_widget_message_photo_wrap', 0)->style, $photo); + $photos = ''; + + foreach ($messageDiv->find('a.tgme_widget_message_photo_wrap') as $photoWrap) { + preg_match($this->backgroundImageRegex, $photoWrap->style, $photo); + + $photos .= <<
+EOD; + } - return << -EOD; + return $photos; } From 566d17691b856c0a1cb481ccc23065e6e6561a96 Mon Sep 17 00:00:00 2001 From: Joseph Date: Tue, 18 Jun 2019 15:27:26 +0100 Subject: [PATCH 06/16] Update processLinkPreview() --- bridges/TelegramBridge.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index a31628b3291..7799bfa6227 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -160,17 +160,33 @@ private function processPoll($messageDiv) { private function processLinkPreview($messageDiv) { $image = ''; + $title = ''; + $site = ''; + $description = ''; + $preview = $messageDiv->find('a.tgme_widget_message_link_preview', 0); - + + if (trim($preview->innertext) != '') { + return ''; + } + if($preview->find('i', 0) && preg_match($this->backgroundImageRegex, $preview->find('i', 0)->style, $photo)) { $image = ''; } - $title = $preview->find('div.link_preview_title', 0)->plaintext; - $site = $preview->find('div.link_preview_site_name', 0)->plaintext; - $description = $preview->find('div.link_preview_description', 0)->plaintext; + if ($preview->find('div.link_preview_title', 0)) { + $title = $preview->find('div.link_preview_title', 0)->plaintext; + } + + if ($preview->find('div.link_preview_site_name', 0)) { + $site = $preview->find('div.link_preview_site_name', 0)->plaintext; + } + + if ($preview->find('div.link_preview_description', 0)) { + $description = $preview->find('div.link_preview_description', 0)->plaintext; + } return <<$image
From dcd656e95f6d9cf217ff9c703871b403dfacb643 Mon Sep 17 00:00:00 2001 From: Joseph Date: Tue, 18 Jun 2019 15:45:08 +0100 Subject: [PATCH 07/16] Add function getName() --- bridges/TelegramBridge.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index 7799bfa6227..5c5b2fd320d 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -15,6 +15,7 @@ class TelegramBridge extends BridgeAbstract { const CACHE_TIMEOUT = 600; // 15 mins + private $feedName = ''; private $backgroundImageRegex = "/background-image:url\('(.*)'\)/"; public function collectData() { @@ -22,6 +23,9 @@ public function collectData() { $html = getSimpleHTMLDOM($this->getURI()) or returnServerError('Could not request: ' . $this->getURI()); + $channelTitle = $html->find('div.tgme_channel_info_header_title span', 0)->plaintext; + $this->feedName = $channelTitle . ' (@' . $this->processUsername() . ')'; + foreach($html->find('div.tgme_widget_message_wrap.js-widget_message_wrap') as $index => $messageDiv) { $item = array(); @@ -44,20 +48,14 @@ public function getURI() { return parent::getURI(); } - /*public function getName() { - - if (!is_null($this->getInput('edition')) && !is_null($this->getInput('category'))) { - $parameters = $this->getParameters(); + public function getName() { - $editionValues = array_flip($parameters[0]['edition']['values']); - $categoryValues = array_flip($parameters[0]['category']['values']); - - return $categoryValues[$this->getInput('category')] . ' - ' . - $editionValues[$this->getInput('edition')] . ' - Brut.'; + if (!empty($this->feedName)) { + return $this->feedName . ' - Telegram'; } return parent::getName(); - }*/ + } private function processUsername() { From 0cf2dd44ea18bd632f3efa7d04b3eea9bdf72966 Mon Sep 17 00:00:00 2001 From: Joseph Date: Tue, 18 Jun 2019 17:07:04 +0100 Subject: [PATCH 08/16] Fix link previews not showing --- bridges/TelegramBridge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index 5c5b2fd320d..abedf2ba7f4 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -164,7 +164,7 @@ private function processLinkPreview($messageDiv) { $preview = $messageDiv->find('a.tgme_widget_message_link_preview', 0); - if (trim($preview->innertext) != '') { + if (trim($preview->innertext) === '') { return ''; } From 686c61d48664f97a3e22ce51b2ed7b121ff428bf Mon Sep 17 00:00:00 2001 From: Joseph Date: Tue, 18 Jun 2019 17:14:22 +0100 Subject: [PATCH 09/16] Add images to item enclosures array --- bridges/TelegramBridge.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index abedf2ba7f4..0039fc54f59 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -16,6 +16,8 @@ class TelegramBridge extends BridgeAbstract { const CACHE_TIMEOUT = 600; // 15 mins private $feedName = ''; + private $enclosures = array(); + private $backgroundImageRegex = "/background-image:url\('(.*)'\)/"; public function collectData() { @@ -27,13 +29,14 @@ public function collectData() { $this->feedName = $channelTitle . ' (@' . $this->processUsername() . ')'; foreach($html->find('div.tgme_widget_message_wrap.js-widget_message_wrap') as $index => $messageDiv) { + $this->enclosures = array(); $item = array(); $item['uri'] = $this->processUri($messageDiv); //$item['title'] $item['content'] = $this->processContent($messageDiv); $item['timestamp'] = $this->processDate($messageDiv); - //$item['enclosures'][]; + $item['enclosures'] = $this->enclosures; $this->items[] = $item; } @@ -128,6 +131,8 @@ private function processSticker($messageDiv) { preg_match($this->backgroundImageRegex, $stickerDiv->find('i', 0)->style, $sticker); + $this->enclosures[] = $sticker[1]; + return << EOD; @@ -172,6 +177,7 @@ private function processLinkPreview($messageDiv) { preg_match($this->backgroundImageRegex, $preview->find('i', 0)->style, $photo)) { $image = ''; + $this->enclosures[] = $photo[1]; } if ($preview->find('div.link_preview_title', 0)) { @@ -197,6 +203,8 @@ private function processVideo($messageDiv) { preg_match($this->backgroundImageRegex, $messageDiv->find('i.tgme_widget_message_video_thumb', 0)->style, $photo); + $this->enclosures[] = $photo[1]; + return << @@ -212,6 +220,8 @@ private function processPhoto($messageDiv) { foreach ($messageDiv->find('a.tgme_widget_message_photo_wrap') as $photoWrap) { preg_match($this->backgroundImageRegex, $photoWrap->style, $photo); + $this->enclosures[] = $photo[1]; + $photos .= <<
EOD; From efbde6cec052ea4021a4febf3f16b46d33d3d9a4 Mon Sep 17 00:00:00 2001 From: Joseph Date: Tue, 18 Jun 2019 17:36:29 +0100 Subject: [PATCH 10/16] Add support for forwarded from note --- bridges/TelegramBridge.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index 0039fc54f59..141711bf0c6 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -82,6 +82,10 @@ private function processTitle($messageDiv) { private function processContent($messageDiv) { $message = ''; + if ($messageDiv->find('div.tgme_widget_message_forwarded_from', 0)) { + $message = $messageDiv->find('div.tgme_widget_message_forwarded_from', 0)->innertext . '

'; + } + if ($messageDiv->find('a.tgme_widget_message_reply', 0)) { $message = $this->processReply($messageDiv); } From 530cdd839176fbb7482bcbb1536f10dcbeb98772 Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 19 Jun 2019 13:15:02 +0100 Subject: [PATCH 11/16] Fix special character ecoding in channel title --- bridges/TelegramBridge.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index 141711bf0c6..136595b29ed 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -25,7 +25,10 @@ public function collectData() { $html = getSimpleHTMLDOM($this->getURI()) or returnServerError('Could not request: ' . $this->getURI()); - $channelTitle = $html->find('div.tgme_channel_info_header_title span', 0)->plaintext; + $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) { From d3e9e788c5d2545e8dce8c4ae5520831665b8cbf Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 19 Jun 2019 13:16:00 +0100 Subject: [PATCH 12/16] Reverse order of items array (newest messages first) --- bridges/TelegramBridge.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index 136595b29ed..5373942740a 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -43,6 +43,9 @@ public function collectData() { $this->items[] = $item; } + + $this->items = array_reverse($this->items); + } public function getURI() { From 93b3d29e5f2dbde83d4795cd81302bffe9563f30 Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 19 Jun 2019 14:01:30 +0100 Subject: [PATCH 13/16] Use message body to create item title, add ellipsisTitle() --- bridges/TelegramBridge.php | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index 5373942740a..aa6d5398a78 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -17,6 +17,7 @@ class TelegramBridge extends BridgeAbstract { private $feedName = ''; private $enclosures = array(); + private $itemTitle = ''; private $backgroundImageRegex = "/background-image:url\('(.*)'\)/"; @@ -32,12 +33,13 @@ public function collectData() { $this->feedName = $channelTitle . ' (@' . $this->processUsername() . ')'; foreach($html->find('div.tgme_widget_message_wrap.js-widget_message_wrap') as $index => $messageDiv) { + $this->itemTitle = ''; $this->enclosures = array(); $item = array(); $item['uri'] = $this->processUri($messageDiv); - //$item['title'] $item['content'] = $this->processContent($messageDiv); + $item['title'] = $this->itemTitle; $item['timestamp'] = $this->processDate($messageDiv); $item['enclosures'] = $this->enclosures; @@ -114,6 +116,7 @@ private function processContent($messageDiv) { if ($messageDiv->find('div.tgme_widget_message_text.js-message_text', 0)) { $message .= $messageDiv->find('div.tgme_widget_message_text.js-message_text', 0); + $this->itemTitle = $this->ellipsisTitle($messageDiv->find('div.tgme_widget_message_text.js-message_text', 0)->plaintext); } if ($messageDiv->find('a.tgme_widget_message_link_preview', 0)) { @@ -137,6 +140,10 @@ 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); @@ -156,6 +163,10 @@ private function processPoll($messageDiv) { $title = $poll->find('div.tgme_widget_message_poll_question', 0)->plaintext; $type = $poll->find('div.tgme_widget_message_poll_type', 0)->plaintext; + if (empty($this->itemTitle)) { + $this->itemTitle = $title; + } + $pollOptions = '
    '; foreach ($poll->find('div.tgme_widget_message_poll_option') as $option) { @@ -211,6 +222,10 @@ private function processLinkPreview($messageDiv) { private function processVideo($messageDiv) { + if (empty($this->itemTitle)) { + $this->itemTitle = '@' . $this->processUsername() . ' posted a video'; + } + preg_match($this->backgroundImageRegex, $messageDiv->find('i.tgme_widget_message_video_thumb', 0)->style, $photo); $this->enclosures[] = $photo[1]; @@ -225,6 +240,10 @@ private function processVideo($messageDiv) { private function processPhoto($messageDiv) { + if (empty($this->itemTitle)) { + $this->itemTitle = '@' . $this->processUsername() . ' posted a photo'; + } + $photos = ''; foreach ($messageDiv->find('a.tgme_widget_message_photo_wrap') as $photoWrap) { @@ -246,4 +265,16 @@ private function processDate($messageDiv) { return $messageDiv->find('time', 0)->datetime; } + + private function ellipsisTitle($text) { + + $length = 100; + + if (strlen($text) > $length) { + $text = explode('
    ', wordwrap($text, $length, '
    ')); + return $text[0] . '...'; + } + return $text; + } + } From d263038ec275316954b109ff1d6d5677bd54257e Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 19 Jun 2019 17:02:03 +0100 Subject: [PATCH 14/16] Fix travis-ci issues https://travis-ci.org/RSS-Bridge/rss-bridge/jobs/547708643 --- bridges/TelegramBridge.php | 68 +++++++++++++++----------------------- 1 file changed, 27 insertions(+), 41 deletions(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index aa6d5398a78..f4d0b1fc61e 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -20,9 +20,9 @@ class TelegramBridge extends BridgeAbstract { private $itemTitle = ''; private $backgroundImageRegex = "/background-image:url\('(.*)'\)/"; - + public function collectData() { - + $html = getSimpleHTMLDOM($this->getURI()) or returnServerError('Could not request: ' . $this->getURI()); @@ -31,7 +31,7 @@ public function collectData() { ENT_QUOTES ); $this->feedName = $channelTitle . ' (@' . $this->processUsername() . ')'; - + foreach($html->find('div.tgme_widget_message_wrap.js-widget_message_wrap') as $index => $messageDiv) { $this->itemTitle = ''; $this->enclosures = array(); @@ -45,9 +45,7 @@ public function collectData() { $this->items[] = $item; } - $this->items = array_reverse($this->items); - } public function getURI() { @@ -62,7 +60,7 @@ public function getURI() { public function getName() { if (!empty($this->feedName)) { - return $this->feedName . ' - Telegram'; + return $this->feedName . ' - Telegram'; } return parent::getName(); @@ -76,17 +74,11 @@ private function processUsername() { return $this->getInput('username'); } - - private function processUri($messageDiv) { + private function processUri($messageDiv) { return $messageDiv->find('a.tgme_widget_message_date', 0)->href; - } - - private function processTitle($messageDiv) { - } - private function processContent($messageDiv) { $message = ''; @@ -116,7 +108,10 @@ private function processContent($messageDiv) { if ($messageDiv->find('div.tgme_widget_message_text.js-message_text', 0)) { $message .= $messageDiv->find('div.tgme_widget_message_text.js-message_text', 0); - $this->itemTitle = $this->ellipsisTitle($messageDiv->find('div.tgme_widget_message_text.js-message_text', 0)->plaintext); + + $this->itemTitle = $this->ellipsisTitle( + $messageDiv->find('div.tgme_widget_message_text.js-message_text', 0)->plaintext + ); } if ($messageDiv->find('a.tgme_widget_message_link_preview', 0)) { @@ -124,38 +119,35 @@ private function processContent($messageDiv) { } return $message; - } private function processReply($messageDiv) { $reply = $messageDiv->find('a.tgme_widget_message_reply', 0); - + return <<{$reply->find('span.tgme_widget_message_author_name', 0)->plaintext}
    {$reply->find('div.tgme_widget_message_text', 0)->innertext} {$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); - + $this->enclosures[] = $sticker[1]; - + return << EOD; - } - + private function processPoll($messageDiv) { $poll = $messageDiv->find('div.tgme_widget_message_poll', 0); @@ -178,22 +170,21 @@ private function processPoll($messageDiv) { return <<$type
    {$pollOptions} EOD; - } - + private function processLinkPreview($messageDiv) { $image = ''; $title = ''; $site = ''; $description = ''; - + $preview = $messageDiv->find('a.tgme_widget_message_link_preview', 0); if (trim($preview->innertext) === '') { return ''; } - + if($preview->find('i', 0) && preg_match($this->backgroundImageRegex, $preview->find('i', 0)->style, $photo)) { @@ -217,33 +208,31 @@ private function processLinkPreview($messageDiv) {
    $image
    {$title} - {$site}
    {$description}
    EOD; - } - + private function processVideo($messageDiv) { if (empty($this->itemTitle)) { $this->itemTitle = '@' . $this->processUsername() . ' posted a video'; } - + preg_match($this->backgroundImageRegex, $messageDiv->find('i.tgme_widget_message_video_thumb', 0)->style, $photo); $this->enclosures[] = $photo[1]; - + return << EOD; - } - + private function processPhoto($messageDiv) { if (empty($this->itemTitle)) { $this->itemTitle = '@' . $this->processUsername() . ' posted a photo'; } - + $photos = ''; foreach ($messageDiv->find('a.tgme_widget_message_photo_wrap') as $photoWrap) { @@ -257,19 +246,16 @@ private function processPhoto($messageDiv) { } return $photos; - } - - private function processDate($messageDiv) { + private function processDate($messageDiv) { return $messageDiv->find('time', 0)->datetime; - } - + private function ellipsisTitle($text) { $length = 100; - + if (strlen($text) > $length) { $text = explode('
    ', wordwrap($text, $length, '
    ')); return $text[0] . '...'; From a21fd061600baf5063d05417ce18d7d0000d764b Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 19 Jun 2019 17:12:56 +0100 Subject: [PATCH 15/16] Fix more travis-ci issues --- bridges/TelegramBridge.php | 43 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index f4d0b1fc61e..3cc2d8280cc 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -85,7 +85,7 @@ private function processContent($messageDiv) { if ($messageDiv->find('div.tgme_widget_message_forwarded_from', 0)) { $message = $messageDiv->find('div.tgme_widget_message_forwarded_from', 0)->innertext . '

    '; } - + if ($messageDiv->find('a.tgme_widget_message_reply', 0)) { $message = $this->processReply($messageDiv); } @@ -93,7 +93,7 @@ private function processContent($messageDiv) { if ($messageDiv->find('div.tgme_widget_message_sticker_wrap', 0)) { $message .= $this->processSticker($messageDiv); } - + if ($messageDiv->find('div.tgme_widget_message_poll', 0)) { $message .= $this->processPoll($messageDiv); } @@ -120,21 +120,22 @@ private function processContent($messageDiv) { return $message; } - + private function processReply($messageDiv) { $reply = $messageDiv->find('a.tgme_widget_message_reply', 0); return <<{$reply->find('span.tgme_widget_message_author_name', 0)->plaintext}
    -{$reply->find('div.tgme_widget_message_text', 0)->innertext} {$reply->href}
    +{$reply->find('div.tgme_widget_message_text', 0)->innertext} +{$reply->href}
    EOD; } private function processSticker($messageDiv) { if (empty($this->itemTitle)) { - $this->itemTitle = '@' . $this->processUsername() . ' posted a sticker'; + $this->itemTitle = '@' . $this->processUsername() . ' posted a sticker'; } $stickerDiv = $messageDiv->find('div.tgme_widget_message_sticker_wrap', 0); @@ -154,19 +155,19 @@ private function processPoll($messageDiv) { $title = $poll->find('div.tgme_widget_message_poll_question', 0)->plaintext; $type = $poll->find('div.tgme_widget_message_poll_type', 0)->plaintext; - + if (empty($this->itemTitle)) { $this->itemTitle = $title; } $pollOptions = '
      '; - + foreach ($poll->find('div.tgme_widget_message_poll_option') as $option) { - $pollOptions .= '
    • ' . $option->children(0)->plaintext . ' - ' . + $pollOptions .= '
    • ' . $option->children(0)->plaintext . ' - ' . $option->find('div.tgme_widget_message_poll_option_text', 0)->plaintext . '
    • '; } $pollOptions .= '
    '; - + return <<$type
    {$pollOptions} EOD; @@ -180,12 +181,12 @@ private function processLinkPreview($messageDiv) { $description = ''; $preview = $messageDiv->find('a.tgme_widget_message_link_preview', 0); - + if (trim($preview->innertext) === '') { return ''; } - if($preview->find('i', 0) && + if($preview->find('i', 0) && preg_match($this->backgroundImageRegex, $preview->find('i', 0)->style, $photo)) { $image = ''; @@ -195,11 +196,11 @@ private function processLinkPreview($messageDiv) { if ($preview->find('div.link_preview_title', 0)) { $title = $preview->find('div.link_preview_title', 0)->plaintext; } - + if ($preview->find('div.link_preview_site_name', 0)) { $site = $preview->find('div.link_preview_site_name', 0)->plaintext; } - + if ($preview->find('div.link_preview_description', 0)) { $description = $preview->find('div.link_preview_description', 0)->plaintext; } @@ -213,7 +214,7 @@ private function processLinkPreview($messageDiv) { private function processVideo($messageDiv) { if (empty($this->itemTitle)) { - $this->itemTitle = '@' . $this->processUsername() . ' posted a video'; + $this->itemTitle = '@' . $this->processUsername() . ' posted a video'; } preg_match($this->backgroundImageRegex, $messageDiv->find('i.tgme_widget_message_video_thumb', 0)->style, $photo); @@ -228,23 +229,22 @@ private function processVideo($messageDiv) { } private function processPhoto($messageDiv) { - + if (empty($this->itemTitle)) { - $this->itemTitle = '@' . $this->processUsername() . ' posted a photo'; + $this->itemTitle = '@' . $this->processUsername() . ' posted a photo'; } $photos = ''; foreach ($messageDiv->find('a.tgme_widget_message_photo_wrap') as $photoWrap) { preg_match($this->backgroundImageRegex, $photoWrap->style, $photo); - + $this->enclosures[] = $photo[1]; - + $photos .= <<
    -EOD; +EOD; } - return $photos; } @@ -258,9 +258,8 @@ private function ellipsisTitle($text) { if (strlen($text) > $length) { $text = explode('
    ', wordwrap($text, $length, '
    ')); - return $text[0] . '...'; + return $text[0] . '...'; } return $text; } - } From b17676a8204e35bea23884905c7ff122646f19a3 Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 19 Jun 2019 20:31:11 +0000 Subject: [PATCH 16/16] Change CACHE_TIMEOUT to 900 (15 mins) Change CACHE_TIMEOUT to 900 (15 mins) as noted in code review. Co-Authored-By: LogMANOriginal --- bridges/TelegramBridge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index 3cc2d8280cc..5fec905ed52 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -13,7 +13,7 @@ class TelegramBridge extends BridgeAbstract { ) ); - const CACHE_TIMEOUT = 600; // 15 mins + const CACHE_TIMEOUT = 900; // 15 mins private $feedName = ''; private $enclosures = array();