PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 1.1.2
Visualizer – Tables & Charts Manager with Built-in AI Generator v1.1.2
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 +18 -35 3.0.51.1.2 View file →
@@ -18,8 +18,9 @@
18 18 // | MA 02110-1301 USA |
19 19 // +----------------------------------------------------------------------+
20 20 // | Author: Eugene Manuilov <eugene@manuilov.org> |
21 21 // +----------------------------------------------------------------------+
22 +
22 23 /**
23 24 * Source manager for local CSV files.
24 25 *
25 26 * @category Visualizer
@@ -58,27 +59,23 @@
58 59 *
59 60 * @access private
60 61 * @param resource $handle The file handle resource.
61 62 */
62 - private function _fetchSeries( &$handle ) {
63 + private function _fetchSeries( $handle ) {
63 64 // read column titles
64 - $labels = fgetcsv( $handle, 0, VISUALIZER_CSV_DELIMITER, VISUALIZER_CSV_ENCLOSURE );
65 + $labels = fgetcsv( $handle );
66 +
65 67 // read series types
66 - $types = fgetcsv( $handle, 0, VISUALIZER_CSV_DELIMITER, VISUALIZER_CSV_ENCLOSURE );
68 + $types = fgetcsv( $handle );
67 69
68 - if ( ! $labels || ! $types ) {
70 + if ( !$labels || !$types ) {
69 71 return false;
70 72 }
71 73
72 74 // if no types were setup, re read labels and empty types array
73 - $types = array_map( 'trim', $types );
74 - if ( ! self::_validateTypes( $types ) ) {
75 - // re open the file
76 - fclose( $handle );
77 - $handle = $this->_get_file_handle();
78 -
79 - // re read the labels and empty types array
80 - $labels = fgetcsv( $handle, 0, VISUALIZER_CSV_DELIMITER, VISUALIZER_CSV_ENCLOSURE );
75 + if ( !self::_validateTypes( $types ) ) {
76 + fseek( $handle, 0 );
77 + $labels = fgetcsv( $handle );
81 78 $types = array();
82 79 }
83 80
84 81 for ( $i = 0, $len = count( $labels ); $i < $len; $i++ ) {
@@ -83,10 +80,10 @@
83 80
84 81 for ( $i = 0, $len = count( $labels ); $i < $len; $i++ ) {
85 82 $default_type = $i == 0 ? 'string' : 'number';
86 83 $this->_series[] = array(
87 - 'label' => $labels[ $i ],
88 - 'type' => isset( $types[ $i ] ) ? $types[ $i ] : $default_type,
84 + 'label' => $labels[$i],
85 + 'type' => isset( $types[$i] ) ? $types[$i] : $default_type,
89 86 );
90 87 }
91 88
92 89 return true;
@@ -92,24 +89,8 @@
92 89 return true;
93 90 }
94 91
95 92 /**
96 - * Returns file handle to fetch data from.
97 - *
98 - * @since 1.4.2
99 - *
100 - * @access protected
101 - * @param string $filename Optional file name to get handle. If omitted, $_filename is used.
102 - * @return resource File handle resource on success, otherwise FALSE.
103 - */
104 - protected function _get_file_handle( $filename = false ) {
105 - // set line endings auto detect mode
106 - ini_set( 'auto_detect_line_endings', true );
107 - // open file and return handle
108 - return fopen( $filename ? $filename : $this->_filename, 'rb' );
109 - }
110 -
111 - /**
112 93 * Fetches information from source, parses it and builds series and data arrays.
113 94 *
114 95 * @since 1.0.0
115 96 *
@@ -121,19 +102,21 @@
121 102 if ( empty( $this->_filename ) ) {
122 103 return false;
123 104 }
124 105
106 + // set line endings auto detect mode
107 + @ini_set( 'auto_detect_line_endings', true );
108 +
125 109 // read file and fill arrays
126 - $handle = $this->_get_file_handle();
110 + $handle = fopen( $this->_filename, 'rb' );
127 111 if ( $handle ) {
128 112 // fetch series
129 - if ( ! $this->_fetchSeries( $handle ) ) {
113 + if ( !$this->_fetchSeries( $handle ) ) {
130 114 return false;
131 115 }
132 116
133 117 // fetch data
134 - while ( ( $data = fgetcsv( $handle, 0, VISUALIZER_CSV_DELIMITER, VISUALIZER_CSV_ENCLOSURE ) ) !== false ) {
135 -
118 + while ( ( $data = fgetcsv( $handle ) ) !== false ) {
136 119 $this->_data[] = $this->_normalizeData( $data );
137 120 }
138 121
139 122 // close file handle
@@ -154,5 +137,5 @@
154 137 public function getSourceName() {
155 138 return __CLASS__;
156 139 }
157 140
158 -}
141 +}