| @@ -751,9 +751,9 @@ | ||
| 751 | 751 | 'lineWrapping' => true, |
| 752 | 752 | 'dragDrop' => false, |
| 753 | 753 | 'matchBrackets' => true, |
| 754 | 754 | 'autoCloseBrackets' => true, |
| 755 | - 'extraKeys' => array( 'Ctrl-Space' => 'autocomplete' ), | |
| 755 | + 'extraKeys' => array( 'Shift-Space' => 'autocomplete' ), | |
| 756 | 756 | 'hintOptions' => array( 'tables' => $table_col_mapping ), |
| 757 | 757 | ), |
| 758 | 758 | ) |
| 759 | 759 | ); |
| @@ -787,9 +787,12 @@ | ||
| 787 | 787 | update_option( 'visualizer-map-api-key', $_POST['map_api_key'] ); |
| 788 | 788 | } |
| 789 | 789 | |
| 790 | 790 | if ( $_SERVER['REQUEST_METHOD'] === 'POST' && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'] ) ) { |
| 791 | - if ( $this->_chart->post_status === 'auto-draft' ) { | |
| 791 | + $is_canceled = isset( $_POST['cancel'] ) && 1 === intval( $_POST['cancel'] ); | |
| 792 | + $is_newly_created = $this->_chart->post_status === 'auto-draft'; | |
| 793 | + | |
| 794 | + if ( $is_newly_created && ! $is_canceled ) { | |
| 792 | 795 | $this->_chart->post_status = 'publish'; |
| 793 | 796 | |
| 794 | 797 | // 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. |
| 795 | 798 | // we do not want any difference in data so disable revisions temporarily. |
| @@ -797,9 +800,9 @@ | ||
| 797 | 800 | |
| 798 | 801 | wp_update_post( $this->_chart->to_array() ); |
| 799 | 802 | } |
| 800 | 803 | // save meta data only when it is NOT being canceled. |
| 801 | - if ( ! ( isset( $_POST['cancel'] ) && 1 === intval( $_POST['cancel'] ) ) ) { | |
| 804 | + if ( ! $is_canceled ) { | |
| 802 | 805 | update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $_POST ); |
| 803 | 806 | |
| 804 | 807 | // we will keep a parameter called 'internal_title' that will be set to the given title or, if empty, the chart ID |
| 805 | 808 | // this will help in searching with the chart id. |
| @@ -873,12 +876,13 @@ | ||
| 873 | 876 | 'visualizer', |
| 874 | 877 | array( |
| 875 | 878 | 'l10n' => array( |
| 876 | 879 | 'invalid_source' => esc_html__( 'You have entered an invalid URL. Please provide a valid URL.', 'visualizer' ), |
| 877 | - 'loading' => esc_html__( 'Loading...', 'visualizer' ), | |
| 878 | - 'json_error' => esc_html__( 'An error occured in fetching data.', 'visualizer' ), | |
| 879 | - 'select_columns' => esc_html__( 'Please select a few columns to include in the chart.', 'visualizer' ), | |
| 880 | - 'save_settings' => __( 'You have modified the chart\'s settings. To modify the source/data again, you must save this chart and reopen it for editing. If you continue without saving the chart, you may lose your changes.', 'visualizer' ), | |
| 880 | + 'loading' => esc_html__( 'Loading...', 'visualizer' ), | |
| 881 | + 'json_error' => esc_html__( 'An error occured in fetching data.', 'visualizer' ), | |
| 882 | + 'select_columns' => esc_html__( 'Please select a few columns to include in the chart.', 'visualizer' ), | |
| 883 | + 'save_settings' => __( 'You have modified the chart\'s settings. To modify the source/data again, you must save this chart and reopen it for editing. If you continue without saving the chart, you may lose your changes.', 'visualizer' ), | |
| 884 | + 'copied' => __( 'The data has been copied to your clipboard. Hit Ctrl-V/Cmd-V in your spreadsheet editor to paste the data.', 'visualizer' ), | |
| 881 | 885 | ), |
| 882 | 886 | 'charts' => array( |
| 883 | 887 | 'canvas' => $data, |
| 884 | 888 | 'id' => $this->_chart->ID, |
| @@ -922,11 +926,10 @@ | ||
| 922 | 926 | if ( filter_input( INPUT_GET, 'library', FILTER_VALIDATE_BOOLEAN ) ) { |
| 923 | 927 | $render->button = filter_input( INPUT_GET, 'action' ) === Visualizer_Plugin::ACTION_EDIT_CHART |
| 924 | 928 | ? esc_html__( 'Save Chart', 'visualizer' ) |
| 925 | 929 | : esc_html__( 'Create Chart', 'visualizer' ); |
| 926 | - if ( filter_input( INPUT_GET, 'action' ) === Visualizer_Plugin::ACTION_EDIT_CHART ) { | |
| 927 | - $render->cancel_button = esc_html__( 'Cancel', 'visualizer' ); | |
| 928 | - } | |
| 930 | + | |
| 931 | + $render->cancel_button = esc_html__( 'Cancel', 'visualizer' ); | |
| 929 | 932 | } else { |
| 930 | 933 | $render->button = esc_attr__( 'Insert Chart', 'visualizer' ); |
| 931 | 934 | } |
| 932 | 935 | |
| @@ -1420,16 +1423,24 @@ | ||
| 1420 | 1423 | */ |
| 1421 | 1424 | public function getQueryData() { |
| 1422 | 1425 | check_ajax_referer( Visualizer_Plugin::ACTION_FETCH_DB_DATA . Visualizer_Plugin::VERSION, 'security' ); |
| 1423 | 1426 | |
| 1424 | - if ( ! current_user_can( 'edit_posts' ) ) { | |
| 1427 | + if ( ! current_user_can( 'administrator' ) ) { | |
| 1425 | 1428 | wp_send_json_error( array( 'msg' => __( 'Action not allowed for this user.', 'visualizer' ) ) ); |
| 1426 | 1429 | } |
| 1430 | + if ( ! is_super_admin() ) { | |
| 1431 | + wp_send_json_error( array( 'msg' => __( 'Action not allowed for this user.', 'visualizer' ) ) ); | |
| 1432 | + } | |
| 1427 | 1433 | |
| 1434 | + if ( ! Visualizer_Module::is_pro() ) { | |
| 1435 | + wp_send_json_error( array( 'msg' => __( 'Feature is not available.', 'visualizer' ) ) ); | |
| 1436 | + } | |
| 1437 | + | |
| 1428 | 1438 | $params = wp_parse_args( $_POST['params'] ); |
| 1429 | 1439 | $chart_id = filter_var( $params['chart_id'], FILTER_VALIDATE_INT ); |
| 1440 | + $query = trim( $params['query'], ';' ); | |
| 1430 | 1441 | |
| 1431 | - $source = new Visualizer_Source_Query( stripslashes( $params['query'] ), $chart_id, $params ); | |
| 1442 | + $source = new Visualizer_Source_Query( stripslashes( $query ), $chart_id, $params ); | |
| 1432 | 1443 | $html = $source->fetch( true ); |
| 1433 | 1444 | $error = $source->get_error(); |
| 1434 | 1445 | if ( ! empty( $error ) ) { |
| 1435 | 1446 | wp_send_json_error( array( 'msg' => $error ) ); |
| @@ -1444,8 +1455,19 @@ | ||
| 1444 | 1455 | */ |
| 1445 | 1456 | public function saveQuery() { |
| 1446 | 1457 | check_ajax_referer( Visualizer_Plugin::ACTION_SAVE_DB_QUERY . Visualizer_Plugin::VERSION, 'security' ); |
| 1447 | 1458 | |
| 1459 | + if ( ! current_user_can( 'administrator' ) ) { | |
| 1460 | + wp_send_json_error( array( 'msg' => __( 'Action not allowed for this user.', 'visualizer' ) ) ); | |
| 1461 | + } | |
| 1462 | + if ( ! is_super_admin() ) { | |
| 1463 | + wp_send_json_error( array( 'msg' => __( 'Action not allowed for this user.', 'visualizer' ) ) ); | |
| 1464 | + } | |
| 1465 | + | |
| 1466 | + if ( ! Visualizer_Module::is_pro() ) { | |
| 1467 | + wp_send_json_error( array( 'msg' => __( 'Feature is not available.', 'visualizer' ) ) ); | |
| 1468 | + } | |
| 1469 | + | |
| 1448 | 1470 | $chart_id = filter_input( |
| 1449 | 1471 | INPUT_GET, |
| 1450 | 1472 | 'chart', |
| 1451 | 1473 | FILTER_VALIDATE_INT, |
| @@ -1474,13 +1496,14 @@ | ||
| 1474 | 1496 | |
| 1475 | 1497 | $render = new Visualizer_Render_Page_Update(); |
| 1476 | 1498 | if ( $chart_id ) { |
| 1477 | 1499 | $params = wp_parse_args( $_POST['params'] ); |
| 1478 | - $source = new Visualizer_Source_Query( stripslashes( $params['query'] ), $chart_id, $params ); | |
| 1500 | + $query = trim( $params['query'], ';' ); | |
| 1501 | + $source = new Visualizer_Source_Query( stripslashes( $query ), $chart_id, $params ); | |
| 1479 | 1502 | $source->fetch( false ); |
| 1480 | 1503 | $error = $source->get_error(); |
| 1481 | 1504 | if ( empty( $error ) ) { |
| 1482 | - update_post_meta( $chart_id, Visualizer_Plugin::CF_DB_QUERY, stripslashes( $params['query'] ) ); | |
| 1505 | + update_post_meta( $chart_id, Visualizer_Plugin::CF_DB_QUERY, stripslashes( $query ) ); | |
| 1483 | 1506 | update_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); |
| 1484 | 1507 | update_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); |
| 1485 | 1508 | update_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, $hours ); |
| 1486 | 1509 | update_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 0 ); |