Passed
Pull Request — master (#379)
by Brian
04:59
created

AyeCode_UI_Settings::maybe_show_examples()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 8
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 9
rs 10
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 = '1.0.1';
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 = "4.3.1";
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
		 * Main AyeCode_UI_Settings Instance.
93
		 *
94
		 * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded.
95
		 *
96
		 * @since 1.0.0
97
		 * @static
98
		 * @return AyeCode_UI_Settings - Main instance.
99
		 */
100
		public static function instance() {
101
			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) {
102
				self::$instance = new AyeCode_UI_Settings;
103
104
				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
105
106
				if ( is_admin() ) {
107
					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
108
					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
109
110
					// Maybe show example page
111
					add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) );
112
				}
113
114
				add_action( 'customize_register', array( self::$instance, 'customizer_settings' ));
115
116
				do_action( 'ayecode_ui_settings_loaded' );
117
			}
118
119
			return self::$instance;
120
		}
121
122
		/**
123
		 * Initiate the settings and add the required action hooks.
124
		 */
125
		public function init() {
126
			$this->settings = $this->get_settings();
127
			$this->url = $this->get_url();
128
129
			/**
130
			 * Maybe load CSS
131
			 *
132
			 * We load super early in case there is a theme version that might change the colors
133
			 */
134
			if ( $this->settings['css'] ) {
135
				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
136
			}
137
			if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) {
138
				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
139
			}
140
141
			// maybe load JS
142
			if ( $this->settings['js'] ) {
143
				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 );
144
			}
145
			if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) {
146
				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 );
147
			}
148
149
			// Maybe set the HTML font size
150
			if ( $this->settings['html_font_size'] ) {
151
				add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 );
152
			}
153
154
155
		}
156
157
		/**
158
		 * Check if we should load the admin scripts or not.
159
		 *
160
		 * @return bool
161
		 */
162
		public function load_admin_scripts(){
163
			$result = true;
164
165
			if(!empty($this->settings['disable_admin'])){
166
				$url_parts = explode("\n",$this->settings['disable_admin']);
167
				foreach($url_parts as $part){
168
					if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){
169
						return false; // return early, no point checking further
170
					}
171
				}
172
			}
173
174
			return $result;
175
		}
176
177
		/**
178
		 * Add a html font size to the footer.
179
		 */
180
		public function html_font_size(){
181
			$this->settings = $this->get_settings();
182
			echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>";
183
		}
184
185
		/**
186
		 * Adds the Font Awesome styles.
187
		 */
188
		public function enqueue_style() {
189
190
			$css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend';
191
192
			if($this->settings[$css_setting]){
193
				$compatibility = $this->settings[$css_setting]=='core' ? false : true;
194
				$url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui.css' : $this->url.'assets/css/ayecode-ui-compatibility.css';
195
				wp_register_style( 'ayecode-ui', $url, array(), $this->latest );
196
				wp_enqueue_style( 'ayecode-ui' );
197
198
				// flatpickr
199
				wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest );
200
201
202
				// fix some wp-admin issues
203
				if(is_admin()){
204
					$custom_css = "
205
                body{
206
                    background-color: #f1f1f1;
207
                    font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif;
208
                    font-size:13px;
209
                }
210
                a {
211
				    color: #0073aa;
212
				    text-decoration: underline;
213
				}
214
                label {
215
				    display: initial;
216
				    margin-bottom: 0;
217
				}
218
				input, select {
219
				    margin: 1px;
220
				    line-height: initial;
221
				}
222
				th, td, div, h2 {
223
				    box-sizing: content-box;
224
				}
225
				p {
226
				    font-size: 13px;
227
				    line-height: 1.5;
228
				    margin: 1em 0;
229
				}
230
				h1, h2, h3, h4, h5, h6 {
231
				    display: block;
232
				    font-weight: 600;
233
				}
234
				h2,h3 {
235
				    font-size: 1.3em;
236
				    margin: 1em 0
237
				}
238
                ";
239
240
					// @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377
241
					$custom_css .= "
242
						.edit-post-sidebar input[type=color].components-text-control__input{
243
						    padding: 0;
244
						}
245
					";
246
					wp_add_inline_style( 'ayecode-ui', $custom_css );
247
				}
248
249
				// custom changes
250
				wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) );
251
252
			}
253
		}
254
255
		/**
256
		 * Get inline script used if bootstrap enqueued
257
		 *
258
		 * If this remains small then its best to use this than to add another JS file.
259
		 */
