Passed
Push — master ( 0a2366...999d0e )
by Stiofan
16:14
created

AyeCode_UI_Settings::get_settings()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 45
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 24
nc 8
nop 0
dl 0
loc 45
rs 8.9137
c 0
b 0
f 0
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.8';
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 ){
0 ignored issues
show
Unused Code introduced by
The parameter $include_outlines is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

137
		public function sd_aui_colors( $theme_colors, /** @scrutinizer ignore-unused */ $include_outlines, $include_branding ){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $include_branding is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

137
		public function sd_aui_colors( $theme_colors, $include_outlines, /** @scrutinizer ignore-unused */ $include_branding ){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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
			define( 'AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be" );
156
			define( 'AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d' );
157
			define( 'AUI_INFO_COLOR_ORIGINAL', '#17a2b8' );
158
			define( 'AUI_WARNING_COLOR_ORIGINAL', '#ffc107' );
159
			define( 'AUI_DANGER_COLOR_ORIGINAL', '#dc3545' );
160
			define( 'AUI_SUCCESS_COLOR_ORIGINAL', '#44c553' );
161
			define( 'AUI_LIGHT_COLOR_ORIGINAL', '#f8f9fa' );
162
			define( 'AUI_DARK_COLOR_ORIGINAL', '#343a40' );
163
			define( 'AUI_WHITE_COLOR_ORIGINAL', '#fff' );
164
			define( 'AUI_PURPLE_COLOR_ORIGINAL', '#ad6edd' );
165
			define( 'AUI_SALMON_COLOR_ORIGINAL', '#ff977a' );
166
			define( 'AUI_CYAN_COLOR_ORIGINAL', '#35bdff' );
167
			define( 'AUI_GRAY_COLOR_ORIGINAL', '#ced4da' );
168
			define( 'AUI_INDIGO_COLOR_ORIGINAL', '#502c6c' );
169
			define( 'AUI_ORANGE_COLOR_ORIGINAL', '#orange' );
170
			define( 'AUI_BLACK_COLOR_ORIGINAL', '#000' );
171
172
			if ( ! defined( 'AUI_PRIMARY_COLOR' ) ) {
173
				define( 'AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL );
174
			}
175
			if ( ! defined( 'AUI_SECONDARY_COLOR' ) ) {
176
				define( 'AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL );
177
			}
178
			if ( ! defined( 'AUI_INFO_COLOR' ) ) {
179
				define( 'AUI_INFO_COLOR', AUI_INFO_COLOR_ORIGINAL );
180
			}
181
			if ( ! defined( 'AUI_WARNING_COLOR' ) ) {
182
				define( 'AUI_WARNING_COLOR', AUI_WARNING_COLOR_ORIGINAL );
183
			}
184
			if ( ! defined( 'AUI_DANGER_COLOR' ) ) {
185
				define( 'AUI_DANGER_COLOR', AUI_DANGER_COLOR_ORIGINAL );
186
			}
187
			if ( ! defined( 'AUI_SUCCESS_COLOR' ) ) {
188
				define( 'AUI_SUCCESS_COLOR', AUI_SUCCESS_COLOR_ORIGINAL );
189
			}
190
			if ( ! defined( 'AUI_LIGHT_COLOR' ) ) {
191
				define( 'AUI_LIGHT_COLOR', AUI_LIGHT_COLOR_ORIGINAL );
192
			}
193
			if ( ! defined( 'AUI_DARK_COLOR' ) ) {
194
				define( 'AUI_DARK_COLOR', AUI_DARK_COLOR_ORIGINAL );
195
			}
196
			if ( ! defined( 'AUI_WHITE_COLOR' ) ) {
197
				define( 'AUI_WHITE_COLOR', AUI_WHITE_COLOR_ORIGINAL );
198
			}
199
			if ( ! defined( 'AUI_PURPLE_COLOR' ) ) {
200
				define( 'AUI_PURPLE_COLOR', AUI_PURPLE_COLOR_ORIGINAL );
201
			}
202
			if ( ! defined( 'AUI_SALMON_COLOR' ) ) {
203
				define( 'AUI_SALMON_COLOR', AUI_SALMON_COLOR_ORIGINAL );
204
			}
205
			if ( ! defined( 'AUI_CYAN_COLOR' ) ) {
206
				define( 'AUI_CYAN_COLOR', AUI_CYAN_COLOR_ORIGINAL );
207
			}
208
			if ( ! defined( 'AUI_GRAY_COLOR' ) ) {
209
				define( 'AUI_GRAY_COLOR', AUI_GRAY_COLOR_ORIGINAL );
210
			}
211
			if ( ! defined( 'AUI_INDIGO_COLOR' ) ) {
212
				define( 'AUI_INDIGO_COLOR', AUI_INDIGO_COLOR_ORIGINAL );
213
			}
214
			if ( ! defined( 'AUI_ORANGE_COLOR' ) ) {
215
				define( 'AUI_ORANGE_COLOR', AUI_ORANGE_COLOR_ORIGINAL );
216
			}
217
			if ( ! defined( 'AUI_BLACK_COLOR' ) ) {
218
				define( 'AUI_BLACK_COLOR', AUI_BLACK_COLOR_ORIGINAL );
219
			}
220
221
		}
222
223
		public static function get_colors( $original = false){
224
225
			if ( ! defined( 'AUI_PRIMARY_COLOR' ) ) {
226
				return array();
227
			}
228
			if ( $original ) {
229
				return array(
230
					'primary'   => AUI_PRIMARY_COLOR_ORIGINAL,
231
					'secondary' => AUI_SECONDARY_COLOR_ORIGINAL,
232
					'info'      => AUI_INFO_COLOR_ORIGINAL,
233
					'warning'   => AUI_WARNING_COLOR_ORIGINAL,
234
					'danger'    => AUI_DANGER_COLOR_ORIGINAL,
235
					'success'   => AUI_SUCCESS_COLOR_ORIGINAL,
236
					'light'     => AUI_LIGHT_COLOR_ORIGINAL,
237
					'dark'      => AUI_DARK_COLOR_ORIGINAL,
238
					'white'     => AUI_WHITE_COLOR_ORIGINAL,
239
					'purple'    => AUI_PURPLE_COLOR_ORIGINAL,
240
					'salmon'    => AUI_SALMON_COLOR_ORIGINAL,
241
					'cyan'      => AUI_CYAN_COLOR_ORIGINAL,
242
					'gray'      => AUI_GRAY_COLOR_ORIGINAL,
243
					'indigo'    => AUI_INDIGO_COLOR_ORIGINAL,
244
					'orange'    => AUI_ORANGE_COLOR_ORIGINAL,
245
					'black'     => AUI_BLACK_COLOR_ORIGINAL,
246
				);
247
			}
248
249
			return array(
250
				'primary'   => AUI_PRIMARY_COLOR,
251
				'secondary' => AUI_SECONDARY_COLOR,
252
				'info'      => AUI_INFO_COLOR,
253
				'warning'   => AUI_WARNING_COLOR,
254
				'danger'    => AUI_DANGER_COLOR,
255
				'success'   => AUI_SUCCESS_COLOR,
256
				'light'     => AUI_LIGHT_COLOR,
257
				'dark'      => AUI_DARK_COLOR,
258
				'white'     => AUI_WHITE_COLOR,
259
				'purple'    => AUI_PURPLE_COLOR,
260
				'salmon'    => AUI_SALMON_COLOR,
261
				'cyan'      => AUI_CYAN_COLOR,
262
				'gray'      => AUI_GRAY_COLOR,
263
				'indigo'    => AUI_INDIGO_COLOR,
264
				'orange'    => AUI_ORANGE_COLOR,
265
				'black'     => AUI_BLACK_COLOR,
266
			);
267
		}
268
269
		/**
270
		 * Add admin body class to show when BS5 is active.
271
		 *
272
		 * @param $classes
273
		 *
274
		 * @return mixed
275
		 */
276
		public function add_bs5_admin_body_class( $classes = '' ) {
277
			$classes .= ' aui_bs5';
278
279
			return $classes;
280
		}
281
282
		/**
283
		 * Add a body class to show when BS5 is active.
284
		 *
285
		 * @param $classes
286
		 *
287
		 * @return mixed
288
		 */
289
		public function add_bs5_body_class( $classes ) {
290
			$classes[] = 'aui_bs5';
291
292
			return $classes;
293
		}
294
295
		/**
296
		 * Initiate the settings and add the required action hooks.
297
		 */
298
		public function init() {
299
            global $aui_bs5;
300
301
			// Maybe fix settings
302
			if ( ! empty( $_REQUEST['aui-fix-admin'] ) && !empty($_REQUEST['nonce']) && wp_verify_nonce( $_REQUEST['nonce'], "aui-fix-admin" ) ) {
303
				$db_settings = get_option( 'ayecode-ui-settings' );
304
				if ( ! empty( $db_settings ) ) {
305
					$db_settings['css_backend'] = 'compatibility';
306
					$db_settings['js_backend'] = 'core-popper';
307
					update_option( 'ayecode-ui-settings', $db_settings );
308
					wp_safe_redirect(admin_url("options-general.php?page=ayecode-ui-settings&updated=true"));
309
				}
310
			}
311
312
			$this->constants();
313
			$this->settings = $this->get_settings();
314
			$this->url = $this->get_url();
315
316
            // define the version
317
			$aui_bs5 = $this->settings['bs_ver'] === '5';
318
319
			if ( $aui_bs5 ) {
320
				include_once( dirname( __FILE__ ) . '/inc/bs-conversion.php' );
321
				add_filter( 'admin_body_class', array( $this, 'add_bs5_admin_body_class' ), 99, 1 );
322
				add_filter( 'body_class', array( $this, 'add_bs5_body_class' ) );
323
			}
324
325
			/**
326
			 * Maybe load CSS
327
			 *
328
			 * We load super early in case there is a theme version that might change the colors
329
			 */
330
			if ( $this->settings['css'] ) {
331
				$priority = $this->is_bs3_compat() ? 100 : 1;
332
                $priority = $aui_bs5 ? 10 : $priority;
333
				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), $priority );
334
			}
335
			if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) {
336
				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
337
			}
338
339
			// maybe load JS
340
			if ( $this->settings['js'] ) {
341
				$priority = $this->is_bs3_compat() ? 100 : 1;
342
				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority );
343
			}
344
			if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) {
345
				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 );
346
			}
347
348
			// Maybe set the HTML font size
349
			if ( $this->settings['html_font_size'] ) {
350
				add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 );
351
			}
352
353
			// Maybe show backend style error
354
			if( $this->settings['css_backend'] != 'compatibility' || $this->settings['js_backend'] != 'core-popper' ){
355
				add_action( 'admin_notices', array( $this, 'show_admin_style_notice' ) );
356
			}
357
358
		}
359
360
		/**
361
		 * Show admin notice if backend scripts not loaded.
362
		 */
363
		public function show_admin_style_notice(){
364
			$fix_url = admin_url("options-general.php?page=ayecode-ui-settings&aui-fix-admin=true&nonce=".wp_create_nonce('aui-fix-admin'));
365
			$button = '<a href="'.esc_url($fix_url).'" class="button-primary">Fix Now</a>';
366
			$message = __( '<b>Style Issue:</b> AyeCode UI is disable or set wrong.')." " .$button;
367
			echo '<div class="notice notice-error aui-settings-error-notice"><p>'.$message.'</p></div>';
368
		}
369
370
		/**
371
		 * Check if we should load the admin scripts or not.
372
		 *
373
		 * @return bool
374
		 */
375
		public function load_admin_scripts(){
376
			$result = true;
377
378
			// check if specifically disabled
379
			if(!empty($this->settings['disable_admin'])){
380
				$url_parts = explode("\n",$this->settings['disable_admin']);
381
				foreach($url_parts as $part){
382
					if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){
383
						return false; // return early, no point checking further
384
					}
385
				}
386
			}
387
388
			return $result;
389
		}
390
391
		/**
392
		 * Add a html font size to the footer.
393
		 */
394
		public function html_font_size(){
395
			$this->settings = $this->get_settings();
396
			echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>";
397
		}
398
399
		/**
400
		 * Check if the current admin screen should load scripts.
401
		 *
402
		 * @return bool
403
		 */
404
		public function is_aui_screen(){
405
//			echo '###';exit;
406
			$load = false;
407
			// check if we should load or not
408
			if ( is_admin() ) {
409
				// Only enable on set pages
410
				$aui_screens = array(
411
					'page',
412
                    //'docs',
413
					'post',
414
					'settings_page_ayecode-ui-settings',
415
					'appearance_page_gutenberg-widgets',
416
					'widgets',
417
					'ayecode-ui-settings',
418
					'site-editor'
419
				);
420
				$screen_ids = apply_filters( 'aui_screen_ids', $aui_screens );
421
422
				$screen = get_current_screen();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $screen is correct as get_current_screen() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
423
424
//				echo '###'.$screen->id;
425
426
				// check if we are on a AUI screen
427
				if ( $screen && in_array( $screen->id, $screen_ids ) ) {
0 ignored issues
show
introduced by
$screen is of type null, thus it always evaluated to false.
Loading history...
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
438
439
			return apply_filters( 'aui_load_on_admin' , $load );
440
		}
441
442
		/**
443
		 * Check if the current theme is a block theme.
444
		 *
445
		 * @return bool
446
		 */
447
		public static function is_block_theme() {
448
			if ( function_exists( 'wp_is_block_theme' && wp_is_block_theme() ) ) {
0 ignored issues
show
Bug introduced by
'wp_is_block_theme' && wp_is_block_theme() of type boolean is incompatible with the type string expected by parameter $function of function_exists(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

448
			if ( function_exists( /** @scrutinizer ignore-type */ 'wp_is_block_theme' && wp_is_block_theme() ) ) {
Loading history...
449
				return true;
450
			}
451
452
			return false;
453
		}
454
455
		/**
456
		 * Adds the styles.
457
		 */
458
		public function enqueue_style() {
459
            global $aui_bs5;
460
461
            $load_fse = false;
462
463
			if( is_admin() && !$this->is_aui_screen()){
464
				// don't add wp-admin scripts if not requested to
465
			}else{
466
				$css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend';
467
468
				$rtl = is_rtl() && ! $aui_bs5 ? '-rtl' : '';
469
470
                $bs_ver = $this->settings['bs_ver'] == '5' ? '-v5' : '';
471
472
				if($this->settings[$css_setting]){
473
					$compatibility = $this->settings[$css_setting]=='core' ? false : true;
474
					$url = $this->settings[$css_setting]=='core' ? $this->url.'assets'.$bs_ver.'/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets'.$bs_ver.'/css/ayecode-ui-compatibility'.$rtl.'.css';
475
476
477
478
					wp_register_style( 'ayecode-ui', $url, array(), $this->version );
479
					wp_enqueue_style( 'ayecode-ui' );
480
481
					$current_screen = function_exists('get_current_screen' ) ? get_current_screen() : '';
0 ignored issues
show
Bug introduced by
Are you sure the usage of get_current_screen() is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
482
483
//					if ( is_admin() && !empty($_REQUEST['postType']) ) {
484
					if ( is_admin() && ( !empty($_REQUEST['postType']) || $current_screen->is_block_editor() ) && ( defined( 'BLOCKSTRAP_VERSION' ) || defined( 'AUI_FSE' ) )  ) {
0 ignored issues
show
Bug introduced by
The method is_block_editor() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

484
					if ( is_admin() && ( !empty($_REQUEST['postType']) || $current_screen->/** @scrutinizer ignore-call */ is_block_editor() ) && ( defined( 'BLOCKSTRAP_VERSION' ) || defined( 'AUI_FSE' ) )  ) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
485
						$url = $this->url.'assets'.$bs_ver.'/css/ayecode-ui-fse.css';
486
						wp_register_style( 'ayecode-ui-fse', $url, array(), $this->version );
487
						wp_enqueue_style( 'ayecode-ui-fse' );
488
						$load_fse = true;
489
					}
490
491
492
					// flatpickr
493
					wp_register_style( 'flatpickr', $this->url.'assets'.$bs_ver.'/css/flatpickr.min.css', array(), $this->version );
494
495
					// fix some wp-admin issues
496
					if(is_admin()){
497
						$custom_css = "
498
                body{
499
                    background-color: #f1f1f1;
500
                    font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif;
501
                    font-size:13px;
502
                }
503
                a {
504
				    color: #0073aa;
505
				    text-decoration: underline;
506
				}
507
                label {
508
				    display: initial;
509
				    margin-bottom: 0;
510
				}
511
				input, select {
512
				    margin: 1px;
513
				    line-height: initial;
514
				}
515
				th, td, div, h2 {
516
				    box-sizing: content-box;
517
				}
518
				h1, h2, h3, h4, h5, h6 {
519
				    display: block;
520
				    font-weight: 600;
521
				}
522
				h2,h3 {
523
				    font-size: 1.3em;
524
				    margin: 1em 0
525
				}
526
				.blocks-widgets-container .bsui *{
527
					box-sizing: border-box;
528
				}
529
				.bs-tooltip-top .arrow{
530
					margin-left:0px;
531
				}
532
				
533
				.custom-switch input[type=checkbox]{
534
				    display:none;
535
				}
536
                ";
537
538
						// @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377
539
						$custom_css .= "
540
						.edit-post-sidebar input[type=color].components-text-control__input{
541
						    padding: 0;
542
						}
543
					";
544
						wp_add_inline_style( 'ayecode-ui', $custom_css );
545
					}
546
547
					// custom changes
548
					if ( $load_fse ) {
549
						wp_add_inline_style( 'ayecode-ui-fse', self::custom_css($compatibility) );
550
					}else{
551
						wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) );
552
553
					}
554
555
				}
556
			}
557
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();
0 ignored issues
show
Unused Code introduced by
The assignment to $flatpickr_locale is dead and can be removed.
Loading history...
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
643
			if( is_admin() && !$this->is_aui_screen()){
644
				// don't add wp-admin scripts if not requested to
645
			}else {
646
647
				$js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend';
648
649
				$bs_ver = $this->settings['bs_ver'] == '5' ? '-v5' : '';
650
651
				// select2
652
				wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version );
653
654
				// flatpickr
655
				wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->version );
656
657
				// iconpicker
658
				if ( defined( 'FAS_ICONPICKER_JS_URL' ) ) {
659
					wp_register_script( 'iconpicker', FAS_ICONPICKER_JS_URL, array(), $this->version );
660
				}else{
661
					wp_register_script( 'iconpicker', $this->url . 'assets/js/fa-iconpicker.min.js', array(), $this->version );
662
				}
663
664
				// Bootstrap file browser
665
				wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version );
666
				wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() );
