| @@ -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 |
| @@ -60,36 +61,33 @@ | ||
| 60 | 61 | * @param resource $handle The file handle resource. |
| 61 | 62 | */ |
| 62 | 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 | + if ( !self::_validateTypes( $types ) ) { | |
| 75 | 76 | // re open the file |
| 76 | 77 | fclose( $handle ); |
| 77 | - $handle = $this->_get_file_handle(); | |
| 78 | + $handle = fopen( $this->_filename, 'rb' ); | |
| 78 | 79 | |
| 79 | 80 | // re read the labels and empty types array |
| 80 | - $labels = fgetcsv( $handle, 0, VISUALIZER_CSV_DELIMITER, VISUALIZER_CSV_ENCLOSURE ); | |
| 81 | + $labels = fgetcsv( $handle ); | |
| 81 | 82 | $types = array(); |
| 82 | 83 | } |
| 83 | 84 | |
| 84 | 85 | for ( $i = 0, $len = count( $labels ); $i < $len; $i++ ) { |
| 85 | 86 | $default_type = $i == 0 ? 'string' : 'number'; |
| 86 | - | |
| 87 | - $labels[ $i ] = $this->toUTF8( $labels[ $i ] ); | |
| 88 | - | |
| 89 | 87 | $this->_series[] = array( |
| 90 | - 'label' => $labels[ $i ], | |
| 91 | - 'type' => isset( $types[ $i ] ) ? $types[ $i ] : $default_type, | |
| 88 | + 'label' => $labels[$i], | |
| 89 | + 'type' => isset( $types[$i] ) ? $types[$i] : $default_type, | |
| 92 | 90 | ); |
| 93 | 91 | } |
| 94 | 92 | |
| 95 | 93 | return true; |
| @@ -95,24 +93,8 @@ | ||
| 95 | 93 | return true; |
| 96 | 94 | } |
| 97 | 95 | |
| 98 | 96 | /** |
| 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 | 97 | * Fetches information from source, parses it and builds series and data arrays. |
| 116 | 98 | * |
| 117 | 99 | * @since 1.0.0 |
| 118 | 100 | * |
| @@ -124,19 +106,21 @@ | ||
| 124 | 106 | if ( empty( $this->_filename ) ) { |
| 125 | 107 | return false; |
| 126 | 108 | } |
| 127 | 109 | |
| 110 | + // set line endings auto detect mode | |
| 111 | + @ini_set( 'auto_detect_line_endings', true ); | |
| 112 | + | |
| 128 | 113 | // read file and fill arrays |
| 129 | - $handle = $this->_get_file_handle(); | |
| 114 | + $handle = fopen( $this->_filename, 'rb' ); | |
| 130 | 115 | if ( $handle ) { |
| 131 | 116 | // fetch series |
| 132 | - if ( ! $this->_fetchSeries( $handle ) ) { | |
| 117 | + if ( !$this->_fetchSeries( $handle ) ) { | |
| 133 | 118 | return false; |
| 134 | 119 | } |
| 135 | 120 | |
| 136 | 121 | // fetch data |
| 137 | - while ( ( $data = fgetcsv( $handle, 0, VISUALIZER_CSV_DELIMITER, VISUALIZER_CSV_ENCLOSURE ) ) !== false ) { | |
| 138 | - | |
| 122 | + while ( ( $data = fgetcsv( $handle ) ) !== false ) { | |
| 139 | 123 | $this->_data[] = $this->_normalizeData( $data ); |
| 140 | 124 | } |
| 141 | 125 | |
| 142 | 126 | // close file handle |
| @@ -157,5 +141,5 @@ | ||
| 157 | 141 | public function getSourceName() { |
| 158 | 142 | return __CLASS__; |
| 159 | 143 | } |
| 160 | 144 | |
| 161 | -} | |
| 145 | +} | |