';
}
$preloader = isset( $shortcode_data['wpcp_preloader'] ) ? $shortcode_data['wpcp_preloader'] : true;
$wpcp_layout = isset( $shortcode_data['wpcp_layout'] ) ? $shortcode_data['wpcp_layout'] : 'carousel';
$wpcp_slider_effect = isset( $shortcode_data['wpcp_slider_style'] ) ? $shortcode_data['wpcp_slider_style'] : 'normal';
$preloader_image = apply_filters( 'wpcp_preloader_image', WPCAROUSEL_URL . 'Frontend/css/spinner.svg' );
$section_title = isset( $shortcode_data['section_title'] ) ? $shortcode_data['section_title'] : true;
$wpcp_screen_sizes = wpcp_get_option( 'wpcp_responsive_screen_setting' );
$desktop_size = isset( $wpcp_screen_sizes['desktop'] ) && ! empty( $wpcp_screen_sizes['desktop'] ) ? $wpcp_screen_sizes['desktop'] : '1200';
$laptop_size = isset( $wpcp_screen_sizes['laptop'] ) && ! empty( $wpcp_screen_sizes['laptop'] ) ? $wpcp_screen_sizes['laptop'] : '980';
$tablet_size = isset( $wpcp_screen_sizes['tablet'] ) && ! empty( $wpcp_screen_sizes['tablet'] ) ? $wpcp_screen_sizes['tablet'] : '736';
$mobile_size = isset( $wpcp_screen_sizes['mobile'] ) && ! empty( $wpcp_screen_sizes['mobile'] ) ? $wpcp_screen_sizes['mobile'] : '480';
// Carousel Column Number Settings.
$column_number = isset( $shortcode_data['wpcp_number_of_columns'] ) ? $shortcode_data['wpcp_number_of_columns'] : '';
$column_lg_desktop = isset( $column_number['lg_desktop'] ) && ! empty( $column_number['lg_desktop'] ) ? $column_number['lg_desktop'] : '5';
$column_desktop = isset( $column_number['desktop'] ) && ! empty( $column_number['desktop'] ) ? $column_number['desktop'] : '4';
$column_laptop = isset( $column_number['laptop'] ) && ! empty( $column_number['laptop'] ) ? $column_number['laptop'] : '3';
$column_tablet = isset( $column_number['tablet'] ) && ! empty( $column_number['tablet'] ) ? $column_number['tablet'] : '2';
$column_mobile = isset( $column_number['mobile'] ) && ! empty( $column_number['mobile'] ) ? $column_number['mobile'] : '1';
$carousel_classes = ' ';
// Slide margin.
$slide_margin = isset( $shortcode_data['wpcp_slide_margin']['all'] ) && is_numeric( $shortcode_data['wpcp_slide_margin']['all'] ) ? $shortcode_data['wpcp_slide_margin']['all'] : '20';
$slide_margin = isset( $shortcode_data['wpcp_slide_margin']['top'] ) && is_numeric( $shortcode_data['wpcp_slide_margin']['top'] ) ? $shortcode_data['wpcp_slide_margin']['top'] : $slide_margin;
$slide_margin_horizontal = isset( $shortcode_data['wpcp_slide_margin']['right'] ) && is_numeric( $shortcode_data['wpcp_slide_margin']['right'] ) ? $shortcode_data['wpcp_slide_margin']['right'] : $slide_margin;
$data_carousel_mode = '';
$data_slider_effect = '';
if ( self::is_carousel( $wpcp_layout ) ) {
// Responsive screen sizes.
$carousel_mode = isset( $shortcode_data['wpcp_carousel_mode'] ) ? $shortcode_data['wpcp_carousel_mode'] : 'standard';
$carousel_orientation = isset( $shortcode_data['wpcp_carousel_orientation'] ) ? $shortcode_data['wpcp_carousel_orientation'] : 'horizontal';
$vertical = ( 'vertical' === $carousel_orientation ) ? 'true' : 'false';
// Center Mode.
$center_mode = 'center' === $carousel_mode ? 'true' : 'false';
$center_padding = '0';
$center_padding_desktop = '0';
$center_padding_laptop = '0';
$center_padding_tablet = '0';
$center_padding_mobile = '0';
if ( 'true' === $center_mode ) {
$center_mode_padding = isset( $shortcode_data['wpcp_image_center_mode_padding'] ) ? $shortcode_data['wpcp_image_center_mode_padding'] : '';
$center_padding = isset( $center_mode_padding['lg_desktop'] ) ? $center_mode_padding['lg_desktop'] : '100';
$center_padding_desktop = isset( $center_mode_padding['desktop'] ) ? $center_mode_padding['desktop'] : '100';
$center_padding_laptop = isset( $center_mode_padding['laptop'] ) ? $center_mode_padding['laptop'] : '70';
$center_padding_tablet = isset( $center_mode_padding['tablet'] ) ? $center_mode_padding['tablet'] : '50';
$center_padding_mobile = isset( $center_mode_padding['mobile'] ) ? $center_mode_padding['mobile'] : '40';
}
// Ticker Mode.
$slide_width = isset( $shortcode_data['wpcp_slide_width']['all'] ) && ! empty( $shortcode_data['wpcp_slide_width']['all'] ) ? $shortcode_data['wpcp_slide_width']['all'] : '250';
// Carousel Row.
$carousel_row = ! empty( $shortcode_data['wpcp_carousel_row'] ) ? $shortcode_data['wpcp_carousel_row'] : array(
'lg_desktop' => '2',
'desktop' => '2',
'laptop' => '2',
'tablet' => '2',
'mobile' => '2',
);
if ( 'multi-row' === $carousel_mode ) {
$row_lg_desktop = ! empty( $carousel_row['lg_desktop'] ) ? $carousel_row['lg_desktop'] : 2;
$row_desktop = ! empty( $carousel_row['desktop'] ) ? $carousel_row['desktop'] : 2;
$row_laptop = ! empty( $carousel_row['laptop'] ) ? $carousel_row['laptop'] : 2;
$row_tablet = ! empty( $carousel_row['tablet'] ) ? $carousel_row['tablet'] : 2;
$row_mobile = ! empty( $carousel_row['mobile'] ) ? $carousel_row['mobile'] : 2;
} else {
$row_lg_desktop = 1;
$row_desktop = 1;
$row_laptop = 1;
$row_tablet = 1;
$row_mobile = 1;
}
$data_carousel_mode = $carousel_mode;
// Ticker Carousel.
$column_number_ticker = isset( $shortcode_data['wpcp_number_of_columns_ticker'] ) ? $shortcode_data['wpcp_number_of_columns_ticker'] : '';
$max_column = isset( $column_number_ticker['lg_desktop'] ) ? $column_number_ticker['lg_desktop'] : '5';
$min_column = isset( $column_number_ticker['mobile'] ) ? $column_number_ticker['mobile'] : '2';
// Carousel Settings.
// Carousel Normal Settings.
$is_auto_play = isset( $shortcode_data['wpcp_carousel_auto_play'] ) ? $shortcode_data['wpcp_carousel_auto_play'] : true;
$auto_play = $is_auto_play ? 'true' : 'false';
// Autoplay Speed.
$autoplay_speed_old = isset( $shortcode_data['carousel_auto_play_speed']['all'] ) && ! empty( $shortcode_data['carousel_auto_play_speed']['all'] ) ? $shortcode_data['carousel_auto_play_speed']['all'] : '3000';
$autoplay_speed = isset( $shortcode_data['carousel_auto_play_speed'] ) && is_string( $shortcode_data['carousel_auto_play_speed'] ) ? $shortcode_data['carousel_auto_play_speed'] : $autoplay_speed_old;
// Carousel Speed.
$old_speed = isset( $shortcode_data['standard_carousel_scroll_speed']['all'] ) && ! empty( $shortcode_data['standard_carousel_scroll_speed']['all'] ) ? $shortcode_data['standard_carousel_scroll_speed']['all'] : '600';
$speed = isset( $shortcode_data['standard_carousel_scroll_speed'] ) && is_string( $shortcode_data['standard_carousel_scroll_speed'] ) ? $shortcode_data['standard_carousel_scroll_speed'] : $old_speed;
$ticker_speed = isset( $shortcode_data['ticker_carousel_scroll_speed']['all'] ) && ! empty( $shortcode_data['ticker_carousel_scroll_speed']['all'] ) ? $shortcode_data['ticker_carousel_scroll_speed']['all'] : '8000';
// Slide to scroll.
$slide_to_scroll_lg_desktop = isset( $shortcode_data['slides_to_scroll']['lg_desktop'] ) ? $shortcode_data['slides_to_scroll']['lg_desktop'] : '1';
$slide_to_scroll_desktop = isset( $shortcode_data['slides_to_scroll']['desktop'] ) ? $shortcode_data['slides_to_scroll']['desktop'] : '1';
$slide_to_scroll_laptop = isset( $shortcode_data['slides_to_scroll']['laptop'] ) ? $shortcode_data['slides_to_scroll']['laptop'] : '1';
$slide_to_scroll_tablet = isset( $shortcode_data['slides_to_scroll']['tablet'] ) ? $shortcode_data['slides_to_scroll']['tablet'] : '1';
$slide_to_scroll_mobile = isset( $shortcode_data['slides_to_scroll']['mobile'] ) ? $shortcode_data['slides_to_scroll']['mobile'] : '1';
$is_infinite = isset( $shortcode_data['carousel_infinite'] ) ? $shortcode_data['carousel_infinite'] : '';
$infinite = $is_infinite ? 'true' : 'false';
$is_pause_on_hover = isset( $shortcode_data['carousel_pause_on_hover'] ) ? $shortcode_data['carousel_pause_on_hover'] : '';
$pause_on_hover = $is_pause_on_hover ? 'true' : 'false';
$carousel_direction = isset( $shortcode_data['wpcp_carousel_direction'] ) ? $shortcode_data['wpcp_carousel_direction'] : '';
$slider_animation = isset( $shortcode_data['wpcp_slider_animation'] ) && 'standard' === $carousel_mode ? $shortcode_data['wpcp_slider_animation'] : 'slider';
// Navigation settings.
$arrow_position = isset( $shortcode_data['wpcp_carousel_nav_position'] ) ? $shortcode_data['wpcp_carousel_nav_position'] : 'vertical_outer';
$wpcp_visible_on_hover = isset( $shortcode_data['wpcp_visible_on_hover'] ) ? $shortcode_data['wpcp_visible_on_hover'] : false;
$wpcp_arrows = isset( $shortcode_data['wpcp_carousel_navigation']['wpcp_navigation'] ) ? $shortcode_data['wpcp_carousel_navigation']['wpcp_navigation'] : true;
$wpcp_hide_on_mobile = isset( $shortcode_data['wpcp_carousel_navigation']['wpcp_hide_on_mobile'] ) ? $shortcode_data['wpcp_carousel_navigation']['wpcp_hide_on_mobile'] : '';
$shaders_effect = isset( $shortcode_data['shaders_effect'] ) ? $shortcode_data['shaders_effect'] : 'random';
$arrows = 'false';
$arrows_mobile = 'false';
if ( $wpcp_arrows ) {
$arrows = 'true';
$arrows_mobile = 'false';
}
if ( $wpcp_hide_on_mobile ) {
$arrows = 'true';
$arrows_mobile = 'true';
}
$nav_icons = isset( $shortcode_data['navigation_icons'] ) ? $shortcode_data['navigation_icons'] : 'angle';
// Pagination settings.
$wpcp_dots = isset( $shortcode_data['wpcp_carousel_pagination']['wpcp_pagination'] ) ? $shortcode_data['wpcp_carousel_pagination']['wpcp_pagination'] : true;
$wpcp_pagination_hide_on_mobile = isset( $shortcode_data['wpcp_carousel_pagination']['wpcp_pagination_hide_on_mobile'] ) ? $shortcode_data['wpcp_carousel_pagination']['wpcp_pagination_hide_on_mobile'] : '';
$dots = 'false';
$dots_mobile = 'false';
if ( $wpcp_dots ) {
$dots = 'true';
$dots_mobile = 'false';
}
if ( $wpcp_pagination_hide_on_mobile ) {
$dots = 'true';
$dots_mobile = 'true';
}
$carousel_pagination_type = isset( $shortcode_data['wpcp_carousel_pagination_type'] ) ? $shortcode_data['wpcp_carousel_pagination_type'] : 'dots';
// Miscellaneous Settings.
$is_adaptive_height = isset( $shortcode_data['wpcp_adaptive_height'] ) ? $shortcode_data['wpcp_adaptive_height'] : true;
$adaptive_height = $is_adaptive_height ? 'true' : 'false';
$is_tab_and_key_accessibility = isset( $shortcode_data['wpcp_accessibility'] ) ? $shortcode_data['wpcp_accessibility'] : true;
$accessibility = $is_tab_and_key_accessibility ? 'true' : 'false';
$is_swipe = isset( $shortcode_data['slider_swipe'] ) ? $shortcode_data['slider_swipe'] : true;
$swipe = $is_swipe ? 'true' : 'false';
$is_draggable = isset( $shortcode_data['slider_draggable'] ) ? $shortcode_data['slider_draggable'] : true;
$draggable = $is_draggable ? 'true' : 'false';
$is_swipetoslide = isset( $shortcode_data['carousel_swipetoslide'] ) ? $shortcode_data['carousel_swipetoslide'] : true;
$swipetoslide = $is_swipetoslide ? 'true' : 'false';
$free_mode = isset( $shortcode_data['free_mode'] ) && $shortcode_data['free_mode'] ? 'true' : 'false';
$is_variable_width = isset( $shortcode_data['_variable_width'] ) ? $shortcode_data['_variable_width'] : '';
$variable_width = 'false';
if ( 'horizontal' === $carousel_orientation ) {
$variable_width = $is_variable_width ? 'true' : 'false';
}
// Vertical carousel always rtl mode.
if ( 'vertical' === $carousel_orientation && 'thumbnails-slider' !== $wpcp_layout ) {
$carousel_direction = 'rtl';
$slider_animation = 'false';
$variable_width = 'false';
}
if ( 'vertical' === $carousel_orientation ) {
$slider_animation = 'false';
}
$the_rtl = '';
$data_shaders_effect = '';
if ( 'ticker' === $carousel_mode && 'thumbnails-slider' !== $wpcp_layout ) {
$carousel_direction = isset( $shortcode_data['wpcp_carousel_direction'] ) ? $shortcode_data['wpcp_carousel_direction'] : '';
$auto_direction = 'rtl' === $carousel_direction ? 'next' : 'prev';
$ticker_drag = true === apply_filters( 'sp_wpcp_enable_mouse_drag_in_ticker', false ) ? 'true' : 'false';
if ( wpcp_get_option( 'wpcp_bx_js', true ) ) {
wp_enqueue_script( 'wpcp-bx-slider' );
}
wp_enqueue_script( 'wpcp-bx-slider-config' );
$carousel_classes .= ' wpcp-ticker';
$wpcp_bx_config = ' data-mode="' . $carousel_orientation . '" data-max-slides="' . $max_column . '" data-min-slides="' . $min_column . '" data-hover-pause="' . $pause_on_hover . '" data-speed="' . $ticker_speed . '" data-slide-width="' . $slide_width . '" data-variable-width="' . $variable_width . '" data-slide-margin="' . $slide_margin . '" data-direction="' . $auto_direction . '" data-ticker-drag="' . $ticker_drag . '"';
} else {
$the_rtl = ( 'ltr' === $carousel_direction ) ? ' dir="rtl"' : ' dir="ltr"';
$rtl = ( 'ltr' === $carousel_direction ) ? 'true' : 'false';
if ( wpcp_get_option( 'wpcp_swiper_js', true ) ) {
wp_enqueue_script( 'wpcp-swiper' );
}
if ( 'thumbnails-slider' === $wpcp_layout ) {
$carousel_classes .= ' wpcp-thumbnail-slider';
} else {
$carousel_classes .= ' wpcp-standard';
}
// Need lazyload var.
$lazy_load_image = isset( $shortcode_data['wpcp_image_lazy_load'] ) ? $shortcode_data['wpcp_image_lazy_load'] : 'false';
$lazy_load_image = ( '1' === $lazy_load_image || 'ondemand' === $lazy_load_image ) && 'true' !== $variable_width ? 'ondemand' : 'false';
// Navigation arrow classes.
if ( $wpcp_arrows && 'ticker' !== $carousel_mode ) {
$visible_on_hover = $wpcp_visible_on_hover ? ' nav-vertical-on-hover' : '';
switch ( $arrow_position ) {
case 'top_right':
$carousel_classes .= ' nav-top-right';
break;
case 'top_center':
$carousel_classes .= ' nav-top-center';
break;
case 'top_left':
$carousel_classes .= ' nav-top-left';
break;
case 'bottom_left':
$carousel_classes .= ' nav-bottom-left';
break;
case 'bottom_center':
$carousel_classes .= ' nav-bottom-center';
break;
case 'bottom_right':
$carousel_classes .= ' nav-bottom-right';
break;
case 'vertical_outer':
$carousel_classes .= ' nav-vertical-center ' . $visible_on_hover . '';
break;
case 'vertical_center_inner':
$carousel_classes .= ' nav-vertical-center-inner ' . $visible_on_hover . '';
break;
case 'vertical_center':
$carousel_classes .= ' nav-vertically-inner-and-outer ' . $visible_on_hover . '';
break;
}
}
$thumbnail_slider_orientation = isset( $shortcode_data['thumbnails_orientation'] ) ? $shortcode_data['thumbnails_orientation'] : 'horizontal';
$thumbnail_position = isset( $shortcode_data['wpcp_thumbnail_position'] ) ? $shortcode_data['wpcp_thumbnail_position'] : 'bottom';
$_position = 'horizontal';
if ( 'left' === $thumbnail_position || 'right' === $thumbnail_position ) {
$_position = 'vertical';
}
if ( 'slider' === $wpcp_layout ) {
$slider_animation = $wpcp_slider_effect;
$data_slider_effect = $wpcp_slider_effect;
$data_shaders_effect = $shaders_effect;
$vertical = 'false';
$center_mode = 'false';
if ( 'kenburn' === $slider_animation ) {
$carousel_classes .= ' wpcp-kenburn';
$slider_animation = 'fade';
}
if ( 'shaders' === $wpcp_slider_effect ) {
wp_enqueue_script( 'wpcp-swiper-gl' );
}
// Setting column and row values for 'slider' layout.
$column_tablet = 1;
$column_desktop = 1;
$column_mobile = 1;
$column_laptop = 1;
$column_lg_desktop = 1;
$row_desktop = 1;
$row_tablet = 1;
$row_mobile = 1;
$row_laptop = 1;
$row_lg_desktop = 1;
$slide_to_scroll_lg_desktop = 1;
$slide_to_scroll_mobile = 1;
$slide_to_scroll_tablet = 1;
$slide_to_scroll_desktop = 1;
$slide_to_scroll_laptop = 1;
} else {
// Effect for carousel.
$data_slider_effect = $carousel_mode;
if ( 'standard' === $carousel_mode ) {
$data_slider_effect = $slider_animation;
}
if ( 'fade' === $slider_animation || 'cube' === $slider_animation || 'flip' === $slider_animation || 'kenburn' === $slider_animation ) {
$carousel_classes .= ' wpcp-advance-effect';
if ( 'kenburn' === $slider_animation ) {
$carousel_classes .= ' wpcp-kenburn';
$slider_animation = 'fade';
}
}
}
if ( 'true' === $center_mode ) {
$carousel_classes .= ' wpcp-center';
}
$wpcp_swiper_options = 'data-swiper=\'{"pagination_type": "' . $carousel_pagination_type . '","vertical":' . $vertical . ',"orientation":"' . $_position . '","slider_orientation": "' . $thumbnail_slider_orientation . '","accessibility":true, "centerMode":' . $center_mode . ', "centerPadding":{"lg_desktop":"' . $center_padding . '", "desktop":"' . $center_padding_desktop . '", "laptop":"' . $center_padding_laptop . '", "tablet":"' . $center_padding_tablet . '", "mobile":"' . $center_padding_mobile . '"}, "swipeToSlide":' . $swipetoslide . ', "adaptiveHeight":' . $adaptive_height . ', "carousel_accessibility":' . $accessibility . ', "arrows":' . $arrows . ', "autoplay":' . $auto_play . ', "autoplaySpeed":' . $autoplay_speed . ', "spaceBetween":' . $slide_margin . ', "dots":' . $dots . ', "infinite":' . $infinite . ', "speed":' . $speed . ', "pauseOnHover":' . $pause_on_hover . ', "slidesToScroll":{"lg_desktop":' . $slide_to_scroll_lg_desktop . ', "desktop":' . $slide_to_scroll_desktop . ', "laptop":' . $slide_to_scroll_laptop . ', "tablet":' . $slide_to_scroll_tablet . ', "mobile":' . $slide_to_scroll_mobile . '}, "slidesToShow":{"lg_desktop":' . $column_lg_desktop . ', "desktop":' . $column_desktop . ', "laptop":' . $column_laptop . ', "tablet":' . $column_tablet . ', "mobile":' . $column_mobile . '}, "rows":{"lg_desktop":' . $row_lg_desktop . ', "desktop":' . $row_desktop . ', "laptop":' . $row_laptop . ', "tablet":' . $row_tablet . ', "mobile":' . $row_mobile . '}, "responsive":{"desktop":' . $desktop_size . ', "laptop": ' . $laptop_size . ', "tablet": ' . $tablet_size . ', "mobile": ' . $mobile_size . '}, "rtl":' . $rtl . ', "variableWidth":' . $variable_width . ', "effect":"' . $slider_animation . '", "lazyLoad": "' . $lazy_load_image . '", "swipe": ' . $swipe . ', "draggable": ' . $draggable . ', "freeMode":' . $free_mode . ' }\' data-arrowtype="' . $nav_icons . '"' . $the_rtl . '';
}
$carousel_attr = ( 'ticker' === $carousel_mode && 'thumbnails-slider' !== $wpcp_layout ? $wpcp_bx_config : $wpcp_swiper_options ) . $the_rtl;
$carousel_types = 'data-carousel_type="' . esc_attr( $carousel_type ) . '"';
}
$wpcp_content_style = isset( $shortcode_data['wpcp_content_style'] ) ? $shortcode_data['wpcp_content_style'] : 'default';
$wpcp_overlay_position = isset( $shortcode_data['wpcp_overlay_position'] ) ? $shortcode_data['wpcp_overlay_position'] : 'full_covered';
$wpcp_caption_full = isset( $shortcode_data['wpcp_caption_full'] ) ? $shortcode_data['wpcp_caption_full'] : 'bottom';
$wpcp_caption_partial = isset( $shortcode_data['wpcp_caption_partial'] ) ? $shortcode_data['wpcp_caption_partial'] : 'bottom_left';
$wpcp_caption_diagonal = isset( $shortcode_data['wpcp_caption_diagonal'] ) ? $shortcode_data['wpcp_caption_diagonal'] : 'bottom_left';
$wpcp_content_box = isset( $shortcode_data['wpcp_content_box'] ) ? $shortcode_data['wpcp_content_box'] : 'bottom';
$wpcp_post_detail = isset( $shortcode_data['wpcp_post_detail_position'] ) ? $shortcode_data['wpcp_post_detail_position'] : '';
$wpcp_overlay_visibility = isset( $shortcode_data['wpcp_overlay_visibility'] ) ? $shortcode_data['wpcp_overlay_visibility'] : '';
$light_box = isset( $shortcode_data['_image_light_box'] ) ? $shortcode_data['_image_light_box'] : false;
$image_link_show = isset( $shortcode_data['wpcp_click_action_type_group']['wpcp_logo_link_show'] ) ? $shortcode_data['wpcp_click_action_type_group']['wpcp_logo_link_show'] : 'l_box';
if ( ( 'product-carousel' === $carousel_type && $light_box ) || 'video-carousel' === $carousel_type || ( 'image-carousel' === $carousel_type && 'l_box' === $image_link_show ) ) {
if ( wpcp_get_option( 'wpcp_fancybox_js', true ) ) {
wp_enqueue_script( 'wpcp-fancybox-popup' );
wp_enqueue_script( 'wpcp-fancybox-config' );
}
}
wp_enqueue_script( 'wpcp-jGallery' );
// Carousel Classes.
$carousel_classes .= ' wpcp-carousel-section sp-wpcp-' . $post_id;
if ( 'image-carousel' === $carousel_type ) {
$carousel_classes .= ' wpcp-image-carousel';
} elseif ( 'video-carousel' === $carousel_type ) {
$carousel_classes .= ' wpcp-video-carousel';
} elseif ( 'post-carousel' === $carousel_type ) {
$carousel_classes .= ' wpcp-post-carousel';
} elseif ( 'content-carousel' === $carousel_type ) {
$carousel_classes .= ' wpcp-content-carousel';
} elseif ( 'product-carousel' === $carousel_type ) {
$carousel_classes .= ' wpcp-product-carousel';
}
// Content Style.
if ( 'video-carousel' !== $carousel_type && 'with_overlay' === $wpcp_content_style ) { // Check if the Content Style is set to 'Overlay'.
$carousel_classes .= ' detail-with-overlay';
switch ( $wpcp_overlay_position ) {
case 'left':
$carousel_classes .= ' overlay-on-left';
break;
case 'right':
$carousel_classes .= ' overlay-on-right';
break;
}
} elseif ( 'video-carousel' !== $carousel_type && 'caption_full' === $wpcp_content_style ) { // Check if the Content Style is set to 'Caption Full'.
$carousel_classes .= ' detail-with-overlay overlay-lower';
switch ( $wpcp_caption_full ) {
case 'center':
$carousel_classes .= ' overlay-on-middle';
break;
case 'top':
$carousel_classes .= ' overlay-on-top';
break;
}
} elseif ( 'video-carousel' !== $carousel_type && 'caption_partial' === $wpcp_content_style ) { // Check if the Content Style is set to 'Caption Partial'.
$carousel_classes .= ' detail-with-overlay caption-on-bottom-left';
switch ( $wpcp_caption_partial ) {
case 'top_left':
$carousel_classes .= ' caption-on-top-left';
break;
case 'bottom_right':
$carousel_classes .= ' caption-on-bottom-right';
break;
case 'top_right':
$carousel_classes .= ' caption-on-top-right';
break;
}
} elseif ( 'video-carousel' !== $carousel_type && 'content_diagonal' === $wpcp_content_style ) { // Check if the Content Style is set to 'Diagonal'.
$carousel_classes .= ' detail-with-overlay overlay-curved';
switch ( $wpcp_caption_diagonal ) {
case 'top_left':
$carousel_classes .= ' diagonal-on-top-left';
break;
case 'bottom_right':
$carousel_classes .= ' diagonal-on-bottom-right';
break;
case 'top_right':
$carousel_classes .= ' diagonal-on-top-right';
break;
}
} elseif ( 'video-carousel' !== $carousel_type && 'content_box' === $wpcp_content_style ) { // Check if the Content Style is set to 'Diagonal'.
$carousel_classes .= ' detail-with-overlay content-box';
switch ( $wpcp_content_box ) {
case 'bottom':
$carousel_classes .= ' box-on-bottom';
break;
case 'top':
$carousel_classes .= ' box-on-top';
break;
case 'left':
$carousel_classes .= ' box-on-left';
break;
case 'right':
$carousel_classes .= ' box-on-right';
break;
case 'center':
$carousel_classes .= ' box-on-center';
break;
}
} elseif ( 'video-carousel' !== $carousel_type && 'moving' === $wpcp_content_style ) {
$carousel_classes .= ' detail-with-overlay caption-on-bottom-left caption-on-moving';
}
// Check if the Overlay Visibility is set to 'On Hover'.
if ( 'video-carousel' !== $carousel_type && 'on_hover' === $wpcp_overlay_visibility ) {
$carousel_classes .= ' overlay-on-hover';
}
// Check if the Content Style is set to 'default'.
if ( 'default' === $wpcp_content_style ) {
switch ( $wpcp_post_detail ) {
case 'on_right':
$carousel_classes .= ' detail-on-right';
break;
case 'on_left':
$carousel_classes .= ' detail-on-left';
break;
case 'top':
$carousel_classes .= ' detail-on-top';
break;
default:
$carousel_classes .= ' detail-on-bottom';
break;
}
$item_same_height = isset( $shortcode_data['item_same_height'] ) ? $shortcode_data['item_same_height'] : false;
// If same height is enabled in default content style, then add class 'wpcp_same_height' for same height of each item.
if ( $item_same_height ) {
$carousel_classes .= ' wpcp_same_height';
}
}
// Overlay content animation.
$wpcp_overlay_animation = isset( $shortcode_data['wpcp_overlay_animation'] ) ? $shortcode_data['wpcp_overlay_animation'] : 'none';
$animation_class = '';
if ( 'none' !== $wpcp_overlay_animation && wpcp_get_option( 'wpcp_enqueue_animation_css', true ) ) {
wp_enqueue_style( 'wpcp-animate' );
}
$img_protection = isset( $shortcode_data['wpcp_img_protection'] ) && ( 'image-carousel' === $carousel_type ) ? $shortcode_data['wpcp_img_protection'] : false;
if ( $img_protection ) {
$carousel_classes .= ' wpcp_img_protection';
}
$masonry_class = '';
// Masonry class.
if ( 'masonry' === $wpcp_layout ) {
$masonry_class = 'wpcp-masonry';
wp_enqueue_script( 'imagesloaded' );
wp_enqueue_script( 'masonry' );
}
// Preloader classes.
if ( $preloader ) {
wp_enqueue_script( 'wpcp-preloader' );
$carousel_classes .= ' wpcp-preloader';
}
// Lightbox meta options.
$show_lightbox_image_counter = isset( $shortcode_data['wpcp_image_counter'] ) ? $shortcode_data['wpcp_image_counter'] : true;
$l_box_thumb_visibility = isset( $shortcode_data['l_box_thumb_visibility'] ) ? $shortcode_data['l_box_thumb_visibility'] : true;
$l_box_protect_image = isset( $shortcode_data['l_box_protect_image'] ) ? $shortcode_data['l_box_protect_image'] : false;
$l_box_keyboard_nav = isset( $shortcode_data['l_box_keyboard_nav'] ) ? $shortcode_data['l_box_keyboard_nav'] : true;
$l_box_loop = isset( $shortcode_data['l_box_loop'] ) ? $shortcode_data['l_box_loop'] : true;
$l_box_hover_img_on_mobile = isset( $shortcode_data['l_box_hover_img_on_mobile'] ) ? $shortcode_data['l_box_hover_img_on_mobile'] : false;
$l_box_autoplay = isset( $shortcode_data['l_box_autoplay'] ) ? $shortcode_data['l_box_autoplay'] : false;
$l_box_outside_close = isset( $shortcode_data['l_box_outside_close'] ) && $shortcode_data['l_box_outside_close'] ? 'true' : 'false';
$l_box_autoplay_speed = ! empty( $shortcode_data['l_box_autoplay_speed'] ) && is_numeric( $shortcode_data['l_box_autoplay_speed'] ) ? $shortcode_data['l_box_autoplay_speed'] : 4000;
$l_box_sliding_effect = isset( $shortcode_data['l_box_sliding_effect'] ) ? $shortcode_data['l_box_sliding_effect'] : 'fade';
$l_box_open_close_effect = isset( $shortcode_data['l_box_open_close_effect'] ) ? $shortcode_data['l_box_open_close_effect'] : 'fade';
$l_box_zoom_button = isset( $shortcode_data['l_box_zoom_button'] ) ? $shortcode_data['l_box_zoom_button'] : 'zoom';
$l_box_icon_position = isset( $shortcode_data['l_box_icon_position'] ) ? $shortcode_data['l_box_icon_position'] : 'middle';
$justified_row_height = isset( $shortcode_data['rowHeight']['all'] ) ? $shortcode_data['rowHeight']['all'] : '250';
$l_box_zoom_button = $l_box_zoom_button ? 'zoom' : '';
$l_box_thumb_visibility = $l_box_thumb_visibility ? 'true' : 'false';
$show_l_box_img_sharper_on_retina = isset( $shortcode_data['l_box_img_sharper_on_retina'] ) ? $shortcode_data['l_box_img_sharper_on_retina'] : false;
$lightbox_data = 'data-infobar="' . $show_lightbox_image_counter . '" data-thumbs="' . $l_box_thumb_visibility . '" data-protect_image="' . $l_box_protect_image . '" data-autoplay="' . $l_box_autoplay . '" data-loop="' . $l_box_loop . '" data-speed="' . $l_box_autoplay_speed . '" data-sliding_effect="' . $l_box_sliding_effect . '" data-open_close="' . $l_box_open_close_effect . '" data-outside="' . $l_box_outside_close . '" data-keyboard="' . $l_box_keyboard_nav . '" data-l_box_img_sharpe="' . $show_l_box_img_sharper_on_retina . '"';
$lightbox_setting = ( 'l_box' === $image_link_show ) ? $lightbox_data : '';
wp_enqueue_script( 'wpcp-carousel-config' );
$lazy_load_image = isset( $shortcode_data['wpcp_image_lazy_load'] ) ? $shortcode_data['wpcp_image_lazy_load'] : 'false';
$lazy_load_image = ( '1' === $lazy_load_image || 'ondemand' === $lazy_load_image ) ? 'ondemand' : 'false';
if ( ! self::is_carousel( $wpcp_layout ) && 'false' !== $lazy_load_image ) {
wp_enqueue_script( 'wpcp-carousel-lazy-load' );
}
$post_per_page = isset( $shortcode_data['post_per_page'] ) ? (int) $shortcode_data['post_per_page'] : 15;
$post_pagination_type = isset( $shortcode_data['wpcp_post_pagination_type'] ) ? $shortcode_data['wpcp_post_pagination_type'] : '';
$post_query = self::wpcp_query( $upload_data, $shortcode_data, $post_id );
$total_page = $post_query->max_num_pages;
$posts_found = $post_query->found_posts;
// Total page calculated, Total page effected after added post per click option on load more.
if ( 'normal' !== $post_pagination_type && 'ajax_number' !== $post_pagination_type && $total_page > 1 ) {
$per_click = isset( $shortcode_data['post_per_click'] ) ? (int) $shortcode_data['post_per_click'] : 10;
$per_click = $per_click > 0 ? $per_click : $post_per_page;
$after_offset_post = $posts_found > $post_per_page ? $posts_found - $post_per_page : 0;
$total_page = ceil( ( $after_offset_post / $per_click ) + 1 );
}
// Check if the carousel type is 'video-carousel' and caching is applicable (not in preview mode).
$is_source_video_type = ( 'video-carousel' === $carousel_type && ! $is_preview ) ? true : false;
$wpcp_paged = 'paged' . $post_id;
$wpcp_paged_id = isset( $_GET[ "$wpcp_paged" ] ) ? sanitize_text_field( wp_unslash( $_GET[ "$wpcp_paged" ] ) ) : 1;
$cache_key = 'sp_wpcp_layout' . $wpcp_paged_id . $post_id . WPCAROUSEL_VERSION;
$cache_data = self::wpcp_get_transient( $cache_key, $is_source_video_type );
if ( false !== $cache_data ) {
$html = $cache_data;
} elseif ( 'carousel' === $wpcp_layout || 'slider' === $wpcp_layout ) {
ob_start();
include self::wpcp_locate_template( 'carousel.php' );
$html = ob_get_clean();
$html = self::minify_output( $html );
self::wpcp_set_transient( $cache_key, $html, $is_source_video_type );
} elseif ( 'tiles' === $wpcp_layout ) {
ob_start();
include self::wpcp_locate_template( 'tiles.php' );
$html = ob_get_clean();
$html = self::minify_output( $html );
self::wpcp_set_transient( $cache_key, $html, $is_source_video_type );
} elseif ( 'justified' === $wpcp_layout ) {
ob_start();
include self::wpcp_locate_template( 'justified.php' );
$html = ob_get_clean();
$html = self::minify_output( $html );
self::wpcp_set_transient( $cache_key, $html, $is_source_video_type );
} elseif ( 'thumbnails-slider' === $wpcp_layout ) {
ob_start();
include self::wpcp_locate_template( 'thumbnails-slider.php' );
$html = ob_get_clean();
$html = self::minify_output( $html );
self::wpcp_set_transient( $cache_key, $html, $is_source_video_type );
} elseif ( 'masonry' === $wpcp_layout ) {
ob_start();
include self::wpcp_locate_template( 'masonry.php' );
$html = ob_get_clean();
$html = self::minify_output( $html );
self::wpcp_set_transient( $cache_key, $html, $is_source_video_type );
} else {
ob_start();
include self::wpcp_locate_template( 'grid.php' );
$html = ob_get_clean();
$html = self::minify_output( $html );
self::wpcp_set_transient( $cache_key, $html, $is_source_video_type );
}
return $html;
}
/**
* Ajax load more data
*
* @param int $post_id post id.
* @param int $wpcppage page number.
* @param array $upload_data upload option.
* @param array $shortcode_data setting options.
* @param boolean $thumbnail_slider show/hide options.
* @return void
*/
public static function wpcp_ajax_more_data( $post_id, $wpcppage, $upload_data, $shortcode_data, $thumbnail_slider = false ) {
include WPCAROUSEL_PATH . 'Frontend/partials/generator-options.php';
$post_per_page = isset( $shortcode_data['post_per_page'] ) ? (int) $shortcode_data['post_per_page'] : 10;
$wpcp_pagination_type = isset( $shortcode_data['wpcp_pagination_type'] ) ? $shortcode_data['wpcp_pagination_type'] : '';
$item_per_click = $post_per_page;
if ( 'ajax_number' !== $wpcp_pagination_type ) {
$item_per_click = isset( $shortcode_data['item_per_click'] ) ? (int) $shortcode_data['item_per_click'] : $post_per_page;
}
// Content.
if ( 'content-carousel' === $carousel_type ) {
$content_sources = isset( $upload_data['carousel_content_source'] ) ? $upload_data['carousel_content_source'] : array();
if ( empty( $content_sources ) ) {
return;
}
if ( 'rand' === $image_orderby ) {
$cash_content_data = get_transient( $post_id . 'sp_wpcp_content_data' );
if ( $cash_content_data ) {
$content_sources = $cash_content_data;
} else {
shuffle( $content_sources );
set_transient( $post_id . 'sp_wpcp_content_data', $content_sources, 10 );
}
}
if ( ! empty( $post_per_page ) && count( $content_sources ) > $post_per_page ) {
$start_post = $post_per_page + ( ( $wpcppage - 1 ) * $item_per_click );
$content_sources = array_slice( $content_sources, $start_post, $item_per_click );
}
include WPCAROUSEL_PATH . 'Frontend/partials/content_sources.php';
}
// Image.
if ( 'image-carousel' === $carousel_type ) {
$gallery_ids = $upload_data['wpcp_gallery'];
$is_image_link_nofollow = isset( $shortcode_data['wpcp_click_action_type_group']['wpcp_logo_link_nofollow'] ) ? $shortcode_data['wpcp_click_action_type_group']['wpcp_logo_link_nofollow'] : '';
$wpcp_watermark = isset( $shortcode_data['wpcp_watermark'] ) ? $shortcode_data['wpcp_watermark'] : false;
$image_link_nofollow = $is_image_link_nofollow ? ' rel=' . esc_attr( 'nofollow' ) . '' : '';
if ( empty( $gallery_ids ) ) {
return;
}
$attachments = explode( ',', $gallery_ids );
if ( 'rand' === $image_orderby ) {
if ( ! empty( $post_per_page ) && count( $attachments ) > $post_per_page ) {
$cached_data = get_transient( $post_id . 'sp_wpcp_attachments_data' );
if ( $cached_data ) {
$attachments = json_decode( $cached_data );
} else {
shuffle( $attachments );
set_transient( $post_id . 'sp_wpcp_attachments_data', json_encode( $attachments ), 10 );
}
} else {
shuffle( $attachments );
}
}
if ( ! empty( $post_per_page ) && count( $attachments ) > $post_per_page ) {
$start_post = $post_per_page + ( ( $wpcppage - 1 ) * $item_per_click );
$attachments = array_unique( $attachments );
$attachments = array_slice( $attachments, $start_post, $item_per_click );
$attachments = array_unique( $attachments );
}
include WPCAROUSEL_PATH . 'Frontend/partials/image_sources.php';
}
// Audio.
if ( 'audio-carousel' === $carousel_type ) {
$audio_sources = ! empty( $upload_data['carousel_audio_source'] ) ? $upload_data['carousel_audio_source'] : array();
if ( empty( $audio_sources ) ) {
return;
}
if ( 'rand' === $image_orderby ) {
$cash_audio_data = get_transient( $post_id . 'sp_wpcp_audio_data' );
if ( $cash_audio_data ) {
$audio_sources = $cash_audio_data;
} else {
shuffle( $audio_sources );
set_transient( $post_id . 'sp_wpcp_audio_data', $audio_sources, 10 );
}
}
if ( ! empty( $post_per_page ) && count( $audio_sources ) > $post_per_page ) {
$start_post = $post_per_page + ( ( $wpcppage - 1 ) * $item_per_click );
$audio_sources = array_slice( $audio_sources, $start_post, $item_per_click );
}
include WPCAROUSEL_PATH . 'Frontend/partials/audio_sources.php';
}
// Video.
if ( 'video-carousel' === $carousel_type ) {
$video_sources = $upload_data['carousel_video_source'];
if ( empty( $video_sources ) ) {
return;
}
$video_play_mode = isset( $shortcode_data['video_play_mode'] ) ? $shortcode_data['video_play_mode'] : 'lightbox';
$lightbox_data = 'data-thumbs="true" data-outside="1" data-loop=1 data-keyboard=1';
$sp_urls = self::get_video_thumb_url( $video_sources );
if ( 'rand' === $image_orderby ) {
$cash_video_data = get_transient( $post_id . 'sp_wpcp_video_data' );
if ( $cash_video_data ) {
$sp_urls = $cash_video_data;
} else {
shuffle( $sp_urls );
set_transient( $post_id . 'sp_wpcp_video_data', $sp_urls, 10 );
}
}
if ( ! empty( $post_per_page ) && count( $sp_urls ) > $post_per_page ) {
$start_post = $post_per_page + ( ( $wpcppage - 1 ) * $item_per_click );
$sp_urls = array_slice( $sp_urls, $start_post, $item_per_click );
}
include WPCAROUSEL_PATH . 'Frontend/partials/video_sources.php';
}
// Mix content.
if ( 'mix-content' === $carousel_type ) {
$mix_sources = isset( $upload_data['carousel_mix_source'] ) ? $upload_data['carousel_mix_source'] : '';
$video_play_mode = isset( $shortcode_data['video_play_mode'] ) ? $shortcode_data['video_play_mode'] : 'lightbox';
$lightbox_data = 'data-thumbs="true" data-outside="1" data-loop=1 data-keyboard=1';
if ( ! empty( $post_per_page ) && count( $mix_sources ) > $post_per_page ) {
$start_post = $post_per_page + ( ( $wpcppage - 1 ) * $item_per_click );
$mix_sources = array_slice( $mix_sources, $start_post, $item_per_click );
}
include WPCAROUSEL_PATH . 'Frontend/partials/mix_content_sources.php';
}
// External.
if ( 'external-carousel' === $carousel_type ) {
$show_total_content = isset( $upload_data['wpcp_external_limit'] ) && ! empty( $upload_data['wpcp_external_limit'] ) ? $upload_data['wpcp_external_limit'] : '10';
$wpcp_feed_content_show = isset( $shortcode_data['wpcp_feed_content_show'] ) ? $shortcode_data['wpcp_feed_content_show'] : true;
$show_feed_title = isset( $shortcode_data['wpcp_feed_title'] ) ? $shortcode_data['wpcp_feed_title'] : true;
$wpcp_feed_content_chars_limit = isset( $shortcode_data['wpcp_feed_content_chars_limit'] ) ? $shortcode_data['wpcp_feed_content_chars_limit'] : '';
$show_feed_read_more = isset( $shortcode_data['wpcp_feed_readmore_button_show'] ) ? $shortcode_data['wpcp_feed_readmore_button_show'] : true;
$wpcp_feed_readmore_text = isset( $shortcode_data['wpcp_feed_readmore_text'] ) ? $shortcode_data['wpcp_feed_readmore_text'] : 'Read More';
$is_image_link_nofollow = isset( $shortcode_data['wpcp_click_action_type_group']['wpcp_logo_link_nofollow'] ) ? $shortcode_data['wpcp_click_action_type_group']['wpcp_logo_link_nofollow'] : '';
$image_link_nofollow = $is_image_link_nofollow ? ' rel=' . esc_attr( 'nofollow' ) . '' : '';
$rss_items = self::rss_feeds( $upload_data, $show_total_content );
if ( ! is_wp_error( $rss_items ) ) { // Checks that the object is created.
if ( ! empty( $post_per_page ) && count( $rss_items ) > $post_per_page ) {
$start_post = $post_per_page + ( ( $wpcppage - 1 ) * $item_per_click );
$rss_items = array_slice( $rss_items, $start_post, $item_per_click );
}
foreach ( $rss_items as $item ) :
$title = $item->get_title();
$link = $item->get_permalink();
$description = $item->get_content();
$description = strip_tags( $description );
if ( ! empty( $wpcp_feed_content_chars_limit ) ) {
$description = wp_html_excerpt( $description, $wpcp_feed_content_chars_limit ) . ' ...';
}
$thumb_src = '';
if ( $enclosure = $item->get_enclosure() ) {
$thumb_src = $enclosure->get_thumbnail();
}
$pub_date = $item->get_date( 'j F Y | g:i a' );
$category = $item->get_category();
include self::wpcp_locate_template( 'loop/external-type/feeds.php' );
endforeach;
}
}
}
/**
* Fetch highest resolution thumb from YouTube .YouTube available thumb size - maxresdefault, sddefault, mqdefault, hqdefault, and default.
*
* @param string $wpcp_video_id YouTube video id.
* @return mixed
*/
public static function fetch_highest_res( $wpcp_video_id ) {
$resolutions = array( 'hqdefault', 'maxresdefault', 'mqdefault', 'sddefault', 'default' );
$http = is_ssl() ? 'https:' : 'http:';
$thumb_resolution = apply_filters( 'wpcp_youtube_thumb_resolution', true );
if ( $thumb_resolution ) {
foreach ( $resolutions as $res ) {
$resolution = apply_filters( 'wp_carousel_youtube_thumb_size', $res );
$thumb_url = "$http//img.youtube.com/vi_webp/$wpcp_video_id/$resolution.webp";
if ( ! empty( $wpcp_video_id ) && ! empty( $thumb_url ) && @getimagesize( $thumb_url ) ) {
return $thumb_url;
}
}
}
$default_resolution = apply_filters( 'wp_carousel_youtube_default_thumb_size', 'hqdefault' );
return "$http//img.youtube.com/vi/$wpcp_video_id/$default_resolution.jpg";
}
/**
* Get video URL and Thumbnail.
*
* @param array $_video_sources video sources.
* @return array
*/
public static function get_video_thumb_url( array $_video_sources ) {
$vid_url = array();
foreach ( $_video_sources as $_video_source ) {
$video_type = isset( $_video_source['carousel_video_source_type'] ) ? $_video_source['carousel_video_source_type'] : 'youtube';
$wpcp_video_id = $_video_source['carousel_video_source_id'];
$wpcp_video_desc = $_video_source['carousel_video_description'];
$carousel_wistia_id = isset( $_video_source['carousel_wistia_url'] ) && ! empty( $_video_source['carousel_wistia_url'] ) ? $_video_source['carousel_wistia_url'] : '';
$wpcp_video_thumb_url = '';
$wpcp_img_click_action = '';
$wpcp_video_url = '';
$video_thumb_alt_text = '';
switch ( $video_type ) {
case 'youtube':
$video_thumb_alt_text = 'youtube-video-thumbnail';
$wpcp_video_url = 'https://www.youtube.com/watch?v=' . $wpcp_video_id;
$wpcp_video_thumb_url = self::fetch_highest_res( $wpcp_video_id );
break;
case 'twitch':
// Get the server name and sanitize.
$wpcp_host = ! empty( $_SERVER['SERVER_NAME'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ) : '';
// Set default twitch id type.
$twitch_id_type = isset( $_video_source['twitch_id_type'] ) ? $_video_source['twitch_id_type'] : 'video';
// Get the relevant Twitch ID.
$video_twitch_id = isset( $_video_source['carousel_video_twitch_id'] ) ? $_video_source['carousel_video_twitch_id'] : '';
$video_channel_id = isset( $_video_source['carousel_video_channel_id'] ) ? $_video_source['carousel_video_channel_id'] : '';
// Construct the Twitch video URL based on the ID type.
if ( 'channel' === $twitch_id_type && $video_channel_id ) {
$wpcp_video_url = 'https://player.twitch.tv/?channel=' . $video_channel_id . '&parent=' . $wpcp_host;
} else {
$wpcp_video_url = 'https://player.twitch.tv/?video=' . $video_twitch_id . '&parent=' . $wpcp_host;
}
$video_thumb_alt_text = 'twitch-video-thumbnail';
$wpcp_video_thumb_url = ! empty( $_video_source['carousel_video_source_thumb']['url'] ) ? $_video_source['carousel_video_source_thumb']['url'] : '';
break;
case 'tiktok':
$wpcp_video_url = 'https://www.tiktok.com/embed/v3/' . $wpcp_video_id . '?autoplay=1';
$video_thumb_alt_text = 'tiktok-video-thumbnail';
$wpcp_video_thumb_url = ! empty( $_video_source['carousel_video_source_thumb']['url'] ) ? $_video_source['carousel_video_source_thumb']['url'] : '';
break;
case 'wistia':
$video_thumb_alt_text = 'wistia-video-thumbnail';
$wpcp_video_url = "https://fast.wistia.net/embed/iframe/$carousel_wistia_id?autoplay=1";
$wpcp_video_thumb_url = isset( $_video_source['carousel_video_source_thumb']['url'] ) && ! empty( $_video_source['carousel_video_source_thumb']['url'] ) ? $_video_source['carousel_video_source_thumb']['url'] : '';
if ( empty( $wpcp_video_thumb_url ) && ! empty( $carousel_wistia_id ) ) {
$wistia_video_width = apply_filters( 'wp_carousel_pro_wistia_thumb_width', '960' );
$wistia_embed_data = wp_remote_get( "https://fast.wistia.net/oembed?url=https://home.wistia.com/medias/$carousel_wistia_id?embedType=async&videoWidth=$wistia_video_width" );
$wistia_data = json_decode( wp_remote_retrieve_body( $wistia_embed_data ), true );
$wpcp_video_thumb_url = isset( $wistia_data['thumbnail_url'] ) ? $wistia_data['thumbnail_url'] : '';
}
break;
case 'vimeo':
$wpcp_video_data = self::get_vimeo_video_data( $wpcp_video_id );
// Access the video URL and thumbnail URL.
$wpcp_video_url = $wpcp_video_data['video_url'];
$wpcp_video_thumb_url = $wpcp_video_data['thumb_url'];
$video_thumb_alt_text = $wpcp_video_data['thumb_alt'];
break;
case 'dailymotion':
$video_thumb_alt_text = 'dailymotion-video-thumbnail';
$wpcp_video_url = 'https://www.dailymotion.com/video/' . $wpcp_video_id;
$wpcp_video_thumb_url = 'https://dailymotion.com/thumbnail/video/' . $wpcp_video_id;
break;
case 'self_hosted':
$wpcp_video_url = $_video_source['carousel_video_source_upload'];
$wpcp_video_thumb_url = $_video_source['carousel_video_source_thumb'];
$video_thumb_alt_text = $wpcp_video_thumb_url['alt'];
break;
default:
$wpcp_video_thumb_url = 'https://via.placeholder.com/650x450';
}
$vid_url[] = array(
'video_type' => $video_type,
'img_click_action' => $wpcp_img_click_action,
'video_id' => $wpcp_video_id,
'video_url' => $wpcp_video_url,
'video_thumb_url' => $wpcp_video_thumb_url,
'video_thumb_alt' => $video_thumb_alt_text,
'video_desc' => $wpcp_video_desc,
);
} // End foreach.
return $vid_url;
}
/**
* Get video URL and Thumbnail.
*
* @param mixed $video_type video types.
* @param mixed $wpcp_video_id video ids.
* @param mixed $wpcp_video_desc descriptions.
* @param array $video_source_thumb thumbnail sources.
* @param array $video_source_upload uploaded sources.
* @param mixed $twitch_video_url twitch video url.
* @return statement
*/
public static function get_mix_video_thumb_url( $video_type, $wpcp_video_id, $wpcp_video_desc = '', $video_source_thumb = '', $video_source_upload = '', $twitch_video_url = '' ) {
$vid_url = array();
$wpcp_video_thumb_url = '';
$wpcp_img_click_action = '';
$wpcp_video_url = '';
$video_thumb_alt_text = '';
switch ( $video_type ) {
case 'youtube':
$wpcp_video_url = 'https://www.youtube.com/watch?v=' . $wpcp_video_id;
$wpcp_video_thumb_url = self::fetch_highest_res( $wpcp_video_id );
$video_thumb_alt_text = 'youtube-video-thumbnail';
break;
case 'vimeo':
$wpcp_video_data = self::get_vimeo_video_data( $wpcp_video_id );
// Access the video URL and thumbnail URL.
$wpcp_video_url = $wpcp_video_data['video_url'];
$wpcp_video_thumb_url = $wpcp_video_data['thumb_url'];
$video_thumb_alt_text = $wpcp_video_data['thumb_alt'];
break;
case 'twitch':
$wpcp_video_thumb_url = $video_source_thumb['url'];
$video_thumb_alt_text = 'twitch-video-thumbnail';
$wpcp_video_url = $twitch_video_url;
break;
case 'tiktok':
$wpcp_video_url = 'https://www.tiktok.com/embed/v3/' . $wpcp_video_id . '?autoplay=1';
$video_thumb_alt_text = 'tiktok-video-thumbnail';
$wpcp_video_thumb_url = $video_source_thumb['url'];
break;
case 'wistia':
$video_thumb_alt_text = 'wistia-video-thumbnail';
$wpcp_video_url = "https://fast.wistia.net/embed/iframe/$wpcp_video_id?autoplay=1";
$wpcp_video_thumb_url = $video_source_thumb['url'];
if ( empty( $wpcp_video_thumb_url ) && ! empty( $wpcp_video_id ) ) {
$wistia_video_width = apply_filters( 'wp_carousel_pro_wistia_thumb_width', '960' );
$wistia_embed_data = wp_remote_get( "https://fast.wistia.net/oembed?url=https://home.wistia.com/medias/$wpcp_video_id?embedType=async&videoWidth=$wistia_video_width" );
$wistia_data = json_decode( wp_remote_retrieve_body( $wistia_embed_data ), true );
$wpcp_video_thumb_url = isset( $wistia_data['thumbnail_url'] ) ? $wistia_data['thumbnail_url'] : '';
}
break;
case 'dailymotion':
$wpcp_video_url = 'https://www.dailymotion.com/video/' . $wpcp_video_id;
$wpcp_video_thumb_url = 'https://dailymotion.com/thumbnail/video/' . $wpcp_video_id;
$video_thumb_alt_text = 'dailymotion-video-thumbnail';
break;
case 'self_hosted':
$wpcp_video_url = $video_source_upload;
$wpcp_video_thumb_url = $video_source_thumb['url'];
$video_thumb_alt_text = 'self-video-thumbnail';
break;
default:
$wpcp_video_thumb_url = 'https://via.placeholder.com/650x450';
}
$vid_url = array(
'video_type' => $video_type,
'img_click_action' => $wpcp_img_click_action,
'video_id' => $wpcp_video_id,
'video_url' => $wpcp_video_url,
'video_thumb_url' => $wpcp_video_thumb_url,
'video_desc' => $wpcp_video_desc,
'video_alt_text' => $video_thumb_alt_text,
);
return $vid_url;
}
/**
* Retrieve Vimeo video data, including video private and public URL.
*
* @param string $video_id Vimeo video ID, which may include '/' for private videos.
* @return array Contains 'video_url' (string), 'thumb_url' (string), and 'thumb_alt' (string).
*/
public static function get_vimeo_video_data( $video_id ) {
$video_data = array(
'video_url' => '',
'thumb_url' => 'https://via.placeholder.com/650x450',
'thumb_alt' => 'vimeo-video-thumbnail',
);
if ( ! $video_id ) {
return $video_data;
}
// Determine if it's a private video (contains '/').
$is_private = strpos( $video_id, '/' ) !== false;
// Construct the correct Vimeo API URL based on video type.
$api_url = $is_private
? "https://vimeo.com/api/oembed.json?url=https://vimeo.com/$video_id"
: "https://vimeo.com/api/v2/video/$video_id.json";
// Fetch the data from Vimeo API.
$response = wp_remote_get( $api_url );
if ( is_wp_error( $response ) ) {
return $video_data; // Return empty data on error.
}
// Retrieve and decode the body content.
$response_body = json_decode( wp_remote_retrieve_body( $response ), true );
// Extract thumbnail URL based on video type.
if ( $is_private ) {
$video_data['thumb_url'] = $response_body['thumbnail_url'] ?? null;
// Adjust thumbnail quality if available.
if ( $video_data['thumb_url'] && strpos( $video_data['thumb_url'], 'd_200x150' ) !== false ) {
$thumb_high_res = str_replace( 'd_200x150', 'd_640', $video_data['thumb_url'] );
$video_data['thumb_url'] = @getimagesize( $thumb_high_res ) ? $thumb_high_res : $video_data['thumb_url'];
}
// Modify the video ID for private video parameters.
$video_id = str_replace( '/', '?h=', $video_id ) . '&autoplay=1&muted=1';
} else {
$video_data['thumb_url'] = $response_body[0]['thumbnail_large'] ?? null;
// Append autoplay and muted parameters for public videos to make the video autoplay.
$video_id .= '?autoplay=1&muted=1';
}
// Construct the final video URL.
$video_data['video_url'] = 'https://vimeo.com/' . $video_id;
return $video_data;
}
}
}