function wc_subs_exporter_admin_init() { global $wc_subs_exporter; $action = wc_subs_exporter_get_action(); switch ($action) { case 'dismiss_memory_prompt': wc_subs_exporter_update_option('dismiss_memory_prompt', 1); $url = add_query_arg('action', null); wp_redirect($url); break; case 'save-options': $export = new stdClass(); $export->delimiter = empty($_POST['delimiter']) ? ',' : $_POST['delimiter']; if ($export->delimiter != wc_subs_exporter_get_option('delimiter')) { wc_subs_exporter_update_option('delimiter', $export->delimiter); } $export->category_separator = $_POST['category_separator']; if ($export->category_separator != wc_subs_exporter_get_option('category_separator')) { wc_subs_exporter_update_option('category_separator', $export->category_separator); } $export->bom = $_POST['bom']; if ($export->bom != wc_subs_exporter_get_option('bom')) { wc_subs_exporter_update_option('bom', $export->bom); } $export->escape_formatting = $_POST['escape_formatting']; if ($export->escape_formatting != wc_subs_exporter_get_option('escape_formatting')) { wc_subs_exporter_update_option('escape_formatting', $export->escape_formatting); } $export->encoding = $_POST['encoding']; if ($export->encoding != wc_subs_exporter_get_option('encoding')) { wc_subs_exporter_update_option('encoding', $export->encoding); } $export->limit_volume = -1; if (!empty($_POST['limit_volume'])) { $export->limit_volume = $_POST['limit_volume']; if ($export->limit_volume != wc_subs_exporter_get_option('limit_volume')) { wc_subs_exporter_update_option('limit_volume', $export->limit_volume); } } $export->offset = 0; if (!empty($_POST['offset'])) { $export->offset = (int) $_POST['offset']; if ($export->offset != wc_subs_exporter_get_option('offset')) { wc_subs_exporter_update_option('offset', $export->offset); } } $export->save_csv_archive = 0; if (!empty($_POST['save_csv_archive'])) { $export->save_csv_archive = (int) $_POST['save_csv_archive']; if ($export->limit_volume != wc_subs_exporter_get_option('save_csv_archive')) { wc_subs_exporter_update_option('save_csv_archive', $export->save_csv_archive); } } $timeout = 600; if (isset($_POST['timeout'])) { $timeout = $_POST['timeout']; if ($timeout != wc_subs_exporter_get_option('timeout')) { wc_subs_exporter_update_option('timeout', $timeout); } } break; case 'export': $export = new stdClass(); $export->type = 'subscriptions'; $export->filename = wc_subs_exporter_generate_csv_filename($export->type); $export->delimiter = wc_subs_exporter_get_option('delimiter', ','); $export->category_separator = wc_subs_exporter_get_option('category_separator', '|'); $export->bom = wc_subs_exporter_get_option('bom', 1); $export->escape_formatting = wc_subs_exporter_get_option('escape_formatting', 'all'); $export->limit_volume = wc_subs_exporter_get_option('limit_volume', -1); $export->offset = wc_subs_exporter_get_option('offset', 0); $export->save_csv_archive = wc_subs_exporter_get_option('save_csv_archive', 1); $export->encoding = wc_subs_exporter_get_option('encoding', 'UTF-8'); $file_encodings = mb_list_encodings(); $export->status = isset($_POST['status']) ? $_POST['status'] : false; $export->dates_from = isset($_POST['from_date']) ? wc_subs_exporter_format_date($_POST['from_date']) : false; $export->dates_to = isset($_POST['to_date']) ? wc_subs_exporter_format_date($_POST['to_date']) : false; if (!ini_get('safe_mode')) { $timeout = wc_subs_exporter_get_option('timeout'); set_time_limit($timeout); } @ini_set('memory_limit', WP_MAX_MEMORY_LIMIT); // get subscriptions $transient_subscriptions = get_transient(wc_subs_exporter_get_transient_name()); if ($transient_subscriptions) { $export->subscriptions = $transient_subscriptions; } else { $export->subscriptions = wc_subs_exporter_get_filtered_subscriptions($export); } if (isset($wc_subs_exporter['debug']) && $wc_subs_exporter['debug']) { wc_subs_exporter_create_csv($export); } else { /* Generate CSV contents */ $bits = wc_subs_exporter_create_csv($export); if (!$bits) { wp_redirect(add_query_arg('empty', 1)); exit; } if (!$export->save_csv_archive) { /* Print to browser */ wc_subs_exporter_generate_csv_header($export->type); echo $bits; exit; } else { /* Save to file and insert to WordPress Media */ if ($export->filename && $bits) { $post_ID = wc_subs_exporter_save_csv_file_attachment($export->filename); $upload = wp_upload_bits($export->filename, null, $bits); $attach_data = wp_generate_attachment_metadata($post_ID, $upload['file']); wp_update_attachment_metadata($post_ID, $attach_data); if ($post_ID) { wc_subs_exporter_save_csv_file_guid($post_ID, $export->type, $upload['url']); } wc_subs_exporter_generate_csv_header($export->type); readfile($upload['file']); } else { wp_redirect(add_query_arg('failed', true)); } exit; } } break; default: break; } }
function wc_subs_exporter_memory_prompt() { if (!wc_subs_exporter_get_option('dismiss_memory_prompt', 0)) { $memory_limit = (int) ini_get('memory_limit'); $minimum_memory_limit = 64; if ($memory_limit < $minimum_memory_limit) { ob_start(); $memory_url = add_query_arg('action', 'dismiss_memory_prompt'); $message = sprintf(__('We recommend setting memory to at least 64MB, your site has %dMB currently allocated. See: <a href="%s" target="_blank">Increasing memory allocated to PHP</a>', 'wc-subs-exporter'), $memory_limit, 'http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP'); ?> <div class="error settings-error"> <p> <strong><?php echo $message; ?> </strong> <span style="float:right;"><a href="<?php echo $memory_url; ?> "><?php _e('Dismiss', 'wc-subs-exporter'); ?> </a></span> </p> </div> <?php ob_end_flush(); } } }
if ('calculate-export-size' != wc_subs_exporter_get_action()) { ?> <input type="submit" value="<?php _e('Calculate Export Size', 'wc-subs-exporter'); ?> " class="button-primary" /> <input type="hidden" name="action" value="calculate-export-size" /> <?php } else { $subscriptions = get_transient(wc_subs_exporter_get_transient_name()); if (false == $subscriptions) { echo '<p>' . __('No subscriptions found.', 'wc-subs-exporter') . '</p>'; } else { $subscriptions_count = sizeof($subscriptions); $offset = wc_subs_exporter_get_option('offset', 0); $limit_volume = wc_subs_exporter_get_option('limit_volume', -1); if (0 == $offset) { if (1 > $limit_volume) { echo '<p>' . sprintf(__('Found %s subscriptions to export.', 'wc-subs-exporter'), number_format_i18n($subscriptions_count)) . '</p>'; } else { echo '<p>' . sprintf(__('Found %s subscriptions, because of volume limit of %s.', 'wc-subs-exporter'), number_format_i18n($subscriptions_count), number_format_i18n($limit_volume)) . '</p>'; } } else { if (1 > $limit_volume) { echo '<p>' . sprintf(__('Found %s subscriptions, after skipping %s of them due to volume offset.', 'wc-subs-exporter'), number_format_i18n($subscriptions_count), number_format_i18n($offset)) . '</p>'; } else { echo '<p>' . sprintf(__('Found %s subscriptions, after skipping %s of them due to volume offset. Volume limit is %s.', 'wc-subs-exporter'), number_format_i18n($subscriptions_count), number_format_i18n($offset), number_format_i18n($limit_volume)) . '</p>'; } } if ($subscriptions_count > 2000 && 1 > $limit_volume && 0 == $offset) { echo '<p class="error">' . sprintf(__('You have more than %s subscriptions to export. Unfortunately not all servers can process that much, so it is advised that you do a partial export.', 'wc-subs-exporter'), number_format_i18n('2000')) . '</p>';