cipher87

class-avia-slideshow.php

Jun 30th, 2023 (edited)
1,013
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 45.40 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Helper for slideshows
  4.  *
  5.  * @since ???
  6.  * @since 4.8.9     extended to support post css files
  7.  */
  8. if( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  9.  
  10.  
  11. if( ! class_exists( 'avia_slideshow', false ) )
  12. {
  13.     class avia_slideshow extends \aviaBuilder\base\aviaSubItemQueryBase
  14.     {
  15.         use \aviaBuilder\traits\scSlideshowUIControls;
  16.  
  17.         /**
  18.          *
  19.          * @var int
  20.          */
  21.         static protected $slider = 0;               //slider count for the current page
  22.  
  23.         /**
  24.          * attachment posts for the current slider
  25.          *
  26.          * @var array
  27.          */
  28.         protected $slides;
  29.  
  30.         /**
  31.          *
  32.          * @since 4.8.9
  33.          * @var array
  34.          */
  35.         protected $subslides;
  36.  
  37.         /**
  38.          * number of slides
  39.          *
  40.          * @var int
  41.          */
  42.         protected $slide_count;
  43.  
  44.         /**
  45.          *
  46.          * @var array
  47.          */
  48.         protected $id_array;
  49.  
  50.         /**
  51.          *
  52.          * @var boolean
  53.          */
  54.         protected $need_conditional_load;
  55.  
  56.         /**
  57.          *
  58.          * @since 4.8.9                     added $sc_context
  59.          * @param array $atts
  60.          * @param aviaShortcodeTemplate $sc_context
  61.          */
  62.         public function __construct( $atts = array(), aviaShortcodeTemplate $sc_context = null )
  63.         {
  64.             parent::__construct( $atts, $sc_context, avia_slideshow::default_args() );
  65.  
  66.             $this->slides = array();
  67.             $this->subslides = array();
  68.             $this->slide_count = 0;
  69.             $this->id_array = array();
  70.             $this->need_conditional_load = false;
  71.  
  72.             /**
  73.              *
  74.              * @param array $this->config
  75.              * @return array
  76.              */
  77.             $this->config = apply_filters( 'avf_slideshow_config', $this->config );
  78.  
  79.             /**
  80.              * Use this filter additionally
  81.              *
  82.              * @since 4.8.2
  83.              * @param string $image_size
  84.              * @param string $context
  85.              * @param array $atts
  86.              * @param string $content
  87.              * @return string
  88.              */
  89.             $this->config['lightbox_size'] = apply_filters( 'avf_alb_lightbox_image_size', $this->config['lightbox_size'], 'avia_slideshow', $this->config, '' );
  90.  
  91.             $this->get_height();
  92.  
  93.             //if we got subslides overwrite the id array
  94.             if( ! empty( $this->config['content'] ) )
  95.             {
  96.                 $this->extract_subslides( $this->config['content'] );
  97.             }
  98.  
  99.             $this->set_slides( $this->config['ids'] );
  100.         }
  101.  
  102.         /**
  103.          * @since 4.4
  104.          */
  105.         public function __destruct()
  106.         {
  107.             unset( $this->slides );
  108.             unset( $this->subslides );
  109.             unset( $this->id_array );
  110.  
  111.             parent::__destruct();
  112.         }
  113.  
  114.         /**
  115.          * Returns the defaults array.
  116.          *
  117.          * ATTENTION: Backwards compatibilty different behaviour !!!
  118.          * ==========
  119.          *
  120.          * Allows shortcodes using this class to get the default values used before,
  121.          * merge them into shortcode generated defaults
  122.          *
  123.          * @since 4.8
  124.          * @param array
  125.          * @return array
  126.          */
  127.         static public function default_args( array $sc_defaults = array() )
  128.         {
  129.             $default = array(
  130.                         'size'                  => 'featured',
  131.                         'lightbox_size'         => 'large',
  132.                         'control_layout'        => '',
  133.                         'slider_navigation'     => 'av-navigate-arrows av-navigate-dots',
  134.                         'nav_arrow_color'       => '',
  135.                         'nav_arrow_bg_color'    => '',
  136.                         'nav_dots_color'        => '',
  137.                         'nav_dot_active_color'  => '',
  138.                         'animation'             => 'slide',
  139.                         'transition_speed'      => '',              //  in ms - empty for default
  140.                         'autoplay'              => 'false',
  141.                         'interval'              => 5,
  142.                         'autoplay_stopper'      => '',
  143.                         'manual_stopper'        => '',
  144.                         'bg_slider'             => 'false',
  145.                         'keep_padding'          => false,           //  needed in js $.AviaSlider
  146.                         'conditional_play'      => '',
  147.                         'ids'                   => '',
  148.                         'video_counter'         => 0,
  149.                         'slide_height'          => '',
  150.                         'handle'                => '',
  151.                         'class'                 => '',
  152.                         'extra_class'           => '',              // additional container class that can be added before call to html()
  153.                         'el_id'                 => '',
  154.                         'css_id'                => '',
  155.                         'scroll_down'           => '',
  156.                         'content'               => array(),
  157.                         'custom_markup'         => '',
  158.                         'perma_caption'         => '',
  159.                         'image_attachment'      => '',
  160.                         'min_height'            => '0px',
  161.                         'lazy_loading'          => 'disabled',
  162.                         'default-height'        => '',
  163.                         'img_scale'             => '',              //  scale effect for images
  164.                         'img_scale_duration'    => 3,
  165.                         'img_scale_opacity'     => 1,
  166.                         'img_copyright'         => '',
  167.                         'img_copyright_color'   => '',
  168.                         'img_copyright_bg'      => ''
  169.                 );
  170.  
  171.             /**
  172.              * Override the defaults from shortcode options for backwards comp.
  173.              */
  174.             $default = array_merge( $sc_defaults, $default );
  175.  
  176.             /**
  177.              * @since 4.8.9
  178.              * @param array $default
  179.              * @return array
  180.              */
  181.             return apply_filters( 'avf_avia_slideshow_defaults', $default );
  182.         }
  183.  
  184.         /**
  185.          * Returns the argument array for a subslide
  186.          *
  187.          * Returns the
  188.          * @since 4.8.9
  189.          * @param int $key
  190.          * @return array
  191.          */
  192.         public function args_item_advanced( $key )
  193.         {
  194.             $default = array(
  195.                             'content'               => $this->subslides[ $key ]['content'],
  196.                             'title'                 => '',
  197.                             'link_apply'            => '',
  198.                             //  direct link from image
  199.                             'link'                  => '',
  200.                             'link_target'           => '',
  201.                             //  button link 1
  202.                             'button_label'          => '',
  203.                             'button_color'          => 'light',
  204.                             'link1'                 => '',
  205.                             'link_target1'          => '',
  206.                             //  button link 2
  207.                             'button_label2'         => '',
  208.                             'button_color2'         => 'light',
  209.                             'link2'                 => '',
  210.                             'link_target2'          => '',
  211.  
  212.                             'position'              => 'center center',
  213.                             'caption_pos'           => 'capt-bottom capt-left',
  214.                             'video_cover'           => '',
  215.                             'video_controls'        => '',
  216.                             'video_mute'            => '',
  217.                             'video_loop'            => '',
  218.                             'video_format'          => '',
  219.                             'video_autoplay'        => '',
  220.                             'video_ratio'           => '16:9',
  221.                             'video_mobile_disabled' => '',
  222.                             'video_mobile'          => 'mobile-fallback-image',
  223.                             'mobile_image'          => '',
  224.                             'fallback_link'         => '',
  225.                             'slide_type'            =>'',
  226.                             'custom_markup'         => '',
  227.                             'custom_title_size'     => '',
  228.                             'custom_content_size'   => '',
  229.                             'font_color'            => '',
  230.                             'custom_title'          => '',
  231.                             'custom_content'        => '',
  232.                             'overlay_enable'        => '',
  233.                             'overlay_opacity'       => '',
  234.                             'overlay_color'         => '',
  235.                             'overlay_pattern'       => '',
  236.                             'overlay_custom_pattern'    => '',
  237.                             'preload'               => $this->need_conditional_load ? 'none' : ''
  238.                         );
  239.  
  240.             $default = array_merge( $default, $this->subslides[ $key ]['attr'] );
  241.  
  242.             /**
  243.              * @since 4.8.9
  244.              * @param array $default
  245.              * @return array
  246.              */
  247.             return apply_filters( 'avf_avia_slideshow_item_advanced_defaults', $default );
  248.         }
  249.  
  250.         /**
  251.          * Create custom stylings
  252.          *
  253.          * Attention: Due to paging we cannot add any backgrouund images to selectors !!!!
  254.          * =========
  255.          *
  256.          * @since 4.8.9
  257.          * @param array $result
  258.          * @return array
  259.          */
  260.         public function get_element_styles( array $result )
  261.         {
  262.             extract( $result );
  263.  
  264.             $element_styling->create_callback_styles( $this->config );
  265.  
  266.             $classes = array(
  267.                             'avia-slideshow',
  268.                             $element_id,
  269.                             'avia-slideshow-' . $this->config['size'],
  270.                             $this->config['handle'],
  271.                             "avia-{$this->config['animation']}-slider",
  272.                         );
  273.  
  274.             $element_styling->add_classes( 'container', $classes );
  275.             $element_styling->add_classes( 'container', $this->config['class'] );
  276.  
  277.             $element_styling->add_responsive_classes( 'container', 'hide_element', $this->config );
  278.  
  279.             $ui_args = array(
  280.                         'element_id'        => $element_id,
  281.                         'element_styling'   => $element_styling,
  282.                         'atts'              => $this->config,
  283.                         'autoplay_option'   => 'true',
  284.                         'context'           => __CLASS__,
  285.                     );
  286.  
  287.             $this->addSlideshowAttributes( $ui_args );
  288.  
  289.             if( ! empty( $this->config['scroll_down'] ) )
  290.             {
  291.                 $element_styling->add_classes( 'container', 'av-slider-scroll-down-active' );
  292.             }
  293.  
  294.             if( ! empty( $this->config['conditional_play'] ) && $this->need_conditional_load )
  295.             {
  296.                 $element_styling->add_classes( 'ul-inner', 'av-show-video-on-click' );
  297.             }
  298.  
  299.             if( $this->config['img_scale'] != '' )
  300.             {
  301.                 $element_styling->add_callback_styles( 'image', array( 'img_scale' ) );
  302.  
  303.                 if( '' == $this->config['img_scale_direction'] )
  304.                 {
  305.                     $element_styling->add_callback_styles( 'image_active', array( 'img_scale_active' ) );
  306.                 }
  307.                 else
  308.                 {
  309.                     $element_styling->add_callback_styles( 'image_active_odd', array( 'img_scale_active' ) );
  310.                     $element_styling->add_callback_styles( 'image_active_even', array( 'img_scale_active_even' ) );
  311.                 }
  312.             }
  313.  
  314.             if( ! empty( $this->config['img_copyright'] ) )
  315.             {
  316.                 if( ! empty( $this->config['img_copyright_color'] ) )
  317.                 {
  318.                     $element_styling->add_styles( 'copyright', array( 'color' => $this->config['img_copyright_color'] ) );
  319.                 }
  320.  
  321.                 if( ! empty( $this->config['img_copyright_bg'] ) )
  322.                 {
  323.                     $element_styling->add_styles( 'copyright', array( 'background-color' => $this->config['img_copyright_bg'] ) );
  324.                 }
  325.  
  326.                 $element_styling->add_responsive_font_sizes( 'copyright', 'img_copyright_font', $this->config, $this->sc_context );
  327.             }
  328.  
  329.  
  330.             $selectors = array(
  331.                         'container'         => ".avia-slideshow.{$element_id}",
  332.                         'ul-inner'          => ".avia-slideshow.{$element_id} .avia-slideshow-inner",
  333.                         'image'             => ".avia-slideshow.{$element_id} .avia-slideshow-slide img",
  334.                         'image_active'      => ".avia-slideshow.{$element_id} .avia-slideshow-slide.next-active-slide img",
  335.                         'image_odd'         => ".avia-slideshow.{$element_id} .avia-slideshow-slide.slide-odd img",
  336.                         'image_active_odd'  => ".avia-slideshow.{$element_id} .avia-slideshow-slide.slide-odd.next-active-slide img",
  337.                         'image_even'        => ".avia-slideshow.{$element_id} .avia-slideshow-slide.slide-even img",
  338.                         'image_active_even' => ".avia-slideshow.{$element_id} .avia-slideshow-slide.slide-even.next-active-slide img",
  339.                         'copyright'         => ".avia-slideshow.{$element_id} .av-image-copyright"
  340.                     );
  341.  
  342.             $element_styling->add_selectors( $selectors );
  343.  
  344.             foreach( $this->id_array as $key => $id )
  345.             {
  346.                 $result_item = array();
  347.                 $result_item['key'] = $key;
  348.                 $result_item['content'] = isset( $this->slides[ $id ] ) ? $this->slides[ $id ] : array();
  349.                 $result_item['element_id'] = $element_id . '__' . $key;
  350.                 $result_item['element_styling'] = new aviaElementStyling( $this->sc_context, $result_item['element_id'] );
  351.  
  352.                 if( empty( $this->subslides ) )
  353.                 {
  354.                     $result_item = $this->get_element_styles_item_default( $result_item );
  355.                 }
  356.                 else
  357.                 {
  358.                     $result_item = $this->get_element_styles_item_advanced( $result_item );
  359.                 }
  360.  
  361.                 $element_styling->add_subitem_styling( $result_item['element_id'], $result_item['element_styling'] );
  362.             }
  363.  
  364.             //  save data for later HTML output
  365.             $this->element_id = $element_id;
  366.             $this->element_styles = $element_styling;
  367.  
  368.             $result['element_styling'] = $element_styling;
  369.  
  370.             return $result;
  371.         }
  372.  
  373.         /**
  374.          * Create custom item stylings
  375.          * Items are called in object of main shortcode attributes
  376.          *
  377.          * @since 4.8.9
  378.          * @param array $result
  379.          * @return array
  380.          */
  381.         protected function get_element_styles_item_default( array $result )
  382.         {
  383.             $result = $this->sc_context->get_element_styles_query_item( $result );
  384.  
  385.             extract( $result );
  386.  
  387.             $classes = array(
  388.                             'avia-slideshow-slide',
  389.                             $element_id
  390.                         );
  391.  
  392.             $element_styling->add_classes( 'container', $classes );
  393.  
  394.             $selectors = array(
  395.                         'container'         => ".avia-slideshow .avia-slideshow-slide.{$element_id}"
  396.                     );
  397.  
  398.             $element_styling->add_selectors( $selectors );
  399.  
  400.             $result['element_styling'] = $element_styling;
  401.  
  402.             return $result;
  403.         }
  404.  
  405.         /**
  406.          * Create custom item stylings
  407.          * Items are called in object of main shortcode attributes
  408.          *
  409.          * @since 4.8.9
  410.          * @param array $result
  411.          * @return array
  412.          */
  413.         protected function get_element_styles_item_advanced( array $result )
  414.         {
  415.             $result = $this->sc_context->get_element_styles_query_item( $result );
  416.  
  417.             extract( $result );
  418.  
  419.             $atts = $this->args_item_advanced( $key );
  420.  
  421.             //  backwards comp.
  422.             $atts['size-title'] = $atts['custom_title_size'];
  423.  
  424.             if( isset( $atts['custom_content_size'] ) )
  425.             {
  426.                 $atts['size'] = $atts['custom_content_size'];
  427.             }
  428.             else
  429.             {
  430.                 $atts['size'] = $atts['custom_size'];
  431.             }
  432.  
  433.             $classes = array(
  434.                             'avia-slideshow-slide',
  435.                             $element_id
  436.                         );
  437.  
  438.             $element_styling->add_classes( 'container', $classes );
  439.  
  440.             $classes = array(
  441.                             'av-slideshow-caption',
  442.                             $element_id
  443.                         );
  444.  
  445.             $element_styling->add_classes( 'caption', $classes );
  446.  
  447.             $important = '';
  448. //  removed 4.8.9.1 - kept if we encounter problems (removed !important from media query in slideshow_fullsize.css for font sizes
  449. //          $obj_class = get_class( $this->sc_context );
  450. //          if( in_array( $obj_class, array( 'avia_sc_slider_fullscreen', 'avia_sc_slider_full' ) ) )
  451. //          {
  452. //              $important = '!important';
  453. //          }
  454.  
  455.             $element_styling->add_responsive_font_sizes( 'title', 'size-title', $atts, $this->sc_context, $important );
  456.             $element_styling->add_responsive_font_sizes( 'content', 'size', $atts, $this->sc_context, $important );
  457.             $element_styling->add_responsive_font_sizes( 'content-p', 'size', $atts, $this->sc_context, $important );
  458.  
  459.             if( 'custom' == $atts['font_color'] )
  460.             {
  461.                 $element_styling->add_styles( 'title', array( 'color' => $atts['custom_title'] ) );
  462.                 $element_styling->add_styles( 'content', array( 'color' => $atts['custom_content'] ) );
  463.                 $element_styling->add_classes( 'content', 'av_inherit_color' );
  464.             }
  465.  
  466.  
  467.             $selectors = array(
  468.                         'container'     => ".avia-slideshow .avia-slideshow-slide.{$element_id}",
  469.                         'caption'       => ".avia-slideshow .av-slideshow-caption.{$element_id}",
  470.                         'title'         => "#top #wrap_all .avia-slideshow .av-slideshow-caption.{$element_id} .avia-caption-title",
  471.                         'content'       => "#top .avia-slideshow .av-slideshow-caption.{$element_id} .avia-caption-content",
  472.                         'content-p'     => "#top .avia-slideshow .av-slideshow-caption.{$element_id} .avia-caption-content p"
  473.                     );
  474.  
  475.             $element_styling->add_selectors( $selectors );
  476.  
  477.             $result['element_styling'] = $element_styling;
  478.  
  479.             return $result;
  480.         }
  481.  
  482.         /**
  483.          * Check how large the slider is and change the classname accordingly
  484.          *
  485.          * @since 4.8.9
  486.          * @return void
  487.          */
  488.         protected function get_height()
  489.         {
  490.             global $_wp_additional_image_sizes;
  491.  
  492.             $width = 1500;
  493.  
  494.             if( isset( $_wp_additional_image_sizes[ $this->config['size'] ]['width'] ) )
  495.             {
  496.                 $width = $_wp_additional_image_sizes[ $this->config['size'] ]['width'];
  497.                 $height = $_wp_additional_image_sizes[ $this->config['size'] ]['height'];
  498.  
  499.                 /**
  500.                  * Avoid notices in case user manipulated image settings to 0
  501.                  */
  502.                 $height = is_numeric( $height ) && $height > 0 ? $height : get_option( 'medium_size_h', 300 );
  503.                 $width = is_numeric( $width ) && $width > 0 ? $width : get_option( 'medium_size_w', $height );
  504.  
  505.                 $this->config['default-height'] = ( 100 / $width ) * $height;
  506.             }
  507.             else if( get_option( $this->config['size'] . '_size_w' ) )
  508.             {
  509.                 $width = get_option( $this->config['size'] . '_size_w' );
  510.             }
  511.  
  512.             if( $width < 600 )
  513.             {
  514.                 $this->config['class'] .= ' avia-small-width-slider';
  515.             }
  516.  
  517.             if( $width < 305 )
  518.             {
  519.                 $this->config['class'] .= ' avia-super-small-width-slider';
  520.             }
  521.         }
  522.  
  523.         /**
  524.          *
  525.          * @param string $ids
  526.          * @return void
  527.          */
  528.         protected function set_slides( $ids )
  529.         {
  530.             $ids = trim( $ids );
  531.  
  532.             if( empty( $ids ) && empty( $this->config['video_counter'] ) )
  533.             {
  534.                 return;
  535.             }
  536.  
  537.             /**
  538.              * video slides have no id and return empty string - avoid an unnecessary db query if only video slides
  539.              */
  540.             $post_ids = explode( ',', $ids );
  541.             $post_ids = array_unique( $post_ids );
  542.             if( ( 1 == count( $post_ids ) ) && empty( $post_ids[0] ) )
  543.             {
  544.                 $post_ids = '';
  545.             }
  546.             else
  547.             {
  548.                 $post_ids = implode( ',', $post_ids );
  549.             }
  550.  
  551.             if( ! empty( $post_ids ) )
  552.             {
  553.                 $this->slides = get_posts( array(
  554.                                     'include'       => $ids,
  555.                                     'post_status'   => 'inherit',
  556.                                     'post_type'     => 'attachment',
  557.                                     'post_mime_type' => 'image',
  558.                                     'order'         => 'ASC',
  559.                                     'orderby'       => 'post__in'
  560.                                 )
  561.                             );
  562.             }
  563.             else
  564.             {
  565.                 $this->slides = array();
  566.             }
  567.  
  568.             //resort slides so the id of each slide matches the post id
  569.             $new_slides = array();
  570.             foreach( $this->slides as $slide )
  571.             {
  572.                 $new_slides[ $slide->ID ] = $slide;
  573.             }
  574.  
  575.             $slideshow_data = array();
  576.             $slideshow_data['slides'] = $new_slides;
  577.             $slideshow_data['id_array'] = explode( ',', $this->config['ids'] );
  578.             $slideshow_data['slide_count'] = count( array_filter( $slideshow_data['id_array'] ) ) + $this->config['video_counter'];
  579.  
  580.             /**
  581.              * @used_by             config-wpml\config.php              10
  582.              * @since 4.4.2
  583.              */
  584.             $slideshow_data = apply_filters( 'avf_avia_builder_slideshow_filter', $slideshow_data, $this );
  585.  
  586.             $this->slides = $slideshow_data['slides'];
  587.             $this->id_array = $slideshow_data['id_array'];
  588.             $this->slide_count = $slideshow_data['slide_count'];
  589.         }
  590.  
  591.         /**
  592.          *
  593.          * @deprecated since 4.8.9
  594.          * @param string $size
  595.          */
  596.         public function set_size( $size )
  597.         {
  598.             _deprecated_function( 'avia_slideshow::set_size', '4.8.9', 'not uses - no replacement. Set in constructor.' );
  599.  
  600.             $this->config['size'] = $size;
  601.         }
  602.  
  603.         /**
  604.          * Add a class that is added to container on html()
  605.          *
  606.          * @since 4.8.9                 modified to 'extra_class'
  607.          * @param string $class
  608.          */
  609.         public function set_extra_class( $class )
  610.         {
  611.             $this->config['extra_class'] .= ' ' . $class;
  612.         }
  613.  
  614.         /**
  615.          * Create the HTML output
  616.          *
  617.          * @return string
  618.          */
  619.         public function html()
  620.         {
  621.             avia_slideshow::$slider++;
  622.  
  623.             if( $this->slide_count == 0 )
  624.             {
  625.                 return '';
  626.             }
  627.  
  628.             $scroll_down_html = '';
  629.             if( ! empty( $this->config['scroll_down'] ) )
  630.             {
  631.                 $scroll_down_html .= "<a href='#next-section' title='' class='scroll-down-link " . $this->config['control_layout'] . "' " . av_icon_string( 'scrolldown' ) . "></a>";
  632.             }
  633.  
  634.             $slide_html = empty( $this->subslides ) ? $this->html_default_slide() : $this->html_advanced_slide();
  635.  
  636.             //  must be set here because changed in html_advanced_slide()
  637.             $style = '';
  638.             if( ! empty( $this->config['default-height'] ) )
  639.             {
  640.                 $style = "style='padding-bottom: {$this->config['default-height']}%;'";
  641.                 $this->element_styles->add_classes( 'container', 'av-default-height-applied' );
  642.             }
  643.  
  644.             $this->element_styles->add_classes( 'container', $this->config['extra_class'] );
  645.  
  646.  
  647.             $markup = avia_markup_helper( array( 'context' => 'image', 'echo' => false, 'custom_markup' => $this->config['custom_markup'] ) );
  648.  
  649.             $style_tag = $this->element_styles->get_style_tag( $this->element_id );
  650.             $container_class = $this->element_styles->get_class_string( 'container' );
  651.             $inner_class = $this->element_styles->get_class_string( 'ul-inner' );
  652.             $data_slideshow_options = $this->element_styles->get_data_attributes_json_string( 'container', 'slideshow-options' );
  653.  
  654.             $output  = '';
  655.             $output .= $style_tag;
  656.             $output .= $scroll_down_html;
  657.             $output .= "<div {$this->config['el_id']} class='{$container_class} avia-slideshow-" . avia_slideshow::$slider . "' {$data_slideshow_options} {$markup}>";
  658.  
  659.             $output .=      "<ul class='avia-slideshow-inner {$inner_class}' {$style}>";
  660.             $output .=          $slide_html;
  661.             $output .=      '</ul>';
  662.  
  663.             if( $this->slide_count > 1 )
  664.             {
  665.                 $output .= $this->slide_navigation_arrows();
  666.  
  667.                 if( 'av-control-hidden' != $this->config['control_layout'] && false !== strpos( $this->config['slider_navigation'], 'av-navigate-dots' )  )
  668.                 {
  669.                     $output .= $this->slide_navigation_dots();
  670.                 }
  671.             }
  672.  
  673.             if( ! empty( $this->config['caption_override'] ) )
  674.             {
  675.                 $output .= $this->config['caption_override'];
  676.             }
  677.  
  678.             $output .= '</div>';
  679.  
  680.             return $output;
  681.         }
  682.  
  683.         /**
  684.          * renders the usual slides. use when we didn't use sub-shorcodes to define the images but ids
  685.          *
  686.          * @return string
  687.          */
  688.         protected function html_default_slide()
  689.         {
  690.             $html = '';
  691.             $counter = 0;
  692.  
  693.             $copyright_class = ! empty( $this->config['img_copyright'] ) ? 'av-copyright-' . $this->config['img_copyright'] : '';
  694.             $markup_url = avia_markup_helper( array( 'context' => 'image_url', 'echo' => false, 'custom_markup' => $this->config['custom_markup'] ) );
  695.  
  696.             foreach( $this->id_array as $key => $id )
  697.             {
  698.                 if( isset( $this->slides[ $id ] ) )
  699.                 {
  700.                     $slide = $this->slides[ $id ];
  701.  
  702.                     $counter ++;
  703.                     $img = wp_get_attachment_image_src( $slide->ID, $this->config['size'] );
  704.  
  705.                     $copy_html = '';
  706.                     if( ! empty( $copyright_class ) )
  707.                     {
  708.                         $copyright_text = get_post_meta( $slide->ID, '_avia_attachment_copyright', true );
  709.  
  710.                         if( ! empty( $copyright_text ) )
  711.                         {
  712.                             $copy_html .= "<div class='av-image-copyright {$copyright_class}'>";
  713.                             $copy_html .=       "<span>{$copyright_text}</span>";
  714.                             $copy_html .= '</div>';
  715.                         }
  716.                     }
  717.  
  718.                     $lightbox_img_src = Av_Responsive_Images()->responsive_image_src( $slide->ID, $this->config['lightbox_size'] );
  719.  
  720.                     $caption = trim( $slide->post_excerpt ) ? '<div class="avia-caption capt-bottom capt-left"><div class="avia-inner-caption">' . wptexturize( $slide->post_excerpt ) . "</div></div>": '';
  721.  
  722.                     $imgalt = get_post_meta( $slide->ID, '_wp_attachment_image_alt', true );
  723.                     $imgalt = ! empty( $imgalt ) ? esc_attr( $imgalt ) : '';
  724.                     $imgtitle = trim( $slide->post_title ) ? esc_attr( $slide->post_title ) : '';
  725.                     if( $imgtitle == '-' )
  726.                     {
  727.                         $imgtitle = '';
  728.                     }
  729.                     $imgdescription = trim( $slide->post_content ) ? esc_attr( $slide->post_content ) : '';
  730.  
  731.                     $lightbox_attr = Av_Responsive_Images()->html_attr_image_src( $lightbox_img_src, false );
  732.  
  733.                     /**
  734.                      * can be filtered and for example be replaced by array('div','div')
  735.                      *
  736.                      * @param array $tags
  737.                      * @return array
  738.                      */
  739.                     $tags = apply_filters( 'avf_slideshow_link_tags', array( "a {$lightbox_attr} title='{$imgdescription}'", 'a' ) );
  740.  
  741.                     $img_tag = "<img src='{$img[0]}' width='{$img[1]}' height='{$img[2]}' title='{$imgtitle}' alt='{$imgalt}' {$markup_url} />";
  742.                     $img_tag = Av_Responsive_Images()->make_image_responsive( $img_tag, $slide->ID, $this->config['lazy_loading'] );
  743.  
  744.                     //  add item container data
  745.                     $item_info = $this->element_styles->get_subitem_styling_info( $key );
  746.                     $container_class = $item_info['element_styling']->get_class_string( 'container' );
  747.                     $odd = $counter % 2 ? 'slide-odd' : 'slide-even';
  748.  
  749.                     $html .= "<li class='{$container_class} slide-{$counter} slide-id-{$slide->ID} {$odd}'>";
  750.                     $html .=    "<{$tags[0]}>{$caption}{$img_tag}</{$tags[1]}>";
  751.                     $html .=    $copy_html;
  752.                     $html .= '</li>';
  753.                 }
  754.                 else
  755.                 {
  756.                     $this->slide_count --;
  757.                 }
  758.             }
  759.  
  760.             return $html;
  761.         }
  762.  
  763.         /**
  764.          * Renders the slides. use when we did use sub-shortcodes to define the images
  765.          *
  766.          * @return string
  767.          */
  768.         protected function html_advanced_slide()
  769.         {
  770.             $html = '';
  771.             $counter = 0;
  772. //          $this->ie8_fallback = '';
  773.  
  774.             $copyright_class = ! empty( $this->config['img_copyright'] ) ? 'av-copyright-' . $this->config['img_copyright'] : '';
  775.  
  776.             foreach( $this->id_array as $key => $id )
  777.             {
  778.                 $dev_tags = aviaShortcodeTemplate::set_frontend_developer_heading_tag( $this->subslides[ $key ]['attr'] );
  779.  
  780.                 $meta = $this->args_item_advanced( $key );
  781.  
  782.                 //  Autoplay videos must be muted to work on several browsers (e.g. FF, Chrome)
  783.                 if( empty( $meta['video_autoplay'] ) )
  784.                 {
  785.                     $meta['video_mute'] = 'aviaTBaviaTBvideo_mute';
  786.                 }
  787.  
  788.                 extract( $meta );
  789.  
  790.                 if( isset( $this->slides[ $id ] ) || 'video' == $slide_type )
  791.                 {
  792.                     $img = array( '' );
  793.                     $slide = '';
  794.                     $attachment_id = isset( $this->slides[ $id ] ) ? $id : false;
  795.                     $link = $slide_type == 'video' ? AviaHelper::get_url( $link, $attachment_id ) : AviaHelper::get_url( $link, $attachment_id, true );
  796.                     $extra_class = '';
  797.                     $linkdescription = '';
  798.                     $linkalt = '';
  799.                     $copy_html  = '';
  800.                     $this->service = false;
  801.                     $slider_data = '';
  802.                     $stretch_height = false;
  803.                     $final_ratio = '';
  804.                     $viewport = 16/9;
  805.  
  806.                     $fallback_img_style = '';
  807.                     $fallback_img_class = '';
  808.  
  809.                     $markup_video = '';
  810.                     $markup_url = avia_markup_helper( array( 'context' => 'image_url', 'echo' => false, 'id' => $attachment_id, 'custom_markup' => $custom_markup ) );
  811.  
  812.                     if( $slide_type == 'video' )
  813.                     {
  814.                         $this->service = avia_slideshow_video_helper::which_video_service( $video );
  815.                         $video = avia_slideshow_video_helper::set_video_slide( $video, $this->service, $meta, $this->config, $markup_video );
  816.                         $video_class  = ! empty( $video_controls ) ? ' av-hide-video-controls' : '';
  817.                         $video_class .= ! empty( $video_mute ) ? ' av-mute-video' : '';
  818.                         $video_class .= ! empty( $video_loop ) ? ' av-loop-video' : '';
  819.                         $video_class .= ! empty( $video_mobile ) ? ' av-' . $video_mobile : '';
  820.  
  821.                         $extra_class .= " av-video-slide {$video_cover} av-video-service-{$this->service} {$video_class} ";
  822.                         $slider_data .= " data-controls='{$video_controls}' data-mute='{$video_mute}' data-loop='{$video_loop}' data-disable-autoplay='{$video_autoplay}' ";
  823.  
  824.                         if( $mobile_image )
  825.                         {
  826.                             $fallback_img = wp_get_attachment_image_src( $mobile_image, $this->config['size'] );
  827.  
  828.                             if( is_array( $fallback_img ) )
  829.                             {
  830.                                 $fallback_img_style = "style='background-image:url(\"{$fallback_img[0]}\");'";
  831.  
  832.                                 $slider_data .= " data-mobile-img='{$fallback_img[0]}'";
  833.  
  834.                                 if( $fallback_link )
  835.                                 {
  836.                                     $slider_data .= " data-fallback-link='" . esc_attr( $fallback_link ) . "'";
  837.                                 }
  838.                             }
  839.                         }
  840.  
  841.                         //if we dont use a fullscreen slider pass the video ratio to the slider
  842.                         if( $this->config['bg_slider'] != 'true' )
  843.                         {
  844.                             global $avia_config;
  845.  
  846.                             //if we use the small slideshow only allow the 'full' $video_format
  847.                             if( $this->config['handle'] == 'av_slideshow' )
  848.                             {
  849.                                 $video_format = 'full';
  850.                             }
  851.  
  852.                             //calculate the viewport ratio
  853.                             if( ! empty( $avia_config['imgSize'][ $this->config['size'] ] ) )
  854.                             {
  855.                                 $viewport = $avia_config['imgSize'][ $this->config['size'] ]['width'] / $avia_config['imgSize'][ $this->config['size'] ]['height'];
  856.                             }
  857.  
  858.  
  859.                             //calculate the ratio when passed as a string (eg: 16:9, 4:3). fallback is 16:9
  860.                             $video_ratio = explode( ':', trim( $video_ratio ) );
  861.                             if( empty( $video_ratio[0] ) )
  862.                             {
  863.                                 $video_ratio[0] = 16;
  864.                             }
  865.                             if( empty( $video_ratio[1] ) )
  866.                             {
  867.                                 $video_ratio[1] = 9;
  868.                             }
  869.  
  870.                             $final_ratio = ( (int) $video_ratio[0] / (int) $video_ratio[1] );
  871.  
  872.                             switch( $video_format )
  873.                             {
  874.                                 case '':
  875.                                     $final_ratio = $viewport;
  876.                                 break;
  877.                                 case 'stretch':
  878.                                     $final_ratio     = $viewport;
  879.                                     $stretch_height  = ceil( $viewport / ( $video_ratio[0] / $video_ratio[1] ) * 100 );
  880.                                     $stretch_pos     = ( ( $stretch_height - 100 ) / 2 ) * -1;
  881.                                     $slider_data    .= " data-video-height='{$stretch_height}'";
  882.                                     $slider_data    .= " data-video-toppos='{$stretch_pos}'";
  883.                                     $extra_class    .= ' av-video-stretch';
  884.                                 break;
  885.                                 case 'full':
  886.                                     // do nothing and apply the entered ratio
  887.                                 break;
  888.                             }
  889.  
  890.                             $slider_data .= " data-video-ratio='{$final_ratio}'";
  891.                         }
  892.  
  893.                     }
  894.                     else //img slide
  895.                     {
  896.                         $slide = $this->slides[ $id ];
  897.                         $linktitle = trim( $slide->post_title ) ? esc_attr( $slide->post_title ) : '';
  898.                         if( $linktitle == '-' )
  899.                         {
  900.                             $linktitle = '';
  901.                         }
  902.  
  903.                         $linkdescription = ( trim( $slide->post_content ) && empty( $link ) ) ? "title='" . esc_attr( $slide->post_content ) . "'" : '';
  904.                         $linkalt = get_post_meta( $slide->ID, '_wp_attachment_image_alt', true );
  905.                         $linkalt = ! empty( $linkalt ) ? esc_attr( $linkalt ) : '';
  906.                         $img = wp_get_attachment_image_src( $slide->ID, $this->config['size'] );
  907.  
  908.                         if( ! empty( $copyright_class ) )
  909.                         {
  910.                             $copyright_text = get_post_meta( $slide->ID, '_avia_attachment_copyright', true );
  911.  
  912.                             if( ! empty( $copyright_text ) )
  913.                             {
  914.                                 $copy_html .= "<div class='av-image-copyright {$copyright_class}'>";
  915.                                 $copy_html .=       "<span>{$copyright_text}</span>";
  916.                                 $copy_html .= '</div>';
  917.                             }
  918.                         }
  919.  
  920.                         $video = '';
  921.                     }
  922.  
  923.                     if( $this->slide_count === 1 )
  924.                     {
  925.                         $extra_class .= ' av-single-slide';
  926.                     }
  927.  
  928.                     $blank = AviaHelper::get_link_target( $link_target );
  929.  
  930.                     $lightbox_attr = Av_Responsive_Images()->html_attr_image_src( $link, false );
  931.  
  932.                     $tags = ( ! empty( $link ) && $link_apply == 'image' ) ? array( "a {$lightbox_attr} {$blank}", 'a' ) : array( 'div', 'div' );
  933.                     $caption = '';
  934.                     $button_html = '';
  935.                     $counter ++;
  936.  
  937.                     $button_count = '';
  938.                     if( strpos( $link_apply, 'button-two' ) !== false )
  939.                     {
  940.                         $button_count = 'avia-multi-slideshow-button';
  941.                     }
  942.  
  943.                     $button_count = '';
  944.                     if( strpos( $link_apply, 'button-three' ) !== false )
  945.                     {
  946.                         $button_count = 'avia-multi-slideshow-button';
  947.                     }
  948.  
  949.                     //if we got a CTA button apply the link to the button instead of the slide
  950.                     if( strpos( $link_apply, 'button' ) !== false )
  951.                     {
  952.                         $button_html .= $this->slideshow_cta_button( $link1, $link_target1, $button_color, $button_label, $button_count );
  953.                         $tags = array( 'div', 'div' );
  954.                     }
  955.  
  956.                     if( strpos( $link_apply, 'button-two' ) !== false )
  957.                     {
  958.                         $button_count .= ' avia-slideshow-button-2';
  959.                         $button_html .= $this->slideshow_cta_button( $link2, $link_target2, $button_color2, $button_label2, $button_count );
  960.                     }
  961.  
  962.                     if( strpos( $link_apply, 'button-three' ) !== false )
  963.                     {
  964.                         $button_count .= ' avia-slideshow-button-3';
  965.                         $button_html .= $this->slideshow_cta_button( $link2, $link_target2, $button_color2, $button_label2, $button_count );
  966.                     }
  967.  
  968.                     //  add item container data
  969.                     $item_info = $this->element_styles->get_subitem_styling_info( $key );
  970.                     $container_class = $item_info['element_styling']->get_class_string( 'container' );
  971.                     $caption_class = $item_info['element_styling']->get_class_string( 'caption' );
  972.                     $content_class = $item_info['element_styling']->get_class_string( 'content' );
  973.  
  974.                     //check if we got a caption
  975.                     $markup_description = avia_markup_helper( array( 'context' => 'description', 'echo' => false, 'id' => $attachment_id, 'custom_markup' => $custom_markup ) );
  976.                     $markup_name = avia_markup_helper( array( 'context' => 'name', 'echo' => false, 'id' => $attachment_id, 'custom_markup' => $custom_markup ) );
  977.  
  978.                     if( trim( $title ) != '' )
  979.                     {
  980.                         $default_heading = ! empty( $dev_tags['heading_tag'] ) ? $dev_tags['heading_tag'] : 'h2';
  981.                         $args = array(
  982.                                     'heading'       => $default_heading,
  983.                                     'extra_class'   => $dev_tags['heading_class']
  984.                                 );
  985.  
  986.                         $extra_args = array( $this, $key );
  987.  
  988.                         /**
  989.                          * @since 4.5.5
  990.                          * @return array
  991.                          */
  992.                         $args = apply_filters( 'avf_customize_heading_settings', $args, __CLASS__, $extra_args );
  993.  
  994.                         $heading = ! empty( $args['heading'] ) ? $args['heading'] : $default_heading;
  995.                         $css = ! empty( $args['extra_class'] ) ? $args['extra_class'] : $dev_tags['heading_class'];
  996.  
  997.                         $title = "<{$heading} class='avia-caption-title {$css}' {$markup_name}>" . trim( apply_filters( 'avf_slideshow_title', $title ) ) . "</{$heading}>";
  998.                     }
  999.  
  1000.                     if( is_array( $content ) )
  1001.                     {
  1002.                         $content = implode( ' ', $content ); //temp fix for trim() expects string warning until I can actually reproduce the problem
  1003.                     }
  1004.  
  1005.                     if( trim( $content ) != '' )
  1006.                     {
  1007.                         $content    = "<div class='avia-caption-content {$content_class}' {$markup_description}>" . ShortcodeHelper::avia_apply_autop( ShortcodeHelper::avia_remove_autop( trim( $content ) ) ) . '</div>';
  1008.                     }
  1009.  
  1010.                     if( trim( $title . $content . $button_html ) != '' )
  1011.                     {
  1012.                         if( trim( $title ) != '' && trim( $button_html ) != '' && trim( $content ) == '' )
  1013.                         {
  1014.                             $content = '<br/>';
  1015.                         }
  1016.  
  1017.                         if( $this->config['handle'] == 'av_slideshow_full' || $this->config['handle'] == 'av_fullscreen' )
  1018.                         {
  1019.                             $caption .= "<div class='{$caption_class} caption_fullwidth {$caption_pos}'>";
  1020.                             $caption .=     '<div class="container caption_container">';
  1021.                             $caption .=             '<div class="slideshow_caption">';
  1022.                             $caption .=                 '<div class="slideshow_inner_caption">';
  1023.                             $caption .=                     '<div class="slideshow_align_caption">';
  1024.                             $caption .=                         $title;
  1025.                             $caption .=                         $content;
  1026.                             $caption .=                         $button_html;
  1027.                             $caption .=                     '</div>';
  1028.                             $caption .=                 '</div>';
  1029.                             $caption .=             '</div>';
  1030.                             $caption .=     '</div>';
  1031.                             $caption .= '</div>';
  1032.                         }
  1033.                         else
  1034.                         {
  1035.                             $caption  = "<div class='{$caption_class} avia-caption'>";
  1036.                             $caption .=     '<div class="avia-inner-caption">';
  1037.                             $caption .=         $title;
  1038.                             $caption .=         $content;
  1039.                             $caption .=     '</div>';
  1040.                             $caption .= '</div>';
  1041.  
  1042.                         }
  1043.                     }
  1044.  
  1045.                     if( ! empty( $this->config['perma_caption'] ) && empty( $this->config['caption_override'] ) )
  1046.                     {
  1047.                         $this->config['caption_override'] = $caption;
  1048.                     }
  1049.  
  1050.                     if( ! empty( $this->config['caption_override'] ) )
  1051.                     {
  1052.                         $caption = '';
  1053.                     }
  1054.  
  1055.                     if( ! empty( $img[0] ) )
  1056.                     {
  1057.                         $slider_data .= $this->config['bg_slider'] == 'true' ? "style='background-position:{$position};' data-img-url='{$img[0]}'" : '';
  1058.  
  1059. //                      if( $slider_data )
  1060. //                      {
  1061. //                          if( empty( $this->ie8_fallback ) )
  1062. //                          {
  1063. //                              $this->ie8_fallback .= "<!--[if lte IE 8]>";
  1064. //                              $this->ie8_fallback .= "<style type='text/css'>";
  1065. //                          }
  1066. //                          $this->ie8_fallback .= "\n #{$this->config['css_id']} .slide-{$counter}{";
  1067. //                          $this->ie8_fallback .= "\n -ms-filter: \"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='{$img[0]}', sizingMethod='scale')\"; ";
  1068. //                          $this->ie8_fallback .= "\n filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='{$img[0]}', sizingMethod='scale'); ";
  1069. //                          $this->ie8_fallback .= "\n } \n";
  1070. //                      }
  1071.                     }
  1072.  
  1073.                     // $img[0] = 'https://kriesi.at/themes/enfold-photography/files/2014/08/darkened_girl.jpg';
  1074.  
  1075.                     $odd = $counter % 2 ? 'slide-odd' : 'slide-even';
  1076.  
  1077.                     $html .= "<li {$slider_data} class='{$container_class} {$extra_class} slide-{$counter} {$odd}'>";
  1078.                     $html .=    "<{$tags[0]} data-rel='slideshow-" . avia_slideshow::$slider . "' class='avia-slide-wrap {$fallback_img_class}' {$fallback_img_style} {$linkdescription} {$markup_video}>{$caption}";
  1079.  
  1080.                     if( $this->config['bg_slider'] != 'true' && empty( $video ) )
  1081.                     {
  1082.                         $img_style = '';
  1083.                         if( ! empty( $this->config['min_height'] ) && $this->config['min_height'] != '0px' )
  1084.                         {
  1085.                             $percent = 100 / ( 100 / $img[2] * (int) $this->config['min_height'] );
  1086.                             $this->config['min_width'] = ceil( ( $img[1] / $percent ) ) . 'px';
  1087.  
  1088.                             $img_style .= AviaHelper::style_string( $this->config, 'min_height', 'min-height' );
  1089.                             $img_style .= AviaHelper::style_string( $this->config, 'min_width', 'min-width' );
  1090.                             $img_style  = AviaHelper::style_string( $img_style );
  1091.                         }
  1092.  
  1093.                         $img_tag = "<img src='{$img[0]}' width='{$img[1]}' height='{$img[2]}' title='{$linktitle}' alt='{$linkalt}' {$markup_url} {$img_style} />";
  1094.                         $img_tag = Av_Responsive_Images()->make_image_responsive( $img_tag, $slide->ID, $this->config['lazy_loading'] );
  1095.  
  1096.                         $html .= $img_tag;
  1097.                     }
  1098.  
  1099.                     $html .= $video;
  1100.                     $html .= $this->create_overlay( $meta );
  1101.                     $html .= $this->create_click_to_play_overlay();
  1102.  
  1103.                     $html .=    '</' . $tags[1]. '>';
  1104.  
  1105.                     $html .=    $copy_html;
  1106.  
  1107.                     $html .= '</li>';
  1108.  
  1109.                     if( $counter === 1 )
  1110.                     {
  1111.                         if( ! empty( $img[1] ) && ! empty( $img[2] ) )
  1112.                         {
  1113.                             $this->config['default-height'] = ( 100 / $img[1] ) * $img[2];
  1114.                         }
  1115.                     }
  1116.                 }
  1117.                 else
  1118.                 {
  1119.                     $this->slide_count --;
  1120.                 }
  1121.             }
  1122.  
  1123. //          if( ! empty( $this->ie8_fallback ) )
  1124. //          {
  1125. //              $this->ie8_fallback .= '</style> <![endif]-->';
  1126. //              add_action( 'wp_footer', array( $this, 'add_ie8_fallback_to_footer' ) );
  1127. //          }
  1128.  
  1129.             return $html;
  1130.         }
  1131.  
  1132. //      public function add_ie8_fallback_to_footer()
  1133. //      {
  1134. //          // echo $this->ie8_fallback;
  1135. //      }
  1136.  
  1137.         /**
  1138.          * Action button link (currently added to fullscreen slideshows, not linking to lightbox)
  1139.          *
  1140.          * @since ??????
  1141.          * @param string $link
  1142.          * @param string $link_target
  1143.          * @param string $button_color
  1144.          * @param string $button_label
  1145.          * @param string $button_count
  1146.          * @return string
  1147.          */
  1148.         protected function slideshow_cta_button( $link, $link_target, $button_color, $button_label, $button_count )
  1149.         {
  1150.             $button_html = '';
  1151.  
  1152.             $link = AviaHelper::get_url( $link );
  1153.             $blank = AviaHelper::get_link_target( $link_target );
  1154.  
  1155.             $button_html .= "<a href='{$link}' {$blank} class='avia-slideshow-button avia-button avia-color-{$button_color} {$button_count}' data-duration='800' data-easing='easeInOutQuad'>";
  1156.             $button_html .=     $button_label;
  1157.             $button_html .= '</a>';
  1158.  
  1159.             return $button_html;
  1160.         }
  1161.  
  1162.         /**
  1163.          * Create arrows to scroll slides
  1164.          *
  1165.          * @since 4.8.3         reroute to aviaFrontTemplates
  1166.          * @return string
  1167.          */
  1168.         protected function slide_navigation_arrows()
  1169.         {
  1170.             $args = array(
  1171.                         'context'   => get_class(),
  1172.                         'params'    => $this
  1173.                     );
  1174.  
  1175.             return aviaFrontTemplates::slide_navigation_arrows( $args );
  1176.         }
  1177.  
  1178.         /**
  1179.          * Create navigation dots
  1180.          *
  1181.          * @since 4.8.3         reroute to aviaFrontTemplates
  1182.          * @return string
  1183.          */
  1184.         protected function slide_navigation_dots()
  1185.         {
  1186.             $args = array(
  1187.                         'total_entries'     => $this->slide_count,
  1188.                         'container_entries' => 1,
  1189.                         'context'           => get_class(),
  1190.                         'params'            => $this
  1191.                     );
  1192.  
  1193.  
  1194.             return aviaFrontTemplates::slide_navigation_dots( $args );
  1195.         }
  1196.  
  1197.         /**
  1198.          *
  1199.          * @param array $slide_array
  1200.          */
  1201.         protected function extract_subslides( array $slide_array )
  1202.         {
  1203.             $this->config['ids'] = array();
  1204.             $this->subslides = array();
  1205.  
  1206.             foreach( $slide_array as $key => $slide )
  1207.             {
  1208.                 $this->subslides[ $key ] = $slide;
  1209.                 $this->config['ids'][] = $slide['attr']['id'];
  1210.  
  1211.                 if( empty( $slide['attr']['id'] ) && ! empty( $slide['attr']['video'] ) && $slide['attr']['slide_type'] === 'video' )
  1212.                 {
  1213.                     $this->config['video_counter'] ++ ;
  1214.  
  1215.                     if( avia_slideshow_video_helper::is_extern_service( $slide['attr']['video'] ) )
  1216.                     {
  1217.                         $this->need_conditional_load = true;
  1218.                     }
  1219.                     else
  1220.                     {
  1221.                         if( ! $this->need_conditional_load )
  1222.                         {
  1223.                             /**
  1224.                              * Allow to change default behaviour to lazy load all video files
  1225.                              *
  1226.                              * @since 4.4
  1227.                              */
  1228.                             $this->need_conditional_load = apply_filters( 'avf_video_slide_conditional_load_html5', true, $slide_array, $this );
  1229.                         }
  1230.                     }
  1231.                 }
  1232.             }
  1233.  
  1234.             $this->config['ids'] = implode( ',', $this->config['ids'] );
  1235.             unset( $this->config['content'] );
  1236.         }
  1237.  
  1238.         /**
  1239.          *
  1240.          * @param array $meta
  1241.          * @return string
  1242.          */
  1243.         protected function create_overlay( array $meta )
  1244.         {
  1245.             extract( $meta );
  1246.  
  1247.             /*check/create overlay*/
  1248.             $overlay = '';
  1249.  
  1250.             if( ! empty( $overlay_enable ) )
  1251.             {
  1252.                 $overlay_src = '';
  1253.                 $overlay = "opacity: {$overlay_opacity}; ";
  1254.                 if( ! empty( $overlay_color ) )
  1255.                 {
  1256.                     $overlay .= "background-color: {$overlay_color}; ";
  1257.                 }
  1258.  
  1259.                 if( ! empty( $overlay_pattern ) )
  1260.                 {
  1261.                     if( $overlay_pattern == 'custom' )
  1262.                     {
  1263.                         $overlay_src = $overlay_custom_pattern;
  1264.                     }
  1265.                     else
  1266.                     {
  1267.                         $overlay_src = str_replace('{{AVIA_BASE_URL}}', AVIA_BASE_URL, $overlay_pattern );
  1268.                     }
  1269.                 }
  1270.  
  1271.                 if( ! empty( $overlay_src ) )
  1272.                 {
  1273.                     $overlay .= "background-image: url({$overlay_src}); background-repeat: repeat;";
  1274.                 }
  1275.  
  1276.                 $overlay = "<div class='av-section-color-overlay' style='{$overlay}'></div>";
  1277.             }
  1278.  
  1279.             return $overlay;
  1280.         }
  1281.  
  1282.         /**
  1283.          * Returns an overlay div if we need late loading of videos
  1284.          *
  1285.          * @since 4.4
  1286.          * @return string
  1287.          */
  1288.         protected function create_click_to_play_overlay()
  1289.         {
  1290.             if( ! $this->need_conditional_load )
  1291.             {
  1292.                 return '';
  1293.             }
  1294.  
  1295.  
  1296.             $overlay =  '<div class="av-click-to-play-overlay">';
  1297.             $overlay .=     '<div class="avia_playpause_icon">';
  1298.             $overlay .=     '</div>';
  1299.             $overlay .= '</div>';
  1300.  
  1301.             return $overlay;
  1302.         }
  1303.  
  1304.     }
  1305. }
  1306.  
  1307.  
  1308. if( ! class_exists( 'avia_slideshow_video_helper', false ) )
  1309. {
  1310.     class avia_slideshow_video_helper
  1311.     {
  1312.  
  1313.         /**
  1314.          * Define extern services that need to be confirmed by user
  1315.          *
  1316.          * @var array
  1317.          */
  1318.         static protected $extern_services = array( 'youtube', 'vimeo' );
  1319.  
  1320.         /**
  1321.          *
  1322.          * @param string $video_url
  1323.          * @param string $service
  1324.          * @param array|false $meta
  1325.          * @param array|false $config
  1326.          * @param string $markup_video              added 4.8.7  returns markup if not set in HTML
  1327.          * @return string
  1328.          */
  1329.         static public function set_video_slide( $video_url, $service = false, $meta = false, $config = false, &$markup_video = '' )
  1330.         {
  1331.             $video = '';
  1332.             $origin_url = $video_url;
  1333.  
  1334.             if( empty( $service ) )
  1335.             {
  1336.                 $service = self::which_video_service( $video_url );
  1337.             }
  1338.  
  1339.             $uid = 'player_' . get_the_ID() . '_' . mt_rand() . '_' . mt_rand();
  1340.             $controls = empty( $meta['video_controls'] ) ? 1 : 0;
  1341.             $atts = array();
  1342.             $atts['loop'] = empty( $meta['video_loop'] ) ? 0 : 1;
  1343.             $atts['autoplay'] = empty( $meta['video_autoplay'] ) ? 1 : 0;
  1344.             $atts['muted'] = empty( $meta['video_mute'] ) ? 0 : 1;
  1345.             $atts['controls'] = $controls;
  1346.  
  1347.             //was previously only used for mobile,now for everything
  1348.             $fallback_img = ! empty( $meta['mobile_image'] ) ? $meta['mobile_image'] : '';
  1349.  
  1350.             if( is_numeric( $fallback_img ) )
  1351.             {
  1352.                 $fallback_size = isset( $config['size'] ) ? $config['size'] : 'thumbnail';
  1353.                 $fallback_img = wp_get_attachment_image_src( $fallback_img, $fallback_size );
  1354.                 $fallback_img = ( is_array( $fallback_img ) ) ? $fallback_img[0] : '';
  1355.             }
  1356.  
  1357.             $markup_video = avia_markup_helper( array( 'context' => 'video', 'echo' => false, 'custom_markup' => ( isset( $meta['custom_markup'] ) ? $meta['custom_markup'] : '' ) ) );
  1358.  
  1359.             switch( $service )
  1360.             {
  1361.                 case 'html5':
  1362.                     $types = array( 'webm' => 'type="video/webm"', 'mp4' => 'type="video/mp4"', 'ogv' => 'type="video/ogg"' );
  1363.                     $video = "<div class='av-click-overlay'></div>" . avia_html5_video_embed( $video_url,  $fallback_img, $types, $atts );
  1364.                     break;
  1365.                 case 'iframe':
  1366.                     $video = $video_url;
  1367.                     break;
  1368.                 case 'youtube':
  1369.                     $explode_at = strpos( $video_url, 'youtu.be/' ) !== false ? '/' : 'v=';
  1370.                     $video_url = explode( $explode_at, trim( $video_url ) );
  1371.                     $video_url = end( $video_url );
  1372.                     $video_id = $video_url;
  1373.  
  1374.                     //if parameters are appended make sure to create the correct video id
  1375.                     if( strpos( $video_url, '?' ) !== false || strpos( $video_url, '?' ) !== false )
  1376.                     {
  1377.                         preg_match( '!(.+)[&?]!', $video_url, $video_id );
  1378.                         $video_id = isset( $video_id[1] ) ? $video_id[1] : $video_id[0];
  1379.                     }
  1380.  
  1381.                     $video_data = apply_filters( 'avf_youtube_video_data', array(
  1382.                             'autoplay'      => 0,
  1383.                             'videoid'       => $video_id,
  1384.                             'hd'            => 1,
  1385.                             'rel'           => 0,
  1386.                             'wmode'         => 'opaque',
  1387.                             'loop'          => 0,
  1388.                             'version'       => 3,
  1389.                             'autohide'      => 1,
  1390.                             'color'         => 'white',
  1391.                             'controls'      => $controls,
  1392.                             'iv_load_policy'=> 3
  1393.                         ));
  1394.  
  1395.                     $data = AviaHelper::create_data_string( $video_data );
  1396.  
  1397.                     $video = "<div class='av-click-overlay'></div><div class='mejs-mediaelement' {$markup_video}><div height='1600' width='900' class='av_youtube_frame' id='{$uid}' {$data} data-original_url='{$origin_url}' ></div></div>";
  1398.                     $markup_video = '';
  1399.                     break;
  1400.                 case 'vimeo':
  1401.                     $color = ltrim( avia_get_option('colorset-main_color-primary'), '#');
  1402.                     $autopause = empty( $meta['video_section_bg'] ) ? 1 : 0; //pause if another vimeo video plays?
  1403.                     $video_url = explode( '/', trim( $video_url ) );
  1404.                     $video_url = end( $video_url );
  1405.                     $video_url = esc_url( add_query_arg(
  1406.                         array(
  1407.                             'portrait'  => 0,
  1408.                             'byline'    => 0,
  1409.                             'title'     => 0,
  1410.                             'badge'     => 0,
  1411.                             'loop'      => $atts['loop'],
  1412.                             'autopause' => $autopause,
  1413.                             'api'       => 1,
  1414.                             'rel'       => 0,
  1415.                             'player_id' => $uid,
  1416.                             'color'     => $color
  1417.                             ),
  1418.                         '//player.vimeo.com/video/' . $video_url
  1419.                         ));
  1420.  
  1421.                     $video_url = apply_filters( 'avf_vimeo_video_url' , $video_url );
  1422.                     $video = "<div class='av-click-overlay'></div><div class='mejs-mediaelement' {$markup_video}><div data-src='{$video_url}' data-original_url='{$origin_url}' height='1600' width='900' class='av_vimeo_frame' id='{$uid}'></div></div>";
  1423.                     $markup_video = '';
  1424.                     break;
  1425.             }
  1426.  
  1427.             return $video;
  1428.         }
  1429.  
  1430.         /**
  1431.          * get the video service based on the url string fo the video
  1432.          *
  1433.          * @param strint $video_url
  1434.          * @return string
  1435.          */
  1436.         static public function which_video_service( $video_url )
  1437.         {
  1438.             $service = '';
  1439.  
  1440.             if( avia_backend_is_file( $video_url, 'html5video' ) )
  1441.             {
  1442.                 $service = 'html5';
  1443.             }
  1444.             else if( strpos( $video_url, '<iframe' ) !== false )
  1445.             {
  1446.                 $service = 'iframe';
  1447.             }
  1448.             else
  1449.             {
  1450.                 if( strpos( $video_url, 'youtube.com/watch' ) !== false || strpos( $video_url, 'youtu.be/' ) !== false )
  1451.                 {
  1452.                     $service = 'youtube';
  1453.                 }
  1454.                 else if( strpos( $video_url, 'vimeo.com' ) !== false )
  1455.                 {
  1456.                     $service = 'vimeo';
  1457.                 }
  1458.             }
  1459.  
  1460.             return $service;
  1461.         }
  1462.  
  1463.         /**
  1464.          * Checks, if the video is an external service
  1465.          *
  1466.          * @since 4.4
  1467.          * @param string $video_url
  1468.          * @return boolean
  1469.          */
  1470.         static public function is_extern_service( $video_url )
  1471.         {
  1472.             $ervice = avia_slideshow_video_helper::which_video_service( $video_url );
  1473.  
  1474.             return in_array( $ervice, avia_slideshow_video_helper::$extern_services );
  1475.         }
  1476.     }
  1477. }
  1478.  
Tags: slider v5.6.3
Advertisement
Add Comment
Please, Sign In to add comment