PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.64
Timetics – Appointment Booking Calendar & Scheduling v1.0.64
1.0.64 1.0.62 1.0.63 1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 All 65 releases
← All changes | base/csv-reader.php +35 -12 1.0.16 → 1.0.64 View file →
@@ -38,30 +38,53 @@
38 38 private static function read_file() {
39 39 $file = self::$file;
40 40 $csv_data = [];
41 41
42 - $handle = fopen( $file, 'r' );
43 - $headers = fgetcsv( $handle );
42 + // Initialize WP_Filesystem
43 + global $wp_filesystem;
44 + if ( empty( $wp_filesystem ) ) {
45 + require_once ABSPATH . 'wp-admin/includes/file.php';
46 + WP_Filesystem();
47 + }
44 48
49 + // Read file contents using WP_Filesystem
50 + $contents = $wp_filesystem->get_contents( $file );
51 + if ( false === $contents ) {
52 + return $csv_data;
53 + }
54 +
55 + // Split content into lines
56 + $lines = explode( "\n", $contents );
57 + if ( empty( $lines ) ) {
58 + return $csv_data;
59 + }
60 +
61 + // Parse header row
62 + $headers = str_getcsv( array_shift( $lines ) );
45 63 if ( ! $headers ) {
46 64 return $csv_data;
47 65 }
48 66
49 - if ( $handle !== false ) {
50 - $header_count = count( $headers );
67 + $header_count = count( $headers );
51 68
52 - while ( ( $data = fgetcsv( $handle ) ) !== false ) {
53 - $row = [];
69 + foreach ( $lines as $line ) {
70 + // Skip empty lines
71 + if ( empty( trim( $line ) ) ) {
72 + continue;
73 + }
54 74
55 - for ( $i = 0; $i < $header_count; $i++ ) {
56 - $row[$headers[$i]] = $data[$i];
57 - }
75 + $data = str_getcsv( $line );
76 + if ( false === $data ) {
77 + continue;
78 + }
58 79
59 - $csv_data[] = $row;
80 + $row = [];
81 + for ( $i = 0; $i < $header_count; $i++ ) {
82 + $row[$headers[$i]] = isset( $data[$i] ) ? $data[$i] : '';
60 83 }
84 +
85 + $csv_data[] = $row;
61 86 }
62 -
63 - fclose( $handle );
64 87
65 88 return $csv_data;
66 89 }
67 90 }