PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.49
E2Pdf – Export Pdf Tool for WordPress v1.32.49
1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 1.08.00 1.08.06 All 72 releases
e2pdf / classes / extension / e2pdf-gravity.php

e2pdf-gravity.php in E2Pdf – Export Pdf Tool for WordPress 1.32.49, at classes/extension/e2pdf-gravity.php

2,723 lines 130.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * File: /extension/e2pdf-gravity.php
5 *
6 * @package E2Pdf
7 * @license GPLv3
8 * @link https://e2pdf.com
9 */
10 if (!defined('ABSPATH')) {
11 die('Access denied.');
12 }
13
14 class Extension_E2pdf_Gravity extends Model_E2pdf_Model {
15
16 private $options;
17 private $info = array(
18 'key' => 'gravity',
19 'title' => 'Gravity Forms',
20 );
21
22 // info
23 public function info($key = false) {
24 if ($key && isset($this->info[$key])) {
25 return $this->info[$key];
26 } else {
27 return array(
28 $this->info['key'] => $this->info['title'],
29 );
30 }
31 }
32
33 // active
34 public function active() {
35
36 if (defined('E2PDF_GRAVITY_EXTENSION') || $this->helper->load('extension')->is_plugin_active('gravityforms/gravityforms.php')) {
37 return true;
38 }
39 return false;
40 }
41
42 // set
43 public function set($key, $value) {
44 if (!isset($this->options)) {
45 $this->options = new stdClass();
46 }
47 $this->options->$key = $value;
48 switch ($key) {
49 case 'item':
50 $this->set('cached_form', false);
51 if ($this->get('item') && class_exists('GFFormsModel')) {
52 $this->set('cached_form', GFFormsModel::get_form_meta($this->get('item')));
53 }
54 break;
55 case 'dataset':
56 $this->set('cached_entry', array());
57 if ($this->get('dataset') && class_exists('GFFormsModel')) {
58 $entry = GFFormsModel::get_entry($this->get('dataset'));
59 if ($entry && !is_wp_error($entry) && isset($entry['form_id'])) {
60 $this->set('cached_entry', $entry);
61 }
62 }
63 break;
64 default:
65 break;
66 }
67 return true;
68 }
69
70 // get
71 public function get($key) {
72 if (isset($this->options->$key)) {
73 $value = $this->options->$key;
74 } else {
75 switch ($key) {
76 case 'args':
77 $value = array();
78 break;
79 default:
80 $value = false;
81 break;
82 }
83 }
84 return $value;
85 }
86
87 // items
88 public function items() {
89 $items = array();
90 if (class_exists('GFFormsModel')) {
91 $forms = GFFormsModel::get_forms(null, 'title');
92 if ($forms) {
93 foreach ($forms as $key => $form) {
94 $items[] = $this->item($form->id);
95 }
96 }
97 }
98 return $items;
99 }
100
101 // datasets
102 public function datasets($item_id = false, $name = false) {
103 $item_id = (int) $item_id;
104 $datasets = array();
105 if (class_exists('GFAPI') && $item_id) {
106 $paging = array(
107 'offset' => 0,
108 'page_size' => 9999999,
109 );
110 $entries = GFAPI::get_entries($item_id, array(), array(), $paging);
111 if ($entries) {
112 $this->set('item', $item_id);
113 foreach ($entries as $key => $entry) {
114 $this->set('dataset', $entry['id']);
115 $entry_title = $this->render($name);
116 if (!$entry_title) {
117 $entry_title = $entry['id'];
118 }
119 $datasets[] = array(
120 'key' => $entry['id'],
121 'value' => $entry_title,
122 );
123 }
124 }
125 }
126 return $datasets;
127 }
128
129 // dataset actions
130 public function get_dataset_actions($dataset_id = false) {
131 $dataset_id = (int) $dataset_id;
132 if (!$dataset_id) {
133 return false;
134 }
135 $entry = GFFormsModel::get_entry($dataset_id);
136 $item = $entry && !is_wp_error($entry) && is_array($entry) && isset($entry['form_id']) ? $entry['form_id'] : '0';
137 $actions = new stdClass();
138 $actions->view = $this->helper->get_url(
139 array(
140 'page' => 'gf_entries',
141 'view' => 'entry',
142 'id' => $item,
143 'lid' => $dataset_id,
144 )
145 );
146 $actions->delete = false;
147 return $actions;
148 }
149
150 // template actions
151 public function get_template_actions($template = false) {
152 $template = (int) $template;
153 if (!$template) {
154 return;
155 }
156 $actions = new stdClass();
157 $actions->delete = false;
158 return $actions;
159 }
160
161 // item
162 public function item($item_id = false) {
163 $item_id = (int) $item_id;
164 if (!$item_id && $this->get('item')) {
165 $item_id = $this->get('item');
166 }
167 $form = false;
168 if (class_exists('GFFormsModel')) {
169 $form = GFFormsModel::get_form_meta($item_id);
170 }
171 $item = new stdClass();
172 if ($form) {
173 $item->id = (string) $item_id;
174 $item->url = $this->helper->get_url(
175 array(
176 'page' => 'gf_edit_forms',
177 'id' => $item_id,
178 )
179 );
180 $item->name = $form['title'];
181 } else {
182 $item->id = '';
183 $item->url = '';
184 $item->name = '';
185 }
186 return $item;
187 }
188
189 // render
190 public function render($value, $field = array(), $convert_shortcodes = true, $raw = false) {
191 $value = $this->render_shortcodes($value, $field);
192 if (!$raw) {
193 $value = $this->strip_shortcodes($value);
194 $value = $this->convert_shortcodes($value, $convert_shortcodes, isset($field['type']) && $field['type'] == 'e2pdf-html' ? true : false);
195 $value = $this->helper->load('field')->render_checkbox($value, $this, $field);
196 }
197 return $value;
198 }
199
200 // load actions
201 public function load_actions() {
202 add_action('gform_after_email', array($this, 'action_gform_after_email'), 30);
203 add_action('gform_after_update_entry', array($this, 'action_gform_after_update_entry'), 0, 2);
204
205 // hooks
206 add_action('gform_entries_first_column_actions', array($this, 'hook_gravity_row_actions'), 10, 4);
207 }
208
209 // load filters
210 public function load_filters() {
211 add_filter('gform_confirmation', array($this, 'filter_gform_confirmation'), 30, 4);
212 add_filter('gform_notification', array($this, 'filter_gform_notification'), 30, 3);
213 add_filter('gform_twilio_message', array($this, 'filter_gform_twilio_message'), 30, 4);
214 add_filter('gform_entry_post_save', array($this, 'filter_gform_entry_post_save'), 0, 2);
215 add_filter('gform_entry_field_value', array($this, 'filter_gform_entry_field_value'), 10, 4);
216 add_filter('gform_merge_tag_filter', array($this, 'filter_gform_merge_tag_filter'), 10, 5);
217 add_filter('gform_entries_field_value', array($this, 'filter_gform_entries_field_value'), 10, 4);
218
219 /* Hooks */
220 add_filter('gform_entry_detail_meta_boxes', array($this, 'hook_gravity_entry_view'), 10, 3);
221 }
222
223 // render shortcodes
224 public function render_shortcodes($value, $field = array()) {
225 $element_id = isset($field['element_id']) ? $field['element_id'] : false;
226 if ($this->verify()) {
227 if (false !== strpos($value, '[')) {
228 $value = $this->helper->load('field')->pre_shortcodes($value, $this, $field);
229 $value = $this->helper->load('field')->inner_shortcodes($value, $this, $field);
230 $value = $this->helper->load('field')->wrapper_shortcodes($value, $this, $field);
231 }
232 $gv_request = false;
233 if (false !== strpos($value, '[gravityview') && function_exists('gravityview') && gravityview()->request->is_admin()) {
234 $gv_request = gravityview()->request;
235 gravityview()->request = new GV\Frontend_Request();
236 }
237 $value = $this->helper->load('field')->do_shortcodes($value, $this, $field);
238 if ($gv_request !== false) {
239 gravityview()->request = $gv_request;
240 }
241 if (class_exists('GFCommon') && $this->get('cached_form') && $this->get('cached_entry')) {
242 add_filter('gp_template_paths', array($this, 'filter_gp_template_paths'), 30, 2);
243 add_filter('gform_merge_tag_filter', array($this, 'filter_gform_merge_tag_filter_tags'), 30, 5);
244 add_filter('gform_display_product_summary', '__return_false', 30);
245 $value = GFCommon::replace_variables($value, $this->get('cached_form'), $this->get('cached_entry'), false, false, false, 'text');
246 remove_filter('gform_display_product_summary', '__return_false', 30);
247 remove_filter('gform_merge_tag_filter', array($this, 'filter_gform_merge_tag_filter_tags'), 30, 5);
248 remove_filter('gp_template_paths', array($this, 'filter_gp_template_paths'), 30, 2);
249 }
250 $value = $this->helper->load('field')->render(
251 apply_filters('e2pdf_extension_render_shortcodes_pre_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false),
252 $this,
253 $field
254 );
255 }
256 return apply_filters(
257 'e2pdf_extension_render_shortcodes_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false
258 );
259 }
260
261 // strip shortcodes
262 public function strip_shortcodes($value) {
263 $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', '', $value);
264 $value = preg_replace('~a\:\d+\:{[^}]*}(*SKIP)(*FAIL)|{[^}]*}~', '', $value);
265 return $value;
266 }
267
268 // strip math
269 public function strip_math($value, &$replacements) {
270 if ($value) {
271 preg_match_all('/\{[^}]+\}/', $value, $matches);
272 foreach ($matches[0] as $match) {
273 $index = count($replacements) + 1;
274 $replacements[] = $match;
275 $value = str_replace($match, '%' . $index . '$s', $value);
276 }
277 }
278 return $value;
279 }
280
281 // convert shortcodes
282 public function convert_shortcodes($value, $to = false, $html = false) {
283 if ($value) {
284 if ($to) {
285 $search = array('&#91;', '&#93;', '&#091;', '&#093;');
286 $replace = array('[', ']', '[', ']');
287 $value = str_replace($search, $replace, $value);
288 if (!$html) {
289 $value = wp_specialchars_decode($value, ENT_QUOTES);
290 }
291 } else {
292 $search = array('[', ']', '&#091;', '&#093;');
293 $replace = array('&#91;', '&#93;', '&#91;', '&#93;');
294 $value = str_replace($search, $replace, $value);
295 }
296 }
297 return $value;
298 }
299
300 // auto
301 public function auto() {
302 $item = $this->get('item');
303 $response = array();
304 $elements = array();
305 $merged_tags = array();
306 $form = false;
307
308 if (class_exists('GFFormsModel')) {
309 $form = GFFormsModel::get_form_meta($item);
310 }
311 if ($form) {
312 if (class_exists('GFCommon')) {
313 foreach ($form['fields'] as $field) {
314 $merged_tags = $this->get_field_merge_tags($merged_tags, $field);
315 }
316 }
317 foreach ($form['fields'] as $field) {
318 if ($this->get('nested') && !in_array($field->id, $this->get('nested_fields'), false)) {
319 continue;
320 }
321 if ($field->type == 'product' || $field->type == 'shipping' || $field->type == 'option') {
322 if ($field->inputType == 'select') {
323 $field->type = 'select';
324 } elseif ($field->inputType == 'radio') {
325 $field->type = 'radio';
326 } elseif ($field->inputType == 'checkbox') {
327 $field->type = 'checkbox';
328 } elseif ($field->inputType == 'price') {
329 $field->type = 'text';
330 }
331 }
332 if ($field->type == 'survey') {
333 if ($field->inputType == 'rating') {
334 $field->type = 'radio';
335 foreach ($field->choices as $key => $choice) {
336 $field->choices[$key]['value'] = $choice['text'];
337 }
338 } elseif ($field->inputType == 'select') {
339 $field->type = 'select';
340 $field->enableChoiceValue = false;
341 foreach ($field->choices as $key => $choice) {
342 $field->choices[$key]['value'] = $choice['text'];
343 }
344 } elseif ($field->inputType == 'rank') {
345 $field->type = 'textarea';
346 } else {
347 $field->type = $field->inputType;
348 }
349 }
350 switch ($field->type) {
351 case 'repeater':
352 $value = isset($field->label) ? $field->label : '';
353 $value .= isset($field->id) ? ':' . $field->id : '';
354 if ($value) {
355 if (!empty($field->fields)) {
356 foreach ($field->fields as $sub_field) {
357 $sub_value = isset($sub_field->label) ? $sub_field->label : '';
358 $sub_value .= isset($field->id) ? ':' . $field->id : '';
359 if ($sub_value) {
360 $sub_field->id = $sub_field->id;
361 $elements = $this->auto_fields($elements, $sub_field, $merged_tags, $item);
362 }
363 }
364 }
365 }
366 break;
367 default:
368 $elements = $this->auto_fields($elements, $field, $merged_tags, $item);
369 break;
370 }
371 }
372 }
373
374 $response['page'] = array(
375 'bottom' => '20',
376 'top' => '20',
377 'left' => '20',
378 'right' => '20',
379 );
380
381 $response['elements'] = $elements;
382 return $response;
383 }
384
385 // auto fields
386 public function auto_fields($elements, $field, $merged_tags, $item) {
387 switch ($field->type) {
388 case 'text':
389 case 'number':
390 case 'date':
391 case 'time':
392 case 'phone':
393 case 'website':
394 case 'email':
395 case 'post_title':
396 case 'post_excerpt':
397 case 'post_tags':
398 case 'post_custom_field':
399 case 'quantity':
400 case 'shipping':
401 case 'total':
402 $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
403 if ($this->get('nested')) {
404 if (substr($value, -1) == '}') {
405 $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}';
406 }
407 }
408 $elements[] = $this->auto_field(
409 $field,
410 array(
411 'type' => 'e2pdf-html',
412 'block' => true,
413 'properties' => array(
414 'top' => '20',
415 'left' => '20',
416 'right' => '20',
417 'width' => '100%',
418 'height' => 'auto',
419 'value' => $field->label,
420 'pass' => $field->enablePasswordInput ? '1' : '0',
421 ),
422 )
423 );
424
425 $elements[] = $this->auto_field(
426 $field,
427 array(
428 'type' => 'e2pdf-input',
429 'properties' => array(
430 'top' => '5',
431 'width' => '100%',
432 'height' => 'auto',
433 'value' => $value,
434 ),
435 )
436 );
437 break;
438 case 'list':
439 $elements[] = $this->auto_field(
440 $field,
441 array(
442 'type' => 'e2pdf-html',
443 'block' => true,
444 'properties' => array(
445 'top' => '20',
446 'left' => '20',
447 'right' => '20',
448 'width' => '100%',
449 'height' => 'auto',
450 'value' => $field->label,
451 ),
452 )
453 );
454 if ($field->enableColumns) {
455 $width = number_format(floor((100 / count($field->choices)) * 100) / 100, 2);
456 foreach ($field->choices as $key => $choice) {
457 $field_id = (int) $key + 1;
458 $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
459
460 if ($this->get('nested')) {
461 if (substr($value, -1) == '}') {
462 $value = substr($value, 0, -1) . ':filter[' . $field->id . ':1_' . $field_id . '],index[0]}';
463 }
464 } else {
465 if (substr($value, -1) == '}') {
466 $value = substr($value, 0, -1) . '1_' . $field_id . '}';
467 }
468 }
469
470 $float = true;
471 if ($key == '0') {
472 $float = false;
473 }
474 $elements[] = $this->auto_field(
475 $field,
476 array(
477 'type' => 'e2pdf-html',
478 'block' => true,
479 'float' => $float,
480 'properties' => array(
481 'top' => '5',
482 'left' => '20',
483 'right' => '20',
484 'width' => $width . '%',
485 'height' => 'auto',
486 'value' => $choice['text'],
487 ),
488 )
489 );
490 $elements[] = $this->auto_field(
491 $field,
492 array(
493 'type' => 'e2pdf-input',
494 'properties' => array(
495 'top' => '5',
496 'width' => '100%',
497 'height' => 'auto',
498 'value' => $value,
499 ),
500 )
501 );
502 }
503 } else {
504 $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
505 if ($this->get('nested')) {
506 if (substr($value, -1) == '}') {
507 $value = substr($value, 0, -1) . ':filter[' . $field->id . ':1],index[0]}';
508 }
509 } else {
510 if (substr($value, -1) == '}') {
511 $value = substr($value, 0, -1) . '1}';
512 }
513 }
514 $elements[] = $this->auto_field(
515 $field,
516 array(
517 'type' => 'e2pdf-input',
518 'properties' => array(
519 'top' => '5',
520 'width' => '100%',
521 'height' => 'auto',
522 'value' => $value,
523 ),
524 )
525 );
526 }
527 break;
528 case 'fileupload':
529 case 'textarea':
530 case 'post_content':
531 $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
532 if ($this->get('nested')) {
533 if (substr($value, -1) == '}') {
534 $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}';
535 }
536 }
537 $elements[] = $this->auto_field(
538 $field,
539 array(
540 'type' => 'e2pdf-html',
541 'block' => true,
542 'properties' => array(
543 'top' => '20',
544 'left' => '20',
545 'right' => '20',
546 'width' => '100%',
547 'height' => 'auto',
548 'value' => $field->label,
549 ),
550 )
551 );
552 $elements[] = $this->auto_field(
553 $field,
554 array(
555 'type' => 'e2pdf-textarea',
556 'properties' => array(
557 'top' => '5',
558 'width' => '100%',
559 'height' => 'auto',
560 'value' => $value,
561 ),
562 )
563 );
564 break;
565 case 'select':
566 case 'multiselect':
567 case 'post_category':
568 case 'option':
569 $elements[] = $this->auto_field(
570 $field,
571 array(
572 'type' => 'e2pdf-html',
573 'block' => true,
574 'properties' => array(
575 'top' => '20',
576 'left' => '20',
577 'right' => '20',
578 'width' => '100%',
579 'height' => 'auto',
580 'value' => $field->label,
581 ),
582 )
583 );
584 $options_tmp = array();
585 if (isset($field->choices) && is_array($field->choices)) {
586 foreach ($field->choices as $opt_key => $option) {
587 $options_tmp[] = isset($option['value']) ? $option['value'] : '';
588 }
589 }
590 $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
591 if ($this->get('nested')) {
592 if ($field->enableChoiceValue && $value) {
593 if (substr($value, -1) == '}') {
594 $value = substr($value, 0, -1) . ':value,filter[' . $field->id . '],index[0]}';
595 }
596 } else {
597 if (substr($value, -1) == '}') {
598 $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}';
599 }
600 }
601 } else {
602 if ($field->enableChoiceValue && $value) {
603 if (substr($value, -1) == '}') {
604 $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}';
605 }
606 }
607 }
608 $elements[] = $this->auto_field(
609 $field,
610 array(
611 'type' => 'e2pdf-select',
612 'properties' => array(
613 'top' => '5',
614 'width' => '100%',
615 'height' => 'auto',
616 'options' => implode("\n", $options_tmp),
617 'value' => $value,
618 'height' => $field->type == 'multiselect' ? '80' : 'auto',
619 'multiline' => $field->type == 'multiselect' ? '1' : '0',
620 ),
621 )
622 );
623 break;
624 case 'checkbox':
625 $elements[] = $this->auto_field(
626 $field,
627 array(
628 'type' => 'e2pdf-html',
629 'block' => true,
630 'properties' => array(
631 'top' => '20',
632 'left' => '20',
633 'right' => '20',
634 'width' => '100%',
635 'height' => 'auto',
636 'value' => $field->label,
637 ),
638 )
639 );
640
641 if (isset($field->choices) && is_array($field->choices)) {
642 $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
643 if ($this->get('nested')) {
644 if ($field->enableChoiceValue && $value) {
645 if (substr($value, -1) == '}') {
646 $value = substr($value, 0, -1) . ':value,filter[' . $field->id . '],index[0]}';
647 }
648 } else {
649 if (substr($value, -1) == '}') {
650 $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}';
651 }
652 }
653 } else {
654 if ($field->enableChoiceValue && $value) {
655 if (substr($value, -1) == '}') {
656 $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}';
657 }
658 }
659 }
660 foreach ($field->choices as $opt_key => $option) {
661 $elements[] = $this->auto_field(
662 $field,
663 array(
664 'type' => 'e2pdf-checkbox',
665 'properties' => array(
666 'top' => '5',
667 'width' => 'auto',
668 'height' => 'auto',
669 'value' => $value,
670 'option' => isset($option['value']) ? $option['value'] : '',
671 ),
672 )
673 );
674 $elements[] = $this->auto_field(
675 $field,
676 array(
677 'type' => 'e2pdf-html',
678 'float' => true,
679 'properties' => array(
680 'left' => '5',
681 'width' => '100%',
682 'height' => 'auto',
683 'value' => isset($option['text']) ? $option['text'] : '',
684 ),
685 )
686 );
687 }
688 }
689 break;
690 case 'radio':
691 $elements[] = $this->auto_field(
692 $field,
693 array(
694 'type' => 'e2pdf-html',
695 'block' => true,
696 'properties' => array(
697 'top' => '20',
698 'left' => '20',
699 'right' => '20',
700 'width' => '100%',
701 'height' => 'auto',
702 'value' => $field->label,
703 ),
704 )
705 );
706
707 if (isset($field->choices) && is_array($field->choices)) {
708 $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
709 if ($this->get('nested')) {
710 if ($field->enableChoiceValue && $value) {
711 if (substr($value, -1) == '}') {
712 $value = substr($value, 0, -1) . ':value,filter[' . $field->id . '],index[0]}';
713 }
714 } else {
715 if (substr($value, -1) == '}') {
716 $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}';
717 }
718 }
719 } else {
720 if ($field->enableChoiceValue && $value) {
721 if (substr($value, -1) == '}') {
722 $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}';
723 }
724 }
725 }
726
727 $choices = array();
728 foreach ($field->choices as $opt_key => $option) {
729 if (!$value && isset($field->inputs) && isset($field->inputs[$opt_key]['id'])) {
730 $value = isset($merged_tags[$field->inputs[$opt_key]['id']]) ? $merged_tags[$field->inputs[$opt_key]['id']] : '';
731 if ($field->enableChoiceValue && $value) {
732 if (substr($value, -1) == '}') {
733 $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}';
734 }
735 }
736 }
737 if (isset($option['value'])) {
738 $choices[] = $option['value'];
739 }
740 $elements[] = $this->auto_field(
741 $field,
742 array(
743 'type' => 'e2pdf-radio',
744 'properties' => array(
745 'top' => '5',
746 'width' => 'auto',
747 'height' => 'auto',
748 'value' => $value,
749 'option' => isset($option['value']) ? $option['value'] : '',
750 'group' => $value,
751 ),
752 )
753 );
754 $elements[] = $this->auto_field(
755 $field,
756 array(
757 'type' => 'e2pdf-html',
758 'float' => true,
759 'properties' => array(
760 'left' => '5',
761 'width' => '100%',
762 'height' => 'auto',
763 'value' => isset($option['text']) ? $option['text'] : '',
764 ),
765 )
766 );
767 }
768
769 //other choice
770 if ($field->enableOtherChoice) {
771 $actions_radio = array();
772 $actions_input = array();
773 if (!empty($choices)) {
774 $conditions = array();
775 $conditions[1] = array(
776 'condition' => '!=',
777 'if' => $value,
778 'value' => '',
779 );
780
781 foreach ($choices as $choice) {
782 $conditions[] = array(
783 'condition' => '!=',
784 'if' => $value,
785 'value' => $choice,
786 );
787 }
788
789 $actions_radio = array(
790 '0' => array(
791 'order' => '0',
792 'action' => 'change',
793 'apply' => 'all',
794 'change' => 'gf_other_choice',
795 'property' => 'value',
796 'conditions' => $conditions,
797 ),
798 );
799
800 $actions_input = array(
801 '0' => array(
802 'order' => '0',
803 'action' => 'change',
804 'apply' => 'all',
805 'change' => $value,
806 'property' => 'value',
807 'conditions' => $conditions,
808 ),
809 );
810 }
811 $elements[] = $this->auto_field(
812 $field,
813 array(
814 'type' => 'e2pdf-radio',
815 'properties' => array(
816 'top' => '5',
817 'width' => 'auto',
818 'height' => 'auto',
819 'value' => $value,
820 'option' => 'gf_other_choice',
821 'group' => $value,
822 ),
823 'actions' => $actions_radio,
824 )
825 );
826 $elements[] = $this->auto_field(
827 $field,
828 array(
829 'type' => 'e2pdf-input',
830 'float' => true,
831 'properties' => array(
832 'left' => '5',
833 'width' => '100%',
834 'height' => 'auto',
835 'value' => '',
836 ),
837 'actions' => $actions_input,
838 )
839 );
840 }
841 }
842 break;
843 case 'name':
844 foreach ($field['inputs'] as $key => $input) {
845 if (isset($input->isHidden) && $input->isHidden) {
846 unset($field['inputs'][$key]);
847 }
848 }
849 $width = '100%';
850 if (count($field['inputs']) == '3') {
851 $width = '33.3%';
852 } else {
853 $width = 100 / count($field['inputs']) . '%';
854 }
855 foreach ($field['inputs'] as $key => $sub_field) {
856 $elements[] = $this->auto_field(
857 $sub_field,
858 array(
859 'type' => 'e2pdf-html',
860 'block' => true,
861 'float' => $key == '0' ? false : true,
862 'properties' => array(
863 'top' => '20',
864 'left' => '20',
865 'right' => '20',
866 'width' => $width,
867 'height' => 'auto',
868 'value' => isset($sub_field['label']) && $sub_field['label'] ? $sub_field['label'] : '',
869 ),
870 )
871 );
872
873 $value = isset($merged_tags[$sub_field['id']]) ? $merged_tags[$sub_field['id']] : '';
874 if ($this->get('nested')) {
875 if (substr($value, -1) == '}') {
876 $value = substr($value, 0, -1) . ':filter[' . $sub_field['id'] . '],index[0]}';
877 }
878 }
879
880 if (isset($sub_field['choices']) && is_array($sub_field['choices'])) {
881 $options_tmp = array();
882 foreach ($sub_field['choices'] as $opt_key => $option) {
883 $options_tmp[] = isset($option['value']) ? $option['value'] : '';
884 }
885 $elements[] = $this->auto_field(
886 $field,
887 array(
888 'type' => 'e2pdf-select',
889 'properties' => array(
890 'top' => '5',
891 'width' => '100%',
892 'height' => 'auto',
893 'options' => implode("\n", $options_tmp),
894 'value' => $value,
895 'height' => 'auto',
896 'multiline' => '0',
897 ),
898 )
899 );
900 } else {
901 $elements[] = $this->auto_field(
902 $sub_field,
903 array(
904 'type' => 'e2pdf-input',
905 'properties' => array(
906 'top' => '5',
907 'width' => '100%',
908 'height' => 'auto',
909 'value' => $value,
910 ),
911 )
912 );
913 }
914 }
915 break;
916 case 'address':
917 $index = 0;
918 foreach ($field['inputs'] as $key => $sub_field) {
919 if (isset($sub_field['isHidden']) && $sub_field['isHidden']) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
920 } else {
921 $value = isset($merged_tags[$sub_field['id']]) ? $merged_tags[$sub_field['id']] : '';
922 if ($this->get('nested')) {
923 if (substr($value, -1) == '}') {
924 $value = substr($value, 0, -1) . ':filter[' . $sub_field['id'] . '],index[0]}';
925 }
926 }
927 $elements[] = $this->auto_field(
928 $sub_field,
929 array(
930 'type' => 'e2pdf-html',
931 'block' => true,
932 'float' => $index == '0' ? false : true,
933 'properties' => array(
934 'top' => '20',
935 'left' => '20',
936 'right' => '20',
937 'width' => $key == '0' || $key == '1' ? '100%' : '50%',
938 'height' => 'auto',
939 'value' => isset($sub_field['label']) && $sub_field['label'] ? $sub_field['label'] : '',
940 ),
941 )
942 );
943 $elements[] = $this->auto_field(
944 $sub_field,
945 array(
946 'type' => 'e2pdf-input',
947 'properties' => array(
948 'top' => '5',
949 'width' => '100%',
950 'height' => 'auto',
951 'value' => $value,
952 ),
953 )
954 );
955 $index++;
956 }
957 }
958 break;
959 case 'consent':
960 $elements[] = $this->auto_field(
961 $field,
962 array(
963 'type' => 'e2pdf-html',
964 'block' => true,
965 'properties' => array(
966 'top' => '20',
967 'left' => '20',
968 'right' => '20',
969 'width' => '100%',
970 'height' => 'auto',
971 'value' => $field->label,
972 ),
973 )
974 );
975 $value = isset($merged_tags[$field->id . '.1']) ? $merged_tags[$field->id . '.1'] : '';
976 if ($this->get('nested')) {
977 if (substr($value, -1) == '}') {
978 $value = substr($value, 0, -1) . ':filter[' . $field->id . '.1],index[0]}';
979 }
980 }
981 $elements[] = $this->auto_field(
982 $field,
983 array(
984 'type' => 'e2pdf-checkbox',
985 'properties' => array(
986 'top' => '5',
987 'width' => 'auto',
988 'height' => 'auto',
989 'value' => $value,
990 'option' => '1',
991 ),
992 )
993 );
994 $elements[] = $this->auto_field(
995 $field,
996 array(
997 'type' => 'e2pdf-html',
998 'float' => true,
999 'properties' => array(
1000 'left' => '5',
1001 'width' => '100%',
1002 'height' => 'auto',
1003 'value' => $field->checkboxLabel,
1004 ),
1005 )
1006 );
1007 break;
1008 case 'post_image':
1009 $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
1010 if ($this->get('nested')) {
1011 if (substr($value, -1) == '}') {
1012 $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}';
1013 }
1014 }
1015 $elements[] = $this->auto_field(
1016 $field,
1017 array(
1018 'type' => 'e2pdf-html',
1019 'block' => true,
1020 'properties' => array(
1021 'top' => '20',
1022 'left' => '20',
1023 'right' => '20',
1024 'width' => '100%',
1025 'height' => 'auto',
1026 'value' => $field->label,
1027 ),
1028 )
1029 );
1030 $elements[] = $this->auto_field(
1031 $field,
1032 array(
1033 'type' => 'e2pdf-image',
1034 'properties' => array(
1035 'top' => '5',
1036 'width' => '100',
1037 'height' => '100',
1038 'value' => $value,
1039 'dimension' => '1',
1040 ),
1041 )
1042 );
1043 if ($field->displayTitle) {
1044 $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
1045 if ($this->get('nested')) {
1046 if (substr($value, -1) == '}') {
1047 $value = substr($value, 0, -1) . ':title,filter[' . $field->id . '],index[0]}';
1048 }
1049 } else {
1050 if (substr($value, -1) == '}') {
1051 $value = substr($value, 0, -1) . ':title}';
1052 }
1053 }
1054 $elements[] = $this->auto_field(
1055 $field,
1056 array(
1057 'type' => 'e2pdf-html',
1058 'block' => true,
1059 'properties' => array(
1060 'top' => '20',
1061 'left' => '20',
1062 'right' => '20',
1063 'width' => '100%',
1064 'height' => 'auto',
1065 'value' => __('Title', 'gravityforms'),
1066 ),
1067 )
1068 );
1069 $elements[] = $this->auto_field(
1070 $field,
1071 array(
1072 'type' => 'e2pdf-input',
1073 'properties' => array(
1074 'top' => '5',
1075 'width' => '100%',
1076 'height' => 'auto',
1077 'value' => $value,
1078 'dimension' => '1',
1079 ),
1080 )
1081 );
1082 }
1083 if ($field->displayCaption) {
1084 $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
1085 if ($this->get('nested')) {
1086 if (substr($value, -1) == '}') {
1087 $value = substr($value, 0, -1) . ':caption,filter[' . $field->id . '],index[0]}';
1088 }
1089 } else {
1090 if (substr($value, -1) == '}') {
1091 $value = substr($value, 0, -1) . ':caption}';
1092 }
1093 }
1094 $elements[] = $this->auto_field(
1095 $field,
1096 array(
1097 'type' => 'e2pdf-html',
1098 'block' => true,
1099 'properties' => array(
1100 'top' => '20',
1101 'left' => '20',
1102 'right' => '20',
1103 'width' => '100%',
1104 'height' => 'auto',
1105 'value' => __('Caption', 'gravityforms'),
1106 ),
1107 )
1108 );
1109 $elements[] = $this->auto_field(
1110 $field,
1111 array(
1112 'type' => 'e2pdf-input',
1113 'properties' => array(
1114 'top' => '5',
1115 'width' => '100%',
1116 'height' => 'auto',
1117 'value' => $value,
1118 'dimension' => '1',
1119 ),
1120 )
1121 );
1122 }
1123 if ($field->displayDescription) {
1124 $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
1125 if ($this->get('nested')) {
1126 if (substr($value, -1) == '}') {
1127 $value = substr($value, 0, -1) . ':description,filter[' . $field->id . '],index[0]}';
1128 }
1129 } else {
1130 if (substr($value, -1) == '}') {
1131 $value = substr($value, 0, -1) . ':description}';
1132 }
1133 }
1134 $elements[] = $this->auto_field(
1135 $field,
1136 array(
1137 'type' => 'e2pdf-html',
1138 'block' => true,
1139 'properties' => array(
1140 'top' => '20',
1141 'left' => '20',
1142 'right' => '20',
1143 'width' => '100%',
1144 'height' => 'auto',
1145 'value' => __('Description', 'gravityforms'),
1146 ),
1147 )
1148 );
1149 $elements[] = $this->auto_field(
1150 $field,
1151 array(
1152 'type' => 'e2pdf-input',
1153 'properties' => array(
1154 'top' => '5',
1155 'width' => '100%',
1156 'height' => 'auto',
1157 'value' => $value && substr($value, -1) == '}' ? substr($value, 0, -1) . ':description}' : '',
1158 'dimension' => '1',
1159 ),
1160 )
1161 );
1162 }
1163 break;
1164 case 'html':
1165 $elements[] = $this->auto_field(
1166 $field,
1167 array(
1168 'type' => 'e2pdf-html',
1169 'block' => true,
1170 'properties' => array(
1171 'top' => '20',
1172 'left' => '20',
1173 'right' => '20',
1174 'width' => '100%',
1175 'height' => 'auto',
1176 'value' => $field->content,
1177 ),
1178 )
1179 );
1180 break;
1181 case 'product':
1182 if ($field->inputType != 'hiddenproduct') {
1183 $elements[] = $this->auto_field(
1184 $field,
1185 array(
1186 'type' => 'e2pdf-html',
1187 'block' => true,
1188 'properties' => array(
1189 'top' => '20',
1190 'left' => '20',
1191 'right' => '20',
1192 'width' => '100%',
1193 'height' => 'auto',
1194 'value' => $field->label,
1195 ),
1196 )
1197 );
1198 if ($field->inputType == 'singleproduct' || $field->inputType == 'calculation') {
1199 if ($field->disableQuantity) {
1200 $width = '50%';
1201 } else {
1202 $width = '33.3%';
1203 }
1204 foreach ($field['inputs'] as $key => $sub_field) {
1205 if ($field->disableQuantity && $key == '2') { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
1206 } else {
1207 $value = isset($merged_tags[$sub_field['id']]) ? $merged_tags[$sub_field['id']] : '';
1208 if ($this->get('nested')) {
1209 if (substr($value, -1) == '}') {
1210 $value = substr($value, 0, -1) . ':filter[' . $sub_field['id'] . '],index[0]}';
1211 }
1212 }
1213 $elements[] = $this->auto_field(
1214 $sub_field,
1215 array(
1216 'type' => 'e2pdf-html',
1217 'block' => true,
1218 'float' => $key == '0' ? false : true,
1219 'properties' => array(
1220 'top' => '5',
1221 'left' => '20',
1222 'right' => '20',
1223 'width' => $width,
1224 'height' => 'auto',
1225 'value' => isset($sub_field['label']) && $sub_field['label'] ? $sub_field['label'] : '',
1226 ),
1227 )
1228 );
1229 $elements[] = $this->auto_field(
1230 $sub_field,
1231 array(
1232 'type' => 'e2pdf-input',
1233 'properties' => array(
1234 'top' => '5',
1235 'width' => '100%',
1236 'height' => 'auto',
1237 'value' => $value,
1238 ),
1239 )
1240 );
1241 }
1242 }
1243 }
1244 }
1245 break;
1246 case 'signature':
1247 $elements[] = $this->auto_field(
1248 $field,
1249 array(
1250 'type' => 'e2pdf-html',
1251 'block' => true,
1252 'properties' => array(
1253 'top' => '20',
1254 'left' => '20',
1255 'right' => '20',
1256 'width' => '100%',
1257 'height' => 'auto',
1258 'value' => $field->label,
1259 ),
1260 )
1261 );
1262 $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
1263 if ($this->get('nested')) {
1264 if (substr($value, -1) == '}') {
1265 $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}';
1266 }
1267 }
1268 $elements[] = $this->auto_field(
1269 $field,
1270 array(
1271 'type' => 'e2pdf-signature',
1272 'properties' => array(
1273 'top' => '5',
1274 'width' => '100%',
1275 'height' => '150',
1276 'dimension' => '1',
1277 'block_dimension' => '1',
1278 'value' => $value,
1279 ),
1280 )
1281 );
1282 break;
1283 case 'form':
1284 if (isset($field->gpnfForm) && $field->gpnfForm) {
1285 $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
1286 if ($value) {
1287 $this->set('item', $field->gpnfForm);
1288 $this->set('nested', $value);
1289 $nested_fields = array();
1290 if (isset($field->gpnfFields) && is_array($field->gpnfFields)) {
1291 $nested_fields = $field->gpnfFields;
1292 }
1293 $this->set('nested_fields', $nested_fields);
1294 $nested_form = $this->auto();
1295 if (!empty($nested_form['elements'])) {
1296 $elements = array_merge($elements, $nested_form['elements']);
1297 }
1298 $this->set('item', $item);
1299 $this->set('nested', '');
1300 }
1301 }
1302 break;
1303 case 'likert':
1304 $elements[] = $this->auto_field(
1305 $field,
1306 array(
1307 'type' => 'e2pdf-html',
1308 'block' => true,
1309 'properties' => array(
1310 'top' => '20',
1311 'left' => '20',
1312 'right' => '20',
1313 'width' => '100%',
1314 'height' => 'auto',
1315 'value' => $field->label,
1316 ),
1317 )
1318 );
1319 if (isset($field->gsurveyLikertEnableMultipleRows) && $field->gsurveyLikertEnableMultipleRows) {
1320 foreach ($field['inputs'] as $key => $sub_field) {
1321 $elements[] = $this->auto_field(
1322 $field,
1323 array(
1324 'type' => 'e2pdf-html',
1325 'block' => true,
1326 'properties' => array(
1327 'top' => '5',
1328 'left' => '20',
1329 'right' => '20',
1330 'width' => '100%',
1331 'height' => 'auto',
1332 'value' => $sub_field['label'],
1333 ),
1334 )
1335 );
1336 if (isset($field->choices) && is_array($field->choices)) {
1337 $value = isset($merged_tags[$sub_field['id']]) ? $merged_tags[$sub_field['id']] : '';
1338 if ($field->enableChoiceValue && $value) {
1339 if (substr($value, -1) == '}') {
1340 $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}';
1341 }
1342 }
1343 $choices = array();
1344 foreach ($field->choices as $opt_key => $option) {
1345
1346 if (!$value && isset($field->inputs) && isset($field->inputs[$opt_key]['id'])) {
1347 $value = isset($merged_tags[$field->inputs[$opt_key]['id']]) ? $merged_tags[$field->inputs[$opt_key]['id']] : '';
1348 if ($field->enableChoiceValue && $value) {
1349 if (substr($value, -1) == '}') {
1350 $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}';
1351 }
1352 }
1353 }
1354 if (isset($option['value'])) {
1355 $choices[] = $option['value'];
1356 }
1357 $elements[] = $this->auto_field(
1358 $field,
1359 array(
1360 'type' => 'e2pdf-radio',
1361 'properties' => array(
1362 'top' => '5',
1363 'width' => 'auto',
1364 'height' => 'auto',
1365 'value' => $value,
1366 'option' => isset($option['text']) ? $option['text'] : '',
1367 'group' => $value,
1368 ),
1369 )
1370 );
1371 $elements[] = $this->auto_field(
1372 $field,
1373 array(
1374 'type' => 'e2pdf-html',
1375 'float' => true,
1376 'properties' => array(
1377 'left' => '5',
1378 'width' => '100%',
1379 'height' => 'auto',
1380 'value' => isset($option['text']) ? $option['text'] : '',
1381 ),
1382 )
1383 );
1384 }
1385 }
1386 }
1387 } else {
1388 if (isset($field->choices) && is_array($field->choices)) {
1389 $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
1390 if ($field->enableChoiceValue && $value) {
1391 if (substr($value, -1) == '}') {
1392 $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}';
1393 }
1394 }
1395 $choices = array();
1396 foreach ($field->choices as $opt_key => $option) {
1397 if (!$value && isset($field->inputs) && isset($field->inputs[$opt_key]['id'])) {
1398 $value = isset($merged_tags[$field->inputs[$opt_key]['id']]) ? $merged_tags[$field->inputs[$opt_key]['id']] : '';
1399 if ($field->enableChoiceValue && $value) {
1400 if (substr($value, -1) == '}') {
1401 $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}';
1402 }
1403 }
1404 }
1405 if (isset($option['value'])) {
1406 $choices[] = $option['value'];
1407 }
1408 $elements[] = $this->auto_field(
1409 $field,
1410 array(
1411 'type' => 'e2pdf-radio',
1412 'properties' => array(
1413 'top' => '5',
1414 'width' => 'auto',
1415 'height' => 'auto',
1416 'value' => $value,
1417 'option' => isset($option['text']) ? $option['text'] : '',
1418 'group' => $value,
1419 ),
1420 )
1421 );
1422 $elements[] = $this->auto_field(
1423 $field,
1424 array(
1425 'type' => 'e2pdf-html',
1426 'float' => true,
1427 'properties' => array(
1428 'left' => '5',
1429 'width' => '100%',
1430 'height' => 'auto',
1431 'value' => isset($option['text']) ? $option['text'] : '',
1432 ),
1433 )
1434 );
1435 }
1436 }
1437 }
1438 break;
1439 case 'repeater':
1440 $value = isset($field->label) ? $field->label : '';
1441 $value .= isset($field->id) ? ':' . $field->id : '';
1442 if ($value) {
1443 if (!empty($field->fields)) {
1444 foreach ($field->fields as $sub_field) {
1445 $sub_value = isset($sub_field->label) ? $sub_field->label : '';
1446 $sub_value .= isset($field->id) ? ':' . $field->id : '';
1447 if ($sub_value) {
1448 $sub_field->id = $sub_field->id;
1449 $elements = $this->auto_fields($elements, $sub_field, $merged_tags, $item);
1450 }
1451 }
1452 }
1453 }
1454 break;
1455 default:
1456 break;
1457 }
1458 return $elements;
1459 }
1460
1461 // auto field
1462 public function auto_field($field = false, $element = array()) {
1463 if (!$field) {
1464 return false;
1465 }
1466 if (!isset($element['block'])) {
1467 $element['block'] = false;
1468 }
1469 if (!isset($element['float'])) {
1470 $element['float'] = false;
1471 }
1472 return $element;
1473 }
1474
1475 // verify
1476 public function verify() {
1477 if ($this->get('cached_form') && $this->get('cached_entry')) {
1478 if ($this->get('cached_entry')['form_id'] == $this->get('item')) {
1479 return true;
1480 }
1481 }
1482 return false;
1483 }
1484
1485 // auto form
1486 public function auto_form($template, $data = array()) {
1487
1488 if ($template->get('ID')) {
1489
1490 $auto_form_label = isset($data['auto_form_label']) && $data['auto_form_label'] ? $data['auto_form_label'] : false;
1491 $auto_form_shortcode = isset($data['auto_form_shortcode']) ? true : false;
1492
1493 if (class_exists('GFAPI')) {
1494 $confirmation_id = uniqid();
1495 $form = array(
1496 'title' => $template->get('title'),
1497 'fields' => array(
1498 ),
1499 'confirmations' => array(),
1500 );
1501
1502 $form['confirmations'][$confirmation_id] = array(
1503 'id' => $confirmation_id,
1504 'name' => __('Default Confirmation', 'gravityforms'),
1505 'isDefault' => true,
1506 'type' => 'message',
1507 /* translators: %d: E2Pdf Template ID */
1508 'message' => sprintf(__('Thanks for contacting us! We will get in touch with you shortly. [e2pdf-download id="%d"]', 'e2pdf'), $template->get('ID')),
1509 'url' => '',
1510 'pageId' => '',
1511 'queryString' => '',
1512 );
1513
1514 $pages = $template->get('pages');
1515 $checkboxes = array();
1516 $radios = array();
1517
1518 $field_id = 1;
1519
1520 foreach ($pages as $page_key => $page) {
1521 if (isset($page['elements']) && !empty($page['elements'])) {
1522 foreach ($page['elements'] as $element_key => $element) {
1523 $type = false;
1524 $labels = array();
1525 $label = '';
1526
1527 if ($auto_form_shortcode) {
1528 $labels[] = $field_id;
1529 }
1530 if ($auto_form_label && $auto_form_label == 'value' && isset($element['value']) && $element['value']) {
1531 $labels[] = $element['value'];
1532 } elseif ($auto_form_label && $auto_form_label == 'name' && isset($element['name']) && $element['name']) {
1533 $labels[] = $element['name'];
1534 }
1535
1536 if ($element['type'] == 'e2pdf-input' || $element['type'] == 'e2pdf-signature') {
1537 $type = 'text';
1538 $label = !empty($labels) ? implode(' ', $labels) : 'Text';
1539 } elseif ($element['type'] == 'e2pdf-textarea') {
1540 $type = 'textarea';
1541 $label = !empty($labels) ? implode(' ', $labels) : 'Textarea';
1542 } elseif ($element['type'] == 'e2pdf-select') {
1543 $type = 'select';
1544 $label = !empty($labels) ? implode(' ', $labels) : 'Select';
1545
1546 $choices = array();
1547 $field_options = array();
1548
1549 if (isset($element['properties']['options'])) {
1550 $field_options = explode("\n", $element['properties']['options']);
1551 foreach ($field_options as $option) {
1552 $choices[] = array(
1553 'text' => $option,
1554 'value' => $option,
1555 );
1556 }
1557 }
1558 } elseif ($element['type'] == 'e2pdf-checkbox') {
1559 $field_key = array_search($element['name'], array_column($checkboxes, 'name'), false);
1560 if ($field_key !== false) {
1561 $checkbox = array_search($checkboxes[$field_key]['id'], array_column($form['fields'], 'id'), false);
1562 if ($checkbox !== false) {
1563 $form['fields'][$checkbox]['choices'][] = array(
1564 'text' => $element['properties']['option'],
1565 'value' => $element['properties']['option'],
1566 );
1567
1568 $num = count($form['fields'][$checkbox]['inputs']) + 1;
1569 $form['fields'][$checkbox]['inputs'][] = array(
1570 'id' => $field_id . '.' . $num,
1571 'label' => $element['properties']['option'],
1572 );
1573 $pages[$page_key]['elements'][$element_key]['value'] = '{' . $form['fields'][$checkbox]['label'] . ':' . $form['fields'][$checkbox]['id'] . '}';
1574 }
1575 } else {
1576 $label = !empty($labels) ? implode(' ', $labels) : 'Checkbox';
1577 $type = 'checkbox';
1578 $checkboxes[] = array(
1579 'id' => $field_id,
1580 'name' => $element['name'],
1581 );
1582 $choices = array(
1583 array(
1584 'text' => $element['properties']['option'],
1585 'value' => $element['properties']['option'],
1586 ),
1587 );
1588
1589 $inputs = array(
1590 array(
1591 'id' => $field_id . '.1',
1592 'label' => $element['properties']['option'],
1593 ),
1594 );
1595 }
1596 } elseif ($element['type'] == 'e2pdf-radio') {
1597 if (isset($element['properties']['group']) && $element['properties']['group']) {
1598 $element['name'] = $element['properties']['group'];
1599 } else {
1600 $element['name'] = $element['element_id'];
1601 }
1602 $field_key = array_search($element['name'], array_column($radios, 'name'), false);
1603 if ($field_key !== false) {
1604 $radio = array_search($radios[$field_key]['id'], array_column($form['fields'], 'id'), false);
1605 if ($radio !== false) {
1606 $form['fields'][$radio]['choices'][] = array(
1607 'text' => $element['properties']['option'],
1608 'value' => $element['properties']['option'],
1609 );
1610
1611 $pages[$page_key]['elements'][$element_key]['value'] = '{' . $form['fields'][$radio]['label'] . ':' . $form['fields'][$radio]['id'] . '}';
1612 }
1613 } else {
1614 $label = !empty($labels) ? implode(' ', $labels) : 'Radio';
1615 $type = 'radio';
1616 $radios[] = array(
1617 'id' => $field_id,
1618 'name' => $element['name'],
1619 );
1620 $choices = array(
1621 array(
1622 'text' => $element['properties']['option'],
1623 'value' => $element['properties']['option'],
1624 ),
1625 );
1626 }
1627 }
1628 if ($type) {
1629 $field = array(
1630 'id' => $field_id,
1631 'type' => $type,
1632 'label' => $label,
1633 );
1634 if ($type == 'select' || $type == 'radio' || $type == 'checkbox') {
1635 $field['choices'] = $choices;
1636 }
1637
1638 if ($type == 'checkbox') {
1639 $field['inputs'] = $inputs;
1640 }
1641
1642 $form['fields'][] = $field;
1643 $pages[$page_key]['elements'][$element_key]['value'] = '{' . $label . ':' . $field_id . '}';
1644
1645 if (isset($element['properties']['esig'])) {
1646 unset($pages[$page_key]['elements'][$element_key]['properties']['esig']);
1647 }
1648 $field_id++;
1649 }
1650 }
1651 }
1652 }
1653
1654 $item = GFAPI::add_form($form);
1655 if (!is_wp_error($item)) {
1656 $template->set('item', $item);
1657 $template->set('pages', $pages);
1658 }
1659 }
1660 }
1661
1662 return $template;
1663 }
1664
1665 // visual mapper
1666 public function visual_mapper() {
1667
1668 $item = $this->get('item');
1669 $html = '';
1670 $source = '';
1671
1672 if ($item && function_exists('gravity_form')) {
1673 ob_start();
1674 $form = false;
1675 if (class_exists('GFFormsModel')) {
1676 $form = GFFormsModel::get_form_meta($item);
1677 }
1678 if ($form) {
1679 add_filter('gform_pre_render', array($this, 'filter_gform_pre_render'), 30);
1680 $source = gravity_form($item, true, true, false, null, false, 0, false);
1681 remove_filter('gform_pre_render', array($this, 'filter_gform_pre_render'), 30);
1682 if ($source) {
1683 $dom = new DOMDocument();
1684 if ($this->get('nested')) {
1685 $source = str_replace(array('<form', '</form>'), array('<div', '</div>'), $source);
1686 } else {
1687 $source = '<div class="gf_browser_chrome gform_wrapper gform-theme gform-theme--foundation gform-theme--framework gform-theme--orbital">' . $source . '</div>';
1688 }
1689 $html = $this->helper->load('convert')->load_html($source, $dom, true);
1690 }
1691 }
1692 if (ob_get_length() > 0) {
1693 while (@ob_end_clean()); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
1694 }
1695 if (!$source) {
1696 return '<div class="e2pdf-vm-error">' . __("The form source is empty or doesn't exist", 'e2pdf') . '</div>';
1697 } elseif (!$html) {
1698 return '<div class="e2pdf-vm-error">' . __('The form could not be parsed due the incorrect HTML', 'e2pdf') . '</div>';
1699 } else {
1700
1701 $merged_tags = array();
1702 if (class_exists('GFCommon')) {
1703 foreach ($form['fields'] as $field) {
1704 $merged_tags = $this->get_field_merge_tags($merged_tags, $field);
1705 }
1706 }
1707 $xml = new Helper_E2pdf_Xml();
1708 $xpath = new DomXPath($dom);
1709
1710 // remove by class
1711 $remove_by_class = array(
1712 'gf_progressbar_wrapper',
1713 'gform_previous_button',
1714 'gform_next_button',
1715 'gform_button button',
1716 'gform_save_link',
1717 'gfield--type-captcha',
1718 );
1719 if ($this->get('nested')) {
1720 $remove_by_class[] = 'gform_heading';
1721 }
1722 foreach ($remove_by_class as $key => $class) {
1723 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
1724 foreach ($elements as $element) {
1725 $element->parentNode->removeChild($element);
1726 }
1727 }
1728
1729 // display:none fix in case fields with conditional logic
1730 $gform_wrappers = array(
1731 'gform_wrapper',
1732 );
1733 foreach ($gform_wrappers as $key => $class) {
1734 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
1735 foreach ($elements as $element) {
1736 if ($element->hasAttribute('style')) {
1737 $element->removeAttribute('style');
1738 }
1739 }
1740 }
1741
1742 // remove by tag
1743 $remove_by_tag = array(
1744 'script',
1745 );
1746 foreach ($remove_by_tag as $key => $tag) {
1747 $elements = $xpath->query('//' . $tag);
1748 foreach ($elements as $element) {
1749 $element->parentNode->removeChild($element);
1750 }
1751 }
1752
1753 // remove by name
1754 $remove_by_name = array(
1755 'gform_field_values',
1756 'gform_uploaded_files',
1757 'MAX_FILE_SIZE',
1758 'is_submit_' . $item,
1759 'gform_submit',
1760 'gform_unique_id',
1761 'state_' . $item,
1762 'gform_target_page_number_' . $item,
1763 'gform_source_page_number_' . $item,
1764 );
1765 foreach ($remove_by_name as $key => $name) {
1766 $elements = $xpath->query('//*[@name="' . $name . '"]');
1767 foreach ($elements as $element) {
1768 $element->parentNode->removeChild($element);
1769 }
1770 }
1771
1772 // replace nested forms
1773 $elements = $xpath->query("//*[contains(@class, 'gpnf-nested-entries-container')]");
1774 foreach ($elements as $element) {
1775 $button = $xpath->query('./*[@data-nestedformid]', $element)->item(0);
1776 $field = $xpath->query("following-sibling::input[@type='hidden']", $element)->item(0);
1777 if ($button && $field) {
1778 $form_id = $xml->get_node_value($button, 'data-nestedformid');
1779 if ($form_id) {
1780 $this->set('item', $form_id);
1781 }
1782 if ($field->attributes->getNamedItem('name')) {
1783 $field_id = preg_replace('/input_([^\[]+)(?:.*)/', '${1}', $xml->get_node_value($field, 'name'));
1784 if ($field_id) {
1785 $value = isset($merged_tags[$field_id]) ? $merged_tags[$field_id] : '';
1786 if (isset($merged_tags[$field_id])) {
1787 $this->set('nested', $value);
1788 }
1789 }
1790 }
1791 $nested_form = $this->visual_mapper();
1792 if ($nested_form) {
1793 $element->parentNode->replaceChild($dom->importNode($nested_form->documentElement, true), $element);
1794 }
1795 $this->set('item', $item);
1796 $this->set('nested', '');
1797 }
1798 }
1799
1800 // replace time fields
1801 $elements = $xpath->query("//*[contains(@class, 'gfield_time_hour')]");
1802 foreach ($elements as $element) {
1803 $sub_elements = $xpath->query('.//*[self::input or self::select]', $element->parentNode);
1804 foreach ($sub_elements as $sub_element) {
1805 $xml->set_node_value($sub_element, 'class', $xml->get_node_value($sub_element, 'class') . ' e2pdf-no-vm');
1806 }
1807 $xml->set_node_value($element, 'class', $xml->get_node_value($element->parentNode, 'class') . ' e2pdf-vm-rel-field', true);
1808 $input = $xpath->query('./input', $element)->item(0);
1809 $field = $dom->createElement('input');
1810 $xml->set_node_value($field, 'type', 'text');
1811 $xml->set_node_value($field, 'class', 'e2pdf-vm-abs-field');
1812 $xml->set_node_value($field, 'name', $xml->get_node_value($input, 'name'));
1813
1814 $element->parentNode->appendChild($field);
1815 }
1816
1817 // replace multiupload field
1818 $elements = $xpath->query("//*[contains(@class, 'gform_drop_area')]");
1819 foreach ($elements as $element) {
1820 $xml->set_node_value($element, 'class', $xml->get_node_value($element, 'class') . ' e2pdf-vm-rel-field');
1821 $field_id = preg_replace('/(?:.*)_([\d]+)/', '${1}', $xml->get_node_value($element, 'id'));
1822 $field = $dom->createElement('input');
1823 $xml->set_node_value($field, 'type', 'text');
1824 $xml->set_node_value($field, 'class', 'e2pdf-vm-abs-field');
1825 $xml->set_node_value($field, 'name', 'input_' . $field_id);
1826 $element->appendChild($field);
1827 }
1828
1829 // hidden fields
1830 $elements = $xpath->query("//*[contains(@class, 'gfield--input-type-hidden')]");
1831 foreach ($elements as $element) {
1832 $xml->set_node_value($element, 'class', str_replace('gform_hidden', '', $xml->get_node_value($element, 'class')));
1833 $inputs = $xpath->query('.//input', $element);
1834 foreach ($inputs as $key => $sub_element) {
1835 $xml->set_node_value($sub_element, 'class', str_replace('gform_hidden', '', $xml->get_node_value($sub_element, 'class')));
1836 }
1837 }
1838
1839 // signature
1840 $elements = $xpath->query("//*[contains(@class, 'gfield_signature_container') and contains(@class, 'ginput_container')]");
1841 foreach ($elements as $element) {
1842 $xml->set_node_value($element, 'class', $xml->get_node_value($element, 'class') . ' e2pdf-vm-rel-field');
1843 $signature = $xpath->query('.//parent::*/input', $element);
1844 if ($signature->item(0)) {
1845 $field = $signature->item(0);
1846 $xml->set_node_value($field, 'type', 'text');
1847 $xml->set_node_value($field, 'class', 'e2pdf-vm-abs-field');
1848 $element->appendChild($field);
1849 }
1850 }
1851
1852 // replace single product
1853 $elements = $xpath->query("//*[contains(@class, 'ginput_container_singleproduct') or contains(@class, 'ginput_container_product_calculation') or contains(@class, 'ginput_container_singleshipping') or contains(@class, 'ginput_container_total')]");
1854 foreach ($elements as $element) {
1855 $spans = $xpath->query('.//span', $element);
1856 foreach ($spans as $key => $sub_element) {
1857 $sub_element->parentNode->removeChild($sub_element);
1858 }
1859 $inputs = $xpath->query('.//input', $element);
1860 foreach ($inputs as $key => $sub_element) {
1861 $xml->set_node_value($sub_element, 'type', 'text');
1862 $xml->set_node_value($sub_element, 'class', '');
1863 }
1864 }
1865
1866 $fields = $this->get_form_fields(array(), $form['fields']);
1867
1868 $elements = $xpath->query("//*[contains(@class, 'gsurvey-likert-choice')]");
1869 foreach ($elements as $element) {
1870 $label = $xml->get_node_value($element, 'data-label');
1871 $sub_element = $xpath->query('.//input', $element)->item(0);
1872 if ($label && $sub_element) {
1873 $xml->set_node_value($sub_element, 'value', $label);
1874 }
1875 }
1876
1877 $elements = $xpath->query("//*[contains(@class, 'gsurvey-rating')]");
1878 foreach ($elements as $element) {
1879 $inputs = $xpath->query('.//input', $element);
1880 foreach ($inputs as $key => $sub_element) {
1881 $label = $xpath->query('.//following-sibling::label[1]', $sub_element)->item(0);
1882 if ($label) {
1883 $title = $xml->get_node_value($label, 'title');
1884 $xml->set_node_value($sub_element, 'value', $title);
1885 }
1886 }
1887 }
1888
1889 $elements = $xpath->query("//*[contains(@class, 'gsurvey-survey-field')]//select");
1890 foreach ($elements as $element) {
1891 $inputs = $xpath->query('.//option', $element);
1892 foreach ($inputs as $key => $sub_element) {
1893 $label = $sub_element->nodeValue;
1894 if ($label) {
1895 $xml->set_node_value($sub_element, 'value', $label);
1896 }
1897 }
1898 }
1899
1900 $elements = $xpath->query("//*[contains(@class, 'ginput_container_rank')]//input");
1901 foreach ($elements as $element) {
1902 $xml->set_node_value($element, 'type', 'text');
1903 }
1904
1905 // replace by types
1906 $replace_by_types = array(
1907 '//input',
1908 '//textarea',
1909 '//select',
1910 );
1911 foreach ($replace_by_types as $replace_by_type) {
1912 $inputs = $xpath->query($replace_by_type);
1913 foreach ($inputs as $element) {
1914 if ($element->attributes->getNamedItem('name')) {
1915 $field_id = false;
1916 $field = false;
1917 $sub_field_id = preg_replace('/input_([^\[]+)(?:.*)/', '${1}', $xml->get_node_value($element, 'name'));
1918 if ($sub_field_id) {
1919 if (substr($sub_field_id, -6) == '_valid') {
1920 $field_id = preg_replace('/(?:.*)\_([\d]+)\_valid/', '${1}', $sub_field_id);
1921 } elseif (substr($sub_field_id, -5) == '_data') {
1922 $field_id = preg_replace('/(?:.*)\_([\d]+)\_data/', '${1}', $sub_field_id);
1923 } else {
1924 $field_id = preg_replace('/([\d]+)\.(?:.*)/', '${1}', $sub_field_id);
1925 }
1926 if (isset($fields[$field_id])) {
1927 $field = $fields[$field_id];
1928 }
1929 }
1930 if ($field) {
1931 if (
1932 $field->type == 'name' ||
1933 $field->type == 'address' || (
1934 $field->type == 'product' &&
1935 $field->inputType &&
1936 ($field->inputType == 'singleproduct' || $field->inputType == 'calculation')
1937 )
1938 ) {
1939 $value = $merged_tags[$sub_field_id];
1940 if ($this->get('nested')) {
1941 if (substr($value, -1) == '}') {
1942 $value = substr($value, 0, -1) . ':filter[' . $sub_field_id . '],index[0]}';
1943 }
1944 }
1945 $xml->set_node_value($element, 'name', $value);
1946 } elseif ($field->type == 'consent') {
1947 $value = isset($merged_tags[$field_id . '.1']) ? $merged_tags[$field_id . '.1'] : '';
1948 if ($this->get('nested')) {
1949 if (substr($value, -1) == '}') {
1950 $value = substr($value, 0, -1) . ':filter[' . $field_id . '.1],index[0]}';
1951 }
1952 }
1953 $xml->set_node_value($element, 'name', $value);
1954 } elseif ($field->type == 'survey') {
1955 $value = isset($merged_tags[$sub_field_id]) ? $merged_tags[$sub_field_id] : '';
1956 if (isset($field['inputType']) &&
1957 $field['inputType'] != 'text' &&
1958 $field['inputType'] != 'textarea' &&
1959 $field['inputType'] != 'select' &&
1960 $field['inputType'] != 'rank') {
1961 if (isset($field['enableChoiceValue'])) {
1962 $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}';
1963 }
1964 }
1965 $xml->set_node_value($element, 'name', $value);
1966 } else {
1967 if (isset($merged_tags[$field_id])) {
1968 $value = $merged_tags[$field_id];
1969 if (substr($value, -1) == '}') {
1970 if (false !== strpos($xml->get_node_value($element->parentNode, 'class'), 'ginput_post_image_')) {
1971 if (false !== strpos($xml->get_node_value($element->parentNode, 'class'), 'ginput_post_image_title')) {
1972 if ($this->get('nested')) {
1973 $value = substr($value, 0, -1) . ':title,filter[' . $field_id . '],index[0]}';
1974 } else {
1975 $value = substr($value, 0, -1) . ':title}';
1976 }
1977 } elseif (false !== strpos($xml->get_node_value($element->parentNode, 'class'), 'ginput_post_image_caption')) {
1978 if ($this->get('nested')) {
1979 $value = substr($value, 0, -1) . ':caption,filter[' . $field_id . '],index[0]}';
1980 } else {
1981 $value = substr($value, 0, -1) . ':caption}';
1982 }
1983 } elseif (false !== strpos($xml->get_node_value($element->parentNode, 'class'), 'ginput_post_image_description')) {
1984 if ($this->get('nested')) {
1985 $value = substr($value, 0, -1) . ':description,filter[' . $field_id . '],index[0]}';
1986 } else {
1987 $value = substr($value, 0, -1) . ':description}';
1988 }
1989 }
1990 } elseif ($field->type == 'list') {
1991 if ($field->enableColumns) {
1992 $parent_class = $xml->get_node_value($element->parentNode, 'class');
1993 $index = 1;
1994 $td = $xpath->query("./td[contains(@class, '{$parent_class}')]/preceding-sibling::td", $element->parentNode->parentNode);
1995 if ($td && isset($td->length)) {
1996 $index = (int) $td->length + 1;
1997 }
1998 if ($this->get('nested')) {
1999 $value = substr($value, 0, -1) . ':value,filter[' . $field_id . ':1_' . $index . '],index[0]}';
2000 } else {
2001 $value = substr($value, 0, -1) . '1_' . $index . '}';
2002 }
2003 } else {
2004 if ($this->get('nested')) {
2005 $value = substr($value, 0, -1) . ':filter[' . $field_id . ':1],index[0]}';
2006 } else {
2007 $value = substr($value, 0, -1) . '1}';
2008 }
2009 }
2010 } elseif ($field->enableChoiceValue && $value) {
2011 if ($this->get('nested')) {
2012 $value = substr($value, 0, -1) . ':value,filter[' . $field_id . '],index[0]}';
2013 } else {
2014 $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}';
2015 }
2016 } else {
2017 if ($this->get('nested')) {
2018 $value = substr($value, 0, -1) . ':filter[' . $field_id . '],index[0]}';
2019 }
2020 }
2021 }
2022 $xml->set_node_value($element, 'name', $value);
2023 }
2024 }
2025 }
2026 }
2027 }
2028 }
2029
2030 /* Replace other choice */
2031 $elements = $xpath->query("//*[@value='gf_other_choice']/parent::*");
2032 foreach ($elements as $element) {
2033 $radio = $xpath->query(".//input[@type='radio']", $element)->item(0);
2034 $input = $xpath->query(".//input[@type='text']", $element)->item(0);
2035 if ($radio && $input) {
2036 $xml->set_node_value($input, 'name', $xml->get_node_value($radio, 'name'));
2037 }
2038 }
2039
2040 if ($this->get('nested')) {
2041 return $dom;
2042 } else {
2043 if (defined('LIBXML_HTML_NOIMPLIED') && defined('LIBXML_HTML_NODEFDTD')) {
2044 return str_replace(array('<html>', '</html>'), '', $dom->saveHTML());
2045 } else {
2046 return $dom->saveHTML();
2047 }
2048 }
2049 }
2050 }
2051
2052 return false;
2053 }
2054
2055 // auto map
2056 public function auto_map($name = false) {
2057
2058 $item = $this->get('item');
2059
2060 $merged_tags = array();
2061 $form = false;
2062 $sub_field_id = false;
2063
2064 if ($name) {
2065 $sub_field_id = preg_replace('/\{(?:.*)\:(.*)\:\}/', '${1}', $name);
2066 }
2067
2068 if ($sub_field_id) {
2069 if (class_exists('GFFormsModel')) {
2070 $form = GFFormsModel::get_form_meta($item);
2071 }
2072
2073 if ($form) {
2074 if (class_exists('GFCommon')) {
2075 foreach ($form['fields'] as $field) {
2076 $merged_tags = $this->get_field_merge_tags($merged_tags, $field);
2077 }
2078 }
2079 if (isset($merged_tags[$sub_field_id])) {
2080 return $merged_tags[$sub_field_id];
2081 }
2082 }
2083 }
2084
2085 return false;
2086 }
2087
2088 // load shortcodes
2089 public function load_shortcodes() { // phpcs:ignore Squiz.WhiteSpace.SuperfluousWhitespace.EndLine
2090 }
2091
2092 // entry field value filter
2093 public function filter_gform_entry_field_value($display_value, $field, $lead, $form) {
2094 if (isset($field->defaultValue) && (false !== strpos($field->defaultValue, '[e2pdf-download') || false !== strpos($field->defaultValue, '[e2pdf-save'))) {
2095 $display_value = wp_specialchars_decode($display_value, ENT_QUOTES);
2096 }
2097 return $display_value;
2098 }
2099
2100 // merge tag filter
2101 public function filter_gform_merge_tag_filter($value, $merge_tag, $modifier, $field, $raw_value) {
2102 if (isset($field->defaultValue) && (false !== strpos($field->defaultValue, '[e2pdf-download') || false !== strpos($field->defaultValue, '[e2pdf-save'))) {
2103 return $raw_value;
2104 }
2105 return $value;
2106 }
2107
2108 // entries field value filter
2109 public function filter_gform_entries_field_value($value, $form_id, $field_id, $entry) {
2110 $field = GFAPI::get_field($form_id, $field_id);
2111 if (isset($field->defaultValue) && (false !== strpos($field->defaultValue, '[e2pdf-download') || false !== strpos($field->defaultValue, '[e2pdf-save'))) {
2112 $value = wp_specialchars_decode($value, ENT_QUOTES);
2113 }
2114 return $value;
2115 }
2116
2117 // gp template path filter
2118 public function filter_gp_template_paths($file_paths, $gp_template) {
2119 $template_dir = $gp_template->get_theme_template_dir_name();
2120 $e2pdf_file_paths = array(
2121 -100 => trailingslashit(get_stylesheet_directory()) . $template_dir . 'e2pdf/',
2122 -99 => trailingslashit(get_template_directory()) . $template_dir . 'e2pdf/',
2123 );
2124 $file_paths = $file_paths + $e2pdf_file_paths;
2125 return $file_paths;
2126 }
2127
2128 // gform confirmation filter
2129 public function filter_gform_confirmation($content, $form, $entry, $ajax) {
2130 return $this->filter_content($content, isset($entry['id']) ? $entry['id'] : 0, false, 'message');
2131 }
2132
2133 // twilio message filter
2134 public function filter_gform_twilio_message($notification, $feed, $entry, $form) {
2135 $content = isset($notification['body']) && $notification['body'] ? $notification['body'] : '';
2136 if (false === strpos($content, '[')) {
2137 return $notification;
2138 }
2139
2140 $shortcode_tags = array(
2141 'e2pdf-download',
2142 'e2pdf-view',
2143 );
2144 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
2145 $tagnames = array_intersect($shortcode_tags, $matches[1]);
2146 if (!empty($tagnames)) {
2147 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
2148 foreach ($shortcodes[0] as $key => $shortcode_value) {
2149 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
2150 $atts = shortcode_parse_atts($shortcode[3]);
2151 if (!isset($atts['dataset']) && isset($atts['id'])) {
2152 $template = new Model_E2pdf_Template();
2153 $template->load($atts['id']);
2154 if ($template->get('extension') === 'gravity') {
2155 $entry_id = $entry && isset($entry['id']) ? $entry['id'] : false;
2156 if ($entry_id) {
2157 $atts['dataset'] = $entry_id;
2158 $shortcode[3] .= ' dataset="' . $entry_id . '"';
2159 }
2160 }
2161 }
2162 if (!isset($atts['apply'])) {
2163 $shortcode[3] .= ' apply="true"';
2164 }
2165 if (!isset($atts['filter'])) {
2166 $shortcode[3] .= ' filter="true"';
2167 }
2168 if ($shortcode[2] === 'e2pdf-download' || ($shortcode[2] === 'e2pdf-view' && isset($atts['output']) && $atts['output'] == 'url')) {
2169 if (class_exists('GFCommon')) {
2170 $shortcode[3] = GFCommon::replace_variables($shortcode[3], $form, $entry, false, false, false, 'text');
2171 }
2172 $notification['body'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $notification['body']);
2173 }
2174 }
2175 }
2176 return $notification;
2177 }
2178
2179 // gfrom post save filter
2180 public function filter_gform_entry_post_save($entry, $form) {
2181 if (isset($form['fields'])) {
2182 foreach ($form['fields'] as $key => $field) {
2183 if (isset($field->defaultValue) && (false !== strpos($field->defaultValue, '[e2pdf-download') || false !== strpos($field->defaultValue, '[e2pdf-save'))) {
2184 $value = $this->filter_content($field->defaultValue, isset($entry['id']) ? $entry['id'] : 0, true);
2185 $entry[$field['id']] = $value;
2186 GFAPI::update_entry_field($entry['id'], $field['id'], $value);
2187 }
2188 }
2189 }
2190 return $entry;
2191 }
2192
2193 // gform notification filter
2194 public function filter_gform_notification($notification, $form, $entry) {
2195
2196 $content = isset($notification['message']) && $notification['message'] ? $notification['message'] : '';
2197
2198 if (false === strpos($content, '[')) {
2199 return $notification;
2200 }
2201
2202 // conditional shortcode fix since 1.13.18
2203 $shortcode_tags = array(
2204 'gravityforms',
2205 );
2206 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
2207 $tagnames = array_intersect($shortcode_tags, $matches[1]);
2208 if (!empty($tagnames)) {
2209 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
2210 foreach ($shortcodes[0] as $key => $shortcode_value) {
2211 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
2212 $conditional_shortcode_tags = array(
2213 'e2pdf-download',
2214 'e2pdf-save',
2215 'e2pdf-view',
2216 'e2pdf-adobesign',
2217 'e2pdf-attachment',
2218 'e2pdf-zapier',
2219 );
2220 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $shortcode[5], $conditional_matches);
2221 $conditional_tagnames = array_intersect($conditional_shortcode_tags, $conditional_matches[1]);
2222 $atts = shortcode_parse_atts($shortcode[3]);
2223 if (isset($atts['action']) && $atts['action'] == 'conditional' && !empty($conditional_tagnames)) {
2224 $shortcode[5] = '1';
2225 if (class_exists('GFCommon')) {
2226 $shortcode[3] = GFCommon::replace_variables($shortcode[3], $form, $entry, false, false, false, 'text');
2227 }
2228 $value = do_shortcode_tag($shortcode);
2229 if ($value !== '1') {
2230 $content = str_replace($shortcode_value, '', $content);
2231 }
2232 }
2233 }
2234 }
2235
2236 $shortcode_tags = array(
2237 'e2pdf-download',
2238 'e2pdf-save',
2239 'e2pdf-view',
2240 'e2pdf-adobesign',
2241 'e2pdf-attachment',
2242 'e2pdf-zapier',
2243 );
2244 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
2245 $tagnames = array_intersect($shortcode_tags, $matches[1]);
2246 if (!empty($tagnames)) {
2247 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
2248 foreach ($shortcodes[0] as $key => $shortcode_value) {
2249 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
2250 $atts = shortcode_parse_atts($shortcode[3]);
2251 if (!isset($atts['dataset']) && isset($atts['id'])) {
2252 $template = new Model_E2pdf_Template();
2253 $template->load($atts['id']);
2254 if ($template->get('extension') === 'gravity') {
2255 $entry_id = $entry && isset($entry['id']) ? $entry['id'] : false;
2256 if ($entry_id) {
2257 $atts['dataset'] = $entry_id;
2258 $shortcode[3] .= ' dataset="' . $entry_id . '"';
2259 }
2260 }
2261 }
2262 if (!isset($atts['apply'])) {
2263 $shortcode[3] .= ' apply="true"';
2264 }
2265 if (!isset($atts['filter'])) {
2266 $shortcode[3] .= ' filter="true"';
2267 }
2268 $file = false;
2269 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) {
2270 if (class_exists('GFCommon')) {
2271 add_filter('gform_merge_tag_filter', array($this, 'filter_gform_merge_tag_filter_attributes'), 30, 5);
2272 $shortcode[3] = GFCommon::replace_variables($shortcode[3], $form, $entry, false, false, false, 'text');
2273 remove_filter('gform_merge_tag_filter', array($this, 'filter_gform_merge_tag_filter_attributes'), 30);
2274 }
2275 $file = do_shortcode_tag($shortcode);
2276 if ($file) {
2277 $tmp = false;
2278 if (substr($file, 0, 4) === 'tmp:') {
2279 $file = substr($file, 4);
2280 $tmp = true;
2281 }
2282 if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
2283 if ($tmp) {
2284 $this->helper->add('gravity_attachments', $file);
2285 }
2286 } else {
2287 $this->helper->add('gravity_attachments', $file);
2288 }
2289 $notification['attachments'] = (is_array(rgget('attachments', $notification))) ? rgget('attachments', $notification) : array();
2290 $notification['attachments'][] = $file;
2291 }
2292 $notification['message'] = str_replace($shortcode_value, '', $notification['message']);
2293 } else {
2294 $notification['message'] = str_replace($shortcode_value, '[' . $shortcode[2] . $shortcode[3] . ']', $notification['message']);
2295 }
2296 }
2297 }
2298 return $notification;
2299 }
2300
2301 // filter content
2302 public function filter_content($content = '', $entry_id = 0, $do_shortcode = false, $type = '') {
2303 if (is_array($content) || false === strpos($content, '[')) {
2304 return $content;
2305 }
2306 $shortcode_tags = array(
2307 'e2pdf-download',
2308 'e2pdf-save',
2309 'e2pdf-view',
2310 'e2pdf-adobesign',
2311 'e2pdf-zapier',
2312 );
2313 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
2314 $tagnames = array_intersect($shortcode_tags, $matches[1]);
2315 if (!empty($tagnames)) {
2316 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
2317 foreach ($shortcodes[0] as $key => $shortcode_value) {
2318 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
2319 $atts = shortcode_parse_atts($shortcode[3]);
2320 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
2321 } else {
2322 if (!isset($atts['dataset']) && isset($atts['id'])) {
2323 $template = new Model_E2pdf_Template();
2324 $template->load($atts['id']);
2325 if ($template->get('extension') === 'gravity') {
2326 if ($entry_id) {
2327 $atts['dataset'] = $entry_id;
2328 $shortcode[3] .= ' dataset="' . $entry_id . '"';
2329 }
2330 }
2331 }
2332 if (!isset($atts['apply'])) {
2333 $shortcode[3] .= ' apply="true"';
2334 }
2335 if (!isset($atts['filter'])) {
2336 $shortcode[3] .= ' filter="true"';
2337 }
2338 if (!isset($atts['iframe_download']) && $type == 'message') {
2339 $shortcode[3] .= ' iframe_download="true"';
2340 }
2341 if ($do_shortcode) {
2342 $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content);
2343 } else {
2344 $content = str_replace($shortcode_value, '[' . $shortcode[2] . $shortcode[3] . ']', $content);
2345 }
2346 }
2347 }
2348 }
2349 return $content;
2350 }
2351
2352 // gform pre render filter
2353 public function filter_gform_pre_render($form) {
2354 if (isset($form['fields'])) {
2355 foreach ($form['fields'] as $key => $field) {
2356 if ($field->pageNumber != '1') {
2357 $field->pageNumber = '1';
2358 $form['fields'][$key] = $field;
2359 }
2360 }
2361 }
2362 return $form;
2363 }
2364
2365 // merge tag attributes filter
2366 public function filter_gform_merge_tag_filter_attributes($value, $merge_tag, $modifier, $field, $raw_value) {
2367 if ($value) {
2368 return esc_attr($value);
2369 }
2370 return $value;
2371 }
2372
2373 // merge tag args filter
2374 public function filter_gform_merge_tag_filter_tags($value, $merge_tag, $modifier, $field, $raw_value) {
2375
2376 if ($field && $value) {
2377 if ($field->type == 'consent') {
2378 if (false !== strpos($modifier, 'filter') && is_callable('gw_all_fields_template')) {
2379 $modifiers = gw_all_fields_template()->parse_modifiers($modifier);
2380 if (isset($modifiers['filter']) && $modifiers['filter'] && !is_array($modifiers['filter'])) {
2381 $merge_tag = $modifiers['filter'];
2382 }
2383 }
2384 $mod = explode('.', $merge_tag);
2385 if (isset($mod[1]) && $mod[1] == '1') {
2386 $value = '1';
2387 }
2388 } elseif ($field->type == 'list') {
2389 if (false !== strpos($modifier, 'filter') && is_callable('gw_all_fields_template')) {
2390 $modifiers = gw_all_fields_template()->parse_modifiers($modifier);
2391 if (isset($modifiers['filter']) && $modifiers['filter'] && !is_array($modifiers['filter'])) {
2392 if (false !== strpos($modifiers['filter'], ':')) {
2393 $mods = explode(':', $modifiers['filter']);
2394 $merge_tag = $mods[0];
2395 $modifier = $mods[1];
2396 } else {
2397 $merge_tag = $modifiers['filter'];
2398 }
2399 }
2400 if ($merge_tag != $field->id) {
2401 return false;
2402 }
2403 }
2404
2405 if ($modifier && $modifier != 'text') {
2406 $list_id = false;
2407 $field_id = false;
2408 if (false !== strpos($modifier, '_')) {
2409 $mod = explode('_', $modifier);
2410 if (isset($mod[0]) && is_numeric($mod[0])) {
2411 $list_id = $mod[0] - 1;
2412 }
2413 if (isset($mod[1]) && is_numeric($mod[1])) {
2414 $field_id = $mod[1] - 1;
2415 }
2416 } elseif (is_numeric($modifier)) {
2417 $list_id = $modifier - 1;
2418 }
2419 if ($list_id !== false) {
2420 $value = '';
2421 if (is_serialized($raw_value)) {
2422 $list = $this->helper->load('convert')->unserialize(trim($raw_value));
2423 } else {
2424 $list = $raw_value;
2425 }
2426 if (is_array($list)) {
2427 if (isset($list[$list_id])) {
2428 if ($field_id !== false) {
2429 if (is_array($list[$list_id]) && isset(array_values($list[$list_id])[$field_id])) {
2430 $value = array_values($list[$list_id])[$field_id];
2431 }
2432 } else {
2433 if (is_array($list[$list_id])) {
2434 $value = implode(',', $list[$list_id]);
2435 } else {
2436 $value = $list[$list_id];
2437 }
2438 }
2439 }
2440 }
2441 }
2442 }
2443 } elseif ($field->type == 'name' || $field->type == 'address') {
2444 if (false !== strpos($modifier, 'filter') && is_callable('gw_all_fields_template')) {
2445 $modifiers = gw_all_fields_template()->parse_modifiers($modifier);
2446 if (isset($modifiers['filter']) && $modifiers['filter'] && !is_array($modifiers['filter'])) {
2447 if (is_array($raw_value) && isset($raw_value[$modifiers['filter']])) {
2448 return $raw_value[$modifiers['filter']];
2449 }
2450 }
2451 }
2452 } elseif ($field->type == 'repeater') {
2453 if (false !== strpos($modifier, 'repeater')) {
2454 $modifiers = explode(',', $modifier);
2455 foreach ($modifiers as $filter) {
2456 if (preg_match('/^repeater(?:\.\d+)+$/', $filter)) {
2457 $value = '';
2458 $path = explode('.', $filter);
2459 if (apply_filters('e2pdf_for_do_shortcode_data_process', false)) {
2460 array_shift($path);
2461 $lead = $this->helper->load('shortcode')->apply_path_attribute($raw_value, implode('.', $path));
2462 if (!empty($lead)) {
2463 $value = serialize($lead); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
2464 }
2465 } else {
2466 $merge_field_id = end($path);
2467 array_shift($path);
2468 array_pop($path);
2469 if (!empty($path)) {
2470 $lead = $this->helper->load('shortcode')->apply_path_attribute($raw_value, implode('.', $path));
2471 if (!empty($lead)) {
2472 $filters = preg_replace('/repeater(?:\.\d+)+,?/', '', $modifier);
2473 $merge_tag = '{:' . $merge_field_id . ($filters ? ':' . $filters : '') . '}';
2474 $value = GFCommon::replace_variables($merge_tag, $this->get('cached_form'), $lead, false, false, false, 'text');
2475 }
2476 }
2477 }
2478 break;
2479 }
2480 }
2481 } elseif (apply_filters('e2pdf_for_do_shortcode_data_process', false)) {
2482 $value = serialize($raw_value); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
2483 }
2484 } elseif (false !== strpos($modifier, 'json')) {
2485 $modifiers = explode(',', $modifier);
2486 foreach ($modifiers as $filter) {
2487 if ($filter == 'json') {
2488 $value = '';
2489 if (!empty($raw_value)) {
2490 $json = @json_decode($raw_value, true); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
2491 if (!empty($json)) {
2492 if (is_array($json)) {
2493 $value = serialize($json); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
2494 } else {
2495 $value = $json;
2496 }
2497 }
2498 }
2499 break;
2500 }
2501 }
2502 }
2503 }
2504 return $value;
2505 }
2506
2507 // delete attachments
2508 public function action_gform_after_email($is_success) {
2509
2510 $files = $this->helper->get('gravity_attachments');
2511 if (is_array($files) && !empty($files)) {
2512 foreach ($files as $key => $file) {
2513 $this->helper->delete_dir(dirname($file) . '/');
2514 }
2515 $this->helper->deset('gravity_attachments');
2516 }
2517 }
2518
2519 // after update entry action
2520 public function action_gform_after_update_entry($form, $entry_id) {
2521 if (isset($form['fields'])) {
2522 foreach ($form['fields'] as $key => $field) {
2523 if (isset($field->defaultValue) && (false !== strpos($field->defaultValue, '[e2pdf-download') || false !== strpos($field->defaultValue, '[e2pdf-save'))) {
2524 $entry = GFFormsModel::get_entry($entry_id);
2525 if ($entry && !is_wp_error($entry) && is_array($entry)) {
2526 if (!rgar($entry, $field['id'])) {
2527 $value = $this->filter_content($field->defaultValue, $entry_id, true);
2528 $entry[$field['id']] = $value;
2529 GFAPI::update_entry_field($entry['id'], $field['id'], $value);
2530 }
2531 }
2532 }
2533 }
2534 }
2535 }
2536
2537 // styles
2538 public function styles($item_id = false) {
2539 $styles = array();
2540 if (class_exists('GFCommon') && class_exists('GFForms')) {
2541 $base_url = GFCommon::get_base_url();
2542 $base_path = GFCommon::get_base_path();
2543 $version = GFForms::$version;
2544 $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
2545 if (file_exists($base_path . '/legacy/css/')) {
2546 $styles[] = $base_url . '/legacy/css/formreset' . $min . '.css?ver=' . $version;
2547 $styles[] = $base_url . '/legacy/css/datepicker' . $min . '.css?ver=' . $version;
2548 $styles[] = $base_url . '/legacy/css/formsmain' . $min . '.css?ver=' . $version;
2549 $styles[] = $base_url . '/legacy/css/readyclass' . $min . '.css?ver=' . $version;
2550 $styles[] = $base_url . '/legacy/css/browsers' . $min . '.css?ver=' . $version;
2551 $styles[] = $base_url . '/legacy/css/rtl' . $min . '.css?ver=' . $version;
2552 if (version_compare($version, '2.9', '>=')) {
2553 $styles[] = $base_url . '/assets/css/dist/basic' . $min . '.css?ver=' . $version;
2554 $styles[] = $base_url . '/assets/css/dist/gravity-forms-theme-reset' . $min . '.css?ver=' . $version;
2555 $styles[] = $base_url . '/assets/css/dist/gravity-forms-theme-foundation' . $min . '.css?ver=' . $version;
2556 $styles[] = $base_url . '/assets/css/dist/gravity-forms-theme-framework' . $min . '.css?ver=' . $version;
2557 $styles[] = $base_url . '/assets/css/dist/gravity-forms-orbital-theme' . $min . '.css?ver=' . $version;
2558 }
2559 } else {
2560 $styles[] = $base_url . '/css/formreset' . $min . '.css?ver=' . $version;
2561 $styles[] = $base_url . '/css/datepicker' . $min . '.css?ver=' . $version;
2562 $styles[] = $base_url . '/css/formsmain' . $min . '.css?ver=' . $version;
2563 $styles[] = $base_url . '/css/readyclass' . $min . '.css?ver=' . $version;
2564 $styles[] = $base_url . '/css/browsers' . $min . '.css?ver=' . $version;
2565 $styles[] = $base_url . '/css/rtl' . $min . '.css?ver=' . $version;
2566 }
2567 $styles[] = plugins_url('css/extension/gravity.css?v=' . time(), $this->helper->get('plugin_file_path'));
2568 }
2569 return $styles;
2570 }
2571
2572 public function hook_gravity_entry_view($metaboxes, $entry, $form) {
2573 if (!empty($form['id'])) {
2574 $hooks = $this->helper->load('hooks')->get('gravity', 'hook_gravity_entry_view', $form['id']);
2575 if (!empty($hooks)) {
2576 $metaboxes['e2pdf'] = array(
2577 'title' => apply_filters('e2pdf_hook_section_title', __('E2Pdf Actions', 'e2pdf'), 'hook_gravity_entry_view'),
2578 'callback' => array($this, 'hook_gravity_entry_view_callback'),
2579 'context' => 'side',
2580 'callback_args' => array(
2581 'entry' => $entry,
2582 'hooks' => $hooks,
2583 ),
2584 );
2585 }
2586 }
2587 return $metaboxes;
2588 }
2589
2590 // entry view callback hook
2591 public function hook_gravity_entry_view_callback($post, $metabox) {
2592 if (!empty($metabox['args']['entry']['id'])) {
2593 foreach ($metabox['args']['hooks'] as $hook) {
2594 if ($this->helper->load('hooks')->process_hook(
2595 $hook,
2596 [
2597 'dataset' => $metabox['args']['entry']['id'],
2598 ],
2599 'hook_gravity_entry_view'
2600 )
2601 ) {
2602 $action = apply_filters(
2603 'e2pdf_hook_action_button',
2604 array(
2605 'html' => '<div class="misc-pub-section"><a class="e2pdf-download-hook" target="_blank" title="%2$s" href="%1$s"><span class="dashicons dashicons-pdf"></span> %2$s</a></div>',
2606 'url' => $this->helper->get_url(
2607 array(
2608 'page' => 'e2pdf',
2609 'action' => 'export',
2610 'id' => $hook,
2611 'dataset' => $metabox['args']['entry']['id'],
2612 ), 'admin.php?'
2613 ),
2614 'title' => 'PDF #' . $hook,
2615 ), 'hook_gravity_entry_view', $hook, $metabox['args']['entry']['id']
2616 );
2617 if (!empty($action)) {
2618 echo sprintf(
2619 $action['html'], $action['url'], $action['title']
2620 );
2621 }
2622 }
2623 }
2624 }
2625 }
2626
2627 // row actions hook
2628 public function hook_gravity_row_actions($form_id, $field_id, $value, $entry) {
2629 if (!empty($entry['form_id']) && !empty($entry['id'])) {
2630 $hooks = $this->helper->load('hooks')->get('gravity', 'hook_gravity_row_actions', $entry['form_id']);
2631 foreach ($hooks as $hook) {
2632 if ($this->helper->load('hooks')->process_hook(
2633 $hook,
2634 [
2635 'dataset' => $entry['id'],
2636 ],
2637 'hook_gravity_row_actions'
2638 )
2639 ) {
2640 $action = apply_filters(
2641 'e2pdf_hook_action_button',
2642 array(
2643 'html' => '<span> | <a class="e2pdf-download-hook" target="_blank" href="%s">%s</a></span>',
2644 'url' => $this->helper->get_url(
2645 array(
2646 'page' => 'e2pdf',
2647 'action' => 'export',
2648 'id' => $hook,
2649 'dataset' => $entry['id'],
2650 ), 'admin.php?'
2651 ),
2652 'title' => 'PDF #' . $hook,
2653 ), 'hook_gravity_row_actions', $hook, $entry['id']
2654 );
2655 if (!empty($action)) {
2656 echo sprintf(
2657 $action['html'], $action['url'], $action['title']
2658 );
2659 }
2660 }
2661 }
2662 }
2663 }
2664
2665 // get field merge tags
2666 public function get_field_merge_tags($merged_tags, $field, $repeater = null, $repeaters = array()) {
2667 $tags = GFCommon::get_field_merge_tags($field);
2668 foreach ($tags as $tag) {
2669 if (isset($tag['tag'])) {
2670 if ($field->type == 'list') {
2671 $field_id = preg_replace('/\{(?:.*)\:(.*)\:\}/', '${1}', $tag['tag']);
2672 } else {
2673 $field_id = preg_replace('/\{(?:.*)\:(.*)\}/', '${1}', $tag['tag']);
2674 }
2675 if ($field_id) {
2676 if ($this->get('nested')) {
2677 $merged_tags[$field_id] = $this->get('nested');
2678 } elseif ($field->type == 'repeater') {
2679 $merged_tags[$field_id] = $tag['tag'];
2680 if (!empty($field->fields)) {
2681 foreach ($field->fields as $sub_field) {
2682 $sub_value = isset($sub_field->label) ? $sub_field->label : '';
2683 if ($repeater) {
2684 $sub_value .= isset($repeater->id) ? ':' . $repeater->id : '';
2685 } else {
2686 $sub_value .= isset($field->id) ? ':' . $field->id : '';
2687 }
2688 if ($sub_value) {
2689 $merged_tags[$sub_field->id] = '{' . $sub_value . ':repeater' . (!empty($repeaters) ? '.0.' . implode('.0', $repeaters) : '') . '.0.' . $sub_field->id . '}';
2690 }
2691 if (isset($sub_field->type) && $sub_field->type == 'repeater') {
2692 if (isset($sub_field->id)) {
2693 $repeaters[] = $sub_field->id;
2694 if ($repeater) {
2695 $merged_tags = $this->get_field_merge_tags($merged_tags, $sub_field, $repeater, $repeaters);
2696 } else {
2697 $merged_tags = $this->get_field_merge_tags($merged_tags, $sub_field, $field, $repeaters);
2698 }
2699 }
2700 }
2701 }
2702 }
2703 } else {
2704 $merged_tags[$field_id] = $tag['tag'];
2705 }
2706 }
2707 }
2708 }
2709 return $merged_tags;
2710 }
2711
2712 // get form fields
2713 public function get_form_fields($form_fields, $fields) {
2714 foreach ($fields as $field) {
2715 $form_fields[$field->id] = $field;
2716 if (!empty($field->fields)) {
2717 $form_fields = $this->get_form_fields($form_fields, $field->fields);
2718 }
2719 }
2720 return $form_fields;
2721 }
2722 }
2723