コード例 #1
0
ファイル: admin.php プロジェクト: mynein/myne
function woo_ce_tab_template($tab = '')
{
    if (!$tab) {
        $tab = 'overview';
    }
    // Store Exporter Deluxe
    $woo_cd_url = 'http://www.visser.com.au/woocommerce/plugins/exporter-deluxe/';
    $woo_cd_link = sprintf('<a href="%s" target="_blank">' . __('Store Exporter Deluxe', 'woo_ce') . '</a>', $woo_cd_url);
    $troubleshooting_url = 'http://www.visser.com.au/documentation/store-exporter-deluxe/';
    switch ($tab) {
        case 'overview':
            $skip_overview = woo_ce_get_option('skip_overview', false);
            break;
        case 'export':
            $export_type = sanitize_text_field(isset($_POST['dataset']) ? $_POST['dataset'] : woo_ce_get_option('last_export', 'product'));
            $types = array_keys(woo_ce_return_export_types());
            // Check if the default export type exists
            if (!in_array($export_type, $types)) {
                $export_type = 'product';
            }
            $products = woo_ce_return_count('product');
            $categories = woo_ce_return_count('category');
            $tags = woo_ce_return_count('tag');
            $brands = '999';
            $orders = '999';
            $customers = '999';
            $users = woo_ce_return_count('user');
            $coupons = '999';
            $attributes = '999';
            $subscriptions = '999';
            $product_vendors = '999';
            $commissions = '999';
            $shipping_classes = '999';
            add_action('woo_ce_export_options', 'woo_ce_export_options_export_format');
            if ($product_fields = woo_ce_get_product_fields()) {
                foreach ($product_fields as $key => $product_field) {
                    $product_fields[$key]['disabled'] = isset($product_field['disabled']) ? $product_field['disabled'] : 0;
                }
                add_action('woo_ce_export_product_options_before_table', 'woo_ce_products_filter_by_product_category');
                add_action('woo_ce_export_product_options_before_table', 'woo_ce_products_filter_by_product_tag');
                add_action('woo_ce_export_product_options_before_table', 'woo_ce_products_filter_by_product_brand');
                add_action('woo_ce_export_product_options_before_table', 'woo_ce_products_filter_by_product_vendor');
                add_action('woo_ce_export_product_options_before_table', 'woo_ce_products_filter_by_product_status');
                add_action('woo_ce_export_product_options_before_table', 'woo_ce_products_filter_by_product_type');
                add_action('woo_ce_export_product_options_before_table', 'woo_ce_products_filter_by_stock_status');
                add_action('woo_ce_export_product_options_after_table', 'woo_ce_product_sorting');
                add_action('woo_ce_export_options', 'woo_ce_products_upsells_formatting');
                add_action('woo_ce_export_options', 'woo_ce_products_crosssells_formatting');
                add_action('woo_ce_export_options', 'woo_ce_export_options_gallery_format');
                add_action('woo_ce_export_after_form', 'woo_ce_products_custom_fields');
            }
            if ($category_fields = woo_ce_get_category_fields()) {
                foreach ($category_fields as $key => $category_field) {
                    $category_fields[$key]['disabled'] = isset($category_field['disabled']) ? $category_field['disabled'] : 0;
                }
                add_action('woo_ce_export_category_options_after_table', 'woo_ce_category_sorting');
            }
            if ($tag_fields = woo_ce_get_tag_fields()) {
                foreach ($tag_fields as $key => $tag_field) {
                    $tag_fields[$key]['disabled'] = isset($tag_field['disabled']) ? $tag_field['disabled'] : 0;
                }
                add_action('woo_ce_export_tag_options_after_table', 'woo_ce_tag_sorting');
            }
            if ($brand_fields = woo_ce_get_brand_fields()) {
                foreach ($brand_fields as $key => $brand_field) {
                    $brand_fields[$key]['disabled'] = isset($brand_field['disabled']) ? $brand_field['disabled'] : 0;
                }
                add_action('woo_ce_export_brand_options_before_table', 'woo_ce_brand_sorting');
            }
            if ($order_fields = woo_ce_get_order_fields()) {
                add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_date');
                add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_status');
                add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_customer');
                add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_billing_country');
                add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_shipping_country');
                add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_user_role');
                add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_coupon');
                add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_product');
                add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_product_category');
                add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_product_tag');
                add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_product_brand');
                add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_order_id');
                add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_payment_gateway');
                add_action('woo_ce_export_order_options_before_table', 'woo_ce_orders_filter_by_shipping_method');
                add_action('woo_ce_export_order_options_after_table', 'woo_ce_order_sorting');
                add_action('woo_ce_export_options', 'woo_ce_orders_items_formatting');
                add_action('woo_ce_export_options', 'woo_ce_orders_max_order_items');
                add_action('woo_ce_export_options', 'woo_ce_orders_items_types');
                add_action('woo_ce_export_after_form', 'woo_ce_orders_custom_fields');
            }
            if ($customer_fields = woo_ce_get_customer_fields()) {
                add_action('woo_ce_export_customer_options_before_table', 'woo_ce_customers_filter_by_status');
                add_action('woo_ce_export_customer_options_before_table', 'woo_ce_customers_filter_by_user_role');
                add_action('woo_ce_export_after_form', 'woo_ce_customers_custom_fields');
            }
            if ($user_fields = woo_ce_get_user_fields()) {
                foreach ($user_fields as $key => $user_field) {
                    $user_fields[$key]['disabled'] = isset($user_field['disabled']) ? $user_field['disabled'] : 0;
                }
                add_action('woo_ce_export_user_options_after_table', 'woo_ce_user_sorting');
                add_action('woo_ce_export_after_form', 'woo_ce_users_custom_fields');
            }
            if ($coupon_fields = woo_ce_get_coupon_fields()) {
                add_action('woo_ce_export_coupon_options_before_table', 'woo_ce_coupon_sorting');
            }
            if ($subscription_fields = woo_ce_get_subscription_fields()) {
                add_action('woo_ce_export_subscription_options_before_table', 'woo_ce_subscriptions_filter_by_subscription_status');
                add_action('woo_ce_export_subscription_options_before_table', 'woo_ce_subscriptions_filter_by_subscription_product');
            }
            $product_vendor_fields = woo_ce_get_product_vendor_fields();
            if ($commission_fields = woo_ce_get_commission_fields()) {
                add_action('woo_ce_export_commission_options_before_table', 'woo_ce_commissions_filter_by_date');
                add_action('woo_ce_export_commission_options_before_table', 'woo_ce_commissions_filter_by_product_vendor');
                add_action('woo_ce_export_commission_options_before_table', 'woo_ce_commissions_filter_by_commission_status');
                add_action('woo_ce_export_commission_options_before_table', 'woo_ce_commission_sorting');
            }
            if ($shipping_class_fields = woo_ce_get_shipping_class_fields()) {
                add_action('woo_ce_export_shipping_class_options_after_table', 'woo_ce_shipping_class_sorting');
            }
            $attribute_fields = false;
            // Export modules
            $modules = woo_ce_modules_list();
            // Export options
            $limit_volume = woo_ce_get_option('limit_volume');
            $offset = woo_ce_get_option('offset');
            break;
        case 'fields':
            $export_type = isset($_GET['type']) ? sanitize_text_field($_GET['type']) : '';
            $types = array_keys(woo_ce_return_export_types());
            $fields = array();
            if (in_array($export_type, $types)) {
                if (has_filter('woo_ce_' . $export_type . '_fields', 'woo_ce_override_' . $export_type . '_field_labels')) {
                    remove_filter('woo_ce_' . $export_type . '_fields', 'woo_ce_override_' . $export_type . '_field_labels', 11);
                }
                if (function_exists(sprintf('woo_ce_get_%s_fields', $export_type))) {
                    $fields = call_user_func('woo_ce_get_' . $export_type . '_fields');
                }
                $labels = woo_ce_get_option($export_type . '_labels', array());
            }
            break;
        case 'archive':
            if (isset($_GET['deleted'])) {
                $message = __('Archived export has been deleted.', 'woo_ce');
                woo_ce_admin_notice($message);
            }
            if ($files = woo_ce_get_archive_files()) {
                foreach ($files as $key => $file) {
                    $files[$key] = woo_ce_get_archive_file($file);
                }
            }
            break;
        case 'settings':
            $export_filename = woo_ce_get_option('export_filename', '');
            // Default export filename
            if (empty($export_filename)) {
                $export_filename = 'woo-export_%dataset%-%date%.csv';
            }
            $delete_file = woo_ce_get_option('delete_file', 0);
            $timeout = woo_ce_get_option('timeout', 0);
            $encoding = woo_ce_get_option('encoding', 'UTF-8');
            $bom = woo_ce_get_option('bom', 1);
            $delimiter = woo_ce_get_option('delimiter', ',');
            $category_separator = woo_ce_get_option('category_separator', '|');
            $escape_formatting = woo_ce_get_option('escape_formatting', 'all');
            $date_format = woo_ce_get_option('date_format', 'd/m/Y');
            if ($date_format == 1 || $date_format == '') {
                $date_format = 'd/m/Y';
            }
            $file_encodings = function_exists('mb_list_encodings') ? mb_list_encodings() : false;
            add_action('woo_ce_export_settings_top', 'woo_ce_export_settings_quicklinks');
            add_action('woo_ce_export_settings_after', 'woo_ce_export_settings_csv');
            add_action('woo_ce_export_settings_after', 'woo_ce_export_settings_cron');
            break;
        case 'tools':
            // Product Importer Deluxe
            $woo_pd_url = 'http://www.visser.com.au/woocommerce/plugins/product-importer-deluxe/';
            $woo_pd_target = ' target="_blank"';
            if (function_exists('woo_pd_init')) {
                $woo_pd_url = add_query_arg(array('page' => 'woo_pd', 'tab' => null));
                $woo_pd_target = false;
            }
            // Store Toolkit
            $woo_st_url = 'http://www.visser.com.au/woocommerce/plugins/store-toolkit/';
            $woo_st_target = ' target="_blank"';
            if (function_exists('woo_st_admin_init')) {
                $woo_st_url = add_query_arg(array('page' => 'woo_st', 'tab' => null));
                $woo_st_target = false;
            }
            break;
    }
    if ($tab) {
        if (file_exists(WOO_CE_PATH . 'templates/admin/tabs-' . $tab . '.php')) {
            include_once WOO_CE_PATH . 'templates/admin/tabs-' . $tab . '.php';
        } else {
            $message = sprintf(__('We couldn\'t load the export template file <code>%s</code> within <code>%s</code>, this file should be present.', 'woo_ce'), 'tabs-' . $tab . '.php', WOO_CE_PATH . 'templates/admin/...');
            woo_ce_admin_notice_html($message, 'error');
            ob_start();
            ?>
<p><?php 
            _e('You can see this error for one of a few common reasons', 'woo_ce');
            ?>
:</p>
<ul class="ul-disc">
	<li><?php 
            _e('WordPress was unable to create this file when the Plugin was installed or updated', 'woo_ce');
            ?>
</li>
	<li><?php 
            _e('The Plugin files have been recently changed and there has been a file conflict', 'woo_ce');
            ?>
</li>
	<li><?php 
            _e('The Plugin file has been locked and cannot be opened by WordPress', 'woo_ce');
            ?>
</li>
</ul>
<p><?php 
            _e('Jump onto our website and download a fresh copy of this Plugin as it might be enough to fix this issue. If this persists get in touch with us.', 'woo_ce');
            ?>
</p>
<?php 
            ob_end_flush();
        }
    }
}
コード例 #2
0
ファイル: functions.php プロジェクト: Junaid-Farid/gocnex
function woo_ce_export_dataset($export_type = null, &$output = null)
{
    global $export;
    $separator = $export->delimiter;
    $export->columns = array();
    $export->total_rows = 0;
    $export->total_columns = 0;
    $troubleshooting_url = 'http://www.visser.com.au/documentation/store-exporter-deluxe/usage/';
    set_transient(WOO_CE_PREFIX . '_running', time(), woo_ce_get_option('timeout', MINUTE_IN_SECONDS));
    // Load up the fatal error notice if we 500 Internal Server Error (memory), hit a server timeout or encounter a fatal PHP error
    add_action('shutdown', 'woo_ce_fatal_error');
    // Drop in our content filters here
    add_filter('sanitize_key', 'woo_ce_sanitize_key');
    switch ($export_type) {
        // Products
        case 'product':
            $fields = woo_ce_get_product_fields('summary');
            if ($export->fields = array_intersect_assoc((array) $export->fields, $fields)) {
                foreach ($export->fields as $key => $field) {
                    $export->columns[] = woo_ce_get_product_field($key);
                }
            }
            $export->total_columns = $size = count($export->columns);
            $export->data_memory_start = woo_ce_current_memory_usage();
            if ($products = woo_ce_get_products($export->args)) {
                $export->total_rows = count($products);
                // Generate the export headers
                if (in_array($export->export_format, array('csv'))) {
                    for ($i = 0; $i < $size; $i++) {
                        if ($i == $size - 1) {
                            $output .= woo_ce_escape_csv_value($export->columns[$i], $export->delimiter, $export->escape_formatting) . "\n";
                        } else {
                            $output .= woo_ce_escape_csv_value($export->columns[$i], $export->delimiter, $export->escape_formatting) . $separator;
                        }
                    }
                }
                $weight_unit = get_option('woocommerce_weight_unit');
                $dimension_unit = get_option('woocommerce_dimension_unit');
                $height_unit = $dimension_unit;
                $width_unit = $dimension_unit;
                $length_unit = $dimension_unit;
                if (!empty($export->fields)) {
                    foreach ($products as $product) {
                        $product = woo_ce_get_product_data($product, $export->args);
                        foreach ($export->fields as $key => $field) {
                            if (isset($product->{$key})) {
                                if (is_array($field)) {
                                    foreach ($field as $array_key => $array_value) {
                                        if (!is_array($array_value)) {
                                            if (in_array($export->export_format, array('csv'))) {
                                                $output .= woo_ce_escape_csv_value($array_value, $export->delimiter, $export->escape_formatting);
                                            }
                                        }
                                    }
                                } else {
                                    if (in_array($export->export_format, array('csv'))) {
                                        $output .= woo_ce_escape_csv_value($product->{$key}, $export->delimiter, $export->escape_formatting);
                                    }
                                }
                            }
                            if (in_array($export->export_format, array('csv'))) {
                                $output .= $separator;
                            }
                        }
                        if (in_array($export->export_format, array('csv'))) {
                            $output = substr($output, 0, -1) . "\n";
                        }
                    }
                }
                unset($products, $product);
            }
            $export->data_memory_end = woo_ce_current_memory_usage();
            break;
            // Categories
        // Categories
        case 'category':
            $fields = woo_ce_get_category_fields('summary');
            if ($export->fields = array_intersect_assoc((array) $export->fields, $fields)) {
                foreach ($export->fields as $key => $field) {
                    $export->columns[] = woo_ce_get_category_field($key);
                }
            }
            $export->total_columns = $size = count($export->columns);
            $export->data_memory_start = woo_ce_current_memory_usage();
            $category_args = array('orderby' => isset($export->args['category_orderby']) ? $export->args['category_orderby'] : 'ID', 'order' => isset($export->args['category_order']) ? $export->args['category_order'] : 'ASC');
            if ($categories = woo_ce_get_product_categories($category_args)) {
                $export->total_rows = count($categories);
                // Generate the export headers
                if (in_array($export->export_format, array('csv'))) {
                    for ($i = 0; $i < $size; $i++) {
                        if ($i == $size - 1) {
                            $output .= woo_ce_escape_csv_value($export->columns[$i], $export->delimiter, $export->escape_formatting) . "\n";
                        } else {
                            $output .= woo_ce_escape_csv_value($export->columns[$i], $export->delimiter, $export->escape_formatting) . $separator;
                        }
                    }
                }
                if (!empty($export->fields)) {
                    foreach ($categories as $category) {
                        foreach ($export->fields as $key => $field) {
                            if (isset($category->{$key})) {
                                if (in_array($export->export_format, array('csv'))) {
                                    $output .= woo_ce_escape_csv_value($category->{$key}, $export->delimiter, $export->escape_formatting);
                                }
                            }
                            if (in_array($export->export_format, array('csv'))) {
                                $output .= $separator;
                            }
                        }
                        if (in_array($export->export_format, array('csv'))) {
                            $output = substr($output, 0, -1) . "\n";
                        }
                    }
                }
                unset($categories, $category);
            }
            $export->data_memory_end = woo_ce_current_memory_usage();
            break;
            // Tags
        // Tags
        case 'tag':
            $fields = woo_ce_get_tag_fields('summary');
            if ($export->fields = array_intersect_assoc((array) $export->fields, $fields)) {
                foreach ($export->fields as $key => $field) {
                    $export->columns[] = woo_ce_get_tag_field($key);
                }
            }
            $export->total_columns = $size = count($export->columns);
            $export->data_memory_start = woo_ce_current_memory_usage();
            $tag_args = array('orderby' => isset($export->args['tag_orderby']) ? $export->args['tag_orderby'] : 'ID', 'order' => isset($export->args['tag_order']) ? $export->args['tag_order'] : 'ASC');
            if ($tags = woo_ce_get_product_tags($tag_args)) {
                $export->total_rows = count($tags);
                // Generate the export headers
                if (in_array($export->export_format, array('csv'))) {
                    for ($i = 0; $i < $size; $i++) {
                        if ($i == $size - 1) {
                            $output .= woo_ce_escape_csv_value($export->columns[$i], $export->delimiter, $export->escape_formatting) . "\n";
                        } else {
                            $output .= woo_ce_escape_csv_value($export->columns[$i], $export->delimiter, $export->escape_formatting) . $separator;
                        }
                    }
                }
                if (!empty($export->fields)) {
                    foreach ($tags as $tag) {
                        foreach ($export->fields as $key => $field) {
                            if (isset($tag->{$key})) {
                                if (in_array($export->export_format, array('csv'))) {
                                    $output .= woo_ce_escape_csv_value($tag->{$key}, $export->delimiter, $export->escape_formatting);
                                }
                            }
                            if (in_array($export->export_format, array('csv'))) {
                                $output .= $separator;
                            }
                        }
                        if (in_array($export->export_format, array('csv'))) {
                            $output = substr($output, 0, -1) . "\n";
                        }
                    }
                }
                unset($tags, $tag);
            }
            $export->data_memory_end = woo_ce_current_memory_usage();
            break;
            // Users
        // Users
        case 'user':
            $fields = woo_ce_get_user_fields('summary');
            if ($export->fields = array_intersect_assoc((array) $export->fields, $fields)) {
                foreach ($export->fields as $key => $field) {
                    $export->columns[] = woo_ce_get_user_field($key);
                }
            }
            $export->total_columns = $size = count($export->columns);
            $export->data_memory_start = woo_ce_current_memory_usage();
            if ($users = woo_ce_get_users($export->args)) {
                // Generate the export headers
                if (in_array($export->export_format, array('csv'))) {
                    $i = 0;
                    foreach ($export->columns as $column) {
                        if ($i == $size - 1) {
                            $output .= woo_ce_escape_csv_value($column, $export->delimiter, $export->escape_formatting) . "\n";
                        } else {
                            $output .= woo_ce_escape_csv_value($column, $export->delimiter, $export->escape_formatting) . $separator;
                        }
                        $i++;
                    }
                }
                if (!empty($export->fields)) {
                    foreach ($users as $user) {
                        $user = woo_ce_get_user_data($user, $export->args);
                        foreach ($export->fields as $key => $field) {
                            if (isset($user->{$key})) {
                                if (in_array($export->export_format, array('csv'))) {
                                    $output .= woo_ce_escape_csv_value($user->{$key}, $export->delimiter, $export->escape_formatting);
                                }
                            }
                            if (in_array($export->export_format, array('csv'))) {
                                $output .= $separator;
                            }
                        }
                        if (in_array($export->export_format, array('csv'))) {
                            $output = substr($output, 0, -1) . "\n";
                        }
                    }
                }
                unset($users, $user);
            }
            $export->data_memory_end = woo_ce_current_memory_usage();
            break;
    }
    // Remove our content filters here to play nice with other Plugins
    remove_filter('sanitize_key', 'woo_ce_sanitize_key');
    // Remove our fatal error notice so not to conflict with the CRON or scheduled export engine
    remove_action('shutdown', 'woo_ce_fatal_error');
    // Export completed successfully
    delete_transient(WOO_CE_PREFIX . '_running');
    // Check that the export file is populated, export columns have been assigned and rows counted
    if ($output && $export->total_rows && $export->total_columns) {
        if (in_array($export->export_format, array('csv'))) {
            $output = woo_ce_file_encoding($output);
            if ($export->export_format == 'csv' && $export->bom && WOO_CE_DEBUG == false) {
                $output = "" . $output;
            }
        }
        if (WOO_CE_DEBUG && !$export->cron) {
            $response = set_transient(WOO_CE_PREFIX . '_debug_log', base64_encode($output), woo_ce_get_option('timeout', MINUTE_IN_SECONDS));
            if ($response !== true) {
                $message = __('The export contents were too large to store in a single WordPress transient, use the Volume offset / Limit volume options to reduce the size of your export and try again.', 'woo_ce') . ' (<a href="' . $troubleshooting_url . '" target="_blank">' . __('Need help?', 'woo_ce') . '</a>)';
                if (function_exists('woo_ce_admin_notice')) {
                    woo_ce_admin_notice($message, 'error');
                } else {
                    error_log(sprintf('[store-exporter] woo_ce_export_dataset() - %s', $message));
                }
            }
        } else {
            return $output;
        }
    }
}
コード例 #3
0
ファイル: exporter.php プロジェクト: GarryVeles/Artibaltika
    function woo_ce_html_page()
    {
        global $wpdb, $export;
        $title = apply_filters('woo_ce_template_header', '');
        woo_ce_template_header($title);
        woo_ce_support_donate();
        $action = woo_get_action();
        switch ($action) {
            case 'export':
                $message = __('Chosen WooCommerce details have been exported from your store.', 'woo_ce');
                woo_ce_admin_notice($message);
                $output = '';
                if (WOO_CE_DEBUG) {
                    if (false === ($export_log = get_transient(WOO_CE_PREFIX . '_debug_log'))) {
                        $export_log = __('No export entries were found, please try again with different export filters.', 'woo_ce');
                    } else {
                        delete_transient(WOO_CE_PREFIX . '_debug_log');
                        $export_log = base64_decode($export_log);
                    }
                    $output = '
<h3>' . __('Export Details') . '</h3>
<textarea id="export_log">' . print_r($export, true) . '</textarea><hr />
<h3>' . sprintf(__('Export Log: %s', 'woo_ce'), $export->filename) . '</h3>
<textarea id="export_log">' . $export_log . '</textarea>
';
                }
                echo $output;
                woo_ce_manage_form();
                break;
            case 'update':
                // Save Custom Product Meta
                if (isset($_POST['custom_products'])) {
                    $custom_products = $_POST['custom_products'];
                    $custom_products = explode("\n", trim($custom_products));
                    $size = count($custom_products);
                    if ($size) {
                        for ($i = 0; $i < $size; $i++) {
                            $custom_products[$i] = trim($custom_products[$i]);
                        }
                        woo_ce_update_option('custom_products', $custom_products);
                    }
                }
                // Save Custom Order Meta
                if (isset($_POST['custom_orders'])) {
                    $custom_orders = $_POST['custom_orders'];
                    $custom_orders = explode("\n", trim($custom_orders));
                    $size = count($custom_orders);
                    if ($size) {
                        for ($i = 0; $i < $size; $i++) {
                            $custom_orders[$i] = trim($custom_orders[$i]);
                        }
                        woo_ce_update_option('custom_orders', $custom_orders);
                    }
                }
                // Save Custom Order Item Meta
                if (isset($_POST['custom_order_items'])) {
                    $custom_order_items = $_POST['custom_order_items'];
                    if (!empty($custom_order_items)) {
                        $custom_order_items = explode("\n", trim($custom_order_items));
                        $size = count($custom_order_items);
                        if ($size) {
                            for ($i = 0; $i < $size; $i++) {
                                $custom_order_items[$i] = trim($custom_order_items[$i]);
                            }
                            woo_ce_update_option('custom_order_items', $custom_order_items);
                        }
                    } else {
                        woo_ce_update_option('custom_order_items', '');
                    }
                }
                $message = __('Custom Fields saved.', 'woo_ce');
                woo_ce_admin_notice($message);
                woo_ce_manage_form();
                break;
            default:
                woo_ce_manage_form();
                break;
        }
        woo_ce_template_footer();
    }
