|
51 | 51 | define( 'ABLEPLAYER_VERSION', '1.2.2' ); |
52 | 52 |
|
53 | 53 | require_once plugin_dir_path( __FILE__ ) . 'inc/settings.php'; |
| 54 | +require_once plugin_dir_path( __FILE__ ) . 'inc/generator.php'; |
54 | 55 | require_once plugin_dir_path( __FILE__ ) . 'inc/kses.php'; |
55 | 56 |
|
56 | 57 | register_activation_hook( __FILE__, 'ableplayer_activation' ); |
|
138 | 139 | function ableplayer_admin_scripts() { |
139 | 140 | $version = ABLEPLAYER_VERSION; |
140 | 141 | $version = ( SCRIPT_DEBUG ) ? $version . '-' . wp_rand( 1000, 9999 ) : $version; |
141 | | - wp_enqueue_script( 'ableplayer-js', plugins_url( '/assets/js/admin.js', __FILE__ ), array( 'jquery' ), $version, true ); |
| 142 | + wp_enqueue_script( 'ableplayer-js', plugins_url( '/assets/js/admin.js', __FILE__ ), array( 'jquery', 'wp-a11y', 'clipboard' ), $version, true ); |
142 | 143 | wp_localize_script( |
143 | 144 | 'ableplayer-js', |
144 | 145 | 'ableplayer', |
145 | 146 | array( |
146 | | - 'firstItem' => 'tab_settings', |
| 147 | + 'posterTitle' => 'Select Poster Image', |
| 148 | + 'sourceTitle' => 'Select Video', |
| 149 | + 'captionsTitle' => 'Select Captions', |
| 150 | + 'subtitlesTitle' => 'Select Subtitles', |
| 151 | + 'descriptionTitle' => 'Select Description', |
| 152 | + 'chaptersTitle' => 'Select Chapters', |
| 153 | + 'buttonName' => 'Choose Media', |
| 154 | + 'thumbHeight' => '100', |
| 155 | + 'removed' => __( 'Selected media removed', 'ableplayer' ), |
| 156 | + 'homeUrl' => home_url(), |
147 | 157 | ) |
148 | 158 | ); |
| 159 | + if ( function_exists( 'wp_enqueue_media' ) && ! did_action( 'wp_enqueue_media' ) ) { |
| 160 | + wp_enqueue_media(); |
| 161 | + } |
149 | 162 | wp_enqueue_style( 'ableplayer', plugins_url( '/assets/css/admin.css', __FILE__ ), array(), $version ); |
150 | 163 | } |
151 | 164 | add_action( 'admin_enqueue_scripts', 'ableplayer_admin_scripts' ); |
|
410 | 423 | 'youtube-nocookie' => '', |
411 | 424 | 'vimeo-id' => '', |
412 | 425 | 'vimeo-desc-id' => '', |
| 426 | + 'media-id' => '', |
| 427 | + 'captions' => '', |
| 428 | + 'subtitles' => '', |
| 429 | + 'descriptions' => '', |
| 430 | + 'chapters' => '', |
413 | 431 | 'autoplay' => 'false', |
414 | 432 | 'preload' => 'metadata', |
415 | 433 | 'loop' => 'false', |
|
430 | 448 | 'ableplayer' |
431 | 449 | ); |
432 | 450 |
|
433 | | - // output. |
434 | | - if ( ! ( $all_atts['youtube-id'] || $all_atts['vimeo-id'] ) ) { |
435 | | - // required fields are missing. |
| 451 | + if ( ! ( $all_atts['youtube-id'] || $all_atts['vimeo-id'] || $all_atts['media-id'] ) ) { |
| 452 | + // Shortcode must have one of YouTube, Vimeo, or local video source. |
436 | 453 | return false; |
437 | 454 | } else { |
| 455 | + if ( $all_atts['media-id'] ) { |
| 456 | + // If Video ID is set but is not a valid URL, |
| 457 | + $media_id = ( is_numeric($all_atts['media-id'] ) ) ? wp_get_attachment_url( $all_atts['media-id'] ) : $all_atts['media-id']; |
| 458 | + if ( ! $media_id ) { |
| 459 | + return false; |
| 460 | + } else { |
| 461 | + $type = get_post_mime_type( $media_id ); |
| 462 | + $source = '<source type="' . esc_attr( $type ) . '" src="' . esc_url( $media_id ) . '">'; |
| 463 | + } |
| 464 | + } |
| 465 | + |
| 466 | + $tracks = array(); |
| 467 | + $kinds = array( |
| 468 | + 'captions' => __( 'Captions', 'ableplayer' ), |
| 469 | + 'subtitles' => __( 'Subtitles', 'ableplayer' ), |
| 470 | + 'description' => __( 'Description', 'ableplayer' ), |
| 471 | + 'chapters' => __( 'Chapters', 'ableplayer' ), |
| 472 | + ); |
| 473 | + // Switch locale to BCP47 syntax. |
| 474 | + $default_lang = str_replace( '_', '-', get_locale() ); |
| 475 | + if ( $all_atts['captions'] || $all_atts['subtitles'] || $all_atts['description'] || $all_atts['chapters'] ) { |
| 476 | + foreach ( $kinds as $kind => $default_label ) { |
| 477 | + $track = ''; |
| 478 | + if ( ! empty( $all_atts[ $kind ] ) ) { |
| 479 | + $data = explode( '|', $all_atts[ $kind ] ); |
| 480 | + if ( empty( $data[0] ) ) { |
| 481 | + continue; |
| 482 | + } |
| 483 | + // Optional lang and language. |
| 484 | + $srclang = ( isset( $data[1] ) && ! empty( $data[1] ) ) ? $data[1] : $default_lang; |
| 485 | + $srclabel = ( isset( $data[2] ) && ! empty( $data[2] ) ) ? $data[2] : $default_label; |
| 486 | + $src = ( is_numeric( $data[0] ) ) ? wp_get_attachment_url( $data[0] ) : $data[0]; |
| 487 | + $track = '<track kind="' . $kind . '" srclang="' . esc_attr( $srclang ) . '" srclabel="' . esc_attr( $srclabel ) . '" src="' . esc_url( $src ) . '">'; |
| 488 | + $tracks[] = $track; |
| 489 | + } |
| 490 | + } |
| 491 | + } |
| 492 | + |
438 | 493 | // build a video player. |
439 | 494 | $o = '<video '; |
440 | 495 | $o .= ' id="' . esc_attr( $all_atts['id'] ) . '"'; |
|
502 | 557 | } |
503 | 558 | $o .= '>'; |
504 | 559 |
|
| 560 | + $o .= $source; |
| 561 | + |
| 562 | + if ( ! empty( $tracks ) ) { |
| 563 | + $o .= implode( PHP_EOL, $tracks ); |
| 564 | + } |
505 | 565 | // enclosing tags. |
506 | 566 | if ( ! is_null( $content ) ) { |
507 | 567 | // run shortcode parser recursively. |
|
0 commit comments