.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
require_once dirname( __FILE__ ) . '/../models/fv-player.php';
if (!class_exists('flowplayer_frontend'))
require_once dirname( __FILE__ ) . '/../models/fv-player-frontend.php';
add_shortcode('flowplayer','flowplayer_content_handle');
add_shortcode('fvplayer','flowplayer_content_handle');
add_shortcode('fv_time','fv_player_time');
function flowplayer_content_handle( $atts, $content = null, $tag = false ) {
global $fv_fp;
if( !$fv_fp ) return false;
if( $fv_fp->_get_option('parse_commas') && strcmp($tag,'flowplayer') == 0 ) {
if( !isset( $atts['src'] ) ) {
foreach( $atts AS $key => $att ) {
if( stripos( $att, 'src=' ) !== FALSE ) {
if( stripos( $att, ',' ) === FALSE ) { // if the broken attribute is not using ','
$atts['src'] = preg_replace( '/^\s*?src=[\'"](.*)[\'"].*?$/', '$1', $att );
} else {
$atts['src'] = preg_replace( '/^\s*?src=[\'"](.*)[\'"],\s*?$/', '$1', $att );
}
$i = $key+1;
unset( $atts[$key] ); // = ''; // let's remove it, so it won't confuse the rest of workaaround
}
}
}
if( !isset( $atts['splash'] ) ) {
foreach( $atts AS $key => $att ) {
if( stripos( $att, 'splash=' ) !== FALSE ) {
$atts['splash'] = preg_replace( '/^\s*?splash=[\'"](.*)[\'"],\s*?$/', '$1', $att );
unset( $atts[$key] ); // = ''; // let's remove it, so it won't confuse the rest of workaround
}
}
}
// the popup should really be a content of the shortcode, not an attribute
// this part will fix the popup if there is any single quote in it.
if( !isset( $atts['popup'] ) ) {
$popup = array();
$is_popup = false;
foreach( $atts AS $key => $att ) {
if( !is_numeric( $key ) ) continue;
if( ( stripos( $att, 'popup=' ) !== FALSE || $is_popup ) && stripos( $att, 'src=' ) === FALSE && stripos( $att, 'splash=' ) === FALSE && stripos( $att, 'ad=' ) === FALSE) {
$popup[] = $att;
$is_popup = true;
unset( $atts[$key] ); // = ''; // let's remove it, so it won't confuse the rest of workaround
}
}
$popup = implode( ' ', $popup );
$atts['popup'] = preg_replace( '/^\s*?popup=[\'"](.*)[\'"]\s*?$/mi', '$1', $popup );
}
// same for ad code
if( !isset( $atts['ad'] ) ) {
$ad = array();
$is_ad = false;
foreach( $atts AS $key => $att ) {
if( !is_numeric( $key ) ) continue;
if( ( stripos( $att, 'ad=' ) !== FALSE || $is_ad ) && stripos( $att, 'src=' ) === FALSE && stripos( $att, 'splash=' ) === FALSE && stripos( $att, 'popup=' ) === FALSE) {
$ad[] = $att;
$is_ad = true;
unset( $atts[$key] ); // = ''; // let's remove it, so it won't confuse the rest of workaround
}
}
$ad = implode( ' ', $ad );
$atts['ad'] = preg_replace( '/^\s*?ad=[\'"](.*)[\'"]\s*?$/mi', '$1', $ad );
}
}
$atts = wp_parse_args( $atts, array(
'admin_warning' => '',
'align' => '',
'autoplay' => '',
'caption' => '',
'caption_html' => '',
'controlbar' => '',
'embed' => '',
'end_popup_preview' => '',
'engine' => '',
'height' => '',
'mobile' => '',
'linking' => '',
'liststyle' => '',
'live' => '',
'logo' => '',
'loop' => '',
'overlay' => '',
'overlay_width' => '',
'overlay_height' => '',
'overlay_skip' => '',
'play_button' => '',
'playlist' => '',
'playlist_advance' => '',
'playlist_hide' => '',
'popup' => '',
'post' => '',
'redirect' => '',
'rtmp' => '',
'rtmp_path' => '',
'share' => '',
'skin' => '',
'speed' => '',
'splash' => '',
'splash_text' => '',
'splashend' => '',
'src' => '',
'src1' => '',
'src2' => '',
'sticky' => '',
'subtitles' => '',
'title' => '',
'width' => '',
) );
if( $fv_fp->_get_option('parse_commas') && strcmp($tag,'flowplayer') == 0 ) {
foreach( $atts AS $k => $v ) {
if( in_array($k, array('admin_warning','caption','caption_html','playlist','popup','share') ) ) {
$arguments[$k] = $v;
} else {
$arguments[$k] = preg_replace('/\,/', '', $v);
}
}
} else {
$arguments = $atts;
}
if( ( !isset($arguments['src']) || strlen(trim($arguments['src'])) == 0 ) && isset($arguments['mobile']) && strlen(trim($arguments['mobile'])) ) {
$arguments['src'] = $arguments['mobile'];
unset($arguments['mobile']);
}
$arguments = apply_filters( 'fv_flowplayer_shortcode', $arguments, $fv_fp, $atts );
if( $arguments['post'] == 'this' ) {
$arguments['post'] = get_the_ID();
}
// accepts:
// 1) [fvplayer id="198"] - a DB-based shortcode in the form
// 2) [fvplayer src="198" playlist="198;199;200"] - a front-end user's playlist shortcode that is programatically passed to this method
if( (!empty($arguments['id']) && intval($arguments['id']) > 0) || (!empty($arguments['src']) && is_numeric($arguments['src']) && intval($arguments['src']) > 0) ) {
$new_player = $fv_fp->build_min_player(false, $arguments);
if (!empty($new_player['script'])) {
$GLOBALS['fv_fp_scripts'] = $new_player['script'];
}
if ( $new_player ) {
return $new_player['html'];
} else {
return '';
}
} else if( intval($arguments['post']) > 0 ) {
$objVideoQuery = new WP_Query( array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_parent' => intval($post), 'post_mime_type' => 'video' ) );
if( $objVideoQuery->have_posts() ) {
$sHTML = '';
while( $objVideoQuery->have_posts() ) {
$objVideoQuery->the_post();
$aArgs = $arguments;
$aArgs['src'] = wp_get_attachment_url(get_the_ID());
if( $aSplash = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'large' ) ) {
$aArgs['splash'] = $aSplash[0];
}
if( strlen($aArgs['lightbox']) ) {
$aArgs['lightbox'] .= ';'.html_entity_decode(get_the_title());
}
if( strlen($aArgs['title']) ) {
$aArgs['title'] = apply_filters( 'fv_player_title', $aArgs['title'], false );
}
$new_player = $fv_fp->build_min_player( $aArgs['src'],$aArgs );
if ( $new_player ) {
$sHTML .= $new_player['html'];
}
}
return $sHTML;
}
} else if( $arguments['src'] != '' || ( ( ( strlen($fv_fp->conf['rtmp']) && $fv_fp->conf['rtmp'] != 'false' ) || strlen($arguments['rtmp'])) && strlen($arguments['rtmp_path']) ) ) {
// build new player
$new_player = $fv_fp->build_min_player($arguments['src'],$arguments);
if (!empty($new_player['script'])) {
$GLOBALS['fv_fp_scripts'] = $new_player['script'];
}
if ( $new_player ) {
return $new_player['html'];
} else {
return '';
}
}
return false;
}
add_filter( 'the_content', 'fv_flowplayer_optimizepress', 1 );
function fv_flowplayer_optimizepress( $post_content ) {
if( stripos( $post_content, '[video_player type="url"' ) === false ) {
return $post_content;
}
$post_content = preg_replace_callback( '~\[video_player.*?\].*?\[/video_player\]~', 'fv_flowplayer_optimizepress_bridge', $post_content );
return $post_content;
}
function fv_flowplayer_optimizepress_bridge( $input ) {
$video = $input[0];
$atts = shortcode_parse_atts($video);
$default = array(
'type' => 'embed', // na
'hide_controls' => 'N', // todo
'auto_play' => 'N', // ok
'auto_buffer' => 'N', // todo
'width' => 511, // ok
'height' => 288, // ok
'margin_top' => 0, // todo
'margin_bottom' => 20, // todo
'border_size' => 0, // todo
'border_color' => '#fff', // todo
'placeholder' => '', // ok
'align' => 'center', // ok
'youtube_url' => '', // na
'youtube_auto_play' => 'N', // na
'youtube_hide_controls' => 'N', // na
'youtube_remove_logo' => 'N', // na
'youtube_show_title_bar' => 'N', // na
'youtube_force_hd' => '', // na
'url1' => '', // ok
'url2' => '', // ok
);
$vars = shortcode_atts($default, $atts);
$shortcode = '[fvplayer';
$content = preg_replace( '~\[video_player.*?\](.*?)\[/video_player\]~', '$1', $video );
$content = base64_decode($content);
if(preg_match('|(https?://[^<"]+)|im',$content,$matches)){
$shortcode .= ' src="' . esc_url( $matches[1] ) . '"';
}
$url1 = base64_decode( $vars['url1'] );
if(preg_match('|(https?://[^<"]+)|im',$url1,$matches)){
$shortcode .= ' src1="' . esc_url( $matches[1] ) . '"';
}
$url2 = base64_decode( $vars['url2'] );
if(preg_match('|(https?://[^<"]+)|im',$url2,$matches)){
$shortcode .= ' src2="' . esc_url( $matches[1] ) . '"';
}
if( $vars['placeholder'] ) {
$shortcode .= ' splash="' . esc_url( $vars['placeholder'] ) . '"';
}
if( $vars['auto_play'] == 'Y' ) {
$shortcode .= ' autoplay="true"';
}
$shortcode .= ' width="' . sanitize_key( $vars['width'] ) . '"';
$shortcode .= ' height="' . sanitize_key( $vars['height'] ) . '"';
$shortcode .= ' align="' . sanitize_key( $vars['align'] ) . '"';
if( current_user_can('manage_options') &&
(
( isset($vars['margin-top']) && $vars['margin-top'] > 0 ) ||
( isset($vars['margin-bottom']) && $vars['margin-bottom'] > 0 && $vars['margin-bottom'] != 20 ) ||
( isset($vars['hide_controls']) && $vars['hide_controls'] == 'Y' ) ||
( isset($vars['auto_buffer']) && $vars['auto_buffer'] == 'Y' ) ||
( isset($vars['border_size']) && $vars['border_size'] > 0 ) ||
isset($vars['border_color'])
)
) {
$shortcode .= ' admin_warning="Admin note: Some of the OptimizePress styling parameters are not supported by FV Player. Please visit the settings and set your global appearance preferences there."';
}
$shortcode .= ']';
return $shortcode;
}
function fv_player_time( $args = array() ) {
global $post, $fv_fp;
if( !empty($args['id']) ) {
$player = new FV_Player_Db_Player($args['id']);
if( $player->getIsValid() ) {
foreach( $player->getVideos() AS $video ) {
if( $duration = $video->getDuration() ) {
return flowplayer::format_hms( $duration );
}
}
}
}
if( $post->ID > 0 && isset($fv_fp->aCurArgs['src']) ) {
return flowplayer::get_duration( $post->ID, $fv_fp->aCurArgs['src'] );
} else {
return flowplayer::get_duration_post();
}
}
function fv_player_handle_vimeo_links( $html, $closing = '' ) {
$html = preg_replace( '~~', '[fvplayer src="http://vimeo.com/$1$2"]' . $closing, $html );
return $html;
}
function fv_player_handle_youtube_links( $html, $closing = '' ) {
$html = preg_replace( '~~', '[fvplayer src="http://youtube.com/watch?v=$1"]' . $closing, $html );
return $html;
}
function fv_player_handle_video_tags( $html, $closing = '' ) {
$html = preg_replace( '~
No watched videos.
"; } $video_ids = array_filter( array_keys($videos), 'is_numeric' ); $video_ids = array_map( 'absint', $video_ids ); $placeholder = implode( ', ', array_fill( 0, count( $video_ids ), '%d' ) ); global $wpdb; $videos2durations = $wpdb->get_results( $wpdb->prepare( // $placeholders is a string of %d created above // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared "SELECT v.id AS video_id, vm.meta_value AS duration FROM {$wpdb->prefix}fv_player_videos AS v JOIN {$wpdb->prefix}fv_player_videometa AS vm ON v.id = vm.id_video WHERE v.id IN ({$placeholder}) AND vm.meta_key = 'duration'", $video_ids ) ); $html = "