| @@ -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 |
| @@ -46,15 +47,13 @@ | ||
| 46 | 47 | * |
| 47 | 48 | * @access public |
| 48 | 49 | * @return string The serialized array of data. |
| 49 | 50 | */ |
| 50 | - public function getData( $dumb = false ) { | |
| 51 | - return serialize( | |
| 52 | - array( | |
| 53 | - 'source' => $this->_filename, | |
| 54 | - 'data' => $this->_data, | |
| 55 | - ) | |
| 56 | - ); | |
| 51 | + public function getData() { | |
| 52 | + return serialize( array( | |
| 53 | + 'source' => $this->_filename, | |
| 54 | + 'data' => $this->_data, | |
| 55 | + ) ); | |
| 57 | 56 | } |
| 58 | 57 | |
| 59 | 58 | /** |
| 60 | 59 | * Re populates data and series. |
| @@ -66,9 +65,9 @@ | ||
| 66 | 65 | * @return boolean TRUE on success, otherwise FALSE. |
| 67 | 66 | */ |
| 68 | 67 | private function _repopulate( $chart_id ) { |
| 69 | 68 | // if it has been already populated, then just return true |
| 70 | - if ( ! empty( $this->_data ) && ! empty( $this->_series ) ) { | |
| 69 | + if ( !empty( $this->_data ) && !empty( $this->_series ) ) { | |
| 71 | 70 | return true; |
| 72 | 71 | } |
| 73 | 72 | |
| 74 | 73 | // if filename is empty, extract it from chart content |
| @@ -73,10 +72,10 @@ | ||
| 73 | 72 | |
| 74 | 73 | // if filename is empty, extract it from chart content |
| 75 | 74 | if ( empty( $this->_filename ) ) { |
| 76 | 75 | $chart = get_post( $chart_id ); |
| 77 | - $data = unserialize( html_entity_decode( $chart->post_content ) ); | |
| 78 | - if ( ! isset( $data['source'] ) ) { | |
| 76 | + $data = unserialize( $chart->post_content ); | |
| 77 | + if ( !isset( $data['source'] ) ) { | |
| 79 | 78 | return false; |
| 80 | 79 | } |
| 81 | 80 | |
| 82 | 81 | $this->_filename = $data['source']; |
| @@ -92,16 +91,13 @@ | ||
| 92 | 91 | * @since 1.1.0 |
| 93 | 92 | * |
| 94 | 93 | * @access public |
| 95 | 94 | * @param array $data The actual array of data. |
| 96 | - * @param int $chart_id The chart id. | |
| 95 | + * @param int $chart_id The chart id. | |
| 97 | 96 | * @return array The re populated array of data or old one. |
| 98 | 97 | */ |
| 99 | 98 | 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; | |
| 99 | + return $this->_repopulate( $chart_id ) ? $this->_data : $data; | |
| 104 | 100 | } |
| 105 | 101 | |
| 106 | 102 | /** |
| 107 | 103 | * Re populates series. |
| @@ -109,13 +105,13 @@ | ||
| 109 | 105 | * @since 1.1.0 |
| 110 | 106 | * |
| 111 | 107 | * @access public |
| 112 | 108 | * @param array $series The actual array of series. |
| 113 | - * @param int $chart_id The chart id. | |
| 109 | + * @param int $chart_id The chart id. | |
| 114 | 110 | * @return array The re populated array of series or old one. |
| 115 | 111 | */ |
| 116 | 112 | public function repopulateSeries( $series, $chart_id ) { |
| 117 | - return $series; | |
| 113 | + return $this->_repopulate( $chart_id ) ? $this->_series : $series; | |
| 118 | 114 | } |
| 119 | 115 | |
| 120 | 116 | /** |
| 121 | 117 | * Returns source name. |
| @@ -141,9 +137,9 @@ | ||
| 141 | 137 | */ |
| 142 | 138 | protected function _get_file_handle( $filename = false ) { |
| 143 | 139 | static $allow_url_fopen = null; |
| 144 | 140 | |
| 145 | - if ( ! is_wp_error( $this->_tmpfile ) && $this->_tmpfile && is_readable( $this->_tmpfile ) ) { | |
| 141 | + if ( $this->_tmpfile && is_readable( $this->_tmpfile ) ) { | |
| 146 | 142 | return parent::_get_file_handle( $this->_tmpfile ); |
| 147 | 143 | } |
| 148 | 144 | |
| 149 | 145 | if ( is_null( $allow_url_fopen ) ) { |
| @@ -150,9 +146,9 @@ | ||
| 150 | 146 | $allow_url_fopen = filter_var( ini_get( 'allow_url_fopen' ), FILTER_VALIDATE_BOOLEAN ); |
| 151 | 147 | } |
| 152 | 148 | |
| 153 | 149 | $scheme = parse_url( $this->_filename, PHP_URL_SCHEME ); |
| 154 | - if ( $allow_url_fopen && in_array( $scheme, stream_get_wrappers(), true ) ) { | |
| 150 | + if ( $allow_url_fopen && in_array( $scheme, stream_get_wrappers() ) ) { | |
| 155 | 151 | return parent::_get_file_handle( $filename ); |
| 156 | 152 | } |
| 157 | 153 | |
| 158 | 154 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
| @@ -158,8 +154,8 @@ | ||
| 158 | 154 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 159 | 155 | |
| 160 | 156 | $this->_tmpfile = download_url( $this->_filename ); |
| 161 | 157 | |
| 162 | - return ! is_wp_error( $this->_tmpfile ) ? parent::_get_file_handle( $this->_tmpfile ) : false; | |
| 158 | + return !is_wp_error( $this->_tmpfile ) ? parent::_get_file_handle( $this->_tmpfile ) : false; | |
| 163 | 159 | } |
| 164 | 160 | |
| 165 | -} | |
| 161 | +} | |