PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 1.1.2
Visualizer – Tables & Charts Manager with Built-in AI Generator v1.1.2
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 +14 -68 4.0.71.1.2 View file →
@@ -18,8 +18,9 @@
18 18 // | MA 02110-1301 USA |
19 19 // +----------------------------------------------------------------------+
20 20 // | Author: Eugene Manuilov <eugene@manuilov.org> |
21 21 // +----------------------------------------------------------------------+
22 +
22 23 /**
23 24 * Source manager for remote CSV files.
24 25 *
25 26 * @category Visualizer
@@ -29,18 +30,8 @@
29 30 */
30 31 class Visualizer_Source_Csv_Remote extends Visualizer_Source_Csv {
31 32
32 33 /**
33 - * Path to the safely downloaded temporary file.
34 - *
35 - * @since 1.4.2
36 - *
37 - * @access private
38 - * @var string|false
39 - */
40 - private $_tmpfile = false;
41 -
42 - /**
43 34 * Returns data parsed from source.
44 35 *
45 36 * @since 1.1.0
46 37 *
@@ -46,15 +37,13 @@
46 37 *
47 38 * @access public
48 39 * @return string The serialized array of data.
49 40 */
50 - public function getData( $dumb = false ) {
51 - return serialize(
52 - array(
53 - 'source' => $this->_filename,
54 - 'data' => $this->_data,
55 - )
56 - );
41 + public function getData() {
42 + return serialize( array(
43 + 'source' => $this->_filename,
44 + 'data' => $this->_data,
45 + ) );
57 46 }
58 47
59 48 /**
60 49 * Re populates data and series.
@@ -66,9 +55,9 @@
66 55 * @return boolean TRUE on success, otherwise FALSE.
67 56 */
68 57 private function _repopulate( $chart_id ) {
69 58 // if it has been already populated, then just return true
70 - if ( ! empty( $this->_data ) && ! empty( $this->_series ) ) {
59 + if ( !empty( $this->_data ) && !empty( $this->_series ) ) {
71 60 return true;
72 61 }
73 62
74 63 // if filename is empty, extract it from chart content
@@ -73,10 +62,10 @@
73 62
74 63 // if filename is empty, extract it from chart content
75 64 if ( empty( $this->_filename ) ) {
76 65 $chart = get_post( $chart_id );
77 - $data = Visualizer_Module::decode_content( html_entity_decode( $chart->post_content ) );
78 - if ( ! isset( $data['source'] ) ) {
66 + $data = unserialize( $chart->post_content );
67 + if ( !isset( $data['source'] ) ) {
79 68 return false;
80 69 }
81 70
82 71 $this->_filename = $data['source'];
@@ -92,16 +81,13 @@
92 81 * @since 1.1.0
93 82 *
94 83 * @access public
95 84 * @param array $data The actual array of data.
96 - * @param int $chart_id The chart id.
85 + * @param int $chart_id The chart id.
97 86 * @return array The re populated array of data or old one.
98 87 */
99 88 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;
89 + return $this->_repopulate( $chart_id ) ? $this->_data : $data;
104 90 }
105 91
106 92 /**
107 93 * Re populates series.
@@ -109,13 +95,13 @@
109 95 * @since 1.1.0
110 96 *
111 97 * @access public
112 98 * @param array $series The actual array of series.
113 - * @param int $chart_id The chart id.
99 + * @param int $chart_id The chart id.
114 100 * @return array The re populated array of series or old one.
115 101 */
116 102 public function repopulateSeries( $series, $chart_id ) {
117 - return $series;
103 + return $this->_repopulate( $chart_id ) ? $this->_series : $series;
118 104 }
119 105
120 106 /**
121 107 * Returns source name.
@@ -128,45 +114,5 @@
128 114 public function getSourceName() {
129 115 return __CLASS__;
130 116 }
131 117
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 - /**
150 - * Returns file handle to fetch data from.
151 - *
152 - * @since 1.4.2
153 - *
154 - * @access protected
155 - * @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.
157 - */
158 - protected function _get_file_handle( $filename = false ) {
159 - if ( $this->_tmpfile && is_readable( $this->_tmpfile ) ) {
160 - return parent::_get_file_handle( $this->_tmpfile );
161 - }
162 -
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;
167 - }
168 -
169 - $this->_tmpfile = $tmpfile;
170 - return parent::_get_file_handle( $this->_tmpfile );
171 - }
172 -}
118 +}