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

1,644 lines 70.8 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 Contact Forms'
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
535 if (isset($field['properties']['preg_pattern']) && $field['properties']['preg_pattern'] && isset($field['properties']['preg_replacement']) && $value) {
536 $value = $this->helper->load('convert')->preg_replace($field['properties']['preg_pattern'], $field['properties']['preg_replacement'], $value);
537 }
538
539 if (!$this->helper->load('image')->get_image($value)) {
540 $value = $this->strip_shortcodes($value);
541 if (
542 $value &&
543 trim($value) != "" &&
544 extension_loaded('gd') &&
545 function_exists('imagettftext')
546 ) {
547 if (isset($field['properties']['text_color']) && $field['properties']['text_color']) {
548 $penColour = $this->helper->load('convert')->to_hex_color($field['properties']['text_color']);
549 } else {
550 $penColour = array(0x14, 0x53, 0x94);
551 }
552
553 $default_options = array(
554 'imageSize' => array(isset($field['width']) ? $field['width'] : '400', isset($field['height']) ? $field['height'] : '150'),
555 'bgColour' => 'transparent',
556 'penColour' => $penColour
557 );
558
559 $options = array();
560 $options = apply_filters('e2pdf_image_sig_output_options', $options, $element_id, $template_id);
561 $options = array_merge($default_options, $options);
562
563 $model_e2pdf_font = new Model_E2pdf_Font();
564
565 $font = false;
566 if (isset($field['properties']['text_font']) && $field['properties']['text_font']) {
567 $font = $model_e2pdf_font->get_font_path($field['properties']['text_font']);
568 }
569 if (!$font) {
570 $font = $model_e2pdf_font->get_font_path('Noto Sans');
571 }
572
573 $size = 150;
574 if (isset($field['properties']['text_font_size']) && $field['properties']['text_font_size']) {
575 $size = $field['properties']['text_font_size'];
576 }
577
578 $model_e2pdf_signature = new Model_E2pdf_Signature();
579 $value = $model_e2pdf_signature->ttf_signature($value, $size, $font, $options);
580 } else {
581 $value = "";
582 }
583 }
584 }
585 } else {
586
587 $value = $this->convert_shortcodes($value);
588
589 if (isset($field['properties']['preg_pattern']) && $field['properties']['preg_pattern'] && isset($field['properties']['preg_replacement']) && $value) {
590 $value = $this->helper->load('convert')->preg_replace($field['properties']['preg_pattern'], $field['properties']['preg_replacement'], $value);
591 }
592 }
593 }
594 }
595
596 $value = apply_filters('e2pdf_extension_render_shortcodes_value', $value, $element_id, $template_id, $item, $dataset);
597
598 return $value;
599 }
600
601 /**
602 * Strip unused shortcodes
603 *
604 * @param string $value - Content
605 *
606 * @return string - Value with removed unused shortcodes
607 */
608 public function strip_shortcodes($value) {
609 $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', "", $value);
610 $value = preg_replace('~(?:%%/?)[^/%%]+/?%%~s', "", $value);
611 return $value;
612 }
613
614 /**
615 * Convert "shortcodes" inside value string
616 *
617 * @param string $value - Value string
618 * @param bool $to - Convert From/To
619 *
620 * @return string - Converted value
621 */
622 public function convert_shortcodes($value, $to = false) {
623 if ($value) {
624 if ($to) {
625 $value = str_replace("&#91;", "[", $value);
626 //$value = str_replace("&#37;", "%", $value);
627 } else {
628 $value = str_replace("[", "&#91;", $value);
629 //$value = str_replace("%", "&#37;", $value);
630 }
631 }
632 return $value;
633 }
634
635 public function auto() {
636
637 $response = array();
638 $elements = array();
639
640 if ($this->get('item')) {
641 $post = $this->get_post($this->get('item'));
642 if ($post && isset($post->post_content)) {
643
644 $content = $post->post_content;
645
646 if (false !== strpos($content, '[')) {
647 $shortcode_tags = array(
648 'et_pb_contact_form',
649 );
650
651 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
652 $tagnames = array_intersect($shortcode_tags, $matches[1]);
653
654 if (!empty($tagnames)) {
655
656 $pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames);
657
658 preg_match_all("/$pattern/", $content, $shortcodes);
659
660 foreach ($shortcodes[0] as $key => $shortcode_value) {
661
662 $shortcode = array();
663 $shortcode[1] = $shortcodes[1][$key];
664 $shortcode[2] = $shortcodes[2][$key];
665 $shortcode[3] = $shortcodes[3][$key];
666 $shortcode[4] = $shortcodes[4][$key];
667 $shortcode[5] = $shortcodes[5][$key];
668 $shortcode[6] = $shortcodes[6][$key];
669
670 $atts = shortcode_parse_atts($shortcode[3]);
671 if (isset($atts['admin_label']) && $atts['admin_label'] == $this->get('item')) {
672
673 require_once(ET_BUILDER_DIR . 'class-et-builder-element.php');
674 require_once(ET_BUILDER_DIR . 'functions.php');
675 require_once(ET_BUILDER_DIR . 'ab-testing.php');
676 require_once(ET_BUILDER_DIR . 'class-et-global-settings.php');
677 require_once(ET_BUILDER_DIR . 'module/ContactForm.php');
678 require_once(ET_BUILDER_DIR . 'module/ContactFormItem.php');
679
680 new ET_Builder_Module_Contact_Form();
681 new ET_Builder_Module_Contact_Form_Item();
682
683 $source = do_shortcode($shortcode_value);
684
685 libxml_use_internal_errors(true);
686 $dom = new DOMDocument();
687 if (function_exists('mb_convert_encoding')) {
688 $html = $dom->loadHTML(mb_convert_encoding($source, 'HTML-ENTITIES', 'UTF-8'));
689 } else {
690 $html = $dom->loadHTML('<?xml encoding="UTF-8">' . $source);
691 }
692 libxml_clear_errors();
693
694 if ($html) {
695
696 $xml = $this->helper->load('xml');
697 $xml->set('dom', $dom);
698 $xpath = new DomXPath($dom);
699
700 $blocks = $xpath->query("//*[contains(@class, 'et_pb_contact_field')]");
701 foreach ($blocks as $element) {
702
703 if ($xml->get_node_value($element, 'data-type') == 'radio') {
704
705 $label = $xpath->query(".//label", $element)->item(0);
706 $check_handler = $xpath->query(".//input[contains(@class, 'et_pb_checkbox_handle')]", $element)->item(0);
707
708 $name = "";
709 if ($check_handler) {
710 $name = '%%' . $xml->get_node_value($check_handler, 'data-original_id') . '%%';
711 }
712
713 if ($label) {
714 $elements[] = $this->auto_field($element, array(
715 'type' => 'e2pdf-html',
716 'block' => true,
717 'class' => $xml->get_node_value($element, 'class'),
718 'properties' => array(
719 'top' => '20',
720 'left' => '20',
721 'right' => '20',
722 'width' => '100%',
723 'height' => 'auto',
724 'value' => $label->nodeValue,
725 )
726 ));
727 }
728
729 $fields = $xpath->query("//*[contains(@class, 'et_pb_contact_field_radio')]", $element);
730 foreach ($fields as $field) {
731 $radio_label = $xpath->query(".//label", $field)->item(0);
732 $radio = $xpath->query(".//input[@type='radio']", $field)->item(0);
733
734 if (
735 $radio->attributes->getNamedItem("data-original_id") &&
736 $radio->attributes->getNamedItem("value")
737 ) {
738 $elements[] = $this->auto_field($field, array(
739 'type' => 'e2pdf-radio',
740 'class' => $xml->get_node_value($field, 'class'),
741 'properties' => array(
742 'top' => '5',
743 'width' => 'auto',
744 'height' => 'auto',
745 'value' => '%%' . $xml->get_node_value($radio, 'data-original_id') . '%%',
746 'option' => $xml->get_node_value($radio, 'value'),
747 'group' => '%%' . $xml->get_node_value($radio, 'data-original_id') . '%%',
748 )
749 ));
750 }
751
752
753 if ($radio_label) {
754 $elements[] = $this->auto_field($radio, array(
755 'type' => 'e2pdf-html',
756 'float' => true,
757 'class' => $xml->get_node_value($radio, 'class'),
758 'properties' => array(
759 'left' => '5',
760 'width' => '100%',
761 'height' => 'auto',
762 'value' => $radio_label->nodeValue
763 )
764 ));
765 }
766 }
767 } elseif ($xml->get_node_value($element, 'data-type') == 'checkbox') {
768
769 $label = $xpath->query(".//label", $element)->item(0);
770 $check_handler = $xpath->query(".//input[contains(@class, 'et_pb_checkbox_handle')]", $element)->item(0);
771
772 $name = "";
773 if ($check_handler) {
774 $name = '%%' . $xml->get_node_value($check_handler, 'data-original_id') . '%%';
775 }
776
777 if ($label) {
778 $elements[] = $this->auto_field($element, array(
779 'type' => 'e2pdf-html',
780 'block' => true,
781 'class' => $xml->get_node_value($element, 'class'),
782 'properties' => array(
783 'top' => '20',
784 'left' => '20',
785 'right' => '20',
786 'width' => '100%',
787 'height' => 'auto',
788 'value' => $label->nodeValue,
789 )
790 ));
791 }
792
793 $fields = $xpath->query("//*[contains(@class, 'et_pb_contact_field_checkbox')]", $element);
794 foreach ($fields as $field) {
795 $checkbox_label = $xpath->query(".//label", $field)->item(0);
796 $checkbox = $xpath->query(".//input[@type='checkbox']", $field)->item(0);
797
798
799 $elements[] = $this->auto_field($field, array(
800 'type' => 'e2pdf-checkbox',
801 'class' => $xml->get_node_value($field, 'class'),
802 'properties' => array(
803 'top' => '5',
804 'width' => 'auto',
805 'height' => 'auto',
806 'value' => $name,
807 'option' => $xml->get_node_value($checkbox, 'value')
808 )
809 ));
810
811
812 if ($checkbox_label) {
813 $elements[] = $this->auto_field($checkbox, array(
814 'type' => 'e2pdf-html',
815 'float' => true,
816 'class' => $xml->get_node_value($checkbox, 'class'),
817 'properties' => array(
818 'left' => '5',
819 'width' => '100%',
820 'height' => 'auto',
821 'value' => $checkbox_label->nodeValue
822 )
823 ));
824 }
825 }
826 } else {
827
828 $label = $xpath->query(".//label", $element)->item(0);
829 $input_text = $xpath->query(".//input[@type='text']", $element)->item(0);
830 $select = $xpath->query(".//select", $element)->item(0);
831 $textarea = $xpath->query(".//textarea", $element)->item(0);
832
833 if ($label && ($input_text || $select || $textarea)) {
834 $elements[] = $this->auto_field($element, array(
835 'type' => 'e2pdf-html',
836 'block' => true,
837 'class' => $xml->get_node_value($element, 'class'),
838 'properties' => array(
839 'top' => '20',
840 'left' => '20',
841 'right' => '20',
842 'width' => '100%',
843 'height' => 'auto',
844 'value' => $label->nodeValue,
845 )
846 ));
847 }
848
849 if ($input_text) {
850 $elements[] = $this->auto_field($input_text, array(
851 'type' => 'e2pdf-input',
852 'class' => $xml->get_node_value($input_text, 'class'),
853 'properties' => array(
854 'top' => '5',
855 'width' => '100%',
856 'height' => 'auto',
857 'value' => '%%' . $xml->get_node_value($input_text, 'data-original_id') . '%%',
858 )
859 ));
860 } elseif ($select) {
861 $options_tmp = array();
862 $options = $xpath->query(".//option", $select);
863 foreach ($options as $option) {
864 $options_tmp[] = $xml->get_node_value($option, 'value');
865 }
866
867 $elements[] = $this->auto_field($select, array(
868 'type' => 'e2pdf-select',
869 'class' => $xml->get_node_value($select, 'class'),
870 'properties' => array(
871 'top' => '5',
872 'width' => '100%',
873 'height' => 'auto',
874 'options' => implode("\n", $options_tmp),
875 'value' => '%%' . $xml->get_node_value($select, 'data-original_id') . '%%',
876 )
877 ));
878 } elseif ($textarea) {
879 $elements[] = $this->auto_field($textarea, array(
880 'type' => 'e2pdf-textarea',
881 'class' => $xml->get_node_value($textarea, 'class'),
882 'properties' => array(
883 'top' => '5',
884 'width' => '100%',
885 'height' => '150',
886 'value' => '%%' . $xml->get_node_value($textarea, 'data-original_id') . '%%',
887 )
888 ));
889 }
890 }
891 }
892 }
893 }
894 }
895 }
896 }
897 }
898 }
899
900 $response['page'] = array(
901 'bottom' => '20',
902 'top' => '20',
903 'right' => '20',
904 'left' => '20'
905 );
906 $response['elements'] = $elements;
907
908 return $response;
909 }
910
911 /**
912 * Convert Field name to Value
913 * @since 0.01.34
914 *
915 * @param string $name - Field name
916 *
917 * @return bool|string - Converted value or false
918 */
919 public function auto_map($name = false) {
920 $item = $this->get('item');
921 if ($item) {
922 $post = $this->get_post($item);
923 if ($post && isset($post->post_content)) {
924 $content = $post->post_content;
925
926 if (false !== strpos($content, '[')) {
927 $shortcode_tags = array(
928 'et_pb_contact_form',
929 );
930
931 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
932 $tagnames = array_intersect($shortcode_tags, $matches[1]);
933
934 if (!empty($tagnames)) {
935
936 $pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames);
937
938 preg_match_all("/$pattern/", $content, $shortcodes);
939
940 foreach ($shortcodes[0] as $key => $shortcode_value) {
941
942 $shortcode = array();
943 $shortcode[1] = $shortcodes[1][$key];
944 $shortcode[2] = $shortcodes[2][$key];
945 $shortcode[3] = $shortcodes[3][$key];
946 $shortcode[4] = $shortcodes[4][$key];
947 $shortcode[5] = $shortcodes[5][$key];
948 $shortcode[6] = $shortcodes[6][$key];
949
950 $atts = shortcode_parse_atts($shortcode[3]);
951 if (isset($atts['admin_label']) && $atts['admin_label'] == $this->get('item')) {
952
953 $field_content = $shortcode_value;
954 $field_shortcode_tags = array(
955 'et_pb_contact_field',
956 );
957
958 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $field_content, $field_matches);
959 $field_tagnames = array_intersect($field_shortcode_tags, $field_matches[1]);
960
961 if (!empty($field_tagnames)) {
962
963 $field_pattern = $this->helper->load('shortcode')->get_shortcode_regex($field_tagnames);
964
965 preg_match_all("/$field_pattern/", $field_content, $field_shortcodes);
966
967 foreach ($field_shortcodes[0] as $field_key => $field_shortcode_value) {
968 $field_shortcode = array();
969 $field_shortcode[3] = $field_shortcodes[3][$field_key];
970 $field_atts = shortcode_parse_atts($field_shortcode[3]);
971 if (isset($field_atts['field_title']) && isset($field_atts['field_id'])) {
972 if ($field_atts['field_title'] == $name || $field_atts['field_id'] == $name) {
973 return "%%" . strtolower($field_atts['field_id']) . "%%";
974 }
975 }
976 }
977 }
978 }
979 }
980 }
981 }
982 }
983 }
984
985 return false;
986 }
987
988 /**
989 * Generate field for Auto PDF
990 *
991 * @param object $field - Formidable field object
992 * @param string $type - Field type
993 * @param array $options - Field additional options
994 *
995 * @return array - Prepared auto field
996 */
997 public function auto_field($field = false, $element = array()) {
998
999 if (!$field) {
1000 return false;
1001 }
1002
1003 if (!isset($element['block'])) {
1004 $element['block'] = false;
1005 }
1006
1007 if (!isset($element['float'])) {
1008 $element['float'] = false;
1009 }
1010
1011 $classes = array();
1012 if (isset($element['class']) && $element['class']) {
1013 $classes = explode(" ", $element['class']);
1014 unset($element['class']);
1015 }
1016
1017
1018 $float_classes = array(
1019 'et_pb_contact_field_half',
1020 );
1021 $array_intersect = array_intersect($classes, $float_classes);
1022
1023 if (!empty($array_intersect) && $element['block']) {
1024 $element['float'] = true;
1025 };
1026
1027 $primary_class = false;
1028 if (!empty($array_intersect)) {
1029 $primary_class = end($array_intersect);
1030 }
1031
1032 if ($element['block']) {
1033 switch ($primary_class) {
1034 case 'et_pb_contact_field_half':
1035 $element['width'] = '50%';
1036 break;
1037 default:
1038 break;
1039 }
1040 }
1041
1042 return $element;
1043 }
1044
1045 /**
1046 * Verify if item and dataset exists
1047 *
1048 * @return bool - item and dataset exists
1049 */
1050 public function verify() {
1051 global $wpdb;
1052 $item = $this->get('item');
1053 $dataset = $this->get('dataset');
1054
1055 if ($item && $dataset) {
1056 $condition = array(
1057 'ID' => array(
1058 'condition' => '=',
1059 'value' => $dataset,
1060 'type' => '%d'
1061 ),
1062 'extension' => array(
1063 'condition' => '=',
1064 'value' => 'divi',
1065 'type' => '%s'
1066 ),
1067 'item' => array(
1068 'condition' => '=',
1069 'value' => $item,
1070 'type' => '%s'
1071 ),
1072 );
1073
1074 $where = $this->helper->load('db')->prepare_where($condition);
1075 $entry = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . 'e2pdf_datasets' . $where['sql'] . "", $where['filter']));
1076
1077 if ($entry) {
1078 return true;
1079 }
1080 }
1081 return false;
1082 }
1083
1084 /**
1085 * Init Visual Mapper data
1086 *
1087 * @return bool|string - HTML data source for Visual Mapper
1088 */
1089 public function visual_mapper() {
1090
1091 $source = '';
1092 $html = '';
1093
1094 if ($this->get('item')) {
1095 $post = $this->get_post($this->get('item'));
1096 if ($post && isset($post->post_content)) {
1097
1098 $content = $post->post_content;
1099
1100 if (false !== strpos($content, '[')) {
1101 $shortcode_tags = array(
1102 'et_pb_contact_form',
1103 );
1104
1105 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
1106 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1107
1108 if (!empty($tagnames)) {
1109
1110 $pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames);
1111
1112 preg_match_all("/$pattern/", $content, $shortcodes);
1113
1114 foreach ($shortcodes[0] as $key => $shortcode_value) {
1115
1116 $shortcode = array();
1117 $shortcode[1] = $shortcodes[1][$key];
1118 $shortcode[2] = $shortcodes[2][$key];
1119 $shortcode[3] = $shortcodes[3][$key];
1120 $shortcode[4] = $shortcodes[4][$key];
1121 $shortcode[5] = $shortcodes[5][$key];
1122 $shortcode[6] = $shortcodes[6][$key];
1123
1124 $atts = shortcode_parse_atts($shortcode[3]);
1125 if (isset($atts['admin_label']) && $atts['admin_label'] == $this->get('item')) {
1126
1127 require_once(ET_BUILDER_DIR . 'class-et-builder-element.php');
1128 require_once(ET_BUILDER_DIR . 'functions.php');
1129 require_once(ET_BUILDER_DIR . 'ab-testing.php');
1130 require_once(ET_BUILDER_DIR . 'class-et-global-settings.php');
1131 require_once(ET_BUILDER_DIR . 'module/ContactForm.php');
1132 require_once(ET_BUILDER_DIR . 'module/ContactFormItem.php');
1133
1134 new ET_Builder_Module_Contact_Form();
1135 new ET_Builder_Module_Contact_Form_Item();
1136
1137 $source = do_shortcode($shortcode_value);
1138
1139 if ($source) {
1140 libxml_use_internal_errors(true);
1141 $dom = new DOMDocument();
1142 if (function_exists('mb_convert_encoding')) {
1143 $html = $dom->loadHTML(mb_convert_encoding($source, 'HTML-ENTITIES', 'UTF-8'));
1144 } else {
1145 $html = $dom->loadHTML('<?xml encoding="UTF-8">' . $source);
1146 }
1147 libxml_clear_errors();
1148 }
1149
1150 if (!$source) {
1151 return __('Form source is empty', 'e2pdf');
1152 } elseif (!$html) {
1153 return __('Form could not be parsed due incorrect HTML', 'e2pdf');
1154 } else {
1155
1156 $xml = $this->helper->load('xml');
1157 $xml->set('dom', $dom);
1158 $xpath = new DomXPath($dom);
1159
1160 // Replace names
1161 $fields = $xpath->query("//*[contains(@name, 'et_pb_contact_')]");
1162 foreach ($fields as $element) {
1163 $element = $xml->set_node_value($element, 'name', '%%' . $xml->get_node_value($element, 'data-original_id') . '%%');
1164 }
1165
1166 $checkboxes = $xpath->query("//*[contains(@class, 'et_pb_contact_field') and @data-type='checkbox']");
1167 foreach ($checkboxes as $element) {
1168 $check_handler = $xpath->query(".//input[contains(@class, 'et_pb_checkbox_handle')]", $element)->item(0);
1169
1170 $name = "";
1171 if ($check_handler) {
1172 $name = '%%' . $xml->get_node_value($check_handler, 'data-original_id') . '%%';
1173 }
1174
1175 $checks = $xpath->query(".//input[@type='checkbox']", $element);
1176 foreach ($checks as $check) {
1177 $check = $xml->set_node_value($check, 'name', $name);
1178 }
1179 }
1180
1181 $remove_by_class = array(
1182 'et_pb_contact_submit',
1183 'et_pb_contactform_validate_field'
1184 );
1185 foreach ($remove_by_class as $key => $class) {
1186 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
1187 foreach ($elements as $element) {
1188 $element->parentNode->removeChild($element);
1189 }
1190 }
1191
1192 $remove_parent_by_class = array(
1193 'et_pb_contact_captcha_question'
1194 );
1195 foreach ($remove_parent_by_class as $key => $class) {
1196 $elements = $xpath->query("//*[contains(@class, '{$class}')]/parent::*");
1197 foreach ($elements as $element) {
1198 $element->parentNode->removeChild($element);
1199 }
1200 }
1201 }
1202
1203 return $dom->saveHTML();
1204 }
1205 }
1206 }
1207 }
1208 }
1209 }
1210
1211 return false;
1212 }
1213
1214 public function filter_wp_mail($args) {
1215 if (isset($args['message'])) {
1216 if (false !== strpos($args['message'], '[')) {
1217 $shortcode_tags = array(
1218 'e2pdf-download',
1219 'e2pdf-save',
1220 'e2pdf-attachment',
1221 'e2pdf-adobesign'
1222 );
1223
1224 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $args['message'], $matches);
1225 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1226
1227 if (!empty($tagnames)) {
1228
1229 $pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames);
1230
1231 preg_match_all("/$pattern/", $args['message'], $shortcodes);
1232
1233 foreach ($shortcodes[0] as $key => $shortcode_value) {
1234
1235 $shortcode = array();
1236 $shortcode[1] = $shortcodes[1][$key];
1237 $shortcode[2] = $shortcodes[2][$key];
1238 $shortcode[3] = $shortcodes[3][$key];
1239 $shortcode[4] = $shortcodes[4][$key];
1240 $shortcode[5] = $shortcodes[5][$key];
1241 $shortcode[6] = $shortcodes[6][$key];
1242
1243 $atts = shortcode_parse_atts($shortcode[3]);
1244
1245 $file = false;
1246
1247 if (!isset($atts['apply'])) {
1248 $shortcode[3] .= " apply=\"true\"";
1249 }
1250
1251 if (!isset($atts['filter'])) {
1252 $shortcode[3] .= " filter=\"true\"";
1253 }
1254
1255 if (($shortcode[2] === 'e2pdf-save' && isset($atts['attachment']) && $atts['attachment'] == 'true') || $shortcode[2] === 'e2pdf-attachment') {
1256 $file = do_shortcode_tag($shortcode);
1257 if ($file) {
1258 if ($shortcode[2] != 'e2pdf-save' && !isset($atts['pdf'])) {
1259 $this->helper->add('divi_attachments', $file);
1260 }
1261 $args['attachments'][] = $file;
1262 }
1263 $args['message'] = str_replace($shortcode_value, '', $args['message']);
1264 } else {
1265 if (is_array($args['headers']) && !in_array('Content-Type: text/html; charset=UTF-8', $args['headers'])) {
1266 $args['headers'][] = 'Content-Type: text/html; charset=UTF-8';
1267 }
1268 $args['message'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $args['message']);
1269 $args['message'] = str_replace("\r\n", "<br/>", $args['message']);
1270 }
1271 }
1272 }
1273 }
1274 }
1275
1276 $wp_mail = array(
1277 'to' => $args['to'],
1278 'subject' => $args['subject'],
1279 'message' => $args['message'],
1280 'headers' => $args['headers'],
1281 'attachments' => $args['attachments'],
1282 );
1283
1284 return $wp_mail;
1285 }
1286
1287 /**
1288 * Load actions for this extension
1289 */
1290 public function load_actions() {
1291
1292 }
1293
1294 /**
1295 * Load filters for this extension
1296 */
1297 public function load_filters() {
1298 add_filter('et_pb_module_shortcode_attributes', array($this, 'filter_et_pb_module_shortcode_attributes'), 30, 5);
1299 add_filter('et_module_shortcode_output', array($this, 'filter_et_module_shortcode_output'), 30, 3);
1300 }
1301
1302 public function filter_et_pb_module_shortcode_attributes($props, $attrs, $render_slug, $address, $content) {
1303 global $wpdb;
1304
1305 if ($render_slug && $render_slug == 'et_pb_contact_form' && !empty($_POST) && $et_contact_proccess = array_search('et_contact_proccess', $_POST)) {
1306
1307 $et_pb_contact_form_num = str_replace("et_pb_contactform_submit_", "", $et_contact_proccess);
1308
1309 $et_contact_error = false;
1310 $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] : '';
1311 $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;
1312 $contact_email = '';
1313 $processed_fields_values = array();
1314
1315 $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;
1316
1317 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])) {
1318 if ('' !== $current_form_fields) {
1319 $fields_data_json = str_replace('\\', '', $current_form_fields);
1320 $fields_data_array = json_decode($fields_data_json, true);
1321
1322 // check whether captcha field is not empty
1323 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]) )) {
1324 $et_contact_error = true;
1325 }
1326
1327 // check all fields on current form and generate error message if needed
1328 if (!empty($fields_data_array)) {
1329 foreach ($fields_data_array as $index => $value) {
1330 // check all the required fields, generate error message if required field is empty
1331 $field_value = isset($_POST[$value['field_id']]) ? trim($_POST[$value['field_id']]) : '';
1332
1333 if ('required' === $value['required_mark'] && empty($field_value) && !is_numeric($field_value)) {
1334 $et_contact_error = true;
1335 continue;
1336 }
1337
1338 // additional check for email field
1339 if ('email' === $value['field_type'] && 'required' === $value['required_mark'] && !empty($field_value)) {
1340 $contact_email = isset($_POST[$value['field_id']]) ? sanitize_email($_POST[$value['field_id']]) : '';
1341
1342 if (!empty($contact_email) && !is_email($contact_email)) {
1343 $et_contact_error = true;
1344 }
1345 }
1346
1347 // prepare the array of processed field values in convenient format
1348 if (false === $et_contact_error) {
1349 $processed_fields_values[$value['original_id']]['value'] = $field_value;
1350 $processed_fields_values[$value['original_id']]['label'] = $value['field_label'];
1351 }
1352 }
1353 }
1354 } else {
1355 $et_contact_error = true;
1356 }
1357 } else {
1358 $et_contact_error = true;
1359 }
1360
1361 if (!$et_contact_error && $nonce_result) {
1362
1363 $dataset = false;
1364
1365 $success_message = '';
1366 $custom_message = '';
1367
1368 if (isset($props['success_message'])) {
1369 $success_message = str_replace(array('&#91;', '&#93;', '&quot;'), array('[', ']', '"'), $props['success_message']);
1370 }
1371
1372 if (false !== strpos($success_message, '[')) {
1373
1374 $shortcode_tags = array(
1375 'e2pdf-download',
1376 'e2pdf-save',
1377 'e2pdf-view',
1378 'e2pdf-adobesign'
1379 );
1380
1381 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $success_message, $matches);
1382 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1383
1384 if (!empty($tagnames)) {
1385
1386 $pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames);
1387
1388 preg_match_all("/$pattern/", $success_message, $shortcodes);
1389
1390 foreach ($shortcodes[0] as $key => $shortcode_value) {
1391
1392 $item = false;
1393
1394 $shortcode = array();
1395 $shortcode[1] = $shortcodes[1][$key];
1396 $shortcode[2] = $shortcodes[2][$key];
1397 $shortcode[3] = $shortcodes[3][$key];
1398 $shortcode[4] = $shortcodes[4][$key];
1399 $shortcode[5] = $shortcodes[5][$key];
1400 $shortcode[6] = $shortcodes[6][$key];
1401
1402 $atts = shortcode_parse_atts($shortcode[3]);
1403
1404 if (($shortcode[2] === 'e2pdf-save' && isset($atts['attachment']) && $atts['attachment'] == 'true') || $shortcode[2] === 'e2pdf-attachment') {
1405
1406 } else {
1407 if (!isset($atts['dataset']) && isset($atts['id'])) {
1408 $template = new Model_E2pdf_Template();
1409 $template->load($atts['id']);
1410
1411 if ($template->get('extension') === 'divi') {
1412 $item = $template->get('item');
1413
1414 if (!$dataset) {
1415 $serialized = serialize($_POST);
1416 $entry = array(
1417 'extension' => 'divi',
1418 'item' => $item,
1419 'entry' => $serialized
1420 );
1421 $wpdb->insert($wpdb->prefix . 'e2pdf_datasets', $entry);
1422 $dataset = $wpdb->insert_id;
1423 }
1424 $atts['dataset'] = $dataset;
1425 $shortcode[3] .= " dataset=\"{$dataset}\" ";
1426 }
1427 }
1428
1429 if (!isset($atts['apply'])) {
1430 $shortcode[3] .= " apply=\"true\"";
1431 }
1432
1433 $props['success_message'] = str_replace(str_replace(array('[', ']'), array('&#91;', '&#93;'), $shortcode_value), "[" . $shortcode[2] . $shortcode[3] . "]", $props['success_message']);
1434 }
1435 }
1436 }
1437 }
1438
1439 if (isset($props['custom_message'])) {
1440 $custom_message = str_replace(array('&#91;', '&#93;'), array('[', ']'), $props['custom_message']);
1441 }
1442
1443 if (false !== strpos($custom_message, '[')) {
1444 $shortcode_tags = array(
1445 'e2pdf-download',
1446 'e2pdf-save',
1447 'e2pdf-attachment',
1448 'e2pdf-adobesign'
1449 );
1450
1451 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $custom_message, $matches);
1452 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1453
1454 if (!empty($tagnames)) {
1455
1456 $pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames);
1457
1458 preg_match_all("/$pattern/", $custom_message, $shortcodes);
1459
1460 add_filter('wp_mail', array($this, 'filter_wp_mail'), 10, 2);
1461
1462 foreach ($shortcodes[0] as $key => $shortcode_value) {
1463 $item = false;
1464
1465 $shortcode = array();
1466 $shortcode[1] = $shortcodes[1][$key];
1467 $shortcode[2] = $shortcodes[2][$key];
1468 $shortcode[3] = $shortcodes[3][$key];
1469 $shortcode[4] = $shortcodes[4][$key];
1470 $shortcode[5] = $shortcodes[5][$key];
1471 $shortcode[6] = $shortcodes[6][$key];
1472
1473 $atts = shortcode_parse_atts($shortcode[3]);
1474
1475 if (!isset($atts['dataset']) && isset($atts['id'])) {
1476 $template = new Model_E2pdf_Template();
1477 $template->load($atts['id']);
1478 if ($template->get('extension') === 'divi') {
1479 $item = $template->get('item');
1480
1481 if (!$dataset) {
1482 $serialized = serialize($_POST);
1483 $entry = array(
1484 'extension' => 'divi',
1485 'item' => $item,
1486 'entry' => $serialized
1487 );
1488 $wpdb->insert($wpdb->prefix . 'e2pdf_datasets', $entry);
1489 $dataset = $wpdb->insert_id;
1490 }
1491 $atts['dataset'] = $dataset;
1492 $shortcode[3] .= " dataset=\"{$dataset}\"";
1493 }
1494 }
1495
1496 $props['custom_message'] = str_replace(str_replace(array('[', ']'), array('&#91;', '&#93;'), $shortcode_value), "[" . $shortcode[2] . $shortcode[3] . "]", $props['custom_message']);
1497 }
1498 }
1499 }
1500 }
1501 }
1502
1503 return $props;
1504 }
1505
1506 public function filter_et_module_shortcode_output($output, $render_slug, $form) {
1507
1508 if ($render_slug && $render_slug == 'et_pb_contact_form' && !empty($_POST) && $et_contact_proccess = array_search('et_contact_proccess', $_POST)) {
1509
1510 $et_pb_contact_form_num = str_replace("et_pb_contactform_submit_", "", $et_contact_proccess);
1511
1512 $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;
1513
1514 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])) {
1515
1516 $dataset = false;
1517
1518 $success_message = '';
1519 $custom_message = '';
1520
1521 if (isset($form->props['success_message'])) {
1522 $success_message = str_replace(array('&#91;', '&#93;', '&quot;'), array('[', ']', '"'), $form->props['success_message']);
1523 }
1524
1525 if (false !== strpos($success_message, '[')) {
1526 $shortcode_tags = array(
1527 'e2pdf-download',
1528 'e2pdf-save',
1529 'e2pdf-view',
1530 'e2pdf-adobesign'
1531 );
1532
1533 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $success_message, $matches);
1534 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1535
1536 if (!empty($tagnames)) {
1537
1538 $pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames);
1539
1540 preg_match_all("/$pattern/", $success_message, $shortcodes);
1541
1542 foreach ($shortcodes[0] as $key => $shortcode_value) {
1543
1544 $shortcode = array();
1545 $shortcode[1] = $shortcodes[1][$key];
1546 $shortcode[2] = $shortcodes[2][$key];
1547 $shortcode[3] = $shortcodes[3][$key];
1548 $shortcode[4] = $shortcodes[4][$key];
1549 $shortcode[5] = $shortcodes[5][$key];
1550 $shortcode[6] = $shortcodes[6][$key];
1551
1552 $output = str_replace(str_replace(array('"'), array('&quot;'), $shortcode_value), do_shortcode_tag($shortcode), $output);
1553 }
1554 }
1555 }
1556 }
1557
1558 remove_filter('wp_mail', array($this, 'filter_wp_mail'), 10);
1559
1560 $files = $this->helper->get('divi_attachments');
1561 if (is_array($files) && !empty($files)) {
1562 foreach ($files as $key => $file) {
1563 $this->helper->delete_dir(dirname($file) . '/');
1564 }
1565 $this->helper->deset('divi_attachments');
1566 }
1567 }
1568
1569 return $output;
1570 }
1571
1572 /**
1573 * Delete dataset for template
1574 *
1575 * @param int $template_id - Template ID
1576 * @param int $dataset - Dataset ID
1577 *
1578 * @return bool - Result of removing items
1579 */
1580 public function delete_item($template_id = false, $dataset = false) {
1581 global $wpdb;
1582
1583 $template = new Model_E2pdf_Template();
1584 if ($template_id && $dataset && $template->load($template_id)) {
1585 if ($template->get('extension') === 'divi' && $template->get('item')) {
1586
1587 $item = $template->get('item');
1588
1589 $where = array(
1590 'ID' => $dataset,
1591 'item' => $item,
1592 'extension' => 'divi'
1593 );
1594 $wpdb->delete($wpdb->prefix . 'e2pdf_datasets', $where);
1595 return true;
1596 }
1597 }
1598
1599 return false;
1600 }
1601
1602 /**
1603 * Delete all datasets for Template
1604 *
1605 * @param int $template_id - Template ID
1606 *
1607 * @return bool - Result of removing items
1608 */
1609 public function delete_items($template_id = false) {
1610 global $wpdb;
1611
1612 $template = new Model_E2pdf_Template();
1613
1614 if ($template_id && $template->load($template_id)) {
1615 if ($template->get('extension') === 'divi' && $template->get('item')) {
1616
1617 $item = $template->get('item');
1618
1619 $where = array(
1620 'item' => $item,
1621 'extension' => 'divi'
1622 );
1623 $wpdb->delete($wpdb->prefix . 'e2pdf_datasets', $where);
1624 return true;
1625 }
1626 }
1627
1628 return false;
1629 }
1630
1631 /**
1632 * Get styles for generating Map Field function
1633 *
1634 * @return array - List of css files to load
1635 */
1636 public function styles() {
1637 $styles = array(
1638 plugins_url('css/extension/divi.css?v=' . time(), $this->helper->get('plugin_file_path'))
1639 );
1640 return $styles;
1641 }
1642
1643 }
1644