| @@ -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 |
| @@ -47,14 +48,12 @@ | ||
| 47 | 48 | * @access public |
| 48 | 49 | * @return string The serialized array of data. |
| 49 | 50 | */ |
| 50 | 51 | public function getData() { |
| 51 | - return serialize( | |
| 52 | - array( | |
| 53 | - 'source' => $this->_filename, | |
| 54 | - 'data' => $this->_data, | |
| 55 | - ) | |
| 56 | - ); | |
| 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,13 +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 | - return array_key_exists( 'data', $data ) ? $data['data'] : $data; | |
| 99 | + return $this->_repopulate( $chart_id ) ? $this->_data : $data; | |
| 101 | 100 | } |
| 102 | 101 | |
| 103 | 102 | /** |
| 104 | 103 | * Re populates series. |
| @@ -106,13 +105,13 @@ | ||
| 106 | 105 | * @since 1.1.0 |
| 107 | 106 | * |
| 108 | 107 | * @access public |
| 109 | 108 | * @param array $series The actual array of series. |
| 110 | - * @param int $chart_id The chart id. | |
| 109 | + * @param int $chart_id The chart id. | |
| 111 | 110 | * @return array The re populated array of series or old one. |
| 112 | 111 | */ |
| 113 | 112 | public function repopulateSeries( $series, $chart_id ) { |
| 114 | - return $series; | |
| 113 | + return $this->_repopulate( $chart_id ) ? $this->_series : $series; | |
| 115 | 114 | } |
| 116 | 115 | |
| 117 | 116 | /** |
| 118 | 117 | * Returns source name. |
| @@ -138,9 +137,9 @@ | ||
| 138 | 137 | */ |
| 139 | 138 | protected function _get_file_handle( $filename = false ) { |
| 140 | 139 | static $allow_url_fopen = null; |
| 141 | 140 | |
| 142 | - if ( ! is_wp_error( $this->_tmpfile ) && $this->_tmpfile && is_readable( $this->_tmpfile ) ) { | |
| 141 | + if ( $this->_tmpfile && is_readable( $this->_tmpfile ) ) { | |
| 143 | 142 | return parent::_get_file_handle( $this->_tmpfile ); |
| 144 | 143 | } |
| 145 | 144 | |
| 146 | 145 | if ( is_null( $allow_url_fopen ) ) { |
| @@ -155,8 +154,8 @@ | ||
| 155 | 154 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 156 | 155 | |
| 157 | 156 | $this->_tmpfile = download_url( $this->_filename ); |
| 158 | 157 | |
| 159 | - 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; | |
| 160 | 159 | } |
| 161 | 160 | |
| 162 | -} | |
| 161 | +} | |