PluginProbe
FV Player 8 / 8.0.21
FV Player 8 v8.0.21
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 8.0.21, at models/custom-videos.php

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