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

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

1,523 lines 63.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * E2pdf 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
649 $fields = $xpath->query("//*[contains(@class, 'et_pb_contact_field_radio')]", $element);
650 foreach ($fields as $field) {
651 $radio_label = $xpath->query(".//label", $field)->item(0);
652 $radio = $xpath->query(".//input[@type='radio']", $field)->item(0);
653
654 $elements[] = $this->auto_field($field, array(
655 'type' => 'e2pdf-radio',
656 'properties' => array(
657 'top' => '5',
658 'width' => 'auto',
659 'height' => 'auto',
660 'value' => "%%" . $radio->attributes->getNamedItem("data-original_id")->nodeValue . "%%",
661 'option' => $radio->attributes->getNamedItem("value")->nodeValue,
662 'group' => $radio->attributes->getNamedItem("data-original_id")->nodeValue,
663 )
664 ));
665 $elements[] = $this->auto_field($radio, array(
666 'type' => 'e2pdf-html',
667 'float' => true,
668 'properties' => array(
669 'left' => '5',
670 'width' => '100%',
671 'height' => 'auto',
672 'value' => $radio_label->nodeValue
673 )
674 ));
675 }
676 } elseif ($data_type == 'checkbox') {
677
678 $label = $xpath->query(".//label", $element)->item(0);
679 $check_handler = $xpath->query(".//input[contains(@class, 'et_pb_checkbox_handle')]", $element)->item(0);
680
681 $name = "";
682 if ($check_handler) {
683 $name = "%%" . $check_handler->attributes->getNamedItem("data-original_id")->nodeValue . "%%";
684 }
685
686 $elements[] = $this->auto_field($element, array(
687 'type' => 'e2pdf-html',
688 'block' => true,
689 'properties' => array(
690 'top' => '20',
691 'left' => '20',
692 'right' => '20',
693 'width' => '100%',
694 'height' => 'auto',
695 'value' => $label->nodeValue,
696 )
697 ));
698
699
700 $fields = $xpath->query("//*[contains(@class, 'et_pb_contact_field_checkbox')]", $element);
701
702 foreach ($fields as $field) {
703 $checkbox_label = $xpath->query(".//label", $field)->item(0);
704 $checkbox = $xpath->query(".//input[@type='checkbox']", $field)->item(0);
705
706
707 $elements[] = $this->auto_field($field, array(
708 'type' => 'e2pdf-checkbox',
709 'properties' => array(
710 'top' => '5',
711 'width' => 'auto',
712 'height' => 'auto',
713 'value' => $name,
714 'option' => $checkbox->attributes->getNamedItem("value")->nodeValue
715 )
716 ));
717 $elements[] = $this->auto_field($checkbox, array(
718 'type' => 'e2pdf-html',
719 'float' => true,
720 'properties' => array(
721 'left' => '5',
722 'width' => '100%',
723 'height' => 'auto',
724 'value' => $checkbox_label->nodeValue
725 )
726 ));
727 }
728 } else {
729
730 $label = $xpath->query(".//label", $element)->item(0);
731 $input_text = $xpath->query(".//input[@type='text']", $element)->item(0);
732 $select = $xpath->query(".//select", $element)->item(0);
733 $textarea = $xpath->query(".//textarea", $element)->item(0);
734
735 if ($label && ($input_text || $select || $textarea)) {
736 $elements[] = $this->auto_field($element, array(
737 'type' => 'e2pdf-html',
738 'block' => true,
739 'properties' => array(
740 'top' => '20',
741 'left' => '20',
742 'right' => '20',
743 'width' => '100%',
744 'height' => 'auto',
745 'value' => $label->nodeValue,
746 )
747 ));
748 }
749
750 if ($input_text) {
751 $elements[] = $this->auto_field($input_text, array(
752 'type' => 'e2pdf-input',
753 'properties' => array(
754 'top' => '5',
755 'width' => '100%',
756 'height' => 'auto',
757 'value' => "%%{$input_text->attributes->getNamedItem("data-original_id")->nodeValue}%%",
758 )
759 ));
760 } elseif ($select) {
761 $options_tmp = array();
762 $options = $xpath->query(".//option", $select);
763 foreach ($options as $option) {
764 $options_tmp[] = $option->attributes->getNamedItem("value")->nodeValue;
765 }
766
767 $elements[] = $this->auto_field($select, array(
768 'type' => 'e2pdf-select',
769 'properties' => array(
770 'top' => '5',
771 'width' => '100%',
772 'height' => 'auto',
773 'options' => implode("\n", $options_tmp),
774 'value' => "%%{$select->attributes->getNamedItem("data-original_id")->nodeValue}%%",
775 )
776 ));
777 } elseif ($textarea) {
778 $elements[] = $this->auto_field($textarea, array(
779 'type' => 'e2pdf-textarea',
780 'properties' => array(
781 'top' => '5',
782 'width' => '100%',
783 'height' => '150',
784 'value' => "%%{$textarea->attributes->getNamedItem("data-original_id")->nodeValue}%%",
785 )
786 ));
787 }
788 }
789 }
790 }
791 }
792 }
793 }
794 }
795 }
796 }
797
798 $response['page'] = array(
799 'bottom' => '20',
800 'top' => '20',
801 'right' => '20',
802 'left' => '20'
803 );
804 $response['elements'] = $elements;
805
806 return $response;
807 }
808
809 /**
810 * Convert Field name to Value
811 * @since 0.01.34
812 *
813 * @param string $name - Field name
814 *
815 * @return bool|string - Converted value or false
816 */
817 public function auto_map($name = false) {
818 $item = $this->get('item');
819 if ($item) {
820 $post = $this->get_post($item);
821 if ($post && isset($post->post_content)) {
822 $content = $post->post_content;
823
824 if (false !== strpos($content, '[')) {
825 $shortcode_tags = array(
826 'et_pb_contact_form',
827 );
828
829 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
830 $tagnames = array_intersect($shortcode_tags, $matches[1]);
831
832 if (!empty($tagnames)) {
833 $pattern = get_shortcode_regex($tagnames);
834
835 preg_match_all("/$pattern/", $content, $shortcodes);
836
837 foreach ($shortcodes[0] as $key => $shortcode_value) {
838
839 $shortcode = array();
840 $shortcode[1] = $shortcodes[1][$key];
841 $shortcode[2] = $shortcodes[2][$key];
842 $shortcode[3] = $shortcodes[3][$key];
843 $shortcode[4] = $shortcodes[4][$key];
844 $shortcode[5] = $shortcodes[5][$key];
845 $shortcode[6] = $shortcodes[6][$key];
846
847
848 $atts = shortcode_parse_atts($shortcode[3]);
849 if (isset($atts['admin_label']) && $atts['admin_label'] == $this->get('item')) {
850
851 $field_content = $shortcode_value;
852 $field_shortcode_tags = array(
853 'et_pb_contact_field',
854 );
855
856 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $field_content, $field_matches);
857 $field_tagnames = array_intersect($field_shortcode_tags, $field_matches[1]);
858
859 if (!empty($field_tagnames)) {
860 $field_pattern = get_shortcode_regex($field_tagnames);
861
862 preg_match_all("/$field_pattern/", $field_content, $field_shortcodes);
863
864 foreach ($field_shortcodes[0] as $field_key => $field_shortcode_value) {
865 $field_shortcode = array();
866 $field_shortcode[3] = $field_shortcodes[3][$field_key];
867 $field_atts = shortcode_parse_atts($field_shortcode[3]);
868 if (isset($field_atts['field_title']) && isset($field_atts['field_id'])) {
869 if ($field_atts['field_title'] == $name || $field_atts['field_id'] == $name) {
870 return "%%" . strtolower($field_atts['field_id']) . "%%";
871 }
872 }
873 }
874 }
875 }
876 }
877 }
878 }
879 }
880 }
881
882 return false;
883 }
884
885 /**
886 * Generate field for Auto PDF
887 *
888 * @param object $field - Formidable field object
889 * @param string $type - Field type
890 * @param array $options - Field additional options
891 *
892 * @return array - Prepared auto field
893 */
894 public function auto_field($field = false, $element = array()) {
895
896 if (!$field) {
897 return false;
898 }
899
900 if (!isset($element['block'])) {
901 $element['block'] = false;
902 }
903
904 if (!isset($element['float'])) {
905 $element['float'] = false;
906 }
907
908 $classes = array();
909 if (isset($field->attributes->getNamedItem("class")->nodeValue)) {
910 $classes = explode(" ", $field->attributes->getNamedItem("class")->nodeValue);
911 }
912
913 $float_classes = array(
914 'et_pb_contact_field_half',
915 );
916 $array_intersect = array_intersect($classes, $float_classes);
917
918 if (!empty($array_intersect) && $element['block']) {
919 $element['float'] = true;
920 };
921
922 $primary_class = false;
923 if (!empty($array_intersect)) {
924 $primary_class = end($array_intersect);
925 }
926
927 if ($element['block']) {
928 switch ($primary_class) {
929 case 'et_pb_contact_field_half':
930 $element['width'] = '50%';
931 break;
932 default:
933 break;
934 }
935 }
936
937 return $element;
938 }
939
940 /**
941 * Verify if form and dataset exists
942 *
943 * @return bool - Exists/Not exists
944 */
945 public function verify() {
946 global $wpdb;
947 $item_id = $this->get('item');
948 $dataset_id = $this->get('dataset');
949
950 if ($item_id && $dataset_id) {
951 $condition = array(
952 'ID' => array(
953 'condition' => '=',
954 'value' => $dataset_id,
955 'type' => '%d'
956 ),
957 'extension' => array(
958 'condition' => '=',
959 'value' => 'divi',
960 'type' => '%s'
961 ),
962 'item' => array(
963 'condition' => '=',
964 'value' => $item_id,
965 'type' => '%s'
966 ),
967 );
968
969 $where = $this->helper->load('db')->prepare_where($condition);
970 $dataset = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . 'e2pdf_datasets' . $where['sql'] . "", $where['filter']));
971
972 if ($dataset) {
973 return true;
974 }
975 }
976 return false;
977 }
978
979 /**
980 * Visual Mapper for Mapping field
981 *
982 * @return bool|string - Prepared form or false
983 */
984 public function visual_mapper() {
985
986 if ($this->get('item')) {
987 $post = $this->get_post($this->get('item'));
988 if ($post && isset($post->post_content)) {
989
990 $content = $post->post_content;
991
992 if (false !== strpos($content, '[')) {
993 $shortcode_tags = array(
994 'et_pb_contact_form',
995 );
996
997 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
998 $tagnames = array_intersect($shortcode_tags, $matches[1]);
999
1000 if (!empty($tagnames)) {
1001 $pattern = get_shortcode_regex($tagnames);
1002
1003 preg_match_all("/$pattern/", $content, $shortcodes);
1004
1005 foreach ($shortcodes[0] as $key => $shortcode_value) {
1006
1007 $shortcode = array();
1008 $shortcode[1] = $shortcodes[1][$key];
1009 $shortcode[2] = $shortcodes[2][$key];
1010 $shortcode[3] = $shortcodes[3][$key];
1011 $shortcode[4] = $shortcodes[4][$key];
1012 $shortcode[5] = $shortcodes[5][$key];
1013 $shortcode[6] = $shortcodes[6][$key];
1014
1015 $atts = shortcode_parse_atts($shortcode[3]);
1016 if (isset($atts['admin_label']) && $atts['admin_label'] == $this->get('item')) {
1017
1018 require_once(ET_BUILDER_DIR . 'class-et-builder-element.php');
1019 require_once(ET_BUILDER_DIR . 'functions.php');
1020 require_once(ET_BUILDER_DIR . 'ab-testing.php');
1021 require_once(ET_BUILDER_DIR . 'class-et-global-settings.php');
1022 require_once(ET_BUILDER_DIR . 'module/ContactForm.php');
1023 require_once(ET_BUILDER_DIR . 'module/ContactFormItem.php');
1024
1025 new ET_Builder_Module_Contact_Form();
1026 new ET_Builder_Module_Contact_Form_Item();
1027
1028 $source = do_shortcode($shortcode_value);
1029
1030 libxml_use_internal_errors(true);
1031 $dom = new DOMDocument();
1032 if (function_exists('mb_convert_encoding')) {
1033 $html = $dom->loadHTML(mb_convert_encoding($source, 'HTML-ENTITIES', 'UTF-8'));
1034 } else {
1035 $html = $dom->loadHTML('<?xml encoding="UTF-8">' . $source);
1036 }
1037 libxml_clear_errors();
1038
1039 if (!$html) {
1040 return __('Form could not be parsed due incorrect HTML', 'e2pdf');
1041 } else {
1042
1043 $xpath = new DomXPath($dom);
1044 // Replace names
1045 $fields = $xpath->query("//*[contains(@name, 'et_pb_contact_')]");
1046 foreach ($fields as $element) {
1047 if ($element->attributes->getNamedItem("name")) {
1048 $element->attributes->getNamedItem("name")->nodeValue = "%%" . $element->attributes->getNamedItem("data-original_id")->nodeValue . "%%";
1049 }
1050 }
1051
1052 $checkboxes = $xpath->query("//*[contains(@class, 'et_pb_contact_field') and @data-type='checkbox']");
1053 foreach ($checkboxes as $element) {
1054
1055 $check_handler = $xpath->query(".//input[contains(@class, 'et_pb_checkbox_handle')]", $element)->item(0);
1056
1057 $name = "";
1058 if ($check_handler) {
1059 $name = "%%" . $check_handler->attributes->getNamedItem("data-original_id")->nodeValue . "%%";
1060 }
1061
1062 $checks = $xpath->query(".//input[@type='checkbox']", $element);
1063 foreach ($checks as $check) {
1064 $attr = $dom->createAttribute('name');
1065 $attr->value = $name;
1066 $check->appendChild($attr);
1067 }
1068 }
1069
1070 $remove_by_class = array(
1071 'et_pb_contact_submit',
1072 'et_pb_contactform_validate_field'
1073 );
1074 foreach ($remove_by_class as $key => $class) {
1075 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
1076 foreach ($elements as $element) {
1077 $element->parentNode->removeChild($element);
1078 }
1079 }
1080
1081 $remove_parent_by_class = array(
1082 'et_pb_contact_captcha_question'
1083 );
1084 foreach ($remove_parent_by_class as $key => $class) {
1085 $elements = $xpath->query("//*[contains(@class, '{$class}')]/parent::*");
1086 foreach ($elements as $element) {
1087 $element->parentNode->removeChild($element);
1088 }
1089 }
1090
1091 if ($xpath->query("//form")->item(0)) {
1092 $autocomplete = $dom->createAttribute('autocomplete');
1093 $autocomplete->value = 'off';
1094 $xpath->query("//form")->item(0)->appendChild($autocomplete);
1095 }
1096 }
1097
1098 return $dom->saveHTML();
1099 }
1100 }
1101 }
1102 }
1103 }
1104 }
1105
1106 return false;
1107 }
1108
1109 public function filter_wp_mail($args) {
1110 if (isset($args['message'])) {
1111 if (false !== strpos($args['message'], '[')) {
1112 $shortcode_tags = array(
1113 'e2pdf-download',
1114 'e2pdf-save',
1115 'e2pdf-attachment',
1116 'e2pdf-adobesign'
1117 );
1118
1119 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $args['message'], $matches);
1120 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1121
1122 if (!empty($tagnames)) {
1123 $pattern = get_shortcode_regex($tagnames);
1124
1125 preg_match_all("/$pattern/", $args['message'], $shortcodes);
1126
1127 foreach ($shortcodes[0] as $key => $shortcode_value) {
1128
1129 $shortcode = array();
1130 $shortcode[1] = $shortcodes[1][$key];
1131 $shortcode[2] = $shortcodes[2][$key];
1132 $shortcode[3] = $shortcodes[3][$key];
1133 $shortcode[4] = $shortcodes[4][$key];
1134 $shortcode[5] = $shortcodes[5][$key];
1135 $shortcode[6] = $shortcodes[6][$key];
1136
1137 $atts = shortcode_parse_atts($shortcode[3]);
1138
1139 if ($shortcode[2] === 'e2pdf-attachment' || $shortcode[2] === 'e2pdf-save' || $shortcode[2] === 'e2pdf-adobesign') {
1140 $shortcode[3] .= " apply=\"true\"";
1141 }
1142
1143 if ($shortcode[2] === 'e2pdf-attachment') {
1144 $file = do_shortcode_tag($shortcode);
1145 if ($file) {
1146 $this->helper->add('divi_attachments', $file);
1147 $args['attachments'][] = $file;
1148 }
1149 $args['message'] = str_replace($shortcode_value, '', $args['message']);
1150 } else {
1151 if (is_array($args['headers']) && !in_array('Content-Type: text/html; charset=UTF-8', $args['headers'])) {
1152 $args['headers'][] = 'Content-Type: text/html; charset=UTF-8';
1153 }
1154 $args['message'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $args['message']);
1155 $args['message'] = str_replace("\r\n", "<br/>", $args['message']);
1156 }
1157 }
1158 }
1159 }
1160 }
1161
1162 $wp_mail = array(
1163 'to' => $args['to'],
1164 'subject' => $args['subject'],
1165 'message' => $args['message'],
1166 'headers' => $args['headers'],
1167 'attachments' => $args['attachments'],
1168 );
1169
1170 return $wp_mail;
1171 }
1172
1173 /**
1174 * Load actions for this extension
1175 */
1176 public function load_actions() {
1177
1178 }
1179
1180 /**
1181 * Load filters for this extension
1182 */
1183 public function load_filters() {
1184 add_filter('et_pb_module_shortcode_attributes', array($this, 'filter_et_pb_module_shortcode_attributes'), 30, 5);
1185 add_filter('et_module_shortcode_output', array($this, 'filter_et_module_shortcode_output'), 30, 3);
1186 }
1187
1188 public function filter_et_pb_module_shortcode_attributes($props, $attrs, $render_slug, $address, $content) {
1189 global $wpdb;
1190
1191 if ($render_slug && $render_slug == 'et_pb_contact_form' && !empty($_POST) && $et_contact_proccess = array_search('et_contact_proccess', $_POST)) {
1192
1193 $et_pb_contact_form_num = str_replace("et_pb_contactform_submit_", "", $et_contact_proccess);
1194
1195 $et_contact_error = false;
1196 $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] : '';
1197 $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;
1198 $contact_email = '';
1199 $processed_fields_values = array();
1200
1201 $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;
1202
1203 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])) {
1204 if ('' !== $current_form_fields) {
1205 $fields_data_json = str_replace('\\', '', $current_form_fields);
1206 $fields_data_array = json_decode($fields_data_json, true);
1207
1208 // check whether captcha field is not empty
1209 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]) )) {
1210 $et_contact_error = true;
1211 }
1212
1213 // check all fields on current form and generate error message if needed
1214 if (!empty($fields_data_array)) {
1215 foreach ($fields_data_array as $index => $value) {
1216 // check all the required fields, generate error message if required field is empty
1217 $field_value = isset($_POST[$value['field_id']]) ? trim($_POST[$value['field_id']]) : '';
1218
1219 if ('required' === $value['required_mark'] && empty($field_value) && !is_numeric($field_value)) {
1220 $et_contact_error = true;
1221 continue;
1222 }
1223
1224 // additional check for email field
1225 if ('email' === $value['field_type'] && 'required' === $value['required_mark'] && !empty($field_value)) {
1226 $contact_email = isset($_POST[$value['field_id']]) ? sanitize_email($_POST[$value['field_id']]) : '';
1227
1228 if (!empty($contact_email) && !is_email($contact_email)) {
1229 $et_contact_error = true;
1230 }
1231 }
1232
1233 // prepare the array of processed field values in convenient format
1234 if (false === $et_contact_error) {
1235 $processed_fields_values[$value['original_id']]['value'] = $field_value;
1236 $processed_fields_values[$value['original_id']]['label'] = $value['field_label'];
1237 }
1238 }
1239 }
1240 } else {
1241 $et_contact_error = true;
1242 }
1243 } else {
1244 $et_contact_error = true;
1245 }
1246
1247 if (!$et_contact_error && $nonce_result) {
1248
1249 $dataset_id = false;
1250
1251 $success_message = '';
1252 $custom_message = '';
1253
1254 if (isset($props['success_message'])) {
1255 $success_message = str_replace(array('&#91;', '&#93;', '&quot;'), array('[', ']', '"'), $props['success_message']);
1256 }
1257
1258 if (false !== strpos($success_message, '[')) {
1259
1260 $shortcode_tags = array(
1261 'e2pdf-download',
1262 'e2pdf-save',
1263 'e2pdf-view',
1264 'e2pdf-adobesign'
1265 );
1266
1267 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $success_message, $matches);
1268 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1269
1270 if (!empty($tagnames)) {
1271 $pattern = get_shortcode_regex($tagnames);
1272
1273 preg_match_all("/$pattern/", $success_message, $shortcodes);
1274
1275 foreach ($shortcodes[0] as $key => $shortcode_value) {
1276
1277 $item = false;
1278
1279 $shortcode = array();
1280 $shortcode[1] = $shortcodes[1][$key];
1281 $shortcode[2] = $shortcodes[2][$key];
1282 $shortcode[3] = $shortcodes[3][$key];
1283 $shortcode[4] = $shortcodes[4][$key];
1284 $shortcode[5] = $shortcodes[5][$key];
1285 $shortcode[6] = $shortcodes[6][$key];
1286
1287 $atts = shortcode_parse_atts($shortcode[3]);
1288
1289 if (!array_key_exists('dataset', $atts) && array_key_exists('id', $atts)) {
1290 $template = new Model_E2pdf_Template();
1291 $template->load($atts['id']);
1292
1293 if ($template->get('extension') === 'divi') {
1294 $item = $template->get('item');
1295
1296 if (!$dataset_id) {
1297 $serialized = serialize($_POST);
1298 $dataset = array(
1299 'extension' => 'divi',
1300 'item' => $item,
1301 'entry' => $serialized
1302 );
1303 $wpdb->insert($wpdb->prefix . 'e2pdf_datasets', $dataset);
1304 $dataset_id = $wpdb->insert_id;
1305 }
1306 $atts['dataset'] = $dataset_id;
1307 $shortcode[3] .= " dataset=\"{$dataset_id}\" ";
1308 }
1309 }
1310
1311 if ($shortcode[2] === 'e2pdf-attachment' || $shortcode[2] === 'e2pdf-save') {
1312 $shortcode[3] .= " apply=\"true\"";
1313 }
1314
1315 $props['success_message'] = str_replace(str_replace(array('[', ']'), array('&#91;', '&#93;'), $shortcode_value), "[" . $shortcode[2] . $shortcode[3] . "]", $props['success_message']);
1316 }
1317 }
1318 }
1319
1320 if (isset($props['custom_message'])) {
1321 $custom_message = str_replace(array('&#91;', '&#93;'), array('[', ']'), $props['custom_message']);
1322 }
1323
1324 if (false !== strpos($custom_message, '[')) {
1325 $shortcode_tags = array(
1326 'e2pdf-download',
1327 'e2pdf-save',
1328 'e2pdf-attachment',
1329 'e2pdf-adobesign'
1330 );
1331
1332 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $custom_message, $matches);
1333 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1334
1335 if (!empty($tagnames)) {
1336 $pattern = get_shortcode_regex($tagnames);
1337
1338 preg_match_all("/$pattern/", $custom_message, $shortcodes);
1339
1340 add_filter('wp_mail', array($this, 'filter_wp_mail'), 10, 2);
1341
1342 foreach ($shortcodes[0] as $key => $shortcode_value) {
1343 $item = false;
1344
1345 $shortcode = array();
1346 $shortcode[1] = $shortcodes[1][$key];
1347 $shortcode[2] = $shortcodes[2][$key];
1348 $shortcode[3] = $shortcodes[3][$key];
1349 $shortcode[4] = $shortcodes[4][$key];
1350 $shortcode[5] = $shortcodes[5][$key];
1351 $shortcode[6] = $shortcodes[6][$key];
1352
1353 $atts = shortcode_parse_atts($shortcode[3]);
1354
1355 if (!array_key_exists('dataset', $atts) && array_key_exists('id', $atts)) {
1356 $template = new Model_E2pdf_Template();
1357 $template->load($atts['id']);
1358 if ($template->get('extension') === 'divi') {
1359 $item = $template->get('item');
1360
1361 if (!$dataset_id) {
1362 $serialized = serialize($_POST);
1363 $dataset = array(
1364 'extension' => 'divi',
1365 'item' => $item,
1366 'entry' => $serialized
1367 );
1368 $wpdb->insert($wpdb->prefix . 'e2pdf_datasets', $dataset);
1369 $dataset_id = $wpdb->insert_id;
1370 }
1371 $atts['dataset'] = $dataset_id;
1372 $shortcode[3] .= " dataset=\"{$dataset_id}\"";
1373 }
1374 }
1375
1376 $props['custom_message'] = str_replace(str_replace(array('[', ']'), array('&#91;', '&#93;'), $shortcode_value), "[" . $shortcode[2] . $shortcode[3] . "]", $props['custom_message']);
1377 }
1378 }
1379 }
1380 }
1381 }
1382
1383 return $props;
1384 }
1385
1386 public function filter_et_module_shortcode_output($output, $render_slug, $form) {
1387
1388 if ($render_slug && $render_slug == 'et_pb_contact_form' && !empty($_POST) && $et_contact_proccess = array_search('et_contact_proccess', $_POST)) {
1389
1390 $et_pb_contact_form_num = str_replace("et_pb_contactform_submit_", "", $et_contact_proccess);
1391
1392 $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;
1393
1394 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])) {
1395
1396 $dataset_id = false;
1397
1398 $success_message = '';
1399 $custom_message = '';
1400
1401 if (isset($form->props['success_message'])) {
1402 $success_message = str_replace(array('&#91;', '&#93;', '&quot;'), array('[', ']', '"'), $form->props['success_message']);
1403 }
1404
1405 if (false !== strpos($success_message, '[')) {
1406 $shortcode_tags = array(
1407 'e2pdf-download',
1408 'e2pdf-save',
1409 'e2pdf-view',
1410 'e2pdf-adobesign'
1411 );
1412
1413 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $success_message, $matches);
1414 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1415
1416 if (!empty($tagnames)) {
1417 $pattern = get_shortcode_regex($tagnames);
1418
1419 preg_match_all("/$pattern/", $success_message, $shortcodes);
1420
1421 foreach ($shortcodes[0] as $key => $shortcode_value) {
1422
1423 $shortcode = array();
1424 $shortcode[1] = $shortcodes[1][$key];
1425 $shortcode[2] = $shortcodes[2][$key];
1426 $shortcode[3] = $shortcodes[3][$key];
1427 $shortcode[4] = $shortcodes[4][$key];
1428 $shortcode[5] = $shortcodes[5][$key];
1429 $shortcode[6] = $shortcodes[6][$key];
1430
1431 $output = str_replace(str_replace(array('"'), array('&quot;'), $shortcode_value), do_shortcode_tag($shortcode), $output);
1432 }
1433 }
1434 }
1435 }
1436
1437 remove_filter('wp_mail', array($this, 'filter_wp_mail'), 10);
1438
1439 $files = $this->helper->get('divi_attachments');
1440 if (is_array($files) && !empty($files)) {
1441 foreach ($files as $key => $file) {
1442 $this->helper->delete_dir(dirname($file) . '/');
1443 }
1444 $this->helper->deset('divi_attachments');
1445 }
1446 }
1447
1448 return $output;
1449 }
1450
1451 /**
1452 * Delete dataset for template
1453 *
1454 * @param int $template_id - Template ID
1455 * @param int $dataset_id - Dataset ID
1456 *
1457 * @return bool - Result of removing items
1458 */
1459 public function delete_item($template_id = false, $dataset_id = false) {
1460 global $wpdb;
1461
1462 $template = new Model_E2pdf_Template();
1463 if ($template_id && $dataset_id && $template->load($template_id)) {
1464 if ($template->get('extension') === 'divi' && $template->get('item')) {
1465
1466 $item_id = $template->get('item');
1467
1468 $where = array(
1469 'ID' => $dataset_id,
1470 'item' => $item_id,
1471 'extension' => 'divi'
1472 );
1473 $wpdb->delete($wpdb->prefix . 'e2pdf_datasets', $where);
1474 return true;
1475 }
1476 }
1477
1478 return false;
1479 }
1480
1481 /**
1482 * Delete all datasets for Template
1483 *
1484 * @param int $template_id - Template ID
1485 *
1486 * @return bool - Result of removing items
1487 */
1488 public function delete_items($template_id = false) {
1489 global $wpdb;
1490
1491 $template = new Model_E2pdf_Template();
1492
1493 if ($template_id && $template->load($template_id)) {
1494 if ($template->get('extension') === 'divi' && $template->get('item')) {
1495
1496 $item_id = $template->get('item');
1497
1498 $where = array(
1499 'item' => $item_id,
1500 'extension' => 'divi'
1501 );
1502 $wpdb->delete($wpdb->prefix . 'e2pdf_datasets', $where);
1503 return true;
1504 }
1505 }
1506
1507 return false;
1508 }
1509
1510 /**
1511 * Get styles for generating Map Field function
1512 *
1513 * @return array - List of css files to load
1514 */
1515 public function styles() {
1516 $styles = array(
1517 plugins_url('css/extension/divi.css?v=' . time(), $this->helper->get('plugin_file_path'))
1518 );
1519 return $styles;
1520 }
1521
1522 }
1523