260
		public function inline_script(){
261
			ob_start();
262
			?>
263
			<script>
264
265
				/**
266
				 * An AUI bootstrap adaptation of GreedyNav.js ( by Luke Jackson ).
267
				 *
268
				 * Simply add the class `greedy` to any <nav> menu and it will do the rest.
269
				 * Licensed under the MIT license - http://opensource.org/licenses/MIT
270
				 * @ver 0.0.1
271
				 */
272
				function aui_init_greedy_nav(){
273
					jQuery('nav.greedy').each(function(i, obj) {
274
275
						// Check if already initialized, if so continue.
276
						if(jQuery(this).hasClass("being-greedy")){return true;}
277
278
						// Make sure its always expanded
279
						jQuery(this).addClass('navbar-expand');
280
281
						// vars
282
						var $vlinks = '';
283
						var $dDownClass = '';
284
						if(jQuery(this).find('.navbar-nav').length){
285
							$vlinks = jQuery(this).find('.navbar-nav').addClass("being-greedy w-100");
286
						}else if(jQuery(this).find('.nav').length){
287
							$vlinks = jQuery(this).find('.nav').addClass("being-greedy w-100");
288
							$dDownClass = ' mt-2 ';
289
						}else{
290
							return false;
291
						}
292
293
						jQuery($vlinks).append('<li class="nav-item list-unstyled ml-auto greedy-btn d-none dropdown ">' +
294
							'<a href="javascript:void(0)" data-toggle="dropdown" class="nav-link"><i class="fas fa-ellipsis-h"></i> <span class="greedy-count badge badge-dark badge-pill"></span></a>' +
295
							'<ul class="greedy-links dropdown-menu  dropdown-menu-right '+$dDownClass+'"></ul>' +
296
							'</li>');
297
298
						var $hlinks = jQuery(this).find('.greedy-links');
299
						var $btn = jQuery(this).find('.greedy-btn');
300
301
						var numOfItems = 0;
302
						var totalSpace = 0;
303
						var closingTime = 1000;
304
						var breakWidths = [];
305
306
						// Get initial state
307
						$vlinks.children().outerWidth(function(i, w) {
308
							totalSpace += w;
309
							numOfItems += 1;
310
							breakWidths.push(totalSpace);
311
						});
312
313
						var availableSpace, numOfVisibleItems, requiredSpace, buttonSpace ,timer;
314
315
						/*
316
						 The check function.
317
						 */
318
						function check() {
319
320
							// Get instant state
321
							buttonSpace = $btn.width();
322
							availableSpace = $vlinks.width() - 10;
323
							numOfVisibleItems = $vlinks.children().length;
324
							requiredSpace = breakWidths[numOfVisibleItems - 1];
325
326
							// There is not enough space
327
							if (numOfVisibleItems > 1 && requiredSpace > availableSpace) {
328
								$vlinks.children().last().prev().prependTo($hlinks);
329
								numOfVisibleItems -= 1;
330
								check();
331
								// There is more than enough space
332
							} else if (availableSpace > breakWidths[numOfVisibleItems]) {
333
								$hlinks.children().first().insertBefore($btn);
334
								numOfVisibleItems += 1;
335
								check();
336
							}
337
							// Update the button accordingly
338
							jQuery($btn).find(".greedy-count").html( numOfItems - numOfVisibleItems);
339
							if (numOfVisibleItems === numOfItems) {
340
								$btn.addClass('d-none');
341
							} else $btn.removeClass('d-none');
342
						}
343
344
						// Window listeners
345
						jQuery(window).resize(function() {
346
							check();
347
						});
348
349
						// do initial check
350
						check();
351
					});
352
				}
353
354
				/**
355
				 * Initiate Select2 items.
356
				 */
357
				function aui_init_select2(){
358
					jQuery("select.aui-select2").select2();
359
				}
360
361
				/**
362
				 * A function to convert a time value to a "ago" time text.
363
				 *
364
				 * @param selector string The .class selector
365
				 */
366
				function aui_time_ago(selector) {
367
368
					var templates = {
369
						prefix: "",
370
						suffix: " ago",
371
						seconds: "less than a minute",
372
						minute: "about a minute",
373
						minutes: "%d minutes",
374
						hour: "about an hour",
375
						hours: "about %d hours",
376
						day: "a day",
377
						days: "%d days",
378
						month: "about a month",
379
						months: "%d months",
380
						year: "about a year",
381
						years: "%d years"
382
					};
383
					var template = function (t, n) {
384
						return templates[t] && templates[t].replace(/%d/i, Math.abs(Math.round(n)));
385
					};
386
387
					var timer = function (time) {
388
						if (!time)
389
							return;
390
						time = time.replace(/\.\d+/, ""); // remove milliseconds
391
						time = time.replace(/-/, "/").replace(/-/, "/");
392
						time = time.replace(/T/, " ").replace(/Z/, " UTC");
393
						time = time.replace(/([\+\-]\d\d)\:?(\d\d)/, " $1$2"); // -04:00 -> -0400
394
						time = new Date(time * 1000 || time);
395
396
						var now = new Date();
397
						var seconds = ((now.getTime() - time) * .001) >> 0;
398
						var minutes = seconds / 60;
399
						var hours = minutes / 60;
400
						var days = hours / 24;
401
						var years = days / 365;
402
403
						return templates.prefix + (
404
								seconds < 45 && template('seconds', seconds) ||
405
								seconds < 90 && template('minute', 1) ||
406
								minutes < 45 && template('minutes', minutes) ||
407
								minutes < 90 && template('hour', 1) ||
408
								hours < 24 && template('hours', hours) ||
409
								hours < 42 && template('day', 1) ||
410
								days < 30 && template('days', days) ||
411
								days < 45 && template('month', 1) ||
412
								days < 365 && template('months', days / 30) ||
413
								years < 1.5 && template('year', 1) ||
414
								template('years', years)
415
							) + templates.suffix;
416
					};
417
418
					var elements = document.getElementsByClassName(selector);
419
					for (var i in elements) {
420
						var $this = elements[i];
421
						if (typeof $this === 'object') {
422
							$this.innerHTML = '<i class="far fa-clock"></i> ' + timer($this.getAttribute('title') || $this.getAttribute('datetime'));
423
						}
424
					}
425
					// update time every minute
426
					setTimeout(aui_time_ago, 60000);
427
428
				}
429
430
				/**
431
				 * Initiate tooltips on the page.
432
				 */
433
				function aui_init_tooltips(){
434
					jQuery('[data-toggle="tooltip"]').tooltip();
435
					jQuery('[data-toggle="popover"]').popover();
436
					jQuery('[data-toggle="popover-html"]').popover({
437
						html: true
438
					});
439
440
					// fix popover container compatibility
441
					jQuery('[data-toggle="popover"],[data-toggle="popover-html"]').on('inserted.bs.popover', function () {
442
						jQuery('body > .popover').wrapAll("<div class='bsui' />");
443
					});
444
				}
445
446
				/**
447
				 * Initiate flatpickrs on the page.
448
				 */
449
				function aui_init_flatpickr(){
450
					if ( jQuery.isFunction(jQuery.fn.flatpickr) ) {
451
						jQuery("input.aui-flatpickr").flatpickr();
452
					}
453
				}
454
455
				/**
456
				 * Initiate all AUI JS.
457
				 */
458
				function aui_init(){
459
					// init tooltips
460
					aui_init_tooltips();
461
462
					// init select2
463
					aui_init_select2();
464
465
					// init flatpickr
466
					aui_init_flatpickr();
467
468
					// init Greedy nav
469
					aui_init_greedy_nav();
470
471
					// Set times to time ago
472
					aui_time_ago('timeago');
473
				}
474
475
				// run on window loaded
476
				jQuery(window).load(function() {
477
					aui_init();
478
				});
479
			</script>
480
			<?php
481
			$output = ob_get_clean();
482
483
			/*
484
			 * We only add the <script> tags for code highlighting, so we strip them from the output.
485
			 */
486
			return str_replace( array(
487
				'<script>',
488
				'</script>'
489
			), '', $output );
490
		}
