Passed
Push — master ( 9dee83...fe7410 )
by Stiofan
06:39
created

AyeCode_UI_Settings::is_beaver_preview()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 7
rs 10
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.28';
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
				$rtl = is_rtl() && ! $aui_bs5 ? '-rtl' : '';
468
                $bs_ver = $this->settings['bs_ver'] == '5' ? '-v5' : '';
469
470
				if ( $this->settings[ $css_setting ] ) {
471
					$compatibility = $this->settings[$css_setting]=='core' ? false : true;
472
					$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';
473
474
					wp_register_style( 'ayecode-ui', $url, array(), $this->version );
475
					wp_enqueue_style( 'ayecode-ui' );
476
477
					if ( is_admin() && ( !empty($_REQUEST['postType']) || self::is_block_editor() ) && ( defined( 'BLOCKSTRAP_VERSION' ) || defined( 'AUI_FSE' ) )  ) {
478
						$url = $this->url.'assets'.$bs_ver.'/css/ayecode-ui-fse.css';
479
						wp_register_style( 'ayecode-ui-fse', $url, array(), $this->version );
480
						wp_enqueue_style( 'ayecode-ui-fse' );
481
						$load_fse = true;
482
					}
483
484
					// flatpickr
485
					wp_register_style( 'flatpickr', $this->url.'assets'.$bs_ver.'/css/flatpickr.min.css', array(), $this->version );
486
487
					// fix some wp-admin issues
488
					if(is_admin()){
489
						$custom_css = "
490
                body{
491
                    background-color: #f1f1f1;
492
                    font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif;
493
                    font-size:13px;
494
                }
495
                a {
496
				    color: #0073aa;
497
				    text-decoration: underline;
498
				}
499
                label {
500
				    display: initial;
501
				    margin-bottom: 0;
502
				}
503
				input, select {
504
				    margin: 1px;
505
				    line-height: initial;
506
				}
507
				th, td, div, h2 {
508
				    box-sizing: content-box;
509
				}
510
				h1, h2, h3, h4, h5, h6 {
511
				    display: block;
512
				    font-weight: 600;
513
				}
514
				h2,h3 {
515
				    font-size: 1.3em;
516
				    margin: 1em 0
517
				}
518
				.blocks-widgets-container .bsui *{
519
					box-sizing: border-box;
520
				}
521
				.bs-tooltip-top .arrow{
522
					margin-left:0px;
523
				}
524
				
525
				.custom-switch input[type=checkbox]{
526
				    display:none;
527
				}
528
                ";
529
530
						// @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377
531
						$custom_css .= "
532
						.edit-post-sidebar input[type=color].components-text-control__input{
533
						    padding: 0;
534
						}
535
					";
536
						wp_add_inline_style( 'ayecode-ui', $custom_css );
537
					}
538
539
					// custom changes
540
					if ( $load_fse ) {
541
						wp_add_inline_style( 'ayecode-ui-fse', self::custom_css($compatibility, true) );
542
					}else{
543
						wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) );
544
					}
545
				}
546
			}
547
		}
548
549
		/**
550
		 * Get inline script used if bootstrap enqueued
551
		 *
552
		 * If this remains small then its best to use this than to add another JS file.
553
		 */
554
		public function inline_script() {
555
            global $aui_bs5;
556
			// Flatpickr calendar locale
557
			$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...
558
559
			ob_start();
560
			if ( $aui_bs5 ) {
561
				include_once( dirname( __FILE__ ) . '/inc/bs5-js.php' );
562
			}else{
563
				include_once( dirname( __FILE__ ) . '/inc/bs4-js.php' );
564
            }
565
566
			$output = ob_get_clean();
567
568
			/*
569
			 * We only add the <script> tags for code highlighting, so we strip them from the output.
570
			 */
571
			return str_replace( array(
572
				'<script>',
573
				'</script>'
574
			), '', self::minify_js($output) );
575
		}
576
577
578
		/**
579
		 * JS to help with conflict issues with other plugins and themes using bootstrap v3.
580
		 *
581
		 * @TODO we may need this when other conflicts arrise.
582
		 * @return mixed
583
		 */
584
		public static function bs3_compat_js() {
585
			ob_start();
586
			?>
587
            <script>
588
				<?php if( defined( 'FUSION_BUILDER_VERSION' ) ){ ?>
589
                /* With Avada builder */
590
591
				<?php } ?>
592
            </script>
593
			<?php
594
			return str_replace( array(
595
				'<script>',
596
				'</script>'
597
			), '', ob_get_clean());
598
		}
599
600
		/**
601
		 * Get inline script used if bootstrap file browser enqueued.
602
		 *
603
		 * If this remains small then its best to use this than to add another JS file.
604
		 */
605
		public function inline_script_file_browser(){
606
			ob_start();
607
			?>
608
            <script>
609
                // run on doc ready
610
                jQuery(document).ready(function () {
611
                    bsCustomFileInput.init();
612
                });
613
            </script>
614
			<?php
615
			$output = ob_get_clean();
616
617
			/*
618
			 * We only add the <script> tags for code highlighting, so we strip them from the output.
619
			 */
620
			return str_replace( array(
621
				'<script>',
622
				'</script>'
623
			), '', $output );
624
		}
625
626
		/**
627
		 * Adds the Font Awesome JS.
628
		 */
629
		public function enqueue_scripts() {
630
631
			if( is_admin() && !$this->is_aui_screen()){
632
				// don't add wp-admin scripts if not requested to
633
			}else {
634
635
				$js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend';
636
637
				$bs_ver = $this->settings['bs_ver'] == '5' ? '-v5' : '';
638
639
				// select2
640
				wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version );
641
642
				// flatpickr
643
				wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->version );
644
645
				// iconpicker
646
				if ( defined( 'FAS_ICONPICKER_JS_URL' ) ) {
647
					wp_register_script( 'iconpicker', FAS_ICONPICKER_JS_URL, array(), $this->version );
648
				}else{
649
					wp_register_script( 'iconpicker', $this->url . 'assets/js/fa-iconpicker.min.js', array(), $this->version );
650
				}
651
652
				// Bootstrap file browser
653
				wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version );
654
				wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() );
655
656
				$load_inline = false;
657
658
				if ( $this->settings[ $js_setting ] == 'core-popper' ) {
659
					// Bootstrap bundle
660
					$url = $this->url . 'assets' . $bs_ver . '/js/bootstrap.bundle.min.js';
661
					wp_register_script( 'bootstrap-js-bundle', $url, array(
662
						'select2',
663
						'jquery'
664
					), $this->version, $this->is_bs3_compat() );
665
					// if in admin then add to footer for compatibility.
666
					is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' );
667
					$script = $this->inline_script();
668
					wp_add_inline_script( 'bootstrap-js-bundle', $script );
669
				} elseif ( $this->settings[ $js_setting ] == 'popper' ) {
670
					$url = $this->url . 'assets/js/popper.min.js'; //@todo we need to update this to bs5
671
					wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->version );
672
					wp_enqueue_script( 'bootstrap-js-popper' );
673
					$load_inline = true;
674
				} else {
675
					$load_inline = true;
676
				}
677
678
				// Load needed inline scripts by faking the loading of a script if the main script is not being loaded
679
				if ( $load_inline ) {
680
					wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) );
681
					wp_enqueue_script( 'bootstrap-dummy' );
682
					$script = $this->inline_script();
683
					wp_add_inline_script( 'bootstrap-dummy', $script );
684
				}
685
			}
686
687
		}
688
689
		/**
690
		 * Enqueue flatpickr if called.
691
		 */
692
		public function enqueue_flatpickr(){
693
			wp_enqueue_style( 'flatpickr' );
694
			wp_enqueue_script( 'flatpickr' );
695
		}
696
697
		/**
698
		 * Enqueue iconpicker if called.
699
		 */
700
		public function enqueue_iconpicker(){
701
			wp_enqueue_style( 'iconpicker' );
702
			wp_enqueue_script( 'iconpicker' );
703
		}
704
705
		/**
706
		 * Get the url path to the current folder.
707
		 *
708
		 * @return string
709
		 */
710
		public function get_url() {
711
			$content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) );
712
			$content_url = untrailingslashit( WP_CONTENT_URL );
713
714
			// Replace http:// to https://.
715
			if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) {
716
				$content_url = str_replace( 'http://', 'https://', $content_url );
717
			}
718
719
			// Check if we are inside a plugin
720
			$file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) );
721
			$url = str_replace( $content_dir, $content_url, $file_dir );
722
723
			return trailingslashit( $url );
724
		}
725
726
		/**
727
		 * Get the url path to the current folder.
728
		 *
729
		 * @return string
730
		 */
731
		public function get_url_old() {
732
733
			$url = '';
734
			// check if we are inside a plugin
735
			$file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) );
736
737
			// add check in-case user has changed wp-content dir name.
738
			$wp_content_folder_name = basename(WP_CONTENT_DIR);
739
			$dir_parts = explode("/$wp_content_folder_name/",$file_dir);
740
			$url_parts = explode("/$wp_content_folder_name/",plugins_url());
741
742
			if(!empty($url_parts[0]) && !empty($dir_parts[1])){
743
				$url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] );
744
			}
745
746
			return $url;
747
		}
748
749
		/**
750
		 * Register the database settings with WordPress.
751
		 */
752
		public function register_settings() {
753
			register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' );
754
		}
755
756
		/**
757
		 * Add the WordPress settings menu item.
758
		 * @since 1.0.10 Calling function name direct will fail theme check so we don't.
759
		 */
760
		public function menu_item() {
761
			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
762
			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array(
763
				$this,
764
				'settings_page'
765
			) );
766
		}
767
768
		/**
769
		 * Get a list of themes and their default JS settings.
770
		 *
771
		 * @return array
772
		 */
773
		public function theme_js_settings(){
774
			return array(
775
				'ayetheme' => 'popper',
776
				'listimia' => 'required',
777
				'listimia_backend' => 'core-popper',
778
				//'avada'    => 'required', // removed as we now add compatibility
779
			);
780
		}
781
782
		/**
783
         * Get the date the site was installed.
784
         *
785
		 * @return false|string
786
		 */
787
        public function get_site_install_date() {
788
	        global $wpdb; // This gives you access to the WordPress database object
789
790
	        // Prepare the SQL query to get the oldest registration date
791
	        $query = "SELECT MIN(user_registered) AS oldest_registration_date FROM {$wpdb->users}";
792
793
	        // Execute the query
794
	        $date = $wpdb->get_var( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
795
796
	        return $date ? $date : false;
797
        }
798
799
		/**
800
		 * Show admin notice if backend scripts not loaded.
801
		 */
802
		public function show_admin_version_notice(){
803
			$fix_url = admin_url("options-general.php?page=ayecode-ui-settings" );
804
			$button = '<a href="'.esc_url($fix_url).'" class="button-primary">View Settings</a>';
805
			$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;
806
			echo '<div class="notice notice-error aui-settings-error-notice"><p>'. wp_kses_post( $message ).'</p></div>';
807
		}
808
809
		/**
810
		 * Get the current Font Awesome output settings.
811
		 *
812
		 * @return array The array of settings.
813
		 */
814
		public function get_settings() {
815
816
			$db_settings = get_option( 'ayecode-ui-settings' );
817
818
            // Maybe show default version notice
819
			$site_install_date = new DateTime( self::get_site_install_date() );
0 ignored issues
show
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

819
			$site_install_date = new DateTime( /** @scrutinizer ignore-type */ self::get_site_install_date() );
Loading history...
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

819
			$site_install_date = new DateTime( self::/** @scrutinizer ignore-call */ get_site_install_date() );
Loading history...
820
			$switch_over_date = new DateTime("2024-02-01");
821
			if ( empty( $db_settings ) && $site_install_date < $switch_over_date ) {
822
				add_action( 'admin_notices', array( $this, 'show_admin_version_notice' ) );
823
			}
824
825
			$js_default = 'core-popper';
826
			$js_default_backend = $js_default;
827
828
			// maybe set defaults (if no settings set)
829
			if(empty($db_settings)){
830
				$active_theme = strtolower( get_template() ); // active parent theme.
831
				$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

831
				/** @scrutinizer ignore-call */ 
832
    $theme_js_settings = self::theme_js_settings();
Loading history...
832
				if(isset($theme_js_settings[$active_theme])){
833
					$js_default = $theme_js_settings[$active_theme];
834
					$js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default;
835
				}
836
			}
837
838
			/**
839
			 * Filter the default settings.
840
			 */
841
			$defaults = apply_filters( 'ayecode-ui-default-settings', array(
842
				'css'            => 'compatibility', // core, compatibility
843
				'js'             => $js_default, // js to load, core-popper, popper
844
				'html_font_size' => '16', // js to load, core-popper, popper
845
				'css_backend'    => 'compatibility', // core, compatibility
846
				'js_backend'     => $js_default_backend, // js to load, core-popper, popper
847
				'disable_admin'  => '', // URL snippets to disable loading on admin
848
                'bs_ver'         => '5', // The default bootstrap version to sue by default
849
			), $db_settings );
850
851
			$settings = wp_parse_args( $db_settings, $defaults );
852
853
			/**
854
			 * Filter the Bootstrap settings.
855
			 *
856
			 * @todo if we add this filer people might use it and then it defeats the purpose of this class :/
857
			 */
858
			return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults );
859
		}
860
861
862
		/**
863
		 * The settings page html output.
864
		 */
865
		public function settings_page() {
866
			if ( ! current_user_can( 'manage_options' ) ) {
867
				wp_die( esc_attr__( 'You do not have sufficient permissions to access this page.', 'ayecode-connect' ) );
868
			}
869
            $overrides = apply_filters( 'ayecode-ui-settings', array(), array(), array() );
870
871
			?>
872
            <div class="wrap">
873
                <h1><?php echo esc_attr( $this->name ); ?></h1>
874
                <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>
875
                <form method="post" action="options.php">
876
					<?php
877
					settings_fields( 'ayecode-ui-settings' );
878
					do_settings_sections( 'ayecode-ui-settings' );
879
					?>
880
881
                    <h2><?php esc_html_e( 'BootStrap Version', 'ayecode-connect' ); ?></h2>
882
                    <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>
883
	                <div class="bsui"><?php
884
	                if ( ! empty( $overrides ) ) {
885
		                echo aui()->alert(array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
886
			                'type'=> 'info',
887
			                'content'=> esc_attr__("Some options are disabled as your current theme is overriding them.", 'ayecode-connect' )
888
		                ));
889
	                }
890
	                ?>
891
                    </div>
892
                    <table class="form-table wpbs-table-version-settings">
893
                        <tr valign="top">
894
                            <th scope="row"><label for="wpbs-css"><?php esc_html_e( 'Version', 'ayecode-connect' ); ?></label></th>
895
                            <td>
896
                                <select name="ayecode-ui-settings[bs_ver]" id="wpbs-css" <?php echo !empty($overrides['bs_ver']) ? 'disabled' : ''; ?>>
897
                                    <option	value="5" <?php selected( $this->settings['bs_ver'], '5' ); ?>><?php esc_html_e( 'v5 (recommended)', 'ayecode-connect' ); ?></option>
898
                                    <option value="4" <?php selected( $this->settings['bs_ver'], '4' ); ?>><?php esc_html_e( 'v4 (legacy)', 'ayecode-connect' ); ?></option>
899
                                </select>
900
                            </td>
901
                        </tr>
902
                    </table>
903
904
                    <h2><?php esc_html_e( 'Frontend', 'ayecode-connect' ); ?></h2>
905
                    <table class="form-table wpbs-table-settings">
906
                        <tr valign="top">
907
                            <th scope="row"><label for="wpbs-css"><?php esc_html_e( 'Load CSS', 'ayecode-connect' ); ?></label></th>
908
                            <td>
909
                                <select name="ayecode-ui-settings[css]" id="wpbs-css" <?php echo !empty($overrides['css']) ? 'disabled' : ''; ?>>
910
                                    <option	value="compatibility" <?php selected( $this->settings['css'], 'compatibility' ); ?>><?php esc_html_e( 'Compatibility Mode (default)', 'ayecode-connect' ); ?></option>
911
                                    <option value="core" <?php selected( $this->settings['css'], 'core' ); ?>><?php esc_html_e( 'Full Mode', 'ayecode-connect' ); ?></option>
912
                                    <option	value="" <?php selected( $this->settings['css'], '' ); ?>><?php esc_html_e( 'Disabled', 'ayecode-connect' ); ?></option>
913
                                </select>
914
                            </td>
915
                        </tr>
916
917
                        <tr valign="top">
918
                            <th scope="row"><label for="wpbs-js"><?php esc_html_e( 'Load JS', 'ayecode-connect' ); ?></label></th>
919
                            <td>
920
                                <select name="ayecode-ui-settings[js]" id="wpbs-js" <?php echo !empty($overrides['js']) ? 'disabled' : ''; ?>>
921
                                    <option	value="core-popper" <?php selected( $this->settings['js'], 'core-popper' ); ?>><?php esc_html_e( 'Core + Popper (default)', 'ayecode-connect' ); ?></option>
922
                                    <option value="popper" <?php selected( $this->settings['js'], 'popper' ); ?>><?php esc_html_e( 'Popper', 'ayecode-connect' ); ?></option>
923
                                    <option value="required" <?php selected( $this->settings['js'], 'required' ); ?>><?php esc_html_e( 'Required functions only', 'ayecode-connect' ); ?></option>
924
                                    <option	value="" <?php selected( $this->settings['js'], '' ); ?>><?php esc_html_e( 'Disabled (not recommended)', 'ayecode-connect' ); ?></option>
925
                                </select>
926
                            </td>
927
                        </tr>
928
929
                        <tr valign="top">
930
                            <th scope="row"><label for="wpbs-font_size"><?php esc_html_e( 'HTML Font Size (px)', 'ayecode-connect' ); ?></label></th>
931
                            <td>
932
                                <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' : ''; ?> />
933
                                <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>
934
                            </td>
935
                        </tr>
936
937
                    </table>
938
939
                    <h2><?php esc_html_e( 'Backend', 'ayecode-connect' ); ?> (wp-admin)</h2>
940
                    <table class="form-table wpbs-table-settings">
941
                        <tr valign="top">
