| @@ -71,9 +71,12 @@ | ||
| 71 | 71 | $query_args = array( |
| 72 | 72 | 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, |
| 73 | 73 | 'posts_per_page' => 9, |
| 74 | 74 | 'paged' => filter_input( |
| 75 | - INPUT_GET, 'page', FILTER_VALIDATE_INT, array( | |
| 75 | + INPUT_GET, | |
| 76 | + 'page', | |
| 77 | + FILTER_VALIDATE_INT, | |
| 78 | + array( | |
| 76 | 79 | 'options' => array( |
| 77 | 80 | 'min_range' => 1, |
| 78 | 81 | 'default' => 1, |
| 79 | 82 | ), |
| @@ -170,9 +173,12 @@ | ||
| 170 | 173 | $nonce = wp_verify_nonce( filter_input( $input_method, 'nonce' ) ); |
| 171 | 174 | $capable = current_user_can( 'delete_posts' ); |
| 172 | 175 | if ( $nonce && $capable ) { |
| 173 | 176 | $chart_id = filter_input( |
| 174 | - $input_method, 'chart', FILTER_VALIDATE_INT, array( | |
| 177 | + $input_method, | |
| 178 | + 'chart', | |
| 179 | + FILTER_VALIDATE_INT, | |
| 180 | + array( | |
| 175 | 181 | 'options' => array( |
| 176 | 182 | 'min_range' => 1, |
| 177 | 183 | ), |
| 178 | 184 | ) |
| @@ -226,9 +232,11 @@ | ||
| 226 | 232 | add_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 1 ); |
| 227 | 233 | add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); |
| 228 | 234 | add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); |
| 229 | 235 | add_post_meta( |
| 230 | - $chart_id, Visualizer_Plugin::CF_SETTINGS, array( | |
| 236 | + $chart_id, | |
| 237 | + Visualizer_Plugin::CF_SETTINGS, | |
| 238 | + array( | |
| 231 | 239 | 'focusTarget' => 'datum', |
| 232 | 240 | ) |
| 233 | 241 | ); |
| 234 | 242 | do_action( 'visualizer_pro_new_chart_defaults', $chart_id ); |
| @@ -243,20 +251,30 @@ | ||
| 243 | 251 | wp_register_style( 'visualizer-frame', VISUALIZER_ABSURL . 'css/frame.css', array( 'visualizer-chosen' ), Visualizer_Plugin::VERSION ); |
| 244 | 252 | wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'visualizer-chosen' ), Visualizer_Plugin::VERSION, true ); |
| 245 | 253 | wp_register_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true ); |
| 246 | 254 | wp_register_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true ); |
| 255 | + wp_register_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true ); | |
| 247 | 256 | wp_register_script( |
| 248 | - 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( | |
| 257 | + 'visualizer-render', | |
| 258 | + VISUALIZER_ABSURL . 'js/render.js', | |
| 259 | + array( | |
| 249 | 260 | 'google-jsapi-old', |
| 250 | 261 | 'google-jsapi-new', |
| 251 | 262 | 'visualizer-frame', |
| 252 | - ), Visualizer_Plugin::VERSION, true | |
| 263 | + 'visualizer-customization', | |
| 264 | + ), | |
| 265 | + Visualizer_Plugin::VERSION, | |
| 266 | + true | |
| 253 | 267 | ); |
| 254 | 268 | wp_register_script( |
| 255 | - 'visualizer-preview', VISUALIZER_ABSURL . 'js/preview.js', array( | |
| 269 | + 'visualizer-preview', | |
| 270 | + VISUALIZER_ABSURL . 'js/preview.js', | |
| 271 | + array( | |
| 256 | 272 | 'wp-color-picker', |
| 257 | 273 | 'visualizer-render', |
| 258 | - ), Visualizer_Plugin::VERSION, true | |
| 274 | + ), | |
| 275 | + Visualizer_Plugin::VERSION, | |
| 276 | + true | |
| 259 | 277 | ); |
| 260 | 278 | // added by Ash/Upwork |
| 261 | 279 | if ( VISUALIZER_PRO ) { |
| 262 | 280 | global $Visualizer_Pro; |
| @@ -306,11 +324,18 @@ | ||
| 306 | 324 | } |
| 307 | 325 | if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'] ) ) { |
| 308 | 326 | if ( $this->_chart->post_status == 'auto-draft' ) { |
| 309 | 327 | $this->_chart->post_status = 'publish'; |
| 328 | + | |
| 329 | + // ensure that a revision is not created. If a revision is created it will have the proper data and the parent of the revision will have default data. | |
| 330 | + // we do not want any difference in data so disable revisions temporarily. | |
| 331 | + add_filter( 'wp_revisions_to_keep', '__return_false' ); | |
| 310 | 332 | wp_update_post( $this->_chart->to_array() ); |
| 311 | 333 | } |
| 312 | - update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $_POST ); | |
| 334 | + // save meta data only when it is NOT being canceled. | |
| 335 | + if ( ! ( isset( $_POST['cancel'] ) && 1 === intval( $_POST['cancel'] ) ) ) { | |
| 336 | + update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $_POST ); | |
| 337 | + } | |
| 313 | 338 | $render = new Visualizer_Render_Page_Send(); |
| 314 | 339 | $render->text = sprintf( '[visualizer id="%d"]', $this->_chart->ID ); |
| 315 | 340 | wp_iframe( array( $render, 'render' ) ); |
| 316 | 341 | |
| @@ -336,9 +361,11 @@ | ||
| 336 | 361 | wp_enqueue_style( 'visualizer-frame' ); |
| 337 | 362 | wp_enqueue_script( 'visualizer-preview' ); |
| 338 | 363 | wp_enqueue_script( 'visualizer-render' ); |
| 339 | 364 | wp_localize_script( |
| 340 | - 'visualizer-render', 'visualizer', array( | |
| 365 | + 'visualizer-render', | |
| 366 | + 'visualizer', | |
| 367 | + array( | |
| 341 | 368 | 'l10n' => array( |
| 342 | 369 | 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ), |
| 343 | 370 | 'loading' => esc_html__( 'Loading...', 'visualizer' ), |
| 344 | 371 | ), |
| @@ -486,9 +513,22 @@ | ||
| 486 | 513 | $render->message = esc_html__( 'CSV file with chart data was not uploaded. Please, try again.', 'visualizer' ); |
| 487 | 514 | } |
| 488 | 515 | if ( $source ) { |
| 489 | 516 | if ( $source->fetch() ) { |
| 490 | - $chart->post_content = $source->getData(); | |
| 517 | + $content = $source->getData(); | |
| 518 | + $populate = true; | |
| 519 | + if ( is_string( $content ) && is_array( unserialize( $content ) ) ) { | |
| 520 | + $json = unserialize( $content ); | |
| 521 | + // if source exists, so should data. if source exists but data is blank, do not populate the chart. | |
| 522 | + // if we populate the data even if it is empty, the chart will show "Table has no columns". | |
| 523 | + if ( array_key_exists( 'source', $json ) && ! empty( $json['source'] ) && ( ! array_key_exists( 'data', $json ) || empty( $json['data'] ) ) ) { | |
| 524 | + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Not populating chart data as source exists (%s) but data is empty!', $json['source'] ), 'warn', __FILE__, __LINE__ ); | |
| 525 | + $populate = false; | |
| 526 | + } | |
| 527 | + } | |
| 528 | + if ( $populate ) { | |
| 529 | + $chart->post_content = $content; | |
| 530 | + } | |
| 491 | 531 | wp_update_post( $chart->to_array() ); |
| 492 | 532 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); |
| 493 | 533 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); |
| 494 | 534 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, 0 ); |
| @@ -517,9 +557,12 @@ | ||
| 517 | 557 | $nonce = wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ), Visualizer_Plugin::ACTION_CLONE_CHART ); |
| 518 | 558 | $capable = current_user_can( 'edit_posts' ); |
| 519 | 559 | if ( $nonce && $capable ) { |
| 520 | 560 | $chart_id = filter_input( |
| 521 | - INPUT_GET, 'chart', FILTER_VALIDATE_INT, array( | |
| 561 | + INPUT_GET, | |
| 562 | + 'chart', | |
| 563 | + FILTER_VALIDATE_INT, | |
| 564 | + array( | |
| 522 | 565 | 'options' => array( |
| 523 | 566 | 'min_range' => 1, |
| 524 | 567 | ), |
| 525 | 568 | ) |
| @@ -549,9 +592,10 @@ | ||
| 549 | 592 | $redirect = add_query_arg( |
| 550 | 593 | array( |
| 551 | 594 | 'page' => 'visualizer', |
| 552 | 595 | 'type' => filter_input( INPUT_GET, 'type' ), |
| 553 | - ), admin_url( 'upload.php' ) | |
| 596 | + ), | |
| 597 | + admin_url( 'upload.php' ) | |
| 554 | 598 | ); |
| 555 | 599 | } |
| 556 | 600 | } |
| 557 | 601 | wp_redirect( $redirect ); |
| @@ -569,9 +613,11 @@ | ||
| 569 | 613 | check_ajax_referer( Visualizer_Plugin::ACTION_EXPORT_DATA . Visualizer_Plugin::VERSION, 'security' ); |
| 570 | 614 | $capable = current_user_can( 'edit_posts' ); |
| 571 | 615 | if ( $capable ) { |
| 572 | 616 | $chart_id = isset( $_GET['chart'] ) ? filter_var( |
| 573 | - $_GET['chart'], FILTER_VALIDATE_INT, array( | |
| 617 | + $_GET['chart'], | |
| 618 | + FILTER_VALIDATE_INT, | |
| 619 | + array( | |
| 574 | 620 | 'options' => array( |
| 575 | 621 | 'min_range' => 1, |
| 576 | 622 | ), |
| 577 | 623 | ) |
| @@ -602,9 +648,11 @@ | ||
| 602 | 648 | unset( $data['settings']['width'], $data['settings']['height'] ); |
| 603 | 649 | wp_enqueue_style( 'visualizer-frame' ); |
| 604 | 650 | wp_enqueue_script( 'visualizer-render' ); |
| 605 | 651 | wp_localize_script( |
| 606 | - 'visualizer-render', 'visualizer', array( | |
| 652 | + 'visualizer-render', | |
| 653 | + 'visualizer', | |
| 654 | + array( | |
| 607 | 655 | 'l10n' => array( |
| 608 | 656 | 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ), |
| 609 | 657 | 'loading' => esc_html__( 'Loading...', 'visualizer' ), |
| 610 | 658 | ), |