Advertisement
Guest User

Untitled

a guest
Mar 30th, 2023
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 23.55 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Video
  4.  *
  5.  * Shortcode which display a video
  6.  *
  7.  * @since ????
  8.  * @since 4.8.9 - complete refactored code
  9.  */
  10. if( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  11.  
  12.  
  13. if( ! class_exists( 'avia_sc_video' ) )
  14. {
  15.     class avia_sc_video extends aviaShortcodeTemplate
  16.     {
  17.         /**
  18.          * Create the config array for the shortcode button
  19.          */
  20.         protected function shortcode_insert_button()
  21.         {
  22.             $this->config['version']            = '1.0';
  23.             $this->config['self_closing']       = 'yes';
  24.             $this->config['base_element']       = 'yes';
  25.  
  26.             $this->config['name']               = __( 'Video', 'avia_framework' );
  27.             $this->config['tab']                = __( 'Media Elements', 'avia_framework' );
  28.             $this->config['icon']               = AviaBuilder::$path['imagesURL'] . 'sc-video.png';
  29.             $this->config['order']              = 90;
  30.             $this->config['target']             = 'avia-target-insert';
  31.             $this->config['shortcode']          = 'av_video';
  32.         //              $this->config['modal_data']     = array( 'modal_class' => 'mediumscreen' );
  33.             $this->config['tooltip']            = __( 'Display a video', 'avia_framework' );
  34.             $this->config['disabling_allowed']  = false; //only allowed to be disabled by extra options
  35.             $this->config['disabled']           = array(
  36.                                                     'condition' => ( avia_get_option( 'disable_mediaelement' ) == 'disable_mediaelement' && avia_get_option( 'disable_video' ) == 'disable_video' ),
  37.                                                     'text'      => __( 'This element is disabled in your theme options. You can enable it in Enfold &raquo; Performance', 'avia_framework' )
  38.                                                 );
  39.             $this->config['id_name']            = 'id';
  40.             $this->config['id_show']            = 'yes';
  41.         }
  42.  
  43.         protected function extra_assets()
  44.         {
  45.             $ver = Avia_Builder()->get_theme_version();
  46.             $min_js = avia_minify_extension( 'js' );
  47.             $min_css = avia_minify_extension( 'css' );
  48.  
  49.             //load css
  50.             wp_enqueue_style( 'avia-module-video', AviaBuilder::$path['pluginUrlRoot'] . "avia-shortcodes/video/video{$min_css}.css", array( 'avia-layout' ), $ver );
  51.  
  52.             wp_enqueue_script( 'avia-module-slideshow-video', AviaBuilder::$path['pluginUrlRoot'] . "avia-shortcodes/slideshow/slideshow-video{$min_js}.js", array( 'avia-shortcodes' ), $ver, true );
  53.             wp_enqueue_script( 'avia-module-video', AviaBuilder::$path['pluginUrlRoot'] . "avia-shortcodes/video/video{$min_js}.js", array( 'avia-shortcodes' ), $ver, true );
  54.         }
  55.  
  56.         /**
  57.          * Popup Elements
  58.          *
  59.          * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  60.          * opens a modal window that allows to edit the element properties
  61.          *
  62.          * @return void
  63.          */
  64.         protected function popup_elements()
  65.         {
  66.  
  67.             //if the element is disabled
  68.             if( true === $this->config['disabled']['condition'] )
  69.             {
  70.                 $this->elements = array(
  71.  
  72.                     array(
  73.                                 'type'          => 'template',
  74.                                 'template_id'   => 'element_disabled',
  75.                                 'args'          => array(
  76.                                                         'desc'  => $this->config['disabled']['text']
  77.                                                     )
  78.                             ),
  79.                         );
  80.  
  81.                 return;
  82.             }
  83.  
  84.  
  85.             $this->elements = array(
  86.  
  87.                 array(
  88.                         'type'  => 'tab_container',
  89.                         'nodescription' => true
  90.                     ),
  91.  
  92.                 array(
  93.                         'type'  => 'tab',
  94.                         'name'  => __( 'Content', 'avia_framework' ),
  95.                         'nodescription' => true
  96.                     ),
  97.  
  98.                     array(
  99.                             'type'          => 'template',
  100.                             'template_id'   => 'toggle_container',
  101.                             'templates_include' => array(
  102.                                                     $this->popup_key( 'content_video' ),
  103.                                                     $this->popup_key( 'content_player' )
  104.                                                 ),
  105.                             'nodescription' => true
  106.                         ),
  107.  
  108.                 array(
  109.                         'type'  => 'tab_close',
  110.                         'nodescription' => true
  111.                     ),
  112.  
  113.                 array(
  114.                         'type'  => 'tab',
  115.                         'name'  => __( 'Styling', 'avia_framework' ),
  116.                         'nodescription' => true
  117.                     ),
  118.  
  119.                     array(
  120.                             'type'          => 'template',
  121.                             'template_id'   => $this->popup_key( 'styling_format' )
  122.                         ),
  123.  
  124.                 array(
  125.                         'type'  => 'tab_close',
  126.                         'nodescription' => true
  127.                     ),
  128.  
  129.                 array(
  130.                         'type'  => 'tab',
  131.                         'name'  => __( 'Advanced', 'avia_framework' ),
  132.                         'nodescription' => true
  133.                     ),
  134.  
  135.                     array(
  136.                             'type'  => 'toggle_container',
  137.                             'nodescription' => true
  138.                         ),
  139.  
  140.                         array(
  141.                                 'type'          => 'template',
  142.                                 'template_id'   => $this->popup_key( 'advanced_privacy' )
  143.                             ),
  144.  
  145.                         array(
  146.                                 'type'          => 'template',
  147.                                 'template_id'   => 'screen_options_toggle',
  148.                                 'lockable'      => true
  149.                             ),
  150.  
  151.                         array(
  152.                                 'type'          => 'template',
  153.                                 'template_id'   => 'developer_options_toggle',
  154.                                 'args'          => array( 'sc' => $this )
  155.                             ),
  156.  
  157.                     array(
  158.                             'type'  => 'toggle_container_close',
  159.                             'nodescription' => true
  160.                         ),
  161.  
  162.                 array(
  163.                         'type'  => 'tab_close',
  164.                         'nodescription' => true
  165.                     ),
  166.  
  167.                 array(
  168.                         'type'          => 'template',
  169.                         'template_id'   => 'element_template_selection_tab',
  170.                         'args'          => array( 'sc' => $this )
  171.                     ),
  172.  
  173.                 array(
  174.                         'type'  => 'tab_container_close',
  175.                         'nodescription' => true
  176.                     )
  177.  
  178.                 );
  179.  
  180.  
  181.         }
  182.  
  183.         /**
  184.          * Create and register templates for easier maintainance
  185.          *
  186.          * @since 4.6.4
  187.          */
  188.         protected function register_dynamic_templates()
  189.         {
  190.             /**
  191.              * Content Tab
  192.              * ===========
  193.              */
  194.  
  195.             $c = array(
  196.                         array(
  197.                             'type'          => 'template',
  198.                             'template_id'   => 'video',
  199.                             'id'            => 'src',
  200.                             'args'          => array(
  201.                                                     'sc'            => $this,
  202.                                                     'html_5_urls'   => current_theme_supports( 'avia_template_builder_custom_html5_video_urls' )
  203.                                                 ),
  204.                             'lockable'      => true
  205.                         ),
  206.  
  207.                         array(
  208.                             'name'      => __( 'Save Video Thumbnail Locally', 'avia_framework' ),
  209.                             'desc'      => __( 'Download the video preview thumbnail and save it in the media library', 'avia_framework' ),
  210.                             'title'     => __( 'Download video thumbnail', 'avia_framework' ),
  211.                             'id'        => 'video_thumbnails',
  212.                             'type'      => 'action_button',
  213.                             'container_class' => 'avia-save_video_thumbnails'
  214.                         ),
  215.  
  216.                         array(
  217.                             'name'      => __( 'Choose a preview/fallback image', 'avia_framework' ),
  218.                             'desc'      => __( 'Either upload a new, or choose an existing image from your media library', 'avia_framework' ) . '<br/><small>' . __( "Video on most mobile devices can't be controlled properly with JavaScript, so you can upload a fallback image which will be displayed instead. This image is also used if lazy loading is active.", 'avia_framework' ) . '</small>',
  219.                             'id'        => 'fallback_img',
  220.                             'type'      => 'image',
  221.                             'title'     => __( 'Choose Image', 'avia_framework' ),
  222.                             'button'    => __( 'Choose Image', 'avia_framework' ),
  223.                             'std'       => '',
  224.                             'lockable'  => true,
  225.                             'locked'    => array( 'src', 'attachment', 'attachment_size' )
  226.                         )
  227.                 );
  228.  
  229.             $template = array(
  230.                             array(
  231.                                 'type'          => 'template',
  232.                                 'template_id'   => 'toggle',
  233.                                 'title'         => __( 'Select Video', 'avia_framework' ),
  234.                                 'content'       => $c
  235.                             ),
  236.                     );
  237.  
  238.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_video' ), $template );
  239.  
  240.             $c = array(
  241.                         array(
  242.                             'name'      => __( 'Enable Autoplay', 'avia_framework' ),
  243.                             'desc'      => __( 'Check if you want to enable video autoplay when page is loaded. Videos will be muted by default.', 'avia_framework' ),
  244.                             'id'        => 'video_autoplay_enabled',
  245.                             'type'      => 'checkbox',
  246.                             'std'       => '',
  247.                             'lockable'  => true
  248.                         ),
  249.  
  250.                         array(
  251.                             'name'      => __( 'Mute Video Player', 'avia_framework' ),
  252.                             'desc'      => __( 'Check if you want to mute the video.', 'avia_framework' ),
  253.                             'id'        => 'video_mute',
  254.                             'type'      => 'checkbox',
  255.                             'std'       => '',
  256.                             'lockable'  => true
  257.                         ),
  258.  
  259.                         array(
  260.                             'name'      => __( 'Loop Video Player', 'avia_framework' ),
  261.                             'desc'      => __( 'Check if you want to loop the video and play it from the beginning again', 'avia_framework' ),
  262.                             'id'        => 'video_loop',
  263.                             'type'      => 'checkbox',
  264.                             'std'       => '',
  265.                             'lockable'  => true
  266.                         ),
  267.  
  268.                         array(
  269.                             'name'      => __( 'Hide Video Controls', 'avia_framework' ),
  270.                             'desc'      => __( 'Check if you want to hide the controls (works for youtube and self hosted videos)', 'avia_framework' ),
  271.                             'id'        => 'video_controls',
  272.                             'type'      => 'checkbox',
  273.                             'std'       => '',
  274.                             'lockable'  => true
  275.                         ),
  276.  
  277.                         array(
  278.                             'name'      => __( 'Show Fullscreen Button (HTML5 videos)', 'avia_framework' ),
  279.                             'desc'      => __( 'Check if you want to show the fullscreen button for HTML5 videos (setting is ignored for other type of videos)', 'avia_framework' ),
  280.                             'id'        => 'html5_fullscreen',
  281.                             'type'      => 'checkbox',
  282.                             'std'       => '',
  283.                             'lockable'  => true
  284.                         )
  285.                 );
  286.  
  287.             $template = array(
  288.                             array(
  289.                                 'type'          => 'template',
  290.                                 'template_id'   => 'toggle',
  291.                                 'title'         => __( 'Player Settings', 'avia_framework' ),
  292.                                 'content'       => $c
  293.                             ),
  294.                     );
  295.  
  296.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_player' ), $template );
  297.  
  298.  
  299.             /**
  300.              * Styling Tab
  301.              * ===========
  302.              */
  303.  
  304.             $c = array(
  305.                         array(
  306.                             'name'      => __( 'Video Format', 'avia_framework' ),
  307.                             'desc'      => __( 'Choose if you want to display a modern 16:9 or classic 4:3 Video, or use a custom ratio', 'avia_framework' ),
  308.                             'id'        => 'format',
  309.                             'type'      => 'select',
  310.                             'std'       => '16:9',
  311.                             'lockable'  => true,
  312.                             'subtype'   => array(
  313.                                                 __( '16:9', 'avia_framework' )          => '16-9',
  314.                                                 __( '4:3', 'avia_framework' )           => '4-3',
  315.                                                 __( 'Custom Ratio', 'avia_framework' )  => 'custom',
  316.                                             )
  317.                         ),
  318.  
  319.                         array(
  320.                             'name'      => __( 'Video width', 'avia_framework' ),
  321.                             'desc'      => __( 'Enter a value for the width', 'avia_framework' ),
  322.                             'id'        => 'width',
  323.                             'type'      => 'input',
  324.                             'std'       => '16',
  325.                             'lockable'  => true,
  326.                             'required'  => array( 'format', 'equals', 'custom' )
  327.                         ),
  328.  
  329.                         array(
  330.                             'name'      => __( 'Video height', 'avia_framework' ),
  331.                             'desc'      => __( 'Enter a value for the height', 'avia_framework' ),
  332.                             'id'        => 'height',
  333.                             'type'      => 'input',
  334.                             'std'       => '9',
  335.                             'lockable'  => true,
  336.                             'required'  => array( 'format', 'equals', 'custom' )
  337.                         )
  338.                 );
  339.  
  340.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_format' ), $c );
  341.  
  342.  
  343.             /**
  344.              * Advanced Tab
  345.              * ===========
  346.              */
  347.  
  348.             $c = array(
  349.                         array(
  350.                             'name'      => __( 'Lazy Load videos', 'avia_framework' ),
  351.                             'desc'      => __( 'Option to only load the preview image. The actual video will only be fetched once the user clicks on the image (Waiting for user interaction speeds up the inital pageload).', 'avia_framework' ),
  352.                             'id'        => 'conditional_play',
  353.                             'type'      => 'select',
  354.                             'std'       => '',
  355.                             'lockable'  => true,
  356.                             'subtype'   => array(
  357.                                                 __( 'Always load videos', 'avia_framework' )                            => '',
  358.                                                 __( 'Wait for user interaction to load the video', 'avia_framework' )   => 'confirm_all',
  359.                                                 __( 'Show in lightbox - loads after user interaction - preview image recommended', 'avia_framework' )   => 'lightbox'
  360.                                             ),
  361.                         )
  362.                 );
  363.  
  364.             $template = array(
  365.                             array(
  366.                                 'type'          => 'template',
  367.                                 'template_id'   => 'toggle',
  368.                                 'title'         => __( 'Privacy Settings', 'avia_framework' ),
  369.                                 'content'       => $c
  370.                             ),
  371.                     );
  372.  
  373.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'advanced_privacy' ), $template );
  374.         }
  375.  
  376.         /**
  377.          * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  378.          * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  379.          * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  380.          *
  381.          * @param array $params         holds the default values for $content and $args.
  382.          * @return array                usually holds an innerHtml key that holds item specific markup.
  383.          */
  384.         public function editor_element( $params )
  385.         {
  386.             $default = array();
  387.             $locked = array();
  388.             $attr = $params['args'];
  389.             Avia_Element_Templates()->set_locked_attributes( $attr, $this, $this->config['shortcode'], $default, $locked );
  390.  
  391.             $template = $this->update_template_lockable( 'src', 'URL: {{src}}', $locked );
  392.             $url = isset( $attr['src'] ) ? $attr['src'] : '';
  393.  
  394.             $params = parent::editor_element( $params );
  395.             $params['innerHtml'].= "<div class='avia-element-url' data-update_element_template='yes' {$template}> URL: {$url}</div>";
  396.  
  397.             $params['content'] = null;
  398.             $params['class'] = 'avia-video-element';
  399.  
  400.             return $params;
  401.         }
  402.  
  403.         /**
  404.          * Create custom stylings
  405.          *
  406.          * @since 4.8.7
  407.          * @param array $args
  408.          * @return array
  409.          */
  410.         protected function get_element_styles( array $args )
  411.         {
  412.             $result = parent::get_element_styles( $args );
  413.  
  414.             extract( $result );
  415.  
  416.             $default = array(
  417.                         'src'               => '',
  418.                         'src_1'             => '',
  419.                         'src_2'             => '',
  420.                         'fallback_link'     => '',
  421.                         'format'            => '16:9',
  422.                         'height'            => '9',
  423.                         'width'             => '16',
  424.                         'conditional_play'  => '',
  425.                         'video_controls'    => '',
  426.                         'video_mute'        => '',
  427.                         'video_loop'        => '',
  428.                         'html5_fullscreen'  => '',
  429.                         'video_autoplay_enabled'    => '',
  430.                         'attachment'        => '',
  431.                         'attachment_size'   => '',
  432.  
  433.                         'fallback_img'      => ''               //  save info to avoid double query
  434.                     );
  435.  
  436.             $default = $this->sync_sc_defaults_array( $default );
  437.  
  438.             $locked = array();
  439.             Avia_Element_Templates()->set_locked_attributes( $atts, $this, $shortcodename, $default, $locked, $content );
  440.             Avia_Element_Templates()->add_template_class( $meta, $atts, $default );
  441.  
  442.             $atts = shortcode_atts( $default, $atts, $this->config['shortcode'] );
  443.  
  444.  
  445.             $classes = array(
  446.                         'avia-video',
  447.                         $element_id,
  448.                         'avia-video-' . $atts['format']
  449.                     );
  450.  
  451.             $element_styling->add_classes( 'container', $classes );
  452.             $element_styling->add_classes_from_array( 'container', $meta, 'custom_class' );
  453.             $element_styling->add_responsive_classes( 'container', 'hide_element', $atts );
  454.  
  455.             if( ! empty( $atts['html5_fullscreen'] ) )
  456.             {
  457.                 $element_styling->add_classes( 'container', 'av-html5-fullscreen-btn' );
  458.             }
  459.  
  460.             $image_class = 'av-no-preview-image';
  461.             if( ! empty( $atts['attachment'] ) )
  462.             {
  463.                 $fallback = wp_get_attachment_image_src( str_replace(",", "", $atts['attachment']), $atts['attachment_size'] );
  464.                
  465.                 if( is_array( $fallback ) )
  466.                 {
  467.                     $atts['fallback_img'] = $fallback[0];
  468.  
  469.                     $image_class = 'av-preview-image';
  470.                     $element_styling->add_styles( 'container', array( 'background-image' => $atts['fallback_img'] ) );
  471.                 }
  472.             }
  473.  
  474.             $element_styling->add_classes( 'container', $image_class );
  475.  
  476.             if( 'custom' == $atts['format'] )
  477.             {
  478.                 $height = is_numeric( $atts['height'] ) ? abs( intval( $atts['height'] ) ) : 9;
  479.                 $width = is_numeric( $atts['width'] ) ? abs( intval( $atts['width'] ) ) : 16;
  480.  
  481.                 //  fallback to 16 : 9
  482.                 if( 0 == $height || 0 == $width )
  483.                 {
  484.                     $height = 9;
  485.                     $width = 16;
  486.                 }
  487.  
  488.                 $ratio = round( ( 100 / $width ) * $height, 0 );
  489.  
  490.                 $element_styling->add_styles( 'container', array( 'padding-bottom' => $ratio . '%' ) );
  491.             }
  492.  
  493.  
  494.             $selectors = array(
  495.                         'container' => ".avia-video.{$element_id}"
  496.                     );
  497.  
  498.             $element_styling->add_selectors( $selectors );
  499.  
  500.  
  501.             $result['default'] = $default;
  502.             $result['atts'] = $atts;
  503.             $result['content'] = $content;
  504.             $result['element_styling'] = $element_styling;
  505.  
  506.             return $result;
  507.         }
  508.  
  509.         /**
  510.          * Frontend Shortcode Handler
  511.          *
  512.          * @param array $atts array of attributes
  513.          * @param string $content text within enclosing form of shortcode element
  514.          * @param string $shortcodename the shortcode found, when == callback name
  515.          * @param array $meta
  516.          * @return string $output returns the modified html string
  517.          */
  518.         public function shortcode_handler( $atts, $content = '', $shortcodename = '', $meta = '' )
  519.         {
  520.             $result = $this->get_element_styles( compact( array( 'atts', 'content', 'shortcodename', 'meta' ) ) );
  521.  
  522.             extract( $result );
  523.             extract( $atts );
  524.  
  525.             $output_html = '';
  526.             $video = '';
  527.             /**
  528.              * Autoplay videos must be muted
  529.              */
  530.             if( ! empty( $video_autoplay_enabled ) )
  531.             {
  532.                 $video_mute = 1;
  533.             }
  534.  
  535.             if( 'lightbox_active' != avia_get_option( 'lightbox_active', '' ) && 'lightbox' == $conditional_play  )
  536.             {
  537.                 /**
  538.                  * Activate a custom lightbox to show video.
  539.                  * In frontend hook into trigger 'avia-open-video-in-lightbox' (<a> tag containing link to video) to load video in your lightbox
  540.                  *
  541.                  * @since 4.6.3
  542.                  * @param array $atts array of attributes
  543.                  * @param string $content text within enclosing form of shortcode element
  544.                  * @param string $shortcodename the shortcode found, when == callback name
  545.                  * @param array $meta
  546.                  * @return boolean
  547.                  */
  548.                 if( false === apply_filters( 'avf_show_video_in_custom_lightbox', false, $atts, $content, $shortcodename, $meta ) )
  549.                 {
  550.                     $conditional_play = 'confirm_all';
  551.                 }
  552.             }
  553.  
  554.             switch( $conditional_play )
  555.             {
  556.                 case 'lightbox':
  557.                 case 'confirm_all':
  558.                     $element_styling->add_classes( 'container', 'avia-video-' . $conditional_play );
  559.                     break;
  560.                 default:
  561.                     $element_styling->add_classes( 'container', 'avia-video-load-always' );
  562.             }
  563.  
  564.             $video_html_raw = '';
  565.             $video_attributes = array(
  566.                                     'autoplay'  => empty( $video_autoplay_enabled ) ? 0 : 1,
  567.                                     'loop'      => empty( $video_loop ) ? 0 : 1,
  568.                                     'preload'   => '',
  569.                                     'muted'     => empty( $video_mute ) ? 0 : 1,
  570.                                     'controls'  => empty( $video_controls ) ? 1 : 0
  571.                                 );
  572.  
  573.  
  574.             $html5_sources = $this->get_html5_sources( array( $src, $src_1, $src_2 ) );
  575.  
  576.  
  577.             if( false !== $html5_sources && $conditional_play != 'lightbox' )
  578.             {
  579.                 $html5_files = isset( $html5_sources['files'] ) ? $html5_sources['files'] : array();
  580.                 $html5_types = isset( $html5_sources['types'] ) ? $html5_sources['types'] : array();
  581.  
  582.                 $video_html_raw = avia_html5_video_embed( $html5_files, $fallback_img, $html5_types, $video_attributes );
  583.                 $output_html = $video_html_raw;
  584.  
  585.                 $element_styling->add_classes( 'container', 'avia-video-html5' );
  586.             }
  587.             else if( $conditional_play != 'lightbox' )
  588.             {
  589.  
  590.                 global $wp_embed;
  591.  
  592.                 $video_html_raw = $wp_embed->run_shortcode( '[embed]' . trim( $src ) . '[/embed]' );
  593.                 $output_html = $video_html_raw;
  594.  
  595.                 if( ! empty( $conditional_play ) )
  596.                 {
  597.                     //append autoplay so the user does not need to click 2 times
  598.                     $video_attributes['autoplay'] = 1;
  599.                 }
  600.                 else
  601.                 {
  602.                     $element_styling->add_classes( 'container', 'av-lazyload-immediate' );
  603.                 }
  604.  
  605.                 /**
  606.                  * Add selected video player params to url, does not remove any manually set parameters
  607.                  */
  608.                 $match = array();
  609.                 preg_match( '!src="(.*?)"!', $output_html, $match );
  610.                 if( isset( $match[1] ) && ( ( false !== strpos( $match[1], 'www.youtube.com/' ) ) || ( false !== strpos( $match[1], 'player.vimeo.com/' ) ) ) )
  611.                 {
  612.                     $params = array();
  613.                     $youtube = false !== strpos( $match[1], 'www.youtube.com/' ) ? true : false;
  614.  
  615.                     $params[] = 'autoplay=' . $video_attributes['autoplay'];
  616.                     $params[] = 'loop=' . $video_attributes['loop'];
  617.                     $params[] = 'controls=' . $video_attributes['controls'];
  618.                     $params[] = $youtube ? 'mute=' . $video_attributes['muted'] : 'muted=' . $video_attributes['muted'];
  619.  
  620.                     if( $youtube && $video_attributes['loop'] && false !== strpos( $src, 'v=' ) )
  621.                     {
  622.                         //  https://developers.google.com/youtube/player_parameters#loop
  623.                         $list = explode( 'v=', $src );
  624.                         if( isset( $list[1] ) && ! empty( $list[1] ) )
  625.                         {
  626.                             $params[] = 'playlist=' .  $list[1];
  627.                         }
  628.                     }
  629.  
  630.                     if( ! empty( $params ) )
  631.                     {
  632.                         $params = implode( '&', $params );
  633.  
  634.                         if( strpos( $match[1], '?' ) === false )
  635.                         {
  636.                             $output_html = str_replace( $match[1], $match[1] . '?' . $params, $output_html );
  637.                         }
  638.                         else
  639.                         {
  640.                             $output_html = str_replace( $match[1], $match[1] . '&' . $params, $output_html );
  641.                         }
  642.                     }
  643.                 }
  644.  
  645.                 $output_html =  "<script type='text/html' class='av-video-tmpl'>{$output_html}</script>";
  646.                 $output_html .= "<div class='av-click-to-play-overlay'>";
  647.                 $output_html .=     '<div class="avia_playpause_icon">';
  648.                 $output_html .=     '</div>';
  649.                 $output_html .= '</div>';
  650.  
  651.                 $element_styling->add_classes( 'container', 'av-lazyload-video-embed' );
  652.             }
  653.             else
  654.             {
  655.                 $element_styling->add_classes( 'container', array( 'av-lazyload-video-embed' ) );
  656.  
  657.                 $overlay  = '<div class="av-click-to-play-overlay play-lightbox">';
  658.                 $overlay .=     '<div class="avia_playpause_icon">';
  659.                 $overlay .=     '</div>';
  660.                 $overlay .= '</div>';
  661.  
  662.                 if( ( false !== stripos( $src, 'youtube.com/watch' ) ) || ( false !== stripos( $src, 'vimeo.com/' ) ) )
  663.                 {
  664.                     $element_styling->add_classes( 'container', 'avia-video-external-service' );
  665.  
  666.                     $src .= ( strpos( $src, '?' ) === false ) ? '?autoplay=1' : '&autoplay=1';
  667.                     $output_html = "<a href='{$src}' class='mfp-iframe lightbox-link'></a>";
  668.                 }
  669.                 else if( ! empty( $src ) )
  670.                 {
  671.                     $element_styling->add_classes( 'container', 'avia-video-standard-html' );
  672.  
  673.                     $output_html = "<a href='{$src}' rel='lightbox' class='mfp-iframe lightbox-link'></a>";
  674.                 }
  675.  
  676.                 if( ! empty( $output_html ) )
  677.                 {
  678.                     $output_html = "<script type='text/html' class='av-video-tmpl'>{$output_html}</script>";
  679.                     $output_html .= $overlay;
  680.                 }
  681.             }
  682.  
  683.             if( ! empty( $output_html ) )
  684.             {
  685.                 $markup_video = avia_markup_helper( array( 'context' => 'video', 'echo' => false, 'custom_markup' => $meta['custom_markup'] ) );
  686.  
  687.                 $style_tag = $element_styling->get_style_tag( $element_id );
  688.                 $container_class = $element_styling->get_class_string( 'container' );
  689.  
  690.                 $output = '';
  691.                 $output .= $style_tag;
  692.                 $output .= "<div {$meta['custom_el_id']} class='{$container_class}' {$markup_video} data-original_url='{$src}'>";
  693.                 $output .=      $output_html;
  694.                 $output .= '</div>';
  695.             }
  696.  
  697.             /**
  698.              * Allow plugins to change output in case they want to handle it by themself.
  699.              * They must return the complete HTML structure.
  700.              *
  701.              * @since 4.5.7.2
  702.              * @since 4.8.7                         added $element_styling
  703.              * @param string $output
  704.              * @param array $atts
  705.              * @param string $content
  706.              * @param string $shortcodename
  707.              * @param array|string $meta
  708.              * @param string $video_html_raw
  709.              * @param aviaElementStyling $element_styling
  710.              * @return string
  711.              */
  712.             $output = apply_filters( 'avf_sc_video_output', $output, $atts, $content, $shortcodename, $meta, $video_html_raw, $element_styling );
  713.  
  714.             return $output;
  715.         }
  716.  
  717.         /**
  718.          * Check for valid HTML5 videos and return split info to build html.
  719.          * Only given HTML 5 video sources are returned.
  720.          * If no one found return false
  721.          *
  722.          * @since 4.8
  723.          * @since 4.8.9                     modified to return false if no HTML5 found
  724.          * @param array $source_files
  725.          * @return array|false
  726.          */
  727.         protected function get_html5_sources( array $source_files )
  728.         {
  729.             $found = false;
  730.  
  731.             $sources = array(
  732.                     'files' => array(),
  733.                     'types' => array()
  734.             );
  735.  
  736.             foreach( $source_files as $source_file )
  737.             {
  738.                 $ext = substr( $source_file, strrpos( $source_file, '.' ) + 1 );
  739.                 if( in_array( $ext, array( 'ogv', 'webm', 'mp4' ) ) )
  740.                 {
  741.                     $found = true;
  742.                     $sources['files'][ $ext ] = $source_file;
  743.                     $sources['types'][ $ext ] = "type='video/{$ext}'";
  744.                 }
  745.             }
  746.  
  747.             if( ! $found )
  748.             {
  749.                 return false;
  750.             }
  751.  
  752.             return $sources;
  753.         }
  754.     }
  755. }
  756.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement