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 -38 3.0.91.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,38 +59,31 @@
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++ ) {
85 82 $default_type = $i == 0 ? 'string' : 'number';
86 -
87 - $labels[ $i ] = $this->toUTF8( $labels[ $i ] );
88 -
89 83 $this->_series[] = array(
90 - 'label' => $labels[ $i ],
91 - 'type' => isset( $types[ $i ] ) ? $types[ $i ] : $default_type,
84 + 'label' => $labels[$i],
85 + 'type' => isset( $types[$i] ) ? $types[$i] : $default_type,
92 86 );
93 87 }
94 88
95 89 return true;
@@ -95,24 +89,8 @@
95 89 return true;
96 90 }
97 91
98 92 /**
99 - * Returns file handle to fetch data from.
100 - *
101 - * @since 1.4.2
102 - *
103 - * @access protected
104 - * @param string $filename Optional file name to get handle. If omitted, $_filename is used.
105 - * @return resource File handle resource on success, otherwise FALSE.
106 - */
107 - protected function _get_file_handle( $filename = false ) {
108 - // set line endings auto detect mode
109 - ini_set( 'auto_detect_line_endings', true );
110 - // open file and return handle
111 - return fopen( $filename ? $filename : $this->_filename, 'rb' );
112 - }
113 -
114 - /**
115 93 * Fetches information from source, parses it and builds series and data arrays.
116 94 *
117 95 * @since 1.0.0
118 96 *
@@ -124,19 +102,21 @@
124 102 if ( empty( $this->_filename ) ) {
125 103 return false;
126 104 }
127 105
106 + // set line endings auto detect mode
107 + @ini_set( 'auto_detect_line_endings', true );
108 +
128 109 // read file and fill arrays
129 - $handle = $this->_get_file_handle();
110 + $handle = fopen( $this->_filename, 'rb' );
130 111 if ( $handle ) {
131 112 // fetch series
132 - if ( ! $this->_fetchSeries( $handle ) ) {
113 + if ( !$this->_fetchSeries( $handle ) ) {
133 114 return false;
134 115 }
135 116
136 117 // fetch data
137 - while ( ( $data = fgetcsv( $handle, 0, VISUALIZER_CSV_DELIMITER, VISUALIZER_CSV_ENCLOSURE ) ) !== false ) {
138 -
118 + while ( ( $data = fgetcsv( $handle ) ) !== false ) {
139 119 $this->_data[] = $this->_normalizeData( $data );
140 120 }
141 121
142 122 // close file handle
@@ -157,5 +137,5 @@
157 137 public function getSourceName() {
158 138 return __CLASS__;
159 139 }
160 140
161 -}
141 +}