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