PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.0.6
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.0.6
3.1.13 3.1.12 3.1.11 3.1.10 3.1.9 3.1.8 3.1.7 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 All 122 releases
firebox / Inc / Core / Form / Fields / Field.php

Field.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 2.0.6, at Inc/Core/Form/Fields/Field.php

184 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package FireBox
4 * @version 2.0.6 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2023 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\Form\Fields;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 class Field
20 {
21 /**
22 * Field options.
23 *
24 * @var array
25 */
26 protected $options = [];
27
28 /**
29 * Validation message that appears when a field fails validation.
30 *
31 * @var string
32 */
33 protected $validation_message = '';
34
35 public function __construct($options = [])
36 {
37 $this->options = \FPFramework\Helpers\ArrayHelper::arrayMerge($this->getDefaultOptions(), $options);
38 }
39
40 /**
41 * Returns the default field options.
42 *
43 * @return array
44 */
45 private function getDefaultOptions()
46 {
47 return [
48 'type' => $this->type,
49 'required' => true,
50 'name' => '',
51 'placeholder' => '',
52 'input_css_class' => ['fb-form-input']
53 ];
54 }
55
56 /**
57 * Validate the field.
58 *
59 * @param mixed $value
60 *
61 * @return void
62 */
63 public function validate(&$value = '')
64 {
65 if ($this->isRequired() && empty($value))
66 {
67 $this->validation_message = firebox()->_('FB_THIS_IS_A_REQUIRED_FIELD');
68 return false;
69 }
70
71 return true;
72 }
73
74 /**
75 * Returns whether the field is required.
76 *
77 * @return bool
78 */
79 public function isRequired()
80 {
81 return $this->options['required'];
82 }
83
84 /**
85 * Prepare value to be displayed to the user as plain text
86 *
87 * @param mixed $value
88 *
89 * @return string
90 */
91 public function prepareValue($value)
92 {
93 if (is_bool($value))
94 {
95 return $value ? '1' : '0';
96 }
97
98 if (is_array($value))
99 {
100 return implode(', ', $value);
101 }
102
103 // Strings and numbers
104 return \FireBox\Core\Helpers\Form\Field::escape($value);
105 }
106
107 public function getValue()
108 {
109 return $this->options['value'];
110 }
111
112 public function prepareValueHTML($value)
113 {
114 return $this->prepareValue($value);
115 }
116
117 public function getValueRaw()
118 {
119 return $this->getValue();
120 }
121
122 public function getValueHTML()
123 {
124 return $this->prepareValueHTML($this->options['value']);
125 }
126
127 public function getValidationMessage()
128 {
129 return $this->validation_message;
130 }
131
132 public function setValue($value = '')
133 {
134 if (!$value)
135 {
136 return;
137 }
138
139 $this->options['value'] = $value;
140 }
141
142 public function setOptionValue($key = '', $value = '')
143 {
144 if (!$key || !$value)
145 {
146 return;
147 }
148
149 $this->options[$key] = $value;
150 }
151
152 public function getOptionValue($key = '')
153 {
154 if (!$key)
155 {
156 return;
157 }
158
159 return isset($this->options[$key]) ? $this->options[$key] : '';
160 }
161
162 public function addInputCSSClass($css = '')
163 {
164 $this->options['input_css_class'][] = $css;
165 }
166
167 /**
168 * Return the field label.
169 *
170 * @return string
171 */
172 public function getLabel()
173 {
174 return $this->getOptionValue('label');
175 }
176
177 /**
178 * Returns the field input.
179 *
180 * @return void
181 */
182 public function getInput()
183 {}
184 }