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

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

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