PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 4.1.10
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v4.1.10
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
TemplateLayouts 1 year ago AirTable.php 1 year ago Boomplay.php 1 year 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 GooglePhotos.php 1 year ago Gumroad.php 2 years ago InstagramFeed.php 1 year ago LinkedIn.php 2 years ago NRKRadio.php 2 years ago OpenSea.php 2 years ago SelfHosted.php 2 years ago Spreaker.php 1 year ago TikTok.php 2 years ago Twitch.php 2 years ago Wrapper.php 3 years ago X.php 2 years ago Youtube.php 1 year ago index.html 7 years ago
InstagramFeed.php
705 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
24
25 class InstagramFeed extends Instagram
26 {
27 /** inline {@inheritdoc} */
28 protected $shouldSendRequest = false;
29
30 /**
31 * Method that verifies if the embed URL belongs to InstagramFeed.
32 *
33 * @param Url $url
34 * @return boolean
35 * @since 1.0.0
36 *
37 */
38
39 /** @var array Array with allowed params for the current Provider */
40 protected $allowedParams = [
41 'maxwidth',
42 'maxheight',
43 'instaLayout',
44 'instafeedColumns',
45 'instafeedColumnsGap',
46 'instafeedPostsPerPage',
47 'instafeedProfileImage',
48 'instafeedProfileImageUrl',
49 'instafeedTab',
50 'instafeedFollowBtn',
51 'instafeedFollowBtnLabel',
52 'instafeedPostsCount',
53 'instafeedPostsCountText',
54 'instafeedFollowersCount',
55 'instafeedFollowersCountText',
56 'instafeedAccName',
57 'instafeedPopup',
58 'instafeedPopupFollowBtn',
59 'instafeedPopupFollowBtnLabel',
60 'instafeedLoadmore',
61 'instafeedLoadmoreLabel',
62 'instafeedHashtag',
63 'instafeedAccountType',
64 'instafeedLikesCount',
65 'instafeedCommentsCount',
66 'instafeedFeedType',
67 'slidesShow',
68 'carouselSpacing'
69 ];
70
71 /** inline {@inheritdoc} */
72 protected $httpsSupport = true;
73
74 public function getAllowedParams()
75 {
76 return $this->allowedParams;
77 }
78
79 public function __construct($url, array $config = [])
80 {
81 parent::__construct($url, $config);
82
83 if ($this->validateReelUrl($url)) {
84 add_action('wp_footer', [$this, 'enqueue_instagram_script'], 100);
85 }
86 }
87
88
89
90 public function validateUrl(Url $url)
91 {
92 return
93 parent::validateUrl($url) ||
94 (bool) preg_match(
95 '/^(?:https?:\/\/)?(?:www\.)?instagram\.com\/(?:[a-zA-Z0-9_\.]+\/?|explore\/tags\/[a-zA-Z0-9_\-]+\/?|(?:reel|p)\/[a-zA-Z0-9_-]+\/?)$/',
96 (string) $url
97 );
98 }
99
100
101 public function validateInstagramFeed($url)
102 {
103 return (bool) preg_match(
104 '/^(?:https?:\/\/)?(?:www\.)?instagram\.com\/(?:[a-zA-Z0-9_\.]+\/?|explore\/tags\/[a-zA-Z0-9_\-]+\/?)$/',
105 (string) $url
106 );
107 }
108
109
110 public function validateReelUrl($url)
111 {
112 return (bool) preg_match(
113 '/^(?:https?:\/\/)?(?:www\.)?instagram\.com\/(?:reel|p)\/[a-zA-Z0-9_-]+\/?$/',
114 (string) $url
115 );
116 }
117 function enqueue_instagram_script()
118 {
119 static $script_loaded = false;
120
121 if (!$script_loaded) {
122 echo '<script async src="https://www.instagram.com/embed.js"></script>';
123 $script_loaded = true;
124 }
125 }
126
127 public function get_connected_account_type($userID)
128 {
129 $instagram_account_data = get_option('ep_instagram_account_data');
130
131 if (is_array($instagram_account_data) && !empty($instagram_account_data)) {
132 foreach ($instagram_account_data as $account) {
133 if ($account['user_id'] == $userID) {
134 return $account['account_type'];
135 }
136 }
137 }
138
139 return false;
140 }
141
142 public function getHashTag($url)
143 {
144 if (preg_match('/\/explore\/tags\/([a-zA-Z0-9_\-]+)/', parse_url($url, PHP_URL_PATH), $matches)) {
145 return $matches[1];
146 }
147 return '';
148 }
149
150 public function getHashTagId($access_token, $hashtag, $user_id)
151 {
152 $transient_key = 'hashtag_id_' . md5($access_token . $hashtag . $user_id);
153 $transient_data = get_transient($transient_key);
154
155 if (false === $transient_data) {
156 $api_url = "https://graph.facebook.com/v17.0/ig_hashtag_search?user_id=$user_id&q=$hashtag&access_token=$access_token";
157
158 // Make a GET request to Instagram's API to retrieve posts
159 $postsResponse = wp_remote_get($api_url);
160
161 // Check if the posts request was successful
162 if (is_wp_error($postsResponse)) {
163 echo 'Error: Unable to retrieve Instagram posts.';
164 } else {
165 $postsBody = wp_remote_retrieve_body($postsResponse);
166 $hashtagId = json_decode($postsBody, true);
167
168 if (empty($hashtagId['data'])) {
169 $transient_data = 'Please add Instagram Access Token';
170 } elseif (isset($hashtagId['data'][0]['id'])) {
171 $transient_data = $hashtagId['data'][0]['id'];
172 } else {
173 $transient_data = '';
174 }
175
176 // Set the transient with a 30-day expiration
177 set_transient($transient_key, $transient_data, 30 * DAY_IN_SECONDS);
178 }
179 }
180
181 return $transient_data;
182 }
183
184
185 public function getHashTagPosts($access_token, $hashtag, $user_id)
186 {
187 // Check if the data is already cached in a transient
188 $hashtag_id = $this->getHashTagId($access_token, $hashtag, $user_id);
189
190
191 $transient_key = 'hashtag_posts_' . $hashtag_id;
192
193 $cached_posts = get_transient($transient_key);
194
195 if (isset($cached_posts[$hashtag_id])) {
196 return $cached_posts[$hashtag_id];
197 }
198
199 $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";
200
201 $postsResponse = wp_remote_get($api_url, array('timeout' => 30));
202
203 if (is_wp_error($postsResponse)) {
204 echo 'Error: Unable to retrieve Hashtag Instagram posts.';
205 } else {
206 $postsBody = wp_remote_retrieve_body($postsResponse);
207 $posts = json_decode($postsBody, true);
208
209 if (empty($posts['data'])) {
210 return 'Please add Instagram Access Token';
211 }
212
213 // Update the cached posts array with the new data
214 $cached_posts[$hashtag_id] = $posts['data'];
215
216 // Store the updated array in the transient
217 set_transient($transient_key, $cached_posts, HOUR_IN_SECONDS);
218
219 return $cached_posts[$hashtag_id];
220 }
221 }
222
223
224 public function update_instagram_feed_data($access_token, $connected_account_type, $user_id, $limit = 100)
225 {
226 $option_key = 'ep_instagram_feed_data';
227 $feed_data = get_option($option_key, array());
228
229 $feed_userinfo = Helper::getInstagramUserInfo($access_token, $connected_account_type, $user_id, false);
230 $feed_posts = Helper::getInstagramPosts($access_token, $connected_account_type, $user_id, $limit, false);
231
232 $feed_data[$user_id] = [
233 'feed_userinfo' => $feed_userinfo,
234 'feed_posts' => $feed_posts,
235 ];
236
237 update_option($option_key, $feed_data);
238 // }
239 }
240
241
242
243 public function getInstaFeedItem($post, $index, $account_type, $hashtag, $profile_picture_url)
244 {
245 $params = $this->getParams();
246
247
248 $caption = !empty($post['caption']) ? $post['caption'] : '';
249 $media_type = !empty($post['media_type']) ? $post['media_type'] : '';
250 $media_url = !empty($post['media_url']) ? $post['media_url'] : '';
251 $permalink = !empty($post['permalink']) ? $post['permalink'] : '';
252 $timestamp = !empty($post['timestamp']) ? $post['timestamp'] : '';
253 $username = !empty($post['username']) ? $post['username'] : '';
254
255 $like_count = !empty($post['like_count']) ? $post['like_count'] : 0;
256 $comments_count = !empty($post['comments_count']) ? $post['comments_count'] : 0;
257
258 $connected_usersAttributes = 'data-caption="' . htmlspecialchars($caption) . '" ' .
259 'data-media-type="' . htmlspecialchars($media_type) . '" ' .
260 'data-media-type="' . htmlspecialchars($media_type) . '" ' .
261 'data-media-url="' . htmlspecialchars($media_url) . '" ' .
262 'data-permalink="' . htmlspecialchars($permalink) . '" ' .
263 'data-timestamp="' . htmlspecialchars($timestamp) . '" ' .
264 'data-username="' . htmlspecialchars($username) . '" ' . (($account_type === 'business') ? 'data-like-count="' . htmlspecialchars($like_count) . '" ' : '') . (($account_type === 'business') ? 'data-comments-count="' . htmlspecialchars($comments_count) . '" ' : '');
265
266 $post['account_type'] = $account_type;
267 $post['profile_picture_url'] = $profile_picture_url;
268 $post['show_likes_count'] = isset($params['instafeedLikesCount']) ? $params['instafeedLikesCount'] : false;
269 $post['show_comments_count'] = isset($params['instafeedCommentsCount']) ? $params['instafeedCommentsCount'] : false;
270 $post['popup_follow_button'] = isset($params['instafeedPopupFollowBtn']) ? $params['instafeedPopupFollowBtn'] : true;
271 $post['popup_follow_button_text'] = isset($params['instafeedPopupFollowBtnLabel']) ? $params['instafeedPopupFollowBtnLabel'] : 'Follow';
272
273 ob_start(); ?>
274 <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); ?>">
275 <?php
276 if (!empty($hashtag) && $media_type == 'CAROUSEL_ALBUM') {
277 if (isset($post['children']['data'][0]['media_url'])) {
278 $hashtag_media_url = $post['children']['data'][0]['media_url'];
279 $hashtag_media_type = $post['children']['data'][0]['media_type'];
280
281 if ($hashtag_media_type == 'VIDEO') {
282 echo '<video class="insta-gallery-image" src="' . esc_url($hashtag_media_url) . '"></video>';
283 } else {
284 echo ' <img class="insta-gallery-image" src="' . esc_url($hashtag_media_url) . '" alt="' . esc_attr('image') . '">';
285 }
286 }
287 } else {
288 if ($media_type == 'VIDEO') {
289 echo '<video class="insta-gallery-image" src="' . esc_url($media_url) . '"></video>';
290 } else {
291 echo ' <img class="insta-gallery-image" src="' . esc_url($media_url) . '" alt="' . esc_attr('image') . '">';
292 }
293 }
294
295 ?>
296
297 <div class="insta-gallery-item-type">
298 <div class="insta-gallery-item-type-icon">
299 <?php
300 if ($media_type == 'VIDEO') {
301 echo Helper::get_insta_video_icon();
302 } else if ($media_type == 'CAROUSEL_ALBUM') {
303 echo Helper::get_insta_image_carousel_icon();
304 } else {
305 echo Helper::get_insta_image_icon();
306 }
307 ?>
308 </div>
309 </div>
310 <div class="insta-gallery-item-info">
311 <?php if (apply_filters('embedpress/is_allow_rander', false) && (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')))) : ?>
312 <?php do_action('embedpress/instafeed_reaction_count', $params, $like_count, $comments_count); ?>
313 <?php else : ?>
314 <div class="insta-gallery-item-permalink">
315 <?php echo Helper::get_instagram_icon(); ?>
316 </div>
317 <?php endif; ?>
318 </div>
319 </div>
320
321 <?php $feed_item = ob_get_clean();
322 return $feed_item;
323 }
324
325 public function getInstagramFeedTemplate($accessToken, $account_type, $userID)
326 {
327 $params = $this->getParams();
328
329 $hashtag = $this->getHashTag($this->url);
330 if (!empty($hashtag) && !apply_filters('embedpress/is_allow_rander', false)) {
331 return sprintf(
332 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'),
333 '<strong>hashtag</strong>',
334 '<strong>Pro subscription</strong>'
335 );
336 }
337
338 $feed_type = isset($params['instafeedFeedType']) ? $params['instafeedFeedType'] : 'user_account_type';
339
340 if ($feed_type === 'user_account_type' && !empty($hashtag)) {
341 return 'Please add valid url for user account';
342 } else if ($feed_type === 'hashtag_type' && empty($hashtag)) {
343 return 'Please add valid url for hashtag feed';
344 } else if ($feed_type === 'mixed_type') {
345 return 'Please add valid url for hashtag feed';
346 } else if ($feed_type === 'tagged_type') {
347 return 'Please add valid url for hashtag feed';
348 }
349
350 $styleAttribute = '';
351
352 if (isset($params['instaLayout'])) {
353 if ($params['instaLayout'] === 'insta-grid') {
354
355
356 if (isset($params['instafeedColumns']) && is_numeric($params['instafeedColumns']) && $params['instafeedColumns'] > 0) {
357 $column = (100 / intval($params['instafeedColumns']));
358 $gap = isset($params['instafeedColumnsGap']) ? $params['instafeedColumnsGap'] : 0;
359
360 $styleAttribute = 'style="grid-template-columns: repeat(' . esc_attr($params['instafeedColumns']) . ', minmax(0, 1fr)); gap: ' . esc_attr($gap) . 'px;"';
361 } else {
362 $styleAttribute = 'style="grid-template-columns: repeat(1, minmax(0, 1fr));"';
363 }
364 } else if ($params['instaLayout'] === 'insta-masonry') {
365 $styleAttribute = 'style="column-count: ' . esc_attr($params['instafeedColumns']) . '; gap: ' . esc_attr(isset($params['instafeedColumnsGap']) ? $params['instafeedColumnsGap'] : 0) . 'px;"';
366 } else if ($params['instaLayout'] === 'insta-carousel') {
367 $styleAttribute = '';
368 if (isset($params['slidesShow'])) {
369 $column = (100 / intval($params['slidesShow']));
370 $space = isset($params['carouselSpacing']) ? $params['carouselSpacing'] : 0;
371 $styleAttribute = $styleAttribute = 'style="grid-auto-columns: calc(' . esc_attr($column) . '% - ' . esc_attr($space) . 'px); gap: ' . esc_attr($space) . 'px"'; // Or some default style
372 }
373 } else {
374 $styleAttribute = ''; // Or some default style
375 }
376 } else {
377 $styleAttribute = ''; // Or some default style
378 }
379
380
381 $feed_data = get_option('ep_instagram_feed_data');
382
383 // print_r($feed_data); die;
384
385 if (!empty($feed_data[$userID]['feed_userinfo']['error'])) {
386 return $feed_data[$userID]['feed_userinfo']['error']['message'];
387 }
388
389 $profile_info = $feed_data[$userID]['feed_userinfo'];
390 $insta_posts = $feed_data[$userID]['feed_posts'];
391
392 $hashtag_id = '';
393 if (!empty($hashtag)) {
394 $option_key = 'ep_instagram_hashtag_feed';
395 $hashtag_feed = get_option($option_key, array());
396
397 $hashtag_id = $this->getHashTagId($accessToken, $hashtag, $userID);
398 $insta_posts = $this->getHashtagPosts($accessToken, $hashtag, $userID);
399
400 $hashtag_feed[$hashtag_id] = $insta_posts;
401
402 update_option($option_key, $hashtag_feed);
403 }
404
405 // Check and assign each item to separate variables
406 $id = !empty($profile_info['id']) ? $profile_info['id'] : '';
407 $username = !empty($profile_info['username']) ? $profile_info['username'] : '';
408 $followers_count = !empty($profile_info['followers_count']) ? $profile_info['followers_count'] : 0;
409 $media_count = !empty($profile_info['media_count']) ? $profile_info['media_count'] : 0;
410 $profile_picture_url = !empty($profile_info['profile_picture_url']) ? $profile_info['profile_picture_url'] : '';
411 $name = !empty($profile_info['name']) ? $profile_info['name'] : '';
412
413
414 $connected_account_type = $account_type;
415
416 if (strtolower($connected_account_type) === 'business') {
417 $tkey = md5($accessToken . $id . $connected_account_type . $feed_type);
418 } else {
419 $tkey = md5($accessToken . $connected_account_type . $feed_type);
420 }
421
422 $loadmore_key = $hashtag_id;
423 if (empty($hashtag) || $hashtag === 'false') :
424 $loadmore_key = $userID;
425 endif;
426
427 if (is_array($insta_posts) and !empty($insta_posts)) {
428 ob_start(); ?>
429
430 <?php
431 $avater_url = 'http://2.gravatar.com/avatar/b642b4217b34b1e8d3bd915fc65c4452?s=150&d=mm&r=g';
432
433 if (!empty($connected_account_type) && (strtolower($connected_account_type) === 'business')) {
434 $avater_url = $profile_picture_url;
435 }
436 if (!empty($params['instafeedProfileImageUrl']) && $params['instafeedProfileImageUrl'] !== 'true' && $params['instafeedProfileImageUrl'] !== 'false') {
437 $avater_url = $params['instafeedProfileImageUrl'];
438 }
439
440 $feed_data[$id]['feed_userinfo']['profile_picture_url'] = $avater_url;
441
442 update_option('ep_instagram_feed_data', $feed_data);
443 ?>
444
445 <?php if (empty($hashtag) || $hashtag === 'false') : ?>
446 <header class="profile-header">
447
448 <?php if (!empty($params['instafeedProfileImage']) && $params['instafeedProfileImage'] !== 'false') : ?>
449 <div class="profile-image">
450 <img src="<?php echo esc_url($avater_url); ?>" alt="<?php echo esc_attr($name); ?>">
451 </div>
452 <?php endif; ?>
453 <section class="profile-details">
454 <div class="username-section">
455 <a class="profile-link" target="__blank" href="<?php echo esc_url('https://instagram.com/' . $username); ?>" role="link" tabindex="0">
456 <h2 class="username" dir="auto"><?php echo esc_html($username); ?></h2>
457 </a>
458
459 <?php if (!empty($params['instafeedFollowBtn']) && $params['instafeedFollowBtn'] !== 'false' && !empty($params['instafeedFollowBtnLabel']) && $params['instafeedFollowBtnLabel'] !== 'false' && $params['instafeedFollowBtnLabel'] !== 'true') : ?>
460 <div class="edit-profile-button">
461 <a class="edit-profile-link" target="__blank" href="<?php echo esc_url('https://instagram.com/' . $username); ?>" role="link" tabindex="0">
462 <?php echo esc_html($params['instafeedFollowBtnLabel']); ?>
463 </a>
464 </div>
465 <?php endif; ?>
466
467 </div>
468 <div class="profile-stats">
469 <?php if (!empty($params['instafeedPostsCount']) && $params['instafeedPostsCount'] !== 'false') : ?>
470 <div class="posts-count">
471 <?php if (!empty($params['instafeedPostsCountText']) && $params['instafeedPostsCountText'] !== 'false' && $params['instafeedPostsCountText'] !== 'true') :
472 $posts_count_text = str_replace('[count]', '<span class="count">' . $media_count . '</span>', $params['instafeedPostsCountText']);
473 echo wp_kses_post($posts_count_text);
474 endif;
475 ?>
476
477 </div>
478 <?php endif; ?>
479
480 <?php if (!empty($params['instafeedFollowersCount']) && $params['instafeedFollowersCount'] !== 'false' && $params['instafeedFollowersCountText'] !== 'true') : ?>
481 <?php if (strtolower($connected_account_type) !== 'personal') : ?>
482 <div class="followers-count">
483 <?php if (!empty($params['instafeedFollowersCountText']) && $params['instafeedFollowersCountText'] !== 'false' && $params['instafeedFollowersCountText'] !== 'true') : ?>
484 <a class="followers-link" target="_blank" href="<?php echo esc_url('https://instagram.com/' . $username . '/followers'); ?>" role="link" tabindex="0">
485 <?php
486 $followers_count_text = str_replace('[count]', '<span class="count">' . $followers_count . '</span>', $params['instafeedFollowersCountText']);
487
488 echo wp_kses_post($followers_count_text);
489 ?>
490 </a>
491 <?php endif; ?>
492 </div>
493 <?php endif; ?>
494 <?php endif; ?>
495 </div>
496 <?php if (!empty($params['instafeedAccName']) && $params['instafeedAccName'] !== 'false') : ?>
497 <div class="bio-section">
498 <span class="bio" dir="auto"><?php echo esc_attr($name); ?></span>
499 </div>
500 <?php endif; ?>
501 </section>
502 </header>
503 <?php else : ?>
504 <div class="hashtag-container">
505 <div class="embedpress-hashtag-header">
506
507 <?php if (!empty($params['instafeedProfileImage']) && $params['instafeedProfileImage'] !== 'false') : ?>
508
509 <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>
510 </a>
511 </div>
512 <?php endif; ?>
513
514 <?php if (!empty($params['instafeedFollowBtn']) && $params['instafeedFollowBtn'] !== 'false' && !empty($params['instafeedFollowBtnLabel']) && $params['instafeedFollowBtnLabel'] !== 'false') : ?>
515 <div class="insta-followbtn">
516 <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>
517 </div>
518 <?php endif; ?>
519 </div>
520 </div>
521 <?php endif; ?>
522
523 <?php if (apply_filters('embedpress/is_allow_rander', false) && (!empty($params['instafeedTab']) && $params['instafeedTab'] !== 'false')) : ?>
524 <?php do_action('embedpress/instafeed_tab_option'); ?>
525 <?php endif; ?>
526
527 <?php
528 $params_data = [
529 'show_likes_count' => isset($params['instafeedLikesCount']) ? $params['instafeedLikesCount'] : false,
530 'show_comments_count' => isset($params['instafeedCommentsCount']) ? $params['instafeedCommentsCount'] : false,
531 'popup_follow_button' => isset($params['instafeedPopupFollowBtn']) ? $params['instafeedPopupFollowBtn'] : true,
532 'popup_follow_button_text' => isset($params['instafeedPopupFollowBtnLabel']) ? $params['instafeedPopupFollowBtnLabel'] : 'Follow'
533 ];
534
535 $params_data_json = json_encode($params_data);
536
537 ?>
538
539 <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'); ?>">
540 <div class="embedpress-insta-container">
541 <div class="insta-gallery cg-carousel__track js-carousel__track" <?php echo $styleAttribute; ?>>
542 <?php
543 $posts_per_page = 12;
544
545 if (!empty($params['instafeedPostsPerPage'])) {
546 $posts_per_page = $params['instafeedPostsPerPage'];
547 }
548 // Set the limit to 5
549 $counter = 0; // Initialize a counter variable
550
551 foreach ($insta_posts as $index => $post) {
552 if ($counter >= $posts_per_page) {
553 break; // Exit the loop when the counter reaches the limit
554 }
555 print_r($this->getInstaFeedItem($post, $index, $connected_account_type, $hashtag, $avater_url));
556
557 $counter++; // Increment the counter for each processed item
558 }
559 ?>
560 </div>
561 <div class="cg-carousel__btns hidden">
562 <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">
563 <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>
564
565 <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">
566 <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>
567 </div>
568 </div>
569
570 <!-- Popup div -->
571 <?php if (!empty($params['instafeedPopup']) && $params['instafeedPopup'] !== 'false') : ?>
572 <div class="insta-popup" style="display: none;">
573 <div class="popup-wrapper popup-is-opened">
574 <div class="popup popup-is-initialized" tabindex="-1"> </div>
575 <div class="popup-close"></div>
576 </div>
577 </div>
578 <?php endif; ?>
579
580 <?php if (!empty($params['instafeedLoadmore']) && $params['instafeedLoadmore'] !== 'false') : ?>
581
582
583 <?php if (count($insta_posts) > $posts_per_page && $params['instafeedLoadmoreLabel'] !== 'false' && $params['instafeedLoadmoreLabel'] !== 'true') : ?>
584 <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); ?>">
585 <button class="insta-load-more-button">
586 <?php echo !empty($params['instafeedLoadmoreLabel']) ? esc_html($params['instafeedLoadmoreLabel']) : ''; ?>
587 </button>
588 </div>
589 <?php endif; ?>
590 <?php endif; ?>
591
592 </div>
593
594
595 <?php
596 $feed_template = ob_get_clean();
597 return $feed_template;
598 }
599 }
600
601 public function getInstagramUnserName($url)
602 {
603 $pattern = '/instagram\.com\/([^\/?]+)/i';
604 preg_match($pattern, $url, $matches);
605 return isset($matches[1]) ? $matches[1] : '';
606 }
607
608
609 public function getStaticResponse()
610 {
611 $url = $this->getUrl();
612
613 if (parent::validateUrl($this->url)) {
614 return parent::getStaticResponse();
615 }
616
617 $insta_feed = [
618 "title" => "Unknown Title",
619 "type" => "video",
620 'provider_name' => 'Instagram Feed',
621 "provider_url" => 'https://instagram.com',
622 'html' => "",
623 ];
624
625
626 if ($this->validateReelUrl($url)) {
627
628 $params = $this->getParams();
629 $width = isset($params['maxwidth']) ? $params['maxwidth'] : 380;
630 $height = isset($params['maxheight']) ? $params['maxheight'] : 600;
631
632 $clean_url = rtrim($url, '/');
633 $src_url = $clean_url . '/embed';
634
635 $IG_reel = '<iframe width="' . esc_attr($width) . 'px" width="' . esc_attr($height) . 'px" allowtransparency="true" allowfullscreen="true" frameborder="0" height="534" data-instgrm-payload-id="instagram-media-payload-0" scrolling="no" style="background-color: white; border-radius: 3px; border: 1px solid rgb(219, 219, 219); box-shadow: none; display: block; margin: 0px 0px 12px; min-width: 326px; padding: 0px;" class="instagram-media instagram-media-rendered" src="' . esc_url($src_url) . '">Fetching content</iframe>';
636
637 $insta_feed['html'] = $IG_reel;
638 return $insta_feed;
639 }
640 $connected_users = get_option('ep_instagram_account_data');
641
642 $username = $this->getInstagramUnserName($url) ? $this->getInstagramUnserName($url) : '';
643
644 if ($this->validateInstagramFeed($url) && $this->getHashTag($url)) {
645 foreach ($connected_users as $entry) {
646 if ($entry['account_type'] === 'business') {
647 $businessUsernames[] = $entry['username'];
648 $username = $businessUsernames[0];
649 }
650 }
651 }
652
653 $access_token = ''; // The access token';
654 $account_type = '';
655 $userid = '';
656
657 if ($this->validateInstagramFeed($url) || !empty($username)) {
658 if (!empty($username)) {
659
660 if (empty($connected_users)) {
661 $connected_users = [];
662 }
663
664 // Find the key of the matching username
665 $index = array_search($username, array_column($connected_users, 'username'));
666
667 if ($index !== false) {
668 // Matching username found
669 $access_token = $connected_users[$index]['access_token'];
670 $userid = $connected_users[$index]['user_id'];
671 $account_type = $connected_users[$index]['account_type'];
672 // <a href="' . esc_url($page) . '">here</a>
673 } else {
674 // No matching username found
675 $page = site_url() . "/wp-admin/admin.php?page=embedpress&page_type=instagram";
676 $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>';
677 return $insta_feed;
678 }
679 }
680
681 $this->update_instagram_feed_data($access_token, $account_type, $userid, $limit = 100);
682
683 if ($this->getInstagramFeedTemplate($access_token, $account_type, $userid)) {
684 $insta_feed['html'] = $this->getInstagramFeedTemplate($access_token, $account_type, $userid);
685 }
686 }
687
688
689 return $insta_feed;
690 }
691
692
693 /** inline {@inheritdoc} */
694 public function getFakeResponse()
695 {
696 return [
697 'type' => 'video',
698 'provider_name' => 'Instagram Feed',
699 'provider_url' => 'https://instagram.com',
700 'title' => 'Unknown title',
701 'html' => '',
702 ];
703 }
704 }
705