You are here

function _node_import_errors in Node import 5

1 string reference to '_node_import_errors'
_node_import_import_validate in ./node_import.module

File

./node_import.module, line 525
This modules provides a wizard at "administer >> content >> import" to import a CSV file with nodes.

Code

function _node_import_errors($edit) {
  if (!isset($edit['errors']) || empty($edit['errors'])) {
    return;
  }
  switch ($edit['file_format']) {
    case '_node_import_csv_get_row':
      header('Content-type: text/comma-separated-values');
      header('Content-Disposition: attachment; filename="rejected-' . $edit['filename'] . '"');

      // As a CSV line may span multiple lines and the fputcsv()
      // function is only for php 5.0, and we need to handle
      // quotes inside cells, we need to write this ourselves.
      // Based on: http://www.php.net/manual/en/function.fputcsv.php
      $quote = variable_get('node_import_csv_qualifier', '"');
      $delimiter = variable_get('node_import_csv_separator', ',');
      $escape = variable_get('node_import_csv_escape', '\\');
      foreach ($edit['errors'] as $row) {
        $str = '';
        $write_delimiter = FALSE;
        foreach ($row as $cell) {
          $cell = str_replace($quote, $escape . $quote, $cell);
          if ($write_delimiter) {
            $str .= $delimiter;
          }
          $str .= $quote . $cell . $quote;
          $write_delimiter = TRUE;
        }
        print $str . "\n";
      }
      break;
    case '_node_import_tsv_get_row':
      header('Content-Type: text/tab-separated-values');
      header('Content-Disposition: attachment; filename="rejected-' . $edit['filename'] . '"');

      // To be correct and pedantic about this format, we would
      // need to check the number of columns of each row as the
      // text/tab-separated-values format specifies that each
      // row should contain the same number of tabs. We won't do
      // that.
      // See: http://www.iana.org/assignments/media-types/text/tab-separated-values
      foreach ($edit['errors'] as $row) {
        print implode(variable_get('node_import_tsv_separator', "\t"), $row) . "\n";
      }
      break;
  }
}