summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-12-23 17:33:04 +0300
committerAndrew Dolgov <[email protected]>2021-12-23 17:33:04 +0300
commit97baf3e8b9be699d972b91a159ccbe0891efe8ae (patch)
treec0e0fb7752dfb9dcd6684963b1ff452dfd3b5960 /plugins
parent1818fc11a52dee85f5fd28e4853ee266116c44ad (diff)
process gallery media in the correct order
Diffstat (limited to 'plugins')
-rwxr-xr-xplugins/af_redditimgur/init.php19
1 files changed, 18 insertions, 1 deletions
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"]);