PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 4.0.8
Visualizer – Tables & Charts Manager with Built-in AI Generator v4.0.8
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/Csv/Remote.php +28 -21 3.10.04.0.8 View file →
@@ -29,14 +29,14 @@
29 29 */
30 30 class Visualizer_Source_Csv_Remote extends Visualizer_Source_Csv {
31 31
32 32 /**
33 - * Temporary file name used when allow_url_fopen option is disabled.
33 + * Path to the safely downloaded temporary file.
34 34 *
35 35 * @since 1.4.2
36 36 *
37 37 * @access private
38 - * @var string
38 + * @var string|false
39 39 */
40 40 private $_tmpfile = false;
41 41
42 42 /**
@@ -73,9 +73,9 @@
73 73
74 74 // if filename is empty, extract it from chart content
75 75 if ( empty( $this->_filename ) ) {
76 76 $chart = get_post( $chart_id );
77 - $data = unserialize( html_entity_decode( $chart->post_content ) );
77 + $data = Visualizer_Module::decode_content( html_entity_decode( $chart->post_content ) );
78 78 if ( ! isset( $data['source'] ) ) {
79 79 return false;
80 80 }
81 81
@@ -129,37 +129,44 @@
129 129 return __CLASS__;
130 130 }
131 131
132 132 /**
133 + * Fetches the remote file and removes its temporary copy.
134 + *
135 + * @access public
136 + * @return boolean TRUE on success, otherwise FALSE.
137 + */
138 + public function fetch() {
139 + $result = parent::fetch();
140 +
141 + if ( $this->_tmpfile && is_file( $this->_tmpfile ) ) {
142 + wp_delete_file( $this->_tmpfile );
143 + $this->_tmpfile = false;
144 + }
145 +
146 + return $result;
147 + }
148 +
149 + /**
133 150 * Returns file handle to fetch data from.
134 151 *
135 152 * @since 1.4.2
136 153 *
137 154 * @access protected
138 - * @staticvar boolean $allow_url_fopen Determines whether or not allow_url_fopen option is enabled.
139 155 * @param string $filename Optional file name to get handle. If omitted, $_filename is used.
140 - * @return resource File handle resource on success, otherwise FALSE.
156 + * @return resource|false File handle resource on success, otherwise FALSE.
141 157 */
142 158 protected function _get_file_handle( $filename = false ) {
143 - static $allow_url_fopen = null;
144 -
145 - if ( ! is_wp_error( $this->_tmpfile ) && $this->_tmpfile && is_readable( $this->_tmpfile ) ) {
159 + if ( $this->_tmpfile && is_readable( $this->_tmpfile ) ) {
146 160 return parent::_get_file_handle( $this->_tmpfile );
147 161 }
148 162
149 - if ( is_null( $allow_url_fopen ) ) {
150 - $allow_url_fopen = filter_var( ini_get( 'allow_url_fopen' ), FILTER_VALIDATE_BOOLEAN );
163 + $tmpfile = Visualizer_Remote_Fetch::download( $this->_filename );
164 + if ( is_wp_error( $tmpfile ) ) {
165 + $this->_error = esc_html__( 'Could not download the file. Please check the URL and try again.', 'visualizer' );
166 + return false;
151 167 }
152 168
153 - $scheme = parse_url( $this->_filename, PHP_URL_SCHEME );
154 - if ( $allow_url_fopen && in_array( $scheme, stream_get_wrappers(), true ) ) {
155 - return parent::_get_file_handle( $filename );
156 - }
157 -
158 - require_once ABSPATH . 'wp-admin/includes/file.php';
159 -
160 - $this->_tmpfile = download_url( $this->_filename );
161 -
162 - return ! is_wp_error( $this->_tmpfile ) ? parent::_get_file_handle( $this->_tmpfile ) : false;
169 + $this->_tmpfile = $tmpfile;
170 + return parent::_get_file_handle( $this->_tmpfile );
163 171 }
164 -
165 172 }