Skip to content

Commit 5fec5a3

Browse files
committed
Merge branch 'master' of github.com:Nebulius/grav-plugin-static-social-embeds
2 parents 25dd280 + 8979e85 commit 5fec5a3

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

CHANGELOG.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
#v1.1.0
1+
# v1.1.3
2+
## 23-08-2018
3+
4+
1. [](#bugfix)
5+
* Fixed error while embedding non-existant Instagram post.
6+
7+
# v1.1.2
8+
## 14-08-2018
9+
10+
1. [](#bugfix)
11+
* Fixed Instagram posts failing to be retrieved in some cases.
12+
13+
# v1.1.1
14+
## 14-08-2018
15+
16+
1. [](#bugfix)
17+
* Fixed a regression where download options were no longer working since the per-network download options (oh the irony).
18+
19+
# v1.1.0
220
## 11-07-2018
321

422
1. [](#new)

blueprints.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Static Social Embeds
2-
version: 1.1.1
2+
version: 1.1.4
33
description: |
44
Embeds social status (like tweets, instagram posts, toots, etc.) in articles without using their embed iframe,
55
but rather statically without any dependency to the service.

shortcodes/InstagramShortcode.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,33 @@ protected function getData($url)
4848
curl_setopt_array($ch, [
4949
CURLOPT_TIMEOUT => 3600,
5050
CURLOPT_URL => $url,
51+
CURLOPT_FOLLOWLOCATION => true,
5152
CURLOPT_RETURNTRANSFER => true,
5253
CURLOPT_SSL_VERIFYPEER => false
5354
]);
5455

5556
$raw_instagram_html = curl_exec($ch);
57+
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
58+
59+
$error_code = curl_errno($ch);
60+
$error = $error_code != 0 ? (': #' . $error_code . ' - ' . curl_error($ch)) : '';
61+
62+
if (!$error && $http_code != 200)
63+
{
64+
$error = ': HTTP ' . $http_code . ($http_code == 404 ? ' - Not Found' : '');
65+
$raw_instagram_html = null;
66+
}
5667

5768
curl_close($ch);
5869

5970
if (!$raw_instagram_html)
60-
return ['errors' => [['code' => 0, 'message' => 'Unable to retrieve instagram post']], 'url' => $url];
71+
return ['errors' => [['code' => 0, 'message' => 'Unable to retrieve instagram post' . $error]], 'url' => $url];
6172

6273
preg_match('/window\._sharedData = (.*);<\/script>/', $raw_instagram_html, $matches, PREG_OFFSET_CAPTURE, 0);
6374

75+
if (!$matches || count($matches) < 2 || count($matches[1]) < 1)
76+
return ['errors' => [['code' => 0, 'message' => 'Unable to retrieve instagram post: cannot parse the web page to retrieve data.']], 'url' => $url];
77+
6478
$post = json_decode($matches[1][0], true);
6579

6680
if (!$post
@@ -70,7 +84,7 @@ protected function getData($url)
7084
|| !isset($post['entry_data']['PostPage'][0]['graphql'])
7185
|| !isset($post['entry_data']['PostPage'][0]['graphql']['shortcode_media']))
7286
{
73-
return ['errors' => [['code' => 0, 'message' => 'Unable to retrieve instagram post']], 'url' => $url];
87+
return ['errors' => [['code' => 0, 'message' => 'Unable to retrieve instagram post: cannot parse the web page to retrieve data.']], 'url' => $url];
7488
}
7589

7690
// Instagram Post or Inner Post (as you like)

0 commit comments

Comments
 (0)