PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.05.03
E2Pdf – Export Pdf Tool for WordPress v1.05.03
1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 1.08.00 1.08.06 All 72 releases
e2pdf / classes / model / e2pdf-shortcode.php

e2pdf-shortcode.php in E2Pdf – Export Pdf Tool for WordPress 1.05.03, at classes/model/e2pdf-shortcode.php

941 lines 37.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
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
11 */
12 if (!defined('ABSPATH')) {
13 die('Access denied.');
14 }
15
16 class Model_E2pdf_Shortcode extends Model_E2pdf_Model {
17
18 function __construct() {
19 parent::__construct();
20 }
21
22 /**
23 * [e2pdf-attachment] shortcode
24 *
25 * @param array $atts - Shortcode attributes
26 */
27 function e2pdf_attachment($atts = array()) {
28
29 $template_id = isset($atts['id']) ? (int) $atts['id'] : 0;
30
31 $response = '';
32
33 if (!array_key_exists('apply', $atts) || !array_key_exists('dataset', $atts) || !$template_id) {
34 return $response;
35 }
36
37 $dataset = $atts['dataset'];
38
39 $template = new Model_E2pdf_Template();
40 if ($template->load($template_id)) {
41
42 $uid_params = array();
43 $uid_params['template_id'] = $template_id;
44 $uid_params['dataset'] = $dataset;
45
46 $template->extension()->set('dataset', $dataset);
47
48 $options = array();
49 $options = apply_filters('e2pdf_model_shortcode_extension_options', $options, $template);
50 $options = apply_filters('e2pdf_model_shortcode_e2pdf_attachment_extension_options', $options, $template);
51
52 foreach ($options as $option_key => $option_value) {
53 $template->extension()->set($option_key, $option_value);
54 }
55
56 if ($template->extension()->verify()) {
57
58 if (array_key_exists('inline', $atts)) {
59 $inline = $atts['inline'] == 'true' ? 1 : 0;
60 $uid_params['inline'] = $inline;
61 }
62
63 if (array_key_exists('flatten', $atts)) {
64 $flatten = (int) $atts['flatten'];
65 $uid_params['flatten'] = $flatten;
66 $template->set('flatten', $flatten);
67 }
68
69 if (array_key_exists('format', $atts)) {
70 $format = $atts['format'];
71 $uid_params['format'] = $format;
72 $template->set('format', $format);
73 }
74
75 if (array_key_exists('password', $atts)) {
76 if (!array_key_exists('filter', $atts)) {
77 $password = $template->extension()->render($atts['password'], 'value');
78 } else {
79 $password = $atts['password'];
80 }
81 $uid_params['password'] = $password;
82 $template->set('password', $password);
83 } else {
84 $template->set('password', $template->extension()->render($template->get('password'), 'value'));
85 }
86
87 if (array_key_exists('name', $atts)) {
88 if (!array_key_exists('filter', $atts)) {
89 $name = $template->extension()->render($atts['name'], 'value');
90 } else {
91 $name = $atts['name'];
92 }
93 $uid_params['name'] = $name;
94 $template->set('name', $name);
95 } else {
96 $template->set('name', $template->extension()->render($template->get('name'), 'value'));
97 }
98
99 $entry = new Model_E2pdf_Entry();
100 $entry->set('entry', $uid_params);
101 if (!$entry->load_by_uid($entry->get('uid'))) {
102 $entry->save();
103 }
104
105 $template->fill($dataset, $entry->get('uid'));
106 $request = $template->render();
107
108 if (!isset($request['error']) && $entry->get('ID')) {
109 $tmp_dir = $this->helper->get('tmp_dir') . 'e2pdf' . md5($entry->get('uid')) . '/';
110
111 $this->helper->create_dir($tmp_dir);
112
113 if ($template->get('name')) {
114 $name = $template->get('name');
115 } else {
116 $name = $template->extension()->render($template->get_filename(), 'value');
117 }
118
119 $file_name = $name . '.pdf';
120 $file_path = $tmp_dir . $file_name;
121 file_put_contents($file_path, base64_decode($request['file']));
122
123 if (file_exists($file_path)) {
124 $entry->set('pdf_num', $entry->get('pdf_num') + 1);
125 $entry->save();
126
127 return $file_path;
128 }
129 }
130 }
131 }
132
133 return $response;
134 }
135
136 /**
137 * [e2pdf-download] shortcode
138 *
139 * @param array $atts - Shortcode attributes
140 */
141 function e2pdf_download($atts = array()) {
142
143 $template_id = isset($atts['id']) ? (int) $atts['id'] : 0;
144 $dataset = isset($atts['dataset']) ? $atts['dataset'] : false;
145 $uid = isset($atts['uid']) ? $atts['uid'] : false;
146 $output = isset($atts['output']) ? $atts['output'] : false;
147 $uid_params = array();
148 $response = '';
149
150 if ($uid) {
151 $entry = new Model_E2pdf_Entry();
152 if ($entry->load_by_uid($uid)) {
153 $uid_params = $entry->get('entry');
154 $template_id = isset($uid_params['template_id']) ? (int) $uid_params['template_id'] : 0;
155 $dataset = isset($uid_params['dataset']) ? $uid_params['dataset'] : false;
156 } else {
157 return $response;
158 }
159 }
160
161 if (!$template_id || !$dataset) {
162 return $response;
163 }
164
165 $template = new Model_E2pdf_Template();
166 if ($template->load($template_id)) {
167
168 $uid_params['template_id'] = $template_id;
169 $uid_params['dataset'] = $dataset;
170
171 if (array_key_exists('class', $atts)) {
172 $classes = explode(" ", $atts['class']);
173 } else {
174 $classes = array();
175 }
176 $classes[] = 'e2pdf-download';
177
178 $template->extension()->set('dataset', $dataset);
179
180 $options = array();
181 $options = apply_filters('e2pdf_model_shortcode_extension_options', $options, $template);
182 $options = apply_filters('e2pdf_model_shortcode_e2pdf_download_extension_options', $options, $template);
183
184 foreach ($options as $option_key => $option_value) {
185 $template->extension()->set($option_key, $option_value);
186 }
187
188 if ($uid) {
189
190 $pdf = isset($uid_params['pdf']) && $uid_params['pdf'] && file_exists($uid_params['pdf']) ? $uid_params['pdf'] : false;
191 if (!$pdf) {
192 return $response;
193 }
194
195 $auto = isset($uid_params['auto']) ? $uid_params['auto'] : $template->get('auto');
196 if ($auto) {
197 $classes[] = 'e2pdf-auto';
198 }
199
200 $inline = isset($uid_params['inline']) ? $uid_params['inline'] : $template->get('inline');
201 if ($inline) {
202 $classes[] = 'e2pdf-inline';
203 }
204
205 $title = isset($uid_params['title']) ? $uid_params['title'] : __('Download', 'e2pdf');
206
207 $url = esc_url(add_query_arg(array(
208 'page' => 'e2pdf-download',
209 'uid' => $entry->get('uid'),
210 ), site_url('/')
211 ));
212
213 if ($output && $output == 'url') {
214 $response = $url;
215 } else {
216 $response = "<a id='e2pdf-download' class='" . implode(" ", $classes) . "' target='_blank' href='{$url}'>{$title}</a>";
217 }
218 } elseif ($template->extension()->verify()) {
219
220 $template->extension()->set('no_filter', true);
221
222 if (array_key_exists('auto', $atts)) {
223 $auto = $atts['auto'] == 'true' ? 1 : 0;
224 } else {
225 $auto = $template->get('auto');
226 }
227
228 if ($auto) {
229 $classes[] = 'e2pdf-auto';
230 }
231
232 if (array_key_exists('inline', $atts)) {
233 $inline = $atts['inline'] == 'true' ? 1 : 0;
234 $uid_params['inline'] = $inline;
235 } else {
236 $inline = $template->get('inline');
237 }
238
239 if ($inline) {
240 $classes[] = 'e2pdf-inline';
241 }
242
243 if (array_key_exists('flatten', $atts)) {
244 $flatten = (int) $atts['flatten'];
245 $uid_params['flatten'] = $flatten;
246 }
247
248 if (array_key_exists('format', $atts)) {
249 $format = $atts['format'];
250 $uid_params['format'] = $format;
251 }
252
253 if (array_key_exists('button-title', $atts)) {
254 if (!array_key_exists('filter', $atts)) {
255 $title = $template->extension()->render($atts['button-title']);
256 } else {
257 $title = $atts['button-title'];
258 }
259 } elseif ($template->extension()->render($template->get('button_title')) !== '') {
260 $title = $template->extension()->render($template->get('button_title'));
261 } else {
262 $title = __('Download', 'e2pdf');
263 }
264
265 if (array_key_exists('password', $atts)) {
266 if (!array_key_exists('filter', $atts)) {
267 $password = $template->extension()->render($atts['password'], 'value');
268 } else {
269 $password = $atts['password'];
270 }
271 $uid_params['password'] = $password;
272 }
273
274 if (array_key_exists('name', $atts)) {
275 if (!array_key_exists('filter', $atts)) {
276 $name = $template->extension()->render($atts['name'], 'value');
277 } else {
278 $name = $atts['name'];
279 }
280 $uid_params['name'] = $name;
281 }
282
283 $entry = new Model_E2pdf_Entry();
284 $entry->set('entry', $uid_params);
285 if (!$entry->load_by_uid($entry->get('uid'))) {
286 $entry->save();
287 }
288
289 if ($entry->get('ID')) {
290 $url = esc_url(add_query_arg(array(
291 'page' => 'e2pdf-download',
292 'uid' => $entry->get('uid'),
293 ), site_url('/')
294 ));
295
296 if ($output && $output == 'url') {
297 $response = $url;
298 } else {
299 $response = "<a id='e2pdf-download' class='" . implode(" ", $classes) . "' target='_blank' href='{$url}'>{$title}</a>";
300 }
301 }
302 }
303 }
304
305 return $response;
306 }
307
308 /**
309 * @since 0.01.44
310 *
311 * [e2pdf-save] shortcode
312 *
313 * @param array $atts - Shortcode attributes
314 */
315 function e2pdf_save($atts = array()) {
316
317 $template_id = isset($atts['id']) ? (int) $atts['id'] : 0;
318 $download = isset($atts['download']) && $atts['download'] == 'true' ? true : false;
319 $view = isset($atts['view']) && $atts['view'] == 'true' ? true : false;
320 $output = isset($atts['output']) ? $atts['output'] : false;
321
322 $response = '';
323
324 if (!array_key_exists('apply', $atts) || !array_key_exists('dataset', $atts) || !$template_id) {
325 return $response;
326 }
327
328 $dataset = $atts['dataset'];
329
330 $template = new Model_E2pdf_Template();
331
332 if ($template->load($template_id)) {
333
334 $uid_params = array();
335 $uid_params['template_id'] = $template_id;
336 $uid_params['dataset'] = $dataset;
337
338 $template->extension()->set('dataset', $dataset);
339
340 $options = array();
341 $options = apply_filters('e2pdf_model_shortcode_extension_options', $options, $template);
342 $options = apply_filters('e2pdf_model_shortcode_e2pdf_save_extension_options', $options, $template);
343
344 foreach ($options as $option_key => $option_value) {
345 $template->extension()->set($option_key, $option_value);
346 }
347
348 if ($template->extension()->verify()) {
349
350 if (array_key_exists('inline', $atts)) {
351 $inline = $atts['inline'] == 'true' ? 1 : 0;
352 $uid_params['inline'] = $inline;
353 }
354
355 if (array_key_exists('flatten', $atts)) {
356 $flatten = (int) $atts['flatten'];
357 $uid_params['flatten'] = $flatten;
358 $template->set('flatten', $flatten);
359 }
360
361 if (array_key_exists('format', $atts)) {
362 $format = $atts['format'];
363 $uid_params['format'] = $format;
364 $template->set('format', $format);
365 }
366
367 if (array_key_exists('password', $atts)) {
368 if (!array_key_exists('filter', $atts)) {
369 $password = $template->extension()->render($atts['password'], 'value');
370 } else {
371 $password = $atts['password'];
372 }
373 $uid_params['password'] = $password;
374 $template->set('password', $password);
375 } else {
376 $template->set('password', $template->extension()->render($template->get('password'), 'value'));
377 }
378
379 if (array_key_exists('name', $atts)) {
380 if (!array_key_exists('filter', $atts)) {
381 $name = $template->extension()->render($atts['name'], 'value');
382 } else {
383 $name = $atts['name'];
384 }
385 $uid_params['name'] = $name;
386 $template->set('name', $name);
387 } else {
388 $template->set('name', $template->extension()->render($template->get('name'), 'value'));
389 }
390
391 if ($download || $view) {
392 if (array_key_exists('button-title', $atts)) {
393 if (!array_key_exists('filter', $atts)) {
394 $title = $template->extension()->render($atts['button-title']);
395 } else {
396 $title = $atts['button-title'];
397 }
398 } elseif ($template->extension()->render($template->get('button_title')) !== '') {
399 $title = $template->extension()->render($template->get('button_title'));
400 } else {
401 $title = __('Download', 'e2pdf');
402 }
403 $uid_params['title'] = $title;
404 $uid_params['pdf'] = false;
405 }
406
407 $entry = new Model_E2pdf_Entry();
408 $entry->set('entry', $uid_params);
409 if (!$entry->load_by_uid($entry->get('uid'))) {
410 $entry->save();
411 }
412
413 $template->fill($dataset, $entry->get('uid'));
414 $request = $template->render();
415
416 if (isset($request['error'])) {
417 return false;
418 } else {
419 if ($entry->get('ID')) {
420
421 if (array_key_exists('dir', $atts)) {
422 $save_dir = $atts['dir'];
423 } else {
424 $tpl_dir = $this->helper->get('tpl_dir') . $template->get('ID') . "/";
425 $save_dir = $tpl_dir . "save/";
426 $this->helper->create_dir($tpl_dir);
427 $this->helper->create_dir($save_dir);
428 }
429
430 if (is_dir($save_dir) && is_writable($save_dir)) {
431
432 if ($template->get('name')) {
433 $name = $template->get('name');
434 } else {
435 $name = $template->extension()->render($template->get_filename(), 'value');
436 }
437
438 $file_name = $name . '.pdf';
439 $file_path = $save_dir . $file_name;
440 file_put_contents($file_path, base64_decode($request['file']));
441
442 if (file_exists($file_path)) {
443 $entry->set('pdf_num', $entry->get('pdf_num') + 1);
444 if ($download || $view) {
445 $uid_params['pdf'] = $file_path;
446 $entry->set('entry', $uid_params);
447 $atts['uid'] = $entry->get('uid');
448 }
449 $entry->save();
450 if ($download) {
451 return $this->e2pdf_download($atts);
452 } elseif ($view) {
453 return $this->e2pdf_view($atts);
454 } elseif ($output && $output == 'path') {
455 $response = $file_path;
456 }
457 }
458 }
459 }
460 }
461 }
462 }
463
464 return $response;
465 }
466
467 /**
468 * [e2pdf-view] shortcode
469 *
470 * @param array $atts - Shortcode attributes
471 */
472 function e2pdf_view($atts = array()) {
473
474 $template_id = isset($atts['id']) ? (int) $atts['id'] : 0;
475 $dataset = isset($atts['dataset']) ? $atts['dataset'] : false;
476 $uid = isset($atts['uid']) ? $atts['uid'] : false;
477 $width = isset($atts['width']) ? $atts['width'] : '100%';
478 $height = isset($atts['height']) ? $atts['height'] : '500';
479 $pdf = isset($atts['pdf']) ? $atts['pdf'] : false;
480
481 $response = '';
482
483 if (array_key_exists('class', $atts)) {
484 $classes = explode(" ", $atts['class']);
485 } else {
486 $classes = array();
487 }
488 $classes[] = 'e2pdf-view';
489
490 if ($uid) {
491 $entry = new Model_E2pdf_Entry();
492 if ($entry->load_by_uid($uid)) {
493 $uid_params = $entry->get('entry');
494
495 $template_id = isset($uid_params['template_id']) ? (int) $uid_params['template_id'] : 0;
496 $dataset = isset($uid_params['dataset']) ? $uid_params['dataset'] : false;
497
498 $name = basename($uid_params['pdf']);
499
500 $template = new Model_E2pdf_Template();
501 if ($uid_params['pdf'] && file_exists($uid_params['pdf']) && isset($uid_params['template_id']) && isset($uid_params['dataset']) && $template->load($uid_params['template_id'])) {
502 $pdf = esc_url_raw(add_query_arg(array(
503 'page' => 'e2pdf-download',
504 'uid' => $entry->get('uid'),
505 'saveName' => $name
506 ), site_url('/')
507 ));
508 }
509 }
510 }
511
512 if ($pdf) {
513 if (filter_var($pdf, FILTER_VALIDATE_URL)) {
514 $url = plugins_url('assets/pdf.js/web/viewer.html?file=' . urlencode($pdf), $this->helper->get('plugin_file_path'));
515 $response = "<iframe class='" . implode(" ", $classes) . "' width='{$width}' height='{$height}' src='{$url}'></iframe>";
516 }
517 } else {
518
519 if (!$template_id || !$dataset) {
520 return $response;
521 }
522
523 $template = new Model_E2pdf_Template();
524 if ($template->load($template_id)) {
525
526 $uid_params = array();
527 $uid_params['template_id'] = $template_id;
528 $uid_params['dataset'] = $dataset;
529
530 $template->extension()->set('dataset', $dataset);
531
532 $options = array();
533 $options = apply_filters('e2pdf_model_shortcode_extension_options', $options, $template);
534 $options = apply_filters('e2pdf_model_shortcode_e2pdf_view_extension_options', $options, $template);
535
536 foreach ($options as $option_key => $option_value) {
537 $template->extension()->set($option_key, $option_value);
538 }
539
540 if ($template->extension()->verify()) {
541
542 $template->extension()->set('no_filter', true);
543
544 if (array_key_exists('inline', $atts)) {
545 $inline = $atts['inline'] == 'true' ? 1 : 0;
546 $uid_params['inline'] = $inline;
547 }
548
549 if (array_key_exists('flatten', $atts)) {
550 $flatten = (int) $atts['flatten'];
551 $uid_params['flatten'] = $flatten;
552 }
553
554 if (array_key_exists('format', $atts)) {
555 $format = $atts['format'];
556 $uid_params['format'] = $format;
557 }
558
559 if (array_key_exists('password', $atts)) {
560 if (!array_key_exists('filter', $atts)) {
561 $password = $template->extension()->render($atts['password']);
562 } else {
563 $password = $atts['password'];
564 }
565 $uid_params['password'] = $password;
566 }
567
568 if (array_key_exists('name', $atts)) {
569 if (!array_key_exists('filter', $atts)) {
570 $name = $template->extension()->render($atts['name'], 'value');
571 } else {
572 $name = $atts['name'];
573 }
574 $uid_params['name'] = $name;
575 $template->set('name', $name);
576 } else {
577 $template->set('name', $template->extension()->render($template->get('name'), 'value'));
578 }
579
580 $entry = new Model_E2pdf_Entry();
581 $entry->set('entry', $uid_params);
582 if (!$entry->load_by_uid($entry->get('uid'))) {
583 $entry->save();
584 }
585
586 if ($entry->get('ID')) {
587
588 $pdf_url = esc_url_raw(add_query_arg(array(
589 'page' => 'e2pdf-download',
590 'uid' => $entry->get('uid'),
591 'saveName' => $template->get('name') ? $template->get('name') . ".pdf" : $template->extension()->render($template->get_filename(), 'value') . ".pdf"
592 ), site_url('/')
593 ));
594
595 $url = plugins_url('assets/pdf.js/web/viewer.html?file=' . urlencode($pdf_url), $this->helper->get('plugin_file_path'));
596 $response = "<iframe class='" . implode(" ", $classes) . "' width='{$width}' height='{$height}' src='{$url}'></iframe>";
597 }
598 }
599 }
600 }
601
602 return $response;
603 }
604
605 function e2pdf_adobesign($atts = array()) {
606
607 $template_id = isset($atts['id']) ? (int) $atts['id'] : 0;
608
609 $response = '';
610
611 if (!array_key_exists('apply', $atts) || !array_key_exists('dataset', $atts) || !$template_id) {
612 return $response;
613 }
614
615 $dataset = $atts['dataset'];
616 $template = new Model_E2pdf_Template();
617 if ($template->load($template_id)) {
618 $uid_params = array();
619 $uid_params['template_id'] = $template_id;
620 $uid_params['dataset'] = $dataset;
621
622 $template->extension()->set('dataset', $dataset);
623
624 $options = array();
625 $options = apply_filters('e2pdf_model_shortcode_extension_options', $options, $template);
626 $options = apply_filters('e2pdf_model_shortcode_e2pdf_adobesign_extension_options', $options, $template);
627
628 foreach ($options as $option_key => $option_value) {
629 $template->extension()->set($option_key, $option_value);
630 }
631
632 if ($template->extension()->verify()) {
633
634 if (array_key_exists('inline', $atts)) {
635 $inline = $atts['inline'] == 'true' ? 1 : 0;
636 $uid_params['inline'] = $inline;
637 }
638
639 if (array_key_exists('flatten', $atts)) {
640 $flatten = (int) $atts['flatten'];
641 $uid_params['flatten'] = $flatten;
642 $template->set('flatten', $flatten);
643 }
644
645 if (array_key_exists('format', $atts)) {
646 $format = $atts['format'];
647 $uid_params['format'] = $format;
648 $template->set('format', $format);
649 }
650
651 if (array_key_exists('password', $atts)) {
652 if (!array_key_exists('filter', $atts)) {
653 $password = $template->extension()->render($atts['password'], 'value');
654 } else {
655 $password = $atts['password'];
656 }
657 $uid_params['password'] = $password;
658 $template->set('password', $password);
659 } else {
660 $template->set('password', $template->extension()->render($template->get('password'), 'value'));
661 }
662
663 if (array_key_exists('name', $atts)) {
664 if (!array_key_exists('filter', $atts)) {
665 $name = $template->extension()->render($atts['name'], 'value');
666 } else {
667 $name = $atts['name'];
668 }
669 $uid_params['name'] = $name;
670 $template->set('name', $name);
671 } else {
672 $template->set('name', $template->extension()->render($template->get('name'), 'value'));
673 }
674
675 $disable = array();
676 if (array_key_exists('disable', $atts)) {
677 $disable = explode(',', $atts['disable']);
678 }
679
680 $entry = new Model_E2pdf_Entry();
681 $entry->set('entry', $uid_params);
682 if (!$entry->load_by_uid($entry->get('uid'))) {
683 $entry->save();
684 }
685
686 $template->fill($dataset, $entry->get('uid'));
687 $request = $template->render();
688
689 if (!isset($request['error']) && $entry->get('ID')) {
690 $tmp_dir = $this->helper->get('tmp_dir') . 'e2pdf' . md5($entry->get('uid')) . '/';
691 $this->helper->create_dir($tmp_dir);
692
693 if ($template->get('name')) {
694 $name = $template->get('name');
695 } else {
696 $name = $template->extension()->render($template->get_filename(), 'value');
697 }
698
699 $file_name = $name . '.pdf';
700 $file_path = $tmp_dir . $file_name;
701 file_put_contents($file_path, base64_decode($request['file']));
702
703 if (file_exists($file_path)) {
704
705 $agreement_id = false;
706 $documents = array();
707 if (!in_array('post_transientDocuments', $disable)) {
708 $model_e2pdf_adobesign = new Model_E2pdf_AdobeSign();
709 $model_e2pdf_adobesign->set(array(
710 'action' => 'api/rest/v5/transientDocuments',
711 'headers' => array(
712 'Content-Type: multipart/form-data',
713 ),
714 'data' => array(
715 'File-Name' => $file_name,
716 'Mime-Type' => 'application/pdf',
717 'File' => class_exists('cURLFile') ? new cURLFile($file_path) : '@' . $file_path
718 ),
719 ));
720
721 if ($transientDocumentId = $model_e2pdf_adobesign->request('transientDocumentId')) {
722 $documents[] = array(
723 'transientDocumentId' => $transientDocumentId
724 );
725 }
726 $model_e2pdf_adobesign->flush();
727 }
728
729 $documents = apply_filters('e2pdf_model_shortcode_e2pdf_adobesign_fileInfos', $documents, $atts, $template, $entry, $template->extension(), $file_path);
730
731 if (!in_array('post_agreements', $disable) && !empty($documents)) {
732
733 $output = false;
734 if (array_key_exists('output', $atts)) {
735 $output = $atts['output'];
736 }
737
738 $recipients = array();
739 if (array_key_exists('recipients', $atts)) {
740 $atts['recipients'] = $template->extension()->render($atts['recipients']);
741 $recipients_list = explode(',', $atts['recipients']);
742
743 foreach ($recipients_list as $recipient_info) {
744 $recipients[] = array(
745 'recipientSetMemberInfos' => array(
746 'email' => trim($recipient_info)
747 ),
748 'recipientSetRole' => 'SIGNER'
749 );
750 }
751 }
752
753 $data = array(
754 'documentCreationInfo' => array(
755 'signatureType' => 'ESIGN',
756 'recipientSetInfos' => $recipients,
757 'signatureFlow' => 'SENDER_SIGNATURE_NOT_REQUIRED',
758 'fileInfos' => $documents,
759 'name' => $name
760 )
761 );
762
763 $data = apply_filters('e2pdf_model_shortcode_e2pdf_adobesign_post_agreements_data', $data, $atts, $template, $entry, $template->extension(), $file_path, $documents);
764
765 $model_e2pdf_adobesign = new Model_E2pdf_AdobeSign();
766 $model_e2pdf_adobesign->set(array(
767 'action' => 'api/rest/v5/agreements',
768 'data' => $data,
769 ));
770
771 $agreement_id = $model_e2pdf_adobesign->request('agreementId');
772 $model_e2pdf_adobesign->flush();
773 }
774
775 $response = apply_filters('e2pdf_model_shortcode_e2pdf_adobesign_response', $response, $atts, $template, $entry, $template->extension(), $file_path, $documents, $agreement_id);
776 }
777
778 $this->helper->delete_dir($tmp_dir);
779 return $response;
780 }
781 }
782 }
783
784 return $response;
785 }
786
787 /**
788 * [e2pdf-format-number] shortcode
789 *
790 * @param array $atts - Shortcode attributes
791 * @param string $value - Value
792 */
793 function e2pdf_format_number($atts = array(), $value = '') {
794
795 $dec_point = isset($atts['dec_point']) ? $atts['dec_point'] : '.';
796 $thousands_sep = isset($atts['thousands_sep']) ? $atts['thousands_sep'] : '';
797 $decimal = isset($atts['decimal']) ? $atts['decimal'] : false;
798 $explode = isset($atts['explode']) ? $atts['explode'] : '';
799 $implode = isset($atts['implode']) ? $atts['implode'] : '';
800
801 $new_value = array();
802 $value = array_filter((array) $value, 'strlen');
803 foreach ($value as $v) {
804 if ($explode && strpos($v, $explode)) {
805 $v = explode($explode, $v);
806 }
807 foreach ((array) $v as $n) {
808 $n = str_replace(array(" ", ","), array("", "."), $n);
809 $n = preg_replace('/\.(?=.*\.)/', '', $n);
810 $n = floatval($n);
811
812 if (!$decimal) {
813 $num = explode('.', $n);
814 $decimal = isset($num[1]) ? strlen($num[1]) : 0;
815 }
816
817 $n = number_format($n, $decimal, $dec_point, $thousands_sep);
818 $new_value[] = $n;
819 }
820 unset($v);
821 }
822 $new_value = array_filter((array) $new_value, 'strlen');
823 return implode($implode, $new_value);
824 }
825
826 function e2pdf_format_date($atts = array(), $value = '') {
827 $format = isset($atts['format']) ? $atts['format'] : get_option('date_format');
828 if (!$value) {
829 return '';
830 }
831 $value = date($format, strtotime($value));
832 return $value;
833 }
834
835 /**
836 * [e2pdf-format-output] shortcode
837 *
838 * @param array $atts - Shortcode attributes
839 * @param string $value - Value
840 */
841 function e2pdf_format_output($atts = array(), $value = '') {
842
843 $explode = isset($atts['explode']) ? $atts['explode'] : false;
844 $implode = isset($atts['implode']) ? $atts['implode'] : '';
845 $output = isset($atts['output']) ? $atts['output'] : false;
846 $filter = isset($atts['filter']) ? $atts['filter'] : false;
847 $search = isset($atts['search']) ? explode("|||", $atts['search']) : array();
848 $ireplace = isset($atts['ireplace']) ? explode("|||", $atts['ireplace']) : array();
849 $replace = isset($atts['replace']) ? explode("|||", $atts['replace']) : array();
850
851 $filters = array();
852 if ($filter) {
853 if (strpos($filter, ',')) {
854 $filters = explode(',', $filter);
855 } else {
856 $filters = array_filter((array) $filter, 'strlen');
857 }
858 }
859
860 $new_value = array();
861
862 if (!empty($ireplace)) {
863 $value = str_ireplace($search, $ireplace, $value);
864 } elseif (!empty($replace)) {
865 $value = str_replace($search, $replace, $value);
866 }
867
868 $value = array_filter((array) $value, 'strlen');
869
870 foreach ($value as $v) {
871 if ($explode && strpos($v, $explode)) {
872 $v = explode($explode, $v);
873 }
874 foreach ((array) $v as $n) {
875 if (!empty($filters)) {
876 foreach ((array) $filters as $sub_filter) {
877 switch ($sub_filter) {
878 case 'trim':
879 $n = trim($n);
880 break;
881
882 case 'strip_tags':
883 $n = strip_tags($n);
884 break;
885
886 case 'strtolower':
887 if (function_exists('mb_strtolower')) {
888 $n = mb_strtolower($n);
889 } elseif (function_exists('strtolower')) {
890 $n = strtolower($n);
891 }
892 break;
893
894 case 'ucfirst':
895 if (function_exists('mb_strtoupper') && function_exists('mb_strtolower')) {
896 $fc = mb_strtoupper(mb_substr($n, 0, 1));
897 $n = $fc . mb_substr($n, 1);
898 } else if (function_exists('ucfirst') && function_exists('strtolower')) {
899 $n = ucfirst($n);
900 }
901 break;
902
903 case 'strtoupper':
904 if (function_exists('mb_strtoupper')) {
905 $n = mb_strtoupper($n);
906 } elseif (function_exists('strtoupper')) {
907 $n = strtoupper($n);
908 }
909 break;
910
911 case 'lines':
912 $n = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $n);
913 break;
914
915 default:
916 break;
917 }
918 }
919 }
920 $new_value[] = $n;
921 }
922 unset($v);
923 }
924
925 if ($output) {
926 $o_search = array();
927 $o_replace = array();
928
929 foreach ($new_value as $key => $value) {
930 $o_search[] = "{" . $key . "}";
931 $o_replace[] = $value;
932 }
933 $output = str_replace($o_search, $o_replace, $output);
934 return preg_replace('~(?:{/?)[^/}]+/?}~s', "", $output);
935 } else {
936 return implode($implode, $new_value);
937 }
938 }
939
940 }
941