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

1,814 lines 82.0 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
20 function __construct() {
21 parent::__construct();
22 }
23
24 /**
25 * Get info about extension
26 *
27 * @return array() - Extension key and name
28 */
29 public function info() {
30 return array(
31 'forminator' => __('Forminator', 'e2pdf')
32 );
33 }
34
35 public function active() {
36
37 if (!function_exists('is_plugin_active')) {
38 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
39 }
40
41 if (is_plugin_active('forminator/forminator.php')) {
42 return true;
43 }
44 return false;
45 }
46
47 /**
48 * Check if export item function available
49 *
50 * @return bool - Item export available/not available
51 */
52 public function export() {
53 return false;
54 }
55
56 /**
57 * Set option
58 *
59 * @param string $key - Key of option
60 * @param string $value - Value of option
61 *
62 * @return bool - Status of setting option
63 */
64 public function set($key, $value) {
65 if (!isset($this->options)) {
66 $this->options = new stdClass();
67 }
68
69 $this->options->$key = $value;
70 return true;
71 }
72
73 /**
74 * Get option by key
75 *
76 * @param string $key - Key to get assigned option value
77 *
78 * @return mixed
79 */
80 public function get($key) {
81 if (isset($this->options->$key)) {
82 $value = $this->options->$key;
83 return $value;
84 } else {
85 return false;
86 }
87 }
88
89 /**
90 * Get items to work with
91 *
92 * @return array() - List of available items
93 */
94 public function get_items() {
95 $content = array();
96 if (class_exists("Forminator_API")) {
97 $forms = Forminator_API::get_forms();
98 foreach ($forms as $key => $value) {
99 $content[] = array(
100 'key' => (string) $value->id,
101 'value' => $value->name
102 );
103 }
104 }
105 return $content;
106 }
107
108 /**
109 * Get entries for export
110 *
111 * @param int $item - Form ID
112 * @param string $name - Entries names
113 *
114 * @return array() - Entries list
115 */
116 public function get_datasets($item = false, $name = false) {
117
118 $datasets = array();
119
120 if (class_exists("Forminator_API") && $item) {
121 $entries = Forminator_API::get_entries($item);
122 foreach ($entries as $key => $dataset) {
123 $this->set('item', $item);
124 $this->set('dataset', $dataset->entry_id);
125
126 $dataset_title = $this->render($name);
127 if (!$dataset_title) {
128 $dataset_title = $dataset->entry_id;
129 }
130 $datasets[] = array(
131 'key' => $dataset->entry_id,
132 'value' => $dataset_title
133 );
134 }
135 }
136
137 return $datasets;
138 }
139
140 /**
141 * Get dataset
142 *
143 * @param int $dataset - Dataset ID
144 *
145 * @return object - Dataset
146 */
147 public function get_dataset($dataset = false) {
148 $dataset = (int) $dataset;
149
150 if (!$dataset) {
151 return false;
152 }
153
154 $data = new stdClass();
155 $data->url = false;
156
157 return $data;
158 }
159
160 /**
161 * Get item
162 *
163 * @param string $item - Item ID
164 *
165 * @return object - Item
166 */
167 public function get_item($item = false) {
168
169 $form = new stdClass();
170
171 $forminator_form = false;
172 if (class_exists("Forminator_API")) {
173 $forminator_form = Forminator_API::get_form($item);
174 }
175
176 if (!is_wp_error($forminator_form)) {
177 $form->url = $this->helper->get_url(array('page' => 'forminator-cform-wizard', 'id' => $forminator_form->id));
178 $form->name = $forminator_form->name;
179 } else {
180 $form->url = 'javascript:void(0);';
181 $form->name = '';
182 }
183 return $form;
184 }
185
186 /**
187 * Render value according to content
188 *
189 * @param string $value - Content
190 * @param string $type - Type of rendering value
191 * @param string $field - Field
192 *
193 * @return string - Fully rendered value
194 */
195 public function render($value, $type = false, $field = array()) {
196
197 $value = $this->render_shortcodes($value, $type, $field);
198 $value = $this->strip_shortcodes($value);
199
200 if ($type === 'value' && isset($field['type']) && $field['type'] === 'e2pdf-checkbox' && isset($field['properties']['option'])) {
201 $option = $this->render($field['properties']['option']);
202 $options = explode(', ', $value);
203 $option_options = explode(', ', $option);
204 if (is_array($options) && is_array($option_options) && !array_diff($option_options, $options)) {
205 return $option;
206 } else {
207 return "";
208 }
209 }
210
211 if ($type === 'value') {
212 $value = str_replace("&#91;", "[", $value);
213 }
214
215 return $value;
216 }
217
218 /**
219 * Render shortcodes which available in this extension
220 *
221 * @param string $type - Type of rendering value
222 * @param string $value - Content
223 *
224 * @return string - Value with rendered shortcodes
225 */
226 public function render_shortcodes($value, $type = false, $field = array()) {
227
228 $dataset = $this->get('dataset');
229 $item = $this->get('item');
230
231 if ($this->verify() && function_exists("forminator_replace_form_data") && class_exists("Forminator_API")) {
232
233 $form = Forminator_API::get_form($item);
234 $entry = Forminator_API::get_entry($item, $dataset);
235 $data = array();
236 foreach ($entry->meta_data as $key => $meta) {
237 if (is_array($meta['value'])) {
238 if (array_unique(array_map("is_int", array_keys($meta['value']))) === array(true)) {
239 $data[$key] = $meta['value'];
240 } else {
241 if (isset($meta['value']['file']['file_url'])) {
242 $data[$key] = $meta['value']['file']['file_url'];
243 } else {
244 foreach ($meta['value'] as $sub_key => $sub_meta) {
245 $data[$key . "-" . $sub_key] = $sub_meta;
246 }
247 }
248 }
249 } else {
250 $data[$key] = $meta['value'];
251 }
252 }
253
254 if (false !== strpos($value, '[')) {
255
256 $shortcode_tags = array(
257 'e2pdf-format-number',
258 'e2pdf-format-date',
259 'e2pdf-format-output',
260 );
261 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches);
262 $tagnames = array_intersect($shortcode_tags, $matches[1]);
263
264 if (!empty($tagnames)) {
265
266 $pattern = get_shortcode_regex($tagnames);
267 preg_match_all("/$pattern/", $value, $shortcodes);
268 foreach ($shortcodes[0] as $key => $shortcode_value) {
269 $shortcode = array();
270 $shortcode[1] = $shortcodes[1][$key];
271 $shortcode[2] = $shortcodes[2][$key];
272 $shortcode[3] = $shortcodes[3][$key];
273 $shortcode[4] = $shortcodes[4][$key];
274 $shortcode[5] = $shortcodes[5][$key];
275 $shortcode[6] = $shortcodes[6][$key];
276
277 if (isset($shortcode['5'])) {
278 $shortcode['5'] = forminator_replace_form_data($shortcode['5'], $data, $form, $entry);
279 $shortcode['5'] = forminator_replace_variables($shortcode['5'], $item);
280 $sub_value = $this->strip_shortcodes($shortcode['5']);
281 $value = str_replace($shortcode_value, "[" . $shortcode['2'] . $shortcode['3'] . "]" . $sub_value . "[/" . $shortcode['2'] . "]", $value);
282 }
283 }
284 }
285 }
286
287 $value = do_shortcode($value);
288 $value = forminator_replace_form_data($value, $data, $form, $entry);
289 $value = forminator_replace_variables($value, $item);
290
291 if (isset($field['type']) && ($field['type'] === 'e2pdf-image' || $field['type'] === 'e2pdf-signature')) {
292 $esig = isset($field['properties']['esig']) && $field['properties']['esig'] ? true : false;
293 if ($esig) {
294 //process e-signature
295 $value = "";
296 } else {
297
298 if (!$this->helper->load('image')->get_image($value)) {
299 $value = $this->strip_shortcodes($value);
300 if (
301 $value &&
302 trim($value) != "" &&
303 extension_loaded('gd') &&
304 function_exists('imagettftext')
305 ) {
306 if (isset($field['properties']['text_color']) && $field['properties']['text_color']) {
307 $penColour = $this->helper->load('convert')->to_hex_color($field['properties']['text_color']);
308 } else {
309 $penColour = array(0x14, 0x53, 0x94);
310 }
311
312 $default_options = array(
313 'imageSize' => array(isset($field['width']) ? $field['width'] : '400', isset($field['height']) ? $field['height'] : '150'),
314 'bgColour' => 'transparent',
315 'penColour' => $penColour
316 );
317
318 $options = array();
319 $options = array_merge($default_options, $options);
320
321 $model_e2pdf_font = new Model_E2pdf_Font();
322
323 $font = false;
324 if (isset($field['properties']['text_font']) && $field['properties']['text_font']) {
325 $font = $model_e2pdf_font->get_font_path($field['properties']['text_font']);
326 }
327
328 if (!$font) {
329 $font = $model_e2pdf_font->get_font_path('Noto Sans');
330 }
331
332 $size = 150;
333 if (isset($field['properties']['text_font_size']) && $field['properties']['text_font_size']) {
334 $size = $field['properties']['text_font_size'];
335 }
336
337 $model_e2pdf_signature = new Model_E2pdf_Signature();
338 $value = $model_e2pdf_signature->ttf_signature($value, $size, $font, $options);
339 } else {
340 $value = "";
341 }
342 }
343 }
344 } else {
345 $value = str_replace("[", '&#91;', $value);
346 }
347 }
348
349 return $value;
350 }
351
352 /**
353 * Strip unused shortcodes
354 *
355 * @param string $value - Content
356 *
357 * @return string - Value with removed unused shortcodes
358 */
359 public function strip_shortcodes($value) {
360 $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', "", $value);
361 $value = preg_replace('~(?:{/?)[^/}]+/?}~s', "", $value);
362 return $value;
363 }
364
365 public function verify() {
366 $item = $this->get('item');
367 $dataset = $this->get('dataset');
368
369 if ($item && $dataset && class_exists("Forminator_API")) {
370 $entry = Forminator_API::get_entry($item, $dataset);
371 if ($entry) {
372 return true;
373 }
374 }
375 return false;
376 }
377
378 public function visual_mapper() {
379
380 $item = $this->get('item');
381
382 if ($item && function_exists("forminator_form_preview") && class_exists("Forminator_API")) {
383
384 ob_start();
385 forminator_form_preview($item, true, array());
386 $source = ob_get_clean();
387
388 $form = Forminator_API::get_form($item);
389
390 if (is_wp_error($form)) {
391 return __('Form could not be found', 'e2pdf');
392 }
393
394 libxml_use_internal_errors(true);
395 $dom = new DOMDocument;
396 $html = $dom->loadHTML($source);
397 libxml_clear_errors();
398
399 if (!$html) {
400 return __('Form could not be parsed due incorrect HTML', 'e2pdf');
401 } else {
402
403 $xpath = new DomXPath($dom);
404
405 $remove_by_class = array(
406 'forminator-pagination-submit'
407 );
408 foreach ($remove_by_class as $key => $class) {
409 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
410 foreach ($elements as $element) {
411 $element->parentNode->removeChild($element);
412 }
413 }
414
415 $inputs = $xpath->query("//*[contains(@class, 'forminator-input')]");
416 foreach ($inputs as $element) {
417 if (!$element->attributes->getNamedItem("type")->nodeValue) {
418 $element->setAttribute("type", "text");
419 }
420 }
421
422 //remove pagination
423 $pagination = $xpath->query("//*[contains(@class, 'forminator-pagination')]");
424 foreach ($pagination as $element) {
425 $element->attributes->getNamedItem("style")->nodeValue = "";
426 }
427
428 //remove buttons
429 $remove_rows = $xpath->query("//*[contains(@class, 'forminator-row')][.//button[contains(@class, 'forminator-button') and not(contains(@class, 'forminator-upload-button'))]]");
430 foreach ($remove_rows as $element) {
431 $element->parentNode->removeChild($element);
432 }
433
434 //replace name on fileuploads
435 $fileuploads = $xpath->query("//*[contains(@class, 'forminator-upload')]");
436 foreach ($fileuploads as $element) {
437 $file = $xpath->query(".//input[contains(@class, 'forminator-input-file')]", $element)->item(0);
438 $button = $xpath->query(".//button[contains(@class, 'forminator-upload-button')]", $element)->item(0);
439 if ($file && $button) {
440 $button->attributes->getNamedItem("type")->nodeValue = "upload";
441 $button->setAttribute("name", "{" . $file->attributes->getNamedItem("name")->nodeValue . "}");
442 }
443 }
444
445 //replace names on inputs
446 $inputs = $xpath->query("//input");
447 foreach ($inputs as $element) {
448 $type = $element->attributes->getNamedItem("type")->nodeValue;
449 if ($type == 'checkbox') {
450 $element->attributes->getNamedItem("name")->nodeValue = str_replace("[]", "", $element->attributes->getNamedItem("name")->nodeValue);
451 }
452
453 $element->attributes->getNamedItem("name")->nodeValue = "{" . $element->attributes->getNamedItem("name")->nodeValue . "}";
454 if (strpos($element->attributes->getNamedItem("class")->nodeValue, 'forminator-checkbox--input') !== false) {
455 $element->attributes->getNamedItem("class")->nodeValue = $element->attributes->getNamedItem("class")->nodeValue . " forminator-checkbox--design";
456 }
457 if (strpos($element->attributes->getNamedItem("class")->nodeValue, 'forminator-radio--input') !== false) {
458 $element->attributes->getNamedItem("class")->nodeValue = $element->attributes->getNamedItem("class")->nodeValue . " forminator-radio--design";
459 }
460 }
461
462 //replace names on textareas
463 $textareas = $xpath->query("//textarea");
464 foreach ($textareas as $element) {
465 $element->attributes->getNamedItem("name")->nodeValue = "{" . $element->attributes->getNamedItem("name")->nodeValue . "}";
466 }
467
468 //replace names on selects
469 $selects = $xpath->query("//select");
470 foreach ($selects as $element) {
471 $element->attributes->getNamedItem("name")->nodeValue = "{" . $element->attributes->getNamedItem("name")->nodeValue . "}";
472 }
473
474 //multiselects
475 $multiselect = $xpath->query("//ul[contains(@class, 'forminator-multiselect')]");
476 foreach ($multiselect as $element) {
477 $name = '';
478 $options = array();
479 $inputs = $xpath->query(".//*[contains(@class, 'forminator-multiselect--item')]", $element);
480
481 foreach ($inputs as $sub_element) {
482 $input = $xpath->query(".//input", $sub_element)->item(0);
483 $label = $xpath->query(".//label", $sub_element)->item(0);
484
485 if ($input && $label) {
486 $options[] = array(
487 'value' => $input->attributes->getNamedItem("value")->nodeValue,
488 'label' => $label->childNodes->item(0)->nodeValue
489 );
490
491 $name = $input->attributes->getNamedItem("name")->nodeValue;
492 }
493
494 $sub_element->parentNode->removeChild($sub_element);
495 }
496
497 $li = $dom->createElement('li');
498 $field_atts = array(
499 'class' => 'forminator-multiselect--item',
500 );
501 foreach ($field_atts as $key => $value) {
502 $attr = $dom->createAttribute($key);
503 $attr->value = $value;
504 $li->appendChild($attr);
505 }
506 $element->appendChild($li);
507
508
509 $field = $dom->createElement('select');
510 $field_atts = array(
511 'multiple' => 'multiple',
512 'name' => $name,
513 );
514 foreach ($field_atts as $key => $value) {
515 $attr = $dom->createAttribute($key);
516 $attr->value = $value;
517 $field->appendChild($attr);
518 }
519
520 $li->appendChild($field);
521
522 foreach ($options as $option) {
523 $option_field = $dom->createElement('option');
524 $field_atts = array(
525 'value' => $option['value'],
526 );
527 foreach ($field_atts as $key => $value) {
528 $attr = $dom->createAttribute($key);
529 $attr->value = $value;
530 $option_field->appendChild($attr);
531 }
532
533 $label = $dom->createTextNode($option['label']);
534 $option_field->appendChild($label);
535 $field->appendChild($option_field);
536 }
537 }
538
539
540
541 return $dom->saveHTML();
542 }
543 }
544 return false;
545 }
546
547 /**
548 * Auto Generate of Template for this extension
549 *
550 * @return array - List of elements
551 */
552 public function auto() {
553
554 $item = $this->get('item');
555
556 $response = array();
557 $elements = array();
558 $fields = array();
559 $form = false;
560
561 if (class_exists("Forminator_API")) {
562 $forminator_form = Forminator_API::get_form($item);
563 if (!is_wp_error($forminator_form)) {
564 $form = $forminator_form;
565 $fields = $form->fields;
566 }
567 }
568
569 if ($form && $fields) {
570
571 foreach ($fields as $field_obj) {
572 $field = $field_obj->raw;
573 $float = true;
574 $width = 100 / (12 / $field['cols']);
575
576 switch ($field['type']) {
577 case 'name':
578 case 'email':
579 case 'phone':
580 case 'url':
581 case 'upload':
582 case 'number':
583 case 'date':
584
585 //multiple name field
586 if ($field['type'] == 'name' && isset($field['multiple_name']) && $field['multiple_name']) {
587
588 if ($field['prefix']) {
589 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
590 'top' => '20',
591 'left' => '20',
592 'right' => '20',
593 'block' => true,
594 'float' => true,
595 'width' => $field['fname'] ? $width / 2 . '%' : $width . '%',
596 'properties' => array(
597 'value' => $field['prefix_label'],
598 )
599 ));
600
601 $options_tmp = array();
602 if (function_exists('forminator_get_name_prefixes')) {
603 $options = forminator_get_name_prefixes();
604 foreach ($options as $key => $option) {
605 $options_tmp[] = $key;
606 }
607 }
608
609 $elements[] = $this->auto_field($field, 'e2pdf-select', array(
610 'properties' => array(
611 'options' => implode("\n", $options_tmp),
612 'value' => "{" . $field['element_id'] . "-prefix" . "}",
613 )
614 ));
615 }
616
617 if ($field['fname']) {
618 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
619 'top' => '20',
620 'left' => '20',
621 'right' => '20',
622 'block' => true,
623 'float' => true,
624 'width' => $field['prefix'] ? ($width / 2) . '%' : $width . '%',
625 'properties' => array(
626 'value' => $field['fname_label'],
627 )
628 ));
629
630
631 $elements[] = $this->auto_field($field, 'e2pdf-input', array(
632 'properties' => array(
633 'value' => "{" . $field['element_id'] . "-first-name" . "}",
634 )
635 ));
636 }
637
638 $block = false;
639 if (!$field['prefix'] && !$field['fname']) {
640 $block = true;
641 }
642
643 if ($field['mname']) {
644 $settings = array(
645 'block' => array(
646 'width' => $width,
647 'top' => '0',
648 'left' => '0',
649 'right' => '0',
650 'add_width' => '0',
651 'margin_left' => '0'
652 ),
653 'field' => array(
654 'width' => '100%',
655 'top' => '0',
656 'left' => '0',
657 'right' => '0',
658 'add_width' => '0',
659 'margin_left' => '0'
660 )
661 );
662
663 if ($block) {
664 $settings['block']['top'] = '20';
665 $settings['block']['left'] = '20';
666 $settings['block']['right'] = '20';
667 $settings['block']['width'] = ($field['lname'] ? ($width / 2) : $width) . '%';
668 } else {
669 $settings['block']['top'] = '40';
670 $settings['field']['top'] = '60';
671 if ($field['prefix'] && $field['fname']) {
672 $settings['block']['left'] = '-100%';
673 $settings['block']['margin_left'] = '-40';
674 if (!$field['lname']) {
675 $settings['block']['add_width'] = '40';
676 }
677 }
678
679 if ($field['prefix'] && $field['fname'] && !$field['lname']) {
680 $settings['block']['width'] = '200%';
681 } elseif ($field['lname'] && (!$field['prefix'] || !$field['fname'])) {
682 $settings['block']['width'] = '45%';
683 } else {
684 $settings['block']['width'] = '100%';
685 }
686
687 $settings['field']['width'] = $settings['block']['width'];
688 $settings['field']['left'] = $settings['block']['left'];
689 $settings['field']['right'] = $settings['block']['right'];
690 $settings['field']['add_width'] = $settings['block']['add_width'];
691 $settings['field']['margin_left'] = $settings['block']['margin_left'];
692 }
693
694 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
695 'top' => $settings['block']['top'],
696 'left' => $settings['block']['left'],
697 'right' => $settings['block']['right'],
698 'add_width' => $settings['block']['add_width'],
699 'margin_left' => $settings['block']['margin_left'],
700 'block' => $block,
701 'float' => true,
702 'width' => $settings['block']['width'],
703 'properties' => array(
704 'value' => $field['mname_label'],
705 )
706 ));
707
708 $elements[] = $this->auto_field($field, 'e2pdf-input', array(
709 'top' => $settings['field']['top'],
710 'left' => $settings['field']['left'],
711 'add_width' => $settings['field']['add_width'],
712 'margin_left' => $settings['field']['margin_left'],
713 'width' => $settings['field']['width'],
714 'properties' => array(
715 'value' => "{" . $field['element_id'] . "-middle-name" . "}",
716 )
717 ));
718 }
719
720 if ($field['lname']) {
721
722 $settings = array(
723 'block' => array(
724 'width' => $width,
725 'top' => '0',
726 'left' => '0',
727 'right' => '0',
728 'add_width' => '0',
729 'margin_left' => '0'
730 ),
731 'field' => array(
732 'width' => '100%',
733 'top' => '0',
734 'left' => '0',
735 'right' => '0',
736 'add_width' => '0',
737 'margin_left' => '0'
738 )
739 );
740
741 if ($block) {
742 $settings['block']['top'] = '20';
743 $settings['block']['left'] = '20';
744 $settings['block']['right'] = '20';
745 $settings['block']['width'] = ($field['mname'] ? ($width / 2) : $width) . '%';
746 } else {
747 $settings['block']['top'] = '40';
748 $settings['field']['top'] = '60';
749
750
751 if ($field['prefix'] && $field['fname'] && !$field['mname']) {
752 $settings['block']['width'] = '200%';
753 $settings['block']['add_width'] = '40';
754 $settings['block']['margin_left'] = '-40';
755 $settings['block']['left'] = '-100%';
756 } elseif ($field['mname'] && (!$field['prefix'] || !$field['fname'])) {
757 $settings['block']['width'] = '45%';
758 $settings['block']['left'] = '55%';
759 } else {
760 $settings['block']['width'] = '100%';
761 }
762
763 $settings['field']['width'] = $settings['block']['width'];
764 $settings['field']['left'] = $settings['block']['left'];
765 $settings['field']['right'] = $settings['block']['right'];
766 $settings['field']['add_width'] = $settings['block']['add_width'];
767 $settings['field']['margin_left'] = $settings['block']['margin_left'];
768 }
769
770 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
771 'top' => $settings['block']['top'],
772 'left' => $settings['block']['left'],
773 'right' => $settings['block']['right'],
774 'add_width' => $settings['block']['add_width'],
775 'margin_left' => $settings['block']['margin_left'],
776 'block' => $block,
777 'float' => true,
778 'width' => $settings['block']['width'],
779 'properties' => array(
780 'value' => $field['lname_label'],
781 )
782 ));
783
784 $elements[] = $this->auto_field($field, 'e2pdf-input', array(
785 'top' => $settings['field']['top'],
786 'left' => $settings['field']['left'],
787 'add_width' => $settings['field']['add_width'],
788 'margin_left' => $settings['field']['margin_left'],
789 'width' => $settings['field']['width'],
790 'properties' => array(
791 'value' => "{" . $field['element_id'] . "-last-name" . "}",
792 )
793 ));
794 }
795 } elseif ($field['type'] == 'date' && $field['field_type'] == 'select') {
796
797 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
798 'top' => '20',
799 'left' => '20',
800 'right' => '20',
801 'block' => true,
802 'float' => $float,
803 'width' => $width . "%",
804 'properties' => array(
805 'value' => $field['field_label'],
806 )
807 ));
808
809 $days = array();
810 $months = array();
811 $years = array();
812 if (class_exists('Forminator_Date')) {
813 $forminator_date = new Forminator_Date();
814 $options = $forminator_date->get_day();
815 foreach ($options as $option) {
816 $days[] = $option['value'];
817 }
818
819 $options = $forminator_date->get_months();
820 foreach ($options as $option) {
821 $months[] = $option['value'];
822 }
823
824 $options = $forminator_date->get_years($field['min_year'], $field['max_year']);
825 foreach ($options as $option) {
826 $years[] = $option['value'];
827 }
828 }
829
830 $elements[] = $this->auto_field($field, 'e2pdf-select', array(
831 'left' => '0',
832 'width' => '30%',
833 'properties' => array(
834 'options' => implode("\n", $days),
835 'value' => "{" . $field['element_id'] . "-month" . "}",
836 )
837 ));
838
839 $elements[] = $this->auto_field($field, 'e2pdf-select', array(
840 'left' => '35%',
841 'width' => '30%',
842 'properties' => array(
843 'options' => implode("\n", $months),
844 'value' => "{" . $field['element_id'] . "-day" . "}",
845 )
846 ));
847
848 $elements[] = $this->auto_field($field, 'e2pdf-select', array(
849 'left' => '70%',
850 'width' => '30%',
851 'properties' => array(
852 'options' => implode("\n", $years),
853 'value' => "{" . $field['element_id'] . "-year" . "}",
854 )
855 ));
856 } elseif ($field['type'] == 'date' && $field['field_type'] == 'input') {
857
858 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
859 'top' => '20',
860 'left' => '20',
861 'right' => '20',
862 'block' => true,
863 'float' => $float,
864 'width' => $width . "%",
865 'properties' => array(
866 'value' => $field['field_label'],
867 )
868 ));
869
870 $elements[] = $this->auto_field($field, 'e2pdf-input', array(
871 'left' => '0',
872 'width' => '30%',
873 'properties' => array(
874 'value' => "{" . $field['element_id'] . "-month" . "}",
875 )
876 ));
877
878 $elements[] = $this->auto_field($field, 'e2pdf-input', array(
879 'left' => '35%',
880 'width' => '30%',
881 'properties' => array(
882 'value' => "{" . $field['element_id'] . "-day" . "}",
883 )
884 ));
885
886 $elements[] = $this->auto_field($field, 'e2pdf-input', array(
887 'left' => '70%',
888 'width' => '30%',
889 'properties' => array(
890 'value' => "{" . $field['element_id'] . "-year" . "}",
891 )
892 ));
893 } else {
894
895 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
896 'top' => '20',
897 'left' => '20',
898 'right' => '20',
899 'block' => true,
900 'float' => $float,
901 'width' => $width . "%",
902 'properties' => array(
903 'value' => $field['field_label'],
904 )
905 ));
906
907 $elements[] = $this->auto_field($field, 'e2pdf-input', array(
908 'properties' => array(
909 'value' => "{" . $field['element_id'] . "}",
910 )
911 ));
912 }
913 break;
914
915
916 case 'address':
917
918 $block = true;
919 $top = 0;
920
921 if ($field['street_address']) {
922 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
923 'top' => '20',
924 'left' => '20',
925 'right' => '20',
926 'block' => $block,
927 'float' => true,
928 'width' => $width . '%',
929 'properties' => array(
930 'value' => $field['street_address_label'],
931 )
932 ));
933
934
935 $elements[] = $this->auto_field($field, 'e2pdf-input', array(
936 'properties' => array(
937 'value' => "{" . $field['element_id'] . "-street_address" . "}",
938 )
939 ));
940
941 $block = false;
942 $top += 40;
943 }
944
945 if ($field['address_line']) {
946
947 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
948 'top' => $block ? '20' : $top,
949 'left' => $block ? '20' : '0',
950 'right' => $block ? '20' : '0',
951 'block' => $block,
952 'float' => true,
953 'width' => $block ? $width . '%' : '100%',
954 'properties' => array(
955 'value' => $field['address_line_label'],
956 )
957 ));
958
959 if (!$block) {
960 $top += 20;
961 }
962
963 $elements[] = $this->auto_field($field, 'e2pdf-input', array(
964 'top' => $block ? '0' : $top,
965 'width' => $block ? $width . '%' : '100%',
966 'properties' => array(
967 'value' => "{" . $field['element_id'] . "-address_line" . "}",
968 )
969 ));
970
971 $top += 40;
972 $block = false;
973 }
974
975 if ($field['address_city']) {
976
977 $settings = array(
978 'block' => array(
979 'width' => $width,
980 'top' => '0',
981 'left' => '0',
982 'right' => '0',
983 'add_width' => '0',
984 'margin_left' => '0'
985 ),
986 'field' => array(
987 'width' => '100%',
988 'top' => '0',
989 'left' => '0',
990 'right' => '0',
991 'add_width' => '0',
992 'margin_left' => '0'
993 )
994 );
995
996 if ($block) {
997 $settings['block']['top'] = '20';
998 $settings['block']['left'] = '20';
999 $settings['block']['right'] = '20';
1000 $settings['block']['width'] = ($field['address_state'] ? ($width / 2) : $width) . '%';
1001
1002 $top += 40;
1003 } else {
1004 $settings['block']['top'] = $top;
1005 $settings['field']['top'] = $top + 20;
1006
1007
1008 if ($field['address_state']) {
1009 $settings['block']['width'] = '45%';
1010 } else {
1011 $settings['block']['width'] = '100%';
1012 }
1013
1014 $settings['field']['width'] = $settings['block']['width'];
1015 $settings['field']['left'] = $settings['block']['left'];
1016 $settings['field']['right'] = $settings['block']['right'];
1017 $settings['field']['add_width'] = $settings['block']['add_width'];
1018 $settings['field']['margin_left'] = $settings['block']['margin_left'];
1019
1020
1021 if (!$field['address_state']) {
1022 $top += 60;
1023 }
1024 }
1025
1026 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
1027 'top' => $settings['block']['top'],
1028 'left' => $settings['block']['left'],
1029 'right' => $settings['block']['right'],
1030 'block' => $block,
1031 'float' => true,
1032 'width' => $settings['block']['width'],
1033 'properties' => array(
1034 'value' => $field['address_city_label'],
1035 )
1036 ));
1037
1038 $elements[] = $this->auto_field($field, 'e2pdf-input', array(
1039 'top' => $settings['field']['top'],
1040 'left' => $settings['field']['left'],
1041 'right' => $settings['field']['right'],
1042 'width' => $settings['field']['width'],
1043 'properties' => array(
1044 'value' => "{" . $field['element_id'] . "-city" . "}",
1045 )
1046 ));
1047
1048 if ($block && $field['address_state']) {
1049 $block = true;
1050 } else {
1051 $block = false;
1052 }
1053 }
1054
1055 if ($field['address_state']) {
1056 $settings = array(
1057 'block' => array(
1058 'width' => $width,
1059 'top' => '0',
1060 'left' => '0',
1061 'right' => '0',
1062 'add_width' => '0',
1063 'margin_left' => '0'
1064 ),
1065 'field' => array(
1066 'width' => '100%',
1067 'top' => '0',
1068 'left' => '0',
1069 'right' => '0',
1070 'add_width' => '0',
1071 'margin_left' => '0'
1072 )
1073 );
1074
1075 if ($block) {
1076 $settings['block']['top'] = '20';
1077 $settings['block']['left'] = '20';
1078 $settings['block']['right'] = '20';
1079 $settings['block']['width'] = ($field['address_city'] ? ($width / 2) : $width) . '%';
1080 } else {
1081 $settings['block']['top'] = $top;
1082 $settings['field']['top'] = $top + 20;
1083
1084
1085 if ($field['address_city']) {
1086 $settings['block']['width'] = '45%';
1087 $settings['block']['left'] = '55%';
1088 } else {
1089 $settings['block']['width'] = '100%';
1090 }
1091
1092 $settings['field']['width'] = $settings['block']['width'];
1093 $settings['field']['left'] = $settings['block']['left'];
1094 $settings['field']['right'] = $settings['block']['right'];
1095 $settings['field']['add_width'] = $settings['block']['add_width'];
1096 $settings['field']['margin_left'] = $settings['block']['margin_left'];
1097
1098 $top += 60;
1099 }
1100
1101 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
1102 'top' => $settings['block']['top'],
1103 'left' => $settings['block']['left'],
1104 'right' => $settings['block']['right'],
1105 'block' => $block,
1106 'float' => true,
1107 'width' => $settings['block']['width'],
1108 'properties' => array(
1109 'value' => $field['address_state_label'],
1110 )
1111 ));
1112
1113 $elements[] = $this->auto_field($field, 'e2pdf-input', array(
1114 'top' => $settings['field']['top'],
1115 'left' => $settings['field']['left'],
1116 'right' => $settings['field']['right'],
1117 'width' => $settings['field']['width'],
1118 'properties' => array(
1119 'value' => "{" . $field['element_id'] . "-state" . "}",
1120 )
1121 ));
1122
1123 $block = false;
1124 }
1125
1126 if ($field['address_zip']) {
1127 $settings = array(
1128 'block' => array(
1129 'width' => $width,
1130 'top' => '0',
1131 'left' => '0',
1132 'right' => '0',
1133 'add_width' => '0',
1134 'margin_left' => '0'
1135 ),
1136 'field' => array(
1137 'width' => '100%',
1138 'top' => '0',
1139 'left' => '0',
1140 'right' => '0',
1141 'add_width' => '0',
1142 'margin_left' => '0'
1143 )
1144 );
1145
1146 if ($block) {
1147 $settings['block']['top'] = '20';
1148 $settings['block']['left'] = '20';
1149 $settings['block']['right'] = '20';
1150 $settings['block']['width'] = ($field['address_country'] ? ($width / 2) : $width) . '%';
1151 } else {
1152 $settings['block']['top'] = $top;
1153 $settings['field']['top'] = $top + 20;
1154 if ($field['address_city'] && $field['address_state'] && !$field['street_address'] && !$field['address_line']) {
1155 $settings['block']['left'] = '-100%';
1156 $settings['block']['margin_left'] = '-40';
1157 if (!$field['address_country']) {
1158 $settings['block']['add_width'] = '40';
1159 }
1160 }
1161
1162 if ($field['address_city'] && $field['address_state'] && !$field['address_country'] && !$field['street_address'] && !$field['address_line']) {
1163 $settings['block']['width'] = '200%';
1164 } elseif ($field['address_country'] && ($field['street_address'] || $field['address_line'] || (!$field['address_city'] || !$field['address_state']))) {
1165 $settings['block']['width'] = '45%';
1166 } else {
1167 $settings['block']['width'] = '100%';
1168 }
1169
1170 $settings['field']['width'] = $settings['block']['width'];
1171 $settings['field']['left'] = $settings['block']['left'];
1172 $settings['field']['right'] = $settings['block']['right'];
1173 $settings['field']['add_width'] = $settings['block']['add_width'];
1174 $settings['field']['margin_left'] = $settings['block']['margin_left'];
1175 }
1176
1177 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
1178 'top' => $settings['block']['top'],
1179 'left' => $settings['block']['left'],
1180 'right' => $settings['block']['right'],
1181 'add_width' => $settings['block']['add_width'],
1182 'margin_left' => $settings['block']['margin_left'],
1183 'block' => $block,
1184 'float' => true,
1185 'width' => $settings['block']['width'],
1186 'properties' => array(
1187 'value' => $field['address_zip_label'],
1188 )
1189 ));
1190
1191
1192 $elements[] = $this->auto_field($field, 'e2pdf-input', array(
1193 'top' => $settings['field']['top'],
1194 'left' => $settings['field']['left'],
1195 'add_width' => $settings['field']['add_width'],
1196 'margin_left' => $settings['field']['margin_left'],
1197 'width' => $settings['field']['width'],
1198 'properties' => array(
1199 'value' => "{" . $field['element_id'] . "-zip" . "}",
1200 )
1201 ));
1202 }
1203
1204 if ($field['address_country']) {
1205 $settings = array(
1206 'block' => array(
1207 'width' => $width,
1208 'top' => '0',
1209 'left' => '0',
1210 'right' => '0',
1211 'add_width' => '0',
1212 'margin_left' => '0'
1213 ),
1214 'field' => array(
1215 'width' => '100%',
1216 'top' => '0',
1217 'left' => '0',
1218 'right' => '0',
1219 'add_width' => '0',
1220 'margin_left' => '0'
1221 )
1222 );
1223
1224 if ($block) {
1225 $settings['block']['top'] = '20';
1226 $settings['block']['left'] = '20';
1227 $settings['block']['right'] = '20';
1228 $settings['block']['width'] = ($field['address_zip'] ? ($width / 2) : $width) . '%';
1229 } else {
1230 $settings['block']['top'] = $top;
1231 $settings['field']['top'] = $top + 20;
1232
1233 if ($field['address_city'] && $field['address_state'] && !$field['address_zip'] && !$field['street_address'] && !$field['address_line']) {
1234 $settings['block']['width'] = '200%';
1235 $settings['block']['add_width'] = '40';
1236 $settings['block']['margin_left'] = '-40';
1237 $settings['block']['left'] = '-100%';
1238 } elseif ($field['address_zip'] && ($field['street_address'] || $field['address_line'] || (!$field['address_city'] || !$field['address_state']))) {
1239 $settings['block']['width'] = '45%';
1240 $settings['block']['left'] = '55%';
1241 } else {
1242 $settings['block']['width'] = '100%';
1243 }
1244
1245 $settings['field']['width'] = $settings['block']['width'];
1246 $settings['field']['left'] = $settings['block']['left'];
1247 $settings['field']['right'] = $settings['block']['right'];
1248 $settings['field']['add_width'] = $settings['block']['add_width'];
1249 $settings['field']['margin_left'] = $settings['block']['margin_left'];
1250 }
1251
1252 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
1253 'top' => $settings['block']['top'],
1254 'left' => $settings['block']['left'],
1255 'right' => $settings['block']['right'],
1256 'add_width' => $settings['block']['add_width'],
1257 'margin_left' => $settings['block']['margin_left'],
1258 'block' => $block,
1259 'float' => true,
1260 'width' => $settings['block']['width'],
1261 'properties' => array(
1262 'value' => $field['address_country_label'],
1263 )
1264 ));
1265
1266 $options_tmp = array();
1267 if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) {
1268 $options = forminator_to_field_array(forminator_get_countries_list(), true);
1269 foreach ($options as $option) {
1270 $options_tmp[] = $option['value'];
1271 }
1272 //can be value or label
1273 }
1274
1275 $elements[] = $this->auto_field($field, 'e2pdf-select', array(
1276 'top' => $settings['field']['top'],
1277 'left' => $settings['field']['left'],
1278 'add_width' => $settings['field']['add_width'],
1279 'margin_left' => $settings['field']['margin_left'],
1280 'width' => $settings['field']['width'],
1281 'properties' => array(
1282 'options' => implode("\n", $options_tmp),
1283 'value' => "{" . $field['element_id'] . "-country" . "}",
1284 )
1285 ));
1286 }
1287 break;
1288 case 'time':
1289
1290 $hours = array();
1291 $minutes = array();
1292
1293 if (class_exists('Forminator_Time')) {
1294 $forminator_time = new Forminator_Time();
1295 $options = $forminator_time->get_hours($field['time_type']);
1296 foreach ($options as $option) {
1297 $hours[] = $option['value'];
1298 }
1299
1300 $options = $forminator_time->get_minutes();
1301 foreach ($options as $option) {
1302 $minutes[] = $option['value'];
1303 }
1304 }
1305
1306 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
1307 'top' => '20',
1308 'left' => '20',
1309 'right' => '20',
1310 'block' => true,
1311 'float' => true,
1312 'width' => ($field['time_type'] == 'twelve' ? $width / 3 : $width / 2) . '%',
1313 'properties' => array(
1314 'value' => $field['hh_label'],
1315 )
1316 ));
1317
1318 if ($field['field_type'] == 'select') {
1319 $elements[] = $this->auto_field($field, 'e2pdf-select', array(
1320 'properties' => array(
1321 'options' => implode("\n", $hours),
1322 'value' => "{" . $field['element_id'] . "-hours" . "}",
1323 )
1324 ));
1325 } else {
1326 $elements[] = $this->auto_field($field, 'e2pdf-input', array(
1327 'properties' => array(
1328 'value' => "{" . $field['element_id'] . "-hours" . "}",
1329 )
1330 ));
1331 }
1332
1333 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
1334 'top' => '20',
1335 'left' => '20',
1336 'right' => '20',
1337 'block' => true,
1338 'float' => true,
1339 'width' => ($field['time_type'] == 'twelve' ? $width / 3 : $width / 2) . '%',
1340 'properties' => array(
1341 'value' => $field['mm_label'],
1342 )
1343 ));
1344
1345 if ($field['field_type'] == 'select') {
1346 $elements[] = $this->auto_field($field, 'e2pdf-select', array(
1347 'properties' => array(
1348 'options' => implode("\n", $minutes),
1349 'value' => "{" . $field['element_id'] . "-minutes" . "}",
1350 )
1351 ));
1352 } else {
1353 $elements[] = $this->auto_field($field, 'e2pdf-input', array(
1354 'properties' => array(
1355 'value' => "{" . $field['element_id'] . "-minutes" . "}",
1356 )
1357 ));
1358 }
1359
1360 if ($field['time_type'] == 'twelve') {
1361 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
1362 'top' => '20',
1363 'left' => '20',
1364 'right' => '20',
1365 'block' => true,
1366 'float' => $float,
1367 'width' => ($width / 3) . '%',
1368 'properties' => array(
1369 'value' => '',
1370 )
1371 ));
1372
1373 $ampm = array(
1374 'am', 'pm'
1375 );
1376
1377 $elements[] = $this->auto_field($field, 'e2pdf-select', array(
1378 'properties' => array(
1379 'options' => implode("\n", $ampm),
1380 'value' => "{" . $field['element_id'] . "-ampm" . "}",
1381 )
1382 ));
1383 }
1384 break;
1385 case 'html': {
1386
1387 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
1388 'top' => '20',
1389 'left' => '20',
1390 'right' => '20',
1391 'width' => $width . '%',
1392 'block' => true,
1393 'properties' => array(
1394 'value' => $field['field_label'],
1395 )
1396 ));
1397
1398 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
1399 'properties' => array(
1400 'height' => '100',
1401 'value' => $field['variations'],
1402 )
1403 ));
1404
1405
1406 break;
1407 }
1408 case 'text':
1409 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
1410 'top' => '20',
1411 'left' => '20',
1412 'right' => '20',
1413 'width' => $width . '%',
1414 'block' => true,
1415 'properties' => array(
1416 'value' => $field['field_label'],
1417 )
1418 ));
1419
1420 $elements[] = $this->auto_field($field, 'e2pdf-textarea', array(
1421 'properties' => array(
1422 'value' => "{" . $field['element_id'] . "}",
1423 )
1424 ));
1425 break;
1426 case 'select': {
1427 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
1428 'top' => '20',
1429 'left' => '20',
1430 'right' => '20',
1431 'block' => true,
1432 'float' => true,
1433 'width' => $width . '%',
1434 'properties' => array(
1435 'value' => $field['field_label'],
1436 )
1437 ));
1438
1439 if ($field['value_type'] == 'radio') {
1440 $top = 0;
1441 foreach ($field['options'] as $opt_key => $option) {
1442 if (is_array($option)) {
1443 $elements[] = $this->auto_field($field, 'e2pdf-radio', array(
1444 'top' => $top,
1445 'properties' => array(
1446 'width' => '15',
1447 'height' => '15',
1448 'value' => "{" . $field['element_id'] . "}",
1449 'option' => $option['value'] ? $option['value'] : $option['label'],
1450 'group' => "group_" . $field['element_id']
1451 )
1452 ));
1453 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
1454 'top' => $top,
1455 'left' => '20',
1456 'properties' => array(
1457 'value' => $option['label']
1458 )
1459 ));
1460 }
1461 $top = $top + 20;
1462 }
1463 } else {
1464
1465 $options_tmp = array();
1466 foreach ($field['options'] as $option) {
1467 $options_tmp[] = $option['value'] ? $option['value'] : $option['label'];
1468 }
1469
1470 $elements[] = $this->auto_field($field, 'e2pdf-select', array(
1471 'properties' => array(
1472 'options' => implode("\n", $options_tmp),
1473 'value' => "{" . $field['element_id'] . "}",
1474 )
1475 ));
1476 }
1477 break;
1478 }
1479 case 'checkbox': {
1480 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
1481 'top' => '20',
1482 'left' => '20',
1483 'right' => '20',
1484 'block' => true,
1485 'float' => true,
1486 'width' => $width . '%',
1487 'properties' => array(
1488 'value' => $field['field_label'],
1489 )
1490 ));
1491
1492 if ($field['value_type'] == 'multiselect') {
1493 $options_tmp = array();
1494 foreach ($field['options'] as $opt_key => $option) {
1495 $options_tmp[] = $option['value'] ? $option['value'] : $option['label'];
1496 }
1497 $elements[] = $this->auto_field($field, 'e2pdf-select', array(
1498 'properties' => array(
1499 'height' => '44',
1500 'multiline' => '1',
1501 'options' => implode("\n", $options_tmp),
1502 'value' => "{" . $field['element_id'] . "}",
1503 )
1504 ));
1505 } else {
1506
1507 $top = 0;
1508 foreach ($field['options'] as $opt_key => $option) {
1509 if (is_array($option)) {
1510 $elements[] = $this->auto_field($field, 'e2pdf-checkbox', array(
1511 'top' => $top,
1512 'properties' => array(
1513 'width' => '15',
1514 'height' => '15',
1515 'value' => "{" . $field['element_id'] . "}",
1516 'option' => $option['value'] ? $option['value'] : $option['label']
1517 )
1518 ));
1519 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
1520 'top' => $top,
1521 'left' => '20',
1522 'properties' => array(
1523 'value' => $option['label']
1524 )
1525 ));
1526 }
1527 $top = $top + 20;
1528 }
1529 }
1530 break;
1531 }
1532
1533
1534 case 'gdprcheckbox': {
1535
1536 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
1537 'top' => '20',
1538 'left' => '20',
1539 'right' => '20',
1540 'block' => true,
1541 'float' => true,
1542 'width' => $width . '%',
1543 'properties' => array(
1544 'value' => '',
1545 )
1546 ));
1547
1548 $elements[] = $this->auto_field($field, 'e2pdf-checkbox', array(
1549 'top' => '0',
1550 'properties' => array(
1551 'width' => '15',
1552 'height' => '15',
1553 'value' => "{" . $field['element_id'] . "}",
1554 'option' => 'true'
1555 )
1556 ));
1557 $elements[] = $this->auto_field($field, 'e2pdf-html', array(
1558 'top' => '0',
1559 'left' => '20',
1560 'properties' => array(
1561 'value' => $field['gdpr_description']
1562 )
1563 ));
1564 break;
1565 }
1566
1567
1568 default:
1569 break;
1570 }
1571 }
1572 }
1573
1574 $response['page'] = array(
1575 'bottom' => '20',
1576 'top' => '20',
1577 );
1578
1579 $response['elements'] = $elements;
1580 return $response;
1581 }
1582
1583 public function auto_field($field = false, $type = false, $options = array()) {
1584
1585 if (!$field || !$type) {
1586 return false;
1587 }
1588
1589 $element = array(
1590 'type' => $type,
1591 'properties' => isset($options['properties']) ? $options['properties'] : array(),
1592 );
1593
1594 $element['top'] = isset($options['top']) ? $options['top'] : '0';
1595 $element['left'] = isset($options['left']) ? $options['left'] : '0';
1596 $element['right'] = isset($options['right']) ? $options['right'] : '0';
1597 $element['block'] = isset($options['block']) ? $options['block'] : false;
1598 $element['float'] = isset($options['float']) ? $options['float'] : false;
1599 $element['margin_left'] = isset($options['margin_left']) ? $options['margin_left'] : '0';
1600 $element['margin_right'] = isset($options['margin_right']) ? $options['margin_right'] : '0';
1601 $element['add_width'] = isset($options['add_width']) ? $options['add_width'] : '0';
1602
1603 if (isset($options['width'])) {
1604 $element['width'] = $options['width'];
1605 }
1606
1607 return $element;
1608 }
1609
1610 /**
1611 * Load actions for this extension
1612 */
1613 public function load_actions() {
1614 add_action('forminator_custom_form_submit_before_set_fields', array($this, 'action_forminator_custom_form_submit_before_set_fields'), 30, 3);
1615 add_action('forminator_custom_form_mail_admin_message', array($this, 'action_forminator_mail_message'), 30, 5);
1616 add_action('forminator_custom_form_mail_user_message', array($this, 'action_forminator_mail_message'), 30, 5);
1617 add_action('forminator_custom_form_mail_before_send_mail', array($this, 'action_forminator_custom_form_mail_before_send_mail'), 30, 4);
1618 add_action('forminator_custom_form_mail_after_send_mail', array($this, 'action_forminator_custom_form_mail_after_send_mail'), 30, 3);
1619 }
1620
1621 /**
1622 * Load filters for this extension
1623 */
1624 public function load_filters() {
1625 add_filter('forminator_custom_form_submit_response', array($this, 'filter_forminator_custom_form_submit_response'), 30, 2);
1626 add_filter('forminator_custom_form_ajax_submit_response', array($this, 'filter_forminator_custom_form_submit_response'), 30, 2);
1627 }
1628
1629 public function action_forminator_custom_form_submit_before_set_fields($entry, $form_id, $field_data_array) {
1630 if ($entry && is_object($entry) && property_exists($entry, 'entry_id') && isset($entry->entry_id)) {
1631 $this->set('dataset', $entry->entry_id);
1632 }
1633 }
1634
1635 public function action_forminator_custom_form_mail_before_send_mail($mail, $custom_form, $data, $entry) {
1636 add_filter('wp_mail', array($this, 'filter_wp_mail'), 30, 1);
1637 }
1638
1639 public function action_forminator_custom_form_mail_after_send_mail($mail, $custom_form, $data) {
1640 remove_filter('wp_mail', array($this, 'filter_wp_mail'), 30);
1641 $files = $this->helper->get('forminator_attachments');
1642 if (is_array($files) && !empty($files)) {
1643 foreach ($files as $key => $file) {
1644 $this->helper->delete_dir(dirname($file) . '/');
1645 }
1646 $this->helper->deset('forminator_attachments');
1647 }
1648 }
1649
1650 public function action_forminator_mail_message($message, $custom_form, $data, $entry, $mail) {
1651 if (isset($message) && false !== strpos($message, '[')) {
1652 $shortcode_tags = array(
1653 'e2pdf-download',
1654 'e2pdf-save',
1655 'e2pdf-attachment',
1656 'e2pdf-adobesign'
1657 );
1658
1659 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $message, $matches);
1660
1661 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1662
1663 if (!empty($tagnames)) {
1664 $pattern = get_shortcode_regex($tagnames);
1665
1666 preg_match_all("/$pattern/", $message, $shortcodes);
1667 foreach ($shortcodes[0] as $key => $shortcode_value) {
1668 $shortcode = array();
1669 $shortcode[1] = $shortcodes[1][$key];
1670 $shortcode[2] = $shortcodes[2][$key];
1671 $shortcode[3] = $shortcodes[3][$key];
1672 $shortcode[4] = $shortcodes[4][$key];
1673 $shortcode[5] = $shortcodes[5][$key];
1674 $shortcode[6] = $shortcodes[6][$key];
1675
1676 $atts = shortcode_parse_atts($shortcode[3]);
1677
1678 if (!array_key_exists('dataset', $atts) && array_key_exists('id', $atts)) {
1679 $template = new Model_E2pdf_Template();
1680 $template->load($atts['id']);
1681 if ($template->get('extension') === 'forminator') {
1682 $entry_id = false;
1683 if ($entry && is_object($entry) && property_exists($entry, 'entry_id') && isset($entry->entry_id)) {
1684 $entry_id = $entry->entry_id;
1685 }
1686 if ($entry_id) {
1687 $atts['dataset'] = $entry_id;
1688 $shortcode[3] .= " dataset=\"{$entry_id}\"";
1689 }
1690 }
1691 }
1692
1693 if ($shortcode[2] === 'e2pdf-save' || $shortcode[2] === 'e2pdf-attachment' || $shortcode[2] === 'e2pdf-adobesign') {
1694 $shortcode[3] .= " apply=\"true\"";
1695 }
1696
1697 $shortcode[3] .= " filter=\"true\"";
1698
1699 if ($shortcode[2] === 'e2pdf-attachment') {
1700 $file = do_shortcode_tag($shortcode);
1701 if ($file) {
1702 $this->helper->add('forminator_attachments', $file);
1703 }
1704 $message = str_replace($shortcode_value, '', $message);
1705 } else {
1706 $message = str_replace($shortcode_value, do_shortcode_tag($shortcode), $message);
1707 }
1708 }
1709 }
1710 }
1711
1712 return $message;
1713 }
1714
1715 public function filter_forminator_custom_form_submit_response($response, $form_id) {
1716
1717 if (isset($response['message']) && false !== strpos($response['message'], '[') && isset($response['success']) && $response['success']) {
1718 $shortcode_tags = array(
1719 'e2pdf-download',
1720 'e2pdf-save',
1721 'e2pdf-view',
1722 'e2pdf-adobesign'
1723 );
1724
1725 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $response['message'], $matches);
1726
1727 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1728
1729 if (!empty($tagnames)) {
1730 $pattern = get_shortcode_regex($tagnames);
1731
1732 preg_match_all("/$pattern/", $response['message'], $shortcodes);
1733 foreach ($shortcodes[0] as $key => $shortcode_value) {
1734 $shortcode = array();
1735 $shortcode[1] = $shortcodes[1][$key];
1736 $shortcode[2] = $shortcodes[2][$key];
1737 $shortcode[3] = $shortcodes[3][$key];
1738 $shortcode[4] = $shortcodes[4][$key];
1739 $shortcode[5] = $shortcodes[5][$key];
1740 $shortcode[6] = $shortcodes[6][$key];
1741
1742 $atts = shortcode_parse_atts($shortcode[3]);
1743
1744 if (!array_key_exists('dataset', $atts) && array_key_exists('id', $atts)) {
1745 $template = new Model_E2pdf_Template();
1746 $template->load($atts['id']);
1747 if ($template->get('extension') === 'forminator') {
1748 $entry_id = $this->get('dataset');
1749 if ($entry_id) {
1750 $atts['dataset'] = $entry_id;
1751 $shortcode[3] .= " dataset=\"{$entry_id}\"";
1752 }
1753 }
1754 }
1755
1756 if ($shortcode[2] === 'e2pdf-save' || $shortcode[2] === 'e2pdf-adobesign') {
1757 $shortcode[3] .= " apply=\"true\"";
1758 }
1759
1760 $shortcode[3] .= " filter=\"true\"";
1761
1762 if ($shortcode['2'] === 'e2pdf-view') {
1763 $response['message'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $response['message']);
1764 } else {
1765 $response['message'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $response['message']);
1766 }
1767 }
1768 }
1769 }
1770 $this->set('dataset', false);
1771 return $response;
1772 }
1773
1774 public function filter_wp_mail($args = array()) {
1775 $files = $this->helper->get('forminator_attachments');
1776 if (is_array($files) && !empty($files)) {
1777 foreach ($files as $file) {
1778 $args['attachments'][] = $file;
1779 }
1780 }
1781 $wp_mail = array(
1782 'to' => $args['to'],
1783 'subject' => $args['subject'],
1784 'message' => $args['message'],
1785 'headers' => $args['headers'],
1786 'attachments' => $args['attachments'],
1787 );
1788
1789 return $wp_mail;
1790 }
1791
1792 /**
1793 * Get styles for generating Map Field function
1794 *
1795 * @return array - List of css files to load
1796 */
1797 public function get_styles() {
1798 $styles = array();
1799 if (function_exists(forminator_plugin_url)) {
1800 if (defined("FORMINATOR_VERSION")) {
1801 $version = FORMINATOR_VERSION;
1802 } else {
1803 $version = '0';
1804 }
1805 $styles = array(
1806 forminator_plugin_url() . 'assets/css/front.min.css?v=' . $version,
1807 plugins_url('css/extension/forminator.css?v=' . time(), $this->helper->get('plugin_file_path'))
1808 );
1809 }
1810 return $styles;
1811 }
1812
1813 }
1814