PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.1.23
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.1.23
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 2.1.23, at Inc/Core/Helpers/Form/Field.php

157 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 2.1.23 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2024 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 $label = sprintf(firebox()->_('FB_X_FIELD'), $label);
54 }
55
56 return $label;
57 }
58
59 public static function prepareFieldLabel($type)
60 {
61 $label = ucfirst(self::getFieldType($type));
62
63 switch (strtolower($type))
64 {
65 case 'datetime':
66 $label = firebox()->_('FB_DATE_TIME_FIELD');
67 break;
68 case 'phonenumber':
69 $label = firebox()->_('FB_PHONE_NUMBER_FIELD');
70 break;
71 }
72
73 $label = sprintf(firebox()->_('FB_X_FIELD'), ucfirst($label));
74
75 return $label;
76 }
77
78 /**
79 * Returns the field tpye given a field block name.
80 *
81 * @param string $blockName
82 *
83 * @return string
84 */
85 public static function getFieldType($blockName)
86 {
87 return str_replace('firebox/', '', $blockName);
88 }
89
90 /**
91 * Returns the field class instance.
92 *
93 * @param array $params
94 *
95 * @return /FireBox/Core/Form/Fields/Field
96 */
97 public static function getFieldClass($params)
98 {
99 $type = isset($params['type']) ? $params['type'] : '';
100 if (!$type)
101 {
102 return;
103 }
104
105 $class = '\FireBox\Core\Form\Fields\Fields\\' . self::getFieldClassFromMap($type);
106 if (!class_exists($class))
107 {
108 return;
109 }
110
111 return new $class($params);
112 }
113
114 public static function getFieldClassFromMap($type)
115 {
116 $class = ucfirst($type);
117
118 switch ($type)
119 {
120 case 'datetime':
121 $class = 'DateTime';
122 break;
123
124 case 'phonenumber':
125 $class = 'PhoneNumber';
126 break;
127 }
128
129 return $class;
130 }
131
132 /**
133 * Convert all applicable characters to HTML entities
134 *
135 * @param string $input The input string.
136 *
137 * @return string
138 */
139 public static function escape($input)
140 {
141 if (!is_string($input))
142 {
143 return $input;
144 }
145
146 // Convert all HTML tags to HTML entities.
147 $input = htmlspecialchars($input, ENT_NOQUOTES, 'UTF-8');
148
149 // We do not need any Smart Tag replacements take place here, so we need to escape curly brackets too.
150 $input = str_replace(['{', '}'], ['&#123;', '&#125;'], $input);
151
152 // Respect newline characters, by converting them to <br> tags.
153 $input = nl2br($input);
154
155 return $input;
156 }
157 }