2424 */
2525class Flowplayer5_Frontend {
2626
27+ public $ has_flowplayer_video = '' ;
28+ public $ has_flowplayer_shortcode = '' ;
29+
2730 /**
2831 * Initialize the plugin by setting localization, filters, and administration functions.
2932 *
3033 * @since 1.0.0
3134 */
3235 public function __construct () {
3336 global $ flowplayer5_shortcode ;
37+
3438 $ plugin = Flowplayer5::get_instance ();
3539 // Call $plugin_version from public plugin class.
3640 $ this ->plugin_version = $ plugin ->get_plugin_version ();
@@ -57,6 +61,9 @@ public function __construct() {
5761 $ this ->flowplayer5_directory = '//releases.flowplayer.org/ ' . $ this ->player_version . '/ ' . ( $ key ? 'commercial ' : '' );
5862 }
5963
64+ // Start check if posts have videos
65+ add_action ( 'wp_enqueue_scripts ' , array ( $ this , 'has_flowplayer_video ' ) );
66+
6067 // Load public-facing style sheet and JavaScript.
6168 add_action ( 'wp_enqueue_scripts ' , array ( $ this , 'enqueue_styles ' ) );
6269 add_action ( 'wp_enqueue_scripts ' , array ( $ this , 'enqueue_scripts ' ) );
@@ -77,18 +84,16 @@ public function __construct() {
7784 public function enqueue_styles () {
7885
7986 // Pull options
80- $ options = get_option ( 'fp5_settings_general ' );
81- $ asf_css = ( ! empty ( $ options ['asf_css ' ] ) ? $ options ['asf_css ' ] : false );
82- $ has_shortcode = $ this ->has_flowplayer_shortcode ();
83- $ has_video = isset ( $ has_shortcode ) || 'flowplayer5 ' == get_post_type () || is_active_widget ( false , false , 'flowplayer5-video-widget ' , true );
84- $ suffix = defined ( 'SCRIPT_DEBUG ' ) && SCRIPT_DEBUG ? '' : '.min ' ;
87+ $ options = get_option ( 'fp5_settings_general ' );
88+ $ asf_css = ( ! empty ( $ options ['asf_css ' ] ) ? $ options ['asf_css ' ] : false );
89+ $ suffix = defined ( 'SCRIPT_DEBUG ' ) && SCRIPT_DEBUG ? '' : '.min ' ;
8590
8691 wp_register_style ( $ this ->plugin_slug . '-skins ' , trailingslashit ( $ this ->flowplayer5_directory ) . 'skin/all-skins.css ' , array (), $ this ->player_version );
8792 wp_register_style ( $ this ->plugin_slug . '-logo-origin ' , plugins_url ( '/assets/css/public-concat ' . $ suffix . '.css ' , __FILE__ ), array (), $ this ->plugin_version );
8893 wp_register_style ( $ this ->plugin_slug . '-asf ' , esc_url ( $ asf_css ), array (), null );
8994
9095 // Register stylesheets
91- if ( apply_filters ( ' fp5_filter_has_shortcode ' , $ has_video ) ) {
96+ if ( $ this -> has_flowplayer_video ) {
9297 wp_enqueue_style ( $ this ->plugin_slug . '-skins ' );
9398 wp_enqueue_style ( $ this ->plugin_slug . '-logo-origin ' );
9499 if ( $ asf_css ) {
@@ -107,8 +112,6 @@ public function enqueue_scripts() {
107112
108113 $ options = get_option ( 'fp5_settings_general ' );
109114 $ asf_js = ( ! empty ( $ options ['asf_js ' ] ) ? $ options ['asf_js ' ] : false );
110- $ has_shortcode = $ this ->has_flowplayer_shortcode ();
111- $ has_video = isset ( $ has_shortcode ) || 'flowplayer5 ' == get_post_type () || is_active_widget ( false , false , 'flowplayer5-video-widget ' , true );
112115 $ is_multiresolution = $ this ->is_multiresolution ();
113116 $ suffix = defined ( 'SCRIPT_DEBUG ' ) && SCRIPT_DEBUG ? '' : '.min ' ;
114117
@@ -118,7 +121,7 @@ public function enqueue_scripts() {
118121 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 );
119122
120123 // Register JavaScript
121- if ( apply_filters ( ' fp5_filter_has_shortcode ' , $ has_video ) ) {
124+ if ( $ this -> has_flowplayer_video ) {
122125 wp_enqueue_script ( $ this ->plugin_slug . '-script ' );
123126 if ( $ asf_js ) {
124127 wp_enqueue_script ( $ this ->plugin_slug . '-asf ' );
@@ -166,10 +169,10 @@ public function global_config_script() {
166169 $ return .= '<script> ' ;
167170 $ return .= 'flowplayer.conf = { ' ;
168171 $ return .= 'embed: { ' ;
169- $ return .= ( ! empty ( $ embed_library ) ? 'library: " ' . $ embed_library . '", ' : '' );
170- $ return .= ( ! empty ( $ embed_script ) ? 'script: " ' . $ embed_script . '", ' : '' );
171- $ return .= ( ! empty ( $ embed_skin ) ? 'skin: " ' . $ embed_skin . '", ' : '' );
172- $ return .= ( ! empty ( $ embed_swf ) ? 'swf: " ' . $ embed_swf . '" ' : '' );
172+ $ return .= ( ! empty ( $ embed_library ) ? 'library: " ' . esc_js ( $ embed_library ) . '", ' : '' );
173+ $ return .= ( ! empty ( $ embed_script ) ? 'script: " ' . esc_js ( $ embed_script ) . '", ' : '' );
174+ $ return .= ( ! empty ( $ embed_skin ) ? 'skin: " ' . esc_js ( $ embed_skin ) . '", ' : '' );
175+ $ return .= ( ! empty ( $ embed_swf ) ? 'swf: " ' . esc_js ( $ embed_swf ) . '" ' : '' );
173176 $ return .= '} ' ;
174177 $ return .= '}; ' ;
175178 $ return .= '</script> ' ;
@@ -189,36 +192,75 @@ public function global_config_script() {
189192 }
190193
191194 public function has_flowplayer_shortcode () {
192- $ post = get_queried_object ();
193- if ( null !== $ post ) {
195+ if ( is_404 () || ! empty ( $ this ->has_flowplayer_shortcode ) ) {
196+ return ;
197+ }
198+
199+ $ post = get_queried_object ();
200+ $ has_shortcode = array ();
201+ $ shortcode_args = array ();
202+
203+ if ( null !== $ post && is_single () ) {
194204 $ post_content = isset ( $ post ->post_content ) ? $ post ->post_content : '' ;
195- $ has_shortcode [] = fp5_has_shortcode_arg ( $ post_content , 'flowplayer ' );
205+ $ shortcode_args = fp5_has_shortcode_arg ( $ post_content , 'flowplayer ' );
206+ foreach ( $ shortcode_args as $ key => $ value ) {
207+ if ( isset ( $ value ['id ' ] ) ) {
208+ $ has_shortcode [ 'id ' . $ value ['id ' ] ] = $ value ['id ' ];
209+ } elseif ( isset ( $ value ['playlist ' ] ) ) {
210+ $ has_shortcode [ 'playlist ' . $ value ['playlist ' ] ] = $ value ['playlist ' ];
211+ }
212+ }
196213 } else {
197214 global $ wp_query ;
198215 foreach ( $ wp_query ->posts as $ post ) {
199216 $ post_content = isset ( $ post ->post_content ) ? $ post ->post_content : '' ;
200- $ has_shortcode [] = fp5_has_shortcode_arg ( $ post_content , 'flowplayer ' );
217+ $ shortcode_args = fp5_has_shortcode_arg ( $ post_content , 'flowplayer ' );
218+ if ( ! $ shortcode_args ) {
219+ continue ;
220+ }
221+ foreach ( $ shortcode_args as $ key => $ value ) {
222+ if ( isset ( $ value ['id ' ] ) ) {
223+ $ has_shortcode [ 'id ' . $ value ['id ' ] ] = $ value ['id ' ];
224+ } elseif ( isset ( $ value ['playlist ' ] ) ) {
225+ $ has_shortcode [ 'playlist ' . $ value ['playlist ' ] ] = $ value ['playlist ' ];
226+ }
227+ }
201228 }
202229 }
203- $ has_shortcode = iterator_to_array (new RecursiveIteratorIterator (
204- new RecursiveArrayIterator ($ has_shortcode )), FALSE );
205230
206- return array_diff ( $ has_shortcode , array ( false ) );
231+ $ this ->has_flowplayer_shortcode = array_filter ( $ has_shortcode );
232+ }
233+
234+ public function has_flowplayer_video () {
235+ if ( ! empty ( $ this ->has_flowplayer_video ) ){
236+ return ;
237+ }
238+
239+ $ has_video = 'flowplayer5 ' == get_post_type () || is_active_widget ( false , false , 'flowplayer5-video-widget ' , true );
240+ if ( ! $ has_video ) {
241+ $ this ->has_flowplayer_shortcode ();
242+ $ has_video = ! empty ( $ this ->has_flowplayer_shortcode );
243+ }
244+
245+ $ this ->has_flowplayer_video = apply_filters ( 'fp5_filter_has_shortcode ' , $ has_video );
207246 }
208247
209248 public function is_multiresolution () {
210- $ post_id = '' ;
249+ $ post_id = '' ;
211250 $ qualities = array ();
251+
212252 // Check if the post is a flowplayer video
213253 if ( 'flowplayer5 ' == get_post_type () && isset ( $ post ->ID ) ) {
214254 $ post_id = $ post ->ID ;
215255 $ qualities [] = get_post_meta ( $ post_id , 'fp5-qualities ' , true );
216256 return $ qualities ;
217257 }
218258
219- $ shortcode_atts = $ this ->has_flowplayer_shortcode ();
220- foreach ( $ shortcode_atts as $ post_id ) {
221- $ qualities [] = get_post_meta ( $ post_id , 'fp5-qualities ' , true );
259+ $ this ->has_flowplayer_shortcode ();
260+ foreach ( $ this ->has_flowplayer_shortcode as $ key => $ value ) {
261+ if ( 'id ' . $ value === $ key ) {
262+ $ qualities [] = get_post_meta ( $ post_id , 'fp5-qualities ' , true );
263+ }
222264 }
223265
224266 return $ qualities ;
0 commit comments