Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/tutor-pro/addons/h5p/src/Assets.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
/**
3
+
* Enqueue scripts and styles
4
+
*
5
+
* @package TutorPro\Addons
6
+
* @subpackage H5P
7
+
* @author Themeum <support@themeum.com>
8
+
* @link https://themeum.com
9
+
* @since 3.0.0
10
+
*/
11
+
12
+
namespace TutorPro\H5P;
13
+
14
+
if ( ! defined( 'ABSPATH' ) ) {
15
+
exit;
16
+
}
17
+
18
+
/**
19
+
* Tutor H5P Assets class
20
+
*/
21
+
class Assets {
22
+
23
+
/**
24
+
* Assets class constructor
25
+
*/
26
+
public function __construct() {
27
+
/**
28
+
* Hook for scripts enqueue
29
+
*/
30
+
add_action( 'wp_enqueue_scripts', array( $this, 'h5p_scripts' ) );
31
+
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
32
+
add_action( 'h5p_alter_library_scripts', array( $this, 'add_h5p_iframe_script' ), 10, 3 );
33
+
add_action( 'tutor_lesson/single/before/wrap', array( $this, 'add_lesson_script' ) );
34
+
add_action( 'tutor_quiz/body/before', array( $this, 'add_quiz_script' ), 10, 1 );
35
+
}
36
+
37
+
/**
38
+
* Add script to handle h5p lesson xAPI statement.
39
+
*
40
+
* @since 3.0.0
41
+
*
42
+
* @return void
43
+
*/
44
+
public function add_lesson_script() {
45
+
wp_enqueue_script(
46
+
'tutor_h5p_lesson',
47
+
Utils::addon_config()->url . 'assets/js/lesson.js',
48
+
array( 'jquery' ),
49
+
filemtime( Utils::addon_config()->path . 'assets/js/lesson.js' ),
50
+
true
51
+
);
52
+
}
53
+
54
+
/**
55
+
* Add script to handle h5p quiz xAPI statement.
56
+
*
57
+
* @since 3.0.0
58
+
*
59
+
* @param int $quiz_id the quiz id.
60
+
* @return void
61
+
*/
62
+
public function add_quiz_script( $quiz_id ) {
63
+
if ( tutor_utils()->is_started_quiz() ) {
64
+
wp_enqueue_script(
65
+
'tutor_h5p_quiz',
66
+
Utils::addon_config()->url . 'assets/js/quiz.js',
67
+
array( 'jquery' ),
68
+
filemtime( Utils::addon_config()->path . 'assets/js/quiz.js' ),
69
+
true
70
+
);
71
+
}
72
+
}
73
+
/**
74
+
* Enqueue frontend script for tutor H5P addon.
75
+
*
76
+
* @since 3.0.0
77
+
*
78
+
* @return void
79
+
*/
80
+
public function h5p_scripts() {
81
+
wp_enqueue_script(
82
+
'tutor_h5p_modal',
83
+
Utils::addon_config()->url . 'assets/js/modal.js',
84
+
array( 'jquery' ),
85
+
filemtime( Utils::addon_config()->path . 'assets/js/modal.js' ),
86
+
true
87
+
);
88
+
89
+
if ( isset( $_GET['page'] ) && 'tutor_h5p' === $_GET['page'] ) {
90
+
wp_enqueue_script(
91
+
'tutor-pro-chart-js',
92
+
tutor_pro()->url . 'assets/lib/Chart.bundle.min.js',
93
+
array(),
94
+
TUTOR_PRO_VERSION,
95
+
true
96
+
);
97
+
98
+
wp_enqueue_script(
99
+
'tutor-pro-analytics',
100
+
Utils::addon_config()->url . 'assets/js/analytics.js',
101
+
array( 'jquery', 'tutor-pro-chart-js' ),
102
+
TUTOR_PRO_VERSION,
103
+
true
104
+
);
105
+
106
+
wp_add_inline_script(
107
+
'tutor-pro-analytics',
108
+
'const _tutor_h5p_analytics=' . json_encode( Utils::chart_data() ),
109
+
'before'
110
+
);
111
+
}
112
+
}
113
+
114
+
/**
115
+
* Enqueue admin script for H5P admin panel.
116
+
*
117
+
* @since 3.0.0
118
+
*
119
+
* @return void
120
+
*/
121
+
public function admin_scripts() {
122
+
wp_enqueue_script(
123
+
'tutor_h5p_modal',
124
+
Utils::addon_config()->url . 'assets/js/modal.js',
125
+
array( 'jquery' ),
126
+
filemtime( Utils::addon_config()->path . 'assets/js/modal.js' ),
127
+
true
128
+
);
129
+
130
+
if ( isset( $_GET['page'] ) && 'tutor_h5p' === $_GET['page'] ) {
131
+
wp_enqueue_script(
132
+
'tutor-pro-chart-js',
133
+
tutor_pro()->url . 'assets/lib/Chart.bundle.min.js',
134
+
array(),
135
+
TUTOR_PRO_VERSION,
136
+
true
137
+
);
138
+
139
+
wp_enqueue_script(
140
+
'tutor-pro-analytics',
141
+
Utils::addon_config()->url . 'assets/js/analytics.js',
142
+
array( 'jquery', 'tutor-pro-chart-js' ),
143
+
TUTOR_PRO_VERSION,
144
+
true
145
+
);
146
+
147
+
wp_add_inline_script(
148
+
'tutor-pro-analytics',
149
+
'const _tutor_h5p_analytics=' . json_encode( Utils::chart_data() ),
150
+
'before'
151
+
);
152
+
153
+
wp_enqueue_style(
154
+
'tutor-h5p-analytics-style',
155
+
Utils::addon_config()->url . 'assets/css/analytics.css',
156
+
array(),
157
+
TUTOR_PRO_VERSION
158
+
);
159
+
160
+
wp_enqueue_style(
161
+
'tutor-h5p-report-style',
162
+
Utils::addon_config()->url . 'assets/css/report.css',
163
+
array(),
164
+
TUTOR_PRO_VERSION
165
+
);
166
+
}
167
+
}
168
+
169
+
/**
170
+
* Add iframe script on the H5P content iframe header
171
+
*
172
+
* @since 3.0.0
173
+
*
174
+
* @param array $scripts the script list of H5P iframe to add to.
175
+
* @param mixed $libraries the current library it depends on.
176
+
* @param string $embed_type the embed type.
177
+
* @return void
178
+
*/
179
+
public function add_h5p_iframe_script( &$scripts, $libraries, $embed_type ) {
180
+
if ( 'iframe' === $embed_type ) {
181
+
$scripts[] = (object) array(
182
+
'path' => Utils::addon_config()->url . 'assets/js/iframe.js',
183
+
'version' => '?ver=1.0.0',
184
+
);
185
+
}
186
+
}
187
+
}
188
+