PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 3.1.13
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v3.1.13
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 / Helpers / Form / Field.php

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

159 lines 3.1 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 3.1.13 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2026 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\Helpers\Form;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 class Field
20 {
21 /**
22 * Get Field Name given a field block.
23 *
24 * @param array $block
25 *
26 * @return string
27 */
28 public static function getFieldName($block)
29 {
30 if (isset($block['attrs']['fieldName']))
31 {
32 return $block['attrs']['fieldName'];
33 }
34
35 return str_replace('firebox/', '', $block['blockName']);
36 }
37
38 /**
39 * Get the field label.
40 *
41 * @param array $block
42 *
43 * @return string
44 */
45 public static function getFieldLabel($block)
46 {
47 $label = isset($block['attrs']['fieldLabel']) ? $block['attrs']['fieldLabel'] : '';
48
49 if (empty($label))
50 {
51 $label = self::prepareFieldLabel($block['blockName']);
52 }
53
54 return $label;
55 }
56
57 public static function prepareFieldLabel($type)
58 {
59 $label = self::getFieldType($type);
60
61 switch ($label)
62 {
63 case 'datetime':
64 $label = firebox()->_('FB_DATE_TIME_FIELD');
65 break;
66 case 'phonenumber':
67 $label = firebox()->_('FB_PHONE_NUMBER_FIELD');
68 break;
69 }
70
71 $label = sprintf(firebox()->_('FB_X_FIELD'), ucfirst($label));
72
73 return $label;
74 }
75
76 /**
77 * Returns the field tpye given a field block name.
78 *
79 * @param string $blockName
80 *
81 * @return string
82 */
83 public static function getFieldType($blockName)
84 {
85 return str_replace('firebox/', '', $blockName);
86 }
87
88 /**
89 * Returns the field class instance.
90 *
91 * @param array $params
92 *
93 * @return /FireBox/Core/Form/Fields/Field
94 */
95 public static function getFieldClass($params)
96 {
97 $type = isset($params['type']) ? $params['type'] : '';
98 if (!$type)
99 {
100 return;
101 }
102
103 $class = '\FireBox\Core\Form\Fields\Fields\\' . self::getFieldClassFromMap($type);
104 if (!class_exists($class))
105 {
106 return;
107 }
108
109 return new $class($params);
110 }
111
112 public static function getFieldClassFromMap($type)
113 {
114 $class = ucfirst($type);
115
116 switch ($type)
117 {
118 case 'datetime':
119 $class = 'DateTime';
120 break;
121
122 case 'phonenumber':
123 $class = 'PhoneNumber';
124 break;
125
126 case 'hcaptcha':
127 $class = 'HCaptcha';
128 break;
129 }
130
131 return $class;
132 }
133
134 /**
135 * Convert all applicable characters to HTML entities
136 *
137 * @param string $input The input string.
138 *
139 * @return string
140 */
141 public static function escape($input)
142 {
143 if (!is_string($input))
144 {
145 return $input;
146 }
147
148 // Convert all HTML tags to HTML entities.
149 $input = htmlspecialchars($input, ENT_NOQUOTES, 'UTF-8');
150
151 // We do not need any Smart Tag replacements take place here, so we need to escape curly brackets too.
152 $input = str_replace(['{', '}'], ['&#123;', '&#125;'], $input);
153
154 // Respect newline characters, by converting them to <br> tags.
155 $input = nl2br($input);
156
157 return $input;
158 }
159 }