PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.23
E2Pdf – Export Pdf Tool for WordPress v1.32.23
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-wordpress.php

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

1,594 lines 73.4 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-wordpress.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 // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName
15 class Extension_E2pdf_Wordpress extends Model_E2pdf_Model {
16
17 private $options;
18 private $info = array(
19 'key' => 'wordpress',
20 'title' => 'WordPress',
21 );
22
23 // info
24 public function info($key = false) {
25 if ($key && isset($this->info[$key])) {
26 return $this->info[$key];
27 } else {
28 return array(
29 $this->info['key'] => $this->info['title'],
30 );
31 }
32 }
33
34 // active
35 public function active() {
36 return true;
37 }
38
39 // set
40 public function set($key, $value) {
41 if (!isset($this->options)) {
42 $this->options = new stdClass();
43 }
44 $this->options->$key = $value;
45 switch ($key) {
46 case 'dataset':
47 $this->set('cached_post', false);
48 if ($this->get('dataset')) {
49 if ($this->get('item') == '-3') {
50 $this->set('cached_post', get_user_by('id', $this->get('dataset')));
51 } else {
52 $pll = $this->helper->load('translator')->isPolylang();
53 if ($pll) {
54 $lang = pll_get_post_language($this->get('dataset'));
55 if ($lang) {
56 PLL()->curlang = PLL()->model->get_language($lang);
57 }
58 }
59 $this->set('cached_post', get_post($this->get('dataset')));
60 }
61 }
62 break;
63 default:
64 break;
65 }
66 }
67
68 // get
69 public function get($key) {
70 if ($key == 'user_id' && $this->get('item') == '-3') {
71 $key = 'dataset';
72 }
73 if (isset($this->options->$key)) {
74 $value = $this->options->$key;
75 } else {
76 switch ($key) {
77 case 'args':
78 $value = array();
79 break;
80 default:
81 $value = false;
82 break;
83 }
84 }
85 return $value;
86 }
87
88 // items
89 public function items() {
90 $items = array();
91 $forms = get_post_types(array(), 'names');
92 foreach ($forms as $form) {
93 if ($form != 'attachment') {
94 $items[] = $this->item($form);
95 }
96 }
97 $items[] = $this->item('-3');
98 return $items;
99 }
100
101 // datasets
102 public function datasets($item_id = false, $name = false) {
103 $datasets = array();
104 if ($item_id) {
105 if ($item_id == '-3') {
106 $entries = get_users(
107 array(
108 'fields' => array(
109 'ID', 'user_login',
110 ),
111 )
112 );
113
114 if ($entries) {
115 $this->set('item', $item_id);
116 foreach ($entries as $key => $entry) {
117 $this->set('dataset', $entry->ID);
118 $entry_title = $this->render($name);
119 if (!$entry_title) {
120 $entry_title = isset($entry->user_login) && $entry->user_login ? $entry->user_login : $entry->ID;
121 }
122 $datasets[] = array(
123 'key' => $entry->ID,
124 'value' => $entry_title,
125 );
126 }
127 }
128 } else {
129 $wpml = $this->helper->load('translator')->isWPML();
130 if ($wpml) {
131 $lang = apply_filters('wpml_current_language', null);
132 $entries = get_posts(
133 array(
134 'post_type' => $item_id,
135 'numberposts' => -1,
136 'post_status' => 'any',
137 'lang' => $lang,
138 'suppress_filters' => false,
139 )
140 );
141 } else {
142 $entries = get_posts(
143 array(
144 'post_type' => $item_id,
145 'numberposts' => -1,
146 'post_status' => 'any',
147 )
148 );
149 }
150 if ($entries) {
151 $this->set('item', $item_id);
152 foreach ($entries as $key => $entry) {
153 $this->set('dataset', $entry->ID);
154 $entry_title = $this->render($name);
155 if (!$entry_title) {
156 $entry_title = isset($entry->post_title) && $entry->post_title ? $entry->post_title : $entry->ID;
157 }
158 $datasets[] = array(
159 'key' => $entry->ID,
160 'value' => $entry_title,
161 );
162 }
163 }
164 }
165 }
166 return $datasets;
167 }
168
169 // get dataset actions
170 public function get_dataset_actions($dataset_id = false) {
171 $dataset_id = (int) $dataset_id;
172 if (!$dataset_id) {
173 return false;
174 }
175 $actions = new stdClass();
176 if ($this->get('item') == '-3') {
177 $actions->view = $this->helper->get_url(
178 array(
179 'user_id' => $dataset_id,
180 ), 'user-edit.php?'
181 );
182 } else {
183 $actions->view = $this->helper->get_url(
184 array(
185 'post' => $dataset_id,
186 'action' => 'edit',
187 ), 'post.php?'
188 );
189 }
190 $actions->delete = false;
191 return $actions;
192 }
193
194 // get template actions
195 public function get_template_actions($template = false) {
196 $template = (int) $template;
197 if (!$template) {
198 return;
199 }
200 $actions = new stdClass();
201 $actions->delete = false;
202 return $actions;
203 }
204
205 // item
206 public function item($item_id = false) {
207 if (!$item_id && $this->get('item')) {
208 $item_id = $this->get('item');
209 }
210 $item = new stdClass();
211 if ($item_id == '-3') {
212 $item->id = $item_id;
213 $item->name = __('Users');
214 $item->url = $this->helper->get_url(array(), 'users.php');
215 } else {
216 $form = get_post_type_object($item_id);
217 if ($form) {
218 $item->id = $item_id;
219 $item->name = $form->label ? $form->label : $item_id;
220 $item->url = $this->helper->get_url(array('post_type' => $item_id), 'edit.php?');
221 } else {
222 $item->id = '';
223 $item->name = '';
224 $item->url = '';
225 }
226 }
227 return $item;
228 }
229
230 // load filters
231 public function load_filters() {
232 add_filter('the_content', array($this, 'filter_the_content'), 10, 2);
233 add_filter('widget_text', array($this, 'filter_content_custom'));
234 add_filter('widget_block_content', array($this, 'filter_content_custom'));
235
236 /**
237 * Popup Maker – Popup for opt-ins, lead gen, & more
238 * https://wordpress.org/plugins/popup-maker/
239 */
240 add_filter('pum_popup_content', array($this, 'filter_the_content'), 10, 2);
241
242 /**
243 * Events Manager
244 * https://wordpress.org/plugins/events-manager/
245 */
246 add_filter('em_event_output_placeholder', array($this, 'filter_content_custom'), 0);
247 add_filter('em_event_output', array($this, 'filter_content_custom'));
248 add_filter('em_booking_output_placeholder', array($this, 'filter_content_custom'), 0);
249 add_filter('em_booking_output', array($this, 'filter_content_custom'));
250 add_filter('em_location_output_placeholder', array($this, 'filter_content_custom'), 0);
251 add_filter('em_location_output', array($this, 'filter_content_custom'));
252 add_filter('em_category_output_placeholder', array($this, 'filter_content_custom'), 0);
253
254 /**
255 * Beaver Builder – WordPress Page Builder
256 * https://wordpress.org/plugins/beaver-builder-lite-version/
257 */
258 add_filter('fl_builder_before_render_shortcodes', array($this, 'filter_content_loop'));
259
260 /**
261 * WPBakery Page Builder Image Object Link
262 */
263 add_filter('vc_map_get_attributes', array($this, 'filter_vc_map_get_attributes'), 10, 2);
264
265 /**
266 * Flatsome theme global tab content
267 */
268 add_filter('theme_mod_tab_content', array($this, 'filter_content_custom'));
269
270 /**
271 * MemberPress Mail attachments
272 * https://memberpress.com/
273 */
274 add_filter('mepr_email_send_attachments', array($this, 'filter_mepr_email_send_attachments'), 10, 4);
275 add_filter('the_content', array($this, 'filter_mepr_the_content'), 99);
276 add_filter('mepr_custom_thankyou_message', array($this, 'filter_mepr_custom_thankyou_message'));
277
278 /**
279 * Thrive Theme Builder dynamic shortcode support
280 */
281 add_filter('thrive_theme_template_content', array($this, 'filter_thrive_theme_template_content'));
282
283 /**
284 * WPBakery Page Builder Grid Item
285 * [e2pdf-download id="1" dataset="{{ post_data:ID }}"]
286 */
287 add_filter('vc_basic_grid_items_list', array($this, 'filter_vc_basic_grid_items_list'));
288
289 /**
290 * Themify Builder dynamic shortcode support
291 * https://wordpress.org/plugins/themify-builder/
292 */
293 add_filter('themify_builder_module_content', array($this, 'filter_themify_builder_module_content'));
294
295 /**
296 * Impreza theme by Up Solutions
297 * https://themeforest.net/item/impreza-retina-responsive-wordpress-theme/6434280
298 */
299 add_filter('us_content_template_the_content', array($this, 'filter_content_custom'));
300
301 /**
302 * Cornerstone Builder
303 * https://theme.co/cornerstone/
304 */
305 add_filter('cs_element_pre_render', array($this, 'filter_cs_element_pre_render'));
306
307 /**
308 * Divi Theme Builder
309 * https://www.elegantthemes.com/
310 */
311 add_filter('et_pb_module_content', array($this, 'filter_et_pb_module_content'), 30, 6);
312
313 /**
314 * User Registration & Membership – Custom Registration Form, Login Form, and User Profile
315 * https://wordpress.org/plugins/user-registration/
316 */
317 add_filter('user_registration_smart_tag_values', array($this, 'filter_user_registration_smart_tag_values'), 0);
318
319 /* Hooks */
320 add_filter('post_row_actions', array($this, 'hook_wordpress_row_actions'), 10, 2);
321 add_filter('page_row_actions', array($this, 'hook_wordpress_row_actions'), 10, 2);
322 add_filter('user_row_actions', array($this, 'hook_wordpress_row_actions'), 10, 2);
323 }
324
325 // load actions
326 public function load_actions() {
327 /**
328 * Elementor Website Builder – More than Just a Page Builder
329 * https://wordpress.org/plugins/elementor/
330 */
331 add_action('elementor/widget/before_render_content', array($this, 'action_elementor_widget_before_render_content'));
332 add_action('elementor/frontend/widget/before_render', array($this, 'action_elementor_widget_before_render_content'), 5);
333
334 /**
335 * JetEngine: WordPress Plugin for Elementor
336 * https://crocoblock.com
337 */
338 add_action('jet-engine/listing/grid/before-render', array($this, 'action_jet_engine_listing_grid_before_render'));
339 add_action('jet-engine/listing/grid/after-render', array($this, 'action_jet_engine_listing_grid_after_render'));
340
341 /**
342 * Happy Addons for Elementor
343 * https://wordpress.org/plugins/happy-elementor-addons/ compatibility fix
344 */
345 add_action('elementor/frontend/before_render', array($this, 'action_elementor_widget_before_render_content'), 0);
346
347 /**
348 * MemberPress Mail attachments remove
349 * https://memberpress.com/
350 */
351 add_action('mepr_email_sent', array($this, 'action_mepr_email_sent'), 10, 3);
352
353 /**
354 * User Registration & Membership – Custom Registration Form, Login Form, and User Profile
355 * https://wordpress.org/plugins/user-registration/
356 */
357 add_action('user_registration_email_send_before', array($this, 'action_user_registration_email_send_before'));
358 add_action('user_registration_email_send_after', array($this, 'action_user_registration_email_send_after'));
359
360 /* Hooks */
361 add_action('add_meta_boxes', array($this, 'hook_wordpress_page_edit'));
362 }
363
364 // render
365 public function render($value, $field = array(), $convert_shortcodes = true, $raw = false) {
366 $value = $this->render_shortcodes($value, $field);
367 if (!$raw) {
368 $value = $this->strip_shortcodes($value);
369 $value = $this->convert_shortcodes($value, $convert_shortcodes, isset($field['type']) && $field['type'] == 'e2pdf-html' ? true : false);
370 $value = $this->helper->load('field')->render_checkbox($value, $this, $field);
371 }
372 return $value;
373 }
374
375 // render shortcodes
376 public function render_shortcodes($value, $field = array()) {
377
378 $element_id = isset($field['element_id']) ? $field['element_id'] : false;
379
380 if ($this->verify()) {
381 /**
382 * Set current Post for Toolset Views
383 * https://toolset.com/
384 */
385 do_action('wpv_action_wpv_set_top_current_post', $this->get('cached_post'));
386
387 $wordpress_shortcodes = array(
388 'id',
389 'post_author',
390 'post_date',
391 'post_date_gmt',
392 'post_content',
393 'post_title',
394 'post_excerpt',
395 'post_status',
396 'comment_status',
397 'ping_status',
398 'post_password',
399 'post_name',
400 'to_ping',
401 'pinged',
402 'post_modified',
403 'post_modified_gmt',
404 'post_content_filtered',
405 'post_parent',
406 'guid',
407 'menu_order',
408 'post_type',
409 'post_mime_type',
410 'comment_count',
411 'filter',
412 'post_thumbnail',
413 'get_the_post_thumbnail',
414 'get_the_post_thumbnail_url',
415 'get_permalink',
416 'get_post_permalink',
417 );
418
419 if (false !== strpos($value, '[')) {
420 $value = $this->helper->load('field')->pre_shortcodes($value, $this, $field);
421 $value = $this->helper->load('field')->inner_shortcodes($value, $this, $field);
422 if ($this->get('item') == '-3') {
423 $shortcode_tags = array(
424 'acf',
425 );
426 } else {
427 $shortcode_tags = array(
428 'meta',
429 'terms',
430 'e2pdf-wp',
431 'e2pdf-wp-term',
432 'e2pdf-content',
433 'acf',
434 );
435 $shortcode_tags = array_merge($shortcode_tags, $wordpress_shortcodes);
436 }
437 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches);
438 $tagnames = array_intersect($shortcode_tags, $matches[1]);
439 if (!empty($tagnames)) {
440 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $value, $shortcodes);
441 foreach ($shortcodes[0] as $key => $shortcode_value) {
442 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
443 $atts = shortcode_parse_atts($shortcode[3]);
444 if ($shortcode[2] === 'e2pdf-content') {
445 if (!isset($atts['id']) && isset($this->get('cached_post')->ID) && $this->get('cached_post')->ID) {
446 $shortcode[3] .= ' id=' . $this->get('cached_post')->ID . '';
447 $value = str_replace($shortcode_value, '[' . $shortcode[2] . $shortcode[3] . ']', $value);
448 }
449 } elseif ($shortcode[2] === 'meta' || $shortcode[2] === 'terms' || $shortcode[2] == 'e2pdf-wp') {
450 if (!isset($atts['id']) && isset($this->get('cached_post')->ID) && $this->get('cached_post')->ID) {
451 $shortcode[3] .= ' id=' . $this->get('cached_post')->ID . '';
452 }
453 if ($shortcode[2] === 'meta') {
454 $shortcode[3] .= ' meta=true';
455 }
456 if ($shortcode[2] === 'terms') {
457 $shortcode[3] .= ' terms=true';
458 }
459 if (substr($shortcode_value, -11) === '[/e2pdf-wp]' || substr($shortcode_value, -8) === '[/terms]' || substr($shortcode_value, -7) === '[/meta]') {
460 if ($shortcode[5]) {
461 $shortcode[5] = $this->render($shortcode[5], array(), false);
462 }
463 $value = str_replace($shortcode_value, '[e2pdf-wp' . $shortcode[3] . ']' . $shortcode[5] . '[/e2pdf-wp]', $value);
464 } else {
465 $value = str_replace($shortcode_value, '[e2pdf-wp' . $shortcode[3] . ']', $value);
466 }
467 } elseif ($shortcode[2] === 'e2pdf-wp-term') {
468 if (substr($shortcode_value, -16) === '[/e2pdf-wp-term]') {
469 if ($shortcode[5]) {
470 $shortcode[5] = $this->render($shortcode[5], array(), false);
471 }
472 $value = str_replace($shortcode_value, '[e2pdf-wp-term' . $shortcode[3] . ']' . $shortcode[5] . '[/e2pdf-wp-term]', $value);
473 }
474 } elseif (in_array($shortcode[2], $wordpress_shortcodes, false)) {
475 if (!isset($atts['id']) && isset($this->get('cached_post')->ID) && $this->get('cached_post')->ID) {
476 $shortcode[3] .= ' id=' . $this->get('cached_post')->ID . '';
477 }
478 $shortcode[3] .= ' key=' . $shortcode[2] . '';
479 $value = str_replace($shortcode_value, '[e2pdf-wp' . $shortcode[3] . ']', $value);
480 } elseif ($shortcode[2] === 'acf') {
481 if (!isset($atts['post_id']) && isset($this->get('cached_post')->ID) && $this->get('cached_post')->ID) {
482 if ($this->get('item') == '-3') {
483 $shortcode[3] .= ' post_id=user_' . $this->get('cached_post')->ID . '';
484 } else {
485 $shortcode[3] .= ' post_id=' . $this->get('cached_post')->ID . '';
486 }
487 $value = str_replace($shortcode_value, '[' . $shortcode[2] . $shortcode[3] . ']', $value);
488 }
489 }
490 }
491 }
492 $value = $this->helper->load('field')->wrapper_shortcodes($value, $this, $field);
493 }
494
495 add_filter('frm_filter_view', array($this, 'filter_frm_filter_view'));
496 $value = $this->helper->load('field')->do_shortcodes($value, $this, $field);
497 $value = $this->helper->load('field')->render(
498 apply_filters('e2pdf_extension_render_shortcodes_pre_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false),
499 $this,
500 $field
501 );
502 remove_filter('frm_filter_view', array($this, 'filter_frm_filter_view'));
503 }
504 return apply_filters(
505 'e2pdf_extension_render_shortcodes_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false
506 );
507 }
508
509 // strip shortcodes
510 public function strip_shortcodes($value) {
511 $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', '', $value);
512 return $value;
513 }
514
515 // convert shortcodes
516 public function convert_shortcodes($value, $to = false, $html = false) {
517 if ($value) {
518 if ($to) {
519 $value = str_replace('&#91;', '[', $value);
520 if (!$html) {
521 $value = wp_specialchars_decode($value, ENT_QUOTES);
522 }
523 } else {
524 $value = str_replace('[', '&#91;', $value);
525 }
526 }
527 return $value;
528 }
529
530 // auto
531 public function auto() {
532
533 $response = array();
534 $elements = array();
535
536 if ($this->get('item') == '-3') {
537 $elements[] = array(
538 'type' => 'e2pdf-html',
539 'block' => true,
540 'properties' => array(
541 'top' => '20',
542 'left' => '20',
543 'right' => '20',
544 'width' => '100%',
545 'height' => 'auto',
546 'value' => '<h1>[e2pdf-user key="user_login"]</h1>',
547 ),
548 );
549 $elements[] = array(
550 'type' => 'e2pdf-image',
551 'block' => true,
552 'properties' => array(
553 'top' => '20',
554 'left' => '20',
555 'right' => '20',
556 'width' => '100%',
557 'height' => '100',
558 'vertical' => 'top',
559 'value' => '[e2pdf-user key="get_avatar_url"]',
560 ),
561 );
562 $elements[] = array(
563 'type' => 'e2pdf-html',
564 'block' => true,
565 'properties' => array(
566 'top' => '20',
567 'left' => '20',
568 'right' => '20',
569 'width' => '100%',
570 'height' => 'auto',
571 'value' => 'ID: [e2pdf-user key="ID"]',
572 ),
573 );
574 $elements[] = array(
575 'type' => 'e2pdf-html',
576 'block' => true,
577 'properties' => array(
578 'top' => '20',
579 'left' => '20',
580 'right' => '20',
581 'width' => '100%',
582 'height' => 'auto',
583 'value' => 'First Name: [e2pdf-user key="user_firstname"]',
584 ),
585 );
586 $elements[] = array(
587 'type' => 'e2pdf-html',
588 'block' => true,
589 'properties' => array(
590 'top' => '20',
591 'left' => '20',
592 'right' => '20',
593 'width' => '100%',
594 'height' => 'auto',
595 'value' => 'Last Name: [e2pdf-user key="user_lastname"]',
596 ),
597 );
598 $elements[] = array(
599 'type' => 'e2pdf-html',
600 'block' => true,
601 'properties' => array(
602 'top' => '20',
603 'left' => '20',
604 'right' => '20',
605 'width' => '100%',
606 'height' => 'auto',
607 'value' => 'Email: [e2pdf-user key="user_email"]',
608 ),
609 );
610 $elements[] = array(
611 'type' => 'e2pdf-html',
612 'block' => true,
613 'properties' => array(
614 'top' => '20',
615 'left' => '20',
616 'right' => '20',
617 'width' => '100%',
618 'height' => 'auto',
619 'value' => 'Registered: [e2pdf-user key="user_registered"]',
620 ),
621 );
622 } else {
623 $elements[] = array(
624 'type' => 'e2pdf-html',
625 'block' => true,
626 'properties' => array(
627 'top' => '20',
628 'left' => '20',
629 'right' => '20',
630 'width' => '100%',
631 'height' => 'auto',
632 'value' => '<h1>[e2pdf-wp key="post_title"]</h1>',
633 ),
634 );
635 $elements[] = array(
636 'type' => 'e2pdf-html',
637 'block' => true,
638 'properties' => array(
639 'top' => '20',
640 'left' => '20',
641 'right' => '20',
642 'width' => '100%',
643 'height' => 'auto',
644 'value' => 'Post name: [e2pdf-wp key="post_name"]',
645 ),
646 );
647 $elements[] = array(
648 'type' => 'e2pdf-html',
649 'block' => true,
650 'properties' => array(
651 'top' => '20',
652 'left' => '20',
653 'right' => '20',
654 'width' => '100%',
655 'height' => 'auto',
656 'value' => 'Post type: [e2pdf-wp key="post_type"]',
657 ),
658 );
659 $elements[] = array(
660 'type' => 'e2pdf-html',
661 'block' => true,
662 'properties' => array(
663 'top' => '20',
664 'left' => '20',
665 'right' => '20',
666 'width' => '100%',
667 'height' => 'auto',
668 'value' => 'ID: [e2pdf-wp key="id"]',
669 ),
670 );
671 $elements[] = array(
672 'type' => 'e2pdf-html',
673 'block' => true,
674 'properties' => array(
675 'top' => '20',
676 'left' => '20',
677 'right' => '20',
678 'width' => '100%',
679 'height' => 'auto',
680 'value' => 'Author: [e2pdf-wp key="post_author"]',
681 ),
682 );
683 $elements[] = array(
684 'type' => 'e2pdf-html',
685 'block' => true,
686 'properties' => array(
687 'top' => '20',
688 'left' => '20',
689 'right' => '20',
690 'width' => '100%',
691 'height' => '300',
692 'value' => '[e2pdf-wp key="post_content"]',
693 ),
694 );
695 $elements[] = array(
696 'type' => 'e2pdf-html',
697 'block' => true,
698 'properties' => array(
699 'top' => '20',
700 'left' => '20',
701 'right' => '20',
702 'width' => '100%',
703 'height' => 'auto',
704 'value' => 'Created: [e2pdf-wp key="post_date"]',
705 ),
706 );
707 $elements[] = array(
708 'type' => 'e2pdf-html',
709 'block' => true,
710 'properties' => array(
711 'top' => '20',
712 'left' => '20',
713 'right' => '20',
714 'width' => '100%',
715 'height' => 'auto',
716 'value' => 'Modified: [e2pdf-wp key="post_modified"]',
717 ),
718 );
719 }
720 $response['page'] = array(
721 'bottom' => '20',
722 'top' => '20',
723 'left' => '20',
724 'right' => '20',
725 );
726
727 $response['elements'] = $elements;
728 return $response;
729 }
730
731 // before render content widget action
732 public function action_elementor_widget_before_render_content($widget) {
733 if ($widget && ($widget->get_name() == 'shortcode' || $widget->get_name() == 'text-editor')) {
734 $content = $widget->get_name() == 'shortcode' ? $widget->get_settings('shortcode') : $widget->get_settings('editor');
735 if ($content && false !== strpos($content, '[e2pdf-')) {
736 $wp_reset_postdata = true;
737 if (class_exists('\ElementorPro\Plugin') && class_exists('\ElementorPro\Modules\LoopBuilder\Documents\Loop')) {
738 $document = \ElementorPro\Plugin::elementor()->documents->get_current();
739 if ($document && $document instanceof \ElementorPro\Modules\LoopBuilder\Documents\Loop) {
740 $wp_reset_postdata = false;
741 }
742 }
743 if ($widget->get_name() == 'shortcode') {
744 $widget->set_settings('shortcode', $this->filter_content($content, false, $wp_reset_postdata));
745 } elseif ($widget->get_name() == 'text-editor' && !$wp_reset_postdata) {
746 $widget->set_settings('editor', $this->filter_content($content, false, $wp_reset_postdata));
747 }
748 }
749 }
750 }
751
752 // jet engine listing grid before render action
753 public function action_jet_engine_listing_grid_before_render($listing_grid) {
754 $this->set('queried_object', true);
755 }
756
757 // jet engine listing grid after render action
758 public function action_jet_engine_listing_grid_after_render($listing_grid) {
759 $this->set('queried_object', false);
760 }
761
762 /**
763 * Delete attachments that were sent by MemberPress email
764 * https://memberpress.com/
765 */
766 public function action_mepr_email_sent($email, $values, $attachments) {
767 $files = $this->helper->get('wordpress_attachments_mepr');
768 if (is_array($files) && !empty($files)) {
769 foreach ($files as $key => $file) {
770 $this->helper->delete_dir(dirname($file) . '/');
771 }
772 $this->helper->deset('wordpress_attachments_mepr');
773 }
774 }
775
776 // registration email send before action
777 public function action_user_registration_email_send_before() {
778 add_filter('wp_mail', array($this, 'filter_wp_mail'), 11);
779 }
780
781 // registration email send after action
782 public function action_user_registration_email_send_after() {
783 remove_filter('wp_mail', array($this, 'filter_wp_mail'), 11);
784 $files = $this->helper->get('wordpress_attachments');
785 if (is_array($files) && !empty($files)) {
786 foreach ($files as $key => $file) {
787 $this->helper->delete_dir(dirname($file) . '/');
788 }
789 $this->helper->deset('wordpress_attachments');
790 }
791 }
792
793 // filter content
794 public function filter_content($content, $post_id = false, $wp_reset_postdata = true) {
795 global $post;
796 if (!is_string($content) || false === strpos($content, '[')) {
797 return $content;
798 }
799 $shortcode_tags = array(
800 'e2pdf-download',
801 'e2pdf-save',
802 'e2pdf-view',
803 'e2pdf-adobesign',
804 'e2pdf-zapier',
805 );
806 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
807 $tagnames = array_intersect($shortcode_tags, $matches[1]);
808 if (!empty($tagnames)) {
809 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
810 foreach ($shortcodes[0] as $key => $shortcode_value) {
811 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
812 $atts = shortcode_parse_atts($shortcode[3]);
813 if (isset($atts['wp_reset_postdata'])) {
814 if ($atts['wp_reset_postdata'] == 'true') {
815 $wp_reset_postdata = true;
816 } else {
817 $wp_reset_postdata = false;
818 }
819 }
820 if ($wp_reset_postdata) {
821 wp_reset_postdata();
822 }
823 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
824 } else {
825 if (isset($atts['id'])) {
826 $template = new Model_E2pdf_Template();
827 $template->load($atts['id']);
828 if ($template->get('extension') === 'woocommerce' || $template->get('extension') === 'jetformbuilder') {
829 continue;
830 } elseif ($template->get('extension') === 'wordpress') { // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
831 if (!isset($atts['dataset'])) {
832 if ($template->get('item') == '-3') {
833 $dataset = get_current_user_id();
834 $atts['dataset'] = $dataset;
835 $shortcode[3] .= ' dataset="' . $dataset . '"';
836 } else {
837 if ($this->get('queried_object') && !$post_id) {
838 $queried_object = get_queried_object();
839 $post_id = $queried_object && isset($queried_object->ID) ? $queried_object->ID : false;
840 }
841 if ($post_id || isset($post->ID)) {
842 $dataset = $post_id ? $post_id : $post->ID;
843 $atts['dataset'] = $dataset;
844 $shortcode[3] .= ' dataset="' . $dataset . '"';
845 }
846 }
847 }
848 }
849 }
850 if (!isset($atts['apply'])) {
851 $shortcode[3] .= ' apply="true"';
852 }
853 if (!isset($atts['filter'])) {
854 $shortcode[3] .= ' filter="true"';
855 }
856 $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content);
857 }
858 }
859 }
860 return $content;
861 }
862
863 // [e2pdf-exclude] support inside Formidable Forms View beforeContent and afterContent
864 public function filter_frm_filter_view($view) {
865 if (isset($view->frm_before_content) && $view->frm_before_content) {
866 $view->frm_before_content = str_replace('[e2pdf-exclude]', '[e2pdf-exclude apply="true"]', $view->frm_before_content);
867 }
868 if (isset($view->post_content) && $view->post_content) {
869 $view->post_content = str_replace('[e2pdf-exclude]', '[e2pdf-exclude apply="true"]', $view->post_content);
870 }
871 if (isset($view->frm_after_content) && $view->frm_after_content) {
872 $view->frm_after_content = str_replace('[e2pdf-exclude]', '[e2pdf-exclude apply="true"]', $view->frm_after_content);
873 }
874 return $view;
875 }
876
877 // vc map get attributes filter
878 public function filter_vc_map_get_attributes($atts, $tag) {
879 if ($tag == 'vc_single_image' && ((isset($atts['onclick']) && $atts['onclick'] == 'custom_link') || (empty($atts['onclick']) && (!isset($atts['img_link_large']) || 'yes' !== $atts['img_link_large']))) && (!empty($atts['link']) || !empty($atts['img_link']))) {
880
881 if (!empty($atts['link'])) {
882 $atts['link'] = $this->filter_content($atts['link']);
883 }
884
885 if (!empty($atts['img_link'])) {
886 $atts['img_link'] = $this->filter_content($atts['img_link']);
887 }
888 }
889 return $atts;
890 }
891
892 // filter cs element pre prender
893 public function filter_cs_element_pre_render($data) {
894 if (!empty($data['_type']) && $data['_type'] == 'raw-content' && !empty($data['raw_content']) && !empty($data['_p'])) {
895 $data['raw_content'] = $this->filter_content($data['raw_content'], $data['_p']);
896 }
897 return $data;
898 }
899
900 // filter themify builder module content
901 public function filter_themify_builder_module_content($content) {
902 if ($content) {
903 $content = $this->filter_content($content);
904 }
905 return $content;
906 }
907
908 // filter vs basic grid items list
909 public function filter_vc_basic_grid_items_list($items) {
910 if ($items) {
911 $items = $this->filter_content($items);
912 }
913 return $items;
914 }
915
916 // filter the content
917 public function filter_the_content($content, $post_id = false) {
918 $content = $this->filter_content($content, $post_id);
919 return $content;
920 }
921
922 // filter content custom
923 public function filter_content_custom($content) {
924 $content = $this->filter_content($content);
925 return $content;
926 }
927
928 // filter content loop
929 public function filter_content_loop($content) {
930 $content = $this->filter_content($content, false, false);
931 return $content;
932 }
933
934 /**
935 * Memberpress Mail attachments filter
936 * https://memberpress.com/
937 */
938 public function filter_mepr_email_send_attachments($attachments, $mail, $body, $values) {
939 $message = $body ? $body : $mail->body();
940 if ($message && false !== strpos($message, '[')) {
941 $message = $mail->replace_variables($message, $values);
942 $shortcode_tags = array(
943 'e2pdf-attachment',
944 'e2pdf-save',
945 );
946 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $message, $matches);
947 $tagnames = array_intersect($shortcode_tags, $matches[1]);
948 if (!empty($tagnames)) {
949 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $message, $shortcodes);
950 foreach ($shortcodes[0] as $key => $shortcode_value) {
951 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
952 $atts = shortcode_parse_atts($shortcode[3]);
953 $file = false;
954 if (isset($atts['id']) && isset($atts['dataset'])) {
955 if (!isset($atts['apply'])) {
956 $shortcode[3] .= ' apply="true"';
957 }
958 if (!isset($atts['filter'])) {
959 $shortcode[3] .= ' filter="true"';
960 }
961 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) {
962 $file = do_shortcode_tag($shortcode);
963 if ($file) {
964 $tmp = false;
965 if (substr($file, 0, 4) === 'tmp:') {
966 $file = substr($file, 4);
967 $tmp = true;
968 }
969 if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
970 if ($tmp) {
971 $this->helper->add('wordpress_attachments_mepr', $file);
972 }
973 } else {
974 $this->helper->add('wordpress_attachments_mepr', $file);
975 }
976 $attachments[] = $file;
977 }
978 }
979 }
980 }
981 }
982 }
983 return $attachments;
984 }
985
986 // mepr the content filter
987 public function filter_mepr_the_content($content) {
988 if (
989 class_exists('MeprUtils') && method_exists('MeprUtils', 'get_current_post') &&
990 class_exists('MeprOptions') && method_exists('MeprOptions', 'fetch')
991 ) {
992 $current_post = MeprUtils::get_current_post();
993 if ($current_post !== false) {
994 $mepr_options = MeprOptions::fetch();
995 if ($current_post->ID == $mepr_options->thankyou_page_id) {
996 remove_shortcode('e2pdf-download');
997 remove_shortcode('e2pdf-view');
998 remove_shortcode('e2pdf-save');
999 remove_shortcode('e2pdf-zapier');
1000 remove_shortcode('e2pdf-adobesign');
1001 }
1002 }
1003 }
1004 return $content;
1005 }
1006
1007 // mepr custom thank you message filter
1008 public function filter_mepr_custom_thankyou_message($content) {
1009 add_shortcode('e2pdf-download', array(new Model_E2pdf_Shortcode(), 'e2pdf_download'));
1010 add_shortcode('e2pdf-view', array(new Model_E2pdf_Shortcode(), 'e2pdf_view'));
1011 add_shortcode('e2pdf-save', array(new Model_E2pdf_Shortcode(), 'e2pdf_save'));
1012 add_shortcode('e2pdf-zapier', array(new Model_E2pdf_Shortcode(), 'e2pdf_zapier'));
1013 add_shortcode('e2pdf-adobesign', array(new Model_E2pdf_Shortcode(), 'e2pdf_adobesign'));
1014 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1015 if (isset($_REQUEST['trans_num']) && class_exists('MeprTransaction') && method_exists('MeprTransaction', 'get_one_by_trans_num')) {
1016 $txn = new MeprTransaction();
1017 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1018 $data = MeprTransaction::get_one_by_trans_num($_REQUEST['trans_num']);
1019 if (method_exists($txn, 'load_data')) {
1020 $txn->load_data($data);
1021 if (false !== strpos($content, '[')) {
1022 $shortcode_tags = array(
1023 'e2pdf-download',
1024 'e2pdf-view',
1025 'e2pdf-save',
1026 'e2pdf-zapier',
1027 'e2pdf-adobesign',
1028 );
1029 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
1030 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1031 if (!empty($tagnames)) {
1032 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
1033 foreach ($shortcodes[0] as $key => $shortcode_value) {
1034 wp_reset_postdata();
1035 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
1036 $atts = shortcode_parse_atts($shortcode[3]);
1037 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
1038 } elseif (isset($atts['id'])) {
1039 $user_id = !empty($txn->user_id) ? $txn->user_id : get_current_user_id();
1040 $template = new Model_E2pdf_Template();
1041 $template->load($atts['id']);
1042 if ($template->get('extension') === 'wordpress' && $template->get('item') == '-3') { // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
1043 if (!isset($atts['dataset'])) {
1044 $atts['dataset'] = $user_id;
1045 $shortcode[3] .= ' dataset="' . $user_id . '"';
1046 }
1047 } else {
1048 if (!isset($atts['user_id'])) {
1049 $atts['user_id'] = $user_id;
1050 $shortcode[3] .= ' user_id="' . $user_id . '"';
1051 }
1052 }
1053 }
1054 if (!isset($atts['apply'])) {
1055 $shortcode[3] .= ' apply="true"';
1056 }
1057 if (!isset($atts['filter'])) {
1058 $shortcode[3] .= ' filter="true"';
1059 }
1060 $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content);
1061 }
1062 }
1063 }
1064 }
1065 }
1066 return $content;
1067 }
1068
1069 // user registration smart tag values filter
1070 public function filter_user_registration_smart_tag_values($values) {
1071 foreach ($values as $key => $value) {
1072 if (is_string($value) && false !== strpos($value, '[e2pdf-')) {
1073 $values[$key] = str_replace('[e2pdf-', '&#91;e2pdf-', $value);
1074 }
1075 }
1076 return $values;
1077 }
1078
1079 // wp mail filter
1080 public function filter_wp_mail($args) {
1081 if (isset($args['message'])) {
1082 if (false !== strpos($args['message'], '[')) {
1083 $shortcode_tags = array(
1084 'e2pdf-download',
1085 'e2pdf-save',
1086 'e2pdf-attachment',
1087 'e2pdf-adobesign',
1088 'e2pdf-zapier',
1089 );
1090 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $args['message'], $matches);
1091 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1092 if (!empty($tagnames)) {
1093 $args['attachments'] = $this->helper->load('convert')->is_string_array($args['attachments']);
1094 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $args['message'], $shortcodes);
1095 foreach ($shortcodes[0] as $key => $shortcode_value) {
1096 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
1097 $atts = shortcode_parse_atts($shortcode[3]);
1098 if (!isset($atts['apply'])) {
1099 $shortcode[3] .= ' apply="true"';
1100 }
1101 if (!isset($atts['filter'])) {
1102 $shortcode[3] .= ' filter="true"';
1103 }
1104 $file = false;
1105 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) {
1106 $file = do_shortcode_tag($shortcode);
1107 if ($file) {
1108 $tmp = false;
1109 if (substr($file, 0, 4) === 'tmp:') {
1110 $file = substr($file, 4);
1111 $tmp = true;
1112 }
1113 if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
1114 if ($tmp) {
1115 $this->helper->add('wordpress_attachments', $file);
1116 }
1117 } else {
1118 $this->helper->add('wordpress_attachments', $file);
1119 }
1120 $args['attachments'][] = $file;
1121 }
1122 $args['message'] = str_replace($shortcode_value, '', $args['message']);
1123 } else {
1124 $args['message'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $args['message']);
1125 }
1126 }
1127 }
1128 }
1129 }
1130 $wp_mail = array(
1131 'to' => $args['to'],
1132 'subject' => $args['subject'],
1133 'message' => $args['message'],
1134 'headers' => $args['headers'],
1135 'attachments' => $args['attachments'],
1136 );
1137 return $wp_mail;
1138 }
1139
1140 // Thrive Theme Builder dynamic shortcode support
1141 public function filter_thrive_theme_template_content($html) {
1142 add_filter('e2pdf_model_shortcode_e2pdf_download_atts', array($this, 'filter_global_post_id'));
1143 add_filter('e2pdf_model_shortcode_e2pdf_view_atts', array($this, 'filter_global_post_id'));
1144 add_filter('e2pdf_model_shortcode_e2pdf_save_atts', array($this, 'filter_global_post_id'));
1145 add_filter('e2pdf_model_shortcode_e2pdf_zapier_atts', array($this, 'filter_global_post_id'));
1146 return $html;
1147 }
1148
1149 // dynamic post id support filter
1150 public function filter_global_post_id($atts) {
1151 if (!isset($atts['dataset']) && isset($atts['id'])) {
1152 $template_id = isset($atts['id']) ? (int) $atts['id'] : 0;
1153 $template = new Model_E2pdf_Template();
1154 if ($template->load($template_id, false)) {
1155 if ($template->get('extension') === 'wordpress') { // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
1156 global $post;
1157 if (isset($post->ID)) {
1158 $atts['dataset'] = (string) $post->ID;
1159 if (!isset($atts['apply'])) {
1160 $atts['apply'] = 'true';
1161 }
1162 if (!isset($atts['filter'])) {
1163 $atts['filter'] = 'true';
1164 }
1165 }
1166 }
1167 }
1168 }
1169 return $atts;
1170 }
1171
1172 // et pb module content filter
1173 public function filter_et_pb_module_content($content, $props, $attrs, $render_slug, $_address, $global_content) {
1174 if (($render_slug == 'et_pb_code' || $render_slug == 'et_pb_text') &&
1175 false !== strpos($content, '[') &&
1176 function_exists('et_core_is_builder_used_on_current_request') &&
1177 !et_core_is_builder_used_on_current_request()
1178 ) {
1179 global $post;
1180 $shortcode_tags = array(
1181 'e2pdf-download',
1182 'e2pdf-save',
1183 'e2pdf-view',
1184 'e2pdf-adobesign',
1185 'e2pdf-zapier',
1186 );
1187 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
1188 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1189 if (!empty($tagnames)) {
1190 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
1191 foreach ($shortcodes[0] as $key => $shortcode_value) {
1192 wp_reset_postdata();
1193 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
1194 $atts = shortcode_parse_atts($shortcode[3]);
1195 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
1196 } else {
1197 if (!isset($atts['dataset']) && isset($atts['id']) && (isset($post->ID))) {
1198 $dataset = $post->ID;
1199 $atts['dataset'] = $dataset;
1200 $shortcode[3] .= ' dataset="' . $dataset . '"';
1201 }
1202 }
1203 if (!isset($atts['apply'])) {
1204 $shortcode[3] .= ' apply="true"';
1205 }
1206
1207 if (!isset($atts['filter'])) {
1208 $shortcode[3] .= ' filter="true"';
1209 }
1210 $new_shortcode = '[' . $shortcode[2] . $shortcode[3] . ']';
1211 $content = str_replace($shortcode_value, $new_shortcode, $content);
1212 }
1213 }
1214 }
1215 return $content;
1216 }
1217
1218 // verify
1219 public function verify() {
1220 if ($this->get('item') && $this->get('cached_post') && (($this->get('item') == get_post_type($this->get('cached_post'))) || ($this->get('item') == '-3' && $this->get('cached_post')))) {
1221 return true;
1222 }
1223 return false;
1224 }
1225
1226 // visual mapper
1227 public function visual_mapper() {
1228
1229 $vc = '';
1230
1231 if ($this->get('item') != '-3') {
1232 $vc .= '<h3 class="e2pdf-plr5">Common</h3>';
1233 $vc .= '<div class="e2pdf-grid">';
1234 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('ID', 'e2pdf-wp key="id"') . '</div>';
1235 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Author', 'e2pdf-wp key="post_author"') . '</div>';
1236 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Author ID', 'e2pdf-wp key="post_author_id"') . '</div>';
1237 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date', 'e2pdf-wp key="post_date"') . '</div>';
1238 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date (GMT)', 'e2pdf-wp key="post_date_gmt"') . '</div>';
1239 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Content', 'e2pdf-wp key="post_content"') . '</div>';
1240 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Title', 'e2pdf-wp key="post_title"') . '</div>';
1241 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Excerpt', 'e2pdf-wp key="post_excerpt"') . '</div>';
1242 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Status', 'e2pdf-wp key="post_status"') . '</div>';
1243 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Comment Status', 'e2pdf-wp key="comment_status"') . '</div>';
1244 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Ping Status', 'e2pdf-wp key="ping_status"') . '</div>';
1245 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Password', 'e2pdf-wp key="post_password"') . '</div>';
1246 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Name', 'e2pdf-wp key="post_name"') . '</div>';
1247 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('To Ping', 'e2pdf-wp key="to_ping"') . '</div>';
1248 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Ping', 'e2pdf-wp key="pinged"') . '</div>';
1249 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Modified Date', 'e2pdf-wp key="post_modified"') . '</div>';
1250 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Modified Date (GMT)', 'e2pdf-wp key="post_modified_gmt"') . '</div>';
1251 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Filtered Content', 'e2pdf-wp key="post_content_filtered"') . '</div>';
1252 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Parent ID', 'e2pdf-wp key="post_parent"') . '</div>';
1253 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('GUID', 'e2pdf-wp key="guid"') . '</div>';
1254 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Menu Order', 'e2pdf-wp key="menu_order"') . '</div>';
1255 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Type', 'e2pdf-wp key="post_type"') . '</div>';
1256 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Mime Type', 'e2pdf-wp key="post_mime_type"') . '</div>';
1257 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Comments Count', 'e2pdf-wp key="comment_count"') . '</div>';
1258 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Filter', 'e2pdf-wp key="filter"') . '</div>';
1259 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Post Thumbnail', 'e2pdf-wp key="get_the_post_thumbnail"') . '</div>';
1260 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Post Thumbnail URL', 'e2pdf-wp key="get_the_post_thumbnail_url"') . '</div>';
1261 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Permalink', 'e2pdf-wp key="get_permalink"') . '</div>';
1262 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Post Permalink', 'e2pdf-wp key="get_post_permalink"') . '</div>';
1263 $vc .= '</div>';
1264
1265 $meta_keys = $this->get_post_meta_keys();
1266 if (!empty($meta_keys)) {
1267 $vc .= '<h3 class="e2pdf-plr5">Meta Keys</h3>';
1268 $vc .= "<div class='e2pdf-grid'>";
1269 foreach ($meta_keys as $meta_key) {
1270 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($meta_key, 'e2pdf-wp key="' . $meta_key . '" meta="true"') . '</div>';
1271 }
1272 $vc .= '</div>';
1273 }
1274
1275 $meta_keys = $this->get_post_taxonomy_keys();
1276 if (!empty($meta_keys)) {
1277 $vc .= '<h3 class="e2pdf-plr5">Taxonomy</h3>';
1278 $vc .= "<div class='e2pdf-grid'>";
1279 foreach ($meta_keys as $meta_key) {
1280 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($meta_key, 'e2pdf-wp key="' . $meta_key . '" terms="true" names="true"') . '</div>';
1281 }
1282 $vc .= '</div>';
1283 }
1284 }
1285
1286 $vc .= '<h3 class="e2pdf-plr5">User</h3>';
1287 $vc .= "<div class='e2pdf-grid'>";
1288 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('ID', 'e2pdf-user key="ID"') . '</div>';
1289 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Description', 'e2pdf-user key="user_description"') . '</div>';
1290 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('First Name', 'e2pdf-user key="user_firstname"') . '</div>';
1291 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Last Name', 'e2pdf-user key="user_lastname"') . '</div>';
1292 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Login', 'e2pdf-user key="user_login"') . '</div>';
1293 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Nicename', 'e2pdf-user key="user_nicename"') . '</div>';
1294 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('E-mail', 'e2pdf-user key="user_email"') . '</div>';
1295 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Url', 'e2pdf-user key="user_url"') . '</div>';
1296 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Registered', 'e2pdf-user key="user_registered"') . '</div>';
1297 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('User Status', 'e2pdf-user key="user_status"') . '</div>';
1298 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('User Level', 'e2pdf-user key="user_level"') . '</div>';
1299 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Display Name', 'e2pdf-user key="display_name"') . '</div>';
1300 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Spam', 'e2pdf-user key="spam"') . '</div>';
1301 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Deleted', 'e2pdf-user key="deleted"') . '</div>';
1302 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Locale', 'e2pdf-user key="locale"') . '</div>';
1303 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Rich Editing', 'e2pdf-user key="rich_editing"') . '</div>';
1304 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Syntax Highlighting', 'e2pdf-user key="syntax_highlighting"') . '</div>';
1305 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Use SSL', 'e2pdf-user key="use_ssl"') . '</div>';
1306 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Roles', 'e2pdf-user key="roles"') . '</div>';
1307 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Avatar', 'e2pdf-user key="get_avatar"') . '</div>';
1308 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Avatar Url', 'e2pdf-user key="get_avatar_url"') . '</div>';
1309 $vc .= '</div>';
1310
1311 $meta_keys = $this->get_user_meta_keys();
1312 if (!empty($meta_keys)) {
1313 $vc .= '<h3 class="e2pdf-plr5">User Meta Keys</h3>';
1314 $vc .= "<div class='e2pdf-grid'>";
1315 foreach ($meta_keys as $meta_key) {
1316 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($meta_key, 'e2pdf-user key="' . $meta_key . '" meta="true"') . '</div>';
1317 }
1318 $vc .= '</div>';
1319 }
1320
1321 if (class_exists('ACF') && function_exists('acf_get_field_groups')) {
1322 $user_groups = acf_get_field_groups(
1323 array(
1324 'user_id' => 'new',
1325 'user_form' => 'all',
1326 )
1327 );
1328 if (!empty($user_groups)) {
1329 $user_groups = array_column($user_groups, 'key');
1330 }
1331 if ($this->get('item') == '-3') {
1332 $groups = acf_get_field_groups(
1333 array(
1334 'user_id' => 'new',
1335 'user_form' => 'all',
1336 )
1337 );
1338 } else {
1339 $groups = acf_get_field_groups(array('post_type' => $this->get('item')));
1340 }
1341 if (!empty($groups)) {
1342 $vc .= "<h3 class='e2pdf-plr5'>ACF</h3>";
1343 foreach ($groups as $group_key => $group) {
1344 $post_id = '';
1345 if (!empty($user_groups)) {
1346 if (in_array($group['key'], $user_groups, false)) {
1347 if ($this->get('item') == '-3') {
1348 $post_id = ' post_id="user_[e2pdf-dataset]"';
1349 } else {
1350 $post_id = ' post_id="user_[e2pdf-userid]"';
1351 }
1352 }
1353 }
1354 $vc .= '<h3 class="e2pdf-plr5">' . $group['title'] . '</h3>';
1355 $vc .= "<div class='e2pdf-grid'>";
1356 foreach (acf_get_fields($group['key']) as $field_key => $field) {
1357 $vc = $this->get_acf_field($vc, $field, $post_id);
1358 }
1359 $vc .= '</div>';
1360 }
1361 }
1362 }
1363 return $vc;
1364 }
1365
1366 // get acf field
1367 public function get_acf_field($vc, $field, $post_id) {
1368 if ($field['type'] == 'repeater' && !empty($field['sub_fields'])) {
1369 $sub_fields = array();
1370 foreach ($field['sub_fields'] as $sub_field_key => $sub_field) {
1371 $sub_fields[] = '[acf field="' . $sub_field['name'] . '"' . $post_id . ']';
1372 $sub_field['label'] = $field['label'] . ' ' . $sub_field['label'];
1373 $sub_field['name'] = $field['name'] . '_0_' . $sub_field['name'];
1374 $vc = $this->get_acf_field($vc, $sub_field, $post_id);
1375 }
1376 if (!empty($sub_fields)) {
1377 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($field['label'] . ' Iteration', 'e2pdf-acf-repeater field="' . $field['name'] . '"' . $post_id . ']' . implode(' ', $sub_fields) . "\r\n" . '[/e2pdf-acf-repeater') . '</div>';
1378 }
1379 } elseif ($field['type'] == 'group' && !empty($field['sub_fields'])) {
1380 $sub_fields = array();
1381 foreach ($field['sub_fields'] as $sub_field_key => $sub_field) {
1382 $sub_field['label'] = $field['label'] . ' ' . $sub_field['label'];
1383 $sub_field['name'] = $field['name'] . '_' . $sub_field['name'];
1384 $vc = $this->get_acf_field($vc, $sub_field, $post_id);
1385 }
1386 } else {
1387 if ($field['name']) {
1388 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($field['label'], 'acf field="' . $field['name'] . '"' . $post_id) . '</div>';
1389 }
1390 }
1391 return $vc;
1392 }
1393
1394 // get post meta keys
1395 public function get_post_meta_keys() {
1396 global $wpdb;
1397 $meta_keys = array();
1398 if ($this->get('item')) {
1399 $condition = array(
1400 'p.post_type' => array(
1401 'condition' => '=',
1402 'value' => $this->get('item'),
1403 'type' => '%s',
1404 ),
1405 );
1406 $order_condition = array(
1407 'orderby' => 'meta_key',
1408 'order' => 'desc',
1409 );
1410 $where = $this->helper->load('db')->prepare_where($condition);
1411 $orderby = $this->helper->load('db')->prepare_orderby($order_condition);
1412 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
1413 $meta_keys = $wpdb->get_col($wpdb->prepare('SELECT DISTINCT `meta_key` FROM `' . $wpdb->postmeta . '` `pm` LEFT JOIN ' . $wpdb->posts . ' `p` ON (`p`.`ID` = `pm`.`post_ID`) ' . $where['sql'] . $orderby . '', $where['filter']));
1414 }
1415 return $meta_keys;
1416 }
1417
1418 // get user meta keys
1419 public function get_user_meta_keys() {
1420 global $wpdb;
1421 $meta_keys = array();
1422 if ($this->get('item')) {
1423 $order_condition = array(
1424 'orderby' => 'meta_key',
1425 'order' => 'desc',
1426 );
1427 $orderby = $this->helper->load('db')->prepare_orderby($order_condition);
1428 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
1429 $meta_keys = $wpdb->get_col($wpdb->prepare('SELECT DISTINCT `meta_key` FROM `' . $wpdb->usermeta . '` ' . $orderby . ''));
1430 }
1431 return $meta_keys;
1432 }
1433
1434 // get post taxonomy keys
1435 public function get_post_taxonomy_keys() {
1436 global $wpdb;
1437 $meta_keys = array();
1438 if ($this->get('item')) {
1439 $order_condition = array(
1440 'orderby' => 'taxonomy',
1441 'order' => 'desc',
1442 );
1443 $orderby = $this->helper->load('db')->prepare_orderby($order_condition);
1444 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
1445 $meta_keys = $wpdb->get_col($wpdb->prepare('SELECT DISTINCT `taxonomy` FROM `' . $wpdb->term_taxonomy . '` `t` ' . $orderby . ''));
1446 }
1447 return $meta_keys;
1448 }
1449
1450 // get wm element
1451 public function get_vm_element($name, $id) {
1452 $element = '<div>';
1453 $element .= '<label>' . $name . ':</label>';
1454 $element .= '<input type="text" name=\'[' . $id . ']\' value=\'[' . $id . ']\' class="e2pdf-w100">';
1455 $element .= '</div>';
1456 return $element;
1457 }
1458
1459 // page edit hook
1460 public function hook_wordpress_page_edit() {
1461 // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
1462 $items = $this->helper->load('hooks')->get_items('wordpress', 'hook_wordpress_page_edit');
1463 if (!empty($items)) {
1464 add_meta_box(
1465 'e2pdf',
1466 apply_filters('e2pdf_hook_section_title', __('E2Pdf Actions', 'e2pdf'), 'hook_wordpress_page_edit'),
1467 array($this, 'hook_wordpress_page_edit_callback'),
1468 $items,
1469 'side',
1470 'default'
1471 );
1472 }
1473 }
1474
1475 // page edit callback hook
1476 public function hook_wordpress_page_edit_callback($post) {
1477 if (!empty($post->post_type)) {
1478 // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
1479 $hooks = $this->helper->load('hooks')->get('wordpress', 'hook_wordpress_page_edit', $post->post_type);
1480 if (!empty($hooks)) {
1481 foreach ($hooks as $hook) {
1482 if ($this->helper->load('hooks')->process_hook(
1483 $hook,
1484 [
1485 'dataset' => $post->ID,
1486 ],
1487 'hook_wordpress_page_edit'
1488 )
1489 ) {
1490 $action = apply_filters(
1491 'e2pdf_hook_action_button',
1492 array(
1493 'html' => '<p><a class="e2pdf-download-hook" target="_blank" title="%2$s" href="%1$s"><span class="dashicons dashicons-pdf"></span> %2$s</a></p>',
1494 'url' => $this->helper->get_url(
1495 array(
1496 'page' => 'e2pdf',
1497 'action' => 'export',
1498 'id' => $hook,
1499 'dataset' => $post->ID,
1500 ), 'admin.php?'
1501 ),
1502 'title' => 'PDF #' . $hook,
1503 ), 'hook_wordpress_page_edit', $hook, $post->ID
1504 );
1505 if (!empty($action)) {
1506 echo sprintf(
1507 $action['html'], $action['url'], $action['title']
1508 );
1509 }
1510 }
1511 }
1512 }
1513 }
1514 }
1515
1516 // row actions hook
1517 public function hook_wordpress_row_actions($actions, $post) {
1518 if ($post && is_a($post, 'WP_User')) {
1519 if (!empty($post->ID)) {
1520 // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
1521 $hooks = $this->helper->load('hooks')->get('wordpress', 'hook_wordpress_row_actions', '-3');
1522 foreach ($hooks as $hook) {
1523 if ($this->helper->load('hooks')->process_hook(
1524 $hook,
1525 [
1526 'dataset' => $post->ID,
1527 ],
1528 'hook_wordpress_row_actions'
1529 )
1530 ) {
1531 $action = apply_filters(
1532 'e2pdf_hook_action_button',
1533 array(
1534 'html' => '<a class="e2pdf-download-hook" target="_blank" href="%s">%s</a>',
1535 'url' => $this->helper->get_url(
1536 array(
1537 'page' => 'e2pdf',
1538 'action' => 'export',
1539 'id' => $hook,
1540 'dataset' => $post->ID,
1541 ), 'admin.php?'
1542 ),
1543 'title' => 'PDF #' . $hook,
1544 ), 'hook_wordpress_row_actions', $hook, $post->ID
1545 );
1546 if (!empty($action)) {
1547 $actions['e2pdf_' . $hook] = sprintf(
1548 $action['html'], $action['url'], $action['title']
1549 );
1550 }
1551 }
1552 }
1553 }
1554 } else {
1555 if (!empty($post->post_type) && !empty($post->ID)) {
1556 // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
1557 $hooks = $this->helper->load('hooks')->get('wordpress', 'hook_wordpress_row_actions', $post->post_type);
1558 foreach ($hooks as $hook) {
1559 if ($this->helper->load('hooks')->process_hook(
1560 $hook,
1561 [
1562 'dataset' => $post->ID,
1563 ],
1564 'hook_wordpress_row_actions'
1565 )
1566 ) {
1567 $action = apply_filters(
1568 'e2pdf_hook_action_button',
1569 array(
1570 'html' => '<a class="e2pdf-download-hook" target="_blank" href="%s">%s</a>',
1571 'url' => $this->helper->get_url(
1572 array(
1573 'page' => 'e2pdf',
1574 'action' => 'export',
1575 'id' => $hook,
1576 'dataset' => $post->ID,
1577 ), 'admin.php?'
1578 ),
1579 'title' => 'PDF #' . $hook,
1580 ), 'hook_wordpress_row_actions', $hook, $post->ID
1581 );
1582 if (!empty($action)) {
1583 $actions['e2pdf_' . $hook] = sprintf(
1584 $action['html'], $action['url'], $action['title']
1585 );
1586 }
1587 }
1588 }
1589 }
1590 }
1591 return $actions;
1592 }
1593 }
1594