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

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