installed plugin Easy Digital Downloads
version 3.1.0.3
This commit is contained in:
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
/**
|
||||
* Batch API Request Logs Export Class
|
||||
*
|
||||
* This class handles API request logs export
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Admin/Reporting/Export
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 2.7
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* EDD_Batch_API_Requests_Export Class
|
||||
*
|
||||
* @since 2.7
|
||||
*/
|
||||
class EDD_Batch_API_Requests_Export extends EDD_Batch_Export {
|
||||
/**
|
||||
* Our export type. Used for export-type specific filters/actions
|
||||
*
|
||||
* @var string
|
||||
* @since 2.7
|
||||
*/
|
||||
public $export_type = 'api_requests';
|
||||
|
||||
/**
|
||||
* Set the CSV columns.
|
||||
*
|
||||
* @since 2.7
|
||||
* @return array $cols All the columns
|
||||
*/
|
||||
public function csv_cols() {
|
||||
$cols = array(
|
||||
'ID' => __( 'Log ID', 'easy-digital-downloads' ),
|
||||
'request' => __( 'API Request', 'easy-digital-downloads' ),
|
||||
'ip' => __( 'IP Address', 'easy-digital-downloads' ),
|
||||
'user' => __( 'API User', 'easy-digital-downloads' ),
|
||||
'key' => __( 'API Key', 'easy-digital-downloads' ),
|
||||
'version' => __( 'API Version', 'easy-digital-downloads' ),
|
||||
'speed' => __( 'Request Speed', 'easy-digital-downloads' ),
|
||||
'date' => __( 'Date', 'easy-digital-downloads' )
|
||||
);
|
||||
|
||||
return $cols;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the export data.
|
||||
*
|
||||
* @since 2.7
|
||||
* @since 3.0 Updated to use new query methods.
|
||||
*
|
||||
* @return array $data The data for the CSV file.
|
||||
*/
|
||||
public function get_data() {
|
||||
$data = array();
|
||||
|
||||
$args = array(
|
||||
'number' => 30,
|
||||
'offset' => ( $this->step * 30 ) - 30
|
||||
);
|
||||
|
||||
if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
|
||||
$args['date_query'] = $this->get_date_query();
|
||||
}
|
||||
|
||||
$logs = edd_get_api_request_logs( $args );
|
||||
|
||||
foreach ( $logs as $log ) {
|
||||
/** @var EDD\Logs\Api_Request_Log $log */
|
||||
|
||||
$data[] = array(
|
||||
'ID' => $log->id,
|
||||
'request' => $log->request,
|
||||
'ip' => $log->ip,
|
||||
'user' => $log->user_id,
|
||||
'key' => $log->api_key,
|
||||
'version' => $log->version,
|
||||
'speed' => $log->time,
|
||||
'date' => $log->date_created
|
||||
);
|
||||
}
|
||||
|
||||
$data = apply_filters( 'edd_export_get_data', $data );
|
||||
$data = apply_filters( 'edd_export_get_data_' . $this->export_type, $data );
|
||||
|
||||
return ! empty( $data )
|
||||
? $data
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the calculated completion percentage.
|
||||
*
|
||||
* @since 2.7
|
||||
* @since 3.0 Updated to use new query methods.
|
||||
*
|
||||
* @return int Percentage complete.
|
||||
*/
|
||||
public function get_percentage_complete() {
|
||||
$args = array(
|
||||
'fields' => 'ids',
|
||||
);
|
||||
|
||||
if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
|
||||
$args['date_query'] = $this->get_date_query();
|
||||
}
|
||||
|
||||
$total = edd_count_api_request_logs( $args );
|
||||
$percentage = 100;
|
||||
|
||||
if ( $total > 0 ) {
|
||||
$percentage = ( ( 30 * $this->step ) / $total ) * 100;
|
||||
}
|
||||
|
||||
if ( $percentage > 100 ) {
|
||||
$percentage = 100;
|
||||
}
|
||||
|
||||
return $percentage;
|
||||
}
|
||||
|
||||
public function set_properties( $request ) {
|
||||
$this->start = isset( $request['api-requests-export-start'] ) ? sanitize_text_field( $request['api-requests-export-start'] ) : '';
|
||||
$this->end = isset( $request['api-requests-export-end'] ) ? sanitize_text_field( $request['api-requests-export-end'] ) : '';
|
||||
}
|
||||
}
|
@ -0,0 +1,230 @@
|
||||
<?php
|
||||
/**
|
||||
* Batch Customers Export Class
|
||||
*
|
||||
* This class handles customer export
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Admin/Reporting/Export
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 2.4
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* EDD_Batch_Customers_Export Class
|
||||
*
|
||||
* @since 2.4
|
||||
* @since 3.0 Allowed customers to be exported by taxonomy.
|
||||
*/
|
||||
class EDD_Batch_Customers_Export extends EDD_Batch_Export {
|
||||
|
||||
/**
|
||||
* Our export type. Used for export-type specific filters/actions.
|
||||
*
|
||||
* @var string
|
||||
* @since 2.4
|
||||
*/
|
||||
public $export_type = 'customers';
|
||||
|
||||
/**
|
||||
* Taxonomy.
|
||||
*
|
||||
* @since 3.0
|
||||
* @var int
|
||||
*/
|
||||
public $taxonomy = null;
|
||||
|
||||
/**
|
||||
* Set the CSV columns.
|
||||
*
|
||||
* @since 2.4
|
||||
*
|
||||
* @return array $cols All the columns
|
||||
*/
|
||||
public function csv_cols() {
|
||||
|
||||
return array(
|
||||
'id' => __( 'ID', 'easy-digital-downloads' ),
|
||||
'user_id' => __( 'User ID', 'easy-digital-downloads' ),
|
||||
'name' => __( 'Name', 'easy-digital-downloads' ),
|
||||
'email' => __( 'Email', 'easy-digital-downloads' ),
|
||||
'purchases' => __( 'Number of Purchases', 'easy-digital-downloads' ),
|
||||
'amount' => __( 'Customer Value', 'easy-digital-downloads' ),
|
||||
'payment_ids' => __( 'Payment IDs', 'easy-digital-downloads' ),
|
||||
'date_created' => __( 'Date Created', 'easy-digital-downloads' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the export data.
|
||||
*
|
||||
* @since 2.4
|
||||
* @since 3.0 Updated to use new query methods.
|
||||
*
|
||||
* @return array $data The data for the CSV file.
|
||||
*/
|
||||
public function get_data() {
|
||||
global $wpdb;
|
||||
|
||||
$data = array();
|
||||
|
||||
// Taxonomy.
|
||||
if ( ! empty( $this->taxonomy ) ) {
|
||||
$taxonomy = $wpdb->prepare( 't.term_id = %d', $this->taxonomy );
|
||||
|
||||
$limit = $wpdb->prepare( '%d, %d', 30 * ( $this->step - 1 ), 30 );
|
||||
|
||||
$sql = "SELECT DISTINCT o.customer_id
|
||||
FROM {$wpdb->terms} t
|
||||
INNER JOIN {$wpdb->term_taxonomy} tt ON t.term_id = tt.term_id
|
||||
INNER JOIN {$wpdb->term_relationships} tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
|
||||
INNER JOIN {$wpdb->edd_order_items} oi ON tr.object_id = oi.product_id
|
||||
INNER JOIN {$wpdb->edd_orders} o ON oi.order_id = o.id
|
||||
WHERE {$taxonomy}
|
||||
LIMIT {$limit}";
|
||||
|
||||
$results = $wpdb->get_col( $sql ); // WPCS: unprepared SQL ok.
|
||||
|
||||
if ( $results ) {
|
||||
foreach ( $results as $customer_id ) {
|
||||
$customer = new EDD_Customer( $customer_id );
|
||||
$name = ! empty( $customer->name ) ? $customer->name : '';
|
||||
if ( preg_match( '~^[+\-=@]~m', $name ) ) {
|
||||
$name = "'{$name}";
|
||||
}
|
||||
|
||||
$data[] = array(
|
||||
'id' => $customer->id,
|
||||
'name' => $name,
|
||||
'email' => $customer->email,
|
||||
'purchases' => $customer->purchase_count,
|
||||
'amount' => edd_format_amount( $customer->purchase_value ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Download.
|
||||
} elseif ( ! empty( $this->download ) ) {
|
||||
// Export customers of a specific product
|
||||
|
||||
$args = array(
|
||||
'product_id' => absint( $this->download ),
|
||||
'number' => 30,
|
||||
'offset' => 30 * ( $this->step - 1 ),
|
||||
);
|
||||
|
||||
if ( null !== $this->price_id ) {
|
||||
$args['price_id'] = (int) $this->price_id;
|
||||
}
|
||||
|
||||
$order_items = edd_get_order_items( $args );
|
||||
|
||||
if ( $order_items ) {
|
||||
foreach ( $order_items as $item ) {
|
||||
$order = edd_get_order( $item->order_id );
|
||||
|
||||
$customer = new EDD_Customer( $order->customer_id );
|
||||
$name = ! empty( $customer->name ) ? $customer->name : '';
|
||||
if ( preg_match( '~^[+\-=@]~m', $name ) ) {
|
||||
$name = "'{$name}";
|
||||
}
|
||||
|
||||
$data[] = array(
|
||||
'id' => $customer->id,
|
||||
'user_id' => $customer->user_id,
|
||||
'name' => $name,
|
||||
'email' => $customer->email,
|
||||
'purchases' => $customer->purchase_count,
|
||||
'amount' => edd_format_amount( $customer->purchase_value ),
|
||||
'payment_ids' => $customer->payment_ids,
|
||||
'date_created' => $customer->date_created,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// All customers.
|
||||
} else {
|
||||
$customers = edd_get_customers( array(
|
||||
'number' => 30,
|
||||
'offset' => 30 * ( $this->step - 1 ),
|
||||
) );
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach ( $customers as $customer ) {
|
||||
$name = ! empty( $customer->name ) ? $customer->name : '';
|
||||
if ( preg_match( '~^[+\-=@]~m', $name ) ) {
|
||||
$name = "'{$name}";
|
||||
}
|
||||
$data[ $i ]= array(
|
||||
'id' => $customer->id,
|
||||
'user_id' => $customer->user_id,
|
||||
'name' => $name,
|
||||
'email' => $customer->email,
|
||||
'purchases' => $customer->purchase_count,
|
||||
'amount' => edd_format_amount( $customer->purchase_value ),
|
||||
'payment_ids' => $customer->payment_ids,
|
||||
'date_created' => $customer->date_created,
|
||||
);
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
$data = apply_filters( 'edd_export_get_data', $data );
|
||||
$data = apply_filters( 'edd_export_get_data_' . $this->export_type, $data );
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the calculated completion percentage.
|
||||
*
|
||||
* @since 2.4
|
||||
*
|
||||
* @return float Percentage complete.
|
||||
*/
|
||||
public function get_percentage_complete() {
|
||||
$percentage = 0;
|
||||
|
||||
// We can't count the number when getting them for a specific download.
|
||||
if ( empty( $this->download ) ) {
|
||||
$total = edd_count_customers();
|
||||
|
||||
if ( $total > 0 ) {
|
||||
$percentage = ( ( 30 * $this->step ) / $total ) * 100;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $percentage > 100 ) {
|
||||
$percentage = 100;
|
||||
}
|
||||
|
||||
return $percentage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the properties specific to the Customers export
|
||||
*
|
||||
* @since 2.4.2
|
||||
*
|
||||
* @param array $request Form data passed into the batch processing.
|
||||
*/
|
||||
public function set_properties( $request ) {
|
||||
$this->taxonomy = isset( $request['taxonomy'] )
|
||||
? absint( $request['taxonomy'] )
|
||||
: null;
|
||||
|
||||
$this->download = isset( $request['download'] )
|
||||
? absint( $request['download'] )
|
||||
: null;
|
||||
|
||||
$this->price_id = ! empty( $request['edd_price_option'] ) && 0 !== $request['edd_price_option']
|
||||
? absint( $request['edd_price_option'] )
|
||||
: null;
|
||||
}
|
||||
}
|
@ -0,0 +1,234 @@
|
||||
<?php
|
||||
/**
|
||||
* Batch Downloads Export Class
|
||||
*
|
||||
* This class handles download products export
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Admin/Reporting/Export
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 2.5
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* EDD_Batch_Downloads_Export Class
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
class EDD_Batch_Downloads_Export extends EDD_Batch_Export {
|
||||
|
||||
/**
|
||||
* Our export type. Used for export-type specific filters/actions
|
||||
*
|
||||
* @var string
|
||||
* @since 2.5
|
||||
*/
|
||||
public $export_type = 'downloads';
|
||||
|
||||
/**
|
||||
* Set the CSV columns.
|
||||
*
|
||||
* @since 2.5
|
||||
*
|
||||
* @return array $cols All the columns.
|
||||
*/
|
||||
public function csv_cols() {
|
||||
$cols = array(
|
||||
'ID' => __( 'ID', 'easy-digital-downloads' ),
|
||||
'post_name' => __( 'Slug', 'easy-digital-downloads' ),
|
||||
'post_title' => __( 'Name', 'easy-digital-downloads' ),
|
||||
'post_date' => __( 'Date Created', 'easy-digital-downloads' ),
|
||||
'post_author' => __( 'Author', 'easy-digital-downloads' ),
|
||||
'post_content' => __( 'Description', 'easy-digital-downloads' ),
|
||||
'post_excerpt' => __( 'Excerpt', 'easy-digital-downloads' ),
|
||||
'post_status' => __( 'Status', 'easy-digital-downloads' ),
|
||||
'categories' => __( 'Categories', 'easy-digital-downloads' ),
|
||||
'tags' => __( 'Tags', 'easy-digital-downloads' ),
|
||||
'edd_price' => __( 'Price', 'easy-digital-downloads' ),
|
||||
'_edd_files' => __( 'Files', 'easy-digital-downloads' ),
|
||||
'_edd_download_limit' => __( 'File Download Limit', 'easy-digital-downloads' ),
|
||||
'_thumbnail_id' => __( 'Featured Image', 'easy-digital-downloads' ),
|
||||
'edd_sku' => __( 'SKU', 'easy-digital-downloads' ),
|
||||
'edd_product_notes' => __( 'Notes', 'easy-digital-downloads' ),
|
||||
'_edd_download_sales' => __( 'Sales', 'easy-digital-downloads' ),
|
||||
'_edd_download_earnings' => __( 'Earnings', 'easy-digital-downloads' ),
|
||||
);
|
||||
|
||||
return $cols;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the export data.
|
||||
*
|
||||
* @since 2.5
|
||||
*
|
||||
* @return array $data The data for the CSV file.
|
||||
*/
|
||||
public function get_data() {
|
||||
$data = array();
|
||||
|
||||
$meta = array(
|
||||
'edd_price',
|
||||
'_edd_files',
|
||||
'_edd_download_limit',
|
||||
'_thumbnail_id',
|
||||
'edd_sku',
|
||||
'edd_product_notes',
|
||||
'_edd_download_sales',
|
||||
'_edd_download_earnings',
|
||||
);
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'download',
|
||||
'posts_per_page' => 30,
|
||||
'paged' => $this->step,
|
||||
'orderby' => 'ID',
|
||||
'order' => 'ASC',
|
||||
);
|
||||
|
||||
if ( 0 !== $this->download ) {
|
||||
$args['post__in'] = array( $this->download );
|
||||
}
|
||||
|
||||
$downloads = new WP_Query( $args );
|
||||
|
||||
if ( $downloads->posts ) {
|
||||
foreach ( $downloads->posts as $download ) {
|
||||
$row = array();
|
||||
|
||||
foreach ( $this->csv_cols() as $key => $value ) {
|
||||
|
||||
// Setup default value
|
||||
$row[ $key ] = '';
|
||||
|
||||
if ( in_array( $key, $meta ) ) {
|
||||
switch ( $key ) {
|
||||
case '_thumbnail_id' :
|
||||
$image_id = get_post_thumbnail_id( $download->ID );
|
||||
$row[ $key ] = wp_get_attachment_url( $image_id );
|
||||
break;
|
||||
|
||||
case 'edd_price' :
|
||||
if ( edd_has_variable_prices( $download->ID ) ) {
|
||||
$prices = array();
|
||||
foreach ( edd_get_variable_prices( $download->ID ) as $price ) {
|
||||
$prices[] = $price['name'] . ': ' . $price['amount'];
|
||||
}
|
||||
|
||||
$row[ $key ] = implode( ' | ', $prices );
|
||||
} else {
|
||||
$row[ $key ] = edd_get_download_price( $download->ID );
|
||||
}
|
||||
break;
|
||||
|
||||
case '_edd_files' :
|
||||
$files = array();
|
||||
|
||||
foreach ( edd_get_download_files( $download->ID ) as $file ) {
|
||||
$f = $file['file'];
|
||||
|
||||
if ( edd_has_variable_prices( $download->ID ) ) {
|
||||
$condition = isset( $file['condition'] ) ? $file['condition'] : 'all';
|
||||
$f .= ';' . $condition;
|
||||
}
|
||||
|
||||
$files[] = $f;
|
||||
|
||||
unset( $file );
|
||||
}
|
||||
|
||||
$row[ $key ] = implode( ' | ', $files );
|
||||
break;
|
||||
|
||||
default :
|
||||
$row[ $key ] = get_post_meta( $download->ID, $key, true );
|
||||
break;
|
||||
}
|
||||
} elseif ( isset( $download->$key ) ) {
|
||||
switch ( $key ) {
|
||||
case 'post_author':
|
||||
$row[ $key ] = get_the_author_meta( 'user_login', $download->post_author );
|
||||
break;
|
||||
|
||||
default:
|
||||
$row[ $key ] = $download->$key;
|
||||
break;
|
||||
}
|
||||
} elseif ( 'tags' == $key ) {
|
||||
$terms = get_the_terms( $download->ID, 'download_tag' );
|
||||
|
||||
if ( $terms ) {
|
||||
$terms = wp_list_pluck( $terms, 'name' );
|
||||
$row[ $key ] = implode( ' | ', $terms );
|
||||
}
|
||||
} elseif ( 'categories' == $key ) {
|
||||
$terms = get_the_terms( $download->ID, 'download_category' );
|
||||
|
||||
if ( $terms ) {
|
||||
$terms = wp_list_pluck( $terms, 'name' );
|
||||
$row[ $key ] = implode( ' | ', $terms );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data[] = $row;
|
||||
}
|
||||
|
||||
$data = apply_filters( 'edd_export_get_data', $data );
|
||||
$data = apply_filters( 'edd_export_get_data_' . $this->export_type, $data );
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the calculated completion percentage.
|
||||
*
|
||||
* @since 2.5
|
||||
*
|
||||
* @return int Percentage complete.
|
||||
*/
|
||||
public function get_percentage_complete() {
|
||||
$args = array(
|
||||
'post_type' => 'download',
|
||||
'posts_per_page' => - 1,
|
||||
'post_status' => 'any',
|
||||
'fields' => 'ids',
|
||||
);
|
||||
|
||||
if ( 0 !== $this->download ) {
|
||||
$args['post__in'] = array( $this->download );
|
||||
}
|
||||
|
||||
$downloads = new WP_Query( $args );
|
||||
$total = (int) $downloads->post_count;
|
||||
$percentage = 100;
|
||||
|
||||
if ( $total > 0 ) {
|
||||
$percentage = ( ( 30 * $this->step ) / $total ) * 100;
|
||||
}
|
||||
|
||||
if ( $percentage > 100 ) {
|
||||
$percentage = 100;
|
||||
}
|
||||
|
||||
return $percentage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the properties specific to the downloads export.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $request Form data passed into the batch processor.
|
||||
*/
|
||||
public function set_properties( $request ) {
|
||||
$this->download = isset( $request['download_id'] ) ? absint( $request['download_id'] ) : null;
|
||||
}
|
||||
}
|
@ -0,0 +1,349 @@
|
||||
<?php
|
||||
/**
|
||||
* Batch Earnings Report Export Class.
|
||||
*
|
||||
* This class handles earnings report export.
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Admin/Reporting/Export
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 2.7
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* EDD_Earnings_Report_Export Class
|
||||
*
|
||||
* @since 2.7
|
||||
*/
|
||||
class EDD_Batch_Earnings_Report_Export extends EDD_Batch_Export {
|
||||
/**
|
||||
* Our export type. Used for export-type specific filters/actions.
|
||||
*
|
||||
* @since 2.7
|
||||
* @var string
|
||||
*/
|
||||
public $export_type = 'earnings_report';
|
||||
|
||||
/**
|
||||
* Set the export headers.
|
||||
*
|
||||
* @since 2.7
|
||||
*/
|
||||
public function headers() {
|
||||
edd_set_time_limit();
|
||||
|
||||
nocache_headers();
|
||||
|
||||
header( 'Content-Type: text/csv; charset=utf-8' );
|
||||
header( 'Content-Disposition: attachment; filename="' . apply_filters( 'edd_earnings_report_export_filename', 'edd-export-' . $this->export_type . '-' . date( 'm' ) . '-' . date( 'Y' ) ) . '.csv"' );
|
||||
header( 'Expires: 0' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the column headers for the Earnings Report.
|
||||
*
|
||||
* @since 2.8.18
|
||||
*
|
||||
* @return array CSV columns.
|
||||
*/
|
||||
public function get_csv_cols() {
|
||||
|
||||
// Always start with the date column.
|
||||
$pre_status_columns = array(
|
||||
__( 'Monthly Sales Activity', 'easy-digital-downloads' ),
|
||||
__( 'Gross Activity', 'easy-digital-downloads' ),
|
||||
);
|
||||
|
||||
$status_cols = $this->get_status_cols();
|
||||
|
||||
// Append the arrays together so it starts with the date, then include the status list.
|
||||
$cols = array_merge( $pre_status_columns, $status_cols );
|
||||
|
||||
// Include the 'net' after all other columns.
|
||||
$cols[] = __( 'Net Activity', 'easy-digital-downloads' );
|
||||
|
||||
return $cols;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifically retrieve the headers for supported order statuses.
|
||||
*
|
||||
* @since 2.8.18
|
||||
*
|
||||
* @return array Order status columns.
|
||||
*/
|
||||
public function get_status_cols() {
|
||||
$status_cols = edd_get_payment_statuses();
|
||||
$supported_statuses = $this->get_supported_statuses();
|
||||
|
||||
foreach ( $status_cols as $id => $label ) {
|
||||
if ( ! in_array( $id, $supported_statuses ) ) {
|
||||
unset( $status_cols[ $id ] );
|
||||
}
|
||||
}
|
||||
|
||||
return array_values( $status_cols );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of the statuses supported in this report.
|
||||
*
|
||||
* @since 2.8.18
|
||||
*
|
||||
* @return array The status keys supported (not labels).
|
||||
*/
|
||||
public function get_supported_statuses() {
|
||||
$statuses = edd_get_payment_statuses();
|
||||
|
||||
// Unset a few statuses we don't need in the report:
|
||||
unset( $statuses['pending'], $statuses['processing'], $statuses['preapproval'] );
|
||||
$supported_statuses = array_keys( $statuses );
|
||||
|
||||
return apply_filters( 'edd_export_earnings_supported_statuses', $supported_statuses );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the CSV columns.
|
||||
*
|
||||
* We make use of this function to set up the header of the earnings report.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @return string $col_data CSV cols.
|
||||
*/
|
||||
public function print_csv_cols() {
|
||||
$cols = $this->get_csv_cols();
|
||||
$col_data = '';
|
||||
$column_count = count( $cols );
|
||||
for ( $i = 0; $i < $column_count; $i++ ) {
|
||||
$col_data .= $cols[ $i ];
|
||||
|
||||
// We don't need an extra space after the first column.
|
||||
if ( $i == 0 ) {
|
||||
$col_data .= ',';
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $i == ( $column_count - 1 ) ) {
|
||||
$col_data .= "\r\n";
|
||||
} else {
|
||||
$col_data .= ",,";
|
||||
}
|
||||
}
|
||||
|
||||
$statuses = $this->get_supported_statuses();
|
||||
$number_cols = count( $statuses ) + 2;
|
||||
|
||||
$col_data .= ',';
|
||||
for ( $i = 1; $i <= $number_cols; $i++ ) {
|
||||
$col_data .= __( 'Order Count', 'easy-digital-downloads' ) . ',';
|
||||
$col_data .= __( 'Gross Amount', 'easy-digital-downloads' );
|
||||
|
||||
if ( $number_cols !== $i ) {
|
||||
$col_data .= ',';
|
||||
}
|
||||
}
|
||||
$col_data .= "\r\n";
|
||||
|
||||
$this->stash_step_data( $col_data );
|
||||
|
||||
return $col_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the CSV rows for the current step.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @return mixed string|false
|
||||
*/
|
||||
public function print_csv_rows() {
|
||||
$row_data = '';
|
||||
|
||||
$data = $this->get_data();
|
||||
|
||||
if ( $data ) {
|
||||
$start_date = date( 'Y-m-d', strtotime( $this->start ) );
|
||||
|
||||
if ( $this->count() == 0 ) {
|
||||
$end_date = date( 'Y-m-d', strtotime( $this->end ) );
|
||||
} else {
|
||||
$end_date = date( 'Y-m-d', strtotime( 'first day of +1 month', strtotime( $start_date ) ) );
|
||||
}
|
||||
|
||||
if ( $this->step == 1 ) {
|
||||
$row_data .= $start_date . ',';
|
||||
} elseif ( $this->step > 1 ) {
|
||||
$start_date = date( 'Y-m-d', strtotime( 'first day of +' . ( $this->step - 1 ) . ' month', strtotime( $start_date ) ) );
|
||||
|
||||
if ( date( 'Y-m', strtotime( $start_date ) ) == date( 'Y-m', strtotime( $this->end ) ) ) {
|
||||
$end_date = date( 'Y-m-d', strtotime( $this->end ) );
|
||||
$row_data .= $end_date . ',';
|
||||
} else {
|
||||
$row_data .= $start_date . ',';
|
||||
}
|
||||
}
|
||||
|
||||
$supported_statuses = $this->get_supported_statuses();
|
||||
|
||||
$gross_count = 0;
|
||||
$gross_amount = 0;
|
||||
foreach ( $supported_statuses as $status ) {
|
||||
$gross_count += absint( $data[ $status ]['count'] );
|
||||
$gross_amount += $data[ $status ]['amount'];
|
||||
}
|
||||
|
||||
$row_data .= $gross_count . ',';
|
||||
$row_data .= '"' . edd_format_amount( $gross_amount ) . '",';
|
||||
|
||||
foreach ( $data as $status => $status_data ) {
|
||||
$row_data .= isset( $data[ $status ]['count'] ) ? $data[ $status ]['count'] . ',' : 0 . ',';
|
||||
|
||||
$column_amount = isset( $data[ $status ]['amount'] ) ? edd_format_amount( $data[ $status ]['amount'] ) : 0;
|
||||
if ( ! empty( $column_amount ) && 'refunded' == $status ) {
|
||||
$column_amount = '-' . $column_amount;
|
||||
}
|
||||
|
||||
$row_data .= isset( $data[ $status ]['amount'] ) ? '"' . $column_amount . '"' . ',' : 0 . ',';
|
||||
}
|
||||
|
||||
// Allows extensions with other 'completed' statuses to alter net earnings, like recurring.
|
||||
$completed_statuses = apply_filters( 'edd_export_earnings_completed_statuses', edd_get_complete_order_statuses() );
|
||||
|
||||
$net_count = 0;
|
||||
$net_amount = 0;
|
||||
foreach ( $completed_statuses as $status ) {
|
||||
if ( ! isset( $data[ $status ] ) ) {
|
||||
continue;
|
||||
}
|
||||
$net_count += absint( $data[ $status ]['count'] );
|
||||
$net_amount += floatval( $data[ $status ]['amount'] );
|
||||
}
|
||||
$row_data .= $net_count . ',';
|
||||
$row_data .= '"' . edd_format_amount( $net_amount ) . '"';
|
||||
|
||||
$row_data .= "\r\n";
|
||||
|
||||
$this->stash_step_data( $row_data );
|
||||
|
||||
return $row_data;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Export Data.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @return array $data The data for the CSV file
|
||||
*/
|
||||
public function get_data() {
|
||||
global $wpdb;
|
||||
|
||||
$data = array();
|
||||
|
||||
$start_date = date( 'Y-m-d 00:00:00', strtotime( $this->start ) );
|
||||
$end_date = date( 'Y-m-t 23:59:59', strtotime( $this->start ) );
|
||||
|
||||
if ( $this->step > 1 ) {
|
||||
$start_timestamp = strtotime( 'first day of +' . ( $this->step - 1 ) . ' month', strtotime( $start_date ) );
|
||||
$start_date = date( 'Y-m-d 00:00:00', $start_timestamp );
|
||||
$end_date = date( 'Y-m-t 23:59:59', $start_timestamp );
|
||||
}
|
||||
|
||||
if ( strtotime( $start_date ) > strtotime( $this->end ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$statuses = $this->get_supported_statuses();
|
||||
$totals = $wpdb->get_results( $wpdb->prepare(
|
||||
"SELECT SUM(total) AS total, COUNT(DISTINCT id) AS count, status
|
||||
FROM {$wpdb->edd_orders}
|
||||
WHERE date_created >= %s AND date_created <= %s
|
||||
GROUP BY YEAR(date_created), MONTH(date_created), status
|
||||
ORDER by date_created ASC", $start_date, $end_date ), ARRAY_A );
|
||||
|
||||
$total_data = array();
|
||||
foreach ( $totals as $row ) {
|
||||
$total_data[ $row['status'] ] = array(
|
||||
'count' => $row['count'],
|
||||
'amount' => floatval( $row['total'] )
|
||||
);
|
||||
}
|
||||
|
||||
foreach ( $statuses as $status ) {
|
||||
|
||||
if ( ! isset( $total_data[ $status ] ) ) {
|
||||
$data[ $status ] = array(
|
||||
'count' => 0,
|
||||
'amount' => 0,
|
||||
);
|
||||
} else {
|
||||
$data[ $status ] = array(
|
||||
'count' => $total_data[ $status ]['count'],
|
||||
'amount' => $total_data[ $status ]['amount'],
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$data = apply_filters( 'edd_export_get_data', $data );
|
||||
$data = apply_filters( 'edd_export_get_data_' . $this->export_type, $data, $start_date, $end_date );
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of months we are dealing with.
|
||||
*
|
||||
* @since 2.7
|
||||
* @access private
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function count() {
|
||||
return abs( ( date( 'Y', strtotime( $this->end ) ) - date( 'Y', strtotime( $this->start ) ) ) * 12 + ( date( 'm', strtotime( $this->end ) ) - date( 'm', strtotime( $this->start ) ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the calculated completion percentage
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @return int Percentage of batch processing complete.
|
||||
*/
|
||||
public function get_percentage_complete() {
|
||||
$percentage = 100;
|
||||
|
||||
$total = $this->count();
|
||||
|
||||
if ( $total > 0 ) {
|
||||
$percentage = ( $this->step / $total ) * 100;
|
||||
}
|
||||
|
||||
if ( $percentage > 100 ) {
|
||||
$percentage = 100;
|
||||
}
|
||||
|
||||
return $percentage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the properties specific to the earnings report.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @param array $request The Form Data passed into the batch processing
|
||||
* @return void
|
||||
*/
|
||||
public function set_properties( $request ) {
|
||||
$this->start = ( isset( $request['start_month'] ) && isset( $request['start_year'] ) ) ? sanitize_text_field( $request['start_year'] ) . '-' . sanitize_text_field( $request['start_month'] ) . '-1' : '';
|
||||
$this->end = ( isset( $request['end_month'] ) && isset( $request['end_year'] ) ) ? sanitize_text_field( $request['end_year'] ) . '-' . sanitize_text_field( $request['end_month'] ) . '-' . cal_days_in_month( CAL_GREGORIAN, sanitize_text_field( $request['end_month'] ), sanitize_text_field( $request['end_year'] ) ) : '';
|
||||
}
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
<?php
|
||||
/**
|
||||
* Batch File Downloads Export Class
|
||||
*
|
||||
* This class handles file downloads export
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Admin/Reporting/Export
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 2.4
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* EDD_Batch_File_Downloads_Export Class
|
||||
*
|
||||
* @since 2.4
|
||||
* @since 3.0 Refactored to use new query methods.
|
||||
*/
|
||||
class EDD_Batch_File_Downloads_Export extends EDD_Batch_Export {
|
||||
|
||||
/**
|
||||
* Our export type. Used for export-type specific filters/actions.
|
||||
*
|
||||
* @var string
|
||||
* @since 2.4
|
||||
*/
|
||||
public $export_type = 'file_downloads';
|
||||
|
||||
/**
|
||||
* Set the CSV columns.
|
||||
*
|
||||
* @since 2.4
|
||||
* @since 3.0 Updated to add 'User Agent' column.
|
||||
*
|
||||
* @return array $cols All the columns.
|
||||
*/
|
||||
public function csv_cols() {
|
||||
$cols = array(
|
||||
'date' => __( 'Date', 'easy-digital-downloads' ),
|
||||
'user' => __( 'Downloaded by', 'easy-digital-downloads' ),
|
||||
'ip' => __( 'IP Address', 'easy-digital-downloads' ),
|
||||
'user_agent' => __( 'User Agent', 'easy-digital-downloads' ),
|
||||
'download' => __( 'Product', 'easy-digital-downloads' ),
|
||||
'file' => __( 'File', 'easy-digital-downloads' ),
|
||||
);
|
||||
|
||||
return $cols;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the export data.
|
||||
*
|
||||
* @since 2.4
|
||||
* @since 3.0 Refactored to use new query methods.
|
||||
*
|
||||
* @return array $data The data for the CSV file.
|
||||
*/
|
||||
public function get_data() {
|
||||
$data = array();
|
||||
|
||||
$args = array(
|
||||
'number' => 30,
|
||||
'offset' => ( $this->step * 30 ) - 30,
|
||||
);
|
||||
|
||||
if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
|
||||
$args['date_created_query'] = $this->get_date_query();
|
||||
}
|
||||
|
||||
if ( 0 !== $this->download_id ) {
|
||||
$args['product_id'] = $this->download_id;
|
||||
}
|
||||
|
||||
$logs = edd_get_file_download_logs( $args );
|
||||
|
||||
foreach ( $logs as $log ) {
|
||||
/** @var EDD\Logs\File_Download_Log $log */
|
||||
|
||||
$files = edd_get_download_files( $log->product_id );
|
||||
$file_id = $log->file_id;
|
||||
$file_name = isset( $files[ $file_id ]['name'] ) ? $files[ $file_id ]['name'] : null;
|
||||
$customer = edd_get_customer( $log->customer_id );
|
||||
|
||||
if ( $customer ) {
|
||||
$customer = $customer->email;
|
||||
if ( ! empty( $customer->name ) ) {
|
||||
$customer = $customer->name;
|
||||
if ( preg_match( '~^[+\-=@]~m', $customer ) ) {
|
||||
$customer = "'{$customer}";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$order = edd_get_order( $log->order_id );
|
||||
|
||||
if ( $order ) {
|
||||
$customer = $order->email;
|
||||
}
|
||||
}
|
||||
|
||||
$data[] = array(
|
||||
'date' => $log->date_created,
|
||||
'user' => $customer,
|
||||
'ip' => $log->ip,
|
||||
'user_agent' => $log->user_agent,
|
||||
'download' => get_the_title( $log->product_id ),
|
||||
'file' => $file_name,
|
||||
);
|
||||
}
|
||||
|
||||
$data = apply_filters( 'edd_export_get_data', $data );
|
||||
$data = apply_filters( 'edd_export_get_data_' . $this->export_type, $data );
|
||||
|
||||
return ! empty( $data )
|
||||
? $data
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the calculated completion percentage.
|
||||
*
|
||||
* @since 2.4
|
||||
* @since 3.0 Updated to use new query methods.
|
||||
*
|
||||
* @return int Percentage complete.
|
||||
*/
|
||||
public function get_percentage_complete() {
|
||||
$args = array(
|
||||
'fields' => 'ids',
|
||||
);
|
||||
|
||||
if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
|
||||
$args['date_created_query'] = $this->get_date_query();
|
||||
}
|
||||
|
||||
if ( 0 !== $this->download_id ) {
|
||||
$args['download_id'] = $this->download_id;
|
||||
}
|
||||
|
||||
$total = edd_count_file_download_logs( $args );
|
||||
$percentage = 100;
|
||||
|
||||
if ( $total > 0 ) {
|
||||
$percentage = ( ( 30 * $this->step ) / $total ) * 100;
|
||||
}
|
||||
|
||||
if ( $percentage > 100 ) {
|
||||
$percentage = 100;
|
||||
}
|
||||
|
||||
return $percentage;
|
||||
}
|
||||
|
||||
public function set_properties( $request ) {
|
||||
$this->start = isset( $request['file-download-export-start'] ) ? sanitize_text_field( $request['file-download-export-start'] ) : '';
|
||||
$this->end = isset( $request['file-download-export-end'] ) ? sanitize_text_field( $request['file-download-export-end'] ) : '';
|
||||
$this->download_id = isset( $request['download_id'] ) ? absint( $request['download_id'] ) : 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,280 @@
|
||||
<?php
|
||||
/**
|
||||
* Payments Export Class
|
||||
*
|
||||
* This class handles payment export in batches
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Admin/Reporting/Export
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 2.4
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* EDD_Batch_Payments_Export Class
|
||||
*
|
||||
* @since 2.4
|
||||
*/
|
||||
class EDD_Batch_Payments_Export extends EDD_Batch_Export {
|
||||
|
||||
/**
|
||||
* Our export type. Used for export-type specific filters/actions.
|
||||
*
|
||||
* @var string
|
||||
* @since 2.4
|
||||
*/
|
||||
public $export_type = 'orders';
|
||||
|
||||
/**
|
||||
* Set the CSV columns
|
||||
*
|
||||
* @since 2.4
|
||||
*
|
||||
* @return array $cols All the columns
|
||||
*/
|
||||
public function csv_cols() {
|
||||
$cols = array(
|
||||
'id' => __( 'Order ID', 'easy-digital-downloads' ), // unaltered payment ID (use for querying)
|
||||
'seq_id' => __( 'Order Number', 'easy-digital-downloads' ), // sequential payment ID
|
||||
'email' => __( 'Email', 'easy-digital-downloads' ),
|
||||
'customer_id' => __( 'Customer ID', 'easy-digital-downloads' ),
|
||||
'name' => __( 'Customer Name', 'easy-digital-downloads' ),
|
||||
'address1' => __( 'Address', 'easy-digital-downloads' ),
|
||||
'address2' => __( 'Address (Line 2)', 'easy-digital-downloads' ),
|
||||
'city' => __( 'City', 'easy-digital-downloads' ),
|
||||
'state' => __( 'State', 'easy-digital-downloads' ),
|
||||
'country' => __( 'Country', 'easy-digital-downloads' ),
|
||||
'zip' => __( 'Zip / Postal Code', 'easy-digital-downloads' ),
|
||||
'products' => __( 'Products (Verbose)', 'easy-digital-downloads' ),
|
||||
'products_raw' => __( 'Products (Raw)', 'easy-digital-downloads' ),
|
||||
'skus' => __( 'SKUs', 'easy-digital-downloads' ),
|
||||
'currency' => __( 'Currency', 'easy-digital-downloads' ),
|
||||
'amount' => __( 'Amount', 'easy-digital-downloads' ),
|
||||
'tax' => __( 'Tax', 'easy-digital-downloads' ),
|
||||
'discount' => __( 'Discount Code', 'easy-digital-downloads' ),
|
||||
'gateway' => __( 'Payment Method', 'easy-digital-downloads' ),
|
||||
'trans_id' => __( 'Transaction ID', 'easy-digital-downloads' ),
|
||||
'key' => __( 'Purchase Key', 'easy-digital-downloads' ),
|
||||
'date' => __( 'Date', 'easy-digital-downloads' ),
|
||||
'user' => __( 'User', 'easy-digital-downloads' ),
|
||||
'ip' => __( 'IP Address', 'easy-digital-downloads' ),
|
||||
'mode' => __( 'Mode (Live|Test)', 'easy-digital-downloads' ),
|
||||
'status' => __( 'Status', 'easy-digital-downloads' ),
|
||||
'country_name' => __( 'Country Name', 'easy-digital-downloads' ),
|
||||
'state_name' => __( 'State Name', 'easy-digital-downloads' ),
|
||||
);
|
||||
|
||||
if ( ! edd_use_skus() ){
|
||||
unset( $cols['skus'] );
|
||||
}
|
||||
|
||||
if ( ! edd_get_option( 'enable_sequential' ) ) {
|
||||
unset( $cols['seq_id'] );
|
||||
}
|
||||
|
||||
return $cols;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the export data.
|
||||
*
|
||||
* @since 2.4
|
||||
* @since 3.0 Updated to use new query methods.
|
||||
*
|
||||
* @return array $data The data for the CSV file.
|
||||
*/
|
||||
public function get_data() {
|
||||
$data = array();
|
||||
|
||||
$args = array(
|
||||
'number' => 30,
|
||||
'offset' => ( $this->step * 30 ) - 30,
|
||||
'status' => $this->status,
|
||||
'order' => 'ASC',
|
||||
'orderby' => 'date_created',
|
||||
'type' => 'sale',
|
||||
'status__not_in' => array( 'trash' ),
|
||||
);
|
||||
|
||||
if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
|
||||
$args['date_query'] = $this->get_date_query();
|
||||
}
|
||||
|
||||
if ( 'all' === $args['status'] ) {
|
||||
unset( $args['status'] );
|
||||
}
|
||||
|
||||
$orders = edd_get_orders( $args );
|
||||
|
||||
foreach ( $orders as $order ) {
|
||||
/** @var EDD\Orders\Order $order */
|
||||
|
||||
$items = $order->get_items();
|
||||
$address = $order->get_address();
|
||||
$total = $order->total;
|
||||
$user_id = $order->id && $order->id != - 1 ? $order->id : $order->email;
|
||||
$customer = edd_get_customer( $order->customer_id );
|
||||
$products = '';
|
||||
$products_raw = '';
|
||||
$skus = '';
|
||||
|
||||
$discounts = $order->get_discounts();
|
||||
$discounts = ! empty( $discounts )
|
||||
? implode( ', ', $discounts )
|
||||
: __( 'none', 'easy-digital-downloads' );
|
||||
|
||||
foreach ( $items as $key => $item ) {
|
||||
/** @var EDD\Orders\Order_Item $item */
|
||||
|
||||
// Setup item information.
|
||||
$id = $item->product_id;
|
||||
$qty = $item->quantity;
|
||||
$price = $item->amount;
|
||||
$tax = $item->tax;
|
||||
$price_id = $item->price_id;
|
||||
|
||||
// Set up verbose product column.
|
||||
$products .= html_entity_decode( get_the_title( $id ) );
|
||||
|
||||
if ( $qty > 1 ) {
|
||||
$products .= html_entity_decode( ' (' . $qty . ')' );
|
||||
}
|
||||
|
||||
$products .= ' - ';
|
||||
|
||||
if ( edd_use_skus() ) {
|
||||
$sku = edd_get_download_sku( $id );
|
||||
|
||||
if ( ! empty( $sku ) ) {
|
||||
$skus .= $sku;
|
||||
}
|
||||
}
|
||||
|
||||
if ( 0 < $item->price_id ) {
|
||||
$products .= html_entity_decode( edd_get_price_option_name( $id, $item->price_id, $order->id ) ) . ' - ';
|
||||
}
|
||||
|
||||
$products .= html_entity_decode( edd_currency_filter( edd_format_amount( $price ), $order->currency ) );
|
||||
|
||||
if ( $key != ( count( $items ) -1 ) ) {
|
||||
$products .= ' / ';
|
||||
|
||||
if ( edd_use_skus() ) {
|
||||
$skus .= ' / ';
|
||||
}
|
||||
}
|
||||
|
||||
// Set up raw products column; nothing but product names.
|
||||
$products_raw .= html_entity_decode( get_the_title( $id ) ) . '|' . $price . '{' . $tax . '}';
|
||||
|
||||
// If we have a price ID, include it.
|
||||
if ( false !== $price_id ) {
|
||||
$products_raw .= '{' . $price_id . '}';
|
||||
}
|
||||
|
||||
if ( $key != ( count( $items ) -1 ) ) {
|
||||
$products_raw .= ' / ';
|
||||
}
|
||||
}
|
||||
|
||||
$user = is_numeric( $user_id )
|
||||
? get_userdata( $user_id )
|
||||
: false;
|
||||
|
||||
$name = ! empty( $customer->name ) ? $customer->name : '';
|
||||
if ( preg_match( '~^[+\-=@]~m', $name ) ) {
|
||||
$name = "'{$name}";
|
||||
}
|
||||
|
||||
$data[] = array(
|
||||
'id' => $order->id,
|
||||
'seq_id' => $order->get_number(),
|
||||
'email' => $order->email,
|
||||
'customer_id' => $order->customer_id,
|
||||
'name' => $name,
|
||||
'address1' => isset( $address->address ) ? $address->address : '',
|
||||
'address2' => isset( $address->address2 ) ? $address->address2 : '',
|
||||
'city' => isset( $address->city ) ? $address->city : '',
|
||||
'state' => isset( $address->region ) ? $address->region : '',
|
||||
'country' => isset( $address->country ) ? $address->country : '',
|
||||
'zip' => isset( $address->postal_code ) ? $address->postal_code : '',
|
||||
'products' => $products,
|
||||
'products_raw' => $products_raw,
|
||||
'skus' => $skus,
|
||||
'currency' => $order->currency,
|
||||
'amount' => html_entity_decode( edd_format_amount( $total ) ), // The non-discounted item price
|
||||
'tax' => html_entity_decode( edd_format_amount( $order->tax ) ),
|
||||
'discount' => $discounts,
|
||||
'gateway' => edd_get_gateway_admin_label( $order->gateway ),
|
||||
'trans_id' => $order->get_transaction_id(),
|
||||
'key' => $order->payment_key,
|
||||
'date' => $order->date_created,
|
||||
'user' => $user ? $user->display_name : __( 'guest', 'easy-digital-downloads' ),
|
||||
'ip' => $order->ip,
|
||||
'mode' => $order->mode,
|
||||
'status' => $order->status,
|
||||
'country_name' => isset( $address->country ) ? edd_get_country_name( $address->country ) : '',
|
||||
'state_name' => isset( $address->country ) && isset( $address->region ) ? edd_get_state_name( $address->country, $address->region ) : '',
|
||||
);
|
||||
}
|
||||
|
||||
$data = apply_filters( 'edd_export_get_data', $data );
|
||||
$data = apply_filters( 'edd_export_get_data_' . $this->export_type, $data );
|
||||
|
||||
return ! empty( $data )
|
||||
? $data
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the calculated completion percentage
|
||||
*
|
||||
* @since 2.4
|
||||
* @since 3.0 Updated to use new query methods.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_percentage_complete() {
|
||||
$args = array(
|
||||
'fields' => 'ids',
|
||||
);
|
||||
|
||||
if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
|
||||
$args['date_query'] = $this->get_date_query();
|
||||
}
|
||||
|
||||
if ( 'any' !== $this->status ) {
|
||||
$args['status'] = $this->status;
|
||||
}
|
||||
|
||||
$total = edd_count_orders( $args );
|
||||
$percentage = 100;
|
||||
|
||||
if ( $total > 0 ) {
|
||||
$percentage = ( ( 30 * $this->step ) / $total ) * 100;
|
||||
}
|
||||
|
||||
if ( $percentage > 100 ) {
|
||||
$percentage = 100;
|
||||
}
|
||||
|
||||
return $percentage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the properties specific to the payments export
|
||||
*
|
||||
* @since 2.4.2
|
||||
*
|
||||
* @param array $request The Form Data passed into the batch processing
|
||||
*/
|
||||
public function set_properties( $request ) {
|
||||
$this->start = isset( $request['orders-export-start'] ) ? sanitize_text_field( $request['orders-export-start'] ) : '';
|
||||
$this->end = isset( $request['orders-export-end'] ) ? sanitize_text_field( $request['orders-export-end'] ) : '';
|
||||
$this->status = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'complete';
|
||||
}
|
||||
}
|
@ -0,0 +1,238 @@
|
||||
<?php
|
||||
/**
|
||||
* Sales and Earnings Export Class.
|
||||
*
|
||||
* This class handles sales and earnings export on a day-by-day basis.
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Admin/Reporting/Export
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* EDD_Batch_Payments_Export Class
|
||||
*
|
||||
* @since 2.4
|
||||
*/
|
||||
class EDD_Batch_Sales_And_Earnings_Export extends EDD_Batch_Export {
|
||||
|
||||
/**
|
||||
* Our export type. Used for export-type specific filters/actions.
|
||||
*
|
||||
* @since 3.0
|
||||
* @var string
|
||||
*/
|
||||
public $export_type = 'sales_and_earnings';
|
||||
|
||||
/**
|
||||
* Download ID.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var int
|
||||
*/
|
||||
protected $download_id = 0;
|
||||
|
||||
/**
|
||||
* Customer ID.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var int
|
||||
*/
|
||||
protected $customer_id = 0;
|
||||
|
||||
/**
|
||||
* Set the CSV columns.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @return array $cols CSV columns.
|
||||
*/
|
||||
public function csv_cols() {
|
||||
$cols = array(
|
||||
'date' => __( 'Date', 'easy-digital-downloads' ),
|
||||
'sales' => __( 'Sales', 'easy-digital-downloads' ),
|
||||
'earnings' => __( 'Earnings', 'easy-digital-downloads' ),
|
||||
);
|
||||
|
||||
return $cols;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the export data.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @return array $data The data for the CSV file.
|
||||
*/
|
||||
public function get_data() {
|
||||
global $wpdb;
|
||||
|
||||
$data = array();
|
||||
|
||||
$args = array(
|
||||
'number' => 30,
|
||||
'offset' => ( $this->step * 30 ) - 30,
|
||||
);
|
||||
|
||||
$status = "AND {$wpdb->edd_orders}.status IN ( '" . implode( "', '", $wpdb->_escape( edd_get_complete_order_statuses() ) ) . "' )";
|
||||
$date_query_sql = '';
|
||||
|
||||
// Customer ID.
|
||||
$customer_id = ! empty( $this->customer_id )
|
||||
? $wpdb->prepare( "AND {$wpdb->edd_orders}.customer_id = %d", $this->customer_id )
|
||||
: '';
|
||||
|
||||
// Download ID.
|
||||
$download_id = ! empty( $this->download_id )
|
||||
? $wpdb->prepare( "AND {$wpdb->edd_order_items}.product_id = %d", $this->download_id )
|
||||
: '';
|
||||
|
||||
// Generate date query SQL if dates have been set.
|
||||
if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
|
||||
|
||||
// Fetch GMT offset.
|
||||
$offset = EDD()->utils->get_gmt_offset();
|
||||
|
||||
$date_query_sql = 'AND ';
|
||||
|
||||
if ( ! empty( $this->start ) ) {
|
||||
$this->start = date( 'Y-m-d 00:00:00', strtotime( $this->start ) );
|
||||
|
||||
$this->start = 0 < $offset
|
||||
? EDD()->utils->date( $this->start )->subSeconds( $offset )->format( 'mysql' )
|
||||
: EDD()->utils->date( $this->start )->addSeconds( $offset )->format( 'mysql' );
|
||||
|
||||
$date_query_sql .= $wpdb->prepare( "{$wpdb->edd_orders}.date_created >= %s", $this->start );
|
||||
}
|
||||
|
||||
// Join dates with `AND` if start and end date set.
|
||||
if ( ! empty( $this->start ) && ! empty( $this->end ) ) {
|
||||
$this->end = date( 'Y-m-d 23:59:59', strtotime( $this->end ) );
|
||||
|
||||
$this->end = 0 < $offset
|
||||
? EDD()->utils->date( $this->end )->addSeconds( $offset )->format( 'mysql' )
|
||||
: EDD()->utils->date( $this->end )->subSeconds( $offset )->format( 'mysql' );
|
||||
|
||||
$date_query_sql .= ' AND ';
|
||||
}
|
||||
|
||||
if ( ! empty( $this->end ) ) {
|
||||
$date_query_sql .= $wpdb->prepare( "{$wpdb->edd_orders}.date_created <= %s", $this->end );
|
||||
}
|
||||
}
|
||||
|
||||
// Look in orders table if a product ID was not passed.
|
||||
if ( 0 === $this->download_id ) {
|
||||
$sql = "
|
||||
SELECT COUNT(id) AS sales, SUM(total) AS earnings, date_created
|
||||
FROM {$wpdb->edd_orders}
|
||||
WHERE 1=1 {$status} {$customer_id} {$date_query_sql}
|
||||
GROUP BY YEAR(date_created), MONTH(date_created), DAY(date_created)
|
||||
ORDER BY YEAR(date_created), MONTH(date_created), DAY(date_created) ASC
|
||||
LIMIT {$args['offset']}, {$args['number']}
|
||||
";
|
||||
|
||||
// Join orders and order items table.
|
||||
} else {
|
||||
$sql = "
|
||||
SELECT SUM({$wpdb->edd_order_items}.quantity) AS sales, SUM({$wpdb->edd_order_items}.total) AS earnings, {$wpdb->edd_orders}.date_created
|
||||
FROM {$wpdb->edd_orders}
|
||||
INNER JOIN {$wpdb->edd_order_items} ON {$wpdb->edd_orders}.id = {$wpdb->edd_order_items}.order_id
|
||||
WHERE 1=1 {$status} {$download_id} {$date_query_sql}
|
||||
GROUP BY YEAR({$wpdb->edd_orders}.date_created), MONTH({$wpdb->edd_orders}.date_created), DAY({$wpdb->edd_orders}.date_created)
|
||||
ORDER BY YEAR({$wpdb->edd_orders}.date_created), MONTH({$wpdb->edd_orders}.date_created), DAY({$wpdb->edd_orders}.date_created) ASC
|
||||
LIMIT {$args['offset']}, {$args['number']}
|
||||
";
|
||||
}
|
||||
|
||||
$results = $wpdb->get_results( $sql );
|
||||
|
||||
foreach ( $results as $result ) {
|
||||
|
||||
// Localize the returned time.
|
||||
$d = EDD()->utils->date( $result->date_created, null, true )->format( 'date' );
|
||||
|
||||
$sales = isset( $result->sales )
|
||||
? absint( $result->sales )
|
||||
: 0;
|
||||
|
||||
$earnings = isset( $result->earnings )
|
||||
? edd_format_amount( $result->earnings )
|
||||
: floatval( 0 );
|
||||
|
||||
$data[] = array(
|
||||
'date' => $d,
|
||||
'sales' => $sales,
|
||||
'earnings' => $earnings,
|
||||
);
|
||||
}
|
||||
|
||||
$data = apply_filters( 'edd_export_get_data', $data );
|
||||
$data = apply_filters( 'edd_export_get_data_' . $this->export_type, $data );
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the calculated completion percentage
|
||||
*
|
||||
* @since 2.4
|
||||
* @since 3.0 Updated to use new query methods.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_percentage_complete() {
|
||||
$args = array(
|
||||
'fields' => 'ids',
|
||||
);
|
||||
|
||||
if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
|
||||
$args['date_query'] = $this->get_date_query();
|
||||
}
|
||||
|
||||
$total = edd_count_orders( $args );
|
||||
$percentage = 100;
|
||||
|
||||
if ( $total > 0 ) {
|
||||
$percentage = ( ( 30 * $this->step ) / $total ) * 100;
|
||||
}
|
||||
|
||||
if ( $percentage > 100 ) {
|
||||
$percentage = 100;
|
||||
}
|
||||
|
||||
return $percentage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the properties specific to the sales and earnings export.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $request Form data passed to the batch processor.
|
||||
*/
|
||||
public function set_properties( $request ) {
|
||||
$this->start = isset( $request['order-export-start'] )
|
||||
? sanitize_text_field( $request['order-export-start'] )
|
||||
: '';
|
||||
|
||||
$this->end = isset( $request['order-export-end'] )
|
||||
? sanitize_text_field( $request['order-export-end'] )
|
||||
: '';
|
||||
|
||||
$this->download_id = isset( $request['download_id'] )
|
||||
? absint( $request['download_id'] )
|
||||
: 0;
|
||||
|
||||
$this->customer_id = isset( $request['customer_id'] )
|
||||
? absint( $request['customer_id'] )
|
||||
: 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,163 @@
|
||||
<?php
|
||||
/**
|
||||
* Batch Sales Logs Export Class
|
||||
*
|
||||
* This class handles Sales logs export
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Admin/Reporting/Export
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 2.7
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* EDD_Batch_Sales_Export Class
|
||||
*
|
||||
* @since 2.7
|
||||
*/
|
||||
class EDD_Batch_Sales_Export extends EDD_Batch_Export {
|
||||
/**
|
||||
* Our export type. Used for export-type specific filters/actions
|
||||
*
|
||||
* @var string
|
||||
* @since 2.7
|
||||
*/
|
||||
public $export_type = 'sales';
|
||||
|
||||
/**
|
||||
* Set the CSV columns
|
||||
*
|
||||
* @since 2.7
|
||||
* @return array $cols All the columns
|
||||
*/
|
||||
public function csv_cols() {
|
||||
$cols = array(
|
||||
'ID' => __( 'Log ID', 'easy-digital-downloads' ),
|
||||
'user_id' => __( 'User', 'easy-digital-downloads' ),
|
||||
'customer_id' => __( 'Customer ID', 'easy-digital-downloads' ),
|
||||
'email' => __( 'Email', 'easy-digital-downloads' ),
|
||||
'first_name' => __( 'First Name', 'easy-digital-downloads' ),
|
||||
'last_name' => __( 'Last Name', 'easy-digital-downloads' ),
|
||||
'download' => edd_get_label_singular(),
|
||||
'quantity' => __( 'Quantity', 'easy-digital-downloads' ),
|
||||
'amount' => __( 'Item Amount', 'easy-digital-downloads' ),
|
||||
'payment_id' => __( 'Payment ID', 'easy-digital-downloads' ),
|
||||
'price_id' => __( 'Price ID', 'easy-digital-downloads' ),
|
||||
'date' => __( 'Date', 'easy-digital-downloads' ),
|
||||
);
|
||||
|
||||
return $cols;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Export Data
|
||||
*
|
||||
* @since 2.7
|
||||
* @since 3.0 Updated to use new query methods.
|
||||
*
|
||||
* @return array|bool The data for the CSV file, false if no data to return.
|
||||
*/
|
||||
public function get_data() {
|
||||
$data = array();
|
||||
|
||||
$args = array(
|
||||
'number' => 30,
|
||||
'offset' => ( $this->step * 30 ) - 30,
|
||||
'order' => 'ASC',
|
||||
);
|
||||
|
||||
if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
|
||||
$args['date_query'] = $this->get_date_query();
|
||||
}
|
||||
|
||||
if ( 0 !== $this->download_id ) {
|
||||
$args['product_id'] = $this->download_id;
|
||||
}
|
||||
|
||||
$items = edd_get_order_items( $args );
|
||||
|
||||
foreach ( $items as $item ) {
|
||||
/** @var EDD\Orders\Order_Item $item */
|
||||
$order = edd_get_order( $item->order_id );
|
||||
$download = edd_get_download( $item->product_id );
|
||||
$user_info = $order->get_user_info();
|
||||
|
||||
$download_title = $item->product_name;
|
||||
|
||||
// Maybe append variable price name.
|
||||
if ( $download->has_variable_prices() ) {
|
||||
$price_option = edd_get_price_option_name( $item->product_id, $item->price_id, $order->id );
|
||||
|
||||
$download_title .= ! empty( $price_option )
|
||||
? ' - ' . $price_option
|
||||
: '';
|
||||
}
|
||||
|
||||
$data[] = array(
|
||||
'ID' => $item->product_id,
|
||||
'user_id' => $order->user_id,
|
||||
'customer_id' => $order->customer_id,
|
||||
'email' => $order->email,
|
||||
'first_name' => isset( $user_info['first_name'] ) ? $user_info['first_name'] : '',
|
||||
'last_name' => isset( $user_info['last_name'] ) ? $user_info['last_name'] : '',
|
||||
'download' => $download_title,
|
||||
'quantity' => $item->quantity,
|
||||
'amount' => $order->total,
|
||||
'payment_id' => $order->id,
|
||||
'price_id' => $item->price_id,
|
||||
'date' => $order->date_created,
|
||||
);
|
||||
}
|
||||
|
||||
$data = apply_filters( 'edd_export_get_data', $data );
|
||||
$data = apply_filters( 'edd_export_get_data_' . $this->export_type, $data );
|
||||
|
||||
return ! empty( $data )
|
||||
? $data
|
||||
: false;
|
||||
}
|
||||
/**
|
||||
* Return the calculated completion percentage.
|
||||
*
|
||||
* @since 2.7
|
||||
* @since 3.0 Updated to use new query methods.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_percentage_complete() {
|
||||
$args = array(
|
||||
'fields' => 'ids',
|
||||
);
|
||||
|
||||
if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
|
||||
$args['date_query'] = $this->get_date_query();
|
||||
}
|
||||
|
||||
if ( 0 !== $this->download_id ) {
|
||||
$args['product_id'] = $this->download_id;
|
||||
}
|
||||
|
||||
$total = edd_count_order_items( $args );
|
||||
$percentage = 100;
|
||||
|
||||
if ( $total > 0 ) {
|
||||
$percentage = ( ( 30 * $this->step ) / $total ) * 100;
|
||||
}
|
||||
|
||||
if ( $percentage > 100 ) {
|
||||
$percentage = 100;
|
||||
}
|
||||
|
||||
return $percentage;
|
||||
}
|
||||
|
||||
public function set_properties( $request ) {
|
||||
$this->start = isset( $request['orders-export-start'] ) ? sanitize_text_field( $request['orders-export-start'] ) : '';
|
||||
$this->end = isset( $request['orders-export-end'] ) ? sanitize_text_field( $request['orders-export-end'] ) . ' 23:59:59' : '';
|
||||
$this->download_id = isset( $request['download_id'] ) ? absint( $request['download_id'] ) : 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,183 @@
|
||||
<?php
|
||||
/**
|
||||
* Taxed Customers Export Class.
|
||||
*
|
||||
* This class handles the taxed orders export in batches.
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Admin/Reporting/Export
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* EDD_Batch_Taxed_Orders_Export Class
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
class EDD_Batch_Taxed_Customers_Export extends EDD_Batch_Export {
|
||||
|
||||
/**
|
||||
* Our export type. Used for export-type specific filters/actions.
|
||||
*
|
||||
* @var string
|
||||
* @since 3.0
|
||||
*/
|
||||
public $export_type = 'taxed_customers';
|
||||
|
||||
/**
|
||||
* Set the CSV columns
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @return array $cols All the columns
|
||||
*/
|
||||
public function csv_cols() {
|
||||
$cols = array(
|
||||
'id' => __( 'ID', 'easy-digital-downloads' ),
|
||||
'name' => __( 'Name', 'easy-digital-downloads' ),
|
||||
'email' => __( 'Email', 'easy-digital-downloads' ),
|
||||
'purchases' => __( 'Number of Purchases', 'easy-digital-downloads' ),
|
||||
'amount' => __( 'Customer Value', 'easy-digital-downloads' ),
|
||||
);
|
||||
|
||||
return $cols;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the export data.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @return array $data The data for the CSV file.
|
||||
*/
|
||||
public function get_data() {
|
||||
$data = array();
|
||||
|
||||
$args = array(
|
||||
'number' => 30,
|
||||
'offset' => ( $this->step * 30 ) - 30,
|
||||
'status__in' => edd_get_complete_order_statuses(),
|
||||
'order' => 'ASC',
|
||||
'orderby' => 'date_created',
|
||||
'fields' => 'customer_id',
|
||||
);
|
||||
|
||||
if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
|
||||
$args['date_query'] = $this->get_date_query();
|
||||
}
|
||||
|
||||
add_filter( 'edd_orders_query_clauses', array( $this, 'query_clauses' ), 10, 2 );
|
||||
|
||||
$customer_ids = edd_get_orders( $args );
|
||||
|
||||
remove_filter( 'edd_orders_query_clauses', array( $this, 'query_clauses' ), 10 );
|
||||
|
||||
$customer_ids = array_unique( $customer_ids );
|
||||
|
||||
asort( $customer_ids );
|
||||
|
||||
foreach ( $customer_ids as $customer_id ) {
|
||||
|
||||
// Bail if a customer ID was not set.
|
||||
if ( 0 === $customer_id ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$customer = edd_get_customer( $customer_id );
|
||||
|
||||
// Bail if a customer record does not exist.
|
||||
if ( ! $customer ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = ! empty( $customer->name ) ? $customer->name : '';
|
||||
if ( preg_match( '~^[+\-=@]~m', $name ) ) {
|
||||
$name = "'{$name}";
|
||||
}
|
||||
|
||||
$data[] = array(
|
||||
'id' => $customer->id,
|
||||
'name' => $name,
|
||||
'email' => $customer->email,
|
||||
'purchases' => $customer->purchase_count,
|
||||
'amount' => edd_format_amount( $customer->purchase_value ),
|
||||
);
|
||||
}
|
||||
|
||||
$data = apply_filters( 'edd_export_get_data', $data );
|
||||
$data = apply_filters( 'edd_export_get_data_' . $this->export_type, $data );
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the calculated completion percentage.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_percentage_complete() {
|
||||
$args = array(
|
||||
'fields' => 'ids',
|
||||
'status__in' => edd_get_complete_order_statuses(),
|
||||
);
|
||||
|
||||
if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
|
||||
$args['date_query'] = $this->get_date_query();
|
||||
}
|
||||
|
||||
add_filter( 'edd_orders_query_clauses', array( $this, 'query_clauses' ), 10, 2 );
|
||||
|
||||
$total = edd_count_orders( $args );
|
||||
|
||||
remove_filter( 'edd_orders_query_clauses', array( $this, 'query_clauses' ), 10 );
|
||||
|
||||
$percentage = 100;
|
||||
|
||||
if ( $total > 0 ) {
|
||||
$percentage = ( ( 30 * $this->step ) / $total ) * 100;
|
||||
}
|
||||
|
||||
if ( $percentage > 100 ) {
|
||||
$percentage = 100;
|
||||
}
|
||||
|
||||
return $percentage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the properties specific to the taxed orders export.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $request The form data passed into the batch processing.
|
||||
*/
|
||||
public function set_properties( $request ) {
|
||||
$this->start = isset( $request['taxed-customers-export-start'] ) ? sanitize_text_field( $request['taxed-customers-export-start'] ) : '';
|
||||
$this->end = isset( $request['taxed-customers-export-end'] ) ? sanitize_text_field( $request['taxed-customers-export-end'] ) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the database query to only return orders which have tax applied to them.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $clauses A compacted array of item query clauses.
|
||||
* @param \EDD\Database\Query $base Instance passed by reference.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function query_clauses( $clauses, $base ) {
|
||||
$clauses['where'] = ! empty( $clauses['where'] )
|
||||
? $clauses['where'] .= ' AND tax > 0'
|
||||
: 'tax > 0';
|
||||
|
||||
return $clauses;
|
||||
}
|
||||
}
|
@ -0,0 +1,306 @@
|
||||
<?php
|
||||
/**
|
||||
* Taxed Orders Export Class.
|
||||
*
|
||||
* This class handles the taxed orders export in batches.
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Admin/Reporting/Export
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* EDD_Batch_Taxed_Orders_Export Class
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
class EDD_Batch_Taxed_Orders_Export extends EDD_Batch_Export {
|
||||
|
||||
/**
|
||||
* Our export type. Used for export-type specific filters/actions.
|
||||
*
|
||||
* @var string
|
||||
* @since 3.0
|
||||
*/
|
||||
public $export_type = 'taxed_orders';
|
||||
|
||||
/**
|
||||
* Set the CSV columns
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @return array $cols All the columns
|
||||
*/
|
||||
public function csv_cols() {
|
||||
$cols = array(
|
||||
'id' => __( 'Order ID', 'easy-digital-downloads' ), // unaltered payment ID (use for querying)
|
||||
'seq_id' => __( 'Order Number', 'easy-digital-downloads' ), // sequential payment ID
|
||||
'email' => __( 'Email', 'easy-digital-downloads' ),
|
||||
'customer_id' => __( 'Customer ID', 'easy-digital-downloads' ),
|
||||
'first' => __( 'First Name', 'easy-digital-downloads' ),
|
||||
'last' => __( 'Last Name', 'easy-digital-downloads' ),
|
||||
'address1' => __( 'Address', 'easy-digital-downloads' ),
|
||||
'address2' => __( 'Address (Line 2)', 'easy-digital-downloads' ),
|
||||
'city' => __( 'City', 'easy-digital-downloads' ),
|
||||
'state' => __( 'State', 'easy-digital-downloads' ),
|
||||
'country' => __( 'Country', 'easy-digital-downloads' ),
|
||||
'zip' => __( 'Zip / Postal Code', 'easy-digital-downloads' ),
|
||||
'products' => __( 'Products (Verbose)', 'easy-digital-downloads' ),
|
||||
'products_raw' => __( 'Products (Raw)', 'easy-digital-downloads' ),
|
||||
'skus' => __( 'SKUs', 'easy-digital-downloads' ),
|
||||
'amount' => __( 'Amount', 'easy-digital-downloads' ) . ' (' . html_entity_decode( edd_currency_filter( '' ) ) . ')',
|
||||
'tax' => __( 'Tax', 'easy-digital-downloads' ) . ' (' . html_entity_decode( edd_currency_filter( '' ) ) . ')',
|
||||
'discount' => __( 'Discount Code', 'easy-digital-downloads' ),
|
||||
'gateway' => __( 'Gateway', 'easy-digital-downloads' ),
|
||||
'trans_id' => __( 'Transaction ID', 'easy-digital-downloads' ),
|
||||
'key' => __( 'Purchase Key', 'easy-digital-downloads' ),
|
||||
'date' => __( 'Date', 'easy-digital-downloads' ),
|
||||
'user' => __( 'User', 'easy-digital-downloads' ),
|
||||
'currency' => __( 'Currency', 'easy-digital-downloads' ),
|
||||
'ip' => __( 'IP Address', 'easy-digital-downloads' ),
|
||||
'mode' => __( 'Mode (Live|Test)', 'easy-digital-downloads' ),
|
||||
'status' => __( 'Status', 'easy-digital-downloads' ),
|
||||
'country_name' => __( 'Country Name', 'easy-digital-downloads' ),
|
||||
);
|
||||
|
||||
if ( ! edd_use_skus() ) {
|
||||
unset( $cols['skus'] );
|
||||
}
|
||||
|
||||
if ( ! edd_get_option( 'enable_sequential' ) ) {
|
||||
unset( $cols['seq_id'] );
|
||||
}
|
||||
|
||||
return $cols;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the export data.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @return array $data The data for the CSV file.
|
||||
*/
|
||||
public function get_data() {
|
||||
$data = array();
|
||||
|
||||
$args = array(
|
||||
'number' => 30,
|
||||
'offset' => ( $this->step * 30 ) - 30,
|
||||
'status' => $this->status,
|
||||
'order' => 'ASC',
|
||||
'orderby' => 'date_created',
|
||||
'status__not_in' => array( 'trash' ),
|
||||
);
|
||||
|
||||
if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
|
||||
$args['date_created_query'] = $this->get_date_query();
|
||||
}
|
||||
|
||||
if ( 'any' === $args['status'] || 'all' === $args['status'] ) {
|
||||
unset( $args['status'] );
|
||||
}
|
||||
|
||||
add_filter( 'edd_orders_query_clauses', array( $this, 'query_clauses' ), 10, 2 );
|
||||
|
||||
$orders = edd_get_orders( $args );
|
||||
|
||||
remove_filter( 'edd_orders_query_clauses', array( $this, 'query_clauses' ), 10 );
|
||||
|
||||
foreach ( $orders as $order ) {
|
||||
/** @var EDD\Orders\Order $order */
|
||||
|
||||
$items = $order->get_items();
|
||||
$address = $order->get_address();
|
||||
$total = $order->total;
|
||||
$user_id = $order->user_id;
|
||||
$products = '';
|
||||
$products_raw = '';
|
||||
$skus = '';
|
||||
|
||||
$discounts = $order->get_discounts();
|
||||
$discounts = ! empty( $discounts )
|
||||
? implode( ', ', $discounts )
|
||||
: __( 'none', 'easy-digital-downloads' );
|
||||
|
||||
foreach ( $items as $key => $item ) {
|
||||
/** @var EDD\Orders\Order_Item $item */
|
||||
|
||||
// Setup item information.
|
||||
$id = $item->product_id;
|
||||
$qty = $item->quantity;
|
||||
$price = $item->amount;
|
||||
$tax = $item->tax;
|
||||
$price_id = $item->price_id;
|
||||
|
||||
// Set up verbose product column.
|
||||
$products .= html_entity_decode( get_the_title( $id ) );
|
||||
|
||||
if ( $qty > 1 ) {
|
||||
$products .= html_entity_decode( ' (' . $qty . ')' );
|
||||
}
|
||||
|
||||
$products .= ' - ';
|
||||
|
||||
if ( edd_use_skus() ) {
|
||||
$sku = edd_get_download_sku( $id );
|
||||
|
||||
if ( ! empty( $sku ) ) {
|
||||
$skus .= $sku;
|
||||
}
|
||||
}
|
||||
|
||||
if ( 0 < $item->price_id ) {
|
||||
$products .= html_entity_decode( edd_get_price_option_name( $id, $item->price_id, $order->id ) ) . ' - ';
|
||||
}
|
||||
|
||||
$products .= html_entity_decode( edd_currency_filter( edd_format_amount( $price ) ) );
|
||||
|
||||
if ( ( count( $items ) - 1 ) !== $key ) {
|
||||
$products .= ' / ';
|
||||
|
||||
if ( edd_use_skus() ) {
|
||||
$skus .= ' / ';
|
||||
}
|
||||
}
|
||||
|
||||
// Set up raw products column; nothing but product names.
|
||||
$products_raw .= html_entity_decode( get_the_title( $id ) ) . '|' . $price . '{' . $tax . '}';
|
||||
|
||||
// If we have a price ID, include it.
|
||||
if ( false !== $price_id ) {
|
||||
$products_raw .= '{' . $price_id . '}';
|
||||
}
|
||||
|
||||
if ( ( count( $items ) - 1 ) !== $key ) {
|
||||
$products_raw .= ' / ';
|
||||
}
|
||||
}
|
||||
|
||||
$user = is_numeric( $user_id )
|
||||
? get_userdata( $user_id )
|
||||
: false;
|
||||
|
||||
$data[] = array(
|
||||
'id' => $order->id,
|
||||
'seq_id' => $order->get_number(),
|
||||
'email' => $order->email,
|
||||
'customer_id' => $order->customer_id,
|
||||
'first' => $address->first_name,
|
||||
'last' => $address->last_name,
|
||||
'address1' => $address->address,
|
||||
'address2' => $address->address2,
|
||||
'city' => $address->city,
|
||||
'state' => $address->region,
|
||||
'country' => $address->country,
|
||||
'zip' => $address->postal_code,
|
||||
'products' => $products,
|
||||
'products_raw' => $products_raw,
|
||||
'skus' => $skus,
|
||||
'amount' => html_entity_decode( edd_format_amount( $total ) ), // The non-discounted item price
|
||||
'tax' => html_entity_decode( edd_format_amount( $order->tax ) ),
|
||||
'discount' => $discounts,
|
||||
'gateway' => edd_get_gateway_admin_label( $order->gateway ),
|
||||
'trans_id' => $order->get_transaction_id(),
|
||||
'key' => $order->payment_key,
|
||||
'date' => $order->date_created,
|
||||
'user' => $user ? $user->display_name : __( 'guest', 'easy-digital-downloads' ),
|
||||
'currency' => $order->currency,
|
||||
'ip' => $order->ip,
|
||||
'mode' => $order->mode,
|
||||
'status' => $order->status,
|
||||
'country_name' => isset( $user_info['address']['country'] ) ? edd_get_country_name( $user_info['address']['country'] ) : '',
|
||||
);
|
||||
}
|
||||
|
||||
$data = apply_filters( 'edd_export_get_data', $data );
|
||||
$data = apply_filters( 'edd_export_get_data_' . $this->export_type, $data );
|
||||
|
||||
return ! empty( $data )
|
||||
? $data
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the calculated completion percentage.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_percentage_complete() {
|
||||
$args = array(
|
||||
'fields' => 'ids',
|
||||
);
|
||||
|
||||
if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
|
||||
$args['date_created_query'] = $this->get_date_query();
|
||||
}
|
||||
|
||||
if ( 'any' !== $this->status ) {
|
||||
$args['status'] = $this->status;
|
||||
}
|
||||
|
||||
$total = edd_count_orders( $args );
|
||||
$percentage = 100;
|
||||
|
||||
if ( $total > 0 ) {
|
||||
$percentage = ( ( 30 * $this->step ) / $total ) * 100;
|
||||
}
|
||||
|
||||
if ( $percentage > 100 ) {
|
||||
$percentage = 100;
|
||||
}
|
||||
|
||||
return $percentage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the properties specific to the taxed orders export.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $request The form data passed into the batch processing.
|
||||
*/
|
||||
public function set_properties( $request ) {
|
||||
$this->start = isset( $request['taxed-orders-export-start'] ) ? sanitize_text_field( $request['taxed-orders-export-start'] ) : '';
|
||||
$this->end = isset( $request['taxed-orders-export-end'] ) ? sanitize_text_field( $request['taxed-orders-export-end'] ) : '';
|
||||
$this->status = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'complete';
|
||||
$this->country = isset( $request['country'] ) ? sanitize_text_field( $request['country'] ) : '';
|
||||
$this->region = isset( $request['region'] ) ? sanitize_text_field( $request['region'] ) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the database query to only return orders which have tax applied to them.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $clauses A compacted array of item query clauses.
|
||||
* @param \EDD\Database\Query $base Instance passed by reference.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function query_clauses( $clauses, $base ) {
|
||||
global $wpdb;
|
||||
|
||||
$clauses['where'] = ! empty( $clauses['where'] )
|
||||
? $clauses['where'] .= ' AND edd_o.tax > 0'
|
||||
: 'edd_o.tax > 0';
|
||||
|
||||
if ( ! empty( $this->country ) ) {
|
||||
$clauses['join'] = " INNER JOIN {$wpdb->edd_order_addresses} edd_oa ON edd_o.id = edd_oa.order_id";
|
||||
$clauses['where'] .= $wpdb->prepare( ' AND edd_oa.country = %s', $this->country );
|
||||
}
|
||||
|
||||
if ( ! empty( $this->region ) ) {
|
||||
$clauses['where'] .= $wpdb->prepare( ' AND edd_oa.region = %s', $this->region );
|
||||
}
|
||||
|
||||
return $clauses;
|
||||
}
|
||||
}
|
@ -0,0 +1,340 @@
|
||||
<?php
|
||||
/**
|
||||
* Batch Export Class
|
||||
*
|
||||
* This is the base class for all batch export methods. Each data export type (customers, payments, etc) extend this class
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Admin/Export
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 2.4
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* EDD_Export Class
|
||||
*
|
||||
* @since 2.4
|
||||
*/
|
||||
class EDD_Batch_Export extends EDD_Export {
|
||||
|
||||
/**
|
||||
* Whether or not we're done processing.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $done;
|
||||
|
||||
/**
|
||||
* The file the data is stored in
|
||||
*
|
||||
* @since 2.4
|
||||
*/
|
||||
protected $file;
|
||||
|
||||
/**
|
||||
* The name of the file the data is stored in
|
||||
*
|
||||
* @since 2.4
|
||||
*/
|
||||
public $filename;
|
||||
|
||||
/**
|
||||
* The file type, typically .csv
|
||||
*
|
||||
* @since 2.4
|
||||
*/
|
||||
public $filetype;
|
||||
|
||||
/**
|
||||
* The current step being processed
|
||||
*
|
||||
* @since 2.4
|
||||
*/
|
||||
public $step;
|
||||
|
||||
/**
|
||||
* Start date, Y-m-d H:i:s
|
||||
*
|
||||
* @since 2.4
|
||||
*/
|
||||
public $start;
|
||||
|
||||
/**
|
||||
* End date, Y-m-d H:i:s
|
||||
*
|
||||
* @since 2.4
|
||||
*/
|
||||
public $end;
|
||||
|
||||
/**
|
||||
* Status to export
|
||||
*
|
||||
* @since 2.4
|
||||
*/
|
||||
public $status;
|
||||
|
||||
/**
|
||||
* Download to export data for
|
||||
*
|
||||
* @since 2.4
|
||||
*/
|
||||
public $download = null;
|
||||
|
||||
/**
|
||||
* Download Price ID to export data for
|
||||
*
|
||||
* @since 2.4
|
||||
*/
|
||||
public $price_id = null;
|
||||
|
||||
/**
|
||||
* Is the export file writable
|
||||
*
|
||||
* @since 2.4.4
|
||||
*/
|
||||
public $is_writable = true;
|
||||
|
||||
/**
|
||||
* Is the export file empty
|
||||
*
|
||||
* @since 2.4.4
|
||||
*/
|
||||
public $is_empty = false;
|
||||
|
||||
/**
|
||||
* The data to return to the script.
|
||||
*
|
||||
* @since 3.0
|
||||
* @var array
|
||||
*/
|
||||
public $result_data = array();
|
||||
|
||||
/**
|
||||
* Get things started
|
||||
*
|
||||
* @param $_step int The step to process
|
||||
* @since 2.4
|
||||
*/
|
||||
public function __construct( $_step = 1 ) {
|
||||
|
||||
$upload_dir = wp_upload_dir();
|
||||
$this->filetype = '.csv';
|
||||
$this->filename = 'edd-' . $this->export_type . $this->filetype;
|
||||
$this->file = trailingslashit( $upload_dir['basedir'] ) . $this->filename;
|
||||
|
||||
if ( ! is_writeable( $upload_dir['basedir'] ) ) {
|
||||
$this->is_writable = false;
|
||||
}
|
||||
|
||||
$this->step = $_step;
|
||||
$this->done = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a step
|
||||
*
|
||||
* @since 2.4
|
||||
* @return bool
|
||||
*/
|
||||
public function process_step() {
|
||||
|
||||
if ( ! $this->can_export() ) {
|
||||
wp_die( __( 'You do not have permission to export data.', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
if( $this->step < 2 ) {
|
||||
|
||||
// Make sure we start with a fresh file on step 1
|
||||
if ( file_exists( $this->file ) ) {
|
||||
unlink( $this->file );
|
||||
}
|
||||
$this->print_csv_cols();
|
||||
}
|
||||
|
||||
$rows = $this->print_csv_rows();
|
||||
|
||||
if( $rows ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the CSV columns
|
||||
*
|
||||
* @since 2.4
|
||||
* @uses EDD_Export::get_csv_cols()
|
||||
* @return string
|
||||
*/
|
||||
public function print_csv_cols() {
|
||||
|
||||
$col_data = '';
|
||||
$cols = $this->get_csv_cols();
|
||||
$i = 1;
|
||||
foreach( $cols as $col_id => $column ) {
|
||||
$col_data .= '"' . addslashes( $column ) . '"';
|
||||
$col_data .= $i == count( $cols ) ? '' : ',';
|
||||
$i++;
|
||||
}
|
||||
$col_data .= "\r\n";
|
||||
|
||||
$this->stash_step_data( $col_data );
|
||||
|
||||
return $col_data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the CSV rows for the current step
|
||||
*
|
||||
* @since 2.4
|
||||
* @return string|false
|
||||
*/
|
||||
public function print_csv_rows() {
|
||||
|
||||
$row_data = '';
|
||||
$data = $this->get_data();
|
||||
$cols = $this->get_csv_cols();
|
||||
|
||||
if( $data ) {
|
||||
|
||||
// Output each row
|
||||
foreach ( $data as $row ) {
|
||||
$i = 1;
|
||||
foreach ( $row as $col_id => $column ) {
|
||||
// Make sure the column is valid
|
||||
if ( array_key_exists( $col_id, $cols ) ) {
|
||||
$row_data .= '"' . addslashes( preg_replace( "/\"/","'", $column ) ) . '"';
|
||||
$row_data .= $i == count( $cols ) ? '' : ',';
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$row_data .= "\r\n";
|
||||
}
|
||||
|
||||
$this->stash_step_data( $row_data );
|
||||
|
||||
return $row_data;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the calculated completion percentage
|
||||
*
|
||||
* @since 2.4
|
||||
* @return int
|
||||
*/
|
||||
public function get_percentage_complete() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the file data is written to
|
||||
*
|
||||
* @since 2.4
|
||||
* @return string
|
||||
*/
|
||||
protected function get_file() {
|
||||
|
||||
$file = '';
|
||||
|
||||
if ( @file_exists( $this->file ) ) {
|
||||
|
||||
if ( ! is_writeable( $this->file ) ) {
|
||||
$this->is_writable = false;
|
||||
}
|
||||
|
||||
$file = @file_get_contents( $this->file );
|
||||
|
||||
} else {
|
||||
|
||||
@file_put_contents( $this->file, '' );
|
||||
@chmod( $this->file, 0664 );
|
||||
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append data to export file
|
||||
*
|
||||
* @since 2.4
|
||||
* @param $data string The data to add to the file
|
||||
* @return void
|
||||
*/
|
||||
protected function stash_step_data( $data = '' ) {
|
||||
|
||||
$file = $this->get_file();
|
||||
$file .= $data;
|
||||
@file_put_contents( $this->file, $file );
|
||||
|
||||
// If we have no rows after this step, mark it as an empty export
|
||||
$file_rows = file( $this->file, FILE_SKIP_EMPTY_LINES);
|
||||
$default_cols = $this->get_csv_cols();
|
||||
$default_cols = empty( $default_cols ) ? 0 : 1;
|
||||
|
||||
$this->is_empty = count( $file_rows ) == $default_cols ? true : false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the export
|
||||
*
|
||||
* @since 2.4
|
||||
* @return void
|
||||
*/
|
||||
public function export() {
|
||||
|
||||
// Set headers
|
||||
$this->headers();
|
||||
|
||||
$file = $this->get_file();
|
||||
|
||||
@unlink( $this->file );
|
||||
|
||||
echo $file;
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the properties specific to the export
|
||||
*
|
||||
* @since 2.4.2
|
||||
* @param array $request The Form Data passed into the batch processing
|
||||
*/
|
||||
public function set_properties( $request ) {}
|
||||
|
||||
/**
|
||||
* Allow for prefetching of data for the remainder of the exporter
|
||||
*
|
||||
* @since 2.5
|
||||
* @return void
|
||||
*/
|
||||
public function pre_fetch() {}
|
||||
|
||||
/**
|
||||
* Gets the date query.
|
||||
*
|
||||
* @since 3.0
|
||||
* @return array
|
||||
*/
|
||||
protected function get_date_query() {
|
||||
return array(
|
||||
array(
|
||||
'after' => $this->start ? date( 'Y-m-d 00:00:00', strtotime( $this->start ) ) : '',
|
||||
'before' => $this->end ? date( 'Y-m-d 23:59:59', strtotime( $this->end ) ) : '',
|
||||
'inclusive' => true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,309 @@
|
||||
<?php
|
||||
/**
|
||||
* Exports Actions
|
||||
*
|
||||
* These are actions related to exporting data from Easy Digital Downloads.
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Admin/Export
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 2.4
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Process the download file generated by a batch export.
|
||||
*
|
||||
* @since 2.4
|
||||
*/
|
||||
function edd_process_batch_export_download() {
|
||||
if ( ! wp_verify_nonce( $_REQUEST['nonce'], 'edd-batch-export' ) ) {
|
||||
wp_die( esc_html__( 'Nonce verification failed', 'easy-digital-downloads' ), esc_html__( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
require_once EDD_PLUGIN_DIR . 'includes/admin/reporting/export/class-batch-export.php';
|
||||
do_action( 'edd_batch_export_class_include', $_REQUEST['class'] );
|
||||
|
||||
if ( class_exists( $_REQUEST['class'] ) && 'EDD_Batch_Export' === get_parent_class( $_REQUEST['class'] ) ) {
|
||||
$export = new $_REQUEST['class']();
|
||||
$export->export();
|
||||
}
|
||||
}
|
||||
add_action( 'edd_download_batch_export', 'edd_process_batch_export_download' );
|
||||
|
||||
/**
|
||||
* Export all the customers to a CSV file.
|
||||
*
|
||||
* Note: The WordPress Database API is being used directly for performance
|
||||
* reasons (workaround of calling all posts and fetch data respectively)
|
||||
*
|
||||
* @since 1.4.4
|
||||
* @return void
|
||||
*/
|
||||
function edd_export_all_customers() {
|
||||
require_once EDD_PLUGIN_DIR . 'includes/admin/reporting/class-export-customers.php';
|
||||
|
||||
$customer_export = new EDD_Customers_Export();
|
||||
|
||||
$customer_export->export();
|
||||
}
|
||||
add_action( 'edd_email_export', 'edd_export_all_customers' );
|
||||
|
||||
/**
|
||||
* Exports all the downloads to a CSV file using the EDD_Export class.
|
||||
*
|
||||
* @since 1.4.4
|
||||
* @return void
|
||||
*/
|
||||
function edd_export_all_downloads_history() {
|
||||
require_once EDD_PLUGIN_DIR . 'includes/admin/reporting/class-export-download-history.php';
|
||||
|
||||
$file_download_export = new EDD_Download_History_Export();
|
||||
|
||||
$file_download_export->export();
|
||||
}
|
||||
add_action( 'edd_downloads_history_export', 'edd_export_all_downloads_history' );
|
||||
|
||||
/**
|
||||
* Add a hook allowing extensions to register a hook on the batch export process
|
||||
*
|
||||
* @since 2.4.2
|
||||
* @return void
|
||||
*/
|
||||
function edd_register_batch_exporters() {
|
||||
if ( is_admin() ) {
|
||||
do_action( 'edd_register_batch_exporter' );
|
||||
}
|
||||
}
|
||||
add_action( 'plugins_loaded', 'edd_register_batch_exporters', 99 );
|
||||
|
||||
/**
|
||||
* Register the payments batch exporter
|
||||
* @since 2.4.2
|
||||
*/
|
||||
function edd_register_payments_batch_export() {
|
||||
add_action( 'edd_batch_export_class_include', 'edd_include_payments_batch_processor', 10, 1 );
|
||||
}
|
||||
add_action( 'edd_register_batch_exporter', 'edd_register_payments_batch_export', 10 );
|
||||
|
||||
/**
|
||||
* Loads the payments batch processor if needed.
|
||||
*
|
||||
* @since 2.4.2
|
||||
*
|
||||
* @param string $class The class being requested to run for the batch export
|
||||
*/
|
||||
function edd_include_payments_batch_processor( $class ) {
|
||||
if ( 'EDD_Batch_Payments_Export' === $class ) {
|
||||
require_once EDD_PLUGIN_DIR . 'includes/admin/reporting/export/class-batch-export-payments.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the customers batch exporter.
|
||||
*
|
||||
* @since 2.4.2
|
||||
*/
|
||||
function edd_register_customers_batch_export() {
|
||||
add_action( 'edd_batch_export_class_include', 'edd_include_customers_batch_processor', 10, 1 );
|
||||
}
|
||||
add_action( 'edd_register_batch_exporter', 'edd_register_customers_batch_export', 10 );
|
||||
|
||||
/**
|
||||
* Loads the customers batch processor if needed.
|
||||
*
|
||||
* @since 2.4.2
|
||||
*
|
||||
* @param string $class The class being requested to run for the batch export.
|
||||
*/
|
||||
function edd_include_customers_batch_processor( $class ) {
|
||||
if ( 'EDD_Batch_Customers_Export' === $class ) {
|
||||
require_once EDD_PLUGIN_DIR . 'includes/admin/reporting/export/class-batch-export-customers.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the download products batch exporter
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
function edd_register_downloads_batch_export() {
|
||||
add_action( 'edd_batch_export_class_include', 'edd_include_downloads_batch_processor', 10, 1 );
|
||||
}
|
||||
add_action( 'edd_register_batch_exporter', 'edd_register_downloads_batch_export', 10 );
|
||||
|
||||
/**
|
||||
* Loads the file downloads batch process if needed
|
||||
*
|
||||
* @since 2.5
|
||||
* @param string $class The class being requested to run for the batch export
|
||||
* @return void
|
||||
*/
|
||||
function edd_include_downloads_batch_processor( $class ) {
|
||||
if ( 'EDD_Batch_Downloads_Export' === $class ) {
|
||||
require_once EDD_PLUGIN_DIR . 'includes/admin/reporting/export/class-batch-export-downloads.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the file downloads batch exporter
|
||||
* @since 2.4.2
|
||||
*/
|
||||
function edd_register_file_downloads_batch_export() {
|
||||
add_action( 'edd_batch_export_class_include', 'edd_include_file_downloads_batch_processor', 10, 1 );
|
||||
}
|
||||
add_action( 'edd_register_batch_exporter', 'edd_register_file_downloads_batch_export', 10 );
|
||||
|
||||
/**
|
||||
* Loads the file downloads batch process if needed
|
||||
*
|
||||
* @since 2.4.2
|
||||
* @param string $class The class being requested to run for the batch export
|
||||
* @return void
|
||||
*/
|
||||
function edd_include_file_downloads_batch_processor( $class ) {
|
||||
if ( 'EDD_Batch_File_Downloads_Export' === $class ) {
|
||||
require_once EDD_PLUGIN_DIR . 'includes/admin/reporting/export/class-batch-export-file-downloads.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the sales batch exporter.
|
||||
*
|
||||
* @since 2.7
|
||||
*/
|
||||
function edd_register_sales_export_batch_export() {
|
||||
add_action( 'edd_batch_export_class_include', 'edd_include_sales_export_batch_processor', 10, 1 );
|
||||
}
|
||||
add_action( 'edd_register_batch_exporter', 'edd_register_sales_export_batch_export', 10 );
|
||||
|
||||
/**
|
||||
* Loads the sales export batch process if needed
|
||||
*
|
||||
* @since 2.7
|
||||
* @param string $class The class being requested to run for the batch export
|
||||
* @return void
|
||||
*/
|
||||
function edd_include_sales_export_batch_processor( $class ) {
|
||||
if ( 'EDD_Batch_Sales_Export' === $class ) {
|
||||
require_once EDD_PLUGIN_DIR . 'includes/admin/reporting/export/class-batch-export-sales.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the earnings report batch exporter
|
||||
*
|
||||
* @since 2.7
|
||||
*/
|
||||
function edd_register_earnings_report_batch_export() {
|
||||
add_action( 'edd_batch_export_class_include', 'edd_include_earnings_report_batch_processor', 10, 1 );
|
||||
}
|
||||
add_action( 'edd_register_batch_exporter', 'edd_register_earnings_report_batch_export', 10 );
|
||||
|
||||
/**
|
||||
* Loads the earnings report batch process if needed
|
||||
*
|
||||
* @since 2.7
|
||||
* @param string $class The class being requested to run for the batch export
|
||||
* @return void
|
||||
*/
|
||||
function edd_include_earnings_report_batch_processor( $class ) {
|
||||
if ( 'EDD_Batch_Earnings_Report_Export' === $class ) {
|
||||
require_once EDD_PLUGIN_DIR . 'includes/admin/reporting/export/class-batch-export-earnings-report.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the API requests batch exporter
|
||||
*
|
||||
* @since 2.7
|
||||
*/
|
||||
function edd_register_api_requests_batch_export() {
|
||||
add_action( 'edd_batch_export_class_include', 'edd_include_api_requests_batch_processor', 10, 1 );
|
||||
}
|
||||
add_action( 'edd_register_batch_exporter', 'edd_register_api_requests_batch_export', 10 );
|
||||
|
||||
/**
|
||||
* Loads the API requests batch process if needed
|
||||
*
|
||||
* @since 2.7
|
||||
* @param string $class The class being requested to run for the batch export
|
||||
* @return void
|
||||
*/
|
||||
function edd_include_api_requests_batch_processor( $class ) {
|
||||
if ( 'EDD_Batch_API_Requests_Export' === $class ) {
|
||||
require_once EDD_PLUGIN_DIR . 'includes/admin/reporting/export/class-batch-export-api-requests.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the taxed orders report batch exporter.
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
function edd_register_taxed_orders_batch_export() {
|
||||
add_action( 'edd_batch_export_class_include', 'edd_include_taxed_orders_batch_processor', 10, 1 );
|
||||
}
|
||||
add_action( 'edd_register_batch_exporter', 'edd_register_taxed_orders_batch_export', 10 );
|
||||
|
||||
/**
|
||||
* Loads the taxed orders report batch process if needed.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param string $class The class being requested to run for the batch export
|
||||
*/
|
||||
function edd_include_taxed_orders_batch_processor( $class ) {
|
||||
if ( 'EDD_Batch_Taxed_Orders_Export' === $class ) {
|
||||
require_once EDD_PLUGIN_DIR . 'includes/admin/reporting/export/class-batch-export-taxed-orders.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the taxed orders report batch exporter.
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
function edd_register_taxed_customers_batch_export() {
|
||||
add_action( 'edd_batch_export_class_include', 'edd_include_taxed_customers_batch_processor', 10, 1 );
|
||||
}
|
||||
add_action( 'edd_register_batch_exporter', 'edd_register_taxed_customers_batch_export', 10 );
|
||||
|
||||
/**
|
||||
* Loads the taxed customers report batch process if needed.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param string $class The class being requested to run for the batch export
|
||||
*/
|
||||
function edd_include_taxed_customers_batch_processor( $class ) {
|
||||
if ( 'EDD_Batch_Taxed_Customers_Export' === $class ) {
|
||||
require_once EDD_PLUGIN_DIR . 'includes/admin/reporting/export/class-batch-export-taxed-customers.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the sales and earnings report batch exporter.
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
function edd_register_sales_and_earnings_batch_export() {
|
||||
add_action( 'edd_batch_export_class_include', 'edd_include_sales_and_earnings_batch_processor', 10, 1 );
|
||||
}
|
||||
add_action( 'edd_register_batch_exporter', 'edd_register_sales_and_earnings_batch_export', 10 );
|
||||
|
||||
/**
|
||||
* Loads the sales and earnings batch process if needed.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param string $class The class being requested to run for the batch export
|
||||
*/
|
||||
function edd_include_sales_and_earnings_batch_processor( $class ) {
|
||||
if ( 'EDD_Batch_Sales_And_Earnings_Export' === $class ) {
|
||||
require_once EDD_PLUGIN_DIR . 'includes/admin/reporting/export/class-batch-export-sales-and-earnings.php';
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* Exports Functions
|
||||
*
|
||||
* These are functions are used for exporting data from Easy Digital Downloads.
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Admin/Export
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
require_once EDD_PLUGIN_DIR . 'includes/admin/reporting/class-export.php';
|
||||
require_once EDD_PLUGIN_DIR . 'includes/admin/reporting/export/export-actions.php';
|
||||
|
||||
/**
|
||||
* Process batch exports via AJAX.
|
||||
*
|
||||
* @since 2.4
|
||||
*/
|
||||
function edd_do_ajax_export() {
|
||||
require_once EDD_PLUGIN_DIR . 'includes/admin/reporting/export/class-batch-export.php';
|
||||
|
||||
parse_str( $_POST['form'], $form ); // WPCS: CSRF ok.
|
||||
|
||||
$_REQUEST = $form;
|
||||
$form = (array) $form;
|
||||
|
||||
if ( ! wp_verify_nonce( $_REQUEST['edd_ajax_export'], 'edd_ajax_export' ) ) {
|
||||
die( '-2' );
|
||||
}
|
||||
|
||||
do_action( 'edd_batch_export_class_include', $form['edd-export-class'] );
|
||||
|
||||
$step = absint( $_POST['step'] );
|
||||
$class = sanitize_text_field( $form['edd-export-class'] );
|
||||
|
||||
/** @var \EDD_Batch_Export $export */
|
||||
$export = new $class( $step );
|
||||
|
||||
if ( ! $export->can_export() ) {
|
||||
die( '-1' );
|
||||
}
|
||||
|
||||
if ( ! $export->is_writable ) {
|
||||
echo wp_json_encode( array(
|
||||
'error' => true,
|
||||
'message' => __( 'Export location or file not writable', 'easy-digital-downloads' ),
|
||||
));
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$export->set_properties( $_REQUEST );
|
||||
|
||||
// Added in 2.5 to allow a bulk processor to pre-fetch some data to speed up the remaining steps and cache data.
|
||||
$export->pre_fetch();
|
||||
|
||||
$ret = $export->process_step();
|
||||
|
||||
$percentage = $export->get_percentage_complete();
|
||||
|
||||
if ( $ret ) {
|
||||
$step++;
|
||||
|
||||
echo wp_json_encode( array(
|
||||
'step' => absint( $step ),
|
||||
'percentage' => esc_attr( $percentage ),
|
||||
) );
|
||||
|
||||
exit;
|
||||
} elseif ( true === $export->is_empty ) {
|
||||
echo wp_json_encode( array(
|
||||
'error' => true,
|
||||
'message' => __( 'No data found for export parameters', 'easy-digital-downloads' ),
|
||||
) );
|
||||
|
||||
exit;
|
||||
} elseif ( true === $export->done && true === $export->is_void ) {
|
||||
$message = ! empty( $export->message )
|
||||
? $export->message
|
||||
: __( 'Batch Processing Complete', 'easy-digital-downloads' );
|
||||
|
||||
echo wp_json_encode( array(
|
||||
'success' => true,
|
||||
'message' => $message,
|
||||
'data' => $export->result_data,
|
||||
) );
|
||||
|
||||
exit;
|
||||
} else {
|
||||
$args = array_merge( $_REQUEST, array(
|
||||
'step' => absint( $step ),
|
||||
'class' => urlencode( $class ),
|
||||
'nonce' => wp_create_nonce( 'edd-batch-export' ),
|
||||
'edd_action' => 'download_batch_export',
|
||||
) );
|
||||
|
||||
$download_url = add_query_arg( $args, admin_url() );
|
||||
|
||||
echo wp_json_encode( array(
|
||||
'step' => 'done',
|
||||
'url' => esc_url_raw( $download_url ),
|
||||
) );
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
add_action( 'wp_ajax_edd_do_ajax_export', 'edd_do_ajax_export' );
|
Reference in New Issue
Block a user