491
492
		/**
493
		 * Get inline script used if bootstrap file browser enqueued.
494
		 *
495
		 * If this remains small then its best to use this than to add another JS file.
496
		 */
497
		public function inline_script_file_browser(){
498
			ob_start();
499
			?>
500
			<script>
501
				// run on doc ready
502
				jQuery(document).ready(function () {
503
					bsCustomFileInput.init();
504
				});
505
			</script>
506
			<?php
507
			$output = ob_get_clean();
508
509
			/*
510
			 * We only add the <script> tags for code highlighting, so we strip them from the output.
511
			 */
512
			return str_replace( array(
513
				'<script>',
514
				'</script>'
515
			), '', $output );
516
		}
517
518
		/**
519
		 * Adds the Font Awesome JS.
520
		 */
521
		public function enqueue_scripts() {
522
523
			$js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend';
524
525
			// select2
526
			wp_register_script( 'select2', $this->url.'assets/js/select2.min.js', array('jquery'), $this->select2_version );
527
528
			// flatpickr
529
			wp_register_script( 'flatpickr', $this->url.'assets/js/flatpickr.min.js', array(), $this->latest );
530
531
			// Bootstrap file browser
532
			wp_register_script( 'aui-custom-file-input', $url = $this->url.'assets/js/bs-custom-file-input.min.js', array('jquery'), $this->select2_version );
533
			wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() );
534
535
			$load_inline = false;
536
537
			if($this->settings[$js_setting]=='core-popper'){
538
				// Bootstrap bundle
539
				$url = $this->url.'assets/js/bootstrap.bundle.min.js';
540
				wp_register_script( 'bootstrap-js-bundle', $url, array('select2','jquery'), $this->latest );
541
				// if in admin then add to footer for compatibility.
542
				is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle');
543
				$script = $this->inline_script();
544
				wp_add_inline_script( 'bootstrap-js-bundle', $script );
545
			}elseif($this->settings[$js_setting]=='popper'){
546
				$url = $this->url.'assets/js/popper.min.js';
547
				wp_register_script( 'bootstrap-js-popper', $url, array('jquery'), $this->latest );
548
				wp_enqueue_script( 'bootstrap-js-popper' );
549
				$load_inline = true;
550
			}else{
551
				$load_inline = true;
552
			}
553
554
			// Load needed inline scripts by faking the loading of a script if the main script is not being loaded
555
			if($load_inline){
556
				wp_register_script( 'bootstrap-dummy', '',array('jquery') );
557
				wp_enqueue_script( 'bootstrap-dummy' );
558
				$script = $this->inline_script();
559
				wp_add_inline_script( 'bootstrap-dummy', $script  );
560
			}
