PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 2.6.2
Tutor LMS – eLearning and online course solution v2.6.2
4.0.1 4.0.0 3.9.15 3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.11 1.2.12 1.2.13 1.2.20 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.15 1.9.16 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.4.0 2.5.0 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / classes / Assets.php
tutor / classes Last commit date
Addons.php 2 years ago Admin.php 2 years ago Ajax.php 2 years ago Announcements.php 3 years ago Assets.php 2 years ago Backend_Page_Trait.php 3 years ago Course.php 2 years ago Course_Embed.php 3 years ago Course_Filter.php 2 years ago Course_List.php 2 years ago Course_Settings_Tabs.php 3 years ago Course_Widget.php 3 years ago Custom_Validation.php 3 years ago Dashboard.php 3 years ago FormHandler.php 2 years ago Frontend.php 2 years ago Gutenberg.php 3 years ago Input.php 3 years ago Instructor.php 2 years ago Instructors_List.php 2 years ago Lesson.php 2 years ago Options_V2.php 2 years ago Permalink.php 2 years ago Post_types.php 2 years ago Private_Course_Access.php 3 years ago Q_and_A.php 2 years ago Question_Answers_List.php 3 years ago Quiz.php 2 years ago Quiz_Attempts_List.php 3 years ago RestAPI.php 2 years ago Reviews.php 3 years ago Rewrite_Rules.php 2 years ago Shortcode.php 2 years ago Student.php 2 years ago Students_List.php 3 years ago Taxonomies.php 3 years ago Template.php 3 years ago Theme_Compatibility.php 3 years ago Tools.php 3 years ago Tools_V2.php 3 years ago Tutor.php 2 years ago TutorEDD.php 2 years ago Tutor_Base.php 2 years ago Tutor_Setup.php 2 years ago Upgrader.php 2 years ago User.php 2 years ago Utils.php 2 years ago Video_Stream.php 3 years ago WhatsNew.php 2 years ago Withdraw.php 2 years ago Withdraw_Requests_List.php 3 years ago WooCommerce.php 2 years ago
Assets.php
684 lines
1 <?php
2 /**
3 * Manage Assets
4 *
5 * @package Tutor
6 * @author Themeum <support@themeum.com>
7 * @link https://themeum.com
8 * @since 1.0.0
9 */
10
11 namespace TUTOR;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Assets class
19 *
20 * @since 1.0.0
21 */
22 class Assets {
23
24 /**
25 * Constructor
26 *
27 * @since 1.0.0
28 * @return void
29 */
30 public function __construct() {
31 /**
32 * Common scripts loading
33 */
34 add_action( 'admin_enqueue_scripts', array( $this, 'common_scripts' ) );
35 add_action( 'wp_enqueue_scripts', array( $this, 'common_scripts' ) );
36 /**
37 * Front and backend script enqueue
38 */
39 add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
40 add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
41
42 add_action( 'admin_enqueue_scripts', array( $this, 'load_meta_data' ) );
43 add_action( 'wp_enqueue_scripts', array( $this, 'load_meta_data' ) );
44
45 /**
46 * Text domain loading
47 */
48 add_action( 'admin_enqueue_scripts', array( $this, 'tutor_script_text_domain' ), 100 );
49 add_action( 'wp_enqueue_scripts', array( $this, 'tutor_script_text_domain' ), 100 );
50 add_filter( 'tutor_localize_data', array( $this, 'modify_localize_data' ) );
51
52 /**
53 * Register translatable function to load
54 * Handled script with text domain attached to
55 *
56 * @since 1.9.0
57 */
58 add_action( 'admin_head', array( $this, 'tutor_add_mce_button' ) );
59 add_filter( 'get_the_generator_html', array( $this, 'tutor_generator_tag' ), 10, 2 );
60 add_filter( 'get_the_generator_xhtml', array( $this, 'tutor_generator_tag' ), 10, 2 );
61
62 /**
63 * Add translation support for external tinyMCE button
64 *
65 * @since 1.9.7
66 */
67 add_filter( 'mce_external_languages', array( $this, 'tutor_tinymce_translate' ) );
68
69 /**
70 * Identifier class to body tag
71 *
72 * @since v1.9.9
73 */
74 add_filter( 'body_class', array( $this, 'add_identifier_class_to_body' ) );
75 add_filter( 'admin_body_class', array( $this, 'add_identifier_class_to_body' ) );
76
77 /**
78 * Add edit with front end builder button on Gutenberg editor
79 *
80 * @since v2.0.5
81 */
82 add_action( 'enqueue_block_editor_assets', __CLASS__ . '::add_frontend_editor_button' );
83 }
84
85 /**
86 * Load default localized data
87 *
88 * @since 1.0.0
89 * @return array
90 */
91 private function get_default_localized_data() {
92 $home_url = get_home_url();
93 $parsed = parse_url( $home_url );
94
95 $base_path = ( is_array( $parsed ) && isset( $parsed['path'] ) ) ? $parsed['path'] : '/';
96 $base_path = rtrim( $base_path, '/' ) . '/';
97
98 $post_id = get_the_ID();
99 $post_type = get_post_type( $post_id );
100
101 $current_page = tutor_utils()->get_current_page_slug();
102
103 /**
104 * Only required current user data.
105 *
106 * @since 2.6.2
107 */
108 $current_user = array();
109 $userdata = get_userdata( get_current_user_id() );
110
111 if ( $userdata ) {
112 $current_user = array(
113 'roles' => $userdata->roles,
114 'data' => array(
115 'id' => $userdata->ID,
116 'display_name' => $userdata->display_name,
117 ),
118 );
119 }
120
121 return array(
122 'ajaxurl' => admin_url( 'admin-ajax.php' ),
123 'home_url' => get_home_url(),
124 'site_title' => get_bloginfo( 'title' ),
125 'base_path' => tutor()->basepath,
126 'tutor_url' => tutor()->url,
127 'tutor_pro_url' => function_exists( 'tutor_pro' ) ? tutor_pro()->url : null,
128 'nonce_key' => tutor()->nonce,
129 tutor()->nonce => wp_create_nonce( tutor()->nonce_action ),
130 'loading_icon_url' => get_admin_url() . 'images/wpspin_light.gif',
131 'placeholder_img_src' => tutor_placeholder_img_src(),
132 'enable_lesson_classic_editor' => get_tutor_option( 'enable_lesson_classic_editor' ),
133 'tutor_frontend_dashboard_url' => tutor_utils()->get_tutor_dashboard_page_permalink(),
134 'wp_date_format' => tutor_js_date_format_against_wp(),
135 'is_admin' => is_admin(),
136 'is_admin_bar_showing' => is_admin_bar_showing(),
137 'addons_data' => tutor_utils()->prepare_free_addons_data(),
138 'current_user' => $current_user,
139 'content_change_event' => 'tutor_content_changed_event',
140 'is_tutor_course_edit' => isset( $_GET['action'] ) && 'edit' === $_GET['action'] && tutor()->course_post_type === get_post_type( get_the_ID() ) ? true : false,
141 'assignment_max_file_allowed' => 'tutor_assignments' === $post_type ? (int) tutor_utils()->get_assignment_option( $post_id, 'upload_files_limit' ) : 0,
142 'current_page' => $current_page,
143 'quiz_answer_display_time' => 1000 * (int) tutor_utils()->get_option( 'quiz_answer_display_time' ),
144 'is_ssl' => is_ssl(),
145 'course_list_page_url' => admin_url( 'admin.php?page=tutor' ),
146 'course_post_type' => tutor()->course_post_type,
147 );
148 }
149
150 /**
151 * Enqueue scripts for admin
152 *
153 * @since 1.0.0
154 * @return void
155 */
156 public function admin_scripts() {
157 wp_enqueue_style( 'tutor-select2', tutor()->url . 'assets/packages/select2/select2.min.css', array(), TUTOR_VERSION );
158 wp_enqueue_style( 'tutor-admin', tutor()->url . 'assets/css/tutor-admin.min.css', array(), TUTOR_VERSION );
159 /**
160 * Scripts
161 */
162 wp_enqueue_media();
163
164 wp_enqueue_script( 'wp-color-picker' );
165 wp_enqueue_style( 'wp-color-picker' );
166
167 wp_enqueue_script( 'jquery-ui-slider' );
168 wp_enqueue_script( 'jquery-ui-datepicker' );
169
170 wp_enqueue_script( 'tutor-select2', tutor()->url . 'assets/packages/select2/select2.full.min.js', array( 'jquery' ), TUTOR_VERSION, true );
171 wp_enqueue_script( 'tutor-admin', tutor()->url . 'assets/js/tutor-admin.min.js', array( 'jquery', 'tutor-script', 'wp-color-picker', 'wp-i18n', 'wp-data' ), TUTOR_VERSION, true );
172 }
173
174 /**
175 * Load frontend scripts
176 *
177 * @since 1.0.0
178 * @return void
179 */
180 public function frontend_scripts() {
181 global $post, $wp_query;
182
183 /**
184 * We checked wp_enqueue_editor() in condition because it conflicting with Divi Builder
185 * condition updated @since v.1.7.4
186 */
187
188 if ( is_single() ) {
189 if ( function_exists( 'et_pb_is_pagebuilder_used' ) ) {
190 $is_page_builder_used = et_pb_is_pagebuilder_used( get_the_ID() );
191 if ( ! $is_page_builder_used ) {
192 wp_enqueue_editor();
193 }
194 } else {
195 wp_enqueue_editor();
196 }
197 }
198
199 /**
200 * Initializing quicktags script to use in wp_editor();
201 */
202 wp_enqueue_script( 'quicktags' );
203
204 $tutor_dashboard_page_id = (int) tutor_utils()->get_option( 'tutor_dashboard_page_id' );
205 if ( get_the_ID() === $tutor_dashboard_page_id ) {
206 wp_enqueue_media();
207 }
208
209 /**
210 * Enabling Sorting, draggable, droppable...
211 */
212 wp_enqueue_script( 'jquery-ui-sortable' );
213 wp_enqueue_script( 'jquery-touch-punch', array( 'jquery-ui-sortable' ) ); //phpcs:ignore
214
215 // Plyr.
216 if ( is_single_course( true ) ) {
217 wp_enqueue_style( 'tutor-plyr', tutor()->url . 'assets/packages/plyr/plyr.css', array(), TUTOR_VERSION );
218 wp_enqueue_script( 'tutor-plyr', tutor()->url . 'assets/packages/plyr/plyr.polyfilled.min.js', array( 'jquery' ), TUTOR_VERSION, true );
219 }
220
221 // Social Share.
222 wp_enqueue_script( 'tutor-social-share', tutor()->url . 'assets/packages/SocialShare/SocialShare.min.js', array( 'jquery' ), TUTOR_VERSION, true );
223
224 /**
225 * Chart Data
226 */
227 if ( ! empty( $wp_query->query_vars['tutor_dashboard_page'] ) ) {
228 wp_enqueue_script( 'jquery-ui-slider' );
229
230 wp_enqueue_style( 'tutor-select2', tutor()->url . 'assets/packages/select2/select2.min.css', array(), TUTOR_VERSION );
231 wp_enqueue_script( 'tutor-select2', tutor()->url . 'assets/packages/select2/select2.full.min.js', array( 'jquery' ), TUTOR_VERSION, true );
232
233 if ( 'earning' === $wp_query->query_vars['tutor_dashboard_page'] ) {
234 wp_enqueue_script( 'tutor-front-chart-js', tutor()->url . 'assets/js/lib/Chart.bundle.min.js', array(), TUTOR_VERSION );
235 wp_enqueue_script( 'jquery-ui-datepicker' );
236 }
237 }
238 /**
239 * Dependency wp-i18n added for translate js file
240 *
241 * @since 1.9.0
242 */
243 wp_enqueue_style( 'tutor-frontend', tutor()->url . 'assets/css/tutor-front.min.css', array(), TUTOR_VERSION );
244 wp_enqueue_script( 'tutor-frontend', tutor()->url . 'assets/js/tutor-front.min.js', array( 'jquery', 'wp-i18n' ), TUTOR_VERSION, true );
245
246 /**
247 * Load frontend dashboard style
248 *
249 * @since v1.9.8
250 */
251 $should_load_dashboard_styles = apply_filters( 'tutor_should_load_dashboard_styles', tutor_utils()->is_tutor_frontend_dashboard() );
252 if ( $should_load_dashboard_styles ) {
253 wp_enqueue_style( 'tutor-frontend-dashboard-css', tutor()->url . 'assets/css/tutor-frontend-dashboard.min.css', array(), TUTOR_VERSION );
254 }
255
256 // Load date picker for announcement at frontend.
257 wp_enqueue_script( 'jquery-ui-datepicker' );
258 $css = '.mce-notification.mce-notification-error{display: none !important;}';
259 wp_add_inline_style( 'tutor-frontend', $css );
260 }
261
262 /**
263 * Modify localize data
264 *
265 * @since 1.0.0
266 *
267 * @param array $localize_data localize data.
268 * @return array
269 */
270 public function modify_localize_data( $localize_data ) {
271 global $post;
272
273 if ( is_admin() ) {
274 $taxonomy = Input::get( 'taxonomy' );
275 if ( 'course-category' === $taxonomy || 'course-tag' === $taxonomy ) {
276 $localize_data['open_tutor_admin_menu'] = true;
277 }
278 } else {
279
280 // Assign quiz option.
281 if ( ! empty( $post->post_type ) && 'tutor_quiz' === $post->post_type ) {
282 $single_quiz_options = (array) tutor_utils()->get_quiz_option( $post->ID );
283 $saved_quiz_options = array(
284 'quiz_when_time_expires' => tutor_utils()->get_option( 'quiz_when_time_expires' ),
285 );
286
287 $quiz_options = array_merge( $single_quiz_options, $saved_quiz_options );
288
289 $previous_attempts = tutor_utils()->quiz_attempts();
290
291 if ( $previous_attempts && count( $previous_attempts ) ) {
292 $quiz_options['quiz_auto_start'] = 0;
293 }
294
295 $localize_data['quiz_options'] = $quiz_options;
296 }
297
298 // Including player assets if video exists.
299 if ( tutor_utils()->has_video_in_single() ) {
300 $localize_data['post_id'] = get_the_ID();
301 $localize_data['best_watch_time'] = 0;
302
303 $best_watch_time = tutor_utils()->get_lesson_reading_info( get_the_ID(), 0, 'video_best_watched_time' );
304 if ( $best_watch_time > 0 ) {
305 $localize_data['best_watch_time'] = $best_watch_time;
306 }
307 }
308 }
309
310 return $localize_data;
311 }
312
313 /**
314 * Load common scripts for frontend and backend
315 *
316 * @since 1.0.0
317 * @return void
318 */
319 public function common_scripts() {
320
321 /**
322 * Load TinyMCE for tutor settings page if tutor pro is not available.
323 *
324 * @since v2.0.8
325 */
326 $baseurl = includes_url( 'js/tinymce' );
327 $current_page = Input::get( 'page' );
328
329 // If it is settings page & tutor pro not activated.
330 if ( 'tutor_settings' === $current_page && ! wp_script_is( 'wp-tinymce-root' ) ) {
331 wp_enqueue_script( 'tutor-tiny', $baseurl . '/tinymce.min.js', array( 'jquery' ), TUTOR_VERSION, true );
332 }
333 wp_enqueue_style( 'tutor-icon', tutor()->url . 'assets/css/tutor-icon.min.css', array(), TUTOR_VERSION );
334
335 // Common css library.
336 if ( is_rtl() ) {
337 wp_enqueue_style( 'tutor', tutor()->url . 'assets/css/tutor.rtl.min.css', array(), TUTOR_VERSION );
338 } else {
339 wp_enqueue_style( 'tutor', tutor()->url . 'assets/css/tutor.min.css', array(), TUTOR_VERSION );
340 }
341
342 // Load course builder resources.
343 $load_course_builder_scripts = apply_filters( 'tutor_load_course_builder_scripts', tutor_utils()->get_course_builder_screen() );
344 if ( $load_course_builder_scripts ) {
345 wp_enqueue_script( 'tutor-course-builder', tutor()->url . 'assets/js/tutor-course-builder.min.js', array( 'jquery', 'wp-i18n' ), TUTOR_VERSION, true );
346 wp_enqueue_style( 'tutor-course-builder-css', tutor()->url . 'assets/css/tutor-course-builder.min.css', array(), TUTOR_VERSION );
347 }
348 /**
349 * Load tutor common scripts both backend and frontend
350 *
351 * @since v2.0.0
352 */
353 wp_enqueue_script( 'tutor-script', tutor()->url . 'assets/js/tutor.min.js', array( 'jquery', 'wp-i18n' ), TUTOR_VERSION, true );
354
355 /**
356 * Enqueue datetime countdown scripts & styles
357 *
358 * Add filter to enqueue countdown scripts & styles
359 * don't return false if it is true to prevent conflict
360 * with other filters
361 *
362 * @since v2.1.0
363 */
364 $should_enqueue = apply_filters( 'tutor_should_enqueue_countdown_scripts', false );
365 if ( $should_enqueue ) {
366 wp_enqueue_script( 'tutor-moment', tutor()->url . 'assets/js/lib/countdown/moment.min.js', array(), TUTOR_VERSION, true );
367
368 wp_enqueue_script( 'tutor-moment-timezone', tutor()->url . 'assets/js/lib/countdown/moment-timezone-with-data.min.js', array(), TUTOR_VERSION, true );
369
370 wp_enqueue_script( 'tutor-jquery-countdown', tutor()->url . 'assets/js/lib/countdown/jquery.countdown.min.js', array( 'jquery' ), TUTOR_VERSION, true );
371
372 wp_enqueue_script( 'tutor-countdown', tutor()->url . 'assets/js/lib/countdown/tutor-countdown.min.js', array( 'jquery' ), TUTOR_VERSION, true );
373
374 wp_enqueue_style( 'tutor-countdown', tutor()->url . 'assets/js/lib/countdown/tutor-countdown.min.css', '', TUTOR_VERSION );
375 }
376 }
377
378 /**
379 * Load meta data
380 *
381 * @since 1.0.0
382 * @return void
383 */
384 public function load_meta_data() {
385 // Localize scripts.
386 $localize_data = apply_filters( 'tutor_localize_data', $this->get_default_localized_data() );
387 wp_localize_script( 'tutor-frontend', '_tutorobject', $localize_data );
388 wp_localize_script( 'tutor-admin', '_tutorobject', $localize_data );
389 wp_localize_script( 'tutor-course-builder', '_tutorobject', $localize_data );
390 wp_localize_script( 'tutor-script', '_tutorobject', $localize_data );
391
392 // Inline styles.
393 wp_add_inline_style( 'tutor-frontend', $this->load_color_palette() );
394 wp_add_inline_style( 'tutor-admin', $this->load_color_palette() );
395 }
396
397 /**
398 * Load color palette
399 *
400 * @since 1.0.0
401 * @return string
402 */
403 private function load_color_palette() {
404 $colors = array(
405 'tutor_primary_color' => '--tutor-color-primary',
406 'tutor_primary_hover_color' => '--tutor-color-primary-hover',
407 'tutor_text_color' => '--tutor-body-color',
408 'tutor_border_color' => '--tutor-border-color',
409 'tutor_gray_color' => '--tutor-color-gray',
410 );
411
412 // Admin colors.
413 $admin_colors = array();
414 if ( is_admin() ) {
415 $admin_color = get_user_option( 'admin_color' );
416
417 switch ( $admin_color ) {
418 case 'light':
419 $admin_color_codes = array( '#04a4cc', '#04b0db' );
420 break;
421
422 case 'modern':
423 $admin_color_codes = array( '#3858e9', '#4664eb' );
424 break;
425
426 case 'blue':
427 $admin_color_codes = array( '#e1a948', '#e3af55' );
428 break;
429
430 case 'coffee':
431 $admin_color_codes = array( '#c7a589', '#ccad93' );
432 break;
433
434 case 'ectoplasm':
435 $admin_color_codes = array( '#a3b745', '#a9bd4f' );
436 break;
437
438 case 'midnight':
439 $admin_color_codes = array( '#e14d43', '#e35950' );
440 break;
441
442 case 'ocean':
443 $admin_color_codes = array( '#9ebaa0', '#a7c0a9' );
444 break;
445
446 case 'sunrise':
447 $admin_color_codes = array( '#dd823b', '#df8a48' );
448 break;
449
450 default:
451 $admin_color_codes = array( '#007cba', '#006ba1' );
452 break;
453 }
454
455 $admin_colors = array(
456 '--tutor-color-primary' => $admin_color_codes[0],
457 '--tutor-color-primary-hover' => $admin_color_codes[1],
458 );
459 }
460
461 $fallback_colors = array(
462 'tutor_primary_color' => '#3E64DE',
463 'tutor_primary_hover_color' => '#395BCA',
464 'tutor_text_color' => '#212327',
465 'tutor_border_color' => '#E3E5EB',
466 'tutor_gray_color' => '#CDCFD5',
467 );
468
469 $color_string = '';
470 foreach ( $colors as $key => $property ) {
471 $fallback_color = isset( $fallback_colors[ $key ] ) ? $fallback_colors[ $key ] : '#212327';
472 $color = tutor_utils()->get_option( $key, $fallback_color );
473 $color_rgb = tutor_utils()->hex2rgb( $color );
474
475 if ( is_admin() && isset( $admin_colors[ $property ] ) ) {
476 $color = $admin_colors[ $property ];
477 $color_rgb = tutor_utils()->hex2rgb( $admin_colors[ $property ] );
478 }
479
480 if ( $color ) {
481 $color_string .= $property . ':' . $color . ';';
482 }
483
484 if ( $color_rgb ) {
485 $color_string .= $property . '-rgb:' . $color_rgb . ';';
486 }
487 }
488
489 return ':root{' . $color_string . '}';
490 }
491
492 /**
493 * Add Tinymce button for placing shortcode
494 *
495 * @since 1.0.0
496 * @return void|null
497 */
498 public function tutor_add_mce_button() {
499 // Check user permissions.
500 if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
501 return;
502 }
503 // Check if WYSIWYG is enabled.
504 if ( 'true' == get_user_option( 'rich_editing' ) ) {
505 add_filter( 'mce_external_plugins', array( $this, 'tutor_add_tinymce_js' ) );
506 add_filter( 'mce_buttons', array( $this, 'tutor_register_mce_button' ) );
507 }
508 }
509
510 /**
511 * Add tinymce button
512 *
513 * @since 1.0.0
514 *
515 * @param array $plugin_array plugin array.
516 * @return array
517 */
518 public function tutor_add_tinymce_js( $plugin_array ) {
519 $plugin_array['tutor_button'] = tutor()->url . 'assets/js/lib/mce-button.js';
520 return $plugin_array;
521 }
522
523 /**
524 * Register new button in the editor
525 *
526 * @since 1.0.0
527 *
528 * @param array $buttons buttons.
529 * @return array
530 */
531 public function tutor_register_mce_button( $buttons ) {
532 array_push( $buttons, 'tutor_button' );
533 return $buttons;
534 }
535
536 /**
537 * Output generator tag to aid debugging.
538 *
539 * @since 1.0.0
540 *
541 * @param string $gen Generator.
542 * @param string $type Type.
543 *
544 * @return string
545 */
546 public function tutor_generator_tag( $gen, $type ) {
547 switch ( $type ) {
548 case 'html':
549 $gen .= "\n" . '<meta name="generator" content="TutorLMS ' . TUTOR_VERSION . '">';
550 break;
551 case 'xhtml':
552 $gen .= "\n" . '<meta name="generator" content="TutorLMS ' . TUTOR_VERSION . '" />';
553 break;
554 }
555 return $gen;
556 }
557
558 /**
559 * Load text domain handled script after all enqueue_scripts
560 * registered functions
561 *
562 * @since 1.9.0
563 * @return void
564 */
565 public function tutor_script_text_domain() {
566 wp_set_script_translations( 'tutor-frontend', 'tutor', tutor()->path . 'languages/' );
567 wp_set_script_translations( 'tutor-admin', 'tutor', tutor()->path . 'languages/' );
568 wp_set_script_translations( 'tutor-course-builder', 'tutor', tutor()->path . 'languages/' );
569 }
570
571 /**
572 * Add translation support for external tinyMCE button
573 *
574 * @since 1.9.7
575 * @return array
576 */
577 public function tutor_tinymce_translate() {
578 $locales['tutor_button'] = tutor()->path . 'includes/tinymce_translate.php';
579 return $locales;
580 }
581
582 /**
583 * Add an identifier class to body
584 *
585 * @since 1.0.0
586 *
587 * @param mixed $classes classes.
588 * @return mixed
589 */
590 public function add_identifier_class_to_body( $classes ) {
591 $course_builder_screen = tutor_utils()->get_course_builder_screen();
592 $to_add = array( 'tutor-lms' );
593
594 // Add backend course editor identifier class to body.
595 if ( $course_builder_screen ) {
596 $to_add[] = is_admin() ? 'tutor-backend' : 'tutor-frontend';
597 $to_add[] = ' tutor-screen-course-builder tutor-screen-course-builder-' . $course_builder_screen . ' ';
598 }
599
600 // Add frontend course builder identifier class.
601 if ( ! $course_builder_screen && tutor_utils()->is_tutor_frontend_dashboard() ) {
602 $to_add[] = 'tutor-screen-frontend-dashboard';
603 }
604
605 if ( is_post_type_archive( tutor()->course_post_type ) ) {
606 $to_add[] = 'tutor-frontend';
607 }
608
609 if ( tutor_utils()->is_tutor_frontend_dashboard() ) {
610 $to_add[] = 'tutor-frontend';
611 }
612
613 if ( is_single() ) {
614 global $post;
615
616 $post_types = array(
617 tutor()->course_post_type,
618 tutor()->lesson_post_type,
619 tutor()->quiz_post_type,
620 tutor()->assignment_post_type,
621 tutor()->zoom_post_type,
622 tutor()->meet_post_type,
623 );
624
625 if ( isset( $post->post_type ) && in_array( $post->post_type, $post_types, true ) ) {
626 $to_add[] = 'tutor-frontend';
627 }
628 }
629
630 if ( is_admin() ) {
631 $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
632 $base = ( $screen && is_object( $screen ) && property_exists( $screen, 'base' ) ) ? $screen->base : '';
633 $index = strpos( $base, 'tutor' );
634
635 if ( 0 === $index || $index > 0 ) {
636 $to_add[] = 'tutor-backend';
637
638 $page = Input::get( 'page' );
639 if ( 'tutor_settings' === $page ) {
640 $to_add[] = 'tutor-screen-backend-settings ';
641 }
642 if ( ! empty( $page ) ) {
643 $to_add[] = 'tutor-backend-' . $page;
644 }
645 }
646 }
647
648 // Remove duplicate classes if any.
649 $to_add = array_unique( $to_add );
650
651 if ( is_array( $classes ) ) {
652 $classes = array_merge( $classes, $to_add );
653 } else {
654 $classes .= implode( ' ', $to_add );
655 }
656
657 return $classes;
658 }
659
660 /**
661 * Enqueue script for adding edit with frontend course builder button
662 * on the Gutenberg editor
663 *
664 * @since 2.0.5
665 * @return void
666 */
667 public static function add_frontend_editor_button() {
668 $wp_screen = get_current_screen();
669
670 if ( is_a( $wp_screen, 'WP_Screen' ) && tutor()->course_post_type === $wp_screen->post_type ) {
671 wp_enqueue_script( 'tutor-gutenberg', tutor()->url . 'assets/js/tutor-gutenberg.min.js', array(), TUTOR_VERSION, true );
672 $data = array(
673 'frontend_dashboard_url' => esc_url( trailingslashit( tutor_utils()->tutor_dashboard_url( 'create-course' ) ) ) . '?course_ID=' . get_the_ID(),
674 );
675
676 wp_add_inline_script(
677 'tutor-gutenberg',
678 'const tutorInlineData =' . json_encode( $data ),
679 'before'
680 );
681 }
682 }
683 }
684