function woo_ce_html_page() { global $wpdb, $woo_ce, $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'); $output = '<div class="updated settings-error"><p><strong>' . $message . '</strong></p></div>'; if (isset($woo_ce['debug']) && $woo_ce['debug']) { if (!isset($woo_ce['debug_log'])) { $woo_ce['debug_log'] = __('No export entries were found, please try again with different export filters.', 'woo_ce'); } $output .= '<h3>' . sprintf(__('Export Log: %s', 'woo_ce'), $export->filename) . '</h3>'; $output .= '<textarea id="export_log">' . $woo_ce['debug_log'] . '</textarea>'; } echo $output; woo_ce_manage_form(); break; case 'update': 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); } } 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'); $output = '<div class="updated settings-error"><p><strong>' . $message . '</strong></p></div>'; echo $output; woo_ce_manage_form(); break; default: woo_ce_manage_form(); break; } woo_ce_template_footer(); }
function woo_pi_import_init() { global $import, $wpdb, $woocommerce; $troubleshooting_url = 'http://www.visser.com.au/documentation/product-importer-deluxe/usage/'; // Notice that we cannot increase memory limits if (!ini_get('memory_limit') && !woo_pi_get_option('memory_notice', false)) { $message = sprintf(__('Your WordPress site does not allow changes to allocated memory limits, because of this memory-related errors are likely. %s', 'woo_pi'), '<a href="' . $troubleshooting_url . '" target="_blank">' . __('Need help?', 'woo_pi') . '</a>'); $dismiss_url = add_query_arg(array('page' => 'woo_pi', 'action' => 'dismiss-memory'), 'admin.php'); $dismiss_link = '<span style="float:right;"><a href="' . $dismiss_url . '">' . __('Dismiss', 'woo_pi') . '</a></span>'; woo_pi_admin_notice($message . $dismiss_link, 'error'); } // Notice to increase WordPress memory allocation if (!woo_pi_get_option('minimum_memory_notice', 0)) { $memory_limit = (int) ini_get('memory_limit'); $minimum_memory_limit = 64; if ($memory_limit < $minimum_memory_limit) { $memory_url = add_query_arg(array('page' => 'woo_pi', 'action' => 'dismiss-minimum-memory'), 'admin.php'); $message = sprintf(__('We recommend setting memory to at least %dMB prior to importing, your site has only %dMB allocated to it. See <a href="%s" target="_blank">Increasing memory allocated to PHP</a> for more information.<span style="float:right;"><a href="%s">Dismiss</a></span>', 'woo_pi'), $minimum_memory_limit, $memory_limit, $troubleshooting_url, $memory_url); woo_pi_admin_notice($message, 'error'); } } // Notice that PHP safe mode is active if (ini_get('safe_mode') && !woo_pi_get_option('safe_mode_notice', false)) { $message = sprintf(__('Your WordPress site appears to be running PHP in \'Safe Mode\', because of this the script timeout cannot be adjusted. This will limit the importing of large catalogues. %s', 'woo_pi'), '<a href="' . $troubleshooting_url . '" target="_blank">' . __('Need help?', 'woo_pi') . '</a>'); $dismiss_url = add_query_arg(array('page' => 'woo_pi', 'action' => 'dismiss-safe_mode'), 'admin.php'); $dismiss_link = '<span style="float:right;"><a href="' . $dismiss_url . '">' . __('Dismiss', 'woo_pi') . '</a></span>'; woo_pi_admin_notice($message . $dismiss_link, 'error'); } // Notice that mb_convert_encoding() does not exist if (!function_exists('mb_convert_encoding') && !woo_pi_get_option('mb_convert_notice', false)) { $message = sprintf(__('The function mb_convert_encoding() requires the mb_strings extension to be enabled, multi-lingual import support has been disabled. %s', 'woo_pi'), '<a href="' . $troubleshooting_url . '" target="_blank">' . __('Need help?', 'woo_pi') . '</a>'); $dismiss_url = add_query_arg(array('page' => 'woo_pi', 'action' => 'dismiss-mb_convert'), 'admin.php'); $dismiss_link = '<span style="float:right;"><a href="' . $dismiss_url . '">' . __('Dismiss', 'woo_pi') . '</a></span>'; woo_pi_admin_notice($message . $dismiss_link, 'error'); } // Notice that mb_list_encodings() does not exist if (!function_exists('mb_list_encodings') && !woo_pi_get_option('mb_list_notice', false)) { $message = sprintf(__('The function mb_list_encodings() requires the mb_strings extension to be enabled, if you are importing non-English and/or special characters the WordPress Transients we use during import will be corrupted and cause the import to fail.', 'woo_pi'), '<a href="' . $troubleshooting_url . '" target="_blank">' . __('Need help?', 'woo_pi') . '</a>'); $dismiss_url = add_query_arg(array('page' => 'woo_pi', 'action' => 'dismiss-mb_list'), 'admin.php'); $dismiss_link = '<span style="float:right;"><a href="' . $dismiss_url . '">' . __('Dismiss', 'woo_pi') . '</a></span>'; woo_pi_admin_notice($message . $dismiss_link, 'error'); } // Notice that PHP version does not include required dismiss-str_getcsv() if (phpversion() < '5.3.0' && !woo_pi_get_option('str_getcsv_notice', false)) { $message = sprintf(__('Your WordPress site is running an older version of PHP which does not support the function str_getcsv(), a substitute will be used. %s', 'woo_pi'), '<a href="' . $troubleshooting_url . '" target="_blank">' . __('Need help?', 'woo_pi') . '</a>'); $dismiss_url = add_query_arg(array('page' => 'woo_pi', 'action' => 'dismiss-str_getcsv'), 'admin.php'); $dismiss_link = '<span style="float:right;"><a href="' . $dismiss_url . '">' . __('Dismiss', 'woo_pi') . '</a></span>'; woo_pi_admin_notice($message . $dismiss_link, 'error'); } // Notice to install/open Store Exporter if (!woo_pi_get_option('exporter_notice', false)) { $woo_ce_message = ' '; if (function_exists('woo_ce_export_dataset')) { $woo_ce_url = add_query_arg('page', 'woo_ce', 'admin.php'); $woo_ce_message .= sprintf(__('Jump over to <a href="%s">Store Exporter</a>.', 'woo_pi'), $woo_ce_url); } else { $woo_ce_url = 'http://www.visser.com.au/woocommerce/plugins/exporter/'; $woo_ce_message .= sprintf(__('Install our free <a href="%s" target="_blank">Store Exporter</a> extension.', 'woo_pi'), $woo_ce_url); } $message = __('Would you like to export an initial CSV file of your existing WooCommerce Products which you can adjust and re-import with Product Importer?', 'woo_pi') . $woo_ce_message; $dismiss_url = add_query_arg(array('page' => 'woo_pi', 'action' => 'dismiss-exporter'), 'admin.php'); $dismiss_link = sprintf('<span style="float:right;"><a href="%s">%s</a></span>', $dismiss_url, __('Dismiss', 'woo_pi')); woo_pi_admin_notice($message . $dismiss_link); } $wpdb->hide_errors(); @ini_set('memory_limit', WP_MAX_MEMORY_LIMIT); // Prevent header sent errors for the import @ob_start(); $action = woo_get_action(); switch ($action) { // Save changes on Settings screen case 'save-settings': woo_pi_update_option('delete_file', isset($_POST['delete_file']) ? absint($_POST['delete_file']) : 0); woo_pi_update_option('encoding', isset($_POST['encoding']) ? sanitize_text_field($_POST['encoding']) : 'UTF-8'); woo_pi_update_option('timeout', isset($_POST['timeout']) ? absint($_POST['timeout']) : 0); woo_pi_update_option('delimiter', isset($_POST['delimiter']) ? sanitize_text_field($_POST['delimiter']) : ','); woo_pi_update_option('category_separator', isset($_POST['category_separator']) ? sanitize_text_field($_POST['category_separator']) : '|'); woo_pi_update_option('parent_child_delimiter', isset($_POST['parent_child_delimiter']) ? sanitize_text_field($_POST['parent_child_delimiter']) : '>'); $message = __('Settings saved.', 'woo_pi'); woo_pi_admin_notice($message); break; default: $import = new stdClass(); $import->upload_method = woo_pi_get_option('upload_method', 'upload'); $import->delimiter = woo_pi_get_option('delimiter', ','); if ($import->delimiter == "\t") { $import->delimiter = 'TAB'; } if ($import->delimiter == '' || $import->delimiter == false) { $import->delimiter = ','; } $import->category_separator = woo_pi_get_option('category_separator', '|'); $import->parent_child_delimiter = woo_pi_get_option('parent_child_delimiter', '>'); $import->delete_file = woo_pi_get_option('delete_file', 0); $import->encoding = woo_pi_get_option('encoding', 'UTF-8'); break; case 'upload': $import = new stdClass(); $import->cancel_import = false; $import->skip_first = false; $import->upload_method = isset($_POST['upload_method']) ? $_POST['upload_method'] : 'upload'; $import->import_method = sanitize_text_field(woo_pi_get_option('import_method', 'new')); $import->advanced_log = absint(woo_pi_get_option('advanced_log', 1)); $import->delimiter = isset($_POST['delimiter']) ? substr($_POST['delimiter'], 0, 3) : ','; if ($import->delimiter == 'TAB') { $import->delimiter = "\t"; } $import->category_separator = isset($_POST['category_separator']) ? sanitize_text_field($_POST['category_separator']) : '|'; $import->parent_child_delimiter = isset($_POST['parent_child_delimiter']) ? sanitize_text_field($_POST['parent_child_delimiter']) : '>'; $import->delete_file = absint(woo_pi_get_option('delete_file', 0)); $import->encoding = isset($_POST['encoding']) ? sanitize_text_field($_POST['encoding']) : 'UTF-8'; $import->timeout = absint(woo_pi_get_option('timeout', 600)); $import->upload_mb = wp_max_upload_size(); woo_pi_update_option('delimiter', $import->delimiter); woo_pi_update_option('category_separator', $import->category_separator); woo_pi_update_option('parent_child_delimiter', $import->parent_child_delimiter); woo_pi_update_option('encoding', $import->encoding); // Capture the CSV file uploaded if ($_FILES['csv_file']['error'] == 0) { $file = $_FILES['csv_file']; } else { $file = array('size' => 0, 'error' => isset($_FILES['csv_file']['error']) ? $_FILES['csv_file']['error'] : 0); } // Validation of the import method chosen and uploaded file if ($file['error'] != 4 && $file['size'] == 0) { if ($file['error'] == 0 && $file['size'] == 0) { // User has uploaded an empty file $import->cancel_import = true; $message = sprintf(__('Your CSV file is empty, re-upload a populated CSV file from the opening import screen. <a href="%s" target="_blank">Need help?</a>', 'woo_pi'), $troubleshooting_url); woo_pi_admin_notice($message, 'error'); } else { // User has uploaded the CSV file but it has expired, usually due to PHP timeout or completed import $import->cancel_import = true; $message = sprintf(__('Your CSV file upload has expired, re-upload it from the opening import screen. <a href="%s" target="_blank">Need help?</a>', 'woo_pi'), $troubleshooting_url); woo_pi_admin_notice($message, 'error'); } } else { if ($file['error'] == 4 && $file['size'] == 0) { // No file uploaded $import->cancel_import = true; $message = sprintf(__('No CSV file was uploaded, check that a file is uploaded from the opening import screen. <a href="%s" target="_blank">Need help?</a>', 'woo_pi'), $troubleshooting_url); woo_pi_admin_notice($message, 'error'); } else { if (strpos(strtolower($file['name']), 'csv') == false) { // Not a CSV file or lacking a *.csv file extension $import->cancel_import = true; $message = sprintf(__('Product Importer Deluxe requires a CSV-formatted upload, if you are sure the file is a CSV please change the file extension and re-upload. <a href="%s" target="_blank">Need help?</a>', 'woo_pi'), $troubleshooting_url); woo_pi_admin_notice($message, 'error'); } else { if ($file['size'] == 0 && empty($file['name'])) { // No file uploaded $import->cancel_import = true; $message = sprintf(__('No CSV file was uploaded. Please select a CSV to upload from the \'Choose File\' dialog or other available upload options, alternatively select a CSV from Past Imports. <a href="%s" target="_blank">Need help?</a>', 'woo_pi'), $troubleshooting_url); woo_pi_admin_notice($message, 'error'); } } } } // Validation of the WordPress site and memory allocation against the uploaded file if ($file['size'] > $import->upload_mb) { $import->cancel_import = true; $message = sprintf(__('The file you\'re importing exceeded the maximum allowed filesize (see Maximum size), increase the file upload limit or import a smaller CSV file. <a href="%s" target="_blank">Need help?</a>', 'woo_pi'), $troubleshooting_url); woo_pi_admin_notice($message, 'error'); } // Check if the delimiter is set if ($import->delimiter == '' || $import->category_separator == '') { $import->cancel_import = true; $message = sprintf(__('You cannot leave the Field delimiter or Product Category separator options under Import Options empty. <a href="%s" target="_blank">Need help?</a>', 'woo_pi'), $troubleshooting_url); woo_pi_admin_notice($message, 'error'); } if ($import->cancel_import) { continue; } if (in_array($import->upload_method, array('upload'))) { $upload = wp_upload_bits($file['name'], null, file_get_contents($file['tmp_name'])); // Fail import if WordPress cannot save the uploaded CSV file if ($upload['error']) { $import->cancel_import = true; $message = sprintf(__('There was an error while uploading your CSV file, <em>%s</em>. %s', 'woo_pi'), $upload['error'], '<a href="' . $troubleshooting_url . '" target="_blank">' . __('Need help?', 'woo_pi') . '</a>'); woo_pi_admin_notice($message, 'error'); } if (!$import->cancel_import) { $import->file = $file; woo_pi_update_option('csv', $upload['file']); } } else { $import->file = $file; } break; case 'save': global $product; $import = new stdClass(); $import->cancel_import = false; $import->log = ''; $import->delimiter = woo_pi_get_option('delimiter', ','); $import->category_separator = woo_pi_get_option('category_separator', '|'); $import->parent_child_delimiter = woo_pi_get_option('parent_child_delimiter', '>'); $import->delete_file = woo_pi_get_option('delete_file', 0); $import->encoding = woo_pi_get_option('encoding', 'UTF-8'); $import->skip_first = isset($_POST['skip_first']) ? $_POST['skip_first'] : false; $import->import_method = isset($_POST['import_method']) ? $_POST['import_method'] : 'new'; $import->advanced_log = isset($_POST['advanced_log']) ? 1 : 0; woo_pi_update_option('import_method', $import->import_method); woo_pi_update_option('advanced_log', absint($import->advanced_log)); if (isset($_POST['timeout'])) { woo_pi_update_option('timeout', sanitize_text_field($_POST['timeout'])); } // Check if our import has expired if (!woo_pi_get_option('csv')) { $import->cancel_import = true; $message = sprintf(__('Your CSV file upload has expired, re-upload it from the opening import screen. %s', 'woo_pi'), '<a href="' . $troubleshooting_url . '" target="_blank">' . __('Need help?', 'woo_pi') . '</a>'); woo_pi_admin_notice($message, 'error'); } if ($import->cancel_import) { return; } // Check if this is a resumed import if (isset($_POST['refresh_step'])) { $step = sanitize_text_field($_POST['refresh_step']); $transient = get_transient(WOO_PI_PREFIX . '_import'); $transient->log = '<br /><br />' . __('Resuming import...', 'woo_pi'); if (sanitize_text_field($_POST['import_method']) == 'new') { $transient->log .= "<br /><br />" . __('Generating Products...', 'woo_pi'); } $settings = array('skip_first' => $transient->skip_first, 'import_method' => isset($_POST['import_method']) ? sanitize_text_field($_POST['import_method']) : 'new', 'restart_from' => isset($_POST['restart_from']) ? absint((int) $_POST['restart_from']) : 0, 'progress' => isset($_POST['progress']) ? absint($_POST['progress']) : 0, 'total_progress' => isset($_POST['total_progress']) ? absint($_POST['total_progress']) : 0, 'log' => __('Resuming import...', 'woo_pi')); $response = set_transient(WOO_PI_PREFIX . '_import', $transient); // Check if the Transient was saved if (is_wp_error($response)) { error_log('[product-importer] Could not save the resume import Transient', 'woo_pi'); } unset($transient); } else { $step = 'prepare_data'; $settings = $_POST; } wp_enqueue_script('jquery'); wp_enqueue_script('progressBar', plugins_url('/js/progress.js', WOO_PI_FILE), array('jquery')); wp_enqueue_script('ajaxUpload', plugins_url('/js/ajaxupload.js', WOO_PI_FILE), array('jquery')); wp_register_script('ajaxImporter', plugins_url('/js/engine.js', WOO_PI_FILE), array('jquery')); wp_enqueue_script('ajaxImporter'); wp_localize_script('ajaxImporter', 'ajaxImport', array('settings' => $settings, 'ajaxurl' => admin_url('admin-ajax.php'), 'step' => $step)); unset($step, $settings); break; } }
function woo_ce_cron() { $action = woo_get_action(); // This is where the CRON export magic happens if( $action == 'woo_ce-cron' ) { // Check that Store Exporter is installed and activated or jump out if( !function_exists( 'woo_ce_get_option' ) ) return; // Return silent response and record to error log if CRON support is disabled or bad secret key provided if( woo_ce_get_option( 'enable_cron', 0 ) == 0 ) { error_log( '[store-exporter-deluxe] Error: Failed CRON access, CRON is disabled' ); return; } $key = ( isset( $_GET['key'] ) ? sanitize_text_field( $_GET['key'] ) : '' ); if( $key <> woo_ce_get_option( 'secret_key', '' ) ) { $ip_address = woo_ce_get_visitor_ip_address(); error_log( sprintf( '[store-exporter-deluxe] Error: Failed CRON attempt from %s, incorrect secret key' ), $ip_address ); return; } $gui = ( isset( $_GET['gui'] ) ? absint( $_GET['gui'] ) : 0 ); $response = ( isset( $_GET['response'] ) ? sanitize_text_field( $_GET['response'] ) : '' ); // Output to screen in friendly design with on-screen error responses if( $gui == 1 ) { woo_ce_cron_export( 'gui' ); // Return export download to browser in different expected formats, uses error_log for error responses } else if( $gui == 0 && in_array( $response, array( 'download', 'raw', 'url', 'file', 'email', 'post', 'ftp' ) ) ) { switch( $response ) { // Return export download to browser case 'download': echo woo_ce_cron_export( 'download' ); break; // Return raw download to browser case 'raw': echo woo_ce_cron_export( 'raw' ); break; // Return the URI to the saved export case 'url': echo woo_ce_cron_export( 'url' ); break; // Return the system path to the saved export case 'file': echo woo_ce_cron_export( 'file' ); break; case 'email': echo woo_ce_cron_export( 'email' ); break; case 'post': echo woo_ce_cron_export( 'post' ); break; case 'ftp': echo woo_ce_cron_export( 'ftp' ); break; } } else { // Return simple binary response echo absint( woo_ce_cron_export() ); } exit(); } }
function woo_st_html_page() { global $wpdb; woo_st_template_header(); woo_st_support_donate(); $action = woo_get_action(); switch ($action) { case 'nuke': $message = __('The selected WooCommerce and/or WordPress details from the previous screen have been permanently erased from your store. <strong>Ta da!</strong>', 'woo_st'); woo_st_admin_notice_html($message); woo_st_default_html_page(); break; default: woo_st_default_html_page(); break; } woo_st_template_footer(); }
function woo_ce_html_page() { global $wpdb, $export; $title = apply_filters('woo_ce_template_header', __('Store Exporter', 'woocommerce-exporter')); woo_ce_template_header($title); woo_ce_support_donate(); $action = woo_get_action(); switch ($action) { case 'export': 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.', 'woocommerce-exporter'); } else { $export_log = base64_decode($export_log); } delete_transient(WOO_CE_PREFIX . '_debug_log'); $output = ' <h3>' . sprintf(__('Export Details: %s', 'woocommerce-exporter'), esc_attr($export->filename)) . '</h3> <p>' . __('This prints the $export global that contains the different export options and filters to help reproduce this on another instance of WordPress. Very useful for debugging blank or unexpected exports.', 'woocommerce-exporter') . '</p> <textarea id="export_log">' . esc_textarea(print_r($export, true)) . '</textarea> <hr />'; if (in_array($export->export_format, array('csv'))) { $output .= ' <script> $j(function() { $j(\'#export_sheet\').CSVToTable(\'\', { startLine: 0 }); }); </script> <h3>' . __('Export', 'woocommerce-exporter') . '</h3> <p>' . __('We use the <a href="http://code.google.com/p/jquerycsvtotable/" target="_blank"><em>CSV to Table plugin</em></a> to see first hand formatting errors or unexpected values within the export file.', 'woocommerce-exporter') . '</p> <div id="export_sheet">' . esc_textarea($export_log) . '</div> <p class="description">' . __('This jQuery plugin can fail with <code>\'Item count (#) does not match header count\'</code> notices which simply mean the number of headers detected does not match the number of cell contents.', 'woocommerce-exporter') . '</p> <hr />'; } $output .= ' <h3>' . __('Export Log', 'woocommerce-exporter') . '</h3> <p>' . __('This prints the raw export contents and is helpful when the jQuery plugin above fails due to major formatting errors.', 'woocommerce-exporter') . '</p> <textarea id="export_log" wrap="off">' . esc_textarea($export_log) . '</textarea> <hr /> '; 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] = sanitize_text_field(trim($custom_products[$i])); } woo_ce_update_option('custom_products', $custom_products); } } $message = __('Custom Fields saved.', 'woocommerce-exporter'); woo_ce_admin_notice_html($message); woo_ce_manage_form(); break; default: woo_ce_manage_form(); break; } woo_ce_template_footer(); }
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(); }
function woo_pi_html_page() { global $import; $action = woo_get_action(); $title = __('Product Importer', 'woo_pi'); if (in_array($action, array('upload', 'save')) && !$import->cancel_import) { if ($file = woo_pi_get_option('csv')) { $title .= ': <em>' . basename($file) . '</em>'; } } $troubleshooting_url = 'http://www.visser.com.au/woocommerce/documentation/plugins/product-importer-deluxe/usage/'; $woo_pd_url = 'http://www.visser.com.au/woocommerce/plugins/product-importer-deluxe/'; $woo_pd_link = sprintf('<a href="%s" target="_blank">' . __('Product Importer Deluxe', 'woo_pi') . '</a>', $woo_pd_url); woo_pi_template_header($title); woo_pi_support_donate(); woo_pi_upload_directories(); switch ($action) { case 'upload': if (isset($import->file)) { $file = $import->file; } else { $file = array('size' => 0); } /* if( $file['size'] == 0 ) { $message = __( '', 'woo_pi' ); woo_pi_admin_notice( '' ); $import->cancel_import = true; } */ // Display the opening Import tab if the import fails if ($import->cancel_import) { woo_pi_manage_form(); return; } $upload_dir = wp_upload_dir(); if ($file) { woo_pi_prepare_data(); $i = 0; $products = woo_pi_return_product_count(); // Override the default import method if no Products exist if (!$products) { $import->import_method = 'new'; } $import->options = woo_pi_product_fields(); $import->options_size = count($import->options); $first_row = array(); $second_row = array(); if (isset($import->lines)) { // Detect character encoding and compare to selected file encoding $auto_encoding = mb_detect_encoding($import->raw); if ($auto_encoding !== false) { if (strtolower($auto_encoding) != strtolower($import->encoding)) { woo_pi_update_option('encoding', $auto_encoding); $message = sprintf(__('It seems the character encoding provided under General Settings on the Settings tab - <code>%s</code> - didn\'t match this import file so we automatically detected the character encoding for you to <code>%s</code>.', 'woo_pi'), $import->encoding, $auto_encoding); // Force the message to the screen as we are post-init woo_pi_admin_notice_html($message); } } $first_row = str_getcsv($import->lines[0], $import->delimiter); $import->columns = count($first_row); // If we only detect a single column then the delimiter may be wrong if ($import->columns == 1) { $auto_delimiter = woo_pi_detect_file_delimiter((string) $first_row[0]); if ($import->delimiter != $auto_delimiter) { $import->delimiter = $auto_delimiter; $first_row = str_getcsv($import->lines[0], $import->delimiter); $import->columns = count($first_row); // If the column count is unchanged then the CSV either has only a single column (which won't work) or we've failed our job $priority = 'updated'; if ($import->columns > 1) { $message = sprintf(__('It seems the field delimiter provided under Import Options - <code>%s</code> - didn\'t match this CSV so we automatically detected the CSV delimiter for you to <code>%s</code>.', 'woo_pi'), woo_pi_get_option('delimiter', ','), $auto_delimiter); woo_pi_update_option('delimiter', $import->delimiter); } else { $priority = 'error'; $message = __('It seems either this CSV has only a single column or we were unable to automatically detect the CSV delimiter.', 'woo_pi') . ' <a href="' . $troubleshooting_url . '" target="_blank">' . __('Need help?', 'woo_pi') . '</a>'; } // Force the message to the screen as we are post-init woo_pi_admin_notice_html($message, $priority); } unset($auto_delimiter); } $second_row = str_getcsv($import->lines[1], $import->delimiter); unset($import->lines); } foreach ($first_row as $key => $cell) { for ($k = 0; $k < $import->options_size; $k++) { if (woo_pi_format_column($import->options[$k]['label']) == woo_pi_format_column($cell)) { $import->skip_first = true; break; } } if (!isset($second_row[$key])) { $second_row[$key] = ''; } } include_once WOO_PI_PATH . 'templates/admin/import_upload.php'; } break; case 'save': // Display the opening Import tab if the import fails if ($import->cancel_import == false) { include_once WOO_PI_PATH . 'templates/admin/import_save.php'; } else { woo_pi_manage_form(); return; } break; default: woo_pi_manage_form(); break; } woo_pi_template_footer(); }