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