PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 2.1.6
Tutor LMS – eLearning and online course solution v2.1.6
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 3 years ago Admin.php 3 years ago Ajax.php 3 years ago Announcements.php 3 years ago Assets.php 3 years ago Backend_Page_Trait.php 3 years ago Course.php 3 years ago Course_Embed.php 3 years ago Course_Filter.php 3 years ago Course_List.php 3 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 3 years ago Frontend.php 3 years ago Gutenberg.php 3 years ago Input.php 3 years ago Instructor.php 3 years ago Instructors_List.php 3 years ago Lesson.php 3 years ago Options_V2.php 3 years ago Post_types.php 3 years ago Private_Course_Access.php 3 years ago Q_and_A.php 3 years ago Question_Answers_List.php 3 years ago Quiz.php 3 years ago Quiz_Attempts_List.php 3 years ago RestAPI.php 3 years ago Reviews.php 3 years ago Rewrite_Rules.php 3 years ago Shortcode.php 3 years ago Student.php 3 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 3 years ago TutorEDD.php 3 years ago Tutor_Base.php 3 years ago Tutor_Setup.php 3 years ago Upgrader.php 3 years ago User.php 3 years ago Utils.php 3 years ago Video_Stream.php 3 years ago Withdraw.php 3 years ago Withdraw_Requests_List.php 3 years ago WooCommerce.php 3 years ago
Assets.php
637 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 return array(
104 'ajaxurl' => admin_url( 'admin-ajax.php' ),
105 'home_url' => get_home_url(),
106 'site_title' => get_bloginfo( 'title' ),
107 'base_path' => tutor()->basepath,
108 'tutor_url' => tutor()->url,
109 'tutor_pro_url' => function_exists( 'tutor_pro' ) ? tutor_pro()->url : null,
110 'nonce_key' => tutor()->nonce,
111 tutor()->nonce => wp_create_nonce( tutor()->nonce_action ),
112 'loading_icon_url' => get_admin_url() . 'images/wpspin_light.gif',
113 'placeholder_img_src' => tutor_placeholder_img_src(),
114 'enable_lesson_classic_editor' => get_tutor_option( 'enable_lesson_classic_editor' ),
115 'tutor_frontend_dashboard_url' => tutor_utils()->get_tutor_dashboard_page_permalink(),
116 'wp_date_format' => tutor_js_date_format_against_wp(),
117 'is_admin' => is_admin(),
118 'is_admin_bar_showing' => is_admin_bar_showing(),
119 'addons_data' => tutor_utils()->prepare_free_addons_data(),
120 'current_user' => wp_get_current_user(),
121 'content_change_event' => 'tutor_content_changed_event',
122 'is_tutor_course_edit' => isset( $_GET['action'] ) && 'edit' === $_GET['action'] && tutor()->course_post_type === get_post_type( get_the_ID() ) ? true : false,
123 'assignment_max_file_allowed' => 'tutor_assignments' === $post_type ? (int) tutor_utils()->get_assignment_option( $post_id, 'upload_files_limit' ) : 0,
124 'current_page' => $current_page,
125 'quiz_answer_display_time' => 1000 * (int) tutor_utils()->get_option( 'quiz_answer_display_time' ),
126 'is_ssl' => is_ssl(),
127 );
128 }
129
130 /**
131 * Enqueue scripts for admin
132 *
133 * @since 1.0.0
134 * @return void
135 */
136 public function admin_scripts() {
137 wp_enqueue_style( 'tutor-select2', tutor()->url . 'assets/packages/select2/select2.min.css', array(), TUTOR_VERSION );
138 wp_enqueue_style( 'tutor-admin', tutor()->url . 'assets/css/tutor-admin.min.css', array(), TUTOR_VERSION );
139 /**
140 * Scripts
141 */
142 wp_enqueue_media();
143
144 wp_enqueue_script( 'wp-color-picker' );
145 wp_enqueue_style( 'wp-color-picker' );
146
147 wp_enqueue_script( 'jquery-ui-slider' );
148 wp_enqueue_script( 'jquery-ui-datepicker' );
149
150 wp_enqueue_script( 'tutor-select2', tutor()->url . 'assets/packages/select2/select2.full.min.js', array( 'jquery' ), TUTOR_VERSION, true );
151 wp_enqueue_script( 'tutor-admin', tutor()->url . 'assets/js/tutor-admin.min.js', array( 'jquery', 'wp-color-picker', 'wp-i18n' ), TUTOR_VERSION, true );
152 }
153
154 /**
155 * Load frontend scripts
156 *
157 * @since 1.0.0
158 * @return void
159 */
160 public function frontend_scripts() {
161 global $post, $wp_query;
162
163 /**
164 * We checked wp_enqueue_editor() in condition because it conflicting with Divi Builder
165 * condition updated @since v.1.7.4
166 */
167
168 if ( is_single() ) {
169 if ( function_exists( 'et_pb_is_pagebuilder_used' ) ) {
170 $is_page_builder_used = et_pb_is_pagebuilder_used( get_the_ID() );
171 if ( ! $is_page_builder_used ) {
172 wp_enqueue_editor();
173 }
174 } else {
175 wp_enqueue_editor();
176 }
177 }
178
179 /**
180 * Initializing quicktags script to use in wp_editor();
181 */
182 wp_enqueue_script( 'quicktags' );
183
184 $tutor_dashboard_page_id = (int) tutor_utils()->get_option( 'tutor_dashboard_page_id' );
185 if ( get_the_ID() === $tutor_dashboard_page_id ) {
186 wp_enqueue_media();
187 }
188
189 /**
190 * Enabling Sorting, draggable, droppable...
191 */
192 wp_enqueue_script( 'jquery-ui-sortable' );
193 wp_enqueue_script( 'jquery-touch-punch', array( 'jquery-ui-sortable' ) );
194
195 // Plyr.
196 if ( is_single_course( true ) ) {
197 wp_enqueue_style( 'tutor-plyr', tutor()->url . 'assets/packages/plyr/plyr.css', array(), TUTOR_VERSION );
198 wp_enqueue_script( 'tutor-plyr', tutor()->url . 'assets/packages/plyr/plyr.polyfilled.min.js', array( 'jquery' ), TUTOR_VERSION, true );
199 }
200
201 // Social Share.
202 wp_enqueue_script( 'tutor-social-share', tutor()->url . 'assets/packages/SocialShare/SocialShare.min.js', array( 'jquery' ), TUTOR_VERSION, true );
203
204 /**
205 * Chart Data
206 */
207 if ( ! empty( $wp_query->query_vars['tutor_dashboard_page'] ) ) {
208 wp_enqueue_script( 'jquery-ui-slider' );
209
210 wp_enqueue_style( 'tutor-select2', tutor()->url . 'assets/packages/select2/select2.min.css', array(), TUTOR_VERSION );
211 wp_enqueue_script( 'tutor-select2', tutor()->url . 'assets/packages/select2/select2.full.min.js', array( 'jquery' ), TUTOR_VERSION, true );
212
213 if ( 'earning' === $wp_query->query_vars['tutor_dashboard_page'] ) {
214 wp_enqueue_script( 'tutor-front-chart-js', tutor()->url . 'assets/js/lib/Chart.bundle.min.js', array(), TUTOR_VERSION );
215 wp_enqueue_script( 'jquery-ui-datepicker' );
216 }
217 }
218 /**
219 * Dependency wp-i18n added for translate js file
220 *
221 * @since 1.9.0
222 */
223 wp_enqueue_style( 'tutor-frontend', tutor()->url . 'assets/css/tutor-front.min.css', array(), TUTOR_VERSION );
224 wp_enqueue_script( 'tutor-frontend', tutor()->url . 'assets/js/tutor-front.min.js', array( 'jquery', 'wp-i18n' ), TUTOR_VERSION, true );
225
226 /**
227 * Load frontend dashboard style
228 *
229 * @since v1.9.8
230 */
231 if ( tutor_utils()->is_tutor_frontend_dashboard() ) {
232 wp_enqueue_style( 'tutor-frontend-dashboard-css', tutor()->url . 'assets/css/tutor-frontend-dashboard.min.css', TUTOR_VERSION );
233 }
234
235 // Load date picker for announcement at frontend.
236 wp_enqueue_script( 'jquery-ui-datepicker' );
237 $css = '.mce-notification.mce-notification-error{display: none !important;}';
238 wp_add_inline_style( 'tutor-frontend', $css );
239 }
240
241 /**
242 * Modify localize data
243 *
244 * @since 1.0.0
245 *
246 * @param array $localize_data localize data.
247 * @return array
248 */
249 public function modify_localize_data( $localize_data ) {
250 global $post;
251
252 if ( is_admin() ) {
253 $taxonomy = Input::get( 'taxonomy' );
254 if ( 'course-category' === $taxonomy || 'course-tag' === $taxonomy ) {
255 $localize_data['open_tutor_admin_menu'] = true;
256 }
257 } else {
258
259 // Assign quiz option.
260 if ( ! empty( $post->post_type ) && 'tutor_quiz' === $post->post_type ) {
261 $single_quiz_options = (array) tutor_utils()->get_quiz_option( $post->ID );
262 $saved_quiz_options = array(
263 'quiz_when_time_expires' => tutor_utils()->get_option( 'quiz_when_time_expires' ),
264 );
265
266 $quiz_options = array_merge( $single_quiz_options, $saved_quiz_options );
267
268 $previous_attempts = tutor_utils()->quiz_attempts();
269
270 if ( $previous_attempts && count( $previous_attempts ) ) {
271 $quiz_options['quiz_auto_start'] = 0;
272 }
273
274 $localize_data['quiz_options'] = $quiz_options;
275 }
276
277 // Including player assets if video exists.
278 if ( tutor_utils()->has_video_in_single() ) {
279 $localize_data['post_id'] = get_the_ID();
280 $localize_data['best_watch_time'] = 0;
281
282 $best_watch_time = tutor_utils()->get_lesson_reading_info( get_the_ID(), 0, 'video_best_watched_time' );
283 if ( $best_watch_time > 0 ) {
284 $localize_data['best_watch_time'] = $best_watch_time;
285 }
286 }
287 }
288
289 return $localize_data;
290 }
291
292 /**
293 * Load common scripts for frontend and backend
294 *
295 * @since 1.0.0
296 * @return void
297 */
298 public function common_scripts() {
299
300 /**
301 * Load TinyMCE for tutor settings page if tutor pro is not available.
302 *
303 * @since v2.0.8
304 */
305 $baseurl = includes_url( 'js/tinymce' );
306 $current_page = Input::get( 'page' );
307
308 // If it is settings page & tutor pro not activated.
309 if ( 'tutor_settings' === $current_page && ! wp_script_is( 'wp-tinymce-root' ) ) {
310 wp_enqueue_script( 'tutor-tiny', $baseurl . '/tinymce.min.js', array( 'jquery' ), TUTOR_VERSION, true );
311 }
312 wp_enqueue_style( 'tutor-icon', tutor()->url . 'assets/css/tutor-icon.min.css', array(), TUTOR_VERSION );
313
314 // Common css library.
315 if ( is_rtl() ) {
316 wp_enqueue_style( 'tutor', tutor()->url . 'assets/css/tutor.rtl.min.css', array(), TUTOR_VERSION );
317 } else {
318 wp_enqueue_style( 'tutor', tutor()->url . 'assets/css/tutor.min.css', array(), TUTOR_VERSION );
319 }
320
321 // Load course builder resources.
322 if ( tutor_utils()->get_course_builder_screen() ) {
323 wp_enqueue_script( 'tutor-course-builder', tutor()->url . 'assets/js/tutor-course-builder.min.js', array( 'jquery', 'wp-i18n' ), TUTOR_VERSION, true );
324 wp_enqueue_style( 'tutor-course-builder-css', tutor()->url . 'assets/css/tutor-course-builder.min.css', array(), TUTOR_VERSION );
325 }
326 /**
327 * Load tutor common scripts both backend and frontend
328 *
329 * @since v2.0.0
330 */
331 wp_enqueue_script( 'tutor-script', tutor()->url . 'assets/js/tutor.min.js', array( 'jquery', 'wp-i18n' ), TUTOR_VERSION, true );
332
333 /**
334 * Enqueue datetime countdown scripts & styles
335 *
336 * Add filter to enqueue countdown scripts & styles
337 * don't return false if it is true to prevent conflict
338 * with other filters
339 *
340 * @since v2.1.0
341 */
342 $should_enqueue = apply_filters( 'tutor_should_enqueue_countdown_scripts', false );
343 if ( $should_enqueue ) {
344 wp_enqueue_script( 'tutor-moment', tutor()->url . 'assets/js/lib/countdown/moment.min.js', array(), TUTOR_VERSION, true );
345
346 wp_enqueue_script( 'tutor-moment-timezone', tutor()->url . 'assets/js/lib/countdown/moment-timezone-with-data.min.js', array(), TUTOR_VERSION, true );
347
348 wp_enqueue_script( 'tutor-jquery-countdown', tutor()->url . 'assets/js/lib/countdown/jquery.countdown.min.js', array( 'jquery' ), TUTOR_VERSION, true );
349
350 wp_enqueue_script( 'tutor-countdown', tutor()->url . 'assets/js/lib/countdown/tutor-countdown.min.js', array( 'jquery' ), TUTOR_VERSION, true );
351
352 wp_enqueue_style( 'tutor-countdown', tutor()->url . 'assets/js/lib/countdown/tutor-countdown.min.css', '', TUTOR_VERSION );
353 }
354 }
355
356 /**
357 * Load meta data
358 *
359 * @since 1.0.0
360 * @return void
361 */
362 public function load_meta_data() {
363 // Localize scripts.
364 $localize_data = apply_filters( 'tutor_localize_data', $this->get_default_localized_data() );
365 wp_localize_script( 'tutor-frontend', '_tutorobject', $localize_data );
366 wp_localize_script( 'tutor-admin', '_tutorobject', $localize_data );
367 wp_localize_script( 'tutor-course-builder', '_tutorobject', $localize_data );
368 wp_localize_script( 'tutor-script', '_tutorobject', $localize_data );
369
370 // Inline styles.
371 wp_add_inline_style( 'tutor-frontend', $this->load_color_palette() );
372 wp_add_inline_style( 'tutor-admin', $this->load_color_palette() );
373 }
374
375 /**
376 * Load color palette
377 *
378 * @since 1.0.0
379 * @return string
380 */
381 private function load_color_palette() {
382 $colors = array(
383 'tutor_primary_color' => '--tutor-color-primary',
384 'tutor_primary_hover_color' => '--tutor-color-primary-hover',
385 'tutor_text_color' => '--tutor-body-color',
386 'tutor_border_color' => '--tutor-border-color',
387 'tutor_gray_color' => '--tutor-color-gray',
388 );
389
390 // Admin colors.
391 $admin_colors = array();
392 if ( is_admin() ) {
393 $admin_color = get_user_option( 'admin_color' );
394
395 switch ( $admin_color ) {
396 case 'light':
397 $admin_color_codes = array( '#04a4cc', '#04b0db' );
398 break;
399
400 case 'modern':
401 $admin_color_codes = array( '#3858e9', '#4664eb' );
402 break;
403
404 case 'blue':
405 $admin_color_codes = array( '#e1a948', '#e3af55' );
406 break;
407
408 case 'coffee':
409 $admin_color_codes = array( '#c7a589', '#ccad93' );
410 break;
411
412 case 'ectoplasm':
413 $admin_color_codes = array( '#a3b745', '#a9bd4f' );
414 break;
415
416 case 'midnight':
417 $admin_color_codes = array( '#e14d43', '#e35950' );
418 break;
419
420 case 'ocean':
421 $admin_color_codes = array( '#9ebaa0', '#a7c0a9' );
422 break;
423
424 case 'sunrise':
425 $admin_color_codes = array( '#dd823b', '#df8a48' );
426 break;
427
428 default:
429 $admin_color_codes = array( '#007cba', '#006ba1' );
430 break;
431 }
432
433 $admin_colors = array(
434 '--tutor-color-primary' => $admin_color_codes[0],
435 '--tutor-color-primary-hover' => $admin_color_codes[1],
436 );
437 }
438
439 $fallback_colors = array(
440 'tutor_primary_color' => '#3E64DE',
441 'tutor_primary_hover_color' => '#395BCA',
442 'tutor_text_color' => '#212327',
443 'tutor_border_color' => '#E3E5EB',
444 'tutor_gray_color' => '#CDCFD5',
445 );
446
447 $color_string = '';
448 foreach ( $colors as $key => $property ) {
449 $fallback_color = isset( $fallback_colors[ $key ] ) ? $fallback_colors[ $key ] : '#212327';
450 $color = tutor_utils()->get_option( $key, $fallback_color );
451 $color_rgb = tutor_utils()->hex2rgb( $color );
452
453 if ( is_admin() && isset( $admin_colors[ $property ] ) ) {
454 $color = $admin_colors[ $property ];
455 $color_rgb = tutor_utils()->hex2rgb( $admin_colors[ $property ] );
456 }
457
458 if ( $color ) {
459 $color_string .= $property . ':' . $color . ';';
460 }
461
462 if ( $color_rgb ) {
463 $color_string .= $property . '-rgb:' . $color_rgb . ';';
464 }
465 }
466
467 return ':root{' . $color_string . '}';
468 }
469
470 /**
471 * Add Tinymce button for placing shortcode
472 *
473 * @since 1.0.0
474 * @return void|null
475 */
476 public function tutor_add_mce_button() {
477 // Check user permissions.
478 if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
479 return;
480 }
481 // Check if WYSIWYG is enabled.
482 if ( 'true' == get_user_option( 'rich_editing' ) ) {
483 add_filter( 'mce_external_plugins', array( $this, 'tutor_add_tinymce_js' ) );
484 add_filter( 'mce_buttons', array( $this, 'tutor_register_mce_button' ) );
485 }
486 }
487
488 /**
489 * Add tinymce button
490 *
491 * @since 1.0.0
492 *
493 * @param array $plugin_array plugin array.
494 * @return array
495 */
496 public function tutor_add_tinymce_js( $plugin_array ) {
497 $plugin_array['tutor_button'] = tutor()->url . 'assets/js/lib/mce-button.js';
498 return $plugin_array;
499 }
500
501 /**
502 * Register new button in the editor
503 *
504 * @since 1.0.0
505 *
506 * @param array $buttons buttons.
507 * @return array
508 */
509 public function tutor_register_mce_button( $buttons ) {
510 array_push( $buttons, 'tutor_button' );
511 return $buttons;
512 }
513
514 /**
515 * Output generator tag to aid debugging.
516 *
517 * @since 1.0.0
518 *
519 * @param string $gen Generator.
520 * @param string $type Type.
521 *
522 * @return string
523 */
524 public function tutor_generator_tag( $gen, $type ) {
525 switch ( $type ) {
526 case 'html':
527 $gen .= "\n" . '<meta name="generator" content="TutorLMS ' . TUTOR_VERSION . '">';
528 break;
529 case 'xhtml':
530 $gen .= "\n" . '<meta name="generator" content="TutorLMS ' . TUTOR_VERSION . '" />';
531 break;
532 }
533 return $gen;
534 }
535
536 /**
537 * Load text domain handled script after all enqueue_scripts
538 * registered functions
539 *
540 * @since 1.9.0
541 * @return void
542 */
543 public function tutor_script_text_domain() {
544 wp_set_script_translations( 'tutor-frontend', 'tutor', tutor()->path . 'languages/' );
545 wp_set_script_translations( 'tutor-admin', 'tutor', tutor()->path . 'languages/' );
546 wp_set_script_translations( 'tutor-course-builder', 'tutor', tutor()->path . 'languages/' );
547 }
548
549 /**
550 * Add translation support for external tinyMCE button
551 *
552 * @since 1.9.7
553 * @return array
554 */
555 public function tutor_tinymce_translate() {
556 $locales['tutor_button'] = tutor()->path . 'includes/tinymce_translate.php';
557 return $locales;
558 }
559
560 /**
561 * Add an identifier class to body
562 *
563 * @since 1.0.0
564 *
565 * @param mixed $classes classes.
566 * @return mixed
567 */
568 public function add_identifier_class_to_body( $classes ) {
569 $course_builder_screen = tutor_utils()->get_course_builder_screen();
570 $to_add = array( 'tutor-lms' );
571
572 // Add backend course editor identifier class to body.
573 if ( $course_builder_screen ) {
574 $to_add[] = is_admin() ? 'tutor-backend' : '';
575 $to_add[] = ' tutor-screen-course-builder tutor-screen-course-builder-' . $course_builder_screen . ' ';
576 }
577
578 // Add frontend course builder identifier class.
579 if ( ! $course_builder_screen && tutor_utils()->is_tutor_frontend_dashboard() ) {
580 $to_add[] = 'tutor-screen-frontend-dashboard';
581 }
582
583 if ( is_admin() ) {
584 $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
585 $base = ( $screen && is_object( $screen ) && property_exists( $screen, 'base' ) ) ? $screen->base : '';
586 $index = strpos( $base, 'tutor' );
587
588 if ( 0 === $index || $index > 0 ) {
589 $to_add[] = 'tutor-backend';
590
591 $page = Input::get( 'page' );
592 if ( 'tutor_settings' === $page ) {
593 $to_add[] = 'tutor-screen-backend-settings ';
594 }
595 if ( ! empty( $page ) ) {
596 $to_add[] = 'tutor-backend-' . $page;
597 }
598 }
599 }
600
601 // Remove duplicate classes if any.
602 $to_add = array_unique( $to_add );
603
604 if ( is_array( $classes ) ) {
605 $classes = array_merge( $classes, $to_add );
606 } else {
607 $classes .= implode( ' ', $to_add );
608 }
609
610 return $classes;
611 }
612
613 /**
614 * Enqueue script for adding edit with frontend course builder button
615 * on the Gutenberg editor
616 *
617 * @since 2.0.5
618 * @return void
619 */
620 public static function add_frontend_editor_button() {
621 $wp_screen = get_current_screen();
622
623 if ( is_a( $wp_screen, 'WP_Screen' ) && tutor()->course_post_type === $wp_screen->post_type ) {
624 wp_enqueue_script( 'tutor-gutenberg', tutor()->url . 'assets/js/tutor-gutenberg.min.js', array(), TUTOR_VERSION, true );
625 $data = array(
626 'frontend_dashboard_url' => esc_url( trailingslashit( tutor_utils()->tutor_dashboard_url( 'create-course' ) ) ) . '?course_ID=' . get_the_ID(),
627 );
628
629 wp_add_inline_script(
630 'tutor-gutenberg',
631 'const tutorInlineData =' . json_encode( $data ),
632 'before'
633 );
634 }
635 }
636 }
637