$maybe_old_video ]; } return $maybe_video; } } if (! function_exists('blocksy_has_video_element')) { function blocksy_has_video_element($args) { $parser = new Blocksy_Attributes_Parser(); $play_icon = ' '; if (! $args['display_video']) { return null; } $video_data = blocksy_get_video_data($args['attachment_id']); if ( ! isset($video_data['url']) || empty($video_data['url']) ) { return null; } return array_merge( $video_data, [ 'icon' => $play_icon, ] ); } } add_action( 'wp_ajax_blocksy_get_image_video_component', 'blocksy_get_via_request_image_video_component' ); add_action( 'wp_ajax_nopriv_blocksy_get_image_video_component', 'blocksy_get_via_request_image_video_component' ); function blocksy_get_via_request_image_video_component() { if (! isset($_GET['media'])) { wp_send_json_error(); } $args = []; if (isset($_GET['ignore_video_options'])) { $args['ignore_video_options'] = true; } $result = blocksy_get_image_video_component($_GET['media'], $args); if (empty($result)) { wp_send_json_error(); } wp_send_json_success([ 'html' => $result ]); return; } function blocksy_get_image_video_component($media_id, $args = []) { $args = wp_parse_args( $args, [ 'ignore_video_options' => false, ] ); if (! isset($media_id)) { return ''; } $video_data = blocksy_get_video_data($media_id); if ( ! isset($video_data['url']) || empty($video_data['url']) ) { return ''; } $use_simple_player = blocksy_akg('media_video_player', $video_data, 'no') === 'yes'; $use_autoplay = blocksy_akg('media_video_autoplay', $video_data, 'no') === 'yes'; $nocookies_mode = blocksy_akg('media_video_youtube_nocookies', $video_data, 'no') === 'yes'; if ($args['ignore_video_options']) { $use_autoplay = false; $use_simple_player = false; } preg_match( '#^(http|https)://.+\.(mp4|MP4|mpeg4)(?=\?|$)#i', $video_data['url'], $matches ); $media_video_loop = blocksy_akg('media_video_loop', $video_data, 'no'); if (isset($matches[0]) && ! empty($matches[0])) { $poster = wp_get_attachment_url($media_id); $video_attr = [ 'poster' => $poster, 'controls' => !$use_simple_player, 'playsinline' => 1 ]; $video_attr['autoplay'] = $use_autoplay; $video_attr['muted'] = $use_autoplay; $video_attr['loop'] = $media_video_loop === 'yes' ? 1 : 0; $result = blocksy_html_tag( 'video', $video_attr, blocksy_html_tag( 'source', [ 'src' => $video_data['url'], 'type' => 'video/mp4', ], false ) ); return $result; } $embed = wp_oembed_get($video_data['url']); $additional_parmas = [ 'autoplay' => $use_autoplay ? 1 : 0, 'controls' => ! $use_simple_player ? 1 : 0, 'loop' => $media_video_loop === 'yes' ? 1 : 0, 'playsinline' => 1, ]; if ( strpos($video_data['url'], 'youtube') !== false || strpos($video_data['url'], 'youtu.be') !== false ) { if ($media_video_loop === 'yes') { $id = explode('?', $video_data['url'])[1]; $id = str_replace('v=', '', array_reverse(explode('/', $id))[0]); $additional_parmas['playlist'] = $id; } $additional_parmas = array_merge( $additional_parmas, [ 'enablejsapi' => 1, 'version' => 3, 'playerapiid' => 'ytplayer', 'mute' => $use_autoplay ? 1 : 0 ] ); if ($nocookies_mode) { $embed = str_replace( 'youtube.com/embed', 'youtube-nocookie.com/embed', $embed ); } } if ( strpos($video_data['url'], 'vimeo') !== false ) { $additional_parmas = array_merge( $additional_parmas, [ 'autopause' => 0, 'background' => $use_simple_player ? 1 : 0, 'muted' => $use_autoplay ? 1 : 0, 'transparent' => 0 ] ); } $src_param = []; preg_match('/src=["](.*?)["]/', $embed, $src_param); if (isset($src_param[1]) && ! empty($src_param[1])) { $embed = str_replace( $src_param[1], add_query_arg( $additional_parmas, $src_param[1] ), $embed ); } return $embed; }