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 +32 -22 3.1.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 /**
@@ -46,9 +46,9 @@
46 46 *
47 47 * @access public
48 48 * @return string The serialized array of data.
49 49 */
50 - public function getData() {
50 + public function getData( $dumb = false ) {
51 51 return serialize(
52 52 array(
53 53 'source' => $this->_filename,
54 54 'data' => $this->_data,
@@ -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
@@ -96,8 +96,11 @@
96 96 * @param int $chart_id The chart id.
97 97 * @return array The re populated array of data or old one.
98 98 */
99 99 public function repopulateData( $data, $chart_id ) {
100 + if ( ! is_array( $data ) ) {
101 + $data = array();
102 + }
100 103 return array_key_exists( 'data', $data ) ? $data['data'] : $data;
101 104 }
102 105
103 106 /**
@@ -126,37 +129,44 @@
126 129 return __CLASS__;
127 130 }
128 131
129 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 + /**
130 150 * Returns file handle to fetch data from.
131 151 *
132 152 * @since 1.4.2
133 153 *
134 154 * @access protected
135 - * @staticvar boolean $allow_url_fopen Determines whether or not allow_url_fopen option is enabled.
136 155 * @param string $filename Optional file name to get handle. If omitted, $_filename is used.
137 - * @return resource File handle resource on success, otherwise FALSE.
156 + * @return resource|false File handle resource on success, otherwise FALSE.
138 157 */
139 158 protected function _get_file_handle( $filename = false ) {
140 - static $allow_url_fopen = null;
141 -
142 - if ( ! is_wp_error( $this->_tmpfile ) && $this->_tmpfile && is_readable( $this->_tmpfile ) ) {
159 + if ( $this->_tmpfile && is_readable( $this->_tmpfile ) ) {
143 160 return parent::_get_file_handle( $this->_tmpfile );
144 161 }
145 162
146 - if ( is_null( $allow_url_fopen ) ) {
147 - $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;
148 167 }
149 168
150 - $scheme = parse_url( $this->_filename, PHP_URL_SCHEME );
151 - if ( $allow_url_fopen && in_array( $scheme, stream_get_wrappers() ) ) {
152 - return parent::_get_file_handle( $filename );
153 - }
154 -
155 - require_once ABSPATH . 'wp-admin/includes/file.php';
156 -
157 - $this->_tmpfile = download_url( $this->_filename );
158 -
159 - 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 );
160 171 }
161 -
162 172 }