Plugin Directory

Changeset 3356360


Ignore:
Timestamp:
09/04/2025 10:40:44 PM (4 months ago)
Author:
bbioon
Message:

Security update

Location:
wc-purchase-orders
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • wc-purchase-orders/tags/1.0.3/includes/class-bbpo-purchase-orders-files.php

    r3354271 r3356360  
    11<?php
     2/**
     3 * The file that defines the purchase orders file handler.
     4 *
     5 * @package BBPO_Purchase_Orders
     6 */
     7
    28if ( ! defined( 'ABSPATH' ) ) {
    3     exit; // Exit if accessed directly
     9    exit; // Exit if accessed directly.
    410}
     11
    512/**
    613 * The purchase orders file handler.
    714 *
    815 * @since      1.0.0
    9  * @package    Woocommerce_Payment_Processor
    10  * @subpackage Woocommerce_Payment_Processor/includes
    11  * @author     AHMAD WAEL <[email protected]>
     16 * @package    BBPO_Purchase_Orders
     17 * @subpackage BBPO_Purchase_Orders/includes
     18 * @author     Ahmad Wael <[email protected]>
    1219 */
    1320class BBPO_Purchase_Orders_Files {
     
    7077    public function file_upload() {
    7178        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' );
    7481            $allowed       = array(
    7582                'application/msword' => 'doc',
     
    7885            );
    7986            if ( ! isset( $_FILES['wcpo-document-file'] ) ) {
    80                 wp_send_json_error(
     87                $this->send_error_signal(
    8188                    array(
    8289                        'code'    => 'file_not_provided',
     
    8592                );
    8693            }
     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            }
    87110            if ( ! in_array( $_FILES['wcpo-document-file']['type'], array_keys( $allowed ), true ) ) {
    88                 wp_send_json_error(
     111                $this->send_error_signal(
    89112                    array(
    90113                        'code'    => 'file_not_allowed',
     
    94117            }
    95118            if ( $_FILES['wcpo-document-file']['size'] > 2097152 ) { // 2 MB (size is also in bytes)
    96                 wp_send_json_error(
     119                $this->send_error_signal(
    97120                    array(
    98121                        'code'    => 'file_too_big',
     
    121144                $new_file_path = $path . $file_name;
    122145                rename( $file['file'], $new_file_path );
    123                 wp_send_json_success(
     146                $this->send_success_signal(
    124147                    array(
    125148                        'file_url'  => $upload_dir['baseurl'] . $dir . $file_name,
    126149                        'file_path' => $dir . $file_name,
    127150                        '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(
    132156                array(
    133157                    'code'    => 'file_error',
     
    136160            );
    137161        }
    138         wp_send_json_error(
     162        $this->send_error_signal(
    139163            array(
    140164                'code'    => 'nonce_failed',
     
    151175    public function delete_file() {
    152176        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'] ) );
    163191            if ( $this->validate_file_path( $file_path ) ) {
    164192                // delete file.
  • wc-purchase-orders/tags/1.0.3/public/js/wc-purchase-orders-public.js

    r3354271 r3356360  
    11(function ($) {
    22    'use strict';
    3 
     3   
     4    let file_name = '';
     5   
    46    // upload purchase order
    57    $(document).on('change', '#wcpo-document-file', function (e) {
     
    2527                    if(response.success) {
    2628                        previewArea.empty().show();
     29                        file_name = response.data.file_name;
    2730                        $('input[name="wcpo-document-file-path"]').val(response.data.file_path);
    2831                        previewArea.append('<span class="wcpo-remove">x</span><span>' + file.name + '</span><img src="' + wcpo_object.icons_url + response.data.file_type + '.png">')
     
    4346            $.ajax({
    4447                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
    4651                }, success: function (response) {
    4752                    file.val('')
  • wc-purchase-orders/trunk/includes/class-bbpo-purchase-orders-files.php

    r3354271 r3356360  
    11<?php
     2/**
     3 * The file that defines the purchase orders file handler.
     4 *
     5 * @package BBPO_Purchase_Orders
     6 */
     7
    28if ( ! defined( 'ABSPATH' ) ) {
    3     exit; // Exit if accessed directly
     9    exit; // Exit if accessed directly.
    410}
     11
    512/**
    613 * The purchase orders file handler.
    714 *
    815 * @since      1.0.0
    9  * @package    Woocommerce_Payment_Processor
    10  * @subpackage Woocommerce_Payment_Processor/includes
    11  * @author     AHMAD WAEL <[email protected]>
     16 * @package    BBPO_Purchase_Orders
     17 * @subpackage BBPO_Purchase_Orders/includes
     18 * @author     Ahmad Wael <[email protected]>
    1219 */
    1320class BBPO_Purchase_Orders_Files {
     
    7077    public function file_upload() {
    7178        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' );
    7481            $allowed       = array(
    7582                'application/msword' => 'doc',
     
    7885            );
    7986            if ( ! isset( $_FILES['wcpo-document-file'] ) ) {
    80                 wp_send_json_error(
     87                $this->send_error_signal(
    8188                    array(
    8289                        'code'    => 'file_not_provided',
     
    8592                );
    8693            }
     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            }
    87110            if ( ! in_array( $_FILES['wcpo-document-file']['type'], array_keys( $allowed ), true ) ) {
    88                 wp_send_json_error(
     111                $this->send_error_signal(
    89112                    array(
    90113                        'code'    => 'file_not_allowed',
     
    94117            }
    95118            if ( $_FILES['wcpo-document-file']['size'] > 2097152 ) { // 2 MB (size is also in bytes)
    96                 wp_send_json_error(
     119                $this->send_error_signal(
    97120                    array(
    98121                        'code'    => 'file_too_big',
     
    121144                $new_file_path = $path . $file_name;
    122145                rename( $file['file'], $new_file_path );
    123                 wp_send_json_success(
     146                $this->send_success_signal(
    124147                    array(
    125148                        'file_url'  => $upload_dir['baseurl'] . $dir . $file_name,
    126149                        'file_path' => $dir . $file_name,
    127150                        '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(
    132156                array(
    133157                    'code'    => 'file_error',
     
    136160            );
    137161        }
    138         wp_send_json_error(
     162        $this->send_error_signal(
    139163            array(
    140164                'code'    => 'nonce_failed',
     
    151175    public function delete_file() {
    152176        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'] ) );
    163191            if ( $this->validate_file_path( $file_path ) ) {
    164192                // delete file.
  • wc-purchase-orders/trunk/public/js/wc-purchase-orders-public.js

    r2990096 r3356360  
    11(function ($) {
    22    'use strict';
    3 
     3   
     4    let file_name = '';
     5   
    46    // upload purchase order
    57    $(document).on('change', '#wcpo-document-file', function (e) {
     
    2527                    if(response.success) {
    2628                        previewArea.empty().show();
     29                        file_name = response.data.file_name;
    2730                        $('input[name="wcpo-document-file-path"]').val(response.data.file_path);
    2831                        previewArea.append('<span class="wcpo-remove">x</span><span>' + file.name + '</span><img src="' + wcpo_object.icons_url + response.data.file_type + '.png">')
     
    4346            $.ajax({
    4447                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
    4651                }, success: function (response) {
    4752                    file.val('')
Note: See TracChangeset for help on using the changeset viewer.