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