| @@ -1,586 +1,599 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Class LP_Assets | |
| 4 | - * | |
| 5 | - * @author ThimPress | |
| 6 | - * @package LearnPress/Classes | |
| 7 | - * @version 4.0.1 | |
| 8 | - */ | |
| 9 | - | |
| 10 | -use LearnPress\Services\OpenAiService; | |
| 11 | - | |
| 12 | -defined( 'ABSPATH' ) || exit; | |
| 13 | - | |
| 14 | -class LP_Assets extends LP_Abstract_Assets { | |
| 15 | - protected static $_instance; | |
| 16 | - | |
| 17 | - /** | |
| 18 | - * Constructor | |
| 19 | - */ | |
| 20 | - protected function __construct() { | |
| 21 | - parent::__construct(); | |
| 22 | - | |
| 23 | - add_action( 'wp_print_footer_scripts', array( $this, 'show_overlay' ) ); | |
| 24 | - //Note: hook wp_head load before hook wp_enqueue_scripts | |
| 25 | - add_action( 'wp_head', [ $this, 'load_scripts_styles_on_head' ], - 1 ); | |
| 26 | - } | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * Get default styles in frontend. | |
| 30 | - * | |
| 31 | - * @return array | |
| 32 | - */ | |
| 33 | - protected function _get_styles(): array { | |
| 34 | - $is_rtl = is_rtl() ? '-rtl' : ''; | |
| 35 | - | |
| 36 | - $only_register_css_learnpress = false; | |
| 37 | - if ( wp_is_block_theme() ) { | |
| 38 | - if ( LP_Page_Controller::is_page_courses() ) { | |
| 39 | - $only_register_css_learnpress = true; | |
| 40 | - } | |
| 41 | - | |
| 42 | - if ( LP_Page_Controller::is_page_single_course() ) { | |
| 43 | - global $post; | |
| 44 | - setup_postdata( $post ); | |
| 45 | - $course_item = LP_Global::course_item(); | |
| 46 | - if ( ! $course_item ) { | |
| 47 | - $only_register_css_learnpress = true; | |
| 48 | - } | |
| 49 | - } | |
| 50 | - } | |
| 51 | - | |
| 52 | - $styles = apply_filters( | |
| 53 | - 'learn-press/frontend-default-styles', | |
| 54 | - array( | |
| 55 | - 'learnpress' => new LP_Asset_Key( | |
| 56 | - self::url( 'css/learnpress' . $is_rtl . self::$_min_assets . '.css' ), | |
| 57 | - array(), | |
| 58 | - array( | |
| 59 | - LP_PAGE_COURSES, | |
| 60 | - LP_PAGE_SINGLE_COURSE, | |
| 61 | - LP_PAGE_SINGLE_COURSE_CURRICULUM, | |
| 62 | - LP_PAGE_QUIZ, | |
| 63 | - LP_PAGE_QUESTION, | |
| 64 | - LP_PAGE_CHECKOUT, | |
| 65 | - LP_PAGE_BECOME_A_TEACHER, | |
| 66 | - LP_PAGE_PROFILE, | |
| 67 | - ), | |
| 68 | - $only_register_css_learnpress | |
| 69 | - ), | |
| 70 | - 'lp-instructor' => new LP_Asset_Key( | |
| 71 | - self::url( 'css/instructor' . $is_rtl . self::$_min_assets . '.css' ), | |
| 72 | - array(), | |
| 73 | - array(), | |
| 74 | - 1 | |
| 75 | - ), | |
| 76 | - 'lp-instructors' => new LP_Asset_Key( | |
| 77 | - self::url( 'css/instructors' . $is_rtl . self::$_min_assets . '.css' ), | |
| 78 | - [], | |
| 79 | - [], | |
| 80 | - 1 | |
| 81 | - ), | |
| 82 | - 'learnpress-widgets' => new LP_Asset_Key( | |
| 83 | - self::url( 'css/widgets' . $is_rtl . self::$_min_assets . '.css' ), | |
| 84 | - array(), | |
| 85 | - array(), | |
| 86 | - 0 | |
| 87 | - ), | |
| 88 | - 'lp-edit-curriculum' => new LP_Asset_Key( | |
| 89 | - $this->url( 'css/edit-curriculum' . $is_rtl . self::$_min_assets . '.css' ), | |
| 90 | - [], | |
| 91 | - [], | |
| 92 | - 1 | |
| 93 | - ), | |
| 94 | - 'lp-edit-quiz' => new LP_Asset_Key( | |
| 95 | - $this->url( 'css/edit-quiz' . $is_rtl . self::$_min_assets . '.css' ), | |
| 96 | - [], | |
| 97 | - [], | |
| 98 | - 1 | |
| 99 | - ), | |
| 100 | - 'lp-edit-question' => new LP_Asset_Key( | |
| 101 | - $this->url( 'css/edit-question' . $is_rtl . self::$_min_assets . '.css' ), | |
| 102 | - [], | |
| 103 | - [], | |
| 104 | - 1 | |
| 105 | - ), | |
| 106 | - 'lp-course-builder' => new LP_Asset_Key( | |
| 107 | - self::url( 'css/course-builder' . $is_rtl . self::$_min_assets . '.css' ), | |
| 108 | - array(), | |
| 109 | - array( LP_PAGE_COURSE_BUILDER ), | |
| 110 | - 0 | |
| 111 | - ), | |
| 112 | - 'lp-tom-select' => new LP_Asset_Key( | |
| 113 | - self::url( 'src/css/vendor/tom-select.min.css' ), | |
| 114 | - [], | |
| 115 | - [], | |
| 116 | - 0 | |
| 117 | - ), | |
| 118 | - ) | |
| 119 | - ); | |
| 120 | - | |
| 121 | - if ( wp_is_block_theme() ) { | |
| 122 | - $styles['learnpress-block'] = new LP_Asset_Key( | |
| 123 | - self::url( 'css/learnpress-block' . $is_rtl . self::$_min_assets . '.css' ), | |
| 124 | - array(), | |
| 125 | - array(), | |
| 126 | - 0 | |
| 127 | - ); | |
| 128 | - } | |
| 129 | - | |
| 130 | - return $styles; | |
| 131 | - } | |
| 132 | - | |
| 133 | - /** | |
| 134 | - * Set localize script data | |
| 135 | - * | |
| 136 | - * @return array | |
| 137 | - */ | |
| 138 | - public function _get_script_data(): array { | |
| 139 | - $localize_script = [ | |
| 140 | - 'lp-global' => array( | |
| 141 | - //'url' => learn_press_get_current_url(), | |
| 142 | - 'siteurl' => site_url(), | |
| 143 | - 'ajax' => admin_url( 'admin-ajax.php' ), | |
| 144 | - 'courses_url' => learn_press_get_page_link( 'courses' ), | |
| 145 | - 'post_id' => get_the_ID(), | |
| 146 | - 'user_id' => get_current_user_id(), | |
| 147 | - 'theme' => get_stylesheet(), | |
| 148 | - 'localize' => array( | |
| 149 | - 'button_ok' => esc_html__( 'OK', 'learnpress' ), | |
| 150 | - 'button_cancel' => esc_html__( 'Cancel', 'learnpress' ), | |
| 151 | - 'button_yes' => esc_html__( 'Yes', 'learnpress' ), | |
| 152 | - 'button_no' => esc_html__( 'No', 'learnpress' ), | |
| 153 | - ), | |
| 154 | - 'lp_rest_url' => get_rest_url(), | |
| 155 | - //Todo: should create nonce for guest and user separation | |
| 156 | - 'nonce' => wp_create_nonce( 'wp_rest' ), | |
| 157 | - 'option_enable_popup_confirm_finish' => LP_Settings::get_option( 'enable_popup_confirm_finish', 'yes' ), | |
| 158 | - 'is_course_archive' => LP_Page_Controller::is_page_courses(), | |
| 159 | - 'lpArchiveSkeleton' => lp_archive_skeleton_get_args(), | |
| 160 | - 'lpArchiveLoadAjax' => LP_Settings_Courses::is_ajax_load_courses() ? 1 : 0, | |
| 161 | - 'lpArchiveNoLoadAjaxFirst' => LP_Settings_Courses::is_ajax_load_courses() && LP_Settings_Courses::is_no_load_ajax_first_courses() ? 1 : 0, | |
| 162 | - 'lpArchivePaginationType' => LP_Settings::get_option( 'course_pagination_type' ), | |
| 163 | - 'noLoadCoursesJs' => LP_Settings::theme_no_support_load_courses_ajax() ? 1 : 0, | |
| 164 | - ), | |
| 165 | - 'lp-checkout' => array( | |
| 166 | - 'ajaxurl' => home_url( '/' ), | |
| 167 | - //'user_checkout' => LP_Checkout::instance()->get_checkout_email(), | |
| 168 | - 'i18n_processing' => esc_html__( 'Processing', 'learnpress' ), | |
| 169 | - 'i18n_redirecting' => esc_html__( 'Redirecting', 'learnpress' ), | |
| 170 | - 'i18n_invalid_field' => esc_html__( 'Invalid field', 'learnpress' ), | |
| 171 | - 'i18n_unknown_error' => esc_html__( 'Unknown error', 'learnpress' ), | |
| 172 | - 'i18n_place_order' => esc_html__( 'Place order', 'learnpress' ), | |
| 173 | - ), | |
| 174 | - 'lp-profile' => array( | |
| 175 | - 'text_upload' => __( 'Upload', 'learnpress' ), | |
| 176 | - 'text_replace' => __( 'Replace', 'learnpress' ), | |
| 177 | - 'text_remove' => __( 'Remove', 'learnpress' ), | |
| 178 | - 'text_save' => __( 'Save', 'learnpress' ), | |
| 179 | - 'avatar_dimensions' => learn_press_get_avatar_thumb_size(), | |
| 180 | - 'default_avatar' => get_avatar_url( get_current_user_id() ), | |
| 181 | - ), | |
| 182 | - 'lp-quiz' => learn_press_single_quiz_args(), | |
| 183 | - ]; | |
| 184 | - | |
| 185 | - return apply_filters( 'learnpress/frontend/localize_script', $localize_script ); | |
| 186 | - } | |
| 187 | - | |
| 188 | - /** | |
| 189 | - * Localize data for all page frontend. | |
| 190 | - * | |
| 191 | - * @return array | |
| 192 | - */ | |
| 193 | - public function localize_data_global(): array { | |
| 194 | - $cover_image_dimensions = LP_Settings::get_option( | |
| 195 | - 'cover_image_dimensions', | |
| 196 | - array( | |
| 197 | - 'width' => 1290, | |
| 198 | - 'height' => 250, | |
| 199 | - ) | |
| 200 | - ); | |
| 201 | - $aspectRatio = $cover_image_dimensions['width'] / $cover_image_dimensions['height']; | |
| 202 | - | |
| 203 | - return apply_filters( | |
| 204 | - 'learn-press/frontend/localize-data-global', | |
| 205 | - [ | |
| 206 | - 'site_url' => site_url(), | |
| 207 | - 'user_id' => get_current_user_id(), | |
| 208 | - 'theme' => get_stylesheet(), | |
| 209 | - 'lp_rest_url' => get_rest_url(), | |
| 210 | - 'nonce' => wp_create_nonce( 'wp_rest' ), | |
| 211 | - 'is_course_archive' => LP_Page_Controller::is_page_courses(), | |
| 212 | - 'courses_url' => learn_press_get_page_link( 'courses' ), | |
| 213 | - 'urlParams' => lp_archive_skeleton_get_args(), | |
| 214 | - 'lp_version' => LearnPress::instance()->version, | |
| 215 | - 'lp_rest_load_ajax' => get_rest_url( null, 'lp/v1/load_content_via_ajax/' ), // @deprecated 4.3.0 | |
| 216 | - 'ajaxUrl' => admin_url( 'admin-ajax.php' ), | |
| 217 | - 'lpAjaxUrl' => LP_Settings::url_handle_lp_ajax(), | |
| 218 | - 'coverImageRatio' => $aspectRatio, | |
| 219 | - 'toast' => [ | |
| 220 | - 'gravity' => 'bottom', | |
| 221 | - 'position' => 'center', | |
| 222 | - 'duration' => 3000, | |
| 223 | - 'close' => 1, | |
| 224 | - 'stopOnFocus' => 1, | |
| 225 | - 'classPrefix' => 'lp-toast', | |
| 226 | - ], | |
| 227 | - 'i18n' => [ | |
| 228 | - 'yes' => esc_html__( 'Yes' ), | |
| 229 | - 'cancel' => esc_html__( 'Cancel' ), | |
| 230 | - 'generate_with_ai' => esc_html__( 'Generate with AI', 'learnpress' ), | |
| 231 | - 'confirm_close_ai' => esc_html__( 'Are you sure you want to close? Generate data will stop.', 'learnpress' ), | |
| 232 | - ], | |
| 233 | - 'enable_open_ai' => OpenAiService::instance()->is_enable() | |
| 234 | - && ! empty( LP_Settings::get_option( 'open_ai_secret_key', '' ) ), | |
| 235 | - ] | |
| 236 | - ); | |
| 237 | - } | |
| 238 | - | |
| 239 | - /** | |
| 240 | - * Localize data for all page frontend. | |
| 241 | - * | |
| 242 | - * @return array | |
| 243 | - */ | |
| 244 | - public function localize_data_courses(): array { | |
| 245 | - return apply_filters( | |
| 246 | - 'learn-press/frontend/localize-script/courses', | |
| 247 | - [ | |
| 248 | - 'lpArchiveLoadAjax' => LP_Settings_Courses::is_ajax_load_courses() ? 1 : 0, | |
| 249 | - 'lpArchiveNoLoadAjaxFirst' => LP_Settings_Courses::is_ajax_load_courses() && LP_Settings_Courses::is_no_load_ajax_first_courses() ? 1 : 0, | |
| 250 | - 'lpArchivePaginationType' => LP_Settings::get_option( 'course_pagination_type' ), | |
| 251 | - 'noLoadCoursesJs' => LP_Settings::theme_no_support_load_courses_ajax() ? 1 : 0, | |
| 252 | - ] | |
| 253 | - ); | |
| 254 | - } | |
| 255 | - | |
| 256 | - /** | |
| 257 | - * Config load scripts | |
| 258 | - * | |
| 259 | - * @return array | |
| 260 | - */ | |
| 261 | - public function _get_scripts(): array { | |
| 262 | - $wp_js = array( | |
| 263 | - 'jquery', | |
| 264 | - 'wp-element', | |
| 265 | - 'wp-compose', | |
| 266 | - 'wp-data', | |
| 267 | - 'wp-hooks', | |
| 268 | - 'wp-api-fetch', | |
| 269 | - 'lodash', | |
| 270 | - ); | |
| 271 | - | |
| 272 | - $scripts = apply_filters( | |
| 273 | - 'learn-press/frontend-default-scripts', | |
| 274 | - array( | |
| 275 | - 'vue-libs' => new LP_Asset_Key( | |
| 276 | - self::url( 'src/js/vendor/vue/vue_libs_special.min.js' ) | |
| 277 | - ), | |
| 278 | - 'lp-modal' => new LP_Asset_Key( | |
| 279 | - self::url( 'js/dist/frontend/modal' . self::$_min_assets . '.js' ), | |
| 280 | - array( 'jquery' ) | |
| 281 | - ), | |
| 282 | - // lp-plugins-all use only for FE, when FE 2 release will remove it. | |
| 283 | - 'lp-plugins-all' => new LP_Asset_Key( self::url( 'js/vendor/plugins.all.min.js' ) ), | |
| 284 | - 'lp-global' => new LP_Asset_Key( | |
| 285 | - self::url( self::$_folder_source . 'js/global' . self::$_min_assets . '.js' ), | |
| 286 | - array( 'jquery', 'underscore', 'utils' ) | |
| 287 | - ), | |
| 288 | - 'lp-utils' => new LP_Asset_Key( | |
| 289 | - self::url( 'js/dist/utils' . self::$_min_assets . '.js' ), | |
| 290 | - array( 'jquery' ) | |
| 291 | - ), | |
| 292 | - 'lp-load-ajax' => new LP_Asset_Key( | |
| 293 | - self::url( 'js/dist/loadAJAX' . self::$_min_assets . '.js' ), | |
| 294 | - [ 'wp-hooks' ], | |
| 295 | - [], | |
| 296 | - 0, | |
| 297 | - 0, | |
| 298 | - '', | |
| 299 | - [ 'strategy' => 'async' ] | |
| 300 | - ), | |
| 301 | - 'lp-checkout' => new LP_Asset_Key( | |
| 302 | - self::url( 'js/dist/frontend/checkout' . self::$_min_assets . '.js' ), | |
| 303 | - [], | |
| 304 | - [ LP_PAGE_CHECKOUT ], | |
| 305 | - 0, | |
| 306 | - 0, | |
| 307 | - '', | |
| 308 | - [ 'strategy' => 'async' ] | |
| 309 | - ), | |
| 310 | - 'lp-data-controls' => new LP_Asset_Key( | |
| 311 | - self::url( 'js/dist/js/data-controls' . self::$_min_assets . '.js' ), | |
| 312 | - array_merge( $wp_js, array( 'lp-global' ) ) | |
| 313 | - ), | |
| 314 | - 'lp-config' => new LP_Asset_Key( | |
| 315 | - self::url( 'js/dist/frontend/lp-configs' . self::$_min_assets . '.js' ), | |
| 316 | - array_merge( $wp_js, array( 'lp-global' ) ) | |
| 317 | - ), | |
| 318 | - // 'lp-lesson' => new LP_Asset_Key( self::url( self::$_folder_source .'js/frontend/lesson' . self::$_min_assets . '.js' ) ), | |
| 319 | - 'lp-question-types' => new LP_Asset_Key( | |
| 320 | - self::url( 'js/dist/frontend/question-types' . self::$_min_assets . '.js' ), | |
| 321 | - array_merge( $wp_js, array( 'lp-global' ) ), | |
| 322 | - array(), | |
| 323 | - 1, | |
| 324 | - 1 | |
| 325 | - ), | |
| 326 | - 'lp-single-curriculum' => new LP_Asset_Key( | |
| 327 | - self::url( 'js/dist/frontend/single-curriculum' . self::$_min_assets . '.js' ), | |
| 328 | - array_merge( | |
| 329 | - $wp_js, | |
| 330 | - array( | |
| 331 | - 'lp-global', | |
| 332 | - 'lp-utils', | |
| 333 | - ) | |
| 334 | - ), | |
| 335 | - array( LP_PAGE_SINGLE_COURSE_CURRICULUM ), | |
| 336 | - 0, | |
| 337 | - 1, | |
| 338 | - '', | |
| 339 | - [ 'strategy' => 'defer' ] | |
| 340 | - ), | |
| 341 | - 'lp-curriculum' => new LP_Asset_Key( | |
| 342 | - self::url( 'js/dist/frontend/curriculum' . self::$_min_assets . '.js' ), | |
| 343 | - [], | |
| 344 | - array( LP_PAGE_SINGLE_COURSE_CURRICULUM, LP_PAGE_SINGLE_COURSE ), | |
| 345 | - 0, | |
| 346 | - 0, | |
| 347 | - '', | |
| 348 | - [ 'strategy' => 'async' ] | |
| 349 | - ), | |
| 350 | - 'lp-quiz' => new LP_Asset_Key( | |
| 351 | - self::url( 'js/dist/frontend/quiz' . self::$_min_assets . '.js' ), | |
| 352 | - array_merge( | |
| 353 | - $wp_js, | |
| 354 | - array( | |
| 355 | - 'wp-i18n', | |
| 356 | - 'lp-global', | |
| 357 | - 'lp-utils', | |
| 358 | - 'lp-data-controls', | |
| 359 | - 'lp-question-types', | |
| 360 | - 'lp-modal', | |
| 361 | - 'lp-config', | |
| 362 | - 'lp-single-curriculum', | |
| 363 | - ) | |
| 364 | - ), | |
| 365 | - array( LP_PAGE_QUIZ ), | |
| 366 | - 0, | |
| 367 | - 1, | |
| 368 | - '', | |
| 369 | - [ 'strategy' => 'defer' ] | |
| 370 | - ), | |
| 371 | - 'lp-single-course' => new LP_Asset_Key( | |
| 372 | - self::url( 'js/dist/frontend/single-course' . self::$_min_assets . '.js' ), | |
| 373 | - array_merge( | |
| 374 | - $wp_js, | |
| 375 | - array( | |
| 376 | - 'lp-global', | |
| 377 | - 'lp-utils', | |
| 378 | - ) | |
| 379 | - ), | |
| 380 | - array( LP_PAGE_SINGLE_COURSE ), | |
| 381 | - 0, | |
| 382 | - 0, | |
| 383 | - '', | |
| 384 | - [ 'strategy' => 'defer' ] | |
| 385 | - ), | |
| 386 | - /*'lp-courses' => new LP_Asset_Key( | |
| 387 | - self::url( 'js/dist/frontend/courses' . self::$_min_assets . '.js' ), | |
| 388 | - array( | |
| 389 | - 'lp-global', | |
| 390 | - 'wp-hooks', | |
| 391 | - ), // when Eduma v5.3.6 release a long time, will be remove lp-global. | |
| 392 | - array(), | |
| 393 | - 1, | |
| 394 | - 0, | |
| 395 | - '', | |
| 396 | - [ 'strategy' => 'defer' ] | |
| 397 | - ),*/ | |
| 398 | - 'lp-courses-v2' => new LP_Asset_Key( | |
| 399 | - self::url( 'js/dist/frontend/courses-v2' . self::$_min_assets . '.js' ), | |
| 400 | - [ 'utils', 'wp-hooks' ], // dependency utils of wp, because js is using wpCookies | |
| 401 | - [ LP_PAGE_COURSES ], | |
| 402 | - 0, | |
| 403 | - 0, | |
| 404 | - '', | |
| 405 | - [ 'strategy' => 'async' ] | |
| 406 | - ), | |
| 407 | - 'lp-instructors' => new LP_Asset_Key( | |
| 408 | - self::url( 'js/dist/frontend/instructors' . self::$_min_assets . '.js' ), | |
| 409 | - [ 'lp-global' ], | |
| 410 | - [], | |
| 411 | - 1, | |
| 412 | - 0, | |
| 413 | - '', | |
| 414 | - [ 'strategy' => 'defer' ] | |
| 415 | - ), | |
| 416 | - 'lp-profile' => new LP_Asset_Key( | |
| 417 | - self::url( 'js/dist/frontend/profile' . self::$_min_assets . '.js' ), | |
| 418 | - [ 'lp-load-ajax', 'wp-i18n' ], | |
| 419 | - array( LP_PAGE_PROFILE ), | |
| 420 | - 0, | |
| 421 | - 0, | |
| 422 | - '', | |
| 423 | - [ 'strategy' => 'defer' ] | |
| 424 | - ), | |
| 425 | - 'lp-list-students-enrolled' => new LP_Asset_Key( | |
| 426 | - self::url( 'dist/js/admin/list-students-enrolled' . self::$_min_assets . '.js' ), | |
| 427 | - [ 'lp-load-ajax' ], | |
| 428 | - [ LP_PAGE_PROFILE ], | |
| 429 | - 0, | |
| 430 | - 0, | |
| 431 | - '', | |
| 432 | - [ 'strategy' => 'async' ] | |
| 433 | - ), | |
| 434 | - 'lp-widgets' => new LP_Asset_Key( | |
| 435 | - self::url( 'js/dist/frontend/widgets' . self::$_min_assets . '.js' ), | |
| 436 | - [ 'lp-course-filter' ], | |
| 437 | - array(), | |
| 438 | - 1, | |
| 439 | - 0, | |
| 440 | - '', | |
| 441 | - [ 'strategy' => 'async' ] | |
| 442 | - ), | |
| 443 | - 'lp-become-a-teacher' => new LP_Asset_Key( | |
| 444 | - self::url( 'js/dist/frontend/become-teacher' . self::$_min_assets . '.js' ), | |
| 445 | - array( 'jquery' ), | |
| 446 | - array( LP_PAGE_BECOME_A_TEACHER ), | |
| 447 | - 0, | |
| 448 | - 1, | |
| 449 | - '', | |
| 450 | - [ 'strategy' => 'defer' ] | |
| 451 | - ), | |
| 452 | - 'lp-course-filter' => new LP_Asset_Key( | |
| 453 | - self::url( 'js/dist/frontend/course-filter' . self::$_min_assets . '.js' ), | |
| 454 | - array(), | |
| 455 | - array(), | |
| 456 | - 1, | |
| 457 | - 0, | |
| 458 | - '', | |
| 459 | - [ 'strategy' => 'async' ] | |
| 460 | - ), | |
| 461 | - 'lp-course-builder' => new LP_Asset_Key( | |
| 462 | - self::url( 'js/dist/frontend/course-builder' . self::$_min_assets . '.js' ), | |
| 463 | - array( 'wp-tinymce', 'editor', 'lp-load-ajax' ), | |
| 464 | - array( LP_PAGE_COURSE_BUILDER ), | |
| 465 | - 0, | |
| 466 | - 0, | |
| 467 | - '', | |
| 468 | - [ 'strategy' => 'defer' ] | |
| 469 | - ), | |
| 470 | - ) | |
| 471 | - ); | |
| 472 | - | |
| 473 | - // Dequeue script 'smoothPageScroll' on item details, it makes can't scroll, when rewrite page item detail, can check to remove. | |
| 474 | - if ( LP_PAGE_SINGLE_COURSE_CURRICULUM === LP_Page_Controller::page_current() || | |
| 475 | - LP_PAGE_QUIZ === LP_Page_Controller::page_current() || | |
| 476 | - LP_PAGE_QUESTION === LP_Page_Controller::page_current() ) { | |
| 477 | - wp_dequeue_script( 'smoothPageScroll' ); | |
| 478 | - } | |
| 479 | - | |
| 480 | - return $scripts; | |
| 481 | - } | |
| 482 | - | |
| 483 | - /** | |
| 484 | - * Load assets | |
| 485 | - * | |
| 486 | - * @author tungnx | |
| 487 | - * @version 1.0.1 | |
| 488 | - * @since 3.2.8 | |
| 489 | - */ | |
| 490 | - public function load_scripts() { | |
| 491 | - $page_current = LP_Page_Controller::page_current(); | |
| 492 | - $this->handle_js( $page_current ); | |
| 493 | - $this->handle_style( $page_current ); | |
| 494 | - | |
| 495 | - do_action( 'learn-press/after-enqueue-scripts' ); | |
| 496 | - } | |
| 497 | - | |
| 498 | - /** | |
| 499 | - * Add javascript to head | |
| 500 | - * Add style to head | |
| 501 | - * | |
| 502 | - * @return void | |
| 503 | - */ | |
| 504 | - public function load_scripts_styles_on_head() { | |
| 505 | - $this->load_scripts_on_head(); | |
| 506 | - $this->load_styles_on_head(); | |
| 507 | - } | |
| 508 | - | |
| 509 | - /** | |
| 510 | - * Load scripts on head | |
| 511 | - * @return void | |
| 512 | - */ | |
| 513 | - public function load_scripts_on_head() { | |
| 514 | - LP_Helper::print_inline_script_tag( 'lpData', $this->localize_data_global(), [ 'id' => 'lpData' ] ); | |
| 515 | - LP_Helper::print_inline_script_tag( 'lpSettingCourses', $this->localize_data_courses(), [ 'id' => 'lpSettingCourses' ] ); | |
| 516 | - } | |
| 517 | - | |
| 518 | - /** | |
| 519 | - * Load styles on head | |
| 520 | - * @return void | |
| 521 | - */ | |
| 522 | - public function load_styles_on_head() { | |
| 523 | - $max_width = esc_html( LP_Settings::get_option( 'width_container', '1290px' ) ); | |
| 524 | - $padding_container = apply_filters( 'learn-press/container-padding-width', '1rem' ); | |
| 525 | - $primary_color = esc_html( LP_Settings::get_option( 'primary_color' ) ); | |
| 526 | - $secondary_color = esc_html( LP_Settings::get_option( 'secondary_color' ) ); | |
| 527 | - ?> | |
| 528 | - <style id="learn-press-custom-css"> | |
| 529 | - :root { | |
| 530 | - --lp-container-max-width: <?php echo $max_width; ?>; | |
| 531 | - --lp-cotainer-padding: <?php echo $padding_container; ?>; | |
| 532 | - --lp-primary-color: <?php echo ! empty( $primary_color ) ? $primary_color : '#ffb606'; ?>; | |
| 533 | - --lp-secondary-color: <?php echo ! empty( $secondary_color ) ? $secondary_color : '#442e66'; ?>; | |
| 534 | - } | |
| 535 | - </style> | |
| 536 | - <?php | |
| 537 | - } | |
| 538 | - | |
| 539 | - /** | |
| 540 | - * Add lp overlay | |
| 541 | - * | |
| 542 | - * @since 3.2.8 | |
| 543 | - * @version 1.0.1 | |
| 544 | - * @author tungnx | |
| 545 | - */ | |
| 546 | - public function show_overlay() { | |
| 547 | - $page_current = LP_Page_Controller::page_current(); | |
| 548 | - if ( ! in_array( | |
| 549 | - $page_current, | |
| 550 | - array( LP_PAGE_SINGLE_COURSE_CURRICULUM, LP_PAGE_SINGLE_COURSE, LP_PAGE_QUIZ ) | |
| 551 | - ) ) { | |
| 552 | - return; | |
| 553 | - } | |
| 554 | - | |
| 555 | - if ( 'yes' !== LP_Settings::get_option( 'enable_popup_confirm_finish', 'yes' ) ) { | |
| 556 | - return; | |
| 557 | - } | |
| 558 | - | |
| 559 | - echo '<div class="lp-overlay" style="display: none">'; | |
| 560 | - learn_press_get_template( 'global/lp-modal-overlay' ); | |
| 561 | - echo '</div>'; | |
| 562 | - } | |
| 563 | - | |
| 564 | - public static function instance() { | |
| 565 | - if ( is_admin() ) { | |
| 566 | - return null; | |
| 567 | - } | |
| 568 | - | |
| 569 | - if ( self::$_instance == null ) { | |
| 570 | - self::$_instance = new self(); | |
| 571 | - } | |
| 572 | - | |
| 573 | - return self::$_instance; | |
| 574 | - } | |
| 575 | -} | |
| 576 | - | |
| 577 | -/** | |
| 578 | - * Shortcut function to get instance of LP_Assets | |
| 579 | - * | |
| 580 | - * @return LP_Assets|null | |
| 581 | - */ | |
| 582 | -function learn_press_assets() { | |
| 583 | - return LP_Assets::instance(); | |
| 584 | -} | |
| 585 | - | |
| 586 | -learn_press_assets(); | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Class LP_Assets | |
| 4 | + * | |
| 5 | + * @author ThimPress | |
| 6 | + * @package LearnPress/Classes | |
| 7 | + * @version 4.0.1 | |
| 8 | + */ | |
| 9 | + | |
| 10 | +use LearnPress\Services\OpenAiService; | |
| 11 | + | |
| 12 | +defined( 'ABSPATH' ) || exit; | |
| 13 | + | |
| 14 | +class LP_Assets extends LP_Abstract_Assets { | |
| 15 | + protected static $_instance; | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * Constructor | |
| 19 | + */ | |
| 20 | + protected function __construct() { | |
| 21 | + parent::__construct(); | |
| 22 | + | |
| 23 | + add_action( 'wp_print_footer_scripts', array( $this, 'show_overlay' ) ); | |
| 24 | + //Note: hook wp_head load before hook wp_enqueue_scripts | |
| 25 | + add_action( 'wp_head', [ $this, 'load_scripts_styles_on_head' ], - 1 ); | |
| 26 | + } | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * Get default styles in frontend. | |
| 30 | + * | |
| 31 | + * @return array | |
| 32 | + */ | |
| 33 | + protected function _get_styles(): array { | |
| 34 | + $is_rtl = is_rtl() ? '-rtl' : ''; | |
| 35 | + | |
| 36 | + $only_register_css_learnpress = false; | |
| 37 | + if ( wp_is_block_theme() ) { | |
| 38 | + if ( LP_Page_Controller::is_page_courses() ) { | |
| 39 | + $only_register_css_learnpress = true; | |
| 40 | + } | |
| 41 | + | |
| 42 | + if ( LP_Page_Controller::is_page_single_course() ) { | |
| 43 | + global $post; | |
| 44 | + setup_postdata( $post ); | |
| 45 | + $course_item = LP_Global::course_item(); | |
| 46 | + if ( ! $course_item ) { | |
| 47 | + $only_register_css_learnpress = true; | |
| 48 | + } | |
| 49 | + } | |
| 50 | + } | |
| 51 | + | |
| 52 | + $styles = apply_filters( | |
| 53 | + 'learn-press/frontend-default-styles', | |
| 54 | + array( | |
| 55 | + 'learnpress' => new LP_Asset_Key( | |
| 56 | + self::url( 'css/learnpress' . $is_rtl . self::$_min_assets . '.css' ), | |
| 57 | + array(), | |
| 58 | + array( | |
| 59 | + LP_PAGE_COURSES, | |
| 60 | + LP_PAGE_SINGLE_COURSE, | |
| 61 | + LP_PAGE_SINGLE_COURSE_CURRICULUM, | |
| 62 | + LP_PAGE_QUIZ, | |
| 63 | + LP_PAGE_QUESTION, | |
| 64 | + LP_PAGE_CHECKOUT, | |
| 65 | + LP_PAGE_BECOME_A_TEACHER, | |
| 66 | + LP_PAGE_PROFILE, | |
| 67 | + ), | |
| 68 | + $only_register_css_learnpress | |
| 69 | + ), | |
| 70 | + 'lp-instructor' => new LP_Asset_Key( | |
| 71 | + self::url( 'css/instructor' . $is_rtl . self::$_min_assets . '.css' ), | |
| 72 | + array(), | |
| 73 | + array(), | |
| 74 | + 1 | |
| 75 | + ), | |
| 76 | + 'lp-instructors' => new LP_Asset_Key( | |
| 77 | + self::url( 'css/instructors' . $is_rtl . self::$_min_assets . '.css' ), | |
| 78 | + [], | |
| 79 | + [], | |
| 80 | + 1 | |
| 81 | + ), | |
| 82 | + 'learnpress-widgets' => new LP_Asset_Key( | |
| 83 | + self::url( 'css/widgets' . $is_rtl . self::$_min_assets . '.css' ), | |
| 84 | + array(), | |
| 85 | + array(), | |
| 86 | + 0 | |
| 87 | + ), | |
| 88 | + 'lp-edit-curriculum' => new LP_Asset_Key( | |
| 89 | + $this->url( 'css/edit-curriculum' . $is_rtl . self::$_min_assets . '.css' ), | |
| 90 | + [], | |
| 91 | + [], | |
| 92 | + 1 | |
| 93 | + ), | |
| 94 | + 'lp-edit-quiz' => new LP_Asset_Key( | |
| 95 | + $this->url( 'css/edit-quiz' . $is_rtl . self::$_min_assets . '.css' ), | |
| 96 | + [], | |
| 97 | + [], | |
| 98 | + 1 | |
| 99 | + ), | |
| 100 | + 'lp-edit-question' => new LP_Asset_Key( | |
| 101 | + $this->url( 'css/edit-question' . $is_rtl . self::$_min_assets . '.css' ), | |
| 102 | + [], | |
| 103 | + [], | |
| 104 | + 1 | |
| 105 | + ), | |
| 106 | + 'lp-course-builder' => new LP_Asset_Key( | |
| 107 | + self::url( 'css/course-builder' . $is_rtl . self::$_min_assets . '.css' ), | |
| 108 | + array(), | |
| 109 | + array( LP_PAGE_COURSE_BUILDER ), | |
| 110 | + 0 | |
| 111 | + ), | |
| 112 | + 'lp-tom-select' => new LP_Asset_Key( | |
| 113 | + self::url( 'src/css/vendor/tom-select.min.css' ), | |
| 114 | + [], | |
| 115 | + [], | |
| 116 | + 0 | |
| 117 | + ), | |
| 118 | + 'lp-ai-assistant' => new LP_Asset_Key( | |
| 119 | + self::url( 'css/frontend/ai-assistant' . self::$_min_assets . '.css' ), | |
| 120 | + array(), | |
| 121 | + array( LP_PAGE_SINGLE_COURSE_CURRICULUM ), | |
| 122 | + 1 | |
| 123 | + ), | |
| 124 | + ) | |
| 125 | + ); | |
| 126 | + | |
| 127 | + if ( wp_is_block_theme() ) { | |
| 128 | + $styles['learnpress-block'] = new LP_Asset_Key( | |
| 129 | + self::url( 'css/learnpress-block' . $is_rtl . self::$_min_assets . '.css' ), | |
| 130 | + array(), | |
| 131 | + array(), | |
| 132 | + 0 | |
| 133 | + ); | |
| 134 | + } | |
| 135 | + | |
| 136 | + return $styles; | |
| 137 | + } | |
| 138 | + | |
| 139 | + /** | |
| 140 | + * Set localize script data | |
| 141 | + * | |
| 142 | + * @return array | |
| 143 | + */ | |
| 144 | + public function _get_script_data(): array { | |
| 145 | + $localize_script = [ | |
| 146 | + 'lp-global' => array( | |
| 147 | + //'url' => learn_press_get_current_url(), | |
| 148 | + 'siteurl' => site_url(), | |
| 149 | + 'ajax' => admin_url( 'admin-ajax.php' ), | |
| 150 | + 'courses_url' => learn_press_get_page_link( 'courses' ), | |
| 151 | + 'post_id' => get_the_ID(), | |
| 152 | + 'user_id' => get_current_user_id(), | |
| 153 | + 'theme' => get_stylesheet(), | |
| 154 | + 'localize' => array( | |
| 155 | + 'button_ok' => esc_html__( 'OK', 'learnpress' ), | |
| 156 | + 'button_cancel' => esc_html__( 'Cancel', 'learnpress' ), | |
| 157 | + 'button_yes' => esc_html__( 'Yes', 'learnpress' ), | |
| 158 | + 'button_no' => esc_html__( 'No', 'learnpress' ), | |
| 159 | + ), | |
| 160 | + 'lp_rest_url' => get_rest_url(), | |
| 161 | + //Todo: should create nonce for guest and user separation | |
| 162 | + 'nonce' => wp_create_nonce( 'wp_rest' ), | |
| 163 | + 'option_enable_popup_confirm_finish' => LP_Settings::get_option( 'enable_popup_confirm_finish', 'yes' ), | |
| 164 | + 'is_course_archive' => LP_Page_Controller::is_page_courses(), | |
| 165 | + 'lpArchiveSkeleton' => lp_archive_skeleton_get_args(), | |
| 166 | + 'lpArchiveLoadAjax' => LP_Settings_Courses::is_ajax_load_courses() ? 1 : 0, | |
| 167 | + 'lpArchiveNoLoadAjaxFirst' => LP_Settings_Courses::is_ajax_load_courses() && LP_Settings_Courses::is_no_load_ajax_first_courses() ? 1 : 0, | |
| 168 | + 'lpArchivePaginationType' => LP_Settings::get_option( 'course_pagination_type' ), | |
| 169 | + 'noLoadCoursesJs' => LP_Settings::theme_no_support_load_courses_ajax() ? 1 : 0, | |
| 170 | + ), | |
| 171 | + 'lp-checkout' => array( | |
| 172 | + 'ajaxurl' => home_url( '/' ), | |
| 173 | + //'user_checkout' => LP_Checkout::instance()->get_checkout_email(), | |
| 174 | + 'i18n_processing' => esc_html__( 'Processing', 'learnpress' ), | |
| 175 | + 'i18n_redirecting' => esc_html__( 'Redirecting', 'learnpress' ), | |
| 176 | + 'i18n_invalid_field' => esc_html__( 'Invalid field', 'learnpress' ), | |
| 177 | + 'i18n_unknown_error' => esc_html__( 'Unknown error', 'learnpress' ), | |
| 178 | + 'i18n_place_order' => esc_html__( 'Place order', 'learnpress' ), | |
| 179 | + ), | |
| 180 | + 'lp-profile' => array( | |
| 181 | + 'text_upload' => __( 'Upload', 'learnpress' ), | |
| 182 | + 'text_replace' => __( 'Replace', 'learnpress' ), | |
| 183 | + 'text_remove' => __( 'Remove', 'learnpress' ), | |
| 184 | + 'text_save' => __( 'Save', 'learnpress' ), | |
| 185 | + 'avatar_dimensions' => learn_press_get_avatar_thumb_size(), | |
| 186 | + 'default_avatar' => get_avatar_url( get_current_user_id() ), | |
| 187 | + ), | |
| 188 | + 'lp-quiz' => learn_press_single_quiz_args(), | |
| 189 | + ]; | |
| 190 | + | |
| 191 | + return apply_filters( 'learnpress/frontend/localize_script', $localize_script ); | |
| 192 | + } | |
| 193 | + | |
| 194 | + /** | |
| 195 | + * Localize data for all page frontend. | |
| 196 | + * | |
| 197 | + * @return array | |
| 198 | + */ | |
| 199 | + public function localize_data_global(): array { | |
| 200 | + $cover_image_dimensions = LP_Settings::get_option( | |
| 201 | + 'cover_image_dimensions', | |
| 202 | + array( | |
| 203 | + 'width' => 1290, | |
| 204 | + 'height' => 250, | |
| 205 | + ) | |
| 206 | + ); | |
| 207 | + $aspectRatio = $cover_image_dimensions['width'] / $cover_image_dimensions['height']; | |
| 208 | + | |
| 209 | + return apply_filters( | |
| 210 | + 'learn-press/frontend/localize-data-global', | |
| 211 | + [ | |
| 212 | + 'site_url' => site_url(), | |
| 213 | + 'user_id' => get_current_user_id(), | |
| 214 | + 'theme' => get_stylesheet(), | |
| 215 | + 'lp_rest_url' => get_rest_url(), | |
| 216 | + 'nonce' => wp_create_nonce( 'wp_rest' ), | |
| 217 | + 'is_course_archive' => LP_Page_Controller::is_page_courses(), | |
| 218 | + 'courses_url' => learn_press_get_page_link( 'courses' ), | |
| 219 | + 'urlParams' => lp_archive_skeleton_get_args(), | |
| 220 | + 'lp_version' => LearnPress::instance()->version, | |
| 221 | + 'lp_rest_load_ajax' => get_rest_url( null, 'lp/v1/load_content_via_ajax/' ), // @deprecated 4.3.0 | |
| 222 | + 'ajaxUrl' => admin_url( 'admin-ajax.php' ), | |
| 223 | + 'lpAjaxUrl' => LP_Settings::url_handle_lp_ajax(), | |
| 224 | + 'coverImageRatio' => $aspectRatio, | |
| 225 | + 'toast' => [ | |
| 226 | + 'gravity' => 'bottom', | |
| 227 | + 'position' => 'center', | |
| 228 | + 'duration' => 3000, | |
| 229 | + 'close' => 1, | |
| 230 | + 'stopOnFocus' => 1, | |
| 231 | + 'classPrefix' => 'lp-toast', | |
| 232 | + ], | |
| 233 | + 'i18n' => [ | |
| 234 | + 'yes' => esc_html__( 'Yes' ), | |
| 235 | + 'cancel' => esc_html__( 'Cancel' ), | |
| 236 | + 'generate_with_ai' => esc_html__( 'Generate with AI', 'learnpress' ), | |
| 237 | + 'confirm_close_ai' => esc_html__( 'Are you sure you want to close? Generate data will stop.', 'learnpress' ), | |
| 238 | + ], | |
| 239 | + 'enable_open_ai' => OpenAiService::instance()->is_enable() | |
| 240 | + && ! empty( LP_Settings::get_option( 'open_ai_secret_key', '' ) ), | |
| 241 | + ] | |
| 242 | + ); | |
| 243 | + } | |
| 244 | + | |
| 245 | + /** | |
| 246 | + * Localize data for all page frontend. | |
| 247 | + * | |
| 248 | + * @return array | |
| 249 | + */ | |
| 250 | + public function localize_data_courses(): array { | |
| 251 | + return apply_filters( | |
| 252 | + 'learn-press/frontend/localize-script/courses', | |
| 253 | + [ | |
| 254 | + 'lpArchiveLoadAjax' => LP_Settings_Courses::is_ajax_load_courses() ? 1 : 0, | |
| 255 | + 'lpArchiveNoLoadAjaxFirst' => LP_Settings_Courses::is_ajax_load_courses() && LP_Settings_Courses::is_no_load_ajax_first_courses() ? 1 : 0, | |
| 256 | + 'lpArchivePaginationType' => LP_Settings::get_option( 'course_pagination_type' ), | |
| 257 | + 'noLoadCoursesJs' => LP_Settings::theme_no_support_load_courses_ajax() ? 1 : 0, | |
| 258 | + ] | |
| 259 | + ); | |
| 260 | + } | |
| 261 | + | |
| 262 | + /** | |
| 263 | + * Config load scripts | |
| 264 | + * | |
| 265 | + * @return array | |
| 266 | + */ | |
| 267 | + public function _get_scripts(): array { | |
| 268 | + $wp_js = array( | |
| 269 | + 'jquery', | |
| 270 | + 'wp-element', | |
| 271 | + 'wp-compose', | |
| 272 | + 'wp-data', | |
| 273 | + 'wp-hooks', | |
| 274 | + 'wp-api-fetch', | |
| 275 | + 'lodash', | |
| 276 | + ); | |
| 277 | + | |
| 278 | + $scripts = apply_filters( | |
| 279 | + 'learn-press/frontend-default-scripts', | |
| 280 | + array( | |
| 281 | + /*'vue-libs' => new LP_Asset_Key( | |
| 282 | + self::url( 'src/js/vendor/vue/vue_libs_special.min.js' ) | |
| 283 | + ),*/ | |
| 284 | + 'lp-modal' => new LP_Asset_Key( | |
| 285 | + self::url( 'js/dist/frontend/modal' . self::$_min_assets . '.js' ), | |
| 286 | + array( 'jquery' ) | |
| 287 | + ), | |
| 288 | + // lp-plugins-all use only for FE, when FE 2 release will remove it. | |
| 289 | + //'lp-plugins-all' => new LP_Asset_Key( self::url( 'js/vendor/plugins.all.min.js' ) ), | |
| 290 | + 'lp-global' => new LP_Asset_Key( | |
| 291 | + self::url( self::$_folder_source . 'js/global' . self::$_min_assets . '.js' ), | |
| 292 | + array( 'jquery', 'underscore', 'utils' ) | |
| 293 | + ), | |
| 294 | + 'lp-utils' => new LP_Asset_Key( | |
| 295 | + self::url( 'js/dist/utils' . self::$_min_assets . '.js' ), | |
| 296 | + array( 'jquery' ) | |
| 297 | + ), | |
| 298 | + 'lp-load-ajax' => new LP_Asset_Key( | |
| 299 | + self::url( 'js/dist/loadAJAX' . self::$_min_assets . '.js' ), | |
| 300 | + [ 'wp-hooks' ], | |
| 301 | + [], | |
| 302 | + 0, | |
| 303 | + 0, | |
| 304 | + '', | |
| 305 | + [ 'strategy' => 'async' ] | |
| 306 | + ), | |
| 307 | + 'lp-checkout' => new LP_Asset_Key( | |
| 308 | + self::url( 'js/dist/frontend/checkout' . self::$_min_assets . '.js' ), | |
| 309 | + [], | |
| 310 | + [ LP_PAGE_CHECKOUT ], | |
| 311 | + 0, | |
| 312 | + 0, | |
| 313 | + '', | |
| 314 | + [ 'strategy' => 'async' ] | |
| 315 | + ), | |
| 316 | + 'lp-data-controls' => new LP_Asset_Key( | |
| 317 | + self::url( 'js/dist/js/data-controls' . self::$_min_assets . '.js' ), | |
| 318 | + array_merge( $wp_js, array( 'lp-global' ) ) | |
| 319 | + ), | |
| 320 | + 'lp-config' => new LP_Asset_Key( | |
| 321 | + self::url( 'js/dist/frontend/lp-configs' . self::$_min_assets . '.js' ), | |
| 322 | + array_merge( $wp_js, array( 'lp-global' ) ) | |
| 323 | + ), | |
| 324 | + // 'lp-lesson' => new LP_Asset_Key( self::url( self::$_folder_source .'js/frontend/lesson' . self::$_min_assets . '.js' ) ), | |
| 325 | + 'lp-question-types' => new LP_Asset_Key( | |
| 326 | + self::url( 'js/dist/frontend/question-types' . self::$_min_assets . '.js' ), | |
| 327 | + array_merge( $wp_js, array( 'lp-global' ) ), | |
| 328 | + array(), | |
| 329 | + 1, | |
| 330 | + 1 | |
| 331 | + ), | |
| 332 | + 'lp-single-curriculum' => new LP_Asset_Key( | |
| 333 | + self::url( 'js/dist/frontend/single-curriculum' . self::$_min_assets . '.js' ), | |
| 334 | + array_merge( | |
| 335 | + $wp_js, | |
| 336 | + array( | |
| 337 | + 'lp-global', | |
| 338 | + 'lp-utils', | |
| 339 | + ) | |
| 340 | + ), | |
| 341 | + array( LP_PAGE_SINGLE_COURSE_CURRICULUM ), | |
| 342 | + 0, | |
| 343 | + 1, | |
| 344 | + '', | |
| 345 | + [ 'strategy' => 'defer' ] | |
| 346 | + ), | |
| 347 | + 'lp-curriculum' => new LP_Asset_Key( | |
| 348 | + self::url( 'js/dist/frontend/curriculum' . self::$_min_assets . '.js' ), | |
| 349 | + [], | |
| 350 | + array( LP_PAGE_SINGLE_COURSE_CURRICULUM, LP_PAGE_SINGLE_COURSE ), | |
| 351 | + 0, | |
| 352 | + 0, | |
| 353 | + '', | |
| 354 | + [ 'strategy' => 'async' ] | |
| 355 | + ), | |
| 356 | + 'lp-quiz' => new LP_Asset_Key( | |
| 357 | + self::url( 'js/dist/frontend/quiz' . self::$_min_assets . '.js' ), | |
| 358 | + array_merge( | |
| 359 | + $wp_js, | |
| 360 | + array( | |
| 361 | + 'wp-i18n', | |
| 362 | + 'lp-global', | |
| 363 | + 'lp-utils', | |
| 364 | + 'lp-data-controls', | |
| 365 | + 'lp-question-types', | |
| 366 | + 'lp-modal', | |
| 367 | + 'lp-config', | |
| 368 | + 'lp-single-curriculum', | |
| 369 | + ) | |
| 370 | + ), | |
| 371 | + array( LP_PAGE_QUIZ ), | |
| 372 | + 0, | |
| 373 | + 1, | |
| 374 | + '', | |
| 375 | + [ 'strategy' => 'defer' ] | |
| 376 | + ), | |
| 377 | + 'lp-single-course' => new LP_Asset_Key( | |
| 378 | + self::url( 'js/dist/frontend/single-course' . self::$_min_assets . '.js' ), | |
| 379 | + array_merge( | |
| 380 | + $wp_js, | |
| 381 | + array( | |
| 382 | + 'lp-global', | |
| 383 | + 'lp-utils', | |
| 384 | + ) | |
| 385 | + ), | |
| 386 | + array( LP_PAGE_SINGLE_COURSE ), | |
| 387 | + 0, | |
| 388 | + 0, | |
| 389 | + '', | |
| 390 | + [ 'strategy' => 'defer' ] | |
| 391 | + ), | |
| 392 | + /*'lp-courses' => new LP_Asset_Key( | |
| 393 | + self::url( 'js/dist/frontend/courses' . self::$_min_assets . '.js' ), | |
| 394 | + array( | |
| 395 | + 'lp-global', | |
| 396 | + 'wp-hooks', | |
| 397 | + ), // when Eduma v5.3.6 release a long time, will be remove lp-global. | |
| 398 | + array(), | |
| 399 | + 1, | |
| 400 | + 0, | |
| 401 | + '', | |
| 402 | + [ 'strategy' => 'defer' ] | |
| 403 | + ),*/ | |
| 404 | + 'lp-courses-v2' => new LP_Asset_Key( | |
| 405 | + self::url( 'js/dist/frontend/courses-v2' . self::$_min_assets . '.js' ), | |
| 406 | + [ 'utils', 'wp-hooks' ], // dependency utils of wp, because js is using wpCookies | |
| 407 | + [ LP_PAGE_COURSES ], | |
| 408 | + 0, | |
| 409 | + 0, | |
| 410 | + '', | |
| 411 | + [ 'strategy' => 'async' ] | |
| 412 | + ), | |
| 413 | + 'lp-instructors' => new LP_Asset_Key( | |
| 414 | + self::url( 'js/dist/frontend/instructors' . self::$_min_assets . '.js' ), | |
| 415 | + [ 'lp-global' ], | |
| 416 | + [], | |
| 417 | + 1, | |
| 418 | + 0, | |
| 419 | + '', | |
| 420 | + [ 'strategy' => 'defer' ] | |
| 421 | + ), | |
| 422 | + 'lp-profile' => new LP_Asset_Key( | |
| 423 | + self::url( 'js/dist/frontend/profile' . self::$_min_assets . '.js' ), | |
| 424 | + [ 'lp-load-ajax', 'wp-i18n' ], | |
| 425 | + array( LP_PAGE_PROFILE ), | |
| 426 | + 0, | |
| 427 | + 0, | |
| 428 | + '', | |
| 429 | + [ 'strategy' => 'defer' ] | |
| 430 | + ), | |
| 431 | + 'lp-list-students-enrolled' => new LP_Asset_Key( | |
| 432 | + self::url( 'dist/js/admin/list-students-enrolled' . self::$_min_assets . '.js' ), | |
| 433 | + [ 'lp-load-ajax' ], | |
| 434 | + [ LP_PAGE_PROFILE ], | |
| 435 | + 0, | |
| 436 | + 0, | |
| 437 | + '', | |
| 438 | + [ 'strategy' => 'async' ] | |
| 439 | + ), | |
| 440 | + 'lp-widgets' => new LP_Asset_Key( | |
| 441 | + self::url( 'js/dist/frontend/widgets' . self::$_min_assets . '.js' ), | |
| 442 | + [ 'lp-course-filter' ], | |
| 443 | + array(), | |
| 444 | + 1, | |
| 445 | + 0, | |
| 446 | + '', | |
| 447 | + [ 'strategy' => 'async' ] | |
| 448 | + ), | |
| 449 | + 'lp-become-a-teacher' => new LP_Asset_Key( | |
| 450 | + self::url( 'js/dist/frontend/become-teacher' . self::$_min_assets . '.js' ), | |
| 451 | + array( 'jquery' ), | |
| 452 | + array( LP_PAGE_BECOME_A_TEACHER ), | |
| 453 | + 0, | |
| 454 | + 1, | |
| 455 | + '', | |
| 456 | + [ 'strategy' => 'defer' ] | |
| 457 | + ), | |
| 458 | + 'lp-course-filter' => new LP_Asset_Key( | |
| 459 | + self::url( 'js/dist/frontend/course-filter' . self::$_min_assets . '.js' ), | |
| 460 | + array(), | |
| 461 | + array(), | |
| 462 | + 1, | |
| 463 | + 0, | |
| 464 | + '', | |
| 465 | + [ 'strategy' => 'async' ] | |
| 466 | + ), | |
| 467 | + 'lp-course-builder' => new LP_Asset_Key( | |
| 468 | + self::url( 'dist/js/frontend/course-builder' . self::$_min_assets . '.js' ), | |
| 469 | + array( 'wp-tinymce', 'editor', 'lp-load-ajax' ), | |
| 470 | + array( LP_PAGE_COURSE_BUILDER ), | |
| 471 | + 0, | |
| 472 | + 0, | |
| 473 | + '', | |
| 474 | + [ 'strategy' => 'defer' ] | |
| 475 | + ), | |
| 476 | + 'lp-ai-assistant' => new LP_Asset_Key( | |
| 477 | + self::url( 'js/dist/frontend/ai-assistant' . self::$_min_assets . '.js' ), | |
| 478 | + array(), | |
| 479 | + array( LP_PAGE_SINGLE_COURSE_CURRICULUM ), | |
| 480 | + 1, | |
| 481 | + 1, | |
| 482 | + ), | |
| 483 | + ) | |
| 484 | + ); | |
| 485 | + | |
| 486 | + // Dequeue script 'smoothPageScroll' on item details, it makes can't scroll, when rewrite page item detail, can check to remove. | |
| 487 | + if ( LP_PAGE_SINGLE_COURSE_CURRICULUM === LP_Page_Controller::page_current() || | |
| 488 | + LP_PAGE_QUIZ === LP_Page_Controller::page_current() || | |
| 489 | + LP_PAGE_QUESTION === LP_Page_Controller::page_current() ) { | |
| 490 | + wp_dequeue_script( 'smoothPageScroll' ); | |
| 491 | + } | |
| 492 | + | |
| 493 | + return $scripts; | |
| 494 | + } | |
| 495 | + | |
| 496 | + /** | |
| 497 | + * Load assets | |
| 498 | + * | |
| 499 | + * @author tungnx | |
| 500 | + * @version 1.0.1 | |
| 501 | + * @since 3.2.8 | |
| 502 | + */ | |
| 503 | + public function load_scripts() { | |
| 504 | + $page_current = LP_Page_Controller::page_current(); | |
| 505 | + $this->handle_js( $page_current ); | |
| 506 | + $this->handle_style( $page_current ); | |
| 507 | + | |
| 508 | + do_action( 'learn-press/after-enqueue-scripts' ); | |
| 509 | + } | |
| 510 | + | |
| 511 | + /** | |
| 512 | + * Add javascript to head | |
| 513 | + * Add style to head | |
| 514 | + * | |
| 515 | + * @return void | |
| 516 | + */ | |
| 517 | + public function load_scripts_styles_on_head() { | |
| 518 | + $this->load_scripts_on_head(); | |
| 519 | + $this->load_styles_on_head(); | |
| 520 | + } | |
| 521 | + | |
| 522 | + /** | |
| 523 | + * Load scripts on head | |
| 524 | + * @return void | |
| 525 | + */ | |
| 526 | + public function load_scripts_on_head() { | |
| 527 | + LP_Helper::print_inline_script_tag( 'lpData', $this->localize_data_global(), [ 'id' => 'lpData' ] ); | |
| 528 | + LP_Helper::print_inline_script_tag( 'lpSettingCourses', $this->localize_data_courses(), [ 'id' => 'lpSettingCourses' ] ); | |
| 529 | + } | |
| 530 | + | |
| 531 | + /** | |
| 532 | + * Load styles on head | |
| 533 | + * @return void | |
| 534 | + */ | |
| 535 | + public function load_styles_on_head() { | |
| 536 | + $max_width = esc_html( LP_Settings::get_option( 'width_container', '1290px' ) ); | |
| 537 | + $padding_container = apply_filters( 'learn-press/container-padding-width', '1rem' ); | |
| 538 | + $primary_color = esc_html( LP_Settings::get_option( 'primary_color' ) ); | |
| 539 | + $secondary_color = esc_html( LP_Settings::get_option( 'secondary_color' ) ); | |
| 540 | + ?> | |
| 541 | + <style id="learn-press-custom-css"> | |
| 542 | + :root { | |
| 543 | + --lp-container-max-width: <?php echo $max_width; ?>; | |
| 544 | + --lp-cotainer-padding: <?php echo $padding_container; ?>; | |
| 545 | + --lp-primary-color: <?php echo ! empty( $primary_color ) ? $primary_color : '#ffb606'; ?>; | |
| 546 | + --lp-secondary-color: <?php echo ! empty( $secondary_color ) ? $secondary_color : '#442e66'; ?>; | |
| 547 | + } | |
| 548 | + </style> | |
| 549 | + <?php | |
| 550 | + } | |
| 551 | + | |
| 552 | + /** | |
| 553 | + * Add lp overlay | |
| 554 | + * | |
| 555 | + * @since 3.2.8 | |
| 556 | + * @version 1.0.1 | |
| 557 | + * @author tungnx | |
| 558 | + */ | |
| 559 | + public function show_overlay() { | |
| 560 | + $page_current = LP_Page_Controller::page_current(); | |
| 561 | + if ( ! in_array( | |
| 562 | + $page_current, | |
| 563 | + array( LP_PAGE_SINGLE_COURSE_CURRICULUM, LP_PAGE_SINGLE_COURSE, LP_PAGE_QUIZ ) | |
| 564 | + ) ) { | |
| 565 | + return; | |
| 566 | + } | |
| 567 | + | |
| 568 | + if ( 'yes' !== LP_Settings::get_option( 'enable_popup_confirm_finish', 'yes' ) ) { | |
| 569 | + return; | |
| 570 | + } | |
| 571 | + | |
| 572 | + echo '<div class="lp-overlay" style="display: none">'; | |
| 573 | + learn_press_get_template( 'global/lp-modal-overlay' ); | |
| 574 | + echo '</div>'; | |
| 575 | + } | |
| 576 | + | |
| 577 | + public static function instance() { | |
| 578 | + if ( is_admin() ) { | |
| 579 | + return null; | |
| 580 | + } | |
| 581 | + | |
| 582 | + if ( self::$_instance == null ) { | |
| 583 | + self::$_instance = new self(); | |
| 584 | + } | |
| 585 | + | |
| 586 | + return self::$_instance; | |
| 587 | + } | |
| 588 | +} | |
| 589 | + | |
| 590 | +/** | |
| 591 | + * Shortcut function to get instance of LP_Assets | |
| 592 | + * | |
| 593 | + * @return LP_Assets|null | |
| 594 | + */ | |
| 595 | +function learn_press_assets() { | |
| 596 | + return LP_Assets::instance(); | |
| 597 | +} | |
| 598 | + | |
| 599 | +learn_press_assets(); | |