prefix . "options";
$wpdb->query( "
DELETE
FROM $table_name
WHERE `option_name` LIKE ('%\_transient\_sby\_%')
" );
$wpdb->query( "
DELETE
FROM $table_name
WHERE `option_name` LIKE ('%\_transient\_timeout\_sby\_%')
" );
$wpdb->query( "
DELETE
FROM $table_name
WHERE `option_name` LIKE ('%\_transient\_&sby\_%')
" );
$wpdb->query( "
DELETE
FROM $table_name
WHERE `option_name` LIKE ('%\_transient\_timeout\_&sby\_%')
" );
$wpdb->query( "
DELETE
FROM $table_name
WHERE `option_name` LIKE ('%\_transient\_\$sby\_%')
" );
$wpdb->query( "
DELETE
FROM $table_name
WHERE `option_name` LIKE ('%\_transient\_timeout\_\$sby\_%')
" );
sby_clear_page_caches();
}
add_action( 'sby_settings_after_configure_save', 'sby_clear_cache' );
/**
* When certain events occur, page caches need to
* clear or errors occur or changes will not be seen
*/
function sby_clear_page_caches() {
if ( isset( $GLOBALS['wp_fastest_cache'] ) && method_exists( $GLOBALS['wp_fastest_cache'], 'deleteCache' ) ){
/* Clear WP fastest cache*/
$GLOBALS['wp_fastest_cache']->deleteCache();
}
if ( function_exists( 'wp_cache_clear_cache' ) ) {
wp_cache_clear_cache();
}
if ( class_exists('W3_Plugin_TotalCacheAdmin') ) {
$plugin_totalcacheadmin = & w3_instance('W3_Plugin_TotalCacheAdmin');
$plugin_totalcacheadmin->flush_all();
}
if ( function_exists( 'rocket_clean_domain' ) ) {
rocket_clean_domain();
}
if ( class_exists( 'autoptimizeCache' ) ) {
/* Clear autoptimize */
autoptimizeCache::clearall();
}
}
/**
* Clear object cachiing
* @since 2.4
*/
function sby_clear_object_cache()
{
// return if the object cache was cleared winthin an hour
if (get_transient('sb_youtube_object_cache_clear')) {
return;
}
if (function_exists('wp_cache_flush')) {
wp_cache_flush();
set_transient('sb_youtube_object_cache_clear', 'true', HOUR_IN_SECONDS);
}
}
function sby_update_or_connect_account( $args ) {
global $sby_settings;
$account_id = $args['channel_id'];
$sby_settings['connected_accounts'][ $account_id ] = array(
'access_token' => $args['access_token'],
'refresh_token' => $args['refresh_token'],
'channel_id' => $args['channel_id'],
'username' => $args['username'],
'is_valid' => true,
'last_checked' => time(),
'profile_picture' => $args['profile_picture'],
'privacy' => $args['privacy'],
'expires' => $args['expires']
);
update_option( 'sby_settings', $sby_settings );
return $sby_settings['connected_accounts'][ $account_id ];
}
function sby_get_first_connected_account() {
global $sby_settings;
$an_account = array();
if ( ! empty( $sby_settings['api_key'] ) ) {
$an_account = array(
'access_token' => '',
'refresh_token' => '',
'channel_id' => '',
'username' => '',
'is_valid' => true,
'last_checked' => '',
'profile_picture' => '',
'privacy' => '',
'expires' => '2574196927',
'api_key' => $sby_settings['api_key']
);
} else {
$connected_accounts = $sby_settings['connected_accounts'];
foreach ( $connected_accounts as $account ) {
if ( empty( $an_account ) ) {
$an_account = $account;
}
}
}
if ( empty( $an_account ) ) {
$an_account = array( 'rss_only' => true );
}
return $an_account;
}
function sby_get_feed_template_part( $part, $settings = array() ) {
$file = '';
$using_custom_templates_in_theme = apply_filters( 'sby_use_theme_templates', $settings['customtemplates'] );
$generic_path = trailingslashit( SBY_PLUGIN_DIR ) . 'templates/';
if ( $using_custom_templates_in_theme ) {
$custom_header_template = locate_template( 'sby/header.php', false, false );
$custom_header_generic_template = locate_template( 'sby/header-generic.php', false, false );
$custom_player_template = locate_template( 'sby/player.php', false, false );
$custom_item_template = locate_template( 'sby/item.php', false, false );
$custom_footer_template = locate_template( 'sby/footer.php', false, false );
$custom_feed_template = locate_template( 'sby/feed.php', false, false );
$custom_info_template = locate_template( 'sby/info.php', false, false );
$custom_cta_template = locate_template( 'sby/cta.php', false, false );
$custom_shortcode_template = locate_template( 'sby/shortcode-content.php', false, false );
$form_template = locate_template( 'sby/form.php', false, false );
$results_template = locate_template( 'sby/results.php', false, false );
$result_template = locate_template( 'sby/result.php', false, false );
} else {
$custom_header_template = false;
$custom_header_generic_template = false;
$custom_player_template = false;
$custom_item_template = false;
$custom_footer_template = false;
$custom_feed_template = false;
$custom_info_template = false;
$custom_cta_template = false;
$custom_shortcode_template = false;
$form_template = false;
$results_template = false;
$result_template = false;
}
if ( $part === 'header' ) {
if ( isset( $settings['generic_header'] ) ) {
if ( $custom_header_generic_template ) {
$file = $custom_header_generic_template;
} else {
$file = $generic_path . 'header-generic.php';
}
} else {
if ( $custom_header_template ) {
$file = $custom_header_template;
} else {
$file = $generic_path . 'header.php';
}
}
} elseif ( $part === 'header-text' ) {
$file = $generic_path . 'header-text.php';
} elseif ( $part === 'header-generic' ) {
if ( $custom_header_generic_template ) {
$file = $custom_header_generic_template;
} else {
$file = $generic_path . 'header-generic.php';
}
} elseif ( $part === 'player' ) {
if ( $custom_player_template ) {
$file = $custom_player_template;
} else {
$file = $generic_path . 'player.php';
}
} elseif ( $part === 'item' ) {
if ( $custom_item_template ) {
$file = $custom_item_template;
} else {
$file = $generic_path . 'item.php';
}
} elseif ( $part === 'footer' ) {
if ( $custom_footer_template ) {
$file = $custom_footer_template;
} else {
$file = $generic_path . 'footer.php';
}
} elseif ( $part === 'feed' ) {
if ( $custom_feed_template ) {
$file = $custom_feed_template;
} else {
$file = $generic_path . 'feed.php';
}
} elseif ( $part === 'info' ) {
if ( $custom_info_template ) {
$file = $custom_info_template;
} else {
$file = $generic_path . 'info.php';
}
} elseif ( $part === 'player-info' ) {
if ( $custom_info_template ) {
$file = $custom_info_template;
} else {
$file = $generic_path . 'player-info.php';
}
} elseif ( $part === 'cta' ) {
if ( $custom_cta_template ) {
$file = $custom_cta_template;
} else {
$file = $generic_path . 'cta.php';
}
} elseif ( $part === 'shortcode-content' ) {
if ( $custom_shortcode_template ) {
$file = $custom_shortcode_template;
} else {
$file = $generic_path . 'single/shortcode-content.php';
}
} elseif ( $part === 'form' ) {
if ( $form_template ) {
$file = $form_template;
} else {
$file = $generic_path . 'search/form.php';
}
} elseif ( $part === 'results' ) {
if ( $results_template ) {
$file = $results_template;
} else {
$file = $generic_path . 'search/results.php';
}
} elseif ( $part === 'result' ) {
if ( $result_template ) {
$file = $result_template;
} else {
$file = $generic_path . 'search/result.php';
}
}
return $file;
}
/**
* Get the settings in the database with defaults
*
* @return array
*/
function sby_get_database_settings() {
global $sby_settings;
$defaults = sby_settings_defaults();
if ( $sby_settings === null ) {
$sby_settings = get_option('sby_settings', []);
}
return array_merge( $defaults, $sby_settings );
}
function sby_get_channel_id_from_channel_name( $channel_name ) {
$channel_ids = get_option( 'sby_channel_ids', array() );
if ( isset( $channel_ids[ strtolower( $channel_name ) ] ) ) {
return $channel_ids[ strtolower( $channel_name ) ];
}
return false;
}
function sby_set_channel_id_from_channel_name( $channel_name, $channel_id ) {
$channel_ids = get_option( 'sby_channel_ids', array() );
$channel_ids[ strtolower( $channel_name ) ] = $channel_id;
update_option( 'sby_channel_ids', $channel_ids, false );
}
function sby_icon( $icon, $class = '' ) {
$class = ! empty( $class ) ? ' ' . trim( $class ) : '';
if ( $icon === SBY_SLUG ) {
return '';
} else {
return '';
}
}
/**
* Print custom palette color styles for the front end
*
* @since 2.0
*/
function sby_maybe_palette_styles( $feed_id, $posts, $settings ) {
if ( sby_doing_customizer( $settings ) ) {
return;
}
$feed_container = 'body #sb_youtube_' . esc_attr( preg_replace( "/[^A-Za-z0-9 ]/", '', $feed_id ) );
$custom_palette_class = trim(SBY_Display_Elements::get_palette_class( $settings ));
if ( SBY_Display_Elements::palette_type( $settings ) !== 'custom' ) {
return;
}
$feed_selector = '.' . $custom_palette_class;
$header_selector = '.' . trim(SBY_Display_Elements::get_palette_class( $settings, '_header' ));
$custom_colors = array(
'bg1' => $settings['custombgcolor1'],
'text1' => $settings['customtextcolor1'],
'text2' => $settings['customtextcolor2'],
'link1' => $settings['customlinkcolor1'],
'button1' => $settings['custombuttoncolor1'],
'button2' => $settings['custombuttoncolor2']
);
?>
';
if ( isset( $settings['buttonhovercolor'] ) && !empty( $settings['buttonhovercolor'] ) ) {
echo $feed_selector . ' .sby_load_btn:hover { background: ' . $settings['buttonhovercolor'] . ' !important}';
}
if ( isset( $settings['customheadertextcolor'] ) && !empty( $settings['customheadertextcolor'] ) ) {
echo $feed_selector . ' .sby-header-type-text { color: ' . $settings['customheadertextcolor'] . ' !important}';
}
if ( isset( $settings['descriptiontextsize'] ) && !empty( $settings['descriptiontextsize'] ) ) {
echo $feed_selector . ' .sby_caption_wrap .sby_caption { font-size: ' . $settings['descriptiontextsize'] . ' !important}';
}
if ( isset( $settings['subscribehovercolor'] ) && !empty( $settings['subscribehovercolor'] ) ) {
echo $feed_selector . ' .sby_follow_btn a:hover { box-shadow:inset 0 0 10px 20px ' . $settings['subscribehovercolor'] . ' !important}';
}
if ( isset( $settings['boxedbgcolor'] ) && !empty( $settings['boxedbgcolor'] ) ) {
echo $feed_selector . '[data-videostyle=boxed] .sby_items_wrap .sby_item .sby_inner_item { background-color: ' . $settings['boxedbgcolor'] . ' !important}';
}
if ( isset( $settings['videocardstyle'] ) && $settings['videocardstyle'] == 'boxed' &&
( isset( $settings['boxborderradius'] ) && !empty( $settings['boxborderradius'] ) )
) {
echo $feed_selector . '[data-videostyle=boxed] .sby_items_wrap .sby_item .sby_inner_item { border-radius: ' . $settings['boxborderradius'] . 'px!important}';
if ( sby_is_pro() ) {
echo $feed_selector . sprintf(' .sby_video_thumbnail { border-radius: %spx %spx 0 0 !important}', $settings['boxborderradius'], $settings['boxborderradius']);
} else {
echo $feed_selector . sprintf(' .sby_video_thumbnail { border-radius: %spx !important}', $settings['boxborderradius']);
}
}
if ( isset( $settings['videodescriptioncolor'] ) && !empty( $settings['videodescriptioncolor'] ) ) {
echo $feed_selector . ' .sby_item_caption_wrap { color: ' . $settings['videodescriptioncolor'] . ' !important}';
}
if ( isset( $settings['videotitlecolor'] ) && !empty( $settings['videotitlecolor'] ) ) {
echo $feed_selector . ' .sby_video_title { color: ' . $settings['videotitlecolor'] . ' !important}';
}
if ( isset( $settings['videouserecolor'] ) && !empty( $settings['videouserecolor'] ) ) {
echo $feed_selector . ' .sby_meta span.sby_username_wrap { color: ' . $settings['videouserecolor'] . ' !important}';
}
if ( isset( $settings['videocountdowncolor'] ) && !empty( $settings['videocountdowncolor'] ) ) {
echo $feed_selector . ' .sby_ls_message_wrap .sby_ls_message { background-color: ' . $settings['videocountdowncolor'] . ' !important}';
}
if ( isset( $settings['videoviewsecolor'] ) && !empty( $settings['videoviewsecolor'] ) ) {
echo $feed_selector . ' .sby_meta span.sby_view_count_wrap { color: ' . $settings['videoviewsecolor'] . ' !important}';
}
if ( isset( $settings['videostatscolor'] ) && !empty( $settings['videostatscolor'] ) ) {
echo $feed_selector . ' .sby_info .sby_stats { color: ' . $settings['videostatscolor'] . ' !important}';
}
if ( isset( $settings['subscribelinkcolorbg'] ) && !empty( $settings['subscribelinkcolorbg'] ) ) {
echo $feed_selector . '.sbc-channel-subscribe-btn button, '. $feed_selector .' .sby-player-info .sby-channel-info-bar .sby-channel-subscribe-btn a { background: ' . $settings['subscribelinkcolorbg'] . ' !important}';
}
if ( isset( $settings['subscribebtnprimarycolor'] ) && !empty( $settings['subscribebtnprimarycolor'] ) ) {
echo $feed_selector . ' .sby-video-header-info h5, '. $feed_selector .' .sby-channel-info-bar .sby-channel-name { color: ' . $settings['subscribebtnprimarycolor'] . ' !important}';
}
if ( isset( $settings['subscribebtnsecondarycolor'] ) && !empty( $settings['subscribebtnsecondarycolor'] ) ) {
echo $feed_selector . ' .sby-channel-info-bar .sby-channel-subscriber-count, '. $feed_selector .' .sby-video-header-info .sby-video-header-meta { color: ' . $settings['subscribebtnsecondarycolor'] . ' !important}';
}
if ( isset( $settings['subscribebtntextcolor'] ) && !empty( $settings['subscribebtntextcolor'] ) ) {
echo $feed_selector . '.sbc-channel-subscribe-btn button, '. $feed_selector .' .sby-player-info .sby-channel-info-bar .sby-channel-subscribe-btn a { color: ' . $settings['subscribebtntextcolor'] . ' !important}';
}
echo '';
}
add_action( 'sby_after_feed', 'sby_custom_feed_styles', 1, 3 );
/**
* @param $a
* @param $b
*
* @return false|int
*/
function sby_date_sort( $a, $b ) {
$time_stamp_a = SBY_Parse::get_timestamp( $a );
$time_stamp_b = SBY_Parse::get_timestamp( $b );
if ( isset( $time_stamp_a ) ) {
return $time_stamp_b - $time_stamp_a;
} else {
return rand ( -1, 1 );
}
}
function sby_scheduled_start_sort( $a, $b ) {
$time_stamp_a = SBY_Parse_Pro::get_actual_start_timestamp( $a );
$time_stamp_b = SBY_Parse_Pro::get_actual_start_timestamp( $b );
$flag_a = false;
$flag_b = false;
if ( empty( $time_stamp_a ) ) { // if hasn't started
$time_stamp_a = SBY_Parse_Pro::get_scheduled_start_timestamp( $a );
if ( ! empty( $time_stamp_a ) ) { // if it's still scheduled to play
if ( $time_stamp_a > time() - 1 * DAY_IN_SECONDS ) { // if its isn't a day passed the scheduled stream time
$time_stamp_a = $time_stamp_a + 30 * DAY_IN_SECONDS; // try to make it the first in line since it's upcoming
$flag_a = true;
}
}
} else { // has already started
$actual_end_timestamp_a = SBY_Parse_Pro::get_actual_end_timestamp( $a ); // get the time it ended
if ( $actual_end_timestamp_a === 0 ) { // started but hasn't ended! show it first, it's streaming now
$time_stamp_a = $time_stamp_a + 1000 * DAY_IN_SECONDS;
}
}
if ( empty( $time_stamp_b ) ) {
$time_stamp_b = SBY_Parse_Pro::get_scheduled_start_timestamp( $b );
if ( ! empty( $time_stamp_b ) ) {
if ( $time_stamp_b > time() - 1 * DAY_IN_SECONDS ) {
$time_stamp_b = $time_stamp_b + 30 * DAY_IN_SECONDS;
$flag_b = true;
}
}
} else {
$actual_end_timestamp_b = SBY_Parse_Pro::get_actual_end_timestamp( $b );
if ( $actual_end_timestamp_b === 0 ) {
$time_stamp_b = $time_stamp_b + 1000 * DAY_IN_SECONDS;
}
}
if ( empty( $time_stamp_a ) ) {
$time_stamp_a = SBY_Parse_Pro::get_timestamp( $a );
}
if ( empty( $time_stamp_b ) ) {
$time_stamp_b = SBY_Parse_Pro::get_timestamp( $b );
}
if ( $flag_a && $flag_b ) { //reverse the order if comparing two upcoming
return $time_stamp_a - $time_stamp_b;
}
return $time_stamp_b - $time_stamp_a;
}
/**
* @param $a
* @param $b
*
* @return false|int
*/
function sby_rand_sort( $a, $b ) {
return rand ( -1, 1 );
}
/**
* Converts a hex code to RGB so opacity can be
* applied more easily
*
* @param $hex
*
* @return string
*/
function sby_hextorgb( $hex ) {
// allows someone to use rgb in shortcode
if ( strpos( $hex, ',' ) !== false ) {
return $hex;
}
$hex = str_replace( '#', '', $hex );
if ( strlen( $hex ) === 3 ) {
$r = hexdec( substr( $hex,0,1 ).substr( $hex,0,1 ) );
$g = hexdec( substr( $hex,1,1 ).substr( $hex,1,1 ) );
$b = hexdec( substr( $hex,2,1 ).substr( $hex,2,1 ) );
} else {
$r = hexdec( substr( $hex,0,2 ) );
$g = hexdec( substr( $hex,2,2 ) );
$b = hexdec( substr( $hex,4,2 ) );
}
$rgb = array( $r, $g, $b );
return implode( ',', $rgb ); // returns the rgb values separated by commas
}
function sby_get_utc_offset() {
return get_option( 'gmt_offset', 0 ) * HOUR_IN_SECONDS;
}
function sby_is_pro_version() {
return sby_is_pro();
}
function sby_strip_after_hash( $string ) {
$string_array = explode( '#', $string );
$finished_string = $string_array[0];
return $finished_string;
}
function sby_esc_html_with_br( $text ) {
return str_replace( array( '<br />', '<br>' ), '
', esc_html( nl2br( $text ) ) );
}
function sby_esc_attr_with_br( $text ) {
return str_replace( array( '<br />', '<br>' ), '<br />', esc_attr( nl2br( $text ) ) );
}
function sby_maybe_shorten_text( $string, $feed_settings ) {
$limit = isset( $feed_settings['textlength'] ) ? $feed_settings['textlength'] : 120;
if ( strlen( $string ) <= $limit ) {
return $string;
}
$string = str_replace( '
', "\n\r", $string );
$parts = preg_split( '/([\s\n\r]+)/', $string, null, PREG_SPLIT_DELIM_CAPTURE );
$parts_count = count( $parts );
$length = 0;
$last_part = 0;
for ( ; $last_part < $parts_count; ++$last_part ) {
$length += strlen( $parts[ $last_part ] );
if ( $length > $limit ) { break; }
}
$last_part = $last_part !== 0 ? $last_part - 1 : 0;
$parts[ $last_part ] = $parts[ $last_part ] . '...';
$return_parts = array_slice( $parts, 0, $last_part + 1 );
$return = implode( ' ', $return_parts );
return $return;
}
function sby_doing_openssl() {
return extension_loaded( 'openssl' );
}
function sby_doing_customizer( $settings ) {
return ! empty( $settings['customizer'] ) && $settings['customizer'] == true;
}
/**
* YouTube Currect User Capability Check
*
* @since 2.0
*/
function sby_current_user_can( $cap ) {
if ( $cap === 'manage_youtube_feed_options' ) {
$cap = current_user_can( 'manage_youtube_feed_options' ) ? 'manage_youtube_feed_options' : 'manage_options';
}
$cap = apply_filters( 'sby_settings_pages_capability', $cap );
return current_user_can( $cap );
}
/**
* Check should add free plugin submenu for the free and pro version
*
* @since 2.0
*/
function sby_should_add_free_plugin_submenu( $plugin ) {
if ( $plugin === 'facebook' && !is_plugin_active( 'custom-facebook-feed/custom-facebook-feed.php' ) && !is_plugin_active( 'custom-facebook-feed-pro/custom-facebook-feed.php' ) ) {
return true;
}
if ( $plugin === 'instagram' && !is_plugin_active( 'instagram-feed/instagram-feed.php' ) && !is_plugin_active( 'instagram-feed-pro/instagram-feed.php' ) ) {
return true;
}
if ( $plugin === 'twitter' && !is_plugin_active( 'custom-twitter-feeds/custom-twitter-feed.php' ) && !is_plugin_active( 'custom-twitter-feeds-pro/custom-twitter-feed.php' ) ) {
return true;
}
if ( $plugin === 'tiktok' && !is_plugin_active( 'feeds-for-tiktok/feeds-for-tiktok.php' ) && !is_plugin_active( 'tiktok-feeds-pro/tiktok-feeds-pro.php' ) ) {
return true;
}
if ( $plugin === 'reviews' && !is_plugin_active( 'reviews-feed/sb-reviews.php' ) && !is_plugin_active( 'reviews-feed-pro/sb-reviews-pro.php' ) ) {
return true;
}
return;
}
/**
* Get other active Smash Balloon plugins info
*
* @since 2.0
*/
function sby_get_active_plugins_info() {
// get the WordPress's core list of installed plugins
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$installed_plugins = get_plugins();
$is_facebook_installed = false;
$facebook_plugin = 'custom-facebook-feed/custom-facebook-feed.php';
if ( isset( $installed_plugins['custom-facebook-feed-pro/custom-facebook-feed.php'] ) ) {
$is_facebook_installed = true;
$facebook_plugin = 'custom-facebook-feed-pro/custom-facebook-feed.php';
} else if ( isset( $installed_plugins['custom-facebook-feed/custom-facebook-feed.php'] ) ) {
$is_facebook_installed = true;
}
$is_instagram_installed = false;
$instagram_plugin = 'instagram-feed/instagram-feed.php';
if ( isset( $installed_plugins['instagram-feed-pro/instagram-feed.php'] ) ) {
$is_instagram_installed = true;
$instagram_plugin = 'instagram-feed-pro/instagram-feed.php';
} else if ( isset( $installed_plugins['instagram-feed/instagram-feed.php'] ) ) {
$is_instagram_installed = true;
}
$is_twitter_installed = false;
$twitter_plugin = 'custom-twitter-feeds/custom-twitter-feed.php';
if ( isset( $installed_plugins['custom-twitter-feeds-pro/custom-twitter-feed.php'] ) ) {
$is_twitter_installed = true;
$twitter_plugin = 'custom-twitter-feeds-pro/custom-twitter-feed.php';
} else if ( isset( $installed_plugins['custom-twitter-feeds/custom-twitter-feed.php'] ) ) {
$is_twitter_installed = true;
}
$is_youtube_installed = false;
$youtube_plugin = 'feeds-for-youtube/youtube-feed.php';
if ( isset( $installed_plugins['youtube-feed-pro/youtube-feed-pro.php'] ) ) {
$is_youtube_installed = true;
$youtube_plugin = 'youtube-feed-pro/youtube-feed-pro.php';
} elseif ( isset( $installed_plugins['feeds-for-youtube/youtube-feed.php'] ) ) {
$is_youtube_installed = true;
}
$is_tiktok_installed = false;
$tiktok_plugin = 'feeds-for-tiktok/feeds-for-tiktok.php';
if ( isset( $installed_plugins['tiktok-feeds-pro/tiktok-feeds-pro.php'] ) ) {
$is_tiktok_installed = true;
$tiktok_plugin = 'tiktok-feeds-pro/tiktok-feeds-pro.php';
} elseif ( isset( $installed_plugins['feeds-for-tiktok/feeds-for-tiktok.php'] ) ) {
$is_tiktok_installed = true;
}
$is_reviews_installed = false;
$reviews_plugin = 'reviews-feed/sb-reviews.php';
if ( isset( $installed_plugins['reviews-feed-pro/sb-reviews-pro.php'] ) ) {
$is_reviews_installed = true;
$reviews_plugin = 'reviews-feed-pro/sb-reviews-pro.php';
} elseif ( isset( $installed_plugins['reviews-feed/sb-reviews.php'] ) ) {
$is_reviews_installed = true;
}
$is_social_wall_installed = isset( $installed_plugins['social-wall/social-wall.php'] ) ? true : false;
$social_wall_plugin = 'social-wall/social-wall.php';
$click_social_plugin = 'click-social/click-social.php';
$is_click_social_installed = isset( $installed_plugins[$click_social_plugin] ) ? true : false;
return array(
'is_facebook_installed' => $is_facebook_installed,
'is_instagram_installed' => $is_instagram_installed,
'is_twitter_installed' => $is_twitter_installed,
'is_youtube_installed' => $is_youtube_installed,
'is_tiktok_installed' => $is_tiktok_installed,
'is_reviews_installed' => $is_reviews_installed,
'is_social_wall_installed' => $is_social_wall_installed,
'is_click_social_installed' => $is_click_social_installed,
'facebook_plugin' => $facebook_plugin,
'instagram_plugin' => $instagram_plugin,
'twitter_plugin' => $twitter_plugin,
'youtube_plugin' => $youtube_plugin,
'tiktok_plugin' => $tiktok_plugin,
'reviews_plugin' => $reviews_plugin,
'social_wall_plugin' => $social_wall_plugin,
'click_social_plugin' => $click_social_plugin,
'installed_plugins' => $installed_plugins
);
}
/**
* Get plugin info
*
* @since 2.0
*/
function sby_get_installed_plugin_info() {
$sb_other_plugins = sby_get_active_plugins_info();
return array(
'facebook' => array(
'displayName' => __( 'Facebook', 'feeds-for-youtube' ),
'name' => __( 'Facebook Feed', 'feeds-for-youtube' ),
'author' => __( 'By Smash Balloon', 'feeds-for-youtube' ),
'description' => __('To display a Facebook feed, our Facebook plugin is required. It provides a clean and beautiful way to add your Facebook posts to your website. Grab your visitors attention and keep them engaged with your site longer.', 'feeds-for-youtube'),
'dashboard_permalink' => admin_url( 'admin.php?page=cff-feed-builder' ),
'svgIcon' => '',
'installed' => isset( $sb_other_plugins['is_facebook_installed'] ) && $sb_other_plugins['is_facebook_installed'] == true,
'class' => 'CFF_Elementor_Widget',
'activated' => is_plugin_active( $sb_other_plugins['facebook_plugin'] ),
'plugin' => $sb_other_plugins['facebook_plugin'],
'download_plugin' => 'https://downloads.wordpress.org/plugin/custom-facebook-feed.zip',
'website_link' => 'https://smashballoon.com/custom-facebook-feed/'
),
'instagram' => array(
'displayName' => __( 'Instagram', 'feeds-for-youtube' ),
'name' => __( 'Instagram Feed', 'feeds-for-youtube' ),
'author' => __( 'By Smash Balloon', 'feeds-for-youtube' ),
'description' => __('To display an Instagram feed, our Instagram plugin is required. It provides a clean and beautiful way to add your Instagram posts to your website. Grab your visitors attention and keep them engaged with your site longer.', 'feeds-for-youtube'),
'dashboard_permalink' => admin_url( 'admin.php?page=sbi-feed-builder' ),
'svgIcon' => '',
'installed' => isset( $sb_other_plugins['is_instagram_installed'] ) && $sb_other_plugins['is_instagram_installed'] == true,
'class' => 'SBI_Elementor_Widget',
'activated' => is_plugin_active( $sb_other_plugins['instagram_plugin'] ),
'plugin' => $sb_other_plugins['instagram_plugin'],
'download_plugin' => 'https://downloads.wordpress.org/plugin/instagram-feed.zip',
'website_link' => 'https://smashballoon.com/instagram-feed/'
),
'twitter' => array(
'displayName' => __( 'Twitter', 'feeds-for-youtube' ),
'name' => __( 'Twitter Feed', 'feeds-for-youtube' ),
'author' => __( 'By Smash Balloon', 'feeds-for-youtube' ),
'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.', 'feeds-for-youtube'),
'dashboard_permalink' => admin_url( 'admin.php?page=ctf-feed-builder' ),
'svgIcon' => '',
'installed' => isset( $sb_other_plugins['is_twitter_installed'] ) && $sb_other_plugins['is_twitter_installed'] == true,
'class' => 'CTF_Elementor_Widget',
'activated' => is_plugin_active( $sb_other_plugins['twitter_plugin'] ),
'plugin' => $sb_other_plugins['twitter_plugin'],
'download_plugin' => 'https://downloads.wordpress.org/plugin/custom-twitter-feeds.zip',
'website_link' => 'https://smashballoon.com/custom-twitter-feeds/'
),
'tiktok' => array(
'displayName' => __( 'Tiktok', 'feeds-for-youtube' ),
'name' => __( 'Tiktok Feed', 'feeds-for-youtube' ),
'author' => __( 'By Smash Balloon', 'feeds-for-youtube' ),
'description' => __('To display your TikToks, TikTok Feeds is required. Display your latest TikTok videos in a clean feed featuring a video player so visitors can watch without leaving your site. Keep your visitors engaged and boost your TikTok audience.', 'feeds-for-youtube'),
'dashboard_permalink' => admin_url( 'admin.php?page=sbtt' ),
'svgIcon' => '',
'installed' => isset( $sb_other_plugins['is_tiktok_installed'] ) && $sb_other_plugins['is_tiktok_installed'] == true,
'class' => 'SBTT_Elementor_Widget',
'activated' => is_plugin_active( $sb_other_plugins['tiktok_plugin'] ),
'plugin' => $sb_other_plugins['tiktok_plugin'],
'download_plugin' => 'https://downloads.wordpress.org/plugin/feeds-for-tiktok.zip',
'website_link' => 'https://smashballoon.com/tiktok-feeds/'
),
'reviews' => array(
'displayName' => __( 'Reviews', 'feeds-for-youtube' ),
'name' => __( 'Reviews Feed', 'feeds-for-youtube' ),
'author' => __( 'By Smash Balloon', 'feeds-for-youtube' ),
'description' => __('To display reviews in a feed, Reviews Feed is required. Display reviews from Google Reviews or Yelp in a clean feed on your site. Increase conversions with social proof from your latest public reviews.', 'feeds-for-youtube'),
'dashboard_permalink' => admin_url( 'admin.php?page=sbr' ),
'svgIcon' => '',
'installed' => isset( $sb_other_plugins['is_reviews_installed'] ) && $sb_other_plugins['is_reviews_installed'] == true,
'class' => 'SBR_Elementor_Widget',
'activated' => is_plugin_active( $sb_other_plugins['reviews_plugin'] ),
'plugin' => $sb_other_plugins['reviews_plugin'],
'download_plugin' => 'https://downloads.wordpress.org/plugin/reviews-feed.zip',
'website_link' => 'https://smashballoon.com/reviews-feed/'
),
'youtube' => [
'installed' => $sb_other_plugins['is_youtube_installed'],
'class' => 'SBY_Elementor_Widget',
'link' => 'https://smashballoon.com/youtube-feed/',
'icon' => '',
'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.', 'feeds-for-youtube'),
'download_plugin' => 'https://downloads.wordpress.org/plugin/feeds-for-youtube.zip',
]
);
}
/**
* Set the customizer feeds table
*
* @since 2.0
*/
function sb_customizer_feeds_table() {
global $wpdb;
return $wpdb->prefix . 'sby_feeds';
}
add_action('sb_customizer_feeds_table', 'sb_customizer_feeds_table');
function sby_get_account_and_feed_info() {
$yt_atts = array();
$yt_database_settings = sby_get_database_settings();
$youtube_feed_settings = new SBY_Settings_Pro( $yt_atts, $yt_database_settings );
$youtube_feed_settings->set_feed_type_and_terms();
$yt_feed_type_and_terms = $youtube_feed_settings->get_feed_type_and_terms();
$type_and_terms = array();
$terms_array = array();
foreach ( $yt_feed_type_and_terms as $key => $values ) {
if ( empty( $type_and_terms['type'] ) ) {
$type_and_terms['type'] = $key;
$type_and_terms['term_label'] = '';
foreach ( $values as $value ) {
$terms_array[] = $value['term'];
}
}
}
$type_and_terms['terms'] = $terms_array;
$return['type_and_terms'] = $type_and_terms;
$return['connected_accounts'] = sby_get_first_connected_account();
if ( isset( $return['connected_accounts']['api_key'] ) ) {
$return['available_types'] = array(
'channels' => array(
'label' => 'Channel',
'shortcode' => 'channel',
'term_shortcode' => 'channel',
'input' => 'text',
'instructions' => __( 'Any channel ID', 'feeds-for-youtube' )
),
'playlist' => array(
'label' => 'Playlist',
'shortcode' => 'playlist',
'term_shortcode' => 'playlist',
'input' => 'text',
'instructions' => __( 'Any playlist ID', 'feeds-for-youtube' )
),
'favorites' => array(
'label' => 'Favorites',
'shortcode' => 'favorites',
'term_shortcode' => 'channel',
'input' => 'text',
'instructions' => __( 'Any channel ID', 'feeds-for-youtube' )
),
'search' => array(
'label' => 'Search',
'shortcode' => 'search',
'term_shortcode' => 'search',
'input' => 'text',
'instructions' => __( 'A search term', 'feeds-for-youtube' )
),
'livestream' => array(
'label' => 'Live Stream',
'shortcode' => 'livestream',
'term_shortcode' => 'channel',
'input' => 'text',
'instructions' => __( 'Any channel ID', 'feeds-for-youtube' )
),
'single' => array(
'label' => 'Single',
'shortcode' => 'single',
'term_shortcode' => 'single',
'input' => 'text',
'instructions' => __( 'Video IDs (separated by comma)', 'feeds-for-youtube' )
),
);
} else {
$return['available_types'] = array(
'channels' => array(
'label' => 'Channel',
'shortcode' => 'channel',
'term_shortcode' => 'channel',
'input' => 'text',
'instructions' => __( 'Any channel ID', 'feeds-for-youtube' )
),
'feed' => array(
'label' => 'Feeds',
'shortcode' => 'feed',
'term_shortcode' => 'feed',
'input' => 'text',
'instructions' => __( 'Feed ID', 'feeds-for-youtube' )
)
);
}
$return['settings'] = array(
'type' => 'type'
);
$channel_ids_names = array();
global $sby_settings;
$connected_accounts = $sby_settings['connected_accounts'];
foreach ( $connected_accounts as $connected_account ) {
if ( ! empty( $connected_account['username'] ) && ! empty( $connected_account['channel_id'] ) ) {
$channel_ids_names[ $connected_account['channel_id'] ] = $connected_account['username'];
}
}
$return['channel_ids_names'] = $channel_ids_names;
return $return;
}
function sby_maybe_clear_cache_using_cron() {
if ( sby_is_pro() ) {
return;
}
global $sby_settings;
$sby_doing_cron_clear = isset( $sby_settings['cronclear'] ) ? $sby_settings['cronclear'] : false;
if ( $sby_doing_cron_clear ) {
sby_clear_cache();
}
}
add_action( 'sby_cron_job', 'sby_maybe_clear_cache_using_cron' );
/**
* This will automatically upload featured image to YouTube CPT posts
*
* @since 2.1
*/
if ( !function_exists( 'sby_upload_featured_image' ) ) {
function sby_native_upload_featured_image( $post_id, $api_data ) {
global $sby_settings;
if ( has_post_thumbnail( $post_id ) || ! $sby_settings[ 'save_featured_images' ] ) {
return;
}
$file = SBY_Parse::get_media_url( $api_data );
$filename = SBY_Parse::get_video_id( $api_data );
$title = SBY_Parse::get_video_title( $api_data );
$uploaddir = wp_upload_dir();
$uploadfile = $uploaddir['path'] . '/' . $filename . '.jpg';
$contents = file_get_contents( $file );
$savefile = fopen( $uploadfile, 'w' );
$success = fwrite( $savefile, $contents );
fclose( $savefile );
if ( $success ) {
// if succesfull insert the new file into the media library (create a new attachment post type).
$wp_filetype = wp_check_filetype( $uploadfile, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_parent' => $post_id,
'post_title' => 'Image for ' . preg_replace( '/\.[^.]+$/', '', $title ),
'post_content' => '',
'post_status' => 'inherit'
);
$attachment_id = wp_insert_attachment( $attachment, $uploadfile, $post_id );
if ( ! is_wp_error( $attachment_id ) ) {
// if attachment post was successfully created, insert it as a thumbnail to the post $post_id.
require_once( ABSPATH . "wp-admin" . '/includes/image.php' );
$attachment_data = wp_generate_attachment_metadata( $attachment_id, $uploadfile );
wp_update_attachment_metadata( $attachment_id, $attachment_data );
set_post_thumbnail( $post_id, $attachment_id );
}
}
}
add_action( 'sby_after_insert_video_post', 'sby_native_upload_featured_image', 10, 2 );
add_action( 'sby_after_update_video_post', 'sby_native_upload_featured_image', 10, 2 );
}
/**
* Get the UTM Campaign name according to the plugin version
*
* @since 2.0
*/
function sby_utm_campaign() {
if ( sby_is_pro() ) {
return 'youtube-pro';
}
return 'youtube-free';
}