PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 3.6.2
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v3.6.2
6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 3.6.66 All 195 releases
fluentform / app / Modules / Form / FormDataParser.php

FormDataParser.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 3.6.2, at app/Modules/Form/FormDataParser.php

284 lines 7.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Modules\Form;
4
5 use FluentForm\Framework\Helpers\ArrayHelper;
6 use WpFluent\Exception;
7
8 class FormDataParser
9 {
10 protected static $data = null;
11
12 public static function parseFormEntries($entries, $form, $fields = null)
13 {
14 $fields = $fields ? $fields : FormFieldsParser::getEntryInputs($form);
15
16 foreach ($entries as $entry) {
17 static::parseFormEntry($entry, $form, $fields);
18 }
19
20 return $entries;
21 }
22
23 public static function parseFormEntry($entry, $form, $fields = null, $isHtml = false)
24 {
25 $fields = $fields ? $fields : FormFieldsParser::getEntryInputs($form);
26
27 $entry->user_inputs = static::parseData(
28 json_decode($entry->response), $fields, $form->id, $isHtml
29 );
30
31 return $entry;
32 }
33
34 public static function parseFormSubmission($submission, $form, $fields, $isHtml = false)
35 {
36 if (is_null(static::$data)) {
37 static::$data = static::parseData(
38 json_decode($submission->response), $fields, $form->id, $isHtml
39 );
40 }
41
42 $submission->user_inputs = static::$data;
43
44 return $submission;
45 }
46
47 public static function parseData( $response, $fields, $formId, $isHtml = false )
48 {
49 $trans = [];
50 foreach ($fields as $field_key => $field) {
51 if (isset($response->{$field_key})) {
52 $value = apply_filters(
53 'fluentform_response_render_'.$field['element'],
54 $response->{$field_key},
55 $field,
56 $formId,
57 $isHtml
58 );
59 $trans[$field_key] = $value;
60 } else {
61 $trans[$field_key] = '';
62 }
63 }
64
65 return $trans;
66 }
67
68 public static function formatValue($value)
69 {
70 if (is_array($value) || is_object($value)) {
71 return fluentImplodeRecursive(', ', array_filter(array_values((array) $value)));
72 }
73
74 return $value;
75 }
76
77 public static function formatFileValues($values, $isHtml)
78 {
79 if(!$values) {
80 return $values;
81 }
82
83 if(is_string($values)) {
84 return $values;
85 }
86
87 if(!$isHtml) {
88 return fluentImplodeRecursive(', ', array_filter(array_values((array) $values)));
89 }
90
91 $html = '<ul class="ff_entry_list">';
92 foreach ($values as $value) {
93 if(!$value) {
94 continue;
95 }
96 $html .= '<li><a href="'.$value.'" target="_blank">'.basename($value).'</a></li>';
97 }
98
99 $html .= '</ul>';
100 return $html;
101 }
102
103 public static function formatImageValues($values, $isHtml)
104 {
105 if(!$values) {
106 return $values;
107 }
108
109 if(is_string($values)) {
110 return $values;
111 }
112
113 if(!$isHtml) {
114 return fluentImplodeRecursive(', ', array_filter(array_values((array) $values)));
115 }
116
117 if(count($values) == 1) {
118 $value = $values[0];
119 if(!$value) {
120 return '';
121 }
122 return '<a href="'.$value.'" target="_blank"><img style="max-width:180px" src="'.$value.'" /></a>';
123 }
124
125 $html = '<ul class="ff_entry_list ff_entry_images">';
126 foreach ($values as $value) {
127 if(!$value) {
128 continue;
129 }
130 $html .= '<li style="margin: 20px 20px 20px 0px; display: inline-block; margin-right: 20px;"><a href="'.$value.'" target="_blank"><img style="max-width:180px" src="'.$value.'" /></a></li>';
131 }
132
133 $html .= '</ul>';
134 return $html;
135 }
136
137 public static function formatRepeatFieldValue($value, $field, $form_id) {
138
139 if(defined('FLUENTFORM_RENDERING_ENTRIES')) {
140 return __('....', 'fluentform');
141 }
142
143 if(is_string($value)) {
144 return $value;
145 }
146
147 try {
148 $repeatColumns = ArrayHelper::get($field, 'raw.fields');
149 $rows = count($value[0]);
150 $columns = count($value);
151
152 ob_start();
153 if($repeatColumns) {
154 ?>
155 <div class="ff_entry_table_wrapper">
156 <table class="ff_entry_table_field ff-table">
157 <thead>
158 <tr>
159 <?php foreach ($repeatColumns as $repeatColumn) : ?>
160 <th><?php echo ArrayHelper::get($repeatColumn, 'settings.label'); ?></th>
161 <?php endforeach; ?>
162 </tr>
163 </thead>
164
165 <tbody>
166 <?php for ($i = 0; $i < $rows; $i++) : ?>
167 <tr>
168 <?php for ($j = 0; $j < $columns; $j++) : ?>
169 <td>
170 <?php echo $value[$j][$i] ?>
171 </td>
172 <?php endfor; ?>
173 </tr>
174 <?php endfor; ?>
175 </tbody>
176 </table>
177 </div>
178 <?php
179 }
180 return ob_get_clean();
181 } catch (Exception $e) {
182
183 }
184
185 return $value;
186 }
187
188 public static function formatTabularGridFieldValue($value, $field, $form_id, $isHtml = false)
189 {
190 if(defined('FLUENTFORM_RENDERING_ENTRIES')) {
191 return __('....', 'fluentform');
192 }
193
194 if(is_string($value)) {
195 return $value;
196 }
197
198 if(is_array($value)) {
199 $value = (object) $value;
200 }
201 try {
202 if(empty($field['raw'])) {
203 return $value;
204 }
205 $columnLabels = $field['raw']['settings']['grid_columns'];
206 $fieldType = $field['raw']['settings']['tabular_field_type'];
207 $columnHeaders = implode('</th><th>', array_values($columnLabels));
208
209 $elMarkup = "<table class='ff-table'><thead><tr><th></th><th>{$columnHeaders}</th></tr></thead><tbody>";
210
211 foreach (static::makeTabularData($field['raw']) as $row) {
212
213 $elMarkup .= "<tr>";
214 $elMarkup .= "<td>{$row['label']}</td>";
215 foreach ($row['columns'] as $column) {
216 $isChecked = '';
217 if ($fieldType == 'radio') {
218 if(isset($value->{$row['name']})) {
219 $isChecked = $value->{$row['name']} == $column['name'] ? 'checked' : '';
220 }
221 } else {
222 if(isset($value->{$row['name']})) {
223 $isChecked = in_array($column['name'], $value->{$row['name']}) ? 'checked' : '';
224 }
225 }
226 $icon = "<input disabled type='{$fieldType}' {$isChecked}>";
227 if($isChecked) {
228 $icon = '';
229 }
230 $elMarkup .= "<td>".$icon."</td>";
231 }
232 $elMarkup .= "</tr>";
233 }
234
235 $elMarkup .= "</tbody></table>";
236
237 return $elMarkup;
238 } catch (Exception $e) {
239
240 }
241 return '';
242 }
243
244 public static function makeTabularData($data)
245 {
246 $table = [];
247 $rows = $data['settings']['grid_rows'];
248 $columns = $data['settings']['grid_columns'];
249
250 foreach ($rows as $rowKey => $rowValue) {
251 $table[$rowKey] = [
252 'name' => $rowKey,
253 'label' => $rowValue,
254 'columns' => []
255 ];
256
257 foreach ($columns as $columnKey => $columnValue) {
258 $table[$rowKey]['columns'][] = [
259 'name' => $columnKey,
260 'label' => $columnValue
261 ];
262 }
263 }
264
265 return $table;
266 }
267
268 /**
269 * Format input_name field value by concatenating all name fields.
270 *
271 * @param array|object $value
272 *
273 * @return string $value
274 */
275 public static function formatName($value)
276 {
277 if (is_array($value) || is_object($value)) {
278 return fluentImplodeRecursive(' ', array_filter(array_values((array) $value)));
279 }
280
281 return $value;
282 }
283 }
284