PluginProbe
FV Player 8 / trunk
FV Player 8 vtrunk
trunk 8.0.18 8.0.19 8.0.20 8.0.21 8.0.25 8.0.27 8.1 8.1.3
fv-player / models / custom-videos.php

custom-videos.php in FV Player 8 trunk, at models/custom-videos.php

908 lines 32.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 class FV_Player_Custom_Videos {
8
9 var $id;
10
11 var $instance_id;
12
13 private $meta;
14
15 private $type;
16
17 public function __construct( $args ) {
18 global $post;
19
20 $args = wp_parse_args( $args, array(
21 'id' => isset($post) && isset($post->ID) ? $post->ID : false,
22 'meta' => '_fv_player_user_video',
23 'type' => isset($post->ID) ? 'post' : 'user'
24 ) );
25
26 $this->id = $args['id'];
27 $this->meta = $args['meta'];
28 $this->type = $args['type'];
29 }
30
31 private function esc_shortcode( $arg ) {
32 $arg = str_replace( array('[',']','"'), array('&#91;','&#93;','&quote;'), $arg );
33 return $arg;
34 }
35
36 public function get_form( $args = array() ) {
37
38 $args = wp_parse_args( $args, array( 'wrapper' => 'div', 'edit' => true, 'limit' => 1000, 'no_form' => false ) );
39
40 $html = '';
41
42 if( $args['wrapper'] != 'li' ) {
43 $html .= '<div class="fv-player-custom-video-list">';
44 }
45
46 if( is_admin() ) {
47 if( $this->have_videos() ) {
48 global $FV_Player_Pro;
49 if( isset($FV_Player_Pro) && $FV_Player_Pro ) {
50 // todo: there should be a better way than this
51 if ( method_exists( $FV_Player_Pro, 'get__cached_splash' ) ) {
52 add_filter( 'fv_flowplayer_splash', array( $FV_Player_Pro, 'get__cached_splash' ) );
53 add_filter( 'fv_flowplayer_playlist_splash', array( $FV_Player_Pro, 'get__cached_splash' ), 10, 3 );
54 }
55
56 if ( method_exists( $FV_Player_Pro, 'youtube_splash' ) ) {
57 add_filter( 'fv_flowplayer_splash', array( $FV_Player_Pro, 'youtube_splash' ) );
58 add_filter( 'fv_flowplayer_playlist_splash', array( $FV_Player_Pro, 'youtube_splash' ), 10, 3 );
59 }
60
61 if ( method_exists( $FV_Player_Pro, 'styles' ) ) {
62 add_action('admin_footer', array( $FV_Player_Pro, 'styles' ) );
63 }
64
65 if ( method_exists( $FV_Player_Pro, 'scripts' ) ) {
66 add_action('admin_footer', array( $FV_Player_Pro, 'scripts' ) ); // todo: not just for FV Player Pro
67 }
68 }
69
70 add_action('admin_footer','flowplayer_prepare_scripts');
71 }
72
73 add_action('admin_footer', array( $this, 'shortcode_editor_load' ), 0 );
74 }
75
76 if( !is_admin() && !$args['no_form'] ) $html .= "<form method='POST'>";
77
78 $html .= $this->get_html( $args );
79
80 $html .= wp_nonce_field( 'fv-player-custom-videos-'.$this->meta.'-'.get_current_user_id(), 'fv-player-custom-videos-'.$this->meta.'-'.get_current_user_id(), true, false );
81
82 if( !is_admin() && !$args['no_form'] ) {
83 $html .= "<input type='hidden' name='action' value='fv-player-custom-videos-save' />";
84 $html .= "<input type='submit' value='Save Videos' />";
85 $html .= "</form>";
86 }
87
88 if( $args['wrapper'] != 'li' ) {
89 $html .= '</div>';
90 }
91
92 return $html;
93 }
94
95 public function get_html_part( $video, $edit = false ) {
96 global $post;
97
98 $defaults = array( 'labels' => array( 'edit' => 'Edit Video', 'remove' => 'Remove Video' ), 'multiple' => true );
99 $args = !empty($post) && !empty( FV_Player_Custom_Videos_Master()->aMetaBoxes[$post->post_type]) ? FV_Player_Custom_Videos_Master()->aMetaBoxes[$post->post_type][$this->meta] : $defaults;
100
101 if( $video ) {
102 $video = wp_kses( $video, 'post' );
103 }
104
105 // exp: what matters here is .fv-player-editor-field and .fv-player-editor-button wrapped in .fv-player-editor-wrapper and .fv-player-editor-preview
106 if( $edit ) {
107 $add_another = $args['multiple'] ? "<button class='button fv-player-editor-more' style='display:none'>Add Another Video</button>" : false;
108
109 $preview = false;
110 $before = 0;
111
112 if( $video ) {
113 global $fv_fp;
114
115 $preview = do_shortcode( str_replace( '[fvplayer ', '[fvplayer autoplay="false" ', $video ) );
116
117 if( $fv_fp->current_player() ) {
118 $before = count($fv_fp->current_player()->getVideos());
119 }
120
121 // Previously we added autoplay="false" to the stored shortcodes by accident, so remove it here
122 $video = str_replace( 'autoplay="false"', '', $video );
123 }
124
125 $html = "<div class='fv-player-editor-wrapper' data-key='fv-player-editor-field-".$this->meta."'>
126 <div class='fv-player-editor-preview'>".$preview."</div>
127 <input class='attachement-shortcode fv-player-editor-field' name='fv_player_videos[".$this->meta."][]' type='hidden' value='".esc_attr($video)."' />
128 <input name='fv_player_videos_before[".$this->meta."][]' type='hidden' value='".$before."' />
129 <div class='edit-video' ".(!$video ? 'style="display:none"' : '').">
130 <button class='button fv-player-editor-button'>".$args['labels']['edit']."</button>
131 <button class='button fv-player-editor-remove'>".$args['labels']['remove']."</button>
132 $add_another
133 </div>
134
135 <div class='add-video' ".($video ? 'style="display:none"' : '').">
136 <button class='button fv-player-editor-button'>Add Video</button>
137 </div>
138 </div>";
139 } else {
140 $html = do_shortcode($video);
141 }
142 return $html;
143 }
144
145 public function get_html( $args = array() ) {
146
147 $args = wp_parse_args( $args, array( 'wrapper' => 'div', 'edit' => false, 'limit' => 1000, 'shortcode' => false ) );
148
149 $html = '';
150 $count = 0;
151 if( $this->have_videos() ) {
152
153 if( $args['wrapper'] ) $html .= '<'.$args['wrapper'].' class="fv-player-custom-video">';
154
155 foreach( $this->get_videos() AS $video ) {
156 $count++;
157 $html .= $this->get_html_part($video, $args['edit']);
158 }
159
160 $html .= '<div style="clear: both"></div>'."\n";
161
162 if( $args['wrapper'] ) $html .= '</'.$args['wrapper'].'>'."\n";
163
164 } else if( $args['edit'] ) {
165 $html .= '<'.$args['wrapper'].' class="fv-player-custom-video">';
166 $html .= $this->get_html_part(false, true);
167 $html .= '<div style="clear: both"></div>'."\n";
168 $html .= '</'.$args['wrapper'].'>';
169 }
170
171 $html .= "<input type='hidden' name='fv-player-custom-videos-entity-id[".$this->meta."]' value='".esc_attr($this->id)."' />";
172 $html .= "<input type='hidden' name='fv-player-custom-videos-entity-type[".$this->meta."]' value='".esc_attr($this->type)."' />";
173
174 return $html;
175 }
176
177 public function get_videos() {
178 if( $this->type == 'user' ) {
179 $aMeta = get_user_meta( $this->id, $this->meta );
180 } else if( $this->type == 'post' ) {
181 $aMeta = get_post_meta( $this->id, $this->meta );
182 }
183
184 $aVideos = array();
185 if( is_array($aMeta) && count($aMeta) > 0 ) {
186 foreach( $aMeta AS $aVideo ) {
187 if( is_array($aVideo) && isset($aVideo['url']) && isset($aVideo['title']) ) {
188 $aVideos[] = '[fvplayer src="'.$this->esc_shortcode($aVideo['url']).'" title="'.$this->esc_shortcode($aVideo['title']).'"]';
189 } else if( is_string($aVideo) && stripos($aVideo,'[fvplayer ') === 0 ) {
190 $aVideos[] = $aVideo;
191 }
192 }
193 }
194
195 return $aVideos;
196 }
197
198 public function have_videos() {
199 return count($this->get_videos()) ? true : false;
200 }
201
202 function shortcode_editor_load() {
203 if( !function_exists('fv_flowplayer_admin_select_popups') ) {
204 fv_wp_flowplayer_edit_form_after_editor();
205 fv_player_shortcode_editor_scripts_enqueue();
206 }
207 }
208
209
210 }
211
212
213
214
215 class FV_Player_Custom_Videos_Master {
216
217 static $instance = null;
218
219 var $aMetaBoxes = array();
220
221 var $aPostListPlayers = array();
222
223 function __construct() {
224
225 if ( ! defined( 'ABSPATH' ) ) {
226 exit;
227 }
228
229 add_action( 'init', array( $this, 'save' ) ); // saving of user profile, both front and back end
230 add_action( 'save_post', array( $this, 'save_post' ) );
231
232 add_filter( 'show_password_fields', array( $this, 'user_profile' ), 10, 2 );
233 add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
234
235 add_filter( 'the_content', array( $this, 'show' ) ); // adding post videos after content automatically
236 add_filter( 'get_the_author_description', array( $this, 'show_bio' ), 10, 2 );
237
238 // EDD
239 add_action('edd_profile_editor_after_email', array($this, 'EDD_profile_editor'));
240 add_action('edd_pre_update_user_profile', array($this, 'save'));
241
242 // bbPress
243 add_action( 'bbp_template_after_user_profile', array( $this, 'bbpress_profile' ), 10 );
244 add_filter( 'bbp_user_edit_after_about', array( $this, 'bbpress_edit' ), 10, 2 );
245
246 // Post list custom columns
247 add_action( 'admin_head-edit.php', array( $this, 'post_list_column_styles' ) );
248 add_action( 'admin_init', array( $this, 'init_post_list_columns' ) );
249 add_action( 'admin_enqueue_scripts', array( $this, 'init_post_list_columns_script' ) );
250 add_filter( 'the_posts', array( $this, 'preload_post_list_players' ) );
251
252 // Admin Columns Pro support
253 /*
254 * That plugin ignores the standard 'manage_'.$post_type.'_columns' hooks
255 * but fortunately we can still add it this way. Then the
256 * 'manage_'.$post_type.'_custom_column' hook works for the column content
257 */
258 add_filter( 'ac/headings', array( $this, 'post_list_column_for_admin_columns_pro' ), 10, 2 );
259 }
260
261 public static function _get_instance() {
262 if( !self::$instance ) {
263 self::$instance = new self();
264 }
265
266 return self::$instance;
267 }
268
269 function add_meta_boxes() {
270 global $post;
271 if ( ! empty( $post->post_type ) && ! empty( $this->aMetaBoxes[ $post->post_type ] ) ) {
272 foreach( $this->aMetaBoxes[$post->post_type] AS $meta_key => $args ) {
273 global $FV_Player_Custom_Videos_form_instances;
274 $id = 'fv_player_custom_videos-field_'.$meta_key;
275 $FV_Player_Custom_Videos_form_instances[$id] = new FV_Player_Custom_Videos( array('id' => $post->ID, 'meta' => $args['meta_key'], 'type' => 'post' ) );
276 add_meta_box( $id,
277 $args['name'],
278 array( $this, 'meta_box' ),
279 null,
280 'normal',
281 'high'
282 );
283 }
284 }
285
286 // todo: following code should not add the meta boxes added by the above again!
287
288 global $fv_fp;
289 if( ! empty( $post->ID ) && isset($fv_fp->conf['profile_videos_enable_bio']) && $fv_fp->conf['profile_videos_enable_bio'] == 'true' ) {
290 $aMeta = get_post_custom($post->ID);
291 if( $aMeta ) {
292 foreach( $aMeta AS $key => $aMetas ) {
293 $objVideos = new FV_Player_Custom_Videos( array('id' => $post->ID, 'meta' => $key, 'type' => 'post' ) );
294 if( $objVideos->have_videos() ) {
295 global $FV_Player_Custom_Videos_form_instances;
296 $id = 'fv_player_custom_videos-field_'.$key;
297 $FV_Player_Custom_Videos_form_instances[$id] = $objVideos;
298 add_meta_box( $id,
299 ucfirst(str_replace( array('_','-'),' ',$key)),
300 array( $this, 'meta_box' ),
301 null,
302 'normal',
303 'high' );
304 }
305
306 }
307 }
308 }
309
310 }
311
312 function bbpress_edit() {
313 global $fv_fp;
314
315 // Match bbpress_profile() / user_profile() — do not expose the editor (or its nonces) unless profile videos are enabled.
316 if ( ! isset( $fv_fp->conf['profile_videos_enable_bio'] ) || $fv_fp->conf['profile_videos_enable_bio'] !== 'true' ) {
317 return;
318 }
319 ?>
320 </fieldset>
321
322 <h2 class="entry-title"><?php esc_attr_e( 'Videos', 'fv-player' ); ?></h2>
323
324 <fieldset class="bbp-form">
325
326 <div>
327 <?php
328 $objVideos = new FV_Player_Custom_Videos(array( 'id' => bbp_get_displayed_user_field('ID'), 'type' => 'user' ));
329
330 global $fv_fp;
331 add_filter( 'wp_kses_allowed_html', array( $fv_fp, 'wp_kses_permit' ), 10, 2 );
332
333 add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses' ) );
334 add_filter( 'safe_style_css', array( $this, 'safe_style_css' ) );
335
336 echo wp_kses_post( $objVideos->get_form( array('no_form' => true) ) );
337
338 remove_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses' ) );
339 remove_filter( 'safe_style_css', array( $this, 'safe_style_css' ) );
340 ?>
341 </div>
342
343 <?php
344
345 if( !function_exists('is_plugin_active') ) include( ABSPATH . 'wp-admin/includes/plugin.php' );
346 if( !function_exists('fv_player_extension_version_is_min') ) include( dirname( __FILE__ ) . '/../controller/backend.php' );
347 if( !function_exists('fv_wp_flowplayer_edit_form_after_editor') ) include( dirname( __FILE__ ) . '/../controller/editor.php' );
348
349 fv_wp_flowplayer_edit_form_after_editor();
350 fv_player_shortcode_editor_scripts_enqueue();
351 }
352
353 function bbpress_profile() {
354 global $fv_fp;
355
356 if( !isset($fv_fp->conf['profile_videos_enable_bio']) || $fv_fp->conf['profile_videos_enable_bio'] !== 'true' )
357 return;
358
359 $objVideos = new FV_Player_Custom_Videos(array( 'id' => bbp_get_displayed_user_field('ID'), 'type' => 'user' ));
360 if( $objVideos->have_videos() ) : ?>
361 <div id="bbp-user-profile" class="bbp-user-profile">
362 <h2 class="entry-title"><?php esc_attr_e( 'Videos', 'bbpress' ); ?></h2>
363 <div class="bbp-user-section">
364
365 <?php
366 global $fv_fp;
367 add_filter( 'wp_kses_allowed_html', array( $fv_fp, 'wp_kses_permit' ), 10, 2 );
368
369 add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses' ) );
370 add_filter( 'safe_style_css', array( $this, 'safe_style_css' ) );
371
372 echo wp_kses_post( $objVideos->get_html() );
373
374 remove_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses' ) );
375 remove_filter( 'safe_style_css', array( $this, 'safe_style_css' ) );
376 ?>
377
378 </div>
379 </div><!-- #bbp-author-topics-started -->
380 <?php endif;
381 }
382
383 function has_post_type( $post_type ) {
384 return !empty( $this->aMetaBoxes[ $post_type ] );
385 }
386
387 // Add post list column for post types which do have a FV Player Video Custom Field
388 function init_post_list_columns() {
389 if( !empty($this->aMetaBoxes) ) {
390 foreach( $this->aMetaBoxes AS $post_type => $boxes ) {
391 if( $post_type == 'post' ) {
392 $post_type = 'posts';
393 } else if( $post_type == 'page' ) {
394 $post_type = 'pages';
395 } else {
396 $post_type = $post_type.'_posts';
397 }
398
399 add_filter( 'manage_'.$post_type.'_columns', array( $this, 'post_list_column' ) );
400 add_filter( 'manage_'.$post_type.'_custom_column', array( $this, 'post_list_column_content' ), 10, 2 );
401 }
402 }
403 }
404
405 function init_post_list_columns_script() {
406 global $current_screen;
407 if( !empty($current_screen->post_type) && $this->has_post_type($current_screen->post_type) ) {
408 fv_player_shortcode_editor_scripts_enqueue();
409
410 // We use 0 priority to ensure both FV Player playback and editor scripts load
411 add_action( 'admin_footer', 'fv_wp_flowplayer_edit_form_after_editor', 0 );
412
413 do_action( 'fvplayer_editor_load' );
414
415 wp_enqueue_media();
416 }
417 }
418
419 function meta_box( $aPosts, $args ) {
420 global $FV_Player_Custom_Videos_form_instances;
421 $objVideos = $FV_Player_Custom_Videos_form_instances[$args['id']];
422
423 global $fv_fp;
424 add_filter( 'wp_kses_allowed_html', array( $fv_fp, 'wp_kses_permit' ), 10, 2 );
425
426 add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses' ) );
427 add_filter( 'safe_style_css', array( $this, 'safe_style_css' ) );
428
429 echo wp_kses_post( $objVideos->get_form() );
430
431 remove_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses' ) );
432 remove_filter( 'safe_style_css', array( $this, 'safe_style_css' ) );
433 }
434
435 function post_list_column( $cols ) {
436 global $current_screen;
437 if( !empty($current_screen->post_type) && $this->has_post_type($current_screen->post_type) ) {
438 foreach( $this->aMetaBoxes[$current_screen->post_type] AS $box ) {
439 $cols = $this->post_list_column_add( $cols, $box );
440 }
441 }
442 return $cols;
443 }
444
445 function post_list_column_add( $cols, $box ) {
446 // Column form player video count
447 $cols[ 'fv-player-video-custom-field-playlist-items-count-'.$box['meta_key'] ] = $box['name'].' playlist videos count';
448
449 // Actual player splash image here
450 $cols[ 'fv-player-video-custom-field-player-'.$box['meta_key'] ] = $box['name'];
451 return $cols;
452 }
453
454 function post_list_column_content( $column_name, $post_id ) {
455 global $current_screen;
456 if( stripos( $column_name, 'fv-player-video-custom-field-' ) === 0 && !empty($current_screen->post_type) && !empty($this->aMetaBoxes[$current_screen->post_type]) ) {
457
458 // TODO: Load the wp-admin -> FV Player styles more sensibly
459 global $fv_wp_flowplayer_ver;
460 wp_enqueue_style('fv-player-list-view', flowplayer::get_plugin_url().'/css/list-view.css',array(), $fv_wp_flowplayer_ver );
461
462 foreach( $this->aMetaBoxes[$current_screen->post_type] AS $box ) {
463 $column_name_sanitized = str_replace( array(
464 'fv-player-video-custom-field-playlist-items-count-',
465 'fv-player-video-custom-field-player-'
466 ), '', $column_name );
467
468 if( $column_name_sanitized == $box['meta_key'] ) {
469 $shortcode = get_post_meta( $post_id, $box['meta_key'], true );
470 $shortcode_atts = shortcode_parse_atts( trim( $shortcode, ']' ) );
471
472 if( !empty($shortcode_atts['id']) ) {
473 $button_text = 'FV Player #'.$shortcode_atts['id'];
474 $video_count = 0;
475
476 // Did we preload the right player?
477 $found = false;
478 foreach( $this->aPostListPlayers AS $objPostPlayer ) {
479 if( $objPostPlayer->id == $shortcode_atts['id'] ) {
480 $button_text = $objPostPlayer->thumbs[0];
481
482 $video_count = count( $objPostPlayer->thumbs );
483 if( $video_count > 1 ) {
484 $video_count .= 'v';
485 } else {
486 $video_count = '';
487 }
488
489 $found = true;
490 break;
491 }
492 }
493
494 // Fallback if it was not preloaded
495 if( !$found ) {
496 global $FV_Player_Db;
497 $objPlayers = $FV_Player_Db->getListPageData( array(
498 'player_id' => $shortcode_atts['id']
499 ) );
500
501 // The above function always gives back the FV Player PHP Players cache, so we need to loop through results
502 foreach( $objPlayers AS $objPlayer ) {
503 if( $objPlayer->id == $shortcode_atts['id'] ) {
504 // Only show the first thumbnail
505 $button_text = $objPlayer->thumbs[0];
506
507 // The above FV_Player_Db::getListPageData() call it supposed to only occur once, it seems $objPlayer->video_objects contains all the videos in cache and that's bad
508 // So we check the HTML :(
509 $video_count = count( $objPlayer->thumbs );
510 if( $video_count > 1 ) {
511 $video_count .= 'v';
512 } else {
513 $video_count = '';
514 }
515
516 $found = true;
517 break;
518 }
519 }
520 }
521
522 if( stripos( $column_name, 'fv-player-video-custom-field-player' ) === 0 ) {
523 echo '<input type="hidden" value="'.esc_attr($shortcode).'" />';
524
525 echo '<a href="#" class="fv-player-edit" data-player_id="' . intval( $shortcode_atts['id'] ) . '">' . wp_kses( $button_text, array(
526 'div' => array(
527 'class' => array(),
528 ),
529 'img' => array(
530 'alt' => array(),
531 'loading' => array(),
532 'src' => array(),
533 'title' => array(),
534 'width' => array(),
535 ),
536 'span' => array()
537 ) ) . '</a>';
538
539 } else if( stripos( $column_name, 'fv-player-video-custom-field-playlist-items-count-' ) === 0 ) {
540 echo esc_html( $video_count );
541 }
542
543 } else if( stripos( $column_name, 'fv-player-video-custom-field-player' ) === 0 ) {
544 echo '<a href="#" class="fv-player-edit" data-post-id="' . intval( $post_id ) . '" data-meta_key="' . esc_attr( $box['meta_key'] ) . '">Add new player</a>';
545
546 }
547 }
548 }
549 }
550 }
551
552 function post_list_column_for_admin_columns_pro( $headings, $list_screen ) {
553 if( method_exists( $list_screen, 'get_post_type' ) ) {
554 if( $post_type = $list_screen->get_post_type() ) {
555 if( $this->has_post_type($post_type) ) {
556 foreach( $this->aMetaBoxes[$post_type] AS $box ) {
557 $headings = $this->post_list_column_add( $headings, $box );
558 }
559 }
560 }
561 }
562 return $headings;
563 }
564
565 function post_list_column_styles() {
566 global $current_screen;
567 if( !empty($current_screen->post_type) && $this->has_post_type($current_screen->post_type) ) {
568 // Set fixed column width to fit the number of videos and hide its label
569 // ..and fixed width for the player splash
570 ?>
571 <style>
572 #fv-player-video-custom-field-playlist-items-count-fv_player, tfoot .column-fv-player-video-custom-field-playlist-items-count-fv_player { text-indent: -9999px; width: 2em }
573 td.column-fv-player-video-custom-field-playlist-items-count-fv_player { padding-left: 0; padding-right: 0 }
574 #fv-player-video-custom-field-player-fv_player { width: 148px; }
575 </style>
576 <?php
577 }
578 }
579
580 /*
581 * The preload might not succeed, for example Admin Columns Pro seems to run WP_Query without the_posts filter
582 */
583 function preload_post_list_players( $posts ) {
584
585 // Only do this once as you never know what plugin might call the_posts filter multiple times
586 static $finished;
587
588 if ( ! empty( $finished ) ) {
589 return $posts;
590 }
591
592 // Are we looking at the wp-admin list of posts?
593 global $current_screen;
594 if( !is_admin() || empty($current_screen->post_type) || 'edit' !== $current_screen->base || !$this->has_post_type($current_screen->post_type) ) {
595 return $posts;
596 }
597
598 $finished = true;
599
600 $players = array();
601 foreach( $posts AS $post ) {
602 if( !empty($this->aMetaBoxes[$post->post_type]) ) {
603 foreach( $this->aMetaBoxes[$post->post_type] AS $box ) {
604
605 // Get shortcode and player ID
606 $shortcode = get_post_meta( $post->ID, $box['meta_key'], true );
607 $shortcode_atts = shortcode_parse_atts( trim( $shortcode, ']' ) );
608 if( !empty($shortcode_atts['id']) ) {
609 $players[] = $shortcode_atts['id'];
610 }
611 }
612 }
613 }
614
615 // Somehow calling it with empty array would pre-load all the players an videos
616 if( count($players) ) {
617 global $FV_Player_Db;
618 $this->aPostListPlayers = $FV_Player_Db->getListPageData( array(
619 'player_id' => $players
620 ) );
621 }
622
623 return $posts;
624 }
625
626 function register_metabox( $args ) {
627 if( !isset($this->aMetaBoxes[$args['post_type']]) ) $this->aMetaBoxes[$args['post_type']] = array();
628
629 $this->aMetaBoxes[$args['post_type']][$args['meta_key']] = $args;
630 }
631
632
633 function save() {
634 if( !isset($_POST['fv_player_videos']) || !isset($_POST['fv-player-custom-videos-entity-type']) || !isset($_POST['fv-player-custom-videos-entity-id']) ) {
635 return;
636 }
637
638 foreach( $_POST['fv_player_videos'] AS $meta => $videos ) {
639 // While it's not ideal that we accept any $meta, we do check for a matching nonce below.
640 $meta = sanitize_text_field( $meta );
641
642 if( !wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['fv-player-custom-videos-'.$meta.'-'.get_current_user_id()] ) ),'fv-player-custom-videos-'.$meta.'-'.get_current_user_id() ) ) {
643 continue;
644 }
645
646 if( sanitize_key( $_POST['fv-player-custom-videos-entity-type'][$meta] ) == 'user' ) {
647 $update_user_id = absint( $_POST['fv-player-custom-videos-entity-id'][$meta] );
648
649 // Do not process if the user is trying to update another user's videos without the edit_user capability
650 if ( $update_user_id != get_current_user_id() && ! current_user_can( 'edit_user', $update_user_id ) ) {
651 continue;
652 }
653
654 delete_user_meta( $update_user_id, $meta );
655
656 foreach( $videos AS $video ) {
657 if( strlen($video) == 0 ) continue;
658
659 // strip html tags to prevent XSS
660 $video = sanitize_text_field( $video );
661
662 // Remove attributes that allow HTML
663 $video = preg_replace( '~\b(ad|popup)\s*?=\s*\\\?\s*?["\'][^"\']*["\']~', '', wp_unslash( $video ) );
664
665 add_user_meta( $update_user_id, $meta, $video );
666 }
667 }
668 }
669 }
670
671 function save_post( $post_id ) {
672 if( !isset($_POST['fv_player_videos']) || !isset($_POST['fv-player-custom-videos-entity-type']) || !isset($_POST['fv-player-custom-videos-entity-id']) ) {
673 return;
674 }
675
676 foreach( $_POST['fv_player_videos'] AS $meta => $value ) {
677 $meta = sanitize_text_field( $meta );
678
679 if( !wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['fv-player-custom-videos-'.$meta.'-'.get_current_user_id()] ) ),'fv-player-custom-videos-'.$meta.'-'.get_current_user_id() ) ) {
680 continue;
681 }
682
683 if( sanitize_key( $_POST['fv-player-custom-videos-entity-type'][$meta] ) == 'post' && absint( $_POST['fv-player-custom-videos-entity-id'][$meta] ) == $post_id ) {
684 delete_post_meta( $post_id, $meta );
685
686 if( is_array($value) && count($value) > 0 ) {
687 foreach( $value AS $k => $v ) {
688 if( strlen($v) == 0 ) continue;
689
690 // strip html tags to prevent XSS
691 $v = sanitize_text_field( $v );
692
693 add_post_meta( $post_id, $meta, $v );
694 }
695 }
696 }
697
698 }
699
700 }
701
702 function show( $content ) {
703 global $post, $fv_fp;
704 if( isset($fv_fp->conf['profile_videos_enable_bio']) && $fv_fp->conf['profile_videos_enable_bio'] == 'true' && isset($post->ID) ) {
705 $aMeta = get_post_custom($post->ID);
706 if( $aMeta ) {
707 foreach( $aMeta AS $key => $aMetas ) {
708 if( !empty($this->aMetaBoxes[$post->post_type][$key]) && $this->aMetaBoxes[$post->post_type][$key]['display'] ) {
709 $objVideos = new FV_Player_Custom_Videos( array('id' => $post->ID, 'meta' => $key, 'type' => 'post' ) );
710 if( $objVideos->have_videos() ) {
711 $content .= $objVideos->get_html();
712 }
713 }
714 }
715 }
716 }
717
718 return $content;
719 }
720
721 function show_bio( $content, $user_id ) {
722 global $fv_fp;
723 if( !is_single() && isset($fv_fp->conf['profile_videos_enable_bio']) && $fv_fp->conf['profile_videos_enable_bio'] == 'true' ) {
724 global $post;
725 $objVideos = new FV_Player_Custom_Videos( array('id' => $user_id, 'type' => 'user' ) );
726 $html = $objVideos->get_html( array( 'wrapper' => false, 'shortcode' => array( 'width' => 272, 'height' => 153 ) ) );
727 if( $html ) {
728 $content .= $html."<div style='clear:both'></div>";
729 }
730 }
731 return $content;
732 }
733
734 function user_profile( $show_password_fields, $profileuser ) {
735 global $fv_fp;
736 if( isset($fv_fp->conf['profile_videos_enable_bio']) && $fv_fp->conf['profile_videos_enable_bio'] == 'true' ) {
737 if( $profileuser->ID > 0 ) {
738 $objUploader = new FV_Player_Custom_Videos( array( 'id' => $profileuser->ID ) );
739 ?>
740 <tr class="user-videos">
741 <th><?php esc_attr_e( 'Videos', 'fv-player' ); ?></th>
742 <td>
743 <?php
744 global $fv_fp;
745 add_filter( 'wp_kses_allowed_html', array( $fv_fp, 'wp_kses_permit' ), 10, 2 );
746
747 add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses' ) );
748 add_filter( 'safe_style_css', array( $this, 'safe_style_css' ) );
749
750 echo wp_kses_post( $objUploader->get_form( array( 'wrapper' => 'div' ) ) );
751
752 remove_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses' ) );
753 remove_filter( 'safe_style_css', array( $this, 'safe_style_css' ) );
754 ?>
755
756 <p class="description"><?php esc_attr_e( 'You can put your Vimeo or YouTube links here.', 'fv-player' ); ?> <abbr title="<?php esc_attr_e( 'These show up as a part of the user bio. Licensed users get FV Player Pro which embeds these video types in FV Player interface without Vimeo or YouTube interface showing up.', 'fv-player' ); ?>"><span class="dashicons dashicons-editor-help"></span></abbr></p>
757 </td>
758 </tr>
759 <?php
760 }
761 }
762
763 return $show_password_fields;
764 }
765
766 public function EDD_profile_editor(){
767 global $fv_fp;
768
769 if( !isset($fv_fp->conf['profile_videos_enable_bio']) || $fv_fp->conf['profile_videos_enable_bio'] !== 'true' )
770 return;
771
772 $user = new FV_Player_Custom_Videos(array( 'id' => get_current_user_id(), 'type' => 'user' ));
773 ?>
774 <p class="edd-profile-videos-label">
775 <span for="edd_email"><?php esc_attr_e( 'Profile Videos', 'fv-player' ); ?></span>
776 <?php
777 global $fv_fp;
778 add_filter( 'wp_kses_allowed_html', array( $fv_fp, 'wp_kses_permit' ), 10, 2 );
779
780 add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses' ) );
781 add_filter( 'safe_style_css', array( $this, 'safe_style_css' ) );
782
783 echo wp_kses_post( $user->get_form(array('no_form' => true)) );
784
785 remove_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses' ) );
786 remove_filter( 'safe_style_css', array( $this, 'safe_style_css' ) );
787 ?>
788 </p>
789 <?php
790
791 if( !function_exists('is_plugin_active') ) include( ABSPATH . 'wp-admin/includes/plugin.php' );
792 if( !function_exists('fv_player_extension_version_is_min') ) include( dirname( __FILE__ ) . '/../controller/backend.php' );
793 if( !function_exists('fv_wp_flowplayer_edit_form_after_editor') ) include( dirname( __FILE__ ) . '/../controller/editor.php' );
794
795 fv_wp_flowplayer_edit_form_after_editor();
796 fv_player_shortcode_editor_scripts_enqueue();
797 }
798
799 // Used to permit FV Player's Custom Video Field markup
800 public function safe_style_css( $styles ) {
801 $styles[] = 'display';
802 return $styles;
803 }
804
805 // Used to permit FV Player's Custom Video Field markup
806 public function wp_kses( $tags ) {
807
808 if ( empty($tags['defs']) ) {
809 $tags['defs'] = array();
810 }
811
812 if ( empty($tags['iframe']) ) {
813 $tags['iframe'] = array();
814 }
815
816 $tags['iframe']['id'] = true;
817 $tags['iframe']['src'] = true;
818 $tags['iframe']['width'] = true;
819 $tags['iframe']['height'] = true;
820 $tags['iframe']['frameborder'] = true;
821 $tags['iframe']['webkitallowfullscreen'] = true;
822 $tags['iframe']['mozallowfullscreen'] = true;
823 $tags['iframe']['allowfullscreen'] = true;
824
825 if ( empty($tags['input']) ) {
826 $tags['input'] = array();
827 }
828
829 $tags['input']['class'] = true;
830 $tags['input']['id'] = true;
831 $tags['input']['name'] = true;
832 $tags['input']['onclick'] = true;
833 $tags['input']['type'] = true;
834 $tags['input']['value'] = true;
835
836 $tags['noscript'] = array();
837
838 if ( empty($tags['path']) ) {
839 $tags['path'] = array();
840 }
841
842 $tags['path']['class'] = true;
843 $tags['path']['d'] = true;
844
845 if ( empty($tags['polygon']) ) {
846 $tags['polygon'] = array();
847 }
848
849 $tags['polygon']['class'] = true;
850 $tags['polygon']['points'] = true;
851 $tags['polygon']['filter'] = true;
852
853 if ( empty($tags['style']) ) {
854 $tags['style'] = array();
855 }
856
857 if ( empty($tags['svg']) ) {
858 $tags['svg'] = array();
859 }
860
861 $tags['svg']['class'] = true;
862 $tags['svg']['viewbox'] = true;
863 $tags['svg']['xmlns'] = true;
864
865 if ( empty($tags['textarea']) ) {
866 $tags['textarea'] = array();
867 }
868
869 $tags['textarea']['onclick'] = true;
870
871 return $tags;
872 }
873
874 }
875
876
877 function FV_Player_Custom_Videos_Master() {
878 return FV_Player_Custom_Videos_Master::_get_instance();
879 }
880
881 FV_Player_Custom_Videos_Master();
882
883
884 class FV_Player_MetaBox {
885
886 function __construct( $args, $meta_key = false, $post_type = false, $display = false ) {
887 if( is_string($args) ) {
888 $args = array(
889 'name' => $args,
890 'meta_key' => $meta_key,
891 'post_type' => $post_type,
892 'display' => $display
893 );
894 }
895
896 $args = wp_parse_args( $args, array(
897 'display' => false,
898 'multiple' => true,
899 'labels' => array(
900 'edit' => 'Edit Video',
901 'remove' => 'Remove Video'
902 ) ) );
903
904 FV_Player_Custom_Videos_Master()->register_metabox($args);
905 }
906
907 }
908