PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.49
E2Pdf – Export Pdf Tool for WordPress v1.32.49
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-wpcf7.php

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

1,530 lines 68.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * File: /extension/e2pdf-wpcf7.php
5 *
6 * @package E2Pdf
7 * @license GPLv3
8 * @link https://e2pdf.com
9 */
10 if (!defined('ABSPATH')) {
11 die('Access denied.');
12 }
13
14 class Extension_E2pdf_Wpcf7 extends Model_E2pdf_Model {
15
16 private $options;
17 private $info = array(
18 'key' => 'wpcf7',
19 'title' => 'Contact Form 7',
20 );
21
22 // info
23 public function info($key = false) {
24 if ($key && isset($this->info[$key])) {
25 return $this->info[$key];
26 } else {
27 return array(
28 $this->info['key'] => $this->info['title'],
29 );
30 }
31 }
32
33 // active
34 public function active() {
35 if (defined('E2PDF_WPCF7_EXTENSION') || $this->helper->load('extension')->is_plugin_active('contact-form-7/wp-contact-form-7.php')) {
36 return true;
37 }
38 return false;
39 }
40
41 // set
42 public function set($key, $value) {
43 if (!isset($this->options)) {
44 $this->options = new stdClass();
45 }
46 $this->options->$key = $value;
47 switch ($key) {
48 case 'item':
49 $this->set('cached_form', false);
50 if ($this->get('item') && class_exists('WPCF7_ContactForm')) {
51 $form = WPCF7_ContactForm::get_instance($this->get('item'));
52 if ($form) {
53 $this->set('cached_form', $form);
54 }
55 }
56 break;
57 case 'dataset':
58 global $wpdb;
59 $this->set('cached_submission', false);
60 $this->set('cached_entry', array());
61 if ($this->get('cached_form') && $this->get('dataset') && $this->get_storing_engine() !== false) {
62 if ($this->get_storing_engine() == '1') {
63 $vxcf_form = new vxcf_form();
64 $entry = $vxcf_form::get_data_object()->get_lead($this->get('dataset'));
65 if ($entry) {
66 $posted_data = array();
67 $lead = $vxcf_form::get_data_object()->attach_lead_detail($entry);
68 foreach ($lead['detail'] as $field_key => $field_value) {
69 if ($field_value) {
70 if (0 === strpos($field_key, 'file-')) {
71 if (is_serialized($field_value)) {
72 $paths = $this->helper->load('convert')->unserialize(trim($field_value));
73 } else {
74 $paths = array();
75 }
76 if (is_array($paths)) {
77 $urls = array_map(
78 function ($uploaded_file) {
79 $vxcf_form = new vxcf_form();
80 $upload = $vxcf_form::get_upload_dir();
81 return $upload['url'] . $uploaded_file;
82 }, $paths
83 );
84 } else {
85 $urls = array();
86 }
87 $posted_data[$field_key] = $urls;
88 } else {
89 if (is_serialized($field_value)) {
90 $posted_data[$field_key] = $this->helper->load('convert')->unserialize(trim($field_value));
91 } else {
92 $posted_data[$field_key] = $field_value;
93 }
94 }
95 } else {
96 $posted_data[$field_key] = '';
97 }
98 }
99
100 $cached_entry = array(
101 'posted_data' => $posted_data,
102 'uploaded_files' => array(),
103 'meta' => array(
104 'timestamp' => !empty($lead['created']) ? strtotime($lead['created']) : '',
105 'remote_ip' => !empty($lead['ip']) ? $lead['ip'] : '',
106 'remote_port' => '',
107 'user_agent' => '',
108 'url' => !empty($lead['url']) ? $lead['url'] : '',
109 'unit_tag' => '',
110 'container_post_id' => '',
111 'current_user_id' => !empty($lead['user_id']) ? $lead['user_id'] : '0',
112 'do_not_store' => '',
113 ),
114 );
115 $this->set('cached_entry', $cached_entry);
116 }
117 } elseif ($this->get_storing_engine() == '2') {
118 $condition = array(
119 'form_id' => array(
120 'condition' => '=',
121 'value' => $this->get('dataset'),
122 'type' => '%d',
123 ),
124 );
125 $where = $this->helper->load('db')->prepare_where($condition);
126 $cfdb = apply_filters('cfdb7_database', $wpdb);
127 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
128 $entry = $wpdb->get_row($wpdb->prepare('SELECT * FROM `' . $cfdb->prefix . 'db7_forms`' . $where['sql'] . '', $where['filter']));
129 if ($entry) {
130 $form_value = $this->helper->load('convert')->unserialize($entry->form_value);
131 $posted_data = array();
132 $upload_dir = wp_upload_dir();
133 $cfdb7_dir_url = $upload_dir['baseurl'] . '/cfdb7_uploads';
134 foreach ($form_value as $field_key => $field_value) {
135 $field_value = str_replace(
136 array('&quot;', '&#039;', '&#047;', '&#092;'),
137 array('"', "'", '/', '\\'), $field_value
138 );
139
140 if (strpos($field_key, 'cfdb7_file') !== false) {
141 $posted_data[substr($field_key, 0, -10)] = empty($field_value) ? '' : $cfdb7_dir_url . '/' . $field_value;
142 continue;
143 }
144 if (is_array($field_value)) {
145 $posted_data[$field_key] = implode(', ', $field_value);
146 continue;
147 }
148 $posted_data[$field_key] = $field_value;
149 }
150 $cached_entry = array(
151 'posted_data' => $posted_data,
152 'uploaded_files' => array(),
153 'meta' => array(
154 'timestamp' => strtotime($entry->form_date),
155 'remote_ip' => '',
156 'remote_port' => '',
157 'user_agent' => '',
158 'url' => '',
159 'unit_tag' => '',
160 'container_post_id' => '',
161 'current_user_id' => '0',
162 'do_not_store' => '',
163 ),
164 );
165 $this->set('cached_entry', $cached_entry);
166 }
167 } elseif ($this->get_storing_engine() == '3') {
168 $condition = array(
169 'cf7_id' => array(
170 'condition' => '=',
171 'value' => $this->get('item'),
172 'type' => '%d',
173 ),
174 'data_id' => array(
175 'condition' => '=',
176 'value' => $this->get('dataset'),
177 'type' => '%d',
178 ),
179 );
180 $where = $this->helper->load('db')->prepare_where($condition);
181 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
182 $entry = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . VSZ_CF7_DATA_ENTRY_TABLE_NAME . '`' . $where['sql'] . '', $where['filter']));
183
184 if (!empty($entry)) {
185 $posted_data = array();
186 foreach ($entry as $k => $v) {
187 if (false !== strpos($v->name, 'checkbox')) {
188 if ($v->value) {
189 $checkboxes = explode(PHP_EOL, stripslashes($v->value));
190 } else {
191 $checkboxes = array();
192 }
193 $posted_data[$v->name] = implode(', ', $checkboxes);
194 } else {
195 $posted_data[$v->name] = stripslashes($v->value);
196 }
197 }
198 $cached_entry = array(
199 'posted_data' => $posted_data,
200 'uploaded_files' => array(),
201 'meta' => array(
202 'timestamp' => isset($posted_data['submit_time']) ? strtotime($posted_data['submit_time']) : '',
203 'remote_ip' => isset($posted_data['submit_ip']) ? $posted_data['submit_ip'] : '',
204 'remote_port' => '',
205 'user_agent' => '',
206 'url' => '',
207 'unit_tag' => '',
208 'container_post_id' => '',
209 'current_user_id' => '0',
210 'do_not_store' => '',
211 ),
212 );
213 $this->set('cached_entry', $cached_entry);
214 }
215 } else {
216 $entry = new Model_E2pdf_Dataset();
217 if ($entry->load($this->get('dataset'), $this->get('item'), 'wpcf7')) {
218 $this->set('cached_entry', $entry->get('entry'));
219 }
220 }
221
222 if ($this->get('cached_entry')) {
223 if (WPCF7_Submission::get_instance() == null) {
224
225 // Digital Signature For Contact Form 7 PHP Warning Fix
226 remove_filter('wpcf7_validate_signature', 'wpcf7_signature_validation_filter', 10, 2);
227 remove_filter('wpcf7_validate_signature*', 'wpcf7_signature_validation_filter', 10, 2);
228
229 $form = WPCF7_ContactForm::get_instance($this->get('item'));
230 add_action('wpcf7_before_send_mail', array($this, 'action_wpcf7_before_send_mail_abort'), 98, 2);
231 $submission = WPCF7_Submission::get_instance($form);
232 remove_action('wpcf7_before_send_mail', array($this, 'action_wpcf7_before_send_mail_abort'), 98, 2);
233 } else {
234 $submission = WPCF7_Submission::get_instance();
235 }
236
237 if (class_exists('ReflectionProperty')) {
238 $reflection = new ReflectionProperty(get_class($submission), 'posted_data');
239 $reflection->setAccessible(true);
240 $reflection->setValue($submission, isset($this->get('cached_entry')['posted_data']) ? $this->get('cached_entry')['posted_data'] : array());
241
242 $reflection = new ReflectionProperty(get_class($submission), 'uploaded_files');
243 $reflection->setAccessible(true);
244 $reflection->setValue($submission, isset($this->get('cached_entry')['uploaded_files']) ? $this->get('cached_entry')['uploaded_files'] : array());
245
246 // Contact Form Warning fix on $submission->__destruct()
247 if (defined('WPCF7_VERSION') && WPCF7_VERSION >= '5.8.6' && isset($this->get('cached_entry')['uploaded_files'])) {
248 foreach ((array) $this->get('cached_entry')['uploaded_files'] as $file_path) {
249 $paths = (array) $file_path;
250 foreach ($paths as $path) {
251 // phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
252 if (!@file_exists($path)) {
253 @mkdir(dirname($path));
254 }
255 // phpcs:enable
256 }
257 }
258 }
259
260 $reflection = new ReflectionProperty(get_class($submission), 'meta');
261 $reflection->setAccessible(true);
262 $reflection->setValue($submission, isset($this->get('cached_entry')['meta']) ? $this->get('cached_entry')['meta'] : array());
263 $this->set('cached_submission', $submission);
264 }
265 }
266 }
267 break;
268 default:
269 break;
270 }
271 return true;
272 }
273
274 // get
275 public function get($key) {
276 if (isset($this->options->$key)) {
277 $value = $this->options->$key;
278 } else {
279 switch ($key) {
280 case 'args':
281 case 'cached_entry':
282 $value = array();
283 break;
284 default:
285 $value = false;
286 break;
287 }
288 }
289 return $value;
290 }
291
292 // load actions
293 public function load_actions() {
294 add_action('wpcf7_before_send_mail', array($this, 'action_wpcf7_before_send_mail'), 99, 2);
295 add_action('wpcf7_mail_sent', array($this, 'action_wpcf7_mail_sent'));
296 add_action('cfdb7_after_save_data', array($this, 'action_cfdb7_after_save_data'));
297 add_action('vsz_cf7_after_insert_db', array($this, 'action_vsz_cf7_after_insert_db'), 10, 3);
298 }
299
300 // load filters
301 public function load_filters() {
302 add_filter('e2pdf_model_options_get_options_options', array($this, 'filter_e2pdf_model_options_get_options_options'));
303 add_filter('vxcf_after_saving_addons', array($this, 'filter_vxcf_after_saving_addons'), 10, 4);
304 }
305
306 // items
307 public function items() {
308 $items = array();
309 if (class_exists('WPCF7_ContactForm')) {
310 $forms = WPCF7_ContactForm::find();
311 if ($forms) {
312 foreach ($forms as $key => $form) {
313 $items[] = $this->item($form->id);
314 }
315 }
316 }
317 return $items;
318 }
319
320 // item
321 public function item($item_id = false) {
322 $item_id = (int) $item_id;
323 if (!$item_id && $this->get('item')) {
324 $item_id = $this->get('item');
325 }
326 $form = false;
327 if (class_exists('WPCF7_ContactForm')) {
328 $form = WPCF7_ContactForm::get_instance($item_id);
329 }
330 $item = new stdClass();
331 if ($form) {
332 $item->id = (string) $form->id();
333 $item->url = $this->helper->get_url(
334 array(
335 'page' => 'wpcf7',
336 'post' => $item_id,
337 'action' => 'edit',
338 )
339 );
340 $item->name = $form->title();
341 } else {
342 $item->id = '';
343 $item->url = '';
344 $item->name = '';
345 }
346 return $item;
347 }
348
349 // datasets
350 public function datasets($item_id = false, $name = false) {
351 global $wpdb;
352 $datasets = array();
353 if ($item_id) {
354 if ($this->get_storing_engine() == '1') {
355 $vxcf_form = new vxcf_form();
356 $entries = $vxcf_form::get_data_object()->get_entries('cf_' . $item_id, 'all');
357 if (!empty($entries['result'])) {
358 $this->set('item', $item_id);
359 foreach ($entries['result'] as $key => $entry) {
360 $this->set('dataset', $entry['id']);
361 $entry_title = $this->render($name);
362 if (!$entry_title) {
363 $entry_title = $entry['id'];
364 }
365 $datasets[] = array(
366 'key' => $entry['id'],
367 'value' => $entry_title,
368 );
369 }
370 }
371 } elseif ($this->get_storing_engine() == '2') {
372 $condition = array(
373 'form_post_id' => array(
374 'condition' => '=',
375 'value' => $item_id,
376 'type' => '%s',
377 ),
378 );
379 $order_condition = array(
380 'orderby' => 'form_id',
381 'order' => 'desc',
382 );
383 $where = $this->helper->load('db')->prepare_where($condition);
384 $orderby = $this->helper->load('db')->prepare_orderby($order_condition);
385
386 $cfdb = apply_filters('cfdb7_database', $wpdb);
387 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
388 $entries = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . $cfdb->prefix . 'db7_forms`' . $where['sql'] . $orderby . '', $where['filter']));
389
390 if ($entries) {
391 $this->set('item', $item_id);
392 foreach ($entries as $key => $entry) {
393 $this->set('dataset', $entry->form_id);
394 $entry_title = $this->render($name);
395 if (!$entry_title) {
396 $entry_title = $entry->form_id;
397 }
398 $datasets[] = array(
399 'key' => $entry->form_id,
400 'value' => $entry_title,
401 );
402 }
403 }
404 } elseif ($this->get_storing_engine() == '3') {
405 $condition = array(
406 'cf7_id' => array(
407 'condition' => '=',
408 'value' => $item_id,
409 'type' => '%s',
410 ),
411 );
412 $order_condition = array(
413 'orderby' => 'data_id',
414 'order' => 'desc',
415 );
416 $where = $this->helper->load('db')->prepare_where($condition);
417 $orderby = $this->helper->load('db')->prepare_orderby($order_condition);
418 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
419 $entries = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . VSZ_CF7_DATA_ENTRY_TABLE_NAME . '`' . $where['sql'] . ' GROUP BY data_id' . $orderby . '', $where['filter']));
420
421 if ($entries) {
422 $this->set('item', $item_id);
423 foreach ($entries as $key => $entry) {
424 $this->set('dataset', $entry->data_id);
425 $entry_title = $this->render($name);
426 if (!$entry_title) {
427 $entry_title = $entry->data_id;
428 }
429 $datasets[] = array(
430 'key' => $entry->data_id,
431 'value' => $entry_title,
432 );
433 }
434 }
435 } else {
436 $condition = array(
437 'extension' => array(
438 'condition' => '=',
439 'value' => 'wpcf7',
440 'type' => '%s',
441 ),
442 'item' => array(
443 'condition' => '=',
444 'value' => $item_id,
445 'type' => '%s',
446 ),
447 );
448 $order_condition = array(
449 'orderby' => 'ID',
450 'order' => 'desc',
451 );
452 $where = $this->helper->load('db')->prepare_where($condition);
453 $orderby = $this->helper->load('db')->prepare_orderby($order_condition);
454 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
455 $entries = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . $wpdb->prefix . 'e2pdf_datasets`' . $where['sql'] . $orderby . '', $where['filter']));
456 if ($entries) {
457 $this->set('item', $item_id);
458 foreach ($entries as $key => $entry) {
459 $this->set('dataset', $entry->ID);
460 $entry_title = $this->render($name);
461 if (!$entry_title) {
462 $entry_title = $entry->ID;
463 }
464 $datasets[] = array(
465 'key' => $entry->ID,
466 'value' => $entry_title,
467 );
468 }
469 }
470 }
471 }
472 return $datasets;
473 }
474
475 // dataset actions
476 public function get_dataset_actions($dataset_id = false) {
477 global $wpdb;
478 $dataset_id = (int) $dataset_id;
479 if (!$dataset_id) {
480 return;
481 }
482 $data = new stdClass();
483 if ($this->get_storing_engine() == '1') {
484 $data->view = $this->helper->get_url(
485 array(
486 'page' => 'vxcf_leads',
487 'tab' => 'entries',
488 'id' => $dataset_id,
489 )
490 );
491 $data->delete = false;
492 } elseif ($this->get_storing_engine() == '2') {
493 $condition = array(
494 'form_id' => array(
495 'condition' => '=',
496 'value' => $dataset_id,
497 'type' => '%d',
498 ),
499 );
500 $where = $this->helper->load('db')->prepare_where($condition);
501 $cfdb = apply_filters('cfdb7_database', $wpdb);
502 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
503 $entry = $wpdb->get_row($wpdb->prepare('SELECT * FROM `' . $cfdb->prefix . 'db7_forms`' . $where['sql'] . '', $where['filter']));
504 $data->view = $this->helper->get_url(
505 array(
506 'page' => 'cfdb7-list.php',
507 'fid' => $entry->form_post_id,
508 'ufid' => $dataset_id,
509 )
510 );
511 $data->delete = false;
512 } elseif ($this->get_storing_engine() == '3') {
513 $data->view = false;
514 $data->delete = false;
515 } else {
516 $data->view = false;
517 $data->delete = true;
518 }
519 return $data;
520 }
521
522 // template actions
523 public function get_template_actions($template = false) {
524 $template = (int) $template;
525 if (!$template) {
526 return;
527 }
528 $actions = new stdClass();
529 if ($this->get_storing_engine() == '0') {
530 $actions->delete = true;
531 } else {
532 $actions->delete = false;
533 }
534 return $actions;
535 }
536
537 // render
538 public function render($value, $field = array(), $convert_shortcodes = true, $raw = false) {
539 $value = $this->render_shortcodes($value, $field);
540 if (!$raw) {
541 $value = $this->strip_shortcodes($value);
542 $value = $this->convert_shortcodes($value, $convert_shortcodes, isset($field['type']) && $field['type'] == 'e2pdf-html' ? true : false);
543 $value = $this->helper->load('field')->render_checkbox($value, $this, $field);
544 }
545 return $value;
546 }
547
548 // render shortcodes
549 public function render_shortcodes($value, $field = array()) {
550
551 $element_id = isset($field['element_id']) ? $field['element_id'] : false;
552
553 if ($this->verify()) {
554 if (false !== strpos($value, '[')) {
555 $value = $this->helper->load('field')->pre_shortcodes($value, $this, $field);
556 $value = $this->helper->load('field')->inner_shortcodes($value, $this, $field);
557 $value = $this->helper->load('field')->wrapper_shortcodes($value, $this, $field);
558 }
559 $value = $this->helper->load('field')->do_shortcodes($value, $this, $field);
560
561 add_filter('wpcf7_mail_tag_replaced_file', array($this, 'filter_wpcf7_file_mail_tag'), 99, 4);
562 add_filter('wpcf7_mail_tag_replaced_file*', array($this, 'filter_wpcf7_file_mail_tag'), 99, 4);
563
564 /**
565 * Ultimate Addons for Contact Form 7 Digital Signature
566 * https://wordpress.org/plugins/ultimate-addons-for-contact-form-7/
567 */
568 add_filter('wpcf7_mail_tag_replaced_uacf7_signature', array($this, 'filter_wpcf7_file_mail_tag'), 99, 4);
569 add_filter('wpcf7_mail_tag_replaced_uacf7_signature*', array($this, 'filter_wpcf7_file_mail_tag'), 99, 4);
570
571 if ($this->get('cached_submission')) {
572 $value = htmlentities($value, ENT_NOQUOTES);
573 $value = $this->get('cached_submission')->get_contact_form()->filter_message($value);
574 $value = html_entity_decode($value);
575 }
576
577 remove_filter('wpcf7_mail_tag_replaced_file', array($this, 'filter_wpcf7_file_mail_tag'), 99);
578 remove_filter('wpcf7_mail_tag_replaced_file*', array($this, 'filter_wpcf7_file_mail_tag'), 99);
579 remove_filter('wpcf7_mail_tag_replaced_uacf7_signature', array($this, 'filter_wpcf7_file_mail_tag'), 99);
580 remove_filter('wpcf7_mail_tag_replaced_uacf7_signature*', array($this, 'filter_wpcf7_file_mail_tag'), 99);
581
582 $value = $this->helper->load('field')->render(
583 apply_filters('e2pdf_extension_render_shortcodes_pre_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false),
584 $this,
585 $field
586 );
587 }
588 return apply_filters(
589 'e2pdf_extension_render_shortcodes_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false
590 );
591 }
592
593 // convert shortcodes
594 public function convert_shortcodes($value, $to = false, $html = false) {
595 if ($value) {
596 if ($to) {
597 $value = str_replace('&#91;', '[', $value);
598 if (!$html) {
599 $value = wp_specialchars_decode($value, ENT_QUOTES);
600 }
601 } else {
602 $value = str_replace('[', '&#91;', $value);
603 }
604 }
605 return $value;
606 }
607
608 // strip shortcodes
609 public function strip_shortcodes($value) {
610 $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', '', $value);
611 return $value;
612 }
613
614 // verify
615 public function verify() {
616 if ($this->get('cached_entry')) {
617 return true;
618 }
619 return false;
620 }
621
622 // visual mapper
623 public function visual_mapper() {
624
625 $html = '';
626 $source = '';
627
628 if ($this->get('item') && class_exists('WPCF7_ContactForm')) {
629 $form = WPCF7_ContactForm::get_instance($this->get('item'));
630 if ($form) {
631 $source = $form->form_html();
632 if ($source) {
633 $dom = new DOMDocument();
634 $html = $this->helper->load('convert')->load_html($source, $dom, true);
635 }
636 }
637 if (!$source) {
638 return '<div class="e2pdf-vm-error">' . __("The form source is empty or doesn't exist", 'e2pdf') . '</div>';
639 } elseif (!$html) {
640 return '<div class="e2pdf-vm-error">' . __('The form could not be parsed due the incorrect HTML', 'e2pdf') . '</div>';
641 } else {
642
643 $xml = $this->helper->load('xml');
644 $xpath = new DomXPath($dom);
645
646 // remove by name
647 $remove_by_name = array(
648 '_wpcf7',
649 '_wpcf7_version',
650 '_wpcf7_locale',
651 '_wpcf7_unit_tag',
652 '_wpcf7_container_post',
653 '_wpcf7_posted_data_hash',
654 );
655 foreach ($remove_by_name as $key => $name) {
656 $elements = $xpath->query('//*[@name="' . $name . '"]');
657 foreach ($elements as $element) {
658 $element->parentNode->removeChild($element);
659 }
660 }
661
662 // remove by class
663 $remove_by_class = array(
664 'dscf7_signature_inner',
665 'as-signature-clear',
666 );
667 foreach ($remove_by_class as $key => $class) {
668 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
669 foreach ($elements as $element) {
670 $element->parentNode->removeChild($element);
671 }
672 }
673
674 /*
675 * Modify Digital Signature
676 * https://wordpress.org/plugins/digital-signature-for-contact-form-7/
677 */
678 $signatures = $xpath->query("//*[contains(@class, 'wpcf7-signaturewpcf7-validates-as-signaturedscf7-signature')]");
679 foreach ($signatures as $element) {
680 $xml->set_node_value($element, 'type', 'text');
681 $xml->set_node_value($element, 'value', __('Signature', 'e2pdf'));
682 }
683
684 /*
685 * Digital Signature Addon for Contact Form 7
686 * https://wordpress.org/plugins/digital-signature-addon-for-contact-form-7/
687 * The plugin is not working due to incorrect JavaScript events
688 */
689 $signatures = $xpath->query("//*[contains(@class, 'wpcf7-as_signature')]");
690 foreach ($signatures as $element) {
691 $xml->set_node_value($element, 'type', 'text');
692 $xml->set_node_value($element, 'value', __('Signature', 'e2pdf'));
693 }
694
695
696 $acceptances = $xpath->query("//*[contains(@class, 'wpcf7-acceptance')]");
697 foreach ($acceptances as $acceptance) {
698 $element = $xpath->query('.//input', $acceptance)->item(0);
699 if ($element) {
700 $xml->set_node_value($element, 'value', 'Consented');
701 }
702 }
703
704 /*
705 * Drag and Drop Multiple File Upload – Contact Form 7
706 * https://wordpress.org/plugins/drag-and-drop-multiple-file-upload-contact-form-7/
707 */
708 $drag_and_drops = $xpath->query("//*[contains(@class, 'wpcf7-drag-n-drop-file')]");
709 foreach ($drag_and_drops as $element) {
710 $xml->set_node_value($element, 'name', $xml->get_node_value($element, 'data-name'));
711 }
712
713 $inputs = $xpath->query('//input|//textarea|//select');
714 foreach ($inputs as $element) {
715 if ($xml->get_node_value($element, 'type') == 'checkbox') {
716 $xml->set_node_value($element, 'name', str_replace('[]', '', $xml->get_node_value($element, 'name')));
717 }
718 $xml->set_node_value($element, 'name', '[' . $xml->get_node_value($element, 'name') . ']');
719 }
720
721 // remove unecessary elements
722 $submit_buttons = $xpath->query("//input[@type='submit']");
723 foreach ($submit_buttons as $element) {
724 $element->parentNode->removeChild($element);
725 }
726 if (defined('LIBXML_HTML_NOIMPLIED') && defined('LIBXML_HTML_NODEFDTD')) {
727 return str_replace(array('<html>', '</html>'), '', $dom->saveHTML());
728 } else {
729 return $dom->saveHTML();
730 }
731 }
732 }
733 return false;
734 }
735
736 // auto
737 public function auto() {
738
739 $response = array();
740 $elements = array();
741
742 if ($this->get('cached_form')) {
743 $source = $this->get('cached_form')->prop('form');
744 foreach ((array) $this->get('cached_form')->scan_form_tags() as $key => $field) {
745 $label = false;
746 preg_match_all('/<label(?:[ \t\n]+.*?)?>(((?!<\/label>).)*)\[' . str_replace('*', '\*', $field->type) . ' ' . $field->name . '(\s|\]).*?<\/label>/s', $source, $matches);
747 if (!empty($matches[1][0])) {
748 $label = trim($matches[1][0]);
749 } else {
750 preg_match_all('/<label(?:[ \t\n]+.*?)?>(((?!<\/label>).)*)<\/label>(?:[\n\r\s]+)\[' . str_replace('*', '\*', $field->type) . ' ' . $field->name . '(\s|\])/', $source, $matches);
751 if (!empty($matches[1][0])) {
752 $label = trim($matches[1][0]);
753 }
754 }
755 switch ($field->type) {
756 case 'text':
757 case 'text*':
758 case 'email':
759 case 'email*':
760 case 'url':
761 case 'tel':
762 case 'number':
763 case 'date':
764 $elements[] = $this->auto_field(
765 $field,
766 array(
767 'type' => 'e2pdf-html',
768 'block' => true,
769 'properties' => array(
770 'top' => '20',
771 'left' => '20',
772 'right' => '20',
773 'width' => '100%',
774 'height' => 'auto',
775 'value' => $label ? $label : $field->name,
776 ),
777 )
778 );
779 $elements[] = $this->auto_field(
780 $field,
781 array(
782 'type' => 'e2pdf-input',
783 'properties' => array(
784 'top' => '5',
785 'width' => '100%',
786 'height' => 'auto',
787 'value' => '[' . $field->name . ']',
788 ),
789 )
790 );
791 break;
792 case 'signature':
793 $elements[] = $this->auto_field(
794 $field,
795 array(
796 'type' => 'e2pdf-html',
797 'block' => true,
798 'properties' => array(
799 'top' => '20',
800 'left' => '20',
801 'right' => '20',
802 'width' => '100%',
803 'height' => 'auto',
804 'value' => $label ? $label : $field->name,
805 ),
806 )
807 );
808 $elements[] = $this->auto_field(
809 $field,
810 array(
811 'type' => 'e2pdf-signature',
812 'properties' => array(
813 'top' => '5',
814 'width' => '100%',
815 'height' => '150',
816 'dimension' => '1',
817 'block_dimension' => '1',
818 'value' => '[' . $field->name . ']',
819 ),
820 )
821 );
822 break;
823 case 'file':
824 case 'mfile':
825 case 'textarea':
826 $elements[] = $this->auto_field(
827 $field,
828 array(
829 'type' => 'e2pdf-html',
830 'block' => true,
831 'properties' => array(
832 'top' => '20',
833 'left' => '20',
834 'right' => '20',
835 'width' => '100%',
836 'height' => 'auto',
837 'value' => $label ? $label : $field->name,
838 'text_auto_font_size' => $field->type == 'textarea' ? '1' : '0',
839 ),
840 )
841 );
842 $elements[] = $this->auto_field(
843 $field,
844 array(
845 'type' => 'e2pdf-textarea',
846 'properties' => array(
847 'top' => '5',
848 'width' => '100%',
849 'height' => '150',
850 'value' => '[' . $field->name . ']',
851 ),
852 )
853 );
854 break;
855 case 'select':
856 $elements[] = $this->auto_field(
857 $field,
858 array(
859 'type' => 'e2pdf-html',
860 'block' => true,
861 'properties' => array(
862 'top' => '20',
863 'left' => '20',
864 'right' => '20',
865 'width' => '100%',
866 'height' => 'auto',
867 'value' => $label ? $label : $field->name,
868 ),
869 )
870 );
871 $elements[] = $this->auto_field(
872 $field,
873 array(
874 'type' => 'e2pdf-select',
875 'properties' => array(
876 'top' => '5',
877 'width' => '100%',
878 'height' => 'auto',
879 'options' => implode("\n", $field->values),
880 'value' => '[' . $field->name . ']',
881 'height' => 'auto',
882 ),
883 )
884 );
885 break;
886 case 'checkbox':
887 $elements[] = $this->auto_field(
888 $field,
889 array(
890 'type' => 'e2pdf-html',
891 'block' => true,
892 'properties' => array(
893 'top' => '20',
894 'left' => '20',
895 'right' => '20',
896 'width' => '100%',
897 'height' => 'auto',
898 'value' => $label ? $label : $field->name,
899 ),
900 )
901 );
902 foreach ($field->values as $checkbox) {
903 $elements[] = $this->auto_field(
904 $field,
905 array(
906 'type' => 'e2pdf-checkbox',
907 'properties' => array(
908 'top' => '5',
909 'width' => 'auto',
910 'height' => 'auto',
911 'value' => '[' . $field->name . ']',
912 'option' => $checkbox,
913 ),
914 )
915 );
916 $elements[] = $this->auto_field(
917 $field,
918 array(
919 'type' => 'e2pdf-html',
920 'float' => true,
921 'properties' => array(
922 'left' => '5',
923 'width' => '100%',
924 'height' => 'auto',
925 'value' => $checkbox,
926 ),
927 )
928 );
929 }
930 break;
931 case 'radio':
932 $elements[] = $this->auto_field(
933 $field,
934 array(
935 'type' => 'e2pdf-html',
936 'block' => true,
937 'properties' => array(
938 'top' => '20',
939 'left' => '20',
940 'right' => '20',
941 'width' => '100%',
942 'height' => 'auto',
943 'value' => $label ? $label : $field->name,
944 ),
945 )
946 );
947 foreach ($field->values as $radio) {
948 $elements[] = $this->auto_field(
949 $field,
950 array(
951 'type' => 'e2pdf-radio',
952 'properties' => array(
953 'top' => '5',
954 'width' => 'auto',
955 'height' => 'auto',
956 'value' => '[' . $field->name . ']',
957 'option' => $radio,
958 'group' => '[' . $field->name . ']',
959 ),
960 )
961 );
962 $elements[] = $this->auto_field(
963 $field,
964 array(
965 'type' => 'e2pdf-html',
966 'float' => true,
967 'properties' => array(
968 'left' => '5',
969 'width' => '100%',
970 'height' => 'auto',
971 'value' => $radio,
972 ),
973 )
974 );
975 }
976 break;
977 case 'acceptance':
978 $elements[] = $this->auto_field(
979 $field,
980 array(
981 'type' => 'e2pdf-html',
982 'block' => true,
983 'properties' => array(
984 'top' => '20',
985 'left' => '20',
986 'right' => '20',
987 'width' => '100%',
988 'height' => 'auto',
989 'value' => $label ? $label : $field->name,
990 ),
991 )
992 );
993 $elements[] = $this->auto_field(
994 $field,
995 array(
996 'type' => 'e2pdf-checkbox',
997 'properties' => array(
998 'top' => '5',
999 'width' => 'auto',
1000 'height' => 'auto',
1001 'value' => '[' . $field->name . ']',
1002 'option' => 'Consented',
1003 ),
1004 )
1005 );
1006 break;
1007 default:
1008 break;
1009 }
1010 }
1011 }
1012
1013 $response['page'] = array(
1014 'bottom' => '20',
1015 'top' => '20',
1016 'right' => '20',
1017 'left' => '20',
1018 );
1019
1020 $response['elements'] = $elements;
1021 return $response;
1022 }
1023
1024 // auto field
1025 public function auto_field($field = false, $element = array()) {
1026 if (!$field) {
1027 return false;
1028 }
1029 if (!isset($element['block'])) {
1030 $element['block'] = false;
1031 }
1032 if (!isset($element['float'])) {
1033 $element['float'] = false;
1034 }
1035 return $element;
1036 }
1037
1038 // styles
1039 public function styles($item_id = false) {
1040 $styles = array(
1041 plugins_url('css/extension/wpcf7.css?v=' . time(), $this->helper->get('plugin_file_path')),
1042 );
1043 return $styles;
1044 }
1045
1046 // delete item
1047 public function delete_item($template_id = false, $dataset_id = false) {
1048 global $wpdb;
1049 $template = new Model_E2pdf_Template();
1050 if ($template_id && $dataset_id && $template->load($template_id)) {
1051 if ($template->get('extension') === 'wpcf7' && $template->get('item')) {
1052 $item_id = $template->get('item');
1053 $where = array(
1054 'ID' => $dataset_id,
1055 'item' => $item_id,
1056 'extension' => 'wpcf7',
1057 );
1058 $wpdb->delete($wpdb->prefix . 'e2pdf_datasets', $where);
1059
1060 if ($dataset_id) {
1061 $upload_dir = $this->helper->get('wpcf7_dir') . $dataset_id . '/';
1062 if (is_dir($upload_dir)) {
1063 $this->helper->delete_dir($upload_dir);
1064 }
1065 }
1066 return true;
1067 }
1068 }
1069 return false;
1070 }
1071
1072 // delete items
1073 public function delete_items($template_id = false) {
1074 global $wpdb;
1075 $template = new Model_E2pdf_Template();
1076 if ($template_id && $template->load($template_id)) {
1077 if ($template->get('extension') === 'wpcf7' && $template->get('item')) {
1078 $where = array(
1079 'item' => $template->get('item'),
1080 'extension' => 'wpcf7',
1081 );
1082 $condition = array(
1083 'extension' => array(
1084 'condition' => '=',
1085 'value' => 'wpcf7',
1086 'type' => '%s',
1087 ),
1088 'item' => array(
1089 'condition' => '=',
1090 'value' => $template->get('item'),
1091 'type' => '%s',
1092 ),
1093 );
1094 $where = $this->helper->load('db')->prepare_where($condition);
1095 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
1096 $datasets = $wpdb->get_results($wpdb->prepare('SELECT ID FROM `' . $wpdb->prefix . 'e2pdf_datasets`' . $where['sql'] . '', $where['filter']));
1097 foreach ($datasets as $dataset) {
1098 $this->delete_item($template_id, $dataset->ID);
1099 }
1100 return true;
1101 }
1102 }
1103 return false;
1104 }
1105
1106 // save item
1107 public function save_item() {
1108 if ($this->get_storing_engine() == '1') {
1109 if ($this->get('vxcf_entry_id')) {
1110 $this->set('dataset', $this->get('vxcf_entry_id'));
1111 }
1112 } elseif ($this->get_storing_engine() == '2') {
1113 if ($this->get('cfdb7_entry_id')) {
1114 $this->set('dataset', $this->get('cfdb7_entry_id'));
1115 }
1116 } elseif ($this->get_storing_engine() == '3') {
1117 if ($this->get('vsz_cf7_entry_id')) {
1118 $this->set('dataset', $this->get('vsz_cf7_entry_id'));
1119 }
1120 } else {
1121 $posted_data = $this->get('submission')->get_posted_data();
1122 $uploaded_files = $this->get('submission')->uploaded_files();
1123 $meta = array(
1124 'timestamp' => $this->get('submission')->get_meta('timestamp'),
1125 'remote_ip' => $this->get('submission')->get_meta('remote_ip'),
1126 'remote_port' => $this->get('submission')->get_meta('remote_port'),
1127 'user_agent' => $this->get('submission')->get_meta('user_agen'),
1128 'url' => $this->get('submission')->get_meta('url'),
1129 'unit_tag' => $this->get('submission')->get_meta('unit_tag'),
1130 'container_post_id' => $this->get('submission')->get_meta('container_post_id'),
1131 'current_user_id' => $this->get('submission')->get_meta('current_user_id'),
1132 'do_not_store' => $this->get('submission')->get_meta('do_not_store'),
1133 );
1134
1135 $entry = new Model_E2pdf_Dataset();
1136 $entry->set('extension', 'wpcf7');
1137 $entry->set('item', $this->get('submission')->get_contact_form()->id());
1138 $dataset = $entry->save();
1139
1140 if ($dataset) {
1141 if (!empty($uploaded_files)) {
1142 $upload_dir = $this->helper->get('wpcf7_dir') . $dataset . '/';
1143 if ($this->helper->create_dir($upload_dir)) {
1144 global $wp_filesystem;
1145 if (!$wp_filesystem) {
1146 if (!function_exists('WP_Filesystem')) {
1147 require_once ABSPATH . '/wp-admin/includes/file.php'; // PHPCS:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
1148 }
1149 WP_Filesystem();
1150 }
1151 foreach ($uploaded_files as $key => $field) {
1152 $uploaded_files[$key] = array_map(
1153 function ($uploaded_file) use ($dataset) {
1154 $upload_dir = $this->helper->get('wpcf7_dir') . $dataset . '/';
1155 $dir = dirname($uploaded_file) . '/';
1156 $new_dir = $upload_dir . basename($dir) . '/';
1157 if (!is_dir($new_dir)) {
1158 if ($this->helper->create_dir($new_dir)) {
1159 copy_dir($dir, $new_dir);
1160 }
1161 }
1162 return $uploaded_file;
1163 }, $uploaded_files[$key]
1164 );
1165 }
1166 }
1167 }
1168 $data = array(
1169 'posted_data' => $posted_data,
1170 'uploaded_files' => $uploaded_files,
1171 'meta' => $meta,
1172 );
1173 $entry->set('entry', $data);
1174 $entry->save();
1175
1176 $this->set('dataset', $dataset);
1177 }
1178 }
1179 }
1180
1181 // Contact Form Entries – Contact Form 7, WPforms and more saving addons filter
1182 public function filter_vxcf_after_saving_addons($lead, $entry_id, $type, $form) {
1183 if ($this->get_storing_engine() == '1' && !empty($lead['__vx_entry']['form_id'])) {
1184 if (0 === strpos($lead['__vx_entry']['form_id'], 'cf_')) {
1185 $this->set('vxcf_entry_id', $entry_id);
1186 }
1187 }
1188 return $lead;
1189 }
1190
1191 // Contact Form 7 Database Addon - CFDB7 after save data action
1192 public function action_cfdb7_after_save_data($entry_id) {
1193 if ($this->get_storing_engine() == '2' && $entry_id) {
1194 $this->set('cfdb7_entry_id', $entry_id);
1195 }
1196 }
1197
1198 // Advanced Contact form 7 DB after insert db action
1199 public function action_vsz_cf7_after_insert_db($form, $cf7_id, $data_id) {
1200 if ($this->get_storing_engine() == '3' && $data_id) {
1201 $this->set('vsz_cf7_entry_id', $data_id);
1202 }
1203 }
1204
1205 // before send mail abort action
1206 public function action_wpcf7_before_send_mail_abort($form, &$abort) {
1207 $abort = true;
1208 }
1209
1210 // before send mail action
1211 public function action_wpcf7_before_send_mail($form, &$abort) {
1212
1213 if ($abort) {
1214 return;
1215 }
1216
1217 $submission = WPCF7_Submission::get_instance();
1218 if (!$submission) {
1219 return;
1220 }
1221
1222 $this->set('dataset', false);
1223 $this->set('submission', $submission);
1224
1225 $properties = $submission->get_contact_form()->get_properties();
1226
1227 if (isset($properties['messages']['mail_sent_ok']) && $properties['messages']['mail_sent_ok']) {
1228 $properties['messages']['mail_sent_ok'] = $this->filter_success_message($properties['messages']['mail_sent_ok']);
1229 }
1230
1231 if (isset($properties['mail']['active']) && $properties['mail']['active'] && isset($properties['mail']['body']) && $properties['mail']['body']) {
1232 $properties['mail']['body'] = $this->filter_mail_body($properties['mail']['body']);
1233 $properties['mail']['attachments'] = $this->filter_mail_body($properties['mail']['attachments']);
1234 }
1235
1236 if (isset($properties['mail_2']['active']) && $properties['mail_2']['active'] && isset($properties['mail']['body']) && $properties['mail_2']['body']) {
1237 $properties['mail_2']['body'] = $this->filter_mail_body($properties['mail_2']['body'], 'mail_2');
1238 $properties['mail_2']['attachments'] = $this->filter_mail_body($properties['mail_2']['attachments'], 'mail_2');
1239 }
1240
1241 if ($this->get('dataset')) {
1242 $submission->get_contact_form()->set_properties($properties);
1243 }
1244 }
1245
1246 // mail sent action
1247 public function action_wpcf7_mail_sent($form) {
1248 $submission = WPCF7_Submission::get_instance();
1249 if (!$submission) {
1250 return $form;
1251 }
1252
1253 $success_message = $submission->get_response();
1254 if (false !== strpos($success_message, '[')) {
1255 $shortcode_tags = array(
1256 'e2pdf-download',
1257 'e2pdf-save',
1258 'e2pdf-view',
1259 'e2pdf-adobesign',
1260 'e2pdf-zapier',
1261 );
1262 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $success_message, $matches);
1263 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1264 if (!empty($tagnames)) {
1265 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $success_message, $shortcodes);
1266 foreach ($shortcodes[0] as $key => $shortcode_value) {
1267 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
1268 $atts = shortcode_parse_atts($shortcode[3]);
1269 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
1270 } else {
1271 $success_message = str_replace($shortcode_value, do_shortcode_tag($shortcode), $success_message);
1272 }
1273 }
1274 $submission->set_response($success_message);
1275 }
1276 }
1277
1278 $files = $this->helper->get('wpcf7_attachments');
1279 if (is_array($files) && !empty($files)) {
1280 foreach ($files as $key => $file) {
1281 $this->helper->delete_dir(dirname($file) . '/');
1282 }
1283 $this->helper->deset('wpcf7_attachments');
1284 }
1285 }
1286
1287 // filter success message
1288 public function filter_success_message($success_message) {
1289 if (false !== strpos($success_message, '[')) {
1290 $shortcode_tags = array(
1291 'e2pdf-download',
1292 'e2pdf-save',
1293 'e2pdf-view',
1294 'e2pdf-adobesign',
1295 'e2pdf-zapier',
1296 );
1297 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $success_message, $matches);
1298 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1299 if (!empty($tagnames)) {
1300 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $success_message, $shortcodes);
1301 foreach ($shortcodes[0] as $key => $shortcode_value) {
1302 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
1303 $atts = shortcode_parse_atts($shortcode[3]);
1304 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
1305 } else {
1306 if (!isset($atts['dataset']) && isset($atts['id'])) {
1307 $template = new Model_E2pdf_Template();
1308 $template->load($atts['id']);
1309
1310 if ($template->get('extension') === 'wpcf7') {
1311 if (!$this->get('dataset')) {
1312 $this->save_item();
1313 }
1314 $atts['dataset'] = $this->get('dataset');
1315 $shortcode[3] .= ' dataset="' . $this->get('dataset') . '"';
1316 }
1317 }
1318 if (!isset($atts['apply'])) {
1319 $shortcode[3] .= ' apply="true"';
1320 }
1321 if (!isset($atts['iframe_download'])) {
1322 $shortcode[3] .= ' iframe_download="true"';
1323 }
1324 $success_message = str_replace($shortcode_value, '[' . $shortcode[2] . $shortcode[3] . ']', $success_message);
1325 }
1326 }
1327 }
1328 }
1329 return $success_message;
1330 }
1331
1332 // filter mail body
1333 public function filter_mail_body($success_message, $tpl = 'mail') {
1334
1335 if (false !== strpos($success_message, '[')) {
1336 $shortcode_tags = array(
1337 'e2pdf-download',
1338 'e2pdf-save',
1339 'e2pdf-adobesign',
1340 'e2pdf-zapier',
1341 'e2pdf-attachment',
1342 );
1343 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $success_message, $matches);
1344 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1345 if (!empty($tagnames)) {
1346 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $success_message, $shortcodes);
1347 foreach ($shortcodes[0] as $key => $shortcode_value) {
1348 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
1349 $atts = shortcode_parse_atts($shortcode[3]);
1350
1351 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) {
1352 if (!isset($atts['dataset']) && isset($atts['id'])) {
1353 $template = new Model_E2pdf_Template();
1354 $template->load($atts['id']);
1355 if ($template->get('extension') === 'wpcf7') {
1356 if (!$this->get('dataset')) {
1357 $this->save_item();
1358 }
1359 $atts['dataset'] = $this->get('dataset');
1360 $shortcode[3] .= ' dataset="' . $this->get('dataset') . '"';
1361 }
1362 }
1363 if (!isset($atts['apply'])) {
1364 $shortcode[3] .= ' apply="true"';
1365 }
1366 $file = do_shortcode_tag($shortcode);
1367 if ($file) {
1368 $tmp = false;
1369 if (substr($file, 0, 4) === 'tmp:') {
1370 $file = substr($file, 4);
1371 $tmp = true;
1372 }
1373 if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
1374 if ($tmp) {
1375 $this->helper->add('wpcf7_attachments', $file);
1376 }
1377 } else {
1378 $this->helper->add('wpcf7_attachments', $file);
1379 }
1380 $this->get('submission')->add_extra_attachments($file, $tpl);
1381 }
1382 $success_message = str_replace($shortcode_value, '', $success_message);
1383 } else {
1384 if (!isset($atts['dataset']) && isset($atts['id'])) {
1385 $template = new Model_E2pdf_Template();
1386 $template->load($atts['id']);
1387 if ($template->get('extension') === 'wpcf7') {
1388 if (!$this->get('dataset')) {
1389 $this->save_item();
1390 }
1391 $atts['dataset'] = $this->get('dataset');
1392 $shortcode[3] .= ' dataset="' . $this->get('dataset') . '"';
1393 }
1394 }
1395 if (!isset($atts['apply'])) {
1396 $shortcode[3] .= ' apply="true"';
1397 }
1398 $success_message = str_replace($shortcode_value, do_shortcode_tag($shortcode), $success_message);
1399 }
1400 }
1401 }
1402 }
1403
1404 return $success_message;
1405 }
1406
1407 // filter mail tag
1408 public function filter_wpcf7_file_mail_tag($replaced, $submitted, $html, $mail_tag) {
1409 $submission = WPCF7_Submission::get_instance();
1410 $uploaded_files = $submission->uploaded_files();
1411 $name = $mail_tag->field_name();
1412
1413 if (!empty($uploaded_files[$name])) {
1414 $paths = (array) $uploaded_files[$name];
1415 $urls = array_map(
1416 function ($uploaded_file) {
1417 $wp_upload_dir = wp_upload_dir();
1418 $upload_dir = $this->helper->get('wpcf7_dir') . $this->get('dataset');
1419 $uploaded_file = str_replace(wpcf7_upload_tmp_dir(), $upload_dir, $uploaded_file);
1420 return str_replace($wp_upload_dir['basedir'], $wp_upload_dir['baseurl'], $uploaded_file);
1421 }, $paths
1422 );
1423
1424 $replaced = wpcf7_flat_join(
1425 $urls,
1426 array(
1427 'separator' => wp_get_list_item_separator(),
1428 )
1429 );
1430 }
1431
1432 return $replaced;
1433 }
1434
1435 // filter options
1436 public function filter_e2pdf_model_options_get_options_options($options = array()) {
1437 $engines = array(
1438 '0' => 'E2Pdf',
1439 );
1440
1441 /**
1442 * Contact Form Entries – Contact Form 7, WPforms and more
1443 * https://wordpress.org/plugins/contact-form-entries/
1444 */
1445 if (class_exists('vxcf_form')) {
1446 $engines['1'] = 'Contact Form Entries – Contact Form 7, WPforms and more';
1447 }
1448
1449 /**
1450 * Contact Form 7 Database Addon - CFDB7
1451 * https://wordpress.org/plugins/contact-form-cfdb7/
1452 */
1453 if (function_exists('cfdb7_init')) {
1454 $engines['2'] = 'Contact Form 7 Database Addon - CFDB7';
1455 }
1456
1457 /**
1458 * Advanced Contact form 7 DB
1459 * https://wordpress.org/plugins/advanced-cf7-db/
1460 */
1461 if (class_exists('Advanced_Cf7_Db')) {
1462 $engines['3'] = 'Advanced Contact form 7 DB';
1463 }
1464
1465 $options['wpcf7_group'] = array(
1466 'name' => 'Contact Form 7',
1467 'action' => 'extension',
1468 'group' => 'wpcf7_group',
1469 'options' => array(
1470 array(
1471 'name' => __('Storing Engine', 'e2pdf'),
1472 'key' => 'e2pdf_wpcf7_storing_engine',
1473 'value' => $this->get_storing_engine(),
1474 'default_value' => '0',
1475 'type' => 'select',
1476 'options' => $engines,
1477 ),
1478 ),
1479 );
1480 return $options;
1481 }
1482
1483 /**
1484 * 0 - E2Pdf (default)
1485 * 1 - Contact Form Entries – Contact Form 7, WPforms and more
1486 * https://wordpress.org/plugins/contact-form-entries/
1487 * 2 - Contact Form 7 Database Addon - CFDB7
1488 * https://wordpress.org/plugins/contact-form-cfdb7/
1489 * 3 - Advanced Contact form 7 DB
1490 * https://wordpress.org/plugins/advanced-cf7-db/)
1491 */
1492 public function get_storing_engine() {
1493 if ($this->get('storing_engine') !== false) {
1494 $storing_engine = $this->get('storing_engine');
1495 if ($storing_engine === '1') {
1496 if (class_exists('vxcf_form')) {
1497 return '1';
1498 } else {
1499 return false;
1500 }
1501 } elseif ($storing_engine === '2') {
1502 if (function_exists('cfdb7_init')) {
1503 return '2';
1504 } else {
1505 return false;
1506 }
1507 } elseif ($storing_engine === '3') {
1508 if (class_exists('Advanced_Cf7_Db')) {
1509 return '3';
1510 } else {
1511 return false;
1512 }
1513 } else {
1514 return '0';
1515 }
1516 } else {
1517 $storing_engine = get_option('e2pdf_wpcf7_storing_engine', '0');
1518 if ($storing_engine === '1' && class_exists('vxcf_form')) {
1519 return '1';
1520 } elseif ($storing_engine === '2' && function_exists('cfdb7_init')) {
1521 return '2';
1522 } elseif ($storing_engine === '3' && class_exists('Advanced_Cf7_Db')) {
1523 return '3';
1524 } else {
1525 return '0';
1526 }
1527 }
1528 }
1529 }
1530