| @@ -26,29 +26,20 @@ | ||
| 26 | 26 | } |
| 27 | 27 | } elseif ($this->post->get('_wpnonce')) { |
| 28 | 28 | if (wp_verify_nonce($this->post->get('_wpnonce'), 'e2pdf_templates')) { |
| 29 | 29 | if ($this->post->get('action') == '-1' && $this->post->get('action2') == '-1') { |
| 30 | + $redirect_url = [ | |
| 31 | + 'page' => 'e2pdf-templates', | |
| 32 | + 'status' => $this->get->get('status'), | |
| 33 | + 'orderby' => $this->get->get('orderby'), | |
| 34 | + 'order' => $this->get->get('order'), | |
| 35 | + ]; | |
| 30 | 36 | if ($this->post->get('s')) { |
| 31 | - $location = $this->helper->get_url( | |
| 32 | - array( | |
| 33 | - 'page' => 'e2pdf-templates', | |
| 34 | - 'status' => $this->get->get('status'), | |
| 35 | - 'orderby' => $this->get->get('orderby'), | |
| 36 | - 'order' => $this->get->get('order'), | |
| 37 | - 's' => $this->post->get('s'), | |
| 38 | - ) | |
| 39 | - ); | |
| 40 | - } else { | |
| 41 | - $location = $this->helper->get_url( | |
| 42 | - array( | |
| 43 | - 'page' => 'e2pdf-templates', | |
| 44 | - 'status' => $this->get->get('status'), | |
| 45 | - 'orderby' => $this->get->get('orderby'), | |
| 46 | - 'order' => $this->get->get('order'), | |
| 47 | - ) | |
| 48 | - ); | |
| 37 | + $redirect_url['s'] = $this->post->get('s'); | |
| 49 | 38 | } |
| 50 | - $this->redirect($location); | |
| 39 | + $this->redirect( | |
| 40 | + $this->helper->get_url($redirect_url) | |
| 41 | + ); | |
| 51 | 42 | } else { |
| 52 | 43 | $action = $this->post->get('action') != '-1' ? $this->post->get('action') : $this->post->get('action2'); |
| 53 | 44 | if ($this->post->get('post')) { |
| 54 | 45 | if ($action == 'trash') { |
| @@ -54,31 +45,31 @@ | ||
| 54 | 45 | if ($action == 'trash') { |
| 55 | 46 | foreach ($this->post->get('post') as $key => $value) { |
| 56 | 47 | $this->trash_template($value); |
| 57 | 48 | } |
| 58 | - $this->add_notification('update', sprintf(__('Trashed: %d', 'e2pdf'), count($this->post->get('post')))); | |
| 49 | + $this->add_notification('update', sprintf(__('Templates Trashed: %d', 'e2pdf'), count($this->post->get('post')))); | |
| 59 | 50 | } elseif ($action == 'activate') { |
| 60 | 51 | foreach ($this->post->get('post') as $key => $value) { |
| 61 | 52 | $this->activate_template($value); |
| 62 | 53 | } |
| 63 | - $this->add_notification('update', sprintf(__('Activated: %d', 'e2pdf'), count($this->post->get('post')))); | |
| 54 | + $this->add_notification('update', sprintf(__('Templates Activated: %d', 'e2pdf'), count($this->post->get('post')))); | |
| 64 | 55 | } elseif ($action == 'deactivate') { |
| 65 | 56 | foreach ($this->post->get('post') as $key => $value) { |
| 66 | 57 | $this->deactivate_template($value); |
| 67 | 58 | } |
| 68 | - $this->add_notification('update', sprintf(__('Deactivated: %d', 'e2pdf'), count($this->post->get('post')))); | |
| 59 | + $this->add_notification('update', sprintf(__('Templates Deactivated: %d', 'e2pdf'), count($this->post->get('post')))); | |
| 69 | 60 | } elseif ($action == 'restore') { |
| 70 | 61 | foreach ($this->post->get('post') as $key => $value) { |
| 71 | 62 | $this->restore_template($value); |
| 72 | 63 | } |
| 73 | - $this->add_notification('update', sprintf(__('Restored: %d', 'e2pdf'), count($this->post->get('post')))); | |
| 64 | + $this->add_notification('update', sprintf(__('Templates Restored: %d', 'e2pdf'), count($this->post->get('post')))); | |
| 74 | 65 | } elseif ($action == 'delete') { |
| 75 | 66 | foreach ($this->post->get('post') as $key => $value) { |
| 76 | 67 | $this->delete_template($value); |
| 77 | 68 | } |
| 78 | - $this->add_notification('update', sprintf(__('Deleted: %d', 'e2pdf'), count($this->post->get('post')))); | |
| 69 | + $this->add_notification('update', sprintf(__('Templates Deleted: %d', 'e2pdf'), count($this->post->get('post')))); | |
| 79 | 70 | } |
| 80 | - $this->helper->get('license')->reload_license(); | |
| 71 | + $this->helper->load('license')->load(); | |
| 81 | 72 | } |
| 82 | 73 | } |
| 83 | 74 | } else { |
| 84 | 75 | wp_die($this->message('wp_verify_nonce_error')); |
| @@ -190,14 +181,15 @@ | ||
| 190 | 181 | $this->add_notification('error', __('Something went wrong!', 'e2pdf')); |
| 191 | 182 | $this->render('blocks', 'notifications'); |
| 192 | 183 | } |
| 193 | 184 | } else { |
| 194 | - $location = $this->helper->get_url( | |
| 195 | - array( | |
| 196 | - 'page' => 'e2pdf', | |
| 185 | + $this->redirect( | |
| 186 | + $this->helper->get_url( | |
| 187 | + [ | |
| 188 | + 'page' => 'e2pdf', | |
| 189 | + ] | |
| 197 | 190 | ) |
| 198 | 191 | ); |
| 199 | - $this->redirect($location); | |
| 200 | 192 | } |
| 201 | 193 | } |
| 202 | 194 | |
| 203 | 195 | /** |
| @@ -391,14 +383,15 @@ | ||
| 391 | 383 | $this->add_notification('error', __('Something went wrong!', 'e2pdf')); |
| 392 | 384 | $this->render('blocks', 'notifications'); |
| 393 | 385 | } |
| 394 | 386 | } else { |
| 395 | - $location = $this->helper->get_url( | |
| 396 | - array( | |
| 397 | - 'page' => 'e2pdf-templates', | |
| 387 | + $this->redirect( | |
| 388 | + $this->helper->get_url( | |
| 389 | + [ | |
| 390 | + 'page' => 'e2pdf-templates', | |
| 391 | + ] | |
| 398 | 392 | ) |
| 399 | 393 | ); |
| 400 | - $this->redirect($location); | |
| 401 | 394 | } |
| 402 | 395 | } |
| 403 | 396 | |
| 404 | 397 | /** |
| @@ -404,26 +397,29 @@ | ||
| 404 | 397 | /** |
| 405 | 398 | * @url admin.php?page=e2pdf-templates&action=trash&id=$id |
| 406 | 399 | */ |
| 407 | 400 | public function trash_action() { |
| 401 | + $notification = ''; | |
| 408 | 402 | if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) { |
| 409 | 403 | if ($this->get->get('id')) { |
| 410 | 404 | $this->trash_template($this->get->get('id')); |
| 411 | - $this->add_notification('update', sprintf(__('Trashed: %d', 'e2pdf'), '1')); | |
| 405 | + $notification = $this->add_notification('update', __('Template Trashed', 'e2pdf')); | |
| 412 | 406 | } |
| 413 | 407 | } else { |
| 414 | 408 | wp_die($this->message('wp_verify_nonce_error')); |
| 415 | 409 | } |
| 416 | - $location = $this->helper->get_url( | |
| 417 | - array( | |
| 418 | - 'page' => 'e2pdf-templates', | |
| 419 | - 'status' => $this->get->get('status'), | |
| 420 | - 'orderby' => $this->get->get('orderby'), | |
| 421 | - 'order' => $this->get->get('order'), | |
| 422 | - 's' => $this->get->get('s'), | |
| 410 | + $this->redirect( | |
| 411 | + $this->helper->get_url( | |
| 412 | + [ | |
| 413 | + 'page' => 'e2pdf-templates', | |
| 414 | + 'status' => $this->get->get('status'), | |
| 415 | + 'orderby' => $this->get->get('orderby'), | |
| 416 | + 'order' => $this->get->get('order'), | |
| 417 | + 's' => $this->get->get('s'), | |
| 418 | + 'notification' => $notification, | |
| 419 | + ] | |
| 423 | 420 | ) |
| 424 | 421 | ); |
| 425 | - $this->redirect($location); | |
| 426 | 422 | } |
| 427 | 423 | |
| 428 | 424 | /** |
| 429 | 425 | * @url admin.php?page=e2pdf-templates&action=restore&id=$id&status=$status |
| @@ -428,26 +424,29 @@ | ||
| 428 | 424 | /** |
| 429 | 425 | * @url admin.php?page=e2pdf-templates&action=restore&id=$id&status=$status |
| 430 | 426 | */ |
| 431 | 427 | public function restore_action() { |
| 428 | + $notification = ''; | |
| 432 | 429 | if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) { |
| 433 | 430 | if ($this->get->get('id')) { |
| 434 | 431 | $this->restore_template($this->get->get('id')); |
| 435 | - $this->add_notification('update', sprintf(__('Restored: %d', 'e2pdf'), '1')); | |
| 432 | + $notification = $this->add_notification('update', __('Template Restored', 'e2pdf')); | |
| 436 | 433 | } |
| 437 | 434 | } else { |
| 438 | 435 | wp_die($this->message('wp_verify_nonce_error')); |
| 439 | 436 | } |
| 440 | - $location = $this->helper->get_url( | |
| 441 | - array( | |
| 442 | - 'page' => 'e2pdf-templates', | |
| 443 | - 'status' => $this->get->get('status'), | |
| 444 | - 'orderby' => $this->get->get('orderby'), | |
| 445 | - 'order' => $this->get->get('order'), | |
| 446 | - 's' => $this->get->get('s'), | |
| 437 | + $this->redirect( | |
| 438 | + $this->helper->get_url( | |
| 439 | + [ | |
| 440 | + 'page' => 'e2pdf-templates', | |
| 441 | + 'status' => $this->get->get('status'), | |
| 442 | + 'orderby' => $this->get->get('orderby'), | |
| 443 | + 'order' => $this->get->get('order'), | |
| 444 | + 's' => $this->get->get('s'), | |
| 445 | + 'notification' => $notification, | |
| 446 | + ] | |
| 447 | 447 | ) |
| 448 | 448 | ); |
| 449 | - $this->redirect($location); | |
| 450 | 449 | } |
| 451 | 450 | |
| 452 | 451 | /** |
| 453 | 452 | * @url admin.php?page=e2pdf-templates&action=delete&id=$id&status=$status |
| @@ -452,26 +451,30 @@ | ||
| 452 | 451 | /** |
| 453 | 452 | * @url admin.php?page=e2pdf-templates&action=delete&id=$id&status=$status |
| 454 | 453 | */ |
| 455 | 454 | public function delete_action() { |
| 455 | + $notification = ''; | |
| 456 | 456 | if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) { |
| 457 | 457 | if ($this->get->get('id')) { |
| 458 | 458 | $this->delete_template($this->get->get('id')); |
| 459 | - $this->add_notification('update', sprintf(__('Deleted: %d', 'e2pdf'), '1')); | |
| 459 | + $notification = $this->add_notification('update', __('Template Deleted', 'e2pdf')); | |
| 460 | 460 | } |
| 461 | 461 | } else { |
| 462 | 462 | wp_die($this->message('wp_verify_nonce_error')); |
| 463 | 463 | } |
| 464 | - $location = $this->helper->get_url( | |
| 465 | - array( | |
| 466 | - 'page' => 'e2pdf-templates', | |
| 467 | - 'status' => $this->get->get('status'), | |
| 468 | - 'orderby' => $this->get->get('orderby'), | |
| 469 | - 'order' => $this->get->get('order'), | |
| 470 | - 's' => $this->get->get('s'), | |
| 464 | + | |
| 465 | + $this->redirect( | |
| 466 | + $this->helper->get_url( | |
| 467 | + [ | |
| 468 | + 'page' => 'e2pdf-templates', | |
| 469 | + 'status' => $this->get->get('status'), | |
| 470 | + 'orderby' => $this->get->get('orderby'), | |
| 471 | + 'order' => $this->get->get('order'), | |
| 472 | + 's' => $this->get->get('s'), | |
| 473 | + 'notification' => $notification, | |
| 474 | + ] | |
| 471 | 475 | ) |
| 472 | 476 | ); |
| 473 | - $this->redirect($location); | |
| 474 | 477 | } |
| 475 | 478 | |
| 476 | 479 | /** |
| 477 | 480 | * @url admin.php?page=e2pdf-templates&action=duplicate&id=$id |
| @@ -476,26 +479,29 @@ | ||
| 476 | 479 | /** |
| 477 | 480 | * @url admin.php?page=e2pdf-templates&action=duplicate&id=$id |
| 478 | 481 | */ |
| 479 | 482 | public function duplicate_action() { |
| 483 | + $notification = ''; | |
| 480 | 484 | if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) { |
| 481 | 485 | if ($this->get->get('id')) { |
| 482 | 486 | $this->duplicate_template($this->get->get('id')); |
| 483 | - $this->add_notification('update', sprintf(__('Duplicated: %d', 'e2pdf'), '1')); | |
| 487 | + $notification = $this->add_notification('update', __('Template Duplicated', 'e2pdf')); | |
| 484 | 488 | } |
| 485 | 489 | } else { |
| 486 | 490 | wp_die($this->message('wp_verify_nonce_error')); |
| 487 | 491 | } |
| 488 | - $location = $this->helper->get_url( | |
| 489 | - array( | |
| 490 | - 'page' => 'e2pdf-templates', | |
| 491 | - 'status' => $this->get->get('status'), | |
| 492 | - 'orderby' => $this->get->get('orderby'), | |
| 493 | - 'order' => $this->get->get('order'), | |
| 494 | - 's' => $this->get->get('s'), | |
| 492 | + $this->redirect( | |
| 493 | + $this->helper->get_url( | |
| 494 | + [ | |
| 495 | + 'page' => 'e2pdf-templates', | |
| 496 | + 'status' => $this->get->get('status'), | |
| 497 | + 'orderby' => $this->get->get('orderby'), | |
| 498 | + 'order' => $this->get->get('order'), | |
| 499 | + 's' => $this->get->get('s'), | |
| 500 | + 'notification' => $notification, | |
| 501 | + ] | |
| 495 | 502 | ) |
| 496 | 503 | ); |
| 497 | - $this->redirect($location); | |
| 498 | 504 | } |
| 499 | 505 | |
| 500 | 506 | /** |
| 501 | 507 | * @url admin.php?page=e2pdf-templates&action=import |
| @@ -506,24 +512,15 @@ | ||
| 506 | 512 | if (!wp_verify_nonce($this->post->get('_wpnonce'), 'e2pdf_templates')) { |
| 507 | 513 | wp_die($this->message('wp_verify_nonce_error')); |
| 508 | 514 | } |
| 509 | 515 | |
| 510 | - $errors = array(); | |
| 511 | - $import = $this->files->get('template'); | |
| 512 | - $name = $import['name']; | |
| 513 | - $tmp = $import['tmp_name']; | |
| 514 | - $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION)); | |
| 515 | - if (!$tmp) { | |
| 516 | - $this->add_notification('error', __('Choose Template file to upload', 'e2pdf')); | |
| 517 | - } elseif ($import['error']) { | |
| 518 | - $this->add_notification('error', $import['error']); | |
| 519 | - } elseif (!in_array($ext, array('xml'))) { | |
| 520 | - $this->add_notification('error', sprintf(__('Only %s files allowed', 'e2pdf'), '.xml')); | |
| 521 | - } elseif ($import['type'] != 'text/xml') { | |
| 522 | - $this->add_notification('error', __('Invalid Type', 'e2pdf')); | |
| 516 | + $file = $this->helper->load('files')->upload($this->files->get('template'), ['xml'], ['text/xml', 'application/xml']); | |
| 517 | + if (isset($file['error'])) { | |
| 518 | + $this->add_notification('error', $file['error']); | |
| 523 | 519 | } else { |
| 520 | + $errors = []; | |
| 524 | 521 | $options = $this->post->get('options'); |
| 525 | - $xml = simplexml_load_file($import['tmp_name'], 'SimpleXMLElement', LIBXML_PARSEHUGE); | |
| 522 | + $xml = simplexml_load_file($file['tmp_name'], 'SimpleXMLElement', LIBXML_PARSEHUGE); | |
| 526 | 523 | if (!isset($xml->template->pages)) { |
| 527 | 524 | $this->add_notification('error', __('The file is not a valid E2Pdf Template', 'e2pdf')); |
| 528 | 525 | } else { |
| 529 | 526 | $pages = $this->helper->load('convert')->unserialize(base64_decode((string) $xml->template->pages)); |
| @@ -830,10 +827,9 @@ | ||
| 830 | 827 | $template->activate(); |
| 831 | 828 | if ($template->get('ID')) { |
| 832 | 829 | $this->add_notification( |
| 833 | 830 | 'update', sprintf( |
| 834 | - __('Imported: %1$d: <a target="_blank" href="%2$s">View</a> | <a target="_blank" href="%3$s">Edit</a>', 'e2pdf'), | |
| 835 | - '1', | |
| 831 | + __('Template Imported: <a target="_blank" href="%1$s">View</a> | <a target="_blank" href="%2$s">Edit</a>', 'e2pdf'), | |
| 836 | 832 | $this->helper->get_url( |
| 837 | 833 | [ |
| 838 | 834 | 'page' => 'e2pdf-templates', |
| 839 | 835 | 'action' => 'view', |
| @@ -839,9 +835,15 @@ | ||
| 839 | 835 | 'action' => 'view', |
| 840 | 836 | 'id' => $template->get('ID') |
| 841 | 837 | ] |
| 842 | 838 | ), |
| 843 | - $this->helper->get_url(array('page' => 'e2pdf-templates', 'action' => 'edit', 'id' => $template->get('ID'))) | |
| 839 | + $this->helper->get_url( | |
| 840 | + [ | |
| 841 | + 'page' => 'e2pdf-templates', | |
| 842 | + 'action' => 'edit', | |
| 843 | + 'id' => $template->get('ID') | |
| 844 | + ] | |
| 845 | + ) | |
| 844 | 846 | ) |
| 845 | 847 | ); |
| 846 | 848 | } else { |
| 847 | 849 | $this->add_notification('error', __('Something went wrong!', 'e2pdf')); |
| @@ -851,9 +853,11 @@ | ||
| 851 | 853 | $this->add_notification('error', $error); |
| 852 | 854 | } |
| 853 | 855 | } |
| 854 | 856 | } |
| 855 | - unlink($import['tmp_name']); | |
| 857 | + if (is_file($file['tmp_name'])) { | |
| 858 | + unlink($file['tmp_name']); | |
| 859 | + } | |
| 856 | 860 | } |
| 857 | 861 | } |
| 858 | 862 | |
| 859 | 863 | $this->view('import_disabled', false); |
| @@ -1219,17 +1223,21 @@ | ||
| 1219 | 1223 | |
| 1220 | 1224 | // screen action |
| 1221 | 1225 | public function screen_action() { |
| 1222 | 1226 | $option = $this->post->get('wp_screen_options'); |
| 1223 | - if (is_array($option) && isset($option['option']) && isset($option['value']) && $option['value']) { | |
| 1224 | - update_option($option['option'], $option['value']); | |
| 1227 | + if (is_array($option) && isset($option['option'], $option['value']) && $option['option'] === 'e2pdf_templates_screen_per_page') { | |
| 1228 | + $per_page = (int) $option['value']; | |
| 1229 | + if ($per_page > 0) { | |
| 1230 | + update_option($option['option'], $per_page); | |
| 1231 | + } | |
| 1225 | 1232 | } |
| 1226 | - $location = $this->helper->get_url( | |
| 1227 | - array( | |
| 1228 | - 'page' => 'e2pdf-templates', | |
| 1233 | + $this->redirect( | |
| 1234 | + $this->helper->get_url( | |
| 1235 | + [ | |
| 1236 | + 'page' => 'e2pdf-templates', | |
| 1237 | + ] | |
| 1229 | 1238 | ) |
| 1230 | 1239 | ); |
| 1231 | - $this->redirect($location); | |
| 1232 | 1240 | } |
| 1233 | 1241 | |
| 1234 | 1242 | // ajax save form |
| 1235 | 1243 | public function ajax_save_form() { |
| @@ -1281,12 +1289,12 @@ | ||
| 1281 | 1289 | array( |
| 1282 | 1290 | 'page' => 'e2pdf-templates', |
| 1283 | 1291 | 'action' => 'edit', |
| 1284 | 1292 | 'id' => $template->get('ID'), |
| 1293 | + 'notification' => $this->add_notification('update', __('Template Saved', 'e2pdf')), | |
| 1285 | 1294 | ) |
| 1286 | 1295 | ), |
| 1287 | 1296 | ); |
| 1288 | - $this->add_notification('update', sprintf(__('Updated: %d', 'e2pdf'), '1')); | |
| 1289 | 1297 | } |
| 1290 | 1298 | } else { |
| 1291 | 1299 | $response['error'] = $this->message('wp_verify_nonce_error'); |
| 1292 | 1300 | } |
| @@ -1404,37 +1412,23 @@ | ||
| 1404 | 1412 | $line_height = isset($data['line_height']) ? $data['line_height'] : false; |
| 1405 | 1413 | $title = isset($data['title']) ? $data['title'] : __('(no title)', 'e2pdf'); |
| 1406 | 1414 | $rtl = isset($data['rtl']) && $data['rtl'] ? '1' : '0'; |
| 1407 | 1415 | $text_align = isset($data['text_align']) ? $data['text_align'] : 'left'; |
| 1408 | - $pdf = $this->files->get('pdf'); | |
| 1409 | - $name = strtolower($pdf['name']); | |
| 1410 | - $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION)); | |
| 1411 | 1416 | |
| 1412 | - if (!empty($pdf['error'])) { | |
| 1417 | + $file = $this->helper->load('files')->upload($this->files->get('pdf'), ['pdf'], ['application/pdf']); | |
| 1418 | + if (isset($file['error'])) { | |
| 1413 | 1419 | $this->json_response( |
| 1414 | 1420 | [ |
| 1415 | - 'error' => $pdf['error'], | |
| 1421 | + 'error' => $file['error'], | |
| 1416 | 1422 | ] |
| 1417 | 1423 | ); |
| 1418 | - } elseif (!in_array($ext, array('pdf'))) { | |
| 1419 | - $this->json_response( | |
| 1420 | - [ | |
| 1421 | - 'error' => sprintf(__('Only %s files allowed', 'e2pdf'), '.pdf'), | |
| 1422 | - ] | |
| 1423 | - ); | |
| 1424 | - } elseif ($pdf['type'] != 'application/pdf') { | |
| 1425 | - $this->json_response( | |
| 1426 | - [ | |
| 1427 | - 'error' => __('Invalid Type', 'e2pdf'), | |
| 1428 | - ] | |
| 1429 | - ); | |
| 1430 | 1424 | } |
| 1431 | 1425 | |
| 1432 | 1426 | wp_raise_memory_limit('admin'); |
| 1433 | - if (get_option('e2pdf_api_protocol', '0') == '1') { | |
| 1434 | - $upload = class_exists('CURLFile') ? new CURLFile(realpath($pdf['tmp_name'])) : '@' . realpath($pdf['tmp_name']); | |
| 1427 | + if (get_option('e2pdf_api_protocol', '0') == '1' && ($tmp = realpath($file['tmp_name']))) { | |
| 1428 | + $upload = class_exists('CURLFile') ? new CURLFile($tmp) : '@' . $tmp; | |
| 1435 | 1429 | } else { |
| 1436 | - $upload = base64_encode(file_get_contents($pdf['tmp_name'])); | |
| 1430 | + $upload = base64_encode(file_get_contents($file['tmp_name'])); | |
| 1437 | 1431 | } |
| 1438 | 1432 | |
| 1439 | 1433 | $model_e2pdf_api = new Model_E2pdf_Api(); |
| 1440 | 1434 | $model_e2pdf_api->set( |
| @@ -1440,9 +1434,9 @@ | ||
| 1440 | 1434 | $model_e2pdf_api->set( |
| 1441 | 1435 | array( |
| 1442 | 1436 | 'action' => 'template/upload2', |
| 1443 | 1437 | 'data' => array( |
| 1444 | - 'title' => $name, | |
| 1438 | + 'title' => $file['name'], | |
| 1445 | 1439 | 'pdf' => $upload, |
| 1446 | 1440 | ), |
| 1447 | 1441 | ) |
| 1448 | 1442 | ); |
| @@ -1468,10 +1462,17 @@ | ||
| 1468 | 1462 | $pdf_dir = $this->helper->get('pdf_dir') . $pdf_name . '/'; |
| 1469 | 1463 | $pdf_images_dir = $pdf_dir . 'images/'; |
| 1470 | 1464 | $this->helper->create_dir($pdf_dir); |
| 1471 | 1465 | $this->helper->create_dir($pdf_images_dir); |
| 1472 | - move_uploaded_file($pdf['tmp_name'], $pdf_dir . $pdf_name . '.pdf'); | |
| 1473 | 1466 | |
| 1467 | + if (!move_uploaded_file($file['tmp_name'], $pdf_dir . $pdf_name . '.pdf')) { | |
| 1468 | + $this->json_response( | |
| 1469 | + [ | |
| 1470 | + 'error' => 'Failed to move uploaded file', | |
| 1471 | + ] | |
| 1472 | + ); | |
| 1473 | + } | |
| 1474 | + | |
| 1474 | 1475 | try { |
| 1475 | 1476 | $xml_template = []; |
| 1476 | 1477 | $pages = []; |
| 1477 | 1478 | if (class_exists('XMLReader')) { |
| @@ -1505,10 +1506,10 @@ | ||
| 1505 | 1506 | $this->helper->load('xml')->parse_xml_page($page_node, $pages, $pdf_images_dir, $extension); |
| 1506 | 1507 | break; |
| 1507 | 1508 | case 'fonts': |
| 1508 | 1509 | $fonts_node = new SimpleXMLElement($reader->readOuterXML(), LIBXML_PARSEHUGE); |
| 1509 | - foreach ($fonts_node->children() as $font) { | |
| 1510 | - $this->helper->load('xml')->parse_xml_font($font); | |
| 1510 | + foreach ($fonts_node->children() as $xml_font) { | |
| 1511 | + $this->helper->load('xml')->parse_xml_font($xml_font); | |
| 1511 | 1512 | } |
| 1512 | 1513 | break; |
| 1513 | 1514 | default: |
| 1514 | 1515 | break; |
| @@ -1542,10 +1543,10 @@ | ||
| 1542 | 1543 | 'font_color' => (string) $xml->template->font_color, |
| 1543 | 1544 | ]; |
| 1544 | 1545 | } |
| 1545 | 1546 | if (isset($xml->fonts) && $xml->fonts) { |
| 1546 | - foreach ($xml->fonts->children() as $key => $font) { | |
| 1547 | - $this->helper->load('xml')->parse_xml_font($font); | |
| 1547 | + foreach ($xml->fonts->children() as $key => $xml_font) { | |
| 1548 | + $this->helper->load('xml')->parse_xml_font($xml_font); | |
| 1548 | 1549 | } |
| 1549 | 1550 | } |
| 1550 | 1551 | } |
| 1551 | 1552 | |
| @@ -1656,37 +1657,22 @@ | ||
| 1656 | 1657 | if (!$template_id) { |
| 1657 | 1658 | return false; |
| 1658 | 1659 | } |
| 1659 | 1660 | |
| 1660 | - $pdf = $this->files->get('pdf'); | |
| 1661 | - $name = strtolower($pdf['name']); | |
| 1662 | - $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION)); | |
| 1663 | - | |
| 1664 | - if (!empty($pdf['error'])) { | |
| 1661 | + $file = $this->helper->load('files')->upload($this->files->get('pdf'), ['pdf'], ['application/pdf']); | |
| 1662 | + if (isset($file['error'])) { | |
| 1665 | 1663 | $this->json_response( |
| 1666 | 1664 | [ |
| 1667 | - 'error' => $pdf['error'], | |
| 1665 | + 'error' => $file['error'], | |
| 1668 | 1666 | ] |
| 1669 | 1667 | ); |
| 1670 | - } elseif (!in_array($ext, array('pdf'))) { | |
| 1671 | - $this->json_response( | |
| 1672 | - [ | |
| 1673 | - 'error' => sprintf(__('Only %s files allowed', 'e2pdf'), '.pdf'), | |
| 1674 | - ] | |
| 1675 | - ); | |
| 1676 | - } elseif ($pdf['type'] != 'application/pdf') { | |
| 1677 | - $this->json_response( | |
| 1678 | - [ | |
| 1679 | - 'error' => __('Invalid Type', 'e2pdf'), | |
| 1680 | - ] | |
| 1681 | - ); | |
| 1682 | 1668 | } |
| 1683 | 1669 | |
| 1684 | 1670 | wp_raise_memory_limit('admin'); |
| 1685 | - if (get_option('e2pdf_api_protocol', '0') == '1') { | |
| 1686 | - $upload = class_exists('CURLFile') ? new CURLFile(realpath($pdf['tmp_name'])) : '@' . realpath($pdf['tmp_name']); | |
| 1671 | + if (get_option('e2pdf_api_protocol', '0') == '1' && ($tmp = realpath($file['tmp_name']))) { | |
| 1672 | + $upload = class_exists('CURLFile') ? new CURLFile($tmp) : '@' . $tmp; | |
| 1687 | 1673 | } else { |
| 1688 | - $upload = base64_encode(file_get_contents($pdf['tmp_name'])); | |
| 1674 | + $upload = base64_encode(file_get_contents($file['tmp_name'])); | |
| 1689 | 1675 | } |
| 1690 | 1676 | |
| 1691 | 1677 | $model_e2pdf_api = new Model_E2pdf_Api(); |
| 1692 | 1678 | $model_e2pdf_api->set( |
| @@ -1692,9 +1678,9 @@ | ||
| 1692 | 1678 | $model_e2pdf_api->set( |
| 1693 | 1679 | array( |
| 1694 | 1680 | 'action' => 'template/upload2', |
| 1695 | 1681 | 'data' => array( |
| 1696 | - 'title' => $name, | |
| 1682 | + 'title' => $file['name'], | |
| 1697 | 1683 | 'pdf' => $upload, |
| 1698 | 1684 | ), |
| 1699 | 1685 | ) |
| 1700 | 1686 | ); |
| @@ -1727,10 +1713,17 @@ | ||
| 1727 | 1713 | $pdf_dir = $this->helper->get('pdf_dir') . $pdf_name . '/'; |
| 1728 | 1714 | $pdf_images_dir = $pdf_dir . 'images/'; |
| 1729 | 1715 | $this->helper->create_dir($pdf_dir); |
| 1730 | 1716 | $this->helper->create_dir($pdf_images_dir); |
| 1731 | - move_uploaded_file($pdf['tmp_name'], $pdf_dir . $pdf_name . '.pdf'); | |
| 1732 | 1717 | |
| 1718 | + if (!move_uploaded_file($file['tmp_name'], $pdf_dir . $pdf_name . '.pdf')) { | |
| 1719 | + $this->json_response( | |
| 1720 | + [ | |
| 1721 | + 'error' => 'Failed to move uploaded file', | |
| 1722 | + ] | |
| 1723 | + ); | |
| 1724 | + } | |
| 1725 | + | |
| 1733 | 1726 | try { |
| 1734 | 1727 | $pages = []; |
| 1735 | 1728 | $pos_pages = []; |
| 1736 | 1729 | if (class_exists('XMLReader')) { |
| @@ -2151,10 +2144,9 @@ | ||
| 2151 | 2144 | $limit_condition = array(); |
| 2152 | 2145 | if (!$count) { |
| 2153 | 2146 | $paged = isset($filters['paged']) && $filters['paged'] ? $filters['paged'] : '0'; |
| 2154 | 2147 | $paged = (int) $paged <= 0 ? 1 : (int) $paged; |
| 2155 | - $per_page = get_option('e2pdf_templates_screen_per_page', '20'); | |
| 2156 | - | |
| 2148 | + $per_page = (int) get_option('e2pdf_templates_screen_per_page', '20'); | |
| 2157 | 2149 | $limit_condition = array( |
| 2158 | 2150 | 'limit' => (int) $per_page, |
| 2159 | 2151 | 'offset' => (int) ($paged - 1) * $per_page, |
| 2160 | 2152 | ); |