Skip to content

Commit ad22ce3

Browse files
release(minor): fixes and new features
- Fixed table chart decimal number issue Decimal Numbers are ignored and not displayed #955 - Fix the scrollbar issue that happens on WP 6.1 version [WP 6.1] Chart permissions selector is not scrollable #950 - Fix PHP Warning Warning when copy (frontend action) is enabled #949 - Compatibility with the WPML translation plugin for translating charts [PRO feature] add support for string translations #731 - Integration with Woocommerce Data endpoints for creating charts [PRO feature] - Show new features on chart library page
2 parents 99e1b40 + 1c811c6 commit ad22ce3

File tree

16 files changed

+401
-49
lines changed

16 files changed

+401
-49
lines changed

classes/Visualizer/Gutenberg/build/block.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

classes/Visualizer/Gutenberg/build/block.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

classes/Visualizer/Gutenberg/src/Components/ChartPermissions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class ChartPermissions extends Component {
7373
<PanelBody
7474
title={ __( 'Who can see this chart?' ) }
7575
initialOpen={ false }
76+
className="vz-permission-tab"
7677
>
7778

7879
<SelectControl
@@ -128,6 +129,7 @@ class ChartPermissions extends Component {
128129
<PanelBody
129130
title={ __( 'Who can edit this chart?' ) }
130131
initialOpen={ false }
132+
className="vz-permission-tab"
131133
>
132134

133135
<SelectControl

classes/Visualizer/Gutenberg/src/style.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,11 @@
377377
.DTCR_pointer {
378378
z-index: 999999 !important;
379379
}
380-
380+
.vz-permission-tab {
381+
select.components-select-control__input {
382+
overflow:auto !important;
383+
}
384+
}
381385
.components-panel {
382386
.components-select-control {
383387
height:auto !important;

classes/Visualizer/Module.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ private function _getCSV( $rows, $filename, $enclose ) {
269269
$filename .= '.csv';
270270

271271
$bom = chr( 0xEF ) . chr( 0xBB ) . chr( 0xBF );
272-
$fp = tmpfile();
272+
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
273+
$fp = @tmpfile();
273274
if ( null === $fp ) {
274275
$fp = fopen( wp_tempnam(), 'w+' );
275276
}
@@ -732,7 +733,7 @@ public static function can_show_feature( $feature ) {
732733
public static final function get_features_for_license( $plan ) {
733734
switch ( $plan ) {
734735
case 1:
735-
return array( 'import-wp', 'db-query' );
736+
return array( 'import-wp', 'db-query', 'import-wc-report' );
736737
case 2:
737738
return array( 'schedule-chart', 'chart-permissions' );
738739
}

classes/Visualizer/Module/Admin.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public function __construct( Visualizer_Plugin $plugin ) {
7474

7575
$this->_addAction( 'admin_init', 'init' );
7676

77+
$this->_addAction( 'visualizer_chart_languages', 'addMultilingualSupport' );
78+
7779
if ( defined( 'TI_CYPRESS_TESTING' ) ) {
7880
$this->load_cypress_hooks();
7981
}
@@ -767,6 +769,22 @@ function setScreenOptions( $status, $option, $value ) {
767769
private function getDisplayFilters( &$query_args ) {
768770
$query = array();
769771

772+
if ( Visualizer_Module::is_pro() && function_exists( 'icl_get_languages' ) ) {
773+
$current_lang = icl_get_current_language();
774+
if ( in_array( $current_lang, array( 'all', icl_get_default_language() ), true ) ) {
775+
$query[] = array(
776+
'key' => 'chart_lang',
777+
'compare' => 'NOT EXISTS',
778+
);
779+
} else {
780+
$query[] = array(
781+
'key' => 'chart_lang',
782+
'value' => $current_lang,
783+
'compare' => '=',
784+
);
785+
}
786+
}
787+
770788
// add chart type filter to the query arguments
771789
$type = filter_input( INPUT_GET, 'type' );
772790
if ( $type && in_array( $type, Visualizer_Plugin::getChartTypes(), true ) ) {
@@ -1112,4 +1130,49 @@ public static function proFeaturesLocked() {
11121130
}
11131131
return 'yes' === get_option( 'visualizer-new-user', 'yes' ) ? false : true;
11141132
}
1133+
1134+
/**
1135+
* Multilingual Support.
1136+
*
1137+
* @param int $chart_id Chart ID.
1138+
* @return bool Default false
1139+
*/
1140+
public function addMultilingualSupport( $chart_id ) {
1141+
if ( Visualizer_Module::is_pro() ) {
1142+
return;
1143+
}
1144+
if ( function_exists( 'icl_get_languages' ) ) {
1145+
$language = icl_get_languages();
1146+
$current_lang = icl_get_current_language();
1147+
$default_lang = icl_get_default_language();
1148+
$post_info = wpml_get_language_information( null, $chart_id );
1149+
1150+
global $sitepress;
1151+
$translations = array();
1152+
if ( ! empty( $post_info ) && ( $default_lang === $post_info['language_code'] ) ) {
1153+
$trid = $sitepress->get_element_trid( $chart_id, 'post_' . Visualizer_Plugin::CPT_VISUALIZER );
1154+
$translations = $sitepress->get_element_translations( $trid );
1155+
}
1156+
if ( empty( $translations ) ) {
1157+
return;
1158+
}
1159+
?>
1160+
<hr><div class="visualizer-languages-list only-pro">
1161+
<?php
1162+
foreach ( $language as $lang ) {
1163+
$lang_code = $lang['code'];
1164+
if ( $current_lang !== $lang_code ) {
1165+
?>
1166+
<a href="javascript:;">
1167+
<img src="<?php echo esc_url( $lang['country_flag_url'] ); ?>" alt="<?php echo esc_attr( $lang['translated_name'] ); ?>">
1168+
</a>
1169+
<?php
1170+
}
1171+
}
1172+
?>
1173+
<a href="<?php echo tsdk_utmify( Visualizer_Plugin::PRO_TEASER_URL, 'wpml-support', 'visualizer_render_char' ); ?>"target="_blank"><?php esc_html_e( 'Upgrade to PRO to active this translation for charts', 'visualizer' ); ?></a>
1174+
</div>
1175+
<?php
1176+
}
1177+
}
11151178
}

classes/Visualizer/Module/Chart.php

Lines changed: 96 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,20 @@ public function setJsonSchedule() {
135135
)
136136
);
137137

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+
138152
delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE );
139153

140154
if ( -1 < $time ) {
@@ -246,6 +260,14 @@ public function setJsonData() {
246260
add_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_PAGING, $params['paging'] );
247261
}
248262

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+
249271
$time = filter_input(
250272
INPUT_POST,
251273
'time',
@@ -439,7 +461,20 @@ public function deleteChart() {
439461
}
440462
}
441463
if ( $success ) {
442-
wp_delete_post( $chart_id, true );
464+
if ( Visualizer_Module::is_pro() && function_exists( 'icl_get_languages' ) ) {
465+
global $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+
}
443478
}
444479
if ( $is_post ) {
445480
self::_sendResponse(
@@ -498,32 +533,68 @@ public function renderChartPages() {
498533
// check chart, if chart not exists, will create new one and redirects to the same page with proper chart id
499534
$chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : '';
500535
if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ) {
501-
$this->deleteOldCharts();
502-
$default_type = isset( $_GET['type'] ) && ! empty( $_GET['type'] ) ? $_GET['type'] : 'line';
503-
$source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $default_type . '.csv' );
504-
$source->fetch();
505-
$chart_id = wp_insert_post(
506-
array(
507-
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
508-
'post_title' => 'Visualization',
509-
'post_author' => get_current_user_id(),
510-
'post_status' => 'auto-draft',
511-
'post_content' => $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ),
512-
)
513-
);
514-
if ( $chart_id && ! is_wp_error( $chart_id ) ) {
515-
add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, $default_type );
516-
add_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 1 );
517-
add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
518-
add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
519-
add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, '' );
520-
add_post_meta(
521-
$chart_id,
522-
Visualizer_Plugin::CF_SETTINGS,
536+
if ( empty( $_GET['lang'] ) || empty( $_GET['parent_chart_id'] ) ) {
537+
$this->deleteOldCharts();
538+
$default_type = isset( $_GET['type'] ) && ! empty( $_GET['type'] ) ? $_GET['type'] : 'line';
539+
$source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $default_type . '.csv' );
540+
$source->fetch();
541+
$chart_id = wp_insert_post(
523542
array(
524-
'focusTarget' => 'datum',
543+
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
544+
'post_title' => 'Visualization',
545+
'post_author' => get_current_user_id(),
546+
'post_status' => 'auto-draft',
547+
'post_content' => $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ),
525548
)
526549
);
550+
if ( $chart_id && ! is_wp_error( $chart_id ) ) {
551+
add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, $default_type );
552+
add_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 1 );
553+
add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
554+
add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
555+
add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, '' );
556+
add_post_meta(
557+
$chart_id,
558+
Visualizer_Plugin::CF_SETTINGS,
559+
array(
560+
'focusTarget' => 'datum',
561+
)
562+
);
563+
564+
do_action( 'visualizer_pro_new_chart_defaults', $chart_id );
565+
}
566+
} else {
567+
if ( current_user_can( 'edit_posts' ) ) {
568+
$parent_chart_id = isset( $_GET['parent_chart_id'] ) ? filter_var( $_GET['parent_chart_id'], FILTER_VALIDATE_INT ) : '';
569+
$success = false;
570+
if ( $parent_chart_id ) {
571+
$parent_chart = get_post( $parent_chart_id );
572+
$success = $parent_chart && $parent_chart->post_type === Visualizer_Plugin::CPT_VISUALIZER;
573+
}
574+
if ( $success ) {
575+
$new_chart_id = wp_insert_post(
576+
array(
577+
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
578+
'post_title' => 'Visualization',
579+
'post_author' => get_current_user_id(),
580+
'post_status' => $parent_chart->post_status,
581+
'post_content' => $parent_chart->post_content,
582+
)
583+
);
584+
585+
if ( is_wp_error( $new_chart_id ) ) {
586+
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__ );
587+
} else {
588+
$post_meta = get_post_meta( $parent_chart_id );
589+
$chart_id = $new_chart_id;
590+
foreach ( $post_meta as $key => $value ) {
591+
if ( strpos( $key, 'visualizer-' ) !== false ) {
592+
add_post_meta( $new_chart_id, $key, maybe_unserialize( $value[0] ) );
593+
}
594+
}
595+
}
596+
}
597+
}
527598
do_action( 'visualizer_pro_new_chart_defaults', $chart_id );
528599
}
529600
wp_redirect( esc_url_raw( add_query_arg( 'chart', (int) $chart_id ) ) );
@@ -832,6 +903,7 @@ private function _handleDataAndSettingsPage() {
832903
'json_tag_separator' => Visualizer_Source_Json::TAG_SEPARATOR,
833904
'json_tag_separator_view' => Visualizer_Source_Json::TAG_SEPARATOR_VIEW,
834905
'is_front' => false,
906+
'rest_base' => get_rest_url( null, 'wc/v3/reports/' ),
835907
)
836908
);
837909

