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

150 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.10 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\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 $type = self::getFieldType($block['blockName']);
52
53 switch ($type) {
54 case 'text':
55 $label = 'Text field';
56 break;
57 case 'textarea':
58 $label = 'Textarea field';
59 break;
60 case 'email':
61 $label = 'Email field';
62 break;
63 }
64 }
65
66 return $label;
67 }
68
69 /**
70 * Returns the field tpye given a field block name.
71 *
72 * @param string $blockName
73 *
74 * @return string
75 */
76 public static function getFieldType($blockName)
77 {
78 return str_replace('firebox/', '', $blockName);
79 }
80
81 /**
82 * Returns the field class instance.
83 *
84 * @param array $params
85 *
86 * @return /FireBox/Core/Form/Fields/Field
87 */
88 public static function getFieldClass($params)
89 {
90 $type = isset($params['type']) ? $params['type'] : '';
91 if (!$type)
92 {
93 return;
94 }
95
96 $class = '\FireBox\Core\Form\Fields\Fields\\' . ucfirst($type);
97 if (!class_exists($class))
98 {
99 return;
100 }
101
102 $options = self::getFieldOptions($params);
103 $options = array_merge($options, $params);
104
105 return new $class($options);
106 }
107
108 /**
109 * Returns the default field options.
110 *
111 * @param array $attrs
112 *
113 * @return array
114 */
115 public static function getFieldOptions($attrs = [])
116 {
117 return [
118 'required' => isset($attrs['required']) ? $attrs['required'] : true,
119 'name' => '',
120 'placeholder' => '',
121 'input_css_class' => ['fb-form-input']
122 ];
123 }
124
125 /**
126 * Convert all applicable characters to HTML entities
127 *
128 * @param string $input The input string.
129 *
130 * @return string
131 */
132 public static function escape($input)
133 {
134 if (!is_string($input))
135 {
136 return $input;
137 }
138
139 // Convert all HTML tags to HTML entities.
140 $input = htmlspecialchars($input, ENT_NOQUOTES, 'UTF-8');
141
142 // We do not need any Smart Tag replacements take place here, so we need to escape curly brackets too.
143 $input = str_replace(['{', '}'], ['&#123;', '&#125;'], $input);
144
145 // Respect newline characters, by converting them to <br> tags.
146 $input = nl2br($input);
147
148 return $input;
149 }
150 }