Instagram Feed - Version 2.7

Version Description

  • Tweak: Several performance improvements have been made in this update such as improved caching and fewer database queries when displaying feeds.
  • Tweak: The limit of resized, local images created and stored were raised for the overall number and the rate at which they could be created.
  • Tweak: Improved how feed errors are handled and reported. API request delays will only apply to feeds encountering errors and will not affect other feeds.
  • Tweak: Added a hook for disabling image resizing dynamically with PHP.
  • Fix: PHP Warning "required parameter follows optional parameter" that would display when using PHP 8+.
  • Fix: The GDPR feature would sometimes report errors when the feature was working fine.
Download this release

Release Info

Developer smashballoon
Plugin Icon 128x128 Instagram Feed
Version 2.7
Comparing to
See all releases

Code changes from version 2.6.2 to 2.7

README.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: smashballoon, craig-at-smash-balloon
3
  Tags: Instagram, Instagram feed, Instagram photos, Instagram widget, Instagram gallery
4
  Requires at least: 3.4
5
  Tested up to: 5.6
6
- Stable tag: 2.6.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -332,6 +332,14 @@ We understand that sometimes you need help, have issues or just have questions.
332
  * Plus more customization options added all the time!
333
 
334
  == Changelog ==
 
 
 
 
 
 
 
 
335
  = 2.6.2 =
336
  * Tweak: If the image resizing feature isn't able to work successfully due to an issue, then the GDPR setting will be disabled unless manually enabled to prevent blank images in the feed.
337
  * Fix: In some situations the GDPR setting was incorrectly reporting an error with image resizing.
3
  Tags: Instagram, Instagram feed, Instagram photos, Instagram widget, Instagram gallery
4
  Requires at least: 3.4
5
  Tested up to: 5.6
6
+ Stable tag: 2.7
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
332
  * Plus more customization options added all the time!
333
 
334
  == Changelog ==
335
+ = 2.7 =
336
+ * Tweak: Several performance improvements have been made in this update such as improved caching and fewer database queries when displaying feeds.
337
+ * Tweak: The limit of resized, local images created and stored were raised for the overall number and the rate at which they could be created.
338
+ * Tweak: Improved how feed errors are handled and reported. API request delays will only apply to feeds encountering errors and will not affect other feeds.
339
+ * Tweak: Added a hook for disabling image resizing dynamically with PHP.
340
+ * Fix: PHP Warning "required parameter follows optional parameter" that would display when using PHP 8+.
341
+ * Fix: The GDPR feature would sometimes report errors when the feature was working fine.
342
+
343
  = 2.6.2 =
344
  * Tweak: If the image resizing feature isn't able to work successfully due to an issue, then the GDPR setting will be disabled unless manually enabled to prevent blank images in the feed.
345
  * Fix: In some situations the GDPR setting was incorrectly reporting an error with image resizing.
inc/admin/actions.php CHANGED
@@ -153,59 +153,22 @@ function sbi_connect_business_accounts() {
153
  }
154
 
155
  $accounts = isset( $_POST['accounts'] ) ? json_decode( stripslashes( $_POST['accounts'] ), true ) : false;
156
- $options = sbi_get_database_settings();
157
- $connected_accounts = isset( $options['connected_accounts'] ) ? $options['connected_accounts'] : array();
158
- $new_user_names = array();
159
 
 
160
  foreach ( $accounts as $account ) {
161
- $access_token = isset( $account['access_token'] ) ? $account['access_token'] : '';
162
- $page_access_token = isset( $account['page_access_token'] ) ? $account['page_access_token'] : '';
163
- $username = isset( $account['username'] ) ? $account['username'] : '';
164
- $name = isset( $account['name'] ) ? $account['name'] : '';
165
- $profile_picture = isset( $account['profile_picture_url'] ) ? $account['profile_picture_url'] : '';
166
- $user_id = isset( $account['id'] ) ? $account['id'] : '';
167
- $type = 'business';
168
-
169
- $connected_accounts[ $user_id ] = array(
170
- 'access_token' => $access_token,
171
- 'page_access_token' => $page_access_token,
172
- 'user_id' => $user_id,
173
- 'username' => $username,
174
- 'is_valid' => true,
175
- 'last_checked' => time(),
176
- 'profile_picture' => $profile_picture,
177
- 'name' => sbi_sanitize_emoji( $name ),
178
- 'type' => $type,
179
- 'use_tagged' => '1'
180
- );
181
- $new_user_names[] = $username;
182
 
183
- if ( !$options['sb_instagram_disable_resize'] ) {
184
- if ( sbi_create_local_avatar( $username, $profile_picture ) ) {
185
- $connected_accounts[ $user_id ]['local_avatar'] = true;
186
- }
187
- } else {
188
- $connected_accounts[ $user_id ]['local_avatar'] = false;
189
- }
190
- global $sb_instagram_posts_manager;
191
 
192
- $sb_instagram_posts_manager->remove_all_errors();
193
- delete_transient( SBI_USE_BACKUP_PREFIX . 'sbi_' . $user_id );
194
- }
195
 
196
- $accounts_to_save = array();
197
- foreach ( $connected_accounts as $account ) {
198
- $account_type = isset( $account['type'] ) ? $account['type'] : 'personal';
199
- if ( $account_type !== 'personal' || ! in_array( $account['username'], $new_user_names, true ) ) {
200
- $accounts_to_save[ $account['user_id'] ] = $account;
201
  }
202
  }
203
 
204
- $options['connected_accounts'] = $accounts_to_save;
205
-
206
- update_option( 'sb_instagram_settings', $options );
207
-
208
- echo sbi_json_encode( $accounts_to_save );
209
 
210
  die();
211
  }
@@ -314,9 +277,11 @@ function sbi_account_data_for_token( $access_token ) {
314
  function sbi_do_account_delete( $account_id ) {
315
  $options = get_option( 'sb_instagram_settings', array() );
316
  $connected_accounts = isset( $options['connected_accounts'] ) ? $options['connected_accounts'] : array();
317
-
 
318
  wp_cache_delete ( 'alloptions', 'options' );
319
  $username = $connected_accounts[ $account_id ]['username'];
 
320
 
321
  $num_times_used = 0;
322
 
@@ -336,13 +301,9 @@ function sbi_do_account_delete( $account_id ) {
336
  sbi_delete_local_avatar( $username );
337
  }
338
 
339
-
340
  $options['connected_accounts'] = $new_con_accounts;
341
 
342
  update_option( 'sb_instagram_settings', $options );
343
- global $sb_instagram_posts_manager;
344
-
345
- $sb_instagram_posts_manager->remove_all_errors();
346
  }
347
 
348
  function sbi_connect_new_account( $access_token, $account_id ) {
@@ -353,226 +314,28 @@ function sbi_connect_new_account( $access_token, $account_id ) {
353
  $access_token = preg_replace("/[^A-Za-z0-9 ]/", '', $split_token[0] );
354
  }
355
 
 
 
 
 
 
356
 
357
- $options = sbi_get_database_settings();
358
- $connected_accounts = isset( $options['connected_accounts'] ) ? $options['connected_accounts'] : array();
359
-
360
- if ( $access_token ) {
361
- wp_cache_delete ( 'alloptions', 'options' );
362
-
363
- $number_dots = substr_count ( $access_token , '.' );
364
- $test_connection_data = array( 'error_message' => 'A successful connection could not be made. Please make sure your Access Token is valid.');
365
-
366
- if ( $number_dots > 1 ) {
367
- $split_token = explode( '.', $access_token );
368
- $new_user_id = isset( $split_token[0] ) ? $split_token[0] : '';
369
-
370
- $test_connection_data = sbi_account_data_for_token( $access_token );
371
- } else if (! empty( $account_id ) ) {
372
-
373
- if ( sbi_code_check( $access_token ) ) {
374
- $data = array(
375
- 'access_token' => $access_token,
376
- 'user_id' => $account_id,
377
- 'type' => 'basic'
378
- );
379
- $basic_account_attempt = new SB_Instagram_API_Connect( $data, 'header', array() );
380
- $basic_account_attempt->connect();
381
-
382
- if ( !$basic_account_attempt->is_wp_error() && ! $basic_account_attempt->is_instagram_error() ) {
383
- $new_data = $basic_account_attempt->get_data();
384
-
385
- $basic_account_access_token_connect = new SB_Instagram_API_Connect( $data, 'access_token', array() );
386
- $basic_account_access_token_connect->connect();
387
- if ( !$basic_account_access_token_connect->is_wp_error() && ! $basic_account_access_token_connect->is_instagram_error() ) {
388
-
389
- $token_data = $basic_account_access_token_connect->get_data();
390
- $expires_in = $token_data['expires_in'];
391
- $expires_timestamp = time() + $expires_in;
392
- $account_type = isset( $new_data['account_type'] ) ? $new_data['account_type'] : 'personal';
393
-
394
- $new_connected_account = array(
395
- 'access_token' => $access_token,
396
- 'account_type' => $account_type,
397
- 'user_id' => $new_data['id'],
398
- 'username' => $new_data['username'],
399
- 'expires_timestamp' => $expires_timestamp,
400
- 'type' => 'basic'
401
- );
402
-
403
- $updated_options = sbi_connect_basic_account( $new_connected_account );
404
-
405
- return sbi_json_encode( $updated_options['connected_accounts'][ $new_data['id'] ] );
406
-
407
- } else {
408
-
409
- $token_data = $basic_account_access_token_connect->get_data();
410
- $expires_timestamp = time() + 60 * DAY_IN_SECONDS;
411
- $account_type = isset( $new_data['account_type'] ) ? $new_data['account_type'] : 'personal';
412
-
413
- $new_connected_account = array(
414
- 'access_token' => $access_token,
415
- 'account_type' => $account_type,
416
- 'user_id' => $new_data['id'],
417
- 'username' => $new_data['username'],
418
- 'expires_timestamp' => $expires_timestamp,
419
- 'type' => 'basic',
420
- 'private' => true
421
- );
422
-
423
- $updated_options = sbi_connect_basic_account( $new_connected_account );
424
-
425
- return sbi_json_encode( $updated_options['connected_accounts'][ $new_data['id'] ] );
426
- }
427
-
428
- } else {
429
-
430
- if ( $basic_account_attempt->is_wp_error() ) {
431
- $error = $basic_account_attempt->get_wp_error();
432
- } else {
433
- $error = $basic_account_attempt->get_data();
434
- }
435
- return sbi_formatted_error( $error );
436
- }
437
- }
438
-
439
- $url = 'https://graph.facebook.com/'.$account_id.'?fields=biography,id,username,website,followers_count,media_count,profile_picture_url,name&access_token='.sbi_maybe_clean( $access_token );
440
- $json = json_decode( sbi_business_account_request( $url, array( 'access_token' => $access_token ) ), true );
441
-
442
- if ( isset( $json['error'] ) && $json['error']['type'] === 'OAuthException' ) {
443
- $data = array(
444
- 'access_token' => $access_token,
445
- 'user_id' => $account_id,
446
- 'type' => 'basic'
447
- );
448
- $basic_account_attempt = new SB_Instagram_API_Connect( $data, 'header', array() );
449
- $basic_account_attempt->connect();
450
-
451
- if ( !$basic_account_attempt->is_wp_error() && ! $basic_account_attempt->is_instagram_error() ) {
452
- $new_data = $basic_account_attempt->get_data();
453
-
454
- $basic_account_access_token_connect = new SB_Instagram_API_Connect( $data, 'access_token', array() );
455
- $basic_account_access_token_connect->connect();
456
- if ( !$basic_account_access_token_connect->is_wp_error() && ! $basic_account_access_token_connect->is_instagram_error() ) {
457
-
458
- $token_data = $basic_account_access_token_connect->get_data();
459
- $expires_in = $token_data['expires_in'];
460
- $expires_timestamp = time() + $expires_in;
461
-
462
- $new_connected_account = array(
463
- 'access_token' => $access_token,
464
- 'account_type' => $new_data['account_type'],
465
- 'user_id' => $new_data['id'],
466
- 'username' => $new_data['username'],
467
- 'expires_timestamp' => $expires_timestamp,
468
- 'type' => 'basic'
469
- );
470
-
471
- $updated_options = sbi_connect_basic_account( $new_connected_account );
472
-
473
- return sbi_json_encode( $updated_options['connected_accounts'][ $new_data['id'] ] );
474
-
475
- } else {
476
- if ( $basic_account_access_token_connect->is_wp_error() ) {
477
- $error = $basic_account_access_token_connect->get_wp_error();
478
- } else {
479
- $error = $basic_account_access_token_connect->get_data();
480
- }
481
- return sbi_formatted_error( $error );
482
- }
483
-
484
- } else {
485
- if ( $basic_account_attempt->is_wp_error() ) {
486
- $error = $basic_account_attempt->get_wp_error();
487
- } else {
488
- $error = $basic_account_attempt->get_data();
489
- }
490
- return sbi_formatted_error( $error );
491
- }
492
-
493
- } else {
494
- if ( isset( $json['id'] ) ) {
495
- $new_user_id = $json['id'];
496
- $test_connection_data = array(
497
- 'access_token' => $access_token,
498
- 'id' => $json['id'],
499
- 'username' => $json['username'],
500
- 'type' => 'business',
501
- 'is_valid' => true,
502
- 'last_checked' => time(),
503
- 'profile_picture' => $json['profile_picture_url']
504
- );
505
- }
506
- }
507
-
508
-
509
- global $sb_instagram_posts_manager;
510
-
511
- $sb_instagram_posts_manager->remove_all_errors();
512
- delete_transient( SBI_USE_BACKUP_PREFIX . 'sbi_' . $json['id'] );
513
-
514
- }
515
-
516
- if ( isset( $test_connection_data['error_message'] ) ) {
517
- return $test_connection_data['error_message'];
518
- } elseif ( $test_connection_data !== false && ! empty( $new_user_id ) ) {
519
- $username = $test_connection_data['username'] ? $test_connection_data['username'] : $connected_accounts[ $new_user_id ]['username'];
520
- $user_id = $test_connection_data['id'] ? $test_connection_data['id'] : $connected_accounts[ $new_user_id ]['user_id'];
521
- $profile_picture = $test_connection_data['profile_picture'] ? $test_connection_data['profile_picture'] : $connected_accounts[ $new_user_id ]['profile_picture'];
522
- $type = isset( $test_connection_data['type'] ) ? $test_connection_data['type'] : 'personal';
523
- $connected_accounts[ $new_user_id ] = array(
524
- 'access_token' => sbi_get_parts( $access_token ),
525
- 'user_id' => $user_id,
526
- 'username' => $username,
527
- 'type' => $type,
528
- 'is_valid' => true,
529
- 'last_checked' => $test_connection_data['last_checked'],
530
- 'profile_picture' => $profile_picture
531
- );
532
-
533
- if ( !$options['sb_instagram_disable_resize'] ) {
534
- if ( sbi_create_local_avatar( $username, $profile_picture ) ) {
535
- $connected_accounts[ $new_user_id ]['local_avatar'] = true;
536
- }
537
- } else {
538
- $connected_accounts[ $new_user_id ]['local_avatar'] = false;
539
- }
540
-
541
- if ( $type === 'business' ) {
542
- $url = 'https://graph.facebook.com/'.$user_id.'/tags?user_id='.$user_id.'&fields=id&limit=1&access_token='.sbi_maybe_clean( $access_token );
543
- $args = array(
544
- 'timeout' => 60,
545
- 'sslverify' => false
546
- );
547
- $response = wp_remote_get( $url, $args );
548
-
549
- if ( ! is_wp_error( $response ) ) {
550
- // certain ways of representing the html for double quotes causes errors so replaced here.
551
- $response = json_decode( str_replace( '%22', '”', $response['body'] ), true );
552
- if ( isset( $response['data'] ) ) {
553
- $connected_accounts[ $new_user_id ]['use_tagged'] = '1';
554
- }
555
- } else {
556
- return sbi_formatted_error( $response );
557
- }
558
- }
559
-
560
- delete_transient( SBI_USE_BACKUP_PREFIX . 'sbi_' . $user_id );
561
- global $sb_instagram_posts_manager;
562
-
563
- $sb_instagram_posts_manager->remove_all_errors();
564
- $options['connected_accounts'] = $connected_accounts;
565
 
566
- update_option( 'sb_instagram_settings', $options );
567
 
568
- return sbi_json_encode( $connected_accounts[ $new_user_id ] );
569
- } else {
570
- return 'A successful connection could not be made. Please make sure your Access Token is valid.';
571
- }
572
 
 
 
 
 
 
 
 
573
  }
574
-
575
- return '';
576
  }
577
 
578
  function sbi_no_js_connected_account_management() {
@@ -721,9 +484,9 @@ function sbi_connect_basic_account( $new_account_details ) {
721
  $options['sb_instagram_user_id'] = $ids_to_save;
722
 
723
  update_option( 'sb_instagram_settings', $options );
724
- global $sb_instagram_posts_manager;
725
 
726
- $sb_instagram_posts_manager->remove_all_errors();
727
  return $options;
728
  }
729
 
@@ -816,6 +579,170 @@ function sbi_after_connection() {
816
  }
817
  add_action( 'wp_ajax_sbi_after_connection', 'sbi_after_connection' );
818
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
819
  function sbi_account_type_display( $type, $private = false ) {
820
  if ( $type === 'basic' ) {
821
  $type = 'personal';
@@ -860,6 +787,9 @@ function sbi_reset_resized() {
860
 
861
  global $sb_instagram_posts_manager;
862
  $sb_instagram_posts_manager->delete_all_sbi_instagram_posts();
 
 
 
863
 
864
  echo "1";
865
 
@@ -867,58 +797,56 @@ function sbi_reset_resized() {
867
  }
868
  add_action( 'wp_ajax_sbi_reset_resized', 'sbi_reset_resized' );
869
 
870
- function sbi_lite_dismiss() {
871
- $nonce = isset( $_POST['sbi_nonce'] ) ? sanitize_text_field( $_POST['sbi_nonce'] ) : '';
872
 
873
- if ( ! wp_verify_nonce( $nonce, 'sbi_nonce' ) ) {
874
- die ( 'You did not do this the right way!' );
875
- }
876
 
877
- set_transient( 'instagram_feed_dismiss_lite', 'dismiss', 1 * WEEK_IN_SECONDS );
878
 
879
  die();
880
  }
881
- add_action( 'wp_ajax_sbi_lite_dismiss', 'sbi_lite_dismiss' );
882
 
883
- function sbi_reset_log() {
884
  global $sb_instagram_posts_manager;
 
885
 
886
- $sb_instagram_posts_manager->remove_all_errors();
887
 
888
  echo "1";
889
 
890
  die();
891
  }
892
- add_action( 'wp_ajax_sbi_reset_log', 'sbi_reset_log' );
 
 
 
 
 
 
 
 
 
 
 
 
 
893
 
894
  add_action('admin_notices', 'sbi_admin_error_notices');
895
  function sbi_admin_error_notices() {
896
 
897
- $is_reconnecting = ! empty( $_POST['sbi_account_json'] );
898
- if ( ! $is_reconnecting && isset( $_GET['page'] ) && in_array( $_GET['page'], array( 'sb-instagram-feed' )) ) {
899
  global $sb_instagram_posts_manager;
900
 
901
  $errors = $sb_instagram_posts_manager->get_errors();
902
-
903
- if ( ! empty( $errors ) && ( isset( $errors['database_create_posts'] ) || isset( $errors['database_create_posts_feeds'] ) || isset( $errors['upload_dir'] ) || isset( $errors['ajax'] ) ) ) : ?>
904
  <div class="notice notice-warning is-dismissible sbi-admin-notice">
 
905
 
906
- <?php foreach ( $sb_instagram_posts_manager->get_errors() as $type => $error ) : ?>
907
- <?php if ( (in_array( $type, array( 'database_create_posts', 'database_create_posts_feeds', 'upload_dir' ) ) && !$sb_instagram_posts_manager->image_resizing_disabled() ) ) : ?>
908
- <p><strong><?php echo $error[0]; ?></strong></p>
909
- <p><?php _e( 'Note for support', 'instagram-feed' ); ?>: <?php echo $error[1]; ?></p>
910
- <?php endif; ?>
911
- <?php endforeach; ?>
912
- <?php if ( ( isset( $errors['database_create_posts'] ) || isset( $errors['database_create_posts_feeds'] ) || isset( $errors['upload_dir'] ) ) && !$sb_instagram_posts_manager->image_resizing_disabled() ) : ?>
913
- <p><?php _e( sprintf( 'Visit our %s page for help', '<a href="https://smashballoon.com/instagram-feed/support/faq/" target="_blank">FAQ</a>' ), 'instagram-feed' ); ?></p>
914
- <?php endif; ?>
915
-
916
- <?php foreach ( $sb_instagram_posts_manager->get_errors() as $type => $error ) : ?>
917
- <?php if (in_array( $type, array( 'ajax' ) )) : ?>
918
- <p class="sbi-admin-error" data-sbi-type="ajax"><strong><?php echo $error[0]; ?></strong></p>
919
- <p><?php echo $error[1]; ?></p>
920
- <?php endif; ?>
921
- <?php endforeach; ?>
922
 
923
  </div>
924
 
@@ -928,14 +856,14 @@ function sbi_admin_error_notices() {
928
  <div class="notice notice-warning is-dismissible sbi-admin-notice">
929
  <p><strong><?php echo esc_html__( 'Instagram Feed is encountering an error and your feeds may not be updating due to the following reasons:', 'instagram-feed') ; ?></strong></p>
930
 
931
- <?php echo $errors; ?>
932
 
933
- <?php
934
- $error_page = $sb_instagram_posts_manager->get_error_page();
935
- if ( $error_page ) {
936
- echo '<a href="' . get_the_permalink( $error_page ) . '" class="sbi-clear-errors-visit-page sbi-space-left button button-secondary">' . __( 'View Feed and Retry', 'instagram-feed' ) . '</a>';
937
- }
938
- ?>
939
  </div>
940
  <?php endif;
941
  }
@@ -979,62 +907,6 @@ function sbi_get_user_names_of_personal_accounts_not_also_already_updated() {
979
  return array();
980
  }
981
 
982
- function sbi_reconnect_accounts_notice() {
983
- if( ! current_user_can( 'manage_options' ) ) return;
984
-
985
- $should_show_link = ! isset( $_GET['page'] ) || $_GET['page'] !== 'sb-instagram-feed';
986
- $personal_accounts_that_need_updating = sbi_get_user_names_of_personal_accounts_not_also_already_updated();
987
- if ( empty( $personal_accounts_that_need_updating ) ) {
988
- return;
989
- } else {
990
- $total = count( $personal_accounts_that_need_updating );
991
- if ( $total > 1 ) {
992
- $user_string = '';
993
- $i = 0;
994
-
995
- foreach ( $personal_accounts_that_need_updating as $username ) {
996
- if ( ($i + 1) === $total ) {
997
- $user_string .= ' and ' . $username;
998
- } else {
999
- if ( $i !== 0 ) {
1000
- $user_string .= ', ' . $username;
1001
- } else {
1002
- $user_string .= $username;
1003
- }
1004
- }
1005
- $i++;
1006
- }
1007
- } else {
1008
- $user_string = $personal_accounts_that_need_updating[0];
1009
- }
1010
-
1011
- if ( sbi_is_after_deprecation_deadline() ) {
1012
- $notice_class = 'notice-error';
1013
- $error = '<p><b>' . sprintf( __( 'Error: Instagram Feed plugin - account for %s needs to be reconnected.', 'instagram-feed' ), '<em>'.$user_string.'</em>' ) . '</b><br>' . __( 'Due to recent Instagram platform changes some Instagram accounts will need to be reconnected in the plugin in order for them to continue updating.', 'instagram-feed' );
1014
- } else {
1015
- $notice_class = 'notice-warning';
1016
- $error = '<p><b>' . sprintf( __( 'Warning: Instagram Feed plugin - account for %s needs to be reconnected.', 'instagram-feed' ), '<em>'.$user_string.'</em>' ) . '</b><br>' . __( 'Due to Instagram platform changes on June 1, 2020, some Instagram accounts will need to be reconnected in the plugin to avoid disruption to your feeds.', 'instagram-feed' );
1017
- }
1018
- if( !$should_show_link ) $error .= __( ' Use the big blue button below to reconnect your account.', 'instagram-feed' );
1019
- }
1020
- $url = admin_url( '?page=sb-instagram-feed' );
1021
-
1022
- ?>
1023
- <div class="notice <?php echo $notice_class; ?> is-dismissible">
1024
- <?php echo $error; ?>
1025
- <p>
1026
- <?php if ( $should_show_link ) : ?>
1027
- <a href="<?php echo $url; ?>" class="button-primary" style="margin-right:10px;"><i class="fa fa-instagram" aria-hidden="true"></i> &nbsp;Reconnect on Settings Page</a>
1028
- <?php endif; ?>
1029
- <a href="https://smashballoon.com/instagram-api-changes-march-2-2020/" target="_blank" rel="noopener">See more details</a>
1030
- </p>
1031
- </div>
1032
-
1033
- <?php
1034
-
1035
- }
1036
- add_action( 'admin_notices', 'sbi_reconnect_accounts_notice' );
1037
-
1038
  function sbi_get_current_time() {
1039
  $current_time = time();
1040
 
153
  }
154
 
155
  $accounts = isset( $_POST['accounts'] ) ? json_decode( stripslashes( $_POST['accounts'] ), true ) : false;
 
 
 
156
 
157
+ $return = array();
158
  foreach ( $accounts as $account ) {
159
+ $account['type'] = 'business';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
 
161
+ $connector = new SBI_Account_Connector();
 
 
 
 
 
 
 
162
 
163
+ $connector->add_account_data( $account );
164
+ if ( $connector->update_stored_account() ) {
165
+ $connector->after_update();
166
 
167
+ $return[ $connector->get_id() ] = $connector->get_account_data();
 
 
 
 
168
  }
169
  }
170
 
171
+ echo sbi_json_encode( $return );
 
 
 
 
172
 
173
  die();
174
  }
277
  function sbi_do_account_delete( $account_id ) {
278
  $options = get_option( 'sb_instagram_settings', array() );
279
  $connected_accounts = isset( $options['connected_accounts'] ) ? $options['connected_accounts'] : array();
280
+ global $sb_instagram_posts_manager;
281
+ $sb_instagram_posts_manager->remove_connected_account_error( $connected_accounts[ $account_id ] );
282
  wp_cache_delete ( 'alloptions', 'options' );
283
  $username = $connected_accounts[ $account_id ]['username'];
284
+ $sb_instagram_posts_manager->add_action_log( 'Deleting account ' . $username );
285
 
286
  $num_times_used = 0;
287
 
301
  sbi_delete_local_avatar( $username );
302
  }
303
 
 
304
  $options['connected_accounts'] = $new_con_accounts;
305
 
306
  update_option( 'sb_instagram_settings', $options );
 
 
 
307
  }
308
 
309
  function sbi_connect_new_account( $access_token, $account_id ) {
314
  $access_token = preg_replace("/[^A-Za-z0-9 ]/", '', $split_token[0] );
315
  }
316
 
317
+ $account = array(
318
+ 'access_token' => $access_token,
319
+ 'user_id' => $account_id,
320
+ 'type' => 'business'
321
+ );
322
 
323
+ if ( sbi_code_check( $access_token ) ) {
324
+ $account['type'] = 'basic';
325
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326
 
327
+ $connector = new SBI_Account_Connector();
328
 
329
+ $response = $connector->fetch( $account );
 
 
 
330
 
331
+ if ( isset( $response['access_token'] ) ) {
332
+ $connector->add_account_data( $response );
333
+ $connector->update_stored_account();
334
+ $connector->after_update();
335
+ return sbi_json_encode( $connector->get_account_data() );
336
+ } else {
337
+ return $response['error'];
338
  }
 
 
339
  }
340
 
341
  function sbi_no_js_connected_account_management() {
484
  $options['sb_instagram_user_id'] = $ids_to_save;
485
 
486
  update_option( 'sb_instagram_settings', $options );
487
+ //global $sb_instagram_posts_manager;
488
 
489
+ //$sb_instagram_posts_manager->remove_all_errors();
490
  return $options;
491
  }
492
 
579
  }
580
  add_action( 'wp_ajax_sbi_after_connection', 'sbi_after_connection' );
581
 
582
+ function sbi_get_business_account_connection_modal($sb_instagram_user_id) {
583
+ $access_token = sbi_maybe_clean(urldecode($_GET['access_token']));
584
+ //
585
+ $url = 'https://graph.facebook.com/me/accounts?fields=instagram_business_account,access_token&limit=500&access_token='.$access_token;
586
+ $args = array(
587
+ 'timeout' => 60,
588
+ 'sslverify' => false
589
+ );
590
+ $result = wp_remote_get( $url, $args );
591
+ $pages_data = '{}';
592
+ if ( ! is_wp_error( $result ) ) {
593
+ $pages_data = $result['body'];
594
+ } else {
595
+ $page_error = $result;
596
+ }
597
+
598
+ $pages_data_arr = json_decode($pages_data);
599
+ $num_accounts = 0;
600
+ if(isset($pages_data_arr)){
601
+ $num_accounts = is_array( $pages_data_arr->data ) ? count( $pages_data_arr->data ) : 0;
602
+ }
603
+ ?>
604
+ <div id="sbi_config_info" class="sb_list_businesses sbi_num_businesses_<?php echo $num_accounts; ?>">
605
+ <div class="sbi_config_modal">
606
+ <div class="sbi-managed-pages">
607
+ <?php if ( isset( $page_error ) && isset( $page_error->errors ) ) {
608
+ foreach ($page_error->errors as $key => $item) {
609
+ echo '<div class="sbi_user_id_error" style="display:block;"><strong>Connection Error: </strong>' . $key . ': ' . $item[0] . '</div>';
610
+ }
611
+ }
612
+ ?>
613
+ <?php if( empty($pages_data_arr->data) ) : ?>
614
+ <span id="sbi-bus-account-error">
615
+ <p style="margin-top: 5px;"><b style="font-size: 16px">Couldn't find Business Profile</b><br />
616
+ Uh oh. It looks like this Facebook account is not currently connected to an Instagram Business profile. Please check that you are logged into the <a href="https://www.facebook.com/" target="_blank">Facebook account</a> in this browser which is associated with your Instagram Business Profile.</p>
617
+ <p><b style="font-size: 16px">Why do I need a Business Profile?</b><br />
618
+ A Business Profile is only required if you are displaying a Hashtag feed. If you want to display a regular User feed then you can do this by selecting to connect a Personal account instead. For directions on how to convert your Personal profile into a Business profile please <a href="https://smashballoon.com/instagram-business-profiles" target="_blank">see here</a>.</p>
619
+ </span>
620
+
621
+ <?php elseif ( $num_accounts === 0 ): ?>
622
+ <span id="sbi-bus-account-error">
623
+ <p style="margin-top: 5px;"><b style="font-size: 16px">Couldn't find Business Profile</b><br />
624
+ Uh oh. It looks like this Facebook account is not currently connected to an Instagram Business profile. Please check that you are logged into the <a href="https://www.facebook.com/" target="_blank">Facebook account</a> in this browser which is associated with your Instagram Business Profile.</p>
625
+ <p>If you are, in fact, logged-in to the correct account please make sure you have Instagram accounts connected with your Facebook account by following <a href="https://smashballoon.com/reconnecting-an-instagram-business-profile/" target="_blank">this FAQ</a></p>
626
+ </span>
627
+ <?php else: ?>
628
+ <p class="sbi-managed-page-intro"><b style="font-size: 16px;">Instagram Business profiles for this account</b><br /><i style="color: #666;">Note: In order to display a Hashtag feed you first need to select a Business profile below.</i></p>
629
+ <?php if ( $num_accounts > 1 ) : ?>
630
+ <div class="sbi-managed-page-select-all"><input type="checkbox" id="sbi-select-all" class="sbi-select-all"><label for="sbi-select-all">Select All</label></div>
631
+ <?php endif; ?>
632
+ <div class="sbi-scrollable-accounts">
633
+
634
+ <?php foreach ( $pages_data_arr->data as $page => $page_data ) : ?>
635
+
636
+ <?php if( isset( $page_data->instagram_business_account ) ) :
637
+
638
+ $instagram_business_id = $page_data->instagram_business_account->id;
639
+
640
+ $page_access_token = isset( $page_data->access_token ) ? $page_data->access_token : '';
641
+
642
+ //Make another request to get page info
643
+ $instagram_account_url = 'https://graph.facebook.com/'.$instagram_business_id.'?fields=name,username,profile_picture_url&access_token='.$access_token;
644
+
645
+ $args = array(
646
+ 'timeout' => 60,
647
+ 'sslverify' => false
648
+ );
649
+ $result = wp_remote_get( $instagram_account_url, $args );
650
+ $instagram_account_info = '{}';
651
+ if ( ! is_wp_error( $result ) ) {
652
+ $instagram_account_info = $result['body'];
653
+ } else {
654
+ $page_error = $result;
655
+ }
656
+
657
+ $instagram_account_data = json_decode($instagram_account_info);
658
+
659
+ $instagram_biz_img = isset( $instagram_account_data->profile_picture_url ) ? $instagram_account_data->profile_picture_url : false;
660
+ $selected_class = $instagram_business_id == $sb_instagram_user_id ? ' sbi-page-selected' : '';
661
+
662
+ ?>
663
+ <?php if ( isset( $page_error ) && isset( $page_error->errors ) ) :
664
+ foreach ($page_error->errors as $key => $item) {
665
+ echo '<div class="sbi_user_id_error" style="display:block;"><strong>Connection Error: </strong>' . $key . ': ' . $item[0] . '</div>';
666
+ }
667
+ else : ?>
668
+ <div class="sbi-managed-page<?php echo $selected_class; ?>" data-page-token="<?php echo esc_attr( $page_access_token ); ?>" data-token="<?php echo esc_attr( $access_token ); ?>" data-page-id="<?php echo esc_attr( $instagram_business_id ); ?>">
669
+ <div class="sbi-add-checkbox">
670
+ <input id="sbi-<?php echo esc_attr( $instagram_business_id ); ?>" type="checkbox" name="sbi_managed_pages[]" value="<?php echo esc_attr( $instagram_account_info ); ?>">
671
+ </div>
672
+ <div class="sbi-managed-page-details">
673
+ <label for="sbi-<?php echo esc_attr( $instagram_business_id ); ?>"><img class="sbi-page-avatar" border="0" height="50" width="50" src="<?php echo esc_url( $instagram_biz_img ); ?>"><b style="font-size: 16px;"><?php echo esc_html( $instagram_account_data->name ); ?></b>
674
+ <br />@<?php echo esc_html( $instagram_account_data->username); ?><span style="font-size: 11px; margin-left: 5px;">(<?php echo esc_html( $instagram_business_id ); ?>)</span></label>
675
+ </div>
676
+ </div>
677
+ <?php endif; ?>
678
+
679
+ <?php endif; ?>
680
+
681
+ <?php endforeach; ?>
682
+
683
+ </div> <!-- end scrollable -->
684
+ <p style="font-size: 11px; line-height: 1.5; margin-bottom: 0;"><i style="color: #666;">*<?php echo sprintf( __( 'Changing the password, updating privacy settings, or removing page admins for the related Facebook page may require %smanually reauthorizing our app%s to reconnect an account.', 'instagram-feed' ), '<a href="https://smashballoon.com/reauthorizing-our-instagram-facebook-app/" target="_blank" rel="noopener noreferrer">', '</a>' ); ?></i></p>
685
+
686
+ <a href="JavaScript:void(0);" id="sbi-connect-business-accounts" class="button button-primary" disabled="disabled" style="margin-top: 20px;">Connect Accounts</a>
687
+
688
+ <?php endif; ?>
689
+
690
+ <a href="JavaScript:void(0);" class="sbi_modal_close"><i class="fa fa-times"></i></a>
691
+ </div>
692
+ </div>
693
+ </div><?php
694
+ }
695
+
696
+ function sbi_get_personal_connection_modal( $connected_accounts, $action_url = 'admin.php?page=sb-instagram-feed' ) {
697
+ $access_token = sanitize_text_field( $_GET['access_token'] );
698
+ $account_type = sanitize_text_field( $_GET['account_type'] );
699
+ $user_id = sanitize_text_field( $_GET['id'] );
700
+ $user_name = sanitize_text_field( $_GET['username'] );
701
+ $expires_in = (int)$_GET['expires_in'];
702
+ $expires_timestamp = time() + $expires_in;
703
+
704
+ $new_account_details = array(
705
+ 'access_token' => $access_token,
706
+ 'account_type' => $account_type,
707
+ 'user_id' => $user_id,
708
+ 'username' => $user_name,
709
+ 'expires_timestamp' => $expires_timestamp,
710
+ 'profile_picture' => '',
711
+ 'type' => 'basic'
712
+ );
713
+
714
+
715
+ $matches_existing_personal = sbi_matches_existing_personal( $new_account_details );
716
+ $button_text = $matches_existing_personal ? __( 'Update This Account', 'instagram-feed' ) : __( 'Connect This Account', 'instagram-feed' );
717
+
718
+ $account_json = sbi_json_encode( $new_account_details );
719
+
720
+ $already_connected_as_business_account = (isset( $connected_accounts[ $user_id ] ) && $connected_accounts[ $user_id ]['type'] === 'business');
721
+
722
+ ?>
723
+
724
+ <div id="sbi_config_info" class="sb_get_token">
725
+ <div class="sbi_config_modal">
726
+ <div class="sbi_ca_username"><strong><?php echo esc_html( $user_name ); ?></strong></div>
727
+ <form action="<?php echo admin_url( $action_url ); ?>" method="post">
728
+ <p class="sbi_submit">
729
+ <?php if ( $already_connected_as_business_account ) :
730
+ _e( 'The Instagram account you are logged into is already connected as a "business" account. Remove the business account if you\'d like to connect as a basic account instead (not recommended).', 'instagram-feed' );
731
+ ?>
732
+ <?php else : ?>
733
+ <input type="submit" name="sbi_submit" id="sbi_connect_account" class="button button-primary" value="<?php echo esc_html( $button_text ); ?>">
734
+ <?php endif; ?>
735
+ <input type="hidden" name="sbi_account_json" value="<?php echo esc_attr( $account_json ) ; ?>">
736
+ <input type="hidden" name="sbi_connect_username" value="<?php echo esc_attr( $user_name ); ?>">
737
+ <a href="JavaScript:void(0);" class="button button-secondary" id="sbi_switch_accounts"><?php esc_html_e( 'Switch Accounts', 'instagram-feed' ); ?></a>
738
+ </p>
739
+ </form>
740
+ <a href="JavaScript:void(0);"><i class="sbi_modal_close fa fa-times"></i></a>
741
+ </div>
742
+ </div>
743
+ <?php
744
+ }
745
+
746
  function sbi_account_type_display( $type, $private = false ) {
747
  if ( $type === 'basic' ) {
748
  $type = 'personal';
787
 
788
  global $sb_instagram_posts_manager;
789
  $sb_instagram_posts_manager->delete_all_sbi_instagram_posts();
790
+ delete_option( 'sbi_top_api_calls' );
791
+
792
+ $sb_instagram_posts_manager->add_action_log( 'Reset resizing tables.' );
793
 
794
  echo "1";
795
 
797
  }
798
  add_action( 'wp_ajax_sbi_reset_resized', 'sbi_reset_resized' );
799
 
800
+ function sbi_reset_log() {
801
+ global $sb_instagram_posts_manager;
802
 
803
+ $sb_instagram_posts_manager->remove_all_errors();
 
 
804
 
805
+ echo "1";
806
 
807
  die();
808
  }
809
+ add_action( 'wp_ajax_sbi_reset_log', 'sbi_reset_log' );
810
 
811
+ function sbi_reset_api_errors() {
812
  global $sb_instagram_posts_manager;
813
+ $sb_instagram_posts_manager->add_action_log( 'View feed and retry button clicked.' );
814
 
815
+ $sb_instagram_posts_manager->reset_api_errors();
816
 
817
  echo "1";
818
 
819
  die();
820
  }
821
+ add_action( 'wp_ajax_sbi_reset_api_errors', 'sbi_reset_api_errors' );
822
+
823
+ function sbi_lite_dismiss() {
824
+ $nonce = isset( $_POST['sbi_nonce'] ) ? sanitize_text_field( $_POST['sbi_nonce'] ) : '';
825
+
826
+ if ( ! wp_verify_nonce( $nonce, 'sbi_nonce' ) ) {
827
+ die ( 'You did not do this the right way!' );
828
+ }
829
+
830
+ set_transient( 'instagram_feed_dismiss_lite', 'dismiss', 1 * WEEK_IN_SECONDS );
831
+
832
+ die();
833
+ }
834
+ add_action( 'wp_ajax_sbi_lite_dismiss', 'sbi_lite_dismiss' );
835
 
836
  add_action('admin_notices', 'sbi_admin_error_notices');
837
  function sbi_admin_error_notices() {
838
 
839
+ if ( isset( $_GET['page'] ) && in_array( $_GET['page'], array( 'sb-instagram-feed' )) ) {
840
+
841
  global $sb_instagram_posts_manager;
842
 
843
  $errors = $sb_instagram_posts_manager->get_errors();
844
+ if ( ! empty( $errors ) && (! empty( $errors['database_create'] ) || ! empty( $errors['upload_dir'] )) ) : ?>
 
845
  <div class="notice notice-warning is-dismissible sbi-admin-notice">
846
+ <?php if ( ! empty( $errors['database_create'] ) ) echo '<p>' . $errors['database_create'] . '</p>'; ?>
847
 
848
+ <?php if ( ! empty( $errors['upload_dir'] ) ) echo '<p>' . $errors['upload_dir'] . '</p>'; ?>
849
+ <p><?php _e( sprintf( 'Visit our %s page for help', '<a href="https://smashballoon.com/instagram-feed/support/faq/" target="_blank">FAQ</a>' ), 'instagram-feed' ); ?></p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
850
 
851
  </div>
852
 
856
  <div class="notice notice-warning is-dismissible sbi-admin-notice">
857
  <p><strong><?php echo esc_html__( 'Instagram Feed is encountering an error and your feeds may not be updating due to the following reasons:', 'instagram-feed') ; ?></strong></p>
858
 
859
+ <?php echo $errors; ?>
860
 
861
+ <?php
862
+ $error_page = $sb_instagram_posts_manager->get_error_page();
863
+ if ( $error_page ) {
864
+ echo '<a href="' . get_the_permalink( $error_page ) . '" class="sbi-clear-errors-visit-page sbi-space-left button button-secondary">' . __( 'View Feed and Retry', 'instagram-feed' ) . '</a>';
865
+ }
866
+ ?>
867
  </div>
868
  <?php endif;
869
  }
907
  return array();
908
  }
909
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
910
  function sbi_get_current_time() {
911
  $current_time = time();
912
 
inc/admin/class-sbi-account-connector.php ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Class SBI_Account_Connector
4
+ *
5
+ * Connecting new accounts from
6
+ *
7
+ * @since 5.10
8
+ */
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ die( '-1' );
12
+ }
13
+
14
+ class SBI_Account_Connector {
15
+
16
+ /**
17
+ * @var array
18
+ *
19
+ * @since 5.10
20
+ */
21
+ private $account_data;
22
+
23
+ /**
24
+ * @var int
25
+ *
26
+ * @since 5.10
27
+ */
28
+ private $id;
29
+
30
+ public function construct() {
31
+ $this->account_data = array();
32
+ }
33
+
34
+ /**
35
+ * When connecting accounts, modals are launched for various parts of the
36
+ * sequence
37
+ *
38
+ * @param $sb_instagram_user_id string
39
+ *
40
+ * @since 5.10
41
+ */
42
+ public static function maybe_launch_modals( $sb_instagram_user_id ) {
43
+ if ( ! empty( $_POST ) ) {
44
+ return;
45
+ }
46
+ $connected_accounts = SBI_Account_Connector::stored_connected_accounts();
47
+ if( isset( $_GET['access_token'] ) && isset( $_GET['graph_api'] ) ) {
48
+ sbi_get_business_account_connection_modal( $sb_instagram_user_id );
49
+ } elseif ( isset( $_GET['access_token'] ) && isset( $_GET['account_type'] ) ) {
50
+ sbi_get_personal_connection_modal( $connected_accounts );
51
+ }
52
+ }
53
+
54
+ /**
55
+ * @return int
56
+ *
57
+ * @since 5.10
58
+ */
59
+ public function get_id() {
60
+ return $this->id;
61
+ }
62
+
63
+ /**
64
+ * @return array
65
+ *
66
+ * @since 5.10
67
+ */
68
+ public function get_account_data() {
69
+ return $this->account_data;
70
+ }
71
+
72
+ /**
73
+ * Get API data for the connected account using the account access
74
+ * token and ID
75
+ *
76
+ * @param $data array
77
+ *
78
+ * @return array
79
+ *
80
+ * @since 5.10
81
+ */
82
+ public function fetch( $data ) {
83
+ if ( ! isset( $data['user_id'] ) ) {
84
+ return array( 'error' => __( 'Invalid account ID', 'instagram-feed' ) );
85
+ }
86
+ if ( ! isset( $data['access_token'] ) ) {
87
+ return array( 'error' => __( 'Invalid access token', 'instagram-feed' ) );
88
+ }
89
+
90
+ $connection = new SB_Instagram_API_Connect( $data, 'header', array() );
91
+ $connection->connect();
92
+
93
+ if ( !$connection->is_wp_error() && ! $connection->is_instagram_error() ) {
94
+ $new_data = $connection->get_data();
95
+
96
+ if ( $data['type'] === 'basic' ) {
97
+ $basic_account_access_token_connect = new SB_Instagram_API_Connect( $data, 'access_token', array() );
98
+ $basic_account_access_token_connect->connect();
99
+ $token_data = $basic_account_access_token_connect->get_data();
100
+
101
+ if ( !$basic_account_access_token_connect->is_wp_error() && ! $basic_account_access_token_connect->is_instagram_error() ) {
102
+ $expires_in = $token_data['expires_in'];
103
+ $expires_timestamp = time() + $expires_in;
104
+ } else {
105
+ $expires_timestamp = time() + 60 * DAY_IN_SECONDS;
106
+ }
107
+
108
+ $new_connected_account = array(
109
+ 'access_token' => $data['access_token'],
110
+ 'account_type' => 'personal',
111
+ 'user_id' => $new_data['id'],
112
+ 'username' => $new_data['username'],
113
+ 'expires_timestamp' => $expires_timestamp,
114
+ 'type' => 'basic',
115
+ 'profile_picture' => ''
116
+ );
117
+
118
+ } else {
119
+ $new_connected_account = array(
120
+ 'access_token' => $data['access_token'],
121
+ 'id' => $new_data['id'],
122
+ 'username' => $new_data['username'],
123
+ 'type' => 'business',
124
+ 'is_valid' => true,
125
+ 'last_checked' => time(),
126
+ 'profile_picture' => $new_data['profile_picture_url']
127
+ );
128
+ }
129
+
130
+ return $new_connected_account;
131
+
132
+ } else {
133
+
134
+ if ( $connection->is_wp_error() ) {
135
+ $error = $connection->get_wp_error();
136
+ } else {
137
+ $error = $connection->get_data();
138
+ }
139
+ return array( 'error' => sbi_formatted_error( $error ) );
140
+ }
141
+
142
+
143
+ }
144
+
145
+ /**
146
+ * Add data to current set of information about the account
147
+ * being connected
148
+ *
149
+ * @param $data array
150
+ *
151
+ * @return bool
152
+ *
153
+ * @since 5.10
154
+ */
155
+ public function add_account_data( $data ) {
156
+ $data['id'] = isset( $data['id'] ) ? $data['id'] : $data['user_id'];
157
+ if ( ! isset( $data['id'] ) ) {
158
+ return false;
159
+ }
160
+ if ( ! isset( $data['access_token'] ) ) {
161
+ return false;
162
+ }
163
+
164
+ $access_token = isset( $data['access_token'] ) ? $data['access_token'] : '';
165
+ $page_access_token = isset( $data['page_access_token'] ) ? $data['page_access_token'] : '';
166
+ $username = isset( $data['username'] ) ? $data['username'] : '';
167
+ $name = isset( $data['name'] ) ? $data['name'] : '';
168
+ $profile_picture = isset( $data['profile_picture_url'] ) ? $data['profile_picture_url'] : '';
169
+ if ( empty( $profile_picture ) ) {
170
+ $profile_picture = isset( $data['profile_picture'] ) ? $data['profile_picture'] : '';
171
+ }
172
+ $user_id = isset( $data['id'] ) ? $data['id'] : '';
173
+ $type = isset( $data['type'] ) ? $data['type'] : 'basic';
174
+ $account_type = isset( $data['account_type'] ) ? $data['account_type'] : 'business';
175
+ $this->id = $user_id;
176
+ $this->account_data = array(
177
+ 'access_token' => $access_token,
178
+ 'user_id' => $user_id,
179
+ 'username' => $username,
180
+ 'is_valid' => true,
181
+ 'last_checked' => time(),
182
+ 'type' => $type,
183
+ 'account_type' => $account_type,
184
+ 'profile_picture' => ''
185
+ );
186
+
187
+ if ( $type === 'business' ) {
188
+ $this->account_data['use_tagged'] = '1';
189
+ $this->account_data['name'] = sbi_sanitize_emoji( $name );
190
+ $this->account_data['profile_picture'] = $profile_picture;
191
+ $this->account_data['local_avatar'] = SB_Instagram_Connected_Account::create_local_avatar( $username, $profile_picture );
192
+ $this->account_data['page_access_token'] = $page_access_token;
193
+ }
194
+
195
+ if ( isset( $data[ 'expires_timestamp']) ) {
196
+ $this->account_data['expires_timestamp'] = $data[ 'expires_timestamp'];
197
+ }
198
+
199
+ return true;
200
+ }
201
+
202
+ /**
203
+ * Save data for new or existing connected account
204
+ *
205
+ * @return bool
206
+ *
207
+ * @since 5.10
208
+ */
209
+ public function update_stored_account() {
210
+ $options = sbi_get_database_settings();
211
+ $connected_accounts = isset( $options['connected_accounts'] ) ? $options['connected_accounts'] : array();
212
+ $options['connected_accounts'] = $connected_accounts;
213
+
214
+ if ( ! empty( $this->account_data ) ) {
215
+ $options['connected_accounts'][ $this->id ] = $this->account_data;
216
+ update_option( 'sb_instagram_settings', $options );
217
+
218
+ return true;
219
+ }
220
+ return false;
221
+ }
222
+
223
+ /**
224
+ * Actions after updating or connecting an account
225
+ *
226
+ * @since 5.10
227
+ */
228
+ public function after_update() {
229
+ global $sb_instagram_posts_manager;
230
+ $sb_instagram_posts_manager->remove_connected_account_error( $this->account_data );
231
+ $sb_instagram_posts_manager->add_action_log( 'Connection or updating account ' . $this->account_data['username'] );
232
+
233
+ do_action( 'sbi_account_connector_after_update', $this->account_data );
234
+ }
235
+
236
+ /**
237
+ * @return array
238
+ *
239
+ * @since 5.10
240
+ */
241
+ public static function stored_connected_accounts() {
242
+ $options = sbi_get_database_settings();
243
+ $connected_accounts = isset( $options['connected_accounts'] ) ? $options['connected_accounts'] : array();
244
+ return $connected_accounts;
245
+ }
246
+ }
inc/admin/main.php CHANGED
@@ -575,6 +575,10 @@ function sb_instagram_settings_page() {
575
  SB_Instagram_Cron_Updater::start_cron_job( $sbi_cache_cron_interval, $sbi_cache_cron_time, $sbi_cache_cron_am_pm );
576
  }
577
 
 
 
 
 
578
  } //End config tab post
579
 
580
  if( isset($_POST[ $sb_instagram_customize_hidden_field ]) && $_POST[ $sb_instagram_customize_hidden_field ] == 'Y' ) {
@@ -804,6 +808,7 @@ function sb_instagram_settings_page() {
804
  </div>
805
  <?php
806
  $sb_instagram_type = 'user';
 
807
  $returned_data = sbi_get_connected_accounts_data( $sb_instagram_at );
808
  $sb_instagram_at = $returned_data['access_token'];
809
  $connected_accounts = $returned_data['connected_accounts'];
@@ -816,169 +821,8 @@ function sb_instagram_settings_page() {
816
 
817
  $new_user_name = false;
818
 
819
-
820
- if( isset($_GET['access_token']) && isset($_GET['graph_api']) && empty($_POST) ) { ?>
821
- <?php
822
- $access_token = sbi_maybe_clean(urldecode($_GET['access_token']));
823
- //
824
- $url = 'https://graph.facebook.com/me/accounts?fields=instagram_business_account,access_token&limit=500&access_token='.$access_token;
825
- $args = array(
826
- 'timeout' => 60,
827
- 'sslverify' => false
828
- );
829
- $result = wp_remote_get( $url, $args );
830
- $pages_data = '{}';
831
- if ( ! is_wp_error( $result ) ) {
832
- $pages_data = $result['body'];
833
- } else {
834
- $page_error = $result;
835
- }
836
-
837
- $pages_data_arr = json_decode($pages_data);
838
- $num_accounts = 0;
839
- if(isset($pages_data_arr)){
840
- $num_accounts = is_array( $pages_data_arr->data ) ? count( $pages_data_arr->data ) : 0;
841
- }
842
- ?>
843
- <div id="sbi_config_info" class="sb_list_businesses sbi_num_businesses_<?php echo $num_accounts; ?>">
844
- <div class="sbi_config_modal">
845
- <div class="sbi-managed-pages">
846
- <?php if ( isset( $page_error ) && isset( $page_error->errors ) ) {
847
- foreach ($page_error->errors as $key => $item) {
848
- echo '<div class="sbi_user_id_error" style="display:block;"><strong>Connection Error: </strong>' . $key . ': ' . $item[0] . '</div>';
849
- }
850
- }
851
- ?>
852
- <?php if( empty($pages_data_arr->data) ) : ?>
853
- <span id="sbi-bus-account-error">
854
- <p style="margin-top: 5px;"><b style="font-size: 16px">Couldn't find Business Profile</b><br />
855
- Uh oh. It looks like this Facebook account is not currently connected to an Instagram Business profile. Please check that you are logged into the <a href="https://www.facebook.com/" target="_blank">Facebook account</a> in this browser which is associated with your Instagram Business Profile.</p>
856
- <p><b style="font-size: 16px">Why do I need a Business Profile?</b><br />
857
- A Business Profile is only required if you are displaying a Hashtag feed. If you want to display a regular User feed then you can do this by selecting to connect a Personal account instead. For directions on how to convert your Personal profile into a Business profile please <a href="https://smashballoon.com/instagram-business-profiles" target="_blank">see here</a>.</p>
858
- </span>
859
-
860
- <?php elseif ( $num_accounts === 0 ): ?>
861
- <span id="sbi-bus-account-error">
862
- <p style="margin-top: 5px;"><b style="font-size: 16px">Couldn't find Business Profile</b><br />
863
- Uh oh. It looks like this Facebook account is not currently connected to an Instagram Business profile. Please check that you are logged into the <a href="https://www.facebook.com/" target="_blank">Facebook account</a> in this browser which is associated with your Instagram Business Profile.</p>
864
- <p>If you are, in fact, logged-in to the correct account please make sure you have Instagram accounts connected with your Facebook account by following <a href="https://smashballoon.com/reconnecting-an-instagram-business-profile/" target="_blank">this FAQ</a></p>
865
- </span>
866
- <?php else: ?>
867
- <p class="sbi-managed-page-intro"><b style="font-size: 16px;">Instagram Business profiles for this account</b><br /><i style="color: #666;">Note: In order to display a Hashtag feed you first need to select a Business profile below.</i></p>
868
- <?php if ( $num_accounts > 1 ) : ?>
869
- <div class="sbi-managed-page-select-all"><input type="checkbox" id="sbi-select-all" class="sbi-select-all"><label for="sbi-select-all">Select All</label></div>
870
- <?php endif; ?>
871
- <div class="sbi-scrollable-accounts">
872
-
873
- <?php foreach ( $pages_data_arr->data as $page => $page_data ) : ?>
874
-
875
- <?php if( isset( $page_data->instagram_business_account ) ) :
876
-
877
- $instagram_business_id = $page_data->instagram_business_account->id;
878
-
879
- $page_access_token = isset( $page_data->access_token ) ? $page_data->access_token : '';
880
-
881
- //Make another request to get page info
882
- $instagram_account_url = 'https://graph.facebook.com/'.$instagram_business_id.'?fields=name,username,profile_picture_url&access_token='.$access_token;
883
-
884
- $args = array(
885
- 'timeout' => 60,
886
- 'sslverify' => false
887
- );
888
- $result = wp_remote_get( $instagram_account_url, $args );
889
- $instagram_account_info = '{}';
890
- if ( ! is_wp_error( $result ) ) {
891
- $instagram_account_info = $result['body'];
892
- } else {
893
- $page_error = $result;
894
- }
895
-
896
- $instagram_account_data = json_decode($instagram_account_info);
897
-
898
- $instagram_biz_img = isset( $instagram_account_data->profile_picture_url ) ? $instagram_account_data->profile_picture_url : false;
899
- $selected_class = $instagram_business_id == $sb_instagram_user_id ? ' sbi-page-selected' : '';
900
-
901
- ?>
902
- <?php if ( isset( $page_error ) && isset( $page_error->errors ) ) :
903
- foreach ($page_error->errors as $key => $item) {
904
- echo '<div class="sbi_user_id_error" style="display:block;"><strong>Connection Error: </strong>' . $key . ': ' . $item[0] . '</div>';
905
- }
906
- else : ?>
907
- <div class="sbi-managed-page<?php echo $selected_class; ?>" data-page-token="<?php echo esc_attr( $page_access_token ); ?>" data-token="<?php echo esc_attr( $access_token ); ?>" data-page-id="<?php echo esc_attr( $instagram_business_id ); ?>">
908
- <div class="sbi-add-checkbox">
909
- <input id="sbi-<?php echo esc_attr( $instagram_business_id ); ?>" type="checkbox" name="sbi_managed_pages[]" value="<?php echo esc_attr( $instagram_account_info ); ?>">
910
- </div>
911
- <div class="sbi-managed-page-details">
912
- <label for="sbi-<?php echo esc_attr( $instagram_business_id ); ?>"><img class="sbi-page-avatar" border="0" height="50" width="50" src="<?php echo esc_url( $instagram_biz_img ); ?>"><b style="font-size: 16px;"><?php echo esc_html( $instagram_account_data->name ); ?></b>
913
- <br />@<?php echo esc_html( $instagram_account_data->username); ?><span style="font-size: 11px; margin-left: 5px;">(<?php echo esc_html( $instagram_business_id ); ?>)</span></label>
914
- </div>
915
- </div>
916
- <?php endif; ?>
917
-
918
- <?php endif; ?>
919
-
920
- <?php endforeach; ?>
921
-
922
- </div> <!-- end scrollable -->
923
- <p style="font-size: 11px; line-height: 1.5; margin-bottom: 0;"><i style="color: #666;">*<?php echo sprintf( __( 'Changing the password, updating privacy settings, or removing page admins for the related Facebook page may require %smanually reauthorizing our app%s to reconnect an account.', 'instagram-feed' ), '<a href="https://smashballoon.com/reauthorizing-our-instagram-facebook-app/" target="_blank" rel="noopener noreferrer">', '</a>' ); ?></i></p>
924
-
925
- <a href="JavaScript:void(0);" id="sbi-connect-business-accounts" class="button button-primary" disabled="disabled" style="margin-top: 20px;">Connect Accounts</a>
926
-
927
- <?php endif; ?>
928
-
929
- <a href="JavaScript:void(0);" class="sbi_modal_close"><i class="fa fa-times"></i></a>
930
- </div>
931
- </div>
932
- </div>
933
- <?php } elseif ( isset( $_GET['access_token'] ) && isset( $_GET['account_type'] ) && empty( $_POST ) ) {
934
- $access_token = sanitize_text_field( $_GET['access_token'] );
935
- $account_type = sanitize_text_field( $_GET['account_type'] );
936
- $user_id = sanitize_text_field( $_GET['id'] );
937
- $user_name = sanitize_text_field( $_GET['username'] );
938
- $expires_in = (int)$_GET['expires_in'];
939
- $expires_timestamp = time() + $expires_in;
940
-
941
- $new_account_details = array(
942
- 'access_token' => $access_token,
943
- 'account_type' => $account_type,
944
- 'user_id' => $user_id,
945
- 'username' => $user_name,
946
- 'expires_timestamp' => $expires_timestamp,
947
- 'type' => 'basic'
948
- );
949
-
950
-
951
- $matches_existing_personal = sbi_matches_existing_personal( $new_account_details );
952
- $button_text = $matches_existing_personal ? __( 'Update This Account', 'instagram-feed' ) : __( 'Connect This Account', 'instagram-feed' );
953
-
954
- $account_json = sbi_json_encode( $new_account_details );
955
-
956
- $already_connected_as_business_account = (isset( $connected_accounts[ $user_id ] ) && $connected_accounts[ $user_id ]['type'] === 'business');
957
-
958
- ?>
959
-
960
- <div id="sbi_config_info" class="sb_get_token">
961
- <div class="sbi_config_modal">
962
- <div class="sbi_ca_username"><strong><?php echo esc_html( $user_name ); ?></strong></div>
963
- <form action="<?php echo admin_url( 'admin.php?page=sb-instagram-feed' ); ?>" method="post">
964
- <p class="sbi_submit">
965
- <?php if ( $already_connected_as_business_account ) :
966
- _e( 'The Instagram account you are logged into is already connected as a "business" account. Remove the business account if you\'d like to connect as a basic account instead (not recommended).', 'instagram-feed' );
967
- ?>
968
- <?php else : ?>
969
- <input type="submit" name="sbi_submit" id="sbi_connect_account" class="button button-primary" value="<?php echo esc_html( $button_text ); ?>">
970
- <?php endif; ?>
971
- <input type="hidden" name="sbi_account_json" value="<?php echo esc_attr( $account_json ) ; ?>">
972
- <input type="hidden" name="sbi_connect_username" value="<?php echo esc_attr( $user_name ); ?>">
973
- <a href="JavaScript:void(0);" class="button button-secondary" id="sbi_switch_accounts"><?php esc_html_e( 'Switch Accounts', 'instagram-feed' ); ?></a>
974
- </p>
975
- </form>
976
- <a href="JavaScript:void(0);"><i class="sbi_modal_close fa fa-times"></i></a>
977
- </div>
978
- </div>
979
- <?php
980
- } elseif ( isset( $_POST['sbi_connect_username'] ) ) {
981
-
982
  $new_user_name = sanitize_text_field( $_POST['sbi_connect_username'] );
983
  $new_account_details = json_decode( stripslashes( $_POST['sbi_account_json'] ), true );
984
  array_map( 'sanitize_text_field', $new_account_details );
@@ -986,9 +830,9 @@ function sb_instagram_settings_page() {
986
  $updated_options = sbi_connect_basic_account( $new_account_details );
987
  $connected_accounts = $updated_options['connected_accounts'];
988
  $user_feed_ids = $updated_options['sb_instagram_user_id'];
989
- }?>
990
 
991
- <?php //Display connected page
992
  if (isset( $sbi_connected_page ) && strpos($sbi_connected_page, ':') !== false) {
993
 
994
  $sbi_connected_page_pieces = explode(":", $sbi_connected_page);
@@ -1046,13 +890,9 @@ function sb_instagram_settings_page() {
1046
  <?php if ( empty( $connected_accounts ) ) : ?>
1047
  <p class="sbi_no_accounts"><?php _e( 'No Instagram accounts connected. Click the button above to connect an account.', 'instagram-feed' ); ?></p><br />
1048
  <?php else:
1049
- if ( sbi_is_after_deprecation_deadline() ) {
1050
- $deprecated_connected_account_message = __( '<b>Action Needed:</b> Reconnect this account to allow feed to update.', 'instagram-feed' );
1051
- } else {
1052
- $deprecated_connected_account_message = __( '<b>Action Needed:</b> Reconnect this account before June 1, 2020 to avoid disruption with this feed.', 'instagram-feed' );
1053
- }
1054
 
1055
- $accounts_that_need_updating = sbi_get_user_names_of_personal_accounts_not_also_already_updated();
1056
  ?>
1057
  <?php foreach ( $connected_accounts as $account ) :
1058
  $username = $account['username'] ? $account['username'] : $account['user_id'];
@@ -1093,13 +933,13 @@ function sb_instagram_settings_page() {
1093
 
1094
  ?>
1095
  <div class="sbi_connected_account<?php echo $is_invalid_class . $updated_or_new_account_class; ?><?php if ( $in_user_feed ) echo ' sbi_account_active' ?> sbi_account_type_<?php echo $account_type; ?>" id="sbi_connected_account_<?php esc_attr_e( $account['user_id'] ); ?>" data-accesstoken="<?php esc_attr_e( $account['access_token'] ); ?>" data-userid="<?php esc_attr_e( $account['user_id'] ); ?>" data-username="<?php esc_attr_e( $account['username'] ); ?>" data-type="<?php esc_attr_e( $account_type ); ?>" data-permissions="<?php if ( $use_tagged ) echo 'tagged'; ?>">
1096
- <?php if ( $account_type === 'personal' && in_array( $username, $accounts_that_need_updating, true ) ) : ?>
1097
  <div class="sbi_deprecated">
1098
- <span><i class="fa fa-exclamation-circle" aria-hidden="true"></i><?php echo $deprecated_connected_account_message; ?> <button class="sbi_reconnect button-primary">Reconnect</button></span>
1099
  </div>
1100
  <?php endif; ?>
1101
  <div class="sbi_ca_alert">
1102
- <span><?php _e( 'The Access Token for this account is expired or invalid. Click the button above to attempt to renew it.', 'instagram-feed' ) ?></span>
1103
  </div>
1104
  <div class="sbi_ca_info">
1105
 
@@ -1108,23 +948,23 @@ function sb_instagram_settings_page() {
1108
  </div>
1109
 
1110
  <div class="sbi_ca_username">
1111
- <?php echo $profile_picture; ?>
1112
  <strong><?php echo $username; ?><span><?php echo sbi_account_type_display( $account_type, isset( $account['private'] ) ); ?></span></strong>
1113
  </div>
1114
 
1115
  <div class="sbi_ca_actions">
1116
- <?php if ( ! $in_user_feed ) : ?>
1117
  <a href="JavaScript:void(0);" class="sbi_use_in_user_feed button-primary"><i class="fa fa-plus-circle" aria-hidden="true"></i><?php _e( 'Add to Primary Feed', 'instagram-feed' ); ?></a>
1118
- <?php else : ?>
1119
  <a href="JavaScript:void(0);" class="sbi_remove_from_user_feed button-primary"><i class="fa fa-minus-circle" aria-hidden="true"></i><?php _e( 'Remove from Primary Feed', 'instagram-feed' ); ?></a>
1120
- <?php endif; ?>
1121
  <a class="sbi_ca_token_shortcode button-secondary" href="JavaScript:void(0);"><i class="fa fa-chevron-circle-right" aria-hidden="true"></i><?php _e( 'Add to another Feed', 'instagram-feed' ); ?></a>
1122
  <a class="sbi_ca_show_token button-secondary" href="JavaScript:void(0);" title="<?php _e('Show access token and account info', 'instagram-feed'); ?>"><i class="fa fa-cog"></i></a>
1123
- <?php if ( $is_private ) :
1124
- $expires_in = max( 0, floor( ($account['expires_timestamp'] - time()) / DAY_IN_SECONDS ) );
1125
- $message = $expires_in > 0 ? sprintf( __( 'Expires in %s days', 'instagram-feed' ), $expires_in ) : __( 'Access Token Expired', 'instagram-feed' );
1126
- $alert_class = $expires_in < 10 ? ' sbi_alert' : '';
1127
- ?>
1128
  <div class="sbi_is_private<?php echo esc_attr( $alert_class ); ?>">
1129
  <span><?php echo esc_html( $message ); ?></span>
1130
  <a class="sbi_tooltip_link sbi_tooltip_outside" href="JavaScript:void(0);" style="position: relative; top: 2px;"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
@@ -1132,7 +972,7 @@ function sb_instagram_settings_page() {
1132
  <a href="https://api.instagram.com/oauth/authorize?app_id=423965861585747&redirect_uri=https://api.smashballoon.com/instagram-basic-display-redirect.php&response_type=code&scope=user_profile,user_media&state=<?php echo admin_url( 'admin.php?page=sb-instagram-feed' ); ?>" class="button button-secondary"><?php _e( 'Refresh now', 'instagram-feed' ); ?></a>
1133
  </div>
1134
  <p class="sbi_tooltip sbi-more-info" style="display: none; width: 100%; box-sizing: border-box;"><?php echo sprintf( __( 'This account is a "private" account on Instagram. It needs to be manually reconnected every 60 days. %sChange this account to be "public"%s to have access tokens that are automatically refreshed.', 'instagram-feed' ), '<a href="https://help.instagram.com/116024195217477/In" target="_blank">', '</a>' ); ?></p>
1135
- <?php endif; ?>
1136
 
1137
  </div>
1138
 
@@ -3283,22 +3123,53 @@ if ( $wpdb->get_var( "show tables like '$table_name'" ) != $table_name ) {
3283
  echo "\n";
3284
  }
3285
  }
3286
-
3287
  ?>
3288
 
3289
- ## Error Log: ##
3290
  <?php
3291
  global $sb_instagram_posts_manager;
3292
  $errors = $sb_instagram_posts_manager->get_errors();
3293
- if ( ! empty( $errors ) ) :
3294
- foreach ( $errors as $type => $error ) :
3295
- echo $type . ': ' . $error[1] . "\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3296
  endforeach;
3297
  endif;
 
3298
  $error_page = $sb_instagram_posts_manager->get_error_page();
3299
  if ( $error_page ) {
3300
  echo 'Feed with error: ' . esc_url( get_the_permalink( $error_page ) ). "\n";
3301
- }?>
3302
 
3303
  ## GDPR: ##
3304
  <?php
575
  SB_Instagram_Cron_Updater::start_cron_job( $sbi_cache_cron_interval, $sbi_cache_cron_time, $sbi_cache_cron_am_pm );
576
  }
577
 
578
+ global $sb_instagram_posts_manager;
579
+ $sb_instagram_posts_manager->add_action_log( 'Saved settings on the configure tab.' );
580
+ $sb_instagram_posts_manager->clear_api_request_delays();
581
+
582
  } //End config tab post
583
 
584
  if( isset($_POST[ $sb_instagram_customize_hidden_field ]) && $_POST[ $sb_instagram_customize_hidden_field ] == 'Y' ) {
808
  </div>
809
  <?php
810
  $sb_instagram_type = 'user';
811
+ $new_user_name = false;
812
  $returned_data = sbi_get_connected_accounts_data( $sb_instagram_at );
813
  $sb_instagram_at = $returned_data['access_token'];
814
  $connected_accounts = $returned_data['connected_accounts'];
821
 
822
  $new_user_name = false;
823
 
824
+ SBI_Account_Connector::maybe_launch_modals( $sb_instagram_user_id );
825
+ if ( isset( $_POST['sbi_connect_username'] ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
826
  $new_user_name = sanitize_text_field( $_POST['sbi_connect_username'] );
827
  $new_account_details = json_decode( stripslashes( $_POST['sbi_account_json'] ), true );
828
  array_map( 'sanitize_text_field', $new_account_details );
830
  $updated_options = sbi_connect_basic_account( $new_account_details );
831
  $connected_accounts = $updated_options['connected_accounts'];
832
  $user_feed_ids = $updated_options['sb_instagram_user_id'];
833
+ }
834
 
835
+ //Display connected page
836
  if (isset( $sbi_connected_page ) && strpos($sbi_connected_page, ':') !== false) {
837
 
838
  $sbi_connected_page_pieces = explode(":", $sbi_connected_page);
890
  <?php if ( empty( $connected_accounts ) ) : ?>
891
  <p class="sbi_no_accounts"><?php _e( 'No Instagram accounts connected. Click the button above to connect an account.', 'instagram-feed' ); ?></p><br />
892
  <?php else:
893
+ $doing_account_error_messages = count( $connected_accounts ) > 1;
894
+ global $sb_instagram_posts_manager;
 
 
 
895
 
 
896
  ?>
897
  <?php foreach ( $connected_accounts as $account ) :
898
  $username = $account['username'] ? $account['username'] : $account['user_id'];
933
 
934
  ?>
935
  <div class="sbi_connected_account<?php echo $is_invalid_class . $updated_or_new_account_class; ?><?php if ( $in_user_feed ) echo ' sbi_account_active' ?> sbi_account_type_<?php echo $account_type; ?>" id="sbi_connected_account_<?php esc_attr_e( $account['user_id'] ); ?>" data-accesstoken="<?php esc_attr_e( $account['access_token'] ); ?>" data-userid="<?php esc_attr_e( $account['user_id'] ); ?>" data-username="<?php esc_attr_e( $account['username'] ); ?>" data-type="<?php esc_attr_e( $account_type ); ?>" data-permissions="<?php if ( $use_tagged ) echo 'tagged'; ?>">
936
+ <?php if ( $doing_account_error_messages && $sb_instagram_posts_manager->connected_account_has_error( $account ) ) : ?>
937
  <div class="sbi_deprecated">
938
+ <span><i class="fa fa-exclamation-circle" aria-hidden="true"></i><?php _e( 'Feeds using this account might not be updating due to an error. Try viewing these feeds after reconnecting the account and saving your settings below.', 'instagram-feed' ); ?></span>
939
  </div>
940
  <?php endif; ?>
941
  <div class="sbi_ca_alert">
942
+ <span><?php _e( 'The Access Token for this account is expired or invalid. Click the button above to attempt to renew it.', 'instagram-feed' ); ?></span>
943
  </div>
944
  <div class="sbi_ca_info">
945
 
948
  </div>
949
 
950
  <div class="sbi_ca_username">
951
+ <?php echo $profile_picture; ?>
952
  <strong><?php echo $username; ?><span><?php echo sbi_account_type_display( $account_type, isset( $account['private'] ) ); ?></span></strong>
953
  </div>
954
 
955
  <div class="sbi_ca_actions">
956
+ <?php if ( ! $in_user_feed ) : ?>
957
  <a href="JavaScript:void(0);" class="sbi_use_in_user_feed button-primary"><i class="fa fa-plus-circle" aria-hidden="true"></i><?php _e( 'Add to Primary Feed', 'instagram-feed' ); ?></a>
958
+ <?php else : ?>
959
  <a href="JavaScript:void(0);" class="sbi_remove_from_user_feed button-primary"><i class="fa fa-minus-circle" aria-hidden="true"></i><?php _e( 'Remove from Primary Feed', 'instagram-feed' ); ?></a>
960
+ <?php endif; ?>
961
  <a class="sbi_ca_token_shortcode button-secondary" href="JavaScript:void(0);"><i class="fa fa-chevron-circle-right" aria-hidden="true"></i><?php _e( 'Add to another Feed', 'instagram-feed' ); ?></a>
962
  <a class="sbi_ca_show_token button-secondary" href="JavaScript:void(0);" title="<?php _e('Show access token and account info', 'instagram-feed'); ?>"><i class="fa fa-cog"></i></a>
963
+ <?php if ( $is_private ) :
964
+ $expires_in = max( 0, floor( ($account['expires_timestamp'] - time()) / DAY_IN_SECONDS ) );
965
+ $message = $expires_in > 0 ? sprintf( __( 'Expires in %s days', 'instagram-feed' ), $expires_in ) : __( 'Access Token Expired', 'instagram-feed' );
966
+ $alert_class = $expires_in < 10 ? ' sbi_alert' : '';
967
+ ?>
968
  <div class="sbi_is_private<?php echo esc_attr( $alert_class ); ?>">
969
  <span><?php echo esc_html( $message ); ?></span>
970
  <a class="sbi_tooltip_link sbi_tooltip_outside" href="JavaScript:void(0);" style="position: relative; top: 2px;"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
972
  <a href="https://api.instagram.com/oauth/authorize?app_id=423965861585747&redirect_uri=https://api.smashballoon.com/instagram-basic-display-redirect.php&response_type=code&scope=user_profile,user_media&state=<?php echo admin_url( 'admin.php?page=sb-instagram-feed' ); ?>" class="button button-secondary"><?php _e( 'Refresh now', 'instagram-feed' ); ?></a>
973
  </div>
974
  <p class="sbi_tooltip sbi-more-info" style="display: none; width: 100%; box-sizing: border-box;"><?php echo sprintf( __( 'This account is a "private" account on Instagram. It needs to be manually reconnected every 60 days. %sChange this account to be "public"%s to have access tokens that are automatically refreshed.', 'instagram-feed' ), '<a href="https://help.instagram.com/116024195217477/In" target="_blank">', '</a>' ); ?></p>
975
+ <?php endif; ?>
976
 
977
  </div>
978
 
3123
  echo "\n";
3124
  }
3125
  }
 
3126
  ?>
3127
 
3128
+ ## Errors: ##
3129
  <?php
3130
  global $sb_instagram_posts_manager;
3131
  $errors = $sb_instagram_posts_manager->get_errors();
3132
+ if ( ! empty( $errors['resizing'] ) ) :
3133
+ echo '* Resizing *' . "\n";
3134
+ echo $errors['resizing'] . "\n";
3135
+ endif;
3136
+ if ( ! empty( $errors['database_create'] ) ) :
3137
+ echo '* Database Create *' . "\n";
3138
+ echo $errors['database_create'] . "\n";
3139
+ endif;
3140
+ if ( ! empty( $errors['upload_dir'] ) ) :
3141
+ echo '* Uploads Directory *' . "\n";
3142
+ echo $errors['upload_dir'] . "\n";
3143
+ endif;
3144
+ if ( ! empty( $errors['connection'] ) ) :
3145
+ echo '* API/WP_HTTP Request *' . "\n";
3146
+ var_export( $errors['connection'] );
3147
+ endif;
3148
+ ?>
3149
+
3150
+ ## Error Log: ##
3151
+ <?php
3152
+ $error_log = $sb_instagram_posts_manager->get_error_log();
3153
+ if ( ! empty( $error_log ) ) :
3154
+ foreach ( $error_log as $error ) :
3155
+ echo $error . "\n";
3156
+ endforeach;
3157
+ endif;
3158
+ ?>
3159
+
3160
+ ## Action Log: ##
3161
+ <?php
3162
+ $actions = $sb_instagram_posts_manager->get_action_log();
3163
+ if ( ! empty( $actions ) ) :
3164
+ foreach ( $actions as $action ) :
3165
+ echo $action . "\n";
3166
  endforeach;
3167
  endif;
3168
+ /*
3169
  $error_page = $sb_instagram_posts_manager->get_error_page();
3170
  if ( $error_page ) {
3171
  echo 'Feed with error: ' . esc_url( get_the_permalink( $error_page ) ). "\n";
3172
+ }*/?>
3173
 
3174
  ## GDPR: ##
3175
  <?php
inc/class-sb-instagram-api-connect.php CHANGED
@@ -47,7 +47,7 @@ class SB_Instagram_API_Connect
47
  public function __construct( $connected_account_or_url, $endpoint = '', $params = array() ) {
48
  if ( is_array( $connected_account_or_url ) && isset( $connected_account_or_url['access_token'] ) ) {
49
  $this->set_url( $connected_account_or_url, $endpoint, $params );
50
- } elseif ( strpos( $connected_account_or_url, 'https' ) !== false ) {
51
  $this->url = $connected_account_or_url;
52
  } else {
53
  $this->url = '';
@@ -160,8 +160,13 @@ class SB_Instagram_API_Connect
160
  *
161
  * @since 2.0/5.0
162
  */
163
- public function is_instagram_error() {
164
- return (isset( $this->response['meta']['error_type'] ) || isset( $this->response['error']['message'] ));
 
 
 
 
 
165
  }
166
 
167
  /**
@@ -182,6 +187,7 @@ class SB_Instagram_API_Connect
182
  }
183
 
184
  $this->response = $response;
 
185
  }
186
 
187
  /**
@@ -198,118 +204,13 @@ class SB_Instagram_API_Connect
198
  global $sb_instagram_posts_manager;
199
  delete_option( 'sbi_dismiss_critical_notice' );
200
 
201
- $sb_instagram_posts_manager->update_error_page( get_the_ID() );
202
-
203
- $error_time = 300;
204
- if ( isset( $response['error']['message'] ) ) {
205
- if ( (int)$response['error']['code'] === 100 ) {
206
- $options = get_option( 'sb_instagram_settings', array() );
207
-
208
- $connected_accounts = isset( $options['connected_accounts'] ) ? $options['connected_accounts'] : array();
209
- $user_name = '';
210
- foreach ( $connected_accounts as $connected_account ) {
211
- if ( $connected_account['access_token'] === $error_connected_account['access_token'] ) {
212
- $connected_accounts[ $connected_account['user_id'] ]['is_valid'] = false;
213
- $connected_accounts[ $connected_account['user_id'] ]['last_checked'] = time();
214
- if ( isset( $connected_account['username'] ) ) {
215
- $user_name = $connected_account['username'];
216
- } else {
217
- $user_name = $connected_account['user_id'];
218
- }
219
- }
220
- }
221
-
222
- $options['connected_accounts'] = $connected_accounts;
223
-
224
- update_option( 'sb_instagram_settings', $options );
225
- $cap = current_user_can( 'manage_instagram_feed_options' ) ? 'manage_instagram_feed_options' : 'manage_options';
226
- $cap = apply_filters( 'sbi_settings_pages_capability', $cap );
227
- if ( (int)$response['error']['code'] === 100 && $error_connected_account['type'] === 'business' ) {
228
- $error = '<p><b>' . sprintf( __( 'Error: Permission for the Smash Balloon App is not valid or has expired.', 'instagram-feed' ), $user_name ) . ' ' . __( 'Feed will not update.', 'instagram-feed' ) . '</b></p>';
229
- $error .= '<p>' . sprintf( __( 'API error %s:', 'instagram-feed' ), $response['error']['code'] ) . ' ' . $response['error']['message'] . '</p>';
230
- $sb_instagram_posts_manager->add_error( 'at_100_' . $user_name, array( 'Business 100 Error', $error, $response['error']['code'] ) );
231
- if ( current_user_can( $cap ) ) {
232
- $error .= '<p class="sbi-error-directions"><a href="https://smashballoon.com/instagram-feed/docs/errors/" target="_blank" rel="noopener">' . __( 'Directions on how to resolve this issue', 'instagram-feed' ) . '</a></p>';
233
- }
234
- $sb_instagram_posts_manager->add_frontend_error( 'at_100_' . $user_name, $error );
235
-
236
- } else {
237
- //set here
238
- $error = '<p><b>' . sprintf( __( 'Error: Access Token for %s is not valid or has expired.', 'instagram-feed' ), $user_name ) . ' ' . __( 'Feed will not update.', 'instagram-feed' ) . '</b></p>';
239
- $error .= '<p>' . __( 'There\'s an issue with the Instagram Access Token that you are using. Please obtain a new Access Token on the plugin\'s Settings page.', 'instagram-feed' );
240
- $error .= '<p>' . sprintf( __( 'API error %s:', 'instagram-feed' ), $response['error']['code'] ) . ' ' . $response['error']['message'] . '</p>';
241
- $sb_instagram_posts_manager->add_error( 'at_' . $user_name, array( 'Access Token Error', $error, $response['error']['code'] ) );
242
- $link = admin_url( '?page=sb-instagram-feed' );
243
- if ( current_user_can( $cap ) ) {
244
- $error .= '<p class="sbi-error-directions sbi-reconnect"><a href="' . esc_url( $link ) . '" target="_blank" rel="noopener">' . __( 'Reconnect your account in the admin area', 'instagram-feed' ) . '</a></p>';
245
- }
246
- $sb_instagram_posts_manager->add_frontend_error( 'at_' . $user_name, $error );
247
- }
248
-
249
- $error_time = 3600;
250
- $account_id = $error_connected_account['user_id'];
251
- } elseif ( (int)$response['error']['code'] === 18 ) {
252
- $options = get_option( 'sb_instagram_settings', array() );
253
-
254
- $connected_accounts = isset( $options['connected_accounts'] ) ? $options['connected_accounts'] : array();
255
- $user_name = '';
256
- $hashtag_refresh_time = time() + (7*24*60*60);
257
- foreach ( $connected_accounts as $connected_account ) {
258
- if ( $connected_account['access_token'] === $error_connected_account['access_token'] ) {
259
- if ( ! isset( $connected_accounts[ $connected_account['user_id'] ]['hashtag_limit_reached'] ) ) {
260
- $connected_accounts[ $connected_account['user_id'] ]['hashtag_limit_reached'] = time();
261
- } else {
262
- $hashtag_refresh_time = $connected_accounts[ $connected_account['user_id'] ]['hashtag_limit_reached'];
263
- }
264
- if ( isset( $connected_account['username'] ) ) {
265
- $user_name = $connected_account['username'];
266
- } else {
267
- $user_name = $connected_account['user_id'];
268
- }
269
- }
270
- }
271
-
272
- $options['connected_accounts'] = $connected_accounts;
273
-
274
- update_option( 'sb_instagram_settings', $options );
275
- global $sb_instagram_posts_manager;
276
- $error = '<p><b>' . __( 'Error: Hashtag limit of 30 unique hashtags per week has been reached.', 'instagram-feed' ) . '</b>';
277
- $error .= '<p>' . __( 'If you need to display more than 30 hashtag feeds on your site, consider connecting an additional business account from a separate Instagram and Facebook account.', 'instagram-feed' );
278
-
279
- $sb_instagram_posts_manager->add_frontend_error( 'hashtag_limit_reached', $error );
280
- $sb_instagram_posts_manager->add_error( 'error_18', array( 'Too many hashtags', $error ) );
281
-
282
- } elseif ( (int)$response['error']['code'] === 10 ) {
283
- $user_name = $error_connected_account['username'];
284
 
285
- $error = '<p><b>' . sprintf( __( 'Error: Connected account for the user %s does not have permission to use this feed type.', 'instagram-feed' ), $user_name ) .'</b></p>';
286
- $error .= '<p>' . __( 'Try using the big blue button on the "Configure" tab to reconnect the account and update its permissions.', 'instagram-feed' ) . '</p>';
287
-
288
- $sb_instagram_posts_manager->add_frontend_error( 'hashtag_limit_reached', $error );
289
-
290
- } elseif ( (int)$response['error']['code'] === 24 ) {
291
- $error = '<p><b>' . __( 'Error: Cannot retrieve posts for this hashtag.', 'instagram-feed' ) .'</b></p>';
292
- $error .= '<p>' . $response['error']['error_user_msg'] . '</p>';
293
-
294
- $sb_instagram_posts_manager->add_frontend_error( 'hashtag_error', $error );
295
- } else {
296
-
297
- $error = '<p>' .sprintf( __( 'API error %s:', 'instagram-feed' ), $response['error']['code'] ) . ' ' . $response['error']['message'] . '</p>';
298
-
299
- $sb_instagram_posts_manager->add_frontend_error( $response['error']['type'], $error );
300
- $sb_instagram_posts_manager->add_error( 'api', array( 'Api Error', $error, $response['error']['code'] ) );
301
- }
302
-
303
- if ( ! empty( $account_id ) ) {
304
- $sb_instagram_posts_manager->add_api_request_delay( $error_time, $account_id );
305
- } else {
306
- $sb_instagram_posts_manager->add_api_request_delay( $error_time );
307
- }
308
 
 
 
309
  }
310
-
311
-
312
-
313
  }
314
 
315
  /**
@@ -322,18 +223,8 @@ class SB_Instagram_API_Connect
322
  public static function handle_wp_remote_get_error( $response ) {
323
  global $sb_instagram_posts_manager;
324
  delete_option( 'sbi_dismiss_critical_notice' );
325
- $sb_instagram_posts_manager->update_error_page( get_the_ID() );
326
-
327
- $message = sprintf( __( 'Error connecting to %s.', 'instagram-feed' ), $response['url'] ). ' ';
328
- if ( isset( $response['response'] ) && isset( $response['response']->errors ) ) {
329
- foreach ( $response['response']->errors as $key => $item ) {
330
- $message .= ' '.$key . ' - ' . $item[0] . ' |';
331
- }
332
- }
333
-
334
- $sb_instagram_posts_manager->add_api_request_delay( 300 );
335
 
336
- $sb_instagram_posts_manager->add_error( 'connection', array( 'Error connecting', $message ) );
337
  }
338
 
339
  /**
@@ -360,7 +251,7 @@ class SB_Instagram_API_Connect
360
  $url = 'https://graph.instagram.com/me?fields=id,username,media_count&access_token=' . sbi_maybe_clean( $connected_account['access_token'] );
361
  } else {
362
  $num = min( $num, 200 );
363
- $url = 'https://graph.instagram.com/' . sbi_maybe_clean( $connected_account['user_id'] ) . '/media?fields=media_url,thumbnail_url,caption,id,media_type,timestamp,username,comments_count,like_count,permalink,children{media_url,id,media_type,timestamp,permalink,thumbnail_url}&limit='.$num.'&access_token=' . sbi_maybe_clean( $connected_account['access_token'] );
364
  }
365
  } elseif ( $account_type === 'personal' ) {
366
  if ( $endpoint_slug === 'header' ) {
@@ -374,7 +265,7 @@ class SB_Instagram_API_Connect
374
  $url = 'https://graph.facebook.com/' . $connected_account['user_id'] . '?fields=biography,id,username,website,followers_count,media_count,profile_picture_url,name&access_token=' . sbi_maybe_clean( $connected_account['access_token'] );
375
  } else {
376
  $num = min( $num, 200 );
377
- $url = 'https://graph.facebook.com/' . $connected_account['user_id'] . '/media?fields=media_url,thumbnail_url,caption,id,media_type,timestamp,username,comments_count,like_count,permalink,children{media_url,id,media_type,timestamp,permalink,thumbnail_url}&limit='.$num.'&access_token=' . sbi_maybe_clean( $connected_account['access_token'] );
378
  }
379
  }
380
 
47
  public function __construct( $connected_account_or_url, $endpoint = '', $params = array() ) {
48
  if ( is_array( $connected_account_or_url ) && isset( $connected_account_or_url['access_token'] ) ) {
49
  $this->set_url( $connected_account_or_url, $endpoint, $params );
50
+ } elseif ( ! is_array( $connected_account_or_url ) && strpos( $connected_account_or_url, 'https' ) !== false ) {
51
  $this->url = $connected_account_or_url;
52
  } else {
53
  $this->url = '';
160
  *
161
  * @since 2.0/5.0
162
  */
163
+ public function is_instagram_error( $response = false ) {
164
+
165
+ if ( ! $response ) {
166
+ $response = $this->response;
167
+ }
168
+
169
+ return (isset( $response['error'] ));
170
  }
171
 
172
  /**
187
  }
188
 
189
  $this->response = $response;
190
+
191
  }
192
 
193
  /**
204
  global $sb_instagram_posts_manager;
205
  delete_option( 'sbi_dismiss_critical_notice' );
206
 
207
+ $type = isset( $response['error']['code'] ) && (int)$response['error']['code'] === 18 ? 'hashtag_limit' : 'api';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
 
209
+ $sb_instagram_posts_manager->add_error( $type, $response, $error_connected_account );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
 
211
+ if ( $type === 'hashtag_limit' ) {
212
+ $sb_instagram_posts_manager->maybe_set_display_error( $type, $response );
213
  }
 
 
 
214
  }
215
 
216
  /**
223
  public static function handle_wp_remote_get_error( $response ) {
224
  global $sb_instagram_posts_manager;
225
  delete_option( 'sbi_dismiss_critical_notice' );
 
 
 
 
 
 
 
 
 
 
226
 
227
+ $sb_instagram_posts_manager->add_error( 'wp_remote_get', $response );
228
  }
229
 
230
  /**
251
  $url = 'https://graph.instagram.com/me?fields=id,username,media_count&access_token=' . sbi_maybe_clean( $connected_account['access_token'] );
252
  } else {
253
  $num = min( $num, 200 );
254
+ $url = 'https://graph.instagram.com/' . sbi_maybe_clean( $connected_account['user_id'] ) . '/media?fields=media_url,thumbnail_url,caption,id,media_type,timestamp,username,comments_count,like_count,permalink,children%7Bmedia_url,id,media_type,timestamp,permalink,thumbnail_url%7D&limit='.$num.'&access_token=' . sbi_maybe_clean( $connected_account['access_token'] );
255
  }
256
  } elseif ( $account_type === 'personal' ) {
257
  if ( $endpoint_slug === 'header' ) {
265
  $url = 'https://graph.facebook.com/' . $connected_account['user_id'] . '?fields=biography,id,username,website,followers_count,media_count,profile_picture_url,name&access_token=' . sbi_maybe_clean( $connected_account['access_token'] );
266
  } else {
267
  $num = min( $num, 200 );
268
+ $url = 'https://graph.facebook.com/' . $connected_account['user_id'] . '/media?fields=media_url,thumbnail_url,caption,id,media_type,timestamp,username,comments_count,like_count,permalink,children%7Bmedia_url,id,media_type,timestamp,permalink,thumbnail_url%7D&limit='.$num.'&access_token=' . sbi_maybe_clean( $connected_account['access_token'] );
269
  }
270
  }
271
 
inc/class-sb-instagram-connected-account.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Class SB_Instagram_Connected_Account
4
+ *
5
+ * Used for parsing data from connected accounts and getting
6
+ * data related to an account using searches.
7
+ *
8
+ * @since 5.10
9
+ */
10
+
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ die( '-1' );
13
+ }
14
+
15
+ class SB_Instagram_Connected_Account {
16
+
17
+ /**
18
+ * @var array
19
+ *
20
+ * @since 5.10
21
+ */
22
+ public $account;
23
+
24
+ public function construct( $search_term_or_account, $search_type = 'user' ) {
25
+ if ( is_array( $search_term_or_account ) ) {
26
+ $this->account = $search_term_or_account;
27
+ } else {
28
+ $this->account = SB_Instagram_Connected_Account::lookup( $search_term_or_account, $search_type );
29
+ }
30
+ }
31
+
32
+ /**
33
+ * @return array
34
+ *
35
+ * @since 5.10
36
+ */
37
+ public function get_account_data() {
38
+ return $this->account;
39
+ }
40
+
41
+ /**
42
+ * Returns data for a connected account based on a search by term
43
+ * or type (business, user)
44
+ *
45
+ * @param $search_term string
46
+ * @param string $search_type string
47
+ *
48
+ * @return array|bool|mixed
49
+ *
50
+ * @since 5.10
51
+ */
52
+ public static function lookup( $search_term, $search_type = 'user' ) {
53
+ $options = sbi_get_database_settings();
54
+ $connected_accounts = isset( $options['connected_accounts'] ) ? $options['connected_accounts'] : array();
55
+
56
+ if ( is_array( $search_term ) ) {
57
+ return false;
58
+ }
59
+
60
+ if ( $search_type === 'business' ) {
61
+ if ( $search_term === '' ) {
62
+ $business_accounts = array();
63
+ $access_tokens_found = array();
64
+ foreach ( $connected_accounts as $connected_account ) {
65
+ if ( isset( $connected_account['type'] )
66
+ && $connected_account['type'] === 'business'
67
+ && ! in_array( $connected_account['access_token'], $access_tokens_found, true ) ) {
68
+ $business_accounts[] = $connected_account;
69
+ $access_tokens_found[] = $connected_account['access_token'];
70
+ }
71
+ }
72
+ return $business_accounts;
73
+ } else {
74
+ foreach ( $connected_accounts as $connected_account ) {
75
+ if ( isset( $connected_account['type'] )
76
+ && $connected_account['type'] === 'business' ) {
77
+ return $connected_account;
78
+ }
79
+ }
80
+
81
+
82
+ }
83
+
84
+ } else {
85
+ if ( isset( $connected_accounts[ $search_term ] ) ) {
86
+ return $connected_accounts[ $search_term ];
87
+ } else {
88
+ foreach ( $connected_accounts as $connected_account ) {
89
+ if ( strtolower( $connected_account['username'] ) === trim( strtolower( $search_term ) ) ) {
90
+ return $connected_account;
91
+ } elseif ( $connected_account['access_token'] === trim( strtolower( $search_term ) ) ) {
92
+ return $connected_account;
93
+ }
94
+ }
95
+ }
96
+ }
97
+
98
+ return false;
99
+ }
100
+
101
+ /**
102
+ * Generates a local version of the avatar image file
103
+ * and stores related information for easy retrieval and
104
+ * management
105
+ *
106
+ * @param $username string
107
+ * @param $profile_picture string
108
+ *
109
+ * @return bool
110
+ *
111
+ * @since 5.10
112
+ */
113
+ public static function create_local_avatar( $username, $profile_picture ) {
114
+ $options = sbi_get_database_settings();
115
+ if ( !$options['sb_instagram_disable_resize'] ) {
116
+ if ( sbi_create_local_avatar( $username, $profile_picture ) ) {
117
+ return true;
118
+ }
119
+ }
120
+ return false;
121
+ }
122
+ }
inc/class-sb-instagram-cron-updater.php CHANGED
@@ -135,17 +135,11 @@ class SB_Instagram_Cron_Updater
135
  $post_data = $instagram_feed->get_post_data();
136
  $post_data = array_slice( $post_data, 0, $settings['num'] );
137
 
138
- if ( $settings['favor_local'] ) {
139
- $image_sizes = array(
140
- 'personal' => array( 'full' => 640, 'low' => 320 ),
141
- 'business' => array( 'full' => 640, 'low' => 320 )
142
- );
143
- } else {
144
- $image_sizes = array(
145
- 'personal' => array( 'low' => 320 ),
146
- 'business' => array( 'full' => 640, 'low' => 320 )
147
- );
148
- }
149
  $post_set = new SB_Instagram_Post_Set( $post_data, $transient_name, NULL, $image_sizes );
150
 
151
  $post_set->maybe_save_update_and_resize_images_for_posts();
135
  $post_data = $instagram_feed->get_post_data();
136
  $post_data = array_slice( $post_data, 0, $settings['num'] );
137
 
138
+ $image_sizes = array(
139
+ 'personal' => array( 'full' => 640, 'low' => 320 ),
140
+ 'business' => array( 'full' => 640, 'low' => 320 )
141
+ );
142
+
 
 
 
 
 
 
143
  $post_set = new SB_Instagram_Post_Set( $post_data, $transient_name, NULL, $image_sizes );
144
 
145
  $post_set->maybe_save_update_and_resize_images_for_posts();
inc/class-sb-instagram-feed.php CHANGED
@@ -92,6 +92,13 @@ class SB_Instagram_Feed
92
  */
93
  private $resized_images;
94
 
 
 
 
 
 
 
 
95
  /**
96
  * @var array
97
  *
@@ -116,6 +123,7 @@ class SB_Instagram_Feed
116
 
117
  $this->post_data = array();
118
  $this->next_pages = array();
 
119
  $this->should_paginate = true;
120
 
121
  // this is a count of how many api calls have been made for each feed
@@ -145,19 +153,10 @@ class SB_Instagram_Feed
145
  /**
146
  * @return array
147
  *
148
- * @since 2.0/5.0
149
  */
150
- public function set_post_data( $post_data ) {
151
- $this->post_data = $post_data;
152
- }
153
-
154
- /**
155
- * @return array
156
- *
157
- * @since 2.1.1/5.2.1
158
- */
159
- public function set_resized_images( $resized_image_data ) {
160
- $this->resized_images = $resized_image_data;
161
  }
162
 
163
  /**
@@ -178,6 +177,20 @@ class SB_Instagram_Feed
178
  return $this->resized_images;
179
  }
180
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  /**
182
  * Checks the database option related the transient expiration
183
  * to ensure it will be available when the page loads
@@ -216,6 +229,19 @@ class SB_Instagram_Feed
216
  return $this->should_use_backup || empty( $this->post_data );
217
  }
218
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
  /**
220
  * The header is only displayed when the setting is enabled and
221
  * an account has been connected
@@ -283,6 +309,10 @@ class SB_Instagram_Feed
283
  $this->transient_atts = $transient_data['atts'];
284
  $this->last_retrieve = $transient_data['last_retrieve'];
285
  }
 
 
 
 
286
  }
287
  }
288
 
@@ -368,55 +398,62 @@ class SB_Instagram_Feed
368
  *
369
  * @since 2.0/5.0
370
  */
371
- public static function get_resized_images_source_set( $num_or_array_of_ids, $offset = 0, $transient_name = '' ) {
372
  global $sb_instagram_posts_manager;
373
 
374
- if ( $sb_instagram_posts_manager->image_resizing_disabled() ) {
375
  return array();
376
  }
377
 
378
- global $wpdb;
 
379
 
380
- $offset = max( 0, $offset );
 
 
 
 
381
 
382
- $posts_table_name = $wpdb->prefix . SBI_INSTAGRAM_POSTS_TYPE;
383
- $feeds_posts_table_name = $wpdb->prefix . SBI_INSTAGRAM_FEEDS_POSTS;
384
 
385
- $feed_id_array = explode( '#', $transient_name );
386
- $feed_id = $feed_id_array[0];
387
 
388
- if ( is_array( $num_or_array_of_ids ) ) {
389
- $ids = $num_or_array_of_ids;
390
 
391
- $id_string = "'" . implode( "','", $ids ) . "'";
392
- $results = $wpdb->get_results( $wpdb->prepare( "
 
 
 
393
  SELECT p.media_id, p.instagram_id, p.aspect_ratio, p.sizes
394
  FROM $posts_table_name AS p
395
  INNER JOIN $feeds_posts_table_name AS f ON p.id = f.id
396
- WHERE f.feed_id = %s
397
- AND p.instagram_id IN($id_string)
398
- AND p.images_done = 1", $feed_id ), ARRAY_A );
399
 
400
- $return = array();
401
- if ( !empty( $results ) && is_array( $results ) ) {
402
 
403
- foreach ( $results as $result ) {
404
- $sizes = maybe_unserialize( $result['sizes'] );
405
- if ( ! is_array( $sizes ) ) {
406
- $sizes = array( 'full' => 640 );
 
 
 
 
 
 
407
  }
408
- $return[ $result['instagram_id'] ] = array(
409
- 'id' => $result['media_id'],
410
- 'ratio' => $result['aspect_ratio'],
411
- 'sizes' => $sizes
412
- );
413
  }
414
 
415
- }
416
- } else {
417
- $num = $num_or_array_of_ids;
418
 
419
- $results = $wpdb->get_results( $wpdb->prepare( "
420
  SELECT p.media_id, p.instagram_id, p.aspect_ratio, p.sizes
421
  FROM $posts_table_name AS p
422
  INNER JOIN $feeds_posts_table_name AS f ON p.id = f.id
@@ -425,24 +462,29 @@ class SB_Instagram_Feed
425
  ORDER BY p.time_stamp
426
  DESC LIMIT %d, %d", $feed_id, $offset, (int)$num ), ARRAY_A );
427
 
428
- $return = array();
429
- if ( !empty( $results ) && is_array( $results ) ) {
430
 
431
- foreach ( $results as $result ) {
432
- $sizes = maybe_unserialize( $result['sizes'] );
433
- if ( ! is_array( $sizes ) ) {
434
- $sizes = array( 'full' => 640 );
 
 
 
 
 
 
435
  }
436
- $return[ $result['instagram_id'] ] = array(
437
- 'id' => $result['media_id'],
438
- 'ratio' => $result['aspect_ratio'],
439
- 'sizes' => $sizes
440
- );
441
  }
442
 
443
  }
444
- }
445
 
 
 
 
 
446
 
447
  return $return;
448
  }
@@ -480,7 +522,7 @@ class SB_Instagram_Feed
480
  * @since 2.0/5.0
481
  */
482
  public function need_to_start_cron_job() {
483
- return (( ! empty( $this->post_data ) && ! isset( $this->transient_atts )) || empty( $this->post_data ));
484
  }
485
 
486
  /**
@@ -573,15 +615,10 @@ class SB_Instagram_Feed
573
 
574
  $term = $term_and_params['term'];
575
  $params = array_merge( $params, $term_and_params['params'] );
576
- $connected_account_for_term = $connected_accounts_for_feed[ $term ];
577
-
578
- $api_requests_delayed = $sb_instagram_posts_manager->are_current_api_request_delays( $connected_account_for_term['user_id'] );
579
-
580
- if ( ! $api_requests_delayed
581
  && (! isset( $next_pages[ $term . '_' . $type ] ) || $next_pages[ $term . '_' . $type ] !== false) ) {
582
-
583
  $account_type = isset( $connected_account_for_term['type'] ) ? $connected_account_for_term['type'] : 'personal';
584
- $skip_connection = false;
585
 
586
  // basic account access tokens need to be refreshed every 60 days
587
  // normally done using WP Cron but can be done here as a fail safe
@@ -598,8 +635,6 @@ class SB_Instagram_Feed
598
  }
599
  }
600
 
601
- } elseif( $account_type === 'personal' && sbi_is_after_deprecation_deadline() ) {
602
- $skip_connection = true;
603
  }
604
 
605
  if ( ! empty( $next_pages[ $term . '_' . $type ] ) ) {
@@ -615,21 +650,17 @@ class SB_Instagram_Feed
615
  }
616
  $this->add_report( 'api call made for ' . $term . ' - ' . $type );
617
 
618
- if ( ! $skip_connection ) {
619
- $connection->connect();
620
- }
621
  $this->num_api_calls++;
622
 
623
- if ( ! $skip_connection && ! $connection->is_wp_error() && ! $connection->is_instagram_error() ) {
624
  $one_successful_connection = true;
625
 
626
  if ( $type === 'hashtags_top' ) {
627
  SB_Instagram_Posts_Manager::maybe_update_list_of_top_hashtags( $term_and_params['hashtag_name'] );
628
  }
629
 
630
- $sb_instagram_posts_manager->remove_error( 'connection' );
631
- $sb_instagram_posts_manager->remove_error( 'api' );
632
- $sb_instagram_posts_manager->remove_error( 'at_' . $term );
633
 
634
  $data = $connection->get_data();
635
 
@@ -656,10 +687,9 @@ class SB_Instagram_Feed
656
  } else {
657
 
658
  if ( $this->can_try_another_request( $type, $connected_accounts_for_feed[ $term ] ) ) {
659
-
660
  $this->add_report( 'trying other accounts' );
661
  $i = 0;
662
- $attempted = array( $connected_accounts_for_feed[ $term ]['user_id'] );
663
  $success = false;
664
  $different = true;
665
  $error = false;
@@ -673,21 +703,21 @@ class SB_Instagram_Feed
673
  if ( $different ) {
674
  $connected_accounts_for_feed[ $term ] = $this->get_different_connected_account( $type, $attempted );
675
  $attempted[] = $connected_accounts_for_feed[ $term ]['user_id'];
 
676
  if ( ! empty( $next_pages[ $term . '_' . $type ] ) ) {
677
- $connection = $this->make_api_connection( $next_pages[ $term . '_' . $type ] );
678
  } else {
679
- $connection = $this->make_api_connection( $connected_accounts_for_feed[ $term ], $type, $params );
680
  }
681
- $connection->connect();
682
  $this->num_api_calls++;
683
- if ( ! $connection->is_wp_error() && ! $connection->is_instagram_error() ) {
684
- $one_successful_connection = true;
685
 
686
- $sb_instagram_posts_manager->remove_error( 'connection' );
687
- $sb_instagram_posts_manager->remove_error( 'api' );
688
- $sb_instagram_posts_manager->remove_error( 'at_' . $term );
689
 
690
- $data = $connection->get_data();
691
  if ( isset( $data[0]['id'] ) ) {
692
  $one_post_found = true;
693
  $post_set = $this->filter_posts( $data, $settings );
@@ -695,7 +725,7 @@ class SB_Instagram_Feed
695
 
696
  $new_post_sets[] = $post_set;
697
  }
698
- $next_page = $connection->get_next_page( $type );
699
  if ( ! empty( $next_page ) ) {
700
  $next_pages[ $term . '_' . $type ] = $next_page;
701
  $next_page_found = true;
@@ -703,10 +733,10 @@ class SB_Instagram_Feed
703
  $next_pages[ $term . '_' . $type ] = false;
704
  }
705
  } else {
706
- if ( $connection->is_wp_error() ) {
707
- $error = $connection->get_wp_error();
708
  } else {
709
- $error = $connection->get_data();
710
  }
711
  }
712
  $i++;
@@ -723,49 +753,18 @@ class SB_Instagram_Feed
723
  SB_Instagram_API_Connect::handle_instagram_error( $error, $connected_accounts_for_feed[ $term ], $type );
724
  }
725
  $next_pages[ $term . '_' . $type ] = false;
726
- $show_error_message = true;
727
 
728
  }
729
  } else {
730
- if ( $skip_connection ) {
731
-
732
- } elseif ( $connection->is_wp_error() ) {
733
  SB_Instagram_API_Connect::handle_wp_remote_get_error( $connection->get_wp_error() );
734
  } else {
735
  SB_Instagram_API_Connect::handle_instagram_error( $connection->get_data(), $connected_accounts_for_feed[ $term ], $type );
736
  }
737
- $show_error_message = true;
738
 
739
  $next_pages[ $term . '_' . $type ] = false;
740
  }
741
  }
742
- } elseif ( $api_requests_delayed ) {
743
- $one_api_request_delayed = true;
744
-
745
- $this->add_report( 'delaying API request for ' . $term . ' - ' . $type );
746
- $show_error_message = true;
747
- }
748
-
749
- if ( isset( $show_error_message ) ) {
750
- $error = '';
751
- if ( $sb_instagram_posts_manager->are_critical_errors() ) {
752
- $error .= $sb_instagram_posts_manager->get_critical_errors();
753
- } else {
754
- $errors = $sb_instagram_posts_manager->get_frontend_errors();
755
- $cap = current_user_can( 'manage_instagram_feed_options' ) ? 'manage_instagram_feed_options' : 'manage_options';
756
- $cap = apply_filters( 'sbi_settings_pages_capability', $cap );
757
- if ( current_user_can( $cap ) ) {
758
- foreach ( $errors as $error_message ) {
759
- $error .= $error_message;
760
- }
761
- $error .= '<p class="sbi-error-directions"><a href="https://smashballoon.com/instagram-feed/docs/errors/" target="_blank" rel="noopener">' . __( 'Directions on how to resolve this issue.', 'instagram-feed' ) . '</a></p>';
762
- } else {
763
- $error = '<p><b>' . sprintf( __( 'Error: API requests are being delayed for this account.', 'instagram-feed' ), $connected_account_for_term['username'] ) . ' ' . __( 'New posts will not be retrieved.', 'instagram-feed' ) . '</b></p>';
764
- $error .= '<p>' . __( 'Log in as an administrator and view the Instagram Feed settings page for more details.', 'instagram-feed' ) . '</p>';
765
- }
766
- }
767
-
768
- $sb_instagram_posts_manager->add_frontend_error( 'at_' . $connected_account_for_term['username'], $error );
769
  }
770
 
771
  }
@@ -813,7 +812,7 @@ class SB_Instagram_Feed
813
  $this->header_data = false;
814
  global $sb_instagram_posts_manager;
815
 
816
- $api_requests_delayed = isset( $connected_accounts_for_feed[ $first_user ]['user_id'] ) ? $sb_instagram_posts_manager->are_current_api_request_delays( $connected_accounts_for_feed[ $first_user ]['user_id'] ) : $sb_instagram_posts_manager->are_current_api_request_delays();
817
 
818
  if ( isset( $connected_accounts_for_feed[ $first_user ] ) && ! $api_requests_delayed ) {
819
  $connection = new SB_Instagram_API_Connect( $connected_accounts_for_feed[ $first_user ], 'header', array() );
@@ -823,9 +822,7 @@ class SB_Instagram_Feed
823
  if ( ! $connection->is_wp_error() && ! $connection->is_instagram_error() ) {
824
  $this->header_data = $connection->get_data();
825
 
826
- $sb_instagram_posts_manager->remove_error( 'connection' );
827
- $sb_instagram_posts_manager->remove_error( 'api' );
828
- $sb_instagram_posts_manager->remove_error( 'at_' . $first_user );
829
 
830
  if ( isset( $connected_accounts_for_feed[ $first_user ]['local_avatar'] ) && $connected_accounts_for_feed[ $first_user ]['local_avatar'] ) {
831
  $upload = wp_upload_dir();
@@ -834,7 +831,7 @@ class SB_Instagram_Feed
834
  $full_file_name = $resized_url . $this->header_data['username'] . '.jpg';
835
  $this->header_data['local_avatar'] = $full_file_name;
836
  } else {
837
- if ( !$sb_instagram_posts_manager->image_resizing_disabled() && ! isset( $connected_accounts_for_feed[ $first_user ]['local_avatar'] ) ) {
838
  if ( sbi_store_local_avatar( $connected_accounts_for_feed[ $first_user ] ) ) {
839
  $upload = wp_upload_dir();
840
  $resized_url = trailingslashit( $upload['baseurl'] ) . trailingslashit( SBI_UPLOADS_NAME );
@@ -850,6 +847,8 @@ class SB_Instagram_Feed
850
  $this->header_data['bio'] = sbi_decode_emoji( $connected_accounts_for_feed[ $first_user ]['bio'] );
851
  }
852
  } else {
 
 
853
  if ( $connection->is_wp_error() ) {
854
  SB_Instagram_API_Connect::handle_wp_remote_get_error( $connection->get_wp_error() );
855
  } else {
@@ -869,7 +868,7 @@ class SB_Instagram_Feed
869
  * @since 2.0/5.1 duplicate posts removed
870
  */
871
  public function cache_feed_data( $cache_time, $save_backup = true ) {
872
- if ( ! empty( $this->post_data ) || ! empty( $this->next_pages ) ) {
873
  $this->remove_duplicate_posts();
874
  $this->trim_posts_to_max();
875
 
@@ -878,11 +877,25 @@ class SB_Instagram_Feed
878
  'pagination' => $this->next_pages
879
  );
880
 
 
 
 
 
 
 
 
 
881
  set_transient( $this->regular_feed_transient_name, sbi_json_encode( $to_cache ), $cache_time );
882
 
 
 
883
  if ( $save_backup ) {
 
 
 
884
  update_option( $this->backup_feed_transient_name, sbi_json_encode( $to_cache ), false );
885
  }
 
886
  } else {
887
  $this->add_report( 'no data not caching' );
888
  }
@@ -902,7 +915,8 @@ class SB_Instagram_Feed
902
  public function set_cron_cache( $to_cache, $cache_time, $save_backup = true ) {
903
  if ( ! empty( $this->post_data )
904
  || ! empty( $this->next_pages )
905
- || ! empty( $to_cache['data'] ) ) {
 
906
  $this->remove_duplicate_posts();
907
  $this->trim_posts_to_max();
908
 
@@ -912,10 +926,27 @@ class SB_Instagram_Feed
912
  $to_cache['last_requested'] = isset( $to_cache['last_requested'] ) ? $to_cache['last_requested'] : time();
913
  $to_cache['last_retrieve'] = isset( $to_cache['last_retrieve'] ) ? $to_cache['last_retrieve'] : $this->last_retrieve;
914
 
 
 
 
 
 
 
 
 
 
 
915
  set_transient( $this->regular_feed_transient_name, sbi_json_encode( $to_cache ), $cache_time );
916
 
917
  if ( $save_backup ) {
918
- update_option( $this->backup_feed_transient_name, sbi_json_encode( $to_cache ), false );
 
 
 
 
 
 
 
919
  }
920
  } else {
921
  $this->add_report( 'no data not caching' );
@@ -936,6 +967,9 @@ class SB_Instagram_Feed
936
  set_transient( $this->header_transient_name, sbi_json_encode( $this->header_data ), $cache_time );
937
 
938
  if ( $save_backup ) {
 
 
 
939
  update_option( $this->backup_header_transient_name, sbi_json_encode( $this->header_data ), false );
940
  }
941
  }
@@ -1073,7 +1107,7 @@ class SB_Instagram_Feed
1073
 
1074
  $flags = array();
1075
 
1076
- if ( $settings['disable_resize'] || $settings['isgutenberg'] ) {
1077
  $flags[] = 'resizeDisable';
1078
  } elseif ( $settings['favor_local'] ) {
1079
  $flags[] = 'favorLocal';
@@ -1095,12 +1129,6 @@ class SB_Instagram_Feed
1095
  $flags[] = 'debug';
1096
  }
1097
 
1098
- $ajax_test_status = $sb_instagram_posts_manager->get_ajax_status();
1099
-
1100
- if ( $sb_instagram_posts_manager->maybe_start_ajax_test() && ! $ajax_test_status['successful'] ) {
1101
- $flags[] = 'testAjax';
1102
- }
1103
-
1104
  $flags = apply_filters( 'sbi_flags', $flags, $settings );
1105
 
1106
  if ( ! empty( $flags ) ) {
@@ -1272,15 +1300,13 @@ class SB_Instagram_Feed
1272
  protected function handle_no_posts_found( $settings = array(), $feed_types_and_terms = array() ) {
1273
  global $sb_instagram_posts_manager;
1274
 
1275
- $error = '<p><b>' . __( 'Error: No posts found.', 'instagram-feed' ) . '</b>';
1276
- $error .= '<p>' . __( 'Make sure this account has posts available on instagram.com.', 'instagram-feed' ) . '</p>';
1277
- $cap = current_user_can( 'manage_instagram_feed_options' ) ? 'manage_instagram_feed_options' : 'manage_options';
1278
- $cap = apply_filters( 'sbi_settings_pages_capability', $cap );
1279
- if ( current_user_can( $cap ) ) {
1280
- $error .= '<p><a href="https://smashballoon.com/instagram-feed/docs/errors/">' . __( 'Click here to troubleshoot', 'instagram-feed' ) . '</a></p>';
1281
- }
1282
-
1283
- $sb_instagram_posts_manager->add_frontend_error( 'noposts', $error );
1284
  }
1285
 
1286
  protected function remove_duplicate_posts() {
@@ -1410,6 +1436,7 @@ class SB_Instagram_Feed
1410
  * @since 2.0/5.0
1411
  */
1412
  private function merge_posts( $post_sets, $settings ) {
 
1413
  $merged_posts = array();
1414
  if ( $settings['sortby'] === 'alternate'
1415
  || $settings['sortby'] === 'api' && isset( $post_sets[1] ) ) {
@@ -1421,9 +1448,18 @@ class SB_Instagram_Feed
1421
  $ii = 0;
1422
  foreach ( $post_sets as $post_set ) {
1423
  if ( isset( $post_sets[ $ii ]['term'] ) ) {
 
 
1424
  if ( ! isset( $terms[ $ii ] ) ) {
1425
- $terms[ $ii ] = $post_set['term'];
1426
- unset( $post_sets[ $ii ]['term'] );
 
 
 
 
 
 
 
1427
  }
1428
  }
1429
  if ( isset( $post_set[ $i ] ) && isset( $post_set[ $i ]['id'] ) ) {
@@ -1435,17 +1471,47 @@ class SB_Instagram_Feed
1435
  }
1436
  } else {
1437
  if ( isset( $post_sets[0]['term'] ) ) {
 
 
1438
  unset( $post_sets[0]['term'] );
 
 
 
 
 
 
 
1439
  }
1440
  $merged_posts = isset( $post_sets[0] ) ? $post_sets[0] : array();
1441
  }
1442
  } elseif ( $settings['sortby'] === 'api' ) {
1443
  if ( isset( $post_sets[0] ) ) {
1444
  if ( isset( $post_sets[0]['term'] ) ) {
 
1445
  unset( $post_sets[0]['term'] );
 
 
 
 
 
 
 
1446
  }
 
1447
  foreach ( $post_sets as $post_set ) {
 
 
 
 
 
 
 
 
 
 
 
1448
  $merged_posts = array_merge( $merged_posts, $post_set );
 
1449
  }
1450
  }
1451
  } else {
@@ -1473,7 +1539,15 @@ class SB_Instagram_Feed
1473
  }
1474
  } else {
1475
  if ( isset( $post_sets[0]['term'] ) ) {
 
1476
  unset( $post_sets[0]['term'] );
 
 
 
 
 
 
 
1477
  }
1478
  $merged_posts = isset( $post_sets[0] ) ? $post_sets[0] : array();
1479
  }
92
  */
93
  private $resized_images;
94
 
95
+ /**
96
+ * @var array
97
+ *
98
+ * @since 2.7/5.10
99
+ */
100
+ private $cached_feed_error;
101
+
102
  /**
103
  * @var array
104
  *
123
 
124
  $this->post_data = array();
125
  $this->next_pages = array();
126
+ $this->cached_feed_error = array();
127
  $this->should_paginate = true;
128
 
129
  // this is a count of how many api calls have been made for each feed
153
  /**
154
  * @return array
155
  *
156
+ * @since 2.7/5.10
157
  */
158
+ public function get_cached_feed_error() {
159
+ return $this->cached_feed_error;
 
 
 
 
 
 
 
 
 
160
  }
161
 
162
  /**
177
  return $this->resized_images;
178
  }
179
 
180
+ /**
181
+ * @since 2.0/5.0
182
+ */
183
+ public function set_post_data( $post_data ) {
184
+ $this->post_data = $post_data;
185
+ }
186
+
187
+ /**
188
+ * @since 2.1.1/5.2.1
189
+ */
190
+ public function set_resized_images( $resized_image_data ) {
191
+ $this->resized_images = $resized_image_data;
192
+ }
193
+
194
  /**
195
  * Checks the database option related the transient expiration
196
  * to ensure it will be available when the page loads
229
  return $this->should_use_backup || empty( $this->post_data );
230
  }
231
 
232
+ public function should_cache_error() {
233
+ global $sb_instagram_posts_manager;
234
+
235
+ $error_messages = $sb_instagram_posts_manager->get_frontend_errors();
236
+ if ( ! empty( $error_messages ) ) {
237
+ $this->cached_feed_error = $error_messages;
238
+
239
+ return true;
240
+ }
241
+
242
+ return false;
243
+ }
244
+
245
  /**
246
  * The header is only displayed when the setting is enabled and
247
  * an account has been connected
309
  $this->transient_atts = $transient_data['atts'];
310
  $this->last_retrieve = $transient_data['last_retrieve'];
311
  }
312
+
313
+ if ( isset( $transient_data['errors'] ) ) {
314
+ $this->cached_feed_error = $transient_data['errors'];
315
+ }
316
  }
317
  }
318
 
398
  *
399
  * @since 2.0/5.0
400
  */
401
+ public static function get_resized_images_source_set( $num_or_array_of_ids, $offset = 0, $transient_name = '', $should_cache = true ) {
402
  global $sb_instagram_posts_manager;
403
 
404
+ if ( $sb_instagram_posts_manager->image_resizing_disabled( $transient_name ) ) {
405
  return array();
406
  }
407
 
408
+ $images_transient_name = str_replace( 'sbi_', 'sbi_i_', $transient_name );
409
+ $cache = $offset === 0 ? get_transient( $images_transient_name ) : false;
410
 
411
+ if ( $cache ) {
412
+ $return = json_decode( $cache, true );
413
+ } else {
414
+
415
+ global $wpdb;
416
 
417
+ $offset = max( 0, $offset );
 
418
 
419
+ $posts_table_name = $wpdb->prefix . SBI_INSTAGRAM_POSTS_TYPE;
420
+ $feeds_posts_table_name = $wpdb->prefix . SBI_INSTAGRAM_FEEDS_POSTS;
421
 
422
+ $feed_id_array = explode( '#', $transient_name );
423
+ $feed_id = $feed_id_array[0];
424
 
425
+ if ( is_array( $num_or_array_of_ids ) ) {
426
+ $ids = $num_or_array_of_ids;
427
+
428
+ $id_string = "'" . implode( "','", $ids ) . "'";
429
+ $results = $wpdb->get_results( "
430
  SELECT p.media_id, p.instagram_id, p.aspect_ratio, p.sizes
431
  FROM $posts_table_name AS p
432
  INNER JOIN $feeds_posts_table_name AS f ON p.id = f.id
433
+ WHERE p.instagram_id IN($id_string)
434
+ AND p.images_done = 1", ARRAY_A );
 
435
 
436
+ $return = array();
437
+ if ( !empty( $results ) && is_array( $results ) ) {
438
 
439
+ foreach ( $results as $result ) {
440
+ $sizes = maybe_unserialize( $result['sizes'] );
441
+ if ( ! is_array( $sizes ) ) {
442
+ $sizes = array( 'full' => 640 );
443
+ }
444
+ $return[ $result['instagram_id'] ] = array(
445
+ 'id' => $result['media_id'],
446
+ 'ratio' => $result['aspect_ratio'],
447
+ 'sizes' => $sizes
448
+ );
449
  }
450
+
 
 
 
 
451
  }
452
 
453
+ } else {
454
+ $num = $num_or_array_of_ids;
 
455
 
456
+ $results = $wpdb->get_results( $wpdb->prepare( "
457
  SELECT p.media_id, p.instagram_id, p.aspect_ratio, p.sizes
458
  FROM $posts_table_name AS p
459
  INNER JOIN $feeds_posts_table_name AS f ON p.id = f.id
462
  ORDER BY p.time_stamp
463
  DESC LIMIT %d, %d", $feed_id, $offset, (int)$num ), ARRAY_A );
464
 
465
+ $return = array();
466
+ if ( !empty( $results ) && is_array( $results ) ) {
467
 
468
+ foreach ( $results as $result ) {
469
+ $sizes = maybe_unserialize( $result['sizes'] );
470
+ if ( ! is_array( $sizes ) ) {
471
+ $sizes = array( 'full' => 640 );
472
+ }
473
+ $return[ $result['instagram_id'] ] = array(
474
+ 'id' => $result['media_id'],
475
+ 'ratio' => $result['aspect_ratio'],
476
+ 'sizes' => $sizes
477
+ );
478
  }
479
+
 
 
 
 
480
  }
481
 
482
  }
 
483
 
484
+ if ( $offset === 0 && $should_cache ) {
485
+ set_transient( $images_transient_name, sbi_json_encode( $return ), HOUR_IN_SECONDS );
486
+ }
487
+ }
488
 
489
  return $return;
490
  }
522
  * @since 2.0/5.0
523
  */
524
  public function need_to_start_cron_job() {
525
+ return (( ! empty( $this->post_data ) && ! isset( $this->transient_atts )) || (empty( $this->post_data ) && empty( $this->cached_feed_error )));
526
  }
527
 
528
  /**
615
 
616
  $term = $term_and_params['term'];
617
  $params = array_merge( $params, $term_and_params['params'] );
618
+ if ( ! isset( $term_and_params['error'] )
 
 
 
 
619
  && (! isset( $next_pages[ $term . '_' . $type ] ) || $next_pages[ $term . '_' . $type ] !== false) ) {
620
+ $connected_account_for_term = isset( $connected_accounts_for_feed[ $term ] ) ? $connected_accounts_for_feed[ $term ] : array();
621
  $account_type = isset( $connected_account_for_term['type'] ) ? $connected_account_for_term['type'] : 'personal';
 
622
 
623
  // basic account access tokens need to be refreshed every 60 days
624
  // normally done using WP Cron but can be done here as a fail safe
635
  }
636
  }
637
 
 
 
638
  }
639
 
640
  if ( ! empty( $next_pages[ $term . '_' . $type ] ) ) {
650
  }
651
  $this->add_report( 'api call made for ' . $term . ' - ' . $type );
652
 
653
+ $connection->connect();
 
 
654
  $this->num_api_calls++;
655
 
656
+ if ( ! $connection->is_wp_error() && ! $connection->is_instagram_error() ) {
657
  $one_successful_connection = true;
658
 
659
  if ( $type === 'hashtags_top' ) {
660
  SB_Instagram_Posts_Manager::maybe_update_list_of_top_hashtags( $term_and_params['hashtag_name'] );
661
  }
662
 
663
+ $sb_instagram_posts_manager->remove_error( 'connection', $connected_account_for_term );
 
 
664
 
665
  $data = $connection->get_data();
666
 
687
  } else {
688
 
689
  if ( $this->can_try_another_request( $type, $connected_accounts_for_feed[ $term ] ) ) {
 
690
  $this->add_report( 'trying other accounts' );
691
  $i = 0;
692
+ $attempted = array( $connected_accounts_for_feed[ $term ]['access_token'] );
693
  $success = false;
694
  $different = true;
695
  $error = false;
703
  if ( $different ) {
704
  $connected_accounts_for_feed[ $term ] = $this->get_different_connected_account( $type, $attempted );
705
  $attempted[] = $connected_accounts_for_feed[ $term ]['user_id'];
706
+
707
  if ( ! empty( $next_pages[ $term . '_' . $type ] ) ) {
708
+ $new_connection = $this->make_api_connection( $next_pages[ $term . '_' . $type ] );
709
  } else {
710
+ $new_connection = $this->make_api_connection( $connected_accounts_for_feed[ $term ], $type, $params );
711
  }
712
+
713
  $this->num_api_calls++;
714
+ if ( ! $new_connection->is_wp_error() && ! $new_connection->is_instagram_error() ) {
 
715
 
716
+ $one_successful_connection = true;
717
+ $success = true;
718
+ $sb_instagram_posts_manager->maybe_remove_display_error( 'hashtag_limit' );
719
 
720
+ $data = $new_connection->get_data();
721
  if ( isset( $data[0]['id'] ) ) {
722
  $one_post_found = true;
723
  $post_set = $this->filter_posts( $data, $settings );
725
 
726
  $new_post_sets[] = $post_set;
727
  }
728
+ $next_page = $new_connection->get_next_page( $type );
729
  if ( ! empty( $next_page ) ) {
730
  $next_pages[ $term . '_' . $type ] = $next_page;
731
  $next_page_found = true;
733
  $next_pages[ $term . '_' . $type ] = false;
734
  }
735
  } else {
736
+ if ( $new_connection->is_wp_error() ) {
737
+ $error = $new_connection->get_wp_error();
738
  } else {
739
+ $error = $new_connection->get_data();
740
  }
741
  }
742
  $i++;
753
  SB_Instagram_API_Connect::handle_instagram_error( $error, $connected_accounts_for_feed[ $term ], $type );
754
  }
755
  $next_pages[ $term . '_' . $type ] = false;
 
756
 
757
  }
758
  } else {
759
+ if ( $connection->is_wp_error() ) {
 
 
760
  SB_Instagram_API_Connect::handle_wp_remote_get_error( $connection->get_wp_error() );
761
  } else {
762
  SB_Instagram_API_Connect::handle_instagram_error( $connection->get_data(), $connected_accounts_for_feed[ $term ], $type );
763
  }
 
764
 
765
  $next_pages[ $term . '_' . $type ] = false;
766
  }
767
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
768
  }
769
 
770
  }
812
  $this->header_data = false;
813
  global $sb_instagram_posts_manager;
814
 
815
+ $api_requests_delayed = isset( $connected_accounts_for_feed[ $first_user ] ) ? $sb_instagram_posts_manager->are_current_api_request_delays( $connected_accounts_for_feed[ $first_user ] ) : false;
816
 
817
  if ( isset( $connected_accounts_for_feed[ $first_user ] ) && ! $api_requests_delayed ) {
818
  $connection = new SB_Instagram_API_Connect( $connected_accounts_for_feed[ $first_user ], 'header', array() );
822
  if ( ! $connection->is_wp_error() && ! $connection->is_instagram_error() ) {
823
  $this->header_data = $connection->get_data();
824
 
825
+ $sb_instagram_posts_manager->remove_error( 'connection', $connected_accounts_for_feed[ $first_user ] );
 
 
826
 
827
  if ( isset( $connected_accounts_for_feed[ $first_user ]['local_avatar'] ) && $connected_accounts_for_feed[ $first_user ]['local_avatar'] ) {
828
  $upload = wp_upload_dir();
831
  $full_file_name = $resized_url . $this->header_data['username'] . '.jpg';
832
  $this->header_data['local_avatar'] = $full_file_name;
833
  } else {
834
+ if ( !$sb_instagram_posts_manager->image_resizing_disabled( $feed_types_and_terms ) && ! isset( $connected_accounts_for_feed[ $first_user ]['local_avatar'] ) ) {
835
  if ( sbi_store_local_avatar( $connected_accounts_for_feed[ $first_user ] ) ) {
836
  $upload = wp_upload_dir();
837
  $resized_url = trailingslashit( $upload['baseurl'] ) . trailingslashit( SBI_UPLOADS_NAME );
847
  $this->header_data['bio'] = sbi_decode_emoji( $connected_accounts_for_feed[ $first_user ]['bio'] );
848
  }
849
  } else {
850
+ $this->should_use_backup = true;
851
+
852
  if ( $connection->is_wp_error() ) {
853
  SB_Instagram_API_Connect::handle_wp_remote_get_error( $connection->get_wp_error() );
854
  } else {
868
  * @since 2.0/5.1 duplicate posts removed
869
  */
870
  public function cache_feed_data( $cache_time, $save_backup = true ) {
871
+ if ( ! empty( $this->post_data ) || ! empty( $this->next_pages ) || ! empty( $this->cached_feed_error ) ) {
872
  $this->remove_duplicate_posts();
873
  $this->trim_posts_to_max();
874
 
877
  'pagination' => $this->next_pages
878
  );
879
 
880
+ global $sb_instagram_posts_manager;
881
+
882
+ $error_messages = $sb_instagram_posts_manager->get_frontend_errors();
883
+
884
+ if ( ! empty( $error_messages ) ) {
885
+ $to_cache['errors'] = $error_messages;
886
+ }
887
+
888
  set_transient( $this->regular_feed_transient_name, sbi_json_encode( $to_cache ), $cache_time );
889
 
890
+ sbi_delete_image_cache( $this->regular_feed_transient_name );
891
+
892
  if ( $save_backup ) {
893
+ if ( isset( $to_cache['errors'] ) ) {
894
+ unset( $to_cache['errors'] );
895
+ }
896
  update_option( $this->backup_feed_transient_name, sbi_json_encode( $to_cache ), false );
897
  }
898
+
899
  } else {
900
  $this->add_report( 'no data not caching' );
901
  }
915
  public function set_cron_cache( $to_cache, $cache_time, $save_backup = true ) {
916
  if ( ! empty( $this->post_data )
917
  || ! empty( $this->next_pages )
918
+ || ! empty( $to_cache['data'] )
919
+ || $this->should_cache_error() ) {
920
  $this->remove_duplicate_posts();
921
  $this->trim_posts_to_max();
922
 
926
  $to_cache['last_requested'] = isset( $to_cache['last_requested'] ) ? $to_cache['last_requested'] : time();
927
  $to_cache['last_retrieve'] = isset( $to_cache['last_retrieve'] ) ? $to_cache['last_retrieve'] : $this->last_retrieve;
928
 
929
+ global $sb_instagram_posts_manager;
930
+
931
+ $error_messages = $sb_instagram_posts_manager->get_frontend_errors();
932
+
933
+ if ( ! empty( $error_messages ) ) {
934
+ $to_cache['errors'] = $error_messages;
935
+ } else {
936
+ $to_cache['errors'] = array();
937
+ }
938
+
939
  set_transient( $this->regular_feed_transient_name, sbi_json_encode( $to_cache ), $cache_time );
940
 
941
  if ( $save_backup ) {
942
+ if ( ! empty( $this->post_data )
943
+ || ! empty( $this->next_pages )
944
+ || ! empty( $to_cache['data'] ) ) {
945
+ if ( isset( $to_cache['errors'] ) ) {
946
+ unset( $to_cache['errors'] );
947
+ }
948
+ update_option( $this->backup_feed_transient_name, sbi_json_encode( $to_cache ), false );
949
+ }
950
  }
951
  } else {
952
  $this->add_report( 'no data not caching' );
967
  set_transient( $this->header_transient_name, sbi_json_encode( $this->header_data ), $cache_time );
968
 
969
  if ( $save_backup ) {
970
+ if ( isset( $this->header_data['errors'] ) ) {
971
+ unset( $this->header_data['errors'] );
972
+ }
973
  update_option( $this->backup_header_transient_name, sbi_json_encode( $this->header_data ), false );
974
  }
975
  }
1107
 
1108
  $flags = array();
1109
 
1110
+ if ( $sb_instagram_posts_manager->image_resizing_disabled( $feed_types_and_terms ) || $settings['isgutenberg'] ) {
1111
  $flags[] = 'resizeDisable';
1112
  } elseif ( $settings['favor_local'] ) {
1113
  $flags[] = 'favorLocal';
1129
  $flags[] = 'debug';
1130
  }
1131
 
 
 
 
 
 
 
1132
  $flags = apply_filters( 'sbi_flags', $flags, $settings );
1133
 
1134
  if ( ! empty( $flags ) ) {
1300
  protected function handle_no_posts_found( $settings = array(), $feed_types_and_terms = array() ) {
1301
  global $sb_instagram_posts_manager;
1302
 
1303
+ $error_message_return = array(
1304
+ 'error_message' => __( 'Error: No posts found.', 'instagram-feed' ),
1305
+ 'admin_only' => __( 'Make sure this account has posts available on instagram.com.', 'instagram-feed' ),
1306
+ 'frontend_directions' => '<a href="https://smashballoon.com/instagram-feed/docs/errors/">' . __( 'Click here to troubleshoot', 'instagram-feed' ) . '</a>',
1307
+ 'backend_directions' => '<a href="https://smashballoon.com/instagram-feed/docs/errors/">' . __( 'Click here to troubleshoot', 'instagram-feed' ) . '</a>'
1308
+ );
1309
+ $sb_instagram_posts_manager->maybe_set_display_error( 'configuration', $error_message_return );
 
 
1310
  }
1311
 
1312
  protected function remove_duplicate_posts() {
1436
  * @since 2.0/5.0
1437
  */
1438
  private function merge_posts( $post_sets, $settings ) {
1439
+
1440
  $merged_posts = array();
1441
  if ( $settings['sortby'] === 'alternate'
1442
  || $settings['sortby'] === 'api' && isset( $post_sets[1] ) ) {
1448
  $ii = 0;
1449
  foreach ( $post_sets as $post_set ) {
1450
  if ( isset( $post_sets[ $ii ]['term'] ) ) {
1451
+ $term = $post_sets[ $ii ]['term'];
1452
+ unset( $post_sets[ $ii ]['term'] );
1453
  if ( ! isset( $terms[ $ii ] ) ) {
1454
+ $terms[ $ii ] = $term;
1455
+ //
1456
+ }
1457
+ if ( strpos( $term, '#' ) !== false ) {
1458
+ $post_index = 0;
1459
+ foreach ( $post_sets[ $ii ] as $post ) {
1460
+ $post_sets[ $ii ][ $post_index ]['term'] = $term;
1461
+ $post_index++;
1462
+ }
1463
  }
1464
  }
1465
  if ( isset( $post_set[ $i ] ) && isset( $post_set[ $i ]['id'] ) ) {
1471
  }
1472
  } else {
1473
  if ( isset( $post_sets[0]['term'] ) ) {
1474
+ $term = $post_sets[0]['term'];
1475
+
1476
  unset( $post_sets[0]['term'] );
1477
+ if ( strpos( $term, '#' ) !== false ) {
1478
+ $post_index = 0;
1479
+ foreach ( $post_sets[0] as $post ) {
1480
+ $post_sets[0][ $post_index ]['term'] = $term;
1481
+ $post_index++;
1482
+ }
1483
+ }
1484
  }
1485
  $merged_posts = isset( $post_sets[0] ) ? $post_sets[0] : array();
1486
  }
1487
  } elseif ( $settings['sortby'] === 'api' ) {
1488
  if ( isset( $post_sets[0] ) ) {
1489
  if ( isset( $post_sets[0]['term'] ) ) {
1490
+ $term = $post_sets[0]['term'];
1491
  unset( $post_sets[0]['term'] );
1492
+ if ( strpos( $term, '#' ) !== false ) {
1493
+ $post_index = 0;
1494
+ foreach ( $post_sets[0] as $post ) {
1495
+ $post_sets[0][ $post_index ]['term'] = $term;
1496
+ $post_index++;
1497
+ }
1498
+ }
1499
  }
1500
+ $post_set_index = 0;
1501
  foreach ( $post_sets as $post_set ) {
1502
+ if ( isset( $post_sets[ $post_set_index ]['term'] ) ) {
1503
+ $term = $post_sets[ $post_set_index ]['term'];
1504
+ unset( $post_sets[ $post_set_index ]['term'] );
1505
+ if ( strpos( $term, '#' ) !== false ) {
1506
+ $post_index = 0;
1507
+ foreach ( $post_sets[0] as $post ) {
1508
+ $post_sets[ $post_set_index ][ $post_index ]['term'] = $term;
1509
+ $post_index++;
1510
+ }
1511
+ }
1512
+ }
1513
  $merged_posts = array_merge( $merged_posts, $post_set );
1514
+ $post_set_index ++;
1515
  }
1516
  }
1517
  } else {
1539
  }
1540
  } else {
1541
  if ( isset( $post_sets[0]['term'] ) ) {
1542
+ $term = $post_sets[0]['term'];
1543
  unset( $post_sets[0]['term'] );
1544
+ if ( strpos( $term, '#' ) !== false ) {
1545
+ $post_index = 0;
1546
+ foreach ( $post_sets[0] as $post ) {
1547
+ $post_sets[0][ $post_index ]['term'] = $term;
1548
+ $post_index++;
1549
+ }
1550
+ }
1551
  }
1552
  $merged_posts = isset( $post_sets[0] ) ? $post_sets[0] : array();
1553
  }
inc/class-sb-instagram-gdpr-integrations.php CHANGED
@@ -105,7 +105,7 @@ class SB_Instagram_GDPR_Integrations {
105
  public static function gdpr_tests_successful( $retest = false ) {
106
  $sbi_statuses_option = get_option( 'sbi_statuses', array() );
107
 
108
- if ( ! isset( $sbi_statuses_option['gdpr'] ) || $retest ) {
109
  $test_image = trailingslashit( SBI_PLUGIN_URL ) . 'img/placeholder.png';
110
 
111
  $image_editor = wp_get_image_editor( $test_image );
@@ -169,7 +169,7 @@ class SB_Instagram_GDPR_Integrations {
169
  }
170
 
171
  if ( isset( $_GET['tab'] ) && $_GET['tab'] !== 'support' ) {
172
- $errors[] = '<a href="?page=sb-instagram-feed&amp;tab=customize-advanced&amp;retest=1" class="button button-secondary">' . __( 'Retest', 'instagram-feed' ) . '</a>';
173
  }
174
 
175
  return implode( '<br>', $errors );
105
  public static function gdpr_tests_successful( $retest = false ) {
106
  $sbi_statuses_option = get_option( 'sbi_statuses', array() );
107
 
108
+ if ( ! isset( $sbi_statuses_option['gdpr']['image_editor'] ) || $retest ) {
109
  $test_image = trailingslashit( SBI_PLUGIN_URL ) . 'img/placeholder.png';
110
 
111
  $image_editor = wp_get_image_editor( $test_image );
169
  }
170
 
171
  if ( isset( $_GET['tab'] ) && $_GET['tab'] !== 'support' ) {
172
+ $errors[] = '<a href="?page=sb-instagram-feed&amp;tab=customize&amp;retest=1" class="button button-secondary">' . __( 'Retest', 'instagram-feed' ) . '</a>';
173
  }
174
 
175
  return implode( '<br>', $errors );
inc/class-sb-instagram-parse.php CHANGED
@@ -125,6 +125,20 @@ class SB_Instagram_Parse
125
  } elseif ( $carousel_item['media_type'] === 'VIDEO' && empty( $full_size ) ) {
126
  if ( isset( $carousel_item['thumbnail_url'] ) ) {
127
  $full_size = $carousel_item['thumbnail_url'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  }
129
  }
130
 
@@ -268,14 +282,7 @@ class SB_Instagram_Parse
268
  } elseif ( ! empty( $header_data['local_avatar'] ) ) {
269
  return $header_data['local_avatar'];
270
  } else {
271
- $use_cdn = true;
272
- if ( SB_Instagram_GDPR_Integrations::doing_gdpr( $settings ) ) {
273
- $use_cdn = false;
274
- if ( ! SB_Instagram_GDPR_Integrations::blocking_cdn( $settings ) ) {
275
- $use_cdn = true;
276
- }
277
- }
278
- if ( $use_cdn ) {
279
  if ( isset( $header_data['profile_picture'] ) ) {
280
  return $header_data['profile_picture'];
281
  } elseif ( isset( $header_data['profile_picture_url'] ) ) {
125
  } elseif ( $carousel_item['media_type'] === 'VIDEO' && empty( $full_size ) ) {
126
  if ( isset( $carousel_item['thumbnail_url'] ) ) {
127
  $full_size = $carousel_item['thumbnail_url'];
128
+ } else {
129
+ $media = trailingslashit( SBI_PLUGIN_URL ) . 'img/thumb-placeholder.png';
130
+ //attempt to get
131
+ $permalink = SB_Instagram_Parse::fix_permalink( SB_Instagram_Parse::get_permalink( $carousel_item ) );
132
+ $single = new SB_Instagram_Single( $permalink );
133
+ $single->init();
134
+ $carousel_item_post = $single->get_post();
135
+
136
+ if ( isset( $carousel_item_post['thumbnail_url'] ) ) {
137
+ $media = $carousel_item_post['thumbnail_url'];
138
+ } elseif ( isset( $carousel_item_post['media_url'] ) && strpos( $carousel_item_post['media_url'], '.mp4' ) === false ) {
139
+ $media = $carousel_item_post['media_url'];
140
+ }
141
+ $full_size = $media;
142
  }
143
  }
144
 
282
  } elseif ( ! empty( $header_data['local_avatar'] ) ) {
283
  return $header_data['local_avatar'];
284
  } else {
285
+ if ( ! SB_Instagram_GDPR_Integrations::doing_gdpr( $settings ) ) {
 
 
 
 
 
 
 
286
  if ( isset( $header_data['profile_picture'] ) ) {
287
  return $header_data['profile_picture'];
288
  } elseif ( isset( $header_data['profile_picture_url'] ) ) {
inc/class-sb-instagram-post-set.php CHANGED
@@ -120,12 +120,12 @@ class SB_Instagram_Post_Set {
120
  $number_resized = 0;
121
  $number_updated = 0;
122
  $resized_image_data_for_set = array();
123
- $resizing_disabled = $sb_instagram_posts_manager->image_resizing_disabled() || $sb_instagram_posts_manager->max_resizing_per_time_period_reached();
124
  $is_top_post_feed = (substr( $this->transient_name, 4, 1 ) === '+');
125
 
126
  foreach ( $this->post_data as $single_instagram_post_data ) {
127
 
128
- if ( $posts_iterated_through < 60 ) {
129
  $single_post = new SB_Instagram_Post( $single_instagram_post_data['id'] );
130
  $single_post->set_instagram_api_data( $single_instagram_post_data );
131
  $resized_image_data_for_set[ $single_instagram_post_data['id'] ] = array();
120
  $number_resized = 0;
121
  $number_updated = 0;
122
  $resized_image_data_for_set = array();
123
+ $resizing_disabled = $sb_instagram_posts_manager->image_resizing_disabled( $this->transient_name ) || $sb_instagram_posts_manager->max_resizing_per_time_period_reached();
124
  $is_top_post_feed = (substr( $this->transient_name, 4, 1 ) === '+');
125
 
126
  foreach ( $this->post_data as $single_instagram_post_data ) {
127
 
128
+ if ( isset( $single_instagram_post_data['id'] ) && $posts_iterated_through < 100 ) {
129
  $single_post = new SB_Instagram_Post( $single_instagram_post_data['id'] );
130
  $single_post->set_instagram_api_data( $single_instagram_post_data );
131
  $resized_image_data_for_set[ $single_instagram_post_data['id'] ] = array();
inc/class-sb-instagram-post.php CHANGED
@@ -173,7 +173,12 @@ class SB_Instagram_Post
173
  $this->db_id = $wpdb->insert_id;
174
  $this->insert_sbi_instagram_feeds_posts( $transient_name );
175
  } else {
176
- // log error
 
 
 
 
 
177
  }
178
 
179
  return true;
@@ -246,25 +251,26 @@ class SB_Instagram_Post
246
 
247
  if ( ! $saved_image ) {
248
  global $sb_instagram_posts_manager;
 
 
249
 
250
- $sb_instagram_posts_manager->add_error( 'image_editor_save', array(
251
- __( 'Error saving edited image.', 'instagram-feed' ),
252
- $full_file_name
253
- ) );
254
  } else {
255
  $one_successful_image_resize = true;
256
  }
257
  } else {
258
- global $sb_instagram_posts_manager;
259
 
260
  $message = __( 'Error editing image.', 'instagram-feed' );
261
  if ( isset( $image_editor ) && isset( $image_editor->errors ) ) {
262
  foreach ( $image_editor->errors as $key => $item ) {
263
- $message .= ' ' . $key . '- ' . $item[0] . ' |';
 
 
 
264
  }
265
  }
266
 
267
- $sb_instagram_posts_manager->add_error( 'image_editor', array( $file_name, $message ) );
 
268
  }
269
 
270
  }
@@ -342,7 +348,7 @@ class SB_Instagram_Post
342
  *
343
  * @since 2.0/4.0
344
  */
345
- public function update_db_data( $update_last_requested = true, $transient_name = false, $image_sizes, $upload_dir, $upload_url, $timestamp_for_update = false ) {
346
 
347
  if ( empty( $this->db_id ) ) {
348
  return false;
@@ -396,7 +402,7 @@ class SB_Instagram_Post
396
  $error = $wpdb->last_error;
397
  $query = $wpdb->last_query;
398
 
399
- $sb_instagram_posts_manager->add_error( 'database_update_post', array( __( 'Error updating post.', 'instagram-feed' ), $error . '<br><code>' . $query . '</code>' ) );
400
  }
401
  }
402
 
@@ -419,7 +425,15 @@ class SB_Instagram_Post
419
  $feed_id = $feed_id_array[0];
420
  $results = $wpdb->get_results( $wpdb->prepare( "SELECT feed_id FROM $table_name WHERE instagram_id = %s AND feed_id = %s LIMIT 1", $this->instagram_post_id, $feed_id ), ARRAY_A );
421
 
422
- return isset( $results[0]['feed_id'] );
 
 
 
 
 
 
 
 
423
  }
424
 
425
  /**
@@ -442,16 +456,24 @@ class SB_Instagram_Post
442
  $entry_data = array(
443
  $this->db_id,
444
  "'" . esc_sql( $this->instagram_api_data['id'] ) . "'",
445
- "'" . esc_sql( $feed_id ) . "'"
446
  );
447
- $entry_string = implode( ',',$entry_data );
448
 
449
- $error = $wpdb->query( "INSERT INTO $table_name
 
 
 
 
 
 
 
 
450
  (id,instagram_id,feed_id) VALUES ($entry_string);" );
 
451
  } else {
452
  global $sb_instagram_posts_manager;
453
 
454
- $sb_instagram_posts_manager->add_error( 'database_insert_post', array( __( 'Error inserting post.', 'instagram-feed' ), __( 'No database ID.', 'instagram-feed' ) ) );
455
  return false;
456
  }
457
 
@@ -462,8 +484,7 @@ class SB_Instagram_Post
462
  global $sb_instagram_posts_manager;
463
  $error = $wpdb->last_error;
464
  $query = $wpdb->last_query;
465
-
466
- $sb_instagram_posts_manager->add_error( 'database_insert_post', array( __( 'Error inserting post.', 'instagram-feed' ), $error . '<br><code>' . $query . '</code>' ) );
467
  }
468
  }
469
 
173
  $this->db_id = $wpdb->insert_id;
174
  $this->insert_sbi_instagram_feeds_posts( $transient_name );
175
  } else {
176
+ global $sb_instagram_posts_manager;
177
+
178
+ $error = $wpdb->last_error;
179
+ $query = $wpdb->last_query;
180
+
181
+ $sb_instagram_posts_manager->add_error( 'storage', __( 'Error inserting post.', 'instagram-feed' ) . ' ' . $error . '<br><code>' . $query . '</code>' );
182
  }
183
 
184
  return true;
251
 
252
  if ( ! $saved_image ) {
253
  global $sb_instagram_posts_manager;
254
+ $details = __( 'Error saving edited image.', 'instagram-feed' ) . ' ' . $full_file_name;
255
+ $sb_instagram_posts_manager->add_error( 'image_editor', $details );
256
 
 
 
 
 
257
  } else {
258
  $one_successful_image_resize = true;
259
  }
260
  } else {
 
261
 
262
  $message = __( 'Error editing image.', 'instagram-feed' );
263
  if ( isset( $image_editor ) && isset( $image_editor->errors ) ) {
264
  foreach ( $image_editor->errors as $key => $item ) {
265
+ $message .= ' ' . $key . ' - ' . $item[0] . ' |';
266
+ }
267
+ if ( isset( $image_editor ) && isset( $image_editor->error_data ) ) {
268
+ $message .= ' ' . sbi_json_encode( $image_editor->error_data ) . ' |';
269
  }
270
  }
271
 
272
+ global $sb_instagram_posts_manager;
273
+ $sb_instagram_posts_manager->add_error( 'image_editor', $message );
274
  }
275
 
276
  }
348
  *
349
  * @since 2.0/4.0
350
  */
351
+ public function update_db_data( $update_last_requested = true, $transient_name = false, $image_sizes = array(), $upload_dir = '', $upload_url ='', $timestamp_for_update = false ) {
352
 
353
  if ( empty( $this->db_id ) ) {
354
  return false;
402
  $error = $wpdb->last_error;
403
  $query = $wpdb->last_query;
404
 
405
+ $sb_instagram_posts_manager->add_error( 'storage', __( 'Error updating post.', 'instagram-feed' ) . ' ' . $error . '<br><code>' . $query . '</code>' );
406
  }
407
  }
408
 
425
  $feed_id = $feed_id_array[0];
426
  $results = $wpdb->get_results( $wpdb->prepare( "SELECT feed_id FROM $table_name WHERE instagram_id = %s AND feed_id = %s LIMIT 1", $this->instagram_post_id, $feed_id ), ARRAY_A );
427
 
428
+ if ( isset( $results[0]['feed_id'] ) ) {
429
+ return true;
430
+ }
431
+ if ( isset( $this->instagram_api_data['term'] ) ) {
432
+ $results = $wpdb->get_results( $wpdb->prepare( "SELECT hashtag FROM $table_name WHERE instagram_id = %s AND hashtag = %s LIMIT 1", $this->instagram_post_id, strtolower( str_replace( '#', '', $this->instagram_api_data['term'] ) ) ), ARRAY_A );
433
+ return isset( $results[0]['hashtag'] );
434
+ }
435
+
436
+ return false;
437
  }
438
 
439
  /**
456
  $entry_data = array(
457
  $this->db_id,
458
  "'" . esc_sql( $this->instagram_api_data['id'] ) . "'",
459
+ "'" . esc_sql( $feed_id ) . "'",
460
  );
 
461
 
462
+ if ( ! empty( $this->instagram_api_data['term'] ) ) {
463
+ $entry_data[] = "'" . esc_sql( strtolower( str_replace( '#', '', $this->instagram_api_data['term'] ) ) ) . "'";
464
+ $entry_string = implode( ',',$entry_data );
465
+
466
+ $error = $wpdb->query( "INSERT INTO $table_name
467
+ (id,instagram_id,feed_id,hashtag) VALUES ($entry_string);" );
468
+ } else {
469
+ $entry_string = implode( ',',$entry_data );
470
+ $error = $wpdb->query( "INSERT INTO $table_name
471
  (id,instagram_id,feed_id) VALUES ($entry_string);" );
472
+ }
473
  } else {
474
  global $sb_instagram_posts_manager;
475
 
476
+ $sb_instagram_posts_manager->add_error( 'storage', __( 'Error inserting post.', 'instagram-feed' ) . ' ' . __( 'No database ID.', 'instagram-feed' ) );
477
  return false;
478
  }
479
 
484
  global $sb_instagram_posts_manager;
485
  $error = $wpdb->last_error;
486
  $query = $wpdb->last_query;
487
+ $sb_instagram_posts_manager->add_error( 'storage', __( 'Error inserting post.', 'instagram-feed' ) . ' ' . $error . '<br><code>' . $query . '</code>' );
 
488
  }
489
  }
490
 
inc/class-sb-instagram-posts-manager.php CHANGED
@@ -32,7 +32,7 @@ class SB_Instagram_Posts_Manager
32
  /**
33
  * @var array
34
  */
35
- var $frontend_errors;
36
 
37
  /**
38
  * @var bool
@@ -45,68 +45,339 @@ class SB_Instagram_Posts_Manager
45
  public function __construct() {
46
  $this->sbi_options = get_option( 'sb_instagram_settings' );
47
  $this->errors = get_option( 'sb_instagram_errors', array() );
48
- $this->ajax_status = get_option( 'sb_instagram_ajax_status', array( 'tested' => false, 'successful' => false ) );
49
- $this->frontend_errors = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  }
51
 
52
  /**
53
- * @return array
54
  *
55
- * @since 2.0/5.0
 
 
 
 
56
  */
57
- public function get_ajax_status() {
58
- return $this->ajax_status;
 
 
 
 
 
 
 
 
 
 
59
  }
60
 
61
  /**
62
- * @param $to_update
 
63
  *
64
- * @since 2.0/5.0
 
 
 
 
65
  */
66
- public function update_ajax_status( $to_update ) {
67
- foreach ( $to_update as $key => $value ) {
68
- $this->ajax_status[ $key ] = $value;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  }
70
 
71
- update_option( 'sb_instagram_ajax_status', $this->ajax_status );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  }
73
 
74
  /**
75
- * When the plugin is first installed and used, an AJAX call to admin-ajax.php
76
- * is made to verify that it's available
77
- *
78
- * @param bool $force_check
79
  *
80
- * @return bool
81
  *
82
- * @since 2.0/5.0
83
  */
84
- public function maybe_start_ajax_test( $force_check = false ) {
85
- if ( ! $this->ajax_status['tested'] || $force_check ) {
86
- set_transient( 'sb_instagram_doing_ajax_test', 'yes', 60*60 );
87
- $this->update_ajax_status( array( 'tested' => true ) );
88
- return true;
 
89
  }
 
90
 
91
- return false;
 
92
  }
93
 
94
  /**
95
- * Called if a successful admin ajax request is made
96
  *
97
- * @since 2.0/5.0
98
  */
99
- public function update_successful_ajax_test() {
100
- $this->update_ajax_status( array( 'successful' => true ) );
101
  }
102
 
103
  /**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  * @return bool
105
  *
106
- * @since 2.0/5.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  */
108
- public function should_add_ajax_test_notice() {
109
- return ($this->ajax_status['tested'] && ! $this->ajax_status['successful'] && get_transient( 'sb_instagram_doing_ajax_test' ) !== 'yes');
 
 
110
  }
111
 
112
  /**
@@ -187,8 +458,10 @@ class SB_Instagram_Posts_Manager
187
  *
188
  * @since 2.0/4.0
189
  */
190
- public function image_resizing_disabled() {
191
- $disable_resizing = isset( $this->sbi_options['sb_instagram_disable_resize'] ) ? $this->sbi_options['sb_instagram_disable_resize'] === 'on' || $this->sbi_options['sb_instagram_disable_resize'] === true : false;
 
 
192
 
193
  if ( ! $disable_resizing ) {
194
  $disable_resizing = isset( $this->resizing_tables_exist ) ? ! $this->resizing_tables_exist : ! $this->does_resizing_tables_exist();
@@ -206,6 +479,9 @@ class SB_Instagram_Posts_Manager
206
  * @since 2.0/5.0
207
  */
208
  public function does_resizing_tables_exist() {
 
 
 
209
  global $wpdb;
210
 
211
  $table_name = esc_sql( $wpdb->prefix . SBI_INSTAGRAM_POSTS_TYPE );
@@ -250,11 +526,9 @@ class SB_Instagram_Posts_Manager
250
  $connected_accounts = isset( $options['connected_accounts'] ) ? $options['connected_accounts'] : array();
251
 
252
  foreach ( $connected_accounts as $account_id => $data ) {
253
-
254
  if ( isset( $data['local_avatar'] ) ) {
255
  unset( $connected_accounts[ $account_id ]['local_avatar'] );
256
  }
257
-
258
  }
259
 
260
  $options['connected_accounts'] = $connected_accounts;
@@ -289,7 +563,7 @@ class SB_Instagram_Posts_Manager
289
  if ( $created ) {
290
  $this->remove_error( 'upload_dir' );
291
  } else {
292
- $this->add_error( 'upload_dir', array( __( 'There was an error creating the folder for storing resized images.', 'instagram-feed' ), $upload_dir ) );
293
  }
294
  } else {
295
  $this->remove_error( 'upload_dir' );
@@ -298,12 +572,24 @@ class SB_Instagram_Posts_Manager
298
  sbi_create_database_table();
299
  }
300
 
 
 
 
 
 
 
 
 
 
301
  public static function top_post_request_already_made( $hashtag ) {
302
  $list_of_top_hashtags = get_option( 'sbi_top_api_calls', array() );
303
 
304
  return in_array( $hashtag, $list_of_top_hashtags, true );
305
  }
306
 
 
 
 
307
  public static function maybe_update_list_of_top_hashtags( $hashtag ) {
308
  $list_of_top_hashtags = get_option( 'sbi_top_api_calls', array() );
309
 
@@ -324,250 +610,465 @@ class SB_Instagram_Posts_Manager
324
  }
325
 
326
  /**
327
- * @param $type
328
- * @param $message_array
329
  *
330
  * @since 2.0/4.0
331
  */
332
- public function add_error( $type, $message_array ) {
333
- $this->errors[ $type ] = $message_array;
334
 
335
- update_option( 'sb_instagram_errors', $this->errors, false );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
  }
337
 
338
  /**
339
- * @param $type
 
 
340
  *
341
- * @since 2.0/4.0
 
 
342
  */
343
- public function remove_error( $type ) {
344
- if ( isset( $this->errors[ $type ] ) ) {
345
- unset( $this->errors[ $type ] );
 
 
 
 
346
 
347
- update_option( 'sb_instagram_errors', $this->errors, false );
348
- } else {
349
 
350
- foreach ( $this->errors as $type => $error ) {
351
- if ( strpos( $type, 'expiration_' ) !== false ) {
352
- unset( $this->errors[ $type ] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
  }
 
354
  }
355
 
356
- delete_option( 'sb_instagram_error_page' );
357
- update_option( 'sb_instagram_errors', $this->errors, false );
 
358
  }
 
 
359
  }
360
 
 
 
 
 
361
  public function remove_all_errors() {
362
- if ( empty( $this->errors ) ) {
363
- return;
364
- }
365
- foreach ( $this->errors as $type => $error ) {
366
- if ( strpos( $type, 'expiration_' ) === false ) {
367
- unset( $this->errors[ $type ] );
368
- }
369
- }
370
- delete_option( 'sb_instagram_error_page' );
 
 
 
 
 
371
  update_option( 'sb_instagram_errors', $this->errors, false );
372
  sb_instagram_cron_clear_cache();
373
  }
374
 
 
 
 
375
  public function update_error_page( $id ) {
376
  if ( $id !== 0 ) {
377
  update_option( 'sb_instagram_error_page', $id, false );
378
  }
379
  }
380
 
 
 
 
 
 
381
  public function get_error_page() {
382
- return get_option( 'sb_instagram_error_page', false );
 
 
 
383
  }
384
 
385
  /**
386
- * @param $type
387
- * @param $message
388
  *
389
  * @since 2.0/5.0
390
  */
391
- public function add_frontend_error( $type, $message ) {
392
- $this->frontend_errors = array();
393
- $this->frontend_errors[ $type ] = $message;
394
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
395
 
396
- public function remove_frontend_error( $type ) {
397
- if ( isset( $this->frontend_errors[ $type ] ) ) {
398
- unset( $this->frontend_errors[ $type ] );
399
  }
 
 
 
 
 
 
 
 
 
400
  }
401
 
402
  /**
403
- * @return array
404
  *
405
- * @since 2.0/5.0
 
 
406
  */
407
- public function get_frontend_errors() {
408
- if ( isset( $this->frontend_errors['api_delay'] ) ) {
409
- return array( 'api_delay' => $this->frontend_errors['api_delay'] );
410
  }
 
 
 
411
 
412
- return $this->frontend_errors;
 
 
 
 
 
 
 
413
  }
414
 
415
- public function get_critical_errors() {
416
- $errors = $this->get_errors();
417
- $error = '';
418
- $error_100_found = false;
419
- $reconnect_instructions_needed = false;
420
- $cap = current_user_can( 'manage_instagram_feed_options' ) ? 'manage_instagram_feed_options' : 'manage_options';
421
- $cap = apply_filters( 'sbi_settings_pages_capability', $cap );
422
- $hash = '';
423
- if ( ! empty( $errors ) && current_user_can( $cap ) ) {
424
- if ( isset( $errors['api'] ) ) {
425
- $error .= '<p>' . $errors['api'][1] . '</p>';
426
- if ( isset( $errors['api'][2] ) ) {
427
- $hash = '#' . $errors['api'][2];
428
- }
429
- } elseif ( isset( $errors['connection'] ) ) {
430
- $error .= '<p>' . $errors['connection'][1] . '</p>';
431
- if ( isset( $errors['connection'][2] ) ) {
432
- $hash = '#' . $errors['connection'][2];
433
- }
434
- } else {
435
- foreach ( $errors as $key => $value ) {
436
- if ( strpos( $key, 'at_' ) !== false ) {
437
- $reconnect_instructions_needed = true;
438
 
439
- $error = '<p>' . $value[1] . '</p>';
440
- if ( strpos( $key, 'at_100' ) !== false ) {
441
- $error_100_found = true;
442
- }
443
- } elseif ( strpos( $key, 'expiration_' ) !== false ) {
444
- $reconnect_instructions_needed = true;
445
 
446
- $error = '<p>' . $value[1] . '</p>';
447
- }
448
- if ( isset( $value[2] ) ) {
449
- $hash = '#' . $value[2];
450
- }
451
  }
452
  }
453
- } else {
454
- return '';
455
  }
 
 
456
 
457
- foreach ( $errors as $error_key => $message ) {
458
- if ( strpos( $error_key, 'ig_no_posts_for_' ) !== false ) {
459
- if ( (int)$message[0] < (time() - 12 * 60 * 60) ) {
460
- $this->remove_error( $error_key );
461
- } else {
462
- $error .= '<p>' . $message[1] . '</p>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
463
  }
464
- } elseif ( strpos( $error_key, 'error_18' ) !== false ) {
465
- if ( (int)$message[0] < (time() - 24 * 60 * 60) ) {
466
- $this->remove_error( $error_key );
 
 
 
 
467
  } else {
468
- $error .= '<p>' . $message[1] . '</p>';
469
  }
470
  }
 
 
 
 
 
 
471
  }
472
 
 
 
473
 
474
- if ( current_user_can( $cap ) ) {
475
- if ( $reconnect_instructions_needed && ! $error_100_found ) {
476
- $on_configure_page = (is_admin() && (! isset( $_GET['tab']) || $_GET['tab'] === 'configure'));
477
- if ( $on_configure_page ) {
478
- $error .= '<p class="sbi-error-directions sbi-reconnect"><a href="https://smashballoon.com/instagram-feed/docs/errors/' . $hash . '" target="_blank" rel="noopener">' . __( 'Reconnect Account and Refresh Token', 'instagram-feed' ) . '</a></p>';
479
- } else {
480
- $link = admin_url( '?page=sb-instagram-feed' );
481
- $error .= '<p class="sbi-error-directions sbi-reconnect"><a href="'. esc_url( $link ).'" target="_blank" rel="noopener">' . __( 'Reconnect Your Account in the Admin Area', 'instagram-feed' ) . '</a></p>';
482
- }
 
 
 
 
 
 
 
 
 
483
  } else {
484
- $error .= '<p class="sbi-error-directions"><a href="https://smashballoon.com/instagram-feed/docs/errors/' . $hash . '" target="_blank" rel="noopener">' . __( 'Directions on How to Resolve This Issue', 'instagram-feed' ) . '</a></p>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
485
  }
486
  }
 
 
 
 
 
 
487
 
488
  // remove link to FB docs
489
- $error = str_replace( 'Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api', '', $error );
490
 
491
- return $error;
492
  }
493
 
494
  /**
495
- * @return array
496
- *
497
  * @since 2.0/5.0
498
  */
499
  public function reset_frontend_errors() {
500
- return $this->frontend_errors = array();
501
  }
502
 
 
 
 
 
 
 
 
 
 
 
503
 
504
- public function clear_hashtag_errors() {
505
- $errors = $this->get_errors();
506
 
507
- foreach ( $errors as $error_key => $message ) {
508
- if ( strpos( $error_key, 'ig_no_posts_for_' ) !== false || strpos( $error_key, 'error_18' ) !== false ) {
509
- $this->remove_error( $error_key );
 
510
  }
 
511
  }
512
- }
513
 
514
- /**
515
- * @since 2.0/5.1.2
516
- */
517
- public function add_api_request_delay( $time_in_seconds = 300, $account_id = false ) {
518
- if ( $account_id ) {
519
- set_transient( SBI_USE_BACKUP_PREFIX . 'sbi_' . $account_id, '1', $time_in_seconds );
520
- } else {
521
- set_transient( SBI_USE_BACKUP_PREFIX . 'sbi_delay_requests', '1', $time_in_seconds );
 
 
 
522
  }
523
  }
524
 
525
  /**
526
  * @since 2.0/5.1.2
527
  */
528
- public function are_current_api_request_delays( $account_id = false ) {
529
- $is_delay = (get_transient( SBI_USE_BACKUP_PREFIX . 'sbi_delay_requests' ) !== false);
530
-
531
- if ( $is_delay ) {
532
- $this->reset_frontend_errors();
533
- $error = '<p><b>' . sprintf( __( 'Error: API requests are being delayed.', 'instagram-feed' ) ) . ' ' . __( 'New posts will not be retrieved for at least 5 minutes.', 'instagram-feed' ) . '</b></p>';
534
- $error .= $this->get_critical_errors();
535
-
536
- $this->add_frontend_error( 'api_delay', $error );
537
-
538
  }
 
539
 
540
- if ( ! $is_delay && $account_id ) {
541
- $is_delay = (get_transient( SBI_USE_BACKUP_PREFIX . 'sbi_' . $account_id ) !== false);
542
- }
543
 
544
- $is_delay = apply_filters( 'sbi_is_api_delay', $is_delay );
 
 
 
 
 
 
 
 
545
 
546
- return $is_delay;
547
  }
548
 
 
 
 
 
 
549
  public function are_critical_errors() {
 
 
 
 
 
 
 
 
 
 
550
 
551
- $critical_error_numbers = array( 100, 400, 24, 18 );
552
- $errors = $this->get_errors();
553
-
554
- $are_errors = false;
555
-
556
- foreach ( $errors as $error_key => $message ) {
557
- if ( strpos( $error_key, 'connection' ) !== false ) {
558
- $are_errors = true;
559
- } elseif ( strpos( $error_key, 'api' ) !== false ) {
560
-
561
- if ( in_array( (int)$errors['api'][2], $critical_error_numbers, true ) ) {
562
- $are_errors = true;
563
  }
564
- } elseif ( strpos( $error_key, 'at_' ) !== false ) {
565
- $are_errors = true;
566
- } elseif ( strpos( $error_key, 'expiration_' ) !== false ) {
567
- $are_errors = true;
568
  }
569
  }
570
 
571
- return $are_errors;
572
  }
573
  }
32
  /**
33
  * @var array
34
  */
35
+ var $display_error;
36
 
37
  /**
38
  * @var bool
45
  public function __construct() {
46
  $this->sbi_options = get_option( 'sb_instagram_settings' );
47
  $this->errors = get_option( 'sb_instagram_errors', array() );
48
+ if ( ! isset( $this->errors['connection'] ) ) {
49
+ $this->errors = array(
50
+ 'connection' => array(),
51
+ 'hashtag' => array(),
52
+ 'resizing' => array(),
53
+ 'database_create' => array(),
54
+ 'upload_dir' => array(),
55
+ 'accounts' => array(),
56
+ 'error_log' => array(),
57
+ 'action_log' => array()
58
+ );
59
+ }
60
+
61
+ $this->display_error = array();
62
+ if ( $this->does_resizing_tables_exist() ) {
63
+ $this->resizing_tables_exist = true;
64
+ }
65
  }
66
 
67
  /**
68
+ * Stores information about an encountered error related to a connected account
69
  *
70
+ * @param $connected_account array
71
+ * @param $error_type string
72
+ * @param $details mixed/array/string
73
+ *
74
+ * @since 2.7/5.10
75
  */
76
+ public function add_connected_account_error( $connected_account, $error_type, $details ) {
77
+ $account_id = $connected_account['user_id'];
78
+ $this->errors['accounts'][ $account_id ][ $error_type ] = $details;
79
+
80
+ if ( $error_type === 'api' ) {
81
+ $this->errors['accounts'][ $account_id ][ $error_type ]['clear_time'] = time() + 60 * 3;
82
+ }
83
+
84
+ if ( isset( $details['error']['code'] )
85
+ && (int)$details['error']['code'] === 18 ) {
86
+ $this->errors['accounts'][ $account_id ][ $error_type ]['clear_time'] = time() + 60 * 15;
87
+ }
88
  }
89
 
90
  /**
91
+ * Stores errors so they can be retrieved and explained to users
92
+ * in messages as well as temporarily disable certain features
93
  *
94
+ * @param string $type
95
+ * @param array $details
96
+ * @param mixed/bool/array $connected_account_term
97
+ *
98
+ * @since 2.7/5.10
99
  */
100
+ public function add_error( $type, $details, $connected_account_term = false ) {
101
+ $connected_account = false;
102
+
103
+ $log_item = date( 'm-d H:i:s' ) . ' - ';
104
+ if ( $connected_account_term ) {
105
+ if ( ! is_array( $connected_account_term ) ) {
106
+ $connected_account = SB_Instagram_Connected_Account::lookup( $connected_account_term );
107
+ } else {
108
+ $connected_account = $connected_account_term;
109
+ }
110
+
111
+ $this->add_connected_account_error( $connected_account, $type, $details );
112
+ }
113
+
114
+ // is it connection? or what type?
115
+ if ( $type === 'api'
116
+ || $type === 'wp_remote_get' ) {
117
+ $connection_details = array(
118
+ 'error_id' => ''
119
+ );
120
+
121
+ $connection_details['critical'] = false;
122
+ if ( isset( $details['error']['code'] ) ) {
123
+ $connection_details['error_id'] = $details['error']['code'];
124
+ if ( $this->is_critical_error( $details ) ) {
125
+ $connection_details['critical'] = true;
126
+ }
127
+ } elseif ( isset( $details['response'] ) && is_wp_error( $details['response'] ) ) {
128
+ foreach ( $details['response']->errors as $key => $item ) {
129
+ $connection_details['error_id'] = $key;
130
+ }
131
+ $connection_details['critical'] = true;
132
+ }
133
+ if ( ! is_admin() ) {
134
+ $connection_details['post_id'] = get_the_ID();
135
+ }
136
+ $connection_details['error_message'] = $this->generate_error_message( $details, $connected_account );
137
+ $log_item .= $connection_details['error_message']['admin_only'];
138
+ $this->maybe_set_display_error( 'connection', $connection_details );
139
+ $this->errors['connection'] = $connection_details;
140
+ }
141
+
142
+ if ( $type === 'hashtag' ) {
143
+ $hashtag_details = array(
144
+ 'error_id' => '',
145
+ 'hashtag' => isset( $details['hashtag'] ) ? $details['hashtag'] : ''
146
+ );
147
+ if ( isset( $details['error']['code'] ) ) {
148
+ if ( (int)$details['error']['code'] === 24 ) {
149
+ $hashtag_details['clear_time'] = time() + 60 * 5;
150
+ }
151
+ }
152
+
153
+ if ( isset( $details['error']['code'] ) ) {
154
+ $hashtag_details['error_id'] = $details['error']['code'];
155
+ } elseif ( isset( $details['response'] ) && is_wp_error( $details['response'] ) ) {
156
+ foreach ( $details['response']->errors as $key => $item ) {
157
+ $hashtag_details['error_id'] = $key;
158
+ }
159
+ }
160
+ if ( ! is_admin() ) {
161
+ $hashtag_details['post_id'] = get_the_ID();
162
+ }
163
+ $hashtag_details['error_message'] = $this->generate_error_message( $details, $connected_account );
164
+ $log_item .= $hashtag_details['error_message']['admin_only'];
165
+ $this->maybe_set_display_error( 'hashtag', $hashtag_details );
166
+
167
+ $found = false;
168
+ if ( isset( $details['hashtag'] ) ) {
169
+ foreach ( $this->errors['hashtag'] as $hashtag_error_item ) {
170
+ if ( isset( $hashtag_error_item['hashtag'] )
171
+ && strtolower( $hashtag_error_item['hashtag'] ) === strtolower( $details['hashtag'] )
172
+ && $hashtag_error_item['error_id'] === $details['error_id'] ) {
173
+ $found = true;
174
+ }
175
+ }
176
+ }
177
+
178
+ if ( ! $found ) {
179
+ $this->errors['hashtag'][] = $hashtag_details;
180
+ }
181
  }
182
 
183
+ if ( $type === 'image_editor'
184
+ || $type === 'storage' ) {
185
+
186
+ $this->errors['resizing'] = $details;
187
+ $log_item .= $details;
188
+ }
189
+
190
+ if ( $type === 'database_create' ) {
191
+ $this->errors['database_create'] = $details;
192
+ $log_item .= $details;
193
+ }
194
+
195
+ if ( $type === 'upload_dir' ) {
196
+ $this->errors['upload_dir'] = $details;
197
+ $log_item .= $details;
198
+ }
199
+
200
+ $current_log = $this->errors['error_log'];
201
+ if ( is_array( $current_log ) && count( $current_log ) >= 10 ) {
202
+ reset( $current_log );
203
+ unset( $current_log[ key( $current_log ) ] );
204
+ }
205
+ $current_log[] = $log_item;
206
+ $this->errors['error_log'] = $current_log;
207
+ update_option( 'sb_instagram_errors', $this->errors, false );
208
  }
209
 
210
  /**
211
+ * Stores a time stamped string of information about
212
+ * actions that might lead to correcting an error
 
 
213
  *
214
+ * @param string $log_item
215
  *
216
+ * @since 2.7/5.10
217
  */
218
+ public function add_action_log( $log_item ) {
219
+ $current_log = $this->errors['action_log'];
220
+
221
+ if ( is_array( $current_log ) && count( $current_log ) >= 10 ) {
222
+ reset( $current_log );
223
+ unset( $current_log[ key( $current_log ) ] );
224
  }
225
+ $current_log[] = date( 'm-d H:i:s' ) . ' - ' . $log_item;
226
 
227
+ $this->errors['action_log'] = $current_log;
228
+ update_option( 'sb_instagram_errors', $this->errors, false );
229
  }
230
 
231
  /**
232
+ * @return mixed
233
  *
234
+ * @since 2.7/5.10
235
  */
236
+ public function get_error_log() {
237
+ return $this->errors['error_log'];
238
  }
239
 
240
  /**
241
+ * @return mixed
242
+ *
243
+ * @since 2.7/5.10
244
+ */
245
+ public function get_action_log() {
246
+ return $this->errors['action_log'];
247
+ }
248
+
249
+ /**
250
+ * Certain API errors are considered critical and will trigger
251
+ * the various notifications to users to correct them.
252
+ *
253
+ * @param $details
254
+ *
255
  * @return bool
256
  *
257
+ * @since 2.7/5.10
258
+ */
259
+ public function is_critical_error( $details ) {
260
+ $error_code = (int)$details['error']['code'];
261
+
262
+ $critical_codes = array(
263
+ 803, // ID doesn't exist
264
+ 100, // access token or permissions
265
+ 10, // app permissions or scopes
266
+ );
267
+
268
+ return in_array( $error_code, $critical_codes, true );
269
+ }
270
+
271
+ /**
272
+ * Creates an array of information for easy display of API errors
273
+ *
274
+ * @param $response
275
+ * @param array $connected_account
276
+ *
277
+ * @return array
278
+ *
279
+ * @since 2.7/5.10
280
+ */
281
+ public function generate_error_message( $response, $connected_account = array( 'username' => '' ) ) {
282
+
283
+ $error_message_return = array(
284
+ 'error_message' => '',
285
+ 'admin_only' => '',
286
+ 'frontend_directions' => '',
287
+ 'backend_directions' => '',
288
+ 'time' => time()
289
+ );
290
+ $hash = isset( $response['error']['code'] ) ? '#' . (int)$response['error']['code'] : '';
291
+
292
+ if ( isset( $response['response'] ) && is_wp_error( $response['response'] ) ) {
293
+ $error_message_return['error_message'] = __( 'HTTP Error. Unable to connect to the Instagram API.', 'instagram-feed' ) . ' ' . __( 'Feed will not update.', 'instagram-feed' );
294
+ $error_message_return['admin_only'] = sprintf( __( 'Error connecting to %s.', 'instagram-feed' ), $response['url'] );
295
+
296
+ $error_message_return['frontend_directions'] = '<a href="https://smashballoon.com/instagram-feed/docs/errors/'.$hash.'" target="_blank" rel="noopener">' . __( 'Directions on how to resolve this issue', 'instagram-feed' ) . '</a>';
297
+
298
+ if ( isset( $response['response'] ) && isset( $response['response']->errors ) ) {
299
+ $num = count( $response['response']->errors );
300
+ $i = 1;
301
+ foreach ( $response['response']->errors as $key => $item ) {
302
+ $error_message_return['admin_only'] .= ' '.$key . ' - ' . $item[0];
303
+ if ( $i < $num ) {
304
+ $error_message_return['admin_only'] .= ',';
305
+ }
306
+ $num++;
307
+ }
308
+ }
309
+
310
+ return $error_message_return;
311
+ }
312
+ $hash = '#' . (int)$response['error']['code'];
313
+ $link = admin_url( '?page=sb-instagram-feed' );
314
+
315
+ if ( isset( $response['error']['message'] ) ) {
316
+ if ( (int)$response['error']['code'] === 100 ) {
317
+ $error_message_return['error_message'] = __( 'Error: Access Token is not valid or has expired.', 'instagram-feed' ) . ' ' . __( 'Feed will not update.', 'instagram-feed' );
318
+ $error_message_return['admin_only'] = sprintf( __( 'API error %s:', 'instagram-feed' ), $response['error']['code'] ) . ' ' . $response['error']['message'];
319
+ $error_message_return['frontend_directions'] = '<a href="https://smashballoon.com/instagram-feed/docs/errors/' . $hash . '" target="_blank" rel="noopener">' . __( 'Directions on how to resolve this issue', 'instagram-feed' ) . '</a>';
320
+ } elseif ( (int)$response['error']['code'] === 18 ) {
321
+ $error_message_return['error_message'] = __( 'Error: Hashtag limit of 30 unique hashtags per week has been reached.', 'instagram-feed' );
322
+ $error_message_return['admin_only'] = __( 'If you need to display more than 30 hashtag feeds on your site, consider connecting an additional business account from a separate Instagram Identity and Facebook page. Connecting an additional Instagram business account from the same Facebook page will not raise the limit.', 'instagram-feed' );
323
+ $error_message_return['frontend_directions'] = '<a href="https://smashballoon.com/instagram-feed/docs/errors/' . $hash . '" target="_blank" rel="noopener">' . __( 'Directions on how to resolve this issue', 'instagram-feed' ) . '</a>';
324
+ } elseif ( (int)$response['error']['code'] === 10 ) {
325
+ $error_message_return['error_message'] = sprintf( __( 'Error: Connected account for the user %s does not have permission to use this feed type.', 'instagram-feed' ), $connected_account['username'] );
326
+ $error_message_return['admin_only'] = __( 'Try using the big blue button on the "Configure" tab to reconnect the account and update its permissions.', 'instagram-feed' );
327
+ $error_message_return['frontend_directions'] = '<a href="https://smashballoon.com/instagram-feed/docs/errors/' . $hash . '" target="_blank" rel="noopener">' . __( 'Directions on how to resolve this issue', 'instagram-feed' ) . '</a>';
328
+ } elseif ( (int)$response['error']['code'] === 24 ) {
329
+ $error_message_return['error_message'] = __( 'Error: Cannot retrieve posts for this hashtag.', 'instagram-feed' );
330
+ $error_message_return['admin_only'] = $response['error']['error_user_msg'];
331
+ $error_message_return['frontend_directions'] = '<a href="https://smashballoon.com/instagram-feed/docs/errors/" target="_blank" rel="noopener">' . __( 'Directions on how to resolve this issue', 'instagram-feed' ) . '</a>';
332
+ } else {
333
+ $error_message_return['error_message'] = __( 'There has been a problem with your Instagram Feed.', 'instagram-feed' );
334
+ $error_message_return['admin_only'] = sprintf( __( 'API error %s:', 'instagram-feed' ), $response['error']['code'] ) . ' ' . $response['error']['message'];
335
+ $error_message_return['frontend_directions'] = '<a href="https://smashballoon.com/instagram-feed/docs/errors/' . $hash . '" target="_blank" rel="noopener">' . __( 'Directions on how to resolve this issue', 'instagram-feed' ) . '</a>';
336
+ }
337
+ } else {
338
+ $error_message_return['error_message'] = __( 'An unknown error has occurred.', 'instagram-feed' );
339
+ $error_message_return['admin_only'] = json_encode( $response );
340
+ }
341
+ return $error_message_return;
342
+ }
343
+
344
+ /**
345
+ * Display errors are saved with the feed cache so they will still be displayed
346
+ * on the frontend
347
+ *
348
+ * @param string $type
349
+ * @param array $error
350
+ *
351
+ * @since 2.7/5.10
352
+ */
353
+ public function maybe_set_display_error( $type, $error ) {
354
+ if ( $type === 'connection' ) {
355
+ if ( empty( $this->display_error['connection'] ) ) {
356
+ $this->display_error['connection'] = $error;
357
+ }
358
+ } elseif ( $type === 'configuration' ) {
359
+ if ( empty( $this->display_error['configuration'] ) ) {
360
+ $this->display_error['configuration'] = $error;
361
+ }
362
+ } elseif ( $type === 'hashtag' ) {
363
+ $this->display_error['hashtag'][] = $error;
364
+ } elseif ( $type === 'hashtag_limit' ) {
365
+ if ( empty( $this->display_error['connection'] ) ) {
366
+ $this->display_error['hashtag_limit'] = $error;
367
+ }
368
+ }
369
+
370
+ }
371
+
372
+ /**
373
+ * @param string $type
374
+ *
375
+ * @since 2.7/5.10
376
  */
377
+ public function maybe_remove_display_error( $type ) {
378
+ if ( isset( $this->display_error[ $type ] ) ) {
379
+ unset( $this->display_error[ $type ] );
380
+ }
381
  }
382
 
383
  /**
458
  *
459
  * @since 2.0/4.0
460
  */
461
+ public function image_resizing_disabled( $data = false ) {
462
+ $options = sbi_get_database_settings();
463
+ $disable_resizing = isset( $options['sb_instagram_disable_resize'] ) ? $options['sb_instagram_disable_resize'] === 'on' || $options['sb_instagram_disable_resize'] === true : false;
464
+ $disable_resizing = apply_filters( 'sbi_image_resizing_disabled', $disable_resizing, $data );
465
 
466
  if ( ! $disable_resizing ) {
467
  $disable_resizing = isset( $this->resizing_tables_exist ) ? ! $this->resizing_tables_exist : ! $this->does_resizing_tables_exist();
479
  * @since 2.0/5.0
480
  */
481
  public function does_resizing_tables_exist() {
482
+ if ( $this->resizing_tables_exist ) {
483
+ return true;
484
+ }
485
  global $wpdb;
486
 
487
  $table_name = esc_sql( $wpdb->prefix . SBI_INSTAGRAM_POSTS_TYPE );
526
  $connected_accounts = isset( $options['connected_accounts'] ) ? $options['connected_accounts'] : array();
527
 
528
  foreach ( $connected_accounts as $account_id => $data ) {
 
529
  if ( isset( $data['local_avatar'] ) ) {
530
  unset( $connected_accounts[ $account_id ]['local_avatar'] );
531
  }
 
532
  }
533
 
534
  $options['connected_accounts'] = $connected_accounts;
563
  if ( $created ) {
564
  $this->remove_error( 'upload_dir' );
565
  } else {
566
+ $this->add_error( 'upload_dir', __( 'There was an error creating the folder for storing resized images.', 'instagram-feed' ) . ' ' . $upload_dir );
567
  }
568
  } else {
569
  $this->remove_error( 'upload_dir' );
572
  sbi_create_database_table();
573
  }
574
 
575
+
576
+ /**
577
+ * Whether or not the one time request to the "top posts" endpoint for the hashtag
578
+ * was made
579
+ *
580
+ * @param string $hashtag
581
+ *
582
+ * @return bool
583
+ */
584
  public static function top_post_request_already_made( $hashtag ) {
585
  $list_of_top_hashtags = get_option( 'sbi_top_api_calls', array() );
586
 
587
  return in_array( $hashtag, $list_of_top_hashtags, true );
588
  }
589
 
590
+ /**
591
+ * @param $hashtag
592
+ */
593
  public static function maybe_update_list_of_top_hashtags( $hashtag ) {
594
  $list_of_top_hashtags = get_option( 'sbi_top_api_calls', array() );
595
 
610
  }
611
 
612
  /**
613
+ * @param string $type
614
+ * @param mixed/array/bool $connected_account
615
  *
616
  * @since 2.0/4.0
617
  */
618
+ public function remove_error( $type, $connected_account = false ) {
619
+ $update = false;
620
 
621
+ if ( ! empty( $this->errors[ $type ] ) ) {
622
+ $this->errors[ $type ] = array();
623
+ $this->add_action_log( 'Cleared ' . $type .' error.' );
624
+ $update = true;
625
+ }
626
+
627
+ if ( ! empty( $connected_account ) ) {
628
+ if ( $this->remove_connected_account_error( $connected_account, $type, false ) ) {
629
+ $this->add_action_log( 'Cleared connected account error ' . $connected_account['username'] . '.' );
630
+
631
+ }
632
+
633
+ if ( $type === 'connection' ) {
634
+ if ( $this->remove_connected_account_error( $connected_account, 'api', false ) ) {
635
+ $this->add_action_log( 'Cleared connected account error ' . $connected_account['username'] . '.' );
636
+ }
637
+ }
638
+
639
+ $update = true;
640
+ }
641
+
642
+ if ( $update ) {
643
+ update_option( 'sb_instagram_errors', $this->errors, false );
644
+ }
645
  }
646
 
647
  /**
648
+ * @param array $clearing_account
649
+ * @param string $clearing_error_type
650
+ * @param bool $update
651
  *
652
+ * @return bool
653
+ *
654
+ * @since 2.7/5.10
655
  */
656
+ public function remove_connected_account_error( $clearing_account, $clearing_error_type = 'all', $update = true ) {
657
+ $cleared = false;
658
+ if ( isset( $this->errors['accounts'] ) ) {
659
+ if ( ! isset( $clearing_account['user_id'] ) ) {
660
+ return $cleared;
661
+ }
662
+ $clearing_account_id = $clearing_account['user_id'];
663
 
664
+ foreach ( $this->errors['accounts'] as $account_id => $error_types ) {
 
665
 
666
+ foreach ( $error_types as $error_type => $details ) {
667
+ if ( (string)$account_id === (string)$clearing_account_id ) {
668
+ if ( $error_type === $clearing_error_type || $clearing_error_type === 'all' ) {
669
+ unset( $this->errors['accounts'][ $account_id ][ $error_type ] );
670
+ $cleared = true;
671
+ }
672
+ } else {
673
+ if ( isset( $details['username'] ) ) {
674
+ if ( $details['username'] === $clearing_account['username'] ) {
675
+ if ( $error_type === $clearing_error_type || $clearing_error_type === 'all' ) {
676
+ unset( $this->errors['accounts'][ $account_id ][ $error_type ] );
677
+ $cleared = true;
678
+ }
679
+ }
680
+ }
681
+ if ( isset( $this->errors['accounts'][ $account_id ] ) && isset( $details['access_token'] ) ) {
682
+ if ( $details['access_token'] === $clearing_account['access_token'] ) {
683
+ if ( $error_type === $clearing_error_type || $clearing_error_type === 'all' ) {
684
+ unset( $this->errors['accounts'][ $account_id ][ $error_type ] );
685
+ $cleared = true;
686
+ }
687
+ }
688
+ }
689
+ }
690
+ }
691
+
692
+ if ( empty( $this->errors['accounts'][ $account_id ] ) ) {
693
+ unset( $this->errors['accounts'][ $account_id ] );
694
  }
695
+
696
  }
697
 
698
+ if ( $update ) {
699
+ update_option( 'sb_instagram_errors', $this->errors, false );
700
+ }
701
  }
702
+
703
+ return $cleared;
704
  }
705
 
706
+ /**
707
+ *
708
+ * @since 2.7/5.10
709
+ */
710
  public function remove_all_errors() {
711
+ delete_option( 'sb_instagram_errors' );
712
+
713
+ sb_instagram_cron_clear_cache();
714
+ }
715
+
716
+ /**
717
+ * When an account is used to make a successful connection
718
+ *
719
+ * @since 2.7/5.10
720
+ */
721
+ public function reset_api_errors() {
722
+ $this->errors['connection'] = array();
723
+ $this->errors['accounts'] = array();
724
+
725
  update_option( 'sb_instagram_errors', $this->errors, false );
726
  sb_instagram_cron_clear_cache();
727
  }
728
 
729
+ /**
730
+ * @deprecated
731
+ */
732
  public function update_error_page( $id ) {
733
  if ( $id !== 0 ) {
734
  update_option( 'sb_instagram_error_page', $id, false );
735
  }
736
  }
737
 
738
+ /**
739
+ * @return bool
740
+ *
741
+ * @since 2.7/5.10
742
+ */
743
  public function get_error_page() {
744
+ if ( isset( $this->errors['connection']['post_id'] ) ) {
745
+ return $this->errors['connection']['post_id'];
746
+ }
747
+ return false;
748
  }
749
 
750
  /**
751
+ * @return array
 
752
  *
753
  * @since 2.0/5.0
754
  */
755
+ public function get_frontend_errors( $instagram_feed = false ) {
756
+ if ( $instagram_feed ) {
757
+ $cached_errors = $instagram_feed->get_cached_feed_error();
758
+ if ( ! empty( $cached_errors ) ) {
759
+ return $cached_errors;
760
+ }
761
+ }
762
+
763
+ $error_messages = array();
764
+ if ( ! empty( $this->display_error['connection']['error_message'] ) ) {
765
+ $error_messages[] = $this->display_error['connection']['error_message'];
766
+ }
767
+ if ( ! empty( $this->display_error['configuration'] ) ) {
768
+ $error_messages[] = $this->display_error['configuration'];
769
+ }
770
+ if ( ! empty( $this->display_error['hashtag'][0] ) ) {
771
+ $error_24 = array();
772
+ $error_24_message = array();
773
+ foreach ( $this->display_error['hashtag'] as $hashtag_error ) {
774
+ if ( $hashtag_error['error_id'] === 24 ) {
775
+ if ( ! in_array( $hashtag_error['hashtag'], $error_24, true ) ) {
776
+ $error_24[] = $hashtag_error['hashtag'];
777
+ }
778
+ if ( empty( $error_24_message ) ) {
779
+ $error_24_message = $hashtag_error['error_message'];
780
+ $error_24_message['admin_only'] = str_replace( $hashtag_error['hashtag'], '###', $error_24_message['admin_only'] );
781
+ }
782
+ } else {
783
+ $error_messages[] = $hashtag_error['error_message'];
784
+ }
785
+ }
786
+ if ( ! empty( $error_24_message ) ) {
787
+ $hashtag_string = count( $error_24 ) > 1 ? implode( '", "', $error_24 ) : $error_24[0];
788
+ $error_24_message['admin_only'] = str_replace( '###', $hashtag_string, $error_24_message['admin_only'] );
789
+ $error_messages[] = $error_24_message;
790
+ }
791
 
 
 
 
792
  }
793
+ if ( ! empty( $this->display_error['hashtag_limit'] ) ) {
794
+ $response = array(
795
+ 'error' => $this->display_error['hashtag_limit']['error']
796
+ );
797
+
798
+ $error_messages[] = $this->generate_error_message( $response );
799
+ }
800
+
801
+ return $error_messages;
802
  }
803
 
804
  /**
805
+ * @param $account
806
  *
807
+ * @return bool
808
+ *
809
+ * @since 2.7/5.10
810
  */
811
+ public function account_over_hashtag_limit( $account ) {
812
+ if ( ! isset( $this->errors['accounts'][ $account['user_id'] ] ) ) {
813
+ return false;
814
  }
815
+ if ( isset( $this->errors['accounts'][ $account['user_id'] ]['hashtag_limit'] ) ) {
816
+ if ( $this->errors['accounts'][ $account['user_id'] ]['hashtag_limit']['clear_time'] < time() ) {
817
+ $this->remove_connected_account_error( $account, 'hashtag_limit', true );
818
 
819
+ return false;
820
+ } else {
821
+ $this->maybe_set_display_error( 'hashtag_limit', $this->errors['accounts'][ $account['user_id'] ]['hashtag_limit'] );
822
+ return true;
823
+ }
824
+ }
825
+
826
+ return false;
827
  }
828
 
829
+ /**
830
+ * @param $connected_account
831
+ *
832
+ * @return bool
833
+ *
834
+ * @since 2.7/5.10
835
+ */
836
+ public function connected_account_has_error( $connected_account ) {
837
+ if ( ! isset( $connected_account['user_id'] ) ) {
838
+ return false;
839
+ }
840
+ if ( empty( $this->errors['accounts'] ) ) {
841
+ return false;
842
+ }
 
 
 
 
 
 
 
 
 
843
 
844
+ $account_id = $connected_account['user_id'];
 
 
 
 
 
845
 
846
+ if ( ! empty( $this->errors['accounts'][ $account_id ] ) ) {
847
+ foreach ( $this->errors['accounts'][ $account_id ] as $error_key => $error_info ) {
848
+ if ( strpos( $error_key, 'hashtag' ) === false ) {
849
+ return true;
 
850
  }
851
  }
 
 
852
  }
853
+ return false;
854
+ }
855
 
856
+ /**
857
+ * Whether or not the hashtag is unvailable in the API for some reason
858
+ *
859
+ * @param $hashtag
860
+ *
861
+ * @return bool
862
+ *
863
+ * @since 2.7/5.10
864
+ */
865
+ public function hashtag_has_error( $hashtag ) {
866
+ if ( ! isset( $this->errors['hashtag'][0] ) ) {
867
+ return false;
868
+ }
869
+
870
+ $to_save = array();
871
+ $changed = false;
872
+ $return = false;
873
+
874
+ foreach ( $this->errors['hashtag'] as $hashtag_error ) {
875
+ if ( ! empty( $hashtag_error['hashtag'] )
876
+ && strtolower( $hashtag_error['hashtag'] ) === strtolower( $hashtag ) ) {
877
+ if ( ! empty( $hashtag_error['clear_time'] ) ) {
878
+
879
+ if ( $hashtag_error['clear_time'] < time() ) {
880
+ $changed = true;
881
+ $return = false;
882
+ // clear the error, return false
883
+ } else {
884
+ $to_save[] = $hashtag_error;
885
+ $this->maybe_set_display_error( 'hashtag', $hashtag_error );
886
+ $return = true;
887
+ }
888
  }
889
+ } else {
890
+ if ( ! empty( $hashtag_error['clear_time'] ) ) {
891
+ if ( $hashtag_error['clear_time'] < time() ) {
892
+ $changed = true;
893
+ } else {
894
+ $to_save[] = $hashtag_error;
895
+ }
896
  } else {
897
+ $to_save[] = $hashtag_error;
898
  }
899
  }
900
+
901
+ }
902
+
903
+ if ( $changed ) {
904
+ $this->errors['hashtag'] = $to_save;
905
+ update_option( 'sb_instagram_errors', $this->errors, false );
906
  }
907
 
908
+ return $return;
909
+ }
910
 
911
+ /**
912
+ * Only some errors should cause the user to be notified using email and site health
913
+ *
914
+ * @return string
915
+ */
916
+ public function get_critical_errors() {
917
+ if ( ! $this->are_critical_errors() ) {
918
+ return '';
919
+ }
920
+ if ( isset( $this->errors['connection']['critical'] ) ) {
921
+ $errors = $this->get_errors();
922
+ $error_message = '';
923
+
924
+ $error_message_array = $errors['connection']['error_message'];
925
+ $error_message .= '<strong>' . $error_message_array['error_message'] . '</strong><br>';
926
+ $error_message .= $error_message_array['admin_only'] . '<br><br>';
927
+ if ( ! empty( $error_message_array['backend_directions'] ) ) {
928
+ $error_message .= $error_message_array['backend_directions'];
929
  } else {
930
+ $hash = isset( $errors['connection']['error_id'] ) ? '#' . (int)$errors['connection']['error_id'] : '';
931
+ $error_message .= '<p class="sbi-error-directions"><a href="https://smashballoon.com/instagram-feed/docs/errors/'.$hash.'" target="_blank" rel="noopener">' . __( 'Directions on how to resolve this issue', 'instagram-feed' ) . '</a></p>';
932
+ }
933
+ } else {
934
+ $options = sbi_get_database_settings();
935
+ $connected_accounts = isset( $options['connected_accounts'] ) ? $options['connected_accounts'] : array();
936
+ foreach ( $connected_accounts as $connected_account ) {
937
+ if ( isset( $connected_account['private'] )
938
+ && sbi_private_account_near_expiration( $connected_account ) ) {
939
+ $link_1 = '<a href="https://help.instagram.com/116024195217477/In">';
940
+ $link_2 = '</a>';
941
+ $error_message_array = array(
942
+ 'error_message' => __( 'Error: Private Instagram Account.', 'instagram-feed' ),
943
+ 'admin_only' => sprintf( __( 'It looks like your Instagram account is private. Instagram requires private accounts to be reauthenticated every 60 days. Refresh your account to allow it to continue updating, or %smake your Instagram account public%s.', 'instagram-feed' ), $link_1, $link_2 ),
944
+ 'frontend_directions' => '<a href="https://smashballoon.com/instagram-feed/docs/errors/#10">' . __( 'Click here to troubleshoot', 'instagram-feed' ) . '</a>',
945
+ 'backend_directions' => ''
946
+ );
947
+ }
948
+
949
+ if ( isset( $this->errors['accounts'][ $connected_account['user_id' ] ]['api'] ) ) {
950
+ if ( isset( $this->errors['accounts'][ $connected_account['user_id'] ]['api']['error'] ) ) {
951
+ if ( $this->is_critical_error( $this->errors['accounts'][ $connected_account['user_id'] ]['api'] ) ) {
952
+ $error_message_array = $this->generate_error_message( $this->errors['accounts'][ $connected_account['user_id'] ]['api'], $connected_account );
953
+ }
954
+ }
955
+ }
956
+
957
+ if ( ! isset( $error_message ) && isset( $error_message_array ) ) {
958
+ $error_message = $error_message_array['admin_only'] . '<br><br>';
959
+ if ( ! empty( $error_message_array['backend_directions'] ) ) {
960
+ $error_message .= $error_message_array['backend_directions'];
961
+ } else {
962
+ $error_message .= '<p class="sbi-error-directions"><a href="https://smashballoon.com/instagram-feed/docs/errors/" target="_blank" rel="noopener">' . __( 'Directions on how to resolve this issue', 'instagram-feed' ) . '</a></p>';
963
+ }
964
+ }
965
+
966
  }
967
  }
968
+ if ( isset( $error_message ) ) {
969
+ $error_message = str_replace( 'Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api', '', $error_message );
970
+
971
+ } else {
972
+ $error_message = '';
973
+ }
974
 
975
  // remove link to FB docs
 
976
 
977
+ return $error_message;
978
  }
979
 
980
  /**
 
 
981
  * @since 2.0/5.0
982
  */
983
  public function reset_frontend_errors() {
984
+ $this->display_error = array();
985
  }
986
 
987
+ /**
988
+ * Remove all API request delays, triggered after saving settings
989
+ *
990
+ * @since 2.7/5.10
991
+ */
992
+ public function clear_api_request_delays() {
993
+ if ( empty( $this->errors['accounts'] )
994
+ && empty( $this->errors['hashtag'] ) ) {
995
+ return;
996
+ }
997
 
 
 
998
 
999
+ $changed = false;
1000
+ foreach( $this->errors['accounts'] as $account_id => $account_error ) {
1001
+ if ( ! empty( $account_error['api']['clear_time'] ) ) {
1002
+ $this->errors['accounts'][ $account_id ]['api']['clear_time'] = 0;
1003
  }
1004
+ $changed = true;
1005
  }
 
1006
 
1007
+ foreach ( $this->errors['hashtag'] as $key => $hashtag_error ) {
1008
+ if ( ! empty( $hashtag_error['hashtag'] ) ) {
1009
+ if ( ! empty( $hashtag_error['clear_time'] ) ) {
1010
+ $this->errors['hashtag'][ $key ]['clear_time'] = 0;
1011
+ $changed = true;
1012
+ }
1013
+ }
1014
+ }
1015
+
1016
+ if ( $changed ) {
1017
+ update_option( 'sb_instagram_errors', $this->errors, false );
1018
  }
1019
  }
1020
 
1021
  /**
1022
  * @since 2.0/5.1.2
1023
  */
1024
+ public function are_current_api_request_delays( $connected_account ) {
1025
+ if ( empty( $this->errors['accounts'] ) ) {
1026
+ return false;
 
 
 
 
 
 
 
1027
  }
1028
+ $account_id = $connected_account['user_id'];
1029
 
1030
+ $is_delay = false;
1031
+ if ( isset( $this->errors['accounts'][ $account_id ]['api'] ) ) {
1032
+ if ( ! empty( $this->errors['accounts'][ $account_id ]['api']['clear_time'] ) ) {
1033
 
1034
+ if ( $this->errors['accounts'][ $account_id ]['api']['clear_time'] < time() ) {
1035
+ $is_delay = false;
1036
+ return apply_filters( 'sbi_is_api_delay', $is_delay );
1037
+ } else {
1038
+ $is_delay = true;
1039
+ return apply_filters( 'sbi_is_api_delay', $is_delay );
1040
+ }
1041
+ }
1042
+ }
1043
 
1044
+ return apply_filters( 'sbi_is_api_delay', $is_delay );
1045
  }
1046
 
1047
+ /**
1048
+ * Whether or not there is at least one critical error
1049
+ *
1050
+ * @return bool
1051
+ */
1052
  public function are_critical_errors() {
1053
+ if ( isset( $this->errors['connection']['critical'] ) ) {
1054
+ return true;
1055
+ } else {
1056
+ $options = sbi_get_database_settings();
1057
+ $connected_accounts = isset( $options['connected_accounts'] ) ? $options['connected_accounts'] : array();
1058
+ foreach ( $connected_accounts as $connected_account ) {
1059
+ if ( isset( $connected_account['private'] )
1060
+ && sbi_private_account_near_expiration( $connected_account ) ) {
1061
+ return true;
1062
+ }
1063
 
1064
+ if ( isset( $this->errors['accounts'][ $connected_account['user_id' ] ]['api'] ) ) {
1065
+ if ( isset( $this->errors['accounts'][ $connected_account['user_id'] ]['api']['error'] ) ) {
1066
+ return $this->is_critical_error( $this->errors['accounts'][ $connected_account['user_id'] ]['api'] );
1067
+ }
 
 
 
 
 
 
 
 
1068
  }
 
 
 
 
1069
  }
1070
  }
1071
 
1072
+ return false;
1073
  }
1074
  }
inc/class-sb-instagram-settings.php CHANGED
@@ -60,6 +60,9 @@ class SB_Instagram_Settings {
60
  * @param array $db settings from the wp_options table
61
  */
62
  public function __construct( $atts, $db ) {
 
 
 
63
  $this->atts = $atts;
64
  $this->db = $db;
65
 
@@ -143,11 +146,11 @@ class SB_Instagram_Settings {
143
  $this->settings['sb_instagram_cache_time'] = isset( $this->db['sb_instagram_cache_time'] ) ? $this->db['sb_instagram_cache_time'] : 1;
144
  $this->settings['sb_instagram_cache_time_unit'] = isset( $this->db['sb_instagram_cache_time_unit'] ) ? $this->db['sb_instagram_cache_time_unit'] : 'hours';
145
 
146
- global $sb_instagram_posts_manager;
147
 
148
  if ( $sb_instagram_posts_manager->are_current_api_request_delays() ) {
149
  $this->settings['alwaysUseBackup'] = true;
150
- }
151
 
152
  $this->settings['isgutenberg'] = SB_Instagram_Blocks::is_gb_editor();
153
  if ( $this->settings['isgutenberg'] ) {
@@ -289,7 +292,7 @@ class SB_Instagram_Settings {
289
  if ( isset( $feed_type_and_terms['users'] ) ) {
290
  foreach ( $feed_type_and_terms['users'] as $term_and_params ) {
291
  $user = $term_and_params['term'];
292
- $connected_account = $this->connected_accounts_in_feed[ $user ];
293
  if ( isset( $connected_account['type'] ) && $connected_account['type'] === 'business' ) {
294
  $sbi_transient_name .= $connected_account['username'];
295
  } else {
@@ -325,363 +328,176 @@ class SB_Instagram_Settings {
325
  }
326
  }
327
 
328
- /**
329
- * Based on the settings related to retrieving post data from the API,
330
- * this setting is used to make sure all endpoints needed for the feed are
331
- * connected and stored for easily looping through when adding posts
332
- *
333
- * Overwritten in the Pro version.
334
- *
335
- * @since 2.0/5.0
336
- */
337
- public function set_feed_type_and_terms() {
338
- global $sb_instagram_posts_manager;
339
-
340
- $connected_accounts_in_feed = array();
341
- $feed_type_and_terms = array(
342
- 'users' => array()
343
- );
344
- $usernames_included = array();
345
- $is_after_deprecation_deadline = sbi_is_after_deprecation_deadline();
346
- $is_using_access_token_in_shortcode = ! empty( $this->atts['accesstoken'] ) && strpos( $this->atts['accesstoken'], '.' ) !== false;
347
- $users_connected_to_old_api_only = array();
348
- $settings_link = '<a href="'.get_admin_url().'?page=sb-instagram-feed" target="_blank">' . __( 'plugin Settings page', 'instagram-feed' ) . '</a>';
349
-
350
- // if using an access token in the shortcode and after the deadline, try to use a connected account by collecting the user IDs
351
- if ( $is_after_deprecation_deadline && $is_using_access_token_in_shortcode ) {
352
- $error = '<p><b>' . __( 'Error: Cannot add access token directly to the shortcode.', 'instagram-feed' ) . '</b><br>' . sprintf( __( 'Due to recent Instagram platform changes, it\'s no longer possible to create a feed by adding the access token to the shortcode. Remove the access token from the shortcode and connect an account on the %s instead.', 'instagram-feed' ), $settings_link );
353
-
354
- $sb_instagram_posts_manager->add_frontend_error( 'deprecation_warning', $error );
355
 
356
- $this->settings['id'] = array();
357
- $access_tokens = explode( ',', str_replace( ' ', '', $this->atts['accesstoken'] ) );
 
358
 
359
- foreach ( $access_tokens as $access_token ) {
360
- $split_token = explode( '.', $access_token );
361
- $this->settings['id'][] = $split_token[0];
362
- }
363
- }
364
 
365
- if ( empty( $this->settings['id'] )
366
- && empty( $this->settings['user'] )
367
- && ! empty ( $this->connected_accounts ) ) {
368
  $set = false;
369
  foreach ( $this->connected_accounts as $connected_account ) {
370
  if ( ! $set ) {
371
  $set = true;
372
  $this->settings['user'] = $connected_account['username'];
373
- }
374
- }
375
- }
376
-
377
- if ( ! $is_after_deprecation_deadline && $is_using_access_token_in_shortcode ) {
378
- $error = '<p><b>' . __( 'Warning: Cannot add access token directly to the shortcode.', 'instagram-feed' ) . '</b><br>' . sprintf( __( 'Due to upcoming Instagram platform changes on June 1, 2020, it will no longer be possible for feeds to use access tokens directly in the shortcode. Remove the access token from the shortcode and connect an account on the %s instead.', 'instagram-feed' ), $settings_link );
379
-
380
- $sb_instagram_posts_manager->add_frontend_error( 'deprecation_warning', $error );
381
- $access_tokens = explode( ',', str_replace( ' ', '', $this->atts['accesstoken'] ) );
382
-
383
- foreach ( $access_tokens as $access_token ) {
384
- $split_token = explode( '.', $access_token );
385
- $connected_accounts_in_feed[ $split_token[0] ] = array(
386
- 'access_token' => $access_token,
387
- 'user_id' => $split_token[0]
388
- );
389
- $feed_type_and_terms['users'][] = array(
390
- 'term' => $split_token[0],
391
- 'params' => array()
392
- );
393
- }
394
-
395
- } elseif ( ! empty( $this->settings['user'] ) ) {
396
- $user_array = is_array( $this->settings['user'] ) ? $this->settings['user'] : explode( ',', str_replace( ' ', '', $this->settings['user'] ) );
397
- foreach ( $user_array as $user ) {
398
- $user_found = false;
399
- $user_for_deprecated_personal_account_only_found = false;
400
- $term_for_this_user = array();
401
- $username_to_match = $user;
402
-
403
- if ( isset( $this->connected_accounts[ $user ] ) ) {
404
- if ( ! in_array( $this->connected_accounts[ $user ]['username'], $usernames_included, true ) ) {
405
- $term_for_this_user = array(
406
- 'term' => $this->connected_accounts[ $user ]['user_id'],
407
- 'params' => array()
408
- );
409
- $connected_accounts_in_feed[ $this->connected_accounts[ $user ]['user_id'] ] = $this->connected_accounts[ $user ];
410
- $usernames_included[] = $this->connected_accounts[ $user ]['username'];
411
- $username_to_match = $this->connected_accounts[ $user ]['username'];
412
- $user_found = true;
413
- if ( ! isset( $this->connected_accounts[ $user ]['type'] ) || $this->connected_accounts[ $user ]['type'] === 'personal' ) {
414
- $user_for_deprecated_personal_account_only_found = true;
415
- }
416
-
417
- if ( isset( $this->connected_accounts[ $user ]['private'] ) && sbi_private_account_near_expiration( $this->connected_accounts[ $user ] ) ) {
418
- $link_1 = '<a href="https://help.instagram.com/116024195217477/In">';
419
- $link_2 = '</a>';
420
- $sb_instagram_posts_manager->add_error( 'expiration_' . $this->connected_accounts[ $user ]['user_id'], array( 'Private Instagram Account Needs Reauthentication', sprintf( __( 'It looks like your Instagram account is private. Instagram requires private accounts to be reauthenticated every 60 days. Refresh your account to allow it to continue updating, or %smake your Instagram account public%s.', 'instagram-feed' ), $link_1, $link_2 ), 10 ) );
421
-
422
- $error = '<p><b>' . __( 'Error: Private Instagram Account.', 'instagram-feed' ) . '</b>';
423
- $cap = current_user_can( 'manage_instagram_feed_options' ) ? 'manage_instagram_feed_options' : 'manage_options';
424
- $cap = apply_filters( 'sbi_settings_pages_capability', $cap );
425
- if ( current_user_can( $cap ) ) {
426
- $error_link = '<p><a href="https://smashballoon.com/instagram-feed/docs/errors/#10">' . __( 'Click here to troubleshoot', 'instagram-feed' ) . '</a></p>';
427
-
428
- } else {
429
- $error_link = '';
430
- $link_1 = '';
431
- $link_2 = '';
432
- }
433
- $error .= '<p>' . sprintf( __( 'It looks like your Instagram account is private. Instagram requires private accounts to be reauthenticated every 60 days. Refresh your account to allow it to continue updating, or %smake your Instagram account public%s.', 'instagram-feed' ), $link_1, $link_2 ) . '</p>';
434
-
435
- $error .= $error_link;
436
- $sb_instagram_posts_manager->add_frontend_error( 'noposts', $error );
437
- }
438
  }
 
439
  }
440
-
441
- if ( ! $user_found || $user_for_deprecated_personal_account_only_found ) {
442
-
443
- foreach ( $this->connected_accounts as $connected_account ) {
444
- $account_type = isset( $connected_account['type'] ) ? $connected_account['type'] : 'personal';
445
- if ( strtolower( $username_to_match ) === strtolower( $connected_account['username'] ) ) {
446
-
447
- if ( $user_for_deprecated_personal_account_only_found || ! in_array( $connected_account['username'], $usernames_included, true ) ) {
448
- if ( $account_type !== 'personal' ) {
449
-
450
- $term_for_this_user = array(
451
- 'term' => $user,
452
- 'params' => array()
453
- );
454
- $connected_accounts_in_feed[ $user ] = $connected_account;
455
- $user_for_deprecated_personal_account_only_found = false;
456
- if ( isset( $this->connected_accounts[ $connected_account['user_id'] ]['private'] ) && sbi_private_account_near_expiration( $this->connected_accounts[ $connected_account['user_id'] ] ) ) {
457
- $link_1 = '<a href="https://help.instagram.com/116024195217477/In">';
458
- $link_2 = '</a>';
459
- $sb_instagram_posts_manager->add_error( 'expiration_' . $this->connected_accounts[ $connected_account['user_id'] ]['user_id'], array( 'Private Instagram Account Needs Reauthentication', sprintf( __( 'It looks like your Instagram account is private. Instagram requires private accounts to be reauthenticated every 60 days. Refresh your account to allow it to continue updating, or %smake your Instagram account public%s.', 'instagram-feed' ), $link_1, $link_2 ), 10 ) );
460
-
461
- $error = '<p><b>' . __( 'Error: Private Instagram Account.', 'instagram-feed' ) . '</b>';
462
- $cap = current_user_can( 'manage_instagram_feed_options' ) ? 'manage_instagram_feed_options' : 'manage_options';
463
- $cap = apply_filters( 'sbi_settings_pages_capability', $cap );
464
- if ( current_user_can( $cap ) ) {
465
- $error_link = '<p><a href="https://smashballoon.com/instagram-feed/docs/errors/#10">' . __( 'Click here to troubleshoot', 'instagram-feed' ) . '</a></p>';
466
-
467
- } else {
468
- $error_link = '';
469
- $link_1 = '';
470
- $link_2 = '';
471
- }
472
- $error .= '<p>' . sprintf( __( 'It looks like your Instagram account is private. Instagram requires private accounts to be reauthenticated every 60 days. Refresh your account to allow it to continue updating, or %smake your Instagram account public%s.', 'instagram-feed' ), $link_1, $link_2 ) . '</p>';
473
-
474
- $error .= $error_link;
475
- $sb_instagram_posts_manager->add_frontend_error( 'noposts', $error );
476
- }
477
- } else {
478
- $term_for_this_user = array(
479
- 'term' => $connected_account['user_id'],
480
- 'params' => array()
481
- );
482
- $connected_accounts_in_feed[ $connected_account['user_id'] ] = $connected_account;
483
- }
484
- $usernames_included[] = $connected_account['username'];
485
- $user_found = true;
486
- }
487
  }
 
 
488
  }
 
 
 
 
 
 
 
489
  }
490
 
491
- if ( ! empty( $term_for_this_user ) ) {
492
- $feed_type_and_terms['users'][] = $term_for_this_user;
493
- }
494
-
495
- if ( ! $user_found ) {
496
- $error = '<p><b>' . sprintf( __( 'Error: There is no connected account for the user %s.', 'instagram-feed' ), $user ) . ' ' . __( 'Feed will not update.', 'instagram-feed' ) . '</b>';
497
 
498
- $sb_instagram_posts_manager->add_frontend_error( 'no_connection_' . $user, $error );
 
 
 
 
 
499
  }
500
 
501
- if ( $user_for_deprecated_personal_account_only_found
502
- && ! in_array( $user, $users_connected_to_old_api_only, true ) ) {
503
- $users_connected_to_old_api_only[] = $connected_accounts_in_feed[ $user ]['username'];
504
- }
505
 
 
 
 
 
 
 
 
506
  }
507
 
508
- } elseif ( ! empty( $this->settings['id'] ) ) {
509
- $user_id_array = is_array( $this->settings['id'] ) ? $this->settings['id'] : explode( ',', str_replace( ' ', '', $this->settings['id'] ) );
510
-
511
- foreach ( $user_id_array as $user ) {
512
- $user_found = false;
513
- $user_for_deprecated_personal_account_only_found = false;
514
- $term_for_this_user = array();
515
- $username_to_match = '';
516
-
517
- if ( isset( $this->connected_accounts[ $user ] ) ) {
518
- if ( ! in_array( $this->connected_accounts[ $user ]['username'], $usernames_included, true ) ) {
519
- $term_for_this_user = array(
520
- 'term' => $this->connected_accounts[ $user ]['user_id'],
521
- 'params' => array()
522
- );
523
- $connected_accounts_in_feed[ $this->connected_accounts[ $user ]['user_id'] ] = $this->connected_accounts[ $user ];
524
- if ( ! in_array( $this->connected_accounts[ $user ]['username'], $usernames_included, true ) ) {
525
- $usernames_included[] = $this->connected_accounts[ $user ]['username'];
526
- }
527
 
528
- if ( isset( $this->connected_accounts[ $user ]['private'] ) && sbi_private_account_near_expiration( $this->connected_accounts[ $user ] ) ) {
529
- $link_1 = '<a href="https://help.instagram.com/116024195217477/In">';
530
- $link_2 = '</a>';
531
- $sb_instagram_posts_manager->add_error( 'expiration_' . $this->connected_accounts[ $user ]['user_id'], array( 'Private Instagram Account Needs Reauthentication', sprintf( __( 'It looks like your Instagram account is private. Instagram requires private accounts to be reauthenticated every 60 days. Refresh your account to allow it to continue updating, or %smake your Instagram account public%s.', 'instagram-feed' ), $link_1, $link_2 ), 10 ) );
532
-
533
- $error = '<p><b>' . __( 'Error: Private Instagram Account.', 'instagram-feed' ) . '</b>';
534
- $cap = current_user_can( 'manage_instagram_feed_options' ) ? 'manage_instagram_feed_options' : 'manage_options';
535
- $cap = apply_filters( 'sbi_settings_pages_capability', $cap );
536
- if ( current_user_can( $cap ) ) {
537
- $error_link = '<p><a href="https://smashballoon.com/instagram-feed/docs/errors/#10">' . __( 'Click here to troubleshoot', 'instagram-feed' ) . '</a></p>';
538
-
539
- } else {
540
- $error_link = '';
541
- $link_1 = '';
542
- $link_2 = '';
543
- }
544
- $error .= '<p>' . sprintf( __( 'It looks like your Instagram account is private. Instagram requires private accounts to be reauthenticated every 60 days. Refresh your account to allow it to continue updating, or %smake your Instagram account public%s.', 'instagram-feed' ), $link_1, $link_2 ) . '</p>';
545
-
546
- $error .= $error_link;
547
- $sb_instagram_posts_manager->add_frontend_error( 'noposts', $error );
548
- }
549
- $username_to_match = $this->connected_accounts[ $user ]['username'];
550
- $user_found = true;
551
- if ( ! isset( $this->connected_accounts[ $user ]['type'] ) || $this->connected_accounts[ $user ]['type'] === 'personal' ) {
552
- $user_for_deprecated_personal_account_only_found = true;
553
- }
554
- }
555
 
556
- }
557
 
558
- if ( ! $user_found || $user_for_deprecated_personal_account_only_found ) {
559
-
560
- foreach ( $this->connected_accounts as $connected_account ) {
561
- $account_type = isset( $connected_account['type'] ) ? $connected_account['type'] : 'personal';
562
- $old_id_matches = ($account_type === 'basic' && isset( $connected_account['old_user_id'] ) && (string)$connected_account['old_user_id'] === (string)$user);
563
- if ( $old_id_matches
564
- || (strtolower( $username_to_match ) === strtolower( $connected_account['username'] )) ) {
565
- if ( $user_for_deprecated_personal_account_only_found || ! in_array( $connected_account['username'], $usernames_included, true ) ) {
566
- if ( $account_type !== 'personal' ) {
567
- $term_for_this_user = array(
568
- 'term' => $user,
569
- 'params' => array()
570
- );
571
- $connected_accounts_in_feed[ $user ] = $connected_account;
572
- $user_for_deprecated_personal_account_only_found = false;
573
- } else {
574
- $term_for_this_user = array(
575
- 'term' => $connected_account['user_id'],
576
- 'params' => array()
577
- );
578
- $connected_accounts_in_feed[ $connected_account['user_id'] ] = $connected_account;
579
-
580
- }
581
- if ( ! in_array( $connected_account['username'], $usernames_included, true ) ) {
582
- $usernames_included[] = $connected_account['username'];
583
- }
584
- $user_found = true;
585
- }
586
- }
587
- }
588
 
589
- }
 
 
 
 
 
 
 
 
 
 
590
 
591
- if ( ! empty( $term_for_this_user ) ) {
592
- $feed_type_and_terms['users'][] = $term_for_this_user;
593
- }
 
 
 
 
 
 
594
 
595
- if ( ! $user_found ) {
596
- $error = '<p><b>' . sprintf( __( 'Error: There is no connected account for the user %s', 'instagram-feed' ), $user ) . ' ' . __( 'Feed will not update.', 'instagram-feed' ) . '</b>';
597
 
598
- $sb_instagram_posts_manager->add_frontend_error( 'no_connection_' . $user, $error );
599
- }
600
 
601
- if ( $user_for_deprecated_personal_account_only_found
602
- && ! in_array( $user, $users_connected_to_old_api_only, true ) ) {
603
- $users_connected_to_old_api_only[] = $connected_accounts_in_feed[ $user ]['username'];
604
- }
605
 
606
- }
 
 
607
 
 
608
  } else {
609
- foreach ( $this->connected_accounts as $connected_account ) {
610
- $account_type = isset( $connected_account['type'] ) ? $connected_account['type'] : 'personal';
611
-
612
- if ( empty( $feed_type_and_terms['users'] ) ) {
613
- if ( $account_type !== 'personal' ) {
614
- $feed_type_and_terms['users'][] = array(
615
- 'term' => $connected_account['username'],
616
- 'params' => array()
617
- );
618
- $connected_accounts_in_feed[ $connected_account['username'] ] = $connected_account;
619
- } elseif ( ! $is_after_deprecation_deadline ) {
620
- $feed_type_and_terms['users'][] = array(
621
- 'term' => $connected_account['user_id'],
622
- 'params' => array()
623
- );
624
- $connected_accounts_in_feed[ $connected_account['user_id'] ] = $connected_account;
625
- if ( isset( $this->connected_accounts[ $connected_account['user_id'] ]['private'] ) && sbi_private_account_near_expiration( $this->connected_accounts[ $connected_account['user_id'] ] ) ) {
626
- $link_1 = '<a href="https://help.instagram.com/116024195217477/In">';
627
- $link_2 = '</a>';
628
- $sb_instagram_posts_manager->add_error( 'expiration_' . $this->connected_accounts[ $connected_account['user_id'] ]['user_id'], array( 'Private Instagram Account Needs Reauthentication', sprintf( __( 'It looks like your Instagram account is private. Instagram requires private accounts to be reauthenticated every 60 days. Refresh your account to allow it to continue updating, or %smake your Instagram account public%s.', 'instagram-feed' ), $link_1, $link_2 ), 10 ) );
629
-
630
- $error = '<p><b>' . __( 'Error: Private Instagram Account.', 'instagram-feed' ) . '</b>';
631
- $cap = current_user_can( 'manage_instagram_feed_options' ) ? 'manage_instagram_feed_options' : 'manage_options';
632
- $cap = apply_filters( 'sbi_settings_pages_capability', $cap );
633
- if ( current_user_can( $cap ) ) {
634
- $error_link = '<p><a href="https://smashballoon.com/instagram-feed/docs/errors/#10">' . __( 'Click here to troubleshoot', 'instagram-feed' ) . '</a></p>';
635
-
636
- } else {
637
- $error_link = '';
638
- $link_1 = '';
639
- $link_2 = '';
640
- }
641
- $error .= '<p>' . sprintf( __( 'It looks like your Instagram account is private. Instagram requires private accounts to be reauthenticated every 60 days. Refresh your account to allow it to continue updating, or %smake your Instagram account public%s.', 'instagram-feed' ), $link_1, $link_2 ) . '</p>';
642
-
643
- $error .= $error_link;
644
- $sb_instagram_posts_manager->add_frontend_error( 'noposts', $error );
645
- }
646
- }
647
- }
648
-
649
  }
 
 
 
 
 
 
 
 
 
 
 
650
  }
651
 
652
- if ( ! empty( $users_connected_to_old_api_only ) ) {
653
- $total = count( $users_connected_to_old_api_only );
654
- if ( $total > 1 ) {
655
- $user_string = '';
656
- $i = 0;
657
 
658
- foreach ( $users_connected_to_old_api_only as $username ) {
659
- if ( ($i + 1) === $total ) {
660
- $user_string .= ' and ' . $username;
661
- } else {
662
- if ( $i !== 0 ) {
663
- $user_string .= ', ' . $username;
664
- } else {
665
- $user_string .= $username;
666
- }
667
- }
668
- $i++;
669
- }
670
- } else {
671
- $user_string = $users_connected_to_old_api_only[0];
672
- }
673
 
674
- if ( $is_after_deprecation_deadline ) {
675
- $error = '<p><b>' . sprintf( __( 'Error: The account for %s needs to be reconnected.', 'instagram-feed' ), '<em>'.$user_string.'</em>' ) . '</b><br>' . __( 'Due to recent Instagram platform changes this Instagram account needs to be reconnected in order to continue updating.', 'instagram-feed' ) . '<a href="'.get_admin_url().'?page=sb-instagram-feed" class="sb_frontend_btn"><i class="fa fa-cog" aria-hidden="true"></i> ' . __( 'Reconnect on plugin Settings page', 'instagram-feed' ) . '</a>';
676
- } else {
677
- $error = '<p><b>' . sprintf( __( 'Warning: The account for %s needs to be reconnected.', 'instagram-feed' ), '<em>'.$user_string.'</em>' ) . '</b><br>' . __( 'Due to Instagram platform changes on June 1, 2020, this Instagram account needs to be reconnected to allow the feed to continue updating.', 'instagram-feed' ) . '<a href="'.get_admin_url().'?page=sb-instagram-feed" class="sb_frontend_btn"><i class="fa fa-cog" aria-hidden="true"></i> ' . __( 'Reconnect on plugin Settings page', 'instagram-feed' ) . '</a>';
678
- }
679
 
680
- $sb_instagram_posts_manager->add_frontend_error( 'deprecation_warning', $error );
681
  }
682
-
683
- $this->connected_accounts_in_feed = $connected_accounts_in_feed;
684
- $this->feed_type_and_terms = $feed_type_and_terms;
685
  }
686
 
687
  /**
60
  * @param array $db settings from the wp_options table
61
  */
62
  public function __construct( $atts, $db ) {
63
+ $this->feed_type_and_terms = array();
64
+ $this->connected_accounts_in_feed = array();
65
+
66
  $this->atts = $atts;
67
  $this->db = $db;
68
 
146
  $this->settings['sb_instagram_cache_time'] = isset( $this->db['sb_instagram_cache_time'] ) ? $this->db['sb_instagram_cache_time'] : 1;
147
  $this->settings['sb_instagram_cache_time_unit'] = isset( $this->db['sb_instagram_cache_time_unit'] ) ? $this->db['sb_instagram_cache_time_unit'] : 'hours';
148
 
149
+ /*global $sb_instagram_posts_manager;
150
 
151
  if ( $sb_instagram_posts_manager->are_current_api_request_delays() ) {
152
  $this->settings['alwaysUseBackup'] = true;
153
+ }*/
154
 
155
  $this->settings['isgutenberg'] = SB_Instagram_Blocks::is_gb_editor();
156
  if ( $this->settings['isgutenberg'] ) {
292
  if ( isset( $feed_type_and_terms['users'] ) ) {
293
  foreach ( $feed_type_and_terms['users'] as $term_and_params ) {
294
  $user = $term_and_params['term'];
295
+ $connected_account = isset( $this->connected_accounts_in_feed[ $user ] ) ? $this->connected_accounts_in_feed[ $user ] : array();
296
  if ( isset( $connected_account['type'] ) && $connected_account['type'] === 'business' ) {
297
  $sbi_transient_name .= $connected_account['username'];
298
  } else {
328
  }
329
  }
330
 
331
+ private function add_connected_accounts_in_feed( $connected_accounts ) {
332
+ foreach ( $connected_accounts as $key => $connected_account ) {
333
+ $this->connected_accounts_in_feed[ $key ] = $connected_account;
334
+ }
335
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
 
337
+ private function add_feed_type_and_terms( $feed_type_and_terms ) {
338
+ $this->feed_type_and_terms = array_merge( $this->feed_type_and_terms, $feed_type_and_terms );
339
+ }
340
 
341
+ private function set_user_feed( $users = false ) {
342
+ global $sb_instagram_posts_manager;
 
 
 
343
 
344
+ if ( ! $users ) {
 
 
345
  $set = false;
346
  foreach ( $this->connected_accounts as $connected_account ) {
347
  if ( ! $set ) {
348
  $set = true;
349
  $this->settings['user'] = $connected_account['username'];
350
+ $this->connected_accounts_in_feed = array( $connected_account['user_id'] => $connected_account );
351
+ $feed_type_and_terms = array(
352
+ 'users'=> array(
353
+ array(
354
+ 'term' => $connected_account['user_id'],
355
+ 'params' => array()
356
+ )
357
+ )
358
+ );
359
+ if ( $sb_instagram_posts_manager->are_current_api_request_delays( $connected_account ) ) {
360
+ $feed_type_and_terms['users'][0]['error'] = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
361
  }
362
+ $this->feed_type_and_terms = $feed_type_and_terms;
363
  }
364
+ }
365
+ return;
366
+ } else {
367
+ $connected_accounts_in_feed = array();
368
+ $feed_type_and_terms = array(
369
+ 'users' => array()
370
+ );
371
+ $usernames_included = array();
372
+ $usernames_not_connected = array();
373
+ foreach ( $users as $user_id_or_name ) {
374
+ $connected_account = SB_Instagram_Connected_Account::lookup( $user_id_or_name );
375
+
376
+ if ( $connected_account ) {
377
+ if ( ! in_array( $connected_account['username'], $usernames_included, true ) ) {
378
+ if ( ! $sb_instagram_posts_manager->are_current_api_request_delays( $connected_account ) ) {
379
+ $feed_type_and_terms['users'][] = array(
380
+ 'term' => $connected_account['user_id'],
381
+ 'params' => array()
382
+ );
383
+ } else {
384
+ $feed_type_and_terms['users'][] = array(
385
+ 'term' => $connected_account['user_id'],
386
+ 'params' => array(),
387
+ 'error' => true
388
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389
  }
390
+ $connected_accounts_in_feed[ $connected_account['user_id'] ] = $connected_account;
391
+ $usernames_included[] = $connected_account['username'];
392
  }
393
+ } else {
394
+ $feed_type_and_terms['users'][] = array(
395
+ 'term' => $user_id_or_name,
396
+ 'params' => array(),
397
+ 'error' => true
398
+ );
399
+ $usernames_not_connected[] = $user_id_or_name;
400
  }
401
 
402
+ }
 
 
 
 
 
403
 
404
+ if ( ! empty( $usernames_not_connected ) ) {
405
+ global $sb_instagram_posts_manager;
406
+ if ( count( $usernames_not_connected ) === 1 ) {
407
+ $user = $usernames_not_connected[0];
408
+ } else {
409
+ $user = implode( ', ', $usernames_not_connected );
410
  }
411
 
412
+ $settings_link = '<a href="'.get_admin_url().'?page=sb-instagram-feed" target="_blank">' . __( 'plugin Settings page', 'instagram-feed' ) . '</a>';
 
 
 
413
 
414
+ $error_message_return = array(
415
+ 'error_message' => sprintf( __( 'Error: There is no connected account for the user %s.', 'instagram-feed' ), $user ),
416
+ 'admin_only' => sprintf( __( 'A connected account related to the user is required to display user feeds. Please connect an account for this user on the %s.', 'instagram-feed' ), $settings_link ),
417
+ 'frontend_directions' => '',
418
+ 'backend_directions' => ''
419
+ );
420
+ $sb_instagram_posts_manager->maybe_set_display_error( 'configuration', $error_message_return );
421
  }
422
 
423
+ $this->add_feed_type_and_terms( $feed_type_and_terms );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
424
 
425
+ $this->add_connected_accounts_in_feed( $connected_accounts_in_feed );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
426
 
427
+ }
428
 
429
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
430
 
431
+ /**
432
+ * Based on the settings related to retrieving post data from the API,
433
+ * this setting is used to make sure all endpoints needed for the feed are
434
+ * connected and stored for easily looping through when adding posts
435
+ *
436
+ * Overwritten in the Pro version.
437
+ *
438
+ * @since 2.0/5.0
439
+ */
440
+ public function set_feed_type_and_terms() {
441
+ global $sb_instagram_posts_manager;
442
 
443
+ $is_using_access_token_in_shortcode = ! empty( $this->atts['accesstoken'] );
444
+ $settings_link = '<a href="'.get_admin_url().'?page=sb-instagram-feed" target="_blank">' . __( 'plugin Settings page', 'instagram-feed' ) . '</a>';
445
+ if ( $is_using_access_token_in_shortcode ) {
446
+ $error_message_return = array(
447
+ 'error_message' => __( 'Error: Cannot add access token directly to the shortcode.', 'instagram-feed' ),
448
+ 'admin_only' => sprintf( __( 'Due to recent Instagram platform changes, it\'s no longer possible to create a feed by adding the access token to the shortcode. Remove the access token from the shortcode and connect an account on the %s instead.', 'instagram-feed' ), $settings_link ),
449
+ 'frontend_directions' => '',
450
+ 'backend_directions' => ''
451
+ );
452
 
453
+ $sb_instagram_posts_manager->maybe_set_display_error( 'configuration', $error_message_return );
 
454
 
 
 
455
 
456
+ $this->atts['accesstoken'] = '';
457
+ }
 
 
458
 
459
+ if ( empty( $this->settings['id'] )
460
+ && empty( $this->settings['user'] )
461
+ && ! empty ( $this->connected_accounts ) ) {
462
 
463
+ $this->set_user_feed();
464
  } else {
465
+ $user_array = array();
466
+ if ( ! empty( $this->settings['user'] ) ) {
467
+ $user_array = is_array( $this->settings['user'] ) ? $this->settings['user'] : explode( ',', str_replace( ' ', '', $this->settings['user'] ) );
468
+ } elseif ( ! empty( $this->settings['id'] ) ) {
469
+ $user_array = is_array( $this->settings['id'] ) ? $this->settings['id'] : explode( ',', str_replace( ' ', '', $this->settings['id'] ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
470
  }
471
+
472
+ $this->set_user_feed( $user_array );
473
+ }
474
+ if ( empty( $this->feed_type_and_terms['users'] ) ) {
475
+ $error_message_return = array(
476
+ 'error_message' => __( 'Error: No users set.', 'instagram-feed' ),
477
+ 'admin_only' => __( 'Please visit the plugin\'s settings page to select a user account or add one to the shortcode - user="username".', 'instagram-feed' ),
478
+ 'frontend_directions' => '',
479
+ 'backend_directions' => ''
480
+ );
481
+ $sb_instagram_posts_manager->maybe_set_display_error( 'configuration', $error_message_return );
482
  }
483
 
 
 
 
 
 
484
 
485
+ foreach ( $this->connected_accounts_in_feed as $connected_account_in_feed ) {
486
+ if ( isset( $connected_account_in_feed['private'] )
487
+ && sbi_private_account_near_expiration( $connected_account_in_feed ) ) {
488
+ $link_1 = '<a href="https://help.instagram.com/116024195217477/In">';
489
+ $link_2 = '</a>';
490
+ $error_message_return = array(
491
+ 'error_message' => __( 'Error: Private Instagram Account.', 'instagram-feed' ),
492
+ 'admin_only' => sprintf( __( 'It looks like your Instagram account is private. Instagram requires private accounts to be reauthenticated every 60 days. Refresh your account to allow it to continue updating, or %smake your Instagram account public%s.', 'instagram-feed' ), $link_1, $link_2 ),
493
+ 'frontend_directions' => '<a href="https://smashballoon.com/instagram-feed/docs/errors/#10">' . __( 'Click here to troubleshoot', 'instagram-feed' ) . '</a>',
494
+ 'backend_directions' => ''
495
+ );
 
 
 
 
496
 
497
+ $sb_instagram_posts_manager->maybe_set_display_error( 'configuration', $error_message_return );
 
 
 
 
498
 
499
+ }
500
  }
 
 
 
501
  }
502
 
503
  /**
inc/if-functions.php CHANGED
@@ -178,7 +178,9 @@ function sbi_add_resized_image_data( $instagram_feed, $feed_id ) {
178
  global $sb_instagram_posts_manager;
179
 
180
  if ( ! $sb_instagram_posts_manager->image_resizing_disabled() ) {
181
- SB_Instagram_Feed::update_last_requested( $instagram_feed->get_image_ids_post_set() );
 
 
182
  }
183
  ?>
184
  <span class="sbi_resized_image_data" data-feed-id="<?php echo esc_attr( $feed_id ); ?>" data-resized="<?php echo esc_attr( sbi_json_encode( SB_Instagram_Feed::get_resized_images_source_set( $instagram_feed->get_image_ids_post_set(), 0, $feed_id ) ) ); ?>">
@@ -223,18 +225,6 @@ function sbi_get_next_post_set() {
223
  }
224
 
225
  $settings = $instagram_feed_settings->get_settings();
226
- $current_image_resolution = isset( $_POST['current_resolution'] ) ? (int)$_POST['current_resolution'] : 640;
227
-
228
- switch ( $current_image_resolution ) {
229
- case 150 :
230
- $settings['imageres'] = 'thumb';
231
- break;
232
- case 320 :
233
- $settings['imageres'] = 'medium';
234
- break;
235
- default :
236
- $settings['imageres'] = 'full';
237
- }
238
 
239
  $feed_type_and_terms = $instagram_feed_settings->get_feed_type_and_terms();
240
 
@@ -246,29 +236,33 @@ function sbi_get_next_post_set() {
246
  $instagram_feed->set_post_data_from_cache();
247
  }
248
 
249
- if ( $instagram_feed->need_posts( $settings['num'], $offset ) && $instagram_feed->can_get_more_posts() ) {
250
- while ( $instagram_feed->need_posts( $settings['num'], $offset ) && $instagram_feed->can_get_more_posts() ) {
251
- $instagram_feed->add_remote_posts( $settings, $feed_type_and_terms, $instagram_feed_settings->get_connected_accounts_in_feed() );
252
- }
253
-
254
- if ( $instagram_feed->need_to_start_cron_job() ) {
255
- $instagram_feed->add_report( 'needed to start cron job' );
256
- $to_cache = array(
257
- 'atts' => $atts,
258
- 'last_requested' => time(),
259
- );
260
-
261
- $instagram_feed->set_cron_cache( $to_cache, $instagram_feed_settings->get_cache_time_in_seconds() );
262
 
263
- } else {
264
- $instagram_feed->add_report( 'updating last requested and adding to cache' );
265
- $to_cache = array(
266
- 'last_requested' => time(),
267
- );
 
 
 
 
 
 
 
 
 
 
268
 
269
- $instagram_feed->set_cron_cache( $to_cache, $instagram_feed_settings->get_cache_time_in_seconds(), $settings['backup_cache_enabled'] );
270
- }
271
- }
 
 
 
272
 
273
  } elseif ( $instagram_feed->regular_cache_exists() ) {
274
  $instagram_feed->add_report( 'regular cache exists' );
@@ -322,15 +316,11 @@ function sbi_get_next_post_set() {
322
  'html' => $instagram_feed->get_the_items_html( $settings, $offset, $instagram_feed_settings->get_feed_type_and_terms(), $instagram_feed_settings->get_connected_accounts_in_feed() ),
323
  'feedStatus' => $feed_status,
324
  'report' => $instagram_feed->get_report(),
325
- 'resizedImages' => SB_Instagram_Feed::get_resized_images_source_set( $instagram_feed->get_image_ids_post_set(), 0, $feed_id )
326
  );
327
 
328
  echo sbi_json_encode( $return );
329
 
330
- global $sb_instagram_posts_manager;
331
-
332
- $sb_instagram_posts_manager->update_successful_ajax_test();
333
-
334
  die();
335
  }
336
  add_action( 'wp_ajax_sbi_load_more_clicked', 'sbi_get_next_post_set' );
@@ -388,6 +378,7 @@ function sbi_process_submitted_resize_ids() {
388
  }
389
 
390
  sbi_resize_posts_by_id( $images_need_resizing, $transient_name, $settings );
 
391
 
392
  global $sb_instagram_posts_manager;
393
 
@@ -402,23 +393,6 @@ function sbi_process_submitted_resize_ids() {
402
  add_action( 'wp_ajax_sbi_resized_images_submit', 'sbi_process_submitted_resize_ids' );
403
  add_action( 'wp_ajax_nopriv_sbi_resized_images_submit', 'sbi_process_submitted_resize_ids' );
404
 
405
- /**
406
- * Used for testing if admin-ajax.php can be successfully reached using
407
- * AJAX in the frontend
408
- */
409
- function sbi_update_successful_ajax() {
410
-
411
- global $sb_instagram_posts_manager;
412
-
413
- delete_transient( 'sb_instagram_doing_ajax_test' );
414
-
415
- $sb_instagram_posts_manager->update_successful_ajax_test();
416
-
417
- die();
418
- }
419
- add_action( 'wp_ajax_sbi_on_ajax_test_trigger', 'sbi_update_successful_ajax' );
420
- add_action( 'wp_ajax_nopriv_sbi_on_ajax_test_trigger', 'sbi_update_successful_ajax' );
421
-
422
  /**
423
  * Outputs an organized error report for the front end.
424
  * This hooks into the end of the feed before the closing div
@@ -427,25 +401,46 @@ add_action( 'wp_ajax_nopriv_sbi_on_ajax_test_trigger', 'sbi_update_successful_aj
427
  * @param string $feed_id
428
  */
429
  function sbi_error_report( $instagram_feed, $feed_id ) {
430
- global $sb_instagram_posts_manager;
431
 
432
- $style = current_user_can( 'manage_instagram_feed_options' ) ? ' style="display: block;"' : '';
433
 
434
- $error_messages = $sb_instagram_posts_manager->get_frontend_errors();
435
- if ( ! empty( $error_messages ) ) {?>
 
436
  <div id="sbi_mod_error"<?php echo $style; ?>>
437
  <span><?php _e('This error message is only visible to WordPress admins', 'instagram-feed' ); ?></span><br />
438
- <?php foreach ( $error_messages as $error_message ) {
439
- echo $error_message;
440
- } ?>
 
 
 
 
 
 
441
  </div>
442
- <?php
443
- }
444
 
445
  $sb_instagram_posts_manager->reset_frontend_errors();
446
  }
447
  add_action( 'sbi_before_feed_end', 'sbi_error_report', 10, 2 );
448
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
449
  /**
450
  * Debug report added at the end of the feed when sbi_debug query arg is added to a page
451
  * that has the feed on it.
@@ -579,10 +574,7 @@ function sbi_create_local_avatar( $username, $file_name ) {
579
  if ( ! $saved_image ) {
580
  global $sb_instagram_posts_manager;
581
 
582
- $sb_instagram_posts_manager->add_error( 'image_editor_save', array(
583
- __( 'Error saving edited image.', 'instagram-feed' ),
584
- $full_file_name
585
- ) );
586
  } else {
587
  return true;
588
  }
@@ -595,8 +587,7 @@ function sbi_create_local_avatar( $username, $file_name ) {
595
  $message .= ' ' . $key . '- ' . $item[0] . ' |';
596
  }
597
  }
598
-
599
- $sb_instagram_posts_manager->add_error( 'image_editor', array( $file_name, $message ) );
600
  }
601
  return false;
602
  }
@@ -814,7 +805,7 @@ function sbi_get_resized_uploads_url() {
814
  $home_url = home_url();
815
 
816
  if ( strpos( $home_url, 'https:' ) !== false ) {
817
- str_replace( 'http:', 'https:', $base_url );
818
  }
819
 
820
  $resize_url = apply_filters( 'sbi_resize_url', trailingslashit( $base_url ) . trailingslashit( SBI_UPLOADS_NAME ) );
178
  global $sb_instagram_posts_manager;
179
 
180
  if ( ! $sb_instagram_posts_manager->image_resizing_disabled() ) {
181
+ if ( $instagram_feed->should_update_last_requested() ) {
182
+ SB_Instagram_Feed::update_last_requested( $instagram_feed->get_image_ids_post_set() );
183
+ }
184
  }
185
  ?>
186
  <span class="sbi_resized_image_data" data-feed-id="<?php echo esc_attr( $feed_id ); ?>" data-resized="<?php echo esc_attr( sbi_json_encode( SB_Instagram_Feed::get_resized_images_source_set( $instagram_feed->get_image_ids_post_set(), 0, $feed_id ) ) ); ?>">
225
  }
226
 
227
  $settings = $instagram_feed_settings->get_settings();
 
 
 
 
 
 
 
 
 
 
 
 
228
 
229
  $feed_type_and_terms = $instagram_feed_settings->get_feed_type_and_terms();
230
 
236
  $instagram_feed->set_post_data_from_cache();
237
  }
238
 
239
+ if ( $instagram_feed->need_posts( $settings['num'], $offset ) && $instagram_feed->can_get_more_posts() ) {
240
+ while ( $instagram_feed->need_posts( $settings['num'], $offset ) && $instagram_feed->can_get_more_posts() ) {
241
+ $instagram_feed->add_remote_posts( $settings, $feed_type_and_terms, $instagram_feed_settings->get_connected_accounts_in_feed() );
242
+ }
 
 
 
 
 
 
 
 
 
243
 
244
+ $normal_method = true;
245
+ if ( $instagram_feed->need_to_start_cron_job() ) {
246
+ $instagram_feed->add_report( 'needed to start cron job' );
247
+ $to_cache = array(
248
+ 'atts' => $atts,
249
+ 'last_requested' => time(),
250
+ );
251
+ $normal_method = false;
252
+
253
+ } else {
254
+ $instagram_feed->add_report( 'updating last requested and adding to cache' );
255
+ $to_cache = array(
256
+ 'last_requested' => time(),
257
+ );
258
+ }
259
 
260
+ if ( $normal_method ) {
261
+ $instagram_feed->set_cron_cache( $to_cache, $instagram_feed_settings->get_cache_time_in_seconds(), $settings['backup_cache_enabled'] );
262
+ } else {
263
+ $instagram_feed->set_cron_cache( $to_cache, $instagram_feed_settings->get_cache_time_in_seconds() );
264
+ }
265
+ }
266
 
267
  } elseif ( $instagram_feed->regular_cache_exists() ) {
268
  $instagram_feed->add_report( 'regular cache exists' );
316
  'html' => $instagram_feed->get_the_items_html( $settings, $offset, $instagram_feed_settings->get_feed_type_and_terms(), $instagram_feed_settings->get_connected_accounts_in_feed() ),
317
  'feedStatus' => $feed_status,
318
  'report' => $instagram_feed->get_report(),
319
+ 'resizedImages' => SB_Instagram_Feed::get_resized_images_source_set( $instagram_feed->get_image_ids_post_set(), 1, $feed_id )
320
  );
321
 
322
  echo sbi_json_encode( $return );
323
 
 
 
 
 
324
  die();
325
  }
326
  add_action( 'wp_ajax_sbi_load_more_clicked', 'sbi_get_next_post_set' );
378
  }
379
 
380
  sbi_resize_posts_by_id( $images_need_resizing, $transient_name, $settings );
381
+ sbi_delete_image_cache( $transient_name );
382
 
383
  global $sb_instagram_posts_manager;
384
 
393
  add_action( 'wp_ajax_sbi_resized_images_submit', 'sbi_process_submitted_resize_ids' );
394
  add_action( 'wp_ajax_nopriv_sbi_resized_images_submit', 'sbi_process_submitted_resize_ids' );
395
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
396
  /**
397
  * Outputs an organized error report for the front end.
398
  * This hooks into the end of the feed before the closing div
401
  * @param string $feed_id
402
  */
403
  function sbi_error_report( $instagram_feed, $feed_id ) {
404
+ global $sb_instagram_posts_manager;
405
 
406
+ $style = sbi_current_user_can( 'manage_instagram_feed_options' ) ? ' style="display: block;"' : '';
407
 
408
+ $error_messages = $sb_instagram_posts_manager->get_frontend_errors( $instagram_feed );
409
+
410
+ if ( ! empty( $error_messages ) ) {?>
411
  <div id="sbi_mod_error"<?php echo $style; ?>>
412
  <span><?php _e('This error message is only visible to WordPress admins', 'instagram-feed' ); ?></span><br />
413
+ <?php foreach ( $error_messages as $error_message ) {
414
+
415
+ echo '<div><strong>' . esc_html( $error_message['error_message'] ) . '</strong>';
416
+ if ( sbi_current_user_can( 'manage_instagram_feed_options' ) ) {
417
+ echo '<br>' . $error_message['admin_only'];
418
+ echo '<br>' . $error_message['frontend_directions'];
419
+ }
420
+ echo '</div>';
421
+ } ?>
422
  </div>
423
+ <?php
424
+ }
425
 
426
  $sb_instagram_posts_manager->reset_frontend_errors();
427
  }
428
  add_action( 'sbi_before_feed_end', 'sbi_error_report', 10, 2 );
429
 
430
+ function sbi_delete_image_cache( $transient_name ) {
431
+ $images_transient_name = str_replace( 'sbi_', 'sbi_i_', $transient_name );
432
+ delete_transient( $images_transient_name );
433
+ }
434
+
435
+ function sbi_current_user_can( $cap ) {
436
+ if ( $cap === 'manage_instagram_feed_options' ) {
437
+ $cap = current_user_can( 'manage_instagram_feed_options' ) ? 'manage_instagram_feed_options' : 'manage_options';
438
+ }
439
+ $cap = apply_filters( 'sbi_settings_pages_capability', $cap );
440
+
441
+ return current_user_can( $cap );
442
+ }
443
+
444
  /**
445
  * Debug report added at the end of the feed when sbi_debug query arg is added to a page
446
  * that has the feed on it.
574
  if ( ! $saved_image ) {
575
  global $sb_instagram_posts_manager;
576
 
577
+ $sb_instagram_posts_manager->add_error( 'image_editor', __( 'Error saving edited image.', 'instagram-feed' ) . ' ' . $full_file_name );
 
 
 
578
  } else {
579
  return true;
580
  }
587
  $message .= ' ' . $key . '- ' . $item[0] . ' |';
588
  }
589
  }
590
+ $sb_instagram_posts_manager->add_error( 'image_editor', $message . ' ' . $file_name );
 
591
  }
592
  return false;
593
  }
805
  $home_url = home_url();
806
 
807
  if ( strpos( $home_url, 'https:' ) !== false ) {
808
+ $base_url = str_replace( 'http:', 'https:', $base_url );
809
  }
810
 
811
  $resize_url = apply_filters( 'sbi_resize_url', trailingslashit( $base_url ) . trailingslashit( SBI_UPLOADS_NAME ) );
instagram-feed.php CHANGED
@@ -3,13 +3,13 @@
3
  Plugin Name: Smash Balloon Instagram Feed
4
  Plugin URI: https://smashballoon.com/instagram-feed
5
  Description: Display beautifully clean, customizable, and responsive Instagram feeds.
6
- Version: 2.6.2
7
  Author: Smash Balloon
8
  Author URI: https://smashballoon.com/
9
  License: GPLv2 or later
10
  Text Domain: instagram-feed
11
 
12
- Copyright 2020 Smash Balloon LLC (email : hey@smashballoon.com)
13
  This program is free software; you can redistribute it and/or modify
14
  it under the terms of the GNU General Public License as published by
15
  the Free Software Foundation; either version 2 of the License, or
@@ -23,11 +23,11 @@ along with this program; if not, write to the Free Software
23
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
  */
25
  if ( ! defined( 'SBIVER' ) ) {
26
- define( 'SBIVER', '2.6.2' );
27
  }
28
  // Db version.
29
  if ( ! defined( 'SBI_DBVERSION' ) ) {
30
- define( 'SBI_DBVERSION', '1.7' );
31
  }
32
 
33
  // Upload folder name for local image files for posts
@@ -89,11 +89,12 @@ if ( function_exists( 'sb_instagram_feed_init' ) ) {
89
  }
90
  // Max Records in Database for Image Resizing
91
  if ( ! defined( 'SBI_MAX_RECORDS' ) ) {
92
- define( 'SBI_MAX_RECORDS', 100 );
93
  }
94
 
95
  require_once trailingslashit( SBI_PLUGIN_DIR ) . 'inc/if-functions.php';
96
  require_once trailingslashit( SBI_PLUGIN_DIR ) . 'inc/class-sb-instagram-api-connect.php';
 
97
  require_once trailingslashit( SBI_PLUGIN_DIR ) . 'inc/class-sb-instagram-cron-updater.php';
98
  require_once trailingslashit( SBI_PLUGIN_DIR ) . 'inc/class-sb-instagram-display-elements.php';
99
  require_once trailingslashit( SBI_PLUGIN_DIR ) . 'inc/class-sb-instagram-feed.php';
@@ -119,6 +120,7 @@ if ( function_exists( 'sb_instagram_feed_init' ) ) {
119
  require_once trailingslashit( SBI_PLUGIN_DIR ) . 'inc/admin/actions.php';
120
  require_once trailingslashit( SBI_PLUGIN_DIR ) . 'inc/admin/main.php';
121
  require_once trailingslashit( SBI_PLUGIN_DIR ) . 'inc/admin/class-sbi-about.php';
 
122
 
123
  if ( version_compare( PHP_VERSION, '5.3.0' ) >= 0
124
  && version_compare( get_bloginfo( 'version' ), '4.6' , '>=' ) ) {
@@ -308,6 +310,8 @@ if ( function_exists( 'sb_instagram_feed_init' ) ) {
308
  global $wpdb;
309
  global $sb_instagram_posts_manager;
310
 
 
 
311
  if ( ! isset( $sb_instagram_posts_manager ) ) {
312
  require_once( trailingslashit( dirname( __FILE__ ) ) . 'inc/class-sb-instagram-posts-manager.php' );
313
  $sb_instagram_posts_manager = new SB_Instagram_Posts_Manager();
@@ -343,6 +347,8 @@ if ( function_exists( 'sb_instagram_feed_init' ) ) {
343
  id INT(11) UNSIGNED NOT NULL,
344
  instagram_id VARCHAR(1000) DEFAULT '' NOT NULL,
345
  feed_id VARCHAR(1000) DEFAULT '' NOT NULL,
 
 
346
  INDEX feed_id (feed_id(100))
347
  );";
348
  $wpdb->query( $sql );
@@ -373,12 +379,8 @@ if ( function_exists( 'sb_instagram_feed_init' ) ) {
373
  $query = $wpdb->last_query;
374
 
375
  if ( $wpdb->get_var( "show tables like '$table_name'" ) != $table_name ) {
376
- $sb_instagram_posts_manager->add_error( 'database_create_posts', array(
377
- __( 'There was an error when trying to create the database tables used for resizing images.', 'instagram-feed' ),
378
- $error . '<br><code>' . $query . '</code>'
379
- ) );
380
- } else {
381
- $sb_instagram_posts_manager->remove_error( 'database_create_posts' );
382
  }
383
 
384
  $feeds_posts_table_name = esc_sql( $wpdb->prefix . SBI_INSTAGRAM_FEEDS_POSTS );
@@ -389,6 +391,8 @@ if ( function_exists( 'sb_instagram_feed_init' ) ) {
389
  id INT(11) UNSIGNED NOT NULL,
390
  instagram_id VARCHAR(1000) DEFAULT '' NOT NULL,
391
  feed_id VARCHAR(1000) DEFAULT '' NOT NULL,
 
 
392
  INDEX feed_id (feed_id(100))
393
  ) $charset_collate;";
394
  $wpdb->query( $sql );
@@ -397,12 +401,12 @@ if ( function_exists( 'sb_instagram_feed_init' ) ) {
397
  $query = $wpdb->last_query;
398
 
399
  if ( $wpdb->get_var( "show tables like '$feeds_posts_table_name'" ) != $feeds_posts_table_name ) {
400
- $sb_instagram_posts_manager->add_error( 'database_create_posts_feeds', array(
401
- __( 'There was an error when trying to create the database tables used for resizing images.', 'instagram-feed' ),
402
- $error . '<br><code>' . $query . '</code>'
403
- ) );
404
- } else {
405
- $sb_instagram_posts_manager->remove_error( 'database_create_posts_feeds' );
406
  }
407
  }
408
  }
@@ -558,6 +562,17 @@ if ( function_exists( 'sb_instagram_feed_init' ) ) {
558
  update_option( 'sbi_db_version', SBI_DBVERSION );
559
  }
560
 
 
 
 
 
 
 
 
 
 
 
 
561
 
562
  }
563
 
3
  Plugin Name: Smash Balloon Instagram Feed
4
  Plugin URI: https://smashballoon.com/instagram-feed
5
  Description: Display beautifully clean, customizable, and responsive Instagram feeds.
6
+ Version: 2.7
7
  Author: Smash Balloon
8
  Author URI: https://smashballoon.com/
9
  License: GPLv2 or later
10
  Text Domain: instagram-feed
11
 
12
+ Copyright 2021 Smash Balloon LLC (email : hey@smashballoon.com)
13
  This program is free software; you can redistribute it and/or modify
14
  it under the terms of the GNU General Public License as published by
15
  the Free Software Foundation; either version 2 of the License, or
23
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
  */
25
  if ( ! defined( 'SBIVER' ) ) {
26
+ define( 'SBIVER', '2.7' );
27
  }
28
  // Db version.
29
  if ( ! defined( 'SBI_DBVERSION' ) ) {
30
+ define( 'SBI_DBVERSION', '1.8' );
31
  }
32
 
33
  // Upload folder name for local image files for posts
89
  }
90
  // Max Records in Database for Image Resizing
91
  if ( ! defined( 'SBI_MAX_RECORDS' ) ) {
92
+ define( 'SBI_MAX_RECORDS', 350 );
93
  }
94
 
95
  require_once trailingslashit( SBI_PLUGIN_DIR ) . 'inc/if-functions.php';
96
  require_once trailingslashit( SBI_PLUGIN_DIR ) . 'inc/class-sb-instagram-api-connect.php';
97
+ include_once trailingslashit( SBI_PLUGIN_DIR ) . 'inc/class-sb-instagram-connected-account.php';
98
  require_once trailingslashit( SBI_PLUGIN_DIR ) . 'inc/class-sb-instagram-cron-updater.php';
99
  require_once trailingslashit( SBI_PLUGIN_DIR ) . 'inc/class-sb-instagram-display-elements.php';
100
  require_once trailingslashit( SBI_PLUGIN_DIR ) . 'inc/class-sb-instagram-feed.php';
120
  require_once trailingslashit( SBI_PLUGIN_DIR ) . 'inc/admin/actions.php';
121
  require_once trailingslashit( SBI_PLUGIN_DIR ) . 'inc/admin/main.php';
122
  require_once trailingslashit( SBI_PLUGIN_DIR ) . 'inc/admin/class-sbi-about.php';
123
+ include_once trailingslashit( SBI_PLUGIN_DIR ) . 'inc/admin/class-sbi-account-connector.php';
124
 
125
  if ( version_compare( PHP_VERSION, '5.3.0' ) >= 0
126
  && version_compare( get_bloginfo( 'version' ), '4.6' , '>=' ) ) {
310
  global $wpdb;
311
  global $sb_instagram_posts_manager;
312
 
313
+ $had_error = false;
314
+
315
  if ( ! isset( $sb_instagram_posts_manager ) ) {
316
  require_once( trailingslashit( dirname( __FILE__ ) ) . 'inc/class-sb-instagram-posts-manager.php' );
317
  $sb_instagram_posts_manager = new SB_Instagram_Posts_Manager();
347
  id INT(11) UNSIGNED NOT NULL,
348
  instagram_id VARCHAR(1000) DEFAULT '' NOT NULL,
349
  feed_id VARCHAR(1000) DEFAULT '' NOT NULL,
350
+ hashtag VARCHAR(1000) DEFAULT '' NOT NULL,
351
+ INDEX hashtag (hashtag(100)),
352
  INDEX feed_id (feed_id(100))
353
  );";
354
  $wpdb->query( $sql );
379
  $query = $wpdb->last_query;
380
 
381
  if ( $wpdb->get_var( "show tables like '$table_name'" ) != $table_name ) {
382
+ $had_error = true;
383
+ $sb_instagram_posts_manager->add_error( 'database_create', '<strong>' . __( 'There was an error when trying to create the database tables used for resizing images.', 'instagram-feed' ) .'</strong><br>' . $error . '<br><code>' . $query . '</code>' );
 
 
 
 
384
  }
385
 
386
  $feeds_posts_table_name = esc_sql( $wpdb->prefix . SBI_INSTAGRAM_FEEDS_POSTS );
391
  id INT(11) UNSIGNED NOT NULL,
392
  instagram_id VARCHAR(1000) DEFAULT '' NOT NULL,
393
  feed_id VARCHAR(1000) DEFAULT '' NOT NULL,
394
+ hashtag VARCHAR(1000) DEFAULT '' NOT NULL,
395
+ INDEX hashtag (hashtag(100)),
396
  INDEX feed_id (feed_id(100))
397
  ) $charset_collate;";
398
  $wpdb->query( $sql );
401
  $query = $wpdb->last_query;
402
 
403
  if ( $wpdb->get_var( "show tables like '$feeds_posts_table_name'" ) != $feeds_posts_table_name ) {
404
+ $had_error = true;
405
+ $sb_instagram_posts_manager->add_error( 'database_create', '<strong>' . __( 'There was an error when trying to create the database tables used for resizing images.', 'instagram-feed' ) .'</strong><br>' . $error . '<br><code>' . $query . '</code>' );
406
+ }
407
+
408
+ if ( ! $had_error ) {
409
+ $sb_instagram_posts_manager->remove_error( 'database_create' );
410
  }
411
  }
412
  }
562
  update_option( 'sbi_db_version', SBI_DBVERSION );
563
  }
564
 
565
+ if ( (float) $db_ver < 1.8 ) {
566
+ global $wpdb;
567
+
568
+ $table_name = $wpdb->prefix . SBI_INSTAGRAM_FEEDS_POSTS;
569
+ $wpdb->query( "ALTER TABLE $table_name ADD hashtag VARCHAR(1000) NOT NULL;" );
570
+
571
+ $wpdb->query( "ALTER TABLE $table_name ADD INDEX hashtag (hashtag(100))" );
572
+
573
+ update_option( 'sbi_db_version', SBI_DBVERSION );
574
+
575
+ }
576
 
577
  }
578
 
js/sb-instagram-2-1.js DELETED
@@ -1,884 +0,0 @@
1
- var sbi_js_exists = (typeof sbi_js_exists !== 'undefined') ? true : false;
2
- if(!sbi_js_exists) {
3
- (function($){
4
-
5
- function sbiAddImgLiquid() {
6
- /*! imgLiquid v0.9.944 / 03-05-2013 https://github.com/karacas/imgLiquid */
7
- var sbi_imgLiquid = sbi_imgLiquid || {VER: "0.9.944"};
8
- sbi_imgLiquid.bgs_Available = !1, sbi_imgLiquid.bgs_CheckRunned = !1, function (i) {
9
- function t() {
10
- if (!sbi_imgLiquid.bgs_CheckRunned) {
11
- sbi_imgLiquid.bgs_CheckRunned = !0;
12
- var t = i('<span style="background-size:cover" />');
13
- i("body").append(t), !function () {
14
- var i = t[0];
15
- if (i && window.getComputedStyle) {
16
- var e = window.getComputedStyle(i, null);
17
- e && e.backgroundSize && (sbi_imgLiquid.bgs_Available = "cover" === e.backgroundSize)
18
- }
19
- }(), t.remove()
20
- }
21
- }
22
-
23
- i.fn.extend({
24
- sbi_imgLiquid: function (e) {
25
- this.defaults = {
26
- fill: !0,
27
- verticalAlign: "center",
28
- horizontalAlign: "center",
29
- useBackgroundSize: !0,
30
- useDataHtmlAttr: !0,
31
- responsive: !0,
32
- delay: 0,
33
- fadeInTime: 0,
34
- removeBoxBackground: !0,
35
- hardPixels: !0,
36
- responsiveCheckTime: 500,
37
- timecheckvisibility: 500,
38
- onStart: null,
39
- onFinish: null,
40
- onItemStart: null,
41
- onItemFinish: null,
42
- onItemError: null
43
- }, t();
44
- var a = this;
45
- return this.options = e, this.settings = i.extend({}, this.defaults, this.options), this.settings.onStart && this.settings.onStart(), this.each(function (t) {
46
- function e() {
47
- -1 === u.css("background-image").indexOf(encodeURI(c.attr("src"))) && u.css({"background-image": 'url("' + encodeURI(c.attr("src")) + '")'}), u.css({
48
- "background-size": g.fill ? "cover" : "contain",
49
- "background-position": (g.horizontalAlign + " " + g.verticalAlign).toLowerCase(),
50
- "background-repeat": "no-repeat"
51
- }), i("a:first", u).css({
52
- display: "block",
53
- width: "100%",
54
- height: "100%"
55
- }), i("img", u).css({display: "none"}), g.onItemFinish && g.onItemFinish(t, u, c), u.addClass("sbi_imgLiquid_bgSize"), u.addClass("sbi_imgLiquid_ready"), l()
56
- }
57
-
58
- function o() {
59
- function e() {
60
- c.data("sbi_imgLiquid_error") || c.data("sbi_imgLiquid_loaded") || c.data("sbi_imgLiquid_oldProcessed") || (u.is(":visible") && c[0].complete && c[0].width > 0 && c[0].height > 0 ? (c.data("sbi_imgLiquid_loaded", !0), setTimeout(r, t * g.delay)) : setTimeout(e, g.timecheckvisibility))
61
- }
62
-
63
- if (c.data("oldSrc") && c.data("oldSrc") !== c.attr("src")) {
64
- var a = c.clone().removeAttr("style");
65
- return a.data("sbi_imgLiquid_settings", c.data("sbi_imgLiquid_settings")), c.parent().prepend(a), c.remove(), c = a, c[0].width = 0, void setTimeout(o, 10)
66
- }
67
- return c.data("sbi_imgLiquid_oldProcessed") ? void r() : (c.data("sbi_imgLiquid_oldProcessed", !1), c.data("oldSrc", c.attr("src")), i("img:not(:first)", u).css("display", "none"), u.css({overflow: "hidden"}), c.fadeTo(0, 0).removeAttr("width").removeAttr("height").css({
68
- visibility: "visible",
69
- "max-width": "none",
70
- "max-height": "none",
71
- width: "auto",
72
- height: "auto",
73
- display: "block"
74
- }), c.on("error", n), c[0].onerror = n, e(), void d())
75
- }
76
-
77
- function d() {
78
- (g.responsive || c.data("sbi_imgLiquid_oldProcessed")) && c.data("sbi_imgLiquid_settings") && (g = c.data("sbi_imgLiquid_settings"), u.actualSize = u.get(0).offsetWidth + u.get(0).offsetHeight / 1e4, u.sizeOld && u.actualSize !== u.sizeOld && r(), u.sizeOld = u.actualSize, setTimeout(d, g.responsiveCheckTime))
79
- }
80
-
81
- function n() {
82
- c.data("sbi_imgLiquid_error", !0), u.addClass("sbi_imgLiquid_error"), g.onItemError && g.onItemError(t, u, c), l()
83
- }
84
-
85
- function s() {
86
- var i = {};
87
- if (a.settings.useDataHtmlAttr) {
88
- var t = u.attr("data-sbi_imgLiquid-fill"),
89
- e = u.attr("data-sbi_imgLiquid-horizontalAlign"),
90
- o = u.attr("data-sbi_imgLiquid-verticalAlign");
91
- ("true" === t || "false" === t) && (i.fill = Boolean("true" === t)), void 0 === e || "left" !== e && "center" !== e && "right" !== e && -1 === e.indexOf("%") || (i.horizontalAlign = e), void 0 === o || "top" !== o && "bottom" !== o && "center" !== o && -1 === o.indexOf("%") || (i.verticalAlign = o)
92
- }
93
- return sbi_imgLiquid.isIE && a.settings.ieFadeInDisabled && (i.fadeInTime = 0), i
94
- }
95
-
96
- function r() {
97
- var i, e, a, o, d, n, s, r, m = 0, h = 0, f = u.width(), v = u.height();
98
- void 0 === c.data("owidth") && c.data("owidth", c[0].width), void 0 === c.data("oheight") && c.data("oheight", c[0].height), g.fill === f / v >= c.data("owidth") / c.data("oheight") ? (i = "100%", e = "auto", a = Math.floor(f), o = Math.floor(f * (c.data("oheight") / c.data("owidth")))) : (i = "auto", e = "100%", a = Math.floor(v * (c.data("owidth") / c.data("oheight"))), o = Math.floor(v)), d = g.horizontalAlign.toLowerCase(), s = f - a, "left" === d && (h = 0), "center" === d && (h = .5 * s), "right" === d && (h = s), -1 !== d.indexOf("%") && (d = parseInt(d.replace("%", ""), 10), d > 0 && (h = s * d * .01)), n = g.verticalAlign.toLowerCase(), r = v - o, "left" === n && (m = 0), "center" === n && (m = .5 * r), "bottom" === n && (m = r), -1 !== n.indexOf("%") && (n = parseInt(n.replace("%", ""), 10), n > 0 && (m = r * n * .01)), g.hardPixels && (i = a, e = o), c.css({
99
- width: i,
100
- height: e,
101
- "margin-left": Math.floor(h),
102
- "margin-top": Math.floor(m)
103
- }), c.data("sbi_imgLiquid_oldProcessed") || (c.fadeTo(g.fadeInTime, 1), c.data("sbi_imgLiquid_oldProcessed", !0), g.removeBoxBackground && u.css("background-image", "none"), u.addClass("sbi_imgLiquid_nobgSize"), u.addClass("sbi_imgLiquid_ready")), g.onItemFinish && g.onItemFinish(t, u, c), l()
104
- }
105
-
106
- function l() {
107
- t === a.length - 1 && a.settings.onFinish && a.settings.onFinish()
108
- }
109
-
110
- var g = a.settings, u = i(this), c = i("img:first", u);
111
- return c.length ? (c.data("sbi_imgLiquid_settings") ? (u.removeClass("sbi_imgLiquid_error").removeClass("sbi_imgLiquid_ready"), g = i.extend({}, c.data("sbi_imgLiquid_settings"), a.options)) : g = i.extend({}, a.settings, s()), c.data("sbi_imgLiquid_settings", g), g.onItemStart && g.onItemStart(t, u, c), void (sbi_imgLiquid.bgs_Available && g.useBackgroundSize ? e() : o())) : void n()
112
- })
113
- }
114
- })
115
- }(jQuery);
116
-
117
- // Use imagefill to set the images as backgrounds so they can be square
118
- !function () {
119
- var css = sbi_imgLiquid.injectCss,
120
- head = document.getElementsByTagName('head')[0],
121
- style = document.createElement('style');
122
- style.type = 'text/css';
123
- if (style.styleSheet) {
124
- style.styleSheet.cssText = css;
125
- } else {
126
- style.appendChild(document.createTextNode(css));
127
- }
128
- head.appendChild(style);
129
- }();
130
- }
131
-
132
- function sbiAddVisibilityListener() {
133
- /* Detect when element becomes visible. Used for when the feed is initially hidden, in a tab for example. https://github.com/shaunbowe/jquery.visibilityChanged */
134
- !function (i) {
135
- var n = {
136
- callback: function () {
137
- }, runOnLoad: !0, frequency: 100, sbiPreviousVisibility: null
138
- }, c = {};
139
- c.sbiCheckVisibility = function (i, n) {
140
- if (jQuery.contains(document, i[0])) {
141
- var e = n.sbiPreviousVisibility, t = i.is(":visible");
142
- n.sbiPreviousVisibility = t, null == e ? n.runOnLoad && n.callback(i, t) : e !== t && n.callback(i, t), setTimeout(function () {
143
- c.sbiCheckVisibility(i, n)
144
- }, n.frequency)
145
- }
146
- }, i.fn.sbiVisibilityChanged = function (e) {
147
- var t = i.extend({}, n, e);
148
- return this.each(function () {
149
- c.sbiCheckVisibility(i(this), t)
150
- })
151
- }
152
- }(jQuery);
153
- }
154
-
155
- function Sbi() {
156
- this.feeds = {};
157
- this.options = sb_instagram_js_options;
158
- }
159
-
160
- Sbi.prototype = {
161
- createPage: function (createFeeds, createFeedsArgs) {
162
- if (typeof window.sbiajaxurl === 'undefined' || window.sbiajaxurl.indexOf(window.location.hostname) === -1) {
163
- window.sbiajaxurl = location.protocol + '//'+ window.location.hostname + '/wp-admin/admin-ajax.php';
164
- }
165
-
166
- $('.sbi_no_js_error_message').remove();
167
- $('.sbi_no_js').removeClass('sbi_no_js');
168
- createFeeds(createFeedsArgs);
169
- },
170
- createFeeds: function (args) {
171
- args.whenFeedsCreated(
172
- $('.sbi').each(function (index) {
173
- $(this).attr('data-sbi-index', index + 1);
174
- var $self = $(this),
175
- flags = typeof $self.attr('data-sbi-flags') !== 'undefined' ? $self.attr('data-sbi-flags').split(',') : [],
176
- general = typeof $self.attr('data-options') !== 'undefined' ? JSON.parse($self.attr('data-options')) : {};
177
- if (flags.indexOf('testAjax') > -1) {
178
- window.sbi.triggeredTest = true;
179
- var submitData = {
180
- 'action' : 'sbi_on_ajax_test_trigger'
181
- },
182
- onSuccess = function(data) {
183
- console.log('did test');
184
- };
185
- sbiAjax(submitData,onSuccess)
186
- }
187
- var feedOptions = {
188
- cols : $self.attr('data-cols'),
189
- colsmobile : $self.attr('data-colsmobile') !== 'same' ? $self.attr('data-colsmobile') : $self.attr('data-cols'),
190
- num : $self.attr('data-num'),
191
- imgRes : $self.attr('data-res'),
192
- feedID : $self.attr('data-feedid'),
193
- shortCodeAtts : $self.attr('data-shortcode-atts'),
194
- resizingEnabled : (flags.indexOf('resizeDisable') === -1),
195
- imageLoadEnabled : (flags.indexOf('imageLoadDisable') === -1),
196
- debugEnabled : (flags.indexOf('debug') > -1),
197
- favorLocal : (flags.indexOf('favorLocal') > -1),
198
- ajaxPostLoad : (flags.indexOf('ajaxPostLoad') > -1),
199
- autoMinRes : 1,
200
- general : general
201
- };
202
-
203
- window.sbi.feeds[index] = sbiGetNewFeed(this, index, feedOptions);
204
- window.sbi.feeds[index].setResizedImages();
205
- window.sbi.feeds[index].init();
206
-
207
- var evt = jQuery.Event('sbiafterfeedcreate');
208
- evt.feed = window.sbi.feeds[index];
209
- jQuery(window).trigger(evt);
210
-
211
- })
212
- );
213
- },
214
- afterFeedsCreated: function () {
215
- // enable header hover action
216
- $('.sb_instagram_header').each(function () {
217
- var $thisHeader = $(this);
218
- $thisHeader.find('.sbi_header_link').hover(function () {
219
- $thisHeader.find('.sbi_header_img_hover').addClass('sbi_fade_in');
220
- }, function () {
221
- $thisHeader.find('.sbi_header_img_hover').removeClass('sbi_fade_in');
222
- });
223
- });
224
-
225
- },
226
- encodeHTML: function(raw) {
227
- // make sure passed variable is defined
228
- if (typeof raw === 'undefined') {
229
- return '';
230
- }
231
- // replace greater than and less than symbols with html entity to disallow html in comments
232
- var encoded = raw.replace(/(>)/g,'&gt;'),
233
- encoded = encoded.replace(/(<)/g,'&lt;');
234
- encoded = encoded.replace(/(&lt;br\/&gt;)/g,'<br>');
235
- encoded = encoded.replace(/(&lt;br&gt;)/g,'<br>');
236
-
237
- return encoded;
238
- },
239
- urlDetect: function(text) {
240
- var urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g;
241
- return text.match(urlRegex);
242
- }
243
- };
244
-
245
- function SbiFeed(el, index, settings) {
246
- this.el = el;
247
- this.index = index;
248
- this.settings = settings;
249
- this.minImageWidth = 0;
250
- this.imageResolution = 150;
251
- this.resizedImages = {};
252
- this.needsResizing = [];
253
- this.outOfPages = false;
254
- this.isInitialized = false;
255
- }
256
-
257
- SbiFeed.prototype = {
258
- init: function() {
259
- var feed = this;
260
- if (this.settings.ajaxPostLoad) {
261
- this.getNewPostSet();
262
- } else {
263
- this.afterInitialImagesLoaded();
264
- //Only check the width once the resize event is over
265
- }
266
- var sbi_delay = (function () {
267
- var sbi_timer = 0;
268
- return function (sbi_callback, sbi_ms) {
269
- clearTimeout(sbi_timer);
270
- sbi_timer = setTimeout(sbi_callback, sbi_ms);
271
- };
272
- })();
273
- jQuery(window).resize(function () {
274
- sbi_delay(function () {
275
- feed.afterResize();
276
- }, 500);
277
- });
278
-
279
- },
280
- initLayout: function() {
281
-
282
- },
283
- afterInitialImagesLoaded: function() {
284
- this.initLayout();
285
- this.loadMoreButtonInit();
286
- this.hideExtraImagesForWidth();
287
- this.beforeNewImagesRevealed();
288
- this.revealNewImages();
289
- this.afterNewImagesRevealed();
290
- },
291
- afterResize: function() {
292
- this.setImageHeight();
293
- this.setImageResolution();
294
- this.maybeRaiseImageResolution();
295
- this.setImageSizeClass();
296
- },
297
- afterLoadMoreClicked: function($button) {
298
- $button.find('.sbi_loader').removeClass('sbi_hidden');
299
- $button.find('.sbi_btn_text').addClass('sbi_hidden');
300
- $button.closest('.sbi').find('.sbi_num_diff_hide').addClass('sbi_transition').removeClass('sbi_num_diff_hide');
301
- },
302
- afterNewImagesLoaded: function() {
303
- var $self = $(this.el),
304
- feed = this;
305
- this.beforeNewImagesRevealed();
306
- this.revealNewImages();
307
- this.afterNewImagesRevealed();
308
- setTimeout(function () {
309
- //Hide the loader in the load more button
310
- $self.find('.sbi_loader').addClass('sbi_hidden');
311
- $self.find('.sbi_btn_text').removeClass('sbi_hidden');
312
- feed.maybeRaiseImageResolution();
313
- }, 500);
314
- },
315
- beforeNewImagesRevealed: function() {
316
- this.setImageHeight();
317
- this.maybeRaiseImageResolution(true);
318
- this.setImageSizeClass();
319
- },
320
- revealNewImages: function() {
321
- var $self = $(this.el),
322
- feed = this;
323
-
324
- // Call Custom JS if it exists
325
- if (typeof sbi_custom_js == 'function') setTimeout(function(){ sbi_custom_js(); }, 100);
326
-
327
- this.applyImageLiquid();
328
- $self.find('.sbi_item').each(function (index) {
329
- var $self = jQuery(this);
330
-
331
- //Photo links
332
- //If lightbox is disabled
333
- $self.find('.sbi_photo').hover(function () {
334
- jQuery(this).fadeTo(200, 0.85);
335
- }, function () {
336
- jQuery(this).stop().fadeTo(500, 1);
337
- });
338
-
339
- }); //End .sbi_item each
340
-
341
- //Remove the new class after 500ms, once the sorting is done
342
- setTimeout(function () {
343
- jQuery('#sbi_images .sbi_item.sbi_new').removeClass('sbi_new');
344
- //Loop through items and remove class to reveal them
345
- var time = 10;
346
- $self.find('.sbi_transition').each(function() {
347
- var $sbi_item_transition_el = jQuery(this);
348
-
349
- setTimeout( function(){
350
- $sbi_item_transition_el.removeClass('sbi_transition');
351
- }, time);
352
- time += 10;
353
- });
354
- }, 500);
355
- },
356
- afterNewImagesRevealed: function() {
357
- this.listenForVisibilityChange();
358
- this.sendNeedsResizingToServer();
359
- if (!this.settings.imageLoadEnabled) {
360
- $('.sbi_no_resraise').removeClass('sbi_no_resraise');
361
- }
362
-
363
- var evt = $.Event('sbiafterimagesloaded');
364
- evt.el = $(this.el);
365
- $(window).trigger(evt);
366
- },
367
- setResizedImages: function () {
368
- if ($(this.el).find('.sbi_resized_image_data').length
369
- && typeof $(this.el).find('.sbi_resized_image_data').attr('data-resized') !== 'undefined'
370
- && $(this.el).find('.sbi_resized_image_data').attr('data-resized').indexOf('{"') === 0) {
371
- this.resizedImages = JSON.parse($(this.el).find('.sbi_resized_image_data').attr('data-resized'));
372
- $(this.el).find('.sbi_resized_image_data').remove();
373
- }
374
- },
375
- sendNeedsResizingToServer: function() {
376
- var feed = this;
377
- if (feed.needsResizing.length > 0 && feed.settings.resizingEnabled) {
378
- var itemOffset = $(this.el).find('.sbi_item').length;
379
-
380
- var submitData = {
381
- action: 'sbi_resized_images_submit',
382
- needs_resizing: feed.needsResizing,
383
- offset: itemOffset,
384
- feed_id: feed.settings.feedID,
385
- atts: feed.settings.shortCodeAtts,
386
- };
387
- var onSuccess = function(data) {
388
- if (data.trim().indexOf('{') === 0) {
389
- var response = JSON.parse(data);
390
- if (feed.settings.debugEnabled) {
391
- console.log(response);
392
- }
393
- }
394
- };
395
- sbiAjax(submitData,onSuccess);
396
- }
397
- },
398
- loadMoreButtonInit: function () {
399
- var $self = $(this.el),
400
- feed = this;
401
- $self.find('#sbi_load .sbi_load_btn').off().on('click', function () {
402
-
403
- feed.afterLoadMoreClicked(jQuery(this));
404
- feed.getNewPostSet();
405
-
406
- }); //End click event
407
- },
408
- getNewPostSet: function () {
409
- var $self = $(this.el),
410
- feed = this;
411
- var itemOffset = $self.find('.sbi_item').length,
412
- submitData = {
413
- action: 'sbi_load_more_clicked',
414
- offset: itemOffset,
415
- feed_id: feed.settings.feedID,
416
- atts: feed.settings.shortCodeAtts,
417
- current_resolution: feed.imageResolution
418
- };
419
- var onSuccess = function (data) {
420
- if (data.trim().indexOf('{') === 0) {
421
- var response = JSON.parse(data);
422
- if (feed.settings.debugEnabled) {
423
- console.log(response);
424
- }
425
- feed.appendNewPosts(response.html);
426
- feed.addResizedImages(response.resizedImages);
427
- if (feed.settings.ajaxPostLoad) {
428
- feed.settings.ajaxPostLoad = false;
429
- feed.afterInitialImagesLoaded();
430
- } else {
431
- feed.afterNewImagesLoaded();
432
- }
433
-
434
- if (!response.feedStatus.shouldPaginate) {
435
- feed.outOfPages = true;
436
- $self.find('.sbi_load_btn').hide();
437
- } else {
438
- feed.outOfPages = false;
439
- }
440
- $('.sbi_no_js').removeClass('sbi_no_js');
441
- }
442
-
443
- };
444
- sbiAjax(submitData, onSuccess);
445
- },
446
- appendNewPosts: function (newPostsHtml) {
447
- var $self = $(this.el),
448
- feed = this;
449
- if ($self.find('#sbi_images .sbi_item').length) {
450
- $self.find('#sbi_images .sbi_item').last().after(newPostsHtml);
451
- } else {
452
- $self.find('#sbi_images').append(newPostsHtml);
453
- }
454
- },
455
- addResizedImages: function (resizedImagesToAdd) {
456
- for (var imageID in resizedImagesToAdd) {
457
- this.resizedImages[imageID] = resizedImagesToAdd[imageID];
458
- }
459
- },
460
- setImageHeight: function() {
461
- var $self = $(this.el);
462
-
463
- var sbi_photo_width = $self.find('.sbi_photo').eq(0).innerWidth();
464
-
465
- //Figure out number of columns for either desktop or mobile
466
- var sbi_num_cols = this.getColumnCount();
467
-
468
- //Figure out what the width should be using the number of cols
469
- //Figure out what the width should be using the number of cols
470
- var imagesPadding = $self.find('#sbi_images').innerWidth() - $self.find('#sbi_images').width(),
471
- imagepadding = imagesPadding / 2;
472
- sbi_photo_width_manual = ( $self.find('#sbi_images').width() / sbi_num_cols ) - imagesPadding;
473
- //If the width is less than it should be then set it manually
474
- //if( sbi_photo_width <= (sbi_photo_width_manual) ) sbi_photo_width = sbi_photo_width_manual;
475
-
476
- $self.find('.sbi_photo').css('height', sbi_photo_width);
477
-
478
- //Set the position of the carousel arrows
479
- if ($self.find('.sbi-owl-nav').length) {
480
- setTimeout(function(){
481
- //If there's 2 rows then adjust position
482
- var sbi_ratio = 2;
483
- if( $self.find('.sbi_owl2row-item').length ) sbi_ratio = 1;
484
-
485
- var sbi_arrows_top = ($self.find('.sbi_photo').eq(0).innerWidth()/sbi_ratio);
486
- sbi_arrows_top += parseInt(imagepadding)*(2+(2-sbi_ratio));
487
- $self.find('.sbi-owl-nav div').css('top', sbi_arrows_top);
488
- }, 100);
489
- }
490
-
491
- },
492
- maybeRaiseSingleImageResolution: function ($item, index, forceChange) {
493
- var feed = this,
494
- imgSrcSet = feed.getImageUrls($item),
495
- currentUrl = $item.find('.sbi_photo img').attr('src'),
496
- currentRes = 150,
497
- imagEl = $item.find('img').get(0),
498
- aspectRatio = currentUrl === window.sbi.options.placeholder ? 1 : imagEl.naturalWidth/imagEl.naturalHeight,
499
- forceChange = typeof forceChange !== 'undefined' ? forceChange : false;
500
-
501
- if ($item.hasClass('sbi_no_resraise') || $item.hasClass('sbi_had_error') || ($item.find('.sbi_link_area').length && $item.find('.sbi_link_area').hasClass('sbi_had_error'))) {
502
- return;
503
- }
504
-
505
- $.each(imgSrcSet, function (index, value) {
506
- if (value === currentUrl) {
507
- currentRes = parseInt(index);
508
- // If the image has already been changed to an existing real source, don't force the change
509
- forceChange = false;
510
- }
511
- });
512
- //Image res
513
- var newRes = 640;
514
- switch (feed.settings.imgRes) {
515
- case 'thumb':
516
- newRes = 150;
517
- break;
518
- case 'medium':
519
- newRes = 320;
520
- break;
521
- case 'full':
522
- newRes = 640;
523
- break;
524
- default:
525
- var minImageWidth = Math.max(feed.settings.autoMinRes,$item.find('.sbi_photo').innerWidth()),
526
- thisImageReplace = feed.getBestResolutionForAuto(minImageWidth, aspectRatio, $item);
527
- switch (thisImageReplace) {
528
- case 320:
529
- newRes = 320;
530
- break;
531
- case 150:
532
- newRes = 150;
533
- break;
534
- }
535
- break;
536
- }
537
-
538
- if (newRes > currentRes || currentUrl === window.sbi.options.placeholder || forceChange) {
539
- if (feed.settings.debugEnabled) {
540
- var reason = currentUrl === window.sbi.options.placeholder ? 'was placeholder' : 'too small';
541
- console.log('rais res for ' + currentUrl, reason);
542
- }
543
- var newUrl = imgSrcSet[newRes].split("?ig_cache_key")[0];
544
- $item.find('.sbi_photo img').attr('src', newUrl);
545
- $item.find('.sbi_photo').css('background-image', 'url("' + newUrl + '")');
546
- currentRes = newRes;
547
-
548
- if (feed.settings.imgRes === 'auto') {
549
- var checked = false;
550
- $item.find('.sbi_photo img').on('load', function () {
551
-
552
- var $this_image = $(this);
553
- var newAspectRatio = ($this_image.get(0).naturalWidth / $this_image.get(0).naturalHeight);
554
-
555
- if ($this_image.get(0).naturalWidth !== 1000 && newAspectRatio > aspectRatio && !checked) {
556
- if (feed.settings.debugEnabled) {
557
- console.log('rais res again for aspect ratio change ' + currentUrl);
558
- }
559
- checked = true;
560
- minImageWidth = $item.find('.sbi_photo').innerWidth();
561
- thisImageReplace = feed.getBestResolutionForAuto(minImageWidth, newAspectRatio, $item);
562
- newRes = 640;
563
-
564
- switch (thisImageReplace) {
565
- case 320:
566
- newRes = 320;
567
- break;
568
- case 150:
569
- newRes = 150;
570
- break;
571
- }
572
-
573
- if (newRes > currentRes) {
574
- newUrl = imgSrcSet[newRes].split("?ig_cache_key")[0];
575
- $this_image.attr('src', newUrl);
576
- $this_image.closest('.sbi_photo').css('background-image', 'url("' + newUrl + '")');
577
- }
578
- if (feed.layout === 'masonry' || feed.layout === 'highlight') {
579
- $(feed.el).find('#sbi_images').smashotope(feed.isotopeArgs);
580
- setTimeout(function() {
581
- $(feed.el).find('#sbi_images').smashotope(feed.isotopeArgs);
582
- },500)
583
- }
584
- } else {
585
- if (feed.settings.debugEnabled) {
586
- var reason = checked ? 'already checked' : 'no aspect ratio change';
587
- console.log('not raising res for replacement ' + currentUrl, reason);
588
- }
589
- }
590
- });
591
- }
592
-
593
-
594
- }
595
-
596
- $item.find('img').on('error', function () {
597
- if (!$(this).hasClass('sbi_img_error')) {
598
- $(this).addClass('sbi_img_error');
599
- var sourceFromAPI = ($(this).attr('src').indexOf('media?size=') > -1 || $(this).attr('src').indexOf('cdninstagram') > -1 || $(this).attr('src').indexOf('fbcdn') > -1)
600
-
601
- if (!sourceFromAPI) {
602
-
603
- if ($(this).closest('.sbi_photo').attr('data-img-src-set') !== 'undefined') {
604
- var srcSet = JSON.parse($(this).closest('.sbi_photo').attr('data-img-src-set').replace(/\\\//g, '/'));
605
- if (typeof srcSet.d !== 'undefined') {
606
- $(this).attr('src', srcSet.d);
607
- $(this).closest('.sbi_photo').css('background-image', 'url(' + srcSet.d + ')');
608
- $(this).closest('.sbi_item').addClass('sbi_had_error').find('.sbi_link_area').attr('href', srcSet[640]).addClass('sbi_had_error');
609
- }
610
- }
611
- } else {
612
- feed.settings.favorLocal = true;
613
- var srcSet = feed.getImageUrls($(this).closest('.sbi_item'));
614
- if (typeof srcSet[640] !== 'undefined') {
615
- $(this).attr('src', srcSet[640]);
616
- $(this).closest('.sbi_photo').css('background-image', 'url(' + srcSet[640] + ')');
617
- $(this).closest('.sbi_item').addClass('sbi_had_error').find('.sbi_link_area').attr('href', srcSet[640]).addClass('sbi_had_error');
618
- }
619
- }
620
- setTimeout(function() {
621
- feed.afterResize();
622
- }, 1500)
623
- } else {
624
- console.log('unfixed error ' + $(this).attr('src'));
625
- }
626
- });
627
- },
628
- maybeRaiseImageResolution: function (justNew) {
629
- var feed = this,
630
- itemsSelector = typeof justNew !== 'undefined' && justNew === true ? '.sbi_item.sbi_new' : '.sbi_item',
631
- forceChange = !feed.isInitialized ? true : false;
632
- $(feed.el).find(itemsSelector).each(function (index) {
633
- if (!$(this).hasClass('sbi_num_diff_hide')
634
- && $(this).find('.sbi_photo').length
635
- && typeof $(this).find('.sbi_photo').attr('data-img-src-set') !== 'undefined') {
636
- feed.maybeRaiseSingleImageResolution($(this),index,forceChange);
637
- }
638
- }); //End .sbi_item each
639
- feed.isInitialized = true;
640
- },
641
- getBestResolutionForAuto: function(colWidth, aspectRatio, $item) {
642
- if (isNaN(aspectRatio) || aspectRatio < 1) {
643
- aspectRatio = 1;
644
- }
645
- var bestWidth = colWidth * aspectRatio,
646
- bestWidthRounded = Math.ceil(bestWidth / 10) * 10,
647
- customSizes = [150, 320, 640];
648
-
649
- if ($item.hasClass('sbi_highlighted')) {
650
- bestWidthRounded = bestWidthRounded *2;
651
- }
652
-
653
- if (customSizes.indexOf(parseInt(bestWidthRounded)) === -1) {
654
- var done = false;
655
- $.each(customSizes, function (index, item) {
656
- if (item > parseInt(bestWidthRounded) && !done) {
657
- bestWidthRounded = item;
658
-
659
- done = true;
660
- }
661
- });
662
- }
663
-
664
- return bestWidthRounded;
665
- },
666
- hideExtraImagesForWidth: function() {
667
- if (this.layout === 'carousel') {
668
- return;
669
- }
670
- var $self = $(this.el),
671
- num = typeof $self.attr('data-num') !== 'undefined' && $self.attr('data-num') !== '' ? parseInt($self.attr('data-num')) : 1,
672
- nummobile = typeof $self.attr('data-nummobile') !== 'undefined' && $self.attr('data-nummobile') !== '' ? parseInt($self.attr('data-nummobile')) : num;
673
-
674
- if ($(window).width() < 480) {
675
- if (nummobile < $self.find('.sbi_item').length) {
676
- $self.find('.sbi_item').slice(nummobile - $self.find('.sbi_item').length).addClass('sbi_num_diff_hide');
677
- }
678
- } else {
679
- if (num < $self.find('.sbi_item').length) {
680
- $self.find('.sbi_item').slice(num - $self.find('.sbi_item').length).addClass('sbi_num_diff_hide');
681
- }
682
- }
683
- },
684
- setImageSizeClass: function () {
685
- var $self = $(this.el);
686
- $self.removeClass('sbi_small sbi_medium');
687
- var feedWidth = $self.innerWidth(),
688
- photoPadding = parseInt(($self.find('#sbi_images').outerWidth() - $self.find('#sbi_images').width())) / 2,
689
- cols = this.getColumnCount(),
690
- feedWidthSansPadding = feedWidth - (photoPadding * (cols+2)),
691
- colWidth = (feedWidthSansPadding / cols);
692
- if (colWidth > 120 && colWidth < 240) {
693
- $self.addClass('sbi_medium');
694
- } else if (colWidth <= 120) {
695
- $self.addClass('sbi_small');
696
- }
697
- },
698
- setMinImageWidth: function () {
699
- if ($(this.el).find('.sbi_item .sbi_photo').first().length) {
700
- this.minImageWidth = $(this.el).find('.sbi_item .sbi_photo').first().innerWidth();
701
- } else {
702
- this.minImageWidth = 150;
703
- }
704
- },
705
- setImageResolution: function () {
706
- if (this.settings.imgRes === 'auto') {
707
- this.imageResolution = 'auto';
708
- } else {
709
- switch (this.settings.imgRes) {
710
- case 'thumb':
711
- this.imageResolution = 150;
712
- break;
713
- case 'medium':
714
- this.imageResolution = 320;
715
- break;
716
- default:
717
- this.imageResolution = 640;
718
- }
719
- }
720
- },
721
- getImageUrls: function ($item) {
722
- var srcSet = JSON.parse($item.find('.sbi_photo').attr('data-img-src-set').replace(/\\\//g, '/')),
723
- id = $item.attr('id').replace('sbi_', '');
724
- if (typeof this.resizedImages[id] !== 'undefined'
725
- && this.resizedImages[id] !== 'video'
726
- && this.resizedImages[id] !== 'pending'
727
- && this.resizedImages[id].id !== 'error'
728
- && this.resizedImages[id].id !== 'video'
729
- && this.resizedImages[id].id !== 'pending') {
730
-
731
- if (typeof this.resizedImages[id]['sizes'] !== 'undefined') {
732
- var foundSizes = [];
733
- if (typeof this.resizedImages[id]['sizes']['full'] !== 'undefined') {
734
- srcSet[640] = sb_instagram_js_options.resized_url + this.resizedImages[id].id + 'full.jpg';
735
- foundSizes.push(640);
736
- }
737
- if (typeof this.resizedImages[id]['sizes']['low'] !== 'undefined') {
738
- srcSet[320] = sb_instagram_js_options.resized_url + this.resizedImages[id].id + 'low.jpg';
739
- foundSizes.push(320);
740
- }
741
- if (typeof this.resizedImages[id]['sizes']['thumb'] !== 'undefined') {
742
- foundSizes.push(150);
743
- srcSet[150] = sb_instagram_js_options.resized_url + this.resizedImages[id].id + 'thumb.jpg';
744
- }
745
- if (this.settings.favorLocal) {
746
- if (foundSizes.indexOf(640) === -1) {
747
- if (foundSizes.indexOf(320) > -1) {
748
- srcSet[640] = sb_instagram_js_options.resized_url + this.resizedImages[id].id + 'low.jpg';
749
- }
750
- }
751
- if (foundSizes.indexOf(320) === -1) {
752
- if (foundSizes.indexOf(640) > -1) {
753
- srcSet[320] = sb_instagram_js_options.resized_url + this.resizedImages[id].id + 'full.jpg';
754
- } else if (foundSizes.indexOf(150) > -1) {
755
- srcSet[320] = sb_instagram_js_options.resized_url + this.resizedImages[id].id + 'thumb.jpg';
756
- }
757
- }
758
- if (foundSizes.indexOf(150) === -1) {
759
- if (foundSizes.indexOf(320) > -1) {
760
- srcSet[150] = sb_instagram_js_options.resized_url + this.resizedImages[id].id + 'low.jpg';
761
- } else if (foundSizes.indexOf(640) > -1) {
762
- srcSet[150] = sb_instagram_js_options.resized_url + this.resizedImages[id].id + 'full.jpg';
763
- }
764
- }
765
- }
766
- }
767
- } else if (typeof this.resizedImages[id] === 'undefined'
768
- || (typeof this.resizedImages[id]['id'] !== 'undefined' && this.resizedImages[id]['id'] !== 'pending' && this.resizedImages[id]['id'] !== 'error')) {
769
- this.addToNeedsResizing(id);
770
- }
771
-
772
- return srcSet;
773
- },
774
- getAvatarUrl: function (username,favorType) {
775
- if (username === '') {
776
- return '';
777
- }
778
-
779
- var availableAvatars = this.settings.general.avatars,
780
- favorType = typeof favorType !== 'undefined' ? favorType : 'local';
781
-
782
- if (favorType === 'local') {
783
- if (typeof availableAvatars['LCL'+username] !== 'undefined' && parseInt(availableAvatars['LCL'+username]) === 1) {
784
- return sb_instagram_js_options.resized_url + username + '.jpg';
785
- } else if (typeof availableAvatars[username] !== 'undefined') {
786
- return availableAvatars[username];
787
- } else {
788
- return '';
789
- }
790
- } else {
791
- if (typeof availableAvatars[username] !== 'undefined') {
792
- return availableAvatars[username];
793
- } else if (typeof availableAvatars['LCL'+username] !== 'undefined' && parseInt(availableAvatars['LCL'+username]) === 1) {
794
- return sb_instagram_js_options.resized_url + username + '.jpg';
795
- } else {
796
- return '';
797
- }
798
- }
799
- },
800
- addToNeedsResizing: function (id) {
801
- if (this.needsResizing.indexOf(id) === -1) {
802
- this.needsResizing.push(id);
803
- }
804
- },
805
- applyImageLiquid: function () {
806
- var $self = $(this.el),
807
- feed = this;
808
- sbiAddImgLiquid();
809
- if (typeof $self.find(".sbi_photo").sbi_imgLiquid == 'function') {
810
- $self.find(".sbi_photo").sbi_imgLiquid({fill: true});
811
- }
812
- },
813
- listenForVisibilityChange: function() {
814
- var feed = this;
815
- sbiAddVisibilityListener();
816
- if (typeof $(this.el).filter(':hidden').sbiVisibilityChanged == 'function') {
817
- //If the feed is initially hidden (in a tab for example) then check for when it becomes visible and set then set the height
818
- $(this.el).filter(':hidden').sbiVisibilityChanged({
819
- callback: function (element, visible) {
820
- feed.afterResize();
821
- },
822
- runOnLoad: false
823
- });
824
- }
825
- },
826
- getColumnCount: function() {
827
- var $self = $(this.el),
828
- cols = this.settings.cols,
829
- colsmobile = this.settings.colsmobile,
830
- returnCols = cols;
831
-
832
- sbiWindowWidth = window.innerWidth;
833
-
834
- if ($self.hasClass('sbi_mob_col_auto')) {
835
- if (sbiWindowWidth < 640 && (parseInt(cols) > 2 && parseInt(cols) < 7)) returnCols = 2;
836
- if (sbiWindowWidth < 640 && (parseInt(cols) > 6 && parseInt(cols) < 11)) returnCols = 4;
837
- if (sbiWindowWidth <= 480 && parseInt(cols) > 2) returnCols = 1;
838
- } else if (sbiWindowWidth <= 480) {
839
- returnCols = colsmobile;
840
- }
841
-
842
- return parseInt(returnCols);
843
- }
844
- };
845
-
846
- window.sbi_init = function() {
847
- window.sbi = new Sbi();
848
- window.sbi.createPage( window.sbi.createFeeds, {whenFeedsCreated: window.sbi.afterFeedsCreated});
849
- };
850
-
851
- function sbiGetNewFeed(feed,index,feedOptions) {
852
- return new SbiFeed(feed,index,feedOptions);
853
- }
854
-
855
- function sbiAjax(submitData,onSuccess) {
856
- $.ajax({
857
- url: sbiajaxurl,
858
- type: 'post',
859
- data: submitData,
860
- success: onSuccess
861
- });
862
- }
863
-
864
- })(jQuery);
865
-
866
- jQuery(document).ready(function($) {
867
- if (typeof window.sb_instagram_js_options === 'undefined') {
868
- window.sb_instagram_js_options = {
869
- font_method: "svg",
870
- resized_url: location.protocol + '//' + window.location.hostname + "/wp-content/uploads/sb-instagram-feed-images/",
871
- placeholder: location.protocol + '//' + window.location.hostname + "/wp-content/plugins/instagram-feed/img/placeholder.png"
872
- };
873
- }
874
- if (typeof window.sb_instagram_js_options.resized_url !== 'undefined' && window.sb_instagram_js_options.resized_url.indexOf(location.protocol) === -1) {
875
- if (location.protocol === 'http:') {
876
- window.sb_instagram_js_options.resized_url = window.sb_instagram_js_options.resized_url.replace('http:','https:');
877
- } else {
878
- window.sb_instagram_js_options.resized_url = window.sb_instagram_js_options.resized_url.replace('https:','http:');
879
- }
880
- }
881
- sbi_init();
882
- });
883
-
884
- } // if sbi_js_exists
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/sb-instagram-2-1.min.js DELETED
@@ -1 +0,0 @@
1
- var sbi_js_exists=void 0!==sbi_js_exists;sbi_js_exists||(!function(i){function e(){var i,e,s,t=t||{VER:"0.9.944"};t.bgs_Available=!1,t.bgs_CheckRunned=!1,function(i){i.fn.extend({sbi_imgLiquid:function(e){this.defaults={fill:!0,verticalAlign:"center",horizontalAlign:"center",useBackgroundSize:!0,useDataHtmlAttr:!0,responsive:!0,delay:0,fadeInTime:0,removeBoxBackground:!0,hardPixels:!0,responsiveCheckTime:500,timecheckvisibility:500,onStart:null,onFinish:null,onItemStart:null,onItemFinish:null,onItemError:null},function(){if(!t.bgs_CheckRunned){t.bgs_CheckRunned=!0;var e=i('<span style="background-size:cover" />');i("body").append(e),function(){var i=e[0];if(i&&window.getComputedStyle){var s=window.getComputedStyle(i,null);s&&s.backgroundSize&&(t.bgs_Available="cover"===s.backgroundSize)}}(),e.remove()}}();var s=this;return this.options=e,this.settings=i.extend({},this.defaults,this.options),this.settings.onStart&&this.settings.onStart(),this.each(function(e){function a(){(r.responsive||g.data("sbi_imgLiquid_oldProcessed"))&&g.data("sbi_imgLiquid_settings")&&(r=g.data("sbi_imgLiquid_settings"),l.actualSize=l.get(0).offsetWidth+l.get(0).offsetHeight/1e4,l.sizeOld&&l.actualSize!==l.sizeOld&&o(),l.sizeOld=l.actualSize,setTimeout(a,r.responsiveCheckTime))}function n(){g.data("sbi_imgLiquid_error",!0),l.addClass("sbi_imgLiquid_error"),r.onItemError&&r.onItemError(e,l,g),d()}function o(){var i,s,t,a,n,o,h,u,m=0,_=0,c=l.width(),f=l.height();void 0===g.data("owidth")&&g.data("owidth",g[0].width),void 0===g.data("oheight")&&g.data("oheight",g[0].height),r.fill===c/f>=g.data("owidth")/g.data("oheight")?(i="100%",s="auto",t=Math.floor(c),a=Math.floor(c*(g.data("oheight")/g.data("owidth")))):(i="auto",s="100%",t=Math.floor(f*(g.data("owidth")/g.data("oheight"))),a=Math.floor(f)),h=c-t,"left"===(n=r.horizontalAlign.toLowerCase())&&(_=0),"center"===n&&(_=.5*h),"right"===n&&(_=h),-1!==n.indexOf("%")&&((n=parseInt(n.replace("%",""),10))>0&&(_=h*n*.01)),u=f-a,"left"===(o=r.verticalAlign.toLowerCase())&&(m=0),"center"===o&&(m=.5*u),"bottom"===o&&(m=u),-1!==o.indexOf("%")&&((o=parseInt(o.replace("%",""),10))>0&&(m=u*o*.01)),r.hardPixels&&(i=t,s=a),g.css({width:i,height:s,"margin-left":Math.floor(_),"margin-top":Math.floor(m)}),g.data("sbi_imgLiquid_oldProcessed")||(g.fadeTo(r.fadeInTime,1),g.data("sbi_imgLiquid_oldProcessed",!0),r.removeBoxBackground&&l.css("background-image","none"),l.addClass("sbi_imgLiquid_nobgSize"),l.addClass("sbi_imgLiquid_ready")),r.onItemFinish&&r.onItemFinish(e,l,g),d()}function d(){e===s.length-1&&s.settings.onFinish&&s.settings.onFinish()}var r=s.settings,l=i(this),g=i("img:first",l);return g.length?(g.data("sbi_imgLiquid_settings")?(l.removeClass("sbi_imgLiquid_error").removeClass("sbi_imgLiquid_ready"),r=i.extend({},g.data("sbi_imgLiquid_settings"),s.options)):r=i.extend({},s.settings,function(){var i={};if(s.settings.useDataHtmlAttr){var e=l.attr("data-sbi_imgLiquid-fill"),a=l.attr("data-sbi_imgLiquid-horizontalAlign"),n=l.attr("data-sbi_imgLiquid-verticalAlign");("true"===e||"false"===e)&&(i.fill=Boolean("true"===e)),void 0===a||"left"!==a&&"center"!==a&&"right"!==a&&-1===a.indexOf("%")||(i.horizontalAlign=a),void 0===n||"top"!==n&&"bottom"!==n&&"center"!==n&&-1===n.indexOf("%")||(i.verticalAlign=n)}return t.isIE&&s.settings.ieFadeInDisabled&&(i.fadeInTime=0),i}()),g.data("sbi_imgLiquid_settings",r),r.onItemStart&&r.onItemStart(e,l,g),void(t.bgs_Available&&r.useBackgroundSize?(-1===l.css("background-image").indexOf(encodeURI(g.attr("src")))&&l.css({"background-image":'url("'+encodeURI(g.attr("src"))+'")'}),l.css({"background-size":r.fill?"cover":"contain","background-position":(r.horizontalAlign+" "+r.verticalAlign).toLowerCase(),"background-repeat":"no-repeat"}),i("a:first",l).css({display:"block",width:"100%",height:"100%"}),i("img",l).css({display:"none"}),r.onItemFinish&&r.onItemFinish(e,l,g),l.addClass("sbi_imgLiquid_bgSize"),l.addClass("sbi_imgLiquid_ready"),d()):function s(){if(g.data("oldSrc")&&g.data("oldSrc")!==g.attr("src")){var t=g.clone().removeAttr("style");return t.data("sbi_imgLiquid_settings",g.data("sbi_imgLiquid_settings")),g.parent().prepend(t),g.remove(),(g=t)[0].width=0,void setTimeout(s,10)}return g.data("sbi_imgLiquid_oldProcessed")?void o():(g.data("sbi_imgLiquid_oldProcessed",!1),g.data("oldSrc",g.attr("src")),i("img:not(:first)",l).css("display","none"),l.css({overflow:"hidden"}),g.fadeTo(0,0).removeAttr("width").removeAttr("height").css({visibility:"visible","max-width":"none","max-height":"none",width:"auto",height:"auto",display:"block"}),g.on("error",n),g[0].onerror=n,function i(){g.data("sbi_imgLiquid_error")||g.data("sbi_imgLiquid_loaded")||g.data("sbi_imgLiquid_oldProcessed")||(l.is(":visible")&&g[0].complete&&g[0].width>0&&g[0].height>0?(g.data("sbi_imgLiquid_loaded",!0),setTimeout(o,e*r.delay)):setTimeout(i,r.timecheckvisibility))}(),void a())}())):void n()})}})}(jQuery),i=t.injectCss,e=document.getElementsByTagName("head")[0],(s=document.createElement("style")).type="text/css",s.styleSheet?s.styleSheet.cssText=i:s.appendChild(document.createTextNode(i)),e.appendChild(s)}function s(){this.feeds={},this.options=sb_instagram_js_options}function t(i,e,s){this.el=i,this.index=e,this.settings=s,this.minImageWidth=0,this.imageResolution=150,this.resizedImages={},this.needsResizing=[],this.outOfPages=!1,this.isInitialized=!1}function a(e,s){i.ajax({url:sbiajaxurl,type:"post",data:e,success:s})}s.prototype={createPage:function(e,s){void 0!==window.sbiajaxurl&&-1!==window.sbiajaxurl.indexOf(window.location.hostname)||(window.sbiajaxurl=location.protocol+"//"+window.location.hostname+"/wp-admin/admin-ajax.php"),i(".sbi_no_js_error_message").remove(),i(".sbi_no_js").removeClass("sbi_no_js"),e(s)},createFeeds:function(e){e.whenFeedsCreated(i(".sbi").each(function(e){i(this).attr("data-sbi-index",e+1);var s=i(this),n=void 0!==s.attr("data-sbi-flags")?s.attr("data-sbi-flags").split(","):[],o=void 0!==s.attr("data-options")?JSON.parse(s.attr("data-options")):{};if(n.indexOf("testAjax")>-1){window.sbi.triggeredTest=!0;a({action:"sbi_on_ajax_test_trigger"},function(i){console.log("did test")})}var d={cols:s.attr("data-cols"),colsmobile:"same"!==s.attr("data-colsmobile")?s.attr("data-colsmobile"):s.attr("data-cols"),num:s.attr("data-num"),imgRes:s.attr("data-res"),feedID:s.attr("data-feedid"),shortCodeAtts:s.attr("data-shortcode-atts"),resizingEnabled:-1===n.indexOf("resizeDisable"),imageLoadEnabled:-1===n.indexOf("imageLoadDisable"),debugEnabled:n.indexOf("debug")>-1,favorLocal:n.indexOf("favorLocal")>-1,ajaxPostLoad:n.indexOf("ajaxPostLoad")>-1,autoMinRes:1,general:o};window.sbi.feeds[e]=function(i,e,s){return new t(i,e,s)}(this,e,d),window.sbi.feeds[e].setResizedImages(),window.sbi.feeds[e].init();var r=jQuery.Event("sbiafterfeedcreate");r.feed=window.sbi.feeds[e],jQuery(window).trigger(r)}))},afterFeedsCreated:function(){i(".sb_instagram_header").each(function(){var e=i(this);e.find(".sbi_header_link").hover(function(){e.find(".sbi_header_img_hover").addClass("sbi_fade_in")},function(){e.find(".sbi_header_img_hover").removeClass("sbi_fade_in")})})},encodeHTML:function(i){return void 0===i?"":i.replace(/(>)/g,"&gt;").replace(/(<)/g,"&lt;").replace(/(&lt;br\/&gt;)/g,"<br>").replace(/(&lt;br&gt;)/g,"<br>")},urlDetect:function(i){return i.match(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)/g)}},t.prototype={init:function(){var i=this;this.settings.ajaxPostLoad?this.getNewPostSet():this.afterInitialImagesLoaded();var e,s=(e=0,function(i,s){clearTimeout(e),e=setTimeout(i,s)});jQuery(window).resize(function(){s(function(){i.afterResize()},500)})},initLayout:function(){},afterInitialImagesLoaded:function(){this.initLayout(),this.loadMoreButtonInit(),this.hideExtraImagesForWidth(),this.beforeNewImagesRevealed(),this.revealNewImages(),this.afterNewImagesRevealed()},afterResize:function(){this.setImageHeight(),this.setImageResolution(),this.maybeRaiseImageResolution(),this.setImageSizeClass()},afterLoadMoreClicked:function(i){i.find(".sbi_loader").removeClass("sbi_hidden"),i.find(".sbi_btn_text").addClass("sbi_hidden"),i.closest(".sbi").find(".sbi_num_diff_hide").addClass("sbi_transition").removeClass("sbi_num_diff_hide")},afterNewImagesLoaded:function(){var e=i(this.el),s=this;this.beforeNewImagesRevealed(),this.revealNewImages(),this.afterNewImagesRevealed(),setTimeout(function(){e.find(".sbi_loader").addClass("sbi_hidden"),e.find(".sbi_btn_text").removeClass("sbi_hidden"),s.maybeRaiseImageResolution()},500)},beforeNewImagesRevealed:function(){this.setImageHeight(),this.maybeRaiseImageResolution(!0),this.setImageSizeClass()},revealNewImages:function(){var e=i(this.el);"function"==typeof sbi_custom_js&&setTimeout(function(){sbi_custom_js()},100),this.applyImageLiquid(),e.find(".sbi_item").each(function(i){jQuery(this).find(".sbi_photo").hover(function(){jQuery(this).fadeTo(200,.85)},function(){jQuery(this).stop().fadeTo(500,1)})}),setTimeout(function(){jQuery("#sbi_images .sbi_item.sbi_new").removeClass("sbi_new");var i=10;e.find(".sbi_transition").each(function(){var e=jQuery(this);setTimeout(function(){e.removeClass("sbi_transition")},i),i+=10})},500)},afterNewImagesRevealed:function(){this.listenForVisibilityChange(),this.sendNeedsResizingToServer(),this.settings.imageLoadEnabled||i(".sbi_no_resraise").removeClass("sbi_no_resraise");var e=i.Event("sbiafterimagesloaded");e.el=i(this.el),i(window).trigger(e)},setResizedImages:function(){i(this.el).find(".sbi_resized_image_data").length&&void 0!==i(this.el).find(".sbi_resized_image_data").attr("data-resized")&&0===i(this.el).find(".sbi_resized_image_data").attr("data-resized").indexOf('{"')&&(this.resizedImages=JSON.parse(i(this.el).find(".sbi_resized_image_data").attr("data-resized")),i(this.el).find(".sbi_resized_image_data").remove())},sendNeedsResizingToServer:function(){var e=this;if(e.needsResizing.length>0&&e.settings.resizingEnabled){var s=i(this.el).find(".sbi_item").length;a({action:"sbi_resized_images_submit",needs_resizing:e.needsResizing,offset:s,feed_id:e.settings.feedID,atts:e.settings.shortCodeAtts},function(i){if(0===i.trim().indexOf("{")){var s=JSON.parse(i);e.settings.debugEnabled&&console.log(s)}})}},loadMoreButtonInit:function(){var e=i(this.el),s=this;e.find("#sbi_load .sbi_load_btn").off().on("click",function(){s.afterLoadMoreClicked(jQuery(this)),s.getNewPostSet()})},getNewPostSet:function(){var e=i(this.el),s=this;a({action:"sbi_load_more_clicked",offset:e.find(".sbi_item").length,feed_id:s.settings.feedID,atts:s.settings.shortCodeAtts,current_resolution:s.imageResolution},function(t){if(0===t.trim().indexOf("{")){var a=JSON.parse(t);s.settings.debugEnabled&&console.log(a),s.appendNewPosts(a.html),s.addResizedImages(a.resizedImages),s.settings.ajaxPostLoad?(s.settings.ajaxPostLoad=!1,s.afterInitialImagesLoaded()):s.afterNewImagesLoaded(),a.feedStatus.shouldPaginate?s.outOfPages=!1:(s.outOfPages=!0,e.find(".sbi_load_btn").hide()),i(".sbi_no_js").removeClass("sbi_no_js")}})},appendNewPosts:function(e){var s=i(this.el);s.find("#sbi_images .sbi_item").length?s.find("#sbi_images .sbi_item").last().after(e):s.find("#sbi_images").append(e)},addResizedImages:function(i){for(var e in i)this.resizedImages[e]=i[e]},setImageHeight:function(){var e=i(this.el),s=e.find(".sbi_photo").eq(0).innerWidth(),t=this.getColumnCount(),a=e.find("#sbi_images").innerWidth()-e.find("#sbi_images").width(),n=a/2;sbi_photo_width_manual=e.find("#sbi_images").width()/t-a,e.find(".sbi_photo").css("height",s),e.find(".sbi-owl-nav").length&&setTimeout(function(){var i=2;e.find(".sbi_owl2row-item").length&&(i=1);var s=e.find(".sbi_photo").eq(0).innerWidth()/i;s+=parseInt(n)*(2-i+2),e.find(".sbi-owl-nav div").css("top",s)},100)},maybeRaiseSingleImageResolution:function(e,s,t){var a=this,n=a.getImageUrls(e),o=e.find(".sbi_photo img").attr("src"),d=150,r=e.find("img").get(0),l=o===window.sbi.options.placeholder?1:r.naturalWidth/r.naturalHeight;t=void 0!==t&&t;if(!(e.hasClass("sbi_no_resraise")||e.hasClass("sbi_had_error")||e.find(".sbi_link_area").length&&e.find(".sbi_link_area").hasClass("sbi_had_error"))){i.each(n,function(i,e){e===o&&(d=parseInt(i),t=!1)});var g=640;switch(a.settings.imgRes){case"thumb":g=150;break;case"medium":g=320;break;case"full":g=640;break;default:var h=Math.max(a.settings.autoMinRes,e.find(".sbi_photo").innerWidth()),u=a.getBestResolutionForAuto(h,l,e);switch(u){case 320:g=320;break;case 150:g=150}}if(g>d||o===window.sbi.options.placeholder||t){if(a.settings.debugEnabled){var m=o===window.sbi.options.placeholder?"was placeholder":"too small";console.log("rais res for "+o,m)}var _=n[g].split("?ig_cache_key")[0];if(e.find(".sbi_photo img").attr("src",_),e.find(".sbi_photo").css("background-image",'url("'+_+'")'),d=g,"auto"===a.settings.imgRes){var c=!1;e.find(".sbi_photo img").on("load",function(){var s=i(this),t=s.get(0).naturalWidth/s.get(0).naturalHeight;if(1e3!==s.get(0).naturalWidth&&t>l&&!c){switch(a.settings.debugEnabled&&console.log("rais res again for aspect ratio change "+o),c=!0,h=e.find(".sbi_photo").innerWidth(),u=a.getBestResolutionForAuto(h,t,e),g=640,u){case 320:g=320;break;case 150:g=150}g>d&&(_=n[g].split("?ig_cache_key")[0],s.attr("src",_),s.closest(".sbi_photo").css("background-image",'url("'+_+'")')),"masonry"!==a.layout&&"highlight"!==a.layout||(i(a.el).find("#sbi_images").smashotope(a.isotopeArgs),setTimeout(function(){i(a.el).find("#sbi_images").smashotope(a.isotopeArgs)},500))}else if(a.settings.debugEnabled){var r=c?"already checked":"no aspect ratio change";console.log("not raising res for replacement "+o,r)}})}}e.find("img").on("error",function(){if(i(this).hasClass("sbi_img_error"))console.log("unfixed error "+i(this).attr("src"));else{var e;if(i(this).addClass("sbi_img_error"),i(this).attr("src").indexOf("media?size=")>-1||i(this).attr("src").indexOf("cdninstagram")>-1||i(this).attr("src").indexOf("fbcdn")>-1)a.settings.favorLocal=!0,void 0!==(e=a.getImageUrls(i(this).closest(".sbi_item")))[640]&&(i(this).attr("src",e[640]),i(this).closest(".sbi_photo").css("background-image","url("+e[640]+")"),i(this).closest(".sbi_item").addClass("sbi_had_error").find(".sbi_link_area").attr("href",e[640]).addClass("sbi_had_error"));else if("undefined"!==i(this).closest(".sbi_photo").attr("data-img-src-set"))void 0!==(e=JSON.parse(i(this).closest(".sbi_photo").attr("data-img-src-set").replace(/\\\//g,"/"))).d&&(i(this).attr("src",e.d),i(this).closest(".sbi_photo").css("background-image","url("+e.d+")"),i(this).closest(".sbi_item").addClass("sbi_had_error").find(".sbi_link_area").attr("href",e[640]).addClass("sbi_had_error"));setTimeout(function(){a.afterResize()},1500)}})}},maybeRaiseImageResolution:function(e){var s=this,t=void 0!==e&&!0===e?".sbi_item.sbi_new":".sbi_item",a=!s.isInitialized;i(s.el).find(t).each(function(e){!i(this).hasClass("sbi_num_diff_hide")&&i(this).find(".sbi_photo").length&&void 0!==i(this).find(".sbi_photo").attr("data-img-src-set")&&s.maybeRaiseSingleImageResolution(i(this),e,a)}),s.isInitialized=!0},getBestResolutionForAuto:function(e,s,t){(isNaN(s)||s<1)&&(s=1);var a=e*s,n=10*Math.ceil(a/10),o=[150,320,640];if(t.hasClass("sbi_highlighted")&&(n*=2),-1===o.indexOf(parseInt(n))){var d=!1;i.each(o,function(i,e){e>parseInt(n)&&!d&&(n=e,d=!0)})}return n},hideExtraImagesForWidth:function(){if("carousel"!==this.layout){var e=i(this.el),s=void 0!==e.attr("data-num")&&""!==e.attr("data-num")?parseInt(e.attr("data-num")):1,t=void 0!==e.attr("data-nummobile")&&""!==e.attr("data-nummobile")?parseInt(e.attr("data-nummobile")):s;i(window).width()<480?t<e.find(".sbi_item").length&&e.find(".sbi_item").slice(t-e.find(".sbi_item").length).addClass("sbi_num_diff_hide"):s<e.find(".sbi_item").length&&e.find(".sbi_item").slice(s-e.find(".sbi_item").length).addClass("sbi_num_diff_hide")}},setImageSizeClass:function(){var e=i(this.el);e.removeClass("sbi_small sbi_medium");var s=e.innerWidth(),t=parseInt(e.find("#sbi_images").outerWidth()-e.find("#sbi_images").width())/2,a=this.getColumnCount(),n=(s-t*(a+2))/a;n>120&&n<240?e.addClass("sbi_medium"):n<=120&&e.addClass("sbi_small")},setMinImageWidth:function(){i(this.el).find(".sbi_item .sbi_photo").first().length?this.minImageWidth=i(this.el).find(".sbi_item .sbi_photo").first().innerWidth():this.minImageWidth=150},setImageResolution:function(){if("auto"===this.settings.imgRes)this.imageResolution="auto";else switch(this.settings.imgRes){case"thumb":this.imageResolution=150;break;case"medium":this.imageResolution=320;break;default:this.imageResolution=640}},getImageUrls:function(i){var e=JSON.parse(i.find(".sbi_photo").attr("data-img-src-set").replace(/\\\//g,"/")),s=i.attr("id").replace("sbi_","");if(void 0!==this.resizedImages[s]&&"video"!==this.resizedImages[s]&&"pending"!==this.resizedImages[s]&&"error"!==this.resizedImages[s].id&&"video"!==this.resizedImages[s].id&&"pending"!==this.resizedImages[s].id){if(void 0!==this.resizedImages[s].sizes){var t=[];void 0!==this.resizedImages[s].sizes.full&&(e[640]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"full.jpg",t.push(640)),void 0!==this.resizedImages[s].sizes.low&&(e[320]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"low.jpg",t.push(320)),void 0!==this.resizedImages[s].sizes.thumb&&(t.push(150),e[150]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"thumb.jpg"),this.settings.favorLocal&&(-1===t.indexOf(640)&&t.indexOf(320)>-1&&(e[640]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"low.jpg"),-1===t.indexOf(320)&&(t.indexOf(640)>-1?e[320]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"full.jpg":t.indexOf(150)>-1&&(e[320]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"thumb.jpg")),-1===t.indexOf(150)&&(t.indexOf(320)>-1?e[150]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"low.jpg":t.indexOf(640)>-1&&(e[150]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"full.jpg")))}}else(void 0===this.resizedImages[s]||void 0!==this.resizedImages[s].id&&"pending"!==this.resizedImages[s].id&&"error"!==this.resizedImages[s].id)&&this.addToNeedsResizing(s);return e},getAvatarUrl:function(i,e){if(""===i)return"";var s=this.settings.general.avatars;return"local"===(e=void 0!==e?e:"local")?void 0!==s["LCL"+i]&&1===parseInt(s["LCL"+i])?sb_instagram_js_options.resized_url+i+".jpg":void 0!==s[i]?s[i]:"":void 0!==s[i]?s[i]:void 0!==s["LCL"+i]&&1===parseInt(s["LCL"+i])?sb_instagram_js_options.resized_url+i+".jpg":""},addToNeedsResizing:function(i){-1===this.needsResizing.indexOf(i)&&this.needsResizing.push(i)},applyImageLiquid:function(){var s=i(this.el);e(),"function"==typeof s.find(".sbi_photo").sbi_imgLiquid&&s.find(".sbi_photo").sbi_imgLiquid({fill:!0})},listenForVisibilityChange:function(){var e,s,t,a=this;e=jQuery,s={callback:function(){},runOnLoad:!0,frequency:100,sbiPreviousVisibility:null},t={sbiCheckVisibility:function(i,e){if(jQuery.contains(document,i[0])){var s=e.sbiPreviousVisibility,a=i.is(":visible");e.sbiPreviousVisibility=a,null==s?e.runOnLoad&&e.callback(i,a):s!==a&&e.callback(i,a),setTimeout(function(){t.sbiCheckVisibility(i,e)},e.frequency)}}},e.fn.sbiVisibilityChanged=function(i){var a=e.extend({},s,i);return this.each(function(){t.sbiCheckVisibility(e(this),a)})},"function"==typeof i(this.el).filter(":hidden").sbiVisibilityChanged&&i(this.el).filter(":hidden").sbiVisibilityChanged({callback:function(i,e){a.afterResize()},runOnLoad:!1})},getColumnCount:function(){var e=i(this.el),s=this.settings.cols,t=this.settings.colsmobile,a=s;return sbiWindowWidth=window.innerWidth,e.hasClass("sbi_mob_col_auto")?(sbiWindowWidth<640&&parseInt(s)>2&&parseInt(s)<7&&(a=2),sbiWindowWidth<640&&parseInt(s)>6&&parseInt(s)<11&&(a=4),sbiWindowWidth<=480&&parseInt(s)>2&&(a=1)):sbiWindowWidth<=480&&(a=t),parseInt(a)}},window.sbi_init=function(){window.sbi=new s,window.sbi.createPage(window.sbi.createFeeds,{whenFeedsCreated:window.sbi.afterFeedsCreated})}}(jQuery),jQuery(document).ready(function(i){void 0===window.sb_instagram_js_options&&(window.sb_instagram_js_options={font_method:"svg",resized_url:location.protocol+"//"+window.location.hostname+"/wp-content/uploads/sb-instagram-feed-images/",placeholder:location.protocol+"//"+window.location.hostname+"/wp-content/plugins/instagram-feed/img/placeholder.png"}),void 0!==window.sb_instagram_js_options.resized_url&&-1===window.sb_instagram_js_options.resized_url.indexOf(location.protocol)&&("http:"===location.protocol?window.sb_instagram_js_options.resized_url=window.sb_instagram_js_options.resized_url.replace("http:","https:"):window.sb_instagram_js_options.resized_url=window.sb_instagram_js_options.resized_url.replace("https:","http:")),sbi_init()}));
 
js/sb-instagram-2-2.js CHANGED
@@ -289,8 +289,6 @@ if(!sbi_js_exists) {
289
  $(this.el).find('.sbi_item').each(function() {
290
  feed.lazyLoadCheck($(this));
291
  });
292
-
293
-
294
  },
295
  initLayout: function() {
296
 
@@ -677,7 +675,7 @@ if(!sbi_js_exists) {
677
  $(this).addClass('sbi_img_error');
678
  var sourceFromAPI = ($(this).attr('src').indexOf('media/?size=') > -1 || $(this).attr('src').indexOf('cdninstagram') > -1 || $(this).attr('src').indexOf('fbcdn') > -1)
679
 
680
- if (!sourceFromAPI) {
681
 
682
  if ($(this).closest('.sbi_photo').attr('data-img-src-set') !== 'undefined') {
683
  var srcSet = JSON.parse($(this).closest('.sbi_photo').attr('data-img-src-set').replace(/\\\//g, '/'));
@@ -946,6 +944,8 @@ if(!sbi_js_exists) {
946
  this.settings.consentGiven = sbiCmplzGetCookie('complianz_consent_status') === 'allow';
947
  } else if (typeof window.Cookiebot !== "undefined") { // Cookiebot by Cybot A/S
948
  this.settings.consentGiven = Cookiebot.consented;
 
 
949
  }
950
 
951
  var evt = jQuery.Event('sbicheckconsent');
@@ -1069,6 +1069,14 @@ if(!sbi_js_exists) {
1069
  window.sbi.feeds[ index ].afterConsentToggled();
1070
  });
1071
  });
 
 
 
 
 
 
 
 
1072
  });
1073
 
1074
  } // if sbi_js_exists
289
  $(this.el).find('.sbi_item').each(function() {
290
  feed.lazyLoadCheck($(this));
291
  });
 
 
292
  },
293
  initLayout: function() {
294
 
675
  $(this).addClass('sbi_img_error');
676
  var sourceFromAPI = ($(this).attr('src').indexOf('media/?size=') > -1 || $(this).attr('src').indexOf('cdninstagram') > -1 || $(this).attr('src').indexOf('fbcdn') > -1)
677
 
678
+ if (!sourceFromAPI && feed.settings.consentGiven) {
679
 
680
  if ($(this).closest('.sbi_photo').attr('data-img-src-set') !== 'undefined') {
681
  var srcSet = JSON.parse($(this).closest('.sbi_photo').attr('data-img-src-set').replace(/\\\//g, '/'));
944
  this.settings.consentGiven = sbiCmplzGetCookie('complianz_consent_status') === 'allow';
945
  } else if (typeof window.Cookiebot !== "undefined") { // Cookiebot by Cybot A/S
946
  this.settings.consentGiven = Cookiebot.consented;
947
+ } else if (typeof window.BorlabsCookie !== 'undefined') { // Borlabs Cookie by Borlabs
948
+ this.settings.consentGiven = window.BorlabsCookie.checkCookieConsent('instagram');
949
  }
950
 
951
  var evt = jQuery.Event('sbicheckconsent');
1069
  window.sbi.feeds[ index ].afterConsentToggled();
1070
  });
1071
  });
1072
+
1073
+ // Borlabs Cookie by Borlabs
1074
+ $(document).on('borlabs-cookie-consent-saved', function (event) {
1075
+ $.each(window.sbi.feeds,function(index){
1076
+ window.sbi.feeds[ index ].settings.consentGiven = false;
1077
+ window.sbi.feeds[ index ].afterConsentToggled();
1078
+ });
1079
+ });
1080
  });
1081
 
1082
  } // if sbi_js_exists
js/sb-instagram-2-2.min.js CHANGED
@@ -1 +1 @@
1
- var sbi_js_exists=void 0!==sbi_js_exists;sbi_js_exists||(!function(i){function e(){var i,e,t,s=s||{VER:"0.9.944"};s.bgs_Available=!1,s.bgs_CheckRunned=!1,function(i){i.fn.extend({sbi_imgLiquid:function(e){this.defaults={fill:!0,verticalAlign:"center",horizontalAlign:"center",useBackgroundSize:!0,useDataHtmlAttr:!0,responsive:!0,delay:0,fadeInTime:0,removeBoxBackground:!0,hardPixels:!0,responsiveCheckTime:500,timecheckvisibility:500,onStart:null,onFinish:null,onItemStart:null,onItemFinish:null,onItemError:null},function(){if(!s.bgs_CheckRunned){s.bgs_CheckRunned=!0;var e=i('<span style="background-size:cover" />');i("body").append(e),function(){var i=e[0];if(i&&window.getComputedStyle){var t=window.getComputedStyle(i,null);t&&t.backgroundSize&&(s.bgs_Available="cover"===t.backgroundSize)}}(),e.remove()}}();var t=this;return this.options=e,this.settings=i.extend({},this.defaults,this.options),this.settings.onStart&&this.settings.onStart(),this.each(function(e){function n(){(r.responsive||h.data("sbi_imgLiquid_oldProcessed"))&&h.data("sbi_imgLiquid_settings")&&(r=h.data("sbi_imgLiquid_settings"),l.actualSize=l.get(0).offsetWidth+l.get(0).offsetHeight/1e4,l.sizeOld&&l.actualSize!==l.sizeOld&&o(),l.sizeOld=l.actualSize,setTimeout(n,r.responsiveCheckTime))}function a(){h.data("sbi_imgLiquid_error",!0),l.addClass("sbi_imgLiquid_error"),r.onItemError&&r.onItemError(e,l,h),d()}function o(){var i,t,s,n,a,o,g,c,f=0,u=0,b=l.width(),_=l.height();void 0===h.data("owidth")&&h.data("owidth",h[0].width),void 0===h.data("oheight")&&h.data("oheight",h[0].height),r.fill===b/_>=h.data("owidth")/h.data("oheight")?(i="100%",t="auto",s=Math.floor(b),n=Math.floor(b*(h.data("oheight")/h.data("owidth")))):(i="auto",t="100%",s=Math.floor(_*(h.data("owidth")/h.data("oheight"))),n=Math.floor(_)),g=b-s,"left"===(a=r.horizontalAlign.toLowerCase())&&(u=0),"center"===a&&(u=.5*g),"right"===a&&(u=g),-1!==a.indexOf("%")&&((a=parseInt(a.replace("%",""),10))>0&&(u=g*a*.01)),c=_-n,"left"===(o=r.verticalAlign.toLowerCase())&&(f=0),"center"===o&&(f=.5*c),"bottom"===o&&(f=c),-1!==o.indexOf("%")&&((o=parseInt(o.replace("%",""),10))>0&&(f=c*o*.01)),r.hardPixels&&(i=s,t=n),h.css({width:i,height:t,"margin-left":Math.floor(u),"margin-top":Math.floor(f)}),h.data("sbi_imgLiquid_oldProcessed")||(h.fadeTo(r.fadeInTime,1),h.data("sbi_imgLiquid_oldProcessed",!0),r.removeBoxBackground&&l.css("background-image","none"),l.addClass("sbi_imgLiquid_nobgSize"),l.addClass("sbi_imgLiquid_ready")),r.onItemFinish&&r.onItemFinish(e,l,h),d()}function d(){e===t.length-1&&t.settings.onFinish&&t.settings.onFinish()}var r=t.settings,l=i(this),h=i("img:first",l);return h.length?(h.data("sbi_imgLiquid_settings")?(l.removeClass("sbi_imgLiquid_error").removeClass("sbi_imgLiquid_ready"),r=i.extend({},h.data("sbi_imgLiquid_settings"),t.options)):r=i.extend({},t.settings,function(){var i={};if(t.settings.useDataHtmlAttr){var e=l.attr("data-sbi_imgLiquid-fill"),n=l.attr("data-sbi_imgLiquid-horizontalAlign"),a=l.attr("data-sbi_imgLiquid-verticalAlign");("true"===e||"false"===e)&&(i.fill=Boolean("true"===e)),void 0===n||"left"!==n&&"center"!==n&&"right"!==n&&-1===n.indexOf("%")||(i.horizontalAlign=n),void 0===a||"top"!==a&&"bottom"!==a&&"center"!==a&&-1===a.indexOf("%")||(i.verticalAlign=a)}return s.isIE&&t.settings.ieFadeInDisabled&&(i.fadeInTime=0),i}()),h.data("sbi_imgLiquid_settings",r),r.onItemStart&&r.onItemStart(e,l,h),void(s.bgs_Available&&r.useBackgroundSize?(-1===l.css("background-image").indexOf(encodeURI(h.attr("src")))&&l.css({"background-image":'url("'+encodeURI(h.attr("src"))+'")'}),l.css({"background-size":r.fill?"cover":"contain","background-position":(r.horizontalAlign+" "+r.verticalAlign).toLowerCase(),"background-repeat":"no-repeat"}),i("a:first",l).css({display:"block",width:"100%",height:"100%"}),i("img",l).css({display:"none"}),r.onItemFinish&&r.onItemFinish(e,l,h),l.addClass("sbi_imgLiquid_bgSize"),l.addClass("sbi_imgLiquid_ready"),d()):function t(){if(h.data("oldSrc")&&h.data("oldSrc")!==h.attr("src")){var s=h.clone().removeAttr("style");return s.data("sbi_imgLiquid_settings",h.data("sbi_imgLiquid_settings")),h.parent().prepend(s),h.remove(),(h=s)[0].width=0,void setTimeout(t,10)}return h.data("sbi_imgLiquid_oldProcessed")?void o():(h.data("sbi_imgLiquid_oldProcessed",!1),h.data("oldSrc",h.attr("src")),i("img:not(:first)",l).css("display","none"),l.css({overflow:"hidden"}),h.fadeTo(0,0).removeAttr("width").removeAttr("height").css({visibility:"visible","max-width":"none","max-height":"none",width:"auto",height:"auto",display:"block"}),h.on("error",a),h[0].onerror=a,function i(){h.data("sbi_imgLiquid_error")||h.data("sbi_imgLiquid_loaded")||h.data("sbi_imgLiquid_oldProcessed")||(l.is(":visible")&&h[0].complete&&h[0].width>0&&h[0].height>0?(h.data("sbi_imgLiquid_loaded",!0),setTimeout(o,e*r.delay)):setTimeout(i,r.timecheckvisibility))}(),void n())}())):void a()})}})}(jQuery),i=s.injectCss,e=document.getElementsByTagName("head")[0],(t=document.createElement("style")).type="text/css",t.styleSheet?t.styleSheet.cssText=i:t.appendChild(document.createTextNode(i)),e.appendChild(t)}function t(){this.feeds={},this.options=sb_instagram_js_options}function s(i,e,t){this.el=i,this.index=e,this.settings=t,this.minImageWidth=0,this.imageResolution=150,this.resizedImages={},this.needsResizing=[],this.outOfPages=!1,this.isInitialized=!1}function n(e,t){i.ajax({url:sbiajaxurl,type:"post",data:e,success:t})}t.prototype={createPage:function(e,t){void 0!==window.sbiajaxurl&&-1!==window.sbiajaxurl.indexOf(window.location.hostname)||(window.sbiajaxurl=location.protocol+"//"+window.location.hostname+"/wp-admin/admin-ajax.php"),i(".sbi_no_js_error_message").remove(),i(".sbi_no_js").removeClass("sbi_no_js"),e(t)},createFeeds:function(e){e.whenFeedsCreated(i(".sbi").each(function(e){i(this).attr("data-sbi-index",e+1);var t=i(this),a=void 0!==t.attr("data-sbi-flags")?t.attr("data-sbi-flags").split(","):[],o=void 0!==t.attr("data-options")?JSON.parse(t.attr("data-options")):{};if(a.indexOf("testAjax")>-1){window.sbi.triggeredTest=!0;n({action:"sbi_on_ajax_test_trigger"},function(i){console.log("did test")})}var d={cols:t.attr("data-cols"),colsmobile:void 0!==t.attr("data-colsmobile")&&"same"!==t.attr("data-colsmobile")?t.attr("data-colsmobile"):t.attr("data-cols"),num:t.attr("data-num"),imgRes:t.attr("data-res"),feedID:t.attr("data-feedid"),shortCodeAtts:t.attr("data-shortcode-atts"),resizingEnabled:-1===a.indexOf("resizeDisable"),imageLoadEnabled:-1===a.indexOf("imageLoadDisable"),debugEnabled:a.indexOf("debug")>-1,favorLocal:a.indexOf("favorLocal")>-1,ajaxPostLoad:a.indexOf("ajaxPostLoad")>-1,gdpr:a.indexOf("gdpr")>-1,overrideBlockCDN:a.indexOf("overrideBlockCDN")>-1,consentGiven:!1,autoMinRes:1,general:o};window.sbi.feeds[e]=function(i,e,t){return new s(i,e,t)}(this,e,d),window.sbi.feeds[e].setResizedImages(),window.sbi.feeds[e].init();var r=jQuery.Event("sbiafterfeedcreate");r.feed=window.sbi.feeds[e],jQuery(window).trigger(r)}))},afterFeedsCreated:function(){i(".sb_instagram_header").each(function(){var e=i(this);e.find(".sbi_header_link").hover(function(){e.find(".sbi_header_img_hover").addClass("sbi_fade_in")},function(){e.find(".sbi_header_img_hover").removeClass("sbi_fade_in")})})},encodeHTML:function(i){return void 0===i?"":i.replace(/(>)/g,"&gt;").replace(/(<)/g,"&lt;").replace(/(&lt;br\/&gt;)/g,"<br>").replace(/(&lt;br&gt;)/g,"<br>")},urlDetect:function(i){return i.match(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)/g)}},s.prototype={init:function(){var e=this;e.settings.consentGiven=e.checkConsent(),i(this.el).find(".sbi_photo").parent("p").length&&i(this.el).addClass("sbi_no_autop"),i(this.el).find("#sbi_mod_error").length&&i(this.el).prepend(i(this.el).find("#sbi_mod_error")),this.settings.ajaxPostLoad?this.getNewPostSet():this.afterInitialImagesLoaded();var t,s=(t=0,function(i,e){clearTimeout(t),t=setTimeout(i,e)});jQuery(window).resize(function(){s(function(){e.afterResize()},500)}),i(this.el).find(".sbi_item").each(function(){e.lazyLoadCheck(i(this))})},initLayout:function(){},afterInitialImagesLoaded:function(){this.initLayout(),this.loadMoreButtonInit(),this.hideExtraImagesForWidth(),this.beforeNewImagesRevealed(),this.revealNewImages(),this.afterNewImagesRevealed()},afterResize:function(){this.setImageHeight(),this.setImageResolution(),this.maybeRaiseImageResolution(),this.setImageSizeClass()},afterLoadMoreClicked:function(i){i.find(".sbi_loader").removeClass("sbi_hidden"),i.find(".sbi_btn_text").addClass("sbi_hidden"),i.closest(".sbi").find(".sbi_num_diff_hide").addClass("sbi_transition").removeClass("sbi_num_diff_hide")},afterNewImagesLoaded:function(){var e=i(this.el),t=this;this.beforeNewImagesRevealed(),this.revealNewImages(),this.afterNewImagesRevealed(),setTimeout(function(){e.find(".sbi_loader").addClass("sbi_hidden"),e.find(".sbi_btn_text").removeClass("sbi_hidden"),t.maybeRaiseImageResolution()},500)},beforeNewImagesRevealed:function(){this.setImageHeight(),this.maybeRaiseImageResolution(!0),this.setImageSizeClass()},revealNewImages:function(){var e=i(this.el);e.find(".sbi-screenreader").each(function(){i(this).find("img").remove()}),"function"==typeof sbi_custom_js&&setTimeout(function(){sbi_custom_js()},100),this.applyImageLiquid(),e.find(".sbi_item").each(function(i){jQuery(this).find(".sbi_photo").hover(function(){jQuery(this).fadeTo(200,.85)},function(){jQuery(this).stop().fadeTo(500,1)})}),setTimeout(function(){jQuery("#sbi_images .sbi_item.sbi_new").removeClass("sbi_new");var i=10;e.find(".sbi_transition").each(function(){var e=jQuery(this);setTimeout(function(){e.removeClass("sbi_transition")},i),i+=10})},500)},lazyLoadCheck:function(e){if(e.find(".sbi_photo").length&&!e.closest(".sbi").hasClass("sbi-no-ll-check")){var t=this.getImageUrls(e),s=void 0!==t[640]?t[640]:e.find(".sbi_photo").attr("data-full-res");if(!this.settings.consentGiven&&s.indexOf("scontent")>-1)return;e.find(".sbi_photo img").each(function(){s&&void 0!==i(this).attr("data-src")&&i(this).attr("data-src",s),s&&void 0!==i(this).attr("data-orig-src")&&i(this).attr("data-orig-src",s),i(this).on("load",function(){!i(this).hasClass("sbi-replaced")&&i(this).attr("src").indexOf("placeholder")>-1&&(i(this).addClass("sbi-replaced"),s&&(i(this).attr("src",s),i(this).closest(".sbi_imgLiquid_bgSize").length&&i(this).closest(".sbi_imgLiquid_bgSize").css("background-image","url("+s+")")))})})}},afterNewImagesRevealed:function(){this.listenForVisibilityChange(),this.sendNeedsResizingToServer(),this.settings.imageLoadEnabled||i(".sbi_no_resraise").removeClass("sbi_no_resraise");var e=i.Event("sbiafterimagesloaded");e.el=i(this.el),i(window).trigger(e)},setResizedImages:function(){i(this.el).find(".sbi_resized_image_data").length&&void 0!==i(this.el).find(".sbi_resized_image_data").attr("data-resized")&&0===i(this.el).find(".sbi_resized_image_data").attr("data-resized").indexOf('{"')&&(this.resizedImages=JSON.parse(i(this.el).find(".sbi_resized_image_data").attr("data-resized")),i(this.el).find(".sbi_resized_image_data").remove())},sendNeedsResizingToServer:function(){var e=this;if(e.needsResizing.length>0&&e.settings.resizingEnabled){var t=i(this.el).find(".sbi_item").length,s=void 0!==e.settings.general.cache_all&&e.settings.general.cache_all;n({action:"sbi_resized_images_submit",needs_resizing:e.needsResizing,offset:t,feed_id:e.settings.feedID,atts:e.settings.shortCodeAtts,cache_all:s},function(i){if(0===i.trim().indexOf("{")){var t=JSON.parse(i);for(var s in e.settings.debugEnabled&&console.log(t),t)t.hasOwnProperty(s)&&(e.resizedImages[s]=t[s]);e.maybeRaiseImageResolution(),setTimeout(function(){e.afterResize()},500)}})}},loadMoreButtonInit:function(){var e=i(this.el),t=this;e.find("#sbi_load .sbi_load_btn").off().on("click",function(){t.afterLoadMoreClicked(jQuery(this)),t.getNewPostSet()})},getNewPostSet:function(){var e=i(this.el),t=this;n({action:"sbi_load_more_clicked",offset:e.find(".sbi_item").length,feed_id:t.settings.feedID,atts:t.settings.shortCodeAtts,current_resolution:t.imageResolution},function(s){if(0===s.trim().indexOf("{")){var n=JSON.parse(s);t.settings.debugEnabled&&console.log(n),t.appendNewPosts(n.html),t.addResizedImages(n.resizedImages),t.settings.ajaxPostLoad?(t.settings.ajaxPostLoad=!1,t.afterInitialImagesLoaded()):t.afterNewImagesLoaded(),n.feedStatus.shouldPaginate?t.outOfPages=!1:(t.outOfPages=!0,e.find(".sbi_load_btn").hide()),i(".sbi_no_js").removeClass("sbi_no_js")}})},appendNewPosts:function(e){var t=i(this.el);t.find("#sbi_images .sbi_item").length?t.find("#sbi_images .sbi_item").last().after(e):t.find("#sbi_images").append(e)},addResizedImages:function(i){for(var e in i)this.resizedImages[e]=i[e]},setImageHeight:function(){var e=i(this.el),t=e.find(".sbi_photo").eq(0).innerWidth(),s=this.getColumnCount(),n=e.find("#sbi_images").innerWidth()-e.find("#sbi_images").width(),a=n/2;sbi_photo_width_manual=e.find("#sbi_images").width()/s-n,e.find(".sbi_photo").css("height",t),e.find(".sbi-owl-nav").length&&setTimeout(function(){var i=2;e.find(".sbi_owl2row-item").length&&(i=1);var t=e.find(".sbi_photo").eq(0).innerWidth()/i;t+=parseInt(a)*(2-i+2),e.find(".sbi-owl-nav div").css("top",t)},100)},maybeRaiseSingleImageResolution:function(e,t,s){var n=this,a=n.getImageUrls(e),o=e.find(".sbi_photo img").attr("src"),d=150,r=e.find("img").get(0),l=o===window.sbi.options.placeholder?1:r.naturalWidth/r.naturalHeight;s=void 0!==s&&s;if(!(e.hasClass("sbi_no_resraise")||e.hasClass("sbi_had_error")||e.find(".sbi_link_area").length&&e.find(".sbi_link_area").hasClass("sbi_had_error")))if(a.length<1)e.find(".sbi_link_area").length&&e.find(".sbi_link_area").attr("href",window.sbi.options.placeholder.replace("placeholder.png","thumb-placeholder.png"));else{(e.find(".sbi_link_area").length&&e.find(".sbi_link_area").attr("href")===window.sbi.options.placeholder.replace("placeholder.png","thumb-placeholder.png")||!n.settings.consentGiven)&&e.find(".sbi_link_area").attr("href",a[a.length-1]),void 0!==a[640]&&e.find(".sbi_photo").attr("data-full-res",a[640]),i.each(a,function(i,e){e===o&&(d=parseInt(i),s=!1)});var h=640;switch(n.settings.imgRes){case"thumb":h=150;break;case"medium":h=320;break;case"full":h=640;break;default:var g=Math.max(n.settings.autoMinRes,e.find(".sbi_photo").innerWidth()),c=n.getBestResolutionForAuto(g,l,e);switch(c){case 320:h=320;break;case 150:h=150}}if(h>d||o===window.sbi.options.placeholder||s){if(n.settings.debugEnabled){var f=o===window.sbi.options.placeholder?"was placeholder":"too small";console.log("rais res for "+o,f)}var u=a[h].split("?ig_cache_key")[0];if(o!==u&&(e.find(".sbi_photo img").attr("src",u),e.find(".sbi_photo").css("background-image",'url("'+u+'")')),d=h,"auto"===n.settings.imgRes){var b=!1;e.find(".sbi_photo img").on("load",function(){var t=i(this),s=t.get(0).naturalWidth/t.get(0).naturalHeight;if(1e3!==t.get(0).naturalWidth&&s>l&&!b){switch(n.settings.debugEnabled&&console.log("rais res again for aspect ratio change "+o),b=!0,g=e.find(".sbi_photo").innerWidth(),c=n.getBestResolutionForAuto(g,s,e),h=640,c){case 320:h=320;break;case 150:h=150}h>d&&(u=a[h].split("?ig_cache_key")[0],t.attr("src",u),t.closest(".sbi_photo").css("background-image",'url("'+u+'")')),"masonry"!==n.layout&&"highlight"!==n.layout||(i(n.el).find("#sbi_images").smashotope(n.isotopeArgs),setTimeout(function(){i(n.el).find("#sbi_images").smashotope(n.isotopeArgs)},500))}else if(n.settings.debugEnabled){var r=b?"already checked":"no aspect ratio change";console.log("not raising res for replacement "+o,r)}})}}e.find("img").on("error",function(){if(i(this).hasClass("sbi_img_error"))console.log("unfixed error "+i(this).attr("src"));else{var e;if(i(this).addClass("sbi_img_error"),i(this).attr("src").indexOf("media/?size=")>-1||i(this).attr("src").indexOf("cdninstagram")>-1||i(this).attr("src").indexOf("fbcdn")>-1)n.settings.favorLocal=!0,void 0!==(e=n.getImageUrls(i(this).closest(".sbi_item")))[640]&&(i(this).attr("src",e[640]),i(this).closest(".sbi_photo").css("background-image","url("+e[640]+")"),i(this).closest(".sbi_item").addClass("sbi_had_error").find(".sbi_link_area").attr("href",e[640]).addClass("sbi_had_error"));else if("undefined"!==i(this).closest(".sbi_photo").attr("data-img-src-set"))void 0!==(e=JSON.parse(i(this).closest(".sbi_photo").attr("data-img-src-set").replace(/\\\//g,"/"))).d&&(i(this).attr("src",e.d),i(this).closest(".sbi_photo").css("background-image","url("+e.d+")"),i(this).closest(".sbi_item").addClass("sbi_had_error").find(".sbi_link_area").attr("href",e[640]).addClass("sbi_had_error"));setTimeout(function(){n.afterResize()},1500)}})}},maybeRaiseImageResolution:function(e){var t=this,s=void 0!==e&&!0===e?".sbi_item.sbi_new":".sbi_item",n=!t.isInitialized;i(t.el).find(s).each(function(e){!i(this).hasClass("sbi_num_diff_hide")&&i(this).find(".sbi_photo").length&&void 0!==i(this).find(".sbi_photo").attr("data-img-src-set")&&t.maybeRaiseSingleImageResolution(i(this),e,n)}),t.isInitialized=!0},getBestResolutionForAuto:function(e,t,s){(isNaN(t)||t<1)&&(t=1);var n=e*t,a=10*Math.ceil(n/10),o=[150,320,640];if(s.hasClass("sbi_highlighted")&&(a*=2),-1===o.indexOf(parseInt(a))){var d=!1;i.each(o,function(i,e){e>parseInt(a)&&!d&&(a=e,d=!0)})}return a},hideExtraImagesForWidth:function(){if("carousel"!==this.layout){var e=i(this.el),t=void 0!==e.attr("data-num")&&""!==e.attr("data-num")?parseInt(e.attr("data-num")):1,s=void 0!==e.attr("data-nummobile")&&""!==e.attr("data-nummobile")?parseInt(e.attr("data-nummobile")):t;i(window).width()<480?s<e.find(".sbi_item").length&&e.find(".sbi_item").slice(s-e.find(".sbi_item").length).addClass("sbi_num_diff_hide"):t<e.find(".sbi_item").length&&e.find(".sbi_item").slice(t-e.find(".sbi_item").length).addClass("sbi_num_diff_hide")}},setImageSizeClass:function(){var e=i(this.el);e.removeClass("sbi_small sbi_medium");var t=e.innerWidth(),s=parseInt(e.find("#sbi_images").outerWidth()-e.find("#sbi_images").width())/2,n=this.getColumnCount(),a=(t-s*(n+2))/n;a>120&&a<240?e.addClass("sbi_medium"):a<=120&&e.addClass("sbi_small")},setMinImageWidth:function(){i(this.el).find(".sbi_item .sbi_photo").first().length?this.minImageWidth=i(this.el).find(".sbi_item .sbi_photo").first().innerWidth():this.minImageWidth=150},setImageResolution:function(){if("auto"===this.settings.imgRes)this.imageResolution="auto";else switch(this.settings.imgRes){case"thumb":this.imageResolution=150;break;case"medium":this.imageResolution=320;break;default:this.imageResolution=640}},getImageUrls:function(i){var e=JSON.parse(i.find(".sbi_photo").attr("data-img-src-set").replace(/\\\//g,"/")),t=i.attr("id").replace("sbi_","");if(this.settings.consentGiven||this.settings.overrideBlockCDN||(e=[]),void 0!==this.resizedImages[t]&&"video"!==this.resizedImages[t]&&"pending"!==this.resizedImages[t]&&"error"!==this.resizedImages[t].id&&"video"!==this.resizedImages[t].id&&"pending"!==this.resizedImages[t].id){if(void 0!==this.resizedImages[t].sizes){var s=[];void 0!==this.resizedImages[t].sizes.full&&(e[640]=sb_instagram_js_options.resized_url+this.resizedImages[t].id+"full.jpg",s.push(640)),void 0!==this.resizedImages[t].sizes.low&&(e[320]=sb_instagram_js_options.resized_url+this.resizedImages[t].id+"low.jpg",s.push(320)),void 0!==this.resizedImages[t].sizes.thumb&&(s.push(150),e[150]=sb_instagram_js_options.resized_url+this.resizedImages[t].id+"thumb.jpg"),this.settings.favorLocal&&(-1===s.indexOf(640)&&s.indexOf(320)>-1&&(e[640]=sb_instagram_js_options.resized_url+this.resizedImages[t].id+"low.jpg"),-1===s.indexOf(320)&&(s.indexOf(640)>-1?e[320]=sb_instagram_js_options.resized_url+this.resizedImages[t].id+"full.jpg":s.indexOf(150)>-1&&(e[320]=sb_instagram_js_options.resized_url+this.resizedImages[t].id+"thumb.jpg")),-1===s.indexOf(150)&&(s.indexOf(320)>-1?e[150]=sb_instagram_js_options.resized_url+this.resizedImages[t].id+"low.jpg":s.indexOf(640)>-1&&(e[150]=sb_instagram_js_options.resized_url+this.resizedImages[t].id+"full.jpg")))}}else(void 0===this.resizedImages[t]||void 0!==this.resizedImages[t].id&&"pending"!==this.resizedImages[t].id&&"error"!==this.resizedImages[t].id)&&this.addToNeedsResizing(t);return e},getAvatarUrl:function(i,e){if(""===i)return"";var t=this.settings.general.avatars;return"local"===(e=void 0!==e?e:"local")?void 0!==t["LCL"+i]&&1===parseInt(t["LCL"+i])?sb_instagram_js_options.resized_url+i+".jpg":void 0!==t[i]?t[i]:"":void 0!==t[i]?t[i]:void 0!==t["LCL"+i]&&1===parseInt(t["LCL"+i])?sb_instagram_js_options.resized_url+i+".jpg":""},addToNeedsResizing:function(i){-1===this.needsResizing.indexOf(i)&&this.needsResizing.push(i)},applyImageLiquid:function(){var t=i(this.el);e(),"function"==typeof t.find(".sbi_photo").sbi_imgLiquid&&t.find(".sbi_photo").sbi_imgLiquid({fill:!0})},listenForVisibilityChange:function(){var e,t,s,n=this;e=jQuery,t={callback:function(){},runOnLoad:!0,frequency:100,sbiPreviousVisibility:null},s={sbiCheckVisibility:function(i,e){if(jQuery.contains(document,i[0])){var t=e.sbiPreviousVisibility,n=i.is(":visible");e.sbiPreviousVisibility=n,null==t?e.runOnLoad&&e.callback(i,n):t!==n&&e.callback(i,n),setTimeout(function(){s.sbiCheckVisibility(i,e)},e.frequency)}}},e.fn.sbiVisibilityChanged=function(i){var n=e.extend({},t,i);return this.each(function(){s.sbiCheckVisibility(e(this),n)})},"function"==typeof i(this.el).filter(":hidden").sbiVisibilityChanged&&i(this.el).filter(":hidden").sbiVisibilityChanged({callback:function(i,e){n.afterResize()},runOnLoad:!1})},getColumnCount:function(){var e=i(this.el),t=this.settings.cols,s=this.settings.colsmobile,n=t;return sbiWindowWidth=window.innerWidth,e.hasClass("sbi_mob_col_auto")?(sbiWindowWidth<640&&parseInt(t)>2&&parseInt(t)<7&&(n=2),sbiWindowWidth<640&&parseInt(t)>6&&parseInt(t)<11&&(n=4),sbiWindowWidth<=480&&parseInt(t)>2&&(n=1)):sbiWindowWidth<=480&&(n=s),parseInt(n)},checkConsent:function(){if(this.settings.consentGiven||!this.settings.gdpr)return!0;if("undefined"!=typeof CLI_Cookie)null!==CLI_Cookie.read(CLI_ACCEPT_COOKIE_NAME)&&(this.settings.consentGiven="yes"===CLI_Cookie.read("cookielawinfo-checkbox-non-necessary"));else if(void 0!==window.cnArgs){var i=("; "+document.cookie).split("; cookie_notice_accepted=");if(2===i.length){var e=i.pop().split(";").shift();this.settings.consentGiven="true"===e}}else void 0!==window.cookieconsent?this.settings.consentGiven="allow"===function(i){for(var e=i+"=",t=window.document.cookie.split(";"),s=0;s<t.length;s++){var n=t[s].trim();if(0==n.indexOf(e))return n.substring(e.length,n.length)}return""}("complianz_consent_status"):void 0!==window.Cookiebot&&(this.settings.consentGiven=Cookiebot.consented);var t=jQuery.Event("sbicheckconsent");return t.feed=this,jQuery(window).trigger(t),this.settings.consentGiven},afterConsentToggled:function(){if(this.checkConsent()){var i=this;i.maybeRaiseImageResolution(),setTimeout(function(){i.afterResize()},500)}}},window.sbi_init=function(){window.sbi=new t,window.sbi.createPage(window.sbi.createFeeds,{whenFeedsCreated:window.sbi.afterFeedsCreated})}}(jQuery),jQuery(document).ready(function(i){void 0===window.sb_instagram_js_options&&(window.sb_instagram_js_options={font_method:"svg",resized_url:location.protocol+"//"+window.location.hostname+"/wp-content/uploads/sb-instagram-feed-images/",placeholder:location.protocol+"//"+window.location.hostname+"/wp-content/plugins/instagram-feed/img/placeholder.png"}),void 0!==window.sb_instagram_js_options.resized_url&&-1===window.sb_instagram_js_options.resized_url.indexOf(location.protocol)&&("http:"===location.protocol?window.sb_instagram_js_options.resized_url=window.sb_instagram_js_options.resized_url.replace("https:","http:"):window.sb_instagram_js_options.resized_url=window.sb_instagram_js_options.resized_url.replace("http:","https:")),sbi_init(),i("#cookie-notice a").click(function(){setTimeout(function(){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].afterConsentToggled()})},1e3)}),i("#cookie-law-info-bar a").click(function(){setTimeout(function(){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].afterConsentToggled()})},1e3)}),i(".cli-user-preference-checkbox").click(function(){setTimeout(function(){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].settings.consentGiven=!1,window.sbi.feeds[i].afterConsentToggled()})},1e3)}),i(window).on("CookiebotOnAccept",function(e){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].settings.consentGiven=!0,window.sbi.feeds[i].afterConsentToggled()})}),i(document).on("cmplzAcceptAll",function(e){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].settings.consentGiven=!0,window.sbi.feeds[i].afterConsentToggled()})}),i(document).on("cmplzRevoke",function(e){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].settings.consentGiven=!1,window.sbi.feeds[i].afterConsentToggled()})})}));
1
+ var sbi_js_exists=void 0!==sbi_js_exists;sbi_js_exists||(!function(i){function e(){var i,e,s,t=t||{VER:"0.9.944"};t.bgs_Available=!1,t.bgs_CheckRunned=!1,function(i){i.fn.extend({sbi_imgLiquid:function(e){this.defaults={fill:!0,verticalAlign:"center",horizontalAlign:"center",useBackgroundSize:!0,useDataHtmlAttr:!0,responsive:!0,delay:0,fadeInTime:0,removeBoxBackground:!0,hardPixels:!0,responsiveCheckTime:500,timecheckvisibility:500,onStart:null,onFinish:null,onItemStart:null,onItemFinish:null,onItemError:null},function(){if(!t.bgs_CheckRunned){t.bgs_CheckRunned=!0;var e=i('<span style="background-size:cover" />');i("body").append(e),function(){var i=e[0];if(i&&window.getComputedStyle){var s=window.getComputedStyle(i,null);s&&s.backgroundSize&&(t.bgs_Available="cover"===s.backgroundSize)}}(),e.remove()}}();var s=this;return this.options=e,this.settings=i.extend({},this.defaults,this.options),this.settings.onStart&&this.settings.onStart(),this.each(function(e){function n(){(r.responsive||h.data("sbi_imgLiquid_oldProcessed"))&&h.data("sbi_imgLiquid_settings")&&(r=h.data("sbi_imgLiquid_settings"),l.actualSize=l.get(0).offsetWidth+l.get(0).offsetHeight/1e4,l.sizeOld&&l.actualSize!==l.sizeOld&&o(),l.sizeOld=l.actualSize,setTimeout(n,r.responsiveCheckTime))}function a(){h.data("sbi_imgLiquid_error",!0),l.addClass("sbi_imgLiquid_error"),r.onItemError&&r.onItemError(e,l,h),d()}function o(){var i,s,t,n,a,o,g,c,f=0,u=0,b=l.width(),_=l.height();void 0===h.data("owidth")&&h.data("owidth",h[0].width),void 0===h.data("oheight")&&h.data("oheight",h[0].height),r.fill===b/_>=h.data("owidth")/h.data("oheight")?(i="100%",s="auto",t=Math.floor(b),n=Math.floor(b*(h.data("oheight")/h.data("owidth")))):(i="auto",s="100%",t=Math.floor(_*(h.data("owidth")/h.data("oheight"))),n=Math.floor(_)),g=b-t,"left"===(a=r.horizontalAlign.toLowerCase())&&(u=0),"center"===a&&(u=.5*g),"right"===a&&(u=g),-1!==a.indexOf("%")&&((a=parseInt(a.replace("%",""),10))>0&&(u=g*a*.01)),c=_-n,"left"===(o=r.verticalAlign.toLowerCase())&&(f=0),"center"===o&&(f=.5*c),"bottom"===o&&(f=c),-1!==o.indexOf("%")&&((o=parseInt(o.replace("%",""),10))>0&&(f=c*o*.01)),r.hardPixels&&(i=t,s=n),h.css({width:i,height:s,"margin-left":Math.floor(u),"margin-top":Math.floor(f)}),h.data("sbi_imgLiquid_oldProcessed")||(h.fadeTo(r.fadeInTime,1),h.data("sbi_imgLiquid_oldProcessed",!0),r.removeBoxBackground&&l.css("background-image","none"),l.addClass("sbi_imgLiquid_nobgSize"),l.addClass("sbi_imgLiquid_ready")),r.onItemFinish&&r.onItemFinish(e,l,h),d()}function d(){e===s.length-1&&s.settings.onFinish&&s.settings.onFinish()}var r=s.settings,l=i(this),h=i("img:first",l);return h.length?(h.data("sbi_imgLiquid_settings")?(l.removeClass("sbi_imgLiquid_error").removeClass("sbi_imgLiquid_ready"),r=i.extend({},h.data("sbi_imgLiquid_settings"),s.options)):r=i.extend({},s.settings,function(){var i={};if(s.settings.useDataHtmlAttr){var e=l.attr("data-sbi_imgLiquid-fill"),n=l.attr("data-sbi_imgLiquid-horizontalAlign"),a=l.attr("data-sbi_imgLiquid-verticalAlign");("true"===e||"false"===e)&&(i.fill=Boolean("true"===e)),void 0===n||"left"!==n&&"center"!==n&&"right"!==n&&-1===n.indexOf("%")||(i.horizontalAlign=n),void 0===a||"top"!==a&&"bottom"!==a&&"center"!==a&&-1===a.indexOf("%")||(i.verticalAlign=a)}return t.isIE&&s.settings.ieFadeInDisabled&&(i.fadeInTime=0),i}()),h.data("sbi_imgLiquid_settings",r),r.onItemStart&&r.onItemStart(e,l,h),void(t.bgs_Available&&r.useBackgroundSize?(-1===l.css("background-image").indexOf(encodeURI(h.attr("src")))&&l.css({"background-image":'url("'+encodeURI(h.attr("src"))+'")'}),l.css({"background-size":r.fill?"cover":"contain","background-position":(r.horizontalAlign+" "+r.verticalAlign).toLowerCase(),"background-repeat":"no-repeat"}),i("a:first",l).css({display:"block",width:"100%",height:"100%"}),i("img",l).css({display:"none"}),r.onItemFinish&&r.onItemFinish(e,l,h),l.addClass("sbi_imgLiquid_bgSize"),l.addClass("sbi_imgLiquid_ready"),d()):function s(){if(h.data("oldSrc")&&h.data("oldSrc")!==h.attr("src")){var t=h.clone().removeAttr("style");return t.data("sbi_imgLiquid_settings",h.data("sbi_imgLiquid_settings")),h.parent().prepend(t),h.remove(),(h=t)[0].width=0,void setTimeout(s,10)}return h.data("sbi_imgLiquid_oldProcessed")?void o():(h.data("sbi_imgLiquid_oldProcessed",!1),h.data("oldSrc",h.attr("src")),i("img:not(:first)",l).css("display","none"),l.css({overflow:"hidden"}),h.fadeTo(0,0).removeAttr("width").removeAttr("height").css({visibility:"visible","max-width":"none","max-height":"none",width:"auto",height:"auto",display:"block"}),h.on("error",a),h[0].onerror=a,function i(){h.data("sbi_imgLiquid_error")||h.data("sbi_imgLiquid_loaded")||h.data("sbi_imgLiquid_oldProcessed")||(l.is(":visible")&&h[0].complete&&h[0].width>0&&h[0].height>0?(h.data("sbi_imgLiquid_loaded",!0),setTimeout(o,e*r.delay)):setTimeout(i,r.timecheckvisibility))}(),void n())}())):void a()})}})}(jQuery),i=t.injectCss,e=document.getElementsByTagName("head")[0],(s=document.createElement("style")).type="text/css",s.styleSheet?s.styleSheet.cssText=i:s.appendChild(document.createTextNode(i)),e.appendChild(s)}function s(){this.feeds={},this.options=sb_instagram_js_options}function t(i,e,s){this.el=i,this.index=e,this.settings=s,this.minImageWidth=0,this.imageResolution=150,this.resizedImages={},this.needsResizing=[],this.outOfPages=!1,this.isInitialized=!1}function n(e,s){i.ajax({url:sbiajaxurl,type:"post",data:e,success:s})}s.prototype={createPage:function(e,s){void 0!==window.sbiajaxurl&&-1!==window.sbiajaxurl.indexOf(window.location.hostname)||(window.sbiajaxurl=location.protocol+"//"+window.location.hostname+"/wp-admin/admin-ajax.php"),i(".sbi_no_js_error_message").remove(),i(".sbi_no_js").removeClass("sbi_no_js"),e(s)},createFeeds:function(e){e.whenFeedsCreated(i(".sbi").each(function(e){i(this).attr("data-sbi-index",e+1);var s=i(this),a=void 0!==s.attr("data-sbi-flags")?s.attr("data-sbi-flags").split(","):[],o=void 0!==s.attr("data-options")?JSON.parse(s.attr("data-options")):{};if(a.indexOf("testAjax")>-1){window.sbi.triggeredTest=!0;n({action:"sbi_on_ajax_test_trigger"},function(i){console.log("did test")})}var d={cols:s.attr("data-cols"),colsmobile:void 0!==s.attr("data-colsmobile")&&"same"!==s.attr("data-colsmobile")?s.attr("data-colsmobile"):s.attr("data-cols"),num:s.attr("data-num"),imgRes:s.attr("data-res"),feedID:s.attr("data-feedid"),shortCodeAtts:s.attr("data-shortcode-atts"),resizingEnabled:-1===a.indexOf("resizeDisable"),imageLoadEnabled:-1===a.indexOf("imageLoadDisable"),debugEnabled:a.indexOf("debug")>-1,favorLocal:a.indexOf("favorLocal")>-1,ajaxPostLoad:a.indexOf("ajaxPostLoad")>-1,gdpr:a.indexOf("gdpr")>-1,overrideBlockCDN:a.indexOf("overrideBlockCDN")>-1,consentGiven:!1,autoMinRes:1,general:o};window.sbi.feeds[e]=function(i,e,s){return new t(i,e,s)}(this,e,d),window.sbi.feeds[e].setResizedImages(),window.sbi.feeds[e].init();var r=jQuery.Event("sbiafterfeedcreate");r.feed=window.sbi.feeds[e],jQuery(window).trigger(r)}))},afterFeedsCreated:function(){i(".sb_instagram_header").each(function(){var e=i(this);e.find(".sbi_header_link").hover(function(){e.find(".sbi_header_img_hover").addClass("sbi_fade_in")},function(){e.find(".sbi_header_img_hover").removeClass("sbi_fade_in")})})},encodeHTML:function(i){return void 0===i?"":i.replace(/(>)/g,"&gt;").replace(/(<)/g,"&lt;").replace(/(&lt;br\/&gt;)/g,"<br>").replace(/(&lt;br&gt;)/g,"<br>")},urlDetect:function(i){return i.match(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)/g)}},t.prototype={init:function(){var e=this;e.settings.consentGiven=e.checkConsent(),i(this.el).find(".sbi_photo").parent("p").length&&i(this.el).addClass("sbi_no_autop"),i(this.el).find("#sbi_mod_error").length&&i(this.el).prepend(i(this.el).find("#sbi_mod_error")),this.settings.ajaxPostLoad?this.getNewPostSet():this.afterInitialImagesLoaded();var s,t=(s=0,function(i,e){clearTimeout(s),s=setTimeout(i,e)});jQuery(window).resize(function(){t(function(){e.afterResize()},500)}),i(this.el).find(".sbi_item").each(function(){e.lazyLoadCheck(i(this))})},initLayout:function(){},afterInitialImagesLoaded:function(){this.initLayout(),this.loadMoreButtonInit(),this.hideExtraImagesForWidth(),this.beforeNewImagesRevealed(),this.revealNewImages(),this.afterNewImagesRevealed()},afterResize:function(){this.setImageHeight(),this.setImageResolution(),this.maybeRaiseImageResolution(),this.setImageSizeClass()},afterLoadMoreClicked:function(i){i.find(".sbi_loader").removeClass("sbi_hidden"),i.find(".sbi_btn_text").addClass("sbi_hidden"),i.closest(".sbi").find(".sbi_num_diff_hide").addClass("sbi_transition").removeClass("sbi_num_diff_hide")},afterNewImagesLoaded:function(){var e=i(this.el),s=this;this.beforeNewImagesRevealed(),this.revealNewImages(),this.afterNewImagesRevealed(),setTimeout(function(){e.find(".sbi_loader").addClass("sbi_hidden"),e.find(".sbi_btn_text").removeClass("sbi_hidden"),s.maybeRaiseImageResolution()},500)},beforeNewImagesRevealed:function(){this.setImageHeight(),this.maybeRaiseImageResolution(!0),this.setImageSizeClass()},revealNewImages:function(){var e=i(this.el);e.find(".sbi-screenreader").each(function(){i(this).find("img").remove()}),"function"==typeof sbi_custom_js&&setTimeout(function(){sbi_custom_js()},100),this.applyImageLiquid(),e.find(".sbi_item").each(function(i){jQuery(this).find(".sbi_photo").hover(function(){jQuery(this).fadeTo(200,.85)},function(){jQuery(this).stop().fadeTo(500,1)})}),setTimeout(function(){jQuery("#sbi_images .sbi_item.sbi_new").removeClass("sbi_new");var i=10;e.find(".sbi_transition").each(function(){var e=jQuery(this);setTimeout(function(){e.removeClass("sbi_transition")},i),i+=10})},500)},lazyLoadCheck:function(e){if(e.find(".sbi_photo").length&&!e.closest(".sbi").hasClass("sbi-no-ll-check")){var s=this.getImageUrls(e),t=void 0!==s[640]?s[640]:e.find(".sbi_photo").attr("data-full-res");if(!this.settings.consentGiven&&t.indexOf("scontent")>-1)return;e.find(".sbi_photo img").each(function(){t&&void 0!==i(this).attr("data-src")&&i(this).attr("data-src",t),t&&void 0!==i(this).attr("data-orig-src")&&i(this).attr("data-orig-src",t),i(this).on("load",function(){!i(this).hasClass("sbi-replaced")&&i(this).attr("src").indexOf("placeholder")>-1&&(i(this).addClass("sbi-replaced"),t&&(i(this).attr("src",t),i(this).closest(".sbi_imgLiquid_bgSize").length&&i(this).closest(".sbi_imgLiquid_bgSize").css("background-image","url("+t+")")))})})}},afterNewImagesRevealed:function(){this.listenForVisibilityChange(),this.sendNeedsResizingToServer(),this.settings.imageLoadEnabled||i(".sbi_no_resraise").removeClass("sbi_no_resraise");var e=i.Event("sbiafterimagesloaded");e.el=i(this.el),i(window).trigger(e)},setResizedImages:function(){i(this.el).find(".sbi_resized_image_data").length&&void 0!==i(this.el).find(".sbi_resized_image_data").attr("data-resized")&&0===i(this.el).find(".sbi_resized_image_data").attr("data-resized").indexOf('{"')&&(this.resizedImages=JSON.parse(i(this.el).find(".sbi_resized_image_data").attr("data-resized")),i(this.el).find(".sbi_resized_image_data").remove())},sendNeedsResizingToServer:function(){var e=this;if(e.needsResizing.length>0&&e.settings.resizingEnabled){var s=i(this.el).find(".sbi_item").length,t=void 0!==e.settings.general.cache_all&&e.settings.general.cache_all;n({action:"sbi_resized_images_submit",needs_resizing:e.needsResizing,offset:s,feed_id:e.settings.feedID,atts:e.settings.shortCodeAtts,cache_all:t},function(i){if(0===i.trim().indexOf("{")){var s=JSON.parse(i);for(var t in e.settings.debugEnabled&&console.log(s),s)s.hasOwnProperty(t)&&(e.resizedImages[t]=s[t]);e.maybeRaiseImageResolution(),setTimeout(function(){e.afterResize()},500)}})}},loadMoreButtonInit:function(){var e=i(this.el),s=this;e.find("#sbi_load .sbi_load_btn").off().on("click",function(){s.afterLoadMoreClicked(jQuery(this)),s.getNewPostSet()})},getNewPostSet:function(){var e=i(this.el),s=this;n({action:"sbi_load_more_clicked",offset:e.find(".sbi_item").length,feed_id:s.settings.feedID,atts:s.settings.shortCodeAtts,current_resolution:s.imageResolution},function(t){if(0===t.trim().indexOf("{")){var n=JSON.parse(t);s.settings.debugEnabled&&console.log(n),s.appendNewPosts(n.html),s.addResizedImages(n.resizedImages),s.settings.ajaxPostLoad?(s.settings.ajaxPostLoad=!1,s.afterInitialImagesLoaded()):s.afterNewImagesLoaded(),n.feedStatus.shouldPaginate?s.outOfPages=!1:(s.outOfPages=!0,e.find(".sbi_load_btn").hide()),i(".sbi_no_js").removeClass("sbi_no_js")}})},appendNewPosts:function(e){var s=i(this.el);s.find("#sbi_images .sbi_item").length?s.find("#sbi_images .sbi_item").last().after(e):s.find("#sbi_images").append(e)},addResizedImages:function(i){for(var e in i)this.resizedImages[e]=i[e]},setImageHeight:function(){var e=i(this.el),s=e.find(".sbi_photo").eq(0).innerWidth(),t=this.getColumnCount(),n=e.find("#sbi_images").innerWidth()-e.find("#sbi_images").width(),a=n/2;sbi_photo_width_manual=e.find("#sbi_images").width()/t-n,e.find(".sbi_photo").css("height",s),e.find(".sbi-owl-nav").length&&setTimeout(function(){var i=2;e.find(".sbi_owl2row-item").length&&(i=1);var s=e.find(".sbi_photo").eq(0).innerWidth()/i;s+=parseInt(a)*(2-i+2),e.find(".sbi-owl-nav div").css("top",s)},100)},maybeRaiseSingleImageResolution:function(e,s,t){var n=this,a=n.getImageUrls(e),o=e.find(".sbi_photo img").attr("src"),d=150,r=e.find("img").get(0),l=o===window.sbi.options.placeholder?1:r.naturalWidth/r.naturalHeight;t=void 0!==t&&t;if(!(e.hasClass("sbi_no_resraise")||e.hasClass("sbi_had_error")||e.find(".sbi_link_area").length&&e.find(".sbi_link_area").hasClass("sbi_had_error")))if(a.length<1)e.find(".sbi_link_area").length&&e.find(".sbi_link_area").attr("href",window.sbi.options.placeholder.replace("placeholder.png","thumb-placeholder.png"));else{(e.find(".sbi_link_area").length&&e.find(".sbi_link_area").attr("href")===window.sbi.options.placeholder.replace("placeholder.png","thumb-placeholder.png")||!n.settings.consentGiven)&&e.find(".sbi_link_area").attr("href",a[a.length-1]),void 0!==a[640]&&e.find(".sbi_photo").attr("data-full-res",a[640]),i.each(a,function(i,e){e===o&&(d=parseInt(i),t=!1)});var h=640;switch(n.settings.imgRes){case"thumb":h=150;break;case"medium":h=320;break;case"full":h=640;break;default:var g=Math.max(n.settings.autoMinRes,e.find(".sbi_photo").innerWidth()),c=n.getBestResolutionForAuto(g,l,e);switch(c){case 320:h=320;break;case 150:h=150}}if(h>d||o===window.sbi.options.placeholder||t){if(n.settings.debugEnabled){var f=o===window.sbi.options.placeholder?"was placeholder":"too small";console.log("rais res for "+o,f)}var u=a[h].split("?ig_cache_key")[0];if(o!==u&&(e.find(".sbi_photo img").attr("src",u),e.find(".sbi_photo").css("background-image",'url("'+u+'")')),d=h,"auto"===n.settings.imgRes){var b=!1;e.find(".sbi_photo img").on("load",function(){var s=i(this),t=s.get(0).naturalWidth/s.get(0).naturalHeight;if(1e3!==s.get(0).naturalWidth&&t>l&&!b){switch(n.settings.debugEnabled&&console.log("rais res again for aspect ratio change "+o),b=!0,g=e.find(".sbi_photo").innerWidth(),c=n.getBestResolutionForAuto(g,t,e),h=640,c){case 320:h=320;break;case 150:h=150}h>d&&(u=a[h].split("?ig_cache_key")[0],s.attr("src",u),s.closest(".sbi_photo").css("background-image",'url("'+u+'")')),"masonry"!==n.layout&&"highlight"!==n.layout||(i(n.el).find("#sbi_images").smashotope(n.isotopeArgs),setTimeout(function(){i(n.el).find("#sbi_images").smashotope(n.isotopeArgs)},500))}else if(n.settings.debugEnabled){var r=b?"already checked":"no aspect ratio change";console.log("not raising res for replacement "+o,r)}})}}e.find("img").on("error",function(){if(i(this).hasClass("sbi_img_error"))console.log("unfixed error "+i(this).attr("src"));else{var e;if(i(this).addClass("sbi_img_error"),!(i(this).attr("src").indexOf("media/?size=")>-1||i(this).attr("src").indexOf("cdninstagram")>-1||i(this).attr("src").indexOf("fbcdn")>-1)&&n.settings.consentGiven){if("undefined"!==i(this).closest(".sbi_photo").attr("data-img-src-set"))void 0!==(e=JSON.parse(i(this).closest(".sbi_photo").attr("data-img-src-set").replace(/\\\//g,"/"))).d&&(i(this).attr("src",e.d),i(this).closest(".sbi_photo").css("background-image","url("+e.d+")"),i(this).closest(".sbi_item").addClass("sbi_had_error").find(".sbi_link_area").attr("href",e[640]).addClass("sbi_had_error"))}else n.settings.favorLocal=!0,void 0!==(e=n.getImageUrls(i(this).closest(".sbi_item")))[640]&&(i(this).attr("src",e[640]),i(this).closest(".sbi_photo").css("background-image","url("+e[640]+")"),i(this).closest(".sbi_item").addClass("sbi_had_error").find(".sbi_link_area").attr("href",e[640]).addClass("sbi_had_error"));setTimeout(function(){n.afterResize()},1500)}})}},maybeRaiseImageResolution:function(e){var s=this,t=void 0!==e&&!0===e?".sbi_item.sbi_new":".sbi_item",n=!s.isInitialized;i(s.el).find(t).each(function(e){!i(this).hasClass("sbi_num_diff_hide")&&i(this).find(".sbi_photo").length&&void 0!==i(this).find(".sbi_photo").attr("data-img-src-set")&&s.maybeRaiseSingleImageResolution(i(this),e,n)}),s.isInitialized=!0},getBestResolutionForAuto:function(e,s,t){(isNaN(s)||s<1)&&(s=1);var n=e*s,a=10*Math.ceil(n/10),o=[150,320,640];if(t.hasClass("sbi_highlighted")&&(a*=2),-1===o.indexOf(parseInt(a))){var d=!1;i.each(o,function(i,e){e>parseInt(a)&&!d&&(a=e,d=!0)})}return a},hideExtraImagesForWidth:function(){if("carousel"!==this.layout){var e=i(this.el),s=void 0!==e.attr("data-num")&&""!==e.attr("data-num")?parseInt(e.attr("data-num")):1,t=void 0!==e.attr("data-nummobile")&&""!==e.attr("data-nummobile")?parseInt(e.attr("data-nummobile")):s;i(window).width()<480?t<e.find(".sbi_item").length&&e.find(".sbi_item").slice(t-e.find(".sbi_item").length).addClass("sbi_num_diff_hide"):s<e.find(".sbi_item").length&&e.find(".sbi_item").slice(s-e.find(".sbi_item").length).addClass("sbi_num_diff_hide")}},setImageSizeClass:function(){var e=i(this.el);e.removeClass("sbi_small sbi_medium");var s=e.innerWidth(),t=parseInt(e.find("#sbi_images").outerWidth()-e.find("#sbi_images").width())/2,n=this.getColumnCount(),a=(s-t*(n+2))/n;a>120&&a<240?e.addClass("sbi_medium"):a<=120&&e.addClass("sbi_small")},setMinImageWidth:function(){i(this.el).find(".sbi_item .sbi_photo").first().length?this.minImageWidth=i(this.el).find(".sbi_item .sbi_photo").first().innerWidth():this.minImageWidth=150},setImageResolution:function(){if("auto"===this.settings.imgRes)this.imageResolution="auto";else switch(this.settings.imgRes){case"thumb":this.imageResolution=150;break;case"medium":this.imageResolution=320;break;default:this.imageResolution=640}},getImageUrls:function(i){var e=JSON.parse(i.find(".sbi_photo").attr("data-img-src-set").replace(/\\\//g,"/")),s=i.attr("id").replace("sbi_","");if(this.settings.consentGiven||this.settings.overrideBlockCDN||(e=[]),void 0!==this.resizedImages[s]&&"video"!==this.resizedImages[s]&&"pending"!==this.resizedImages[s]&&"error"!==this.resizedImages[s].id&&"video"!==this.resizedImages[s].id&&"pending"!==this.resizedImages[s].id){if(void 0!==this.resizedImages[s].sizes){var t=[];void 0!==this.resizedImages[s].sizes.full&&(e[640]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"full.jpg",t.push(640)),void 0!==this.resizedImages[s].sizes.low&&(e[320]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"low.jpg",t.push(320)),void 0!==this.resizedImages[s].sizes.thumb&&(t.push(150),e[150]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"thumb.jpg"),this.settings.favorLocal&&(-1===t.indexOf(640)&&t.indexOf(320)>-1&&(e[640]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"low.jpg"),-1===t.indexOf(320)&&(t.indexOf(640)>-1?e[320]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"full.jpg":t.indexOf(150)>-1&&(e[320]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"thumb.jpg")),-1===t.indexOf(150)&&(t.indexOf(320)>-1?e[150]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"low.jpg":t.indexOf(640)>-1&&(e[150]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"full.jpg")))}}else(void 0===this.resizedImages[s]||void 0!==this.resizedImages[s].id&&"pending"!==this.resizedImages[s].id&&"error"!==this.resizedImages[s].id)&&this.addToNeedsResizing(s);return e},getAvatarUrl:function(i,e){if(""===i)return"";var s=this.settings.general.avatars;return"local"===(e=void 0!==e?e:"local")?void 0!==s["LCL"+i]&&1===parseInt(s["LCL"+i])?sb_instagram_js_options.resized_url+i+".jpg":void 0!==s[i]?s[i]:"":void 0!==s[i]?s[i]:void 0!==s["LCL"+i]&&1===parseInt(s["LCL"+i])?sb_instagram_js_options.resized_url+i+".jpg":""},addToNeedsResizing:function(i){-1===this.needsResizing.indexOf(i)&&this.needsResizing.push(i)},applyImageLiquid:function(){var s=i(this.el);e(),"function"==typeof s.find(".sbi_photo").sbi_imgLiquid&&s.find(".sbi_photo").sbi_imgLiquid({fill:!0})},listenForVisibilityChange:function(){var e,s,t,n=this;e=jQuery,s={callback:function(){},runOnLoad:!0,frequency:100,sbiPreviousVisibility:null},t={sbiCheckVisibility:function(i,e){if(jQuery.contains(document,i[0])){var s=e.sbiPreviousVisibility,n=i.is(":visible");e.sbiPreviousVisibility=n,null==s?e.runOnLoad&&e.callback(i,n):s!==n&&e.callback(i,n),setTimeout(function(){t.sbiCheckVisibility(i,e)},e.frequency)}}},e.fn.sbiVisibilityChanged=function(i){var n=e.extend({},s,i);return this.each(function(){t.sbiCheckVisibility(e(this),n)})},"function"==typeof i(this.el).filter(":hidden").sbiVisibilityChanged&&i(this.el).filter(":hidden").sbiVisibilityChanged({callback:function(i,e){n.afterResize()},runOnLoad:!1})},getColumnCount:function(){var e=i(this.el),s=this.settings.cols,t=this.settings.colsmobile,n=s;return sbiWindowWidth=window.innerWidth,e.hasClass("sbi_mob_col_auto")?(sbiWindowWidth<640&&parseInt(s)>2&&parseInt(s)<7&&(n=2),sbiWindowWidth<640&&parseInt(s)>6&&parseInt(s)<11&&(n=4),sbiWindowWidth<=480&&parseInt(s)>2&&(n=1)):sbiWindowWidth<=480&&(n=t),parseInt(n)},checkConsent:function(){if(this.settings.consentGiven||!this.settings.gdpr)return!0;if("undefined"!=typeof CLI_Cookie)null!==CLI_Cookie.read(CLI_ACCEPT_COOKIE_NAME)&&(this.settings.consentGiven="yes"===CLI_Cookie.read("cookielawinfo-checkbox-non-necessary"));else if(void 0!==window.cnArgs){var i=("; "+document.cookie).split("; cookie_notice_accepted=");if(2===i.length){var e=i.pop().split(";").shift();this.settings.consentGiven="true"===e}}else void 0!==window.cookieconsent?this.settings.consentGiven="allow"===function(i){for(var e=i+"=",s=window.document.cookie.split(";"),t=0;t<s.length;t++){var n=s[t].trim();if(0==n.indexOf(e))return n.substring(e.length,n.length)}return""}("complianz_consent_status"):void 0!==window.Cookiebot?this.settings.consentGiven=Cookiebot.consented:void 0!==window.BorlabsCookie&&(this.settings.consentGiven=window.BorlabsCookie.checkCookieConsent("instagram"));var s=jQuery.Event("sbicheckconsent");return s.feed=this,jQuery(window).trigger(s),this.settings.consentGiven},afterConsentToggled:function(){if(this.checkConsent()){var i=this;i.maybeRaiseImageResolution(),setTimeout(function(){i.afterResize()},500)}}},window.sbi_init=function(){window.sbi=new s,window.sbi.createPage(window.sbi.createFeeds,{whenFeedsCreated:window.sbi.afterFeedsCreated})}}(jQuery),jQuery(document).ready(function(i){void 0===window.sb_instagram_js_options&&(window.sb_instagram_js_options={font_method:"svg",resized_url:location.protocol+"//"+window.location.hostname+"/wp-content/uploads/sb-instagram-feed-images/",placeholder:location.protocol+"//"+window.location.hostname+"/wp-content/plugins/instagram-feed/img/placeholder.png"}),void 0!==window.sb_instagram_js_options.resized_url&&-1===window.sb_instagram_js_options.resized_url.indexOf(location.protocol)&&("http:"===location.protocol?window.sb_instagram_js_options.resized_url=window.sb_instagram_js_options.resized_url.replace("https:","http:"):window.sb_instagram_js_options.resized_url=window.sb_instagram_js_options.resized_url.replace("http:","https:")),sbi_init(),i("#cookie-notice a").click(function(){setTimeout(function(){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].afterConsentToggled()})},1e3)}),i("#cookie-law-info-bar a").click(function(){setTimeout(function(){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].afterConsentToggled()})},1e3)}),i(".cli-user-preference-checkbox").click(function(){setTimeout(function(){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].settings.consentGiven=!1,window.sbi.feeds[i].afterConsentToggled()})},1e3)}),i(window).on("CookiebotOnAccept",function(e){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].settings.consentGiven=!0,window.sbi.feeds[i].afterConsentToggled()})}),i(document).on("cmplzAcceptAll",function(e){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].settings.consentGiven=!0,window.sbi.feeds[i].afterConsentToggled()})}),i(document).on("cmplzRevoke",function(e){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].settings.consentGiven=!1,window.sbi.feeds[i].afterConsentToggled()})}),i(document).on("borlabs-cookie-consent-saved",function(e){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].settings.consentGiven=!1,window.sbi.feeds[i].afterConsentToggled()})})}));
js/sb-instagram-admin-2-2.js CHANGED
@@ -1141,7 +1141,6 @@ jQuery(document).ready(function($) {
1141
  sbiCheckGdprSetting( jQuery(this).val() );
1142
  });
1143
  function sbiCheckGdprSetting(option) {
1144
- console.log('heretere')
1145
  if( option == 'yes' ){
1146
  jQuery('.sbi_gdpr_yes').show();
1147
  jQuery('.sbi_gdpr_no, .sbi_gdpr_auto').hide();
1141
  sbiCheckGdprSetting( jQuery(this).val() );
1142
  });
1143
  function sbiCheckGdprSetting(option) {
 
1144
  if( option == 'yes' ){
1145
  jQuery('.sbi_gdpr_yes').show();
1146
  jQuery('.sbi_gdpr_no, .sbi_gdpr_auto').hide();
js/sbi-scripts.js CHANGED
@@ -289,8 +289,6 @@ if(!sbi_js_exists) {
289
  $(this.el).find('.sbi_item').each(function() {
290
  feed.lazyLoadCheck($(this));
291
  });
292
-
293
-
294
  },
295
  initLayout: function() {
296
 
@@ -677,7 +675,7 @@ if(!sbi_js_exists) {
677
  $(this).addClass('sbi_img_error');
678
  var sourceFromAPI = ($(this).attr('src').indexOf('media/?size=') > -1 || $(this).attr('src').indexOf('cdninstagram') > -1 || $(this).attr('src').indexOf('fbcdn') > -1)
679
 
680
- if (!sourceFromAPI) {
681
 
682
  if ($(this).closest('.sbi_photo').attr('data-img-src-set') !== 'undefined') {
683
  var srcSet = JSON.parse($(this).closest('.sbi_photo').attr('data-img-src-set').replace(/\\\//g, '/'));
@@ -946,6 +944,8 @@ if(!sbi_js_exists) {
946
  this.settings.consentGiven = sbiCmplzGetCookie('complianz_consent_status') === 'allow';
947
  } else if (typeof window.Cookiebot !== "undefined") { // Cookiebot by Cybot A/S
948
  this.settings.consentGiven = Cookiebot.consented;
 
 
949
  }
950
 
951
  var evt = jQuery.Event('sbicheckconsent');
@@ -1069,6 +1069,14 @@ if(!sbi_js_exists) {
1069
  window.sbi.feeds[ index ].afterConsentToggled();
1070
  });
1071
  });
 
 
 
 
 
 
 
 
1072
  });
1073
 
1074
  } // if sbi_js_exists
289
  $(this.el).find('.sbi_item').each(function() {
290
  feed.lazyLoadCheck($(this));
291
  });
 
 
292
  },
293
  initLayout: function() {
294
 
675
  $(this).addClass('sbi_img_error');
676
  var sourceFromAPI = ($(this).attr('src').indexOf('media/?size=') > -1 || $(this).attr('src').indexOf('cdninstagram') > -1 || $(this).attr('src').indexOf('fbcdn') > -1)
677
 
678
+ if (!sourceFromAPI && feed.settings.consentGiven) {
679
 
680
  if ($(this).closest('.sbi_photo').attr('data-img-src-set') !== 'undefined') {
681
  var srcSet = JSON.parse($(this).closest('.sbi_photo').attr('data-img-src-set').replace(/\\\//g, '/'));
944
  this.settings.consentGiven = sbiCmplzGetCookie('complianz_consent_status') === 'allow';
945
  } else if (typeof window.Cookiebot !== "undefined") { // Cookiebot by Cybot A/S
946
  this.settings.consentGiven = Cookiebot.consented;
947
+ } else if (typeof window.BorlabsCookie !== 'undefined') { // Borlabs Cookie by Borlabs
948
+ this.settings.consentGiven = window.BorlabsCookie.checkCookieConsent('instagram');
949
  }
950
 
951
  var evt = jQuery.Event('sbicheckconsent');
1069
  window.sbi.feeds[ index ].afterConsentToggled();
1070
  });
1071
  });
1072
+
1073
+ // Borlabs Cookie by Borlabs
1074
+ $(document).on('borlabs-cookie-consent-saved', function (event) {
1075
+ $.each(window.sbi.feeds,function(index){
1076
+ window.sbi.feeds[ index ].settings.consentGiven = false;
1077
+ window.sbi.feeds[ index ].afterConsentToggled();
1078
+ });
1079
+ });
1080
  });
1081
 
1082
  } // if sbi_js_exists
js/sbi-scripts.min.js CHANGED
@@ -1 +1 @@
1
- var sbi_js_exists=void 0!==sbi_js_exists;sbi_js_exists||(!function(i){function e(){var i,e,t,s=s||{VER:"0.9.944"};s.bgs_Available=!1,s.bgs_CheckRunned=!1,function(i){i.fn.extend({sbi_imgLiquid:function(e){this.defaults={fill:!0,verticalAlign:"center",horizontalAlign:"center",useBackgroundSize:!0,useDataHtmlAttr:!0,responsive:!0,delay:0,fadeInTime:0,removeBoxBackground:!0,hardPixels:!0,responsiveCheckTime:500,timecheckvisibility:500,onStart:null,onFinish:null,onItemStart:null,onItemFinish:null,onItemError:null},function(){if(!s.bgs_CheckRunned){s.bgs_CheckRunned=!0;var e=i('<span style="background-size:cover" />');i("body").append(e),function(){var i=e[0];if(i&&window.getComputedStyle){var t=window.getComputedStyle(i,null);t&&t.backgroundSize&&(s.bgs_Available="cover"===t.backgroundSize)}}(),e.remove()}}();var t=this;return this.options=e,this.settings=i.extend({},this.defaults,this.options),this.settings.onStart&&this.settings.onStart(),this.each(function(e){function n(){(r.responsive||h.data("sbi_imgLiquid_oldProcessed"))&&h.data("sbi_imgLiquid_settings")&&(r=h.data("sbi_imgLiquid_settings"),l.actualSize=l.get(0).offsetWidth+l.get(0).offsetHeight/1e4,l.sizeOld&&l.actualSize!==l.sizeOld&&o(),l.sizeOld=l.actualSize,setTimeout(n,r.responsiveCheckTime))}function a(){h.data("sbi_imgLiquid_error",!0),l.addClass("sbi_imgLiquid_error"),r.onItemError&&r.onItemError(e,l,h),d()}function o(){var i,t,s,n,a,o,g,c,f=0,u=0,b=l.width(),_=l.height();void 0===h.data("owidth")&&h.data("owidth",h[0].width),void 0===h.data("oheight")&&h.data("oheight",h[0].height),r.fill===b/_>=h.data("owidth")/h.data("oheight")?(i="100%",t="auto",s=Math.floor(b),n=Math.floor(b*(h.data("oheight")/h.data("owidth")))):(i="auto",t="100%",s=Math.floor(_*(h.data("owidth")/h.data("oheight"))),n=Math.floor(_)),g=b-s,"left"===(a=r.horizontalAlign.toLowerCase())&&(u=0),"center"===a&&(u=.5*g),"right"===a&&(u=g),-1!==a.indexOf("%")&&((a=parseInt(a.replace("%",""),10))>0&&(u=g*a*.01)),c=_-n,"left"===(o=r.verticalAlign.toLowerCase())&&(f=0),"center"===o&&(f=.5*c),"bottom"===o&&(f=c),-1!==o.indexOf("%")&&((o=parseInt(o.replace("%",""),10))>0&&(f=c*o*.01)),r.hardPixels&&(i=s,t=n),h.css({width:i,height:t,"margin-left":Math.floor(u),"margin-top":Math.floor(f)}),h.data("sbi_imgLiquid_oldProcessed")||(h.fadeTo(r.fadeInTime,1),h.data("sbi_imgLiquid_oldProcessed",!0),r.removeBoxBackground&&l.css("background-image","none"),l.addClass("sbi_imgLiquid_nobgSize"),l.addClass("sbi_imgLiquid_ready")),r.onItemFinish&&r.onItemFinish(e,l,h),d()}function d(){e===t.length-1&&t.settings.onFinish&&t.settings.onFinish()}var r=t.settings,l=i(this),h=i("img:first",l);return h.length?(h.data("sbi_imgLiquid_settings")?(l.removeClass("sbi_imgLiquid_error").removeClass("sbi_imgLiquid_ready"),r=i.extend({},h.data("sbi_imgLiquid_settings"),t.options)):r=i.extend({},t.settings,function(){var i={};if(t.settings.useDataHtmlAttr){var e=l.attr("data-sbi_imgLiquid-fill"),n=l.attr("data-sbi_imgLiquid-horizontalAlign"),a=l.attr("data-sbi_imgLiquid-verticalAlign");("true"===e||"false"===e)&&(i.fill=Boolean("true"===e)),void 0===n||"left"!==n&&"center"!==n&&"right"!==n&&-1===n.indexOf("%")||(i.horizontalAlign=n),void 0===a||"top"!==a&&"bottom"!==a&&"center"!==a&&-1===a.indexOf("%")||(i.verticalAlign=a)}return s.isIE&&t.settings.ieFadeInDisabled&&(i.fadeInTime=0),i}()),h.data("sbi_imgLiquid_settings",r),r.onItemStart&&r.onItemStart(e,l,h),void(s.bgs_Available&&r.useBackgroundSize?(-1===l.css("background-image").indexOf(encodeURI(h.attr("src")))&&l.css({"background-image":'url("'+encodeURI(h.attr("src"))+'")'}),l.css({"background-size":r.fill?"cover":"contain","background-position":(r.horizontalAlign+" "+r.verticalAlign).toLowerCase(),"background-repeat":"no-repeat"}),i("a:first",l).css({display:"block",width:"100%",height:"100%"}),i("img",l).css({display:"none"}),r.onItemFinish&&r.onItemFinish(e,l,h),l.addClass("sbi_imgLiquid_bgSize"),l.addClass("sbi_imgLiquid_ready"),d()):function t(){if(h.data("oldSrc")&&h.data("oldSrc")!==h.attr("src")){var s=h.clone().removeAttr("style");return s.data("sbi_imgLiquid_settings",h.data("sbi_imgLiquid_settings")),h.parent().prepend(s),h.remove(),(h=s)[0].width=0,void setTimeout(t,10)}return h.data("sbi_imgLiquid_oldProcessed")?void o():(h.data("sbi_imgLiquid_oldProcessed",!1),h.data("oldSrc",h.attr("src")),i("img:not(:first)",l).css("display","none"),l.css({overflow:"hidden"}),h.fadeTo(0,0).removeAttr("width").removeAttr("height").css({visibility:"visible","max-width":"none","max-height":"none",width:"auto",height:"auto",display:"block"}),h.on("error",a),h[0].onerror=a,function i(){h.data("sbi_imgLiquid_error")||h.data("sbi_imgLiquid_loaded")||h.data("sbi_imgLiquid_oldProcessed")||(l.is(":visible")&&h[0].complete&&h[0].width>0&&h[0].height>0?(h.data("sbi_imgLiquid_loaded",!0),setTimeout(o,e*r.delay)):setTimeout(i,r.timecheckvisibility))}(),void n())}())):void a()})}})}(jQuery),i=s.injectCss,e=document.getElementsByTagName("head")[0],(t=document.createElement("style")).type="text/css",t.styleSheet?t.styleSheet.cssText=i:t.appendChild(document.createTextNode(i)),e.appendChild(t)}function t(){this.feeds={},this.options=sb_instagram_js_options}function s(i,e,t){this.el=i,this.index=e,this.settings=t,this.minImageWidth=0,this.imageResolution=150,this.resizedImages={},this.needsResizing=[],this.outOfPages=!1,this.isInitialized=!1}function n(e,t){i.ajax({url:sbiajaxurl,type:"post",data:e,success:t})}t.prototype={createPage:function(e,t){void 0!==window.sbiajaxurl&&-1!==window.sbiajaxurl.indexOf(window.location.hostname)||(window.sbiajaxurl=location.protocol+"//"+window.location.hostname+"/wp-admin/admin-ajax.php"),i(".sbi_no_js_error_message").remove(),i(".sbi_no_js").removeClass("sbi_no_js"),e(t)},createFeeds:function(e){e.whenFeedsCreated(i(".sbi").each(function(e){i(this).attr("data-sbi-index",e+1);var t=i(this),a=void 0!==t.attr("data-sbi-flags")?t.attr("data-sbi-flags").split(","):[],o=void 0!==t.attr("data-options")?JSON.parse(t.attr("data-options")):{};if(a.indexOf("testAjax")>-1){window.sbi.triggeredTest=!0;n({action:"sbi_on_ajax_test_trigger"},function(i){console.log("did test")})}var d={cols:t.attr("data-cols"),colsmobile:void 0!==t.attr("data-colsmobile")&&"same"!==t.attr("data-colsmobile")?t.attr("data-colsmobile"):t.attr("data-cols"),num:t.attr("data-num"),imgRes:t.attr("data-res"),feedID:t.attr("data-feedid"),shortCodeAtts:t.attr("data-shortcode-atts"),resizingEnabled:-1===a.indexOf("resizeDisable"),imageLoadEnabled:-1===a.indexOf("imageLoadDisable"),debugEnabled:a.indexOf("debug")>-1,favorLocal:a.indexOf("favorLocal")>-1,ajaxPostLoad:a.indexOf("ajaxPostLoad")>-1,gdpr:a.indexOf("gdpr")>-1,overrideBlockCDN:a.indexOf("overrideBlockCDN")>-1,consentGiven:!1,autoMinRes:1,general:o};window.sbi.feeds[e]=function(i,e,t){return new s(i,e,t)}(this,e,d),window.sbi.feeds[e].setResizedImages(),window.sbi.feeds[e].init();var r=jQuery.Event("sbiafterfeedcreate");r.feed=window.sbi.feeds[e],jQuery(window).trigger(r)}))},afterFeedsCreated:function(){i(".sb_instagram_header").each(function(){var e=i(this);e.find(".sbi_header_link").hover(function(){e.find(".sbi_header_img_hover").addClass("sbi_fade_in")},function(){e.find(".sbi_header_img_hover").removeClass("sbi_fade_in")})})},encodeHTML:function(i){return void 0===i?"":i.replace(/(>)/g,"&gt;").replace(/(<)/g,"&lt;").replace(/(&lt;br\/&gt;)/g,"<br>").replace(/(&lt;br&gt;)/g,"<br>")},urlDetect:function(i){return i.match(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)/g)}},s.prototype={init:function(){var e=this;e.settings.consentGiven=e.checkConsent(),i(this.el).find(".sbi_photo").parent("p").length&&i(this.el).addClass("sbi_no_autop"),i(this.el).find("#sbi_mod_error").length&&i(this.el).prepend(i(this.el).find("#sbi_mod_error")),this.settings.ajaxPostLoad?this.getNewPostSet():this.afterInitialImagesLoaded();var t,s=(t=0,function(i,e){clearTimeout(t),t=setTimeout(i,e)});jQuery(window).resize(function(){s(function(){e.afterResize()},500)}),i(this.el).find(".sbi_item").each(function(){e.lazyLoadCheck(i(this))})},initLayout:function(){},afterInitialImagesLoaded:function(){this.initLayout(),this.loadMoreButtonInit(),this.hideExtraImagesForWidth(),this.beforeNewImagesRevealed(),this.revealNewImages(),this.afterNewImagesRevealed()},afterResize:function(){this.setImageHeight(),this.setImageResolution(),this.maybeRaiseImageResolution(),this.setImageSizeClass()},afterLoadMoreClicked:function(i){i.find(".sbi_loader").removeClass("sbi_hidden"),i.find(".sbi_btn_text").addClass("sbi_hidden"),i.closest(".sbi").find(".sbi_num_diff_hide").addClass("sbi_transition").removeClass("sbi_num_diff_hide")},afterNewImagesLoaded:function(){var e=i(this.el),t=this;this.beforeNewImagesRevealed(),this.revealNewImages(),this.afterNewImagesRevealed(),setTimeout(function(){e.find(".sbi_loader").addClass("sbi_hidden"),e.find(".sbi_btn_text").removeClass("sbi_hidden"),t.maybeRaiseImageResolution()},500)},beforeNewImagesRevealed:function(){this.setImageHeight(),this.maybeRaiseImageResolution(!0),this.setImageSizeClass()},revealNewImages:function(){var e=i(this.el);e.find(".sbi-screenreader").each(function(){i(this).find("img").remove()}),"function"==typeof sbi_custom_js&&setTimeout(function(){sbi_custom_js()},100),this.applyImageLiquid(),e.find(".sbi_item").each(function(i){jQuery(this).find(".sbi_photo").hover(function(){jQuery(this).fadeTo(200,.85)},function(){jQuery(this).stop().fadeTo(500,1)})}),setTimeout(function(){jQuery("#sbi_images .sbi_item.sbi_new").removeClass("sbi_new");var i=10;e.find(".sbi_transition").each(function(){var e=jQuery(this);setTimeout(function(){e.removeClass("sbi_transition")},i),i+=10})},500)},lazyLoadCheck:function(e){if(e.find(".sbi_photo").length&&!e.closest(".sbi").hasClass("sbi-no-ll-check")){var t=this.getImageUrls(e),s=void 0!==t[640]?t[640]:e.find(".sbi_photo").attr("data-full-res");if(!this.settings.consentGiven&&s.indexOf("scontent")>-1)return;e.find(".sbi_photo img").each(function(){s&&void 0!==i(this).attr("data-src")&&i(this).attr("data-src",s),s&&void 0!==i(this).attr("data-orig-src")&&i(this).attr("data-orig-src",s),i(this).on("load",function(){!i(this).hasClass("sbi-replaced")&&i(this).attr("src").indexOf("placeholder")>-1&&(i(this).addClass("sbi-replaced"),s&&(i(this).attr("src",s),i(this).closest(".sbi_imgLiquid_bgSize").length&&i(this).closest(".sbi_imgLiquid_bgSize").css("background-image","url("+s+")")))})})}},afterNewImagesRevealed:function(){this.listenForVisibilityChange(),this.sendNeedsResizingToServer(),this.settings.imageLoadEnabled||i(".sbi_no_resraise").removeClass("sbi_no_resraise");var e=i.Event("sbiafterimagesloaded");e.el=i(this.el),i(window).trigger(e)},setResizedImages:function(){i(this.el).find(".sbi_resized_image_data").length&&void 0!==i(this.el).find(".sbi_resized_image_data").attr("data-resized")&&0===i(this.el).find(".sbi_resized_image_data").attr("data-resized").indexOf('{"')&&(this.resizedImages=JSON.parse(i(this.el).find(".sbi_resized_image_data").attr("data-resized")),i(this.el).find(".sbi_resized_image_data").remove())},sendNeedsResizingToServer:function(){var e=this;if(e.needsResizing.length>0&&e.settings.resizingEnabled){var t=i(this.el).find(".sbi_item").length,s=void 0!==e.settings.general.cache_all&&e.settings.general.cache_all;n({action:"sbi_resized_images_submit",needs_resizing:e.needsResizing,offset:t,feed_id:e.settings.feedID,atts:e.settings.shortCodeAtts,cache_all:s},function(i){if(0===i.trim().indexOf("{")){var t=JSON.parse(i);for(var s in e.settings.debugEnabled&&console.log(t),t)t.hasOwnProperty(s)&&(e.resizedImages[s]=t[s]);e.maybeRaiseImageResolution(),setTimeout(function(){e.afterResize()},500)}})}},loadMoreButtonInit:function(){var e=i(this.el),t=this;e.find("#sbi_load .sbi_load_btn").off().on("click",function(){t.afterLoadMoreClicked(jQuery(this)),t.getNewPostSet()})},getNewPostSet:function(){var e=i(this.el),t=this;n({action:"sbi_load_more_clicked",offset:e.find(".sbi_item").length,feed_id:t.settings.feedID,atts:t.settings.shortCodeAtts,current_resolution:t.imageResolution},function(s){if(0===s.trim().indexOf("{")){var n=JSON.parse(s);t.settings.debugEnabled&&console.log(n),t.appendNewPosts(n.html),t.addResizedImages(n.resizedImages),t.settings.ajaxPostLoad?(t.settings.ajaxPostLoad=!1,t.afterInitialImagesLoaded()):t.afterNewImagesLoaded(),n.feedStatus.shouldPaginate?t.outOfPages=!1:(t.outOfPages=!0,e.find(".sbi_load_btn").hide()),i(".sbi_no_js").removeClass("sbi_no_js")}})},appendNewPosts:function(e){var t=i(this.el);t.find("#sbi_images .sbi_item").length?t.find("#sbi_images .sbi_item").last().after(e):t.find("#sbi_images").append(e)},addResizedImages:function(i){for(var e in i)this.resizedImages[e]=i[e]},setImageHeight:function(){var e=i(this.el),t=e.find(".sbi_photo").eq(0).innerWidth(),s=this.getColumnCount(),n=e.find("#sbi_images").innerWidth()-e.find("#sbi_images").width(),a=n/2;sbi_photo_width_manual=e.find("#sbi_images").width()/s-n,e.find(".sbi_photo").css("height",t),e.find(".sbi-owl-nav").length&&setTimeout(function(){var i=2;e.find(".sbi_owl2row-item").length&&(i=1);var t=e.find(".sbi_photo").eq(0).innerWidth()/i;t+=parseInt(a)*(2-i+2),e.find(".sbi-owl-nav div").css("top",t)},100)},maybeRaiseSingleImageResolution:function(e,t,s){var n=this,a=n.getImageUrls(e),o=e.find(".sbi_photo img").attr("src"),d=150,r=e.find("img").get(0),l=o===window.sbi.options.placeholder?1:r.naturalWidth/r.naturalHeight;s=void 0!==s&&s;if(!(e.hasClass("sbi_no_resraise")||e.hasClass("sbi_had_error")||e.find(".sbi_link_area").length&&e.find(".sbi_link_area").hasClass("sbi_had_error")))if(a.length<1)e.find(".sbi_link_area").length&&e.find(".sbi_link_area").attr("href",window.sbi.options.placeholder.replace("placeholder.png","thumb-placeholder.png"));else{(e.find(".sbi_link_area").length&&e.find(".sbi_link_area").attr("href")===window.sbi.options.placeholder.replace("placeholder.png","thumb-placeholder.png")||!n.settings.consentGiven)&&e.find(".sbi_link_area").attr("href",a[a.length-1]),void 0!==a[640]&&e.find(".sbi_photo").attr("data-full-res",a[640]),i.each(a,function(i,e){e===o&&(d=parseInt(i),s=!1)});var h=640;switch(n.settings.imgRes){case"thumb":h=150;break;case"medium":h=320;break;case"full":h=640;break;default:var g=Math.max(n.settings.autoMinRes,e.find(".sbi_photo").innerWidth()),c=n.getBestResolutionForAuto(g,l,e);switch(c){case 320:h=320;break;case 150:h=150}}if(h>d||o===window.sbi.options.placeholder||s){if(n.settings.debugEnabled){var f=o===window.sbi.options.placeholder?"was placeholder":"too small";console.log("rais res for "+o,f)}var u=a[h].split("?ig_cache_key")[0];if(o!==u&&(e.find(".sbi_photo img").attr("src",u),e.find(".sbi_photo").css("background-image",'url("'+u+'")')),d=h,"auto"===n.settings.imgRes){var b=!1;e.find(".sbi_photo img").on("load",function(){var t=i(this),s=t.get(0).naturalWidth/t.get(0).naturalHeight;if(1e3!==t.get(0).naturalWidth&&s>l&&!b){switch(n.settings.debugEnabled&&console.log("rais res again for aspect ratio change "+o),b=!0,g=e.find(".sbi_photo").innerWidth(),c=n.getBestResolutionForAuto(g,s,e),h=640,c){case 320:h=320;break;case 150:h=150}h>d&&(u=a[h].split("?ig_cache_key")[0],t.attr("src",u),t.closest(".sbi_photo").css("background-image",'url("'+u+'")')),"masonry"!==n.layout&&"highlight"!==n.layout||(i(n.el).find("#sbi_images").smashotope(n.isotopeArgs),setTimeout(function(){i(n.el).find("#sbi_images").smashotope(n.isotopeArgs)},500))}else if(n.settings.debugEnabled){var r=b?"already checked":"no aspect ratio change";console.log("not raising res for replacement "+o,r)}})}}e.find("img").on("error",function(){if(i(this).hasClass("sbi_img_error"))console.log("unfixed error "+i(this).attr("src"));else{var e;if(i(this).addClass("sbi_img_error"),i(this).attr("src").indexOf("media/?size=")>-1||i(this).attr("src").indexOf("cdninstagram")>-1||i(this).attr("src").indexOf("fbcdn")>-1)n.settings.favorLocal=!0,void 0!==(e=n.getImageUrls(i(this).closest(".sbi_item")))[640]&&(i(this).attr("src",e[640]),i(this).closest(".sbi_photo").css("background-image","url("+e[640]+")"),i(this).closest(".sbi_item").addClass("sbi_had_error").find(".sbi_link_area").attr("href",e[640]).addClass("sbi_had_error"));else if("undefined"!==i(this).closest(".sbi_photo").attr("data-img-src-set"))void 0!==(e=JSON.parse(i(this).closest(".sbi_photo").attr("data-img-src-set").replace(/\\\//g,"/"))).d&&(i(this).attr("src",e.d),i(this).closest(".sbi_photo").css("background-image","url("+e.d+")"),i(this).closest(".sbi_item").addClass("sbi_had_error").find(".sbi_link_area").attr("href",e[640]).addClass("sbi_had_error"));setTimeout(function(){n.afterResize()},1500)}})}},maybeRaiseImageResolution:function(e){var t=this,s=void 0!==e&&!0===e?".sbi_item.sbi_new":".sbi_item",n=!t.isInitialized;i(t.el).find(s).each(function(e){!i(this).hasClass("sbi_num_diff_hide")&&i(this).find(".sbi_photo").length&&void 0!==i(this).find(".sbi_photo").attr("data-img-src-set")&&t.maybeRaiseSingleImageResolution(i(this),e,n)}),t.isInitialized=!0},getBestResolutionForAuto:function(e,t,s){(isNaN(t)||t<1)&&(t=1);var n=e*t,a=10*Math.ceil(n/10),o=[150,320,640];if(s.hasClass("sbi_highlighted")&&(a*=2),-1===o.indexOf(parseInt(a))){var d=!1;i.each(o,function(i,e){e>parseInt(a)&&!d&&(a=e,d=!0)})}return a},hideExtraImagesForWidth:function(){if("carousel"!==this.layout){var e=i(this.el),t=void 0!==e.attr("data-num")&&""!==e.attr("data-num")?parseInt(e.attr("data-num")):1,s=void 0!==e.attr("data-nummobile")&&""!==e.attr("data-nummobile")?parseInt(e.attr("data-nummobile")):t;i(window).width()<480?s<e.find(".sbi_item").length&&e.find(".sbi_item").slice(s-e.find(".sbi_item").length).addClass("sbi_num_diff_hide"):t<e.find(".sbi_item").length&&e.find(".sbi_item").slice(t-e.find(".sbi_item").length).addClass("sbi_num_diff_hide")}},setImageSizeClass:function(){var e=i(this.el);e.removeClass("sbi_small sbi_medium");var t=e.innerWidth(),s=parseInt(e.find("#sbi_images").outerWidth()-e.find("#sbi_images").width())/2,n=this.getColumnCount(),a=(t-s*(n+2))/n;a>120&&a<240?e.addClass("sbi_medium"):a<=120&&e.addClass("sbi_small")},setMinImageWidth:function(){i(this.el).find(".sbi_item .sbi_photo").first().length?this.minImageWidth=i(this.el).find(".sbi_item .sbi_photo").first().innerWidth():this.minImageWidth=150},setImageResolution:function(){if("auto"===this.settings.imgRes)this.imageResolution="auto";else switch(this.settings.imgRes){case"thumb":this.imageResolution=150;break;case"medium":this.imageResolution=320;break;default:this.imageResolution=640}},getImageUrls:function(i){var e=JSON.parse(i.find(".sbi_photo").attr("data-img-src-set").replace(/\\\//g,"/")),t=i.attr("id").replace("sbi_","");if(this.settings.consentGiven||this.settings.overrideBlockCDN||(e=[]),void 0!==this.resizedImages[t]&&"video"!==this.resizedImages[t]&&"pending"!==this.resizedImages[t]&&"error"!==this.resizedImages[t].id&&"video"!==this.resizedImages[t].id&&"pending"!==this.resizedImages[t].id){if(void 0!==this.resizedImages[t].sizes){var s=[];void 0!==this.resizedImages[t].sizes.full&&(e[640]=sb_instagram_js_options.resized_url+this.resizedImages[t].id+"full.jpg",s.push(640)),void 0!==this.resizedImages[t].sizes.low&&(e[320]=sb_instagram_js_options.resized_url+this.resizedImages[t].id+"low.jpg",s.push(320)),void 0!==this.resizedImages[t].sizes.thumb&&(s.push(150),e[150]=sb_instagram_js_options.resized_url+this.resizedImages[t].id+"thumb.jpg"),this.settings.favorLocal&&(-1===s.indexOf(640)&&s.indexOf(320)>-1&&(e[640]=sb_instagram_js_options.resized_url+this.resizedImages[t].id+"low.jpg"),-1===s.indexOf(320)&&(s.indexOf(640)>-1?e[320]=sb_instagram_js_options.resized_url+this.resizedImages[t].id+"full.jpg":s.indexOf(150)>-1&&(e[320]=sb_instagram_js_options.resized_url+this.resizedImages[t].id+"thumb.jpg")),-1===s.indexOf(150)&&(s.indexOf(320)>-1?e[150]=sb_instagram_js_options.resized_url+this.resizedImages[t].id+"low.jpg":s.indexOf(640)>-1&&(e[150]=sb_instagram_js_options.resized_url+this.resizedImages[t].id+"full.jpg")))}}else(void 0===this.resizedImages[t]||void 0!==this.resizedImages[t].id&&"pending"!==this.resizedImages[t].id&&"error"!==this.resizedImages[t].id)&&this.addToNeedsResizing(t);return e},getAvatarUrl:function(i,e){if(""===i)return"";var t=this.settings.general.avatars;return"local"===(e=void 0!==e?e:"local")?void 0!==t["LCL"+i]&&1===parseInt(t["LCL"+i])?sb_instagram_js_options.resized_url+i+".jpg":void 0!==t[i]?t[i]:"":void 0!==t[i]?t[i]:void 0!==t["LCL"+i]&&1===parseInt(t["LCL"+i])?sb_instagram_js_options.resized_url+i+".jpg":""},addToNeedsResizing:function(i){-1===this.needsResizing.indexOf(i)&&this.needsResizing.push(i)},applyImageLiquid:function(){var t=i(this.el);e(),"function"==typeof t.find(".sbi_photo").sbi_imgLiquid&&t.find(".sbi_photo").sbi_imgLiquid({fill:!0})},listenForVisibilityChange:function(){var e,t,s,n=this;e=jQuery,t={callback:function(){},runOnLoad:!0,frequency:100,sbiPreviousVisibility:null},s={sbiCheckVisibility:function(i,e){if(jQuery.contains(document,i[0])){var t=e.sbiPreviousVisibility,n=i.is(":visible");e.sbiPreviousVisibility=n,null==t?e.runOnLoad&&e.callback(i,n):t!==n&&e.callback(i,n),setTimeout(function(){s.sbiCheckVisibility(i,e)},e.frequency)}}},e.fn.sbiVisibilityChanged=function(i){var n=e.extend({},t,i);return this.each(function(){s.sbiCheckVisibility(e(this),n)})},"function"==typeof i(this.el).filter(":hidden").sbiVisibilityChanged&&i(this.el).filter(":hidden").sbiVisibilityChanged({callback:function(i,e){n.afterResize()},runOnLoad:!1})},getColumnCount:function(){var e=i(this.el),t=this.settings.cols,s=this.settings.colsmobile,n=t;return sbiWindowWidth=window.innerWidth,e.hasClass("sbi_mob_col_auto")?(sbiWindowWidth<640&&parseInt(t)>2&&parseInt(t)<7&&(n=2),sbiWindowWidth<640&&parseInt(t)>6&&parseInt(t)<11&&(n=4),sbiWindowWidth<=480&&parseInt(t)>2&&(n=1)):sbiWindowWidth<=480&&(n=s),parseInt(n)},checkConsent:function(){if(this.settings.consentGiven||!this.settings.gdpr)return!0;if("undefined"!=typeof CLI_Cookie)null!==CLI_Cookie.read(CLI_ACCEPT_COOKIE_NAME)&&(this.settings.consentGiven="yes"===CLI_Cookie.read("cookielawinfo-checkbox-non-necessary"));else if(void 0!==window.cnArgs){var i=("; "+document.cookie).split("; cookie_notice_accepted=");if(2===i.length){var e=i.pop().split(";").shift();this.settings.consentGiven="true"===e}}else void 0!==window.cookieconsent?this.settings.consentGiven="allow"===function(i){for(var e=i+"=",t=window.document.cookie.split(";"),s=0;s<t.length;s++){var n=t[s].trim();if(0==n.indexOf(e))return n.substring(e.length,n.length)}return""}("complianz_consent_status"):void 0!==window.Cookiebot&&(this.settings.consentGiven=Cookiebot.consented);var t=jQuery.Event("sbicheckconsent");return t.feed=this,jQuery(window).trigger(t),this.settings.consentGiven},afterConsentToggled:function(){if(this.checkConsent()){var i=this;i.maybeRaiseImageResolution(),setTimeout(function(){i.afterResize()},500)}}},window.sbi_init=function(){window.sbi=new t,window.sbi.createPage(window.sbi.createFeeds,{whenFeedsCreated:window.sbi.afterFeedsCreated})}}(jQuery),jQuery(document).ready(function(i){void 0===window.sb_instagram_js_options&&(window.sb_instagram_js_options={font_method:"svg",resized_url:location.protocol+"//"+window.location.hostname+"/wp-content/uploads/sb-instagram-feed-images/",placeholder:location.protocol+"//"+window.location.hostname+"/wp-content/plugins/instagram-feed/img/placeholder.png"}),void 0!==window.sb_instagram_js_options.resized_url&&-1===window.sb_instagram_js_options.resized_url.indexOf(location.protocol)&&("http:"===location.protocol?window.sb_instagram_js_options.resized_url=window.sb_instagram_js_options.resized_url.replace("https:","http:"):window.sb_instagram_js_options.resized_url=window.sb_instagram_js_options.resized_url.replace("http:","https:")),sbi_init(),i("#cookie-notice a").click(function(){setTimeout(function(){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].afterConsentToggled()})},1e3)}),i("#cookie-law-info-bar a").click(function(){setTimeout(function(){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].afterConsentToggled()})},1e3)}),i(".cli-user-preference-checkbox").click(function(){setTimeout(function(){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].settings.consentGiven=!1,window.sbi.feeds[i].afterConsentToggled()})},1e3)}),i(window).on("CookiebotOnAccept",function(e){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].settings.consentGiven=!0,window.sbi.feeds[i].afterConsentToggled()})}),i(document).on("cmplzAcceptAll",function(e){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].settings.consentGiven=!0,window.sbi.feeds[i].afterConsentToggled()})}),i(document).on("cmplzRevoke",function(e){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].settings.consentGiven=!1,window.sbi.feeds[i].afterConsentToggled()})})}));
1
+ var sbi_js_exists=void 0!==sbi_js_exists;sbi_js_exists||(!function(i){function e(){var i,e,s,t=t||{VER:"0.9.944"};t.bgs_Available=!1,t.bgs_CheckRunned=!1,function(i){i.fn.extend({sbi_imgLiquid:function(e){this.defaults={fill:!0,verticalAlign:"center",horizontalAlign:"center",useBackgroundSize:!0,useDataHtmlAttr:!0,responsive:!0,delay:0,fadeInTime:0,removeBoxBackground:!0,hardPixels:!0,responsiveCheckTime:500,timecheckvisibility:500,onStart:null,onFinish:null,onItemStart:null,onItemFinish:null,onItemError:null},function(){if(!t.bgs_CheckRunned){t.bgs_CheckRunned=!0;var e=i('<span style="background-size:cover" />');i("body").append(e),function(){var i=e[0];if(i&&window.getComputedStyle){var s=window.getComputedStyle(i,null);s&&s.backgroundSize&&(t.bgs_Available="cover"===s.backgroundSize)}}(),e.remove()}}();var s=this;return this.options=e,this.settings=i.extend({},this.defaults,this.options),this.settings.onStart&&this.settings.onStart(),this.each(function(e){function n(){(r.responsive||h.data("sbi_imgLiquid_oldProcessed"))&&h.data("sbi_imgLiquid_settings")&&(r=h.data("sbi_imgLiquid_settings"),l.actualSize=l.get(0).offsetWidth+l.get(0).offsetHeight/1e4,l.sizeOld&&l.actualSize!==l.sizeOld&&o(),l.sizeOld=l.actualSize,setTimeout(n,r.responsiveCheckTime))}function a(){h.data("sbi_imgLiquid_error",!0),l.addClass("sbi_imgLiquid_error"),r.onItemError&&r.onItemError(e,l,h),d()}function o(){var i,s,t,n,a,o,g,c,f=0,u=0,b=l.width(),_=l.height();void 0===h.data("owidth")&&h.data("owidth",h[0].width),void 0===h.data("oheight")&&h.data("oheight",h[0].height),r.fill===b/_>=h.data("owidth")/h.data("oheight")?(i="100%",s="auto",t=Math.floor(b),n=Math.floor(b*(h.data("oheight")/h.data("owidth")))):(i="auto",s="100%",t=Math.floor(_*(h.data("owidth")/h.data("oheight"))),n=Math.floor(_)),g=b-t,"left"===(a=r.horizontalAlign.toLowerCase())&&(u=0),"center"===a&&(u=.5*g),"right"===a&&(u=g),-1!==a.indexOf("%")&&((a=parseInt(a.replace("%",""),10))>0&&(u=g*a*.01)),c=_-n,"left"===(o=r.verticalAlign.toLowerCase())&&(f=0),"center"===o&&(f=.5*c),"bottom"===o&&(f=c),-1!==o.indexOf("%")&&((o=parseInt(o.replace("%",""),10))>0&&(f=c*o*.01)),r.hardPixels&&(i=t,s=n),h.css({width:i,height:s,"margin-left":Math.floor(u),"margin-top":Math.floor(f)}),h.data("sbi_imgLiquid_oldProcessed")||(h.fadeTo(r.fadeInTime,1),h.data("sbi_imgLiquid_oldProcessed",!0),r.removeBoxBackground&&l.css("background-image","none"),l.addClass("sbi_imgLiquid_nobgSize"),l.addClass("sbi_imgLiquid_ready")),r.onItemFinish&&r.onItemFinish(e,l,h),d()}function d(){e===s.length-1&&s.settings.onFinish&&s.settings.onFinish()}var r=s.settings,l=i(this),h=i("img:first",l);return h.length?(h.data("sbi_imgLiquid_settings")?(l.removeClass("sbi_imgLiquid_error").removeClass("sbi_imgLiquid_ready"),r=i.extend({},h.data("sbi_imgLiquid_settings"),s.options)):r=i.extend({},s.settings,function(){var i={};if(s.settings.useDataHtmlAttr){var e=l.attr("data-sbi_imgLiquid-fill"),n=l.attr("data-sbi_imgLiquid-horizontalAlign"),a=l.attr("data-sbi_imgLiquid-verticalAlign");("true"===e||"false"===e)&&(i.fill=Boolean("true"===e)),void 0===n||"left"!==n&&"center"!==n&&"right"!==n&&-1===n.indexOf("%")||(i.horizontalAlign=n),void 0===a||"top"!==a&&"bottom"!==a&&"center"!==a&&-1===a.indexOf("%")||(i.verticalAlign=a)}return t.isIE&&s.settings.ieFadeInDisabled&&(i.fadeInTime=0),i}()),h.data("sbi_imgLiquid_settings",r),r.onItemStart&&r.onItemStart(e,l,h),void(t.bgs_Available&&r.useBackgroundSize?(-1===l.css("background-image").indexOf(encodeURI(h.attr("src")))&&l.css({"background-image":'url("'+encodeURI(h.attr("src"))+'")'}),l.css({"background-size":r.fill?"cover":"contain","background-position":(r.horizontalAlign+" "+r.verticalAlign).toLowerCase(),"background-repeat":"no-repeat"}),i("a:first",l).css({display:"block",width:"100%",height:"100%"}),i("img",l).css({display:"none"}),r.onItemFinish&&r.onItemFinish(e,l,h),l.addClass("sbi_imgLiquid_bgSize"),l.addClass("sbi_imgLiquid_ready"),d()):function s(){if(h.data("oldSrc")&&h.data("oldSrc")!==h.attr("src")){var t=h.clone().removeAttr("style");return t.data("sbi_imgLiquid_settings",h.data("sbi_imgLiquid_settings")),h.parent().prepend(t),h.remove(),(h=t)[0].width=0,void setTimeout(s,10)}return h.data("sbi_imgLiquid_oldProcessed")?void o():(h.data("sbi_imgLiquid_oldProcessed",!1),h.data("oldSrc",h.attr("src")),i("img:not(:first)",l).css("display","none"),l.css({overflow:"hidden"}),h.fadeTo(0,0).removeAttr("width").removeAttr("height").css({visibility:"visible","max-width":"none","max-height":"none",width:"auto",height:"auto",display:"block"}),h.on("error",a),h[0].onerror=a,function i(){h.data("sbi_imgLiquid_error")||h.data("sbi_imgLiquid_loaded")||h.data("sbi_imgLiquid_oldProcessed")||(l.is(":visible")&&h[0].complete&&h[0].width>0&&h[0].height>0?(h.data("sbi_imgLiquid_loaded",!0),setTimeout(o,e*r.delay)):setTimeout(i,r.timecheckvisibility))}(),void n())}())):void a()})}})}(jQuery),i=t.injectCss,e=document.getElementsByTagName("head")[0],(s=document.createElement("style")).type="text/css",s.styleSheet?s.styleSheet.cssText=i:s.appendChild(document.createTextNode(i)),e.appendChild(s)}function s(){this.feeds={},this.options=sb_instagram_js_options}function t(i,e,s){this.el=i,this.index=e,this.settings=s,this.minImageWidth=0,this.imageResolution=150,this.resizedImages={},this.needsResizing=[],this.outOfPages=!1,this.isInitialized=!1}function n(e,s){i.ajax({url:sbiajaxurl,type:"post",data:e,success:s})}s.prototype={createPage:function(e,s){void 0!==window.sbiajaxurl&&-1!==window.sbiajaxurl.indexOf(window.location.hostname)||(window.sbiajaxurl=location.protocol+"//"+window.location.hostname+"/wp-admin/admin-ajax.php"),i(".sbi_no_js_error_message").remove(),i(".sbi_no_js").removeClass("sbi_no_js"),e(s)},createFeeds:function(e){e.whenFeedsCreated(i(".sbi").each(function(e){i(this).attr("data-sbi-index",e+1);var s=i(this),a=void 0!==s.attr("data-sbi-flags")?s.attr("data-sbi-flags").split(","):[],o=void 0!==s.attr("data-options")?JSON.parse(s.attr("data-options")):{};if(a.indexOf("testAjax")>-1){window.sbi.triggeredTest=!0;n({action:"sbi_on_ajax_test_trigger"},function(i){console.log("did test")})}var d={cols:s.attr("data-cols"),colsmobile:void 0!==s.attr("data-colsmobile")&&"same"!==s.attr("data-colsmobile")?s.attr("data-colsmobile"):s.attr("data-cols"),num:s.attr("data-num"),imgRes:s.attr("data-res"),feedID:s.attr("data-feedid"),shortCodeAtts:s.attr("data-shortcode-atts"),resizingEnabled:-1===a.indexOf("resizeDisable"),imageLoadEnabled:-1===a.indexOf("imageLoadDisable"),debugEnabled:a.indexOf("debug")>-1,favorLocal:a.indexOf("favorLocal")>-1,ajaxPostLoad:a.indexOf("ajaxPostLoad")>-1,gdpr:a.indexOf("gdpr")>-1,overrideBlockCDN:a.indexOf("overrideBlockCDN")>-1,consentGiven:!1,autoMinRes:1,general:o};window.sbi.feeds[e]=function(i,e,s){return new t(i,e,s)}(this,e,d),window.sbi.feeds[e].setResizedImages(),window.sbi.feeds[e].init();var r=jQuery.Event("sbiafterfeedcreate");r.feed=window.sbi.feeds[e],jQuery(window).trigger(r)}))},afterFeedsCreated:function(){i(".sb_instagram_header").each(function(){var e=i(this);e.find(".sbi_header_link").hover(function(){e.find(".sbi_header_img_hover").addClass("sbi_fade_in")},function(){e.find(".sbi_header_img_hover").removeClass("sbi_fade_in")})})},encodeHTML:function(i){return void 0===i?"":i.replace(/(>)/g,"&gt;").replace(/(<)/g,"&lt;").replace(/(&lt;br\/&gt;)/g,"<br>").replace(/(&lt;br&gt;)/g,"<br>")},urlDetect:function(i){return i.match(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)/g)}},t.prototype={init:function(){var e=this;e.settings.consentGiven=e.checkConsent(),i(this.el).find(".sbi_photo").parent("p").length&&i(this.el).addClass("sbi_no_autop"),i(this.el).find("#sbi_mod_error").length&&i(this.el).prepend(i(this.el).find("#sbi_mod_error")),this.settings.ajaxPostLoad?this.getNewPostSet():this.afterInitialImagesLoaded();var s,t=(s=0,function(i,e){clearTimeout(s),s=setTimeout(i,e)});jQuery(window).resize(function(){t(function(){e.afterResize()},500)}),i(this.el).find(".sbi_item").each(function(){e.lazyLoadCheck(i(this))})},initLayout:function(){},afterInitialImagesLoaded:function(){this.initLayout(),this.loadMoreButtonInit(),this.hideExtraImagesForWidth(),this.beforeNewImagesRevealed(),this.revealNewImages(),this.afterNewImagesRevealed()},afterResize:function(){this.setImageHeight(),this.setImageResolution(),this.maybeRaiseImageResolution(),this.setImageSizeClass()},afterLoadMoreClicked:function(i){i.find(".sbi_loader").removeClass("sbi_hidden"),i.find(".sbi_btn_text").addClass("sbi_hidden"),i.closest(".sbi").find(".sbi_num_diff_hide").addClass("sbi_transition").removeClass("sbi_num_diff_hide")},afterNewImagesLoaded:function(){var e=i(this.el),s=this;this.beforeNewImagesRevealed(),this.revealNewImages(),this.afterNewImagesRevealed(),setTimeout(function(){e.find(".sbi_loader").addClass("sbi_hidden"),e.find(".sbi_btn_text").removeClass("sbi_hidden"),s.maybeRaiseImageResolution()},500)},beforeNewImagesRevealed:function(){this.setImageHeight(),this.maybeRaiseImageResolution(!0),this.setImageSizeClass()},revealNewImages:function(){var e=i(this.el);e.find(".sbi-screenreader").each(function(){i(this).find("img").remove()}),"function"==typeof sbi_custom_js&&setTimeout(function(){sbi_custom_js()},100),this.applyImageLiquid(),e.find(".sbi_item").each(function(i){jQuery(this).find(".sbi_photo").hover(function(){jQuery(this).fadeTo(200,.85)},function(){jQuery(this).stop().fadeTo(500,1)})}),setTimeout(function(){jQuery("#sbi_images .sbi_item.sbi_new").removeClass("sbi_new");var i=10;e.find(".sbi_transition").each(function(){var e=jQuery(this);setTimeout(function(){e.removeClass("sbi_transition")},i),i+=10})},500)},lazyLoadCheck:function(e){if(e.find(".sbi_photo").length&&!e.closest(".sbi").hasClass("sbi-no-ll-check")){var s=this.getImageUrls(e),t=void 0!==s[640]?s[640]:e.find(".sbi_photo").attr("data-full-res");if(!this.settings.consentGiven&&t.indexOf("scontent")>-1)return;e.find(".sbi_photo img").each(function(){t&&void 0!==i(this).attr("data-src")&&i(this).attr("data-src",t),t&&void 0!==i(this).attr("data-orig-src")&&i(this).attr("data-orig-src",t),i(this).on("load",function(){!i(this).hasClass("sbi-replaced")&&i(this).attr("src").indexOf("placeholder")>-1&&(i(this).addClass("sbi-replaced"),t&&(i(this).attr("src",t),i(this).closest(".sbi_imgLiquid_bgSize").length&&i(this).closest(".sbi_imgLiquid_bgSize").css("background-image","url("+t+")")))})})}},afterNewImagesRevealed:function(){this.listenForVisibilityChange(),this.sendNeedsResizingToServer(),this.settings.imageLoadEnabled||i(".sbi_no_resraise").removeClass("sbi_no_resraise");var e=i.Event("sbiafterimagesloaded");e.el=i(this.el),i(window).trigger(e)},setResizedImages:function(){i(this.el).find(".sbi_resized_image_data").length&&void 0!==i(this.el).find(".sbi_resized_image_data").attr("data-resized")&&0===i(this.el).find(".sbi_resized_image_data").attr("data-resized").indexOf('{"')&&(this.resizedImages=JSON.parse(i(this.el).find(".sbi_resized_image_data").attr("data-resized")),i(this.el).find(".sbi_resized_image_data").remove())},sendNeedsResizingToServer:function(){var e=this;if(e.needsResizing.length>0&&e.settings.resizingEnabled){var s=i(this.el).find(".sbi_item").length,t=void 0!==e.settings.general.cache_all&&e.settings.general.cache_all;n({action:"sbi_resized_images_submit",needs_resizing:e.needsResizing,offset:s,feed_id:e.settings.feedID,atts:e.settings.shortCodeAtts,cache_all:t},function(i){if(0===i.trim().indexOf("{")){var s=JSON.parse(i);for(var t in e.settings.debugEnabled&&console.log(s),s)s.hasOwnProperty(t)&&(e.resizedImages[t]=s[t]);e.maybeRaiseImageResolution(),setTimeout(function(){e.afterResize()},500)}})}},loadMoreButtonInit:function(){var e=i(this.el),s=this;e.find("#sbi_load .sbi_load_btn").off().on("click",function(){s.afterLoadMoreClicked(jQuery(this)),s.getNewPostSet()})},getNewPostSet:function(){var e=i(this.el),s=this;n({action:"sbi_load_more_clicked",offset:e.find(".sbi_item").length,feed_id:s.settings.feedID,atts:s.settings.shortCodeAtts,current_resolution:s.imageResolution},function(t){if(0===t.trim().indexOf("{")){var n=JSON.parse(t);s.settings.debugEnabled&&console.log(n),s.appendNewPosts(n.html),s.addResizedImages(n.resizedImages),s.settings.ajaxPostLoad?(s.settings.ajaxPostLoad=!1,s.afterInitialImagesLoaded()):s.afterNewImagesLoaded(),n.feedStatus.shouldPaginate?s.outOfPages=!1:(s.outOfPages=!0,e.find(".sbi_load_btn").hide()),i(".sbi_no_js").removeClass("sbi_no_js")}})},appendNewPosts:function(e){var s=i(this.el);s.find("#sbi_images .sbi_item").length?s.find("#sbi_images .sbi_item").last().after(e):s.find("#sbi_images").append(e)},addResizedImages:function(i){for(var e in i)this.resizedImages[e]=i[e]},setImageHeight:function(){var e=i(this.el),s=e.find(".sbi_photo").eq(0).innerWidth(),t=this.getColumnCount(),n=e.find("#sbi_images").innerWidth()-e.find("#sbi_images").width(),a=n/2;sbi_photo_width_manual=e.find("#sbi_images").width()/t-n,e.find(".sbi_photo").css("height",s),e.find(".sbi-owl-nav").length&&setTimeout(function(){var i=2;e.find(".sbi_owl2row-item").length&&(i=1);var s=e.find(".sbi_photo").eq(0).innerWidth()/i;s+=parseInt(a)*(2-i+2),e.find(".sbi-owl-nav div").css("top",s)},100)},maybeRaiseSingleImageResolution:function(e,s,t){var n=this,a=n.getImageUrls(e),o=e.find(".sbi_photo img").attr("src"),d=150,r=e.find("img").get(0),l=o===window.sbi.options.placeholder?1:r.naturalWidth/r.naturalHeight;t=void 0!==t&&t;if(!(e.hasClass("sbi_no_resraise")||e.hasClass("sbi_had_error")||e.find(".sbi_link_area").length&&e.find(".sbi_link_area").hasClass("sbi_had_error")))if(a.length<1)e.find(".sbi_link_area").length&&e.find(".sbi_link_area").attr("href",window.sbi.options.placeholder.replace("placeholder.png","thumb-placeholder.png"));else{(e.find(".sbi_link_area").length&&e.find(".sbi_link_area").attr("href")===window.sbi.options.placeholder.replace("placeholder.png","thumb-placeholder.png")||!n.settings.consentGiven)&&e.find(".sbi_link_area").attr("href",a[a.length-1]),void 0!==a[640]&&e.find(".sbi_photo").attr("data-full-res",a[640]),i.each(a,function(i,e){e===o&&(d=parseInt(i),t=!1)});var h=640;switch(n.settings.imgRes){case"thumb":h=150;break;case"medium":h=320;break;case"full":h=640;break;default:var g=Math.max(n.settings.autoMinRes,e.find(".sbi_photo").innerWidth()),c=n.getBestResolutionForAuto(g,l,e);switch(c){case 320:h=320;break;case 150:h=150}}if(h>d||o===window.sbi.options.placeholder||t){if(n.settings.debugEnabled){var f=o===window.sbi.options.placeholder?"was placeholder":"too small";console.log("rais res for "+o,f)}var u=a[h].split("?ig_cache_key")[0];if(o!==u&&(e.find(".sbi_photo img").attr("src",u),e.find(".sbi_photo").css("background-image",'url("'+u+'")')),d=h,"auto"===n.settings.imgRes){var b=!1;e.find(".sbi_photo img").on("load",function(){var s=i(this),t=s.get(0).naturalWidth/s.get(0).naturalHeight;if(1e3!==s.get(0).naturalWidth&&t>l&&!b){switch(n.settings.debugEnabled&&console.log("rais res again for aspect ratio change "+o),b=!0,g=e.find(".sbi_photo").innerWidth(),c=n.getBestResolutionForAuto(g,t,e),h=640,c){case 320:h=320;break;case 150:h=150}h>d&&(u=a[h].split("?ig_cache_key")[0],s.attr("src",u),s.closest(".sbi_photo").css("background-image",'url("'+u+'")')),"masonry"!==n.layout&&"highlight"!==n.layout||(i(n.el).find("#sbi_images").smashotope(n.isotopeArgs),setTimeout(function(){i(n.el).find("#sbi_images").smashotope(n.isotopeArgs)},500))}else if(n.settings.debugEnabled){var r=b?"already checked":"no aspect ratio change";console.log("not raising res for replacement "+o,r)}})}}e.find("img").on("error",function(){if(i(this).hasClass("sbi_img_error"))console.log("unfixed error "+i(this).attr("src"));else{var e;if(i(this).addClass("sbi_img_error"),!(i(this).attr("src").indexOf("media/?size=")>-1||i(this).attr("src").indexOf("cdninstagram")>-1||i(this).attr("src").indexOf("fbcdn")>-1)&&n.settings.consentGiven){if("undefined"!==i(this).closest(".sbi_photo").attr("data-img-src-set"))void 0!==(e=JSON.parse(i(this).closest(".sbi_photo").attr("data-img-src-set").replace(/\\\//g,"/"))).d&&(i(this).attr("src",e.d),i(this).closest(".sbi_photo").css("background-image","url("+e.d+")"),i(this).closest(".sbi_item").addClass("sbi_had_error").find(".sbi_link_area").attr("href",e[640]).addClass("sbi_had_error"))}else n.settings.favorLocal=!0,void 0!==(e=n.getImageUrls(i(this).closest(".sbi_item")))[640]&&(i(this).attr("src",e[640]),i(this).closest(".sbi_photo").css("background-image","url("+e[640]+")"),i(this).closest(".sbi_item").addClass("sbi_had_error").find(".sbi_link_area").attr("href",e[640]).addClass("sbi_had_error"));setTimeout(function(){n.afterResize()},1500)}})}},maybeRaiseImageResolution:function(e){var s=this,t=void 0!==e&&!0===e?".sbi_item.sbi_new":".sbi_item",n=!s.isInitialized;i(s.el).find(t).each(function(e){!i(this).hasClass("sbi_num_diff_hide")&&i(this).find(".sbi_photo").length&&void 0!==i(this).find(".sbi_photo").attr("data-img-src-set")&&s.maybeRaiseSingleImageResolution(i(this),e,n)}),s.isInitialized=!0},getBestResolutionForAuto:function(e,s,t){(isNaN(s)||s<1)&&(s=1);var n=e*s,a=10*Math.ceil(n/10),o=[150,320,640];if(t.hasClass("sbi_highlighted")&&(a*=2),-1===o.indexOf(parseInt(a))){var d=!1;i.each(o,function(i,e){e>parseInt(a)&&!d&&(a=e,d=!0)})}return a},hideExtraImagesForWidth:function(){if("carousel"!==this.layout){var e=i(this.el),s=void 0!==e.attr("data-num")&&""!==e.attr("data-num")?parseInt(e.attr("data-num")):1,t=void 0!==e.attr("data-nummobile")&&""!==e.attr("data-nummobile")?parseInt(e.attr("data-nummobile")):s;i(window).width()<480?t<e.find(".sbi_item").length&&e.find(".sbi_item").slice(t-e.find(".sbi_item").length).addClass("sbi_num_diff_hide"):s<e.find(".sbi_item").length&&e.find(".sbi_item").slice(s-e.find(".sbi_item").length).addClass("sbi_num_diff_hide")}},setImageSizeClass:function(){var e=i(this.el);e.removeClass("sbi_small sbi_medium");var s=e.innerWidth(),t=parseInt(e.find("#sbi_images").outerWidth()-e.find("#sbi_images").width())/2,n=this.getColumnCount(),a=(s-t*(n+2))/n;a>120&&a<240?e.addClass("sbi_medium"):a<=120&&e.addClass("sbi_small")},setMinImageWidth:function(){i(this.el).find(".sbi_item .sbi_photo").first().length?this.minImageWidth=i(this.el).find(".sbi_item .sbi_photo").first().innerWidth():this.minImageWidth=150},setImageResolution:function(){if("auto"===this.settings.imgRes)this.imageResolution="auto";else switch(this.settings.imgRes){case"thumb":this.imageResolution=150;break;case"medium":this.imageResolution=320;break;default:this.imageResolution=640}},getImageUrls:function(i){var e=JSON.parse(i.find(".sbi_photo").attr("data-img-src-set").replace(/\\\//g,"/")),s=i.attr("id").replace("sbi_","");if(this.settings.consentGiven||this.settings.overrideBlockCDN||(e=[]),void 0!==this.resizedImages[s]&&"video"!==this.resizedImages[s]&&"pending"!==this.resizedImages[s]&&"error"!==this.resizedImages[s].id&&"video"!==this.resizedImages[s].id&&"pending"!==this.resizedImages[s].id){if(void 0!==this.resizedImages[s].sizes){var t=[];void 0!==this.resizedImages[s].sizes.full&&(e[640]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"full.jpg",t.push(640)),void 0!==this.resizedImages[s].sizes.low&&(e[320]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"low.jpg",t.push(320)),void 0!==this.resizedImages[s].sizes.thumb&&(t.push(150),e[150]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"thumb.jpg"),this.settings.favorLocal&&(-1===t.indexOf(640)&&t.indexOf(320)>-1&&(e[640]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"low.jpg"),-1===t.indexOf(320)&&(t.indexOf(640)>-1?e[320]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"full.jpg":t.indexOf(150)>-1&&(e[320]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"thumb.jpg")),-1===t.indexOf(150)&&(t.indexOf(320)>-1?e[150]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"low.jpg":t.indexOf(640)>-1&&(e[150]=sb_instagram_js_options.resized_url+this.resizedImages[s].id+"full.jpg")))}}else(void 0===this.resizedImages[s]||void 0!==this.resizedImages[s].id&&"pending"!==this.resizedImages[s].id&&"error"!==this.resizedImages[s].id)&&this.addToNeedsResizing(s);return e},getAvatarUrl:function(i,e){if(""===i)return"";var s=this.settings.general.avatars;return"local"===(e=void 0!==e?e:"local")?void 0!==s["LCL"+i]&&1===parseInt(s["LCL"+i])?sb_instagram_js_options.resized_url+i+".jpg":void 0!==s[i]?s[i]:"":void 0!==s[i]?s[i]:void 0!==s["LCL"+i]&&1===parseInt(s["LCL"+i])?sb_instagram_js_options.resized_url+i+".jpg":""},addToNeedsResizing:function(i){-1===this.needsResizing.indexOf(i)&&this.needsResizing.push(i)},applyImageLiquid:function(){var s=i(this.el);e(),"function"==typeof s.find(".sbi_photo").sbi_imgLiquid&&s.find(".sbi_photo").sbi_imgLiquid({fill:!0})},listenForVisibilityChange:function(){var e,s,t,n=this;e=jQuery,s={callback:function(){},runOnLoad:!0,frequency:100,sbiPreviousVisibility:null},t={sbiCheckVisibility:function(i,e){if(jQuery.contains(document,i[0])){var s=e.sbiPreviousVisibility,n=i.is(":visible");e.sbiPreviousVisibility=n,null==s?e.runOnLoad&&e.callback(i,n):s!==n&&e.callback(i,n),setTimeout(function(){t.sbiCheckVisibility(i,e)},e.frequency)}}},e.fn.sbiVisibilityChanged=function(i){var n=e.extend({},s,i);return this.each(function(){t.sbiCheckVisibility(e(this),n)})},"function"==typeof i(this.el).filter(":hidden").sbiVisibilityChanged&&i(this.el).filter(":hidden").sbiVisibilityChanged({callback:function(i,e){n.afterResize()},runOnLoad:!1})},getColumnCount:function(){var e=i(this.el),s=this.settings.cols,t=this.settings.colsmobile,n=s;return sbiWindowWidth=window.innerWidth,e.hasClass("sbi_mob_col_auto")?(sbiWindowWidth<640&&parseInt(s)>2&&parseInt(s)<7&&(n=2),sbiWindowWidth<640&&parseInt(s)>6&&parseInt(s)<11&&(n=4),sbiWindowWidth<=480&&parseInt(s)>2&&(n=1)):sbiWindowWidth<=480&&(n=t),parseInt(n)},checkConsent:function(){if(this.settings.consentGiven||!this.settings.gdpr)return!0;if("undefined"!=typeof CLI_Cookie)null!==CLI_Cookie.read(CLI_ACCEPT_COOKIE_NAME)&&(this.settings.consentGiven="yes"===CLI_Cookie.read("cookielawinfo-checkbox-non-necessary"));else if(void 0!==window.cnArgs){var i=("; "+document.cookie).split("; cookie_notice_accepted=");if(2===i.length){var e=i.pop().split(";").shift();this.settings.consentGiven="true"===e}}else void 0!==window.cookieconsent?this.settings.consentGiven="allow"===function(i){for(var e=i+"=",s=window.document.cookie.split(";"),t=0;t<s.length;t++){var n=s[t].trim();if(0==n.indexOf(e))return n.substring(e.length,n.length)}return""}("complianz_consent_status"):void 0!==window.Cookiebot?this.settings.consentGiven=Cookiebot.consented:void 0!==window.BorlabsCookie&&(this.settings.consentGiven=window.BorlabsCookie.checkCookieConsent("instagram"));var s=jQuery.Event("sbicheckconsent");return s.feed=this,jQuery(window).trigger(s),this.settings.consentGiven},afterConsentToggled:function(){if(this.checkConsent()){var i=this;i.maybeRaiseImageResolution(),setTimeout(function(){i.afterResize()},500)}}},window.sbi_init=function(){window.sbi=new s,window.sbi.createPage(window.sbi.createFeeds,{whenFeedsCreated:window.sbi.afterFeedsCreated})}}(jQuery),jQuery(document).ready(function(i){void 0===window.sb_instagram_js_options&&(window.sb_instagram_js_options={font_method:"svg",resized_url:location.protocol+"//"+window.location.hostname+"/wp-content/uploads/sb-instagram-feed-images/",placeholder:location.protocol+"//"+window.location.hostname+"/wp-content/plugins/instagram-feed/img/placeholder.png"}),void 0!==window.sb_instagram_js_options.resized_url&&-1===window.sb_instagram_js_options.resized_url.indexOf(location.protocol)&&("http:"===location.protocol?window.sb_instagram_js_options.resized_url=window.sb_instagram_js_options.resized_url.replace("https:","http:"):window.sb_instagram_js_options.resized_url=window.sb_instagram_js_options.resized_url.replace("http:","https:")),sbi_init(),i("#cookie-notice a").click(function(){setTimeout(function(){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].afterConsentToggled()})},1e3)}),i("#cookie-law-info-bar a").click(function(){setTimeout(function(){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].afterConsentToggled()})},1e3)}),i(".cli-user-preference-checkbox").click(function(){setTimeout(function(){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].settings.consentGiven=!1,window.sbi.feeds[i].afterConsentToggled()})},1e3)}),i(window).on("CookiebotOnAccept",function(e){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].settings.consentGiven=!0,window.sbi.feeds[i].afterConsentToggled()})}),i(document).on("cmplzAcceptAll",function(e){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].settings.consentGiven=!0,window.sbi.feeds[i].afterConsentToggled()})}),i(document).on("cmplzRevoke",function(e){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].settings.consentGiven=!1,window.sbi.feeds[i].afterConsentToggled()})}),i(document).on("borlabs-cookie-consent-saved",function(e){i.each(window.sbi.feeds,function(i){window.sbi.feeds[i].settings.consentGiven=!1,window.sbi.feeds[i].afterConsentToggled()})})}));