Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/tutor-pro/classes/Assets.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
/**
3
+
* Handle Pro Assets
4
+
*
5
+
* @package TutorPro\Classes
6
+
* @author Themeum <support@themeum.com>
7
+
* @link https://themeum.com
8
+
* @since 1.0.0
9
+
*/
10
+
11
+
namespace TUTOR_PRO;
12
+
13
+
use Tutor\Ecommerce\OrderController;
14
+
use TUTOR\Input;
15
+
use TutorPro\Ecommerce\GuestCheckout\GuestCheckout;
16
+
17
+
if ( ! defined( 'ABSPATH' ) ) {
18
+
exit;
19
+
}
20
+
21
+
/**
22
+
* Enqueue styles & scripts
23
+
*/
24
+
class Assets {
25
+
26
+
/**
27
+
* Register hooks
28
+
*/
29
+
public function __construct() {
30
+
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
31
+
add_action( 'wp_enqueue_scripts', __CLASS__ . '::frontend_scripts' );
32
+
add_action( 'login_enqueue_scripts', __CLASS__ . '::frontend_scripts' );
33
+
34
+
add_action( 'admin_enqueue_scripts', array( $this, 'load_js_translations' ), 100 );
35
+
add_action( 'wp_enqueue_scripts', array( $this, 'load_js_translations' ), 100 );
36
+
add_action( 'tutor_course_builder_before_wp_editor_load', array( $this, 'enqueue_tinymce_codesample_asset' ) );
37
+
}
38
+
39
+
/**
40
+
* Load JS translations
41
+
*
42
+
* @see https://make.wordpress.org/core/2018/11/09/new-javascript-i18n-support-in-wordpress/
43
+
*
44
+
* @since 2.6.0
45
+
* @since 4.0.0 Refactored to dynamically detect scripts instead of hardcoded list.
46
+
*
47
+
* @return void
48
+
*/
49
+
public function load_js_translations() {
50
+
global $wp_scripts;
51
+
52
+
if ( empty( $wp_scripts->registered ) ) {
53
+
return;
54
+
}
55
+
56
+
foreach ( $wp_scripts->registered as $handle => $data ) {
57
+
$src = $data->src ?? '';
58
+
$is_from_tutor_pro = str_contains( $src, 'tutor-pro' ) && str_contains( $src, '/assets/js' );
59
+
60
+
if ( ! $is_from_tutor_pro ) {
61
+
continue;
62
+
}
63
+
64
+
wp_set_script_translations( $handle, 'tutor-pro', tutor_pro()->languages );
65
+
}
66
+
}
67
+
68
+
/**
69
+
* Enqueue styles & scripts for the admin side
70
+
*
71
+
* @return void
72
+
*/
73
+
public function admin_scripts() {
74
+
wp_enqueue_style( 'tutor-pro-admin', tutor_pro()->url . 'assets/css/admin.css', array(), TUTOR_PRO_VERSION );
75
+
wp_enqueue_script( 'tutor-pro-admin', tutor_pro()->url . 'assets/js/admin.js', array( 'jquery' ), TUTOR_PRO_VERSION, true );
76
+
77
+
// Enqueue TinyMCE codesample assets.
78
+
self::enqueue_tinymce_codesample_asset();
79
+
80
+
// Enqueue html2canvas and jsPDf.
81
+
$invoice_id = Input::get( 'invoice', 0, Input::TYPE_INT );
82
+
$current_page = Input::get( 'page' );
83
+
84
+
if ( OrderController::PAGE_SLUG === $current_page && $invoice_id ) {
85
+
wp_enqueue_script( 'html2canvas', tutor_pro()->url . 'assets/lib/html2canvas/html2canvas.min.js', array( 'jquery' ), TUTOR_VERSION, true );
86
+
wp_enqueue_script( 'jsPDf', tutor_pro()->url . 'assets/lib/jspdf/jspdf.umd.min.js', array( 'jquery' ), TUTOR_VERSION, true );
87
+
}
88
+
}
89
+
90
+
/**
91
+
* Enqueue style & scripts on the frontend
92
+
*
93
+
* @since 3.3.0 Guest checkout js enqueued
94
+
*
95
+
* @return void
96
+
*/
97
+
public static function frontend_scripts() {
98
+
self::enqueue_tinymce_codesample_asset();
99
+
100
+
wp_enqueue_script( 'tutor-pro-front', tutor_pro()->url . 'assets/js/front.js', array( 'wp-i18n' ), TUTOR_PRO_VERSION, true );
101
+
102
+
if ( 'wp-login.php' === $GLOBALS['pagenow'] ) {
103
+
$current_page = tutor_utils()->get_current_page_slug();
104
+
105
+
wp_localize_script(
106
+
'tutor-pro-front',
107
+
'_tutorobject',
108
+
array(
109
+
'ajaxurl' => admin_url( 'admin-ajax.php' ),
110
+
'nonce_key' => tutor()->nonce,
111
+
tutor()->nonce => wp_create_nonce( tutor()->nonce_action ),
112
+
'current_page' => $current_page,
113
+
)
114
+
);
115
+
}
116
+
117
+
// Enqueue html2canvas and jsPDf.
118
+
$invoice_id = Input::get( 'invoice', 0, Input::TYPE_INT );
119
+
if ( get_query_var( 'tutor_dashboard_page' ) === 'purchase_history' && $invoice_id ) {
120
+
wp_enqueue_script( 'html2canvas', tutor_pro()->url . 'assets/lib/html2canvas/html2canvas.min.js', array( 'jquery' ), TUTOR_VERSION, true );
121
+
wp_enqueue_script( 'jsPDf', tutor_pro()->url . 'assets/lib/jspdf/jspdf.umd.min.js', array( 'jquery' ), TUTOR_VERSION, true );
122
+
}
123
+
124
+
if ( is_single() && in_array( get_post_type( get_the_ID() ), array( tutor()->course_post_type, tutor()->bundle_post_type ), true ) ) {
125
+
wp_enqueue_style( 'tutor-pro-course-details', tutor_pro()->url . 'assets/css/course-details.css', array(), TUTOR_VERSION );
126
+
}
127
+
128
+
wp_enqueue_style( 'tutor-pro-front', tutor_pro()->url . 'assets/css/front.css', array(), TUTOR_VERSION );
129
+
130
+
if ( tutor_utils()->is_monetize_by_tutor() && GuestCheckout::is_enable() ) {
131
+
wp_enqueue_script( 'tutor-pro-guest-checkout', tutor_pro()->url . 'assets/js/guest-checkout.js', array( 'jquery', 'wp-i18n' ), TUTOR_PRO_VERSION, true );
132
+
}
133
+
}
134
+
135
+
/**
136
+
* Load codesample plugin css & js to support
137
+
* code snippet on the lesson & quiz
138
+
*
139
+
* @since v2.0.8
140
+
*/
141
+
public static function enqueue_tinymce_codesample_asset() {
142
+
global $wp_query;
143
+
$query_vars = $wp_query->query_vars;
144
+
$current_post_type = get_post_type();
145
+
$dashboard_page = $query_vars['tutor_dashboard_page'] ?? '';
146
+
$page = Input::get( 'page', '' );
147
+
$editor_pages = array( 'create-course', 'course-bundle', 'create-bundle', 'tutor_settings', 'tutor-content-bank' );
148
+
149
+
if ( in_array( $current_post_type, array( tutor()->course_post_type, tutor()->bundle_post_type ), true ) ||
150
+
in_array( $dashboard_page, $editor_pages, true ) ||
151
+
in_array( $page, $editor_pages, true )
152
+
) {
153
+
if ( ! wp_script_is( 'wp-tinymce-root' ) ) {
154
+
wp_enqueue_script( 'tutor-tiny', includes_url( 'js/tinymce' ) . '/tinymce.min.js', array( 'jquery' ), TUTOR_VERSION, true );
155
+
}
156
+
wp_enqueue_script( 'tutor-tinymce-codesample', tutor_pro()->url . 'assets/lib/codesample/prism.min.js', array( 'jquery' ), TUTOR_VERSION, true );
157
+
wp_enqueue_script( 'tutor-tinymce-code', tutor_pro()->url . 'assets/lib/tinymce/code.plugin.min.js', array( 'jquery' ), TUTOR_VERSION, true );
158
+
}
159
+
160
+
wp_enqueue_style( 'tutor-prism-css', tutor_pro()->url . 'assets/lib/codesample/prism.css', array(), TUTOR_VERSION );
161
+
wp_enqueue_script( 'tutor-prism-js', tutor_pro()->url . 'assets/lib/prism/prism.min.js', array( 'jquery' ), TUTOR_VERSION, true );
162
+
wp_enqueue_script( 'tutor-prism-script', tutor_pro()->url . 'assets/lib/prism/script.js', array( 'jquery' ), TUTOR_VERSION, true );
163
+
}
164
+
}
165
+