561
562
		}
563
564
		/**
565
		 * Enqueue flatpickr if called.
566
		 */
567
		public function enqueue_flatpickr(){
568
			wp_enqueue_style( 'flatpickr' );
569
			wp_enqueue_script( 'flatpickr' );
570
		}
571
572
		/**
573
		 * Get the url path to the current folder.
574
		 *
575
		 * @return string
576
		 */
577
		public function get_url() {
578
579
			$url = '';
580
			// check if we are inside a plugin
581
			$file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) );
582
583
			// add check in-case user has changed wp-content dir name.
584
			$wp_content_folder_name = basename(WP_CONTENT_DIR);
585
			$dir_parts = explode("/$wp_content_folder_name/",$file_dir);
586
			$url_parts = explode("/$wp_content_folder_name/",plugins_url());
587
588
			if(!empty($url_parts[0]) && !empty($dir_parts[1])){
589
				$url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] );
590
			}
591
592
			return $url;
593
		}
594
595
		/**
596
		 * Register the database settings with WordPress.
597
		 */
598
		public function register_settings() {
599
			register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' );
600
		}
601
602
		/**
603
		 * Add the WordPress settings menu item.
604
		 * @since 1.0.10 Calling function name direct will fail theme check so we don't.
605
		 */
606
		public function menu_item() {
607
			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
608
			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array(
609
				$this,
610
				'settings_page'
611
			) );
612
		}
613
614
		/**
615
		 * Get a list of themes and their default JS settings.
616
		 *
617
		 * @return array
618
		 */
619
		public function theme_js_settings(){
620
			return array(
621
				'ayetheme' => 'popper',
622
				'listimia' => 'required',
623
				'listimia_backend' => 'core-popper',
624
				'avada'    => 'required',
625
			);
626
		}
627
628
		/**
629
		 * Get the current Font Awesome output settings.
630
		 *
631
		 * @return array The array of settings.
632
		 */
633
		public function get_settings() {
634
635
			$db_settings = get_option( 'ayecode-ui-settings' );
636
			$js_default = 'core-popper';
637
			$js_default_backend = $js_default;
638
639
			// maybe set defaults (if no settings set)
640
			if(empty($db_settings)){
641
				$active_theme = strtolower( get_template() ); // active parent theme.
642
				$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

642
				/** @scrutinizer ignore-call */ 
643
    $theme_js_settings = self::theme_js_settings();
Loading history...
643
				if(isset($theme_js_settings[$active_theme])){
644
					$js_default = $theme_js_settings[$active_theme];
645
					$js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default;
646
				}
647
			}
648
649
			$defaults = array(
650
				'css'       => 'compatibility', // core, compatibility
651
				'js'        => $js_default, // js to load, core-popper, popper
652
				'html_font_size'        => '16', // js to load, core-popper, popper
653
				'css_backend'       => 'compatibility', // core, compatibility
654
				'js_backend'        => $js_default_backend, // js to load, core-popper, popper
655
				'disable_admin'     =>  '', // URL snippets to disable loading on admin
656
			);
657
658
			$settings = wp_parse_args( $db_settings, $defaults );
659
660
			/**
661
			 * Filter the Bootstrap settings.
662
			 *
663
			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
664
			 */
665
			return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults );
666
		}
667
668
669
		/**
670
		 * The settings page html output.
671
		 */
672
		public function settings_page() {
673
			if ( ! current_user_can( 'manage_options' ) ) {
674
				wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) );
675
			}
676
			?>
677
			<div class="wrap">
678
				<h1><?php echo $this->name; ?></h1>
679
				<p><?php _e("Here you can adjust settings if you are having compatibility issues.","aui");?></p>
680
				<form method="post" action="options.php">
681
					<?php
682
					settings_fields( 'ayecode-ui-settings' );
683
					do_settings_sections( 'ayecode-ui-settings' );
684
					?>
685
686
					<h2><?php _e( 'Frontend', 'aui' ); ?></h2>
687
					<table class="form-table wpbs-table-settings">
688
						<tr valign="top">
689
							<th scope="row"><label
690
									for="wpbs-css"><?php _e( 'Load CSS', 'aui' ); ?></label></th>
691
							<td>
692
								<select name="ayecode-ui-settings[css]" id="wpbs-css">
693
									<option	value="compatibility" <?php selected( $this->settings['css'], 'compatibility' ); ?>><?php _e( 'Compatibility Mode', 'aui' ); ?></option>
694
									<option value="core" <?php selected( $this->settings['css'], 'core' ); ?>><?php _e( 'Full Mode', 'aui' ); ?></option>
695
									<option	value="" <?php selected( $this->settings['css'], '' ); ?>><?php _e( 'Disabled', 'aui' ); ?></option>
696
								</select>
697
							</td>
698
						</tr>
699
700
						<tr valign="top">
701
							<th scope="row"><label
702
									for="wpbs-js"><?php _e( 'Load JS', 'aui' ); ?></label></th>
