PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.2.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.2.0
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 +12 -9 3.10.133.2.0 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,20 +76,22 @@
76 76 // read series types
77 77 $types = fgetcsv( $handle, 0, VISUALIZER_CSV_DELIMITER, VISUALIZER_CSV_ENCLOSURE );
78 78 }
79 79
80 - $labels = array_filter( $labels );
81 - $types = array_filter( $types );
82 -
83 80 if ( ! $labels || ! $types ) {
84 - $this->_error = esc_html__( 'File should have a heading row (1st row) and a data type row (2nd row). Please try again.', 'visualizer' );
85 81 return false;
86 82 }
87 83
84 + // if no types were setup, re read labels and empty types array
88 85 $types = array_map( 'trim', $types );
89 86 if ( ! self::_validateTypes( $types ) ) {
90 - $this->_error = esc_html__( 'Invalid data types detected in the data type row (2nd row). Please try again.', 'visualizer' );
91 - return false;
87 + // re open the file
88 + fclose( $handle );
89 + $handle = $this->_get_file_handle();
90 +
91 + // re read the labels and empty types array
92 + $labels = fgetcsv( $handle, 0, VISUALIZER_CSV_DELIMITER, VISUALIZER_CSV_ENCLOSURE );
93 + $types = array();
92 94 }
93 95
94 96 for ( $i = 0, $len = count( $labels ); $i < $len; $i++ ) {
95 97 $default_type = $i === 0 ? 'string' : 'number';
@@ -114,8 +116,10 @@
114 116 * @param string $filename Optional file name to get handle. If omitted, $_filename is used.
115 117 * @return resource File handle resource on success, otherwise FALSE.
116 118 */
117 119 protected function _get_file_handle( $filename = false ) {
120 + // set line endings auto detect mode
121 + ini_set( 'auto_detect_line_endings', true );
118 122 // open file and return handle
119 123 return fopen( $filename ? $filename : $this->_filename, 'rb' );
120 124 }
121 125
@@ -129,9 +133,8 @@
129 133 */
130 134 public function fetch() {
131 135 // if filename is empty return false
132 136 if ( empty( $this->_filename ) ) {
133 - $this->_error = esc_html__( 'No file provided. Please try again.', 'visualizer' );
134 137 return false;
135 138 }
136 139
137 140 // read file and fill arrays