@@ -12,218 +12,218 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Graph_Downloader { |
14 | 14 | |
15 | - /** |
|
16 | - * @var GetPaid_Reports_Report |
|
17 | - */ |
|
18 | - public $handler; |
|
19 | - |
|
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - */ |
|
24 | - public function __construct() { |
|
25 | - $this->handler = new GetPaid_Reports_Report(); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Prepares the datastore handler. |
|
30 | - * |
|
31 | - * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
|
32 | - */ |
|
33 | - public function prepare_handler( $graph ) { |
|
34 | - |
|
35 | - if ( empty( $this->handler->views[ $graph ] ) ) { |
|
36 | - wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 ); |
|
37 | - } |
|
38 | - |
|
39 | - return new $this->handler->views[ $graph ]['class'](); |
|
40 | - |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Prepares the output stream. |
|
45 | - * |
|
46 | - * @return resource |
|
47 | - */ |
|
48 | - public function prepare_output() { |
|
49 | - |
|
50 | - $output = fopen( 'php://output', 'w' ); |
|
51 | - |
|
52 | - if ( false === $output ) { |
|
53 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
54 | - } |
|
55 | - |
|
56 | - return $output; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Prepares the file type. |
|
61 | - * |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - public function prepare_file_type( $graph ) { |
|
65 | - |
|
66 | - $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
67 | - $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
68 | - |
|
69 | - header( "Content-Type:application/$file_type" ); |
|
70 | - header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
71 | - |
|
72 | - return $file_type; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Handles the actual download. |
|
77 | - * |
|
78 | - */ |
|
79 | - public function download( $graph ) { |
|
80 | - global $wpdb; |
|
81 | - |
|
82 | - $handler = $this->prepare_handler( $graph ); |
|
83 | - $stream = $this->prepare_output(); |
|
84 | - $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
85 | - $headers = array( $handler->field, 'total', 'total_raw' ); |
|
86 | - $file_type = $this->prepare_file_type( $graph ); |
|
87 | - |
|
88 | - if ( 'csv' == $file_type ) { |
|
89 | - $this->download_csv( $stats, $stream, $headers ); |
|
90 | - } elseif ( 'xml' == $file_type ) { |
|
91 | - $this->download_xml( $stats, $stream, $headers ); |
|
92 | - } else { |
|
93 | - $this->download_json( $stats, $stream, $headers ); |
|
94 | - } |
|
95 | - |
|
96 | - fclose( $stream ); |
|
97 | - exit; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Downloads graph as csv |
|
102 | - * |
|
103 | - * @param array $stats The stats being downloaded. |
|
104 | - * @param resource $stream The stream to output to. |
|
105 | - * @param array $headers The fields to stream. |
|
106 | - * @since 1.0.19 |
|
107 | - */ |
|
108 | - public function download_csv( $stats, $stream, $headers ) { |
|
109 | - |
|
110 | - // Output the csv column headers. |
|
111 | - fputcsv( $stream, $headers ); |
|
112 | - |
|
113 | - // Loop through |
|
114 | - foreach ( $stats as $stat ) { |
|
115 | - $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
116 | - $row = array_map( 'maybe_serialize', $row ); |
|
117 | - fputcsv( $stream, $row ); |
|
118 | - } |
|
119 | - |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Downloads graph as json |
|
124 | - * |
|
125 | - * @param array $stats The stats being downloaded. |
|
126 | - * @param resource $stream The stream to output to. |
|
127 | - * @param array $headers The fields to stream. |
|
128 | - * @since 1.0.19 |
|
129 | - */ |
|
130 | - public function download_json( $stats, $stream, $headers ) { |
|
131 | - |
|
132 | - $prepared = array(); |
|
133 | - |
|
134 | - // Loop through |
|
135 | - foreach ( $stats as $stat ) { |
|
136 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
137 | - } |
|
138 | - |
|
139 | - fwrite( $stream, wp_json_encode( $prepared ) ); |
|
140 | - |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Downloads graph as xml |
|
145 | - * |
|
146 | - * @param array $stats The stats being downloaded. |
|
147 | - * @param resource $stream The stream to output to. |
|
148 | - * @param array $headers The fields to stream. |
|
149 | - * @since 1.0.19 |
|
150 | - */ |
|
151 | - public function download_xml( $stats, $stream, $headers ) { |
|
152 | - |
|
153 | - $prepared = array(); |
|
154 | - |
|
155 | - // Loop through |
|
156 | - foreach ( $stats as $stat ) { |
|
157 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
158 | - } |
|
159 | - |
|
160 | - $xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' ); |
|
161 | - $this->convert_array_xml( $prepared, $xml ); |
|
162 | - |
|
163 | - fwrite( $stream, $xml->asXML() ); |
|
164 | - |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Converts stats array to xml |
|
169 | - * |
|
170 | - * @access public |
|
171 | - * @since 1.0.19 |
|
172 | - */ |
|
173 | - public function convert_array_xml( $data, $xml ) { |
|
174 | - |
|
175 | - // Loop through |
|
176 | - foreach ( $data as $key => $value ) { |
|
177 | - |
|
178 | - $key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key ); |
|
179 | - |
|
180 | - if ( is_array( $value ) ) { |
|
181 | - |
|
182 | - if ( is_numeric( $key ) ) { |
|
183 | - $key = 'item' . $key; //dealing with <0/>..<n/> issues |
|
184 | - } |
|
185 | - |
|
186 | - $subnode = $xml->addChild( $key ); |
|
187 | - $this->convert_array_xml( $value, $subnode ); |
|
188 | - |
|
189 | - } else { |
|
190 | - $xml->addChild( $key, $value ? htmlspecialchars( $value ) : $value ); |
|
191 | - } |
|
15 | + /** |
|
16 | + * @var GetPaid_Reports_Report |
|
17 | + */ |
|
18 | + public $handler; |
|
19 | + |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + */ |
|
24 | + public function __construct() { |
|
25 | + $this->handler = new GetPaid_Reports_Report(); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Prepares the datastore handler. |
|
30 | + * |
|
31 | + * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
|
32 | + */ |
|
33 | + public function prepare_handler( $graph ) { |
|
34 | + |
|
35 | + if ( empty( $this->handler->views[ $graph ] ) ) { |
|
36 | + wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 ); |
|
37 | + } |
|
38 | + |
|
39 | + return new $this->handler->views[ $graph ]['class'](); |
|
40 | + |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Prepares the output stream. |
|
45 | + * |
|
46 | + * @return resource |
|
47 | + */ |
|
48 | + public function prepare_output() { |
|
49 | + |
|
50 | + $output = fopen( 'php://output', 'w' ); |
|
51 | + |
|
52 | + if ( false === $output ) { |
|
53 | + wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
54 | + } |
|
55 | + |
|
56 | + return $output; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Prepares the file type. |
|
61 | + * |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + public function prepare_file_type( $graph ) { |
|
65 | + |
|
66 | + $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
67 | + $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
68 | + |
|
69 | + header( "Content-Type:application/$file_type" ); |
|
70 | + header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
71 | + |
|
72 | + return $file_type; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Handles the actual download. |
|
77 | + * |
|
78 | + */ |
|
79 | + public function download( $graph ) { |
|
80 | + global $wpdb; |
|
81 | + |
|
82 | + $handler = $this->prepare_handler( $graph ); |
|
83 | + $stream = $this->prepare_output(); |
|
84 | + $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
85 | + $headers = array( $handler->field, 'total', 'total_raw' ); |
|
86 | + $file_type = $this->prepare_file_type( $graph ); |
|
87 | + |
|
88 | + if ( 'csv' == $file_type ) { |
|
89 | + $this->download_csv( $stats, $stream, $headers ); |
|
90 | + } elseif ( 'xml' == $file_type ) { |
|
91 | + $this->download_xml( $stats, $stream, $headers ); |
|
92 | + } else { |
|
93 | + $this->download_json( $stats, $stream, $headers ); |
|
94 | + } |
|
95 | + |
|
96 | + fclose( $stream ); |
|
97 | + exit; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Downloads graph as csv |
|
102 | + * |
|
103 | + * @param array $stats The stats being downloaded. |
|
104 | + * @param resource $stream The stream to output to. |
|
105 | + * @param array $headers The fields to stream. |
|
106 | + * @since 1.0.19 |
|
107 | + */ |
|
108 | + public function download_csv( $stats, $stream, $headers ) { |
|
109 | + |
|
110 | + // Output the csv column headers. |
|
111 | + fputcsv( $stream, $headers ); |
|
112 | + |
|
113 | + // Loop through |
|
114 | + foreach ( $stats as $stat ) { |
|
115 | + $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
116 | + $row = array_map( 'maybe_serialize', $row ); |
|
117 | + fputcsv( $stream, $row ); |
|
118 | + } |
|
119 | + |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Downloads graph as json |
|
124 | + * |
|
125 | + * @param array $stats The stats being downloaded. |
|
126 | + * @param resource $stream The stream to output to. |
|
127 | + * @param array $headers The fields to stream. |
|
128 | + * @since 1.0.19 |
|
129 | + */ |
|
130 | + public function download_json( $stats, $stream, $headers ) { |
|
131 | + |
|
132 | + $prepared = array(); |
|
133 | + |
|
134 | + // Loop through |
|
135 | + foreach ( $stats as $stat ) { |
|
136 | + $prepared[] = $this->prepare_row( $stat, $headers ); |
|
137 | + } |
|
138 | + |
|
139 | + fwrite( $stream, wp_json_encode( $prepared ) ); |
|
140 | + |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Downloads graph as xml |
|
145 | + * |
|
146 | + * @param array $stats The stats being downloaded. |
|
147 | + * @param resource $stream The stream to output to. |
|
148 | + * @param array $headers The fields to stream. |
|
149 | + * @since 1.0.19 |
|
150 | + */ |
|
151 | + public function download_xml( $stats, $stream, $headers ) { |
|
152 | + |
|
153 | + $prepared = array(); |
|
154 | + |
|
155 | + // Loop through |
|
156 | + foreach ( $stats as $stat ) { |
|
157 | + $prepared[] = $this->prepare_row( $stat, $headers ); |
|
158 | + } |
|
159 | + |
|
160 | + $xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' ); |
|
161 | + $this->convert_array_xml( $prepared, $xml ); |
|
162 | + |
|
163 | + fwrite( $stream, $xml->asXML() ); |
|
164 | + |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Converts stats array to xml |
|
169 | + * |
|
170 | + * @access public |
|
171 | + * @since 1.0.19 |
|
172 | + */ |
|
173 | + public function convert_array_xml( $data, $xml ) { |
|
174 | + |
|
175 | + // Loop through |
|
176 | + foreach ( $data as $key => $value ) { |
|
177 | + |
|
178 | + $key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key ); |
|
179 | + |
|
180 | + if ( is_array( $value ) ) { |
|
181 | + |
|
182 | + if ( is_numeric( $key ) ) { |
|
183 | + $key = 'item' . $key; //dealing with <0/>..<n/> issues |
|
184 | + } |
|
185 | + |
|
186 | + $subnode = $xml->addChild( $key ); |
|
187 | + $this->convert_array_xml( $value, $subnode ); |
|
188 | + |
|
189 | + } else { |
|
190 | + $xml->addChild( $key, $value ? htmlspecialchars( $value ) : $value ); |
|
191 | + } |
|
192 | 192 | } |
193 | 193 | |
194 | - } |
|
194 | + } |
|
195 | 195 | |
196 | - /** |
|
197 | - * Prepares a single row for download. |
|
198 | - * |
|
199 | - * @param stdClass|array $row The row to prepare.. |
|
200 | - * @param array $fields The fields to stream. |
|
201 | - * @since 1.0.19 |
|
202 | - * @return array |
|
203 | - */ |
|
204 | - public function prepare_row( $row, $fields ) { |
|
196 | + /** |
|
197 | + * Prepares a single row for download. |
|
198 | + * |
|
199 | + * @param stdClass|array $row The row to prepare.. |
|
200 | + * @param array $fields The fields to stream. |
|
201 | + * @since 1.0.19 |
|
202 | + * @return array |
|
203 | + */ |
|
204 | + public function prepare_row( $row, $fields ) { |
|
205 | 205 | |
206 | - $prepared = array(); |
|
207 | - $row = (array) $row; |
|
206 | + $prepared = array(); |
|
207 | + $row = (array) $row; |
|
208 | 208 | |
209 | - foreach ( $fields as $field ) { |
|
209 | + foreach ( $fields as $field ) { |
|
210 | 210 | |
211 | - if ( $field === 'total' ) { |
|
212 | - $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
213 | - continue; |
|
214 | - } |
|
211 | + if ( $field === 'total' ) { |
|
212 | + $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
213 | + continue; |
|
214 | + } |
|
215 | 215 | |
216 | - if ( $field === 'total_raw' ) { |
|
217 | - $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
218 | - continue; |
|
219 | - } |
|
216 | + if ( $field === 'total_raw' ) { |
|
217 | + $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
218 | + continue; |
|
219 | + } |
|
220 | 220 | |
221 | - $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
221 | + $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
222 | 222 | |
223 | - } |
|
223 | + } |
|
224 | 224 | |
225 | - return $prepared; |
|
226 | - } |
|
225 | + return $prepared; |
|
226 | + } |
|
227 | 227 | |
228 | 228 | |
229 | 229 | } |
@@ -12,236 +12,236 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Invoice_Exporter extends GetPaid_Graph_Downloader { |
14 | 14 | |
15 | - /** |
|
16 | - * Retrieves invoices query args. |
|
17 | - * |
|
18 | - * @param string $post_type post type to retrieve. |
|
19 | - * @param array $args Args to search for. |
|
20 | - * @return array |
|
21 | - */ |
|
22 | - public function get_invoice_query_args( $post_type, $args ) { |
|
23 | - |
|
24 | - $query_args = array( |
|
25 | - 'post_type' => $post_type, |
|
26 | - 'post_status' => array_keys( wpinv_get_invoice_statuses( true, false, $post_type ) ), |
|
27 | - 'posts_per_page' => -1, |
|
28 | - 'no_found_rows' => true, |
|
29 | - 'update_post_term_cache' => false, |
|
30 | - 'fields' => 'ids', |
|
31 | - ); |
|
32 | - |
|
33 | - if ( ! empty( $args['status'] ) && in_array( $args['status'], $query_args['post_status'], true ) ) { |
|
34 | - $query_args['post_status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
35 | - } |
|
36 | - |
|
37 | - $date_query = array(); |
|
38 | - if ( ! empty( $args['to_date'] ) ) { |
|
39 | - $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
40 | - } |
|
41 | - |
|
42 | - if ( ! empty( $args['from_date'] ) ) { |
|
43 | - $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
44 | - } |
|
45 | - |
|
46 | - if ( ! empty( $date_query ) ) { |
|
47 | - $date_query['inclusive'] = true; |
|
48 | - $query_args['date_query'] = array( $date_query ); |
|
49 | - } |
|
50 | - |
|
51 | - return $query_args; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Retrieves invoices. |
|
56 | - * |
|
57 | - * @param array $query_args WP_Query args. |
|
58 | - * @return WPInv_Invoice[] |
|
59 | - */ |
|
60 | - public function get_invoices( $query_args ) { |
|
61 | - |
|
62 | - // Get invoices. |
|
63 | - $invoices = new WP_Query( $query_args ); |
|
64 | - |
|
65 | - // Prepare the results. |
|
66 | - return array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
67 | - |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Handles the actual download. |
|
72 | - * |
|
73 | - */ |
|
74 | - public function export( $post_type, $args ) { |
|
75 | - |
|
76 | - $invoices = $this->get_invoices( $this->get_invoice_query_args( $post_type, $args ) ); |
|
77 | - $stream = $this->prepare_output(); |
|
78 | - $headers = $this->get_export_fields( $post_type ); |
|
79 | - $file_type = $this->prepare_file_type( strtolower( getpaid_get_post_type_label( $post_type ) ) ); |
|
80 | - |
|
81 | - if ( 'csv' == $file_type ) { |
|
82 | - $this->download_csv( $invoices, $stream, $headers ); |
|
83 | - } elseif ( 'xml' == $file_type ) { |
|
84 | - $this->download_xml( $invoices, $stream, $headers ); |
|
85 | - } else { |
|
86 | - $this->download_json( $invoices, $stream, $headers ); |
|
87 | - } |
|
88 | - |
|
89 | - fclose( $stream ); |
|
90 | - exit; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Prepares a single invoice for download. |
|
95 | - * |
|
96 | - * @param WPInv_Invoice $invoice The invoice to prepare.. |
|
97 | - * @param array $fields The fields to stream. |
|
98 | - * @since 1.0.19 |
|
99 | - * @return array |
|
100 | - */ |
|
101 | - public function prepare_row( $invoice, $fields ) { |
|
102 | - |
|
103 | - $prepared = array(); |
|
104 | - $amount_fields = $this->get_amount_fields( $invoice->get_post_type() ); |
|
105 | - $meta_fields = $this->get_payment_form_meta( $invoice ); |
|
106 | - |
|
107 | - foreach ( $fields as $field ) { |
|
108 | - $value = ''; |
|
109 | - $method = "get_$field"; |
|
110 | - |
|
111 | - if ( method_exists( $invoice, $method ) ) { |
|
112 | - $value = $invoice->$method(); |
|
113 | - } else if( strpos( $field, '_' ) === 0 && isset( $meta_fields[ $field ] ) ) { |
|
114 | - $value = $meta_fields[ $field ]; |
|
115 | - } |
|
116 | - |
|
117 | - if ( in_array( $field, $amount_fields ) ) { |
|
118 | - $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
119 | - } |
|
120 | - |
|
121 | - $prepared[ $field ] = wpinv_clean( $value ); |
|
122 | - |
|
123 | - } |
|
124 | - |
|
125 | - return $prepared; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Retrieves export fields. |
|
130 | - * |
|
131 | - * @param string $post_type |
|
132 | - * @since 1.0.19 |
|
133 | - * @return array |
|
134 | - */ |
|
135 | - public function get_export_fields( $post_type ) { |
|
136 | - |
|
137 | - $fields = array( |
|
138 | - 'id', |
|
139 | - 'parent_id', |
|
140 | - 'status', |
|
141 | - 'date_created', |
|
142 | - 'date_modified', |
|
143 | - 'date_due', |
|
144 | - 'date_completed', |
|
145 | - 'number', |
|
146 | - 'key', |
|
147 | - 'description', |
|
148 | - 'post_type', |
|
149 | - 'mode', |
|
150 | - 'customer_id', |
|
151 | - 'customer_first_name', |
|
152 | - 'customer_last_name', |
|
153 | - 'customer_phone', |
|
154 | - 'customer_email', |
|
155 | - 'customer_country', |
|
156 | - 'customer_city', |
|
157 | - 'customer_state', |
|
158 | - 'customer_zip', |
|
159 | - 'customer_company', |
|
160 | - 'customer_vat_number', |
|
161 | - 'customer_address', |
|
162 | - 'subtotal', |
|
163 | - 'total_discount', |
|
164 | - 'total_tax', |
|
165 | - 'total_fees', |
|
166 | - 'fees', |
|
167 | - 'discounts', |
|
168 | - 'taxes', |
|
169 | - 'cart_details', |
|
170 | - 'item_ids', |
|
171 | - 'payment_form', |
|
172 | - 'discount_code', |
|
173 | - 'gateway', |
|
174 | - 'transaction_id', |
|
175 | - 'currency', |
|
176 | - 'disable_taxes', |
|
177 | - 'subscription_id', |
|
178 | - 'remote_subscription_id', |
|
179 | - 'is_viewed', |
|
180 | - 'email_cc', |
|
181 | - 'template', |
|
182 | - 'created_via', |
|
183 | - ); |
|
184 | - |
|
185 | - // Payment form meta fields. |
|
186 | - $meta_fields = getpaid_get_payment_form_custom_fields(); |
|
187 | - |
|
188 | - if ( ! empty( $meta_fields ) ) { |
|
189 | - foreach ( $meta_fields as $field_key => $field_label ) { |
|
190 | - $fields[] = $field_key; |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - return apply_filters( 'getpaid_invoice_exporter_get_fields', $fields, $post_type ); |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Retrieves amount fields. |
|
199 | - * |
|
200 | - * @param string $post_type |
|
201 | - * @since 1.0.19 |
|
202 | - * @return array |
|
203 | - */ |
|
204 | - public function get_amount_fields( $post_type ) { |
|
205 | - |
|
206 | - $fields = array( |
|
207 | - 'subtotal', |
|
208 | - 'total_discount', |
|
209 | - 'total_tax', |
|
210 | - 'total_fees', |
|
211 | - ); |
|
212 | - |
|
213 | - return apply_filters( 'getpaid_invoice_exporter_get_amount_fields', $fields, $post_type ); |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Retrieves payment form meta fields. |
|
218 | - * |
|
219 | - * @since 2.8.23 |
|
220 | - * |
|
221 | - * @return array |
|
222 | - */ |
|
223 | - public function get_payment_form_meta( $invoice ) { |
|
224 | - // Payment form meta fields. |
|
225 | - $field_keys = getpaid_get_payment_form_custom_fields(); |
|
226 | - $meta = get_post_meta( $invoice->get_id(), 'additional_meta_data', true ); |
|
227 | - |
|
228 | - $field_values = array(); |
|
229 | - if ( ! empty( $field_keys ) ) { |
|
230 | - foreach ( $field_keys as $field_key => $field_label ) { |
|
231 | - $value = ''; |
|
232 | - |
|
233 | - if ( ! empty( $meta ) ) { |
|
234 | - foreach ( $meta as $meta_label => $meta_value ) { |
|
235 | - if ( getpaid_strtolower( wpinv_clean( wp_unslash( $meta_label ) ) ) == getpaid_strtolower( $field_label ) ) { |
|
236 | - $value = $meta_value; |
|
237 | - } |
|
238 | - } |
|
239 | - } |
|
240 | - |
|
241 | - $field_values[ $field_key ] = $value; |
|
242 | - } |
|
243 | - } |
|
244 | - |
|
245 | - return $field_values; |
|
246 | - } |
|
15 | + /** |
|
16 | + * Retrieves invoices query args. |
|
17 | + * |
|
18 | + * @param string $post_type post type to retrieve. |
|
19 | + * @param array $args Args to search for. |
|
20 | + * @return array |
|
21 | + */ |
|
22 | + public function get_invoice_query_args( $post_type, $args ) { |
|
23 | + |
|
24 | + $query_args = array( |
|
25 | + 'post_type' => $post_type, |
|
26 | + 'post_status' => array_keys( wpinv_get_invoice_statuses( true, false, $post_type ) ), |
|
27 | + 'posts_per_page' => -1, |
|
28 | + 'no_found_rows' => true, |
|
29 | + 'update_post_term_cache' => false, |
|
30 | + 'fields' => 'ids', |
|
31 | + ); |
|
32 | + |
|
33 | + if ( ! empty( $args['status'] ) && in_array( $args['status'], $query_args['post_status'], true ) ) { |
|
34 | + $query_args['post_status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
35 | + } |
|
36 | + |
|
37 | + $date_query = array(); |
|
38 | + if ( ! empty( $args['to_date'] ) ) { |
|
39 | + $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
40 | + } |
|
41 | + |
|
42 | + if ( ! empty( $args['from_date'] ) ) { |
|
43 | + $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
44 | + } |
|
45 | + |
|
46 | + if ( ! empty( $date_query ) ) { |
|
47 | + $date_query['inclusive'] = true; |
|
48 | + $query_args['date_query'] = array( $date_query ); |
|
49 | + } |
|
50 | + |
|
51 | + return $query_args; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Retrieves invoices. |
|
56 | + * |
|
57 | + * @param array $query_args WP_Query args. |
|
58 | + * @return WPInv_Invoice[] |
|
59 | + */ |
|
60 | + public function get_invoices( $query_args ) { |
|
61 | + |
|
62 | + // Get invoices. |
|
63 | + $invoices = new WP_Query( $query_args ); |
|
64 | + |
|
65 | + // Prepare the results. |
|
66 | + return array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
67 | + |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Handles the actual download. |
|
72 | + * |
|
73 | + */ |
|
74 | + public function export( $post_type, $args ) { |
|
75 | + |
|
76 | + $invoices = $this->get_invoices( $this->get_invoice_query_args( $post_type, $args ) ); |
|
77 | + $stream = $this->prepare_output(); |
|
78 | + $headers = $this->get_export_fields( $post_type ); |
|
79 | + $file_type = $this->prepare_file_type( strtolower( getpaid_get_post_type_label( $post_type ) ) ); |
|
80 | + |
|
81 | + if ( 'csv' == $file_type ) { |
|
82 | + $this->download_csv( $invoices, $stream, $headers ); |
|
83 | + } elseif ( 'xml' == $file_type ) { |
|
84 | + $this->download_xml( $invoices, $stream, $headers ); |
|
85 | + } else { |
|
86 | + $this->download_json( $invoices, $stream, $headers ); |
|
87 | + } |
|
88 | + |
|
89 | + fclose( $stream ); |
|
90 | + exit; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Prepares a single invoice for download. |
|
95 | + * |
|
96 | + * @param WPInv_Invoice $invoice The invoice to prepare.. |
|
97 | + * @param array $fields The fields to stream. |
|
98 | + * @since 1.0.19 |
|
99 | + * @return array |
|
100 | + */ |
|
101 | + public function prepare_row( $invoice, $fields ) { |
|
102 | + |
|
103 | + $prepared = array(); |
|
104 | + $amount_fields = $this->get_amount_fields( $invoice->get_post_type() ); |
|
105 | + $meta_fields = $this->get_payment_form_meta( $invoice ); |
|
106 | + |
|
107 | + foreach ( $fields as $field ) { |
|
108 | + $value = ''; |
|
109 | + $method = "get_$field"; |
|
110 | + |
|
111 | + if ( method_exists( $invoice, $method ) ) { |
|
112 | + $value = $invoice->$method(); |
|
113 | + } else if( strpos( $field, '_' ) === 0 && isset( $meta_fields[ $field ] ) ) { |
|
114 | + $value = $meta_fields[ $field ]; |
|
115 | + } |
|
116 | + |
|
117 | + if ( in_array( $field, $amount_fields ) ) { |
|
118 | + $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
119 | + } |
|
120 | + |
|
121 | + $prepared[ $field ] = wpinv_clean( $value ); |
|
122 | + |
|
123 | + } |
|
124 | + |
|
125 | + return $prepared; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Retrieves export fields. |
|
130 | + * |
|
131 | + * @param string $post_type |
|
132 | + * @since 1.0.19 |
|
133 | + * @return array |
|
134 | + */ |
|
135 | + public function get_export_fields( $post_type ) { |
|
136 | + |
|
137 | + $fields = array( |
|
138 | + 'id', |
|
139 | + 'parent_id', |
|
140 | + 'status', |
|
141 | + 'date_created', |
|
142 | + 'date_modified', |
|
143 | + 'date_due', |
|
144 | + 'date_completed', |
|
145 | + 'number', |
|
146 | + 'key', |
|
147 | + 'description', |
|
148 | + 'post_type', |
|
149 | + 'mode', |
|
150 | + 'customer_id', |
|
151 | + 'customer_first_name', |
|
152 | + 'customer_last_name', |
|
153 | + 'customer_phone', |
|
154 | + 'customer_email', |
|
155 | + 'customer_country', |
|
156 | + 'customer_city', |
|
157 | + 'customer_state', |
|
158 | + 'customer_zip', |
|
159 | + 'customer_company', |
|
160 | + 'customer_vat_number', |
|
161 | + 'customer_address', |
|
162 | + 'subtotal', |
|
163 | + 'total_discount', |
|
164 | + 'total_tax', |
|
165 | + 'total_fees', |
|
166 | + 'fees', |
|
167 | + 'discounts', |
|
168 | + 'taxes', |
|
169 | + 'cart_details', |
|
170 | + 'item_ids', |
|
171 | + 'payment_form', |
|
172 | + 'discount_code', |
|
173 | + 'gateway', |
|
174 | + 'transaction_id', |
|
175 | + 'currency', |
|
176 | + 'disable_taxes', |
|
177 | + 'subscription_id', |
|
178 | + 'remote_subscription_id', |
|
179 | + 'is_viewed', |
|
180 | + 'email_cc', |
|
181 | + 'template', |
|
182 | + 'created_via', |
|
183 | + ); |
|
184 | + |
|
185 | + // Payment form meta fields. |
|
186 | + $meta_fields = getpaid_get_payment_form_custom_fields(); |
|
187 | + |
|
188 | + if ( ! empty( $meta_fields ) ) { |
|
189 | + foreach ( $meta_fields as $field_key => $field_label ) { |
|
190 | + $fields[] = $field_key; |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + return apply_filters( 'getpaid_invoice_exporter_get_fields', $fields, $post_type ); |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Retrieves amount fields. |
|
199 | + * |
|
200 | + * @param string $post_type |
|
201 | + * @since 1.0.19 |
|
202 | + * @return array |
|
203 | + */ |
|
204 | + public function get_amount_fields( $post_type ) { |
|
205 | + |
|
206 | + $fields = array( |
|
207 | + 'subtotal', |
|
208 | + 'total_discount', |
|
209 | + 'total_tax', |
|
210 | + 'total_fees', |
|
211 | + ); |
|
212 | + |
|
213 | + return apply_filters( 'getpaid_invoice_exporter_get_amount_fields', $fields, $post_type ); |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Retrieves payment form meta fields. |
|
218 | + * |
|
219 | + * @since 2.8.23 |
|
220 | + * |
|
221 | + * @return array |
|
222 | + */ |
|
223 | + public function get_payment_form_meta( $invoice ) { |
|
224 | + // Payment form meta fields. |
|
225 | + $field_keys = getpaid_get_payment_form_custom_fields(); |
|
226 | + $meta = get_post_meta( $invoice->get_id(), 'additional_meta_data', true ); |
|
227 | + |
|
228 | + $field_values = array(); |
|
229 | + if ( ! empty( $field_keys ) ) { |
|
230 | + foreach ( $field_keys as $field_key => $field_label ) { |
|
231 | + $value = ''; |
|
232 | + |
|
233 | + if ( ! empty( $meta ) ) { |
|
234 | + foreach ( $meta as $meta_label => $meta_value ) { |
|
235 | + if ( getpaid_strtolower( wpinv_clean( wp_unslash( $meta_label ) ) ) == getpaid_strtolower( $field_label ) ) { |
|
236 | + $value = $meta_value; |
|
237 | + } |
|
238 | + } |
|
239 | + } |
|
240 | + |
|
241 | + $field_values[ $field_key ] = $value; |
|
242 | + } |
|
243 | + } |
|
244 | + |
|
245 | + return $field_values; |
|
246 | + } |
|
247 | 247 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
141 | 141 | */ |
142 | 142 | function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
143 | + return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | function wpinv_get_theme_template_dir_name() { |
161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
161 | + return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -175,125 +175,125 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
178 | + do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
179 | 179 | |
180 | - // Setup possible parts |
|
181 | - $templates = array(); |
|
182 | - if ( isset( $name ) ) { |
|
183 | - $templates[] = $slug . '-' . $name . '.php'; |
|
180 | + // Setup possible parts |
|
181 | + $templates = array(); |
|
182 | + if ( isset( $name ) ) { |
|
183 | + $templates[] = $slug . '-' . $name . '.php'; |
|
184 | 184 | } |
185 | - $templates[] = $slug . '.php'; |
|
185 | + $templates[] = $slug . '.php'; |
|
186 | 186 | |
187 | - // Allow template parts to be filtered |
|
188 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
187 | + // Allow template parts to be filtered |
|
188 | + $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
189 | 189 | |
190 | - // Return the part that is found |
|
191 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
190 | + // Return the part that is found |
|
191 | + return wpinv_locate_tmpl( $templates, $load, false ); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
195 | - // No file found yet |
|
196 | - $located = false; |
|
195 | + // No file found yet |
|
196 | + $located = false; |
|
197 | 197 | |
198 | - // Try to find a template file |
|
199 | - foreach ( (array)$template_names as $template_name ) { |
|
198 | + // Try to find a template file |
|
199 | + foreach ( (array)$template_names as $template_name ) { |
|
200 | 200 | |
201 | - // Continue if template is empty |
|
202 | - if ( empty( $template_name ) ) { |
|
203 | - continue; |
|
201 | + // Continue if template is empty |
|
202 | + if ( empty( $template_name ) ) { |
|
203 | + continue; |
|
204 | 204 | } |
205 | 205 | |
206 | - // Trim off any slashes from the template name |
|
207 | - $template_name = ltrim( $template_name, '/' ); |
|
206 | + // Trim off any slashes from the template name |
|
207 | + $template_name = ltrim( $template_name, '/' ); |
|
208 | 208 | |
209 | - // try locating this template file by looping through the template paths |
|
210 | - foreach ( wpinv_get_theme_template_paths() as $template_path ) { |
|
209 | + // try locating this template file by looping through the template paths |
|
210 | + foreach ( wpinv_get_theme_template_paths() as $template_path ) { |
|
211 | 211 | |
212 | - if ( file_exists( $template_path . $template_name ) ) { |
|
213 | - $located = $template_path . $template_name; |
|
214 | - break; |
|
215 | - } |
|
216 | - } |
|
212 | + if ( file_exists( $template_path . $template_name ) ) { |
|
213 | + $located = $template_path . $template_name; |
|
214 | + break; |
|
215 | + } |
|
216 | + } |
|
217 | 217 | |
218 | - if ( ! empty( $located ) ) { |
|
219 | - break; |
|
220 | - } |
|
221 | - } |
|
218 | + if ( ! empty( $located ) ) { |
|
219 | + break; |
|
220 | + } |
|
221 | + } |
|
222 | 222 | |
223 | - if ( ( true == $load ) && ! empty( $located ) ) { |
|
224 | - load_template( $located, $require_once ); |
|
223 | + if ( ( true == $load ) && ! empty( $located ) ) { |
|
224 | + load_template( $located, $require_once ); |
|
225 | 225 | } |
226 | 226 | |
227 | - return $located; |
|
227 | + return $located; |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | function wpinv_get_theme_template_paths() { |
231 | - $template_dir = wpinv_get_theme_template_dir_name(); |
|
231 | + $template_dir = wpinv_get_theme_template_dir_name(); |
|
232 | 232 | |
233 | - $file_paths = array( |
|
234 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
235 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
236 | - 100 => wpinv_get_templates_dir(), |
|
237 | - ); |
|
233 | + $file_paths = array( |
|
234 | + 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
235 | + 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
236 | + 100 => wpinv_get_templates_dir(), |
|
237 | + ); |
|
238 | 238 | |
239 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
239 | + $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
240 | 240 | |
241 | - // sort the file paths based on priority |
|
242 | - ksort( $file_paths, SORT_NUMERIC ); |
|
241 | + // sort the file paths based on priority |
|
242 | + ksort( $file_paths, SORT_NUMERIC ); |
|
243 | 243 | |
244 | - return array_map( 'trailingslashit', $file_paths ); |
|
244 | + return array_map( 'trailingslashit', $file_paths ); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | function wpinv_checkout_meta_tags() { |
248 | 248 | |
249 | - $pages = array(); |
|
250 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
251 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
252 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
253 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
249 | + $pages = array(); |
|
250 | + $pages[] = wpinv_get_option( 'success_page' ); |
|
251 | + $pages[] = wpinv_get_option( 'failure_page' ); |
|
252 | + $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
253 | + $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
254 | 254 | |
255 | - if ( ! wpinv_is_checkout() && ! is_page( $pages ) ) { |
|
256 | - return; |
|
257 | - } |
|
255 | + if ( ! wpinv_is_checkout() && ! is_page( $pages ) ) { |
|
256 | + return; |
|
257 | + } |
|
258 | 258 | |
259 | - echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
259 | + echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
260 | 260 | } |
261 | 261 | add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
262 | 262 | |
263 | 263 | function wpinv_add_body_classes( $class ) { |
264 | - $classes = (array)$class; |
|
264 | + $classes = (array)$class; |
|
265 | 265 | |
266 | - if ( wpinv_is_checkout() ) { |
|
267 | - $classes[] = 'wpinv-checkout'; |
|
268 | - $classes[] = 'wpinv-page'; |
|
269 | - } |
|
266 | + if ( wpinv_is_checkout() ) { |
|
267 | + $classes[] = 'wpinv-checkout'; |
|
268 | + $classes[] = 'wpinv-page'; |
|
269 | + } |
|
270 | 270 | |
271 | - if ( wpinv_is_success_page() ) { |
|
272 | - $classes[] = 'wpinv-success'; |
|
273 | - $classes[] = 'wpinv-page'; |
|
274 | - } |
|
271 | + if ( wpinv_is_success_page() ) { |
|
272 | + $classes[] = 'wpinv-success'; |
|
273 | + $classes[] = 'wpinv-page'; |
|
274 | + } |
|
275 | 275 | |
276 | - if ( wpinv_is_failed_transaction_page() ) { |
|
277 | - $classes[] = 'wpinv-failed-transaction'; |
|
278 | - $classes[] = 'wpinv-page'; |
|
279 | - } |
|
276 | + if ( wpinv_is_failed_transaction_page() ) { |
|
277 | + $classes[] = 'wpinv-failed-transaction'; |
|
278 | + $classes[] = 'wpinv-page'; |
|
279 | + } |
|
280 | 280 | |
281 | - if ( wpinv_is_invoice_history_page() ) { |
|
282 | - $classes[] = 'wpinv-history'; |
|
283 | - $classes[] = 'wpinv-page'; |
|
284 | - } |
|
281 | + if ( wpinv_is_invoice_history_page() ) { |
|
282 | + $classes[] = 'wpinv-history'; |
|
283 | + $classes[] = 'wpinv-page'; |
|
284 | + } |
|
285 | 285 | |
286 | - if ( wpinv_is_subscriptions_history_page() ) { |
|
287 | - $classes[] = 'wpinv-subscription'; |
|
288 | - $classes[] = 'wpinv-page'; |
|
289 | - } |
|
286 | + if ( wpinv_is_subscriptions_history_page() ) { |
|
287 | + $classes[] = 'wpinv-subscription'; |
|
288 | + $classes[] = 'wpinv-page'; |
|
289 | + } |
|
290 | 290 | |
291 | - if ( wpinv_is_test_mode() ) { |
|
292 | - $classes[] = 'wpinv-test-mode'; |
|
293 | - $classes[] = 'wpinv-page'; |
|
294 | - } |
|
291 | + if ( wpinv_is_test_mode() ) { |
|
292 | + $classes[] = 'wpinv-test-mode'; |
|
293 | + $classes[] = 'wpinv-page'; |
|
294 | + } |
|
295 | 295 | |
296 | - return array_unique( $classes ); |
|
296 | + return array_unique( $classes ); |
|
297 | 297 | } |
298 | 298 | add_filter( 'body_class', 'wpinv_add_body_classes' ); |
299 | 299 | |
@@ -467,16 +467,16 @@ discard block |
||
467 | 467 | |
468 | 468 | wpinv_html_select( |
469 | 469 | array( |
470 | - 'name' => $args['name'], |
|
471 | - 'selected' => $args['selected'], |
|
472 | - 'id' => $args['id'], |
|
473 | - 'class' => $args['class'], |
|
474 | - 'options' => $options, |
|
475 | - 'multiple' => $args['multiple'], |
|
476 | - 'placeholder' => $args['placeholder'], |
|
477 | - 'show_option_all' => $args['show_option_all'], |
|
478 | - 'show_option_none' => $args['show_option_none'], |
|
479 | - 'data' => $args['data'], |
|
470 | + 'name' => $args['name'], |
|
471 | + 'selected' => $args['selected'], |
|
472 | + 'id' => $args['id'], |
|
473 | + 'class' => $args['class'], |
|
474 | + 'options' => $options, |
|
475 | + 'multiple' => $args['multiple'], |
|
476 | + 'placeholder' => $args['placeholder'], |
|
477 | + 'show_option_all' => $args['show_option_all'], |
|
478 | + 'show_option_none' => $args['show_option_none'], |
|
479 | + 'data' => $args['data'], |
|
480 | 480 | ) |
481 | 481 | ); |
482 | 482 | |
@@ -776,21 +776,21 @@ discard block |
||
776 | 776 | |
777 | 777 | $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
778 | 778 | |
779 | - // Remove unavailable tags. |
|
779 | + // Remove unavailable tags. |
|
780 | 780 | $formatted_address = preg_replace( '/\{\{\w+\}\}/', '', $formatted_address ); |
781 | 781 | |
782 | 782 | // Clean up white space. |
783 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
783 | + $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
784 | 784 | $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
785 | 785 | |
786 | 786 | // Break newlines apart and remove empty lines/trim commas and white space. |
787 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
787 | + $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
788 | 788 | |
789 | 789 | // Add html breaks. |
790 | - $formatted_address = implode( $separator, $formatted_address ); |
|
790 | + $formatted_address = implode( $separator, $formatted_address ); |
|
791 | 791 | |
792 | - // We're done! |
|
793 | - return $formatted_address; |
|
792 | + // We're done! |
|
793 | + return $formatted_address; |
|
794 | 794 | |
795 | 795 | } |
796 | 796 | |
@@ -836,7 +836,7 @@ discard block |
||
836 | 836 | function getpaid_display_invoice_subscriptions( $invoice ) { |
837 | 837 | |
838 | 838 | // Subscriptions. |
839 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
839 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
840 | 840 | |
841 | 841 | if ( empty( $subscriptions ) || ! $invoice->is_recurring() ) { |
842 | 842 | return; |
@@ -1052,7 +1052,7 @@ discard block |
||
1052 | 1052 | } |
1053 | 1053 | |
1054 | 1054 | function wpinv_empty_cart_message() { |
1055 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1055 | + return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1056 | 1056 | } |
1057 | 1057 | |
1058 | 1058 | /** |
@@ -1250,9 +1250,9 @@ discard block |
||
1250 | 1250 | |
1251 | 1251 | if ( 0 == count( $form->get_items() ) ) { |
1252 | 1252 | aui()->alert( |
1253 | - array( |
|
1254 | - 'type' => 'warning', |
|
1255 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1253 | + array( |
|
1254 | + 'type' => 'warning', |
|
1255 | + 'content' => __( 'No published items found', 'invoicing' ), |
|
1256 | 1256 | ), |
1257 | 1257 | true |
1258 | 1258 | ); |
@@ -1275,10 +1275,10 @@ discard block |
||
1275 | 1275 | $invoice = wpinv_get_invoice( $invoice_id ); |
1276 | 1276 | |
1277 | 1277 | if ( empty( $invoice ) ) { |
1278 | - aui()->alert( |
|
1279 | - array( |
|
1280 | - 'type' => 'warning', |
|
1281 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1278 | + aui()->alert( |
|
1279 | + array( |
|
1280 | + 'type' => 'warning', |
|
1281 | + 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1282 | 1282 | ), |
1283 | 1283 | true |
1284 | 1284 | ); |
@@ -1286,10 +1286,10 @@ discard block |
||
1286 | 1286 | } |
1287 | 1287 | |
1288 | 1288 | if ( $invoice->is_paid() ) { |
1289 | - aui()->alert( |
|
1290 | - array( |
|
1291 | - 'type' => 'warning', |
|
1292 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1289 | + aui()->alert( |
|
1290 | + array( |
|
1291 | + 'type' => 'warning', |
|
1292 | + 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1293 | 1293 | ), |
1294 | 1294 | true |
1295 | 1295 | ); |
@@ -1354,7 +1354,7 @@ discard block |
||
1354 | 1354 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; |
1355 | 1355 | } |
1356 | 1356 | |
1357 | - if ( ! empty( $items ) ) { |
|
1357 | + if ( ! empty( $items ) ) { |
|
1358 | 1358 | $items = esc_attr( $items ); |
1359 | 1359 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; |
1360 | 1360 | } |
@@ -1554,21 +1554,21 @@ discard block |
||
1554 | 1554 | |
1555 | 1555 | return aui()->select( |
1556 | 1556 | array( |
1557 | - 'options' => $states, |
|
1558 | - 'name' => esc_attr( $field_name ), |
|
1559 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1560 | - 'value' => sanitize_text_field( $state ), |
|
1561 | - 'placeholder' => $placeholder, |
|
1562 | - 'required' => $required, |
|
1563 | - 'label' => wp_kses_post( $label ), |
|
1564 | - 'label_type' => 'vertical', |
|
1565 | - 'help_text' => $help_text, |
|
1566 | - 'class' => 'getpaid-address-field wpinv_state', |
|
1567 | - 'wrap_class' => "$wrapper_class getpaid-address-field-wrapper__state", |
|
1568 | - 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state', |
|
1569 | - 'extra_attributes' => array( |
|
1570 | - 'autocomplete' => 'address-level1', |
|
1571 | - ), |
|
1557 | + 'options' => $states, |
|
1558 | + 'name' => esc_attr( $field_name ), |
|
1559 | + 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1560 | + 'value' => sanitize_text_field( $state ), |
|
1561 | + 'placeholder' => $placeholder, |
|
1562 | + 'required' => $required, |
|
1563 | + 'label' => wp_kses_post( $label ), |
|
1564 | + 'label_type' => 'vertical', |
|
1565 | + 'help_text' => $help_text, |
|
1566 | + 'class' => 'getpaid-address-field wpinv_state', |
|
1567 | + 'wrap_class' => "$wrapper_class getpaid-address-field-wrapper__state", |
|
1568 | + 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state', |
|
1569 | + 'extra_attributes' => array( |
|
1570 | + 'autocomplete' => 'address-level1', |
|
1571 | + ), |
|
1572 | 1572 | ), |
1573 | 1573 | $echo |
1574 | 1574 | ); |
@@ -1664,34 +1664,34 @@ discard block |
||
1664 | 1664 | * @return array Array of custom fields. |
1665 | 1665 | */ |
1666 | 1666 | function getpaid_get_payment_form_custom_fields() { |
1667 | - global $wpdb, $payment_form_meta_fields; |
|
1667 | + global $wpdb, $payment_form_meta_fields; |
|
1668 | 1668 | |
1669 | - if ( ! empty( $payment_form_meta_fields ) ) { |
|
1670 | - return $payment_form_meta_fields; |
|
1671 | - } |
|
1669 | + if ( ! empty( $payment_form_meta_fields ) ) { |
|
1670 | + return $payment_form_meta_fields; |
|
1671 | + } |
|
1672 | 1672 | |
1673 | - $results = $wpdb->get_results( "SELECT `pm`.`meta_value` FROM `{$wpdb->postmeta}` AS pm LEFT JOIN `{$wpdb->posts}` AS p ON p.ID = pm.post_id WHERE `pm`.`meta_key` = 'wpinv_form_elements' AND `p`.`post_type` = 'wpi_payment_form'" ); |
|
1673 | + $results = $wpdb->get_results( "SELECT `pm`.`meta_value` FROM `{$wpdb->postmeta}` AS pm LEFT JOIN `{$wpdb->posts}` AS p ON p.ID = pm.post_id WHERE `pm`.`meta_key` = 'wpinv_form_elements' AND `p`.`post_type` = 'wpi_payment_form'" ); |
|
1674 | 1674 | |
1675 | - $meta_fields = array(); |
|
1675 | + $meta_fields = array(); |
|
1676 | 1676 | |
1677 | - if ( ! empty( $results ) ) { |
|
1678 | - foreach ( $results as $row ) { |
|
1679 | - $fields = maybe_unserialize( $row->meta_value ); |
|
1677 | + if ( ! empty( $results ) ) { |
|
1678 | + foreach ( $results as $row ) { |
|
1679 | + $fields = maybe_unserialize( $row->meta_value ); |
|
1680 | 1680 | |
1681 | - if ( ! empty( $fields ) && is_array( $fields ) ) { |
|
1682 | - foreach ( $fields as $field ) { |
|
1683 | - $label = ! empty( $field['add_meta'] ) && ! empty( $field['label'] ) ? wpinv_clean( wp_unslash( $field['label'] ) ) : ''; |
|
1681 | + if ( ! empty( $fields ) && is_array( $fields ) ) { |
|
1682 | + foreach ( $fields as $field ) { |
|
1683 | + $label = ! empty( $field['add_meta'] ) && ! empty( $field['label'] ) ? wpinv_clean( wp_unslash( $field['label'] ) ) : ''; |
|
1684 | 1684 | |
1685 | - if ( $label ) { |
|
1686 | - $field_key = '_' . str_replace( array( ' ', "'", '"', ',' ), array( '_', '', '', '_' ), getpaid_strtolower( $label ) ); |
|
1687 | - $meta_fields[ $field_key ] = $label; |
|
1688 | - } |
|
1689 | - } |
|
1690 | - } |
|
1691 | - } |
|
1692 | - } |
|
1685 | + if ( $label ) { |
|
1686 | + $field_key = '_' . str_replace( array( ' ', "'", '"', ',' ), array( '_', '', '', '_' ), getpaid_strtolower( $label ) ); |
|
1687 | + $meta_fields[ $field_key ] = $label; |
|
1688 | + } |
|
1689 | + } |
|
1690 | + } |
|
1691 | + } |
|
1692 | + } |
|
1693 | 1693 | |
1694 | - $payment_form_meta_fields = $meta_fields; |
|
1694 | + $payment_form_meta_fields = $meta_fields; |
|
1695 | 1695 | |
1696 | - return $meta_fields; |
|
1696 | + return $meta_fields; |
|
1697 | 1697 | } |
@@ -137,13 +137,13 @@ discard block |
||
137 | 137 | */ |
138 | 138 | function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
139 | 139 | |
140 | - $invoice_statuses = array( |
|
141 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
140 | + $invoice_statuses = array( |
|
141 | + 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
142 | 142 | 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
143 | 143 | 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
144 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
145 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
146 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
144 | + 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
145 | + 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
146 | + 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
147 | 147 | 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
148 | 148 | 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
149 | 149 | ); |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $invoice = $invoice->get_post_type(); |
161 | 161 | } |
162 | 162 | |
163 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
163 | + return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -278,25 +278,25 @@ discard block |
||
278 | 278 | * @return string |
279 | 279 | */ |
280 | 280 | function getpaid_get_price_format() { |
281 | - $currency_pos = wpinv_currency_position(); |
|
282 | - $format = '%1$s%2$s'; |
|
283 | - |
|
284 | - switch ( $currency_pos ) { |
|
285 | - case 'left': |
|
286 | - $format = '%1$s%2$s'; |
|
287 | - break; |
|
288 | - case 'right': |
|
289 | - $format = '%2$s%1$s'; |
|
290 | - break; |
|
291 | - case 'left_space': |
|
292 | - $format = '%1$s %2$s'; |
|
293 | - break; |
|
294 | - case 'right_space': |
|
295 | - $format = '%2$s %1$s'; |
|
296 | - break; |
|
297 | - } |
|
298 | - |
|
299 | - return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
281 | + $currency_pos = wpinv_currency_position(); |
|
282 | + $format = '%1$s%2$s'; |
|
283 | + |
|
284 | + switch ( $currency_pos ) { |
|
285 | + case 'left': |
|
286 | + $format = '%1$s%2$s'; |
|
287 | + break; |
|
288 | + case 'right': |
|
289 | + $format = '%2$s%1$s'; |
|
290 | + break; |
|
291 | + case 'left_space': |
|
292 | + $format = '%1$s %2$s'; |
|
293 | + break; |
|
294 | + case 'right_space': |
|
295 | + $format = '%2$s %1$s'; |
|
296 | + break; |
|
297 | + } |
|
298 | + |
|
299 | + return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -402,13 +402,13 @@ discard block |
||
402 | 402 | * @param mixed $value Value. |
403 | 403 | */ |
404 | 404 | function getpaid_maybe_define_constant( $name, $value ) { |
405 | - if ( ! defined( $name ) ) { |
|
406 | - define( $name, $value ); |
|
407 | - } |
|
405 | + if ( ! defined( $name ) ) { |
|
406 | + define( $name, $value ); |
|
407 | + } |
|
408 | 408 | } |
409 | 409 | |
410 | 410 | function wpinv_get_php_arg_separator_output() { |
411 | - return ini_get( 'arg_separator.output' ); |
|
411 | + return ini_get( 'arg_separator.output' ); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | function wpinv_rgb_from_hex( $color ) { |
@@ -719,16 +719,16 @@ discard block |
||
719 | 719 | return wp_kses( |
720 | 720 | html_entity_decode( $var ), |
721 | 721 | array( |
722 | - 'br' => array(), |
|
723 | - 'em' => array(), |
|
724 | - 'strong' => array(), |
|
725 | - 'b' => array(), |
|
726 | - 'small' => array(), |
|
727 | - 'span' => array(), |
|
728 | - 'ul' => array(), |
|
729 | - 'li' => array(), |
|
730 | - 'ol' => array(), |
|
731 | - 'p' => array(), |
|
722 | + 'br' => array(), |
|
723 | + 'em' => array(), |
|
724 | + 'strong' => array(), |
|
725 | + 'b' => array(), |
|
726 | + 'small' => array(), |
|
727 | + 'span' => array(), |
|
728 | + 'ul' => array(), |
|
729 | + 'li' => array(), |
|
730 | + 'ol' => array(), |
|
731 | + 'p' => array(), |
|
732 | 732 | ) |
733 | 733 | ); |
734 | 734 | } |
@@ -779,11 +779,11 @@ discard block |
||
779 | 779 | $list = array(); |
780 | 780 | } |
781 | 781 | |
782 | - if ( ! is_array( $list ) ) { |
|
783 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
784 | - } |
|
782 | + if ( ! is_array( $list ) ) { |
|
783 | + return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
784 | + } |
|
785 | 785 | |
786 | - return $list; |
|
786 | + return $list; |
|
787 | 787 | } |
788 | 788 | |
789 | 789 | /** |
@@ -824,17 +824,17 @@ discard block |
||
824 | 824 | */ |
825 | 825 | function wpinv_clean( $var ) { |
826 | 826 | |
827 | - if ( is_array( $var ) ) { |
|
828 | - return array_map( 'wpinv_clean', $var ); |
|
827 | + if ( is_array( $var ) ) { |
|
828 | + return array_map( 'wpinv_clean', $var ); |
|
829 | 829 | } |
830 | 830 | |
831 | 831 | if ( is_object( $var ) ) { |
832 | - $object_vars = get_object_vars( $var ); |
|
833 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
834 | - $var->$property_name = wpinv_clean( $property_value ); |
|
832 | + $object_vars = get_object_vars( $var ); |
|
833 | + foreach ( $object_vars as $property_name => $property_value ) { |
|
834 | + $var->$property_name = wpinv_clean( $property_value ); |
|
835 | 835 | } |
836 | 836 | return $var; |
837 | - } |
|
837 | + } |
|
838 | 838 | |
839 | 839 | return is_string( $var ) ? sanitize_text_field( stripslashes( $var ) ) : $var; |
840 | 840 | } |
@@ -847,7 +847,7 @@ discard block |
||
847 | 847 | */ |
848 | 848 | function getpaid_convert_price_string_to_options( $str ) { |
849 | 849 | |
850 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
850 | + $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
851 | 851 | $options = array(); |
852 | 852 | |
853 | 853 | foreach ( $raw_options as $option ) { |
@@ -936,7 +936,7 @@ discard block |
||
936 | 936 | * @return string |
937 | 937 | */ |
938 | 938 | function getpaid_date_format() { |
939 | - return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
939 | + return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
940 | 940 | } |
941 | 941 | |
942 | 942 | /** |
@@ -945,7 +945,7 @@ discard block |
||
945 | 945 | * @return string |
946 | 946 | */ |
947 | 947 | function getpaid_time_format() { |
948 | - return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
948 | + return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
949 | 949 | } |
950 | 950 | |
951 | 951 | /** |
@@ -958,15 +958,15 @@ discard block |
||
958 | 958 | function getpaid_limit_length( $string, $limit ) { |
959 | 959 | $str_limit = $limit - 3; |
960 | 960 | |
961 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
962 | - if ( mb_strlen( $string ) > $limit ) { |
|
963 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
964 | - } |
|
965 | - } else { |
|
966 | - if ( strlen( $string ) > $limit ) { |
|
967 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
968 | - } |
|
969 | - } |
|
961 | + if ( function_exists( 'mb_strimwidth' ) ) { |
|
962 | + if ( mb_strlen( $string ) > $limit ) { |
|
963 | + $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
964 | + } |
|
965 | + } else { |
|
966 | + if ( strlen( $string ) > $limit ) { |
|
967 | + $string = substr( $string, 0, $str_limit ) . '...'; |
|
968 | + } |
|
969 | + } |
|
970 | 970 | return $string; |
971 | 971 | |
972 | 972 | } |
@@ -1096,12 +1096,12 @@ discard block |
||
1096 | 1096 | $types = get_allowed_mime_types(); |
1097 | 1097 | |
1098 | 1098 | if ( isset( $types['htm|html'] ) ) { |
1099 | - unset( $types['htm|html'] ); |
|
1100 | - } |
|
1099 | + unset( $types['htm|html'] ); |
|
1100 | + } |
|
1101 | 1101 | |
1102 | 1102 | if ( isset( $types['js'] ) ) { |
1103 | - unset( $types['js'] ); |
|
1104 | - } |
|
1103 | + unset( $types['js'] ); |
|
1104 | + } |
|
1105 | 1105 | |
1106 | 1106 | return $types; |
1107 | 1107 | |
@@ -1157,11 +1157,11 @@ discard block |
||
1157 | 1157 | * @return string Returns converted string. |
1158 | 1158 | */ |
1159 | 1159 | function getpaid_strtolower( $string, $charset = 'UTF-8' ) { |
1160 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
1161 | - return mb_convert_case( $string, MB_CASE_LOWER, $charset ); |
|
1162 | - } else { |
|
1163 | - return strtolower( $string ); |
|
1164 | - } |
|
1160 | + if ( function_exists( 'mb_convert_case' ) ) { |
|
1161 | + return mb_convert_case( $string, MB_CASE_LOWER, $charset ); |
|
1162 | + } else { |
|
1163 | + return strtolower( $string ); |
|
1164 | + } |
|
1165 | 1165 | } |
1166 | 1166 | |
1167 | 1167 | /** |
@@ -1174,9 +1174,9 @@ discard block |
||
1174 | 1174 | * @return string Returns converted string. |
1175 | 1175 | */ |
1176 | 1176 | function getpaid_strtoupper( $string, $charset = 'UTF-8' ) { |
1177 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
1178 | - return mb_convert_case( $string, MB_CASE_UPPER, $charset ); |
|
1179 | - } else { |
|
1180 | - return strtoupper( $string ); |
|
1181 | - } |
|
1177 | + if ( function_exists( 'mb_convert_case' ) ) { |
|
1178 | + return mb_convert_case( $string, MB_CASE_UPPER, $charset ); |
|
1179 | + } else { |
|
1180 | + return strtoupper( $string ); |
|
1181 | + } |
|
1182 | 1182 | } |
1183 | 1183 | \ No newline at end of file |