Changeset 3356360
- Timestamp:
- 09/04/2025 10:40:44 PM (4 months ago)
- Location:
- wc-purchase-orders
- Files:
-
- 4 edited
-
tags/1.0.3/includes/class-bbpo-purchase-orders-files.php (modified) (8 diffs)
-
tags/1.0.3/public/js/wc-purchase-orders-public.js (modified) (3 diffs)
-
trunk/includes/class-bbpo-purchase-orders-files.php (modified) (8 diffs)
-
trunk/public/js/wc-purchase-orders-public.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wc-purchase-orders/tags/1.0.3/includes/class-bbpo-purchase-orders-files.php
r3354271 r3356360 1 1 <?php 2 /** 3 * The file that defines the purchase orders file handler. 4 * 5 * @package BBPO_Purchase_Orders 6 */ 7 2 8 if ( ! defined( 'ABSPATH' ) ) { 3 exit; // Exit if accessed directly 9 exit; // Exit if accessed directly. 4 10 } 11 5 12 /** 6 13 * The purchase orders file handler. 7 14 * 8 15 * @since 1.0.0 9 * @package Woocommerce_Payment_Processor10 * @subpackage Woocommerce_Payment_Processor/includes11 * @author A HMAD WAEL<[email protected]>16 * @package BBPO_Purchase_Orders 17 * @subpackage BBPO_Purchase_Orders/includes 18 * @author Ahmad Wael <[email protected]> 12 19 */ 13 20 class BBPO_Purchase_Orders_Files { … … 70 77 public function file_upload() { 71 78 if ( isset( $_POST['nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'wcpo-nonce' ) ) { 72 $current_year = date( 'Y' );73 $current_month = date( 'm' );79 $current_year = gmdate( 'Y' ); 80 $current_month = gmdate( 'm' ); 74 81 $allowed = array( 75 82 'application/msword' => 'doc', … … 78 85 ); 79 86 if ( ! isset( $_FILES['wcpo-document-file'] ) ) { 80 wp_send_json_error(87 $this->send_error_signal( 81 88 array( 82 89 'code' => 'file_not_provided', … … 85 92 ); 86 93 } 94 if ( ! isset( $_FILES['wcpo-document-file']['type'] ) ) { 95 $this->send_error_signal( 96 array( 97 'code' => 'file_type_not_provided', 98 'message' => esc_html__( 'This file you are trying to upload is missing!', 'wc-purchase-orders' ), 99 ) 100 ); 101 } 102 if ( ! isset( $_FILES['wcpo-document-file']['size'] ) ) { 103 $this->send_error_signal( 104 array( 105 'code' => 'file_size_not_provided', 106 'message' => esc_html__( 'This file size you are trying to upload is missing!', 'wc-purchase-orders' ), 107 ) 108 ); 109 } 87 110 if ( ! in_array( $_FILES['wcpo-document-file']['type'], array_keys( $allowed ), true ) ) { 88 wp_send_json_error(111 $this->send_error_signal( 89 112 array( 90 113 'code' => 'file_not_allowed', … … 94 117 } 95 118 if ( $_FILES['wcpo-document-file']['size'] > 2097152 ) { // 2 MB (size is also in bytes) 96 wp_send_json_error(119 $this->send_error_signal( 97 120 array( 98 121 'code' => 'file_too_big', … … 121 144 $new_file_path = $path . $file_name; 122 145 rename( $file['file'], $new_file_path ); 123 wp_send_json_success(146 $this->send_success_signal( 124 147 array( 125 148 'file_url' => $upload_dir['baseurl'] . $dir . $file_name, 126 149 'file_path' => $dir . $file_name, 127 150 'file_type' => sanitize_text_field( $allowed[ $_FILES['wcpo-document-file']['type'] ] ), 128 ) 129 ); 130 } 131 wp_send_json_error( 151 'file_name' => $file_name, 152 ) 153 ); 154 } 155 $this->send_error_signal( 132 156 array( 133 157 'code' => 'file_error', … … 136 160 ); 137 161 } 138 wp_send_json_error(162 $this->send_error_signal( 139 163 array( 140 164 'code' => 'nonce_failed', … … 151 175 public function delete_file() { 152 176 if ( isset( $_REQUEST['nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ), 'wcpo-nonce' ) ) { 153 if ( empty( $_POST['file_path'] ) ) { 154 wp_send_json_error( 155 array( 156 'code' => 'file_path_required', 157 'message' => esc_html__( 'File path is required', 'wc-purchase-orders' ), 158 ) 159 ); 160 } 161 162 $file_path = wp_upload_dir()['basedir'] . sanitize_text_field( $_POST['file_path'] ); 177 if ( empty( $_POST['file_name'] ) ) { 178 $this->send_error_signal( 179 array( 180 'code' => 'file_name_required', 181 'message' => esc_html__( 'File name is required', 'wc-purchase-orders' ), 182 ) 183 ); 184 } 185 186 $upload_dir = wp_upload_dir(); 187 $current_year = gmdate( 'Y' ); 188 $current_month = gmdate( 'm' ); 189 $dir = DIRECTORY_SEPARATOR . 'wc-purchase-orders' . DIRECTORY_SEPARATOR . $current_year . DIRECTORY_SEPARATOR . $current_month . DIRECTORY_SEPARATOR; 190 $file_path = $upload_dir['basedir'] . $dir . sanitize_file_name( wp_unslash( $_POST['file_name'] ) ); 163 191 if ( $this->validate_file_path( $file_path ) ) { 164 192 // delete file. -
wc-purchase-orders/tags/1.0.3/public/js/wc-purchase-orders-public.js
r3354271 r3356360 1 1 (function ($) { 2 2 'use strict'; 3 3 4 let file_name = ''; 5 4 6 // upload purchase order 5 7 $(document).on('change', '#wcpo-document-file', function (e) { … … 25 27 if(response.success) { 26 28 previewArea.empty().show(); 29 file_name = response.data.file_name; 27 30 $('input[name="wcpo-document-file-path"]').val(response.data.file_path); 28 31 previewArea.append('<span class="wcpo-remove">x</span><span>' + file.name + '</span><img src="' + wcpo_object.icons_url + response.data.file_type + '.png">') … … 43 46 $.ajax({ 44 47 type: "post", dataType: "json", url: wcpo_object.ajax_url, data: { 45 action: "wcpo_delete_purchase_order_file", file_path: file.val(), nonce: wcpo_object.nonce 48 action: "wcpo_delete_purchase_order_file", 49 nonce: wcpo_object.nonce, 50 file_name: file_name 46 51 }, success: function (response) { 47 52 file.val('') -
wc-purchase-orders/trunk/includes/class-bbpo-purchase-orders-files.php
r3354271 r3356360 1 1 <?php 2 /** 3 * The file that defines the purchase orders file handler. 4 * 5 * @package BBPO_Purchase_Orders 6 */ 7 2 8 if ( ! defined( 'ABSPATH' ) ) { 3 exit; // Exit if accessed directly 9 exit; // Exit if accessed directly. 4 10 } 11 5 12 /** 6 13 * The purchase orders file handler. 7 14 * 8 15 * @since 1.0.0 9 * @package Woocommerce_Payment_Processor10 * @subpackage Woocommerce_Payment_Processor/includes11 * @author A HMAD WAEL<[email protected]>16 * @package BBPO_Purchase_Orders 17 * @subpackage BBPO_Purchase_Orders/includes 18 * @author Ahmad Wael <[email protected]> 12 19 */ 13 20 class BBPO_Purchase_Orders_Files { … … 70 77 public function file_upload() { 71 78 if ( isset( $_POST['nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'wcpo-nonce' ) ) { 72 $current_year = date( 'Y' );73 $current_month = date( 'm' );79 $current_year = gmdate( 'Y' ); 80 $current_month = gmdate( 'm' ); 74 81 $allowed = array( 75 82 'application/msword' => 'doc', … … 78 85 ); 79 86 if ( ! isset( $_FILES['wcpo-document-file'] ) ) { 80 wp_send_json_error(87 $this->send_error_signal( 81 88 array( 82 89 'code' => 'file_not_provided', … … 85 92 ); 86 93 } 94 if ( ! isset( $_FILES['wcpo-document-file']['type'] ) ) { 95 $this->send_error_signal( 96 array( 97 'code' => 'file_type_not_provided', 98 'message' => esc_html__( 'This file you are trying to upload is missing!', 'wc-purchase-orders' ), 99 ) 100 ); 101 } 102 if ( ! isset( $_FILES['wcpo-document-file']['size'] ) ) { 103 $this->send_error_signal( 104 array( 105 'code' => 'file_size_not_provided', 106 'message' => esc_html__( 'This file size you are trying to upload is missing!', 'wc-purchase-orders' ), 107 ) 108 ); 109 } 87 110 if ( ! in_array( $_FILES['wcpo-document-file']['type'], array_keys( $allowed ), true ) ) { 88 wp_send_json_error(111 $this->send_error_signal( 89 112 array( 90 113 'code' => 'file_not_allowed', … … 94 117 } 95 118 if ( $_FILES['wcpo-document-file']['size'] > 2097152 ) { // 2 MB (size is also in bytes) 96 wp_send_json_error(119 $this->send_error_signal( 97 120 array( 98 121 'code' => 'file_too_big', … … 121 144 $new_file_path = $path . $file_name; 122 145 rename( $file['file'], $new_file_path ); 123 wp_send_json_success(146 $this->send_success_signal( 124 147 array( 125 148 'file_url' => $upload_dir['baseurl'] . $dir . $file_name, 126 149 'file_path' => $dir . $file_name, 127 150 'file_type' => sanitize_text_field( $allowed[ $_FILES['wcpo-document-file']['type'] ] ), 128 ) 129 ); 130 } 131 wp_send_json_error( 151 'file_name' => $file_name, 152 ) 153 ); 154 } 155 $this->send_error_signal( 132 156 array( 133 157 'code' => 'file_error', … … 136 160 ); 137 161 } 138 wp_send_json_error(162 $this->send_error_signal( 139 163 array( 140 164 'code' => 'nonce_failed', … … 151 175 public function delete_file() { 152 176 if ( isset( $_REQUEST['nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ), 'wcpo-nonce' ) ) { 153 if ( empty( $_POST['file_path'] ) ) { 154 wp_send_json_error( 155 array( 156 'code' => 'file_path_required', 157 'message' => esc_html__( 'File path is required', 'wc-purchase-orders' ), 158 ) 159 ); 160 } 161 162 $file_path = wp_upload_dir()['basedir'] . sanitize_text_field( $_POST['file_path'] ); 177 if ( empty( $_POST['file_name'] ) ) { 178 $this->send_error_signal( 179 array( 180 'code' => 'file_name_required', 181 'message' => esc_html__( 'File name is required', 'wc-purchase-orders' ), 182 ) 183 ); 184 } 185 186 $upload_dir = wp_upload_dir(); 187 $current_year = gmdate( 'Y' ); 188 $current_month = gmdate( 'm' ); 189 $dir = DIRECTORY_SEPARATOR . 'wc-purchase-orders' . DIRECTORY_SEPARATOR . $current_year . DIRECTORY_SEPARATOR . $current_month . DIRECTORY_SEPARATOR; 190 $file_path = $upload_dir['basedir'] . $dir . sanitize_file_name( wp_unslash( $_POST['file_name'] ) ); 163 191 if ( $this->validate_file_path( $file_path ) ) { 164 192 // delete file. -
wc-purchase-orders/trunk/public/js/wc-purchase-orders-public.js
r2990096 r3356360 1 1 (function ($) { 2 2 'use strict'; 3 3 4 let file_name = ''; 5 4 6 // upload purchase order 5 7 $(document).on('change', '#wcpo-document-file', function (e) { … … 25 27 if(response.success) { 26 28 previewArea.empty().show(); 29 file_name = response.data.file_name; 27 30 $('input[name="wcpo-document-file-path"]').val(response.data.file_path); 28 31 previewArea.append('<span class="wcpo-remove">x</span><span>' + file.name + '</span><img src="' + wcpo_object.icons_url + response.data.file_type + '.png">') … … 43 46 $.ajax({ 44 47 type: "post", dataType: "json", url: wcpo_object.ajax_url, data: { 45 action: "wcpo_delete_purchase_order_file", file_path: file.val(), nonce: wcpo_object.nonce 48 action: "wcpo_delete_purchase_order_file", 49 nonce: wcpo_object.nonce, 50 file_name: file_name 46 51 }, success: function (response) { 47 52 file.val('')
Note: See TracChangeset
for help on using the changeset viewer.