703
							<td>
704
								<select name="ayecode-ui-settings[js]" id="wpbs-js">
705
									<option	value="core-popper" <?php selected( $this->settings['js'], 'core-popper' ); ?>><?php _e( 'Core + Popper (default)', 'aui' ); ?></option>
706
									<option value="popper" <?php selected( $this->settings['js'], 'popper' ); ?>><?php _e( 'Popper', 'aui' ); ?></option>
707
									<option value="required" <?php selected( $this->settings['js'], 'required' ); ?>><?php _e( 'Required functions only', 'aui' ); ?></option>
708
									<option	value="" <?php selected( $this->settings['js'], '' ); ?>><?php _e( 'Disabled (not recommended)', 'aui' ); ?></option>
709
								</select>
710
							</td>
711
						</tr>
712
713
						<tr valign="top">
714
							<th scope="row"><label
715
									for="wpbs-font_size"><?php _e( 'HTML Font Size (px)', 'aui' ); ?></label></th>
716
							<td>
717
								<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" />
718
								<p class="description" ><?php _e("Our font sizing is rem (responsive based) here you can set the html font size in-case your theme is setting it too low.","aui");?></p>
719
							</td>
720
						</tr>
721
722
					</table>
723
724
					<h2><?php _e( 'Backend', 'aui' ); ?> (wp-admin)</h2>
725
					<table class="form-table wpbs-table-settings">
726
						<tr valign="top">
727
							<th scope="row"><label
728
									for="wpbs-css-admin"><?php _e( 'Load CSS', 'aui' ); ?></label></th>
729
							<td>
730
								<select name="ayecode-ui-settings[css_backend]" id="wpbs-css-admin">
731
									<option	value="compatibility" <?php selected( $this->settings['css_backend'], 'compatibility' ); ?>><?php _e( 'Compatibility Mode', 'aui' ); ?></option>
732
									<option value="core" <?php selected( $this->settings['css_backend'], 'core' ); ?>><?php _e( 'Full Mode', 'aui' ); ?></option>
733
									<option	value="" <?php selected( $this->settings['css_backend'], '' ); ?>><?php _e( 'Disabled', 'aui' ); ?></option>
734
								</select>
735
							</td>
736
						</tr>
737
738
						<tr valign="top">
739
							<th scope="row"><label
740
									for="wpbs-js-admin"><?php _e( 'Load JS', 'aui' ); ?></label></th>
741
							<td>
742
								<select name="ayecode-ui-settings[js_backend]" id="wpbs-js-admin">
743
									<option	value="core-popper" <?php selected( $this->settings['js_backend'], 'core-popper' ); ?>><?php _e( 'Core + Popper (default)', 'aui' ); ?></option>
744
									<option value="popper" <?php selected( $this->settings['js_backend'], 'popper' ); ?>><?php _e( 'Popper', 'aui' ); ?></option>
745
									<option value="required" <?php selected( $this->settings['js_backend'], 'required' ); ?>><?php _e( 'Required functions only', 'aui' ); ?></option>
746
									<option	value="" <?php selected( $this->settings['js_backend'], '' ); ?>><?php _e( 'Disabled (not recommended)', 'aui' ); ?></option>
747
								</select>
748
							</td>
749
						</tr>
750
751
						<tr valign="top">
752
							<th scope="row"><label
753
									for="wpbs-disable-admin"><?php _e( 'Disable load on URL', 'aui' ); ?></label></th>
754
							<td>
755
								<p><?php _e( 'If you have backend conflict you can enter a partial URL argument that will disable the loading of AUI on those pages. Add each argument on a new line.', 'aui' ); ?></p>
756
								<textarea name="ayecode-ui-settings[disable_admin]" rows="10" cols="50" id="wpbs-disable-admin" class="large-text code" spellcheck="false" placeholder="myplugin.php &#10;action=go"><?php echo $this->settings['disable_admin'];?></textarea>
757
758
							</td>
759
						</tr>
760
761
					</table>
762
763
					<?php
764
					submit_button();
765
					?>
766
				</form>
767
768
				<div id="wpbs-version"><?php echo $this->version; ?></div>
769
			</div>
770
771
			<?php
772
		}
773
774
		public function customizer_settings($wp_customize){
775
			$wp_customize->add_section('aui_settings', array(
776
				'title'    => __('AyeCode UI'),
777
				'priority' => 120,
778
			));
779
780
			//  =============================
781
			//  = Color Picker              =
782
			//  =============================
783
			$wp_customize->add_setting('aui_options[color_primary]', array(
784
				'default'           => '#1e73be',
785
				'sanitize_callback' => 'sanitize_hex_color',
786
				'capability'        => 'edit_theme_options',
787
				'type'              => 'option',
788
				'transport'         => 'refresh',
789
			));
790
			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array(
791
				'label'    => __('Primary Color'),
792
				'section'  => 'aui_settings',
793
				'settings' => 'aui_options[color_primary]',
794
			)));
