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