]> git.mxchange.org Git - friendica-addons.git/commitdiff
[twitter] Add support for multiple images in parse_url hook function
authorHypolite Petovan <hypolite@mrpetovan.com>
Thu, 5 Nov 2020 14:34:10 +0000 (09:34 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 5 Nov 2020 14:34:10 +0000 (09:34 -0500)
twitter/twitter.php

index e2208090c12c6a6fdc3b08815a59943d7569bcff..83731943d2f30901f8d457788b5920296509510d 100644 (file)
@@ -934,12 +934,15 @@ function twitter_parse_link(App $a, array &$b)
        $item = twitter_createpost($a, 0, $status, [], true, false, true);
 
        if ($b['format'] == 'json') {
-               if (!empty($status->extended_entities->media[0]->media_url_https)) {
-                       $images = [[
-                               'src'    => $status->extended_entities->media[0]->media_url_https,
-                               'width'  => $status->extended_entities->media[0]->sizes->thumb->w,
-                               'height' => $status->extended_entities->media[0]->sizes->thumb->h,
-                       ]];
+               $images = [];
+               foreach ($status->extended_entities->media ?? [] as $media) {
+                       if (!empty($media->media_url_https)) {
+                               $images[] = [
+                                       'src'    => $media->media_url_https,
+                                       'width'  => $media->sizes->thumb->w,
+                                       'height' => $media->sizes->thumb->h,
+                               ];
+                       }
                }
 
                $b['text'] = [
@@ -948,7 +951,7 @@ function twitter_parse_link(App $a, array &$b)
                                'url' => $item['plink'],
                                'title' => DI::l10n()->t('%s on Twitter', $status->user->name),
                                'text' => BBCode::toPlaintext($item['body'], false),
-                               'images' => $images ?? [],
+                               'images' => $images,
                        ],
                        'contentType' => 'attachment',
                        'success' => true,