667
668
				$load_inline = false;
669
670
				if ( $this->settings[ $js_setting ] == 'core-popper' ) {
671
					// Bootstrap bundle
672
					$url = $this->url . 'assets' . $bs_ver . '/js/bootstrap.bundle.min.js';
673
					wp_register_script( 'bootstrap-js-bundle', $url, array(
674
						'select2',
675
						'jquery'
676
					), $this->version, $this->is_bs3_compat() );
677
					// if in admin then add to footer for compatibility.
678
					is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' );
679
					$script = $this->inline_script();
680
					wp_add_inline_script( 'bootstrap-js-bundle', $script );
681
				} elseif ( $this->settings[ $js_setting ] == 'popper' ) {
682
					$url = $this->url . 'assets/js/popper.min.js'; //@todo we need to update this to bs5
683
					wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->version );
684
					wp_enqueue_script( 'bootstrap-js-popper' );
685
					$load_inline = true;
686
				} else {
687
					$load_inline = true;
688
				}
689
690
				// Load needed inline scripts by faking the loading of a script if the main script is not being loaded
691
				if ( $load_inline ) {
692
					wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) );
693
					wp_enqueue_script( 'bootstrap-dummy' );
694
					$script = $this->inline_script();
695
					wp_add_inline_script( 'bootstrap-dummy', $script );
696
				}
697
			}
698
699
		}
700
701
		/**
702
		 * Enqueue flatpickr if called.
703
		 */
704
		public function enqueue_flatpickr(){
705
			wp_enqueue_style( 'flatpickr' );
706
			wp_enqueue_script( 'flatpickr' );
707
		}
708
709
		/**
710
		 * Enqueue iconpicker if called.
711
		 */
712
		public function enqueue_iconpicker(){
713
			wp_enqueue_style( 'iconpicker' );
714
			wp_enqueue_script( 'iconpicker' );
715
		}
716
717
		/**
718
		 * Get the url path to the current folder.
719
		 *
720
		 * @return string
721
		 */
722
		public function get_url() {
723
			$content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) );
724
			$content_url = untrailingslashit( WP_CONTENT_URL );
725
726
			// Replace http:// to https://.
727
			if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) {
728
				$content_url = str_replace( 'http://', 'https://', $content_url );
729
			}
730
731
			// Check if we are inside a plugin
732
			$file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) );
733
			$url = str_replace( $content_dir, $content_url, $file_dir );
734
735
			return trailingslashit( $url );
736
		}
737
738
		/**
739
		 * Get the url path to the current folder.
740
		 *
741
		 * @return string
742
		 */
743
		public function get_url_old() {
744
745
			$url = '';
746
			// check if we are inside a plugin
747
			$file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) );
748
749
			// add check in-case user has changed wp-content dir name.
750
			$wp_content_folder_name = basename(WP_CONTENT_DIR);
751
			$dir_parts = explode("/$wp_content_folder_name/",$file_dir);
752
			$url_parts = explode("/$wp_content_folder_name/",plugins_url());
753
754
			if(!empty($url_parts[0]) && !empty($dir_parts[1])){
755
				$url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] );
756
			}
757
758
			return $url;
759
		}
760
761
		/**
762
		 * Register the database settings with WordPress.
763
		 */
764
		public function register_settings() {
765
			register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' );
766
		}
767
768
		/**
769
		 * Add the WordPress settings menu item.
770
		 * @since 1.0.10 Calling function name direct will fail theme check so we don't.
771
		 */
772
		public function menu_item() {
773
			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
774
			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array(
775
				$this,
776
				'settings_page'
777
			) );
778
		}
779
780
		/**
781
		 * Get a list of themes and their default JS settings.
782
		 *
783
		 * @return array
784
		 */
785
		public function theme_js_settings(){
786
			return array(
787
				'ayetheme' => 'popper',
788
				'listimia' => 'required',
789
				'listimia_backend' => 'core-popper',
790
				//'avada'    => 'required', // removed as we now add compatibility
791
			);
792
		}
793
794
		/**
795
         * Get the date the site was installed.
796
         *
797
		 * @return false|string
798
		 */
799
        public function get_site_install_date() {
800
	        global $wpdb; // This gives you access to the WordPress database object
801
802
	        // Prepare the SQL query to get the oldest registration date
803
	        $query = "SELECT MIN(user_registered) AS oldest_registration_date FROM {$wpdb->users}";
804
805
	        // Execute the query
806
	        $date = $wpdb->get_var($query);
807
808
	        return $date ? $date : false;
809
        }
810
811
		/**
812
		 * Show admin notice if backend scripts not loaded.
813
		 */
814
		public function show_admin_version_notice(){
815
			$fix_url = admin_url("options-general.php?page=ayecode-ui-settings" );
816
			$button = '<a href="'.esc_url($fix_url).'" class="button-primary">View Settings</a>';
817
			$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;
818
			echo '<div class="notice notice-error aui-settings-error-notice"><p>'.$message.'</p></div>';
819
		}
820
821
		/**
822
		 * Get the current Font Awesome output settings.
823
		 *
824
		 * @return array The array of settings.
825
		 */
826
		public function get_settings() {
827
828
			$db_settings = get_option( 'ayecode-ui-settings' );
829
830
            // Maybe show default version notice
831
			$site_install_date = new DateTime( self::get_site_install_date() );
0 ignored issues
show
Bug Best Practice introduced by
The method AyeCode_UI_Settings::get_site_install_date() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

831
			$site_install_date = new DateTime( self::/** @scrutinizer ignore-call */ get_site_install_date() );
Loading history...
Bug introduced by
It seems like self::get_site_install_date() can also be of type false; however, parameter $datetime of DateTime::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

831
			$site_install_date = new DateTime( /** @scrutinizer ignore-type */ self::get_site_install_date() );
Loading history...
832
			$switch_over_date = new DateTime("2024-02-01");
833
			if ( empty( $db_settings ) && $site_install_date < $switch_over_date ) {
834
				add_action( 'admin_notices', array( $this, 'show_admin_version_notice' ) );
835
			}
836
837
			$js_default = 'core-popper';
838
			$js_default_backend = $js_default;
839
840
			// maybe set defaults (if no settings set)
841
			if(empty($db_settings)){
842
				$active_theme = strtolower( get_template() ); // active parent theme.
843
				$theme_js_settings = self::theme_js_settings();
0 ignored issues
show
Bug Best Practice introduced by
The method AyeCode_UI_Settings::theme_js_settings() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

843
				/** @scrutinizer ignore-call */ 
844
    $theme_js_settings = self::theme_js_settings();
Loading history...
844
				if(isset($theme_js_settings[$active_theme])){
845
					$js_default = $theme_js_settings[$active_theme];
846
					$js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default;
847
				}
848
			}
849
850
			/**
851
			 * Filter the default settings.
852
			 */
853
			$defaults = apply_filters( 'ayecode-ui-default-settings', array(
854
				'css'            => 'compatibility', // core, compatibility
855
				'js'             => $js_default, // js to load, core-popper, popper
856
				'html_font_size' => '16', // js to load, core-popper, popper
857
				'css_backend'    => 'compatibility', // core, compatibility
858
				'js_backend'     => $js_default_backend, // js to load, core-popper, popper
859
				'disable_admin'  => '', // URL snippets to disable loading on admin
860
                'bs_ver'         => '5', // The default bootstrap version to sue by default
861
			), $db_settings );
862
863
			$settings = wp_parse_args( $db_settings, $defaults );
864
865
			/**
866
			 * Filter the Bootstrap settings.
867
			 *
868
			 * @todo if we add this filer people might use it and then it defeats the purpose of this class :/
869
			 */
870
			return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults );
871
		}
872
873
874
		/**
875
		 * The settings page html output.
876
		 */
877
		public function settings_page() {
878
			if ( ! current_user_can( 'manage_options' ) ) {
879
				wp_die( __( 'You do not have sufficient permissions to access this page.', 'ayecode-connect' ) );
880
			}
881
            $overrides = apply_filters( 'ayecode-ui-settings', array(), array(), array() );
882
883
			?>
884
            <div class="wrap">
885
                <h1><?php echo $this->name; ?></h1>
886
                <p><?php echo apply_filters( 'ayecode-ui-settings-message', __("Here you can adjust settings if you are having compatibility issues.", 'ayecode-connect' ) );?></p>
887
                <form method="post" action="options.php">
888
					<?php
889
					settings_fields( 'ayecode-ui-settings' );
890
					do_settings_sections( 'ayecode-ui-settings' );
891
					?>
892
893
                    <h2><?php _e( 'BootStrap Version', 'ayecode-connect' ); ?></h2>
894
                    <p><?php echo 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>
895
	                <div class="bsui"><?php
896
	                if ( ! empty( $overrides ) ) {
897
		                echo aui()->alert(array(
898
			                'type'=> 'info',
899
			                'content'=> __("Some options are disabled as your current theme is overriding them.", 'ayecode-connect' )
900
		                ));
901
	                }
902
	                ?>
903
                    </div>
904
                    <table class="form-table wpbs-table-version-settings">
905
                        <tr valign="top">
906
                            <th scope="row"><label for="wpbs-css"><?php _e( 'Version', 'ayecode-connect' ); ?></label></th>
907
                            <td>
908
                                <select name="ayecode-ui-settings[bs_ver]" id="wpbs-css" <?php echo !empty($overrides['bs_ver']) ? 'disabled' : ''; ?>>
909
                                    <option	value="5" <?php selected( $this->settings['bs_ver'], '5' ); ?>><?php _e( 'v5 (recommended)', 'ayecode-connect' ); ?></option>
910
                                    <option value="4" <?php selected( $this->settings['bs_ver'], '4' ); ?>><?php _e( 'v4 (legacy)', 'ayecode-connect' ); ?></option>
911
                                </select>
912
                            </td>
913
                        </tr>
914
                    </table>
915
916
                    <h2><?php _e( 'Frontend', 'ayecode-connect' ); ?></h2>
917
                    <table class="form-table wpbs-table-settings">
918
                        <tr valign="top">
919
                            <th scope="row"><label for="wpbs-css"><?php _e( 'Load CSS', 'ayecode-connect' ); ?></label></th>
920
                            <td>
921
                                <select name="ayecode-ui-settings[css]" id="wpbs-css" <?php echo !empty($overrides['css']) ? 'disabled' : ''; ?>>
922
                                    <option	value="compatibility" <?php selected( $this->settings['css'], 'compatibility' ); ?>><?php _e( 'Compatibility Mode (default)', 'ayecode-connect' ); ?></option>
923
                                    <option value="core" <?php selected( $this->settings['css'], 'core' ); ?>><?php _e( 'Full Mode', 'ayecode-connect' ); ?></option>
924
                                    <option	value="" <?php selected( $this->settings['css'], '' ); ?>><?php _e( 'Disabled', 'ayecode-connect' ); ?></option>
925
                                </select>
926
                            </td>
927
                        </tr>
928
929
                        <tr valign="top">
930
                            <th scope="row"><label for="wpbs-js"><?php _e( 'Load JS', 'ayecode-connect' ); ?></label></th>
931
                            <td>
932
                                <select name="ayecode-ui-settings[js]" id="wpbs-js" <?php echo !empty($overrides['js']) ? 'disabled' : ''; ?>>
933
                                    <option	value="core-popper" <?php selected( $this->settings['js'], 'core-popper' ); ?>><?php _e( 'Core + Popper (default)', 'ayecode-connect' ); ?></option>
934
                                    <option value="popper" <?php selected( $this->settings['js'], 'popper' ); ?>><?php _e( 'Popper', 'ayecode-connect' ); ?></option>
935
                                    <option value="required" <?php selected( $this->settings['js'], 'required' ); ?>><?php _e( 'Required functions only', 'ayecode-connect' ); ?></option>
936
                                    <option	value="" <?php selected( $this->settings['js'], '' ); ?>><?php _e( 'Disabled (not recommended)', 'ayecode-connect' ); ?></option>
937
                                </select>
938
                            </td>
939
                        </tr>
940
941
                        <tr valign="top">
942
                            <th scope="row"><label for="wpbs-font_size"><?php _e( 'HTML Font Size (px)', 'ayecode-connect' ); ?></label></th>
943
                            <td>
944
                                <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' : ''; ?> />
945
                                <p class="description" ><?php _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>
946
                            </td>
947
                        </tr>
948
949
                    </table>
950
951
                    <h2><?php _e( 'Backend', 'ayecode-connect' ); ?> (wp-admin)</h2>
952
                    <table class="form-table wpbs-table-settings">
953
                        <tr valign="top">
954
                            <th scope="row"><label for="wpbs-css-admin"><?php _e( 'Load CSS', 'ayecode-connect' ); ?></label></th>
955
                            <td>
956
                                <select name="ayecode-ui-settings[css_backend]" id="wpbs-css-admin" <?php echo !empty($overrides['css_backend']) ? 'disabled' : ''; ?>>
957
                                    <option	value="compatibility" <?php selected( $this->settings['css_backend'], 'compatibility' ); ?>><?php _e( 'Compatibility Mode (default)', 'ayecode-connect' ); ?></option>
958
                                    <option value="core" <?php selected( $this->settings['css_backend'], 'core' ); ?>><?php _e( 'Full Mode (will cause style issues)', 'ayecode-connect' ); ?></option>
959
                                    <option	value="" <?php selected( $this->settings['css_backend'], '' ); ?>><?php _e( 'Disabled', 'ayecode-connect' ); ?></option>
960
                                </select>
961
                            </td>
962
                        </tr>
963
964
                        <tr valign="top">
965
                            <th scope="row"><label for="wpbs-js-admin"><?php _e( 'Load JS', 'ayecode-connect' ); ?></label></th>
966
                            <td>
967
                                <select name="ayecode-ui-settings[js_backend]" id="wpbs-js-admin" <?php echo !empty($overrides['js_backend']) ? 'disabled' : ''; ?>>
968
                                    <option	value="core-popper" <?php selected( $this->settings['js_backend'], 'core-popper' ); ?>><?php _e( 'Core + Popper (default)', 'ayecode-connect' ); ?></option>
969
                                    <option value="popper" <?php selected( $this->settings['js_backend'], 'popper' ); ?>><?php _e( 'Popper', 'ayecode-connect' ); ?></option>
970
                                    <option value="required" <?php selected( $this->settings['js_backend'], 'required' ); ?>><?php _e( 'Required functions only', 'ayecode-connect' ); ?></option>
971
                                    <option	value="" <?php selected( $this->settings['js_backend'], '' ); ?>><?php _e( 'Disabled (not recommended)', 'ayecode-connect' ); ?></option>
972
                                </select>
973
                            </td>
974
                        </tr>
975
976
                        <tr valign="top">
977
                            <th scope="row"><label for="wpbs-disable-admin"><?php _e( 'Disable load on URL', 'ayecode-connect' ); ?></label></th>
978
                            <td>
979
                                <p><?php _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>
980
                                <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 $this->settings['disable_admin'];?></textarea>
981
                            </td>
982
                        </tr>
983
                    </table>
984
985
					<?php
986
					submit_button();
987
					?>
988
                </form>
989
                <div id="wpbs-version" data-aui-source="<?php echo esc_attr( $this->get_load_source() ); ?>"><?php echo $this->version; ?></div>
990
            </div>
991
			<?php
992
		}
