PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.08.00
E2Pdf – Export Pdf Tool for WordPress v1.08.00
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-forminator.php

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

2,443 lines 117.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * E2pdf Forminator Extension
5 *
6 * @copyright Copyright 2017 https://e2pdf.com
7 * @license GPL v2
8 * @version 1
9 * @link https://e2pdf.com
10 * @since 01.01.01
11 */
12 if (!defined('ABSPATH')) {
13 die('Access denied.');
14 }
15
16 class Extension_E2pdf_Forminator extends Model_E2pdf_Model {
17
18 private $options;
19 private $info = array(
20 'key' => 'forminator',
21 'title' => 'Forminator'
22 );
23
24 function __construct() {
25 parent::__construct();
26 }
27
28 /**
29 * Get info about extension
30 *
31 * @param string $key - Key to get assigned extension info value
32 *
33 * @return array|string - Extension Key and Title or Assigned extension info value
34 */
35 public function info($key = false) {
36 if ($key && isset($this->info[$key])) {
37 return $this->info[$key];
38 } else {
39 return array(
40 $this->info['key'] => $this->info['title']
41 );
42 }
43 }
44
45 public function active() {
46
47 if (!function_exists('is_plugin_active')) {
48 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
49 }
50
51 if (is_plugin_active('forminator/forminator.php')) {
52 return true;
53 }
54 return false;
55 }
56
57 /**
58 * Set option
59 *
60 * @param string $key - Key of option
61 * @param string $value - Value of option
62 *
63 * @return bool - Status of setting option
64 */
65 public function set($key, $value) {
66 if (!isset($this->options)) {
67 $this->options = new stdClass();
68 }
69
70 $this->options->$key = $value;
71 return true;
72 }
73
74 /**
75 * Get option by key
76 *
77 * @param string $key - Key to get assigned option value
78 *
79 * @return mixed
80 */
81 public function get($key) {
82 if (isset($this->options->$key)) {
83 $value = $this->options->$key;
84 return $value;
85 } elseif ($key == 'args') {
86 return array();
87 } else {
88 return false;
89 }
90 }
91
92 /**
93 * Get items to work with
94 *
95 * @return array() - List of available items
96 */
97 public function items() {
98 $content = array();
99 if (class_exists("Forminator_API")) {
100 $forms = Forminator_API::get_forms();
101 foreach ($forms as $key => $value) {
102 $content[] = $this->item($value->id);
103 }
104 }
105 return $content;
106 }
107
108 /**
109 * Get entries for export
110 *
111 * @param int $item - Form ID
112 * @param string $name - Entries names
113 *
114 * @return array() - Entries list
115 */
116 public function datasets($item = false, $name = false) {
117
118 $datasets = array();
119
120 if (class_exists("Forminator_API") && $item) {
121 $entries = Forminator_API::get_entries($item);
122 foreach ($entries as $key => $dataset) {
123 $this->set('item', $item);
124 $this->set('dataset', $dataset->entry_id);
125
126 $dataset_title = $this->render($name);
127 if (!$dataset_title) {
128 $dataset_title = $dataset->entry_id;
129 }
130 $datasets[] = array(
131 'key' => $dataset->entry_id,
132 'value' => $dataset_title
133 );
134 }
135 }
136
137 return $datasets;
138 }
139
140 /**
141 * Get dataset
142 *
143 * @param int $dataset - Dataset ID
144 *
145 * @return object - Dataset
146 */
147 public function dataset($dataset = false) {
148 $dataset = (int) $dataset;
149
150 if (!$dataset) {
151 return false;
152 }
153
154 $data = new stdClass();
155 $data->url = false;
156
157 return $data;
158 }
159
160 /**
161 * Get item
162 *
163 * @param string $item - Item ID
164 *
165 * @return object - Item
166 */
167 public function item($item = false) {
168
169 $form = new stdClass();
170
171 if (!$item && $this->get('item')) {
172 $item = $this->get('item');
173 }
174
175 $forminator_form = false;
176 if (class_exists("Forminator_API")) {
177 $forminator_form = Forminator_API::get_form($item);
178 }
179
180 if (!is_wp_error($forminator_form)) {
181 $form->id = (string) $item;
182 $form->url = $this->helper->get_url(array('page' => 'forminator-cform-wizard', 'id' => $forminator_form->id));
183 $form->name = $forminator_form->name;
184 } else {
185 $form->id = '';
186 $form->url = 'javascript:void(0);';
187 $form->name = '';
188 }
189 return $form;
190 }
191
192 /**
193 * Render value according to content
194 *
195 * @param string $value - Content
196 * @param string $type - Type of rendering value
197 * @param string $field - Field
198 *
199 * @return string - Fully rendered value
200 */
201 public function render($value, $type = false, $field = array()) {
202
203 $value = $this->render_shortcodes($value, $type, $field);
204 $value = $this->strip_shortcodes($value);
205
206 if ($type === 'value' && isset($field['type']) && $field['type'] === 'e2pdf-checkbox' && isset($field['properties']['option'])) {
207 $option = $this->render($field['properties']['option']);
208 $options = explode(', ', $value);
209 $option_options = explode(', ', $option);
210 if (is_array($options) && is_array($option_options) && !array_diff($option_options, $options)) {
211 return $option;
212 } else {
213 return "";
214 }
215 }
216
217 if ($type === 'value') {
218 $value = $this->convert_shortcodes($value, true);
219 }
220
221 return $value;
222 }
223
224 /**
225 * Render shortcodes which available in this extension
226 *
227 * @param string $type - Type of rendering value
228 * @param string $value - Content
229 *
230 * @return string - Value with rendered shortcodes
231 */
232 public function render_shortcodes($value, $type = false, $field = array()) {
233
234 $dataset = $this->get('dataset');
235 $item = $this->get('item');
236 $user_id = $this->get('user_id');
237 $args = $this->get('args');
238 $template_id = $this->get('template_id') ? $this->get('template_id') : '0';
239 $element_id = isset($field['element_id']) ? $field['element_id'] : '0';
240
241 if ($this->verify() && function_exists("forminator_replace_form_data") && class_exists("Forminator_API")) {
242
243 $args = apply_filters('e2pdf_extension_render_shortcodes_args', $args, $element_id, $template_id, $item, $dataset);
244
245 $form = Forminator_API::get_form($item);
246
247 $metas = array();
248 $data = array();
249
250 if ($form->is_prevent_store()) {
251 if (class_exists('Forminator_Form_Entry_Model')) {
252 $entry = new Forminator_Form_Entry_Model();
253 if ($this->get('field_data_array') && is_array($this->get('field_data_array'))) {
254 $entry->set_fields($this->get('field_data_array'));
255 $metas = $entry->meta_data;
256 }
257 } else {
258 $entry = null;
259 }
260 } else {
261 $entry = Forminator_API::get_entry($item, $dataset);
262 $metas = $entry->meta_data;
263 }
264
265 foreach ($metas as $key => $meta) {
266 if (is_array($meta['value'])) {
267 if (array_unique(array_map("is_int", array_keys($meta['value']))) === array(true)) {
268 $data[$key] = $meta['value'];
269 } else {
270 if (isset($meta['value']['file']['file_url'])) {
271 $data[$key] = $meta['value']['file']['file_url'];
272 } else {
273 foreach ($meta['value'] as $sub_key => $sub_meta) {
274 $data[$key . "-" . $sub_key] = $sub_meta;
275 }
276 }
277 }
278 } else {
279 $data[$key] = $meta['value'];
280 }
281 }
282
283 if (false !== strpos($value, '[')) {
284
285 $shortcode_tags = array(
286 'e2pdf-user',
287 'e2pdf-arg'
288 );
289 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches);
290 $tagnames = array_intersect($shortcode_tags, $matches[1]);
291
292 if (!empty($tagnames)) {
293
294 $pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames);
295
296 preg_match_all("/$pattern/", $value, $shortcodes);
297
298 foreach ($shortcodes[0] as $key => $shortcode_value) {
299 $shortcode = array();
300 $shortcode[1] = $shortcodes[1][$key];
301 $shortcode[2] = $shortcodes[2][$key];
302 $shortcode[3] = $shortcodes[3][$key];
303 $shortcode[4] = $shortcodes[4][$key];
304 $shortcode[5] = $shortcodes[5][$key];
305 $shortcode[6] = $shortcodes[6][$key];
306
307 $atts = shortcode_parse_atts($shortcode[3]);
308
309 if ($shortcode['2'] == 'e2pdf-user') {
310 if (!isset($atts['id']) && $user_id) {
311 $shortcode[3] .= " id=\"" . $user_id . "\"";
312 $value = str_replace($shortcode_value, "[" . $shortcode['2'] . $shortcode['3'] . "]", $value);
313 }
314 } elseif ($shortcode['2'] == 'e2pdf-arg') {
315 if (isset($atts['key']) && isset($args[$atts['key']])) {
316 $sub_value = $this->strip_shortcodes($args[$atts['key']]);
317 $value = str_replace($shortcode_value, $sub_value, $value);
318 } else {
319 $value = str_replace($shortcode_value, '', $value);
320 }
321 }
322 }
323 }
324
325 $shortcode_tags = array(
326 'e2pdf-format-number',
327 'e2pdf-format-date',
328 'e2pdf-format-output',
329 );
330 $shortcode_tags = apply_filters('e2pdf_extension_render_shortcodes_tags', $shortcode_tags);
331 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches);
332 $tagnames = array_intersect($shortcode_tags, $matches[1]);
333
334 if (!empty($tagnames)) {
335
336 $pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames);
337
338 preg_match_all("/$pattern/", $value, $shortcodes);
339 foreach ($shortcodes[0] as $key => $shortcode_value) {
340 $shortcode = array();
341 $shortcode[1] = $shortcodes[1][$key];
342 $shortcode[2] = $shortcodes[2][$key];
343 $shortcode[3] = $shortcodes[3][$key];
344 $shortcode[4] = $shortcodes[4][$key];
345 $shortcode[5] = $shortcodes[5][$key];
346 $shortcode[6] = $shortcodes[6][$key];
347
348 if (!$shortcode['5']) {
349 $sub_value = '';
350 } elseif (isset($field['type']) && ($field['type'] === 'e2pdf-image' || $field['type'] === 'e2pdf-signature')) {
351 $sub_value = $this->render($shortcode['5'], $type);
352 } else {
353 $sub_value = $this->render($shortcode['5'], $type, $field);
354 }
355 $value = str_replace($shortcode_value, "[" . $shortcode['2'] . $shortcode['3'] . "]" . $sub_value . "[/" . $shortcode['2'] . "]", $value);
356 }
357 }
358 }
359
360 $value = do_shortcode($value);
361 $value = forminator_replace_form_data($value, $data, $form, $entry);
362 $value = forminator_replace_variables($value, $item);
363
364 if (isset($field['type']) && ($field['type'] === 'e2pdf-image' || $field['type'] === 'e2pdf-signature')) {
365 $esig = isset($field['properties']['esig']) && $field['properties']['esig'] ? true : false;
366 if ($esig) {
367 //process e-signature
368 $value = "";
369 } else {
370
371 if (isset($field['properties']['preg_pattern']) && $field['properties']['preg_pattern'] && isset($field['properties']['preg_replacement']) && $value) {
372 $value = $this->helper->load('convert')->preg_replace($field['properties']['preg_pattern'], $field['properties']['preg_replacement'], $value);
373 }
374
375 if (!$this->helper->load('image')->get_image($value)) {
376 $value = $this->strip_shortcodes($value);
377 if (
378 $value &&
379 trim($value) != "" &&
380 extension_loaded('gd') &&
381 function_exists('imagettftext')
382 ) {
383 if (isset($field['properties']['text_color']) && $field['properties']['text_color']) {
384 $penColour = $this->helper->load('convert')->to_hex_color($field['properties']['text_color']);
385 } else {
386 $penColour = array(0x14, 0x53, 0x94);
387 }
388
389 $default_options = array(
390 'imageSize' => array(isset($field['width']) ? $field['width'] : '400', isset($field['height']) ? $field['height'] : '150'),
391 'bgColour' => 'transparent',
392 'penColour' => $penColour
393 );
394
395 $options = array();
396 $options = apply_filters('e2pdf_image_sig_output_options', $options, $element_id, $template_id);
397 $options = array_merge($default_options, $options);
398
399 $model_e2pdf_font = new Model_E2pdf_Font();
400
401 $font = false;
402 if (isset($field['properties']['text_font']) && $field['properties']['text_font']) {
403 $font = $model_e2pdf_font->get_font_path($field['properties']['text_font']);
404 }
405
406 if (!$font) {
407 $font = $model_e2pdf_font->get_font_path('Noto Sans');
408 }
409
410 $size = 150;
411 if (isset($field['properties']['text_font_size']) && $field['properties']['text_font_size']) {
412 $size = $field['properties']['text_font_size'];
413 }
414
415 $model_e2pdf_signature = new Model_E2pdf_Signature();
416 $value = $model_e2pdf_signature->ttf_signature($value, $size, $font, $options);
417 } else {
418 $value = "";
419 }
420 }
421 }
422 } else {
423
424 $value = $this->convert_shortcodes($value);
425
426 if (isset($field['properties']['preg_pattern']) && $field['properties']['preg_pattern'] && isset($field['properties']['preg_replacement']) && $value) {
427 $value = $this->helper->load('convert')->preg_replace($field['properties']['preg_pattern'], $field['properties']['preg_replacement'], $value);
428 }
429 }
430 }
431
432 $value = apply_filters('e2pdf_extension_render_shortcodes_value', $value, $element_id, $template_id, $item, $dataset);
433
434 return $value;
435 }
436
437 /**
438 * Strip unused shortcodes
439 *
440 * @param string $value - Content
441 *
442 * @return string - Value with removed unused shortcodes
443 */
444 public function strip_shortcodes($value) {
445 $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', "", $value);
446 $value = preg_replace('~(?:{/?)[^/}]+/?}~s', "", $value);
447 return $value;
448 }
449
450 /**
451 * Convert "shortcodes" inside value string
452 *
453 * @param string $value - Value string
454 * @param bool $to - Convert From/To
455 *
456 * @return string - Converted value
457 */
458 public function convert_shortcodes($value, $to = false) {
459 if ($value) {
460 if ($to) {
461 $value = str_replace("&#91;", "[", $value);
462 //$value = str_replace("&#37;", "%", $value);
463 } else {
464 $value = str_replace("[", "&#91;", $value);
465 //$value = str_replace("%", "&#37;", $value);
466 }
467 }
468 return $value;
469 }
470
471 /**
472 * Verify if item and dataset exists
473 *
474 * @return bool - item and dataset exists
475 */
476 public function verify() {
477 $item = $this->get('item');
478 $dataset = $this->get('dataset');
479
480 if ($item && $dataset && class_exists('Forminator_API')) {
481 $form = Forminator_API::get_form($item);
482 if (!is_wp_error($form)) {
483 if ($form->is_prevent_store()) {
484 if ($dataset == 'is_prevent_store') {
485 return true;
486 }
487 } else {
488 $entry = Forminator_API::get_entry($item, $dataset);
489 if (!is_wp_error($entry)) {
490 return true;
491 }
492 }
493 }
494 }
495 return false;
496 }
497
498 public function auto_form($template, $data = array()) {
499
500 if ($template->get('ID')) {
501
502 $auto_form_label = isset($data['auto_form_label']) && $data['auto_form_label'] ? $data['auto_form_label'] : false;
503 $auto_form_shortcode = isset($data['auto_form_shortcode']) ? true : false;
504
505 $wrappers = array();
506
507 $pages = $template->get('pages');
508
509 $checkboxes = array();
510 $radios = array();
511
512 foreach ($pages as $page_key => $page) {
513 if (isset($page['elements']) && !empty($page['elements'])) {
514 foreach ($page['elements'] as $element_key => $element) {
515
516 $type = false;
517 $label = '';
518
519 if ($element['type'] == 'e2pdf-input' || $element['type'] == 'e2pdf-signature') {
520 $type = 'text';
521 $label = __('Text', 'e2pdf');
522 } elseif ($element['type'] == 'e2pdf-textarea') {
523 $type = 'textarea';
524 $label = __('Textarea', 'e2pdf');
525 } elseif ($element['type'] == 'e2pdf-select') {
526
527 $type = 'select';
528 $label = __('Select', 'e2pdf');
529
530 $options = array();
531 $field_options = array();
532
533 if (isset($element['properties']['options'])) {
534 $field_options = explode("\n", $element['properties']['options']);
535 foreach ($field_options as $option) {
536 $options[] = array(
537 'label' => $option,
538 'value' => ''
539 );
540 }
541 }
542 } elseif ($element['type'] == 'e2pdf-checkbox') {
543 $field_key = array_search($element['name'], array_column($checkboxes, 'name'));
544 if ($field_key !== false) {
545 $checkboxes[$field_key]['options'][] = array(
546 'label' => $element['properties']['option'],
547 'value' => $element['properties']['option'],
548 );
549 $pages[$page_key]['elements'][$element_key]['value'] = '{checkbox-' . $checkboxes[$field_key]['element_id'] . '}';
550 } else {
551 $type = 'checkbox';
552 $label = __('Checkbox', 'e2pdf');
553 $options = array(
554 'label' => $element['properties']['option'],
555 'value' => $element['properties']['option'],
556 );
557 }
558 } elseif ($element['type'] == 'e2pdf-radio') {
559 if (isset($element['properties']['group']) && $element['properties']['group']) {
560 $element['name'] = $element['properties']['group'];
561 } else {
562 $element['name'] = $element['element_id'];
563 }
564
565 $field_key = array_search($element['name'], array_column($radios, 'name'));
566 if ($field_key !== false) {
567 $radios[$field_key]['options'][] = array(
568 'label' => $element['properties']['option'],
569 'value' => '',
570 );
571 $pages[$page_key]['elements'][$element_key]['value'] = '{radio-' . $radios[$field_key]['element_id'] . '}';
572 } else {
573 $type = 'radio';
574 $label = __('Radio', 'e2pdf');
575 $options = array(
576 'label' => $element['properties']['option'],
577 'value' => '',
578 );
579 }
580 }
581
582 if ($type) {
583 $labels = array();
584 if ($auto_form_shortcode) {
585 $labels[] = '{' . $type . '-' . $element['element_id'] . '}';
586 }
587
588 if ($auto_form_label && $auto_form_label == 'value' && isset($element['value']) && $element['value']) {
589 $labels[] = $element['value'];
590 } elseif ($auto_form_label && $auto_form_label == 'name' && isset($element['name']) && $element['name']) {
591 $labels[] = $element['name'];
592 }
593
594 if ($type == 'checkbox' || $type == 'radio') {
595
596 $field_data = array(
597 'name' => $element['name'],
598 'element_id' => $element['element_id'],
599 'field_label' => !empty($labels) ? implode(' ', $labels) : $label,
600 'options' => array(
601 $options
602 )
603 );
604
605 if ($type == 'checkbox') {
606 $checkboxes[] = $field_data;
607 } else {
608 $radios[] = $field_data;
609 }
610 } else {
611 $field_data = array(
612 'element_id' => $type . '-' . $element['element_id'],
613 'type' => $type,
614 'cols' => '12',
615 'required' => false,
616 'field_label' => !empty($labels) ? implode(' ', $labels) : $label,
617 'placeholder' => '',
618 'validation' => false,
619 );
620
621 if ($type == 'select') {
622 $field_data['options'] = $options;
623 }
624
625 $wrappers[] = array(
626 'wrapper_id' => 'wrapper-' . mt_rand(1000000000000, 9999999999999) . '-' . mt_rand(1000, 9999),
627 'fields' => array(
628 $field_data
629 ),
630 );
631 }
632
633 $pages[$page_key]['elements'][$element_key]['value'] = '{' . $type . '-' . $element['element_id'] . '}';
634 if (isset($element['properties']['esig'])) {
635 unset($pages[$page_key]['elements'][$element_key]['properties']['esig']);
636 }
637 }
638 }
639 }
640 }
641
642 foreach ($checkboxes as $element) {
643 $wrappers[] = array(
644 'wrapper_id' => 'wrapper-' . mt_rand(1000000000000, 9999999999999) . '-' . mt_rand(1000, 9999),
645 'fields' => array(
646 array(
647 'element_id' => 'checkbox-' . $element['element_id'],
648 'type' => 'checkbox',
649 'cols' => '12',
650 'required' => false,
651 'options' => $element['options'],
652 'field_label' => $element['field_label'],
653 'placeholder' => '',
654 'validation' => false,
655 ),
656 ),
657 );
658 }
659
660 foreach ($radios as $element) {
661 $wrappers[] = array(
662 'wrapper_id' => 'wrapper-' . mt_rand(1000000000000, 9999999999999) . '-' . mt_rand(1000, 9999),
663 'fields' => array(
664 array(
665 'element_id' => 'radio-' . $element['element_id'],
666 'type' => 'radio',
667 'cols' => '12',
668 'required' => false,
669 'options' => $element['options'],
670 'field_label' => $element['field_label'],
671 'placeholder' => '',
672 'validation' => false,
673 ),
674 ),
675 );
676 }
677
678 $template->set('pages', $pages);
679 $settings = array(
680 'formName' => $template->get('title'),
681 'thankyou' => "true",
682 'thankyou-message' => sprintf(__("Success. [e2pdf-download id=\"%s\"]", 'e2pdf'), $template->get('ID')),
683 'use-custom-submit' => "true",
684 'custom-submit-text' => __("Send Message", Forminator::DOMAIN),
685 'use-custom-invalid-form' => "true",
686 'custom-invalid-form-message' => __("Error: Your form is not valid, please fix the errors!", Forminator::DOMAIN),
687 'enable-ajax' => "true",
688 'validation' => "on_submit"
689 );
690
691 if (class_exists('Forminator_API')) {
692 if ($item = Forminator_API::add_form($template->get('title'), $wrappers, $settings)) {
693 $template->set('item', $item);
694 }
695 }
696 }
697
698 return $template;
699 }
700
701 /**
702 * Init Visual Mapper data
703 *
704 * @return bool|string - HTML data source for Visual Mapper
705 */
706 public function visual_mapper() {
707
708 $item = $this->get('item');
709 $html = '';
710 $source = '';
711
712 if ($item && function_exists("forminator_form_preview") && class_exists("Forminator_API")) {
713
714 $form = Forminator_API::get_form($item);
715 if (is_wp_error($form)) {
716 return __('Form could not be found', 'e2pdf');
717 }
718
719 ob_start();
720 forminator_form_preview($item, true, array());
721 $source = ob_get_clean();
722 if (!$source) {
723 $source = forminator_form_preview($item, false, array());
724 }
725
726 if ($source) {
727 libxml_use_internal_errors(true);
728 $dom = new DOMDocument();
729 if (function_exists('mb_convert_encoding')) {
730 $html = $dom->loadHTML(mb_convert_encoding($source, 'HTML-ENTITIES', 'UTF-8'));
731 } else {
732 $html = $dom->loadHTML('<?xml encoding="UTF-8">' . $source);
733 }
734 libxml_clear_errors();
735 }
736
737 if (!$source) {
738 return __('Form source is empty', 'e2pdf');
739 } elseif (!$html) {
740 return __('Form could not be parsed due incorrect HTML', 'e2pdf');
741 } else {
742
743 $xml = $this->helper->load('xml');
744 $xml->set('dom', $dom);
745 $xpath = new DomXPath($dom);
746
747 $remove_by_class = array(
748 'forminator-pagination-submit',
749 'forminator-response-message'
750 );
751 foreach ($remove_by_class as $key => $class) {
752 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
753 foreach ($elements as $element) {
754 $element->parentNode->removeChild($element);
755 }
756 }
757
758 $remove_by_tag = array(
759 'script'
760 );
761 foreach ($remove_by_tag as $key => $tag) {
762 $elements = $xpath->query("//{$tag}");
763 foreach ($elements as $element) {
764 $element->parentNode->removeChild($element);
765 }
766 }
767
768 $inputs = $xpath->query("//*[contains(@class, 'forminator-input')]");
769 foreach ($inputs as $element) {
770 $element = $xml->set_node_value($element, 'type', 'text');
771 }
772
773 //remove pagination
774 $pagination = $xpath->query("//*[contains(@class, 'forminator-pagination')]");
775 foreach ($pagination as $element) {
776 $element = $xml->set_node_value($element, 'style', '');
777 }
778
779 //remove buttons
780 $remove_rows = $xpath->query("//*[contains(@class, 'forminator-row')][.//button[contains(@class, 'forminator-button') and not(contains(@class, 'forminator-upload-button'))]]");
781 foreach ($remove_rows as $element) {
782 $element->parentNode->removeChild($element);
783 }
784
785 //replace name on fileuploads
786 $fileuploads = $xpath->query("//*[contains(@class, 'forminator-upload')]");
787 foreach ($fileuploads as $element) {
788 $file = $xpath->query(".//input[contains(@class, 'forminator-input-file')]", $element)->item(0);
789 $button = $xpath->query(".//button[contains(@class, 'forminator-upload-button')]", $element)->item(0);
790 if ($file && $button) {
791 $button = $xml->set_node_value($button, 'type', 'upload');
792 $button = $xml->set_node_value($button, 'name', $xml->get_node_value($file, 'name'));
793 }
794 }
795
796 //replace names on inputs
797 $inputs = $xpath->query("//input|//textarea|//select");
798 foreach ($inputs as $element) {
799 if ($xml->get_node_value($element, 'type') == 'checkbox') {
800 $element = $xml->set_node_value($element, 'name', str_replace("[]", "", $xml->get_node_value($element, 'name')));
801 }
802 $element = $xml->set_node_value($element, 'name', '{' . $xml->get_node_value($element, 'name') . '}');
803
804 if (strpos($xml->get_node_value($element, 'class'), 'forminator-checkbox--input') !== false) {
805 $element = $xml->set_node_value($element, 'class', $xml->get_node_value($element, 'class') . ' forminator-checkbox--design');
806 }
807 if (strpos($xml->get_node_value($element, 'class'), 'forminator-radio--input') !== false) {
808 $element = $xml->set_node_value($element, 'class', $xml->get_node_value($element, 'class') . ' forminator-radio--design');
809 }
810 }
811
812 //multiselects
813 $multiselect = $xpath->query("//ul[contains(@class, 'forminator-multiselect')]");
814 foreach ($multiselect as $element) {
815 $name = '';
816 $options = array();
817 $inputs = $xpath->query(".//*[contains(@class, 'forminator-multiselect--item')]", $element);
818
819 foreach ($inputs as $sub_element) {
820 $input = $xpath->query(".//input", $sub_element)->item(0);
821 $label = $xpath->query(".//label", $sub_element)->item(0);
822
823 if ($input && $label) {
824 if ($label->childNodes->item(0)) {
825 $options[] = array(
826 'value' => $xml->get_node_value($input, 'value'),
827 'label' => $label->childNodes->item(0)->nodeValue
828 );
829 }
830 $name = $xml->get_node_value($input, 'name');
831 }
832 $sub_element->parentNode->removeChild($sub_element);
833 }
834
835 $li = $dom->createElement('li');
836 $field_atts = array(
837 'class' => 'forminator-multiselect--item',
838 );
839 foreach ($field_atts as $key => $value) {
840 $attr = $dom->createAttribute($key);
841 $attr->value = $value;
842 $li->appendChild($attr);
843 }
844 $element->appendChild($li);
845
846
847 $field = $dom->createElement('select');
848 $field_atts = array(
849 'multiple' => 'multiple',
850 'name' => $name,
851 );
852 foreach ($field_atts as $key => $value) {
853 $attr = $dom->createAttribute($key);
854 $attr->value = $value;
855 $field->appendChild($attr);
856 }
857
858 $li->appendChild($field);
859
860 foreach ($options as $option) {
861 $option_field = $dom->createElement('option');
862 $field_atts = array(
863 'value' => $option['value'],
864 );
865 foreach ($field_atts as $key => $value) {
866 $attr = $dom->createAttribute($key);
867 $attr->value = $value;
868 $option_field->appendChild($attr);
869 }
870
871 $label = $dom->createTextNode($option['label']);
872 $option_field->appendChild($label);
873 $field->appendChild($option_field);
874 }
875 }
876
877 return $dom->saveHTML();
878 }
879 }
880 return false;
881 }
882
883 /**
884 * Auto Generate of Template for this extension
885 *
886 * @return array - List of elements
887 */
888 public function auto() {
889
890 $item = $this->get('item');
891
892 $response = array();
893 $elements = array();
894 $fields = array();
895 $form = false;
896
897 if (class_exists("Forminator_API")) {
898 $forminator_form = Forminator_API::get_form($item);
899 if (!is_wp_error($forminator_form)) {
900 $form = $forminator_form;
901 $fields = $form->fields;
902 }
903 }
904
905 if ($form && $fields) {
906
907 foreach ($fields as $field_obj) {
908 $field = $field_obj->raw;
909 $float = true;
910 $width = 100 / (12 / $field['cols']);
911
912 switch ($field['type']) {
913 case 'name':
914 case 'email':
915 case 'phone':
916 case 'url':
917 case 'upload':
918 case 'number':
919 case 'date':
920 //multiple name field
921 if ($field['type'] == 'name' && isset($field['multiple_name']) && $field['multiple_name']) {
922
923 if (!$field['prefix'] && !$field['fname']) {
924 if ($field['mname']) {
925 $elements[] = $this->auto_field($field, array(
926 'type' => 'e2pdf-html',
927 'block' => true,
928 'float' => true,
929 'properties' => array(
930 'top' => '20',
931 'left' => '20',
932 'right' => '20',
933 'width' => $field['lname'] ? $width / 2 . '%' : $width . '%',
934 'height' => 'auto',
935 'value' => $field['mname_label'],
936 )
937 ));
938
939 $elements[] = $this->auto_field($field, array(
940 'type' => 'e2pdf-input',
941 'properties' => array(
942 'top' => '5',
943 'width' => '100%',
944 'height' => 'auto',
945 'value' => "{" . $field['element_id'] . "-middle-name" . "}",
946 )
947 ));
948 }
949
950 if ($field['lname']) {
951 $elements[] = $this->auto_field($field, array(
952 'type' => 'e2pdf-html',
953 'block' => true,
954 'float' => true,
955 'properties' => array(
956 'top' => '20',
957 'left' => '20',
958 'right' => '20',
959 'width' => $field['mname'] ? $width / 2 . '%' : $width . '%',
960 'height' => 'auto',
961 'value' => $field['lname_label'],
962 )
963 ));
964
965 $elements[] = $this->auto_field($field, array(
966 'type' => 'e2pdf-input',
967 'properties' => array(
968 'top' => '5',
969 'width' => '100%',
970 'height' => 'auto',
971 'value' => "{" . $field['element_id'] . "-last-name" . "}",
972 )
973 ));
974 }
975 } else {
976
977 if ($field['prefix']) {
978 $elements[] = $this->auto_field($field, array(
979 'type' => 'e2pdf-html',
980 'block' => true,
981 'float' => true,
982 'properties' => array(
983 'top' => '20',
984 'left' => '20',
985 'right' => '20',
986 'width' => $field['fname'] ? $width / 2 . '%' : $width . '%',
987 'height' => 'auto',
988 'value' => $field['prefix_label'],
989 )
990 ));
991
992 $options_tmp = array();
993 if (function_exists('forminator_get_name_prefixes')) {
994 $options = forminator_get_name_prefixes();
995 foreach ($options as $key => $option) {
996 $options_tmp[] = $key;
997 }
998 }
999
1000 $elements[] = $this->auto_field($field, array(
1001 'type' => 'e2pdf-select',
1002 'properties' => array(
1003 'top' => '5',
1004 'width' => '100%',
1005 'height' => 'auto',
1006 'options' => implode("\n", $options_tmp),
1007 'value' => "{" . $field['element_id'] . "-prefix" . "}",
1008 )
1009 ));
1010
1011 if ($field['mname'] && $field['fname']) {
1012 $elements[] = $this->auto_field($field, array(
1013 'type' => 'e2pdf-html',
1014 'properties' => array(
1015 'top' => '20',
1016 'width' => $field['lname'] ? '100%' : '200%',
1017 'right' => $field['lname'] ? '0' : '-40',
1018 'height' => 'auto',
1019 'value' => $field['mname_label'],
1020 )
1021 ));
1022
1023 $elements[] = $this->auto_field($field, array(
1024 'type' => 'e2pdf-input',
1025 'properties' => array(
1026 'top' => '5',
1027 'width' => $field['lname'] ? '100%' : '200%',
1028 'height' => 'auto',
1029 'right' => $field['lname'] ? '0' : '-40',
1030 'value' => "{" . $field['element_id'] . "-middle-name" . "}",
1031 )
1032 ));
1033 } elseif ($field['lname'] && !$field['mname'] && $field['fname']) {
1034
1035 $elements[] = $this->auto_field($field, array(
1036 'type' => 'e2pdf-html',
1037 'properties' => array(
1038 'top' => '20',
1039 'width' => $field['mname'] ? '100%' : '200%',
1040 'height' => 'auto',
1041 'right' => $field['mname'] ? '0' : '-40',
1042 'value' => $field['lname_label'],
1043 )
1044 ));
1045
1046 $elements[] = $this->auto_field($field, array(
1047 'type' => 'e2pdf-input',
1048 'properties' => array(
1049 'top' => '5',
1050 'width' => $field['mname'] ? '100%' : '200%',
1051 'height' => 'auto',
1052 'right' => $field['mname'] ? '0' : '-40',
1053 'value' => "{" . $field['element_id'] . "-last-name" . "}",
1054 )
1055 ));
1056 }
1057 }
1058
1059 if ($field['fname']) {
1060 $elements[] = $this->auto_field($field, array(
1061 'type' => 'e2pdf-html',
1062 'block' => true,
1063 'float' => true,
1064 'properties' => array(
1065 'top' => '20',
1066 'left' => '20',
1067 'right' => '20',
1068 'width' => $field['prefix'] ? ($width / 2) . '%' : $width . '%',
1069 'height' => 'auto',
1070 'value' => $field['fname_label'],
1071 )
1072 ));
1073
1074 $elements[] = $this->auto_field($field, array(
1075 'type' => 'e2pdf-input',
1076 'properties' => array(
1077 'top' => '5',
1078 'width' => '100%',
1079 'height' => 'auto',
1080 'value' => "{" . $field['element_id'] . "-first-name" . "}",
1081 )
1082 ));
1083
1084 if ($field['lname'] && $field['mname'] && $field['prefix']) {
1085 $elements[] = $this->auto_field($field, array(
1086 'type' => 'e2pdf-html',
1087 'properties' => array(
1088 'top' => '20',
1089 'width' => $field['mname'] ? '100%' : '200%',
1090 'height' => 'auto',
1091 'right' => $field['mname'] ? '0' : '-40',
1092 'value' => $field['lname_label'],
1093 )
1094 ));
1095
1096 $elements[] = $this->auto_field($field, array(
1097 'type' => 'e2pdf-input',
1098 'properties' => array(
1099 'top' => '5',
1100 'width' => $field['mname'] ? '100%' : '200%',
1101 'height' => 'auto',
1102 'right' => $field['mname'] ? '0' : '-40',
1103 'value' => "{" . $field['element_id'] . "-last-name" . "}",
1104 )
1105 ));
1106 }
1107 }
1108
1109 if (!$field['prefix'] || !$field['fname']) {
1110 if ($field['mname']) {
1111 $elements[] = $this->auto_field($field, array(
1112 'type' => 'e2pdf-html',
1113 'properties' => array(
1114 'top' => '20',
1115 'right' => $field['lname'] ? '20' : '0',
1116 'width' => $field['lname'] ? '50%' : '100%',
1117 'height' => 'auto',
1118 'value' => $field['mname_label'],
1119 )
1120 ));
1121 }
1122
1123 if ($field['lname']) {
1124 $elements[] = $this->auto_field($field, array(
1125 'type' => 'e2pdf-html',
1126 'float' => $field['mname'] ? true : false,
1127 'properties' => array(
1128 'top' => '20',
1129 'left' => $field['mname'] ? '20' : '0',
1130 'width' => $field['mname'] ? '50%' : '100%',
1131 'height' => 'auto',
1132 'value' => $field['lname_label'],
1133 )
1134 ));
1135 }
1136
1137 if ($field['mname']) {
1138 $elements[] = $this->auto_field($field, array(
1139 'type' => 'e2pdf-input',
1140 'properties' => array(
1141 'top' => '5',
1142 'right' => $field['lname'] ? '20' : '0',
1143 'width' => $field['lname'] ? '50%' : '100%',
1144 'height' => 'auto',
1145 'value' => "{" . $field['element_id'] . "-middle-name" . "}",
1146 )
1147 ));
1148 }
1149
1150 if ($field['lname']) {
1151 $elements[] = $this->auto_field($field, array(
1152 'type' => 'e2pdf-input',
1153 'float' => $field['mname'] ? true : false,
1154 'properties' => array(
1155 'top' => '5',
1156 'left' => $field['mname'] ? '20' : '0',
1157 'width' => $field['mname'] ? '50%' : '100%',
1158 'height' => 'auto',
1159 'value' => "{" . $field['element_id'] . "-last-name" . "}",
1160 )
1161 ));
1162 }
1163 }
1164 }
1165 } elseif ($field['type'] == 'date' && $field['field_type'] == 'select') {
1166
1167 $elements[] = $this->auto_field($field, array(
1168 'type' => 'e2pdf-html',
1169 'block' => true,
1170 'float' => $float,
1171 'properties' => array(
1172 'top' => '20',
1173 'left' => '20',
1174 'right' => '20',
1175 'width' => $width . "%",
1176 'height' => 'auto',
1177 'value' => $field['field_label'],
1178 )
1179 ));
1180
1181 $days = array();
1182 $months = array();
1183 $years = array();
1184 if (class_exists('Forminator_Date')) {
1185 $forminator_date = new Forminator_Date();
1186 $options = $forminator_date->get_day();
1187 foreach ($options as $option) {
1188 $days[] = $option['value'];
1189 }
1190
1191 $options = $forminator_date->get_months();
1192 foreach ($options as $option) {
1193 $months[] = $option['value'];
1194 }
1195
1196 $options = $forminator_date->get_years($field['min_year'], $field['max_year']);
1197 foreach ($options as $option) {
1198 $years[] = $option['value'];
1199 }
1200 }
1201
1202 $elements[] = $this->auto_field($field, array(
1203 'type' => 'e2pdf-select',
1204 'properties' => array(
1205 'top' => '5',
1206 'width' => '30%',
1207 'height' => 'auto',
1208 'options' => implode("\n", $days),
1209 'value' => "{" . $field['element_id'] . "-month" . "}",
1210 )
1211 ));
1212
1213 $elements[] = $this->auto_field($field, array(
1214 'type' => 'e2pdf-select',
1215 'float' => true,
1216 'properties' => array(
1217 'top' => '5',
1218 'left' => '5%',
1219 'right' => '5%',
1220 'width' => '40%',
1221 'height' => 'auto',
1222 'options' => implode("\n", $months),
1223 'value' => "{" . $field['element_id'] . "-day" . "}",
1224 )
1225 ));
1226
1227 $elements[] = $this->auto_field($field, array(
1228 'type' => 'e2pdf-select',
1229 'float' => true,
1230 'properties' => array(
1231 'top' => '5',
1232 'width' => '30%',
1233 'height' => 'auto',
1234 'options' => implode("\n", $years),
1235 'value' => "{" . $field['element_id'] . "-year" . "}",
1236 )
1237 ));
1238 } elseif ($field['type'] == 'date' && $field['field_type'] == 'input') {
1239
1240 $elements[] = $this->auto_field($field, array(
1241 'type' => 'e2pdf-html',
1242 'block' => true,
1243 'float' => $float,
1244 'properties' => array(
1245 'top' => '20',
1246 'left' => '20',
1247 'right' => '20',
1248 'width' => $width . "%",
1249 'height' => 'auto',
1250 'value' => $field['field_label'],
1251 )
1252 ));
1253
1254 $elements[] = $this->auto_field($field, array(
1255 'type' => 'e2pdf-input',
1256 'properties' => array(
1257 'top' => '5',
1258 'width' => '30%',
1259 'height' => 'auto',
1260 'value' => "{" . $field['element_id'] . "-month" . "}",
1261 )
1262 ));
1263
1264 $elements[] = $this->auto_field($field, array(
1265 'type' => 'e2pdf-input',
1266 'float' => true,
1267 'properties' => array(
1268 'top' => '5',
1269 'left' => '5%',
1270 'right' => '5%',
1271 'width' => '40%',
1272 'height' => 'auto',
1273 'value' => "{" . $field['element_id'] . "-day" . "}",
1274 )
1275 ));
1276
1277 $elements[] = $this->auto_field($field, array(
1278 'float' => true,
1279 'type' => 'e2pdf-input',
1280 'properties' => array(
1281 'top' => '5',
1282 'width' => '30%',
1283 'height' => 'auto',
1284 'value' => "{" . $field['element_id'] . "-year" . "}",
1285 )
1286 ));
1287 } else {
1288
1289 $elements[] = $this->auto_field($field, array(
1290 'type' => 'e2pdf-html',
1291 'block' => true,
1292 'float' => $float,
1293 'properties' => array(
1294 'top' => '20',
1295 'left' => '20',
1296 'right' => '20',
1297 'width' => $width . "%",
1298 'height' => 'auto',
1299 'value' => $field['field_label'],
1300 )
1301 ));
1302
1303 $elements[] = $this->auto_field($field, array(
1304 'type' => 'e2pdf-input',
1305 'properties' => array(
1306 'top' => '5',
1307 'width' => '100%',
1308 'height' => 'auto',
1309 'value' => "{" . $field['element_id'] . "}",
1310 )
1311 ));
1312 }
1313 break;
1314 case 'address':
1315 if (!$field['street_address'] && !$field['address_line']) {
1316
1317 if (!$field['address_city'] && !$field['address_state']) {
1318 if ($field['address_zip']) {
1319 $elements[] = $this->auto_field($field, array(
1320 'type' => 'e2pdf-html',
1321 'block' => true,
1322 'float' => true,
1323 'properties' => array(
1324 'top' => '20',
1325 'left' => '20',
1326 'right' => '20',
1327 'width' => $field['address_country'] ? $width / 2 . '%' : $width . '%',
1328 'height' => 'auto',
1329 'value' => $field['address_zip_label']
1330 )
1331 ));
1332
1333 $elements[] = $this->auto_field($field, array(
1334 'type' => 'e2pdf-input',
1335 'properties' => array(
1336 'top' => '5',
1337 'width' => '100%',
1338 'height' => 'auto',
1339 'value' => "{" . $field['element_id'] . "-zip" . "}",
1340 )
1341 ));
1342 }
1343
1344 if ($field['address_country']) {
1345 $elements[] = $this->auto_field($field, array(
1346 'type' => 'e2pdf-html',
1347 'block' => true,
1348 'float' => true,
1349 'properties' => array(
1350 'top' => '20',
1351 'left' => '20',
1352 'right' => '20',
1353 'width' => $field['address_zip'] ? $width / 2 . '%' : $width . '%',
1354 'height' => 'auto',
1355 'value' => $field['address_country_label'],
1356 )
1357 ));
1358
1359 $options_tmp = array();
1360 if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) {
1361 $options = forminator_to_field_array(forminator_get_countries_list(), true);
1362 foreach ($options as $option) {
1363 $options_tmp[] = $option['value'];
1364 }
1365 //can be value or label
1366 }
1367
1368 $elements[] = $this->auto_field($field, array(
1369 'type' => 'e2pdf-select',
1370 'properties' => array(
1371 'top' => '5',
1372 'width' => '100%',
1373 'height' => 'auto',
1374 'options' => implode("\n", $options_tmp),
1375 'value' => "{" . $field['element_id'] . "-country" . "}",
1376 )
1377 ));
1378 }
1379 } else {
1380
1381 if ($field['address_city']) {
1382 $elements[] = $this->auto_field($field, array(
1383 'type' => 'e2pdf-html',
1384 'block' => true,
1385 'float' => true,
1386 'properties' => array(
1387 'top' => '20',
1388 'left' => '20',
1389 'right' => '20',
1390 'width' => $field['address_state'] ? $width / 2 . '%' : $width . '%',
1391 'height' => 'auto',
1392 'value' => $field['address_city_label'],
1393 )
1394 ));
1395
1396 $elements[] = $this->auto_field($field, array(
1397 'type' => 'e2pdf-input',
1398 'properties' => array(
1399 'top' => '5',
1400 'width' => '100%',
1401 'height' => 'auto',
1402 'value' => "{" . $field['element_id'] . "-city" . "}",
1403 )
1404 ));
1405
1406 if ($field['address_zip'] && $field['address_state']) {
1407 $elements[] = $this->auto_field($field, array(
1408 'type' => 'e2pdf-html',
1409 'properties' => array(
1410 'top' => '20',
1411 'right' => $field['address_country'] ? '0' : '-40',
1412 'width' => $field['address_country'] ? '100%' : '200%',
1413 'height' => 'auto',
1414 'value' => $field['address_zip_label'],
1415 )
1416 ));
1417
1418 $elements[] = $this->auto_field($field, array(
1419 'type' => 'e2pdf-input',
1420 'properties' => array(
1421 'top' => '5',
1422 'right' => $field['address_country'] ? '0' : '-40',
1423 'width' => $field['address_country'] ? '100%' : '200%',
1424 'height' => 'auto',
1425 'value' => "{" . $field['element_id'] . "-zip" . "}",
1426 )
1427 ));
1428 } elseif ($field['address_country'] && !$field['address_zip'] && $field['address_state']) {
1429
1430 $elements[] = $this->auto_field($field, array(
1431 'type' => 'e2pdf-html',
1432 'properties' => array(
1433 'top' => '20',
1434 'right' => $field['address_zip'] ? '0' : '-40',
1435 'width' => $field['address_zip'] ? '100%' : '200%',
1436 'height' => 'auto',
1437 'value' => $field['address_country_label'],
1438 )
1439 ));
1440
1441 $options_tmp = array();
1442 if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) {
1443 $options = forminator_to_field_array(forminator_get_countries_list(), true);
1444 foreach ($options as $option) {
1445 $options_tmp[] = $option['value'];
1446 }
1447 //can be value or label
1448 }
1449
1450 $elements[] = $this->auto_field($field, array(
1451 'type' => 'e2pdf-select',
1452 'properties' => array(
1453 'top' => '5',
1454 'right' => $field['address_zip'] ? '0' : '-40',
1455 'width' => $field['address_zip'] ? '100%' : '200%',
1456 'height' => 'auto',
1457 'options' => implode("\n", $options_tmp),
1458 'value' => "{" . $field['element_id'] . "-country" . "}",
1459 )
1460 ));
1461 }
1462 }
1463
1464 if ($field['address_state']) {
1465 $elements[] = $this->auto_field($field, array(
1466 'type' => 'e2pdf-html',
1467 'block' => true,
1468 'float' => true,
1469 'properties' => array(
1470 'top' => '20',
1471 'left' => '20',
1472 'right' => '20',
1473 'width' => $field['address_city'] ? ($width / 2) . '%' : $width . '%',
1474 'height' => 'auto',
1475 'value' => $field['address_state_label'],
1476 )
1477 ));
1478
1479 $elements[] = $this->auto_field($field, array(
1480 'type' => 'e2pdf-input',
1481 'properties' => array(
1482 'top' => '5',
1483 'width' => '100%',
1484 'height' => 'auto',
1485 'value' => "{" . $field['element_id'] . "-state" . "}",
1486 )
1487 ));
1488
1489 if ($field['address_country'] && $field['address_zip'] && $field['address_city']) {
1490
1491 $elements[] = $this->auto_field($field, array(
1492 'type' => 'e2pdf-html',
1493 'properties' => array(
1494 'top' => '20',
1495 'right' => $field['address_zip'] ? '0' : '-40',
1496 'width' => $field['address_zip'] ? '100%' : '200%',
1497 'height' => 'auto',
1498 'value' => $field['address_country_label'],
1499 )
1500 ));
1501
1502 $options_tmp = array();
1503 if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) {
1504 $options = forminator_to_field_array(forminator_get_countries_list(), true);
1505 foreach ($options as $option) {
1506 $options_tmp[] = $option['value'];
1507 }
1508 //can be value or label
1509 }
1510
1511 $elements[] = $this->auto_field($field, array(
1512 'type' => 'e2pdf-select',
1513 'properties' => array(
1514 'top' => '5',
1515 'right' => $field['address_zip'] ? '0' : '-40',
1516 'width' => $field['address_zip'] ? '100%' : '200%',
1517 'height' => 'auto',
1518 'options' => implode("\n", $options_tmp),
1519 'value' => "{" . $field['element_id'] . "-country" . "}",
1520 )
1521 ));
1522 }
1523 }
1524
1525 if (!$field['address_city'] || !$field['address_state']) {
1526 if ($field['address_zip']) {
1527 $elements[] = $this->auto_field($field, array(
1528 'type' => 'e2pdf-html',
1529 'properties' => array(
1530 'top' => '20',
1531 'right' => $field['address_country'] ? '20' : '0',
1532 'width' => $field['address_country'] ? '50%' : '100%',
1533 'height' => 'auto',
1534 'value' => $field['address_zip_label'],
1535 )
1536 ));
1537 }
1538
1539 if ($field['address_country']) {
1540
1541 $elements[] = $this->auto_field($field, array(
1542 'type' => 'e2pdf-html',
1543 'float' => $field['address_zip'] ? true : false,
1544 'properties' => array(
1545 'top' => '20',
1546 'left' => $field['address_zip'] ? '20' : '0',
1547 'width' => $field['address_zip'] ? '50%' : '100%',
1548 'height' => 'auto',
1549 'value' => $field['address_country_label'],
1550 )
1551 ));
1552 }
1553
1554 if ($field['address_zip']) {
1555 $elements[] = $this->auto_field($field, array(
1556 'type' => 'e2pdf-input',
1557 'properties' => array(
1558 'top' => '5',
1559 'right' => $field['address_country'] ? '20' : '0',
1560 'width' => $field['address_country'] ? '50%' : '100%',
1561 'height' => 'auto',
1562 'value' => "{" . $field['element_id'] . "-zip" . "}",
1563 )
1564 ));
1565 }
1566
1567 if ($field['address_country']) {
1568 $options_tmp = array();
1569 if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) {
1570 $options = forminator_to_field_array(forminator_get_countries_list(), true);
1571 foreach ($options as $option) {
1572 $options_tmp[] = $option['value'];
1573 }
1574 //can be value or label
1575 }
1576
1577 $elements[] = $this->auto_field($field, array(
1578 'type' => 'e2pdf-select',
1579 'float' => $field['address_zip'] ? true : false,
1580 'properties' => array(
1581 'top' => '5',
1582 'left' => $field['address_zip'] ? '20' : '0',
1583 'width' => $field['address_zip'] ? '50%' : '100%',
1584 'height' => 'auto',
1585 'options' => implode("\n", $options_tmp),
1586 'value' => "{" . $field['element_id'] . "-country" . "}",
1587 )
1588 ));
1589 }
1590 }
1591 }
1592 } else {
1593
1594 if ($field['street_address']) {
1595 $elements[] = $this->auto_field($field, array(
1596 'type' => 'e2pdf-html',
1597 'block' => true,
1598 'float' => true,
1599 'properties' => array(
1600 'top' => '20',
1601 'left' => '20',
1602 'right' => '20',
1603 'width' => $width . '%',
1604 'height' => 'auto',
1605 'value' => $field['street_address_label'],
1606 )
1607 ));
1608
1609 $elements[] = $this->auto_field($field, array(
1610 'type' => 'e2pdf-input',
1611 'properties' => array(
1612 'top' => '5',
1613 'width' => '100%',
1614 'height' => 'auto',
1615 'value' => "{" . $field['element_id'] . "-street_address" . "}",
1616 )
1617 ));
1618 }
1619
1620 if ($field['address_line']) {
1621
1622 if ($field['address_line_label']) {
1623 $elements[] = $this->auto_field($field, array(
1624 'type' => 'e2pdf-html',
1625 'block' => $field['street_address'] ? false : true,
1626 'float' => $field['street_address'] ? false : true,
1627 'properties' => array(
1628 'top' => '20',
1629 'left' => $field['street_address'] ? '0' : '20',
1630 'right' => $field['street_address'] ? '0' : '20',
1631 'width' => $field['street_address'] ? '100%' : $width . '%',
1632 'height' => 'auto',
1633 'value' => $field['address_line_label'],
1634 )
1635 ));
1636 }
1637
1638 $elements[] = $this->auto_field($field, array(
1639 'type' => 'e2pdf-input',
1640 'properties' => array(
1641 'top' => $field['address_line_label'] ? '0' : '20',
1642 'width' => '100%',
1643 'height' => 'auto',
1644 'value' => "{" . $field['element_id'] . "-address_line" . "}",
1645 )
1646 ));
1647 }
1648
1649 if ($field['address_city']) {
1650
1651 $elements[] = $this->auto_field($field, array(
1652 'type' => 'e2pdf-html',
1653 'properties' => array(
1654 'top' => '20',
1655 'right' => $field['address_state'] ? '20' : '0',
1656 'width' => $field['address_state'] ? '50%' : '100%',
1657 'height' => 'auto',
1658 'value' => $field['address_city_label'],
1659 )
1660 ));
1661 }
1662
1663 if ($field['address_state']) {
1664 $elements[] = $this->auto_field($field, array(
1665 'type' => 'e2pdf-html',
1666 'float' => $field['address_city'] ? true : false,
1667 'properties' => array(
1668 'top' => $field['address_city'] ? '0' : '20',
1669 'left' => $field['address_city'] ? '20' : '0',
1670 'width' => $field['address_city'] ? '50%' : '100%',
1671 'height' => 'auto',
1672 'value' => $field['address_state_label'],
1673 )
1674 ));
1675 }
1676
1677 if ($field['address_city']) {
1678 $elements[] = $this->auto_field($field, array(
1679 'type' => 'e2pdf-input',
1680 'properties' => array(
1681 'top' => '5',
1682 'right' => $field['address_state'] ? '20' : '0',
1683 'width' => $field['address_state'] ? '50%' : '100%',
1684 'height' => 'auto',
1685 'value' => "{" . $field['element_id'] . "-city" . "}",
1686 )
1687 ));
1688 }
1689
1690 if ($field['address_state']) {
1691 $elements[] = $this->auto_field($field, array(
1692 'type' => 'e2pdf-input',
1693 'float' => $field['address_city'] ? true : false,
1694 'properties' => array(
1695 'top' => '5',
1696 'left' => $field['address_city'] ? '20' : '0',
1697 'width' => $field['address_city'] ? '50%' : '100%',
1698 'height' => 'auto',
1699 'value' => "{" . $field['element_id'] . "-state" . "}",
1700 )
1701 ));
1702 }
1703
1704 if ($field['address_zip']) {
1705
1706 $elements[] = $this->auto_field($field, array(
1707 'type' => 'e2pdf-html',
1708 'properties' => array(
1709 'top' => '20',
1710 'right' => $field['address_country'] ? '20' : '0',
1711 'width' => $field['address_country'] ? '50%' : '100%',
1712 'height' => 'auto',
1713 'value' => $field['address_zip_label'],
1714 )
1715 ));
1716 }
1717
1718 if ($field['address_country']) {
1719 $elements[] = $this->auto_field($field, array(
1720 'type' => 'e2pdf-html',
1721 'float' => $field['address_zip'] ? true : false,
1722 'properties' => array(
1723 'top' => '20',
1724 'left' => $field['address_zip'] ? '20' : '0',
1725 'width' => $field['address_zip'] ? '50%' : '100%',
1726 'height' => 'auto',
1727 'value' => $field['address_country_label'],
1728 )
1729 ));
1730 }
1731
1732 if ($field['address_zip']) {
1733 $elements[] = $this->auto_field($field, array(
1734 'type' => 'e2pdf-input',
1735 'properties' => array(
1736 'top' => '5',
1737 'right' => $field['address_country'] ? '20' : '0',
1738 'width' => $field['address_country'] ? '50%' : '100%',
1739 'height' => 'auto',
1740 'value' => "{" . $field['element_id'] . "-zip" . "}",
1741 )
1742 ));
1743 }
1744
1745 if ($field['address_country']) {
1746 $options_tmp = array();
1747 if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) {
1748 $options = forminator_to_field_array(forminator_get_countries_list(), true);
1749 foreach ($options as $option) {
1750 $options_tmp[] = $option['value'];
1751 }
1752 //can be value or label
1753 }
1754
1755 $elements[] = $this->auto_field($field, array(
1756 'type' => 'e2pdf-select',
1757 'float' => $field['address_zip'] ? true : false,
1758 'properties' => array(
1759 'top' => '5',
1760 'left' => $field['address_zip'] ? '20' : '0',
1761 'width' => $field['address_zip'] ? '50%' : '100%',
1762 'height' => 'auto',
1763 'options' => implode("\n", $options_tmp),
1764 'value' => "{" . $field['element_id'] . "-country" . "}",
1765 )
1766 ));
1767 }
1768 }
1769 break;
1770 case 'time':
1771 $hours = array();
1772 $minutes = array();
1773
1774 if (class_exists('Forminator_Time')) {
1775 $forminator_time = new Forminator_Time();
1776 $options = $forminator_time->get_hours($field['time_type']);
1777 foreach ($options as $option) {
1778 $hours[] = $option['value'];
1779 }
1780
1781 $options = $forminator_time->get_minutes();
1782 foreach ($options as $option) {
1783 $minutes[] = $option['value'];
1784 }
1785 }
1786
1787 $elements[] = $this->auto_field($field, array(
1788 'type' => 'e2pdf-html',
1789 'block' => true,
1790 'float' => true,
1791 'properties' => array(
1792 'top' => '20',
1793 'left' => '20',
1794 'right' => '20',
1795 'width' => ($field['time_type'] == 'twelve' ? $width / 3 : $width / 2) . '%',
1796 'height' => 'auto',
1797 'value' => $field['hh_label'],
1798 )
1799 ));
1800
1801 if ($field['field_type'] == 'select') {
1802 $elements[] = $this->auto_field($field, array(
1803 'type' => 'e2pdf-select',
1804 'properties' => array(
1805 'top' => '5',
1806 'width' => '100%',
1807 'height' => 'auto',
1808 'options' => implode("\n", $hours),
1809 'value' => "{" . $field['element_id'] . "-hours" . "}",
1810 )
1811 ));
1812 } else {
1813 $elements[] = $this->auto_field($field, array(
1814 'type' => 'e2pdf-input',
1815 'properties' => array(
1816 'top' => '5',
1817 'width' => '100%',
1818 'height' => 'auto',
1819 'value' => "{" . $field['element_id'] . "-hours" . "}",
1820 )
1821 ));
1822 }
1823
1824 $elements[] = $this->auto_field($field, array(
1825 'type' => 'e2pdf-html',
1826 'block' => true,
1827 'float' => true,
1828 'properties' => array(
1829 'top' => '20',
1830 'left' => '20',
1831 'right' => '20',
1832 'width' => ($field['time_type'] == 'twelve' ? $width / 3 : $width / 2) . '%',
1833 'height' => 'auto',
1834 'value' => $field['mm_label'],
1835 )
1836 ));
1837
1838 if ($field['field_type'] == 'select') {
1839 $elements[] = $this->auto_field($field, array(
1840 'type' => 'e2pdf-select',
1841 'properties' => array(
1842 'top' => '5',
1843 'width' => '100%',
1844 'height' => 'auto',
1845 'options' => implode("\n", $minutes),
1846 'value' => "{" . $field['element_id'] . "-minutes" . "}",
1847 )
1848 ));
1849 } else {
1850 $elements[] = $this->auto_field($field, array(
1851 'type' => 'e2pdf-input',
1852 'properties' => array(
1853 'top' => '5',
1854 'width' => '100%',
1855 'height' => 'auto',
1856 'value' => "{" . $field['element_id'] . "-minutes" . "}",
1857 )
1858 ));
1859 }
1860
1861 if ($field['time_type'] == 'twelve') {
1862 $elements[] = $this->auto_field($field, array(
1863 'type' => 'e2pdf-html',
1864 'block' => true,
1865 'float' => $float,
1866 'properties' => array(
1867 'top' => '20',
1868 'left' => '20',
1869 'right' => '20',
1870 'width' => ($width / 3) . '%',
1871 'height' => 'auto',
1872 'value' => '',
1873 )
1874 ));
1875
1876 $ampm = array(
1877 'am', 'pm'
1878 );
1879
1880 $elements[] = $this->auto_field($field, array(
1881 'type' => 'e2pdf-select',
1882 'properties' => array(
1883 'top' => '5',
1884 'width' => '100%',
1885 'height' => 'auto',
1886 'options' => implode("\n", $ampm),
1887 'value' => "{" . $field['element_id'] . "-ampm" . "}",
1888 )
1889 ));
1890 }
1891 break;
1892 case 'html':
1893 if ($field['field_label']) {
1894 $elements[] = $this->auto_field($field, array(
1895 'type' => 'e2pdf-html',
1896 'block' => true,
1897 'properties' => array(
1898 'top' => '20',
1899 'left' => '20',
1900 'right' => '20',
1901 'width' => $width . '%',
1902 'height' => 'auto',
1903 'value' => $field['field_label'],
1904 )
1905 ));
1906
1907 $elements[] = $this->auto_field($field, array(
1908 'type' => 'e2pdf-html',
1909 'properties' => array(
1910 'top' => '5',
1911 'width' => '100%',
1912 'height' => 'auto',
1913 'value' => $field['variations'],
1914 )
1915 ));
1916 } else {
1917 $elements[] = $this->auto_field($field, array(
1918 'type' => 'e2pdf-html',
1919 'block' => true,
1920 'properties' => array(
1921 'top' => '20',
1922 'left' => '20',
1923 'right' => '20',
1924 'width' => $width . '%',
1925 'height' => 'auto',
1926 'value' => $field['variations'],
1927 )
1928 ));
1929 }
1930 break;
1931 case 'section':
1932 $section = '';
1933 if ($field['section_title']) {
1934 $section .= "<h2>" . $field['section_title'] . "</h2>";
1935 }
1936 if ($field['section_subtitle']) {
1937 $section .= $field['section_subtitle'];
1938 }
1939 if ($section) {
1940 $elements[] = $this->auto_field($field, array(
1941 'type' => 'e2pdf-html',
1942 'block' => true,
1943 'properties' => array(
1944 'top' => '20',
1945 'left' => '20',
1946 'right' => '20',
1947 'width' => $width . '%',
1948 'height' => 'auto',
1949 'value' => $section,
1950 )
1951 ));
1952 }
1953 break;
1954 case 'text':
1955 $elements[] = $this->auto_field($field, array(
1956 'type' => 'e2pdf-html',
1957 'block' => true,
1958 'properties' => array(
1959 'top' => '20',
1960 'left' => '20',
1961 'right' => '20',
1962 'width' => $width . '%',
1963 'height' => 'auto',
1964 'value' => $field['field_label'],
1965 )
1966 ));
1967
1968 if (isset($field['input_type']) && $field['input_type'] == 'line') {
1969 $elements[] = $this->auto_field($field, array(
1970 'type' => 'e2pdf-input',
1971 'properties' => array(
1972 'top' => '5',
1973 'width' => '100%',
1974 'height' => 'auto',
1975 'value' => "{" . $field['element_id'] . "}",
1976 )
1977 ));
1978 } else {
1979 $elements[] = $this->auto_field($field, array(
1980 'type' => 'e2pdf-textarea',
1981 'properties' => array(
1982 'top' => '5',
1983 'width' => '100%',
1984 'height' => 'auto',
1985 'value' => "{" . $field['element_id'] . "}",
1986 )
1987 ));
1988 }
1989 break;
1990 case 'textarea':
1991 $elements[] = $this->auto_field($field, array(
1992 'type' => 'e2pdf-html',
1993 'block' => true,
1994 'properties' => array(
1995 'top' => '20',
1996 'left' => '20',
1997 'right' => '20',
1998 'width' => $width . '%',
1999 'height' => 'auto',
2000 'value' => $field['field_label'],
2001 )
2002 ));
2003 $elements[] = $this->auto_field($field, array(
2004 'type' => 'e2pdf-textarea',
2005 'properties' => array(
2006 'top' => '5',
2007 'width' => '100%',
2008 'height' => 'auto',
2009 'value' => "{" . $field['element_id'] . "}",
2010 )
2011 ));
2012 break;
2013 case 'select':
2014 $elements[] = $this->auto_field($field, array(
2015 'type' => 'e2pdf-html',
2016 'block' => true,
2017 'float' => true,
2018 'properties' => array(
2019 'top' => '20',
2020 'left' => '20',
2021 'right' => '20',
2022 'width' => $width . '%',
2023 'height' => 'auto',
2024 'value' => $field['field_label'],
2025 )
2026 ));
2027
2028 if ($field['value_type'] == 'radio') {
2029 foreach ($field['options'] as $opt_key => $option) {
2030 if (is_array($option)) {
2031 $elements[] = $this->auto_field($field, array(
2032 'type' => 'e2pdf-radio',
2033 'properties' => array(
2034 'top' => '5',
2035 'width' => 'auto',
2036 'height' => 'auto',
2037 'value' => "{" . $field['element_id'] . "}",
2038 'option' => $option['value'] ? $option['value'] : $option['label'],
2039 'group' => "{" . $field['element_id'] . "}",
2040 )
2041 ));
2042 $elements[] = $this->auto_field($field, array(
2043 'type' => 'e2pdf-html',
2044 'float' => true,
2045 'properties' => array(
2046 'left' => '5',
2047 'width' => '100%',
2048 'height' => 'auto',
2049 'value' => $option['label']
2050 )
2051 ));
2052 }
2053 }
2054 } else {
2055 $options_tmp = array();
2056 foreach ($field['options'] as $option) {
2057 $options_tmp[] = $option['value'] ? $option['value'] : $option['label'];
2058 }
2059 $elements[] = $this->auto_field($field, array(
2060 'type' => 'e2pdf-select',
2061 'properties' => array(
2062 'top' => '5',
2063 'width' => '100%',
2064 'height' => 'auto',
2065 'options' => implode("\n", $options_tmp),
2066 'value' => "{" . $field['element_id'] . "}",
2067 )
2068 ));
2069 }
2070 break;
2071 case 'checkbox':
2072 $elements[] = $this->auto_field($field, array(
2073 'type' => 'e2pdf-html',
2074 'block' => true,
2075 'float' => true,
2076 'properties' => array(
2077 'top' => '20',
2078 'left' => '20',
2079 'right' => '20',
2080 'width' => $width . '%',
2081 'height' => 'auto',
2082 'value' => $field['field_label'],
2083 )
2084 ));
2085
2086 if ($field['value_type'] == 'multiselect') {
2087 $options_tmp = array();
2088 foreach ($field['options'] as $opt_key => $option) {
2089 $options_tmp[] = $option['value'] ? $option['value'] : $option['label'];
2090 }
2091 $elements[] = $this->auto_field($field, array(
2092 'type' => 'e2pdf-select',
2093 'properties' => array(
2094 'top' => '5',
2095 'width' => '100%',
2096 'height' => '44',
2097 'multiline' => '1',
2098 'options' => implode("\n", $options_tmp),
2099 'value' => "{" . $field['element_id'] . "}",
2100 )
2101 ));
2102 } else {
2103 foreach ($field['options'] as $opt_key => $option) {
2104 if (is_array($option)) {
2105 $elements[] = $this->auto_field($field, array(
2106 'type' => 'e2pdf-checkbox',
2107 'properties' => array(
2108 'top' => '5',
2109 'width' => 'auto',
2110 'height' => 'auto',
2111 'value' => "{" . $field['element_id'] . "}",
2112 'option' => $option['value'] ? $option['value'] : $option['label']
2113 )
2114 ));
2115 $elements[] = $this->auto_field($field, array(
2116 'type' => 'e2pdf-html',
2117 'float' => true,
2118 'properties' => array(
2119 'left' => '5',
2120 'width' => '100%',
2121 'height' => 'auto',
2122 'value' => $option['label']
2123 )
2124 ));
2125 }
2126 }
2127 }
2128 break;
2129 case 'gdprcheckbox':
2130 $elements[] = $this->auto_field($field, array(
2131 'type' => 'e2pdf-html',
2132 'block' => true,
2133 'float' => true,
2134 'properties' => array(
2135 'top' => '20',
2136 'left' => '20',
2137 'right' => '20',
2138 'width' => $width . '%',
2139 'height' => 'auto',
2140 'value' => '',
2141 )
2142 ));
2143
2144 $elements[] = $this->auto_field($field, array(
2145 'type' => 'e2pdf-checkbox',
2146 'properties' => array(
2147 'top' => '5',
2148 'width' => 'auto',
2149 'height' => 'auto',
2150 'value' => "{" . $field['element_id'] . "}",
2151 'option' => 'true'
2152 )
2153 ));
2154 $elements[] = $this->auto_field($field, array(
2155 'type' => 'e2pdf-html',
2156 'float' => true,
2157 'properties' => array(
2158 'left' => '5',
2159 'width' => '100%',
2160 'height' => 'auto',
2161 'value' => $field['gdpr_description']
2162 )
2163 ));
2164 break;
2165 default:
2166 break;
2167 }
2168 }
2169 }
2170
2171 $response['page'] = array(
2172 'bottom' => '20',
2173 'top' => '20',
2174 'left' => '20',
2175 'right' => '20'
2176 );
2177
2178 $response['elements'] = $elements;
2179 return $response;
2180 }
2181
2182 public function auto_field($field = false, $element = array()) {
2183
2184 if (!$field) {
2185 return false;
2186 }
2187
2188 if (!isset($element['block'])) {
2189 $element['block'] = false;
2190 }
2191
2192 if (!isset($element['float'])) {
2193 $element['float'] = false;
2194 }
2195
2196 return $element;
2197 }
2198
2199 /**
2200 * Load actions for this extension
2201 */
2202 public function load_actions() {
2203 add_action('forminator_custom_form_submit_before_set_fields', array($this, 'action_forminator_custom_form_submit_before_set_fields'), 30, 3);
2204 add_action('forminator_custom_form_mail_admin_message', array($this, 'action_forminator_mail_message'), 30, 5);
2205 add_action('forminator_custom_form_mail_user_message', array($this, 'action_forminator_mail_message'), 30, 5);
2206 add_action('forminator_custom_form_mail_before_send_mail', array($this, 'action_forminator_custom_form_mail_before_send_mail'), 30, 4);
2207 add_action('forminator_custom_form_mail_after_send_mail', array($this, 'action_forminator_custom_form_mail_after_send_mail'), 30, 3);
2208 }
2209
2210 /**
2211 * Load filters for this extension
2212 */
2213 public function load_filters() {
2214 add_filter('forminator_custom_form_submit_response', array($this, 'filter_forminator_custom_form_submit_response'), 30, 2);
2215 add_filter('forminator_custom_form_ajax_submit_response', array($this, 'filter_forminator_custom_form_submit_response'), 30, 2);
2216 }
2217
2218 public function action_forminator_custom_form_submit_before_set_fields($entry, $form_id, $field_data_array) {
2219 if (class_exists('Forminator_API')) {
2220 $form = Forminator_API::get_form($form_id);
2221 if (!is_wp_error($form)) {
2222 if ($form->is_prevent_store()) {
2223 $this->set('field_data_array', $field_data_array);
2224 $this->set('dataset', 'is_prevent_store');
2225 } elseif ($entry && is_object($entry) && property_exists($entry, 'entry_id') && isset($entry->entry_id)) {
2226 $this->set('dataset', $entry->entry_id);
2227 }
2228 }
2229 }
2230 }
2231
2232 public function action_forminator_custom_form_mail_before_send_mail($mail, $custom_form, $data, $entry) {
2233 add_filter('wp_mail', array($this, 'filter_wp_mail'), 30, 1);
2234 }
2235
2236 public function action_forminator_custom_form_mail_after_send_mail($mail, $custom_form, $data) {
2237 remove_filter('wp_mail', array($this, 'filter_wp_mail'), 30);
2238 $files = $this->helper->get('forminator_attachments');
2239 if (is_array($files) && !empty($files)) {
2240 foreach ($files as $key => $file) {
2241 $this->helper->delete_dir(dirname($file) . '/');
2242 }
2243 $this->helper->deset('forminator_attachments');
2244 $this->helper->deset('forminator_mail_attachments');
2245 }
2246 }
2247
2248 public function action_forminator_mail_message($message, $custom_form, $data, $entry, $mail) {
2249 if (isset($message) && false !== strpos($message, '[')) {
2250 $shortcode_tags = array(
2251 'e2pdf-download',
2252 'e2pdf-save',
2253 'e2pdf-attachment',
2254 'e2pdf-adobesign'
2255 );
2256
2257 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $message, $matches);
2258
2259 $tagnames = array_intersect($shortcode_tags, $matches[1]);
2260
2261 if (!empty($tagnames)) {
2262
2263 $pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames);
2264
2265 preg_match_all("/$pattern/", $message, $shortcodes);
2266 foreach ($shortcodes[0] as $key => $shortcode_value) {
2267 $shortcode = array();
2268 $shortcode[1] = $shortcodes[1][$key];
2269 $shortcode[2] = $shortcodes[2][$key];
2270 $shortcode[3] = $shortcodes[3][$key];
2271 $shortcode[4] = $shortcodes[4][$key];
2272 $shortcode[5] = $shortcodes[5][$key];
2273 $shortcode[6] = $shortcodes[6][$key];
2274
2275 $atts = shortcode_parse_atts($shortcode[3]);
2276
2277 $file = false;
2278
2279 if (!isset($atts['dataset']) && isset($atts['id'])) {
2280 $template = new Model_E2pdf_Template();
2281 $template->load($atts['id']);
2282 if ($template->get('extension') === 'forminator') {
2283 $entry_id = $this->get('dataset');
2284 if ($entry_id) {
2285 if (($shortcode[2] === 'e2pdf-download' || $shortcode['2'] === 'e2pdf-view') && $entry_id == 'is_prevent_store') {
2286 //data is empty to fill pdf
2287 } else {
2288 if ($entry_id == 'is_prevent_store') {
2289 add_filter('e2pdf_model_shortcode_extension_options', array($this, 'filter_e2pdf_model_shortcode_extension_options'), 30, 2);
2290 }
2291 $atts['dataset'] = $entry_id;
2292 $shortcode[3] .= " dataset=\"{$entry_id}\"";
2293 }
2294 }
2295 }
2296 }
2297
2298 if (!isset($atts['apply'])) {
2299 $shortcode[3] .= " apply=\"true\"";
2300 }
2301
2302 if (!isset($atts['filter'])) {
2303 $shortcode[3] .= " filter=\"true\"";
2304 }
2305
2306 if (($shortcode[2] === 'e2pdf-save' && isset($atts['attachment']) && $atts['attachment'] == 'true') || $shortcode[2] === 'e2pdf-attachment') {
2307 $file = do_shortcode_tag($shortcode);
2308 if ($file) {
2309 if ($shortcode[2] != 'e2pdf-save' && !isset($atts['pdf'])) {
2310 $this->helper->add('forminator_attachments', $file);
2311 }
2312 $this->helper->add('forminator_mail_attachments', $file);
2313 }
2314 $message = str_replace($shortcode_value, '', $message);
2315 } else {
2316 $message = str_replace($shortcode_value, do_shortcode_tag($shortcode), $message);
2317 }
2318 remove_filter('e2pdf_model_shortcode_extension_options', array($this, 'filter_e2pdf_model_shortcode_extension_options'), 30);
2319 }
2320 }
2321 }
2322
2323 return $message;
2324 }
2325
2326 public function filter_e2pdf_model_shortcode_extension_options($options = array(), $template) {
2327 if ($this->get('dataset') && $this->get('dataset') == 'is_prevent_store') {
2328 $options['field_data_array'] = $this->get('field_data_array');
2329 }
2330 return $options;
2331 }
2332
2333 public function filter_forminator_custom_form_submit_response($response, $form_id) {
2334
2335 if (isset($response['message']) && false !== strpos($response['message'], '[') && isset($response['success']) && $response['success']) {
2336 $shortcode_tags = array(
2337 'e2pdf-download',
2338 'e2pdf-save',
2339 'e2pdf-view',
2340 'e2pdf-adobesign'
2341 );
2342
2343 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $response['message'], $matches);
2344
2345 $tagnames = array_intersect($shortcode_tags, $matches[1]);
2346
2347 if (!empty($tagnames)) {
2348
2349 $pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames);
2350
2351 preg_match_all("/$pattern/", $response['message'], $shortcodes);
2352 foreach ($shortcodes[0] as $key => $shortcode_value) {
2353 $shortcode = array();
2354 $shortcode[1] = $shortcodes[1][$key];
2355 $shortcode[2] = $shortcodes[2][$key];
2356 $shortcode[3] = $shortcodes[3][$key];
2357 $shortcode[4] = $shortcodes[4][$key];
2358 $shortcode[5] = $shortcodes[5][$key];
2359 $shortcode[6] = $shortcodes[6][$key];
2360
2361 $atts = shortcode_parse_atts($shortcode[3]);
2362
2363 if (($shortcode[2] === 'e2pdf-save' && isset($atts['attachment']) && $atts['attachment'] == 'true') || $shortcode[2] === 'e2pdf-attachment') {
2364
2365 } else {
2366 if (!isset($atts['dataset']) && isset($atts['id'])) {
2367 $template = new Model_E2pdf_Template();
2368 $template->load($atts['id']);
2369 if ($template->get('extension') === 'forminator') {
2370 $entry_id = $this->get('dataset');
2371 if ($entry_id) {
2372 if (($shortcode[2] === 'e2pdf-download' || $shortcode['2'] === 'e2pdf-view') && $entry_id == 'is_prevent_store') {
2373 //data is empty to fill pdf
2374 } else {
2375 if ($entry_id == 'is_prevent_store') {
2376 add_filter('e2pdf_model_shortcode_extension_options', array($this, 'filter_e2pdf_model_shortcode_extension_options'), 30, 2);
2377 }
2378 $atts['dataset'] = $entry_id;
2379 $shortcode[3] .= " dataset=\"{$entry_id}\"";
2380 }
2381 }
2382 }
2383 }
2384
2385 if (!isset($atts['apply'])) {
2386 $shortcode[3] .= " apply=\"true\"";
2387 }
2388
2389 if (!isset($atts['filter'])) {
2390 $shortcode[3] .= " filter=\"true\"";
2391 }
2392
2393 $response['message'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $response['message']);
2394 remove_filter('e2pdf_model_shortcode_extension_options', array($this, 'filter_e2pdf_model_shortcode_extension_options'), 30);
2395 }
2396 }
2397 }
2398 }
2399 $this->set('dataset', false);
2400 return $response;
2401 }
2402
2403 public function filter_wp_mail($args = array()) {
2404 $files = $this->helper->get('forminator_mail_attachments');
2405 if (is_array($files) && !empty($files)) {
2406 foreach ($files as $file) {
2407 $args['attachments'][] = $file;
2408 }
2409 }
2410 $wp_mail = array(
2411 'to' => $args['to'],
2412 'subject' => $args['subject'],
2413 'message' => $args['message'],
2414 'headers' => $args['headers'],
2415 'attachments' => $args['attachments'],
2416 );
2417
2418 return $wp_mail;
2419 }
2420
2421 /**
2422 * Get styles for generating Map Field function
2423 *
2424 * @return array - List of css files to load
2425 */
2426 public function styles() {
2427 $styles = array();
2428 if (function_exists('forminator_plugin_url')) {
2429 if (defined('FORMINATOR_VERSION')) {
2430 $version = FORMINATOR_VERSION;
2431 } else {
2432 $version = '0';
2433 }
2434 $styles = array(
2435 forminator_plugin_url() . 'assets/forminator-ui/css/forminator-forms.min.css?v=' . $version,
2436 plugins_url('css/extension/forminator.css?v=' . time(), $this->helper->get('plugin_file_path'))
2437 );
2438 }
2439 return $styles;
2440 }
2441
2442 }
2443