| 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 |
$pdf = isset($atts['pdf']) ? $atts['pdf'] : false; |
| 31 |
$apply = isset($atts['apply']) ? true : false; |
| 32 |
$dataset = isset($atts['dataset']) ? $atts['dataset'] : false; |
| 33 |
|
| 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; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
$response = ''; |
| 42 |
|
| 43 |
if ($pdf) { |
| 44 |
if ($apply && file_exists($pdf)) { |
| 45 |
return $pdf; |
| 46 |
} else { |
| 47 |
return ''; |
| 48 |
} |
| 49 |
} else { |
| 50 |
|
| 51 |
if (!$apply || !$dataset || !$template_id) { |
| 52 |
return $response; |
| 53 |
} |
| 54 |
|
| 55 |
$template = new Model_E2pdf_Template(); |
| 56 |
if ($template->load($template_id)) { |
| 57 |
|
| 58 |
$uid_params = array(); |
| 59 |
$uid_params['template_id'] = $template_id; |
| 60 |
$uid_params['dataset'] = $dataset; |
| 61 |
|
| 62 |
$template->extension()->set('dataset', $dataset); |
| 63 |
|
| 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); |
| 67 |
|
| 68 |
foreach ($options as $option_key => $option_value) { |
| 69 |
$template->extension()->set($option_key, $option_value); |
| 70 |
} |
| 71 |
|
| 72 |
if ($template->extension()->verify()) { |
| 73 |
|
| 74 |
if (array_key_exists('inline', $atts)) { |
| 75 |
$inline = $atts['inline'] == 'true' ? 1 : 0; |
| 76 |
$uid_params['inline'] = $inline; |
| 77 |
} |
| 78 |
|
| 79 |
if (array_key_exists('flatten', $atts)) { |
| 80 |
$flatten = (int) $atts['flatten']; |
| 81 |
$uid_params['flatten'] = $flatten; |
| 82 |
$template->set('flatten', $flatten); |
| 83 |
} |
| 84 |
|
| 85 |
if (array_key_exists('format', $atts)) { |
| 86 |
$format = $atts['format']; |
| 87 |
$uid_params['format'] = $format; |
| 88 |
$template->set('format', $format); |
| 89 |
} |
| 90 |
|
| 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']; |
| 96 |
} |
| 97 |
$uid_params['password'] = $password; |
| 98 |
$template->set('password', $password); |
| 99 |
} else { |
| 100 |
$template->set('password', $template->extension()->render($template->get('password'), 'value')); |
| 101 |
} |
| 102 |
|
| 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'); |
| 106 |
} else { |
| 107 |
$meta_title = $atts['meta_title']; |
| 108 |
} |
| 109 |
$uid_params['meta_title'] = $meta_title; |
| 110 |
$template->set('meta_title', $meta_title); |
| 111 |
} else { |
| 112 |
$template->set('meta_title', $template->extension()->render($template->get('meta_title'), 'value')); |
| 113 |
} |
| 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'); |
| 118 |
} else { |
| 119 |
$meta_subject = $atts['meta_subject']; |
| 120 |
} |
| 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 |
} |
| 126 |
|
| 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'); |
| 130 |
} else { |
| 131 |
$meta_author = $atts['meta_author']; |
| 132 |
} |
| 133 |
$uid_params['meta_author'] = $meta_author; |
| 134 |
$template->set('meta_author', $meta_author); |
| 135 |
} else { |
| 136 |
$template->set('meta_author', $template->extension()->render($template->get('meta_author'), 'value')); |
| 137 |
} |
| 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'); |
| 142 |
} else { |
| 143 |
$meta_keywords = $atts['meta_keywords']; |
| 144 |
} |
| 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 |
} |
| 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']; |
| 156 |
} |
| 157 |
$uid_params['name'] = $name; |
| 158 |
$template->set('name', $name); |
| 159 |
} else { |
| 160 |
$template->set('name', $template->extension()->render($template->get('name'), 'value')); |
| 161 |
} |
| 162 |
|
| 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 |
} |
| 168 |
|
| 169 |
$uid_params['args'] = $args; |
| 170 |
|
| 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 |
} |
| 176 |
|
| 177 |
$template->fill($dataset, $entry->get('uid')); |
| 178 |
$request = $template->render(); |
| 179 |
|
| 180 |
if (!isset($request['error']) && $entry->get('ID')) { |
| 181 |
$tmp_dir = $this->helper->get('tmp_dir') . 'e2pdf' . md5($entry->get('uid')) . '/'; |
| 182 |
|
| 183 |
$this->helper->create_dir($tmp_dir); |
| 184 |
|
| 185 |
if ($template->get('name')) { |
| 186 |
$name = $template->get('name'); |
| 187 |
} else { |
| 188 |
$name = $template->extension()->render($template->get_filename(), 'value'); |
| 189 |
} |
| 190 |
|
| 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'])); |
| 195 |
|
| 196 |
if (file_exists($file_path)) { |
| 197 |
$entry->set('pdf_num', $entry->get('pdf_num') + 1); |
| 198 |
$entry->save(); |
| 199 |
|
| 200 |
return $file_path; |
| 201 |
} |
| 202 |
} |
| 203 |
} |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
return $response; |
| 210 |
} |
| 211 |
|
| 212 |
/** |
| 213 |
* [e2pdf-download] shortcode |
| 214 |
* |
| 215 |
* @param array $atts - Shortcode attributes |
| 216 |
*/ |
| 217 |
function e2pdf_download($atts = array()) { |
| 218 |
|
| 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 |
} |
| 229 |
} |
| 230 |
|
| 231 |
$uid_params = array(); |
| 232 |
$response = ''; |
| 233 |
|
| 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 |
} |
| 243 |
} |
| 244 |
|
| 245 |
if (!$template_id || !$dataset) { |
| 246 |
return $response; |
| 247 |
} |
| 248 |
|
| 249 |
$template = new Model_E2pdf_Template(); |
| 250 |
if ($template->load($template_id)) { |
| 251 |
|
| 252 |
$uid_params['template_id'] = $template_id; |
| 253 |
$uid_params['dataset'] = $dataset; |
| 254 |
|
| 255 |
if (array_key_exists('class', $atts)) { |
| 256 |
$classes = explode(" ", $atts['class']); |
| 257 |
} else { |
| 258 |
$classes = array(); |
| 259 |
} |
| 260 |
$classes[] = 'e2pdf-download'; |
| 261 |
|
| 262 |
$template->extension()->set('dataset', $dataset); |
| 263 |
|
| 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); |
| 267 |
|
| 268 |
foreach ($options as $option_key => $option_value) { |
| 269 |
$template->extension()->set($option_key, $option_value); |
| 270 |
} |
| 271 |
|
| 272 |
if ($uid) { |
| 273 |
|
| 274 |
$pdf = isset($uid_params['pdf']) && $uid_params['pdf'] && file_exists($uid_params['pdf']) ? $uid_params['pdf'] : false; |
| 275 |
if (!$pdf) { |
| 276 |
return $response; |
| 277 |
} |
| 278 |
|
| 279 |
$auto = isset($uid_params['auto']) ? $uid_params['auto'] : $template->get('auto'); |
| 280 |
if ($auto) { |
| 281 |
$classes[] = 'e2pdf-auto'; |
| 282 |
} |
| 283 |
|
| 284 |
$inline = isset($uid_params['inline']) ? $uid_params['inline'] : $template->get('inline'); |
| 285 |
if ($inline) { |
| 286 |
$classes[] = 'e2pdf-inline'; |
| 287 |
} |
| 288 |
|
| 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'); |
| 299 |
} |
| 300 |
|
| 301 |
$url = esc_url(add_query_arg(array( |
| 302 |
'page' => 'e2pdf-download', |
| 303 |
'uid' => $entry->get('uid'), |
| 304 |
), site_url('/') |
| 305 |
)); |
| 306 |
|
| 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>"; |
| 311 |
} |
| 312 |
} elseif ($template->extension()->verify()) { |
| 313 |
|
| 314 |
if (array_key_exists('auto', $atts)) { |
| 315 |
$auto = $atts['auto'] == 'true' ? 1 : 0; |
| 316 |
} else { |
| 317 |
$auto = $template->get('auto'); |
| 318 |
} |
| 319 |
|
| 320 |
if ($auto) { |
| 321 |
$classes[] = 'e2pdf-auto'; |
| 322 |
} |
| 323 |
|
| 324 |
if (array_key_exists('inline', $atts)) { |
| 325 |
$inline = $atts['inline'] == 'true' ? 1 : 0; |
| 326 |
$uid_params['inline'] = $inline; |
| 327 |
} else { |
| 328 |
$inline = $template->get('inline'); |
| 329 |
} |
| 330 |
|
| 331 |
if ($inline) { |
| 332 |
$classes[] = 'e2pdf-inline'; |
| 333 |
} |
| 334 |
|
| 335 |
if (array_key_exists('flatten', $atts)) { |
| 336 |
$flatten = (int) $atts['flatten']; |
| 337 |
$uid_params['flatten'] = $flatten; |
| 338 |
} |
| 339 |
|
| 340 |
if (array_key_exists('format', $atts)) { |
| 341 |
$format = $atts['format']; |
| 342 |
$uid_params['format'] = $format; |
| 343 |
} |
| 344 |
|
| 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']; |
| 350 |
} |
| 351 |
} elseif ($template->extension()->render($template->get('button_title')) !== '') { |
| 352 |
$title = $template->extension()->render($template->get('button_title')); |
| 353 |
} else { |
| 354 |
$title = __('Download', 'e2pdf'); |
| 355 |
} |
| 356 |
|
| 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']; |
| 362 |
} |
| 363 |
$uid_params['password'] = $password; |
| 364 |
} |
| 365 |
|
| 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']; |
| 371 |
} |
| 372 |
$uid_params['meta_title'] = $meta_title; |
| 373 |
} |
| 374 |
|
| 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']; |
| 380 |
} |
| 381 |
$uid_params['meta_subject'] = $meta_subject; |
| 382 |
} |
| 383 |
|
| 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']; |
| 389 |
} |
| 390 |
$uid_params['meta_author'] = $meta_author; |
| 391 |
} |
| 392 |
|
| 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 |
} |
| 401 |
|
| 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']; |
| 407 |
} |
| 408 |
$uid_params['name'] = $name; |
| 409 |
} |
| 410 |
|
| 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 |
} |
| 416 |
|
| 417 |
$uid_params['args'] = $args; |
| 418 |
|
| 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 |
} |
| 424 |
|
| 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 |
)); |
| 431 |
|
| 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>"; |
| 436 |
} |
| 437 |
} |
| 438 |
} |
| 439 |
} |
| 440 |
|
| 441 |
return $response; |
| 442 |
} |
| 443 |
|
| 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()) { |
| 452 |
|
| 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; |
| 458 |
|
| 459 |
$response = ''; |
| 460 |
|
| 461 |
if (!array_key_exists('apply', $atts) || !array_key_exists('dataset', $atts) || !$template_id) { |
| 462 |
return $response; |
| 463 |
} |
| 464 |
|
| 465 |
$dataset = $atts['dataset']; |
| 466 |
|
| 467 |
$template = new Model_E2pdf_Template(); |
| 468 |
|
| 469 |
if ($template->load($template_id)) { |
| 470 |
|
| 471 |
$uid_params = array(); |
| 472 |
$uid_params['template_id'] = $template_id; |
| 473 |
$uid_params['dataset'] = $dataset; |
| 474 |
|
| 475 |
$template->extension()->set('dataset', $dataset); |
| 476 |
|
| 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); |
| 480 |
|
| 481 |
foreach ($options as $option_key => $option_value) { |
| 482 |
$template->extension()->set($option_key, $option_value); |
| 483 |
} |
| 484 |
|
| 485 |
if ($template->extension()->verify()) { |
| 486 |
|
| 487 |
if (array_key_exists('inline', $atts)) { |
| 488 |
$inline = $atts['inline'] == 'true' ? 1 : 0; |
| 489 |
$uid_params['inline'] = $inline; |
| 490 |
} |
| 491 |
|
| 492 |
if (array_key_exists('flatten', $atts)) { |
| 493 |
$flatten = (int) $atts['flatten']; |
| 494 |
$uid_params['flatten'] = $flatten; |
| 495 |
$template->set('flatten', $flatten); |
| 496 |
} |
| 497 |
|
| 498 |
if (array_key_exists('format', $atts)) { |
| 499 |
$format = $atts['format']; |
| 500 |
$uid_params['format'] = $format; |
| 501 |
$template->set('format', $format); |
| 502 |
} |
| 503 |
|
| 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']; |
| 509 |
} |
| 510 |
$uid_params['password'] = $password; |
| 511 |
$template->set('password', $password); |
| 512 |
} else { |
| 513 |
$template->set('password', $template->extension()->render($template->get('password'), 'value')); |
| 514 |
} |
| 515 |
|
| 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']; |
| 521 |
} |
| 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 |
} |
| 527 |
|
| 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']; |
| 533 |
} |
| 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 |
} |
| 539 |
|
| 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']; |
| 545 |
} |
| 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 |
} |
| 551 |
|
| 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']; |
| 557 |
} |
| 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 |
} |
| 563 |
|
| 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']; |
| 569 |
} |
| 570 |
$uid_params['name'] = $name; |
| 571 |
$template->set('name', $name); |
| 572 |
} else { |
| 573 |
$template->set('name', $template->extension()->render($template->get('name'), 'value')); |
| 574 |
} |
| 575 |
|
| 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'); |
| 587 |
} |
| 588 |
$uid_params['title'] = $title; |
| 589 |
$uid_params['pdf'] = false; |
| 590 |
} |
| 591 |
|
| 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(); |
| 596 |
} |
| 597 |
|
| 598 |
$uid_params['args'] = $args; |
| 599 |
|
| 600 |
$entry = new Model_E2pdf_Entry(); |
| 601 |
$entry->set('entry', $uid_params); |
| 602 |
if (!$entry->load_by_uid($entry->get('uid'))) { |
| 603 |
$entry->save(); |
| 604 |
} |
| 605 |
|
| 606 |
$template->fill($dataset, $entry->get('uid')); |
| 607 |
$request = $template->render(); |
| 608 |
|
| 609 |
if (isset($request['error'])) { |
| 610 |
return false; |
| 611 |
} 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); |
| 621 |
} |
| 622 |
|
| 623 |
if (is_dir($save_dir) && is_writable($save_dir)) { |
| 624 |
|
| 625 |
if ($template->get('name')) { |
| 626 |
$name = $template->get('name'); |
| 627 |
} else { |
| 628 |
$name = $template->extension()->render($template->get_filename(), 'value'); |
| 629 |
} |
| 630 |
|
| 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'])); |
| 635 |
|
| 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'); |
| 642 |
} |
| 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; |
| 650 |
} |
| 651 |
} |
| 652 |
} |
| 653 |
} |
| 654 |
} |
| 655 |
} |
| 656 |
} |
| 657 |
|
| 658 |
return $response; |
| 659 |
} |
| 660 |
|
| 661 |
/** |
| 662 |
* [e2pdf-view] shortcode |
| 663 |
* |
| 664 |
* @param array $atts - Shortcode attributes |
| 665 |
*/ |
| 666 |
function e2pdf_view($atts = array()) { |
| 667 |
|
| 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; |
| 678 |
|
| 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; |
| 683 |
} |
| 684 |
} |
| 685 |
|
| 686 |
$viewer_options = array(); |
| 687 |
if ($page) { |
| 688 |
$viewer_options[] = 'page=' . $page; |
| 689 |
} |
| 690 |
if ($zoom) { |
| 691 |
$viewer_options[] = 'zoom=' . $zoom; |
| 692 |
} |
| 693 |
if ($nameddest) { |
| 694 |
$viewer_options[] = 'nameddest=' . $nameddest; |
| 695 |
} |
| 696 |
if ($pagemode) { |
| 697 |
$viewer_options[] = 'pagemode=' . $pagemode; |
| 698 |
} |
| 699 |
|
| 700 |
$response = ''; |
| 701 |
|
| 702 |
if (array_key_exists('class', $atts)) { |
| 703 |
$classes = explode(" ", $atts['class']); |
| 704 |
} else { |
| 705 |
$classes = array(); |
| 706 |
} |
| 707 |
$classes[] = 'e2pdf-view'; |
| 708 |
|
| 709 |
if ($uid) { |
| 710 |
$entry = new Model_E2pdf_Entry(); |
| 711 |
if ($entry->load_by_uid($uid)) { |
| 712 |
$uid_params = $entry->get('entry'); |
| 713 |
|
| 714 |
$template_id = isset($uid_params['template_id']) ? (int) $uid_params['template_id'] : 0; |
| 715 |
$dataset = isset($uid_params['dataset']) ? $uid_params['dataset'] : false; |
| 716 |
|
| 717 |
$name = basename($uid_params['pdf']); |
| 718 |
|
| 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 |
)); |
| 727 |
} |
| 728 |
} |
| 729 |
} |
| 730 |
|
| 731 |
if ($pdf) { |
| 732 |
if (filter_var($pdf, FILTER_VALIDATE_URL)) { |
| 733 |
|
| 734 |
$file = urlencode($pdf); |
| 735 |
if (!empty($viewer_options)) { |
| 736 |
$file .= '#' . implode('&', $viewer_options); |
| 737 |
} |
| 738 |
|
| 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>"; |
| 741 |
} |
| 742 |
} else { |
| 743 |
|
| 744 |
if (!$template_id || !$dataset) { |
| 745 |
return $response; |
| 746 |
} |
| 747 |
|
| 748 |
$template = new Model_E2pdf_Template(); |
| 749 |
if ($template->load($template_id)) { |
| 750 |
|
| 751 |
$uid_params = array(); |
| 752 |
$uid_params['template_id'] = $template_id; |
| 753 |
$uid_params['dataset'] = $dataset; |
| 754 |
|
| 755 |
$template->extension()->set('dataset', $dataset); |
| 756 |
|
| 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); |
| 760 |
|
| 761 |
foreach ($options as $option_key => $option_value) { |
| 762 |
$template->extension()->set($option_key, $option_value); |
| 763 |
} |
| 764 |
|
| 765 |
if ($template->extension()->verify()) { |
| 766 |
|
| 767 |
if (array_key_exists('inline', $atts)) { |
| 768 |
$inline = $atts['inline'] == 'true' ? 1 : 0; |
| 769 |
$uid_params['inline'] = $inline; |
| 770 |
} |
| 771 |
|
| 772 |
if (array_key_exists('flatten', $atts)) { |
| 773 |
$flatten = (int) $atts['flatten']; |
| 774 |
$uid_params['flatten'] = $flatten; |
| 775 |
} |
| 776 |
|
| 777 |
if (array_key_exists('format', $atts)) { |
| 778 |
$format = $atts['format']; |
| 779 |
$uid_params['format'] = $format; |
| 780 |
} |
| 781 |
|
| 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; |
| 789 |
} |
| 790 |
|
| 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; |
| 798 |
} |
| 799 |
|
| 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'); |
| 803 |
} else { |
| 804 |
$meta_subject = $atts['meta_subject']; |
| 805 |
} |
| 806 |
$uid_params['meta_subject'] = $meta_subject; |
| 807 |
} |
| 808 |
|
| 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; |
| 816 |
} |
| 817 |
|
| 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'); |
| 821 |
} else { |
| 822 |
$meta_keywords = $atts['meta_keywords']; |
| 823 |
} |
| 824 |
$uid_params['meta_keywords'] = $meta_keywords; |
| 825 |
} |
| 826 |
|
| 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')); |
| 837 |
} |
| 838 |
|
| 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(); |
| 843 |
} |
| 844 |
|
| 845 |
$uid_params['args'] = $args; |
| 846 |
|
| 847 |
$entry = new Model_E2pdf_Entry(); |
| 848 |
$entry->set('entry', $uid_params); |
| 849 |
if (!$entry->load_by_uid($entry->get('uid'))) { |
| 850 |
$entry->save(); |
| 851 |
} |
| 852 |
|
| 853 |
if ($entry->get('ID')) { |
| 854 |
|
| 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 |
)); |
| 861 |
|
| 862 |
$file = urlencode($pdf_url); |
| 863 |
if (!empty($viewer_options)) { |
| 864 |
$file .= '#' . implode('&', $viewer_options); |
| 865 |
} |
| 866 |
|
| 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>"; |
| 869 |
} |
| 870 |
} |
| 871 |
} |
| 872 |
} |
| 873 |
|
| 874 |
return $response; |
| 875 |
} |
| 876 |
|
| 877 |
function e2pdf_adobesign($atts = array()) { |
| 878 |
|
| 879 |
$template_id = isset($atts['id']) ? (int) $atts['id'] : 0; |
| 880 |
|
| 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 |
} |
| 886 |
} |
| 887 |
|
| 888 |
$response = ''; |
| 889 |
|
| 890 |
if (!array_key_exists('apply', $atts) || !array_key_exists('dataset', $atts) || !$template_id) { |
| 891 |
return $response; |
| 892 |
} |
| 893 |
|
| 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; |
| 900 |
|
| 901 |
$template->extension()->set('dataset', $dataset); |
| 902 |
|
| 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); |
| 906 |
|
| 907 |
foreach ($options as $option_key => $option_value) { |
| 908 |
$template->extension()->set($option_key, $option_value); |
| 909 |
} |
| 910 |
|
| 911 |
if ($template->extension()->verify()) { |
| 912 |
|
| 913 |
if (array_key_exists('inline', $atts)) { |
| 914 |
$inline = $atts['inline'] == 'true' ? 1 : 0; |
| 915 |
$uid_params['inline'] = $inline; |
| 916 |
} |
| 917 |
|
| 918 |
if (array_key_exists('flatten', $atts)) { |
| 919 |
$flatten = (int) $atts['flatten']; |
| 920 |
$uid_params['flatten'] = $flatten; |
| 921 |
$template->set('flatten', $flatten); |
| 922 |
} |
| 923 |
|
| 924 |
if (array_key_exists('format', $atts)) { |
| 925 |
$format = $atts['format']; |
| 926 |
$uid_params['format'] = $format; |
| 927 |
$template->set('format', $format); |
| 928 |
} |
| 929 |
|
| 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']; |
| 935 |
} |
| 936 |
$uid_params['password'] = $password; |
| 937 |
$template->set('password', $password); |
| 938 |
} else { |
| 939 |
$template->set('password', $template->extension()->render($template->get('password'), 'value')); |
| 940 |
} |
| 941 |
|
| 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'); |
| 945 |
} else { |
| 946 |
$meta_title = $atts['meta_title']; |
| 947 |
} |
| 948 |
$uid_params['meta_title'] = $meta_title; |
| 949 |
$template->set('meta_title', $meta_title); |
| 950 |
} else { |
| 951 |
$template->set('meta_title', $template->extension()->render($template->get('meta_title'), 'value')); |
| 952 |
} |
| 953 |
|
| 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']; |
| 959 |
} |
| 960 |
$uid_params['meta_subject'] = $meta_subject; |
| 961 |
$template->set('meta_subject', $meta_subject); |
| 962 |
} else { |
| 963 |
$template->set('meta_subject', $template->extension()->render($template->get('meta_subject'), 'value')); |
| 964 |
} |
| 965 |
|
| 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'); |
| 969 |
} else { |
| 970 |
$meta_author = $atts['meta_author']; |
| 971 |
} |
| 972 |
$uid_params['meta_author'] = $meta_author; |
| 973 |
$template->set('meta_author', $meta_author); |
| 974 |
} else { |
| 975 |
$template->set('meta_author', $template->extension()->render($template->get('meta_author'), 'value')); |
| 976 |
} |
| 977 |
|
| 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'); |
| 981 |
} else { |
| 982 |
$meta_keywords = $atts['meta_keywords']; |
| 983 |
} |
| 984 |
$uid_params['meta_keywords'] = $meta_keywords; |
| 985 |
$template->set('meta_keywords', $meta_keywords); |
| 986 |
} else { |
| 987 |
$template->set('meta_keywords', $template->extension()->render($template->get('meta_keywords'), 'value')); |
| 988 |
} |
| 989 |
|
| 990 |
if (array_key_exists('name', $atts)) { |
| 991 |
if (!array_key_exists('filter', $atts)) { |
| 992 |
$name = $template->extension()->render($atts['name'], 'value'); |
| 993 |
} else { |
| 994 |
$name = $atts['name']; |
| 995 |
} |
| 996 |
$uid_params['name'] = $name; |
| 997 |
$template->set('name', $name); |
| 998 |
} else { |
| 999 |
$template->set('name', $template->extension()->render($template->get('name'), 'value')); |
| 1000 |
} |
| 1001 |
|
| 1002 |
$disable = array(); |
| 1003 |
if (array_key_exists('disable', $atts)) { |
| 1004 |
$disable = explode(',', $atts['disable']); |
| 1005 |
} |
| 1006 |
|
| 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 |
} |
| 1012 |
|
| 1013 |
$uid_params['args'] = $args; |
| 1014 |
|
| 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 |
} |
| 1020 |
|
| 1021 |
$template->fill($dataset, $entry->get('uid')); |
| 1022 |
$request = $template->render(); |
| 1023 |
|
| 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); |
| 1027 |
|
| 1028 |
if ($template->get('name')) { |
| 1029 |
$name = $template->get('name'); |
| 1030 |
} else { |
| 1031 |
$name = $template->extension()->render($template->get_filename(), 'value'); |
| 1032 |
} |
| 1033 |
|
| 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'])); |
| 1038 |
|
| 1039 |
if (file_exists($file_path)) { |
| 1040 |
|
| 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 |
)); |
| 1056 |
|
| 1057 |
if ($transientDocumentId = $model_e2pdf_adobesign->request('transientDocumentId')) { |
| 1058 |
$documents[] = array( |
| 1059 |
'transientDocumentId' => $transientDocumentId |
| 1060 |
); |
| 1061 |
} |
| 1062 |
$model_e2pdf_adobesign->flush(); |
| 1063 |
} |
| 1064 |
|
| 1065 |
$documents = apply_filters('e2pdf_model_shortcode_e2pdf_adobesign_fileInfos', $documents, $atts, $template, $entry, $template->extension(), $file_path); |
| 1066 |
|
| 1067 |
if (!in_array('post_agreements', $disable) && !empty($documents)) { |
| 1068 |
|
| 1069 |
$output = false; |
| 1070 |
if (array_key_exists('output', $atts)) { |
| 1071 |
$output = $atts['output']; |
| 1072 |
} |
| 1073 |
|
| 1074 |
$recipients = array(); |
| 1075 |
if (array_key_exists('recipients', $atts)) { |
| 1076 |
$atts['recipients'] = $template->extension()->render($atts['recipients']); |
| 1077 |
$recipients_list = explode(',', $atts['recipients']); |
| 1078 |
|
| 1079 |
foreach ($recipients_list as $recipient_info) { |
| 1080 |
$recipients[] = array( |
| 1081 |
'recipientSetMemberInfos' => array( |
| 1082 |
'email' => trim($recipient_info) |
| 1083 |
), |
| 1084 |
'recipientSetRole' => 'SIGNER' |
| 1085 |
); |
| 1086 |
} |
| 1087 |
} |
| 1088 |
|
| 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 |
); |
| 1098 |
|
| 1099 |
$data = apply_filters('e2pdf_model_shortcode_e2pdf_adobesign_post_agreements_data', $data, $atts, $template, $entry, $template->extension(), $file_path, $documents); |
| 1100 |
|
| 1101 |
$model_e2pdf_adobesign = new Model_E2pdf_AdobeSign(); |
| 1102 |
$model_e2pdf_adobesign->set(array( |
| 1103 |
'action' => 'api/rest/v5/agreements', |
| 1104 |
'data' => $data, |
| 1105 |
)); |
| 1106 |
|
| 1107 |
$agreement_id = $model_e2pdf_adobesign->request('agreementId'); |
| 1108 |
$model_e2pdf_adobesign->flush(); |
| 1109 |
} |
| 1110 |
|
| 1111 |
$response = apply_filters('e2pdf_model_shortcode_e2pdf_adobesign_response', $response, $atts, $template, $entry, $template->extension(), $file_path, $documents, $agreement_id); |
| 1112 |
} |
| 1113 |
|
| 1114 |
$this->helper->delete_dir($tmp_dir); |
| 1115 |
return $response; |
| 1116 |
} |
| 1117 |
} |
| 1118 |
} |
| 1119 |
|
| 1120 |
return $response; |
| 1121 |
} |
| 1122 |
|
| 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 = '') { |
| 1130 |
|
| 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'] : ''; |
| 1136 |
|
| 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); |
| 1147 |
|
| 1148 |
if (!$decimal) { |
| 1149 |
$num = explode('.', $n); |
| 1150 |
$decimal = isset($num[1]) ? strlen($num[1]) : 0; |
| 1151 |
} |
| 1152 |
|
| 1153 |
$n = number_format($n, $decimal, $dec_point, $thousands_sep); |
| 1154 |
$new_value[] = $n; |
| 1155 |
} |
| 1156 |
unset($v); |
| 1157 |
} |
| 1158 |
$new_value = array_filter((array) $new_value, 'strlen'); |
| 1159 |
return implode($implode, $new_value); |
| 1160 |
} |
| 1161 |
|
| 1162 |
function e2pdf_format_date($atts = array(), $value = '') { |
| 1163 |
$format = isset($atts['format']) ? $atts['format'] : get_option('date_format'); |
| 1164 |
if (!$value) { |
| 1165 |
return ''; |
| 1166 |
} |
| 1167 |
$value = date($format, strtotime($value)); |
| 1168 |
return $value; |
| 1169 |
} |
| 1170 |
|
| 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 = '') { |
| 1178 |
|
| 1179 |
$explode = isset($atts['explode']) ? $atts['explode'] : false; |
| 1180 |
$implode = isset($atts['implode']) ? $atts['implode'] : ''; |
| 1181 |
$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(); |
| 1186 |
|
| 1187 |
$filters = array(); |
| 1188 |
if ($filter) { |
| 1189 |
if (strpos($filter, ',')) { |
| 1190 |
$filters = explode(',', $filter); |
| 1191 |
} else { |
| 1192 |
$filters = array_filter((array) $filter, 'strlen'); |
| 1193 |
} |
| 1194 |
} |
| 1195 |
|
| 1196 |
$new_value = array(); |
| 1197 |
|
| 1198 |
if (!empty($ireplace)) { |
| 1199 |
$value = str_ireplace($search, $ireplace, $value); |
| 1200 |
} elseif (!empty($replace)) { |
| 1201 |
$value = str_replace($search, $replace, $value); |
| 1202 |
} |
| 1203 |
|
| 1204 |
$value = array_filter((array) $value, 'strlen'); |
| 1205 |
|
| 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; |
| 1217 |
|
| 1218 |
case 'strip_tags': |
| 1219 |
$n = strip_tags($n); |
| 1220 |
break; |
| 1221 |
|
| 1222 |
case 'strtolower': |
| 1223 |
if (function_exists('mb_strtolower')) { |
| 1224 |
$n = mb_strtolower($n); |
| 1225 |
} elseif (function_exists('strtolower')) { |
| 1226 |
$n = strtolower($n); |
| 1227 |
} |
| 1228 |
break; |
| 1229 |
|
| 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); |
| 1236 |
} |
| 1237 |
break; |
| 1238 |
|
| 1239 |
case 'strtoupper': |
| 1240 |
if (function_exists('mb_strtoupper')) { |
| 1241 |
$n = mb_strtoupper($n); |
| 1242 |
} elseif (function_exists('strtoupper')) { |
| 1243 |
$n = strtoupper($n); |
| 1244 |
} |
| 1245 |
break; |
| 1246 |
|
| 1247 |
case 'lines': |
| 1248 |
$n = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $n); |
| 1249 |
break; |
| 1250 |
|
| 1251 |
default: |
| 1252 |
break; |
| 1253 |
} |
| 1254 |
} |
| 1255 |
} |
| 1256 |
$new_value[] = $n; |
| 1257 |
} |
| 1258 |
unset($v); |
| 1259 |
} |
| 1260 |
|
| 1261 |
if ($output) { |
| 1262 |
$o_search = array(); |
| 1263 |
$o_replace = array(); |
| 1264 |
|
| 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 |
} |
| 1275 |
|
| 1276 |
function e2pdf_user($atts = array()) { |
| 1277 |
|
| 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; |
| 1281 |
|
| 1282 |
$response = ''; |
| 1283 |
|
| 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 |
); |
| 1294 |
|
| 1295 |
$data_fields = apply_filters('e2pdf_model_shortcode_user_data_fields', $data_fields); |
| 1296 |
|
| 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; |
| 1302 |
} |
| 1303 |
} else { |
| 1304 |
$response = get_user_meta($id, $key, true); |
| 1305 |
} |
| 1306 |
} else { |
| 1307 |
$response = $id; |
| 1308 |
} |
| 1309 |
} |
| 1310 |
return $response; |
| 1311 |
} |
| 1312 |
|
| 1313 |
function e2pdf_content($atts = array(), $value = '') { |
| 1314 |
$response = ''; |
| 1315 |
|
| 1316 |
$id = isset($atts['id']) ? $atts['id'] : false; |
| 1317 |
$key = isset($atts['key']) ? $atts['key'] : false; |
| 1318 |
|
| 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; |
| 1329 |
} |
| 1330 |
} |
| 1331 |
} elseif ($value) { |
| 1332 |
$response = apply_filters('the_content', $value); |
| 1333 |
} |
| 1334 |
|
| 1335 |
return $response; |
| 1336 |
} |
| 1337 |
|
| 1338 |
function e2pdf_exclude($atts = array(), $value = '') { |
| 1339 |
|
| 1340 |
$apply = isset($atts['apply']) ? true : false; |
| 1341 |
|
| 1342 |
if ($apply) { |
| 1343 |
$response = ''; |
| 1344 |
} else { |
| 1345 |
$response = apply_filters('the_content', $value); |
| 1346 |
} |
| 1347 |
|
| 1348 |
return $response; |
| 1349 |
} |
| 1350 |
|
| 1351 |
function e2pdf_wp($atts = array(), $value = '') { |
| 1352 |
|
| 1353 |
$response = ''; |
| 1354 |
|
| 1355 |
$id = isset($atts['id']) ? $atts['id'] : false; |
| 1356 |
$key = isset($atts['key']) ? $atts['key'] : false; |
| 1357 |
$meta = isset($atts['meta']) && $atts['meta'] == 'true' ? true : false; |
| 1358 |
|
| 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' |
| 1384 |
); |
| 1385 |
|
| 1386 |
$data_fields = apply_filters('e2pdf_model_shortcode_wp_data_fields', $data_fields); |
| 1387 |
|
| 1388 |
if ($id && $key) { |
| 1389 |
$post = get_post($id); |
| 1390 |
if ($post) { |
| 1391 |
if (in_array($key, $data_fields) && !$meta) { |
| 1392 |
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 |
|
| 1399 |
if (false !== strpos($content, '[')) { |
| 1400 |
$shortcode_tags = array( |
| 1401 |
'e2pdf-exclude', |
| 1402 |
); |
| 1403 |
|
| 1404 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); |
| 1405 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 1406 |
|
| 1407 |
if (!empty($tagnames)) { |
| 1408 |
$pattern = get_shortcode_regex($tagnames); |
| 1409 |
|
| 1410 |
preg_match_all("/$pattern/", $content, $shortcodes); |
| 1411 |
|
| 1412 |
foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 1413 |
|
| 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]; |
| 1421 |
|
| 1422 |
$shortcode[3] .= " apply=\"true\""; |
| 1423 |
$content = str_replace($shortcode_value, "[" . $shortcode['2'] . $shortcode['3'] . "]" . $shortcode['5'] . "[/" . $shortcode['2'] . "]", $content); |
| 1424 |
} |
| 1425 |
} |
| 1426 |
} |
| 1427 |
|
| 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; |
| 1433 |
} |
| 1434 |
} else { |
| 1435 |
$response = get_post_meta($id, $key, true); |
| 1436 |
} |
| 1437 |
} |
| 1438 |
} |
| 1439 |
|
| 1440 |
return $response; |
| 1441 |
} |
| 1442 |
|
| 1443 |
function e2pdf_filter($atts = array(), $value = '') { |
| 1444 |
if ($value) { |
| 1445 |
$search = array( |
| 1446 |
'[', ']', '\'', '"' |
| 1447 |
); |
| 1448 |
|
| 1449 |
$replace = array( |
| 1450 |
'[', ']', ''', '"' |
| 1451 |
); |
| 1452 |
$value = str_replace($search, $replace, $value); |
| 1453 |
} |
| 1454 |
return $value; |
| 1455 |
} |
| 1456 |
|
| 1457 |
} |
| 1458 |
|