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

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