Skip to content

Commit

Permalink
release(minor): fixes and new features
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
vytisbulkevicius authored Nov 10, 2022
2 parents 99e1b40 + 1c811c6 commit ad22ce3
Show file tree
Hide file tree
Showing 16 changed files with 401 additions and 49 deletions.
2 changes: 1 addition & 1 deletion classes/Visualizer/Gutenberg/build/block.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion classes/Visualizer/Gutenberg/build/block.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class ChartPermissions extends Component {
<PanelBody
title={ __( 'Who can see this chart?' ) }
initialOpen={ false }
className="vz-permission-tab"
>

<SelectControl
Expand Down Expand Up @@ -128,6 +129,7 @@ class ChartPermissions extends Component {
<PanelBody
title={ __( 'Who can edit this chart?' ) }
initialOpen={ false }
className="vz-permission-tab"
>

<SelectControl
Expand Down
6 changes: 5 additions & 1 deletion classes/Visualizer/Gutenberg/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,11 @@
.DTCR_pointer {
z-index: 999999 !important;
}

.vz-permission-tab {
select.components-select-control__input {
overflow:auto !important;
}
}
.components-panel {
.components-select-control {
height:auto !important;
Expand Down
5 changes: 3 additions & 2 deletions classes/Visualizer/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ private function _getCSV( $rows, $filename, $enclose ) {
$filename .= '.csv';

$bom = chr( 0xEF ) . chr( 0xBB ) . chr( 0xBF );
$fp = tmpfile();
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$fp = @tmpfile();
if ( null === $fp ) {
$fp = fopen( wp_tempnam(), 'w+' );
}
Expand Down Expand Up @@ -732,7 +733,7 @@ public static function can_show_feature( $feature ) {
public static final function get_features_for_license( $plan ) {
switch ( $plan ) {
case 1:
return array( 'import-wp', 'db-query' );
return array( 'import-wp', 'db-query', 'import-wc-report' );
case 2:
return array( 'schedule-chart', 'chart-permissions' );
}
Expand Down
63 changes: 63 additions & 0 deletions classes/Visualizer/Module/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public function __construct( Visualizer_Plugin $plugin ) {

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

$this->_addAction( 'visualizer_chart_languages', 'addMultilingualSupport' );

if ( defined( 'TI_CYPRESS_TESTING' ) ) {
$this->load_cypress_hooks();
}
Expand Down Expand Up @@ -767,6 +769,22 @@ function setScreenOptions( $status, $option, $value ) {
private function getDisplayFilters( &$query_args ) {
$query = array();

if ( Visualizer_Module::is_pro() && function_exists( 'icl_get_languages' ) ) {
$current_lang = icl_get_current_language();
if ( in_array( $current_lang, array( 'all', icl_get_default_language() ), true ) ) {
$query[] = array(
'key' => 'chart_lang',
'compare' => 'NOT EXISTS',
);
} else {
$query[] = array(
'key' => 'chart_lang',
'value' => $current_lang,
'compare' => '=',
);
}
}

// add chart type filter to the query arguments
$type = filter_input( INPUT_GET, 'type' );
if ( $type && in_array( $type, Visualizer_Plugin::getChartTypes(), true ) ) {
Expand Down Expand Up @@ -1112,4 +1130,49 @@ public static function proFeaturesLocked() {
}
return 'yes' === get_option( 'visualizer-new-user', 'yes' ) ? false : true;
}

/**
* Multilingual Support.
*
* @param int $chart_id Chart ID.
* @return bool Default false
*/
public function addMultilingualSupport( $chart_id ) {
if ( Visualizer_Module::is_pro() ) {
return;
}
if ( function_exists( 'icl_get_languages' ) ) {
$language = icl_get_languages();
$current_lang = icl_get_current_language();
$default_lang = icl_get_default_language();
$post_info = wpml_get_language_information( null, $chart_id );

global $sitepress;
$translations = array();
if ( ! empty( $post_info ) && ( $default_lang === $post_info['language_code'] ) ) {
$trid = $sitepress->get_element_trid( $chart_id, 'post_' . Visualizer_Plugin::CPT_VISUALIZER );
$translations = $sitepress->get_element_translations( $trid );
}
if ( empty( $translations ) ) {
return;
}
?>
<hr><div class="visualizer-languages-list only-pro">
<?php
foreach ( $language as $lang ) {
$lang_code = $lang['code'];
if ( $current_lang !== $lang_code ) {
?>
<a href="javascript:;">
<img src="<?php echo esc_url( $lang['country_flag_url'] ); ?>" alt="<?php echo esc_attr( $lang['translated_name'] ); ?>">
</a>
<?php
}
}
?>
<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>
</div>
<?php
}
}
}
120 changes: 96 additions & 24 deletions classes/Visualizer/Module/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ public function setJsonSchedule() {
)
);

if ( Visualizer_Module::is_pro() ) {
$is_woocommerce_report = filter_input(
INPUT_POST,
'is_woocommerce_report',
FILTER_VALIDATE_BOOLEAN
);

if ( $is_woocommerce_report ) {
update_post_meta( $chart_id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true );
} else {
delete_post_meta( $chart_id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE );
}
}

delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE );

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

if ( Visualizer_Module::is_pro() ) {
if ( ! empty( $params['vz_woo_source'] ) ) {
update_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_WOOCOMMERCE_SOURCE, $params['vz_woo_source'] );
} else {
delete_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_WOOCOMMERCE_SOURCE );
}
}

$time = filter_input(
INPUT_POST,
'time',
Expand Down Expand Up @@ -439,7 +461,20 @@ public function deleteChart() {
}
}
if ( $success ) {
wp_delete_post( $chart_id, true );
if ( Visualizer_Module::is_pro() && function_exists( 'icl_get_languages' ) ) {
global $sitepress;
$trid = $sitepress->get_element_trid( $chart_id, 'post_' . Visualizer_Plugin::CPT_VISUALIZER );
$translations = $sitepress->get_element_translations( $trid );
if ( ! empty( $translations ) ) {
foreach ( $translations as $translated_post ) {
wp_delete_post( $translated_post->element_id, true );
}
} else {
wp_delete_post( $chart_id, true );
}
} else {
wp_delete_post( $chart_id, true );
}
}
if ( $is_post ) {
self::_sendResponse(
Expand Down Expand Up @@ -498,32 +533,68 @@ public function renderChartPages() {
// check chart, if chart not exists, will create new one and redirects to the same page with proper chart id
$chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT ) : '';
if ( ! $chart_id || ! ( $chart = get_post( $chart_id ) ) || $chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ) {
$this->deleteOldCharts();
$default_type = isset( $_GET['type'] ) && ! empty( $_GET['type'] ) ? $_GET['type'] : 'line';
$source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $default_type . '.csv' );
$source->fetch();
$chart_id = wp_insert_post(
array(
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
'post_title' => 'Visualization',
'post_author' => get_current_user_id(),
'post_status' => 'auto-draft',
'post_content' => $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ),
)
);
if ( $chart_id && ! is_wp_error( $chart_id ) ) {
add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, $default_type );
add_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 1 );
add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, '' );
add_post_meta(
$chart_id,
Visualizer_Plugin::CF_SETTINGS,
if ( empty( $_GET['lang'] ) || empty( $_GET['parent_chart_id'] ) ) {
$this->deleteOldCharts();
$default_type = isset( $_GET['type'] ) && ! empty( $_GET['type'] ) ? $_GET['type'] : 'line';
$source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $default_type . '.csv' );
$source->fetch();
$chart_id = wp_insert_post(
array(
'focusTarget' => 'datum',
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
'post_title' => 'Visualization',
'post_author' => get_current_user_id(),
'post_status' => 'auto-draft',
'post_content' => $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ),
)
);
if ( $chart_id && ! is_wp_error( $chart_id ) ) {
add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, $default_type );
add_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 1 );
add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, '' );
add_post_meta(
$chart_id,
Visualizer_Plugin::CF_SETTINGS,
array(
'focusTarget' => 'datum',
)
);

do_action( 'visualizer_pro_new_chart_defaults', $chart_id );
}
} else {
if ( current_user_can( 'edit_posts' ) ) {
$parent_chart_id = isset( $_GET['parent_chart_id'] ) ? filter_var( $_GET['parent_chart_id'], FILTER_VALIDATE_INT ) : '';
$success = false;
if ( $parent_chart_id ) {
$parent_chart = get_post( $parent_chart_id );
$success = $parent_chart && $parent_chart->post_type === Visualizer_Plugin::CPT_VISUALIZER;
}
if ( $success ) {
$new_chart_id = wp_insert_post(
array(
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
'post_title' => 'Visualization',
'post_author' => get_current_user_id(),
'post_status' => $parent_chart->post_status,
'post_content' => $parent_chart->post_content,
)
);

if ( is_wp_error( $new_chart_id ) ) {
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__ );
} else {
$post_meta = get_post_meta( $parent_chart_id );
$chart_id = $new_chart_id;
foreach ( $post_meta as $key => $value ) {
if ( strpos( $key, 'visualizer-' ) !== false ) {
add_post_meta( $new_chart_id, $key, maybe_unserialize( $value[0] ) );
}
}
}
}
}
do_action( 'visualizer_pro_new_chart_defaults', $chart_id );
}
wp_redirect( esc_url_raw( add_query_arg( 'chart', (int) $chart_id ) ) );
Expand Down Expand Up @@ -832,6 +903,7 @@ private function _handleDataAndSettingsPage() {
'json_tag_separator' => Visualizer_Source_Json::TAG_SEPARATOR,
'json_tag_separator_view' => Visualizer_Source_Json::TAG_SEPARATOR_VIEW,
'is_front' => false,
'rest_base' => get_rest_url( null, 'wc/v3/reports/' ),
)
);