993
994
        public function get_load_source(){
995
	        $file = str_replace( array( "/", "\\" ), "/", realpath( __FILE__ ) );
996
	        $plugins_dir = str_replace( array( "/", "\\" ), "/", realpath( WP_PLUGIN_DIR ) );
997
998
	        // Find source plugin/theme of SD
999
	        $source = array();
1000
	        if ( strpos( $file, $plugins_dir ) !== false ) {
1001
		        $source = explode( "/", plugin_basename( $file ) );
1002
	        } else if ( function_exists( 'get_theme_root' ) ) {
1003
		        $themes_dir = str_replace( array( "/", "\\" ), "/", realpath( get_theme_root() ) );
1004
1005
		        if ( strpos( $file, $themes_dir ) !== false ) {
1006
			        $source = explode( "/", ltrim( str_replace( $themes_dir, "", $file ), "/" ) );
1007
		        }
1008
	        }
1009
1010
            return isset($source[0]) ? esc_attr($source[0]) : '';
1011
        }
1012
1013
		public function customizer_settings($wp_customize){
1014
			$wp_customize->add_section('aui_settings', array(
1015
				'title'    => __('AyeCode UI', 'ayecode-connect' ),
1016
				'priority' => 120,
1017
			));
1018
1019
			//  =============================
1020
			//  = Color Picker              =
1021
			//  =============================
1022
			$wp_customize->add_setting('aui_options[color_primary]', array(
1023
				'default'           => AUI_PRIMARY_COLOR,
1024
				'sanitize_callback' => 'sanitize_hex_color',
1025
				'capability'        => 'edit_theme_options',
1026
				'type'              => 'option',
1027
				'transport'         => 'refresh',
1028
			));
1029
			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array(
1030
				'label'    => __('Primary Color', 'ayecode-connect' ),
1031
				'section'  => 'aui_settings',
1032
				'settings' => 'aui_options[color_primary]',
1033
			)));
1034
1035
			$wp_customize->add_setting('aui_options[color_secondary]', array(
1036
				'default'           => '#6c757d',
1037
				'sanitize_callback' => 'sanitize_hex_color',
1038
				'capability'        => 'edit_theme_options',
1039
				'type'              => 'option',
1040
				'transport'         => 'refresh',
1041
			));
1042
			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array(
1043
				'label'    => __('Secondary Color', 'ayecode-connect' ),
1044
				'section'  => 'aui_settings',
1045
				'settings' => 'aui_options[color_secondary]',
1046
			)));
1047
		}
1048
1049
		/**
1050
		 * CSS to help with conflict issues with other plugins and themes using bootstrap v3.
1051
		 *
1052
		 * @return mixed
1053
		 */
1054
		public static function bs3_compat_css() {
1055
			ob_start();
1056
			?>
1057
            <style>
1058
                /* Bootstrap 3 compatibility */
1059
                body.modal-open .modal-backdrop.show:not(.in) {opacity:0.5;}
1060
                body.modal-open .modal.show:not(.in)  {opacity:1;z-index: 99999}
1061
                body.modal-open .modal.show:not(.in) .modal-content  {box-shadow: none;}
1062
                body.modal-open .modal.show:not(.in)  .modal-dialog {transform: initial;}
1063
1064
                body.modal-open .modal.bsui .modal-dialog{left: auto;}
1065
1066
                .collapse.show:not(.in){display: inherit;}
1067
                .fade.show{opacity: 1;}
1068
1069
                <?php if( defined( 'SVQ_THEME_VERSION' ) ){ ?>
1070
                /* KLEO theme specific */
1071
                .kleo-main-header .navbar-collapse.collapse.show:not(.in){display: block !important;}
1072
                <?php } ?>
1073
1074
                <?php if( defined( 'FUSION_BUILDER_VERSION' ) ){ ?>
1075
                /* With Avada builder */
1076
                body.modal-open .modal.in  {opacity:1;z-index: 99999}
1077
                body.modal-open .modal.bsui.in .modal-content  {box-shadow: none;}
1078
                .bsui .collapse.in{display: inherit;}
1079
                .bsui .collapse.in.row.show{display: flex;}
1080
                .bsui .collapse.in.row:not(.show){display: none;}
1081
1082
                <?php } ?>
1083
            </style>
1084
			<?php
1085
			return str_replace( array(
1086
				'<style>',
1087
				'</style>'
1088
			), '', self::minify_css( ob_get_clean() ) );
1089
		}
1090
1091
1092
		public static function custom_css($compatibility = true) {
1093
            global $aui_bs5;
1094
1095
			$colors = array();
1096
			if ( defined( 'BLOCKSTRAP_VERSION' ) ) {
1097
1098
1099
				$setting = wp_get_global_settings();
1100
1101
//                print_r(wp_get_global_styles());//exit;
1102
//                print_r(get_default_block_editor_settings());exit;
1103
1104
//                print_r($setting);echo  '###';exit;
1105
				if(!empty($setting['color']['palette']['theme'])){
1106
					foreach($setting['color']['palette']['theme'] as $color){
1107
						$colors[$color['slug']] = esc_attr($color['color']);
1108
					}
1109
				}
1110
1111
				if(!empty($setting['color']['palette']['custom'])){
1112
					foreach($setting['color']['palette']['custom'] as $color){
1113
						$colors[$color['slug']] = esc_attr($color['color']);
1114
					}
1115
				}
1116
			}else{
1117
				$settings = get_option('aui_options');
1118
				$colors = array(
1119
					'primary'   => ! empty( $settings['color_primary'] ) ? $settings['color_primary'] : AUI_PRIMARY_COLOR,
1120
					'secondary' => ! empty( $settings['color_secondary'] ) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR
1121
				);
1122
			}
1123
1124
			ob_start();
1125
1126
			?>
1127
            <style>
1128
                <?php
1129
1130
					// BS v3 compat
1131
					if( self::is_bs3_compat() ){
1132
						echo self::bs3_compat_css();
1133
					}
1134
1135
                    $current_screen = function_exists('get_current_screen' ) ? get_current_screen() : '';
0 ignored issues
show
Bug introduced by
Are you sure the usage of get_current_screen() is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1136
                    $is_fse = false;
1137
                    if ( is_admin() && ( !empty($_REQUEST['postType']) || $current_screen->is_block_editor() ) && ( defined( 'BLOCKSTRAP_VERSION' ) || defined( 'AUI_FSE' ) )  ) {
1138
                        $is_fse = true;
1139
                    }
1140
1141
					if(!empty($colors)){
1142
						$d_colors = self::get_colors(true);
1143
1144
//						$is_fse = !empty($_REQUEST['postType']) && $_REQUEST['postType']=='wp_template';
1145
						foreach($colors as $key => $color ){
1146
							if((empty( $d_colors[$key]) ||  $d_colors[$key] != $color) || $is_fse ) {
1147
								$var = $is_fse ? "var(--wp--preset--color--$key)" : $color;
1148
								$compat = $is_fse ? '.editor-styles-wrapper' : $compatibility;
1149
								echo $aui_bs5 ? self::css_overwrite_bs5($key,$var,$compat,$color) : self::css_overwrite($key,$var,$compat,$color);
1150
							}
1151
						}
1152
					   // exit;
1153
					}
1154
1155
					// Set admin bar z-index lower when modal is open.
1156
					echo ' body.modal-open #wpadminbar{z-index:999}.embed-responsive-16by9 .fluid-width-video-wrapper{padding:0 !important;position:initial}';
1157
1158
					if(is_admin()){
1159
						echo ' body.modal-open #adminmenuwrap{z-index:999} body.modal-open #wpadminbar{z-index:1025}';
1160
					}
1161
1162
                    if( $aui_bs5 && defined( 'BLOCKSTRAP_VERSION' )  ){
1163
                        $css = '';
1164
                        $theme_settings = wp_get_global_styles();
1165
1166
//                        print_r( $theme_settings);exit;
1167
1168
                        // font face
1169
                        if( !empty( $theme_settings['typography']['fontFamily'] ) ){
1170
                            $t_fontface = str_replace( array('var:preset|','font-family|'), array('--wp--preset--','font-family--'), $theme_settings['typography']['fontFamily']  ); //var(--wp--preset--font-family--poppins)
1171
                            $css .= '--bs-body-font-family: ' . esc_attr($t_fontface) . ';';
1172
                        }
1173
1174
                        // font size
1175
                        if( !empty( $theme_settings['typography']['fontSize'] ) ){
1176
                            $css .= '--bs-body-font-size: ' . esc_attr( $theme_settings['typography']['fontSize'] ) . ' ;';
1177
                        }
1178
1179
                        // line height
1180
                         if( !empty( $theme_settings['typography']['lineHeight'] ) ){
1181
                            $css .= '--bs-body-line-height: ' . esc_attr( $theme_settings['typography']['lineHeight'] ) . ';';
1182
                        }
1183
1184
1185
                           // font weight
1186
                         if( !empty( $theme_settings['typography']['fontWeight'] ) ){
1187
                            $css .= '--bs-body-font-weight: ' . esc_attr( $theme_settings['typography']['fontWeight'] ) . ';';
1188
                        }
1189
1190
                        // Background
1191
                         if( !empty( $theme_settings['color']['background'] ) ){
1192
                            $css .= '--bs-body-bg: ' . esc_attr( $theme_settings['color']['background'] ) . ';';
1193
                        }
1194
1195
                         // Background Gradient
1196
                         if( !empty( $theme_settings['color']['gradient'] ) ){
1197
                            $css .= 'background: ' . esc_attr( $theme_settings['color']['gradient'] ) . ';';
1198
                        }
1199
1200
                           // Background Gradient
1201
                         if( !empty( $theme_settings['color']['gradient'] ) ){
1202
                            $css .= 'background: ' . esc_attr( $theme_settings['color']['gradient'] ) . ';';
1203
                        }
1204
1205
                        // text color
1206
                        if( !empty( $theme_settings['color']['text'] ) ){
1207
                            $css .= '--bs-body-color: ' . esc_attr( $theme_settings['color']['text'] ) . ';';
1208
                        }
1209
1210
1211
                        // link colors
1212
                        if( !empty( $theme_settings['elements']['link']['color']['text'] ) ){
1213
                            $css .= '--bs-link-color: ' . esc_attr( $theme_settings['elements']['link']['color']['text'] ) . ';';
1214
                        }
1215
                        if( !empty( $theme_settings['elements']['link'][':hover']['color']['text'] ) ){
1216
                            $css .= '--bs-link-hover-color: ' . esc_attr( $theme_settings['elements']['link'][':hover']['color']['text'] ) . ';';
1217
                        }
1218
1219
1220
1221
                        if($css){
1222
                            echo  $is_fse ? 'body.editor-styles-wrapper{' . $css . '}' : 'body{' . $css . '}';
1223
                        }
1224
1225
                        $bep = $is_fse ? 'body.editor-styles-wrapper ' : '';
1226
1227
1228
                        // Headings
1229
                        $headings_css = '';
1230
                        if( !empty( $theme_settings['elements']['heading']['color']['text'] ) ){
1231
                            $headings_css .= "color: " . esc_attr( $theme_settings['elements']['heading']['color']['text'] ) . ";";
1232
                        }
1233
1234
                        // heading background
1235
                        if( !empty( $theme_settings['elements']['heading']['color']['background'] ) ){
1236
                            $headings_css .= 'background: ' . esc_attr( $theme_settings['elements']['heading']['color']['background'] ) . ';';
1237
                        }
1238
1239
                         // heading font family
1240
                        if( !empty( $theme_settings['elements']['heading']['typography']['fontFamily'] ) ){
1241
                            $headings_css .= 'font-family: ' . esc_attr( $theme_settings['elements']['heading']['typography']['fontFamily']  ) . ';';
1242
                        }
1243
1244
                        if( $headings_css ){
1245
                            echo "$bep h1,$bep h2,$bep h3, $bep h4,$bep h5,$bep h6{ " . $headings_css . "}";
1246
                        }
1247
1248
                        $hs = array('h1','h2','h3','h4','h5','h6');
1249
1250
                        foreach($hs as $hn){
1251
                            $h_css = '';
1252
                             if( !empty( $theme_settings['elements'][$hn]['color']['text'] ) ){
1253
                                $h_css .= 'color: ' . esc_attr( $theme_settings['elements'][$hn]['color']['text'] ) . ';';
1254
                             }
1255
1256
                              if( !empty( $theme_settings['elements'][$hn]['typography']['fontSize'] ) ){
1257
                                $h_css .= 'font-size: ' . esc_attr( $theme_settings['elements'][$hn]['typography']['fontSize']  ) . ';';
1258
                             }
1259
1260
                              if( !empty( $theme_settings['elements'][$hn]['typography']['fontFamily'] ) ){
1261
                                $h_css .= 'font-family: ' . esc_attr( $theme_settings['elements'][$hn]['typography']['fontFamily']  ) . ';';
1262
                             }
1263
1264
                             if($h_css){
1265
                                echo $bep . $hn . '{'.$h_css.'}';
1266
                             }
1267
                        }
1268
1269
//                        wp_mail('[email protected]','ss',print_r($_SERVER,true).'@@@');
1270
//                        print_r($_SERVER);exit;
1271
1272
1273
1274
1275
                    }
1276
				?>
1277
            </style>
1278
			<?php
1279
1280
1281
			/*
1282
			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1283
			 */
1284
			return str_replace( array(
1285
				'<style>',
1286
				'</style>'
1287
			), '', self::minify_css( ob_get_clean() ) );
1288
		}
