| @@ -130,9 +130,9 @@ | ||
| 130 | 130 | $source = new Visualizer_Source_Json( $params ); |
| 131 | 131 | |
| 132 | 132 | $roots = $source->fetchRoots(); |
| 133 | 133 | if ( empty( $roots ) ) { |
| 134 | - wp_send_json_error(); | |
| 134 | + wp_send_json_error( array( 'msg' => $source->get_error() ) ); | |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | wp_send_json_success( array( 'url' => $params['url'], 'roots' => $roots ) ); |
| 138 | 138 | } |
| @@ -158,9 +158,9 @@ | ||
| 158 | 158 | $source = new Visualizer_Source_Json( $params ); |
| 159 | 159 | |
| 160 | 160 | $data = $source->parse(); |
| 161 | 161 | if ( empty( $data ) ) { |
| 162 | - wp_send_json_error(); | |
| 162 | + wp_send_json_error( array( 'msg' => esc_html__( 'Unable to fetch data from the endpoint. Please try again.', 'visualizer' ) ) ); | |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | $data = Visualizer_Render_Layout::show( 'editor-table', $data, $chart_id, 'viz-json-table', false, false ); |
| 166 | 166 | wp_send_json_success( array( 'table' => $data, 'root' => $params['root'], 'url' => $params['url'], 'paging' => $source->getPaginationElements() ) ); |
| @@ -379,9 +379,9 @@ | ||
| 379 | 379 | 'success' => $success, |
| 380 | 380 | ) |
| 381 | 381 | ); |
| 382 | 382 | } |
| 383 | - wp_redirect( wp_get_referer() ); | |
| 383 | + wp_redirect( remove_query_arg( 'vaction', wp_get_referer() ) ); | |
| 384 | 384 | exit; |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | /** |
| @@ -455,10 +455,17 @@ | ||
| 455 | 455 | wp_redirect( add_query_arg( 'chart', (int) $chart_id ) ); |
| 456 | 456 | defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); |
| 457 | 457 | } |
| 458 | 458 | |
| 459 | - $this->load_chart_type( $chart_id ); | |
| 459 | + $lib = $this->load_chart_type( $chart_id ); | |
| 460 | 460 | |
| 461 | + // the alpha color picker (RGBA) is not supported by google. | |
| 462 | + $color_picker_dep = 'wp-color-picker'; | |
| 463 | + if ( in_array( $lib, array( 'chartjs', 'datatables' ), true ) && ! wp_script_is( 'wp-color-picker-alpha', 'registered' ) ) { | |
| 464 | + wp_register_script( 'wp-color-picker-alpha', VISUALIZER_ABSURL . 'js/lib/wp-color-picker-alpha.min.js', array( 'wp-color-picker' ), Visualizer_Plugin::VERSION ); | |
| 465 | + $color_picker_dep = 'wp-color-picker-alpha'; | |
| 466 | + } | |
| 467 | + | |
| 461 | 468 | // enqueue and register scripts and styles |
| 462 | 469 | wp_register_script( 'visualizer-chosen', VISUALIZER_ABSURL . 'js/lib/chosen.jquery.min.js', array( 'jquery' ), Visualizer_Plugin::VERSION ); |
| 463 | 470 | wp_register_style( 'visualizer-chosen', VISUALIZER_ABSURL . 'css/lib/chosen.min.css', array(), Visualizer_Plugin::VERSION ); |
| 464 | 471 | |
| @@ -475,9 +482,9 @@ | ||
| 475 | 482 | wp_register_script( |
| 476 | 483 | 'visualizer-preview', |
| 477 | 484 | VISUALIZER_ABSURL . 'js/preview.js', |
| 478 | 485 | array( |
| 479 | - 'wp-color-picker', | |
| 486 | + $color_picker_dep, | |
| 480 | 487 | 'visualizer-render', |
| 481 | 488 | ), |
| 482 | 489 | Visualizer_Plugin::VERSION, |
| 483 | 490 | true |
| @@ -483,10 +490,11 @@ | ||
| 483 | 490 | true |
| 484 | 491 | ); |
| 485 | 492 | wp_register_script( 'visualizer-editor-simple', VISUALIZER_ABSURL . 'js/simple-editor.js', array( 'jquery' ), Visualizer_Plugin::VERSION, true ); |
| 486 | 493 | |
| 487 | - // added by Ash/Upwork | |
| 488 | - if ( VISUALIZER_PRO ) { | |
| 494 | + do_action( 'visualizer_add_scripts' ); | |
| 495 | + | |
| 496 | + if ( Visualizer_Module::is_pro() && Visualizer_Module::is_pro_older_than( '1.9.0' ) ) { | |
| 489 | 497 | global $Visualizer_Pro; |
| 490 | 498 | $Visualizer_Pro->_addScriptsAndStyles(); |
| 491 | 499 | } |
| 492 | 500 | |
| @@ -533,15 +541,15 @@ | ||
| 533 | 541 | |
| 534 | 542 | $wp_scripts = wp_scripts(); |
| 535 | 543 | |
| 536 | 544 | // data tables assets. |
| 537 | - wp_register_script( 'visualizer-datatables', '//cdn.datatables.net/v/dt/dt-1.10.18/b-1.5.6/b-colvis-1.5.6/cr-1.5.0/fc-3.2.5/fh-3.1.4/r-2.2.2/sc-2.0.0/sl-1.3.0/datatables.min.js', array( 'jquery-ui-core' ), Visualizer_Plugin::VERSION ); | |
| 538 | - wp_register_style( 'visualizer-datatables', '//cdn.datatables.net/v/dt/dt-1.10.18/b-1.5.6/b-colvis-1.5.6/cr-1.5.0/fc-3.2.5/fh-3.1.4/r-2.2.2/sc-2.0.0/sl-1.3.0/datatables.min.css', array(), Visualizer_Plugin::VERSION ); | |
| 545 | + wp_register_script( 'visualizer-datatables', VISUALIZER_ABSURL . 'js/lib/datatables.min.js', array( 'jquery-ui-core' ), Visualizer_Plugin::VERSION ); | |
| 546 | + wp_register_style( 'visualizer-datatables', VISUALIZER_ABSURL . 'css/lib/datatables.min.css', array(), Visualizer_Plugin::VERSION ); | |
| 539 | 547 | wp_register_style( 'visualizer-jquery-ui', sprintf( '//ajax.googleapis.com/ajax/libs/jqueryui/%s/themes/smoothness/jquery-ui.css', $wp_scripts->registered['jquery-ui-core']->ver ), array( 'visualizer-datatables' ), Visualizer_Plugin::VERSION ); |
| 540 | 548 | wp_enqueue_script( 'visualizer-datatables' ); |
| 541 | 549 | wp_enqueue_style( 'visualizer-jquery-ui' ); |
| 542 | 550 | |
| 543 | - if ( ! VISUALIZER_PRO ) { | |
| 551 | + if ( ! Visualizer_Module::is_pro() ) { | |
| 544 | 552 | return; |
| 545 | 553 | } |
| 546 | 554 | |
| 547 | 555 | $table_col_mapping = Visualizer_Source_Query_Params::get_all_db_tables_column_mapping(); |
| @@ -598,8 +606,24 @@ | ||
| 598 | 606 | } |
| 599 | 607 | // save meta data only when it is NOT being canceled. |
| 600 | 608 | if ( ! ( isset( $_POST['cancel'] ) && 1 === intval( $_POST['cancel'] ) ) ) { |
| 601 | 609 | update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $_POST ); |
| 610 | + | |
| 611 | + // we will keep a parameter called 'internal_title' that will be set to the given title or, if empty, the chart ID | |
| 612 | + // this will help in searching with the chart id. | |
| 613 | + $settings = get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, true ); | |
| 614 | + $title = null; | |
| 615 | + if ( isset( $settings['title'] ) && ! empty( $settings['title'] ) ) { | |
| 616 | + $title = $settings['title']; | |
| 617 | + if ( is_array( $title ) ) { | |
| 618 | + $title = $settings['title']['text']; | |
| 619 | + } | |
| 620 | + } | |
| 621 | + if ( empty( $title ) ) { | |
| 622 | + $title = $this->_chart->ID; | |
| 623 | + } | |
| 624 | + $settings['internal_title'] = $title; | |
| 625 | + update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $settings ); | |
| 602 | 626 | } |
| 603 | 627 | $render = new Visualizer_Render_Page_Send(); |
| 604 | 628 | $render->text = sprintf( '[visualizer id="%d"]', $this->_chart->ID ); |
| 605 | 629 | wp_iframe( array( $render, 'render' ) ); |
| @@ -607,9 +631,9 @@ | ||
| 607 | 631 | return; |
| 608 | 632 | } |
| 609 | 633 | $data = $this->_getChartArray(); |
| 610 | 634 | $sidebar = ''; |
| 611 | - $sidebar_class = 'Visualizer_Render_Sidebar_Type_' . ucfirst( $data['type'] ); | |
| 635 | + $sidebar_class = $this->load_chart_class_name( $this->_chart->ID ); | |
| 612 | 636 | if ( class_exists( $sidebar_class, true ) ) { |
| 613 | 637 | $sidebar = new $sidebar_class( $data['settings'] ); |
| 614 | 638 | $sidebar->__series = $data['series']; |
| 615 | 639 | $sidebar->__data = $data['data']; |
| @@ -619,9 +643,9 @@ | ||
| 619 | 643 | $sidebar->__series = $data['series']; |
| 620 | 644 | $sidebar->__data = $data['data']; |
| 621 | 645 | } |
| 622 | 646 | } |
| 623 | - unset( $data['settings']['width'], $data['settings']['height'] ); | |
| 647 | + unset( $data['settings']['width'], $data['settings']['height'], $data['settings']['chartArea'] ); | |
| 624 | 648 | wp_enqueue_style( 'wp-color-picker' ); |
| 625 | 649 | wp_enqueue_style( 'visualizer-frame' ); |
| 626 | 650 | wp_enqueue_script( 'visualizer-preview' ); |
| 627 | 651 | wp_enqueue_script( 'visualizer-chosen' ); |
| @@ -626,9 +650,9 @@ | ||
| 626 | 650 | wp_enqueue_script( 'visualizer-preview' ); |
| 627 | 651 | wp_enqueue_script( 'visualizer-chosen' ); |
| 628 | 652 | wp_enqueue_script( 'visualizer-render' ); |
| 629 | 653 | |
| 630 | - if ( ! VISUALIZER_PRO ) { | |
| 654 | + if ( ! Visualizer_Module::is_pro() ) { | |
| 631 | 655 | wp_enqueue_script( 'visualizer-editor-simple' ); |
| 632 | 656 | wp_localize_script( |
| 633 | 657 | 'visualizer-editor-simple', |
| 634 | 658 | 'visualizer1', |
| @@ -680,9 +704,9 @@ | ||
| 680 | 704 | ), |
| 681 | 705 | 'db_query' => array( |
| 682 | 706 | 'tables' => $table_col_mapping, |
| 683 | 707 | ), |
| 684 | - 'is_pro' => VISUALIZER_PRO, | |
| 708 | + 'is_pro' => Visualizer_Module::is_pro(), | |
| 685 | 709 | 'page_type' => 'chart', |
| 686 | 710 | 'json_tag_separator' => Visualizer_Source_Json::TAG_SEPARATOR, |
| 687 | 711 | 'json_tag_separator_view' => Visualizer_Source_Json::TAG_SEPARATOR_VIEW, |
| 688 | 712 | 'is_front' => false, |
| @@ -703,12 +727,16 @@ | ||
| 703 | 727 | } |
| 704 | 728 | } else { |
| 705 | 729 | $render->button = esc_attr__( 'Insert Chart', 'visualizer' ); |
| 706 | 730 | } |
| 707 | - if ( VISUALIZER_PRO ) { | |
| 731 | + | |
| 732 | + do_action( 'visualizer_enqueue_scripts_and_styles', $data ); | |
| 733 | + | |
| 734 | + if ( Visualizer_Module::is_pro() && Visualizer_Module::is_pro_older_than( '1.9.0' ) ) { | |
| 708 | 735 | global $Visualizer_Pro; |
| 709 | 736 | $Visualizer_Pro->_enqueueScriptsAndStyles( $data ); |
| 710 | 737 | } |
| 738 | + | |
| 711 | 739 | $this->_addAction( 'admin_head', 'renderFlattrScript' ); |
| 712 | 740 | wp_iframe( array( $render, 'render' ) ); |
| 713 | 741 | } |
| 714 | 742 | |
| @@ -722,11 +750,19 @@ | ||
| 722 | 750 | private function _handleTypesPage() { |
| 723 | 751 | // process post request |
| 724 | 752 | if ( $_SERVER['REQUEST_METHOD'] === 'POST' && wp_verify_nonce( filter_input( INPUT_POST, 'nonce' ) ) ) { |
| 725 | 753 | $type = filter_input( INPUT_POST, 'type' ); |
| 754 | + $library = filter_input( INPUT_POST, 'chart-library' ); | |
| 726 | 755 | if ( in_array( $type, Visualizer_Plugin::getChartTypes(), true ) ) { |
| 756 | + if ( empty( $library ) ) { | |
| 757 | + // library cannot be empty. | |
| 758 | + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'Chart library empty while creating the chart! Aborting...', 'error', __FILE__, __LINE__ ); | |
| 759 | + return; | |
| 760 | + } | |
| 761 | + | |
| 727 | 762 | // save new chart type |
| 728 | 763 | update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_CHART_TYPE, $type ); |
| 764 | + update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_CHART_LIBRARY, $library ); | |
| 729 | 765 | // if the chart has default data, update it with appropriate default data for new type |
| 730 | 766 | if ( filter_var( get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, true ), FILTER_VALIDATE_BOOLEAN ) ) { |
| 731 | 767 | $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $type . '.csv' ); |
| 732 | 768 | $source->fetch(); |
| @@ -733,8 +769,11 @@ | ||
| 733 | 769 | $this->_chart->post_content = $source->getData(); |
| 734 | 770 | wp_update_post( $this->_chart->to_array() ); |
| 735 | 771 | update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); |
| 736 | 772 | } |
| 773 | + | |
| 774 | + Visualizer_Module_Utility::set_defaults( $this->_chart ); | |
| 775 | + | |
| 737 | 776 | // redirect to next tab |
| 738 | 777 | // changed by Ash/Upwork |
| 739 | 778 | wp_redirect( add_query_arg( 'tab', 'settings' ) ); |
| 740 | 779 | |
| @@ -742,9 +781,9 @@ | ||
| 742 | 781 | } |
| 743 | 782 | } |
| 744 | 783 | $render = new Visualizer_Render_Page_Types(); |
| 745 | 784 | $render->type = get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ); |
| 746 | - $render->types = Visualizer_Module_Admin::_getChartTypesLocalized(); | |
| 785 | + $render->types = Visualizer_Module_Admin::_getChartTypesLocalized( false, false, false, 'types' ); | |
| 747 | 786 | $render->chart = $this->_chart; |
| 748 | 787 | wp_enqueue_style( 'visualizer-frame' ); |
| 749 | 788 | wp_enqueue_script( 'visualizer-frame' ); |
| 750 | 789 | wp_iframe( array( $render, 'render' ) ); |
| @@ -768,9 +807,11 @@ | ||
| 768 | 807 | * @since 3.2.0 |
| 769 | 808 | */ |
| 770 | 809 | private function handleCSVasString( $data ) { |
| 771 | 810 | $source = null; |
| 772 | - if ( VISUALIZER_PRO ) { | |
| 811 | + | |
| 812 | + // @issue https://github.com/Codeinwp/visualizer/issues/412 | |
| 813 | + if ( has_filter( 'visualizer_pro_handle_chart_data' ) ) { | |
| 773 | 814 | $source = apply_filters( 'visualizer_pro_handle_chart_data', $data, '' ); |
| 774 | 815 | } else { |
| 775 | 816 | // data coming in from the text editor. |
| 776 | 817 | $tmpfile = tempnam( get_temp_dir(), Visualizer_Plugin::NAME ); |
| @@ -926,9 +967,9 @@ | ||
| 926 | 967 | $source = $this->handleCSVasString( $_POST['chart_data'] ); |
| 927 | 968 | } elseif ( isset( $_POST['table_data'] ) && 'yes' === $_POST['table_data'] ) { |
| 928 | 969 | $source = $this->handleTabularData(); |
| 929 | 970 | } else { |
| 930 | - $render->message = esc_html__( 'CSV file with chart data was not uploaded. Please, try again.', 'visualizer' ); | |
| 971 | + $render->message = esc_html__( 'CSV file with chart data was not uploaded. Please try again.', 'visualizer' ); | |
| 931 | 972 | } |
| 932 | 973 | if ( $source ) { |
| 933 | 974 | if ( $source->fetch() ) { |
| 934 | 975 | $content = $source->getData(); |
| @@ -948,13 +989,22 @@ | ||
| 948 | 989 | wp_update_post( $chart->to_array() ); |
| 949 | 990 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); |
| 950 | 991 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); |
| 951 | 992 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, 0 ); |
| 993 | + | |
| 994 | + Visualizer_Module_Utility::set_defaults( $chart, null ); | |
| 995 | + | |
| 996 | + $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true ); | |
| 997 | + | |
| 952 | 998 | $render->id = $chart->ID; |
| 953 | 999 | $render->data = json_encode( $source->getRawData() ); |
| 954 | 1000 | $render->series = json_encode( $source->getSeries() ); |
| 1001 | + $render->settings = json_encode( $settings ); | |
| 955 | 1002 | } else { |
| 956 | - $render->message = esc_html__( 'CSV file is broken or invalid. Please, try again.', 'visualizer' ); | |
| 1003 | + $render->message = $source->get_error(); | |
| 1004 | + if ( empty( $render->message ) ) { | |
| 1005 | + $render->message = esc_html__( 'CSV file is broken or invalid. Please try again.', 'visualizer' ); | |
| 1006 | + } | |
| 957 | 1007 | } |
| 958 | 1008 | } |
| 959 | 1009 | $render->render(); |
| 960 | 1010 | if ( ! $can_die ) { |
| @@ -989,9 +1039,9 @@ | ||
| 989 | 1039 | $chart = get_post( $chart_id ); |
| 990 | 1040 | $success = $chart && $chart->post_type === Visualizer_Plugin::CPT_VISUALIZER; |
| 991 | 1041 | } |
| 992 | 1042 | } |
| 993 | - $redirect = wp_get_referer(); | |
| 1043 | + $redirect = remove_query_arg( 'vaction', wp_get_referer() ); | |
| 994 | 1044 | if ( $success ) { |
| 995 | 1045 | $new_chart_id = wp_insert_post( |
| 996 | 1046 | array( |
| 997 | 1047 | 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, |
| @@ -1010,10 +1060,11 @@ | ||
| 1010 | 1060 | $redirect = add_query_arg( |
| 1011 | 1061 | array( |
| 1012 | 1062 | 'page' => 'visualizer', |
| 1013 | 1063 | 'type' => filter_input( INPUT_GET, 'type' ), |
| 1064 | + 'vaction' => false, | |
| 1014 | 1065 | ), |
| 1015 | - admin_url( 'upload.php' ) | |
| 1066 | + admin_url( 'admin.php' ) | |
| 1016 | 1067 | ); |
| 1017 | 1068 | } |
| 1018 | 1069 | } |
| 1019 | 1070 | wp_redirect( $redirect ); |
| @@ -1062,9 +1113,9 @@ | ||
| 1062 | 1113 | $data = $this->_getChartArray(); |
| 1063 | 1114 | $render = new Visualizer_Render_Page_Data(); |
| 1064 | 1115 | $render->chart = $this->_chart; |
| 1065 | 1116 | $render->type = $data['type']; |
| 1066 | - unset( $data['settings']['width'], $data['settings']['height'] ); | |
| 1117 | + unset( $data['settings']['width'], $data['settings']['height'], $data['settings']['chartArea'] ); | |
| 1067 | 1118 | wp_enqueue_style( 'visualizer-frame' ); |
| 1068 | 1119 | wp_enqueue_script( 'visualizer-render' ); |
| 1069 | 1120 | wp_localize_script( |
| 1070 | 1121 | 'visualizer-render', |
| @@ -1078,13 +1129,16 @@ | ||
| 1078 | 1129 | 'canvas' => $data, |
| 1079 | 1130 | ), |
| 1080 | 1131 | ) |
| 1081 | 1132 | ); |
| 1082 | - // Added by Ash/Upwork | |
| 1083 | - if ( VISUALIZER_PRO ) { | |
| 1133 | + | |
| 1134 | + do_action( 'visualizer_enqueue_scripts_and_styles', $data ); | |
| 1135 | + | |
| 1136 | + if ( Visualizer_Module::is_pro() && Visualizer_Module::is_pro_older_than( '1.9.0' ) ) { | |
| 1084 | 1137 | global $Visualizer_Pro; |
| 1085 | 1138 | $Visualizer_Pro->_enqueueScriptsAndStyles( $data ); |
| 1086 | 1139 | } |
| 1140 | + | |
| 1087 | 1141 | // Added by Ash/Upwork |
| 1088 | 1142 | $this->_addAction( 'admin_head', 'renderFlattrScript' ); |
| 1089 | 1143 | wp_iframe( array( $render, 'render' ) ); |
| 1090 | 1144 | } |