'html_location' => array( 'content' ),
);
$count = \SB_Instagram_Feed_Locator::count( $args );
$content_locations = \SB_Instagram_Feed_Locator::instagram_feed_locator_query( $args );
// if this is the last page, add in the header footer and sidebar locations
if ( count( $content_locations ) < SBI_Db::RESULTS_PER_PAGE ) {
$args = array(
'feed_id' => '*' . $single_feed['id'],
'html_location' => array( 'header', 'footer', 'sidebar' ),
'group_by' => 'html_location',
);
$other_locations = \SB_Instagram_Feed_Locator::instagram_feed_locator_query( $args );
$locations = array();
$combined_locations = array_merge( $other_locations, $content_locations );
} else {
$combined_locations = $content_locations;
}
foreach ( $combined_locations as $location ) {
$page_text = get_the_title( $location['post_id'] );
if ( $location['html_location'] === 'header' ) {
$html_location = __( 'Header', 'instagram-feed' );
} elseif ( $location['html_location'] === 'footer' ) {
$html_location = __( 'Footer', 'instagram-feed' );
} elseif ( $location['html_location'] === 'sidebar' ) {
$html_location = __( 'Sidebar', 'instagram-feed' );
} else {
$html_location = __( 'Content', 'instagram-feed' );
}
$shortcode_atts = json_decode( $location['shortcode_atts'], true );
$shortcode_atts = is_array( $shortcode_atts ) ? $shortcode_atts : array();
$full_shortcode_string = '[instagram-feed';
foreach ( $shortcode_atts as $key => $value ) {
if ( ! empty( $value ) ) {
$full_shortcode_string .= ' ' . esc_html( $key ) . '="' . esc_html( $value ) . '"';
}
}
$full_shortcode_string .= ']';
$locations[] = array(
'link' => esc_url( get_the_permalink( $location['post_id'] ) ),
'page_text' => $page_text,
'html_location' => $html_location,
'shortcode' => $full_shortcode_string
);
}
$feeds_data[ $i ]['instance_count'] = $count;
$feeds_data[ $i ]['location_summary'] = $locations;
$settings = json_decode( $feeds_data[ $i ]['settings'], true );
$settings['feed'] = $single_feed['id'];
$instagram_feed_settings = new \SB_Instagram_Settings( $settings, sbi_defaults() );
$feeds_data[ $i ]['settings'] = $instagram_feed_settings->get_settings();
$i++;
}
return $feeds_data;
}
/**
* Returns an associate array of all existing sources along with their data
*
* @return array
*
* @since 4.0
*/
public function get_legacy_feed_list() {
if ( ! empty( $_GET['feed_id'] ) ) {
return array();
}
$sbi_statuses = get_option( 'sbi_statuses', array() );
$sources_list = self::get_source_list();
if ( empty( $sbi_statuses['support_legacy_shortcode'] ) ) {
return array();
}
$args = array(
'html_location' => array( 'header', 'footer', 'sidebar', 'content' ),
'group_by' => 'shortcode_atts',
'page' => 1
);
$feeds_data = \SB_Instagram_Feed_Locator::legacy_instagram_feed_locator_query( $args );
if ( empty( $feeds_data ) ) {
$args = array(
'html_location' => array( 'header', 'footer', 'sidebar', 'content' ),
'group_by' => 'shortcode_atts',
'page' => 1
);
$feeds_data = \SB_Instagram_Feed_Locator::legacy_instagram_feed_locator_query( $args );
}
$feed_saver = new SBI_Feed_Saver( 'legacy' );
$settings = $feed_saver->get_feed_settings();
$default_type = 'timeline';
if ( isset( $settings['feedtype'] ) ) {
$default_type = $settings['feedtype'];
} elseif ( isset( $settings['type'] ) ) {
if ( strpos( $settings['type'], ',' ) === false ) {
$default_type = $settings['type'];
}
}
$i = 0;
$reindex = false;
foreach ( $feeds_data as $single_feed ) {
$args = array(
'shortcode_atts' => $single_feed['shortcode_atts'],
'html_location' => array( 'content' ),
);
$content_locations = \SB_Instagram_Feed_Locator::instagram_feed_locator_query( $args );
$count = \SB_Instagram_Feed_Locator::count( $args );
if ( count( $content_locations ) < SBI_Db::RESULTS_PER_PAGE ) {
$args = array(
'feed_id' => $single_feed['feed_id'],
'html_location' => array( 'header', 'footer', 'sidebar' ),
'group_by' => 'html_location'
);
$other_locations = \SB_Instagram_Feed_Locator::instagram_feed_locator_query( $args );
$combined_locations = array_merge( $other_locations, $content_locations );
} else {
$combined_locations = $content_locations;
}
$locations = array();
foreach ( $combined_locations as $location ) {
$page_text = get_the_title( $location['post_id'] );
if ( $location['html_location'] === 'header' ) {
$html_location = __( 'Header', 'instagram-feed' );
} elseif ( $location['html_location'] === 'footer' ) {
$html_location = __( 'Footer', 'instagram-feed' );
} elseif ( $location['html_location'] === 'sidebar' ) {
$html_location = __( 'Sidebar', 'instagram-feed' );
} else {
$html_location = __( 'Content', 'instagram-feed' );
}
$shortcode_atts = json_decode( $location['shortcode_atts'], true );
$shortcode_atts = is_array( $shortcode_atts ) ? $shortcode_atts : array();
$full_shortcode_string = '[instagram-feed';
foreach ( $shortcode_atts as $key => $value ) {
if ( ! empty( $value ) ) {
if ( is_array( $value ) ) {
$value = implode( ',', $value );
}
$full_shortcode_string .= ' ' . esc_html( $key ) . '="' . esc_html( $value ) . '"';
}
}
$full_shortcode_string .= ']';
$locations[] = array(
'link' => esc_url( get_the_permalink( $location['post_id'] ) ),
'page_text' => $page_text,
'html_location' => $html_location,
'shortcode' => $full_shortcode_string
);
}
$shortcode_atts = json_decode( $feeds_data[ $i ]['shortcode_atts'], true );
$shortcode_atts = is_array( $shortcode_atts ) ? $shortcode_atts : array();
$full_shortcode_string = '[instagram-feed';
foreach ( $shortcode_atts as $key => $value ) {
if ( ! empty( $value ) ) {
if ( is_array( $value ) ) {
$value = implode( ',', $value );
}
$full_shortcode_string .= ' ' . esc_html( $key ) . '="' . esc_html( $value ) . '"';
}
}
$full_shortcode_string .= ']';
$feeds_data[ $i ]['shortcode'] = $full_shortcode_string;
$feeds_data[ $i ]['instance_count'] = $count;
$feeds_data[ $i ]['location_summary'] = $locations;
$feeds_data[ $i ]['feed_name'] = self::get_legacy_feed_name( $sources_list, $feeds_data[ $i ]['feed_id'] );
$feeds_data[ $i ]['feed_type'] = $default_type;
if ( isset( $shortcode_atts['feedtype'] ) ) {
$feeds_data[ $i ]['feed_type'] = $shortcode_atts['feedtype'];
} elseif ( isset( $shortcode_atts['type'] ) ) {
if ( strpos( $shortcode_atts['type'], ',' ) === false ) {
$feeds_data[ $i ]['feed_type'] = $shortcode_atts['type'];
}
}
if ( isset( $feeds_data[ $i ]['id'] ) ) {
unset( $feeds_data[ $i ]['id'] );
}
if ( isset( $feeds_data[ $i ]['html_location'] ) ) {
unset( $feeds_data[ $i ]['html_location'] );
}
if ( isset( $feeds_data[ $i ]['last_update'] ) ) {
unset( $feeds_data[ $i ]['last_update'] );
}
if ( isset( $feeds_data[ $i ]['post_id'] ) ) {
unset( $feeds_data[ $i ]['post_id'] );
}
if ( ! empty( $shortcode_atts['feed'] ) ) {
$reindex = true;
unset( $feeds_data[ $i ] );
}
if ( isset( $feeds_data[ $i ]['shortcode_atts'] ) ) {
unset( $feeds_data[ $i ]['shortcode_atts'] );
}
$i++;
}
if ( $reindex ) {
$feeds_data = array_values( $feeds_data );
}
// if there were no feeds found in the locator table we still want the legacy settings to be available
// if it appears as though they had used version 3.x or under at some point.
if ( empty( $feeds_data )
&& ! is_array( $sbi_statuses['support_legacy_shortcode'] )
&& ( $sbi_statuses['support_legacy_shortcode'] ) ) {
$feeds_data = array(
array(
'feed_id' => __( 'Legacy Feed', 'instagram-feed' ) . ' ' . __( '(unknown location)', 'instagram-feed' ),
'feed_name' => __( 'Legacy Feed', 'instagram-feed' ) . ' ' . __( '(unknown location)', 'instagram-feed' ),
'shortcode' => '[instagram-feed]',
'feed_type' => '',
'instance_count' => false,
'location_summary' => array()
)
);
}
return $feeds_data;
}
public static function get_legacy_feed_name( $sources_list, $source_id ) {
foreach ( $sources_list as $source ) {
if ( $source['account_id'] == $source_id ) {
return $source['username'];
}
}
return $source_id;
}
/**
* Status of the onboarding sequence for specific user
*
* @return string|boolean
*
* @since 6.0
*/
public static function onboarding_status( $type = 'newuser' ) {
$onboarding_statuses = get_user_meta( get_current_user_id(), 'sbi_onboarding', true );
$status = false;
if ( ! empty( $onboarding_statuses ) ) {
$statuses = Util::safe_unserialize( $onboarding_statuses );
$status = isset( $statuses[ $type ] ) ? $statuses[ $type ] : false;
}
return $status;
}
/**
* Update status of onboarding sequence for specific user
*
* @return string|boolean
*
* @since 6.0
*/
public static function update_onboarding_meta( $value, $type = 'newuser' ) {
$onboarding_statuses = get_user_meta( get_current_user_id(), 'sbi_onboarding', true );
if ( ! empty( $onboarding_statuses ) ) {
$statuses = Util::safe_unserialize( $onboarding_statuses );
$statuses[ $type ] = $value;
} else {
$statuses = array(
$type => $value
);
}
$statuses = maybe_serialize( $statuses );
update_user_meta( get_current_user_id(), 'sbi_onboarding', $statuses );
}
/**
* Used to dismiss onboarding using AJAX
*
* @since 6.0
*/
public static function after_dismiss_onboarding() {
check_ajax_referer( 'sbi-admin', 'nonce' );
$cap = current_user_can( 'manage_instagram_feed_options' ) ? 'manage_instagram_feed_options' : 'manage_options';
$cap = apply_filters( 'sbi_settings_pages_capability', $cap );
if ( current_user_can( $cap ) ) {
$type = 'newuser';
if ( isset( $_POST['was_active'] ) ) {
$type = sanitize_key( $_POST['was_active'] );
}
self::update_onboarding_meta( 'dismissed', $type );
}
wp_die();
}
public static function add_customizer_att( $atts ) {
if ( ! is_array( $atts ) ) {
$atts = array();
}
$atts['feedtype'] = 'customizer';
return $atts;
}
/**
* Feed Builder Wrapper.
*
* @since 6.0
*/
public function feed_builder() {
include_once SBI_BUILDER_DIR . 'templates/builder.php';
}
/**
* For types listed on the top of the select feed type screen
*
* @return array
*
* @since 6.0
*/
public function get_feed_types() {
$feed_types = array(
array(
'type' => 'user',
'title' => __( 'User Timeline', 'instagram-feed' ),
'description' => __( 'Fetch posts from your Instagram profile', 'instagram-feed' ),
'icon' => 'usertimelineIcon'
),
array(
'type' => 'hashtag',
'title' => __( 'Public Hashtag', 'instagram-feed' ),
'description' => __( 'Fetch posts from a public Instagram hashtag', 'instagram-feed' ),
'tooltip' => __( 'Hashtag feeds require a connected Instagram business account', 'instagram-feed' ),
'businessRequired' => true,
'icon' => 'publichashtagIcon'
),
array(
'type' => 'tagged',
'title' => __( 'Tagged Posts', 'instagram-feed' ),
'description' => __( 'Display posts your Instagram account has been tagged in', 'instagram-feed' ),
'tooltip' => __( 'Tagged posts feeds require a connected Instagram business account', 'instagram-feed' ),
'businessRequired' => true,
'icon' => 'taggedpostsIcon'
),
array(
'type' => 'socialwall',
'title' => __( 'Social Wall', 'instagram-feed' ),
'description' => __( 'Create a feed with sources from different social platforms', 'instagram-feed' ),
'icon' => 'socialwall1Icon'
)
);
return $feed_types;
}
/**
* For types listed on the bottom of the select feed type screen
*
* @return array
*
* @since 6.0
*/
public function get_advanced_feed_types() {
$feed_types = array(
array(
'type' => 'hashtag',
'title' => __( 'Public Hashtag', 'instagram-feed' ),
'description' => __( 'Fetch posts from a public Instagram hashtag', 'instagram-feed' ),
'tooltip' => __( 'Hashtag feeds require a connected Instagram business account', 'instagram-feed' ),
'businessRequired' => true,
'icon' => 'publichashtagIcon'
),
array(
'type' => 'tagged',
'title' => __( 'Tagged Posts', 'instagram-feed' ),
'description' => __( 'Display posts your Instagram account has been tagged in', 'instagram-feed' ),
'tooltip' => __( 'Tagged posts feeds require a connected Instagram business account', 'instagram-feed' ),
'businessRequired' => true,
'icon' => 'taggedpostsIcon'
),
array(
'type' => 'socialwall',
'title' => __( 'Social Wall', 'instagram-feed' ),
'description' => __( 'Create a feed with sources from different social platforms', 'instagram-feed' ),
'icon' => 'socialwall1Icon'
),
);
return $feed_types;
}
/**
* Personal Account
*
* @return array
*
* @since 6.0.8
*/
public static function personal_account_screen_text() {
return array(
'mainHeading1' => __( 'We’re almost there...', 'instagram-feed' ),
'mainHeading2' => __( 'Update Personal Account', 'instagram-feed' ),
'mainHeading3' => __( 'Add Instagram Profile Picture and Bio', 'instagram-feed' ),
'mainDescription' => __( 'Instagram does not provide us access to your profile picture or bio for personal accounts. Would you like to set up a custom profile photo and bio?.', 'instagram-feed' ),
'bioLabel' => __( 'Bio (140 Characters)', 'instagram-feed' ),
'bioPlaceholder' => __( 'Add your profile bio here', 'instagram-feed' ),
'confirmBtn' => __( 'Yes, let\'s do it', 'instagram-feed' ),
'cancelBtn' => __( 'No, maybe later', 'instagram-feed' ),
'uploadBtn' => __( 'Upload Profile Picture', 'instagram-feed' )
);
}
/**
* Get Smahballoon Plugins Info
*
* @since 6.2.9
*/
public static function get_smashballoon_plugins_info() {
$active_sb_plugins = Util::get_sb_active_plugins_info();
return [
'facebook' => [
'installed' => $active_sb_plugins['is_facebook_installed'],
'class' => 'CFF_Elementor_Widget',
'link' => 'https://smashballoon.com/custom-facebook-feed/',
'icon' => self::builder_svg_icons('install-plugins-popup.facebook'),
'description' => __('Custom Facebook Feeds is a highly customizable way to display tweets from your Facebook account. Promote your latest content and update your site content automatically.', 'instagram-feed'),
'download_plugin' => 'https://downloads.wordpress.org/plugin/custom-facebook-feed.zip',
'dashboard_link' => admin_url('admin.php?page=cff-feed-builder'),
'active' => is_plugin_active($active_sb_plugins['facebook_plugin'])
],
'instagram' => [
'installed' => $active_sb_plugins['is_instagram_installed'],
'class' => 'SBI_Elementor_Widget',
'link' => 'https://smashballoon.com/instagram-feed/',
'icon' => self::builder_svg_icons('install-plugins-popup.instagram'),
'description' => __('Instagram Feeds is a highly customizable way to display tweets from your Instagram account. Promote your latest content and update your site content automatically.', 'instagram-feed'),
'download_plugin' => 'https://downloads.wordpress.org/plugin/instagram-feed.zip',
'dashboard_link' => admin_url('admin.php?page=sbi-feed-builder'),
'active' => is_plugin_active($active_sb_plugins['instagram_plugin'])
],
'twitter' => [
'installed' => $active_sb_plugins['is_twitter_installed'],
'class' => 'CTF_Elementor_Widget',
'link' => 'https://smashballoon.com/custom-twitter-feeds/',
'icon' => self::builder_svg_icons('install-plugins-popup.twitter'),
'description' => __('Custom Twitter Feeds is a highly customizable way to display tweets from your Twitter account. Promote your latest content and update your site content automatically.', 'instagram-feed'),
'download_plugin' => 'https://downloads.wordpress.org/plugin/custom-twitter-feeds.zip',
'dashboard_link' => admin_url('admin.php?page=ctf-feed-builder'),
'active' => is_plugin_active($active_sb_plugins['twitter_plugin'])
],
'youtube' => [
'installed' => $active_sb_plugins['is_youtube_installed'],
'class' => 'SBY_Elementor_Widget',
'link' => 'https://smashballoon.com/youtube-feed/',
'icon' => self::builder_svg_icons('install-plugins-popup.youtube'),
'description' => __('YouTube Feeds is a highly customizable way to display tweets from your YouTube account. Promote your latest content and update your site content automatically.', 'instagram-feed'),
'download_plugin' => 'https://downloads.wordpress.org/plugin/feeds-for-youtube.zip',
'dashboard_link' => admin_url('admin.php?page=sby-feed-builder'),
'active' => is_plugin_active($active_sb_plugins['youtube_plugin'])
]
];
}
}