795
796
			$wp_customize->add_setting('aui_options[color_secondary]', array(
797
				'default'           => '#6c757d',
798
				'sanitize_callback' => 'sanitize_hex_color',
799
				'capability'        => 'edit_theme_options',
800
				'type'              => 'option',
801
				'transport'         => 'refresh',
802
			));
803
			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array(
804
				'label'    => __('Secondary Color'),
805
				'section'  => 'aui_settings',
806
				'settings' => 'aui_options[color_secondary]',
807
			)));
808
		}
809
810
811
		public static function custom_css($compatibility = true) {
812
			$settings = get_option('aui_options');
813
814
			ob_start();
815
			?>
816
			<style>
817
				<?php
818
					if(!empty($settings['color_primary']) && $settings['color_primary'] != "#1e73be"){
819
						echo self::css_primary($settings['color_primary'],$compatibility);
820
					}
821
822
					if(!empty($settings['color_secondary']) && $settings['color_secondary'] != "#6c757d"){
823
						echo self::css_secondary($settings['color_secondary'],$compatibility);
824
					}
825
                ?>
826
			</style>
827
			<?php
828
829
830
			/*
831
			 * We only add the <script> tags for code highlighting, so we strip them from the output.
832
			 */
833
			return str_replace( array(
834
				'<style>',
835
				'</style>'
836
			), '', ob_get_clean());
837
		}
838
839
		public static function css_primary($color_code,$compatibility){;
840
			$color_code = sanitize_hex_color($color_code);
841
			if(!$color_code){return '';}
842
			/**
843
			 * c = color, b = background color, o = border-color, f = fill
844
			 */
845
			$selectors = array(
846
				'a' => array('c'),
847
				'.btn-primary' => array('b','o'),
848
				'.btn-primary.disabled' => array('b','o'),
849
				'.btn-primary:disabled' => array('b','o'),
850
				'.btn-outline-primary' => array('c','o'),
851
				'.btn-outline-primary:hover' => array('b','o'),
852
				'.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'),
853
				'.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'),
854
				'.show>.btn-outline-primary.dropdown-toggle' => array('b','o'),
855
				'.btn-link' => array('c'),
856
				'.dropdown-item.active' => array('b'),
857
				'.custom-control-input:checked~.custom-control-label::before' => array('b','o'),
858
				'.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'),
859
//				'.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules...
860
//				'.custom-range::-moz-range-thumb' => array('b'),
861
//				'.custom-range::-ms-thumb' => array('b'),
862
				'.nav-pills .nav-link.active' => array('b'),
863
				'.nav-pills .show>.nav-link' => array('b'),
864
				'.page-link' => array('c'),
865
				'.page-item.active .page-link' => array('b','o'),
866
				'.badge-primary' => array('b'),
867
				'.alert-primary' => array('b','o'),
868
				'.progress-bar' => array('b'),
869
				'.list-group-item.active' => array('b','o'),
870
				'.bg-primary' => array('b','f'),
871
				'.btn-link.btn-primary' => array('c'),
872
				'.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'),
873
			);
874
875
			$important_selectors = array(
876
				'.bg-primary' => array('b','f'),
877
				'.border-primary' => array('o'),
878
				'.text-primary' => array('c'),
879
			);
880
881
			$color = array();
882
			$color_i = array();
883
			$background = array();
884
			$background_i = array();
885
			$border = array();
886
			$border_i = array();
887
			$fill = array();
888
			$fill_i = array();
889
890
			$output = '';
891
892
			// build rules into each type
893
			foreach($selectors as $selector => $types){
894
				$selector = $compatibility ? ".bsui ".$selector : $selector;
895
				$types = array_combine($types,$types);
896
				if(isset($types['c'])){$color[] = $selector;}
897
				if(isset($types['b'])){$background[] = $selector;}
898
				if(isset($types['o'])){$border[] = $selector;}
899
				if(isset($types['f'])){$fill[] = $selector;}
900
			}
901
902
			// build rules into each type
903
			foreach($important_selectors as $selector => $types){
904
				$selector = $compatibility ? ".bsui ".$selector : $selector;
905
				$types = array_combine($types,$types);
906
				if(isset($types['c'])){$color_i[] = $selector;}
907
				if(isset($types['b'])){$background_i[] = $selector;}
908
				if(isset($types['o'])){$border_i[] = $selector;}
909
				if(isset($types['f'])){$fill_i[] = $selector;}
910
			}
911
912
			// add any color rules
913
			if(!empty($color)){
914
				$output .= implode(",",$color) . "{color: $color_code;} ";
915
			}
916
			if(!empty($color_i)){
917
				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
918
			}
919
920
			// add any background color rules
921
			if(!empty($background)){
922
				$output .= implode(",",$background) . "{background-color: $color_code;} ";
923
			}
924
			if(!empty($background_i)){
925
				$output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
926
			}
927
928
			// add any border color rules
929
			if(!empty($border)){
930
				$output .= implode(",",$border) . "{border-color: $color_code;} ";
931
			}
932
			if(!empty($border_i)){
933
				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
934
			}
935
936
			// add any fill color rules
