PluginProbe
Repeater Fields for Gravity Forms / 3.0.2
Repeater Fields for Gravity Forms v3.0.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
repeater-for-gravity-forms / fields / repeater_field.php

repeater_field.php in Repeater Fields for Gravity Forms 3.0.2, at fields/repeater_field.php

865 lines 27.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 }
184 }
185 return $form;
186 }
187 function validate($value, $form)
188 {
189 $datas = json_decode($value, true);
190 $list_fields_validate = array();
191 $failedValidation = false;
192 foreach ($form["fields"] as $field) {
193 if (is_array($field->repeater_validate)) {
194 foreach ($field->repeater_validate as $k => $v) {
195 if ($k == "isRequired" && $v == true) {
196 $list_fields_validate["input_" . $field->id] = $field->type;
197 }
198 }
199 }
200 }
201 if (isset($datas["id"]) && is_array($datas["id"])) {
202 // Check if file upload is attempted without the Pro version activated
203 if (!class_exists('Yeeaddons_Upgrade_GF_Repeater_Plugin')) {
204 $is_fileupload_attempt = false;
205 foreach ($datas["id"] as $id) {
206 foreach ($datas["fields"] as $field) {
207 if ($field == "") {
208 continue;
209 }
210 $field = str_replace('[]', '', $field);
211 $input_name = $field . "__" . $id;
212 // Standard file upload
213 if (isset($_FILES[$input_name]) && !empty($_FILES[$input_name]['name']) && (is_array($_FILES[$input_name]['name']) ? !empty(array_filter($_FILES[$input_name]['name'])) : true)) {
214 $is_fileupload_attempt = true;
215 break 2;
216 }
217 // Multi-file upload (Ajax/plupload)
218 if (strpos($field, 'gform_multifile_upload_') === 0 && !empty($_POST[$input_name])) {
219 $is_fileupload_attempt = true;
220 break 2;
221 }
222 }
223 }
224 if ($is_fileupload_attempt) {
225 $this->failed_validation = true;
226 $this->validation_message = esc_html__('File upload in repeater is only supported in the Pro version.', 'repeater-for-gravity-forms');
227 return;
228 }
229 }
230
231 foreach ($datas["id"] as $id) {
232 foreach ($datas["fields"] as $field) {
233 if ($field == "") {
234 continue;
235 }
236 $field = str_replace('[]', '', $field);
237 if (isset($list_fields_validate[$field])) {
238 $getInputData = rgpost($field . "__" . $id);
239 switch ($list_fields_validate[$field]) {
240 case "name":
241 $first_name = rgpost($field . "_3__" . $id);
242 $last_name = rgpost($field . "_6__" . $id);
243 if (empty($first_name) || empty($last_name)) {
244 $failedValidation = true;
245 }
246 break;
247 case 'address':
248 $address = rgpost($field . "_1__" . $id);
249 if (empty($address)) {
250 $failedValidation = true;
251 }
252 break;
253 case 'fileupload':
254 if (isset($_FILES[$field . "__" . $id]) && $_FILES[$field . "__" . $id]['name'][0]) {
255 //file uploaded
256 } else {
257 $failedValidation = true;
258 }
259 break;
260 default:
261 if (is_array($getInputData)) {
262 foreach ($getInputData as $vl) {
263 if (empty($vl)) {
264 $failedValidation = true;
265 }
266 }
267 } else {
268 if (empty($getInputData)) {
269 $failedValidation = true;
270 }
271 }
272 break;
273 }
274 }
275 }
276 }
277 if ($failedValidation) {
278 $this->failed_validation = true;
279 if ($this->errorMessage) {
280 $this->validation_message = $this->errorMessage;
281 } else {
282 $this->validation_message = esc_html__('This field is required.', 'gravityforms');
283 }
284 return;
285 } else {
286 $this->failed_validation = false;
287 }
288 }
289 }
290 function custom_validation($form)
291 {
292 $dataRepeater = array();
293 $zo = false;
294 $zo_datas = array();
295 foreach ($form["fields"] as $field) {
296 $type = $field->type;
297 if ($type == "repeater_start") {
298 $zo = true;
299 continue;
300 }
301 if ($zo) {
302 $zo_datas[$field->id] = array("isRequired" => $field->isRequired);
303 $field->isRequired = false;
304 }
305 if ($type == "repeater_end") {
306 $zo = false;
307 $zo_datas = array();
308 continue;
309 }
310 }
311 return $form;
312 }
313 /**
314 * Gets the value of the submitted field.
315 *
316 * @since Unknown
317 * @access public
318 *
319 * @used-by GFFormsModel::get_field_value()
320 * @uses GF_Field::get_value_submission()
321 * @uses GF_Field_Phone::sanitize_entry_value()
322 *
323 * @param array $field_values The dynamic population parameter names with their corresponding values to be populated.
324 * @param bool $get_from_post_global_var Whether to get the value from the $_POST array as opposed to $field_values. Defaults to true.
325 *
326 * @return array|string
327 */
328 public function get_value_submission($field_values, $get_from_post_global_var = true)
329 {
330 $value = parent::get_value_submission($field_values, $get_from_post_global_var);
331 $value = $this->sanitize_entry_value($value, $this->formId);
332 return $value;
333 }
334 /**
335 * Sanitizes the entry value.
336 *
337 * @since Unknown
338 * @access public
339 *
340 * @used-by GF_Field_Phone::get_value_save_entry()
341 * @used-by GF_Field_Phone::get_value_submission()
342 *
343 * @param string $value The value to be sanitized.
344 * @param int $form_id The form ID of the submitted item.
345 *
346 * @return string The sanitized value.
347 */
348 public function sanitize_entry_value($value, $form_id)
349 {
350 $value = is_array($value) ? array_map('sanitize_text_field', $value) : sanitize_text_field($value);
351 return $value;
352 }
353 /**
354 * Gets the field value when an entry is being saved.
355 *
356 * @since Unknown
357 * @access public
358 *
359 * @used-by GFFormsModel::prepare_value()
360 * @uses GF_Field_Phone::sanitize_entry_value()
361 * @uses GF_Field_Phone::$phoneFormat
362 *
363 * @param string $value The input value.
364 * @param array $form The Form Object.
365 * @param string $input_name The input name.
366 * @param int $lead_id The Entry ID.
367 * @param array $lead The Entry Object.
368 *
369 * @return string The field value.
370 */
371 public function get_value_save_entry($value, $form, $input_name, $lead_id, $lead)
372 {
373 $this->lead_id = $lead_id;
374 $datas = json_decode($value, true);
375
376 $values = array();
377 $form_id = $this->formId;
378 $get_form = GFFormsModel::get_form_meta_by_id($form_id);
379 $form = $get_form[0];
380 $fields = array();
381 foreach ($datas["fields"] as $f) {
382 $datas_f = explode(".", $f);
383 $fields[] = $datas_f[0];
384 }
385 $fields = array_unique($fields);
386 foreach ($datas["id"] as $id_rand) {
387 $datas_step = array();
388 foreach ($fields as $field) {
389 $field = str_replace("[]", "", $field);
390 $inputs = $this->get_inputs($form, $field);
391 if (is_array($inputs)) {
392 $getInputData = array();
393 foreach ($inputs as $child_input) {
394 $getInputName = "input_" . $child_input["id"] . "__" . $id_rand;
395 $vl = rgpost(str_replace('.', '_', strval($getInputName)));
396 if ($vl != "") {
397 $getInputData[$child_input["id"]] = $vl;
398 }
399 }
400 $datas_step[$getInputName] = $getInputData;
401 } else {
402 $getInputName = $field . "__" . $id_rand;
403 $saved_url = '';
404
405 // 1. Check transient saved across multi-step pages by gform_unique_id or form_id
406 $unique_id = rgpost('gform_unique_id');
407 $transient_keys = array();
408 if (!empty($unique_id)) {
409 $transient_keys[] = 'gf_repeater_files_' . $unique_id;
410 }
411 $transient_keys[] = 'gf_repeater_files_' . $form_id;
412 $transient_keys[] = 'gf_repeater_files_1';
413
414 foreach ($transient_keys as $t_key) {
415 $transient_files = get_transient($t_key);
416 if (is_array($transient_files)) {
417 if (!empty($transient_files[$getInputName])) {
418 $saved_url = $transient_files[$getInputName];
419 break;
420 }
421 // Also check alternative key name format
422 foreach ($transient_files as $tk => $tv) {
423 if (strpos($tk, '__' . $id_rand) !== false && !empty($tv)) {
424 $clean_f = str_replace('gform_multifile_upload_' . $form_id . '_', '', $field);
425 $clean_f = str_replace('input_', '', $clean_f);
426 if (strpos($tk, '_' . $clean_f . '__') !== false || strpos($tk, 'input_' . $clean_f . '__') !== false) {
427 $saved_url = $tv;
428 break 2;
429 }
430 }
431 }
432 }
433 }
434
435
436 // 2. Check if $_POST contains a direct URL
437 if (empty($saved_url)) {
438 $post_val = rgpost(str_replace('.', '_', strval($getInputName)));
439 if (!empty($post_val) && is_string($post_val) && strpos($post_val, 'http') === 0) {
440 $saved_url = $post_val;
441 }
442 }
443
444 // 3. Check gform_uploaded_files (GF native temp file store)
445 if (empty($saved_url)) {
446 $uploaded_files_json = rgpost('gform_uploaded_files');
447 if (!empty($uploaded_files_json)) {
448 $uploaded_files = json_decode(stripslashes($uploaded_files_json), true);
449 if (is_array($uploaded_files) && isset($uploaded_files[$getInputName])) {
450 $file_info = $uploaded_files[$getInputName];
451 if (is_string($file_info) && strpos($file_info, 'http') === 0) {
452 $saved_url = $file_info;
453 }
454 }
455 }
456 }
457
458 // 4. Check $_FILES if uploaded on the current submit step
459 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))) {
460 $res = apply_filters("yeeaddons_gf_repeater_file", "", $form_id, $_FILES[$getInputName]);
461 if ($res && $res !== "Upgrade to pro version") {
462 $saved_url = $res;
463 }
464 }
465
466 // 5. Fallback to $_POST value if available
467 if (empty($saved_url)) {
468 $saved_url = rgpost(str_replace('.', '_', strval($getInputName)));
469 }
470
471 $datas_step[$getInputName] = $saved_url;
472 }
473 }
474 $values[$id_rand] = $datas_step;
475 }
476 return maybe_serialize($values);
477 }
478 public function upload_file($form_id, $file)
479 {
480 $target = GFFormsModel::get_file_upload_path($form_id, $file['name']);
481 if (!$target) {
482 return 'FAILED (Upload folder could not be created.)';
483 }
484 if (move_uploaded_file($file['tmp_name'], $target['path'])) {
485 $this->set_permissions($target['path']);
486 return $target['url'];
487 } else {
488 return 'FAILED (Temporary file could not be copied.)';
489 }
490 }
491 function set_permissions($path)
492 {
493 GFFormsModel::set_permissions($path);
494 }
495 public function get_value_entry_list($value, $entry, $field_id, $columns, $form)
496 {
497 if (empty($value)) {
498 return '';
499 } else {
500 $dataArray = GFFormsModel::unserialize($value);
501 $arrayCount = count($dataArray);
502 if ($arrayCount > 1) {
503 $returnText = $arrayCount . ' entries';
504 } else {
505 $returnText = $arrayCount . ' entry';
506 }
507 return $returnText;
508 }
509 }
510 function get_datas_field($format = "html", $value = '', $form_id = "")
511 {
512 global $wpdb;
513 $dataArray = GFFormsModel::unserialize($value);
514 $get_form = GFFormsModel::get_form_meta_by_id($form_id);
515 $form = $get_form[0];
516 if (isset($_GET['lid'])) {
517 $result = GFAPI::get_entry($_GET['lid']);
518 } else {
519 $table = $wpdb->prefix . "gf_entry";
520 $mylink = $wpdb->get_row("SELECT id FROM $table ORDER BY id DESC");
521 $result = GFAPI::get_entry($mylink->id);
522 }
523 //var_dump($dataArray);
524 if ($format === 'html') {
525 $html = '<ol>';
526 foreach ($dataArray as $step_datas) {
527 $html .= '<li><ul>';
528 foreach ($step_datas as $name => $vl) {
529 $type = $this->get_type($form, $name, $form_id);
530 $lb = $this->get_custom_field_label($form, $name, $type, false, $form_id);
531 if (is_array($vl)) {
532 switch ($type) {
533 case "address":
534 $vl_data = "";
535 foreach ($vl as $k => $v) {
536 $child_lb = $this->get_custom_field_label($form, "input_" . $k, $type, true);
537 $vl_data .= $child_lb . ": " . $v . "<br>";
538 }
539 $html .= '<li>' . $lb . ": <br>" . $vl_data . "</li>";
540 break;
541 default:
542 $vl_data = implode(", ", $vl);
543 $html .= '<li>' . $lb . ": " . $vl_data . "</li>";
544 break;
545 }
546 } else {
547 $vl_data = $vl;
548
549 switch ($type) {
550 case "fileupload":
551 if ($vl_data === "Upgrade to pro version") {
552 $html .= '<li>' . esc_html($lb) . ": " . esc_html($vl_data) . "</li>";
553 break;
554 }
555
556 // Hàm helper nhỏ để encode Unicode URL an toàn
557 $encode_url = function ($url) {
558 return preg_replace_callback('/[^\x20-\x7E]/u', function ($match) {
559 return rawurlencode($match[0]);
560 }, trim($url));
561 };
562
563 // Hàm kiểm tra URL hợp lệ (chấp nhận cả ký tự Unicode)
564 $is_valid_url = function ($url) use ($encode_url) {
565 if (empty($url))
566 return false;
567 $encoded = $encode_url($url);
568 return filter_var($encoded, FILTER_VALIDATE_URL) !== false;
569 };
570
571 // Tách chuỗi theo dấu phẩy phòng trường hợp có nhiều file
572 $parts = array_filter(array_map('trim', explode(",", $vl_data)));
573 $content = array();
574
575 // TRƯỜNG HỢP 1: Tất cả các phần tử đều là URL hợp lệ
576 $all_are_urls = !empty($parts);
577 foreach ($parts as $part) {
578 if (!$is_valid_url($part)) {
579 $all_are_urls = false;
580 break;
581 }
582 }
583
584 if ($all_are_urls) {
585 foreach ($parts as $part) {
586 $filename = basename($part);
587 // Dùng esc_url() của WP để tự động encode và bảo mật output
588 $content[] = '<a href="' . esc_url($part) . '" download>' . esc_html($filename) . '</a>';
589 }
590 $html .= '<li>' . esc_html($lb) . ': ' . implode(" | ", $content) . "</li>";
591 break;
592 }
593
594 // TRƯỜNG HỢP 2: Chuỗi chứa tên file hoặc URL không hợp lệ -> Tìm trong $result
595 $main_name = explode("__", $name);
596 $main_name = explode("_", $main_name[0]);
597 $main_name_id = isset($main_name[4]) ? $main_name[4] : (isset($main_name[1]) ? $main_name[1] : null);
598
599 if ($main_name_id && isset($result[$main_name_id])) {
600 $raw_uploads = $result[$main_name_id];
601 $data_uploads = is_array($raw_uploads) ? $raw_uploads : json_decode($raw_uploads, true);
602
603 if (!is_array($data_uploads)) {
604 $data_uploads = array_filter(array_map('trim', explode(",", (string) $raw_uploads)));
605 }
606
607 foreach ($parts as $n) {
608 $clean_n = sanitize_file_name($n);
609 $name_s = preg_quote(pathinfo($clean_n, PATHINFO_FILENAME), '/');
610
611 foreach ($data_uploads as $upload_file) {
612 // Regex khớp chính xác tên file gốc hoặc tên file có đánh số thứ tự
613 if (preg_match('/' . $name_s . '(\d+)?\./i', $upload_file)) {
614 $content[] = '<a href="' . esc_url($upload_file) . '" download>' . esc_html($clean_n) . '</a>';
615 break;
616 }
617 }
618 }
619 }
620
621 $html .= '<li>' . esc_html($lb) . ': ' . (!empty($content) ? implode(" | ", $content) : esc_html($vl_data)) . "</li>";
622 break;
623
624 default:
625 $html .= '<li>' . esc_html($lb) . ": " . esc_html($vl_data) . "</li>";
626 break;
627 }
628 }
629 }
630 $html .= '</ul></li>';
631 }
632 $html .= '<ol>';
633 $html = apply_filters("yeeadons_gravity_forms_repeater_html", $html, $dataArray, $form);
634 return $html;
635 } else {
636 $html = '';
637 foreach ($dataArray as $step_datas) {
638 foreach ($step_datas as $name => $vl) {
639 $type = $this->get_type($form, $name, $form_id);
640 $lb = $this->get_custom_field_label($form, $name, $type, false, $form_id);
641 if (is_array($vl)) {
642 switch ($type) {
643 case "address":
644 $vl_data = "";
645 foreach ($vl as $k => $v) {
646 $child_lb = $this->get_custom_field_label($form, "input_" . $k, $type, true);
647 $vl_data .= $child_lb . ": " . $v . "\n";
648 }
649 $html .= $lb . " : " . $vl_data . "\n";
650 break;
651 default:
652 $vl_data = implode(", ", $vl);
653 $html .= $lb . ": " . $vl_data . "\n";
654 break;
655 }
656 } else {
657 $vl_data = $vl;
658 switch ($type) {
659 case "fileupload":
660 if (filter_var($vl_data, FILTER_VALIDATE_URL) === FALSE) {
661 $content = array();
662 $parts = array_map('trim', explode(",", $vl_data));
663 $is_urls = true;
664 foreach ($parts as $part) {
665 if (empty($part) || filter_var($part, FILTER_VALIDATE_URL) === FALSE) {
666 $is_urls = false;
667 break;
668 }
669 }
670 if ($is_urls) {
671 foreach ($parts as $part) {
672 $filename = basename($part);
673 $content[] = '<a href="' . esc_url($part) . '" download>' . esc_html($filename) . '</a>';
674 }
675 $html .= $lb . ': ' . implode(" | ", $content) . "\n";
676 } else {
677 $main_name = explode("__", $name);
678 $main_name = explode("_", $main_name[0]);
679 $main_name_id = $main_name[4];
680 if (isset($result[$main_name_id])) {
681 $data_uploads = json_decode($result[$main_name_id], true);
682 foreach ($parts as $n) {
683 $n = sanitize_file_name($n);
684 foreach ($data_uploads as $name) {
685 $name_s = explode(".", $n);
686 $name_s = $name_s[0];
687 $re = "/" . $name_s . "\.|" . $name_s . "[\d]\./";
688 if (preg_match($re, $name)) {
689 $content[] = '<a href="' . $name . '" download>' . $n . "</a> ";
690 break;
691 }
692 }
693 }
694 }
695 $html .= $lb . ': ' . implode(" | ", $content) . "\n";
696 }
697 } else {
698 $html .= $lb . ':' . $vl_data . "\n";
699 }
700 break;
701 default:
702 $html .= $lb . ": " . $vl_data . "\n";
703 break;
704 }
705 }
706 }
707 $html .= "\n";
708 }
709 $html = apply_filters("yeeadons_gravity_forms_repeater_text", $html, $dataArray, $form);
710 return $html;
711 }
712 }
713 public function get_value_export($entry, $input_id = '', $use_text = false, $is_csv = false)
714 {
715 //Export doesn’t require encoding, but field data may require some manipulation or formatting before it is exported
716 $form_id = $entry["form_id"];
717 $return = $this->get_datas_field("text", rgar($entry, $input_id), $form_id);
718 return $return;
719 }
720 public function get_value_merge_tag($value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br)
721 {
722 if (empty($value)) {
723 return '';
724 }
725 $form_id = isset($form['id']) ? absint($form['id']) : null;
726 $return = $this->get_datas_field($format, $value, $form_id);
727 return $return;
728 }
729 public function get_value_entry_detail($value, $currency = '', $use_text = false, $format = 'html', $media = 'screen')
730 {
731 global $wpdb;
732 if (empty($value)) {
733 return '';
734 } else {
735 $form_id = $this->formId;
736 $return = $this->get_datas_field($format, $value, $form_id);
737 return $return;
738 }
739 }
740 function get_custom_field_label($form, $name = '', $type = '', $child = false, $form_id = '')
741 {
742 if (is_array($form)) {
743 if (!array_key_exists('fields', $form)) {
744 return false;
745 }
746 } else {
747 return false;
748 }
749 $name = str_replace("gform_multifile_upload_" . $form_id, "input", $name);
750 $names = explode("__", $name);
751 $names = explode("_", $names[0]);
752 $name = $names[1];
753 foreach ($form['fields'] as $field_key => $field_value) {
754 if (is_array($field_value->inputs)) {
755 foreach ($field_value->inputs as $children_id) {
756 if ($children_id["id"] == $name) {
757 if ($child) {
758 return $children_id["label"];
759 } else {
760 return $field_value->label;
761 }
762 }
763 }
764 } else {
765 if ($field_value->id == $name) {
766 return $field_value->label;
767 }
768 }
769 }
770 return "";
771 }
772 function get_inputs($form, $name = '')
773 {
774 if (is_array($form)) {
775 if (!array_key_exists('fields', $form)) {
776 return false;
777 }
778 } else {
779 return false;
780 }
781 $names = explode("__", $name);
782 $names = explode("_", $names[0]);
783 $name = $names[1];
784 foreach ($form['fields'] as $field_key => $field_value) {
785 if ($field_value->id == $name) {
786 if ($field_value->type == "date") {
787 return $name;
788 }
789 if (is_array($field_value->inputs)) {
790 return $field_value->inputs;
791 }
792 }
793 }
794 return false;
795 }
796 function get_type($form, $name = '', $form_id = "")
797 {
798 if (is_array($form)) {
799 if (!array_key_exists('fields', $form)) {
800 return false;
801 }
802 } else {
803 return false;
804 }
805 $name = str_replace("gform_multifile_upload_" . $form_id, "input", $name);
806 $names = explode("__", $name);
807 $names = explode("_", $names[0]);
808 $name = $names[1];
809 foreach ($form['fields'] as $field_key => $field_value) {
810 if (is_array($field_value->inputs)) {
811 foreach ($field_value->inputs as $children_id) {
812 if ($children_id["id"] == $name) {
813 return $field_value->type;
814 }
815 }
816 } else {
817 if ($field_value->id == $name) {
818 return $field_value->type;
819 }
820 }
821 }
822 return "";
823 }
824
825 public static function remove_child_fields($form)
826 {
827 if (!is_admin()) {
828 return $form;
829 }
830
831 $page = isset($_GET['page']) ? $_GET['page'] : '';
832 $gf_page = isset($_GET['gf_page']) ? $_GET['gf_page'] : '';
833
834 $target_pages = array('gf_entries', 'gf_export');
835 $target_gf_pages = array('select_columns', 'print-entry');
836
837 if (in_array($page, $target_pages) || in_array($gf_page, $target_gf_pages)) {
838 $fields = array();
839 $zo = false;
840 foreach ($form["fields"] as $field) {
841 $type = $field->type;
842 if ($type == "repeater_start") {
843 $zo = true;
844 $fields[] = $field;
845 continue;
846 }
847 if ($type == "repeater_end") {
848 $zo = false;
849 $fields[] = $field;
850 continue;
851 }
852 if ($zo) {
853 continue;
854 }
855 $fields[] = $field;
856 }
857 $form["fields"] = $fields;
858 }
859
860 return $form;
861 }
862 }
863 // Register the phone field with the field framework.
864 GF_Fields::register(new Superaddons_GFRepeater_Field());
865