PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.2.2
GiveWP – Donation Plugin and Fundraising Platform v2.2.2
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-forms.php 8 years ago class-batch-export.php 8 years ago class-core-settings-export.php 8 years ago class-export-earnings.php 8 years ago class-export.php 8 years ago class-give-export-donations.php 8 years ago export-actions.php 8 years ago export-functions.php 8 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
351 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, WordImpress
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 $rows = $this->print_csv_rows();
158
159 if ( $rows ) {
160 return true;
161 } else {
162 return false;
163 }
164 }
165
166 /**
167 * Output the CSV columns.
168 *
169 * @access public
170 * @since 1.5
171 * @uses Give_Export::get_csv_cols()
172 * @return string
173 */
174 public function print_csv_cols() {
175
176 $col_data = '';
177 $cols = $this->get_csv_cols();
178 $i = 1;
179 foreach ( $cols as $col_id => $column ) {
180 $col_data .= '"' . addslashes( $column ) . '"';
181 $col_data .= $i == count( $cols ) ? '' : ',';
182 $i ++;
183 }
184 $col_data .= "\r\n";
185
186 $this->stash_step_data( $col_data );
187
188 return $col_data;
189
190 }
191
192 /**
193 * Print the CSV rows for the current step.
194 *
195 * @access public
196 * @since 1.5
197 * @return string|false
198 */
199 public function print_csv_rows() {
200
201 $row_data = '';
202 $data = $this->get_data();
203 $cols = $this->get_csv_cols();
204
205 if ( $data ) {
206
207 // Output each row
208 foreach ( $data as $row ) {
209 $i = 1;
210 foreach ( $row as $col_id => $column ) {
211 // Make sure the column is valid
212 if ( array_key_exists( $col_id, $cols ) ) {
213 $row_data .= '"' . addslashes( preg_replace( '/"/', "'", $column ) ) . '"';
214 $row_data .= $i == count( $cols ) ? '' : ',';
215 $i ++;
216 }
217 }
218 $row_data .= "\r\n";
219 }
220
221 $this->stash_step_data( $row_data );
222
223 return $row_data;
224 }
225
226 return false;
227 }
228
229 /**
230 * Return the calculated completion percentage.
231 *
232 * @since 1.5
233 * @return int
234 */
235 public function get_percentage_complete() {
236 return 100;
237 }
238
239 /**
240 * Retrieve the file data is written to.
241 *
242 * @since 1.5
243 * @return string
244 */
245 protected function get_file() {
246
247 $file = '';
248
249 if ( @file_exists( $this->file ) ) {
250
251 if ( ! is_writeable( $this->file ) ) {
252 $this->is_writable = false;
253 }
254
255 $file = @file_get_contents( $this->file );
256
257 } else {
258
259 @file_put_contents( $this->file, '' );
260 @chmod( $this->file, 0664 );
261
262 }
263
264 return $file;
265 }
266
267 /**
268 * Append data to export file.
269 *
270 * @since 1.5
271 *
272 * @param $data string The data to add to the file.
273 *
274 * @return void
275 */
276 protected function stash_step_data( $data = '' ) {
277
278 $file = $this->get_file();
279 $file .= $data;
280 @file_put_contents( $this->file, $file );
281
282 // If we have no rows after this step, mark it as an empty export.
283 $file_rows = file( $this->file, FILE_SKIP_EMPTY_LINES );
284 $default_cols = $this->get_csv_cols();
285 $default_cols = empty( $default_cols ) ? 0 : 1;
286
287 $this->is_empty = count( $file_rows ) == $default_cols ? true : false;
288
289 }
290
291 /**
292 * Perform the export.
293 *
294 * @access public
295 * @since 1.5
296 * @return void
297 */
298 public function export() {
299
300 // Set headers
301 $this->headers();
302
303 $file = $this->get_file();
304
305 @unlink( $this->file );
306
307 echo $file;
308
309 /**
310 * Fire action after file output.
311 *
312 * @since 1.8
313 */
314 do_action( 'give_file_export_complete', $_REQUEST );
315
316 give_die();
317 }
318
319 /**
320 * Set the properties specific to the export.
321 *
322 * @since 1.5
323 *
324 * @param array $request The Form Data passed into the batch processing.
325 */
326 public function set_properties( $request ) {
327 }
328
329 /**
330 * Unset the properties specific to the export.
331 *
332 * @since 1.8.9
333 *
334 * @param array $request The Form Data passed into the batch processing.
335 * @param Give_Batch_Export $export
336 */
337 public function unset_properties( $request, $export ) {
338 }
339
340 /**
341 * Allow for pre-fetching of data for the remainder of the exporter.
342 *
343 * @access public
344 * @since 1.5
345 * @return void
346 */
347 public function pre_fetch() {
348 }
349
350 }
351