937
			if(!empty($fill)){
938
				$output .= implode(",",$fill) . "{fill: $color_code;} ";
939
			}
940
			if(!empty($fill_i)){
941
				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
942
			}
943
944
945
			$prefix = $compatibility ? ".bsui " : "";
946
947
			// darken
948
			$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

948
			$darker_075 = self::css_hex_lighten_darken($color_code,/** @scrutinizer ignore-type */ "-0.075");
Loading history...
949
			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
950
			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
951
952
			// lighten
953
			$lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
954
955
			// opacity see https://css-tricks.com/8-digit-hex-codes/
956
			$op_25 = $color_code."40"; // 25% opacity
957
958
959
			// button states
960
			$output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
961
			$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;} ";
962
			$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.";} ";
963
			$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;} ";
964
965
966
			// dropdown's
967
			$output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
968
969
970
			// input states
971
			$output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} ";
972
973
			// page link
974
			$output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
975
976
			return $output;
977
		}
978
979
		public static function css_secondary($color_code,$compatibility){;
980
			$color_code = sanitize_hex_color($color_code);
981
			if(!$color_code){return '';}
982
			/**
983
			 * c = color, b = background color, o = border-color, f = fill
984
			 */
985
			$selectors = array(
986
				'.btn-secondary' => array('b','o'),
987
				'.btn-secondary.disabled' => array('b','o'),
988
				'.btn-secondary:disabled' => array('b','o'),
989
				'.btn-outline-secondary' => array('c','o'),
990
				'.btn-outline-secondary:hover' => array('b','o'),
991
				'.btn-outline-secondary.disabled' => array('c'),
992
				'.btn-outline-secondary:disabled' => array('c'),
993
				'.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'),
994
				'.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'),
995
				'.btn-outline-secondary.dropdown-toggle' => array('b','o'),
996
				'.badge-secondary' => array('b'),
997
				'.alert-secondary' => array('b','o'),
998
				'.btn-link.btn-secondary' => array('c'),
999
			);
1000
1001
			$important_selectors = array(
1002
				'.bg-secondary' => array('b','f'),
1003
				'.border-secondary' => array('o'),
1004
				'.text-secondary' => array('c'),
1005
			);
1006
1007
			$color = array();
1008
			$color_i = array();
1009
			$background = array();
1010
			$background_i = array();
1011
			$border = array();
1012
			$border_i = array();
1013
			$fill = array();
1014
			$fill_i = array();
1015
1016
			$output = '';
1017
1018
			// build rules into each type
1019
			foreach($selectors as $selector => $types){
1020
				$selector = $compatibility ? ".bsui ".$selector : $selector;
1021
				$types = array_combine($types,$types);
1022
				if(isset($types['c'])){$color[] = $selector;}
1023
				if(isset($types['b'])){$background[] = $selector;}
1024
				if(isset($types['o'])){$border[] = $selector;}
1025
				if(isset($types['f'])){$fill[] = $selector;}
1026
			}
1027
1028
			// build rules into each type
1029
			foreach($important_selectors as $selector => $types){
1030
				$selector = $compatibility ? ".bsui ".$selector : $selector;
1031
				$types = array_combine($types,$types);
1032
				if(isset($types['c'])){$color_i[] = $selector;}
1033
				if(isset($types['b'])){$background_i[] = $selector;}
1034
				if(isset($types['o'])){$border_i[] = $selector;}
1035
				if(isset($types['f'])){$fill_i[] = $selector;}
1036
			}
1037
1038
			// add any color rules
1039
			if(!empty($color)){
1040
				$output .= implode(",",$color) . "{color: $color_code;} ";
1041
			}
1042
			if(!empty($color_i)){
1043
				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1044
			}
1045
1046
			// add any background color rules
1047
			if(!empty($background)){
1048
				$output .= implode(",",$background) . "{background-color: $color_code;} ";
1049
			}
1050
			if(!empty($background_i)){
1051
				$output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1052
			}
1053
1054
			// add any border color rules
1055
			if(!empty($border)){
1056
				$output .= implode(",",$border) . "{border-color: $color_code;} ";
1057
			}
1058
			if(!empty($border_i)){
1059
				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1060
			}
1061
1062
			// add any fill color rules
1063
			if(!empty($fill)){
1064
				$output .= implode(",",$fill) . "{fill: $color_code;} ";
1065
			}
1066
			if(!empty($fill_i)){
1067
				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1068
			}
1069
1070
1071
			$prefix = $compatibility ? ".bsui " : "";
1072
1073
			// darken
1074
			$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

1074
			$darker_075 = self::css_hex_lighten_darken($color_code,/** @scrutinizer ignore-type */ "-0.075");
Loading history...
1075
			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1076
			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1077
1078
			// lighten
1079
			$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...
1080
1081
			// opacity see https://css-tricks.com/8-digit-hex-codes/
1082
			$op_25 = $color_code."40"; // 25% opacity
1083
1084
1085
			// button states
1086
			$output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1087
			$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;} ";
1088
			$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.";} ";
1089
			$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;} ";
1090
1091
1092
			return $output;
1093
		}