942
                            <th scope="row"><label for="wpbs-css-admin"><?php esc_html_e( 'Load CSS', 'ayecode-connect' ); ?></label></th>
943
                            <td>
944
                                <select name="ayecode-ui-settings[css_backend]" id="wpbs-css-admin" <?php echo !empty($overrides['css_backend']) ? 'disabled' : ''; ?>>
945
                                    <option	value="compatibility" <?php selected( $this->settings['css_backend'], 'compatibility' ); ?>><?php esc_html_e( 'Compatibility Mode (default)', 'ayecode-connect' ); ?></option>
946
                                    <option value="core" <?php selected( $this->settings['css_backend'], 'core' ); ?>><?php esc_html_e( 'Full Mode (will cause style issues)', 'ayecode-connect' ); ?></option>
947
                                    <option	value="" <?php selected( $this->settings['css_backend'], '' ); ?>><?php esc_html_e( 'Disabled', 'ayecode-connect' ); ?></option>
948
                                </select>
949
                            </td>
950
                        </tr>
951
952
                        <tr valign="top">
953
                            <th scope="row"><label for="wpbs-js-admin"><?php esc_html_e( 'Load JS', 'ayecode-connect' ); ?></label></th>
954
                            <td>
955
                                <select name="ayecode-ui-settings[js_backend]" id="wpbs-js-admin" <?php echo !empty($overrides['js_backend']) ? 'disabled' : ''; ?>>
956
                                    <option	value="core-popper" <?php selected( $this->settings['js_backend'], 'core-popper' ); ?>><?php esc_html_e( 'Core + Popper (default)', 'ayecode-connect' ); ?></option>
957
                                    <option value="popper" <?php selected( $this->settings['js_backend'], 'popper' ); ?>><?php esc_html_e( 'Popper', 'ayecode-connect' ); ?></option>
958
                                    <option value="required" <?php selected( $this->settings['js_backend'], 'required' ); ?>><?php esc_html_e( 'Required functions only', 'ayecode-connect' ); ?></option>
959
                                    <option	value="" <?php selected( $this->settings['js_backend'], '' ); ?>><?php esc_html_e( 'Disabled (not recommended)', 'ayecode-connect' ); ?></option>
960
                                </select>
961
                            </td>
962
                        </tr>
963
964
                        <tr valign="top">
965
                            <th scope="row"><label for="wpbs-disable-admin"><?php esc_html_e( 'Disable load on URL', 'ayecode-connect' ); ?></label></th>
966
                            <td>
967
                                <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>
968
                                <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>
969
                            </td>
970
                        </tr>
971
                    </table>
972
973
					<?php
974
					submit_button();
975
					?>
976
                </form>
977
                <div id="wpbs-version" data-aui-source="<?php echo esc_attr( $this->get_load_source() ); ?>"><?php echo esc_html( $this->version ); ?></div>
978
            </div>
979
			<?php
980
		}
981
982
        public function get_load_source(){
983
	        $file = str_replace( array( "/", "\\" ), "/", realpath( __FILE__ ) );
984
	        $plugins_dir = str_replace( array( "/", "\\" ), "/", realpath( WP_PLUGIN_DIR ) );
985
986
	        // Find source plugin/theme of SD
987
	        $source = array();
988
	        if ( strpos( $file, $plugins_dir ) !== false ) {
989
		        $source = explode( "/", plugin_basename( $file ) );
990
	        } else if ( function_exists( 'get_theme_root' ) ) {
991
		        $themes_dir = str_replace( array( "/", "\\" ), "/", realpath( get_theme_root() ) );
992
993
		        if ( strpos( $file, $themes_dir ) !== false ) {
994
			        $source = explode( "/", ltrim( str_replace( $themes_dir, "", $file ), "/" ) );
995
		        }
996
	        }
997
998
            return isset($source[0]) ? esc_attr($source[0]) : '';
999
        }
1000
1001
		public function customizer_settings($wp_customize){
1002
			$wp_customize->add_section('aui_settings', array(
1003
				'title'    => __('AyeCode UI', 'ayecode-connect' ),
1004
				'priority' => 120,
1005
			));
1006
1007
			//  =============================
1008
			//  = Color Picker              =
1009
			//  =============================
1010
			$wp_customize->add_setting('aui_options[color_primary]', array(
1011
				'default'           => AUI_PRIMARY_COLOR,
1012
				'sanitize_callback' => 'sanitize_hex_color',
1013
				'capability'        => 'edit_theme_options',
1014
				'type'              => 'option',
1015
				'transport'         => 'refresh',
1016
			));
1017
			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array(
1018
				'label'    => __('Primary Color', 'ayecode-connect' ),
1019
				'section'  => 'aui_settings',
1020
				'settings' => 'aui_options[color_primary]',
1021
			)));
1022
1023
			$wp_customize->add_setting('aui_options[color_secondary]', array(
1024
				'default'           => '#6c757d',
1025
				'sanitize_callback' => 'sanitize_hex_color',
1026
				'capability'        => 'edit_theme_options',
1027
				'type'              => 'option',
1028
				'transport'         => 'refresh',
1029
			));
1030
			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array(
1031
				'label'    => __('Secondary Color', 'ayecode-connect' ),
1032
				'section'  => 'aui_settings',
1033
				'settings' => 'aui_options[color_secondary]',
1034
			)));
1035
		}
1036
1037
		/**
1038
		 * CSS to help with conflict issues with other plugins and themes using bootstrap v3.
1039
		 *
1040
		 * @return mixed
1041
		 */
