/var/www/html_uk/wp-content/plugins/automatewoo/includes/Download.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php

namespace AutomateWoo;

if ( ! 
defined'ABSPATH' ) ) {
    exit;
}

/**
 * Download class.
 *
 * @since 5.6.6
 */
class Download {

    
/**
     * Download ID.
     *
     * @var int
     */
    
public $id;

    
/**
     * The ID of the associated product.
     *
     * @var int
     */
    
public $product_id;

    
/**
     * The ID of the associated order.
     *
     * @var int
     */
    
public $order_id;

    
/**
     * Constructor.
     *
     * @param int $id
     * @param int $product_id
     * @param int $order_id
     */
    
public function __construct$id$product_id$order_id ) {
        
$this->id         $id;
        
$this->product_id $product_id;
        
$this->order_id   $order_id;
    }

    
/**
     * Get the download ID.
     *
     * @return int
     */
    
public function get_id() {
        return 
$this->id;
    }

    
/**
     * Get the product ID.
     *
     * @return int
     */
    
public function get_product_id() {
        return 
$this->product_id;
    }

    
/**
     * Get the order ID.
     *
     * @return int
     */
    
public function get_order_id() {
        return 
$this->order_id;
    }

    
/**
     * Get the file name.
     *
     * @return string
     */
    
public function get_file_name() {
        
$product wc_get_product$this->product_id );
        if ( ! 
$product ) {
            return 
'';
        }

        
$file $product->get_file$this->id );
        if ( ! 
$file ) {
            return 
'';
        }

        return 
$file['name'];
    }

    
/**
     * Get the download URL.
     *
     * @return string
     */
    
public function get_download_url() {
        
$order wc_get_order$this->order_id );
        if ( ! 
$order ) {
            return 
'';
        }

        
// SEMGREP WARNING EXPLANATION
        // This is escaped by esc_url_raw but semgrep only takes into consideration esc_url.
        // Also, the URL is just a Home URL and the email is encoded. Rest of the params are just integer IDs.
        
return esc_url_raw(
            
add_query_arg(
                array(
                    
'download_file' => $this->product_id,
                    
'order'         => $order->get_order_key(),
                    
'email'         => rawurlencode$order->get_billing_email() ),
                    
'key'           => $this->id,
                ),
                
trailingslashithome_url() )
            )
        );
    }

    
/**
     * Get the download count.
     *
     * @return int
     */
    
public function get_download_count() {
        
$data_store \WC_Data_Store::load'customer-download' );
        
$downloads  $data_store->get_downloads(
            array(
                
'download_id' => $this->id,
                
'product_id'  => $this->product_id,
                
'order_id'    => $this->order_id,
                
'limit'       => 1,
                
'order'       => 'DESC',
            )
        );

        if ( ! empty( 
$downloads ) ) {
            
$download current$downloads );
            return 
$download->get_download_count();
        }

        return 
0;
    }
}