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