Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release #958

Merged
merged 22 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e573329
Add wpml plugin support #731
girishpanchal30 Oct 11, 2022
ae91c41
Move pro feature #731
girishpanchal30 Oct 11, 2022
f91a3b2
Sync branch [skip ci]
pirate-bot Oct 12, 2022
9ec8081
Sync branch [skip ci]
pirate-bot Oct 12, 2022
0cc4425
Merge branch 'development' of github.com:Codeinwp/visualizer into enh…
girishpanchal30 Oct 13, 2022
0233725
Compatible Woocommerce data Codeinwp/visualizer-pro#323
girishpanchal30 Oct 20, 2022
e8497ef
Fix scrollbar issue #950
girishpanchal30 Oct 20, 2022
c52e945
Disable temp file creation error #949
girishpanchal30 Oct 20, 2022
efc1c2e
Trigger chart data change action Codeinwp/visualizer-pro#323
girishpanchal30 Oct 27, 2022
308337e
Remove unicode from number #955
girishpanchal30 Oct 27, 2022
77d4505
Fix float value issue in dataTable chart #955
girishpanchal30 Oct 27, 2022
61bf50d
Sync branch [skip ci]
pirate-bot Nov 2, 2022
63d2d6b
Fix auto render another language chart #731
girishpanchal30 Nov 4, 2022
bc68b1b
Skip new chart popup #731
girishpanchal30 Nov 4, 2022
e0b2fe4
Merge pull request #956 from Codeinwp/bugfix/955
vytisbulkevicius Nov 4, 2022
2c42a03
Merge pull request #947 from Codeinwp/enhancement/731
vytisbulkevicius Nov 4, 2022
927789e
Merge pull request #952 from Codeinwp/enhancement/pro/323
vytisbulkevicius Nov 4, 2022
47d94e6
Merge pull request #953 from Codeinwp/bugfix/950
vytisbulkevicius Nov 4, 2022
f616cf3
Merge pull request #954 from Codeinwp/bugfix/949
vytisbulkevicius Nov 4, 2022
a71fc59
Show new features on chart library page Codeinwp/visualizer-pro#360
girishpanchal30 Nov 10, 2022
87582e5
Remove debug code Codeinwp/visualizer-pro#360
girishpanchal30 Nov 10, 2022
1c811c6
Merge pull request #959 from Codeinwp/enhancement/pro/360
vytisbulkevicius Nov 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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