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