Passed
Push — master ( 9fabf9...229147 )
by Stiofan
14:51
created

AyeCode_UI_Settings::hex_to_rgb()   B

Complexity

Conditions 7
Paths 10

Size

Total Lines 27
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 13
nc 10
nop 1
dl 0
loc 27
rs 8.8333
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.15';
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>'. wp_kses_post( $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 ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
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>'. wp_kses_post( $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( esc_attr__( '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 esc_attr( $this->name ); ?></h1>
886
                <p><?php echo esc_html( apply_filters( 'ayecode-ui-settings-message', __("Here you can adjust settings if you are having compatibility issues.", 'ayecode-connect' ) ) );?></p>
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 esc_html_e( 'BootStrap Version', 'ayecode-connect' ); ?></h2>
894
                    <p><?php echo esc_html( apply_filters( 'ayecode-ui-version-settings-message', __("V5 is recommended, however if you have another plugin installed using v4, you may need to use v4 also.", 'ayecode-connect' ) ) );?></p>
895
	                <div class="bsui"><?php
896
	                if ( ! empty( $overrides ) ) {
897
		                echo aui()->alert(array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
898
			                'type'=> 'info',
899
			                'content'=> esc_attr__("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 esc_html_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 esc_html_e( 'v5 (recommended)', 'ayecode-connect' ); ?></option>
910
                                    <option value="4" <?php selected( $this->settings['bs_ver'], '4' ); ?>><?php esc_html_e( 'v4 (legacy)', 'ayecode-connect' ); ?></option>
911
                                </select>
912
                            </td>
913
                        </tr>
914
                    </table>
915
916
                    <h2><?php esc_html_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 esc_html_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 esc_html_e( 'Compatibility Mode (default)', 'ayecode-connect' ); ?></option>
923
                                    <option value="core" <?php selected( $this->settings['css'], 'core' ); ?>><?php esc_html_e( 'Full Mode', 'ayecode-connect' ); ?></option>
924
                                    <option	value="" <?php selected( $this->settings['css'], '' ); ?>><?php esc_html_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 esc_html_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 esc_html_e( 'Core + Popper (default)', 'ayecode-connect' ); ?></option>
934
                                    <option value="popper" <?php selected( $this->settings['js'], 'popper' ); ?>><?php esc_html_e( 'Popper', 'ayecode-connect' ); ?></option>
935
                                    <option value="required" <?php selected( $this->settings['js'], 'required' ); ?>><?php esc_html_e( 'Required functions only', 'ayecode-connect' ); ?></option>
936
                                    <option	value="" <?php selected( $this->settings['js'], '' ); ?>><?php esc_html_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 esc_html_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 esc_html_e("Our font sizing is rem (responsive based) here you can set the html font size in-case your theme is setting it too low.", 'ayecode-connect' );?></p>
946
                            </td>
947
                        </tr>
948
949
                    </table>
950
951
                    <h2><?php esc_html_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 esc_html_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 esc_html_e( 'Compatibility Mode (default)', 'ayecode-connect' ); ?></option>
958
                                    <option value="core" <?php selected( $this->settings['css_backend'], 'core' ); ?>><?php esc_html_e( 'Full Mode (will cause style issues)', 'ayecode-connect' ); ?></option>
959
                                    <option	value="" <?php selected( $this->settings['css_backend'], '' ); ?>><?php esc_html_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 esc_html_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 esc_html_e( 'Core + Popper (default)', 'ayecode-connect' ); ?></option>
969
                                    <option value="popper" <?php selected( $this->settings['js_backend'], 'popper' ); ?>><?php esc_html_e( 'Popper', 'ayecode-connect' ); ?></option>
970
                                    <option value="required" <?php selected( $this->settings['js_backend'], 'required' ); ?>><?php esc_html_e( 'Required functions only', 'ayecode-connect' ); ?></option>
971
                                    <option	value="" <?php selected( $this->settings['js_backend'], '' ); ?>><?php esc_html_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 esc_html_e( 'Disable load on URL', 'ayecode-connect' ); ?></label></th>
978
                            <td>
979
                                <p><?php esc_html_e( 'If you have backend conflict you can enter a partial URL argument that will disable the loading of AUI on those pages. Add each argument on a new line.', 'ayecode-connect' ); ?></p>
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 esc_textarea( $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 esc_html( $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(); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
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); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
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{' . esc_attr( $css ) . '}' : 'body{' . esc_attr( $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{ " . esc_attr( $headings_css ) . "}"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
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 esc_attr( $bep  . $hn ) . '{'.esc_attr( $h_css ).'}';
1266
                             }
1267
                        }
1268
1269
                    }
1270
				?>
1271
            </style>
1272
			<?php
1273
1274
1275
			/*
1276
			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1277
			 */
1278
			return str_replace( array(
1279
				'<style>',
1280
				'</style>'
1281
			), '', self::minify_css( ob_get_clean() ) );
1282
		}
1283
1284
1285
1286
		/**
1287
		 * Check if we should add booststrap 3 compatibility changes.
1288
		 *
1289
		 * @return bool
1290
		 */
1291
		public static function is_bs3_compat(){
1292
			return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION');
1293
		}
1294
1295
		public static function hex_to_rgb( $hex ) {
1296
			// Remove '#' if present
1297
			$hex = str_replace( '#', '', $hex );
1298
1299
			// Check if input is RGB
1300
			if ( strpos( $hex, 'rgba(' ) === 0 || strpos( $hex, 'rgb(' ) === 0 ) {
1301
				$_rgb = explode( ',', str_replace( array( 'rgba(', 'rgb(', ')' ), '', $hex ) );
1302
1303
				$rgb = ( isset( $_rgb[0] ) ? (int) trim( $_rgb[0] ) : '0' ) . ',';
1304
				$rgb .= ( isset( $_rgb[1] ) ? (int) trim( $_rgb[1] ) : '0' ) . ',';
1305
				$rgb .= ( isset( $_rgb[2] ) ? (int) trim( $_rgb[2] ) : '0' );
1306
1307
				return $rgb;
1308
			}
1309
1310
			// Convert 3-digit hex to 6-digit hex
1311
			if ( strlen( $hex ) == 3 ) {
1312
				$hex = str_repeat( substr( $hex, 0, 1 ), 2 ) . str_repeat( substr( $hex, 1, 1 ), 2 ) . str_repeat( substr( $hex, 2, 1 ), 2 );
1313
			}
1314
1315
			// Convert hex to RGB
1316
			$r = hexdec( substr( $hex, 0, 2 ) );
1317
			$g = hexdec( substr( $hex, 2, 2 ) );
1318
			$b = hexdec( substr( $hex, 4, 2 ) );
1319
1320
			// Return RGB values as an array
1321
			return $r . ',' . $g . ',' . $b;
1322
		}
1323
1324
		/**
1325
		 * Build the CSS to overwrite a bootstrap color variable.
1326
		 *
1327
		 * @param $type
1328
		 * @param $color_code
1329
		 * @param $compatibility
1330
		 *
1331
		 * @return string
1332
		 */
1333
		public static function css_overwrite_bs5($type,$color_code,$compatibility, $hex = '' ){
1334
			global $aui_bs5;
1335
1336
			$is_var = false;
1337
			$is_custom = strpos($type, 'custom-') !== false ? true : false;
1338
			if(!$color_code){return '';}
1339
			if(strpos($color_code, 'var') !== false){
1340
				//if(!sanitize_hex_color($color_code)){
1341
				$color_code = esc_attr($color_code);
1342
				$is_var = true;
1343
//				$color_code = "rgba($color_code, 0.5)";
1344
//                echo '###1'.$color_code.'###';//exit;
1345
			}
1346
1347
//            echo '@@@'.$color_code.'==='.self::hex_to_rgb($color_code);exit;
1348
1349
			if(!$color_code){return '';}
1350
1351
			$rgb = self::hex_to_rgb($hex);
1352
1353
			if($compatibility===true || $compatibility===1){
1354
				$compatibility = '.bsui';
1355
			}elseif(!$compatibility){
1356
				$compatibility = '';
1357
			}else{
1358
				$compatibility = esc_attr($compatibility);
1359
			}
1360
1361
			$prefix = $compatibility ? $compatibility . " " : "";
1362
1363
1364
            $output = '';
1365
1366
//            echo '####'.$color_code;exit;
1367
1368
			$type = sanitize_html_class($type);
1369
1370
			/**
1371
			 * c = color, b = background color, o = border-color, f = fill
1372
			 */
1373
			$selectors = array(
1374
				".btn-{$type}"                                              => array( 'b', 'o' ),
1375
				".btn-{$type}.disabled"                                     => array( 'b', 'o' ),
1376
				".btn-{$type}:disabled"                                     => array( 'b', 'o' ),
1377
				".btn-outline-{$type}"                                      => array( 'c', 'o' ),
1378
				".btn-outline-{$type}:hover"                                => array( 'b', 'o' ),
1379
				".btn-outline-{$type}:not(:disabled):not(.disabled).active" => array( 'b', 'o' ),
1380
				".btn-outline-{$type}:not(:disabled):not(.disabled):active" => array( 'b', 'o' ),
1381
				".show>.btn-outline-{$type}.dropdown-toggle"                => array( 'b', 'o' ),
1382
				".badge-{$type}"                                            => array( 'b' ),
1383
				".alert-{$type}"                                            => array( 'b', 'o' ),
1384
				".bg-{$type}"                                               => array( 'b', 'f' ),
1385
				".btn-link.btn-{$type}"                                     => array( 'c' ),
1386
				".text-{$type}"                                     => array( 'c' ),
1387
			);
1388
1389
			if ( $aui_bs5 ) {
1390
				unset($selectors[".alert-{$type}" ]);
1391
			}
1392
1393
			if ( $type == 'primary' ) {
1394
				$selectors = $selectors + array(
1395
						'a'                                                                                                    => array( 'c' ),
1396
						'.btn-link'                                                                                            => array( 'c' ),
1397
						'.dropdown-item.active'                                                                                => array( 'b' ),
1398
						'.custom-control-input:checked~.custom-control-label::before'                                          => array(
1399
							'b',
1400
							'o'
1401
						),
1402
						'.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before'                   => array(
1403
							'b',
1404
							'o'
1405
						),
1406
						'.nav-pills .nav-link.active'                                                                          => array( 'b' ),
1407
						'.nav-pills .show>.nav-link'                                                                           => array( 'b' ),
1408
						'.page-link'                                                                                           => array( 'c' ),
1409
						'.page-item.active .page-link'                                                                         => array(
1410
							'b',
1411
							'o'
1412
						),
1413
						'.progress-bar'                                                                                        => array( 'b' ),
1414
						'.list-group-item.active'                                                                              => array(
1415
							'b',
1416
							'o'
1417
						),
1418
						'.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array( 'b' ),
1419
					);
1420
			}
1421
1422
1423
1424
            // link
1425
			if ( $type === 'primary' ) {
1426
				$output .= 'html body {--bs-link-hover-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .75); --bs-link-color: var(--bs-'.esc_attr($type).'); }';
1427
				$output .= $prefix . ' .breadcrumb{--bs-breadcrumb-item-active-color: '.esc_attr($color_code).';  }';
1428
				$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).'; }';
1429
1430
				$output .= $prefix . ' a{color: var(--bs-'.esc_attr($type).');}';
1431
				$output .= $prefix . ' .text-primary{color: var(--bs-'.esc_attr($type).') !important;}';
1432
1433
                // dropdown
1434
				$output .= $prefix . ' .dropdown-menu{--bs-dropdown-link-hover-color: var(--bs-'.esc_attr($type).'); --bs-dropdown-link-active-color: var(--bs-'.esc_attr($type).');}';
1435
1436
                // pagination
1437
				$output .= $prefix . ' .pagination{--bs-pagination-hover-color: var(--bs-'.esc_attr($type).'); --bs-pagination-active-bg: var(--bs-'.esc_attr($type).');}';
1438
1439
			}
1440
1441
			$output .= $prefix . ' .link-'.esc_attr($type).' {color: var(--bs-'.esc_attr($type).'-rgb) !important;}';
1442
			$output .= $prefix . ' .link-'.esc_attr($type).':hover {color: rgba(var(--bs-'.esc_attr($type).'-rgb), .8) !important;}';
1443
1444
			//  buttons
1445
			$output .= $prefix . ' .btn-'.esc_attr($type).'{';
1446
			$output .= ' 
1447
            --bs-btn-bg: '.esc_attr($color_code).';
1448
            --bs-btn-border-color: '.esc_attr($color_code).';
1449
            --bs-btn-hover-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1450
            --bs-btn-hover-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1451
            --bs-btn-focus-shadow-rgb: --bs-'.esc_attr($type).'-rgb;
1452
            --bs-btn-active-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1453
            --bs-btn-active-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1454
            --bs-btn-active-shadow: unset;
1455
            --bs-btn-disabled-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .5);
