PluginProbe
Repeater Fields for Gravity Forms / 2.3.2
Repeater Fields for Gravity Forms v2.3.2
3.2.0 3.1.1 3.1.0 3.0.4 3.0.3 3.0.2 3.0.1 3.0.0 2.5.1 2.5.0 2.4.6 trunk 2.0.5 2.0.9 2.1.0 2.3.2 2.3.7 2.4.1 2.4.3 2.4.4 2.4.5
← All changes | fields/repeater_field.php +0 -865 3.0.32.3.2 View file →
@@ -1,865 +1,0 @@
1 -<?php
2 -// If Gravity Forms isn't loaded, bail.
3 -if (!class_exists('GFForms')) {
4 - die();
5 -}
6 -/**
7 - * Class GF_Field_Phone
8 - *
9 - * Handles the behavior of Phone fields.
10 - *
11 - * @since Unknown
12 - */
13 -class Superaddons_GFRepeater_Field extends GF_Field
14 -{
15 - private $lead_id = null;
16 - /**
17 - * Defines the field type.
18 - *
19 - * @since Unknown
20 - * @access public
21 - *
22 - * @var string The field type.
23 - */
24 - public $type = 'repeater_end';
25 - public $list_fields_validate = array();
26 - /**
27 - * Defines the field title to be used in the form editor.
28 - *
29 - * @since Unknown
30 - * @access public
31 - *
32 - * @used-by GFCommon::get_field_type_title()
33 - *
34 - * @return string The field title. Translatable and escaped.
35 - */
36 - public function get_form_editor_field_title()
37 - {
38 - return esc_attr__('Repeater end', 'repeater-for-gravity-forms');
39 - }
40 - public function get_form_editor_button()
41 - {
42 - return array(
43 - 'group' => 'advanced_fields',
44 - 'text' => $this->get_form_editor_field_title()
45 - );
46 - }
47 - /**
48 - * Defines the field settings available within the field editor.
49 - *
50 - * @since Unknown
51 - * @access public
52 - *
53 - * @return array The field settings available for the field.
54 - */
55 - function get_form_editor_field_settings()
56 - {
57 - return array(
58 - 'conditional_logic_field_setting',
59 - 'prepopulate_field_setting',
60 - 'error_message_setting',
61 - 'label_setting',
62 - 'field_field_repeater_end_text_setting',
63 - 'field_field_repeater_initial_rows_setting',
64 - 'field_field_repeater_max_setting',
65 - 'label_placement_setting',
66 - 'admin_label_setting',
67 - 'size_setting',
68 - 'rules_setting',
69 - 'visibility_setting',
70 - 'duplicate_setting',
71 - 'placeholder_setting',
72 - 'description_setting',
73 - 'css_class_setting',
74 - );
75 - }
76 - /**
77 - * Defines if conditional logic is supported in this field type.
78 - *
79 - * @since Unknown
80 - * @access public
81 - *
82 - * @used-by GFFormDetail::inline_scripts()
83 - * @used-by GFFormSettings::output_field_scripts()
84 - *
85 - * @return bool true
86 - */
87 - public function is_conditional_logic_supported()
88 - {
89 - return false;
90 - }
91 - /**
92 - * Returns the field input.
93 - *
94 - * @since Unknown
95 - * @access public
96 - *
97 - * @used-by GFCommon::get_field_input()
98 - * @uses GF_Field::is_entry_detail()
99 - * @uses GF_Field::is_form_editor()
100 - * @uses GF_Field_Phone::$failed_validation
101 - * @uses GF_Field_Phone::get_phone_format()
102 - * @uses GFFormsModel::is_html5_enabled()
103 - * @uses GF_Field::get_field_placeholder_attribute()
104 - * @uses GF_Field_Phone::$isRequired
105 - * @uses GF_Field::get_tabindex()
106 - *
107 - * @param array $form The Form Object.
108 - * @param string $value The value of the input. Defaults to empty string.
109 - * @param null|array $entry The Entry Object. Defaults to null.
110 - *
111 - * @return string The HTML markup for the field.
112 - */
113 - public function get_field_input($form, $value = '', $entry = null)
114 - {
115 - if (is_array($value)) {
116 - $value = '';
117 - }
118 - $is_entry_detail = $this->is_entry_detail();
119 - $is_form_editor = $this->is_form_editor();
120 - $form_id = $form['id'];
121 - $id = intval($this->id);
122 - $field_id = $is_entry_detail || $is_form_editor || $form_id == 0 ? "input_$id" : 'input_' . $form_id . "_$id";
123 - $size = $this->size;
124 - $disabled_text = $is_form_editor ? "disabled='disabled'" : '';
125 - $class_suffix = $is_entry_detail ? '_admin' : '';
126 - $class = $size . $class_suffix . " gf-field-repeater-data hidden";
127 - $class = esc_attr($class);
128 - $instruction_div = '';
129 - $html_input_type = 'hidden';
130 - $placeholder_attribute = $this->get_field_placeholder_attribute();
131 - $required_attribute = $this->isRequired ? 'aria-required="true"' : '';
132 - $invalid_attribute = $this->failed_validation ? 'aria-invalid="true"' : 'aria-invalid="false"';
133 - $aria_describedby = $this->get_aria_describedby();
134 - $tabindex = $this->get_tabindex();
135 - $repeater_add_button = $this->field_repeater_end_text;
136 - if ($repeater_add_button == "") {
137 - $repeater_add_button = esc_attr__("Add more", "gravityforms-repeater");
138 - }
139 - $initial_rows = $this->repeater_initial_rows;
140 - if ($initial_rows == "") {
141 - $initial_rows = 1;
142 - }
143 - $limit = $this->repeater_max;
144 - if ($limit == "" or $limit < 1) {
145 - $limit = 9999;
146 - }
147 - $limit = apply_filters("yeeaddons_gf_repeater_limit", 5, $limit);
148 - $initial_rows = apply_filters("yeeaddons_gf_repeater_initial_rows", 1, $initial_rows);
149 - $input = "<input data-initial_rows_map_check='" . $this->repeater_initial_rows_map . "' data-initial_rows_map='input_{$form_id}_" . $this->repeater_initial_rows_map . "' data-map_id='field_" . $form_id . "_" . $id . "' name='input_{$id}' id='{$field_id}' type='{$html_input_type}' value='{$value}' class='{$class}' {$tabindex} {$placeholder_attribute} {$required_attribute} {$invalid_attribute} {$disabled_text}/>";
150 - $html = '<div data-initial_rows_map_check="' . $this->repeater_initial_rows_map . '" class="repeater-field-warp-item-data" data-initial_rows="' . $initial_rows . '" data-limit="' . $limit . '" data-initial_rows_map="input_' . $form_id . '_' . $this->repeater_initial_rows_map . '" data-map_id="field_' . $form_id . '_' . $id . '">
151 - <div class="repeater-field-warp-item">
152 - </div>
153 - <div class="repeater-field-footer"><a href="#"" class="gf-repeater-field-button-add" >' . $repeater_add_button . '</a></div>
154 - ' . $input . '
155 - <input type="hidden" class="gf-field-repeater-data-html hidden" />
156 - </div>';
157 - if (is_admin()) {
158 - $html = '<hr>End Repeater<hr>';
159 - return sprintf("<div class='ginput_container1'>%s</div>", $html);
160 - } else {
161 - return sprintf("<div class='ginput_container'>%s</div>", $html);
162 - }
163 - }
164 - public static function remove_validation($form)
165 - {
166 - $zo = false;
167 - $zo_datas = array();
168 - foreach ($form["fields"] as $field) {
169 - $type = $field->type;
170 - if ($type == "repeater_start") {
171 - $zo = true;
172 - continue;
173 - }
174 - if ($type == "repeater_end") {
175 - $zo = false;
176 - continue;
177 - }
178 - if ($zo) {
179 - if (!isset($field->repeater_validate)) {
180 - $field->repeater_validate = array("isRequired" => $field->isRequired);
181 - }
182 - $field->isRequired = false;
183 - $field->validateState = false;
184 - }
185 - }
186 - return $form;
187 - }
188 - function validate($value, $form)
189 - {
190 - $datas = json_decode($value, true);
191 - $list_fields_validate = array();
192 - $failedValidation = false;
193 - foreach ($form["fields"] as $field) {
194 - if (is_array($field->repeater_validate)) {
195 - foreach ($field->repeater_validate as $k => $v) {
196 - if ($k == "isRequired" && $v == true) {
197 - $list_fields_validate["input_" . $field->id] = $field->type;
198 - }
199 - }
200 - }
201 - }
202 - if (isset($datas["id"]) && is_array($datas["id"])) {
203 - // Check if file upload is attempted without the Pro version activated
204 - if (!class_exists('Yeeaddons_Upgrade_GF_Repeater_Plugin')) {
205 - $is_fileupload_attempt = false;
206 - foreach ($datas["id"] as $id) {
207 - foreach ($datas["fields"] as $field) {
208 - if ($field == "") {
209 - continue;
210 - }
211 - $field = str_replace('[]', '', $field);
212 - $input_name = $field . "__" . $id;
213 - // Standard file upload
214 - if (isset($_FILES[$input_name]) && !empty($_FILES[$input_name]['name']) && (is_array($_FILES[$input_name]['name']) ? !empty(array_filter($_FILES[$input_name]['name'])) : true)) {
215 - $is_fileupload_attempt = true;
216 - break 2;
217 - }
218 - // Multi-file upload (Ajax/plupload)
219 - if (strpos($field, 'gform_multifile_upload_') === 0 && !empty($_POST[$input_name])) {
220 - $is_fileupload_attempt = true;
221 - break 2;
222 - }
223 - }
224 - }
225 - if ($is_fileupload_attempt) {
226 - $this->failed_validation = true;
227 - $this->validation_message = esc_html__('File upload in repeater is only supported in the Pro version.', 'repeater-for-gravity-forms');
228 - return;
229 - }
230 - }
231 -
232 - foreach ($datas["id"] as $id) {
233 - foreach ($datas["fields"] as $field) {
234 - if ($field == "") {
235 - continue;
236 - }
237 - $field = str_replace('[]', '', $field);
238 - if (isset($list_fields_validate[$field])) {
239 - $getInputData = rgpost($field . "__" . $id);
240 - switch ($list_fields_validate[$field]) {
241 - case "name":
242 - $first_name = rgpost($field . "_3__" . $id);
243 - $last_name = rgpost($field . "_6__" . $id);
244 - if (empty($first_name) || empty($last_name)) {
245 - $failedValidation = true;
246 - }
247 - break;
248 - case 'address':
249 - $address = rgpost($field . "_1__" . $id);
250 - if (empty($address)) {
251 - $failedValidation = true;
252 - }
253 - break;
254 - case 'fileupload':
255 - if (isset($_FILES[$field . "__" . $id]) && $_FILES[$field . "__" . $id]['name'][0]) {
256 - //file uploaded
257 - } else {
258 - $failedValidation = true;
259 - }
260 - break;
261 - default:
262 - if (is_array($getInputData)) {
263 - foreach ($getInputData as $vl) {
264 - if (empty($vl)) {
265 - $failedValidation = true;
266 - }
267 - }
268 - } else {
269 - if (empty($getInputData)) {
270 - $failedValidation = true;
271 - }
272 - }
273 - break;
274 - }
275 - }
276 - }
277 - }
278 - if ($failedValidation) {
279 - $this->failed_validation = true;
280 - if ($this->errorMessage) {
281 - $this->validation_message = $this->errorMessage;
282 - } else {
283 - $this->validation_message = esc_html__('This field is required.', 'gravityforms');
284 - }
285 - return;
286 - } else {
287 - $this->failed_validation = false;
288 - }
289 - }
290 - }
291 - function custom_validation($form)
292 - {
293 - $dataRepeater = array();
294 - $zo = false;
295 - $zo_datas = array();
296 - foreach ($form["fields"] as $field) {
297 - $type = $field->type;
298 - if ($type == "repeater_start") {
299 - $zo = true;
300 - continue;
301 - }
302 - if ($zo) {
303 - $zo_datas[$field->id] = array("isRequired" => $field->isRequired);
304 - $field->isRequired = false;
305 - }
306 - if ($type == "repeater_end") {
307 - $zo = false;
308 - $zo_datas = array();
309 - continue;
310 - }
311 - }
312 - return $form;
313 - }
314 - /**
315 - * Gets the value of the submitted field.
316 - *
317 - * @since Unknown
318 - * @access public
319 - *
320 - * @used-by GFFormsModel::get_field_value()
321 - * @uses GF_Field::get_value_submission()
322 - * @uses GF_Field_Phone::sanitize_entry_value()
323 - *
324 - * @param array $field_values The dynamic population parameter names with their corresponding values to be populated.
325 - * @param bool $get_from_post_global_var Whether to get the value from the $_POST array as opposed to $field_values. Defaults to true.
326 - *
327 - * @return array|string
328 - */
329 - public function get_value_submission($field_values, $get_from_post_global_var = true)
330 - {
331 - $value = parent::get_value_submission($field_values, $get_from_post_global_var);
332 - $value = $this->sanitize_entry_value($value, $this->formId);
333 - return $value;
334 - }
335 - /**
336 - * Sanitizes the entry value.
337 - *
338 - * @since Unknown
339 - * @access public
340 - *
341 - * @used-by GF_Field_Phone::get_value_save_entry()
342 - * @used-by GF_Field_Phone::get_value_submission()
343 - *
344 - * @param string $value The value to be sanitized.
345 - * @param int $form_id The form ID of the submitted item.
346 - *
347 - * @return string The sanitized value.
348 - */
349 - public function sanitize_entry_value($value, $form_id)
350 - {
351 - $value = is_array($value) ? array_map('sanitize_text_field', $value) : sanitize_text_field($value);
352 - return $value;
353 - }
354 - /**
355 - * Gets the field value when an entry is being saved.
356 - *
357 - * @since Unknown
358 - * @access public
359 - *
360 - * @used-by GFFormsModel::prepare_value()
361 - * @uses GF_Field_Phone::sanitize_entry_value()
362 - * @uses GF_Field_Phone::$phoneFormat
363 - *
364 - * @param string $value The input value.
365 - * @param array $form The Form Object.
366 - * @param string $input_name The input name.
367 - * @param int $lead_id The Entry ID.
368 - * @param array $lead The Entry Object.
369 - *
370 - * @return string The field value.
371 - */
372 - public function get_value_save_entry($value, $form, $input_name, $lead_id, $lead)
373 - {
374 - $this->lead_id = $lead_id;
375 - $datas = json_decode($value, true);
376 -
377 - $values = array();
378 - $form_id = $this->formId;
379 - $get_form = GFFormsModel::get_form_meta_by_id($form_id);
380 - $form = $get_form[0];
381 - $fields = array();
382 - foreach ($datas["fields"] as $f) {
383 - $datas_f = explode(".", $f);
384 - $fields[] = $datas_f[0];
385 - }
386 - $fields = array_unique($fields);
387 - foreach ($datas["id"] as $id_rand) {
388 - $datas_step = array();
389 - foreach ($fields as $field) {
390 - $field = str_replace("[]", "", $field);
391 - $inputs = $this->get_inputs($form, $field);
392 - if (is_array($inputs)) {
393 - $getInputData = array();
394 - foreach ($inputs as $child_input) {
395 - $getInputName = "input_" . $child_input["id"] . "__" . $id_rand;
396 - $vl = rgpost(str_replace('.', '_', strval($getInputName)));
397 - if ($vl != "") {
398 - $getInputData[$child_input["id"]] = $vl;
399 - }
400 - }
401 - $datas_step[$getInputName] = $getInputData;
402 - } else {
403 - $getInputName = $field . "__" . $id_rand;
404 - $saved_url = '';
405 -
406 - // 1. Check transient saved across multi-step pages by gform_unique_id or form_id
407 - $unique_id = rgpost('gform_unique_id');
408 - $transient_keys = array();
409 - if (!empty($unique_id)) {
410 - $transient_keys[] = 'gf_repeater_files_' . $unique_id;
411 - }
412 - $transient_keys[] = 'gf_repeater_files_' . $form_id;
413 - $transient_keys[] = 'gf_repeater_files_1';
414 -
415 - foreach ($transient_keys as $t_key) {
416 - $transient_files = get_transient($t_key);
417 - if (is_array($transient_files)) {
418 - if (!empty($transient_files[$getInputName])) {
419 - $saved_url = $transient_files[$getInputName];
420 - break;
421 - }
422 - // Also check alternative key name format
423 - foreach ($transient_files as $tk => $tv) {
424 - if (strpos($tk, '__' . $id_rand) !== false && !empty($tv)) {
425 - $clean_f = str_replace('gform_multifile_upload_' . $form_id . '_', '', $field);
426 - $clean_f = str_replace('input_', '', $clean_f);
427 - if (strpos($tk, '_' . $clean_f . '__') !== false || strpos($tk, 'input_' . $clean_f . '__') !== false) {
428 - $saved_url = $tv;
429 - break 2;
430 - }
431 - }
432 - }
433 - }
434 - }
435 -
436 -
437 - // 2. Check if $_POST contains a direct URL
438 - if (empty($saved_url)) {
439 - $post_val = rgpost(str_replace('.', '_', strval($getInputName)));
440 - if (!empty($post_val) && is_string($post_val) && strpos($post_val, 'http') === 0) {
441 - $saved_url = $post_val;
442 - }
443 - }
444 -
445 - // 3. Check gform_uploaded_files (GF native temp file store)
446 - if (empty($saved_url)) {
447 - $uploaded_files_json = rgpost('gform_uploaded_files');
448 - if (!empty($uploaded_files_json)) {
449 - $uploaded_files = json_decode(stripslashes($uploaded_files_json), true);
450 - if (is_array($uploaded_files) && isset($uploaded_files[$getInputName])) {
451 - $file_info = $uploaded_files[$getInputName];
452 - if (is_string($file_info) && strpos($file_info, 'http') === 0) {
453 - $saved_url = $file_info;
454 - }
455 - }
456 - }
457 - }
458 -
459 - // 4. Check $_FILES if uploaded on the current submit step
460 - if (empty($saved_url) && isset($_FILES[$getInputName]) && !empty($_FILES[$getInputName]['name']) && (is_array($_FILES[$getInputName]['name']) ? !empty(array_filter($_FILES[$getInputName]['name'])) : ($_FILES[$getInputName]['error'] === UPLOAD_ERR_OK))) {
461 - $res = apply_filters("yeeaddons_gf_repeater_file", "", $form_id, $_FILES[$getInputName]);
462 - if ($res && $res !== "Upgrade to pro version") {
463 - $saved_url = $res;
464 - }
465 - }
466 -
467 - // 5. Fallback to $_POST value if available
468 - if (empty($saved_url)) {
469 - $saved_url = rgpost(str_replace('.', '_', strval($getInputName)));
470 - }
471 -
472 - $datas_step[$getInputName] = $saved_url;
473 - }
474 - }
475 - $values[$id_rand] = $datas_step;
476 - }
477 - return maybe_serialize($values);
478 - }
479 - public function upload_file($form_id, $file)
480 - {
481 - $target = GFFormsModel::get_file_upload_path($form_id, $file['name']);
482 - if (!$target) {
483 - return 'FAILED (Upload folder could not be created.)';
484 - }
485 - if (move_uploaded_file($file['tmp_name'], $target['path'])) {
486 - $this->set_permissions($target['path']);
487 - return $target['url'];
488 - } else {
489 - return 'FAILED (Temporary file could not be copied.)';
490 - }
491 - }
492 - function set_permissions($path)
493 - {
494 - GFFormsModel::set_permissions($path);
495 - }
496 - public function get_value_entry_list($value, $entry, $field_id, $columns, $form)
497 - {
498 - if (empty($value)) {
499 - return '';
500 - } else {
501 - $dataArray = GFFormsModel::unserialize($value);
502 - $arrayCount = count($dataArray);
503 - if ($arrayCount > 1) {
504 - $returnText = $arrayCount . ' entries';
505 - } else {
506 - $returnText = $arrayCount . ' entry';
507 - }
508 - return $returnText;
509 - }
510 - }
511 - function get_datas_field($format = "html", $value = '', $form_id = "")
512 - {
513 - global $wpdb;
514 - $dataArray = GFFormsModel::unserialize($value);
515 - $get_form = GFFormsModel::get_form_meta_by_id($form_id);
516 - $form = $get_form[0];
517 - if (isset($_GET['lid'])) {
518 - $result = GFAPI::get_entry($_GET['lid']);
519 - } else {
520 - $table = $wpdb->prefix . "gf_entry";
521 - $mylink = $wpdb->get_row("SELECT id FROM $table ORDER BY id DESC");
522 - $result = GFAPI::get_entry($mylink->id);
523 - }
524 - //var_dump($dataArray);
525 - if ($format === 'html') {
526 - $html = '<ol>';
527 - foreach ($dataArray as $step_datas) {
528 - $html .= '<li><ul>';
529 - foreach ($step_datas as $name => $vl) {
530 - $type = $this->get_type($form, $name, $form_id);
531 - $lb = $this->get_custom_field_label($form, $name, $type, false, $form_id);
532 - if (is_array($vl)) {
533 - switch ($type) {
534 - case "address":
535 - $vl_data = "";
536 - foreach ($vl as $k => $v) {
537 - $child_lb = $this->get_custom_field_label($form, "input_" . $k, $type, true);
538 - $vl_data .= $child_lb . ": " . $v . "<br>";
539 - }
540 - $html .= '<li>' . $lb . ": <br>" . $vl_data . "</li>";
541 - break;
542 - default:
543 - $vl_data = implode(", ", $vl);
544 - $html .= '<li>' . $lb . ": " . $vl_data . "</li>";
545 - break;
546 - }
547 - } else {
548 - $vl_data = $vl;
549 -
550 - switch ($type) {
551 - case "fileupload":
552 - if ($vl_data === "Upgrade to pro version") {
553 - $html .= '<li>' . esc_html($lb) . ": " . esc_html($vl_data) . "</li>";
554 - break;
555 - }
556 -
557 - // Hàm helper nhỏ để encode Unicode URL an toàn
558 - $encode_url = function ($url) {
559 - return preg_replace_callback('/[^\x20-\x7E]/u', function ($match) {
560 - return rawurlencode($match[0]);
561 - }, trim($url));
562 - };
563 -
564 - // Hàm kiểm tra URL hợp lệ (chấp nhận cả ký tự Unicode)
565 - $is_valid_url = function ($url) use ($encode_url) {
566 - if (empty($url))
567 - return false;
568 - $encoded = $encode_url($url);
569 - return filter_var($encoded, FILTER_VALIDATE_URL) !== false;
570 - };
571 -
572 - // Tách chuỗi theo dấu phẩy phòng trường hợp có nhiều file
573 - $parts = array_filter(array_map('trim', explode(",", $vl_data)));
574 - $content = array();
575 -
576 - // TRƯỜNG HỢP 1: Tất cả các phần tử đều là URL hợp lệ
577 - $all_are_urls = !empty($parts);
578 - foreach ($parts as $part) {
579 - if (!$is_valid_url($part)) {
580 - $all_are_urls = false;
581 - break;
582 - }
583 - }
584 -
585 - if ($all_are_urls) {
586 - foreach ($parts as $part) {
587 - $filename = basename($part);
588 - // Dùng esc_url() của WP để tự động encode và bảo mật output
589 - $content[] = '<a href="' . esc_url($part) . '" download>' . esc_html($filename) . '</a>';
590 - }
591 - $html .= '<li>' . esc_html($lb) . ': ' . implode(" | ", $content) . "</li>";
592 - break;
593 - }
594 -
595 - // TRƯỜNG HỢP 2: Chuỗi chứa tên file hoặc URL không hợp lệ -> Tìm trong $result
596 - $main_name = explode("__", $name);
597 - $main_name = explode("_", $main_name[0]);
598 - $main_name_id = isset($main_name[4]) ? $main_name[4] : (isset($main_name[1]) ? $main_name[1] : null);
599 -
600 - if ($main_name_id && isset($result[$main_name_id])) {
601 - $raw_uploads = $result[$main_name_id];
602 - $data_uploads = is_array($raw_uploads) ? $raw_uploads : json_decode($raw_uploads, true);
603 -
604 - if (!is_array($data_uploads)) {
605 - $data_uploads = array_filter(array_map('trim', explode(",", (string) $raw_uploads)));
606 - }
607 -
608 - foreach ($parts as $n) {
609 - $clean_n = sanitize_file_name($n);
610 - $name_s = preg_quote(pathinfo($clean_n, PATHINFO_FILENAME), '/');
611 -
612 - foreach ($data_uploads as $upload_file) {
613 - // Regex khớp chính xác tên file gốc hoặc tên file có đánh số thứ tự
614 - if (preg_match('/' . $name_s . '(\d+)?\./i', $upload_file)) {
615 - $content[] = '<a href="' . esc_url($upload_file) . '" download>' . esc_html($clean_n) . '</a>';
616 - break;
617 - }
618 - }
619 - }
620 - }
621 -
622 - $html .= '<li>' . esc_html($lb) . ': ' . (!empty($content) ? implode(" | ", $content) : esc_html($vl_data)) . "</li>";
623 - break;
624 -
625 - default:
626 - $html .= '<li>' . esc_html($lb) . ": " . esc_html($vl_data) . "</li>";
627 - break;
628 - }
629 - }
630 - }
631 - $html .= '</ul></li>';
632 - }
633 - $html .= '<ol>';
634 - $html = apply_filters("yeeadons_gravity_forms_repeater_html", $html, $dataArray, $form);
635 - return $html;
636 - } else {
637 - $html = '';
638 - foreach ($dataArray as $step_datas) {
639 - foreach ($step_datas as $name => $vl) {
640 - $type = $this->get_type($form, $name, $form_id);
641 - $lb = $this->get_custom_field_label($form, $name, $type, false, $form_id);
642 - if (is_array($vl)) {
643 - switch ($type) {
644 - case "address":
645 - $vl_data = "";
646 - foreach ($vl as $k => $v) {
647 - $child_lb = $this->get_custom_field_label($form, "input_" . $k, $type, true);
648 - $vl_data .= $child_lb . ": " . $v . "\n";
649 - }
650 - $html .= $lb . " : " . $vl_data . "\n";
651 - break;
652 - default:
653 - $vl_data = implode(", ", $vl);
654 - $html .= $lb . ": " . $vl_data . "\n";
655 - break;
656 - }
657 - } else {
658 - $vl_data = $vl;
659 - switch ($type) {
660 - case "fileupload":
661 - if (filter_var($vl_data, FILTER_VALIDATE_URL) === FALSE) {
662 - $content = array();
663 - $parts = array_map('trim', explode(",", $vl_data));
664 - $is_urls = true;
665 - foreach ($parts as $part) {
666 - if (empty($part) || filter_var($part, FILTER_VALIDATE_URL) === FALSE) {
667 - $is_urls = false;
668 - break;
669 - }
670 - }
671 - if ($is_urls) {
672 - foreach ($parts as $part) {
673 - $filename = basename($part);
674 - $content[] = '<a href="' . esc_url($part) . '" download>' . esc_html($filename) . '</a>';
675 - }
676 - $html .= $lb . ': ' . implode(" | ", $content) . "\n";
677 - } else {
678 - $main_name = explode("__", $name);
679 - $main_name = explode("_", $main_name[0]);
680 - $main_name_id = $main_name[4];
681 - if (isset($result[$main_name_id])) {
682 - $data_uploads = json_decode($result[$main_name_id], true);
683 - foreach ($parts as $n) {
684 - $n = sanitize_file_name($n);
685 - foreach ($data_uploads as $name) {
686 - $name_s = explode(".", $n);
687 - $name_s = $name_s[0];
688 - $re = "/" . $name_s . "\.|" . $name_s . "[\d]\./";
689 - if (preg_match($re, $name)) {
690 - $content[] = '<a href="' . $name . '" download>' . $n . "</a> ";
691 - break;
692 - }
693 - }
694 - }
695 - }
696 - $html .= $lb . ': ' . implode(" | ", $content) . "\n";
697 - }
698 - } else {
699 - $html .= $lb . ':' . $vl_data . "\n";
700 - }
701 - break;
702 - default:
703 - $html .= $lb . ": " . $vl_data . "\n";
704 - break;
705 - }
706 - }
707 - }
708 - $html .= "\n";
709 - }
710 - $html = apply_filters("yeeadons_gravity_forms_repeater_text", $html, $dataArray, $form);
711 - return $html;
712 - }
713 - }
714 - public function get_value_export($entry, $input_id = '', $use_text = false, $is_csv = false)
715 - {
716 - //Export doesn’t require encoding, but field data may require some manipulation or formatting before it is exported
717 - $form_id = $entry["form_id"];
718 - $return = $this->get_datas_field("text", rgar($entry, $input_id), $form_id);
719 - return $return;
720 - }
721 - public function get_value_merge_tag($value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br)
722 - {
723 - if (empty($value)) {
724 - return '';
725 - }
726 - $form_id = isset($form['id']) ? absint($form['id']) : null;
727 - $return = $this->get_datas_field($format, $value, $form_id);
728 - return $return;
729 - }
730 - public function get_value_entry_detail($value, $currency = '', $use_text = false, $format = 'html', $media = 'screen')
731 - {
732 - global $wpdb;
733 - if (empty($value)) {
734 - return '';
735 - } else {
736 - $form_id = $this->formId;
737 - $return = $this->get_datas_field($format, $value, $form_id);
738 - return $return;
739 - }
740 - }
741 - function get_custom_field_label($form, $name = '', $type = '', $child = false, $form_id = '')
742 - {
743 - if (is_array($form)) {
744 - if (!array_key_exists('fields', $form)) {
745 - return false;
746 - }
747 - } else {
748 - return false;
749 - }
750 - $name = str_replace("gform_multifile_upload_" . $form_id, "input", $name);
751 - $names = explode("__", $name);
752 - $names = explode("_", $names[0]);
753 - $name = $names[1];
754 - foreach ($form['fields'] as $field_key => $field_value) {
755 - if (is_array($field_value->inputs)) {
756 - foreach ($field_value->inputs as $children_id) {
757 - if ($children_id["id"] == $name) {
758 - if ($child) {
759 - return $children_id["label"];
760 - } else {
761 - return $field_value->label;
762 - }
763 - }
764 - }
765 - } else {
766 - if ($field_value->id == $name) {
767 - return $field_value->label;
768 - }
769 - }
770 - }
771 - return "";
772 - }
773 - function get_inputs($form, $name = '')
774 - {
775 - if (is_array($form)) {
776 - if (!array_key_exists('fields', $form)) {
777 - return false;
778 - }
779 - } else {
780 - return false;
781 - }
782 - $names = explode("__", $name);
783 - $names = explode("_", $names[0]);
784 - $name = $names[1];
785 - foreach ($form['fields'] as $field_key => $field_value) {
786 - if ($field_value->id == $name) {
787 - if ($field_value->type == "date") {
788 - return $name;
789 - }
790 - if (is_array($field_value->inputs)) {
791 - return $field_value->inputs;
792 - }
793 - }
794 - }
795 - return false;
796 - }
797 - function get_type($form, $name = '', $form_id = "")
798 - {
799 - if (is_array($form)) {
800 - if (!array_key_exists('fields', $form)) {
801 - return false;
802 - }
803 - } else {
804 - return false;
805 - }
806 - $name = str_replace("gform_multifile_upload_" . $form_id, "input", $name);
807 - $names = explode("__", $name);
808 - $names = explode("_", $names[0]);
809 - $name = $names[1];
810 - foreach ($form['fields'] as $field_key => $field_value) {
811 - if (is_array($field_value->inputs)) {
812 - foreach ($field_value->inputs as $children_id) {
813 - if ($children_id["id"] == $name) {
814 - return $field_value->type;
815 - }
816 - }
817 - } else {
818 - if ($field_value->id == $name) {
819 - return $field_value->type;
820 - }
821 - }
822 - }
823 - return "";
824 - }
825 -
826 - public static function remove_child_fields($form)
827 - {
828 - if (!is_admin()) {
829 - return $form;
830 - }
831 -
832 - $page = isset($_GET['page']) ? $_GET['page'] : '';
833 - $gf_page = isset($_GET['gf_page']) ? $_GET['gf_page'] : '';
834 -
835 - $target_pages = array('gf_entries', 'gf_export');
836 - $target_gf_pages = array('select_columns', 'print-entry');
837 -
838 - if (in_array($page, $target_pages) || in_array($gf_page, $target_gf_pages)) {
839 - $fields = array();
840 - $zo = false;
841 - foreach ($form["fields"] as $field) {
842 - $type = $field->type;
843 - if ($type == "repeater_start") {
844 - $zo = true;
845 - $fields[] = $field;
846 - continue;
847 - }
848 - if ($type == "repeater_end") {
849 - $zo = false;
850 - $fields[] = $field;
851 - continue;
852 - }
853 - if ($zo) {
854 - continue;
855 - }
856 - $fields[] = $field;
857 - }
858 - $form["fields"] = $fields;
859 - }
860 -
861 - return $form;
862 - }
863 -}
864 -// Register the phone field with the field framework.
865 -GF_Fields::register(new Superaddons_GFRepeater_Field());