Expand Down
31 changes: 24 additions & 7 deletions classes/Visualizer/Module/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,17 @@ public function renderChart( $atts ) {
$atts
);

if ( Visualizer_Module::is_pro() && function_exists( 'icl_get_languages' ) ) {
global $sitepress;
$locale = icl_get_current_language();
$locale = strtolower( str_replace( '_', '-', $locale ) );
$trid = $sitepress->get_element_trid( $atts['id'], 'post_' . Visualizer_Plugin::CPT_VISUALIZER );
$translations = $sitepress->get_element_translations( $trid );
if ( isset( $translations[ $locale ] ) && is_object( $translations[ $locale ] ) ) {
$atts['id'] = $translations[ $locale ]->element_id;
}
}

$chart_data = $this->getChartData( Visualizer_Plugin::CF_CHART_CACHE, $atts['id'] );
// if empty chart does not exists, then return empty string.
if ( ! $chart_data ) {
Expand All @@ -319,6 +330,10 @@ public function renderChart( $atts ) {
return '';
}

if ( ! is_admin() && ! empty( $chart_data['is_woocommerce_report'] ) ) {
return '';
}

// in case revisions exist.
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
if ( true === ( $revisions = $this->undoRevisions( $chart->ID, true ) ) ) {
Expand Down Expand Up @@ -639,8 +654,9 @@ private function getChartData( $cache_key = '', $chart_id = 0 ) {
// Get chart by ID.
$chart = get_post( $chart_id );
if ( $chart && Visualizer_Plugin::CPT_VISUALIZER === $chart->post_type ) {
$settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
$series = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true );
$settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
$series = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true );
$is_woocommerce_report = get_post_meta( $chart->ID, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true );

if ( isset( $settings['series'] ) && ! ( count( $settings['series'] ) - count( $series ) > 1 ) ) {
$diff_total_series = abs( count( $settings['series'] ) - count( $series ) );
Expand All @@ -651,11 +667,12 @@ private function getChartData( $cache_key = '', $chart_id = 0 ) {
}
}
$chart_data = array(
'chart' => $chart,
'type' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ),
'settings' => $settings,
'series' => $series,
'chart_image' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_IMAGE, true ),
'chart' => $chart,
'type' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ),
'settings' => $settings,
'series' => $series,
'chart_image' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_IMAGE, true ),
'is_woocommerce_report' => $is_woocommerce_report,
);

// Put the results in a transient. Expire after 12 hours.
Expand Down
2 changes: 2 additions & 0 deletions classes/Visualizer/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class Visualizer_Plugin {
const PRO_TEASER_TITLE = 'Check PRO version ';

const CF_CHART_CACHE = 'visualizer-chart-cache';
const CF_JSON_WOOCOMMERCE_SOURCE = 'visualizer-woocommerce-source';
const CF_IS_WOOCOMMERCE_SOURCE = 'visualizer-is-woocommerce-source';

/**
* Name of the option for WordPress DB.
Expand Down
Loading

0 comments on commit ad22ce3

Please sign in to comment.