From 065a56a4beb4299fa5a886be4873d5ee52308733 Mon Sep 17 00:00:00 2001 From: Amaury Carrade Date: Tue, 14 Aug 2018 20:53:45 +0200 Subject: [PATCH] Fixed Instagram posts badly retrieved if Instagram redirects to another URL. (May happen if there is a missing trailing shash, for example.) --- CHANGELOG.md | 6 ++++++ blueprints.yaml | 2 +- shortcodes/InstagramShortcode.php | 6 +++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6e71cf..9751d81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v1.1.2 +## 14-08-2018 + +1. [](#bugfix) + * Fixed Instagram posts failing to be retrieved in some cases. + # v1.1.1 ## 14-08-2018 diff --git a/blueprints.yaml b/blueprints.yaml index e0a42e9..3f5df0d 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,5 +1,5 @@ name: Static Social Embeds -version: 1.1.1 +version: 1.1.2 description: | Embeds social status (like tweets, instagram posts, toots, etc.) in articles without using their embed iframe, but rather statically without any dependency to the service. diff --git a/shortcodes/InstagramShortcode.php b/shortcodes/InstagramShortcode.php index 48b1dd0..4a195a6 100644 --- a/shortcodes/InstagramShortcode.php +++ b/shortcodes/InstagramShortcode.php @@ -48,16 +48,20 @@ protected function getData($url) curl_setopt_array($ch, [ CURLOPT_TIMEOUT => 3600, CURLOPT_URL => $url, + CURLOPT_FOLLOWLOCATION => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false ]); $raw_instagram_html = curl_exec($ch); + $error_code = curl_errno($ch); + $error = $error_code != 0 ? (': #' . $error_code . ' - ' . curl_error($ch)) : ''; + curl_close($ch); if (!$raw_instagram_html) - return ['errors' => [['code' => 0, 'message' => 'Unable to retrieve instagram post']], 'url' => $url]; + return ['errors' => [['code' => 0, 'message' => 'Unable to retrieve instagram post' . $error]], 'url' => $url]; preg_match('/window\._sharedData = (.*);<\/script>/', $raw_instagram_html, $matches, PREG_OFFSET_CAPTURE, 0);