1094
1095
		/**
1096
		 * Increases or decreases the brightness of a color by a percentage of the current brightness.
1097
		 *
1098
		 * @param   string  $hexCode        Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF`
1099
		 * @param   float   $adjustPercent  A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker.
1100
		 *
1101
		 * @return  string
1102
		 */
1103
		public static function css_hex_lighten_darken($hexCode, $adjustPercent) {
1104
			$hexCode = ltrim($hexCode, '#');
1105
1106
			if (strlen($hexCode) == 3) {
1107
				$hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2];
1108
			}
1109
1110
			$hexCode = array_map('hexdec', str_split($hexCode, 2));
1111
1112
			foreach ($hexCode as & $color) {
1113
				$adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color;
1114
				$adjustAmount = ceil($adjustableLimit * $adjustPercent);
1115
1116
				$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 $number 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

1116
				$color = str_pad(dechex(/** @scrutinizer ignore-type */ $color + $adjustAmount), 2, '0', STR_PAD_LEFT);
Loading history...
1117
			}
1118
1119
			return '#' . implode($hexCode);
1120
		}
1121
1122
		/**
1123
		 * Check if we should display examples.
1124
		 */
1125
		public function maybe_show_examples(){
1126
			if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){
1127
				echo "<head>";
1128
				wp_head();
1129
				echo "</head>";
1130
				echo "<body>";
1131
				echo $this->get_examples();
1132
				echo "</body>";
1133
				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...
1134
			}
1135
		}
1136
1137
		/**
1138
		 * Get developer examples.
1139
		 *
1140
		 * @return string
1141
		 */
1142
		public function get_examples(){
1143
			$output = '';
1144
1145
1146
			// open form
1147
			$output .= "<form class='p-5 m-5 border rounded'>";
1148
1149
			// input example
1150
			$output .= aui()->input(array(
1151
				'type'  =>  'text',
1152
				'id'    =>  'text-example',
1153
				'name'    =>  'text-example',
1154
				'placeholder'   => 'text placeholder',
1155
				'title'   => 'Text input example',
1156
				'value' =>  '',
1157
				'required'  => false,
1158
				'help_text' => 'help text',
1159
				'label' => 'Text input example label'
1160
			));
1161
1162
			// input example
1163
			$output .= aui()->input(array(
1164
				'type'  =>  'url',
1165
				'id'    =>  'text-example2',
1166
				'name'    =>  'text-example',
1167
				'placeholder'   => 'url placeholder',
1168
				'title'   => 'Text input example',
1169
				'value' =>  '',
1170
				'required'  => false,
1171
				'help_text' => 'help text',
1172
				'label' => 'Text input example label'
1173
			));
1174
1175
			// checkbox example
1176
			$output .= aui()->input(array(
1177
				'type'  =>  'checkbox',
1178
				'id'    =>  'checkbox-example',
1179
				'name'    =>  'checkbox-example',
1180
				'placeholder'   => 'checkbox-example',
1181
				'title'   => 'Checkbox example',
1182
				'value' =>  '1',
1183
				'checked'   => true,
1184
				'required'  => false,
1185
				'help_text' => 'help text',
1186
				'label' => 'Checkbox checked'
1187
			));
1188
1189
			// checkbox example
1190
			$output .= aui()->input(array(
1191
				'type'  =>  'checkbox',
1192
				'id'    =>  'checkbox-example2',
1193
				'name'    =>  'checkbox-example2',
1194
				'placeholder'   => 'checkbox-example',
1195
				'title'   => 'Checkbox example',
1196
				'value' =>  '1',
1197
				'checked'   => false,
1198
				'required'  => false,
1199
				'help_text' => 'help text',
1200
				'label' => 'Checkbox un-checked'
1201
			));
1202
1203
			// switch example
1204
			$output .= aui()->input(array(
1205
				'type'  =>  'checkbox',
1206
				'id'    =>  'switch-example',
1207
				'name'    =>  'switch-example',
1208
				'placeholder'   => 'checkbox-example',
1209
				'title'   => 'Switch example',
1210
				'value' =>  '1',
1211
				'checked'   => true,
1212
				'switch'    => true,
1213
				'required'  => false,
1214
				'help_text' => 'help text',
1215
				'label' => 'Switch on'
1216
			));
1217
1218
			// switch example
1219
			$output .= aui()->input(array(
1220
				'type'  =>  'checkbox',
1221
				'id'    =>  'switch-example2',
1222
				'name'    =>  'switch-example2',
1223
				'placeholder'   => 'checkbox-example',
1224
				'title'   => 'Switch example',
1225
				'value' =>  '1',
1226
				'checked'   => false,
1227
				'switch'    => true,
1228
				'required'  => false,
1229
				'help_text' => 'help text',
1230
				'label' => 'Switch off'
1231
			));
1232
1233
			// close form
1234
			$output .= "</form>";
1235
1236
			return $output;
1237
		}
1238
1239
	}
1240
1241
	/**
1242
	 * Run the class if found.
1243
	 */
1244
	AyeCode_UI_Settings::instance();
1245
}