Version Description
Download this release
Release Info
Developer | blossomthemes |
Plugin | BlossomThemes Social Feed |
Version | 1.0.2 |
Comparing to | |
See all releases |
Code changes from version 1.0.1 to 1.0.2
- README.txt +6 -2
- blossomthemes-instagram-feed.php +1 -1
- includes/class-blossomthemes-instagram-feed-settings.php +0 -12
- includes/class-blossomthemes-instagram-feed-shortcodes.php +34 -13
- includes/vendor/InstagramSpider.php +142 -58
- includes/widgets/widget-blossomthemes-instagram-feed.php +24 -15
- public/css/blossomthemes-instagram-feed-public.css +3 -0
README.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://blossomthemes.com
|
|
4 |
Tags: comments, spam
|
5 |
Requires at least: 4.3
|
6 |
Tested up to: 4.9
|
7 |
-
Stable tag: 1.0.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -48,4 +48,8 @@ If you do not enter the Instagram username in the widget, the username assigned
|
|
48 |
* Initial release
|
49 |
|
50 |
= 1.0.1 =
|
51 |
-
* Compatibility tested
|
|
|
|
|
|
|
|
4 |
Tags: comments, spam
|
5 |
Requires at least: 4.3
|
6 |
Tested up to: 4.9
|
7 |
+
Stable tag: 1.0.2
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
48 |
* Initial release
|
49 |
|
50 |
= 1.0.1 =
|
51 |
+
* Compatibility tested
|
52 |
+
|
53 |
+
|
54 |
+
= 1.0.2 =
|
55 |
+
* Issue fixed
|
blossomthemes-instagram-feed.php
CHANGED
@@ -16,7 +16,7 @@
|
|
16 |
* Plugin Name: BlossomThemes Instagram Feed
|
17 |
* Plugin URI: https://wordpress.org/plugins/blossomthemes-instagram-feed
|
18 |
* Description: Show instagram feed on your website using shortcode and widget.
|
19 |
-
* Version: 1.0.
|
20 |
* Author: blossomthemes
|
21 |
* Author URI: https://blossomthemes.com
|
22 |
* License: GPL-2.0+
|
16 |
* Plugin Name: BlossomThemes Instagram Feed
|
17 |
* Plugin URI: https://wordpress.org/plugins/blossomthemes-instagram-feed
|
18 |
* Description: Show instagram feed on your website using shortcode and widget.
|
19 |
+
* Version: 1.0.2
|
20 |
* Author: blossomthemes
|
21 |
* Author URI: https://blossomthemes.com
|
22 |
* License: GPL-2.0+
|
includes/class-blossomthemes-instagram-feed-settings.php
CHANGED
@@ -41,22 +41,10 @@ class BlossomThemes_Instagram_Feed_Settings
|
|
41 |
<label for="blossomthemes_instagram_feed_settings[photos]"><?php _e('Number of Photos', 'blossomthemes-instagram-feed'); ?></label>
|
42 |
<input min="1" max="20" id="blossomthemes_instagram_feed_settings[photos]" name="blossomthemes_instagram_feed_settings[photos]" type="number" value="<?php echo isset( $options['photos'] ) ? esc_attr( $options['photos'] ):'10'; ?>">
|
43 |
</div>
|
44 |
-
<div class="btif-option-field-wrap">
|
45 |
-
<label for="blossomthemes_instagram_feed_settings[photos]"><?php _e('Number of Photos Per Row', 'blossomthemes-instagram-feed'); ?></label>
|
46 |
-
<input min="1" max="5" id="blossomthemes_instagram_feed_settings[photos_row]" name="blossomthemes_instagram_feed_settings[photos_row]" max="6" type="number" value="<?php echo isset( $options['photos_row'] ) ? esc_attr( $options['photos_row'] ):'5'; ?>">
|
47 |
-
</div>
|
48 |
<div class="btif-option-field-wrap">
|
49 |
<label for="blossomthemes_instagram_feed_settings[follow_me]"><?php _e('Profile Link Text', 'blossomthemes-instagram-feed'); ?></label>
|
50 |
<input id="blossomthemes_instagram_feed_settings[follow_me]" name="blossomthemes_instagram_feed_settings[follow_me]" type="text" value="<?php echo isset( $options['follow_me'] ) ? esc_attr( $options['follow_me'] ):'Follow Me!'; ?>">
|
51 |
</div>
|
52 |
-
<div class="btif-option-field-wrap">
|
53 |
-
<label for="likes-comments"><?php _e( 'Show Likes/Comments', 'blossomthemes-instagram-feed' ); ?></label>
|
54 |
-
<input type="checkbox" value="1" id="likes-comments" name="blossomthemes_instagram_feed_settings[meta]" <?php
|
55 |
-
if ( isset( $options['meta'] ) ) {
|
56 |
-
checked( $options['meta'], true );
|
57 |
-
}
|
58 |
-
?>>
|
59 |
-
</div>
|
60 |
</div>
|
61 |
<div class="blossomthemes-instagram-feed-settings usage" id="blossomthemes-instagram-feed-settings-usage">
|
62 |
<?php $custom_id = get_the_ID(); ?>
|
41 |
<label for="blossomthemes_instagram_feed_settings[photos]"><?php _e('Number of Photos', 'blossomthemes-instagram-feed'); ?></label>
|
42 |
<input min="1" max="20" id="blossomthemes_instagram_feed_settings[photos]" name="blossomthemes_instagram_feed_settings[photos]" type="number" value="<?php echo isset( $options['photos'] ) ? esc_attr( $options['photos'] ):'10'; ?>">
|
43 |
</div>
|
|
|
|
|
|
|
|
|
44 |
<div class="btif-option-field-wrap">
|
45 |
<label for="blossomthemes_instagram_feed_settings[follow_me]"><?php _e('Profile Link Text', 'blossomthemes-instagram-feed'); ?></label>
|
46 |
<input id="blossomthemes_instagram_feed_settings[follow_me]" name="blossomthemes_instagram_feed_settings[follow_me]" type="text" value="<?php echo isset( $options['follow_me'] ) ? esc_attr( $options['follow_me'] ):'Follow Me!'; ?>">
|
47 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
</div>
|
49 |
<div class="blossomthemes-instagram-feed-settings usage" id="blossomthemes-instagram-feed-settings-usage">
|
50 |
<?php $custom_id = get_the_ID(); ?>
|
includes/class-blossomthemes-instagram-feed-shortcodes.php
CHANGED
@@ -13,34 +13,55 @@ class BlossomThemes_Instagram_Feed_Shortcodes
|
|
13 |
add_shortcode( 'blossomthemes_instagram_feed', array( $this, 'blossomthemes_instagram_feed_sc' ) );
|
14 |
}
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
function blossomthemes_instagram_feed_sc(){
|
17 |
ob_start();
|
18 |
$options = get_option( 'blossomthemes_instagram_feed_settings', true );
|
19 |
-
|
20 |
if( !isset( $options['username'] ) || $options['username'] == '' )
|
21 |
{
|
22 |
return;
|
23 |
}
|
24 |
|
25 |
-
$
|
26 |
-
$photos = absint($options['photos']);
|
27 |
$photos_row = isset( $options['photos_row'] ) ? esc_attr( $options['photos_row'] ) :'5';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
$instaUrl = 'https://www.instagram.com/';
|
29 |
$instaUrl .= $options['username'];
|
30 |
|
31 |
-
$
|
32 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
echo '<ul class="popup-gallery photos-'.$photos_row.'">';
|
34 |
$i=0;
|
35 |
-
foreach ($
|
36 |
if( $i<$photos )
|
37 |
-
{
|
38 |
-
|
39 |
-
|
40 |
-
{
|
41 |
-
echo '<span class="instagram-meta"><i class="fa fa-heart" aria-hidden="true">'.$key['likes'].'</i>'.'<i class="fa fa-comment" aria-hidden="true">'.$key['comments'].'</i>'.'</span>';
|
42 |
-
}
|
43 |
-
echo '</li>';
|
44 |
}
|
45 |
$i++;
|
46 |
}
|
13 |
add_shortcode( 'blossomthemes_instagram_feed', array( $this, 'blossomthemes_instagram_feed_sc' ) );
|
14 |
}
|
15 |
|
16 |
+
|
17 |
+
function scrape_insta_user_images($username) {
|
18 |
+
$insta_source = file_get_contents('https://www.instagram.com/'.$username.'/'); // instagram user url'
|
19 |
+
$shards = explode('window._sharedData = ', $insta_source);
|
20 |
+
$insta_json = explode(';</script>', $shards[1]);
|
21 |
+
$insta_array = json_decode($insta_json[0], TRUE);
|
22 |
+
return $insta_array; // this return a lot things print it and see what else you need
|
23 |
+
}
|
24 |
+
|
25 |
+
|
26 |
function blossomthemes_instagram_feed_sc(){
|
27 |
ob_start();
|
28 |
$options = get_option( 'blossomthemes_instagram_feed_settings', true );
|
|
|
29 |
if( !isset( $options['username'] ) || $options['username'] == '' )
|
30 |
{
|
31 |
return;
|
32 |
}
|
33 |
|
34 |
+
$photos = isset( $options['photos'] ) ? esc_attr( $options['photos'] ) :8;
|
|
|
35 |
$photos_row = isset( $options['photos_row'] ) ? esc_attr( $options['photos_row'] ) :'5';
|
36 |
+
|
37 |
+
$profile_link_text = isset( $options['follow_me'] ) ? esc_attr( $options['follow_me'] ):'Follow Me!';
|
38 |
+
$username = $options['username'];
|
39 |
+
$insta_source = file_get_contents('https://www.instagram.com/'.$username.'/'); // instagram user url'
|
40 |
+
$shards = explode('window._sharedData = ', $insta_source);
|
41 |
+
$results_array = $this->scrape_insta_user_images($username);
|
42 |
+
|
43 |
$instaUrl = 'https://www.instagram.com/';
|
44 |
$instaUrl .= $options['username'];
|
45 |
|
46 |
+
$limit = 6; // provide the limit thats important because one page only give some images.
|
47 |
+
$image_array= array(); // array to store images.
|
48 |
+
for ($i=0; $i < $limit; $i++) {
|
49 |
+
//new code to get images from json
|
50 |
+
if(isset($results_array['entry_data']['ProfilePage'][0]['graphql']['user']['edge_owner_to_timeline_media']['edges'][$i])){
|
51 |
+
$latest_array = $results_array['entry_data']['ProfilePage'][0]['graphql']['user']['edge_owner_to_timeline_media']['edges'][$i]['node'];
|
52 |
+
$image_data = $latest_array['thumbnail_src']; // thumbnail and same sizes
|
53 |
+
//$image_data = '<img src="'.$latest_array['display_src'].'">'; actual image and different sizes
|
54 |
+
array_push($image_array, $image_data);
|
55 |
+
}
|
56 |
+
}
|
57 |
+
|
58 |
echo '<ul class="popup-gallery photos-'.$photos_row.'">';
|
59 |
$i=0;
|
60 |
+
foreach ($image_array as $image) {
|
61 |
if( $i<$photos )
|
62 |
+
{ ?>
|
63 |
+
<li><a href="<?php echo strip_tags($image);?>"><img src="<?php echo $image;?>"></a></li>
|
64 |
+
<?php
|
|
|
|
|
|
|
|
|
65 |
}
|
66 |
$i++;
|
67 |
}
|
includes/vendor/InstagramSpider.php
CHANGED
@@ -1,18 +1,26 @@
|
|
1 |
<?php
|
2 |
|
3 |
/**
|
4 |
-
* Instagram Spider
|
5 |
* @author Karan Singh
|
6 |
-
* @version 1.
|
7 |
-
* @
|
|
|
8 |
*/
|
|
|
|
|
|
|
9 |
class InstagramSpider
|
10 |
{
|
11 |
|
12 |
protected $instagram;
|
13 |
|
|
|
|
|
|
|
14 |
public $messages;
|
15 |
|
|
|
16 |
public function __construct()
|
17 |
{
|
18 |
$this->instagram = 'https://www.instagram.com/';
|
@@ -25,7 +33,7 @@ class InstagramSpider
|
|
25 |
* @param string $username
|
26 |
* @return array
|
27 |
*/
|
28 |
-
function getUserItems($username = '')
|
29 |
{
|
30 |
$username = urlencode((string) $username); // non-english string support
|
31 |
if (empty($username)) {
|
@@ -33,45 +41,55 @@ class InstagramSpider
|
|
33 |
return;
|
34 |
}
|
35 |
|
36 |
-
$inURL = $this->instagram . $username . '
|
37 |
-
|
|
|
38 |
$instaRes = @json_decode($instaRes);
|
39 |
-
|
40 |
$items = array();
|
41 |
-
if (isset($instaRes->
|
42 |
-
$
|
43 |
|
44 |
-
if (! empty($
|
45 |
-
foreach ($
|
46 |
$items[] = array(
|
47 |
-
'img_standard' => $res->
|
48 |
-
'img_low' => $res->
|
49 |
-
'img_thumb' => $res->
|
50 |
'likes' => $res->likes->count,
|
51 |
'comments' => $res->comments->count,
|
52 |
-
'caption' => isset($res->caption
|
|
|
53 |
);
|
54 |
}
|
55 |
}
|
56 |
}
|
57 |
-
|
58 |
-
if
|
59 |
-
|
60 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
$instaRes = @json_decode($instaRes);
|
|
|
62 |
$items = array();
|
63 |
-
if (isset($instaRes->
|
64 |
-
$instaItems = $instaRes->
|
65 |
|
66 |
if (! empty($instaItems) && is_array($instaItems)) {
|
67 |
foreach ($instaItems as $res) {
|
68 |
$items[] = array(
|
69 |
-
'img_standard' => $res->
|
70 |
-
'img_low' => $res->
|
71 |
-
'img_thumb' => $res->
|
72 |
'likes' => $res->likes->count,
|
73 |
'comments' => $res->comments->count,
|
74 |
-
'caption' => isset($res->caption) ? htmlspecialchars($res->caption) : ''
|
75 |
);
|
76 |
}
|
77 |
}
|
@@ -84,9 +102,11 @@ class InstagramSpider
|
|
84 |
* takes #Tag name and return items list array
|
85 |
*
|
86 |
* @param string $tag
|
|
|
|
|
87 |
* @return array
|
88 |
*/
|
89 |
-
function getTagItems($tag = '')
|
90 |
{
|
91 |
$tag = urlencode((string) $tag);
|
92 |
if (empty($tag)) {
|
@@ -94,26 +114,109 @@ class InstagramSpider
|
|
94 |
return;
|
95 |
}
|
96 |
$inURL = $this->instagram . 'explore/tags/' . $tag . '/?__a=1';
|
97 |
-
$instaRes = $this->
|
98 |
$instaRes = json_decode($instaRes);
|
99 |
$items = array();
|
100 |
if (isset($instaRes->tag->media->nodes)) {
|
101 |
-
$instaRes = $instaRes->tag->media->nodes;
|
102 |
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
$items[] = array(
|
106 |
'img_standard' => $res->display_src,
|
107 |
'img_low' => $res->thumbnail_src,
|
108 |
-
'img_thumb' => str_replace('s640x640','s150x150'
|
109 |
'likes' => $res->likes->count,
|
110 |
'comments' => $res->comments->count,
|
111 |
-
'caption' => isset($res->caption) ? htmlspecialchars($res->caption) : ''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
);
|
113 |
}
|
114 |
}
|
115 |
}
|
116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
return $items;
|
118 |
}
|
119 |
|
@@ -123,7 +226,7 @@ class InstagramSpider
|
|
123 |
* @param string $url
|
124 |
* @return string
|
125 |
*/
|
126 |
-
|
127 |
{
|
128 |
if (empty($url) || (! filter_var($url, FILTER_VALIDATE_URL))) {
|
129 |
$this->messages[] = 'Please provide a Valid URL';
|
@@ -135,44 +238,25 @@ class InstagramSpider
|
|
135 |
if (function_exists('wp_remote_request')) {
|
136 |
$result = wp_remote_request($url);
|
137 |
if (is_wp_error($result)) {
|
138 |
-
|
139 |
-
// $this->messages[] = 'WP Error: ' . end($result->get_error_messages());
|
140 |
} else {
|
141 |
if (! empty($result['body'])) {
|
142 |
$instaItems = $result['body'];
|
143 |
}
|
144 |
}
|
|
|
|
|
145 |
}
|
146 |
|
147 |
-
|
148 |
-
|
149 |
-
if (function_exists('curl_version')) {
|
150 |
-
$ch = curl_init();
|
151 |
-
curl_setopt($ch, CURLOPT_URL, $url);
|
152 |
-
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
153 |
-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
154 |
-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
155 |
-
$contents = curl_exec($ch);
|
156 |
-
if (curl_error($ch)) {
|
157 |
-
$this->messages[] = 'error: ' . curl_error($ch);
|
158 |
-
}
|
159 |
-
curl_close($ch);
|
160 |
-
$instaItems = $contents;
|
161 |
-
} else {
|
162 |
-
if (ini_get('allow_url_fopen')) {
|
163 |
-
$instaItems = @file_get_contents($url);
|
164 |
-
} else {
|
165 |
-
$this->messages[] = 'Your server does\'t have enabled the required extensions/functions.';
|
166 |
-
}
|
167 |
-
}
|
168 |
-
}
|
169 |
return $instaItems;
|
170 |
}
|
171 |
|
172 |
// return messages array
|
173 |
public function getMessages()
|
174 |
{
|
175 |
-
return $this->messages;
|
176 |
}
|
177 |
}
|
178 |
|
1 |
<?php
|
2 |
|
3 |
/**
|
4 |
+
* Instagram Spider [MOD : WP - Insta Gallery]
|
5 |
* @author Karan Singh
|
6 |
+
* @version 1.3.6
|
7 |
+
* @depends RUSpider
|
8 |
+
* @description script to get instagram media by using Username and Tag-name. added WP (wp_remote_request) to run in WP.
|
9 |
*/
|
10 |
+
|
11 |
+
// loading dependencies
|
12 |
+
|
13 |
class InstagramSpider
|
14 |
{
|
15 |
|
16 |
protected $instagram;
|
17 |
|
18 |
+
// handle raw result from server, for further processing in your app
|
19 |
+
public $instagramResult;
|
20 |
+
|
21 |
public $messages;
|
22 |
|
23 |
+
|
24 |
public function __construct()
|
25 |
{
|
26 |
$this->instagram = 'https://www.instagram.com/';
|
33 |
* @param string $username
|
34 |
* @return array
|
35 |
*/
|
36 |
+
public function getUserItems($username = '')
|
37 |
{
|
38 |
$username = urlencode((string) $username); // non-english string support
|
39 |
if (empty($username)) {
|
41 |
return;
|
42 |
}
|
43 |
|
44 |
+
$inURL = $this->instagram . $username . '/?__a=1';
|
45 |
+
// For next 12 images, use ID of the last item (maxId = media.nodes[11].id) in the max_id param: /{USER_NAME}/?__a=1&max_id={maxId}
|
46 |
+
$instaRes = $this->igSpider($inURL);
|
47 |
$instaRes = @json_decode($instaRes);
|
|
|
48 |
$items = array();
|
49 |
+
if (isset($instaRes->user->media->nodes)) {
|
50 |
+
$instaItems = $instaRes->user->media->nodes;
|
51 |
|
52 |
+
if (! empty($instaItems) && is_array($instaItems)) {
|
53 |
+
foreach ($instaItems as $res) {
|
54 |
$items[] = array(
|
55 |
+
'img_standard' => $res->display_src,
|
56 |
+
'img_low' => $res->thumbnail_resources[4]->src,
|
57 |
+
'img_thumb' => $res->thumbnail_resources[0]->src,
|
58 |
'likes' => $res->likes->count,
|
59 |
'comments' => $res->comments->count,
|
60 |
+
'caption' => isset($res->caption) ? htmlspecialchars($res->caption) : '',
|
61 |
+
'code' => $res->code,
|
62 |
);
|
63 |
}
|
64 |
}
|
65 |
}
|
66 |
+
|
67 |
+
// if empty, continus with the next API : HTML
|
68 |
+
if (! empty($items)) {
|
69 |
+
$inURL = $this->instagram . $username . '/';
|
70 |
+
$items = $this->getFromHtmlAPI($inURL);
|
71 |
+
}
|
72 |
+
|
73 |
+
// if empty, continus with the next API
|
74 |
+
// removed API from Nov 2017
|
75 |
+
if (empty($items)) {
|
76 |
+
$inURL = $this->instagram . $username . '/media/';
|
77 |
+
$instaRes = $this->igSpider($inURL);
|
78 |
$instaRes = @json_decode($instaRes);
|
79 |
+
|
80 |
$items = array();
|
81 |
+
if (isset($instaRes->items)) {
|
82 |
+
$instaItems = $instaRes->items;
|
83 |
|
84 |
if (! empty($instaItems) && is_array($instaItems)) {
|
85 |
foreach ($instaItems as $res) {
|
86 |
$items[] = array(
|
87 |
+
'img_standard' => $res->images->standard_resolution->url,
|
88 |
+
'img_low' => $res->images->low_resolution->url,
|
89 |
+
'img_thumb' => $res->images->thumbnail->url,
|
90 |
'likes' => $res->likes->count,
|
91 |
'comments' => $res->comments->count,
|
92 |
+
'caption' => isset($res->caption->text) ? htmlspecialchars($res->caption->text) : ''
|
93 |
);
|
94 |
}
|
95 |
}
|
102 |
* takes #Tag name and return items list array
|
103 |
*
|
104 |
* @param string $tag
|
105 |
+
* @param
|
106 |
+
* boolean get top posts (10 posts)
|
107 |
* @return array
|
108 |
*/
|
109 |
+
public function getTagItems($tag = '', $getTopItems = false)
|
110 |
{
|
111 |
$tag = urlencode((string) $tag);
|
112 |
if (empty($tag)) {
|
114 |
return;
|
115 |
}
|
116 |
$inURL = $this->instagram . 'explore/tags/' . $tag . '/?__a=1';
|
117 |
+
$instaRes = $this->igSpider($inURL);
|
118 |
$instaRes = json_decode($instaRes);
|
119 |
$items = array();
|
120 |
if (isset($instaRes->tag->media->nodes)) {
|
|
|
121 |
|
122 |
+
$instaItems = $instaRes->tag->media->nodes;
|
123 |
+
if (empty($instaItems) && isset($instaRes->tag->top_posts->nodes)) {
|
124 |
+
$instaItems = $instaRes->tag->top_posts->nodes;
|
125 |
+
}
|
126 |
+
|
127 |
+
// get top posts
|
128 |
+
if ($getTopItems && isset($instaRes->tag->top_posts->nodes)) {
|
129 |
+
$instaItems = $instaRes->tag->top_posts->nodes;
|
130 |
+
}
|
131 |
+
|
132 |
+
if (! empty($instaItems) && is_array($instaItems)) {
|
133 |
+
foreach ($instaItems as $res) {
|
134 |
$items[] = array(
|
135 |
'img_standard' => $res->display_src,
|
136 |
'img_low' => $res->thumbnail_src,
|
137 |
+
'img_thumb' => str_replace('s640x640', 's150x150', $res->thumbnail_src),
|
138 |
'likes' => $res->likes->count,
|
139 |
'comments' => $res->comments->count,
|
140 |
+
'caption' => isset($res->caption) ? htmlspecialchars($res->caption) : ''
|
141 |
+
);
|
142 |
+
}
|
143 |
+
}
|
144 |
+
}
|
145 |
+
|
146 |
+
// continue to next API : API updated on Jan 03 17
|
147 |
+
if (empty($items) && isset($instaRes->graphql->hashtag->edge_hashtag_to_media->edges)) {
|
148 |
+
|
149 |
+
//$instaItems = $instaRes->tag->media->nodes;
|
150 |
+
$instaItems = $instaRes->graphql->hashtag->edge_hashtag_to_media->edges;
|
151 |
+
if (empty($instaItems) && isset($instaRes->tag->top_posts->nodes)) {
|
152 |
+
$instaItems = $instaRes->tag->top_posts->nodes;
|
153 |
+
}
|
154 |
+
|
155 |
+
// get top posts
|
156 |
+
if ($getTopItems && isset($instaRes->graphql->hashtag->edge_hashtag_to_top_posts->edges)) {
|
157 |
+
$instaItems = $instaRes->graphql->hashtag->edge_hashtag_to_top_posts->edges;
|
158 |
+
}
|
159 |
+
|
160 |
+
if (! empty($instaItems) && is_array($instaItems)) {
|
161 |
+
foreach ($instaItems as $res) {
|
162 |
+
$items[] = array(
|
163 |
+
'img_standard' => $res->node->display_url,
|
164 |
+
'img_low' => $res->node->thumbnail_src,
|
165 |
+
'img_thumb' => $res->node->thumbnail_resources[0]->src,
|
166 |
+
'likes' => $res->node->edge_liked_by->count,
|
167 |
+
'comments' => $res->node->edge_media_to_comment->count,
|
168 |
+
'caption' => isset($res->node->edge_media_to_caption->edges[0]->node->text) ? htmlspecialchars($res->node->edge_media_to_caption->edges[0]->node->text) : '',
|
169 |
+
'code' => $res->node->shortcode
|
170 |
);
|
171 |
}
|
172 |
}
|
173 |
}
|
174 |
|
175 |
+
// if empty, continus with the next API
|
176 |
+
if (empty($items)) {
|
177 |
+
$inURL = $this->instagram . 'explore/tags/' . $tag . '/';
|
178 |
+
$items = $this->getFromHtmlAPI($inURL);
|
179 |
+
}
|
180 |
+
return $items;
|
181 |
+
}
|
182 |
+
|
183 |
+
/**
|
184 |
+
* takes page URL and return items list array
|
185 |
+
*
|
186 |
+
* @param
|
187 |
+
* string url
|
188 |
+
* @return array
|
189 |
+
*/
|
190 |
+
protected function getFromHtmlAPI($inURL = '')
|
191 |
+
{
|
192 |
+
$instaRes = $this->igSpider($inURL);
|
193 |
+
$items = array();
|
194 |
+
if (! empty($instaRes)) {
|
195 |
+
$insta_json = explode('window._sharedData = ', $instaRes);
|
196 |
+
$insta_json = explode(';</script>', $insta_json[1]);
|
197 |
+
$instaArray = json_decode($insta_json[0], true);
|
198 |
+
|
199 |
+
$nodes = array();
|
200 |
+
if (isset($instaArray['entry_data']['ProfilePage'][0]['user']['media']['nodes'])) {
|
201 |
+
$nodes = $instaArray['entry_data']['ProfilePage'][0]['user']['media']['nodes'];
|
202 |
+
} else if (isset($instaArray['entry_data']['TagPage'][0]['tag']['media']['nodes'])) {
|
203 |
+
$nodes = $instaArray['entry_data']['TagPage'][0]['tag']['media']['nodes'];
|
204 |
+
}
|
205 |
+
if (! empty($nodes) && is_array($nodes)) {
|
206 |
+
foreach ($nodes as $node) {
|
207 |
+
$caption = (! empty($node['caption'])) ? $node['caption'] : '';
|
208 |
+
$items[] = array(
|
209 |
+
'img_standard' => $node['display_src'],
|
210 |
+
'img_low' => $node['thumbnail_src'],
|
211 |
+
'img_thumb' => $node['thumbnail_resources'][0]['src'],
|
212 |
+
'likes' => $node['likes']['count'],
|
213 |
+
'comments' => $node['comments']['count'],
|
214 |
+
'caption' => $caption,
|
215 |
+
'code' => $node['code']
|
216 |
+
);
|
217 |
+
}
|
218 |
+
}
|
219 |
+
}
|
220 |
return $items;
|
221 |
}
|
222 |
|
226 |
* @param string $url
|
227 |
* @return string
|
228 |
*/
|
229 |
+
public function igSpider($url = '')
|
230 |
{
|
231 |
if (empty($url) || (! filter_var($url, FILTER_VALIDATE_URL))) {
|
232 |
$this->messages[] = 'Please provide a Valid URL';
|
238 |
if (function_exists('wp_remote_request')) {
|
239 |
$result = wp_remote_request($url);
|
240 |
if (is_wp_error($result)) {
|
241 |
+
$this->messages[] = 'WP Error: ' . implode(', ',$result->get_error_messages());
|
|
|
242 |
} else {
|
243 |
if (! empty($result['body'])) {
|
244 |
$instaItems = $result['body'];
|
245 |
}
|
246 |
}
|
247 |
+
} else {
|
248 |
+
$this->messages[] = 'Error: running outside WP.';
|
249 |
}
|
250 |
|
251 |
+
|
252 |
+
$this->instagramResult = $instaItems;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
return $instaItems;
|
254 |
}
|
255 |
|
256 |
// return messages array
|
257 |
public function getMessages()
|
258 |
{
|
259 |
+
return array_unique($this->messages);
|
260 |
}
|
261 |
}
|
262 |
|
includes/widgets/widget-blossomthemes-instagram-feed.php
CHANGED
@@ -26,7 +26,13 @@ class BlossomThemes_Instagram_Widget extends WP_Widget {
|
|
26 |
array( 'description' => __( 'A Instagram Widget that displays your latest Instagram photos.', 'blossomthemes-instagram-feed' ), ) // Args
|
27 |
);
|
28 |
}
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
/**
|
31 |
* Front-end display of widget.
|
32 |
*
|
@@ -45,7 +51,6 @@ class BlossomThemes_Instagram_Widget extends WP_Widget {
|
|
45 |
$username = empty( $instance['username'] ) ? $options['username'] : $instance['username'];
|
46 |
$profile_link = 'https://www.instagram.com/'.$username ;
|
47 |
$profile_link_text = empty( $instance['profile_link_text'] ) ? 'Follow Me!' : $instance['profile_link_text'];
|
48 |
-
$meta = isset( $instance['meta'] ) ? 'true' : 'false';
|
49 |
|
50 |
echo $args['before_widget'];
|
51 |
|
@@ -53,24 +58,30 @@ class BlossomThemes_Instagram_Widget extends WP_Widget {
|
|
53 |
if ( $username != '' )
|
54 |
{
|
55 |
$ran = rand(1,100); $ran++;
|
56 |
-
require_once BTIF_BASE_PATH . '/includes/vendor/InstagramSpider.php';
|
57 |
ob_start();
|
58 |
-
$obj = new InstagramSpider;
|
59 |
$photos_row = isset( $per_row ) ? esc_attr( $per_row ) :'5';
|
60 |
-
$instaItems = $obj->getUserItems($username);
|
61 |
add_filter('widget_text','do_shortcode');
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
echo '<ul class="popup-gallery-'.$ran.' photos-'.$photos_row.'">';
|
64 |
$i=0;
|
65 |
-
foreach ($
|
66 |
if( $i<$limit )
|
67 |
-
{
|
68 |
-
|
69 |
-
|
70 |
-
{
|
71 |
-
echo '<span class="instagram-meta"><i class="fa fa-heart" aria-hidden="true">'.$key['likes'].'</i>'.'<i class="fa fa-comment" aria-hidden="true">'.$key['comments'].'</i>'.'</span>';
|
72 |
-
}
|
73 |
-
echo '</li>';
|
74 |
}
|
75 |
$i++;
|
76 |
}
|
@@ -128,7 +139,6 @@ class BlossomThemes_Instagram_Widget extends WP_Widget {
|
|
128 |
$per_row = empty( $instance['per_row'] ) ? 5 : $instance['per_row'];
|
129 |
$profile_link = 'https://www.instagram.com/'.$username;
|
130 |
$profile_link_text = empty( $instance['profile_link_text'] ) ? 'Follow Me!' : $instance['profile_link_text'];
|
131 |
-
$meta = !isset( $instance['meta'] ) ? '' : $instance['meta'];
|
132 |
?>
|
133 |
<p>
|
134 |
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title', 'blossomthemes-instagram-feed' ); ?></label>
|
@@ -189,7 +199,6 @@ class BlossomThemes_Instagram_Widget extends WP_Widget {
|
|
189 |
$instance['number'] = ! absint( $new_instance['number'] ) ? 6 : $new_instance['number'];
|
190 |
$instance['size'] = $new_instance['size'];
|
191 |
$instance['per_row'] = ! absint( $new_instance['per_row'] ) ? 5 : $new_instance['per_row'];
|
192 |
-
$instance['meta'] = $new_instance['meta'];
|
193 |
$instance['profile_link'] = 'https://www.instagram.com/'.$username;
|
194 |
$instance['username'] = $new_instance['username'] ;
|
195 |
|
26 |
array( 'description' => __( 'A Instagram Widget that displays your latest Instagram photos.', 'blossomthemes-instagram-feed' ), ) // Args
|
27 |
);
|
28 |
}
|
29 |
+
function scrape_insta_user_images($username) {
|
30 |
+
$insta_source = file_get_contents('https://www.instagram.com/'.$username.'/'); // instagram user url'
|
31 |
+
$shards = explode('window._sharedData = ', $insta_source);
|
32 |
+
$insta_json = explode(';</script>', $shards[1]);
|
33 |
+
$insta_array = json_decode($insta_json[0], TRUE);
|
34 |
+
return $insta_array; // this return a lot things print it and see what else you need
|
35 |
+
}
|
36 |
/**
|
37 |
* Front-end display of widget.
|
38 |
*
|
51 |
$username = empty( $instance['username'] ) ? $options['username'] : $instance['username'];
|
52 |
$profile_link = 'https://www.instagram.com/'.$username ;
|
53 |
$profile_link_text = empty( $instance['profile_link_text'] ) ? 'Follow Me!' : $instance['profile_link_text'];
|
|
|
54 |
|
55 |
echo $args['before_widget'];
|
56 |
|
58 |
if ( $username != '' )
|
59 |
{
|
60 |
$ran = rand(1,100); $ran++;
|
|
|
61 |
ob_start();
|
|
|
62 |
$photos_row = isset( $per_row ) ? esc_attr( $per_row ) :'5';
|
|
|
63 |
add_filter('widget_text','do_shortcode');
|
64 |
|
65 |
+
$results_array = $this->scrape_insta_user_images($username);
|
66 |
+
|
67 |
+
$image_array= array(); // array to store images.
|
68 |
+
for ($i=0; $i < $limit; $i++) {
|
69 |
+
//new code to get images from json
|
70 |
+
if(isset($results_array['entry_data']['ProfilePage'][0]['graphql']['user']['edge_owner_to_timeline_media']['edges'][$i])){
|
71 |
+
$latest_array = $results_array['entry_data']['ProfilePage'][0]['graphql']['user']['edge_owner_to_timeline_media']['edges'][$i]['node'];
|
72 |
+
$image_data = $latest_array['thumbnail_src']; // thumbnail and same sizes
|
73 |
+
//$image_data = '<img src="'.$latest_array['display_src'].'">'; actual image and different sizes
|
74 |
+
array_push($image_array, $image_data);
|
75 |
+
}
|
76 |
+
}
|
77 |
+
|
78 |
echo '<ul class="popup-gallery-'.$ran.' photos-'.$photos_row.'">';
|
79 |
$i=0;
|
80 |
+
foreach ($image_array as $key) {
|
81 |
if( $i<$limit )
|
82 |
+
{ ?>
|
83 |
+
<li><a href="<?php echo strip_tags($key);?>"><img src="<?php echo $key;?>"></a></li>
|
84 |
+
<?php
|
|
|
|
|
|
|
|
|
85 |
}
|
86 |
$i++;
|
87 |
}
|
139 |
$per_row = empty( $instance['per_row'] ) ? 5 : $instance['per_row'];
|
140 |
$profile_link = 'https://www.instagram.com/'.$username;
|
141 |
$profile_link_text = empty( $instance['profile_link_text'] ) ? 'Follow Me!' : $instance['profile_link_text'];
|
|
|
142 |
?>
|
143 |
<p>
|
144 |
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title', 'blossomthemes-instagram-feed' ); ?></label>
|
199 |
$instance['number'] = ! absint( $new_instance['number'] ) ? 6 : $new_instance['number'];
|
200 |
$instance['size'] = $new_instance['size'];
|
201 |
$instance['per_row'] = ! absint( $new_instance['per_row'] ) ? 5 : $new_instance['per_row'];
|
|
|
202 |
$instance['profile_link'] = 'https://www.instagram.com/'.$username;
|
203 |
$instance['username'] = $new_instance['username'] ;
|
204 |
|
public/css/blossomthemes-instagram-feed-public.css
CHANGED
@@ -56,6 +56,9 @@
|
|
56 |
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00000000', endColorstr='#a6000000',GradientType=0 ); /* IE6-9 */
|
57 |
}
|
58 |
|
|
|
|
|
|
|
59 |
.widget_btif_instagram_widget ul li:hover .instagram-meta{
|
60 |
opacity: 1;
|
61 |
}
|
56 |
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00000000', endColorstr='#a6000000',GradientType=0 ); /* IE6-9 */
|
57 |
}
|
58 |
|
59 |
+
.widget_btif_instagram_widget ul.photos-4 li .instagram-meta,
|
60 |
+
.widget_btif_instagram_widget ul.photos-5 li .instagram-meta{display: none;}
|
61 |
+
|
62 |
.widget_btif_instagram_widget ul li:hover .instagram-meta{
|
63 |
opacity: 1;
|
64 |
}
|