PluginProbe
Age Gate / 3.7.3
Age Gate v3.7.3
3.7.3 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 All 113 releases
age-gate / src / Presentation / Form.php

Form.php in Age Gate 3.7.3, at src/Presentation/Form.php

121 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AgeGate\Presentation;
4
5 use Asylum\Utility\Color;
6 use Asylum\Utility\Storage;
7 use AgeGate\Common\Settings;
8
9 class Form
10 {
11 private $settings;
12 private $custom = 'age-gate-custom';
13 private $options = 'age-gate-options';
14
15 public function __construct()
16 {
17 $this->settings = Settings::getInstance();
18 }
19
20 public function optionStyle()
21 {
22 wp_register_style($this->custom, false); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
23 wp_add_inline_style($this->custom, wp_strip_all_tags(stripslashes(html_entity_decode($this->getStyleOptions(), ENT_QUOTES))));
24
25 return $this;
26 }
27
28 public function customStyle()
29 {
30 if (!trim($this->settings->css)) {
31 return $this;
32 }
33
34 if ($this->settings->cssFile && file_exists(Storage::storageDir('css', 'age-gate') . '/custom.css')) {
35 $deps = [];
36
37 if ($this->settings->enqueueCss) {
38 $deps = ['age-gate'];
39 }
40
41 wp_register_style($this->custom, Storage::storageUrl('css', 'age-gate') . '/custom.css', $deps, AGE_GATE_VERSION);
42 } else {
43 wp_register_style($this->custom, false); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
44
45 wp_add_inline_style($this->custom, wp_strip_all_tags(stripslashes(html_entity_decode($this->settings->css, ENT_QUOTES))));
46 }
47
48 return $this;
49 }
50
51 public function enqueue()
52 {
53 wp_enqueue_style($this->custom);
54 wp_enqueue_style($this->options);
55 }
56
57 private function getStyleOptions()
58 {
59 $options = [
60 'backgroundColor',
61 'backgroundOpacity',
62 'backgroundImage',
63 'backgroundPosition',
64 'backgroundImageOpacity',
65 'blur',
66 'foregroundColor',
67 'foregroundOpacity',
68 'textColor',
69 ];
70
71 $styles = '';
72
73 if ($this->settings->backgroundColor) {
74 $styles .= $this->variable('--ag-background-color', Color::hex2rgb($this->settings->backgroundColor, $this->settings->backgroundOpacity !== false ? (float) $this->settings->backgroundOpacity : 1));
75 }
76
77 if ($this->settings->backgroundImage) {
78 $styles .= $this->variable('--ag-background-image', 'url(' . $this->settings->backgroundImage . ')');
79 }
80
81 if ($this->settings->backgroundPosition) {
82 $styles .= $this->variable('--ag-background-image-position', $this->settings->backgroundPosition['x'] . ' ' . $this->settings->backgroundPosition['y']);
83 }
84
85 if ($this->settings->backgroundImageOpacity) {
86 $styles .= $this->variable('--ag-background-image-opacity', $this->settings->backgroundImageOpacity !== false ? (float) $this->settings->backgroundImageOpacity : 1);
87 }
88
89
90 if ($this->settings->foregroundColor) {
91 $styles .= $this->variable('--ag-form-background', Color::hex2rgb($this->settings->foregroundColor, $this->settings->foregroundOpacity !== false ? (float) $this->settings->foregroundOpacity : 1));
92 }
93
94 if ($this->settings->textColor) {
95 $styles .= $this->variable('--ag-text-color', $this->settings->textColor);
96 }
97
98
99 if ($this->settings->blur) {
100 $styles .= $this->variable('--ag-blur', $this->settings->blur . 'px');
101 }
102
103 $styles = trim($styles);
104 wp_register_style($this->options, false, ['age-gate']); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
105
106 if ($styles) {
107 $styles = sprintf(':root{%s}', $styles);
108
109 wp_add_inline_style($this->options, wp_strip_all_tags(stripslashes(html_entity_decode($styles, ENT_QUOTES))));
110 }
111
112 return $styles;
113
114 }
115
116 private function variable($key, $value)
117 {
118 return sprintf('%s: %s;', $key, $value);
119 }
120 }
121