PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 2.1.3
Visualizer – Tables & Charts Manager with Built-in AI Generator v2.1.3
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
visualizer / classes / Visualizer / Source / Csv / Remote.php

Remote.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 2.1.3, at classes/Visualizer/Source/Csv/Remote.php

161 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // +----------------------------------------------------------------------+
4 // | Copyright 2013 Madpixels (email : visualizer@madpixels.net) |
5 // +----------------------------------------------------------------------+
6 // | This program is free software; you can redistribute it and/or modify |
7 // | it under the terms of the GNU General Public License, version 2, as |
8 // | published by the Free Software Foundation. |
9 // | |
10 // | This program is distributed in the hope that it will be useful, |
11 // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 // | GNU General Public License for more details. |
14 // | |
15 // | You should have received a copy of the GNU General Public License |
16 // | along with this program; if not, write to the Free Software |
17 // | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
18 // | MA 02110-1301 USA |
19 // +----------------------------------------------------------------------+
20 // | Author: Eugene Manuilov <eugene@manuilov.org> |
21 // +----------------------------------------------------------------------+
22 /**
23 * Source manager for remote CSV files.
24 *
25 * @category Visualizer
26 * @package Source
27 *
28 * @since 1.1.0
29 */
30 class Visualizer_Source_Csv_Remote extends Visualizer_Source_Csv {
31
32 /**
33 * Temporary file name used when allow_url_fopen option is disabled.
34 *
35 * @since 1.4.2
36 *
37 * @access private
38 * @var string
39 */
40 private $_tmpfile = false;
41
42 /**
43 * Returns data parsed from source.
44 *
45 * @since 1.1.0
46 *
47 * @access public
48 * @return string The serialized array of data.
49 */
50 public function getData() {
51 return serialize( array(
52 'source' => $this->_filename,
53 'data' => $this->_data,
54 ) );
55 }
56
57 /**
58 * Re populates data and series.
59 *
60 * @since 1.1.0
61 *
62 * @access private
63 * @param int $chart_id The chart id.
64 * @return boolean TRUE on success, otherwise FALSE.
65 */
66 private function _repopulate( $chart_id ) {
67 // if it has been already populated, then just return true
68 if ( ! empty( $this->_data ) && ! empty( $this->_series ) ) {
69 return true;
70 }
71
72 // if filename is empty, extract it from chart content
73 if ( empty( $this->_filename ) ) {
74 $chart = get_post( $chart_id );
75 $data = unserialize( html_entity_decode( $chart->post_content ) );
76 if ( ! isset( $data['source'] ) ) {
77 return false;
78 }
79
80 $this->_filename = $data['source'];
81 }
82
83 // populate series and data information
84 return $this->fetch();
85 }
86
87 /**
88 * Re populates data.
89 *
90 * @since 1.1.0
91 *
92 * @access public
93 * @param array $data The actual array of data.
94 * @param int $chart_id The chart id.
95 * @return array The re populated array of data or old one.
96 */
97 public function repopulateData( $data, $chart_id ) {
98 return $this->_repopulate( $chart_id ) ? $this->_data : $data;
99 }
100
101 /**
102 * Re populates series.
103 *
104 * @since 1.1.0
105 *
106 * @access public
107 * @param array $series The actual array of series.
108 * @param int $chart_id The chart id.
109 * @return array The re populated array of series or old one.
110 */
111 public function repopulateSeries( $series, $chart_id ) {
112 return $this->_repopulate( $chart_id ) ? $this->_series : $series;
113 }
114
115 /**
116 * Returns source name.
117 *
118 * @since 1.0.0
119 *
120 * @access public
121 * @return string The name of source.
122 */
123 public function getSourceName() {
124 return __CLASS__;
125 }
126
127 /**
128 * Returns file handle to fetch data from.
129 *
130 * @since 1.4.2
131 *
132 * @access protected
133 * @staticvar boolean $allow_url_fopen Determines whether or not allow_url_fopen option is enabled.
134 * @param string $filename Optional file name to get handle. If omitted, $_filename is used.
135 * @return resource File handle resource on success, otherwise FALSE.
136 */
137 protected function _get_file_handle( $filename = false ) {
138 static $allow_url_fopen = null;
139
140 if ( ! is_wp_error( $this->_tmpfile ) && $this->_tmpfile && is_readable( $this->_tmpfile ) ) {
141 return parent::_get_file_handle( $this->_tmpfile );
142 }
143
144 if ( is_null( $allow_url_fopen ) ) {
145 $allow_url_fopen = filter_var( ini_get( 'allow_url_fopen' ), FILTER_VALIDATE_BOOLEAN );
146 }
147
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;
158 }
159
160 }
161