_get_option('lightbox_force') // "Remove fancyBox" compatibility option is disabled ) return; if ( $fv_fp->_get_option('js-optimize') && ! did_action('fv_player_force_load_lightbox') ) { // TODO: Should we still enqueue CSS somehow? } else { wp_enqueue_style( 'fv_player_lightbox', FV_FP_RELATIVE_PATH . '/css/fancybox.css', array(), $fv_wp_flowplayer_ver ); } } function conf_defaults($conf){ //TODO probbably not needed in the future if(isset($conf['lightbox_images']) && $conf['lightbox_images'] && !isset($conf['lightbox_improve_galleries']) )$conf['lightbox_improve_galleries'] = false; $conf += array( 'lightbox_images' => false, 'lightbox_improve_galleries' => false ); return $conf; } function remove_pro_hooks() { global $FV_Player_Pro; if (isset($FV_Player_Pro)) { //remove_filter('fv_flowplayer_shortcode', array($FV_Player_Pro, 'shortcode')); remove_filter('fv_flowplayer_html', array($FV_Player_Pro, 'lightbox_html'), 11 ); remove_filter('fv_flowplayer_playlist_style', array($FV_Player_Pro, 'lightbox_playlist'), 10); remove_filter('fv_flowplayer_args', array($FV_Player_Pro, 'disable_autoplay')); // disable autoplay for lightboxed videos, todo: it should work instead! remove_filter('the_content', array($FV_Player_Pro, 'lightbox_add')); remove_filter('the_content', array($FV_Player_Pro, 'lightbox_add_post'), 999 ); // moved after the shortcodes are parsed to work for galleries } } function improve_galleries( $args ) { global $fv_fp; if ( empty( $args['link'] ) && $fv_fp->_get_option('lightbox_images') && $fv_fp->_get_option('lightbox_improve_galleries') ) { $args['link'] = 'file'; } return $args; } function lightbox_enable($sType) { if ($sType === 'video') { add_filter('fv_flowplayer_html', array($this, 'lightbox_html'), 11, 2); } else { remove_filter('fv_flowplayer_html', array($this, 'lightbox_html'), 11); } return $sType; } /* * Runs when "Remove fancyBox" compatibility option is enabled. Removes any other fancyBox script. */ function remove_other_fancybox() { global $fv_fp; if( $fv_fp->_get_option('lightbox_force') ) { global $wp_scripts; if( isset($wp_scripts) && isset($wp_scripts->queue) && is_array($wp_scripts->queue) ) { foreach( $wp_scripts->queue as $handle ) { if( stripos($handle,'fancybox') !== false ) { wp_dequeue_script($handle); } } } } } function shortcode($attrs) { $aArgs = func_get_args(); if (isset($aArgs[2]) && isset($aArgs[2]['lightbox'])) { $attrs['lightbox'] = $aArgs[2]['lightbox']; } return $attrs; } // Used in integration tests public function clear_lightboxed_players() { $this->lightboxHtml = ''; } function disp__lightboxed_players() { if ( strlen( $this->lightboxHtml ) ) { echo wp_kses_post( $this->lightboxHtml ) . "\n\n"; } } function editor_setting( $options ) { global $fv_fp; $options['general']['items'][] = array( 'label' => __( 'Lightbox', 'fv-player' ), 'name' => 'lightbox', 'description' => __( 'Video will play in a popup box.', 'fv-player' ), 'dependencies' => array( 'autoplay' => false, 'sticky' => false ), 'visible' => $fv_fp->_get_option( array('interface','lightbox') ), 'children' => array( array( 'label' => __( 'Lightbox Title', 'fv-player' ), 'name' => 'lightbox_caption', 'description' => __( 'Shows when the lightbox is open.', 'fv-player' ), 'type' => 'text', 'visible' => true ), ) ); return $options; } /* * Controls the stylesheet and script loading */ public function enqueue() { do_action('fv_player_force_load_lightbox'); } function is_text_lightbox($aArgs) { $aLightbox = preg_split('~[;]~', $aArgs['lightbox']); foreach ($aLightbox AS $k => $i) { if ($i == 'text') { return true; } } return false; } function lightbox_html($html) { $aArgs = func_get_args(); if (isset($aArgs[1]) ) { $args = $aArgs[1]->aCurArgs; if ( isset($args['lightbox']) && $args['lightbox'] != false && ! get_query_var( 'fv_player_embed' ) && ! get_query_var( 'fv_player_cms_id' ) ) { $this->bLoad = true; global $fv_fp; $iConfWidth = intval($fv_fp->_get_option('width')); $iConfHeight = intval($fv_fp->_get_option('height')); $iPlayerWidth = ( isset($args['width']) && intval($args['width']) > 0 ) ? intval($args['width']) : $iConfWidth; $iPlayerHeight = ( isset($args['height']) && intval($args['height']) > 0 ) ? intval($args['height']) : $iConfHeight; /* * Going back to the oldschool days... * The possibilities here are: * * true * true;text * true;Lightbox title * true;640;360;Lightbox title */ $aLightbox = preg_split('~[;]~', $args['lightbox']); // Properties set up by FV Player DB if( !empty($args['lightbox_width']) ) { $aLightbox[1] = $args['lightbox_width']; } if( !empty($args['lightbox_height']) ) { $aLightbox[2] = $args['lightbox_height']; } if( !empty($args['lightbox_caption']) ) { $aLightbox[3] = $args['lightbox_caption']; } $hash = $aArgs[1]->hash; $container = "wpfp_".$hash."_container"; $button = "fv_flowplayer_".$hash."_lightbox_starter"; $sTitle = ''; // Using "text" as in "true;640;360;text" makes it a text lightbox and it should not be used for the lightbox title if( !empty($aLightbox[3]) && $aLightbox[3] != 'text' ) { $sTitle = $aLightbox[3]; // If we only have "true;Lightbox title" then we know it's the lightbox title } else if( !empty($aLightbox[1]) && !isset($aLightbox[2]) && !isset($aLightbox[3]) && $aLightbox[1] != 'text' ) { $sTitle = $aLightbox[1]; // Allow caption="..." to override the title, some users use that still } else if( empty( $args['playlist'] ) && ! empty( $args['caption'] ) ) { $sTitle = wp_kses_post( $args['caption'] ); } else if( empty( $args['playlist'] ) && ! empty( $args['title'] ) ) { $sTitle = wp_kses_post( $args['title'] ); } $title_attribute = ! empty( $sTitle ) ? " title='" . esc_attr( $sTitle ) . "'" : ''; // Allow scripts for the lightboxed HTML for playlist sizing add_filter( 'wp_kses_allowed_html', array( $fv_fp, 'wp_kses_permit_scripts' ), 999, 2 ); // The original player HTML markup becomes the hidden lightbox content // We add the lightboxed class $lightbox = str_replace(array('class="freedomplayer ', "class='freedomplayer "), array('class="freedomplayer lightboxed ', "class='freedomplayer lightboxed "), $html); // ...and wrap it in hidden DIV $lightbox = "\n".'\n"; remove_filter( 'wp_kses_allowed_html', array( $fv_fp, 'wp_kses_permit_scripts' ), 999, 2 ); if ( $this->is_text_lightbox($args) ) { if( !empty($args['playlist']) ) { list( $playlist_items_external_html, $aPlaylistItems, $aSplashScreens, $aCaptions ) = $fv_fp->build_playlist( $args, $args['src'], $args['src1'], $args['src2'], false, false ); if( is_array($aCaptions) ) { $html = ''; } } else { $html = 'fancybox_opts().' id="'.$button.'"' . $title_attribute . ' class="fv-player-lightbox-link" href="#" data-src="#'.$container.'">' . $sTitle . ''; } // in this case we put the lightboxed player into footer as putting it behind the anchor might break the parent block element $this->lightboxHtml .= $lightbox; } else { $iWidth = ( isset($aLightbox[1]) && intval($aLightbox[1]) > 0 ) ? intval($aLightbox[1]) : ( ($iPlayerWidth > $iConfWidth) ? $iPlayerWidth : $iConfWidth ); $iHeight = ( isset($aLightbox[2]) && intval($aLightbox[2]) > 0 ) ? intval($aLightbox[2]) : ( ($iPlayerHeight > $iConfHeight) ? $iPlayerHeight : $iConfHeight ); // new classes to be added $add_classes = array( 'lightbox-starter' ); // use the align for the lightbox button if( isset($args['lightbox_align']) ) { $add_classes[] = 'align' . $args['lightbox_align']; } $sSplash = apply_filters('fv_flowplayer_playlist_splash', $args['splash'], $args['src']); // re-use the existing player HTML and add data-fancybox, data-options, new id and href $html = str_replace( '
fancybox_opts($sSplash).' id="'.$button.'"' . $title_attribute . ' href="#'.$container.'" ', $html ); // add all the new classes $html = str_replace( 'class="freedomplayer ', 'class="freedomplayer ' . implode(' ', $add_classes ). ' ' , $html ); // use new size $html = str_replace( array( "max-width: ".$iPlayerWidth."px", "max-height: ".$iPlayerHeight."px"), array('max-width: '.$iWidth.'px', 'max-height: '.$iHeight.'px'), $html ); // Only use new ratio for responsiveness if the lightbox size is specified $have_custom_size = ! empty( $aLightbox[1] ) || ! empty( $aLightbox[2] ); if ( $have_custom_size ) { $ratio = $iHeight / $iWidth; if( $ratio > 0 ) { $ratio = round($ratio, 4); $html = preg_replace( '~ data-ratio=".*?"~', ' data-ratio="'.$ratio.'"', $html ); $ratio = str_replace(',','.', $ratio * 100 ); $html = preg_replace( '~
~', '
', $html ); } } // this is how we link playlist items to the player $html = str_replace( ' rel="wpfp_'.$hash.'"', ' rel="'.$button.'"', $html ); // we removed FV Player data to make sure it won't initialize here $html = preg_replace( "~ data-item='.*?'~", '', $html ); $html = preg_replace( '~ data-item=".*?"~', '', $html ); // put the hidden player after our lightbox button $html .= $lightbox; } } } return $html; } /* * Load the scripts and stylesheets */ function load_scripts() { global $fv_fp, $fv_wp_flowplayer_ver; $aConf = array(); $aConf['lightbox_images'] = $fv_fp->_get_option('lightbox_images'); // should FV Player fancybox be used to show images? $aConf['js_url'] = flowplayer::get_plugin_url().'/js/fancybox.js'; $aConf['css_url'] = FV_FP_RELATIVE_PATH . '/css/fancybox.css'; $this->css_enqueue(true); if ( $fv_fp->_get_option('js-optimize') && ! did_action('fv_player_force_load_lightbox') ) { $script = " ( function() { let fv_player_fancybox_loaded = false; const triggers = document.querySelectorAll( '[data-fancybox], .fp-playlist-external[rel$=_lightbox_starter] a' ); for (let i = 0; i < triggers.length; i++) { triggers[i].addEventListener( 'click', function( e ) { if ( fv_player_fancybox_loaded ) return; fv_player_fancybox_loaded = true; let i = this, l = document.createElement('link'), s = document.createElement('script'); e.preventDefault(); e.stopPropagation(); l.rel = 'stylesheet'; l.type = 'text/css'; l.href = fv_player_lightbox.css_url; document.head.appendChild(l); s.onload = function () { let evt = new MouseEvent('click',{bubbles: true,cancelable:true,view:window}); i.dispatchEvent(evt); }; s.src = fv_player_lightbox.js_url; document.head.appendChild(s); }); } })(); "; if( !defined('SCRIPT_DEBUG') || !SCRIPT_DEBUG ) { // remove /* comments */ $script = preg_replace( '~/\*[\s\S]*?\*/~m', '', $script ); // remove whitespace $script = preg_replace( '~\s+~m', ' ', $script ); } // Load inline JS only, but will this work with WordPress 5.7? wp_register_script( 'fv_player_lightbox', '', array( 'jquery') ); wp_enqueue_script( 'fv_player_lightbox' ); wp_add_inline_script( 'fv_player_lightbox', trim( $script ) ); } else { wp_enqueue_script( 'fv_player_lightbox', flowplayer::get_plugin_url().'/js/fancybox.js', 'jquery', $fv_wp_flowplayer_ver, true ); } wp_localize_script( 'fv_player_lightbox', 'fv_player_lightbox', $aConf ); } function html_to_lightbox_videos($content) { // todo: disabling the option should turn this off if (stripos($content, 'colorbox') !== false) { $content = preg_replace_callback('~]*?class=[\'"][^\'"]*?\bcolorbox\b[^\'"]*?[\'"][^>]*?>([\s\S]*?)~', array($this, 'html_to_lightbox_videos_callback'), $content); return $content; } if( stripos($content, 'lightbox') !== false ) { $content = preg_replace_callback('~]*?class=[\'"][^\'"]*?\blightbox\b[^\'"]*?[\'"][^>]*?>([\s\S]*?)~', array($this, 'html_to_lightbox_videos_callback'), $content); return $content; } return $content; } function html_to_lightbox_videos_callback($matches) { $html = $matches[0]; $caption = trim($matches[1]); if( stripos($html,'.mp4') !== false && stripos($html,'.webm') !== false && stripos($html,'.m4v') !== false && stripos($html,'.mov') !== false && stripos($html,'.ogv') !== false && stripos($html,'.ogg') !== false && stripos($html,'.m3u8') !== false && stripos($html,'youtube.com/') !== false && stripos($html,'youtu.be/') !== false && stripos($html,'vimeo.com/') !== false ) { return $html; } if( preg_match( '~href=[\'"](.*?(?:mp4|webm|m4v|mov|ogv|ogg|m3u8|youtube\.com|youtu\.be|vimeo.com).*?)[\'"]~', $html, $href ) ) { if( stripos($caption,'_get_option('lightbox_images') === false ) { return $content; } // Look for any image links $content = preg_replace_callback('~(]*?href=[\'"][^\'"]*?(jpeg|jpg|jpe|gif|png)(?:\?.*?|\s*?)[\'"][^>]*?>\s*?)~', array($this, 'html_lightbox_images_callback'), $content, -1, $count ); if( $count ) { $this->bLoad = true; } return $content; } function html_lightbox_images_callback($matches) { if( stripos($matches[1],'data-fancybox') ) return $matches[0]; $matches[1] = str_replace( 'should_load() || $fv_fp->should_force_load_js() || // "Load FV Player JS everywhere" is enabled $fv_fp->_get_option('lightbox_force') // "Remove fancyBox" compatibility option is enabled ) { $this->load_scripts(); } } function parse_args( $aArgs ) { foreach ($aArgs AS $k => $i) { if ($i == 'text') { unset($aArgs[$k]); $bUseAnchor = true; } } return $aArgs; } function parse_html_caption( $aArgs ) { if( isset($aArgs['caption_html']) && $aArgs['caption_html'] ) { $aArgs['caption'] = base64_decode($aArgs['caption_html']); unset($aArgs['caption_html']); } return $aArgs; } function shortcode_editor() { global $fv_fp; $bLightbox = $fv_fp->_get_option(array('interface','lightbox')); if ($bLightbox) { ?> _get_checkbox(__( 'Remove fancyBox', 'fv-player' ), 'lightbox_force', __( 'Use if FV Player lightbox is not working and you see a "fancyBox already initialized" message on JavaScript console.', 'fv-player' )); } function lightbox_admin_interface_html() { global $fv_fp; $fv_fp->_get_checkbox(__( 'Enable video lightbox', 'fv-player' ), array('interface', 'lightbox'), __( 'You can also put in <a href="http://path.to.your/video.mp4" class="colorbox">Your link title</a> for a quick lightboxed video.', 'fv-player' )); } function lightbox_admin_default_options_html() { global $fv_fp; ?>

_get_option('lightbox_images')) echo 'checked="checked"'; ?> /> off your lightbox plugin when using this.', 'fv-player' ), array( 'strong' => array() ) ); ?> [gallery] galleries - these are automatically switched to link to image URLs rather than the attachment pages.'), array( 'code' => array() ) ); ?> (…)

_get_option('lightbox_improve_galleries')) echo 'checked="checked"'; ?> />

false); if( !empty($splash) ) $options['thumb'] = $splash; return " data-fancybox='gallery' data-options='".wp_json_encode($options)."'"; } /* * Was it enqueued with self::enqueue() ? */ function should_load() { return $this->bLoad || did_action('fv_player_force_load_lightbox'); } } global $FV_Player_lightbox; $FV_Player_lightbox = FV_Player_lightbox::_get_instance(); function FV_Player_lightbox() { return FV_Player_lightbox::_get_instance(); }