PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.4.3
GiveWP – Donation Plugin and Fundraising Platform v2.4.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 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / tools / export / class-batch-export.php
give / includes / admin / tools / export Last commit date
class-batch-export-donors.php 7 years ago class-batch-export.php 7 years ago class-core-settings-export.php 7 years ago class-export-earnings.php 7 years ago class-export.php 7 years ago class-give-export-donations.php 7 years ago export-actions.php 7 years ago export-functions.php 7 years ago give-export-donations-exporter.php 7 years ago give-export-donations-functions.php 7 years ago pdf-reports.php 7 years ago
class-batch-export.php
347 lines
1 <?php
2 /**
3 * Batch Export Class
4 *
5 * This is the base class for all batch export methods. Each data export type (donors, payments, etc) extend this class.
6 *
7 * @package Give
8 * @subpackage Admin/Export
9 * @copyright Copyright (c) 2016, GiveWP
10 * @license https://opensource.org/licenses/gpl-license GNU Public License
11 * @since 1.5
12 */
13
14 // Exit if accessed directly.
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 /**
20 * Give_Batch_Export Class
21 *
22 * @since 1.5
23 */
24 class Give_Batch_Export extends Give_Export {
25
26 /**
27 * The file the data is stored in.
28 *
29 * @since 1.5
30 */
31 private $file;
32
33 /**
34 * The name of the file the data is stored in.
35 *
36 * @since 1.5
37 */
38 public $filename;
39
40 /**
41 * The file type, typically .csv
42 *
43 * @since 1.5
44 */
45 public $filetype;
46
47 /**
48 * The current step being processed.
49 *
50 * @since 1.5
51 */
52 public $step;
53
54 /**
55 * Start date, Y-m-d H:i:s
56 *
57 * @since 1.5
58 */
59 public $start;
60
61 /**
62 * End date, Y-m-d H:i:s
63 *
64 * @since 1.5
65 */
66 public $end;
67
68 /**
69 * Status to export.
70 *
71 * @since 1.5
72 */
73 public $status;
74
75 /**
76 * Form to export data for.
77 *
78 * @since 1.5
79 */
80 public $form = null;
81
82 /**
83 * Form Price ID to export data for.
84 *
85 * @since 1.5
86 */
87 public $price_id = null;
88
89 /**
90 * Is the export file writable.
91 *
92 * @since 1.5
93 */
94 public $is_writable = true;
95
96 /**
97 * Is the export file empty.
98 *
99 * @since 1.5
100 */
101 public $is_empty = false;
102
103 /**
104 *
105 * @since 1.8.9
106 */
107 public $is_void = false;
108
109 /**
110 * Is the export file complete.
111 *
112 * @since 1.8.9
113 */
114 public $done = false;
115
116 /**
117 * Give_Batch_Export constructor.
118 *
119 * @param int $_step
120 */
121 public function __construct( $_step = 1 ) {
122
123 $upload_dir = wp_upload_dir();
124 $this->filetype = '.csv';
125 $this->filename = 'give-' . $this->export_type . $this->filetype;
126 $this->file = trailingslashit( $upload_dir['basedir'] ) . $this->filename;
127
128 if ( ! is_writeable( $upload_dir['basedir'] ) ) {
129 $this->is_writable = false;
130 }
131
132 $this->step = $_step;
133 $this->done = false;
134 }
135
136 /**
137 * Process a step.
138 *
139 * @since 1.5
140 * @return bool
141 */
142 public function process_step() {
143
144 if ( ! $this->can_export() ) {
145 wp_die( esc_html__( 'You do not have permission to export data.', 'give' ), esc_html__( 'Error', 'give' ), array(
146 'response' => 403,
147 ) );
148 }
149
150 if ( $this->step < 2 ) {
151
152 // Make sure we start with a fresh file on step 1.
153 @unlink( $this->file );
154 $this->print_csv_cols();
155 }
156
157 $this->print_csv_rows();
158
159 return 100 !== $this->get_percentage_complete();
160 }
161
162 /**
163 * Output the CSV columns.
164 *
165 * @access public
166 * @since 1.5
167 * @uses Give_Export::get_csv_cols()
168 * @return string
169 */
170 public function print_csv_cols() {
171
172 $col_data = '';
173 $cols = $this->get_csv_cols();
174 $i = 1;
175 foreach ( $cols as $col_id => $column ) {
176 $col_data .= '"' . addslashes( $column ) . '"';
177 $col_data .= $i == count( $cols ) ? '' : ',';
178 $i ++;
179 }
180 $col_data .= "\r\n";
181
182 $this->stash_step_data( $col_data );
183
184 return $col_data;
185
186 }
187
188 /**
189 * Print the CSV rows for the current step.
190 *
191 * @access public
192 * @since 1.5
193 * @return string|false
194 */
195 public function print_csv_rows() {
196
197 $row_data = '';
198 $data = $this->get_data();
199 $cols = $this->get_csv_cols();
200
201 if ( $data ) {
202
203 // Output each row
204 foreach ( $data as $row ) {
205 $i = 1;
206 foreach ( $row as $col_id => $column ) {
207 // Make sure the column is valid
208 if ( array_key_exists( $col_id, $cols ) ) {
209 $row_data .= '"' . addslashes( preg_replace( '/"/', "'", $column ) ) . '"';
210 $row_data .= $i == count( $cols ) ? '' : ',';
211 $i ++;
212 }
213 }
214 $row_data .= "\r\n";
215 }
216
217 $this->stash_step_data( $row_data );
218
219 return $row_data;
220 }
221
222 return false;
223 }
224
225 /**
226 * Return the calculated completion percentage.
227 *
228 * @since 1.5
229 * @return int
230 */
231 public function get_percentage_complete() {
232 return 100;
233 }
234
235 /**
236 * Retrieve the file data is written to.
237 *
238 * @since 1.5
239 * @return string
240 */
241 protected function get_file() {
242
243 $file = '';
244
245 if ( @file_exists( $this->file ) ) {
246
247 if ( ! is_writeable( $this->file ) ) {
248 $this->is_writable = false;
249 }
250
251 $file = @file_get_contents( $this->file );
252
253 } else {
254
255 @file_put_contents( $this->file, '' );
256 @chmod( $this->file, 0664 );
257
258 }
259
260 return $file;
261 }
262
263 /**
264 * Append data to export file.
265 *
266 * @since 1.5
267 *
268 * @param $data string The data to add to the file.
269 *
270 * @return void
271 */
272 protected function stash_step_data( $data = '' ) {
273
274 $file = $this->get_file();
275 $file .= $data;
276 @file_put_contents( $this->file, $file );
277
278 // If we have no rows after this step, mark it as an empty export.
279 $file_rows = file( $this->file, FILE_SKIP_EMPTY_LINES );
280 $default_cols = $this->get_csv_cols();
281 $default_cols = empty( $default_cols ) ? 0 : 1;
282
283 $this->is_empty = count( $file_rows ) == $default_cols ? true : false;
284
285 }
286
287 /**
288 * Perform the export.
289 *
290 * @access public
291 * @since 1.5
292 * @return void
293 */
294 public function export() {
295
296 // Set headers
297 $this->headers();
298
299 $file = $this->get_file();
300
301 @unlink( $this->file );
302
303 echo $file;
304
305 /**
306 * Fire action after file output.
307 *
308 * @since 1.8
309 */
310 do_action( 'give_file_export_complete', $_REQUEST );
311
312 give_die();
313 }
314
315 /**
316 * Set the properties specific to the export.
317 *
318 * @since 1.5
319 *
320 * @param array $request The Form Data passed into the batch processing.
321 */
322 public function set_properties( $request ) {
323 }
324
325 /**
326 * Unset the properties specific to the export.
327 *
328 * @since 1.8.9
329 *
330 * @param array $request The Form Data passed into the batch processing.
331 * @param Give_Batch_Export $export
332 */
333 public function unset_properties( $request, $export ) {
334 }
335
336 /**
337 * Allow for pre-fetching of data for the remainder of the exporter.
338 *
339 * @access public
340 * @since 1.5
341 * @return void
342 */
343 public function pre_fetch() {
344 }
345
346 }
347