Addons.php
5 years ago
Admin.php
5 years ago
Ajax.php
5 years ago
Assets.php
5 years ago
Course.php
5 years ago
Course_Filter.php
5 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
5 years ago
Instructor.php
5 years ago
Instructors_List.php
5 years ago
Lesson.php
5 years ago
Options.php
5 years ago
Post_types.php
5 years ago
Private_Course_Access.php
5 years ago
Q_and_A.php
5 years ago
Question_Answers_List.php
5 years ago
Quiz.php
5 years ago
Quiz_Attempts_List.php
5 years ago
RestAPI.php
5 years ago
Rewrite_Rules.php
5 years ago
Shortcode.php
5 years ago
Student.php
5 years ago
Students_List.php
5 years ago
Taxonomies.php
5 years ago
Template.php
5 years ago
Theme_Compatibility.php
5 years ago
Tools.php
5 years ago
Tutor.php
5 years ago
TutorEDD.php
5 years ago
Tutor_Base.php
5 years ago
Tutor_List_Table.php
5 years ago
Tutor_Setup.php
5 years ago
Upgrader.php
5 years ago
User.php
5 years ago
Utils.php
5 years ago
Video_Stream.php
5 years ago
Withdraw.php
5 years ago
Withdraw_Requests_List.php
5 years ago
WooCommerce.php
5 years ago
Assets.php
267 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('wp_enqueue_scripts', array($this, 'frontend_scripts')); |
| 12 | add_action( 'admin_head', array($this, 'tutor_add_mce_button')); |
| 13 | add_filter( 'get_the_generator_html', array($this, 'tutor_generator_tag'), 10, 2 ); |
| 14 | add_filter( 'get_the_generator_xhtml', array($this, 'tutor_generator_tag'), 10, 2 ); |
| 15 | } |
| 16 | |
| 17 | public function admin_scripts(){ |
| 18 | wp_enqueue_style('tutor-select2', tutor()->url.'assets/packages/select2/select2.min.css', array(), tutor()->version); |
| 19 | wp_enqueue_style('tutor-admin', tutor()->url.'assets/css/tutor-admin.min.css', array(), tutor()->version); |
| 20 | wp_enqueue_style('tutor-icon', tutor()->url.'assets/icons/css/tutor-icon.css', array(), tutor()->version); |
| 21 | |
| 22 | /** |
| 23 | * Scripts |
| 24 | */ |
| 25 | wp_enqueue_media(); |
| 26 | |
| 27 | wp_enqueue_script( 'wp-color-picker' ); |
| 28 | wp_enqueue_style( 'wp-color-picker' ); |
| 29 | |
| 30 | wp_enqueue_script('jquery-ui-slider'); |
| 31 | wp_enqueue_script('jquery-ui-datepicker'); |
| 32 | |
| 33 | wp_enqueue_script('tutor-select2', tutor()->url.'assets/packages/select2/select2.full.min.js', array('jquery'), tutor()->version, true ); |
| 34 | wp_enqueue_script( 'tutor-main', tutor()->url . 'assets/js/tutor.js', array( 'jquery' ), tutor()->version, true ); |
| 35 | wp_enqueue_script('tutor-admin', tutor()->url.'assets/js/tutor-admin.js', array('jquery', 'wp-color-picker'), tutor()->version, true ); |
| 36 | |
| 37 | $tutor_localize_data = array( |
| 38 | 'delete_confirm_text' => __('Are you sure? it can not be undone.', 'tutor'), |
| 39 | 'tutor_url' => tutor()->url, |
| 40 | 'nonce_key' => tutor()->nonce, |
| 41 | tutor()->nonce => wp_create_nonce( tutor()->nonce_action ), |
| 42 | ); |
| 43 | if ( ! empty($_GET['taxonomy']) && ( $_GET['taxonomy'] === 'course-category' || $_GET['taxonomy'] === 'course-tag') ){ |
| 44 | $tutor_localize_data['open_tutor_admin_menu'] = true; |
| 45 | } |
| 46 | |
| 47 | wp_localize_script('tutor-admin', 'tutor_data', $tutor_localize_data); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Load frontend scripts |
| 52 | */ |
| 53 | public function frontend_scripts(){ |
| 54 | global $post, $wp_query; |
| 55 | |
| 56 | $is_script_debug = tutor_utils()->is_script_debug(); |
| 57 | $suffix = $is_script_debug ? '' : '.min'; |
| 58 | |
| 59 | /** |
| 60 | * We checked wp_enqueue_editor() in condition because it conflicting with Divi Builder |
| 61 | * condition updated @since v.1.7.4 |
| 62 | */ |
| 63 | |
| 64 | if (is_single()){ |
| 65 | if (function_exists('et_pb_is_pagebuilder_used')) { |
| 66 | $is_page_builder_used = et_pb_is_pagebuilder_used(get_the_ID()); |
| 67 | if (!$is_page_builder_used) { |
| 68 | wp_enqueue_editor(); |
| 69 | } |
| 70 | } else { |
| 71 | wp_enqueue_editor(); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Initializing quicktags script to use in wp_editor(); |
| 77 | */ |
| 78 | wp_enqueue_script( 'quicktags'); |
| 79 | |
| 80 | $tutor_dashboard_page_id = (int) tutor_utils()->get_option('tutor_dashboard_page_id'); |
| 81 | if ($tutor_dashboard_page_id === get_the_ID()){ |
| 82 | wp_enqueue_media(); |
| 83 | } |
| 84 | |
| 85 | //$options = tutor_utils()->get_option(); |
| 86 | $localize_data = array( |
| 87 | 'ajaxurl' => admin_url('admin-ajax.php'), |
| 88 | 'tutor_url' => tutor()->url, |
| 89 | 'nonce_key' => tutor()->nonce, |
| 90 | tutor()->nonce => wp_create_nonce( tutor()->nonce_action ), |
| 91 | //'options' => $options, |
| 92 | 'placeholder_img_src' => tutor_placeholder_img_src(), |
| 93 | 'enable_lesson_classic_editor' => get_tutor_option('enable_lesson_classic_editor'), |
| 94 | |
| 95 | 'text' => array( |
| 96 | 'assignment_text_validation_msg' => __('Assignment answer can not be empty', 'tutor'), |
| 97 | ), |
| 98 | ); |
| 99 | |
| 100 | if ( ! empty($post->post_type) && $post->post_type === 'tutor_quiz'){ |
| 101 | $single_quiz_options = (array) tutor_utils()->get_quiz_option($post->ID); |
| 102 | $saved_quiz_options = array( |
| 103 | 'quiz_when_time_expires' => tutils()->get_option('quiz_when_time_expires'), |
| 104 | ); |
| 105 | |
| 106 | $quiz_options = array_merge($single_quiz_options, $saved_quiz_options); |
| 107 | |
| 108 | $previous_attempts = tutor_utils()->quiz_attempts(); |
| 109 | |
| 110 | if ($previous_attempts && count($previous_attempts)) { |
| 111 | $quiz_options['quiz_auto_start'] = 0; |
| 112 | } |
| 113 | |
| 114 | $localize_data['quiz_options'] = $quiz_options; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Enabling Sorting, draggable, droppable... |
| 119 | */ |
| 120 | wp_enqueue_script('jquery-ui-sortable'); |
| 121 | /** |
| 122 | * Tutor Icon |
| 123 | */ |
| 124 | wp_enqueue_style('tutor-icon', tutor()->url.'assets/icons/css/tutor-icon.css', array(), tutor()->version); |
| 125 | |
| 126 | |
| 127 | //Plyr |
| 128 | wp_enqueue_style( 'tutor-plyr', tutor()->url . 'assets/packages/plyr/plyr.css', array(), tutor()->version ); |
| 129 | wp_enqueue_script( 'tutor-plyr', tutor()->url . 'assets/packages/plyr/plyr.polyfilled.min.js', array( 'jquery' ), tutor()->version, true ); |
| 130 | |
| 131 | //Social Share |
| 132 | wp_enqueue_script( 'tutor-social-share', tutor()->url . 'assets/packages/SocialShare/SocialShare.min.js', array( 'jquery' ), tutor()->version, true ); |
| 133 | |
| 134 | //Including player assets if video exists |
| 135 | if (tutor_utils()->has_video_in_single()) { |
| 136 | $localize_data['post_id'] = get_the_ID(); |
| 137 | $localize_data['best_watch_time'] = 0; |
| 138 | |
| 139 | $best_watch_time = tutor_utils()->get_lesson_reading_info(get_the_ID(), 0, 'video_best_watched_time'); |
| 140 | if ($best_watch_time > 0){ |
| 141 | $localize_data['best_watch_time'] = $best_watch_time; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Chart Data |
| 147 | */ |
| 148 | if ( ! empty($wp_query->query_vars['tutor_dashboard_page']) ) { |
| 149 | wp_enqueue_script('jquery-ui-slider'); |
| 150 | |
| 151 | wp_enqueue_style('tutor-select2', tutor()->url.'assets/packages/select2/select2.min.css', array(), tutor()->version); |
| 152 | wp_enqueue_script('tutor-select2', tutor()->url.'assets/packages/select2/select2.full.min.js', array('jquery'), tutor()->version, true ); |
| 153 | |
| 154 | if ($wp_query->query_vars['tutor_dashboard_page'] === 'earning'){ |
| 155 | wp_enqueue_script( 'tutor-front-chart-js', tutor()->url . 'assets/js/Chart.bundle.min.js', array(), tutor()->version ); |
| 156 | wp_enqueue_script( 'jquery-ui-datepicker' ); |
| 157 | } |
| 158 | } |
| 159 | //End: chart data |
| 160 | |
| 161 | $localize_data = apply_filters('tutor_localize_data', $localize_data); |
| 162 | if (tutor_utils()->get_option('load_tutor_css')){ |
| 163 | wp_enqueue_style('tutor-frontend', tutor()->url."assets/css/tutor-front{$suffix}.css", array(), tutor()->version); |
| 164 | } |
| 165 | if (tutor_utils()->get_option('load_tutor_js')) { |
| 166 | wp_enqueue_script( 'tutor-main', tutor()->url . 'assets/js/tutor.js', array( 'jquery' ), tutor()->version, true ); |
| 167 | wp_enqueue_script( 'tutor-frontend', tutor()->url . 'assets/js/tutor-front.js', array( 'jquery' ), tutor()->version, true ); |
| 168 | wp_localize_script('tutor-frontend', '_tutorobject', $localize_data); |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Default Color |
| 173 | */ |
| 174 | $tutor_css = ":root{"; |
| 175 | $tutor_primary_color = tutor_utils()->get_option('tutor_primary_color'); |
| 176 | $tutor_primary_hover_color = tutor_utils()->get_option('tutor_primary_hover_color'); |
| 177 | $tutor_text_color = tutor_utils()->get_option('tutor_text_color'); |
| 178 | $tutor_light_color = tutor_utils()->get_option('tutor_light_color'); |
| 179 | |
| 180 | /** |
| 181 | * tutor buttons style |
| 182 | */ |
| 183 | $tutor_button_primary = tutor_utils()->get_option('tutor_button_primary'); |
| 184 | $tutor_button_danger = tutor_utils()->get_option('tutor_button_danger'); |
| 185 | $tutor_button_success = tutor_utils()->get_option('tutor_button_success'); |
| 186 | $tutor_button_warning = tutor_utils()->get_option('tutor_button_warning'); |
| 187 | |
| 188 | if ($tutor_primary_color){ |
| 189 | $tutor_css .= " --tutor-primary-color: {$tutor_primary_color};"; |
| 190 | } |
| 191 | if ($tutor_primary_hover_color){ |
| 192 | $tutor_css .= " --tutor-primary-hover-color: {$tutor_primary_hover_color};"; |
| 193 | } |
| 194 | if ($tutor_text_color){ |
| 195 | $tutor_css .= " --tutor-text-color: {$tutor_text_color};"; |
| 196 | } |
| 197 | if ($tutor_light_color){ |
| 198 | $tutor_css .= " --tutor-light-color: {$tutor_light_color};"; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * check if button style setup |
| 203 | */ |
| 204 | if($tutor_button_primary){ |
| 205 | $tutor_css .= " --tutor-primary-button-color: {$tutor_button_primary}; "; |
| 206 | } |
| 207 | if($tutor_button_danger){ |
| 208 | $tutor_css .= " --tutor-danger-button-color: {$tutor_button_danger}; "; |
| 209 | } |
| 210 | if($tutor_button_success){ |
| 211 | $tutor_css .= " --tutor-success-button-color: {$tutor_button_success}; "; |
| 212 | } |
| 213 | if($tutor_button_warning){ |
| 214 | $tutor_css .= " --tutor-warning-button-color: {$tutor_button_warning}; "; |
| 215 | } |
| 216 | |
| 217 | $tutor_css .= "}"; |
| 218 | wp_add_inline_style( 'tutor-frontend', $tutor_css ); |
| 219 | //END: Default Color |
| 220 | |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Add Tinymce button for placing shortcode |
| 225 | */ |
| 226 | function tutor_add_mce_button() { |
| 227 | // check user permissions |
| 228 | if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) { |
| 229 | return; |
| 230 | } |
| 231 | // check if WYSIWYG is enabled |
| 232 | if ( 'true' == get_user_option( 'rich_editing' ) ) { |
| 233 | add_filter( 'mce_external_plugins', array($this, 'tutor_add_tinymce_js') ); |
| 234 | add_filter( 'mce_buttons', array($this, 'tutor_register_mce_button') ); |
| 235 | } |
| 236 | } |
| 237 | // Declare script for new button |
| 238 | function tutor_add_tinymce_js( $plugin_array ) { |
| 239 | $plugin_array['tutor_button'] = tutor()->url .'assets/js/mce-button.js'; |
| 240 | return $plugin_array; |
| 241 | } |
| 242 | // Register new button in the editor |
| 243 | function tutor_register_mce_button( $buttons ) { |
| 244 | array_push( $buttons, 'tutor_button' ); |
| 245 | return $buttons; |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Output generator tag to aid debugging. |
| 250 | * |
| 251 | * @param string $gen Generator. |
| 252 | * @param string $type Type. |
| 253 | * @return string |
| 254 | */ |
| 255 | function tutor_generator_tag( $gen, $type ) { |
| 256 | switch ( $type ) { |
| 257 | case 'html': |
| 258 | $gen .= "\n" . '<meta name="generator" content="TutorLMS ' . esc_attr( TUTOR_VERSION ) . '">'; |
| 259 | break; |
| 260 | case 'xhtml': |
| 261 | $gen .= "\n" . '<meta name="generator" content="TutorLMS ' . esc_attr( TUTOR_VERSION ) . '" />'; |
| 262 | break; |
| 263 | } |
| 264 | return $gen; |
| 265 | } |
| 266 | |
| 267 | } |