@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Graph_Downloader Class. |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
32 | 32 | */ |
33 | - public function prepare_handler( $graph ) { |
|
33 | + public function prepare_handler($graph) { |
|
34 | 34 | |
35 | - if ( empty( $this->handler->views[ $graph ] ) ) { |
|
36 | - wp_die( __( 'Invalid Graph', 'invoicing' ), 400 ); |
|
35 | + if (empty($this->handler->views[$graph])) { |
|
36 | + wp_die(__('Invalid Graph', 'invoicing'), 400); |
|
37 | 37 | } |
38 | 38 | |
39 | - return new $this->handler->views[ $graph ]['class'](); |
|
39 | + return new $this->handler->views[$graph]['class'](); |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | |
@@ -47,10 +47,10 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function prepare_output() { |
49 | 49 | |
50 | - $output = fopen( 'php://output', 'w' ); |
|
50 | + $output = fopen('php://output', 'w'); |
|
51 | 51 | |
52 | - if ( false === $output ) { |
|
53 | - wp_die( __( 'Unsupported server', 'invoicing' ), 500 ); |
|
52 | + if (false === $output) { |
|
53 | + wp_die(__('Unsupported server', 'invoicing'), 500); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | return $output; |
@@ -61,13 +61,13 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @return string |
63 | 63 | */ |
64 | - public function prepare_file_type( $graph ) { |
|
64 | + public function prepare_file_type($graph) { |
|
65 | 65 | |
66 | - $file_type = empty( $_GET['file_type'] ) ? 'csv' : sanitize_text_field( $_GET['file_type'] ); |
|
67 | - $file_name = "getpaid-$graph-" . current_time( 'Y-m-d' ); |
|
66 | + $file_type = empty($_GET['file_type']) ? 'csv' : sanitize_text_field($_GET['file_type']); |
|
67 | + $file_name = "getpaid-$graph-" . current_time('Y-m-d'); |
|
68 | 68 | |
69 | - header( "Content-Type:application/$file_type" ); |
|
70 | - header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
69 | + header("Content-Type:application/$file_type"); |
|
70 | + header("Content-Disposition:attachment;filename=$file_name.$file_type"); |
|
71 | 71 | |
72 | 72 | return $file_type; |
73 | 73 | } |
@@ -76,24 +76,24 @@ discard block |
||
76 | 76 | * Handles the actual download. |
77 | 77 | * |
78 | 78 | */ |
79 | - public function download( $graph ) { |
|
79 | + public function download($graph) { |
|
80 | 80 | global $wpdb; |
81 | 81 | |
82 | - $handler = $this->prepare_handler( $graph ); |
|
82 | + $handler = $this->prepare_handler($graph); |
|
83 | 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 | - } else if( 'xml' == $file_type ) { |
|
91 | - $this->download_xml( $stats, $stream, $headers ); |
|
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 | + } else if ('xml' == $file_type) { |
|
91 | + $this->download_xml($stats, $stream, $headers); |
|
92 | 92 | } else { |
93 | - $this->download_json( $stats, $stream, $headers ); |
|
93 | + $this->download_json($stats, $stream, $headers); |
|
94 | 94 | } |
95 | 95 | |
96 | - fclose( $stream ); |
|
96 | + fclose($stream); |
|
97 | 97 | exit; |
98 | 98 | } |
99 | 99 | |
@@ -105,15 +105,15 @@ discard block |
||
105 | 105 | * @param array $headers The fields to stream. |
106 | 106 | * @since 1.0.19 |
107 | 107 | */ |
108 | - public function download_csv( $stats, $stream, $headers ) { |
|
108 | + public function download_csv($stats, $stream, $headers) { |
|
109 | 109 | |
110 | 110 | // Output the csv column headers. |
111 | - fputcsv( $stream, $headers ); |
|
111 | + fputcsv($stream, $headers); |
|
112 | 112 | |
113 | 113 | // Loop through |
114 | - foreach ( $stats as $stat ) { |
|
115 | - $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
116 | - fputcsv( $stream, $row ); |
|
114 | + foreach ($stats as $stat) { |
|
115 | + $row = array_values($this->prepare_row($stat, $headers)); |
|
116 | + fputcsv($stream, $row); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | } |
@@ -126,16 +126,16 @@ discard block |
||
126 | 126 | * @param array $headers The fields to stream. |
127 | 127 | * @since 1.0.19 |
128 | 128 | */ |
129 | - public function download_json( $stats, $stream, $headers ) { |
|
129 | + public function download_json($stats, $stream, $headers) { |
|
130 | 130 | |
131 | 131 | $prepared = array(); |
132 | 132 | |
133 | 133 | // Loop through |
134 | - foreach ( $stats as $stat ) { |
|
135 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
134 | + foreach ($stats as $stat) { |
|
135 | + $prepared[] = $this->prepare_row($stat, $headers); |
|
136 | 136 | } |
137 | 137 | |
138 | - fwrite( $stream, wp_json_encode( $prepared ) ); |
|
138 | + fwrite($stream, wp_json_encode($prepared)); |
|
139 | 139 | |
140 | 140 | } |
141 | 141 | |
@@ -147,19 +147,19 @@ discard block |
||
147 | 147 | * @param array $headers The fields to stream. |
148 | 148 | * @since 1.0.19 |
149 | 149 | */ |
150 | - public function download_xml( $stats, $stream, $headers ) { |
|
150 | + public function download_xml($stats, $stream, $headers) { |
|
151 | 151 | |
152 | 152 | $prepared = array(); |
153 | 153 | |
154 | 154 | // Loop through |
155 | - foreach ( $stats as $stat ) { |
|
156 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
155 | + foreach ($stats as $stat) { |
|
156 | + $prepared[] = $this->prepare_row($stat, $headers); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | $xml = new SimpleXMLElement('<?xml version="1.0"?><data></data>'); |
160 | - $this->convert_array_xml( $prepared, $xml ); |
|
160 | + $this->convert_array_xml($prepared, $xml); |
|
161 | 161 | |
162 | - fwrite( $stream, $xml->asXML() ); |
|
162 | + fwrite($stream, $xml->asXML()); |
|
163 | 163 | |
164 | 164 | } |
165 | 165 | |
@@ -169,24 +169,24 @@ discard block |
||
169 | 169 | * @access public |
170 | 170 | * @since 1.0.19 |
171 | 171 | */ |
172 | - public function convert_array_xml( $data, $xml ) { |
|
172 | + public function convert_array_xml($data, $xml) { |
|
173 | 173 | |
174 | 174 | // Loop through |
175 | - foreach ( $data as $key => $value ) { |
|
175 | + foreach ($data as $key => $value) { |
|
176 | 176 | |
177 | - $key = preg_replace( "/[^A-Za-z0-9_\-]/", '', $key ); |
|
177 | + $key = preg_replace("/[^A-Za-z0-9_\-]/", '', $key); |
|
178 | 178 | |
179 | - if ( is_array( $value ) ) { |
|
179 | + if (is_array($value)) { |
|
180 | 180 | |
181 | - if ( is_numeric( $key ) ){ |
|
182 | - $key = 'item'.$key; //dealing with <0/>..<n/> issues |
|
181 | + if (is_numeric($key)) { |
|
182 | + $key = 'item' . $key; //dealing with <0/>..<n/> issues |
|
183 | 183 | } |
184 | 184 | |
185 | - $subnode = $xml->addChild( $key ); |
|
186 | - $this->convert_array_xml( $value, $subnode ); |
|
185 | + $subnode = $xml->addChild($key); |
|
186 | + $this->convert_array_xml($value, $subnode); |
|
187 | 187 | |
188 | 188 | } else { |
189 | - $xml->addChild( $key, htmlspecialchars( $value ) ); |
|
189 | + $xml->addChild($key, htmlspecialchars($value)); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | } |
@@ -201,24 +201,24 @@ discard block |
||
201 | 201 | * @since 1.0.19 |
202 | 202 | * @return array |
203 | 203 | */ |
204 | - public function prepare_row( $row, $fields ) { |
|
204 | + public function prepare_row($row, $fields) { |
|
205 | 205 | |
206 | 206 | $prepared = array(); |
207 | 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 ); |
|
211 | + if ($field === 'total') { |
|
212 | + $prepared[$field] = html_entity_decode(strip_tags(wpinv_price($row['total'])), ENT_QUOTES); |
|
213 | 213 | continue; |
214 | 214 | } |
215 | 215 | |
216 | - if ( $field === 'total_raw' ) { |
|
217 | - $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
216 | + if ($field === 'total_raw') { |
|
217 | + $prepared[$field] = wpinv_round_amount(wpinv_sanitize_amount($row['total'])); |
|
218 | 218 | continue; |
219 | 219 | } |
220 | 220 | |
221 | - $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
221 | + $prepared[$field] = strip_tags($row[$field]); |
|
222 | 222 | |
223 | 223 | } |
224 | 224 |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports Class. |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | * |
18 | 18 | */ |
19 | 19 | public function __construct() { |
20 | - add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
21 | - add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
22 | - add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
23 | - add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
20 | + add_action('admin_menu', array($this, 'register_reports_page'), 20); |
|
21 | + add_action('wpinv_reports_tab_reports', array($this, 'display_reports_tab')); |
|
22 | + add_action('wpinv_reports_tab_export', array($this, 'display_exports_tab')); |
|
23 | + add_action('getpaid_authenticated_admin_action_download_graph', array($this, 'download_graph')); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -31,11 +31,11 @@ discard block |
||
31 | 31 | |
32 | 32 | add_submenu_page( |
33 | 33 | 'wpinv', |
34 | - __( 'Reports', 'invoicing' ), |
|
35 | - __( 'Reports', 'invoicing' ), |
|
34 | + __('Reports', 'invoicing'), |
|
35 | + __('Reports', 'invoicing'), |
|
36 | 36 | wpinv_get_capability(), |
37 | 37 | 'wpinv-reports', |
38 | - array( $this, 'display_reports_page' ) |
|
38 | + array($this, 'display_reports_page') |
|
39 | 39 | ); |
40 | 40 | |
41 | 41 | } |
@@ -48,26 +48,26 @@ discard block |
||
48 | 48 | |
49 | 49 | // Prepare variables. |
50 | 50 | $tabs = $this->get_tabs(); |
51 | - $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
52 | - $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
51 | + $current_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'reports'; |
|
52 | + $current_tab = array_key_exists($current_tab, $tabs) ? $current_tab : 'reports'; |
|
53 | 53 | |
54 | 54 | // Display the current tab. |
55 | 55 | ?> |
56 | 56 | |
57 | 57 | <div class="wrap"> |
58 | 58 | |
59 | - <h1><?php echo sanitize_text_field( $tabs[ $current_tab ] ); ?></h1> |
|
59 | + <h1><?php echo sanitize_text_field($tabs[$current_tab]); ?></h1> |
|
60 | 60 | |
61 | 61 | <nav class="nav-tab-wrapper"> |
62 | 62 | |
63 | 63 | <?php |
64 | - foreach( $tabs as $key => $label ) { |
|
64 | + foreach ($tabs as $key => $label) { |
|
65 | 65 | |
66 | - $key = sanitize_text_field( $key ); |
|
67 | - $label = sanitize_text_field( $label ); |
|
66 | + $key = sanitize_text_field($key); |
|
67 | + $label = sanitize_text_field($label); |
|
68 | 68 | $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
69 | 69 | $url = esc_url( |
70 | - add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) ) |
|
70 | + add_query_arg('tab', $key, admin_url('admin.php?page=wpinv-reports')) |
|
71 | 71 | ); |
72 | 72 | |
73 | 73 | echo "\n\t\t\t<a href='$url' class='$class'>$label</a>"; |
@@ -77,15 +77,15 @@ discard block |
||
77 | 77 | |
78 | 78 | </nav> |
79 | 79 | |
80 | - <div class="bsui <?php echo esc_attr( $current_tab ); ?>"> |
|
81 | - <?php do_action( "wpinv_reports_tab_{$current_tab}" ); ?> |
|
80 | + <div class="bsui <?php echo esc_attr($current_tab); ?>"> |
|
81 | + <?php do_action("wpinv_reports_tab_{$current_tab}"); ?> |
|
82 | 82 | </div> |
83 | 83 | |
84 | 84 | </div> |
85 | 85 | <?php |
86 | 86 | |
87 | - wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true ); |
|
88 | - wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' ); |
|
87 | + wp_enqueue_script('chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array('jquery'), '2.9.4', true); |
|
88 | + wp_enqueue_style('chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4'); |
|
89 | 89 | |
90 | 90 | } |
91 | 91 | |
@@ -97,11 +97,11 @@ discard block |
||
97 | 97 | public function get_tabs() { |
98 | 98 | |
99 | 99 | $tabs = array( |
100 | - 'reports' => __( 'Reports', 'invoicing' ), |
|
101 | - 'export' => __( 'Export', 'invoicing' ), |
|
100 | + 'reports' => __('Reports', 'invoicing'), |
|
101 | + 'export' => __('Export', 'invoicing'), |
|
102 | 102 | ); |
103 | 103 | |
104 | - return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
104 | + return apply_filters('getpaid_report_tabs', $tabs); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @param array $args |
133 | 133 | */ |
134 | - public function download_graph( $args ) { |
|
134 | + public function download_graph($args) { |
|
135 | 135 | |
136 | - if ( ! empty( $args['graph'] ) ) { |
|
136 | + if (!empty($args['graph'])) { |
|
137 | 137 | $downloader = new GetPaid_Graph_Downloader(); |
138 | - $downloader->download( $args['graph'] ); |
|
138 | + $downloader->download($args['graph']); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports_Report Class. |
@@ -23,26 +23,26 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function __construct() { |
25 | 25 | |
26 | - $this->views = array( |
|
26 | + $this->views = array( |
|
27 | 27 | |
28 | 28 | 'items' => array( |
29 | - 'label' => __( 'Items', 'invoicing' ), |
|
29 | + 'label' => __('Items', 'invoicing'), |
|
30 | 30 | 'class' => 'GetPaid_Reports_Report_Items', |
31 | 31 | ), |
32 | 32 | |
33 | 33 | 'gateways' => array( |
34 | - 'label' => __( 'Payment Methods', 'invoicing' ), |
|
34 | + 'label' => __('Payment Methods', 'invoicing'), |
|
35 | 35 | 'class' => 'GetPaid_Reports_Report_Gateways', |
36 | 36 | ), |
37 | 37 | |
38 | 38 | 'discounts' => array( |
39 | - 'label' => __( 'Discount Codes', 'invoicing' ), |
|
39 | + 'label' => __('Discount Codes', 'invoicing'), |
|
40 | 40 | 'class' => 'GetPaid_Reports_Report_Discounts', |
41 | 41 | ), |
42 | 42 | |
43 | 43 | ); |
44 | 44 | |
45 | - $this->views = apply_filters( 'wpinv_report_views', $this->views ); |
|
45 | + $this->views = apply_filters('wpinv_report_views', $this->views); |
|
46 | 46 | |
47 | 47 | } |
48 | 48 | |
@@ -84,14 +84,14 @@ discard block |
||
84 | 84 | * Retrieves the download url. |
85 | 85 | * |
86 | 86 | */ |
87 | - public function get_download_url( $graph, $file_type) { |
|
87 | + public function get_download_url($graph, $file_type) { |
|
88 | 88 | |
89 | 89 | return wp_nonce_url( |
90 | 90 | add_query_arg( |
91 | 91 | array( |
92 | 92 | 'getpaid-admin-action' => 'download_graph', |
93 | - 'file_type' => urlencode( $file_type ), |
|
94 | - 'graph' => urlencode( $graph ), |
|
93 | + 'file_type' => urlencode($file_type), |
|
94 | + 'graph' => urlencode($graph), |
|
95 | 95 | ) |
96 | 96 | ), |
97 | 97 | 'getpaid-nonce', |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | |
109 | 109 | ?> |
110 | 110 | |
111 | - <?php foreach ( $this->views as $key => $view ) : ?> |
|
111 | + <?php foreach ($this->views as $key => $view) : ?> |
|
112 | 112 | <div class="row mb-4"> |
113 | 113 | <div class="col-12"> |
114 | 114 | <div class="card m-0 p-0" style="max-width:100%"> |
@@ -118,17 +118,17 @@ discard block |
||
118 | 118 | <strong><?php echo $view['label']; ?></strong> |
119 | 119 | </div> |
120 | 120 | <div class="col-3"> |
121 | - <a title="<?php esc_attr_e( 'Download JSON', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'json' ) ); ?>"> |
|
121 | + <a title="<?php esc_attr_e('Download JSON', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'json')); ?>"> |
|
122 | 122 | <i class="fa fa-download text-dark" style="font-size: 16px" aria-hidden="true"></i> |
123 | - <span class="screen-reader-text"><?php _e( 'Download JSON', 'invoicing' ); ?></span> |
|
123 | + <span class="screen-reader-text"><?php _e('Download JSON', 'invoicing'); ?></span> |
|
124 | 124 | </a> |
125 | - <a title="<?php esc_attr_e( 'Download CSV', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'csv' ) ); ?>"> |
|
125 | + <a title="<?php esc_attr_e('Download CSV', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'csv')); ?>"> |
|
126 | 126 | <i class="fa fa-file-csv text-dark" style="font-size: 16px" aria-hidden="true"></i> |
127 | - <span class="screen-reader-text"><?php _e( 'Download CSV', 'invoicing' ); ?></span> |
|
127 | + <span class="screen-reader-text"><?php _e('Download CSV', 'invoicing'); ?></span> |
|
128 | 128 | </a> |
129 | - <a title="<?php esc_attr_e( 'Download XML', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'xml' ) ); ?>"> |
|
129 | + <a title="<?php esc_attr_e('Download XML', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'xml')); ?>"> |
|
130 | 130 | <i class="fa fa-file-code text-dark" style="font-size: 16px" aria-hidden="true"></i> |
131 | - <span class="screen-reader-text"><?php _e( 'Download XML', 'invoicing' ); ?></span> |
|
131 | + <span class="screen-reader-text"><?php _e('Download XML', 'invoicing'); ?></span> |
|
132 | 132 | </a> |
133 | 133 | </div> |
134 | 134 | </div> |