PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.56
E2Pdf – Export Pdf Tool for WordPress v1.32.56
1.32.55 1.32.56 1.32.53 1.32.51 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 All 76 releases
e2pdf / classes / extension / e2pdf-gravity.php

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

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