| @@ -76,13 +76,8 @@ | ||
| 76 | 76 | // read series types |
| 77 | 77 | $types = fgetcsv( $handle, 0, VISUALIZER_CSV_DELIMITER, VISUALIZER_CSV_ENCLOSURE ); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - if ( ! is_array( $labels ) || ! is_array( $types ) ) { | |
| 81 | - $this->_error = esc_html__( 'File should have a heading row (1st row) and a data type row (2nd row). Please try again.', 'visualizer' ); | |
| 82 | - return false; | |
| 83 | - } | |
| 84 | - | |
| 85 | 80 | $labels = array_filter( $labels ); |
| 86 | 81 | $types = array_filter( $types ); |
| 87 | 82 | |
| 88 | 83 | if ( ! $labels || ! $types ) { |
| @@ -101,9 +96,9 @@ | ||
| 101 | 96 | |
| 102 | 97 | $labels[ $i ] = $this->toUTF8( $labels[ $i ] ); |
| 103 | 98 | |
| 104 | 99 | $this->_series[] = array( |
| 105 | - 'label' => sanitize_text_field( wp_strip_all_tags( $labels[ $i ] ) ), | |
| 100 | + 'label' => $labels[ $i ], | |
| 106 | 101 | 'type' => isset( $types[ $i ] ) ? $types[ $i ] : $default_type, |
| 107 | 102 | ); |
| 108 | 103 | } |
| 109 | 104 | |
| @@ -116,9 +111,9 @@ | ||
| 116 | 111 | * @since 1.4.2 |
| 117 | 112 | * |
| 118 | 113 | * @access protected |
| 119 | 114 | * @param string $filename Optional file name to get handle. If omitted, $_filename is used. |
| 120 | - * @return resource|false File handle resource on success, otherwise FALSE. | |
| 115 | + * @return resource File handle resource on success, otherwise FALSE. | |
| 121 | 116 | */ |
| 122 | 117 | protected function _get_file_handle( $filename = false ) { |
| 123 | 118 | // open file and return handle |
| 124 | 119 | return fopen( $filename ? $filename : $this->_filename, 'rb' ); |
| @@ -140,30 +135,23 @@ | ||
| 140 | 135 | } |
| 141 | 136 | |
| 142 | 137 | // read file and fill arrays |
| 143 | 138 | $handle = $this->_get_file_handle(); |
| 144 | - if ( ! $handle ) { | |
| 145 | - if ( empty( $this->_error ) ) { | |
| 146 | - $this->_error = esc_html__( 'The file could not be opened. Please try again.', 'visualizer' ); | |
| 139 | + if ( $handle ) { | |
| 140 | + // fetch series | |
| 141 | + if ( ! $this->_fetchSeries( $handle ) ) { | |
| 142 | + return false; | |
| 147 | 143 | } |
| 148 | - return false; | |
| 149 | - } | |
| 150 | 144 | |
| 151 | - // fetch series | |
| 152 | - if ( ! $this->_fetchSeries( $handle ) ) { | |
| 145 | + // fetch data | |
| 146 | + // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition | |
| 147 | + while ( ( $data = fgetcsv( $handle, 0, VISUALIZER_CSV_DELIMITER, VISUALIZER_CSV_ENCLOSURE ) ) !== false ) { | |
| 148 | + $this->_data[] = $this->_normalizeData( $data ); | |
| 149 | + } | |
| 150 | + | |
| 151 | + // close file handle | |
| 153 | 152 | fclose( $handle ); |
| 154 | - return false; | |
| 155 | 153 | } |
| 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 ); | |
| 161 | - $data = fgetcsv( $handle, 0, VISUALIZER_CSV_DELIMITER, VISUALIZER_CSV_ENCLOSURE ); | |
| 162 | - } | |
| 163 | - | |
| 164 | - // close file handle | |
| 165 | - fclose( $handle ); | |
| 166 | 154 | |
| 167 | 155 | return true; |
| 168 | 156 | } |
| 169 | 157 | |