You are here

public function CSVFIReader::init in Feed Import 7.3

Here you'll init your reader.

Overrides FeedImportReader::init

File

feed_import_base/inc/feed_import_readers.inc, line 542
This file contains implementations of feed import readers.

Class

CSVFIReader
CSV Reader class, used to read csv files.

Code

public function init() {

  // Require url.
  if (empty($this->options['url'])) {
    return FALSE;
  }

  // Set default options.
  $this->options += array(
    'length' => 0,
    'delimiter' => ',',
    'enclosure' => '"',
    'escape' => '\\',
    'use_column_names' => FALSE,
    'stream' => NULL,
  );

  // Check for stream options.
  if ($ctx = $this
    ->getStreamContext($this->options['stream'])) {

    // Open the file using stream options.
    $this->fh = fopen($this->options['url'], 'rb', FALSE, $ctx);
  }
  else {

    // Open the file.
    $this->fh = fopen($this->options['url'], 'rb');
  }
  if (!$this->fh) {
    return FALSE;
  }

  // Check to see if column names are used.
  if ($this->options['use_column_names']) {
    if ($this->columns = $this
      ->get()) {
      $this->columns = array_flip($this->columns);
    }
    else {
      return FALSE;
    }
  }
  return TRUE;
}