PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
← All changes | includes/admin/tools/export/pdf-reports.php +85 -84 2.3.04.17.0 View file →
@@ -3,9 +3,9 @@
3 3 * PDF Report Generation Functions.
4 4 *
5 5 * @package Give
6 6 * @subpackage Admin/Reports
7 - * @copyright Copyright (c) 2016, WordImpress
7 + * @copyright Copyright (c) 2016, GiveWP
8 8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 9 * @since 1.0
10 10 */
11 11
@@ -18,26 +18,26 @@
18 18 * Generate PDF Reports.
19 19 *
20 20 * Generates PDF report on donations and income for all forms for the current year.
21 21 *
22 + * @param string $data Data.
23 + *
22 24 * @since 1.0
23 25 *
24 - * @param string $data Data.
25 - *
26 26 * @uses give_pdf
27 27 */
28 28 function give_generate_pdf( $data ) {
29 29
30 30 if ( ! current_user_can( 'view_give_reports' ) ) {
31 - wp_die( __( 'You do not have permission to generate PDF sales reports.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
31 + wp_die( __( 'You do not have permission to generate PDF sales reports.', 'give' ), __( 'Error', 'give' ), [ 'response' => 403 ] );
32 32 }
33 33
34 34 if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'give_generate_pdf' ) ) {
35 - wp_die( __( 'Nonce verification failed.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
35 + wp_die( __( 'We\'re unable to recognize your session. Please refresh the screen to try again; otherwise contact your website administrator for assistance.', 'give' ), __( 'Error', 'give' ), [ 'response' => 403 ] );
36 36 }
37 37
38 38 if ( ! file_exists( GIVE_PLUGIN_DIR . '/includes/libraries/give-pdf.php' ) ) {
39 - wp_die( __( 'Dependency missing.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
39 + wp_die( __( 'Dependency missing.', 'give' ), __( 'Error', 'give' ), [ 'response' => 403 ] );
40 40 }
41 41
42 42 require_once GIVE_PLUGIN_DIR . '/includes/libraries/give-pdf.php';
43 43
@@ -56,21 +56,14 @@
56 56 $pdf = new Give_PDF( 'L', 'mm', 'A', true, 'UTF-8', false );
57 57 $default_font = apply_filters( 'give_pdf_default_font', 'Helvetica' );
58 58 $custom_font = 'dejavusans';
59 59 $font_style = '';
60 - $font_path = '';
60 + $font_path = GIVE_PLUGIN_DIR . '/vendor/tecnickcom/tcpdf/fonts/CODE2000.TTF';
61 61
62 - if ( file_exists( GIVE_PLUGIN_DIR . 'vendor/autoload.php' ) ) {
63 - $font_path = GIVE_PLUGIN_DIR . '/vendor/tecnickcom/tcpdf/fonts/CODE2000.TTF';
64 - } else {
65 - $font_path = GIVE_PLUGIN_DIR . '/includes/libraries/tcpdf/fonts/CODE2000.TTF';
66 - }
67 -
68 62 if (
69 63 file_exists( $font_path ) &&
70 -
71 64 // RIAL exist for backward compatibility.
72 - in_array( give_get_currency(), array( 'RIAL', 'RUB', 'IRR' ) )
65 + in_array( give_get_currency(), [ 'RIAL', 'RUB', 'IRR' ] )
73 66 ) {
74 67 TCPDF_FONTS::addTTFfont( $font_path, '' );
75 68 $custom_font = 'CODE2000';
76 69 $font_style = 'B';
@@ -78,13 +71,13 @@
78 71
79 72 $pdf->AddPage( 'L', 'A4' );
80 73 $pdf->setImageScale( 1.5 );
81 74 $pdf->SetTitle( utf8_decode( __( 'Donation report for the current year for all forms', 'give' ) ) );
82 - $pdf->SetAuthor( utf8_decode( __( 'Give - Democratizing Generosity', 'give' ) ) );
83 - $pdf->SetCreator( utf8_decode( __( 'Give - Democratizing Generosity', 'give' ) ) );
75 + $pdf->SetAuthor( utf8_decode( __( 'GiveWP - Democratizing Generosity', 'give' ) ) );
76 + $pdf->SetCreator( utf8_decode( __( 'GiveWP - Democratizing Generosity', 'give' ) ) );
84 77
85 78 // Image URL should have absolute path. @see https://tcpdf.org/examples/example_009/.
86 - $pdf->Image( apply_filters( 'give_pdf_export_logo', GIVE_PLUGIN_DIR . 'assets/dist/images/give-logo-small.png' ), 247, 8 );
79 + $pdf->Image( apply_filters( 'give_pdf_export_logo', GIVE_PLUGIN_DIR . 'build/assets/dist/images/give-logo-small.png' ), 247, 8 );
87 80
88 81 $pdf->SetMargins( 8, 8, 8 );
89 82 $pdf->SetX( 8 );
90 83
@@ -117,9 +110,9 @@
117 110 $pdf->Cell( 45, 6, utf8_decode( __( 'Tags', 'give' ) ), 1, 0, 'L', true );
118 111 }
119 112
120 113 $pdf->Cell( 45, 6, utf8_decode( __( 'Number of Donations', 'give' ) ), 1, 0, 'L', true );
121 - $pdf->Cell( 45, 6, utf8_decode( __( 'Income to Date', 'give' ) ), 1, 1, 'L', true );
114 + $pdf->Cell( 45, 6, utf8_decode( __( 'Revenue to Date', 'give' ) ), 1, 1, 'L', true );
122 115
123 116 // Set Custom Font to support various currencies.
124 117 $pdf->SetFont( apply_filters( 'give_pdf_custom_font', $custom_font ), $font_style, 12 );
125 118
@@ -125,18 +118,20 @@
125 118
126 119 // Object for getting stats.
127 120 $donation_stats = new Give_Payment_Stats();
128 121
129 - $give_forms = get_posts( array(
130 - 'post_type' => 'give_forms',
131 - 'posts_per_page' => - 1,
132 - 'suppress_filters' => false,
133 - ) );
122 + $give_forms = get_posts(
123 + [
124 + 'post_type' => 'give_forms',
125 + 'posts_per_page' => - 1,
126 + 'suppress_filters' => false,
127 + ]
128 + );
134 129
135 130 if ( $give_forms ) {
136 - $pdf->SetWidths( array( 50, 50, 45, 45, 45, 45 ) );
131 + $pdf->SetWidths( [ 50, 50, 45, 45, 45, 45 ] );
137 132
138 - foreach ( $give_forms as $form ):
133 + foreach ( $give_forms as $form ) :
139 134 $pdf->SetFillColor( 255, 255, 255 );
140 135
141 136 $title = $form->post_title;
142 137
@@ -142,13 +137,13 @@
142 137
143 138 if ( give_has_variable_prices( $form->ID ) ) {
144 139 $price = html_entity_decode( give_price_range( $form->ID, false ), ENT_COMPAT, 'UTF-8' );
145 140 } else {
146 - $price = give_currency_filter( give_get_form_price( $form->ID ), array( 'decode_currency' => true ) );
141 + $price = give_currency_filter( give_get_form_price( $form->ID ), [ 'decode_currency' => true ] );
147 142 }
148 143
149 144 // Display Categories Data only, if user has opted for it.
150 - $categories = array();
145 + $categories = [];
151 146 if ( $categories_enabled ) {
152 147 $categories = get_the_term_list( $form->ID, 'give_forms_category', '', ', ', '' );
153 148 $categories = ! is_wp_error( $categories ) ? strip_tags( $categories ) : '';
154 149 }
@@ -153,9 +148,9 @@
153 148 $categories = ! is_wp_error( $categories ) ? strip_tags( $categories ) : '';
154 149 }
155 150
156 151 // Display Tags Data only, if user has opted for it.
157 - $tags = array();
152 + $tags = [];
158 153 if ( $tags_enabled ) {
159 154 $tags = get_the_term_list( $form->ID, 'give_forms_tag', '', ', ', '' );
160 155 $tags = ! is_wp_error( $tags ) ? strip_tags( $tags ) : '';
161 156 }
@@ -160,12 +155,12 @@
160 155 $tags = ! is_wp_error( $tags ) ? strip_tags( $tags ) : '';
161 156 }
162 157
163 158 $sales = $donation_stats->get_sales( $form->ID, 'this_year' );
164 - $earnings = give_currency_filter( give_format_amount( $donation_stats->get_earnings( $form->ID, 'this_year' ), array( 'sanitize' => false, ) ), array( 'decode_currency' => true ) );
159 + $earnings = give_currency_filter( give_format_amount( $donation_stats->get_earnings( $form->ID, 'this_year' ), [ 'sanitize' => false ] ), [ 'decode_currency' => true ] );
165 160
166 161 // This will help filter data before appending it to PDF Receipt.
167 - $prepare_pdf_data = array();
162 + $prepare_pdf_data = [];
168 163 $prepare_pdf_data[] = $title;
169 164 $prepare_pdf_data[] = $price;
170 165
171 166 // Append Categories Data only, if user has opted for it.
@@ -223,15 +218,15 @@
223 218 *
224 219 * Draws the sales and earnings chart for the PDF report and then retrieves the
225 220 * URL of that chart to display on the PDF Report.
226 221 *
227 - * @since 1.1.4.0
222 + * @return string $chart->getUrl() URL for the Google Chart
228 223 * @uses GoogleChart
229 224 * @uses GoogleChartData
230 225 * @uses GoogleChartShapeMarker
231 226 * @uses GoogleChartTextMarker
232 227 * @uses GoogleChartAxis
233 - * @return string $chart->getUrl() URL for the Google Chart
228 + * @since 1.1.4.0
234 229 */
235 230 function give_draw_chart_image() {
236 231 require_once GIVE_PLUGIN_DIR . '/includes/libraries/googlechartlib/GoogleChart.php';
237 232 require_once GIVE_PLUGIN_DIR . '/includes/libraries/googlechartlib/markers/GoogleChartShapeMarker.php';
@@ -239,19 +234,19 @@
239 234
240 235 $chart = new GoogleChart( 'lc', 900, 330 );
241 236
242 237 $i = 1;
243 - $earnings = "";
244 - $sales = "";
238 + $earnings = '';
239 + $sales = '';
245 240
246 241 while ( $i <= 12 ) :
247 - $earnings .= give_get_earnings_by_date( null, $i, date( 'Y' ) ) . ",";
248 - $sales .= give_get_sales_by_date( null, $i, date( 'Y' ) ) . ",";
242 + $earnings .= give_get_earnings_by_date( null, $i, date( 'Y' ) ) . ',';
243 + $sales .= give_get_sales_by_date( null, $i, date( 'Y' ) ) . ',';
249 244 $i ++;
250 245 endwhile;
251 246
252 - $earnings_array = explode( ",", $earnings );
253 - $sales_array = explode( ",", $sales );
247 + $earnings_array = explode( ',', $earnings );
248 + $sales_array = explode( ',', $sales );
254 249
255 250 $i = 0;
256 251 while ( $i <= 11 ) {
257 252 if ( empty( $sales_array[ $i ] ) ) {
@@ -263,24 +258,26 @@
263 258 $min_earnings = 0;
264 259 $max_earnings = max( $earnings_array );
265 260 $earnings_scale = round( $max_earnings, - 1 );
266 261
267 - $data = new GoogleChartData( array(
268 - $earnings_array[0],
269 - $earnings_array[1],
270 - $earnings_array[2],
271 - $earnings_array[3],
272 - $earnings_array[4],
273 - $earnings_array[5],
274 - $earnings_array[6],
275 - $earnings_array[7],
276 - $earnings_array[8],
277 - $earnings_array[9],
278 - $earnings_array[10],
279 - $earnings_array[11],
280 - ) );
262 + $data = new GoogleChartData(
263 + [
264 + $earnings_array[0],
265 + $earnings_array[1],
266 + $earnings_array[2],
267 + $earnings_array[3],
268 + $earnings_array[4],
269 + $earnings_array[5],
270 + $earnings_array[6],
271 + $earnings_array[7],
272 + $earnings_array[8],
273 + $earnings_array[9],
274 + $earnings_array[10],
275 + $earnings_array[11],
276 + ]
277 + );
281 278
282 - $data->setLegend( __( 'Income', 'give' ) );
279 + $data->setLegend( __( 'Revenue', 'give' ) );
283 280 $data->setColor( '1b58a3' );
284 281 $chart->addData( $data );
285 282
286 283 $shape_marker = new GoogleChartShapeMarker( GoogleChartShapeMarker::CIRCLE );
@@ -294,50 +291,54 @@
294 291 $value_marker->setColor( '000000' );
295 292 $value_marker->setData( $data );
296 293 $chart->addMarker( $value_marker );
297 294
298 - $data = new GoogleChartData( array(
299 - $sales_array[0],
300 - $sales_array[1],
301 - $sales_array[2],
302 - $sales_array[3],
303 - $sales_array[4],
304 - $sales_array[5],
305 - $sales_array[6],
306 - $sales_array[7],
307 - $sales_array[8],
308 - $sales_array[9],
309 - $sales_array[10],
310 - $sales_array[11],
311 - ) );
295 + $data = new GoogleChartData(
296 + [
297 + $sales_array[0],
298 + $sales_array[1],
299 + $sales_array[2],
300 + $sales_array[3],
301 + $sales_array[4],
302 + $sales_array[5],
303 + $sales_array[6],
304 + $sales_array[7],
305 + $sales_array[8],
306 + $sales_array[9],
307 + $sales_array[10],
308 + $sales_array[11],
309 + ]
310 + );
312 311 $data->setLegend( __( 'Donations', 'give' ) );
313 312 $data->setColor( 'ff6c1c' );
314 313 $chart->addData( $data );
315 314
316 - $chart->setTitle( __( 'Donations by Month for all Give Forms', 'give' ), '336699', 18 );
315 + $chart->setTitle( __( 'Donations by Month for all GiveWP Forms', 'give' ), '336699', 18 );
317 316
318 317 $chart->setScale( 0, $max_earnings );
319 318
320 319 $y_axis = new GoogleChartAxis( 'y' );
321 - $y_axis->setDrawTickMarks( true )->setLabels( array( 0, $max_earnings ) );
320 + $y_axis->setDrawTickMarks( true )->setLabels( [ 0, $max_earnings ] );
322 321 $chart->addAxis( $y_axis );
323 322
324 323 $x_axis = new GoogleChartAxis( 'x' );
325 324 $x_axis->setTickMarks( 5 );
326 - $x_axis->setLabels( array(
327 - __( 'Jan', 'give' ),
328 - __( 'Feb', 'give' ),
329 - __( 'Mar', 'give' ),
330 - __( 'Apr', 'give' ),
331 - __( 'May', 'give' ),
332 - __( 'June', 'give' ),
333 - __( 'July', 'give' ),
334 - __( 'Aug', 'give' ),
335 - __( 'Sept', 'give' ),
336 - __( 'Oct', 'give' ),
337 - __( 'Nov', 'give' ),
338 - __( 'Dec', 'give' ),
339 - ) );
325 + $x_axis->setLabels(
326 + [
327 + __( 'Jan', 'give' ),
328 + __( 'Feb', 'give' ),
329 + __( 'Mar', 'give' ),
330 + __( 'Apr', 'give' ),
331 + __( 'May', 'give' ),
332 + __( 'June', 'give' ),
333 + __( 'July', 'give' ),
334 + __( 'Aug', 'give' ),
335 + __( 'Sept', 'give' ),
336 + __( 'Oct', 'give' ),
337 + __( 'Nov', 'give' ),
338 + __( 'Dec', 'give' ),
339 + ]
340 + );
340 341 $chart->addAxis( $x_axis );
341 342
342 343 $shape_marker = new GoogleChartShapeMarker( GoogleChartShapeMarker::CIRCLE );
343 344 $shape_marker->setSize( 6 );