PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 1.5.3
Visualizer – Tables & Charts Manager with Built-in AI Generator v1.5.3
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 +161 -164 4.0.31.5.3 View file →
@@ -1,164 +1,161 @@
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( $dumb = false ) {
51 - return serialize(
52 - array(
53 - 'source' => $this->_filename,
54 - 'data' => $this->_data,
55 - )
56 - );
57 - }
58 -
59 - /**
60 - * Re populates data and series.
61 - *
62 - * @since 1.1.0
63 - *
64 - * @access private
65 - * @param int $chart_id The chart id.
66 - * @return boolean TRUE on success, otherwise FALSE.
67 - */
68 - private function _repopulate( $chart_id ) {
69 - // if it has been already populated, then just return true
70 - if ( ! empty( $this->_data ) && ! empty( $this->_series ) ) {
71 - return true;
72 - }
73 -
74 - // if filename is empty, extract it from chart content
75 - if ( empty( $this->_filename ) ) {
76 - $chart = get_post( $chart_id );
77 - $data = unserialize( html_entity_decode( $chart->post_content ) );
78 - if ( ! isset( $data['source'] ) ) {
79 - return false;
80 - }
81 -
82 - $this->_filename = $data['source'];
83 - }
84 -
85 - // populate series and data information
86 - return $this->fetch();
87 - }
88 -
89 - /**
90 - * Re populates data.
91 - *
92 - * @since 1.1.0
93 - *
94 - * @access public
95 - * @param array $data The actual array of data.
96 - * @param int $chart_id The chart id.
97 - * @return array The re populated array of data or old one.
98 - */
99 - 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;
104 - }
105 -
106 - /**
107 - * Re populates series.
108 - *
109 - * @since 1.1.0
110 - *
111 - * @access public
112 - * @param array $series The actual array of series.
113 - * @param int $chart_id The chart id.
114 - * @return array The re populated array of series or old one.
115 - */
116 - public function repopulateSeries( $series, $chart_id ) {
117 - return $series;
118 - }
119 -
120 - /**
121 - * Returns source name.
122 - *
123 - * @since 1.0.0
124 - *
125 - * @access public
126 - * @return string The name of source.
127 - */
128 - public function getSourceName() {
129 - return __CLASS__;
130 - }
131 -
132 - /**
133 - * Returns file handle to fetch data from.
134 - *
135 - * @since 1.4.2
136 - *
137 - * @access protected
138 - * @staticvar boolean $allow_url_fopen Determines whether or not allow_url_fopen option is enabled.
139 - * @param string $filename Optional file name to get handle. If omitted, $_filename is used.
140 - * @return resource File handle resource on success, otherwise FALSE.
141 - */
142 - 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 ) ) {
146 - return parent::_get_file_handle( $this->_tmpfile );
147 - }
148 -
149 - if ( is_null( $allow_url_fopen ) ) {
150 - $allow_url_fopen = filter_var( ini_get( 'allow_url_fopen' ), FILTER_VALIDATE_BOOLEAN );
151 - }
152 -
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;
163 - }
164 -}
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 +/**
24 + * Source manager for remote CSV files.
25 + *
26 + * @category Visualizer
27 + * @package Source
28 + *
29 + * @since 1.1.0
30 + */
31 +class Visualizer_Source_Csv_Remote extends Visualizer_Source_Csv {
32 +
33 + /**
34 + * Temporary file name used when allow_url_fopen option is disabled.
35 + *
36 + * @since 1.4.2
37 + *
38 + * @access private
39 + * @var string
40 + */
41 + private $_tmpfile = false;
42 +
43 + /**
44 + * Returns data parsed from source.
45 + *
46 + * @since 1.1.0
47 + *
48 + * @access public
49 + * @return string The serialized array of data.
50 + */
51 + public function getData() {
52 + return serialize( array(
53 + 'source' => $this->_filename,
54 + 'data' => $this->_data,
55 + ) );
56 + }
57 +
58 + /**
59 + * Re populates data and series.
60 + *
61 + * @since 1.1.0
62 + *
63 + * @access private
64 + * @param int $chart_id The chart id.
65 + * @return boolean TRUE on success, otherwise FALSE.
66 + */
67 + private function _repopulate( $chart_id ) {
68 + // if it has been already populated, then just return true
69 + if ( !empty( $this->_data ) && !empty( $this->_series ) ) {
70 + return true;
71 + }
72 +
73 + // if filename is empty, extract it from chart content
74 + if ( empty( $this->_filename ) ) {
75 + $chart = get_post( $chart_id );
76 + $data = unserialize( $chart->post_content );
77 + if ( !isset( $data['source'] ) ) {
78 + return false;
79 + }
80 +
81 + $this->_filename = $data['source'];
82 + }
83 +
84 + // populate series and data information
85 + return $this->fetch();
86 + }
87 +
88 + /**
89 + * Re populates data.
90 + *
91 + * @since 1.1.0
92 + *
93 + * @access public
94 + * @param array $data The actual array of data.
95 + * @param int $chart_id The chart id.
96 + * @return array The re populated array of data or old one.
97 + */
98 + public function repopulateData( $data, $chart_id ) {
99 + return $this->_repopulate( $chart_id ) ? $this->_data : $data;
100 + }
101 +
102 + /**
103 + * Re populates series.
104 + *
105 + * @since 1.1.0
106 + *
107 + * @access public
108 + * @param array $series The actual array of series.
109 + * @param int $chart_id The chart id.
110 + * @return array The re populated array of series or old one.
111 + */
112 + public function repopulateSeries( $series, $chart_id ) {
113 + return $this->_repopulate( $chart_id ) ? $this->_series : $series;
114 + }
115 +
116 + /**
117 + * Returns source name.
118 + *
119 + * @since 1.0.0
120 + *
121 + * @access public
122 + * @return string The name of source.
123 + */
124 + public function getSourceName() {
125 + return __CLASS__;
126 + }
127 +
128 + /**
129 + * Returns file handle to fetch data from.
130 + *
131 + * @since 1.4.2
132 + *
133 + * @access protected
134 + * @staticvar boolean $allow_url_fopen Determines whether or not allow_url_fopen option is enabled.
135 + * @param string $filename Optional file name to get handle. If omitted, $_filename is used.
136 + * @return resource File handle resource on success, otherwise FALSE.
137 + */
138 + protected function _get_file_handle( $filename = false ) {
139 + static $allow_url_fopen = null;
140 +
141 + if ( $this->_tmpfile && is_readable( $this->_tmpfile ) ) {
142 + return parent::_get_file_handle( $this->_tmpfile );
143 + }
144 +
145 + if ( is_null( $allow_url_fopen ) ) {
146 + $allow_url_fopen = filter_var( ini_get( 'allow_url_fopen' ), FILTER_VALIDATE_BOOLEAN );
147 + }
148 +
149 + $scheme = parse_url( $this->_filename, PHP_URL_SCHEME );
150 + if ( $allow_url_fopen && in_array( $scheme, stream_get_wrappers() ) ) {
151 + return parent::_get_file_handle( $filename );
152 + }
153 +
154 + require_once ABSPATH . 'wp-admin/includes/file.php';
155 +
156 + $this->_tmpfile = download_url( $this->_filename );
157 +
158 + return !is_wp_error( $this->_tmpfile ) ? parent::_get_file_handle( $this->_tmpfile ) : false;
159 + }
160 +
161 +}