PluginProbe ʕ •ᴥ•ʔ
Download Manager / trunk
Download Manager vtrunk
3.3.61 3.3.60 3.3.59 3.3.58 3.3.57 3.3.56 trunk 2.1.3 2.3.0 2.5.96 2.5.97 2.6.2 2.6.96 2.8.3 2.9.99 3.0.4 3.1.05 3.1.07 3.1.08 3.1.11 3.1.12 3.1.14 3.1.17 3.1.18 3.1.22 3.1.23 3.1.24 3.1.25 3.1.26 3.1.27 3.1.28 3.2.04 3.2.13 3.2.14 3.2.16 3.2.18 3.2.19 3.2.21 3.2.22 3.2.23 3.2.24 3.2.25 3.2.27 3.2.28 3.2.29 3.2.30 3.2.31 3.2.32 3.2.33 3.2.34 3.2.35 3.2.37 3.2.38 3.2.39 3.2.40 3.2.41 3.2.42 3.2.43 3.2.44 3.2.45 3.2.46 3.2.47 3.2.48 3.2.49 3.2.50 3.2.51 3.2.52 3.2.53 3.2.54 3.2.55 3.2.56 3.2.57 3.2.58 3.2.59 3.2.60 3.2.61 3.2.63 3.2.64 3.2.65 3.2.66 3.2.67 3.2.68 3.2.69 3.2.70 3.2.71 3.2.72 3.2.73 3.2.74 3.2.75 3.2.76 3.2.77 3.2.78 3.2.79 3.2.80 3.2.81 3.2.82 3.2.83 3.2.84 3.2.85 3.2.86 3.2.87 3.2.88 3.2.89 3.2.90 3.2.91 3.2.92 3.2.93 3.2.94 3.2.95 3.2.96 3.2.97 3.2.98 3.2.99 3.3.00 3.3.01 3.3.02 3.3.03 3.3.04 3.3.05 3.3.06 3.3.07 3.3.08 3.3.09 3.3.10 3.3.11 3.3.12 3.3.13 3.3.14 3.3.15 3.3.16 3.3.17 3.3.18 3.3.19 3.3.20 3.3.21 3.3.22 3.3.23 3.3.24 3.3.25 3.3.26 3.3.27 3.3.28 3.3.29 3.3.30 3.3.31 3.3.32 3.3.33 3.3.34 3.3.35 3.3.36 3.3.37 3.3.38 3.3.39 3.3.40 3.3.41 3.3.42 3.3.43 3.3.44 3.3.45 3.3.46 3.3.47 3.3.48 3.3.49 3.3.50 3.3.51 3.3.52 3.3.53 3.3.54 3.3.55
download-manager / src / Form / Form.php
download-manager / src / Form Last commit date
Field.php 5 months ago Form.php 5 months ago
Form.php
206 lines
1 <?php
2
3 namespace WPDM\Form;
4
5 use WPDM\__\__;
6
7 class Form
8 {
9 private $fieldGroups = [];
10 private $formFields;
11 private $method = 'post';
12 private $action = '';
13 private $name = 'form';
14 private $id = 'form';
15 private $class = 'form';
16 public $submit_button = [];
17 public $error = '';
18 public $noForm = false;
19
20 function __construct($formFields, $attrs = array())
21 {
22 /*if (!isset($attrs['id'])) {
23 $this->error = '<div class="alert alert-danger">Form ID is require, field id is missing in $attrs<br/><pre style="border-radius: 0;margin-top: 10px;margin-bottom: 5px">' . print_r($attrs, 1) . '</pre></div>';
24 return;
25 }*/
26 if (isset($attrs['groups']))
27 $this->fieldGroups = $attrs['groups'];
28 foreach ($attrs as $name => $value) {
29 $this->$name = $value;
30 }
31 $this->formFields = apply_filters("{$this->id}_fields", $formFields, $attrs);
32
33 }
34
35 function div($class = '', $id = '')
36 {
37 return "<div class='{$class}' id='row_{$id}'>";
38 }
39
40 function divClose()
41 {
42 return "</div>";
43 }
44
45 function label($label, $for = '')
46 {
47 return "<label form='{$for}'>{$label}</label>";
48 }
49
50 function row($id, $fields)
51 {
52 $row = $this->div("row", $id);
53 if (isset($fields['label']))
54 $this->label($fields['label'], $id);
55
56 foreach ($fields['cols'] as $id => $field) {
57 $row .= $this->formGroup($id, $field);
58 }
59
60 $row .= $this->divClose();
61 return $row;
62 }
63
64 function fieldGroup($id, $name, $fields_html)
65 {
66 $group = $this->div('card', $id);
67 $group .= $this->div('card-header', $id) . $name . $this->divClose();
68 $group .= $this->div('card-body') . $fields_html . $this->divClose();
69 $group .= $this->divClose();
70 return $group;
71 }
72
73 function formGroup($id, $field)
74 {
75 $grid_class = isset($field['grid_class']) ? $field['grid_class'] : '';
76 $field_html = $this->div("form-group {$grid_class}", $id);
77 $type = $field['type'];
78 $field_html .= $this->div("input-wrapper {$type}-input-wrapper", $id . "_wrapper");
79 if (isset($field['label']))
80 $field_html .= $this->label($field['label'], $id);
81
82 $input = $type === 'custom' ? Field::custom($field['custom_control'], $field['attrs']) : Field::$type($field['attrs'], __::valueof($field, 'value'));
83 if (in_array($type, ['reCaptcha', 'hidden'])) return $input;
84
85 $prepend = isset($field['prepend']) ? $field['prepend'] : null;
86 $append = isset($field['append']) ? $field['append'] : null;
87 $input = $this->inputGroup($input, $prepend, $append);
88 $field_html .= $this->note(__::valueof($field, 'note_before'));
89 $field_html .= $input;
90 $field_html .= $this->note(__::valueof($field, 'note'));
91 $field_html .= $this->note(__::valueof($field, 'note_after'));
92 $field_html .= $this->divClose();
93 $field_html .= $this->divClose();
94 return $field_html;
95 }
96
97 function note($note)
98 {
99 if ($note) return "<em class='note'>{$note}</em>";
100 }
101
102 function inputGroup($input, $prepend = null, $append = null)
103 {
104 if (!$prepend && !$prepend) return $input;
105 $input_group = "<div class='input-group'>";
106 $input_group .= $prepend ? "<div class='input-group-prepend'><span class='input-group-text'>{$prepend}</span></div>" : "";
107 $input_group .= $input;
108 $input_group .= $append ? "<div class='input-group-append'><span class='input-group-text'>{$append}</span></div>" : "";
109 $input_group .= "</div>";
110 return $input_group;
111 }
112
113 function heading($attrs)
114 {
115 $_attrs = "";
116 $text = $attrs['text'];
117 unset($attrs['text']);
118 foreach ($attrs as $key => $value) {
119 $_attrs .= "{$key}='{$value}' ";
120 }
121 return "<div class=''>{$text}</div>";
122 }
123
124 function reCaptcha($attrs)
125 {
126 ob_start();
127 ?>
128 <div class="form-group row">
129 <div class="col-sm-12">
130 <input type="hidden" id="<?php echo $attrs['id'] ?>" name="<?php echo $attrs['name'] ?>" value=""/>
131 <script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
132 async defer></script>
133 <div id="<?php echo $attrs['id'] ?>_field"></div>
134 <style>
135 #wpdmlogin #<?php echo $attrs['id'] ?>_field iframe {
136 transform: scale(1.16);
137 margin-left: 24px;
138 margin-top: 5px;
139 margin-bottom: 5px;
140 }
141
142 #wpdmlogin #<?php echo $attrs['id'] ?>_field {
143 padding-bottom: 10px !important;
144 }
145 </style>
146 <script type="text/javascript">
147 var verifyCallback = function (response) {
148 jQuery('#<?php echo $attrs['id'] ?>').val(response);
149 };
150 var widgetId2;
151 var onloadCallback = function () {
152 grecaptcha.render('<?php echo $attrs['id'] ?>_field', {
153 'sitekey': '<?php echo get_option('_wpdm_recaptcha_site_key'); ?>',
154 'callback': verifyCallback,
155 'theme': 'light'
156 });
157 };
158 </script>
159 </div>
160
161 </div>
162 <?php
163 $captcha = ob_get_clean();
164 return $captcha;
165 }
166
167 function render()
168 {
169 if ($this->error) return $this->error;
170 $form_html = $this->noForm ? "" : "<form method='{$this->method}' action='{$this->action}' name='{$this->name}' id='{$this->id}' class='{$this->class}'>";
171 $before_form_fields = "";
172 $form_html .= apply_filters("wpdm_form_{$this->id}_before_fields", $before_form_fields, $this);
173
174 //Initial field groups
175 $_field_group_html = [];
176 foreach ($this->fieldGroups as $group_id => $group_name){
177 $_field_group_html[$group_id] = '';
178 }
179
180 //Generate form fields
181 foreach ($this->formFields as $id => $field) {
182 $field_html = '';
183 if (isset($field['cols']))
184 $field_html = $this->row($id, $field);
185 else
186 $field_html = $this->formGroup($id, $field);
187 if(isset($field['group']) && isset($this->fieldGroups[$field['group']]))
188 $_field_group_html[$field['group']] .= $field_html;
189 else
190 $form_html .= $field_html;
191 }
192
193 foreach ($this->fieldGroups as $group_id => $group_name){
194 $form_html .= $this->fieldGroup($group_id, $group_name, $_field_group_html[$group_id]);
195 }
196
197 if ($this->submit_button) {
198 $form_html .= "<button class='{$this->submit_button['class']}'>{$this->submit_button['label']}</button>";
199 }
200 $after_form_fields = "";
201 $form_html .= apply_filters("wpdm_form_{$this->id}_before_fields", $after_form_fields, $this);
202 $form_html .= $this->noForm ? "" : "</form>";
203 return $form_html;
204 }
205 }
206