コード例 #4
0
ファイル: exporter.php プロジェクト: hikaram/wee
 function woo_ce_admin_init()
 {
     global $export, $wp_roles;
     // Now is the time to de-activate Store Exporter if Store Exporter Deluxe is activated
     if (defined('WOO_CD_PREFIX')) {
         include_once WOO_CE_PATH . 'includes/install.php';
         woo_ce_deactivate_ce();
         return;
     }
     // Detect if WooCommerce Subscriptions Exporter is activated
     if (function_exists('wc_subs_exporter_admin_init')) {
         $message = sprintf(__('We have detected a WooCommerce Plugin that is activated and known to conflict with Store Exporter, please de-activate WooCommerce Subscriptions Exporter to resolve export issues. <a href="%s" target="_blank">Need help?</a>', 'woocommerce-exporter'), $troubleshooting_url);
         woo_cd_admin_notice($message, 'error', array('plugins.php', 'admin.php'));
     }
     // Check that we are on the Store Exporter screen
     $page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : false;
     if ($page != strtolower(WOO_CE_PREFIX)) {
         return;
     }
     // Detect other platform versions
     woo_ce_detect_non_woo_install();
     // Process any pre-export notice confirmations
     $action = woo_get_action();
     switch ($action) {
         // Prompt on Export screen when insufficient memory (less than 64M is allocated)
         case 'dismiss_memory_prompt':
             woo_ce_update_option('dismiss_memory_prompt', 1);
             $url = esc_url(add_query_arg('action', null));
             wp_redirect($url);
             exit;
             break;
             // Prompt on Export screen when PHP configuration option max_execution_time cannot be increased
         // Prompt on Export screen when PHP configuration option max_execution_time cannot be increased
         case 'dismiss_execution_time_prompt':
             woo_ce_update_option('dismiss_execution_time_prompt', 1);
             $url = esc_url(add_query_arg('action', null));
             wp_redirect($url);
             exit;
             break;
             // Prompt on Export screen when insufficient memory (less than 64M is allocated)
         // Prompt on Export screen when insufficient memory (less than 64M is allocated)
         case 'dismiss_php_legacy':
             woo_ce_update_option('dismiss_php_legacy', 1);
             $url = esc_url(add_query_arg('action', null));
             wp_redirect($url);
             exit;
             break;
         case 'dismiss_subscription_prompt':
             woo_ce_update_option('dismiss_subscription_prompt', 1);
             $url = esc_url(add_query_arg('action', null));
             wp_redirect($url);
             exit;
             break;
             // Save skip overview preference
         // Save skip overview preference
         case 'skip_overview':
             $skip_overview = false;
             if (isset($_POST['skip_overview'])) {
                 $skip_overview = 1;
             }
             woo_ce_update_option('skip_overview', $skip_overview);
             if ($skip_overview == 1) {
                 $url = esc_url(add_query_arg('tab', 'export'));
                 wp_redirect($url);
                 exit;
             }
             break;
             // This is where the magic happens
         // This is where the magic happens
         case 'export':
             // Make sure we play nice with other WooCommerce and WordPress exporters
             if (isset($_POST['woo_ce_export']) && !check_admin_referer('manual_export', 'woo_ce_export')) {
                 return false;
             }
             // Set up the basic export options
             $export = new stdClass();
             $export->cron = 0;
             $export->scheduled_export = 0;
             $export->start_time = time();
             $export->idle_memory_start = woo_ce_current_memory_usage();
             $export->delete_file = woo_ce_get_option('delete_file', 0);
             $export->encoding = woo_ce_get_option('encoding', get_option('blog_charset', 'UTF-8'));
             // Reset the Encoding if corrupted
             if ($export->encoding == '' || $export->encoding == false || $export->encoding == 'System default') {
                 error_log('[store-exporter] Encoding export option was corrupted, defaulted to UTF-8');
                 $export->encoding = 'UTF-8';
                 woo_ce_update_option('encoding', 'UTF-8');
             }
             $export->delimiter = woo_ce_get_option('delimiter', ',');
             // Reset the Delimiter if corrupted
             if ($export->delimiter == '' || $export->delimiter == false) {
                 error_log('[store-exporter] Delimiter export option was corrupted, defaulted to ,');
                 $export->delimiter = ',';
                 woo_ce_update_option('delimiter', ',');
             }
             $export->category_separator = woo_ce_get_option('category_separator', '|');
             // Reset the Category Separator if corrupted
             if ($export->category_separator == '' || $export->category_separator == false) {
                 error_log('[store-exporter] Category Separator export option was corrupted, defaulted to |');
                 $export->category_separator = '|';
                 woo_ce_update_option('category_separator', '|');
             }
             $export->bom = woo_ce_get_option('bom', 1);
             $export->escape_formatting = woo_ce_get_option('escape_formatting', 'all');
             // Reset the Escape Formatting if corrupted
             if ($export->escape_formatting == '' || $export->escape_formatting == false) {
                 error_log('[store-exporter] Escape Formatting export option was corrupted, defaulted to all');
                 $export->escape_formatting = 'all';
                 woo_ce_update_option('escape_formatting', 'all');
             }
             $export->date_format = woo_ce_get_option('date_format', 'd/m/Y');
             // Reset the Date Format if corrupted
             if ($export->date_format == '1' || $export->date_format == '' || $export->date_format == false) {
                 error_log('[store-exporter] Date Format export option was corrupted, defaulted to d/m/Y');
                 $export->date_format = 'd/m/Y';
                 woo_ce_update_option('date_format', 'd/m/Y');
             }
             // Save export option changes made on the Export screen
             $export->limit_volume = isset($_POST['limit_volume']) ? sanitize_text_field($_POST['limit_volume']) : '';
             woo_ce_update_option('limit_volume', $export->limit_volume);
             if ($export->limit_volume == '') {
                 $export->limit_volume = -1;
             }
             $export->offset = isset($_POST['offset']) ? sanitize_text_field($_POST['offset']) : '';
             woo_ce_update_option('offset', $export->offset);
             if ($export->offset == '') {
                 $export->offset = 0;
             }
             // Set default values for all export options to be later passed onto the export process
             $export->fields = array();
             $export->fields_order = false;
             $export->export_format = 'csv';
             // Product sorting
             $export->product_categories = false;
             $export->product_tags = false;
             $export->product_status = false;
             $export->product_type = false;
             $export->product_orderby = false;
             $export->product_order = false;
             $export->gallery_formatting = false;
             $export->upsell_formatting = false;
             $export->crosssell_formatting = false;
             // Category sorting
             $export->category_orderby = false;
             $export->category_order = false;
             // Tag sorting
             $export->tag_orderby = false;
             $export->tag_order = false;
             // User sorting
             $export->user_orderby = false;
             $export->user_order = false;
             $export->type = isset($_POST['dataset']) ? sanitize_text_field($_POST['dataset']) : false;
             if ($export->type) {
                 $export->fields = isset($_POST[$export->type . '_fields']) ? array_map('sanitize_text_field', $_POST[$export->type . '_fields']) : false;
                 $export->fields_order = isset($_POST[$export->type . '_fields_order']) ? array_map('absint', $_POST[$export->type . '_fields_order']) : false;
                 woo_ce_update_option('last_export', $export->type);
             }
             switch ($export->type) {
                 case 'product':
                     // Set up dataset specific options
                     $export->product_categories = isset($_POST['product_filter_category']) ? woo_ce_format_product_filters(array_map('absint', $_POST['product_filter_category'])) : false;
                     $export->product_tags = isset($_POST['product_filter_tag']) ? woo_ce_format_product_filters(array_map('absint', $_POST['product_filter_tag'])) : false;
                     $export->product_status = isset($_POST['product_filter_status']) ? woo_ce_format_product_filters(array_map('sanitize_text_field', $_POST['product_filter_status'])) : false;
                     $export->product_type = isset($_POST['product_filter_type']) ? woo_ce_format_product_filters(array_map('sanitize_text_field', $_POST['product_filter_type'])) : false;
                     $export->product_orderby = isset($_POST['product_orderby']) ? sanitize_text_field($_POST['product_orderby']) : false;
                     $export->product_order = isset($_POST['product_order']) ? sanitize_text_field($_POST['product_order']) : false;
                     $export->gallery_formatting = isset($_POST['product_gallery_formatting']) ? absint($_POST['product_gallery_formatting']) : false;
                     $export->upsell_formatting = isset($_POST['product_upsell_formatting']) ? absint($_POST['product_upsell_formatting']) : false;
                     $export->crosssell_formatting = isset($_POST['product_crosssell_formatting']) ? absint($_POST['product_crosssell_formatting']) : false;
                     // Save dataset export specific options
                     if ($export->product_orderby != woo_ce_get_option('product_orderby')) {
                         woo_ce_update_option('product_orderby', $export->product_orderby);
                     }
                     if ($export->product_order != woo_ce_get_option('product_order')) {
                         woo_ce_update_option('product_order', $export->product_order);
                     }
                     if ($export->upsell_formatting != woo_ce_get_option('upsell_formatting')) {
                         woo_ce_update_option('upsell_formatting', $export->upsell_formatting);
                     }
                     if ($export->crosssell_formatting != woo_ce_get_option('crosssell_formatting')) {
                         woo_ce_update_option('crosssell_formatting', $export->crosssell_formatting);
                     }
                     break;
                 case 'category':
                     // Set up dataset specific options
                     $export->category_orderby = isset($_POST['category_orderby']) ? sanitize_text_field($_POST['category_orderby']) : false;
                     $export->category_order = isset($_POST['category_order']) ? sanitize_text_field($_POST['category_order']) : false;
                     // Save dataset export specific options
                     if ($export->category_orderby != woo_ce_get_option('category_orderby')) {
                         woo_ce_update_option('category_orderby', $export->category_orderby);
                     }
                     if ($export->category_order != woo_ce_get_option('category_order')) {
                         woo_ce_update_option('category_order', $export->category_order);
                     }
                     break;
                 case 'tag':
                     // Set up dataset specific options
                     $export->tag_orderby = isset($_POST['tag_orderby']) ? sanitize_text_field($_POST['tag_orderby']) : false;
                     $export->tag_order = isset($_POST['tag_order']) ? sanitize_text_field($_POST['tag_order']) : false;
                     // Save dataset export specific options
                     if ($export->tag_orderby != woo_ce_get_option('tag_orderby')) {
                         woo_ce_update_option('tag_orderby', $export->tag_orderby);
                     }
                     if ($export->tag_order != woo_ce_get_option('tag_order')) {
                         woo_ce_update_option('tag_order', $export->tag_order);
                     }
                     break;
                 case 'user':
                     // Set up dataset specific options
                     $export->user_orderby = isset($_POST['user_orderby']) ? sanitize_text_field($_POST['user_orderby']) : false;
                     $export->user_order = isset($_POST['user_order']) ? sanitize_text_field($_POST['user_order']) : false;
                     // Save dataset export specific options
                     if ($export->user_orderby != woo_ce_get_option('user_orderby')) {
                         woo_ce_update_option('user_orderby', $export->user_orderby);
                     }
                     if ($export->user_order != woo_ce_get_option('user_order')) {
                         woo_ce_update_option('user_order', $export->user_order);
                     }
                     break;
             }
             if ($export->type) {
                 $timeout = 600;
                 if (isset($_POST['timeout'])) {
                     $timeout = absint((int) $_POST['timeout']);
                     if ($timeout != woo_ce_get_option('timeout')) {
                         woo_ce_update_option('timeout', $timeout);
                     }
                 }
                 if (!ini_get('safe_mode')) {
                     @set_time_limit((int) $timeout);
                 }
                 @ini_set('memory_limit', WP_MAX_MEMORY_LIMIT);
                 @ini_set('max_execution_time', (int) $timeout);
                 $export->args = array('limit_volume' => $export->limit_volume, 'offset' => $export->offset, 'encoding' => $export->encoding, 'date_format' => $export->date_format, 'product_categories' => $export->product_categories, 'product_tags' => $export->product_tags, 'product_status' => $export->product_status, 'product_type' => $export->product_type, 'product_orderby' => $export->product_orderby, 'product_order' => $export->product_order, 'category_orderby' => $export->category_orderby, 'category_order' => $export->category_order, 'tag_orderby' => $export->tag_orderby, 'tag_order' => $export->tag_order, 'user_orderby' => $export->user_orderby, 'user_order' => $export->user_order);
                 if (empty($export->fields)) {
                     $message = __('No export fields were selected, please try again with at least a single export field.', 'woocommerce-exporter');
                     woo_ce_admin_notice($message, 'error');
                     return false;
                 }
                 woo_ce_save_fields($export->type, $export->fields, $export->fields_order);
                 if ($export->export_format == 'csv') {
                     $export->filename = woo_ce_generate_csv_filename($export->type);
                 }
                 // Print file contents to debug export screen
                 if (WOO_CE_DEBUG) {
                     if (in_array($export->export_format, array('csv'))) {
                         woo_ce_export_dataset($export->type);
                     }
                     $export->idle_memory_end = woo_ce_current_memory_usage();
                     $export->end_time = time();
                     // Print file contents to browser
                 } else {
                     if (in_array($export->export_format, array('csv'))) {
                         // Generate CSV contents
                         $bits = woo_ce_export_dataset($export->type);
                         unset($export->fields);
                         if (!$bits) {
                             $message = __('No export entries were found, please try again with different export filters.', 'woocommerce-exporter');
                             woo_ce_admin_notice($message, 'error');
                             return false;
                         }
                         if ($export->delete_file) {
                             // Print to browser
                             if ($export->export_format == 'csv') {
                                 woo_ce_generate_csv_header($export->type);
                             }
                             echo $bits;
                             exit;
                         } else {
                             // Save to file and insert to WordPress Media
                             if ($export->filename && $bits) {
                                 if ($export->export_format == 'csv') {
                                     $post_ID = woo_ce_save_file_attachment($export->filename, 'text/csv');
                                 }
                                 $upload = wp_upload_bits($export->filename, null, $bits);
                                 if ($post_ID == false || $upload['error']) {
                                     wp_delete_attachment($post_ID, true);
                                     if (isset($upload['error'])) {
                                         wp_redirect(esc_url(add_query_arg(array('failed' => true, 'message' => urlencode($upload['error'])))));
                                     } else {
                                         wp_redirect(esc_url(add_query_arg(array('failed' => true))));
                                     }
                                     return false;
                                 }
                                 $attach_data = wp_generate_attachment_metadata($post_ID, $upload['file']);
                                 wp_update_attachment_metadata($post_ID, $attach_data);
                                 update_attached_file($post_ID, $upload['file']);
                                 if ($post_ID) {
                                     woo_ce_save_file_guid($post_ID, $export->type, $upload['url']);
                                     woo_ce_save_file_details($post_ID);
                                 }
                                 $export_type = $export->type;
                                 unset($export);
                                 // The end memory usage and time is collected at the very last opportunity prior to the CSV header being rendered to the screen
                                 woo_ce_update_file_detail($post_ID, '_woo_idle_memory_end', woo_ce_current_memory_usage());
                                 woo_ce_update_file_detail($post_ID, '_woo_end_time', time());
                                 // Generate CSV header
                                 woo_ce_generate_csv_header($export_type);
                                 unset($export_type);
                                 // Print file contents to screen
                                 if ($upload['file']) {
                                     readfile($upload['file']);
                                 } else {
                                     wp_redirect(esc_url(add_query_arg('failed', true)));
                                 }
                                 unset($upload);
                             } else {
                                 wp_redirect(esc_url(add_query_arg('failed', true)));
                             }
                         }
                     }
                     exit;
                 }
             }
             break;
             // Save changes on Settings screen
         // Save changes on Settings screen
         case 'save-settings':
             // Sanitize each setting field as needed
             woo_ce_update_option('export_filename', strip_tags((string) $_POST['export_filename']));
             woo_ce_update_option('delete_file', sanitize_text_field((int) $_POST['delete_file']));
             woo_ce_update_option('encoding', sanitize_text_field((string) $_POST['encoding']));
             woo_ce_update_option('delimiter', sanitize_text_field((string) $_POST['delimiter']));
             woo_ce_update_option('category_separator', sanitize_text_field((string) $_POST['category_separator']));
             woo_ce_update_option('bom', absint((int) $_POST['bom']));
             woo_ce_update_option('escape_formatting', sanitize_text_field((string) $_POST['escape_formatting']));
             if ($_POST['date_format'] == 'custom' && !empty($_POST['date_format_custom'])) {
                 woo_ce_update_option('date_format', sanitize_text_field((string) $_POST['date_format_custom']));
             } else {
                 woo_ce_update_option('date_format', sanitize_text_field((string) $_POST['date_format']));
             }
             $message = __('Changes have been saved.', 'woocommerce-exporter');
             woo_ce_admin_notice($message);
             break;
             // Save changes on Field Editor screen
         // Save changes on Field Editor screen
         case 'save-fields':
             $fields = isset($_POST['fields']) ? array_filter($_POST['fields']) : array();
             $types = array_keys(woo_ce_return_export_types());
             $export_type = isset($_POST['type']) ? sanitize_text_field($_POST['type']) : '';
             if (in_array($export_type, $types)) {
                 woo_ce_update_option($export_type . '_labels', $fields);
                 $message = __('Changes have been saved.', 'woocommerce-exporter');
                 woo_ce_admin_notice($message);
             } else {
                 $message = __('Changes could not be saved.', 'woocommerce-exporter');
                 woo_ce_admin_notice($message, 'error');
             }
             break;
     }
 }
