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.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 4 years ago Admin.php 4 years ago Ajax.php 4 years ago Announcements.php 4 years ago Assets.php 4 years ago Backend_Page_Trait.php 4 years ago Course.php 4 years ago Course_Filter.php 4 years ago Course_List.php 4 years ago Course_Settings_Tabs.php 4 years ago Course_Widget.php 4 years ago Custom_Validation.php 5 years ago Dashboard.php 4 years ago FormHandler.php 4 years ago Frontend.php 4 years ago Gutenberg.php 4 years ago Instructor.php 4 years ago Instructors_List.php 4 years ago Lesson.php 4 years ago Options_V2.php 4 years ago Post_types.php 4 years ago Private_Course_Access.php 4 years ago Q_and_A.php 4 years ago Question_Answers_List.php 4 years ago Quiz.php 4 years ago Quiz_Attempts_List.php 4 years ago RestAPI.php 4 years ago Reviews.php 4 years ago Rewrite_Rules.php 4 years ago Shortcode.php 4 years ago Student.php 4 years ago Students_List.php 4 years ago Taxonomies.php 4 years ago Template.php 4 years ago Theme_Compatibility.php 5 years ago Tools.php 4 years ago Tools_V2.php 4 years ago Tutor.php 4 years ago TutorEDD.php 4 years ago Tutor_Base.php 5 years ago Tutor_List_Table.php 4 years ago Tutor_Setup.php 4 years ago Upgrader.php 4 years ago User.php 4 years ago Utils.php 4 years ago Video_Stream.php 4 years ago Withdraw.php 4 years ago Withdraw_Requests_List.php 4 years ago WooCommerce.php 4 years ago
Assets.php
441 lines
1 <?php
2
3 namespace TUTOR;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 class Assets {
10
11 public function __construct()
12 {
13 /**
14 * Common scripts loading
15 */
16 add_action('admin_enqueue_scripts', array($this, 'common_scripts'));
17 add_action('wp_enqueue_scripts', array($this, 'common_scripts'));
18 /**
19 * Front and backend script enqueue
20 */
21 add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
22 add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
23
24 add_action('admin_enqueue_scripts', array($this, 'load_meta_data'));
25 add_action('wp_enqueue_scripts', array($this, 'load_meta_data'));
26
27 /**
28 * Text domain loading
29 */
30 add_action( 'admin_enqueue_scripts', array( $this, 'tutor_script_text_domain' ), 100 );
31 add_action( 'wp_enqueue_scripts', array( $this, 'tutor_script_text_domain' ), 100 );
32 add_filter( 'tutor_localize_data', array( $this, 'modify_localize_data' ) );
33
34 /**
35 * register translateable function to load
36 * handled script with text domain attached to
37 *
38 * @since 1.9.0
39 */
40 add_action( 'admin_head', array( $this, 'tutor_add_mce_button' ) );
41 add_filter( 'get_the_generator_html', array( $this, 'tutor_generator_tag' ), 10, 2 );
42 add_filter( 'get_the_generator_xhtml', array( $this, 'tutor_generator_tag' ), 10, 2 );
43
44 /**
45 * Add translation support for external tinyMCE button
46 *
47 * @since 1.9.7
48 */
49 add_filter('mce_external_languages', array($this, 'tutor_tinymce_translate'));
50
51 /**
52 * Identifier class to body tag
53 *
54 * @since v1.9.9
55 */
56 add_filter( 'body_class', array( $this, 'add_identifier_class_to_body' ) );
57 add_filter( 'admin_body_class', array( $this, 'add_identifier_class_to_body' ) );
58 }
59
60 private function get_default_localized_data()
61 {
62 global $wp_version;
63 $home_url = get_home_url();
64 $parsed = parse_url($home_url);
65
66 $base_path = (is_array($parsed) && isset($parsed['path'])) ? $parsed['path'] : '/';
67 $base_path = rtrim($base_path, '/') . '/';
68
69 $post_id = get_the_ID();
70 $post_type = get_post_type( $post_id );
71
72 return array(
73 'ajaxurl' => admin_url( 'admin-ajax.php' ),
74 'home_url' => get_home_url(),
75 'site_title' => get_bloginfo( 'title' ),
76 'base_path' => tutor()->basepath,
77 'tutor_url' => tutor()->url,
78 'tutor_pro_url' => function_exists( 'tutor_pro' ) ? tutor_pro()->url : null,
79 'nonce_key' => tutor()->nonce,
80 tutor()->nonce => wp_create_nonce( tutor()->nonce_action ),
81 'loading_icon_url' => get_admin_url() . 'images/wpspin_light.gif',
82 'placeholder_img_src' => tutor_placeholder_img_src(),
83 'enable_lesson_classic_editor' => get_tutor_option( 'enable_lesson_classic_editor' ),
84 'tutor_frontend_dashboard_url' => tutor_utils()->get_tutor_dashboard_page_permalink(),
85 'wp_date_format' => tutor_js_date_format_against_wp(),
86 'is_admin' => is_admin(),
87 'is_admin_bar_showing' => is_admin_bar_showing(),
88 'addons_data' => tutor_utils()->prepare_free_addons_data(),
89 'current_user' => wp_get_current_user(),
90 'content_change_event' => 'tutor_content_changed_event',
91 'is_tutor_course_edit' => isset( $_GET[ 'action'] ) && 'edit' === $_GET['action'] && tutor()->course_post_type === get_post_type( get_the_ID() ) || isset( $_GET['post_type'] ) && 'courses' === $_GET['post_type'] ? true : false,
92 'assignment_max_file_allowed' => 'tutor_assignments' === $post_type ? (int) tutor_utils()->get_assignment_option( $post_id, 'upload_files_limit' ) : 0,
93 );
94 }
95
96 public function admin_scripts()
97 {
98 wp_enqueue_style('tutor-select2', tutor()->url . 'assets/packages/select2/select2.min.css', array(), TUTOR_VERSION);
99 wp_enqueue_style('tutor-admin', tutor()->url . 'assets/css/tutor-admin.min.css', array(), TUTOR_VERSION);
100 /**
101 * Scripts
102 */
103 wp_enqueue_media();
104
105 wp_enqueue_script('wp-color-picker');
106 wp_enqueue_style('wp-color-picker');
107
108 wp_enqueue_script( 'jquery-ui-slider' );
109 wp_enqueue_script( 'jquery-ui-datepicker' );
110
111 wp_enqueue_script('tutor-select2', tutor()->url . 'assets/packages/select2/select2.full.min.js', array('jquery'), TUTOR_VERSION, true);
112 wp_enqueue_script('tutor-admin', tutor()->url . 'assets/js/tutor-admin.min.js', array('jquery', 'wp-color-picker', 'wp-i18n'), TUTOR_VERSION, true);
113 }
114
115 /**
116 * Load frontend scripts
117 */
118 public function frontend_scripts()
119 {
120 global $post, $wp_query;
121
122 /**
123 * We checked wp_enqueue_editor() in condition because it conflicting with Divi Builder
124 * condition updated @since v.1.7.4
125 */
126
127 if ( is_single() ) {
128 if ( function_exists( 'et_pb_is_pagebuilder_used' ) ) {
129 $is_page_builder_used = et_pb_is_pagebuilder_used( get_the_ID() );
130 if ( ! $is_page_builder_used ) {
131 wp_enqueue_editor();
132 }
133 } else {
134 wp_enqueue_editor();
135 }
136 }
137
138 /**
139 * Initializing quicktags script to use in wp_editor();
140 */
141 wp_enqueue_script( 'quicktags' );
142
143 $tutor_dashboard_page_id = (int) tutor_utils()->get_option( 'tutor_dashboard_page_id' );
144 if ( $tutor_dashboard_page_id === get_the_ID() ) {
145 wp_enqueue_media();
146 }
147
148 /**
149 * Enabling Sorting, draggable, droppable...
150 */
151 wp_enqueue_script( 'jquery-ui-sortable' );
152
153 // Plyr
154 if(is_single_course(true)) {
155 wp_enqueue_style('tutor-plyr', tutor()->url . 'assets/packages/plyr/plyr.css', array(), TUTOR_VERSION);
156 wp_enqueue_script('tutor-plyr', tutor()->url . 'assets/packages/plyr/plyr.polyfilled.min.js', array('jquery'), TUTOR_VERSION, true);
157 }
158
159 // Social Share
160 wp_enqueue_script('tutor-social-share', tutor()->url . 'assets/packages/SocialShare/SocialShare.min.js', array('jquery'), TUTOR_VERSION, true);
161
162 /**
163 * Chart Data
164 */
165 if (!empty($wp_query->query_vars['tutor_dashboard_page'])) {
166 wp_enqueue_script('jquery-ui-slider');
167
168 wp_enqueue_style('tutor-select2', tutor()->url . 'assets/packages/select2/select2.min.css', array(), TUTOR_VERSION);
169 wp_enqueue_script('tutor-select2', tutor()->url . 'assets/packages/select2/select2.full.min.js', array('jquery'), TUTOR_VERSION, true);
170
171 if ($wp_query->query_vars['tutor_dashboard_page'] === 'earning') {
172 wp_enqueue_script('tutor-front-chart-js', tutor()->url . 'assets/js/lib/Chart.bundle.min.js', array(), TUTOR_VERSION);
173 wp_enqueue_script('jquery-ui-datepicker');
174 }
175 }
176 /**
177 * dependency wp-i18n added for
178 * translate js file
179 *
180 * @since 1.9.0
181 */
182 wp_enqueue_style('tutor-frontend', tutor()->url . 'assets/css/tutor-front.min.css', array(), TUTOR_VERSION);
183 wp_enqueue_script('tutor-frontend', tutor()->url . 'assets/js/tutor-front.min.js', array('jquery', 'wp-i18n'), TUTOR_VERSION, true );
184
185 /**
186 * Load frontend dashboard style
187 *
188 * @since v1.9.8
189 */
190 if (tutor_utils()->is_tutor_frontend_dashboard()) {
191 wp_enqueue_style('tutor-frontend-dashboard-css', tutor()->url . 'assets/css/tutor-frontend-dashboard.min.css', TUTOR_VERSION);
192 }
193
194 // Load date picker for announcement at frontend
195 wp_enqueue_script( 'jquery-ui-datepicker' );
196 }
197
198 public function modify_localize_data($localize_data)
199 {
200 global $post;
201
202 if ( is_admin() ) {
203 if ( ! empty( $_GET['taxonomy'] ) && ( $_GET['taxonomy'] === 'course-category' || $_GET['taxonomy'] === 'course-tag' ) ) {
204 $localize_data['open_tutor_admin_menu'] = true;
205 }
206 } else {
207
208 // Assign quiz option
209 if (!empty($post->post_type) && $post->post_type === 'tutor_quiz') {
210 $single_quiz_options = (array) tutor_utils()->get_quiz_option($post->ID);
211 $saved_quiz_options = array(
212 'quiz_when_time_expires' => tutor_utils()->get_option('quiz_when_time_expires'),
213 );
214
215 $quiz_options = array_merge($single_quiz_options, $saved_quiz_options);
216
217 $previous_attempts = tutor_utils()->quiz_attempts();
218
219 if ($previous_attempts && count($previous_attempts)) {
220 $quiz_options['quiz_auto_start'] = 0;
221 }
222
223 $localize_data['quiz_options'] = $quiz_options;
224 }
225
226 // Including player assets if video exists
227 if ( tutor_utils()->has_video_in_single() ) {
228 $localize_data['post_id'] = get_the_ID();
229 $localize_data['best_watch_time'] = 0;
230
231 $best_watch_time = tutor_utils()->get_lesson_reading_info( get_the_ID(), 0, 'video_best_watched_time' );
232 if ( $best_watch_time > 0 ) {
233 $localize_data['best_watch_time'] = $best_watch_time;
234 }
235 }
236 }
237
238 return $localize_data;
239 }
240
241 public function common_scripts() {
242
243 // Fonts
244 wp_enqueue_style('tutor-inter-fonts', 'https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap', array(), TUTOR_VERSION);
245 wp_enqueue_style('tutor-icon', tutor()->url . 'assets/css/tutor-icon.css', array(), TUTOR_VERSION);
246
247 // Common css library
248 wp_enqueue_style('tutor', tutor()->url . 'assets/css/tutor.min.css', array(), TUTOR_VERSION);
249
250 // Load course builder resources
251 if ($this->get_course_builder_screen()) {
252 wp_enqueue_script('tutor-course-builder', tutor()->url . 'assets/js/tutor-course-builder.min.js', array('jquery', 'wp-i18n'), TUTOR_VERSION, true);
253 wp_enqueue_style('tutor-course-builder-css', tutor()->url . 'assets/css/tutor-course-builder.min.css', array(), TUTOR_VERSION);
254 }
255 /**
256 * Load tutor common scripts both backend and frontend
257 *
258 * @since v2.0.0
259 */
260 wp_enqueue_script('tutor-script', tutor()->url . 'assets/js/tutor.min.js', array('jquery', 'wp-i18n'), TUTOR_VERSION, true);
261 }
262
263 public function load_meta_data()
264 {
265 // Localize scripts
266 $localize_data = apply_filters('tutor_localize_data', $this->get_default_localized_data());
267 wp_localize_script('tutor-frontend', '_tutorobject', $localize_data);
268 wp_localize_script('tutor-admin', '_tutorobject', $localize_data);
269 wp_localize_script('tutor-course-builder', '_tutorobject', $localize_data);
270 wp_localize_script('tutor-script', '_tutorobject', $localize_data);
271
272 // Inline styles
273 wp_add_inline_style('tutor-frontend', $this->load_color_palette());
274 wp_add_inline_style('tutor-admin', $this->load_color_palette());
275 }
276
277 private function load_color_palette()
278 {
279 $colors = array(
280 'tutor_primary_color' => '--tutor-primary-color',
281 'tutor_primary_hover_color' => '--tutor-primary-hover-color',
282 'tutor_text_color' => '--tutor-text-color',
283 'tutor_background_color' => '--tutor-background-color',
284 'tutor_border_color' => '--tutor-border-color',
285 'tutor_success_color' => '--tutor-success-color',
286 'tutor_warning_color' => '--tutor-warning-color',
287 'tutor_danger_color' => '--tutor-danger-color',
288 'tutor_disable_color' => '--tutor-disable-color',
289 'tutor_table_background_color' => '--tutor-table-background-color',
290
291 'tutor_primary_text_color' => '--tutor-primary-text-color',
292 'tutor_light_color' => '--tutor-light-color',
293 'tutor_button_primary' => '--tutor-primary-button-color',
294 'tutor_button_danger' => '--tutor-danger-button-color',
295 'tutor_button_success' => '--tutor-success-button-color',
296 'tutor_button_warning' => '--tutor-warning-button-color',
297 );
298
299 $color_string = '';
300 foreach ($colors as $key => $property) {
301 $color = tutor_utils()->get_option($key);
302 if ($color) {
303 $color_string .= $property . ':' . $color . ';';
304 }
305 }
306
307 return ':root{' . $color_string . '}';
308 }
309
310 /**
311 * Add Tinymce button for placing shortcode
312 */
313 function tutor_add_mce_button()
314 {
315 // check user permissions
316 if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) {
317 return;
318 }
319 // check if WYSIWYG is enabled
320 if ('true' == get_user_option('rich_editing')) {
321 add_filter('mce_external_plugins', array($this, 'tutor_add_tinymce_js'));
322 add_filter('mce_buttons', array($this, 'tutor_register_mce_button'));
323 }
324 }
325 // Declare script for new button
326 function tutor_add_tinymce_js($plugin_array)
327 {
328 $plugin_array['tutor_button'] = tutor()->url . 'assets/js/lib/mce-button.js';
329 return $plugin_array;
330 }
331 // Register new button in the editor
332 function tutor_register_mce_button($buttons)
333 {
334 array_push($buttons, 'tutor_button');
335 return $buttons;
336 }
337
338 /**
339 * Output generator tag to aid debugging.
340 *
341 * @param string $gen Generator.
342 * @param string $type Type.
343 * @return string
344 */
345 function tutor_generator_tag($gen, $type)
346 {
347 switch ($type) {
348 case 'html':
349 $gen .= "\n" . '<meta name="generator" content="TutorLMS ' . TUTOR_VERSION . '">';
350 break;
351 case 'xhtml':
352 $gen .= "\n" . '<meta name="generator" content="TutorLMS ' . TUTOR_VERSION . '" />';
353 break;
354 }
355 return $gen;
356 }
357
358 /**
359 * load text domain handled script after all enqueue_scripts
360 * registered functions
361 *
362 * @since 1.9.0
363 */
364 function tutor_script_text_domain() {
365 wp_set_script_translations( 'tutor-frontend', 'tutor', tutor()->path . 'languages/' );
366 wp_set_script_translations( 'tutor-admin', 'tutor', tutor()->path . 'languages/' );
367 wp_set_script_translations( 'tutor-course-builder', 'tutor', tutor()->path . 'languages/' );
368 }
369
370 /**
371 * Add translation support for external tinyMCE button
372 *
373 * @since 1.9.7
374 */
375 function tutor_tinymce_translate() {
376 $locales['tutor_button'] = tutor()->path . 'includes/tinymce_translate.php';
377 return $locales;
378 }
379
380 private function get_course_builder_screen()
381 {
382
383 // Add course editor identifier class
384 if ( is_admin() ) {
385 $screen = get_current_screen();
386 if ( is_object( $screen ) && $screen->base == 'post' && $screen->id == 'courses' ) {
387 return $screen->is_block_editor ? 'gutenberg' : 'classic';
388 }
389 } elseif ( tutor_utils()->is_tutor_frontend_dashboard( 'create-course' ) ) {
390 return 'frontend';
391 }
392
393 return null;
394 }
395
396 public function add_identifier_class_to_body($classes)
397 {
398 $course_builder_screen = $this->get_course_builder_screen();
399 $to_add = array();
400
401 // Add backend course editor identifier class to body
402 if ($course_builder_screen) {
403 $to_add[] = is_admin() ? 'tutor-backend' : '';
404 $to_add[] = ' tutor-screen-course-builder tutor-screen-course-builder-' . $course_builder_screen . ' ';
405 }
406
407 // Add frontend course builder identifier class
408 if (!$course_builder_screen && tutor_utils()->is_tutor_frontend_dashboard()) {
409 $to_add[] = 'tutor-screen-frontend-dashboard';
410 }
411
412 if (is_admin()) {
413 $screen = function_exists('get_current_screen') ? get_current_screen() : null;
414 $base = ($screen && is_object($screen) && property_exists($screen, 'base')) ? $screen->base : '';
415 $index = strpos($base, 'tutor');
416
417 if($index===0 || $index>0) {
418 $to_add[] = 'tutor-backend';
419
420 if (isset($_GET['page']) && $_GET['page'] == 'tutor_settings') {
421 $to_add[] = 'tutor-screen-backend-settings ';
422 }
423 if (isset($_GET['page'])) {
424 $to_add[] = 'tutor-backend-' . $_GET['page'];
425 }
426 }
427 }
428
429 // Remove duplicate classes if any
430 $to_add = array_unique($to_add);
431
432 if(is_array($classes)) {
433 $classes = array_merge($classes, $to_add);
434 } else {
435 $classes .= implode(' ', $to_add);
436 }
437
438 return $classes;
439 }
440 }
441