1456
            --bs-btn-disabled-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .1);
1457
            ';
1458
//			$output .= '
1459
//		    --bs-btn-color: #fff;
1460
//			--bs-btn-hover-color: #fff;
1461
//			--bs-btn-active-color: #fff;
1462
//			--bs-btn-disabled-color: #fff;
1463
//            ';
1464
			$output .= '}';
1465
1466
			//  buttons outline
1467
			$output .= $prefix . ' .btn-outline-'.esc_attr($type).'{';
1468
			$output .= ' 
1469
			--bs-btn-color: '.esc_attr($color_code).';
1470
            --bs-btn-border-color: '.esc_attr($color_code).';
1471
            --bs-btn-hover-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1472
            --bs-btn-hover-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1473
            --bs-btn-focus-shadow-rgb: --bs-'.esc_attr($type).'-rgb;
1474
            --bs-btn-active-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1475
            --bs-btn-active-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1476
            --bs-btn-active-shadow: unset;
1477
            --bs-btn-disabled-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .5);
1478
            --bs-btn-disabled-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .1);
1479
            ';
1480
//			$output .= '
1481
//		    --bs-btn-color: #fff;
1482
//			--bs-btn-hover-color: #fff;
1483
//			--bs-btn-active-color: #fff;
1484
//			--bs-btn-disabled-color: #fff;
1485
//            ';
1486
			$output .= '}';
