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