diff --git a/admin/class-flowplayer5-admin.php b/admin/class-flowplayer5-admin.php index 249d32e..e320918 100644 --- a/admin/class-flowplayer5-admin.php +++ b/admin/class-flowplayer5-admin.php @@ -350,7 +350,7 @@ public function shortcode_row( $column, $post_id ){ switch ( $column ) { case 'shortcode' : - echo '[flowplayer id="' . $post_id . '"]'; + echo '[flowplayer id="' . absint( $post_id ) . '"]'; break; } diff --git a/admin/class-flowplayer5-meta-box.php b/admin/class-flowplayer5-meta-box.php index 31a2e0d..8657855 100644 --- a/admin/class-flowplayer5-meta-box.php +++ b/admin/class-flowplayer5-meta-box.php @@ -137,7 +137,10 @@ public function add_video_meta_box() { public function display_video_meta_box( $post ) { wp_nonce_field( plugin_basename( __FILE__ ), 'fp5-nonce' ); - $fp5_stored_meta = get_post_meta( $post->ID ); + $fp5_stored_meta = wp_parse_args( + get_post_meta( $post->ID ), + apply_filters( 'fp5_post_meta_defaults', array() ) + ); include_once( plugin_dir_path( __FILE__ ) . 'views/display-video-meta-box.php' ); diff --git a/admin/flowplayer-drive/class-flowplayer-drive.php b/admin/flowplayer-drive/class-flowplayer-drive.php index 746006f..e8b0da4 100644 --- a/admin/flowplayer-drive/class-flowplayer-drive.php +++ b/admin/flowplayer-drive/class-flowplayer-drive.php @@ -188,35 +188,37 @@ public function get_videos() { continue; } - $quality = $encoding->height . 'p'; + $quality = $encoding->height . 'p'; + $default_video = true; + $hls = ''; if ( 'mp4' === $encoding->format && 1 < $video->hlsResolutions ) { - // 'example-video-216p.mp4' - '-216p' Exclude default video size - if ( strpos( $encoding->filename, ( '-' . $quality ) ) === false ) { - $default_video = true; - continue; + // 'example-video-216p.mp4' - '-216p' Fetch sizes from non-default sizes + if ( strpos( $encoding->filename, ( '-' . $quality ) ) !== false ) { + $default_video = false; + $qualities[] = $quality; } - $default_video = false; - $qualities[] = $quality; } - if ( ! $default_video ) { + if ( false === $default_video ) { continue; } - if ( 'webm' === $encoding->format ) { - $webm = $encoding->url; - $height = $encoding->height; - $width = $encoding->width; - } elseif ( 'mp4' === $encoding->format ) { - $mp4 = $encoding->url; - $flash = $encoding->filename; - $height = $encoding->height; - $width = $encoding->width; - } elseif ( 'hls' === $encoding->format ) { - $hls = $encoding->url; - } else { - $hls = ''; + switch ( $encoding->format ) { + case 'webm': + $webm = $encoding->url; + $height = $encoding->height; + $width = $encoding->width; + break; + case 'mp4': + $mp4 = $encoding->url; + $flash = $encoding->filename; + $height = $encoding->height; + $width = $encoding->width; + break; + case 'hls': + $hls = $encoding->url; + break; } if ( in_array( $encoding->format, array( 'mp4', 'webm' ) ) ) { @@ -265,12 +267,12 @@ public function get_video_html() { } $return = '
'; - $return .= ''; - $return .= '

' . $video['title'] . '

'; - $return .= '
'; + $return .= ''; + $return .= '

' . esc_html( $video['title'] ) . '

'; + $return .= '
'; $return .= '
'; $return .= $multi_res; - $return .= '' . $video['duration'] . ''; + $return .= '' . esc_attr( $video['duration'] ) . ''; $return .= '
'; $return .= '
'; $return .= '
'; diff --git a/flowplayer.php b/flowplayer.php index a7401e2..5abead8 100644 --- a/flowplayer.php +++ b/flowplayer.php @@ -11,7 +11,7 @@ * Plugin Name: Flowplayer HTML5 for WordPress * Plugin URI: http://wordpress.org/plugins/flowplayer5/ * Description: A HTML5 responsive video player plugin. From the makers of Flowplayer. Includes player skins, tracking with Google Analytics, splash images and support for subtitles and multi-resolution videos. You can use your own watermark logo if you own a Commercial Flowplayer license. - * Version: 1.10.4 + * Version: 1.10.5 * Author: Flowplayer ltd. * Author URI: http://flowplayer.org/ * Text Domain: flowplayer5 diff --git a/frontend/class-flowplayer5-frontend.php b/frontend/class-flowplayer5-frontend.php index edda90f..b3c4703 100644 --- a/frontend/class-flowplayer5-frontend.php +++ b/frontend/class-flowplayer5-frontend.php @@ -24,6 +24,9 @@ */ class Flowplayer5_Frontend { + public $has_flowplayer_video = ''; + public $has_flowplayer_shortcode = ''; + /** * Initialize the plugin by setting localization, filters, and administration functions. * @@ -31,6 +34,7 @@ class Flowplayer5_Frontend { */ public function __construct() { global $flowplayer5_shortcode; + $plugin = Flowplayer5::get_instance(); // Call $plugin_version from public plugin class. $this->plugin_version = $plugin->get_plugin_version(); @@ -57,6 +61,9 @@ public function __construct() { $this->flowplayer5_directory = '//releases.flowplayer.org/' . $this->player_version . '/'. ( $key ? 'commercial' : '' ); } + // Start check if posts have videos + add_action( 'wp_enqueue_scripts', array( $this, 'has_flowplayer_video' ) ); + // Load public-facing style sheet and JavaScript. add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); @@ -77,18 +84,16 @@ public function __construct() { public function enqueue_styles() { // Pull options - $options = get_option( 'fp5_settings_general' ); - $asf_css = ( ! empty ( $options['asf_css'] ) ? $options['asf_css'] : false ); - $has_shortcode = $this->has_flowplayer_shortcode(); - $has_video = isset ( $has_shortcode ) || 'flowplayer5' == get_post_type() || is_active_widget( false, false, 'flowplayer5-video-widget', true ); - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + $options = get_option( 'fp5_settings_general' ); + $asf_css = ( ! empty ( $options['asf_css'] ) ? $options['asf_css'] : false ); + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; wp_register_style( $this->plugin_slug . '-skins', trailingslashit( $this->flowplayer5_directory ) . 'skin/all-skins.css', array(), $this->player_version ); wp_register_style( $this->plugin_slug . '-logo-origin', plugins_url( '/assets/css/public-concat' . $suffix . '.css', __FILE__ ), array(), $this->plugin_version ); wp_register_style( $this->plugin_slug . '-asf', esc_url( $asf_css ), array(), null ); // Register stylesheets - if ( apply_filters( 'fp5_filter_has_shortcode', $has_video ) ) { + if ( $this->has_flowplayer_video ) { wp_enqueue_style( $this->plugin_slug . '-skins' ); wp_enqueue_style( $this->plugin_slug . '-logo-origin' ); if ( $asf_css ) { @@ -107,8 +112,6 @@ public function enqueue_scripts() { $options = get_option( 'fp5_settings_general' ); $asf_js = ( ! empty ( $options['asf_js'] ) ? $options['asf_js'] : false ); - $has_shortcode = $this->has_flowplayer_shortcode(); - $has_video = isset ( $has_shortcode ) || 'flowplayer5' == get_post_type() || is_active_widget( false, false, 'flowplayer5-video-widget', true ); $is_multiresolution = $this->is_multiresolution(); $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; @@ -118,7 +121,7 @@ public function enqueue_scripts() { wp_register_script( $this->plugin_slug . '-quality-selector', plugins_url( '/assets/drive/quality-selector' . $suffix . '.js', __FILE__ ), array( $this->plugin_slug . '-script' ), $this->player_version, false ); // Register JavaScript - if ( apply_filters( 'fp5_filter_has_shortcode', $has_video ) ) { + if ( $this->has_flowplayer_video ) { wp_enqueue_script( $this->plugin_slug . '-script' ); if ( $asf_js ) { wp_enqueue_script( $this->plugin_slug . '-asf' ); @@ -166,10 +169,10 @@ public function global_config_script() { $return .= ''; @@ -189,26 +192,63 @@ public function global_config_script() { } public function has_flowplayer_shortcode() { - $post = get_queried_object(); - if ( null !== $post ) { + if ( is_404() || ! empty( $this->has_flowplayer_shortcode ) ) { + return; + } + + $post = get_queried_object(); + $has_shortcode = array(); + $shortcode_args = array(); + + if ( null !== $post && is_single() ) { $post_content = isset( $post->post_content ) ? $post->post_content : ''; - $has_shortcode[] = fp5_has_shortcode_arg( $post_content, 'flowplayer' ); + $shortcode_args = fp5_has_shortcode_arg( $post_content, 'flowplayer' ); + foreach ( $shortcode_args as $key => $value ) { + if ( isset( $value['id'] ) ) { + $has_shortcode[ 'id' . $value['id'] ] = $value['id']; + } elseif ( isset( $value['playlist'] ) ) { + $has_shortcode[ 'playlist' . $value['playlist'] ] = $value['playlist']; + } + } } else { global $wp_query; foreach ( $wp_query->posts as $post ) { $post_content = isset( $post->post_content ) ? $post->post_content : ''; - $has_shortcode[] = fp5_has_shortcode_arg( $post_content, 'flowplayer' ); + $shortcode_args = fp5_has_shortcode_arg( $post_content, 'flowplayer' ); + if ( ! $shortcode_args ) { + continue; + } + foreach ( $shortcode_args as $key => $value ) { + if ( isset( $value['id'] ) ) { + $has_shortcode[ 'id' . $value['id'] ] = $value['id']; + } elseif ( isset( $value['playlist'] ) ) { + $has_shortcode[ 'playlist' . $value['playlist'] ] = $value['playlist']; + } + } } } - $has_shortcode = iterator_to_array(new RecursiveIteratorIterator( - new RecursiveArrayIterator($has_shortcode)), FALSE); - return array_diff( $has_shortcode, array( false ) ); + $this->has_flowplayer_shortcode = array_filter( $has_shortcode ); + } + + public function has_flowplayer_video() { + if ( ! empty( $this->has_flowplayer_video ) ){ + return; + } + + $has_video = 'flowplayer5' == get_post_type() || is_active_widget( false, false, 'flowplayer5-video-widget', true ); + if ( ! $has_video ) { + $this->has_flowplayer_shortcode(); + $has_video = ! empty ( $this->has_flowplayer_shortcode ); + } + + $this->has_flowplayer_video = apply_filters( 'fp5_filter_has_shortcode', $has_video ); } public function is_multiresolution() { - $post_id = ''; + $post_id = ''; $qualities = array(); + // Check if the post is a flowplayer video if ( 'flowplayer5' == get_post_type() && isset ( $post->ID ) ) { $post_id = $post->ID; @@ -216,9 +256,11 @@ public function is_multiresolution() { return $qualities; } - $shortcode_atts = $this->has_flowplayer_shortcode(); - foreach ( $shortcode_atts as $post_id ) { - $qualities[] = get_post_meta( $post_id, 'fp5-qualities', true ); + $this->has_flowplayer_shortcode(); + foreach ( $this->has_flowplayer_shortcode as $key => $value ) { + if ( 'id' . $value === $key ) { + $qualities[] = get_post_meta( $post_id, 'fp5-qualities', true ); + } } return $qualities; diff --git a/includes/class-flowplayer5.php b/includes/class-flowplayer5.php index 18c5475..7f3f85c 100644 --- a/includes/class-flowplayer5.php +++ b/includes/class-flowplayer5.php @@ -31,7 +31,7 @@ class Flowplayer5 { * * @var string */ - protected $plugin_version = '1.10.4'; + protected $plugin_version = '1.10.5'; /** * Player version, used for cache-busting of style and script file references. diff --git a/readme.txt b/readme.txt index 1bc2024..754219b 100644 --- a/readme.txt +++ b/readme.txt @@ -230,6 +230,16 @@ function fp5_video_config() { add_action( 'fp5_video_config', 'fp5_video_config' );` +`/** + * Define post meta defaults + */ +function fp5_post_meta_defaults( $defaults ) { + $defaults['fp5-no-embed'] = array( 'true' ); + return $defaults; +} +add_filter( 'fp5_post_meta_defaults', 'fp5_post_meta_defaults' );` + + == Screenshots == 1. Posting a video @@ -242,11 +252,16 @@ add_action( 'fp5_video_config', 'fp5_video_config' );` We have a lot of plans for this plugin. You can see some of the up and coming features in the [roadmap](https://github.com/flowplayer/wordpress-flowplayer/issues?labels=enhancement&page=1&state=open) -= 1.10.4 - 3 Febuary 2015 = += 1.10.5 - 1 March 2015 = +* fix bug: playing videos on different pages +* fix bug: fix issue with videos from Flowplayer Drive +* add filter to define new video defaults + += 1.10.4 - 21 February 2015 = * fix bug: play videos when in a blog loop * fix bug: fix issue with loading all of the videos from Flowplayer Drive -= 1.10.3 - 3 Febuary 2015 = += 1.10.3 - 3 February 2015 = * fix bug: fix code Flowplayer Drive API * fix bug: fix issue with Playlist JS @@ -379,6 +394,9 @@ We have a lot of plans for this plugin. You can see some of the up and coming fe == Upgrade Notice == += 1.10.5 = +* fix bugs with Flowplayer Drive and playing videos + = 1.10.4 = * fix bugs with Flowplayer Drive and playing videos on the blog page