1042
		public static function bs3_compat_css() {
1043
			ob_start();
1044
			?>
1045
            <style>
1046
                /* Bootstrap 3 compatibility */
1047
                body.modal-open .modal-backdrop.show:not(.in) {opacity:0.5;}
1048
                body.modal-open .modal.show:not(.in)  {opacity:1;z-index: 99999}
1049
                body.modal-open .modal.show:not(.in) .modal-content  {box-shadow: none;}
1050
                body.modal-open .modal.show:not(.in)  .modal-dialog {transform: initial;}
1051
1052
                body.modal-open .modal.bsui .modal-dialog{left: auto;}
1053
1054
                .collapse.show:not(.in){display: inherit;}
1055
                .fade.show{opacity: 1;}
1056
1057
                <?php if( defined( 'SVQ_THEME_VERSION' ) ){ ?>
1058
                /* KLEO theme specific */
1059
                .kleo-main-header .navbar-collapse.collapse.show:not(.in){display: block !important;}
1060
                <?php } ?>
1061
1062
                <?php if( defined( 'FUSION_BUILDER_VERSION' ) ){ ?>
1063
                /* With Avada builder */
1064
                body.modal-open .modal.in  {opacity:1;z-index: 99999}
1065
                body.modal-open .modal.bsui.in .modal-content  {box-shadow: none;}
1066
                .bsui .collapse.in{display: inherit;}
1067
                .bsui .collapse.in.row.show{display: flex;}
1068
                .bsui .collapse.in.row:not(.show){display: none;}
1069
1070
                <?php } ?>
1071
            </style>
1072
			<?php
1073
			return str_replace( array(
1074
				'<style>',
1075
				'</style>'
1076
			), '', self::minify_css( ob_get_clean() ) );
1077
		}
1078
1079
		public static function custom_css( $compatibility = true, $is_fse = false ) {
1080
			global $aui_bs5;
1081
1082
			$colors = array();
1083
1084
			if ( defined( 'BLOCKSTRAP_VERSION' ) ) {
1085
				$setting = wp_get_global_settings();
1086
1087
				if ( ! empty( $setting['color']['palette']['theme'] ) ) {
1088
					foreach ( $setting['color']['palette']['theme'] as $color ) {
1089
						$colors[$color['slug']] = esc_attr( $color['color'] );
1090
					}
1091
				}
1092
1093
				if ( ! empty( $setting['color']['palette']['custom'] ) ) {
1094
					foreach ( $setting['color']['palette']['custom'] as $color ) {
1095
						$colors[$color['slug']] = esc_attr( $color['color'] );
1096
					}
1097
				}
1098
			} else {
1099
				$settings = get_option( 'aui_options' );
1100
1101
				$colors = array(
1102
					'primary'   => ! empty( $settings['color_primary'] ) ? $settings['color_primary'] : AUI_PRIMARY_COLOR,
1103
					'secondary' => ! empty( $settings['color_secondary'] ) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR
1104
				);
1105
			}
1106
1107
			ob_start();
1108
			?><style><?php
1109
			// BS v3 compat
1110
			if( self::is_bs3_compat() ){
1111
				echo self::bs3_compat_css(); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1112
			}
1113
1114
			//$is_fse = false;
1115
			//if ( is_admin() && ( !empty($_REQUEST['postType']) || self::is_block_editor() ) && ( defined( 'BLOCKSTRAP_VERSION' ) || defined( 'AUI_FSE' ) )  ) {
1116
				//$is_fse = true;
1117
			//}
1118
1119
			$custom_front = ! is_admin() ? true : apply_filters('ayecode_ui_custom_front', false );
1120
			$custom_admin = $is_fse || self::is_preview() ? true : apply_filters('ayecode_ui_custom_admin', false );
1121
            $bs_custom_css = apply_filters( 'ayecode_ui_bs_custom_css', $custom_admin || $custom_front );
1122
			//$bs_custom_css = true; // Force true to fix any color issue.
1123
1124
			$colors_css = '';
1125
			if ( ! empty( $colors ) && $bs_custom_css ) {
1126
				$d_colors = self::get_colors(true);
1127
1128
				foreach ( $colors as $key => $color ) {
1129
					if ( ( empty( $d_colors[$key]) || $d_colors[$key] != $color) || $is_fse ) {
1130
						$var = $is_fse ? "var(--wp--preset--color--$key)" : $color;
1131
						$compat = $is_fse ? '.editor-styles-wrapper' : $compatibility;
1132
1133
						$colors_css .= $aui_bs5 ? self::css_overwrite_bs5( $key,$var, $compat, $color ) : self::css_overwrite( $key, $var, $compat, $color );
1134
					}
1135
				}
1136
			}
1137
1138
			if ( $colors_css ) {
1139
				echo $colors_css; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1140
			}
1141
1142
			// Set admin bar z-index lower when modal is open.
1143
			echo ' body.modal-open #wpadminbar{z-index:999}.embed-responsive-16by9 .fluid-width-video-wrapper{padding:0 !important;position:initial}';
1144
1145
			if ( is_admin() ) {
1146
				echo ' body.modal-open #adminmenuwrap{z-index:999} body.modal-open #wpadminbar{z-index:1025}';
1147
			}
1148
1149
			$custom_css = '';
1150
1151
			if ( $aui_bs5 && defined( 'BLOCKSTRAP_VERSION' ) && $bs_custom_css ) {
1152
				$css = '';
1153
				$theme_settings = wp_get_global_styles();
1154
1155
				// Font face
1156
				if( !empty( $theme_settings['typography']['fontFamily'] ) ){
1157
					$t_fontface = str_replace( array('var:preset|','font-family|'), array('--wp--preset--','font-family--'), $theme_settings['typography']['fontFamily']  ); //var(--wp--preset--font-family--poppins)
1158
					$css .= '--bs-body-font-family: ' . esc_attr($t_fontface) . ';';
1159
				}
1160
1161
				// font size
1162
				if( !empty( $theme_settings['typography']['fontSize'] ) ){
1163
					$css .= '--bs-body-font-size: ' . esc_attr( $theme_settings['typography']['fontSize'] ) . ' ;';
1164
				}
1165
1166
				// line height
1167
				 if( !empty( $theme_settings['typography']['lineHeight'] ) ){
1168
					$css .= '--bs-body-line-height: ' . esc_attr( $theme_settings['typography']['lineHeight'] ) . ';';
1169
				}
1170
1171
1172
				   // font weight
1173
				 if( !empty( $theme_settings['typography']['fontWeight'] ) ){
1174
					$css .= '--bs-body-font-weight: ' . esc_attr( $theme_settings['typography']['fontWeight'] ) . ';';
1175
				}
1176
1177
				// Background
1178
				 if( !empty( $theme_settings['color']['background'] ) ){
1179
					$css .= '--bs-body-bg: ' . esc_attr( $theme_settings['color']['background'] ) . ';';
1180
				}
1181
1182
				 // Background Gradient
1183
				 if( !empty( $theme_settings['color']['gradient'] ) ){
1184
					$css .= 'background: ' . esc_attr( $theme_settings['color']['gradient'] ) . ';';
1185
				}
1186
1187
				   // Background Gradient
1188
				 if( !empty( $theme_settings['color']['gradient'] ) ){
1189
					$css .= 'background: ' . esc_attr( $theme_settings['color']['gradient'] ) . ';';
1190
				}
1191
1192
				// text color
1193
				if( !empty( $theme_settings['color']['text'] ) ){
1194
					$css .= '--bs-body-color: ' . esc_attr( $theme_settings['color']['text'] ) . ';';
1195
				}
1196
1197
1198
				// link colors
1199
				if( !empty( $theme_settings['elements']['link']['color']['text'] ) ){
1200
					$css .= '--bs-link-color: ' . esc_attr( $theme_settings['elements']['link']['color']['text'] ) . ';';
1201
				}
1202
				if( !empty( $theme_settings['elements']['link'][':hover']['color']['text'] ) ){
1203
					$css .= '--bs-link-hover-color: ' . esc_attr( $theme_settings['elements']['link'][':hover']['color']['text'] ) . ';';
1204
				}
1205
1206
				if($css){
1207
					$custom_css .= $is_fse ? 'body.editor-styles-wrapper{' . esc_attr( $css ) . '}' : 'body{' . esc_attr( $css ) . '}';
1208
				}
1209
1210
				$bep = $is_fse ? 'body.editor-styles-wrapper ' : '';
1211
1212
				// Headings
1213
				$headings_css = '';
1214
				if( !empty( $theme_settings['elements']['heading']['color']['text'] ) ){
1215
					$headings_css .= "color: " . esc_attr( $theme_settings['elements']['heading']['color']['text'] ) . ";";
1216
				}
1217
1218
				// heading background
1219
				if( !empty( $theme_settings['elements']['heading']['color']['background'] ) ){
1220
					$headings_css .= 'background: ' . esc_attr( $theme_settings['elements']['heading']['color']['background'] ) . ';';
1221
				}
1222
1223
				 // heading font family
1224
				if( !empty( $theme_settings['elements']['heading']['typography']['fontFamily'] ) ){
1225
					$headings_css .= 'font-family: ' . esc_attr( $theme_settings['elements']['heading']['typography']['fontFamily']  ) . ';';
1226
				}
1227
1228
				if( $headings_css ){
1229
					$custom_css .= "$bep h1,$bep h2,$bep h3, $bep h4,$bep h5,$bep h6{ " . esc_attr( $headings_css ) . "}";
1230
				}
1231
1232
				$hs = array('h1','h2','h3','h4','h5','h6');
1233
1234
				foreach($hs as $hn){
1235
					$h_css = '';
1236
					 if( !empty( $theme_settings['elements'][$hn]['color']['text'] ) ){
1237
						$h_css .= 'color: ' . esc_attr( $theme_settings['elements'][$hn]['color']['text'] ) . ';';
1238
					 }
1239
1240
					  if( !empty( $theme_settings['elements'][$hn]['typography']['fontSize'] ) ){
1241
						$h_css .= 'font-size: ' . esc_attr( $theme_settings['elements'][$hn]['typography']['fontSize']  ) . ';';
1242
					 }
1243
1244
					  if( !empty( $theme_settings['elements'][$hn]['typography']['fontFamily'] ) ){
1245
						$h_css .= 'font-family: ' . esc_attr( $theme_settings['elements'][$hn]['typography']['fontFamily']  ) . ';';
1246
					 }
1247
1248
					 if($h_css){
1249
						$custom_css .= esc_attr( $bep  . $hn ) . '{'.esc_attr( $h_css ).'}';
1250
					 }
1251
				}
1252
			}
1253
			
1254
			if ( $custom_css ) {
1255
				echo $custom_css; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1256
			}
1257
1258
			// Pagination on Hello Elementor theme.
1259
			if ( function_exists( 'hello_elementor_setup' ) ) {
1260
				echo '.aui-nav-links .pagination{justify-content:inherit}';
1261
			}
1262
			?></style><?php
1263
			$custom_css = ob_get_clean();
1264
1265
			/*
1266
			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1267
			 */
1268
			return str_replace( array(
1269
				'<style>',
1270
				'</style>'
1271
			), '', self::minify_css( $custom_css ) );
1272
		}