classes/Visualizer/Module/Frontend.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,17 @@ public function renderChart( $atts ) {
305305
$atts
306306
);
307307

308+
if ( Visualizer_Module::is_pro() && function_exists( 'icl_get_languages' ) ) {
309+
global $sitepress;
310+
$locale = icl_get_current_language();
311+
$locale = strtolower( str_replace( '_', '-', $locale ) );
312+
$trid = $sitepress->get_element_trid( $atts['id'], 'post_' . Visualizer_Plugin::CPT_VISUALIZER );
313+
$translations = $sitepress->get_element_translations( $trid );
314+
if ( isset( $translations[ $locale ] ) && is_object( $translations[ $locale ] ) ) {
315+
$atts['id'] = $translations[ $locale ]->element_id;
316+
}
317+
}
318+
308319
$chart_data = $this->getChartData( Visualizer_Plugin::CF_CHART_CACHE, $atts['id'] );
309320
// if empty chart does not exists, then return empty string.
310321
if ( ! $chart_data ) {
@@ -319,6 +330,10 @@ public function renderChart( $atts ) {
319330
return '';
320331
}
321332

333+
if ( ! is_admin() && ! empty( $chart_data['is_woocommerce_report'] ) ) {
334+
return '';
335+
}
336+
322337
// in case revisions exist.
323338
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
324339
if ( true === ( $revisions = $this->undoRevisions( $chart->ID, true ) ) ) {
@@ -639,8 +654,9 @@ private function getChartData( $cache_key = '', $chart_id = 0 ) {
639654
// Get chart by ID.
640655
$chart = get_post( $chart_id );
641656
if ( $chart && Visualizer_Plugin::CPT_VISUALIZER === $chart->post_type ) {
642-
$settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
643-
$series = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true );
657+
$settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
658+
$series = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true );
659+
$is_woocommerce_report = get_post_meta( $chart->ID, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true );
644660

645661
if ( isset( $settings['series'] ) && ! ( count( $settings['series'] ) - count( $series ) > 1 ) ) {
646662
$diff_total_series = abs( count( $settings['series'] ) - count( $series ) );
@@ -651,11 +667,12 @@ private function getChartData( $cache_key = '', $chart_id = 0 ) {
651667
}
652668
}
653669
$chart_data = array(
654-
'chart' => $chart,
655-
'type' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ),
656-
'settings' => $settings,
657-
'series' => $series,
658-
'chart_image' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_IMAGE, true ),
670+
'chart' => $chart,
671+
'type' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ),
672+
'settings' => $settings,
673+
'series' => $series,
674+
'chart_image' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_IMAGE, true ),
675+
'is_woocommerce_report' => $is_woocommerce_report,
659676
);
660677

661678
// Put the results in a transient. Expire after 12 hours.

classes/Visualizer/Plugin.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ class Visualizer_Plugin {
102102
const PRO_TEASER_TITLE = 'Check PRO version ';
103103

104104
const CF_CHART_CACHE = 'visualizer-chart-cache';
105+
const CF_JSON_WOOCOMMERCE_SOURCE = 'visualizer-woocommerce-source';
106+
const CF_IS_WOOCOMMERCE_SOURCE = 'visualizer-is-woocommerce-source';
105107

106108
/**
107109
* Name of the option for WordPress DB.

0 commit comments

Comments
 (0)