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

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

1,451 lines 61.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * File: /extension/e2pdf-jetformbuilder.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_Jetformbuilder extends Model_E2pdf_Model {
15
16 private $options;
17 private $info = array(
18 'key' => 'jetformbuilder',
19 'title' => 'JetFormBuilder',
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_JETFORMBUILDER_EXTENSION') || $this->helper->load('extension')->is_plugin_active('jetformbuilder/jet-form-builder.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 $this->set('cached_forms', array());
51 $form = get_post($this->get('item'));
52 if ($form) {
53 $this->set('cached_form', jet_fb_handler()->set_form_id($this->get('item')));
54 }
55 break;
56 case 'dataset':
57 $this->set('cached_entry', false);
58 if ($this->get('cached_form') && $this->get('dataset')) {
59 $forms = $this->get_all_forms($this->get('cached_form')->get_form_id());
60 if (substr($this->get('dataset'), 0, 4) === 'tmp_') {
61 $transient = get_transient('e2pdf_' . $this->get('dataset'));
62 if (isset($transient['__form_id']) && (in_array($transient['__form_id'], $forms, false))) {
63 $this->set('cached_entry', $transient);
64 }
65 } else {
66 global $wpdb;
67 $placeholders = implode(',', array_fill(0, count($forms), '%d'));
68 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
69 $record = $wpdb->get_row($wpdb->prepare('SELECT * FROM `' . \JFB_Modules\Form_Record\Models\Record_Model::table() . '` WHERE id = %d AND form_id IN (' . $placeholders . ')', array_merge([$this->get('dataset')], $forms)), ARRAY_A);
70 if ($record) {
71 \JFB_Modules\Form_Record\Tools::apply_context($record);
72 $this->set('cached_entry', $record);
73 }
74 }
75 }
76 break;
77 default:
78 break;
79 }
80 return true;
81 }
82
83 // get
84 public function get($key) {
85 if (isset($this->options->$key)) {
86 $value = $this->options->$key;
87 } else {
88 switch ($key) {
89 case 'args':
90 case 'cached_post':
91 $value = array();
92 break;
93 default:
94 $value = false;
95 break;
96 }
97 }
98 return $value;
99 }
100
101 // actions
102 public function load_actions() {
103 add_action('jet-form-builder/send-email/send-before', array($this, 'action_jet_form_builder_send_email_send_before'));
104 add_action('jet-form-builder/form-handler/before-send', array($this, 'action_jet_form_builder_form_handler_before_send'));
105 add_action('jet-form-builder/form-handler/after-send', array($this, 'action_jet_form_builder_form_handler_after_send'));
106 add_action('jet-form-builder/before-do-action/redirect_to_page', array($this, 'action_jet_form_builder_before_do_action_redirect_to_page'));
107 }
108
109 public function action_jet_form_builder_before_do_action_redirect_to_page($action) {
110 if (!empty($action->settings['redirect_args']) && is_array($action->settings['redirect_args']) && in_array('e2pdf-hash', $action->settings['redirect_args'], true)) {
111 $dataset = jet_fb_action_handler()->get_context('save_record', 'id');
112 if ($dataset) {
113 $hash_id = $this->helper->load('encryption')->random_md5();
114 set_transient('e2pdf_hash_' . $hash_id, $dataset, apply_filters('e2pdf_hash_timeout', '1200', 'jfb_redirect'));
115 jet_fb_context()->update_request($hash_id, 'e2pdf-hash');
116 }
117 }
118 }
119
120 // filters
121 public function load_filters() {
122 add_filter('jet-form-builder/before-end-form', array($this, 'filter_jet_form_builder_before_end_form'), 99);
123 add_filter('jet-form-builder/send-email/message_content', array($this, 'filter_jet_form_builder_send_email_message_content'), 99, 2);
124 add_filter('jet-form-builder/content-filters', array($this, 'filter_jet_form_builder_content_filter'));
125
126 // hooks
127 add_filter('jet-form-builder/page-containers/jfb-records-single', array($this, 'hook_jetformbuilder_entry_view'));
128 }
129
130 public function filter_wp_kses_allowed_html($html, $context) {
131 if (is_array($context)) {
132 return $html;
133 }
134 if ($context === 'post') {
135 $html['iframe']['name'] = true;
136 $html['iframe']['onload'] = true;
137 $html['iframe']['style'] = true;
138 $html['iframe']['class'] = true;
139 $html['iframe']['width'] = true;
140 $html['iframe']['height'] = true;
141 $html['iframe']['src'] = true;
142 $html['iframe']['preload'] = true;
143 $html['iframe']['resolution'] = true;
144 $html['iframe']['cursor'] = true;
145 $html['iframe']['scroll'] = true;
146 $html['iframe']['spread'] = true;
147 $html['img']['onload'] = true;
148 $html['img']['style'] = true;
149 $html['img']['preload'] = true;
150 $html['img']['class'] = true;
151 $html['a']['lid'] = true;
152 $html['a']['download'] = true;
153 $html['a']['class'] = true;
154 }
155 return $html;
156 }
157
158 public function filter_safe_style_css($styles) {
159 $styles[] = 'display';
160 $styles[] = 'width';
161 $styles[] = 'height';
162 $styles[] = 'border-width';
163 $styles[] = 'border';
164 return $styles;
165 }
166
167 public function action_jet_form_builder_form_handler_before_send() {
168 foreach (jet_fb_action_handler()->get_all() as $action) {
169 if (method_exists($action, 'get_id') && $action->get_id() == 'send_email') {
170 if (!empty($action->settings['content'])) {
171 $content = $action->settings['content'];
172 if (is_string($content) && false !== strpos($content, '[e2pdf-')) {
173 foreach (jet_fb_action_handler()->get_all() as $sub_action) {
174 if (is_a($sub_action, '\JFB_Modules\Form_Record\Action_Types\Save_Record')) {
175 $this->set('save_record', true);
176 jet_fb_action_handler()->process_single_action($sub_action);
177 jet_fb_action_handler()->unregister_action($sub_action->_id);
178 break;
179 }
180 }
181 break;
182 }
183 }
184 } elseif (method_exists($action, 'get_id') && $action->get_id() == 'redirect_to_page') {
185 if (!empty($action->settings['redirect_args']) && is_array($action->settings['redirect_args']) && in_array('e2pdf-hash', $action->settings['redirect_args'], true)) {
186 foreach (jet_fb_action_handler()->get_all() as $sub_action) {
187 if (is_a($sub_action, '\JFB_Modules\Form_Record\Action_Types\Save_Record')) {
188 $this->set('save_record', true);
189 jet_fb_action_handler()->process_single_action($sub_action);
190 jet_fb_action_handler()->unregister_action($sub_action->_id);
191 break;
192 }
193 }
194 break;
195 }
196 }
197 }
198 }
199
200 public function action_jet_form_builder_form_handler_after_send($form_handler) {
201 $files = $this->helper->get('jetformbuilder_attachments');
202 if (is_array($files) && !empty($files)) {
203 foreach ($files as $key => $file) {
204 $this->helper->delete_dir(dirname($file) . '/');
205 }
206 $this->helper->deset('jetformbuilder_attachments');
207 }
208
209 if ($this->get('save_record')) {
210 $dataset = jet_fb_action_handler()->get_context('save_record', 'id');
211 if ($dataset) {
212 \JFB_Modules\Form_Record\Tools::update_record($dataset);
213 $args = jet_form_builder()->form_handler->get_response_args();
214 (new \JFB_Modules\Form_Record\Models\Record_Model())->update(
215 array(
216 'status' => $args['status'] ?? '',
217 ),
218 array(
219 'id' => $dataset,
220 )
221 );
222 }
223 }
224
225 $messages = jet_form_builder()->msg_router->get_manager()->get_messages();
226 foreach ($messages as $message_key => $success_message) {
227 if (is_string($success_message) && false !== strpos($success_message, '[e2pdf-')) {
228 $dataset = jet_fb_action_handler()->get_context('save_record', 'id');
229 if ($dataset) {
230 $hash_id = $this->helper->load('encryption')->random_md5();
231 set_transient('e2pdf_hash_' . $hash_id, $dataset, apply_filters('e2pdf_hash_timeout', '1200', 'jfb_message'));
232 $form_handler->add_response_data(
233 array(
234 'e2pdf-hash' => $hash_id,
235 )
236 );
237 }
238 break;
239 }
240 }
241 }
242
243 public function action_jet_form_builder_send_email_send_before($send_email) {
244 $message = $send_email->get_content();
245 $attachments = $send_email->get_attachments();
246 $message = preg_replace('/(\{\{)((e2pdf-download|e2pdf-view|e2pdf-save|e2pdf-attachment|e2pdf-adobesign|e2pdf-zapier)[^\}]*?)(\}\})/', '[$2]', $message);
247 if (false !== strpos($message, '[')) {
248 $shortcode_tags = array(
249 'e2pdf-download',
250 'e2pdf-save',
251 'e2pdf-attachment',
252 'e2pdf-adobesign',
253 'e2pdf-zapier',
254 );
255 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $message, $matches);
256 $tagnames = array_intersect($shortcode_tags, $matches[1]);
257 if (!empty($tagnames)) {
258 $context = jet_form_builder()->module('block-parsers')::instance()->get_context();
259 $request = $context->get_request();
260 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $message, $shortcodes);
261 foreach ($shortcodes[0] as $key => $shortcode_value) {
262 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
263 $atts = shortcode_parse_atts($shortcode[3]);
264 $file = false;
265 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) {
266 $transient = isset($atts['dataset']) && substr($atts['dataset'], 0, 4) === 'tmp_' ? 'e2pdf_' . $atts['dataset'] : false;
267 $file = do_shortcode_tag($shortcode);
268 if ($file) {
269 $tmp = false;
270 if (substr($file, 0, 4) === 'tmp:') {
271 $file = substr($file, 4);
272 $tmp = true;
273 }
274 if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
275 if ($tmp) {
276 $this->helper->add('jetformbuilder_attachments', $file);
277 }
278 } else {
279 $this->helper->add('jetformbuilder_attachments', $file);
280 }
281 $attachments[] = $file;
282 }
283 $message = str_replace($shortcode_value, '', $message);
284 if ($transient) {
285 delete_transient($transient);
286 }
287 } else {
288 $message = str_replace($shortcode_value, do_shortcode_tag($shortcode), $message);
289 }
290 }
291 $send_email->set_attachments($attachments);
292 $send_email->set_content($message);
293 $context->set_request($request);
294 $context->apply_request();
295 }
296 }
297 }
298
299 public function filter_jet_form_builder_send_email_message_content($message, $send_email) {
300 if (false !== strpos($message, '[')) {
301 $shortcode_tags = array(
302 'e2pdf-download',
303 'e2pdf-save',
304 'e2pdf-attachment',
305 'e2pdf-adobesign',
306 'e2pdf-zapier',
307 );
308 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $message, $matches);
309 $tagnames = array_intersect($shortcode_tags, $matches[1]);
310 if (!empty($tagnames)) {
311 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $message, $shortcodes);
312 foreach ($shortcodes[0] as $key => $shortcode_value) {
313 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
314 $atts = shortcode_parse_atts($shortcode[3]);
315 if (!isset($atts['dataset']) && isset($atts['id'])) {
316 $template = new Model_E2pdf_Template();
317 $template->load($atts['id']);
318 if ($template->get('extension') === 'jetformbuilder') {
319 $dataset = jet_fb_action_handler()->get_context('save_record', 'id');
320 if ($dataset) {
321 $atts['dataset'] = $dataset;
322 $shortcode[3] .= ' dataset="' . $dataset . '"';
323 } elseif ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
324 $dataset = 'tmp_' . $this->helper->load('encryption')->random_md5();
325 set_transient('e2pdf_' . $dataset, jet_fb_context()->get_request(), 1800);
326 $atts['dataset'] = $dataset;
327 $shortcode[3] .= ' dataset="' . $dataset . '"';
328 }
329 }
330 }
331 if (!isset($atts['apply'])) {
332 $shortcode[3] .= ' apply="true"';
333 }
334 if (!isset($atts['filter'])) {
335 $shortcode[3] .= ' filter="true"';
336 }
337 $message = str_replace($shortcode_value, '{{' . $shortcode[2] . $shortcode[3] . '}}', $message);
338 }
339 }
340 }
341 return $message;
342 }
343
344 public function filter_jet_form_builder_before_end_form($str) {
345 $messages = jet_form_builder()->msg_router->get_manager()->get_messages();
346 if (jet_form_builder()->msg_router->get_builder()->get_form_status() == 'success') {
347
348 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
349 $hash_id = isset($_GET['e2pdf-hash']) ? sanitize_text_field(wp_unslash($_GET['e2pdf-hash'])) : '';
350 $dataset = get_transient('e2pdf_hash_' . $hash_id);
351 if (apply_filters('e2pdf_hash_clear', true, 'jfb_message', array())) {
352 delete_transient('e2pdf_hash_' . $hash_id);
353 }
354 if ($dataset) {
355 foreach ($messages as $message_key => $success_message) {
356 if (is_string($success_message) && false !== strpos($success_message, '[')) {
357 $shortcode_tags = array(
358 'e2pdf-download',
359 'e2pdf-save',
360 'e2pdf-view',
361 'e2pdf-adobesign',
362 'e2pdf-zapier',
363 );
364 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $success_message, $matches);
365 $tagnames = array_intersect($shortcode_tags, $matches[1]);
366 if (!empty($tagnames)) {
367 add_filter('wp_kses_allowed_html', array($this, 'filter_wp_kses_allowed_html'), 10, 2);
368 add_filter('safe_style_css', array($this, 'filter_safe_style_css'));
369 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $success_message, $shortcodes);
370 foreach ($shortcodes[0] as $key => $shortcode_value) {
371 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
372 $atts = shortcode_parse_atts($shortcode[3]);
373 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
374 } else {
375 if (!isset($atts['dataset']) && isset($atts['id'])) {
376 $template = new Model_E2pdf_Template();
377 $template->load($atts['id']);
378 if ($template->get('extension') === 'jetformbuilder') {
379 $atts['dataset'] = $dataset;
380 $shortcode[3] .= ' dataset="' . $dataset . '"';
381 }
382 }
383 if (!isset($atts['apply'])) {
384 $shortcode[3] .= ' apply="true"';
385 }
386 if (!isset($atts['iframe_download'])) {
387 $shortcode[3] .= ' iframe_download="true"';
388 }
389 if (!isset($atts['iframe_loader'])) {
390 $shortcode[3] .= ' iframe_loader="true"';
391 }
392 $success_message = str_replace($shortcode_value, '[' . $shortcode[2] . $shortcode[3] . ']', $success_message);
393 }
394 }
395 jet_form_builder()->msg_router->get_manager()->_types[$message_key] = $success_message;
396 }
397 }
398 }
399 }
400 }
401 return $str;
402 }
403
404 // items
405 public function items() {
406 $items = array();
407 $forms = get_posts(
408 array(
409 'post_status' => 'publish',
410 'posts_per_page' => -1,
411 'post_type' => jet_form_builder()->post_type->slug(),
412 )
413 );
414 if ($forms) {
415 foreach ($forms as $key => $form) {
416 $items[] = $this->item($form->ID);
417 }
418 }
419 return $items;
420 }
421
422 // item
423 public function item($item_id = false) {
424 if (!$item_id && $this->get('item')) {
425 $item_id = $this->get('item');
426 }
427 $item = new stdClass();
428 $form = get_post($item_id);
429 if ($form) {
430 $item->id = (string) $item_id;
431 $item->name = $form->post_title ? $form->post_title : $item_id;
432 $item->url = $this->helper->get_url(
433 array(
434 'post' => $item_id,
435 'action' => 'edit',
436 ), 'post.php?'
437 );
438 } else {
439 $item->id = '';
440 $item->name = '';
441 $item->url = '';
442 }
443
444 return $item;
445 }
446
447 // datasets
448 public function datasets($item_id = false, $name = false) {
449
450 $datasets = array();
451 if ($item_id) {
452 $forms = $this->get_all_forms($item_id);
453 $record_view = (new \JFB_Modules\Form_Record\Query_Views\Record_View())->add_conditions(
454 array(
455 array(
456 'type' => 'in',
457 'values' => array('form_id', $forms),
458 ),
459 )
460 );
461 $columns['id'] = true;
462 $record_view->set_select(array_keys($columns));
463 try {
464 $entries = $record_view->query()->generate_all(ARRAY_A);
465 if ($entries) {
466 $this->set('item', $item_id);
467 foreach ($entries as $key => $entry) {
468 $this->set('dataset', $entry['id']);
469 $entry_title = $this->render($name);
470 if (!$entry_title) {
471 $entry_title = $entry['id'];
472 }
473 $datasets[] = array(
474 'key' => $entry['id'],
475 'value' => $entry_title,
476 );
477 }
478 }
479 } catch (Exception $ex) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
480 }
481 }
482 return $datasets;
483 }
484
485 // dataset actions
486 public function get_dataset_actions($dataset_id = false) {
487 $dataset_id = (int) $dataset_id;
488 if (!$dataset_id) {
489 return;
490 }
491 $data = new stdClass();
492 $data->view = $this->helper->get_url(
493 array(
494 'post_type' => jet_form_builder()->post_type->slug(),
495 'page' => 'jfb-records',
496 'item_id' => $dataset_id,
497 ), 'edit.php?'
498 );
499 $data->delete = false;
500 return $data;
501 }
502
503 // template actions
504 public function get_template_actions($template = false) {
505 $template = (int) $template;
506 if (!$template) {
507 return;
508 }
509 $actions = new stdClass();
510 $actions->delete = false;
511 return $actions;
512 }
513
514 // render
515 public function render($value, $field = array(), $convert_shortcodes = true, $raw = false) {
516 $value = $this->render_shortcodes($value, $field);
517 if (!$raw) {
518 $value = $this->strip_shortcodes($value);
519 $value = $this->convert_shortcodes($value, $convert_shortcodes, isset($field['type']) && $field['type'] == 'e2pdf-html' ? true : false);
520 $value = $this->helper->load('field')->render_checkbox($value, $this, $field);
521 }
522 return $value;
523 }
524
525 // render shortcodes
526 public function render_shortcodes($value, $field = array()) {
527
528 $element_id = isset($field['element_id']) ? $field['element_id'] : false;
529
530 if ($this->verify()) {
531 if (false !== strpos($value, '[')) {
532 $value = $this->helper->load('field')->pre_shortcodes($value, $this, $field);
533 $value = $this->helper->load('field')->inner_shortcodes($value, $this, $field);
534 $value = $this->helper->load('field')->wrapper_shortcodes($value, $this, $field);
535 }
536
537 add_filter('jet-form-builder/send-email/template-repeater', array($this, 'filter_jet_form_builder_send_email_template_repeater'), 99, 3);
538 $value = $this->helper->load('field')->do_shortcodes($value, $this, $field);
539 $value = jet_form_builder()->module('rich-content')::rich($value);
540 remove_filter('jet-form-builder/send-email/template-repeater', array($this, 'filter_jet_form_builder_send_email_template_repeater'), 99);
541
542 $value = $this->helper->load('field')->render(
543 apply_filters('e2pdf_extension_render_shortcodes_pre_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false),
544 $this,
545 $field
546 );
547 }
548 return apply_filters(
549 'e2pdf_extension_render_shortcodes_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false
550 );
551 }
552
553 public function filter_jet_form_builder_send_email_template_repeater($data, $items, $macros_parser) {
554 return !empty($items) ? serialize($items) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
555 }
556
557 public function filter_jet_form_builder_content_filter($filters) {
558 if (class_exists('\Jet_Form_Builder\Classes\Filters\Base_Multiple_Filter')) {
559 $filters[] = hook_e2pdf_jetformbuilder_content_filter();
560 }
561 return $filters;
562 }
563
564 // convert shortcodes
565 public function convert_shortcodes($value, $to = false, $html = false) {
566 if ($value) {
567 if ($to) {
568 $value = str_replace('&#91;', '[', $value);
569 if (!$html) {
570 $value = wp_specialchars_decode($value, ENT_QUOTES);
571 }
572 } else {
573 $value = str_replace('[', '&#91;', $value);
574 }
575 }
576 return $value;
577 }
578
579 // strip shortcodes
580 public function strip_shortcodes($value) {
581 $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', '', $value);
582 $value = preg_replace('~%[^%]*%~', '', $value);
583 return $value;
584 }
585
586 public function strip_math($value, &$replacements) {
587 if ($value) {
588 preg_match_all('~%[^%]*%~', $value, $matches);
589 foreach ($matches[0] as $match) {
590 $index = count($replacements) + 1;
591 $replacements[] = $match;
592 $value = str_replace($match, '%' . $index . '$s', $value);
593 }
594 }
595 return $value;
596 }
597
598 // verify
599 public function verify() {
600 if ($this->get('cached_entry')) {
601 return true;
602 }
603 return false;
604 }
605
606 // visual mapper
607 public function visual_mapper() {
608
609 $html = '';
610 $source = '';
611
612 if (function_exists('jet_fb_render_form')) {
613 $source = jet_fb_render_form(array('form_id' => $this->get('item')));
614 if ($source) {
615 $dom = new DOMDocument();
616 $html = $this->helper->load('convert')->load_html($source, $dom, true);
617 }
618 }
619 if (!$source) {
620 return '<div class="e2pdf-vm-error">' . __("The form source is empty or doesn't exist", 'e2pdf') . '</div>';
621 } elseif (!$html) {
622 return '<div class="e2pdf-vm-error">' . __('The form could not be parsed due the incorrect HTML', 'e2pdf') . '</div>';
623 } else {
624 $xml = $this->helper->load('xml');
625 $xpath = new DomXPath($dom);
626
627 $remove_classes = array(
628 'jet-form-builder-repeater__initial',
629 'jet-form-builder-page--hidden',
630 );
631 foreach ($remove_classes as $key => $class) {
632 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
633 foreach ($elements as $element) {
634 $xml->set_node_value($element, 'class', str_replace($class, '', $xml->get_node_value($element, 'class')));
635 }
636 }
637
638 // remove by class
639 $remove_by_class = array(
640 'jet-form-builder__next-page-wrap',
641 'jet-form-builder-repeater__actions',
642 'jet-form-builder-repeater__row-remove',
643 );
644 foreach ($remove_by_class as $key => $class) {
645 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
646 foreach ($elements as $element) {
647 $element->parentNode->removeChild($element);
648 }
649 }
650
651 // remove by name
652 $remove_by_name = array(
653 '_jfb_current_render_states[]',
654 '_jet_engine_booking_form_id',
655 '_jet_engine_refer',
656 '__queried_post_id'
657 );
658 foreach ($remove_by_name as $key => $name) {
659 $elements = $xpath->query('//*[@name="' . $name . '"]');
660 foreach ($elements as $element) {
661 $element->parentNode->removeChild($element);
662 }
663 }
664
665 $elements = $xpath->query('//template');
666 foreach ($elements as $element) {
667 $div = $dom->createElement('div');
668 if ($element->hasChildNodes()) {
669 $children = [];
670 foreach ($element->childNodes as $child) {
671 $children[] = $child;
672 }
673 foreach ($children as $child) {
674 $div->appendChild($child->parentNode->removeChild($child));
675 }
676 }
677 $element->parentNode->replaceChild($div, $element);
678 }
679
680 $elements = $xpath->query('//input|//textarea|//select');
681 foreach ($elements as $element) {
682 if ($xml->get_node_value($element, 'type') == 'checkbox' || $xml->get_node_value($element, 'type') == 'file') {
683 $xml->set_node_value($element, 'name', str_replace('[]', '', $xml->get_node_value($element, 'name')));
684 }
685 $xml->set_node_value($element, 'name', '%' . $xml->get_node_value($element, 'name') . '%');
686 }
687
688 // repeaters
689 $elements = $xpath->query("//*[contains(@class, 'field-type-repeater-field')]");
690 foreach ($elements as $element) {
691 $sub_elements = $xpath->query('.//input|.//textarea|.//select', $element);
692 foreach ($sub_elements as $sub_element) {
693 $xml->get_node_value($element, 'name');
694 $field_data = array();
695 preg_match('/%(.*?)\[__i__\]\[(.*?)\]%/i', $xml->get_node_value($sub_element, 'name'), $field_data);
696 if (!empty($field_data[1]) && !empty($field_data[2])) {
697 $xml->set_node_value($sub_element, 'name', '%' . $field_data[1] . '.0.' . $field_data[2] . '%');
698 } else {
699 $xml->set_node_value($sub_element, 'name', '');
700 }
701 $xml->set_node_value($sub_element, 'class', 'ff_gdpr_field');
702 }
703 }
704
705 // remove unecessary elements
706 $submit_buttons = $xpath->query("//button[@type='submit']");
707 foreach ($submit_buttons as $element) {
708 $element->parentNode->removeChild($element);
709 }
710
711 return $dom->saveHTML();
712 }
713 return false;
714 }
715
716 // auto
717 public function auto() {
718 $response = array();
719 $elements = array();
720
721 if ($this->get('cached_form')) {
722 $fields = \Jet_Form_Builder\Live_Form::instance()
723 ->set_form_id($this->get('cached_form')->get_form_id())
724 ->set_specific_data_for_render(array())
725 ->setup_fields();
726 foreach ($fields as $key => $field) {
727 $elements = $this->auto_fields($elements, $field);
728 }
729 }
730
731 $response['page'] = array(
732 'bottom' => '20',
733 'top' => '20',
734 'right' => '20',
735 'left' => '20',
736 );
737
738 $response['elements'] = $elements;
739 return $response;
740 }
741
742 // auto fields
743 public function auto_fields($elements = array(), $field = array(), $repeater = '') {
744
745 $type = !empty($field['blockName']) ? $field['blockName'] : '';
746 $label = !empty($field['attrs']['label']) ? $field['attrs']['label'] : '';
747 $desc = !empty($field['attrs']['desc']) ? $field['attrs']['desc'] : '';
748
749 if ($repeater) {
750 $value = !empty($field['attrs']['name']) ? $field['attrs']['name'] : 'field_name';
751 $value = '%' . $repeater . '.0.' . $value . '%';
752 } else {
753 $value = !empty($field['attrs']['name']) ? '%' . $field['attrs']['name'] . '%' : '%field_name%';
754 }
755
756 switch ($type) {
757 case 'jet-forms/text-field':
758 case 'jet-forms/color-picker-field':
759 case 'jet-forms/date-field':
760 case 'jet-forms/datetime-field':
761 case 'jet-forms/number-field':
762 case 'jet-forms/range-field':
763 case 'jet-forms/calculated-field':
764 case 'jet-forms/time-field':
765 if ($label) {
766 $elements[] = $this->auto_field(
767 $field,
768 array(
769 'type' => 'e2pdf-html',
770 'block' => true,
771 'properties' => array(
772 'top' => '20',
773 'left' => '20',
774 'right' => '20',
775 'width' => '100%',
776 'height' => 'auto',
777 'value' => $label,
778 ),
779 )
780 );
781 }
782 $elements[] = $this->auto_field(
783 $field,
784 array(
785 'block' => $label ? false : true,
786 'type' => 'e2pdf-input',
787 'properties' => array(
788 'top' => $label ? '5' : '20',
789 'left' => $label ? '0' : '20',
790 'right' => $label ? '0' : '20',
791 'width' => '100%',
792 'height' => 'auto',
793 'value' => $value,
794 ),
795 )
796 );
797 if ($desc) {
798 $elements[] = $this->auto_field(
799 $field,
800 array(
801 'type' => 'e2pdf-html',
802 'block' => true,
803 'properties' => array(
804 'top' => '5',
805 'left' => '20',
806 'right' => '20',
807 'width' => '100%',
808 'height' => 'auto',
809 'value' => $desc,
810 ),
811 )
812 );
813 }
814 break;
815 case 'jet-forms/checkbox-field':
816 $elements[] = $this->auto_field(
817 $field,
818 array(
819 'type' => 'e2pdf-html',
820 'block' => true,
821 'properties' => array(
822 'top' => '20',
823 'left' => '20',
824 'right' => '20',
825 'width' => '100%',
826 'height' => 'auto',
827 'value' => $label,
828 ),
829 )
830 );
831
832 $field_options_from = isset($field['attrs']['field_options_from']) ? $field['attrs']['field_options_from'] : false;
833
834 $options = array();
835 if ($field_options_from == 'glossary' && isset($field['attrs']['glossary_id'])) {
836 if (function_exists('jet_engine') && jet_engine()->glossaries) {
837 $glossary = jet_engine()->glossaries->data->get_item_for_edit($field['attrs']['glossary_id']);
838 if (!empty($glossary['fields']) && is_array($glossary['fields'])) {
839 $options = $glossary['fields'];
840 }
841 }
842 } elseif (isset($field['attrs']['field_options'])) {
843 $options = $field['attrs']['field_options'];
844 }
845
846 foreach ($options as $checkbox) {
847 $elements[] = $this->auto_field(
848 $field,
849 array(
850 'type' => 'e2pdf-checkbox',
851 'properties' => array(
852 'top' => '5',
853 'width' => 'auto',
854 'height' => 'auto',
855 'value' => $value,
856 'option' => $checkbox['value'],
857 ),
858 )
859 );
860 $elements[] = $this->auto_field(
861 $field,
862 array(
863 'type' => 'e2pdf-html',
864 'float' => true,
865 'properties' => array(
866 'left' => '5',
867 'width' => '100%',
868 'height' => 'auto',
869 'value' => $checkbox['label'],
870 ),
871 )
872 );
873 }
874 if ($desc) {
875 $elements[] = $this->auto_field(
876 $field,
877 array(
878 'type' => 'e2pdf-html',
879 'block' => true,
880 'properties' => array(
881 'top' => '5',
882 'left' => '20',
883 'right' => '20',
884 'width' => '100%',
885 'height' => 'auto',
886 'value' => $desc,
887 ),
888 )
889 );
890 }
891 break;
892 case 'jet-forms/radio-field':
893 $elements[] = $this->auto_field(
894 $field,
895 array(
896 'type' => 'e2pdf-html',
897 'block' => true,
898 'properties' => array(
899 'top' => '20',
900 'left' => '20',
901 'right' => '20',
902 'width' => '100%',
903 'height' => 'auto',
904 'value' => $label,
905 ),
906 )
907 );
908 foreach ($field['attrs']['field_options'] as $radio) {
909 $elements[] = $this->auto_field(
910 $field,
911 array(
912 'type' => 'e2pdf-radio',
913 'properties' => array(
914 'top' => '5',
915 'width' => 'auto',
916 'height' => 'auto',
917 'value' => $value,
918 'option' => $radio['value'],
919 'group' => $value,
920 ),
921 )
922 );
923 $elements[] = $this->auto_field(
924 $field,
925 array(
926 'type' => 'e2pdf-html',
927 'float' => true,
928 'properties' => array(
929 'left' => '5',
930 'width' => '100%',
931 'height' => 'auto',
932 'value' => $radio['label'],
933 ),
934 )
935 );
936 }
937 if ($desc) {
938 $elements[] = $this->auto_field(
939 $field,
940 array(
941 'type' => 'e2pdf-html',
942 'block' => true,
943 'properties' => array(
944 'top' => '5',
945 'left' => '20',
946 'right' => '20',
947 'width' => '100%',
948 'height' => 'auto',
949 'value' => $desc,
950 ),
951 )
952 );
953 }
954 break;
955 case 'jet-forms/media-field':
956 case 'jet-forms/textarea-field':
957 if ($label) {
958 $elements[] = $this->auto_field(
959 $field,
960 array(
961 'type' => 'e2pdf-html',
962 'block' => true,
963 'properties' => array(
964 'top' => '20',
965 'left' => '20',
966 'right' => '20',
967 'width' => '100%',
968 'height' => 'auto',
969 'value' => $label,
970 ),
971 )
972 );
973 }
974 $elements[] = $this->auto_field(
975 $field,
976 array(
977 'block' => $label ? false : true,
978 'type' => 'e2pdf-textarea',
979 'properties' => array(
980 'top' => $label ? '5' : '20',
981 'left' => $label ? '0' : '20',
982 'right' => $label ? '0' : '20',
983 'width' => '100%',
984 'height' => '150',
985 'value' => $value,
986 ),
987 )
988 );
989 if ($desc) {
990 $elements[] = $this->auto_field(
991 $field,
992 array(
993 'type' => 'e2pdf-html',
994 'block' => true,
995 'properties' => array(
996 'top' => '5',
997 'left' => '20',
998 'right' => '20',
999 'width' => '100%',
1000 'height' => 'auto',
1001 'value' => $desc,
1002 ),
1003 )
1004 );
1005 }
1006 break;
1007 case 'jet-forms/select-field':
1008 if ($label) {
1009 $elements[] = $this->auto_field(
1010 $field,
1011 array(
1012 'type' => 'e2pdf-html',
1013 'block' => true,
1014 'properties' => array(
1015 'top' => '20',
1016 'left' => '20',
1017 'right' => '20',
1018 'width' => '100%',
1019 'height' => 'auto',
1020 'value' => $label,
1021 ),
1022 )
1023 );
1024 }
1025
1026 $options = array();
1027 foreach ($field['attrs']['field_options'] as $option) {
1028 $options[] = $option['value'];
1029 }
1030 $elements[] = $this->auto_field(
1031 $field,
1032 array(
1033 'block' => $label ? false : true,
1034 'type' => 'e2pdf-select',
1035 'properties' => array(
1036 'top' => $label ? '5' : '20',
1037 'left' => $label ? '0' : '20',
1038 'right' => $label ? '0' : '20',
1039 'width' => '100%',
1040 'height' => 'auto',
1041 'options' => implode("\n", $options),
1042 'value' => $value,
1043 'height' => 'auto',
1044 ),
1045 )
1046 );
1047 if ($desc) {
1048 $elements[] = $this->auto_field(
1049 $field,
1050 array(
1051 'type' => 'e2pdf-html',
1052 'block' => true,
1053 'properties' => array(
1054 'top' => '5',
1055 'left' => '20',
1056 'right' => '20',
1057 'width' => '100%',
1058 'height' => 'auto',
1059 'value' => $desc,
1060 ),
1061 )
1062 );
1063 }
1064 break;
1065 case 'jet-forms/wysiwyg-field':
1066 if ($label) {
1067 $elements[] = $this->auto_field(
1068 $field,
1069 array(
1070 'type' => 'e2pdf-html',
1071 'block' => true,
1072 'properties' => array(
1073 'top' => '20',
1074 'left' => '20',
1075 'right' => '20',
1076 'width' => '100%',
1077 'height' => 'auto',
1078 'value' => $label,
1079 ),
1080 )
1081 );
1082 }
1083 $elements[] = array(
1084 'block' => $label ? false : true,
1085 'type' => 'e2pdf-html',
1086 'properties' => array(
1087 'top' => $label ? '5' : '20',
1088 'left' => $label ? '0' : '20',
1089 'right' => $label ? '0' : '20',
1090 'width' => '100%',
1091 'height' => '300',
1092 'value' => $value,
1093 ),
1094 );
1095 if ($desc) {
1096 $elements[] = $this->auto_field(
1097 $field,
1098 array(
1099 'type' => 'e2pdf-html',
1100 'block' => true,
1101 'properties' => array(
1102 'top' => '5',
1103 'left' => '20',
1104 'right' => '20',
1105 'width' => '100%',
1106 'height' => 'auto',
1107 'value' => $desc,
1108 ),
1109 )
1110 );
1111 }
1112 break;
1113 case 'jet-forms/switcher':
1114 $elements[] = $this->auto_field(
1115 $field,
1116 array(
1117 'type' => 'e2pdf-html',
1118 'block' => true,
1119 'properties' => array(
1120 'top' => '20',
1121 'left' => '20',
1122 'right' => '20',
1123 'width' => '100%',
1124 'height' => 'auto',
1125 'value' => $label,
1126 ),
1127 )
1128 );
1129 $elements[] = $this->auto_field(
1130 $field,
1131 array(
1132 'type' => 'e2pdf-checkbox',
1133 'properties' => array(
1134 'top' => '5',
1135 'width' => 'auto',
1136 'height' => 'auto',
1137 'value' => $value,
1138 'option' => 'on',
1139 ),
1140 )
1141 );
1142 break;
1143 case 'jet-forms/choices-field':
1144 $elements[] = $this->auto_field(
1145 $field,
1146 array(
1147 'type' => 'e2pdf-html',
1148 'block' => true,
1149 'properties' => array(
1150 'top' => '20',
1151 'left' => '20',
1152 'right' => '20',
1153 'width' => '100%',
1154 'height' => 'auto',
1155 'value' => $label,
1156 ),
1157 )
1158 );
1159 foreach ($field['innerBlocks'] as $checkbox) {
1160 $elements[] = $this->auto_field(
1161 $field,
1162 array(
1163 'type' => 'e2pdf-checkbox',
1164 'properties' => array(
1165 'top' => '5',
1166 'width' => 'auto',
1167 'height' => 'auto',
1168 'value' => $value,
1169 'option' => $checkbox['attrs']['value'],
1170 ),
1171 )
1172 );
1173 $elements[] = $this->auto_field(
1174 $field,
1175 array(
1176 'type' => 'e2pdf-html',
1177 'float' => true,
1178 'properties' => array(
1179 'left' => '5',
1180 'width' => '100%',
1181 'height' => 'auto',
1182 'value' => $checkbox['attrs']['value'],
1183 ),
1184 )
1185 );
1186 }
1187 if ($desc) {
1188 $elements[] = $this->auto_field(
1189 $field,
1190 array(
1191 'type' => 'e2pdf-html',
1192 'block' => true,
1193 'properties' => array(
1194 'top' => '5',
1195 'width' => '100%',
1196 'height' => 'auto',
1197 'value' => $desc,
1198 ),
1199 )
1200 );
1201 }
1202 break;
1203 case 'jet-forms/repeater-field':
1204 $repeater = !empty($field['attrs']['name']) ? $field['attrs']['name'] : '%field_name%';
1205 foreach ($field['innerBlocks'] as $subfield) {
1206 $elements = $this->auto_fields($elements, $subfield, $repeater);
1207 }
1208 break;
1209 case 'jet-forms/hidden-field':
1210 case 'jet-forms/submit-field':
1211 break;
1212 default:
1213 if (!empty($field['innerBlocks'])) {
1214 foreach ($field['innerBlocks'] as $subfield) {
1215 $elements = $this->auto_fields($elements, $subfield);
1216 }
1217 }
1218 break;
1219 }
1220 return $elements;
1221 }
1222
1223 // auto field
1224 public function auto_field($field = false, $element = array()) {
1225 if (!$field) {
1226 return false;
1227 }
1228 if (!isset($element['block'])) {
1229 $element['block'] = false;
1230 }
1231 if (!isset($element['float'])) {
1232 $element['float'] = false;
1233 }
1234 return $element;
1235 }
1236
1237 // styles
1238 public function styles($item_id = false) {
1239 $styles = array(
1240 plugins_url('css/extension/jetformbuilder.css?v=' . time(), $this->helper->get('plugin_file_path')),
1241 );
1242 return $styles;
1243 }
1244
1245 // get all forms
1246 public function get_all_forms($item_id) {
1247
1248 // phpcs:disable WordPress.Arrays.ArrayIndentation.ItemNotAligned
1249 $forms = new WP_Query(
1250 [
1251 'post_parent' => $item_id,
1252 'post_type' => ['any', 'revision'],
1253 'post_status' => ['any'],
1254 'posts_per_page' => -1,
1255 'fields' => 'ids',
1256 ]
1257 );
1258 // phpcs:enable WordPress.Arrays.ArrayIndentation.ItemNotAligned
1259
1260 return array_merge([$item_id], $forms->posts);
1261 }
1262
1263 // entry view hook
1264 public function hook_jetformbuilder_entry_view($containers) {
1265 if (class_exists('\JFB_Modules\Form_Record\Models\Record_Model') && !empty($containers[1]) && is_a($containers[1], '\Jet_Form_Builder\Admin\Single_Pages\Meta_Containers\Side_Meta_Container')) {
1266 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1267 $item_id = isset($_GET['item_id']) ? (int) $_GET['item_id'] : '0';
1268 global $wpdb;
1269
1270 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
1271 $form_id = $wpdb->get_var($wpdb->prepare('SELECT form_id FROM `' . \JFB_Modules\Form_Record\Models\Record_Model::table() . '` WHERE id = %d', $item_id));
1272 if ($form_id) {
1273 $hooks = $this->helper->load('hooks')->get('jetformbuilder', 'hook_jetformbuilder_entry_view', $form_id);
1274 if (!empty($hooks)) {
1275 if (
1276 class_exists('\Jet_Form_Builder\Admin\Table_Views\Column_Advanced_Base') &&
1277 class_exists('\Jet_Form_Builder\Admin\Single_Pages\Meta_Boxes\Base_List_Box') &&
1278 class_exists('\JFB_Modules\Form_Record\Query_Views\Record_View') &&
1279 class_exists('\Jet_Form_Builder\Exceptions\Query_Builder_Exception') &&
1280 class_exists('\Jet_Form_Builder\Admin\Exceptions\Not_Found_Page_Exception')
1281 ) {
1282 $containers[1]->add_meta_box(hook_e2pdf_jetformbuilder_entry_view_meta_box($hooks));
1283 }
1284 }
1285 }
1286 }
1287 return $containers;
1288 }
1289 }
1290
1291 // Hook to add a custom meta box for E2Pdf actions in JetFormBuilder entry view.
1292 function hook_e2pdf_jetformbuilder_entry_view_meta_box($hooks = array()) {
1293
1294 if (!class_exists('Hook_E2pdf_Jetformbuilder_Meta_Box')) {
1295
1296 // phpcs:ignore Generic.Files.OneObjectStructurePerFile.MultipleFound
1297 class Hook_E2pdf_Jetformbuilder_Meta_Box extends \Jet_Form_Builder\Admin\Single_Pages\Meta_Boxes\Base_List_Box {
1298
1299 protected $hooks = array();
1300
1301 public function get_title(): string {
1302 return apply_filters('e2pdf_hook_section_title', __('E2Pdf Actions', 'e2pdf'), 'hook_jetformbuilder_entry_view');
1303 }
1304
1305 public function get_columns(): array {
1306 $columns = array();
1307 foreach ($this->hooks as $hook) {
1308 $columns['e2pdf_' . $hook] = hook_e2pdf_jetformbuilder_entry_view_column($hook);
1309 }
1310 return $columns;
1311 }
1312
1313 public function get_list(): array {
1314 try {
1315 return \JFB_Modules\Form_Record\Query_Views\Record_View::findById($this->get_id());
1316 } catch (\Jet_Form_Builder\Exceptions\Query_Builder_Exception $exception) {
1317 throw new \Jet_Form_Builder\Admin\Exceptions\Not_Found_Page_Exception(
1318 esc_html($exception->getMessage()),
1319 // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
1320 ...$exception->get_additional()
1321 );
1322 }
1323 }
1324
1325 public function set_hooks($hooks = array()) {
1326 $this->hooks = $hooks;
1327 }
1328 }
1329
1330 }
1331
1332 $meta_box = new Hook_E2pdf_Jetformbuilder_Meta_Box();
1333 $meta_box->set_hooks($hooks);
1334 return $meta_box;
1335 }
1336
1337 // Generate a column definition for E2Pdf actions in JetFormBuilder entry view.
1338 function hook_e2pdf_jetformbuilder_entry_view_column($hook = '') {
1339
1340 if (!class_exists('Hook_E2pdf_Jetformbuilder_Column')) {
1341
1342 // phpcs:ignore Generic.Files.OneObjectStructurePerFile.MultipleFound
1343 class Hook_E2pdf_Jetformbuilder_Column extends \Jet_Form_Builder\Admin\Table_Views\Column_Advanced_Base {
1344
1345 protected $column = 'e2pdf';
1346 protected $type = self::LINK;
1347 protected $hook = '';
1348
1349 public function get_label(): string {
1350 return '';
1351 }
1352
1353 public function get_value(array $record = array()) {
1354 $record_id = (int) $record['id'];
1355 $action = array();
1356 if (Helper_E2pdf_Helper::instance()->load('hooks')->process_hook(
1357 $this->hook,
1358 [
1359 'dataset' => $record_id,
1360 ],
1361 'hook_jetformbuilder_entry_view'
1362 )
1363 ) {
1364 $action = apply_filters(
1365 'e2pdf_hook_action_button',
1366 array(
1367 'html' => '<p style="padding: 6px 12px 6.5px 42px"><a class="e2pdf-download-hook" target="_blank" href="%s"><span class="dashicons dashicons-pdf"></span> %s</a></p>',
1368 'url' => Helper_E2pdf_Helper::instance()->get_url(
1369 array(
1370 'page' => 'e2pdf',
1371 'action' => 'export',
1372 'id' => $this->hook,
1373 'dataset' => $record_id,
1374 ), 'admin.php?'
1375 ),
1376 'title' => 'PDF #' . $this->hook,
1377 ), 'hook_jetformbuilder_entry_view', $this->hook, $record_id
1378 );
1379 }
1380 if (!empty($action)) {
1381 return array(
1382 'text' => $action['title'],
1383 'href' => $action['url'],
1384 'target' => '_blank',
1385 'type' => 'media-document',
1386 );
1387 } else {
1388 return array();
1389 }
1390 }
1391
1392 public function set_hook($hook = '') {
1393 $this->hook = $hook;
1394 }
1395 }
1396
1397 }
1398
1399 $column = new Hook_E2pdf_Jetformbuilder_Column();
1400 $column->set_hook($hook);
1401 return $column;
1402 }
1403
1404 // Hook to add a content filter
1405 function hook_e2pdf_jetformbuilder_content_filter($hooks = array()) {
1406 if (!class_exists('Hook_E2pdf_Jetformbuilder_Filter')) {
1407
1408 // phpcs:ignore Generic.Files.OneObjectStructurePerFile.MultipleFound
1409 class Hook_E2pdf_Jetformbuilder_Content_Filter extends \Jet_Form_Builder\Classes\Filters\Base_Multiple_Filter {
1410
1411 public function get_id(): string {
1412 return 'e2pdf';
1413 }
1414
1415 public function callback_args(): array {
1416 return array();
1417 }
1418
1419 public function apply_macros($value, ...$args): string {
1420 if (empty($value)) {
1421 return '';
1422 }
1423 $sub_args = array();
1424 if (!empty($args[0])) {
1425 $sub_args = explode(':', $args[0]);
1426 }
1427 $filter = isset($sub_args[0]) ? $sub_args[0] : '';
1428 if ($filter == 'glossary_labels') {
1429 if (function_exists('jet_engine_label_by_glossary') && !empty($sub_args[1])) {
1430 if (!is_array($value)) {
1431 $value = explode(',', (string) $value);
1432 }
1433 $labels = jet_engine_label_by_glossary($value, $sub_args[1]);
1434 if (is_string($labels)) {
1435 return $labels;
1436 }
1437 }
1438 }
1439
1440 return '';
1441 }
1442
1443 protected function apply_item($item, ...$args): string {
1444 return $item;
1445 }
1446 }
1447
1448 }
1449 return new Hook_E2pdf_Jetformbuilder_Content_Filter();
1450 }
1451