PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.49
E2Pdf – Export Pdf Tool for WordPress v1.32.49
1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 1.08.00 1.08.06 All 72 releases
← All changes | classes/controller/e2pdf-templates.php +38 -60 1.32.321.32.49 View file →
@@ -512,24 +512,15 @@
512 512 if (!wp_verify_nonce($this->post->get('_wpnonce'), 'e2pdf_templates')) {
513 513 wp_die($this->message('wp_verify_nonce_error'));
514 514 }
515 515
516 - $errors = array();
517 - $import = $this->files->get('template');
518 - $name = $import['name'];
519 - $tmp = $import['tmp_name'];
520 - $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
521 - if (!$tmp) {
522 - $this->add_notification('error', __('Choose Template file to upload', 'e2pdf'));
523 - } elseif ($import['error']) {
524 - $this->add_notification('error', $import['error']);
525 - } elseif (!in_array($ext, array('xml'))) {
526 - $this->add_notification('error', sprintf(__('Only %s files allowed', 'e2pdf'), '.xml'));
527 - } elseif ($import['type'] != 'text/xml') {
528 - $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']);
529 519 } else {
520 + $errors = [];
530 521 $options = $this->post->get('options');
531 - $xml = simplexml_load_file($import['tmp_name'], 'SimpleXMLElement', LIBXML_PARSEHUGE);
522 + $xml = simplexml_load_file($file['tmp_name'], 'SimpleXMLElement', LIBXML_PARSEHUGE);
532 523 if (!isset($xml->template->pages)) {
533 524 $this->add_notification('error', __('The file is not a valid E2Pdf Template', 'e2pdf'));
534 525 } else {
535 526 $pages = $this->helper->load('convert')->unserialize(base64_decode((string) $xml->template->pages));
@@ -862,9 +853,11 @@
862 853 $this->add_notification('error', $error);
863 854 }
864 855 }
865 856 }
866 - unlink($import['tmp_name']);
857 + if (is_file($file['tmp_name'])) {
858 + unlink($file['tmp_name']);
859 + }
867 860 }
868 861 }
869 862
870 863 $this->view('import_disabled', false);
@@ -1419,37 +1412,23 @@
1419 1412 $line_height = isset($data['line_height']) ? $data['line_height'] : false;
1420 1413 $title = isset($data['title']) ? $data['title'] : __('(no title)', 'e2pdf');
1421 1414 $rtl = isset($data['rtl']) && $data['rtl'] ? '1' : '0';
1422 1415 $text_align = isset($data['text_align']) ? $data['text_align'] : 'left';
1423 - $pdf = $this->files->get('pdf');
1424 - $name = strtolower($pdf['name']);
1425 - $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
1426 1416
1427 - if (!empty($pdf['error'])) {
1417 + $file = $this->helper->load('files')->upload($this->files->get('pdf'), ['pdf'], ['application/pdf']);
1418 + if (isset($file['error'])) {
1428 1419 $this->json_response(
1429 1420 [
1430 - 'error' => $pdf['error'],
1421 + 'error' => $file['error'],
1431 1422 ]
1432 1423 );
1433 - } elseif (!in_array($ext, array('pdf'))) {
1434 - $this->json_response(
1435 - [
1436 - 'error' => sprintf(__('Only %s files allowed', 'e2pdf'), '.pdf'),
1437 - ]
1438 - );
1439 - } elseif ($pdf['type'] != 'application/pdf') {
1440 - $this->json_response(
1441 - [
1442 - 'error' => __('Invalid Type', 'e2pdf'),
1443 - ]
1444 - );
1445 1424 }
1446 1425
1447 1426 wp_raise_memory_limit('admin');
1448 - if (get_option('e2pdf_api_protocol', '0') == '1') {
1449 - $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;
1450 1429 } else {
1451 - $upload = base64_encode(file_get_contents($pdf['tmp_name']));
1430 + $upload = base64_encode(file_get_contents($file['tmp_name']));
1452 1431 }
1453 1432
1454 1433 $model_e2pdf_api = new Model_E2pdf_Api();
1455 1434 $model_e2pdf_api->set(
@@ -1455,9 +1434,9 @@
1455 1434 $model_e2pdf_api->set(
1456 1435 array(
1457 1436 'action' => 'template/upload2',
1458 1437 'data' => array(
1459 - 'title' => $name,
1438 + 'title' => $file['name'],
1460 1439 'pdf' => $upload,
1461 1440 ),
1462 1441 )
1463 1442 );
@@ -1483,10 +1462,17 @@
1483 1462 $pdf_dir = $this->helper->get('pdf_dir') . $pdf_name . '/';
1484 1463 $pdf_images_dir = $pdf_dir . 'images/';
1485 1464 $this->helper->create_dir($pdf_dir);
1486 1465 $this->helper->create_dir($pdf_images_dir);
1487 - move_uploaded_file($pdf['tmp_name'], $pdf_dir . $pdf_name . '.pdf');
1488 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 +
1489 1475 try {
1490 1476 $xml_template = [];
1491 1477 $pages = [];
1492 1478 if (class_exists('XMLReader')) {
@@ -1671,37 +1657,22 @@
1671 1657 if (!$template_id) {
1672 1658 return false;
1673 1659 }
1674 1660
1675 - $pdf = $this->files->get('pdf');
1676 - $name = strtolower($pdf['name']);
1677 - $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
1678 -
1679 - if (!empty($pdf['error'])) {
1661 + $file = $this->helper->load('files')->upload($this->files->get('pdf'), ['pdf'], ['application/pdf']);
1662 + if (isset($file['error'])) {
1680 1663 $this->json_response(
1681 1664 [
1682 - 'error' => $pdf['error'],
1665 + 'error' => $file['error'],
1683 1666 ]
1684 1667 );
1685 - } elseif (!in_array($ext, array('pdf'))) {
1686 - $this->json_response(
1687 - [
1688 - 'error' => sprintf(__('Only %s files allowed', 'e2pdf'), '.pdf'),
1689 - ]
1690 - );
1691 - } elseif ($pdf['type'] != 'application/pdf') {
1692 - $this->json_response(
1693 - [
1694 - 'error' => __('Invalid Type', 'e2pdf'),
1695 - ]
1696 - );
1697 1668 }
1698 1669
1699 1670 wp_raise_memory_limit('admin');
1700 - if (get_option('e2pdf_api_protocol', '0') == '1') {
1701 - $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;
1702 1673 } else {
1703 - $upload = base64_encode(file_get_contents($pdf['tmp_name']));
1674 + $upload = base64_encode(file_get_contents($file['tmp_name']));
1704 1675 }
1705 1676
1706 1677 $model_e2pdf_api = new Model_E2pdf_Api();
1707 1678 $model_e2pdf_api->set(
@@ -1707,9 +1678,9 @@
1707 1678 $model_e2pdf_api->set(
1708 1679 array(
1709 1680 'action' => 'template/upload2',
1710 1681 'data' => array(
1711 - 'title' => $name,
1682 + 'title' => $file['name'],
1712 1683 'pdf' => $upload,
1713 1684 ),
1714 1685 )
1715 1686 );
@@ -1742,9 +1713,16 @@
1742 1713 $pdf_dir = $this->helper->get('pdf_dir') . $pdf_name . '/';
1743 1714 $pdf_images_dir = $pdf_dir . 'images/';
1744 1715 $this->helper->create_dir($pdf_dir);
1745 1716 $this->helper->create_dir($pdf_images_dir);
1746 - move_uploaded_file($pdf['tmp_name'], $pdf_dir . $pdf_name . '.pdf');
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 + }
1747 1725
1748 1726 try {
1749 1727 $pages = [];
1750 1728 $pos_pages = [];