| @@ -205,10 +205,22 @@ | ||
| 205 | 205 | } |
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - $filename = isset( $settings['title'] ) && ! empty( $settings['title'] ) ? $settings['title'] : 'visualizer#' . $chart_id; | |
| 209 | + $title = 'visualizer#' . $chart_id; | |
| 210 | + if ( ! empty( $settings['title'] ) ) { | |
| 211 | + $title = $settings['title']; | |
| 212 | + } | |
| 213 | + // for ChartJS, title is an array. | |
| 214 | + if ( is_array( $title ) && isset( $title['text'] ) ) { | |
| 215 | + $title = $title['text']; | |
| 216 | + } | |
| 217 | + if ( empty( $title ) ) { | |
| 218 | + $title = 'visualizer#' . $chart_id; | |
| 219 | + } | |
| 210 | 220 | |
| 221 | + $filename = $title; | |
| 222 | + | |
| 211 | 223 | switch ( $type ) { |
| 212 | 224 | case 'csv': |
| 213 | 225 | $final = $this->_getCSV( $rows, $filename ); |
| 214 | 226 | break; |
| @@ -475,18 +487,18 @@ | ||
| 475 | 487 | /** |
| 476 | 488 | * Load the class for the given chart's chart type so that its assets can be loaded. |
| 477 | 489 | */ |
| 478 | 490 | protected function load_chart_type( $chart_id ) { |
| 479 | - $type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true ); | |
| 480 | - $name = 'Visualizer_Render_Sidebar_Type_' . ucwords( $type ); | |
| 491 | + $name = $this->load_chart_class_name( $chart_id ); | |
| 481 | 492 | $class = null; |
| 482 | 493 | if ( class_exists( $name ) || true === apply_filters( 'visualizer_load_chart', false, $name ) ) { |
| 483 | 494 | $class = new $name; |
| 484 | 495 | } |
| 485 | 496 | |
| 486 | - if ( is_null( $class ) && VISUALIZER_PRO ) { | |
| 497 | + if ( is_null( $class ) && Visualizer_Module::is_pro() ) { | |
| 487 | 498 | // lets see if this type exists in pro. New Lite(3.1.0+) & old Pro(1.8.0-). |
| 488 | - $class = apply_filters( 'visualizer_pro_chart_type_sidebar', null, array( 'type' => $type, 'settings' => get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true ) ) ); | |
| 499 | + $type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true ); | |
| 500 | + $class = apply_filters( 'visualizer_pro_chart_type_sidebar', null, array( 'id' => $chart_id, 'type' => $type, 'settings' => get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true ) ) ); | |
| 489 | 501 | } |
| 490 | 502 | |
| 491 | 503 | return is_null( $class ) ? null : $class->getLibrary(); |
| 492 | 504 | } |
| @@ -491,8 +503,26 @@ | ||
| 491 | 503 | return is_null( $class ) ? null : $class->getLibrary(); |
| 492 | 504 | } |
| 493 | 505 | |
| 494 | 506 | /** |
| 507 | + * Returns the class name for the given chart's chart type. | |
| 508 | + */ | |
| 509 | + protected function load_chart_class_name( $chart_id ) { | |
| 510 | + $type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true ); | |
| 511 | + $lib = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, true ); | |
| 512 | + | |
| 513 | + // backward compatibility. | |
| 514 | + if ( empty( $lib ) ) { | |
| 515 | + $lib = 'GoogleCharts'; | |
| 516 | + if ( 'dataTable' === $type ) { | |
| 517 | + $lib = 'DataTable'; | |
| 518 | + } | |
| 519 | + } | |
| 520 | + $name = 'Visualizer_Render_Sidebar_Type_' . $lib . '_' . ucwords( $type ); | |
| 521 | + return $name; | |
| 522 | + } | |
| 523 | + | |
| 524 | + /** | |
| 495 | 525 | * Generates the inline CSS to apply to the chart and adds these classes to the settings. |
| 496 | 526 | * |
| 497 | 527 | * @access public |
| 498 | 528 | * @param int $id The id of the chart. |
| @@ -513,9 +543,9 @@ | ||
| 513 | 543 | foreach ( $element as $property => $value ) { |
| 514 | 544 | $attributes[] = $this->handle_css_property( $property, $value ); |
| 515 | 545 | } |
| 516 | 546 | $class_name = $id . $name; |
| 517 | - $properties = implode( '; ', array_filter( $attributes ) ); | |
| 547 | + $properties = implode( ' !important; ', array_filter( $attributes ) ); | |
| 518 | 548 | if ( ! empty( $properties ) ) { |
| 519 | 549 | $css .= '.' . $class_name . ' {' . $properties . ' !important;}'; |
| 520 | 550 | $classes[ $name ] = $class_name; |
| 521 | 551 | } |
| @@ -567,7 +597,42 @@ | ||
| 567 | 597 | ); |
| 568 | 598 | |
| 569 | 599 | $q = new WP_Query( $args ); |
| 570 | 600 | return $q->found_posts > 0; |
| 601 | + } | |
| 602 | + | |
| 603 | + /** | |
| 604 | + * Determines how many charts have been created. | |
| 605 | + */ | |
| 606 | + protected static function numberOfCharts() { | |
| 607 | + $args = array( | |
| 608 | + 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, | |
| 609 | + 'fields' => 'ids', | |
| 610 | + 'post_status' => 'publish', | |
| 611 | + 'posts_per_page' => 300, | |
| 612 | + ); | |
| 613 | + | |
| 614 | + $q = new WP_Query( $args ); | |
| 615 | + return $q->found_posts; | |
| 616 | + } | |
| 617 | + | |
| 618 | + /** | |
| 619 | + * Checks if the PRO version is active. | |
| 620 | + * | |
| 621 | + * @since 3.3.0 | |
| 622 | + */ | |
| 623 | + public static function is_pro() { | |
| 624 | + // versions of pro before 1.9.0 will use the constant VISUALIZER_PRO | |
| 625 | + // versions of pro 1.9.0 onwards will use the filter | |
| 626 | + return apply_filters( 'visualizer_is_pro', VISUALIZER_PRO ); | |
| 627 | + } | |
| 628 | + | |
| 629 | + /** | |
| 630 | + * Checks if the PRO version is older than a particular version. | |
| 631 | + * | |
| 632 | + * @since 3.3.0 | |
| 633 | + */ | |
| 634 | + public static function is_pro_older_than( $version ) { | |
| 635 | + return version_compare( VISUALIZER_PRO_VERSION, $version, '<' ); | |
| 571 | 636 | } |
| 572 | 637 | |
| 573 | 638 | } |