| @@ -46,10 +46,10 @@ | ||
| 46 | 46 | * |
| 47 | 47 | * @access public |
| 48 | 48 | * @param string $filename The path to the file. |
| 49 | 49 | */ |
| 50 | - public function __construct( $filename = '' ) { | |
| 51 | - $this->_filename = trim( (string) $filename ); | |
| 50 | + public function __construct( $filename = null ) { | |
| 51 | + $this->_filename = trim( $filename ); | |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | 55 | * Fetches series information. |
| @@ -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 | |
| @@ -119,8 +114,10 @@ | ||
| 119 | 114 | * @param string $filename Optional file name to get handle. If omitted, $_filename is used. |
| 120 | 115 | * @return resource File handle resource on success, otherwise FALSE. |
| 121 | 116 | */ |
| 122 | 117 | protected function _get_file_handle( $filename = false ) { |
| 118 | + // set line endings auto detect mode | |
| 119 | + ini_set( 'auto_detect_line_endings', true ); | |
| 123 | 120 | // open file and return handle |
| 124 | 121 | return fopen( $filename ? $filename : $this->_filename, 'rb' ); |
| 125 | 122 | } |
| 126 | 123 | |
| @@ -147,12 +144,11 @@ | ||
| 147 | 144 | return false; |
| 148 | 145 | } |
| 149 | 146 | |
| 150 | 147 | // fetch data |
| 151 | - $data = fgetcsv( $handle, 0, VISUALIZER_CSV_DELIMITER, VISUALIZER_CSV_ENCLOSURE ); | |
| 152 | - while ( $data !== false ) { | |
| 148 | + // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition | |
| 149 | + while ( ( $data = fgetcsv( $handle, 0, VISUALIZER_CSV_DELIMITER, VISUALIZER_CSV_ENCLOSURE ) ) !== false ) { | |
| 153 | 150 | $this->_data[] = $this->_normalizeData( $data ); |
| 154 | - $data = fgetcsv( $handle, 0, VISUALIZER_CSV_DELIMITER, VISUALIZER_CSV_ENCLOSURE ); | |
| 155 | 151 | } |
| 156 | 152 | |
| 157 | 153 | // close file handle |
| 158 | 154 | fclose( $handle ); |