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