admin-modules.php
13.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<?php
namespace uncanny_learndash_toolkit;
/**
* A variable with some data, for now it has:
* - has_toolkit_pro: Boolean to determinate if the user has the Pro version installed.
*
* @var Array
*/
$config = [
'has_toolkit_pro' => ( defined( 'UNCANNY_TOOLKIT_PRO_VERSION' ) ) ? true : false,
'get_toolkit_pro' => 'https://www.uncannyowl.com/downloads/uncanny-learndash-toolkit-pro/',
'pro_name' => __( 'Uncanny Toolkit Pro for LearnDash', 'uncanny-learndash-toolkit' ),
];
/**
* Array that defines all the Toolkit Free and Pro modules
* Each element will have:
* - title: The title of the module
* - description: The description of the module
* - keywords: A list of words separated by commas to use
* when using the search algorithm
* - is_active: Boolean to determinate if the module is active
* - version: Boolean to determinate if this module is pro-only
* - categories: An array with the module categories
* - dependencies: An array with the dependencies of this module
* - documentation: The URL where users will be sent when they press on "Get more info"
* - settings_id: The ID of the modal box that loads the fields
*
*
* Don't define these elements, we're going to define them later.
* - can_use: Boolean to define if the user can use or not this module.
* - cant_use_notice: The message the user will see if can't use the module.
* - missing_dependencies: An array with all the mising dependencies for this module.
*
* @var Array
*/
$modules = AdminMenu::$modules;
/**
* Sort alphabetically
*/
$add_on_titles = array();
foreach ( $modules as $key => $row ) {
$add_on_titles[ $key ] = $row['title'];
}
array_multisort( $add_on_titles, SORT_ASC, $modules );
/**
* If Pro is disabled then push Pro modules to the bottom
*/
// Check if it doesn't have the pro version
if ( ! defined( 'UNCANNY_TOOLKIT_PRO_VERSION' ) ) {
// Create arrays to separate free and pro modules
$free_modules = [];
$pro_modules = [];
// Iterate each module
foreach ( $modules as $module_key => $module ) {
// Check if it's a pro module
if ( isset( $module['is_pro'] ) && $module['is_pro'] ) {
// Add to the pro array
$pro_modules[ $module_key ] = $module;
} else {
// Add to the free array
$free_modules[ $module_key ] = $module;
}
}
// Create array, inserting all the free modules first
$modules = array_merge( $free_modules, $pro_modules );
}
/**
* Determinate if each module can be used
* we're going to check if the user has pro enabled and if it has the required dependencies
*/
?>
<script>
<?php
$js_modules = [];
foreach ( $modules as $module ) {
$js_modules[] = [
'id' => $module[ 'id' ],
'title' => $module[ 'title' ],
'description' => $module[ 'description' ],
];
}
?>
var ultModules = <?php echo json_encode( $js_modules ); ?>;
</script>
<div class="container">
<div class="ult">
<div class="ult-directory">
<div class="ult-directory-actions">
<div class="ult-directory-filters">
<div class="ult-directory-filter ult-directory-filter--version">
<div class="ult-form-element">
<div class="ult-form-element__field">
<select name="version" data-name="version" class="ult-form-element__select">
<option value="">
<?php _e( 'All versions', 'uncanny-learndash-toolkit' ) ?>
</option>
<option value="free">
<?php _e( 'Free only', 'uncanny-learndash-toolkit' ) ?>
</option>
<option value="pro">
<?php _e( 'Pro only', 'uncanny-learndash-toolkit' ) ?>
</option>
</select>
</div>
</div>
</div>
<div class="ult-directory-filter ult-directory-filter--categories">
<div class="ult-form-element">
<div class="ult-form-element__field">
<select name="category" data-name="category" class="ult-form-element__select">
<option value="">
<?php _e( 'All categories', 'uncanny-learndash-toolkit' ) ?>
</option>
<option value="learndash">
<?php _e( 'LearnDash', 'uncanny-learndash-toolkit' ) ?>
</option>
<option value="wordpress">
<?php _e( 'General WordPress', 'uncanny-learndash-toolkit' ) ?>
</option>
</select>
</div>
</div>
</div>
<div class="ult-directory-filter ult-directory-filter--statuses">
<div class="ult-form-element">
<div class="ult-form-element__field">
<select name="status" data-name="status" class="ult-form-element__select">
<option value="">
<?php _e( 'All statuses', 'uncanny-learndash-toolkit' ) ?>
</option>
<option value="active">
<?php _e( 'Active', 'uncanny-learndash-toolkit' ) ?>
</option>
<option value="inactive">
<?php _e( 'Inactive', 'uncanny-learndash-toolkit' ) ?>
</option>
</select>
</div>
</div>
</div>
</div>
<div class="ult-directory-search">
<div class="ult-form-element">
<div class="ult-form-element__field">
<input type="text" id="ult-directory-search-input"
class="ult-directory-search-input ult-form-element__text"
placeholder="<?php _e( 'Search modules by title, description or keywords', 'uncanny-learndash-toolkit' ) ?>">
</div>
</div>
</div>
<div class="ult-directory-layout">
<div id="ult-directory-layout-toggle">
<div class="ult-directory-layout-item" data-view="grid">
<span class="ult-icon ult-icon--th"></span>
</div>
<div class="ult-directory-layout-item" data-view="table">
<span class="ult-icon ult-icon--th-list"></span>
</div>
</div>
</div>
</div>
<div class="ult-directory-modules">
<?php
foreach ( $modules as $module ) {
$css_classes = [];
if ( ! isset( $module['can_use'] ) || ! $module['can_use'] ) {
$css_classes[] = 'ult-directory-module--cant-use';
}
if ( isset( $module['version'] ) && $module['version'] ) {
$css_classes[] = 'ult-directory-module--is-pro';
}
?>
<div class="ult-directory-module <?php echo implode( ' ', $css_classes ); ?>"
data-id="<?php echo isset( $module['id'] ) ? $module['id'] : md5( time() ); ?>"
data-version="<?php echo isset( $module['version'] ) ? $module['version'] : 'free'; ?>"
data-status="<?php echo isset( $module['is_active'] ) && $module['is_active'] ? 'active' : 'inactive'; ?>"
data-category='<?php echo isset( $module['category'] ) ? json_encode( $module['category'] ) : json_encode( array() ); ?>'
>
<div class="ult-directory-module-content">
<?php if ( ! empty( $module['cant_use_notice'] ) ) { ?>
<div class="ult-directory-module-notice">
<div class="ult-directory-module-notice__icon">
<span class="ult-icon ult-icon--lock-alt"></span>
</div>
<div class="ult-directory-module-notice__text">
<?php echo $module['cant_use_notice']; ?>
</div>
</div>
<?php } ?>
<div class="ult-directory-module-header">
<div class="ult-directory-module-header-left">
<div class="ult-directory-module__title">
<?php echo $module['title']; ?>
</div>
<?php if ( isset( $module['version'] ) && 'pro' === $module['version'] ) { ?>
<?php
// Get the link
// Check if the module ID is defined
if ( ! empty( $module[ 'utm_id' ] ) ){
$get_toolkit_pro_link = Config::utm_parameters( $config[ 'get_toolkit_pro' ], 'modules', 'pro_badge_on_title-' . $module[ 'utm_id' ] );
}
else {
$get_toolkit_pro_link = Config::utm_parameters( $config[ 'get_toolkit_pro' ], 'modules', 'pro_badge_on_title' );
}
?>
<a href="<?php echo $get_toolkit_pro_link; ?>" target="_blank"
class="ult-directory-module__pro-label">
<?php _e( 'Pro', 'uncanny-learndash-toolkit' ); ?>
</a>
<?php } ?>
</div>
<?php if ( isset( $module['can_use'] ) && $module['can_use'] ) { ?>
<div class="ult-directory-module__status">
<div class="ult-form-element">
<div class="ult-form-checkbox ult-form-checkbox--toggle ult-form-checkbox--toggle-gutenberg">
<label class="ult-form-checkbox__container">
<input type="checkbox"
class="ult-directory-module__status-toggle ult-checkbox--hidden ult-checkbox--primary"
value="<?php echo $module['class_name']; ?>"
<?php echo $module['is_active'] ? 'checked="checked"' : ''; ?>
/>
<div class="ult-checkbox--show"></div>
</label>
</div>
</div>
</div>
<?php } ?>
</div>
<div class="ult-directory-module__description">
<?php echo $module['description']; ?>
</div>
<div class="ult-directory-module-actions">
<?php if ( isset( $module['can_use'] ) && $module['can_use'] ) { ?>
<?php if ( false !== $module['has_settings'] ) { ?>
<div class="ult-directory-module-settings ult-directory-module-settings--modal ult-directory-module__btn ult-btn ult-btn--primary"
data-settings="<?php echo $module['settings_id']; ?>">
<?php _e( 'Settings', 'uncanny-learndash-toolkit' ); ?>
</div>
<?php } ?>
<?php }
// Check if it has a KB article
if ( ! empty( $module['kb_link'] ) ) {
// Get the link
// Check if the module ID is defined
if ( ! empty( $module[ 'utm_id' ] ) ){
$module_kb_link = Config::utm_parameters( $module[ 'kb_link' ], 'modules', 'learn_more-' . $module[ 'utm_id' ] );
}
else {
$module_kb_link = Config::utm_parameters( $module[ 'kb_link' ], 'modules', 'learn_more' );
}
// Add the link
?>
<a href="<?php echo $module_kb_link; ?>" target="_blank"
class="ult-directory-module-settings ult-directory-module-settings--kb-link ult-directory-module__btn ult-btn ult-btn--secondary">
<?php _e( 'Learn More', 'uncanny-learndash-toolkit' ); ?>
</a>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>