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

2,358 lines 114.3 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' => 'text-' . $element['element_id'],
442 'type' => 'text',
443 'cols' => '12',
444 "required" => false,
445 "field_label" => $element['value'] ? '{text-' . $element['element_id'] . '} ' . $element['value'] : '{text-' . $element['element_id'] . '}',
446 "placeholder" => '',
447 "validation" => false,
448 ),
449 ),
450 );
451 $pages[$page_key]['elements'][$element_key]['value'] = '{text-' . $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' => 'textarea-' . $element['element_id'],
461 'type' => 'textarea',
462 'cols' => '12',
463 "required" => false,
464 "field_label" => $element['value'] ? '{textarea-' . $element['element_id'] . '} ' . $element['value'] : '{textarea-' . $element['element_id'] . '}',
465 "placeholder" => '',
466 "validation" => false,
467 ),
468 ),
469 );
470 $pages[$page_key]['elements'][$element_key]['value'] = '{textarea-' . $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' => 'select-' . $element['element_id'],
491 'type' => 'select',
492 'cols' => '12',
493 "required" => false,
494 'options' => $options,
495 "field_label" => '{select-' . $element['element_id'] . '}',
496 "placeholder" => '',
497 "validation" => false,
498 ),
499 ),
500 );
501 $pages[$page_key]['elements'][$element_key]['value'] = '{select-' . $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'] = '{checkbox-' . $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'] = '{checkbox-' . $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'] = '{radio-' . $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'] = '{radio-' . $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' => 'checkbox-' . $element['element_id'],
557 'type' => 'checkbox',
558 'cols' => '12',
559 "required" => false,
560 'options' => $element['options'],
561 "field_label" => '{checkbox-' . $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' => 'radio-' . $element['element_id'],
575 'type' => 'radio',
576 'cols' => '12',
577 'required' => false,
578 'options' => $element['options'],
579 'field_label' => '{radio-' . $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 "use-custom-submit" => "true",
593 "custom-submit-text" => __("Send Message", Forminator::DOMAIN),
594 "use-custom-invalid-form" => "true",
595 "custom-invalid-form-message" => __("Error: Your form is not valid, please fix the errors!", Forminator::DOMAIN),
596 "enable-ajax" => "true",
597 "validation" => "on_submit"
598 );
599
600 if (class_exists('Forminator_API')) {
601 if ($item = Forminator_API::add_form($template->get('title'), $wrappers, $settings)) {
602 $template->set('item', $item);
603 }
604 }
605 }
606
607 return $template;
608 }
609
610 public function visual_mapper() {
611
612 $item = $this->get('item');
613 $html = '';
614 $source = '';
615
616 if ($item && function_exists("forminator_form_preview") && class_exists("Forminator_API")) {
617
618 $form = Forminator_API::get_form($item);
619 if (is_wp_error($form)) {
620 return __('Form could not be found', 'e2pdf');
621 }
622
623 ob_start();
624 forminator_form_preview($item, true, array());
625 $source = ob_get_clean();
626 if (!$source) {
627 $source = forminator_form_preview($item, false, array());
628 }
629
630 if ($source) {
631 libxml_use_internal_errors(true);
632 $dom = new DOMDocument();
633 if (function_exists('mb_convert_encoding')) {
634 $html = $dom->loadHTML(mb_convert_encoding($source, 'HTML-ENTITIES', 'UTF-8'));
635 } else {
636 $html = $dom->loadHTML('<?xml encoding="UTF-8">' . $source);
637 }
638 libxml_clear_errors();
639 }
640
641 if (!$source) {
642 return __('Form source is empty', 'e2pdf');
643 } elseif (!$html) {
644 return __('Form could not be parsed due incorrect HTML', 'e2pdf');
645 } else {
646
647 $xpath = new DomXPath($dom);
648
649 $remove_by_class = array(
650 'forminator-pagination-submit'
651 );
652 foreach ($remove_by_class as $key => $class) {
653 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
654 foreach ($elements as $element) {
655 $element->parentNode->removeChild($element);
656 }
657 }
658
659 $remove_by_tag = array(
660 'script'
661 );
662 foreach ($remove_by_tag as $key => $tag) {
663 $elements = $xpath->query("//{$tag}");
664 foreach ($elements as $element) {
665 $element->parentNode->removeChild($element);
666 }
667 }
668
669 $inputs = $xpath->query("//*[contains(@class, 'forminator-input')]");
670 foreach ($inputs as $element) {
671 if (!$element->attributes->getNamedItem("type")->nodeValue) {
672 $element->setAttribute("type", "text");
673 }
674 }
675
676 //remove pagination
677 $pagination = $xpath->query("//*[contains(@class, 'forminator-pagination')]");
678 foreach ($pagination as $element) {
679 if ($element->attributes->getNamedItem("style")) {
680 $element->attributes->getNamedItem("style")->nodeValue = "";
681 }
682 }
683
684 //remove buttons
685 $remove_rows = $xpath->query("//*[contains(@class, 'forminator-row')][.//button[contains(@class, 'forminator-button') and not(contains(@class, 'forminator-upload-button'))]]");
686 foreach ($remove_rows as $element) {
687 $element->parentNode->removeChild($element);
688 }
689
690 //replace name on fileuploads
691 $fileuploads = $xpath->query("//*[contains(@class, 'forminator-upload')]");
692 foreach ($fileuploads as $element) {
693 $file = $xpath->query(".//input[contains(@class, 'forminator-input-file')]", $element)->item(0);
694 $button = $xpath->query(".//button[contains(@class, 'forminator-upload-button')]", $element)->item(0);
695 if ($file && $button) {
696 if ($button->attributes->getNamedItem("type")) {
697 $button->attributes->getNamedItem("type")->nodeValue = "upload";
698 }
699 $button->setAttribute("name", "{" . $file->attributes->getNamedItem("name")->nodeValue . "}");
700 }
701 }
702
703 //replace names on inputs
704 $inputs = $xpath->query("//input");
705 foreach ($inputs as $element) {
706 $type = $element->attributes->getNamedItem("type")->nodeValue;
707 if ($type == 'checkbox') {
708 if ($element->attributes->getNamedItem("name")) {
709 $element->attributes->getNamedItem("name")->nodeValue = str_replace("[]", "", $element->attributes->getNamedItem("name")->nodeValue);
710 }
711 }
712
713 if ($element->attributes->getNamedItem("name")) {
714 $element->attributes->getNamedItem("name")->nodeValue = "{" . $element->attributes->getNamedItem("name")->nodeValue . "}";
715 }
716
717 if ($element->attributes->getNamedItem("class")) {
718 if (strpos($element->attributes->getNamedItem("class")->nodeValue, 'forminator-checkbox--input') !== false) {
719 $element->attributes->getNamedItem("class")->nodeValue = $element->attributes->getNamedItem("class")->nodeValue . " forminator-checkbox--design";
720 }
721 if (strpos($element->attributes->getNamedItem("class")->nodeValue, 'forminator-radio--input') !== false) {
722 $element->attributes->getNamedItem("class")->nodeValue = $element->attributes->getNamedItem("class")->nodeValue . " forminator-radio--design";
723 }
724 }
725 }
726
727 //replace names on textareas
728 $textareas = $xpath->query("//textarea");
729 foreach ($textareas as $element) {
730 if ($element->attributes->getNamedItem("name")) {
731 $element->attributes->getNamedItem("name")->nodeValue = "{" . $element->attributes->getNamedItem("name")->nodeValue . "}";
732 }
733 }
734
735 //replace names on selects
736 $selects = $xpath->query("//select");
737 foreach ($selects as $element) {
738 if ($element->attributes->getNamedItem("name")) {
739 $element->attributes->getNamedItem("name")->nodeValue = "{" . $element->attributes->getNamedItem("name")->nodeValue . "}";
740 }
741 }
742
743 //multiselects
744 $multiselect = $xpath->query("//ul[contains(@class, 'forminator-multiselect')]");
745 foreach ($multiselect as $element) {
746 $name = '';
747 $options = array();
748 $inputs = $xpath->query(".//*[contains(@class, 'forminator-multiselect--item')]", $element);
749
750 foreach ($inputs as $sub_element) {
751 $input = $xpath->query(".//input", $sub_element)->item(0);
752 $label = $xpath->query(".//label", $sub_element)->item(0);
753
754 if ($input && $label) {
755 $options[] = array(
756 'value' => $input->attributes->getNamedItem("value")->nodeValue,
757 'label' => $label->childNodes->item(0)->nodeValue
758 );
759
760 $name = $input->attributes->getNamedItem("name")->nodeValue;
761 }
762
763 $sub_element->parentNode->removeChild($sub_element);
764 }
765
766 $li = $dom->createElement('li');
767 $field_atts = array(
768 'class' => 'forminator-multiselect--item',
769 );
770 foreach ($field_atts as $key => $value) {
771 $attr = $dom->createAttribute($key);
772 $attr->value = $value;
773 $li->appendChild($attr);
774 }
775 $element->appendChild($li);
776
777
778 $field = $dom->createElement('select');
779 $field_atts = array(
780 'multiple' => 'multiple',
781 'name' => $name,
782 );
783 foreach ($field_atts as $key => $value) {
784 $attr = $dom->createAttribute($key);
785 $attr->value = $value;
786 $field->appendChild($attr);
787 }
788
789 $li->appendChild($field);
790
791 foreach ($options as $option) {
792 $option_field = $dom->createElement('option');
793 $field_atts = array(
794 'value' => $option['value'],
795 );
796 foreach ($field_atts as $key => $value) {
797 $attr = $dom->createAttribute($key);
798 $attr->value = $value;
799 $option_field->appendChild($attr);
800 }
801
802 $label = $dom->createTextNode($option['label']);
803 $option_field->appendChild($label);
804 $field->appendChild($option_field);
805 }
806 }
807
808 return $dom->saveHTML();
809 }
810 }
811 return false;
812 }
813
814 /**
815 * Auto Generate of Template for this extension
816 *
817 * @return array - List of elements
818 */
819 public function auto() {
820
821 $item = $this->get('item');
822
823 $response = array();
824 $elements = array();
825 $fields = array();
826 $form = false;
827
828 if (class_exists("Forminator_API")) {
829 $forminator_form = Forminator_API::get_form($item);
830 if (!is_wp_error($forminator_form)) {
831 $form = $forminator_form;
832 $fields = $form->fields;
833 }
834 }
835
836 if ($form && $fields) {
837
838 foreach ($fields as $field_obj) {
839 $field = $field_obj->raw;
840 $float = true;
841 $width = 100 / (12 / $field['cols']);
842
843 switch ($field['type']) {
844 case 'name':
845 case 'email':
846 case 'phone':
847 case 'url':
848 case 'upload':
849 case 'number':
850 case 'date':
851 //multiple name field
852 if ($field['type'] == 'name' && isset($field['multiple_name']) && $field['multiple_name']) {
853
854 if (!$field['prefix'] && !$field['fname']) {
855 if ($field['mname']) {
856 $elements[] = $this->auto_field($field, array(
857 'type' => 'e2pdf-html',
858 'block' => true,
859 'float' => true,
860 'properties' => array(
861 'top' => '20',
862 'left' => '20',
863 'right' => '20',
864 'width' => $field['lname'] ? $width / 2 . '%' : $width . '%',
865 'height' => 'auto',
866 'value' => $field['mname_label'],
867 )
868 ));
869
870 $elements[] = $this->auto_field($field, array(
871 'type' => 'e2pdf-input',
872 'properties' => array(
873 'top' => '5',
874 'width' => '100%',
875 'height' => 'auto',
876 'value' => "{" . $field['element_id'] . "-middle-name" . "}",
877 )
878 ));
879 }
880
881 if ($field['lname']) {
882 $elements[] = $this->auto_field($field, array(
883 'type' => 'e2pdf-html',
884 'block' => true,
885 'float' => true,
886 'properties' => array(
887 'top' => '20',
888 'left' => '20',
889 'right' => '20',
890 'width' => $field['mname'] ? $width / 2 . '%' : $width . '%',
891 'height' => 'auto',
892 'value' => $field['lname_label'],
893 )
894 ));
895
896 $elements[] = $this->auto_field($field, array(
897 'type' => 'e2pdf-input',
898 'properties' => array(
899 'top' => '5',
900 'width' => '100%',
901 'height' => 'auto',
902 'value' => "{" . $field['element_id'] . "-last-name" . "}",
903 )
904 ));
905 }
906 } else {
907
908 if ($field['prefix']) {
909 $elements[] = $this->auto_field($field, array(
910 'type' => 'e2pdf-html',
911 'block' => true,
912 'float' => true,
913 'properties' => array(
914 'top' => '20',
915 'left' => '20',
916 'right' => '20',
917 'width' => $field['fname'] ? $width / 2 . '%' : $width . '%',
918 'height' => 'auto',
919 'value' => $field['prefix_label'],
920 )
921 ));
922
923 $options_tmp = array();
924 if (function_exists('forminator_get_name_prefixes')) {
925 $options = forminator_get_name_prefixes();
926 foreach ($options as $key => $option) {
927 $options_tmp[] = $key;
928 }
929 }
930
931 $elements[] = $this->auto_field($field, array(
932 'type' => 'e2pdf-select',
933 'properties' => array(
934 'top' => '5',
935 'width' => '100%',
936 'height' => 'auto',
937 'options' => implode("\n", $options_tmp),
938 'value' => "{" . $field['element_id'] . "-prefix" . "}",
939 )
940 ));
941
942 if ($field['mname'] && $field['fname']) {
943 $elements[] = $this->auto_field($field, array(
944 'type' => 'e2pdf-html',
945 'properties' => array(
946 'top' => '20',
947 'width' => $field['lname'] ? '100%' : '200%',
948 'right' => $field['lname'] ? '0' : '-40',
949 'height' => 'auto',
950 'value' => $field['mname_label'],
951 )
952 ));
953
954 $elements[] = $this->auto_field($field, array(
955 'type' => 'e2pdf-input',
956 'properties' => array(
957 'top' => '5',
958 'width' => $field['lname'] ? '100%' : '200%',
959 'height' => 'auto',
960 'right' => $field['lname'] ? '0' : '-40',
961 'value' => "{" . $field['element_id'] . "-middle-name" . "}",
962 )
963 ));
964 } elseif ($field['lname'] && !$field['mname'] && $field['fname']) {
965
966 $elements[] = $this->auto_field($field, array(
967 'type' => 'e2pdf-html',
968 'properties' => array(
969 'top' => '20',
970 'width' => $field['mname'] ? '100%' : '200%',
971 'height' => 'auto',
972 'right' => $field['mname'] ? '0' : '-40',
973 'value' => $field['lname_label'],
974 )
975 ));
976
977 $elements[] = $this->auto_field($field, array(
978 'type' => 'e2pdf-input',
979 'properties' => array(
980 'top' => '5',
981 'width' => $field['mname'] ? '100%' : '200%',
982 'height' => 'auto',
983 'right' => $field['mname'] ? '0' : '-40',
984 'value' => "{" . $field['element_id'] . "-last-name" . "}",
985 )
986 ));
987 }
988 }
989
990 if ($field['fname']) {
991 $elements[] = $this->auto_field($field, array(
992 'type' => 'e2pdf-html',
993 'block' => true,
994 'float' => true,
995 'properties' => array(
996 'top' => '20',
997 'left' => '20',
998 'right' => '20',
999 'width' => $field['prefix'] ? ($width / 2) . '%' : $width . '%',
1000 'height' => 'auto',
1001 'value' => $field['fname_label'],
1002 )
1003 ));
1004
1005 $elements[] = $this->auto_field($field, array(
1006 'type' => 'e2pdf-input',
1007 'properties' => array(
1008 'top' => '5',
1009 'width' => '100%',
1010 'height' => 'auto',
1011 'value' => "{" . $field['element_id'] . "-first-name" . "}",
1012 )
1013 ));
1014
1015 if ($field['lname'] && $field['mname'] && $field['prefix']) {
1016 $elements[] = $this->auto_field($field, array(
1017 'type' => 'e2pdf-html',
1018 'properties' => array(
1019 'top' => '20',
1020 'width' => $field['mname'] ? '100%' : '200%',
1021 'height' => 'auto',
1022 'right' => $field['mname'] ? '0' : '-40',
1023 'value' => $field['lname_label'],
1024 )
1025 ));
1026
1027 $elements[] = $this->auto_field($field, array(
1028 'type' => 'e2pdf-input',
1029 'properties' => array(
1030 'top' => '5',
1031 'width' => $field['mname'] ? '100%' : '200%',
1032 'height' => 'auto',
1033 'right' => $field['mname'] ? '0' : '-40',
1034 'value' => "{" . $field['element_id'] . "-last-name" . "}",
1035 )
1036 ));
1037 }
1038 }
1039
1040 if (!$field['prefix'] || !$field['fname']) {
1041 if ($field['mname']) {
1042 $elements[] = $this->auto_field($field, array(
1043 'type' => 'e2pdf-html',
1044 'properties' => array(
1045 'top' => '20',
1046 'right' => $field['lname'] ? '20' : '0',
1047 'width' => $field['lname'] ? '50%' : '100%',
1048 'height' => 'auto',
1049 'value' => $field['mname_label'],
1050 )
1051 ));
1052 }
1053
1054 if ($field['lname']) {
1055 $elements[] = $this->auto_field($field, array(
1056 'type' => 'e2pdf-html',
1057 'float' => $field['mname'] ? true : false,
1058 'properties' => array(
1059 'top' => '20',
1060 'left' => $field['mname'] ? '20' : '0',
1061 'width' => $field['mname'] ? '50%' : '100%',
1062 'height' => 'auto',
1063 'value' => $field['lname_label'],
1064 )
1065 ));
1066 }
1067
1068 if ($field['mname']) {
1069 $elements[] = $this->auto_field($field, array(
1070 'type' => 'e2pdf-input',
1071 'properties' => array(
1072 'top' => '5',
1073 'right' => $field['lname'] ? '20' : '0',
1074 'width' => $field['lname'] ? '50%' : '100%',
1075 'height' => 'auto',
1076 'value' => "{" . $field['element_id'] . "-middle-name" . "}",
1077 )
1078 ));
1079 }
1080
1081 if ($field['lname']) {
1082 $elements[] = $this->auto_field($field, array(
1083 'type' => 'e2pdf-input',
1084 'float' => $field['mname'] ? true : false,
1085 'properties' => array(
1086 'top' => '5',
1087 'left' => $field['mname'] ? '20' : '0',
1088 'width' => $field['mname'] ? '50%' : '100%',
1089 'height' => 'auto',
1090 'value' => "{" . $field['element_id'] . "-last-name" . "}",
1091 )
1092 ));
1093 }
1094 }
1095 }
1096 } elseif ($field['type'] == 'date' && $field['field_type'] == 'select') {
1097
1098 $elements[] = $this->auto_field($field, array(
1099 'type' => 'e2pdf-html',
1100 'block' => true,
1101 'float' => $float,
1102 'properties' => array(
1103 'top' => '20',
1104 'left' => '20',
1105 'right' => '20',
1106 'width' => $width . "%",
1107 'height' => 'auto',
1108 'value' => $field['field_label'],
1109 )
1110 ));
1111
1112 $days = array();
1113 $months = array();
1114 $years = array();
1115 if (class_exists('Forminator_Date')) {
1116 $forminator_date = new Forminator_Date();
1117 $options = $forminator_date->get_day();
1118 foreach ($options as $option) {
1119 $days[] = $option['value'];
1120 }
1121
1122 $options = $forminator_date->get_months();
1123 foreach ($options as $option) {
1124 $months[] = $option['value'];
1125 }
1126
1127 $options = $forminator_date->get_years($field['min_year'], $field['max_year']);
1128 foreach ($options as $option) {
1129 $years[] = $option['value'];
1130 }
1131 }
1132
1133 $elements[] = $this->auto_field($field, array(
1134 'type' => 'e2pdf-select',
1135 'properties' => array(
1136 'top' => '5',
1137 'width' => '30%',
1138 'height' => 'auto',
1139 'options' => implode("\n", $days),
1140 'value' => "{" . $field['element_id'] . "-month" . "}",
1141 )
1142 ));
1143
1144 $elements[] = $this->auto_field($field, array(
1145 'type' => 'e2pdf-select',
1146 'float' => true,
1147 'properties' => array(
1148 'top' => '5',
1149 'left' => '5%',
1150 'right' => '5%',
1151 'width' => '40%',
1152 'height' => 'auto',
1153 'options' => implode("\n", $months),
1154 'value' => "{" . $field['element_id'] . "-day" . "}",
1155 )
1156 ));
1157
1158 $elements[] = $this->auto_field($field, array(
1159 'type' => 'e2pdf-select',
1160 'float' => true,
1161 'properties' => array(
1162 'top' => '5',
1163 'width' => '30%',
1164 'height' => 'auto',
1165 'options' => implode("\n", $years),
1166 'value' => "{" . $field['element_id'] . "-year" . "}",
1167 )
1168 ));
1169 } elseif ($field['type'] == 'date' && $field['field_type'] == 'input') {
1170
1171 $elements[] = $this->auto_field($field, array(
1172 'type' => 'e2pdf-html',
1173 'block' => true,
1174 'float' => $float,
1175 'properties' => array(
1176 'top' => '20',
1177 'left' => '20',
1178 'right' => '20',
1179 'width' => $width . "%",
1180 'height' => 'auto',
1181 'value' => $field['field_label'],
1182 )
1183 ));
1184
1185 $elements[] = $this->auto_field($field, array(
1186 'type' => 'e2pdf-input',
1187 'properties' => array(
1188 'top' => '5',
1189 'width' => '30%',
1190 'height' => 'auto',
1191 'value' => "{" . $field['element_id'] . "-month" . "}",
1192 )
1193 ));
1194
1195 $elements[] = $this->auto_field($field, array(
1196 'type' => 'e2pdf-input',
1197 'float' => true,
1198 'properties' => array(
1199 'top' => '5',
1200 'left' => '5%',
1201 'right' => '5%',
1202 'width' => '40%',
1203 'height' => 'auto',
1204 'value' => "{" . $field['element_id'] . "-day" . "}",
1205 )
1206 ));
1207
1208 $elements[] = $this->auto_field($field, array(
1209 'float' => true,
1210 'type' => 'e2pdf-input',
1211 'properties' => array(
1212 'top' => '5',
1213 'width' => '30%',
1214 'height' => 'auto',
1215 'value' => "{" . $field['element_id'] . "-year" . "}",
1216 )
1217 ));
1218 } else {
1219
1220 $elements[] = $this->auto_field($field, array(
1221 'type' => 'e2pdf-html',
1222 'block' => true,
1223 'float' => $float,
1224 'properties' => array(
1225 'top' => '20',
1226 'left' => '20',
1227 'right' => '20',
1228 'width' => $width . "%",
1229 'height' => 'auto',
1230 'value' => $field['field_label'],
1231 )
1232 ));
1233
1234 $elements[] = $this->auto_field($field, array(
1235 'type' => 'e2pdf-input',
1236 'properties' => array(
1237 'top' => '5',
1238 'width' => '100%',
1239 'height' => 'auto',
1240 'value' => "{" . $field['element_id'] . "}",
1241 )
1242 ));
1243 }
1244 break;
1245 case 'address':
1246 if (!$field['street_address'] && !$field['address_line']) {
1247
1248 if (!$field['address_city'] && !$field['address_state']) {
1249 if ($field['address_zip']) {
1250 $elements[] = $this->auto_field($field, array(
1251 'type' => 'e2pdf-html',
1252 'block' => true,
1253 'float' => true,
1254 'properties' => array(
1255 'top' => '20',
1256 'left' => '20',
1257 'right' => '20',
1258 'width' => $field['address_country'] ? $width / 2 . '%' : $width . '%',
1259 'height' => 'auto',
1260 'value' => $field['address_zip_label']
1261 )
1262 ));
1263
1264 $elements[] = $this->auto_field($field, array(
1265 'type' => 'e2pdf-input',
1266 'properties' => array(
1267 'top' => '5',
1268 'width' => '100%',
1269 'height' => 'auto',
1270 'value' => "{" . $field['element_id'] . "-zip" . "}",
1271 )
1272 ));
1273 }
1274
1275 if ($field['address_country']) {
1276 $elements[] = $this->auto_field($field, array(
1277 'type' => 'e2pdf-html',
1278 'block' => true,
1279 'float' => true,
1280 'properties' => array(
1281 'top' => '20',
1282 'left' => '20',
1283 'right' => '20',
1284 'width' => $field['address_zip'] ? $width / 2 . '%' : $width . '%',
1285 'height' => 'auto',
1286 'value' => $field['address_country_label'],
1287 )
1288 ));
1289
1290 $options_tmp = array();
1291 if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) {
1292 $options = forminator_to_field_array(forminator_get_countries_list(), true);
1293 foreach ($options as $option) {
1294 $options_tmp[] = $option['value'];
1295 }
1296 //can be value or label
1297 }
1298
1299 $elements[] = $this->auto_field($field, array(
1300 'type' => 'e2pdf-select',
1301 'properties' => array(
1302 'top' => '5',
1303 'width' => '100%',
1304 'height' => 'auto',
1305 'options' => implode("\n", $options_tmp),
1306 'value' => "{" . $field['element_id'] . "-country" . "}",
1307 )
1308 ));
1309 }
1310 } else {
1311
1312 if ($field['address_city']) {
1313 $elements[] = $this->auto_field($field, array(
1314 'type' => 'e2pdf-html',
1315 'block' => true,
1316 'float' => true,
1317 'properties' => array(
1318 'top' => '20',
1319 'left' => '20',
1320 'right' => '20',
1321 'width' => $field['address_state'] ? $width / 2 . '%' : $width . '%',
1322 'height' => 'auto',
1323 'value' => $field['address_city_label'],
1324 )
1325 ));
1326
1327 $elements[] = $this->auto_field($field, array(
1328 'type' => 'e2pdf-input',
1329 'properties' => array(
1330 'top' => '5',
1331 'width' => '100%',
1332 'height' => 'auto',
1333 'value' => "{" . $field['element_id'] . "-city" . "}",
1334 )
1335 ));
1336
1337 if ($field['address_zip'] && $field['address_state']) {
1338 $elements[] = $this->auto_field($field, array(
1339 'type' => 'e2pdf-html',
1340 'properties' => array(
1341 'top' => '20',
1342 'right' => $field['address_country'] ? '0' : '-40',
1343 'width' => $field['address_country'] ? '100%' : '200%',
1344 'height' => 'auto',
1345 'value' => $field['address_zip_label'],
1346 )
1347 ));
1348
1349 $elements[] = $this->auto_field($field, array(
1350 'type' => 'e2pdf-input',
1351 'properties' => array(
1352 'top' => '5',
1353 'right' => $field['address_country'] ? '0' : '-40',
1354 'width' => $field['address_country'] ? '100%' : '200%',
1355 'height' => 'auto',
1356 'value' => "{" . $field['element_id'] . "-zip" . "}",
1357 )
1358 ));
1359 } elseif ($field['address_country'] && !$field['address_zip'] && $field['address_state']) {
1360
1361 $elements[] = $this->auto_field($field, array(
1362 'type' => 'e2pdf-html',
1363 'properties' => array(
1364 'top' => '20',
1365 'right' => $field['address_zip'] ? '0' : '-40',
1366 'width' => $field['address_zip'] ? '100%' : '200%',
1367 'height' => 'auto',
1368 'value' => $field['address_country_label'],
1369 )
1370 ));
1371
1372 $options_tmp = array();
1373 if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) {
1374 $options = forminator_to_field_array(forminator_get_countries_list(), true);
1375 foreach ($options as $option) {
1376 $options_tmp[] = $option['value'];
1377 }
1378 //can be value or label
1379 }
1380
1381 $elements[] = $this->auto_field($field, array(
1382 'type' => 'e2pdf-select',
1383 'properties' => array(
1384 'top' => '5',
1385 'right' => $field['address_zip'] ? '0' : '-40',
1386 'width' => $field['address_zip'] ? '100%' : '200%',
1387 'height' => 'auto',
1388 'options' => implode("\n", $options_tmp),
1389 'value' => "{" . $field['element_id'] . "-country" . "}",
1390 )
1391 ));
1392 }
1393 }
1394
1395 if ($field['address_state']) {
1396 $elements[] = $this->auto_field($field, array(
1397 'type' => 'e2pdf-html',
1398 'block' => true,
1399 'float' => true,
1400 'properties' => array(
1401 'top' => '20',
1402 'left' => '20',
1403 'right' => '20',
1404 'width' => $field['address_city'] ? ($width / 2) . '%' : $width . '%',
1405 'height' => 'auto',
1406 'value' => $field['address_state_label'],
1407 )
1408 ));
1409
1410 $elements[] = $this->auto_field($field, array(
1411 'type' => 'e2pdf-input',
1412 'properties' => array(
1413 'top' => '5',
1414 'width' => '100%',
1415 'height' => 'auto',
1416 'value' => "{" . $field['element_id'] . "-state" . "}",
1417 )
1418 ));
1419
1420 if ($field['address_country'] && $field['address_zip'] && $field['address_city']) {
1421
1422 $elements[] = $this->auto_field($field, array(
1423 'type' => 'e2pdf-html',
1424 'properties' => array(
1425 'top' => '20',
1426 'right' => $field['address_zip'] ? '0' : '-40',
1427 'width' => $field['address_zip'] ? '100%' : '200%',
1428 'height' => 'auto',
1429 'value' => $field['address_country_label'],
1430 )
1431 ));
1432
1433 $options_tmp = array();
1434 if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) {
1435 $options = forminator_to_field_array(forminator_get_countries_list(), true);
1436 foreach ($options as $option) {
1437 $options_tmp[] = $option['value'];
1438 }
1439 //can be value or label
1440 }
1441
1442 $elements[] = $this->auto_field($field, array(
1443 'type' => 'e2pdf-select',
1444 'properties' => array(
1445 'top' => '5',
1446 'right' => $field['address_zip'] ? '0' : '-40',
1447 'width' => $field['address_zip'] ? '100%' : '200%',
1448 'height' => 'auto',
1449 'options' => implode("\n", $options_tmp),
1450 'value' => "{" . $field['element_id'] . "-country" . "}",
1451 )
1452 ));
1453 }
1454 }
1455
1456 if (!$field['address_city'] || !$field['address_state']) {
1457 if ($field['address_zip']) {
1458 $elements[] = $this->auto_field($field, array(
1459 'type' => 'e2pdf-html',
1460 'properties' => array(
1461 'top' => '20',
1462 'right' => $field['address_country'] ? '20' : '0',
1463 'width' => $field['address_country'] ? '50%' : '100%',
1464 'height' => 'auto',
1465 'value' => $field['address_zip_label'],
1466 )
1467 ));
1468 }
1469
1470 if ($field['address_country']) {
1471
1472 $elements[] = $this->auto_field($field, array(
1473 'type' => 'e2pdf-html',
1474 'float' => $field['address_zip'] ? true : false,
1475 'properties' => array(
1476 'top' => '20',
1477 'left' => $field['address_zip'] ? '20' : '0',
1478 'width' => $field['address_zip'] ? '50%' : '100%',
1479 'height' => 'auto',
1480 'value' => $field['address_country_label'],
1481 )
1482 ));
1483 }
1484
1485 if ($field['address_zip']) {
1486 $elements[] = $this->auto_field($field, array(
1487 'type' => 'e2pdf-input',
1488 'properties' => array(
1489 'top' => '5',
1490 'right' => $field['address_country'] ? '20' : '0',
1491 'width' => $field['address_country'] ? '50%' : '100%',
1492 'height' => 'auto',
1493 'value' => "{" . $field['element_id'] . "-zip" . "}",
1494 )
1495 ));
1496 }
1497
1498 if ($field['address_country']) {
1499 $options_tmp = array();
1500 if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) {
1501 $options = forminator_to_field_array(forminator_get_countries_list(), true);
1502 foreach ($options as $option) {
1503 $options_tmp[] = $option['value'];
1504 }
1505 //can be value or label
1506 }
1507
1508 $elements[] = $this->auto_field($field, array(
1509 'type' => 'e2pdf-select',
1510 'float' => $field['address_zip'] ? true : false,
1511 'properties' => array(
1512 'top' => '5',
1513 'left' => $field['address_zip'] ? '20' : '0',
1514 'width' => $field['address_zip'] ? '50%' : '100%',
1515 'height' => 'auto',
1516 'options' => implode("\n", $options_tmp),
1517 'value' => "{" . $field['element_id'] . "-country" . "}",
1518 )
1519 ));
1520 }
1521 }
1522 }
1523 } else {
1524
1525 if ($field['street_address']) {
1526 $elements[] = $this->auto_field($field, array(
1527 'type' => 'e2pdf-html',
1528 'block' => true,
1529 'float' => true,
1530 'properties' => array(
1531 'top' => '20',
1532 'left' => '20',
1533 'right' => '20',
1534 'width' => $width . '%',
1535 'height' => 'auto',
1536 'value' => $field['street_address_label'],
1537 )
1538 ));
1539
1540 $elements[] = $this->auto_field($field, array(
1541 'type' => 'e2pdf-input',
1542 'properties' => array(
1543 'top' => '5',
1544 'width' => '100%',
1545 'height' => 'auto',
1546 'value' => "{" . $field['element_id'] . "-street_address" . "}",
1547 )
1548 ));
1549 }
1550
1551 if ($field['address_line']) {
1552
1553 if ($field['address_line_label']) {
1554 $elements[] = $this->auto_field($field, array(
1555 'type' => 'e2pdf-html',
1556 'block' => $field['street_address'] ? false : true,
1557 'float' => $field['street_address'] ? false : true,
1558 'properties' => array(
1559 'top' => '20',
1560 'left' => $field['street_address'] ? '0' : '20',
1561 'right' => $field['street_address'] ? '0' : '20',
1562 'width' => $field['street_address'] ? '100%' : $width . '%',
1563 'height' => 'auto',
1564 'value' => $field['address_line_label'],
1565 )
1566 ));
1567 }
1568
1569 $elements[] = $this->auto_field($field, array(
1570 'type' => 'e2pdf-input',
1571 'properties' => array(
1572 'top' => $field['address_line_label'] ? '0' : '20',
1573 'width' => '100%',
1574 'height' => 'auto',
1575 'value' => "{" . $field['element_id'] . "-address_line" . "}",
1576 )
1577 ));
1578 }
1579
1580 if ($field['address_city']) {
1581
1582 $elements[] = $this->auto_field($field, array(
1583 'type' => 'e2pdf-html',
1584 'properties' => array(
1585 'top' => '20',
1586 'right' => $field['address_state'] ? '20' : '0',
1587 'width' => $field['address_state'] ? '50%' : '100%',
1588 'height' => 'auto',
1589 'value' => $field['address_city_label'],
1590 )
1591 ));
1592 }
1593
1594 if ($field['address_state']) {
1595 $elements[] = $this->auto_field($field, array(
1596 'type' => 'e2pdf-html',
1597 'float' => $field['address_city'] ? true : false,
1598 'properties' => array(
1599 'top' => $field['address_city'] ? '0' : '20',
1600 'left' => $field['address_city'] ? '20' : '0',
1601 'width' => $field['address_city'] ? '50%' : '100%',
1602 'height' => 'auto',
1603 'value' => $field['address_state_label'],
1604 )
1605 ));
1606 }
1607
1608 if ($field['address_city']) {
1609 $elements[] = $this->auto_field($field, array(
1610 'type' => 'e2pdf-input',
1611 'properties' => array(
1612 'top' => '5',
1613 'right' => $field['address_state'] ? '20' : '0',
1614 'width' => $field['address_state'] ? '50%' : '100%',
1615 'height' => 'auto',
1616 'value' => "{" . $field['element_id'] . "-city" . "}",
1617 )
1618 ));
1619 }
1620
1621 if ($field['address_state']) {
1622 $elements[] = $this->auto_field($field, array(
1623 'type' => 'e2pdf-input',
1624 'float' => $field['address_city'] ? true : false,
1625 'properties' => array(
1626 'top' => '5',
1627 'left' => $field['address_city'] ? '20' : '0',
1628 'width' => $field['address_city'] ? '50%' : '100%',
1629 'height' => 'auto',
1630 'value' => "{" . $field['element_id'] . "-state" . "}",
1631 )
1632 ));
1633 }
1634
1635 if ($field['address_zip']) {
1636
1637 $elements[] = $this->auto_field($field, array(
1638 'type' => 'e2pdf-html',
1639 'properties' => array(
1640 'top' => '20',
1641 'right' => $field['address_country'] ? '20' : '0',
1642 'width' => $field['address_country'] ? '50%' : '100%',
1643 'height' => 'auto',
1644 'value' => $field['address_zip_label'],
1645 )
1646 ));
1647 }
1648
1649 if ($field['address_country']) {
1650 $elements[] = $this->auto_field($field, array(
1651 'type' => 'e2pdf-html',
1652 'float' => $field['address_zip'] ? true : false,
1653 'properties' => array(
1654 'top' => '20',
1655 'left' => $field['address_zip'] ? '20' : '0',
1656 'width' => $field['address_zip'] ? '50%' : '100%',
1657 'height' => 'auto',
1658 'value' => $field['address_country_label'],
1659 )
1660 ));
1661 }
1662
1663 if ($field['address_zip']) {
1664 $elements[] = $this->auto_field($field, array(
1665 'type' => 'e2pdf-input',
1666 'properties' => array(
1667 'top' => '5',
1668 'right' => $field['address_country'] ? '20' : '0',
1669 'width' => $field['address_country'] ? '50%' : '100%',
1670 'height' => 'auto',
1671 'value' => "{" . $field['element_id'] . "-zip" . "}",
1672 )
1673 ));
1674 }
1675
1676 if ($field['address_country']) {
1677 $options_tmp = array();
1678 if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) {
1679 $options = forminator_to_field_array(forminator_get_countries_list(), true);
1680 foreach ($options as $option) {
1681 $options_tmp[] = $option['value'];
1682 }
1683 //can be value or label
1684 }
1685
1686 $elements[] = $this->auto_field($field, array(
1687 'type' => 'e2pdf-select',
1688 'float' => $field['address_zip'] ? true : false,
1689 'properties' => array(
1690 'top' => '5',
1691 'left' => $field['address_zip'] ? '20' : '0',
1692 'width' => $field['address_zip'] ? '50%' : '100%',
1693 'height' => 'auto',
1694 'options' => implode("\n", $options_tmp),
1695 'value' => "{" . $field['element_id'] . "-country" . "}",
1696 )
1697 ));
1698 }
1699 }
1700 break;
1701 case 'time':
1702 $hours = array();
1703 $minutes = array();
1704
1705 if (class_exists('Forminator_Time')) {
1706 $forminator_time = new Forminator_Time();
1707 $options = $forminator_time->get_hours($field['time_type']);
1708 foreach ($options as $option) {
1709 $hours[] = $option['value'];
1710 }
1711
1712 $options = $forminator_time->get_minutes();
1713 foreach ($options as $option) {
1714 $minutes[] = $option['value'];
1715 }
1716 }
1717
1718 $elements[] = $this->auto_field($field, array(
1719 'type' => 'e2pdf-html',
1720 'block' => true,
1721 'float' => true,
1722 'properties' => array(
1723 'top' => '20',
1724 'left' => '20',
1725 'right' => '20',
1726 'width' => ($field['time_type'] == 'twelve' ? $width / 3 : $width / 2) . '%',
1727 'height' => 'auto',
1728 'value' => $field['hh_label'],
1729 )
1730 ));
1731
1732 if ($field['field_type'] == 'select') {
1733 $elements[] = $this->auto_field($field, array(
1734 'type' => 'e2pdf-select',
1735 'properties' => array(
1736 'top' => '5',
1737 'width' => '100%',
1738 'height' => 'auto',
1739 'options' => implode("\n", $hours),
1740 'value' => "{" . $field['element_id'] . "-hours" . "}",
1741 )
1742 ));
1743 } else {
1744 $elements[] = $this->auto_field($field, array(
1745 'type' => 'e2pdf-input',
1746 'properties' => array(
1747 'top' => '5',
1748 'width' => '100%',
1749 'height' => 'auto',
1750 'value' => "{" . $field['element_id'] . "-hours" . "}",
1751 )
1752 ));
1753 }
1754
1755 $elements[] = $this->auto_field($field, array(
1756 'type' => 'e2pdf-html',
1757 'block' => true,
1758 'float' => true,
1759 'properties' => array(
1760 'top' => '20',
1761 'left' => '20',
1762 'right' => '20',
1763 'width' => ($field['time_type'] == 'twelve' ? $width / 3 : $width / 2) . '%',
1764 'height' => 'auto',
1765 'value' => $field['mm_label'],
1766 )
1767 ));
1768
1769 if ($field['field_type'] == 'select') {
1770 $elements[] = $this->auto_field($field, array(
1771 'type' => 'e2pdf-select',
1772 'properties' => array(
1773 'top' => '5',
1774 'width' => '100%',
1775 'height' => 'auto',
1776 'options' => implode("\n", $minutes),
1777 'value' => "{" . $field['element_id'] . "-minutes" . "}",
1778 )
1779 ));
1780 } else {
1781 $elements[] = $this->auto_field($field, array(
1782 'type' => 'e2pdf-input',
1783 'properties' => array(
1784 'top' => '5',
1785 'width' => '100%',
1786 'height' => 'auto',
1787 'value' => "{" . $field['element_id'] . "-minutes" . "}",
1788 )
1789 ));
1790 }
1791
1792 if ($field['time_type'] == 'twelve') {
1793 $elements[] = $this->auto_field($field, array(
1794 'type' => 'e2pdf-html',
1795 'block' => true,
1796 'float' => $float,
1797 'properties' => array(
1798 'top' => '20',
1799 'left' => '20',
1800 'right' => '20',
1801 'width' => ($width / 3) . '%',
1802 'height' => 'auto',
1803 'value' => '',
1804 )
1805 ));
1806
1807 $ampm = array(
1808 'am', 'pm'
1809 );
1810
1811 $elements[] = $this->auto_field($field, array(
1812 'type' => 'e2pdf-select',
1813 'properties' => array(
1814 'top' => '5',
1815 'width' => '100%',
1816 'height' => 'auto',
1817 'options' => implode("\n", $ampm),
1818 'value' => "{" . $field['element_id'] . "-ampm" . "}",
1819 )
1820 ));
1821 }
1822 break;
1823 case 'html':
1824 if ($field['field_label']) {
1825 $elements[] = $this->auto_field($field, array(
1826 'type' => 'e2pdf-html',
1827 'block' => true,
1828 'properties' => array(
1829 'top' => '20',
1830 'left' => '20',
1831 'right' => '20',
1832 'width' => $width . '%',
1833 'height' => 'auto',
1834 'value' => $field['field_label'],
1835 )
1836 ));
1837
1838 $elements[] = $this->auto_field($field, array(
1839 'type' => 'e2pdf-html',
1840 'properties' => array(
1841 'top' => '5',
1842 'width' => '100%',
1843 'height' => 'auto',
1844 'value' => $field['variations'],
1845 )
1846 ));
1847 } else {
1848 $elements[] = $this->auto_field($field, array(
1849 'type' => 'e2pdf-html',
1850 'block' => true,
1851 'properties' => array(
1852 'top' => '20',
1853 'left' => '20',
1854 'right' => '20',
1855 'width' => $width . '%',
1856 'height' => 'auto',
1857 'value' => $field['variations'],
1858 )
1859 ));
1860 }
1861 break;
1862 case 'section':
1863 $section = '';
1864 if ($field['section_title']) {
1865 $section .= "<h2>" . $field['section_title'] . "</h2>";
1866 }
1867 if ($field['section_subtitle']) {
1868 $section .= $field['section_subtitle'];
1869 }
1870 if ($section) {
1871 $elements[] = $this->auto_field($field, array(
1872 'type' => 'e2pdf-html',
1873 'block' => true,
1874 'properties' => array(
1875 'top' => '20',
1876 'left' => '20',
1877 'right' => '20',
1878 'width' => $width . '%',
1879 'height' => 'auto',
1880 'value' => $section,
1881 )
1882 ));
1883 }
1884
1885 break;
1886 case 'text':
1887 $elements[] = $this->auto_field($field, array(
1888 'type' => 'e2pdf-html',
1889 'block' => true,
1890 'properties' => array(
1891 'top' => '20',
1892 'left' => '20',
1893 'right' => '20',
1894 'width' => $width . '%',
1895 'height' => 'auto',
1896 'value' => $field['field_label'],
1897 )
1898 ));
1899
1900 if (isset($field['input_type']) && $field['input_type'] == 'line') {
1901 $elements[] = $this->auto_field($field, array(
1902 'type' => 'e2pdf-input',
1903 'properties' => array(
1904 'top' => '5',
1905 'width' => '100%',
1906 'height' => 'auto',
1907 'value' => "{" . $field['element_id'] . "}",
1908 )
1909 ));
1910 } else {
1911 $elements[] = $this->auto_field($field, array(
1912 'type' => 'e2pdf-textarea',
1913 'properties' => array(
1914 'top' => '5',
1915 'width' => '100%',
1916 'height' => 'auto',
1917 'value' => "{" . $field['element_id'] . "}",
1918 )
1919 ));
1920 }
1921 break;
1922 case 'textarea':
1923 $elements[] = $this->auto_field($field, array(
1924 'type' => 'e2pdf-html',
1925 'block' => true,
1926 'properties' => array(
1927 'top' => '20',
1928 'left' => '20',
1929 'right' => '20',
1930 'width' => $width . '%',
1931 'height' => 'auto',
1932 'value' => $field['field_label'],
1933 )
1934 ));
1935 $elements[] = $this->auto_field($field, array(
1936 'type' => 'e2pdf-textarea',
1937 'properties' => array(
1938 'top' => '5',
1939 'width' => '100%',
1940 'height' => 'auto',
1941 'value' => "{" . $field['element_id'] . "}",
1942 )
1943 ));
1944 break;
1945 case 'select':
1946 $elements[] = $this->auto_field($field, array(
1947 'type' => 'e2pdf-html',
1948 'block' => true,
1949 'float' => true,
1950 'properties' => array(
1951 'top' => '20',
1952 'left' => '20',
1953 'right' => '20',
1954 'width' => $width . '%',
1955 'height' => 'auto',
1956 'value' => $field['field_label'],
1957 )
1958 ));
1959
1960 if ($field['value_type'] == 'radio') {
1961 foreach ($field['options'] as $opt_key => $option) {
1962 if (is_array($option)) {
1963 $elements[] = $this->auto_field($field, array(
1964 'type' => 'e2pdf-radio',
1965 'properties' => array(
1966 'top' => '5',
1967 'width' => 'auto',
1968 'height' => 'auto',
1969 'value' => "{" . $field['element_id'] . "}",
1970 'option' => $option['value'] ? $option['value'] : $option['label'],
1971 'group' => "group_" . $field['element_id']
1972 )
1973 ));
1974 $elements[] = $this->auto_field($field, array(
1975 'type' => 'e2pdf-html',
1976 'float' => true,
1977 'properties' => array(
1978 'left' => '5',
1979 'width' => '100%',
1980 'height' => 'auto',
1981 'value' => $option['label']
1982 )
1983 ));
1984 }
1985 }
1986 } else {
1987 $options_tmp = array();
1988 foreach ($field['options'] as $option) {
1989 $options_tmp[] = $option['value'] ? $option['value'] : $option['label'];
1990 }
1991 $elements[] = $this->auto_field($field, array(
1992 'type' => 'e2pdf-select',
1993 'properties' => array(
1994 'top' => '5',
1995 'width' => '100%',
1996 'height' => 'auto',
1997 'options' => implode("\n", $options_tmp),
1998 'value' => "{" . $field['element_id'] . "}",
1999 )
2000 ));
2001 }
2002 break;
2003 case 'checkbox':
2004 $elements[] = $this->auto_field($field, array(
2005 'type' => 'e2pdf-html',
2006 'block' => true,
2007 'float' => true,
2008 'properties' => array(
2009 'top' => '20',
2010 'left' => '20',
2011 'right' => '20',
2012 'width' => $width . '%',
2013 'height' => 'auto',
2014 'value' => $field['field_label'],
2015 )
2016 ));
2017
2018 if ($field['value_type'] == 'multiselect') {
2019 $options_tmp = array();
2020 foreach ($field['options'] as $opt_key => $option) {
2021 $options_tmp[] = $option['value'] ? $option['value'] : $option['label'];
2022 }
2023 $elements[] = $this->auto_field($field, array(
2024 'type' => 'e2pdf-select',
2025 'properties' => array(
2026 'top' => '5',
2027 'width' => '100%',
2028 'height' => '44',
2029 'multiline' => '1',
2030 'options' => implode("\n", $options_tmp),
2031 'value' => "{" . $field['element_id'] . "}",
2032 )
2033 ));
2034 } else {
2035 foreach ($field['options'] as $opt_key => $option) {
2036 if (is_array($option)) {
2037 $elements[] = $this->auto_field($field, array(
2038 'type' => 'e2pdf-checkbox',
2039 'properties' => array(
2040 'top' => '5',
2041 'width' => 'auto',
2042 'height' => 'auto',
2043 'value' => "{" . $field['element_id'] . "}",
2044 'option' => $option['value'] ? $option['value'] : $option['label']
2045 )
2046 ));
2047 $elements[] = $this->auto_field($field, array(
2048 'type' => 'e2pdf-html',
2049 'float' => true,
2050 'properties' => array(
2051 'left' => '5',
2052 'width' => '100%',
2053 'height' => 'auto',
2054 'value' => $option['label']
2055 )
2056 ));
2057 }
2058 }
2059 }
2060 break;
2061 case 'gdprcheckbox':
2062 $elements[] = $this->auto_field($field, array(
2063 'type' => 'e2pdf-html',
2064 'block' => true,
2065 'float' => true,
2066 'properties' => array(
2067 'top' => '20',
2068 'left' => '20',
2069 'right' => '20',
2070 'width' => $width . '%',
2071 'height' => 'auto',
2072 'value' => '',
2073 )
2074 ));
2075
2076 $elements[] = $this->auto_field($field, array(
2077 'type' => 'e2pdf-checkbox',
2078 'properties' => array(
2079 'top' => '5',
2080 'width' => 'auto',
2081 'height' => 'auto',
2082 'value' => "{" . $field['element_id'] . "}",
2083 'option' => 'true'
2084 )
2085 ));
2086 $elements[] = $this->auto_field($field, array(
2087 'type' => 'e2pdf-html',
2088 'float' => true,
2089 'properties' => array(
2090 'left' => '5',
2091 'width' => '100%',
2092 'height' => 'auto',
2093 'value' => $field['gdpr_description']
2094 )
2095 ));
2096 break;
2097 default:
2098 break;
2099 }
2100 }
2101 }
2102
2103 $response['page'] = array(
2104 'bottom' => '20',
2105 'top' => '20',
2106 'left' => '20',
2107 'right' => '20'
2108 );
2109
2110 $response['elements'] = $elements;
2111 return $response;
2112 }
2113
2114 public function auto_field($field = false, $element = array()) {
2115
2116 if (!$field) {
2117 return false;
2118 }
2119
2120 if (!isset($element['block'])) {
2121 $element['block'] = false;
2122 }
2123
2124 if (!isset($element['float'])) {
2125 $element['float'] = false;
2126 }
2127
2128 return $element;
2129 }
2130
2131 /**
2132 * Load actions for this extension
2133 */
2134 public function load_actions() {
2135 add_action('forminator_custom_form_submit_before_set_fields', array($this, 'action_forminator_custom_form_submit_before_set_fields'), 30, 3);
2136 add_action('forminator_custom_form_mail_admin_message', array($this, 'action_forminator_mail_message'), 30, 5);
2137 add_action('forminator_custom_form_mail_user_message', array($this, 'action_forminator_mail_message'), 30, 5);
2138 add_action('forminator_custom_form_mail_before_send_mail', array($this, 'action_forminator_custom_form_mail_before_send_mail'), 30, 4);
2139 add_action('forminator_custom_form_mail_after_send_mail', array($this, 'action_forminator_custom_form_mail_after_send_mail'), 30, 3);
2140 }
2141
2142 /**
2143 * Load filters for this extension
2144 */
2145 public function load_filters() {
2146 add_filter('forminator_custom_form_submit_response', array($this, 'filter_forminator_custom_form_submit_response'), 30, 2);
2147 add_filter('forminator_custom_form_ajax_submit_response', array($this, 'filter_forminator_custom_form_submit_response'), 30, 2);
2148 }
2149
2150 public function action_forminator_custom_form_submit_before_set_fields($entry, $form_id, $field_data_array) {
2151 if (class_exists('Forminator_API')) {
2152 $form = Forminator_API::get_form($form_id);
2153 if (!is_wp_error($form)) {
2154 if ($form->is_prevent_store()) {
2155 $this->set('field_data_array', $field_data_array);
2156 $this->set('dataset', 'is_prevent_store');
2157 } elseif ($entry && is_object($entry) && property_exists($entry, 'entry_id') && isset($entry->entry_id)) {
2158 $this->set('dataset', $entry->entry_id);
2159 }
2160 }
2161 }
2162 }
2163
2164 public function action_forminator_custom_form_mail_before_send_mail($mail, $custom_form, $data, $entry) {
2165 add_filter('wp_mail', array($this, 'filter_wp_mail'), 30, 1);
2166 }
2167
2168 public function action_forminator_custom_form_mail_after_send_mail($mail, $custom_form, $data) {
2169 remove_filter('wp_mail', array($this, 'filter_wp_mail'), 30);
2170 $files = $this->helper->get('forminator_attachments');
2171 if (is_array($files) && !empty($files)) {
2172 foreach ($files as $key => $file) {
2173 $this->helper->delete_dir(dirname($file) . '/');
2174 }
2175 $this->helper->deset('forminator_attachments');
2176 }
2177 }
2178
2179 public function action_forminator_mail_message($message, $custom_form, $data, $entry, $mail) {
2180 if (isset($message) && false !== strpos($message, '[')) {
2181 $shortcode_tags = array(
2182 'e2pdf-download',
2183 'e2pdf-save',
2184 'e2pdf-attachment',
2185 'e2pdf-adobesign'
2186 );
2187
2188 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $message, $matches);
2189
2190 $tagnames = array_intersect($shortcode_tags, $matches[1]);
2191
2192 if (!empty($tagnames)) {
2193 $pattern = get_shortcode_regex($tagnames);
2194
2195 preg_match_all("/$pattern/", $message, $shortcodes);
2196 foreach ($shortcodes[0] as $key => $shortcode_value) {
2197 $shortcode = array();
2198 $shortcode[1] = $shortcodes[1][$key];
2199 $shortcode[2] = $shortcodes[2][$key];
2200 $shortcode[3] = $shortcodes[3][$key];
2201 $shortcode[4] = $shortcodes[4][$key];
2202 $shortcode[5] = $shortcodes[5][$key];
2203 $shortcode[6] = $shortcodes[6][$key];
2204
2205 $atts = shortcode_parse_atts($shortcode[3]);
2206
2207 if (!array_key_exists('dataset', $atts) && array_key_exists('id', $atts)) {
2208 $template = new Model_E2pdf_Template();
2209 $template->load($atts['id']);
2210 if ($template->get('extension') === 'forminator') {
2211 $entry_id = $this->get('dataset');
2212 if ($entry_id) {
2213 if (($shortcode[2] === 'e2pdf-download' || $shortcode['2'] === 'e2pdf-view') && $entry_id == 'is_prevent_store') {
2214 //data is empty to fill pdf
2215 } else {
2216 if ($entry_id == 'is_prevent_store') {
2217 add_filter('e2pdf_model_shortcode_extension_options', array($this, 'filter_e2pdf_model_shortcode_extension_options'), 30, 2);
2218 }
2219 $atts['dataset'] = $entry_id;
2220 $shortcode[3] .= " dataset=\"{$entry_id}\"";
2221 }
2222 }
2223 }
2224 }
2225
2226 if ($shortcode[2] === 'e2pdf-save' || $shortcode[2] === 'e2pdf-attachment' || $shortcode[2] === 'e2pdf-adobesign') {
2227 $shortcode[3] .= " apply=\"true\"";
2228 }
2229
2230 $shortcode[3] .= " filter=\"true\"";
2231
2232 if ($shortcode[2] === 'e2pdf-attachment') {
2233 $file = do_shortcode_tag($shortcode);
2234 if ($file) {
2235 $this->helper->add('forminator_attachments', $file);
2236 }
2237 $message = str_replace($shortcode_value, '', $message);
2238 } else {
2239 $message = str_replace($shortcode_value, do_shortcode_tag($shortcode), $message);
2240 }
2241 remove_filter('e2pdf_model_shortcode_extension_options', array($this, 'filter_e2pdf_model_shortcode_extension_options'), 30);
2242 }
2243 }
2244 }
2245
2246 return $message;
2247 }
2248
2249 public function filter_e2pdf_model_shortcode_extension_options($options = array(), $template) {
2250 if ($this->get('dataset') && $this->get('dataset') == 'is_prevent_store') {
2251 $options['field_data_array'] = $this->get('field_data_array');
2252 }
2253 return $options;
2254 }
2255
2256 public function filter_forminator_custom_form_submit_response($response, $form_id) {
2257
2258 if (isset($response['message']) && false !== strpos($response['message'], '[') && isset($response['success']) && $response['success']) {
2259 $shortcode_tags = array(
2260 'e2pdf-download',
2261 'e2pdf-save',
2262 'e2pdf-view',
2263 'e2pdf-adobesign'
2264 );
2265
2266 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $response['message'], $matches);
2267
2268 $tagnames = array_intersect($shortcode_tags, $matches[1]);
2269
2270 if (!empty($tagnames)) {
2271 $pattern = get_shortcode_regex($tagnames);
2272
2273 preg_match_all("/$pattern/", $response['message'], $shortcodes);
2274 foreach ($shortcodes[0] as $key => $shortcode_value) {
2275 $shortcode = array();
2276 $shortcode[1] = $shortcodes[1][$key];
2277 $shortcode[2] = $shortcodes[2][$key];
2278 $shortcode[3] = $shortcodes[3][$key];
2279 $shortcode[4] = $shortcodes[4][$key];
2280 $shortcode[5] = $shortcodes[5][$key];
2281 $shortcode[6] = $shortcodes[6][$key];
2282
2283 $atts = shortcode_parse_atts($shortcode[3]);
2284
2285 if (!array_key_exists('dataset', $atts) && array_key_exists('id', $atts)) {
2286 $template = new Model_E2pdf_Template();
2287 $template->load($atts['id']);
2288 if ($template->get('extension') === 'forminator') {
2289 $entry_id = $this->get('dataset');
2290 if ($entry_id) {
2291 if (($shortcode[2] === 'e2pdf-download' || $shortcode['2'] === 'e2pdf-view') && $entry_id == 'is_prevent_store') {
2292 //data is empty to fill pdf
2293 } else {
2294 if ($entry_id == 'is_prevent_store') {
2295 add_filter('e2pdf_model_shortcode_extension_options', array($this, 'filter_e2pdf_model_shortcode_extension_options'), 30, 2);
2296 }
2297 $atts['dataset'] = $entry_id;
2298 $shortcode[3] .= " dataset=\"{$entry_id}\"";
2299 }
2300 }
2301 }
2302 }
2303
2304 if ($shortcode[2] === 'e2pdf-save' || $shortcode[2] === 'e2pdf-adobesign') {
2305 $shortcode[3] .= " apply=\"true\"";
2306 }
2307
2308 $shortcode[3] .= " filter=\"true\"";
2309 $response['message'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $response['message']);
2310 remove_filter('e2pdf_model_shortcode_extension_options', array($this, 'filter_e2pdf_model_shortcode_extension_options'), 30);
2311 }
2312 }
2313 }
2314 $this->set('dataset', false);
2315 return $response;
2316 }
2317
2318 public function filter_wp_mail($args = array()) {
2319 $files = $this->helper->get('forminator_attachments');
2320 if (is_array($files) && !empty($files)) {
2321 foreach ($files as $file) {
2322 $args['attachments'][] = $file;
2323 }
2324 }
2325 $wp_mail = array(
2326 'to' => $args['to'],
2327 'subject' => $args['subject'],
2328 'message' => $args['message'],
2329 'headers' => $args['headers'],
2330 'attachments' => $args['attachments'],
2331 );
2332
2333 return $wp_mail;
2334 }
2335
2336 /**
2337 * Get styles for generating Map Field function
2338 *
2339 * @return array - List of css files to load
2340 */
2341 public function styles() {
2342 $styles = array();
2343 if (function_exists(forminator_plugin_url)) {
2344 if (defined("FORMINATOR_VERSION")) {
2345 $version = FORMINATOR_VERSION;
2346 } else {
2347 $version = '0';
2348 }
2349 $styles = array(
2350 forminator_plugin_url() . 'assets/css/front.min.css?v=' . $version,
2351 plugins_url('css/extension/forminator.css?v=' . time(), $this->helper->get('plugin_file_path'))
2352 );
2353 }
2354 return $styles;
2355 }
2356
2357 }
2358