PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.56
E2Pdf – Export Pdf Tool for WordPress v1.32.56
1.32.55 1.32.56 1.32.53 1.32.51 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 All 76 releases
e2pdf / classes / extension / e2pdf-wpforms.php

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

1,661 lines 79.8 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-wpforms.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_Wpforms extends Model_E2pdf_Model {
15
16 private $options;
17 private $info = array(
18 'key' => 'wpforms',
19 'title' => 'WPForms',
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_WPFORMS_EXTENSION') || $this->helper->load('extension')->is_plugin_active('wpforms-lite/wpforms.php') || $this->helper->load('extension')->is_plugin_active('wpforms/wpforms.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')) {
51 $this->set('cached_form', get_post($this->get('item')));
52 }
53 break;
54 case 'dataset':
55 $this->set('cached_entry', false);
56 if ($this->get('dataset')) {
57 if (substr($this->get('dataset'), 0, 4) === 'tmp_') {
58 $cached_entry = new stdClass();
59 $cached_entry->entry_id = '';
60 $cached_entry->form_id = $this->get('item');
61 $cached_entry->fields = json_encode(get_transient('e2pdf_' . $this->get('dataset'))); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
62 $this->set('cached_entry', $cached_entry);
63 } else {
64 if ($this->get('dataset') && function_exists('wpforms') && wpforms()->entry) {
65 $this->set('cached_entry', wpforms()->entry->get($this->get('dataset')));
66 }
67 }
68 }
69 break;
70 default:
71 break;
72 }
73 return true;
74 }
75
76 // get
77 public function get($key) {
78 if (isset($this->options->$key)) {
79 $value = $this->options->$key;
80 } else {
81 switch ($key) {
82 case 'args':
83 $value = array();
84 break;
85 default:
86 $value = false;
87 break;
88 }
89 }
90 return $value;
91 }
92
93 // items
94 public function items() {
95 $items = array();
96 if (function_exists('wpforms')) {
97 $forms = wpforms()->form->get();
98 if (!empty($forms)) {
99 foreach ($forms as $form) {
100 $items[] = $this->item($form->ID);
101 }
102 }
103 }
104 return $items;
105 }
106
107 // item
108 public function item($item_id = false) {
109 $item_id = (int) $item_id;
110 if (!$item_id && $this->get('item')) {
111 $item_id = $this->get('item');
112 }
113 $form = get_post($item_id);
114 $item = new stdClass();
115 if ($form) {
116 $item->id = (string) $item_id;
117 $item->url = $this->helper->get_url(
118 array(
119 'page' => 'wpforms-builder',
120 'view' => 'fields',
121 'form_id' => $item_id,
122 )
123 );
124 $item->name = $form->post_title;
125 } else {
126 $item->id = '';
127 $item->url = '';
128 $item->name = '';
129 }
130 return $item;
131 }
132
133 // datasets
134 public function datasets($item_id = false, $name = false) {
135 $item_id = (int) $item_id;
136 $datasets = array();
137 $entries_args = array(
138 'form_id' => absint($item_id),
139 'number' => 9999999,
140 );
141
142 if (isset(wpforms()->entry)) {
143 $entries = wpforms()->entry->get_entries($entries_args);
144 if ($entries) {
145 $this->set('item', $item_id);
146 foreach ($entries as $key => $entry) {
147 $this->set('dataset', $entry->entry_id);
148 $entry_title = $this->render($name);
149 if (!$entry_title) {
150 $entry_title = $entry->entry_id;
151 }
152 $datasets[] = array(
153 'key' => $entry->entry_id,
154 'value' => $entry_title,
155 );
156 }
157 }
158 }
159 return $datasets;
160 }
161
162 // get dataset actions
163 public function get_dataset_actions($dataset_id = false) {
164 $dataset_id = (int) $dataset_id;
165 if (!$dataset_id) {
166 return false;
167 }
168 $actions = new stdClass();
169 $actions->view = $this->helper->get_url(
170 array(
171 'page' => 'wpforms-entries',
172 'view' => 'details',
173 'entry_id' => $dataset_id,
174 )
175 );
176 $actions->delete = false;
177 return $actions;
178 }
179
180 // get template actions
181 public function get_template_actions($template = false) {
182 $template = (int) $template;
183 if (!$template) {
184 return;
185 }
186 $actions = new stdClass();
187 $actions->delete = false;
188 return $actions;
189 }
190
191 // render
192 public function render($value, $field = array(), $convert_shortcodes = true, $raw = false) {
193 $value = $this->render_shortcodes($value, $field);
194 if (!$raw) {
195 $value = $this->strip_shortcodes($value);
196 $value = $this->convert_shortcodes($value, $convert_shortcodes, isset($field['type']) && $field['type'] == 'e2pdf-html' ? true : false);
197 $value = $this->helper->load('field')->render_checkbox($value, $this, $field);
198 }
199 return $value;
200 }
201
202 // load actions
203 public function load_actions() {
204 $options = get_option('wpforms_settings', false);
205 $async = is_array($options) && !empty($options['email-async']) ? wp_unslash($options['email-async']) : false;
206 if ($async) {
207 add_action('action_scheduler_begin_execute', array($this, 'action_scheduler_begin_execute'), 10, 2);
208 add_action('action_scheduler_after_execute', array($this, 'action_scheduler_after_execute'), 10, 3);
209 } else {
210 add_action('wpforms_email_send_after', array($this, 'action_wpforms_email_send_after'));
211 }
212
213 // hidden default value
214 add_action('wpforms_process_entry_saved', array($this, 'action_wpforms_process_entry_saved'), 10, 4);
215
216 // hooks
217 add_action('wpforms_entry_details_sidebar', array($this, 'hook_wpforms_entry_view'));
218 add_action('wpforms_pro_admin_entries_edit_sidebar', array($this, 'hook_wpforms_entry_edit'));
219 }
220
221 // hidden default value
222 public function action_wpforms_process_entry_saved($fields, $entry, $form_data, $dataset) {
223
224 if (!$dataset || empty($form_data['fields'])) {
225 return;
226 }
227
228 foreach ($form_data['fields'] as $field) {
229 if ($field['type'] === 'hidden' && !empty($field['default_value']) && !empty($field['id'])) {
230
231 $field_id = $field['id'];
232 $default_value = $field['default_value'];
233
234 if (is_string($field['default_value']) && false !== strpos($default_value, '[e2pdf-download') || false !== strpos($default_value, '[e2pdf-save')) {
235 $shortcode_tags = array(
236 'e2pdf-download',
237 'e2pdf-save',
238 );
239 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $default_value, $matches);
240 $tagnames = array_intersect($shortcode_tags, $matches[1]);
241 if (!empty($tagnames)) {
242 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $default_value, $shortcodes);
243 foreach ($shortcodes[0] as $key => $shortcode_value) {
244 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
245 $atts = shortcode_parse_atts($shortcode[3]);
246 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
247 } else {
248 if (!isset($atts['dataset']) && isset($atts['id'])) {
249 $template = new Model_E2pdf_Template();
250 $template->load($atts['id']);
251 if ($template->get('extension') === 'wpforms') {
252 $atts['dataset'] = $dataset;
253 $shortcode[3] .= ' dataset="' . $dataset . '"';
254 }
255 }
256 if (!isset($atts['apply'])) {
257 $shortcode[3] .= ' apply="true"';
258 }
259 $default_value = str_replace($shortcode_value, do_shortcode_tag($shortcode), $default_value);
260 }
261 }
262 }
263
264 // Uncanny Automator
265 $process = wpforms()->obj('process');
266 if ($process) {
267 if (isset($process->fields[$field_id])) {
268 $process->fields[$field_id]['value'] = $default_value;
269 }
270 }
271
272 $db_entry = wpforms()->entry->get($dataset);
273 if (!$db_entry) {
274 return;
275 }
276 if (isset($db_entry->fields)) {
277 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
278 $db_entry_fields = @json_decode($db_entry->fields, true);
279 if (isset($db_entry_fields[$field_id])) {
280 $db_entry_fields[$field_id]['value'] = $default_value;
281 wpforms()->entry->update(
282 $dataset,
283 [
284 'fields' => wp_json_encode($db_entry_fields),
285 ]
286 );
287 }
288 }
289 }
290 }
291 }
292 }
293
294 // email send after action
295 public function action_wpforms_email_send_after() {
296 $files = $this->helper->get('wpforms_attachments');
297 if (is_array($files) && !empty($files)) {
298 foreach ($files as $key => $file) {
299 $this->helper->delete_dir(dirname($file) . '/');
300 }
301 $this->helper->deset('wpforms_attachments');
302 }
303 }
304
305 // scheduler begin execute action
306 public function action_scheduler_begin_execute($action_id, $context) {
307 if (class_exists('ActionScheduler_Store')) {
308 $store = ActionScheduler_Store::instance();
309 if ($store) {
310 $action = $store->fetch_action($action_id);
311 if ($action->get_hook() == 'wpforms_process_entry_emails') {
312 add_filter('wp_mail', array($this, 'filter_wp_mail'), 30);
313 }
314 }
315 }
316 }
317
318 // scheduler after execute action
319 public function action_scheduler_after_execute($action_id, $action, $context) {
320 $files = $this->helper->get('wpforms_attachments');
321 if (is_array($files) && !empty($files)) {
322 foreach ($files as $key => $file) {
323 $this->helper->delete_dir(dirname($file) . '/');
324 }
325 $this->helper->deset('wpforms_attachments');
326 }
327 }
328
329 // filter wp mail
330 public function filter_wp_mail($args = array()) {
331 $message = preg_replace('/(\{\{)((e2pdf-save|e2pdf-attachment)[^\}]*?)(\}\})/', '[$2]', $args['message']);
332 if (false !== strpos($message, '[')) {
333 $shortcode_tags = array(
334 'e2pdf-save',
335 'e2pdf-attachment',
336 );
337 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $message, $matches);
338 $tagnames = array_intersect($shortcode_tags, $matches[1]);
339 if (!empty($tagnames)) {
340 // shortcodes do not work when user is not logged-in in async mode
341 if (!shortcode_exists('e2pdf-save')) {
342 add_shortcode('e2pdf-save', array(new Model_E2pdf_Shortcode(), 'e2pdf_save'));
343 }
344 if (!shortcode_exists('e2pdf-attachment')) {
345 add_shortcode('e2pdf-attachment', array(new Model_E2pdf_Shortcode(), 'e2pdf_attachment'));
346 }
347 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $message, $shortcodes);
348 foreach ($shortcodes[0] as $key => $shortcode_value) {
349 $file = false;
350 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
351 $atts = shortcode_parse_atts($shortcode[3]);
352 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) {
353 $transient = isset($atts['dataset']) && substr($atts['dataset'], 0, 4) === 'tmp_' ? 'e2pdf_' . $atts['dataset'] : false;
354 $file = do_shortcode_tag($shortcode);
355 if ($file) {
356 $tmp = false;
357 if (substr($file, 0, 4) === 'tmp:') {
358 $file = substr($file, 4);
359 $tmp = true;
360 }
361 if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
362 if ($tmp) {
363 $this->helper->add('wpforms_attachments', $file);
364 }
365 } else {
366 $this->helper->add('wpforms_attachments', $file);
367 }
368 $args['attachments'][] = $file;
369 }
370 $message = str_replace($shortcode_value, '', $message);
371 if ($transient) {
372 delete_transient($transient);
373 }
374 }
375 }
376 $args['message'] = $message;
377 }
378 }
379 $wp_mail = array(
380 'to' => $args['to'],
381 'subject' => $args['subject'],
382 'message' => $args['message'],
383 'headers' => $args['headers'],
384 'attachments' => $args['attachments'],
385 );
386 return $wp_mail;
387 }
388
389 // load filters
390 public function load_filters() {
391 add_filter('wpforms_frontend_confirmation_message', array($this, 'filter_wpforms_frontend_confirmation_message'), 10, 4);
392 add_filter('wpforms_emails_send_email_data', array($this, 'filter_wpforms_emails_send_email_data'), 11, 2);
393 add_filter('wpforms_process_smart_tags', array(new Model_E2pdf_Filter(), 'pre_filter'), 0);
394 add_filter('wpforms_process_smart_tags', array(new Model_E2pdf_Filter(), 'filter'), 999);
395
396 // hooks
397 add_filter('wpforms_entry_table_actions', array($this, 'hook_wpforms_row_actions'), 10, 2);
398
399 // extension hooks
400 add_filter('e2pdf_extension_hooks', function ($hooks) {
401 $hooks[$this->info['key']] = [
402 'hook_wpforms_entry_view' => __('WP Admin Entry View', 'e2pdf'),
403 'hook_wpforms_entry_edit' => __('WP Admin Entry Edit', 'e2pdf'),
404 'hook_wpforms_row_actions' => __('WP Admin Entry Row Actions', 'e2pdf')
405 ];
406 return $hooks;
407 });
408 }
409
410 // frontend confirmation message filter
411 public function filter_wpforms_frontend_confirmation_message($message, $form_data, $fields, $dataset) {
412 if (false !== strpos($message, '[')) {
413 $shortcode_tags = array(
414 'e2pdf-download',
415 'e2pdf-save',
416 'e2pdf-view',
417 'e2pdf-adobesign',
418 'e2pdf-zapier',
419 );
420 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $message, $matches);
421 $tagnames = array_intersect($shortcode_tags, $matches[1]);
422 if (!empty($tagnames)) {
423 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $message, $shortcodes);
424 foreach ($shortcodes[0] as $key => $shortcode_value) {
425 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
426 $atts = shortcode_parse_atts($shortcode[3]);
427 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
428 } else {
429 if (!isset($atts['dataset']) && isset($atts['id'])) {
430 $template = new Model_E2pdf_Template();
431 $template->load($atts['id']);
432 if ($template->get('extension') === 'wpforms') {
433 $atts['dataset'] = $dataset;
434 $shortcode[3] .= ' dataset="' . $dataset . '"';
435 }
436 }
437 if (!isset($atts['apply'])) {
438 $shortcode[3] .= ' apply="true"';
439 }
440 if (!isset($atts['iframe_download'])) {
441 $shortcode[3] .= ' iframe_download="true"';
442 }
443 $message = str_replace($shortcode_value, do_shortcode_tag($shortcode), $message);
444 }
445 }
446 }
447 }
448 return $message;
449 }
450
451 // send email data filter
452 public function filter_wpforms_emails_send_email_data($mail, $data) {
453 if ($mail && isset($mail['message'])) {
454 if (false !== strpos($mail['message'], '[')) {
455 $shortcode_tags = array(
456 'e2pdf-download',
457 'e2pdf-save',
458 'e2pdf-attachment',
459 'e2pdf-adobesign',
460 'e2pdf-zapier',
461 );
462 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $mail['message'], $matches);
463 $tagnames = array_intersect($shortcode_tags, $matches[1]);
464 if (!empty($tagnames)) {
465 $options = get_option('wpforms_settings', false);
466 $async = is_array($options) && !empty($options['email-async']) ? wp_unslash($options['email-async']) : false;
467 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $mail['message'], $shortcodes);
468 foreach ($shortcodes[0] as $key => $shortcode_value) {
469 $file = false;
470 $transient = false;
471 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
472 $atts = shortcode_parse_atts($shortcode[3]);
473 if (!isset($atts['dataset']) && isset($atts['id'])) {
474 $template = new Model_E2pdf_Template();
475 $template->load($atts['id']);
476 if ($template->get('extension') === 'wpforms') {
477 if (isset($data->entry_id) && $data->entry_id) {
478 $atts['dataset'] = $data->entry_id;
479 $shortcode[3] .= ' dataset="' . $data->entry_id . '"';
480 } elseif ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) {
481 $dataset = 'tmp_' . $this->helper->load('encryption')->random_md5();
482 $transient = 'e2pdf_' . $dataset;
483 set_transient($transient, $data->fields, 1800);
484 $atts['dataset'] = $dataset;
485 $shortcode[3] .= ' dataset="' . $dataset . '"';
486 }
487 }
488 }
489 if (!isset($atts['apply'])) {
490 $shortcode[3] .= ' apply="true"';
491 }
492 if (!isset($atts['filter'])) {
493 $shortcode[3] .= ' filter="true"';
494 }
495 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) {
496 if ($async) {
497 $mail['message'] = str_replace($shortcode_value, '{{' . $shortcode[2] . $shortcode[3] . '}}', $mail['message']);
498 } else {
499 $file = do_shortcode_tag($shortcode);
500 if ($file) {
501 $tmp = false;
502 if (substr($file, 0, 4) === 'tmp:') {
503 $file = substr($file, 4);
504 $tmp = true;
505 }
506 if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
507 if ($tmp) {
508 $this->helper->add('wpforms_attachments', $file);
509 }
510 } else {
511 $this->helper->add('wpforms_attachments', $file);
512 }
513 $mail['attachments'][] = $file;
514 }
515 $mail['message'] = str_replace($shortcode_value, '', $mail['message']);
516 if ($transient) {
517 delete_transient($transient);
518 }
519 }
520 } else {
521 $mail['message'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $mail['message']);
522 if ($transient) {
523 delete_transient($transient);
524 }
525 }
526 }
527 }
528 }
529 }
530 return $mail;
531 }
532
533 // render shortcodes
534 public function render_shortcodes($value, $field = array()) {
535 $element_id = isset($field['element_id']) ? $field['element_id'] : false;
536 if ($this->verify()) {
537 if (false !== strpos($value, '[')) {
538 $value = $this->helper->load('field')->pre_shortcodes($value, $this, $field);
539 $value = $this->helper->load('field')->inner_shortcodes($value, $this, $field);
540 $value = $this->helper->load('field')->wrapper_shortcodes($value, $this, $field);
541 }
542 $value = $this->helper->load('field')->do_shortcodes($value, $this, $field);
543 if (function_exists('wpforms_process_smart_tags')) {
544 add_filter('wpforms_smart_tags_formatted_field_value', array($this, 'filter_wpforms_smart_tags_formatted_field_value'), 99, 4);
545 add_filter('wpforms_smarttags_process_value', array($this, 'filter_wpforms_smarttags_process_value'), 10, 6);
546 $value = wpforms_process_smart_tags($value, wpforms_decode($this->get('cached_form')->post_content), wpforms_decode($this->get('cached_entry')->fields), $this->get('cached_entry')->entry_id);
547 remove_filter('wpforms_smarttags_process_value', array($this, 'filter_wpforms_smarttags_process_value'), 10);
548 remove_filter('wpforms_smart_tags_formatted_field_value', array($this, 'filter_wpforms_smart_tags_formatted_field_value'), 99);
549 }
550 $value = $this->helper->load('field')->render(
551 apply_filters('e2pdf_extension_render_shortcodes_pre_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false),
552 $this,
553 $field
554 );
555 }
556 return apply_filters(
557 'e2pdf_extension_render_shortcodes_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false
558 );
559 }
560
561 // wpforms checkboxes, multi-selects, and payment checkboxes in email PDF attachments
562 public function filter_wpforms_smart_tags_formatted_field_value($value, $field_id, $fields, $field_key) {
563 if (function_exists('wpforms_get_multi_fields')) {
564 $field_type = $fields[$field_id]['type'] ?? '';
565 if (in_array($field_type, wpforms_get_multi_fields(), true)) {
566 return $fields[$field_id][$field_key] ?? '';
567 }
568 }
569 return $value;
570 }
571
572 // smarttags process value filter
573 public function filter_wpforms_smarttags_process_value($value, $tag_name, $form_data, $fields, $entry_id, $smart_tag_object) {
574
575 $field_id = $smart_tag_object->get_attributes()['field_id'] ?? 0;
576 $field_id = explode('|', $field_id)[0];
577
578 if (false !== strpos($field_id, '_')) {
579 $repeater = array_map('intval', explode('_', $field_id, 2));
580 if (wpforms_is_repeated_field($repeater[0], $fields)) {
581 $prefix = $repeater[1] == '1' ? $repeater[0] : $repeater[0] . '_' . $repeater[1];
582 if ($tag_name == 'field_value_id') {
583 $field_key = isset($fields[$prefix]['value_raw']) && !is_array($fields[$prefix]['value_raw']) && (string) $fields[$prefix]['value_raw'] !== '' ? 'value_raw' : 'value';
584 } else {
585 $field_key = 'value';
586 }
587 $value = isset($fields[$prefix][$field_key]) ? $fields[$prefix][$field_key] : '';
588 }
589 }
590
591 if (false === strpos($field_id, '_') && apply_filters('e2pdf_for_do_shortcode_data_process', false) && wpforms_is_repeated_field((int) $field_id, $fields)) {
592 $values = array();
593 $prefix = (int) $field_id . '_';
594 foreach ($fields as $key => $field) {
595 if (strpos($key, $prefix) === 0 || $key == (int) $field_id) {
596 $values[] = $field;
597 }
598 }
599 $value = serialize($values); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
600 } else {
601 if (
602 $this->get_field_property('type', $smart_tag_object, $form_data, $tag_name) == 'checkbox' ||
603 ($this->get_field_property('type', $smart_tag_object, $form_data, $tag_name) == 'select' && $this->get_field_property('multiple', $smart_tag_object, $form_data, $tag_name) == '1')
604 ) {
605 $value = implode(', ', explode("\n", $value));
606 } elseif ($this->get_field_property('type', $smart_tag_object, $form_data, $tag_name) == 'payment-checkbox') {
607 if ($tag_name == 'field_value_id') {
608 $value = implode(', ', explode(',', $value));
609 } else {
610 $value = implode(', ', explode("\r\n", $value));
611 }
612 } elseif ($this->get_field_property('type', $smart_tag_object, $form_data, $tag_name) == 'likert_scale') {
613 $sub_field_id = $smart_tag_object->get_attributes()['field_id'] ?? 0;
614 $sub_field = explode('|', $sub_field_id);
615 if (isset($sub_field[1])) {
616 $row = $sub_field[1];
617 if (is_numeric($row)) {
618 $value = isset($fields[$field_id]['value_raw'][$row]) ? $fields[$field_id]['value_raw'][$row] : '';
619 if (is_array($value)) {
620 $value = implode(', ', $value);
621 }
622 } else {
623 $input = !empty($fields[$field_id]['value']) ? $fields[$field_id]['value'] : '';
624 $lines = explode("\n", $input);
625 $lines_count = count($lines);
626 $result = [];
627 for ($i = 0; $i < $lines_count; $i += 2) {
628 $key = trim($lines[$i], ":\n");
629 $value = isset($lines[$i + 1]) ? trim($lines[$i + 1]) : '';
630 $result[$key] = $value;
631 }
632 $value = isset($result[$row]) ? $result[$row] : '';
633 }
634 }
635 }
636 $entity_decode = array(
637 'payment-multiple',
638 'payment-checkbox',
639 'payment-total',
640 'payment-single',
641 'payment-select',
642 );
643 if (in_array($this->get_field_property('type', $smart_tag_object, $form_data, $tag_name), $entity_decode, true)) {
644 $value = html_entity_decode($value);
645 }
646 }
647 return $value;
648 }
649
650 public function get_field_property($attr, $smart_tag_object, $form_data, $tag_name) {
651 if (isset($smart_tag_object->get_attributes()[$tag_name])) {
652 $field_id = $smart_tag_object->get_attributes()['field_id'] ?? 0;
653 $field_id = (int) explode('|', $field_id)[0];
654 if (isset($form_data['fields'][$field_id][$attr])) {
655 return $form_data['fields'][$field_id][$attr];
656 }
657 }
658 return false;
659 }
660
661 // strip shortcodes
662 public function strip_shortcodes($value) {
663 $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', '', $value);
664 $value = preg_replace('~a\:\d+\:{[^}]*}(*SKIP)(*FAIL)|{[^}]*}~', '', $value);
665 return $value;
666 }
667
668 // strip math
669 public function strip_math($value, &$replacements) {
670 if ($value) {
671 preg_match_all('/\{[^}]+\}/', $value, $matches);
672 foreach ($matches[0] as $match) {
673 $index = count($replacements) + 1;
674 $replacements[] = $match;
675 $value = str_replace($match, '%' . $index . '$s', $value);
676 }
677 }
678 return $value;
679 }
680
681 // convert shortcodes
682 public function convert_shortcodes($value, $to = false, $html = false) {
683 if ($value) {
684 if ($to) {
685 $search = array('&#91;', '&#93;', '&#091;', '&#093;');
686 $replace = array('[', ']', '[', ']');
687 $value = str_replace($search, $replace, $value);
688 if (!$html) {
689 $value = wp_specialchars_decode($value, ENT_QUOTES);
690 }
691 } else {
692 $search = array('[', ']', '&#091;', '&#093;');
693 $replace = array('&#91;', '&#93;', '&#91;', '&#93;');
694 $value = str_replace($search, $replace, $value);
695 }
696 }
697 return $value;
698 }
699
700 // auto
701 public function auto() {
702
703 $elements = array();
704 if ($this->get('cached_form') && function_exists('wpforms_get_form_fields')) {
705 $form = wpforms_decode($this->get('cached_form')->post_content);
706 $form_fields = isset($form['fields']) ? $form['fields'] : array();
707 $sizes = array();
708 $repeaters = array();
709 $new_form_fields = array();
710
711 foreach ($form_fields as $field) {
712 if ($field['type'] == 'layout' || $field['type'] == 'repeater') {
713 foreach ($field['columns'] as $column) {
714 foreach ($column['fields'] as $sub_field) {
715 $sizes[$sub_field] = $column['width_preset'];
716 if ($field['type'] == 'repeater') {
717 $repeaters[] = $sub_field;
718 }
719 }
720 }
721 }
722 }
723
724 foreach ($form_fields as $field) {
725 if ($field['type'] == 'layout' || $field['type'] == 'repeater') {
726 foreach ($field['columns'] as $column) {
727 foreach ($column['fields'] as $sub_field) {
728 $found = $this->inner_field($form_fields, $sub_field);
729 if ($found !== false) {
730 $new_form_fields[] = $form_fields[$found];
731 }
732 }
733 }
734 } else {
735 $field_id = isset($field['id']) ? $field['id'] : '0';
736 if (!in_array($field_id, $repeaters, true) && !array_key_exists($field_id, $sizes)) {
737 $new_form_fields[] = $field;
738 }
739 }
740 }
741
742 foreach ($new_form_fields as $field) {
743 $width = '100';
744 $field_id = isset($field['id']) ? $field['id'] : '0';
745 $field_value = in_array($field_id, $repeaters, true) ? '{field_id="' . $field_id . '_1"}' : '{field_id="' . $field_id . '"}';
746 if (isset($sizes[$field_id])) {
747 $width = $sizes[$field_id];
748 }
749 switch ($field['type']) {
750 case 'divider':
751 $elements[] = $this->auto_field(
752 $field,
753 array(
754 'type' => 'e2pdf-html',
755 'block' => true,
756 'float' => true,
757 'properties' => array(
758 'top' => '20',
759 'left' => '20',
760 'right' => '20',
761 'width' => $width . '%',
762 'height' => 'auto',
763 'value' => isset($field['label']) ? $field['label'] : '',
764 ),
765 )
766 );
767 if ($field['description']) {
768 $elements[] = $this->auto_field(
769 $field,
770 array(
771 'type' => 'e2pdf-html',
772 'properties' => array(
773 'top' => '20',
774 'left' => '20',
775 'right' => '20',
776 'width' => $width . '%',
777 'height' => 'auto',
778 'value' => $field['description'],
779 ),
780 )
781 );
782 }
783 break;
784 case 'payment-total':
785 case 'payment-single':
786 $elements[] = $this->auto_field(
787 $field,
788 array(
789 'type' => 'e2pdf-html',
790 'block' => true,
791 'float' => true,
792 'properties' => array(
793 'top' => '20',
794 'left' => '20',
795 'right' => '20',
796 'width' => $width . '%',
797 'height' => 'auto',
798 'value' => isset($field['label']) && $field['label'] ? $field['label'] . ': ' . $field_value : $field_value,
799 ),
800 )
801 );
802 break;
803 case 'html':
804 case 'content':
805 $label = isset($field['label']) && $field['label'] ? $field['label'] : '';
806 if ($label) {
807 $elements[] = $this->auto_field(
808 $field,
809 array(
810 'type' => 'e2pdf-html',
811 'block' => true,
812 'float' => true,
813 'properties' => array(
814 'top' => '20',
815 'left' => '20',
816 'right' => '20',
817 'width' => $width . '%',
818 'height' => 'auto',
819 'value' => isset($field['label']) ? $field['label'] : '',
820 ),
821 )
822 );
823 }
824 if ($field['type'] == 'code') {
825 $content = isset($field['code']) && $field['code'] ? $field['code'] : '';
826 } else {
827 $content = isset($field['content']) && $field['content'] ? $field['content'] : '';
828 }
829 if ($content) {
830 $elements[] = $this->auto_field(
831 $field,
832 array(
833 'type' => 'e2pdf-html',
834 'block' => true,
835 'float' => true,
836 'properties' => array(
837 'top' => '20',
838 'left' => '20',
839 'right' => '20',
840 'width' => $width . '%',
841 'height' => 'auto',
842 'value' => $content,
843 ),
844 )
845 );
846 }
847 break;
848 case 'name':
849 case 'text':
850 case 'number':
851 case 'email':
852 case 'number-slider':
853 case 'phone':
854 case 'date-time':
855 case 'url':
856 case 'rating':
857 case 'hidden':
858 case 'payment-coupon':
859 $elements[] = $this->auto_field(
860 $field,
861 array(
862 'type' => 'e2pdf-html',
863 'block' => true,
864 'float' => true,
865 'properties' => array(
866 'top' => '20',
867 'left' => '20',
868 'right' => '20',
869 'width' => $width . '%',
870 'height' => 'auto',
871 'value' => isset($field['label']) ? $field['label'] : '',
872 ),
873 )
874 );
875
876 $elements[] = $this->auto_field(
877 $field,
878 array(
879 'type' => 'e2pdf-input',
880 'properties' => array(
881 'top' => '5',
882 'width' => '100%',
883 'height' => 'auto',
884 'value' => $field_value,
885 ),
886 )
887 );
888 break;
889 case 'select':
890 case 'payment-select':
891 $elements[] = $this->auto_field(
892 $field,
893 array(
894 'type' => 'e2pdf-html',
895 'block' => true,
896 'float' => true,
897 'properties' => array(
898 'top' => '20',
899 'left' => '20',
900 'right' => '20',
901 'width' => $width . '%',
902 'height' => 'auto',
903 'value' => isset($field['label']) ? $field['label'] : '',
904 ),
905 )
906 );
907 $field_options = array();
908 foreach ($field['choices'] as $option) {
909 $option_value = isset($option['label']) ? $option['label'] : '';
910 if ($field['type'] == 'payment-select') {
911 $option_value .= isset($option['value']) ? ' - ' . html_entity_decode(wpforms_format_amount(wpforms_sanitize_amount($option['value']), true)) : '';
912 }
913 $field_options[] = $option_value;
914 }
915 if (isset($field['multiple']) && $field['multiple']) {
916
917 $elements[] = $this->auto_field(
918 $field,
919 array(
920 'type' => 'e2pdf-select',
921 'properties' => array(
922 'top' => '5',
923 'width' => '100%',
924 'height' => '44',
925 'multiline' => '1',
926 'options' => implode("\n", $field_options),
927 'value' => $field_value,
928 ),
929 )
930 );
931 } else {
932 $elements[] = $this->auto_field(
933 $field,
934 array(
935 'type' => 'e2pdf-select',
936 'properties' => array(
937 'top' => '5',
938 'width' => '100%',
939 'height' => 'auto',
940 'options' => implode("\n", $field_options),
941 'value' => $field_value,
942 ),
943 )
944 );
945 }
946 break;
947 case 'textarea':
948 case 'address':
949 case 'file-upload':
950 $elements[] = $this->auto_field(
951 $field,
952 array(
953 'type' => 'e2pdf-html',
954 'block' => true,
955 'float' => true,
956 'properties' => array(
957 'top' => '20',
958 'left' => '20',
959 'right' => '20',
960 'width' => $width . '%',
961 'height' => 'auto',
962 'value' => isset($field['label']) ? $field['label'] : '',
963 ),
964 )
965 );
966 $elements[] = $this->auto_field(
967 $field,
968 array(
969 'type' => 'e2pdf-textarea',
970 'properties' => array(
971 'top' => '5',
972 'width' => '100%',
973 'height' => 'auto',
974 'value' => $field_value,
975 ),
976 )
977 );
978 break;
979 case 'richtext':
980 $elements[] = $this->auto_field(
981 $field,
982 array(
983 'type' => 'e2pdf-html',
984 'block' => true,
985 'float' => true,
986 'properties' => array(
987 'top' => '20',
988 'left' => '20',
989 'right' => '20',
990 'width' => $width . '%',
991 'height' => 'auto',
992 'value' => isset($field['label']) ? $field['label'] : '',
993 ),
994 )
995 );
996 $elements[] = $this->auto_field(
997 $field,
998 array(
999 'type' => 'e2pdf-html',
1000 'properties' => array(
1001 'top' => '5',
1002 'width' => '100%',
1003 'height' => '150',
1004 'value' => $field_value,
1005 ),
1006 )
1007 );
1008 break;
1009 case 'radio':
1010 case 'payment-multiple':
1011 $elements[] = $this->auto_field(
1012 $field,
1013 array(
1014 'type' => 'e2pdf-html',
1015 'block' => true,
1016 'float' => true,
1017 'properties' => array(
1018 'top' => '20',
1019 'left' => '20',
1020 'right' => '20',
1021 'width' => $width . '%',
1022 'height' => 'auto',
1023 'value' => isset($field['label']) ? $field['label'] : '',
1024 ),
1025 )
1026 );
1027
1028 foreach ($field['choices'] as $opt_key => $option) {
1029 $option_value = isset($option['label']) ? $option['label'] : '';
1030 if ($field['type'] == 'payment-multiple') {
1031 $option_value .= isset($option['value']) ? ' - ' . html_entity_decode(wpforms_format_amount(wpforms_sanitize_amount($option['value']), true)) : '';
1032 }
1033 $elements[] = $this->auto_field(
1034 $field,
1035 array(
1036 'type' => 'e2pdf-radio',
1037 'properties' => array(
1038 'top' => '5',
1039 'width' => 'auto',
1040 'height' => 'auto',
1041 'value' => $field_value,
1042 'option' => sanitize_text_field($option_value),
1043 'group' => $field_value,
1044 ),
1045 )
1046 );
1047 $elements[] = $this->auto_field(
1048 $field,
1049 array(
1050 'type' => 'e2pdf-html',
1051 'float' => true,
1052 'properties' => array(
1053 'left' => '5',
1054 'width' => '100%',
1055 'height' => 'auto',
1056 'value' => !empty($field['show_price_after_labels']) ? $option_value : $option['label'],
1057 ),
1058 )
1059 );
1060 }
1061 break;
1062 case 'checkbox':
1063 case 'payment-checkbox':
1064 $elements[] = $this->auto_field(
1065 $field,
1066 array(
1067 'type' => 'e2pdf-html',
1068 'block' => true,
1069 'float' => true,
1070 'properties' => array(
1071 'top' => '20',
1072 'left' => '20',
1073 'right' => '20',
1074 'width' => $width . '%',
1075 'height' => 'auto',
1076 'value' => isset($field['label']) ? $field['label'] : '',
1077 ),
1078 )
1079 );
1080 foreach ($field['choices'] as $opt_key => $option) {
1081 $option_value = isset($option['label']) ? $option['label'] : '';
1082 if ($field['type'] == 'payment-checkbox') {
1083 $option_value .= isset($option['value']) ? ' - ' . html_entity_decode(wpforms_format_amount(wpforms_sanitize_amount($option['value']), true)) : '';
1084 }
1085
1086 $elements[] = $this->auto_field(
1087 $field,
1088 array(
1089 'type' => 'e2pdf-checkbox',
1090 'properties' => array(
1091 'top' => '5',
1092 'width' => 'auto',
1093 'height' => 'auto',
1094 'value' => $field_value,
1095 'option' => sanitize_text_field($option_value),
1096 ),
1097 )
1098 );
1099 $elements[] = $this->auto_field(
1100 $field,
1101 array(
1102 'type' => 'e2pdf-html',
1103 'float' => true,
1104 'properties' => array(
1105 'left' => '5',
1106 'width' => '100%',
1107 'height' => 'auto',
1108 'value' => !empty($field['show_price_after_labels']) ? $option_value : $option['label'],
1109 ),
1110 )
1111 );
1112 }
1113 break;
1114 case 'signature':
1115 $elements[] = $this->auto_field(
1116 $field,
1117 array(
1118 'type' => 'e2pdf-html',
1119 'block' => true,
1120 'float' => true,
1121 'properties' => array(
1122 'top' => '20',
1123 'left' => '20',
1124 'right' => '20',
1125 'width' => $width . '%',
1126 'height' => 'auto',
1127 'value' => isset($field['label']) ? $field['label'] : '',
1128 ),
1129 )
1130 );
1131 $elements[] = $this->auto_field(
1132 $field,
1133 array(
1134 'type' => 'e2pdf-signature',
1135 'properties' => array(
1136 'top' => '5',
1137 'width' => '100%',
1138 'height' => '150',
1139 'dimension' => '1',
1140 'block_dimension' => '1',
1141 'value' => $field_value,
1142 ),
1143 )
1144 );
1145 break;
1146 case 'likert_scale':
1147 $elements[] = $this->auto_field(
1148 $field,
1149 array(
1150 'type' => 'e2pdf-html',
1151 'block' => true,
1152 'properties' => array(
1153 'top' => '20',
1154 'left' => '20',
1155 'right' => '20',
1156 'width' => $width . '%',
1157 'height' => 'auto',
1158 'value' => isset($field['label']) ? $field['label'] : '',
1159 ),
1160 )
1161 );
1162 foreach ($field['rows'] as $key => $sub_field) {
1163 if (isset($field['columns']) && is_array($field['columns'])) {
1164 if (!empty($field['single_row'])) {
1165 $width = 100 / (count($field['columns']));
1166 } else {
1167 $width = 100 / (count($field['columns']) + 1);
1168 }
1169 if (empty($field['single_row'])) {
1170 $elements[] = $this->auto_field(
1171 $field,
1172 array(
1173 'type' => 'e2pdf-html',
1174 'block' => true,
1175 'hidden' => true,
1176 'properties' => array(
1177 'top' => '5',
1178 'left' => '20',
1179 'right' => '20',
1180 'width' => $width . '%',
1181 'height' => 'auto',
1182 'value' => '',
1183 ),
1184 )
1185 );
1186 }
1187 foreach ($field['columns'] as $opt_key => $option) {
1188 $elements[] = $this->auto_field(
1189 $field,
1190 array(
1191 'type' => 'e2pdf-html',
1192 'float' => true,
1193 'block' => true,
1194 'properties' => array(
1195 'top' => '10',
1196 'left' => '20',
1197 'right' => '20',
1198 'width' => $width . '%',
1199 'height' => 'auto',
1200 'value' => $option,
1201 ),
1202 )
1203 );
1204 }
1205 }
1206 break;
1207 }
1208 foreach ($field['rows'] as $key => $sub_field) {
1209 if (isset($field['columns']) && is_array($field['columns'])) {
1210 if (!empty($field['single_row'])) {
1211 $width = 100 / (count($field['columns']));
1212 } else {
1213 $width = 100 / (count($field['columns']) + 1);
1214 }
1215 if (empty($field['single_row'])) {
1216 $elements[] = $this->auto_field(
1217 $field,
1218 array(
1219 'type' => 'e2pdf-html',
1220 'block' => true,
1221 'properties' => array(
1222 'top' => '5',
1223 'left' => '20',
1224 'right' => '20',
1225 'width' => $width . '%',
1226 'height' => 'auto',
1227 'value' => $sub_field,
1228 ),
1229 )
1230 );
1231 }
1232 foreach ($field['columns'] as $opt_key => $option) {
1233 $elements[] = $this->auto_field(
1234 $field,
1235 array(
1236 'type' => 'e2pdf-html',
1237 'float' => true,
1238 'block' => true,
1239 'hidden' => true,
1240 'properties' => array(
1241 'top' => '5',
1242 'left' => '20',
1243 'right' => '20',
1244 'width' => $width . '%',
1245 'height' => '5',
1246 'value' => '',
1247 ),
1248 )
1249 );
1250 $field_value = '{field_id="' . $field_id . '|' . $key . '"}';
1251 if (!empty($field['multiple_responses'])) {
1252 $elements[] = $this->auto_field(
1253 $field,
1254 array(
1255 'type' => 'e2pdf-checkbox',
1256 'properties' => array(
1257 'top' => '-5',
1258 'width' => 'auto',
1259 'height' => 'auto',
1260 'value' => $field_value,
1261 'option' => $opt_key,
1262 ),
1263 )
1264 );
1265 } else {
1266 $elements[] = $this->auto_field(
1267 $field,
1268 array(
1269 'type' => 'e2pdf-radio',
1270 'properties' => array(
1271 'top' => '-5',
1272 'width' => 'auto',
1273 'height' => 'auto',
1274 'value' => $field_value,
1275 'option' => $opt_key,
1276 'group' => $field_value,
1277 ),
1278 )
1279 );
1280 }
1281 }
1282 if (!empty($field['single_row'])) {
1283 break;
1284 }
1285 }
1286 }
1287 break;
1288 default:
1289 break;
1290 }
1291 }
1292 }
1293 $response = array();
1294 $response['page'] = array(
1295 'bottom' => '20',
1296 'top' => '20',
1297 'left' => '20',
1298 'right' => '20',
1299 );
1300
1301 $response['elements'] = $elements;
1302 return $response;
1303 }
1304
1305 // inner field
1306 public function inner_field($array, $id) {
1307 foreach ($array as $index => $item) {
1308 if (is_array($item)) {
1309 if (isset($item['id']) && $item['id'] == $id) {
1310 return $index;
1311 }
1312 }
1313 }
1314 return false;
1315 }
1316
1317 // auto field
1318 public function auto_field($field = false, $element = array()) {
1319 if (!$field) {
1320 return false;
1321 }
1322 return $element;
1323 }
1324
1325 // verify
1326 public function verify() {
1327 if ($this->get('cached_form') && $this->get('cached_entry') && $this->get('cached_form')->ID == $this->get('cached_entry')->form_id) {
1328 return true;
1329 }
1330 return false;
1331 }
1332
1333 // visual mapper
1334 public function visual_mapper() {
1335 $html = '';
1336 $source = '';
1337 if ($this->get('item')) {
1338 ob_start();
1339 add_filter('wpforms_forms_anti_spam_v3_is_honeypot_enabled', '__return_false');
1340 echo do_shortcode('[wpforms id="' . $this->get('item') . '"]');
1341 add_filter('wpforms_forms_anti_spam_v3_is_honeypot_enabled', '__return_true');
1342 $source = ob_get_clean();
1343 if ($source) {
1344 $dom = new DOMDocument();
1345 $html = $this->helper->load('convert')->load_html(preg_replace('/<script\b[^>]*>.*?<\/script>/is', '', $source), $dom, true);
1346 }
1347
1348 if (ob_get_length() > 0) {
1349 while (@ob_end_clean()); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
1350 }
1351 if (!$source) {
1352 return '<div class="e2pdf-vm-error">' . __("The form source is empty or doesn't exist", 'e2pdf') . '</div>';
1353 } elseif (!$html) {
1354 return '<div class="e2pdf-vm-error">' . __('The form could not be parsed due the incorrect HTML', 'e2pdf') . '</div>';
1355 } else {
1356 $form_handler = new WPForms_Form_Handler();
1357 $xml = new Helper_E2pdf_Xml();
1358 $xpath = new DomXPath($dom);
1359
1360 // remove by name
1361 $remove_by_name = array(
1362 'wpforms[id]',
1363 'wpforms[nonce]',
1364 'page_title',
1365 'page_url',
1366 'url_referer',
1367 );
1368 foreach ($remove_by_name as $key => $name) {
1369 $elements = $xpath->query('//*[@name="' . $name . '"]');
1370 foreach ($elements as $element) {
1371 $element->parentNode->removeChild($element);
1372 }
1373 }
1374
1375 // remove by tag
1376 $remove_by_tag = array(
1377 'script',
1378 'noscript',
1379 );
1380 foreach ($remove_by_tag as $key => $tag) {
1381 $elements = $xpath->query('//' . $tag);
1382 foreach ($elements as $element) {
1383 $element->parentNode->removeChild($element);
1384 }
1385 }
1386
1387 // remove by class
1388 $remove_by_class = array(
1389 'wpforms-page-button',
1390 'wpforms-field-pagebreak',
1391 'wpforms-signature-wrap',
1392 'dz-message',
1393 'wp-editor-tabs',
1394 'wpforms-page-indicator progress',
1395 'quicktags-toolbar',
1396 'wpforms-field-entry-preview',
1397 'wpforms-field-payment-coupon-button',
1398 'wpforms-single-item-price',
1399 );
1400 foreach ($remove_by_class as $key => $class) {
1401 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
1402 foreach ($elements as $element) {
1403 $element->parentNode->removeChild($element);
1404 }
1405 }
1406
1407 // remove styles
1408 $remove_styles = array(
1409 'wpforms-page',
1410 'dropzone-input',
1411 'wpforms-conditional-field',
1412 );
1413 foreach ($remove_styles as $key => $class) {
1414 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
1415 foreach ($elements as $element) {
1416 $xml->set_node_value($element, 'style', '');
1417 }
1418 }
1419
1420 $elements = $xpath->query("//*[contains(@class, 'wpforms-field-payment-checkbox') or contains(@class, 'wpforms-field-payment-multiple') or contains(@class, 'wpforms-field-payment-select')]");
1421 foreach ($elements as $element) {
1422 $field_id = $xml->get_node_value($element, 'data-field-id');
1423 $field = $form_handler->get_field($this->get('item'), $field_id);
1424 $sub_elements = $xpath->query('.//input|.//option', $element);
1425 foreach ($sub_elements as $sub_element) {
1426 $field_value = $xml->get_node_value($sub_element, 'value');
1427 $option_value = '';
1428 if ($field_value) {
1429 if (isset($field['choices'][$field_value])) {
1430 $option = $field['choices'][$field_value];
1431 $option_value = isset($option['label']) ? $option['label'] : '';
1432 $option_value .= isset($option['value']) ? ' - ' . html_entity_decode(wpforms_format_amount(wpforms_sanitize_amount($option['value']), true)) : '';
1433 }
1434 }
1435 $xml->set_node_value($sub_element, 'value', $option_value);
1436 }
1437 }
1438 $elements = $xpath->query("//*[contains(@class, 'wpforms-field-payment-single') or contains(@class, 'wpforms-field-payment-total')]");
1439 foreach ($elements as $element) {
1440 $sub_elements = $xpath->query('.//input', $element);
1441 foreach ($sub_elements as $sub_element) {
1442 $xml->set_node_value($sub_element, 'type', 'text');
1443 $xml->set_node_value($sub_element, 'class', '');
1444 }
1445 }
1446
1447 // remove by class
1448 $remove_by_class = array(
1449 'wpforms-payment-total',
1450 );
1451 foreach ($remove_by_class as $key => $class) {
1452 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
1453 foreach ($elements as $element) {
1454 $element->parentNode->removeChild($element);
1455 }
1456 }
1457
1458 $elements = $xpath->query("//*[contains(@class, 'wpforms-field-repeater-display-rows')]");
1459 foreach ($elements as $element) {
1460 $sub_elements = $xpath->query('.//input|.//textarea|.//select', $element);
1461 foreach ($sub_elements as $sub_element) {
1462 $xml->set_node_value($sub_element, 'name', preg_replace('/(wpforms\[fields\]\[)(\d+)(\].*)/', '$1$2_1$3', $xml->get_node_value($sub_element, 'name')));
1463 }
1464 }
1465 $elements = $xpath->query("//*[contains(@class, 'wpforms-field-likert_scale')]");
1466 foreach ($elements as $element) {
1467 $sub_elements = $xpath->query('.//input', $element);
1468 foreach ($sub_elements as $sub_element) {
1469 $xml->set_node_value($sub_element, 'name', preg_replace('/(wpforms\[fields\]\[)(\d+)(\]\[)(\d+)(\].*)/', '$1$2|$4$5', $xml->get_node_value($sub_element, 'name')));
1470 }
1471 }
1472 $elements = $xpath->query("//*[contains(@class, 'dropzone-input')]");
1473 foreach ($elements as $element) {
1474 $xml->set_node_value($element, 'name', preg_replace('/wpforms_\d+_(\d+)/', 'wpforms[fields][$1]', $xml->get_node_value($element, 'name')));
1475 }
1476
1477 // radio, checkbox mapping html value fix
1478 $elements = $xpath->query('//input[@type="checkbox"]|//input[@type="radio"]');
1479 foreach ($elements as $element) {
1480 $value = $xml->get_node_value($element, 'value');
1481 if ($value) {
1482 $xml->set_node_value($element, 'value', sanitize_text_field($value));
1483 }
1484 }
1485
1486 $elements = $xpath->query('//input|//textarea|//select');
1487 foreach ($elements as $element) {
1488 $xml->set_node_value($element, 'name', '{field_id="' . preg_replace('/wpforms\[fields\]\[(\d+|\d+_\d+|\d+\|\d+)\].*/', '$1', $xml->get_node_value($element, 'name')) . '"}');
1489 }
1490 $submit_buttons = $xpath->query("//input[@type='submit']|//button[@type='submit']");
1491 foreach ($submit_buttons as $element) {
1492 $element->parentNode->removeChild($element);
1493 }
1494
1495 if (defined('LIBXML_HTML_NOIMPLIED') && defined('LIBXML_HTML_NODEFDTD')) {
1496 return str_replace(array('<html>', '</html>'), '', $dom->saveHTML());
1497 } else {
1498 return $dom->saveHTML();
1499 }
1500 }
1501 }
1502 return false;
1503 }
1504
1505 // load shortcodes
1506 public function load_shortcodes() { // phpcs:ignore Squiz.WhiteSpace.SuperfluousWhitespace.EndLine
1507 }
1508
1509 // styles
1510 public function styles($item_id = false) {
1511 $styles = array();
1512 if (defined('WPFORMS_PLUGIN_URL')) {
1513 if (defined('WPFORMS_PLUGIN_SLUG') && WPFORMS_PLUGIN_SLUG == 'wpforms') {
1514 $styles[] = WPFORMS_PLUGIN_URL . 'assets/pro/css/fields/content/frontend.min.css';
1515 $styles[] = WPFORMS_PLUGIN_URL . 'assets/pro/css/fields/layout.min.css';
1516 $styles[] = WPFORMS_PLUGIN_URL . 'assets/pro/css/fields/repeater.min.css';
1517 }
1518 $styles[] = WPFORMS_PLUGIN_URL . 'assets/css/frontend/modern/wpforms-full.min.css';
1519
1520 if (function_exists('wpforms_surveys_polls') && isset(wpforms_surveys_polls()->url)) {
1521 $styles[] = wpforms_surveys_polls()->url . 'assets/css/wpforms-surveys-polls.min.css';
1522 }
1523 }
1524 $styles[] = plugins_url('css/extension/wpforms.css?v=' . time(), $this->helper->get('plugin_file_path'));
1525 return $styles;
1526 }
1527
1528 // entry view hook
1529 public function hook_wpforms_entry_view($entry) {
1530 if (!empty($entry->form_id)) {
1531 $hooks = $this->helper->load('hooks')->get('wpforms', 'hook_wpforms_entry_view', $entry->form_id);
1532 if (!empty($hooks)) {
1533 echo '<div id="wpforms-entry-actions" class="postbox">';
1534 echo '<div class="postbox-header"><h2 class="hndle"><span>' . apply_filters('e2pdf_hook_section_title', __('E2Pdf Actions', 'e2pdf'), 'hook_wpforms_entry_view') . '</span></h2></div>';
1535 echo '<div class="inside">';
1536 echo '<div class="wpforms-entry-actions-meta">';
1537 foreach ($hooks as $hook) {
1538 if ($this->helper->load('hooks')->process_hook(
1539 $hook,
1540 [
1541 'dataset' => $entry->entry_id,
1542 ],
1543 'hook_wpforms_entry_view'
1544 )
1545 ) {
1546 $action = apply_filters(
1547 'e2pdf_hook_action_button',
1548 array(
1549 'html' => '<p style="padding: 6px 12px 6.5px 42px"><a class="e2pdf-download-hook" target="_blank" href="%s"><span class="dashicons dashicons-pdf"></span> %s</a></p>',
1550 'url' => $this->helper->get_url(
1551 array(
1552 'page' => 'e2pdf',
1553 'action' => 'export',
1554 'id' => $hook,
1555 'dataset' => $entry->entry_id,
1556 ), 'admin.php?'
1557 ),
1558 'title' => 'PDF #' . $hook,
1559 ), 'hook_wpforms_entry_view', $hook, $entry->entry_id
1560 );
1561 if (!empty($action)) {
1562 echo sprintf(
1563 $action['html'], $action['url'], $action['title']
1564 );
1565 }
1566 }
1567 }
1568 echo '</div>';
1569 echo '</div>';
1570 echo '</div>';
1571 }
1572 }
1573 }
1574
1575 // entry edit hook
1576 public function hook_wpforms_entry_edit($entry) {
1577 if (!empty($entry->form_id)) {
1578 $hooks = $this->helper->load('hooks')->get('wpforms', 'hook_wpforms_entry_edit', $entry->form_id);
1579 if (!empty($hooks)) {
1580 echo '<div id="wpforms-entry-actions" class="postbox">';
1581 echo '<div class="postbox-header"><h2 class="hndle"><span>' . apply_filters('e2pdf_hook_section_title', __('E2Pdf Actions', 'e2pdf'), 'hook_wpforms_entry_edit') . '</span></h2></div>';
1582 echo '<div class="inside">';
1583 echo '<div class="wpforms-entry-actions-meta">';
1584 foreach ($hooks as $hook) {
1585 if ($this->helper->load('hooks')->process_hook(
1586 $hook,
1587 [
1588 'dataset' => $entry->entry_id,
1589 ],
1590 'hook_wpforms_entry_edit'
1591 )
1592 ) {
1593 $action = apply_filters(
1594 'e2pdf_hook_action_button',
1595 array(
1596 'html' => '<p style="padding: 6px 12px 6.5px 42px"><a class="e2pdf-download-hook" target="_blank" href="%s"><span class="dashicons dashicons-pdf"></span> %s</a></p>',
1597 'url' => $this->helper->get_url(
1598 array(
1599 'page' => 'e2pdf',
1600 'action' => 'export',
1601 'id' => $hook,
1602 'dataset' => $entry->entry_id,
1603 ), 'admin.php?'
1604 ),
1605 'title' => 'PDF #' . $hook,
1606 ), 'hook_wpforms_entry_edit', $hook, $entry->entry_id
1607 );
1608 if (!empty($action)) {
1609 echo sprintf(
1610 $action['html'], $action['url'], $action['title']
1611 );
1612 }
1613 }
1614 }
1615 echo '</div>';
1616 echo '</div>';
1617 echo '</div>';
1618 }
1619 }
1620 }
1621
1622 // row actions hook
1623 public function hook_wpforms_row_actions($actions, $entry) {
1624 if (!empty($entry->form_id)) {
1625 $hooks = $this->helper->load('hooks')->get('wpforms', 'hook_wpforms_row_actions', $entry->form_id);
1626 foreach ($hooks as $hook) {
1627 if ($this->helper->load('hooks')->process_hook(
1628 $hook,
1629 [
1630 'dataset' => $entry->entry_id,
1631 ],
1632 'hook_wpforms_row_actions'
1633 )
1634 ) {
1635 $action = apply_filters(
1636 'e2pdf_hook_action_button',
1637 array(
1638 'html' => '<a class="e2pdf-download-hook" target="_blank" href="%s">%s</a>',
1639 'url' => $this->helper->get_url(
1640 array(
1641 'page' => 'e2pdf',
1642 'action' => 'export',
1643 'id' => $hook,
1644 'dataset' => $entry->entry_id,
1645 ), 'admin.php?'
1646 ),
1647 'title' => 'PDF #' . $hook,
1648 ), 'hook_wpforms_row_actions', $hook, $entry->entry_id
1649 );
1650 if (!empty($action)) {
1651 $actions['e2pdf_' . $hook] = sprintf(
1652 $action['html'], $action['url'], $action['title']
1653 );
1654 }
1655 }
1656 }
1657 }
1658 return $actions;
1659 }
1660 }
1661