1289
1290
1291
1292
		/**
1293
		 * Check if we should add booststrap 3 compatibility changes.
1294
		 *
1295
		 * @return bool
1296
		 */
1297
		public static function is_bs3_compat(){
1298
			return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION');
1299
		}
1300
1301
		public static function hex_to_rgb($hex) {
1302
			// Remove '#' if present
1303
			$hex = str_replace('#', '', $hex);
1304
1305
			// Convert 3-digit hex to 6-digit hex
1306
			if(strlen($hex) == 3) {
1307
				$hex = str_repeat(substr($hex, 0, 1), 2) . str_repeat(substr($hex, 1, 1), 2) . str_repeat(substr($hex, 2, 1), 2);
1308
			}
1309
1310
			// Convert hex to RGB
1311
			$r = hexdec(substr($hex, 0, 2));
1312
			$g = hexdec(substr($hex, 2, 2));
1313
			$b = hexdec(substr($hex, 4, 2));
1314
1315
			// Return RGB values as an array
1316
			return $r . ',' . $g . ',' . $b;
1317
		}
1318
1319
		/**
1320
		 * Build the CSS to overwrite a bootstrap color variable.
1321
		 *
1322
		 * @param $type
1323
		 * @param $color_code
1324
		 * @param $compatibility
1325
		 *
1326
		 * @return string
1327
		 */
1328
		public static function css_overwrite_bs5($type,$color_code,$compatibility, $hex = '' ){
1329
			global $aui_bs5;
1330
1331
			$is_var = false;
1332
			$is_custom = strpos($type, 'custom-') !== false ? true : false;
1333
			if(!$color_code){return '';}
1334
			if(strpos($color_code, 'var') !== false){
1335
				//if(!sanitize_hex_color($color_code)){
1336
				$color_code = esc_attr($color_code);
1337
				$is_var = true;
1338
//				$color_code = "rgba($color_code, 0.5)";
1339
//                echo '###1'.$color_code.'###';//exit;
1340
			}
1341
1342
//            echo '@@@'.$color_code.'==='.self::hex_to_rgb($color_code);exit;
1343
1344
			if(!$color_code){return '';}
1345
1346
			$rgb = self::hex_to_rgb($hex);
1347
1348
			if($compatibility===true || $compatibility===1){
1349
				$compatibility = '.bsui';
1350
			}elseif(!$compatibility){
1351
				$compatibility = '';
1352
			}else{
1353
				$compatibility = esc_attr($compatibility);
1354
			}
1355
1356
			$prefix = $compatibility ? $compatibility . " " : "";
1357
1358
1359
            $output = '';
1360
1361
//            echo '####'.$color_code;exit;
1362
1363
			$type = sanitize_html_class($type);
1364
1365
			/**
1366
			 * c = color, b = background color, o = border-color, f = fill
1367
			 */
1368
			$selectors = array(
1369
				".btn-{$type}"                                              => array( 'b', 'o' ),
1370
				".btn-{$type}.disabled"                                     => array( 'b', 'o' ),
1371
				".btn-{$type}:disabled"                                     => array( 'b', 'o' ),
1372
				".btn-outline-{$type}"                                      => array( 'c', 'o' ),
1373
				".btn-outline-{$type}:hover"                                => array( 'b', 'o' ),
1374
				".btn-outline-{$type}:not(:disabled):not(.disabled).active" => array( 'b', 'o' ),
1375
				".btn-outline-{$type}:not(:disabled):not(.disabled):active" => array( 'b', 'o' ),
1376
				".show>.btn-outline-{$type}.dropdown-toggle"                => array( 'b', 'o' ),
1377
				".badge-{$type}"                                            => array( 'b' ),
1378
				".alert-{$type}"                                            => array( 'b', 'o' ),
1379
				".bg-{$type}"                                               => array( 'b', 'f' ),
1380
				".btn-link.btn-{$type}"                                     => array( 'c' ),
1381
				".text-{$type}"                                     => array( 'c' ),
1382
			);
1383
1384
			if ( $aui_bs5 ) {
1385
				unset($selectors[".alert-{$type}" ]);
1386
			}
1387
1388
			if ( $type == 'primary' ) {
1389
				$selectors = $selectors + array(
1390
						'a'                                                                                                    => array( 'c' ),
1391
						'.btn-link'                                                                                            => array( 'c' ),
1392
						'.dropdown-item.active'                                                                                => array( 'b' ),
1393
						'.custom-control-input:checked~.custom-control-label::before'                                          => array(
1394
							'b',
1395
							'o'
1396
						),
1397
						'.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before'                   => array(
1398
							'b',
1399
							'o'
1400
						),
1401
						'.nav-pills .nav-link.active'                                                                          => array( 'b' ),
1402
						'.nav-pills .show>.nav-link'                                                                           => array( 'b' ),
1403
						'.page-link'                                                                                           => array( 'c' ),
1404
						'.page-item.active .page-link'                                                                         => array(
1405
							'b',
1406
							'o'
1407
						),
1408
						'.progress-bar'                                                                                        => array( 'b' ),
1409
						'.list-group-item.active'                                                                              => array(
1410
							'b',
1411
							'o'
1412
						),
1413
						'.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array( 'b' ),
1414
					);
1415
			}
1416
1417
1418
1419
            // link
1420
			if ( $type === 'primary' ) {
1421
				$output .= 'html body {--bs-link-hover-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .75); --bs-link-color: var(--bs-'.esc_attr($type).'); }';
1422
				$output .= $prefix . ' .breadcrumb{--bs-breadcrumb-item-active-color: '.esc_attr($color_code).';  }';
1423
				$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).'; }';
1424
1425
				$output .= $prefix . ' a{color: var(--bs-'.esc_attr($type).');}';
1426
				$output .= $prefix . ' .text-primary{color: var(--bs-'.esc_attr($type).') !important;}';
1427
1428
                // dropdown
1429
				$output .= $prefix . ' .dropdown-menu{--bs-dropdown-link-hover-color: var(--bs-'.esc_attr($type).'); --bs-dropdown-link-active-color: var(--bs-'.esc_attr($type).');}';
1430
1431
                // pagination
1432
				$output .= $prefix . ' .pagination{--bs-pagination-hover-color: var(--bs-'.esc_attr($type).'); --bs-pagination-active-bg: var(--bs-'.esc_attr($type).');}';
1433
1434
			}
1435
1436
			$output .= $prefix . ' .link-'.esc_attr($type).':hover {color: rgba(var(--bs-'.esc_attr($type).'-rgb), .8) !important;}';
1437
1438
			//  buttons
1439
			$output .= $prefix . ' .btn-'.esc_attr($type).'{';
1440
			$output .= ' 
1441
            --bs-btn-bg: '.esc_attr($color_code).';
1442
            --bs-btn-border-color: '.esc_attr($color_code).';
1443
            --bs-btn-hover-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1444
            --bs-btn-hover-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1445
            --bs-btn-focus-shadow-rgb: --bs-'.esc_attr($type).'-rgb;
1446
            --bs-btn-active-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1447
            --bs-btn-active-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1448
            --bs-btn-active-shadow: unset;
1449
            --bs-btn-disabled-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .5);
1450
            --bs-btn-disabled-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .1);
1451
            ';
1452
//			$output .= '
1453
//		    --bs-btn-color: #fff;
1454
//			--bs-btn-hover-color: #fff;
1455
//			--bs-btn-active-color: #fff;
1456
//			--bs-btn-disabled-color: #fff;
1457
//            ';
1458
			$output .= '}';
1459
1460
			//  buttons outline
1461
			$output .= $prefix . ' .btn-outline-'.esc_attr($type).'{';
1462
			$output .= ' 
1463
            --bs-btn-border-color: '.esc_attr($color_code).';
1464
            --bs-btn-hover-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1465
            --bs-btn-hover-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1466
            --bs-btn-focus-shadow-rgb: --bs-'.esc_attr($type).'-rgb;
1467
            --bs-btn-active-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1468
            --bs-btn-active-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1469
            --bs-btn-active-shadow: unset;
1470
            --bs-btn-disabled-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .5);
1471
            --bs-btn-disabled-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .1);
1472
            ';
1473
//			$output .= '
1474
//		    --bs-btn-color: #fff;
1475
//			--bs-btn-hover-color: #fff;
1476
//			--bs-btn-active-color: #fff;
1477
//			--bs-btn-disabled-color: #fff;
1478
//            ';
1479
			$output .= '}';
1480
1481
1482
            // button hover
1483
			$output .= $prefix . ' .btn-'.esc_attr($type).':hover{';
1484
			$output .= ' 
1485
            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);
1486
            }
1487
            ';
1488
1489
1490
			if ( $aui_bs5 ) {
1491
//				$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).'; }';
1492
				$output .= 'html body {--bs-'.esc_attr($type).': '.esc_attr($color_code).'; }';
1493
				$output .= 'html body {--bs-'.esc_attr($type).'-rgb: '.$rgb.'; }';
1494
			}
1495
1496
1497
			if ( $is_custom ) {
1498
1499
//				echo '###'.$type;exit;
1500
1501
				// build rules into each type
1502
				foreach($selectors as $selector => $types){
1503
					$selector = $compatibility ? $compatibility . " ".$selector : $selector;
1504
					$types = array_combine($types,$types);
1505
					if(isset($types['c'])){$color[] = $selector;}
1506
					if(isset($types['b'])){$background[] = $selector;}
1507
					if(isset($types['o'])){$border[] = $selector;}
1508
					if(isset($types['f'])){$fill[] = $selector;}
1509
				}
1510
1511
//				// build rules into each type
1512
//				foreach($important_selectors as $selector => $types){
1513
//					$selector = $compatibility ? $compatibility . " ".$selector : $selector;
1514
//					$types = array_combine($types,$types);
1515
//					if(isset($types['c'])){$color_i[] = $selector;}
1516
//					if(isset($types['b'])){$background_i[] = $selector;}
1517
//					if(isset($types['o'])){$border_i[] = $selector;}
1518
//					if(isset($types['f'])){$fill_i[] = $selector;}
1519
//				}
1520
1521
				// add any color rules
1522
				if(!empty($color)){
1523
					$output .= implode(",",$color) . "{color: $color_code;} ";
1524
				}
1525
				if(!empty($color_i)){
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $color_i does not exist. Did you maybe mean $color?
Loading history...
1526
					$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1527
				}
1528
1529
				// add any background color rules
1530
				if(!empty($background)){
1531
					$output .= implode(",",$background) . "{background-color: $color_code;} ";
1532
				}
1533
				if(!empty($background_i)){
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $background_i does not exist. Did you maybe mean $background?
Loading history...
1534
					$output .= $aui_bs5 ? '' : implode(",",$background_i) . "{background-color: $color_code !important;} ";
1535
//				$output .= implode(",",$background_i) . "{background-color: rgba(var(--bs-primary-rgb), var(--bs-bg-opacity)) !important;} ";
1536
				}
1537
1538
				// add any border color rules
1539
				if(!empty($border)){
1540
					$output .= implode(",",$border) . "{border-color: $color_code;} ";
1541
				}
1542
				if(!empty($border_i)){
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $border_i does not exist. Did you maybe mean $border?
Loading history...
1543
					$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1544
				}
1545
1546
				// add any fill color rules
1547
				if(!empty($fill)){
1548
					$output .= implode(",",$fill) . "{fill: $color_code;} ";
1549
				}
1550
				if(!empty($fill_i)){
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fill_i does not exist. Did you maybe mean $fill?
Loading history...
1551
					$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1552
				}
1553
1554
			}
1555
1556
1557
1558
1559
			$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;' : '';
1560
			// darken
1561
			$darker_075 = $is_var ? $color_code.';filter:brightness(0.925)' : self::css_hex_lighten_darken($color_code,"-0.075");
0 ignored issues
show
Bug introduced by
'-0.075' of type string is incompatible with the type double expected by parameter $adjustPercent of AyeCode_UI_Settings::css_hex_lighten_darken(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1561
			$darker_075 = $is_var ? $color_code.';filter:brightness(0.925)' : self::css_hex_lighten_darken($color_code,/** @scrutinizer ignore-type */ "-0.075");
Loading history...
1562
			$darker_10 = $is_var ? $color_code.';filter:brightness(0.9)' : self::css_hex_lighten_darken($color_code,"-0.10");
1563
			$darker_125 = $is_var ? $color_code.';filter:brightness(0.875)' : self::css_hex_lighten_darken($color_code,"-0.125");
1564
			$darker_40 = $is_var ? $color_code.';filter:brightness(0.6)' : self::css_hex_lighten_darken($color_code,"-0.4");
0 ignored issues
show
Unused Code introduced by
The assignment to $darker_40 is dead and can be removed.
Loading history...
1565
1566
			// lighten
1567
			$lighten_25 = $is_var ? $color_code.';filter:brightness(1.25)' :self::css_hex_lighten_darken($color_code,"0.25");
0 ignored issues
show
Unused Code introduced by
The assignment to $lighten_25 is dead and can be removed.
Loading history...
1568
1569
			// opacity see https://css-tricks.com/8-digit-hex-codes/
1570
			$op_25 = $color_code."40"; // 25% opacity
1571
1572
1573
			// button states
1574
			$output .= $is_var ? $prefix ." .btn-{$type}{{$transition }} " : '';
1575
			$output .= $prefix ." .btn-{$type}:hover, $prefix .btn-{$type}:focus, $prefix .btn-{$type}.focus{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1576
//			$output .= $prefix ." .btn-{$type}:hover, $prefix .btn-{$type}:focus, $prefix .btn-{$type}.focus{background-color: #000;    border-color: #000;} ";
1577
			$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;} ";
1578
			$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.";} ";
1579
			$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;} ";
1580
1581
			// text
1582
//			$output .= $prefix .".xxx, .text-{$type} {color: var(--bs-".esc_attr($type).");} ";
1583
1584
1585
//			if ( $type == 'primary' ) {
1586
//				// dropdown's
1587
//				$output .= $prefix . " .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
1588
//
1589
//				// input states
1590
//				$output .= $prefix . " .form-control:focus{border-color: " . $lighten_25 . ";box-shadow: 0 0 0 0.2rem $op_25;} ";
1591
//
1592
//				// page link
1593
//				$output .= $prefix . " .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1594
//			}
1595
1596
			// alerts
1597
			if ( $aui_bs5 ) {
1598
//				$output .= $is_var ? '' : $prefix ." .alert-{$type} {background-color: ".$color_code."20;    border-color: ".$color_code."30;color:$darker_40} ";
1599
				$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;} ";
1600
			}
1601
1602
			return $output;
1603
		}
1604
1605
		/**
1606
		 * Build the CSS to overwrite a bootstrap color variable.
1607
		 *
1608
		 * @param $type
1609
		 * @param $color_code
1610
		 * @param $compatibility
1611
		 *
1612
		 * @return string
1613
		 */
