[VkBridge] Photo fixes (#3039)

This commit fixes following issues:

- Photos from user profile wall started appearing as blured
- On posts with photo collection small thumbnails are shown
This commit is contained in:
Eugene Molotov 2022-09-16 01:17:10 +05:00 committed by GitHub
parent a1e229a7e1
commit 11220ef373
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 2 deletions

View File

@ -304,8 +304,30 @@ class VkBridge extends BridgeAbstract
}
$item = [];
$item['content'] = strip_tags(backgroundToImg($post->find('div.wall_text', 0)->innertext), '<a><br><img>');
$item['content'] .= $content_suffix;
$content = strip_tags(backgroundToImg($post->find('div.wall_text', 0)->innertext), '<a><br><img>');
$content .= $content_suffix;
$content = str_get_html($content);
foreach ($content->find('img') as $img) {
$parsed_src = parse_url($img->getAttribute('src'));
// unblur images (case of impf)
// get original images instead of thumbnails (case of impg)
$imgPrefix = array_reduce(['/impf/', '/impg/'], function ($a, $c) use ($parsed_src) {
if ($a) {
return $a;
}
if (str_starts_with($parsed_src['path'], $c)) {
return $c;
}
return $a;
}, '');
if ($imgPrefix) {
$new_src = $parsed_src['scheme'] . '://' . $parsed_src['host'];
$new_src .= substr($parsed_src['path'], strlen($imgPrefix) - 1);
$img->setAttribute('src', $new_src);
}
}
$item['content'] = $content->outertext;
$item['categories'] = $hashtags;
// get post link