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

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

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