PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 4.0.5
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v4.0.5
4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / EmbedPress / Providers / InstagramFeed.php
embedpress / EmbedPress / Providers Last commit date
Boomplay.php 2 years ago Calendly.php 2 years ago Giphy.php 2 years ago GitHub.php 3 years ago GoogleDocs.php 2 years ago GoogleDrive.php 2 years ago GoogleMaps.php 2 years ago Gumroad.php 2 years ago InstagramFeed.php 2 years ago LinkedIn.php 2 years ago NRKRadio.php 2 years ago OpenSea.php 2 years ago SelfHosted.php 2 years ago TikTok.php 2 years ago Twitch.php 2 years ago Wrapper.php 3 years ago X.php 2 years ago Youtube.php 2 years ago index.html 7 years ago
InstagramFeed.php
694 lines
1 <?php
2
3 namespace EmbedPress\Providers;
4
5 use EmbedPress\Includes\Classes\Helper;
6 use Embera\Provider\ProviderAdapter;
7 use Embera\Provider\ProviderInterface;
8 use Embera\Provider\Instagram;
9 use Embera\Url;
10
11 (defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed.");
12
13 /**
14 * Entity responsible to support InstagramFeed embeds.
15 *
16 * @package EmbedPress
17 * @subpackage EmbedPress/Providers
18 * @author EmbedPress <help@embedpress.com>
19 * @copyright Copyright (C) 2020 WPDeveloper. All rights reserved.
20 * @license GPLv3 or later
21 * @since 1.0.0
22 */
23 class InstagramFeed extends Instagram
24 {
25 /** inline {@inheritdoc} */
26 protected $shouldSendRequest = false;
27
28 /**
29 * Method that verifies if the embed URL belongs to InstagramFeed.
30 *
31 * @param Url $url
32 * @return boolean
33 * @since 1.0.0
34 *
35 */
36
37 /** @var array Array with allowed params for the current Provider */
38 protected $allowedParams = [
39 'maxwidth',
40 'maxheight',
41 'instaLayout',
42 'instafeedColumns',
43 'instafeedColumnsGap',
44 'instafeedPostsPerPage',
45 'instafeedProfileImage',
46 'instafeedProfileImageUrl',
47 'instafeedTab',
48 'instafeedFollowBtn',
49 'instafeedFollowBtnLabel',
50 'instafeedPostsCount',
51 'instafeedPostsCountText',
52 'instafeedFollowersCount',
53 'instafeedFollowersCountText',
54 'instafeedAccName',
55 'instafeedPopup',
56 'instafeedPopupFollowBtn',
57 'instafeedPopupFollowBtnLabel',
58 'instafeedLoadmore',
59 'instafeedLoadmoreLabel',
60 'instafeedHashtag',
61 'instafeedAccountType',
62 'instafeedLikesCount',
63 'instafeedCommentsCount',
64 'instafeedFeedType',
65 'slidesShow',
66 'carouselSpacing'
67 ];
68
69 /** inline {@inheritdoc} */
70 protected $httpsSupport = true;
71
72 public function getAllowedParams()
73 {
74 return $this->allowedParams;
75 }
76
77 public function __construct($url, array $config = [])
78 {
79 parent::__construct($url, $config);
80 }
81
82
83
84 public function validateUrl(Url $url)
85 {
86 return
87 parent::validateUrl($url) ||
88 (bool) preg_match(
89 '/^(?:https?:\/\/)?(?:www\.)?instagram\.com\/(?:[a-zA-Z0-9_\.]+\/?|explore\/tags\/[a-zA-Z0-9_\-]+\/?)$/',
90 (string) $url
91 );
92 }
93
94 public function validateInstagramFeed($url)
95 {
96 return (bool) preg_match(
97 '/^(?:https?:\/\/)?(?:www\.)?instagram\.com\/(?:[a-zA-Z0-9_\.]+\/?|explore\/tags\/[a-zA-Z0-9_\-]+\/?)$/',
98 (string) $url
99 );
100 }
101
102
103
104
105 public function get_connected_account_type($userID)
106 {
107 $instagram_account_data = get_option('ep_instagram_account_data');
108
109 if (is_array($instagram_account_data) && !empty($instagram_account_data)) {
110 foreach ($instagram_account_data as $account) {
111 if ($account['user_id'] == $userID) {
112 return $account['account_type'];
113 }
114 }
115 }
116
117 return false;
118 }
119
120 public function getHashTag($url)
121 {
122 if (preg_match('/\/explore\/tags\/([a-zA-Z0-9_\-]+)/', parse_url($url, PHP_URL_PATH), $matches)) {
123 return $matches[1];
124 }
125 return '';
126 }
127
128 public function getHashTagId($access_token, $hashtag, $user_id)
129 {
130 $transient_key = 'hashtag_id_' . md5($access_token . $hashtag . $user_id);
131 $transient_data = get_transient($transient_key);
132
133 if (false === $transient_data) {
134 $api_url = "https://graph.facebook.com/v17.0/ig_hashtag_search?user_id=$user_id&q=$hashtag&access_token=$access_token";
135
136 // Make a GET request to Instagram's API to retrieve posts
137 $postsResponse = wp_remote_get($api_url);
138
139 // Check if the posts request was successful
140 if (is_wp_error($postsResponse)) {
141 echo 'Error: Unable to retrieve Instagram posts.';
142 } else {
143 $postsBody = wp_remote_retrieve_body($postsResponse);
144 $hashtagId = json_decode($postsBody, true);
145
146 if (empty($hashtagId['data'])) {
147 $transient_data = 'Please add Instagram Access Token';
148 } elseif (isset($hashtagId['data'][0]['id'])) {
149 $transient_data = $hashtagId['data'][0]['id'];
150 } else {
151 $transient_data = '';
152 }
153
154 // Set the transient with a 30-day expiration
155 set_transient($transient_key, $transient_data, 30 * DAY_IN_SECONDS);
156 }
157 }
158
159 return $transient_data;
160 }
161
162
163 public function getHashTagPosts($access_token, $hashtag, $user_id)
164 {
165 // Check if the data is already cached in a transient
166 $hashtag_id = $this->getHashTagId($access_token, $hashtag, $user_id);
167
168
169 $transient_key = 'hashtag_posts_' . $hashtag_id;
170
171 $cached_posts = get_transient($transient_key);
172
173 if (isset($cached_posts[$hashtag_id])) {
174 return $cached_posts[$hashtag_id];
175 }
176
177 $api_url = "https://graph.facebook.com/$hashtag_id/top_media?user_id=$user_id&fields=id,media_url,media_type,comments_count,like_count,caption,children{media_url,id,media_type},permalink,timestamp&access_token=$access_token";
178
179 $postsResponse = wp_remote_get($api_url, array('timeout' => 30));
180
181 if (is_wp_error($postsResponse)) {
182 echo 'Error: Unable to retrieve Hashtag Instagram posts.';
183 } else {
184 $postsBody = wp_remote_retrieve_body($postsResponse);
185 $posts = json_decode($postsBody, true);
186
187 if (empty($posts['data'])) {
188 return 'Please add Instagram Access Token';
189 }
190
191 // Update the cached posts array with the new data
192 $cached_posts[$hashtag_id] = $posts['data'];
193
194 // Store the updated array in the transient
195 set_transient($transient_key, $cached_posts, HOUR_IN_SECONDS);
196
197 return $cached_posts[$hashtag_id];
198 }
199 }
200
201
202 public function update_instagram_feed_data($access_token, $connected_account_type, $user_id, $limit = 100)
203 {
204 $option_key = 'ep_instagram_feed_data';
205 $feed_data = get_option($option_key, array());
206
207 $feed_userinfo = Helper::getInstagramUserInfo($access_token, $connected_account_type, $user_id, false);
208 $feed_posts = Helper::getInstagramPosts($access_token, $connected_account_type, $user_id, $limit, false);
209
210 $feed_data[$user_id] = [
211 'feed_userinfo' => $feed_userinfo,
212 'feed_posts' => $feed_posts,
213 ];
214
215 update_option($option_key, $feed_data);
216 // }
217 }
218
219
220
221 public function getInstaFeedItem($post, $index, $account_type, $hashtag, $profile_picture_url)
222 {
223 $params = $this->getParams();
224
225
226 $caption = !empty($post['caption']) ? $post['caption'] : '';
227 $media_type = !empty($post['media_type']) ? $post['media_type'] : '';
228 $media_url = !empty($post['media_url']) ? $post['media_url'] : '';
229 $permalink = !empty($post['permalink']) ? $post['permalink'] : '';
230 $timestamp = !empty($post['timestamp']) ? $post['timestamp'] : '';
231 $username = !empty($post['username']) ? $post['username'] : '';
232
233 $like_count = !empty($post['like_count']) ? $post['like_count'] : 0;
234 $comments_count = !empty($post['comments_count']) ? $post['comments_count'] : 0;
235
236 $connected_usersAttributes = 'data-caption="' . htmlspecialchars($caption) . '" ' .
237 'data-media-type="' . htmlspecialchars($media_type) . '" ' .
238 'data-media-type="' . htmlspecialchars($media_type) . '" ' .
239 'data-media-url="' . htmlspecialchars($media_url) . '" ' .
240 'data-permalink="' . htmlspecialchars($permalink) . '" ' .
241 'data-timestamp="' . htmlspecialchars($timestamp) . '" ' .
242 'data-username="' . htmlspecialchars($username) . '" ' . (($account_type === 'business') ? 'data-like-count="' . htmlspecialchars($like_count) . '" ' : '') . (($account_type === 'business') ? 'data-comments-count="' . htmlspecialchars($comments_count) . '" ' : '');
243
244 $post['account_type'] = $account_type;
245 $post['profile_picture_url'] = $profile_picture_url;
246 $post['show_likes_count'] = isset($params['instafeedLikesCount']) ? $params['instafeedLikesCount'] : false;
247 $post['show_comments_count'] = isset($params['instafeedCommentsCount']) ? $params['instafeedCommentsCount'] : false;
248 $post['popup_follow_button'] = isset($params['instafeedPopupFollowBtn']) ? $params['instafeedPopupFollowBtn'] : true;
249 $post['popup_follow_button_text'] = isset($params['instafeedPopupFollowBtnLabel']) ? $params['instafeedPopupFollowBtnLabel'] : 'Follow';
250
251 ob_start(); ?>
252 <div class="insta-gallery-item cg-carousel__slide js-carousel__slide" data-insta-postid="<?php echo esc_attr($post['id']) ?>" data-postindex="<?php echo esc_attr($index + 1); ?>" data-postdata="<?php echo htmlspecialchars(json_encode($post), ENT_QUOTES, 'UTF-8'); ?>" data-media-type="<?php echo esc_attr($media_type); ?>">
253 <?php
254 if (!empty($hashtag) && $media_type == 'CAROUSEL_ALBUM') {
255 if (isset($post['children']['data'][0]['media_url'])) {
256 $hashtag_media_url = $post['children']['data'][0]['media_url'];
257 $hashtag_media_type = $post['children']['data'][0]['media_type'];
258
259 if ($hashtag_media_type == 'VIDEO') {
260 echo '<video class="insta-gallery-image" src="' . esc_url($hashtag_media_url) . '"></video>';
261 } else {
262 echo ' <img class="insta-gallery-image" src="' . esc_url($hashtag_media_url) . '" alt="' . esc_attr('image') . '">';
263 }
264 }
265 } else {
266 if ($media_type == 'VIDEO') {
267 echo '<video class="insta-gallery-image" src="' . esc_url($media_url) . '"></video>';
268 } else {
269 echo ' <img class="insta-gallery-image" src="' . esc_url($media_url) . '" alt="' . esc_attr('image') . '">';
270 }
271 }
272
273 ?>
274
275 <div class="insta-gallery-item-type">
276 <div class="insta-gallery-item-type-icon">
277 <?php
278 if ($media_type == 'VIDEO') {
279 echo Helper::get_insta_video_icon();
280 } else if ($media_type == 'CAROUSEL_ALBUM') {
281 echo Helper::get_insta_image_carousel_icon();
282 } else {
283 echo Helper::get_insta_image_icon();
284 }
285 ?>
286 </div>
287 </div>
288 <div class="insta-gallery-item-info">
289 <?php if (Helper::is_pro_active() && (isset($params['instafeedFeedType']) && $params['instafeedFeedType'] === 'hashtag_type' || (isset($params['instafeedAccountType']) && strtolower($account_type) === 'business' && $params['instafeedAccountType'] === 'business') && ((!empty($params['instafeedLikesCount']) && $params['instafeedLikesCount'] !== 'false') || (!empty($params['instafeedLikesCount']) || $params['instafeedLikesCount'] !== 'false')))) : ?>
290 <div class="insta-item-reaction-count">
291 <?php if (!empty($params['instafeedLikesCount']) && $params['instafeedLikesCount'] !== 'false') : ?>
292 <div class="insta-gallery-item-likes">
293 <?php echo Helper::get_insta_like_icon();
294 echo esc_html($like_count); ?>
295 </div>
296 <?php endif; ?>
297 <?php if (!empty($params['instafeedCommentsCount']) && $params['instafeedCommentsCount'] !== 'false') : ?>
298 <div class="insta-gallery-item-comments">
299 <?php echo Helper::get_insta_comment_icon();
300 echo esc_html($comments_count); ?>
301 </div>
302 <?php endif; ?>
303 </div>
304 <?php else : ?>
305 <div class="insta-gallery-item-permalink">
306 <?php echo Helper::get_instagram_icon(); ?>
307 </div>
308 <?php endif; ?>
309 </div>
310 </div>
311
312 <?php $feed_item = ob_get_clean();
313 return $feed_item;
314 }
315
316 public function getInstagramFeedTemplate($accessToken, $account_type, $userID)
317 {
318 $params = $this->getParams();
319
320 $hashtag = $this->getHashTag($this->url);
321 if (!empty($hashtag) && !Helper::is_pro_active()) {
322 return sprintf(
323 esc_html__('Unlock %s support by upgrading to our %s! Upgrade today to unlock a whole new level of functionality and make the most out of your experience with Hashtag.', 'embedpress'),
324 '<strong>hashtag</strong>',
325 '<strong>Pro subscription</strong>'
326 );
327 }
328
329 $feed_type = isset($params['instafeedFeedType']) ? $params['instafeedFeedType'] : 'user_account_type';
330
331 if ($feed_type === 'user_account_type' && !empty($hashtag)) {
332 return 'Please add valid url for user account';
333 } else if ($feed_type === 'hashtag_type' && empty($hashtag)) {
334 return 'Please add valid url for hashtag feed';
335 } else if ($feed_type === 'mixed_type') {
336 return 'Please add valid url for hashtag feed';
337 } else if ($feed_type === 'tagged_type') {
338 return 'Please add valid url for hashtag feed';
339 }
340
341 $styleAttribute = '';
342
343 if (isset($params['instaLayout'])) {
344 if ($params['instaLayout'] === 'insta-grid') {
345
346
347 if (isset($params['instafeedColumns']) && is_numeric($params['instafeedColumns']) && $params['instafeedColumns'] > 0) {
348 $column = (100 / intval($params['instafeedColumns']));
349 $gap = isset($params['instafeedColumnsGap']) ? $params['instafeedColumnsGap'] : 0;
350
351 $styleAttribute = 'style="grid-template-columns: repeat(' . esc_attr($params['instafeedColumns']) . ', minmax(0, 1fr)); gap: ' . esc_attr($gap) . 'px;"';
352 } else {
353 $styleAttribute = 'style="grid-template-columns: repeat(1, minmax(0, 1fr));"';
354 }
355 } else if ($params['instaLayout'] === 'insta-masonry') {
356 $styleAttribute = 'style="column-count: ' . esc_attr($params['instafeedColumns']) . '; gap: ' . esc_attr(isset($params['instafeedColumnsGap']) ? $params['instafeedColumnsGap'] : 0) . 'px;"';
357 } else if ($params['instaLayout'] === 'insta-carousel') {
358 $styleAttribute = '';
359 if (isset($params['slidesShow'])) {
360 $column = (100 / intval($params['slidesShow']));
361 $space = isset($params['carouselSpacing']) ? $params['carouselSpacing'] : 0;
362 $styleAttribute = $styleAttribute = 'style="grid-auto-columns: calc(' . esc_attr($column) . '% - ' . esc_attr($space) . 'px); gap: ' . esc_attr($space) . 'px"'; // Or some default style
363 }
364 } else {
365 $styleAttribute = ''; // Or some default style
366 }
367 } else {
368 $styleAttribute = ''; // Or some default style
369 }
370
371
372 $feed_data = get_option('ep_instagram_feed_data');
373
374 // print_r($feed_data); die;
375
376 if (!empty($feed_data[$userID]['feed_userinfo']['error'])) {
377 return $feed_data[$userID]['feed_userinfo']['error']['message'];
378 }
379
380 $profile_info = $feed_data[$userID]['feed_userinfo'];
381 $insta_posts = $feed_data[$userID]['feed_posts'];
382
383 $hashtag_id = '';
384 if (!empty($hashtag)) {
385 $option_key = 'ep_instagram_hashtag_feed';
386 $hashtag_feed = get_option($option_key, array());
387
388 $hashtag_id = $this->getHashTagId($accessToken, $hashtag, $userID);
389 $insta_posts = $this->getHashtagPosts($accessToken, $hashtag, $userID);
390
391 $hashtag_feed[$hashtag_id] = $insta_posts;
392
393 update_option($option_key, $hashtag_feed);
394 }
395
396 // Check and assign each item to separate variables
397 $id = !empty($profile_info['id']) ? $profile_info['id'] : '';
398 $username = !empty($profile_info['username']) ? $profile_info['username'] : '';
399 $followers_count = !empty($profile_info['followers_count']) ? $profile_info['followers_count'] : 0;
400 $media_count = !empty($profile_info['media_count']) ? $profile_info['media_count'] : 0;
401 $profile_picture_url = !empty($profile_info['profile_picture_url']) ? $profile_info['profile_picture_url'] : '';
402 $name = !empty($profile_info['name']) ? $profile_info['name'] : '';
403
404
405 $connected_account_type = $account_type;
406
407 if (strtolower($connected_account_type) === 'business') {
408 $tkey = md5($accessToken . $id . $connected_account_type . $feed_type);
409 } else {
410 $tkey = md5($accessToken . $connected_account_type . $feed_type);
411 }
412
413 $loadmore_key = $hashtag_id;
414 if (empty($hashtag) || $hashtag === 'false') :
415 $loadmore_key = $userID;
416 endif;
417
418 if (is_array($insta_posts) and !empty($insta_posts)) {
419 ob_start(); ?>
420
421 <?php
422 $avater_url = 'http://2.gravatar.com/avatar/b642b4217b34b1e8d3bd915fc65c4452?s=150&d=mm&r=g';
423
424 if (!empty($connected_account_type) && (strtolower($connected_account_type) === 'business')) {
425 $avater_url = $profile_picture_url;
426 }
427 if (!empty($params['instafeedProfileImageUrl']) && $params['instafeedProfileImageUrl'] !== 'true' && $params['instafeedProfileImageUrl'] !== 'false') {
428 $avater_url = $params['instafeedProfileImageUrl'];
429 }
430
431 $feed_data[$id]['feed_userinfo']['profile_picture_url'] = $avater_url;
432
433 update_option('ep_instagram_feed_data', $feed_data);
434 ?>
435
436 <?php if (empty($hashtag) || $hashtag === 'false') : ?>
437 <header class="profile-header">
438
439 <?php if (!empty($params['instafeedProfileImage']) && $params['instafeedProfileImage'] !== 'false') : ?>
440 <div class="profile-image">
441 <img src="<?php echo esc_url($avater_url); ?>" alt="<?php echo esc_attr($name); ?>">
442 </div>
443 <?php endif; ?>
444 <section class="profile-details">
445 <div class="username-section">
446 <a class="profile-link" target="__blank" href="<?php echo esc_url('https://instagram.com/' . $username); ?>" role="link" tabindex="0">
447 <h2 class="username" dir="auto"><?php echo esc_html($username); ?></h2>
448 </a>
449
450 <?php if (!empty($params['instafeedFollowBtn']) && $params['instafeedFollowBtn'] !== 'false' && !empty($params['instafeedFollowBtnLabel']) && $params['instafeedFollowBtnLabel'] !== 'false' && $params['instafeedFollowBtnLabel'] !== 'true') : ?>
451 <div class="edit-profile-button">
452 <a class="edit-profile-link" target="__blank" href="<?php echo esc_url('https://instagram.com/' . $username); ?>" role="link" tabindex="0">
453 <?php echo esc_html($params['instafeedFollowBtnLabel']); ?>
454 </a>
455 </div>
456 <?php endif; ?>
457
458 </div>
459 <div class="profile-stats">
460 <?php if (!empty($params['instafeedPostsCount']) && $params['instafeedPostsCount'] !== 'false') : ?>
461 <div class="posts-count">
462 <?php if (!empty($params['instafeedPostsCountText']) && $params['instafeedPostsCountText'] !== 'false' && $params['instafeedPostsCountText'] !== 'true') :
463 $posts_count_text = str_replace('[count]', '<span class="count">' . $media_count . '</span>', $params['instafeedPostsCountText']);
464 echo wp_kses_post($posts_count_text);
465 endif;
466 ?>
467
468 </div>
469 <?php endif; ?>
470
471 <?php if (!empty($params['instafeedFollowersCount']) && $params['instafeedFollowersCount'] !== 'false' && $params['instafeedFollowersCountText'] !== 'true') : ?>
472 <?php if (strtolower($connected_account_type) !== 'personal') : ?>
473 <div class="followers-count">
474 <?php if (!empty($params['instafeedFollowersCountText']) && $params['instafeedFollowersCountText'] !== 'false' && $params['instafeedFollowersCountText'] !== 'true') : ?>
475 <a class="followers-link" target="_blank" href="<?php echo esc_url('https://instagram.com/' . $username . '/followers'); ?>" role="link" tabindex="0">
476 <?php
477 $followers_count_text = str_replace('[count]', '<span class="count">' . $followers_count . '</span>', $params['instafeedFollowersCountText']);
478
479 echo wp_kses_post($followers_count_text);
480 ?>
481 </a>
482 <?php endif; ?>
483 </div>
484 <?php endif; ?>
485 <?php endif; ?>
486 </div>
487 <?php if (!empty($params['instafeedAccName']) && $params['instafeedAccName'] !== 'false') : ?>
488 <div class="bio-section">
489 <span class="bio" dir="auto"><?php echo esc_attr($name); ?></span>
490 </div>
491 <?php endif; ?>
492 </section>
493 </header>
494 <?php else : ?>
495 <div class="hashtag-container">
496 <div class="embedpress-hashtag-header">
497
498 <?php if (!empty($params['instafeedProfileImage']) && $params['instafeedProfileImage'] !== 'false') : ?>
499
500 <div class="embedpress-hashtag-header-img"> <a target="_blank" href="<?php echo esc_url("https://www.instagram.com/explore/tags/$hashtag/"); ?>" class="embedpress-href"> <img decoding="async" loading="lazy" class="embedpress-hashtag-round" src="<?php echo esc_url($avater_url); ?>" width="30" height="30"> <span class="embedpress-hashtag-username"><?php echo esc_html("#$hashtag"); ?></span>
501 </a>
502 </div>
503 <?php endif; ?>
504
505 <?php if (!empty($params['instafeedFollowBtn']) && $params['instafeedFollowBtn'] !== 'false' && !empty($params['instafeedFollowBtnLabel']) && $params['instafeedFollowBtnLabel'] !== 'false') : ?>
506 <div class="insta-followbtn">
507 <a target="_new" href="<?php echo esc_url("https://www.instagram.com/explore/tags/$hashtag/"); ?>" type="button" class="btn btn-primary"><?php echo esc_html($params['instafeedFollowBtnLabel']); ?></a>
508 </div>
509 <?php endif; ?>
510 </div>
511 </div>
512 <?php endif; ?>
513
514 <?php if (Helper::is_pro_active() && (!empty($params['instafeedTab']) && $params['instafeedTab'] !== 'false')) : ?>
515 <div class="posts-tab-options">
516 <ul class="tabs">
517 <li data-media-type="ALL" class="active"><svg class="_ab6-" color="#000" height="20" viewBox="5 5 30 30" width="20">
518 <path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="3.3333333333333335" d="M5 5h30v30H5zm10.025 0v30m9.95 -30v30M35 15.025H5m30 9.95H5" /></svg>Posts</li>
519 <li data-media-type="VIDEO"><svg class="_ab6-" color="#000" height="20" viewBox="0 0 40 40" width="20">
520 <path fill="none" stroke="currentColor" stroke-linejoin="round" stroke-width="3.333" d="M3.415 11.67h33.168" />
521 <path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="3.333" d="m22.507 3.335 4.763 8.335M12.012 3.517l4.658 8.153M3.333 20.002v5.748c0 4.748 1.163 6.677 2.677 8.242 1.567 1.513 3.497 2.678 8.243 2.678h11.493c4.747 0 6.677-1.165 8.243-2.678 1.513-1.565 2.677-3.493 2.677-8.242V14.253c0-4.747-1.163-6.677-2.677-8.242-1.566-1.513-3.496-2.678-8.242-2.678H14.253c-4.747 0-6.677 1.165-8.243 2.678-1.513 1.566-2.677 3.496-2.677 8.242Z" />
522 <path class="fill-color" d="M16.272 29.44a1.513 1.513 0 0 1-.757-1.312v-8.745a1.515 1.515 0 0 1 2.273-1.313l7.575 4.373a1.515 1.515 0 0 1 0 2.625l-7.575 4.373a1.517 1.517 0 0 1-1.517 0Z" fill-rule="evenodd" /></svg>Reels</li>
523 <li data-media-type="CAROUSEL_ALBUM"><svg aria-label="Carousel" class="x1lliihq x1n2onr6" color="#000" height="20" viewBox="0 0 43.636 43.636" width="20">
524 <path class="fill-color" d="M31.636 27V10a4.695 4.695 0 0 0-4.727-4.727H10A4.695 4.695 0 0 0 5.273 10v17A4.695 4.695 0 0 0 10 31.727h17c2.545-.091 4.636-2.182 4.636-4.727zm4-13.364v14.636c0 4.091-3.364 7.455-7.455 7.455H13.545c-.545 0-.818.636-.455 1 .909 1 2.182 1.636 3.727 1.636h12.182a9.35 9.35 0 0 0 9.364-9.364V16.818a5.076 5.076 0 0 0-1.636-3.727c-.455-.364-1.091 0-1.091.545z" /></svg>Album</li>
525 </ul>
526 </div>
527 <?php endif; ?>
528
529 <?php
530 $params_data = [
531 'show_likes_count' => isset($params['instafeedLikesCount']) ? $params['instafeedLikesCount'] : false,
532 'show_comments_count' => isset($params['instafeedCommentsCount']) ? $params['instafeedCommentsCount'] : false,
533 'popup_follow_button' => isset($params['instafeedPopupFollowBtn']) ? $params['instafeedPopupFollowBtn'] : true,
534 'popup_follow_button_text' => isset($params['instafeedPopupFollowBtnLabel']) ? $params['instafeedPopupFollowBtnLabel'] : 'Follow'
535 ];
536
537 $params_data_json = json_encode($params_data);
538
539 ?>
540
541 <div class="instagram-container" data-feed-type="<?php echo esc_attr($feed_type); ?>" data-hashtag="<?php echo esc_attr($hashtag); ?>" data-hashtag-id="<?php echo esc_attr($hashtag_id); ?>" data-connected-acc-type="<?php echo esc_attr($connected_account_type); ?>" data-uid="<?php echo esc_attr($userID); ?>" data-params="<?php echo htmlspecialchars($params_data_json, ENT_QUOTES, 'UTF-8'); ?>">
542 <div class="embedpress-insta-container">
543 <div class="insta-gallery cg-carousel__track js-carousel__track" <?php echo $styleAttribute; ?>>
544 <?php
545 $posts_per_page = 12;
546
547 if (!empty($params['instafeedPostsPerPage'])) {
548 $posts_per_page = $params['instafeedPostsPerPage'];
549 }
550 // Set the limit to 5
551 $counter = 0; // Initialize a counter variable
552
553 foreach ($insta_posts as $index => $post) {
554 if ($counter >= $posts_per_page) {
555 break; // Exit the loop when the counter reaches the limit
556 }
557 print_r($this->getInstaFeedItem($post, $index, $connected_account_type, $hashtag, $avater_url));
558
559 $counter++; // Increment the counter for each processed item
560 }
561 ?>
562 </div>
563 <div class="cg-carousel__btns hidden">
564 <button class="cg-carousel__btn" id="js-carousel__prev-1"><svg width="20" height="30" viewBox="-5 0 23 23" xmlns="http://www.w3.org/2000/svg">
565 <path d="M11.24.29.361 10.742l-.06.054a.97.97 0 0 0-.301.642v.124a.97.97 0 0 0 .3.642l.054.044L11.239 22.71a1.061 1.061 0 0 0 1.459 0 .964.964 0 0 0 0-1.402l-10.15-9.746 10.15-9.87a.964.964 0 0 0 0-1.402 1.061 1.061 0 0 0-1.459 0Z" fill="#fff" /></svg></button>
566
567 <button class="cg-carousel__btn" id="js-carousel__next-1"><svg width="20" height="30" viewBox="-5 0 23 23" xmlns="http://www.w3.org/2000/svg">
568 <path d="m1.76.29 10.879 10.452.06.054a.97.97 0 0 1 .301.642v.124a.97.97 0 0 1-.3.642l-.054.044L1.761 22.71a1.061 1.061 0 0 1-1.459 0 .964.964 0 0 1 0-1.402l10.15-9.746-10.15-9.87a.964.964 0 0 1 0-1.402 1.061 1.061 0 0 1 1.459 0Z" fill="#fff" /></svg></button>
569 </div>
570 </div>
571
572 <!-- Popup div -->
573 <?php if (!empty($params['instafeedPopup']) && $params['instafeedPopup'] !== 'false') : ?>
574 <div class="insta-popup" style="display: none;">
575 <div class="popup-wrapper popup-is-opened">
576 <div class="popup popup-is-initialized" tabindex="-1"> </div>
577 <div class="popup-close"></div>
578 </div>
579 </div>
580 <?php endif; ?>
581
582 <?php if (!empty($params['instafeedLoadmore']) && $params['instafeedLoadmore'] !== 'false') : ?>
583
584
585 <?php if (count($insta_posts) > $posts_per_page && $params['instafeedLoadmoreLabel'] !== 'false' && $params['instafeedLoadmoreLabel'] !== 'true') : ?>
586 <div class="load-more-button-container" data-loadmorekey="<?php echo esc_attr($loadmore_key); ?>" data-loaded-posts="<?php echo esc_attr($posts_per_page); ?>" data-posts-per-page="<?php echo esc_attr($posts_per_page); ?>">
587 <button class="insta-load-more-button">
588 <?php echo !empty($params['instafeedLoadmoreLabel']) ? esc_html($params['instafeedLoadmoreLabel']) : ''; ?>
589 </button>
590 </div>
591 <?php endif; ?>
592 <?php endif; ?>
593
594 </div>
595
596
597 <?php
598 $feed_template = ob_get_clean();
599 return $feed_template;
600 }
601 }
602
603 public function getInstagramUnserName($url)
604 {
605 $pattern = '/instagram\.com\/([^\/?]+)/i';
606 preg_match($pattern, $url, $matches);
607 return isset($matches[1]) ? $matches[1] : '';
608 }
609
610
611 public function getStaticResponse()
612 {
613 $url = $this->getUrl();
614
615 if (parent::validateUrl($this->url)) {
616 return parent::getStaticResponse();
617 }
618
619 $insta_feed = [
620 "title" => "Unknown Title",
621 "type" => "video",
622 'provider_name' => 'Instagram Feed',
623 "provider_url" => 'https://instagram.com',
624 'html' => "",
625 ];
626
627 $connected_users = get_option('ep_instagram_account_data');
628
629
630 $username = $this->getInstagramUnserName($url) ? $this->getInstagramUnserName($url) : '';
631
632 if ($this->validateInstagramFeed($url) && $this->getHashTag($url)) {
633 foreach ($connected_users as $entry) {
634 if ($entry['account_type'] === 'business') {
635 $businessUsernames[] = $entry['username'];
636 $username = $businessUsernames[0];
637 }
638 }
639 }
640
641
642 $access_token = ''; // The access token';
643 $account_type = '';
644 $userid = '';
645
646 if ($this->validateInstagramFeed($url) || !empty($username)) {
647 if (!empty($username)) {
648
649 if (empty($connected_users)) {
650 $connected_users = [];
651 }
652
653 // Find the key of the matching username
654 $index = array_search($username, array_column($connected_users, 'username'));
655
656 if ($index !== false) {
657 // Matching username found
658 $access_token = $connected_users[$index]['access_token'];
659 $userid = $connected_users[$index]['user_id'];
660 $account_type = $connected_users[$index]['account_type'];
661 // <a href="' . esc_url($page) . '">here</a>
662 } else {
663 // No matching username found
664 $page = site_url() . "/wp-admin/admin.php?page=embedpress&page_type=instagram";
665 $insta_feed['html'] = '<p style="text-align:center;height:100%;display:flex;justify-content:center;align-items:center;margin:0;flex-direction: column;">To enable full Instagram embedding experience, please add your access token by navigating to: <b>Dashboard > EmbedPress > Settings > Sources > Instagram</></p>';
666 return $insta_feed;
667 }
668 }
669
670 $this->update_instagram_feed_data($access_token, $account_type, $userid, $limit = 100);
671
672 if ($this->getInstagramFeedTemplate($access_token, $account_type, $userid)) {
673 $insta_feed['html'] = $this->getInstagramFeedTemplate($access_token, $account_type, $userid);
674 }
675 }
676
677
678 return $insta_feed;
679 }
680
681
682 /** inline {@inheritdoc} */
683 public function getFakeResponse()
684 {
685 return [
686 'type' => 'video',
687 'provider_name' => 'Instagram Feed',
688 'provider_url' => 'https://instagram.com',
689 'title' => 'Unknown title',
690 'html' => '',
691 ];
692 }
693 }
694