PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.76
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.76
1.2.76 1.2.75 1.2.74 1.2.73 1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 All 176 releases
userswp / vendor / ayecode / wp-ayecode-ui / includes / ayecode-ui-settings.php

ayecode-ui-settings.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.2.76, at vendor/ayecode/wp-ayecode-ui/includes/ayecode-ui-settings.php

3,511 lines 137.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * A class for adjusting AyeCode UI settings on WordPress
4 *
5 * This class can be added to any plugin or theme and will add a settings screen to WordPress to control Bootstrap settings.
6 *
7 * @link https://github.com/AyeCode/wp-ayecode-ui
8 *
9 * @internal This file should not be edited directly but pulled from the github repo above.
10 */
11
12 /**
13 * Bail if we are not in WP.
14 */
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 /**
20 * Only add if the class does not already exist.
21 */
22 if ( ! class_exists( 'AyeCode_UI_Settings' ) ) {
23
24 /**
25 * A Class to be able to change settings for Font Awesome.
26 *
27 * Class AyeCode_UI_Settings
28 * @ver 1.0.0
29 * @todo decide how to implement textdomain
30 */
31 class AyeCode_UI_Settings {
32
33 /**
34 * Class version version.
35 *
36 * @var string
37 */
38 public $version = '0.2.56';
39
40 /**
41 * Class textdomain.
42 *
43 * @var string
44 */
45 public $textdomain = 'aui';
46
47 /**
48 * Latest version of Bootstrap at time of publish published.
49 *
50 * @var string
51 */
52 public $latest = "5.2.2";
53
54 /**
55 * Current version of select2 being used.
56 *
57 * @var string
58 */
59 public $select2_version = "4.0.11";
60
61 /**
62 * The title.
63 *
64 * @var string
65 */
66 public $name = 'AyeCode UI';
67
68 /**
69 * The relative url to the assets.
70 *
71 * @var string
72 */
73 public $url = '';
74
75 /**
76 * Holds the settings values.
77 *
78 * @var array
79 */
80 private $settings;
81
82 /**
83 * AyeCode_UI_Settings instance.
84 *
85 * @access private
86 * @since 1.0.0
87 * @var AyeCode_UI_Settings There can be only one!
88 */
89 private static $instance = null;
90
91
92 /**
93 * Main AyeCode_UI_Settings Instance.
94 *
95 * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded.
96 *
97 * @since 1.0.0
98 * @static
99 * @return AyeCode_UI_Settings - Main instance.
100 */
101 public static function instance() {
102 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) {
103
104 self::$instance = new AyeCode_UI_Settings;
105
106 add_action( 'init', array( self::$instance, 'init' ) ); // set settings
107
108 if ( is_admin() ) {
109 add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
110 add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
111
112 // Maybe show example page
113 add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) );
114
115 if ( defined( 'BLOCKSTRAP_VERSION' ) ) {
116 add_filter( 'sd_aui_colors', array( self::$instance,'sd_aui_colors' ), 10, 3 );
117 }
118 }
119
120 add_action( 'customize_register', array( self::$instance, 'customizer_settings' ));
121
122 do_action( 'ayecode_ui_settings_loaded' );
123 }
124
125 return self::$instance;
126 }
127
128 /**
129 * Add custom colors to the color selector.
130 *
131 * @param $theme_colors
132 * @param $include_outlines
133 * @param $include_branding
134 *
135 * @return mixed
136 */
137 public function sd_aui_colors( $theme_colors, $include_outlines, $include_branding ){
138
139
140 $setting = wp_get_global_settings();
141
142 if(!empty($setting['color']['palette']['custom'])){
143 foreach($setting['color']['palette']['custom'] as $color){
144 $theme_colors[$color['slug']] = esc_attr($color['name']);
145 }
146 }
147
148 return $theme_colors;
149 }
150
151 /**
152 * Setup some constants.
153 */
154 public function constants(){
155 // Another copy of this package may have defined these already.
156 defined( 'AUI_PRIMARY_COLOR_ORIGINAL' ) || define( 'AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be" );
157 defined( 'AUI_SECONDARY_COLOR_ORIGINAL' ) || define( 'AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d' );
158 defined( 'AUI_INFO_COLOR_ORIGINAL' ) || define( 'AUI_INFO_COLOR_ORIGINAL', '#17a2b8' );
159 defined( 'AUI_WARNING_COLOR_ORIGINAL' ) || define( 'AUI_WARNING_COLOR_ORIGINAL', '#ffc107' );
160 defined( 'AUI_DANGER_COLOR_ORIGINAL' ) || define( 'AUI_DANGER_COLOR_ORIGINAL', '#dc3545' );
161 defined( 'AUI_SUCCESS_COLOR_ORIGINAL' ) || define( 'AUI_SUCCESS_COLOR_ORIGINAL', '#44c553' );
162 defined( 'AUI_LIGHT_COLOR_ORIGINAL' ) || define( 'AUI_LIGHT_COLOR_ORIGINAL', '#f8f9fa' );
163 defined( 'AUI_DARK_COLOR_ORIGINAL' ) || define( 'AUI_DARK_COLOR_ORIGINAL', '#343a40' );
164 defined( 'AUI_WHITE_COLOR_ORIGINAL' ) || define( 'AUI_WHITE_COLOR_ORIGINAL', '#fff' );
165 defined( 'AUI_PURPLE_COLOR_ORIGINAL' ) || define( 'AUI_PURPLE_COLOR_ORIGINAL', '#ad6edd' );
166 defined( 'AUI_SALMON_COLOR_ORIGINAL' ) || define( 'AUI_SALMON_COLOR_ORIGINAL', '#ff977a' );
167 defined( 'AUI_CYAN_COLOR_ORIGINAL' ) || define( 'AUI_CYAN_COLOR_ORIGINAL', '#35bdff' );
168 defined( 'AUI_GRAY_COLOR_ORIGINAL' ) || define( 'AUI_GRAY_COLOR_ORIGINAL', '#ced4da' );
169 defined( 'AUI_INDIGO_COLOR_ORIGINAL' ) || define( 'AUI_INDIGO_COLOR_ORIGINAL', '#502c6c' );
170 defined( 'AUI_ORANGE_COLOR_ORIGINAL' ) || define( 'AUI_ORANGE_COLOR_ORIGINAL', '#orange' );
171 defined( 'AUI_BLACK_COLOR_ORIGINAL' ) || define( 'AUI_BLACK_COLOR_ORIGINAL', '#000' );
172
173 if ( ! defined( 'AUI_PRIMARY_COLOR' ) ) {
174 define( 'AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL );
175 }
176 if ( ! defined( 'AUI_SECONDARY_COLOR' ) ) {
177 define( 'AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL );
178 }
179 if ( ! defined( 'AUI_INFO_COLOR' ) ) {
180 define( 'AUI_INFO_COLOR', AUI_INFO_COLOR_ORIGINAL );
181 }
182 if ( ! defined( 'AUI_WARNING_COLOR' ) ) {
183 define( 'AUI_WARNING_COLOR', AUI_WARNING_COLOR_ORIGINAL );
184 }
185 if ( ! defined( 'AUI_DANGER_COLOR' ) ) {
186 define( 'AUI_DANGER_COLOR', AUI_DANGER_COLOR_ORIGINAL );
187 }
188 if ( ! defined( 'AUI_SUCCESS_COLOR' ) ) {
189 define( 'AUI_SUCCESS_COLOR', AUI_SUCCESS_COLOR_ORIGINAL );
190 }
191 if ( ! defined( 'AUI_LIGHT_COLOR' ) ) {
192 define( 'AUI_LIGHT_COLOR', AUI_LIGHT_COLOR_ORIGINAL );
193 }
194 if ( ! defined( 'AUI_DARK_COLOR' ) ) {
195 define( 'AUI_DARK_COLOR', AUI_DARK_COLOR_ORIGINAL );
196 }
197 if ( ! defined( 'AUI_WHITE_COLOR' ) ) {
198 define( 'AUI_WHITE_COLOR', AUI_WHITE_COLOR_ORIGINAL );
199 }
200 if ( ! defined( 'AUI_PURPLE_COLOR' ) ) {
201 define( 'AUI_PURPLE_COLOR', AUI_PURPLE_COLOR_ORIGINAL );
202 }
203 if ( ! defined( 'AUI_SALMON_COLOR' ) ) {
204 define( 'AUI_SALMON_COLOR', AUI_SALMON_COLOR_ORIGINAL );
205 }
206 if ( ! defined( 'AUI_CYAN_COLOR' ) ) {
207 define( 'AUI_CYAN_COLOR', AUI_CYAN_COLOR_ORIGINAL );
208 }
209 if ( ! defined( 'AUI_GRAY_COLOR' ) ) {
210 define( 'AUI_GRAY_COLOR', AUI_GRAY_COLOR_ORIGINAL );
211 }
212 if ( ! defined( 'AUI_INDIGO_COLOR' ) ) {
213 define( 'AUI_INDIGO_COLOR', AUI_INDIGO_COLOR_ORIGINAL );
214 }
215 if ( ! defined( 'AUI_ORANGE_COLOR' ) ) {
216 define( 'AUI_ORANGE_COLOR', AUI_ORANGE_COLOR_ORIGINAL );
217 }
218 if ( ! defined( 'AUI_BLACK_COLOR' ) ) {
219 define( 'AUI_BLACK_COLOR', AUI_BLACK_COLOR_ORIGINAL );
220 }
221
222 }
223
224 public static function get_colors( $original = false){
225
226 if ( ! defined( 'AUI_PRIMARY_COLOR' ) ) {
227 return array();
228 }
229 if ( $original ) {
230 return array(
231 'primary' => AUI_PRIMARY_COLOR_ORIGINAL,
232 'secondary' => AUI_SECONDARY_COLOR_ORIGINAL,
233 'info' => AUI_INFO_COLOR_ORIGINAL,
234 'warning' => AUI_WARNING_COLOR_ORIGINAL,
235 'danger' => AUI_DANGER_COLOR_ORIGINAL,
236 'success' => AUI_SUCCESS_COLOR_ORIGINAL,
237 'light' => AUI_LIGHT_COLOR_ORIGINAL,
238 'dark' => AUI_DARK_COLOR_ORIGINAL,
239 'white' => AUI_WHITE_COLOR_ORIGINAL,
240 'purple' => AUI_PURPLE_COLOR_ORIGINAL,
241 'salmon' => AUI_SALMON_COLOR_ORIGINAL,
242 'cyan' => AUI_CYAN_COLOR_ORIGINAL,
243 'gray' => AUI_GRAY_COLOR_ORIGINAL,
244 'indigo' => AUI_INDIGO_COLOR_ORIGINAL,
245 'orange' => AUI_ORANGE_COLOR_ORIGINAL,
246 'black' => AUI_BLACK_COLOR_ORIGINAL,
247 );
248 }
249
250 return array(
251 'primary' => AUI_PRIMARY_COLOR,
252 'secondary' => AUI_SECONDARY_COLOR,
253 'info' => AUI_INFO_COLOR,
254 'warning' => AUI_WARNING_COLOR,
255 'danger' => AUI_DANGER_COLOR,
256 'success' => AUI_SUCCESS_COLOR,
257 'light' => AUI_LIGHT_COLOR,
258 'dark' => AUI_DARK_COLOR,
259 'white' => AUI_WHITE_COLOR,
260 'purple' => AUI_PURPLE_COLOR,
261 'salmon' => AUI_SALMON_COLOR,
262 'cyan' => AUI_CYAN_COLOR,
263 'gray' => AUI_GRAY_COLOR,
264 'indigo' => AUI_INDIGO_COLOR,
265 'orange' => AUI_ORANGE_COLOR,
266 'black' => AUI_BLACK_COLOR,
267 );
268 }
269
270 /**
271 * Add admin body class to show when BS5 is active.
272 *
273 * @param $classes
274 *
275 * @return mixed
276 */
277 public function add_bs5_admin_body_class( $classes = '' ) {
278 $classes .= ' aui_bs5';
279
280 return $classes;
281 }
282
283 /**
284 * Add a body class to show when BS5 is active.
285 *
286 * @param $classes
287 *
288 * @return mixed
289 */
290 public function add_bs5_body_class( $classes ) {
291 $classes[] = 'aui_bs5';
292
293 return $classes;
294 }
295
296 /**
297 * Initiate the settings and add the required action hooks.
298 */
299 public function init() {
300 global $aui_bs5;
301
302 // Maybe fix settings
303 if ( ! empty( $_REQUEST['aui-fix-admin'] ) && !empty($_REQUEST['nonce']) && wp_verify_nonce( $_REQUEST['nonce'], "aui-fix-admin" ) ) {
304 $db_settings = get_option( 'ayecode-ui-settings' );
305 if ( ! empty( $db_settings ) ) {
306 $db_settings['css_backend'] = 'compatibility';
307 $db_settings['js_backend'] = 'core-popper';
308 update_option( 'ayecode-ui-settings', $db_settings );
309 wp_safe_redirect(admin_url("options-general.php?page=ayecode-ui-settings&updated=true"));
310 }
311 }
312
313 $this->constants();
314 $this->settings = $this->get_settings();
315 $this->url = $this->get_url();
316
317 // define the version
318 $aui_bs5 = $this->settings['bs_ver'] === '5';
319
320 if ( $aui_bs5 ) {
321 include_once( dirname( __FILE__ ) . '/inc/bs-conversion.php' );
322 add_filter( 'admin_body_class', array( $this, 'add_bs5_admin_body_class' ), 99, 1 );
323 add_filter( 'body_class', array( $this, 'add_bs5_body_class' ) );
324 }
325
326 /**
327 * Maybe load CSS
328 *
329 * We load super early in case there is a theme version that might change the colors
330 */
331 if ( $this->settings['css'] ) {
332 $priority = $this->is_bs3_compat() ? 100 : 1;
333 $priority = $aui_bs5 ? 10 : $priority;
334 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), $priority );
335 }
336 if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) {
337 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
338 // WordPress 6.9+ iframe compatibility.
339 add_action( 'enqueue_block_assets', [ $this, 'enqueue_block_assets' ], 100 );
340 }
341
342 // maybe load JS
343 if ( $this->settings['js'] ) {
344 $priority = $this->is_bs3_compat() ? 100 : 1;
345 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority );
346 }
347 if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) {
348 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 );
349 }
350
351 // Maybe set the HTML font size
352 if ( $this->settings['html_font_size'] ) {
353 add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 );
354 }
355
356 // Maybe show backend style error
357 if( $this->settings['css_backend'] != 'compatibility' || $this->settings['js_backend'] != 'core-popper' ){
358 add_action( 'admin_notices', array( $this, 'show_admin_style_notice' ) );
359 }
360
361 }
362
363 /**
364 * Show admin notice if backend scripts not loaded.
365 */
366 public function show_admin_style_notice(){
367 $fix_url = admin_url("options-general.php?page=ayecode-ui-settings&aui-fix-admin=true&nonce=".wp_create_nonce('aui-fix-admin'));
368 $button = '<a href="'.esc_url($fix_url).'" class="button-primary">Fix Now</a>';
369 $message = __( '<b>Style Issue:</b> AyeCode UI is disable or set wrong.')." " .$button;
370 echo '<div class="notice notice-error aui-settings-error-notice"><p>'. wp_kses_post( $message ).'</p></div>';
371 }
372
373 /**
374 * Check if we should load the admin scripts or not.
375 *
376 * @return bool
377 */
378 public function load_admin_scripts(){
379 $result = true;
380
381 // check if specifically disabled
382 if(!empty($this->settings['disable_admin'])){
383 $url_parts = explode("\n",$this->settings['disable_admin']);
384 foreach($url_parts as $part){
385 if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){
386 return false; // return early, no point checking further
387 }
388 }
389 }
390
391 return $result;
392 }
393
394 /**
395 * Add a html font size to the footer.
396 */
397 public function html_font_size(){
398 $this->settings = $this->get_settings();
399 echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>";
400 }
401
402 /**
403 * Check if the current admin screen should load scripts.
404 *
405 * @return bool
406 */
407 public function is_aui_screen() {
408 $load = false;
409
410 // Check if we should load or not
411 if ( is_admin() ) {
412 // Only enable on set pages
413 $aui_screens = array(
414 'page',
415 'post',
416 'settings_page_ayecode-ui-settings',
417 'appearance_page_gutenberg-widgets',
418 'widgets',
419 'ayecode-ui-settings',
420 'site-editor'
421 );
422
423 $screen_ids = apply_filters( 'aui_screen_ids', $aui_screens );
424 $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : array();
425
426 // Check if we are on a AUI screen
427 if ( $screen && in_array( $screen->id, $screen_ids ) ) {
428 $load = true;
429 }
430
431 // Load for widget previews in WP 5.8
432 if ( ! empty( $_REQUEST['legacy-widget-preview'] ) ) {
433 $load = true;
434 }
435 }
436
437 return apply_filters( 'aui_load_on_admin' , $load );
438 }
439
440 /**
441 * Check if the current theme is a block theme.
442 *
443 * @return bool
444 */
445 public static function is_block_theme() {
446 if ( function_exists( 'wp_is_block_theme' && wp_is_block_theme() ) ) {
447 return true;
448 }
449
450 return false;
451 }
452
453 /**
454 * Adds the styles.
455 */
456 public function enqueue_style( $context = '' ) {
457 global $aui_bs5;
458
459 $load_fse = false;
460
461 if ( is_admin() && ! $this->is_aui_screen() ) {
462 // Don't add wp-admin scripts if not requested to.
463 } else {
464 $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend';
465 $rtl = is_rtl() && ! $aui_bs5 ? '-rtl' : '';
466 $bs_ver = $this->settings['bs_ver'] == '5' ? '-v5' : '';
467
468 if ( $this->settings[ $css_setting ] ) {
469 $compatibility = $this->settings[ $css_setting ] == 'core' ? false : true;
470 $base_url = $this->url . 'assets' . $bs_ver . '/css/';
471 $url = $this->settings[ $css_setting ] == 'core' ? $base_url . 'ayecode-ui' . $rtl . '.css' : $base_url . 'ayecode-ui-compatibility' . $rtl . '.css';
472
473 wp_register_style( 'ayecode-ui', $url, array(), $this->version );
474 wp_enqueue_style( 'ayecode-ui' );
475
476 if ( is_admin() && ( ! empty( $_REQUEST['postType'] ) || self::is_block_editor() ) && ( defined( 'BLOCKSTRAP_VERSION' ) || defined( 'AUI_FSE' ) ) ) {
477 $url = $base_url . 'ayecode-ui-fse.css';
478 $load_fse = true;
479
480 wp_register_style( 'ayecode-ui-fse', $url, array(), $this->version );
481 wp_enqueue_style( 'ayecode-ui-fse' );
482 }
483
484 // Flatpickr
485 wp_register_style( 'flatpickr', $base_url . 'flatpickr.min.css', array(), $this->version );
486
487 // Fix some wp-admin issues
488 if ( is_admin() ) {
489 $custom_css = "
490 body:not(.editor-styles-wrapper){
491 background-color: #f1f1f1;
492 font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif;
493 font-size:13px;
494 }
495 a {
496 color: #0073aa;
497 text-decoration: underline;
498 }
499 label {
500 display: initial;
501 margin-bottom: 0;
502 }
503 input, select {
504 margin: 1px;
505 line-height: initial;
506 }
507 th, td, div, h2 {
508 box-sizing: content-box;
509 }
510 h1, h2, h3, h4, h5, h6 {
511 display: block;
512 font-weight: 600;
513 }
514 h2,h3 {
515 font-size: 1.3em;
516 margin: 1em 0
517 }
518 .blocks-widgets-container .bsui *{
519 box-sizing: border-box;
520 }
521 .bs-tooltip-top .arrow{
522 margin-left:0px;
523 }
524 .custom-switch input[type=checkbox]{
525 display:none;
526 }
527 ";
528
529 // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377
530 $custom_css .= "
531 .edit-post-sidebar input[type=color].components-text-control__input{
532 padding: 0;
533 }
534 ";
535
536 wp_add_inline_style( 'ayecode-ui', $custom_css );
537 }
538
539 // Custom changes.
540 if ( $load_fse ) {
541 wp_add_inline_style( 'ayecode-ui-fse', self::custom_css( $compatibility, true ) );
542 } else {
543 wp_add_inline_style( 'ayecode-ui', self::custom_css( $compatibility ) );
544 }
545 }
546 }
547 }
548
549 /**
550 * Enqueue styles for block assets (both editor and frontend).
551 * This ensures compatibility with WordPress 6.9+ requirements.
552 */
553 public function enqueue_block_assets() {
554 global $wp_version;
555
556 if ( is_admin() && version_compare( $wp_version, '6.9', '>=' ) ) {
557 $this->enqueue_style( 'block_assets' );
558 }
559 }
560
561 /**
562 * Get inline script used if bootstrap enqueued
563 *
564 * If this remains small then its best to use this than to add another JS file.
565 */
566 public function inline_script() {
567 global $aui_bs5;
568 // Flatpickr calendar locale
569 $flatpickr_locale = self::flatpickr_locale();
570
571 ob_start();
572 if ( $aui_bs5 ) {
573 include_once( dirname( __FILE__ ) . '/inc/bs5-js.php' );
574 }else{
575 include_once( dirname( __FILE__ ) . '/inc/bs4-js.php' );
576 }
577
578 $output = ob_get_clean();
579
580 /*
581 * We only add the <script> tags for code highlighting, so we strip them from the output.
582 */
583 return str_replace( array(
584 '<script>',
585 '</script>'
586 ), '', self::minify_js($output) );
587 }
588
589
590 /**
591 * JS to help with conflict issues with other plugins and themes using bootstrap v3.
592 *
593 * @TODO we may need this when other conflicts arrise.
594 * @return mixed
595 */
596 public static function bs3_compat_js() {
597 ob_start();
598 ?>
599 <script>
600 <?php if( defined( 'FUSION_BUILDER_VERSION' ) ){ ?>
601 /* With Avada builder */
602
603 <?php } ?>
604 </script>
605 <?php
606 return str_replace( array(
607 '<script>',
608 '</script>'
609 ), '', ob_get_clean());
610 }
611
612 /**
613 * Get inline script used if bootstrap file browser enqueued.
614 *
615 * If this remains small then its best to use this than to add another JS file.
616 */
617 public function inline_script_file_browser(){
618 ob_start();
619 ?>
620 <script>
621 // run on doc ready
622 jQuery(document).ready(function () {
623 bsCustomFileInput.init();
624 });
625 </script>
626 <?php
627 $output = ob_get_clean();
628
629 /*
630 * We only add the <script> tags for code highlighting, so we strip them from the output.
631 */
632 return str_replace( array(
633 '<script>',
634 '</script>'
635 ), '', $output );
636 }
637
638 /**
639 * Adds the Font Awesome JS.
640 */
641 public function enqueue_scripts() {
642 if( is_admin() && !$this->is_aui_screen()){
643 // Don't add wp-admin scripts if not requested to.
644 } else {
645 $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend';
646
647 $bs_ver = $this->settings['bs_ver'] == '5' ? '-v5' : '';
648
649 // select2
650 wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version );
651
652 // flatpickr
653 wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->version );
654
655 // iconpicker
656 if ( defined( 'FAS_ICONPICKER_JS_URL' ) ) {
657 wp_register_script( 'iconpicker', FAS_ICONPICKER_JS_URL, array(), $this->version );
658 }else{
659 wp_register_script( 'iconpicker', $this->url . 'assets/js/fa-iconpicker.min.js', array(), $this->version );
660 }
661
662 // Bootstrap file browser
663 wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version );
664 wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() );
665
666 $load_inline = false;
667
668 // Load select2 only when required.
669 if ( $this->force_load_select2() ) {
670 $dependency = array( 'select2', 'jquery' );
671 } else {
672 $dependency = array( 'jquery' );
673 }
674
675 if ( $this->settings[ $js_setting ] == 'core-popper' ) {
676 // Bootstrap bundle
677 $url = $this->url . 'assets' . $bs_ver . '/js/bootstrap.bundle.min.js';
678 wp_register_script( 'bootstrap-js-bundle', $url, $dependency, $this->version, $this->is_bs3_compat() );
679
680 // If in admin then add to footer for compatibility.
681 is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' );
682
683 $script = $this->inline_script();
684 wp_add_inline_script( 'bootstrap-js-bundle', $script );
685 } elseif ( $this->settings[ $js_setting ] == 'popper' ) {
686 $url = $this->url . 'assets/js/popper.min.js'; // @todo we need to update this to bs5
687 wp_register_script( 'bootstrap-js-popper', $url, $dependency, $this->version );
688 wp_enqueue_script( 'bootstrap-js-popper' );
689 $load_inline = true;
690 } else {
691 $load_inline = true;
692 }
693
694 // Load needed inline scripts by faking the loading of a script if the main script is not being loaded
695 if ( $load_inline ) {
696 wp_register_script( 'bootstrap-dummy', '', $dependency );
697 wp_enqueue_script( 'bootstrap-dummy' );
698
699 $script = $this->inline_script();
700 wp_add_inline_script( 'bootstrap-dummy', $script );
701 }
702 }
703 }
704
705 /**
706 * Enqueue select2 if called.
707 *
708 * @since 0.2.29
709 */
710 public function force_load_select2() {
711 global $aui_select2_enqueued;
712
713 $conditional_select2 = apply_filters( 'aui_is_conditional_select2', true );
714
715 if ( $conditional_select2 !== true ) {
716 return true;
717 }
718
719 $load = is_admin() && ! $aui_select2_enqueued;
720
721 return apply_filters( 'aui_force_load_select2', $load );
722 }
723
724 /**
725 * Enqueue select2 if called.
726 *
727 * @since 0.2.29
728 */
729 public function enqueue_select2() {
730 wp_enqueue_script( 'select2' );
731 }
732
733 /**
734 * Enqueue flatpickr if called.
735 */
736 public function enqueue_flatpickr(){
737 wp_enqueue_style( 'flatpickr' );
738 wp_enqueue_script( 'flatpickr' );
739 }
740
741 /**
742 * Enqueue iconpicker if called.
743 */
744 public function enqueue_iconpicker(){
745 wp_enqueue_style( 'iconpicker' );
746 wp_enqueue_script( 'iconpicker' );
747 }
748
749 /**
750 * Get the url path to the current folder.
751 *
752 * This can be called very early, hence the need for the dynamic way of getting the URL.
753 *
754 * @since 0.2.31 changed to support edge cases like bitnami containers.
755 * @return string
756 */
757 public function get_url() {
758 $content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) );
759 $content_url = untrailingslashit( WP_CONTENT_URL );
760
761 // maybe Replace http:// to https://.
762 if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) {
763 $content_url = str_replace( 'http://', 'https://', $content_url );
764 }
765
766 // First find where in the path our content directory starts
767 $content_basename = basename($content_dir);
768 $file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) );
769
770 // Find the relative path by matching from content directory name
771 $after_content = substr($file_dir, strpos($file_dir, '/' . $content_basename . '/') + strlen('/' . $content_basename . '/'));
772
773 // Build URL using WP_CONTENT_URL and the relative path
774 $url = trailingslashit($content_url) . $after_content;
775
776 // some hosts end up with /wp-content/wp-content/
777 $url = str_replace( '/wp-content/wp-content/', '/wp-content/', $url );
778
779 /**
780 * Filters the URL to the AyeCode UI folder.
781 *
782 * Useful when the folder URL can't be worked out from its path, e.g. a symlinked plugin.
783 *
784 * @since 0.2.54
785 *
786 * @param string $url The AyeCode UI folder URL.
787 * @param string $file_dir The AyeCode UI folder path.
788 */
789 $url = apply_filters( 'ayecode_ui_url', $url, $file_dir );
790
791 return trailingslashit($url);
792 }
793
794 /**
795 * Get the url path to the current folder.
796 * @todo remove
797 * @return string
798 */
799 public function get_url_old() {
800
801 $url = '';
802 // check if we are inside a plugin
803 $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) );
804
805 // add check in-case user has changed wp-content dir name.
806 $wp_content_folder_name = basename(WP_CONTENT_DIR);
807 $dir_parts = explode("/$wp_content_folder_name/",$file_dir);
808 $url_parts = explode("/$wp_content_folder_name/",plugins_url());
809
810 if(!empty($url_parts[0]) && !empty($dir_parts[1])){
811 $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] );
812 }
813
814 return $url;
815 }
816
817 /**
818 * Register the database settings with WordPress.
819 */
820 public function register_settings() {
821 register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' );
822 }
823
824 /**
825 * Add the WordPress settings menu item.
826 * @since 1.0.10 Calling function name direct will fail theme check so we don't.
827 */
828 public function menu_item() {
829 $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
830 call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array(
831 $this,
832 'settings_page'
833 ) );
834 }
835
836 /**
837 * Get a list of themes and their default JS settings.
838 *
839 * @return array
840 */
841 public function theme_js_settings(){
842 return array(
843 'ayetheme' => 'popper',
844 'listimia' => 'required',
845 'listimia_backend' => 'core-popper',
846 //'avada' => 'required', // removed as we now add compatibility
847 );
848 }
849
850 /**
851 * Get the date the site was installed.
852 *
853 * @return false|string
854 */
855 public function get_site_install_date() {
856 global $wpdb; // This gives you access to the WordPress database object
857
858 // Prepare the SQL query to get the oldest registration date
859 $query = "SELECT MIN(user_registered) AS oldest_registration_date FROM {$wpdb->users}";
860
861 // Execute the query
862 $date = $wpdb->get_var( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
863
864 return $date ? $date : false;
865 }
866
867 /**
868 * Show admin notice if backend scripts not loaded.
869 */
870 public function show_admin_version_notice(){
871 $fix_url = admin_url("options-general.php?page=ayecode-ui-settings" );
872 $button = '<a href="'.esc_url($fix_url).'" class="button-primary">View Settings</a>';
873 $message = __( '<b>Style Issue:</b> AyeCode UI has changed its default version from v4 to v5, if you notice unwanted style changes, please revert to v4 (saving the settings page will remove this notice)')." " .$button;
874 echo '<div class="notice notice-error aui-settings-error-notice"><p>'. wp_kses_post( $message ).'</p></div>';
875 }
876
877 /**
878 * Get the current Font Awesome output settings.
879 *
880 * @return array The array of settings.
881 */
882 public function get_settings() {
883 $db_settings = get_option( 'ayecode-ui-settings' );
884
885 // Maybe show default version notice
886 if ( empty( $db_settings ) ) {
887 $site_install_date = new DateTime( self::get_site_install_date() );
888 $switch_over_date = new DateTime( "2024-02-01" );
889
890 if ( $site_install_date < $switch_over_date ) {
891 add_action( 'admin_notices', array( $this, 'show_admin_version_notice' ) );
892 }
893 }
894
895 $js_default = 'core-popper';
896 $js_default_backend = $js_default;
897
898 // maybe set defaults (if no settings set)
899 if(empty($db_settings)){
900 $active_theme = strtolower( get_template() ); // active parent theme.
901 $theme_js_settings = self::theme_js_settings();
902 if(isset($theme_js_settings[$active_theme])){
903 $js_default = $theme_js_settings[$active_theme];
904 $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default;
905 }
906 }
907
908 /**
909 * Filter the default settings.
910 */
911 $defaults = apply_filters( 'ayecode-ui-default-settings', array(
912 'css' => 'compatibility', // core, compatibility
913 'js' => $js_default, // js to load, core-popper, popper
914 'html_font_size' => '16', // js to load, core-popper, popper
915 'css_backend' => 'compatibility', // core, compatibility
916 'js_backend' => $js_default_backend, // js to load, core-popper, popper
917 'disable_admin' => '', // URL snippets to disable loading on admin
918 'bs_ver' => '5', // The default bootstrap version to sue by default
919 ), $db_settings );
920
921 $settings = wp_parse_args( $db_settings, $defaults );
922
923 /**
924 * Filter the Bootstrap settings.
925 *
926 * @todo if we add this filer people might use it and then it defeats the purpose of this class :/
927 */
928 return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults );
929 }
930
931
932 /**
933 * The settings page html output.
934 */
935 public function settings_page() {
936 if ( ! current_user_can( 'manage_options' ) ) {
937 wp_die( esc_attr__( 'You do not have sufficient permissions to access this page.', 'ayecode-connect' ) );
938 }
939 $overrides = apply_filters( 'ayecode-ui-settings', array(), array(), array() );
940
941 ?>
942 <div class="wrap">
943 <h1><?php echo esc_attr( $this->name ); ?></h1>
944 <p><?php echo esc_html( apply_filters( 'ayecode-ui-settings-message', __("Here you can adjust settings if you are having compatibility issues.", 'ayecode-connect' ) ) );?></p>
945 <form method="post" action="options.php">
946 <?php
947 settings_fields( 'ayecode-ui-settings' );
948 do_settings_sections( 'ayecode-ui-settings' );
949 ?>
950
951 <h2><?php esc_html_e( 'BootStrap Version', 'ayecode-connect' ); ?></h2>
952 <p><?php echo esc_html( apply_filters( 'ayecode-ui-version-settings-message', __("V5 is recommended, however if you have another plugin installed using v4, you may need to use v4 also.", 'ayecode-connect' ) ) );?></p>
953 <div class="bsui"><?php
954 if ( ! empty( $overrides ) ) {
955 echo aui()->alert(array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
956 'type'=> 'info',
957 'content'=> esc_attr__("Some options are disabled as your current theme is overriding them.", 'ayecode-connect' )
958 ));
959 }
960 ?>
961 </div>
962 <table class="form-table wpbs-table-version-settings">
963 <tr valign="top">
964 <th scope="row"><label for="wpbs-css"><?php esc_html_e( 'Version', 'ayecode-connect' ); ?></label></th>
965 <td>
966 <select name="ayecode-ui-settings[bs_ver]" id="wpbs-css" <?php echo !empty($overrides['bs_ver']) ? 'disabled' : ''; ?>>
967 <option value="5" <?php selected( $this->settings['bs_ver'], '5' ); ?>><?php esc_html_e( 'v5 (recommended)', 'ayecode-connect' ); ?></option>
968 <option value="4" <?php selected( $this->settings['bs_ver'], '4' ); ?>><?php esc_html_e( 'v4 (legacy)', 'ayecode-connect' ); ?></option>
969 </select>
970 </td>
971 </tr>
972 </table>
973
974 <h2><?php esc_html_e( 'Frontend', 'ayecode-connect' ); ?></h2>
975 <table class="form-table wpbs-table-settings">
976 <tr valign="top">
977 <th scope="row"><label for="wpbs-css"><?php esc_html_e( 'Load CSS', 'ayecode-connect' ); ?></label></th>
978 <td>
979 <select name="ayecode-ui-settings[css]" id="wpbs-css" <?php echo !empty($overrides['css']) ? 'disabled' : ''; ?>>
980 <option value="compatibility" <?php selected( $this->settings['css'], 'compatibility' ); ?>><?php esc_html_e( 'Compatibility Mode (default)', 'ayecode-connect' ); ?></option>
981 <option value="core" <?php selected( $this->settings['css'], 'core' ); ?>><?php esc_html_e( 'Full Mode', 'ayecode-connect' ); ?></option>
982 <option value="" <?php selected( $this->settings['css'], '' ); ?>><?php esc_html_e( 'Disabled', 'ayecode-connect' ); ?></option>
983 </select>
984 </td>
985 </tr>
986
987 <tr valign="top">
988 <th scope="row"><label for="wpbs-js"><?php esc_html_e( 'Load JS', 'ayecode-connect' ); ?></label></th>
989 <td>
990 <select name="ayecode-ui-settings[js]" id="wpbs-js" <?php echo !empty($overrides['js']) ? 'disabled' : ''; ?>>
991 <option value="core-popper" <?php selected( $this->settings['js'], 'core-popper' ); ?>><?php esc_html_e( 'Core + Popper (default)', 'ayecode-connect' ); ?></option>
992 <option value="popper" <?php selected( $this->settings['js'], 'popper' ); ?>><?php esc_html_e( 'Popper', 'ayecode-connect' ); ?></option>
993 <option value="required" <?php selected( $this->settings['js'], 'required' ); ?>><?php esc_html_e( 'Required functions only', 'ayecode-connect' ); ?></option>
994 <option value="" <?php selected( $this->settings['js'], '' ); ?>><?php esc_html_e( 'Disabled (not recommended)', 'ayecode-connect' ); ?></option>
995 </select>
996 </td>
997 </tr>
998
999 <tr valign="top">
1000 <th scope="row"><label for="wpbs-font_size"><?php esc_html_e( 'HTML Font Size (px)', 'ayecode-connect' ); ?></label></th>
1001 <td>
1002 <input type="number" name="ayecode-ui-settings[html_font_size]" id="wpbs-font_size" value="<?php echo absint( $this->settings['html_font_size']); ?>" placeholder="16" <?php echo !empty($overrides['html_font_size']) ? 'disabled' : ''; ?> />
1003 <p class="description" ><?php esc_html_e("Our font sizing is rem (responsive based) here you can set the html font size in-case your theme is setting it too low.", 'ayecode-connect' );?></p>
1004 </td>
1005 </tr>
1006
1007 </table>
1008
1009 <h2><?php esc_html_e( 'Backend', 'ayecode-connect' ); ?> (wp-admin)</h2>
1010 <table class="form-table wpbs-table-settings">
1011 <tr valign="top">
1012 <th scope="row"><label for="wpbs-css-admin"><?php esc_html_e( 'Load CSS', 'ayecode-connect' ); ?></label></th>
1013 <td>
1014 <select name="ayecode-ui-settings[css_backend]" id="wpbs-css-admin" <?php echo !empty($overrides['css_backend']) ? 'disabled' : ''; ?>>
1015 <option value="compatibility" <?php selected( $this->settings['css_backend'], 'compatibility' ); ?>><?php esc_html_e( 'Compatibility Mode (default)', 'ayecode-connect' ); ?></option>
1016 <option value="core" <?php selected( $this->settings['css_backend'], 'core' ); ?>><?php esc_html_e( 'Full Mode (will cause style issues)', 'ayecode-connect' ); ?></option>
1017 <option value="" <?php selected( $this->settings['css_backend'], '' ); ?>><?php esc_html_e( 'Disabled', 'ayecode-connect' ); ?></option>
1018 </select>
1019 </td>
1020 </tr>
1021
1022 <tr valign="top">
1023 <th scope="row"><label for="wpbs-js-admin"><?php esc_html_e( 'Load JS', 'ayecode-connect' ); ?></label></th>
1024 <td>
1025 <select name="ayecode-ui-settings[js_backend]" id="wpbs-js-admin" <?php echo !empty($overrides['js_backend']) ? 'disabled' : ''; ?>>
1026 <option value="core-popper" <?php selected( $this->settings['js_backend'], 'core-popper' ); ?>><?php esc_html_e( 'Core + Popper (default)', 'ayecode-connect' ); ?></option>
1027 <option value="popper" <?php selected( $this->settings['js_backend'], 'popper' ); ?>><?php esc_html_e( 'Popper', 'ayecode-connect' ); ?></option>
1028 <option value="required" <?php selected( $this->settings['js_backend'], 'required' ); ?>><?php esc_html_e( 'Required functions only', 'ayecode-connect' ); ?></option>
1029 <option value="" <?php selected( $this->settings['js_backend'], '' ); ?>><?php esc_html_e( 'Disabled (not recommended)', 'ayecode-connect' ); ?></option>
1030 </select>
1031 </td>
1032 </tr>
1033
1034 <tr valign="top">
1035 <th scope="row"><label for="wpbs-disable-admin"><?php esc_html_e( 'Disable load on URL', 'ayecode-connect' ); ?></label></th>
1036 <td>
1037 <p><?php esc_html_e( 'If you have backend conflict you can enter a partial URL argument that will disable the loading of AUI on those pages. Add each argument on a new line.', 'ayecode-connect' ); ?></p>
1038 <textarea name="ayecode-ui-settings[disable_admin]" rows="10" cols="50" id="wpbs-disable-admin" class="large-text code" spellcheck="false" placeholder="myplugin.php &#10;action=go"><?php echo esc_textarea( $this->settings['disable_admin'] );?></textarea>
1039 </td>
1040 </tr>
1041 </table>
1042
1043 <?php
1044 submit_button();
1045 ?>
1046 </form>
1047 <div id="wpbs-version" data-aui-source="<?php echo esc_attr( $this->get_load_source() ); ?>"><?php echo esc_html( $this->version ); ?></div>
1048 </div>
1049 <?php
1050 }
1051
1052 public function get_load_source(){
1053 $file = str_replace( array( "/", "\\" ), "/", realpath( __FILE__ ) );
1054 $plugins_dir = str_replace( array( "/", "\\" ), "/", realpath( WP_PLUGIN_DIR ) );
1055
1056 // Find source plugin/theme of SD
1057 $source = array();
1058 if ( strpos( $file, $plugins_dir ) !== false ) {
1059 $source = explode( "/", plugin_basename( $file ) );
1060 } else if ( function_exists( 'get_theme_root' ) ) {
1061 $themes_dir = str_replace( array( "/", "\\" ), "/", realpath( get_theme_root() ) );
1062
1063 if ( strpos( $file, $themes_dir ) !== false ) {
1064 $source = explode( "/", ltrim( str_replace( $themes_dir, "", $file ), "/" ) );
1065 }
1066 }
1067
1068 return isset($source[0]) ? esc_attr($source[0]) : '';
1069 }
1070
1071 public function customizer_settings($wp_customize){
1072 $wp_customize->add_section('aui_settings', array(
1073 'title' => __('AyeCode UI', 'ayecode-connect' ),
1074 'priority' => 120,
1075 ));
1076
1077 // =============================
1078 // = Color Picker =
1079 // =============================
1080 $wp_customize->add_setting('aui_options[color_primary]', array(
1081 'default' => AUI_PRIMARY_COLOR,
1082 'sanitize_callback' => 'sanitize_hex_color',
1083 'capability' => 'edit_theme_options',
1084 'type' => 'option',
1085 'transport' => 'refresh',
1086 ));
1087 $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array(
1088 'label' => __('Primary Color', 'ayecode-connect' ),
1089 'section' => 'aui_settings',
1090 'settings' => 'aui_options[color_primary]',
1091 )));
1092
1093 $wp_customize->add_setting('aui_options[color_secondary]', array(
1094 'default' => '#6c757d',
1095 'sanitize_callback' => 'sanitize_hex_color',
1096 'capability' => 'edit_theme_options',
1097 'type' => 'option',
1098 'transport' => 'refresh',
1099 ));
1100 $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array(
1101 'label' => __('Secondary Color', 'ayecode-connect' ),
1102 'section' => 'aui_settings',
1103 'settings' => 'aui_options[color_secondary]',
1104 )));
1105 }
1106
1107 /**
1108 * CSS to help with conflict issues with other plugins and themes using bootstrap v3.
1109 *
1110 * @return mixed
1111 */
1112 public static function bs3_compat_css() {
1113 ob_start();
1114 ?>
1115 <style>
1116 /* Bootstrap 3 compatibility */
1117 body.modal-open .modal-backdrop.show:not(.in) {opacity:0.5;}
1118 body.modal-open .modal.show:not(.in) {opacity:1;z-index: 99999}
1119 body.modal-open .modal.show:not(.in) .modal-content {box-shadow: none;}
1120 body.modal-open .modal.show:not(.in) .modal-dialog {transform: initial;}
1121
1122 body.modal-open .modal.bsui .modal-dialog{left: auto;}
1123
1124 .collapse.show:not(.in){display: inherit;}
1125 .fade.show{opacity: 1;}
1126
1127 <?php if( defined( 'SVQ_THEME_VERSION' ) ){ ?>
1128 /* KLEO theme specific */
1129 .kleo-main-header .navbar-collapse.collapse.show:not(.in){display: block !important;}
1130 <?php } ?>
1131
1132 <?php if( defined( 'FUSION_BUILDER_VERSION' ) ){ ?>
1133 /* With Avada builder */
1134 body.modal-open .modal.in {opacity:1;z-index: 99999}
1135 body.modal-open .modal.bsui.in .modal-content {box-shadow: none;}
1136 .bsui .collapse.in{display: inherit;}
1137 .bsui .collapse.in.row.show{display: flex;}
1138 .bsui .collapse.in.row:not(.show){display: none;}
1139
1140 <?php } ?>
1141 </style>
1142 <?php
1143 return str_replace( array(
1144 '<style>',
1145 '</style>'
1146 ), '', self::minify_css( ob_get_clean() ) );
1147 }
1148
1149 public static function custom_css( $compatibility = true, $is_fse = false ) {
1150 global $aui_bs5;
1151
1152 $colors = array();
1153
1154 if ( defined( 'BLOCKSTRAP_VERSION' ) ) {
1155 $setting = wp_get_global_settings();
1156
1157 if ( ! empty( $setting['color']['palette']['theme'] ) ) {
1158 foreach ( $setting['color']['palette']['theme'] as $color ) {
1159 $colors[$color['slug']] = esc_attr( $color['color'] );
1160 }
1161 }
1162
1163 if ( ! empty( $setting['color']['palette']['custom'] ) ) {
1164 foreach ( $setting['color']['palette']['custom'] as $color ) {
1165 $colors[$color['slug']] = esc_attr( $color['color'] );
1166 }
1167 }
1168 } else {
1169 $settings = get_option( 'aui_options' );
1170
1171 $colors = array(
1172 'primary' => ! empty( $settings['color_primary'] ) ? $settings['color_primary'] : AUI_PRIMARY_COLOR,
1173 'secondary' => ! empty( $settings['color_secondary'] ) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR
1174 );
1175 }
1176
1177 ob_start();
1178 ?><style><?php
1179 // BS v3 compat
1180 if( self::is_bs3_compat() ){
1181 echo self::bs3_compat_css(); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1182 }
1183
1184 //$is_fse = false;
1185 //if ( is_admin() && ( !empty($_REQUEST['postType']) || self::is_block_editor() ) && ( defined( 'BLOCKSTRAP_VERSION' ) || defined( 'AUI_FSE' ) ) ) {
1186 //$is_fse = true;
1187 //}
1188
1189 $custom_front = ! is_admin() ? true : apply_filters('ayecode_ui_custom_front', false );
1190 $custom_admin = $is_fse || self::is_preview() ? true : apply_filters('ayecode_ui_custom_admin', false );
1191 $bs_custom_css = apply_filters( 'ayecode_ui_bs_custom_css', $custom_admin || $custom_front );
1192 //$bs_custom_css = true; // Force true to fix any color issue.
1193
1194 $colors_css = '';
1195 if ( ! empty( $colors ) && $bs_custom_css ) {
1196 $d_colors = self::get_colors(true);
1197
1198 foreach ( $colors as $key => $color ) {
1199 if ( ( empty( $d_colors[$key]) || $d_colors[$key] != $color) || $is_fse ) {
1200 $var = $is_fse ? "var(--wp--preset--color--$key)" : $color;
1201 $compat = $is_fse ? '.editor-styles-wrapper' : $compatibility;
1202
1203 $colors_css .= $aui_bs5 ? self::css_overwrite_bs5( $key,$var, $compat, $color ) : self::css_overwrite( $key, $var, $compat, $color );
1204 }
1205 }
1206 }
1207
1208 if ( $colors_css ) {
1209 echo $colors_css; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1210 }
1211
1212 // Set admin bar z-index lower when modal is open.
1213 echo ' body.modal-open #wpadminbar{z-index:999}.embed-responsive-16by9 .fluid-width-video-wrapper{padding:0 !important;position:initial}';
1214
1215 if ( is_admin() ) {
1216 echo ' body.modal-open #adminmenuwrap{z-index:999} body.modal-open #wpadminbar{z-index:1025}';
1217 }
1218
1219 /* Prevent the backdrop from covering the modal inside a sticky element */
1220 echo 'body.modal-open .sticky:has(.modal),body.modal-open .sticky-top:has(.modal){position:static!important}';
1221
1222 $custom_css = '';
1223
1224 if ( $aui_bs5 && defined( 'BLOCKSTRAP_VERSION' ) && $bs_custom_css ) {
1225 $css = '';
1226 $theme_settings = wp_get_global_styles();
1227
1228 // Font face
1229 if( !empty( $theme_settings['typography']['fontFamily'] ) ){
1230 $t_fontface = str_replace( array('var:preset|','font-family|'), array('--wp--preset--','font-family--'), $theme_settings['typography']['fontFamily'] ); //var(--wp--preset--font-family--poppins)
1231 $css .= '--bs-body-font-family: ' . esc_attr($t_fontface) . ';';
1232 }
1233
1234 // font size
1235 if( !empty( $theme_settings['typography']['fontSize'] ) ){
1236 $css .= '--bs-body-font-size: ' . esc_attr( $theme_settings['typography']['fontSize'] ) . ' ;';
1237 }
1238
1239 // line height
1240 if( !empty( $theme_settings['typography']['lineHeight'] ) ){
1241 $css .= '--bs-body-line-height: ' . esc_attr( $theme_settings['typography']['lineHeight'] ) . ';';
1242 }
1243
1244
1245 // font weight
1246 if( !empty( $theme_settings['typography']['fontWeight'] ) ){
1247 $css .= '--bs-body-font-weight: ' . esc_attr( $theme_settings['typography']['fontWeight'] ) . ';';
1248 }
1249
1250 // Background
1251 if( !empty( $theme_settings['color']['background'] ) ){
1252 $css .= '--bs-body-bg: ' . esc_attr( $theme_settings['color']['background'] ) . ';';
1253 }
1254
1255 // Background Gradient
1256 if( !empty( $theme_settings['color']['gradient'] ) ){
1257 $css .= 'background: ' . esc_attr( $theme_settings['color']['gradient'] ) . ';';
1258 }
1259
1260 // Background Gradient
1261 if( !empty( $theme_settings['color']['gradient'] ) ){
1262 $css .= 'background: ' . esc_attr( $theme_settings['color']['gradient'] ) . ';';
1263 }
1264
1265 // text color
1266 if( !empty( $theme_settings['color']['text'] ) ){
1267 $css .= '--bs-body-color: ' . esc_attr( $theme_settings['color']['text'] ) . ';';
1268 }
1269
1270
1271 // link colors
1272 if( !empty( $theme_settings['elements']['link']['color']['text'] ) ){
1273 $css .= '--bs-link-color: ' . esc_attr( $theme_settings['elements']['link']['color']['text'] ) . ';';
1274 }
1275 if( !empty( $theme_settings['elements']['link'][':hover']['color']['text'] ) ){
1276 $css .= '--bs-link-hover-color: ' . esc_attr( $theme_settings['elements']['link'][':hover']['color']['text'] ) . ';';
1277 }
1278
1279 if($css){
1280 $custom_css .= $is_fse ? 'body.editor-styles-wrapper{' . esc_attr( $css ) . '}' : 'body{' . esc_attr( $css ) . '}';
1281 }
1282
1283 $bep = $is_fse ? 'body.editor-styles-wrapper ' : '';
1284
1285 // Headings
1286 $headings_css = '';
1287 if( !empty( $theme_settings['elements']['heading']['color']['text'] ) ){
1288 $headings_css .= "color: " . esc_attr( $theme_settings['elements']['heading']['color']['text'] ) . ";";
1289 }
1290
1291 // heading background
1292 if( !empty( $theme_settings['elements']['heading']['color']['background'] ) ){
1293 $headings_css .= 'background: ' . esc_attr( $theme_settings['elements']['heading']['color']['background'] ) . ';';
1294 }
1295
1296 // heading font family
1297 if( !empty( $theme_settings['elements']['heading']['typography']['fontFamily'] ) ){
1298 $headings_css .= 'font-family: ' . esc_attr( $theme_settings['elements']['heading']['typography']['fontFamily'] ) . ';';
1299 }
1300
1301 if( $headings_css ){
1302 $custom_css .= "$bep h1,$bep h2,$bep h3, $bep h4,$bep h5,$bep h6{ " . esc_attr( $headings_css ) . "}";
1303 }
1304
1305 $hs = array('h1','h2','h3','h4','h5','h6');
1306
1307 foreach($hs as $hn){
1308 $h_css = '';
1309 if( !empty( $theme_settings['elements'][$hn]['color']['text'] ) ){
1310 $h_css .= 'color: ' . esc_attr( $theme_settings['elements'][$hn]['color']['text'] ) . ';';
1311 }
1312
1313 if( !empty( $theme_settings['elements'][$hn]['typography']['fontSize'] ) ){
1314 $h_css .= 'font-size: ' . esc_attr( $theme_settings['elements'][$hn]['typography']['fontSize'] ) . ';';
1315 }
1316
1317 if( !empty( $theme_settings['elements'][$hn]['typography']['fontFamily'] ) ){
1318 $h_css .= 'font-family: ' . esc_attr( $theme_settings['elements'][$hn]['typography']['fontFamily'] ) . ';';
1319 }
1320
1321 if($h_css){
1322 $custom_css .= esc_attr( $bep . $hn ) . '{'.esc_attr( $h_css ).'}';
1323 }
1324 }
1325 }
1326
1327 if ( $custom_css ) {
1328 echo $custom_css; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1329 }
1330
1331 // Pagination on Hello Elementor theme.
1332 if ( function_exists( 'hello_elementor_setup' ) ) {
1333 echo '.aui-nav-links .pagination{justify-content:inherit}';
1334 }
1335
1336 // Astra theme - when woocommerce active they add compatibility CSS which breaks select2 in modals
1337 if( defined('ASTRA_THEME_VERSION')){
1338 echo '.woocommerce-js.modal-open .select2-container .select2-dropdown, .woocommerce-js.modal-open .select2-container .select2-search__field, .woocommerce-page.modal-open .select2-container .select2-dropdown, .woocommerce-page.modal-open .select2-container .select2-search__field{z-index: 1056;}';
1339 }
1340
1341 ?></style><?php
1342 $custom_css = ob_get_clean();
1343
1344 /*
1345 * We only add the <script> tags for code highlighting, so we strip them from the output.
1346 */
1347 return str_replace( array(
1348 '<style>',
1349 '</style>'
1350 ), '', self::minify_css( $custom_css ) );
1351 }
1352
1353 /**
1354 * Check if we should add booststrap 3 compatibility changes.
1355 *
1356 * @return bool
1357 */
1358 public static function is_bs3_compat(){
1359 return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION');
1360 }
1361
1362 public static function hex_to_rgb( $hex ) {
1363 $hex = trim( (string) $hex );
1364
1365 // CSS variables can't be resolved to RGB server side.
1366 if ( $hex === '' || strpos( $hex, 'var(' ) !== false ) {
1367 return '';
1368 }
1369
1370 // Remove '#' if present
1371 $hex = str_replace( '#', '', $hex );
1372
1373 // Check if input is RGB
1374 if ( strpos( $hex, 'rgba(' ) === 0 || strpos( $hex, 'rgb(' ) === 0 ) {
1375 $_rgb = explode( ',', str_replace( array( 'rgba(', 'rgb(', ')' ), '', $hex ) );
1376
1377 $rgb = ( isset( $_rgb[0] ) ? (int) trim( $_rgb[0] ) : '0' ) . ',';
1378 $rgb .= ( isset( $_rgb[1] ) ? (int) trim( $_rgb[1] ) : '0' ) . ',';
1379 $rgb .= ( isset( $_rgb[2] ) ? (int) trim( $_rgb[2] ) : '0' );
1380
1381 return $rgb;
1382 }
1383
1384 // Only 3, 4, 6 or 8 digit hex can be converted, anything else (named colours, hsl() etc.) would give a wrong value.
1385 if ( ! preg_match( '/^([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i', $hex ) ) {
1386 return '';
1387 }
1388
1389 // Convert 3 or 4 digit hex to 6-digit hex (alpha is ignored)
1390 if ( strlen( $hex ) <= 4 ) {
1391 $hex = str_repeat( substr( $hex, 0, 1 ), 2 ) . str_repeat( substr( $hex, 1, 1 ), 2 ) . str_repeat( substr( $hex, 2, 1 ), 2 );
1392 }
1393
1394 // Convert hex to RGB
1395 $r = hexdec( substr( $hex, 0, 2 ) );
1396 $g = hexdec( substr( $hex, 2, 2 ) );
1397 $b = hexdec( substr( $hex, 4, 2 ) );
1398
1399 // Return RGB values as an array
1400 return $r . ',' . $g . ',' . $b;
1401 }
1402
1403 /**
1404 * Replace --bs-{type}-rgb usages when the color has no RGB value (eg a CSS variable).
1405 *
1406 * rgba(var(--bs-{type}-rgb), .5) would be invalid without the -rgb variable, so use color-mix() on the color itself.
1407 *
1408 * @param string $css The generated CSS.
1409 * @param string $type The color slug.
1410 * @param string $color_code The color value.
1411 *
1412 * @return string
1413 */
1414 public static function css_rgb_fallback( $css, $type, $color_code ) {
1415 $type = preg_quote( $type, '/' );
1416
1417 // A comma triplet is required here, so leave the value from the stylesheet in place.
1418 $css = preg_replace( '/--bs-btn-focus-shadow-rgb:\s*var\(--bs-' . $type . '-rgb\);/', '', $css );
1419
1420 return preg_replace_callback( '/rgba?\(\s*var\(--bs-' . $type . '-rgb\)\s*(?:,\s*([0-9]*\.?[0-9]+)\s*)?\)/', function( $m ) use ( $color_code ) {
1421 if ( ! isset( $m[1] ) || (float) $m[1] >= 1 ) {
1422 return $color_code;
1423 }
1424
1425 return 'color-mix(in srgb, ' . $color_code . ' ' . round( (float) $m[1] * 100, 2 ) . '%, transparent)';
1426 }, $css );
1427 }
1428
1429 /**
1430 * Build the CSS to overwrite a bootstrap color variable.
1431 *
1432 * @param $type
1433 * @param $color_code
1434 * @param $compatibility
1435 *
1436 * @return string
1437 */
1438 public static function css_overwrite_bs5($type,$color_code,$compatibility, $hex = '' ){
1439 global $aui_bs5;
1440
1441 $is_var = false;
1442 $is_custom = strpos($type, 'custom-') !== false ? true : false;
1443 if(!$color_code){return '';}
1444 if(strpos($color_code, 'var') !== false){
1445 //if(!sanitize_hex_color($color_code)){
1446 $color_code = esc_attr($color_code);
1447 $is_var = true;
1448 // $color_code = "rgba($color_code, 0.5)";
1449 // echo '###1'.$color_code.'###';//exit;
1450 }
1451
1452 // echo '@@@'.$color_code.'==='.self::hex_to_rgb($color_code);exit;
1453
1454 if(!$color_code){return '';}
1455
1456 $rgb = self::hex_to_rgb($hex);
1457
1458 if($compatibility===true || $compatibility===1){
1459 $compatibility = '.bsui';
1460 }elseif(!$compatibility){
1461 $compatibility = '';
1462 }else{
1463 $compatibility = esc_attr($compatibility);
1464 }
1465
1466 $prefix = $compatibility ? $compatibility . " " : "";
1467
1468
1469 $output = '';
1470
1471 // echo '####'.$color_code;exit;
1472
1473 $type = sanitize_html_class($type);
1474
1475 /**
1476 * c = color, b = background color, o = border-color, f = fill
1477 */
1478 $selectors = array(
1479 ".btn-{$type}" => array( 'b', 'o' ),
1480 ".btn-{$type}.disabled" => array( 'b', 'o' ),
1481 ".btn-{$type}:disabled" => array( 'b', 'o' ),
1482 ".btn-outline-{$type}" => array( 'c', 'o' ),
1483 ".btn-outline-{$type}:hover" => array( 'b', 'o' ),
1484 ".btn-outline-{$type}:not(:disabled):not(.disabled).active" => array( 'b', 'o' ),
1485 ".btn-outline-{$type}:not(:disabled):not(.disabled):active" => array( 'b', 'o' ),
1486 ".show>.btn-outline-{$type}.dropdown-toggle" => array( 'b', 'o' ),
1487 ".badge-{$type}" => array( 'b' ),
1488 ".alert-{$type}" => array( 'b', 'o' ),
1489 ".bg-{$type}" => array( 'b', 'f' ),
1490 ".btn-link.btn-{$type}" => array( 'c' ),
1491 ".text-{$type}" => array( 'c' ),
1492 );
1493
1494 if ( $aui_bs5 ) {
1495 unset($selectors[".alert-{$type}" ]);
1496 }
1497
1498 if ( $type == 'primary' ) {
1499 $selectors = $selectors + array(
1500 'a' => array( 'c' ),
1501 '.btn-link' => array( 'c' ),
1502 '.dropdown-item.active' => array( 'b' ),
1503 '.custom-control-input:checked~.custom-control-label::before' => array(
1504 'b',
1505 'o'
1506 ),
1507 '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array(
1508 'b',
1509 'o'
1510 ),
1511 '.nav-pills .nav-link.active' => array( 'b' ),
1512 '.nav-pills .show>.nav-link' => array( 'b' ),
1513 '.page-link' => array( 'c' ),
1514 '.page-item.active .page-link' => array(
1515 'b',
1516 'o'
1517 ),
1518 '.progress-bar' => array( 'b' ),
1519 '.list-group-item.active' => array(
1520 'b',
1521 'o'
1522 ),
1523 '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array( 'b' ),
1524 );
1525 }
1526
1527
1528
1529 // link
1530 if ( $type === 'primary' ) {
1531 $output .= 'html body {--bs-link-hover-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .75); --bs-link-color: var(--bs-'.esc_attr($type).'); }';
1532 $output .= $prefix . ' .breadcrumb{--bs-breadcrumb-item-active-color: '.esc_attr($color_code).'; }';
1533 $output .= $prefix . ' .navbar { --bs-nav-link-hover-color: '.esc_attr($color_code).'; --bs-navbar-hover-color: '.esc_attr($color_code).'; --bs-navbar-active-color: '.esc_attr($color_code).'; }';
1534
1535 $output .= $prefix . ' a{color: var(--bs-'.esc_attr($type).');}';
1536 $output .= $prefix . ' .text-primary{color: var(--bs-'.esc_attr($type).') !important;}';
1537
1538 // dropdown
1539 $output .= $prefix . ' .dropdown-menu{--bs-dropdown-link-hover-color: var(--bs-'.esc_attr($type).'); --bs-dropdown-link-active-color: var(--bs-'.esc_attr($type).');}';
1540
1541 // pagination
1542 $output .= $prefix . ' .pagination{--bs-pagination-hover-color: var(--bs-'.esc_attr($type).'); --bs-pagination-active-bg: var(--bs-'.esc_attr($type).');}';
1543
1544 } else if ( $aui_bs5 ) {
1545 $output .= $prefix . ' .text-' . sanitize_key( $type ) . '{color: var(--bs-' . sanitize_key( $type ) . ') !important;}';
1546 }
1547
1548 $output .= $prefix . ' .link-'.esc_attr($type).' {color: var(--bs-'.esc_attr($type).') !important;}';
1549 $output .= $prefix . ' .link-'.esc_attr($type).':hover {color: rgba(var(--bs-'.esc_attr($type).'-rgb), .8) !important;}';
1550
1551 // buttons
1552 $output .= $prefix . ' .btn-'.esc_attr($type).'{';
1553 $output .= '
1554 --bs-btn-bg: '.esc_attr($color_code).';
1555 --bs-btn-border-color: '.esc_attr($color_code).';
1556 --bs-btn-hover-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1557 --bs-btn-hover-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1558 --bs-btn-focus-shadow-rgb: var(--bs-'.esc_attr($type).'-rgb);
1559 --bs-btn-active-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1560 --bs-btn-active-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1561 --bs-btn-active-shadow: unset;
1562 --bs-btn-disabled-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .5);
1563 --bs-btn-disabled-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .1);
1564 ';
1565 // $output .= '
1566 // --bs-btn-color: #fff;
1567 // --bs-btn-hover-color: #fff;
1568 // --bs-btn-active-color: #fff;
1569 // --bs-btn-disabled-color: #fff;
1570 // ';
1571 $output .= '}';
1572
1573 // buttons outline
1574 $output .= $prefix . ' .btn-outline-'.esc_attr($type).'{';
1575 $output .= '
1576 --bs-btn-color: '.esc_attr($color_code).';
1577 --bs-btn-border-color: '.esc_attr($color_code).';
1578 --bs-btn-hover-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1579 --bs-btn-hover-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1580 --bs-btn-focus-shadow-rgb: var(--bs-'.esc_attr($type).'-rgb);
1581 --bs-btn-active-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1582 --bs-btn-active-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1583 --bs-btn-active-shadow: unset;
1584 --bs-btn-disabled-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .5);
1585 --bs-btn-disabled-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .1);
1586 ';
1587 // $output .= '
1588 // --bs-btn-color: #fff;
1589 // --bs-btn-hover-color: #fff;
1590 // --bs-btn-active-color: #fff;
1591 // --bs-btn-disabled-color: #fff;
1592 // ';
1593 $output .= '}';
1594
1595 // button hover
1596 $output .= $prefix . ' .btn-'.esc_attr($type).':hover{';
1597 $output .= '
1598 box-shadow: 0 0.25rem 0.25rem 0.125rem rgb(var(--bs-'.esc_attr($type).'-rgb), .1), 0 0.375rem 0.75rem -0.125rem rgb(var(--bs-'.esc_attr($type).'-rgb) , .4);
1599 }
1600 ';
1601
1602 if ( $aui_bs5 ) {
1603 // translucent primary
1604 if ( $type == 'primary' ) {
1605 $output .= $prefix . ' .btn-translucent-primary{color:rgb(var(--bs-primary-rgb));}';
1606 $output .= $prefix . ' .btn-translucent-primary:hover,' . $prefix . ' .btn-translucent-primary:focus,' . $prefix . ' .btn-translucent-primary.focus{background-color: rgb(var(--bs-primary-rgb));}';
1607 }
1608
1609 // $output .= $is_var ? 'html body {--bs-'.esc_attr($type).'-rgb: '.$color_code.'; }' : 'html body {--bs-'.esc_attr($type).'-rgb: '.self::hex_to_rgb($color_code).'; }';
1610 $output .= 'html body {--bs-'.esc_attr($type).': '.esc_attr($color_code).'; }';
1611
1612 if ( $rgb !== '' ) {
1613 $output .= 'html body {--bs-' . esc_attr( $type ) . '-rgb: ' . $rgb . '; }';
1614 }
1615 }
1616
1617 if ( $is_custom ) {
1618 // build rules into each type
1619 foreach($selectors as $selector => $types){
1620 $selector = $compatibility ? $compatibility . " ".$selector : $selector;
1621 $types = array_combine($types,$types);
1622 if(isset($types['c'])){$color[] = $selector;}
1623 if(isset($types['b'])){$background[] = $selector;}
1624 if(isset($types['o'])){$border[] = $selector;}
1625 if(isset($types['f'])){$fill[] = $selector;}
1626 }
1627
1628 // // build rules into each type
1629 // foreach($important_selectors as $selector => $types){
1630 // $selector = $compatibility ? $compatibility . " ".$selector : $selector;
1631 // $types = array_combine($types,$types);
1632 // if(isset($types['c'])){$color_i[] = $selector;}
1633 // if(isset($types['b'])){$background_i[] = $selector;}
1634 // if(isset($types['o'])){$border_i[] = $selector;}
1635 // if(isset($types['f'])){$fill_i[] = $selector;}
1636 // }
1637
1638 // add any color rules
1639 if(!empty($color)){
1640 $output .= implode(",",$color) . "{color: $color_code;} ";
1641 }
1642 if(!empty($color_i)){
1643 $output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1644 }
1645
1646 // add any background color rules
1647 if(!empty($background)){
1648 $output .= implode(",",$background) . "{background-color: $color_code;} ";
1649 }
1650 if(!empty($background_i)){
1651 $output .= $aui_bs5 ? '' : implode(",",$background_i) . "{background-color: $color_code !important;} ";
1652 // $output .= implode(",",$background_i) . "{background-color: rgba(var(--bs-primary-rgb), var(--bs-bg-opacity)) !important;} ";
1653 }
1654
1655 // add any border color rules
1656 if(!empty($border)){
1657 $output .= implode(",",$border) . "{border-color: $color_code;} ";
1658 }
1659 if(!empty($border_i)){
1660 $output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1661 }
1662
1663 // add any fill color rules
1664 if(!empty($fill)){
1665 $output .= implode(",",$fill) . "{fill: $color_code;} ";
1666 }
1667 if(!empty($fill_i)){
1668 $output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1669 }
1670
1671 }
1672
1673
1674
1675
1676 $transition = $is_var ? 'transition: color 0.15s ease-in-out,background-color 0.15s ease-in-out,border-color 0.15s ease-in-out,box-shadow 0.15s ease-in-out,filter 0.15s ease-in-out;' : '';
1677 // darken
1678 $darker_075 = $is_var ? $color_code.';filter:brightness(0.925)' : self::css_hex_lighten_darken($color_code,"-0.075");
1679 $darker_10 = $is_var ? $color_code.';filter:brightness(0.9)' : self::css_hex_lighten_darken($color_code,"-0.10");
1680 $darker_125 = $is_var ? $color_code.';filter:brightness(0.875)' : self::css_hex_lighten_darken($color_code,"-0.125");
1681 $darker_40 = $is_var ? $color_code.';filter:brightness(0.6)' : self::css_hex_lighten_darken($color_code,"-0.4");
1682
1683 // lighten
1684 $lighten_25 = $is_var ? $color_code.';filter:brightness(1.25)' :self::css_hex_lighten_darken($color_code,"0.25");
1685
1686 // opacity see https://css-tricks.com/8-digit-hex-codes/
1687 $op_25 = $color_code."40"; // 25% opacity
1688
1689
1690 // button states
1691 $output .= $is_var ? $prefix ." .btn-{$type}{{$transition }} " : '';
1692 $output .= $prefix ." .btn-{$type}:hover, $prefix .btn-{$type}:focus, $prefix .btn-{$type}.focus{background-color: ".$darker_075."; border-color: ".$darker_10.";} ";
1693 // $output .= $prefix ." .btn-{$type}:hover, $prefix .btn-{$type}:focus, $prefix .btn-{$type}.focus{background-color: #000; border-color: #000;} ";
1694 $output .= $prefix ." .btn-outline-{$type}:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-{$type}:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-{$type}.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1695 $output .= $prefix ." .btn-{$type}:not(:disabled):not(.disabled):active, $prefix .btn-{$type}:not(:disabled):not(.disabled).active, .show>$prefix .btn-{$type}.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} ";
1696 $output .= $prefix ." .btn-{$type}:not(:disabled):not(.disabled):active:focus, $prefix .btn-{$type}:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-{$type}.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1697 $output .= $prefix ." .btn-{$type}:not(:disabled):not(.disabled):active:focus, $prefix .btn-{$type}:not(:disabled):not(.disabled):focus {box-shadow: 0 0.25rem 0.25rem 0.125rem rgba(var(--bs-{$type}-rgb), 0.1), 0 0.375rem 0.75rem -0.125rem rgba(var(--bs-{$type}-rgb), 0.4);} ";
1698
1699 // text
1700 // $output .= $prefix .".xxx, .text-{$type} {color: var(--bs-".esc_attr($type).");} ";
1701
1702
1703 // if ( $type == 'primary' ) {
1704 // // dropdown's
1705 // $output .= $prefix . " .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
1706 //
1707 // // input states
1708 // $output .= $prefix . " .form-control:focus{border-color: " . $lighten_25 . ";box-shadow: 0 0 0 0.2rem $op_25;} ";
1709 //
1710 // // page link
1711 // $output .= $prefix . " .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1712 // }
1713
1714 // alerts
1715 if ( $aui_bs5 ) {
1716 // $output .= $is_var ? '' : $prefix ." .alert-{$type} {background-color: ".$color_code."20; border-color: ".$color_code."30;color:$darker_40} ";
1717 $output .= $prefix ." .alert-{$type} {--bs-alert-bg: rgba(var(--bs-{$type}-rgb), .1 ) !important;--bs-alert-border-color: rgba(var(--bs-{$type}-rgb), .25 ) !important;--bs-alert-color: rgba(var(--bs-{$type}-rgb), 1 ) !important;} ";
1718 }
1719
1720 if ( $rgb === '' ) {
1721 // The stylesheet builds these from --bs-{type}-rgb, which is not set for this color.
1722 if ( $aui_bs5 ) {
1723 $output .= $prefix . " .bg-{$type}{background-color: color-mix(in srgb, $color_code calc(var(--bs-bg-opacity, 1) * 100%), transparent) !important;} ";
1724 $output .= $prefix . " .border-{$type}{border-color: color-mix(in srgb, $color_code calc(var(--bs-border-opacity, 1) * 100%), transparent) !important;} ";
1725 }
1726
1727 $output = self::css_rgb_fallback( $output, $type, $color_code );
1728 }
1729
1730 return $output;
1731 }
1732
1733 /**
1734 * Build the CSS to overwrite a bootstrap color variable.
1735 *
1736 * @param $type
1737 * @param $color_code
1738 * @param $compatibility
1739 *
1740 * @return string
1741 */
1742 public static function css_overwrite($type,$color_code,$compatibility, $hex = '' ){
1743 global $aui_bs5;
1744
1745 $is_var = false;
1746 if(!$color_code){return '';}
1747 if(strpos($color_code, 'var') !== false){
1748 //if(!sanitize_hex_color($color_code)){
1749 $color_code = esc_attr($color_code);
1750 $is_var = true;
1751 // $color_code = "rgba($color_code, 0.5)";
1752 // echo '###1'.$color_code.'###';//exit;
1753 }
1754
1755 // echo '@@@'.$color_code.'==='.self::hex_to_rgb($color_code);exit;
1756
1757 if(!$color_code){return '';}
1758
1759 $rgb = self::hex_to_rgb($hex);
1760
1761 if($compatibility===true || $compatibility===1){
1762 $compatibility = '.bsui';
1763 }elseif(!$compatibility){
1764 $compatibility = '';
1765 }else{
1766 $compatibility = esc_attr($compatibility);
1767 }
1768
1769
1770
1771 // echo '####'.$color_code;exit;
1772
1773 $type = sanitize_html_class($type);
1774
1775 /**
1776 * c = color, b = background color, o = border-color, f = fill
1777 */
1778 $selectors = array(
1779 ".btn-{$type}" => array( 'b', 'o' ),
1780 ".btn-{$type}.disabled" => array( 'b', 'o' ),
1781 ".btn-{$type}:disabled" => array( 'b', 'o' ),
1782 ".btn-outline-{$type}" => array( 'c', 'o' ),
1783 ".btn-outline-{$type}:hover" => array( 'b', 'o' ),
1784 ".btn-outline-{$type}:not(:disabled):not(.disabled).active" => array( 'b', 'o' ),
1785 ".btn-outline-{$type}:not(:disabled):not(.disabled):active" => array( 'b', 'o' ),
1786 ".show>.btn-outline-{$type}.dropdown-toggle" => array( 'b', 'o' ),
1787 ".badge-{$type}" => array( 'b' ),
1788 ".alert-{$type}" => array( 'b', 'o' ),
1789 ".bg-{$type}" => array( 'b', 'f' ),
1790 ".btn-link.btn-{$type}" => array( 'c' ),
1791 );
1792
1793 if ( $aui_bs5 ) {
1794 unset($selectors[".alert-{$type}" ]);
1795 }
1796
1797 if ( $type == 'primary' ) {
1798 $selectors = $selectors + array(
1799 'a' => array( 'c' ),
1800 '.btn-link' => array( 'c' ),
1801 '.dropdown-item.active' => array( 'b' ),
1802 '.custom-control-input:checked~.custom-control-label::before' => array(
1803 'b',
1804 'o'
1805 ),
1806 '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array(
1807 'b',
1808 'o'
1809 ),
1810 '.nav-pills .nav-link.active' => array( 'b' ),
1811 '.nav-pills .show>.nav-link' => array( 'b' ),
1812 '.page-link' => array( 'c' ),
1813 '.page-item.active .page-link' => array(
1814 'b',
1815 'o'
1816 ),
1817 '.progress-bar' => array( 'b' ),
1818 '.list-group-item.active' => array(
1819 'b',
1820 'o'
1821 ),
1822 '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array( 'b' ),
1823 // '.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules...
1824 // '.custom-range::-moz-range-thumb' => array('b'),
1825 // '.custom-range::-ms-thumb' => array('b'),
1826 );
1827 }
1828
1829 $important_selectors = array(
1830 ".bg-{$type}" => array('b','f'),
1831 ".border-{$type}" => array('o'),
1832 ".text-{$type}" => array('c'),
1833 );
1834
1835 $color = array();
1836 $color_i = array();
1837 $background = array();
1838 $background_i = array();
1839 $border = array();
1840 $border_i = array();
1841 $fill = array();
1842 $fill_i = array();
1843
1844 $output = '';
1845
1846 if ( $aui_bs5 ) {
1847 // $output .= $is_var ? 'html body {--bs-'.esc_attr($type).'-rgb: '.$color_code.'; }' : 'html body {--bs-'.esc_attr($type).'-rgb: '.self::hex_to_rgb($color_code).'; }';
1848
1849 if ( $rgb !== '' ) {
1850 $output .= 'html body {--bs-' . esc_attr( $type ) . '-rgb: ' . $rgb . '; }';
1851 }
1852 }
1853
1854 // build rules into each type
1855 foreach($selectors as $selector => $types){
1856 $selector = $compatibility ? $compatibility . " ".$selector : $selector;
1857 $types = array_combine($types,$types);
1858 if(isset($types['c'])){$color[] = $selector;}
1859 if(isset($types['b'])){$background[] = $selector;}
1860 if(isset($types['o'])){$border[] = $selector;}
1861 if(isset($types['f'])){$fill[] = $selector;}
1862 }
1863
1864 // build rules into each type
1865 foreach($important_selectors as $selector => $types){
1866 $selector = $compatibility ? $compatibility . " ".$selector : $selector;
1867 $types = array_combine($types,$types);
1868 if(isset($types['c'])){$color_i[] = $selector;}
1869 if(isset($types['b'])){$background_i[] = $selector;}
1870 if(isset($types['o'])){$border_i[] = $selector;}
1871 if(isset($types['f'])){$fill_i[] = $selector;}
1872 }
1873
1874 // add any color rules
1875 if(!empty($color)){
1876 $output .= implode(",",$color) . "{color: $color_code;} ";
1877 }
1878 if(!empty($color_i)){
1879 $output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1880 }
1881
1882 // add any background color rules
1883 if(!empty($background)){
1884 $output .= implode(",",$background) . "{background-color: $color_code;} ";
1885 }
1886 if(!empty($background_i)){
1887 $output .= $aui_bs5 ? '' : implode(",",$background_i) . "{background-color: $color_code !important;} ";
1888 // $output .= implode(",",$background_i) . "{background-color: rgba(var(--bs-primary-rgb), var(--bs-bg-opacity)) !important;} ";
1889 }
1890
1891 // add any border color rules
1892 if(!empty($border)){
1893 $output .= implode(",",$border) . "{border-color: $color_code;} ";
1894 }
1895 if(!empty($border_i)){
1896 $output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1897 }
1898
1899 // add any fill color rules
1900 if(!empty($fill)){
1901 $output .= implode(",",$fill) . "{fill: $color_code;} ";
1902 }
1903 if(!empty($fill_i)){
1904 $output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1905 }
1906
1907
1908 $prefix = $compatibility ? $compatibility . " " : "";
1909
1910 $transition = $is_var ? 'transition: color 0.15s ease-in-out,background-color 0.15s ease-in-out,border-color 0.15s ease-in-out,box-shadow 0.15s ease-in-out,filter 0.15s ease-in-out;' : '';
1911 // darken
1912 $darker_075 = $is_var ? $color_code.';filter:brightness(0.925)' : self::css_hex_lighten_darken($color_code,"-0.075");
1913 $darker_10 = $is_var ? $color_code.';filter:brightness(0.9)' : self::css_hex_lighten_darken($color_code,"-0.10");
1914 $darker_125 = $is_var ? $color_code.';filter:brightness(0.875)' : self::css_hex_lighten_darken($color_code,"-0.125");
1915 $darker_40 = $is_var ? $color_code.';filter:brightness(0.6)' : self::css_hex_lighten_darken($color_code,"-0.4");
1916
1917 // lighten
1918 $lighten_25 = $is_var ? $color_code.';filter:brightness(1.25)' :self::css_hex_lighten_darken($color_code,"0.25");
1919
1920 // opacity see https://css-tricks.com/8-digit-hex-codes/
1921 $op_25 = $color_code."40"; // 25% opacity
1922
1923
1924 // button states
1925 $output .= $is_var ? $prefix ." .btn-{$type}{{$transition }} " : '';
1926 $output .= $prefix ." .btn-{$type}:hover, $prefix .btn-{$type}:focus, $prefix .btn-{$type}.focus{background-color: ".$darker_075."; border-color: ".$darker_10.";} ";
1927 // $output .= $prefix ." .btn-{$type}:hover, $prefix .btn-{$type}:focus, $prefix .btn-{$type}.focus{background-color: #000; border-color: #000;} ";
1928 $output .= $prefix ." .btn-outline-{$type}:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-{$type}:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-{$type}.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1929 $output .= $prefix ." .btn-{$type}:not(:disabled):not(.disabled):active, $prefix .btn-{$type}:not(:disabled):not(.disabled).active, .show>$prefix .btn-{$type}.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} ";
1930 $output .= $prefix ." .btn-{$type}:not(:disabled):not(.disabled):active:focus, $prefix .btn-{$type}:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-{$type}.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1931
1932 if ( $type == 'primary' ) {
1933 // dropdown's
1934 $output .= $prefix . " .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
1935
1936 // input states
1937 $output .= $prefix . " .form-control:focus{border-color: " . $lighten_25 . ";box-shadow: 0 0 0 0.2rem $op_25;} ";
1938
1939 // page link
1940 $output .= $prefix . " .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1941 }
1942
1943 // alerts
1944 if ( $aui_bs5 ) {
1945 // $output .= $is_var ? '' : $prefix ." .alert-{$type} {background-color: ".$color_code."20; border-color: ".$color_code."30;color:$darker_40} ";
1946 $output .= $prefix ." .alert-{$type} {--bs-alert-bg: rgba(var(--bs-{$type}-rgb), .1 ) !important;--bs-alert-border-color: rgba(var(--bs-{$type}-rgb), .25 ) !important;--bs-alert-color: rgba(var(--bs-{$type}-rgb), 1 ) !important;} ";
1947 }
1948
1949 if ( $rgb === '' ) {
1950 // The stylesheet builds these from --bs-{type}-rgb, which is not set for this color.
1951 if ( $aui_bs5 ) {
1952 $output .= $prefix . " .bg-{$type}{background-color: color-mix(in srgb, $color_code calc(var(--bs-bg-opacity, 1) * 100%), transparent) !important;} ";
1953 $output .= $prefix . " .border-{$type}{border-color: color-mix(in srgb, $color_code calc(var(--bs-border-opacity, 1) * 100%), transparent) !important;} ";
1954 }
1955
1956 $output = self::css_rgb_fallback( $output, $type, $color_code );
1957 }
1958
1959 return $output;
1960 }
1961
1962 /**
1963 *
1964 * @deprecated 0.1.76 Use css_overwrite()
1965 *
1966 * @param $color_code
1967 * @param $compatibility
1968 * @param $use_variable
1969 *
1970 * @return string
1971 */
1972 public static function css_primary($color_code,$compatibility, $use_variable = false){
1973
1974 if(!$use_variable){
1975 $color_code = sanitize_hex_color($color_code);
1976 if(!$color_code){return '';}
1977 }
1978
1979 /**
1980 * c = color, b = background color, o = border-color, f = fill
1981 */
1982 $selectors = array(
1983 'a' => array('c'),
1984 '.btn-primary' => array('b','o'),
1985 '.btn-primary.disabled' => array('b','o'),
1986 '.btn-primary:disabled' => array('b','o'),
1987 '.btn-outline-primary' => array('c','o'),
1988 '.btn-outline-primary:hover' => array('b','o'),
1989 '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'),
1990 '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'),
1991 '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'),
1992 '.btn-link' => array('c'),
1993 '.dropdown-item.active' => array('b'),
1994 '.custom-control-input:checked~.custom-control-label::before' => array('b','o'),
1995 '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'),
1996 // '.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules...
1997 // '.custom-range::-moz-range-thumb' => array('b'),
1998 // '.custom-range::-ms-thumb' => array('b'),
1999 '.nav-pills .nav-link.active' => array('b'),
2000 '.nav-pills .show>.nav-link' => array('b'),
2001 '.page-link' => array('c'),
2002 '.page-item.active .page-link' => array('b','o'),
2003 '.badge-primary' => array('b'),
2004 '.alert-primary' => array('b','o'),
2005 '.progress-bar' => array('b'),
2006 '.list-group-item.active' => array('b','o'),
2007 '.bg-primary' => array('b','f'),
2008 '.btn-link.btn-primary' => array('c'),
2009 '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'),
2010 );
2011
2012 $important_selectors = array(
2013 '.bg-primary' => array('b','f'),
2014 '.border-primary' => array('o'),
2015 '.text-primary' => array('c'),
2016 );
2017
2018 $color = array();
2019 $color_i = array();
2020 $background = array();
2021 $background_i = array();
2022 $border = array();
2023 $border_i = array();
2024 $fill = array();
2025 $fill_i = array();
2026
2027 $output = '';
2028
2029 // build rules into each type
2030 foreach($selectors as $selector => $types){
2031 $selector = $compatibility ? ".bsui ".$selector : $selector;
2032 $types = array_combine($types,$types);
2033 if(isset($types['c'])){$color[] = $selector;}
2034 if(isset($types['b'])){$background[] = $selector;}
2035 if(isset($types['o'])){$border[] = $selector;}
2036 if(isset($types['f'])){$fill[] = $selector;}
2037 }
2038
2039 // build rules into each type
2040 foreach($important_selectors as $selector => $types){
2041 $selector = $compatibility ? ".bsui ".$selector : $selector;
2042 $types = array_combine($types,$types);
2043 if(isset($types['c'])){$color_i[] = $selector;}
2044 if(isset($types['b'])){$background_i[] = $selector;}
2045 if(isset($types['o'])){$border_i[] = $selector;}
2046 if(isset($types['f'])){$fill_i[] = $selector;}
2047 }
2048
2049 // add any color rules
2050 if(!empty($color)){
2051 $output .= implode(",",$color) . "{color: $color_code;} ";
2052 }
2053 if(!empty($color_i)){
2054 $output .= implode(",",$color_i) . "{color: $color_code !important;} ";
2055 }
2056
2057 // add any background color rules
2058 if(!empty($background)){
2059 $output .= implode(",",$background) . "{background-color: $color_code;} ";
2060 }
2061 if(!empty($background_i)){
2062 $output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
2063 }
2064
2065 // add any border color rules
2066 if(!empty($border)){
2067 $output .= implode(",",$border) . "{border-color: $color_code;} ";
2068 }
2069 if(!empty($border_i)){
2070 $output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
2071 }
2072
2073 // add any fill color rules
2074 if(!empty($fill)){
2075 $output .= implode(",",$fill) . "{fill: $color_code;} ";
2076 }
2077 if(!empty($fill_i)){
2078 $output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
2079 }
2080
2081
2082 $prefix = $compatibility ? ".bsui " : "";
2083
2084 // darken
2085 $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
2086 $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
2087 $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
2088
2089 // lighten
2090 $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
2091
2092 // opacity see https://css-tricks.com/8-digit-hex-codes/
2093 $op_25 = $color_code."40"; // 25% opacity
2094
2095
2096 // button states
2097 $output .= $prefix ." .btn-primary:hover, $prefix .btn-primary:focus, $prefix .btn-primary.focus{background-color: ".$darker_075."; border-color: ".$darker_10.";} ";
2098 $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
2099 $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} ";
2100 $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
2101
2102
2103 // dropdown's
2104 $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
2105
2106
2107 // input states
2108 $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} ";
2109
2110 // page link
2111 $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
2112
2113 return $output;
2114 }
2115
2116 /**
2117 *
2118 * @deprecated 0.1.76 Use css_overwrite()
2119 *
2120 * @param $color_code
2121 * @param $compatibility
2122 *
2123 * @return string
2124 */
2125 public static function css_secondary($color_code,$compatibility){;
2126 $color_code = sanitize_hex_color($color_code);
2127 if(!$color_code){return '';}
2128 /**
2129 * c = color, b = background color, o = border-color, f = fill
2130 */
2131 $selectors = array(
2132 '.btn-secondary' => array('b','o'),
2133 '.btn-secondary.disabled' => array('b','o'),
2134 '.btn-secondary:disabled' => array('b','o'),
2135 '.btn-outline-secondary' => array('c','o'),
2136 '.btn-outline-secondary:hover' => array('b','o'),
2137 '.btn-outline-secondary.disabled' => array('c'),
2138 '.btn-outline-secondary:disabled' => array('c'),
2139 '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'),
2140 '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'),
2141 '.btn-outline-secondary.dropdown-toggle' => array('b','o'),
2142 '.badge-secondary' => array('b'),
2143 '.alert-secondary' => array('b','o'),
2144 '.btn-link.btn-secondary' => array('c'),
2145 );
2146
2147 $important_selectors = array(
2148 '.bg-secondary' => array('b','f'),
2149 '.border-secondary' => array('o'),
2150 '.text-secondary' => array('c'),
2151 );
2152
2153 $color = array();
2154 $color_i = array();
2155 $background = array();
2156 $background_i = array();
2157 $border = array();
2158 $border_i = array();
2159 $fill = array();
2160 $fill_i = array();
2161
2162 $output = '';
2163
2164 // build rules into each type
2165 foreach($selectors as $selector => $types){
2166 $selector = $compatibility ? ".bsui ".$selector : $selector;
2167 $types = array_combine($types,$types);
2168 if(isset($types['c'])){$color[] = $selector;}
2169 if(isset($types['b'])){$background[] = $selector;}
2170 if(isset($types['o'])){$border[] = $selector;}
2171 if(isset($types['f'])){$fill[] = $selector;}
2172 }
2173
2174 // build rules into each type
2175 foreach($important_selectors as $selector => $types){
2176 $selector = $compatibility ? ".bsui ".$selector : $selector;
2177 $types = array_combine($types,$types);
2178 if(isset($types['c'])){$color_i[] = $selector;}
2179 if(isset($types['b'])){$background_i[] = $selector;}
2180 if(isset($types['o'])){$border_i[] = $selector;}
2181 if(isset($types['f'])){$fill_i[] = $selector;}
2182 }
2183
2184 // add any color rules
2185 if(!empty($color)){
2186 $output .= implode(",",$color) . "{color: $color_code;} ";
2187 }
2188 if(!empty($color_i)){
2189 $output .= implode(",",$color_i) . "{color: $color_code !important;} ";
2190 }
2191
2192 // add any background color rules
2193 if(!empty($background)){
2194 $output .= implode(",",$background) . "{background-color: $color_code;} ";
2195 }
2196 if(!empty($background_i)){
2197 $output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
2198 }
2199
2200 // add any border color rules
2201 if(!empty($border)){
2202 $output .= implode(",",$border) . "{border-color: $color_code;} ";
2203 }
2204 if(!empty($border_i)){
2205 $output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
2206 }
2207
2208 // add any fill color rules
2209 if(!empty($fill)){
2210 $output .= implode(",",$fill) . "{fill: $color_code;} ";
2211 }
2212 if(!empty($fill_i)){
2213 $output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
2214 }
2215
2216
2217 $prefix = $compatibility ? ".bsui " : "";
2218
2219 // darken
2220 $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
2221 $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
2222 $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
2223
2224 // lighten
2225 $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
2226
2227 // opacity see https://css-tricks.com/8-digit-hex-codes/
2228 $op_25 = $color_code."40"; // 25% opacity
2229
2230
2231 // button states
2232 $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} ";
2233 $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
2234 $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} ";
2235 $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
2236
2237
2238 return $output;
2239 }
2240
2241 /**
2242 * Increases or decreases the brightness of a color by a percentage of the current brightness.
2243 *
2244 * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF`
2245 * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker.
2246 *
2247 * @return string
2248 */
2249 public static function css_hex_lighten_darken($hexCode, $adjustPercent) {
2250 $hexCode = ltrim($hexCode, '#');
2251
2252 if ( strpos( $hexCode, 'rgba(' ) !== false || strpos( $hexCode, 'rgb(' ) !== false ) {
2253 return $hexCode;
2254 }
2255
2256 if (strlen($hexCode) == 3) {
2257 $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2];
2258 }
2259
2260 $hexCode = array_map('hexdec', str_split($hexCode, 2));
2261
2262 foreach ($hexCode as & $color) {
2263 $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color;
2264 $adjustAmount = ceil($adjustableLimit * $adjustPercent);
2265
2266 $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT);
2267 }
2268
2269 return '#' . implode($hexCode);
2270 }
2271
2272 /**
2273 * Check if we should display examples.
2274 */
2275 public function maybe_show_examples(){
2276 if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){
2277 echo "<head>";
2278 wp_head();
2279 echo "</head>";
2280 echo "<body>";
2281 echo $this->get_examples(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2282 echo "</body>";
2283 exit;
2284 }
2285 }
2286
2287 /**
2288 * Get developer examples.
2289 *
2290 * @return string
2291 */
2292 public function get_examples(){
2293 $output = '';
2294
2295
2296 // open form
2297 $output .= "<form class='p-5 m-5 border rounded'>";
2298
2299 // input example
2300 $output .= aui()->input(array(
2301 'type' => 'text',
2302 'id' => 'text-example',
2303 'name' => 'text-example',
2304 'placeholder' => 'text placeholder',
2305 'title' => 'Text input example',
2306 'value' => '',
2307 'required' => false,
2308 'help_text' => 'help text',
2309 'label' => 'Text input example label'
2310 ));
2311
2312 // input example
2313 $output .= aui()->input(array(
2314 'type' => 'url',
2315 'id' => 'text-example2',
2316 'name' => 'text-example',
2317 'placeholder' => 'url placeholder',
2318 'title' => 'Text input example',
2319 'value' => '',
2320 'required' => false,
2321 'help_text' => 'help text',
2322 'label' => 'Text input example label'
2323 ));
2324
2325 // checkbox example
2326 $output .= aui()->input(array(
2327 'type' => 'checkbox',
2328 'id' => 'checkbox-example',
2329 'name' => 'checkbox-example',
2330 'placeholder' => 'checkbox-example',
2331 'title' => 'Checkbox example',
2332 'value' => '1',
2333 'checked' => true,
2334 'required' => false,
2335 'help_text' => 'help text',
2336 'label' => 'Checkbox checked'
2337 ));
2338
2339 // checkbox example
2340 $output .= aui()->input(array(
2341 'type' => 'checkbox',
2342 'id' => 'checkbox-example2',
2343 'name' => 'checkbox-example2',
2344 'placeholder' => 'checkbox-example',
2345 'title' => 'Checkbox example',
2346 'value' => '1',
2347 'checked' => false,
2348 'required' => false,
2349 'help_text' => 'help text',
2350 'label' => 'Checkbox un-checked'
2351 ));
2352
2353 // switch example
2354 $output .= aui()->input(array(
2355 'type' => 'checkbox',
2356 'id' => 'switch-example',
2357 'name' => 'switch-example',
2358 'placeholder' => 'checkbox-example',
2359 'title' => 'Switch example',
2360 'value' => '1',
2361 'checked' => true,
2362 'switch' => true,
2363 'required' => false,
2364 'help_text' => 'help text',
2365 'label' => 'Switch on'
2366 ));
2367
2368 // switch example
2369 $output .= aui()->input(array(
2370 'type' => 'checkbox',
2371 'id' => 'switch-example2',
2372 'name' => 'switch-example2',
2373 'placeholder' => 'checkbox-example',
2374 'title' => 'Switch example',
2375 'value' => '1',
2376 'checked' => false,
2377 'switch' => true,
2378 'required' => false,
2379 'help_text' => 'help text',
2380 'label' => 'Switch off'
2381 ));
2382
2383 // close form
2384 $output .= "</form>";
2385
2386 return $output;
2387 }
2388
2389 /**
2390 * Calendar params.
2391 *
2392 * @since 0.1.44
2393 *
2394 * @return array Calendar params.
2395 */
2396 public static function calendar_params() {
2397 $params = array(
2398 'month_long_1' => __( 'January', 'ayecode-connect' ),
2399 'month_long_2' => __( 'February', 'ayecode-connect' ),
2400 'month_long_3' => __( 'March', 'ayecode-connect' ),
2401 'month_long_4' => __( 'April', 'ayecode-connect' ),
2402 'month_long_5' => __( 'May', 'ayecode-connect' ),
2403 'month_long_6' => __( 'June', 'ayecode-connect' ),
2404 'month_long_7' => __( 'July', 'ayecode-connect' ),
2405 'month_long_8' => __( 'August', 'ayecode-connect' ),
2406 'month_long_9' => __( 'September', 'ayecode-connect' ),
2407 'month_long_10' => __( 'October', 'ayecode-connect' ),
2408 'month_long_11' => __( 'November', 'ayecode-connect' ),
2409 'month_long_12' => __( 'December', 'ayecode-connect' ),
2410 'month_s_1' => _x( 'Jan', 'January abbreviation', 'ayecode-connect' ),
2411 'month_s_2' => _x( 'Feb', 'February abbreviation', 'ayecode-connect' ),
2412 'month_s_3' => _x( 'Mar', 'March abbreviation', 'ayecode-connect' ),
2413 'month_s_4' => _x( 'Apr', 'April abbreviation', 'ayecode-connect' ),
2414 'month_s_5' => _x( 'May', 'May abbreviation', 'ayecode-connect' ),
2415 'month_s_6' => _x( 'Jun', 'June abbreviation', 'ayecode-connect' ),
2416 'month_s_7' => _x( 'Jul', 'July abbreviation', 'ayecode-connect' ),
2417 'month_s_8' => _x( 'Aug', 'August abbreviation', 'ayecode-connect' ),
2418 'month_s_9' => _x( 'Sep', 'September abbreviation', 'ayecode-connect' ),
2419 'month_s_10' => _x( 'Oct', 'October abbreviation', 'ayecode-connect' ),
2420 'month_s_11' => _x( 'Nov', 'November abbreviation', 'ayecode-connect' ),
2421 'month_s_12' => _x( 'Dec', 'December abbreviation', 'ayecode-connect' ),
2422 'day_s1_1' => _x( 'S', 'Sunday initial', 'ayecode-connect' ),
2423 'day_s1_2' => _x( 'M', 'Monday initial', 'ayecode-connect' ),
2424 'day_s1_3' => _x( 'T', 'Tuesday initial', 'ayecode-connect' ),
2425 'day_s1_4' => _x( 'W', 'Wednesday initial', 'ayecode-connect' ),
2426 'day_s1_5' => _x( 'T', 'Friday initial', 'ayecode-connect' ),
2427 'day_s1_6' => _x( 'F', 'Thursday initial', 'ayecode-connect' ),
2428 'day_s1_7' => _x( 'S', 'Saturday initial', 'ayecode-connect' ),
2429 'day_s2_1' => __( 'Su', 'ayecode-connect' ),
2430 'day_s2_2' => __( 'Mo', 'ayecode-connect' ),
2431 'day_s2_3' => __( 'Tu', 'ayecode-connect' ),
2432 'day_s2_4' => __( 'We', 'ayecode-connect' ),
2433 'day_s2_5' => __( 'Th', 'ayecode-connect' ),
2434 'day_s2_6' => __( 'Fr', 'ayecode-connect' ),
2435 'day_s2_7' => __( 'Sa', 'ayecode-connect' ),
2436 'day_s3_1' => __( 'Sun', 'ayecode-connect' ),
2437 'day_s3_2' => __( 'Mon', 'ayecode-connect' ),
2438 'day_s3_3' => __( 'Tue', 'ayecode-connect' ),
2439 'day_s3_4' => __( 'Wed', 'ayecode-connect' ),
2440 'day_s3_5' => __( 'Thu', 'ayecode-connect' ),
2441 'day_s3_6' => __( 'Fri', 'ayecode-connect' ),
2442 'day_s3_7' => __( 'Sat', 'ayecode-connect' ),
2443 'day_s5_1' => __( 'Sunday', 'ayecode-connect' ),
2444 'day_s5_2' => __( 'Monday', 'ayecode-connect' ),
2445 'day_s5_3' => __( 'Tuesday', 'ayecode-connect' ),
2446 'day_s5_4' => __( 'Wednesday', 'ayecode-connect' ),
2447 'day_s5_5' => __( 'Thursday', 'ayecode-connect' ),
2448 'day_s5_6' => __( 'Friday', 'ayecode-connect' ),
2449 'day_s5_7' => __( 'Saturday', 'ayecode-connect' ),
2450 'am_lower' => __( 'am', 'ayecode-connect' ),
2451 'pm_lower' => __( 'pm', 'ayecode-connect' ),
2452 'am_upper' => __( 'AM', 'ayecode-connect' ),
2453 'pm_upper' => __( 'PM', 'ayecode-connect' ),
2454 'firstDayOfWeek' => (int) get_option( 'start_of_week' ),
2455 'time_24hr' => false,
2456 'year' => __( 'Year', 'ayecode-connect' ),
2457 'hour' => __( 'Hour', 'ayecode-connect' ),
2458 'minute' => __( 'Minute', 'ayecode-connect' ),
2459 'weekAbbreviation' => __( 'Wk', 'ayecode-connect' ),
2460 'rangeSeparator' => __( ' to ', 'ayecode-connect' ),
2461 'scrollTitle' => __( 'Scroll to increment', 'ayecode-connect' ),
2462 'toggleTitle' => __( 'Click to toggle', 'ayecode-connect' )
2463 );
2464
2465 return apply_filters( 'ayecode_ui_calendar_params', $params );
2466 }
2467
2468 /**
2469 * Flatpickr calendar localize.
2470 *
2471 * @since 0.1.44
2472 *
2473 * @return string Calendar locale.
2474 */
2475 public static function flatpickr_locale() {
2476 $params = self::calendar_params();
2477
2478 if ( is_string( $params ) ) {
2479 $params = html_entity_decode( $params, ENT_QUOTES, 'UTF-8' );
2480 } else {
2481 foreach ( (array) $params as $key => $value ) {
2482 if ( ! is_scalar( $value ) ) {
2483 continue;
2484 }
2485
2486 $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
2487 }
2488 }
2489
2490 $day_s3 = array();
2491 $day_s5 = array();
2492
2493 for ( $i = 1; $i <= 7; $i ++ ) {
2494 $day_s3[] = addslashes( $params[ 'day_s3_' . $i ] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2495 $day_s5[] = addslashes( $params[ 'day_s3_' . $i ] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2496 }
2497
2498 $month_s = array();
2499 $month_long = array();
2500
2501 for ( $i = 1; $i <= 12; $i ++ ) {
2502 $month_s[] = addslashes( $params[ 'month_s_' . $i ] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2503 $month_long[] = addslashes( $params[ 'month_long_' . $i ] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2504 }
2505
2506 ob_start();
2507 if ( 0 ) { ?><script><?php } ?>
2508 {
2509 weekdays: {
2510 shorthand: ['<?php echo implode( "','", $day_s3 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>'],
2511 longhand: ['<?php echo implode( "','", $day_s5 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>'],
2512 },
2513 months: {
2514 shorthand: ['<?php echo implode( "','", $month_s ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>'],
2515 longhand: ['<?php echo implode( "','", $month_long ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>'],
2516 },
2517 daysInMonth: [31,28,31,30,31,30,31,31,30,31,30,31],
2518 firstDayOfWeek: <?php echo (int) $params[ 'firstDayOfWeek' ]; ?>,
2519 ordinal: function (nth) {
2520 var s = nth % 100;
2521 if (s > 3 && s < 21)
2522 return "th";
2523 switch (s % 10) {
2524 case 1:
2525 return "st";
2526 case 2:
2527 return "nd";
2528 case 3:
2529 return "rd";
2530 default:
2531 return "th";
2532 }
2533 },
2534 rangeSeparator: '<?php echo esc_attr( $params[ 'rangeSeparator' ] ); ?>',
2535 weekAbbreviation: '<?php echo esc_attr( $params[ 'weekAbbreviation' ] ); ?>',
2536 scrollTitle: '<?php echo esc_attr( $params[ 'scrollTitle' ] ); ?>',
2537 toggleTitle: '<?php echo esc_attr( $params[ 'toggleTitle' ] ); ?>',
2538 amPM: ['<?php echo esc_attr( $params[ 'am_upper' ] ); ?>','<?php echo esc_attr( $params[ 'pm_upper' ] ); ?>'],
2539 yearAriaLabel: '<?php echo esc_attr( $params[ 'year' ] ); ?>',
2540 hourAriaLabel: '<?php echo esc_attr( $params[ 'hour' ] ); ?>',
2541 minuteAriaLabel: '<?php echo esc_attr( $params[ 'minute' ] ); ?>',
2542 time_24hr: <?php echo ( $params[ 'time_24hr' ] ? 'true' : 'false' ) ; ?>
2543 }
2544 <?php if ( 0 ) { ?></script><?php } ?>
2545 <?php
2546 $locale = ob_get_clean();
2547
2548 return apply_filters( 'ayecode_ui_flatpickr_locale', trim( $locale ) );
2549 }
2550
2551 /**
2552 * Select2 JS params.
2553 *
2554 * @since 0.1.44
2555 *
2556 * @return array Select2 JS params.
2557 */
2558 public static function select2_params() {
2559 $params = array(
2560 'i18n_select_state_text' => esc_attr__( 'Select an option&hellip;', 'ayecode-connect' ),
2561 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'ayecode-connect' ),
2562 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'ayecode-connect' ),
2563 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'ayecode-connect' ),
2564 'i18n_input_too_short_n' => _x( 'Please enter %item% or more characters', 'enhanced select', 'ayecode-connect' ),
2565 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'ayecode-connect' ),
2566 'i18n_input_too_long_n' => _x( 'Please delete %item% characters', 'enhanced select', 'ayecode-connect' ),
2567 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'ayecode-connect' ),
2568 'i18n_selection_too_long_n' => _x( 'You can only select %item% items', 'enhanced select', 'ayecode-connect' ),
2569 'i18n_load_more' => _x( 'Loading more results&hellip;', 'enhanced select', 'ayecode-connect' ),
2570 'i18n_searching' => _x( 'Searching&hellip;', 'enhanced select', 'ayecode-connect' )
2571 );
2572
2573 return apply_filters( 'ayecode_ui_select2_params', $params );
2574 }
2575
2576 /**
2577 * Select2 JS localize.
2578 *
2579 * @since 0.1.44
2580 *
2581 * @return string Select2 JS locale.
2582 */
2583 public static function select2_locale() {
2584 $params = self::select2_params();
2585
2586 foreach ( (array) $params as $key => $value ) {
2587 if ( ! is_scalar( $value ) ) {
2588 continue;
2589 }
2590
2591 $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
2592 }
2593
2594 $locale = json_encode( $params );
2595
2596 return apply_filters( 'ayecode_ui_select2_locale', trim( $locale ) );
2597 }
2598
2599 /**
2600 * Time ago JS localize.
2601 *
2602 * @since 0.1.47
2603 *
2604 * @return string Time ago JS locale.
2605 */
2606 public static function timeago_locale() {
2607 $params = array(
2608 'prefix_ago' => '',
2609 'suffix_ago' => ' ' . _x( 'ago', 'time ago', 'ayecode-connect' ),
2610 'prefix_after' => _x( 'after', 'time ago', 'ayecode-connect' ) . ' ',
2611 'suffix_after' => '',
2612 'seconds' => _x( 'less than a minute', 'time ago', 'ayecode-connect' ),
2613 'minute' => _x( 'about a minute', 'time ago', 'ayecode-connect' ),
2614 'minutes' => _x( '%d minutes', 'time ago', 'ayecode-connect' ),
2615 'hour' => _x( 'about an hour', 'time ago', 'ayecode-connect' ),
2616 'hours' => _x( 'about %d hours', 'time ago', 'ayecode-connect' ),
2617 'day' => _x( 'a day', 'time ago', 'ayecode-connect' ),
2618 'days' => _x( '%d days', 'time ago', 'ayecode-connect' ),
2619 'month' => _x( 'about a month', 'time ago', 'ayecode-connect' ),
2620 'months' => _x( '%d months', 'time ago', 'ayecode-connect' ),
2621 'year' => _x( 'about a year', 'time ago', 'ayecode-connect' ),
2622 'years' => _x( '%d years', 'time ago', 'ayecode-connect' ),
2623 );
2624
2625 $params = apply_filters( 'ayecode_ui_timeago_params', $params );
2626
2627 foreach ( (array) $params as $key => $value ) {
2628 if ( ! is_scalar( $value ) ) {
2629 continue;
2630 }
2631
2632 $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
2633 }
2634
2635 $locale = json_encode( $params );
2636
2637 return apply_filters( 'ayecode_ui_timeago_locale', trim( $locale ) );
2638 }
2639
2640 /**
2641 * JavaScript Minifier
2642 *
2643 * @param $input
2644 *
2645 * @return mixed
2646 */
2647 public static function minify_js($input) {
2648 if(trim($input) === "") return $input;
2649 return preg_replace(
2650 array(
2651 // Remove comment(s)
2652 '#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#',
2653 // Remove white-space(s) outside the string and regex
2654 '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#s',
2655 // Remove the last semicolon
2656 '#;+\}#',
2657 // Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}`
2658 '#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i',
2659 // --ibid. From `foo['bar']` to `foo.bar`
2660 '#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i'
2661 ),
2662 array(
2663 '$1',
2664 '$1$2',
2665 '}',
2666 '$1$3',
2667 '$1.$3'
2668 ),
2669 $input);
2670 }
2671
2672 /**
2673 * Minify CSS
2674 *
2675 * @param $input
2676 *
2677 * @return mixed
2678 */
2679 public static function minify_css($input) {
2680 if(trim($input) === "") return $input;
2681 return preg_replace(
2682 array(
2683 // Remove comment(s)
2684 '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\/\*(?!\!)(?>.*?\*\/)|^\s*|\s*$#s',
2685 // Remove unused white-space(s)
2686 '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/))|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~]|\s(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si',
2687 // Replace `0(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)` with `0`
2688 '#(?<=[\s:])(0)(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)#si',
2689 // Replace `:0 0 0 0` with `:0`
2690 '#:(0\s+0|0\s+0\s+0\s+0)(?=[;\}]|\!important)#i',
2691 // Replace `background-position:0` with `background-position:0 0`
2692 '#(background-position):0(?=[;\}])#si',
2693 // Replace `0.6` with `.6`, but only when preceded by `:`, `,`, `-` or a white-space
2694 '#(?<=[\s:,\-])0+\.(\d+)#s',
2695 // Minify string value
2696 '#(\/\*(?>.*?\*\/))|(?<!content\:)([\'"])([a-z_][a-z0-9\-_]*?)\2(?=[\s\{\}\];,])#si',
2697 '#(\/\*(?>.*?\*\/))|(\burl\()([\'"])([^\s]+?)\3(\))#si',
2698 // Minify HEX color code
2699 '#(?<=[\s:,\-]\#)([a-f0-6]+)\1([a-f0-6]+)\2([a-f0-6]+)\3#i',
2700 // Replace `(border|outline):none` with `(border|outline):0`
2701 '#(?<=[\{;])(border|outline):none(?=[;\}\!])#',
2702 // Remove empty selector(s)
2703 '#(\/\*(?>.*?\*\/))|(^|[\{\}])(?:[^\s\{\}]+)\{\}#s'
2704 ),
2705 array(
2706 '$1',
2707 '$1$2$3$4$5$6$7',
2708 '$1',
2709 ':0',
2710 '$1:0 0',
2711 '.$1',
2712 '$1$3',
2713 '$1$2$4$5',
2714 '$1$2$3',
2715 '$1:0',
2716 '$1$2'
2717 ),
2718 $input);
2719 }
2720
2721 /**
2722 * Get the conditional fields JavaScript.
2723 *
2724 * @return mixed
2725 */
2726 public function conditional_fields_js() {
2727 ob_start();
2728 ?>
2729 <script>
2730 /**
2731 * Conditional Fields
2732 */
2733 var aui_cf_field_rules = [], aui_cf_field_key_rules = {}, aui_cf_field_default_values = {};
2734
2735 jQuery(function($) {
2736 aui_cf_field_init_rules($);
2737 });
2738
2739 /**
2740 * Conditional fields init.
2741 */
2742 function aui_cf_field_init_rules($) {
2743 if (!$('[data-has-rule]').length) {
2744 return;
2745 }
2746 $('input.select2-search__field,.aui-cf-ignore-rule').attr('data-ignore-rule','');
2747 $('[data-rule-key]').on('change keypress keyup gdclear', 'input, textarea', function() {
2748 if (!$(this).hasClass('select2-search__field')) {
2749 aui_cf_field_apply_rules($(this));
2750 }
2751 });
2752
2753 $('[data-rule-key]').on('change change.select2 gdclear', 'select', function() {
2754 aui_cf_field_apply_rules($(this));
2755 });
2756
2757 aui_cf_field_setup_rules($);
2758 }
2759
2760 /**
2761 * Setup conditional field rules.
2762 */
2763 function aui_cf_field_setup_rules($) {
2764 var aui_cf_field_keys = [];
2765
2766 $('[data-rule-key]').each(function() {
2767 var key = $(this).data('rule-key'), irule = parseInt($(this).data('has-rule'));
2768 if (key) {
2769 aui_cf_field_keys.push(key);
2770 }
2771
2772 var parse_conds = {};
2773 if ($(this).data('rule-fie-0')) {
2774 $(this).find('input,select,textarea').each(function() {
2775 if ($(this).attr('required') || $(this).attr('oninvalid')) {
2776 $(this).addClass('aui-cf-req');
2777 if ($(this).attr('required')) {
2778 $(this).attr('data-rule-req', true);
2779 }
2780 if ($(this).attr('oninvalid')) {
2781 $(this).attr('data-rule-oninvalid', $(this).attr('oninvalid'));
2782 }
2783 }
2784 });
2785 for (var i = 0; i < irule; i++) {
2786 var field = $(this).data('rule-fie-' + i);
2787 if (typeof parse_conds[i] === 'undefined') {
2788 parse_conds[i] = {};
2789 }
2790 parse_conds[i]['action'] = $(this).data('rule-act-' + i);
2791 parse_conds[i]['field'] = $(this).data('rule-fie-' + i);
2792 parse_conds[i]['condition'] = $(this).data('rule-con-' + i);
2793 parse_conds[i]['value'] = $(this).data('rule-val-' + i);
2794 }
2795
2796 $.each(parse_conds, function(j, data) {
2797 var item = {
2798 'field': {
2799 key: key,
2800 action: data.action,
2801 field: data.field,
2802 condition: data.condition,
2803 value: data.value,
2804 rule: {
2805 key: key,
2806 action: data.action,
2807 condition: data.condition,
2808 value: data.value
2809 }
2810 }
2811 };
2812 aui_cf_field_rules.push(item);
2813 });
2814 }
2815 aui_cf_field_default_values[$(this).data('rule-key')] = aui_cf_field_get_default_value($(this));
2816 });
2817
2818 $.each(aui_cf_field_keys, function(i, fkey) {
2819 aui_cf_field_key_rules[fkey] = aui_cf_field_get_children(fkey);
2820 });
2821
2822 $('[data-rule-key]:visible').each(function() {
2823 var conds = aui_cf_field_key_rules[$(this).data('rule-key')];
2824 if (conds && conds.length) {
2825 var $main_el = $(this), el = aui_cf_field_get_element($main_el);
2826 if ($(el).length) {
2827 aui_cf_field_apply_rules($(el));
2828 }
2829 }
2830 });
2831 }
2832
2833 /**
2834 * Apply conditional field rules.
2835 */
2836 function aui_cf_field_apply_rules($el) {
2837 if (!$el.parents('[data-rule-key]').length) {
2838 return;
2839 }
2840
2841 if ($el.data('no-rule')) {
2842 return;
2843 }
2844
2845 var key = $el.parents('[data-rule-key]').data('rule-key');
2846 var conditions = aui_cf_field_key_rules[key];
2847 if (typeof conditions === 'undefined') {
2848 return;
2849 }
2850 var field_type = aui_cf_field_get_type($el.parents('[data-rule-key]')), current_value = aui_cf_field_get_value($el);
2851 var $keys = {}, $keys_values = {}, $key_rules = {};
2852
2853 jQuery.each(conditions, function(index, condition) {
2854 if (typeof $keys_values[condition.key] == 'undefined') {
2855 $keys_values[condition.key] = [];
2856 $key_rules[condition.key] = {}
2857 }
2858
2859 $keys_values[condition.key].push(condition.value);
2860 $key_rules[condition.key] = condition;
2861 });
2862
2863 jQuery.each(conditions, function(index, condition) {
2864 if (typeof $keys[condition.key] == 'undefined') {
2865 $keys[condition.key] = {};
2866 }
2867
2868 if (condition.condition === 'empty') {
2869 var field_value = Array.isArray(current_value) ? current_value.join('') : current_value;
2870 if (!field_value || field_value === '') {
2871 $keys[condition.key][index] = true;
2872 } else {
2873 $keys[condition.key][index] = false;
2874 }
2875 } else if (condition.condition === 'not empty') {
2876 var field_value = Array.isArray(current_value) ? current_value.join('') : current_value;
2877 if (field_value && field_value !== '') {
2878 $keys[condition.key][index] = true;
2879 } else {
2880 $keys[condition.key][index] = false;
2881 }
2882 } else if (condition.condition === 'equals to') {
2883 var field_value = (Array.isArray(current_value) && current_value.length === 1) ? current_value[0] : current_value;
2884 if (((condition.value && condition.value == condition.value) || (condition.value === field_value)) && aui_cf_field_in_array(field_value, $keys_values[condition.key])) {
2885 $keys[condition.key][index] = true;
2886 } else {
2887 $keys[condition.key][index] = false;
2888 }
2889 } else if (condition.condition === 'not equals') {
2890 var field_value = (Array.isArray(current_value) && current_value.length === 1) ? current_value[0] : current_value;
2891 if (jQuery.isNumeric(condition.value) && parseInt(field_value) !== parseInt(condition.value) && field_value && !aui_cf_field_in_array(field_value, $keys_values[condition.key])) {
2892 $keys[condition.key][index] = true;
2893 } else if (condition.value != field_value && !aui_cf_field_in_array(field_value, $keys_values[condition.key])) {
2894 $keys[condition.key][index] = true;
2895 } else {
2896 $keys[condition.key][index] = false;
2897 }
2898 } else if (condition.condition === 'greater than') {
2899 var field_value = (Array.isArray(current_value) && current_value.length === 1) ? current_value[0] : current_value;
2900 if (jQuery.isNumeric(condition.value) && parseInt(field_value) > parseInt(condition.value)) {
2901 $keys[condition.key][index] = true;
2902 } else {
2903 $keys[condition.key][index] = false;
2904 }
2905 } else if (condition.condition === 'less than') {
2906 var field_value = (Array.isArray(current_value) && current_value.length === 1) ? current_value[0] : current_value;
2907 if (jQuery.isNumeric(condition.value) && parseInt(field_value) < parseInt(condition.value)) {
2908 $keys[condition.key][index] = true;
2909 } else {
2910 $keys[condition.key][index] = false;
2911 }
2912 } else if (condition.condition === 'contains') {
2913 var avalues = condition.value;
2914 if (!Array.isArray(avalues)) {
2915 if (jQuery.isNumeric(avalues)) {
2916 avalues = [avalues];
2917 } else {
2918 avalues = avalues.split(",");
2919 }
2920 }
2921 switch (field_type) {
2922 case 'multiselect':
2923 var found = false;
2924 for (var key in avalues) {
2925 var svalue = jQuery.isNumeric(avalues[key]) ? avalues[key] : (avalues[key]).trim();
2926 if (!found && current_value && ((!Array.isArray(current_value) && current_value.indexOf(svalue) >= 0) || (Array.isArray(current_value) && aui_cf_field_in_array(svalue, current_value)))) {
2927 found = true;
2928 }
2929 }
2930
2931 if (found) {
2932 $keys[condition.key][index] = true;
2933 } else {
2934 $keys[condition.key][index] = false;
2935 }
2936 break;
2937 case 'checkbox':
2938 if (current_value && ((!Array.isArray(current_value) && current_value.indexOf(condition.value) >= 0) || (Array.isArray(current_value) && aui_cf_field_in_array(condition.value, current_value)))) {
2939 $keys[condition.key][index] = true;
2940 } else {
2941 $keys[condition.key][index] = false;
2942 }
2943 break;
2944 default:
2945 if (typeof $keys[condition.key][index] === 'undefined') {
2946 if (current_value && current_value.indexOf(condition.value) >= 0 && aui_cf_field_in_array(current_value, $keys_values[condition.key], false, true)) {
2947 $keys[condition.key][index] = true;
2948 } else {
2949 $keys[condition.key][index] = false;
2950 }
2951 }
2952 break;
2953 }
2954 }
2955 });
2956
2957 jQuery.each($keys, function(index, field) {
2958 if (aui_cf_field_in_array(true, field)) {
2959 aui_cf_field_apply_action($el, $key_rules[index], true);
2960 } else {
2961 aui_cf_field_apply_action($el, $key_rules[index], false);
2962 }
2963 });
2964
2965 /* Trigger field change */
2966 if ($keys.length) {
2967 $el.trigger('aui_cf_field_on_change');
2968 }
2969 }
2970
2971 /**
2972 * Get the field element.
2973 */
2974 function aui_cf_field_get_element($el) {
2975 var el = $el.find('input,textarea,select').not('[data-ignore-rule]'), type = aui_cf_field_get_type($el);
2976 if (type && window._aui_cf_field_elements && typeof window._aui_cf_field_elements == 'object' && typeof window._aui_cf_field_elements[type] != 'undefined') {
2977 el = window._aui_cf_field_elements[type];
2978 }
2979 return el;
2980 }
2981
2982 /**
2983 * Get the field type.
2984 */
2985 function aui_cf_field_get_type($el) {
2986 return $el.data('rule-type');
2987 }
2988
2989 /**
2990 * Get the field value.
2991 */
2992 function aui_cf_field_get_value($el) {
2993 var current_value = $el.val();
2994
2995 if ($el.is(':checkbox')) {
2996 current_value = '';
2997 if ($el.parents('[data-rule-key]').find('input:checked').not('[data-ignore-rule]').length > 1) {
2998 $el.parents('[data-rule-key]').find('input:checked').not('[data-ignore-rule]').each(function() {
2999 current_value = current_value + jQuery(this).val() + ' ';
3000 });
3001 } else {
3002 if ($el.parents('[data-rule-key]').find('input:checked').not('[data-ignore-rule]').length >= 1) {
3003 current_value = $el.parents('[data-rule-key]').find('input:checked').not('[data-ignore-rule]').val();
3004 }
3005 }
3006 }
3007
3008 if ($el.is(':radio')) {
3009 current_value = $el.parents('[data-rule-key]').find('input[type=radio]:checked').not('[data-ignore-rule]').val();
3010 }
3011
3012 return current_value;
3013 }
3014
3015 /**
3016 * Get the field default value.
3017 */
3018 function aui_cf_field_get_default_value($el) {
3019 var value = '', type = aui_cf_field_get_type($el);
3020
3021 switch (type) {
3022 case 'text':
3023 case 'number':
3024 case 'date':
3025 case 'textarea':
3026 case 'select':
3027 value = $el.find('input:text,input[type="number"],textarea,select').not('[data-ignore-rule]').val();
3028 break;
3029 case 'phone':
3030 case 'email':
3031 case 'color':
3032 case 'url':
3033 case 'hidden':
3034 case 'password':
3035 case 'file':
3036 value = $el.find('input[type="' + type + '"]').not('[data-ignore-rule]').val();
3037 break;
3038 case 'multiselect':
3039 value = $el.find('select').not('[data-ignore-rule]').val();
3040 break;
3041 case 'radio':
3042 if ($el.find('input[type="radio"]:checked').not('[data-ignore-rule]').length >= 1) {
3043 value = $el.find('input[type="radio"]:checked').not('[data-ignore-rule]').val();
3044 }
3045 break;
3046 case 'checkbox':
3047 if ($el.find('input[type="checkbox"]:checked').not('[data-ignore-rule]').length >= 1) {
3048 if ($el.find('input[type="checkbox"]:checked').not('[data-ignore-rule]').length > 1) {
3049 var values = [];
3050 values.push(value);
3051 $el.find('input[type="checkbox"]:checked').not('[data-ignore-rule]').each(function() {
3052 values.push(jQuery(this).val());
3053 });
3054 value = values;
3055 } else {
3056 value = $el.find('input[type="checkbox"]:checked').not('[data-ignore-rule]').val();
3057 }
3058 }
3059 break;
3060 default:
3061 if (window._aui_cf_field_default_values && typeof window._aui_cf_field_default_values == 'object' && typeof window._aui_cf_field_default_values[type] != 'undefined') {
3062 value = window._aui_cf_field_default_values[type];
3063 }
3064 break;
3065 }
3066 return {
3067 type: type,
3068 value: value
3069 };
3070 }
3071
3072 /**
3073 * Reset field default value.
3074 */
3075 function aui_cf_field_reset_default_value($el, bHide, setVal) {
3076 if (!($el && $el.length)) {
3077 return;
3078 }
3079 var type = aui_cf_field_get_type($el), key = $el.data('rule-key'), field = aui_cf_field_default_values[key];
3080 if (typeof setVal === 'undefined' || (typeof setVal !== 'undefined' && setVal === null)) {
3081 setVal = field.value;
3082 }
3083
3084 switch (type) {
3085 case 'text':
3086 case 'number':
3087 case 'date':
3088 case 'textarea':
3089 $el.find('input:text,input[type="number"],textarea').not('[data-ignore-rule]').val(setVal);
3090 break;
3091 case 'phone':
3092 case 'email':
3093 case 'color':
3094 case 'url':
3095 case 'hidden':
3096 case 'password':
3097 case 'file':
3098 $el.find('input[type="' + type + '"]:not("[data-ignore-rule]")').val(setVal);
3099 break;
3100 case 'select':
3101 var $elSelect = $el.find('select').not('[data-ignore-rule]');
3102 $elSelect.find('option').prop('selected', false);
3103 $elSelect.val(setVal);
3104 $elSelect.trigger('change');
3105 break;
3106 case 'multiselect':
3107 var $elSelect = $el.find('select').not('[data-ignore-rule]');
3108 $elSelect.find('option').prop('selected', false);
3109 if ((typeof setVal === 'object' || typeof setVal === 'array') && !setVal.length && $elSelect.find('option:first').text() == '') {
3110 $elSelect.find('option:first').remove(); // Clear first option to show placeholder.
3111 }
3112 if (typeof setVal === 'string') {
3113 $elSelect.val(setVal);
3114 } else {
3115 jQuery.each(setVal, function(i, v) {
3116 $elSelect.find('option[value="' + v + '"]').prop('selected', true);
3117 });
3118 }
3119 $elSelect.trigger('change');
3120 break;
3121 case 'checkbox':
3122 if ($el.find('input[type="checkbox"]:checked').not('[data-ignore-rule]').length >= 1) {
3123 $el.find('input[type="checkbox"]:checked').not('[data-ignore-rule]').prop('checked', false).removeAttr('checked');
3124 }
3125 if (Array.isArray(setVal)) {
3126 jQuery.each(setVal, function(i, v) {
3127 $el.find('input[type="checkbox"][value="' + v + '"]').not('[data-ignore-rule]').prop('checked', true);
3128 });
3129 } else {
3130 $el.find('input[type="checkbox"][value="' + setVal + '"]').not('[data-ignore-rule]').prop('checked', true);
3131 }
3132 break;
3133 case 'radio':
3134 setTimeout(function() {
3135 if ($el.find('input[type="radio"]:checked').not('[data-ignore-rule]').length >= 1) {
3136 $el.find('input[type="radio"]:checked').not('[data-ignore-rule]').prop('checked', false).removeAttr('checked');
3137 }
3138 $el.find('input[type="radio"][value="' + setVal + '"]').not('[data-ignore-rule]').prop('checked', true);
3139 }, 100);
3140 break;
3141 default:
3142 jQuery(document.body).trigger('aui_cf_field_reset_default_value', type, $el, field);
3143 break;
3144 }
3145
3146 if (!$el.hasClass('aui-cf-field-has-changed')) {
3147 var el = aui_cf_field_get_element($el);
3148 if (type === 'radio' || type === 'checkbox') {
3149 el = el.find(':checked');
3150 }
3151 if (el) {
3152 el.trigger('change');
3153 $el.addClass('aui-cf-field-has-changed');
3154 }
3155 }
3156 }
3157
3158 /**
3159 * Get the field children.
3160 */
3161 function aui_cf_field_get_children(field_key) {
3162 var rules = [];
3163 jQuery.each(aui_cf_field_rules, function(j, rule) {
3164 if (rule.field.field === field_key) {
3165 rules.push(rule.field.rule);
3166 }
3167 });
3168 return rules;
3169 }
3170
3171 /**
3172 * Check in array field value.
3173 */
3174 function aui_cf_field_in_array(find, item, exact, match) {
3175 var found = false, key;
3176 exact = !!exact;
3177
3178 for (key in item) {
3179 if ((exact && item[key] === find) || (!exact && item[key] == find) || (match && (typeof find === 'string' || typeof find === 'number') && (typeof item[key] === 'string' || typeof item[key] === 'number') && find.length && find.indexOf(item[key]) >= 0)) {
3180 found = true;
3181 break;
3182 }
3183 }
3184 return found;
3185 }
3186
3187 /**
3188 * App the field condition action.
3189 */
3190 function aui_cf_field_apply_action($el, rule, isTrue) {
3191 var $destEl = jQuery('[data-rule-key="' + rule.key + '"]'), $inputEl = (rule.key && $destEl.find('[name="' + rule.key + '"]').length) ? $destEl.find('[name="' + rule.key + '"]') : null;
3192
3193 if (rule.action === 'show' && isTrue) {
3194 if ($destEl.is(':hidden') && !($destEl.hasClass('aui-cf-skip-reset') || ($inputEl && $inputEl.hasClass('aui-cf-skip-reset')))) {
3195 aui_cf_field_reset_default_value($destEl);
3196 }
3197 aui_cf_field_show_element($destEl);
3198 } else if (rule.action === 'show' && !isTrue) {
3199 if ((!$destEl.is(':hidden') || ($destEl.is(':hidden') && ($destEl.hasClass('aui-cf-force-reset') || ($inputEl && $inputEl.hasClass('aui-cf-skip-reset')) || ($destEl.closest('.aui-cf-use-parent').length && $destEl.closest('.aui-cf-use-parent').is(':hidden'))))) && !($destEl.hasClass('aui-cf-skip-reset') || ($inputEl && $inputEl.hasClass('aui-cf-skip-reset')))) {
3200 var _setVal = $destEl.hasClass('aui-cf-force-empty') || ($inputEl && $inputEl.hasClass('aui-cf-force-empty')) ? '' : null;
3201 aui_cf_field_reset_default_value($destEl, true, _setVal);
3202 }
3203 aui_cf_field_hide_element($destEl);
3204 } else if (rule.action === 'hide' && isTrue) {
3205 if ((!$destEl.is(':hidden') || ($destEl.is(':hidden') && ($destEl.hasClass('aui-cf-force-reset') || ($inputEl && $inputEl.hasClass('aui-cf-skip-reset')) || ($destEl.closest('.aui-cf-use-parent').length && $destEl.closest('.aui-cf-use-parent').is(':hidden'))))) && !($destEl.hasClass('aui-cf-skip-reset') || ($inputEl && $inputEl.hasClass('aui-cf-skip-reset')))) {
3206 var _setVal = $destEl.hasClass('aui-cf-force-empty') || ($inputEl && $inputEl.hasClass('aui-cf-force-empty')) ? '' : null;
3207 aui_cf_field_reset_default_value($destEl, true, _setVal);
3208 }
3209 aui_cf_field_hide_element($destEl);
3210 } else if (rule.action === 'hide' && !isTrue) {
3211 if ($destEl.is(':hidden') && !($destEl.hasClass('aui-cf-skip-reset') || ($inputEl && $inputEl.hasClass('aui-cf-skip-reset')))) {
3212 aui_cf_field_reset_default_value($destEl);
3213 }
3214 aui_cf_field_show_element($destEl);
3215 }
3216 return $el.removeClass('aui-cf-field-has-changed');
3217 }
3218
3219 /**
3220 * Show field element.
3221 */
3222 function aui_cf_field_show_element($el) {
3223 $el.removeClass('d-none').show();
3224
3225 $el.find('.aui-cf-req').each(function() {
3226 if (jQuery(this).data('rule-req')) {
3227 jQuery(this).removeAttr('required').prop('required', true);
3228 }
3229 if (jQuery(this).data('rule-oninvalid')) {
3230 jQuery(this).removeAttr('oninvalid').attr('oninvalid', jQuery(this).data('rule-oninvalid'));
3231 }
3232 });
3233
3234 if (window && window.navigator.userAgent.indexOf("MSIE") !== -1) {
3235 $el.css({
3236 "visibility": "visible"
3237 });
3238 }
3239 }
3240
3241 /**
3242 * Hide field element.
3243 */
3244 function aui_cf_field_hide_element($el) {
3245 $el.addClass('d-none').hide();
3246
3247 $el.find('.aui-cf-req').each(function() {
3248 if (jQuery(this).data('rule-req')) {
3249 jQuery(this).removeAttr('required');
3250 }
3251 if (jQuery(this).data('rule-oninvalid')) {
3252 jQuery(this).removeAttr('oninvalid');
3253 }
3254 });
3255
3256 if (window && window.navigator.userAgent.indexOf("MSIE") !== -1) {
3257 $el.css({
3258 "visibility": "hidden"
3259 });
3260 }
3261 }
3262 <?php do_action( 'aui_conditional_fields_js', $this ); ?>
3263 </script>
3264 <?php
3265 $output = ob_get_clean();
3266
3267 return str_replace( array( '<script>', '</script>' ), '', self::minify_js( $output ) );
3268 }
3269
3270 /**
3271 * Check if block editor page.
3272 *
3273 * @since 0.2.27
3274 *
3275 * @return bool
3276 */
3277 public static function is_block_editor() {
3278 if ( is_admin() ) {
3279 $current_screen = function_exists( 'get_current_screen' ) ? get_current_screen() : array();
3280
3281 if ( ! empty( $current_screen ) && $current_screen->is_block_editor() ) {
3282 return true;
3283 }
3284 }
3285
3286 return false;
3287 }
3288
3289 /**
3290 * Checks if the current call is a ajax call to get the block content.
3291 *
3292 * This can be used in your widget to return different content as the block content.
3293 *
3294 * @since 0.2.27
3295 *
3296 * @return bool
3297 */
3298 public static function is_block_content_call() {
3299 $result = false;
3300 if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) {
3301 $result = true;
3302 }
3303
3304 return $result;
3305 }
3306
3307 /**
3308 * Tests if the current output is inside a Divi preview.
3309 *
3310 * @since 0.2.27
3311 *
3312 * @return bool
3313 */
3314 public static function is_divi_preview() {
3315 $result = false;
3316 if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) {
3317 $result = true;
3318 }
3319
3320 return $result;
3321 }
3322
3323 /**
3324 * Tests if the current output is inside a elementor preview.
3325 *
3326 *
3327 * @since 0.2.27
3328 *
3329 * @return bool
3330 */
3331 public static function is_elementor_preview() {
3332 $result = false;
3333 if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) {
3334 $result = true;
3335 }
3336
3337 return $result;
3338 }
3339
3340 /**
3341 * Tests if the current output is inside a Beaver builder preview.
3342 *
3343 * @since 0.2.27
3344 *
3345 * @return bool
3346 */
3347 public static function is_beaver_preview() {
3348 $result = false;
3349 if ( isset( $_REQUEST['fl_builder'] ) ) {
3350 $result = true;
3351 }
3352
3353 return $result;
3354 }
3355
3356 /**
3357 * Tests if the current output is inside a siteorigin builder preview.
3358 *
3359 * @since 0.2.27
3360 *
3361 * @return bool
3362 */
3363 public static function is_siteorigin_preview() {
3364 $result = false;
3365 if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) {
3366 $result = true;
3367 }
3368
3369 return $result;
3370 }
3371
3372 /**
3373 * Tests if the current output is inside a cornerstone builder preview.
3374 *
3375 * @since 0.2.27
3376 *
3377 * @return bool
3378 */
3379 public static function is_cornerstone_preview() {
3380 $result = false;
3381 if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) {
3382 $result = true;
3383 }
3384
3385 return $result;
3386 }
3387
3388 /**
3389 * Tests if the current output is inside a fusion builder preview.
3390 *
3391 * @return bool
3392 *@since 1.1.0
3393 */
3394 public static function is_fusion_preview() {
3395 $result = false;
3396 if ( ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ) ) {
3397 $result = true;
3398 }
3399
3400 return $result;
3401 }
3402
3403 /**
3404 * Tests if the current output is inside a Oxygen builder preview.
3405 *
3406 * @return bool
3407 *@since 1.0.18
3408 */
3409 public static function is_oxygen_preview() {
3410 $result = false;
3411 if ( ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) ) ) {
3412 $result = true;
3413 }
3414
3415 return $result;
3416 }
3417
3418 /**
3419 * Check for Kallyas theme Zion builder preview.
3420 *
3421 * @since 0.2.27
3422 *
3423 * @return bool
3424 */
3425 public static function is_kallyas_zion_preview() {
3426 $result = false;
3427
3428 if ( function_exists( 'znhg_kallyas_theme_config' ) && ! empty( $_REQUEST['zn_pb_edit'] ) ) {
3429 $result = true;
3430 }
3431
3432 return $result;
3433 }
3434
3435 /**
3436 * Check for Bricks theme builder preview.
3437 *
3438 * @since 0.2.27
3439 *
3440 * @return bool
3441 */
3442 public static function is_bricks_preview() {
3443 $result = false;
3444
3445 if ( function_exists( 'bricks_is_builder' ) && ( bricks_is_builder() || bricks_is_builder_call() ) ) {
3446 $result = true;
3447 }
3448
3449 return $result;
3450 }
3451
3452 /**
3453 * Check for Breakdance builder preview.
3454 *
3455 * @since 0.2.42
3456 *
3457 * @return bool True when preview page otherwise false.
3458 */
3459 public static function is_breakdance_preview() {
3460 return ( \function_exists( 'Breakdance\\isRequestFromBuilderIframe' ) && ( \Breakdance\isRequestFromBuilderIframe() || \Breakdance\isRequestFromBuilderSsr() ) );
3461 }
3462
3463 /**
3464 * General function to check if we are in a preview situation.
3465 *
3466 * @since 0.2.27
3467 *
3468 * @return bool
3469 */
3470 public static function is_preview() {
3471 $preview = false;
3472
3473 if ( self::is_block_editor() ) {
3474 return true;
3475 }
3476
3477 if( self::is_block_content_call() ) {
3478 $preview = true;
3479 } elseif ( self::is_divi_preview() ) {
3480 $preview = true;
3481 } elseif ( self::is_elementor_preview() ) {
3482 $preview = true;
3483 } elseif ( self::is_beaver_preview() ) {
3484 $preview = true;
3485 } elseif ( self::is_siteorigin_preview() ) {
3486 $preview = true;
3487 } elseif ( self::is_cornerstone_preview() ) {
3488 $preview = true;
3489 } elseif ( self::is_fusion_preview() ) {
3490 $preview = true;
3491 } elseif ( self::is_oxygen_preview() ) {
3492 $preview = true;
3493 } elseif( self::is_kallyas_zion_preview() ) {
3494 $preview = true;
3495 } elseif( self::is_bricks_preview() ) {
3496 $preview = true;
3497 } elseif( self::is_breakdance_preview() ) {
3498 $preview = true;
3499 }
3500
3501 return $preview;
3502 }
3503 }
3504
3505 global $ayecode_ui_settings;
3506
3507 /**
3508 * Run the class if found.
3509 */
3510 $ayecode_ui_settings = AyeCode_UI_Settings::instance();
3511 }