From 59bbc9d2e7a38c8ec1c05040f2c63314877cd628 Mon Sep 17 00:00:00 2001
From: Eugene Molotov <eugene.molotov@yandex.ru>
Date: Fri, 18 Dec 2020 07:58:51 +0500
Subject: [PATCH] [VkBridge] Several improvements (#1802)

* Improved post author computation
* Show repost sources
* Handle second copy quote
* Fixed incorrect image uri's
---
 bridges/VkBridge.php | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/bridges/VkBridge.php b/bridges/VkBridge.php
index 87eaef20..89c11278 100644
--- a/bridges/VkBridge.php
+++ b/bridges/VkBridge.php
@@ -232,11 +232,16 @@ class VkBridge extends BridgeAbstract
 				$div->outertext = '';
 			}
 
-			// get sign
+			// get sign / post author
 			$post_author = $pageName;
-			foreach($post->find('a.wall_signed_by') as $a) {
-				$post_author = $a->innertext;
-				$a->outertext = '';
+			$author_selectors = array('a.wall_signed_by', 'a.author');
+			foreach($author_selectors as $author_selector) {
+				$a = $post->find($author_selector, 0);
+				if (is_object($a)) {
+					$post_author = $a->innertext;
+					$a->outertext = '';
+					break;
+				}
 			}
 
 			// fix links and get post hashtags
@@ -274,16 +279,24 @@ class VkBridge extends BridgeAbstract
 				}
 			}
 
-			if (is_object($post->find('div.copy_quote', 0))) {
+			$copy_quote = $post->find('div.copy_quote', 0);
+			if (is_object($copy_quote)) {
 				if ($this->getInput('hide_reposts') === true) {
 					continue;
 				}
-				$copy_quote = $post->find('div.copy_quote', 0);
 				if ($copy_post_header = $copy_quote->find('div.copy_post_header', 0)) {
 					$copy_post_header->outertext = '';
 				}
+
+				$second_copy_quote = $copy_quote->find('div.published_sec_quote', 0);
+				if (is_object($second_copy_quote)) {
+					$second_copy_quote_author = $second_copy_quote->find('a.copy_author', 0)->outertext;
+					$second_copy_quote_content = $second_copy_quote->find('div.copy_post_date', 0)->outertext;
+					$second_copy_quote->outertext = "<br>Reposted ($second_copy_quote_author): $second_copy_quote_content";
+				}
+				$copy_quote_author = $copy_quote->find('a.copy_author', 0)->outertext;
 				$copy_quote_content = $copy_quote->innertext;
-				$copy_quote->outertext = "<br>Reposted: <br>$copy_quote_content";
+				$copy_quote->outertext = "<br>Reposted ($copy_quote_author): <br>$copy_quote_content";
 			}
 
 			$item = array();
@@ -333,7 +346,7 @@ class VkBridge extends BridgeAbstract
 		$data = json_decode($arg, true);
 		if ($data == null) return;
 
-		$thumb = $data['temp']['base'] . $data['temp']['x_'][0] . '.jpg';
+		$thumb = $data['temp']['base'] . $data['temp']['x_'][0];
 		$original = '';
 		foreach(array('y_', 'z_', 'w_') as $key) {
 			if (!isset($data['temp'][$key])) continue;
@@ -343,7 +356,7 @@ class VkBridge extends BridgeAbstract
 			} else {
 				$base = $data['temp']['base'];
 			}
-			$original = $base . $data['temp'][$key][0] . '.jpg';
+			$original = $base . $data['temp'][$key][0];
 		}
 
 		if ($original) {