1273
1274
		/**
1275
		 * Check if we should add booststrap 3 compatibility changes.
1276
		 *
1277
		 * @return bool
1278
		 */
1279
		public static function is_bs3_compat(){
1280
			return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION');
1281
		}
1282
1283
		public static function hex_to_rgb( $hex ) {
1284
			// Remove '#' if present
1285
			$hex = str_replace( '#', '', $hex );
1286
1287
			// Check if input is RGB
1288
			if ( strpos( $hex, 'rgba(' ) === 0 || strpos( $hex, 'rgb(' ) === 0 ) {
1289
				$_rgb = explode( ',', str_replace( array( 'rgba(', 'rgb(', ')' ), '', $hex ) );
1290
1291
				$rgb = ( isset( $_rgb[0] ) ? (int) trim( $_rgb[0] ) : '0' ) . ',';
1292
				$rgb .= ( isset( $_rgb[1] ) ? (int) trim( $_rgb[1] ) : '0' ) . ',';
1293
				$rgb .= ( isset( $_rgb[2] ) ? (int) trim( $_rgb[2] ) : '0' );
1294
1295
				return $rgb;
1296
			}
1297
1298
			// Convert 3-digit hex to 6-digit hex
1299
			if ( strlen( $hex ) == 3 ) {
1300
				$hex = str_repeat( substr( $hex, 0, 1 ), 2 ) . str_repeat( substr( $hex, 1, 1 ), 2 ) . str_repeat( substr( $hex, 2, 1 ), 2 );
1301
			}
1302
1303
			// Convert hex to RGB
1304
			$r = hexdec( substr( $hex, 0, 2 ) );
1305
			$g = hexdec( substr( $hex, 2, 2 ) );
1306
			$b = hexdec( substr( $hex, 4, 2 ) );
1307
1308
			// Return RGB values as an array
1309
			return $r . ',' . $g . ',' . $b;
1310
		}
