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

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