| @@ -116,9 +116,9 @@ | ||
| 116 | 116 | * @since 1.4.2 |
| 117 | 117 | * |
| 118 | 118 | * @access protected |
| 119 | 119 | * @param string $filename Optional file name to get handle. If omitted, $_filename is used. |
| 120 | - * @return resource File handle resource on success, otherwise FALSE. | |
| 120 | + * @return resource|false File handle resource on success, otherwise FALSE. | |
| 121 | 121 | */ |
| 122 | 122 | protected function _get_file_handle( $filename = false ) { |
| 123 | 123 | // open file and return handle |
| 124 | 124 | return fopen( $filename ? $filename : $this->_filename, 'rb' ); |
| @@ -140,24 +140,30 @@ | ||
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // read file and fill arrays |
| 143 | 143 | $handle = $this->_get_file_handle(); |
| 144 | - if ( $handle ) { | |
| 145 | - // fetch series | |
| 146 | - if ( ! $this->_fetchSeries( $handle ) ) { | |
| 147 | - return false; | |
| 144 | + if ( ! $handle ) { | |
| 145 | + if ( empty( $this->_error ) ) { | |
| 146 | + $this->_error = esc_html__( 'The file could not be opened. Please try again.', 'visualizer' ); | |
| 148 | 147 | } |
| 148 | + return false; | |
| 149 | + } | |
| 149 | 150 | |
| 150 | - // fetch data | |
| 151 | + // fetch series | |
| 152 | + if ( ! $this->_fetchSeries( $handle ) ) { | |
| 153 | + fclose( $handle ); | |
| 154 | + return false; | |
| 155 | + } | |
| 156 | + | |
| 157 | + // fetch data | |
| 158 | + $data = fgetcsv( $handle, 0, VISUALIZER_CSV_DELIMITER, VISUALIZER_CSV_ENCLOSURE ); | |
| 159 | + while ( $data !== false ) { | |
| 160 | + $this->_data[] = $this->_normalizeData( $data ); | |
| 151 | 161 | $data = fgetcsv( $handle, 0, VISUALIZER_CSV_DELIMITER, VISUALIZER_CSV_ENCLOSURE ); |
| 152 | - while ( $data !== false ) { | |
| 153 | - $this->_data[] = $this->_normalizeData( $data ); | |
| 154 | - $data = fgetcsv( $handle, 0, VISUALIZER_CSV_DELIMITER, VISUALIZER_CSV_ENCLOSURE ); | |
| 155 | - } | |
| 162 | + } | |
| 156 | 163 | |
| 157 | - // close file handle | |
| 158 | - fclose( $handle ); | |
| 159 | - } | |
| 164 | + // close file handle | |
| 165 | + fclose( $handle ); | |
| 160 | 166 | |
| 161 | 167 | return true; |
| 162 | 168 | } |
| 163 | 169 | |