PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 1.7.6
Visualizer – Tables & Charts Manager with Built-in AI Generator v1.7.6
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 3.10.4 All 148 releases
← All changes | classes/Visualizer/Source/Csv/Remote.php +28 -40 4.0.71.7.6 View file →
@@ -29,14 +29,14 @@
29 29 */
30 30 class Visualizer_Source_Csv_Remote extends Visualizer_Source_Csv {
31 31
32 32 /**
33 - * Path to the safely downloaded temporary file.
33 + * Temporary file name used when allow_url_fopen option is disabled.
34 34 *
35 35 * @since 1.4.2
36 36 *
37 37 * @access private
38 - * @var string|false
38 + * @var string
39 39 */
40 40 private $_tmpfile = false;
41 41
42 42 /**
@@ -46,15 +46,13 @@
46 46 *
47 47 * @access public
48 48 * @return string The serialized array of data.
49 49 */
50 - public function getData( $dumb = false ) {
51 - return serialize(
52 - array(
53 - 'source' => $this->_filename,
54 - 'data' => $this->_data,
55 - )
56 - );
50 + public function getData() {
51 + return serialize( array(
52 + 'source' => $this->_filename,
53 + 'data' => $this->_data,
54 + ) );
57 55 }
58 56
59 57 /**
60 58 * Re populates data and series.
@@ -73,9 +71,9 @@
73 71
74 72 // if filename is empty, extract it from chart content
75 73 if ( empty( $this->_filename ) ) {
76 74 $chart = get_post( $chart_id );
77 - $data = Visualizer_Module::decode_content( html_entity_decode( $chart->post_content ) );
75 + $data = unserialize( $chart->post_content );
78 76 if ( ! isset( $data['source'] ) ) {
79 77 return false;
80 78 }
81 79
@@ -96,12 +94,9 @@
96 94 * @param int $chart_id The chart id.
97 95 * @return array The re populated array of data or old one.
98 96 */
99 97 public function repopulateData( $data, $chart_id ) {
100 - if ( ! is_array( $data ) ) {
101 - $data = array();
102 - }
103 - return array_key_exists( 'data', $data ) ? $data['data'] : $data;
98 + return $this->_repopulate( $chart_id ) ? $this->_data : $data;
104 99 }
105 100
106 101 /**
107 102 * Re populates series.
@@ -113,9 +108,9 @@
113 108 * @param int $chart_id The chart id.
114 109 * @return array The re populated array of series or old one.
115 110 */
116 111 public function repopulateSeries( $series, $chart_id ) {
117 - return $series;
112 + return $this->_repopulate( $chart_id ) ? $this->_series : $series;
118 113 }
119 114
120 115 /**
121 116 * Returns source name.
@@ -129,44 +124,37 @@
129 124 return __CLASS__;
130 125 }
131 126
132 127 /**
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 - /**
150 128 * Returns file handle to fetch data from.
151 129 *
152 130 * @since 1.4.2
153 131 *
154 132 * @access protected
133 + * @staticvar boolean $allow_url_fopen Determines whether or not allow_url_fopen option is enabled.
155 134 * @param string $filename Optional file name to get handle. If omitted, $_filename is used.
156 - * @return resource|false File handle resource on success, otherwise FALSE.
135 + * @return resource File handle resource on success, otherwise FALSE.
157 136 */
158 137 protected function _get_file_handle( $filename = false ) {
159 - if ( $this->_tmpfile && is_readable( $this->_tmpfile ) ) {
138 + static $allow_url_fopen = null;
139 +
140 + if ( ! is_wp_error( $this->_tmpfile ) && $this->_tmpfile && is_readable( $this->_tmpfile ) ) {
160 141 return parent::_get_file_handle( $this->_tmpfile );
161 142 }
162 143
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;
144 + if ( is_null( $allow_url_fopen ) ) {
145 + $allow_url_fopen = filter_var( ini_get( 'allow_url_fopen' ), FILTER_VALIDATE_BOOLEAN );
167 146 }
168 147
169 - $this->_tmpfile = $tmpfile;
170 - return parent::_get_file_handle( $this->_tmpfile );
148 + $scheme = parse_url( $this->_filename, PHP_URL_SCHEME );
149 + if ( $allow_url_fopen && in_array( $scheme, stream_get_wrappers() ) ) {
150 + return parent::_get_file_handle( $filename );
151 + }
152 +
153 + require_once ABSPATH . 'wp-admin/includes/file.php';
154 +
155 + $this->_tmpfile = download_url( $this->_filename );
156 +
157 + return ! is_wp_error( $this->_tmpfile ) ? parent::_get_file_handle( $this->_tmpfile ) : false;
171 158 }
159 +
172 160 }