Exemplo n.º 1
0
 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();
 }
Exemplo n.º 2
0
 function woo_pi_total_columns()
 {
     global $import;
     if ($import->rows) {
         if ($import->skip_first) {
             $message = sprintf(__('%s rows have been detected within this import file, and by the looks of it the first row contains the column headers. Let\'s get started!', 'woo_pi'), $import->rows);
         } else {
             $message = sprintf(__('%s rows have been detected within this import file. Let\'s get started!', 'woo_pi'), $import->rows);
         }
         woo_pi_admin_notice_html($message);
     }
 }
Exemplo n.º 3
0
function woo_pi_tab_template($tab = '')
{
    global $import;
    if (!$tab) {
        $tab = 'overview';
    }
    // Product Importer Deluxe
    $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);
    $troubleshooting_url = 'http://www.visser.com.au/documentation/product-importer/';
    switch ($tab) {
        case 'overview':
            $skip_overview = woo_pi_get_option('skip_overview', false);
            break;
        case 'import':
            woo_pi_upload_directories();
            $upload_dir = wp_upload_dir();
            $max_upload = (int) ini_get('upload_max_filesize');
            $max_post = (int) ini_get('post_max_size');
            $memory_limit = (int) ini_get('memory_limit');
            $wp_upload_limit = round(wp_max_upload_size() / 1024 / 1024, 2);
            $upload_mb = min($max_upload, $max_post, $memory_limit, $wp_upload_limit);
            $file_path = $upload_dir['basedir'] . '/';
            $file_path_relative = 'imports/store-a.csv';
            $file_url = 'http://www.domain.com/wp-content/uploads/imports/store-a.jpg';
            $file_ftp_host = 'ftp.domain.com';
            $file_ftp_user = '******';
            $file_ftp_pass = '******';
            $file_ftp_port = '';
            $file_ftp_path = 'wp-content/uploads/imports/store-a.jpg';
            $file_ftp_timeout = '';
            if (isset($_POST['csv_file_path'])) {
                $file_path_relative = $_POST['csv_file_path'];
            }
            $modules = woo_pi_modules_list();
            $csv_sample_link = 'http://www.visser.com.au/woocommerce/plugins/product-importer-deluxe/#sample-csv';
            $csv_template_link = 'http://www.visser.com.au/woocommerce/plugins/product-importer-deluxe/#blank-csv';
            if (isset($_GET['import']) && $_GET['import'] == WOO_PI_PREFIX) {
                $url = 'import';
            }
            if (isset($_GET['page']) && $_GET['page'] == WOO_PI_PREFIX) {
                $url = 'page';
            }
            break;
        case 'settings':
            $delete_file = woo_pi_get_option('delete_file', 0);
            $timeout = woo_pi_get_option('timeout', 0);
            $encoding = woo_pi_get_option('encoding', 'UTF-8');
            $delimiter = woo_pi_get_option('delimiter', ',');
            $category_separator = woo_pi_get_option('category_separator', '|');
            $parent_child_delimiter = woo_pi_get_option('parent_child_delimiter', '>');
            $secret_key = woo_pi_get_option('secret_key', '');
            $file_encodings = function_exists('mb_list_encodings') ? mb_list_encodings() : false;
            break;
        case 'tools':
            // Store Exporter
            $woo_ce_url = 'http://www.visser.com.au/woocommerce/plugins/exporter/';
            $woo_ce_target = ' target="_blank"';
            if (function_exists('woo_ce_export_dataset')) {
                $woo_ce_url = add_query_arg(array('page' => 'woo_ce', 'tab' => null));
                $woo_ce_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_PI_PATH . 'templates/admin/tabs-' . $tab . '.php')) {
            include_once WOO_PI_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_pi'), 'tabs-' . $tab . '.php', WOO_PI_PATH . 'templates/admin/...');
            woo_pi_admin_notice_html($message, 'error');
            ob_start();
            ?>
<p><?php 
            _e('You can see this error for one of a few common reasons', 'woo_pi');
            ?>
:</p>
<ul class="ul-disc">
	<li><?php 
            _e('WordPress was unable to create this file when the Plugin was installed or updated', 'woo_pi');
            ?>
</li>
	<li><?php 
            _e('The Plugin files have been recently changed and there has been a file conflict', 'woo_pi');
            ?>
</li>
	<li><?php 
            _e('The Plugin file has been locked and cannot be opened by WordPress', 'woo_pi');
            ?>
</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_pi');
            ?>
</p>
<?php 
            ob_end_flush();
        }
    }
}