| @@ -90,13 +90,17 @@ | ||
| 90 | 90 | if ( is_null( $chart ) ) { |
| 91 | 91 | $chart = $this->_chart; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | + $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ); | |
| 95 | + $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type ); | |
| 96 | + $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( $chart->post_content ), $chart->ID, $type ); | |
| 97 | + | |
| 94 | 98 | return array( |
| 95 | - 'type' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ), | |
| 96 | - 'series' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), | |
| 99 | + 'type' => $type, | |
| 100 | + 'series' => $series, | |
| 97 | 101 | 'settings' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true ), |
| 98 | - 'data' => unserialize( $chart->post_content ), | |
| 102 | + 'data' => $data, | |
| 99 | 103 | ); |
| 100 | 104 | } |
| 101 | 105 | |
| 102 | 106 | /** |
| @@ -307,8 +311,12 @@ | ||
| 307 | 311 | |
| 308 | 312 | wp_enqueue_style( 'visualizer-frame' ); |
| 309 | 313 | wp_enqueue_script( 'visualizer-render' ); |
| 310 | 314 | wp_localize_script( 'visualizer-render', 'visualizer', array( |
| 315 | + 'l10n' => array( | |
| 316 | + 'remotecsv_prompt' => esc_html__( 'Please, enter the URL of CSV file:', Visualizer_Plugin::NAME ), | |
| 317 | + 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', Visualizer_Plugin::NAME ), | |
| 318 | + ), | |
| 311 | 319 | 'charts' => array( |
| 312 | 320 | 'canvas' => $data, |
| 313 | 321 | ), |
| 314 | 322 | ) ); |
| @@ -395,13 +403,19 @@ | ||
| 395 | 403 | status_header( 400 ); |
| 396 | 404 | exit; |
| 397 | 405 | } |
| 398 | 406 | |
| 407 | + $source = null; | |
| 399 | 408 | $render = new Visualizer_Render_Page_Update(); |
| 400 | - if ( !isset( $_FILES['data'] ) || $_FILES['data']['error'] != 0 ) { | |
| 409 | + if ( filter_input( INPUT_POST, 'remote_data', FILTER_VALIDATE_URL ) ) { | |
| 410 | + $source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] ); | |
| 411 | + } elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) { | |
| 412 | + $source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] ); | |
| 413 | + } else { | |
| 401 | 414 | $render->message = esc_html__( "CSV file with chart data was not uploaded. Please, try again.", Visualizer_Plugin::NAME ); |
| 402 | - } else { | |
| 403 | - $source = new Visualizer_Source_Csv( $_FILES['data']['tmp_name'] ); | |
| 415 | + } | |
| 416 | + | |
| 417 | + if ( $source ) { | |
| 404 | 418 | if ( $source->fetch() ) { |
| 405 | 419 | $chart->post_content = $source->getData(); |
| 406 | 420 | wp_update_post( $chart->to_array() ); |
| 407 | 421 | |
| @@ -408,12 +422,12 @@ | ||
| 408 | 422 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); |
| 409 | 423 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); |
| 410 | 424 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, 0 ); |
| 411 | 425 | |
| 412 | - $render->data = json_encode( unserialize( $source->getData() ) ); | |
| 426 | + $render->data = json_encode( $source->getRawData() ); | |
| 413 | 427 | $render->series = json_encode( $source->getSeries() ); |
| 414 | 428 | } else { |
| 415 | - $render->message = esc_html__( "CSV file is broken or incorrect. Please, try again.", Visualizer_Plugin::NAME ); | |
| 429 | + $render->message = esc_html__( "CSV file is broken or invalid. Please, try again.", Visualizer_Plugin::NAME ); | |
| 416 | 430 | } |
| 417 | 431 | } |
| 418 | 432 | |
| 419 | 433 | $render->render(); |