course
3 years ago
course-add-edd-product-metabox.php
3 years ago
course-add-product-metabox.php
3 years ago
course-additional-data.php
3 years ago
course-contents.php
3 years ago
course-level-metabox.php
3 years ago
course-topics.php
3 years ago
instructors-metabox.php
3 years ago
lesson-attachments-metabox.php
3 years ago
lesson-metabox.php
3 years ago
product-selection.php
3 years ago
settings-tabs.php
3 years ago
user-profile-fields.php
3 years ago
video-metabox.php
3 years ago
video-metabox.php
220 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Video meta box |
| 4 | * |
| 5 | * @package Tutor\Views |
| 6 | * @subpackage Tutor\MetaBox |
| 7 | * @author Themeum <support@themeum.com> |
| 8 | * @link https://themeum.com |
| 9 | * @since 1.0.0 |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * Don't change it, it's supporting modal in other place |
| 14 | * if get_the_ID() empty, then it's means we are passing $post variable from another place |
| 15 | */ |
| 16 | if ( get_the_ID() ) { |
| 17 | global $post; |
| 18 | } |
| 19 | |
| 20 | $video = maybe_unserialize( get_post_meta( $post->ID, '_video', true ) ); |
| 21 | $videoSource = tutor_utils()->avalue_dot( 'source', $video, 'html5' ); |
| 22 | $runtimeHours = tutor_utils()->avalue_dot( 'runtime.hours', $video ); |
| 23 | $runtimeMinutes = tutor_utils()->avalue_dot( 'runtime.minutes', $video ); |
| 24 | $runtimeSeconds = tutor_utils()->avalue_dot( 'runtime.seconds', $video ); |
| 25 | $sourceVideoID = tutor_utils()->avalue_dot( 'source_video_id', $video ); |
| 26 | $poster = tutor_utils()->avalue_dot( 'poster', $video ); |
| 27 | $videoAttachment = $sourceVideoID ? tutor_utils()->get_attachment_data( $sourceVideoID ) : null; |
| 28 | |
| 29 | $video_sources = tutor_utils()->get_video_sources( false ); |
| 30 | |
| 31 | $supported_sources = tutor_utils()->get_option( 'supported_video_sources', array() ); |
| 32 | ! is_array( $supported_sources ) ? $supported_sources = array( $supported_sources ) : 0; |
| 33 | $GLOBALS['supported_sources'] = $supported_sources; |
| 34 | |
| 35 | if ( ! is_array( $supported_sources ) || ! count( $supported_sources ) ) { |
| 36 | $notice = __( 'No video source selected from settings!', 'tutor' ); |
| 37 | ?> |
| 38 | <div class='tutor-alert tutor-warning'> |
| 39 | <div class='tutor-alert-text'> |
| 40 | <span class='tutor-alert-icon tutor-fs-4 tutor-icon-circle-info tutor-mr-12'></span> |
| 41 | <span> |
| 42 | <?php echo esc_html( $notice ); ?> |
| 43 | </span> |
| 44 | </div> |
| 45 | </div> |
| 46 | <?php |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * On course create |
| 52 | * From video source list first item will be selected, When only one video source selected from settings |
| 53 | * |
| 54 | * @since 2.0.6 |
| 55 | */ |
| 56 | if ( is_array( $supported_sources ) && 1 === count( $supported_sources ) && false === $video ) { |
| 57 | $videoSource = $supported_sources[0]; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Should meta box visible or not |
| 62 | * |
| 63 | * @param array $videoSource video source. |
| 64 | * @param array $source source. |
| 65 | * @param boolean $echo should echo. |
| 66 | * @return string |
| 67 | */ |
| 68 | function tutor_video_input_state( $videoSource, $source, $echo = true ) { |
| 69 | $value = ( $videoSource == $source && in_array( $source, $GLOBALS['supported_sources'] ) ) ? 'block' : 'none'; |
| 70 | if ( $echo ) { |
| 71 | echo esc_attr( 'display: ' . $value ); |
| 72 | } else { |
| 73 | return "display: {$value};"; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | ?> |
| 78 | |
| 79 | <div class="tutor-mb-32"> |
| 80 | <label class="tutor-form-label"> |
| 81 | <?php |
| 82 | if ( tutor()->course_post_type === $post->post_type ) { |
| 83 | esc_html_e( 'Course Intro Video', 'tutor' ); |
| 84 | } else { |
| 85 | esc_html_e( 'Video Source', 'tutor' ); |
| 86 | } |
| 87 | ?> |
| 88 | </label> |
| 89 | |
| 90 | <div class="tutor-input-group tutor-mb-16 tutor-mt-12 tutor-d-block"> |
| 91 | <div class="tutor-video-upload-wrap"> |
| 92 | <div class="tutor-dropdown-icon-pack tutor-mt-4" data-video_source="<?php echo esc_attr( empty( $videoSource ) ? '' : $videoSource ); ?>"> |
| 93 | <i class="tutor-icon-brand-html5-bold" data-for="html5"></i> |
| 94 | <i class="tutor-icon-brand-youtube-line" data-for="youtube"></i> |
| 95 | <i class="tutor-icon-brand-vimeo-line" data-for="vimeo"></i> |
| 96 | <i class="tutor-icon-shortcode" data-for="shortcode"></i> |
| 97 | <i class="tutor-icon-link" data-for="external_url"></i> |
| 98 | <i class="tutor-icon-coding" data-for="embedded"></i> |
| 99 | <?php |
| 100 | /** |
| 101 | * Hook added to add external video source icon |
| 102 | * |
| 103 | * @since v2.1.2 |
| 104 | */ |
| 105 | do_action( 'tutor_after_video_source_icon' ); |
| 106 | ?> |
| 107 | </div> |
| 108 | <select name="video[source]" class="tutor-form-control tutor-select-icon-primary tutor_lesson_video_source no-tutor-dropdown"> |
| 109 | <option value="-1"><?php esc_html_e( 'Select Video Source', 'tutor' ); ?></option> |
| 110 | <?php |
| 111 | foreach ( $video_sources as $value => $source ) { |
| 112 | if ( in_array( $value, $supported_sources ) ) { |
| 113 | ?> |
| 114 | <option value="<?php echo esc_attr( $value );?>" <?php selected( $value, $videoSource ); ?> |
| 115 | data-icon="<?php echo wp_kses( $source['icon'], tutor_utils()->allowed_icon_tags() ); ?>"> |
| 116 | <?php echo esc_html( $source['title'] ); ?> |
| 117 | </option> |
| 118 | <?php |
| 119 | } |
| 120 | } |
| 121 | ?> |
| 122 | </select> |
| 123 | |
| 124 | <div class="tutor-mt-16 video-metabox-source-item video_source_wrap_html5 tutor-dashed-uploader <?php echo $sourceVideoID ? 'tutor-has-video' : ''; ?>" style="<?php tutor_video_input_state( $videoSource, 'html5' ); ?>"> |
| 125 | <div class="video-metabox-source-html5-upload"> |
| 126 | <p class="video-upload-icon"><i class="tutor-icon-upload-icon-line"></i></p> |
| 127 | <p><strong><?php esc_html_e( 'Drag & Drop Your Video', 'tutor' ); ?></strong></p> |
| 128 | <p><?php esc_html_e( 'File Format: ', 'tutor' ); ?> <span class="tutor-color-black">.mp4</span></p> |
| 129 | <p class="tutor-color-black"><?php esc_html_e( 'or', 'tutor' ); ?></p> |
| 130 | |
| 131 | <div class="video_source_upload_wrap_html5"> |
| 132 | <button class="video_upload_btn tutor-btn tutor-btn-secondary tutor-btn-md"> |
| 133 | <?php esc_html_e( 'Browse File', 'tutor' ); ?> |
| 134 | </button> |
| 135 | <input type="hidden" class="input_source_video_id" name="video[source_video_id]" value="<?php echo esc_attr( $sourceVideoID ); ?>"> |
| 136 | </div> |
| 137 | </div> |
| 138 | |
| 139 | <div class="html5-video-data"> |
| 140 | <?php |
| 141 | // Load Attachment card segment. |
| 142 | tutor_load_template_from_custom_path( |
| 143 | tutor()->path . '/views/fragments/attachments.php', |
| 144 | array( |
| 145 | 'attachments' => array( |
| 146 | $videoAttachment ? $videoAttachment : (object) array( |
| 147 | 'id' => 0, |
| 148 | 'url' => '', |
| 149 | 'title' => '', |
| 150 | 'size' => '', |
| 151 | ), |
| 152 | ), |
| 153 | 'size_below' => true, |
| 154 | 'no_control' => true, |
| 155 | ), |
| 156 | false |
| 157 | ); |
| 158 | |
| 159 | //phpcs:ignore |
| 160 | echo '<div class="tutor-fs-6 tutor-fw-medium tutor-color-secondary tutor-mb-12" >' . __( 'Upload Video Poster', 'tutor' ) . '</div>'; |
| 161 | // Load thumbnail segment. |
| 162 | tutor_load_template_from_custom_path( |
| 163 | tutor()->path . '/views/fragments/thumbnail-uploader.php', |
| 164 | array( |
| 165 | 'media_id' => tutor_utils()->avalue_dot( 'poster', $video ), |
| 166 | 'input_name' => 'video[poster]', |
| 167 | ), |
| 168 | false |
| 169 | ); |
| 170 | ?> |
| 171 | </div> |
| 172 | </div> |
| 173 | |
| 174 | <div class="tutor-mt-16 video-metabox-source-item video_source_wrap_external_url tutor-dashed-uploader" style="<?php tutor_video_input_state( $videoSource, 'external_url' ); ?>"> |
| 175 | <input class="tutor-form-control" type="text" name="video[source_external_url]" value="<?php echo esc_attr( tutor_utils()->avalue_dot( 'source_external_url', $video ) ); ?>" placeholder="<?php esc_attr_e( 'Paste External Video URL', 'tutor' ); ?>"> |
| 176 | </div> |
| 177 | |
| 178 | <div class="tutor-mt-16 video-metabox-source-item video_source_wrap_shortcode tutor-dashed-uploader" style="<?php tutor_video_input_state( $videoSource, 'shortcode' ); ?>"> |
| 179 | <input class="tutor-form-control" type="text" name="video[source_shortcode]" value="<?php echo esc_attr( tutor_utils()->avalue_dot( 'source_shortcode', $video ) ); ?>" placeholder="<?php esc_attr_e( 'Paste Shortcode', 'tutor' ); ?>"> |
| 180 | </div> |
| 181 | |
| 182 | <div class="tutor-mt-16 video-metabox-source-item video_source_wrap_youtube tutor-dashed-uploader" style="<?php tutor_video_input_state( $videoSource, 'youtube' ); ?>"> |
| 183 | <input class="tutor-form-control" type="text" name="video[source_youtube]" value="<?php echo esc_attr( tutor_utils()->avalue_dot( 'source_youtube', $video ) ); ?>" placeholder="<?php esc_attr_e( 'Paste YouTube Video URL', 'tutor' ); ?>" data-youtube_api_key="<?php echo esc_attr( tutor_utils()->get_option( 'lesson_video_duration_youtube_api_key', '' ) ); ?>"> |
| 184 | </div> |
| 185 | |
| 186 | <div class="tutor-mt-16 video-metabox-source-item video_source_wrap_vimeo tutor-dashed-uploader" style="<?php tutor_video_input_state( $videoSource, 'vimeo' ); ?>"> |
| 187 | <input class="tutor-form-control" type="text" name="video[source_vimeo]" value="<?php echo esc_attr( tutor_utils()->avalue_dot( 'source_vimeo', $video ) ); ?>" placeholder="<?php esc_attr_e( 'Paste Vimeo Video URL', 'tutor' ); ?>"> |
| 188 | </div> |
| 189 | |
| 190 | <div class="tutor-mt-16 video-metabox-source-item video_source_wrap_embedded tutor-dashed-uploader" style="<?php tutor_video_input_state( $videoSource, 'embedded' ); ?>"> |
| 191 | <textarea class="tutor-form-control" name="video[source_embedded]" placeholder="<?php esc_attr_e( 'Place your embedded code here', 'tutor' ); ?>"><?php echo esc_textarea( tutor_utils()->avalue_dot( 'source_embedded', $video ) ); ?></textarea> |
| 192 | </div> |
| 193 | <?php do_action( 'tutor_after_video_meta_box_item', tutor_video_input_state( $videoSource, 'bunnynet', false ), $post ); ?> |
| 194 | </div> |
| 195 | </div> |
| 196 | </div> |
| 197 | |
| 198 | <!-- For Lesson --> |
| 199 | <?php if ( $post->post_type !== tutor()->course_post_type ) : ?> |
| 200 | <div class="tutor-mb-20"> |
| 201 | <label class="tutor-form-label"><?php esc_html_e( 'Video playback time', 'tutor' ); ?></label> |
| 202 | <div class="tutor-input-group tutor-option-field-video-duration"> |
| 203 | <div class="tutor-row"> |
| 204 | <div class="tutor-col-4"> |
| 205 | <input class="tutor-form-control" type="number" value="<?php echo esc_attr( $runtimeHours ? $runtimeHours : '00' ); ?>" name="video[runtime][hours]" min="0"> |
| 206 | <span><?php esc_html_e( 'Hour', 'tutor' ); ?></span> |
| 207 | </div> |
| 208 | <div class="tutor-col-4"> |
| 209 | <input class="tutor-form-control" type="number" class="tutor-number-validation" data-min="0" data-max="59" value="<?php echo esc_attr( $runtimeMinutes ? $runtimeMinutes : '00' ); ?>" name="video[runtime][minutes]" min="0"> |
| 210 | <span><?php esc_html_e( 'Minute', 'tutor' ); ?></span> |
| 211 | </div> |
| 212 | <div class="tutor-col-4"> |
| 213 | <input class="tutor-form-control" type="number" class="tutor-number-validation" data-min="0" data-max="59" value="<?php echo esc_attr( $runtimeSeconds ? $runtimeSeconds : '00' ); ?>" name="video[runtime][seconds]" min="0"> |
| 214 | <span><?php esc_html_e( 'Second', 'tutor' ); ?></span> |
| 215 | </div> |
| 216 | </div> |
| 217 | </div> |
| 218 | </div> |
| 219 | <?php endif; ?> |
| 220 |