| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
class FV_Player_lightbox { |
| 8 |
|
| 9 |
static $instance = null; |
| 10 |
|
| 11 |
private $lightboxHtml = ''; |
| 12 |
|
| 13 |
public $bLoad = false; |
| 14 |
|
| 15 |
public static function _get_instance() { |
| 16 |
if( !self::$instance ) { |
| 17 |
self::$instance = new self(); |
| 18 |
} |
| 19 |
|
| 20 |
return self::$instance; |
| 21 |
} |
| 22 |
|
| 23 |
public function __construct() { |
| 24 |
|
| 25 |
if ( ! defined( 'ABSPATH' ) ) { |
| 26 |
exit; |
| 27 |
} |
| 28 |
|
| 29 |
add_action('init', array($this, 'remove_pro_hooks'), 10); |
| 30 |
|
| 31 |
add_filter('fv_flowplayer_shortcode', array($this, 'shortcode'), 15, 3); |
| 32 |
|
| 33 |
add_filter('fv_flowplayer_player_type', array($this, 'lightbox_enable')); |
| 34 |
|
| 35 |
add_filter('fv_flowplayer_args', array($this, 'disable_autoplay')); // disable autoplay for lightboxed videos |
| 36 |
add_filter('fv_flowplayer_args', array($this, 'lightbox_button_align')); // save align for lightbox button |
| 37 |
|
| 38 |
add_filter('fv_flowplayer_args_pre', array($this, 'lightbox_playlist_style')); // force slider style for lightboxed playlist |
| 39 |
|
| 40 |
add_filter('fv_flowplayer_args', array($this, 'parse_html_caption'), 0); |
| 41 |
|
| 42 |
add_filter('the_content', array($this, 'html_to_lightbox_videos')); |
| 43 |
add_filter('the_content', array($this, 'html_lightbox_images'), 999); // moved after the shortcodes are parsed to work for galleries |
| 44 |
|
| 45 |
add_action('fv_flowplayer_shortcode_editor_tab_options', array($this, 'shortcode_editor'), 8); |
| 46 |
|
| 47 |
add_filter( 'fv_player_editor_player_options', array( $this, 'editor_setting' ) ); |
| 48 |
|
| 49 |
add_action('fv_flowplayer_admin_default_options_after', array( $this, 'lightbox_admin_default_options_html' ) ); |
| 50 |
add_filter('fv_flowplayer_admin_interface_options_after', array( $this, 'lightbox_admin_interface_html' ) ); |
| 51 |
add_filter('fv_flowplayer_admin_integration_options_after', array( $this, 'lightbox_admin_integrations_html' ) ); |
| 52 |
|
| 53 |
add_action( 'wp_footer', array( $this, 'disp__lightboxed_players' ), 0 ); |
| 54 |
|
| 55 |
add_filter('fv_player_conf_defaults', array( $this, 'conf_defaults' ) ); |
| 56 |
|
| 57 |
add_action('wp_head', array( $this, 'remove_other_fancybox' ), 8 ); |
| 58 |
add_action('wp_footer', array( $this, 'remove_other_fancybox' ), 19 ); |
| 59 |
|
| 60 |
add_filter( 'shortcode_atts_gallery', array( $this, 'improve_galleries' ) ); |
| 61 |
|
| 62 |
add_action( 'wp_enqueue_scripts', array( $this, 'css_enqueue' ), 999 ); |
| 63 |
} |
| 64 |
|
| 65 |
/* |
| 66 |
* Load CSS if it's actually needed or if the global settings are set. |
| 67 |
* |
| 68 |
* @param bool $force Used to tell the function that the CSS is indeed required |
| 69 |
*/ |
| 70 |
function css_enqueue( $force ) { |
| 71 |
global $fv_fp, $fv_wp_flowplayer_ver; |
| 72 |
if( |
| 73 |
!$force && |
| 74 |
!$fv_fp->_get_option('lightbox_force') // "Remove fancyBox" compatibility option is disabled |
| 75 |
) return; |
| 76 |
|
| 77 |
if ( $fv_fp->_get_option('js-optimize') && ! did_action('fv_player_force_load_lightbox') ) { |
| 78 |
// TODO: Should we still enqueue CSS somehow? |
| 79 |
|
| 80 |
} else { |
| 81 |
wp_enqueue_style( 'fv_player_lightbox', FV_FP_RELATIVE_PATH . '/css/fancybox.css', array(), $fv_wp_flowplayer_ver ); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
function conf_defaults($conf){ |
| 86 |
//TODO probbably not needed in the future |
| 87 |
if(isset($conf['lightbox_images']) && $conf['lightbox_images'] && !isset($conf['lightbox_improve_galleries']) )$conf['lightbox_improve_galleries'] = false; |
| 88 |
|
| 89 |
$conf += array( |
| 90 |
'lightbox_images' => false, |
| 91 |
'lightbox_improve_galleries' => false |
| 92 |
); |
| 93 |
|
| 94 |
return $conf; |
| 95 |
} |
| 96 |
|
| 97 |
function remove_pro_hooks() { |
| 98 |
global $FV_Player_Pro; |
| 99 |
|
| 100 |
if (isset($FV_Player_Pro)) { |
| 101 |
//remove_filter('fv_flowplayer_shortcode', array($FV_Player_Pro, 'shortcode')); |
| 102 |
remove_filter('fv_flowplayer_html', array($FV_Player_Pro, 'lightbox_html'), 11 ); |
| 103 |
remove_filter('fv_flowplayer_playlist_style', array($FV_Player_Pro, 'lightbox_playlist'), 10); |
| 104 |
remove_filter('fv_flowplayer_args', array($FV_Player_Pro, 'disable_autoplay')); // disable autoplay for lightboxed videos, todo: it should work instead! |
| 105 |
remove_filter('the_content', array($FV_Player_Pro, 'lightbox_add')); |
| 106 |
remove_filter('the_content', array($FV_Player_Pro, 'lightbox_add_post'), 999 ); // moved after the shortcodes are parsed to work for galleries |
| 107 |
|
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
function improve_galleries( $args ) { |
| 112 |
global $fv_fp; |
| 113 |
if ( empty( $args['link'] ) && $fv_fp->_get_option('lightbox_images') && $fv_fp->_get_option('lightbox_improve_galleries') ) { |
| 114 |
$args['link'] = 'file'; |
| 115 |
} |
| 116 |
return $args; |
| 117 |
} |
| 118 |
|
| 119 |
function lightbox_enable($sType) { |
| 120 |
|
| 121 |
if ($sType === 'video') { |
| 122 |
add_filter('fv_flowplayer_html', array($this, 'lightbox_html'), 11, 2); |
| 123 |
} else { |
| 124 |
remove_filter('fv_flowplayer_html', array($this, 'lightbox_html'), 11); |
| 125 |
} |
| 126 |
|
| 127 |
return $sType; |
| 128 |
} |
| 129 |
|
| 130 |
/* |
| 131 |
* Runs when "Remove fancyBox" compatibility option is enabled. Removes any other fancyBox script. |
| 132 |
*/ |
| 133 |
function remove_other_fancybox() { |
| 134 |
global $fv_fp; |
| 135 |
if( $fv_fp->_get_option('lightbox_force') ) { |
| 136 |
global $wp_scripts; |
| 137 |
if( isset($wp_scripts) && isset($wp_scripts->queue) && is_array($wp_scripts->queue) ) { |
| 138 |
foreach( $wp_scripts->queue as $handle ) { |
| 139 |
if( stripos($handle,'fancybox') !== false ) { |
| 140 |
wp_dequeue_script($handle); |
| 141 |
} |
| 142 |
} |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
function shortcode($attrs) { |
| 148 |
$aArgs = func_get_args(); |
| 149 |
|
| 150 |
if (isset($aArgs[2]) && isset($aArgs[2]['lightbox'])) { |
| 151 |
$attrs['lightbox'] = $aArgs[2]['lightbox']; |
| 152 |
} |
| 153 |
|
| 154 |
return $attrs; |
| 155 |
} |
| 156 |
|
| 157 |
// Used in integration tests |
| 158 |
public function clear_lightboxed_players() { |
| 159 |
$this->lightboxHtml = ''; |
| 160 |
} |
| 161 |
|
| 162 |
function disp__lightboxed_players() { |
| 163 |
if ( strlen( $this->lightboxHtml ) ) { |
| 164 |
echo wp_kses_post( $this->lightboxHtml ) . "<!-- lightboxed players -->\n\n"; |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
function editor_setting( $options ) { |
| 169 |
global $fv_fp; |
| 170 |
$options['general']['items'][] = array( |
| 171 |
'label' => __( 'Lightbox', 'fv-player' ), |
| 172 |
'name' => 'lightbox', |
| 173 |
'description' => __( 'Video will play in a popup box.', 'fv-player' ), |
| 174 |
'dependencies' => array( 'autoplay' => false, 'sticky' => false ), |
| 175 |
'visible' => $fv_fp->_get_option( array('interface','lightbox') ), |
| 176 |
'children' => array( |
| 177 |
array( |
| 178 |
'label' => __( 'Lightbox Title', 'fv-player' ), |
| 179 |
'name' => 'lightbox_caption', |
| 180 |
'description' => __( 'Shows when the lightbox is open.', 'fv-player' ), |
| 181 |
'type' => 'text', |
| 182 |
'visible' => true |
| 183 |
), |
| 184 |
) |
| 185 |
); |
| 186 |
return $options; |
| 187 |
} |
| 188 |
|
| 189 |
/* |
| 190 |
* Controls the stylesheet and script loading |
| 191 |
*/ |
| 192 |
public function enqueue() { |
| 193 |
do_action('fv_player_force_load_lightbox'); |
| 194 |
} |
| 195 |
|
| 196 |
function is_text_lightbox($aArgs) { |
| 197 |
$aLightbox = preg_split('~[;]~', $aArgs['lightbox']); |
| 198 |
|
| 199 |
foreach ($aLightbox AS $k => $i) { |
| 200 |
if ($i == 'text') { |
| 201 |
return true; |
| 202 |
} |
| 203 |
} |
| 204 |
return false; |
| 205 |
} |
| 206 |
|
| 207 |
function lightbox_html($html) { |
| 208 |
|
| 209 |
$aArgs = func_get_args(); |
| 210 |
|
| 211 |
if (isset($aArgs[1]) ) { |
| 212 |
$args = $aArgs[1]->aCurArgs; |
| 213 |
if ( isset($args['lightbox']) && $args['lightbox'] != false && ! get_query_var( 'fv_player_embed' ) && ! get_query_var( 'fv_player_cms_id' ) ) { |
| 214 |
|
| 215 |
$this->bLoad = true; |
| 216 |
|
| 217 |
global $fv_fp; |
| 218 |
|
| 219 |
$iConfWidth = intval($fv_fp->_get_option('width')); |
| 220 |
$iConfHeight = intval($fv_fp->_get_option('height')); |
| 221 |
|
| 222 |
$iPlayerWidth = ( isset($args['width']) && intval($args['width']) > 0 ) ? intval($args['width']) : $iConfWidth; |
| 223 |
$iPlayerHeight = ( isset($args['height']) && intval($args['height']) > 0 ) ? intval($args['height']) : $iConfHeight; |
| 224 |
|
| 225 |
/* |
| 226 |
* Going back to the oldschool days... |
| 227 |
* The possibilities here are: |
| 228 |
* |
| 229 |
* true |
| 230 |
* true;text |
| 231 |
* true;Lightbox title |
| 232 |
* true;640;360;Lightbox title |
| 233 |
*/ |
| 234 |
$aLightbox = preg_split('~[;]~', $args['lightbox']); |
| 235 |
|
| 236 |
// Properties set up by FV Player DB |
| 237 |
if( !empty($args['lightbox_width']) ) { |
| 238 |
$aLightbox[1] = $args['lightbox_width']; |
| 239 |
} |
| 240 |
if( !empty($args['lightbox_height']) ) { |
| 241 |
$aLightbox[2] = $args['lightbox_height']; |
| 242 |
} |
| 243 |
if( !empty($args['lightbox_caption']) ) { |
| 244 |
$aLightbox[3] = $args['lightbox_caption']; |
| 245 |
} |
| 246 |
|
| 247 |
$hash = $aArgs[1]->hash; |
| 248 |
$container = "wpfp_".$hash."_container"; |
| 249 |
$button = "fv_flowplayer_".$hash."_lightbox_starter"; |
| 250 |
|
| 251 |
$sTitle = ''; |
| 252 |
|
| 253 |
// Using "text" as in "true;640;360;text" makes it a text lightbox and it should not be used for the lightbox title |
| 254 |
if( !empty($aLightbox[3]) && $aLightbox[3] != 'text' ) { |
| 255 |
$sTitle = $aLightbox[3]; |
| 256 |
|
| 257 |
// If we only have "true;Lightbox title" then we know it's the lightbox title |
| 258 |
} else if( !empty($aLightbox[1]) && !isset($aLightbox[2]) && !isset($aLightbox[3]) && $aLightbox[1] != 'text' ) { |
| 259 |
$sTitle = $aLightbox[1]; |
| 260 |
|
| 261 |
// Allow caption="..." to override the title, some users use that still |
| 262 |
} else if( empty( $args['playlist'] ) && ! empty( $args['caption'] ) ) { |
| 263 |
$sTitle = wp_kses_post( $args['caption'] ); |
| 264 |
|
| 265 |
} else if( empty( $args['playlist'] ) && ! empty( $args['title'] ) ) { |
| 266 |
$sTitle = wp_kses_post( $args['title'] ); |
| 267 |
|
| 268 |
} |
| 269 |
|
| 270 |
$title_attribute = ! empty( $sTitle ) ? " title='" . esc_attr( $sTitle ) . "'" : ''; |
| 271 |
|
| 272 |
// Allow scripts for the lightboxed HTML for playlist sizing |
| 273 |
add_filter( 'wp_kses_allowed_html', array( $fv_fp, 'wp_kses_permit_scripts' ), 999, 2 ); |
| 274 |
|
| 275 |
// The original player HTML markup becomes the hidden lightbox content |
| 276 |
// We add the lightboxed class |
| 277 |
$lightbox = str_replace(array('class="freedomplayer ', "class='freedomplayer "), array('class="freedomplayer lightboxed ', "class='freedomplayer lightboxed "), $html); |
| 278 |
// ...and wrap it in hidden DIV |
| 279 |
$lightbox = "\n".'<div id="'.$container.'" class="fv_player_lightbox_hidden" style="display: none">'."\n" . wp_kses_post( $lightbox ) . "</div>\n"; |
| 280 |
|
| 281 |
remove_filter( 'wp_kses_allowed_html', array( $fv_fp, 'wp_kses_permit_scripts' ), 999, 2 ); |
| 282 |
|
| 283 |
if ( $this->is_text_lightbox($args) ) { |
| 284 |
if( !empty($args['playlist']) ) { |
| 285 |
list( $playlist_items_external_html, $aPlaylistItems, $aSplashScreens, $aCaptions ) = $fv_fp->build_playlist( $args, $args['src'], $args['src1'], $args['src2'], false, false ); |
| 286 |
if( is_array($aCaptions) ) { |
| 287 |
$html = '<ul class="fv-player-lightbox-text-playlist" rel="'.$container.'">'; |
| 288 |
foreach( $aCaptions AS $key => $caption ) { |
| 289 |
$html .= '<li><a'; |
| 290 |
// we only add the fancyBox attributes for the first link as having multiple links for one fancyBox view causes issues, we handle the clicks in JS |
| 291 |
if( $key == 0 ) { |
| 292 |
$html .= $this->fancybox_opts().' href="#'.$container.'"'; |
| 293 |
} else { |
| 294 |
$html .= ' href="#"'; |
| 295 |
} |
| 296 |
$html .= ' class="fv-player-lightbox-link" title="'.esc_attr($caption).'">'.$caption.'</li>'; |
| 297 |
} |
| 298 |
$html .= '</ul>'; |
| 299 |
} |
| 300 |
} else { |
| 301 |
$html = '<a'.$this->fancybox_opts().' id="'.$button.'"' . $title_attribute . ' class="fv-player-lightbox-link" href="#" data-src="#'.$container.'">' . $sTitle . '</a>'; |
| 302 |
} |
| 303 |
|
| 304 |
// in this case we put the lightboxed player into footer as putting it behind the anchor might break the parent block element |
| 305 |
$this->lightboxHtml .= $lightbox; |
| 306 |
|
| 307 |
} else { |
| 308 |
$iWidth = ( isset($aLightbox[1]) && intval($aLightbox[1]) > 0 ) ? intval($aLightbox[1]) : ( ($iPlayerWidth > $iConfWidth) ? $iPlayerWidth : $iConfWidth ); |
| 309 |
$iHeight = ( isset($aLightbox[2]) && intval($aLightbox[2]) > 0 ) ? intval($aLightbox[2]) : ( ($iPlayerHeight > $iConfHeight) ? $iPlayerHeight : $iConfHeight ); |
| 310 |
|
| 311 |
// new classes to be added |
| 312 |
$add_classes = array( 'lightbox-starter' ); |
| 313 |
|
| 314 |
// use the align for the lightbox button |
| 315 |
if( isset($args['lightbox_align']) ) { |
| 316 |
$add_classes[] = 'align' . $args['lightbox_align']; |
| 317 |
} |
| 318 |
|
| 319 |
$sSplash = apply_filters('fv_flowplayer_playlist_splash', $args['splash'], $args['src']); |
| 320 |
|
| 321 |
// re-use the existing player HTML and add data-fancybox, data-options, new id and href |
| 322 |
$html = str_replace( '<div id="wpfp_'.$hash.'" ', '<div'.$this->fancybox_opts($sSplash).' id="'.$button.'"' . $title_attribute . ' href="#'.$container.'" ', $html ); |
| 323 |
|
| 324 |
// add all the new classes |
| 325 |
$html = str_replace( 'class="freedomplayer ', 'class="freedomplayer ' . implode(' ', $add_classes ). ' ' , $html ); |
| 326 |
|
| 327 |
// use new size |
| 328 |
$html = str_replace( array( "max-width: ".$iPlayerWidth."px", "max-height: ".$iPlayerHeight."px"), array('max-width: '.$iWidth.'px', 'max-height: '.$iHeight.'px'), $html ); |
| 329 |
|
| 330 |
// Only use new ratio for responsiveness if the lightbox size is specified |
| 331 |
$have_custom_size = ! empty( $aLightbox[1] ) || ! empty( $aLightbox[2] ); |
| 332 |
|
| 333 |
if ( $have_custom_size ) { |
| 334 |
$ratio = $iHeight / $iWidth; |
| 335 |
if( $ratio > 0 ) { |
| 336 |
$ratio = round($ratio, 4); |
| 337 |
$html = preg_replace( '~ data-ratio=".*?"~', ' data-ratio="'.$ratio.'"', $html ); |
| 338 |
|
| 339 |
$ratio = str_replace(',','.', $ratio * 100 ); |
| 340 |
$html = preg_replace( '~<div class="fp-ratio".*?</div>~', '<div class="fp-ratio" style="padding-top: '.$ratio.'%"></div>', $html ); |
| 341 |
} |
| 342 |
} |
| 343 |
|
| 344 |
// this is how we link playlist items to the player |
| 345 |
$html = str_replace( ' rel="wpfp_'.$hash.'"', ' rel="'.$button.'"', $html ); |
| 346 |
|
| 347 |
// we removed FV Player data to make sure it won't initialize here |
| 348 |
$html = preg_replace( "~ data-item='.*?'~", '', $html ); |
| 349 |
$html = preg_replace( '~ data-item=".*?"~', '', $html ); |
| 350 |
|
| 351 |
// put the hidden player after our lightbox button |
| 352 |
$html .= $lightbox; |
| 353 |
} |
| 354 |
} |
| 355 |
} |
| 356 |
return $html; |
| 357 |
} |
| 358 |
|
| 359 |
/* |
| 360 |
* Load the scripts and stylesheets |
| 361 |
*/ |
| 362 |
function load_scripts() { |
| 363 |
global $fv_fp, $fv_wp_flowplayer_ver; |
| 364 |
|
| 365 |
$aConf = array(); |
| 366 |
$aConf['lightbox_images'] = $fv_fp->_get_option('lightbox_images'); // should FV Player fancybox be used to show images? |
| 367 |
$aConf['js_url'] = flowplayer::get_plugin_url().'/js/fancybox.js'; |
| 368 |
$aConf['css_url'] = FV_FP_RELATIVE_PATH . '/css/fancybox.css'; |
| 369 |
|
| 370 |
$this->css_enqueue(true); |
| 371 |
|
| 372 |
if ( $fv_fp->_get_option('js-optimize') && ! did_action('fv_player_force_load_lightbox') ) { |
| 373 |
|
| 374 |
$script = " |
| 375 |
( function() { |
| 376 |
let fv_player_fancybox_loaded = false; |
| 377 |
const triggers = document.querySelectorAll( '[data-fancybox], .fp-playlist-external[rel$=_lightbox_starter] a' ); |
| 378 |
for (let i = 0; i < triggers.length; i++) { |
| 379 |
triggers[i].addEventListener( 'click', function( e ) { |
| 380 |
if ( fv_player_fancybox_loaded ) return; |
| 381 |
fv_player_fancybox_loaded = true; |
| 382 |
|
| 383 |
let i = this, |
| 384 |
l = document.createElement('link'), |
| 385 |
s = document.createElement('script'); |
| 386 |
|
| 387 |
e.preventDefault(); |
| 388 |
e.stopPropagation(); |
| 389 |
|
| 390 |
l.rel = 'stylesheet'; |
| 391 |
l.type = 'text/css'; |
| 392 |
l.href = fv_player_lightbox.css_url; |
| 393 |
document.head.appendChild(l); |
| 394 |
|
| 395 |
s.onload = function () { |
| 396 |
let evt = new MouseEvent('click',{bubbles: true,cancelable:true,view:window}); |
| 397 |
i.dispatchEvent(evt); |
| 398 |
}; |
| 399 |
s.src = fv_player_lightbox.js_url; |
| 400 |
document.head.appendChild(s); |
| 401 |
}); |
| 402 |
} |
| 403 |
})(); |
| 404 |
"; |
| 405 |
|
| 406 |
if( !defined('SCRIPT_DEBUG') || !SCRIPT_DEBUG ) { |
| 407 |
// remove /* comments */ |
| 408 |
$script = preg_replace( '~/\*[\s\S]*?\*/~m', '', $script ); |
| 409 |
// remove whitespace |
| 410 |
$script = preg_replace( '~\s+~m', ' ', $script ); |
| 411 |
} |
| 412 |
|
| 413 |
// Load inline JS only, but will this work with WordPress 5.7? |
| 414 |
wp_register_script( 'fv_player_lightbox', '', array( 'jquery') ); |
| 415 |
wp_enqueue_script( 'fv_player_lightbox' ); |
| 416 |
wp_add_inline_script( 'fv_player_lightbox', trim( $script ) ); |
| 417 |
|
| 418 |
} else { |
| 419 |
|
| 420 |
wp_enqueue_script( 'fv_player_lightbox', flowplayer::get_plugin_url().'/js/fancybox.js', 'jquery', $fv_wp_flowplayer_ver, true ); |
| 421 |
} |
| 422 |
|
| 423 |
wp_localize_script( 'fv_player_lightbox', 'fv_player_lightbox', $aConf ); |
| 424 |
} |
| 425 |
|
| 426 |
function html_to_lightbox_videos($content) { |
| 427 |
|
| 428 |
// todo: disabling the option should turn this off |
| 429 |
if (stripos($content, 'colorbox') !== false) { |
| 430 |
$content = preg_replace_callback('~<a[^>]*?class=[\'"][^\'"]*?\bcolorbox\b[^\'"]*?[\'"][^>]*?>([\s\S]*?)</a>~', array($this, 'html_to_lightbox_videos_callback'), $content); |
| 431 |
return $content; |
| 432 |
} |
| 433 |
|
| 434 |
if( stripos($content, 'lightbox') !== false ) { |
| 435 |
$content = preg_replace_callback('~<a[^>]*?class=[\'"][^\'"]*?\blightbox\b[^\'"]*?[\'"][^>]*?>([\s\S]*?)</a>~', array($this, 'html_to_lightbox_videos_callback'), $content); |
| 436 |
return $content; |
| 437 |
} |
| 438 |
|
| 439 |
return $content; |
| 440 |
} |
| 441 |
|
| 442 |
function html_to_lightbox_videos_callback($matches) { |
| 443 |
$html = $matches[0]; |
| 444 |
$caption = trim($matches[1]); |
| 445 |
if( stripos($html,'.mp4') !== false && |
| 446 |
stripos($html,'.webm') !== false && |
| 447 |
stripos($html,'.m4v') !== false && |
| 448 |
stripos($html,'.mov') !== false && |
| 449 |
stripos($html,'.ogv') !== false && |
| 450 |
stripos($html,'.ogg') !== false && |
| 451 |
stripos($html,'.m3u8') !== false && |
| 452 |
stripos($html,'youtube.com/') !== false && |
| 453 |
stripos($html,'youtu.be/') !== false && |
| 454 |
stripos($html,'vimeo.com/') !== false |
| 455 |
) { |
| 456 |
return $html; |
| 457 |
} |
| 458 |
|
| 459 |
if( preg_match( '~href=[\'"](.*?(?:mp4|webm|m4v|mov|ogv|ogg|m3u8|youtube\.com|youtu\.be|vimeo.com).*?)[\'"]~', $html, $href ) ) { |
| 460 |
if( stripos($caption,'<img') === 0 ) { |
| 461 |
return '[fvplayer src="'.esc_attr($href[1]).'" lightbox="true;text" caption_html="'.base64_encode($caption).'"]'; |
| 462 |
} else { |
| 463 |
return '[fvplayer src="'.esc_attr($href[1]).'" lightbox="true;text" caption="'.esc_attr($caption).'"]'; |
| 464 |
} |
| 465 |
} |
| 466 |
|
| 467 |
return $html; |
| 468 |
} |
| 469 |
|
| 470 |
function html_lightbox_images($content) { |
| 471 |
global $fv_fp; |
| 472 |
//TODO IMAGES |
| 473 |
|
| 474 |
if( $fv_fp->_get_option('lightbox_images') === false ) { |
| 475 |
return $content; |
| 476 |
} |
| 477 |
|
| 478 |
// Look for any image links |
| 479 |
$content = preg_replace_callback('~(<a[^>]*?>\s*?)~', array($this, 'html_lightbox_images_callback'), $content, -1, $count ); |
| 480 |
|
| 481 |
if( $count ) { |
| 482 |
$this->bLoad = true; |
| 483 |
} |
| 484 |
|
| 485 |
return $content; |
| 486 |
} |
| 487 |
|
| 488 |
function html_lightbox_images_callback($matches) { |
| 489 |
if( stripos($matches[1],'data-fancybox') ) return $matches[0]; |
| 490 |
|
| 491 |
if (!preg_match('/href=[\'"][^\'"]*?(jpeg|jpg|jpe|gif|png)(?:\?.*?|\s*?)[\'"]/i', $matches[1])) |
| 492 |
return $matches[0]; |
| 493 |
|
| 494 |
$matches[1] = str_replace( '<a ', '<a data-fancybox="gallery" ', $matches[1] ); |
| 495 |
|
| 496 |
return $matches[1]; |
| 497 |
} |
| 498 |
|
| 499 |
function disable_autoplay($aArgs) { |
| 500 |
if (isset($aArgs['lightbox'])) { |
| 501 |
$aArgs['autoplay'] = 'false'; |
| 502 |
} |
| 503 |
return $aArgs; |
| 504 |
} |
| 505 |
|
| 506 |
function lightbox_button_align($aArgs) { |
| 507 |
if (isset($aArgs['lightbox']) && !empty($aArgs['align']) ) { |
| 508 |
$aArgs['lightbox_align'] = $aArgs['align']; // save align to new key |
| 509 |
unset($aArgs['align']); // do not allow the align for lightbox as it doesn't make sense |
| 510 |
} |
| 511 |
return $aArgs; |
| 512 |
} |
| 513 |
|
| 514 |
function lightbox_playlist_style($aArgs) { |
| 515 |
if ( isset( $aArgs['lightbox'] ) && $aArgs['lightbox'] ) { // we force the slider playlist style as that' the only one where the lightbox works properly with the sizing right now |
| 516 |
$aArgs['liststyle'] = 'slider'; |
| 517 |
} |
| 518 |
return $aArgs; |
| 519 |
} |
| 520 |
|
| 521 |
/* |
| 522 |
* Check if scripts and styles is the lightbox is actually used or it scripts are set to load everywhere. Called in FV Player's flowplayer_prepare_scripts() |
| 523 |
*/ |
| 524 |
function maybe_load() { |
| 525 |
global $fv_fp; |
| 526 |
if( |
| 527 |
$this->should_load() || |
| 528 |
$fv_fp->should_force_load_js() || // "Load FV Player JS everywhere" is enabled |
| 529 |
$fv_fp->_get_option('lightbox_force') // "Remove fancyBox" compatibility option is enabled |
| 530 |
) { |
| 531 |
$this->load_scripts(); |
| 532 |
} |
| 533 |
} |
| 534 |
|
| 535 |
function parse_args( $aArgs ) { |
| 536 |
foreach ($aArgs AS $k => $i) { |
| 537 |
if ($i == 'text') { |
| 538 |
unset($aArgs[$k]); |
| 539 |
$bUseAnchor = true; |
| 540 |
} |
| 541 |
} |
| 542 |
return $aArgs; |
| 543 |
} |
| 544 |
|
| 545 |
function parse_html_caption( $aArgs ) { |
| 546 |
if( isset($aArgs['caption_html']) && $aArgs['caption_html'] ) { |
| 547 |
$aArgs['caption'] = base64_decode($aArgs['caption_html']); |
| 548 |
unset($aArgs['caption_html']); |
| 549 |
} |
| 550 |
return $aArgs; |
| 551 |
} |
| 552 |
|
| 553 |
function shortcode_editor() { |
| 554 |
global $fv_fp; |
| 555 |
|
| 556 |
$bLightbox = $fv_fp->_get_option(array('interface','lightbox')); |
| 557 |
|
| 558 |
if ($bLightbox) { |
| 559 |
?> |
| 560 |
<script> |
| 561 |
|
| 562 |
jQuery(document).on('fv_flowplayer_shortcode_parse', function (e, shortcode) { |
| 563 |
var sLightbox = shortcode.match(/lightbox="(.*?)"/); |
| 564 |
if (sLightbox && typeof (sLightbox) != "undefined" && typeof (sLightbox[1]) != "undefined") { |
| 565 |
sLightbox = sLightbox[1]; |
| 566 |
|
| 567 |
if( sLightbox ) { |
| 568 |
var aLightbox = sLightbox.split(/[;]/, 4); |
| 569 |
if (aLightbox.length > 2) { |
| 570 |
for (var i in aLightbox) { |
| 571 |
if (i == 0 && aLightbox[i] == 'true') { |
| 572 |
fv_player_editor.get_field('lightbox').prop('checked', true).trigger('change'); |
| 573 |
} else if (i == 1) { |
| 574 |
// ignore Lightbox Width |
| 575 |
} else if (i == 2) { |
| 576 |
// ignore Lightbox Height |
| 577 |
} else if (i == 3) { |
| 578 |
fv_player_editor.get_field('lightbox_caption').val( aLightbox[i].trim() ).trigger('change'); |
| 579 |
} |
| 580 |
} |
| 581 |
} else { |
| 582 |
if (typeof (aLightbox[0]) != "undefined" && aLightbox[0] == 'true') { |
| 583 |
fv_player_editor.get_field('lightbox').prop('checked', true).trigger('change'); |
| 584 |
} |
| 585 |
if (typeof (aLightbox[1]) != "undefined") { |
| 586 |
fv_player_editor.get_field('lightbox_caption').val( aLightbox[1].trim() ).trigger('change'); |
| 587 |
} |
| 588 |
} |
| 589 |
} |
| 590 |
} |
| 591 |
}); |
| 592 |
</script> |
| 593 |
<?php |
| 594 |
} |
| 595 |
} |
| 596 |
|
| 597 |
function lightbox_admin_integrations_html() { |
| 598 |
global $fv_fp; |
| 599 |
$fv_fp->_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' )); |
| 600 |
} |
| 601 |
|
| 602 |
function lightbox_admin_interface_html() { |
| 603 |
global $fv_fp; |
| 604 |
$fv_fp->_get_checkbox(__( 'Enable video lightbox', 'fv-player' ), array('interface', 'lightbox'), __( 'You can also put in <code><a href="http://path.to.your/video.mp4" class="colorbox">Your link title</a></code> for a quick lightboxed video.', 'fv-player' )); |
| 605 |
} |
| 606 |
|
| 607 |
function lightbox_admin_default_options_html() { |
| 608 |
global $fv_fp; |
| 609 |
?> |
| 610 |
<tr> |
| 611 |
<td style="width: 250px"><label for="lightbox_images"><?php esc_html_e( 'Use video lightbox for images as well', 'fv-player' ); ?>:</label></td> |
| 612 |
<td> |
| 613 |
<p class="description"> |
| 614 |
<input type="hidden" value="false" name="lightbox_images" /> |
| 615 |
<input type="checkbox" value="true" name="lightbox_images" id="lightbox_images" <?php if ($fv_fp->_get_option('lightbox_images')) echo 'checked="checked"'; ?> /> |
| 616 |
<?php echo wp_kses( __( 'Will group images as well as videos into the same lightbox gallery. Turn <strong>off</strong> your lightbox plugin when using this.', 'fv-player' ), array( 'strong' => array() ) ); ?> <span class="more"><?php echo wp_kses( __('Also works with WordPress <code>[gallery]</code> galleries - these are automatically switched to link to image URLs rather than the attachment pages.'), array( 'code' => array() ) ); ?></span> <a href="#" class="show-more">(…)</a> |
| 617 |
</p> |
| 618 |
</td> |
| 619 |
</tr> |
| 620 |
<tr id="lightbox-wp-galleries"> |
| 621 |
<td style="width: 250px"><label for="lightbox_improve_galleries"><?php esc_html_e( 'Use video lightbox for WP Galleries', 'fv-player' ); ?>:</label></td> |
| 622 |
<td> |
| 623 |
<p class="description"> |
| 624 |
<input type="hidden" value="false" name="lightbox_improve_galleries" /> |
| 625 |
<input type="checkbox" value="true" name="lightbox_improve_galleries" id="lightbox_improve_galleries" <?php if ($fv_fp->_get_option('lightbox_improve_galleries')) echo 'checked="checked"'; ?> /> |
| 626 |
<?php esc_html_e( 'Your gallery items will link to image files directly to allow this.', 'fv-player' ); ?> |
| 627 |
</p> |
| 628 |
</td> |
| 629 |
</tr> |
| 630 |
<script> |
| 631 |
jQuery(document).ready(function(){ |
| 632 |
var lightbox_images = jQuery('#lightbox_images'); |
| 633 |
if(lightbox_images.prop('checked')){ |
| 634 |
jQuery('#lightbox-wp-galleries').show(); |
| 635 |
}else{ |
| 636 |
jQuery('#lightbox-wp-galleries').hide(); |
| 637 |
} |
| 638 |
lightbox_images.on('click',function(){ |
| 639 |
if(jQuery(this).prop('checked')){ |
| 640 |
jQuery('#lightbox-wp-galleries').show(); |
| 641 |
}else{ |
| 642 |
jQuery('#lightbox-wp-galleries').hide(); |
| 643 |
} |
| 644 |
}) |
| 645 |
}) |
| 646 |
</script> |
| 647 |
<?php |
| 648 |
} |
| 649 |
|
| 650 |
function fancybox_opts( $splash = false ) { |
| 651 |
$options = array('touch' => false); |
| 652 |
if( !empty($splash) ) $options['thumb'] = $splash; |
| 653 |
return " data-fancybox='gallery' data-options='".wp_json_encode($options)."'"; |
| 654 |
} |
| 655 |
|
| 656 |
/* |
| 657 |
* Was it enqueued with self::enqueue() ? |
| 658 |
*/ |
| 659 |
function should_load() { |
| 660 |
return $this->bLoad || did_action('fv_player_force_load_lightbox'); |
| 661 |
} |
| 662 |
|
| 663 |
} |
| 664 |
|
| 665 |
global $FV_Player_lightbox; |
| 666 |
$FV_Player_lightbox = FV_Player_lightbox::_get_instance(); |
| 667 |
|
| 668 |
function FV_Player_lightbox() { |
| 669 |
return FV_Player_lightbox::_get_instance(); |
| 670 |
} |
| 671 |
|