1487
1488
1489
            // button hover
1490
			$output .= $prefix . ' .btn-'.esc_attr($type).':hover{';
1491
			$output .= ' 
1492
            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);
1493
            }
1494
            ';
1495
1496
1497
			if ( $aui_bs5 ) {
1498
//				$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).'; }';
1499
				$output .= 'html body {--bs-'.esc_attr($type).': '.esc_attr($color_code).'; }';
1500
				$output .= 'html body {--bs-'.esc_attr($type).'-rgb: '.$rgb.'; }';
1501
			}
1502
1503
1504
			if ( $is_custom ) {
1505
1506
//				echo '###'.$type;exit;
1507
1508
				// build rules into each type
1509
				foreach($selectors as $selector => $types){
1510
					$selector = $compatibility ? $compatibility . " ".$selector : $selector;
1511
					$types = array_combine($types,$types);
1512
					if(isset($types['c'])){$color[] = $selector;}
1513
					if(isset($types['b'])){$background[] = $selector;}
1514
					if(isset($types['o'])){$border[] = $selector;}
1515
					if(isset($types['f'])){$fill[] = $selector;}
1516
				}
1517
1518
//				// build rules into each type
1519
//				foreach($important_selectors as $selector => $types){
1520
//					$selector = $compatibility ? $compatibility . " ".$selector : $selector;
1521
//					$types = array_combine($types,$types);
1522
//					if(isset($types['c'])){$color_i[] = $selector;}
1523
//					if(isset($types['b'])){$background_i[] = $selector;}
1524
//					if(isset($types['o'])){$border_i[] = $selector;}
1525
//					if(isset($types['f'])){$fill_i[] = $selector;}
1526
//				}
1527
1528
				// add any color rules
1529
				if(!empty($color)){
1530
					$output .= implode(",",$color) . "{color: $color_code;} ";
1531
				}
1532
				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...
1533
					$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1534
				}
