Total Complexity | 348 |
Total Lines | 3087 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like AyeCode_UI_Settings often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AyeCode_UI_Settings, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
31 | class AyeCode_UI_Settings { |
||
32 | |||
33 | /** |
||
34 | * Class version version. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | public $version = '0.2.15'; |
||
39 | |||
40 | /** |
||
41 | * Class textdomain. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | public $textdomain = 'aui'; |
||
46 | |||
47 | /** |
||
48 | * Latest version of Bootstrap at time of publish published. |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | public $latest = "5.2.2"; |
||
53 | |||
54 | /** |
||
55 | * Current version of select2 being used. |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | public $select2_version = "4.0.11"; |
||
60 | |||
61 | /** |
||
62 | * The title. |
||
63 | * |
||
64 | * @var string |
||
65 | */ |
||
66 | public $name = 'AyeCode UI'; |
||
67 | |||
68 | /** |
||
69 | * The relative url to the assets. |
||
70 | * |
||
71 | * @var string |
||
72 | */ |
||
73 | public $url = ''; |
||
74 | |||
75 | /** |
||
76 | * Holds the settings values. |
||
77 | * |
||
78 | * @var array |
||
79 | */ |
||
80 | private $settings; |
||
81 | |||
82 | /** |
||
83 | * AyeCode_UI_Settings instance. |
||
84 | * |
||
85 | * @access private |
||
86 | * @since 1.0.0 |
||
87 | * @var AyeCode_UI_Settings There can be only one! |
||
88 | */ |
||
89 | private static $instance = null; |
||
90 | |||
91 | |||
92 | /** |
||
93 | * Main AyeCode_UI_Settings Instance. |
||
94 | * |
||
95 | * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded. |
||
96 | * |
||
97 | * @since 1.0.0 |
||
98 | * @static |
||
99 | * @return AyeCode_UI_Settings - Main instance. |
||
100 | */ |
||
101 | public static function instance() { |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * Add custom colors to the color selector. |
||
130 | * |
||
131 | * @param $theme_colors |
||
132 | * @param $include_outlines |
||
133 | * @param $include_branding |
||
134 | * |
||
135 | * @return mixed |
||
136 | */ |
||
137 | public function sd_aui_colors( $theme_colors, $include_outlines, $include_branding ){ |
||
138 | |||
139 | |||
140 | $setting = wp_get_global_settings(); |
||
141 | |||
142 | if(!empty($setting['color']['palette']['custom'])){ |
||
143 | foreach($setting['color']['palette']['custom'] as $color){ |
||
144 | $theme_colors[$color['slug']] = esc_attr($color['name']); |
||
145 | } |
||
146 | } |
||
147 | |||
148 | return $theme_colors; |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * Setup some constants. |
||
153 | */ |
||
154 | public function constants(){ |
||
219 | } |
||
220 | |||
221 | } |
||
222 | |||
223 | public static function get_colors( $original = false){ |
||
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(){ |
||
389 | } |
||
390 | |||
391 | /** |
||
392 | * Add a html font size to the footer. |
||
393 | */ |
||
394 | public function html_font_size(){ |
||
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(); |
||
423 | |||
424 | // echo '###'.$screen->id; |
||
425 | |||
426 | // check if we are on a AUI screen |
||
427 | if ( $screen && in_array( $screen->id, $screen_ids ) ) { |
||
428 | $load = true; |
||
429 | } |
||
430 | |||
431 | //load for widget previews in WP 5.8 |
||
432 | if( !empty($_REQUEST['legacy-widget-preview'])){ |
||
433 | $load = true; |
||
434 | } |
||
435 | } |
||
436 | |||
437 | |||
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() { |
||
453 | } |
||
454 | |||
455 | /** |
||
456 | * Adds the styles. |
||
457 | */ |
||
458 | public function enqueue_style() { |
||
459 | global $aui_bs5; |
||
460 | |||
461 | $load_fse = false; |
||
462 | |||
463 | if( is_admin() && !$this->is_aui_screen()){ |
||
464 | // don't add wp-admin scripts if not requested to |
||
465 | }else{ |
||
466 | $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
||
467 | |||
468 | $rtl = is_rtl() && ! $aui_bs5 ? '-rtl' : ''; |
||
469 | |||
470 | $bs_ver = $this->settings['bs_ver'] == '5' ? '-v5' : ''; |
||
471 | |||
472 | if($this->settings[$css_setting]){ |
||
473 | $compatibility = $this->settings[$css_setting]=='core' ? false : true; |
||
474 | $url = $this->settings[$css_setting]=='core' ? $this->url.'assets'.$bs_ver.'/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets'.$bs_ver.'/css/ayecode-ui-compatibility'.$rtl.'.css'; |
||
475 | |||
476 | |||
477 | |||
478 | wp_register_style( 'ayecode-ui', $url, array(), $this->version ); |
||
479 | wp_enqueue_style( 'ayecode-ui' ); |
||
480 | |||
481 | $current_screen = function_exists('get_current_screen' ) ? get_current_screen() : ''; |
||
482 | |||
483 | // if ( is_admin() && !empty($_REQUEST['postType']) ) { |
||
484 | if ( is_admin() && ( !empty($_REQUEST['postType']) || $current_screen->is_block_editor() ) && ( defined( 'BLOCKSTRAP_VERSION' ) || defined( 'AUI_FSE' ) ) ) { |
||
485 | $url = $this->url.'assets'.$bs_ver.'/css/ayecode-ui-fse.css'; |
||
486 | wp_register_style( 'ayecode-ui-fse', $url, array(), $this->version ); |
||
487 | wp_enqueue_style( 'ayecode-ui-fse' ); |
||
488 | $load_fse = true; |
||
489 | } |
||
490 | |||
491 | |||
492 | // flatpickr |
||
493 | wp_register_style( 'flatpickr', $this->url.'assets'.$bs_ver.'/css/flatpickr.min.css', array(), $this->version ); |
||
494 | |||
495 | // fix some wp-admin issues |
||
496 | if(is_admin()){ |
||
497 | $custom_css = " |
||
498 | body{ |
||
499 | background-color: #f1f1f1; |
||
500 | font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif; |
||
501 | font-size:13px; |
||
502 | } |
||
503 | a { |
||
504 | color: #0073aa; |
||
505 | text-decoration: underline; |
||
506 | } |
||
507 | label { |
||
508 | display: initial; |
||
509 | margin-bottom: 0; |
||
510 | } |
||
511 | input, select { |
||
512 | margin: 1px; |
||
513 | line-height: initial; |
||
514 | } |
||
515 | th, td, div, h2 { |
||
516 | box-sizing: content-box; |
||
517 | } |
||
518 | h1, h2, h3, h4, h5, h6 { |
||
519 | display: block; |
||
520 | font-weight: 600; |
||
521 | } |
||
522 | h2,h3 { |
||
523 | font-size: 1.3em; |
||
524 | margin: 1em 0 |
||
525 | } |
||
526 | .blocks-widgets-container .bsui *{ |
||
527 | box-sizing: border-box; |
||
528 | } |
||
529 | .bs-tooltip-top .arrow{ |
||
530 | margin-left:0px; |
||
531 | } |
||
532 | |||
533 | .custom-switch input[type=checkbox]{ |
||
534 | display:none; |
||
535 | } |
||
536 | "; |
||
537 | |||
538 | // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 |
||
539 | $custom_css .= " |
||
540 | .edit-post-sidebar input[type=color].components-text-control__input{ |
||
541 | padding: 0; |
||
542 | } |
||
543 | "; |
||
544 | wp_add_inline_style( 'ayecode-ui', $custom_css ); |
||
545 | } |
||
546 | |||
547 | // custom changes |
||
548 | if ( $load_fse ) { |
||
549 | wp_add_inline_style( 'ayecode-ui-fse', self::custom_css($compatibility) ); |
||
550 | }else{ |
||
551 | wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); |
||
552 | |||
553 | } |
||
554 | |||
555 | } |
||
556 | } |
||
557 | |||
558 | |||
559 | } |
||
560 | |||
561 | /** |
||
562 | * Get inline script used if bootstrap enqueued |
||
563 | * |
||
564 | * If this remains small then its best to use this than to add another JS file. |
||
565 | */ |
||
566 | public function inline_script() { |
||
567 | global $aui_bs5; |
||
568 | // Flatpickr calendar locale |
||
569 | $flatpickr_locale = self::flatpickr_locale(); |
||
570 | |||
571 | ob_start(); |
||
572 | if ( $aui_bs5 ) { |
||
573 | include_once( dirname( __FILE__ ) . '/inc/bs5-js.php' ); |
||
574 | }else{ |
||
575 | include_once( dirname( __FILE__ ) . '/inc/bs4-js.php' ); |
||
576 | } |
||
577 | |||
578 | $output = ob_get_clean(); |
||
579 | |||
580 | /* |
||
581 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
||
582 | */ |
||
583 | return str_replace( array( |
||
584 | '<script>', |
||
585 | '</script>' |
||
586 | ), '', self::minify_js($output) ); |
||
587 | } |
||
588 | |||
589 | |||
590 | /** |
||
591 | * JS to help with conflict issues with other plugins and themes using bootstrap v3. |
||
592 | * |
||
593 | * @TODO we may need this when other conflicts arrise. |
||
594 | * @return mixed |
||
595 | */ |
||
596 | public static function bs3_compat_js() { |
||
597 | ob_start(); |
||
598 | ?> |
||
599 | <script> |
||
600 | <?php if( defined( 'FUSION_BUILDER_VERSION' ) ){ ?> |
||
601 | /* With Avada builder */ |
||
602 | |||
603 | <?php } ?> |
||
604 | </script> |
||
605 | <?php |
||
606 | return str_replace( array( |
||
607 | '<script>', |
||
608 | '</script>' |
||
609 | ), '', ob_get_clean()); |
||
610 | } |
||
611 | |||
612 | /** |
||
613 | * Get inline script used if bootstrap file browser enqueued. |
||
614 | * |
||
615 | * If this remains small then its best to use this than to add another JS file. |
||
616 | */ |
||
617 | public function inline_script_file_browser(){ |
||
618 | ob_start(); |
||
619 | ?> |
||
620 | <script> |
||
621 | // run on doc ready |
||
622 | jQuery(document).ready(function () { |
||
623 | bsCustomFileInput.init(); |
||
624 | }); |
||
625 | </script> |
||
626 | <?php |
||
627 | $output = ob_get_clean(); |
||
628 | |||
629 | /* |
||
630 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
||
631 | */ |
||
632 | return str_replace( array( |
||
633 | '<script>', |
||
634 | '</script>' |
||
635 | ), '', $output ); |
||
636 | } |
||
637 | |||
638 | /** |
||
639 | * Adds the Font Awesome JS. |
||
640 | */ |
||
641 | public function enqueue_scripts() { |
||
642 | |||
643 | if( is_admin() && !$this->is_aui_screen()){ |
||
644 | // don't add wp-admin scripts if not requested to |
||
645 | }else { |
||
646 | |||
647 | $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend'; |
||
648 | |||
649 | $bs_ver = $this->settings['bs_ver'] == '5' ? '-v5' : ''; |
||
650 | |||
651 | // select2 |
||
652 | wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version ); |
||
653 | |||
654 | // flatpickr |
||
655 | wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->version ); |
||
656 | |||
657 | // iconpicker |
||
658 | if ( defined( 'FAS_ICONPICKER_JS_URL' ) ) { |
||
659 | wp_register_script( 'iconpicker', FAS_ICONPICKER_JS_URL, array(), $this->version ); |
||
660 | }else{ |
||
661 | wp_register_script( 'iconpicker', $this->url . 'assets/js/fa-iconpicker.min.js', array(), $this->version ); |
||
662 | } |
||
663 | |||
664 | // Bootstrap file browser |
||
665 | wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version ); |
||
666 | wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() ); |
||
667 | |||
668 | $load_inline = false; |
||
669 | |||
670 | if ( $this->settings[ $js_setting ] == 'core-popper' ) { |
||
671 | // Bootstrap bundle |
||
672 | $url = $this->url . 'assets' . $bs_ver . '/js/bootstrap.bundle.min.js'; |
||
673 | wp_register_script( 'bootstrap-js-bundle', $url, array( |
||
674 | 'select2', |
||
675 | 'jquery' |
||
676 | ), $this->version, $this->is_bs3_compat() ); |
||
677 | // if in admin then add to footer for compatibility. |
||
678 | is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' ); |
||
679 | $script = $this->inline_script(); |
||
680 | wp_add_inline_script( 'bootstrap-js-bundle', $script ); |
||
681 | } elseif ( $this->settings[ $js_setting ] == 'popper' ) { |
||
682 | $url = $this->url . 'assets/js/popper.min.js'; //@todo we need to update this to bs5 |
||
683 | wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->version ); |
||
684 | wp_enqueue_script( 'bootstrap-js-popper' ); |
||
685 | $load_inline = true; |
||
686 | } else { |
||
687 | $load_inline = true; |
||
688 | } |
||
689 | |||
690 | // Load needed inline scripts by faking the loading of a script if the main script is not being loaded |
||
691 | if ( $load_inline ) { |
||
692 | wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) ); |
||
693 | wp_enqueue_script( 'bootstrap-dummy' ); |
||
694 | $script = $this->inline_script(); |
||
695 | wp_add_inline_script( 'bootstrap-dummy', $script ); |
||
696 | } |
||
697 | } |
||
698 | |||
699 | } |
||
700 | |||
701 | /** |
||
702 | * Enqueue flatpickr if called. |
||
703 | */ |
||
704 | public function enqueue_flatpickr(){ |
||
705 | wp_enqueue_style( 'flatpickr' ); |
||
706 | wp_enqueue_script( 'flatpickr' ); |
||
707 | } |
||
708 | |||
709 | /** |
||
710 | * Enqueue iconpicker if called. |
||
711 | */ |
||
712 | public function enqueue_iconpicker(){ |
||
713 | wp_enqueue_style( 'iconpicker' ); |
||
714 | wp_enqueue_script( 'iconpicker' ); |
||
715 | } |
||
716 | |||
717 | /** |
||
718 | * Get the url path to the current folder. |
||
719 | * |
||
720 | * @return string |
||
721 | */ |
||
722 | public function get_url() { |
||
723 | $content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) ); |
||
724 | $content_url = untrailingslashit( WP_CONTENT_URL ); |
||
725 | |||
726 | // Replace http:// to https://. |
||
727 | if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) { |
||
728 | $content_url = str_replace( 'http://', 'https://', $content_url ); |
||
729 | } |
||
730 | |||
731 | // Check if we are inside a plugin |
||
732 | $file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) ); |
||
733 | $url = str_replace( $content_dir, $content_url, $file_dir ); |
||
734 | |||
735 | return trailingslashit( $url ); |
||
736 | } |
||
737 | |||
738 | /** |
||
739 | * Get the url path to the current folder. |
||
740 | * |
||
741 | * @return string |
||
742 | */ |
||
743 | public function get_url_old() { |
||
744 | |||
745 | $url = ''; |
||
746 | // check if we are inside a plugin |
||
747 | $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) ); |
||
748 | |||
749 | // add check in-case user has changed wp-content dir name. |
||
750 | $wp_content_folder_name = basename(WP_CONTENT_DIR); |
||
751 | $dir_parts = explode("/$wp_content_folder_name/",$file_dir); |
||
752 | $url_parts = explode("/$wp_content_folder_name/",plugins_url()); |
||
753 | |||
754 | if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
||
755 | $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] ); |
||
756 | } |
||
757 | |||
758 | return $url; |
||
759 | } |
||
760 | |||
761 | /** |
||
762 | * Register the database settings with WordPress. |
||
763 | */ |
||
764 | public function register_settings() { |
||
765 | register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' ); |
||
766 | } |
||
767 | |||
768 | /** |
||
769 | * Add the WordPress settings menu item. |
||
770 | * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
||
771 | */ |
||
772 | public function menu_item() { |
||
773 | $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
||
774 | call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array( |
||
775 | $this, |
||
776 | 'settings_page' |
||
777 | ) ); |
||
778 | } |
||
779 | |||
780 | /** |
||
781 | * Get a list of themes and their default JS settings. |
||
782 | * |
||
783 | * @return array |
||
784 | */ |
||
785 | public function theme_js_settings(){ |
||
790 | //'avada' => 'required', // removed as we now add compatibility |
||
791 | ); |
||
792 | } |
||
793 | |||
794 | /** |
||
795 | * Get the date the site was installed. |
||
796 | * |
||
797 | * @return false|string |
||
798 | */ |
||
799 | public function get_site_install_date() { |
||
800 | global $wpdb; // This gives you access to the WordPress database object |
||
801 | |||
802 | // Prepare the SQL query to get the oldest registration date |
||
803 | $query = "SELECT MIN(user_registered) AS oldest_registration_date FROM {$wpdb->users}"; |
||
804 | |||
805 | // Execute the query |
||
806 | $date = $wpdb->get_var( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
||
807 | |||
808 | return $date ? $date : false; |
||
809 | } |
||
810 | |||
811 | /** |
||
812 | * Show admin notice if backend scripts not loaded. |
||
813 | */ |
||
814 | public function show_admin_version_notice(){ |
||
815 | $fix_url = admin_url("options-general.php?page=ayecode-ui-settings" ); |
||
816 | $button = '<a href="'.esc_url($fix_url).'" class="button-primary">View Settings</a>'; |
||
817 | $message = __( '<b>Style Issue:</b> AyeCode UI has changed its default version from v4 to v5, if you notice unwanted style changes, please revert to v4 (saving the settings page will remove this notice)')." " .$button; |
||
818 | echo '<div class="notice notice-error aui-settings-error-notice"><p>'. wp_kses_post( $message ).'</p></div>'; |
||
819 | } |
||
820 | |||
821 | /** |
||
822 | * Get the current Font Awesome output settings. |
||
823 | * |
||
824 | * @return array The array of settings. |
||
825 | */ |
||
826 | public function get_settings() { |
||
827 | |||
828 | $db_settings = get_option( 'ayecode-ui-settings' ); |
||
829 | |||
830 | // Maybe show default version notice |
||
831 | $site_install_date = new DateTime( self::get_site_install_date() ); |
||
832 | $switch_over_date = new DateTime("2024-02-01"); |
||
833 | if ( empty( $db_settings ) && $site_install_date < $switch_over_date ) { |
||
834 | add_action( 'admin_notices', array( $this, 'show_admin_version_notice' ) ); |
||
835 | } |
||
836 | |||
837 | $js_default = 'core-popper'; |
||
838 | $js_default_backend = $js_default; |
||
839 | |||
840 | // maybe set defaults (if no settings set) |
||
841 | if(empty($db_settings)){ |
||
842 | $active_theme = strtolower( get_template() ); // active parent theme. |
||
843 | $theme_js_settings = self::theme_js_settings(); |
||
844 | if(isset($theme_js_settings[$active_theme])){ |
||
845 | $js_default = $theme_js_settings[$active_theme]; |
||
846 | $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default; |
||
847 | } |
||
848 | } |
||
849 | |||
850 | /** |
||
851 | * Filter the default settings. |
||
852 | */ |
||
853 | $defaults = apply_filters( 'ayecode-ui-default-settings', array( |
||
854 | 'css' => 'compatibility', // core, compatibility |
||
855 | 'js' => $js_default, // js to load, core-popper, popper |
||
856 | 'html_font_size' => '16', // js to load, core-popper, popper |
||
857 | 'css_backend' => 'compatibility', // core, compatibility |
||
858 | 'js_backend' => $js_default_backend, // js to load, core-popper, popper |
||
859 | 'disable_admin' => '', // URL snippets to disable loading on admin |
||
860 | 'bs_ver' => '5', // The default bootstrap version to sue by default |
||
861 | ), $db_settings ); |
||
862 | |||
863 | $settings = wp_parse_args( $db_settings, $defaults ); |
||
864 | |||
865 | /** |
||
866 | * Filter the Bootstrap settings. |
||
867 | * |
||
868 | * @todo if we add this filer people might use it and then it defeats the purpose of this class :/ |
||
869 | */ |
||
870 | return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults ); |
||
871 | } |
||
872 | |||
873 | |||
874 | /** |
||
875 | * The settings page html output. |
||
876 | */ |
||
877 | public function settings_page() { |
||
878 | if ( ! current_user_can( 'manage_options' ) ) { |
||
879 | wp_die( esc_attr__( 'You do not have sufficient permissions to access this page.', 'ayecode-connect' ) ); |
||
880 | } |
||
881 | $overrides = apply_filters( 'ayecode-ui-settings', array(), array(), array() ); |
||
882 | |||
883 | ?> |
||
884 | <div class="wrap"> |
||
885 | <h1><?php echo esc_attr( $this->name ); ?></h1> |
||
886 | <p><?php echo esc_html( apply_filters( 'ayecode-ui-settings-message', __("Here you can adjust settings if you are having compatibility issues.", 'ayecode-connect' ) ) );?></p> |
||
887 | <form method="post" action="options.php"> |
||
888 | <?php |
||
889 | settings_fields( 'ayecode-ui-settings' ); |
||
890 | do_settings_sections( 'ayecode-ui-settings' ); |
||
891 | ?> |
||
892 | |||
893 | <h2><?php esc_html_e( 'BootStrap Version', 'ayecode-connect' ); ?></h2> |
||
894 | <p><?php echo esc_html( apply_filters( 'ayecode-ui-version-settings-message', __("V5 is recommended, however if you have another plugin installed using v4, you may need to use v4 also.", 'ayecode-connect' ) ) );?></p> |
||
895 | <div class="bsui"><?php |
||
896 | if ( ! empty( $overrides ) ) { |
||
897 | echo aui()->alert(array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
||
898 | 'type'=> 'info', |
||
899 | 'content'=> esc_attr__("Some options are disabled as your current theme is overriding them.", 'ayecode-connect' ) |
||
900 | )); |
||
901 | } |
||
902 | ?> |
||
903 | </div> |
||
904 | <table class="form-table wpbs-table-version-settings"> |
||
905 | <tr valign="top"> |
||
906 | <th scope="row"><label for="wpbs-css"><?php esc_html_e( 'Version', 'ayecode-connect' ); ?></label></th> |
||
907 | <td> |
||
908 | <select name="ayecode-ui-settings[bs_ver]" id="wpbs-css" <?php echo !empty($overrides['bs_ver']) ? 'disabled' : ''; ?>> |
||
909 | <option value="5" <?php selected( $this->settings['bs_ver'], '5' ); ?>><?php esc_html_e( 'v5 (recommended)', 'ayecode-connect' ); ?></option> |
||
910 | <option value="4" <?php selected( $this->settings['bs_ver'], '4' ); ?>><?php esc_html_e( 'v4 (legacy)', 'ayecode-connect' ); ?></option> |
||
911 | </select> |
||
912 | </td> |
||
913 | </tr> |
||
914 | </table> |
||
915 | |||
916 | <h2><?php esc_html_e( 'Frontend', 'ayecode-connect' ); ?></h2> |
||
917 | <table class="form-table wpbs-table-settings"> |
||
918 | <tr valign="top"> |
||
919 | <th scope="row"><label for="wpbs-css"><?php esc_html_e( 'Load CSS', 'ayecode-connect' ); ?></label></th> |
||
920 | <td> |
||
921 | <select name="ayecode-ui-settings[css]" id="wpbs-css" <?php echo !empty($overrides['css']) ? 'disabled' : ''; ?>> |
||
922 | <option value="compatibility" <?php selected( $this->settings['css'], 'compatibility' ); ?>><?php esc_html_e( 'Compatibility Mode (default)', 'ayecode-connect' ); ?></option> |
||
923 | <option value="core" <?php selected( $this->settings['css'], 'core' ); ?>><?php esc_html_e( 'Full Mode', 'ayecode-connect' ); ?></option> |
||
924 | <option value="" <?php selected( $this->settings['css'], '' ); ?>><?php esc_html_e( 'Disabled', 'ayecode-connect' ); ?></option> |
||
925 | </select> |
||
926 | </td> |
||
927 | </tr> |
||
928 | |||
929 | <tr valign="top"> |
||
930 | <th scope="row"><label for="wpbs-js"><?php esc_html_e( 'Load JS', 'ayecode-connect' ); ?></label></th> |
||
931 | <td> |
||
932 | <select name="ayecode-ui-settings[js]" id="wpbs-js" <?php echo !empty($overrides['js']) ? 'disabled' : ''; ?>> |
||
933 | <option value="core-popper" <?php selected( $this->settings['js'], 'core-popper' ); ?>><?php esc_html_e( 'Core + Popper (default)', 'ayecode-connect' ); ?></option> |
||
934 | <option value="popper" <?php selected( $this->settings['js'], 'popper' ); ?>><?php esc_html_e( 'Popper', 'ayecode-connect' ); ?></option> |
||
935 | <option value="required" <?php selected( $this->settings['js'], 'required' ); ?>><?php esc_html_e( 'Required functions only', 'ayecode-connect' ); ?></option> |
||
936 | <option value="" <?php selected( $this->settings['js'], '' ); ?>><?php esc_html_e( 'Disabled (not recommended)', 'ayecode-connect' ); ?></option> |
||
937 | </select> |
||
938 | </td> |
||
939 | </tr> |
||
940 | |||
941 | <tr valign="top"> |
||
942 | <th scope="row"><label for="wpbs-font_size"><?php esc_html_e( 'HTML Font Size (px)', 'ayecode-connect' ); ?></label></th> |
||
943 | <td> |
||
944 | <input type="number" name="ayecode-ui-settings[html_font_size]" id="wpbs-font_size" value="<?php echo absint( $this->settings['html_font_size']); ?>" placeholder="16" <?php echo !empty($overrides['html_font_size']) ? 'disabled' : ''; ?> /> |
||
945 | <p class="description" ><?php esc_html_e("Our font sizing is rem (responsive based) here you can set the html font size in-case your theme is setting it too low.", 'ayecode-connect' );?></p> |
||
946 | </td> |
||
947 | </tr> |
||
948 | |||
949 | </table> |
||
950 | |||
951 | <h2><?php esc_html_e( 'Backend', 'ayecode-connect' ); ?> (wp-admin)</h2> |
||
952 | <table class="form-table wpbs-table-settings"> |
||
953 | <tr valign="top"> |
||
954 | <th scope="row"><label for="wpbs-css-admin"><?php esc_html_e( 'Load CSS', 'ayecode-connect' ); ?></label></th> |
||
955 | <td> |
||
956 | <select name="ayecode-ui-settings[css_backend]" id="wpbs-css-admin" <?php echo !empty($overrides['css_backend']) ? 'disabled' : ''; ?>> |
||
957 | <option value="compatibility" <?php selected( $this->settings['css_backend'], 'compatibility' ); ?>><?php esc_html_e( 'Compatibility Mode (default)', 'ayecode-connect' ); ?></option> |
||
958 | <option value="core" <?php selected( $this->settings['css_backend'], 'core' ); ?>><?php esc_html_e( 'Full Mode (will cause style issues)', 'ayecode-connect' ); ?></option> |
||
959 | <option value="" <?php selected( $this->settings['css_backend'], '' ); ?>><?php esc_html_e( 'Disabled', 'ayecode-connect' ); ?></option> |
||
960 | </select> |
||
961 | </td> |
||
962 | </tr> |
||
963 | |||
964 | <tr valign="top"> |
||
965 | <th scope="row"><label for="wpbs-js-admin"><?php esc_html_e( 'Load JS', 'ayecode-connect' ); ?></label></th> |
||
966 | <td> |
||
967 | <select name="ayecode-ui-settings[js_backend]" id="wpbs-js-admin" <?php echo !empty($overrides['js_backend']) ? 'disabled' : ''; ?>> |
||
968 | <option value="core-popper" <?php selected( $this->settings['js_backend'], 'core-popper' ); ?>><?php esc_html_e( 'Core + Popper (default)', 'ayecode-connect' ); ?></option> |
||
969 | <option value="popper" <?php selected( $this->settings['js_backend'], 'popper' ); ?>><?php esc_html_e( 'Popper', 'ayecode-connect' ); ?></option> |
||
970 | <option value="required" <?php selected( $this->settings['js_backend'], 'required' ); ?>><?php esc_html_e( 'Required functions only', 'ayecode-connect' ); ?></option> |
||
971 | <option value="" <?php selected( $this->settings['js_backend'], '' ); ?>><?php esc_html_e( 'Disabled (not recommended)', 'ayecode-connect' ); ?></option> |
||
972 | </select> |
||
973 | </td> |
||
974 | </tr> |
||
975 | |||
976 | <tr valign="top"> |
||
977 | <th scope="row"><label for="wpbs-disable-admin"><?php esc_html_e( 'Disable load on URL', 'ayecode-connect' ); ?></label></th> |
||
978 | <td> |
||
979 | <p><?php esc_html_e( 'If you have backend conflict you can enter a partial URL argument that will disable the loading of AUI on those pages. Add each argument on a new line.', 'ayecode-connect' ); ?></p> |
||
980 | <textarea name="ayecode-ui-settings[disable_admin]" rows="10" cols="50" id="wpbs-disable-admin" class="large-text code" spellcheck="false" placeholder="myplugin.php action=go"><?php echo esc_textarea( $this->settings['disable_admin'] );?></textarea> |
||
981 | </td> |
||
982 | </tr> |
||
983 | </table> |
||
984 | |||
985 | <?php |
||
986 | submit_button(); |
||
987 | ?> |
||
988 | </form> |
||
989 | <div id="wpbs-version" data-aui-source="<?php echo esc_attr( $this->get_load_source() ); ?>"><?php echo esc_html( $this->version ); ?></div> |
||
990 | </div> |
||
991 | <?php |
||
992 | } |
||
993 | |||
994 | public function get_load_source(){ |
||
995 | $file = str_replace( array( "/", "\\" ), "/", realpath( __FILE__ ) ); |
||
996 | $plugins_dir = str_replace( array( "/", "\\" ), "/", realpath( WP_PLUGIN_DIR ) ); |
||
997 | |||
998 | // Find source plugin/theme of SD |
||
999 | $source = array(); |
||
1000 | if ( strpos( $file, $plugins_dir ) !== false ) { |
||
1001 | $source = explode( "/", plugin_basename( $file ) ); |
||
1002 | } else if ( function_exists( 'get_theme_root' ) ) { |
||
1003 | $themes_dir = str_replace( array( "/", "\\" ), "/", realpath( get_theme_root() ) ); |
||
1004 | |||
1005 | if ( strpos( $file, $themes_dir ) !== false ) { |
||
1006 | $source = explode( "/", ltrim( str_replace( $themes_dir, "", $file ), "/" ) ); |
||
1007 | } |
||
1008 | } |
||
1009 | |||
1010 | return isset($source[0]) ? esc_attr($source[0]) : ''; |
||
1011 | } |
||
1012 | |||
1013 | public function customizer_settings($wp_customize){ |
||
1014 | $wp_customize->add_section('aui_settings', array( |
||
1015 | 'title' => __('AyeCode UI', 'ayecode-connect' ), |
||
1016 | 'priority' => 120, |
||
1017 | )); |
||
1018 | |||
1019 | // ============================= |
||
1020 | // = Color Picker = |
||
1021 | // ============================= |
||
1022 | $wp_customize->add_setting('aui_options[color_primary]', array( |
||
1023 | 'default' => AUI_PRIMARY_COLOR, |
||
1024 | 'sanitize_callback' => 'sanitize_hex_color', |
||
1025 | 'capability' => 'edit_theme_options', |
||
1026 | 'type' => 'option', |
||
1027 | 'transport' => 'refresh', |
||
1028 | )); |
||
1029 | $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array( |
||
1030 | 'label' => __('Primary Color', 'ayecode-connect' ), |
||
1031 | 'section' => 'aui_settings', |
||
1032 | 'settings' => 'aui_options[color_primary]', |
||
1033 | ))); |
||
1034 | |||
1035 | $wp_customize->add_setting('aui_options[color_secondary]', array( |
||
1036 | 'default' => '#6c757d', |
||
1037 | 'sanitize_callback' => 'sanitize_hex_color', |
||
1038 | 'capability' => 'edit_theme_options', |
||
1039 | 'type' => 'option', |
||
1040 | 'transport' => 'refresh', |
||
1041 | )); |
||
1042 | $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array( |
||
1043 | 'label' => __('Secondary Color', 'ayecode-connect' ), |
||
1044 | 'section' => 'aui_settings', |
||
1045 | 'settings' => 'aui_options[color_secondary]', |
||
1046 | ))); |
||
1047 | } |
||
1048 | |||
1049 | /** |
||
1050 | * CSS to help with conflict issues with other plugins and themes using bootstrap v3. |
||
1051 | * |
||
1052 | * @return mixed |
||
1053 | */ |
||
1054 | public static function bs3_compat_css() { |
||
1089 | } |
||
1090 | |||
1091 | |||
1092 | public static function custom_css($compatibility = true) { |
||
1093 | global $aui_bs5; |
||
1094 | |||
1095 | $colors = array(); |
||
1096 | if ( defined( 'BLOCKSTRAP_VERSION' ) ) { |
||
1097 | |||
1098 | |||
1099 | $setting = wp_get_global_settings(); |
||
1100 | |||
1101 | // print_r(wp_get_global_styles());//exit; |
||
1102 | // print_r(get_default_block_editor_settings());exit; |
||
1103 | |||
1104 | // print_r($setting);echo '###';exit; |
||
1105 | if(!empty($setting['color']['palette']['theme'])){ |
||
1106 | foreach($setting['color']['palette']['theme'] as $color){ |
||
1107 | $colors[$color['slug']] = esc_attr($color['color']); |
||
1108 | } |
||
1109 | } |
||
1110 | |||
1111 | if(!empty($setting['color']['palette']['custom'])){ |
||
1112 | foreach($setting['color']['palette']['custom'] as $color){ |
||
1113 | $colors[$color['slug']] = esc_attr($color['color']); |
||
1114 | } |
||
1115 | } |
||
1116 | }else{ |
||
1117 | $settings = get_option('aui_options'); |
||
1118 | $colors = array( |
||
1119 | 'primary' => ! empty( $settings['color_primary'] ) ? $settings['color_primary'] : AUI_PRIMARY_COLOR, |
||
1120 | 'secondary' => ! empty( $settings['color_secondary'] ) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR |
||
1121 | ); |
||
1122 | } |
||
1123 | |||
1124 | ob_start(); |
||
1125 | |||
1126 | ?> |
||
1127 | <style> |
||
1128 | <?php |
||
1129 | |||
1130 | // BS v3 compat |
||
1131 | if( self::is_bs3_compat() ){ |
||
1132 | echo self::bs3_compat_css(); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
||
1133 | } |
||
1134 | |||
1135 | $current_screen = function_exists('get_current_screen' ) ? get_current_screen() : ''; |
||
1136 | $is_fse = false; |
||
1137 | if ( is_admin() && ( !empty($_REQUEST['postType']) || $current_screen->is_block_editor() ) && ( defined( 'BLOCKSTRAP_VERSION' ) || defined( 'AUI_FSE' ) ) ) { |
||
1138 | $is_fse = true; |
||
1139 | } |
||
1140 | |||
1141 | if(!empty($colors)){ |
||
1142 | $d_colors = self::get_colors(true); |
||
1143 | |||
1144 | // $is_fse = !empty($_REQUEST['postType']) && $_REQUEST['postType']=='wp_template'; |
||
1145 | foreach($colors as $key => $color ){ |
||
1146 | if((empty( $d_colors[$key]) || $d_colors[$key] != $color) || $is_fse ) { |
||
1147 | $var = $is_fse ? "var(--wp--preset--color--$key)" : $color; |
||
1148 | $compat = $is_fse ? '.editor-styles-wrapper' : $compatibility; |
||
1149 | echo $aui_bs5 ? self::css_overwrite_bs5($key,$var,$compat,$color) : self::css_overwrite($key,$var,$compat,$color); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
||
1150 | } |
||
1151 | } |
||
1152 | // exit; |
||
1153 | } |
||
1154 | |||
1155 | // Set admin bar z-index lower when modal is open. |
||
1156 | echo ' body.modal-open #wpadminbar{z-index:999}.embed-responsive-16by9 .fluid-width-video-wrapper{padding:0 !important;position:initial}'; |
||
1157 | |||
1158 | if(is_admin()){ |
||
1159 | echo ' body.modal-open #adminmenuwrap{z-index:999} body.modal-open #wpadminbar{z-index:1025}'; |
||
1160 | } |
||
1161 | |||
1162 | if( $aui_bs5 && defined( 'BLOCKSTRAP_VERSION' ) ){ |
||
1163 | $css = ''; |
||
1164 | $theme_settings = wp_get_global_styles(); |
||
1165 | |||
1166 | // print_r( $theme_settings);exit; |
||
1167 | |||
1168 | // font face |
||
1169 | if( !empty( $theme_settings['typography']['fontFamily'] ) ){ |
||
1170 | $t_fontface = str_replace( array('var:preset|','font-family|'), array('--wp--preset--','font-family--'), $theme_settings['typography']['fontFamily'] ); //var(--wp--preset--font-family--poppins) |
||
1171 | $css .= '--bs-body-font-family: ' . esc_attr($t_fontface) . ';'; |
||
1172 | } |
||
1173 | |||
1174 | // font size |
||
1175 | if( !empty( $theme_settings['typography']['fontSize'] ) ){ |
||
1176 | $css .= '--bs-body-font-size: ' . esc_attr( $theme_settings['typography']['fontSize'] ) . ' ;'; |
||
1177 | } |
||
1178 | |||
1179 | // line height |
||
1180 | if( !empty( $theme_settings['typography']['lineHeight'] ) ){ |
||
1181 | $css .= '--bs-body-line-height: ' . esc_attr( $theme_settings['typography']['lineHeight'] ) . ';'; |
||
1182 | } |
||
1183 | |||
1184 | |||
1185 | // font weight |
||
1186 | if( !empty( $theme_settings['typography']['fontWeight'] ) ){ |
||
1187 | $css .= '--bs-body-font-weight: ' . esc_attr( $theme_settings['typography']['fontWeight'] ) . ';'; |
||
1188 | } |
||
1189 | |||
1190 | // Background |
||
1191 | if( !empty( $theme_settings['color']['background'] ) ){ |
||
1192 | $css .= '--bs-body-bg: ' . esc_attr( $theme_settings['color']['background'] ) . ';'; |
||
1193 | } |
||
1194 | |||
1195 | // Background Gradient |
||
1196 | if( !empty( $theme_settings['color']['gradient'] ) ){ |
||
1197 | $css .= 'background: ' . esc_attr( $theme_settings['color']['gradient'] ) . ';'; |
||
1198 | } |
||
1199 | |||
1200 | // Background Gradient |
||
1201 | if( !empty( $theme_settings['color']['gradient'] ) ){ |
||
1202 | $css .= 'background: ' . esc_attr( $theme_settings['color']['gradient'] ) . ';'; |
||
1203 | } |
||
1204 | |||
1205 | // text color |
||
1206 | if( !empty( $theme_settings['color']['text'] ) ){ |
||
1207 | $css .= '--bs-body-color: ' . esc_attr( $theme_settings['color']['text'] ) . ';'; |
||
1208 | } |
||
1209 | |||
1210 | |||
1211 | // link colors |
||
1212 | if( !empty( $theme_settings['elements']['link']['color']['text'] ) ){ |
||
1213 | $css .= '--bs-link-color: ' . esc_attr( $theme_settings['elements']['link']['color']['text'] ) . ';'; |
||
1214 | } |
||
1215 | if( !empty( $theme_settings['elements']['link'][':hover']['color']['text'] ) ){ |
||
1216 | $css .= '--bs-link-hover-color: ' . esc_attr( $theme_settings['elements']['link'][':hover']['color']['text'] ) . ';'; |
||
1217 | } |
||
1218 | |||
1219 | |||
1220 | |||
1221 | if($css){ |
||
1222 | echo $is_fse ? 'body.editor-styles-wrapper{' . esc_attr( $css ) . '}' : 'body{' . esc_attr( $css ) . '}'; |
||
1223 | } |
||
1224 | |||
1225 | $bep = $is_fse ? 'body.editor-styles-wrapper ' : ''; |
||
1226 | |||
1227 | |||
1228 | // Headings |
||
1229 | $headings_css = ''; |
||
1230 | if( !empty( $theme_settings['elements']['heading']['color']['text'] ) ){ |
||
1231 | $headings_css .= "color: " . esc_attr( $theme_settings['elements']['heading']['color']['text'] ) . ";"; |
||
1232 | } |
||
1233 | |||
1234 | // heading background |
||
1235 | if( !empty( $theme_settings['elements']['heading']['color']['background'] ) ){ |
||
1236 | $headings_css .= 'background: ' . esc_attr( $theme_settings['elements']['heading']['color']['background'] ) . ';'; |
||
1237 | } |
||
1238 | |||
1239 | // heading font family |
||
1240 | if( !empty( $theme_settings['elements']['heading']['typography']['fontFamily'] ) ){ |
||
1241 | $headings_css .= 'font-family: ' . esc_attr( $theme_settings['elements']['heading']['typography']['fontFamily'] ) . ';'; |
||
1242 | } |
||
1243 | |||
1244 | if( $headings_css ){ |
||
1245 | echo "$bep h1,$bep h2,$bep h3, $bep h4,$bep h5,$bep h6{ " . esc_attr( $headings_css ) . "}"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
||
1246 | } |
||
1247 | |||
1248 | $hs = array('h1','h2','h3','h4','h5','h6'); |
||
1249 | |||
1250 | foreach($hs as $hn){ |
||
1251 | $h_css = ''; |
||
1252 | if( !empty( $theme_settings['elements'][$hn]['color']['text'] ) ){ |
||
1253 | $h_css .= 'color: ' . esc_attr( $theme_settings['elements'][$hn]['color']['text'] ) . ';'; |
||
1254 | } |
||
1255 | |||
1256 | if( !empty( $theme_settings['elements'][$hn]['typography']['fontSize'] ) ){ |
||
1257 | $h_css .= 'font-size: ' . esc_attr( $theme_settings['elements'][$hn]['typography']['fontSize'] ) . ';'; |
||
1258 | } |
||
1259 | |||
1260 | if( !empty( $theme_settings['elements'][$hn]['typography']['fontFamily'] ) ){ |
||
1261 | $h_css .= 'font-family: ' . esc_attr( $theme_settings['elements'][$hn]['typography']['fontFamily'] ) . ';'; |
||
1262 | } |
||
1263 | |||
1264 | if($h_css){ |
||
1265 | echo esc_attr( $bep . $hn ) . '{'.esc_attr( $h_css ).'}'; |
||
1266 | } |
||
1267 | } |
||
1268 | |||
1269 | } |
||
1270 | ?> |
||
1271 | </style> |
||
1272 | <?php |
||
1273 | |||
1274 | |||
1275 | /* |
||
1276 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
||
1277 | */ |
||
1278 | return str_replace( array( |
||
1279 | '<style>', |
||
1280 | '</style>' |
||
1281 | ), '', self::minify_css( ob_get_clean() ) ); |
||
1282 | } |
||
1283 | |||
1284 | |||
1285 | |||
1286 | /** |
||
1287 | * Check if we should add booststrap 3 compatibility changes. |
||
1288 | * |
||
1289 | * @return bool |
||
1290 | */ |
||
1291 | public static function is_bs3_compat(){ |
||
1293 | } |
||
1294 | |||
1295 | public static function hex_to_rgb( $hex ) { |
||
1296 | // Remove '#' if present |
||
1297 | $hex = str_replace( '#', '', $hex ); |
||
1298 | |||
1299 | // Check if input is RGB |
||
1300 | if ( strpos( $hex, 'rgba(' ) === 0 || strpos( $hex, 'rgb(' ) === 0 ) { |
||
1301 | $_rgb = explode( ',', str_replace( array( 'rgba(', 'rgb(', ')' ), '', $hex ) ); |
||
1302 | |||
1303 | $rgb = ( isset( $_rgb[0] ) ? (int) trim( $_rgb[0] ) : '0' ) . ','; |
||
1304 | $rgb .= ( isset( $_rgb[1] ) ? (int) trim( $_rgb[1] ) : '0' ) . ','; |
||
1305 | $rgb .= ( isset( $_rgb[2] ) ? (int) trim( $_rgb[2] ) : '0' ); |
||
1306 | |||
1307 | return $rgb; |
||
1308 | } |
||
1309 | |||
1310 | // Convert 3-digit hex to 6-digit hex |
||
1311 | if ( strlen( $hex ) == 3 ) { |
||
1312 | $hex = str_repeat( substr( $hex, 0, 1 ), 2 ) . str_repeat( substr( $hex, 1, 1 ), 2 ) . str_repeat( substr( $hex, 2, 1 ), 2 ); |
||
1313 | } |
||
1314 | |||
1315 | // Convert hex to RGB |
||
1316 | $r = hexdec( substr( $hex, 0, 2 ) ); |
||
1317 | $g = hexdec( substr( $hex, 2, 2 ) ); |
||
1318 | $b = hexdec( substr( $hex, 4, 2 ) ); |
||
1319 | |||
1320 | // Return RGB values as an array |
||
1321 | return $r . ',' . $g . ',' . $b; |
||
1322 | } |
||
1323 | |||
1324 | /** |
||
1325 | * Build the CSS to overwrite a bootstrap color variable. |
||
1326 | * |
||
1327 | * @param $type |
||
1328 | * @param $color_code |
||
1329 | * @param $compatibility |
||
1330 | * |
||
1331 | * @return string |
||
1332 | */ |
||
1333 | public static function css_overwrite_bs5($type,$color_code,$compatibility, $hex = '' ){ |
||
1334 | global $aui_bs5; |
||
1335 | |||
1336 | $is_var = false; |
||
1337 | $is_custom = strpos($type, 'custom-') !== false ? true : false; |
||
1338 | if(!$color_code){return '';} |
||
1339 | if(strpos($color_code, 'var') !== false){ |
||
1340 | //if(!sanitize_hex_color($color_code)){ |
||
1341 | $color_code = esc_attr($color_code); |
||
1342 | $is_var = true; |
||
1343 | // $color_code = "rgba($color_code, 0.5)"; |
||
1344 | // echo '###1'.$color_code.'###';//exit; |
||
1345 | } |
||
1346 | |||
1347 | // echo '@@@'.$color_code.'==='.self::hex_to_rgb($color_code);exit; |
||
1348 | |||
1349 | if(!$color_code){return '';} |
||
1350 | |||
1351 | $rgb = self::hex_to_rgb($hex); |
||
1352 | |||
1353 | if($compatibility===true || $compatibility===1){ |
||
1354 | $compatibility = '.bsui'; |
||
1355 | }elseif(!$compatibility){ |
||
1356 | $compatibility = ''; |
||
1357 | }else{ |
||
1358 | $compatibility = esc_attr($compatibility); |
||
1359 | } |
||
1360 | |||
1361 | $prefix = $compatibility ? $compatibility . " " : ""; |
||
1362 | |||
1363 | |||
1364 | $output = ''; |
||
1365 | |||
1366 | // echo '####'.$color_code;exit; |
||
1367 | |||
1368 | $type = sanitize_html_class($type); |
||
1369 | |||
1370 | /** |
||
1371 | * c = color, b = background color, o = border-color, f = fill |
||
1372 | */ |
||
1373 | $selectors = array( |
||
1374 | ".btn-{$type}" => array( 'b', 'o' ), |
||
1375 | ".btn-{$type}.disabled" => array( 'b', 'o' ), |
||
1376 | ".btn-{$type}:disabled" => array( 'b', 'o' ), |
||
1377 | ".btn-outline-{$type}" => array( 'c', 'o' ), |
||
1378 | ".btn-outline-{$type}:hover" => array( 'b', 'o' ), |
||
1379 | ".btn-outline-{$type}:not(:disabled):not(.disabled).active" => array( 'b', 'o' ), |
||
1380 | ".btn-outline-{$type}:not(:disabled):not(.disabled):active" => array( 'b', 'o' ), |
||
1381 | ".show>.btn-outline-{$type}.dropdown-toggle" => array( 'b', 'o' ), |
||
1382 | ".badge-{$type}" => array( 'b' ), |
||
1383 | ".alert-{$type}" => array( 'b', 'o' ), |
||
1384 | ".bg-{$type}" => array( 'b', 'f' ), |
||
1385 | ".btn-link.btn-{$type}" => array( 'c' ), |
||
1386 | ".text-{$type}" => array( 'c' ), |
||
1387 | ); |
||
1388 | |||
1389 | if ( $aui_bs5 ) { |
||
1390 | unset($selectors[".alert-{$type}" ]); |
||
1391 | } |
||
1392 | |||
1393 | if ( $type == 'primary' ) { |
||
1394 | $selectors = $selectors + array( |
||
1395 | 'a' => array( 'c' ), |
||
1396 | '.btn-link' => array( 'c' ), |
||
1397 | '.dropdown-item.active' => array( 'b' ), |
||
1398 | '.custom-control-input:checked~.custom-control-label::before' => array( |
||
1399 | 'b', |
||
1400 | 'o' |
||
1401 | ), |
||
1402 | '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array( |
||
1403 | 'b', |
||
1404 | 'o' |
||
1405 | ), |
||
1406 | '.nav-pills .nav-link.active' => array( 'b' ), |
||
1407 | '.nav-pills .show>.nav-link' => array( 'b' ), |
||
1408 | '.page-link' => array( 'c' ), |
||
1409 | '.page-item.active .page-link' => array( |
||
1410 | 'b', |
||
1411 | 'o' |
||
1412 | ), |
||
1413 | '.progress-bar' => array( 'b' ), |
||
1414 | '.list-group-item.active' => array( |
||
1415 | 'b', |
||
1416 | 'o' |
||
1417 | ), |
||
1418 | '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array( 'b' ), |
||
1419 | ); |
||
1420 | } |
||
1421 | |||
1422 | |||
1423 | |||
1424 | // link |
||
1425 | if ( $type === 'primary' ) { |
||
1426 | $output .= 'html body {--bs-link-hover-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .75); --bs-link-color: var(--bs-'.esc_attr($type).'); }'; |
||
1427 | $output .= $prefix . ' .breadcrumb{--bs-breadcrumb-item-active-color: '.esc_attr($color_code).'; }'; |
||
1428 | $output .= $prefix . ' .navbar { --bs-nav-link-hover-color: '.esc_attr($color_code).'; --bs-navbar-hover-color: '.esc_attr($color_code).'; --bs-navbar-active-color: '.esc_attr($color_code).'; }'; |
||
1429 | |||
1430 | $output .= $prefix . ' a{color: var(--bs-'.esc_attr($type).');}'; |
||
1431 | $output .= $prefix . ' .text-primary{color: var(--bs-'.esc_attr($type).') !important;}'; |
||
1432 | |||
1433 | // dropdown |
||
1434 | $output .= $prefix . ' .dropdown-menu{--bs-dropdown-link-hover-color: var(--bs-'.esc_attr($type).'); --bs-dropdown-link-active-color: var(--bs-'.esc_attr($type).');}'; |
||
1435 | |||
1436 | // pagination |
||
1437 | $output .= $prefix . ' .pagination{--bs-pagination-hover-color: var(--bs-'.esc_attr($type).'); --bs-pagination-active-bg: var(--bs-'.esc_attr($type).');}'; |
||
1438 | |||
1439 | } |
||
1440 | |||
1441 | $output .= $prefix . ' .link-'.esc_attr($type).' {color: var(--bs-'.esc_attr($type).'-rgb) !important;}'; |
||
1442 | $output .= $prefix . ' .link-'.esc_attr($type).':hover {color: rgba(var(--bs-'.esc_attr($type).'-rgb), .8) !important;}'; |
||
1443 | |||
1444 | // buttons |
||
1445 | $output .= $prefix . ' .btn-'.esc_attr($type).'{'; |
||
1446 | $output .= ' |
||
1447 | --bs-btn-bg: '.esc_attr($color_code).'; |
||
1448 | --bs-btn-border-color: '.esc_attr($color_code).'; |
||
1449 | --bs-btn-hover-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9); |
||
1450 | --bs-btn-hover-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9); |
||
1451 | --bs-btn-focus-shadow-rgb: --bs-'.esc_attr($type).'-rgb; |
||
1452 | --bs-btn-active-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9); |
||
1453 | --bs-btn-active-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9); |
||
1454 | --bs-btn-active-shadow: unset; |
||
1455 | --bs-btn-disabled-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .5); |
||
1456 | --bs-btn-disabled-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .1); |
||
1457 | '; |
||
1458 | // $output .= ' |
||
1459 | // --bs-btn-color: #fff; |
||
1460 | // --bs-btn-hover-color: #fff; |
||
1461 | // --bs-btn-active-color: #fff; |
||
1462 | // --bs-btn-disabled-color: #fff; |
||
1463 | // '; |
||
1464 | $output .= '}'; |
||
1465 | |||
1466 | // buttons outline |
||
1467 | $output .= $prefix . ' .btn-outline-'.esc_attr($type).'{'; |
||
1468 | $output .= ' |
||
1469 | --bs-btn-color: '.esc_attr($color_code).'; |
||
1470 | --bs-btn-border-color: '.esc_attr($color_code).'; |
||
1471 | --bs-btn-hover-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9); |
||
1472 | --bs-btn-hover-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9); |
||
1473 | --bs-btn-focus-shadow-rgb: --bs-'.esc_attr($type).'-rgb; |
||
1474 | --bs-btn-active-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .9); |
||
1475 | --bs-btn-active-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .9); |
||
1476 | --bs-btn-active-shadow: unset; |
||
1477 | --bs-btn-disabled-bg: rgba(var(--bs-'.esc_attr($type).'-rgb), .5); |
||
1478 | --bs-btn-disabled-border-color: rgba(var(--bs-'.esc_attr($type).'-rgb), .1); |
||
1479 | '; |
||
1480 | // $output .= ' |
||
1481 | // --bs-btn-color: #fff; |
||
1482 | // --bs-btn-hover-color: #fff; |
||
1483 | // --bs-btn-active-color: #fff; |
||
1484 | // --bs-btn-disabled-color: #fff; |
||
1485 | // '; |
||
1486 | $output .= '}'; |
||
1487 | |||
1488 | |||
1489 | // button hover |
||
1490 | $output .= $prefix . ' .btn-'.esc_attr($type).':hover{'; |
||
1491 | $output .= ' |
||
1492 | box-shadow: 0 0.25rem 0.25rem 0.125rem rgb(var(--bs-'.esc_attr($type).'-rgb), .1), 0 0.375rem 0.75rem -0.125rem rgb(var(--bs-'.esc_attr($type).'-rgb) , .4); |
||
1493 | } |
||
1494 | '; |
||
1495 | |||
1496 | |||
1497 | if ( $aui_bs5 ) { |
||
1498 | // $output .= $is_var ? 'html body {--bs-'.esc_attr($type).'-rgb: '.$color_code.'; }' : 'html body {--bs-'.esc_attr($type).'-rgb: '.self::hex_to_rgb($color_code).'; }'; |
||
1499 | $output .= 'html body {--bs-'.esc_attr($type).': '.esc_attr($color_code).'; }'; |
||
1500 | $output .= 'html body {--bs-'.esc_attr($type).'-rgb: '.$rgb.'; }'; |
||
1501 | } |
||
1502 | |||
1503 | |||
1504 | if ( $is_custom ) { |
||
1505 | |||
1506 | // echo '###'.$type;exit; |
||
1507 | |||
1508 | // build rules into each type |
||
1509 | foreach($selectors as $selector => $types){ |
||
1510 | $selector = $compatibility ? $compatibility . " ".$selector : $selector; |
||
1511 | $types = array_combine($types,$types); |
||
1512 | if(isset($types['c'])){$color[] = $selector;} |
||
1513 | if(isset($types['b'])){$background[] = $selector;} |
||
1514 | if(isset($types['o'])){$border[] = $selector;} |
||
1515 | if(isset($types['f'])){$fill[] = $selector;} |
||
1516 | } |
||
1517 | |||
1518 | // // build rules into each type |
||
1519 | // foreach($important_selectors as $selector => $types){ |
||
1520 | // $selector = $compatibility ? $compatibility . " ".$selector : $selector; |
||
1521 | // $types = array_combine($types,$types); |
||
1522 | // if(isset($types['c'])){$color_i[] = $selector;} |
||
1523 | // if(isset($types['b'])){$background_i[] = $selector;} |
||
1524 | // if(isset($types['o'])){$border_i[] = $selector;} |
||
1525 | // if(isset($types['f'])){$fill_i[] = $selector;} |
||
1526 | // } |
||
1527 | |||
1528 | // add any color rules |
||
1529 | if(!empty($color)){ |
||
1530 | $output .= implode(",",$color) . "{color: $color_code;} "; |
||
1531 | } |
||
1532 | if(!empty($color_i)){ |
||
1533 | $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
||
1534 | } |
||
1535 | |||
1536 | // add any background color rules |
||
1537 | if(!empty($background)){ |
||
1538 | $output .= implode(",",$background) . "{background-color: $color_code;} "; |
||
1539 | } |
||
1540 | if(!empty($background_i)){ |
||
1541 | $output .= $aui_bs5 ? '' : implode(",",$background_i) . "{background-color: $color_code !important;} "; |
||
1542 | // $output .= implode(",",$background_i) . "{background-color: rgba(var(--bs-primary-rgb), var(--bs-bg-opacity)) !important;} "; |
||
1543 | } |
||
1544 | |||
1545 | // add any border color rules |
||
1546 | if(!empty($border)){ |
||
1547 | $output .= implode(",",$border) . "{border-color: $color_code;} "; |
||
1548 | } |
||
1549 | if(!empty($border_i)){ |
||
1550 | $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
||
1551 | } |
||
1552 | |||
1553 | // add any fill color rules |
||
1554 | if(!empty($fill)){ |
||
1555 | $output .= implode(",",$fill) . "{fill: $color_code;} "; |
||
1556 | } |
||
1557 | if(!empty($fill_i)){ |
||
1558 | $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
||
1559 | } |
||
1560 | |||
1561 | } |
||
1562 | |||
1563 | |||
1564 | |||
1565 | |||
1566 | $transition = $is_var ? 'transition: color 0.15s ease-in-out,background-color 0.15s ease-in-out,border-color 0.15s ease-in-out,box-shadow 0.15s ease-in-out,filter 0.15s ease-in-out;' : ''; |
||
1567 | // darken |
||
1568 | $darker_075 = $is_var ? $color_code.';filter:brightness(0.925)' : self::css_hex_lighten_darken($color_code,"-0.075"); |
||
1569 | $darker_10 = $is_var ? $color_code.';filter:brightness(0.9)' : self::css_hex_lighten_darken($color_code,"-0.10"); |
||
1570 | $darker_125 = $is_var ? $color_code.';filter:brightness(0.875)' : self::css_hex_lighten_darken($color_code,"-0.125"); |
||
1571 | $darker_40 = $is_var ? $color_code.';filter:brightness(0.6)' : self::css_hex_lighten_darken($color_code,"-0.4"); |
||
1572 | |||
1573 | // lighten |
||
1574 | $lighten_25 = $is_var ? $color_code.';filter:brightness(1.25)' :self::css_hex_lighten_darken($color_code,"0.25"); |
||
1575 | |||
1576 | // opacity see https://css-tricks.com/8-digit-hex-codes/ |
||
1577 | $op_25 = $color_code."40"; // 25% opacity |
||
1578 | |||
1579 | |||
1580 | // button states |
||
1581 | $output .= $is_var ? $prefix ." .btn-{$type}{{$transition }} " : ''; |
||
1582 | $output .= $prefix ." .btn-{$type}:hover, $prefix .btn-{$type}:focus, $prefix .btn-{$type}.focus{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
||
1583 | // $output .= $prefix ." .btn-{$type}:hover, $prefix .btn-{$type}:focus, $prefix .btn-{$type}.focus{background-color: #000; border-color: #000;} "; |
||
1584 | $output .= $prefix ." .btn-outline-{$type}:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-{$type}:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-{$type}.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
1585 | $output .= $prefix ." .btn-{$type}:not(:disabled):not(.disabled):active, $prefix .btn-{$type}:not(:disabled):not(.disabled).active, .show>$prefix .btn-{$type}.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
||
1586 | $output .= $prefix ." .btn-{$type}:not(:disabled):not(.disabled):active:focus, $prefix .btn-{$type}:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-{$type}.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
1587 | |||
1588 | // text |
||
1589 | // $output .= $prefix .".xxx, .text-{$type} {color: var(--bs-".esc_attr($type).");} "; |
||
1590 | |||
1591 | |||
1592 | // if ( $type == 'primary' ) { |
||
1593 | // // dropdown's |
||
1594 | // $output .= $prefix . " .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
||
1595 | // |
||
1596 | // // input states |
||
1597 | // $output .= $prefix . " .form-control:focus{border-color: " . $lighten_25 . ";box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
1598 | // |
||
1599 | // // page link |
||
1600 | // $output .= $prefix . " .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
1601 | // } |
||
1602 | |||
1603 | // alerts |
||
1604 | if ( $aui_bs5 ) { |
||
1605 | // $output .= $is_var ? '' : $prefix ." .alert-{$type} {background-color: ".$color_code."20; border-color: ".$color_code."30;color:$darker_40} "; |
||
1606 | $output .= $prefix ." .alert-{$type} {--bs-alert-bg: rgba(var(--bs-{$type}-rgb), .1 ) !important;--bs-alert-border-color: rgba(var(--bs-{$type}-rgb), .25 ) !important;--bs-alert-color: rgba(var(--bs-{$type}-rgb), 1 ) !important;} "; |
||
1607 | } |
||
1608 | |||
1609 | return $output; |
||
1610 | } |
||
1611 | |||
1612 | /** |
||
1613 | * Build the CSS to overwrite a bootstrap color variable. |
||
1614 | * |
||
1615 | * @param $type |
||
1616 | * @param $color_code |
||
1617 | * @param $compatibility |
||
1618 | * |
||
1619 | * @return string |
||
1620 | */ |
||
1621 | public static function css_overwrite($type,$color_code,$compatibility, $hex = '' ){ |
||
1622 | global $aui_bs5; |
||
1623 | |||
1624 | $is_var = false; |
||
1625 | if(!$color_code){return '';} |
||
1626 | if(strpos($color_code, 'var') !== false){ |
||
1627 | //if(!sanitize_hex_color($color_code)){ |
||
1628 | $color_code = esc_attr($color_code); |
||
1629 | $is_var = true; |
||
1630 | // $color_code = "rgba($color_code, 0.5)"; |
||
1631 | // echo '###1'.$color_code.'###';//exit; |
||
1632 | } |
||
1633 | |||
1634 | // echo '@@@'.$color_code.'==='.self::hex_to_rgb($color_code);exit; |
||
1635 | |||
1636 | if(!$color_code){return '';} |
||
1637 | |||
1638 | $rgb = self::hex_to_rgb($hex); |
||
1639 | |||
1640 | if($compatibility===true || $compatibility===1){ |
||
1641 | $compatibility = '.bsui'; |
||
1642 | }elseif(!$compatibility){ |
||
1643 | $compatibility = ''; |
||
1644 | }else{ |
||
1645 | $compatibility = esc_attr($compatibility); |
||
1646 | } |
||
1647 | |||
1648 | |||
1649 | |||
1650 | // echo '####'.$color_code;exit; |
||
1651 | |||
1652 | $type = sanitize_html_class($type); |
||
1653 | |||
1654 | /** |
||
1655 | * c = color, b = background color, o = border-color, f = fill |
||
1656 | */ |
||
1657 | $selectors = array( |
||
1658 | ".btn-{$type}" => array( 'b', 'o' ), |
||
1659 | ".btn-{$type}.disabled" => array( 'b', 'o' ), |
||
1660 | ".btn-{$type}:disabled" => array( 'b', 'o' ), |
||
1661 | ".btn-outline-{$type}" => array( 'c', 'o' ), |
||
1662 | ".btn-outline-{$type}:hover" => array( 'b', 'o' ), |
||
1663 | ".btn-outline-{$type}:not(:disabled):not(.disabled).active" => array( 'b', 'o' ), |
||
1664 | ".btn-outline-{$type}:not(:disabled):not(.disabled):active" => array( 'b', 'o' ), |
||
1665 | ".show>.btn-outline-{$type}.dropdown-toggle" => array( 'b', 'o' ), |
||
1666 | ".badge-{$type}" => array( 'b' ), |
||
1667 | ".alert-{$type}" => array( 'b', 'o' ), |
||
1668 | ".bg-{$type}" => array( 'b', 'f' ), |
||
1669 | ".btn-link.btn-{$type}" => array( 'c' ), |
||
1670 | ); |
||
1671 | |||
1672 | if ( $aui_bs5 ) { |
||
1673 | unset($selectors[".alert-{$type}" ]); |
||
1674 | } |
||
1675 | |||
1676 | if ( $type == 'primary' ) { |
||
1677 | $selectors = $selectors + array( |
||
1678 | 'a' => array( 'c' ), |
||
1679 | '.btn-link' => array( 'c' ), |
||
1680 | '.dropdown-item.active' => array( 'b' ), |
||
1681 | '.custom-control-input:checked~.custom-control-label::before' => array( |
||
1682 | 'b', |
||
1683 | 'o' |
||
1684 | ), |
||
1685 | '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array( |
||
1686 | 'b', |
||
1687 | 'o' |
||
1688 | ), |
||
1689 | '.nav-pills .nav-link.active' => array( 'b' ), |
||
1690 | '.nav-pills .show>.nav-link' => array( 'b' ), |
||
1691 | '.page-link' => array( 'c' ), |
||
1692 | '.page-item.active .page-link' => array( |
||
1693 | 'b', |
||
1694 | 'o' |
||
1695 | ), |
||
1696 | '.progress-bar' => array( 'b' ), |
||
1697 | '.list-group-item.active' => array( |
||
1698 | 'b', |
||
1699 | 'o' |
||
1700 | ), |
||
1701 | '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array( 'b' ), |
||
1702 | // '.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules... |
||
1703 | // '.custom-range::-moz-range-thumb' => array('b'), |
||
1704 | // '.custom-range::-ms-thumb' => array('b'), |
||
1705 | ); |
||
1706 | } |
||
1707 | |||
1708 | $important_selectors = array( |
||
1709 | ".bg-{$type}" => array('b','f'), |
||
1710 | ".border-{$type}" => array('o'), |
||
1711 | ".text-{$type}" => array('c'), |
||
1712 | ); |
||
1713 | |||
1714 | $color = array(); |
||
1715 | $color_i = array(); |
||
1716 | $background = array(); |
||
1717 | $background_i = array(); |
||
1718 | $border = array(); |
||
1719 | $border_i = array(); |
||
1720 | $fill = array(); |
||
1721 | $fill_i = array(); |
||
1722 | |||
1723 | $output = ''; |
||
1724 | |||
1725 | if ( $aui_bs5 ) { |
||
1726 | // $output .= $is_var ? 'html body {--bs-'.esc_attr($type).'-rgb: '.$color_code.'; }' : 'html body {--bs-'.esc_attr($type).'-rgb: '.self::hex_to_rgb($color_code).'; }'; |
||
1727 | $output .= 'html body {--bs-'.esc_attr($type).'-rgb: '.$rgb.'; }'; |
||
1728 | } |
||
1729 | |||
1730 | // build rules into each type |
||
1731 | foreach($selectors as $selector => $types){ |
||
1732 | $selector = $compatibility ? $compatibility . " ".$selector : $selector; |
||
1733 | $types = array_combine($types,$types); |
||
1734 | if(isset($types['c'])){$color[] = $selector;} |
||
1735 | if(isset($types['b'])){$background[] = $selector;} |
||
1736 | if(isset($types['o'])){$border[] = $selector;} |
||
1737 | if(isset($types['f'])){$fill[] = $selector;} |
||
1738 | } |
||
1739 | |||
1740 | // build rules into each type |
||
1741 | foreach($important_selectors as $selector => $types){ |
||
1742 | $selector = $compatibility ? $compatibility . " ".$selector : $selector; |
||
1743 | $types = array_combine($types,$types); |
||
1744 | if(isset($types['c'])){$color_i[] = $selector;} |
||
1745 | if(isset($types['b'])){$background_i[] = $selector;} |
||
1746 | if(isset($types['o'])){$border_i[] = $selector;} |
||
1747 | if(isset($types['f'])){$fill_i[] = $selector;} |
||
1748 | } |
||
1749 | |||
1750 | // add any color rules |
||
1751 | if(!empty($color)){ |
||
1752 | $output .= implode(",",$color) . "{color: $color_code;} "; |
||
1753 | } |
||
1754 | if(!empty($color_i)){ |
||
1755 | $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
||
1756 | } |
||
1757 | |||
1758 | // add any background color rules |
||
1759 | if(!empty($background)){ |
||
1760 | $output .= implode(",",$background) . "{background-color: $color_code;} "; |
||
1761 | } |
||
1762 | if(!empty($background_i)){ |
||
1763 | $output .= $aui_bs5 ? '' : implode(",",$background_i) . "{background-color: $color_code !important;} "; |
||
1764 | // $output .= implode(",",$background_i) . "{background-color: rgba(var(--bs-primary-rgb), var(--bs-bg-opacity)) !important;} "; |
||
1765 | } |
||
1766 | |||
1767 | // add any border color rules |
||
1768 | if(!empty($border)){ |
||
1769 | $output .= implode(",",$border) . "{border-color: $color_code;} "; |
||
1770 | } |
||
1771 | if(!empty($border_i)){ |
||
1772 | $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
||
1773 | } |
||
1774 | |||
1775 | // add any fill color rules |
||
1776 | if(!empty($fill)){ |
||
1777 | $output .= implode(",",$fill) . "{fill: $color_code;} "; |
||
1778 | } |
||
1779 | if(!empty($fill_i)){ |
||
1780 | $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
||
1781 | } |
||
1782 | |||
1783 | |||
1784 | $prefix = $compatibility ? $compatibility . " " : ""; |
||
1785 | |||
1786 | $transition = $is_var ? 'transition: color 0.15s ease-in-out,background-color 0.15s ease-in-out,border-color 0.15s ease-in-out,box-shadow 0.15s ease-in-out,filter 0.15s ease-in-out;' : ''; |
||
1787 | // darken |
||
1788 | $darker_075 = $is_var ? $color_code.';filter:brightness(0.925)' : self::css_hex_lighten_darken($color_code,"-0.075"); |
||
1789 | $darker_10 = $is_var ? $color_code.';filter:brightness(0.9)' : self::css_hex_lighten_darken($color_code,"-0.10"); |
||
1790 | $darker_125 = $is_var ? $color_code.';filter:brightness(0.875)' : self::css_hex_lighten_darken($color_code,"-0.125"); |
||
1791 | $darker_40 = $is_var ? $color_code.';filter:brightness(0.6)' : self::css_hex_lighten_darken($color_code,"-0.4"); |
||
1792 | |||
1793 | // lighten |
||
1794 | $lighten_25 = $is_var ? $color_code.';filter:brightness(1.25)' :self::css_hex_lighten_darken($color_code,"0.25"); |
||
1795 | |||
1796 | // opacity see https://css-tricks.com/8-digit-hex-codes/ |
||
1797 | $op_25 = $color_code."40"; // 25% opacity |
||
1798 | |||
1799 | |||
1800 | // button states |
||
1801 | $output .= $is_var ? $prefix ." .btn-{$type}{{$transition }} " : ''; |
||
1802 | $output .= $prefix ." .btn-{$type}:hover, $prefix .btn-{$type}:focus, $prefix .btn-{$type}.focus{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
||
1803 | // $output .= $prefix ." .btn-{$type}:hover, $prefix .btn-{$type}:focus, $prefix .btn-{$type}.focus{background-color: #000; border-color: #000;} "; |
||
1804 | $output .= $prefix ." .btn-outline-{$type}:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-{$type}:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-{$type}.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
1805 | $output .= $prefix ." .btn-{$type}:not(:disabled):not(.disabled):active, $prefix .btn-{$type}:not(:disabled):not(.disabled).active, .show>$prefix .btn-{$type}.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
||
1806 | $output .= $prefix ." .btn-{$type}:not(:disabled):not(.disabled):active:focus, $prefix .btn-{$type}:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-{$type}.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
1807 | |||
1808 | if ( $type == 'primary' ) { |
||
1809 | // dropdown's |
||
1810 | $output .= $prefix . " .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
||
1811 | |||
1812 | // input states |
||
1813 | $output .= $prefix . " .form-control:focus{border-color: " . $lighten_25 . ";box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
1814 | |||
1815 | // page link |
||
1816 | $output .= $prefix . " .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
1817 | } |
||
1818 | |||
1819 | // alerts |
||
1820 | if ( $aui_bs5 ) { |
||
1821 | // $output .= $is_var ? '' : $prefix ." .alert-{$type} {background-color: ".$color_code."20; border-color: ".$color_code."30;color:$darker_40} "; |
||
1822 | $output .= $prefix ." .alert-{$type} {--bs-alert-bg: rgba(var(--bs-{$type}-rgb), .1 ) !important;--bs-alert-border-color: rgba(var(--bs-{$type}-rgb), .25 ) !important;--bs-alert-color: rgba(var(--bs-{$type}-rgb), 1 ) !important;} "; |
||
1823 | } |
||
1824 | |||
1825 | return $output; |
||
1826 | } |
||
1827 | |||
1828 | /** |
||
1829 | * |
||
1830 | * @deprecated 0.1.76 Use css_overwrite() |
||
1831 | * |
||
1832 | * @param $color_code |
||
1833 | * @param $compatibility |
||
1834 | * @param $use_variable |
||
1835 | * |
||
1836 | * @return string |
||
1837 | */ |
||
1838 | public static function css_primary($color_code,$compatibility, $use_variable = false){ |
||
1839 | |||
1840 | if(!$use_variable){ |
||
1841 | $color_code = sanitize_hex_color($color_code); |
||
1842 | if(!$color_code){return '';} |
||
1843 | } |
||
1844 | |||
1845 | /** |
||
1846 | * c = color, b = background color, o = border-color, f = fill |
||
1847 | */ |
||
1848 | $selectors = array( |
||
1849 | 'a' => array('c'), |
||
1850 | '.btn-primary' => array('b','o'), |
||
1851 | '.btn-primary.disabled' => array('b','o'), |
||
1852 | '.btn-primary:disabled' => array('b','o'), |
||
1853 | '.btn-outline-primary' => array('c','o'), |
||
1854 | '.btn-outline-primary:hover' => array('b','o'), |
||
1855 | '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'), |
||
1856 | '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'), |
||
1857 | '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'), |
||
1858 | '.btn-link' => array('c'), |
||
1859 | '.dropdown-item.active' => array('b'), |
||
1860 | '.custom-control-input:checked~.custom-control-label::before' => array('b','o'), |
||
1861 | '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'), |
||
1862 | // '.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules... |
||
1863 | // '.custom-range::-moz-range-thumb' => array('b'), |
||
1864 | // '.custom-range::-ms-thumb' => array('b'), |
||
1865 | '.nav-pills .nav-link.active' => array('b'), |
||
1866 | '.nav-pills .show>.nav-link' => array('b'), |
||
1867 | '.page-link' => array('c'), |
||
1868 | '.page-item.active .page-link' => array('b','o'), |
||
1869 | '.badge-primary' => array('b'), |
||
1870 | '.alert-primary' => array('b','o'), |
||
1871 | '.progress-bar' => array('b'), |
||
1872 | '.list-group-item.active' => array('b','o'), |
||
1873 | '.bg-primary' => array('b','f'), |
||
1874 | '.btn-link.btn-primary' => array('c'), |
||
1875 | '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'), |
||
1876 | ); |
||
1877 | |||
1878 | $important_selectors = array( |
||
1879 | '.bg-primary' => array('b','f'), |
||
1880 | '.border-primary' => array('o'), |
||
1881 | '.text-primary' => array('c'), |
||
1882 | ); |
||
1883 | |||
1884 | $color = array(); |
||
1885 | $color_i = array(); |
||
1886 | $background = array(); |
||
1887 | $background_i = array(); |
||
1888 | $border = array(); |
||
1889 | $border_i = array(); |
||
1890 | $fill = array(); |
||
1891 | $fill_i = array(); |
||
1892 | |||
1893 | $output = ''; |
||
1894 | |||
1895 | // build rules into each type |
||
1896 | foreach($selectors as $selector => $types){ |
||
1897 | $selector = $compatibility ? ".bsui ".$selector : $selector; |
||
1898 | $types = array_combine($types,$types); |
||
1899 | if(isset($types['c'])){$color[] = $selector;} |
||
1900 | if(isset($types['b'])){$background[] = $selector;} |
||
1901 | if(isset($types['o'])){$border[] = $selector;} |
||
1902 | if(isset($types['f'])){$fill[] = $selector;} |
||
1903 | } |
||
1904 | |||
1905 | // build rules into each type |
||
1906 | foreach($important_selectors as $selector => $types){ |
||
1907 | $selector = $compatibility ? ".bsui ".$selector : $selector; |
||
1908 | $types = array_combine($types,$types); |
||
1909 | if(isset($types['c'])){$color_i[] = $selector;} |
||
1910 | if(isset($types['b'])){$background_i[] = $selector;} |
||
1911 | if(isset($types['o'])){$border_i[] = $selector;} |
||
1912 | if(isset($types['f'])){$fill_i[] = $selector;} |
||
1913 | } |
||
1914 | |||
1915 | // add any color rules |
||
1916 | if(!empty($color)){ |
||
1917 | $output .= implode(",",$color) . "{color: $color_code;} "; |
||
1918 | } |
||
1919 | if(!empty($color_i)){ |
||
1920 | $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
||
1921 | } |
||
1922 | |||
1923 | // add any background color rules |
||
1924 | if(!empty($background)){ |
||
1925 | $output .= implode(",",$background) . "{background-color: $color_code;} "; |
||
1926 | } |
||
1927 | if(!empty($background_i)){ |
||
1928 | $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
||
1929 | } |
||
1930 | |||
1931 | // add any border color rules |
||
1932 | if(!empty($border)){ |
||
1933 | $output .= implode(",",$border) . "{border-color: $color_code;} "; |
||
1934 | } |
||
1935 | if(!empty($border_i)){ |
||
1936 | $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
||
1937 | } |
||
1938 | |||
1939 | // add any fill color rules |
||
1940 | if(!empty($fill)){ |
||
1941 | $output .= implode(",",$fill) . "{fill: $color_code;} "; |
||
1942 | } |
||
1943 | if(!empty($fill_i)){ |
||
1944 | $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
||
1945 | } |
||
1946 | |||
1947 | |||
1948 | $prefix = $compatibility ? ".bsui " : ""; |
||
1949 | |||
1950 | // darken |
||
1951 | $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
||
1952 | $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
||
1953 | $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
||
1954 | |||
1955 | // lighten |
||
1956 | $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
||
1957 | |||
1958 | // opacity see https://css-tricks.com/8-digit-hex-codes/ |
||
1959 | $op_25 = $color_code."40"; // 25% opacity |
||
1960 | |||
1961 | |||
1962 | // button states |
||
1963 | $output .= $prefix ." .btn-primary:hover, $prefix .btn-primary:focus, $prefix .btn-primary.focus{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
||
1964 | $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
1965 | $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
||
1966 | $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
1967 | |||
1968 | |||
1969 | // dropdown's |
||
1970 | $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
||
1971 | |||
1972 | |||
1973 | // input states |
||
1974 | $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
1975 | |||
1976 | // page link |
||
1977 | $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
1978 | |||
1979 | return $output; |
||
1980 | } |
||
1981 | |||
1982 | /** |
||
1983 | * |
||
1984 | * @deprecated 0.1.76 Use css_overwrite() |
||
1985 | * |
||
1986 | * @param $color_code |
||
1987 | * @param $compatibility |
||
1988 | * |
||
1989 | * @return string |
||
1990 | */ |
||
1991 | public static function css_secondary($color_code,$compatibility){; |
||
1992 | $color_code = sanitize_hex_color($color_code); |
||
1993 | if(!$color_code){return '';} |
||
1994 | /** |
||
1995 | * c = color, b = background color, o = border-color, f = fill |
||
1996 | */ |
||
1997 | $selectors = array( |
||
1998 | '.btn-secondary' => array('b','o'), |
||
1999 | '.btn-secondary.disabled' => array('b','o'), |
||
2000 | '.btn-secondary:disabled' => array('b','o'), |
||
2001 | '.btn-outline-secondary' => array('c','o'), |
||
2002 | '.btn-outline-secondary:hover' => array('b','o'), |
||
2003 | '.btn-outline-secondary.disabled' => array('c'), |
||
2004 | '.btn-outline-secondary:disabled' => array('c'), |
||
2005 | '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'), |
||
2006 | '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'), |
||
2007 | '.btn-outline-secondary.dropdown-toggle' => array('b','o'), |
||
2008 | '.badge-secondary' => array('b'), |
||
2009 | '.alert-secondary' => array('b','o'), |
||
2010 | '.btn-link.btn-secondary' => array('c'), |
||
2011 | ); |
||
2012 | |||
2013 | $important_selectors = array( |
||
2014 | '.bg-secondary' => array('b','f'), |
||
2015 | '.border-secondary' => array('o'), |
||
2016 | '.text-secondary' => array('c'), |
||
2017 | ); |
||
2018 | |||
2019 | $color = array(); |
||
2020 | $color_i = array(); |
||
2021 | $background = array(); |
||
2022 | $background_i = array(); |
||
2023 | $border = array(); |
||
2024 | $border_i = array(); |
||
2025 | $fill = array(); |
||
2026 | $fill_i = array(); |
||
2027 | |||
2028 | $output = ''; |
||
2029 | |||
2030 | // build rules into each type |
||
2031 | foreach($selectors as $selector => $types){ |
||
2032 | $selector = $compatibility ? ".bsui ".$selector : $selector; |
||
2033 | $types = array_combine($types,$types); |
||
2034 | if(isset($types['c'])){$color[] = $selector;} |
||
2035 | if(isset($types['b'])){$background[] = $selector;} |
||
2036 | if(isset($types['o'])){$border[] = $selector;} |
||
2037 | if(isset($types['f'])){$fill[] = $selector;} |
||
2038 | } |
||
2039 | |||
2040 | // build rules into each type |
||
2041 | foreach($important_selectors as $selector => $types){ |
||
2042 | $selector = $compatibility ? ".bsui ".$selector : $selector; |
||
2043 | $types = array_combine($types,$types); |
||
2044 | if(isset($types['c'])){$color_i[] = $selector;} |
||
2045 | if(isset($types['b'])){$background_i[] = $selector;} |
||
2046 | if(isset($types['o'])){$border_i[] = $selector;} |
||
2047 | if(isset($types['f'])){$fill_i[] = $selector;} |
||
2048 | } |
||
2049 | |||
2050 | // add any color rules |
||
2051 | if(!empty($color)){ |
||
2052 | $output .= implode(",",$color) . "{color: $color_code;} "; |
||
2053 | } |
||
2054 | if(!empty($color_i)){ |
||
2055 | $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
||
2056 | } |
||
2057 | |||
2058 | // add any background color rules |
||
2059 | if(!empty($background)){ |
||
2060 | $output .= implode(",",$background) . "{background-color: $color_code;} "; |
||
2061 | } |
||
2062 | if(!empty($background_i)){ |
||
2063 | $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
||
2064 | } |
||
2065 | |||
2066 | // add any border color rules |
||
2067 | if(!empty($border)){ |
||
2068 | $output .= implode(",",$border) . "{border-color: $color_code;} "; |
||
2069 | } |
||
2070 | if(!empty($border_i)){ |
||
2071 | $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
||
2072 | } |
||
2073 | |||
2074 | // add any fill color rules |
||
2075 | if(!empty($fill)){ |
||
2076 | $output .= implode(",",$fill) . "{fill: $color_code;} "; |
||
2077 | } |
||
2078 | if(!empty($fill_i)){ |
||
2079 | $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
||
2080 | } |
||
2081 | |||
2082 | |||
2083 | $prefix = $compatibility ? ".bsui " : ""; |
||
2084 | |||
2085 | // darken |
||
2086 | $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
||
2087 | $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
||
2088 | $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
||
2089 | |||
2090 | // lighten |
||
2091 | $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
||
2092 | |||
2093 | // opacity see https://css-tricks.com/8-digit-hex-codes/ |
||
2094 | $op_25 = $color_code."40"; // 25% opacity |
||
2095 | |||
2096 | |||
2097 | // button states |
||
2098 | $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
||
2099 | $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
2100 | $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
||
2101 | $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
2102 | |||
2103 | |||
2104 | return $output; |
||
2105 | } |
||
2106 | |||
2107 | /** |
||
2108 | * Increases or decreases the brightness of a color by a percentage of the current brightness. |
||
2109 | * |
||
2110 | * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF` |
||
2111 | * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker. |
||
2112 | * |
||
2113 | * @return string |
||
2114 | */ |
||
2115 | public static function css_hex_lighten_darken($hexCode, $adjustPercent) { |
||
2116 | $hexCode = ltrim($hexCode, '#'); |
||
2117 | |||
2118 | if ( strpos( $hexCode, 'rgba(' ) !== false || strpos( $hexCode, 'rgb(' ) !== false ) { |
||
2119 | return $hexCode; |
||
2120 | } |
||
2121 | |||
2122 | if (strlen($hexCode) == 3) { |
||
2123 | $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2]; |
||
2124 | } |
||
2125 | |||
2126 | $hexCode = array_map('hexdec', str_split($hexCode, 2)); |
||
2127 | |||
2128 | foreach ($hexCode as & $color) { |
||
2129 | $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color; |
||
2130 | $adjustAmount = ceil($adjustableLimit * $adjustPercent); |
||
2131 | |||
2132 | $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT); |
||
2133 | } |
||
2134 | |||
2135 | return '#' . implode($hexCode); |
||
2136 | } |
||
2137 | |||
2138 | /** |
||
2139 | * Check if we should display examples. |
||
2140 | */ |
||
2141 | public function maybe_show_examples(){ |
||
2142 | if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
||
2143 | echo "<head>"; |
||
2144 | wp_head(); |
||
2145 | echo "</head>"; |
||
2146 | echo "<body>"; |
||
2147 | echo $this->get_examples(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
||
2148 | echo "</body>"; |
||
2149 | exit; |
||
2150 | } |
||
2151 | } |
||
2152 | |||
2153 | /** |
||
2154 | * Get developer examples. |
||
2155 | * |
||
2156 | * @return string |
||
2157 | */ |
||
2158 | public function get_examples(){ |
||
2159 | $output = ''; |
||
2160 | |||
2161 | |||
2162 | // open form |
||
2163 | $output .= "<form class='p-5 m-5 border rounded'>"; |
||
2164 | |||
2165 | // input example |
||
2166 | $output .= aui()->input(array( |
||
2167 | 'type' => 'text', |
||
2168 | 'id' => 'text-example', |
||
2169 | 'name' => 'text-example', |
||
2170 | 'placeholder' => 'text placeholder', |
||
2171 | 'title' => 'Text input example', |
||
2172 | 'value' => '', |
||
2173 | 'required' => false, |
||
2174 | 'help_text' => 'help text', |
||
2175 | 'label' => 'Text input example label' |
||
2176 | )); |
||
2177 | |||
2178 | // input example |
||
2179 | $output .= aui()->input(array( |
||
2180 | 'type' => 'url', |
||
2181 | 'id' => 'text-example2', |
||
2182 | 'name' => 'text-example', |
||
2183 | 'placeholder' => 'url placeholder', |
||
2184 | 'title' => 'Text input example', |
||
2185 | 'value' => '', |
||
2186 | 'required' => false, |
||
2187 | 'help_text' => 'help text', |
||
2188 | 'label' => 'Text input example label' |
||
2189 | )); |
||
2190 | |||
2191 | // checkbox example |
||
2192 | $output .= aui()->input(array( |
||
2193 | 'type' => 'checkbox', |
||
2194 | 'id' => 'checkbox-example', |
||
2195 | 'name' => 'checkbox-example', |
||
2196 | 'placeholder' => 'checkbox-example', |
||
2197 | 'title' => 'Checkbox example', |
||
2198 | 'value' => '1', |
||
2199 | 'checked' => true, |
||
2200 | 'required' => false, |
||
2201 | 'help_text' => 'help text', |
||
2202 | 'label' => 'Checkbox checked' |
||
2203 | )); |
||
2204 | |||
2205 | // checkbox example |
||
2206 | $output .= aui()->input(array( |
||
2207 | 'type' => 'checkbox', |
||
2208 | 'id' => 'checkbox-example2', |
||
2209 | 'name' => 'checkbox-example2', |
||
2210 | 'placeholder' => 'checkbox-example', |
||
2211 | 'title' => 'Checkbox example', |
||
2212 | 'value' => '1', |
||
2213 | 'checked' => false, |
||
2214 | 'required' => false, |
||
2215 | 'help_text' => 'help text', |
||
2216 | 'label' => 'Checkbox un-checked' |
||
2217 | )); |
||
2218 | |||
2219 | // switch example |
||
2220 | $output .= aui()->input(array( |
||
2221 | 'type' => 'checkbox', |
||
2222 | 'id' => 'switch-example', |
||
2223 | 'name' => 'switch-example', |
||
2224 | 'placeholder' => 'checkbox-example', |
||
2225 | 'title' => 'Switch example', |
||
2226 | 'value' => '1', |
||
2227 | 'checked' => true, |
||
2228 | 'switch' => true, |
||
2229 | 'required' => false, |
||
2230 | 'help_text' => 'help text', |
||
2231 | 'label' => 'Switch on' |
||
2232 | )); |
||
2233 | |||
2234 | // switch example |
||
2235 | $output .= aui()->input(array( |
||
2236 | 'type' => 'checkbox', |
||
2237 | 'id' => 'switch-example2', |
||
2238 | 'name' => 'switch-example2', |
||
2239 | 'placeholder' => 'checkbox-example', |
||
2240 | 'title' => 'Switch example', |
||
2241 | 'value' => '1', |
||
2242 | 'checked' => false, |
||
2243 | 'switch' => true, |
||
2244 | 'required' => false, |
||
2245 | 'help_text' => 'help text', |
||
2246 | 'label' => 'Switch off' |
||
2247 | )); |
||
2248 | |||
2249 | // close form |
||
2250 | $output .= "</form>"; |
||
2251 | |||
2252 | return $output; |
||
2253 | } |
||
2254 | |||
2255 | /** |
||
2256 | * Calendar params. |
||
2257 | * |
||
2258 | * @since 0.1.44 |
||
2259 | * |
||
2260 | * @return array Calendar params. |
||
2261 | */ |
||
2262 | public static function calendar_params() { |
||
2263 | $params = array( |
||
2264 | 'month_long_1' => __( 'January', 'ayecode-connect' ), |
||
2265 | 'month_long_2' => __( 'February', 'ayecode-connect' ), |
||
2266 | 'month_long_3' => __( 'March', 'ayecode-connect' ), |
||
2267 | 'month_long_4' => __( 'April', 'ayecode-connect' ), |
||
2268 | 'month_long_5' => __( 'May', 'ayecode-connect' ), |
||
2269 | 'month_long_6' => __( 'June', 'ayecode-connect' ), |
||
2270 | 'month_long_7' => __( 'July', 'ayecode-connect' ), |
||
2271 | 'month_long_8' => __( 'August', 'ayecode-connect' ), |
||
2272 | 'month_long_9' => __( 'September', 'ayecode-connect' ), |
||
2273 | 'month_long_10' => __( 'October', 'ayecode-connect' ), |
||
2274 | 'month_long_11' => __( 'November', 'ayecode-connect' ), |
||
2275 | 'month_long_12' => __( 'December', 'ayecode-connect' ), |
||
2276 | 'month_s_1' => _x( 'Jan', 'January abbreviation', 'ayecode-connect' ), |
||
2277 | 'month_s_2' => _x( 'Feb', 'February abbreviation', 'ayecode-connect' ), |
||
2278 | 'month_s_3' => _x( 'Mar', 'March abbreviation', 'ayecode-connect' ), |
||
2279 | 'month_s_4' => _x( 'Apr', 'April abbreviation', 'ayecode-connect' ), |
||
2280 | 'month_s_5' => _x( 'May', 'May abbreviation', 'ayecode-connect' ), |
||
2281 | 'month_s_6' => _x( 'Jun', 'June abbreviation', 'ayecode-connect' ), |
||
2282 | 'month_s_7' => _x( 'Jul', 'July abbreviation', 'ayecode-connect' ), |
||
2283 | 'month_s_8' => _x( 'Aug', 'August abbreviation', 'ayecode-connect' ), |
||
2284 | 'month_s_9' => _x( 'Sep', 'September abbreviation', 'ayecode-connect' ), |
||
2285 | 'month_s_10' => _x( 'Oct', 'October abbreviation', 'ayecode-connect' ), |
||
2286 | 'month_s_11' => _x( 'Nov', 'November abbreviation', 'ayecode-connect' ), |
||
2287 | 'month_s_12' => _x( 'Dec', 'December abbreviation', 'ayecode-connect' ), |
||
2288 | 'day_s1_1' => _x( 'S', 'Sunday initial', 'ayecode-connect' ), |
||
2289 | 'day_s1_2' => _x( 'M', 'Monday initial', 'ayecode-connect' ), |
||
2290 | 'day_s1_3' => _x( 'T', 'Tuesday initial', 'ayecode-connect' ), |
||
2291 | 'day_s1_4' => _x( 'W', 'Wednesday initial', 'ayecode-connect' ), |
||
2292 | 'day_s1_5' => _x( 'T', 'Friday initial', 'ayecode-connect' ), |
||
2293 | 'day_s1_6' => _x( 'F', 'Thursday initial', 'ayecode-connect' ), |
||
2294 | 'day_s1_7' => _x( 'S', 'Saturday initial', 'ayecode-connect' ), |
||
2295 | 'day_s2_1' => __( 'Su', 'ayecode-connect' ), |
||
2296 | 'day_s2_2' => __( 'Mo', 'ayecode-connect' ), |
||
2297 | 'day_s2_3' => __( 'Tu', 'ayecode-connect' ), |
||
2298 | 'day_s2_4' => __( 'We', 'ayecode-connect' ), |
||
2299 | 'day_s2_5' => __( 'Th', 'ayecode-connect' ), |
||
2300 | 'day_s2_6' => __( 'Fr', 'ayecode-connect' ), |
||
2301 | 'day_s2_7' => __( 'Sa', 'ayecode-connect' ), |
||
2302 | 'day_s3_1' => __( 'Sun', 'ayecode-connect' ), |
||
2303 | 'day_s3_2' => __( 'Mon', 'ayecode-connect' ), |
||
2304 | 'day_s3_3' => __( 'Tue', 'ayecode-connect' ), |
||
2305 | 'day_s3_4' => __( 'Wed', 'ayecode-connect' ), |
||
2306 | 'day_s3_5' => __( 'Thu', 'ayecode-connect' ), |
||
2307 | 'day_s3_6' => __( 'Fri', 'ayecode-connect' ), |
||
2308 | 'day_s3_7' => __( 'Sat', 'ayecode-connect' ), |
||
2309 | 'day_s5_1' => __( 'Sunday', 'ayecode-connect' ), |
||
2310 | 'day_s5_2' => __( 'Monday', 'ayecode-connect' ), |
||
2311 | 'day_s5_3' => __( 'Tuesday', 'ayecode-connect' ), |
||
2312 | 'day_s5_4' => __( 'Wednesday', 'ayecode-connect' ), |
||
2313 | 'day_s5_5' => __( 'Thursday', 'ayecode-connect' ), |
||
2314 | 'day_s5_6' => __( 'Friday', 'ayecode-connect' ), |
||
2315 | 'day_s5_7' => __( 'Saturday', 'ayecode-connect' ), |
||
2316 | 'am_lower' => __( 'am', 'ayecode-connect' ), |
||
2317 | 'pm_lower' => __( 'pm', 'ayecode-connect' ), |
||
2318 | 'am_upper' => __( 'AM', 'ayecode-connect' ), |
||
2319 | 'pm_upper' => __( 'PM', 'ayecode-connect' ), |
||
2320 | 'firstDayOfWeek' => (int) get_option( 'start_of_week' ), |
||
2321 | 'time_24hr' => false, |
||
2322 | 'year' => __( 'Year', 'ayecode-connect' ), |
||
2323 | 'hour' => __( 'Hour', 'ayecode-connect' ), |
||
2324 | 'minute' => __( 'Minute', 'ayecode-connect' ), |
||
2325 | 'weekAbbreviation' => __( 'Wk', 'ayecode-connect' ), |
||
2326 | 'rangeSeparator' => __( ' to ', 'ayecode-connect' ), |
||
2327 | 'scrollTitle' => __( 'Scroll to increment', 'ayecode-connect' ), |
||
2328 | 'toggleTitle' => __( 'Click to toggle', 'ayecode-connect' ) |
||
2329 | ); |
||
2330 | |||
2331 | return apply_filters( 'ayecode_ui_calendar_params', $params ); |
||
2332 | } |
||
2333 | |||
2334 | /** |
||
2335 | * Flatpickr calendar localize. |
||
2336 | * |
||
2337 | * @since 0.1.44 |
||
2338 | * |
||
2339 | * @return string Calendar locale. |
||
2340 | */ |
||
2341 | public static function flatpickr_locale() { |
||
2342 | $params = self::calendar_params(); |
||
2343 | |||
2344 | if ( is_string( $params ) ) { |
||
2345 | $params = html_entity_decode( $params, ENT_QUOTES, 'UTF-8' ); |
||
2346 | } else { |
||
2347 | foreach ( (array) $params as $key => $value ) { |
||
2348 | if ( ! is_scalar( $value ) ) { |
||
2349 | continue; |
||
2350 | } |
||
2351 | |||
2352 | $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
||
2353 | } |
||
2354 | } |
||
2355 | |||
2356 | $day_s3 = array(); |
||
2357 | $day_s5 = array(); |
||
2358 | |||
2359 | for ( $i = 1; $i <= 7; $i ++ ) { |
||
2360 | $day_s3[] = addslashes( $params[ 'day_s3_' . $i ] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
||
2361 | $day_s5[] = addslashes( $params[ 'day_s3_' . $i ] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
||
2362 | } |
||
2363 | |||
2364 | $month_s = array(); |
||
2365 | $month_long = array(); |
||
2366 | |||
2367 | for ( $i = 1; $i <= 12; $i ++ ) { |
||
2368 | $month_s[] = addslashes( $params[ 'month_s_' . $i ] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
||
2369 | $month_long[] = addslashes( $params[ 'month_long_' . $i ] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
||
2370 | } |
||
2371 | |||
2372 | ob_start(); |
||
2373 | if ( 0 ) { ?><script><?php } ?> |
||
2374 | { |
||
2375 | weekdays: { |
||
2376 | shorthand: ['<?php echo implode( "','", $day_s3 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>'], |
||
2377 | longhand: ['<?php echo implode( "','", $day_s5 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>'], |
||
2378 | }, |
||
2379 | months: { |
||
2380 | shorthand: ['<?php echo implode( "','", $month_s ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>'], |
||
2381 | longhand: ['<?php echo implode( "','", $month_long ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>'], |
||
2382 | }, |
||
2383 | daysInMonth: [31,28,31,30,31,30,31,31,30,31,30,31], |
||
2384 | firstDayOfWeek: <?php echo (int) $params[ 'firstDayOfWeek' ]; ?>, |
||
2385 | ordinal: function (nth) { |
||
2386 | var s = nth % 100; |
||
2387 | if (s > 3 && s < 21) |
||
2388 | return "th"; |
||
2389 | switch (s % 10) { |
||
2390 | case 1: |
||
2391 | return "st"; |
||
2392 | case 2: |
||
2393 | return "nd"; |
||
2394 | case 3: |
||
2395 | return "rd"; |
||
2396 | default: |
||
2397 | return "th"; |
||
2398 | } |
||
2399 | }, |
||
2400 | rangeSeparator: '<?php echo esc_attr( $params[ 'rangeSeparator' ] ); ?>', |
||
2401 | weekAbbreviation: '<?php echo esc_attr( $params[ 'weekAbbreviation' ] ); ?>', |
||
2402 | scrollTitle: '<?php echo esc_attr( $params[ 'scrollTitle' ] ); ?>', |
||
2403 | toggleTitle: '<?php echo esc_attr( $params[ 'toggleTitle' ] ); ?>', |
||
2404 | amPM: ['<?php echo esc_attr( $params[ 'am_upper' ] ); ?>','<?php echo esc_attr( $params[ 'pm_upper' ] ); ?>'], |
||
2405 | yearAriaLabel: '<?php echo esc_attr( $params[ 'year' ] ); ?>', |
||
2406 | hourAriaLabel: '<?php echo esc_attr( $params[ 'hour' ] ); ?>', |
||
2407 | minuteAriaLabel: '<?php echo esc_attr( $params[ 'minute' ] ); ?>', |
||
2408 | time_24hr: <?php echo ( $params[ 'time_24hr' ] ? 'true' : 'false' ) ; ?> |
||
2409 | } |
||
2410 | <?php if ( 0 ) { ?></script><?php } ?> |
||
2411 | <?php |
||
2412 | $locale = ob_get_clean(); |
||
2413 | |||
2414 | return apply_filters( 'ayecode_ui_flatpickr_locale', trim( $locale ) ); |
||
2415 | } |
||
2416 | |||
2417 | /** |
||
2418 | * Select2 JS params. |
||
2419 | * |
||
2420 | * @since 0.1.44 |
||
2421 | * |
||
2422 | * @return array Select2 JS params. |
||
2423 | */ |
||
2424 | public static function select2_params() { |
||
2440 | } |
||
2441 | |||
2442 | /** |
||
2443 | * Select2 JS localize. |
||
2444 | * |
||
2445 | * @since 0.1.44 |
||
2446 | * |
||
2447 | * @return string Select2 JS locale. |
||
2448 | */ |
||
2449 | public static function select2_locale() { |
||
2450 | $params = self::select2_params(); |
||
2451 | |||
2452 | foreach ( (array) $params as $key => $value ) { |
||
2453 | if ( ! is_scalar( $value ) ) { |
||
2454 | continue; |
||
2455 | } |
||
2456 | |||
2457 | $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
||
2458 | } |
||
2459 | |||
2460 | $locale = json_encode( $params ); |
||
2461 | |||
2462 | return apply_filters( 'ayecode_ui_select2_locale', trim( $locale ) ); |
||
2463 | } |
||
2464 | |||
2465 | /** |
||
2466 | * Time ago JS localize. |
||
2467 | * |
||
2468 | * @since 0.1.47 |
||
2469 | * |
||
2470 | * @return string Time ago JS locale. |
||
2471 | */ |
||
2472 | public static function timeago_locale() { |
||
2473 | $params = array( |
||
2474 | 'prefix_ago' => '', |
||
2475 | 'suffix_ago' => ' ' . _x( 'ago', 'time ago', 'ayecode-connect' ), |
||
2476 | 'prefix_after' => _x( 'after', 'time ago', 'ayecode-connect' ) . ' ', |
||
2477 | 'suffix_after' => '', |
||
2478 | 'seconds' => _x( 'less than a minute', 'time ago', 'ayecode-connect' ), |
||
2479 | 'minute' => _x( 'about a minute', 'time ago', 'ayecode-connect' ), |
||
2480 | 'minutes' => _x( '%d minutes', 'time ago', 'ayecode-connect' ), |
||
2481 | 'hour' => _x( 'about an hour', 'time ago', 'ayecode-connect' ), |
||
2482 | 'hours' => _x( 'about %d hours', 'time ago', 'ayecode-connect' ), |
||
2483 | 'day' => _x( 'a day', 'time ago', 'ayecode-connect' ), |
||
2484 | 'days' => _x( '%d days', 'time ago', 'ayecode-connect' ), |
||
2485 | 'month' => _x( 'about a month', 'time ago', 'ayecode-connect' ), |
||
2486 | 'months' => _x( '%d months', 'time ago', 'ayecode-connect' ), |
||
2487 | 'year' => _x( 'about a year', 'time ago', 'ayecode-connect' ), |
||
2488 | 'years' => _x( '%d years', 'time ago', 'ayecode-connect' ), |
||
2489 | ); |
||
2490 | |||
2491 | $params = apply_filters( 'ayecode_ui_timeago_params', $params ); |
||
2492 | |||
2493 | foreach ( (array) $params as $key => $value ) { |
||
2494 | if ( ! is_scalar( $value ) ) { |
||
2495 | continue; |
||
2496 | } |
||
2497 | |||
2498 | $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
||
2499 | } |
||
2500 | |||
2501 | $locale = json_encode( $params ); |
||
2502 | |||
2503 | return apply_filters( 'ayecode_ui_timeago_locale', trim( $locale ) ); |
||
2504 | } |
||
2505 | |||
2506 | /** |
||
2507 | * JavaScript Minifier |
||
2508 | * |
||
2509 | * @param $input |
||
2510 | * |
||
2511 | * @return mixed |
||
2512 | */ |
||
2513 | public static function minify_js($input) { |
||
2514 | if(trim($input) === "") return $input; |
||
2515 | return preg_replace( |
||
2516 | array( |
||
2517 | // Remove comment(s) |
||
2518 | '#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#', |
||
2519 | // Remove white-space(s) outside the string and regex |
||
2520 | '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#s', |
||
2521 | // Remove the last semicolon |
||
2522 | '#;+\}#', |
||
2523 | // Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}` |
||
2524 | '#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i', |
||
2525 | // --ibid. From `foo['bar']` to `foo.bar` |
||
2526 | '#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i' |
||
2527 | ), |
||
2528 | array( |
||
2529 | '$1', |
||
2530 | '$1$2', |
||
2531 | '}', |
||
2532 | '$1$3', |
||
2533 | '$1.$3' |
||
2534 | ), |
||
2535 | $input); |
||
2536 | } |
||
2537 | |||
2538 | /** |
||
2539 | * Minify CSS |
||
2540 | * |
||
2541 | * @param $input |
||
2542 | * |
||
2543 | * @return mixed |
||
2544 | */ |
||
2545 | public static function minify_css($input) { |
||
2585 | } |
||
2586 | |||
2587 | /** |
||
2588 | * Get the conditional fields JavaScript. |
||
2589 | * |
||
2590 | * @return mixed |
||
2591 | */ |
||
2592 | public function conditional_fields_js() { |
||
3118 | } |
||
3119 | } |
||
3120 | |||
3121 | /** |
||
3122 | * Run the class if found. |
||
3123 | */ |
||
3124 | AyeCode_UI_Settings::instance(); |
||
3125 | } |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.