Changeset 2785195
- Timestamp:
- 09/15/2022 09:21:16 AM (4 years ago)
- Location:
- dhlpwc
- Files:
-
- 16 edited
- 1 copied
-
tags/2.0.8 (copied) (copied from dhlpwc/trunk)
-
tags/2.0.8/README.md (modified) (1 diff)
-
tags/2.0.8/dhlpwoocommerce.php (modified) (1 diff)
-
tags/2.0.8/includes/controller/admin/class-dhlpwc-controller-admin-order.php (modified) (4 diffs)
-
tags/2.0.8/includes/model/logic/class-dhlpwc-model-logic-label.php (modified) (4 diffs)
-
tags/2.0.8/includes/model/service/class-dhlpwc-model-service-label-metabox.php (modified) (1 diff)
-
tags/2.0.8/includes/model/service/class-dhlpwc-model-service-label.php (modified) (2 diffs)
-
tags/2.0.8/includes/model/service/class-dhlpwc-model-service-shipment.php (modified) (5 diffs)
-
tags/2.0.8/readme.txt (modified) (2 diffs)
-
trunk/README.md (modified) (1 diff)
-
trunk/dhlpwoocommerce.php (modified) (1 diff)
-
trunk/includes/controller/admin/class-dhlpwc-controller-admin-order.php (modified) (4 diffs)
-
trunk/includes/model/logic/class-dhlpwc-model-logic-label.php (modified) (4 diffs)
-
trunk/includes/model/service/class-dhlpwc-model-service-label-metabox.php (modified) (1 diff)
-
trunk/includes/model/service/class-dhlpwc-model-service-label.php (modified) (2 diffs)
-
trunk/includes/model/service/class-dhlpwc-model-service-shipment.php (modified) (5 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dhlpwc/tags/2.0.8/README.md
r2777069 r2785195 1 1 # DHL Parcel for WooCommerce 2 3 v2.0.8 4 ## Changes 5 - Updated label downloads to now serve from the temporary folder instead of the public folder for additional security and storage usage 2 6 3 7 v2.0.7 -
dhlpwc/tags/2.0.8/dhlpwoocommerce.php
r2777069 r2785195 5 5 * Description: This is the official DHL Parcel for WooCommerce plugin. 6 6 * Author: DHL Parcel 7 * Version: 2.0. 77 * Version: 2.0.8 8 8 * Requires at least: 4.7.16 9 9 * Tested up to: 6.0 -
dhlpwc/tags/2.0.8/includes/controller/admin/class-dhlpwc-controller-admin-order.php
r2688414 r2785195 56 56 add_action('admin_notices', array($this, 'bulk_create_notice')); 57 57 } 58 59 add_action('admin_action_dhlpwc_download_label', array($this, 'download_label')); 58 60 59 61 if ($service->check(DHLPWC_Model_Service_Access_Control::ACCESS_BULK_DOWNLOAD)) { … … 284 286 } 285 287 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 286 312 public function add_bulk_download_action($bulk_actions) 287 313 { … … 295 321 296 322 $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) { 300 326 wp_redirect(''); 301 327 } 302 328 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); 304 335 exit; 305 336 } … … 417 448 } 418 449 $is_return = (!empty($label['is_return'])) ? $label['is_return'] : false; 450 $logic = DHLPWC_Model_Logic_Label::instance(); 419 451 420 452 $view->render(array( 421 'url' => $l abel['pdf']['url'],453 'url' => $logic->get_pdf_url($label), 422 454 'label_size' => $label['label_size'], 423 455 'label_description' => DHLPWC_Model_Service_Translation::instance()->parcelType($label['label_size']), -
dhlpwc/tags/2.0.8/includes/model/logic/class-dhlpwc-model-logic-label.php
r2688414 r2785195 11 11 const BATCH_FILE_PREFIX = 'dhlpwc-labels-'; 12 12 13 public function create_pdf_file($order_id, $base64_pdf)13 public function single_pdf($label_id) 14 14 { 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; 20 22 21 23 // TODO, handle errors … … 23 25 file_put_contents($path, $pdf); 24 26 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 29 50 } 30 51 … … 54 75 55 76 $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; 59 79 60 80 $response = $connector->stream('labels/multi', $path, array( … … 68 88 } 69 89 70 return array( 71 'url' => $url, 72 'path' => $path 73 ); 90 return $path; 74 91 } 75 92 -
dhlpwc/tags/2.0.8/includes/model/service/class-dhlpwc-model-service-label-metabox.php
r2777069 r2785195 306 306 $debug_label_requests = $service->check(DHLPWC_Model_Service_Access_Control::ACCESS_LABEL_REQUEST); 307 307 308 $logic = DHLPWC_Model_Logic_Label::instance(); 309 308 310 $actions = array(); 309 311 $actions[] = array( 310 'url' => $l abel['pdf']['url'],312 'url' => $logic->get_pdf_url($label), 311 313 'name' => __('Download PDF label', 'dhlpwc'), 312 314 'action' => "dhlpwc_action_download", -
dhlpwc/tags/2.0.8/includes/model/service/class-dhlpwc-model-service-label.php
r2688414 r2785195 10 10 class DHLPWC_Model_Service_Label extends DHLPWC_Model_Core_Singleton_Abstract 11 11 { 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 } 12 28 13 29 public function combine($order_ids) … … 24 40 switch ($bulk_combine) { 25 41 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); 27 43 break; 28 44 default: 29 $ combined= $logic->combine_pdfs($order_ids);45 $path = $logic->combine_pdfs($order_ids); 30 46 } 31 47 32 if (!$ combined) {48 if (!$path) { 33 49 return null; 34 50 } 35 51 36 return $ combined['url'];52 return $path; 37 53 } 38 54 -
dhlpwc/tags/2.0.8/includes/model/service/class-dhlpwc-model-service-shipment.php
r2757780 r2785195 99 99 } 100 100 101 $label_logic = DHLPWC_Model_Logic_Label::instance();102 $pdf_info = $label_logic->create_pdf_file($order_id, $label['pdf']);103 104 101 $label_data = array( 105 102 'label_id' => $label['labelId'], … … 107 104 'label_size' => $label_size, 108 105 'tracker_code' => $label['trackerCode'], 109 'routing_code' => $label['routingCode'],106 'routing_code' => null, 110 107 'order_reference' => $label['orderReference'], 111 112 'pdf' => array(113 'url' => $pdf_info['url'],114 'path' => $pdf_info['path'],115 )116 108 ); 117 109 … … 146 138 } 147 139 148 $return_pdf_info = $label_logic->create_pdf_file($order_id, $return_label['pdf']);149 150 140 $label_data = array( 151 141 'label_id' => $return_label['labelId'], … … 153 143 'label_size' => $label_size, 154 144 'tracker_code' => $return_label['trackerCode'], 155 'routing_code' => $return_label['routingCode'],145 'routing_code' => null, 156 146 'order_reference' => $return_label['orderReference'], 157 147 'is_return' => true, 158 159 'pdf' => array(160 'url' => $return_pdf_info['url'],161 'path' => $return_pdf_info['path'],162 ),163 148 ); 164 149 … … 185 170 { 186 171 // 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 } 203 185 204 186 return $label; -
dhlpwc/tags/2.0.8/readme.txt
r2777069 r2785195 5 5 Requires PHP: 5.6 6 6 Tested up to: 5.9 7 Stable tag: 2.0. 77 Stable tag: 2.0.8 8 8 WC requires at least: 3.0.0 9 9 WC tested up to: 5.3.0 … … 53 53 54 54 == Changelog == 55 56 = 2.0.8 = 57 - Updated label downloads to now serve from the temporary folder instead of the public folder for additional security and storage usage 55 58 56 59 = 2.0.7 = -
dhlpwc/trunk/README.md
r2777069 r2785195 1 1 # DHL Parcel for WooCommerce 2 3 v2.0.8 4 ## Changes 5 - Updated label downloads to now serve from the temporary folder instead of the public folder for additional security and storage usage 2 6 3 7 v2.0.7 -
dhlpwc/trunk/dhlpwoocommerce.php
r2777069 r2785195 5 5 * Description: This is the official DHL Parcel for WooCommerce plugin. 6 6 * Author: DHL Parcel 7 * Version: 2.0. 77 * Version: 2.0.8 8 8 * Requires at least: 4.7.16 9 9 * Tested up to: 6.0 -
dhlpwc/trunk/includes/controller/admin/class-dhlpwc-controller-admin-order.php
r2688414 r2785195 56 56 add_action('admin_notices', array($this, 'bulk_create_notice')); 57 57 } 58 59 add_action('admin_action_dhlpwc_download_label', array($this, 'download_label')); 58 60 59 61 if ($service->check(DHLPWC_Model_Service_Access_Control::ACCESS_BULK_DOWNLOAD)) { … … 284 286 } 285 287 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 286 312 public function add_bulk_download_action($bulk_actions) 287 313 { … … 295 321 296 322 $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) { 300 326 wp_redirect(''); 301 327 } 302 328 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); 304 335 exit; 305 336 } … … 417 448 } 418 449 $is_return = (!empty($label['is_return'])) ? $label['is_return'] : false; 450 $logic = DHLPWC_Model_Logic_Label::instance(); 419 451 420 452 $view->render(array( 421 'url' => $l abel['pdf']['url'],453 'url' => $logic->get_pdf_url($label), 422 454 'label_size' => $label['label_size'], 423 455 'label_description' => DHLPWC_Model_Service_Translation::instance()->parcelType($label['label_size']), -
dhlpwc/trunk/includes/model/logic/class-dhlpwc-model-logic-label.php
r2688414 r2785195 11 11 const BATCH_FILE_PREFIX = 'dhlpwc-labels-'; 12 12 13 public function create_pdf_file($order_id, $base64_pdf)13 public function single_pdf($label_id) 14 14 { 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; 20 22 21 23 // TODO, handle errors … … 23 25 file_put_contents($path, $pdf); 24 26 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 29 50 } 30 51 … … 54 75 55 76 $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; 59 79 60 80 $response = $connector->stream('labels/multi', $path, array( … … 68 88 } 69 89 70 return array( 71 'url' => $url, 72 'path' => $path 73 ); 90 return $path; 74 91 } 75 92 -
dhlpwc/trunk/includes/model/service/class-dhlpwc-model-service-label-metabox.php
r2777069 r2785195 306 306 $debug_label_requests = $service->check(DHLPWC_Model_Service_Access_Control::ACCESS_LABEL_REQUEST); 307 307 308 $logic = DHLPWC_Model_Logic_Label::instance(); 309 308 310 $actions = array(); 309 311 $actions[] = array( 310 'url' => $l abel['pdf']['url'],312 'url' => $logic->get_pdf_url($label), 311 313 'name' => __('Download PDF label', 'dhlpwc'), 312 314 'action' => "dhlpwc_action_download", -
dhlpwc/trunk/includes/model/service/class-dhlpwc-model-service-label.php
r2688414 r2785195 10 10 class DHLPWC_Model_Service_Label extends DHLPWC_Model_Core_Singleton_Abstract 11 11 { 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 } 12 28 13 29 public function combine($order_ids) … … 24 40 switch ($bulk_combine) { 25 41 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); 27 43 break; 28 44 default: 29 $ combined= $logic->combine_pdfs($order_ids);45 $path = $logic->combine_pdfs($order_ids); 30 46 } 31 47 32 if (!$ combined) {48 if (!$path) { 33 49 return null; 34 50 } 35 51 36 return $ combined['url'];52 return $path; 37 53 } 38 54 -
dhlpwc/trunk/includes/model/service/class-dhlpwc-model-service-shipment.php
r2757780 r2785195 99 99 } 100 100 101 $label_logic = DHLPWC_Model_Logic_Label::instance();102 $pdf_info = $label_logic->create_pdf_file($order_id, $label['pdf']);103 104 101 $label_data = array( 105 102 'label_id' => $label['labelId'], … … 107 104 'label_size' => $label_size, 108 105 'tracker_code' => $label['trackerCode'], 109 'routing_code' => $label['routingCode'],106 'routing_code' => null, 110 107 'order_reference' => $label['orderReference'], 111 112 'pdf' => array(113 'url' => $pdf_info['url'],114 'path' => $pdf_info['path'],115 )116 108 ); 117 109 … … 146 138 } 147 139 148 $return_pdf_info = $label_logic->create_pdf_file($order_id, $return_label['pdf']);149 150 140 $label_data = array( 151 141 'label_id' => $return_label['labelId'], … … 153 143 'label_size' => $label_size, 154 144 'tracker_code' => $return_label['trackerCode'], 155 'routing_code' => $return_label['routingCode'],145 'routing_code' => null, 156 146 'order_reference' => $return_label['orderReference'], 157 147 'is_return' => true, 158 159 'pdf' => array(160 'url' => $return_pdf_info['url'],161 'path' => $return_pdf_info['path'],162 ),163 148 ); 164 149 … … 185 170 { 186 171 // 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 } 203 185 204 186 return $label; -
dhlpwc/trunk/readme.txt
r2777069 r2785195 5 5 Requires PHP: 5.6 6 6 Tested up to: 5.9 7 Stable tag: 2.0. 77 Stable tag: 2.0.8 8 8 WC requires at least: 3.0.0 9 9 WC tested up to: 5.3.0 … … 53 53 54 54 == Changelog == 55 56 = 2.0.8 = 57 - Updated label downloads to now serve from the temporary folder instead of the public folder for additional security and storage usage 55 58 56 59 = 2.0.7 =
Note: See TracChangeset
for help on using the changeset viewer.