/**
  * Get preview for sample CSV data
  *
  * @since 3.0.0
  */
 public function get_preview()
 {
     check_ajax_referer('get-csv-preview', 'security');
     $delimiter = isset($_GET['delimiter']) ? $_GET['delimiter'] : ',';
     $file = isset($_GET['file']) ? $_GET['file'] : '';
     if (!$file) {
         wp_die();
     }
     list($data, $headers) = WC_CSV_Import_Suite_Parser::parse_sample_data($file, $delimiter);
     $data = array(1 => $headers) + $data;
     echo WC_CSV_Import_Suite_Parser::generate_html_rows($data);
     wp_die();
 }
 /**
  * Find related items (lines) in a multi-line format CSV file
  *
  * @since 3.0.0
  * @param mixed $item_identifier Identifier used to match related lines
  * @param array $parsed_data Parsed data from CSV
  * @param int $line_num Current line number counter. Passed by reference
  * @param array $options Import options
  * @return array Array of related items/lines
  */
 protected function find_related_items($item_identifier, $parsed_data, &$line_num, $options)
 {
     $related_items = array();
     do {
         $next_item = $next_parsed_item = null;
         $item_continued = $results = false;
         // the next line has already been read from the CSV file
         if (isset($parsed_data[$line_num + 1])) {
             $next_item = $parsed_data[$line_num + 1];
         } else {
             $_options = $options;
             $_options['start_pos'] = $this->import_progress['pos'];
             // we continue from last pointer position
             $_options['start_line'] = $this->import_progress['line'] + 1;
             // but we need to increment the line number ourselves
             $_options['max_lines'] = 1;
             // read raw data from CSV file
             $results = WC_CSV_Import_Suite_Parser::parse($this->file, $_options);
             $next_item = !empty($results[0]) ? $results[0][$line_num + 1] : null;
         }
         // an item (line) was successfully found
         if (!empty($next_item)) {
             // check if the next line is related to the last (current) line
             $item_continued = $item_identifier == $this->get_item_identifier($next_item);
             // if the next item identifier matches current, we know those lines
             // belong together to form a single item
             if ($item_continued) {
                 // increment import progress
                 // NB! Intentional overwrite of $line_num
                 $line_num++;
                 $related_items[$line_num] = $next_item;
                 $this->import_progress = array('line' => $line_num, 'pos' => $results[2]);
             }
         }
     } while ($next_item && $item_continued);
     return $related_items;
 }