| @@ -68,39 +68,11 @@ | ||
| 68 | 68 | $this->_addAjaxAction( Visualizer_Plugin::ACTION_JSON_SET_SCHEDULE, 'setJsonSchedule' ); |
| 69 | 69 | |
| 70 | 70 | $this->_addAjaxAction( Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY, 'saveFilter' ); |
| 71 | 71 | |
| 72 | - $this->_addFilter( 'visualizer_get_sidebar', 'getSidebar', 10, 2 ); | |
| 73 | - | |
| 74 | 72 | } |
| 75 | 73 | |
| 76 | 74 | /** |
| 77 | - * Generates the HTML of the sidebar for the chart. | |
| 78 | - * | |
| 79 | - * @since ? | |
| 80 | - * | |
| 81 | - * @access public | |
| 82 | - */ | |
| 83 | - public function getSidebar( $sidebar, $chart_id ) { | |
| 84 | - $chart = get_post( $chart_id ); | |
| 85 | - $data = $this->_getChartArray( $chart ); | |
| 86 | - $sidebar = ''; | |
| 87 | - $sidebar_class = $this->load_chart_class_name( $chart_id ); | |
| 88 | - if ( class_exists( $sidebar_class, true ) ) { | |
| 89 | - $sidebar = new $sidebar_class( $data['settings'] ); | |
| 90 | - $sidebar->__series = $data['series']; | |
| 91 | - $sidebar->__data = $data['data']; | |
| 92 | - } else { | |
| 93 | - $sidebar = apply_filters( 'visualizer_pro_chart_type_sidebar', '', $data ); | |
| 94 | - if ( $sidebar !== '' ) { | |
| 95 | - $sidebar->__series = $data['series']; | |
| 96 | - $sidebar->__data = $data['data']; | |
| 97 | - } | |
| 98 | - } | |
| 99 | - return str_replace( "'", '"', $sidebar->__toString() ); | |
| 100 | - } | |
| 101 | - | |
| 102 | - /** | |
| 103 | 75 | * Sets the schedule for how JSON-endpoint charts should be updated. |
| 104 | 76 | * |
| 105 | 77 | * @since ? |
| 106 | 78 | * |
| @@ -134,30 +106,12 @@ | ||
| 134 | 106 | ), |
| 135 | 107 | ) |
| 136 | 108 | ); |
| 137 | 109 | |
| 138 | - if ( Visualizer_Module::is_pro() ) { | |
| 139 | - $is_woocommerce_report = filter_input( | |
| 140 | - INPUT_POST, | |
| 141 | - 'is_woocommerce_report', | |
| 142 | - FILTER_VALIDATE_BOOLEAN | |
| 143 | - ); | |
| 144 | - | |
| 145 | - if ( $is_woocommerce_report ) { | |
| 146 | - update_post_meta( $chart_id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true ); | |
| 147 | - } else { | |
| 148 | - delete_post_meta( $chart_id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE ); | |
| 149 | - } | |
| 150 | - } | |
| 151 | - | |
| 152 | 110 | delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE ); |
| 153 | 111 | |
| 154 | 112 | if ( -1 < $time ) { |
| 155 | 113 | add_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, $time ); |
| 156 | - // Update schedules. | |
| 157 | - $schedules = get_option( Visualizer_Plugin::CF_JSON_SCHEDULE, array() ); | |
| 158 | - $schedules[ $chart_id ] = time() + $time * HOUR_IN_SECONDS; | |
| 159 | - update_option( Visualizer_Plugin::CF_JSON_SCHEDULE, $schedules ); | |
| 160 | 114 | } |
| 161 | 115 | wp_send_json_success(); |
| 162 | 116 | } |
| 163 | 117 | |
| @@ -176,9 +130,9 @@ | ||
| 176 | 130 | $source = new Visualizer_Source_Json( $params ); |
| 177 | 131 | |
| 178 | 132 | $roots = $source->fetchRoots(); |
| 179 | 133 | if ( empty( $roots ) ) { |
| 180 | - wp_send_json_error( array( 'msg' => $source->get_error() ) ); | |
| 134 | + wp_send_json_error(); | |
| 181 | 135 | } |
| 182 | 136 | |
| 183 | 137 | wp_send_json_success( array( 'url' => $params['url'], 'roots' => $roots ) ); |
| 184 | 138 | } |
| @@ -201,13 +155,12 @@ | ||
| 201 | 155 | wp_die(); |
| 202 | 156 | } |
| 203 | 157 | |
| 204 | 158 | $source = new Visualizer_Source_Json( $params ); |
| 205 | - $source->fetch(); | |
| 206 | - $data = $source->getRawData(); | |
| 207 | 159 | |
| 160 | + $data = $source->parse(); | |
| 208 | 161 | if ( empty( $data ) ) { |
| 209 | - wp_send_json_error( array( 'msg' => esc_html__( 'Unable to fetch data from the endpoint. Please try again.', 'visualizer' ) ) ); | |
| 162 | + wp_send_json_error(); | |
| 210 | 163 | } |
| 211 | 164 | |
| 212 | 165 | $data = Visualizer_Render_Layout::show( 'editor-table', $data, $chart_id, 'viz-json-table', false, false ); |
| 213 | 166 | wp_send_json_success( array( 'table' => $data, 'root' => $params['root'], 'url' => $params['url'], 'paging' => $source->getPaginationElements() ) ); |
| @@ -232,12 +185,11 @@ | ||
| 232 | 185 | |
| 233 | 186 | $chart = get_post( $chart_id ); |
| 234 | 187 | |
| 235 | 188 | $source = new Visualizer_Source_Json( $params ); |
| 236 | - update_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ); | |
| 237 | - $source->fetchFromEditableTable(); | |
| 189 | + $source->fetch(); | |
| 238 | 190 | |
| 239 | - $content = $source->getData( get_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ); | |
| 191 | + $content = $source->getData(); | |
| 240 | 192 | $chart->post_content = $content; |
| 241 | 193 | wp_update_post( $chart->to_array() ); |
| 242 | 194 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); |
| 243 | 195 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); |
| @@ -243,58 +195,16 @@ | ||
| 243 | 195 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); |
| 244 | 196 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, 0 ); |
| 245 | 197 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_URL, $params['url'] ); |
| 246 | 198 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_ROOT, $params['root'] ); |
| 247 | - | |
| 248 | - delete_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_HEADERS ); | |
| 249 | - $headers = array( 'method' => $params['method'] ); | |
| 250 | - if ( ! empty( $params['auth'] ) ) { | |
| 251 | - $headers['auth'] = $params['auth']; | |
| 252 | - } elseif ( ! empty( $params['username'] ) && ! empty( $params['password'] ) ) { | |
| 253 | - $headers['auth'] = array( 'username' => $params['username'], 'password' => $params['password'] ); | |
| 254 | - } | |
| 255 | - | |
| 256 | - add_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_HEADERS, $headers ); | |
| 257 | - | |
| 258 | 199 | delete_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_PAGING ); |
| 259 | 200 | if ( ! empty( $params['paging'] ) ) { |
| 260 | 201 | add_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_PAGING, $params['paging'] ); |
| 261 | 202 | } |
| 262 | 203 | |
| 263 | - if ( Visualizer_Module::is_pro() ) { | |
| 264 | - if ( ! empty( $params['vz_woo_source'] ) ) { | |
| 265 | - update_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_WOOCOMMERCE_SOURCE, $params['vz_woo_source'] ); | |
| 266 | - } else { | |
| 267 | - delete_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_WOOCOMMERCE_SOURCE ); | |
| 268 | - } | |
| 269 | - } | |
| 270 | - | |
| 271 | - $time = filter_input( | |
| 272 | - INPUT_POST, | |
| 273 | - 'time', | |
| 274 | - FILTER_VALIDATE_INT, | |
| 275 | - array( | |
| 276 | - 'options' => array( | |
| 277 | - 'min_range' => -1, | |
| 278 | - ), | |
| 279 | - ) | |
| 280 | - ); | |
| 281 | - | |
| 282 | - delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE ); | |
| 283 | - | |
| 284 | - if ( -1 < $time ) { | |
| 285 | - add_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, $time ); | |
| 286 | - } | |
| 287 | - | |
| 288 | - // delete other source specific parameters. | |
| 289 | - delete_post_meta( $chart_id, Visualizer_Plugin::CF_DB_QUERY ); | |
| 290 | - delete_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE ); | |
| 291 | - delete_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_URL ); | |
| 292 | - delete_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_SCHEDULE ); | |
| 293 | - | |
| 294 | 204 | $render = new Visualizer_Render_Page_Update(); |
| 295 | 205 | $render->id = $chart->ID; |
| 296 | - $render->data = json_encode( $source->getRawData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) ); | |
| 206 | + $render->data = json_encode( $source->getRawData() ); | |
| 297 | 207 | $render->series = json_encode( $source->getSeries() ); |
| 298 | 208 | $render->render(); |
| 299 | 209 | |
| 300 | 210 | defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); |
| @@ -384,9 +294,9 @@ | ||
| 384 | 294 | $chart = $this->_chart; |
| 385 | 295 | } |
| 386 | 296 | $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ); |
| 387 | 297 | $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type ); |
| 388 | - $data = self::get_chart_data( $chart, $type ); | |
| 298 | + $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( $chart->post_content ), $chart->ID, $type ); | |
| 389 | 299 | $library = $this->load_chart_type( $chart->ID ); |
| 390 | 300 | |
| 391 | 301 | $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true ); |
| 392 | 302 | $settings = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SETTINGS, $settings, $chart->ID, $type ); |
| @@ -460,22 +370,9 @@ | ||
| 460 | 370 | $success = $chart && $chart->post_type === Visualizer_Plugin::CPT_VISUALIZER; |
| 461 | 371 | } |
| 462 | 372 | } |
| 463 | 373 | if ( $success ) { |
| 464 | - global $sitepress; | |
| 465 | - if ( Visualizer_Module::is_pro() && ( function_exists( 'icl_get_languages' ) && $sitepress instanceof \SitePress ) ) { | |
| 466 | - $trid = $sitepress->get_element_trid( $chart_id, 'post_' . Visualizer_Plugin::CPT_VISUALIZER ); | |
| 467 | - $translations = $sitepress->get_element_translations( $trid ); | |
| 468 | - if ( ! empty( $translations ) ) { | |
| 469 | - foreach ( $translations as $translated_post ) { | |
| 470 | - wp_delete_post( $translated_post->element_id, true ); | |
| 471 | - } | |
| 472 | - } else { | |
| 473 | - wp_delete_post( $chart_id, true ); | |
| 474 | - } | |
| 475 | - } else { | |
| 476 | - wp_delete_post( $chart_id, true ); | |
| 477 | - } | |
| 374 | + wp_delete_post( $chart_id, true ); | |
| 478 | 375 | } |
| 479 | 376 | if ( $is_post ) { |
| 480 | 377 | self::_sendResponse( |
| 481 | 378 | array( |
| @@ -482,9 +379,9 @@ | ||
| 482 | 379 | 'success' => $success, |
| 483 | 380 | ) |
| 484 | 381 | ); |
| 485 | 382 | } |
| 486 | - wp_redirect( remove_query_arg( 'vaction', wp_get_referer() ) ); | |
| 383 | + wp_redirect( wp_get_referer() ); | |
| 487 | 384 | exit; |
| 488 | 385 | } |
| 489 | 386 | |
| 490 | 387 | /** |
| @@ -524,119 +421,50 @@ | ||
| 524 | 421 | * @access public |
| 525 | 422 | */ |
| 526 | 423 | public function renderChartPages() { |
| 527 | 424 | defined( 'IFRAME_REQUEST' ) || define( 'IFRAME_REQUEST', 1 ); |
| 528 | - if ( ! defined( 'ET_BUILDER_PRODUCT_VERSION' ) && function_exists( 'et_get_theme_version' ) ) { | |
| 529 | - define( 'ET_BUILDER_PRODUCT_VERSION', et_get_theme_version() ); | |
| 530 | - } | |
| 531 | - // Set current screen for the render chart. | |
| 532 | - set_current_screen( 'visualizer_render_chart' ); | |
| 533 | 425 | // check chart, if chart not exists, will create new one and redirects to the same page with proper chart id |
| 534 | 426 | $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : ''; |
| 535 | - if ( ! empty( $_POST ) ) { | |
| 536 | - $_POST = map_deep( $_POST, 'wp_strip_all_tags' ); | |
| 537 | - } | |
| 538 | 427 | if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ) { |
| 539 | - if ( empty( $_GET['lang'] ) || empty( $_GET['parent_chart_id'] ) ) { | |
| 540 | - $this->deleteOldCharts(); | |
| 541 | - $default_type = isset( $_GET['type'] ) && ! empty( $_GET['type'] ) ? $_GET['type'] : 'line'; | |
| 542 | - $chart_status = Visualizer_Module_Admin::checkChartStatus( $default_type ); | |
| 543 | - if ( ! $chart_status ) { | |
| 544 | - $default_type = 'line'; | |
| 545 | - } | |
| 546 | - $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $default_type . '.csv' ); | |
| 547 | - $source->fetch(); | |
| 548 | - $chart_id = wp_insert_post( | |
| 428 | + $this->deleteOldCharts(); | |
| 429 | + $default_type = isset( $_GET['type'] ) && ! empty( $_GET['type'] ) ? $_GET['type'] : 'line'; | |
| 430 | + $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $default_type . '.csv' ); | |
| 431 | + $source->fetch(); | |
| 432 | + $chart_id = wp_insert_post( | |
| 433 | + array( | |
| 434 | + 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, | |
| 435 | + 'post_title' => 'Visualization', | |
| 436 | + 'post_author' => get_current_user_id(), | |
| 437 | + 'post_status' => 'auto-draft', | |
| 438 | + 'post_content' => $source->getData(), | |
| 439 | + ) | |
| 440 | + ); | |
| 441 | + if ( $chart_id && ! is_wp_error( $chart_id ) ) { | |
| 442 | + add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, $default_type ); | |
| 443 | + add_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 1 ); | |
| 444 | + add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); | |
| 445 | + add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); | |
| 446 | + add_post_meta( | |
| 447 | + $chart_id, | |
| 448 | + Visualizer_Plugin::CF_SETTINGS, | |
| 549 | 449 | array( |
| 550 | - 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, | |
| 551 | - 'post_title' => 'Visualization', | |
| 552 | - 'post_author' => get_current_user_id(), | |
| 553 | - 'post_status' => 'auto-draft', | |
| 554 | - 'post_content' => $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ), | |
| 450 | + 'focusTarget' => 'datum', | |
| 555 | 451 | ) |
| 556 | 452 | ); |
| 557 | - if ( $chart_id && ! is_wp_error( $chart_id ) ) { | |
| 558 | - add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, $default_type ); | |
| 559 | - add_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 1 ); | |
| 560 | - add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); | |
| 561 | - add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); | |
| 562 | - add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, '' ); | |
| 563 | - add_post_meta( | |
| 564 | - $chart_id, | |
| 565 | - Visualizer_Plugin::CF_SETTINGS, | |
| 566 | - array( | |
| 567 | - 'focusTarget' => 'datum', | |
| 568 | - ) | |
| 569 | - ); | |
| 570 | - | |
| 571 | - do_action( 'visualizer_pro_new_chart_defaults', $chart_id ); | |
| 572 | - } | |
| 573 | - } else { | |
| 574 | - if ( current_user_can( 'edit_posts' ) ) { | |
| 575 | - $parent_chart_id = isset( $_GET['parent_chart_id'] ) ? filter_var( $_GET['parent_chart_id'], FILTER_VALIDATE_INT ) : ''; | |
| 576 | - $success = false; | |
| 577 | - if ( $parent_chart_id ) { | |
| 578 | - $parent_chart = get_post( $parent_chart_id ); | |
| 579 | - $success = $parent_chart && $parent_chart->post_type === Visualizer_Plugin::CPT_VISUALIZER; | |
| 580 | - } | |
| 581 | - if ( $success ) { | |
| 582 | - $new_chart_id = wp_insert_post( | |
| 583 | - array( | |
| 584 | - 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, | |
| 585 | - 'post_title' => 'Visualization', | |
| 586 | - 'post_author' => get_current_user_id(), | |
| 587 | - 'post_status' => $parent_chart->post_status, | |
| 588 | - 'post_content' => $parent_chart->post_content, | |
| 589 | - ) | |
| 590 | - ); | |
| 591 | - | |
| 592 | - if ( is_wp_error( $new_chart_id ) ) { | |
| 593 | - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Error while cloning chart %d = %s', $parent_chart_id, print_r( $new_chart_id, true ) ), 'error', __FILE__, __LINE__ ); | |
| 594 | - } else { | |
| 595 | - $post_meta = get_post_meta( $parent_chart_id ); | |
| 596 | - $chart_id = $new_chart_id; | |
| 597 | - foreach ( $post_meta as $key => $value ) { | |
| 598 | - if ( strpos( $key, 'visualizer-' ) !== false ) { | |
| 599 | - add_post_meta( $new_chart_id, $key, maybe_unserialize( $value[0] ) ); | |
| 600 | - } | |
| 601 | - } | |
| 602 | - } | |
| 603 | - } | |
| 604 | - } | |
| 605 | 453 | do_action( 'visualizer_pro_new_chart_defaults', $chart_id ); |
| 606 | 454 | } |
| 607 | - wp_redirect( esc_url_raw( add_query_arg( 'chart', (int) $chart_id ) ) ); | |
| 608 | - | |
| 609 | - if ( defined( 'WP_TESTS_DOMAIN' ) ) { | |
| 610 | - wp_die(); | |
| 611 | - } | |
| 612 | - exit(); | |
| 455 | + wp_redirect( add_query_arg( 'chart', (int) $chart_id ) ); | |
| 456 | + defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); | |
| 613 | 457 | } |
| 614 | 458 | |
| 615 | - $_POST['save_chart_image'] = isset( $_POST['save_chart_image'] ) && 'yes' === $_POST['save_chart_image'] ? true : false; | |
| 616 | - $_POST['lazy_load_chart'] = isset( $_POST['lazy_load_chart'] ) && 'yes' === $_POST['lazy_load_chart'] ? true : false; | |
| 459 | + $this->load_chart_type( $chart_id ); | |
| 617 | 460 | |
| 618 | - if ( isset( $_POST['chart-img'] ) && ! empty( $_POST['chart-img'] ) ) { | |
| 619 | - $attachment_id = $this->save_chart_image( $_POST['chart-img'], $chart_id, $_POST['save_chart_image'] ); | |
| 620 | - if ( $attachment_id ) { | |
| 621 | - update_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_IMAGE, $attachment_id ); | |
| 622 | - } | |
| 623 | - } | |
| 624 | - $lib = $this->load_chart_type( $chart_id ); | |
| 625 | - | |
| 626 | - // the alpha color picker (RGBA) is not supported by google. | |
| 627 | - $color_picker_dep = 'wp-color-picker'; | |
| 628 | - if ( in_array( $lib, array( 'chartjs', 'datatables' ), true ) && ! wp_script_is( 'wp-color-picker-alpha', 'registered' ) ) { | |
| 629 | - wp_register_script( 'wp-color-picker-alpha', VISUALIZER_ABSURL . 'js/lib/wp-color-picker-alpha.min.js', array( 'wp-color-picker' ), Visualizer_Plugin::VERSION ); | |
| 630 | - $color_picker_dep = 'wp-color-picker-alpha'; | |
| 631 | - } | |
| 632 | - | |
| 633 | 461 | // enqueue and register scripts and styles |
| 634 | 462 | wp_register_script( 'visualizer-chosen', VISUALIZER_ABSURL . 'js/lib/chosen.jquery.min.js', array( 'jquery' ), Visualizer_Plugin::VERSION ); |
| 635 | 463 | wp_register_style( 'visualizer-chosen', VISUALIZER_ABSURL . 'css/lib/chosen.min.css', array(), Visualizer_Plugin::VERSION ); |
| 636 | 464 | |
| 637 | 465 | wp_register_style( 'visualizer-frame', VISUALIZER_ABSURL . 'css/frame.css', array( 'visualizer-chosen' ), Visualizer_Plugin::VERSION ); |
| 638 | - wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'visualizer-chosen', 'jquery-ui-accordion', 'jquery-ui-tabs' ), Visualizer_Plugin::VERSION, true ); | |
| 466 | + wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'visualizer-chosen', 'jquery-ui-accordion' ), Visualizer_Plugin::VERSION, true ); | |
| 639 | 467 | wp_register_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true ); |
| 640 | 468 | wp_register_script( |
| 641 | 469 | 'visualizer-render', |
| 642 | 470 | VISUALIZER_ABSURL . 'js/render-facade.js', |
| @@ -647,9 +475,9 @@ | ||
| 647 | 475 | wp_register_script( |
| 648 | 476 | 'visualizer-preview', |
| 649 | 477 | VISUALIZER_ABSURL . 'js/preview.js', |
| 650 | 478 | array( |
| 651 | - $color_picker_dep, | |
| 479 | + 'wp-color-picker', | |
| 652 | 480 | 'visualizer-render', |
| 653 | 481 | ), |
| 654 | 482 | Visualizer_Plugin::VERSION, |
| 655 | 483 | true |
| @@ -655,11 +483,10 @@ | ||
| 655 | 483 | true |
| 656 | 484 | ); |
| 657 | 485 | wp_register_script( 'visualizer-editor-simple', VISUALIZER_ABSURL . 'js/simple-editor.js', array( 'jquery' ), Visualizer_Plugin::VERSION, true ); |
| 658 | 486 | |
| 659 | - do_action( 'visualizer_add_scripts' ); | |
| 660 | - | |
| 661 | - if ( Visualizer_Module::is_pro() && Visualizer_Module::is_pro_older_than( '1.9.0' ) ) { | |
| 487 | + // added by Ash/Upwork | |
| 488 | + if ( VISUALIZER_PRO ) { | |
| 662 | 489 | global $Visualizer_Pro; |
| 663 | 490 | $Visualizer_Pro->_addScriptsAndStyles(); |
| 664 | 491 | } |
| 665 | 492 | |
| @@ -675,9 +502,8 @@ | ||
| 675 | 502 | if ( isset( $_POST['cancel'] ) && 1 === intval( $_POST['cancel'] ) ) { |
| 676 | 503 | // if the cancel button is clicked. |
| 677 | 504 | $this->undoRevisions( $chart_id, true ); |
| 678 | 505 | } elseif ( isset( $_POST['save'] ) && 1 === intval( $_POST['save'] ) ) { |
| 679 | - $this->handlePermissions(); | |
| 680 | 506 | // if the save button is clicked. |
| 681 | 507 | $this->undoRevisions( $chart_id, false ); |
| 682 | 508 | } else { |
| 683 | 509 | // if the edit button is clicked. |
| @@ -683,16 +509,8 @@ | ||
| 683 | 509 | // if the edit button is clicked. |
| 684 | 510 | $this->_chart = $this->handleExistingRevisions( $chart_id, $this->_chart ); |
| 685 | 511 | } |
| 686 | 512 | |
| 687 | - // Clear existing chart cache. | |
| 688 | - if ( isset( $_POST['save'] ) && 1 === intval( $_POST['save'] ) ) { | |
| 689 | - $cache_key = Visualizer_Plugin::CF_CHART_CACHE . '_' . $chart_id; | |
| 690 | - if ( get_transient( $cache_key ) ) { | |
| 691 | - delete_transient( $cache_key ); | |
| 692 | - } | |
| 693 | - } | |
| 694 | - | |
| 695 | 513 | switch ( $tab ) { |
| 696 | 514 | case 'settings': |
| 697 | 515 | $this->_handleDataAndSettingsPage(); |
| 698 | 516 | break; |
| @@ -700,9 +518,9 @@ | ||
| 700 | 518 | case 'visualizer': // fall through. |
| 701 | 519 | $this->_handleTypesPage(); |
| 702 | 520 | break; |
| 703 | 521 | default: |
| 704 | - // this should never happen. | |
| 522 | + do_action( 'visualizer_pro_handle_tab', $tab, $this->_chart ); | |
| 705 | 523 | break; |
| 706 | 524 | } |
| 707 | 525 | defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); |
| 708 | 526 | } |
| @@ -709,25 +527,25 @@ | ||
| 709 | 527 | |
| 710 | 528 | /** |
| 711 | 529 | * Load code editor assets. |
| 712 | 530 | */ |
| 713 | - private function loadCodeEditorAssets( $chart_id ) { | |
| 531 | + private function loadCodeEditorAssets() { | |
| 714 | 532 | global $wp_version; |
| 715 | 533 | |
| 716 | 534 | $wp_scripts = wp_scripts(); |
| 717 | 535 | |
| 718 | 536 | // data tables assets. |
| 719 | - wp_register_script( 'visualizer-datatables', VISUALIZER_ABSURL . 'js/lib/datatables.min.js', array( 'jquery-ui-core' ), Visualizer_Plugin::VERSION ); | |
| 720 | - wp_register_style( 'visualizer-datatables', VISUALIZER_ABSURL . 'css/lib/datatables.min.css', array(), Visualizer_Plugin::VERSION ); | |
| 721 | - wp_register_style( 'visualizer-jquery-ui', sprintf( '//code.jquery.com/ui/%s/themes/smoothness/jquery-ui.css', $wp_scripts->registered['jquery-ui-core']->ver ), array( 'visualizer-datatables' ), Visualizer_Plugin::VERSION ); | |
| 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 ); | |
| 539 | + 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 ); | |
| 722 | 540 | wp_enqueue_script( 'visualizer-datatables' ); |
| 723 | 541 | wp_enqueue_style( 'visualizer-jquery-ui' ); |
| 724 | 542 | |
| 725 | - if ( ! Visualizer_Module::is_pro() ) { | |
| 543 | + if ( ! VISUALIZER_PRO ) { | |
| 726 | 544 | return; |
| 727 | 545 | } |
| 728 | 546 | |
| 729 | - $table_col_mapping = Visualizer_Source_Query_Params::get_all_db_tables_column_mapping( $chart_id ); | |
| 547 | + $table_col_mapping = Visualizer_Source_Query_Params::get_all_db_tables_column_mapping(); | |
| 730 | 548 | |
| 731 | 549 | if ( version_compare( $wp_version, '4.9.0', '<' ) ) { |
| 732 | 550 | // code mirror assets. |
| 733 | 551 | wp_register_script( 'visualizer-codemirror-core', '//codemirror.net/lib/codemirror.js', array( 'jquery' ), Visualizer_Plugin::VERSION ); |
| @@ -762,25 +580,8 @@ | ||
| 762 | 580 | return $table_col_mapping; |
| 763 | 581 | } |
| 764 | 582 | |
| 765 | 583 | /** |
| 766 | - * Handle permissions from the new conslidated settings sidebar. | |
| 767 | - */ | |
| 768 | - private function handlePermissions() { | |
| 769 | - if ( ! Visualizer_Module::is_pro() ) { | |
| 770 | - return; | |
| 771 | - } | |
| 772 | - | |
| 773 | - // we will not support old free and new pro. | |
| 774 | - // handling new free and old pro. | |
| 775 | - if ( has_action( 'visualizer_pro_handle_tab' ) ) { | |
| 776 | - do_action( 'visualizer_pro_handle_tab', 'permissions', $this->_chart ); | |
| 777 | - } else { | |
| 778 | - do_action( 'visualizer_handle_permissions', $this->_chart ); | |
| 779 | - } | |
| 780 | - } | |
| 781 | - | |
| 782 | - /** | |
| 783 | 584 | * Handle data and settings page |
| 784 | 585 | */ |
| 785 | 586 | private function _handleDataAndSettingsPage() { |
| 786 | 587 | if ( isset( $_POST['map_api_key'] ) ) { |
| @@ -785,9 +586,8 @@ | ||
| 785 | 586 | private function _handleDataAndSettingsPage() { |
| 786 | 587 | if ( isset( $_POST['map_api_key'] ) ) { |
| 787 | 588 | update_option( 'visualizer-map-api-key', $_POST['map_api_key'] ); |
| 788 | 589 | } |
| 789 | - | |
| 790 | 590 | if ( $_SERVER['REQUEST_METHOD'] === 'POST' && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'] ) ) { |
| 791 | 591 | if ( $this->_chart->post_status === 'auto-draft' ) { |
| 792 | 592 | $this->_chart->post_status = 'publish'; |
| 793 | 593 | |
| @@ -792,46 +592,24 @@ | ||
| 792 | 592 | $this->_chart->post_status = 'publish'; |
| 793 | 593 | |
| 794 | 594 | // 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 | 595 | // we do not want any difference in data so disable revisions temporarily. |
| 796 | - $this->disableRevisionsTemporarily(); | |
| 797 | - | |
| 596 | + add_filter( 'wp_revisions_to_keep', '__return_false' ); | |
| 798 | 597 | wp_update_post( $this->_chart->to_array() ); |
| 799 | 598 | } |
| 800 | 599 | // save meta data only when it is NOT being canceled. |
| 801 | 600 | if ( ! ( isset( $_POST['cancel'] ) && 1 === intval( $_POST['cancel'] ) ) ) { |
| 802 | 601 | update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $_POST ); |
| 803 | - | |
| 804 | - // we will keep a parameter called 'internal_title' that will be set to the given title or, if empty, the chart ID | |
| 805 | - // this will help in searching with the chart id. | |
| 806 | - $settings = get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, true ); | |
| 807 | - $title = null; | |
| 808 | - if ( isset( $settings['title'] ) && ! empty( $settings['title'] ) ) { | |
| 809 | - $title = $settings['title']; | |
| 810 | - if ( is_array( $title ) ) { | |
| 811 | - $title = $settings['title']['text']; | |
| 812 | - } | |
| 813 | - } | |
| 814 | - if ( empty( $title ) ) { | |
| 815 | - $title = $this->_chart->ID; | |
| 816 | - } | |
| 817 | - $settings['internal_title'] = $title; | |
| 818 | - $settings_label = isset( $settings['pieResidueSliceLabel'] ) ? $settings['pieResidueSliceLabel'] : ''; | |
| 819 | - if ( empty( $settings_label ) ) { | |
| 820 | - $settings['pieResidueSliceLabel'] = esc_html__( 'Other', 'visualizer' ); | |
| 821 | - } else { | |
| 822 | - $settings['pieResidueSliceLabel'] = $settings_label; | |
| 823 | - } | |
| 824 | - update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $settings ); | |
| 825 | 602 | } |
| 826 | 603 | $render = new Visualizer_Render_Page_Send(); |
| 827 | 604 | $render->text = sprintf( '[visualizer id="%d"]', $this->_chart->ID ); |
| 828 | 605 | wp_iframe( array( $render, 'render' ) ); |
| 606 | + | |
| 829 | 607 | return; |
| 830 | 608 | } |
| 831 | 609 | $data = $this->_getChartArray(); |
| 832 | 610 | $sidebar = ''; |
| 833 | - $sidebar_class = $this->load_chart_class_name( $this->_chart->ID ); | |
| 611 | + $sidebar_class = 'Visualizer_Render_Sidebar_Type_' . ucfirst( $data['type'] ); | |
| 834 | 612 | if ( class_exists( $sidebar_class, true ) ) { |
| 835 | 613 | $sidebar = new $sidebar_class( $data['settings'] ); |
| 836 | 614 | $sidebar->__series = $data['series']; |
| 837 | 615 | $sidebar->__data = $data['data']; |
| @@ -841,9 +619,9 @@ | ||
| 841 | 619 | $sidebar->__series = $data['series']; |
| 842 | 620 | $sidebar->__data = $data['data']; |
| 843 | 621 | } |
| 844 | 622 | } |
| 845 | - unset( $data['settings']['width'], $data['settings']['height'], $data['settings']['chartArea'] ); | |
| 623 | + unset( $data['settings']['width'], $data['settings']['height'] ); | |
| 846 | 624 | wp_enqueue_style( 'wp-color-picker' ); |
| 847 | 625 | wp_enqueue_style( 'visualizer-frame' ); |
| 848 | 626 | wp_enqueue_script( 'visualizer-preview' ); |
| 849 | 627 | wp_enqueue_script( 'visualizer-chosen' ); |
| @@ -848,9 +626,9 @@ | ||
| 848 | 626 | wp_enqueue_script( 'visualizer-preview' ); |
| 849 | 627 | wp_enqueue_script( 'visualizer-chosen' ); |
| 850 | 628 | wp_enqueue_script( 'visualizer-render' ); |
| 851 | 629 | |
| 852 | - if ( Visualizer_Module::can_show_feature( 'simple-editor' ) ) { | |
| 630 | + if ( ! VISUALIZER_PRO ) { | |
| 853 | 631 | wp_enqueue_script( 'visualizer-editor-simple' ); |
| 854 | 632 | wp_localize_script( |
| 855 | 633 | 'visualizer-editor-simple', |
| 856 | 634 | 'visualizer1', |
| @@ -865,9 +643,9 @@ | ||
| 865 | 643 | ) |
| 866 | 644 | ); |
| 867 | 645 | } |
| 868 | 646 | |
| 869 | - $table_col_mapping = $this->loadCodeEditorAssets( $this->_chart->ID ); | |
| 647 | + $table_col_mapping = $this->loadCodeEditorAssets(); | |
| 870 | 648 | |
| 871 | 649 | wp_localize_script( |
| 872 | 650 | 'visualizer-render', |
| 873 | 651 | 'visualizer', |
| @@ -872,13 +650,11 @@ | ||
| 872 | 650 | 'visualizer-render', |
| 873 | 651 | 'visualizer', |
| 874 | 652 | array( |
| 875 | 653 | 'l10n' => array( |
| 876 | - 'invalid_source' => esc_html__( 'You have entered an invalid URL. Please provide a valid URL.', 'visualizer' ), | |
| 654 | + 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ), | |
| 877 | 655 | 'loading' => esc_html__( 'Loading...', 'visualizer' ), |
| 878 | 656 | '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' ), | |
| 881 | 657 | ), |
| 882 | 658 | 'charts' => array( |
| 883 | 659 | 'canvas' => $data, |
| 884 | 660 | 'id' => $this->_chart->ID, |
| @@ -904,14 +680,13 @@ | ||
| 904 | 680 | ), |
| 905 | 681 | 'db_query' => array( |
| 906 | 682 | 'tables' => $table_col_mapping, |
| 907 | 683 | ), |
| 908 | - 'is_pro' => Visualizer_Module::is_pro(), | |
| 684 | + 'is_pro' => VISUALIZER_PRO, | |
| 909 | 685 | 'page_type' => 'chart', |
| 910 | 686 | 'json_tag_separator' => Visualizer_Source_Json::TAG_SEPARATOR, |
| 911 | 687 | 'json_tag_separator_view' => Visualizer_Source_Json::TAG_SEPARATOR_VIEW, |
| 912 | 688 | 'is_front' => false, |
| 913 | - 'rest_base' => get_rest_url( null, 'wc/v3/reports/' ), | |
| 914 | 689 | ) |
| 915 | 690 | ); |
| 916 | 691 | |
| 917 | 692 | $render = new Visualizer_Render_Page_Data(); |
| @@ -928,16 +703,12 @@ | ||
| 928 | 703 | } |
| 929 | 704 | } else { |
| 930 | 705 | $render->button = esc_attr__( 'Insert Chart', 'visualizer' ); |
| 931 | 706 | } |
| 932 | - | |
| 933 | - do_action( 'visualizer_enqueue_scripts_and_styles', $data, $this->_chart->ID ); | |
| 934 | - | |
| 935 | - if ( Visualizer_Module::is_pro() && Visualizer_Module::is_pro_older_than( '1.9.0' ) ) { | |
| 707 | + if ( VISUALIZER_PRO ) { | |
| 936 | 708 | global $Visualizer_Pro; |
| 937 | - $Visualizer_Pro->_enqueueScriptsAndStyles( $data, $this->_chart->ID ); | |
| 709 | + $Visualizer_Pro->_enqueueScriptsAndStyles( $data ); | |
| 938 | 710 | } |
| 939 | - | |
| 940 | 711 | $this->_addAction( 'admin_head', 'renderFlattrScript' ); |
| 941 | 712 | wp_iframe( array( $render, 'render' ) ); |
| 942 | 713 | } |
| 943 | 714 | |
| @@ -951,33 +722,22 @@ | ||
| 951 | 722 | private function _handleTypesPage() { |
| 952 | 723 | // process post request |
| 953 | 724 | if ( $_SERVER['REQUEST_METHOD'] === 'POST' && wp_verify_nonce( filter_input( INPUT_POST, 'nonce' ) ) ) { |
| 954 | 725 | $type = filter_input( INPUT_POST, 'type' ); |
| 955 | - $library = filter_input( INPUT_POST, 'chart-library' ); | |
| 956 | - if ( Visualizer_Module_Admin::checkChartStatus( $type ) ) { | |
| 957 | - if ( empty( $library ) ) { | |
| 958 | - // library cannot be empty. | |
| 959 | - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'Chart library empty while creating the chart! Aborting...', 'error', __FILE__, __LINE__ ); | |
| 960 | - return; | |
| 961 | - } | |
| 962 | - | |
| 726 | + if ( in_array( $type, Visualizer_Plugin::getChartTypes(), true ) ) { | |
| 963 | 727 | // save new chart type |
| 964 | 728 | update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_CHART_TYPE, $type ); |
| 965 | - update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_CHART_LIBRARY, $library ); | |
| 966 | 729 | // if the chart has default data, update it with appropriate default data for new type |
| 967 | 730 | if ( filter_var( get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, true ), FILTER_VALIDATE_BOOLEAN ) ) { |
| 968 | 731 | $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $type . '.csv' ); |
| 969 | 732 | $source->fetch(); |
| 970 | - $this->_chart->post_content = $source->getData( get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ); | |
| 733 | + $this->_chart->post_content = $source->getData(); | |
| 971 | 734 | wp_update_post( $this->_chart->to_array() ); |
| 972 | 735 | update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); |
| 973 | 736 | } |
| 974 | - | |
| 975 | - Visualizer_Module_Utility::set_defaults( $this->_chart ); | |
| 976 | - | |
| 977 | 737 | // redirect to next tab |
| 978 | 738 | // changed by Ash/Upwork |
| 979 | - wp_redirect( esc_url_raw( add_query_arg( 'tab', 'settings' ) ) ); | |
| 739 | + wp_redirect( add_query_arg( 'tab', 'settings' ) ); | |
| 980 | 740 | |
| 981 | 741 | return; |
| 982 | 742 | } |
| 983 | 743 | } |
| @@ -982,9 +742,9 @@ | ||
| 982 | 742 | } |
| 983 | 743 | } |
| 984 | 744 | $render = new Visualizer_Render_Page_Types(); |
| 985 | 745 | $render->type = get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ); |
| 986 | - $render->types = Visualizer_Module_Admin::_getChartTypesLocalized( false, false, false, 'types' ); | |
| 746 | + $render->types = Visualizer_Module_Admin::_getChartTypesLocalized(); | |
| 987 | 747 | $render->chart = $this->_chart; |
| 988 | 748 | wp_enqueue_style( 'visualizer-frame' ); |
| 989 | 749 | wp_enqueue_script( 'visualizer-frame' ); |
| 990 | 750 | wp_iframe( array( $render, 'render' ) ); |
| @@ -1006,51 +766,28 @@ | ||
| 1006 | 766 | * Processes the CSV that is sent in the request as a string. |
| 1007 | 767 | * |
| 1008 | 768 | * @since 3.2.0 |
| 1009 | 769 | */ |
| 1010 | - private function handleCSVasString( $data, $editor_type ) { | |
| 770 | + private function handleCSVasString( $data ) { | |
| 1011 | 771 | $source = null; |
| 1012 | - | |
| 1013 | - switch ( $editor_type ) { | |
| 1014 | - case 'text': | |
| 1015 | - // data coming in from the text editor. | |
| 1016 | - $tmpfile = tempnam( get_temp_dir(), Visualizer_Plugin::NAME ); | |
| 1017 | - $handle = fopen( $tmpfile, 'w' ); | |
| 1018 | - $values = preg_split( '/[\n\r]+/', stripslashes( trim( $data ) ) ); | |
| 1019 | - if ( $values ) { | |
| 1020 | - foreach ( $values as $row ) { | |
| 1021 | - if ( empty( $row ) ) { | |
| 1022 | - continue; | |
| 1023 | - } | |
| 1024 | - $row = explode( ',', $row ); | |
| 1025 | - $row = array_map( | |
| 1026 | - function( $r ) { | |
| 1027 | - return '' === $r ? ' ' : $r; | |
| 1028 | - }, | |
| 1029 | - $row | |
| 1030 | - ); | |
| 1031 | - $row = implode( ',', $row ); | |
| 1032 | - // don't use fpucsv here because we need to just dump the data | |
| 1033 | - // minus the empty rows | |
| 1034 | - // because fputcsv needs to tokenize | |
| 1035 | - // we can standardize the CSV enclosure here and replace all ' with " | |
| 1036 | - // we can assume that if there are an even number of ' they should be changed to " | |
| 1037 | - // but that will screw up words like fo'c'sle | |
| 1038 | - // so here let's just assume ' will NOT be used for enclosures | |
| 1039 | - fwrite( $handle, $row ); | |
| 1040 | - fwrite( $handle, PHP_EOL ); | |
| 772 | + if ( VISUALIZER_PRO ) { | |
| 773 | + $source = apply_filters( 'visualizer_pro_handle_chart_data', $data, '' ); | |
| 774 | + } else { | |
| 775 | + // data coming in from the text editor. | |
| 776 | + $tmpfile = tempnam( get_temp_dir(), Visualizer_Plugin::NAME ); | |
| 777 | + $handle = fopen( $tmpfile, 'w' ); | |
| 778 | + $values = preg_split( '/[\n\r]+/', stripslashes( trim( $data ) ) ); | |
| 779 | + if ( $values ) { | |
| 780 | + foreach ( $values as $row ) { | |
| 781 | + if ( empty( $row ) ) { | |
| 782 | + continue; | |
| 1041 | 783 | } |
| 784 | + $columns = explode( ',', $row ); | |
| 785 | + fputcsv( $handle, $columns ); | |
| 1042 | 786 | } |
| 1043 | - $source = new Visualizer_Source_Csv( $tmpfile ); | |
| 1044 | - fclose( $handle ); | |
| 1045 | - break; | |
| 1046 | - case 'table': | |
| 1047 | - // Import from Chart | |
| 1048 | - // fall-through. | |
| 1049 | - case 'excel': | |
| 1050 | - // data coming in from the excel editor. | |
| 1051 | - $source = apply_filters( 'visualizer_pro_handle_chart_data', $data, '' ); | |
| 1052 | - break; | |
| 787 | + } | |
| 788 | + $source = new Visualizer_Source_Csv( $tmpfile ); | |
| 789 | + fclose( $handle ); | |
| 1053 | 790 | } |
| 1054 | 791 | return $source; |
| 1055 | 792 | } |
| 1056 | 793 | |
| @@ -1099,9 +836,9 @@ | ||
| 1099 | 836 | $csv[] = $types; |
| 1100 | 837 | for ( $j = 0; $j < count( $columns[0] ); $j++ ) { |
| 1101 | 838 | $row = array(); |
| 1102 | 839 | for ( $i = 0; $i < count( $headers ); $i++ ) { |
| 1103 | - $row[] = sanitize_text_field( $columns[ $i ][ $j ] ); | |
| 840 | + $row[] = $columns[ $i ][ $j ]; | |
| 1104 | 841 | } |
| 1105 | 842 | $csv[] = $row; |
| 1106 | 843 | } |
| 1107 | 844 | |
| @@ -1154,10 +891,8 @@ | ||
| 1154 | 891 | status_header( 400 ); |
| 1155 | 892 | exit; |
| 1156 | 893 | } |
| 1157 | 894 | |
| 1158 | - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Uploading data for chart %d with POST = %s and GET = %s', $chart_id, print_r( $_POST, true ), print_r( $_GET, true ) ), 'debug', __FILE__, __LINE__ ); | |
| 1159 | - | |
| 1160 | 895 | if ( ! isset( $_POST['vz-import-time'] ) ) { |
| 1161 | 896 | apply_filters( 'visualizer_pro_remove_schedule', $chart_id ); |
| 1162 | 897 | } |
| 1163 | 898 | |
| @@ -1169,9 +904,8 @@ | ||
| 1169 | 904 | |
| 1170 | 905 | // delete "import from db" specific parameters. |
| 1171 | 906 | delete_post_meta( $chart_id, Visualizer_Plugin::CF_DB_QUERY ); |
| 1172 | 907 | delete_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE ); |
| 1173 | - delete_post_meta( $chart_id, Visualizer_Plugin::CF_REMOTE_DB_PARAMS ); | |
| 1174 | 908 | } |
| 1175 | 909 | |
| 1176 | 910 | // delete json related data. |
| 1177 | 911 | delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_URL ); |
| @@ -1176,51 +910,29 @@ | ||
| 1176 | 910 | // delete json related data. |
| 1177 | 911 | delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_URL ); |
| 1178 | 912 | delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_ROOT ); |
| 1179 | 913 | delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_PAGING ); |
| 1180 | - delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_HEADERS ); | |
| 1181 | 914 | |
| 1182 | - // delete last error | |
| 1183 | - delete_post_meta( $chart_id, Visualizer_Plugin::CF_ERROR ); | |
| 1184 | - | |
| 1185 | - // delete editor related data. | |
| 1186 | - delete_post_meta( $chart_id, Visualizer_Plugin::CF_EDITOR ); | |
| 1187 | - | |
| 1188 | - // delete this so that a JSON import can be later edited manually without a problem. | |
| 1189 | - delete_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE ); | |
| 1190 | - | |
| 1191 | 915 | $source = null; |
| 1192 | 916 | $render = new Visualizer_Render_Page_Update(); |
| 1193 | - | |
| 1194 | - $remote_data = false; | |
| 1195 | - if ( isset( $_POST['remote_data'] ) && function_exists( 'wp_http_validate_url' ) ) { | |
| 1196 | - $remote_data = wp_http_validate_url( $_POST['remote_data'] ); | |
| 1197 | - } | |
| 1198 | - if ( false !== $remote_data ) { | |
| 1199 | - $source = new Visualizer_Source_Csv_Remote( $remote_data ); | |
| 917 | + if ( isset( $_POST['remote_data'] ) && filter_var( $_POST['remote_data'], FILTER_VALIDATE_URL ) ) { | |
| 918 | + $source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] ); | |
| 1200 | 919 | if ( isset( $_POST['vz-import-time'] ) ) { |
| 1201 | - apply_filters( 'visualizer_pro_chart_schedule', $chart_id, $remote_data, $_POST['vz-import-time'] ); | |
| 920 | + apply_filters( 'visualizer_pro_chart_schedule', $chart_id, $_POST['remote_data'], $_POST['vz-import-time'] ); | |
| 1202 | 921 | } |
| 1203 | 922 | // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
| 1204 | 923 | } elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) { |
| 1205 | 924 | $source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] ); |
| 1206 | 925 | } elseif ( isset( $_POST['chart_data'] ) && strlen( $_POST['chart_data'] ) > 0 ) { |
| 1207 | - $source = $this->handleCSVasString( $_POST['chart_data'], $_POST['editor-type'] ); | |
| 1208 | - update_post_meta( $chart_id, Visualizer_Plugin::CF_EDITOR, $_POST['editor-type'] ); | |
| 926 | + $source = $this->handleCSVasString( $_POST['chart_data'] ); | |
| 1209 | 927 | } elseif ( isset( $_POST['table_data'] ) && 'yes' === $_POST['table_data'] ) { |
| 1210 | 928 | $source = $this->handleTabularData(); |
| 1211 | - update_post_meta( $chart_id, Visualizer_Plugin::CF_EDITOR, $_POST['editor-type'] ); | |
| 1212 | 929 | } else { |
| 1213 | - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'CSV file with chart data was not uploaded for chart %d.', $chart_id ), 'error', __FILE__, __LINE__ ); | |
| 1214 | - $render->message = esc_html__( 'CSV file with chart data was not uploaded. Please try again.', 'visualizer' ); | |
| 1215 | - update_post_meta( $chart_id, Visualizer_Plugin::CF_ERROR, esc_html__( 'CSV file with chart data was not uploaded. Please try again.', 'visualizer' ) ); | |
| 930 | + $render->message = esc_html__( 'CSV file with chart data was not uploaded. Please, try again.', 'visualizer' ); | |
| 1216 | 931 | } |
| 1217 | - | |
| 1218 | - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Uploaded data for chart %d with source %s', $chart_id, print_r( $source, true ) ), 'debug', __FILE__, __LINE__ ); | |
| 1219 | - | |
| 1220 | 932 | if ( $source ) { |
| 1221 | 933 | if ( $source->fetch() ) { |
| 1222 | - $content = $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ); | |
| 934 | + $content = $source->getData(); | |
| 1223 | 935 | $populate = true; |
| 1224 | 936 | if ( is_string( $content ) && is_array( unserialize( $content ) ) ) { |
| 1225 | 937 | $json = unserialize( $content ); |
| 1226 | 938 | // if source exists, so should data. if source exists but data is blank, do not populate the chart. |
| @@ -1226,9 +938,8 @@ | ||
| 1226 | 938 | // if source exists, so should data. if source exists but data is blank, do not populate the chart. |
| 1227 | 939 | // if we populate the data even if it is empty, the chart will show "Table has no columns". |
| 1228 | 940 | if ( array_key_exists( 'source', $json ) && ! empty( $json['source'] ) && ( ! array_key_exists( 'data', $json ) || empty( $json['data'] ) ) ) { |
| 1229 | 941 | 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__ ); |
| 1230 | - update_post_meta( $chart_id, Visualizer_Plugin::CF_ERROR, sprintf( 'Not populating chart data as source exists (%s) but data is empty!', $json['source'] ) ); | |
| 1231 | 942 | $populate = false; |
| 1232 | 943 | } |
| 1233 | 944 | } |
| 1234 | 945 | if ( $populate ) { |
| @@ -1234,43 +945,17 @@ | ||
| 1234 | 945 | if ( $populate ) { |
| 1235 | 946 | $chart->post_content = $content; |
| 1236 | 947 | } |
| 1237 | 948 | wp_update_post( $chart->to_array() ); |
| 1238 | - | |
| 1239 | 949 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); |
| 1240 | 950 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); |
| 1241 | 951 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, 0 ); |
| 1242 | - | |
| 1243 | - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Updated post for chart %d', $chart_id ), 'debug', __FILE__, __LINE__ ); | |
| 1244 | - | |
| 1245 | - Visualizer_Module_Utility::set_defaults( $chart, null ); | |
| 1246 | - | |
| 1247 | - $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true ); | |
| 1248 | - if ( isset( $settings['series'] ) && ! ( count( $settings['series'] ) - count( $source->getSeries() ) > 1 ) ) { | |
| 1249 | - $diff_total_series = abs( count( $settings['series'] ) - count( $source->getSeries() ) ); | |
| 1250 | - if ( $diff_total_series ) { | |
| 1251 | - foreach ( range( 1, $diff_total_series ) as $k => $diff_series ) { | |
| 1252 | - $settings['series'][] = end( $settings['series'] ); | |
| 1253 | - } | |
| 1254 | - update_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, $settings ); | |
| 1255 | - } | |
| 1256 | - } | |
| 1257 | - | |
| 1258 | 952 | $render->id = $chart->ID; |
| 1259 | - $render->data = json_encode( $source->getRawData( get_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) ); | |
| 953 | + $render->data = json_encode( $source->getRawData() ); | |
| 1260 | 954 | $render->series = json_encode( $source->getSeries() ); |
| 1261 | - $render->settings = json_encode( $settings ); | |
| 1262 | 955 | } else { |
| 1263 | - $error = $source->get_error(); | |
| 1264 | - if ( empty( $error ) ) { | |
| 1265 | - $error = esc_html__( 'CSV file is broken or invalid. Please try again.', 'visualizer' ); | |
| 1266 | - } | |
| 1267 | - $render->message = $error; | |
| 1268 | - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( '%s for chart %d.', $error, $chart_id ), 'error', __FILE__, __LINE__ ); | |
| 1269 | - update_post_meta( $chart_id, Visualizer_Plugin::CF_ERROR, $error ); | |
| 956 | + $render->message = esc_html__( 'CSV file is broken or invalid. Please, try again.', 'visualizer' ); | |
| 1270 | 957 | } |
| 1271 | - } else { | |
| 1272 | - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unknown internal error for chart %d.', $chart_id ), 'error', __FILE__, __LINE__ ); | |
| 1273 | 958 | } |
| 1274 | 959 | $render->render(); |
| 1275 | 960 | if ( ! $can_die ) { |
| 1276 | 961 | return; |
| @@ -1286,18 +971,27 @@ | ||
| 1286 | 971 | * @access public |
| 1287 | 972 | */ |
| 1288 | 973 | public function cloneChart() { |
| 1289 | 974 | $chart_id = $success = false; |
| 1290 | - $nonce = isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'], Visualizer_Plugin::ACTION_CLONE_CHART ); | |
| 975 | + $nonce = wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ), Visualizer_Plugin::ACTION_CLONE_CHART ); | |
| 1291 | 976 | $capable = current_user_can( 'edit_posts' ); |
| 1292 | 977 | if ( $nonce && $capable ) { |
| 1293 | - $chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : ''; | |
| 978 | + $chart_id = filter_input( | |
| 979 | + INPUT_GET, | |
| 980 | + 'chart', | |
| 981 | + FILTER_VALIDATE_INT, | |
| 982 | + array( | |
| 983 | + 'options' => array( | |
| 984 | + 'min_range' => 1, | |
| 985 | + ), | |
| 986 | + ) | |
| 987 | + ); | |
| 1294 | 988 | if ( $chart_id ) { |
| 1295 | 989 | $chart = get_post( $chart_id ); |
| 1296 | 990 | $success = $chart && $chart->post_type === Visualizer_Plugin::CPT_VISUALIZER; |
| 1297 | 991 | } |
| 1298 | 992 | } |
| 1299 | - $redirect = remove_query_arg( 'vaction', wp_get_referer() ); | |
| 993 | + $redirect = wp_get_referer(); | |
| 1300 | 994 | if ( $success ) { |
| 1301 | 995 | $new_chart_id = wp_insert_post( |
| 1302 | 996 | array( |
| 1303 | 997 | 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, |
| @@ -1306,35 +1000,23 @@ | ||
| 1306 | 1000 | 'post_status' => $chart->post_status, |
| 1307 | 1001 | 'post_content' => $chart->post_content, |
| 1308 | 1002 | ) |
| 1309 | 1003 | ); |
| 1310 | - if ( is_wp_error( $new_chart_id ) ) { | |
| 1311 | - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Error while cloning chart %d = %s', $chart_id, print_r( $new_chart_id, true ) ), 'error', __FILE__, __LINE__ ); | |
| 1312 | - } else { | |
| 1313 | - $post_meta = get_post_meta( $chart_id ); | |
| 1314 | - foreach ( $post_meta as $key => $value ) { | |
| 1315 | - if ( strpos( $key, 'visualizer-' ) !== false ) { | |
| 1316 | - add_post_meta( $new_chart_id, $key, maybe_unserialize( $value[0] ) ); | |
| 1317 | - } | |
| 1318 | - } | |
| 1319 | - $redirect = esc_url( | |
| 1320 | - add_query_arg( | |
| 1321 | - array( | |
| 1322 | - 'page' => 'visualizer', | |
| 1323 | - 'type' => filter_input( INPUT_GET, 'type' ), | |
| 1324 | - 'vaction' => false, | |
| 1325 | - ), | |
| 1326 | - admin_url( 'admin.php' ) | |
| 1004 | + if ( $new_chart_id && ! is_wp_error( $new_chart_id ) ) { | |
| 1005 | + add_post_meta( $new_chart_id, Visualizer_Plugin::CF_CHART_TYPE, get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true ) ); | |
| 1006 | + add_post_meta( $new_chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, get_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, true ) ); | |
| 1007 | + add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SOURCE, get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) ); | |
| 1008 | + add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SERIES, get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true ) ); | |
| 1009 | + add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SETTINGS, get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true ) ); | |
| 1010 | + $redirect = add_query_arg( | |
| 1011 | + array( | |
| 1012 | + 'page' => 'visualizer', | |
| 1013 | + 'type' => filter_input( INPUT_GET, 'type' ), | |
| 1327 | 1014 | ), |
| 1328 | - null, | |
| 1329 | - 'db' | |
| 1015 | + admin_url( 'upload.php' ) | |
| 1330 | 1016 | ); |
| 1331 | 1017 | } |
| 1332 | 1018 | } |
| 1333 | - | |
| 1334 | - if ( defined( 'WP_TESTS_DOMAIN' ) ) { | |
| 1335 | - wp_die(); | |
| 1336 | - } | |
| 1337 | 1019 | wp_redirect( $redirect ); |
| 1338 | 1020 | exit; |
| 1339 | 1021 | } |
| 1340 | 1022 | |
| @@ -1380,12 +1062,9 @@ | ||
| 1380 | 1062 | $data = $this->_getChartArray(); |
| 1381 | 1063 | $render = new Visualizer_Render_Page_Data(); |
| 1382 | 1064 | $render->chart = $this->_chart; |
| 1383 | 1065 | $render->type = $data['type']; |
| 1384 | - | |
| 1385 | - if ( $data && $data['settings'] ) { | |
| 1386 | - unset( $data['settings']['width'], $data['settings']['height'], $data['settings']['chartArea'] ); | |
| 1387 | - } | |
| 1066 | + unset( $data['settings']['width'], $data['settings']['height'] ); | |
| 1388 | 1067 | wp_enqueue_style( 'visualizer-frame' ); |
| 1389 | 1068 | wp_enqueue_script( 'visualizer-render' ); |
| 1390 | 1069 | wp_localize_script( |
| 1391 | 1070 | 'visualizer-render', |
| @@ -1391,9 +1070,9 @@ | ||
| 1391 | 1070 | 'visualizer-render', |
| 1392 | 1071 | 'visualizer', |
| 1393 | 1072 | array( |
| 1394 | 1073 | 'l10n' => array( |
| 1395 | - 'invalid_source' => esc_html__( 'You have entered an invalid URL. Please provide a valid URL.', 'visualizer' ), | |
| 1074 | + 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ), | |
| 1396 | 1075 | 'loading' => esc_html__( 'Loading...', 'visualizer' ), |
| 1397 | 1076 | ), |
| 1398 | 1077 | 'charts' => array( |
| 1399 | 1078 | 'canvas' => $data, |
| @@ -1399,16 +1078,13 @@ | ||
| 1399 | 1078 | 'canvas' => $data, |
| 1400 | 1079 | ), |
| 1401 | 1080 | ) |
| 1402 | 1081 | ); |
| 1403 | - | |
| 1404 | - do_action( 'visualizer_enqueue_scripts_and_styles', $data, $this->_chart->ID ); | |
| 1405 | - | |
| 1406 | - if ( Visualizer_Module::is_pro() && Visualizer_Module::is_pro_older_than( '1.9.0' ) ) { | |
| 1082 | + // Added by Ash/Upwork | |
| 1083 | + if ( VISUALIZER_PRO ) { | |
| 1407 | 1084 | global $Visualizer_Pro; |
| 1408 | - $Visualizer_Pro->_enqueueScriptsAndStyles( $data, $this->_chart->ID ); | |
| 1085 | + $Visualizer_Pro->_enqueueScriptsAndStyles( $data ); | |
| 1409 | 1086 | } |
| 1410 | - | |
| 1411 | 1087 | // Added by Ash/Upwork |
| 1412 | 1088 | $this->_addAction( 'admin_head', 'renderFlattrScript' ); |
| 1413 | 1089 | wp_iframe( array( $render, 'render' ) ); |
| 1414 | 1090 | } |
| @@ -1420,19 +1096,14 @@ | ||
| 1420 | 1096 | */ |
| 1421 | 1097 | public function getQueryData() { |
| 1422 | 1098 | check_ajax_referer( Visualizer_Plugin::ACTION_FETCH_DB_DATA . Visualizer_Plugin::VERSION, 'security' ); |
| 1423 | 1099 | |
| 1424 | - if ( ! current_user_can( 'administrator' ) ) { | |
| 1425 | - wp_send_json_error( array( 'msg' => __( 'Action not allowed for this user.', 'visualizer' ) ) ); | |
| 1426 | - } | |
| 1427 | - | |
| 1428 | 1100 | $params = wp_parse_args( $_POST['params'] ); |
| 1429 | - $chart_id = filter_var( $params['chart_id'], FILTER_VALIDATE_INT ); | |
| 1430 | - | |
| 1431 | - $source = new Visualizer_Source_Query( stripslashes( $params['query'] ), $chart_id, $params ); | |
| 1101 | + $source = new Visualizer_Source_Query( stripslashes( $params['query'] ) ); | |
| 1432 | 1102 | $html = $source->fetch( true ); |
| 1433 | - $error = $source->get_error(); | |
| 1434 | - if ( ! empty( $error ) ) { | |
| 1103 | + $error = ''; | |
| 1104 | + if ( empty( $html ) ) { | |
| 1105 | + $error = $source->get_error(); | |
| 1435 | 1106 | wp_send_json_error( array( 'msg' => $error ) ); |
| 1436 | 1107 | } |
| 1437 | 1108 | wp_send_json_success( array( 'table' => $html ) ); |
| 1438 | 1109 | } |
| @@ -1455,42 +1126,21 @@ | ||
| 1455 | 1126 | ), |
| 1456 | 1127 | ) |
| 1457 | 1128 | ); |
| 1458 | 1129 | |
| 1459 | - $hours = filter_input( | |
| 1460 | - INPUT_POST, | |
| 1461 | - 'refresh', | |
| 1462 | - FILTER_VALIDATE_FLOAT, | |
| 1463 | - array( | |
| 1464 | - 'options' => array( | |
| 1465 | - 'min_range' => -1, | |
| 1466 | - 'max_range' => apply_filters( 'visualizer_is_business', false ) ? PHP_INT_MAX : -1, | |
| 1467 | - ), | |
| 1468 | - ) | |
| 1469 | - ); | |
| 1470 | - | |
| 1471 | - if ( ! is_numeric( $hours ) ) { | |
| 1472 | - $hours = -1; | |
| 1473 | - } | |
| 1474 | - | |
| 1475 | 1130 | $render = new Visualizer_Render_Page_Update(); |
| 1476 | 1131 | if ( $chart_id ) { |
| 1477 | 1132 | $params = wp_parse_args( $_POST['params'] ); |
| 1478 | - $source = new Visualizer_Source_Query( stripslashes( $params['query'] ), $chart_id, $params ); | |
| 1133 | + $source = new Visualizer_Source_Query( stripslashes( $params['query'] ) ); | |
| 1479 | 1134 | $source->fetch( false ); |
| 1480 | 1135 | $error = $source->get_error(); |
| 1481 | 1136 | if ( empty( $error ) ) { |
| 1137 | + $hours = $_POST['refresh']; | |
| 1482 | 1138 | update_post_meta( $chart_id, Visualizer_Plugin::CF_DB_QUERY, stripslashes( $params['query'] ) ); |
| 1483 | 1139 | update_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); |
| 1484 | 1140 | update_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); |
| 1485 | 1141 | update_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, $hours ); |
| 1486 | 1142 | update_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 0 ); |
| 1487 | - if ( isset( $params['db_type'] ) && $params['db_type'] !== Visualizer_Plugin::WP_DB_NAME ) { | |
| 1488 | - $remote_db_params = $params; | |
| 1489 | - unset( $remote_db_params['query'] ); | |
| 1490 | - unset( $remote_db_params['chart_id'] ); | |
| 1491 | - update_post_meta( $chart_id, Visualizer_Plugin::CF_REMOTE_DB_PARAMS, $remote_db_params ); | |
| 1492 | - } | |
| 1493 | 1143 | |
| 1494 | 1144 | $schedules = get_option( Visualizer_Plugin::CF_DB_SCHEDULE, array() ); |
| 1495 | 1145 | $schedules[ $chart_id ] = time() + $hours * HOUR_IN_SECONDS; |
| 1496 | 1146 | update_option( Visualizer_Plugin::CF_DB_SCHEDULE, $schedules ); |
| @@ -1497,14 +1147,13 @@ | ||
| 1497 | 1147 | |
| 1498 | 1148 | wp_update_post( |
| 1499 | 1149 | array( |
| 1500 | 1150 | 'ID' => $chart_id, |
| 1501 | - 'post_content' => $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ), | |
| 1151 | + 'post_content' => $source->getData(), | |
| 1502 | 1152 | ) |
| 1503 | 1153 | ); |
| 1504 | - $render->data = json_encode( $source->getRawData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) ); | |
| 1154 | + $render->data = json_encode( $source->getRawData() ); | |
| 1505 | 1155 | $render->series = json_encode( $source->getSeries() ); |
| 1506 | - $render->id = $chart_id; | |
| 1507 | 1156 | } else { |
| 1508 | 1157 | $render->message = $error; |
| 1509 | 1158 | } |
| 1510 | 1159 | } |
| @@ -1533,80 +1182,13 @@ | ||
| 1533 | 1182 | ), |
| 1534 | 1183 | ) |
| 1535 | 1184 | ); |
| 1536 | 1185 | |
| 1537 | - $hours = filter_input( | |
| 1538 | - INPUT_POST, | |
| 1539 | - 'refresh', | |
| 1540 | - FILTER_VALIDATE_INT, | |
| 1541 | - array( | |
| 1542 | - 'options' => array( | |
| 1543 | - 'min_range' => -1, | |
| 1544 | - 'max_range' => apply_filters( 'visualizer_is_business', false ) ? PHP_INT_MAX : -1, | |
| 1545 | - ), | |
| 1546 | - ) | |
| 1547 | - ); | |
| 1186 | + $hours = $_POST['refresh']; | |
| 1548 | 1187 | |
| 1549 | - if ( 0 !== $hours && empty( $hours ) ) { | |
| 1550 | - $hours = -1; | |
| 1551 | - } | |
| 1552 | - | |
| 1553 | 1188 | do_action( 'visualizer_save_filter', $chart_id, $hours ); |
| 1554 | 1189 | |
| 1555 | 1190 | if ( ! ( defined( 'VISUALIZER_DO_NOT_DIE' ) && VISUALIZER_DO_NOT_DIE ) ) { |
| 1556 | 1191 | defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); |
| 1557 | 1192 | } |
| 1558 | - } | |
| 1559 | - | |
| 1560 | - /** | |
| 1561 | - * Save chart image. | |
| 1562 | - * | |
| 1563 | - * @param string $base64_img Chart image. | |
| 1564 | - * @param int $chart_id Chart ID. | |
| 1565 | - * @param bool $save_attachment Save attachment. | |
| 1566 | - * @return attachment ID | |
| 1567 | - */ | |
| 1568 | - public function save_chart_image( $base64_img, $chart_id, $save_attachment = true ) { | |
| 1569 | - // Delete old chart image. | |
| 1570 | - $old_attachment_id = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_IMAGE, true ); | |
| 1571 | - if ( $old_attachment_id ) { | |
| 1572 | - wp_delete_attachment( $old_attachment_id, true ); | |
| 1573 | - } | |
| 1574 | - | |
| 1575 | - if ( ! $save_attachment ) { | |
| 1576 | - return 0; | |
| 1577 | - } | |
| 1578 | - | |
| 1579 | - // Upload dir. | |
| 1580 | - $upload_dir = wp_upload_dir(); | |
| 1581 | - $upload_path = str_replace( '/', DIRECTORY_SEPARATOR, $upload_dir['path'] ) . DIRECTORY_SEPARATOR; | |
| 1582 | - | |
| 1583 | - $img = str_replace( 'data:image/png;base64,', '', $base64_img ); | |
| 1584 | - $img = str_replace( ' ', '+', $img ); | |
| 1585 | - $decoded = base64_decode( $img ); | |
| 1586 | - $filename = 'visualization-' . $chart_id . '.png'; | |
| 1587 | - $file_type = 'image/png'; | |
| 1588 | - $hashed_filename = $filename; | |
| 1589 | - | |
| 1590 | - // Save the image in the uploads directory. | |
| 1591 | - require_once ABSPATH . '/wp-admin/includes/file.php'; | |
| 1592 | - \WP_Filesystem(); | |
| 1593 | - global $wp_filesystem; | |
| 1594 | - if ( ! is_a( $wp_filesystem, 'WP_Filesystem_Base' ) ) { | |
| 1595 | - $creds = request_filesystem_credentials( site_url() ); | |
| 1596 | - wp_filesystem( $creds ); | |
| 1597 | - } | |
| 1598 | - $upload_file = $wp_filesystem->put_contents( $upload_path . $hashed_filename, $decoded ); | |
| 1599 | - | |
| 1600 | - // Insert new chart image. | |
| 1601 | - $attachment = array( | |
| 1602 | - 'post_mime_type' => $file_type, | |
| 1603 | - 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $hashed_filename ) ), | |
| 1604 | - 'post_content' => '', | |
| 1605 | - 'post_status' => 'inherit', | |
| 1606 | - 'guid' => $upload_dir['url'] . '/' . basename( $hashed_filename ), | |
| 1607 | - ); | |
| 1608 | - | |
| 1609 | - $attach_id = wp_insert_attachment( $attachment, $upload_dir['path'] . '/' . $hashed_filename ); | |
| 1610 | - return $attach_id; | |
| 1611 | 1193 | } |
| 1612 | 1194 | } |