1311
1312
		/**
1313
		 * Build the CSS to overwrite a bootstrap color variable.
1314
		 *
1315
		 * @param $type
1316
		 * @param $color_code
1317
		 * @param $compatibility
1318
		 *
1319
		 * @return string
1320
		 */
1321
		public static function css_overwrite_bs5($type,$color_code,$compatibility, $hex = '' ){
1322
			global $aui_bs5;
1323
1324
			$is_var = false;
1325
			$is_custom = strpos($type, 'custom-') !== false ? true : false;
1326
			if(!$color_code){return '';}
1327
			if(strpos($color_code, 'var') !== false){
1328
				//if(!sanitize_hex_color($color_code)){
1329
				$color_code = esc_attr($color_code);
1330
				$is_var = true;
1331
//				$color_code = "rgba($color_code, 0.5)";
1332
//                echo '###1'.$color_code.'###';//exit;
1333
			}
1334
1335
//            echo '@@@'.$color_code.'==='.self::hex_to_rgb($color_code);exit;
1336
1337
			if(!$color_code){return '';}
1338
1339
			$rgb = self::hex_to_rgb($hex);
1340
1341
			if($compatibility===true || $compatibility===1){
1342
				$compatibility = '.bsui';
1343
			}elseif(!$compatibility){
1344
				$compatibility = '';
1345
			}else{
1346
				$compatibility = esc_attr($compatibility);
1347
			}
1348
1349
			$prefix = $compatibility ? $compatibility . " " : "";
1350
1351
1352
            $output = '';
1353
1354
//            echo '####'.$color_code;exit;
1355
1356
			$type = sanitize_html_class($type);
1357
1358
			/**
1359
			 * c = color, b = background color, o = border-color, f = fill
1360
			 */
1361
			$selectors = array(
1362
				".btn-{$type}"                                              => array( 'b', 'o' ),
1363
				".btn-{$type}.disabled"                                     => array( 'b', 'o' ),
1364
				".btn-{$type}:disabled"                                     => array( 'b', 'o' ),
1365
				".btn-outline-{$type}"                                      => array( 'c', 'o' ),
1366
				".btn-outline-{$type}:hover"                                => array( 'b', 'o' ),
1367
				".btn-outline-{$type}:not(:disabled):not(.disabled).active" => array( 'b', 'o' ),
1368
				".btn-outline-{$type}:not(:disabled):not(.disabled):active" => array( 'b', 'o' ),
1369
				".show>.btn-outline-{$type}.dropdown-toggle"                => array( 'b', 'o' ),
1370
				".badge-{$type}"                                            => array( 'b' ),
1371
				".alert-{$type}"                                            => array( 'b', 'o' ),
1372
				".bg-{$type}"                                               => array( 'b', 'f' ),
1373
				".btn-link.btn-{$type}"                                     => array( 'c' ),
1374
				".text-{$type}"                                     => array( 'c' ),
1375
			);
1376
1377
			if ( $aui_bs5 ) {
1378
				unset($selectors[".alert-{$type}" ]);
1379
			}
1380
1381
			if ( $type == 'primary' ) {
1382
				$selectors = $selectors + array(
1383
						'a'                                                                                                    => array( 'c' ),
1384
						'.btn-link'                                                                                            => array( 'c' ),
1385
						'.dropdown-item.active'                                                                                => array( 'b' ),
1386
						'.custom-control-input:checked~.custom-control-label::before'                                          => array(
1387
							'b',
1388
							'o'
1389
						),
1390
						'.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before'                   => array(
1391
							'b',
1392
							'o'
1393
						),
1394
						'.nav-pills .nav-link.active'                                                                          => array( 'b' ),
1395
						'.nav-pills .show>.nav-link'                                                                           => array( 'b' ),
1396
						'.page-link'                                                                                           => array( 'c' ),
1397
						'.page-item.active .page-link'                                                                         => array(
1398
							'b',
1399
							'o'
1400
						),
1401
						'.progress-bar'                                                                                        => array( 'b' ),
1402
						'.list-group-item.active'                                                                              => array(
1403
							'b',
1404
							'o'
1405
						),
1406
						'.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array( 'b' ),
1407
					);
1408
			}
1409
1410
1411
1412
            // link
1413
			if ( $type === 'primary' ) {
1414
				$output .= 'html body {--bs-link-hover-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .75); --bs-link-color: var(--bs-'.esc_attr($type).'); }';
1415
				$output .= $prefix . ' .breadcrumb{--bs-breadcrumb-item-active-color: '.esc_attr($color_code).';  }';
1416
				$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).'; }';
1417
1418
				$output .= $prefix . ' a{color: var(--bs-'.esc_attr($type).');}';
1419
				$output .= $prefix . ' .text-primary{color: var(--bs-'.esc_attr($type).') !important;}';
1420
1421
                // dropdown
1422
				$output .= $prefix . ' .dropdown-menu{--bs-dropdown-link-hover-color: var(--bs-'.esc_attr($type).'); --bs-dropdown-link-active-color: var(--bs-'.esc_attr($type).');}';
1423
1424
                // pagination
1425
				$output .= $prefix . ' .pagination{--bs-pagination-hover-color: var(--bs-'.esc_attr($type).'); --bs-pagination-active-bg: var(--bs-'.esc_attr($type).');}';
1426
1427
			}
1428
1429
			$output .= $prefix . ' .link-'.esc_attr($type).' {color: var(--bs-'.esc_attr($type).'-rgb) !important;}';
1430
			$output .= $prefix . ' .link-'.esc_attr($type).':hover {color: rgba(var(--bs-'.esc_attr($type).'-rgb), .8) !important;}';
1431
1432
			//  buttons
1433
			$output .= $prefix . ' .btn-'.esc_attr($type).'{';
1434
			$output .= ' 
1435
            --bs-btn-bg: '.esc_attr($color_code).';
1436
            --bs-btn-border-color: '.esc_attr($color_code).';
1437
            --bs-btn-hover-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1438
            --bs-btn-hover-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1439
            --bs-btn-focus-shadow-rgb: --bs-'.esc_attr($type).'-rgb;
1440
            --bs-btn-active-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1441
            --bs-btn-active-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1442
            --bs-btn-active-shadow: unset;