1614
		public static function css_overwrite($type,$color_code,$compatibility, $hex = '' ){
1615
            global $aui_bs5;
1616
1617
			$is_var = false;
1618
			if(!$color_code){return '';}
1619
			if(strpos($color_code, 'var') !== false){
1620
				//if(!sanitize_hex_color($color_code)){
1621
				$color_code = esc_attr($color_code);
1622
				$is_var = true;
1623
//				$color_code = "rgba($color_code, 0.5)";
1624
//                echo '###1'.$color_code.'###';//exit;
1625
			}
1626
1627
//            echo '@@@'.$color_code.'==='.self::hex_to_rgb($color_code);exit;
1628
1629
			if(!$color_code){return '';}
1630
1631
            $rgb = self::hex_to_rgb($hex);
1632
1633
			if($compatibility===true || $compatibility===1){
1634
				$compatibility = '.bsui';
1635
			}elseif(!$compatibility){
1636
				$compatibility = '';
1637
			}else{
1638
				$compatibility = esc_attr($compatibility);
1639
			}
1640
1641
1642
1643
//            echo '####'.$color_code;exit;
1644
1645
			$type = sanitize_html_class($type);
1646
1647
			/**
1648
			 * c = color, b = background color, o = border-color, f = fill
1649
			 */
1650
			$selectors = array(
1651
				".btn-{$type}"                                              => array( 'b', 'o' ),
1652
				".btn-{$type}.disabled"                                     => array( 'b', 'o' ),
1653
				".btn-{$type}:disabled"                                     => array( 'b', 'o' ),
1654
				".btn-outline-{$type}"                                      => array( 'c', 'o' ),
1655
				".btn-outline-{$type}:hover"                                => array( 'b', 'o' ),
1656
				".btn-outline-{$type}:not(:disabled):not(.disabled).active" => array( 'b', 'o' ),
1657
				".btn-outline-{$type}:not(:disabled):not(.disabled):active" => array( 'b', 'o' ),
1658
				".show>.btn-outline-{$type}.dropdown-toggle"                => array( 'b', 'o' ),
1659
				".badge-{$type}"                                            => array( 'b' ),
1660
				".alert-{$type}"                                            => array( 'b', 'o' ),
1661
				".bg-{$type}"                                               => array( 'b', 'f' ),
1662
				".btn-link.btn-{$type}"                                     => array( 'c' ),
1663
			);
1664
1665
			if ( $aui_bs5 ) {
1666
                unset($selectors[".alert-{$type}" ]);
1667
			}
1668
1669
			if ( $type == 'primary' ) {
1670
				$selectors = $selectors + array(
1671
						'a'                                                                                                    => array( 'c' ),
1672
						'.btn-link'                                                                                            => array( 'c' ),
1673
						'.dropdown-item.active'                                                                                => array( 'b' ),
1674
						'.custom-control-input:checked~.custom-control-label::before'                                          => array(
1675
							'b',
1676
							'o'
1677
						),
1678
						'.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before'                   => array(
1679
							'b',
1680
							'o'
1681
						),
1682
						'.nav-pills .nav-link.active'                                                                          => array( 'b' ),
1683
						'.nav-pills .show>.nav-link'                                                                           => array( 'b' ),
1684
						'.page-link'                                                                                           => array( 'c' ),
1685
						'.page-item.active .page-link'                                                                         => array(
1686
							'b',
1687
							'o'
1688
						),
1689
						'.progress-bar'                                                                                        => array( 'b' ),
1690
						'.list-group-item.active'                                                                              => array(
1691
							'b',
1692
							'o'
1693
						),
1694
						'.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array( 'b' ),
1695
//				    '.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules...
1696
//				    '.custom-range::-moz-range-thumb' => array('b'),
1697
//				    '.custom-range::-ms-thumb' => array('b'),
1698
					);
1699
			}
1700
1701
			$important_selectors = array(
1702
				".bg-{$type}" => array('b','f'),
1703
				".border-{$type}" => array('o'),
1704
				".text-{$type}" => array('c'),
1705
			);
1706
1707
			$color = array();
1708
			$color_i = array();
1709
			$background = array();
1710
			$background_i = array();
1711
			$border = array();
1712
			$border_i = array();
1713
			$fill = array();
1714
			$fill_i = array();
1715
1716
			$output = '';
1717
1718
			if ( $aui_bs5 ) {
1719
//				$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).'; }';
1720
				$output .= 'html body {--bs-'.esc_attr($type).'-rgb: '.$rgb.'; }';
1721
			}
1722
1723
			// build rules into each type
1724
			foreach($selectors as $selector => $types){
1725
				$selector = $compatibility ? $compatibility . " ".$selector : $selector;
1726
				$types = array_combine($types,$types);
1727
				if(isset($types['c'])){$color[] = $selector;}
1728
				if(isset($types['b'])){$background[] = $selector;}
1729
				if(isset($types['o'])){$border[] = $selector;}
1730
				if(isset($types['f'])){$fill[] = $selector;}
1731
			}
1732
1733
			// build rules into each type
1734
			foreach($important_selectors as $selector => $types){
1735
				$selector = $compatibility ? $compatibility . " ".$selector : $selector;
1736
				$types = array_combine($types,$types);
1737
				if(isset($types['c'])){$color_i[] = $selector;}
1738
				if(isset($types['b'])){$background_i[] = $selector;}
1739
				if(isset($types['o'])){$border_i[] = $selector;}
1740
				if(isset($types['f'])){$fill_i[] = $selector;}
1741
			}
1742
1743
			// add any color rules
1744
			if(!empty($color)){
1745
				$output .= implode(",",$color) . "{color: $color_code;} ";
1746
			}
1747
			if(!empty($color_i)){
1748
				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1749
			}
1750
1751
			// add any background color rules
1752
			if(!empty($background)){
1753
				$output .= implode(",",$background) . "{background-color: $color_code;} ";
1754
			}
1755
			if(!empty($background_i)){
1756
				$output .= $aui_bs5 ? '' : implode(",",$background_i) . "{background-color: $color_code !important;} ";
1757
//				$output .= implode(",",$background_i) . "{background-color: rgba(var(--bs-primary-rgb), var(--bs-bg-opacity)) !important;} ";
1758
			}
1759
1760
			// add any border color rules
1761
			if(!empty($border)){
1762
				$output .= implode(",",$border) . "{border-color: $color_code;} ";
1763
			}
1764
			if(!empty($border_i)){
1765
				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1766
			}
1767
1768
			// add any fill color rules
1769
			if(!empty($fill)){
1770
				$output .= implode(",",$fill) . "{fill: $color_code;} ";
1771
			}
1772
			if(!empty($fill_i)){
1773
				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1774
			}
1775
1776
1777
			$prefix = $compatibility ? $compatibility . " " : "";
1778
1779
			$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;' : '';
1780
			// darken
1781
			$darker_075 = $is_var ? $color_code.';filter:brightness(0.925)' : self::css_hex_lighten_darken($color_code,"-0.075");
0 ignored issues
show
Bug introduced by
'-0.075' of type string is incompatible with the type double expected by parameter $adjustPercent of AyeCode_UI_Settings::css_hex_lighten_darken(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1781
			$darker_075 = $is_var ? $color_code.';filter:brightness(0.925)' : self::css_hex_lighten_darken($color_code,/** @scrutinizer ignore-type */ "-0.075");
Loading history...
1782
			$darker_10 = $is_var ? $color_code.';filter:brightness(0.9)' : self::css_hex_lighten_darken($color_code,"-0.10");
1783
			$darker_125 = $is_var ? $color_code.';filter:brightness(0.875)' : self::css_hex_lighten_darken($color_code,"-0.125");
1784
			$darker_40 = $is_var ? $color_code.';filter:brightness(0.6)' : self::css_hex_lighten_darken($color_code,"-0.4");
0 ignored issues
show
Unused Code introduced by
The assignment to $darker_40 is dead and can be removed.
Loading history...
1785
1786
			// lighten
1787
			$lighten_25 = $is_var ? $color_code.';filter:brightness(1.25)' :self::css_hex_lighten_darken($color_code,"0.25");
1788
1789
			// opacity see https://css-tricks.com/8-digit-hex-codes/
1790
			$op_25 = $color_code."40"; // 25% opacity
1791
1792
1793
			// button states
1794
			$output .= $is_var ? $prefix ." .btn-{$type}{{$transition }} " : '';
1795
			$output .= $prefix ." .btn-{$type}:hover, $prefix .btn-{$type}:focus, $prefix .btn-{$type}.focus{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1796
//			$output .= $prefix ." .btn-{$type}:hover, $prefix .btn-{$type}:focus, $prefix .btn-{$type}.focus{background-color: #000;    border-color: #000;} ";
1797
			$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;} ";
1798
			$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.";} ";
1799
			$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;} ";
1800
1801
			if ( $type == 'primary' ) {
1802
				// dropdown's
1803
				$output .= $prefix . " .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
1804
1805
				// input states
1806
				$output .= $prefix . " .form-control:focus{border-color: " . $lighten_25 . ";box-shadow: 0 0 0 0.2rem $op_25;} ";
1807
1808
				// page link
1809
				$output .= $prefix . " .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1810
			}
1811
1812
            // alerts
1813
			if ( $aui_bs5 ) {
1814
//				$output .= $is_var ? '' : $prefix ." .alert-{$type} {background-color: ".$color_code."20;    border-color: ".$color_code."30;color:$darker_40} ";
1815
				$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;} ";
1816
			}
1817
1818
			return $output;
1819
		}
1820
1821
		/**
1822
		 *
1823
		 * @deprecated 0.1.76 Use css_overwrite()
1824
		 *
1825
		 * @param $color_code
1826
		 * @param $compatibility
1827
		 * @param $use_variable
1828
		 *
1829
		 * @return string
1830
		 */
1831
		public static function css_primary($color_code,$compatibility, $use_variable = false){
1832
1833
			if(!$use_variable){
1834
				$color_code = sanitize_hex_color($color_code);
1835
				if(!$color_code){return '';}
1836
			}
1837
1838
			/**
1839
			 * c = color, b = background color, o = border-color, f = fill
1840
			 */
1841
			$selectors = array(
1842
				'a' => array('c'),
1843
				'.btn-primary' => array('b','o'),
1844
				'.btn-primary.disabled' => array('b','o'),
1845
				'.btn-primary:disabled' => array('b','o'),
1846
				'.btn-outline-primary' => array('c','o'),
1847
				'.btn-outline-primary:hover' => array('b','o'),
1848
				'.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'),
1849
				'.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'),
1850
				'.show>.btn-outline-primary.dropdown-toggle' => array('b','o'),
1851
				'.btn-link' => array('c'),
1852
				'.dropdown-item.active' => array('b'),
1853
				'.custom-control-input:checked~.custom-control-label::before' => array('b','o'),
1854
				'.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'),
1855
//				'.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules...
1856
//				'.custom-range::-moz-range-thumb' => array('b'),
1857
//				'.custom-range::-ms-thumb' => array('b'),
1858
				'.nav-pills .nav-link.active' => array('b'),
1859
				'.nav-pills .show>.nav-link' => array('b'),
1860
				'.page-link' => array('c'),
1861
				'.page-item.active .page-link' => array('b','o'),
1862
				'.badge-primary' => array('b'),
1863
				'.alert-primary' => array('b','o'),
1864
				'.progress-bar' => array('b'),
1865
				'.list-group-item.active' => array('b','o'),
1866
				'.bg-primary' => array('b','f'),
1867
				'.btn-link.btn-primary' => array('c'),
1868
				'.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'),
1869
			);
1870
1871
			$important_selectors = array(
1872
				'.bg-primary' => array('b','f'),
1873
				'.border-primary' => array('o'),
1874
				'.text-primary' => array('c'),
1875
			);
1876
1877
			$color = array();
1878
			$color_i = array();
1879
			$background = array();
1880
			$background_i = array();
1881
			$border = array();
1882
			$border_i = array();
1883
			$fill = array();
1884
			$fill_i = array();
1885
1886
			$output = '';
1887
1888
			// build rules into each type
1889
			foreach($selectors as $selector => $types){
1890
				$selector = $compatibility ? ".bsui ".$selector : $selector;
1891
				$types = array_combine($types,$types);
1892
				if(isset($types['c'])){$color[] = $selector;}
1893
				if(isset($types['b'])){$background[] = $selector;}
1894
				if(isset($types['o'])){$border[] = $selector;}
1895
				if(isset($types['f'])){$fill[] = $selector;}
1896
			}
1897
1898
			// build rules into each type
1899
			foreach($important_selectors as $selector => $types){
1900
				$selector = $compatibility ? ".bsui ".$selector : $selector;
1901
				$types = array_combine($types,$types);
1902
				if(isset($types['c'])){$color_i[] = $selector;}
1903
				if(isset($types['b'])){$background_i[] = $selector;}
1904
				if(isset($types['o'])){$border_i[] = $selector;}
1905
				if(isset($types['f'])){$fill_i[] = $selector;}
1906
			}
1907
1908
			// add any color rules
1909
			if(!empty($color)){
1910
				$output .= implode(",",$color) . "{color: $color_code;} ";
1911
			}
1912
			if(!empty($color_i)){
1913
				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1914
			}
1915
1916
			// add any background color rules
1917
			if(!empty($background)){
1918
				$output .= implode(",",$background) . "{background-color: $color_code;} ";
1919
			}
1920
			if(!empty($background_i)){
1921
				$output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1922
			}
1923
1924
			// add any border color rules
1925
			if(!empty($border)){
1926
				$output .= implode(",",$border) . "{border-color: $color_code;} ";
1927
			}
1928
			if(!empty($border_i)){
1929
				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1930
			}
1931
1932
			// add any fill color rules
1933
			if(!empty($fill)){
1934
				$output .= implode(",",$fill) . "{fill: $color_code;} ";
1935
			}
1936
			if(!empty($fill_i)){
1937
				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1938
			}
1939
1940
1941
			$prefix = $compatibility ? ".bsui " : "";
1942
1943
			// darken
1944
			$darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
0 ignored issues
show
Bug introduced by
'-0.075' of type string is incompatible with the type double expected by parameter $adjustPercent of AyeCode_UI_Settings::css_hex_lighten_darken(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1944
			$darker_075 = self::css_hex_lighten_darken($color_code,/** @scrutinizer ignore-type */ "-0.075");
Loading history...
1945
			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1946
			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1947
1948
			// lighten
1949
			$lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1950
1951
			// opacity see https://css-tricks.com/8-digit-hex-codes/
1952
			$op_25 = $color_code."40"; // 25% opacity
1953
1954
1955
			// button states
1956
			$output .= $prefix ." .btn-primary:hover, $prefix .btn-primary:focus, $prefix .btn-primary.focus{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1957
			$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;} ";
1958
			$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.";} ";
1959
			$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;} ";
1960
1961
1962
			// dropdown's
1963
			$output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
1964
1965
1966
			// input states
1967
			$output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} ";
1968
1969
			// page link
1970
			$output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1971
1972
			return $output;
1973
		}
1974
1975
		/**
1976
		 *
1977
		 * @deprecated 0.1.76 Use css_overwrite()
1978
		 *
1979
		 * @param $color_code
1980
		 * @param $compatibility
1981
		 *
1982
		 * @return string
1983
		 */
1984
		public static function css_secondary($color_code,$compatibility){;
1985
			$color_code = sanitize_hex_color($color_code);
1986
			if(!$color_code){return '';}
1987
			/**
1988
			 * c = color, b = background color, o = border-color, f = fill
1989
			 */
1990
			$selectors = array(
1991
				'.btn-secondary' => array('b','o'),
1992
				'.btn-secondary.disabled' => array('b','o'),
1993
				'.btn-secondary:disabled' => array('b','o'),
1994
				'.btn-outline-secondary' => array('c','o'),
1995
				'.btn-outline-secondary:hover' => array('b','o'),
1996
				'.btn-outline-secondary.disabled' => array('c'),
1997
				'.btn-outline-secondary:disabled' => array('c'),
1998
				'.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'),
1999
				'.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'),
2000
				'.btn-outline-secondary.dropdown-toggle' => array('b','o'),
2001
				'.badge-secondary' => array('b'),
2002
				'.alert-secondary' => array('b','o'),
2003
				'.btn-link.btn-secondary' => array('c'),
2004
			);
2005
2006
			$important_selectors = array(
2007
				'.bg-secondary' => array('b','f'),
2008
				'.border-secondary' => array('o'),
2009
				'.text-secondary' => array('c'),
2010
			);
2011
2012
			$color = array();
