PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 4.0.8
Visualizer – Tables & Charts Manager with Built-in AI Generator v4.0.8
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
← All changes | classes/Visualizer/Source/Csv.php +25 -15 3.10.24.0.8 View file →
@@ -76,8 +76,13 @@
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 +
80 85 $labels = array_filter( $labels );
81 86 $types = array_filter( $types );
82 87
83 88 if ( ! $labels || ! $types ) {
@@ -96,9 +101,9 @@
96 101
97 102 $labels[ $i ] = $this->toUTF8( $labels[ $i ] );
98 103
99 104 $this->_series[] = array(
100 - 'label' => $labels[ $i ],
105 + 'label' => sanitize_text_field( wp_strip_all_tags( $labels[ $i ] ) ),
101 106 'type' => isset( $types[ $i ] ) ? $types[ $i ] : $default_type,
102 107 );
103 108 }
104 109
@@ -111,13 +116,11 @@
111 116 * @since 1.4.2
112 117 *
113 118 * @access protected
114 119 * @param string $filename Optional file name to get handle. If omitted, $_filename is used.
115 - * @return resource File handle resource on success, otherwise FALSE.
120 + * @return resource|false File handle resource on success, otherwise FALSE.
116 121 */
117 122 protected function _get_file_handle( $filename = false ) {
118 - // set line endings auto detect mode
119 - ini_set( 'auto_detect_line_endings', true );
120 123 // open file and return handle
121 124 return fopen( $filename ? $filename : $this->_filename, 'rb' );
122 125 }
123 126
@@ -137,23 +140,30 @@
137 140 }
138 141
139 142 // read file and fill arrays
140 143 $handle = $this->_get_file_handle();
141 - if ( $handle ) {
142 - // fetch series
143 - if ( ! $this->_fetchSeries( $handle ) ) {
144 - 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' );
145 147 }
148 + return false;
149 + }
146 150
147 - // fetch data
148 - // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
149 - while ( ( $data = fgetcsv( $handle, 0, VISUALIZER_CSV_DELIMITER, VISUALIZER_CSV_ENCLOSURE ) ) !== false ) {
150 - $this->_data[] = $this->_normalizeData( $data );
151 - }
151 + // fetch series
152 + if ( ! $this->_fetchSeries( $handle ) ) {
153 + fclose( $handle );
154 + return false;
155 + }
152 156
153 - // close file handle
154 - fclose( $handle );
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 );
155 162 }
163 +
164 + // close file handle
165 + fclose( $handle );
156 166
157 167 return true;
158 168 }
159 169