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 / helper / e2pdf-hooks.php

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

93 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * File: /helper/e2pdf-hooks.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 Helper_E2pdf_Hooks {
15
16 private $helper;
17
18 // construct
19 public function __construct() {
20 $this->helper = Helper_E2pdf_Helper::instance();
21 }
22
23 // get
24 public function get($extension = '', $hook = '', $item = '') {
25 global $wpdb;
26 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
27 $hooks = $wpdb->get_col($wpdb->prepare('SELECT `ID` FROM `' . (new Model_E2pdf_Template())->get_table() . '` WHERE trash = %s AND activated = %s AND extension = %s AND item = %s AND FIND_IN_SET(%s, hooks)', '0', '1', $extension, $item, $hook));
28 return $hooks;
29 }
30
31 // get items
32 public function get_items($extension = '', $hook = '') {
33 global $wpdb;
34 if ($hook == 'hook_wordpress_metabox') {
35 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
36 $hooks = $wpdb->get_col($wpdb->prepare('SELECT DISTINCT `item` FROM `' . (new Model_E2pdf_Template())->get_table() . '` WHERE trash = %s AND activated = %s AND extension = %s AND item != %s AND item != %s AND FIND_IN_SET(%s, hooks)', '0', '1', $extension, '', '-3', $hook));
37 } else {
38 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
39 $hooks = $wpdb->get_col($wpdb->prepare('SELECT DISTINCT `item` FROM `' . (new Model_E2pdf_Template())->get_table() . '` WHERE trash = %s AND activated = %s AND extension = %s AND item != %s AND FIND_IN_SET(%s, hooks)', '0', '1', $extension, '', $hook));
40 }
41 return $hooks;
42 }
43
44 // proces hook
45 public function process_hook($template_id = 0, $atts = [], $hook = '') {
46 global $wpdb;
47
48 if ($wpdb->get_var($wpdb->prepare('SELECT 1 FROM `' . $wpdb->prefix . 'e2pdf_templates` WHERE ID = %d AND (actions LIKE %s OR actions LIKE %s) LIMIT 1', $template_id, '%' . $hook . '%', '%hooks%'))) {
49
50 $dataset = isset($atts['dataset']) ? $atts['dataset'] : false;
51 $dataset2 = isset($atts['dataset2']) ? $atts['dataset2'] : false;
52 $wc_order_id = isset($atts['wc_order_id']) ? $atts['wc_order_id'] : false;
53 $wc_product_item_id = isset($atts['wc_product_item_id']) ? $atts['wc_product_item_id'] : false;
54
55 $template = new Model_E2pdf_Template();
56 if (!$template->load($template_id, false)) {
57 return true;
58 }
59
60 $template->extension()->patch('template_id', $template_id);
61 $template->extension()->patch('dataset', $dataset);
62 $template->extension()->patch('dataset2', $dataset2);
63 $template->extension()->patch('wc_order_id', $wc_order_id);
64 $template->extension()->patch('wc_product_item_id', $wc_product_item_id);
65 if (!($template->get('extension') === 'wordpress' && $template->get('item') === '-3')) {
66 $template->extension()->patch('user_id', get_current_user_id());
67 }
68 $template->extension()->patch('storing_engine', $template->extension()->get_storing_engine());
69
70 if ($template->get('actions')) {
71 $model_e2pdf_action = new Model_E2pdf_Action();
72 $model_e2pdf_action->load($template->extension());
73 if (!is_array($template->get('actions'))) {
74 $template->set('actions', $this->helper->load('convert')->unserialize($template->get('actions')));
75 }
76 $actions = $model_e2pdf_action->process_global_actions($template->get('actions'));
77 foreach ($actions as $action) {
78 if (isset($action['action']) && $action['action'] == 'disable_hooks' && isset($action['success'])) {
79 return false;
80 } elseif (isset($action['action']) && $action['action'] == 'enable_hooks' && !isset($action['success'])) {
81 return false;
82 } elseif (isset($action['action']) && $action['action'] == 'disable_' . $hook && isset($action['success'])) {
83 return false;
84 } elseif (isset($action['action']) && $action['action'] == 'enable_' . $hook && !isset($action['success'])) {
85 return false;
86 }
87 }
88 }
89 }
90 return true;
91 }
92 }
93