2013
			$color_i = array();
2014
			$background = array();
2015
			$background_i = array();
2016
			$border = array();
2017
			$border_i = array();
2018
			$fill = array();
2019
			$fill_i = array();
2020
2021
			$output = '';
2022
2023
			// build rules into each type
2024
			foreach($selectors as $selector => $types){
2025
				$selector = $compatibility ? ".bsui ".$selector : $selector;
2026
				$types = array_combine($types,$types);
2027
				if(isset($types['c'])){$color[] = $selector;}
2028
				if(isset($types['b'])){$background[] = $selector;}
2029
				if(isset($types['o'])){$border[] = $selector;}
2030
				if(isset($types['f'])){$fill[] = $selector;}
2031
			}
2032
2033
			// build rules into each type
2034
			foreach($important_selectors as $selector => $types){
2035
				$selector = $compatibility ? ".bsui ".$selector : $selector;
2036
				$types = array_combine($types,$types);
2037
				if(isset($types['c'])){$color_i[] = $selector;}
2038
				if(isset($types['b'])){$background_i[] = $selector;}
2039
				if(isset($types['o'])){$border_i[] = $selector;}
2040
				if(isset($types['f'])){$fill_i[] = $selector;}
2041
			}
2042
2043
			// add any color rules
2044
			if(!empty($color)){
2045
				$output .= implode(",",$color) . "{color: $color_code;} ";
2046
			}
2047
			if(!empty($color_i)){
2048
				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
2049
			}
2050
2051
			// add any background color rules
2052
			if(!empty($background)){
2053
				$output .= implode(",",$background) . "{background-color: $color_code;} ";
2054
			}
2055
			if(!empty($background_i)){
2056
				$output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
2057
			}
2058
2059
			// add any border color rules
2060
			if(!empty($border)){
2061
				$output .= implode(",",$border) . "{border-color: $color_code;} ";
2062
			}
2063
			if(!empty($border_i)){
2064
				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
2065
			}
2066
2067
			// add any fill color rules
2068
			if(!empty($fill)){
2069
				$output .= implode(",",$fill) . "{fill: $color_code;} ";
2070
			}
2071
			if(!empty($fill_i)){
2072
				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
2073
			}
2074
2075
2076
			$prefix = $compatibility ? ".bsui " : "";
2077
2078
			// darken
2079
			$darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
0 ignored issues
show
Bug introduced by
'-0.075' of type string is incompatible with the type double expected by parameter $adjustPercent of AyeCode_UI_Settings::css_hex_lighten_darken(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

2079
			$darker_075 = self::css_hex_lighten_darken($color_code,/** @scrutinizer ignore-type */ "-0.075");
Loading history...
2080
			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
2081
			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
2082
2083
			// lighten
2084
			$lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
0 ignored issues
show
Unused Code introduced by
The assignment to $lighten_25 is dead and can be removed.
Loading history...
2085
2086
			// opacity see https://css-tricks.com/8-digit-hex-codes/
2087
			$op_25 = $color_code."40"; // 25% opacity
2088
2089
2090
			// button states
2091
			$output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
2092
			$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;} ";
2093
			$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.";} ";
2094
			$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;} ";
2095
2096
2097
			return $output;
2098
		}
2099
2100
		/**
2101
		 * Increases or decreases the brightness of a color by a percentage of the current brightness.
2102
		 *
2103
		 * @param   string  $hexCode        Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF`
2104
		 * @param   float   $adjustPercent  A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker.
2105
		 *
2106
		 * @return  string
2107
		 */
2108
		public static function css_hex_lighten_darken($hexCode, $adjustPercent) {
2109
			$hexCode = ltrim($hexCode, '#');
2110
2111
			if (strlen($hexCode) == 3) {
2112
				$hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2];
2113
			}
2114
2115
			$hexCode = array_map('hexdec', str_split($hexCode, 2));
0 ignored issues
show
Bug introduced by
It seems like str_split($hexCode, 2) can also be of type true; however, parameter $array of array_map() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

2115
			$hexCode = array_map('hexdec', /** @scrutinizer ignore-type */ str_split($hexCode, 2));
Loading history...
2116
2117
			foreach ($hexCode as & $color) {
2118
				$adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color;
2119
				$adjustAmount = ceil($adjustableLimit * $adjustPercent);
2120
2121
				$color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT);
0 ignored issues
show
Bug introduced by
$color + $adjustAmount of type double is incompatible with the type integer expected by parameter $num of dechex(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

2121
				$color = str_pad(dechex(/** @scrutinizer ignore-type */ $color + $adjustAmount), 2, '0', STR_PAD_LEFT);
Loading history...
2122
			}
2123
2124
			return '#' . implode($hexCode);
2125
		}
2126
2127
		/**
2128
		 * Check if we should display examples.
2129
		 */
2130
		public function maybe_show_examples(){
2131
			if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){
2132
				echo "<head>";
2133
				wp_head();
2134
				echo "</head>";
2135
				echo "<body>";
2136
				echo $this->get_examples();
2137
				echo "</body>";
2138
				exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
2139
			}
2140
		}
2141
2142
		/**
2143
		 * Get developer examples.
2144
		 *
2145
		 * @return string
2146
		 */
2147
		public function get_examples(){
2148
			$output = '';
2149
2150
2151
			// open form
2152
			$output .= "<form class='p-5 m-5 border rounded'>";
2153
2154
			// input example
2155
			$output .= aui()->input(array(
2156
				'type'  =>  'text',
2157
				'id'    =>  'text-example',
2158
				'name'    =>  'text-example',
2159
				'placeholder'   => 'text placeholder',
2160
				'title'   => 'Text input example',
2161
				'value' =>  '',
2162
				'required'  => false,
2163
				'help_text' => 'help text',
2164
				'label' => 'Text input example label'
2165
			));
2166
2167
			// input example
2168
			$output .= aui()->input(array(
2169
				'type'  =>  'url',
2170
				'id'    =>  'text-example2',
2171
				'name'    =>  'text-example',
2172
				'placeholder'   => 'url placeholder',
2173
				'title'   => 'Text input example',
2174
				'value' =>  '',
2175
				'required'  => false,
2176
				'help_text' => 'help text',
2177
				'label' => 'Text input example label'
2178
			));
2179
2180
			// checkbox example
2181
			$output .= aui()->input(array(
2182
				'type'  =>  'checkbox',
2183
				'id'    =>  'checkbox-example',
2184
				'name'    =>  'checkbox-example',
2185
				'placeholder'   => 'checkbox-example',
2186
				'title'   => 'Checkbox example',
2187
				'value' =>  '1',
2188
				'checked'   => true,
2189
				'required'  => false,
2190
				'help_text' => 'help text',
2191
				'label' => 'Checkbox checked'
2192
			));
2193
2194
			// checkbox example
2195
			$output .= aui()->input(array(
2196
				'type'  =>  'checkbox',
2197
				'id'    =>  'checkbox-example2',
2198
				'name'    =>  'checkbox-example2',
2199
				'placeholder'   => 'checkbox-example',
2200
				'title'   => 'Checkbox example',
2201
				'value' =>  '1',
2202
				'checked'   => false,
2203
				'required'  => false,
2204
				'help_text' => 'help text',
2205
				'label' => 'Checkbox un-checked'
2206
			));
2207
2208
			// switch example
2209
			$output .= aui()->input(array(
2210
				'type'  =>  'checkbox',
2211
				'id'    =>  'switch-example',
2212
				'name'    =>  'switch-example',
2213
				'placeholder'   => 'checkbox-example',
2214
				'title'   => 'Switch example',
2215
				'value' =>  '1',
2216
				'checked'   => true,
2217
				'switch'    => true,
2218
				'required'  => false,
2219
				'help_text' => 'help text',
2220
				'label' => 'Switch on'
2221
			));
2222
2223
			// switch example
2224
			$output .= aui()->input(array(
2225
				'type'  =>  'checkbox',
2226
				'id'    =>  'switch-example2',
2227
				'name'    =>  'switch-example2',
2228
				'placeholder'   => 'checkbox-example',
2229
				'title'   => 'Switch example',
2230
				'value' =>  '1',
2231
				'checked'   => false,
2232
				'switch'    => true,
2233
				'required'  => false,
2234
				'help_text' => 'help text',
2235
				'label' => 'Switch off'
2236
			));
2237
2238
			// close form
2239
			$output .= "</form>";
2240
2241
			return $output;
2242
		}
2243
2244
		/**
2245
		 * Calendar params.
2246
		 *
2247
		 * @since 0.1.44
2248
		 *
2249
		 * @return array Calendar params.
2250
		 */
2251
		public static function calendar_params() {
2252
			$params = array(
2253
				'month_long_1' => __( 'January', 'ayecode-connect' ),
2254
				'month_long_2' => __( 'February', 'ayecode-connect' ),
2255
				'month_long_3' => __( 'March', 'ayecode-connect' ),
2256
				'month_long_4' => __( 'April', 'ayecode-connect' ),
2257
				'month_long_5' => __( 'May', 'ayecode-connect' ),
2258
				'month_long_6' => __( 'June', 'ayecode-connect' ),
2259
				'month_long_7' => __( 'July', 'ayecode-connect' ),
2260
				'month_long_8' => __( 'August', 'ayecode-connect' ),
2261
				'month_long_9' => __( 'September', 'ayecode-connect' ),
2262
				'month_long_10' => __( 'October', 'ayecode-connect' ),
2263
				'month_long_11' => __( 'November', 'ayecode-connect' ),
2264
				'month_long_12' => __( 'December', 'ayecode-connect' ),
2265
				'month_s_1' => _x( 'Jan', 'January abbreviation', 'ayecode-connect' ),
2266
				'month_s_2' => _x( 'Feb', 'February abbreviation', 'ayecode-connect' ),
2267
				'month_s_3' => _x( 'Mar', 'March abbreviation', 'ayecode-connect' ),
2268
				'month_s_4' => _x( 'Apr', 'April abbreviation', 'ayecode-connect' ),
2269
				'month_s_5' => _x( 'May', 'May abbreviation', 'ayecode-connect' ),
2270
				'month_s_6' => _x( 'Jun', 'June abbreviation', 'ayecode-connect' ),
2271
				'month_s_7' => _x( 'Jul', 'July abbreviation', 'ayecode-connect' ),
2272
				'month_s_8' => _x( 'Aug', 'August abbreviation', 'ayecode-connect' ),
2273
				'month_s_9' => _x( 'Sep', 'September abbreviation', 'ayecode-connect' ),
2274
				'month_s_10' => _x( 'Oct', 'October abbreviation', 'ayecode-connect' ),
2275
				'month_s_11' => _x( 'Nov', 'November abbreviation', 'ayecode-connect' ),
2276
				'month_s_12' => _x( 'Dec', 'December abbreviation', 'ayecode-connect' ),
2277
				'day_s1_1' => _x( 'S', 'Sunday initial', 'ayecode-connect' ),
2278
				'day_s1_2' => _x( 'M', 'Monday initial', 'ayecode-connect' ),
2279
				'day_s1_3' => _x( 'T', 'Tuesday initial', 'ayecode-connect' ),
2280
				'day_s1_4' => _x( 'W', 'Wednesday initial', 'ayecode-connect' ),
2281
				'day_s1_5' => _x( 'T', 'Friday initial', 'ayecode-connect' ),
2282
				'day_s1_6' => _x( 'F', 'Thursday initial', 'ayecode-connect' ),
2283
				'day_s1_7' => _x( 'S', 'Saturday initial', 'ayecode-connect' ),
2284
				'day_s2_1' => __( 'Su', 'ayecode-connect' ),
2285
				'day_s2_2' => __( 'Mo', 'ayecode-connect' ),
2286
				'day_s2_3' => __( 'Tu', 'ayecode-connect' ),
2287
				'day_s2_4' => __( 'We', 'ayecode-connect' ),
2288
				'day_s2_5' => __( 'Th', 'ayecode-connect' ),
2289
				'day_s2_6' => __( 'Fr', 'ayecode-connect' ),
2290
				'day_s2_7' => __( 'Sa', 'ayecode-connect' ),
2291
				'day_s3_1' => __( 'Sun', 'ayecode-connect' ),
2292
				'day_s3_2' => __( 'Mon', 'ayecode-connect' ),
2293
				'day_s3_3' => __( 'Tue', 'ayecode-connect' ),
2294
				'day_s3_4' => __( 'Wed', 'ayecode-connect' ),
2295
				'day_s3_5' => __( 'Thu', 'ayecode-connect' ),
2296
				'day_s3_6' => __( 'Fri', 'ayecode-connect' ),
2297
				'day_s3_7' => __( 'Sat', 'ayecode-connect' ),
2298
				'day_s5_1' => __( 'Sunday', 'ayecode-connect' ),
2299
				'day_s5_2' => __( 'Monday', 'ayecode-connect' ),
2300
				'day_s5_3' => __( 'Tuesday', 'ayecode-connect' ),
2301
				'day_s5_4' => __( 'Wednesday', 'ayecode-connect' ),
2302
				'day_s5_5' => __( 'Thursday', 'ayecode-connect' ),
2303
				'day_s5_6' => __( 'Friday', 'ayecode-connect' ),
2304
				'day_s5_7' => __( 'Saturday', 'ayecode-connect' ),
2305
				'am_lower' => __( 'am', 'ayecode-connect' ),
2306
				'pm_lower' => __( 'pm', 'ayecode-connect' ),
2307
				'am_upper' => __( 'AM', 'ayecode-connect' ),
2308
				'pm_upper' => __( 'PM', 'ayecode-connect' ),
2309
				'firstDayOfWeek' => (int) get_option( 'start_of_week' ),
2310
				'time_24hr' => false,
2311
				'year' => __( 'Year', 'ayecode-connect' ),
2312
				'hour' => __( 'Hour', 'ayecode-connect' ),
2313
				'minute' => __( 'Minute', 'ayecode-connect' ),
2314
				'weekAbbreviation' => __( 'Wk', 'ayecode-connect' ),
2315
				'rangeSeparator' => __( ' to ', 'ayecode-connect' ),
2316
				'scrollTitle' => __( 'Scroll to increment', 'ayecode-connect' ),
2317
				'toggleTitle' => __( 'Click to toggle', 'ayecode-connect' )
2318
			);
2319
2320
			return apply_filters( 'ayecode_ui_calendar_params', $params );
2321
		}
2322
2323
		/**
2324
		 * Flatpickr calendar localize.
2325
		 *
2326
		 * @since 0.1.44
2327
		 *
2328
		 * @return string Calendar locale.
2329
		 */
