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