PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.51
E2Pdf – Export Pdf Tool for WordPress v1.32.51
1.32.51 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 All 73 releases
← All changes | classes/controller/e2pdf-templates.php +44 -64 1.32.231.32.51 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);
@@ -1230,10 +1223,13 @@
1230 1223
1231 1224 // screen action
1232 1225 public function screen_action() {
1233 1226 $option = $this->post->get('wp_screen_options');
1234 - if (is_array($option) && isset($option['option']) && isset($option['value']) && $option['value']) {
1235 - 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 + }
1236 1232 }
1237 1233 $this->redirect(
1238 1234 $this->helper->get_url(
1239 1235 [
@@ -1416,37 +1412,23 @@
1416 1412 $line_height = isset($data['line_height']) ? $data['line_height'] : false;
1417 1413 $title = isset($data['title']) ? $data['title'] : __('(no title)', 'e2pdf');
1418 1414 $rtl = isset($data['rtl']) && $data['rtl'] ? '1' : '0';
1419 1415 $text_align = isset($data['text_align']) ? $data['text_align'] : 'left';
1420 - $pdf = $this->files->get('pdf');
1421 - $name = strtolower($pdf['name']);
1422 - $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
1423 1416
1424 - if (!empty($pdf['error'])) {
1417 + $file = $this->helper->load('files')->upload($this->files->get('pdf'), ['pdf'], ['application/pdf']);
1418 + if (isset($file['error'])) {
1425 1419 $this->json_response(
1426 1420 [
1427 - 'error' => $pdf['error'],
1421 + 'error' => $file['error'],
1428 1422 ]
1429 1423 );
1430 - } elseif (!in_array($ext, array('pdf'))) {
1431 - $this->json_response(
1432 - [
1433 - 'error' => sprintf(__('Only %s files allowed', 'e2pdf'), '.pdf'),
1434 - ]
1435 - );
1436 - } elseif ($pdf['type'] != 'application/pdf') {
1437 - $this->json_response(
1438 - [
1439 - 'error' => __('Invalid Type', 'e2pdf'),
1440 - ]
1441 - );
1442 1424 }
1443 1425
1444 1426 wp_raise_memory_limit('admin');
1445 - if (get_option('e2pdf_api_protocol', '0') == '1') {
1446 - $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;
1447 1429 } else {
1448 - $upload = base64_encode(file_get_contents($pdf['tmp_name']));
1430 + $upload = base64_encode(file_get_contents($file['tmp_name']));
1449 1431 }
1450 1432
1451 1433 $model_e2pdf_api = new Model_E2pdf_Api();
1452 1434 $model_e2pdf_api->set(
@@ -1452,9 +1434,9 @@
1452 1434 $model_e2pdf_api->set(
1453 1435 array(
1454 1436 'action' => 'template/upload2',
1455 1437 'data' => array(
1456 - 'title' => $name,
1438 + 'title' => $file['name'],
1457 1439 'pdf' => $upload,
1458 1440 ),
1459 1441 )
1460 1442 );
@@ -1480,10 +1462,17 @@
1480 1462 $pdf_dir = $this->helper->get('pdf_dir') . $pdf_name . '/';
1481 1463 $pdf_images_dir = $pdf_dir . 'images/';
1482 1464 $this->helper->create_dir($pdf_dir);
1483 1465 $this->helper->create_dir($pdf_images_dir);
1484 - move_uploaded_file($pdf['tmp_name'], $pdf_dir . $pdf_name . '.pdf');
1485 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 +
1486 1475 try {
1487 1476 $xml_template = [];
1488 1477 $pages = [];
1489 1478 if (class_exists('XMLReader')) {
@@ -1668,37 +1657,22 @@
1668 1657 if (!$template_id) {
1669 1658 return false;
1670 1659 }
1671 1660
1672 - $pdf = $this->files->get('pdf');
1673 - $name = strtolower($pdf['name']);
1674 - $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
1675 -
1676 - if (!empty($pdf['error'])) {
1661 + $file = $this->helper->load('files')->upload($this->files->get('pdf'), ['pdf'], ['application/pdf']);
1662 + if (isset($file['error'])) {
1677 1663 $this->json_response(
1678 1664 [
1679 - 'error' => $pdf['error'],
1665 + 'error' => $file['error'],
1680 1666 ]
1681 1667 );
1682 - } elseif (!in_array($ext, array('pdf'))) {
1683 - $this->json_response(
1684 - [
1685 - 'error' => sprintf(__('Only %s files allowed', 'e2pdf'), '.pdf'),
1686 - ]
1687 - );
1688 - } elseif ($pdf['type'] != 'application/pdf') {
1689 - $this->json_response(
1690 - [
1691 - 'error' => __('Invalid Type', 'e2pdf'),
1692 - ]
1693 - );
1694 1668 }
1695 1669
1696 1670 wp_raise_memory_limit('admin');
1697 - if (get_option('e2pdf_api_protocol', '0') == '1') {
1698 - $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;
1699 1673 } else {
1700 - $upload = base64_encode(file_get_contents($pdf['tmp_name']));
1674 + $upload = base64_encode(file_get_contents($file['tmp_name']));
1701 1675 }
1702 1676
1703 1677 $model_e2pdf_api = new Model_E2pdf_Api();
1704 1678 $model_e2pdf_api->set(
@@ -1704,9 +1678,9 @@
1704 1678 $model_e2pdf_api->set(
1705 1679 array(
1706 1680 'action' => 'template/upload2',
1707 1681 'data' => array(
1708 - 'title' => $name,
1682 + 'title' => $file['name'],
1709 1683 'pdf' => $upload,
1710 1684 ),
1711 1685 )
1712 1686 );
@@ -1739,10 +1713,17 @@
1739 1713 $pdf_dir = $this->helper->get('pdf_dir') . $pdf_name . '/';
1740 1714 $pdf_images_dir = $pdf_dir . 'images/';
1741 1715 $this->helper->create_dir($pdf_dir);
1742 1716 $this->helper->create_dir($pdf_images_dir);
1743 - move_uploaded_file($pdf['tmp_name'], $pdf_dir . $pdf_name . '.pdf');
1744 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 +
1745 1726 try {
1746 1727 $pages = [];
1747 1728 $pos_pages = [];
1748 1729 if (class_exists('XMLReader')) {
@@ -2163,10 +2144,9 @@
2163 2144 $limit_condition = array();
2164 2145 if (!$count) {
2165 2146 $paged = isset($filters['paged']) && $filters['paged'] ? $filters['paged'] : '0';
2166 2147 $paged = (int) $paged <= 0 ? 1 : (int) $paged;
2167 - $per_page = get_option('e2pdf_templates_screen_per_page', '20');
2168 -
2148 + $per_page = (int) get_option('e2pdf_templates_screen_per_page', '20');
2169 2149 $limit_condition = array(
2170 2150 'limit' => (int) $per_page,
2171 2151 'offset' => (int) ($paged - 1) * $per_page,
2172 2152 );