1535
1536
				// add any background color rules
1537
				if(!empty($background)){
1538
					$output .= implode(",",$background) . "{background-color: $color_code;} ";
1539
				}
1540
				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...
1541
					$output .= $aui_bs5 ? '' : implode(",",$background_i) . "{background-color: $color_code !important;} ";
1542
//				$output .= implode(",",$background_i) . "{background-color: rgba(var(--bs-primary-rgb), var(--bs-bg-opacity)) !important;} ";
1543
				}
1544
1545
				// add any border color rules
1546
				if(!empty($border)){
1547
					$output .= implode(",",$border) . "{border-color: $color_code;} ";
1548
				}
1549
				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...
1550
					$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1551
				}
1552
1553
				// add any fill color rules
1554
				if(!empty($fill)){
1555
					$output .= implode(",",$fill) . "{fill: $color_code;} ";
1556
				}
1557
				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...
1558
					$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1559
				}
1560
1561
			}
1562
1563
1564
1565
1566
			$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;' : '';
1567
			// darken
1568
			$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

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

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

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

2086
			$darker_075 = self::css_hex_lighten_darken($color_code,/** @scrutinizer ignore-type */ "-0.075");
Loading history...
2087
			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
2088
			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
2089
2090
			// lighten
2091
			$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...
2092
2093
			// opacity see https://css-tricks.com/8-digit-hex-codes/
2094
			$op_25 = $color_code."40"; // 25% opacity
2095
2096
2097
			// button states
2098
			$output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
2099
			$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;} ";
2100
			$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.";} ";
2101
			$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;} ";
2102
2103
2104
			return $output;
2105
		}
2106
2107
		/**
2108
		 * Increases or decreases the brightness of a color by a percentage of the current brightness.
2109
		 *
2110
		 * @param   string  $hexCode        Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF`
2111
		 * @param   float   $adjustPercent  A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker.
2112
		 *
2113
		 * @return  string
2114
		 */
2115
		public static function css_hex_lighten_darken($hexCode, $adjustPercent) {
2116
			$hexCode = ltrim($hexCode, '#');
2117
2118
			if ( strpos( $hexCode, 'rgba(' ) !== false || strpos( $hexCode, 'rgb(' ) !== false ) {
2119
				return $hexCode;
2120
			}
2121
2122
			if (strlen($hexCode) == 3) {
2123
				$hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2];
2124
			}
2125
2126
			$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

2126
			$hexCode = array_map('hexdec', /** @scrutinizer ignore-type */ str_split($hexCode, 2));
Loading history...
2127
2128
			foreach ($hexCode as & $color) {
2129
				$adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color;
2130
				$adjustAmount = ceil($adjustableLimit * $adjustPercent);
2131
2132
				$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

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