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-wpforms.php

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

1,651 lines 79.3 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
400 // frontend confirmation message filter
401 public function filter_wpforms_frontend_confirmation_message($message, $form_data, $fields, $dataset) {
402 if (false !== strpos($message, '[')) {
403 $shortcode_tags = array(
404 'e2pdf-download',
405 'e2pdf-save',
406 'e2pdf-view',
407 'e2pdf-adobesign',
408 'e2pdf-zapier',
409 );
410 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $message, $matches);
411 $tagnames = array_intersect($shortcode_tags, $matches[1]);
412 if (!empty($tagnames)) {
413 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $message, $shortcodes);
414 foreach ($shortcodes[0] as $key => $shortcode_value) {
415 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
416 $atts = shortcode_parse_atts($shortcode[3]);
417 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
418 } else {
419 if (!isset($atts['dataset']) && isset($atts['id'])) {
420 $template = new Model_E2pdf_Template();
421 $template->load($atts['id']);
422 if ($template->get('extension') === 'wpforms') {
423 $atts['dataset'] = $dataset;
424 $shortcode[3] .= ' dataset="' . $dataset . '"';
425 }
426 }
427 if (!isset($atts['apply'])) {
428 $shortcode[3] .= ' apply="true"';
429 }
430 if (!isset($atts['iframe_download'])) {
431 $shortcode[3] .= ' iframe_download="true"';
432 }
433 $message = str_replace($shortcode_value, do_shortcode_tag($shortcode), $message);
434 }
435 }
436 }
437 }
438 return $message;
439 }
440
441 // send email data filter
442 public function filter_wpforms_emails_send_email_data($mail, $data) {
443 if ($mail && isset($mail['message'])) {
444 if (false !== strpos($mail['message'], '[')) {
445 $shortcode_tags = array(
446 'e2pdf-download',
447 'e2pdf-save',
448 'e2pdf-attachment',
449 'e2pdf-adobesign',
450 'e2pdf-zapier',
451 );
452 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $mail['message'], $matches);
453 $tagnames = array_intersect($shortcode_tags, $matches[1]);
454 if (!empty($tagnames)) {
455 $options = get_option('wpforms_settings', false);
456 $async = is_array($options) && !empty($options['email-async']) ? wp_unslash($options['email-async']) : false;
457 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $mail['message'], $shortcodes);
458 foreach ($shortcodes[0] as $key => $shortcode_value) {
459 $file = false;
460 $transient = false;
461 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
462 $atts = shortcode_parse_atts($shortcode[3]);
463 if (!isset($atts['dataset']) && isset($atts['id'])) {
464 $template = new Model_E2pdf_Template();
465 $template->load($atts['id']);
466 if ($template->get('extension') === 'wpforms') {
467 if (isset($data->entry_id) && $data->entry_id) {
468 $atts['dataset'] = $data->entry_id;
469 $shortcode[3] .= ' dataset="' . $data->entry_id . '"';
470 } elseif ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) {
471 $dataset = 'tmp_' . $this->helper->load('encryption')->random_md5();
472 $transient = 'e2pdf_' . $dataset;
473 set_transient($transient, $data->fields, 1800);
474 $atts['dataset'] = $dataset;
475 $shortcode[3] .= ' dataset="' . $dataset . '"';
476 }
477 }
478 }
479 if (!isset($atts['apply'])) {
480 $shortcode[3] .= ' apply="true"';
481 }
482 if (!isset($atts['filter'])) {
483 $shortcode[3] .= ' filter="true"';
484 }
485 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) {
486 if ($async) {
487 $mail['message'] = str_replace($shortcode_value, '{{' . $shortcode[2] . $shortcode[3] . '}}', $mail['message']);
488 } else {
489 $file = do_shortcode_tag($shortcode);
490 if ($file) {
491 $tmp = false;
492 if (substr($file, 0, 4) === 'tmp:') {
493 $file = substr($file, 4);
494 $tmp = true;
495 }
496 if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
497 if ($tmp) {
498 $this->helper->add('wpforms_attachments', $file);
499 }
500 } else {
501 $this->helper->add('wpforms_attachments', $file);
502 }
503 $mail['attachments'][] = $file;
504 }
505 $mail['message'] = str_replace($shortcode_value, '', $mail['message']);
506 if ($transient) {
507 delete_transient($transient);
508 }
509 }
510 } else {
511 $mail['message'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $mail['message']);
512 if ($transient) {
513 delete_transient($transient);
514 }
515 }
516 }
517 }
518 }
519 }
520 return $mail;
521 }
522
523 // render shortcodes
524 public function render_shortcodes($value, $field = array()) {
525 $element_id = isset($field['element_id']) ? $field['element_id'] : false;
526 if ($this->verify()) {
527 if (false !== strpos($value, '[')) {
528 $value = $this->helper->load('field')->pre_shortcodes($value, $this, $field);
529 $value = $this->helper->load('field')->inner_shortcodes($value, $this, $field);
530 $value = $this->helper->load('field')->wrapper_shortcodes($value, $this, $field);
531 }
532 $value = $this->helper->load('field')->do_shortcodes($value, $this, $field);
533 if (function_exists('wpforms_process_smart_tags')) {
534 add_filter('wpforms_smart_tags_formatted_field_value', array($this, 'filter_wpforms_smart_tags_formatted_field_value'), 99, 4);
535 add_filter('wpforms_smarttags_process_value', array($this, 'filter_wpforms_smarttags_process_value'), 10, 6);
536 $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);
537 remove_filter('wpforms_smarttags_process_value', array($this, 'filter_wpforms_smarttags_process_value'), 10);
538 remove_filter('wpforms_smart_tags_formatted_field_value', array($this, 'filter_wpforms_smart_tags_formatted_field_value'), 99);
539 }
540 $value = $this->helper->load('field')->render(
541 apply_filters('e2pdf_extension_render_shortcodes_pre_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false),
542 $this,
543 $field
544 );
545 }
546 return apply_filters(
547 'e2pdf_extension_render_shortcodes_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false
548 );
549 }
550
551 // wpforms checkboxes, multi-selects, and payment checkboxes in email PDF attachments
552 public function filter_wpforms_smart_tags_formatted_field_value($value, $field_id, $fields, $field_key) {
553 if (function_exists('wpforms_get_multi_fields')) {
554 $field_type = $fields[$field_id]['type'] ?? '';
555 if (in_array($field_type, wpforms_get_multi_fields(), true)) {
556 return $fields[$field_id][$field_key] ?? '';
557 }
558 }
559 return $value;
560 }
561
562 // smarttags process value filter
563 public function filter_wpforms_smarttags_process_value($value, $tag_name, $form_data, $fields, $entry_id, $smart_tag_object) {
564
565 $field_id = $smart_tag_object->get_attributes()['field_id'] ?? 0;
566 $field_id = explode('|', $field_id)[0];
567
568 if (false !== strpos($field_id, '_')) {
569 $repeater = array_map('intval', explode('_', $field_id, 2));
570 if (wpforms_is_repeated_field($repeater[0], $fields)) {
571 $prefix = $repeater[1] == '1' ? $repeater[0] : $repeater[0] . '_' . $repeater[1];
572 if ($tag_name == 'field_value_id') {
573 $field_key = isset($fields[$prefix]['value_raw']) && !is_array($fields[$prefix]['value_raw']) && (string) $fields[$prefix]['value_raw'] !== '' ? 'value_raw' : 'value';
574 } else {
575 $field_key = 'value';
576 }
577 $value = isset($fields[$prefix][$field_key]) ? $fields[$prefix][$field_key] : '';
578 }
579 }
580
581 if (false === strpos($field_id, '_') && apply_filters('e2pdf_for_do_shortcode_data_process', false) && wpforms_is_repeated_field((int) $field_id, $fields)) {
582 $values = array();
583 $prefix = (int) $field_id . '_';
584 foreach ($fields as $key => $field) {
585 if (strpos($key, $prefix) === 0 || $key == (int) $field_id) {
586 $values[] = $field;
587 }
588 }
589 $value = serialize($values); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
590 } else {
591 if (
592 $this->get_field_property('type', $smart_tag_object, $form_data, $tag_name) == 'checkbox' ||
593 ($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')
594 ) {
595 $value = implode(', ', explode("\n", $value));
596 } elseif ($this->get_field_property('type', $smart_tag_object, $form_data, $tag_name) == 'payment-checkbox') {
597 if ($tag_name == 'field_value_id') {
598 $value = implode(', ', explode(',', $value));
599 } else {
600 $value = implode(', ', explode("\r\n", $value));
601 }
602 } elseif ($this->get_field_property('type', $smart_tag_object, $form_data, $tag_name) == 'likert_scale') {
603 $sub_field_id = $smart_tag_object->get_attributes()['field_id'] ?? 0;
604 $sub_field = explode('|', $sub_field_id);
605 if (isset($sub_field[1])) {
606 $row = $sub_field[1];
607 if (is_numeric($row)) {
608 $value = isset($fields[$field_id]['value_raw'][$row]) ? $fields[$field_id]['value_raw'][$row] : '';
609 if (is_array($value)) {
610 $value = implode(', ', $value);
611 }
612 } else {
613 $input = !empty($fields[$field_id]['value']) ? $fields[$field_id]['value'] : '';
614 $lines = explode("\n", $input);
615 $lines_count = count($lines);
616 $result = [];
617 for ($i = 0; $i < $lines_count; $i += 2) {
618 $key = trim($lines[$i], ":\n");
619 $value = isset($lines[$i + 1]) ? trim($lines[$i + 1]) : '';
620 $result[$key] = $value;
621 }
622 $value = isset($result[$row]) ? $result[$row] : '';
623 }
624 }
625 }
626 $entity_decode = array(
627 'payment-multiple',
628 'payment-checkbox',
629 'payment-total',
630 'payment-single',
631 'payment-select',
632 );
633 if (in_array($this->get_field_property('type', $smart_tag_object, $form_data, $tag_name), $entity_decode, true)) {
634 $value = html_entity_decode($value);
635 }
636 }
637 return $value;
638 }
639
640 public function get_field_property($attr, $smart_tag_object, $form_data, $tag_name) {
641 if (isset($smart_tag_object->get_attributes()[$tag_name])) {
642 $field_id = $smart_tag_object->get_attributes()['field_id'] ?? 0;
643 $field_id = (int) explode('|', $field_id)[0];
644 if (isset($form_data['fields'][$field_id][$attr])) {
645 return $form_data['fields'][$field_id][$attr];
646 }
647 }
648 return false;
649 }
650
651 // strip shortcodes
652 public function strip_shortcodes($value) {
653 $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', '', $value);
654 $value = preg_replace('~a\:\d+\:{[^}]*}(*SKIP)(*FAIL)|{[^}]*}~', '', $value);
655 return $value;
656 }
657
658 // strip math
659 public function strip_math($value, &$replacements) {
660 if ($value) {
661 preg_match_all('/\{[^}]+\}/', $value, $matches);
662 foreach ($matches[0] as $match) {
663 $index = count($replacements) + 1;
664 $replacements[] = $match;
665 $value = str_replace($match, '%' . $index . '$s', $value);
666 }
667 }
668 return $value;
669 }
670
671 // convert shortcodes
672 public function convert_shortcodes($value, $to = false, $html = false) {
673 if ($value) {
674 if ($to) {
675 $search = array('&#91;', '&#93;', '&#091;', '&#093;');
676 $replace = array('[', ']', '[', ']');
677 $value = str_replace($search, $replace, $value);
678 if (!$html) {
679 $value = wp_specialchars_decode($value, ENT_QUOTES);
680 }
681 } else {
682 $search = array('[', ']', '&#091;', '&#093;');
683 $replace = array('&#91;', '&#93;', '&#91;', '&#93;');
684 $value = str_replace($search, $replace, $value);
685 }
686 }
687 return $value;
688 }
689
690 // auto
691 public function auto() {
692
693 $elements = array();
694 if ($this->get('cached_form') && function_exists('wpforms_get_form_fields')) {
695 $form = wpforms_decode($this->get('cached_form')->post_content);
696 $form_fields = isset($form['fields']) ? $form['fields'] : array();
697 $sizes = array();
698 $repeaters = array();
699 $new_form_fields = array();
700
701 foreach ($form_fields as $field) {
702 if ($field['type'] == 'layout' || $field['type'] == 'repeater') {
703 foreach ($field['columns'] as $column) {
704 foreach ($column['fields'] as $sub_field) {
705 $sizes[$sub_field] = $column['width_preset'];
706 if ($field['type'] == 'repeater') {
707 $repeaters[] = $sub_field;
708 }
709 }
710 }
711 }
712 }
713
714 foreach ($form_fields as $field) {
715 if ($field['type'] == 'layout' || $field['type'] == 'repeater') {
716 foreach ($field['columns'] as $column) {
717 foreach ($column['fields'] as $sub_field) {
718 $found = $this->inner_field($form_fields, $sub_field);
719 if ($found !== false) {
720 $new_form_fields[] = $form_fields[$found];
721 }
722 }
723 }
724 } else {
725 $field_id = isset($field['id']) ? $field['id'] : '0';
726 if (!in_array($field_id, $repeaters, true) && !array_key_exists($field_id, $sizes)) {
727 $new_form_fields[] = $field;
728 }
729 }
730 }
731
732 foreach ($new_form_fields as $field) {
733 $width = '100';
734 $field_id = isset($field['id']) ? $field['id'] : '0';
735 $field_value = in_array($field_id, $repeaters, true) ? '{field_id="' . $field_id . '_1"}' : '{field_id="' . $field_id . '"}';
736 if (isset($sizes[$field_id])) {
737 $width = $sizes[$field_id];
738 }
739 switch ($field['type']) {
740 case 'divider':
741 $elements[] = $this->auto_field(
742 $field,
743 array(
744 'type' => 'e2pdf-html',
745 'block' => true,
746 'float' => true,
747 'properties' => array(
748 'top' => '20',
749 'left' => '20',
750 'right' => '20',
751 'width' => $width . '%',
752 'height' => 'auto',
753 'value' => isset($field['label']) ? $field['label'] : '',
754 ),
755 )
756 );
757 if ($field['description']) {
758 $elements[] = $this->auto_field(
759 $field,
760 array(
761 'type' => 'e2pdf-html',
762 'properties' => array(
763 'top' => '20',
764 'left' => '20',
765 'right' => '20',
766 'width' => $width . '%',
767 'height' => 'auto',
768 'value' => $field['description'],
769 ),
770 )
771 );
772 }
773 break;
774 case 'payment-total':
775 case 'payment-single':
776 $elements[] = $this->auto_field(
777 $field,
778 array(
779 'type' => 'e2pdf-html',
780 'block' => true,
781 'float' => true,
782 'properties' => array(
783 'top' => '20',
784 'left' => '20',
785 'right' => '20',
786 'width' => $width . '%',
787 'height' => 'auto',
788 'value' => isset($field['label']) && $field['label'] ? $field['label'] . ': ' . $field_value : $field_value,
789 ),
790 )
791 );
792 break;
793 case 'html':
794 case 'content':
795 $label = isset($field['label']) && $field['label'] ? $field['label'] : '';
796 if ($label) {
797 $elements[] = $this->auto_field(
798 $field,
799 array(
800 'type' => 'e2pdf-html',
801 'block' => true,
802 'float' => true,
803 'properties' => array(
804 'top' => '20',
805 'left' => '20',
806 'right' => '20',
807 'width' => $width . '%',
808 'height' => 'auto',
809 'value' => isset($field['label']) ? $field['label'] : '',
810 ),
811 )
812 );
813 }
814 if ($field['type'] == 'code') {
815 $content = isset($field['code']) && $field['code'] ? $field['code'] : '';
816 } else {
817 $content = isset($field['content']) && $field['content'] ? $field['content'] : '';
818 }
819 if ($content) {
820 $elements[] = $this->auto_field(
821 $field,
822 array(
823 'type' => 'e2pdf-html',
824 'block' => true,
825 'float' => true,
826 'properties' => array(
827 'top' => '20',
828 'left' => '20',
829 'right' => '20',
830 'width' => $width . '%',
831 'height' => 'auto',
832 'value' => $content,
833 ),
834 )
835 );
836 }
837 break;
838 case 'name':
839 case 'text':
840 case 'number':
841 case 'email':
842 case 'number-slider':
843 case 'phone':
844 case 'date-time':
845 case 'url':
846 case 'rating':
847 case 'hidden':
848 case 'payment-coupon':
849 $elements[] = $this->auto_field(
850 $field,
851 array(
852 'type' => 'e2pdf-html',
853 'block' => true,
854 'float' => true,
855 'properties' => array(
856 'top' => '20',
857 'left' => '20',
858 'right' => '20',
859 'width' => $width . '%',
860 'height' => 'auto',
861 'value' => isset($field['label']) ? $field['label'] : '',
862 ),
863 )
864 );
865
866 $elements[] = $this->auto_field(
867 $field,
868 array(
869 'type' => 'e2pdf-input',
870 'properties' => array(
871 'top' => '5',
872 'width' => '100%',
873 'height' => 'auto',
874 'value' => $field_value,
875 ),
876 )
877 );
878 break;
879 case 'select':
880 case 'payment-select':
881 $elements[] = $this->auto_field(
882 $field,
883 array(
884 'type' => 'e2pdf-html',
885 'block' => true,
886 'float' => true,
887 'properties' => array(
888 'top' => '20',
889 'left' => '20',
890 'right' => '20',
891 'width' => $width . '%',
892 'height' => 'auto',
893 'value' => isset($field['label']) ? $field['label'] : '',
894 ),
895 )
896 );
897 $field_options = array();
898 foreach ($field['choices'] as $option) {
899 $option_value = isset($option['label']) ? $option['label'] : '';
900 if ($field['type'] == 'payment-select') {
901 $option_value .= isset($option['value']) ? ' - ' . html_entity_decode(wpforms_format_amount(wpforms_sanitize_amount($option['value']), true)) : '';
902 }
903 $field_options[] = $option_value;
904 }
905 if (isset($field['multiple']) && $field['multiple']) {
906
907 $elements[] = $this->auto_field(
908 $field,
909 array(
910 'type' => 'e2pdf-select',
911 'properties' => array(
912 'top' => '5',
913 'width' => '100%',
914 'height' => '44',
915 'multiline' => '1',
916 'options' => implode("\n", $field_options),
917 'value' => $field_value,
918 ),
919 )
920 );
921 } else {
922 $elements[] = $this->auto_field(
923 $field,
924 array(
925 'type' => 'e2pdf-select',
926 'properties' => array(
927 'top' => '5',
928 'width' => '100%',
929 'height' => 'auto',
930 'options' => implode("\n", $field_options),
931 'value' => $field_value,
932 ),
933 )
934 );
935 }
936 break;
937 case 'textarea':
938 case 'address':
939 case 'file-upload':
940 $elements[] = $this->auto_field(
941 $field,
942 array(
943 'type' => 'e2pdf-html',
944 'block' => true,
945 'float' => true,
946 'properties' => array(
947 'top' => '20',
948 'left' => '20',
949 'right' => '20',
950 'width' => $width . '%',
951 'height' => 'auto',
952 'value' => isset($field['label']) ? $field['label'] : '',
953 ),
954 )
955 );
956 $elements[] = $this->auto_field(
957 $field,
958 array(
959 'type' => 'e2pdf-textarea',
960 'properties' => array(
961 'top' => '5',
962 'width' => '100%',
963 'height' => 'auto',
964 'value' => $field_value,
965 ),
966 )
967 );
968 break;
969 case 'richtext':
970 $elements[] = $this->auto_field(
971 $field,
972 array(
973 'type' => 'e2pdf-html',
974 'block' => true,
975 'float' => true,
976 'properties' => array(
977 'top' => '20',
978 'left' => '20',
979 'right' => '20',
980 'width' => $width . '%',
981 'height' => 'auto',
982 'value' => isset($field['label']) ? $field['label'] : '',
983 ),
984 )
985 );
986 $elements[] = $this->auto_field(
987 $field,
988 array(
989 'type' => 'e2pdf-html',
990 'properties' => array(
991 'top' => '5',
992 'width' => '100%',
993 'height' => '150',
994 'value' => $field_value,
995 ),
996 )
997 );
998 break;
999 case 'radio':
1000 case 'payment-multiple':
1001 $elements[] = $this->auto_field(
1002 $field,
1003 array(
1004 'type' => 'e2pdf-html',
1005 'block' => true,
1006 'float' => true,
1007 'properties' => array(
1008 'top' => '20',
1009 'left' => '20',
1010 'right' => '20',
1011 'width' => $width . '%',
1012 'height' => 'auto',
1013 'value' => isset($field['label']) ? $field['label'] : '',
1014 ),
1015 )
1016 );
1017
1018 foreach ($field['choices'] as $opt_key => $option) {
1019 $option_value = isset($option['label']) ? $option['label'] : '';
1020 if ($field['type'] == 'payment-multiple') {
1021 $option_value .= isset($option['value']) ? ' - ' . html_entity_decode(wpforms_format_amount(wpforms_sanitize_amount($option['value']), true)) : '';
1022 }
1023 $elements[] = $this->auto_field(
1024 $field,
1025 array(
1026 'type' => 'e2pdf-radio',
1027 'properties' => array(
1028 'top' => '5',
1029 'width' => 'auto',
1030 'height' => 'auto',
1031 'value' => $field_value,
1032 'option' => sanitize_text_field($option_value),
1033 'group' => $field_value,
1034 ),
1035 )
1036 );
1037 $elements[] = $this->auto_field(
1038 $field,
1039 array(
1040 'type' => 'e2pdf-html',
1041 'float' => true,
1042 'properties' => array(
1043 'left' => '5',
1044 'width' => '100%',
1045 'height' => 'auto',
1046 'value' => !empty($field['show_price_after_labels']) ? $option_value : $option['label'],
1047 ),
1048 )
1049 );
1050 }
1051 break;
1052 case 'checkbox':
1053 case 'payment-checkbox':
1054 $elements[] = $this->auto_field(
1055 $field,
1056 array(
1057 'type' => 'e2pdf-html',
1058 'block' => true,
1059 'float' => true,
1060 'properties' => array(
1061 'top' => '20',
1062 'left' => '20',
1063 'right' => '20',
1064 'width' => $width . '%',
1065 'height' => 'auto',
1066 'value' => isset($field['label']) ? $field['label'] : '',
1067 ),
1068 )
1069 );
1070 foreach ($field['choices'] as $opt_key => $option) {
1071 $option_value = isset($option['label']) ? $option['label'] : '';
1072 if ($field['type'] == 'payment-checkbox') {
1073 $option_value .= isset($option['value']) ? ' - ' . html_entity_decode(wpforms_format_amount(wpforms_sanitize_amount($option['value']), true)) : '';
1074 }
1075
1076 $elements[] = $this->auto_field(
1077 $field,
1078 array(
1079 'type' => 'e2pdf-checkbox',
1080 'properties' => array(
1081 'top' => '5',
1082 'width' => 'auto',
1083 'height' => 'auto',
1084 'value' => $field_value,
1085 'option' => sanitize_text_field($option_value),
1086 ),
1087 )
1088 );
1089 $elements[] = $this->auto_field(
1090 $field,
1091 array(
1092 'type' => 'e2pdf-html',
1093 'float' => true,
1094 'properties' => array(
1095 'left' => '5',
1096 'width' => '100%',
1097 'height' => 'auto',
1098 'value' => !empty($field['show_price_after_labels']) ? $option_value : $option['label'],
1099 ),
1100 )
1101 );
1102 }
1103 break;
1104 case 'signature':
1105 $elements[] = $this->auto_field(
1106 $field,
1107 array(
1108 'type' => 'e2pdf-html',
1109 'block' => true,
1110 'float' => true,
1111 'properties' => array(
1112 'top' => '20',
1113 'left' => '20',
1114 'right' => '20',
1115 'width' => $width . '%',
1116 'height' => 'auto',
1117 'value' => isset($field['label']) ? $field['label'] : '',
1118 ),
1119 )
1120 );
1121 $elements[] = $this->auto_field(
1122 $field,
1123 array(
1124 'type' => 'e2pdf-signature',
1125 'properties' => array(
1126 'top' => '5',
1127 'width' => '100%',
1128 'height' => '150',
1129 'dimension' => '1',
1130 'block_dimension' => '1',
1131 'value' => $field_value,
1132 ),
1133 )
1134 );
1135 break;
1136 case 'likert_scale':
1137 $elements[] = $this->auto_field(
1138 $field,
1139 array(
1140 'type' => 'e2pdf-html',
1141 'block' => true,
1142 'properties' => array(
1143 'top' => '20',
1144 'left' => '20',
1145 'right' => '20',
1146 'width' => $width . '%',
1147 'height' => 'auto',
1148 'value' => isset($field['label']) ? $field['label'] : '',
1149 ),
1150 )
1151 );
1152 foreach ($field['rows'] as $key => $sub_field) {
1153 if (isset($field['columns']) && is_array($field['columns'])) {
1154 if (!empty($field['single_row'])) {
1155 $width = 100 / (count($field['columns']));
1156 } else {
1157 $width = 100 / (count($field['columns']) + 1);
1158 }
1159 if (empty($field['single_row'])) {
1160 $elements[] = $this->auto_field(
1161 $field,
1162 array(
1163 'type' => 'e2pdf-html',
1164 'block' => true,
1165 'hidden' => true,
1166 'properties' => array(
1167 'top' => '5',
1168 'left' => '20',
1169 'right' => '20',
1170 'width' => $width . '%',
1171 'height' => 'auto',
1172 'value' => '',
1173 ),
1174 )
1175 );
1176 }
1177 foreach ($field['columns'] as $opt_key => $option) {
1178 $elements[] = $this->auto_field(
1179 $field,
1180 array(
1181 'type' => 'e2pdf-html',
1182 'float' => true,
1183 'block' => true,
1184 'properties' => array(
1185 'top' => '10',
1186 'left' => '20',
1187 'right' => '20',
1188 'width' => $width . '%',
1189 'height' => 'auto',
1190 'value' => $option,
1191 ),
1192 )
1193 );
1194 }
1195 }
1196 break;
1197 }
1198 foreach ($field['rows'] as $key => $sub_field) {
1199 if (isset($field['columns']) && is_array($field['columns'])) {
1200 if (!empty($field['single_row'])) {
1201 $width = 100 / (count($field['columns']));
1202 } else {
1203 $width = 100 / (count($field['columns']) + 1);
1204 }
1205 if (empty($field['single_row'])) {
1206 $elements[] = $this->auto_field(
1207 $field,
1208 array(
1209 'type' => 'e2pdf-html',
1210 'block' => true,
1211 'properties' => array(
1212 'top' => '5',
1213 'left' => '20',
1214 'right' => '20',
1215 'width' => $width . '%',
1216 'height' => 'auto',
1217 'value' => $sub_field,
1218 ),
1219 )
1220 );
1221 }
1222 foreach ($field['columns'] as $opt_key => $option) {
1223 $elements[] = $this->auto_field(
1224 $field,
1225 array(
1226 'type' => 'e2pdf-html',
1227 'float' => true,
1228 'block' => true,
1229 'hidden' => true,
1230 'properties' => array(
1231 'top' => '5',
1232 'left' => '20',
1233 'right' => '20',
1234 'width' => $width . '%',
1235 'height' => '5',
1236 'value' => '',
1237 ),
1238 )
1239 );
1240 $field_value = '{field_id="' . $field_id . '|' . $key . '"}';
1241 if (!empty($field['multiple_responses'])) {
1242 $elements[] = $this->auto_field(
1243 $field,
1244 array(
1245 'type' => 'e2pdf-checkbox',
1246 'properties' => array(
1247 'top' => '-5',
1248 'width' => 'auto',
1249 'height' => 'auto',
1250 'value' => $field_value,
1251 'option' => $opt_key,
1252 ),
1253 )
1254 );
1255 } else {
1256 $elements[] = $this->auto_field(
1257 $field,
1258 array(
1259 'type' => 'e2pdf-radio',
1260 'properties' => array(
1261 'top' => '-5',
1262 'width' => 'auto',
1263 'height' => 'auto',
1264 'value' => $field_value,
1265 'option' => $opt_key,
1266 'group' => $field_value,
1267 ),
1268 )
1269 );
1270 }
1271 }
1272 if (!empty($field['single_row'])) {
1273 break;
1274 }
1275 }
1276 }
1277 break;
1278 default:
1279 break;
1280 }
1281 }
1282 }
1283 $response = array();
1284 $response['page'] = array(
1285 'bottom' => '20',
1286 'top' => '20',
1287 'left' => '20',
1288 'right' => '20',
1289 );
1290
1291 $response['elements'] = $elements;
1292 return $response;
1293 }
1294
1295 // inner field
1296 public function inner_field($array, $id) {
1297 foreach ($array as $index => $item) {
1298 if (is_array($item)) {
1299 if (isset($item['id']) && $item['id'] == $id) {
1300 return $index;
1301 }
1302 }
1303 }
1304 return false;
1305 }
1306
1307 // auto field
1308 public function auto_field($field = false, $element = array()) {
1309 if (!$field) {
1310 return false;
1311 }
1312 return $element;
1313 }
1314
1315 // verify
1316 public function verify() {
1317 if ($this->get('cached_form') && $this->get('cached_entry') && $this->get('cached_form')->ID == $this->get('cached_entry')->form_id) {
1318 return true;
1319 }
1320 return false;
1321 }
1322
1323 // visual mapper
1324 public function visual_mapper() {
1325 $html = '';
1326 $source = '';
1327 if ($this->get('item')) {
1328 ob_start();
1329 add_filter('wpforms_forms_anti_spam_v3_is_honeypot_enabled', '__return_false');
1330 echo do_shortcode('[wpforms id="' . $this->get('item') . '"]');
1331 add_filter('wpforms_forms_anti_spam_v3_is_honeypot_enabled', '__return_true');
1332 $source = ob_get_clean();
1333 if ($source) {
1334 $dom = new DOMDocument();
1335 $html = $this->helper->load('convert')->load_html(preg_replace('/<script\b[^>]*>.*?<\/script>/is', '', $source), $dom, true);
1336 }
1337
1338 if (ob_get_length() > 0) {
1339 while (@ob_end_clean()); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
1340 }
1341 if (!$source) {
1342 return '<div class="e2pdf-vm-error">' . __("The form source is empty or doesn't exist", 'e2pdf') . '</div>';
1343 } elseif (!$html) {
1344 return '<div class="e2pdf-vm-error">' . __('The form could not be parsed due the incorrect HTML', 'e2pdf') . '</div>';
1345 } else {
1346 $form_handler = new WPForms_Form_Handler();
1347 $xml = new Helper_E2pdf_Xml();
1348 $xpath = new DomXPath($dom);
1349
1350 // remove by name
1351 $remove_by_name = array(
1352 'wpforms[id]',
1353 'wpforms[nonce]',
1354 'page_title',
1355 'page_url',
1356 'url_referer',
1357 );
1358 foreach ($remove_by_name as $key => $name) {
1359 $elements = $xpath->query('//*[@name="' . $name . '"]');
1360 foreach ($elements as $element) {
1361 $element->parentNode->removeChild($element);
1362 }
1363 }
1364
1365 // remove by tag
1366 $remove_by_tag = array(
1367 'script',
1368 'noscript',
1369 );
1370 foreach ($remove_by_tag as $key => $tag) {
1371 $elements = $xpath->query('//' . $tag);
1372 foreach ($elements as $element) {
1373 $element->parentNode->removeChild($element);
1374 }
1375 }
1376
1377 // remove by class
1378 $remove_by_class = array(
1379 'wpforms-page-button',
1380 'wpforms-field-pagebreak',
1381 'wpforms-signature-wrap',
1382 'dz-message',
1383 'wp-editor-tabs',
1384 'wpforms-page-indicator progress',
1385 'quicktags-toolbar',
1386 'wpforms-field-entry-preview',
1387 'wpforms-field-payment-coupon-button',
1388 'wpforms-single-item-price',
1389 );
1390 foreach ($remove_by_class as $key => $class) {
1391 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
1392 foreach ($elements as $element) {
1393 $element->parentNode->removeChild($element);
1394 }
1395 }
1396
1397 // remove styles
1398 $remove_styles = array(
1399 'wpforms-page',
1400 'dropzone-input',
1401 'wpforms-conditional-field',
1402 );
1403 foreach ($remove_styles as $key => $class) {
1404 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
1405 foreach ($elements as $element) {
1406 $xml->set_node_value($element, 'style', '');
1407 }
1408 }
1409
1410 $elements = $xpath->query("//*[contains(@class, 'wpforms-field-payment-checkbox') or contains(@class, 'wpforms-field-payment-multiple') or contains(@class, 'wpforms-field-payment-select')]");
1411 foreach ($elements as $element) {
1412 $field_id = $xml->get_node_value($element, 'data-field-id');
1413 $field = $form_handler->get_field($this->get('item'), $field_id);
1414 $sub_elements = $xpath->query('.//input|.//option', $element);
1415 foreach ($sub_elements as $sub_element) {
1416 $field_value = $xml->get_node_value($sub_element, 'value');
1417 $option_value = '';
1418 if ($field_value) {
1419 if (isset($field['choices'][$field_value])) {
1420 $option = $field['choices'][$field_value];
1421 $option_value = isset($option['label']) ? $option['label'] : '';
1422 $option_value .= isset($option['value']) ? ' - ' . html_entity_decode(wpforms_format_amount(wpforms_sanitize_amount($option['value']), true)) : '';
1423 }
1424 }
1425 $xml->set_node_value($sub_element, 'value', $option_value);
1426 }
1427 }
1428 $elements = $xpath->query("//*[contains(@class, 'wpforms-field-payment-single') or contains(@class, 'wpforms-field-payment-total')]");
1429 foreach ($elements as $element) {
1430 $sub_elements = $xpath->query('.//input', $element);
1431 foreach ($sub_elements as $sub_element) {
1432 $xml->set_node_value($sub_element, 'type', 'text');
1433 $xml->set_node_value($sub_element, 'class', '');
1434 }
1435 }
1436
1437 // remove by class
1438 $remove_by_class = array(
1439 'wpforms-payment-total',
1440 );
1441 foreach ($remove_by_class as $key => $class) {
1442 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
1443 foreach ($elements as $element) {
1444 $element->parentNode->removeChild($element);
1445 }
1446 }
1447
1448 $elements = $xpath->query("//*[contains(@class, 'wpforms-field-repeater-display-rows')]");
1449 foreach ($elements as $element) {
1450 $sub_elements = $xpath->query('.//input|.//textarea|.//select', $element);
1451 foreach ($sub_elements as $sub_element) {
1452 $xml->set_node_value($sub_element, 'name', preg_replace('/(wpforms\[fields\]\[)(\d+)(\].*)/', '$1$2_1$3', $xml->get_node_value($sub_element, 'name')));
1453 }
1454 }
1455 $elements = $xpath->query("//*[contains(@class, 'wpforms-field-likert_scale')]");
1456 foreach ($elements as $element) {
1457 $sub_elements = $xpath->query('.//input', $element);
1458 foreach ($sub_elements as $sub_element) {
1459 $xml->set_node_value($sub_element, 'name', preg_replace('/(wpforms\[fields\]\[)(\d+)(\]\[)(\d+)(\].*)/', '$1$2|$4$5', $xml->get_node_value($sub_element, 'name')));
1460 }
1461 }
1462 $elements = $xpath->query("//*[contains(@class, 'dropzone-input')]");
1463 foreach ($elements as $element) {
1464 $xml->set_node_value($element, 'name', preg_replace('/wpforms_\d+_(\d+)/', 'wpforms[fields][$1]', $xml->get_node_value($element, 'name')));
1465 }
1466
1467 // radio, checkbox mapping html value fix
1468 $elements = $xpath->query('//input[@type="checkbox"]|//input[@type="radio"]');
1469 foreach ($elements as $element) {
1470 $value = $xml->get_node_value($element, 'value');
1471 if ($value) {
1472 $xml->set_node_value($element, 'value', sanitize_text_field($value));
1473 }
1474 }
1475
1476 $elements = $xpath->query('//input|//textarea|//select');
1477 foreach ($elements as $element) {
1478 $xml->set_node_value($element, 'name', '{field_id="' . preg_replace('/wpforms\[fields\]\[(\d+|\d+_\d+|\d+\|\d+)\].*/', '$1', $xml->get_node_value($element, 'name')) . '"}');
1479 }
1480 $submit_buttons = $xpath->query("//input[@type='submit']|//button[@type='submit']");
1481 foreach ($submit_buttons as $element) {
1482 $element->parentNode->removeChild($element);
1483 }
1484
1485 if (defined('LIBXML_HTML_NOIMPLIED') && defined('LIBXML_HTML_NODEFDTD')) {
1486 return str_replace(array('<html>', '</html>'), '', $dom->saveHTML());
1487 } else {
1488 return $dom->saveHTML();
1489 }
1490 }
1491 }
1492 return false;
1493 }
1494
1495 // load shortcodes
1496 public function load_shortcodes() { // phpcs:ignore Squiz.WhiteSpace.SuperfluousWhitespace.EndLine
1497 }
1498
1499 // styles
1500 public function styles($item_id = false) {
1501 $styles = array();
1502 if (defined('WPFORMS_PLUGIN_URL')) {
1503 if (defined('WPFORMS_PLUGIN_SLUG') && WPFORMS_PLUGIN_SLUG == 'wpforms') {
1504 $styles[] = WPFORMS_PLUGIN_URL . 'assets/pro/css/fields/content/frontend.min.css';
1505 $styles[] = WPFORMS_PLUGIN_URL . 'assets/pro/css/fields/layout.min.css';
1506 $styles[] = WPFORMS_PLUGIN_URL . 'assets/pro/css/fields/repeater.min.css';
1507 }
1508 $styles[] = WPFORMS_PLUGIN_URL . 'assets/css/frontend/modern/wpforms-full.min.css';
1509
1510 if (function_exists('wpforms_surveys_polls') && isset(wpforms_surveys_polls()->url)) {
1511 $styles[] = wpforms_surveys_polls()->url . 'assets/css/wpforms-surveys-polls.min.css';
1512 }
1513 }
1514 $styles[] = plugins_url('css/extension/wpforms.css?v=' . time(), $this->helper->get('plugin_file_path'));
1515 return $styles;
1516 }
1517
1518 // entry view hook
1519 public function hook_wpforms_entry_view($entry) {
1520 if (!empty($entry->form_id)) {
1521 $hooks = $this->helper->load('hooks')->get('wpforms', 'hook_wpforms_entry_view', $entry->form_id);
1522 if (!empty($hooks)) {
1523 echo '<div id="wpforms-entry-actions" class="postbox">';
1524 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>';
1525 echo '<div class="inside">';
1526 echo '<div class="wpforms-entry-actions-meta">';
1527 foreach ($hooks as $hook) {
1528 if ($this->helper->load('hooks')->process_hook(
1529 $hook,
1530 [
1531 'dataset' => $entry->entry_id,
1532 ],
1533 'hook_wpforms_entry_view'
1534 )
1535 ) {
1536 $action = apply_filters(
1537 'e2pdf_hook_action_button',
1538 array(
1539 '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>',
1540 'url' => $this->helper->get_url(
1541 array(
1542 'page' => 'e2pdf',
1543 'action' => 'export',
1544 'id' => $hook,
1545 'dataset' => $entry->entry_id,
1546 ), 'admin.php?'
1547 ),
1548 'title' => 'PDF #' . $hook,
1549 ), 'hook_wpforms_entry_view', $hook, $entry->entry_id
1550 );
1551 if (!empty($action)) {
1552 echo sprintf(
1553 $action['html'], $action['url'], $action['title']
1554 );
1555 }
1556 }
1557 }
1558 echo '</div>';
1559 echo '</div>';
1560 echo '</div>';
1561 }
1562 }
1563 }
1564
1565 // entry edit hook
1566 public function hook_wpforms_entry_edit($entry) {
1567 if (!empty($entry->form_id)) {
1568 $hooks = $this->helper->load('hooks')->get('wpforms', 'hook_wpforms_entry_edit', $entry->form_id);
1569 if (!empty($hooks)) {
1570 echo '<div id="wpforms-entry-actions" class="postbox">';
1571 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>';
1572 echo '<div class="inside">';
1573 echo '<div class="wpforms-entry-actions-meta">';
1574 foreach ($hooks as $hook) {
1575 if ($this->helper->load('hooks')->process_hook(
1576 $hook,
1577 [
1578 'dataset' => $entry->entry_id,
1579 ],
1580 'hook_wpforms_entry_edit'
1581 )
1582 ) {
1583 $action = apply_filters(
1584 'e2pdf_hook_action_button',
1585 array(
1586 '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>',
1587 'url' => $this->helper->get_url(
1588 array(
1589 'page' => 'e2pdf',
1590 'action' => 'export',
1591 'id' => $hook,
1592 'dataset' => $entry->entry_id,
1593 ), 'admin.php?'
1594 ),
1595 'title' => 'PDF #' . $hook,
1596 ), 'hook_wpforms_entry_edit', $hook, $entry->entry_id
1597 );
1598 if (!empty($action)) {
1599 echo sprintf(
1600 $action['html'], $action['url'], $action['title']
1601 );
1602 }
1603 }
1604 }
1605 echo '</div>';
1606 echo '</div>';
1607 echo '</div>';
1608 }
1609 }
1610 }
1611
1612 // row actions hook
1613 public function hook_wpforms_row_actions($actions, $entry) {
1614 if (!empty($entry->form_id)) {
1615 $hooks = $this->helper->load('hooks')->get('wpforms', 'hook_wpforms_row_actions', $entry->form_id);
1616 foreach ($hooks as $hook) {
1617 if ($this->helper->load('hooks')->process_hook(
1618 $hook,
1619 [
1620 'dataset' => $entry->entry_id,
1621 ],
1622 'hook_wpforms_row_actions'
1623 )
1624 ) {
1625 $action = apply_filters(
1626 'e2pdf_hook_action_button',
1627 array(
1628 'html' => '<a class="e2pdf-download-hook" target="_blank" href="%s">%s</a>',
1629 'url' => $this->helper->get_url(
1630 array(
1631 'page' => 'e2pdf',
1632 'action' => 'export',
1633 'id' => $hook,
1634 'dataset' => $entry->entry_id,
1635 ), 'admin.php?'
1636 ),
1637 'title' => 'PDF #' . $hook,
1638 ), 'hook_wpforms_row_actions', $hook, $entry->entry_id
1639 );
1640 if (!empty($action)) {
1641 $actions['e2pdf_' . $hook] = sprintf(
1642 $action['html'], $action['url'], $action['title']
1643 );
1644 }
1645 }
1646 }
1647 }
1648 return $actions;
1649 }
1650 }
1651