diff --git a/CHANGELOG.md b/CHANGELOG.md index bc49e0c..d63e6e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,22 @@ -#v1.1.0 +# v1.1.3 +## 23-08-2018 + +1. [](#bugfix) + * Fixed error while embedding non-existant Instagram post. + +# v1.1.2 +## 14-08-2018 + +1. [](#bugfix) + * Fixed Instagram posts failing to be retrieved in some cases. + +# v1.1.1 +## 14-08-2018 + +1. [](#bugfix) + * Fixed a regression where download options were no longer working since the per-network download options (oh the irony). + +# v1.1.0 ## 11-07-2018 1. [](#new) diff --git a/blueprints.yaml b/blueprints.yaml index b6e771b..c685167 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,5 +1,5 @@ name: Static Social Embeds -version: 1.1.1 +version: 1.1.4 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..7202e88 100644 --- a/shortcodes/InstagramShortcode.php +++ b/shortcodes/InstagramShortcode.php @@ -48,19 +48,33 @@ 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); + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + $error_code = curl_errno($ch); + $error = $error_code != 0 ? (': #' . $error_code . ' - ' . curl_error($ch)) : ''; + + if (!$error && $http_code != 200) + { + $error = ': HTTP ' . $http_code . ($http_code == 404 ? ' - Not Found' : ''); + $raw_instagram_html = null; + } 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); + if (!$matches || count($matches) < 2 || count($matches[1]) < 1) + return ['errors' => [['code' => 0, 'message' => 'Unable to retrieve instagram post: cannot parse the web page to retrieve data.']], 'url' => $url]; + $post = json_decode($matches[1][0], true); if (!$post @@ -70,7 +84,7 @@ protected function getData($url) || !isset($post['entry_data']['PostPage'][0]['graphql']) || !isset($post['entry_data']['PostPage'][0]['graphql']['shortcode_media'])) { - return ['errors' => [['code' => 0, 'message' => 'Unable to retrieve instagram post']], 'url' => $url]; + return ['errors' => [['code' => 0, 'message' => 'Unable to retrieve instagram post: cannot parse the web page to retrieve data.']], 'url' => $url]; } // Instagram Post or Inner Post (as you like)