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