コード例 #5
0
ファイル: functions.php プロジェクト: GarryVeles/Artibaltika
 function woo_ce_fail_notices()
 {
     woo_ce_memory_prompt();
     $troubleshooting_url = 'http://www.visser.com.au/documentation/store-exporter-deluxe/usage/';
     if (isset($_GET['failed'])) {
         $message = '';
         if (isset($_GET['message'])) {
             $message = urldecode($_GET['message']);
         }
         if ($message) {
             $message = __('A WordPress or server error caused the exporter to fail, the exporter was provided with a reason: ', 'woo_ce') . '<em>' . $message . '</em>' . ' (<a href="' . $troubleshooting_url . '" target="_blank">' . __('Need help?', 'woo_ce') . '</a>)';
         } else {
             $message = __('A WordPress or server error caused the exporter to fail, no reason was provided, please get in touch so we can reproduce and resolve this.', 'woo_ce') . ' (<a href="' . $troubleshooting_url . '" target="_blank">' . __('Need help?', 'woo_ce') . '</a>)';
         }
         woo_ce_admin_notice($message, 'error');
     }
     if (isset($_GET['empty'])) {
         $message = __('No export entries were found, please try again with different export filters.', 'woo_ce');
         woo_ce_admin_notice($message, 'error');
     }
     if (get_transient(WOO_CE_PREFIX . '_running')) {
         $message = __('A WordPress or server error caused the exporter to fail with a blank screen, this is either a memory or timeout issue, please get in touch so we can reproduce and resolve this.', 'woo_ce') . ' (<a href="' . $troubleshooting_url . '" target="_blank">' . __('Need help?', 'woo_ce') . '</a>)';
         woo_ce_admin_notice($message, 'error');
     }
 }