PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.53
E2Pdf – Export Pdf Tool for WordPress v1.32.53
1.32.53 1.32.51 1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 All 74 releases
e2pdf / classes / extension / e2pdf-fluent.php

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

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