WordPress.org

Ready to get started?Download WordPress

Forums

Business Directory Plugin
[resolved] csv import fails when fields have newlines (PATCH) (5 posts)

  1. mandric
    Member
    Posted 1 year ago #

    Test: http://cl.ly/461g1U1v2Q2M

    name,address,phone
    bob,"123 whitehouse ln
    washington, dc 12345",+13122255331
    sam,"567 main st, chicago il",+7082255331

    Patch: http://cl.ly/1x1b1n383f2C

    http://wordpress.org/extend/plugins/business-directory-plugin/

  2. businessdirectoryplugin
    Member
    Plugin Author

    Posted 1 year ago #

    Hi mandric,

    Any chance you can post the actual code changes up here instead? The patch did not download for me at all to view the code.

  3. mandric
    Member
    Posted 1 year ago #

    343,344c343
    <     private function process_line($line) {
    <         $row = str_getcsv($line, $this->settings['csv-file-separator']);
    ---
    >     private function process_line($row) {
    358,364c357,360
    <         $this->csv = explode("\n", str_replace(array("\r\n", "\r"), "\n", file_get_contents($csv_file)));
    <         array_map('rtrim', $this->csv);
    <
    <         foreach ($this->csv as $n => $line) {
    <             $line = trim($line);
    <
    <             if ($line) {
    ---
    >         $line_count = 0;
    >         if (($handle = fopen($csv_file, "r")) !== FALSE) {
    >             while (($row = fgetcsv($handle, 0, $this->settings['csv-file-separator'])) !== FALSE) {
    >                 $row = array_map('rtrim', $row);
    366c362
    <                     $this->header = str_getcsv($line, $this->settings['csv-file-separator']);
    ---
    >                     $this->header = $row;
    368,369c364,365
    <                     if ($row = $this->process_line($line)) {
    <                         $this->rows[] = array('line' => $n + 1, 'data' => $row, 'error' => false);
    ---
    >                     if ($row = $this->process_line($row)) {
    >                         $this->rows[] = array('line' => $line_count + 1, 'data' => $row, 'error' => false);
    371c367
    <                         $this->rejected_rows[] = array('line' => $n + 1, 'data' => $row, 'error' => _x('Malformed row (too many columns)', 'admin csv-import', 'WPBDM') );
    ---
    >                         $this->rejected_rows[] = array('line' => $line_count + 1, 'data' => $row, 'error' => _x('Malformed row (too many columns)', 'admin csv-import', 'WPBDM') );
    373a370
    >                 $line_count++;
    374a372
    >             fclose($handle);
    547c545
    <  }
    \ No newline at end of file
    ---
    >  }
  4. mandric
    Member
    Posted 1 year ago #

    that is for csv-import.php

  5. businessdirectoryplugin
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks, Mandric. We'll look at adding those fixes.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.