PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.03.07
E2Pdf – Export Pdf Tool for WordPress v1.03.07
1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 1.08.00 1.08.06 All 72 releases
e2pdf / classes / extension / e2pdf-forminator.php

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

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