PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.04.07
E2Pdf – Export Pdf Tool for WordPress v1.04.07
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.04.07, at classes/extension/e2pdf-forminator.php

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