| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* E2pdf Post Helper |
| 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 |
if (!array_key_exists('apply', $atts) || !array_key_exists('dataset', $atts) || !$template_id) { |
| 32 |
return ''; |
| 33 |
} |
| 34 |
|
| 35 |
$dataset = $atts['dataset']; |
| 36 |
|
| 37 |
$template = new Model_E2pdf_Template(); |
| 38 |
|
| 39 |
if ($template->load($template_id)) { |
| 40 |
|
| 41 |
$uid_params = array(); |
| 42 |
$uid_params['template_id'] = $template_id; |
| 43 |
$uid_params['dataset'] = $dataset; |
| 44 |
|
| 45 |
$extension = new Model_E2pdf_Extension(); |
| 46 |
$extension->load($template->get('extension')); |
| 47 |
$extension->set('item', $template->get('item')); |
| 48 |
$extension->set('dataset', $dataset); |
| 49 |
|
| 50 |
|
| 51 |
if ($extension->verify()) { |
| 52 |
|
| 53 |
if (array_key_exists('inline', $atts)) { |
| 54 |
$inline = $atts['inline'] ? 1 : 0; |
| 55 |
$uid_params['inline'] = $inline; |
| 56 |
} |
| 57 |
|
| 58 |
if (array_key_exists('flatten', $atts)) { |
| 59 |
$flatten = (int) $atts['flatten']; |
| 60 |
$uid_params['flatten'] = $flatten; |
| 61 |
} else { |
| 62 |
$flatten = $template->get('flatten'); |
| 63 |
} |
| 64 |
|
| 65 |
if (array_key_exists('format', $atts)) { |
| 66 |
$format = $atts['format']; |
| 67 |
$uid_params['format'] = $format; |
| 68 |
} else { |
| 69 |
$format = $template->get('format'); |
| 70 |
} |
| 71 |
|
| 72 |
if (array_key_exists('password', $atts)) { |
| 73 |
$password = $atts['password']; |
| 74 |
$uid_params['password'] = $password; |
| 75 |
} else { |
| 76 |
$password = $template->get('password'); |
| 77 |
} |
| 78 |
|
| 79 |
if (array_key_exists('name', $atts)) { |
| 80 |
$template->set('name', $atts['name']); |
| 81 |
$uid_params['name'] = $atts['name']; |
| 82 |
} |
| 83 |
|
| 84 |
/* |
| 85 |
* @since 0.01.33 |
| 86 |
*/ |
| 87 |
$entry = new Model_E2pdf_Entry(); |
| 88 |
$entry->set('entry', $uid_params); |
| 89 |
if (!$entry->load_by_uid($entry->get('uid'))) { |
| 90 |
$entry->save(); |
| 91 |
} |
| 92 |
|
| 93 |
$template->set('format', $format); |
| 94 |
$template->set('flatten', $flatten); |
| 95 |
$template->set('password', $extension->render($password)); |
| 96 |
$template->fill($dataset, $entry->get('uid')); |
| 97 |
$request = $template->render(); |
| 98 |
|
| 99 |
if (isset($request['error'])) { |
| 100 |
return false; |
| 101 |
} else { |
| 102 |
|
| 103 |
if ($entry->get('ID')) { |
| 104 |
$tmp_dir = $this->helper->get('tmp_dir') . 'e2pdf' . md5($entry->get('uid')) . '/'; |
| 105 |
|
| 106 |
$this->helper->create_dir($tmp_dir); |
| 107 |
|
| 108 |
$name = $extension->render($template->get_filename()); |
| 109 |
|
| 110 |
$file_name = $name . '.pdf'; |
| 111 |
$file_path = $tmp_dir . $file_name; |
| 112 |
file_put_contents($file_path, base64_decode($request['file'])); |
| 113 |
|
| 114 |
if (file_exists($file_path)) { |
| 115 |
|
| 116 |
/* |
| 117 |
* Pdf count increase |
| 118 |
* @since 0.01.33 |
| 119 |
*/ |
| 120 |
$entry->set('pdf_num', $entry->get('pdf_num') + 1); |
| 121 |
$entry->save(); |
| 122 |
|
| 123 |
return $file_path; |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
} else { |
| 129 |
return false; |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
/** |
| 134 |
* [e2pdf-download] shortcode |
| 135 |
* |
| 136 |
* @param array $atts - Shortcode attributes |
| 137 |
*/ |
| 138 |
function e2pdf_download($atts = array()) { |
| 139 |
|
| 140 |
$template_id = (int) $atts['id']; |
| 141 |
|
| 142 |
$response = ''; |
| 143 |
|
| 144 |
if (!$template_id) { |
| 145 |
return $response; |
| 146 |
} |
| 147 |
|
| 148 |
if (array_key_exists('dataset', $atts)) { |
| 149 |
$dataset = $atts['dataset']; |
| 150 |
} else { |
| 151 |
return $response; |
| 152 |
} |
| 153 |
|
| 154 |
$template = new Model_E2pdf_Template(); |
| 155 |
|
| 156 |
if ($template->load($template_id)) { |
| 157 |
|
| 158 |
$uid_params = array(); |
| 159 |
$uid_params['template_id'] = $template_id; |
| 160 |
$uid_params['dataset'] = $dataset; |
| 161 |
|
| 162 |
if (array_key_exists('class', $atts)) { |
| 163 |
$classes = explode(" ", $atts['class']); |
| 164 |
} else { |
| 165 |
$classes = array(); |
| 166 |
} |
| 167 |
|
| 168 |
$classes[] = 'e2pdf-download'; |
| 169 |
|
| 170 |
$extension = new Model_E2pdf_Extension(); |
| 171 |
$extension->load($template->get('extension')); |
| 172 |
$extension->set('item', $template->get('item')); |
| 173 |
$extension->set('dataset', $dataset); |
| 174 |
|
| 175 |
if ($extension->verify()) { |
| 176 |
$extension->set('no_filter', true); |
| 177 |
|
| 178 |
if (array_key_exists('auto', $atts)) { |
| 179 |
$auto = $atts['auto'] ? 1 : 0; |
| 180 |
} else { |
| 181 |
$auto = $template->get('auto'); |
| 182 |
} |
| 183 |
|
| 184 |
if (array_key_exists('button-title', $atts)) { |
| 185 |
$title = $extension->render($atts['button-title']); |
| 186 |
} elseif ($extension->render($template->get('button_title')) !== '') { |
| 187 |
$title = $extension->render($template->get('button_title')); |
| 188 |
} else { |
| 189 |
$title = __('Download', 'e2pdf'); |
| 190 |
} |
| 191 |
|
| 192 |
if ($auto) { |
| 193 |
$classes[] = 'e2pdf-auto'; |
| 194 |
} |
| 195 |
|
| 196 |
if (array_key_exists('inline', $atts)) { |
| 197 |
$inline = $atts['inline'] ? 1 : 0; |
| 198 |
$uid_params['inline'] = $inline; |
| 199 |
} else { |
| 200 |
$inline = $template->get('inline'); |
| 201 |
} |
| 202 |
|
| 203 |
if ($inline) { |
| 204 |
$classes[] = 'e2pdf-inline'; |
| 205 |
} |
| 206 |
|
| 207 |
if (array_key_exists('flatten', $atts)) { |
| 208 |
$flatten = (int) $atts['flatten']; |
| 209 |
$uid_params['flatten'] = $flatten; |
| 210 |
} else { |
| 211 |
$flatten = $template->get('flatten'); |
| 212 |
} |
| 213 |
|
| 214 |
if (array_key_exists('format', $atts)) { |
| 215 |
$format = $atts['format']; |
| 216 |
$uid_params['format'] = $format; |
| 217 |
} else { |
| 218 |
$format = $template->get('format'); |
| 219 |
} |
| 220 |
|
| 221 |
if (array_key_exists('password', $atts)) { |
| 222 |
$password = $atts['password']; |
| 223 |
} else { |
| 224 |
$password = $template->get('password'); |
| 225 |
} |
| 226 |
|
| 227 |
if (array_key_exists('name', $atts)) { |
| 228 |
$name = $atts['name']; |
| 229 |
$uid_params['name'] = $name; |
| 230 |
} elseif ($template->get('name') != '') { |
| 231 |
$name = $template->get('name'); |
| 232 |
} else { |
| 233 |
$name = $template->get('title'); |
| 234 |
} |
| 235 |
|
| 236 |
/* |
| 237 |
* @since 0.01.33 |
| 238 |
*/ |
| 239 |
$entry = new Model_E2pdf_Entry(); |
| 240 |
$entry->set('entry', $uid_params); |
| 241 |
if (!$entry->load_by_uid($entry->get('uid'))) { |
| 242 |
$entry->save(); |
| 243 |
} |
| 244 |
|
| 245 |
if ($entry->get('ID')) { |
| 246 |
$url = esc_url(add_query_arg(array( |
| 247 |
'page' => 'e2pdf-download', |
| 248 |
'uid' => $entry->get('uid'), |
| 249 |
), site_url('/') |
| 250 |
)); |
| 251 |
|
| 252 |
$response = "<a id='e2pdf-download' class='" . implode(" ", $classes) . "' target='_blank' href='{$url}'>{$title}</a>"; |
| 253 |
} |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
return $response; |
| 258 |
} |
| 259 |
|
| 260 |
/** |
| 261 |
* [e2pdf-format-number] shortcode |
| 262 |
* |
| 263 |
* @param array $atts - Shortcode attributes |
| 264 |
* @param string $value - Value |
| 265 |
*/ |
| 266 |
function e2pdf_format_number($atts = array(), $value = '') { |
| 267 |
|
| 268 |
$dec_point = isset($atts['dec_point']) ? $atts['dec_point'] : '.'; |
| 269 |
$thousands_sep = isset($atts['thousands_sep']) ? $atts['thousands_sep'] : ''; |
| 270 |
$decimal = isset($atts['decimal']) ? $atts['decimal'] : false; |
| 271 |
$explode = isset($atts['explode']) ? $atts['explode'] : ''; |
| 272 |
$implode = isset($atts['implode']) ? $atts['implode'] : ''; |
| 273 |
|
| 274 |
$new_value = array(); |
| 275 |
$value = array_filter((array) $value, 'strlen'); |
| 276 |
foreach ($value as $v) { |
| 277 |
if ($explode && strpos($v, $explode)) { |
| 278 |
$v = explode($explode, $v); |
| 279 |
} |
| 280 |
foreach ((array) $v as $n) { |
| 281 |
$n = str_replace(array(" ", ","), array("", "."), $n); |
| 282 |
$n = preg_replace('/\.(?=.*\.)/', '', $n); |
| 283 |
$n = floatval($n); |
| 284 |
|
| 285 |
if (!$decimal) { |
| 286 |
$num = explode('.', $n); |
| 287 |
$decimal = isset($num[1]) ? strlen($num[1]) : 0; |
| 288 |
} |
| 289 |
|
| 290 |
$n = number_format($n, $decimal, $dec_point, $thousands_sep); |
| 291 |
$new_value[] = $n; |
| 292 |
} |
| 293 |
unset($v); |
| 294 |
} |
| 295 |
$new_value = array_filter((array) $new_value, 'strlen'); |
| 296 |
return implode($implode, $new_value); |
| 297 |
} |
| 298 |
|
| 299 |
function e2pdf_format_date($atts = array(), $value = '') { |
| 300 |
$format = isset($atts['format']) ? $atts['format'] : get_option('date_format'); |
| 301 |
if (!$value) { |
| 302 |
return ''; |
| 303 |
} |
| 304 |
$value = date($format, strtotime($value)); |
| 305 |
return $value; |
| 306 |
} |
| 307 |
|
| 308 |
/** |
| 309 |
* [e2pdf-format-output] shortcode |
| 310 |
* |
| 311 |
* @param array $atts - Shortcode attributes |
| 312 |
* @param string $value - Value |
| 313 |
*/ |
| 314 |
function e2pdf_format_output($atts = array(), $value = '') { |
| 315 |
|
| 316 |
$explode = isset($atts['explode']) ? $atts['explode'] : false; |
| 317 |
$implode = isset($atts['implode']) ? $atts['implode'] : ''; |
| 318 |
$output = isset($atts['output']) ? $atts['output'] : false; |
| 319 |
$filter = isset($atts['filter']) ? $atts['filter'] : false; |
| 320 |
|
| 321 |
$new_value = array(); |
| 322 |
$value = array_filter((array) $value, 'strlen'); |
| 323 |
|
| 324 |
foreach ($value as $v) { |
| 325 |
if ($explode && strpos($v, $explode)) { |
| 326 |
$v = explode($explode, $v); |
| 327 |
} |
| 328 |
foreach ((array) $v as $n) { |
| 329 |
if ($filter) { |
| 330 |
if (strpos($filter, ',')) { |
| 331 |
$filter = explode(',', $filter); |
| 332 |
} else { |
| 333 |
$filter = array_filter((array) $filter, 'strlen'); |
| 334 |
} |
| 335 |
foreach ((array) $filter as $sub_filter) { |
| 336 |
switch ($sub_filter) { |
| 337 |
case 'trim': |
| 338 |
$n = trim($n); |
| 339 |
break; |
| 340 |
|
| 341 |
case 'strip_tags': |
| 342 |
$n = strip_tags($n); |
| 343 |
break; |
| 344 |
|
| 345 |
case 'strtolower': |
| 346 |
if (function_exists('mb_strtolower')) { |
| 347 |
$n = mb_strtolower($n); |
| 348 |
} elseif (function_exists('strtolower')) { |
| 349 |
$n = strtolower($n); |
| 350 |
} |
| 351 |
break; |
| 352 |
|
| 353 |
case 'ucfirst': |
| 354 |
if (function_exists('mb_strtoupper') && function_exists('mb_strtolower')) { |
| 355 |
$fc = mb_strtoupper(mb_substr($n, 0, 1)); |
| 356 |
$n = $fc . mb_substr($n, 1); |
| 357 |
} else if (function_exists('ucfirst') && function_exists('strtolower')) { |
| 358 |
$n = ucfirst($n); |
| 359 |
} |
| 360 |
break; |
| 361 |
|
| 362 |
case 'strtoupper': |
| 363 |
if (function_exists('mb_strtoupper')) { |
| 364 |
$n = mb_strtoupper($n); |
| 365 |
} elseif (function_exists('strtoupper')) { |
| 366 |
$n = strtoupper($n); |
| 367 |
} |
| 368 |
break; |
| 369 |
|
| 370 |
case 'lines': |
| 371 |
$n = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $n); |
| 372 |
break; |
| 373 |
|
| 374 |
default: |
| 375 |
break; |
| 376 |
} |
| 377 |
} |
| 378 |
} |
| 379 |
$new_value[] = $n; |
| 380 |
} |
| 381 |
unset($v); |
| 382 |
} |
| 383 |
|
| 384 |
if ($output) { |
| 385 |
$search = array(); |
| 386 |
$replace = array(); |
| 387 |
|
| 388 |
foreach ($new_value as $key => $value) { |
| 389 |
$search[] = "{" . $key . "}"; |
| 390 |
$replace[] = $value; |
| 391 |
} |
| 392 |
$output = str_replace($search, $replace, $output); |
| 393 |
return preg_replace('~(?:{/?)[^/}]+/?}~s', "", $output); |
| 394 |
} else { |
| 395 |
return implode($implode, $new_value); |
| 396 |
} |
| 397 |
} |
| 398 |
|
| 399 |
/** |
| 400 |
* @since 0.01.44 |
| 401 |
* |
| 402 |
* [e2pdf-save] shortcode |
| 403 |
* |
| 404 |
* @param array $atts - Shortcode attributes |
| 405 |
*/ |
| 406 |
function e2pdf_save($atts = array()) { |
| 407 |
|
| 408 |
$template_id = (int) $atts['id']; |
| 409 |
|
| 410 |
if (!array_key_exists('apply', $atts) || !array_key_exists('dataset', $atts) || !$template_id) { |
| 411 |
return ''; |
| 412 |
} |
| 413 |
|
| 414 |
$dataset = $atts['dataset']; |
| 415 |
|
| 416 |
$template = new Model_E2pdf_Template(); |
| 417 |
|
| 418 |
if ($template->load($template_id)) { |
| 419 |
|
| 420 |
$uid_params = array(); |
| 421 |
$uid_params['template_id'] = $template_id; |
| 422 |
$uid_params['dataset'] = $dataset; |
| 423 |
|
| 424 |
$extension = new Model_E2pdf_Extension(); |
| 425 |
$extension->load($template->get('extension')); |
| 426 |
$extension->set('item', $template->get('item')); |
| 427 |
$extension->set('dataset', $dataset); |
| 428 |
|
| 429 |
if ($extension->verify()) { |
| 430 |
|
| 431 |
if (array_key_exists('inline', $atts)) { |
| 432 |
$inline = $atts['inline'] ? 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 |
} else { |
| 440 |
$flatten = $template->get('flatten'); |
| 441 |
} |
| 442 |
|
| 443 |
if (array_key_exists('format', $atts)) { |
| 444 |
$format = $atts['format']; |
| 445 |
$uid_params['format'] = $format; |
| 446 |
} else { |
| 447 |
$format = $template->get('format'); |
| 448 |
} |
| 449 |
|
| 450 |
if (array_key_exists('password', $atts)) { |
| 451 |
$password = $atts['password']; |
| 452 |
$uid_params['password'] = $password; |
| 453 |
} else { |
| 454 |
$password = $template->get('password'); |
| 455 |
} |
| 456 |
|
| 457 |
if (array_key_exists('name', $atts)) { |
| 458 |
$template->set('name', $atts['name']); |
| 459 |
$uid_params['name'] = $atts['name']; |
| 460 |
} |
| 461 |
|
| 462 |
$entry = new Model_E2pdf_Entry(); |
| 463 |
$entry->set('entry', $uid_params); |
| 464 |
if (!$entry->load_by_uid($entry->get('uid'))) { |
| 465 |
$entry->save(); |
| 466 |
} |
| 467 |
|
| 468 |
$template->set('format', $format); |
| 469 |
$template->set('flatten', $flatten); |
| 470 |
$template->set('password', $extension->render($password)); |
| 471 |
$template->fill($dataset, $entry->get('uid')); |
| 472 |
$request = $template->render(); |
| 473 |
|
| 474 |
if (isset($request['error'])) { |
| 475 |
return false; |
| 476 |
} else { |
| 477 |
if ($entry->get('ID')) { |
| 478 |
|
| 479 |
if (array_key_exists('dir', $atts)) { |
| 480 |
$save_dir = $atts['dir']; |
| 481 |
} else { |
| 482 |
$tpl_dir = $this->helper->get('tpl_dir') . $template->get('ID') . "/"; |
| 483 |
$save_dir = $tpl_dir . "save/"; |
| 484 |
$this->helper->create_dir($tpl_dir); |
| 485 |
$this->helper->create_dir($save_dir); |
| 486 |
} |
| 487 |
|
| 488 |
if (is_dir($save_dir) && is_writable($save_dir)) { |
| 489 |
|
| 490 |
$name = $extension->render($template->get_filename()); |
| 491 |
|
| 492 |
$file_name = $name . '.pdf'; |
| 493 |
$file_path = $save_dir . $file_name; |
| 494 |
file_put_contents($file_path, base64_decode($request['file'])); |
| 495 |
|
| 496 |
if (file_exists($file_path)) { |
| 497 |
$entry->set('pdf_num', $entry->get('pdf_num') + 1); |
| 498 |
$entry->save(); |
| 499 |
} |
| 500 |
} |
| 501 |
} |
| 502 |
} |
| 503 |
} |
| 504 |
} |
| 505 |
|
| 506 |
return ''; |
| 507 |
} |
| 508 |
|
| 509 |
/** |
| 510 |
* [e2pdf-view] shortcode |
| 511 |
* |
| 512 |
* @param array $atts - Shortcode attributes |
| 513 |
*/ |
| 514 |
function e2pdf_view($atts = array()) { |
| 515 |
|
| 516 |
$template_id = (int) $atts['id']; |
| 517 |
|
| 518 |
$response = ''; |
| 519 |
|
| 520 |
$width = isset($atts['width']) ? $atts['width'] : '100%'; |
| 521 |
$height = isset($atts['height']) ? $atts['height'] : '500'; |
| 522 |
$pdf_url = isset($atts['pdf']) ? $atts['pdf'] : false; |
| 523 |
|
| 524 |
if (array_key_exists('class', $atts)) { |
| 525 |
$classes = explode(" ", $atts['class']); |
| 526 |
} else { |
| 527 |
$classes = array(); |
| 528 |
} |
| 529 |
$classes[] = 'e2pdf-view'; |
| 530 |
|
| 531 |
if ($pdf_url) { |
| 532 |
if (filter_var($pdf_url, FILTER_VALIDATE_URL)) { |
| 533 |
$url = plugins_url('assets/pdf.js/web/viewer.html?file=' . urlencode($pdf_url), $this->helper->get('plugin_file_path')); |
| 534 |
$response = "<iframe class='" . implode(" ", $classes) . "' width='{$width}' height='{$height}' src='{$url}'></iframe>"; |
| 535 |
} |
| 536 |
} else { |
| 537 |
|
| 538 |
if (!$template_id) { |
| 539 |
return $response; |
| 540 |
} |
| 541 |
|
| 542 |
if (array_key_exists('dataset', $atts)) { |
| 543 |
$dataset = $atts['dataset']; |
| 544 |
} else { |
| 545 |
return $response; |
| 546 |
} |
| 547 |
|
| 548 |
$template = new Model_E2pdf_Template(); |
| 549 |
|
| 550 |
if ($template->load($template_id)) { |
| 551 |
|
| 552 |
$uid_params = array(); |
| 553 |
$uid_params['template_id'] = $template_id; |
| 554 |
$uid_params['dataset'] = $dataset; |
| 555 |
|
| 556 |
$extension = new Model_E2pdf_Extension(); |
| 557 |
$extension->load($template->get('extension')); |
| 558 |
$extension->set('item', $template->get('item')); |
| 559 |
$extension->set('dataset', $dataset); |
| 560 |
|
| 561 |
if ($extension->verify()) { |
| 562 |
$extension->set('no_filter', true); |
| 563 |
|
| 564 |
if (array_key_exists('auto', $atts)) { |
| 565 |
$auto = $atts['auto'] ? 1 : 0; |
| 566 |
} else { |
| 567 |
$auto = $template->get('auto'); |
| 568 |
} |
| 569 |
|
| 570 |
if (array_key_exists('button-title', $atts)) { |
| 571 |
$title = $extension->render($atts['button-title']); |
| 572 |
} elseif ($extension->render($template->get('button_title')) !== '') { |
| 573 |
$title = $extension->render($template->get('button_title')); |
| 574 |
} else { |
| 575 |
$title = __('Download', 'e2pdf'); |
| 576 |
} |
| 577 |
|
| 578 |
if (array_key_exists('inline', $atts)) { |
| 579 |
$inline = $atts['inline'] ? 1 : 0; |
| 580 |
$uid_params['inline'] = $inline; |
| 581 |
} else { |
| 582 |
$inline = $template->get('inline'); |
| 583 |
} |
| 584 |
|
| 585 |
|
| 586 |
if (array_key_exists('flatten', $atts)) { |
| 587 |
$flatten = (int) $atts['flatten']; |
| 588 |
$uid_params['flatten'] = $flatten; |
| 589 |
} else { |
| 590 |
$flatten = $template->get('flatten'); |
| 591 |
} |
| 592 |
|
| 593 |
if (array_key_exists('format', $atts)) { |
| 594 |
$format = $atts['format']; |
| 595 |
$uid_params['format'] = $format; |
| 596 |
} else { |
| 597 |
$format = $template->get('format'); |
| 598 |
} |
| 599 |
|
| 600 |
if (array_key_exists('password', $atts)) { |
| 601 |
$password = $atts['password']; |
| 602 |
} else { |
| 603 |
$password = $template->get('password'); |
| 604 |
} |
| 605 |
|
| 606 |
if (array_key_exists('name', $atts)) { |
| 607 |
$name = $atts['name']; |
| 608 |
$uid_params['name'] = $name; |
| 609 |
} elseif ($template->get('name') != '') { |
| 610 |
$name = $template->get('name'); |
| 611 |
} else { |
| 612 |
$name = $template->get('title'); |
| 613 |
} |
| 614 |
|
| 615 |
$entry = new Model_E2pdf_Entry(); |
| 616 |
$entry->set('entry', $uid_params); |
| 617 |
if (!$entry->load_by_uid($entry->get('uid'))) { |
| 618 |
$entry->save(); |
| 619 |
} |
| 620 |
|
| 621 |
if ($entry->get('ID')) { |
| 622 |
$pdf_url = esc_url_raw(add_query_arg(array( |
| 623 |
'page' => 'e2pdf-download', |
| 624 |
'uid' => $entry->get('uid'), |
| 625 |
), site_url('/') |
| 626 |
)); |
| 627 |
|
| 628 |
$url = plugins_url('assets/pdf.js/web/viewer.html?file=' . urlencode($pdf_url), $this->helper->get('plugin_file_path')); |
| 629 |
$response = "<iframe class='" . implode(" ", $classes) . "' width='{$width}' height='{$height}' src='{$url}'></iframe>"; |
| 630 |
} |
| 631 |
} |
| 632 |
} |
| 633 |
} |
| 634 |
|
| 635 |
return $response; |
| 636 |
} |
| 637 |
|
| 638 |
} |
| 639 |
|