From 97baf3e8b9be699d972b91a159ccbe0891efe8ae Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 23 Dec 2021 17:33:04 +0300 Subject: process gallery media in the correct order --- plugins/af_redditimgur/init.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index e724d9b06..f2a04ce24 100755 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -158,7 +158,24 @@ class Af_RedditImgur extends Plugin { private function process_post_media(array $data, DOMDocument $doc, DOMXPath $xpath, DOMElement $anchor) : bool { $found = 0; - if (isset($data["media_metadata"])) { + // process galleries in the right order + if (isset($data["gallery_data"]) && isset($data["media_metadata"])) { + foreach ($data["gallery_data"]["items"] as $gal_item) { + $media_id = $gal_item["media_id"] ?? null; + + if ($media_id) { + $media_url = htmlspecialchars_decode($data["media_metadata"][$media_id]["s"]["u"] ?? ""); + + if ($media_url) { + Debug::log("found gallery item: $media_id, url: $media_url", Debug::LOG_EXTENDED); + + $this->handle_as_image($doc, $anchor, $media_url); + $found = 1; + } + } + } + // i'm not sure if this is a thing, but if there's no gallery just process any possible attaches in the random order... + } else if (isset($data["media_metadata"])) { foreach ($data["media_metadata"] as $media) { if (!empty($media["s"]["u"])) { $media_url = htmlspecialchars_decode($media["s"]["u"]); -- cgit v1.2.3