-
Notifications
You must be signed in to change notification settings - Fork 0
/
OxyLearnDash.php
337 lines (250 loc) · 11.6 KB
/
OxyLearnDash.php
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
327
328
329
330
331
332
333
334
335
336
337
<?php
if (class_exists('OxyLearnDash')) {
return;
}
Class OxyLearnDash{
function __construct() {
$this->load_files();
$this->setup_options();
// Register +Add LearnDash section
add_action('oxygen_add_plus_sections', array($this, 'oxydash_register_section'));
// Register +Add LearnDash subsections
// oxygen_add_plus_{$id}_section_content
add_action('oxygen_add_plus_dash_section_content', array($this, 'oxydash_register_subsections'));
// Dash Global Styles UI
add_action('oxygen_vsb_global_styles_tabs', array($this, 'global_settings_tab'));
add_action('oxygen_vsb_settings_content', array($this, 'global_settings'));
// Global styles CSS
add_filter('oxy_global_settings_defaults', array($this, 'filter_global_settings_defaults'));
add_filter('oxy_elements_api_page_css_output', array($this, 'filter_global_settings'));
add_filter('oxygen_builder_options', array($this, 'builder_global_styles_css'));
add_filter('oxygen_header_font_families', array($this, 'header_font_families'));
add_action('oxygen_default_classes_output', array($this, 'global_styles_universal_css'));
add_action('wp_footer', array($this, 'flexslider_fix'));
add_action('init', array($this, 'init_callback'));
}
function setup_options() {
// Buttons
$this->buttons_settings = array(
"--primary-cta" => __("Primary CTA"),
"--primary-cta-hover" => __("Primary CTA Hover"),
"--primary-cta-text" => __("Primary CTA Text"),
"--secondary-cta" => __("Secondary CTA"),
"--secondary-cta-hover" => __("Secondary CTA Hover"),
"--secondary-cta-text" => __("Secondary CTA Text"),
"--tertiary-cta" => __("Tertiary CTA"),
"--tertiary-cta-hover" => __("Tertiary CTA Hover"),
"--tertiary-cta-background" => __("Tertiary CTA Background"),
"--disabled-button" => __("Disabled Button"),
"--button-radius" => __("Button Radius"),
);
$this->buttons_settings_defaults = array(
"--primary-cta" => "#65bec2",
"--primary-cta-hover" => "#6799b2",
"--primary-cta-text" => "#ffffff",
"--secondary-cta" => "#666666",
"--secondary-cta-hover" => "#999999",
"--secondary-cta-text" => "#ffffff",
"--tertiary-cta" => "#65bec2",
"--tertiary-cta-hover" => "#6799b2",
"--tertiary-cta-background" => "#ffffff",
"--disabled-button" => "#cccccc",
"--button-radius" => "4",
"--button-radius-unit" => "px",
);
// Links
$this->links_settings = array(
"--standard-link" => __("Standard Link"),
"--standard-link-hover" => __("Standard Link Hover"),
);
$this->links_settings_defaults = array(
"--standard-link" => "#6799b2",
"--standard-link-hover" => "#65bec2"
);
// Inputs
$this->inputs_settings = array(
"--input-border" => __("Input Border"),
"--input-focus-border" => __("Input Focus Border"),
"--input-placeholder-text" => __("Input Placeholder Text"),
"--input-background" => __("Input Background"),
"--input-radius" => __("Input Radius"),
);
$this->inputs_settings_defaults = array(
"--input-border" => "#d3ced2",
"--input-focus-border" => "#65bec2",
"--input-placeholder-text" => "#d3ced2",
"--input-background" => "#ffffff",
"--input-radius" => "4",
"--input-radius-unit" => "px",
);
// Text
$this->text_settings = array(
"--text-normal" => __("Text Normal"),
"--text-strong" => __("Text Strong"),
);
$this->text_settings_defaults = array(
"--text-normal" => "#666666",
"--text-strong" => "#000000",
);
// Notifications
$this->notifications_settings = array(
"--info-color" => __("Info Color"),
"--error-color" => __("Error Color"),
"--message-color" => __("Message Color"),
);
$this->notifications_settings_defaults = array(
"--info-color" => "#00adef",
"--error-color" => "#e96199",
"--message-color" => "#65bec2",
);
// Misc
$this->misc_settings = array(
"--sale-badge-color" => __("Sale Badge Color"),
"--star-rating-primary" => __("Star Rating Primary"),
"--star-rating-greyed" => __("Star Rating Greyed"),
"--border-normal" => __("Border Normal"),
"--border-image" => __("Border Image"),
"--box-background" => __("Box Background"),
);
$this->misc_settings_defaults = array(
"--sale-badge-color" => "#65bec2",
"--star-rating-primary" => "#65bec2",
"--star-rating-greyed" => "#d3d3d3",
"--border-normal" => "#d3ced2",
"--border-image" => "#d3ced2",
"--box-background" => "#ffffff",
);
// Misc
$this->widget_settings = array(
"--widget-title-font-size" => __("Widget Title Font Size"),
"--widget-title-font-weight" => __("Widget Title Font Weight"),
"--widget-title-font-family" => __("Widget Title Font Family"),
);
$this->widget_settings_defaults = array(
"--widget-title-font-size" => "",
"--widget-title-font-size-unit" => "px",
"--widget-title-font-weight" => "",
"--widget-title-font-family" => "",
);
}
/** */
function load_files() {
// Single Course
include_once "elements/course-list.php";
// auto include new elements
$element_filenames = glob(plugin_dir_path(__FILE__)."elements/*.php");
foreach ($element_filenames as $filename) {
include_once $filename;
}
}
/** Registers the LearnDash section in Oxygen */
function oxydash_register_section() {
CT_Toolbar::oxygen_add_plus_accordion_section("dash",_e("LearnDash"));
}
/** Loads all the LearnDash elements for Oxygen */
function oxydash_register_subsections() { ?>
<h2><?php _e("Course List");?></h2>
<?php do_action("oxygen_add_plus_dash_single"); ?>
<?php }
function global_settings_tab() {
global $oxygen_toolbar;
$oxygen_toolbar->settings_tab(__("LearnDash", "oxygen"), "woo", "panelsection-icons/styles.svg");
}
function global_settings() { ?>
<div ng-if="isShowTab('settings','dash')">
<?php include_once "settings/global-settings.view.php"; ?>
</div>
<?php }
function filter_global_settings_defaults( $defaults ) {
$defaults['dash'] = array();
$defaults['dash'] = array_merge($defaults['dash'], $this->buttons_settings_defaults);
$defaults['dash'] = array_merge($defaults['dash'], $this->links_settings_defaults);
$defaults['dash'] = array_merge($defaults['dash'], $this->inputs_settings_defaults);
$defaults['dash'] = array_merge($defaults['dash'], $this->text_settings_defaults);
$defaults['dash'] = array_merge($defaults['dash'], $this->notifications_settings_defaults);
$defaults['dash'] = array_merge($defaults['dash'], $this->misc_settings_defaults);
$defaults['dash'] = array_merge($defaults['dash'], $this->widget_settings_defaults);
return $defaults;
}
function filter_global_settings( $css ) {
// remove variables definitions
$css = preg_replace('%\/\*STRIP START\*\/(.*?)\/\*STRIP END\*\/%s', '', $css);
$global_settings = ct_get_global_settings();
if (isset($global_settings['dash'])){
// units
foreach ($global_settings['dash'] as $key => $value) {
if (isset($global_settings['dash'][$key."-unit"])) {
$global_settings['dash'][$key] = $value.$global_settings['woo'][$key."-unit"];
}
}
$options = array_keys ($global_settings['dash']);
$values = array_values($global_settings['dash']);
$options = array_map(function($value){
return "var($value)";
}, $options);
// global colors
$values = array_map(function($value){
return oxygen_vsb_get_global_color_value($value);
}, $values);
$css = str_replace($options, $values, $css);
}
return $css;
}
function builder_global_styles_css($options) {
$options["dashGlobalStyles"] = file_get_contents(__DIR__.'/elements/dash-global-styler.css');
$options["dashAssetsPath"] = OXY_DASH_ASSETS_PATH;
return $options;
}
function header_font_families($fonts) {
$global_settings = ct_get_global_settings();
foreach ($global_settings['dash'] as $key => $value) {
if (strpos($key, "font-family") !== false) {
$fonts[] = $value;
}
}
return $fonts;
}
function global_styles_universal_css() {
$global_css = file_get_contents(__DIR__.'/elements/dash-global-styler.css');
$global_css = str_replace("%%ASSETS_PATH%%", OXY_DASH_ASSETS_PATH, $global_css);
$global_css = $this->filter_global_settings($global_css);
echo $global_css;
}
function flexslider_fix() {
if (!defined("SHOW_CT_BUILDER") || !defined("OXYGEN_IFRAME")) {
return;
}
?><script type="text/javascript">
document.addEventListener('oxygen-ajax-element-loaded', function (e) {
setTimeout(function() {
jQuery(".learndash-coruse-gallery").each(function(){
var gallery = jQuery(this);
var viewport = gallery.find('.flex-viewport');
if (viewport.length > 1){
viewport.first().remove();
}
var thumbs = gallery.find('.flex-control-nav');
if (thumbs.length > 1){
thumbs.first().remove();
}
var icon = gallery.find('.learndash-course-gallery__trigger');
if (icon.length > 1){
icon.first().remove();
}
var flexSlider = gallery.data('flexslider');
if (flexSlider) {
flexSlider.update();
flexSlider.doMath();
}
});
}, 100);
}, false);
</script><?php
}
function init_callback() {
// we don't want learndash redirects to work when builder is loading
if ( defined("SHOW_CT_BUILDER") || defined("OXYGEN_IFRAME") ) {
remove_action( 'template_redirect', 'ld_template_redirect' );
}
}
}