class-batch-export-donors.php
8 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
8 years ago
give-export-donations-functions.php
8 years ago
pdf-reports.php
8 years ago
export-functions.php
122 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Exports Functions |
| 4 | * |
| 5 | * These functions are used for exporting data from Give |
| 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 | */ |
| 12 | |
| 13 | // Exit if accessed directly. |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit; |
| 16 | } |
| 17 | |
| 18 | |
| 19 | |
| 20 | /** |
| 21 | * Process batch exports via ajax |
| 22 | * |
| 23 | * @since 1.5 |
| 24 | * @return void |
| 25 | */ |
| 26 | function give_do_ajax_export() { |
| 27 | |
| 28 | require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/export/class-batch-export.php'; |
| 29 | |
| 30 | parse_str( $_POST['form'], $form ); |
| 31 | |
| 32 | $_REQUEST = $form = (array) $form; |
| 33 | |
| 34 | if ( ! wp_verify_nonce( $_REQUEST['give_ajax_export'], 'give_ajax_export' ) ) { |
| 35 | die( '-2' ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Fires before batch export. |
| 40 | * |
| 41 | * @since 1.5 |
| 42 | * |
| 43 | * @param string $class Export class. |
| 44 | */ |
| 45 | do_action( 'give_batch_export_class_include', $form['give-export-class'] ); |
| 46 | |
| 47 | $step = absint( $_POST['step'] ); |
| 48 | $class = sanitize_text_field( $form['give-export-class'] ); |
| 49 | |
| 50 | /* @var Give_Batch_Export $export */ |
| 51 | $export = new $class( $step ); |
| 52 | |
| 53 | if ( ! $export->can_export() ) { |
| 54 | die( '-1' ); |
| 55 | } |
| 56 | |
| 57 | if ( ! $export->is_writable ) { |
| 58 | $json_args = array( |
| 59 | 'error' => true, |
| 60 | 'message' => esc_html__( 'Export location or file not writable.', 'give' ) |
| 61 | ); |
| 62 | echo json_encode($json_args); |
| 63 | exit; |
| 64 | } |
| 65 | |
| 66 | $export->set_properties( give_clean( $_REQUEST ) ); |
| 67 | |
| 68 | $export->pre_fetch(); |
| 69 | |
| 70 | $ret = $export->process_step(); |
| 71 | |
| 72 | $percentage = $export->get_percentage_complete(); |
| 73 | |
| 74 | if ( $ret ) { |
| 75 | |
| 76 | $step += 1; |
| 77 | $json_data = array( |
| 78 | 'step' => $step, |
| 79 | 'percentage' => $percentage |
| 80 | ); |
| 81 | |
| 82 | } elseif ( true === $export->is_empty ) { |
| 83 | |
| 84 | $json_data = array( |
| 85 | 'error' => true, |
| 86 | 'message' => esc_html__( 'No data found for export parameters.', 'give' ) |
| 87 | ); |
| 88 | |
| 89 | } elseif ( true === $export->done && true === $export->is_void ) { |
| 90 | |
| 91 | $message = ! empty( $export->message ) ? |
| 92 | $export->message : |
| 93 | esc_html__( 'Batch Processing Complete', 'give' ); |
| 94 | |
| 95 | $json_data = array( |
| 96 | 'success' => true, |
| 97 | 'message' => $message |
| 98 | ); |
| 99 | |
| 100 | } else { |
| 101 | |
| 102 | $args = array_merge( $_REQUEST, array( |
| 103 | 'step' => $step, |
| 104 | 'class' => $class, |
| 105 | 'nonce' => wp_create_nonce( 'give-batch-export' ), |
| 106 | 'give_action' => 'form_batch_export', |
| 107 | ) ); |
| 108 | |
| 109 | $json_data = array( |
| 110 | 'step' => 'done', |
| 111 | 'url' => add_query_arg( $args, admin_url() ) |
| 112 | ); |
| 113 | |
| 114 | } |
| 115 | |
| 116 | $export->unset_properties( give_clean( $_REQUEST ), $export ); |
| 117 | echo json_encode( $json_data ); |
| 118 | exit; |
| 119 | } |
| 120 | |
| 121 | add_action( 'wp_ajax_give_do_ajax_export', 'give_do_ajax_export' ); |
| 122 |