2330
		public static function flatpickr_locale() {
2331
			$params = self::calendar_params();
2332
2333
			if ( is_string( $params ) ) {
0 ignored issues
show
introduced by
The condition is_string($params) is always false.
Loading history...
2334
				$params = html_entity_decode( $params, ENT_QUOTES, 'UTF-8' );
2335
			} else {
2336
				foreach ( (array) $params as $key => $value ) {
2337
					if ( ! is_scalar( $value ) ) {
2338
						continue;
2339
					}
2340
2341
					$params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
2342
				}
2343
			}
2344
2345
			$day_s3 = array();
2346
			$day_s5 = array();
2347
2348
			for ( $i = 1; $i <= 7; $i ++ ) {
2349
				$day_s3[] = addslashes( $params[ 'day_s3_' . $i ] );
2350
				$day_s5[] = addslashes( $params[ 'day_s3_' . $i ] );
2351
			}
2352
2353
			$month_s = array();
2354
			$month_long = array();
2355
2356
			for ( $i = 1; $i <= 12; $i ++ ) {
2357
				$month_s[] = addslashes( $params[ 'month_s_' . $i ] );
2358
				$month_long[] = addslashes( $params[ 'month_long_' . $i ] );
2359
			}
2360
2361
			ob_start();
2362
		if ( 0 ) { ?><script><?php } ?>
2363
                {
2364
                    weekdays: {
2365
                        shorthand: ['<?php echo implode( "','", $day_s3 ); ?>'],
2366
                            longhand: ['<?php echo implode( "','", $day_s5 ); ?>'],
2367
                    },
2368
                    months: {
2369
                        shorthand: ['<?php echo implode( "','", $month_s ); ?>'],
2370
                            longhand: ['<?php echo implode( "','", $month_long ); ?>'],
2371
                    },
2372
                    daysInMonth: [31,28,31,30,31,30,31,31,30,31,30,31],
2373
                        firstDayOfWeek: <?php echo (int) $params[ 'firstDayOfWeek' ]; ?>,
2374
                    ordinal: function (nth) {
2375
                        var s = nth % 100;
2376
                        if (s > 3 && s < 21)
2377
                            return "th";
2378
                        switch (s % 10) {
2379
                            case 1:
2380
                                return "st";
2381
                            case 2:
2382
                                return "nd";
2383
                            case 3:
2384
                                return "rd";
2385
                            default:
2386
                                return "th";
2387
                        }
2388
                    },
2389
                    rangeSeparator: '<?php echo addslashes( $params[ 'rangeSeparator' ] ); ?>',
2390
                        weekAbbreviation: '<?php echo addslashes( $params[ 'weekAbbreviation' ] ); ?>',
2391
                    scrollTitle: '<?php echo addslashes( $params[ 'scrollTitle' ] ); ?>',
2392
                    toggleTitle: '<?php echo addslashes( $params[ 'toggleTitle' ] ); ?>',
2393
                    amPM: ['<?php echo addslashes( $params[ 'am_upper' ] ); ?>','<?php echo addslashes( $params[ 'pm_upper' ] ); ?>'],
2394
                    yearAriaLabel: '<?php echo addslashes( $params[ 'year' ] ); ?>',
2395
                    hourAriaLabel: '<?php echo addslashes( $params[ 'hour' ] ); ?>',
2396
                    minuteAriaLabel: '<?php echo addslashes( $params[ 'minute' ] ); ?>',
2397
                    time_24hr: <?php echo ( $params[ 'time_24hr' ] ? 'true' : 'false' ) ; ?>
2398
                }
2399
				<?php if ( 0 ) { ?></script><?php } ?>
2400
			<?php
2401
			$locale = ob_get_clean();
2402
2403
			return apply_filters( 'ayecode_ui_flatpickr_locale', trim( $locale ) );
2404
		}
2405
2406
		/**
2407
		 * Select2 JS params.
2408
		 *
2409
		 * @since 0.1.44
2410
		 *
2411
		 * @return array Select2 JS params.
2412
		 */
2413
		public static function select2_params() {
2414
			$params = array(
2415
				'i18n_select_state_text'    => esc_attr__( 'Select an option&hellip;', 'ayecode-connect' ),
2416
				'i18n_no_matches'           => _x( 'No matches found', 'enhanced select', 'ayecode-connect' ),
2417
				'i18n_ajax_error'           => _x( 'Loading failed', 'enhanced select', 'ayecode-connect' ),
2418
				'i18n_input_too_short_1'    => _x( 'Please enter 1 or more characters', 'enhanced select', 'ayecode-connect' ),
2419
				'i18n_input_too_short_n'    => _x( 'Please enter %item% or more characters', 'enhanced select', 'ayecode-connect' ),
2420
				'i18n_input_too_long_1'     => _x( 'Please delete 1 character', 'enhanced select', 'ayecode-connect' ),
2421
				'i18n_input_too_long_n'     => _x( 'Please delete %item% characters', 'enhanced select', 'ayecode-connect' ),
2422
				'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'ayecode-connect' ),
2423
				'i18n_selection_too_long_n' => _x( 'You can only select %item% items', 'enhanced select', 'ayecode-connect' ),
2424
				'i18n_load_more'            => _x( 'Loading more results&hellip;', 'enhanced select', 'ayecode-connect' ),
2425
				'i18n_searching'            => _x( 'Searching&hellip;', 'enhanced select', 'ayecode-connect' )
2426
			);
2427
2428
			return apply_filters( 'ayecode_ui_select2_params', $params );
2429
		}
2430
2431
		/**
2432
		 * Select2 JS localize.
2433
		 *
2434
		 * @since 0.1.44
2435
		 *
2436
		 * @return string Select2 JS locale.
2437
		 */
2438
		public static function select2_locale() {
2439
			$params = self::select2_params();
2440
2441
			foreach ( (array) $params as $key => $value ) {
2442
				if ( ! is_scalar( $value ) ) {
2443
					continue;
2444
				}
2445
2446
				$params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
2447
			}
2448
2449
			$locale = json_encode( $params );
2450
2451
			return apply_filters( 'ayecode_ui_select2_locale', trim( $locale ) );
2452
		}
2453
2454
		/**
2455
		 * Time ago JS localize.
2456
		 *
2457
		 * @since 0.1.47
2458
		 *
2459
		 * @return string Time ago JS locale.
2460
		 */
2461
		public static function timeago_locale() {
2462
			$params = array(
2463
				'prefix_ago' => '',
2464
				'suffix_ago' => ' ' . _x( 'ago', 'time ago', 'ayecode-connect' ),
2465
				'prefix_after' => _x( 'after', 'time ago', 'ayecode-connect' ) . ' ',
2466
				'suffix_after' => '',
2467
				'seconds' => _x( 'less than a minute', 'time ago', 'ayecode-connect' ),
2468
				'minute' => _x( 'about a minute', 'time ago', 'ayecode-connect' ),
2469
				'minutes' => _x( '%d minutes', 'time ago', 'ayecode-connect' ),
2470
				'hour' => _x( 'about an hour', 'time ago', 'ayecode-connect' ),
2471
				'hours' => _x( 'about %d hours', 'time ago', 'ayecode-connect' ),
2472
				'day' => _x( 'a day', 'time ago', 'ayecode-connect' ),
2473
				'days' => _x( '%d days', 'time ago', 'ayecode-connect' ),
2474
				'month' => _x( 'about a month', 'time ago', 'ayecode-connect' ),
2475
				'months' => _x( '%d months', 'time ago', 'ayecode-connect' ),
2476
				'year' => _x( 'about a year', 'time ago', 'ayecode-connect' ),
2477
				'years' => _x( '%d years', 'time ago', 'ayecode-connect' ),
2478
			);
2479
2480
			$params = apply_filters( 'ayecode_ui_timeago_params', $params );
2481
2482
			foreach ( (array) $params as $key => $value ) {
2483
				if ( ! is_scalar( $value ) ) {
2484
					continue;
2485
				}
2486
2487
				$params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
2488
			}
2489
2490
			$locale = json_encode( $params );
2491
2492
			return apply_filters( 'ayecode_ui_timeago_locale', trim( $locale ) );
2493
		}
2494
2495
		/**
2496
		 * JavaScript Minifier
2497
		 *
2498
		 * @param $input
2499
		 *
2500
		 * @return mixed
2501
		 */
2502
		public static function minify_js($input) {
2503
			if(trim($input) === "") return $input;
2504
			return preg_replace(
2505
				array(
2506
					// Remove comment(s)
2507
					'#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#',
2508
					// Remove white-space(s) outside the string and regex
2509
					'#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#s',
2510
					// Remove the last semicolon
2511
					'#;+\}#',
2512
					// Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}`
2513
					'#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i',
2514
					// --ibid. From `foo['bar']` to `foo.bar`
2515
					'#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i'
2516
				),
2517
				array(
2518
					'$1',
2519
					'$1$2',
2520
					'}',
2521
					'$1$3',
2522
					'$1.$3'
2523
				),
2524
				$input);
2525
		}
2526
2527
		/**
2528
		 * Minify CSS
2529
		 *
2530
		 * @param $input
2531
		 *
2532
		 * @return mixed
2533
		 */
2534
		public static function minify_css($input) {
2535
			if(trim($input) === "") return $input;
2536
			return preg_replace(
2537
				array(
2538
					// Remove comment(s)
2539
					'#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\/\*(?!\!)(?>.*?\*\/)|^\s*|\s*$#s',
2540
					// Remove unused white-space(s)
2541
					'#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/))|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~]|\s(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si',
2542
					// Replace `0(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)` with `0`
2543
					'#(?<=[\s:])(0)(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)#si',
2544
					// Replace `:0 0 0 0` with `:0`
2545
					'#:(0\s+0|0\s+0\s+0\s+0)(?=[;\}]|\!important)#i',
2546
					// Replace `background-position:0` with `background-position:0 0`
2547
					'#(background-position):0(?=[;\}])#si',
2548
					// Replace `0.6` with `.6`, but only when preceded by `:`, `,`, `-` or a white-space
2549
					'#(?<=[\s:,\-])0+\.(\d+)#s',
2550
					// Minify string value
2551
					'#(\/\*(?>.*?\*\/))|(?<!content\:)([\'"])([a-z_][a-z0-9\-_]*?)\2(?=[\s\{\}\];,])#si',
2552
					'#(\/\*(?>.*?\*\/))|(\burl\()([\'"])([^\s]+?)\3(\))#si',
2553
					// Minify HEX color code
2554
					'#(?<=[\s:,\-]\#)([a-f0-6]+)\1([a-f0-6]+)\2([a-f0-6]+)\3#i',
2555
					// Replace `(border|outline):none` with `(border|outline):0`
2556
					'#(?<=[\{;])(border|outline):none(?=[;\}\!])#',
2557
					// Remove empty selector(s)
2558
					'#(\/\*(?>.*?\*\/))|(^|[\{\}])(?:[^\s\{\}]+)\{\}#s'
2559
				),
2560
				array(
2561
					'$1',
2562
					'$1$2$3$4$5$6$7',
2563
					'$1',
2564
					':0',
2565
					'$1:0 0',
2566
					'.$1',
2567
					'$1$3',
2568
					'$1$2$4$5',
2569
					'$1$2$3',
2570
					'$1:0',
2571
					'$1$2'
2572
				),
2573
				$input);
2574
		}
2575
2576
		/**
2577
		 * Get the conditional fields JavaScript.
2578
		 *
2579
		 * @return mixed
2580
		 */
2581
		public function conditional_fields_js() {
2582
			ob_start();
2583
			?>
2584
            <script>
2585
                /**
2586
                 * Conditional Fields
2587
                 */
2588
                var aui_cf_field_rules = [], aui_cf_field_key_rules = {}, aui_cf_field_default_values = {};
2589
2590
                jQuery(function($) {
2591
                    aui_cf_field_init_rules($);
2592
                });
2593
2594
                /**
2595
                 * Conditional fields init.
2596
                 */
2597
                function aui_cf_field_init_rules($) {
2598
                    if (!$('[data-has-rule]').length) {
2599
                        return;
2600
                    }
2601
                    $('input.select2-search__field').attr('data-ignore-rule','');
2602
                    $('[data-rule-key]').on('change keypress keyup gdclear', 'input, textarea', function() {
2603
                        if (!$(this).hasClass('select2-search__field')) {
2604
                            aui_cf_field_apply_rules($(this));
2605
                        }
2606
                    });
2607
2608
                    $('[data-rule-key]').on('change change.select2 gdclear', 'select', function() {
2609
                        aui_cf_field_apply_rules($(this));
2610
                    });
2611
2612
                    aui_cf_field_setup_rules($);
2613
                }
2614
2615
                /**
2616
                 * Setup conditional field rules.
2617
                 */
2618
                function aui_cf_field_setup_rules($) {
2619
                    var aui_cf_field_keys = [];
2620
2621
                    $('[data-rule-key]').each(function() {
2622
                        var key = $(this).data('rule-key'), irule = parseInt($(this).data('has-rule'));
2623
                        if (key) {
2624
                            aui_cf_field_keys.push(key);
2625
                        }
2626
2627
                        var parse_conds = {};
2628
                        if ($(this).data('rule-fie-0')) {
2629
                            $(this).find('input,select,textarea').each(function() {
2630
                                if ($(this).attr('required') || $(this).attr('oninvalid')) {
2631
                                    $(this).addClass('aui-cf-req');
2632
                                    if ($(this).attr('required')) {
2633
                                        $(this).attr('data-rule-req', true);
2634
                                    }
2635
                                    if ($(this).attr('oninvalid')) {
2636
                                        $(this).attr('data-rule-oninvalid', $(this).attr('oninvalid'));
2637
                                    }
2638
                                }
2639
                            });
2640
                            for (var i = 0; i < irule; i++) {
2641
                                var field = $(this).data('rule-fie-' + i);
2642
                                if (typeof parse_conds[i] === 'undefined') {
2643
                                    parse_conds[i] = {};
2644
                                }
2645
                                parse_conds[i]['action'] = $(this).data('rule-act-' + i);
2646
                                parse_conds[i]['field'] = $(this).data('rule-fie-' + i);
2647
                                parse_conds[i]['condition'] = $(this).data('rule-con-' + i);
2648
                                parse_conds[i]['value'] = $(this).data('rule-val-' + i);
2649
                            }
2650
2651
                            $.each(parse_conds, function(j, data) {
2652
                                var item = {
2653
                                    'field': {
2654
                                        key: key,
2655
                                        action: data.action,
2656
                                        field: data.field,
2657
                                        condition: data.condition,
2658
                                        value: data.value,
2659
                                        rule: {
2660
                                            key: key,
2661
                                            action: data.action,
2662
                                            condition: data.condition,
2663
                                            value: data.value
2664
                                        }
2665
                                    }
2666
                                };
2667
                                aui_cf_field_rules.push(item);
2668
                            });
2669
                        }
2670
                        aui_cf_field_default_values[$(this).data('rule-key')] = aui_cf_field_get_default_value($(this));
2671
                    });
2672
2673
                    $.each(aui_cf_field_keys, function(i, fkey) {
2674
                        aui_cf_field_key_rules[fkey] = aui_cf_field_get_children(fkey);
2675
                    });
2676
2677
                    $('[data-rule-key]:visible').each(function() {
2678
                        var conds = aui_cf_field_key_rules[$(this).data('rule-key')];
2679
                        if (conds && conds.length) {
2680
                            var $main_el = $(this), el = aui_cf_field_get_element($main_el);
2681
                            if ($(el).length) {
2682
                                aui_cf_field_apply_rules($(el));
2683
                            }
2684
                        }
2685
                    });
2686
                }
2687
2688
                /**
2689
                 * Apply conditional field rules.
2690
                 */
2691
                function aui_cf_field_apply_rules($el) {
2692
                    if (!$el.parents('[data-rule-key]').length) {
2693
                        return;
2694
                    }
2695
2696
                    if ($el.data('no-rule')) {
2697
                        return;
2698
                    }
2699
2700
                    var key = $el.parents('[data-rule-key]').data('rule-key');
2701
                    var conditions = aui_cf_field_key_rules[key];
2702
                    if (typeof conditions === 'undefined') {
2703
                        return;
2704
                    }
2705
                    var field_type = aui_cf_field_get_type($el.parents('[data-rule-key]')), current_value = aui_cf_field_get_value($el);
2706
                    var $keys = {}, $keys_values = {}, $key_rules = {};
2707
2708
                    jQuery.each(conditions, function(index, condition) {
2709
                        if (typeof $keys_values[condition.key] == 'undefined') {
2710
                            $keys_values[condition.key] = [];
2711
                            $key_rules[condition.key] = {}
2712
                        }
2713
2714
                        $keys_values[condition.key].push(condition.value);
2715
                        $key_rules[condition.key] = condition;
2716
                    });
2717
2718
                    jQuery.each(conditions, function(index, condition) {
2719
                        if (typeof $keys[condition.key] == 'undefined') {
2720
                            $keys[condition.key] = {};
2721
                        }
2722
2723
                        if (condition.condition === 'empty') {
2724
                            var field_value = Array.isArray(current_value) ? current_value.join('') : current_value;
2725
                            if (!field_value || field_value === '') {
2726
                                $keys[condition.key][index] = true;
2727
                            } else {
2728
                                $keys[condition.key][index] = false;
2729
                            }
2730
                        } else if (condition.condition === 'not empty') {
2731
                            var field_value = Array.isArray(current_value) ? current_value.join('') : current_value;
2732
                            if (field_value && field_value !== '') {
2733
                                $keys[condition.key][index] = true;
2734
                            } else {
2735
                                $keys[condition.key][index] = false;
2736
                            }
2737
                        } else if (condition.condition === 'equals to') {
2738
                            var field_value = (Array.isArray(current_value) && current_value.length === 1) ? current_value[0] : current_value;
2739
                            if (((condition.value && condition.value == condition.value) || (condition.value === field_value)) && aui_cf_field_in_array(field_value, $keys_values[condition.key])) {
2740
                                $keys[condition.key][index] = true;
2741
                            } else {
2742
                                $keys[condition.key][index] = false;
2743
                            }
2744
                        } else if (condition.condition === 'not equals') {
2745
                            var field_value = (Array.isArray(current_value) && current_value.length === 1) ? current_value[0] : current_value;
2746
                            if (jQuery.isNumeric(condition.value) && parseInt(field_value) !== parseInt(condition.value) && field_value && !aui_cf_field_in_array(field_value, $keys_values[condition.key])) {
2747
                                $keys[condition.key][index] = true;
2748
                            } else if (condition.value != field_value && !aui_cf_field_in_array(field_value, $keys_values[condition.key])) {
2749
                                $keys[condition.key][index] = true;
2750
                            } else {
2751
                                $keys[condition.key][index] = false;
2752
                            }
2753
                        } else if (condition.condition === 'greater than') {
2754
                            var field_value = (Array.isArray(current_value) && current_value.length === 1) ? current_value[0] : current_value;
2755
                            if (jQuery.isNumeric(condition.value) && parseInt(field_value) > parseInt(condition.value)) {
2756
                                $keys[condition.key][index] = true;
2757
                            } else {
2758
                                $keys[condition.key][index] = false;
2759
                            }
2760
                        } else if (condition.condition === 'less than') {
2761
                            var field_value = (Array.isArray(current_value) && current_value.length === 1) ? current_value[0] : current_value;
2762
                            if (jQuery.isNumeric(condition.value) && parseInt(field_value) < parseInt(condition.value)) {
2763
                                $keys[condition.key][index] = true;
2764
                            } else {
2765
                                $keys[condition.key][index] = false;
2766
                            }
2767
                        } else if (condition.condition === 'contains') {
2768
                            var avalues = condition.value;
2769
                            if (!Array.isArray(avalues)) {
2770
                                if (jQuery.isNumeric(avalues)) {
2771
                                    avalues = [avalues];
2772
                                } else {
2773
                                    avalues = avalues.split(",");
2774
                                }
2775
                            }
2776
                            switch (field_type) {
2777
                                case 'multiselect':
2778
                                    var found = false;
2779
                                    for (var key in avalues) {
2780
                                        var svalue = jQuery.isNumeric(avalues[key]) ? avalues[key] : (avalues[key]).trim();
2781
                                        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)))) {
2782
                                            found = true;
2783
                                        }
2784
                                    }
2785
                    
2786
                                    if (found) {
2787
                                        $keys[condition.key][index] = true;
2788
                                    } else {
2789
                                        $keys[condition.key][index] = false;
2790
                                    }
2791
                                    break;
2792
                                case 'checkbox':
2793
                                    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)))) {
2794
                                        $keys[condition.key][index] = true;
2795
                                    } else {
2796
                                        $keys[condition.key][index] = false;
2797
                                    }
