PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.7.9
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.7.9
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 3.10.4 All 148 releases
← All changes | classes/Visualizer/Source/Csv.php +17 -27 4.0.73.7.9 View file →
@@ -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
@@ -116,11 +111,13 @@
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 ) {
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
@@ -140,30 +137,23 @@
140 137 }
141 138
142 139 // read file and fill arrays
143 140 $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' );
141 + if ( $handle ) {
142 + // fetch series
143 + if ( ! $this->_fetchSeries( $handle ) ) {
144 + return false;
147 145 }
148 - return false;
149 - }
150 146
151 - // fetch series
152 - if ( ! $this->_fetchSeries( $handle ) ) {
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 + }
152 +
153 + // close file handle
153 154 fclose( $handle );
154 - return false;
155 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 );
161 - $data = fgetcsv( $handle, 0, VISUALIZER_CSV_DELIMITER, VISUALIZER_CSV_ENCLOSURE );
162 - }
163 -
164 - // close file handle
165 - fclose( $handle );
166 156
167 157 return true;
168 158 }
169 159