1443
            --bs-btn-disabled-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .5);
1444
            --bs-btn-disabled-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .1);
1445
            ';
1446
//			$output .= '
1447
//		    --bs-btn-color: #fff;
1448
//			--bs-btn-hover-color: #fff;
1449
//			--bs-btn-active-color: #fff;
1450
//			--bs-btn-disabled-color: #fff;
1451
//            ';
1452
			$output .= '}';
1453
1454
			//  buttons outline
1455
			$output .= $prefix . ' .btn-outline-'.esc_attr($type).'{';
1456
			$output .= ' 
1457
			--bs-btn-color: '.esc_attr($color_code).';
1458
            --bs-btn-border-color: '.esc_attr($color_code).';
1459
            --bs-btn-hover-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1460
            --bs-btn-hover-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1461
            --bs-btn-focus-shadow-rgb: --bs-'.esc_attr($type).'-rgb;
1462
            --bs-btn-active-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1463
            --bs-btn-active-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9);
1464
            --bs-btn-active-shadow: unset;
1465
            --bs-btn-disabled-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .5);
1466
            --bs-btn-disabled-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .1);
1467
            ';
1468
//			$output .= '
1469
//		    --bs-btn-color: #fff;
1470
//			--bs-btn-hover-color: #fff;
1471
//			--bs-btn-active-color: #fff;
1472
//			--bs-btn-disabled-color: #fff;
1473
//            ';
1474
			$output .= '}';
1475
1476
1477
            // button hover
1478
			$output .= $prefix . ' .btn-'.esc_attr($type).':hover{';
1479
			$output .= ' 
1480
            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);
1481
            }
1482
            ';
1483
1484
1485
			if ( $aui_bs5 ) {
1486
//				$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).'; }';
1487
				$output .= 'html body {--bs-'.esc_attr($type).': '.esc_attr($color_code).'; }';
1488
				$output .= 'html body {--bs-'.esc_attr($type).'-rgb: '.$rgb.'; }';
1489
			}
1490
1491
1492
			if ( $is_custom ) {
1493
1494
//				echo '###'.$type;exit;
1495
1496
				// build rules into each type
1497
				foreach($selectors as $selector => $types){
1498
					$selector = $compatibility ? $compatibility . " ".$selector : $selector;
1499
					$types = array_combine($types,$types);
1500
					if(isset($types['c'])){$color[] = $selector;}
1501
					if(isset($types['b'])){$background[] = $selector;}
1502
					if(isset($types['o'])){$border[] = $selector;}
1503
					if(isset($types['f'])){$fill[] = $selector;}
1504
				}
1505
1506
//				// build rules into each type
1507
//				foreach($important_selectors as $selector => $types){
1508
//					$selector = $compatibility ? $compatibility . " ".$selector : $selector;
1509
//					$types = array_combine($types,$types);
1510
//					if(isset($types['c'])){$color_i[] = $selector;}
1511
//					if(isset($types['b'])){$background_i[] = $selector;}
1512
//					if(isset($types['o'])){$border_i[] = $selector;}
1513
//					if(isset($types['f'])){$fill_i[] = $selector;}
1514
//				}
1515
1516
				// add any color rules
1517
				if(!empty($color)){
1518
					$output .= implode(",",$color) . "{color: $color_code;} ";
1519
				}
1520
				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...
1521
					$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1522
				}
1523
1524
				// add any background color rules
1525
				if(!empty($background)){
1526
					$output .= implode(",",$background) . "{background-color: $color_code;} ";
1527
				}
1528
				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...
1529
					$output .= $aui_bs5 ? '' : implode(",",$background_i) . "{background-color: $color_code !important;} ";
1530
//				$output .= implode(",",$background_i) . "{background-color: rgba(var(--bs-primary-rgb), var(--bs-bg-opacity)) !important;} ";
1531
				}
1532
1533
				// add any border color rules
1534
				if(!empty($border)){
1535
					$output .= implode(",",$border) . "{border-color: $color_code;} ";
1536
				}
1537
				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...
1538
					$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1539
				}
1540
1541
				// add any fill color rules
1542
				if(!empty($fill)){
1543
					$output .= implode(",",$fill) . "{fill: $color_code;} ";
1544
				}
1545
				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...
1546
					$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1547
				}
1548
1549
			}
1550
1551
1552
1553
1554
			$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;' : '';
1555
			// darken
1556
			$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

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

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

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

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

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

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

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

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

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

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

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

3295
			if ( function_exists( 'bricks_is_builder' ) && ( bricks_is_builder() || /** @scrutinizer ignore-call */ bricks_is_builder_call() ) ) {
Loading history...
3296
				$result = true;
3297
			}
3298
3299
			return $result;
3300
		}
3301
3302
		/**
3303
		 * General function to check if we are in a preview situation.
3304
		 *
3305
		 * @since 0.2.27
3306
		 *
3307
		 * @return bool
3308
		 */
3309
		public static function is_preview() {
3310
			$preview = false;
3311
3312
			if ( self::is_block_editor() ) {
3313
				return true;
3314
			}
3315
3316
			if( self::is_block_content_call() ) {
3317
				$preview = true;
3318
			} elseif ( self::is_divi_preview() ) {
3319
				$preview = true;
3320
			} elseif ( self::is_elementor_preview() ) {
3321
				$preview = true;
3322
			} elseif ( self::is_beaver_preview() ) {
3323
				$preview = true;
3324
			} elseif ( self::is_siteorigin_preview() ) {
3325
				$preview = true;
3326
			} elseif ( self::is_cornerstone_preview() ) {
3327
				$preview = true;
3328
			} elseif ( self::is_fusion_preview() ) {
3329
				$preview = true;
3330
			} elseif ( self::is_oxygen_preview() ) {
3331
				$preview = true;
3332
			} elseif( self::is_kallyas_zion_preview() ) {
3333
				$preview = true;
3334
			} elseif( self::is_bricks_preview() ) {
3335
				$preview = true;
3336
			}
3337
3338
			return $preview;
3339
		}
3340
	}
3341
3342
	/**
3343
	 * Run the class if found.
3344
	 */
3345
	AyeCode_UI_Settings::instance();
3346
}