2798
                                    break;
2799
                                default:
2800
                                    if (typeof $keys[condition.key][index] === 'undefined') {
2801
                                        if (current_value && current_value.indexOf(condition.value) >= 0 && aui_cf_field_in_array(current_value, $keys_values[condition.key], false, true)) {
2802
                                            $keys[condition.key][index] = true;
2803
                                        } else {
2804
                                            $keys[condition.key][index] = false;
2805
                                        }
2806
                                    }
2807
                                    break;
2808
                            }
2809
                        }
2810
                    });
2811
2812
                    jQuery.each($keys, function(index, field) {
2813
                        if (aui_cf_field_in_array(true, field)) {
2814
                            aui_cf_field_apply_action($el, $key_rules[index], true);
2815
                        } else {
2816
                            aui_cf_field_apply_action($el, $key_rules[index], false);
2817
                        }
2818
                    });
2819
2820
                    /* Trigger field change */
2821
                    if ($keys.length) {
2822
                        $el.trigger('aui_cf_field_on_change');
2823
                    }
2824
                }
2825
2826
                /**
2827
                 * Get the field element.
2828
                 */
2829
                function aui_cf_field_get_element($el) {
2830
                    var el = $el.find('input:not("[data-ignore-rule]"),textarea,select'), type = aui_cf_field_get_type($el);
2831
                    if (type && window._aui_cf_field_elements && typeof window._aui_cf_field_elements == 'object' && typeof window._aui_cf_field_elements[type] != 'undefined') {
2832
                        el = window._aui_cf_field_elements[type];
2833
                    }
2834
                    return el;
2835
                }
2836
2837
                /**
2838
                 * Get the field type.
2839
                 */
2840
                function aui_cf_field_get_type($el) {
2841
                    return $el.data('rule-type');
2842
                }
2843
2844
                /**
2845
                 * Get the field value.
2846
                 */
2847
                function aui_cf_field_get_value($el) {
2848
                    var current_value = $el.val();
2849
2850
                    if ($el.is(':checkbox')) {
2851
                        current_value = '';
2852
                        if ($el.parents('[data-rule-key]').find('input:checked').length > 1) {
2853
                            $el.parents('[data-rule-key]').find('input:checked').each(function() {
2854
                                current_value = current_value + jQuery(this).val() + ' ';
2855
                            });
2856
                        } else {
2857
                            if ($el.parents('[data-rule-key]').find('input:checked').length >= 1) {
2858
                                current_value = $el.parents('[data-rule-key]').find('input:checked').val();
2859
                            }
2860
                        }
2861
                    }
2862
2863
                    if ($el.is(':radio')) {
2864
                        current_value = $el.parents('[data-rule-key]').find('input[type=radio]:checked').val();
2865
                    }
2866
2867
                    return current_value;
2868
                }
2869
2870
                /**
2871
                 * Get the field default value.
2872
                 */
2873
                function aui_cf_field_get_default_value($el) {
2874
                    var value = '', type = aui_cf_field_get_type($el);
2875
2876
                    switch (type) {
2877
                        case 'text':
2878
                        case 'number':
2879
                        case 'date':
2880
                        case 'textarea':
2881
                        case 'select':
2882
                            value = $el.find('input:text,input[type="number"],textarea,select').val();
2883
                            break;
2884
                        case 'phone':
2885
                        case 'email':
2886
                        case 'color':
2887
                        case 'url':
2888
                        case 'hidden':
2889
                        case 'password':
2890
                        case 'file':
2891
                            value = $el.find('input[type="' + type + '"]').val();
2892
                            break;
2893
                        case 'multiselect':
2894
                            value = $el.find('select').val();
2895
                            break;
2896
                        case 'radio':
2897
                            if ($el.find('input[type="radio"]:checked').length >= 1) {
2898
                                value = $el.find('input[type="radio"]:checked').val();
2899
                            }
2900
                            break;
2901
                        case 'checkbox':
2902
                            if ($el.find('input[type="checkbox"]:checked').length >= 1) {
2903
                                if ($el.find('input[type="checkbox"]:checked').length > 1) {
2904
                                    var values = [];
2905
                                    values.push(value);
2906
                                    $el.find('input[type="checkbox"]:checked').each(function() {
2907
                                        values.push(jQuery(this).val());
2908
                                    });
2909
                                    value = values;
2910
                                } else {
2911
                                    value = $el.find('input[type="checkbox"]:checked').val();
2912
                                }
2913
                            }
2914
                            break;
2915
                        default:
2916
                            if (window._aui_cf_field_default_values && typeof window._aui_cf_field_default_values == 'object' && typeof window._aui_cf_field_default_values[type] != 'undefined') {
2917
                                value = window._aui_cf_field_default_values[type];
2918
                            }
2919
                            break;
2920
                    }
2921
                    return {
2922
                        type: type,
2923
                        value: value
2924
                    };
2925
                }
2926
2927
                /**
2928
                 * Reset field default value.
2929
                 */
2930
                function aui_cf_field_reset_default_value($el) {
2931
                    var type = aui_cf_field_get_type($el), key = $el.data('rule-key'), field = aui_cf_field_default_values[key];
2932
2933
                    switch (type) {
2934
                        case 'text':
2935
                        case 'number':
2936
                        case 'date':
2937
                        case 'textarea':
2938
                            $el.find('input:text,input[type="number"],textarea').val(field.value);
2939
                            break;
2940
                        case 'phone':
2941
                        case 'email':
2942
                        case 'color':
2943
                        case 'url':
2944
                        case 'hidden':
2945
                        case 'password':
2946
                        case 'file':
2947
                            $el.find('input[type="' + type + '"]').val(field.value);
2948
                            break;
2949
                        case 'select':
2950
                            $el.find('select').find('option').prop('selected', false);
2951
                            $el.find('select').val(field.value);
2952
                            $el.find('select').trigger('change');
2953
                            break;
2954
                        case 'multiselect':
2955
                            $el.find('select').find('option').prop('selected', false);
2956
                            if ((typeof field.value === 'object' || typeof field.value === 'array') && !field.value.length && $el.find('select option:first').text() == '') {
2957
                                $el.find('select option:first').remove(); // Clear first option to show placeholder.
2958
                            }
2959
                            if (typeof field.value === 'string') {
2960
                                $el.find('select').val(field.value);
2961
                            } else {
2962
                                jQuery.each(field.value, function(i, v) {
2963
                                    $el.find('select').find('option[value="' + v + '"]').attr('selected', true);
2964
                                });
2965
                            }
2966
                            $el.find('select').trigger('change');
2967
                            break;
2968
                        case 'checkbox':
2969
                            if ($el.find('input[type="checkbox"]:checked').length >= 1) {
2970
                                $el.find('input[type="checkbox"]:checked').prop('checked', false);
2971
                                if (Array.isArray(field.value)) {
2972
                                    jQuery.each(field.value, function(i, v) {
2973
                                        $el.find('input[type="checkbox"][value="' + v + '"]').attr('checked', true);
2974
                                    });
2975
                                } else {
2976
                                    $el.find('input[type="checkbox"][value="' + field.value + '"]').attr('checked', true);
2977
                                }
2978
                            }
2979
                            break;
2980
                        case 'radio':
2981
                            if ($el.find('input[type="radio"]:checked').length >= 1) {
2982
                                setTimeout(function() {
2983
                                    $el.find('input[type="radio"]:checked').prop('checked', false);
2984
                                    $el.find('input[type="radio"][value="' + field.value + '"]').attr('checked', true);
2985
                                }, 100);
2986
                            }
2987
                            break;
2988
                        default:
2989
                            jQuery(document.body).trigger('aui_cf_field_reset_default_value', type, $el, field);
2990
                            break;
2991
                    }
2992
2993
                    if (!$el.hasClass('aui-cf-field-has-changed')) {
2994
                        var el = aui_cf_field_get_element($el);
2995
                        if (type === 'radio' || type === 'checkbox') {
2996
                            el = el.find(':checked');
2997
                        }
2998
                        if (el) {
2999
                            el.trigger('change');
3000
                            $el.addClass('aui-cf-field-has-changed');
3001
                        }
3002
                    }
3003
                }
3004
3005
                /**
3006
                 * Get the field children.
3007
                 */
3008
                function aui_cf_field_get_children(field_key) {
3009
                    var rules = [];
3010
                    jQuery.each(aui_cf_field_rules, function(j, rule) {
3011
                        if (rule.field.field === field_key) {
3012
                            rules.push(rule.field.rule);
3013
                        }
3014
                    });
3015
                    return rules;
3016
                }
3017
3018
                /**
3019
                 * Check in array field value.
3020
                 */
3021
                function aui_cf_field_in_array(find, item, exact, match) {
3022
                    var found = false, key;
3023
                    exact = !!exact;
3024
3025
                    for (key in item) {
3026
                        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)) {
3027
                            found = true;
3028
                            break;
3029
                        }
3030
                    }
3031
                    return found;
3032
                }
3033
3034
                /**
3035
                 * App the field condition action.
3036
                 */
3037
                function aui_cf_field_apply_action($el, rule, isTrue) {
3038
                    var $destEl = jQuery('[data-rule-key="' + rule.key + '"]');
3039
3040
                    if (rule.action === 'show' && isTrue) {
3041
                        if ($destEl.is(':hidden')) {
3042
                            aui_cf_field_reset_default_value($destEl);
3043
                        }
3044
                        aui_cf_field_show_element($destEl);
3045
                    } else if (rule.action === 'show' && !isTrue) {
3046
                        aui_cf_field_hide_element($destEl);
3047
                    } else if (rule.action === 'hide' && isTrue) {
3048
                        aui_cf_field_hide_element($destEl);
3049
                    } else if (rule.action === 'hide' && !isTrue) {
3050
                        if ($destEl.is(':hidden')) {
3051
                            aui_cf_field_reset_default_value($destEl);
3052
                        }
3053
                        aui_cf_field_show_element($destEl);
3054
                    }
3055
                    return $el.removeClass('aui-cf-field-has-changed');
3056
                }
3057
3058
                /**
3059
                 * Show field element.
3060
                 */
3061
                function aui_cf_field_show_element($el) {
3062
                    $el.removeClass('d-none').show();
3063
3064
                    $el.find('.aui-cf-req').each(function() {
3065
                        if (jQuery(this).data('rule-req')) {
3066
                            jQuery(this).removeAttr('required').prop('required', true);
3067
                        }
3068
                        if (jQuery(this).data('rule-oninvalid')) {
3069
                            jQuery(this).removeAttr('oninvalid').attr('oninvalid', jQuery(this).data('rule-oninvalid'));
3070
                        }
3071
                    });
3072
3073
                    if (window && window.navigator.userAgent.indexOf("MSIE") !== -1) {
3074
                        $el.css({
3075
                            "visibility": "visible"
3076
                        });
3077
                    }
3078
                }
3079
3080
                /**
3081
                 * Hide field element.
3082
                 */
3083
                function aui_cf_field_hide_element($el) {
3084
                    $el.addClass('d-none').hide();
3085
3086
                    $el.find('.aui-cf-req').each(function() {
3087
                        if (jQuery(this).data('rule-req')) {
3088
                            jQuery(this).removeAttr('required');
3089
                        }
3090
                        if (jQuery(this).data('rule-oninvalid')) {
3091
                            jQuery(this).removeAttr('oninvalid');
3092
                        }
3093
                    });
3094
3095
                    if (window && window.navigator.userAgent.indexOf("MSIE") !== -1) {
3096
                        $el.css({
3097
                            "visibility": "hidden"
3098
                        });
3099
                    }
3100
                }
3101
				<?php do_action( 'aui_conditional_fields_js', $this ); ?>
3102
            </script>
3103
			<?php
3104
			$output = ob_get_clean();
3105
3106
			return str_replace( array( '<script>', '</script>' ), '', self::minify_js( $output ) );
3107
		}
3108
	}
3109
3110
	/**
3111
	 * Run the class if found.
3112
	 */
3113
	AyeCode_UI_Settings::instance();
3114
}