コード例 #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();
 }
コード例 #2
0
ファイル: functions.php プロジェクト: GarryVeles/Artibaltika
function woo_pi_delete_file()
{
    global $import;
    switch ($import->delete_file) {
        case '1':
            // Delete CSV from /wp-content/uploads/
            if ($file = woo_pi_get_option('csv')) {
                if (file_exists($file)) {
                    @unlink($file);
                }
            }
            if ($import->advanced_log) {
                $import->log .= "<br /><br />" . __('Temporary CSV deleted', 'woo_pi');
            }
            break;
        case '0':
        default:
            // Add CSV to Past Imports
            if ($file = woo_pi_get_option('csv')) {
                woo_pi_add_past_import($file);
            }
            break;
    }
    woo_pi_update_option('csv', '');
}
コード例 #3
0
ファイル: admin.php プロジェクト: hikaram/wee
function woo_pi_add_past_import($file = '')
{
    global $import;
    $upload_dir = wp_upload_dir();
    if (!empty($file)) {
        if (file_exists($file)) {
            if ($past_imports = woo_pi_get_option('past_imports')) {
                $past_imports = maybe_unserialize($past_imports);
            } else {
                $past_imports = array();
            }
            if (is_array($past_imports) && !woo_pi_array_search($past_imports, 'filename', $file)) {
                $past_imports[] = array('filename' => $file, 'date' => current_time('mysql'));
                woo_pi_update_option('past_imports', $past_imports);
                if ($import->advanced_log) {
                    $import->log .= "<br /><br />" . sprintf(__('Added %s to Past Imports', 'woo_pi'), basename($file));
                }
            } else {
                if ($import->advanced_log) {
                    $import->log .= "<br /><br />" . sprintf(__('%s already appears in Past Imports', 'woo_pi'), basename($file));
                }
            }
        }
    }
}