From 80376830c5ffe55fd0f9e05e674e79fb4525101f Mon Sep 17 00:00:00 2001 From: Eugene Molotov Date: Sat, 10 Jun 2023 21:27:32 +0500 Subject: [PATCH] [VkBridge] Handle some secondary attachments (#3430) --- bridges/VkBridge.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/bridges/VkBridge.php b/bridges/VkBridge.php index 0b00fca7..0cd2fba8 100644 --- a/bridges/VkBridge.php +++ b/bridges/VkBridge.php @@ -311,6 +311,44 @@ class VkBridge extends BridgeAbstract $copy_quote->outertext = "
Reposted ($copy_quote_author):
$copy_quote_content"; } + foreach ($post->find('.SecondaryAttachment') as $sa) { + $sa_href = $sa->getAttribute('href'); + if (!$sa_href) { + $sa_href = ''; + } + $sa_task_click = $sa->getAttribute('data-task-click'); + + if (str_starts_with($sa_href, 'https://vk.com/doc')) { + // document + $doc_title = $sa->find('.SecondaryAttachment__childrenText', 0)->innertext; + $doc_size = $sa->find('.SecondaryAttachmentSubhead', 0)->innertext; + $doc_link = $sa_href; + $content_suffix .= "
Doc: $doc_title ($doc_size)"; + $sa->outertext = ''; + } else if (str_starts_with($sa_href, 'https://vk.com/@')) { + // article + $article_title = $sa->find('.SecondaryAttachment__childrenText', 0)->innertext; + $article_author = explode('Article ยท from ', $sa->find('.SecondaryAttachmentSubhead', 0)->innertext)[1]; + $article_link = $sa_href; + $content_suffix .= "
Article: $article_title ($article_author)"; + $sa->outertext = ''; + } else if ($sa_task_click == 'SecondaryAttachment/playAudio') { + // audio + $audio_json = json_decode(html_entity_decode($sa->getAttribute('data-audio'))); + $audio_link = $audio_json->url; + $audio_title = $sa->find('.SecondaryAttachment__childrenText', 0)->innertext; + $audio_author = $sa->find('.SecondaryAttachmentSubhead', 0)->innertext; + $content_suffix .= "
Audio: $audio_title ($audio_author)"; + $sa->outertext = ''; + } else if ($sa_task_click == 'SecondaryAttachment/playPlaylist') { + // playlist link + $playlist_title = $sa->find('.SecondaryAttachment__childrenText', 0)->innertext; + $playlist_link = $sa->find('.SecondaryAttachment__link', 0)->getAttribute('href'); + $content_suffix .= "
Playlist: $playlist_title"; + $sa->outertext = ''; + } + } + $item = []; $content = strip_tags(backgroundToImg($post->find('div.wall_text', 0)->innertext), '
'); $content .= $content_suffix;