PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 3.9.7
Tutor LMS – eLearning and online course solution v3.9.7
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 11 months ago Admin.php 8 months ago Ajax.php 9 months ago Announcements.php 1 year ago Assets.php 7 months ago Backend_Page_Trait.php 1 year ago BaseController.php 1 year ago Config.php 11 months ago Container.php 11 months ago Course.php 5 months ago Course_Embed.php 3 years ago Course_Filter.php 1 year ago Course_List.php 5 months ago Course_Settings_Tabs.php 1 year ago Course_Widget.php 1 year ago Custom_Validation.php 3 years ago Dashboard.php 1 year ago Earnings.php 9 months ago FormHandler.php 2 years ago Frontend.php 1 year ago Gutenberg.php 1 year ago Icon.php 8 months ago Input.php 1 year ago Instructor.php 1 year ago Instructors_List.php 11 months ago Lesson.php 8 months ago Options_V2.php 7 months ago Permalink.php 2 years ago Post_types.php 1 year ago Private_Course_Access.php 1 year ago Q_And_A.php 10 months ago Question_Answers_List.php 11 months ago Quiz.php 5 months ago QuizBuilder.php 11 months ago Quiz_Attempts_List.php 9 months ago RestAPI.php 2 years ago Reviews.php 9 months ago Rewrite_Rules.php 2 years ago Shortcode.php 9 months ago Singleton.php 1 year ago Student.php 1 year ago Students_List.php 1 year ago Taxonomies.php 1 year ago Template.php 9 months ago Theme_Compatibility.php 3 years ago Tools.php 1 year ago Tools_V2.php 1 year ago Tutor.php 7 months ago TutorEDD.php 1 year ago Tutor_Base.php 2 years ago Tutor_Setup.php 8 months ago Upgrader.php 9 months ago User.php 4 months ago Utils.php 5 months ago Video_Stream.php 3 years ago WhatsNew.php 9 months ago Withdraw.php 1 year ago Withdraw_Requests_List.php 11 months ago WooCommerce.php 7 months ago
Assets.php
751 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 use Tutor\Ecommerce\CouponController;
14 use Tutor\Ecommerce\OptionKeys;
15 use Tutor\Ecommerce\OrderController;
16 use Tutor\Ecommerce\Settings;
17 use Tutor\Models\CourseModel;
18
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit;
21 }
22
23 /**
24 * Assets class
25 *
26 * @since 1.0.0
27 */
28 class Assets {
29
30
31 /**
32 * Constructor
33 *
34 * @since 1.0.0
35 *
36 * @since 3.0.0 register hook param added
37 *
38 * @param bool $register_hooks param added to enable or disable registering hooks.
39 *
40 * @return void
41 */
42 public function __construct( $register_hooks = true ) {
43 if ( ! $register_hooks ) {
44 return;
45 }
46
47 /**
48 * Common scripts loading
49 */
50 add_action( 'admin_enqueue_scripts', array( $this, 'common_scripts' ) );
51 add_action( 'wp_enqueue_scripts', array( $this, 'common_scripts' ) );
52 /**
53 * Front and backend script enqueue
54 */
55 add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
56 add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
57
58 add_action( 'admin_enqueue_scripts', array( $this, 'load_meta_data' ) );
59 add_action( 'wp_enqueue_scripts', array( $this, 'load_meta_data' ) );
60
61 /**
62 * Text domain loading
63 */
64 add_action( 'admin_enqueue_scripts', array( $this, 'tutor_script_text_domain' ), 100 );
65 add_action( 'wp_enqueue_scripts', array( $this, 'tutor_script_text_domain' ), 100 );
66 add_filter( 'tutor_localize_data', array( $this, 'modify_localize_data' ) );
67
68 /**
69 * Register translatable function to load
70 * Handled script with text domain attached to
71 *
72 * @since 1.9.0
73 */
74 add_action( 'admin_head', array( $this, 'tutor_add_mce_button' ) );
75 add_filter( 'get_the_generator_html', array( $this, 'tutor_generator_tag' ), 10, 2 );
76 add_filter( 'get_the_generator_xhtml', array( $this, 'tutor_generator_tag' ), 10, 2 );
77
78 /**
79 * Add translation support for external tinyMCE button
80 *
81 * @since 1.9.7
82 */
83 add_filter( 'mce_external_languages', array( $this, 'tutor_tinymce_translate' ) );
84
85 /**
86 * Identifier class to body tag
87 *
88 * @since v1.9.9
89 */
90 add_filter( 'body_class', array( $this, 'add_identifier_class_to_body' ) );
91 add_filter( 'admin_body_class', array( $this, 'add_identifier_class_to_body' ) );
92
93 /**
94 * Add edit with front end builder button on Gutenberg editor
95 *
96 * @since v2.0.5
97 */
98 add_action( 'enqueue_block_editor_assets', __CLASS__ . '::add_frontend_editor_button' );
99 }
100
101 /**
102 * Load default localized data
103 *
104 * @since 1.0.0
105 * @return array
106 */
107 public function get_default_localized_data() {
108 $home_url = get_home_url();
109 $parsed = parse_url( $home_url );
110
111 $base_path = ( is_array( $parsed ) && isset( $parsed['path'] ) ) ? $parsed['path'] : '/';
112 $base_path = rtrim( $base_path, '/' ) . '/';
113
114 $post_id = get_the_ID();
115 $post_type = get_post_type( $post_id );
116
117 $current_page = tutor_utils()->get_current_page_slug();
118
119 /**
120 * Only required current user data.
121 *
122 * @since 2.6.2
123 */
124 $current_user = array();
125 $userdata = get_userdata( get_current_user_id() );
126
127 if ( $userdata ) {
128 $current_user = array(
129 'roles' => array_values( $userdata->roles ),
130 'data' => array(
131 'id' => $userdata->ID,
132 'display_name' => $userdata->display_name,
133 ),
134 );
135 }
136
137 $tutor_currency = array(
138 'symbol' => Settings::get_currency_symbol_by_code( tutor_utils()->get_option( OptionKeys::CURRENCY_CODE, 'USD' ) ),
139 'currency' => tutor_utils()->get_option( OptionKeys::CURRENCY_CODE ),
140 'position' => tutor_utils()->get_option( OptionKeys::CURRENCY_POSITION, 'left' ),
141 'thousand_separator' => tutor_utils()->get_option( OptionKeys::THOUSAND_SEPARATOR, ',' ),
142 'decimal_separator' => tutor_utils()->get_option( OptionKeys::DECIMAL_SEPARATOR, '.' ),
143 'no_of_decimal' => tutor_utils()->get_option( OptionKeys::NUMBER_OF_DECIMALS, '2' ),
144 );
145
146 /**
147 * Get only required options.
148 *
149 * @since 3.0.0
150 */
151 $required_options = array(
152 'monetize_by',
153 );
154
155 $tutor_settings = Options_V2::get_only( $required_options );
156
157 return array(
158 'ajaxurl' => admin_url( 'admin-ajax.php' ),
159 'home_url' => rtrim( get_home_url(), '/' ),
160 'site_url' => rtrim( get_site_url(), '/' ),
161 'site_title' => get_bloginfo( 'title' ),
162 'base_path' => tutor()->basepath,
163 'tutor_url' => tutor()->url,
164 'tutor_pro_url' => function_exists( 'tutor_pro' ) ? tutor_pro()->url : null,
165 'nonce_key' => tutor()->nonce,
166 tutor()->nonce => wp_create_nonce( tutor()->nonce_action ),
167 'loading_icon_url' => get_admin_url() . 'images/wpspin_light.gif',
168 'placeholder_img_src' => tutor_placeholder_img_src(),
169 'enable_lesson_classic_editor' => get_tutor_option( 'enable_lesson_classic_editor' ),
170 'tutor_frontend_dashboard_url' => tutor_utils()->get_tutor_dashboard_page_permalink(),
171 'wp_date_format' => tutor_js_date_format_against_wp(),
172 'start_of_week' => get_option( 'start_of_week', 1 ),
173 'is_admin' => is_admin(),
174 'is_admin_bar_showing' => is_admin_bar_showing(),
175 'addons_data' => tutor_utils()->prepare_free_addons_data(),
176 'current_user' => $current_user,
177 'content_change_event' => 'tutor_content_changed_event',
178 'is_tutor_course_edit' => isset( $_GET['action'] ) && 'edit' === $_GET['action'] && tutor()->course_post_type === get_post_type( get_the_ID() ) ? true : false,
179 'assignment_max_file_allowed' => 'tutor_assignments' === $post_type ? (int) tutor_utils()->get_assignment_option( $post_id, 'upload_files_limit' ) : 0,
180 'current_page' => $current_page,
181 'quiz_answer_display_time' => 1000 * (int) tutor_utils()->get_option( 'quiz_answer_display_time' ),
182 'is_ssl' => is_ssl(),
183 'course_list_page_url' => admin_url( 'admin.php?page=tutor' ),
184 'course_post_type' => tutor()->course_post_type,
185 'tutor_currency' => $tutor_currency,
186 'local' => get_locale(),
187 'settings' => $tutor_settings,
188 'max_upload_size' => wp_max_upload_size(),
189 'monetize_by' => tutor_utils()->get_option( 'monetize_by' ),
190 );
191 }
192
193 /**
194 * Enqueue scripts for admin
195 *
196 * @since 1.0.0
197 * @since 3.0.0 Order details & coupon scripts added.
198 *
199 * @return void
200 */
201 public function admin_scripts() {
202 wp_enqueue_style( 'tutor-select2', tutor()->url . 'assets/lib/select2/select2.min.css', array(), TUTOR_VERSION );
203 wp_enqueue_style( 'tutor-admin', tutor()->url . 'assets/css/tutor-admin.min.css', array(), TUTOR_VERSION );
204 /**
205 * Scripts
206 */
207 wp_enqueue_media();
208
209 wp_enqueue_script( 'wp-color-picker' );
210 wp_enqueue_style( 'wp-color-picker' );
211
212 wp_enqueue_script( 'jquery-ui-slider' );
213 wp_enqueue_script( 'jquery-ui-datepicker' );
214
215 wp_enqueue_script( 'tutor-select2', tutor()->url . 'assets/lib/select2/select2.full.min.js', array( 'jquery' ), TUTOR_VERSION, true );
216 wp_enqueue_script( 'tutor-admin', tutor()->url . 'assets/js/tutor-admin.js', array( 'jquery', 'tutor-script', 'wp-color-picker', 'wp-i18n', 'wp-data' ), TUTOR_VERSION, true );
217
218 // Tutor order detail & coupon scripts.
219 $page = Input::get( 'page', '' );
220 $action = Input::get( 'action' );
221 $sub_page = Input::get( 'sub_page' );
222
223 $allowed_actions = array( 'add_new', 'edit' );
224
225 if ( tutor_utils()->is_monetize_by_tutor() ) {
226 if ( OrderController::PAGE_SLUG === $page && 'edit' === $action ) {
227 wp_enqueue_script( 'tutor-order-details', tutor()->url . 'assets/js/tutor-order-details.js', array( 'wp-i18n', 'wp-element' ), TUTOR_VERSION, true );
228 }
229
230 if ( CouponController::PAGE_SLUG === $page && in_array( $action, $allowed_actions, true ) ) {
231 wp_enqueue_script( 'tutor-coupon', tutor()->url . 'assets/js/tutor-coupon.js', array( 'wp-date', 'wp-i18n', 'wp-element' ), TUTOR_VERSION, true );
232 }
233
234 // @since 3.0.0 add tax react app on the settings page.
235 if ( 'tutor_settings' === $page && ! Input::has( 'edit' ) ) {
236 wp_enqueue_editor();
237 wp_enqueue_script( 'tutor-tax-settings', tutor()->url . 'assets/js/tutor-tax-settings.js', array( 'wp-i18n', 'wp-element' ), TUTOR_VERSION, true );
238 wp_enqueue_script( 'tutor-payment-settings', tutor()->url . 'assets/js/tutor-payment-settings.js', array( 'wp-i18n', 'wp-element' ), TUTOR_VERSION, true );
239 }
240 }
241
242 if ( 'tutor-tools' === $page && 'import_export' === $sub_page ) {
243 wp_enqueue_script( 'tutor-import-export', tutor()->url . 'assets/js/tutor-import-export.js', array( 'wp-i18n', 'wp-element' ), TUTOR_VERSION, true );
244 }
245
246 if ( 'tutor-addons' === $page ) {
247 wp_enqueue_script( 'tutor-coupon', tutor()->url . 'assets/js/tutor-addon-list.js', array( 'wp-i18n', 'wp-element' ), TUTOR_VERSION, true );
248 }
249
250 if ( 'tutor-themes' === $page ) {
251 wp_enqueue_style( 'tutor-template-import', tutor()->url . 'assets/css/tutor-template-import.min.css', array(), TUTOR_VERSION, 'all' );
252 wp_enqueue_script( 'tutor-template-import-js', tutor()->url . 'assets/js/tutor-template-import-script.js', array( 'wp-i18n' ), TUTOR_VERSION, true );
253 }
254 }
255
256 /**
257 * Load frontend scripts
258 *
259 * @since 1.0.0
260 * @return void
261 */
262 public function frontend_scripts() {
263 global $post, $wp_query;
264
265 /**
266 * We checked wp_enqueue_editor() in condition because it conflicting with Divi Builder
267 * condition updated @since v.1.7.4
268 *
269 * @since 2.7.0 is_user_logged_in() check added to remove duplicate H1 tag on each single post.
270 */
271 if ( is_single() && is_user_logged_in() ) {
272 if ( function_exists( 'et_pb_is_pagebuilder_used' ) ) {
273 $is_page_builder_used = et_pb_is_pagebuilder_used( get_the_ID() );
274 if ( ! $is_page_builder_used ) {
275 wp_enqueue_editor();
276 }
277 } else {
278 wp_enqueue_editor();
279 }
280 }
281
282 /**
283 * Initializing quicktags script to use in wp_editor();
284 */
285 wp_enqueue_script( 'quicktags' );
286
287 $tutor_dashboard_page_id = (int) tutor_utils()->get_option( 'tutor_dashboard_page_id' );
288 if ( get_the_ID() === $tutor_dashboard_page_id ) {
289 wp_enqueue_media();
290 }
291
292 /**
293 * Enabling Sorting, draggable, droppable...
294 */
295 wp_enqueue_script( 'jquery-ui-sortable' );
296 wp_enqueue_script('jquery-touch-punch', ['jquery-ui-sortable']); //phpcs:ignore
297
298 // Plyr.
299 if ( is_single_course( true ) ) {
300 wp_enqueue_style( 'tutor-plyr', tutor()->url . 'assets/lib/plyr/plyr.css', array(), TUTOR_VERSION );
301 wp_enqueue_script( 'tutor-plyr', tutor()->url . 'assets/lib/plyr/plyr.polyfilled.min.js', array( 'jquery' ), TUTOR_VERSION, true );
302 }
303
304 // Social Share.
305 wp_enqueue_script( 'tutor-social-share', tutor()->url . 'assets/lib/SocialShare/SocialShare.min.js', array( 'jquery' ), TUTOR_VERSION, true );
306
307 /**
308 * Chart Data
309 */
310 if ( ! empty( $wp_query->query_vars['tutor_dashboard_page'] ) ) {
311 wp_enqueue_script( 'jquery-ui-slider' );
312
313 wp_enqueue_style( 'tutor-select2', tutor()->url . 'assets/lib/select2/select2.min.css', array(), TUTOR_VERSION );
314 wp_enqueue_script( 'tutor-select2', tutor()->url . 'assets/lib/select2/select2.full.min.js', array( 'jquery' ), TUTOR_VERSION, true );
315
316 if ( 'earning' === $wp_query->query_vars['tutor_dashboard_page'] ) {
317 wp_enqueue_script( 'tutor-front-chart-js', tutor()->url . 'assets/lib/Chart.bundle.min.js', array(), TUTOR_VERSION );
318 wp_enqueue_script( 'jquery-ui-datepicker' );
319 }
320 }
321 /**
322 * Dependency wp-i18n added for translate js file
323 *
324 * @since 1.9.0
325 */
326 wp_enqueue_style( 'tutor-frontend', tutor()->url . 'assets/css/tutor-front.min.css', array(), TUTOR_VERSION );
327 wp_enqueue_script( 'tutor-frontend', tutor()->url . 'assets/js/tutor-front.js', array( 'jquery', 'wp-i18n', 'wp-date' ), TUTOR_VERSION, true );
328
329 /**
330 * Load frontend dashboard style
331 *
332 * @since v1.9.8
333 */
334 $should_load_dashboard_styles = apply_filters( 'tutor_should_load_dashboard_styles', tutor_utils()->is_tutor_frontend_dashboard() );
335 if ( $should_load_dashboard_styles ) {
336 wp_enqueue_style( 'tutor-frontend-dashboard-css', tutor()->url . 'assets/css/tutor-frontend-dashboard.min.css', array(), TUTOR_VERSION );
337 }
338
339 // Load date picker for announcement at frontend.
340 wp_enqueue_script( 'jquery-ui-datepicker' );
341 $css = '.mce-notification.mce-notification-error{display: none !important;}';
342 wp_add_inline_style( 'tutor-frontend', $css );
343 }
344
345 /**
346 * Modify localize data
347 *
348 * @since 1.0.0
349 *
350 * @param array $localize_data localize data.
351 * @return array
352 */
353 public function modify_localize_data( $localize_data ) {
354 global $post;
355
356 if ( is_admin() ) {
357 $taxonomy = Input::get( 'taxonomy' );
358 if ( CourseModel::COURSE_CATEGORY === $taxonomy || CourseModel::COURSE_TAG === $taxonomy ) {
359 $localize_data['open_tutor_admin_menu'] = true;
360 }
361
362 if ( 'en_US' !== $localize_data['local'] ) {
363 $page = Input::get( 'page', '' );
364 $action = Input::get( 'action' );
365 $allowed_actions = array( 'add_new', 'edit' );
366 if ( CouponController::PAGE_SLUG === $page && in_array( $action, $allowed_actions, true ) ) {
367 $localize_data['coupon_main_content_locales'] = tutils()->get_script_locale_data( 'tutor-coupon-main-content', $localize_data['local'] );
368 }
369 }
370 } else {
371
372 // Assign quiz option.
373 if ( ! empty( $post->post_type ) && 'tutor_quiz' === $post->post_type ) {
374 $single_quiz_options = (array) tutor_utils()->get_quiz_option( $post->ID );
375 $saved_quiz_options = array(
376 'quiz_when_time_expires' => tutor_utils()->get_option( 'quiz_when_time_expires' ),
377 );
378
379 $quiz_options = array_merge( $single_quiz_options, $saved_quiz_options );
380
381 $previous_attempts = tutor_utils()->quiz_attempts();
382
383 if ( $previous_attempts && count( $previous_attempts ) ) {
384 $quiz_options['quiz_auto_start'] = 0;
385 }
386
387 $localize_data['quiz_options'] = $quiz_options;
388 }
389
390 // Including player assets if video exists.
391 if ( tutor_utils()->has_video_in_single() ) {
392 $localize_data['post_id'] = get_the_ID();
393 $localize_data['best_watch_time'] = 0;
394
395 $best_watch_time = tutor_utils()->get_lesson_reading_info( get_the_ID(), 0, 'video_best_watched_time' );
396 if ( $best_watch_time > 0 ) {
397 $localize_data['best_watch_time'] = $best_watch_time;
398 }
399 }
400 }
401
402 return $localize_data;
403 }
404
405 /**
406 * Load common scripts for frontend and backend
407 *
408 * @since 1.0.0
409 * @return void
410 */
411 public function common_scripts() {
412
413 /**
414 * Load TinyMCE for tutor settings page if tutor pro is not available.
415 *
416 * @since v2.0.8
417 */
418 $baseurl = includes_url( 'js/tinymce' );
419 $current_page = Input::get( 'page' );
420
421 // If it is settings page & tutor pro not activated.
422 if ( 'tutor_settings' === $current_page && ! wp_script_is( 'wp-tinymce-root' ) ) {
423 wp_enqueue_script( 'tutor-tiny', $baseurl . '/tinymce.min.js', array( 'jquery' ), TUTOR_VERSION, true );
424 }
425 wp_enqueue_style( 'tutor-icon', tutor()->url . 'assets/css/tutor-icon.min.css', array(), TUTOR_VERSION );
426
427 // Common css library.
428 if ( is_rtl() ) {
429 wp_enqueue_style( 'tutor', tutor()->url . 'assets/css/tutor-rtl.min.css', array(), TUTOR_VERSION );
430 } else {
431 wp_enqueue_style( 'tutor', tutor()->url . 'assets/css/tutor.min.css', array(), TUTOR_VERSION );
432 }
433
434 /**
435 * Load tutor common scripts both backend and frontend
436 *
437 * @since v2.0.0
438 */
439 wp_enqueue_script( 'tutor-script', tutor()->url . 'assets/js/tutor.js', array( 'jquery', 'wp-i18n', 'wp-element' ), TUTOR_VERSION, true );
440
441 /**
442 * Enqueue datetime countdown scripts & styles
443 *
444 * Add filter to enqueue countdown scripts & styles
445 * don't return false if it is true to prevent conflict
446 * with other filters
447 *
448 * @since v2.1.0
449 */
450 $should_enqueue = apply_filters( 'tutor_should_enqueue_countdown_scripts', false );
451 if ( $should_enqueue ) {
452 wp_enqueue_script( 'tutor-moment', tutor()->url . 'assets/lib/countdown/moment.min.js', array(), TUTOR_VERSION, true );
453
454 wp_enqueue_script( 'tutor-moment-timezone', tutor()->url . 'assets/lib/countdown/moment-timezone-with-data.min.js', array(), TUTOR_VERSION, true );
455
456 wp_enqueue_script( 'tutor-jquery-countdown', tutor()->url . 'assets/lib/countdown/jquery.countdown.min.js', array( 'jquery' ), TUTOR_VERSION, true );
457
458 wp_enqueue_script( 'tutor-countdown', tutor()->url . 'assets/lib/countdown/tutor-countdown.min.js', array( 'jquery' ), TUTOR_VERSION, true );
459
460 wp_enqueue_style( 'tutor-countdown', tutor()->url . 'assets/lib/countdown/tutor-countdown.min.css', '', TUTOR_VERSION );
461 }
462 }
463
464 /**
465 * Load meta data
466 *
467 * @since 1.0.0
468 * @return void
469 */
470 public function load_meta_data() {
471 // Localize scripts.
472 $localize_data = apply_filters( 'tutor_localize_data', $this->get_default_localized_data() );
473 wp_localize_script( 'tutor-frontend', '_tutorobject', $localize_data );
474 wp_localize_script( 'tutor-admin', '_tutorobject', $localize_data );
475 wp_localize_script( 'tutor-script', '_tutorobject', $localize_data );
476 wp_localize_script( 'tutor-order-details', '_tutorobject', $localize_data );
477 wp_localize_script( 'tutor-tax-settings', '_tutorobject', $localize_data );
478 wp_localize_script( 'tutor-coupon', '_tutorobject', $localize_data );
479 wp_localize_script( 'tutor-course-builder', '_tutorobject', $localize_data );
480
481 // Inline styles.
482 wp_add_inline_style( 'tutor-frontend', $this->load_color_palette() );
483 wp_add_inline_style( 'tutor-admin', $this->load_color_palette() );
484 }
485
486 /**
487 * Load color palette
488 *
489 * @since 1.0.0
490 * @return string
491 */
492 private function load_color_palette() {
493 $colors = array(
494 'tutor_primary_color' => '--tutor-color-primary',
495 'tutor_primary_hover_color' => '--tutor-color-primary-hover',
496 'tutor_text_color' => '--tutor-body-color',
497 'tutor_border_color' => '--tutor-border-color',
498 'tutor_gray_color' => '--tutor-color-gray',
499 );
500
501 // Admin colors.
502 $admin_colors = array();
503 if ( is_admin() ) {
504 $admin_colors = array(
505 '--tutor-color-primary' => '#3E64DE',
506 '--tutor-color-primary-hover' => '#3A5CCC',
507 '--tutor-body-color' => '#212327',
508 '--tutor-border-color' => '#CDCFD5',
509 '--tutor-color-gray' => '#CDCFD5',
510 );
511 }
512
513 $fallback_colors = array(
514 'tutor_primary_color' => '#3E64DE',
515 'tutor_primary_hover_color' => '#3A5CCC',
516 'tutor_text_color' => '#212327',
517 'tutor_border_color' => '#E3E5EB',
518 'tutor_gray_color' => '#CDCFD5',
519 );
520
521 $color_string = '';
522 foreach ( $colors as $key => $property ) {
523 $fallback_color = isset( $fallback_colors[ $key ] ) ? $fallback_colors[ $key ] : '#212327';
524 $color = tutor_utils()->get_option( $key, $fallback_color );
525 $color_rgb = tutor_utils()->hex2rgb( $color );
526
527 if ( is_admin() && isset( $admin_colors[ $property ] ) ) {
528 $color = $admin_colors[ $property ];
529 $color_rgb = tutor_utils()->hex2rgb( $admin_colors[ $property ] );
530 }
531
532 if ( $color ) {
533 $color_string .= $property . ':' . $color . ';';
534 }
535
536 if ( $color_rgb ) {
537 $color_string .= $property . '-rgb:' . $color_rgb . ';';
538 }
539 }
540
541 return ':root{' . $color_string . '}';
542 }
543
544 /**
545 * Add Tinymce button for placing shortcode
546 *
547 * @since 1.0.0
548 * @return void|null
549 */
550 public function tutor_add_mce_button() {
551 // Check user permissions.
552 if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
553 return;
554 }
555 // Check if WYSIWYG is enabled.
556 if ( 'true' == get_user_option( 'rich_editing' ) ) {
557 add_filter( 'mce_external_plugins', array( $this, 'tutor_add_tinymce_js' ) );
558 add_filter( 'mce_buttons', array( $this, 'tutor_register_mce_button' ) );
559 }
560 }
561
562 /**
563 * Add tinymce button
564 *
565 * @since 1.0.0
566 *
567 * @param array $plugin_array plugin array.
568 * @return array
569 */
570 public function tutor_add_tinymce_js( $plugin_array ) {
571 $plugin_array['tutor_button'] = tutor()->url . 'assets/lib/mce-button.js';
572 return $plugin_array;
573 }
574
575 /**
576 * Register new button in the editor
577 *
578 * @since 1.0.0
579 *
580 * @param array $buttons buttons.
581 * @return array
582 */
583 public function tutor_register_mce_button( $buttons ) {
584 array_push( $buttons, 'tutor_button' );
585 return $buttons;
586 }
587
588 /**
589 * Output generator tag to aid debugging.
590 *
591 * @since 1.0.0
592 *
593 * @param string $gen Generator.
594 * @param string $type Type.
595 *
596 * @return string
597 */
598 public function tutor_generator_tag( $gen, $type ) {
599 switch ( $type ) {
600 case 'html':
601 $gen .= "\n" . '<meta name="generator" content="TutorLMS ' . TUTOR_VERSION . '">';
602 break;
603 case 'xhtml':
604 $gen .= "\n" . '<meta name="generator" content="TutorLMS ' . TUTOR_VERSION . '" />';
605 break;
606 }
607 return $gen;
608 }
609
610 /**
611 * Load text domain handled script after all enqueue_scripts
612 * registered functions
613 *
614 * @since 1.9.0
615 * @since 3.9.2 Refactored to dynamically detect scripts instead of hardcoded list.
616 *
617 * @return void
618 */
619 public function tutor_script_text_domain() {
620 global $wp_scripts;
621
622 if ( empty( $wp_scripts->registered ) ) {
623 return;
624 }
625
626 foreach ( $wp_scripts->registered as $handle => $data ) {
627 $src = $data->src ?? '';
628 $is_from_tutor = str_contains( $src, 'tutor/assets/js' );
629
630 if ( ! $is_from_tutor ) {
631 continue;
632 }
633
634 wp_set_script_translations( $handle, 'tutor', tutor()->path . 'languages/' );
635 }
636 }
637
638 /**
639 * Add translation support for external tinyMCE button
640 *
641 * @since 1.9.7
642 * @return array
643 */
644 public function tutor_tinymce_translate() {
645 $locales['tutor_button'] = tutor()->path . 'includes/tinymce_translate.php';
646 return $locales;
647 }
648
649 /**
650 * Add an identifier class to body
651 *
652 * @since 1.0.0
653 *
654 * @param mixed $classes classes.
655 * @return mixed
656 */
657 public function add_identifier_class_to_body( $classes ) {
658 $course_builder_screen = tutor_utils()->get_course_builder_screen();
659 $to_add = array( 'tutor-lms' );
660
661 // Add backend course editor identifier class to body.
662 if ( $course_builder_screen ) {
663 $to_add[] = is_admin() ? 'tutor-backend' : 'tutor-frontend';
664 $to_add[] = ' tutor-screen-course-builder tutor-screen-course-builder-' . $course_builder_screen . ' ';
665 }
666
667 // Add frontend course builder identifier class.
668 if ( ! $course_builder_screen && tutor_utils()->is_tutor_frontend_dashboard() ) {
669 $to_add[] = 'tutor-screen-frontend-dashboard';
670 }
671
672 if ( is_post_type_archive( tutor()->course_post_type ) ) {
673 $to_add[] = 'tutor-frontend';
674 }
675
676 if ( tutor_utils()->is_tutor_frontend_dashboard() ) {
677 $to_add[] = 'tutor-frontend';
678 }
679
680 if ( is_single() ) {
681 global $post;
682
683 $post_types = array(
684 tutor()->course_post_type,
685 tutor()->lesson_post_type,
686 tutor()->quiz_post_type,
687 tutor()->assignment_post_type,
688 tutor()->zoom_post_type,
689 tutor()->meet_post_type,
690 );
691
692 if ( isset( $post->post_type ) && in_array( $post->post_type, $post_types, true ) ) {
693 $to_add[] = 'tutor-frontend';
694 }
695 }
696
697 if ( is_admin() ) {
698 $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
699 $base = ( $screen && is_object( $screen ) && property_exists( $screen, 'base' ) ) ? $screen->base : '';
700 $index = strpos( $base, 'tutor' );
701
702 if ( 0 === $index || $index > 0 ) {
703 $to_add[] = 'tutor-backend';
704
705 $page = Input::get( 'page' );
706 if ( 'tutor_settings' === $page ) {
707 $to_add[] = 'tutor-screen-backend-settings ';
708 }
709 if ( ! empty( $page ) ) {
710 $to_add[] = 'tutor-backend-' . $page;
711 }
712 }
713 }
714
715 // Remove duplicate classes if any.
716 $to_add = array_unique( $to_add );
717
718 if ( is_array( $classes ) ) {
719 $classes = array_merge( $classes, $to_add );
720 } else {
721 $classes .= implode( ' ', $to_add );
722 }
723
724 return $classes;
725 }
726
727 /**
728 * Enqueue script for adding edit with frontend course builder button
729 * on the Gutenberg editor
730 *
731 * @since 2.0.5
732 * @return void
733 */
734 public static function add_frontend_editor_button() {
735 $wp_screen = get_current_screen();
736
737 if ( is_a( $wp_screen, 'WP_Screen' ) && tutor()->course_post_type === $wp_screen->post_type ) {
738 wp_enqueue_script( 'tutor-gutenberg', tutor()->url . 'assets/js/tutor-gutenberg.js', array(), TUTOR_VERSION, true );
739 $data = array(
740 'frontend_dashboard_url' => esc_url( trailingslashit( tutor_utils()->tutor_dashboard_url( 'create-course' ) ) ) . '?course_id=' . get_the_ID(),
741 );
742
743 wp_add_inline_script(
744 'tutor-gutenberg',
745 'const tutorInlineData =' . json_encode( $data ),
746 'before'
747 );
748 }
749 }
750 }
751