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

137 lines 2.7 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.16 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 {
55 case 'text':
56 $label = 'Text field';
57 break;
58 case 'textarea':
59 $label = 'Textarea field';
60 break;
61 case 'email':
62 $label = 'Email field';
63 break;
64 case 'hidden':
65 $label = 'Hidden field';
66 break;
67 case 'dropdown':
68 $label = 'Dropdown field';
69 break;
70 }
71 }
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\\' . ucfirst($type);
104 if (!class_exists($class))
105 {
106 return;
107 }
108
109 return new $class($params);
110 }
111
112 /**
113 * Convert all applicable characters to HTML entities
114 *
115 * @param string $input The input string.
116 *
117 * @return string
118 */
119 public static function escape($input)
120 {
121 if (!is_string($input))
122 {
123 return $input;
124 }
125
126 // Convert all HTML tags to HTML entities.
127 $input = htmlspecialchars($input, ENT_NOQUOTES, 'UTF-8');
128
129 // We do not need any Smart Tag replacements take place here, so we need to escape curly brackets too.
130 $input = str_replace(['{', '}'], ['&#123;', '&#125;'], $input);
131
132 // Respect newline characters, by converting them to <br> tags.
133 $input = nl2br($input);
134
135 return $input;
136 }
137 }