PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 4.0.1
Visualizer – Tables & Charts Manager with Built-in AI Generator v4.0.1
4.0.8 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 All 149 releases
← All changes | classes/Visualizer/Source/Xlsx/Remote.php +27 -16 4.0.74.0.1 View file →
@@ -85,34 +85,45 @@
85 85 * 'visualizer_xlsx_max_filesize') before handing the path to the parser,
86 86 * guarding against ZIP-bomb and DoS attacks.
87 87 *
88 88 * @access protected
89 - * @return string|false Path to the temporary file, or false if download failed.
89 + * @return string Path to the temporary file, or the original URL if download failed.
90 90 */
91 91 protected function _get_file_path() {
92 - if ( $this->_tmpfile && is_readable( $this->_tmpfile ) ) {
92 + if ( $this->_tmpfile && ! is_wp_error( $this->_tmpfile ) && is_readable( $this->_tmpfile ) ) {
93 93 return $this->_tmpfile;
94 94 }
95 95
96 - $max_bytes = (int) apply_filters( 'visualizer_xlsx_max_filesize', 10 * 1024 * 1024 );
97 - $tmpfile = Visualizer_Remote_Fetch::download(
98 - $this->_filename,
99 - array( 'limit_response_size' => $max_bytes )
100 - );
101 - if ( is_wp_error( $tmpfile ) ) {
102 - $this->_error = 'visualizer_remote_size' === $tmpfile->get_error_code()
103 - ? esc_html__( 'The XLSX file exceeds the maximum allowed size and cannot be imported.', 'visualizer' )
104 - : esc_html__( 'Could not download the XLSX file. Please check the URL and try again.', 'visualizer' );
105 - return false;
96 + require_once ABSPATH . 'wp-admin/includes/file.php';
97 +
98 + $this->_tmpfile = download_url( $this->_filename );
99 +
100 + if ( is_wp_error( $this->_tmpfile ) ) {
101 + $this->_error = esc_html__( 'Could not download the XLSX file. Please check the URL and try again.', 'visualizer' );
102 + $this->_tmpfile = false;
103 + // Return the original URL so the parent's open() call will fail
104 + // gracefully and set an error rather than throwing a PHP error.
105 + return $this->_filename;
106 106 }
107 - $this->_tmpfile = $tmpfile;
108 107
109 108 if ( ! is_file( $this->_tmpfile ) ) {
110 109 $this->_tmpfile = false;
111 110 $this->_error = esc_html__( 'Could not access the downloaded XLSX file. Please try again.', 'visualizer' );
112 - return false;
111 + return $this->_filename;
113 112 }
114 113
114 + // Maximum allowed file size in bytes. Default 10 MB; override via filter.
115 + $max_bytes = (int) apply_filters( 'visualizer_xlsx_max_filesize', 10 * 1024 * 1024 );
116 + if ( filesize( $this->_tmpfile ) > $max_bytes ) {
117 + @unlink( $this->_tmpfile ); // phpcs:ignore WordPress.PHP.NoSilencedErrors
118 + $this->_tmpfile = false;
119 + $this->_error = esc_html__(
120 + 'The XLSX file exceeds the maximum allowed size and cannot be imported.',
121 + 'visualizer'
122 + );
123 + return $this->_filename;
124 + }
125 +
115 126 return $this->_tmpfile;
116 127 }
117 128
118 129 /**
@@ -124,10 +135,10 @@
124 135 public function fetch() {
125 136 $result = parent::fetch();
126 137
127 138 // Clean up the temporary file after parsing.
128 - if ( $this->_tmpfile && is_file( $this->_tmpfile ) ) {
129 - wp_delete_file( $this->_tmpfile );
139 + if ( $this->_tmpfile && ! is_wp_error( $this->_tmpfile ) && is_file( $this->_tmpfile ) ) {
140 + @unlink( $this->_tmpfile ); // phpcs:ignore WordPress.PHP.NoSilencedErrors
130 141 $this->_tmpfile = false;
131 142 }
132 143
133 144 return $result;