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

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