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

891 lines 31.2 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( 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 ?>
314 </fieldset>
315
316 <h2 class="entry-title"><?php esc_attr_e( 'Videos', 'fv-player' ); ?></h2>
317
318 <fieldset class="bbp-form">
319
320 <div>
321 <?php
322 $objVideos = new FV_Player_Custom_Videos(array( 'id' => bbp_get_displayed_user_field('ID'), 'type' => 'user' ));
323
324 global $fv_fp;
325 add_filter( 'wp_kses_allowed_html', array( $fv_fp, 'wp_kses_permit' ), 10, 2 );
326
327 add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses' ) );
328 add_filter( 'safe_style_css', array( $this, 'safe_style_css' ) );
329
330 echo wp_kses_post( $objVideos->get_form( array('no_form' => true) ) );
331
332 remove_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses' ) );
333 remove_filter( 'safe_style_css', array( $this, 'safe_style_css' ) );
334 ?>
335 </div>
336
337 <?php
338
339 if( !function_exists('is_plugin_active') ) include( ABSPATH . 'wp-admin/includes/plugin.php' );
340 if( !function_exists('fv_player_extension_version_is_min') ) include( dirname( __FILE__ ) . '/../controller/backend.php' );
341 if( !function_exists('fv_wp_flowplayer_edit_form_after_editor') ) include( dirname( __FILE__ ) . '/../controller/editor.php' );
342
343 fv_wp_flowplayer_edit_form_after_editor();
344 fv_player_shortcode_editor_scripts_enqueue();
345 }
346
347 function bbpress_profile() {
348 global $fv_fp;
349
350 if( !isset($fv_fp->conf['profile_videos_enable_bio']) || $fv_fp->conf['profile_videos_enable_bio'] !== 'true' )
351 return;
352
353 $objVideos = new FV_Player_Custom_Videos(array( 'id' => bbp_get_displayed_user_field('ID'), 'type' => 'user' ));
354 if( $objVideos->have_videos() ) : ?>
355 <div id="bbp-user-profile" class="bbp-user-profile">
356 <h2 class="entry-title"><?php esc_attr_e( 'Videos', 'bbpress' ); ?></h2>
357 <div class="bbp-user-section">
358
359 <?php
360 global $fv_fp;
361 add_filter( 'wp_kses_allowed_html', array( $fv_fp, 'wp_kses_permit' ), 10, 2 );
362
363 add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses' ) );
364 add_filter( 'safe_style_css', array( $this, 'safe_style_css' ) );
365
366 echo wp_kses_post( $objVideos->get_html() );
367
368 remove_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses' ) );
369 remove_filter( 'safe_style_css', array( $this, 'safe_style_css' ) );
370 ?>
371
372 </div>
373 </div><!-- #bbp-author-topics-started -->
374 <?php endif;
375 }
376
377 function has_post_type( $post_type ) {
378 return !empty( $this->aMetaBoxes[ $post_type ] );
379 }
380
381 // Add post list column for post types which do have a FV Player Video Custom Field
382 function init_post_list_columns() {
383 if( !empty($this->aMetaBoxes) ) {
384 foreach( $this->aMetaBoxes AS $post_type => $boxes ) {
385 if( $post_type == 'post' ) {
386 $post_type = 'posts';
387 } else if( $post_type == 'page' ) {
388 $post_type = 'pages';
389 } else {
390 $post_type = $post_type.'_posts';
391 }
392
393 add_filter( 'manage_'.$post_type.'_columns', array( $this, 'post_list_column' ) );
394 add_filter( 'manage_'.$post_type.'_custom_column', array( $this, 'post_list_column_content' ), 10, 2 );
395 }
396 }
397 }
398
399 function init_post_list_columns_script() {
400 global $current_screen;
401 if( !empty($current_screen->post_type) && $this->has_post_type($current_screen->post_type) ) {
402 fv_player_shortcode_editor_scripts_enqueue();
403
404 // We use 0 priority to ensure both FV Player playback and editor scripts load
405 add_action( 'admin_footer', 'fv_wp_flowplayer_edit_form_after_editor', 0 );
406
407 do_action( 'fvplayer_editor_load' );
408
409 wp_enqueue_media();
410 }
411 }
412
413 function meta_box( $aPosts, $args ) {
414 global $FV_Player_Custom_Videos_form_instances;
415 $objVideos = $FV_Player_Custom_Videos_form_instances[$args['id']];
416
417 global $fv_fp;
418 add_filter( 'wp_kses_allowed_html', array( $fv_fp, 'wp_kses_permit' ), 10, 2 );
419
420 add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses' ) );
421 add_filter( 'safe_style_css', array( $this, 'safe_style_css' ) );
422
423 echo wp_kses_post( $objVideos->get_form() );
424
425 remove_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses' ) );
426 remove_filter( 'safe_style_css', array( $this, 'safe_style_css' ) );
427 }
428
429 function post_list_column( $cols ) {
430 global $current_screen;
431 if( !empty($current_screen->post_type) && $this->has_post_type($current_screen->post_type) ) {
432 foreach( $this->aMetaBoxes[$current_screen->post_type] AS $box ) {
433 $cols = $this->post_list_column_add( $cols, $box );
434 }
435 }
436 return $cols;
437 }
438
439 function post_list_column_add( $cols, $box ) {
440 // Column form player video count
441 $cols[ 'fv-player-video-custom-field-playlist-items-count-'.$box['meta_key'] ] = $box['name'].' playlist videos count';
442
443 // Actual player splash image here
444 $cols[ 'fv-player-video-custom-field-player-'.$box['meta_key'] ] = $box['name'];
445 return $cols;
446 }
447
448 function post_list_column_content( $column_name, $post_id ) {
449 global $current_screen;
450 if( stripos( $column_name, 'fv-player-video-custom-field-' ) === 0 && !empty($current_screen->post_type) && !empty($this->aMetaBoxes[$current_screen->post_type]) ) {
451
452 // TODO: Load the wp-admin -> FV Player styles more sensibly
453 global $fv_wp_flowplayer_ver;
454 wp_enqueue_style('fv-player-list-view', flowplayer::get_plugin_url().'/css/list-view.css',array(), $fv_wp_flowplayer_ver );
455
456 foreach( $this->aMetaBoxes[$current_screen->post_type] AS $box ) {
457 $column_name_sanitized = str_replace( array(
458 'fv-player-video-custom-field-playlist-items-count-',
459 'fv-player-video-custom-field-player-'
460 ), '', $column_name );
461
462 if( $column_name_sanitized == $box['meta_key'] ) {
463 $shortcode = get_post_meta( $post_id, $box['meta_key'], true );
464 $shortcode_atts = shortcode_parse_atts( trim( $shortcode, ']' ) );
465
466 if( !empty($shortcode_atts['id']) ) {
467 $button_text = 'FV Player #'.$shortcode_atts['id'];
468 $video_count = 0;
469
470 // Did we preload the right player?
471 $found = false;
472 foreach( $this->aPostListPlayers AS $objPostPlayer ) {
473 if( $objPostPlayer->id == $shortcode_atts['id'] ) {
474 $button_text = $objPostPlayer->thumbs[0];
475
476 $video_count = count( $objPostPlayer->thumbs );
477 if( $video_count > 1 ) {
478 $video_count .= 'v';
479 } else {
480 $video_count = '';
481 }
482
483 $found = true;
484 break;
485 }
486 }
487
488 // Fallback if it was not preloaded
489 if( !$found ) {
490 global $FV_Player_Db;
491 $objPlayers = $FV_Player_Db->getListPageData( array(
492 'player_id' => $shortcode_atts['id']
493 ) );
494
495 // The above function always gives back the FV Player PHP Players cache, so we need to loop through results
496 foreach( $objPlayers AS $objPlayer ) {
497 if( $objPlayer->id == $shortcode_atts['id'] ) {
498 // Only show the first thumbnail
499 $button_text = $objPlayer->thumbs[0];
500
501 // 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
502 // So we check the HTML :(
503 $video_count = count( $objPlayer->thumbs );
504 if( $video_count > 1 ) {
505 $video_count .= 'v';
506 } else {
507 $video_count = '';
508 }
509
510 $found = true;
511 break;
512 }
513 }
514 }
515
516 if( stripos( $column_name, 'fv-player-video-custom-field-player' ) === 0 ) {
517 echo '<input type="hidden" value="'.esc_attr($shortcode).'" />';
518
519 echo '<a href="#" class="fv-player-edit" data-player_id="' . intval( $shortcode_atts['id'] ) . '">' . wp_kses( $button_text, array(
520 'div' => array(
521 'class' => array(),
522 ),
523 'img' => array(
524 'alt' => array(),
525 'loading' => array(),
526 'src' => array(),
527 'title' => array(),
528 'width' => array(),
529 ),
530 'span' => array()
531 ) ) . '</a>';
532
533 } else if( stripos( $column_name, 'fv-player-video-custom-field-playlist-items-count-' ) === 0 ) {
534 echo esc_html( $video_count );
535 }
536
537 } else if( stripos( $column_name, 'fv-player-video-custom-field-player' ) === 0 ) {
538 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>';
539
540 }
541 }
542 }
543 }
544 }
545
546 function post_list_column_for_admin_columns_pro( $headings, $list_screen ) {
547 if( method_exists( $list_screen, 'get_post_type' ) ) {
548 if( $post_type = $list_screen->get_post_type() ) {
549 if( $this->has_post_type($post_type) ) {
550 foreach( $this->aMetaBoxes[$post_type] AS $box ) {
551 $headings = $this->post_list_column_add( $headings, $box );
552 }
553 }
554 }
555 }
556 return $headings;
557 }
558
559 function post_list_column_styles() {
560 global $current_screen;
561 if( !empty($current_screen->post_type) && $this->has_post_type($current_screen->post_type) ) {
562 // Set fixed column width to fit the number of videos and hide its label
563 // ..and fixed width for the player splash
564 ?>
565 <style>
566 #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 }
567 td.column-fv-player-video-custom-field-playlist-items-count-fv_player { padding-left: 0; padding-right: 0 }
568 #fv-player-video-custom-field-player-fv_player { width: 148px; }
569 </style>
570 <?php
571 }
572 }
573
574 /*
575 * The preload might not succeed, for example Admin Columns Pro seems to run WP_Query without the_posts filter
576 */
577 function preload_post_list_players( $posts ) {
578
579 // Only do this once as you never know what plugin might call the_posts filter multiple times
580 static $finished;
581
582 if ( ! empty( $finished ) ) {
583 return $posts;
584 }
585
586 // Are we looking at the wp-admin list of posts?
587 global $current_screen;
588 if( !is_admin() || empty($current_screen->post_type) || 'edit' !== $current_screen->base || !$this->has_post_type($current_screen->post_type) ) {
589 return $posts;
590 }
591
592 $finished = true;
593
594 $players = array();
595 foreach( $posts AS $post ) {
596 if( !empty($this->aMetaBoxes[$post->post_type]) ) {
597 foreach( $this->aMetaBoxes[$post->post_type] AS $box ) {
598
599 // Get shortcode and player ID
600 $shortcode = get_post_meta( $post->ID, $box['meta_key'], true );
601 $shortcode_atts = shortcode_parse_atts( trim( $shortcode, ']' ) );
602 if( !empty($shortcode_atts['id']) ) {
603 $players[] = $shortcode_atts['id'];
604 }
605 }
606 }
607 }
608
609 // Somehow calling it with empty array would pre-load all the players an videos
610 if( count($players) ) {
611 global $FV_Player_Db;
612 $this->aPostListPlayers = $FV_Player_Db->getListPageData( array(
613 'player_id' => $players
614 ) );
615 }
616
617 return $posts;
618 }
619
620 function register_metabox( $args ) {
621 if( !isset($this->aMetaBoxes[$args['post_type']]) ) $this->aMetaBoxes[$args['post_type']] = array();
622
623 $this->aMetaBoxes[$args['post_type']][$args['meta_key']] = $args;
624 }
625
626
627 function save() {
628 if( !isset($_POST['fv_player_videos']) || !isset($_POST['fv-player-custom-videos-entity-type']) || !isset($_POST['fv-player-custom-videos-entity-id']) ) {
629 return;
630 }
631
632 foreach( $_POST['fv_player_videos'] AS $meta => $videos ) {
633 $meta = sanitize_text_field( $meta );
634
635 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() ) ) {
636 continue;
637 }
638
639 if( sanitize_key( $_POST['fv-player-custom-videos-entity-type'][$meta] ) == 'user' ) {
640 delete_user_meta( absint( $_POST['fv-player-custom-videos-entity-id'][$meta] ), $meta );
641
642 foreach( $videos AS $video ) {
643 if( strlen($video) == 0 ) continue;
644
645 // strip html tags to prevent XSS
646 $video = sanitize_text_field( $video );
647
648 add_user_meta( absint( $_POST['fv-player-custom-videos-entity-id'][$meta] ), $meta, $video );
649 }
650 }
651 }
652 }
653
654 function save_post( $post_id ) {
655 if( !isset($_POST['fv_player_videos']) || !isset($_POST['fv-player-custom-videos-entity-type']) || !isset($_POST['fv-player-custom-videos-entity-id']) ) {
656 return;
657 }
658
659 foreach( $_POST['fv_player_videos'] AS $meta => $value ) {
660 $meta = sanitize_text_field( $meta );
661
662 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() ) ) {
663 continue;
664 }
665
666 if( sanitize_key( $_POST['fv-player-custom-videos-entity-type'][$meta] ) == 'post' && absint( $_POST['fv-player-custom-videos-entity-id'][$meta] ) == $post_id ) {
667 delete_post_meta( $post_id, $meta );
668
669 if( is_array($value) && count($value) > 0 ) {
670 foreach( $value AS $k => $v ) {
671 if( strlen($v) == 0 ) continue;
672
673 // strip html tags to prevent XSS
674 $v = sanitize_text_field( $v );
675
676 add_post_meta( $post_id, $meta, $v );
677 }
678 }
679 }
680
681 }
682
683 }
684
685 function show( $content ) {
686 global $post, $fv_fp;
687 if( isset($fv_fp->conf['profile_videos_enable_bio']) && $fv_fp->conf['profile_videos_enable_bio'] == 'true' && isset($post->ID) ) {
688 $aMeta = get_post_custom($post->ID);
689 if( $aMeta ) {
690 foreach( $aMeta AS $key => $aMetas ) {
691 if( !empty($this->aMetaBoxes[$post->post_type][$key]) && $this->aMetaBoxes[$post->post_type][$key]['display'] ) {
692 $objVideos = new FV_Player_Custom_Videos( array('id' => $post->ID, 'meta' => $key, 'type' => 'post' ) );
693 if( $objVideos->have_videos() ) {
694 $content .= $objVideos->get_html();
695 }
696 }
697 }
698 }
699 }
700
701 return $content;
702 }
703
704 function show_bio( $content, $user_id ) {
705 global $fv_fp;
706 if( !is_single() && isset($fv_fp->conf['profile_videos_enable_bio']) && $fv_fp->conf['profile_videos_enable_bio'] == 'true' ) {
707 global $post;
708 $objVideos = new FV_Player_Custom_Videos( array('id' => $user_id, 'type' => 'user' ) );
709 $html = $objVideos->get_html( array( 'wrapper' => false, 'shortcode' => array( 'width' => 272, 'height' => 153 ) ) );
710 if( $html ) {
711 $content .= $html."<div style='clear:both'></div>";
712 }
713 }
714 return $content;
715 }
716
717 function user_profile( $show_password_fields, $profileuser ) {
718 global $fv_fp;
719 if( isset($fv_fp->conf['profile_videos_enable_bio']) && $fv_fp->conf['profile_videos_enable_bio'] == 'true' ) {
720 if( $profileuser->ID > 0 ) {
721 $objUploader = new FV_Player_Custom_Videos( array( 'id' => $profileuser->ID ) );
722 ?>
723 <tr class="user-videos">
724 <th><?php esc_attr_e( 'Videos', 'fv-player' ); ?></th>
725 <td>
726 <?php
727 global $fv_fp;
728 add_filter( 'wp_kses_allowed_html', array( $fv_fp, 'wp_kses_permit' ), 10, 2 );
729
730 add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses' ) );
731 add_filter( 'safe_style_css', array( $this, 'safe_style_css' ) );
732
733 echo wp_kses_post( $objUploader->get_form( array( 'wrapper' => 'div' ) ) );
734
735 remove_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses' ) );
736 remove_filter( 'safe_style_css', array( $this, 'safe_style_css' ) );
737 ?>
738
739 <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>
740 </td>
741 </tr>
742 <?php
743 }
744 }
745
746 return $show_password_fields;
747 }
748
749 public function EDD_profile_editor(){
750 global $fv_fp;
751
752 if( !isset($fv_fp->conf['profile_videos_enable_bio']) || $fv_fp->conf['profile_videos_enable_bio'] !== 'true' )
753 return;
754
755 $user = new FV_Player_Custom_Videos(array( 'id' => get_current_user_id(), 'type' => 'user' ));
756 ?>
757 <p class="edd-profile-videos-label">
758 <span for="edd_email"><?php esc_attr_e( 'Profile Videos', 'fv-player' ); ?></span>
759 <?php
760 global $fv_fp;
761 add_filter( 'wp_kses_allowed_html', array( $fv_fp, 'wp_kses_permit' ), 10, 2 );
762
763 add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses' ) );
764 add_filter( 'safe_style_css', array( $this, 'safe_style_css' ) );
765
766 echo wp_kses_post( $user->get_form(array('no_form' => true)) );
767
768 remove_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses' ) );
769 remove_filter( 'safe_style_css', array( $this, 'safe_style_css' ) );
770 ?>
771 </p>
772 <?php
773
774 if( !function_exists('is_plugin_active') ) include( ABSPATH . 'wp-admin/includes/plugin.php' );
775 if( !function_exists('fv_player_extension_version_is_min') ) include( dirname( __FILE__ ) . '/../controller/backend.php' );
776 if( !function_exists('fv_wp_flowplayer_edit_form_after_editor') ) include( dirname( __FILE__ ) . '/../controller/editor.php' );
777
778 fv_wp_flowplayer_edit_form_after_editor();
779 fv_player_shortcode_editor_scripts_enqueue();
780 }
781
782 // Used to permit FV Player's Custom Video Field markup
783 public function safe_style_css( $styles ) {
784 $styles[] = 'display';
785 return $styles;
786 }
787
788 // Used to permit FV Player's Custom Video Field markup
789 public function wp_kses( $tags ) {
790
791 if ( empty($tags['defs']) ) {
792 $tags['defs'] = array();
793 }
794
795 if ( empty($tags['iframe']) ) {
796 $tags['iframe'] = array();
797 }
798
799 $tags['iframe']['id'] = true;
800 $tags['iframe']['src'] = true;
801 $tags['iframe']['width'] = true;
802 $tags['iframe']['height'] = true;
803 $tags['iframe']['frameborder'] = true;
804 $tags['iframe']['webkitallowfullscreen'] = true;
805 $tags['iframe']['mozallowfullscreen'] = true;
806 $tags['iframe']['allowfullscreen'] = true;
807
808 if ( empty($tags['input']) ) {
809 $tags['input'] = array();
810 }
811
812 $tags['input']['class'] = true;
813 $tags['input']['id'] = true;
814 $tags['input']['name'] = true;
815 $tags['input']['onclick'] = true;
816 $tags['input']['type'] = true;
817 $tags['input']['value'] = true;
818
819 $tags['noscript'] = array();
820
821 if ( empty($tags['path']) ) {
822 $tags['path'] = array();
823 }
824
825 $tags['path']['class'] = true;
826 $tags['path']['d'] = true;
827
828 if ( empty($tags['polygon']) ) {
829 $tags['polygon'] = array();
830 }
831
832 $tags['polygon']['class'] = true;
833 $tags['polygon']['points'] = true;
834 $tags['polygon']['filter'] = true;
835
836 if ( empty($tags['style']) ) {
837 $tags['style'] = array();
838 }
839
840 if ( empty($tags['svg']) ) {
841 $tags['svg'] = array();
842 }
843
844 $tags['svg']['class'] = true;
845 $tags['svg']['viewbox'] = true;
846 $tags['svg']['xmlns'] = true;
847
848 if ( empty($tags['textarea']) ) {
849 $tags['textarea'] = array();
850 }
851
852 $tags['textarea']['onclick'] = true;
853
854 return $tags;
855 }
856
857 }
858
859
860 function FV_Player_Custom_Videos_Master() {
861 return FV_Player_Custom_Videos_Master::_get_instance();
862 }
863
864 FV_Player_Custom_Videos_Master();
865
866
867 class FV_Player_MetaBox {
868
869 function __construct( $args, $meta_key = false, $post_type = false, $display = false ) {
870 if( is_string($args) ) {
871 $args = array(
872 'name' => $args,
873 'meta_key' => $meta_key,
874 'post_type' => $post_type,
875 'display' => $display
876 );
877 }
878
879 $args = wp_parse_args( $args, array(
880 'display' => false,
881 'multiple' => true,
882 'labels' => array(
883 'edit' => 'Edit Video',
884 'remove' => 'Remove Video'
885 ) ) );
886
887 FV_Player_Custom_Videos_Master()->register_metabox($args);
888 }
889
890 }
891