Plugin Directory

Changeset 2785196


Ignore:
Timestamp:
09/15/2022 09:21:30 AM (4 years ago)
Author:
shindhl
Message:

Release 3.0.1 (DHL Parcel)

  • DHL Parcel: Updated label downloads to now serve from the temporary folder instead of the public folder for additional security and storage usage
Location:
dhl-for-woocommerce
Files:
11 edited
1 copied

Legend:

Unmodified
Added
Removed
  • dhl-for-woocommerce/tags/3.0.1/dhlpwoocommerce/README.md

    r2777070 r2785196  
    11# DHL Parcel for WooCommerce
     2 
     3v2.0.7
     4## Changes
     5- Added a new service option: Secure delivery by code
     6- Added an option to show Same Day Delivery as a separate shipping method when delivery times are enabled
    27 
    38v2.0.6
  • dhl-for-woocommerce/tags/3.0.1/dhlpwoocommerce/dhlpwoocommerce.php

    r2777070 r2785196  
    55 * Description:          This is the official DHL Parcel for WooCommerce plugin.
    66 * Author:               DHL Parcel
    7  * Version:              2.0.7
     7 * Version:              2.0.8
    88 * Requires at least:    4.7.16
    99 * Tested up to:         6.0
  • dhl-for-woocommerce/tags/3.0.1/dhlpwoocommerce/includes/controller/admin/class-dhlpwc-controller-admin-order.php

    r2551455 r2785196  
    5656            add_action('admin_notices', array($this, 'bulk_create_notice'));
    5757        }
     58
     59        add_action('admin_action_dhlpwc_download_label', array($this, 'download_label'));
    5860
    5961        if ($service->check(DHLPWC_Model_Service_Access_Control::ACCESS_BULK_DOWNLOAD)) {
     
    284286    }
    285287
     288    public function download_label()
     289    {
     290        $label_id = isset($_GET['label_id']) && is_string($_GET['label_id']) ? wc_clean($_GET['label_id']) : null;
     291
     292        if (!$label_id) {
     293            wp_redirect('');
     294        }
     295
     296        $service = DHLPWC_Model_Service_Label::instance();
     297        $path = $service->single($label_id);
     298
     299        if (!$path) {
     300            wp_redirect('');
     301        }
     302
     303        $file = explode(DIRECTORY_SEPARATOR, $path);
     304        header('Content-type: application/pdf');
     305        header('Content-Disposition: attachment; filename="'.end($file).'"');
     306        header('Cache-Control: must-revalidate');
     307        header('Content-Length: ' . filesize($path));
     308        readfile($path);
     309        exit;
     310    }
     311
    286312    public function add_bulk_download_action($bulk_actions)
    287313    {
     
    295321
    296322        $service = DHLPWC_Model_Service_Label::instance();
    297         $url = $service->combine($order_ids);
    298 
    299         if (!$url) {
     323        $path = $service->combine($order_ids);
     324
     325        if (!$path) {
    300326            wp_redirect('');
    301327        }
    302328
    303         wp_redirect($url);
     329        $file = explode(DIRECTORY_SEPARATOR, $path);
     330        header('Content-type: application/pdf');
     331        header('Content-Disposition: attachment; filename="'.end($file).'"');
     332        header('Cache-Control: must-revalidate');
     333        header('Content-Length: ' . filesize($path));
     334        readfile($path);
    304335        exit;
    305336    }
     
    417448                    }
    418449                    $is_return = (!empty($label['is_return'])) ? $label['is_return'] : false;
     450                    $logic = DHLPWC_Model_Logic_Label::instance();
    419451
    420452                    $view->render(array(
    421                         'url'               => $label['pdf']['url'],
     453                        'url'               => $logic->get_pdf_url($label),
    422454                        'label_size'        => $label['label_size'],
    423455                        'label_description' => DHLPWC_Model_Service_Translation::instance()->parcelType($label['label_size']),
  • dhl-for-woocommerce/tags/3.0.1/dhlpwoocommerce/includes/model/logic/class-dhlpwc-model-logic-label.php

    r2519608 r2785196  
    1111    const BATCH_FILE_PREFIX = 'dhlpwc-labels-';
    1212
    13     public function create_pdf_file($order_id, $base64_pdf)
     13    public function single_pdf($label_id)
    1414    {
    15         $pdf = base64_decode($base64_pdf);
    16         $file_name = self::FILE_PREFIX . $order_id . '_' . str_shuffle((string)time() . rand(1000, 9999)) . '.pdf';
    17         $upload_path = wp_upload_dir();
    18         $path = $upload_path['path'] . DIRECTORY_SEPARATOR . $file_name;
    19         $url = $upload_path['url'] . '/' . $file_name;
     15        $connector = DHLPWC_Model_API_Connector::instance();
     16        $label = $connector->get(sprintf('labels/%s', $label_id));
     17
     18        $pdf = base64_decode($label['pdf']);
     19        $file_name = self::FILE_PREFIX . rand(100000, 999999) . '_' . str_shuffle((string)time() . rand(1000, 9999)) . '.pdf';
     20        $upload_path = get_temp_dir();
     21        $path = $upload_path . DIRECTORY_SEPARATOR . $file_name;
    2022
    2123        // TODO, handle errors
     
    2325        file_put_contents($path, $pdf);
    2426
    25         return array(
    26             'url' => $url,
    27             'path' => $path
    28         );
     27        return $path;
     28    }
     29
     30    public function get_pdf_url($label)
     31    {
     32        if (isset($label['pdf']) && isset($label['pdf']['url']) && isset($label['pdf']['path'])) {
     33            $path = $label['pdf']['path'];
     34            if (!$this->validate_pdf_file($path)) {
     35                // Attempt to fix path
     36                $path = $this->restore_pdf_path($path);
     37            }
     38            if ($this->validate_pdf_file($path)) {
     39                return $label['pdf']['url'];
     40            }
     41        }
     42
     43        if (isset($label['label_id'])) {
     44            // Not found
     45            admin_url('edit.php?post_type=shop_order');
     46        }
     47
     48        return admin_url('edit.php?post_type=shop_order&action=dhlpwc_download_label&label_id='.$label['label_id']);
     49
    2950    }
    3051
     
    5475
    5576        $file_name = self::BATCH_FILE_PREFIX . $order_id_tag . '_' . str_shuffle((string)time() . rand(1000, 9999)) . '.pdf';
    56         $upload_dir = wp_upload_dir();
    57         $path = $upload_dir['path'] . DIRECTORY_SEPARATOR . $file_name;
    58         $url = $upload_dir['url'] . '/' . $file_name;
     77        $upload_dir = get_temp_dir();
     78        $path = $upload_dir . DIRECTORY_SEPARATOR . $file_name;
    5979
    6080        $response = $connector->stream('labels/multi', $path, array(
     
    6888        }
    6989
    70         return array(
    71             'url' => $url,
    72             'path' => $path
    73         );
     90        return $path;
    7491    }
    7592
  • dhl-for-woocommerce/tags/3.0.1/dhlpwoocommerce/includes/model/service/class-dhlpwc-model-service-label-metabox.php

    r2777070 r2785196  
    306306            $debug_label_requests = $service->check(DHLPWC_Model_Service_Access_Control::ACCESS_LABEL_REQUEST);
    307307
     308            $logic = DHLPWC_Model_Logic_Label::instance();
     309
    308310            $actions = array();
    309311            $actions[] = array(
    310                 'url'    => $label['pdf']['url'],
     312                'url'    => $logic->get_pdf_url($label),
    311313                'name'   => __('Download PDF label', 'dhlpwc'),
    312314                'action' => "dhlpwc_action_download",
  • dhl-for-woocommerce/tags/3.0.1/dhlpwoocommerce/includes/model/service/class-dhlpwc-model-service-label.php

    r2519608 r2785196  
    1010class DHLPWC_Model_Service_Label extends DHLPWC_Model_Core_Singleton_Abstract
    1111{
     12
     13    public function single($label_id)
     14    {
     15        if (empty($label_id)) {
     16            return null;
     17        }
     18
     19        $logic = DHLPWC_Model_Logic_Label::instance();
     20        $path = $logic->single_pdf($label_id);
     21
     22        if (!$path) {
     23            return null;
     24        }
     25
     26        return $path;
     27    }
    1228
    1329    public function combine($order_ids)
     
    2440        switch ($bulk_combine) {
    2541            case DHLPWC_Model_WooCommerce_Settings_Shipping_Method::COMBINE_A4:
    26                 $combined = $logic->combine_pdfs($order_ids, 'L', 3);
     42                $path = $logic->combine_pdfs($order_ids, 'L', 3);
    2743                break;
    2844            default:
    29                 $combined = $logic->combine_pdfs($order_ids);
     45                $path = $logic->combine_pdfs($order_ids);
    3046        }
    3147
    32         if (!$combined) {
     48        if (!$path) {
    3349            return null;
    3450        }
    3551
    36         return $combined['url'];
     52        return $path;
    3753    }
    3854
  • dhl-for-woocommerce/tags/3.0.1/dhlpwoocommerce/includes/model/service/class-dhlpwc-model-service-shipment.php

    r2757781 r2785196  
    9999        }
    100100
    101         $label_logic = DHLPWC_Model_Logic_Label::instance();
    102         $pdf_info = $label_logic->create_pdf_file($order_id, $label['pdf']);
    103 
    104101        $label_data = array(
    105102            'label_id' => $label['labelId'],
     
    107104            'label_size' => $label_size,
    108105            'tracker_code' => $label['trackerCode'],
    109             'routing_code' => $label['routingCode'],
     106            'routing_code' => null,
    110107            'order_reference' => $label['orderReference'],
    111 
    112             'pdf' => array(
    113                 'url' => $pdf_info['url'],
    114                 'path' => $pdf_info['path'],
    115             )
    116108        );
    117109
     
    146138            }
    147139
    148             $return_pdf_info = $label_logic->create_pdf_file($order_id, $return_label['pdf']);
    149 
    150140            $label_data = array(
    151141                'label_id' => $return_label['labelId'],
     
    153143                'label_size' => $label_size,
    154144                'tracker_code' => $return_label['trackerCode'],
    155                 'routing_code' => $return_label['routingCode'],
     145                'routing_code' => null,
    156146                'order_reference' => $return_label['orderReference'],
    157147                'is_return' => true,
    158 
    159                 'pdf' => array(
    160                     'url' => $return_pdf_info['url'],
    161                     'path' => $return_pdf_info['path'],
    162                 ),
    163148            );
    164149
     
    185170    {
    186171        // TODO currently the code handles single pieces, but can be expanded for multiple pieces in the future
    187         $current_label_id = null;
    188 
    189         if (!empty($response['pieces'])) {
    190             foreach($response['pieces'] as $label_response) {
    191                 if (!empty($label_response['labelId'])) {
    192                     $current_label_id = $label_response['labelId'];
    193                 }
    194             }
    195         }
    196 
    197         if (!$current_label_id) {
    198             return false;
    199         }
    200 
    201         $connector = DHLPWC_Model_API_Connector::instance();
    202         $label = $connector->get(sprintf('labels/%s', $current_label_id));
     172        if (empty($response['pieces'])) {
     173            return false;
     174        }
     175
     176        foreach($response['pieces'] as $label_response) {
     177            if (!empty($label_response['labelId'])) {
     178                $label = $label_response;
     179            }
     180        }
     181
     182        if (empty($label)) {
     183            return false;
     184        }
    203185
    204186        return $label;
  • dhl-for-woocommerce/tags/3.0.1/dhlpwoocommerce/readme.txt

    r2777070 r2785196  
    55Requires PHP:         5.6
    66Tested up to:         5.9
    7 Stable tag:           2.0.7
     7Stable tag:           2.0.8
    88WC requires at least: 3.0.0
    99WC tested up to:      5.3.0
     
    5353
    5454== Changelog ==
     55 
     56= 2.0.7 =
     57- Added a new service option: Secure delivery by code
     58- Added an option to show Same Day Delivery as a separate shipping method when delivery times are enabled
    5559 
    5660= 2.0.6 =
  • dhl-for-woocommerce/tags/3.0.1/pr-dhl-woocommerce.php

    r2780526 r2785196  
    88 * Text Domain: dhl-for-woocommerce
    99 * Domain Path: /lang
    10  * Version: 3.0.0
     10 * Version: 3.0.1
    1111 * Tested up to: 6.0
    1212 * WC requires at least: 3.0
     
    3737class PR_DHL_WC {
    3838
    39     private $version = "3.0.0";
     39    private $version = "3.0.1";
    4040
    4141    /**
  • dhl-for-woocommerce/tags/3.0.1/readme.txt

    r2780526 r2785196  
    66Requires PHP: 5.6
    77Tested up to: 6.0
    8 Stable tag: 3.0.0
     8Stable tag: 3.0.1
    99WC requires at least: 3.0
    1010WC tested up to: 6.6
     
    7777
    7878== Changelog ==
     79 
     80= 3.0.1 =
     81* DHL Parcel: Updated label downloads to now serve from the temporary folder instead of the public folder for additional security and storage usage
    7982 
    8083= 3.0.0 =
  • dhl-for-woocommerce/trunk/readme.txt

    r2780526 r2785196  
    66Requires PHP: 5.6
    77Tested up to: 4.8.2
    8 Stable tag: 3.0.0
     8Stable tag: 3.0.1
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.