PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.49
E2Pdf – Export Pdf Tool for WordPress v1.32.49
1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 1.08.00 1.08.06 All 72 releases
← All changes | classes/model/e2pdf-shortcode.php +6237 -1182 1.08.061.32.49 View file →
@@ -1,14 +1,12 @@
1 1 <?php
2 2
3 3 /**
4 - * E2pdf Shortcode Model
5 - *
6 - * @copyright Copyright 2017 https://e2pdf.com
7 - * @license GPL v2
8 - * @version 1
9 - * @link https://e2pdf.com
10 - * @since 0.00.01
4 + * File: /model/e2pdf-shortcode.php
5 + *
6 + * @package E2Pdf
7 + * @license GPLv3
8 + * @link https://e2pdf.com
11 9 */
12 10 if (!defined('ABSPATH')) {
13 11 die('Access denied.');
14 12 }
@@ -14,300 +12,370 @@
14 12 }
15 13
16 14 class Model_E2pdf_Shortcode extends Model_E2pdf_Model {
17 15
18 - function __construct() {
19 - parent::__construct();
20 - }
16 + // e2pdf-attachment
17 + public function e2pdf_attachment($atts = []) {
21 18
22 - /**
23 - * [e2pdf-attachment] shortcode
24 - *
25 - * @param array $atts - Attributes
26 - */
27 - function e2pdf_attachment($atts = array()) {
28 -
29 19 $response = '';
30 20
31 - $template_id = isset($atts['id']) ? (int) $atts['id'] : 0;
32 - $pdf = isset($atts['pdf']) ? $atts['pdf'] : false;
33 - $apply = isset($atts['apply']) ? true : false;
34 - $dataset = isset($atts['dataset']) ? $atts['dataset'] : false;
35 - $uid = isset($atts['uid']) ? $atts['uid'] : false;
21 + $atts = apply_filters('e2pdf_model_shortcode_e2pdf_attachment_atts', $atts);
22 + $attributes = (new Helper_E2pdf_Atts())->load($atts);
36 23
37 - $args = array();
38 - foreach ($atts as $att_key => $att_value) {
39 - if (substr($att_key, 0, 3) === "arg") {
40 - $args[$att_key] = $att_value;
24 + if ($attributes->get('pdf') || $attributes->get('attachment_id') || $attributes->get('file_id')) {
25 + $pdf = $attributes->get('pdf');
26 + $downloadable = false;
27 + if ($attributes->get('file_id')) {
28 + $pdf = (new Model_E2pdf_Gdrive())->exists($attributes->get('file_id'));
29 + if ($pdf) {
30 + $downloadable = $attributes->get('apply') && $pdf;
31 + }
32 + } else {
33 + if ($attributes->get('attachment_id')) {
34 + $pdf = get_attached_file($attributes->get('attachment_id'));
35 + } else {
36 + $pdf = $this->helper->load('convert')->to_file_dir($pdf);
37 + }
38 + if (strpos($pdf, '/') !== 0 && !preg_match('/^[A-Za-z]:/', $pdf)) {
39 + $pdf = ABSPATH . $pdf;
40 + }
41 + $downloadable = $attributes->get('apply') && !$this->helper->load('filter')->is_stream($pdf) && file_exists($pdf) && $this->helper->load('filter')->is_downloadable($pdf);
41 42 }
42 - }
43 43
44 - if ($uid) {
45 - $entry = new Model_E2pdf_Entry();
46 - if ($entry->load_by_uid($uid)) {
47 - $uid_params = $entry->get('entry');
48 - $template_id = isset($uid_params['template_id']) ? (int) $uid_params['template_id'] : 0;
49 - $dataset = isset($uid_params['dataset']) ? $uid_params['dataset'] : false;
50 - $pdf = isset($uid_params['pdf']) ? $uid_params['pdf'] : false;
51 - } else {
44 + if (!$downloadable) {
52 45 return $response;
53 46 }
54 - }
55 47
56 - if ($pdf) {
57 - if ($apply && !$this->helper->load('filter')->is_stream($pdf) && file_exists($pdf)) {
58 - return $pdf;
59 - } else {
60 - return $response;
48 + $pdf = apply_filters('e2pdf_model_e2pdf_shortcode_attachment_path', $pdf, $atts);
49 + if (trim($attributes->get('name', ''))) {
50 + $name = $attributes->get('name');
51 + $ext = pathinfo($pdf, PATHINFO_EXTENSION);
52 + $tmp_dir = $this->helper->get('tmp_dir') . 'e2pdf' . md5($pdf . $name) . '/';
53 + $this->helper->create_dir($tmp_dir);
54 + $filename = $this->helper->load('convert')->to_file_name($name . '.' . ($ext == 'jpg' ? 'jpg' : 'pdf'));
55 + $filepath = $tmp_dir . $filename;
56 + if (copy($pdf, $filepath)) {
57 + $pdf = 'tmp:' . $filepath;
58 + }
61 59 }
60 + return $pdf;
62 61 }
63 62
64 - if (!$apply || !$dataset || !$template_id) {
63 + if (!$attributes->get('apply') || !$attributes->get('id') || (!$attributes->get('dataset') && !$attributes->get('dataset2'))) {
65 64 return $response;
66 65 }
67 66
68 67 $template = new Model_E2pdf_Template();
69 - if ($template->load($template_id)) {
70 68
71 - $uid_params = array();
72 - $uid_params['template_id'] = $template_id;
73 - $uid_params['dataset'] = $dataset;
69 + if (!$template->load($attributes->get('id'))) {
70 + return $response;
71 + }
74 72
75 - $template->extension()->set('dataset', $dataset);
73 + $entry = new Model_E2pdf_Entry();
76 74
77 - $options = array();
78 - $options = apply_filters('e2pdf_model_shortcode_extension_options', $options, $template);
79 - $options = apply_filters('e2pdf_model_shortcode_e2pdf_attachment_extension_options', $options, $template);
75 + $template->extension()->patch('template_id', $attributes->get('id'), $entry);
76 + $template->extension()->patch('dataset', $attributes->get('dataset'), $entry);
77 + $template->extension()->patch('dataset2', $attributes->get('dataset2'), $entry);
78 + $template->extension()->patch('wc_order_id', $attributes->get('wc_order_id'), $entry);
79 + $template->extension()->patch('wc_product_item_id', $attributes->get('wc_product_item_id'), $entry);
80 + // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
81 + if (!($template->get('extension') === 'wordpress' && $template->get('item') === '-3')) {
82 + $template->extension()->patch('user_id', $attributes->get('user_id'), $entry);
83 + }
84 + $template->extension()->patch('args', $attributes->get('arguments'), $entry);
85 + $template->extension()->patch('storing_engine', $template->extension()->get_storing_engine(), $entry);
80 86
81 - foreach ($options as $option_key => $option_value) {
82 - $template->extension()->set($option_key, $option_value);
83 - }
87 + $options = apply_filters('e2pdf_model_shortcode_extension_options', [], $template);
88 + $options = apply_filters('e2pdf_model_shortcode_e2pdf_attachment_extension_options', $options, $template);
89 + foreach ($options as $option_key => $option_value) {
90 + $template->extension()->set($option_key, $option_value);
91 + }
84 92
85 - if ($template->extension()->verify()) {
93 + if ($template->extension()->verify() && $this->process_shortcode('e2pdf_attachment', $template, $attributes)) {
86 94
87 - if (array_key_exists('inline', $atts)) {
88 - $inline = $atts['inline'] == 'true' ? 1 : 0;
89 - $uid_params['inline'] = $inline;
90 - }
95 + $template->patch('inline', $attributes->get('inline'), $entry, $attributes->get('filter'));
96 + $template->patch('flatten', $attributes->get('flatten'), $entry, $attributes->get('filter'));
97 + $template->patch('format', $attributes->get('format'), $entry, $attributes->get('filter'));
98 + $template->patch('password', $attributes->get('password'), $entry, $attributes->get('filter'));
99 + $template->patch('dpdf', $attributes->get('dpdf'), $entry, $attributes->get('filter'));
100 + $template->patch('name', $attributes->get('name'), $entry, $attributes->get('filter'));
101 + $template->patch('meta_title', $attributes->get('meta_title'), $entry, $attributes->get('filter'));
102 + $template->patch('meta_subject', $attributes->get('meta_subject'), $entry, $attributes->get('filter'));
103 + $template->patch('meta_author', $attributes->get('meta_author'), $entry, $attributes->get('filter'));
104 + $template->patch('meta_keywords', $attributes->get('meta_keywords'), $entry, $attributes->get('filter'));
91 105
92 - if (array_key_exists('flatten', $atts)) {
93 - $flatten = (int) $atts['flatten'];
94 - $uid_params['flatten'] = $flatten;
95 - $template->set('flatten', $flatten);
96 - }
106 + $template->extension()->set('entry', $entry);
107 + $template->fill();
108 + $request = $template->render();
97 109
98 - if (array_key_exists('format', $atts)) {
99 - $format = $atts['format'];
100 - $uid_params['format'] = $format;
101 - $template->set('format', $format);
102 - }
110 + if (!isset($request['error'])) {
111 + $attach = $attributes->get('attach') === 'always' ? '_' . bin2hex(random_bytes(8)) : '';
112 + $tmp_dir = $this->helper->get('tmp_dir') . 'e2pdf' . md5($entry->get('uid') . $attach) . '/';
113 + $this->helper->create_dir($tmp_dir);
103 114
104 - if (array_key_exists('password', $atts)) {
105 - if (!array_key_exists('filter', $atts)) {
106 - $password = $template->extension()->render($atts['password'], 'value');
107 - } else {
108 - $password = $atts['password'];
109 - }
110 - $uid_params['password'] = $password;
111 - $template->set('password', $password);
112 - } else {
113 - $template->set('password', $template->extension()->render($template->get('password'), 'value'));
114 - }
115 + $filename = $template->get('name') . '.' . $template->get('format');
116 + $filename = $this->helper->load('convert')->to_file_name($filename);
117 + $filepath = $tmp_dir . $filename;
115 118
116 - if (array_key_exists('meta_title', $atts)) {
117 - if (!array_key_exists('filter', $atts)) {
118 - $meta_title = $template->extension()->render($atts['meta_title'], 'value');
119 - } else {
120 - $meta_title = $atts['meta_title'];
121 - }
122 - $uid_params['meta_title'] = $meta_title;
123 - $template->set('meta_title', $meta_title);
124 - } else {
125 - $template->set('meta_title', $template->extension()->render($template->get('meta_title'), 'value'));
126 - }
127 -
128 - if (array_key_exists('meta_subject', $atts)) {
129 - if (!array_key_exists('filter', $atts)) {
130 - $meta_subject = $template->extension()->render($atts['meta_subject'], 'value');
131 - } else {
132 - $meta_subject = $atts['meta_subject'];
133 - }
134 - $uid_params['meta_subject'] = $meta_subject;
135 - $template->set('meta_subject', $meta_subject);
136 - } else {
137 - $template->set('meta_subject', $template->extension()->render($template->get('meta_subject'), 'value'));
138 - }
139 -
140 - if (array_key_exists('meta_author', $atts)) {
141 - if (!array_key_exists('filter', $atts)) {
142 - $meta_author = $template->extension()->render($atts['meta_author'], 'value');
143 - } else {
144 - $meta_author = $atts['meta_author'];
145 - }
146 - $uid_params['meta_author'] = $meta_author;
147 - $template->set('meta_author', $meta_author);
148 - } else {
149 - $template->set('meta_author', $template->extension()->render($template->get('meta_author'), 'value'));
150 - }
151 -
152 - if (array_key_exists('meta_keywords', $atts)) {
153 - if (!array_key_exists('filter', $atts)) {
154 - $meta_keywords = $template->extension()->render($atts['meta_keywords'], 'value');
155 - } else {
156 - $meta_keywords = $atts['meta_keywords'];
157 - }
158 - $uid_params['meta_keywords'] = $meta_keywords;
159 - $template->set('meta_keywords', $meta_keywords);
160 - } else {
161 - $template->set('meta_keywords', $template->extension()->render($template->get('meta_keywords'), 'value'));
162 - }
163 -
164 - if (array_key_exists('name', $atts)) {
165 - if (!array_key_exists('filter', $atts)) {
166 - $name = $template->extension()->render($atts['name'], 'value');
167 - } else {
168 - $name = $atts['name'];
169 - }
170 - $uid_params['name'] = $name;
171 - $template->set('name', $name);
172 - } else {
173 - $template->set('name', $template->extension()->render($template->get('name'), 'value'));
174 - }
175 -
176 - if (array_key_exists('user_id', $atts)) {
177 - $uid_params['user_id'] = (int) $atts['user_id'];
178 - } else {
179 - $uid_params['user_id'] = get_current_user_id();
180 - }
181 -
182 - $uid_params['args'] = $args;
183 -
184 - $entry = new Model_E2pdf_Entry();
185 - $entry->set('entry', $uid_params);
186 - if (!$entry->load_by_uid($entry->get('uid'))) {
187 - $entry->save();
188 - }
189 -
190 - $template->fill($dataset, $entry->get('uid'));
191 - $request = $template->render();
192 -
193 - if (!isset($request['error']) && $entry->get('ID')) {
194 - $tmp_dir = $this->helper->get('tmp_dir') . 'e2pdf' . md5($entry->get('uid')) . '/';
195 -
196 - $this->helper->create_dir($tmp_dir);
197 -
198 - if ($template->get('name')) {
199 - $name = $template->get('name');
200 - } else {
201 - $name = $template->extension()->render($template->get_filename(), 'value');
202 - }
203 -
204 - $file_name = $name . '.pdf';
205 - $file_name = $this->helper->load('convert')->to_file_name($file_name);
206 - $file_path = $tmp_dir . $file_name;
207 - file_put_contents($file_path, base64_decode($request['file']));
208 -
209 - if (file_exists($file_path)) {
119 + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
120 + file_put_contents($filepath, $request['file'], LOCK_EX);
121 + if (file_exists($filepath)) {
122 + if ($entry->load_by_uid()) {
210 123 $entry->set('pdf_num', $entry->get('pdf_num') + 1);
211 124 $entry->save();
212 - return $file_path;
213 125 }
126 + $filepath = apply_filters('e2pdf_model_e2pdf_shortcode_attachment_path', $filepath, $atts);
127 + return $filepath;
214 128 }
215 129 }
216 130 }
131 +
217 132 return $response;
218 133 }
219 134
220 - /**
221 - * [e2pdf-download] shortcode
222 - *
223 - * @param array $atts - Attributes
224 - */
225 - function e2pdf_download($atts = array()) {
135 + // e2pdf-download
136 + public function e2pdf_download($atts = []) {
226 137
138 + if (function_exists('vc_is_page_editable') && vc_is_page_editable()) {
139 + return '[e2pdf-download]';
140 + }
141 +
227 142 $response = '';
143 + $iframe_download = false;
228 144
229 - $template_id = isset($atts['id']) ? (int) $atts['id'] : 0;
230 - $dataset = isset($atts['dataset']) ? $atts['dataset'] : false;
231 - $uid = isset($atts['uid']) ? $atts['uid'] : false;
232 - $output = isset($atts['output']) ? $atts['output'] : false;
233 - $pdf = isset($atts['pdf']) ? $atts['pdf'] : false;
145 + $atts = apply_filters('e2pdf_model_shortcode_e2pdf_download_atts', $atts);
146 + $attributes = (new Helper_E2pdf_Atts())->load($atts);
234 147
235 - $args = array();
236 - foreach ($atts as $att_key => $att_value) {
237 - if (substr($att_key, 0, 3) === "arg") {
238 - $args[$att_key] = $att_value;
148 + $target = $attributes->get('target', '_blank');
149 +
150 + /**
151 + * WPBakery Page Builder Grid Item
152 + * [e2pdf-download id="1" dataset="{{ post_data:ID }}"]
153 + */
154 + if (strpos($attributes->get('dataset'), 'post_data:ID') !== false) {
155 + $response .= '[e2pdf-download ';
156 + foreach ($atts as $key => $value) {
157 + $response .= sanitize_key($key) . '="' . esc_attr($value) . '" ';
239 158 }
159 + $response .= ']';
160 + return $response;
240 161 }
241 162
242 - if ($uid) {
163 + if ($attributes->get('pdf') || $attributes->get('attachment_id') || $attributes->get('file_id')) {
164 + $pdf = $attributes->get('pdf');
165 + $downloadable = false;
166 + if ($attributes->get('file_id')) {
167 + $pdf = (new Model_E2pdf_Gdrive())->exists($attributes->get('file_id'));
168 + if ($pdf) {
169 + $downloadable = true;
170 + }
171 + } else {
172 + if ($attributes->get('attachment_id')) {
173 + $pdf = get_attached_file($attributes->get('attachment_id'));
174 + } else {
175 + $pdf = $this->helper->load('convert')->to_file_dir($pdf);
176 + }
177 + if (strpos($pdf, '/') !== 0 && !preg_match('/^[A-Za-z]:/', $pdf)) {
178 + $pdf = ABSPATH . $pdf;
179 + }
180 + $downloadable = !$this->helper->load('filter')->is_stream($pdf) && file_exists($pdf) && $this->helper->load('filter')->is_downloadable($pdf);
181 + }
182 +
183 + if (!$downloadable) {
184 + return $response;
185 + }
243 186 $entry = new Model_E2pdf_Entry();
244 - if ($entry->load_by_uid($uid)) {
245 - $uid_params = $entry->get('entry');
246 - $template_id = isset($uid_params['template_id']) ? (int) $uid_params['template_id'] : 0;
247 - $dataset = isset($uid_params['dataset']) ? $uid_params['dataset'] : false;
248 - $pdf = isset($uid_params['pdf']) ? $uid_params['pdf'] : false;
187 + if ($attributes->get('attachment_id')) {
188 + $entry->set_data('attachment_id', $attributes->get('attachment_id'));
189 + } elseif ($attributes->get('file_id')) {
190 + $entry->set_data('file_id', $attributes->get('file_id'));
249 191 } else {
250 - return $response;
192 + $entry->set_data('pdf', $pdf);
251 193 }
252 - }
253 194
254 - if ($pdf) {
255 - if (!$this->helper->load('filter')->is_stream($pdf) && file_exists($pdf)) {
195 + $classes = array_merge($attributes->get('class'), ['e2pdf-download', 'e2pdf-format-pdf']);
256 196
257 - $uid_params = array();
258 - $uid_params['pdf'] = $pdf;
197 + $inline = '0';
198 + if ($attributes->get('inline') !== false) {
199 + $inline = $attributes->get('inline');
200 + $entry->set_data('inline', $inline);
201 + }
202 + if ($inline) {
203 + $classes[] = 'e2pdf-inline';
204 + }
259 205
260 - if (array_key_exists('class', $atts)) {
261 - $classes = explode(" ", $atts['class']);
262 - } else {
263 - $classes = array();
206 + $auto = $attributes->get('auto', '0');
207 + if ($auto) {
208 + $classes[] = 'e2pdf-auto';
209 + if ($attributes->get('iframe_download')) {
210 + $classes[] = 'e2pdf-iframe-download';
211 + $iframe_download = true;
264 212 }
265 - $classes[] = 'e2pdf-download';
213 + }
266 214
267 - if (array_key_exists('auto', $atts)) {
268 - $auto = $atts['auto'] == 'true' ? 1 : 0;
269 - if ($auto) {
270 - $classes[] = 'e2pdf-auto';
271 - }
272 - }
215 + if ($attributes->get('name') !== false) {
216 + $entry->set_data('name', $attributes->get('name'));
217 + }
273 218
274 - if (array_key_exists('inline', $atts)) {
275 - $inline = $atts['inline'] == 'true' ? 1 : 0;
276 - $uid_params['inline'] = $inline;
219 + $button_title = apply_filters('e2pdf_model_shortcode_e2pdf_download_button_title', $attributes->button_title(), $atts);
220 + if ($attributes->get('output') === 'button_title') {
221 + return $button_title;
222 + }
223 +
224 + if ($attributes->get('local')) {
225 + if ($attributes->get('file_id')) {
277 226 if ($inline) {
278 - $classes[] = 'e2pdf-inline';
227 + $url = 'https://drive.google.com/file/d/' . $entry->get_data('file_id') . '/view';
228 + } else {
229 + $url = 'https://drive.google.com/uc?id=' . $entry->get_data('file_id') . '&export=download';
279 230 }
231 + } else {
232 + $url = $attributes->get('attachment_id') ? wp_get_attachment_url($entry->get_data('attachment_id')) : $this->helper->get_frontend_local_pdf_url($pdf);
280 233 }
234 + switch ($attributes->get('output')) {
235 + case 'url':
236 + case 'url_raw':
237 + case 'url_encode':
238 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_download_output_url', $url, $atts);
239 + if ($attributes->get('output') === 'url') {
240 + $response = esc_url($url);
241 + } elseif ($attributes->get('output') === 'url_raw') {
242 + $response = esc_url_raw($url);
243 + } elseif ($attributes->get('output') === 'url_encode') {
244 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
245 + $response = urlencode(esc_url_raw($url));
246 + }
247 + break;
248 + default:
249 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_download_pdf_url', $url, $atts);
250 + $file_download = '';
251 + if ($attributes->get('print') && $this->helper->load('server')->isPrintingSupported()) {
252 + $classes[] = 'e2pdf-print-pdf';
253 + $url = add_query_arg(['v' => $this->helper->get('version')], $url);
254 + } elseif ($attributes->get('view')) {
255 + $iframe_download = false;
256 + $viewer_atts = array_merge(
257 + array_diff_key($atts, ['class' => '']),
258 + [
259 + 'class' => isset($atts['view_class']) ? $atts['view_class'] : '',
260 + 'file' => $url,
261 + 'output' => 'url_raw',
262 + ]
263 + );
264 + $url = $this->e2pdf_view($viewer_atts);
265 + } elseif (get_option('e2pdf_download_loader', '0') == '1' && $this->helper->load('server')->isLoaderSupported()) {
266 + if ($inline) {
267 + $target = '_blank';
268 + } else {
269 + $download_name = $entry->get_data('name') ? $entry->get_data('name') : basename($pdf, '.' . pathinfo($pdf, PATHINFO_EXTENSION));
270 + $download_name = apply_filters('e2pdf_controller_frontend_e2pdf_download_name', $download_name, $entry->get('uid'), $entry->get('entry'));
271 + $file_download = 'download="' . esc_attr($download_name . '.' . (pathinfo($pdf, PATHINFO_EXTENSION))) . '"';
272 + $classes[] = 'e2pdf-download-loader';
273 + if ($this->helper->load('server')->isIOS() && $this->helper->load('server')->isSafari()) {
274 + $classes[] = 'e2pdf-ios-safari-loader';
275 + }
276 + }
277 + }
281 278
282 - if (array_key_exists('name', $atts)) {
283 - $name = $atts['name'];
284 - $uid_params['name'] = $name;
285 - }
279 + $lid = uniqid('', true);
280 + $response = '<a lid="' . esc_attr($lid) . '" rel="nofollow" ' . $file_download . ' id="e2pdf-download" class="' . esc_attr(implode(' ', $classes)) . '" style="' . esc_attr(implode(';', $attributes->get('style'))) . '" target="' . esc_attr($target) . '" href="' . esc_url($url) . '">' . $button_title . '</a>';
281 + if ($iframe_download) {
282 + $url = add_query_arg(['v' => $this->helper->get('version')], $url);
286 283
287 - if (array_key_exists('button-title', $atts)) {
288 - $button_title = $atts['button-title'];
289 - } else {
290 - $button_title = __('Download', 'e2pdf');
284 + $src = $attributes->get('preload') ? 'preload' : 'src';
285 + $preload_class = $attributes->get('preload') ? 'e2pdf-preload' : '';
286 +
287 + if ($inline || (get_option('e2pdf_download_loader', '0') == '1' && $this->helper->load('server')->isLoaderSupported())) {
288 + $response .= '<img class="' . esc_attr($preload_class) . '" onload="e2pdfViewer.autoDownload(\'' . esc_attr($lid) . '\');" style="display:none" ' . $src . '="' . $attributes->get('iframe_loader') . '">';
289 + } else {
290 + $response .= '<iframe class="' . esc_attr($preload_class) . '" style="width:0;height:0;border-width:0;border:none;" ' . $src . '="' . esc_url($url) . '"></iframe>';
291 + }
292 + }
293 + break;
291 294 }
292 -
293 - $entry = new Model_E2pdf_Entry();
294 - $entry->set('entry', $uid_params);
295 - if (!$entry->load_by_uid($entry->get('uid'))) {
295 + } else {
296 + if (!$entry->load_by_uid()) {
296 297 $entry->save();
297 298 }
298 -
299 299 if ($entry->get('ID')) {
300 - $url = esc_url(add_query_arg(array(
300 + $url_data = [
301 301 'page' => 'e2pdf-download',
302 302 'uid' => $entry->get('uid'),
303 - ), site_url('/')
304 - ));
303 + ];
305 304
306 - if ($output && $output == 'url') {
307 - $response = $url;
308 - } else {
309 - $response = "<a id='e2pdf-download' class='" . implode(" ", $classes) . "' target='_blank' href='{$url}'>{$button_title}</a>";
305 + $url_data = apply_filters(
306 + 'e2pdf_model_shortcode_e2pdf_download_url_data',
307 + apply_filters('e2pdf_model_shortcode_url_data', $url_data, $atts),
308 + $atts
309 + );
310 +
311 + $url = $this->helper->get_frontend_pdf_url(
312 + $url_data, $attributes->get('site_url'),
313 + [
314 + 'e2pdf_model_shortcode_site_url',
315 + 'e2pdf_model_shortcode_e2pdf_download_site_url',
316 + ]
317 + );
318 + switch ($attributes->get('output')) {
319 + case 'url':
320 + case 'url_raw':
321 + case 'url_encode':
322 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_download_output_url', $url, $atts);
323 + if ($attributes->get('output') === 'url') {
324 + $response = esc_url($url);
325 + } elseif ($attributes->get('output') === 'url_raw') {
326 + $response = esc_url_raw($url);
327 + } elseif ($attributes->get('output') === 'url_encode') {
328 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
329 + $response = urlencode(esc_url_raw($url));
330 + }
331 + break;
332 + default:
333 + $file_download = '';
334 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_download_pdf_url', $url, $atts);
335 + if ($attributes->get('print') && $this->helper->load('server')->isPrintingSupported()) {
336 + $classes[] = 'e2pdf-print-pdf';
337 + $url = add_query_arg(['v' => $this->helper->get('version')], $url);
338 + } elseif ($attributes->get('view')) {
339 + $iframe_download = false;
340 + $viewer_atts = array_merge(
341 + array_diff_key($atts, ['class' => '']),
342 + [
343 + 'class' => isset($atts['view_class']) ? $atts['view_class'] : '',
344 + 'file' => $url,
345 + 'output' => 'url_raw',
346 + ]
347 + );
348 + $url = $this->e2pdf_view($viewer_atts);
349 + } elseif (get_option('e2pdf_download_loader', '0') == '1' && $this->helper->load('server')->isLoaderSupported()) {
350 + if ($inline) {
351 + $target = '_blank';
352 + } else {
353 + $download_name = $entry->get_data('name') ? $entry->get_data('name') : basename($pdf, '.' . pathinfo($pdf, PATHINFO_EXTENSION));
354 + $download_name = apply_filters('e2pdf_controller_frontend_e2pdf_download_name', $download_name, $entry->get('uid'), $entry->get('entry'));
355 + $file_download = 'download="' . esc_attr($download_name . '.' . (pathinfo($pdf, PATHINFO_EXTENSION))) . '"';
356 + $classes[] = 'e2pdf-download-loader';
357 + if ($this->helper->load('server')->isIOS() && $this->helper->load('server')->isSafari()) {
358 + $classes[] = 'e2pdf-ios-safari-loader';
359 + }
360 + }
361 + }
362 +
363 + $lid = uniqid('', true);
364 + $response = '<a lid="' . esc_attr($lid) . '" rel="nofollow" ' . $file_download . ' id="e2pdf-download" class="' . esc_attr(implode(' ', $classes)) . '" style="' . esc_attr(implode(';', $attributes->get('style'))) . '" target="' . esc_attr($target) . '" href="' . esc_url($url) . '">' . $button_title . '</a>';
365 + if ($iframe_download) {
366 + $url = add_query_arg(['v' => $this->helper->get('version')], $url);
367 +
368 + $src = $attributes->get('preload') ? 'preload' : 'src';
369 + $preload_class = $attributes->get('preload') ? 'e2pdf-preload' : '';
370 +
371 + if ($inline || (get_option('e2pdf_download_loader', '0') == '1' && $this->helper->load('server')->isLoaderSupported())) {
372 + $response .= '<img class="' . esc_attr($preload_class) . '" onload="e2pdfViewer.autoDownload(\'' . esc_attr($lid) . '\');" style="display:none" ' . $src . '="' . $attributes->get('iframe_loader') . '">';
373 + } else {
374 + $response .= '<iframe class="' . esc_attr($preload_class) . '" style="width:0;height:0;border-width:0;border:none;" ' . $src . '="' . esc_url($url) . '"></iframe>';
375 + }
376 + }
377 + break;
310 378 }
311 379 }
312 380 }
313 381 return $response;
@@ -312,376 +380,709 @@
312 380 }
313 381 return $response;
314 382 }
315 383
316 - if (!$dataset || !$template_id) {
384 + // phpcs:disable WordPress.Security.NonceVerification.Recommended
385 + if (isset($_GET['e2pdf-hash']) && !$attributes->get('dataset')) {
386 + $hash_id = sanitize_text_field(wp_unslash($_GET['e2pdf-hash']));
387 + $attributes->set('dataset', get_transient('e2pdf_hash_' . $hash_id));
388 + if ($attributes->get('dataset') && apply_filters('e2pdf_hash_clear', true, 'shortcode', $atts) && has_action('shutdown', [$this, 'action_e2pdf_hash_clear']) === false) {
389 + add_action('shutdown', [$this, 'action_e2pdf_hash_clear']);
390 + }
391 + }
392 + // phpcs:enable
393 +
394 + if (!$attributes->get('id') || (!$attributes->get('dataset') && !$attributes->get('dataset2'))) {
317 395 return $response;
318 396 }
319 397
320 398 $template = new Model_E2pdf_Template();
321 - if ($template->load($template_id, false)) {
399 + if (!$template->load($attributes->get('id'), false)) {
400 + return $response;
401 + }
322 402
323 - $uid_params = array();
324 - $uid_params['template_id'] = $template_id;
325 - $uid_params['dataset'] = $dataset;
403 + $entry = new Model_E2pdf_Entry();
326 404
327 - if (array_key_exists('class', $atts)) {
328 - $classes = explode(" ", $atts['class']);
329 - } else {
330 - $classes = array();
331 - }
332 - $classes[] = 'e2pdf-download';
405 + $template->extension()->patch('template_id', $attributes->get('id'), $entry);
406 + $template->extension()->patch('dataset', $attributes->get('dataset'), $entry);
407 + $template->extension()->patch('dataset2', $attributes->get('dataset2'), $entry);
408 + $template->extension()->patch('wc_order_id', $attributes->get('wc_order_id'), $entry);
409 + $template->extension()->patch('wc_product_item_id', $attributes->get('wc_product_item_id'), $entry);
410 + // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
411 + if (!($template->get('extension') === 'wordpress' && $template->get('item') === '-3')) {
412 + $template->extension()->patch('user_id', $attributes->get('user_id'), $entry);
413 + }
414 + $template->extension()->patch('args', $attributes->get('arguments'), $entry);
415 + $template->extension()->patch('storing_engine', $template->extension()->get_storing_engine(), $entry);
333 416
334 - $template->extension()->set('dataset', $dataset);
417 + $classes = array_merge($attributes->get('class'), ['e2pdf-download']);
335 418
336 - $options = array();
337 - $options = apply_filters('e2pdf_model_shortcode_extension_options', $options, $template);
338 - $options = apply_filters('e2pdf_model_shortcode_e2pdf_download_extension_options', $options, $template);
419 + $options = apply_filters('e2pdf_model_shortcode_extension_options', [], $template);
420 + $options = apply_filters('e2pdf_model_shortcode_e2pdf_download_extension_options', $options, $template);
339 421
340 - foreach ($options as $option_key => $option_value) {
341 - $template->extension()->set($option_key, $option_value);
342 - }
422 + foreach ($options as $option_key => $option_value) {
423 + $template->extension()->set($option_key, $option_value);
424 + }
343 425
344 - if ($template->extension()->verify()) {
426 + if ($template->extension()->verify() && $this->process_shortcode('e2pdf_download', $template, $attributes)) {
345 427
346 - if (array_key_exists('auto', $atts)) {
347 - $auto = $atts['auto'] == 'true' ? 1 : 0;
348 - } else {
349 - $auto = $template->get('auto');
350 - }
428 + $button_title = apply_filters('e2pdf_model_shortcode_e2pdf_download_button_title', $attributes->button_title($template), $atts);
429 + if ($attributes->get('output') === 'button_title') {
430 + return $button_title;
431 + }
351 432
352 - if ($auto) {
353 - $classes[] = 'e2pdf-auto';
354 - }
433 + $template->patch('inline', $attributes->get('inline'), $entry, $attributes->get('filter'));
434 + $template->patch('flatten', $attributes->get('flatten'), $entry, $attributes->get('filter'));
435 + $template->patch('format', $attributes->get('format'), $entry, $attributes->get('filter'));
436 + $template->patch('password', $attributes->get('password'), $entry, $attributes->get('filter'));
437 + $template->patch('dpdf', $attributes->get('dpdf'), $entry, $attributes->get('filter'));
438 + $template->patch('name', $attributes->get('name'), $entry, $attributes->get('filter'));
439 + $template->patch('meta_title', $attributes->get('meta_title'), $entry, $attributes->get('filter'));
440 + $template->patch('meta_subject', $attributes->get('meta_subject'), $entry, $attributes->get('filter'));
441 + $template->patch('meta_author', $attributes->get('meta_author'), $entry, $attributes->get('filter'));
442 + $template->patch('meta_keywords', $attributes->get('meta_keywords'), $entry, $attributes->get('filter'));
355 443
356 - if (array_key_exists('inline', $atts)) {
357 - $inline = $atts['inline'] == 'true' ? 1 : 0;
358 - $uid_params['inline'] = $inline;
359 - } else {
360 - $inline = $template->get('inline');
361 - }
444 + if ($template->get('inline')) {
445 + $classes[] = 'e2pdf-inline';
446 + }
362 447
363 - if ($inline) {
364 - $classes[] = 'e2pdf-inline';
448 + if ($attributes->get('auto') !== false) {
449 + $template->set('auto', $attributes->get('auto'));
450 + }
451 + if ($template->get('auto')) {
452 + $classes[] = 'e2pdf-auto';
453 + if ($attributes->get('iframe_download')) {
454 + $classes[] = 'e2pdf-iframe-download';
455 + $iframe_download = true;
365 456 }
457 + }
458 + $classes[] = 'e2pdf-format-' . $template->get('format');
366 459
367 - if (array_key_exists('flatten', $atts)) {
368 - $flatten = (int) $atts['flatten'];
369 - $uid_params['flatten'] = $flatten;
370 - }
460 + if (!$entry->load_by_uid()) {
461 + $entry->save();
462 + }
371 463
372 - if (array_key_exists('format', $atts)) {
373 - $format = $atts['format'];
374 - $uid_params['format'] = $format;
375 - }
464 + if ($entry->get('ID')) {
376 465
377 - if (array_key_exists('button-title', $atts)) {
378 - if (!array_key_exists('filter', $atts)) {
379 - $button_title = $template->extension()->render($atts['button-title'], 'value');
380 - } else {
381 - $button_title = $atts['button-title'];
382 - }
383 - } elseif ($template->extension()->render($template->get('button_title'), 'value') !== '') {
384 - $button_title = $template->extension()->render($template->get('button_title'), 'value');
385 - } else {
386 - $button_title = __('Download', 'e2pdf');
387 - }
466 + $download_name = apply_filters('e2pdf_controller_frontend_e2pdf_download_name', $template->get('name'), $entry->get('uid'), $entry->get('entry'));
388 467
389 - if (array_key_exists('password', $atts)) {
390 - if (!array_key_exists('filter', $atts)) {
391 - $password = $template->extension()->render($atts['password'], 'value');
392 - } else {
393 - $password = $atts['password'];
394 - }
395 - $uid_params['password'] = $password;
396 - }
468 + $url_data = [
469 + 'page' => 'e2pdf-download',
470 + 'uid' => $entry->get('uid'),
471 + ];
397 472
398 - if (array_key_exists('meta_title', $atts)) {
399 - if (!array_key_exists('filter', $atts)) {
400 - $meta_title = $template->extension()->render($atts['meta_title'], 'value');
401 - } else {
402 - $meta_title = $atts['meta_title'];
403 - }
404 - $uid_params['meta_title'] = $meta_title;
473 + if ($attributes->get('wc_product_download')) {
474 + $url_data['#saveName'] = '/' . $download_name . '.' . $template->get('format');
405 475 }
406 476
407 - if (array_key_exists('meta_subject', $atts)) {
408 - if (!array_key_exists('filter', $atts)) {
409 - $meta_subject = $template->extension()->render($atts['meta_subject'], 'value');
410 - } else {
411 - $meta_subject = $atts['meta_subject'];
412 - }
413 - $uid_params['meta_subject'] = $meta_subject;
414 - }
477 + $url_data = apply_filters(
478 + 'e2pdf_model_shortcode_e2pdf_download_url_data',
479 + apply_filters('e2pdf_model_shortcode_url_data', $url_data, $atts),
480 + $atts
481 + );
415 482
416 - if (array_key_exists('meta_author', $atts)) {
417 - if (!array_key_exists('filter', $atts)) {
418 - $meta_author = $template->extension()->render($atts['meta_author'], 'value');
419 - } else {
420 - $meta_author = $atts['meta_author'];
421 - }
422 - $uid_params['meta_author'] = $meta_author;
423 - }
483 + $url = $this->helper->get_frontend_pdf_url(
484 + $url_data, $attributes->get('site_url'),
485 + [
486 + 'e2pdf_model_shortcode_site_url',
487 + 'e2pdf_model_shortcode_e2pdf_download_site_url',
488 + ]
489 + );
490 + switch ($attributes->get('output')) {
491 + case 'url':
492 + case 'url_raw':
493 + case 'url_encode':
494 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_download_output_url', $url, $atts);
495 + if ($attributes->get('output') === 'url') {
496 + $response = esc_url($url);
497 + } elseif ($attributes->get('output') === 'url_raw') {
498 + $response = esc_url_raw($url);
499 + } elseif ($attributes->get('output') === 'url_encode') {
500 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
501 + $response = urlencode(esc_url_raw($url));
502 + }
503 + break;
504 + default:
505 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_download_pdf_url', $url, $atts);
506 + $file_download = '';
507 + if ($attributes->get('print') && $this->helper->load('server')->isPrintingSupported()) {
508 + $classes[] = 'e2pdf-print-pdf';
509 + $url = add_query_arg(['v' => $this->helper->get('version')], $url);
510 + } elseif ($attributes->get('view')) {
511 + $iframe_download = false;
512 + $viewer_atts = array_merge(
513 + array_diff_key($atts, ['class' => '']),
514 + [
515 + 'class' => isset($atts['view_class']) ? $atts['view_class'] : '',
516 + 'file' => $url,
517 + 'output' => 'url_raw',
518 + ]
519 + );
520 + $url = $this->e2pdf_view($viewer_atts);
521 + } elseif (get_option('e2pdf_download_loader', '0') == '1' && $this->helper->load('server')->isLoaderSupported()) {
522 + if ($template->get('inline')) {
523 + $target = '_blank';
524 + } else {
525 + $file_download = 'download="' . esc_attr($download_name) . '.' . $template->get('format') . '"';
526 + $classes[] = 'e2pdf-download-loader';
527 + if ($this->helper->load('server')->isIOS() && $this->helper->load('server')->isSafari()) {
528 + $classes[] = 'e2pdf-ios-safari-loader';
529 + }
530 + }
531 + }
424 532
425 - if (array_key_exists('meta_keywords', $atts)) {
426 - if (!array_key_exists('filter', $atts)) {
427 - $meta_keywords = $template->extension()->render($atts['meta_keywords'], 'value');
428 - } else {
429 - $meta_keywords = $atts['meta_keywords'];
430 - }
431 - $uid_params['meta_keywords'] = $meta_keywords;
432 - }
533 + $lid = uniqid('', true);
534 + $response = '<a lid="' . esc_attr($lid) . '" rel="nofollow" ' . $file_download . ' id="e2pdf-download" class="' . esc_attr(implode(' ', $classes)) . '" style="' . esc_attr(implode(';', $attributes->get('style'))) . '" target="' . esc_attr($target) . '" href="' . esc_url($url) . '">' . $button_title . '</a>';
535 + if ($iframe_download) {
536 + $url = add_query_arg(['v' => $this->helper->get('version')], $url);
433 537
434 - if (array_key_exists('name', $atts)) {
435 - if (!array_key_exists('filter', $atts)) {
436 - $name = $template->extension()->render($atts['name'], 'value');
437 - } else {
438 - $name = $atts['name'];
439 - }
440 - $uid_params['name'] = $name;
441 - }
538 + $src = $attributes->get('preload') ? 'preload' : 'src';
539 + $preload_class = $attributes->get('preload') ? 'e2pdf-preload' : '';
442 540
443 - if (array_key_exists('user_id', $atts)) {
444 - $uid_params['user_id'] = (int) $atts['user_id'];
445 - } else {
446 - $uid_params['user_id'] = get_current_user_id();
541 + if ($template->get('inline') || (get_option('e2pdf_download_loader', '0') == '1' && $this->helper->load('server')->isLoaderSupported())) {
542 + $response .= '<img class="' . esc_attr($preload_class) . '" onload="e2pdfViewer.autoDownload(\'' . esc_attr($lid) . '\');" style="display:none" ' . $src . '="' . $attributes->get('iframe_loader') . '">';
543 + } else {
544 + $response .= '<iframe class="' . esc_attr($preload_class) . '" style="width:0;height:0;border-width:0;border:none;" ' . $src . '="' . esc_url($url) . '"></iframe>';
545 + }
546 + }
547 + break;
447 548 }
448 -
449 - $uid_params['args'] = $args;
450 -
451 - $entry = new Model_E2pdf_Entry();
452 - $entry->set('entry', $uid_params);
453 - if (!$entry->load_by_uid($entry->get('uid'))) {
454 - $entry->save();
455 - }
456 -
457 - if ($entry->get('ID')) {
458 - $url = esc_url(add_query_arg(array(
459 - 'page' => 'e2pdf-download',
460 - 'uid' => $entry->get('uid'),
461 - ), site_url('/')
462 - ));
463 -
464 - if ($output && $output == 'url') {
465 - $response = $url;
466 - } else {
467 - $response = "<a id='e2pdf-download' class='" . implode(" ", $classes) . "' target='_blank' href='{$url}'>{$button_title}</a>";
468 - }
469 - }
470 549 }
471 550 }
551 +
472 552 return $response;
473 553 }
474 554
475 - /**
476 - * @since 0.01.44
477 - *
478 - * [e2pdf-save] shortcode
479 - *
480 - * @param array $atts - Attributes
481 - */
482 - function e2pdf_save($atts = array()) {
555 + // e2pdf-save
556 + public function e2pdf_save($atts = []) {
483 557
558 + unset($atts['pdf']);
559 +
484 560 $response = '';
485 561
486 - $template_id = isset($atts['id']) ? (int) $atts['id'] : 0;
487 - $dataset = isset($atts['dataset']) ? $atts['dataset'] : false;
488 - $download = isset($atts['download']) && $atts['download'] == 'true' ? true : false;
489 - $view = isset($atts['view']) && $atts['view'] == 'true' ? true : false;
490 - $attachment = isset($atts['attachment']) && $atts['attachment'] == 'true' ? true : false;
491 - $overwrite = isset($atts['overwrite']) && $atts['overwrite'] == 'false' ? false : true;
492 - $output = isset($atts['output']) ? $atts['output'] : false;
493 - $apply = isset($atts['apply']) ? true : false;
562 + $atts = apply_filters('e2pdf_model_shortcode_e2pdf_save_atts', $atts);
563 + $attributes = (new Helper_E2pdf_Atts())->load($atts);
494 564
495 - $args = array();
496 - foreach ($atts as $att_key => $att_value) {
497 - if (substr($att_key, 0, 3) === "arg") {
498 - $args[$att_key] = $att_value;
499 - }
565 + if (!$attributes->get('apply') || !$attributes->get('id') || (!$attributes->get('dataset') && !$attributes->get('dataset2'))) {
566 + return $response;
500 567 }
501 568
502 - if (!$apply || !$dataset || !$template_id) {
569 + $template = new Model_E2pdf_Template();
570 +
571 + if (!$template->load($attributes->get('id'))) {
503 572 return $response;
504 573 }
505 574
506 - $template = new Model_E2pdf_Template();
575 + $entry = new Model_E2pdf_Entry();
576 + $update = $attributes->get('media') || $attributes->get('gdrive') ? true : false;
507 577
508 - if ($template->load($template_id)) {
578 + $template->extension()->patch('template_id', $attributes->get('id'), $update ? $entry : null);
579 + $template->extension()->patch('dataset', $attributes->get('dataset'), $update ? $entry : null);
580 + $template->extension()->patch('dataset2', $attributes->get('dataset2'), $update ? $entry : null);
581 + $template->extension()->patch('wc_order_id', $attributes->get('wc_order_id'), $update ? $entry : null);
582 + $template->extension()->patch('wc_product_item_id', $attributes->get('wc_product_item_id'), $update ? $entry : null);
583 + $template->extension()->patch('user_id', $attributes->get('user_id'), $update ? $entry : null);
584 + $template->extension()->patch('args', $attributes->get('arguments'), $update ? $entry : null);
585 + $template->extension()->patch('storing_engine', $template->extension()->get_storing_engine(), $update ? $entry : null);
509 586
510 - $uid_params = array();
511 - $uid_params['template_id'] = $template_id;
512 - $uid_params['dataset'] = $dataset;
587 + $options = apply_filters('e2pdf_model_shortcode_extension_options', [], $template);
588 + $options = apply_filters('e2pdf_model_shortcode_e2pdf_save_extension_options', $options, $template);
589 + foreach ($options as $option_key => $option_value) {
590 + $template->extension()->set($option_key, $option_value);
591 + }
513 592
514 - $template->extension()->set('dataset', $dataset);
593 + if ($template->extension()->verify() && $this->process_shortcode('e2pdf_save', $template, $attributes)) {
515 594
516 - $options = array();
517 - $options = apply_filters('e2pdf_model_shortcode_extension_options', $options, $template);
518 - $options = apply_filters('e2pdf_model_shortcode_e2pdf_save_extension_options', $options, $template);
595 + $template->patch('inline', $attributes->get('inline'), $update ? $entry : null, $attributes->get('filter'));
596 + $template->patch('flatten', $attributes->get('flatten'), $update ? $entry : null, $attributes->get('filter'));
597 + $template->patch('format', $attributes->get('format'), $update ? $entry : null, $attributes->get('filter'));
598 + $template->patch('password', $attributes->get('password'), $update ? $entry : null, $attributes->get('filter'));
599 + $template->patch('dpdf', $attributes->get('dpdf'), $update ? $entry : null, $attributes->get('filter'));
600 + $template->patch('name', $attributes->get('name'), $update ? $entry : null, $attributes->get('filter'));
601 + $template->patch('savename', $attributes->get('savename'), $update ? $entry : null, $attributes->get('filter'));
602 + $template->patch('meta_title', $attributes->get('meta_title'), $update ? $entry : null, $attributes->get('filter'));
603 + $template->patch('meta_subject', $attributes->get('meta_subject'), $update ? $entry : null, $attributes->get('filter'));
604 + $template->patch('meta_author', $attributes->get('meta_author'), $update ? $entry : null, $attributes->get('filter'));
605 + $template->patch('meta_keywords', $attributes->get('meta_keywords'), $update ? $entry : null, $attributes->get('filter'));
519 606
520 - foreach ($options as $option_key => $option_value) {
521 - $template->extension()->set($option_key, $option_value);
607 + if ($template->get('inline')) {
608 + $entry->set_data('inline', $template->get('inline'));
609 + $atts['inline'] = $template->get('inline');
522 610 }
523 611
524 - if ($template->extension()->verify()) {
525 -
526 - if (array_key_exists('inline', $atts)) {
527 - $inline = $atts['inline'] == 'true' ? 1 : 0;
528 - $uid_params['inline'] = $inline;
612 + if (!$attributes->get('media') && !$attributes->get('gdrive')) {
613 + $dir = $attributes->get('dir');
614 + if ($dir) {
615 + $dir = $attributes->get('filter') ? $template->extension()->convert_shortcodes($dir, true) : $template->extension()->render($dir);
616 + $dir = rtrim(trim($this->helper->load('convert')->to_file_dir($dir)), '/') . '/';
617 + if (strpos($dir, '/') !== 0 && !preg_match('/^[A-Za-z]:/', $dir)) {
618 + $dir = ABSPATH . $dir;
619 + }
620 + if ($attributes->get('create_dir')) {
621 + $this->helper->create_dir($dir, true, $attributes->get('create_index', '1'), $attributes->get('create_htaccess', '1'));
622 + }
623 + } else {
624 + $tpl_dir = $this->helper->get('tpl_dir') . $template->get('ID') . '/';
625 + $dir = $tpl_dir . 'save/';
626 + $this->helper->create_dir($tpl_dir, false, true);
627 + $this->helper->create_dir($dir, false, $attributes->get('create_index', '1'), $attributes->get('create_htaccess', '1'));
529 628 }
629 + $htaccess = $dir . '.htaccess';
630 + if ($attributes->get('create_htaccess', '1') && !file_exists($htaccess)) {
631 + if ($attributes->get('local')) {
632 + $htaccess_content = 'DENY FROM ALL' . PHP_EOL;
633 + $htaccess_content .= '<Files ~ "\.(jpg|pdf)$">' . PHP_EOL;
634 + $htaccess_content .= 'ALLOW FROM ALL' . PHP_EOL;
635 + $htaccess_content .= '</Files>' . PHP_EOL;
636 + $this->helper->create_file($htaccess, $htaccess_content);
637 + } else {
638 + $this->helper->create_file($htaccess, 'DENY FROM ALL');
639 + }
640 + }
641 + }
530 642
531 - if (array_key_exists('flatten', $atts)) {
532 - $flatten = (int) $atts['flatten'];
533 - $uid_params['flatten'] = $flatten;
534 - $template->set('flatten', $flatten);
535 - }
643 + $filename = $template->get('savename') . '.' . $template->get('format');
644 + $filename = $this->helper->load('convert')->to_file_name($filename);
536 645
537 - if (array_key_exists('format', $atts)) {
538 - $format = $atts['format'];
539 - $uid_params['format'] = $format;
540 - $template->set('format', $format);
541 - }
646 + if ($template->get('savename') !== $template->get('name')) {
647 + $entry->set_data('name', $template->get('name'));
648 + $atts['name'] = $template->get('name');
649 + }
542 650
543 - if (array_key_exists('password', $atts)) {
544 - if (!array_key_exists('filter', $atts)) {
545 - $password = $template->extension()->render($atts['password'], 'value');
651 + if ($attributes->get('media')) {
652 + $entry->set_data('format', $template->get('format'));
653 + $entry->set_data('media', true);
654 + if ($entry->load_by_uid() && $entry->get_data('attachment_id')) {
655 + $filepath = get_attached_file($entry->get_data('attachment_id'));
656 + if ($filepath) {
657 + if ($attributes->get('overwrite', '1') || !file_exists($filepath)) {
658 + $template->extension()->set('entry', $entry);
659 + $template->fill();
660 + $request = $template->render();
661 + if (isset($request['error'])) {
662 + return $response;
663 + }
664 + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
665 + file_put_contents($filepath, $request['file'], LOCK_EX);
666 + $entry->set('pdf_num', $entry->get('pdf_num') + 1);
667 + $entry->save();
668 + }
546 669 } else {
547 - $password = $atts['password'];
670 + $template->extension()->set('entry', $entry);
671 + $template->fill();
672 + $request = $template->render();
673 + if (isset($request['error'])) {
674 + return $response;
675 + } else {
676 + $file = wp_upload_bits(
677 + $filename,
678 + null,
679 + $request['file']
680 + );
681 + if (is_array($file) && isset($file['file']) && file_exists($file['file'])) {
682 + $attachment_args = [
683 + 'import_id' => $entry->get_data('attachment_id'),
684 + 'guid' => $file['url'],
685 + 'post_mime_type' => $file['type'],
686 + 'post_title' => preg_replace('/\.[^.]+$/', '', basename($file['file'])),
687 + 'post_excerpt' => '',
688 + 'post_content' => '',
689 + ];
690 + $attachment_id = wp_insert_attachment($attachment_args, $file['file']);
691 + if (!is_wp_error($attachment_id) && $attachment_id) {
692 + require_once ABSPATH . 'wp-admin/includes/image.php';
693 + $attachment_metadata = wp_generate_attachment_metadata($attachment_id, $file['file']);
694 + wp_update_attachment_metadata($attachment_id, $attachment_metadata);
695 + $filepath = get_attached_file($attachment_id);
696 + $entry->set('pdf_num', $entry->get('pdf_num') + 1);
697 + $entry->set_data('attachment_id', $attachment_id);
698 + $entry->save();
699 + } else {
700 + return $response;
701 + }
702 + } else {
703 + return $response;
704 + }
705 + }
548 706 }
549 - $uid_params['password'] = $password;
550 - $template->set('password', $password);
551 707 } else {
552 - $template->set('password', $template->extension()->render($template->get('password'), 'value'));
553 - }
554 -
555 - if (array_key_exists('meta_title', $atts)) {
556 - if (!array_key_exists('filter', $atts)) {
557 - $meta_title = $template->extension()->render($atts['meta_title'], 'value');
708 + $template->extension()->set('entry', $entry);
709 + $template->fill();
710 + $request = $template->render();
711 + if (isset($request['error'])) {
712 + return $response;
558 713 } else {
559 - $meta_title = $atts['meta_title'];
714 + $file = wp_upload_bits(
715 + $filename,
716 + null,
717 + $request['file']
718 + );
719 + if (is_array($file) && isset($file['file']) && file_exists($file['file'])) {
720 + $attachment_args = [
721 + 'guid' => $file['url'],
722 + 'post_mime_type' => $file['type'],
723 + 'post_title' => preg_replace('/\.[^.]+$/', '', basename($file['file'])),
724 + 'post_excerpt' => '',
725 + 'post_content' => '',
726 + ];
727 + $attachment_id = wp_insert_attachment($attachment_args, $file['file']);
728 + if (!is_wp_error($attachment_id) && $attachment_id) {
729 + require_once ABSPATH . 'wp-admin/includes/image.php';
730 + $attachment_metadata = wp_generate_attachment_metadata($attachment_id, $file['file']);
731 + wp_update_attachment_metadata($attachment_id, $attachment_metadata);
732 + $filepath = get_attached_file($attachment_id);
733 + $entry->save();
734 + $entry->set_data('attachment_id', $attachment_id);
735 + $entry->save();
736 + } else {
737 + return $response;
738 + }
739 + } else {
740 + return $response;
741 + }
560 742 }
561 - $uid_params['meta_title'] = $meta_title;
562 - $template->set('meta_title', $meta_title);
563 - } else {
564 - $template->set('meta_title', $template->extension()->render($template->get('meta_title'), 'value'));
565 743 }
566 -
567 - if (array_key_exists('meta_subject', $atts)) {
568 - if (!array_key_exists('filter', $atts)) {
569 - $meta_subject = $template->extension()->render($atts['meta_subject'], 'value');
744 + if (!$this->helper->load('filter')->is_stream($filepath) && file_exists($filepath) && $entry->get_data('attachment_id')) {
745 + $atts['attachment_id'] = $entry->get_data('attachment_id');
746 + if ($attributes->get('download')) {
747 + $atts['button_title'] = $attributes->button_title($template);
748 + $response = $this->e2pdf_download($atts);
749 + } elseif ($attributes->get('view')) {
750 + $response = $this->e2pdf_view($atts);
751 + } elseif ($attributes->get('attachment')) {
752 + $response = $this->e2pdf_attachment($atts);
753 + } elseif ($attributes->get('zapier')) {
754 + $response = $this->e2pdf_zapier($atts);
755 + } elseif ($attributes->get('output') === 'path') {
756 + $response = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_path', $filepath, $atts);
570 757 } else {
571 - $meta_subject = $atts['meta_subject'];
758 + if ($attributes->get('local')) {
759 + $url = wp_get_attachment_url($entry->get_data('attachment_id'));
760 + switch ($attributes->get('output')) {
761 + case 'attachment_id':
762 + $attachment_id = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_attachment_id', $entry->get_data('attachment_id'), $atts);
763 + $response = $attachment_id;
764 + break;
765 + case 'url':
766 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_url', $url, $atts);
767 + $response = esc_url($url);
768 + break;
769 + case 'url_raw':
770 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_url', $url, $atts);
771 + $response = esc_url_raw($url);
772 + break;
773 + case 'url_encode':
774 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_url', $url, $atts);
775 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
776 + $response = urlencode(esc_url_raw($url));
777 + break;
778 + default:
779 + $response = '';
780 + break;
781 + }
782 + } else {
783 + if (!$entry->load_by_uid()) {
784 + $entry->save();
785 + }
786 + if ($entry->get('ID')) {
787 + $url_data = [
788 + 'page' => 'e2pdf-download',
789 + 'uid' => $entry->get('uid'),
790 + ];
791 + $url_data = apply_filters('e2pdf_model_shortcode_url_data', $url_data, $atts);
792 + $url_data = apply_filters('e2pdf_model_shortcode_e2pdf_save_url_data', $url_data, $atts);
793 + $url = $this->helper->get_frontend_pdf_url(
794 + $url_data, $attributes->get('site_url'),
795 + [
796 + 'e2pdf_model_shortcode_site_url',
797 + 'e2pdf_model_shortcode_e2pdf_save_site_url',
798 + ]
799 + );
800 + switch ($attributes->get('output')) {
801 + case 'attachment_id':
802 + $attachment_id = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_attachment_id', $entry->get_data('attachment_id'), $atts);
803 + $response = $attachment_id;
804 + break;
805 + case 'url':
806 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_url', $url, $atts);
807 + $response = esc_url($url);
808 + break;
809 + case 'url_raw':
810 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_url', $url, $atts);
811 + $response = esc_url_raw($url);
812 + break;
813 + case 'url_encode':
814 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_url', $url, $atts);
815 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
816 + $response = urlencode(esc_url_raw($url));
817 + break;
818 + default:
819 + $response = '';
820 + break;
821 + }
822 + }
823 + }
572 824 }
573 - $uid_params['meta_subject'] = $meta_subject;
574 - $template->set('meta_subject', $meta_subject);
825 + }
826 + } elseif ($attributes->get('gdrive')) {
827 + $dir = $attributes->get('dir');
828 + if ($dir) {
829 + $dir = $attributes->get('filter') ? $template->extension()->convert_shortcodes($dir, true) : $template->extension()->render($dir);
830 + $dir = (new Model_E2pdf_Gdrive())->create_dir($dir);
575 831 } else {
576 - $template->set('meta_subject', $template->extension()->render($template->get('meta_subject'), 'value'));
832 + $dir = 'root';
577 833 }
834 + if ($dir !== 'root') {
835 + $entry->set_data('dir', $dir);
836 + }
578 837
579 - if (array_key_exists('meta_author', $atts)) {
580 - if (!array_key_exists('filter', $atts)) {
581 - $meta_author = $template->extension()->render($atts['meta_author'], 'value');
838 + $entry->set_data('format', $template->get('format'));
839 + $entry->set_data('gdrive', true);
840 +
841 + if ($entry->load_by_uid() && $entry->get_data('file_id')) {
842 + $file_id = $entry->get_data('file_id');
843 + if ((new Model_E2pdf_Gdrive())->exists($file_id)) {
844 + if ($attributes->get('overwrite', '1')) {
845 + $template->extension()->set('entry', $entry);
846 + $template->fill();
847 + $request = $template->render();
848 + if (isset($request['error'])) {
849 + return $response;
850 + }
851 + $file_id = (new Model_E2pdf_Gdrive())->reupload($request['file'], $file_id);
852 + if ($file_id) {
853 + $entry->set('pdf_num', $entry->get('pdf_num') + 1);
854 + $entry->save();
855 + }
856 + }
582 857 } else {
583 - $meta_author = $atts['meta_author'];
858 + $template->extension()->set('entry', $entry);
859 + $template->fill();
860 + $request = $template->render();
861 + if (isset($request['error'])) {
862 + return $response;
863 + } else {
864 + $file_id = (new Model_E2pdf_Gdrive())->upload($request['file'], $filename, $dir);
865 + if ($file_id) {
866 + $entry->set('pdf_num', $entry->get('pdf_num') + 1);
867 + $entry->set_data('file_id', $file_id);
868 + $entry->save();
869 + } else {
870 + return $response;
871 + }
872 + }
584 873 }
585 - $uid_params['meta_author'] = $meta_author;
586 - $template->set('meta_author', $meta_author);
587 874 } else {
588 - $template->set('meta_author', $template->extension()->render($template->get('meta_author'), 'value'));
589 - }
590 -
591 - if (array_key_exists('meta_keywords', $atts)) {
592 - if (!array_key_exists('filter', $atts)) {
593 - $meta_keywords = $template->extension()->render($atts['meta_keywords'], 'value');
875 + $template->extension()->set('entry', $entry);
876 + $template->fill();
877 + $request = $template->render();
878 + if (isset($request['error'])) {
879 + return $response;
594 880 } else {
595 - $meta_keywords = $atts['meta_keywords'];
881 + $file_id = (new Model_E2pdf_Gdrive())->upload($request['file'], $filename, $dir);
882 + if ($file_id) {
883 + $entry->save();
884 + $entry->set_data('file_id', $file_id);
885 + $entry->save();
886 + } else {
887 + return $response;
888 + }
596 889 }
597 - $uid_params['meta_keywords'] = $meta_keywords;
598 - $template->set('meta_keywords', $meta_keywords);
599 - } else {
600 - $template->set('meta_keywords', $template->extension()->render($template->get('meta_keywords'), 'value'));
601 890 }
602 -
603 - if (array_key_exists('name', $atts)) {
604 - if (!array_key_exists('filter', $atts)) {
605 - $name = $template->extension()->render($atts['name'], 'value');
891 + if ($entry->get_data('file_id')) {
892 + $atts['file_id'] = $entry->get_data('file_id');
893 + if ($attributes->get('download')) {
894 + $atts['button_title'] = $attributes->button_title($template);
895 + $response = $this->e2pdf_download($atts);
896 + } elseif ($attributes->get('view')) {
897 + $response = $this->e2pdf_view($atts);
898 + } elseif ($attributes->get('attachment')) {
899 + $response = $this->e2pdf_attachment($atts);
900 + } elseif ($attributes->get('zapier')) {
901 + $response = $this->e2pdf_zapier($atts);
902 + } elseif ($attributes->get('output') === 'path') {
903 + $response = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_path', $filepath, $atts);
606 904 } else {
607 - $name = $atts['name'];
905 + if ($attributes->get('local')) {
906 + if ($template->get('inline')) {
907 + $url = 'https://drive.google.com/file/d/' . $entry->get_data('file_id') . '/view';
908 + } else {
909 + $url = 'https://drive.google.com/uc?id=' . $entry->get_data('file_id') . '&export=download';
910 + }
911 + switch ($attributes->get('output')) {
912 + case 'file_id':
913 + $file_id = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_file_id', $entry->get_data('file_id'), $atts);
914 + $response = $file_id;
915 + break;
916 + case 'url':
917 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_url', $url, $atts);
918 + $response = esc_url($url);
919 + break;
920 + case 'url_raw':
921 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_url', $url, $atts);
922 + $response = esc_url_raw($url);
923 + break;
924 + case 'url_encode':
925 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_url', $url, $atts);
926 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
927 + $response = urlencode(esc_url_raw($url));
928 + break;
929 + default:
930 + $response = '';
931 + break;
932 + }
933 + } else {
934 + if (!$entry->load_by_uid()) {
935 + $entry->save();
936 + }
937 + if ($entry->get('ID')) {
938 + $url_data = [
939 + 'page' => 'e2pdf-download',
940 + 'uid' => $entry->get('uid'),
941 + ];
942 + $url_data = apply_filters('e2pdf_model_shortcode_url_data', $url_data, $atts);
943 + $url_data = apply_filters('e2pdf_model_shortcode_e2pdf_save_url_data', $url_data, $atts);
944 + $url = $this->helper->get_frontend_pdf_url(
945 + $url_data, $attributes->get('site_url'),
946 + [
947 + 'e2pdf_model_shortcode_site_url',
948 + 'e2pdf_model_shortcode_e2pdf_save_site_url',
949 + ]
950 + );
951 + switch ($attributes->get('output')) {
952 + case 'file_id':
953 + $file_id = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_file_id', $entry->get_data('file_id'), $atts);
954 + $response = $file_id;
955 + break;
956 + case 'url':
957 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_url', $url, $atts);
958 + $response = esc_url($url);
959 + break;
960 + case 'url_raw':
961 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_url', $url, $atts);
962 + $response = esc_url_raw($url);
963 + break;
964 + case 'url_encode':
965 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_url', $url, $atts);
966 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
967 + $response = urlencode(esc_url_raw($url));
968 + break;
969 + default:
970 + $response = '';
971 + break;
972 + }
973 + }
974 + }
608 975 }
609 - $uid_params['name'] = $name;
610 - $template->set('name', $name);
611 - } else {
612 - $template->set('name', $template->extension()->render($template->get('name'), 'value'));
613 976 }
614 -
615 - if ($download || $view || $attachment) {
616 - $uid_params['pdf'] = false;
977 + } else {
978 + $filepath = apply_filters('e2pdf_model_e2pdf_shortcode_pre_save_path', $dir . $filename, $atts);
979 + $entry->set_data('pdf', $filepath);
980 + if ($attributes->get('local')) {
981 + $entry->set_data('e2pdf-url', $this->helper->get_frontend_local_pdf_url($filepath));
617 982 }
618 -
619 - if (array_key_exists('user_id', $atts)) {
620 - $uid_params['user_id'] = (int) $atts['user_id'];
621 - } else {
622 - $uid_params['user_id'] = get_current_user_id();
623 - }
624 -
625 - $uid_params['args'] = $args;
626 -
627 - $entry = new Model_E2pdf_Entry();
628 - $entry->set('entry', $uid_params);
629 - if (!$entry->load_by_uid($entry->get('uid'))) {
630 - $entry->save();
631 - }
632 -
633 - if (array_key_exists('dir', $atts)) {
634 - $save_dir = $atts['dir'];
635 - } else {
636 - $tpl_dir = $this->helper->get('tpl_dir') . $template->get('ID') . "/";
637 - $save_dir = $tpl_dir . "save/";
638 - $this->helper->create_dir($tpl_dir);
639 - $this->helper->create_dir($save_dir);
640 - }
641 -
642 - if ($template->get('name')) {
643 - $name = $template->get('name');
644 - } else {
645 - $name = $template->extension()->render($template->get_filename(), 'value');
646 - }
647 -
648 - $file_name = $name . '.pdf';
649 - $file_name = $this->helper->load('convert')->to_file_name($file_name);
650 - $file_path = $save_dir . $file_name;
651 -
652 - if ($overwrite || !file_exists($file_path)) {
653 - $template->fill($dataset, $entry->get('uid'));
983 + if ($attributes->get('overwrite', '1') || !file_exists($filepath)) {
984 + $template->extension()->set('entry', $entry);
985 + $template->fill();
654 986 $request = $template->render();
655 987 }
656 -
657 - if (isset($request['error'])) {
988 + if (isset($request['error']) && ($attributes->get('overwrite', '1') || !file_exists($filepath))) {
658 989 return false;
659 990 } else {
660 - if ($entry->get('ID')) {
661 -
662 - if (is_dir($save_dir) && is_writable($save_dir)) {
663 -
664 - if ($overwrite || !file_exists($file_path)) {
665 - file_put_contents($file_path, base64_decode($request['file']));
991 + if (is_dir($dir) && is_writable($dir)) {
992 + if ($attributes->get('overwrite', '1') || !file_exists($filepath)) {
993 + if ($attributes->get('overwrite', '1') === '2' && file_exists($filepath)) {
994 + $path = pathinfo($filepath);
995 + $current_name = $path['filename'];
996 + $i = 1;
997 + while (file_exists($path['dirname'] . '/' . $current_name . '.' . $path['extension'])) {
998 + $current_name = $path['filename'] . '(' . $i . ')';
999 + $filepath = $path['dirname'] . '/' . $current_name . '.' . $path['extension'];
1000 + $i++;
1001 + }
1002 + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
1003 + file_put_contents($filepath, $request['file'], LOCK_EX);
1004 + } else {
1005 + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
1006 + file_put_contents($filepath, $request['file'], LOCK_EX);
666 1007 }
667 -
668 - if (!$this->helper->load('filter')->is_stream($file_path) && file_exists($file_path)) {
1008 + if ($entry->load_by_uid()) {
669 1009 $entry->set('pdf_num', $entry->get('pdf_num') + 1);
670 - if ($download || $view || $attachment) {
671 - $uid_params['pdf'] = $file_path;
672 - $entry->set('entry', $uid_params);
673 - $atts['uid'] = $entry->get('uid');
674 - }
675 1010 $entry->save();
676 - if ($download) {
677 - $response = $this->e2pdf_download($atts);
678 - } elseif ($view) {
679 - $response = $this->e2pdf_view($atts);
680 - } elseif ($attachment) {
681 - $response = $this->e2pdf_attachment($atts);
682 - } elseif ($output && $output == 'path') {
683 - $response = $file_path;
1011 + }
1012 + }
1013 + if (!$this->helper->load('filter')->is_stream($filepath) && file_exists($filepath)) {
1014 + $filepath = apply_filters('e2pdf_model_e2pdf_shortcode_save_path', $filepath, $atts);
1015 + $atts['pdf'] = $filepath;
1016 + if ($attributes->get('download')) {
1017 + $atts['button_title'] = $attributes->button_title($template);
1018 + $response = $this->e2pdf_download($atts);
1019 + } elseif ($attributes->get('view')) {
1020 + $response = $this->e2pdf_view($atts);
1021 + } elseif ($attributes->get('attachment')) {
1022 + $response = $this->e2pdf_attachment($atts);
1023 + } elseif ($attributes->get('zapier')) {
1024 + $response = $this->e2pdf_zapier($atts);
1025 + } elseif ($attributes->get('output') === 'path') {
1026 + $response = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_path', $filepath, $atts);
1027 + } else {
1028 + if ($attributes->get('local')) {
1029 + $url = $this->helper->get_frontend_local_pdf_url($filepath);
1030 + switch ($attributes->get('output')) {
1031 + case 'url':
1032 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_url', $url, $atts);
1033 + $response = esc_url($url);
1034 + break;
1035 + case 'url_raw':
1036 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_url', $url, $atts);
1037 + $response = esc_url_raw($url);
1038 + break;
1039 + case 'url_encode':
1040 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_url', $url, $atts);
1041 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
1042 + $response = urlencode(esc_url_raw($url));
1043 + break;
1044 + default:
1045 + $response = '';
1046 + break;
1047 + }
1048 + } else {
1049 + if (!$entry->load_by_uid()) {
1050 + $entry->save();
1051 + }
1052 + if ($entry->get('ID')) {
1053 + $url_data = [
1054 + 'page' => 'e2pdf-download',
1055 + 'uid' => $entry->get('uid'),
1056 + ];
1057 + $url_data = apply_filters('e2pdf_model_shortcode_url_data', $url_data, $atts);
1058 + $url_data = apply_filters('e2pdf_model_shortcode_e2pdf_save_url_data', $url_data, $atts);
1059 + $url = $this->helper->get_frontend_pdf_url(
1060 + $url_data, $attributes->get('site_url'),
1061 + [
1062 + 'e2pdf_model_shortcode_site_url',
1063 + 'e2pdf_model_shortcode_e2pdf_save_site_url',
1064 + ]
1065 + );
1066 + switch ($attributes->get('output')) {
1067 + case 'url':
1068 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_url', $url, $atts);
1069 + $response = esc_url($url);
1070 + break;
1071 + case 'url_raw':
1072 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_url', $url, $atts);
1073 + $response = esc_url_raw($url);
1074 + break;
1075 + case 'url_encode':
1076 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_save_output_url', $url, $atts);
1077 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
1078 + $response = urlencode(esc_url_raw($url));
1079 + break;
1080 + default:
1081 + $response = '';
1082 + break;
1083 + }
1084 + }
684 1085 }
685 1086 }
686 1087 }
687 1088 }
@@ -687,599 +1088,1338 @@
687 1088 }
688 1089 }
689 1090 }
690 1091 }
1092 +
691 1093 return $response;
692 1094 }
693 1095
694 - /**
695 - * [e2pdf-view] shortcode
696 - *
697 - * @param array $atts - Attributes
698 - */
699 - function e2pdf_view($atts = array()) {
1096 + // e2pdf-zapier
1097 + public function e2pdf_zapier($atts = []) {
700 1098
701 1099 $response = '';
702 - $name = '';
703 1100
704 - $template_id = isset($atts['id']) ? (int) $atts['id'] : 0;
705 - $dataset = isset($atts['dataset']) ? $atts['dataset'] : false;
706 - $uid = isset($atts['uid']) ? $atts['uid'] : false;
707 - $width = isset($atts['width']) ? $atts['width'] : '100%';
708 - $height = isset($atts['height']) ? $atts['height'] : '500';
709 - $pdf = isset($atts['pdf']) ? $atts['pdf'] : false;
710 - $page = isset($atts['page']) ? $atts['page'] : false;
711 - $zoom = isset($atts['zoom']) ? $atts['zoom'] : false;
712 - $nameddest = isset($atts['nameddest']) ? $atts['nameddest'] : false;
713 - $pagemode = isset($atts['pagemode']) ? $atts['pagemode'] : false;
1101 + $atts = apply_filters('e2pdf_model_shortcode_e2pdf_zapier_atts', $atts);
1102 + $attributes = (new Helper_E2pdf_Atts())->load($atts);
714 1103
715 - $args = array();
716 - foreach ($atts as $att_key => $att_value) {
717 - if (substr($att_key, 0, 3) === "arg") {
718 - $args[$att_key] = $att_value;
719 - }
1104 + if (!$attributes->get('webhook')) {
1105 + return $response;
720 1106 }
721 1107
722 - $viewer_options = array();
723 - if ($page) {
724 - $viewer_options[] = 'page=' . $page;
725 - }
726 - if ($zoom) {
727 - $viewer_options[] = 'zoom=' . $zoom;
728 - }
729 - if ($nameddest) {
730 - $viewer_options[] = 'nameddest=' . $nameddest;
731 - }
732 - if ($pagemode) {
733 - $viewer_options[] = 'pagemode=' . $pagemode;
734 - }
1108 + if ($attributes->get('pdf') || $attributes->get('attachment_id') || $attributes->get('file_id')) {
1109 + $pdf = $attributes->get('pdf');
1110 + $downloadable = false;
1111 + if ($attributes->get('file_id')) {
1112 + $pdf = (new Model_E2pdf_Gdrive())->exists($attributes->get('file_id'));
1113 + if ($pdf) {
1114 + $downloadable = true;
1115 + }
1116 + } else {
1117 + if ($attributes->get('attachment_id')) {
1118 + $pdf = get_attached_file($attributes->get('attachment_id'));
1119 + } else {
1120 + $pdf = $this->helper->load('convert')->to_file_dir($pdf);
1121 + }
1122 + if (strpos($pdf, '/') !== 0 && !preg_match('/^[A-Za-z]:/', $pdf)) {
1123 + $pdf = ABSPATH . $pdf;
1124 + }
1125 + $downloadable = !$this->helper->load('filter')->is_stream($pdf) && file_exists($pdf) && $this->helper->load('filter')->is_downloadable($pdf);
1126 + }
735 1127
736 - if (array_key_exists('class', $atts)) {
737 - $classes = explode(" ", $atts['class']);
738 - } else {
739 - $classes = array();
740 - }
741 - $classes[] = 'e2pdf-view';
1128 + if (!$downloadable) {
1129 + return $response;
1130 + }
742 1131
743 - if ($uid) {
744 1132 $entry = new Model_E2pdf_Entry();
745 - if ($entry->load_by_uid($uid)) {
1133 + if ($attributes->get('attachment_id')) {
1134 + $entry->set_data('attachment_id', $attributes->get('attachment_id'));
1135 + } elseif ($attributes->get('file_id')) {
1136 + $entry->set_data('file_id', $attributes->get('file_id'));
1137 + } else {
1138 + $entry->set_data('pdf', $pdf);
1139 + }
746 1140
747 - $uid_params = $entry->get('entry');
1141 + $classes = $attributes->get('class');
1142 + $classes[] = 'e2pdf-download';
748 1143
749 - $template_id = isset($uid_params['template_id']) ? (int) $uid_params['template_id'] : 0;
750 - $dataset = isset($uid_params['dataset']) ? $uid_params['dataset'] : false;
1144 + $inline = '0';
1145 + if ($attributes->get('inline') !== false) {
1146 + $inline = $attributes->get('inline');
1147 + $entry->set_data('inline', $inline);
1148 + }
751 1149
752 - $template = new Model_E2pdf_Template();
753 - if ($uid_params['pdf'] && file_exists($uid_params['pdf']) && isset($uid_params['template_id']) && isset($uid_params['dataset']) && $template->load($uid_params['template_id'])) {
1150 + if ($attributes->get('name') !== false) {
1151 + $name = $attributes->get('name');
1152 + $entry->set_data('name', $name);
1153 + } else {
1154 + $name = '';
1155 + }
1156 + $content_type = 'application/json';
1157 + $blog_charset = get_option('blog_charset');
1158 + if (!empty($blog_charset)) {
1159 + $content_type .= '; charset=' . get_option('blog_charset');
1160 + }
1161 + if ($attributes->get('local')) {
1162 + $url = $attributes->get('attachment_id') ? wp_get_attachment_url($attributes->get('attachment_id')) : $this->helper->get_frontend_local_pdf_url($pdf);
1163 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_zapier_pdf_url', $url, $atts);
1164 + $ext = pathinfo($pdf, PATHINFO_EXTENSION);
1165 + $name = basename($pdf, '.' . $ext);
1166 + } else {
1167 + if (!$entry->load_by_uid()) {
1168 + $entry->save();
1169 + }
754 1170
755 - if (isset($uid_params['name'])) {
756 - $template->set('name', $uid_params['name']);
757 - } else {
758 - $template->set('name', $template->extension()->render($template->get('name'), 'value'));
759 - }
760 - if ($template->get('name')) {
761 - $name = $template->get('name');
762 - } else {
763 - $name = $template->extension()->render($template->get_filename(), 'value');
764 - }
1171 + if ($entry->get('ID')) {
765 1172
1173 + $url_data = [
1174 + 'page' => 'e2pdf-download',
1175 + 'uid' => $entry->get('uid'),
1176 + ];
1177 + $url_data = apply_filters('e2pdf_model_shortcode_url_data', $url_data, $atts);
1178 + $url_data = apply_filters('e2pdf_model_shortcode_e2pdf_zapier_url_data', $url_data, $atts);
1179 +
1180 + $url = esc_url_raw(
1181 + $this->helper->get_frontend_pdf_url(
1182 + $url_data, $attributes->get('site_url'),
1183 + [
1184 + 'e2pdf_model_shortcode_site_url',
1185 + 'e2pdf_model_shortcode_e2pdf_zapier_site_url',
1186 + ]
1187 + )
1188 + );
1189 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_zapier_pdf_url', $url, $atts);
1190 + $ext = pathinfo($pdf, PATHINFO_EXTENSION);
766 1191 if (!$name) {
767 - $name = basename($uid_params['pdf'], ".pdf");
1192 + $name = basename($pdf, '.' . $ext);
768 1193 }
769 -
770 - $pdf = esc_url_raw(add_query_arg(array(
771 - 'page' => 'e2pdf-download',
772 - 'uid' => $entry->get('uid'),
773 - 'saveName' => $name
774 - ), site_url('/')
775 - ));
776 1194 }
777 - } else {
778 - return $response;
779 1195 }
780 - }
781 -
782 - if ($pdf) {
783 - if (filter_var($pdf, FILTER_VALIDATE_URL)) {
784 - $file = urlencode($pdf);
785 - if (!empty($viewer_options)) {
786 - $file .= '#' . implode('&', $viewer_options);
1196 + if ($attributes->get('local') || $entry->get('ID')) {
1197 + $zapier = [];
1198 + if ($attributes->get('id')) {
1199 + $zapier['id'] = $attributes->get('id');
787 1200 }
788 -
789 - $url = plugins_url('assets/pdf.js/web/viewer.html?file=' . $file, $this->helper->get('plugin_file_path'));
790 - $response = "<iframe class='" . implode(" ", $classes) . "' width='{$width}' height='{$height}' src='{$url}'></iframe>";
791 - } else if (!$this->helper->load('filter')->is_stream($pdf) && file_exists($pdf)) {
792 -
793 - $uid_params['pdf'] = $pdf;
794 -
795 - if (array_key_exists('name', $atts)) {
796 - $name = $atts['name'];
797 - $uid_params['name'] = $name;
1201 + if ($attributes->get('dataset')) {
1202 + $zapier['dataset'] = $attributes->get('dataset');
798 1203 }
799 -
800 - $entry = new Model_E2pdf_Entry();
801 - $entry->set('entry', $uid_params);
802 - if (!$entry->load_by_uid($entry->get('uid'))) {
803 - $entry->save();
1204 + if ($attributes->get('dataset2')) {
1205 + $zapier['dataset2'] = $attributes->get('dataset2');
804 1206 }
805 -
1207 + if ($attributes->get('wc_order_id')) {
1208 + $zapier['wc_order_id'] = $attributes->get('wc_order_id');
1209 + }
1210 + if ($attributes->get('wc_product_item_id')) {
1211 + $zapier['wc_product_item_id'] = $attributes->get('wc_product_item_id');
1212 + }
806 1213 if ($entry->get('ID')) {
807 - if (!$name) {
808 - $name = basename($uid_params['pdf'], ".pdf");
809 - }
1214 + $zapier['uid'] = $entry->get('uid');
1215 + }
1216 + $zapier['name'] = $name;
1217 + $zapier['format'] = strtolower($ext);
1218 + $zapier['url'] = $url;
810 1219
811 - $pdf_url = esc_url_raw(add_query_arg(array(
812 - 'page' => 'e2pdf-download',
813 - 'uid' => $entry->get('uid'),
814 - 'saveName' => $name
815 - ), site_url('/')
816 - ));
1220 + $data = apply_filters(
1221 + 'e2pdf_model_shortcode_e2pdf_zapier_data',
1222 + array_merge(
1223 + $zapier, $attributes->get('arguments')
1224 + ), $atts
1225 + );
817 1226
818 - $file = urlencode($pdf_url);
819 - if (!empty($viewer_options)) {
820 - $file .= '#' . implode('&', $viewer_options);
821 - }
822 -
823 - $url = plugins_url('assets/pdf.js/web/viewer.html?file=' . $file, $this->helper->get('plugin_file_path'));
824 - $response = "<iframe class='" . implode(" ", $classes) . "' width='{$width}' height='{$height}' src='{$url}'></iframe>";
1227 + $zapier_args = apply_filters(
1228 + 'e2pdf_model_shortcode_e2pdf_zapier_args',
1229 + [
1230 + 'method' => 'POST',
1231 + 'body' => json_encode($data), // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
1232 + 'headers' => [
1233 + 'Content-Type' => $content_type,
1234 + ],
1235 + ], $atts
1236 + );
1237 + $result = [];
1238 + if ($attributes->get('webhook') !== 'local') {
1239 + $result = wp_remote_post($attributes->get('webhook'), $zapier_args);
825 1240 }
1241 + $response = apply_filters('e2pdf_model_shortcode_e2pdf_zapier_response', $response, $result, $atts, $data);
826 1242 }
1243 +
827 1244 return $response;
828 1245 }
829 1246
830 - if (!$template_id || !$dataset) {
1247 + if (!$attributes->get('id') || (!$attributes->get('dataset') && !$attributes->get('dataset2'))) {
831 1248 return $response;
832 1249 }
833 1250
834 1251 $template = new Model_E2pdf_Template();
835 - if ($template->load($template_id, false)) {
1252 + if (!$template->load($attributes->get('id'), false)) {
1253 + return $response;
1254 + }
836 1255
837 - $uid_params = array();
838 - $uid_params['template_id'] = $template_id;
839 - $uid_params['dataset'] = $dataset;
1256 + $entry = new Model_E2pdf_Entry();
840 1257
841 - $template->extension()->set('dataset', $dataset);
1258 + $template->extension()->patch('template_id', $attributes->get('id'), $entry);
1259 + $template->extension()->patch('dataset', $attributes->get('dataset'), $entry);
1260 + $template->extension()->patch('dataset2', $attributes->get('dataset2'), $entry);
1261 + $template->extension()->patch('wc_order_id', $attributes->get('wc_order_id'), $entry);
1262 + $template->extension()->patch('wc_product_item_id', $attributes->get('wc_product_item_id'), $entry);
1263 + // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
1264 + if (!($template->get('extension') === 'wordpress' && $template->get('item') === '-3')) {
1265 + $template->extension()->patch('user_id', $attributes->get('user_id'), $entry);
1266 + }
1267 + $template->extension()->patch('args', $attributes->get('arguments'), $entry);
1268 + $template->extension()->patch('storing_engine', $template->extension()->get_storing_engine(), $entry);
842 1269
843 - $options = array();
844 - $options = apply_filters('e2pdf_model_shortcode_extension_options', $options, $template);
845 - $options = apply_filters('e2pdf_model_shortcode_e2pdf_view_extension_options', $options, $template);
1270 + $classes = $attributes->get('class');
1271 + $classes[] = 'e2pdf-download';
846 1272
847 - foreach ($options as $option_key => $option_value) {
848 - $template->extension()->set($option_key, $option_value);
849 - }
1273 + $options = apply_filters('e2pdf_model_shortcode_extension_options', [], $template);
1274 + $options = apply_filters('e2pdf_model_shortcode_e2pdf_zapier_extension_options', $options, $template);
1275 + foreach ($options as $option_key => $option_value) {
1276 + $template->extension()->set($option_key, $option_value);
1277 + }
850 1278
851 - if ($template->extension()->verify()) {
1279 + if ($template->extension()->verify() && $this->process_shortcode('e2pdf_zapier', $template, $attributes)) {
852 1280
853 - if (array_key_exists('inline', $atts)) {
854 - $inline = $atts['inline'] == 'true' ? 1 : 0;
855 - $uid_params['inline'] = $inline;
856 - }
1281 + $template->patch('inline', $attributes->get('inline'), $entry, $attributes->get('filter'));
1282 + $template->patch('flatten', $attributes->get('flatten'), $entry, $attributes->get('filter'));
1283 + $template->patch('format', $attributes->get('format'), $entry, $attributes->get('filter'));
1284 + $template->patch('password', $attributes->get('password'), $entry, $attributes->get('filter'));
1285 + $template->patch('dpdf', $attributes->get('dpdf'), $entry, $attributes->get('filter'));
1286 + $template->patch('name', $attributes->get('name'), $entry, $attributes->get('filter'));
1287 + $template->patch('meta_title', $attributes->get('meta_title'), $entry, $attributes->get('filter'));
1288 + $template->patch('meta_subject', $attributes->get('meta_subject'), $entry, $attributes->get('filter'));
1289 + $template->patch('meta_author', $attributes->get('meta_author'), $entry, $attributes->get('filter'));
1290 + $template->patch('meta_keywords', $attributes->get('meta_keywords'), $entry, $attributes->get('filter'));
857 1291
858 - if (array_key_exists('flatten', $atts)) {
859 - $flatten = (int) $atts['flatten'];
860 - $uid_params['flatten'] = $flatten;
861 - }
1292 + if (!$entry->load_by_uid()) {
1293 + $entry->save();
1294 + }
862 1295
863 - if (array_key_exists('format', $atts)) {
864 - $format = $atts['format'];
865 - $uid_params['format'] = $format;
866 - }
1296 + if ($entry->get('ID')) {
867 1297
868 - if (array_key_exists('password', $atts)) {
869 - if (!array_key_exists('filter', $atts)) {
870 - $password = $template->extension()->render($atts['password']);
871 - } else {
872 - $password = $atts['password'];
873 - }
874 - $uid_params['password'] = $password;
1298 + $content_type = 'application/json';
1299 + $blog_charset = get_option('blog_charset');
1300 + if (!empty($blog_charset)) {
1301 + $content_type .= '; charset=' . get_option('blog_charset');
875 1302 }
876 1303
877 - if (array_key_exists('meta_title', $atts)) {
878 - if (!array_key_exists('filter', $atts)) {
879 - $meta_title = $template->extension()->render($atts['meta_title'], 'value');
880 - } else {
881 - $meta_title = $atts['meta_title'];
882 - }
883 - $uid_params['meta_title'] = $meta_title;
884 - }
1304 + $url_data = [
1305 + 'page' => 'e2pdf-download',
1306 + 'uid' => $entry->get('uid'),
1307 + ];
1308 + $url_data = apply_filters('e2pdf_model_shortcode_url_data', $url_data, $atts);
1309 + $url_data = apply_filters('e2pdf_model_shortcode_e2pdf_zapier_url_data', $url_data, $atts);
885 1310
886 - if (array_key_exists('meta_subject', $atts)) {
887 - if (!array_key_exists('filter', $atts)) {
888 - $meta_subject = $template->extension()->render($atts['meta_subject'], 'value');
889 - } else {
890 - $meta_subject = $atts['meta_subject'];
891 - }
892 - $uid_params['meta_subject'] = $meta_subject;
893 - }
1311 + $url = esc_url_raw(
1312 + $this->helper->get_frontend_pdf_url(
1313 + $url_data, $attributes->get('site_url'),
1314 + [
1315 + 'e2pdf_model_shortcode_site_url',
1316 + 'e2pdf_model_shortcode_e2pdf_zapier_site_url',
1317 + ]
1318 + )
1319 + );
1320 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_zapier_pdf_url', $url, $atts);
894 1321
895 - if (array_key_exists('meta_author', $atts)) {
896 - if (!array_key_exists('filter', $atts)) {
897 - $meta_author = $template->extension()->render($atts['meta_author'], 'value');
898 - } else {
899 - $meta_author = $atts['meta_author'];
900 - }
901 - $uid_params['meta_author'] = $meta_author;
1322 + $zapier = [];
1323 + if ($attributes->get('id')) {
1324 + $zapier['id'] = $attributes->get('id');
902 1325 }
903 -
904 - if (array_key_exists('meta_keywords', $atts)) {
905 - if (!array_key_exists('filter', $atts)) {
906 - $meta_keywords = $template->extension()->render($atts['meta_keywords'], 'value');
907 - } else {
908 - $meta_keywords = $atts['meta_keywords'];
909 - }
910 - $uid_params['meta_keywords'] = $meta_keywords;
1326 + if ($attributes->get('dataset')) {
1327 + $zapier['dataset'] = $attributes->get('dataset');
911 1328 }
912 -
913 - if (array_key_exists('name', $atts)) {
914 - if (!array_key_exists('filter', $atts)) {
915 - $name = $template->extension()->render($atts['name'], 'value');
916 - } else {
917 - $name = $atts['name'];
918 - }
919 - $uid_params['name'] = $name;
920 - $template->set('name', $name);
921 - } else {
922 - $template->set('name', $template->extension()->render($template->get('name'), 'value'));
1329 + if ($attributes->get('dataset2')) {
1330 + $zapier['dataset2'] = $attributes->get('dataset2');
923 1331 }
924 -
925 - if (array_key_exists('user_id', $atts)) {
926 - $uid_params['user_id'] = (int) $atts['user_id'];
927 - } else {
928 - $uid_params['user_id'] = get_current_user_id();
1332 + if ($attributes->get('wc_order_id')) {
1333 + $zapier['wc_order_id'] = $attributes->get('wc_order_id');
929 1334 }
930 -
931 - $uid_params['args'] = $args;
932 -
933 - $entry = new Model_E2pdf_Entry();
934 - $entry->set('entry', $uid_params);
935 - if (!$entry->load_by_uid($entry->get('uid'))) {
936 - $entry->save();
1335 + if ($attributes->get('wc_product_item_id')) {
1336 + $zapier['wc_product_item_id'] = $attributes->get('wc_product_item_id');
937 1337 }
938 1338
939 - if ($entry->get('ID')) {
1339 + $zapier['uid'] = $entry->get('uid');
1340 + $zapier['name'] = $template->get('name');
1341 + $zapier['format'] = $template->get('format');
1342 + $zapier['url'] = $url;
940 1343
941 - $pdf_url = esc_url_raw(add_query_arg(array(
942 - 'page' => 'e2pdf-download',
943 - 'uid' => $entry->get('uid'),
944 - 'saveName' => $template->get('name') ? $template->get('name') . ".pdf" : $template->extension()->render($template->get_filename(), 'value') . ".pdf"
945 - ), site_url('/')
946 - ));
1344 + $data = apply_filters(
1345 + 'e2pdf_model_shortcode_e2pdf_zapier_data',
1346 + array_merge(
1347 + $zapier, $attributes->get('arguments')
1348 + ), $atts
1349 + );
947 1350
948 - $file = urlencode($pdf_url);
949 - if (!empty($viewer_options)) {
950 - $file .= '#' . implode('&', $viewer_options);
951 - }
1351 + $zapier_args = apply_filters(
1352 + 'e2pdf_model_shortcode_e2pdf_zapier_args',
1353 + [
1354 + 'method' => 'POST',
1355 + 'body' => json_encode($data), // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
1356 + 'headers' => [
1357 + 'Content-Type' => $content_type,
1358 + ],
1359 + ], $atts
1360 + );
952 1361
953 - $url = plugins_url('assets/pdf.js/web/viewer.html?file=' . $file, $this->helper->get('plugin_file_path'));
954 - $response = "<iframe class='" . implode(" ", $classes) . "' width='{$width}' height='{$height}' src='{$url}'></iframe>";
1362 + $result = [];
1363 + if ($attributes->get('webhook') !== 'local') {
1364 + $result = wp_remote_post($attributes->get('webhook'), $zapier_args);
955 1365 }
1366 +
1367 + $response = apply_filters('e2pdf_model_shortcode_e2pdf_zapier_response', $response, $result, $atts, $data);
956 1368 }
957 1369 }
1370 +
958 1371 return $response;
959 1372 }
960 1373
961 - /**
962 - * [e2pdf-adobesign] shortcode
963 - *
964 - * @param array $atts - Attributes
965 - */
966 - function e2pdf_adobesign($atts = array()) {
1374 + // e2pdf-view
1375 + public function e2pdf_view($atts = []) {
967 1376
968 - $template_id = isset($atts['id']) ? (int) $atts['id'] : 0;
1377 + if (function_exists('vc_is_page_editable') && vc_is_page_editable()) {
1378 + return '[e2pdf-view]';
1379 + }
969 1380
970 - $args = array();
971 - foreach ($atts as $att_key => $att_value) {
972 - if (substr($att_key, 0, 3) === "arg") {
973 - $args[$att_key] = $att_value;
974 - }
1381 + $response = '';
1382 + $name = '';
1383 +
1384 + $atts = apply_filters('e2pdf_model_shortcode_e2pdf_view_atts', $atts);
1385 + $attributes = (new Helper_E2pdf_Atts())->load($atts);
1386 +
1387 + $style = $attributes->get('style');
1388 +
1389 + $app_options = [];
1390 + if ($attributes->get('resolution') !== false) {
1391 + $app_options[] = 'resolution="' . esc_attr($attributes->get('resolution')) . '"';
975 1392 }
1393 + if ($attributes->get('cursor') !== false) {
1394 + $app_options[] = 'cursor="' . esc_attr($attributes->get('cursor')) . '"';
1395 + }
1396 + if ($attributes->get('scroll') !== false) {
1397 + $app_options[] = 'scroll="' . esc_attr($attributes->get('scroll')) . '"';
1398 + }
1399 + if ($attributes->get('spread') !== false) {
1400 + $app_options[] = 'spread="' . esc_attr($attributes->get('spread')) . '"';
1401 + }
976 1402
977 - $response = '';
1403 + $viewer_options = [];
1404 + if ($attributes->get('page') !== false) {
1405 + $viewer_options[] = 'page=' . $attributes->get('page');
1406 + }
978 1407
979 - if (!array_key_exists('apply', $atts) || !array_key_exists('dataset', $atts) || !$template_id) {
980 - return $response;
1408 + if ($attributes->get('zoom') !== false) {
1409 + $viewer_options[] = 'zoom=' . $attributes->get('zoom');
981 1410 }
982 1411
983 - $dataset = $atts['dataset'];
984 - $template = new Model_E2pdf_Template();
985 - if ($template->load($template_id)) {
986 - $uid_params = array();
987 - $uid_params['template_id'] = $template_id;
988 - $uid_params['dataset'] = $dataset;
1412 + if ($attributes->get('nameddest') !== false) {
1413 + $viewer_options[] = 'nameddest=' . $attributes->get('nameddest');
1414 + }
989 1415
990 - $template->extension()->set('dataset', $dataset);
1416 + if ($attributes->get('pagemode') !== false) {
1417 + $attributes->set('sidebar', $attributes->get('pagemode'));
1418 + }
991 1419
992 - $options = array();
993 - $options = apply_filters('e2pdf_model_shortcode_extension_options', $options, $template);
994 - $options = apply_filters('e2pdf_model_shortcode_e2pdf_adobesign_extension_options', $options, $template);
1420 + if ($attributes->get('sidebar') !== false) {
1421 + $viewer_options[] = 'pagemode=' . $attributes->get('sidebar');
1422 + }
995 1423
996 - foreach ($options as $option_key => $option_value) {
997 - $template->extension()->set($option_key, $option_value);
1424 + $classes = $attributes->get('class');
1425 + $classes[] = 'e2pdf-view';
1426 +
1427 + if ($attributes->get('preload')) {
1428 + $classes[] = 'e2pdf-preload';
1429 + }
1430 +
1431 + if ($attributes->get('responsive')) {
1432 + $classes[] = 'e2pdf-responsive';
1433 + if ($attributes->get('responsive') === 'page') {
1434 + $classes[] = 'e2pdf-responsive-page';
998 1435 }
1436 + }
999 1437
1000 - if ($template->extension()->verify()) {
1438 + if ($attributes->get('single_page_mode')) {
1439 + $classes[] = 'e2pdf-single-page-mode';
1440 + }
1001 1441
1002 - if (array_key_exists('inline', $atts)) {
1003 - $inline = $atts['inline'] == 'true' ? 1 : 0;
1004 - $uid_params['inline'] = $inline;
1442 + if ($attributes->get('theme', 'dark') === 'dark') {
1443 + $classes[] = 'e2pdf-dark-theme';
1444 + }
1445 +
1446 + if ($attributes->get('hide')) {
1447 + $hidden = array_map('trim', explode(',', $attributes->get('hide')));
1448 + foreach ($hidden as $item) {
1449 + if ($item !== '') {
1450 + $classes[] = 'e2pdf-hide-' . $item;
1005 1451 }
1452 + }
1453 + }
1006 1454
1007 - if (array_key_exists('flatten', $atts)) {
1008 - $flatten = (int) $atts['flatten'];
1009 - $uid_params['flatten'] = $flatten;
1010 - $template->set('flatten', $flatten);
1455 + if ($attributes->get('background') !== false) {
1456 + $classes[] = 'e2pdf-hide-background';
1457 + }
1458 +
1459 + if ($attributes->get('border') !== false) {
1460 + array_unshift($style, 'border:' . $attributes->get('border'));
1461 + }
1462 +
1463 + if ($attributes->get('background') !== false) {
1464 + array_unshift($style, 'background:' . $attributes->get('background'));
1465 + }
1466 +
1467 + if ($attributes->get('pdf') || $attributes->get('attachment_id') || $attributes->get('file_id')) {
1468 + $pdf = $attributes->get('pdf');
1469 + if ($pdf && filter_var($pdf, FILTER_VALIDATE_URL)) {
1470 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
1471 + $file = urlencode($pdf);
1472 + if (!empty($viewer_options)) {
1473 + $file .= '#' . implode('&', $viewer_options);
1011 1474 }
1475 + switch ($attributes->get('output')) {
1476 + case 'url':
1477 + case 'url_raw':
1478 + case 'url_encode':
1479 + $viewer_url = add_query_arg(
1480 + [
1481 + 'class' => implode(';', $classes),
1482 + 'file' => $file,
1483 + ],
1484 + $attributes->get('viewer', plugins_url('assets/pdf.js/web/viewer.html', $this->helper->get('plugin_file_path')))
1485 + );
1486 + if ($attributes->get('output') === 'url') {
1487 + $response = esc_url($viewer_url);
1488 + } elseif ($attributes->get('output') === 'url_raw') {
1489 + $response = esc_url_raw($viewer_url);
1490 + } elseif ($attributes->get('output') === 'url_encode') {
1491 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
1492 + $response = urlencode(esc_url_raw($viewer_url));
1493 + }
1494 + break;
1495 + default:
1496 + $viewer_url = esc_url(
1497 + add_query_arg(
1498 + [
1499 + 'file' => $file,
1500 + ],
1501 + $attributes->get('viewer', plugins_url('assets/pdf.js/web/viewer.html', $this->helper->get('plugin_file_path')))
1502 + )
1503 + );
1012 1504
1013 - if (array_key_exists('format', $atts)) {
1014 - $format = $atts['format'];
1015 - $uid_params['format'] = $format;
1016 - $template->set('format', $format);
1505 + $attrs = [
1506 + 'onload="e2pdfViewer.iframeLoad(this)"',
1507 + 'name="' . md5($this->helper->get('version')) . '"',
1508 + 'style="' . esc_attr(implode(';', $style)) . '"',
1509 + 'class="' . esc_attr(implode(' ', $classes)) . '"',
1510 + implode(' ', $app_options),
1511 + 'width="' . esc_attr($attributes->get('width', '100%')) . '"',
1512 + 'height="' . esc_attr($attributes->get('height', '500')) . '"',
1513 + ];
1514 +
1515 + if ($attributes->get('preload')) {
1516 + $attrs[] = 'preload="' . $viewer_url . '"';
1517 + } else {
1518 + $attrs[] = 'src="' . $viewer_url . '"';
1519 + }
1520 + $response = '<iframe ' . implode(' ', $attrs) . '></iframe>';
1521 + break;
1017 1522 }
1018 -
1019 - if (array_key_exists('password', $atts)) {
1020 - if (!array_key_exists('filter', $atts)) {
1021 - $password = $template->extension()->render($atts['password'], 'value');
1523 + } else {
1524 + $downloadable = false;
1525 + if ($attributes->get('file_id')) {
1526 + $pdf = (new Model_E2pdf_Gdrive())->exists($attributes->get('file_id'));
1527 + if ($pdf) {
1528 + $downloadable = true;
1529 + }
1530 + } else {
1531 + if ($attributes->get('attachment_id')) {
1532 + $pdf = get_attached_file($attributes->get('attachment_id'));
1022 1533 } else {
1023 - $password = $atts['password'];
1534 + $pdf = $this->helper->load('convert')->to_file_dir($pdf);
1024 1535 }
1025 - $uid_params['password'] = $password;
1026 - $template->set('password', $password);
1536 + if (strpos($pdf, '/') !== 0 && !preg_match('/^[A-Za-z]:/', $pdf)) {
1537 + $pdf = ABSPATH . $pdf;
1538 + }
1539 + $downloadable = !$this->helper->load('filter')->is_stream($pdf) && file_exists($pdf) && $this->helper->load('filter')->is_downloadable($pdf);
1540 + }
1541 + if (!$downloadable) {
1542 + return $response;
1543 + }
1544 + $entry = new Model_E2pdf_Entry();
1545 + if ($attributes->get('attachment_id')) {
1546 + $entry->set_data('attachment_id', $attributes->get('attachment_id'));
1027 1547 } else {
1028 - $template->set('password', $template->extension()->render($template->get('password'), 'value'));
1548 + $entry->set_data('pdf', $pdf);
1029 1549 }
1030 1550
1031 - if (array_key_exists('meta_title', $atts)) {
1032 - if (!array_key_exists('filter', $atts)) {
1033 - $meta_title = $template->extension()->render($atts['meta_title'], 'value');
1034 - } else {
1035 - $meta_title = $atts['meta_title'];
1551 + $inline = '0';
1552 + if ($attributes->get('inline') !== false) {
1553 + $inline = $attributes->get('inline');
1554 + $entry->set_data('inline', $inline);
1555 + }
1556 +
1557 + if ($attributes->get('name') !== false) {
1558 + $name = $attributes->get('name');
1559 + $entry->set_data('name', $name);
1560 + }
1561 +
1562 + if ($attributes->get('local')) {
1563 + $ext = pathinfo($pdf, PATHINFO_EXTENSION);
1564 + $url = $attributes->get('attachment_id') ? wp_get_attachment_url($attributes->get('attachment_id')) : $this->helper->get_frontend_local_pdf_url($pdf);
1565 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_view_pdf_url', $url, $atts);
1566 + if ($ext == 'pdf') {
1567 + $file = $url;
1568 + if (!empty($viewer_options)) {
1569 + $file .= '#' . implode('&', $viewer_options);
1570 + }
1571 + switch ($attributes->get('output')) {
1572 + case 'url':
1573 + case 'url_raw':
1574 + case 'url_encode':
1575 + $viewer_url = add_query_arg(
1576 + [
1577 + 'class' => implode(';', $classes),
1578 + 'file' => $file,
1579 + ],
1580 + $attributes->get('viewer', plugins_url('assets/pdf.js/web/viewer.html', $this->helper->get('plugin_file_path')))
1581 + );
1582 + if ($attributes->get('output') === 'url') {
1583 + $response = esc_url($viewer_url);
1584 + } elseif ($attributes->get('output') === 'url_raw') {
1585 + $response = esc_url_raw($viewer_url);
1586 + } elseif ($attributes->get('output') === 'url_encode') {
1587 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
1588 + $response = urlencode(esc_url_raw($viewer_url));
1589 + }
1590 + break;
1591 + default:
1592 + $viewer_url = esc_url(
1593 + add_query_arg(
1594 + [
1595 + 'file' => $file,
1596 + ],
1597 + $attributes->get('viewer', plugins_url('assets/pdf.js/web/viewer.html', $this->helper->get('plugin_file_path')))
1598 + )
1599 + );
1600 + $attrs = [
1601 + 'onload="e2pdfViewer.iframeLoad(this)"',
1602 + 'name="' . md5($this->helper->get('version')) . '"',
1603 + 'style="' . esc_attr(implode(';', $style)) . '"',
1604 + 'class="' . esc_attr(implode(' ', $classes)) . '"',
1605 + implode(' ', $app_options),
1606 + 'width="' . esc_attr($attributes->get('width', '100%')) . '"',
1607 + 'height="' . esc_attr($attributes->get('height', '500')) . '"',
1608 + ];
1609 +
1610 + if ($attributes->get('preload')) {
1611 + $attrs[] = 'preload="' . $viewer_url . '"';
1612 + } else {
1613 + $attrs[] = 'src="' . $viewer_url . '"';
1614 + }
1615 + $response = '<iframe ' . implode(' ', $attrs) . '></iframe>';
1616 + break;
1617 + }
1618 + } elseif ($ext == 'jpg') {
1619 + switch ($attributes->get('output')) {
1620 + case 'url':
1621 + $response = esc_url($url);
1622 + break;
1623 + case 'url_raw':
1624 + $response = esc_url_raw($url);
1625 + break;
1626 + case 'url_encode':
1627 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
1628 + $response = urlencode(esc_url_raw($url));
1629 + break;
1630 + default:
1631 + $url = esc_url($url);
1632 + if ($attributes->get('preload', 'true')) {
1633 + $classes[] = 'e2pdf-preload';
1634 + if ($attributes->get('theme', 'dark') === 'dark') {
1635 + $style[] = 'background: url(\'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0OCIgaGVpZ2h0PSI0OCIgdmlld0JveD0iMCAwIDI0IDI0Ij48ZyBzdHJva2U9IndoaXRlIj48Y2lyY2xlIGN4PSIxMiIgY3k9IjEyIiByPSI5LjUiIGZpbGw9Im5vbmUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLXdpZHRoPSIzIj48YW5pbWF0ZSBhdHRyaWJ1dGVOYW1lPSJzdHJva2UtZGFzaGFycmF5IiBjYWxjTW9kZT0ic3BsaW5lIiBkdXI9IjEuNXMiIGtleVNwbGluZXM9IjAuNDIsMCwwLjU4LDE7MC40MiwwLDAuNTgsMTswLjQyLDAsMC41OCwxIiBrZXlUaW1lcz0iMDswLjQ3NTswLjk1OzEiIHJlcGVhdENvdW50PSJpbmRlZmluaXRlIiB2YWx1ZXM9IjAgMTUwOzQyIDE1MDs0MiAxNTA7NDIgMTUwIi8+PGFuaW1hdGUgYXR0cmlidXRlTmFtZT0ic3Ryb2tlLWRhc2hvZmZzZXQiIGNhbGNNb2RlPSJzcGxpbmUiIGR1cj0iMS41cyIga2V5U3BsaW5lcz0iMC40MiwwLDAuNTgsMTswLjQyLDAsMC41OCwxOzAuNDIsMCwwLjU4LDEiIGtleVRpbWVzPSIwOzAuNDc1OzAuOTU7MSIgcmVwZWF0Q291bnQ9ImluZGVmaW5pdGUiIHZhbHVlcz0iMDstMTY7LTU5Oy01OSIvPjwvY2lyY2xlPjxhbmltYXRlVHJhbnNmb3JtIGF0dHJpYnV0ZU5hbWU9InRyYW5zZm9ybSIgZHVyPSIycyIgcmVwZWF0Q291bnQ9ImluZGVmaW5pdGUiIHR5cGU9InJvdGF0ZSIgdmFsdWVzPSIwIDEyIDEyOzM2MCAxMiAxMiIvPjwvZz48L3N2Zz4=\') no-repeat center center';
1636 + } else {
1637 + $style[] = 'background: url(\'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0OCIgaGVpZ2h0PSI0OCIgdmlld0JveD0iMCAwIDI0IDI0Ij48ZyBzdHJva2U9ImJsYWNrIj48Y2lyY2xlIGN4PSIxMiIgY3k9IjEyIiByPSI5LjUiIGZpbGw9Im5vbmUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLXdpZHRoPSIzIj48YW5pbWF0ZSBhdHRyaWJ1dGVOYW1lPSJzdHJva2UtZGFzaGFycmF5IiBjYWxjTW9kZT0ic3BsaW5lIiBkdXI9IjEuNXMiIGtleVNwbGluZXM9IjAuNDIsMCwwLjU4LDE7MC40MiwwLDAuNTgsMTswLjQyLDAsMC41OCwxIiBrZXlUaW1lcz0iMDswLjQ3NTswLjk1OzEiIHJlcGVhdENvdW50PSJpbmRlZmluaXRlIiB2YWx1ZXM9IjAgMTUwOzQyIDE1MDs0MiAxNTA7NDIgMTUwIi8+PGFuaW1hdGUgYXR0cmlidXRlTmFtZT0ic3Ryb2tlLWRhc2hvZmZzZXQiIGNhbGNNb2RlPSJzcGxpbmUiIGR1cj0iMS41cyIga2V5U3BsaW5lcz0iMC40MiwwLDAuNTgsMTswLjQyLDAsMC41OCwxOzAuNDIsMCwwLjU4LDEiIGtleVRpbWVzPSIwOzAuNDc1OzAuOTU7MSIgcmVwZWF0Q291bnQ9ImluZGVmaW5pdGUiIHZhbHVlcz0iMDstMTY7LTU5Oy01OSIvPjwvY2lyY2xlPjxhbmltYXRlVHJhbnNmb3JtIGF0dHJpYnV0ZU5hbWU9InRyYW5zZm9ybSIgZHVyPSIycyIgcmVwZWF0Q291bnQ9ImluZGVmaW5pdGUiIHR5cGU9InJvdGF0ZSIgdmFsdWVzPSIwIDEyIDEyOzM2MCAxMiAxMiIvPjwvZz48L3N2Zz4=\') no-repeat center center';
1638 + }
1639 + }
1640 + $attrs = [
1641 + 'style="' . esc_attr(implode(';', $style)) . '"',
1642 + 'class="' . esc_attr(implode(' ', $classes)) . '"',
1643 + 'width="' . esc_attr($attributes->get('width', '100%')) . '"',
1644 + ];
1645 + if ($attributes->get('preload', 'true')) {
1646 + $attrs[] = 'onload="e2pdfViewer.imageLoad(this)"';
1647 + $attrs[] = 'preload="' . $url . '"';
1648 + $attrs[] = 'src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mM8VA8AAgkBQ6KtxDkAAAAASUVORK5CYII="';
1649 + } else {
1650 + $attrs[] = 'src="' . $url . '"';
1651 + }
1652 + $response = '<img ' . implode(' ', $attrs) . '>';
1653 + break;
1654 + }
1036 1655 }
1037 - $uid_params['meta_title'] = $meta_title;
1038 - $template->set('meta_title', $meta_title);
1039 1656 } else {
1040 - $template->set('meta_title', $template->extension()->render($template->get('meta_title'), 'value'));
1041 - }
1657 + if (!$entry->load_by_uid()) {
1658 + $entry->save();
1659 + }
1042 1660
1043 - if (array_key_exists('meta_subject', $atts)) {
1044 - if (!array_key_exists('filter', $atts)) {
1045 - $meta_subject = $template->extension()->render($atts['meta_subject'], 'value');
1046 - } else {
1047 - $meta_subject = $atts['meta_subject'];
1661 + if ($entry->get('ID')) {
1662 + $ext = pathinfo($pdf, PATHINFO_EXTENSION);
1663 + if (!$name) {
1664 + $name = basename($pdf, '.' . $ext);
1665 + }
1666 +
1667 + $url_data = [
1668 + 'page' => 'e2pdf-download',
1669 + 'uid' => $entry->get('uid'),
1670 + 'v' => $this->helper->get('version'),
1671 + ];
1672 + if ($ext == 'pdf') {
1673 + $url_data['saveName'] = $name;
1674 + }
1675 + $url_data = apply_filters('e2pdf_model_shortcode_url_data', $url_data, $atts);
1676 + $url_data = apply_filters('e2pdf_model_shortcode_e2pdf_viewer_url_data', $url_data, $atts);
1677 +
1678 + $url = esc_url_raw(
1679 + $this->helper->get_frontend_pdf_url(
1680 + $url_data, $attributes->get('site_url'),
1681 + [
1682 + 'e2pdf_model_shortcode_site_url',
1683 + 'e2pdf_model_shortcode_e2pdf_view_site_url',
1684 + ]
1685 + )
1686 + );
1687 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_view_pdf_url', $url, $atts);
1688 +
1689 + if ($ext == 'pdf') {
1690 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
1691 + $file = urlencode($url);
1692 + if (!empty($viewer_options)) {
1693 + $file .= '#' . implode('&', $viewer_options);
1694 + }
1695 + switch ($attributes->get('output')) {
1696 + case 'url':
1697 + case 'url_raw':
1698 + case 'url_encode':
1699 + $viewer_url = add_query_arg(
1700 + [
1701 + 'class' => implode(';', $classes),
1702 + 'file' => $file,
1703 + ],
1704 + $attributes->get('viewer', plugins_url('assets/pdf.js/web/viewer.html', $this->helper->get('plugin_file_path')))
1705 + );
1706 + if ($attributes->get('output') === 'url') {
1707 + $response = esc_url($viewer_url);
1708 + } elseif ($attributes->get('output') === 'url_raw') {
1709 + $response = esc_url_raw($viewer_url);
1710 + } elseif ($attributes->get('output') === 'url_encode') {
1711 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
1712 + $response = urlencode(esc_url_raw($viewer_url));
1713 + }
1714 + break;
1715 + default:
1716 + $viewer_url = esc_url(
1717 + add_query_arg(
1718 + [
1719 + 'file' => $file,
1720 + ],
1721 + $attributes->get('viewer', plugins_url('assets/pdf.js/web/viewer.html', $this->helper->get('plugin_file_path')))
1722 + )
1723 + );
1724 + $attrs = [
1725 + 'onload="e2pdfViewer.iframeLoad(this)"',
1726 + 'name="' . md5($this->helper->get('version')) . '"',
1727 + 'style="' . esc_attr(implode(';', $style)) . '"',
1728 + 'class="' . esc_attr(implode(' ', $classes)) . '"',
1729 + implode(' ', $app_options),
1730 + 'width="' . esc_attr($attributes->get('width', '100%')) . '"',
1731 + 'height="' . esc_attr($attributes->get('height', '500')) . '"',
1732 + ];
1733 +
1734 + if ($attributes->get('preload')) {
1735 + $attrs[] = 'preload="' . $viewer_url . '"';
1736 + } else {
1737 + $attrs[] = 'src="' . $viewer_url . '"';
1738 + }
1739 + $response = '<iframe ' . implode(' ', $attrs) . '></iframe>';
1740 + break;
1741 + }
1742 + } elseif ($ext == 'jpg') {
1743 + switch ($attributes->get('output')) {
1744 + case 'url':
1745 + $response = esc_url($url);
1746 + break;
1747 + case 'url_raw':
1748 + $response = esc_url_raw($url);
1749 + break;
1750 + case 'url_encode':
1751 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
1752 + $response = urlencode(esc_url_raw($url));
1753 + break;
1754 + default:
1755 + $url = esc_url($url);
1756 + if ($attributes->get('preload', 'true')) {
1757 + $classes[] = 'e2pdf-preload';
1758 + if ($attributes->get('theme', 'dark') === 'dark') {
1759 + $style[] = 'background: url(\'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0OCIgaGVpZ2h0PSI0OCIgdmlld0JveD0iMCAwIDI0IDI0Ij48ZyBzdHJva2U9IndoaXRlIj48Y2lyY2xlIGN4PSIxMiIgY3k9IjEyIiByPSI5LjUiIGZpbGw9Im5vbmUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLXdpZHRoPSIzIj48YW5pbWF0ZSBhdHRyaWJ1dGVOYW1lPSJzdHJva2UtZGFzaGFycmF5IiBjYWxjTW9kZT0ic3BsaW5lIiBkdXI9IjEuNXMiIGtleVNwbGluZXM9IjAuNDIsMCwwLjU4LDE7MC40MiwwLDAuNTgsMTswLjQyLDAsMC41OCwxIiBrZXlUaW1lcz0iMDswLjQ3NTswLjk1OzEiIHJlcGVhdENvdW50PSJpbmRlZmluaXRlIiB2YWx1ZXM9IjAgMTUwOzQyIDE1MDs0MiAxNTA7NDIgMTUwIi8+PGFuaW1hdGUgYXR0cmlidXRlTmFtZT0ic3Ryb2tlLWRhc2hvZmZzZXQiIGNhbGNNb2RlPSJzcGxpbmUiIGR1cj0iMS41cyIga2V5U3BsaW5lcz0iMC40MiwwLDAuNTgsMTswLjQyLDAsMC41OCwxOzAuNDIsMCwwLjU4LDEiIGtleVRpbWVzPSIwOzAuNDc1OzAuOTU7MSIgcmVwZWF0Q291bnQ9ImluZGVmaW5pdGUiIHZhbHVlcz0iMDstMTY7LTU5Oy01OSIvPjwvY2lyY2xlPjxhbmltYXRlVHJhbnNmb3JtIGF0dHJpYnV0ZU5hbWU9InRyYW5zZm9ybSIgZHVyPSIycyIgcmVwZWF0Q291bnQ9ImluZGVmaW5pdGUiIHR5cGU9InJvdGF0ZSIgdmFsdWVzPSIwIDEyIDEyOzM2MCAxMiAxMiIvPjwvZz48L3N2Zz4=\') no-repeat center center';
1760 + } else {
1761 + $style[] = 'background: url(\'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0OCIgaGVpZ2h0PSI0OCIgdmlld0JveD0iMCAwIDI0IDI0Ij48ZyBzdHJva2U9ImJsYWNrIj48Y2lyY2xlIGN4PSIxMiIgY3k9IjEyIiByPSI5LjUiIGZpbGw9Im5vbmUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLXdpZHRoPSIzIj48YW5pbWF0ZSBhdHRyaWJ1dGVOYW1lPSJzdHJva2UtZGFzaGFycmF5IiBjYWxjTW9kZT0ic3BsaW5lIiBkdXI9IjEuNXMiIGtleVNwbGluZXM9IjAuNDIsMCwwLjU4LDE7MC40MiwwLDAuNTgsMTswLjQyLDAsMC41OCwxIiBrZXlUaW1lcz0iMDswLjQ3NTswLjk1OzEiIHJlcGVhdENvdW50PSJpbmRlZmluaXRlIiB2YWx1ZXM9IjAgMTUwOzQyIDE1MDs0MiAxNTA7NDIgMTUwIi8+PGFuaW1hdGUgYXR0cmlidXRlTmFtZT0ic3Ryb2tlLWRhc2hvZmZzZXQiIGNhbGNNb2RlPSJzcGxpbmUiIGR1cj0iMS41cyIga2V5U3BsaW5lcz0iMC40MiwwLDAuNTgsMTswLjQyLDAsMC41OCwxOzAuNDIsMCwwLjU4LDEiIGtleVRpbWVzPSIwOzAuNDc1OzAuOTU7MSIgcmVwZWF0Q291bnQ9ImluZGVmaW5pdGUiIHZhbHVlcz0iMDstMTY7LTU5Oy01OSIvPjwvY2lyY2xlPjxhbmltYXRlVHJhbnNmb3JtIGF0dHJpYnV0ZU5hbWU9InRyYW5zZm9ybSIgZHVyPSIycyIgcmVwZWF0Q291bnQ9ImluZGVmaW5pdGUiIHR5cGU9InJvdGF0ZSIgdmFsdWVzPSIwIDEyIDEyOzM2MCAxMiAxMiIvPjwvZz48L3N2Zz4=\') no-repeat center center';
1762 + }
1763 + }
1764 + $attrs = [
1765 + 'style="' . esc_attr(implode(';', $style)) . '"',
1766 + 'class="' . esc_attr(implode(' ', $classes)) . '"',
1767 + 'width="' . esc_attr($attributes->get('width', '100%')) . '"',
1768 + ];
1769 + if ($attributes->get('preload', 'true')) {
1770 + $attrs[] = 'onload="e2pdfViewer.imageLoad(this)"';
1771 + $attrs[] = 'preload="' . $url . '"';
1772 + $attrs[] = 'src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mM8VA8AAgkBQ6KtxDkAAAAASUVORK5CYII="';
1773 + } else {
1774 + $attrs[] = 'src="' . $url . '"';
1775 + }
1776 + $response = '<img ' . implode(' ', $attrs) . '>';
1777 + break;
1778 + }
1779 + }
1048 1780 }
1049 - $uid_params['meta_subject'] = $meta_subject;
1050 - $template->set('meta_subject', $meta_subject);
1051 - } else {
1052 - $template->set('meta_subject', $template->extension()->render($template->get('meta_subject'), 'value'));
1053 1781 }
1782 + }
1783 + return $response;
1784 + }
1054 1785
1055 - if (array_key_exists('meta_author', $atts)) {
1056 - if (!array_key_exists('filter', $atts)) {
1057 - $meta_author = $template->extension()->render($atts['meta_author'], 'value');
1058 - } else {
1059 - $meta_author = $atts['meta_author'];
1786 + // phpcs:disable WordPress.Security.NonceVerification.Recommended
1787 + if (isset($_GET['e2pdf-hash']) && !$attributes->get('dataset')) {
1788 + $hash_id = sanitize_text_field(wp_unslash($_GET['e2pdf-hash']));
1789 + $attributes->set('dataset', get_transient('e2pdf_hash_' . $hash_id));
1790 + if ($attributes->get('dataset') && apply_filters('e2pdf_hash_clear', true, 'shortcode', $atts) && has_action('shutdown', [$this, 'action_e2pdf_hash_clear']) === false) {
1791 + add_action('shutdown', [$this, 'action_e2pdf_hash_clear']);
1792 + }
1793 + }
1794 + // phpcs:enable
1795 +
1796 + if (!$attributes->get('id') || (!$attributes->get('dataset') && !$attributes->get('dataset2'))) {
1797 + return $response;
1798 + }
1799 +
1800 + $template = new Model_E2pdf_Template();
1801 + if (!$template->load($attributes->get('id'), false)) {
1802 + return $response;
1803 + }
1804 +
1805 + $entry = new Model_E2pdf_Entry();
1806 +
1807 + $template->extension()->patch('template_id', $attributes->get('id'), $entry);
1808 + $template->extension()->patch('dataset', $attributes->get('dataset'), $entry);
1809 + $template->extension()->patch('dataset2', $attributes->get('dataset2'), $entry);
1810 + $template->extension()->patch('wc_order_id', $attributes->get('wc_order_id'), $entry);
1811 + $template->extension()->patch('wc_product_item_id', $attributes->get('wc_product_item_id'), $entry);
1812 + // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
1813 + if (!($template->get('extension') === 'wordpress' && $template->get('item') === '-3')) {
1814 + $template->extension()->patch('user_id', $attributes->get('user_id'), $entry);
1815 + }
1816 + $template->extension()->patch('args', $attributes->get('arguments'), $entry);
1817 + $template->extension()->patch('storing_engine', $template->extension()->get_storing_engine(), $entry);
1818 +
1819 + $options = apply_filters('e2pdf_model_shortcode_extension_options', [], $template);
1820 + $options = apply_filters('e2pdf_model_shortcode_e2pdf_view_extension_options', $options, $template);
1821 + foreach ($options as $option_key => $option_value) {
1822 + $template->extension()->set($option_key, $option_value);
1823 + }
1824 +
1825 + if ($template->extension()->verify() && $this->process_shortcode('e2pdf_view', $template, $attributes)) {
1826 +
1827 + $template->patch('inline', $attributes->get('inline'), $entry, $attributes->get('filter'));
1828 + $template->patch('flatten', $attributes->get('flatten'), $entry, $attributes->get('filter'));
1829 + $template->patch('format', $attributes->get('format'), $entry, $attributes->get('filter'));
1830 + $template->patch('password', $attributes->get('password'), $entry, $attributes->get('filter'));
1831 + $template->patch('dpdf', $attributes->get('dpdf'), $entry, $attributes->get('filter'));
1832 + $template->patch('name', $attributes->get('name'), $entry, $attributes->get('filter'));
1833 + $template->patch('meta_title', $attributes->get('meta_title'), $entry, $attributes->get('filter'));
1834 + $template->patch('meta_subject', $attributes->get('meta_subject'), $entry, $attributes->get('filter'));
1835 + $template->patch('meta_author', $attributes->get('meta_author'), $entry, $attributes->get('filter'));
1836 + $template->patch('meta_keywords', $attributes->get('meta_keywords'), $entry, $attributes->get('filter'));
1837 +
1838 + if (!$entry->load_by_uid()) {
1839 + $entry->save();
1840 + }
1841 +
1842 + if ($entry->get('ID')) {
1843 + if ($template->get('format') == 'jpg') {
1844 +
1845 + $url_data = [
1846 + 'page' => 'e2pdf-download',
1847 + 'uid' => $entry->get('uid'),
1848 + 'v' => $this->helper->get('version'),
1849 + ];
1850 + $url_data = apply_filters('e2pdf_model_shortcode_url_data', $url_data, $atts);
1851 + $url_data = apply_filters('e2pdf_model_shortcode_e2pdf_viewer_url_data', $url_data, $atts);
1852 +
1853 + $url = esc_url_raw(
1854 + $this->helper->get_frontend_pdf_url(
1855 + $url_data, $attributes->get('site_url'),
1856 + [
1857 + 'e2pdf_model_shortcode_site_url',
1858 + 'e2pdf_model_shortcode_e2pdf_view_site_url',
1859 + ]
1860 + )
1861 + );
1862 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_view_pdf_url', $url, $atts);
1863 + switch ($attributes->get('output')) {
1864 + case 'url':
1865 + $response = esc_url($url);
1866 + break;
1867 + case 'url_raw':
1868 + $response = esc_url_raw($url);
1869 + break;
1870 + case 'url_encode':
1871 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
1872 + $response = urlencode(esc_url_raw($url));
1873 + break;
1874 + default:
1875 + $url = esc_url($url);
1876 + if ($attributes->get('preload', 'true')) {
1877 + $classes[] = 'e2pdf-preload';
1878 + if ($attributes->get('theme', 'dark') === 'dark') {
1879 + $style[] = 'background: url(\'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0OCIgaGVpZ2h0PSI0OCIgdmlld0JveD0iMCAwIDI0IDI0Ij48ZyBzdHJva2U9IndoaXRlIj48Y2lyY2xlIGN4PSIxMiIgY3k9IjEyIiByPSI5LjUiIGZpbGw9Im5vbmUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLXdpZHRoPSIzIj48YW5pbWF0ZSBhdHRyaWJ1dGVOYW1lPSJzdHJva2UtZGFzaGFycmF5IiBjYWxjTW9kZT0ic3BsaW5lIiBkdXI9IjEuNXMiIGtleVNwbGluZXM9IjAuNDIsMCwwLjU4LDE7MC40MiwwLDAuNTgsMTswLjQyLDAsMC41OCwxIiBrZXlUaW1lcz0iMDswLjQ3NTswLjk1OzEiIHJlcGVhdENvdW50PSJpbmRlZmluaXRlIiB2YWx1ZXM9IjAgMTUwOzQyIDE1MDs0MiAxNTA7NDIgMTUwIi8+PGFuaW1hdGUgYXR0cmlidXRlTmFtZT0ic3Ryb2tlLWRhc2hvZmZzZXQiIGNhbGNNb2RlPSJzcGxpbmUiIGR1cj0iMS41cyIga2V5U3BsaW5lcz0iMC40MiwwLDAuNTgsMTswLjQyLDAsMC41OCwxOzAuNDIsMCwwLjU4LDEiIGtleVRpbWVzPSIwOzAuNDc1OzAuOTU7MSIgcmVwZWF0Q291bnQ9ImluZGVmaW5pdGUiIHZhbHVlcz0iMDstMTY7LTU5Oy01OSIvPjwvY2lyY2xlPjxhbmltYXRlVHJhbnNmb3JtIGF0dHJpYnV0ZU5hbWU9InRyYW5zZm9ybSIgZHVyPSIycyIgcmVwZWF0Q291bnQ9ImluZGVmaW5pdGUiIHR5cGU9InJvdGF0ZSIgdmFsdWVzPSIwIDEyIDEyOzM2MCAxMiAxMiIvPjwvZz48L3N2Zz4=\') no-repeat center center';
1880 + } else {
1881 + $style[] = 'background: url(\'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0OCIgaGVpZ2h0PSI0OCIgdmlld0JveD0iMCAwIDI0IDI0Ij48ZyBzdHJva2U9ImJsYWNrIj48Y2lyY2xlIGN4PSIxMiIgY3k9IjEyIiByPSI5LjUiIGZpbGw9Im5vbmUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLXdpZHRoPSIzIj48YW5pbWF0ZSBhdHRyaWJ1dGVOYW1lPSJzdHJva2UtZGFzaGFycmF5IiBjYWxjTW9kZT0ic3BsaW5lIiBkdXI9IjEuNXMiIGtleVNwbGluZXM9IjAuNDIsMCwwLjU4LDE7MC40MiwwLDAuNTgsMTswLjQyLDAsMC41OCwxIiBrZXlUaW1lcz0iMDswLjQ3NTswLjk1OzEiIHJlcGVhdENvdW50PSJpbmRlZmluaXRlIiB2YWx1ZXM9IjAgMTUwOzQyIDE1MDs0MiAxNTA7NDIgMTUwIi8+PGFuaW1hdGUgYXR0cmlidXRlTmFtZT0ic3Ryb2tlLWRhc2hvZmZzZXQiIGNhbGNNb2RlPSJzcGxpbmUiIGR1cj0iMS41cyIga2V5U3BsaW5lcz0iMC40MiwwLDAuNTgsMTswLjQyLDAsMC41OCwxOzAuNDIsMCwwLjU4LDEiIGtleVRpbWVzPSIwOzAuNDc1OzAuOTU7MSIgcmVwZWF0Q291bnQ9ImluZGVmaW5pdGUiIHZhbHVlcz0iMDstMTY7LTU5Oy01OSIvPjwvY2lyY2xlPjxhbmltYXRlVHJhbnNmb3JtIGF0dHJpYnV0ZU5hbWU9InRyYW5zZm9ybSIgZHVyPSIycyIgcmVwZWF0Q291bnQ9ImluZGVmaW5pdGUiIHR5cGU9InJvdGF0ZSIgdmFsdWVzPSIwIDEyIDEyOzM2MCAxMiAxMiIvPjwvZz48L3N2Zz4=\') no-repeat center center';
1882 + }
1883 + }
1884 + $attrs = [
1885 + 'style="' . esc_attr(implode(';', $style)) . '"',
1886 + 'class="' . esc_attr(implode(' ', $classes)) . '"',
1887 + 'width="' . esc_attr($attributes->get('width', '100%')) . '"',
1888 + ];
1889 + if ($attributes->get('preload', 'true')) {
1890 + $attrs[] = 'onload="e2pdfViewer.imageLoad(this)"';
1891 + $attrs[] = 'preload="' . $url . '"';
1892 + $attrs[] = 'src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mM8VA8AAgkBQ6KtxDkAAAAASUVORK5CYII="';
1893 + } else {
1894 + $attrs[] = 'src="' . $url . '"';
1895 + }
1896 + $response = '<img ' . implode(' ', $attrs) . '>';
1897 + break;
1060 1898 }
1061 - $uid_params['meta_author'] = $meta_author;
1062 - $template->set('meta_author', $meta_author);
1063 1899 } else {
1064 - $template->set('meta_author', $template->extension()->render($template->get('meta_author'), 'value'));
1065 - }
1900 + $url_data = [
1901 + 'page' => 'e2pdf-download',
1902 + 'uid' => $entry->get('uid'),
1903 + 'v' => $this->helper->get('version'),
1904 + 'saveName' => $template->get('name') . '.pdf',
1905 + ];
1906 + $url_data = apply_filters('e2pdf_model_shortcode_url_data', $url_data, $atts);
1907 + $url_data = apply_filters('e2pdf_model_shortcode_e2pdf_viewer_url_data', $url_data, $atts);
1066 1908
1067 - if (array_key_exists('meta_keywords', $atts)) {
1068 - if (!array_key_exists('filter', $atts)) {
1069 - $meta_keywords = $template->extension()->render($atts['meta_keywords'], 'value');
1070 - } else {
1071 - $meta_keywords = $atts['meta_keywords'];
1909 + $url = esc_url_raw(
1910 + $this->helper->get_frontend_pdf_url(
1911 + $url_data, $attributes->get('site_url'),
1912 + [
1913 + 'e2pdf_model_shortcode_site_url',
1914 + 'e2pdf_model_shortcode_e2pdf_view_site_url',
1915 + ]
1916 + )
1917 + );
1918 + $url = apply_filters('e2pdf_model_shortcode_e2pdf_view_pdf_url', $url, $atts);
1919 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
1920 + $file = urlencode($url);
1921 + if (!empty($viewer_options)) {
1922 + $file .= '#' . implode('&', $viewer_options);
1072 1923 }
1073 - $uid_params['meta_keywords'] = $meta_keywords;
1074 - $template->set('meta_keywords', $meta_keywords);
1075 - } else {
1076 - $template->set('meta_keywords', $template->extension()->render($template->get('meta_keywords'), 'value'));
1077 - }
1924 + switch ($attributes->get('output')) {
1925 + case 'url':
1926 + case 'url_raw':
1927 + case 'url_encode':
1928 + $viewer_url = add_query_arg(
1929 + [
1930 + 'class' => implode(';', $classes),
1931 + 'file' => $file,
1932 + ],
1933 + $attributes->get('viewer', plugins_url('assets/pdf.js/web/viewer.html', $this->helper->get('plugin_file_path')))
1934 + );
1935 + if ($attributes->get('output') === 'url') {
1936 + $response = esc_url($viewer_url);
1937 + } elseif ($attributes->get('output') === 'url_raw') {
1938 + $response = esc_url_raw($viewer_url);
1939 + } elseif ($attributes->get('output') === 'url_encode') {
1940 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
1941 + $response = urlencode(esc_url_raw($viewer_url));
1942 + }
1943 + break;
1944 + default:
1945 + $viewer_url = esc_url(
1946 + add_query_arg(
1947 + [
1948 + 'file' => $file,
1949 + ],
1950 + $attributes->get('viewer', plugins_url('assets/pdf.js/web/viewer.html', $this->helper->get('plugin_file_path')))
1951 + )
1952 + );
1953 + $attrs = [
1954 + 'onload="e2pdfViewer.iframeLoad(this)"',
1955 + 'name="' . md5($this->helper->get('version')) . '"',
1956 + 'style="' . esc_attr(implode(';', $style)) . '"',
1957 + 'class="' . esc_attr(implode(' ', $classes)) . '"',
1958 + implode(' ', $app_options),
1959 + 'width="' . esc_attr($attributes->get('width', '100%')) . '"',
1960 + 'height="' . esc_attr($attributes->get('height', '500')) . '"',
1961 + ];
1078 1962
1079 - if (array_key_exists('name', $atts)) {
1080 - if (!array_key_exists('filter', $atts)) {
1081 - $name = $template->extension()->render($atts['name'], 'value');
1082 - } else {
1083 - $name = $atts['name'];
1963 + if ($attributes->get('preload')) {
1964 + $attrs[] = 'preload="' . $viewer_url . '"';
1965 + } else {
1966 + $attrs[] = 'src="' . $viewer_url . '"';
1967 + }
1968 + $response = '<iframe ' . implode(' ', $attrs) . '></iframe>';
1969 + break;
1084 1970 }
1085 - $uid_params['name'] = $name;
1086 - $template->set('name', $name);
1087 - } else {
1088 - $template->set('name', $template->extension()->render($template->get('name'), 'value'));
1089 1971 }
1972 + }
1973 + }
1090 1974
1091 - $disable = array();
1092 - if (array_key_exists('disable', $atts)) {
1093 - $disable = explode(',', $atts['disable']);
1094 - }
1975 + return $response;
1976 + }
1095 1977
1096 - if (array_key_exists('user_id', $atts)) {
1097 - $uid_params['user_id'] = (int) $atts['user_id'];
1098 - } else {
1099 - $uid_params['user_id'] = get_current_user_id();
1100 - }
1978 + // e2pdf-adobesign
1979 + public function e2pdf_adobesign($atts = []) {
1101 1980
1102 - $uid_params['args'] = $args;
1981 + $atts = apply_filters('e2pdf_model_shortcode_e2pdf_adobesign_atts', $atts);
1982 + $attributes = (new Helper_E2pdf_Atts())->load($atts);
1103 1983
1104 - $entry = new Model_E2pdf_Entry();
1105 - $entry->set('entry', $uid_params);
1106 - if (!$entry->load_by_uid($entry->get('uid'))) {
1107 - $entry->save();
1108 - }
1984 + $response = '';
1109 1985
1110 - $template->fill($dataset, $entry->get('uid'));
1111 - $request = $template->render();
1986 + if (!$attributes->get('apply') || !$attributes->get('id') || (!$attributes->get('dataset') && !$attributes->get('dataset2'))) {
1987 + return $response;
1988 + }
1112 1989
1113 - if (!isset($request['error']) && $entry->get('ID')) {
1114 - $tmp_dir = $this->helper->get('tmp_dir') . 'e2pdf' . md5($entry->get('uid')) . '/';
1115 - $this->helper->create_dir($tmp_dir);
1990 + $template = new Model_E2pdf_Template();
1991 + if (!$template->load($attributes->get('id'))) {
1992 + return $response;
1993 + }
1116 1994
1117 - if ($template->get('name')) {
1118 - $name = $template->get('name');
1119 - } else {
1120 - $name = $template->extension()->render($template->get_filename(), 'value');
1121 - }
1995 + $entry = new Model_E2pdf_Entry();
1122 1996
1123 - $file_name = $name . '.pdf';
1124 - $file_name = $this->helper->load('convert')->to_file_name($file_name);
1125 - $file_path = $tmp_dir . $file_name;
1126 - file_put_contents($file_path, base64_decode($request['file']));
1997 + $template->extension()->patch('template_id', $attributes->get('id'), $entry);
1998 + $template->extension()->patch('dataset', $attributes->get('dataset'), $entry);
1999 + $template->extension()->patch('dataset2', $attributes->get('dataset2'), $entry);
2000 + $template->extension()->patch('wc_order_id', $attributes->get('wc_order_id'), $entry);
2001 + $template->extension()->patch('wc_product_item_id', $attributes->get('wc_product_item_id'), $entry);
2002 + // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
2003 + if (!($template->get('extension') === 'wordpress' && $template->get('item') === '-3')) {
2004 + $template->extension()->patch('user_id', $attributes->get('user_id'), $entry);
2005 + }
2006 + $template->extension()->patch('args', $attributes->get('arguments'), $entry);
2007 + $template->extension()->patch('storing_engine', $template->extension()->get_storing_engine(), $entry);
1127 2008
1128 - if (file_exists($file_path)) {
2009 + $options = apply_filters('e2pdf_model_shortcode_extension_options', [], $template);
2010 + $options = apply_filters('e2pdf_model_shortcode_e2pdf_adobesign_extension_options', $options, $template);
2011 + foreach ($options as $option_key => $option_value) {
2012 + $template->extension()->set($option_key, $option_value);
2013 + }
1129 2014
1130 - $agreement_id = false;
1131 - $documents = array();
1132 - if (!in_array('post_transientDocuments', $disable)) {
1133 - $model_e2pdf_adobesign = new Model_E2pdf_AdobeSign();
1134 - $model_e2pdf_adobesign->set(array(
1135 - 'action' => 'api/rest/v5/transientDocuments',
1136 - 'headers' => array(
1137 - 'Content-Type: multipart/form-data',
1138 - ),
1139 - 'data' => array(
1140 - 'File-Name' => $file_name,
1141 - 'Mime-Type' => 'application/pdf',
1142 - 'File' => class_exists('cURLFile') ? new cURLFile($file_path) : '@' . $file_path
1143 - ),
1144 - ));
2015 + if ($template->extension()->verify() && $this->process_shortcode('e2pdf_adobesign', $template, $attributes)) {
1145 2016
1146 - if ($transientDocumentId = $model_e2pdf_adobesign->request('transientDocumentId')) {
1147 - $documents[] = array(
1148 - 'transientDocumentId' => $transientDocumentId
1149 - );
1150 - }
1151 - $model_e2pdf_adobesign->flush();
1152 - }
2017 + $template->patch('inline', $attributes->get('inline'), $entry, $attributes->get('filter'));
2018 + $template->patch('flatten', $attributes->get('flatten'), $entry, $attributes->get('filter'));
2019 + $template->patch('format', $attributes->get('format'), $entry, $attributes->get('filter'));
2020 + $template->patch('password', $attributes->get('password'), $entry, $attributes->get('filter'));
2021 + $template->patch('dpdf', $attributes->get('dpdf'), $entry, $attributes->get('filter'));
2022 + $template->patch('name', $attributes->get('name'), $entry, $attributes->get('filter'));
2023 + $template->patch('meta_title', $attributes->get('meta_title'), $entry, $attributes->get('filter'));
2024 + $template->patch('meta_subject', $attributes->get('meta_subject'), $entry, $attributes->get('filter'));
2025 + $template->patch('meta_author', $attributes->get('meta_author'), $entry, $attributes->get('filter'));
2026 + $template->patch('meta_keywords', $attributes->get('meta_keywords'), $entry, $attributes->get('filter'));
1153 2027
1154 - $documents = apply_filters('e2pdf_model_shortcode_e2pdf_adobesign_fileInfos', $documents, $atts, $template, $entry, $template->extension(), $file_path);
2028 + $template->extension()->set('entry', $entry);
2029 + $template->fill();
2030 + $request = $template->render();
1155 2031
1156 - if (!in_array('post_agreements', $disable) && !empty($documents)) {
2032 + if (!isset($request['error'])) {
1157 2033
1158 - $output = false;
1159 - if (array_key_exists('output', $atts)) {
1160 - $output = $atts['output'];
1161 - }
2034 + $tmp_dir = $this->helper->get('tmp_dir') . 'e2pdf' . md5($entry->get('uid')) . '/';
2035 + $this->helper->create_dir($tmp_dir);
1162 2036
1163 - $recipients = array();
1164 - if (array_key_exists('recipients', $atts)) {
1165 - $atts['recipients'] = $template->extension()->render($atts['recipients']);
1166 - $recipients_list = explode(',', $atts['recipients']);
2037 + $filename = $template->get('name') . '.pdf';
2038 + $filename = $this->helper->load('convert')->to_file_name($filename);
2039 + $filepath = $tmp_dir . $filename;
2040 + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
2041 + file_put_contents($filepath, $request['file'], LOCK_EX);
1167 2042
1168 - foreach ($recipients_list as $recipient_info) {
1169 - $recipients[] = array(
1170 - 'recipientSetMemberInfos' => array(
1171 - 'email' => trim($recipient_info)
1172 - ),
1173 - 'recipientSetRole' => 'SIGNER'
1174 - );
1175 - }
1176 - }
2043 + $disable = $attributes->get('disable');
1177 2044
1178 - $data = array(
1179 - 'documentCreationInfo' => array(
1180 - 'signatureType' => 'ESIGN',
1181 - 'recipientSetInfos' => $recipients,
1182 - 'signatureFlow' => 'SENDER_SIGNATURE_NOT_REQUIRED',
1183 - 'fileInfos' => $documents,
1184 - 'name' => $name
1185 - )
1186 - );
2045 + if (file_exists($filepath)) {
1187 2046
1188 - $data = apply_filters('e2pdf_model_shortcode_e2pdf_adobesign_post_agreements_data', $data, $atts, $template, $entry, $template->extension(), $file_path, $documents);
2047 + $agreement_id = false;
2048 + $documents = [];
2049 + if (!in_array('post_transientDocuments', $disable, true)) {
2050 + $model_e2pdf_adobesign = new Model_E2pdf_AdobeSign();
2051 + $model_e2pdf_adobesign->set(
2052 + [
2053 + 'action' => 'api/rest/v5/transientDocuments',
2054 + 'headers' => [
2055 + 'Content-Type: multipart/form-data',
2056 + ],
2057 + 'data' => [
2058 + 'File-Name' => $filename,
2059 + 'Mime-Type' => 'application/pdf',
2060 + 'File' => class_exists('cURLFile') ? new cURLFile($filepath) : '@' . $filepath,
2061 + ],
2062 + ]
2063 + );
1189 2064
1190 - $model_e2pdf_adobesign = new Model_E2pdf_AdobeSign();
1191 - $model_e2pdf_adobesign->set(array(
1192 - 'action' => 'api/rest/v5/agreements',
1193 - 'data' => $data,
1194 - ));
2065 + $transientDocumentId = $model_e2pdf_adobesign->request('transientDocumentId');
2066 + if ($transientDocumentId) {
2067 + $documents[] = [
2068 + 'transientDocumentId' => $transientDocumentId,
2069 + ];
2070 + }
2071 + $model_e2pdf_adobesign->flush();
2072 + }
2073 + // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
2074 + $documents = apply_filters('e2pdf_model_shortcode_e2pdf_adobesign_fileInfos', $documents, $atts, $template, $entry, $template->extension(), $filepath);
1195 2075
1196 - $agreement_id = $model_e2pdf_adobesign->request('agreementId');
1197 - $model_e2pdf_adobesign->flush();
2076 + if (!in_array('post_agreements', $disable, true) && !empty($documents)) {
2077 + $recipients = [];
2078 + if ($attributes->get('recipients') !== false) {
2079 + $recipients_list = explode(',', $template->extension()->render($attributes->get('recipients')));
2080 + foreach ($recipients_list as $recipient_info) {
2081 + $recipients[] = [
2082 + 'recipientSetMemberInfos' => [
2083 + 'email' => trim($recipient_info),
2084 + ],
2085 + 'recipientSetRole' => 'SIGNER',
2086 + ];
2087 + }
1198 2088 }
1199 2089
1200 - $response = apply_filters('e2pdf_model_shortcode_e2pdf_adobesign_response', $response, $atts, $template, $entry, $template->extension(), $file_path, $documents, $agreement_id);
2090 + $data = [
2091 + 'documentCreationInfo' => [
2092 + 'signatureType' => 'ESIGN',
2093 + 'recipientSetInfos' => $recipients,
2094 + 'signatureFlow' => 'SENDER_SIGNATURE_NOT_REQUIRED',
2095 + 'fileInfos' => $documents,
2096 + 'name' => $template->get('name'),
2097 + ],
2098 + ];
2099 +
2100 + $data = apply_filters('e2pdf_model_shortcode_e2pdf_adobesign_post_agreements_data', $data, $atts, $template, $entry, $template->extension(), $filepath, $documents);
2101 +
2102 + $model_e2pdf_adobesign = new Model_E2pdf_AdobeSign();
2103 + $model_e2pdf_adobesign->set(
2104 + [
2105 + 'action' => 'api/rest/v5/agreements',
2106 + 'data' => $data,
2107 + ]
2108 + );
2109 +
2110 + $agreement_id = $model_e2pdf_adobesign->request('agreementId');
2111 + $model_e2pdf_adobesign->flush();
1201 2112 }
1202 2113
1203 - $this->helper->delete_dir($tmp_dir);
1204 - return $response;
2114 + $response = apply_filters('e2pdf_model_shortcode_e2pdf_adobesign_response', $response, $atts, $template, $entry, $template->extension(), $filepath, $documents, $agreement_id);
1205 2115 }
2116 +
2117 + $this->helper->delete_dir($tmp_dir);
2118 + return $response;
1206 2119 }
1207 2120 }
2121 +
1208 2122 return $response;
1209 2123 }
1210 2124
1211 - /**
1212 - * [e2pdf-format-number] shortcode
1213 - *
1214 - * @param array $atts - Attributes
1215 - * @param string $value - Content
1216 - */
1217 - function e2pdf_format_number($atts = array(), $value = '') {
2125 + // e2pdf-format-number
2126 + public function e2pdf_format_number($atts = [], $value = '') {
1218 2127
2128 + // phpcs:ignore Squiz.PHP.CommentedOutCode.Found
2129 + /*
2130 + * TODO: Prevent shortcode execution outside PDF rendering context
2131 + * if (!apply_filters('e2pdf_shortcode_enable_e2pdf_format_number', false) && !apply_filters('e2pdf_pdf_render', false)) {
2132 + * return '';
2133 + * }
2134 + */
2135 +
2136 + $response = $value;
2137 + $atts = apply_filters('e2pdf_model_shortcode_e2pdf_format_number_atts', $atts);
2138 +
1219 2139 $dec_point = isset($atts['dec_point']) ? $atts['dec_point'] : '.';
1220 2140 $thousands_sep = isset($atts['thousands_sep']) ? $atts['thousands_sep'] : '';
1221 - $decimal = isset($atts['decimal']) ? $atts['decimal'] : false;
2141 + $decimal = isset($atts['decimal']) ? (int) $atts['decimal'] : false;
1222 2142 $explode = isset($atts['explode']) ? $atts['explode'] : '';
1223 2143 $implode = isset($atts['implode']) ? $atts['implode'] : '';
1224 2144
1225 - $new_value = array();
1226 - $value = array_filter((array) $value, 'strlen');
1227 - foreach ($value as $v) {
1228 - if ($explode && strpos($v, $explode)) {
2145 + $new_value = [];
2146 + $response = array_filter((array) $response, 'strlen');
2147 + foreach ($response as $v) {
2148 + if ($explode && strpos($v, $explode) !== false) {
1229 2149 $v = explode($explode, $v);
1230 2150 }
1231 2151 foreach ((array) $v as $n) {
1232 - $n = str_replace(array(" ", ","), array("", "."), $n);
2152 + $n = str_replace([' ', ','], ['', '.'], $n);
1233 2153 $n = preg_replace('/\.(?=.*\.)/', '', $n);
1234 2154 $n = floatval($n);
1235 -
1236 - if (!$decimal) {
2155 + if ($decimal === false) {
1237 2156 $num = explode('.', $n);
1238 2157 $decimal = isset($num[1]) ? strlen($num[1]) : 0;
1239 2158 }
1240 -
1241 2159 $n = number_format($n, $decimal, $dec_point, $thousands_sep);
1242 2160 $new_value[] = $n;
1243 2161 }
1244 2162 unset($v);
1245 2163 }
1246 - $new_value = array_filter((array) $new_value, 'strlen');
1247 - return implode($implode, $new_value);
2164 +
2165 + $response = implode($implode, array_filter((array) $new_value, 'strlen'));
2166 + if (!apply_filters('e2pdf_pdf_fill', false)) {
2167 + $response = $this->sanitize_html($response);
2168 + }
2169 + return apply_filters('e2pdf_model_shortcode_e2pdf_format_number', $response, $atts, $value);
1248 2170 }
1249 2171
1250 - /**
1251 - * [e2pdf-format-date] shortcode
1252 - *
1253 - * @param array $atts - Attributes
1254 - * @param string $value - Content
1255 - */
1256 - function e2pdf_format_date($atts = array(), $value = '') {
2172 + // e2pdf-format-date
2173 + public function e2pdf_format_date($atts = [], $value = '') {
2174 +
2175 + // phpcs:ignore Squiz.PHP.CommentedOutCode.Found
2176 + /*
2177 + * TODO: Prevent shortcode execution outside PDF rendering context
2178 + * if (!apply_filters('e2pdf_shortcode_enable_e2pdf_format_date', false) && !apply_filters('e2pdf_pdf_render', false)) {
2179 + * return '';
2180 + * }
2181 + */
2182 +
2183 + $response = trim(strtolower($value));
2184 +
2185 + $atts = apply_filters('e2pdf_model_shortcode_e2pdf_format_date_atts', $atts);
2186 +
1257 2187 $format = isset($atts['format']) ? $atts['format'] : get_option('date_format');
1258 - if (!$value) {
2188 + $offset = isset($atts['offset']) ? $atts['offset'] : false;
2189 + $function = isset($atts['function']) ? $atts['function'] : false;
2190 + $timestamp = isset($atts['timestamp']) && $atts['timestamp'] == 'true' ? true : false;
2191 +
2192 + $timezone = null;
2193 + if (isset($atts['timezone'])) {
2194 + try {
2195 + $timezone = new DateTimeZone($atts['timezone']);
2196 + } catch (Exception $e) {
2197 + $timezone = null;
2198 + }
2199 + }
2200 +
2201 + $gmt = isset($atts['gmt']) && $atts['gmt'] == 'true' ? true : false;
2202 + $locale = isset($atts['locale']) && $atts['locale'] ? $atts['locale'] : false;
2203 +
2204 + if (!$response) {
1259 2205 return '';
1260 2206 }
1261 - $value = date($format, strtotime($value));
1262 - return $value;
2207 +
2208 + switch ($response) {
2209 + case 'time':
2210 + $response = time();
2211 + break;
2212 + case 'current_time':
2213 + // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
2214 + $response = current_time('timestamp', $gmt);
2215 + break;
2216 + default:
2217 + if (!$timestamp) {
2218 + $response = strtotime($response);
2219 + }
2220 + break;
2221 + }
2222 +
2223 + if ($timestamp && !is_numeric($response)) {
2224 + return '';
2225 + }
2226 +
2227 + if ($locale && function_exists('switch_to_locale') && function_exists('restore_previous_locale')) {
2228 + switch_to_locale($locale);
2229 + }
2230 +
2231 + if ($offset) {
2232 + if ($function == 'wp_date' && function_exists('wp_date')) {
2233 + $response = wp_date($format, strtotime($offset, $response), $timezone);
2234 + } elseif ($function == 'date_i18n') {
2235 + $response = date_i18n($format, strtotime($offset, $response));
2236 + } else {
2237 + // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
2238 + $response = date($format, strtotime($offset, $response));
2239 + }
2240 + } else {
2241 + if ($function == 'wp_date' && function_exists('wp_date')) {
2242 + $response = wp_date($format, $response, $timezone);
2243 + } elseif ($function == 'date_i18n') {
2244 + $response = date_i18n($format, $response);
2245 + } else {
2246 + // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
2247 + $response = date($format, $response);
2248 + }
2249 + }
2250 +
2251 + if ($locale && function_exists('switch_to_locale') && function_exists('restore_previous_locale')) {
2252 + restore_previous_locale();
2253 + }
2254 +
2255 + if (!apply_filters('e2pdf_pdf_fill', false)) {
2256 + $response = $this->sanitize_html($response);
2257 + }
2258 + return apply_filters('e2pdf_model_shortcode_e2pdf_format_date', $response, $atts, $value);
1263 2259 }
1264 2260
1265 - /**
1266 - * [e2pdf-format-output] shortcode
1267 - *
1268 - * @param array $atts - Attributes
1269 - * @param string $value - Content
1270 - */
1271 - function e2pdf_format_output($atts = array(), $value = '') {
2261 + // e2pdf-format-output
2262 + public function e2pdf_format_output($atts = [], $value = '') {
1272 2263
2264 + // phpcs:ignore Squiz.PHP.CommentedOutCode.Found
2265 + /*
2266 + * TODO: Prevent shortcode execution outside PDF rendering context
2267 + * if (!apply_filters('e2pdf_shortcode_enable_e2pdf_format_output', false) && !apply_filters('e2pdf_pdf_render', false)) {
2268 + * return '';
2269 + * }
2270 + */
2271 +
2272 + $response = $value;
2273 + $atts = apply_filters('e2pdf_model_shortcode_e2pdf_format_output_atts', $atts);
2274 +
1273 2275 $explode = isset($atts['explode']) ? $atts['explode'] : false;
2276 + $explode_filter = isset($atts['explode_filter']) ? $atts['explode_filter'] : false;
2277 + $explode_limit = isset($atts['explode_limit']) ? intval($atts['explode_limit']) : false;
1274 2278 $implode = isset($atts['implode']) ? $atts['implode'] : '';
1275 2279 $output = isset($atts['output']) ? $atts['output'] : false;
1276 2280 $filter = isset($atts['filter']) ? $atts['filter'] : false;
1277 - $search = isset($atts['search']) ? explode("|||", $atts['search']) : array();
1278 - $ireplace = isset($atts['ireplace']) ? explode("|||", $atts['ireplace']) : array();
1279 - $replace = isset($atts['replace']) ? explode("|||", $atts['replace']) : array();
2281 + $search = isset($atts['search']) ? explode('|||', $atts['search']) : [];
2282 + $sreplace = isset($atts['sreplace']) ? explode('|||', $atts['sreplace']) : [];
2283 + $ireplace = isset($atts['ireplace']) ? explode('|||', $atts['ireplace']) : [];
2284 + $replace = isset($atts['replace']) ? explode('|||', $atts['replace']) : [];
2285 + $substr = isset($atts['substr']) ? $atts['substr'] : false;
2286 + $sprintf = isset($atts['sprintf']) ? $atts['sprintf'] : false;
2287 + $remove_tags = isset($atts['remove_tags']) ? $atts['remove_tags'] : false;
2288 + $trim = isset($atts['trim']) ? $atts['trim'] : false;
2289 + $rtrim = isset($atts['rtrim']) ? $atts['rtrim'] : false;
2290 + $ltrim = isset($atts['ltrim']) ? $atts['ltrim'] : false;
2291 + $strip_tags_allowed = isset($atts['strip_tags_allowed']) ? $atts['strip_tags_allowed'] : false;
2292 + $pre = isset($atts['pre']) && $atts['pre'] ? $atts['pre'] : '';
2293 + $after = isset($atts['after']) && $atts['after'] ? $atts['after'] : '';
2294 + $strip_shortcodes_tags = isset($atts['strip_shortcodes_tags']) ? explode(',', $atts['strip_shortcodes_tags']) : [];
2295 + $strip_shortcodes_tags_full = isset($atts['strip_shortcodes_tags_full']) ? explode(',', $atts['strip_shortcodes_tags_full']) : [];
2296 + $extract_by_tag = isset($atts['extract_by_tag']) ? explode(',', $atts['extract_by_tag']) : [];
2297 + $extract_by_id = isset($atts['extract_by_id']) ? explode(',', $atts['extract_by_id']) : [];
2298 + $extract_by_class = isset($atts['extract_by_class']) ? explode(',', $atts['extract_by_class']) : [];
2299 + $extract_implode = isset($atts['extract_implode']) ? $atts['extract_implode'] : '';
2300 + $remove_by_tag = isset($atts['remove_by_tag']) ? explode(',', $atts['remove_by_tag']) : [];
2301 + $remove_by_id = isset($atts['remove_by_id']) ? explode(',', $atts['remove_by_id']) : [];
2302 + $remove_by_class = isset($atts['remove_by_class']) ? explode(',', $atts['remove_by_class']) : [];
2303 + $transliterate = isset($atts['transliterate']) ? $atts['transliterate'] : false;
2304 + $truncate = isset($atts['truncate']) ? intval($atts['truncate']) : false;
2305 + $truncate_html = isset($atts['truncate_html']) ? intval($atts['truncate_html']) : false;
2306 + $truncate_ishtml = isset($atts['truncate_ishtml']) && $atts['truncate_ishtml'] == 'true' ? true : false;
2307 + $truncate_breakwords = isset($atts['truncate_breakwords']) && $atts['truncate_breakwords'] == 'true' ? true : false;
2308 + $truncate_readmore = isset($atts['truncate_readmore']) ? $atts['truncate_readmore'] : '...';
2309 + $path = isset($atts['path']) ? $atts['path'] : false;
1280 2310
1281 - $filters = array();
2311 + /*
2312 + * Backward compatibility
2313 + */
2314 + if (isset($atts['implode_filter']) && $atts['implode_filter'] == 'serialize') {
2315 + $output = '{serialize}';
2316 + }
2317 +
2318 + if ((!empty($extract_by_id) || !empty($extract_by_class) || !empty($extract_by_tag)) && $value) {
2319 + $extracted = [];
2320 + $dom = new DOMDocument();
2321 + $html = $this->helper->load('convert')->load_html($value, $dom);
2322 + if ($html) {
2323 + $xpath = new DomXPath($dom);
2324 +
2325 + if (!empty($extract_by_tag)) {
2326 + foreach ($extract_by_tag as $by_tag) {
2327 + $query = '//' . $by_tag;
2328 + $elements = $xpath->query($query);
2329 + foreach ($elements as $element) {
2330 + $extracted[] = $this->helper->load('convert')->html_entities_decode($dom->saveHTML($element));
2331 + }
2332 + }
2333 + }
2334 +
2335 + if (!empty($extract_by_id)) {
2336 + foreach ($extract_by_id as $by_id) {
2337 + $query = "//*[contains(concat(' ', @id, ' '), ' {$by_id} ')]";
2338 + $elements = $xpath->query($query);
2339 + foreach ($elements as $element) {
2340 + $extracted[] = $this->helper->load('convert')->html_entities_decode($dom->saveHTML($element));
2341 + }
2342 + }
2343 + }
2344 +
2345 + if (!empty($extract_by_class)) {
2346 + foreach ($extract_by_class as $by_class) {
2347 + $query = '//*[';
2348 + $by_sub_classes = explode(' ', $by_class);
2349 + foreach ($by_sub_classes as $index => $by_sub_class) {
2350 + if ($index !== 0) {
2351 + $query .= ' and ';
2352 + }
2353 + $query .= "contains(concat(' ', normalize-space(@class), ' '), ' {$by_sub_class} ')";
2354 + }
2355 + $query .= ']';
2356 + $elements = $xpath->query($query);
2357 + foreach ($elements as $element) {
2358 + $extracted[] = $this->helper->load('convert')->html_entities_decode($dom->saveHTML($element));
2359 + }
2360 + }
2361 + }
2362 + }
2363 + $response = implode($extract_implode, $extracted);
2364 + }
2365 +
2366 + if ((!empty($remove_by_tag) || !empty($remove_by_id) || !empty($remove_by_class)) && $response) {
2367 + $dom = new DOMDocument();
2368 + $html = $this->helper->load('convert')->load_html($response, $dom);
2369 + if ($html) {
2370 + $xpath = new DomXPath($dom);
2371 +
2372 + if (!empty($remove_by_tag)) {
2373 + foreach ($remove_by_tag as $by_tag) {
2374 + $query = '//' . $by_tag;
2375 + $elements = $xpath->query($query);
2376 + foreach ($elements as $element) {
2377 + $element->parentNode->removeChild($element);
2378 + }
2379 + }
2380 + }
2381 +
2382 + if (!empty($remove_by_id)) {
2383 + foreach ($remove_by_id as $by_id) {
2384 + $query = "//*[contains(concat(' ', @id, ' '), ' {$by_id} ')]";
2385 + $elements = $xpath->query($query);
2386 + foreach ($elements as $element) {
2387 + $element->parentNode->removeChild($element);
2388 + }
2389 + }
2390 + }
2391 +
2392 + if (!empty($remove_by_class)) {
2393 + foreach ($remove_by_class as $by_class) {
2394 + $query = '//*[';
2395 + $by_sub_classes = explode(' ', $by_class);
2396 + foreach ($by_sub_classes as $index => $by_sub_class) {
2397 + if ($index !== 0) {
2398 + $query .= ' and ';
2399 + }
2400 + $query .= "contains(concat(' ', normalize-space(@class), ' '), ' {$by_sub_class} ')";
2401 + }
2402 + $query .= ']';
2403 + $elements = $xpath->query($query);
2404 + foreach ($elements as $element) {
2405 + $element->parentNode->removeChild($element);
2406 + }
2407 + }
2408 + }
2409 +
2410 + $dom2 = new DOMDocument();
2411 + $body = $dom->getElementsByTagName('body')->item(0);
2412 + if ($body) {
2413 + foreach ($body->childNodes as $child) {
2414 + $dom2->appendChild($dom2->importNode($child, true));
2415 + }
2416 + }
2417 + $response = $this->helper->load('convert')->html_entities_decode($dom2->saveHTML());
2418 + }
2419 + }
2420 +
2421 + $filters = [];
1282 2422 if ($filter) {
1283 2423 if (strpos($filter, ',')) {
1284 2424 $filters = explode(',', $filter);
1285 2425 } else {
@@ -1286,33 +2426,206 @@
1286 2426 $filters = array_filter((array) $filter, 'strlen');
1287 2427 }
1288 2428 }
1289 2429
1290 - $new_value = array();
1291 - if (!empty($ireplace)) {
1292 - $value = str_ireplace($search, $ireplace, $value);
1293 - } elseif (!empty($replace)) {
1294 - $value = str_replace($search, $replace, $value);
2430 + $explode_filters = [];
2431 + if ($explode_filter) {
2432 + if (strpos($explode_filter, ',')) {
2433 + $explode_filters = explode(',', $explode_filter);
2434 + } else {
2435 + $explode_filters = array_filter((array) $explode_filter, 'strlen');
2436 + }
1295 2437 }
1296 2438
1297 - $value = array_filter((array) $value, 'strlen');
2439 + $response = apply_filters('e2pdf_model_shortcode_e2pdf_format_output_pre_filter', $response, $atts, $value);
2440 + if (!in_array('ireplace', $filters, true) && !in_array('replace', $filters, true) && !in_array('sreplace', $filters, true)) {
2441 + if (!empty($sreplace)) {
2442 + if (!empty($search) && count($search) === count($sreplace)) {
2443 + $replacements = array_combine($search, $sreplace);
2444 + if (is_array($replacements)) {
2445 + $response = strtr($response, $replacements);
2446 + }
2447 + }
2448 + } elseif (!empty($ireplace)) {
2449 + $response = str_ireplace($search, $ireplace, $response);
2450 + } elseif (!empty($replace)) {
2451 + $response = str_replace($search, $replace, $response);
2452 + }
2453 + }
1298 2454
1299 - foreach ($value as $v) {
1300 - if ($explode && strpos($v, $explode)) {
1301 - $v = explode($explode, $v);
2455 + if (!in_array('substr', $filters, true)) {
2456 + if ($substr !== false) {
2457 + $substr_start = false;
2458 + $substr_length = false;
2459 + if (strpos($substr, ',')) {
2460 + $substr_data = explode(',', $substr);
2461 + if (isset($substr_data[0])) {
2462 + $substr_start = trim($substr_data[0]);
2463 + }
2464 + if (isset($substr_data[1])) {
2465 + $substr_length = trim($substr_data[1]);
2466 + }
2467 + } else {
2468 + $substr_start = trim($substr);
2469 + }
2470 +
2471 + if ($substr_start !== false && $substr_length !== false) {
2472 + $response = substr($response, $substr_start, $substr_length);
2473 + } elseif ($substr_start !== false) {
2474 + $response = substr($response, $substr_start);
2475 + }
1302 2476 }
2477 + }
2478 +
2479 + if (!in_array('trim', $filters, true)) {
2480 + if ($trim !== false) {
2481 + $response = trim($response, $trim);
2482 + }
2483 + }
2484 +
2485 + if (!in_array('rtrim', $filters, true)) {
2486 + if ($rtrim !== false) {
2487 + $response = rtrim($response, $rtrim);
2488 + }
2489 + }
2490 +
2491 + if (!in_array('ltrim', $filters, true)) {
2492 + if ($ltrim !== false) {
2493 + $response = ltrim($response, $ltrim);
2494 + }
2495 + }
2496 +
2497 + if (!in_array('sprintf', $filters, true)) {
2498 + if ($sprintf !== false) {
2499 + $response = sprintf($sprintf, $response);
2500 + }
2501 + }
2502 +
2503 + if (!in_array('transliterate', $filters, true)) {
2504 + if ($transliterate !== false && function_exists('transliterator_transliterate')) {
2505 + $response = transliterator_transliterate(str_replace(['{{', '}}'], ['[', ']'], $transliterate), $response);
2506 + }
2507 + }
2508 +
2509 + if (!in_array('truncate', $filters, true)) {
2510 + if ($truncate !== false) {
2511 + $max_length = $truncate && intval($truncate) > 0 ? intval($truncate) : 100;
2512 + $response = $this->helper->load('truncate')->truncate($response, $max_length, $truncate_readmore, $truncate_breakwords, $truncate_ishtml);
2513 + }
2514 + }
2515 +
2516 + if (!in_array('truncate_html', $filters, true)) {
2517 + if ($truncate_html !== false) {
2518 + $max_length = $truncate_html && intval($truncate_html) > 0 ? intval($truncate_html) : 100;
2519 + $response = $this->helper->load('truncate')->truncate($response, $max_length, $truncate_readmore, $truncate_breakwords, true);
2520 + }
2521 + }
2522 +
2523 + $closed_tags = [
2524 + 'style', 'script', 'title', 'head', 'a',
2525 + ];
2526 + if (isset($atts['closed_tags']) && $atts['closed_tags']) {
2527 + $closed_tags = array_merge($closed_tags, explode(',', $atts['closed_tags']));
2528 + }
2529 +
2530 + $mixed_tags = [];
2531 + if (isset($atts['mixed_tags']) && $atts['mixed_tags']) {
2532 + $closed_tags = array_merge($closed_tags, explode(',', $atts['mixed_tags']));
2533 + }
2534 +
2535 + $closed_tags = apply_filters('e2pdf_model_shortcode_wp_e2pdf_format_output_closed_tags', $closed_tags);
2536 + $mixed_tags = apply_filters('e2pdf_model_shortcode_wp_e2pdf_format_output_mixed_tags', $mixed_tags);
2537 +
2538 + if (!in_array('remove_tags', $filters, true)) {
2539 + if ($remove_tags) {
2540 + $remove_tags_list = explode(',', $remove_tags);
2541 + foreach ($remove_tags_list as $remove_tag) {
2542 + if (in_array($remove_tag, $mixed_tags, true)) {
2543 + $response = preg_replace('#<' . $remove_tag . '(.*?)>(.*?)</' . $remove_tag . '>#is', '', $response);
2544 + $response = preg_replace('#<' . $remove_tag . '([^>]+)?\>#is', '', $response);
2545 + } elseif (in_array($remove_tag, $closed_tags, true)) {
2546 + $response = preg_replace('#<' . $remove_tag . '(.*?)>(.*?)</' . $remove_tag . '>#is', '', $response);
2547 + } else {
2548 + $response = preg_replace('#<' . $remove_tag . '([^>]+)?\>#is', '', $response);
2549 + }
2550 + }
2551 + }
2552 + }
2553 +
2554 + $new_value = [];
2555 + if ($path !== false) {
2556 + $response = $this->helper->load('shortcode')->apply_path_attribute($response, $path);
2557 + if (is_array($response) || is_object($response)) {
2558 + if (is_array($response) && !$this->helper->is_multidimensional($response)) {
2559 + $response = implode(', ', $response);
2560 + } else {
2561 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
2562 + $response = serialize($response);
2563 + }
2564 + }
2565 + }
2566 +
2567 + $response = array_filter((array) $response, 'strlen');
2568 + foreach ($response as $v) {
2569 + if ($explode && strpos($v, $explode) !== false) {
2570 + if ($explode_limit !== false) {
2571 + $v = explode($explode, $v, $explode_limit);
2572 + } else {
2573 + $v = explode($explode, $v);
2574 + }
2575 + if (is_array($v) && !empty($explode_filters)) {
2576 + foreach ((array) $explode_filters as $sub_explode_filter) {
2577 + switch ($sub_explode_filter) {
2578 + case 'array_filter':
2579 + $v = array_filter($v);
2580 + break;
2581 + case 'array_values':
2582 + $v = array_values($v);
2583 + break;
2584 + default:
2585 + break;
2586 + }
2587 + }
2588 + }
2589 + }
2590 +
1303 2591 foreach ((array) $v as $n) {
1304 2592 if (!empty($filters)) {
1305 2593 foreach ((array) $filters as $sub_filter) {
1306 2594 switch ($sub_filter) {
1307 2595 case 'trim':
1308 - $n = trim($n);
2596 + if ($trim !== false) {
2597 + $n = trim($n, $trim);
2598 + } else {
2599 + $n = trim($n);
2600 + }
1309 2601 break;
1310 -
2602 + case 'rtrim':
2603 + if ($rtrim !== false) {
2604 + $n = rtrim($n, $rtrim);
2605 + } else {
2606 + $n = rtrim($n);
2607 + }
2608 + break;
2609 + case 'ltrim':
2610 + if ($ltrim !== false) {
2611 + $n = ltrim($n, $ltrim);
2612 + } else {
2613 + $n = ltrim($n);
2614 + }
2615 + break;
1311 2616 case 'strip_tags':
1312 - $n = strip_tags($n);
2617 + if ($strip_tags_allowed !== false) {
2618 + // phpcs:ignore WordPress.WP.AlternativeFunctions.strip_tags_strip_tags
2619 + $n = strip_tags($n, $strip_tags_allowed);
2620 + } else {
2621 + // phpcs:ignore WordPress.WP.AlternativeFunctions.strip_tags_strip_tags
2622 + $n = strip_tags($n);
2623 + }
1313 2624 break;
1314 -
2625 + case 'strip_comments':
2626 + $n = preg_replace('/<!--(.|\s)*?-->/', '', $n);
2627 + break;
1315 2628 case 'strtolower':
1316 2629 if (function_exists('mb_strtolower')) {
1317 2630 $n = mb_strtolower($n);
1318 2631 } elseif (function_exists('strtolower')) {
@@ -1318,18 +2631,38 @@
1318 2631 } elseif (function_exists('strtolower')) {
1319 2632 $n = strtolower($n);
1320 2633 }
1321 2634 break;
1322 -
2635 + case 'normalize_whitespace':
2636 + $n = normalize_whitespace($n);
2637 + break;
2638 + case 'sanitize_title':
2639 + $n = sanitize_title($n);
2640 + break;
2641 + case 'transliterate':
2642 + if (function_exists('transliterator_transliterate')) {
2643 + if ($transliterate !== false) {
2644 + $n = transliterator_transliterate(str_replace(['{{', '}}'], ['[', ']'], $transliterate), $n);
2645 + } else {
2646 + $n = transliterator_transliterate('Any-Latin; Latin-ASCII; NFD; NFC;', $n);
2647 + }
2648 + }
2649 + break;
1323 2650 case 'ucfirst':
1324 2651 if (function_exists('mb_strtoupper') && function_exists('mb_strtolower')) {
1325 2652 $fc = mb_strtoupper(mb_substr($n, 0, 1));
1326 2653 $n = $fc . mb_substr($n, 1);
1327 - } else if (function_exists('ucfirst') && function_exists('strtolower')) {
2654 + } elseif (function_exists('ucfirst') && function_exists('strtolower')) {
1328 2655 $n = ucfirst($n);
1329 2656 }
1330 2657 break;
1331 -
2658 + case 'ucwords':
2659 + if (version_compare(PHP_VERSION, '7.3.0', '>=') && function_exists('mb_convert_case')) {
2660 + $n = mb_convert_case($n, MB_CASE_TITLE);
2661 + } elseif (function_exists('ucwords')) {
2662 + $n = ucwords($n);
2663 + }
2664 + break;
1332 2665 case 'strtoupper':
1333 2666 if (function_exists('mb_strtoupper')) {
1334 2667 $n = mb_strtoupper($n);
1335 2668 } elseif (function_exists('strtoupper')) {
@@ -1335,18 +2668,149 @@
1335 2668 } elseif (function_exists('strtoupper')) {
1336 2669 $n = strtoupper($n);
1337 2670 }
1338 2671 break;
1339 -
1340 2672 case 'lines':
1341 2673 $n = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $n);
1342 2674 break;
1343 -
1344 2675 case 'nl2br':
1345 2676 $n = nl2br($n);
1346 2677 break;
2678 + case 'wpautop':
2679 + $n = wpautop($n);
2680 + break;
2681 + case 'html_entity_decode':
2682 + $n = html_entity_decode($n);
2683 + break;
2684 + case 'urlencode':
2685 + $n = urlencode($n); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
2686 + break;
2687 + case 'urldecode':
2688 + $n = urldecode($n);
2689 + break;
2690 + case 'strip_shortcodes':
2691 + if (false !== strpos($n, '&#091;')) {
2692 + $n = str_replace('&#091;', '[', $n);
2693 + if (!empty($strip_shortcodes_tags_full)) {
2694 + foreach ($strip_shortcodes_tags_full as $strip_shortcode_tag) {
2695 + $n = preg_replace('~(\[(' . $strip_shortcode_tag . ')[^\]]*\].*?\[\/' . $strip_shortcode_tag . '])~s', '', $n);
2696 + }
2697 + }
1347 2698
2699 + if (!empty($strip_shortcodes_tags)) {
2700 + foreach ($strip_shortcodes_tags as $strip_shortcode_tag) {
2701 + $n = preg_replace(' ~\[/?' . $strip_shortcode_tag . '[^\]]*\]~s', '', $n);
2702 + }
2703 + }
2704 +
2705 + $n = strip_shortcodes($n);
2706 + $n = str_replace('[', '&#091;', $n);
2707 + }
2708 + break;
2709 + case 'strip_shortcodes_tags_full':
2710 + if (!empty($strip_shortcodes_tags_full) && false !== strpos($n, '&#091;')) {
2711 + $n = str_replace('&#091;', '[', $n);
2712 + foreach ($strip_shortcodes_tags_full as $strip_shortcode_tag) {
2713 + $n = preg_replace('~(\[(' . $strip_shortcode_tag . ')[^\]]*\].*?\[\/' . $strip_shortcode_tag . '])~s', '', $n);
2714 + }
2715 + $n = str_replace('[', '&#091;', $n);
2716 + }
2717 + break;
2718 + case 'strip_shortcodes_tags':
2719 + if (!empty($strip_shortcodes_tags) && false !== strpos($n, '&#091;')) {
2720 + $n = str_replace('&#091;', '[', $n);
2721 + foreach ($strip_shortcodes_tags as $strip_shortcode_tag) {
2722 + $n = preg_replace(' ~\[/?' . $strip_shortcode_tag . '[^\]]*\]~s', '', $n);
2723 + }
2724 + $n = str_replace('[', '&#091;', $n);
2725 + }
2726 + break;
2727 + case 'do_shortcode':
2728 + if (false !== strpos($n, '&#091;')) {
2729 + $n = str_replace('&#091;', '[', $n);
2730 + $n = do_shortcode($n);
2731 + $n = str_replace('[', '&#091;', $n);
2732 + }
2733 + break;
2734 + case 'htmlentities':
2735 + $n = htmlentities($n);
2736 + break;
2737 + case 'substr':
2738 + if ($substr !== false) {
2739 + $substr_start = false;
2740 + $substr_length = false;
2741 + if (strpos($substr, ',')) {
2742 + $substr_data = explode(',', $substr);
2743 + if (isset($substr_data[0])) {
2744 + $substr_start = trim($substr_data[0]);
2745 + }
2746 + if (isset($substr_data[1])) {
2747 + $substr_length = trim($substr_data[1]);
2748 + }
2749 + } else {
2750 + $substr_start = trim($substr);
2751 + }
2752 +
2753 + if ($substr_start !== false && $substr_length !== false) {
2754 + $n = substr($n, $substr_start, $substr_length);
2755 + } elseif ($substr_start !== false) {
2756 + $n = substr($n, $substr_start);
2757 + }
2758 + }
2759 + break;
2760 + case 'sreplace':
2761 + if (!empty($sreplace)) {
2762 + if (!empty($search) && count($search) === count($sreplace)) {
2763 + $replacements = array_combine($search, $sreplace);
2764 + if (is_array($replacements)) {
2765 + $n = strtr($n, $replacements);
2766 + }
2767 + }
2768 + }
2769 + break;
2770 + case 'ireplace':
2771 + if (!empty($ireplace)) {
2772 + $n = str_ireplace($search, $ireplace, $n);
2773 + }
2774 + break;
2775 + case 'replace':
2776 + if (!empty($replace)) {
2777 + $n = str_replace($search, $replace, $n);
2778 + }
2779 + break;
2780 + case 'remove_tags':
2781 + if ($remove_tags) {
2782 + $remove_tags_list = explode(',', $remove_tags);
2783 + foreach ($remove_tags_list as $remove_tag) {
2784 + if (in_array($remove_tag, $mixed_tags, true)) {
2785 + $n = preg_replace('#<' . $remove_tag . '(.*?)>(.*?)</' . $remove_tag . '>#is', '', $n);
2786 + $n = preg_replace('#<' . $remove_tag . '([^>]+)?\>#is', '', $n);
2787 + } elseif (in_array($remove_tag, $closed_tags, true)) {
2788 + $n = preg_replace('#<' . $remove_tag . '(.*?)>(.*?)</' . $remove_tag . '>#is', '', $n);
2789 + } else {
2790 + $n = preg_replace('#<' . $remove_tag . '([^>]+)?\>#is', '', $n);
2791 + }
2792 + }
2793 + }
2794 + break;
2795 + case 'basename':
2796 + $n = basename($n);
2797 + break;
2798 + case 'sprintf':
2799 + if ($sprintf !== false) {
2800 + $n = sprintf($sprintf, $n);
2801 + }
2802 + break;
2803 + case 'truncate':
2804 + $max_length = $truncate && intval($truncate) > 0 ? intval($truncate) : 100;
2805 + $n = $this->helper->load('truncate')->truncate($n, $max_length, $truncate_readmore, $truncate_breakwords, $truncate_ishtml);
2806 + break;
2807 + case 'truncate_html':
2808 + $max_length = $truncate_html && intval($truncate_html) > 0 ? intval($truncate_html) : 100;
2809 + $n = $this->helper->load('truncate')->truncate($n, $max_length, $truncate_readmore, $truncate_breakwords, true);
2810 + break;
1348 2811 default:
2812 + $n = apply_filters('e2pdf_model_shortcode_e2pdf_format_output_filter', $n, $sub_filter, $atts, $value);
1349 2813 break;
1350 2814 }
1351 2815 }
1352 2816 }
@@ -1353,87 +2817,308 @@
1353 2817 $new_value[] = $n;
1354 2818 }
1355 2819 unset($v);
1356 2820 }
1357 -
2821 + $new_value = apply_filters('e2pdf_model_shortcode_e2pdf_format_output_after_filter', $new_value, $atts, $value);
1358 2822 if ($output) {
1359 - $o_search = array();
1360 - $o_replace = array();
1361 -
1362 - foreach ($new_value as $key => $value) {
1363 - $o_search[] = "{" . $key . "}";
1364 - $o_replace[] = $value;
2823 + if ($output == '{count}') {
2824 + $response = count($new_value);
2825 + } elseif ($output == '{serialize}') {
2826 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
2827 + $response = serialize($new_value);
2828 + } else {
2829 + $o_search = [];
2830 + $o_replace = [];
2831 + foreach ($new_value as $key => $val) {
2832 + $o_search[] = '{' . $key . '}';
2833 + $o_replace[] = $val;
2834 + }
2835 + $output = str_replace($o_search, $o_replace, $output);
2836 + $response = preg_replace('~(?:{/?)[^/}]+/?}~s', '', $output);
1365 2837 }
1366 - $output = str_replace($o_search, $o_replace, $output);
1367 - return preg_replace('~(?:{/?)[^/}]+/?}~s', "", $output);
1368 2838 } else {
1369 - return implode($implode, $new_value);
2839 + if ($pre || $after) {
2840 + $wrapped = [];
2841 + foreach ($new_value as $key => $val) {
2842 + $wrapped[] = $pre . $val . $after;
2843 + }
2844 + $response = implode($implode, $wrapped);
2845 + } else {
2846 + $response = implode($implode, $new_value);
2847 + }
1370 2848 }
2849 +
2850 + if (!apply_filters('e2pdf_pdf_fill', false)) {
2851 + $response = $this->sanitize_html($response);
2852 + }
2853 + return apply_filters('e2pdf_model_shortcode_e2pdf_format_output', $response, $atts, $value);
1371 2854 }
1372 2855
1373 - /**
1374 - * [e2pdf-user] shortcode
1375 - *
1376 - * @param array $atts - Attributes
1377 - */
1378 - function e2pdf_user($atts = array()) {
2856 + // e2pdf-math
2857 + public function e2pdf_math($atts = [], $value = '') {
1379 2858
1380 - $id = isset($atts['id']) ? $atts['id'] : false;
1381 - $key = isset($atts['key']) ? $atts['key'] : false;
2859 + // phpcs:ignore Squiz.PHP.CommentedOutCode.Found
2860 + /*
2861 + * TODO: Prevent shortcode execution outside PDF rendering context
2862 + * if (!apply_filters('e2pdf_shortcode_enable_e2pdf_math', false) && !apply_filters('e2pdf_pdf_render', false)) {
2863 + * return '';
2864 + * }
2865 + */
2866 +
2867 + $thousands_sep_split = isset($atts['thousands_sep_split']) ? $atts['thousands_sep_split'] : ',';
2868 + $dec_point_split = isset($atts['dec_point_split']) ? $atts['dec_point_split'] : '.';
2869 + $default = isset($atts['default']) ? $atts['default'] : '0';
2870 + $value = strtr(
2871 + $value,
2872 + [
2873 + $thousands_sep_split => '',
2874 + $dec_point_split => '.',
2875 + '%%' => '¦',
2876 + ]
2877 + );
2878 + $value = $value ? $this->helper->load('math')->evaluate($value) : $default;
2879 +
2880 + $response = is_numeric($value) ? $this->e2pdf_format_number($atts, $value) : $value;
2881 + if (!apply_filters('e2pdf_pdf_fill', false)) {
2882 + $response = $this->sanitize_html($response);
2883 + }
2884 + return $response;
2885 + }
2886 +
2887 + // e2pdf-user
2888 + public function e2pdf_user($atts = [], $value = '') {
2889 +
2890 + if (!apply_filters('e2pdf_shortcode_enable_e2pdf_user', false) && !apply_filters('e2pdf_pdf_render', false)) {
2891 + return '';
2892 + }
2893 +
2894 + $atts = apply_filters('e2pdf_model_shortcode_e2pdf_user_atts', $atts);
2895 +
2896 + $id = isset($atts['id']) ? $atts['id'] : '0';
2897 +
2898 + if ($id == 'current') {
2899 + $id = get_current_user_id();
2900 + } elseif ($id == 'dynamic') {
2901 + $id = $value;
2902 + }
2903 +
2904 + $key = isset($atts['key']) ? $atts['key'] : 'ID';
1382 2905 $meta = isset($atts['meta']) && $atts['meta'] == 'true' ? true : false;
2906 + $path = isset($atts['path']) ? $atts['path'] : false;
2907 + $explode = isset($atts['explode']) ? $atts['explode'] : false;
2908 + $implode = isset($atts['implode']) ? $atts['implode'] : false;
2909 + $attachment_url = isset($atts['attachment_url']) && $atts['attachment_url'] == 'true' ? true : false;
2910 + $attachment_image_url = isset($atts['attachment_image_url']) && $atts['attachment_image_url'] == 'true' ? true : false;
2911 + $size = isset($atts['size']) ? $atts['size'] : 'thumbnail';
2912 + $has_cap = isset($atts['has_cap']) && $atts['has_cap'] ? $atts['has_cap'] : false;
2913 + $has_role = isset($atts['has_role']) && $atts['has_role'] ? $atts['has_role'] : false;
2914 + $convert = isset($atts['convert']) ? $atts['convert'] : false;
1383 2915
1384 2916 $response = '';
1385 2917
1386 - if ($id) {
1387 - $data_fields = array(
1388 - 'ID',
1389 - 'user_login',
1390 - 'user_nicename',
1391 - 'user_email',
1392 - 'user_url',
1393 - 'user_registered',
1394 - 'display_name'
1395 - );
2918 + $data_fields = apply_filters(
2919 + 'e2pdf_model_shortcode_user_data_fields',
2920 + [
2921 + 'ID',
2922 + 'user_description',
2923 + 'user_firstname',
2924 + 'user_lastname',
2925 + 'user_login',
2926 + 'user_nicename',
2927 + 'user_email',
2928 + 'user_url',
2929 + 'user_registered',
2930 + 'user_status',
2931 + 'user_level',
2932 + 'display_name',
2933 + 'spam',
2934 + 'deleted',
2935 + 'locale',
2936 + 'rich_editing',
2937 + 'syntax_highlighting',
2938 + 'use_ssl',
2939 + 'roles',
2940 + ]
2941 + );
1396 2942
1397 - $data_fields = apply_filters('e2pdf_model_shortcode_user_data_fields', $data_fields);
2943 + if ($has_cap) {
2944 + $user = get_userdata($id);
2945 + if ($user && $user->has_cap($has_cap)) {
2946 + $user_meta = 'true';
2947 + } else {
2948 + $user_meta = 'false';
2949 + }
2950 + } elseif ($has_role) {
2951 + $user = get_userdata($id);
2952 + if ($user && in_array($has_role, (array) $user->roles, true)) {
2953 + $user_meta = 'true';
2954 + } else {
2955 + $user_meta = 'false';
2956 + }
2957 + } elseif ($key && in_array($key, $data_fields, true) && !$meta) {
2958 + $user = get_userdata($id);
2959 + if (isset($user->$key)) {
2960 + $user_meta = $user->$key;
2961 + } elseif ($key == 'ID') {
2962 + $user_meta = '0';
2963 + } else {
2964 + $user_meta = false;
2965 + }
2966 + } elseif (($key == 'user_avatar' || $key == 'get_avatar_url') && !$meta) {
2967 + $user_meta = get_avatar_url($id, $atts);
2968 + } elseif ($key == 'get_avatar' && !$meta) {
2969 + $size = (int) $size;
2970 + if (!$size) {
2971 + $size = 96;
2972 + }
2973 + $user_meta = get_avatar($id, $size);
2974 + } elseif ($key) {
2975 + $user_meta = get_user_meta($id, $key, true);
2976 + } else {
2977 + $user_meta = false;
2978 + }
1398 2979
1399 - if ($key) {
1400 - if (in_array($key, $data_fields) && !$meta) {
1401 - $user = get_userdata($id);
1402 - if (isset($user->$key)) {
1403 - $response = $user->$key;
2980 + $user_meta = apply_filters('e2pdf_wp_user_meta', $user_meta, $id, $key, $atts);
2981 +
2982 + if ($user_meta !== false) {
2983 +
2984 + if (is_object($user_meta)) {
2985 + $user_meta = apply_filters('e2pdf_model_shortcode_e2pdf_user_object', $user_meta, $atts);
2986 + }
2987 +
2988 + if ($explode && !is_array($user_meta)) {
2989 + $user_meta = explode($explode, $user_meta);
2990 + }
2991 +
2992 + if (is_array($user_meta)) {
2993 + $user_meta = apply_filters('e2pdf_model_shortcode_e2pdf_user_array', $user_meta, $atts);
2994 + }
2995 +
2996 + if (is_string($user_meta) && $path !== false && is_object(json_decode($user_meta))) {
2997 + $user_meta = apply_filters('e2pdf_model_shortcode_e2pdf_user_json', json_decode($user_meta, true), $atts);
2998 + }
2999 +
3000 + if ((is_array($user_meta) || is_object($user_meta)) && $path !== false) {
3001 + $user_meta = $this->helper->load('shortcode')->apply_path_attribute($user_meta, $path);
3002 + }
3003 +
3004 + if ($attachment_url || $attachment_image_url) {
3005 + if (!is_array($user_meta)) {
3006 + if (strpos($user_meta, ',') !== false) {
3007 + $user_meta = explode(',', $user_meta);
3008 + if ($implode === false) {
3009 + $implode = ',';
3010 + }
1404 3011 }
3012 + }
3013 + if ($attachment_url) {
3014 + $user_meta = $this->helper->load('shortcode')->apply_attachment_attribute($user_meta, 'attachment_url', $size);
1405 3015 } else {
1406 - $response = get_user_meta($id, $key, true);
3016 + $user_meta = $this->helper->load('shortcode')->apply_attachment_attribute($user_meta, 'attachment_image_url', $size);
1407 3017 }
3018 + }
3019 +
3020 + if ($convert) {
3021 + $user_meta = $this->helper->load('shortcode')->apply_convert_attribute($convert, $user_meta, $implode);
3022 + }
3023 +
3024 + if (apply_filters('e2pdf_raw_output', false)) {
3025 + $response = $user_meta;
1408 3026 } else {
1409 - $response = $id;
3027 + if (is_array($user_meta)) {
3028 + if ($implode !== false) {
3029 + if (!$this->helper->is_multidimensional($user_meta)) {
3030 + foreach ($user_meta as $user_meta_key => $user_meta_value) {
3031 + $user_meta[$user_meta_key] = $this->helper->load('translator')->translate($user_meta_value);
3032 + }
3033 + $response = implode($implode, $user_meta);
3034 + } else {
3035 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
3036 + $response = serialize($user_meta);
3037 + }
3038 + } else {
3039 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
3040 + $response = serialize($user_meta);
3041 + }
3042 + } elseif (is_object($user_meta)) {
3043 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
3044 + $response = serialize($user_meta);
3045 + } else {
3046 + $response = $user_meta;
3047 + }
1410 3048 }
1411 3049 }
1412 - return $response;
3050 +
3051 + if (apply_filters('e2pdf_raw_output', false)) {
3052 + return apply_filters('e2pdf_model_shortcode_e2pdf_user_raw', $response, $atts, $value);
3053 + } else {
3054 + $response = $this->helper->load('translator')->translate($response, 'partial');
3055 + if (!apply_filters('e2pdf_pdf_fill', false)) {
3056 + $response = $this->sanitize_html($response);
3057 + }
3058 + return apply_filters('e2pdf_model_shortcode_e2pdf_user_response', $response, $atts, $value);
3059 + }
1413 3060 }
1414 3061
1415 - /**
1416 - * [e2pdf-content] shortcode
1417 - *
1418 - * @param array $atts - Attributes
1419 - * @param string $value - Content
1420 - */
1421 - function e2pdf_content($atts = array(), $value = '') {
3062 + // e2pdf-frm-field-value
3063 + public function e2pdf_frm_field_value($atts, $value = '') {
3064 +
3065 + if (!apply_filters('e2pdf_shortcode_enable_e2pdf_frm_field_value', false) && !apply_filters('e2pdf_pdf_render', false)) {
3066 + return '';
3067 + }
3068 +
1422 3069 $response = '';
3070 + if (class_exists('FrmProEntriesController')) {
3071 + foreach ($atts as $atts_key => $att) {
3072 + if ($att === 'dynamic') {
3073 + $atts[$atts_key] = $value;
3074 + }
3075 + }
3076 + $response = FrmProEntriesController::get_field_value_shortcode($atts);
3077 + }
1423 3078
3079 + if (!apply_filters('e2pdf_pdf_fill', false)) {
3080 + $response = $this->sanitize_html($response);
3081 + }
3082 + return apply_filters('e2pdf_model_shortcode_e2pdf_frm_field_value', $response, $atts, $value);
3083 + }
3084 +
3085 + public function e2pdf_translate($atts, $value = null) {
3086 + if (!apply_filters('e2pdf_shortcode_enable_e2pdf_translate', false) && !apply_filters('e2pdf_pdf_render', false)) {
3087 + return '';
3088 + }
3089 + $atts = shortcode_atts(
3090 + [
3091 + 'context' => '',
3092 + 'domain' => 'default',
3093 + ], $atts, 'e2pdf-translate'
3094 + );
3095 + if ($value) {
3096 + // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText, WordPress.WP.I18n.NonSingularStringLiteralContext, WordPress.WP.I18n.NonSingularStringLiteralDomain
3097 + return _x($value, $atts['context'], $atts['domain']);
3098 + }
3099 + return '';
3100 + }
3101 +
3102 + // e2pdf-content
3103 + public function e2pdf_content($atts = [], $value = '') {
3104 +
3105 + $response = '';
3106 +
3107 + $atts = apply_filters('e2pdf_model_shortcode_e2pdf_content_atts', $atts);
3108 +
1424 3109 $id = isset($atts['id']) ? $atts['id'] : false;
1425 3110 $key = isset($atts['key']) ? $atts['key'] : false;
1426 3111
1427 3112 if ($id && $key) {
1428 - $post = get_post($id);
1429 - if ($post) {
1430 - if (isset($post->post_content) && $post->post_content) {
1431 - $content = $this->helper->load('convert')->to_content_key($key, $post->post_content);
3113 + $wp_post = get_post($id);
3114 + if ($wp_post) {
3115 + if (isset($wp_post->post_content) && $wp_post->post_content) {
3116 + $content = $this->helper->load('convert')->is_content_key($key, $wp_post->post_content);
1432 3117 remove_filter('the_content', 'wpautop');
1433 - $content = apply_filters('the_content', $content);
3118 + $content = apply_filters('the_content', $content, $id);
1434 3119 add_filter('the_content', 'wpautop');
1435 - $content = str_replace("</p>", "</p>\r\n", $content);
3120 + $content = str_replace('</p>', "</p>\r\n", $content);
1436 3121 $response = $content;
1437 3122 }
1438 3123 }
1439 3124 } elseif ($value) {
@@ -1441,248 +3126,3618 @@
1441 3126 }
1442 3127 return $response;
1443 3128 }
1444 3129
1445 - /**
1446 - * [e2pdf-exclude] shortcode
1447 - *
1448 - * @param array $atts - Attributes
1449 - * @param string $value - Content
1450 - */
1451 - function e2pdf_exclude($atts = array(), $value = '') {
3130 + // e2pdf-exclude
3131 + public function e2pdf_exclude($atts = [], $value = '') {
3132 + $atts = apply_filters('e2pdf_model_shortcode_e2pdf_exclude_atts', $atts);
3133 + $attributes = (new Helper_E2pdf_Atts())->load($atts);
3134 + return $attributes->get('apply') ? '' : apply_filters('the_content', $value);
3135 + }
1452 3136
1453 - $apply = isset($atts['apply']) ? true : false;
3137 + // e2pdf-wp
3138 + public function e2pdf_wp($atts = [], $value = '') {
1454 3139
1455 - if ($apply) {
1456 - $response = '';
3140 + if (!apply_filters('e2pdf_shortcode_enable_e2pdf_wp', false) && !apply_filters('e2pdf_pdf_render', false)) {
3141 + return '';
3142 + }
3143 +
3144 + $post_meta = false;
3145 + $response = '';
3146 +
3147 + $atts = apply_filters('e2pdf_model_shortcode_e2pdf_wp_atts', $atts);
3148 +
3149 + $id = isset($atts['id']) ? $atts['id'] : false;
3150 + $key = isset($atts['key']) ? $atts['key'] : false;
3151 + $subkey = isset($atts['subkey']) ? $atts['subkey'] : false;
3152 + $path = isset($atts['path']) ? $atts['path'] : false;
3153 + $names = isset($atts['names']) && $atts['names'] == 'true' ? true : false;
3154 + $explode = isset($atts['explode']) ? $atts['explode'] : false;
3155 + $implode = isset($atts['implode']) ? $atts['implode'] : false;
3156 + $attachment_url = isset($atts['attachment_url']) && $atts['attachment_url'] == 'true' ? true : false;
3157 + $attachment_image_url = isset($atts['attachment_image_url']) && $atts['attachment_image_url'] == 'true' ? true : false;
3158 + $size = isset($atts['size']) ? $atts['size'] : 'thumbnail';
3159 + $meta = isset($atts['meta']) && $atts['meta'] == 'true' ? true : false;
3160 + $terms = isset($atts['terms']) && $atts['terms'] == 'true' ? true : false;
3161 + $output = isset($atts['output']) ? $atts['output'] : false;
3162 + $convert = isset($atts['convert']) ? $atts['convert'] : false;
3163 +
3164 + /* Backward compatibility */
3165 + if ($convert == 'id_to_term') {
3166 + if ($subkey) {
3167 + $convert = 'term_id_to_' . $subkey;
3168 + } else {
3169 + $convert = 'term_id_to_term';
3170 + }
3171 + }
3172 +
3173 + if ($id == 'dynamic') {
3174 + $id = $value;
3175 + }
3176 +
3177 + $data_fields = apply_filters(
3178 + 'e2pdf_model_shortcode_wp_data_fields',
3179 + [
3180 + 'id',
3181 + 'post_author',
3182 + 'post_author_id',
3183 + 'post_date',
3184 + 'post_date_gmt',
3185 + 'post_content',
3186 + 'post_title',
3187 + 'post_excerpt',
3188 + 'post_status',
3189 + 'permalink',
3190 + 'post_permalink',
3191 + 'get_permalink',
3192 + 'get_post_permalink',
3193 + 'comment_status',
3194 + 'ping_status',
3195 + 'post_password',
3196 + 'post_name',
3197 + 'to_ping',
3198 + 'pinged',
3199 + 'post_modified',
3200 + 'post_modified_gmt',
3201 + 'post_content_filtered',
3202 + 'post_parent',
3203 + 'guid',
3204 + 'menu_order',
3205 + 'post_type',
3206 + 'post_mime_type',
3207 + 'comment_count',
3208 + 'filter',
3209 + 'post_thumbnail',
3210 + 'get_the_post_thumbnail',
3211 + 'get_the_post_thumbnail_url',
3212 + 'response_hook',
3213 + ]
3214 + );
3215 +
3216 + if ($id && $key) {
3217 + $wp_post = get_post($id);
3218 + if ($wp_post) {
3219 + if (in_array($key, $data_fields, true) && !$meta && !$terms) {
3220 + if ($key == 'post_author') {
3221 + if (isset($wp_post->post_author) && $wp_post->post_author) {
3222 + if (isset($atts['subkey'])) {
3223 + $atts['id'] = $wp_post->post_author;
3224 + $atts['key'] = $subkey;
3225 + $post_meta = $this->e2pdf_user($atts);
3226 + } else {
3227 + $post_meta = get_userdata($wp_post->post_author)->user_nicename;
3228 + }
3229 + }
3230 + } elseif ($key == 'post_author_id') {
3231 + $post_meta = isset($wp_post->post_author) && $wp_post->post_author ? $wp_post->post_author : '0';
3232 + } elseif ($key == 'id' && isset($wp_post->ID)) {
3233 + $post_meta = $wp_post->ID;
3234 + } elseif (($key == 'post_thumbnail' || $key == 'get_the_post_thumbnail_url') && isset($wp_post->ID)) {
3235 + $post_meta = get_the_post_thumbnail_url($wp_post->ID, $size);
3236 + } elseif ($key == 'get_the_post_thumbnail' && isset($wp_post->ID)) {
3237 + $post_meta = get_the_post_thumbnail($wp_post->ID, $size);
3238 + } elseif ($key == 'post_content' && isset($wp_post->post_content)) {
3239 + $content = $wp_post->post_content;
3240 + if (false !== strpos($content, '[')) {
3241 + $shortcode_tags = [
3242 + 'e2pdf-exclude',
3243 + 'e2pdf-save',
3244 + 'e2pdf-view',
3245 + ];
3246 + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
3247 + $tagnames = array_intersect($shortcode_tags, $matches[1]);
3248 + if (!empty($tagnames)) {
3249 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
3250 + foreach ($shortcodes[0] as $key => $shortcode_value) {
3251 + $content = str_replace($shortcode_value, '', $content);
3252 + }
3253 + }
3254 + }
3255 + if ($output) {
3256 + global $post;
3257 + $tmp_post = $post;
3258 + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
3259 + $post = $wp_post;
3260 + if ($output == 'backend') {
3261 + if (did_action('elementor/loaded') && class_exists('\Elementor\Plugin')) {
3262 + \Elementor\Plugin::instance()->frontend->remove_content_filter();
3263 + }
3264 + } elseif ($output == 'frontend') {
3265 + if (did_action('elementor/loaded') && class_exists('\Elementor\Plugin')) {
3266 + \Elementor\Plugin::instance()->frontend->add_content_filter();
3267 + }
3268 + }
3269 + }
3270 +
3271 + if (defined('ET_BUILDER_DIR') && 'on' === get_post_meta($id, '_et_pb_use_builder', true) && function_exists('et_builder_init_global_settings') && function_exists('et_builder_add_main_elements')) {
3272 + if (file_exists(ET_BUILDER_DIR . 'class-et-builder-value.php') && !class_exists('ET_Builder_Value')) {
3273 + require_once ET_BUILDER_DIR . 'class-et-builder-value.php';
3274 + }
3275 + require_once ET_BUILDER_DIR . 'class-et-builder-element.php';
3276 + require_once ET_BUILDER_DIR . 'functions.php';
3277 + require_once ET_BUILDER_DIR . 'ab-testing.php';
3278 + require_once ET_BUILDER_DIR . 'class-et-global-settings.php';
3279 + et_builder_add_main_elements();
3280 + }
3281 +
3282 + if (class_exists('WPBMap') && method_exists('WPBMap', 'addAllMappedShortcodes')) {
3283 + WPBMap::addAllMappedShortcodes();
3284 + }
3285 +
3286 + $content = apply_filters('the_content', $content, $id);
3287 + $content = str_replace('</p>', "</p>\r\n", $content);
3288 + $post_meta = $content;
3289 +
3290 + if ($output) {
3291 + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
3292 + $post = $tmp_post;
3293 + }
3294 + } elseif ($key == 'get_permalink' || $key == 'permalink') {
3295 + $leavename = isset($atts['leavename']) && $atts['leavename'] == 'true' ? true : false;
3296 + $post_meta = get_permalink($id, $leavename);
3297 + $post_meta = $this->helper->load('translator')->translate_url($post_meta);
3298 + } elseif ($key == 'get_post_permalink' || $key == 'post_permalink') {
3299 + $leavename = isset($atts['leavename']) && $atts['leavename'] == 'true' ? true : false;
3300 + $post_meta = get_post_permalink($id, $leavename);
3301 + $post_meta = $this->helper->load('translator')->translate_url($post_meta);
3302 + } elseif ($key == 'response_hook') {
3303 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wp_response_hook', '', $id, $atts, $wp_post);
3304 + } elseif (isset($wp_post->$key)) {
3305 + $post_meta = $wp_post->$key;
3306 + }
3307 + } elseif ($terms && $names) {
3308 + $post_terms = wp_get_post_terms($id, $key, ['fields' => 'names']);
3309 + if (!is_wp_error($post_terms) && is_array($post_terms)) {
3310 + foreach ($post_terms as $post_term_key => $post_terms_value) {
3311 + $post_terms[$post_term_key] = $this->helper->load('translator')->translate($post_terms_value);
3312 + }
3313 + if ($implode === false) {
3314 + $implode = ', ';
3315 + }
3316 + $post_meta = implode($implode, $post_terms);
3317 + }
3318 + } elseif ($terms) {
3319 + $post_terms = wp_get_post_terms($id, $key);
3320 + if (!is_wp_error($post_terms)) {
3321 + // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
3322 + $post_meta = json_decode(json_encode($post_terms), true);
3323 + }
3324 + } else {
3325 + $post_meta = get_post_meta($id, $key, true);
3326 + }
3327 +
3328 + $post_meta = apply_filters('e2pdf_wp_post_meta', $post_meta, $id, $key, $atts);
3329 +
3330 + if ($post_meta !== false) {
3331 +
3332 + if (is_object($post_meta)) {
3333 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wp_object', $post_meta, $atts);
3334 + }
3335 +
3336 + if ($explode && !is_array($post_meta)) {
3337 + $post_meta = explode($explode, $post_meta);
3338 + }
3339 +
3340 + if (is_array($post_meta)) {
3341 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wp_array', $post_meta, $atts);
3342 + }
3343 +
3344 + if (is_string($post_meta) && $path !== false && is_object(json_decode($post_meta))) {
3345 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wp_json', json_decode($post_meta, true), $atts);
3346 + }
3347 +
3348 + if ((is_array($post_meta) || is_object($post_meta)) && $path !== false) {
3349 + $post_meta = $this->helper->load('shortcode')->apply_path_attribute($post_meta, $path);
3350 + }
3351 +
3352 + if ($attachment_url || $attachment_image_url) {
3353 + if (!is_array($post_meta)) {
3354 + if (strpos($post_meta, ',') !== false) {
3355 + $post_meta = explode(',', $post_meta);
3356 + if ($implode === false) {
3357 + $implode = ',';
3358 + }
3359 + }
3360 + }
3361 + if ($attachment_url) {
3362 + $post_meta = $this->helper->load('shortcode')->apply_attachment_attribute($post_meta, 'attachment_url', $size);
3363 + } else {
3364 + $post_meta = $this->helper->load('shortcode')->apply_attachment_attribute($post_meta, 'attachment_image_url', $size);
3365 + }
3366 + }
3367 +
3368 + if ($convert) {
3369 + $post_meta = $this->helper->load('shortcode')->apply_convert_attribute($convert, $post_meta, $implode);
3370 + }
3371 +
3372 + if (apply_filters('e2pdf_raw_output', false)) {
3373 + $response = $post_meta;
3374 + } else {
3375 + if (is_array($post_meta)) {
3376 + if ($implode !== false) {
3377 + if (!$this->helper->is_multidimensional($post_meta)) {
3378 + foreach ($post_meta as $post_meta_key => $post_meta_value) {
3379 + $post_meta[$post_meta_key] = $this->helper->load('translator')->translate($post_meta_value, 'default', $id);
3380 + }
3381 + $response = implode($implode, $post_meta);
3382 + } else {
3383 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
3384 + $response = serialize($post_meta);
3385 + }
3386 + } else {
3387 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
3388 + $response = serialize($post_meta);
3389 + }
3390 + } elseif (is_object($post_meta)) {
3391 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
3392 + $response = serialize($post_meta);
3393 + } else {
3394 + $response = $post_meta;
3395 + }
3396 + }
3397 + }
3398 + }
3399 + }
3400 +
3401 + if (apply_filters('e2pdf_raw_output', false)) {
3402 + return apply_filters('e2pdf_model_shortcode_e2pdf_wp_raw', $response, $atts, $value);
1457 3403 } else {
1458 - $response = apply_filters('the_content', $value);
3404 + $response = $this->helper->load('translator')->translate($response, 'partial', $id);
3405 + if (!apply_filters('e2pdf_pdf_fill', false)) {
3406 + $response = $this->sanitize_html($response);
3407 + }
3408 + return apply_filters('e2pdf_model_shortcode_e2pdf_wp_response', $response, $atts, $value);
1459 3409 }
3410 + }
1460 3411
1461 - return $response;
3412 + // e2pdf-wp-term
3413 + public function e2pdf_wp_term($atts = [], $value = '') {
3414 +
3415 + if (!apply_filters('e2pdf_shortcode_enable_e2pdf_wp_term', false) && !apply_filters('e2pdf_pdf_render', false)) {
3416 + return '';
3417 + }
3418 +
3419 + $post_meta = false;
3420 + $response = '';
3421 +
3422 + $id = isset($atts['id']) ? $atts['id'] : false;
3423 + $key = isset($atts['key']) ? $atts['key'] : false;
3424 + $meta = isset($atts['meta']) && $atts['meta'] == 'true' ? true : false;
3425 + $implode = isset($atts['implode']) ? $atts['implode'] : false;
3426 + $explode = isset($atts['explode']) ? $atts['explode'] : false;
3427 + $attachment_url = isset($atts['attachment_url']) && $atts['attachment_url'] == 'true' ? true : false;
3428 + $attachment_image_url = isset($atts['attachment_image_url']) && $atts['attachment_image_url'] == 'true' ? true : false;
3429 + $size = isset($atts['size']) ? $atts['size'] : 'thumbnail';
3430 + $path = isset($atts['path']) ? $atts['path'] : false;
3431 +
3432 + if ($id == 'dynamic') {
3433 + $id = $value;
3434 + }
3435 +
3436 + if ($id && $key) {
3437 + $wp_post = get_term($id);
3438 + if ($wp_post && !is_wp_error($wp_post)) {
3439 + if (!$meta) {
3440 + if (isset($wp_post->$key)) {
3441 + $post_meta = $wp_post->$key;
3442 + }
3443 + } else {
3444 + $post_meta = get_term_meta($id, $key, true);
3445 + }
3446 +
3447 + $post_meta = apply_filters('e2pdf_wp_term_meta', $post_meta, $id, $key, $atts);
3448 +
3449 + if ($post_meta !== false) {
3450 +
3451 + if (is_object($post_meta)) {
3452 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wp_term_object', $post_meta, $atts);
3453 + }
3454 +
3455 + if ($explode && !is_array($post_meta)) {
3456 + $post_meta = explode($explode, $post_meta);
3457 + }
3458 +
3459 + if (is_array($post_meta)) {
3460 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wp_term_array', $post_meta, $atts);
3461 + }
3462 +
3463 + if (is_string($post_meta) && $path !== false && is_object(json_decode($post_meta))) {
3464 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wp_term_json', json_decode($post_meta, true), $atts);
3465 + }
3466 +
3467 + if ((is_array($post_meta) || is_object($post_meta)) && $path !== false) {
3468 + $post_meta = $this->helper->load('shortcode')->apply_path_attribute($post_meta, $path);
3469 + }
3470 +
3471 + if ($attachment_url || $attachment_image_url) {
3472 + if (!is_array($post_meta)) {
3473 + if (strpos($post_meta, ',') !== false) {
3474 + $post_meta = explode(',', $post_meta);
3475 + if ($implode === false) {
3476 + $implode = ',';
3477 + }
3478 + }
3479 + }
3480 + if ($attachment_url) {
3481 + $post_meta = $this->helper->load('shortcode')->apply_attachment_attribute($post_meta, 'attachment_url', $size);
3482 + } else {
3483 + $post_meta = $this->helper->load('shortcode')->apply_attachment_attribute($post_meta, 'attachment_image_url', $size);
3484 + }
3485 + }
3486 +
3487 + if (apply_filters('e2pdf_raw_output', false)) {
3488 + $response = $post_meta;
3489 + } else {
3490 + if (is_array($post_meta)) {
3491 + if ($implode !== false) {
3492 + if (!$this->helper->is_multidimensional($post_meta)) {
3493 + foreach ($post_meta as $post_meta_key => $post_meta_value) {
3494 + $post_meta[$post_meta_key] = $this->helper->load('translator')->translate($post_meta_value);
3495 + }
3496 + $response = implode($implode, $post_meta);
3497 + } else {
3498 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
3499 + $response = serialize($post_meta);
3500 + }
3501 + } else {
3502 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
3503 + $response = serialize($post_meta);
3504 + }
3505 + } elseif (is_object($post_meta)) {
3506 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
3507 + $response = serialize($post_meta);
3508 + } else {
3509 + $response = $post_meta;
3510 + }
3511 + }
3512 + }
3513 + }
3514 + }
3515 +
3516 + if (apply_filters('e2pdf_raw_output', false)) {
3517 + return apply_filters('e2pdf_model_shortcode_e2pdf_wp_term_raw', $response, $atts, $value);
3518 + } else {
3519 + $response = $this->helper->load('translator')->translate($response, 'partial');
3520 + if (!apply_filters('e2pdf_pdf_fill', false)) {
3521 + $response = $this->sanitize_html($response);
3522 + }
3523 + return apply_filters('e2pdf_model_shortcode_e2pdf_wp_term_response', $response, $atts, $value);
3524 + }
1462 3525 }
1463 3526
1464 - /**
1465 - * [e2pdf-wp] shortcode
1466 - *
1467 - * @param array $atts - Attributes
1468 - * @param string $value - Content
1469 - */
1470 - function e2pdf_wp($atts = array(), $value = '') {
3527 + // e2pdf-wp-posts
3528 + public function e2pdf_wp_posts($atts = [], $value = '') {
1471 3529
3530 + if (!apply_filters('e2pdf_shortcode_enable_e2pdf_wp_posts', false) && !apply_filters('e2pdf_pdf_render', false)) {
3531 + return '';
3532 + }
3533 +
3534 + $post_meta = false;
1472 3535 $response = '';
1473 3536
3537 + $atts = apply_filters('e2pdf_model_shortcode_e2pdf_posts_atts', $atts);
3538 +
3539 + $path = isset($atts['path']) ? $atts['path'] : false;
3540 + $explode = isset($atts['explode']) ? $atts['explode'] : false;
3541 + $implode = isset($atts['implode']) ? $atts['implode'] : false;
3542 + $attachment_url = isset($atts['attachment_url']) && $atts['attachment_url'] == 'true' ? true : false;
3543 + $attachment_image_url = isset($atts['attachment_image_url']) && $atts['attachment_image_url'] == 'true' ? true : false;
3544 + $size = isset($atts['size']) ? $atts['size'] : 'thumbnail';
3545 +
3546 + $args = [];
3547 +
3548 + if (isset($atts['fields'])) {
3549 + $args['fields'] = $atts['fields'];
3550 + }
3551 +
3552 + if (isset($atts['numberposts'])) {
3553 + $args['numberposts'] = $atts['numberposts'];
3554 + }
3555 +
3556 + if (isset($atts['posts_per_page'])) {
3557 + $args['posts_per_page'] = $atts['posts_per_page'];
3558 + }
3559 +
3560 + if (isset($atts['offset'])) {
3561 + $args['offset'] = $atts['offset'];
3562 + }
3563 +
3564 + if (isset($atts['category'])) {
3565 + $category = $atts['category'] == 'dynamic' ? $value : $atts['category'];
3566 + $args['category'] = $category;
3567 + }
3568 +
3569 + if (isset($atts['category_name'])) {
3570 + $args['category_name'] = $atts['category_name'];
3571 + }
3572 +
3573 + if (isset($atts['tag'])) {
3574 + $args['tag'] = $atts['tag'];
3575 + }
3576 +
3577 + if (isset($atts['include'])) {
3578 + $args['include'] = explode(',', $atts['include']);
3579 + }
3580 +
3581 + if (isset($atts['exclude'])) {
3582 + $args['exclude'] = explode(',', $atts['exclude']);
3583 + }
3584 +
3585 + if (isset($atts['meta_key'])) {
3586 + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
3587 + $args['meta_key'] = $atts['meta_key'];
3588 + }
3589 +
3590 + if (isset($atts['meta_value'])) {
3591 + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
3592 + $args['meta_value'] = $atts['meta_value'];
3593 + }
3594 +
3595 + if (isset($atts['post_type'])) {
3596 + $args['post_type'] = explode(',', $atts['post_type']);
3597 + }
3598 +
3599 + if (isset($atts['post_mime_type'])) {
3600 + $args['post_mime_type'] = explode(',', $atts['post_mime_type']);
3601 + }
3602 +
3603 + if (isset($atts['post_status'])) {
3604 + $args['post_status'] = $atts['post_status'];
3605 + }
3606 +
3607 + if (isset($atts['post_parent'])) {
3608 + $args['post_parent'] = $atts['post_parent'];
3609 + }
3610 +
3611 + if (isset($atts['nopaging'])) {
3612 + $args['nopaging'] = $atts['nopaging'] === 'true' ? true : false;
3613 + }
3614 +
3615 + if (isset($atts['orderby'])) {
3616 + $args['orderby'] = $atts['orderby'];
3617 + }
3618 +
3619 + if (isset($atts['order'])) {
3620 + $args['order'] = $atts['order'];
3621 + }
3622 +
3623 + if (isset($atts['meta_value_list'])) {
3624 + $args['meta_value_list'] = explode(',', $atts['meta_value_list']);
3625 + }
3626 +
3627 + if (isset($atts['suppress_filters'])) {
3628 + $args['suppress_filters'] = $args['suppress_filters'] === 'true' ? true : false;
3629 + }
3630 +
3631 + $tax_query = [];
3632 + foreach ($atts as $att_key => $att_value) {
3633 + if (substr($att_key, 0, 9) === 'tax_query') {
3634 + $tax = explode('|||', $att_value, 5);
3635 + if (count($tax) >= 3) {
3636 + $tax_query[] = [
3637 + 'taxonomy' => $tax[0],
3638 + 'field' => $tax[1],
3639 + 'terms' => explode(',', $tax[2]),
3640 + 'operator' => isset($tax[3]) ? $tax[3] : 'IN',
3641 + 'include_children' => isset($tax[4]) && $tax[4] == 'false' ? false : true,
3642 + ];
3643 + }
3644 + }
3645 + }
3646 + if (!empty($tax_query)) {
3647 + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
3648 + $args['tax_query'] = $tax_query;
3649 + }
3650 +
3651 + $post_meta = get_posts(
3652 + apply_filters('e2pdf_model_shortcode_e2pdf_posts_args', $args, $atts, $value)
3653 + );
3654 +
3655 + if ($post_meta !== false) {
3656 +
3657 + if (is_object($post_meta)) {
3658 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_posts_object', $post_meta, $atts);
3659 + }
3660 +
3661 + if ($explode && !is_array($post_meta)) {
3662 + $post_meta = explode($explode, $post_meta);
3663 + }
3664 +
3665 + if (is_array($post_meta)) {
3666 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_posts_array', $post_meta, $atts);
3667 + }
3668 +
3669 + if (is_string($post_meta) && $path !== false && is_object(json_decode($post_meta))) {
3670 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_posts_json', json_decode($post_meta, true), $atts);
3671 + }
3672 +
3673 + if ((is_array($post_meta) || is_object($post_meta)) && $path !== false) {
3674 + $post_meta = $this->helper->load('shortcode')->apply_path_attribute($post_meta, $path);
3675 + }
3676 +
3677 + if ($attachment_url || $attachment_image_url) {
3678 + if (!is_array($post_meta)) {
3679 + if (strpos($post_meta, ',') !== false) {
3680 + $post_meta = explode(',', $post_meta);
3681 + if ($implode === false) {
3682 + $implode = ',';
3683 + }
3684 + }
3685 + }
3686 + if ($attachment_url) {
3687 + $post_meta = $this->helper->load('shortcode')->apply_attachment_attribute($post_meta, 'attachment_url', $size);
3688 + } else {
3689 + $post_meta = $this->helper->load('shortcode')->apply_attachment_attribute($post_meta, 'attachment_image_url', $size);
3690 + }
3691 + }
3692 +
3693 + if (apply_filters('e2pdf_raw_output', false)) {
3694 + $response = $post_meta;
3695 + } else {
3696 + if (is_array($post_meta)) {
3697 + if ($implode !== false) {
3698 + if (!$this->helper->is_multidimensional($post_meta)) {
3699 + foreach ($post_meta as $post_meta_key => $post_meta_value) {
3700 + $post_meta[$post_meta_key] = $this->helper->load('translator')->translate($post_meta_value);
3701 + }
3702 + $response = implode($implode, $post_meta);
3703 + } else {
3704 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
3705 + $response = serialize($post_meta);
3706 + }
3707 + } else {
3708 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
3709 + $response = serialize($post_meta);
3710 + }
3711 + } elseif (is_object($post_meta)) {
3712 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
3713 + $response = serialize($post_meta);
3714 + } else {
3715 + $response = $post_meta;
3716 + }
3717 + }
3718 + }
3719 +
3720 + if (apply_filters('e2pdf_raw_output', false)) {
3721 + return apply_filters('e2pdf_model_shortcode_e2pdf_posts_raw', $response, $atts, $value);
3722 + } else {
3723 + $response = $this->helper->load('translator')->translate($response, 'partial');
3724 + if (!apply_filters('e2pdf_pdf_fill', false)) {
3725 + $response = $this->sanitize_html($response);
3726 + }
3727 + return apply_filters('e2pdf_model_shortcode_e2pdf_posts_response', $response, $atts, $value);
3728 + }
3729 + }
3730 +
3731 + // e2pdf-wp-users
3732 + public function e2pdf_wp_users($atts = [], $value = '') {
3733 +
3734 + if (!apply_filters('e2pdf_shortcode_enable_e2pdf_wp_users', false) && !apply_filters('e2pdf_pdf_render', false)) {
3735 + return '';
3736 + }
3737 +
3738 + $post_meta = false;
3739 + $response = '';
3740 +
3741 + $atts = apply_filters('e2pdf_model_shortcode_e2pdf_users_atts', $atts);
3742 +
3743 + $path = isset($atts['path']) ? $atts['path'] : false;
3744 + $explode = isset($atts['explode']) ? $atts['explode'] : false;
3745 + $implode = isset($atts['implode']) ? $atts['implode'] : false;
3746 + $attachment_url = isset($atts['attachment_url']) && $atts['attachment_url'] == 'true' ? true : false;
3747 + $attachment_image_url = isset($atts['attachment_image_url']) && $atts['attachment_image_url'] == 'true' ? true : false;
3748 + $size = isset($atts['size']) ? $atts['size'] : 'thumbnail';
3749 +
3750 + $args = [];
3751 +
3752 + if (isset($atts['fields'])) {
3753 + $args['fields'] = $atts['fields'];
3754 + }
3755 +
3756 + if (isset($atts['search'])) {
3757 + $args['search'] = $atts['search'];
3758 + }
3759 +
3760 + $post_meta = get_users(
3761 + apply_filters('e2pdf_model_shortcode_e2pdf_users_args', $args, $atts, $value)
3762 + );
3763 +
3764 + if ($post_meta !== false) {
3765 +
3766 + if (is_object($post_meta)) {
3767 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_users_object', $post_meta, $atts);
3768 + }
3769 +
3770 + if ($explode && !is_array($post_meta)) {
3771 + $post_meta = explode($explode, $post_meta);
3772 + }
3773 +
3774 + if (is_array($post_meta)) {
3775 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_users_array', $post_meta, $atts);
3776 + }
3777 +
3778 + if (is_string($post_meta) && $path !== false && is_object(json_decode($post_meta))) {
3779 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_users_json', json_decode($post_meta, true), $atts);
3780 + }
3781 +
3782 + if ((is_array($post_meta) || is_object($post_meta)) && $path !== false) {
3783 + $post_meta = $this->helper->load('shortcode')->apply_path_attribute($post_meta, $path);
3784 + }
3785 +
3786 + if ($attachment_url || $attachment_image_url) {
3787 + if (!is_array($post_meta)) {
3788 + if (strpos($post_meta, ',') !== false) {
3789 + $post_meta = explode(',', $post_meta);
3790 + if ($implode === false) {
3791 + $implode = ',';
3792 + }
3793 + }
3794 + }
3795 + if ($attachment_url) {
3796 + $post_meta = $this->helper->load('shortcode')->apply_attachment_attribute($post_meta, 'attachment_url', $size);
3797 + } else {
3798 + $post_meta = $this->helper->load('shortcode')->apply_attachment_attribute($post_meta, 'attachment_image_url', $size);
3799 + }
3800 + }
3801 +
3802 + if (apply_filters('e2pdf_raw_output', false)) {
3803 + $response = $post_meta;
3804 + } else {
3805 + if (is_array($post_meta)) {
3806 + if ($implode !== false) {
3807 + if (!$this->helper->is_multidimensional($post_meta)) {
3808 + foreach ($post_meta as $post_meta_key => $post_meta_value) {
3809 + $post_meta[$post_meta_key] = $this->helper->load('translator')->translate($post_meta_value);
3810 + }
3811 + $response = implode($implode, $post_meta);
3812 + } else {
3813 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
3814 + $response = serialize($post_meta);
3815 + }
3816 + } else {
3817 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
3818 + $response = serialize($post_meta);
3819 + }
3820 + } elseif (is_object($post_meta)) {
3821 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
3822 + $response = serialize($post_meta);
3823 + } else {
3824 + $response = $post_meta;
3825 + }
3826 + }
3827 + }
3828 +
3829 + if (apply_filters('e2pdf_raw_output', false)) {
3830 + return apply_filters('e2pdf_model_shortcode_e2pdf_users_raw', $response, $atts, $value);
3831 + } else {
3832 + $response = $this->helper->load('translator')->translate($response, 'partial');
3833 + if (!apply_filters('e2pdf_pdf_fill', false)) {
3834 + $response = $this->sanitize_html($response);
3835 + }
3836 + return apply_filters('e2pdf_model_shortcode_e2pdf_users_response', $response, $atts, $value);
3837 + }
3838 + }
3839 +
3840 + // e2pdf-wc-product
3841 + public function e2pdf_wc_product($atts = [], $value = '') {
3842 +
3843 + if (!apply_filters('e2pdf_shortcode_enable_e2pdf_wc_product', false) && !apply_filters('e2pdf_pdf_render', false)) {
3844 + return '';
3845 + }
3846 +
3847 + $post_meta = false;
3848 + $response = '';
3849 +
3850 + $atts = apply_filters('e2pdf_model_shortcode_e2pdf_wc_product_atts', $atts);
3851 +
1474 3852 $id = isset($atts['id']) ? $atts['id'] : false;
3853 + $index = isset($atts['index']) ? $atts['index'] : false;
3854 + $wc_product_item_id = isset($atts['wc_product_item_id']) ? $atts['wc_product_item_id'] : false;
1475 3855 $key = isset($atts['key']) ? $atts['key'] : false;
1476 3856 $path = isset($atts['path']) ? $atts['path'] : false;
1477 3857 $names = isset($atts['names']) && $atts['names'] == 'true' ? true : false;
1478 - $explode = isset($atts['explode']) ? $atts['explode'] : '.';
1479 - $implode = isset($atts['implode']) ? $atts['implode'] : ', ';
3858 + $explode = isset($atts['explode']) ? $atts['explode'] : false;
3859 + $implode = isset($atts['implode']) ? $atts['implode'] : false;
1480 3860 $attachment_url = isset($atts['attachment_url']) && $atts['attachment_url'] == 'true' ? true : false;
1481 3861 $attachment_image_url = isset($atts['attachment_image_url']) && $atts['attachment_image_url'] == 'true' ? true : false;
1482 3862 $size = isset($atts['size']) ? $atts['size'] : 'thumbnail';
1483 3863 $meta = isset($atts['meta']) && $atts['meta'] == 'true' ? true : false;
3864 + $output = isset($atts['output']) ? $atts['output'] : false;
1484 3865 $terms = isset($atts['terms']) && $atts['terms'] == 'true' ? true : false;
3866 + $parent = isset($atts['parent']) && $atts['parent'] == 'true' ? true : false;
3867 + $wc_order_id = isset($atts['wc_order_id']) ? $atts['wc_order_id'] : false;
3868 + $download_index = isset($atts['download_index']) ? $atts['download_index'] : false;
3869 + $attribute = isset($atts['attribute']) ? $atts['attribute'] : false;
3870 + $order = isset($atts['order']) && $atts['order'] == 'true' ? true : false;
3871 + $detached = isset($atts['detached']) && $atts['detached'] == 'true' ? true : false;
3872 + $order_item_meta = isset($atts['order_item_meta']) && $atts['order_item_meta'] == 'true' ? true : false;
3873 + $wc_filter = isset($atts['wc_filter']) && $atts['wc_filter'] == 'true' ? true : false;
3874 + $convert = isset($atts['convert']) ? $atts['convert'] : false;
3875 + $wc_price = isset($atts['wc_price']) && $atts['wc_price'] == 'true' ? true : false;
3876 + $wc_price_raw = isset($atts['wc_price_raw']) && $atts['wc_price_raw'] == 'true' ? true : false;
1485 3877
1486 - $data_fields = array(
1487 - 'id',
1488 - 'post_author',
1489 - 'post_date',
1490 - 'post_date_gmt',
1491 - 'post_content',
1492 - 'post_title',
1493 - 'post_excerpt',
1494 - 'post_status',
1495 - 'comment_status',
1496 - 'ping_status',
1497 - 'post_password',
1498 - 'post_name',
1499 - 'to_ping',
1500 - 'pinged',
1501 - 'post_modified',
1502 - 'post_modified_gmt',
1503 - 'post_content_filtered',
1504 - 'post_parent',
1505 - 'guid',
1506 - 'menu_order',
1507 - 'post_type',
1508 - 'post_mime_type',
1509 - 'comment_count',
1510 - 'filter',
1511 - 'post_thumbnail'
3878 + if ($id == 'dynamic') {
3879 + $id = $value;
3880 + }
3881 +
3882 + /* Backward compatibility 1.14.07 */
3883 + if ($attribute === 'true' && $key != 'get_attribute') {
3884 + $attribute = $key;
3885 + $key = 'get_attribute';
3886 + }
3887 +
3888 + /* Backward compatibility 1.24.07 */
3889 + if ($key == 'get_category_ids' && $order) {
3890 + $order = false;
3891 + }
3892 +
3893 + $data_fields = apply_filters(
3894 + 'e2pdf_model_shortcode_wc_product_data_fields',
3895 + [
3896 + 'id',
3897 + 'post_author',
3898 + 'post_author_id',
3899 + 'post_date',
3900 + 'post_date_gmt',
3901 + 'post_content',
3902 + 'post_title',
3903 + 'post_excerpt',
3904 + 'post_status',
3905 + 'permalink',
3906 + 'post_permalink',
3907 + 'get_post_permalink',
3908 + 'comment_status',
3909 + 'ping_status',
3910 + 'post_password',
3911 + 'post_name',
3912 + 'to_ping',
3913 + 'pinged',
3914 + 'post_modified',
3915 + 'post_modified_gmt',
3916 + 'post_content_filtered',
3917 + 'post_parent',
3918 + 'guid',
3919 + 'menu_order',
3920 + 'post_type',
3921 + 'post_mime_type',
3922 + 'comment_count',
3923 + 'filter',
3924 + 'post_thumbnail',
3925 + 'get_the_post_thumbnail',
3926 + 'get_the_post_thumbnail_url',
3927 + 'response_hook',
3928 + ]
1512 3929 );
1513 3930
1514 - $data_fields = apply_filters('e2pdf_model_shortcode_wp_data_fields', $data_fields);
3931 + $product_fields = apply_filters(
3932 + 'e2pdf_model_shortcode_wc_product_product_fields',
3933 + [
3934 + 'get_name',
3935 + 'get_type',
3936 + 'get_slug',
3937 + 'get_date_created',
3938 + 'get_date_modified',
3939 + 'get_status',
3940 + 'get_featured',
3941 + 'get_catalog_visibility',
3942 + 'get_description',
3943 + 'get_short_description',
3944 + 'get_sku',
3945 + 'get_price',
3946 + 'get_regular_price',
3947 + 'get_sale_price',
3948 + 'get_date_on_sale_from',
3949 + 'get_date_on_sale_to',
3950 + 'get_total_sales',
3951 + 'get_tax_status',
3952 + 'get_tax_class',
3953 + 'get_manage_stock',
3954 + 'get_stock_quantity',
3955 + 'get_stock_status',
3956 + 'get_backorders',
3957 + 'get_low_stock_amount',
3958 + 'get_sold_individually',
3959 + 'get_weight',
3960 + 'get_length',
3961 + 'get_width',
3962 + 'get_height',
3963 + 'get_dimensions',
3964 + 'get_upsell_ids',
3965 + 'get_cross_sell_ids',
3966 + 'get_parent_id',
3967 + 'get_reviews_allowed',
3968 + 'get_purchase_note',
3969 + 'get_attributes',
3970 + 'get_variation_attributes',
3971 + 'get_default_attributes',
3972 + 'get_menu_order',
3973 + 'get_post_password',
3974 + 'get_category_ids',
3975 + 'get_tag_ids',
3976 + 'get_virtual',
3977 + 'get_gallery_image_ids',
3978 + 'get_shipping_class_id',
3979 + 'get_downloads',
3980 + 'get_download_expiry',
3981 + 'get_downloadable',
3982 + 'get_download_limit',
3983 + 'get_image_id',
3984 + 'get_rating_counts',
3985 + 'get_average_rating',
3986 + 'get_review_count',
3987 + 'get_title',
3988 + 'get_permalink',
3989 + 'get_children',
3990 + 'get_stock_managed_by_id',
3991 + 'get_price_html',
3992 + 'get_formatted_name',
3993 + 'get_min_purchase_quantity',
3994 + 'get_max_purchase_quantity',
3995 + 'get_image',
3996 + 'get_shipping_class',
3997 + 'get_attribute',
3998 + 'get_variation_attribute',
3999 + 'get_rating_count',
4000 + 'get_file',
4001 + 'get_file_download_path',
4002 + 'get_price_suffix',
4003 + 'get_availability',
4004 + ]
4005 + );
1515 4006
1516 - if ($id && $key) {
1517 - $post = get_post($id);
1518 - if ($post) {
1519 - if (in_array($key, $data_fields) && !$meta && !$terms) {
4007 + $product_item_fields = apply_filters(
4008 + 'e2pdf_model_shortcode_wc_product_item_fields',
4009 + [
4010 + 'get_order_id',
4011 + 'get_name',
4012 + 'get_type',
4013 + 'get_quantity',
4014 + 'get_image',
4015 + 'get_tax_status',
4016 + 'get_tax_class',
4017 + 'get_formatted_meta_data',
4018 + 'get_formatted_cart_item_data', // Only cart
4019 + 'get_product_id',
4020 + 'get_variation_id',
4021 + 'get_subtotal',
4022 + 'get_subtotal_tax',
4023 + 'get_total',
4024 + 'get_total_tax',
4025 + 'get_taxes',
4026 + 'get_item_download_url',
4027 + 'get_item_downloads',
4028 + 'get_tax_status',
4029 + 'get_product_price',
4030 + 'get_order_item_id',
4031 + 'item_response_hook',
4032 + 'item_cart_response_hook',
4033 + 'cart_response_hook',
4034 + ]
4035 + );
4036 +
4037 + $product_order_fields = apply_filters(
4038 + 'e2pdf_model_shortcode_wc_product_order_item_fields',
4039 + [
4040 + 'get_item_subtotal',
4041 + 'get_item_total',
4042 + 'get_item_tax',
4043 + 'get_line_total',
4044 + 'get_line_tax',
4045 + 'get_formatted_line_subtotal',
4046 + 'order_response_hook',
4047 + ]
4048 + );
4049 +
4050 + $wc_product = false;
4051 + $wc_order = false;
4052 + $wc_order_items = [];
4053 + $wc_order_item_id = false;
4054 + $wc_order_item = false;
4055 + $wc_order_item_index = 0;
4056 +
4057 + if ($wc_order_id && ($index !== false || $id !== false) && !$detached) {
4058 + if ($wc_order_id == 'cart') {
4059 + if (function_exists('WC') && isset(WC()->cart) && WC()->cart && is_object(WC()->cart)) {
4060 + WC()->cart->calculate_totals();
4061 + $wc_order = WC()->cart;
4062 + $wc_order_items = WC()->cart->get_cart();
4063 + }
4064 + } else {
4065 + $wc_order = wc_get_order($wc_order_id);
4066 + if ($wc_order) {
4067 + $wc_order_items = $wc_order->get_items();
4068 + }
4069 + }
4070 +
4071 + foreach ($wc_order_items as $item_id => $item) {
4072 + if ($wc_order_id == 'cart') {
4073 + $item_product = apply_filters('woocommerce_cart_item_product', $item['data'], $item, $item_id);
4074 + if ($item['variation_id']) {
4075 + $product_id = $item['variation_id'];
4076 + } else {
4077 + $product_id = apply_filters('woocommerce_cart_item_product_id', $item['product_id'], $item, $item_id);
4078 + }
4079 + } else {
4080 + $item_product = $item->get_product();
4081 + if (!$item_product) {
4082 + $item_product = $item;
4083 + }
4084 + if ($item->get_variation_id()) {
4085 + $product_id = $item->get_variation_id();
4086 + } else {
4087 + $product_id = $item->get_product_id();
4088 + }
4089 + }
4090 + if ($wc_order_id != 'cart' || ($item_product && $item_product->exists() && $item['quantity'] > 0 && apply_filters('woocommerce_cart_item_visible', true, $item, $item_id))) {
4091 + if (
4092 + ($id === false && $index !== false && $wc_order_item_index == $index) ||
4093 + ($id !== false && $index !== false && $product_id == $id && $wc_order_item_index == $index) ||
4094 + ($id !== false && $index === false && $wc_product_item_id === false && $product_id == $id) ||
4095 + ($id !== false && $index === false && $wc_product_item_id !== false && $product_id == $id && $wc_product_item_id == $item_id)
4096 + ) {
4097 + $id = $product_id;
4098 + $wc_order_item = $item;
4099 + $wc_order_item_id = $item_id;
4100 + $wc_product = $item_product;
4101 + break;
4102 + }
4103 + if ($id !== false && $index !== false) {
4104 + if ($product_id == $id) {
4105 + $wc_order_item_index++;
4106 + }
4107 + } else {
4108 + $wc_order_item_index++;
4109 + }
4110 + }
4111 + }
4112 + }
4113 +
4114 + if ($key && (!$wc_order_id || ($wc_order_id && ($wc_product || $detached)))) {
4115 + if ($id) {
4116 + $wp_post = get_post($id);
4117 + if ($parent) {
4118 + $variation = wc_get_product($id);
4119 + if (get_post_type($id) == 'product_variation' && $variation) {
4120 + $id = $variation->get_parent_id();
4121 + $wp_post = get_post($variation->get_parent_id());
4122 + $wc_product = wc_get_product($id);
4123 + } else {
4124 + $wc_product = false;
4125 + $wp_post = false;
4126 + }
4127 + } elseif (!$wc_product) {
4128 + $wc_product = wc_get_product($id);
4129 + }
4130 + } else {
4131 + $wp_post = false;
4132 + }
4133 +
4134 + if (in_array($key, $data_fields, true) && !$meta && !$terms && !$order_item_meta && !$order) {
4135 + if ($wp_post) {
1520 4136 if ($key == 'post_author') {
1521 - $response = isset($post->post_author) && $post->post_author ? get_userdata($post->post_author)->user_nicename : '';
1522 - } elseif ($key == 'id' && isset($post->ID)) {
1523 - $response = $post->ID;
1524 - } elseif ($key == 'post_thumbnail' && isset($post->ID)) {
1525 - $response = get_the_post_thumbnail_url($post->ID, $size);
1526 - } elseif ($key == 'post_content' && isset($post->post_content)) {
1527 - $content = $post->post_content;
4137 + $post_meta = isset($wp_post->post_author) && $wp_post->post_author ? get_userdata($wp_post->post_author)->user_nicename : '';
4138 + } elseif ($key == 'post_author_id') {
4139 + $post_meta = isset($wp_post->post_author) && $wp_post->post_author ? $wp_post->post_author : '0';
4140 + } elseif ($key == 'id' && isset($wp_post->ID)) {
4141 + $post_meta = $wp_post->ID;
4142 + } elseif (($key == 'post_thumbnail' || $key == 'get_the_post_thumbnail_url') && isset($wp_post->ID)) {
4143 + $post_meta = get_the_post_thumbnail_url($wp_post->ID, $size);
4144 + } elseif ($key == 'get_the_post_thumbnail' && isset($wp_post->ID)) {
4145 + $post_meta = get_the_post_thumbnail($wp_post->ID, $size);
4146 + } elseif ($key == 'post_content' && isset($wp_post->post_content)) {
4147 + $content = $wp_post->post_content;
4148 + if (false !== strpos($content, '[')) {
4149 + $shortcode_tags = [
4150 + 'e2pdf-exclude',
4151 + 'e2pdf-save',
4152 + 'e2pdf-view',
4153 + ];
4154 + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
4155 + $tagnames = array_intersect($shortcode_tags, $matches[1]);
4156 + if (!empty($tagnames)) {
4157 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
4158 + foreach ($shortcodes[0] as $key => $shortcode_value) {
4159 + $content = str_replace($shortcode_value, '', $content);
4160 + }
4161 + }
4162 + }
1528 4163
4164 + if ($output) {
4165 + global $post;
4166 + $tmp_post = $post;
4167 + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
4168 + $post = $wp_post;
4169 + if ($output == 'backend') {
4170 + if (did_action('elementor/loaded') && class_exists('\Elementor\Plugin')) {
4171 + \Elementor\Plugin::instance()->frontend->remove_content_filter();
4172 + }
4173 + } elseif ($output == 'frontend') {
4174 + if (did_action('elementor/loaded') && class_exists('\Elementor\Plugin')) {
4175 + \Elementor\Plugin::instance()->frontend->add_content_filter();
4176 + }
4177 + }
4178 + }
4179 +
4180 + if (defined('ET_BUILDER_DIR') && 'on' === get_post_meta($id, '_et_pb_use_builder', true) && function_exists('et_builder_init_global_settings') && function_exists('et_builder_add_main_elements')) {
4181 + require_once ET_BUILDER_DIR . 'class-et-builder-element.php';
4182 + require_once ET_BUILDER_DIR . 'functions.php';
4183 + require_once ET_BUILDER_DIR . 'ab-testing.php';
4184 + require_once ET_BUILDER_DIR . 'class-et-global-settings.php';
4185 + et_builder_add_main_elements();
4186 + }
4187 +
4188 + if (class_exists('WPBMap') && method_exists('WPBMap', 'addAllMappedShortcodes')) {
4189 + WPBMap::addAllMappedShortcodes();
4190 + }
4191 +
4192 + $content = apply_filters('the_content', $content, $id);
4193 + $content = str_replace('</p>', "</p>\r\n", $content);
4194 + $post_meta = $content;
4195 +
4196 + if ($output) {
4197 + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
4198 + $post = $tmp_post;
4199 + }
4200 + } elseif ($key == 'permalink') {
4201 + $leavename = isset($atts['leavename']) && $atts['leavename'] == 'true' ? true : false;
4202 + $post_meta = get_permalink($id, $leavename);
4203 + $post_meta = $this->helper->load('translator')->translate_url($post_meta);
4204 + } elseif ($key == 'get_post_permalink' || $key == 'post_permalink') {
4205 + $leavename = isset($atts['leavename']) && $atts['leavename'] == 'true' ? true : false;
4206 + $post_meta = get_post_permalink($id, $leavename);
4207 + $post_meta = $this->helper->load('translator')->translate_url($post_meta);
4208 + } elseif ($key == 'response_hook') {
4209 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wc_product_response_hook', '', $id, $atts, $wp_post);
4210 + } elseif (isset($wp_post->$key)) {
4211 + $post_meta = $wp_post->$key;
4212 + }
4213 + }
4214 + } elseif (in_array($key, $product_fields, true) && !$meta && !$terms && !$order_item_meta && !$order) {
4215 + if ($wc_product && is_object($wc_product) && (method_exists($wc_product, $key) || $key == 'get_variation_attribute')) {
4216 + if ($key == 'get_attributes' || $key == 'get_variation_attributes') {
4217 + $wc_parent_product = false;
4218 + $parent_attributes = [];
4219 + $child_attributes = [];
4220 + if ($key == 'get_variation_attributes') {
4221 + $post_meta = $wc_product->get_attributes($wc_product);
4222 + } else {
4223 + if ($wc_product->is_type('variation')) {
4224 + $wc_parent_product = wc_get_product($wc_product->get_parent_id());
4225 + }
4226 + if ($wc_parent_product) {
4227 + if (isset($atts['hidden']) && $atts['hidden'] == 'true') {
4228 + $parent_attributes = $wc_parent_product->get_attributes();
4229 + } else {
4230 + $parent_attributes = array_filter($wc_parent_product->get_attributes(), 'wc_attributes_array_filter_visible');
4231 + }
4232 + $child_attributes = $wc_product->get_attributes($wc_product);
4233 + $post_meta = array_merge($parent_attributes, $child_attributes);
4234 + } else {
4235 + if (isset($atts['hidden']) && $atts['hidden'] == 'true') {
4236 + $post_meta = $wc_product->get_attributes();
4237 + } else {
4238 + $post_meta = array_filter($wc_product->get_attributes(), 'wc_attributes_array_filter_visible');
4239 + }
4240 + }
4241 + }
4242 +
4243 + if (is_array($post_meta) && !empty($post_meta)) {
4244 + $exclude = [];
4245 + if (isset($atts['exclude'])) {
4246 + $exclude = explode(',', $atts['exclude']);
4247 + }
4248 + foreach ($exclude as $excluded) {
4249 + if (array_key_exists($excluded, $post_meta)) {
4250 + unset($post_meta[$excluded]);
4251 + }
4252 + }
4253 + }
4254 +
4255 + if ($wc_filter) {
4256 + $product_attributes = [];
4257 + foreach ($post_meta as $attribute_key => $attribute) {
4258 + if ($attribute && is_a($attribute, 'WC_Product_Attribute')) {
4259 + $values = [];
4260 + if ($attribute->is_taxonomy()) {
4261 + $attribute_taxonomy = $attribute->get_taxonomy_object();
4262 + if ($wc_parent_product) {
4263 + $attribute_values = wc_get_product_terms($wc_parent_product->get_id(), $attribute->get_name(), ['fields' => 'all']);
4264 + } else {
4265 + $attribute_values = wc_get_product_terms($wc_product->get_id(), $attribute->get_name(), ['fields' => 'all']);
4266 + }
4267 + foreach ($attribute_values as $attribute_value) {
4268 + $value_name = esc_html($attribute_value->name);
4269 + if ($attribute_taxonomy->attribute_public) {
4270 + $values[] = '<a href="' . esc_url(get_term_link($attribute_value->term_id, $attribute->get_name())) . '" rel="tag">' . $value_name . '</a>';
4271 + } else {
4272 + $values[] = $value_name;
4273 + }
4274 + }
4275 + } else {
4276 + $values = $attribute->get_options();
4277 + foreach ($values as &$value) {
4278 + $value = make_clickable(esc_html($value));
4279 + }
4280 + }
4281 +
4282 + $product_attributes['attribute_' . sanitize_title_with_dashes($attribute->get_name())] = [
4283 + 'label' => wc_attribute_label($attribute->get_name()),
4284 + 'value' => apply_filters('woocommerce_attribute', wpautop(wptexturize(implode(', ', $values))), $attribute, $values),
4285 + ];
4286 + } else {
4287 + $attribute_value = $wc_product->get_attribute($attribute_key);
4288 + $attribute_value = implode(', ', array_map('trim', explode('|', $attribute_value)));
4289 + $attribute_value = apply_filters('e2pdf_model_shortcode_wc_product_get_attribute_value', $attribute_value, $wc_product);
4290 + $product_attributes['attribute_' . $attribute_key] = [
4291 + 'label' => wc_attribute_label($attribute_key, $wc_product),
4292 + 'value' => $attribute_value,
4293 + ];
4294 + }
4295 + }
4296 +
4297 + if ($key != 'get_variation_attributes') {
4298 + if ($wc_parent_product) {
4299 + $product_attributes = apply_filters('woocommerce_display_product_attributes', $product_attributes, $wc_parent_product);
4300 + } else {
4301 + $product_attributes = apply_filters('woocommerce_display_product_attributes', $product_attributes, $wc_product);
4302 + }
4303 + }
4304 + $post_meta = $product_attributes;
4305 + }
4306 + } elseif ($key == 'get_attribute' || $key == 'get_variation_attribute') {
4307 + if ($attribute) {
4308 +
4309 + $wc_parent_product = false;
4310 + $parent_attributes = [];
4311 + $child_attributes = [];
4312 +
4313 + if ($key == 'get_variation_attribute') {
4314 + $attributes = $wc_product->get_attributes($wc_product);
4315 + } else {
4316 + if ($wc_product->is_type('variation')) {
4317 + $wc_parent_product = wc_get_product($wc_product->get_parent_id());
4318 + }
4319 + if ($wc_parent_product) {
4320 + $parent_attributes = $wc_parent_product->get_attributes();
4321 + $child_attributes = $wc_product->get_attributes($wc_product);
4322 + $attributes = array_merge($parent_attributes, $child_attributes);
4323 + } else {
4324 + $attributes = $wc_product->get_attributes();
4325 + }
4326 + }
4327 +
4328 + if (isset($atts['show']) && $atts['show'] == 'label') {
4329 + if (isset($attributes[$attribute]) || isset($attributes['pa_' . $attribute])) {
4330 + $wc_attribute = isset($attributes[$attribute]) ? $attributes[$attribute] : $attributes['pa_' . $attribute];
4331 + if ($wc_attribute && is_a($wc_attribute, 'WC_Product_Attribute')) {
4332 + $post_meta = wc_attribute_label($wc_attribute->get_name());
4333 + } else {
4334 + $post_meta = wc_attribute_label($attribute, $wc_product);
4335 + }
4336 + }
4337 + } elseif (isset($atts['show']) && $atts['show'] == 'value') {
4338 + if ($wc_filter) {
4339 + if (isset($attributes[$attribute]) || isset($attributes['pa_' . $attribute])) {
4340 + $wc_attribute = isset($attributes[$attribute]) ? $attributes[$attribute] : $attributes['pa_' . $attribute];
4341 + if ($wc_attribute && is_a($wc_attribute, 'WC_Product_Attribute')) {
4342 + if ($wc_attribute->is_taxonomy()) {
4343 + $attribute_taxonomy = $wc_attribute->get_taxonomy_object();
4344 + if ($wc_parent_product) {
4345 + $attribute_values = wc_get_product_terms($wc_parent_product->get_id(), $wc_attribute->get_name(), ['fields' => 'all']);
4346 + } else {
4347 + $attribute_values = wc_get_product_terms($wc_product->get_id(), $wc_attribute->get_name(), ['fields' => 'all']);
4348 + }
4349 + foreach ($attribute_values as $attribute_value) {
4350 + $value_name = esc_html($attribute_value->name);
4351 + if ($attribute_taxonomy->attribute_public) {
4352 + $values[] = '<a href="' . esc_url(get_term_link($attribute_value->term_id, $wc_attribute->get_name())) . '" rel="tag">' . $value_name . '</a>';
4353 + } else {
4354 + $values[] = $value_name;
4355 + }
4356 + }
4357 + } else {
4358 + $values = $wc_attribute->get_options();
4359 + foreach ($values as &$value) {
4360 + $value = make_clickable(esc_html($value));
4361 + }
4362 + }
4363 + $post_meta = apply_filters('woocommerce_attribute', wpautop(wptexturize(implode(', ', $values))), $wc_attribute, $values);
4364 + $post_meta = apply_filters('e2pdf_model_shortcode_wc_product_get_attribute_value', $post_meta, $wc_product);
4365 + } else {
4366 + if ($wc_parent_product) {
4367 + if (isset($child_attributes[$attribute]) || isset($child_attributes['pa_' . $attribute])) {
4368 + $post_meta = $wc_product->get_attribute($attribute);
4369 + $post_meta = implode(', ', array_map('trim', explode('|', $post_meta)));
4370 + $post_meta = apply_filters('e2pdf_model_shortcode_wc_product_get_attribute_value', $post_meta, $wc_product);
4371 + } else {
4372 + $post_meta = $wc_parent_product->get_attribute($attribute);
4373 + $post_meta = implode(', ', array_map('trim', explode('|', $post_meta)));
4374 + $post_meta = apply_filters('e2pdf_model_shortcode_wc_product_get_attribute_value', $post_meta, $wc_parent_product);
4375 + }
4376 + } else {
4377 + $post_meta = $wc_product->get_attribute($attribute);
4378 + $post_meta = implode(', ', array_map('trim', explode('|', $post_meta)));
4379 + $post_meta = apply_filters('e2pdf_model_shortcode_wc_product_get_attribute_value', $post_meta, $wc_product);
4380 + }
4381 + }
4382 + }
4383 + } else {
4384 + if ($wc_parent_product) {
4385 + if (isset($child_attributes[$attribute]) || isset($child_attributes['pa_' . $attribute])) {
4386 + $post_meta = $wc_product->get_attribute($attribute);
4387 + $post_meta = implode(', ', array_map('trim', explode('|', $post_meta)));
4388 + $post_meta = apply_filters('e2pdf_model_shortcode_wc_product_get_attribute_value', $post_meta, $wc_product);
4389 + } else {
4390 + $post_meta = $wc_parent_product->get_attribute($attribute);
4391 + $post_meta = implode(', ', array_map('trim', explode('|', $post_meta)));
4392 + $post_meta = apply_filters('e2pdf_model_shortcode_wc_product_get_attribute_value', $post_meta, $wc_parent_product);
4393 + }
4394 + } else {
4395 + $post_meta = $wc_product->get_attribute($attribute);
4396 + $post_meta = implode(', ', array_map('trim', explode('|', $post_meta)));
4397 + $post_meta = apply_filters('e2pdf_model_shortcode_wc_product_get_attribute_value', $post_meta, $wc_product);
4398 + }
4399 + }
4400 + } else {
4401 + if ($wc_parent_product) {
4402 + if (isset($child_attributes[$attribute]) || isset($child_attributes['pa_' . $attribute])) {
4403 + $post_meta = $wc_product->get_attribute($attribute);
4404 + } else {
4405 + $post_meta = $wc_parent_product->get_attribute($attribute);
4406 + }
4407 + } else {
4408 + $post_meta = $wc_product->get_attribute($attribute);
4409 + }
4410 + }
4411 + }
4412 + } elseif ($key == 'get_short_description' || $key == 'get_description') {
4413 + $content = $wc_product->$key();
1529 4414 if (false !== strpos($content, '[')) {
1530 - $shortcode_tags = array(
4415 + $shortcode_tags = [
1531 4416 'e2pdf-exclude',
1532 - );
1533 -
4417 + 'e2pdf-save',
4418 + 'e2pdf-view',
4419 + ];
1534 4420 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
1535 4421 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1536 -
1537 4422 if (!empty($tagnames)) {
4423 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
4424 + foreach ($shortcodes[0] as $key => $shortcode_value) {
4425 + $content = str_replace($shortcode_value, '', $content);
4426 + }
4427 + }
4428 + }
1538 4429
1539 - $pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames);
1540 - preg_match_all("/$pattern/", $content, $shortcodes);
1541 - foreach ($shortcodes[0] as $key => $shortcode_value) {
1542 - $shortcode = array();
1543 - $shortcode[1] = $shortcodes[1][$key];
1544 - $shortcode[2] = $shortcodes[2][$key];
1545 - $shortcode[3] = $shortcodes[3][$key];
1546 - $shortcode[4] = $shortcodes[4][$key];
1547 - $shortcode[5] = $shortcodes[5][$key];
1548 - $shortcode[6] = $shortcodes[6][$key];
4430 + if (isset($atts['wc_format_content']) && $atts['wc_format_content'] == 'true') {
4431 + $content = apply_filters('e2pdf_model_shortcode_e2pdf_wc_product_description', $content, $id);
4432 + $content = wc_format_content($content);
4433 + }
1549 4434
1550 - $shortcode[3] .= " apply=\"true\"";
1551 - $content = str_replace($shortcode_value, "[" . $shortcode['2'] . $shortcode['3'] . "]" . $shortcode['5'] . "[/" . $shortcode['2'] . "]", $content);
4435 + $post_meta = $content;
4436 + } elseif ($key == 'get_file_download_path') {
4437 + if ($download_index !== false) {
4438 + $downloads = $wc_product->get_downloads();
4439 + $download_item_index = 0;
4440 + foreach ($downloads as $download) {
4441 + if ($download_item_index == $download_index) {
4442 + $post_meta = $wc_product->$key($download['id']);
4443 + break;
1552 4444 }
1553 4445 }
1554 4446 }
1555 - $content = apply_filters('the_content', $content);
1556 - $content = str_replace("</p>", "</p>\r\n", $content);
1557 - $response = $content;
1558 - } elseif (isset($post->$key)) {
1559 - $response = $post->$key;
4447 + } elseif ($key == 'get_image') {
4448 + $size = isset($atts['size']) ? $atts['size'] : 'woocommerce_thumbnail';
4449 + if (false !== strpos($size, 'x')) {
4450 + $image_size = explode('x', $size);
4451 + if (isset($image_size['0']) && isset($image_size['1'])) {
4452 + $image_width = absint($image_size['0']);
4453 + $image_height = absint($image_size['1']);
4454 + if ($image_width && $image_height) {
4455 + $size = [
4456 + $image_width, $image_height,
4457 + ];
4458 + }
4459 + }
4460 + }
4461 + $post_meta = $wc_product->$key($size);
4462 + } elseif ($key == 'get_file') {
4463 + if ($download_index !== false) {
4464 + $downloads = $wc_product->get_downloads();
4465 + $download_item_index = 0;
4466 + foreach ($downloads as $download) {
4467 + if ($download_item_index == $download_index) {
4468 + $post_meta = $wc_product->$key($download['id']);
4469 + break;
4470 + }
4471 + }
4472 + } else {
4473 + $post_meta = $wc_product->$key();
4474 + }
4475 + } elseif ($key == 'get_date_created' || $key == 'get_date_modified') {
4476 + $format = isset($atts['format']) && $atts['format'] ? $atts['format'] : get_option('date_format') . ', ' . get_option('time_format');
4477 + $post_meta = wc_format_datetime($wc_product->$key(), $format);
4478 + } elseif ($key == 'get_category_ids') {
4479 + $wc_parent_product = false;
4480 + if ($wc_product->is_type('variation')) {
4481 + $wc_parent_product = wc_get_product($wc_product->get_parent_id());
4482 + }
4483 + if ($wc_parent_product) {
4484 + $post_meta = $wc_parent_product->$key();
4485 + } else {
4486 + $post_meta = $wc_product->$key();
4487 + }
4488 + } else {
4489 + $post_meta = $wc_product->$key();
1560 4490 }
1561 - } elseif ($terms) {
1562 - if ($names) {
1563 - $post_terms = wp_get_post_terms($id, $key, array('fields' => 'names'));
1564 - if (!is_wp_error($post_terms) && is_array($post_terms)) {
1565 - $response = implode($implode, $post_terms);
4491 + }
4492 + } elseif (in_array($key, $product_item_fields, true) && !$meta && !$terms && !$order_item_meta) {
4493 + if ($wc_order_id == 'cart' && $wc_order_item && is_array($wc_order_item) && $wc_product && is_object($wc_product)) {
4494 + if ($key == 'item_cart_response_hook') {
4495 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wc_product_item_cart_response_hook', '', $id, $atts, $wc_product, $wc_order_item, $wc_order_item_id, $wc_order_item_index);
4496 + } elseif ($key == 'cart_response_hook') {
4497 + /* Backward compatibility fix 1.16.09 */
4498 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wc_product_cart_response_hook', '', $id, $atts, $wc_product, $wc_order_item, $wc_order_item_id, $wc_order_item_index);
4499 + } elseif ($key == 'get_name') {
4500 + if ($wc_filter) {
4501 + $product_permalink = apply_filters('woocommerce_cart_item_permalink', $wc_product->is_visible() ? $wc_product->get_permalink($wc_order_item) : '', $wc_order_item, $wc_order_item_id);
4502 + if (!$product_permalink) {
4503 + $post_meta = wp_kses_post(apply_filters('woocommerce_cart_item_name', $wc_product->get_name(), $wc_order_item, $wc_order_item_id) . '&nbsp;');
4504 + } else {
4505 + $post_meta = wp_kses_post(apply_filters('woocommerce_cart_item_name', sprintf('<a target="_blank" href="%s">%s</a>', esc_url($product_permalink), $wc_product->get_name()), $wc_order_item, $wc_order_item_id));
4506 + }
4507 + } else {
4508 + $post_meta = $wc_product->$key($attribute);
1566 4509 }
4510 + } elseif ($key == 'get_image') {
4511 + if (false !== strpos($size, 'x')) {
4512 + $image_size = explode('x', $size);
4513 + if (isset($image_size['0']) && isset($image_size['1'])) {
4514 + $image_width = absint($image_size['0']);
4515 + $image_height = absint($image_size['1']);
4516 + if ($image_width && $image_height) {
4517 + $size = [
4518 + $image_width, $image_height,
4519 + ];
4520 + }
4521 + }
4522 + }
4523 + if ($wc_filter) {
4524 + $post_meta = apply_filters('woocommerce_cart_item_thumbnail', $wc_product->get_image($size), $wc_order_item, $wc_order_item_id);
4525 + } else {
4526 + $post_meta = $wc_product->get_image($size);
4527 + }
4528 + } elseif ($key == 'get_quantity') {
4529 + $post_meta = isset($wc_order_item['quantity']) ? $wc_order_item['quantity'] : '0';
4530 + } elseif ($key == 'get_subtotal') {
4531 + if ($wc_filter) {
4532 + $post_meta = apply_filters('woocommerce_cart_item_subtotal', $wc_order->get_product_subtotal($wc_product, $wc_order_item['quantity']), $wc_order_item, $wc_order_item_id);
4533 + } else {
4534 + $post_meta = $wc_order->get_product_subtotal($wc_product, $wc_order_item['quantity']);
4535 + }
4536 + } elseif ($key == 'get_product_price') {
4537 + if ($wc_filter) {
4538 + $post_meta = apply_filters('woocommerce_cart_item_price', $wc_order->get_product_price($wc_product), $wc_order_item, $wc_order_item_id);
4539 + } else {
4540 + $post_meta = $wc_order->get_product_price($wc_product);
4541 + }
4542 + } elseif ($key == 'get_formatted_meta_data' || $key == 'get_formatted_cart_item_data') {
4543 + if ($wc_filter || $key == 'get_formatted_cart_item_data') {
4544 + if (isset($atts['flat']) && $atts['flat'] == 'true') {
4545 + $flat = true;
4546 + } else {
4547 + $flat = false;
4548 + }
4549 + if (isset($atts['nl2br']) && $atts['nl2br'] == 'true') {
4550 + $post_meta = nl2br(wc_get_formatted_cart_item_data($wc_order_item, $flat));
4551 + } else {
4552 + $post_meta = wc_get_formatted_cart_item_data($wc_order_item, $flat);
4553 + }
4554 + } else {
4555 + $item_data = [];
4556 + if ($wc_order_item['data']->is_type('variation') && is_array($wc_order_item['variation'])) {
4557 + foreach ($wc_order_item['variation'] as $name => $value) {
4558 + $taxonomy = wc_attribute_taxonomy_name(str_replace('attribute_pa_', '', urldecode($name)));
4559 + if (taxonomy_exists($taxonomy)) {
4560 + $term = get_term_by('slug', $value, $taxonomy);
4561 + if (!is_wp_error($term) && $term && $term->name) {
4562 + $value = $term->name;
4563 + }
4564 + $label = wc_attribute_label($taxonomy);
4565 + } else {
4566 + $value = apply_filters('woocommerce_variation_option_name', $value, null, $taxonomy, $wc_order_item['data']);
4567 + $label = wc_attribute_label(str_replace('attribute_', '', $name), $wc_order_item['data']);
4568 + }
4569 +
4570 + if ('' === $value || wc_is_attribute_in_product_name($value, $wc_order_item['data']->get_name())) {
4571 + continue;
4572 + }
4573 +
4574 + $item_data[] = [
4575 + 'key' => $label,
4576 + 'value' => $value,
4577 + ];
4578 + }
4579 + }
4580 +
4581 + $item_data = apply_filters('woocommerce_get_item_data', $item_data, $wc_order_item);
4582 +
4583 + foreach ($item_data as $key => $data) {
4584 + if (isset($atts['hidden']) && $atts['hidden'] == 'false') {
4585 + if (!empty($data['hidden'])) {
4586 + unset($item_data[$key]);
4587 + continue;
4588 + }
4589 + }
4590 + $item_data[$key]['display_key'] = !empty($data['key']) ? $data['key'] : $data['name'];
4591 + $item_data[$key]['display_value'] = !empty($data['display']) ? $data['display'] : $data['value'];
4592 + }
4593 +
4594 + $post_meta = $item_data;
4595 + }
1567 4596 } else {
1568 - $post_terms = wp_get_post_terms($id, $key);
1569 - if (!is_wp_error($post_terms)) {
1570 - $post_terms = json_decode(json_encode($post_terms), true);
1571 - if ($path !== false) {
1572 - $path_parts = explode($explode, $path);
1573 - $path_value = &$post_terms;
1574 - $found = true;
1575 - foreach ($path_parts as $path_part) {
1576 - if (isset($path_value[$path_part])) {
1577 - $path_value = &$path_value[$path_part];
1578 - } else {
1579 - $found = false;
4597 + $post_meta = isset($wc_order_item[$key]) ? $wc_order_item[$key] : '';
4598 + }
4599 + } elseif ($wc_order_item && is_object($wc_order_item)) {
4600 + if ($key == 'get_order_item_id') {
4601 + $post_meta = $wc_order_item_id ? $wc_order_item_id : '';
4602 + } elseif ($key == 'item_response_hook') {
4603 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wc_product_item_response_hook', '', $id, $atts, $wc_product, $wc_order_item, $wc_order_item_id, $wc_order_item_index);
4604 + } elseif (method_exists($wc_order_item, $key)) {
4605 + if ($key == 'get_item_download_url') {
4606 + if ($download_index !== false) {
4607 + $downloads = $wc_order_item->get_item_downloads();
4608 + $download_item_index = 0;
4609 + foreach ($downloads as $download) {
4610 + if ($download_item_index == $download_index) {
4611 + $post_meta = $wc_order_item->$key($download['id']);
1580 4612 break;
1581 4613 }
1582 4614 }
4615 + }
4616 + } elseif ($key == 'get_item_downloads' && $download_index !== false) {
4617 + $download_item_index = 0;
4618 + foreach ($downloads as $download) {
4619 + if ($download_item_index == $download_index) {
4620 + $post_meta = $download;
4621 + break;
4622 + }
4623 + }
4624 + } else {
4625 + $post_meta = $wc_order_item->$key();
4626 + }
4627 + }
4628 + }
4629 + } elseif (in_array($key, $product_order_fields, true) && !$meta && !$terms && !$order_item_meta) {
4630 + if ($wc_order_item) {
4631 + if ($key == 'order_response_hook') {
4632 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wc_product_order_response_hook', '', $id, $atts, $wc_product, $wc_order_item, $wc_order_item_id, $wc_order_item_index);
4633 + } elseif ($wc_order && is_object($wc_order) && method_exists($wc_order, $key)) {
4634 + if ($key == 'get_item_subtotal' || $key == 'get_item_total' || $key == 'get_line_total') {
4635 + $inc_tax = isset($atts['inc_tax']) && $atts['inc_tax'] == 'true' ? true : false;
4636 + $round = isset($atts['round']) && $atts['round'] == 'false' ? false : true;
4637 + $post_meta = $wc_order->$key($wc_order_item, $inc_tax, $round);
4638 + } elseif ($key == 'get_item_tax') {
4639 + $round = isset($atts['round']) && $atts['round'] == 'false' ? false : true;
4640 + $post_meta = $wc_order->$key($wc_order_item, $round);
4641 + } elseif ($key == 'get_formatted_line_subtotal') {
4642 + $tax_display = isset($atts['tax_display']) && $atts['tax_display'] ? $atts['tax_display'] : '';
4643 + $post_meta = $wc_order->$key($wc_order_item, $tax_display);
4644 + } else {
4645 + $post_meta = $wc_order->$key($wc_order_item);
4646 + }
4647 + }
4648 + }
4649 + } elseif ($order_item_meta) {
4650 + if ($wc_order_item_id) {
4651 + $post_meta = wc_get_order_item_meta($wc_order_item_id, $key, true);
4652 + }
4653 + } elseif ($terms && $names) {
4654 + if ($wp_post) {
4655 + $post_terms = wp_get_post_terms($id, $key, ['fields' => 'names']);
4656 + if (!is_wp_error($post_terms) && is_array($post_terms)) {
4657 + foreach ($post_terms as $post_term_key => $post_terms_value) {
4658 + $post_terms[$post_term_key] = $this->helper->load('translator')->translate($post_terms_value);
4659 + }
4660 + if ($implode === false) {
4661 + $implode = ', ';
4662 + }
4663 + $post_meta = implode($implode, $post_terms);
4664 + }
4665 + }
4666 + } elseif ($terms) {
4667 + if ($wp_post) {
4668 + $post_terms = wp_get_post_terms($id, $key);
4669 + if (!is_wp_error($post_terms)) {
4670 + // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
4671 + $post_meta = json_decode(json_encode($post_terms), true);
4672 + }
4673 + }
4674 + } else {
4675 + $post_meta = $wp_post ? get_post_meta($id, $key, true) : false;
4676 + if ($post_meta === false && $wc_order_item) {
4677 + $post_meta = $wc_order_item->get_meta($key);
4678 + }
4679 + }
1583 4680
1584 - if ($found) {
1585 - if ($attachment_url) {
1586 - if (!is_array($path_value)) {
1587 - $response = wp_get_attachment_url($path_value);
4681 + if ($post_meta !== false) {
4682 +
4683 + if (is_object($post_meta)) {
4684 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wc_product_object', $post_meta, $atts);
4685 + }
4686 +
4687 + if ($explode && !is_array($post_meta)) {
4688 + $post_meta = explode($explode, $post_meta);
4689 + }
4690 +
4691 + if (is_array($post_meta)) {
4692 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wc_product_array', $post_meta, $atts);
4693 + }
4694 +
4695 + if (is_string($post_meta) && $path !== false && is_object(json_decode($post_meta))) {
4696 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wc_product_json', json_decode($post_meta, true), $atts);
4697 + }
4698 +
4699 + if ((is_array($post_meta) || is_object($post_meta)) && $path !== false) {
4700 + $post_meta = $this->helper->load('shortcode')->apply_path_attribute($post_meta, $path);
4701 + }
4702 +
4703 + if ($attachment_url || $attachment_image_url) {
4704 + if (!is_array($post_meta)) {
4705 + if (strpos($post_meta, ',') !== false) {
4706 + $post_meta = explode(',', $post_meta);
4707 + if ($implode === false) {
4708 + $implode = ',';
4709 + }
4710 + }
4711 + }
4712 + if ($attachment_url) {
4713 + $post_meta = $this->helper->load('shortcode')->apply_attachment_attribute($post_meta, 'attachment_url', $size);
4714 + } else {
4715 + $post_meta = $this->helper->load('shortcode')->apply_attachment_attribute($post_meta, 'attachment_image_url', $size);
4716 + }
4717 + }
4718 +
4719 + if ($wc_price || $wc_price_raw) {
4720 + if (is_array($post_meta) || is_object($post_meta)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
4721 + } else {
4722 + if (isset($atts['currency'])) {
4723 + $post_meta = wc_price($post_meta, $atts['currency']);
4724 + } else {
4725 + if (!$wc_order && $wc_order_id) {
4726 + $wc_order = wc_get_order($wc_order_id);
4727 + }
4728 + if ($wc_order && is_object($wc_order) && method_exists($wc_order, 'get_currency')) {
4729 + $post_meta = wc_price($post_meta, $wc_order->get_currency());
4730 + } else {
4731 + $post_meta = wc_price($post_meta);
4732 + }
4733 + }
4734 + if ($wc_price_raw) {
4735 + $post_meta = html_entity_decode(wp_strip_all_tags($post_meta));
4736 + }
4737 + }
4738 + }
4739 +
4740 + if ($convert) {
4741 + $post_meta = $this->helper->load('shortcode')->apply_convert_attribute($convert, $post_meta, $implode);
4742 + }
4743 +
4744 + if (apply_filters('e2pdf_raw_output', false)) {
4745 + $response = $post_meta;
4746 + } else {
4747 + if (is_array($post_meta)) {
4748 + if ($implode !== false) {
4749 + if (!$this->helper->is_multidimensional($post_meta)) {
4750 + foreach ($post_meta as $post_meta_key => $post_meta_value) {
4751 + $post_meta[$post_meta_key] = $this->helper->load('translator')->translate($post_meta_value);
4752 + }
4753 + $response = implode($implode, $post_meta);
4754 + } else {
4755 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
4756 + $response = serialize($post_meta);
4757 + }
4758 + } else {
4759 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
4760 + $response = serialize($post_meta);
4761 + }
4762 + } elseif (is_object($post_meta)) {
4763 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
4764 + $response = serialize($post_meta);
4765 + } else {
4766 + $response = $post_meta;
4767 + }
4768 + }
4769 + }
4770 + }
4771 +
4772 + if (apply_filters('e2pdf_raw_output', false)) {
4773 + return apply_filters('e2pdf_model_shortcode_e2pdf_wc_product_raw', $response, $atts, $value);
4774 + } else {
4775 + $response = $this->helper->load('translator')->translate($response, 'partial');
4776 + if (!apply_filters('e2pdf_pdf_fill', false)) {
4777 + $response = $this->sanitize_html($response);
4778 + }
4779 + return apply_filters('e2pdf_model_shortcode_e2pdf_wc_product_response', $response, $atts, $value);
4780 + }
4781 + }
4782 +
4783 + // e2pdf-wc-order
4784 + public function e2pdf_wc_order($atts = [], $value = '') {
4785 +
4786 + if (!apply_filters('e2pdf_shortcode_enable_e2pdf_wc_order', false) && !apply_filters('e2pdf_pdf_render', false)) {
4787 + return '';
4788 + }
4789 +
4790 + $post_meta = false;
4791 + $response = '';
4792 +
4793 + $atts = apply_filters('e2pdf_model_shortcode_e2pdf_wc_order_atts', $atts);
4794 +
4795 + $id = isset($atts['id']) ? $atts['id'] : false;
4796 + $key = isset($atts['key']) ? $atts['key'] : false;
4797 + $subkey = isset($atts['subkey']) ? $atts['subkey'] : false;
4798 + $index = isset($atts['index']) ? $atts['index'] : false;
4799 + $path = isset($atts['path']) ? $atts['path'] : false;
4800 + $names = isset($atts['names']) && $atts['names'] == 'true' ? true : false;
4801 + $explode = isset($atts['explode']) ? $atts['explode'] : false;
4802 + $implode = isset($atts['implode']) ? $atts['implode'] : false;
4803 + $attachment_url = isset($atts['attachment_url']) && $atts['attachment_url'] == 'true' ? true : false;
4804 + $attachment_image_url = isset($atts['attachment_image_url']) && $atts['attachment_image_url'] == 'true' ? true : false;
4805 + $size = isset($atts['size']) ? $atts['size'] : 'thumbnail';
4806 + $meta = isset($atts['meta']) && $atts['meta'] == 'true' ? true : false;
4807 + $order_item_meta = isset($atts['order_item_meta']) && $atts['order_item_meta'] == 'true' ? true : false;
4808 + $terms = isset($atts['terms']) && $atts['terms'] == 'true' ? true : false;
4809 + $output = isset($atts['output']) ? $atts['output'] : false;
4810 + $checkout_field_editor = isset($atts['checkout_field_editor']) && $atts['checkout_field_editor'] == 'true' ? true : false;
4811 + $parent = isset($atts['parent']) && $atts['parent'] == 'true' ? true : false;
4812 + $wc_price = isset($atts['wc_price']) && $atts['wc_price'] == 'true' ? true : false;
4813 + $wc_price_raw = isset($atts['wc_price_raw']) && $atts['wc_price_raw'] == 'true' ? true : false;
4814 +
4815 + if ($id == 'dynamic') {
4816 + $id = $value;
4817 + }
4818 +
4819 + if ($parent) {
4820 + $order_id = false;
4821 + if ($id && function_exists('wcs_get_subscription') && get_post_type($id) == 'shop_subscription') {
4822 + $subscription = wcs_get_subscription($id);
4823 + if ($subscription) {
4824 + $subscription_order = $subscription->get_parent();
4825 + if ($subscription_order) {
4826 + $order_id = $subscription_order->get_id();
4827 + }
4828 + }
4829 + }
4830 + $id = $order_id;
4831 + }
4832 +
4833 + $data_fields = apply_filters(
4834 + 'e2pdf_model_shortcode_wc_order_data_fields',
4835 + [
4836 + 'id',
4837 + 'post_author',
4838 + 'post_author_id',
4839 + 'post_date',
4840 + 'post_date_gmt',
4841 + 'post_content',
4842 + 'post_title',
4843 + 'post_excerpt',
4844 + 'post_status',
4845 + 'permalink',
4846 + 'post_permalink',
4847 + 'get_post_permalink',
4848 + 'comment_status',
4849 + 'ping_status',
4850 + 'post_password',
4851 + 'post_name',
4852 + 'to_ping',
4853 + 'pinged',
4854 + 'post_modified',
4855 + 'post_modified_gmt',
4856 + 'post_content_filtered',
4857 + 'post_parent',
4858 + 'guid',
4859 + 'menu_order',
4860 + 'post_type',
4861 + 'post_mime_type',
4862 + 'comment_count',
4863 + 'filter',
4864 + 'post_thumbnail',
4865 + 'get_the_post_thumbnail',
4866 + 'get_the_post_thumbnail_url',
4867 + 'response_hook',
4868 + ]
4869 + );
4870 +
4871 + $order_fields = apply_filters(
4872 + 'e2pdf_model_shortcode_wc_order_order_fields',
4873 + [
4874 + 'cart',
4875 + 'get_id',
4876 + 'get_order_key',
4877 + 'get_order_number',
4878 + 'get_formatted_order_total',
4879 + 'get_cart_tax',
4880 + 'get_currency',
4881 + 'get_discount_tax',
4882 + 'get_discount_to_display',
4883 + 'get_discount_total',
4884 + 'get_shipping_tax',
4885 + 'get_shipping_total',
4886 + 'get_subtotal',
4887 + 'get_subtotal_to_display',
4888 + 'get_total',
4889 + 'get_total_discount',
4890 + 'get_total_tax',
4891 + 'get_total_refunded',
4892 + 'get_total_tax_refunded',
4893 + 'get_total_shipping_refunded',
4894 + 'get_item_count_refunded',
4895 + 'get_total_qty_refunded',
4896 + 'get_remaining_refund_amount',
4897 + 'get_item_count',
4898 + 'get_shipping_method',
4899 + 'get_shipping_to_display',
4900 + 'get_date_created',
4901 + 'get_date_modified',
4902 + 'get_date_completed',
4903 + 'get_date_paid',
4904 + 'get_customer_id',
4905 + 'get_user_id',
4906 + 'get_customer_ip_address',
4907 + 'get_customer_user_agent',
4908 + 'get_created_via',
4909 + 'get_customer_note',
4910 + 'get_billing_first_name',
4911 + 'get_billing_last_name',
4912 + 'get_billing_company',
4913 + 'get_billing_address_1',
4914 + 'get_billing_address_2',
4915 + 'get_billing_city',
4916 + 'get_billing_state',
4917 + 'get_billing_postcode',
4918 + 'get_billing_country',
4919 + 'get_billing_email',
4920 + 'get_billing_phone',
4921 + 'get_shipping_first_name',
4922 + 'get_shipping_last_name',
4923 + 'get_shipping_company',
4924 + 'get_shipping_address_1',
4925 + 'get_shipping_address_2',
4926 + 'get_shipping_city',
4927 + 'get_shipping_state',
4928 + 'get_shipping_postcode',
4929 + 'get_shipping_country',
4930 + 'get_shipping_address_map_url',
4931 + 'get_formatted_billing_full_name',
4932 + 'get_formatted_shipping_full_name',
4933 + 'get_formatted_billing_address',
4934 + 'get_formatted_shipping_address',
4935 + 'get_payment_method',
4936 + 'get_payment_method_title',
4937 + 'get_transaction_id',
4938 + 'get_checkout_payment_url',
4939 + 'get_checkout_order_received_url',
4940 + 'get_cancel_order_url',
4941 + 'get_cancel_order_url_raw',
4942 + 'get_cancel_endpoint',
4943 + 'get_view_order_url',
4944 + 'get_edit_order_url',
4945 + 'get_status',
4946 + 'get_coupons',
4947 + 'get_fees',
4948 + 'get_taxes',
4949 + 'get_shipping_methods',
4950 + 'get_coupon_codes',
4951 + 'get_items_tax_classes',
4952 + 'get_total_fees',
4953 + 'get_order_item_totals',
4954 + 'get_tax_totals',
4955 + 'get_items',
4956 + 'get_items_ids',
4957 + 'get_items_category',
4958 + 'get_items_category_ids',
4959 + ]
4960 + );
4961 +
4962 + if ($id && $key) {
4963 + $wp_post = get_post($id);
4964 + if ($wp_post) {
4965 + if (in_array($key, $data_fields, true) && !$meta && !$order_item_meta && !$terms) {
4966 + if ($key == 'post_author') {
4967 + $post_meta = isset($wp_post->post_author) && $wp_post->post_author ? get_userdata($wp_post->post_author)->user_nicename : '';
4968 + } elseif ($key == 'post_author_id') {
4969 + $post_meta = isset($wp_post->post_author) && $wp_post->post_author ? $wp_post->post_author : '0';
4970 + } elseif ($key == 'id' && isset($wp_post->ID)) {
4971 + $post_meta = $wp_post->ID;
4972 + } elseif (($key == 'post_thumbnail' || $key == 'get_the_post_thumbnail_url') && isset($wp_post->ID)) {
4973 + $post_meta = get_the_post_thumbnail_url($wp_post->ID, $size);
4974 + } elseif ($key == 'get_the_post_thumbnail' && isset($wp_post->ID)) {
4975 + $post_meta = get_the_post_thumbnail($wp_post->ID, $size);
4976 + } elseif ($key == 'post_content' && isset($wp_post->post_content)) {
4977 + $content = $wp_post->post_content;
4978 + if (false !== strpos($content, '[')) {
4979 + $shortcode_tags = array(
4980 + 'e2pdf-exclude',
4981 + 'e2pdf-save',
4982 + 'e2pdf-view',
4983 + );
4984 + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
4985 + $tagnames = array_intersect($shortcode_tags, $matches[1]);
4986 + if (!empty($tagnames)) {
4987 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
4988 + foreach ($shortcodes[0] as $key => $shortcode_value) {
4989 + $content = str_replace($shortcode_value, '', $content);
4990 + }
4991 + }
4992 + }
4993 + if ($output) {
4994 + global $post;
4995 + $tmp_post = $post;
4996 + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
4997 + $post = $wp_post;
4998 + if ($output == 'backend') {
4999 + if (did_action('elementor/loaded') && class_exists('\Elementor\Plugin')) {
5000 + \Elementor\Plugin::instance()->frontend->remove_content_filter();
5001 + }
5002 + } elseif ($output == 'frontend') {
5003 + if (did_action('elementor/loaded') && class_exists('\Elementor\Plugin')) {
5004 + \Elementor\Plugin::instance()->frontend->add_content_filter();
5005 + }
5006 + }
5007 + }
5008 +
5009 + if (defined('ET_BUILDER_DIR') && 'on' === get_post_meta($id, '_et_pb_use_builder', true) && function_exists('et_builder_init_global_settings') && function_exists('et_builder_add_main_elements')) {
5010 + require_once ET_BUILDER_DIR . 'class-et-builder-element.php';
5011 + require_once ET_BUILDER_DIR . 'functions.php';
5012 + require_once ET_BUILDER_DIR . 'ab-testing.php';
5013 + require_once ET_BUILDER_DIR . 'class-et-global-settings.php';
5014 + et_builder_add_main_elements();
5015 + }
5016 +
5017 + if (class_exists('WPBMap') && method_exists('WPBMap', 'addAllMappedShortcodes')) {
5018 + WPBMap::addAllMappedShortcodes();
5019 + }
5020 +
5021 + $content = apply_filters('the_content', $content, $id);
5022 + $content = str_replace('</p>', "</p>\r\n", $content);
5023 + $post_meta = $content;
5024 +
5025 + if ($output) {
5026 + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
5027 + $post = $tmp_post;
5028 + }
5029 + } elseif ($key == 'permalink') {
5030 + $leavename = isset($atts['leavename']) && $atts['leavename'] == 'true' ? true : false;
5031 + $post_meta = get_permalink($id, $leavename);
5032 + $post_meta = $this->helper->load('translator')->translate_url($post_meta);
5033 + } elseif ($key == 'get_post_permalink' || $key == 'post_permalink') {
5034 + $leavename = isset($atts['leavename']) && $atts['leavename'] == 'true' ? true : false;
5035 + $post_meta = get_post_permalink($id, $leavename);
5036 + $post_meta = $this->helper->load('translator')->translate_url($post_meta);
5037 + } elseif ($key == 'response_hook') {
5038 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wc_order_response_hook', '', $id, $atts, $wp_post);
5039 + } elseif (isset($wp_post->$key)) {
5040 + $post_meta = $wp_post->$key;
5041 + }
5042 + } elseif (in_array($key, $order_fields, true) && !$meta && !$order_item_meta && !$terms) {
5043 + $order = wc_get_order($id);
5044 + if ($order) {
5045 + if ($key == 'cart') {
5046 + $items = $order->get_items();
5047 + $content = '';
5048 + if ($items) {
5049 + $show_products = isset($atts['show_products']) && $atts['show_products'] == 'false' ? false : true;
5050 + $show_image = isset($atts['show_image']) && $atts['show_image'] == 'false' ? false : true;
5051 + $show_sku = isset($atts['show_sku']) && $atts['show_sku'] == 'false' ? false : true;
5052 + $show_name = isset($atts['show_name']) && $atts['show_name'] == 'false' ? false : true;
5053 + $show_quantity = isset($atts['show_quantity']) && $atts['show_quantity'] == 'false' ? false : true;
5054 + $show_price = isset($atts['show_price']) && $atts['show_price'] == 'false' ? false : true;
5055 + $show_subtotal = isset($atts['show_subtotal']) && $atts['show_subtotal'] == 'false' ? false : true;
5056 + $show_meta = isset($atts['show_meta']) && $atts['show_meta'] == 'false' ? false : true;
5057 +
5058 + $show_totals = isset($atts['show_totals']) && $atts['show_totals'] == 'false' ? false : true;
5059 + $show_totals_subtotal = isset($atts['show_totals_subtotal']) && $atts['show_totals_subtotal'] == 'false' ? false : true;
5060 + $show_totals_discount = isset($atts['show_totals_discount']) && $atts['show_totals_discount'] == 'false' ? false : true;
5061 + $show_totals_payment_method = isset($atts['show_totals_payment_method']) && $atts['show_totals_payment_method'] == 'false' ? false : true;
5062 + $show_totals_shipping = isset($atts['show_totals_shipping']) && $atts['show_totals_shipping'] == 'false' ? false : true;
5063 + $show_totals_total = isset($atts['show_totals_total']) && $atts['show_totals_total'] == 'false' ? false : true;
5064 + $show_comment = isset($atts['show_comment']) && $atts['show_comment'] == 'false' ? false : true;
5065 +
5066 + if (isset($atts['size'])) {
5067 + $size = $atts['size'];
5068 + } elseif (isset($atts['image_size'])) {
5069 + $size = $atts['image_size'];
5070 + } else {
5071 + $size = '32x32';
5072 + }
5073 +
5074 + if (false !== strpos($size, 'x')) {
5075 + $image_size = explode('x', $size);
5076 + if (isset($image_size['0']) && isset($image_size['1'])) {
5077 + $image_width = absint($image_size['0']);
5078 + $image_height = absint($image_size['1']);
5079 + if ($image_width && $image_height) {
5080 + $size = [
5081 + $image_width, $image_height,
5082 + ];
1588 5083 }
1589 - } elseif ($attachment_image_url) {
1590 - if (!is_array($path_value)) {
1591 - $image = wp_get_attachment_image_url($path_value, $size);
1592 - if ($image) {
1593 - $response = $image;
5084 + }
5085 + }
5086 +
5087 + $plain_text = isset($atts['plain_text']) ? $atts['plain_text'] : false;
5088 +
5089 + if ($show_products) {
5090 + $content .= "<table split='true' border='1' bordercolor='#eeeeee' cellpadding='5' class='e2pdf-wc-cart-products'>";
5091 + $content .= "<tr bgcolor='#eeeeee' class='e2pdf-wc-cart-products-header'>";
5092 + if ($show_image) {
5093 + $content .= "<td class='e2pdf-wc-cart-products-header-image'>" . apply_filters('e2pdf_model_shortcode_wc_order_cart_header_image_text', '', $atts, $value) . '</td>';
5094 + }
5095 + if ($show_name) {
5096 + $content .= "<td class='e2pdf-wc-cart-products-header-name'>" . apply_filters('e2pdf_model_shortcode_wc_order_cart_header_name_text', __('Product', 'woocommerce'), $atts, $value) . '</td>';
5097 + }
5098 + if ($show_sku) {
5099 + $content .= "<td class='e2pdf-wc-cart-products-header-sku'>" . apply_filters('e2pdf_model_shortcode_wc_order_cart_header_sku_text', __('SKU', 'woocommerce'), $atts, $value) . '</td>';
5100 + }
5101 + if ($show_quantity) {
5102 + $content .= "<td class='e2pdf-wc-cart-products-header-quantity'>" . apply_filters('e2pdf_model_shortcode_wc_order_cart_header_quantity_text', __('Quantity', 'woocommerce'), $atts, $value) . '</td>';
5103 + }
5104 + if ($show_price) {
5105 + $content .= "<td class='e2pdf-wc-cart-products-header-price'>" . apply_filters('e2pdf_model_shortcode_wc_order_cart_header_pricey_text', __('Price', 'woocommerce'), $atts, $value) . '</td>';
5106 + }
5107 + if ($show_subtotal) {
5108 + $content .= "<td class='e2pdf-wc-cart-products-header-subtotal'>" . apply_filters('e2pdf_model_shortcode_wc_order_cart_header_pricey_text', __('Subtotal', 'woocommerce'), $atts, $value) . '</td>';
5109 + }
5110 + $content .= '</tr>';
5111 +
5112 + $item_index = 0;
5113 + foreach ($items as $item_id => $item) {
5114 +
5115 + $product = $item->get_product();
5116 + $sku = '';
5117 + $purchase_note = '';
5118 + $image = '';
5119 +
5120 + $woocommerce_order_item_visible = apply_filters('woocommerce_order_item_visible', true, $item);
5121 + if (!apply_filters('e2pdf_woocommerce_order_item_visible', $woocommerce_order_item_visible, $item, $atts)) {
5122 + continue;
5123 + }
5124 +
5125 + if (!empty($atts['in_categories'])) {
5126 + $in_categories = explode(',', $atts['in_categories']);
5127 + $categories = wp_get_post_terms($item->get_product_id(), 'product_cat', ['fields' => 'slugs']);
5128 + if (empty($categories) || !array_intersect($in_categories, $categories)) {
5129 + continue;
1594 5130 }
1595 5131 }
5132 +
5133 + if (is_object($product)) {
5134 + $sku = $product->get_sku();
5135 + $purchase_note = $product->get_purchase_note();
5136 + $image = $product->get_image($size);
5137 + }
5138 +
5139 + $even_odd = $item_index % 2 ? 'e2pdf-wc-cart-product-odd' : 'e2pdf-wc-cart-product-even';
5140 + $content .= "<tr class='e2pdf-wc-cart-product " . $even_odd . "'>";
5141 +
5142 + if ($show_image) {
5143 + $content .= "<td align='center' class='e2pdf-wc-cart-product-image'>" . apply_filters('woocommerce_order_item_thumbnail', $image, $item) . '</td>';
5144 + }
5145 +
5146 + if ($show_name) {
5147 + $content .= "<td class='e2pdf-wc-cart-product-name'>";
5148 +
5149 + $is_visible = $product && $product->is_visible();
5150 + $product_permalink = apply_filters('woocommerce_order_item_permalink', $is_visible ? $product->get_permalink($item) : '', $item, $order);
5151 + $content .= apply_filters('woocommerce_order_item_name', $product_permalink ? sprintf('<a target="_blank" href="%s">%s</a>', $product_permalink, $item->get_name()) : $item->get_name(), $item, $is_visible);
5152 +
5153 + if ($show_meta) {
5154 + $wc_display_item_meta = wc_display_item_meta(
5155 + $item,
5156 + [
5157 + 'echo' => false,
5158 + 'before' => '',
5159 + 'separator' => '',
5160 + 'after' => '',
5161 + 'label_before' => "<div size='8px' class='e2pdf-wc-cart-product-meta'>",
5162 + 'lable_after' => '</div>',
5163 + ]
5164 + );
5165 +
5166 + if ($wc_display_item_meta) {
5167 + $content .= str_replace(['<p>', '</p>'], ['', ''], $wc_display_item_meta);
5168 + }
5169 + }
5170 +
5171 + $content .= '</td>';
5172 + }
5173 +
5174 + if ($show_sku) {
5175 + $content .= "<td class='e2pdf-wc-cart-product-sku'>" . $sku . '</td>';
5176 + }
5177 +
5178 + if ($show_quantity) {
5179 + $qty = $item->get_quantity();
5180 + $refunded_qty = $order->get_qty_refunded_for_item($item_id);
5181 + if ($refunded_qty) {
5182 + $qty_display = '<del>' . esc_html($qty) . '</del> ' . esc_html($qty - ($refunded_qty * -1)) . '';
5183 + } else {
5184 + $qty_display = esc_html($qty);
5185 + }
5186 + $content .= "<td class='e2pdf-wc-cart-product-quantity'>" . apply_filters('woocommerce_email_order_item_quantity', $qty_display, $item) . '</td>';
5187 + }
5188 +
5189 + if ($show_price) {
5190 + $content .= "<td class='e2pdf-wc-cart-product-price'>" . wc_price($order->get_item_subtotal($item, false, true), ['currency' => $order->get_currency()]) . '</td>';
5191 + }
5192 +
5193 + if ($show_subtotal) {
5194 + $content .= "<td class='e2pdf-wc-cart-product-subtotal'>" . $order->get_formatted_line_subtotal($item) . '</td>';
5195 + }
5196 +
5197 + $content .= '</tr>';
5198 + $item_index++;
5199 + }
5200 + $content .= '</table>';
5201 + }
5202 +
5203 + if ($show_comment && $order->get_customer_note()) {
5204 + $content .= "<table split='true' size='8px' margin-top='1' border='1' bordercolor='#eeeeee' cellpadding='5' class='e2pdf-wc-cart-comment'>";
5205 + $content .= '<tr>';
5206 + $content .= '<td>' . nl2br(wptexturize($order->get_customer_note())) . '</td>';
5207 + $content .= '</tr>';
5208 + $content .= '</table>';
5209 + }
5210 +
5211 + if ($show_totals) {
5212 + $item_totals = apply_filters('e2pdf_model_shortcode_wc_order_item_totals', $order->get_order_item_totals(), $atts, $value);
5213 + if (!empty($item_totals)) {
5214 + $total_index = 0;
5215 + $content .= "<table split='true' cellpadding='5' class='e2pdf-wc-cart-totals'>";
5216 + foreach ($item_totals as $total_key => $total) {
5217 + if (
5218 + ($total_key == 'cart_subtotal' && !$show_totals_subtotal) ||
5219 + ($total_key == 'discount' && !$show_totals_discount) ||
5220 + ($total_key == 'shipping' && !$show_totals_shipping) ||
5221 + ($total_key == 'payment_method' && !$show_totals_payment_method) ||
5222 + ($total_key == 'order_total' && !$show_totals_total)
5223 + ) {
5224 + continue;
5225 + }
5226 + $even_odd = $total_index % 2 ? 'e2pdf-wc-cart-total-odd' : 'e2pdf-wc-cart-total-even';
5227 + $content .= "<tr class='e2pdf-wc-cart-total e2pdf-wc-cart-total-" . $total_key . ' ' . $even_odd . "'>";
5228 + $content .= "<td valign='top' width='60%' align='right' class='e2pdf-wc-cart-total-label'>" . $total['label'] . '</td>';
5229 + $content .= "<td valign='top' align='right' class='e2pdf-wc-cart-total-value'>" . $total['value'] . '</td>';
5230 + $content .= '</tr>';
5231 + $total_index++;
5232 + }
5233 + $content .= '</table>';
5234 + }
5235 + }
5236 +
5237 + $post_meta = $content;
5238 + }
5239 + } elseif ($key == 'get_items_category' || $key == 'get_items_category_ids') {
5240 + $item_metas = [];
5241 + foreach ($order->get_items() as $item) {
5242 + if (is_callable(array($item, 'get_product_id'))) {
5243 + $product_categories = wp_get_post_terms($item->get_product_id(), 'product_cat');
5244 + foreach ($product_categories as $product_category) {
5245 + if ($key == 'get_items_category') {
5246 + $item_metas[] = $product_category->name;
5247 + } else {
5248 + $item_metas[] = $product_category->term_id;
5249 + }
5250 + }
5251 + }
5252 + }
5253 + $post_meta = $item_metas;
5254 + } elseif ($key == 'get_items_ids') {
5255 + $item_metas = [];
5256 + foreach ($order->get_items() as $item) {
5257 + if (is_callable(array($item, 'get_product_id')) && $item->get_product_id()) {
5258 + $item_metas[] = $item->get_product_id();
5259 + }
5260 + if (is_callable(array($item, 'get_variation_id')) && $item->get_variation_id()) {
5261 + $item_metas[] = $item->get_variation_id();
5262 + }
5263 + }
5264 + $post_meta = $item_metas;
5265 + } else {
5266 + if ($order && is_object($order) && method_exists($order, $key)) {
5267 + if ($key == 'get_date_created' || $key == 'get_date_modified' || $key == 'get_date_completed' || $key == 'get_date_paid') {
5268 + $format = isset($atts['format']) && $atts['format'] ? $atts['format'] : get_option('date_format') . ', ' . get_option('time_format');
5269 + $post_meta = wc_format_datetime($order->$key(), $format);
5270 + } elseif ($key == 'get_formatted_billing_address' || $key == 'get_formatted_shipping_address') {
5271 + $empty_content = isset($atts['empty_content']) ? $atts['empty_content'] : '';
5272 + $post_meta = $order->$key($empty_content);
5273 + } elseif ($key == 'get_status') {
5274 + $post_meta = $order->$key();
5275 + $wc_get_order_status_name = isset($atts['wc_get_order_status_name']) && $atts['wc_get_order_status_name'] == 'true' ? true : false;
5276 + if ($wc_get_order_status_name) {
5277 + $post_meta = wc_get_order_status_name($post_meta);
5278 + }
5279 + } elseif ($key == 'get_items') {
5280 + $types = isset($atts['types']) ? explode(',', $atts['types']) : ['line_item'];
5281 + $post_meta = $order->$key($types);
5282 + } elseif ($key == 'get_subtotal_to_display') {
5283 + $compound = isset($atts['compound']) && $atts['compound'] == 'true' ? true : false;
5284 + $tax_display = isset($atts['tax_display']) ? $atts['tax_display'] : '';
5285 + $post_meta = $order->$key($compound, $tax_display);
5286 + } elseif ($key == 'get_total_discount') {
5287 + $ex_tax = isset($atts['ex_tax']) && $atts['ex_tax'] == 'false' ? false : true;
5288 + $post_meta = $order->$key($ex_tax);
5289 + } else {
5290 + $post_meta = $order->$key();
5291 + }
5292 + }
5293 + }
5294 + }
5295 + } elseif ($terms && $names) {
5296 + $post_terms = wp_get_post_terms($id, $key, ['fields' => 'names']);
5297 + if (!is_wp_error($post_terms) && is_array($post_terms)) {
5298 + foreach ($post_terms as $post_term_key => $post_terms_value) {
5299 + $post_terms[$post_term_key] = $this->helper->load('translator')->translate($post_terms_value);
5300 + }
5301 + if ($implode === false) {
5302 + $implode = ', ';
5303 + }
5304 + $post_meta = implode($implode, $post_terms);
5305 + }
5306 + } elseif ($terms) {
5307 + $post_terms = wp_get_post_terms($id, $key);
5308 + if (!is_wp_error($post_terms)) {
5309 + // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
5310 + $post_meta = json_decode(json_encode($post_terms), true);
5311 + }
5312 + } elseif ($order_item_meta) {
5313 + if ($subkey) {
5314 + $order = wc_get_order($id);
5315 + if ($order) {
5316 + $items = $order->get_items($key);
5317 + if ($items) {
5318 + if ($index !== false) {
5319 + $i = 0;
5320 + foreach ($items as $item_id => $item) {
5321 + if ($i == $index) {
5322 + $post_meta = wc_get_order_item_meta($item_id, $subkey, true);
5323 + break;
5324 + }
5325 + $i++;
5326 + }
5327 + } else {
5328 + $item_metas = [];
5329 + foreach ($items as $item_id => $item) {
5330 + $item_metas[] = wc_get_order_item_meta($item_id, $subkey, true);
5331 + }
5332 + $post_meta = $item_metas;
5333 + }
5334 + }
5335 + }
5336 + } else {
5337 + $order = wc_get_order($id);
5338 + if ($order) {
5339 + $items = $order->get_items($key);
5340 + if ($items) {
5341 + global $wpdb;
5342 + $item_metas = [];
5343 + $i = 0;
5344 + foreach ($items as $item_id => $item) {
5345 + if ($index !== false) {
5346 + if ($i == $index) {
5347 + $condition = [
5348 + 'meta.order_item_id' => [
5349 + 'condition' => '=',
5350 + 'value' => $item_id,
5351 + 'type' => '%d',
5352 + ],
5353 + ];
5354 + $where = $this->helper->load('db')->prepare_where($condition);
5355 +
5356 + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
5357 + $meta_data = $wpdb->get_results($wpdb->prepare('SELECT DISTINCT `meta`.`meta_key` FROM `' . $wpdb->prefix . 'woocommerce_order_itemmeta` `meta`' . $where['sql'] . '', $where['filter']), ARRAY_A);
5358 + if (!empty($meta_data)) {
5359 + foreach ($meta_data as $meta_key) {
5360 + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
5361 + $item_metas[$i][$meta_key['meta_key']] = wc_get_order_item_meta($item_id, $meta_key['meta_key'], true);
5362 + }
5363 + }
5364 + break;
5365 + }
1596 5366 } else {
1597 - if (is_array($path_value)) {
1598 - $response = serialize($path_value);
1599 - } else {
1600 - $response = $path_value;
5367 + $condition = [
5368 + 'meta.order_item_id' => [
5369 + 'condition' => '=',
5370 + 'value' => $item_id,
5371 + 'type' => '%d',
5372 + ],
5373 + ];
5374 + $where = $this->helper->load('db')->prepare_where($condition);
5375 +
5376 + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
5377 + $meta_data = $wpdb->get_results($wpdb->prepare('SELECT DISTINCT `meta`.`meta_key` FROM `' . $wpdb->prefix . 'woocommerce_order_itemmeta` `meta`' . $where['sql'] . '', $where['filter']), ARRAY_A);
5378 + if (!empty($meta_data)) {
5379 + foreach ($meta_data as $meta_key) {
5380 + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
5381 + $item_metas[$i][$meta_key['meta_key']] = wc_get_order_item_meta($item_id, $meta_key['meta_key'], true);
5382 + }
1601 5383 }
1602 5384 }
5385 + $i++;
1603 5386 }
5387 + $post_meta = $item_metas;
5388 + }
5389 + }
5390 + }
5391 + } else {
5392 + if (get_option('woocommerce_custom_orders_table_enabled') === 'yes' && get_option('woocommerce_custom_orders_table_data_sync_enabled') !== 'yes') {
5393 + $order = wc_get_order($id);
5394 + if ($order) {
5395 + $post_meta = $order->get_meta($key, true, 'edit');
5396 + if (!$post_meta) {
5397 + $post_meta = get_post_meta($id, $key, true);
5398 + }
5399 + }
5400 + } else {
5401 + $post_meta = get_post_meta($id, $key, true);
5402 + }
5403 + }
5404 +
5405 + if ($post_meta !== false) {
5406 +
5407 + if (is_object($post_meta)) {
5408 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wc_order_object', $post_meta, $atts);
5409 + }
5410 +
5411 + if ($explode && !is_array($post_meta)) {
5412 + $post_meta = explode($explode, $post_meta);
5413 + }
5414 +
5415 + if (is_array($post_meta)) {
5416 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wc_order_array', $post_meta, $atts);
5417 + }
5418 +
5419 + if (is_string($post_meta) && $path !== false && is_object(json_decode($post_meta))) {
5420 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wc_order_json', json_decode($post_meta, true), $atts);
5421 + }
5422 +
5423 + if ((is_array($post_meta) || is_object($post_meta)) && $path !== false) {
5424 + $post_meta = $this->helper->load('shortcode')->apply_path_attribute($post_meta, $path);
5425 + }
5426 +
5427 + if ($attachment_url || $attachment_image_url) {
5428 + if (!is_array($post_meta)) {
5429 + if (strpos($post_meta, ',') !== false) {
5430 + $post_meta = explode(',', $post_meta);
5431 + if ($implode === false) {
5432 + $implode = ',';
5433 + }
5434 + }
5435 + }
5436 + if ($attachment_url) {
5437 + $post_meta = $this->helper->load('shortcode')->apply_attachment_attribute($post_meta, 'attachment_url', $size);
5438 + } else {
5439 + $post_meta = $this->helper->load('shortcode')->apply_attachment_attribute($post_meta, 'attachment_image_url', $size);
5440 + }
5441 + }
5442 +
5443 + if ($wc_price || $wc_price_raw) {
5444 + if (is_array($post_meta) || is_object($post_meta)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
5445 + } else {
5446 + if (isset($atts['currency'])) {
5447 + $post_meta = wc_price($post_meta, $atts['currency']);
1604 5448 } else {
1605 - $response = serialize($post_terms);
5449 + if (!$order) {
5450 + $order = wc_get_order($id);
5451 + }
5452 + if ($order) {
5453 + $post_meta = wc_price($post_meta, $order->get_currency());
5454 + } else {
5455 + $post_meta = wc_price($post_meta);
5456 + }
1606 5457 }
5458 + if ($wc_price_raw) {
5459 + $post_meta = html_entity_decode(wp_strip_all_tags($post_meta));
5460 + }
1607 5461 }
1608 5462 }
1609 - } else {
1610 - $post_meta = get_post_meta($id, $key, true);
1611 - if ($post_meta) {
5463 +
5464 + /*
5465 + * Checkout Field Editor (Checkout Manager) for WooCommerce
5466 + * https://wordpress.org/plugins/woo-checkout-field-editor-pro/
5467 + */
5468 + if ($checkout_field_editor) {
5469 + $checkout_field = false;
5470 +
5471 + if (class_exists('WCFE_Checkout_Fields_Utils') && class_exists('THWCFE_Utils_Section') && class_exists('THWCFE_Utils')) {
5472 + $checkout_field_editor_sections = WCFE_Checkout_Fields_Utils::get_checkout_sections();
5473 + foreach ($checkout_field_editor_sections as $checkout_field_editor_section) {
5474 + $checkout_field_editor_fields = THWCFE_Utils_Section::get_fields($checkout_field_editor_section);
5475 + if (isset($checkout_field_editor_fields[$key])) {
5476 + $post_meta = THWCFE_Utils::get_option_text_from_value($checkout_field_editor_fields[$key], $post_meta);
5477 + $checkout_field = true;
5478 + break;
5479 + }
5480 + }
5481 + }
5482 +
5483 + if (!$checkout_field && class_exists('THWCFD_Utils')) {
5484 + $checkout_field_editor_fields = array_merge(THWCFD_Utils::get_fields('billing'), THWCFD_Utils::get_fields('shipping'), THWCFD_Utils::get_fields('additional'));
5485 + if (isset($checkout_field_editor_fields[$key])) {
5486 + $post_meta = THWCFD_Utils::get_option_text($checkout_field_editor_fields[$key], $post_meta);
5487 + $checkout_field = true;
5488 + }
5489 + }
5490 +
5491 + if (!$checkout_field && class_exists('THWCFD_Utils_Block') && class_exists('THWCFE_Utils_Section') && class_exists('THWCFE_Utils_Section')) {
5492 + $checkout_field_editor_sections = THWCFD_Utils_Block::get_block_checkout_sections();
5493 + foreach ($checkout_field_editor_sections as $checkout_field_editor_section) {
5494 + $checkout_field_editor_fields = THWCFE_Utils_Section::get_fields($checkout_field_editor_section);
5495 + if (isset($checkout_field_editor_fields[$key])) {
5496 + $post_meta = THWCFE_Utils::get_option_text_from_value($checkout_field_editor_fields[$key], $post_meta);
5497 + $checkout_field = true;
5498 + break;
5499 + }
5500 + }
5501 + }
5502 +
5503 + if (!$checkout_field && class_exists('THWCFD_Utils_Block') && class_exists('THWCFD_Utils_Section') && class_exists('THWCFD_Utils')) {
5504 + $checkout_field_editor_sections = THWCFD_Utils_Block::get_block_checkout_sections();
5505 + foreach ($checkout_field_editor_sections as $checkout_field_editor_section) {
5506 + $checkout_field_editor_fields = [];
5507 + $checkout_field_editor_fields = THWCFD_Utils_Section::get_fieldset($checkout_field_editor_section);
5508 + if (isset($checkout_field_editor_fields[$key])) {
5509 + $post_meta = THWCFD_Utils::get_option_text($checkout_field_editor_fields[$key], $post_meta);
5510 + $checkout_field = true;
5511 + break;
5512 + }
5513 + }
5514 + }
5515 + }
5516 +
5517 + if (apply_filters('e2pdf_raw_output', false)) {
5518 + $response = $post_meta;
5519 + } else {
1612 5520 if (is_array($post_meta)) {
1613 - if ($path !== false) {
1614 - $path_parts = explode($explode, $path);
1615 - $path_value = &$post_meta;
1616 - $found = true;
1617 - foreach ($path_parts as $path_part) {
1618 - if (isset($path_value[$path_part])) {
1619 - $path_value = &$path_value[$path_part];
1620 - } else {
1621 - $found = false;
1622 - break;
5521 + if ($implode !== false) {
5522 + if (!$this->helper->is_multidimensional($post_meta)) {
5523 + foreach ($post_meta as $post_meta_key => $post_meta_value) {
5524 + $post_meta[$post_meta_key] = $this->helper->load('translator')->translate($post_meta_value);
1623 5525 }
5526 + $response = implode($implode, $post_meta);
5527 + } else {
5528 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
5529 + $response = serialize($post_meta);
1624 5530 }
5531 + } else {
5532 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
5533 + $response = serialize($post_meta);
5534 + }
5535 + } elseif (is_object($post_meta)) {
5536 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
5537 + $response = serialize($post_meta);
5538 + } else {
5539 + $response = $post_meta;
5540 + }
5541 + }
5542 + }
5543 + }
5544 + }
1625 5545
1626 - if ($found) {
1627 - if ($attachment_url) {
1628 - if (!is_array($path_value)) {
1629 - $response = wp_get_attachment_url($path_value);
5546 + if (apply_filters('e2pdf_raw_output', false)) {
5547 + return apply_filters('e2pdf_model_shortcode_e2pdf_wc_order_raw', $response, $atts, $value);
5548 + } else {
5549 + $response = $this->helper->load('translator')->translate($response, 'partial');
5550 + if (!apply_filters('e2pdf_pdf_fill', false)) {
5551 + $response = $this->sanitize_html($response);
5552 + }
5553 + return apply_filters('e2pdf_model_shortcode_e2pdf_wc_order_response', $response, $atts, $value);
5554 + }
5555 + }
5556 +
5557 + // e2pdf-foreach
5558 + public function e2pdf_foreach($atts = [], $value = '') {
5559 +
5560 + if (!apply_filters('e2pdf_shortcode_enable_e2pdf_foreach', false) && !apply_filters('e2pdf_pdf_render', false)) {
5561 + return '';
5562 + }
5563 +
5564 + $response = [];
5565 + $implode = isset($atts['implode']) ? $atts['implode'] : '';
5566 + if (isset($atts['shortcode'])) {
5567 + $foreach_shortcode = str_replace('-', '_', $atts['shortcode']);
5568 + if (method_exists($this, $foreach_shortcode)) {
5569 + add_filter('e2pdf_raw_output', array($this->helper, '__return_true'), 999);
5570 + $data = $this->$foreach_shortcode($atts, '');
5571 + remove_filter('e2pdf_raw_output', array($this->helper, '__return_true'), 999);
5572 + if ($data && (is_string($data) || is_numeric($data))) {
5573 + $data = [$data];
5574 + }
5575 + if (is_array($data) && count($data) > 0) {
5576 + $index = 0;
5577 + foreach ($data as $data_key => $data_value) {
5578 + $sub_value = $this->helper->load('foreach')->do_shortcode($value, $data_key, $data_value, $index);
5579 + $response[] = $this->helper->load('foreach')->add($atts, $sub_value, 1);
5580 + $index++;
5581 + }
5582 + }
5583 + }
5584 + }
5585 +
5586 + $response = implode($implode, $response);
5587 + if (!apply_filters('e2pdf_pdf_fill', false)) {
5588 + $response = $this->sanitize_html($response);
5589 + }
5590 + return $response;
5591 + }
5592 +
5593 + // e2pdf-wc-cart
5594 + public function e2pdf_wc_cart($atts = [], $value = '') {
5595 +
5596 + if (!apply_filters('e2pdf_shortcode_enable_e2pdf_wc_cart', false) && !apply_filters('e2pdf_pdf_render', false)) {
5597 + return '';
5598 + }
5599 +
5600 + $post_meta = false;
5601 + $response = '';
5602 +
5603 + $atts = apply_filters('e2pdf_model_shortcode_e2pdf_wc_cart_atts', $atts);
5604 +
5605 + $id = isset($atts['id']) ? $atts['id'] : false;
5606 + $key = isset($atts['key']) ? $atts['key'] : false;
5607 + $path = isset($atts['path']) ? $atts['path'] : false;
5608 + $names = isset($atts['names']) && $atts['names'] == 'true' ? true : false;
5609 + $explode = isset($atts['explode']) ? $atts['explode'] : false;
5610 + $implode = isset($atts['implode']) ? $atts['implode'] : false;
5611 + $attachment_url = isset($atts['attachment_url']) && $atts['attachment_url'] == 'true' ? true : false;
5612 + $attachment_image_url = isset($atts['attachment_image_url']) && $atts['attachment_image_url'] == 'true' ? true : false;
5613 + $size = isset($atts['size']) ? $atts['size'] : 'thumbnail';
5614 + $meta = isset($atts['meta']) && $atts['meta'] == 'true' ? true : false;
5615 + $terms = isset($atts['terms']) && $atts['terms'] == 'true' ? true : false;
5616 + $output = isset($atts['output']) ? $atts['output'] : false;
5617 + $wc_price = isset($atts['wc_price']) && $atts['wc_price'] == 'true' ? true : false;
5618 + $wc_price_raw = isset($atts['wc_price_raw']) && $atts['wc_price_raw'] == 'true' ? true : false;
5619 +
5620 + $data_fields = apply_filters(
5621 + 'e2pdf_model_shortcode_wc_cart_data_fields',
5622 + [
5623 + 'id',
5624 + 'post_author',
5625 + 'post_author_id',
5626 + 'post_date',
5627 + 'post_date_gmt',
5628 + 'post_content',
5629 + 'post_title',
5630 + 'post_excerpt',
5631 + 'post_status',
5632 + 'permalink',
5633 + 'post_permalink',
5634 + 'get_post_permalink',
5635 + 'comment_status',
5636 + 'ping_status',
5637 + 'post_password',
5638 + 'post_name',
5639 + 'to_ping',
5640 + 'pinged',
5641 + 'post_modified',
5642 + 'post_modified_gmt',
5643 + 'post_content_filtered',
5644 + 'post_parent',
5645 + 'guid',
5646 + 'menu_order',
5647 + 'post_type',
5648 + 'post_mime_type',
5649 + 'comment_count',
5650 + 'filter',
5651 + 'post_thumbnail',
5652 + 'get_the_post_thumbnail',
5653 + 'get_the_post_thumbnail_url',
5654 + 'response_hook',
5655 + ]
5656 + );
5657 +
5658 + $cart_fields = apply_filters(
5659 + 'e2pdf_model_shortcode_wc_cart_cart_fields',
5660 + [
5661 + 'cart',
5662 + 'get_cart',
5663 + 'get_applied_coupons',
5664 + 'get_cart_total',
5665 + 'get_formatted_cart_totals',
5666 + 'get_cart_subtotal',
5667 + 'get_cart_tax',
5668 + 'get_cart_hash',
5669 + 'get_cart_contents_total',
5670 + 'get_cart_contents_tax',
5671 + 'get_cart_contents_taxes',
5672 + 'get_cart_contents_count',
5673 + 'get_cart_contents_weight',
5674 + 'get_cart_item_quantities',
5675 + 'get_cart_item_tax_classes',
5676 + 'get_cart_item_tax_classes_for_shipping',
5677 + 'get_cart_shipping_total',
5678 + 'get_coupon_discount_totals',
5679 + 'get_coupon_discount_tax_totals',
5680 + 'get_totals',
5681 + 'get_total',
5682 + 'get_total_tax',
5683 + 'get_total_ex_tax',
5684 + 'get_total_discount',
5685 + 'get_subtotal',
5686 + 'get_subtotal_tax',
5687 + 'get_discount_total',
5688 + 'get_discount_tax',
5689 + 'get_shipping_total',
5690 + 'get_shipping_tax',
5691 + 'get_shipping_taxes',
5692 + 'get_fees',
5693 + 'get_fee_total',
5694 + 'get_fee_tax',
5695 + 'get_fee_taxes',
5696 + 'get_displayed_subtotal',
5697 + 'get_tax_price_display_mode',
5698 + 'get_taxes',
5699 + 'get_taxes_total',
5700 + 'get_shipping_method_title',
5701 + 'get_payment_method_title',
5702 + ]
5703 + );
5704 +
5705 + if ($id && $key) {
5706 + $wp_post = get_post($id);
5707 + if ($wp_post) {
5708 + if (in_array($key, $data_fields, true) && !$meta && !$terms) {
5709 + if ($key == 'post_author') {
5710 + $post_meta = isset($wp_post->post_author) && $wp_post->post_author ? get_userdata($wp_post->post_author)->user_nicename : '';
5711 + } elseif ($key == 'post_author_id') {
5712 + $post_meta = isset($wp_post->post_author) && $wp_post->post_author ? $wp_post->post_author : '0';
5713 + } elseif ($key == 'id' && isset($wp_post->ID)) {
5714 + $post_meta = $wp_post->ID;
5715 + } elseif (($key == 'post_thumbnail' || $key == 'get_the_post_thumbnail_url') && isset($wp_post->ID)) {
5716 + $post_meta = get_the_post_thumbnail_url($wp_post->ID, $size);
5717 + } elseif ($key == 'get_the_post_thumbnail' && isset($wp_post->ID)) {
5718 + $post_meta = get_the_post_thumbnail($wp_post->ID, $size);
5719 + } elseif ($key == 'post_content' && isset($wp_post->post_content)) {
5720 + $content = $wp_post->post_content;
5721 + if (false !== strpos($content, '[')) {
5722 + $shortcode_tags = [
5723 + 'e2pdf-exclude',
5724 + 'e2pdf-save',
5725 + 'e2pdf-view',
5726 + ];
5727 + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
5728 + $tagnames = array_intersect($shortcode_tags, $matches[1]);
5729 + if (!empty($tagnames)) {
5730 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
5731 + foreach ($shortcodes[0] as $key => $shortcode_value) {
5732 + $content = str_replace($shortcode_value, '', $content);
5733 + }
5734 + }
5735 + }
5736 +
5737 + if ($output) {
5738 + global $post;
5739 + $tmp_post = $post;
5740 + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
5741 + $post = $wp_post;
5742 + if ($output == 'backend') {
5743 + if (did_action('elementor/loaded') && class_exists('\Elementor\Plugin')) {
5744 + \Elementor\Plugin::instance()->frontend->remove_content_filter();
5745 + }
5746 + } elseif ($output == 'frontend') {
5747 + if (did_action('elementor/loaded') && class_exists('\Elementor\Plugin')) {
5748 + \Elementor\Plugin::instance()->frontend->add_content_filter();
5749 + }
5750 + }
5751 + }
5752 +
5753 + if (defined('ET_BUILDER_DIR') && 'on' === get_post_meta($id, '_et_pb_use_builder', true) && function_exists('et_builder_init_global_settings') && function_exists('et_builder_add_main_elements')) {
5754 + require_once ET_BUILDER_DIR . 'class-et-builder-element.php';
5755 + require_once ET_BUILDER_DIR . 'functions.php';
5756 + require_once ET_BUILDER_DIR . 'ab-testing.php';
5757 + require_once ET_BUILDER_DIR . 'class-et-global-settings.php';
5758 + et_builder_add_main_elements();
5759 + }
5760 +
5761 + if (class_exists('WPBMap') && method_exists('WPBMap', 'addAllMappedShortcodes')) {
5762 + WPBMap::addAllMappedShortcodes();
5763 + }
5764 +
5765 + $content = apply_filters('the_content', $content, $id);
5766 + $content = str_replace('</p>', "</p>\r\n", $content);
5767 + $post_meta = $content;
5768 +
5769 + if ($output) {
5770 + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
5771 + $post = $tmp_post;
5772 + }
5773 + } elseif ($key == 'permalink') {
5774 + $leavename = isset($atts['leavename']) && $atts['leavename'] == 'true' ? true : false;
5775 + $post_meta = get_permalink($id, $leavename);
5776 + $post_meta = $this->helper->load('translator')->translate_url($post_meta);
5777 + } elseif ($key == 'get_post_permalink' || $key == 'post_permalink') {
5778 + $leavename = isset($atts['leavename']) && $atts['leavename'] == 'true' ? true : false;
5779 + $post_meta = get_post_permalink($id, $leavename);
5780 + $post_meta = $this->helper->load('translator')->translate_url($post_meta);
5781 + } elseif ($key == 'response_hook') {
5782 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wc_cart_response_hook', '', $id, $atts, $wp_post);
5783 + } elseif (isset($wp_post->$key)) {
5784 + $post_meta = $wp_post->$key;
5785 + }
5786 + } elseif (in_array($key, $cart_fields, true) && !$meta && !$terms) {
5787 + if (function_exists('WC') && isset(WC()->cart) && WC()->cart && is_object(WC()->cart)) {
5788 + WC()->cart->calculate_totals();
5789 + if ($key == 'cart') {
5790 +
5791 + $items = WC()->cart->get_cart();
5792 + $content = '';
5793 +
5794 + if ($items) {
5795 + $show_products = isset($atts['show_products']) && $atts['show_products'] == 'false' ? false : true;
5796 + $show_image = isset($atts['show_image']) && $atts['show_image'] == 'false' ? false : true;
5797 + $show_sku = isset($atts['show_sku']) && $atts['show_sku'] == 'false' ? false : true;
5798 + $show_name = isset($atts['show_name']) && $atts['show_name'] == 'false' ? false : true;
5799 + $show_quantity = isset($atts['show_quantity']) && $atts['show_quantity'] == 'false' ? false : true;
5800 + $show_price = isset($atts['show_price']) && $atts['show_price'] == 'false' ? false : true;
5801 + $show_subtotal = isset($atts['show_subtotal']) && $atts['show_subtotal'] == 'false' ? false : true;
5802 + $show_meta = isset($atts['show_meta']) && $atts['show_meta'] == 'false' ? false : true;
5803 +
5804 + $show_totals = isset($atts['show_totals']) && $atts['show_totals'] == 'false' ? false : true;
5805 + $show_totals_subtotal = isset($atts['show_totals_subtotal']) && $atts['show_totals_subtotal'] == 'false' ? false : true;
5806 + $show_totals_coupons = isset($atts['show_totals_coupons']) && $atts['show_totals_coupons'] == 'false' ? false : true;
5807 + $show_totals_shipping = isset($atts['show_totals_shipping']) && $atts['show_totals_shipping'] == 'false' ? false : true;
5808 + $show_totals_shipping_destination = isset($atts['show_totals_shipping_destination']) && $atts['show_totals_shipping_destination'] == 'false' ? false : true;
5809 + $show_totals_shipping_package = isset($atts['show_totals_shipping_package']) && $atts['show_totals_shipping_package'] == 'false' ? false : true;
5810 + $show_totals_fees = isset($atts['show_totals_fees']) && $atts['show_totals_fees'] == 'false' ? false : true;
5811 + $show_totals_taxes = isset($atts['show_totals_taxes']) && $atts['show_totals_taxes'] == 'false' ? false : true;
5812 + $show_totals_total = isset($atts['show_totals_total']) && $atts['show_totals_total'] == 'false' ? false : true;
5813 +
5814 + if (isset($atts['size'])) {
5815 + $size = $atts['size'];
5816 + } elseif (isset($atts['image_size'])) {
5817 + $size = $atts['image_size'];
5818 + } else {
5819 + $size = '32x32';
5820 + }
5821 +
5822 + if (false !== strpos($size, 'x')) {
5823 + $image_size = explode('x', $size);
5824 + if (isset($image_size['0']) && isset($image_size['1'])) {
5825 + $image_width = absint($image_size['0']);
5826 + $image_height = absint($image_size['1']);
5827 + if ($image_width && $image_height) {
5828 + $size = [
5829 + $image_width, $image_height,
5830 + ];
1630 5831 }
1631 - } elseif ($attachment_image_url) {
1632 - if (!is_array($path_value)) {
1633 - $image = wp_get_attachment_image_url($path_value, $size);
1634 - if ($image) {
1635 - $response = $image;
5832 + }
5833 + }
5834 +
5835 + $plain_text = isset($atts['plain_text']) ? $atts['plain_text'] : false;
5836 + if ($show_products) {
5837 +
5838 + $content .= "<table border='1' split='true' bordercolor='#eeeeee' cellpadding='5' class='e2pdf-wc-cart-products'>";
5839 + $content .= "<tr bgcolor='#eeeeee' class='e2pdf-wc-cart-products-header'>";
5840 + if ($show_image) {
5841 + $content .= "<td class='e2pdf-wc-cart-products-header-image'>" . apply_filters('e2pdf_model_shortcode_wc_cart_cart_header_image_text', '', $atts, $value) . '</td>';
5842 + }
5843 + if ($show_name) {
5844 + $content .= "<td class='e2pdf-wc-cart-products-header-name'>" . apply_filters('e2pdf_model_shortcode_wc_cart_cart_header_name_text', __('Product', 'woocommerce'), $atts, $value) . '</td>';
5845 + }
5846 + if ($show_sku) {
5847 + $content .= "<td class='e2pdf-wc-cart-products-header-sku'>" . apply_filters('e2pdf_model_shortcode_wc_cart_cart_header_sku_text', __('SKU', 'woocommerce'), $atts, $value) . '</td>';
5848 + }
5849 + if ($show_quantity) {
5850 + $content .= "<td class='e2pdf-wc-cart-products-header-quantity'>" . apply_filters('e2pdf_model_shortcode_wc_cart_cart_header_quantity_text', __('Quantity', 'woocommerce'), $atts, $value) . '</td>';
5851 + }
5852 + if ($show_price) {
5853 + $content .= "<td class='e2pdf-wc-cart-products-header-price'>" . apply_filters('e2pdf_model_shortcode_wc_cart_cart_header_pricey_text', __('Price', 'woocommerce'), $atts, $value) . '</td>';
5854 + }
5855 + if ($show_subtotal) {
5856 + $content .= "<td class='e2pdf-wc-cart-products-header-subtotal'>" . apply_filters('e2pdf_model_shortcode_wc_cart_cart_header_pricey_text', __('Subtotal', 'woocommerce'), $atts, $value) . '</td>';
5857 + }
5858 + $content .= '</tr>';
5859 +
5860 + $item_index = 0;
5861 + foreach ($items as $item_id => $item) {
5862 + $product = apply_filters('woocommerce_cart_item_product', $item['data'], $item, $item_id);
5863 + if ($product && $product->exists() && $item['quantity'] > 0 && apply_filters('woocommerce_cart_item_visible', true, $item, $item_id)) {
5864 + $sku = '';
5865 + $purchase_note = '';
5866 + $image = '';
5867 +
5868 + if (is_object($product)) {
5869 + $sku = $product->get_sku();
5870 + $purchase_note = $product->get_purchase_note();
5871 + $image = $product->get_image($size);
1636 5872 }
5873 +
5874 + $even_odd = $item_index % 2 ? 'e2pdf-wc-cart-product-odd' : 'e2pdf-wc-cart-product-even';
5875 + $content .= "<tr class='e2pdf-wc-cart-product " . $even_odd . "'>";
5876 + if ($show_image) {
5877 + $content .= "<td align='center' class='e2pdf-wc-cart-product-image'>" . apply_filters('woocommerce_cart_item_thumbnail', $image, $item, $item_id) . '</td>';
5878 + }
5879 + if ($show_name) {
5880 + $content .= "<td class='e2pdf-wc-cart-product-name'>";
5881 + $product_permalink = apply_filters('woocommerce_cart_item_permalink', $product->is_visible() ? $product->get_permalink($item) : '', $item, $item_id);
5882 + if (!$product_permalink) {
5883 + $content .= wp_kses_post(apply_filters('woocommerce_cart_item_name', $product->get_name(), $item, $item_id) . '&nbsp;');
5884 + } else {
5885 + $content .= wp_kses_post(apply_filters('woocommerce_cart_item_name', sprintf('<a target="_blank" href="%s">%s</a>', esc_url($product_permalink), $product->get_name()), $item, $item_id));
5886 + }
5887 +
5888 + if ($show_meta) {
5889 + $wc_display_item_meta = wc_get_formatted_cart_item_data($item, true);
5890 +
5891 + if ($wc_display_item_meta) {
5892 + $content .= "<div size='8px' class='e2pdf-wc-cart-product-meta'>" . nl2br($wc_display_item_meta) . '</div>';
5893 + }
5894 + }
5895 +
5896 + $content .= '</td>';
5897 + }
5898 + if ($show_sku) {
5899 + $content .= "<td class='e2pdf-wc-cart-product-sku'>" . $sku . '</td>';
5900 + }
5901 + if ($show_quantity) {
5902 + $content .= "<td class='e2pdf-wc-cart-product-quantity'>" . $item['quantity'] . '</td>';
5903 + }
5904 + if ($show_price) {
5905 + $content .= "<td class='e2pdf-wc-cart-product-price'>" . apply_filters('woocommerce_cart_item_price', WC()->cart->get_product_price($product), $item, $item_id) . '</td>';
5906 + }
5907 + if ($show_subtotal) {
5908 + $content .= "<td class='e2pdf-wc-cart-product-subtotal'>" . apply_filters('woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal($product, $item['quantity']), $item, $item_id) . '</td>';
5909 + }
5910 + $content .= '</tr>';
5911 + $item_index++;
1637 5912 }
5913 + }
5914 + $content .= '</table>';
5915 + }
5916 +
5917 + $item_totals = [];
5918 + if ($show_totals) {
5919 + /* Total Subtotal */
5920 + if ($show_totals_subtotal) {
5921 + $item_totals['subtotal'] = [
5922 + 'label' => __('Subtotal', 'woocommerce'),
5923 + 'value' => WC()->cart->get_cart_subtotal(),
5924 + ];
5925 + }
5926 +
5927 + /* Total Coupons */
5928 + if ($show_totals_coupons) {
5929 + $index_id = 0;
5930 + foreach (WC()->cart->get_coupons() as $code => $coupon) {
5931 + if (is_string($coupon)) {
5932 + $coupon = new WC_Coupon($coupon);
5933 + }
5934 +
5935 + $discount_amount_html = '';
5936 + $amount = WC()->cart->get_coupon_discount_amount($coupon->get_code(), WC()->cart->display_cart_ex_tax);
5937 + $discount_amount_html = '-' . wc_price($amount);
5938 +
5939 + if ($coupon->get_free_shipping() && empty($amount)) {
5940 + $discount_amount_html = __('Free shipping coupon', 'woocommerce');
5941 + }
5942 +
5943 + $item_totals['coupon_' . $index_id] = [
5944 + 'label' => wc_cart_totals_coupon_label($coupon, false),
5945 + 'value' => $discount_amount_html,
5946 + ];
5947 + $index_id++;
5948 + }
5949 + }
5950 +
5951 + /* Total Shipping */
5952 + if ($show_totals_shipping) {
5953 + if (WC()->cart->needs_shipping() && WC()->cart->show_shipping()) {
5954 +
5955 + $packages = WC()->shipping()->get_packages();
5956 + $first = true;
5957 +
5958 + $index_id = 0;
5959 + foreach ($packages as $i => $package) {
5960 + $chosen_method = isset(WC()->session->chosen_shipping_methods[$i]) ? WC()->session->chosen_shipping_methods[$i] : '';
5961 + if ($chosen_method) {
5962 + $product_names = [];
5963 + if (count($packages) > 1) {
5964 + foreach ($package['contents'] as $item_id => $values) {
5965 + $product_names[$item_id] = $values['data']->get_name() . ' &times;' . $values['quantity'];
5966 + }
5967 + $product_names = apply_filters('woocommerce_shipping_package_details_array', $product_names, $package);
5968 + }
5969 +
5970 + $available_methods = $package['rates'];
5971 + $show_package_details = count($packages) > 1;
5972 + $package_details = implode(', ', $product_names);
5973 + /* translators: %d: shipping package number */
5974 + $package_name = apply_filters('woocommerce_shipping_package_name', (($i + 1) > 1) ? sprintf(_x('Shipping %d', 'shipping packages', 'woocommerce'), ($i + 1)) : _x('Shipping', 'shipping packages', 'woocommerce'), $i, $package);
5975 + $formatted_destination = WC()->countries->get_formatted_address($package['destination'], ', ');
5976 +
5977 + $item_totals['shipping_' . $index_id] = [
5978 + 'label' => wp_kses_post($package_name),
5979 + 'value' => '',
5980 + ];
5981 +
5982 + if ($available_methods) {
5983 + foreach ($available_methods as $method) {
5984 + if ($method->get_id() == $chosen_method) {
5985 + $item_totals['shipping_' . $index_id]['value'] .= '<div>' . wc_cart_totals_shipping_method_label($method) . '</div>';
5986 + }
5987 + }
5988 + }
5989 +
5990 + if ($show_totals_shipping_destination) {
5991 + if ($formatted_destination) {
5992 + /* translators: %s: location */
5993 + $item_totals['shipping_' . $index_id]['value'] .= "<div size='8px' class='e2pdf-wc-cart-total-shipping-destination'>" . sprintf(esc_html__('Shipping to %s.', 'woocommerce') . ' ', esc_html($formatted_destination)) . '</div>';
5994 + } else {
5995 + $item_totals['shipping_' . $index_id]['value'] .= "<div size='8px' class='e2pdf-wc-cart-total-shipping-destination'>" . wp_kses_post(apply_filters('woocommerce_shipping_estimate_html', __('Shipping options will be updated during checkout.', 'woocommerce'))) . '</div>';
5996 + }
5997 + }
5998 +
5999 + if ($show_totals_shipping_package) {
6000 + if ($show_package_details) {
6001 + $item_totals['shipping_' . $index_id]['value'] .= "<div size='8px' class='e2pdf-wc-cart-total-shipping-package'>" . esc_html($package_details) . '</div>';
6002 + }
6003 + }
6004 +
6005 + $index_id++;
6006 + $first = false;
6007 + }
6008 + }
6009 + } elseif (WC()->cart->needs_shipping() && 'yes' === get_option('woocommerce_enable_shipping_calc')) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedElseif
6010 + }
6011 + }
6012 +
6013 + /* Total Fees */
6014 + if ($show_totals_fees) {
6015 + $index_id = 0;
6016 + foreach (WC()->cart->get_fees() as $fee) {
6017 + $cart_totals_fee_html = WC()->cart->display_prices_including_tax() ? wc_price($fee->total + $fee->tax) : wc_price($fee->total);
6018 + $item_totals['fee_' . $index_id] = [
6019 + 'label' => esc_html($fee->name),
6020 + 'value' => apply_filters('woocommerce_cart_totals_fee_html', $cart_totals_fee_html, $fee),
6021 + ];
6022 + $index_id++;
6023 + }
6024 + }
6025 +
6026 + /* Total Taxes */
6027 + if ($show_totals_taxes) {
6028 + if (wc_tax_enabled() && !WC()->cart->display_prices_including_tax()) {
6029 + $taxable_address = WC()->customer->get_taxable_address();
6030 + $estimated_text = '';
6031 +
6032 + if (WC()->customer->is_customer_outside_base() && !WC()->customer->has_calculated_shipping()) {
6033 + /* translators: %s: location */
6034 + $estimated_text = sprintf(' <small>' . esc_html__('(estimated for %s)', 'woocommerce') . '</small>', WC()->countries->estimated_for_prefix($taxable_address[0]) . WC()->countries->countries[$taxable_address[0]]);
6035 + }
6036 +
6037 + if ('itemized' === get_option('woocommerce_tax_total_display')) {
6038 + $index_id = 0;
6039 + foreach (WC()->cart->get_tax_totals() as $code => $tax) {
6040 + $item_totals['tax_' . $index_id] = [
6041 + 'label' => esc_html($tax->label) . $estimated_text,
6042 + 'value' => wp_kses_post($tax->formatted_amount),
6043 + ];
6044 + $index_id++;
6045 + }
6046 + } else {
6047 + $item_totals['tax_or_vat'] = [
6048 + 'label' => esc_html(WC()->countries->tax_or_vat()) . $estimated_text,
6049 + 'value' => apply_filters('woocommerce_cart_totals_taxes_total_html', wc_price(WC()->cart->get_taxes_total())),
6050 + ];
6051 + }
6052 + }
6053 + }
6054 +
6055 + /* Total Total */
6056 + if ($show_totals_total) {
6057 + $total = WC()->cart->get_total();
6058 + if (wc_tax_enabled() && WC()->cart->display_prices_including_tax()) {
6059 + $tax_string_array = [];
6060 + $cart_tax_totals = WC()->cart->get_tax_totals();
6061 +
6062 + if (get_option('woocommerce_tax_total_display') === 'itemized') {
6063 + foreach ($cart_tax_totals as $code => $tax) {
6064 + $tax_string_array[] = sprintf('%s %s', $tax->formatted_amount, $tax->label);
6065 + }
6066 + } elseif (!empty($cart_tax_totals)) {
6067 + $tax_string_array[] = sprintf('%s %s', wc_price(WC()->cart->get_taxes_total(true, true)), WC()->countries->tax_or_vat());
6068 + }
6069 +
6070 + if (!empty($tax_string_array)) {
6071 + $taxable_address = WC()->customer->get_taxable_address();
6072 + /* translators: %s: location */
6073 + $estimated_text = WC()->customer->is_customer_outside_base() && !WC()->customer->has_calculated_shipping() ? sprintf(' ' . __('estimated for %s', 'woocommerce'), WC()->countries->estimated_for_prefix($taxable_address[0]) . WC()->countries->countries[$taxable_address[0]]) : '';
6074 + $total .= '<small class="includes_tax"> ('
6075 + . esc_html__('includes', 'woocommerce')
6076 + . ' '
6077 + . wp_kses_post(implode(', ', $tax_string_array))
6078 + . esc_html($estimated_text)
6079 + . ')</small>';
6080 + }
6081 + }
6082 +
6083 + $item_totals['total'] = [
6084 + 'label' => __('Total', 'woocommerce'),
6085 + 'value' => apply_filters('woocommerce_cart_totals_order_total_html', $total),
6086 + ];
6087 + }
6088 +
6089 + $item_totals = apply_filters('e2pdf_model_shortcode_wc_cart_item_totals', $item_totals, $atts, $value);
6090 +
6091 + if (!empty($item_totals)) {
6092 + $total_index = 0;
6093 + $content .= "<table split='true' cellpadding='5' class='e2pdf-wc-cart-totals'>";
6094 + foreach ($item_totals as $total_key => $total) {
6095 + $even_odd = $total_index % 2 ? 'e2pdf-wc-cart-total-odd' : 'e2pdf-wc-cart-total-even';
6096 + $content .= "<tr class='e2pdf-wc-cart-total e2pdf-wc-cart-total-" . $total_key . ' ' . $even_odd . "'>";
6097 + $content .= "<td valign='top' width='60%' align='right' class='e2pdf-wc-cart-total-label'>" . $total['label'] . ':</td>';
6098 + $content .= "<td valign='top' align='right' class='e2pdf-wc-cart-total-value'>" . $total['value'] . '</td>';
6099 + $content .= '</tr>';
6100 + $total_index++;
6101 + }
6102 + $content .= '</table>';
6103 + }
6104 + }
6105 + }
6106 + $post_meta = $content;
6107 + } elseif ($key == 'get_shipping_method_title') {
6108 + $packages = WC()->shipping()->get_packages();
6109 + foreach ($packages as $i => $package) {
6110 + $chosen_method = isset(WC()->session->chosen_shipping_methods[$i]) ? WC()->session->chosen_shipping_methods[$i] : '';
6111 + if ($chosen_method) {
6112 + $available_methods = $package['rates'];
6113 + if ($available_methods) {
6114 + foreach ($available_methods as $method) {
6115 + if ($method->get_id() == $chosen_method) {
6116 + $post_meta = wc_cart_totals_shipping_method_label($method);
6117 + break;
6118 + }
6119 + }
6120 + }
6121 + }
6122 + }
6123 + } elseif ($key == 'get_payment_method_title') {
6124 + $chosen_method = isset(WC()->session->chosen_payment_method) ? WC()->session->chosen_payment_method : '';
6125 + $packages = WC()->payment_gateways->get_available_payment_gateways();
6126 + foreach ($packages as $i => $package) {
6127 + if ($i == $chosen_method) {
6128 + $post_meta = $package->get_title();
6129 + break;
6130 + }
6131 + }
6132 + } elseif ($key == 'get_formatted_cart_totals') {
6133 +
6134 + $include = [
6135 + 'subtotal',
6136 + 'coupons',
6137 + 'shipping',
6138 + 'shipping_destination',
6139 + 'shipping_package',
6140 + 'fees',
6141 + 'taxes',
6142 + 'total',
6143 + ];
6144 +
6145 + if (isset($atts['include'])) {
6146 + $include = explode(',', $atts['include']);
6147 + }
6148 +
6149 + $exclude = [];
6150 + if (isset($atts['exclude'])) {
6151 + $exclude = explode(',', $atts['exclude']);
6152 + }
6153 + $include = array_diff($include, $exclude);
6154 +
6155 + /* Total Subtotal */
6156 + if (in_array('subtotal', $include, true)) {
6157 + $item_totals['subtotal'] = [
6158 + 'label' => __('Subtotal', 'woocommerce'),
6159 + 'value' => WC()->cart->get_cart_subtotal(),
6160 + ];
6161 + }
6162 +
6163 + /* Total Coupons */
6164 + if (in_array('coupons', $include, true)) {
6165 + $index_id = 0;
6166 + foreach (WC()->cart->get_coupons() as $code => $coupon) {
6167 + if (is_string($coupon)) {
6168 + $coupon = new WC_Coupon($coupon);
6169 + }
6170 +
6171 + $discount_amount_html = '';
6172 + $amount = WC()->cart->get_coupon_discount_amount($coupon->get_code(), WC()->cart->display_cart_ex_tax);
6173 + $discount_amount_html = '-' . wc_price($amount);
6174 +
6175 + if ($coupon->get_free_shipping() && empty($amount)) {
6176 + $discount_amount_html = __('Free shipping coupon', 'woocommerce');
6177 + }
6178 +
6179 + $item_totals['coupon_' . $index_id] = [
6180 + 'label' => wc_cart_totals_coupon_label($coupon, false),
6181 + 'value' => $discount_amount_html,
6182 + ];
6183 + $index_id++;
6184 + }
6185 + }
6186 +
6187 + /* Total Shipping */
6188 + if (in_array('shipping', $include, true)) {
6189 + if (WC()->cart->needs_shipping() && WC()->cart->show_shipping()) {
6190 +
6191 + $packages = WC()->shipping()->get_packages();
6192 + $first = true;
6193 +
6194 + $index_id = 0;
6195 + foreach ($packages as $i => $package) {
6196 + $chosen_method = isset(WC()->session->chosen_shipping_methods[$i]) ? WC()->session->chosen_shipping_methods[$i] : '';
6197 + if ($chosen_method) {
6198 + $product_names = [];
6199 + if (count($packages) > 1) {
6200 + foreach ($package['contents'] as $item_id => $values) {
6201 + $product_names[$item_id] = $values['data']->get_name() . ' &times;' . $values['quantity'];
6202 + }
6203 + $product_names = apply_filters('woocommerce_shipping_package_details_array', $product_names, $package);
6204 + }
6205 +
6206 + $available_methods = $package['rates'];
6207 + $show_package_details = count($packages) > 1;
6208 + $package_details = implode(', ', $product_names);
6209 + /* translators: %d: shipping package number */
6210 + $package_name = apply_filters('woocommerce_shipping_package_name', (($i + 1) > 1) ? sprintf(_x('Shipping %d', 'shipping packages', 'woocommerce'), ($i + 1)) : _x('Shipping', 'shipping packages', 'woocommerce'), $i, $package);
6211 + $formatted_destination = WC()->countries->get_formatted_address($package['destination'], ', ');
6212 +
6213 + $item_totals['shipping_' . $index_id] = [
6214 + 'label' => wp_kses_post($package_name),
6215 + 'value' => '',
6216 + ];
6217 +
6218 + if ($available_methods) {
6219 + foreach ($available_methods as $method) {
6220 + if ($method->get_id() == $chosen_method) {
6221 + $item_totals['shipping_' . $index_id]['value'] .= '<div>' . wc_cart_totals_shipping_method_label($method) . '</div>';
6222 + }
6223 + }
6224 + }
6225 +
6226 + if (in_array('shipping_destination', $include, true)) {
6227 + if ($formatted_destination) {
6228 + /* translators: %s location */
6229 + $item_totals['shipping_' . $index_id]['value'] .= "<div size='8px' class='e2pdf-wc-cart-total-shipping-destination'>" . sprintf(esc_html__('Shipping to %s.', 'woocommerce') . ' ', esc_html($formatted_destination)) . '</div>';
6230 + } else {
6231 + $item_totals['shipping_' . $index_id]['value'] .= "<div size='8px' class='e2pdf-wc-cart-total-shipping-destination'>" . wp_kses_post(apply_filters('woocommerce_shipping_estimate_html', __('Shipping options will be updated during checkout.', 'woocommerce'))) . '</div>';
6232 + }
6233 + }
6234 +
6235 + if (in_array('shipping_package', $include, true)) {
6236 + if ($show_package_details) {
6237 + $item_totals['shipping_' . $index_id]['value'] .= "<div size='8px' class='e2pdf-wc-cart-total-shipping-package'>" . esc_html($package_details) . '</div>';
6238 + }
6239 + }
6240 +
6241 + $index_id++;
6242 + $first = false;
6243 + }
6244 + }
6245 + } elseif (WC()->cart->needs_shipping() && 'yes' === get_option('woocommerce_enable_shipping_calc')) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedElseif
6246 + }
6247 + }
6248 +
6249 + /* Total Fees */
6250 + if (in_array('fees', $include, true)) {
6251 + $index_id = 0;
6252 + foreach (WC()->cart->get_fees() as $fee) {
6253 + $cart_totals_fee_html = WC()->cart->display_prices_including_tax() ? wc_price($fee->total + $fee->tax) : wc_price($fee->total);
6254 + $item_totals['fee_' . $index_id] = [
6255 + 'label' => esc_html($fee->name),
6256 + 'value' => apply_filters('woocommerce_cart_totals_fee_html', $cart_totals_fee_html, $fee),
6257 + ];
6258 + $index_id++;
6259 + }
6260 + }
6261 +
6262 + /* Total Taxes */
6263 + if (in_array('taxes', $include, true)) {
6264 + if (wc_tax_enabled() && !WC()->cart->display_prices_including_tax()) {
6265 + $taxable_address = WC()->customer->get_taxable_address();
6266 + $estimated_text = '';
6267 +
6268 + if (WC()->customer->is_customer_outside_base() && !WC()->customer->has_calculated_shipping()) {
6269 + /* translators: %s: location */
6270 + $estimated_text = sprintf(' <small>' . esc_html__('(estimated for %s)', 'woocommerce') . '</small>', WC()->countries->estimated_for_prefix($taxable_address[0]) . WC()->countries->countries[$taxable_address[0]]);
6271 + }
6272 +
6273 + if ('itemized' === get_option('woocommerce_tax_total_display')) {
6274 + $index_id = 0;
6275 + foreach (WC()->cart->get_tax_totals() as $code => $tax) {
6276 + $item_totals['tax_' . $index_id] = [
6277 + 'label' => esc_html($tax->label) . $estimated_text,
6278 + 'value' => wp_kses_post($tax->formatted_amount),
6279 + ];
6280 + $index_id++;
6281 + }
1638 6282 } else {
1639 - if (is_array($path_value)) {
1640 - $response = serialize($path_value);
1641 - } else {
1642 - $response = $path_value;
6283 + $item_totals['tax_or_vat'] = [
6284 + 'label' => esc_html(WC()->countries->tax_or_vat()) . $estimated_text,
6285 + 'value' => apply_filters('woocommerce_cart_totals_taxes_total_html', wc_price(WC()->cart->get_taxes_total())),
6286 + ];
6287 + }
6288 + }
6289 + }
6290 +
6291 + /*
6292 + * Total Total
6293 + */
6294 + if (in_array('total', $include, true)) {
6295 + $total = WC()->cart->get_total();
6296 + if (wc_tax_enabled() && WC()->cart->display_prices_including_tax()) {
6297 + $tax_string_array = [];
6298 + $cart_tax_totals = WC()->cart->get_tax_totals();
6299 +
6300 + if (get_option('woocommerce_tax_total_display') === 'itemized') {
6301 + foreach ($cart_tax_totals as $code => $tax) {
6302 + $tax_string_array[] = sprintf('%s %s', $tax->formatted_amount, $tax->label);
1643 6303 }
6304 + } elseif (!empty($cart_tax_totals)) {
6305 + $tax_string_array[] = sprintf('%s %s', wc_price(WC()->cart->get_taxes_total(true, true)), WC()->countries->tax_or_vat());
1644 6306 }
6307 +
6308 + if (!empty($tax_string_array)) {
6309 + $taxable_address = WC()->customer->get_taxable_address();
6310 + /* translators: %s: location */
6311 + $estimated_text = WC()->customer->is_customer_outside_base() && !WC()->customer->has_calculated_shipping() ? sprintf(' ' . __('estimated for %s', 'woocommerce'), WC()->countries->estimated_for_prefix($taxable_address[0]) . WC()->countries->countries[$taxable_address[0]]) : '';
6312 + $total .= '<small class="includes_tax"> ('
6313 + . esc_html__('includes', 'woocommerce')
6314 + . ' '
6315 + . wp_kses_post(implode(', ', $tax_string_array))
6316 + . esc_html($estimated_text)
6317 + . ')</small>';
6318 + }
1645 6319 }
6320 +
6321 + $item_totals['total'] = [
6322 + 'label' => __('Total', 'woocommerce'),
6323 + 'value' => apply_filters('woocommerce_cart_totals_order_total_html', $total),
6324 + ];
6325 + }
6326 +
6327 + $item_totals = apply_filters('e2pdf_model_shortcode_wc_cart_get_cart_totals', $item_totals, $atts, $value);
6328 + $post_meta = $item_totals;
6329 + } else {
6330 + if (method_exists(WC()->cart, $key)) {
6331 + if ($key == 'get_cart_subtotal' && $output == 'compound') {
6332 + $post_meta = WC()->cart->$key(true);
6333 + } elseif ($key == 'get_total' && $output == 'edit') {
6334 + $post_meta = WC()->cart->$key('edit');
6335 + } elseif ($key == 'get_taxes_total' && $output) {
6336 + $compound = true;
6337 + $display = true;
6338 + $output_data = explode('|', $output);
6339 + if (in_array('nocompound', $output_data, true)) {
6340 + $compound = false;
6341 + }
6342 + if (in_array('nodisplay', $output_data, true)) {
6343 + $display = false;
6344 + }
6345 + $post_meta = WC()->cart->$key($compound, $display);
6346 + } else {
6347 + $post_meta = WC()->cart->$key();
6348 + }
6349 + }
6350 + }
6351 + }
6352 + } elseif ($terms && $names) {
6353 + $post_terms = wp_get_post_terms($id, $key, ['fields' => 'names']);
6354 + if (!is_wp_error($post_terms) && is_array($post_terms)) {
6355 + foreach ($post_terms as $post_term_key => $post_terms_value) {
6356 + $post_terms[$post_term_key] = $this->helper->load('translator')->translate($post_terms_value);
6357 + }
6358 + if ($implode === false) {
6359 + $implode = ', ';
6360 + }
6361 + $post_meta = implode($implode, $post_terms);
6362 + }
6363 + } elseif ($terms) {
6364 + $post_terms = wp_get_post_terms($id, $key);
6365 + if (!is_wp_error($post_terms)) {
6366 + // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
6367 + $post_meta = json_decode(json_encode($post_terms), true);
6368 + }
6369 + } else {
6370 + $post_meta = get_post_meta($id, $key, true);
6371 + }
6372 +
6373 + if ($post_meta !== false) {
6374 +
6375 + if (is_object($post_meta)) {
6376 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wc_cart_object', $post_meta, $atts);
6377 + }
6378 +
6379 + if ($explode && !is_array($post_meta)) {
6380 + $post_meta = explode($explode, $post_meta);
6381 + }
6382 +
6383 + if (is_array($post_meta)) {
6384 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wc_cart_array', $post_meta, $atts);
6385 + }
6386 +
6387 + if (is_string($post_meta) && $path !== false && is_object(json_decode($post_meta))) {
6388 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wc_cart_json', json_decode($post_meta, true), $atts);
6389 + }
6390 +
6391 + if ((is_array($post_meta) || is_object($post_meta)) && $path !== false) {
6392 + $post_meta = $this->helper->load('shortcode')->apply_path_attribute($post_meta, $path);
6393 + }
6394 +
6395 + if ($attachment_url || $attachment_image_url) {
6396 + if (!is_array($post_meta)) {
6397 + if (strpos($post_meta, ',') !== false) {
6398 + $post_meta = explode(',', $post_meta);
6399 + if ($implode === false) {
6400 + $implode = ',';
6401 + }
6402 + }
6403 + }
6404 + if ($attachment_url) {
6405 + $post_meta = $this->helper->load('shortcode')->apply_attachment_attribute($post_meta, 'attachment_url', $size);
6406 + } else {
6407 + $post_meta = $this->helper->load('shortcode')->apply_attachment_attribute($post_meta, 'attachment_image_url', $size);
6408 + }
6409 + }
6410 +
6411 + if ($wc_price || $wc_price_raw) {
6412 + if (is_array($post_meta) || is_object($post_meta)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
6413 + } else {
6414 + if (isset($atts['currency'])) {
6415 + $post_meta = wc_price($post_meta, $atts['currency']);
1646 6416 } else {
6417 + $post_meta = wc_price($post_meta);
6418 + }
6419 + if ($wc_price_raw) {
6420 + $post_meta = html_entity_decode(wp_strip_all_tags($post_meta));
6421 + }
6422 + }
6423 + }
6424 +
6425 + if (apply_filters('e2pdf_raw_output', false)) {
6426 + $response = $post_meta;
6427 + } else {
6428 + if (is_array($post_meta)) {
6429 + if ($implode !== false) {
6430 + if (!$this->helper->is_multidimensional($post_meta)) {
6431 + foreach ($post_meta as $post_meta_key => $post_meta_value) {
6432 + $post_meta[$post_meta_key] = $this->helper->load('translator')->translate($post_meta_value);
6433 + }
6434 + $response = implode($implode, $post_meta);
6435 + } else {
6436 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
6437 + $response = serialize($post_meta);
6438 + }
6439 + } else {
6440 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
1647 6441 $response = serialize($post_meta);
1648 6442 }
6443 + } elseif (is_object($post_meta)) {
6444 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
6445 + $response = serialize($post_meta);
1649 6446 } else {
1650 - if ($attachment_url) {
1651 - $response = wp_get_attachment_url($post_meta);
1652 - } elseif ($attachment_image_url) {
1653 - $image = wp_get_attachment_image_url($post_meta, $size);
1654 - if ($image) {
1655 - $response = $image;
1656 - }
1657 - } else {
1658 - $response = $post_meta;
6447 + $response = $post_meta;
6448 + }
6449 + }
6450 + }
6451 + }
6452 + }
6453 +
6454 + if (apply_filters('e2pdf_raw_output', false)) {
6455 + return apply_filters('e2pdf_model_shortcode_e2pdf_wc_cart_raw', $response, $atts, $value);
6456 + } else {
6457 + $response = $this->helper->load('translator')->translate($response, 'partial');
6458 + if (!apply_filters('e2pdf_pdf_fill', false)) {
6459 + $response = $this->sanitize_html($response);
6460 + }
6461 + return apply_filters('e2pdf_model_shortcode_e2pdf_wc_cart_response', $response, $atts, $value);
6462 + }
6463 + }
6464 +
6465 + // e2pdf-wc-customer
6466 + public function e2pdf_wc_customer($atts = [], $value = '') {
6467 +
6468 + if (!apply_filters('e2pdf_shortcode_enable_e2pdf_wc_customer', false) && !apply_filters('e2pdf_pdf_render', false)) {
6469 + return '';
6470 + }
6471 +
6472 + $post_meta = false;
6473 + $response = '';
6474 +
6475 + $atts = apply_filters('e2pdf_model_shortcode_e2pdf_wc_customer', $atts);
6476 +
6477 + $key = isset($atts['key']) ? $atts['key'] : false;
6478 + $path = isset($atts['path']) ? $atts['path'] : false;
6479 + $explode = isset($atts['explode']) ? $atts['explode'] : false;
6480 + $implode = isset($atts['implode']) ? $atts['implode'] : false;
6481 + $size = isset($atts['size']) ? $atts['size'] : 'thumbnail';
6482 + $attachment_url = isset($atts['attachment_url']) && $atts['attachment_url'] == 'true' ? true : false;
6483 + $attachment_image_url = isset($atts['attachment_image_url']) && $atts['attachment_image_url'] == 'true' ? true : false;
6484 + $output = isset($atts['output']) ? $atts['output'] : false;
6485 +
6486 + $customer_fields = apply_filters(
6487 + 'e2pdf_model_shortcode_wc_customer_fields',
6488 + [
6489 + 'get_taxable_address',
6490 + 'is_vat_exempt',
6491 + 'get_is_vat_exempt',
6492 + 'has_calculated_shipping',
6493 + 'get_calculated_shipping',
6494 + 'get_avatar_url',
6495 + 'get_username',
6496 + 'get_email',
6497 + 'get_first_name',
6498 + 'get_last_name',
6499 + 'get_display_name',
6500 + 'get_role',
6501 + 'get_date_created',
6502 + 'get_date_modified',
6503 + 'get_billing',
6504 + 'get_billing_first_name',
6505 + 'get_billing_last_name',
6506 + 'get_billing_company',
6507 + 'get_billing_address',
6508 + 'get_billing_address_1',
6509 + 'get_billing_address_2',
6510 + 'get_billing_city',
6511 + 'get_billing_state',
6512 + 'get_billing_postcode',
6513 + 'get_billing_country',
6514 + 'get_billing_email',
6515 + 'get_billing_phone',
6516 + 'get_shipping',
6517 + 'get_shipping_first_name',
6518 + 'get_shipping_last_name',
6519 + 'get_shipping_company',
6520 + 'get_shipping_address',
6521 + 'get_shipping_address_1',
6522 + 'get_shipping_address_2',
6523 + 'get_shipping_city',
6524 + 'get_shipping_state',
6525 + 'get_shipping_postcode',
6526 + 'get_shipping_country',
6527 + 'get_is_paying_customer',
6528 + 'get_formatted_shipping_address',
6529 + 'get_formatted_billing_address',
6530 + ]
6531 + );
6532 +
6533 + if (in_array($key, $customer_fields, true)) {
6534 + if (function_exists('WC') && isset(WC()->customer) && WC()->customer && is_object(WC()->customer)) {
6535 + if ($key == 'get_formatted_shipping_address') {
6536 + if (isset(WC()->countries) && isset(WC()->customer)) {
6537 + $post_meta = WC()->countries->get_formatted_address(WC()->customer->data['shipping']);
6538 + }
6539 + } elseif ($key == 'get_formatted_billing_address') {
6540 + if (isset(WC()->countries) && isset(WC()->customer)) {
6541 + $post_meta = WC()->countries->get_formatted_address(WC()->customer->data['billing']);
6542 + }
6543 + } elseif ($key == 'get_date_created' || $key == 'get_date_modified') {
6544 + $format = isset($atts['format']) && $atts['format'] ? $atts['format'] : get_option('date_format') . ', ' . get_option('time_format');
6545 + $post_meta = wc_format_datetime(WC()->customer->$key(), $format);
6546 + } else {
6547 + if (method_exists(WC()->customer, $key)) {
6548 + if ($output == 'edit') {
6549 + $post_meta = WC()->customer->$key('edit');
6550 + } else {
6551 + $post_meta = WC()->customer->$key();
6552 + }
6553 + }
6554 + }
6555 + }
6556 + }
6557 +
6558 + if ($post_meta !== false) {
6559 +
6560 + if (is_object($post_meta)) {
6561 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wc_customer_object', $post_meta, $atts);
6562 + }
6563 +
6564 + if ($explode && !is_array($post_meta)) {
6565 + $post_meta = explode($explode, $post_meta);
6566 + }
6567 +
6568 + if (is_array($post_meta)) {
6569 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wc_customer_array', $post_meta, $atts);
6570 + }
6571 +
6572 + if (is_string($post_meta) && $path !== false && is_object(json_decode($post_meta))) {
6573 + $post_meta = apply_filters('e2pdf_model_shortcode_e2pdf_wc_customer_json', json_decode($post_meta, true), $atts);
6574 + }
6575 +
6576 + if ((is_array($post_meta) || is_object($post_meta)) && $path !== false) {
6577 + $post_meta = $this->helper->load('shortcode')->apply_path_attribute($post_meta, $path);
6578 + }
6579 +
6580 + if ($attachment_url || $attachment_image_url) {
6581 + if (!is_array($post_meta)) {
6582 + if (strpos($post_meta, ',') !== false) {
6583 + $post_meta = explode(',', $post_meta);
6584 + if ($implode === false) {
6585 + $implode = ',';
6586 + }
6587 + }
6588 + }
6589 + if ($attachment_url) {
6590 + $post_meta = $this->helper->load('shortcode')->apply_attachment_attribute($post_meta, 'attachment_url', $size);
6591 + } else {
6592 + $post_meta = $this->helper->load('shortcode')->apply_attachment_attribute($post_meta, 'attachment_image_url', $size);
6593 + }
6594 + }
6595 +
6596 + if (apply_filters('e2pdf_raw_output', false)) {
6597 + $response = $post_meta;
6598 + } else {
6599 + if (is_array($post_meta)) {
6600 + if ($implode !== false) {
6601 + if (!$this->helper->is_multidimensional($post_meta)) {
6602 + foreach ($post_meta as $post_meta_key => $post_meta_value) {
6603 + $post_meta[$post_meta_key] = $this->helper->load('translator')->translate($post_meta_value);
1659 6604 }
6605 + $response = implode($implode, $post_meta);
6606 + } else {
6607 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
6608 + $response = serialize($post_meta);
1660 6609 }
6610 + } else {
6611 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
6612 + $response = serialize($post_meta);
1661 6613 }
6614 + } elseif (is_object($post_meta)) {
6615 + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
6616 + $response = serialize($post_meta);
6617 + } else {
6618 + $response = $post_meta;
1662 6619 }
1663 6620 }
1664 6621 }
1665 - return $response;
6622 +
6623 + if (apply_filters('e2pdf_raw_output', false)) {
6624 + return apply_filters('e2pdf_model_shortcode_e2pdf_wc_customer_raw', $response, $atts, $value);
6625 + } else {
6626 + $response = $this->helper->load('translator')->translate($response, 'partial');
6627 + if (!apply_filters('e2pdf_pdf_fill', false)) {
6628 + $response = $this->sanitize_html($response);
6629 + }
6630 + return apply_filters('e2pdf_model_shortcode_e2pdf_wc_customer_response', $response, $atts, $value);
6631 + }
1666 6632 }
1667 6633
1668 - /**
1669 - * [e2pdf-filter] shortcode
1670 - *
1671 - * @param array $atts - Attributes
1672 - * @param string $value - Content
1673 - */
1674 - function e2pdf_filter($atts = array(), $value = '') {
6634 + public function e2pdf_page_number($atts = [], $value = '') {
6635 + return 'e2pdf-page-number';
6636 + }
6637 +
6638 + public function e2pdf_page_total($atts = [], $value = '') {
6639 + return 'e2pdf-page-total';
6640 + }
6641 +
6642 + public function e2pdf_acf_repeater($atts, $value = '') {
6643 +
6644 + if (!apply_filters('e2pdf_shortcode_enable_e2pdf_acf_repeater', false) && !apply_filters('e2pdf_pdf_render', false)) {
6645 + return '';
6646 + }
6647 +
6648 + $response = $this->helper->load('acfrepeater')->do_shortcode($atts, $value);
6649 + if (!apply_filters('e2pdf_pdf_fill', false)) {
6650 + $response = $this->sanitize_html($response);
6651 + }
6652 + return apply_filters('e2pdf_model_shortcode_e2pdf_acf_repeater_response', $response, $atts, $value);
6653 + }
6654 +
6655 + // e2pdf-filter
6656 + public function e2pdf_filter($atts = [], $value = '') {
6657 + $atts = apply_filters('e2pdf_model_shortcode_e2pdf_filter_atts', $atts);
1675 6658 if ($value) {
1676 - $search = array(
1677 - '[', ']', '\'', '"', '&#091;', '&#093;'
1678 - );
1679 -
1680 - $replace = array(
1681 - '&#91;', '&#93;', '&#39;', '&#34;', '&#91;', '&#93;'
1682 - );
6659 + $search = ['[', ']', '&#091;', '&#093;'];
6660 + $replace = ['&#91;', '&#93;', '&#91;', '&#93;'];
1683 6661 $value = str_replace($search, $replace, $value);
6662 + $value = esc_attr($value);
1684 6663 }
1685 6664 return $value;
1686 6665 }
1687 6666
6667 + public function process_shortcode($shortcode = false, $template = null, $attributes = null) {
6668 + if (!$attributes->get('noactions') && $template->get('actions')) {
6669 + $model_e2pdf_action = new Model_E2pdf_Action();
6670 + $model_e2pdf_action->load($template->extension());
6671 + if (!is_array($template->get('actions'))) {
6672 + $template->set('actions', $this->helper->load('convert')->unserialize($template->get('actions')));
6673 + }
6674 + $actions = $model_e2pdf_action->process_global_actions($template->get('actions'));
6675 + foreach ($actions as $action) {
6676 + if (isset($action['action']) && $action['action'] == 'disable_shortcodes' && isset($action['success'])) {
6677 + return false;
6678 + } elseif (isset($action['action']) && $action['action'] == 'enable_shortcodes' && !isset($action['success'])) {
6679 + return false;
6680 + } elseif ($shortcode && isset($action['action']) && $action['action'] == 'disable_' . $shortcode && isset($action['success'])) {
6681 + return false;
6682 + } elseif ($shortcode && isset($action['action']) && $action['action'] == 'enable_' . $shortcode && !isset($action['success'])) {
6683 + return false;
6684 + }
6685 + }
6686 + }
6687 + return true;
6688 + }
6689 +
6690 + public function action_e2pdf_hash_clear() {
6691 + // phpcs:disable WordPress.Security.NonceVerification.Recommended
6692 + if (isset($_GET['e2pdf-hash'])) {
6693 + $hash_id = sanitize_text_field(wp_unslash($_GET['e2pdf-hash']));
6694 + delete_transient('e2pdf_hash_' . $hash_id);
6695 + }
6696 + // phpcs:enable
6697 + }
6698 +
6699 + // WPBakery Page Builder Download Shortcode
6700 + public function e2pdf_vc_download($atts, $value = null) {
6701 + if (function_exists('get_the_ID')) {
6702 + $atts = array_filter((array) $atts, 'strlen');
6703 + $atts['dataset'] = get_the_ID();
6704 + return $this->e2pdf_download($atts);
6705 + }
6706 + return '';
6707 + }
6708 +
6709 + // WPBakery Page Builder View Shortcode
6710 + public function e2pdf_vc_view($atts, $value = null) {
6711 + if (function_exists('get_the_ID')) {
6712 + $atts = array_filter((array) $atts, 'strlen');
6713 + $atts['dataset'] = get_the_ID();
6714 + return $this->e2pdf_view($atts);
6715 + }
6716 + return '';
6717 + }
6718 +
6719 + // WPBakery Page Builder Grid Item Download Shortcode
6720 + public function e2pdf_vc_download_item($atts, $value = null) {
6721 + return '{{ e2pdf_download:' . http_build_query((array) $atts) . ' }}';
6722 + }
6723 +
6724 + // WPBakery Page Builder Grid Item View Shortcode
6725 + public function e2pdf_vc_view_item($atts, $value = null) {
6726 + return '{{ e2pdf_view:' . http_build_query((array) $atts) . ' }}';
6727 + }
6728 +
6729 + // sanitize css
6730 + public function sanitize_css($css) {
6731 + $css = apply_filters('e2pdf_safe_css', $css);
6732 + return $css;
6733 + }
6734 +
6735 + // sanitize html
6736 + public function sanitize_html($html) {
6737 + $allowed_html = apply_filters('e2pdf_safe_html', wp_kses_allowed_html('post'));
6738 + add_filter('safe_style_css', [$this, 'sanitize_css']);
6739 + $html = wp_kses($html, $allowed_html);
6740 + remove_filter('safe_style_css', [$this, 'sanitize_css']);
6741 + return $html;
6742 + }
1688 6743 }