@@ -511,33 +511,68 @@ public function renderChartPages() {
511
511
// check chart, if chart not exists, will create new one and redirects to the same page with proper chart id
512
512
$ chart_id = isset ( $ _GET ['chart ' ] ) ? filter_var ( $ _GET ['chart ' ], FILTER_VALIDATE_INT ) : '' ;
513
513
if ( ! $ chart_id || ! ( $ chart = get_post ( $ chart_id ) ) || $ chart ->post_type !== Visualizer_Plugin::CPT_VISUALIZER ) {
514
- $ this ->deleteOldCharts ();
515
- $ default_type = isset ( $ _GET ['type ' ] ) && ! empty ( $ _GET ['type ' ] ) ? $ _GET ['type ' ] : 'line ' ;
516
- $ source = new Visualizer_Source_Csv ( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples ' . DIRECTORY_SEPARATOR . $ default_type . '.csv ' );
517
- $ source ->fetch ();
518
- $ chart_id = wp_insert_post (
519
- array (
520
- 'post_type ' => Visualizer_Plugin::CPT_VISUALIZER ,
521
- 'post_title ' => 'Visualization ' ,
522
- 'post_author ' => get_current_user_id (),
523
- 'post_status ' => 'auto-draft ' ,
524
- 'post_content ' => $ source ->getData ( get_post_meta ( $ chart_id , Visualizer_Plugin::CF_EDITABLE_TABLE , true ) ),
525
- )
526
- );
527
- if ( $ chart_id && ! is_wp_error ( $ chart_id ) ) {
528
- add_post_meta ( $ chart_id , Visualizer_Plugin::CF_CHART_TYPE , $ default_type );
529
- add_post_meta ( $ chart_id , Visualizer_Plugin::CF_DEFAULT_DATA , 1 );
530
- add_post_meta ( $ chart_id , Visualizer_Plugin::CF_SOURCE , $ source ->getSourceName () );
531
- add_post_meta ( $ chart_id , Visualizer_Plugin::CF_SERIES , $ source ->getSeries () );
532
- add_post_meta ( $ chart_id , Visualizer_Plugin::CF_CHART_LIBRARY , '' );
533
- add_post_meta (
534
- $ chart_id ,
535
- Visualizer_Plugin::CF_SETTINGS ,
514
+ if ( empty ( $ _GET ['lang ' ] ) || empty ( $ _GET ['parent_chart_id ' ] ) ) {
515
+ $ this ->deleteOldCharts ();
516
+ $ default_type = isset ( $ _GET ['type ' ] ) && ! empty ( $ _GET ['type ' ] ) ? $ _GET ['type ' ] : 'line ' ;
517
+ $ source = new Visualizer_Source_Csv ( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples ' . DIRECTORY_SEPARATOR . $ default_type . '.csv ' );
518
+ $ source ->fetch ();
519
+ $ chart_id = wp_insert_post (
536
520
array (
537
- 'focusTarget ' => 'datum ' ,
521
+ 'post_type ' => Visualizer_Plugin::CPT_VISUALIZER ,
522
+ 'post_title ' => 'Visualization ' ,
523
+ 'post_author ' => get_current_user_id (),
524
+ 'post_status ' => 'auto-draft ' ,
525
+ 'post_content ' => $ source ->getData ( get_post_meta ( $ chart_id , Visualizer_Plugin::CF_EDITABLE_TABLE , true ) ),
538
526
)
539
527
);
528
+ if ( $ chart_id && ! is_wp_error ( $ chart_id ) ) {
529
+ add_post_meta ( $ chart_id , Visualizer_Plugin::CF_CHART_TYPE , $ default_type );
530
+ add_post_meta ( $ chart_id , Visualizer_Plugin::CF_DEFAULT_DATA , 1 );
531
+ add_post_meta ( $ chart_id , Visualizer_Plugin::CF_SOURCE , $ source ->getSourceName () );
532
+ add_post_meta ( $ chart_id , Visualizer_Plugin::CF_SERIES , $ source ->getSeries () );
533
+ add_post_meta ( $ chart_id , Visualizer_Plugin::CF_CHART_LIBRARY , '' );
534
+ add_post_meta (
535
+ $ chart_id ,
536
+ Visualizer_Plugin::CF_SETTINGS ,
537
+ array (
538
+ 'focusTarget ' => 'datum ' ,
539
+ )
540
+ );
540
541
542
+ do_action ( 'visualizer_pro_new_chart_defaults ' , $ chart_id );
543
+ }
544
+ } else {
545
+ if ( current_user_can ( 'edit_posts ' ) ) {
546
+ $ parent_chart_id = isset ( $ _GET ['parent_chart_id ' ] ) ? filter_var ( $ _GET ['parent_chart_id ' ], FILTER_VALIDATE_INT ) : '' ;
547
+ $ success = false ;
548
+ if ( $ parent_chart_id ) {
549
+ $ parent_chart = get_post ( $ parent_chart_id );
550
+ $ success = $ parent_chart && $ parent_chart ->post_type === Visualizer_Plugin::CPT_VISUALIZER ;
551
+ }
552
+ if ( $ success ) {
553
+ $ new_chart_id = wp_insert_post (
554
+ array (
555
+ 'post_type ' => Visualizer_Plugin::CPT_VISUALIZER ,
556
+ 'post_title ' => 'Visualization ' ,
557
+ 'post_author ' => get_current_user_id (),
558
+ 'post_status ' => $ parent_chart ->post_status ,
559
+ 'post_content ' => $ parent_chart ->post_content ,
560
+ )
561
+ );
562
+
563
+ if ( is_wp_error ( $ new_chart_id ) ) {
564
+ 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__ );
565
+ } else {
566
+ $ post_meta = get_post_meta ( $ parent_chart_id );
567
+ $ chart_id = $ new_chart_id ;
568
+ foreach ( $ post_meta as $ key => $ value ) {
569
+ if ( strpos ( $ key , 'visualizer- ' ) !== false ) {
570
+ add_post_meta ( $ new_chart_id , $ key , maybe_unserialize ( $ value [0 ] ) );
571
+ }
572
+ }
573
+ }
574
+ }
575
+ }
541
576
do_action ( 'visualizer_pro_new_chart_defaults ' , $ chart_id );
542
577
}
543
578
wp_redirect ( esc_url_raw ( add_query_arg ( 'chart ' , (int ) $ chart_id ) ) );
0 commit comments