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 +56 -70 1.32.221.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));
@@ -836,9 +827,9 @@
836 827 $template->activate();
837 828 if ($template->get('ID')) {
838 829 $this->add_notification(
839 830 'update', sprintf(
840 - __('Template Imported: <a target="_blank" href="%2$s">View</a> | <a target="_blank" href="%3$s">Edit</a>', 'e2pdf'),
831 + __('Template Imported: <a target="_blank" href="%1$s">View</a> | <a target="_blank" href="%2$s">Edit</a>', 'e2pdf'),
841 832 $this->helper->get_url(
842 833 [
843 834 'page' => 'e2pdf-templates',
844 835 'action' => 'view',
@@ -844,9 +835,15 @@
844 835 'action' => 'view',
845 836 'id' => $template->get('ID')
846 837 ]
847 838 ),
848 - $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 + )
849 846 )
850 847 );
851 848 } else {
852 849 $this->add_notification('error', __('Something went wrong!', 'e2pdf'));
@@ -856,9 +853,11 @@
856 853 $this->add_notification('error', $error);
857 854 }
858 855 }
859 856 }
860 - unlink($import['tmp_name']);
857 + if (is_file($file['tmp_name'])) {
858 + unlink($file['tmp_name']);
859 + }
861 860 }
862 861 }
863 862
864 863 $this->view('import_disabled', false);
@@ -1224,10 +1223,13 @@
1224 1223
1225 1224 // screen action
1226 1225 public function screen_action() {
1227 1226 $option = $this->post->get('wp_screen_options');
1228 - if (is_array($option) && isset($option['option']) && isset($option['value']) && $option['value']) {
1229 - 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 + }
1230 1232 }
1231 1233 $this->redirect(
1232 1234 $this->helper->get_url(
1233 1235 [
@@ -1410,37 +1412,23 @@
1410 1412 $line_height = isset($data['line_height']) ? $data['line_height'] : false;
1411 1413 $title = isset($data['title']) ? $data['title'] : __('(no title)', 'e2pdf');
1412 1414 $rtl = isset($data['rtl']) && $data['rtl'] ? '1' : '0';
1413 1415 $text_align = isset($data['text_align']) ? $data['text_align'] : 'left';
1414 - $pdf = $this->files->get('pdf');
1415 - $name = strtolower($pdf['name']);
1416 - $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
1417 1416
1418 - if (!empty($pdf['error'])) {
1417 + $file = $this->helper->load('files')->upload($this->files->get('pdf'), ['pdf'], ['application/pdf']);
1418 + if (isset($file['error'])) {
1419 1419 $this->json_response(
1420 1420 [
1421 - 'error' => $pdf['error'],
1421 + 'error' => $file['error'],
1422 1422 ]
1423 1423 );
1424 - } elseif (!in_array($ext, array('pdf'))) {
1425 - $this->json_response(
1426 - [
1427 - 'error' => sprintf(__('Only %s files allowed', 'e2pdf'), '.pdf'),
1428 - ]
1429 - );
1430 - } elseif ($pdf['type'] != 'application/pdf') {
1431 - $this->json_response(
1432 - [
1433 - 'error' => __('Invalid Type', 'e2pdf'),
1434 - ]
1435 - );
1436 1424 }
1437 1425
1438 1426 wp_raise_memory_limit('admin');
1439 - if (get_option('e2pdf_api_protocol', '0') == '1') {
1440 - $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;
1441 1429 } else {
1442 - $upload = base64_encode(file_get_contents($pdf['tmp_name']));
1430 + $upload = base64_encode(file_get_contents($file['tmp_name']));
1443 1431 }
1444 1432
1445 1433 $model_e2pdf_api = new Model_E2pdf_Api();
1446 1434 $model_e2pdf_api->set(
@@ -1446,9 +1434,9 @@
1446 1434 $model_e2pdf_api->set(
1447 1435 array(
1448 1436 'action' => 'template/upload2',
1449 1437 'data' => array(
1450 - 'title' => $name,
1438 + 'title' => $file['name'],
1451 1439 'pdf' => $upload,
1452 1440 ),
1453 1441 )
1454 1442 );
@@ -1474,10 +1462,17 @@
1474 1462 $pdf_dir = $this->helper->get('pdf_dir') . $pdf_name . '/';
1475 1463 $pdf_images_dir = $pdf_dir . 'images/';
1476 1464 $this->helper->create_dir($pdf_dir);
1477 1465 $this->helper->create_dir($pdf_images_dir);
1478 - move_uploaded_file($pdf['tmp_name'], $pdf_dir . $pdf_name . '.pdf');
1479 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 +
1480 1475 try {
1481 1476 $xml_template = [];
1482 1477 $pages = [];
1483 1478 if (class_exists('XMLReader')) {
@@ -1511,10 +1506,10 @@
1511 1506 $this->helper->load('xml')->parse_xml_page($page_node, $pages, $pdf_images_dir, $extension);
1512 1507 break;
1513 1508 case 'fonts':
1514 1509 $fonts_node = new SimpleXMLElement($reader->readOuterXML(), LIBXML_PARSEHUGE);
1515 - foreach ($fonts_node->children() as $font) {
1516 - $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);
1517 1512 }
1518 1513 break;
1519 1514 default:
1520 1515 break;
@@ -1548,10 +1543,10 @@
1548 1543 'font_color' => (string) $xml->template->font_color,
1549 1544 ];
1550 1545 }
1551 1546 if (isset($xml->fonts) && $xml->fonts) {
1552 - foreach ($xml->fonts->children() as $key => $font) {
1553 - $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);
1554 1549 }
1555 1550 }
1556 1551 }
1557 1552
@@ -1662,37 +1657,22 @@
1662 1657 if (!$template_id) {
1663 1658 return false;
1664 1659 }
1665 1660
1666 - $pdf = $this->files->get('pdf');
1667 - $name = strtolower($pdf['name']);
1668 - $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
1669 -
1670 - if (!empty($pdf['error'])) {
1661 + $file = $this->helper->load('files')->upload($this->files->get('pdf'), ['pdf'], ['application/pdf']);
1662 + if (isset($file['error'])) {
1671 1663 $this->json_response(
1672 1664 [
1673 - 'error' => $pdf['error'],
1665 + 'error' => $file['error'],
1674 1666 ]
1675 1667 );
1676 - } elseif (!in_array($ext, array('pdf'))) {
1677 - $this->json_response(
1678 - [
1679 - 'error' => sprintf(__('Only %s files allowed', 'e2pdf'), '.pdf'),
1680 - ]
1681 - );
1682 - } elseif ($pdf['type'] != 'application/pdf') {
1683 - $this->json_response(
1684 - [
1685 - 'error' => __('Invalid Type', 'e2pdf'),
1686 - ]
1687 - );
1688 1668 }
1689 1669
1690 1670 wp_raise_memory_limit('admin');
1691 - if (get_option('e2pdf_api_protocol', '0') == '1') {
1692 - $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;
1693 1673 } else {
1694 - $upload = base64_encode(file_get_contents($pdf['tmp_name']));
1674 + $upload = base64_encode(file_get_contents($file['tmp_name']));
1695 1675 }
1696 1676
1697 1677 $model_e2pdf_api = new Model_E2pdf_Api();
1698 1678 $model_e2pdf_api->set(
@@ -1698,9 +1678,9 @@
1698 1678 $model_e2pdf_api->set(
1699 1679 array(
1700 1680 'action' => 'template/upload2',
1701 1681 'data' => array(
1702 - 'title' => $name,
1682 + 'title' => $file['name'],
1703 1683 'pdf' => $upload,
1704 1684 ),
1705 1685 )
1706 1686 );
@@ -1733,10 +1713,17 @@
1733 1713 $pdf_dir = $this->helper->get('pdf_dir') . $pdf_name . '/';
1734 1714 $pdf_images_dir = $pdf_dir . 'images/';
1735 1715 $this->helper->create_dir($pdf_dir);
1736 1716 $this->helper->create_dir($pdf_images_dir);
1737 - move_uploaded_file($pdf['tmp_name'], $pdf_dir . $pdf_name . '.pdf');
1738 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 +
1739 1726 try {
1740 1727 $pages = [];
1741 1728 $pos_pages = [];
1742 1729 if (class_exists('XMLReader')) {
@@ -2157,10 +2144,9 @@
2157 2144 $limit_condition = array();
2158 2145 if (!$count) {
2159 2146 $paged = isset($filters['paged']) && $filters['paged'] ? $filters['paged'] : '0';
2160 2147 $paged = (int) $paged <= 0 ? 1 : (int) $paged;
2161 - $per_page = get_option('e2pdf_templates_screen_per_page', '20');
2162 -
2148 + $per_page = (int) get_option('e2pdf_templates_screen_per_page', '20');
2163 2149 $limit_condition = array(
2164 2150 'limit' => (int) $per_page,
2165 2151 'offset' => (int) ($paged - 1) * $per_page,
2166 2152 );