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

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

1,528 lines 64.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * E2pdf Divi Extension
5 *
6 * @copyright Copyright 2017 https://e2pdf.com
7 * @license GPL v2
8 * @version 1
9 * @link https://e2pdf.com
10 * @since 0.00.01
11 */
12 if (!defined('ABSPATH')) {
13 die('Access denied.');
14 }
15
16 class Extension_E2pdf_Divi extends Model_E2pdf_Model {
17
18 private $options;
19 private $info = array(
20 'key' => 'divi',
21 'title' => 'Divi'
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 /**
46 * Check if needed plugin active
47 *
48 * @return bool - Activated/Not Activated plugin
49 */
50 public function active() {
51 if (file_exists(get_template_directory() . "/et-pagebuilder/et-pagebuilder.php")) {
52 require_once(get_template_directory() . "/et-pagebuilder/et-pagebuilder.php");
53 if (defined('ET_BUILDER_THEME')) {
54 return true;
55 }
56 }
57 return false;
58 }
59
60 /**
61 * Set option
62 *
63 * @param string $attr - Key of option
64 * @param string $value - Value of option
65 *
66 * @return bool - Status of setting option
67 */
68 public function set($key, $value) {
69 if (!isset($this->options)) {
70 $this->options = new stdClass();
71 }
72
73 $this->options->$key = $value;
74 }
75
76 /**
77 * Get option by key
78 *
79 * @param string $key - Key to get assigned option value
80 *
81 * @return mixed
82 */
83 public function get($key) {
84 if (isset($this->options->$key)) {
85 $value = $this->options->$key;
86 return $value;
87 } else {
88 return false;
89 }
90 }
91
92 /**
93 * Get items to work with
94 *
95 * @return array() - List of available items
96 */
97 public function items() {
98 global $wpdb;
99
100 $condition = array(
101 'post_content' => array(
102 'condition' => 'LIKE',
103 'value' => '%et_pb_contact_form%',
104 'type' => '%s'
105 ),
106 'post_type' => array(
107 'condition' => '<>',
108 'value' => array(
109 'revision',
110 'et_pb_layout'
111 ),
112 'type' => '%s'
113 ),
114 );
115
116 $order_condition = array(
117 'orderby' => 'id',
118 'order' => 'desc',
119 );
120
121 $where = $this->helper->load('db')->prepare_where($condition);
122 $orderby = $this->helper->load('db')->prepare_orderby($order_condition);
123
124 $posts = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . 'posts' . $where['sql'] . $orderby . "", $where['filter']));
125
126 $content = array();
127 foreach ($posts as $key => $post) {
128 if ($forms_labels = $this->get_forms($post->post_content)) {
129 foreach ($forms_labels as $form_key => $form_value) {
130 $content[] = $this->item($form_key);
131 }
132 }
133 }
134 return $content;
135 }
136
137 /**
138 * Parse available forms from pages
139 *
140 * @param string $content - Page content
141 *
142 * @return array() - Forms list
143 */
144 public function get_forms($content) {
145
146 $forms = array();
147 if (false !== strpos($content, 'et_pb_contact_form')) {
148 $shortcode_tags = array(
149 'et_pb_contact_form',
150 );
151
152 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
153 $tagnames = array_intersect($shortcode_tags, $matches[1]);
154
155 if (!empty($tagnames)) {
156 $pattern = get_shortcode_regex($tagnames);
157
158 preg_match_all("/$pattern/", $content, $shortcodes);
159 foreach ($shortcodes[0] as $key => $shortcode_value) {
160
161 $shortcode = array();
162 $shortcode[1] = $shortcodes[1][$key];
163 $shortcode[2] = $shortcodes[2][$key];
164 $shortcode[3] = $shortcodes[3][$key];
165 $shortcode[4] = $shortcodes[4][$key];
166 $shortcode[5] = $shortcodes[5][$key];
167 $shortcode[6] = $shortcodes[6][$key];
168
169 preg_match_all('/admin_label="(.*?)"/', $shortcode[3], $labels);
170 if (isset($labels['1'])) {
171 foreach ($labels['1'] as $label) {
172 $forms[$label] = $label;
173 }
174 }
175 }
176 }
177 }
178
179 return $forms;
180 }
181
182 /**
183 * Get entries for export
184 *
185 * @param string $item - Item
186 * @param string $name - Entries names
187 *
188 * @return array() - Entries list
189 */
190 public function datasets($item = false, $name = false) {
191
192 global $wpdb;
193
194 $datasets = array();
195
196 if ($item) {
197 $condition = array(
198 'extension' => array(
199 'condition' => '=',
200 'value' => 'divi',
201 'type' => '%s'
202 ),
203 'item' => array(
204 'condition' => '=',
205 'value' => $item,
206 'type' => '%s'
207 ),
208 );
209
210 $order_condition = array(
211 'orderby' => 'ID',
212 'order' => 'desc',
213 );
214
215 $where = $this->helper->load('db')->prepare_where($condition);
216 $orderby = $this->helper->load('db')->prepare_orderby($order_condition);
217
218 $datasets_tmp = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . 'e2pdf_datasets' . $where['sql'] . $orderby . "", $where['filter']));
219
220 if ($datasets_tmp) {
221 foreach ($datasets_tmp as $key => $dataset) {
222 $this->set('item', $item);
223 $this->set('dataset', $dataset->ID);
224 $dataset_title = $this->render($name);
225 if (!$dataset_title) {
226 $dataset_title = $dataset->ID;
227 }
228 $datasets[] = array(
229 'key' => $dataset->ID,
230 'value' => $dataset_title
231 );
232 }
233 }
234 }
235
236 return $datasets;
237 }
238
239 /**
240 * Get dataset
241 *
242 * @param int $dataset - Dataset ID
243 *
244 * @return object - Dataset
245 */
246 public function dataset($dataset = false) {
247
248 $dataset = (int) $dataset;
249
250 if (!$dataset) {
251 return;
252 }
253
254 $data = new stdClass();
255 $data->url = false;
256
257 return $data;
258 }
259
260 /**
261 * Get item
262 *
263 * @param string $item - Item
264 *
265 * @return object - Item
266 */
267 public function item($item = false) {
268
269 $form = new stdClass();
270
271 if (!$item && $this->get('item')) {
272 $item = $this->get('item');
273 }
274
275 if ($item) {
276 $form->id = (string) $item;
277 $form->name = $item;
278 $post = $this->get_post($item);
279 $form->url = isset($post->ID) ? $this->helper->get_url(array('post' => $post->ID, 'action' => 'edit'), 'post.php?') : 'javascript:void(0);';
280 } else {
281 $form->id = '';
282 $form->name = '';
283 $form->url = 'javascript:void(0);';
284 }
285 return $form;
286 }
287
288 /**
289 * Get post
290 *
291 * @param string $item_id - Form label
292 *
293 * @return object - Post
294 */
295 public function get_post($item_id = false) {
296 global $wpdb;
297
298 $item_post = false;
299
300 $condition = array(
301 'post_content' => array(
302 'condition' => 'LIKE',
303 'value' => '%admin_label="' . $item_id . '"%',
304 'type' => '%s'
305 ),
306 'post_type' => array(
307 'condition' => '<>',
308 'value' => array(
309 'revision',
310 'et_pb_layout'
311 ),
312 'type' => '%s'
313 ),
314 );
315
316 $order_condition = array(
317 'orderby' => 'id',
318 'order' => 'desc',
319 );
320
321 $where = $this->helper->load('db')->prepare_where($condition);
322 $orderby = $this->helper->load('db')->prepare_orderby($order_condition);
323
324 $posts = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . 'posts' . $where['sql'] . $orderby . "", $where['filter']));
325 foreach ($posts as $key => $post) {
326 if ($forms_labels = $this->get_forms($post->post_content)) {
327 if (in_array($item_id, $forms_labels)) {
328 $item_post = $post;
329 break;
330 }
331 }
332 }
333 return $item_post;
334 }
335
336 /**
337 * Render value according to content
338 *
339 * @param string $value - Content
340 * @param string $type - Type of rendering value
341 * @param array $field - Field details
342 *
343 * @return string - Fully rendered value
344 */
345 public function render($value, $type = false, $field = array()) {
346
347 $value = $this->render_shortcodes($value, $type, $field);
348 $value = $this->strip_shortcodes($value);
349
350 if ($type === 'value' && isset($field['type']) && $field['type'] === 'e2pdf-checkbox' && isset($field['properties']['option'])) {
351 $option = $this->render($field['properties']['option']);
352 $options = explode(', ', $value);
353 $option_options = explode(', ', $option);
354 if (is_array($options) && is_array($option_options) && !array_diff($option_options, $options)) {
355 return $option;
356 } else {
357 return "";
358 }
359 }
360
361 if ($type === 'value') {
362 $value = $this->convert_shortcodes($value, true);
363 }
364
365 return $value;
366 }
367
368 /**
369 * Render shortcodes which available in this extension
370 *
371 * @param string $value - Content
372 * @param string $type - Type of rendering value
373 * @param array $field - Field details
374 *
375 * @return string - Value with rendered shortcodes
376 */
377 public function render_shortcodes($value, $type = false, $field = array()) {
378 global $wpdb;
379
380 $dataset_id = $this->get('dataset');
381 $item_id = $this->get('item');
382
383 $condition = array(
384 'ID' => array(
385 'condition' => '=',
386 'value' => $dataset_id,
387 'type' => '%d'
388 ),
389 'item' => array(
390 'condition' => '=',
391 'value' => $item_id,
392 'type' => '%s'
393 ),
394 'extension' => array(
395 'condition' => '=',
396 'value' => 'divi',
397 'type' => '%s'
398 ),
399 );
400
401 $where = $this->helper->load('db')->prepare_where($condition);
402
403 $dataset = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . 'e2pdf_datasets' . $where['sql'] . "", $where['filter']));
404
405 $processed_fields_values = array();
406 if ($dataset) {
407 $post = unserialize($dataset->entry);
408 if ($post && is_array($post)) {
409
410 $et_pb_contact_form_num = 0;
411
412 $current_form_fields = isset($post['et_pb_contact_email_fields_' . $et_pb_contact_form_num]) ? $post['et_pb_contact_email_fields_' . $et_pb_contact_form_num] : '';
413 $hidden_form_fields = isset($post['et_pb_contact_email_hidden_fields_' . $et_pb_contact_form_num]) ? $post['et_pb_contact_email_hidden_fields_' . $et_pb_contact_form_num] : false;
414 $processed_fields_values = array();
415
416 if ('' !== $current_form_fields) {
417 $fields_data_json = str_replace('\\', '', $current_form_fields);
418 $fields_data_array = json_decode($fields_data_json, true);
419
420 if (!empty($fields_data_array)) {
421 foreach ($fields_data_array as $index => $field_value) {
422 $processed_fields_values[$field_value['original_id']]['value'] = isset($post[$field_value['field_id']]) ? $post[$field_value['field_id']] : '';
423 $processed_fields_values[$field_value['original_id']]['label'] = $field_value['field_label'];
424 }
425 }
426 }
427 }
428
429 $replace = array();
430 foreach ($processed_fields_values as $field_key => $field_value) {
431 $replace["%%" . $field_key . "%%"] = wp_strip_all_tags($field_value['value']);
432 }
433
434 if (false !== strpos($value, '[')) {
435
436 $shortcode_tags = array(
437 'e2pdf-format-number',
438 'e2pdf-format-date',
439 'e2pdf-format-output',
440 );
441 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches);
442 $tagnames = array_intersect($shortcode_tags, $matches[1]);
443
444 if (!empty($tagnames)) {
445
446 $pattern = get_shortcode_regex($tagnames);
447 preg_match_all("/$pattern/", $value, $shortcodes);
448 foreach ($shortcodes[0] as $key => $shortcode_value) {
449 $shortcode = array();
450 $shortcode[1] = $shortcodes[1][$key];
451 $shortcode[2] = $shortcodes[2][$key];
452 $shortcode[3] = $shortcodes[3][$key];
453 $shortcode[4] = $shortcodes[4][$key];
454 $shortcode[5] = $shortcodes[5][$key];
455 $shortcode[6] = $shortcodes[6][$key];
456
457 if (isset($shortcode['5'])) {
458 if (isset($field['type']) && ($field['type'] === 'e2pdf-image' || $field['type'] === 'e2pdf-signature')) {
459 $sub_value = $this->render($shortcode['5'], $type);
460 } else {
461 $sub_value = $this->render($shortcode['5'], $type, $field);
462 }
463 $value = str_replace($shortcode_value, "[" . $shortcode['2'] . $shortcode['3'] . "]" . $sub_value . "[/" . $shortcode['2'] . "]", $value);
464 }
465 }
466 }
467 }
468
469 $value = do_shortcode($value);
470
471 if ($dataset) {
472 $value = $this->helper->load('convert')->stritr($value, $replace);
473 }
474
475 if (isset($field['type']) && ($field['type'] === 'e2pdf-image' || $field['type'] === 'e2pdf-signature')) {
476 $esig = isset($field['properties']['esig']) && $field['properties']['esig'] ? true : false;
477 if ($esig) {
478 //process e-signature
479 $value = "";
480 } else {
481 if (!$this->helper->load('image')->get_image($value)) {
482 $value = $this->strip_shortcodes($value);
483 if (
484 $value &&
485 trim($value) != "" &&
486 extension_loaded('gd') &&
487 function_exists('imagettftext')
488 ) {
489 if (isset($field['properties']['text_color']) && $field['properties']['text_color']) {
490 $penColour = $this->helper->load('convert')->to_hex_color($field['properties']['text_color']);
491 } else {
492 $penColour = array(0x14, 0x53, 0x94);
493 }
494
495 $default_options = array(
496 'imageSize' => array(isset($field['width']) ? $field['width'] : '400', isset($field['height']) ? $field['height'] : '150'),
497 'bgColour' => 'transparent',
498 'penColour' => $penColour
499 );
500
501 $options = array();
502 $options = array_merge($default_options, $options);
503
504 $model_e2pdf_font = new Model_E2pdf_Font();
505
506 $font = false;
507 if (isset($field['properties']['text_font']) && $field['properties']['text_font']) {
508 $font = $model_e2pdf_font->get_font_path($field['properties']['text_font']);
509 }
510 if (!$font) {
511 $font = $model_e2pdf_font->get_font_path('Noto Sans');
512 }
513
514 $size = 150;
515 if (isset($field['properties']['text_font_size']) && $field['properties']['text_font_size']) {
516 $size = $field['properties']['text_font_size'];
517 }
518
519 $model_e2pdf_signature = new Model_E2pdf_Signature();
520 $value = $model_e2pdf_signature->ttf_signature($value, $size, $font, $options);
521 } else {
522 $value = "";
523 }
524 }
525 }
526 } else {
527 $value = $this->convert_shortcodes($value);
528 }
529 }
530
531 return $value;
532 }
533
534 /**
535 * Strip unused shortcodes
536 *
537 * @param string $value - Content
538 *
539 * @return string - Value with removed unused shortcodes
540 */
541 public function strip_shortcodes($value) {
542 $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', "", $value);
543 $value = preg_replace('~(?:%%/?)[^/%%]+/?%%~s', "", $value);
544 return $value;
545 }
546
547 public function convert_shortcodes($value, $to = false) {
548 if ($value) {
549 if ($to) {
550 $value = str_replace("&#91;", "[", $value);
551 //$value = str_replace("&#37;", "%", $value);
552 } else {
553 $value = str_replace("[", "&#91;", $value);
554 //$value = str_replace("%", "&#37;", $value);
555 }
556 }
557 return $value;
558 }
559
560 public function auto() {
561
562 $response = array();
563 $elements = array();
564
565 if ($this->get('item')) {
566 $post = $this->get_post($this->get('item'));
567 if ($post && isset($post->post_content)) {
568
569 $content = $post->post_content;
570
571 if (false !== strpos($content, '[')) {
572 $shortcode_tags = array(
573 'et_pb_contact_form',
574 );
575
576 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
577 $tagnames = array_intersect($shortcode_tags, $matches[1]);
578
579 if (!empty($tagnames)) {
580 $pattern = get_shortcode_regex($tagnames);
581
582 preg_match_all("/$pattern/", $content, $shortcodes);
583
584 foreach ($shortcodes[0] as $key => $shortcode_value) {
585
586 $shortcode = array();
587 $shortcode[1] = $shortcodes[1][$key];
588 $shortcode[2] = $shortcodes[2][$key];
589 $shortcode[3] = $shortcodes[3][$key];
590 $shortcode[4] = $shortcodes[4][$key];
591 $shortcode[5] = $shortcodes[5][$key];
592 $shortcode[6] = $shortcodes[6][$key];
593
594 $atts = shortcode_parse_atts($shortcode[3]);
595 if (isset($atts['admin_label']) && $atts['admin_label'] == $this->get('item')) {
596
597 require_once(ET_BUILDER_DIR . 'class-et-builder-element.php');
598 require_once(ET_BUILDER_DIR . 'functions.php');
599 require_once(ET_BUILDER_DIR . 'ab-testing.php');
600 require_once(ET_BUILDER_DIR . 'class-et-global-settings.php');
601 require_once(ET_BUILDER_DIR . 'module/ContactForm.php');
602 require_once(ET_BUILDER_DIR . 'module/ContactFormItem.php');
603
604 new ET_Builder_Module_Contact_Form();
605 new ET_Builder_Module_Contact_Form_Item();
606
607 $source = do_shortcode($shortcode_value);
608
609 libxml_use_internal_errors(true);
610 $dom = new DOMDocument();
611 if (function_exists('mb_convert_encoding')) {
612 $html = $dom->loadHTML(mb_convert_encoding($source, 'HTML-ENTITIES', 'UTF-8'));
613 } else {
614 $html = $dom->loadHTML('<?xml encoding="UTF-8">' . $source);
615 }
616 libxml_clear_errors();
617
618 if ($html) {
619 $xpath = new DomXPath($dom);
620 $blocks = $xpath->query("//*[contains(@class, 'et_pb_contact_field')]");
621 foreach ($blocks as $element) {
622
623 $data_type = $element->attributes->getNamedItem("data-type")->nodeValue;
624
625 if ($data_type == 'radio') {
626
627 $label = $xpath->query(".//label", $element)->item(0);
628 $check_handler = $xpath->query(".//input[contains(@class, 'et_pb_checkbox_handle')]", $element)->item(0);
629
630 $name = "";
631 if ($check_handler) {
632 $name = "%%" . $check_handler->attributes->getNamedItem("data-original_id")->nodeValue . "%%";
633 }
634
635 $elements[] = $this->auto_field($element, array(
636 'type' => 'e2pdf-html',
637 'block' => true,
638 'properties' => array(
639 'top' => '20',
640 'left' => '20',
641 'right' => '20',
642 'width' => '100%',
643 'height' => 'auto',
644 'value' => $label->nodeValue,
645 )
646 ));
647
648 $fields = $xpath->query("//*[contains(@class, 'et_pb_contact_field_radio')]", $element);
649 foreach ($fields as $field) {
650 $radio_label = $xpath->query(".//label", $field)->item(0);
651 $radio = $xpath->query(".//input[@type='radio']", $field)->item(0);
652
653 $elements[] = $this->auto_field($field, array(
654 'type' => 'e2pdf-radio',
655 'properties' => array(
656 'top' => '5',
657 'width' => 'auto',
658 'height' => 'auto',
659 'value' => "%%" . $radio->attributes->getNamedItem("data-original_id")->nodeValue . "%%",
660 'option' => $radio->attributes->getNamedItem("value")->nodeValue,
661 'group' => $radio->attributes->getNamedItem("data-original_id")->nodeValue,
662 )
663 ));
664 $elements[] = $this->auto_field($radio, array(
665 'type' => 'e2pdf-html',
666 'float' => true,
667 'properties' => array(
668 'left' => '5',
669 'width' => '100%',
670 'height' => 'auto',
671 'value' => $radio_label->nodeValue
672 )
673 ));
674 }
675 } elseif ($data_type == 'checkbox') {
676
677 $label = $xpath->query(".//label", $element)->item(0);
678 $check_handler = $xpath->query(".//input[contains(@class, 'et_pb_checkbox_handle')]", $element)->item(0);
679
680 $name = "";
681 if ($check_handler) {
682 $name = "%%" . $check_handler->attributes->getNamedItem("data-original_id")->nodeValue . "%%";
683 }
684
685 $elements[] = $this->auto_field($element, array(
686 'type' => 'e2pdf-html',
687 'block' => true,
688 'properties' => array(
689 'top' => '20',
690 'left' => '20',
691 'right' => '20',
692 'width' => '100%',
693 'height' => 'auto',
694 'value' => $label->nodeValue,
695 )
696 ));
697
698
699 $fields = $xpath->query("//*[contains(@class, 'et_pb_contact_field_checkbox')]", $element);
700
701 foreach ($fields as $field) {
702 $checkbox_label = $xpath->query(".//label", $field)->item(0);
703 $checkbox = $xpath->query(".//input[@type='checkbox']", $field)->item(0);
704
705
706 $elements[] = $this->auto_field($field, array(
707 'type' => 'e2pdf-checkbox',
708 'properties' => array(
709 'top' => '5',
710 'width' => 'auto',
711 'height' => 'auto',
712 'value' => $name,
713 'option' => $checkbox->attributes->getNamedItem("value")->nodeValue
714 )
715 ));
716 $elements[] = $this->auto_field($checkbox, array(
717 'type' => 'e2pdf-html',
718 'float' => true,
719 'properties' => array(
720 'left' => '5',
721 'width' => '100%',
722 'height' => 'auto',
723 'value' => $checkbox_label->nodeValue
724 )
725 ));
726 }
727 } else {
728
729 $label = $xpath->query(".//label", $element)->item(0);
730 $input_text = $xpath->query(".//input[@type='text']", $element)->item(0);
731 $select = $xpath->query(".//select", $element)->item(0);
732 $textarea = $xpath->query(".//textarea", $element)->item(0);
733
734 if ($label && ($input_text || $select || $textarea)) {
735 $elements[] = $this->auto_field($element, array(
736 'type' => 'e2pdf-html',
737 'block' => true,
738 'properties' => array(
739 'top' => '20',
740 'left' => '20',
741 'right' => '20',
742 'width' => '100%',
743 'height' => 'auto',
744 'value' => $label->nodeValue,
745 )
746 ));
747 }
748
749 if ($input_text) {
750 $elements[] = $this->auto_field($input_text, array(
751 'type' => 'e2pdf-input',
752 'properties' => array(
753 'top' => '5',
754 'width' => '100%',
755 'height' => 'auto',
756 'value' => "%%{$input_text->attributes->getNamedItem("data-original_id")->nodeValue}%%",
757 )
758 ));
759 } elseif ($select) {
760 $options_tmp = array();
761 $options = $xpath->query(".//option", $select);
762 foreach ($options as $option) {
763 $options_tmp[] = $option->attributes->getNamedItem("value")->nodeValue;
764 }
765
766 $elements[] = $this->auto_field($select, array(
767 'type' => 'e2pdf-select',
768 'properties' => array(
769 'top' => '5',
770 'width' => '100%',
771 'height' => 'auto',
772 'options' => implode("\n", $options_tmp),
773 'value' => "%%{$select->attributes->getNamedItem("data-original_id")->nodeValue}%%",
774 )
775 ));
776 } elseif ($textarea) {
777 $elements[] = $this->auto_field($textarea, array(
778 'type' => 'e2pdf-textarea',
779 'properties' => array(
780 'top' => '5',
781 'width' => '100%',
782 'height' => '150',
783 'value' => "%%{$textarea->attributes->getNamedItem("data-original_id")->nodeValue}%%",
784 )
785 ));
786 }
787 }
788 }
789 }
790 }
791 }
792 }
793 }
794 }
795 }
796
797 $response['page'] = array(
798 'bottom' => '20',
799 'top' => '20',
800 'right' => '20',
801 'left' => '20'
802 );
803 $response['elements'] = $elements;
804
805 return $response;
806 }
807
808 /**
809 * Convert Field name to Value
810 * @since 0.01.34
811 *
812 * @param string $name - Field name
813 *
814 * @return bool|string - Converted value or false
815 */
816 public function auto_map($name = false) {
817 $item = $this->get('item');
818 if ($item) {
819 $post = $this->get_post($item);
820 if ($post && isset($post->post_content)) {
821 $content = $post->post_content;
822
823 if (false !== strpos($content, '[')) {
824 $shortcode_tags = array(
825 'et_pb_contact_form',
826 );
827
828 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
829 $tagnames = array_intersect($shortcode_tags, $matches[1]);
830
831 if (!empty($tagnames)) {
832 $pattern = get_shortcode_regex($tagnames);
833
834 preg_match_all("/$pattern/", $content, $shortcodes);
835
836 foreach ($shortcodes[0] as $key => $shortcode_value) {
837
838 $shortcode = array();
839 $shortcode[1] = $shortcodes[1][$key];
840 $shortcode[2] = $shortcodes[2][$key];
841 $shortcode[3] = $shortcodes[3][$key];
842 $shortcode[4] = $shortcodes[4][$key];
843 $shortcode[5] = $shortcodes[5][$key];
844 $shortcode[6] = $shortcodes[6][$key];
845
846 $atts = shortcode_parse_atts($shortcode[3]);
847 if (isset($atts['admin_label']) && $atts['admin_label'] == $this->get('item')) {
848
849 $field_content = $shortcode_value;
850 $field_shortcode_tags = array(
851 'et_pb_contact_field',
852 );
853
854 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $field_content, $field_matches);
855 $field_tagnames = array_intersect($field_shortcode_tags, $field_matches[1]);
856
857 if (!empty($field_tagnames)) {
858 $field_pattern = get_shortcode_regex($field_tagnames);
859
860 preg_match_all("/$field_pattern/", $field_content, $field_shortcodes);
861
862 foreach ($field_shortcodes[0] as $field_key => $field_shortcode_value) {
863 $field_shortcode = array();
864 $field_shortcode[3] = $field_shortcodes[3][$field_key];
865 $field_atts = shortcode_parse_atts($field_shortcode[3]);
866 if (isset($field_atts['field_title']) && isset($field_atts['field_id'])) {
867 if ($field_atts['field_title'] == $name || $field_atts['field_id'] == $name) {
868 return "%%" . strtolower($field_atts['field_id']) . "%%";
869 }
870 }
871 }
872 }
873 }
874 }
875 }
876 }
877 }
878 }
879
880 return false;
881 }
882
883 /**
884 * Generate field for Auto PDF
885 *
886 * @param object $field - Formidable field object
887 * @param string $type - Field type
888 * @param array $options - Field additional options
889 *
890 * @return array - Prepared auto field
891 */
892 public function auto_field($field = false, $element = array()) {
893
894 if (!$field) {
895 return false;
896 }
897
898 if (!isset($element['block'])) {
899 $element['block'] = false;
900 }
901
902 if (!isset($element['float'])) {
903 $element['float'] = false;
904 }
905
906 $classes = array();
907 if (isset($field->attributes->getNamedItem("class")->nodeValue)) {
908 $classes = explode(" ", $field->attributes->getNamedItem("class")->nodeValue);
909 }
910
911 $float_classes = array(
912 'et_pb_contact_field_half',
913 );
914 $array_intersect = array_intersect($classes, $float_classes);
915
916 if (!empty($array_intersect) && $element['block']) {
917 $element['float'] = true;
918 };
919
920 $primary_class = false;
921 if (!empty($array_intersect)) {
922 $primary_class = end($array_intersect);
923 }
924
925 if ($element['block']) {
926 switch ($primary_class) {
927 case 'et_pb_contact_field_half':
928 $element['width'] = '50%';
929 break;
930 default:
931 break;
932 }
933 }
934
935 return $element;
936 }
937
938 /**
939 * Verify if form and dataset exists
940 *
941 * @return bool - Exists/Not exists
942 */
943 public function verify() {
944 global $wpdb;
945 $item_id = $this->get('item');
946 $dataset_id = $this->get('dataset');
947
948 if ($item_id && $dataset_id) {
949 $condition = array(
950 'ID' => array(
951 'condition' => '=',
952 'value' => $dataset_id,
953 'type' => '%d'
954 ),
955 'extension' => array(
956 'condition' => '=',
957 'value' => 'divi',
958 'type' => '%s'
959 ),
960 'item' => array(
961 'condition' => '=',
962 'value' => $item_id,
963 'type' => '%s'
964 ),
965 );
966
967 $where = $this->helper->load('db')->prepare_where($condition);
968 $dataset = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . 'e2pdf_datasets' . $where['sql'] . "", $where['filter']));
969
970 if ($dataset) {
971 return true;
972 }
973 }
974 return false;
975 }
976
977 /**
978 * Visual Mapper for Mapping field
979 *
980 * @return bool|string - Prepared form or false
981 */
982 public function visual_mapper() {
983
984 $source = '';
985 $html = '';
986
987 if ($this->get('item')) {
988 $post = $this->get_post($this->get('item'));
989 if ($post && isset($post->post_content)) {
990
991 $content = $post->post_content;
992
993 if (false !== strpos($content, '[')) {
994 $shortcode_tags = array(
995 'et_pb_contact_form',
996 );
997
998 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
999 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1000
1001 if (!empty($tagnames)) {
1002 $pattern = get_shortcode_regex($tagnames);
1003
1004 preg_match_all("/$pattern/", $content, $shortcodes);
1005
1006 foreach ($shortcodes[0] as $key => $shortcode_value) {
1007
1008 $shortcode = array();
1009 $shortcode[1] = $shortcodes[1][$key];
1010 $shortcode[2] = $shortcodes[2][$key];
1011 $shortcode[3] = $shortcodes[3][$key];
1012 $shortcode[4] = $shortcodes[4][$key];
1013 $shortcode[5] = $shortcodes[5][$key];
1014 $shortcode[6] = $shortcodes[6][$key];
1015
1016 $atts = shortcode_parse_atts($shortcode[3]);
1017 if (isset($atts['admin_label']) && $atts['admin_label'] == $this->get('item')) {
1018
1019 require_once(ET_BUILDER_DIR . 'class-et-builder-element.php');
1020 require_once(ET_BUILDER_DIR . 'functions.php');
1021 require_once(ET_BUILDER_DIR . 'ab-testing.php');
1022 require_once(ET_BUILDER_DIR . 'class-et-global-settings.php');
1023 require_once(ET_BUILDER_DIR . 'module/ContactForm.php');
1024 require_once(ET_BUILDER_DIR . 'module/ContactFormItem.php');
1025
1026 new ET_Builder_Module_Contact_Form();
1027 new ET_Builder_Module_Contact_Form_Item();
1028
1029 $source = do_shortcode($shortcode_value);
1030
1031 if ($source) {
1032 libxml_use_internal_errors(true);
1033 $dom = new DOMDocument();
1034 if (function_exists('mb_convert_encoding')) {
1035 $html = $dom->loadHTML(mb_convert_encoding($source, 'HTML-ENTITIES', 'UTF-8'));
1036 } else {
1037 $html = $dom->loadHTML('<?xml encoding="UTF-8">' . $source);
1038 }
1039 libxml_clear_errors();
1040 }
1041
1042 if (!$source) {
1043 return __('Form source is empty', 'e2pdf');
1044 } elseif (!$html) {
1045 return __('Form could not be parsed due incorrect HTML', 'e2pdf');
1046 } else {
1047
1048 $xpath = new DomXPath($dom);
1049 // Replace names
1050 $fields = $xpath->query("//*[contains(@name, 'et_pb_contact_')]");
1051 foreach ($fields as $element) {
1052 if ($element->attributes->getNamedItem("name")) {
1053 $element->attributes->getNamedItem("name")->nodeValue = "%%" . $element->attributes->getNamedItem("data-original_id")->nodeValue . "%%";
1054 }
1055 }
1056
1057 $checkboxes = $xpath->query("//*[contains(@class, 'et_pb_contact_field') and @data-type='checkbox']");
1058 foreach ($checkboxes as $element) {
1059
1060 $check_handler = $xpath->query(".//input[contains(@class, 'et_pb_checkbox_handle')]", $element)->item(0);
1061
1062 $name = "";
1063 if ($check_handler) {
1064 $name = "%%" . $check_handler->attributes->getNamedItem("data-original_id")->nodeValue . "%%";
1065 }
1066
1067 $checks = $xpath->query(".//input[@type='checkbox']", $element);
1068 foreach ($checks as $check) {
1069 $attr = $dom->createAttribute('name');
1070 $attr->value = $name;
1071 $check->appendChild($attr);
1072 }
1073 }
1074
1075 $remove_by_class = array(
1076 'et_pb_contact_submit',
1077 'et_pb_contactform_validate_field'
1078 );
1079 foreach ($remove_by_class as $key => $class) {
1080 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
1081 foreach ($elements as $element) {
1082 $element->parentNode->removeChild($element);
1083 }
1084 }
1085
1086 $remove_parent_by_class = array(
1087 'et_pb_contact_captcha_question'
1088 );
1089 foreach ($remove_parent_by_class as $key => $class) {
1090 $elements = $xpath->query("//*[contains(@class, '{$class}')]/parent::*");
1091 foreach ($elements as $element) {
1092 $element->parentNode->removeChild($element);
1093 }
1094 }
1095
1096 if ($xpath->query("//form")->item(0)) {
1097 $autocomplete = $dom->createAttribute('autocomplete');
1098 $autocomplete->value = 'off';
1099 $xpath->query("//form")->item(0)->appendChild($autocomplete);
1100 }
1101 }
1102
1103 return $dom->saveHTML();
1104 }
1105 }
1106 }
1107 }
1108 }
1109 }
1110
1111 return false;
1112 }
1113
1114 public function filter_wp_mail($args) {
1115 if (isset($args['message'])) {
1116 if (false !== strpos($args['message'], '[')) {
1117 $shortcode_tags = array(
1118 'e2pdf-download',
1119 'e2pdf-save',
1120 'e2pdf-attachment',
1121 'e2pdf-adobesign'
1122 );
1123
1124 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $args['message'], $matches);
1125 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1126
1127 if (!empty($tagnames)) {
1128 $pattern = get_shortcode_regex($tagnames);
1129
1130 preg_match_all("/$pattern/", $args['message'], $shortcodes);
1131
1132 foreach ($shortcodes[0] as $key => $shortcode_value) {
1133
1134 $shortcode = array();
1135 $shortcode[1] = $shortcodes[1][$key];
1136 $shortcode[2] = $shortcodes[2][$key];
1137 $shortcode[3] = $shortcodes[3][$key];
1138 $shortcode[4] = $shortcodes[4][$key];
1139 $shortcode[5] = $shortcodes[5][$key];
1140 $shortcode[6] = $shortcodes[6][$key];
1141
1142 $atts = shortcode_parse_atts($shortcode[3]);
1143
1144 if ($shortcode[2] === 'e2pdf-attachment' || $shortcode[2] === 'e2pdf-save' || $shortcode[2] === 'e2pdf-adobesign') {
1145 $shortcode[3] .= " apply=\"true\"";
1146 }
1147
1148 if ($shortcode[2] === 'e2pdf-attachment') {
1149 $file = do_shortcode_tag($shortcode);
1150 if ($file) {
1151 $this->helper->add('divi_attachments', $file);
1152 $args['attachments'][] = $file;
1153 }
1154 $args['message'] = str_replace($shortcode_value, '', $args['message']);
1155 } else {
1156 if (is_array($args['headers']) && !in_array('Content-Type: text/html; charset=UTF-8', $args['headers'])) {
1157 $args['headers'][] = 'Content-Type: text/html; charset=UTF-8';
1158 }
1159 $args['message'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $args['message']);
1160 $args['message'] = str_replace("\r\n", "<br/>", $args['message']);
1161 }
1162 }
1163 }
1164 }
1165 }
1166
1167 $wp_mail = array(
1168 'to' => $args['to'],
1169 'subject' => $args['subject'],
1170 'message' => $args['message'],
1171 'headers' => $args['headers'],
1172 'attachments' => $args['attachments'],
1173 );
1174
1175 return $wp_mail;
1176 }
1177
1178 /**
1179 * Load actions for this extension
1180 */
1181 public function load_actions() {
1182
1183 }
1184
1185 /**
1186 * Load filters for this extension
1187 */
1188 public function load_filters() {
1189 add_filter('et_pb_module_shortcode_attributes', array($this, 'filter_et_pb_module_shortcode_attributes'), 30, 5);
1190 add_filter('et_module_shortcode_output', array($this, 'filter_et_module_shortcode_output'), 30, 3);
1191 }
1192
1193 public function filter_et_pb_module_shortcode_attributes($props, $attrs, $render_slug, $address, $content) {
1194 global $wpdb;
1195
1196 if ($render_slug && $render_slug == 'et_pb_contact_form' && !empty($_POST) && $et_contact_proccess = array_search('et_contact_proccess', $_POST)) {
1197
1198 $et_pb_contact_form_num = str_replace("et_pb_contactform_submit_", "", $et_contact_proccess);
1199
1200 $et_contact_error = false;
1201 $current_form_fields = isset($_POST['et_pb_contact_email_fields_' . $et_pb_contact_form_num]) ? $_POST['et_pb_contact_email_fields_' . $et_pb_contact_form_num] : '';
1202 $hidden_form_fields = isset($_POST['et_pb_contact_email_hidden_fields_' . $et_pb_contact_form_num]) ? $_POST['et_pb_contact_email_hidden_fields_' . $et_pb_contact_form_num] : false;
1203 $contact_email = '';
1204 $processed_fields_values = array();
1205
1206 $nonce_result = isset($_POST['_wpnonce-et-pb-contact-form-submitted-' . $et_pb_contact_form_num]) && wp_verify_nonce($_POST['_wpnonce-et-pb-contact-form-submitted-' . $et_pb_contact_form_num], 'et-pb-contact-form-submit') ? true : false;
1207
1208 if ($nonce_result && isset($_POST['et_pb_contactform_submit_' . $et_pb_contact_form_num]) && empty($_POST['et_pb_contactform_validate_' . $et_pb_contact_form_num])) {
1209 if ('' !== $current_form_fields) {
1210 $fields_data_json = str_replace('\\', '', $current_form_fields);
1211 $fields_data_array = json_decode($fields_data_json, true);
1212
1213 // check whether captcha field is not empty
1214 if ('on' === $captcha && (!isset($_POST['et_pb_contact_captcha_' . $et_pb_contact_form_num]) || empty($_POST['et_pb_contact_captcha_' . $et_pb_contact_form_num]) )) {
1215 $et_contact_error = true;
1216 }
1217
1218 // check all fields on current form and generate error message if needed
1219 if (!empty($fields_data_array)) {
1220 foreach ($fields_data_array as $index => $value) {
1221 // check all the required fields, generate error message if required field is empty
1222 $field_value = isset($_POST[$value['field_id']]) ? trim($_POST[$value['field_id']]) : '';
1223
1224 if ('required' === $value['required_mark'] && empty($field_value) && !is_numeric($field_value)) {
1225 $et_contact_error = true;
1226 continue;
1227 }
1228
1229 // additional check for email field
1230 if ('email' === $value['field_type'] && 'required' === $value['required_mark'] && !empty($field_value)) {
1231 $contact_email = isset($_POST[$value['field_id']]) ? sanitize_email($_POST[$value['field_id']]) : '';
1232
1233 if (!empty($contact_email) && !is_email($contact_email)) {
1234 $et_contact_error = true;
1235 }
1236 }
1237
1238 // prepare the array of processed field values in convenient format
1239 if (false === $et_contact_error) {
1240 $processed_fields_values[$value['original_id']]['value'] = $field_value;
1241 $processed_fields_values[$value['original_id']]['label'] = $value['field_label'];
1242 }
1243 }
1244 }
1245 } else {
1246 $et_contact_error = true;
1247 }
1248 } else {
1249 $et_contact_error = true;
1250 }
1251
1252 if (!$et_contact_error && $nonce_result) {
1253
1254 $dataset_id = false;
1255
1256 $success_message = '';
1257 $custom_message = '';
1258
1259 if (isset($props['success_message'])) {
1260 $success_message = str_replace(array('&#91;', '&#93;', '&quot;'), array('[', ']', '"'), $props['success_message']);
1261 }
1262
1263 if (false !== strpos($success_message, '[')) {
1264
1265 $shortcode_tags = array(
1266 'e2pdf-download',
1267 'e2pdf-save',
1268 'e2pdf-view',
1269 'e2pdf-adobesign'
1270 );
1271
1272 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $success_message, $matches);
1273 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1274
1275 if (!empty($tagnames)) {
1276 $pattern = get_shortcode_regex($tagnames);
1277
1278 preg_match_all("/$pattern/", $success_message, $shortcodes);
1279
1280 foreach ($shortcodes[0] as $key => $shortcode_value) {
1281
1282 $item = false;
1283
1284 $shortcode = array();
1285 $shortcode[1] = $shortcodes[1][$key];
1286 $shortcode[2] = $shortcodes[2][$key];
1287 $shortcode[3] = $shortcodes[3][$key];
1288 $shortcode[4] = $shortcodes[4][$key];
1289 $shortcode[5] = $shortcodes[5][$key];
1290 $shortcode[6] = $shortcodes[6][$key];
1291
1292 $atts = shortcode_parse_atts($shortcode[3]);
1293
1294 if (!array_key_exists('dataset', $atts) && array_key_exists('id', $atts)) {
1295 $template = new Model_E2pdf_Template();
1296 $template->load($atts['id']);
1297
1298 if ($template->get('extension') === 'divi') {
1299 $item = $template->get('item');
1300
1301 if (!$dataset_id) {
1302 $serialized = serialize($_POST);
1303 $dataset = array(
1304 'extension' => 'divi',
1305 'item' => $item,
1306 'entry' => $serialized
1307 );
1308 $wpdb->insert($wpdb->prefix . 'e2pdf_datasets', $dataset);
1309 $dataset_id = $wpdb->insert_id;
1310 }
1311 $atts['dataset'] = $dataset_id;
1312 $shortcode[3] .= " dataset=\"{$dataset_id}\" ";
1313 }
1314 }
1315
1316 if ($shortcode[2] === 'e2pdf-attachment' || $shortcode[2] === 'e2pdf-save') {
1317 $shortcode[3] .= " apply=\"true\"";
1318 }
1319
1320 $props['success_message'] = str_replace(str_replace(array('[', ']'), array('&#91;', '&#93;'), $shortcode_value), "[" . $shortcode[2] . $shortcode[3] . "]", $props['success_message']);
1321 }
1322 }
1323 }
1324
1325 if (isset($props['custom_message'])) {
1326 $custom_message = str_replace(array('&#91;', '&#93;'), array('[', ']'), $props['custom_message']);
1327 }
1328
1329 if (false !== strpos($custom_message, '[')) {
1330 $shortcode_tags = array(
1331 'e2pdf-download',
1332 'e2pdf-save',
1333 'e2pdf-attachment',
1334 'e2pdf-adobesign'
1335 );
1336
1337 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $custom_message, $matches);
1338 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1339
1340 if (!empty($tagnames)) {
1341 $pattern = get_shortcode_regex($tagnames);
1342
1343 preg_match_all("/$pattern/", $custom_message, $shortcodes);
1344
1345 add_filter('wp_mail', array($this, 'filter_wp_mail'), 10, 2);
1346
1347 foreach ($shortcodes[0] as $key => $shortcode_value) {
1348 $item = false;
1349
1350 $shortcode = array();
1351 $shortcode[1] = $shortcodes[1][$key];
1352 $shortcode[2] = $shortcodes[2][$key];
1353 $shortcode[3] = $shortcodes[3][$key];
1354 $shortcode[4] = $shortcodes[4][$key];
1355 $shortcode[5] = $shortcodes[5][$key];
1356 $shortcode[6] = $shortcodes[6][$key];
1357
1358 $atts = shortcode_parse_atts($shortcode[3]);
1359
1360 if (!array_key_exists('dataset', $atts) && array_key_exists('id', $atts)) {
1361 $template = new Model_E2pdf_Template();
1362 $template->load($atts['id']);
1363 if ($template->get('extension') === 'divi') {
1364 $item = $template->get('item');
1365
1366 if (!$dataset_id) {
1367 $serialized = serialize($_POST);
1368 $dataset = array(
1369 'extension' => 'divi',
1370 'item' => $item,
1371 'entry' => $serialized
1372 );
1373 $wpdb->insert($wpdb->prefix . 'e2pdf_datasets', $dataset);
1374 $dataset_id = $wpdb->insert_id;
1375 }
1376 $atts['dataset'] = $dataset_id;
1377 $shortcode[3] .= " dataset=\"{$dataset_id}\"";
1378 }
1379 }
1380
1381 $props['custom_message'] = str_replace(str_replace(array('[', ']'), array('&#91;', '&#93;'), $shortcode_value), "[" . $shortcode[2] . $shortcode[3] . "]", $props['custom_message']);
1382 }
1383 }
1384 }
1385 }
1386 }
1387
1388 return $props;
1389 }
1390
1391 public function filter_et_module_shortcode_output($output, $render_slug, $form) {
1392
1393 if ($render_slug && $render_slug == 'et_pb_contact_form' && !empty($_POST) && $et_contact_proccess = array_search('et_contact_proccess', $_POST)) {
1394
1395 $et_pb_contact_form_num = str_replace("et_pb_contactform_submit_", "", $et_contact_proccess);
1396
1397 $nonce_result = isset($_POST['_wpnonce-et-pb-contact-form-submitted-' . $et_pb_contact_form_num]) && wp_verify_nonce($_POST['_wpnonce-et-pb-contact-form-submitted-' . $et_pb_contact_form_num], 'et-pb-contact-form-submit') ? true : false;
1398
1399 if ($nonce_result && isset($_POST['et_pb_contactform_submit_' . $et_pb_contact_form_num]) && empty($_POST['et_pb_contactform_validate_' . $et_pb_contact_form_num])) {
1400
1401 $dataset_id = false;
1402
1403 $success_message = '';
1404 $custom_message = '';
1405
1406 if (isset($form->props['success_message'])) {
1407 $success_message = str_replace(array('&#91;', '&#93;', '&quot;'), array('[', ']', '"'), $form->props['success_message']);
1408 }
1409
1410 if (false !== strpos($success_message, '[')) {
1411 $shortcode_tags = array(
1412 'e2pdf-download',
1413 'e2pdf-save',
1414 'e2pdf-view',
1415 'e2pdf-adobesign'
1416 );
1417
1418 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $success_message, $matches);
1419 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1420
1421 if (!empty($tagnames)) {
1422 $pattern = get_shortcode_regex($tagnames);
1423
1424 preg_match_all("/$pattern/", $success_message, $shortcodes);
1425
1426 foreach ($shortcodes[0] as $key => $shortcode_value) {
1427
1428 $shortcode = array();
1429 $shortcode[1] = $shortcodes[1][$key];
1430 $shortcode[2] = $shortcodes[2][$key];
1431 $shortcode[3] = $shortcodes[3][$key];
1432 $shortcode[4] = $shortcodes[4][$key];
1433 $shortcode[5] = $shortcodes[5][$key];
1434 $shortcode[6] = $shortcodes[6][$key];
1435
1436 $output = str_replace(str_replace(array('"'), array('&quot;'), $shortcode_value), do_shortcode_tag($shortcode), $output);
1437 }
1438 }
1439 }
1440 }
1441
1442 remove_filter('wp_mail', array($this, 'filter_wp_mail'), 10);
1443
1444 $files = $this->helper->get('divi_attachments');
1445 if (is_array($files) && !empty($files)) {
1446 foreach ($files as $key => $file) {
1447 $this->helper->delete_dir(dirname($file) . '/');
1448 }
1449 $this->helper->deset('divi_attachments');
1450 }
1451 }
1452
1453 return $output;
1454 }
1455
1456 /**
1457 * Delete dataset for template
1458 *
1459 * @param int $template_id - Template ID
1460 * @param int $dataset_id - Dataset ID
1461 *
1462 * @return bool - Result of removing items
1463 */
1464 public function delete_item($template_id = false, $dataset_id = false) {
1465 global $wpdb;
1466
1467 $template = new Model_E2pdf_Template();
1468 if ($template_id && $dataset_id && $template->load($template_id)) {
1469 if ($template->get('extension') === 'divi' && $template->get('item')) {
1470
1471 $item_id = $template->get('item');
1472
1473 $where = array(
1474 'ID' => $dataset_id,
1475 'item' => $item_id,
1476 'extension' => 'divi'
1477 );
1478 $wpdb->delete($wpdb->prefix . 'e2pdf_datasets', $where);
1479 return true;
1480 }
1481 }
1482
1483 return false;
1484 }
1485
1486 /**
1487 * Delete all datasets for Template
1488 *
1489 * @param int $template_id - Template ID
1490 *
1491 * @return bool - Result of removing items
1492 */
1493 public function delete_items($template_id = false) {
1494 global $wpdb;
1495
1496 $template = new Model_E2pdf_Template();
1497
1498 if ($template_id && $template->load($template_id)) {
1499 if ($template->get('extension') === 'divi' && $template->get('item')) {
1500
1501 $item_id = $template->get('item');
1502
1503 $where = array(
1504 'item' => $item_id,
1505 'extension' => 'divi'
1506 );
1507 $wpdb->delete($wpdb->prefix . 'e2pdf_datasets', $where);
1508 return true;
1509 }
1510 }
1511
1512 return false;
1513 }
1514
1515 /**
1516 * Get styles for generating Map Field function
1517 *
1518 * @return array - List of css files to load
1519 */
1520 public function styles() {
1521 $styles = array(
1522 plugins_url('css/extension/divi.css?v=' . time(), $this->helper->get('plugin_file_path'))
1523 );
1524 return $styles;
1525 }
1526
1527 }
1528