Skip to content

Commit 909ec6e

Browse files
author
Eugene Manuilov
committed
Fixed remote CSV uploading issue when allow_url_fopen option is disabled in php.ini
1 parent 2b3831b commit 909ec6e

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

classes/Visualizer/Source/Csv.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ private function _fetchSeries( &$handle ) {
9393
return true;
9494
}
9595

96+
/**
97+
* Returns file handle to fetch data from.
98+
*
99+
* @since 1.4.2
100+
*
101+
* @access protected
102+
* @param string $filename Optional file name to get handle. If omitted, $_filename is used.
103+
* @return resource File handle resource on success, otherwise FALSE.
104+
*/
105+
protected function _get_file_handle( $filename = false ) {
106+
// set line endings auto detect mode
107+
@ini_set( 'auto_detect_line_endings', true );
108+
// open file and return handle
109+
return fopen( $filename ? $filename : $this->_filename, 'rb' );
110+
}
111+
96112
/**
97113
* Fetches information from source, parses it and builds series and data arrays.
98114
*
@@ -107,11 +123,8 @@ public function fetch() {
107123
return false;
108124
}
109125

110-
// set line endings auto detect mode
111-
@ini_set( 'auto_detect_line_endings', true );
112-
113126
// read file and fill arrays
114-
$handle = fopen( $this->_filename, 'rb' );
127+
$handle = $this->_get_file_handle();
115128
if ( $handle ) {
116129
// fetch series
117130
if ( !$this->_fetchSeries( $handle ) ) {

classes/Visualizer/Source/Csv/Remote.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,25 @@ public function getSourceName() {
115115
return __CLASS__;
116116
}
117117

118+
/**
119+
* Returns file handle to fetch data from.
120+
*
121+
* @since 1.4.2
122+
*
123+
* @access protected
124+
* @param string $filename Optional file name to get handle. If omitted, $_filename is used.
125+
* @return resource File handle resource on success, otherwise FALSE.
126+
*/
127+
protected function _get_file_handle( $filename = false ) {
128+
$scheme = parse_url( $this->_filename, PHP_URL_SCHEME );
129+
$allow_url_fopen = filter_var( ini_get( 'allow_url_fopen' ), FILTER_VALIDATE_BOOLEAN );
130+
if ( $allow_url_fopen && in_array( $scheme, stream_get_wrappers() ) ) {
131+
return parent::_get_file_handle( $filename );
132+
}
133+
134+
$filename = download_url( $this->_filename );
135+
136+
return !is_wp_error( $filename ) ? parent::_get_file_handle( $filename ) : false;
137+
}
138+
118139
}

readme.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ Pay attention that to turn your shortcodes into graphs, your theme has to have `
5858

5959
== Changelog ==
6060

61+
= 1.4.2 =
62+
* Fixed remote CSV uploading issue when allow_url_fopen option is disabled in php.ini
63+
6164
= 1.4.1.1 =
6265
* Removed CSV parser escape constant to prevent warnings which appears when PHP 5.2.x or less is used
6366

0 commit comments

Comments
 (0)