PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.8
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.8
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 3.10.4 All 148 releases
← All changes | classes/Visualizer/Module/Chart.php +42 -240 3.10.123.4.8 View file →
@@ -134,30 +134,12 @@
134 134 ),
135 135 )
136 136 );
137 137
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 138 delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE );
153 139
154 140 if ( -1 < $time ) {
155 141 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 142 }
161 143 wp_send_json_success();
162 144 }
163 145
@@ -259,16 +241,8 @@
259 241 if ( ! empty( $params['paging'] ) ) {
260 242 add_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_PAGING, $params['paging'] );
261 243 }
262 244
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 245 $time = filter_input(
272 246 INPUT_POST,
273 247 'time',
274 248 FILTER_VALIDATE_INT,
@@ -460,22 +434,9 @@
460 434 $success = $chart && $chart->post_type === Visualizer_Plugin::CPT_VISUALIZER;
461 435 }
462 436 }
463 437 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 - }
438 + wp_delete_post( $chart_id, true );
478 439 }
479 440 if ( $is_post ) {
480 441 self::_sendResponse(
481 442 array(
@@ -524,104 +485,43 @@
524 485 * @access public
525 486 */
526 487 public function renderChartPages() {
527 488 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 489 // check chart, if chart not exists, will create new one and redirects to the same page with proper chart id
534 490 $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 491 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(
492 + $this->deleteOldCharts();
493 + $default_type = isset( $_GET['type'] ) && ! empty( $_GET['type'] ) ? $_GET['type'] : 'line';
494 + $source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $default_type . '.csv' );
495 + $source->fetch();
496 + $chart_id = wp_insert_post(
497 + array(
498 + 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
499 + 'post_title' => 'Visualization',
500 + 'post_author' => get_current_user_id(),
501 + 'post_status' => 'auto-draft',
502 + 'post_content' => $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ),
503 + )
504 + );
505 + if ( $chart_id && ! is_wp_error( $chart_id ) ) {
506 + add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, $default_type );
507 + add_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 1 );
508 + add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
509 + add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
510 + add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, '' );
511 + add_post_meta(
512 + $chart_id,
513 + Visualizer_Plugin::CF_SETTINGS,
549 514 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 ) ),
515 + 'focusTarget' => 'datum',
555 516 )
556 517 );
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 518 do_action( 'visualizer_pro_new_chart_defaults', $chart_id );
606 519 }
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();
520 + wp_redirect( add_query_arg( 'chart', (int) $chart_id ) );
521 + defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
613 522 }
614 523
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;
617 -
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 524 $lib = $this->load_chart_type( $chart_id );
625 525
626 526 // the alpha color picker (RGBA) is not supported by google.
627 527 $color_picker_dep = 'wp-color-picker';
@@ -683,16 +583,8 @@
683 583 // if the edit button is clicked.
684 584 $this->_chart = $this->handleExistingRevisions( $chart_id, $this->_chart );
685 585 }
686 586
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 587 switch ( $tab ) {
696 588 case 'settings':
697 589 $this->_handleDataAndSettingsPage();
698 590 break;
@@ -717,9 +609,9 @@
717 609
718 610 // data tables assets.
719 611 wp_register_script( 'visualizer-datatables', VISUALIZER_ABSURL . 'js/lib/datatables.min.js', array( 'jquery-ui-core' ), Visualizer_Plugin::VERSION );
720 612 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 );
613 + 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 614 wp_enqueue_script( 'visualizer-datatables' );
723 615 wp_enqueue_style( 'visualizer-jquery-ui' );
724 616
725 617 if ( ! Visualizer_Module::is_pro() ) {
@@ -814,14 +706,8 @@
814 706 if ( empty( $title ) ) {
815 707 $title = $this->_chart->ID;
816 708 }
817 709 $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 710 update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $settings );
825 711 }
826 712 $render = new Visualizer_Render_Page_Send();
827 713 $render->text = sprintf( '[visualizer id="%d"]', $this->_chart->ID );
@@ -909,9 +795,8 @@
909 795 'page_type' => 'chart',
910 796 'json_tag_separator' => Visualizer_Source_Json::TAG_SEPARATOR,
911 797 'json_tag_separator_view' => Visualizer_Source_Json::TAG_SEPARATOR_VIEW,
912 798 'is_front' => false,
913 - 'rest_base' => get_rest_url( null, 'wc/v3/reports/' ),
914 799 )
915 800 );
916 801
917 802 $render = new Visualizer_Render_Page_Data();
@@ -952,9 +837,9 @@
952 837 // process post request
953 838 if ( $_SERVER['REQUEST_METHOD'] === 'POST' && wp_verify_nonce( filter_input( INPUT_POST, 'nonce' ) ) ) {
954 839 $type = filter_input( INPUT_POST, 'type' );
955 840 $library = filter_input( INPUT_POST, 'chart-library' );
956 - if ( Visualizer_Module_Admin::checkChartStatus( $type ) ) {
841 + if ( in_array( $type, Visualizer_Plugin::getChartTypes(), true ) ) {
957 842 if ( empty( $library ) ) {
958 843 // library cannot be empty.
959 844 do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'Chart library empty while creating the chart! Aborting...', 'error', __FILE__, __LINE__ );
960 845 return;
@@ -975,9 +860,9 @@
975 860 Visualizer_Module_Utility::set_defaults( $this->_chart );
976 861
977 862 // redirect to next tab
978 863 // changed by Ash/Upwork
979 - wp_redirect( esc_url_raw( add_query_arg( 'tab', 'settings' ) ) );
864 + wp_redirect( add_query_arg( 'tab', 'settings' ) );
980 865
981 866 return;
982 867 }
983 868 }
@@ -1020,16 +905,8 @@
1020 905 foreach ( $values as $row ) {
1021 906 if ( empty( $row ) ) {
1022 907 continue;
1023 908 }
1024 - $row = explode( ',', $row );
1025 - $row = array_map(
1026 - function( $r ) {
1027 - return '' === $r ? ' ' : $r;
1028 - },
1029 - $row
1030 - );
1031 - $row = implode( ',', $row );
1032 909 // don't use fpucsv here because we need to just dump the data
1033 910 // minus the empty rows
1034 911 // because fputcsv needs to tokenize
1035 912 // we can standardize the CSV enclosure here and replace all ' with "
@@ -1189,17 +1066,12 @@
1189 1066 delete_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE );
1190 1067
1191 1068 $source = null;
1192 1069 $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 );
1070 + if ( isset( $_POST['remote_data'] ) && filter_var( $_POST['remote_data'], FILTER_VALIDATE_URL ) ) {
1071 + $source = new Visualizer_Source_Csv_Remote( $_POST['remote_data'] );
1200 1072 if ( isset( $_POST['vz-import-time'] ) ) {
1201 - apply_filters( 'visualizer_pro_chart_schedule', $chart_id, $remote_data, $_POST['vz-import-time'] );
1073 + apply_filters( 'visualizer_pro_chart_schedule', $chart_id, $_POST['remote_data'], $_POST['vz-import-time'] );
1202 1074 }
1203 1075 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1204 1076 } elseif ( isset( $_FILES['local_data'] ) && $_FILES['local_data']['error'] == 0 ) {
1205 1077 $source = new Visualizer_Source_Csv( $_FILES['local_data']['tmp_name'] );
@@ -1234,9 +1106,8 @@
1234 1106 if ( $populate ) {
1235 1107 $chart->post_content = $content;
1236 1108 }
1237 1109 wp_update_post( $chart->to_array() );
1238 -
1239 1110 update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
1240 1111 update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
1241 1112 update_post_meta( $chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, 0 );
1242 1113
@@ -1244,17 +1115,8 @@
1244 1115
1245 1116 Visualizer_Module_Utility::set_defaults( $chart, null );
1246 1117
1247 1118 $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 1119
1258 1120 $render->id = $chart->ID;
1259 1121 $render->data = json_encode( $source->getRawData( get_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) );
1260 1122 $render->series = json_encode( $source->getSeries() );
@@ -1315,19 +1177,15 @@
1315 1177 if ( strpos( $key, 'visualizer-' ) !== false ) {
1316 1178 add_post_meta( $new_chart_id, $key, maybe_unserialize( $value[0] ) );
1317 1179 }
1318 1180 }
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' )
1181 + $redirect = add_query_arg(
1182 + array(
1183 + 'page' => 'visualizer',
1184 + 'type' => filter_input( INPUT_GET, 'type' ),
1185 + 'vaction' => false,
1327 1186 ),
1328 - null,
1329 - 'db'
1187 + admin_url( 'admin.php' )
1330 1188 );
1331 1189 }
1332 1190 }
1333 1191
@@ -1333,8 +1191,9 @@
1333 1191
1334 1192 if ( defined( 'WP_TESTS_DOMAIN' ) ) {
1335 1193 wp_die();
1336 1194 }
1195 +
1337 1196 wp_redirect( $redirect );
1338 1197 exit;
1339 1198 }
1340 1199
@@ -1420,12 +1279,8 @@
1420 1279 */
1421 1280 public function getQueryData() {
1422 1281 check_ajax_referer( Visualizer_Plugin::ACTION_FETCH_DB_DATA . Visualizer_Plugin::VERSION, 'security' );
1423 1282
1424 - if ( ! current_user_can( 'edit_posts' ) ) {
1425 - wp_send_json_error( array( 'msg' => __( 'Action not allowed for this user.', 'visualizer' ) ) );
1426 - }
1427 -
1428 1283 $params = wp_parse_args( $_POST['params'] );
1429 1284 $chart_id = filter_var( $params['chart_id'], FILTER_VALIDATE_INT );
1430 1285
1431 1286 $source = new Visualizer_Source_Query( stripslashes( $params['query'] ), $chart_id, $params );
@@ -1458,9 +1313,9 @@
1458 1313
1459 1314 $hours = filter_input(
1460 1315 INPUT_POST,
1461 1316 'refresh',
1462 - FILTER_VALIDATE_FLOAT,
1317 + FILTER_VALIDATE_INT,
1463 1318 array(
1464 1319 'options' => array(
1465 1320 'min_range' => -1,
1466 1321 'max_range' => apply_filters( 'visualizer_is_business', false ) ? PHP_INT_MAX : -1,
@@ -1467,9 +1322,9 @@
1467 1322 ),
1468 1323 )
1469 1324 );
1470 1325
1471 - if ( ! is_numeric( $hours ) ) {
1326 + if ( ! is_int( $hours ) ) {
1472 1327 $hours = -1;
1473 1328 }
1474 1329
1475 1330 $render = new Visualizer_Render_Page_Update();
@@ -1545,9 +1400,9 @@
1545 1400 ),
1546 1401 )
1547 1402 );
1548 1403
1549 - if ( 0 !== $hours && empty( $hours ) ) {
1404 + if ( ! $hours ) {
1550 1405 $hours = -1;
1551 1406 }
1552 1407
1553 1408 do_action( 'visualizer_save_filter', $chart_id, $hours );
@@ -1554,59 +1409,6 @@
1554 1409
1555 1410 if ( ! ( defined( 'VISUALIZER_DO_NOT_DIE' ) && VISUALIZER_DO_NOT_DIE ) ) {
1556 1411 defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
1557 1412 }
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 1413 }
1612 1414 }