| @@ -52,9 +52,9 @@ | ||
| 52 | 52 | public function __construct( Visualizer_Plugin $plugin ) { |
| 53 | 53 | parent::__construct( $plugin ); |
| 54 | 54 | $this->_addAction( 'load-post.php', 'enqueueMediaScripts' ); |
| 55 | 55 | $this->_addAction( 'load-post-new.php', 'enqueueMediaScripts' ); |
| 56 | - $this->_addAction( 'admin_footer', 'renderTempaltes' ); | |
| 56 | + $this->_addAction( 'admin_footer', 'renderTemplates' ); | |
| 57 | 57 | $this->_addAction( 'admin_enqueue_scripts', 'enqueueLibraryScripts', null, 8 ); |
| 58 | 58 | $this->_addAction( 'admin_menu', 'registerAdminMenu' ); |
| 59 | 59 | $this->_addFilter( 'media_view_strings', 'setupMediaViewStrings' ); |
| 60 | 60 | $this->_addFilter( 'plugin_action_links', 'getPluginActionLinks', 10, 2 ); |
| @@ -212,11 +212,14 @@ | ||
| 212 | 212 | public function enqueueMediaScripts() { |
| 213 | 213 | global $typenow; |
| 214 | 214 | if ( post_type_supports( $typenow, 'editor' ) ) { |
| 215 | 215 | wp_enqueue_style( 'visualizer-media', VISUALIZER_ABSURL . 'css/media.css', array( 'media-views' ), Visualizer_Plugin::VERSION ); |
| 216 | - wp_enqueue_script( 'visualizer-google-jsapi-new', '//www.gstatic.com/charts/loader.js', array( 'media-editor' ), null, true ); | |
| 217 | - wp_enqueue_script( 'visualizer-google-jsapi-old', '//www.google.com/jsapi', array( 'visualizer-google-jsapi-new' ), null, true ); | |
| 218 | - wp_enqueue_script( 'visualizer-media-model', VISUALIZER_ABSURL . 'js/media/model.js', array( 'visualizer-google-jsapi-old' ), Visualizer_Plugin::VERSION, true ); | |
| 216 | + | |
| 217 | + // Load all the assets for the different libraries we support. | |
| 218 | + $deps = Visualizer_Render_Sidebar_Google::enqueue_assets( array( 'media-editor' ) ); | |
| 219 | + $deps += Visualizer_Render_Sidebar_Type_DataTable::enqueue_assets( array( 'media-editor' ) ); | |
| 220 | + | |
| 221 | + wp_enqueue_script( 'visualizer-media-model', VISUALIZER_ABSURL . 'js/media/model.js', $deps, Visualizer_Plugin::VERSION, true ); | |
| 219 | 222 | wp_enqueue_script( 'visualizer-media-collection', VISUALIZER_ABSURL . 'js/media/collection.js', array( 'visualizer-media-model' ), Visualizer_Plugin::VERSION, true ); |
| 220 | 223 | wp_enqueue_script( 'visualizer-media-controller', VISUALIZER_ABSURL . 'js/media/controller.js', array( 'visualizer-media-collection' ), Visualizer_Plugin::VERSION, true ); |
| 221 | 224 | wp_enqueue_script( 'visualizer-media-view', VISUALIZER_ABSURL . 'js/media/view.js', array( 'visualizer-media-controller' ), Visualizer_Plugin::VERSION, true ); |
| 222 | 225 | wp_localize_script( |
| @@ -277,9 +280,9 @@ | ||
| 277 | 280 | * @static |
| 278 | 281 | * @access private |
| 279 | 282 | * @return array The associated array of chart types with localized names. |
| 280 | 283 | */ |
| 281 | - public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darray = false, $add_select = false ) { | |
| 284 | + public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darray = false, $add_select = false, $where = null ) { | |
| 282 | 285 | $additional = array(); |
| 283 | 286 | if ( $add_select ) { |
| 284 | 287 | $additional['select'] = array( |
| 285 | 288 | 'name' => esc_html__( 'All', 'visualizer' ), |
| @@ -289,8 +292,12 @@ | ||
| 289 | 292 | |
| 290 | 293 | $types = array_merge( |
| 291 | 294 | $additional, |
| 292 | 295 | array( |
| 296 | + 'dataTable' => array( | |
| 297 | + 'name' => esc_html__( 'Table (New)', 'visualizer' ), | |
| 298 | + 'enabled' => true, | |
| 299 | + ), | |
| 293 | 300 | 'pie' => array( |
| 294 | 301 | 'name' => esc_html__( 'Pie', 'visualizer' ), |
| 295 | 302 | 'enabled' => true, |
| 296 | 303 | ), |
| @@ -327,9 +334,9 @@ | ||
| 327 | 334 | 'enabled' => true, |
| 328 | 335 | ), |
| 329 | 336 | // pro types |
| 330 | 337 | 'table' => array( |
| 331 | - 'name' => esc_html__( 'Table', 'visualizer' ), | |
| 338 | + 'name' => esc_html__( 'Table (Deprecated)', 'visualizer' ), | |
| 332 | 339 | 'enabled' => false, |
| 333 | 340 | ), |
| 334 | 341 | 'timeline' => array( |
| 335 | 342 | 'name' => esc_html__( 'Timeline', 'visualizer' ), |
| @@ -367,8 +374,69 @@ | ||
| 367 | 374 | } |
| 368 | 375 | $types = $doubleD; |
| 369 | 376 | } |
| 370 | 377 | |
| 378 | + return self::handleDeprecatedCharts( $types, $enabledOnly, $get2Darray, $where ); | |
| 379 | + } | |
| 380 | + | |
| 381 | + /** | |
| 382 | + * Handle (soon-to-be) deprecated charts. | |
| 383 | + */ | |
| 384 | + private static function handleDeprecatedCharts( $types, $enabledOnly, $get2Darray, $where ) { | |
| 385 | + $deprecated = array(); | |
| 386 | + | |
| 387 | + switch ( $where ) { | |
| 388 | + case 'library': | |
| 389 | + // if the user has a Google Table chart, show it as deprecated otherwise remove the option from the library. | |
| 390 | + if ( ! self::hasChartType( 'table' ) ) { | |
| 391 | + $deprecated[] = 'table'; | |
| 392 | + if ( $get2Darray ) { | |
| 393 | + $types['dataTable'] = esc_html__( 'Table', 'visualizer' ); | |
| 394 | + } else { | |
| 395 | + $types['dataTable']['name'] = esc_html__( 'Table', 'visualizer' ); | |
| 396 | + } | |
| 397 | + } | |
| 398 | + | |
| 399 | + // if a user has a Gauge/Candlestick chart, then let them keep using it. | |
| 400 | + if ( ! VISUALIZER_PRO ) { | |
| 401 | + if ( ! self::hasChartType( 'gauge' ) ) { | |
| 402 | + $deprecated[] = 'gauge'; | |
| 403 | + } | |
| 404 | + if ( ! self::hasChartType( 'candlestick' ) ) { | |
| 405 | + $deprecated[] = 'candlestick'; | |
| 406 | + } | |
| 407 | + } | |
| 408 | + break; | |
| 409 | + default: | |
| 410 | + // remove the option to create a Google Table chart. | |
| 411 | + $deprecated[] = 'table'; | |
| 412 | + | |
| 413 | + // rename the new table chart type. | |
| 414 | + if ( self::hasChartType( 'table' ) ) { | |
| 415 | + if ( $get2Darray ) { | |
| 416 | + $types['dataTable'] = esc_html__( 'Table', 'visualizer' ); | |
| 417 | + } else { | |
| 418 | + $types['dataTable']['name'] = esc_html__( 'Table', 'visualizer' ); | |
| 419 | + } | |
| 420 | + } | |
| 421 | + | |
| 422 | + // if a user has a Gauge/Candlestick chart, then let them keep using it. | |
| 423 | + if ( ! VISUALIZER_PRO ) { | |
| 424 | + if ( ! self::hasChartType( 'gauge' ) ) { | |
| 425 | + $deprecated[] = 'gauge'; | |
| 426 | + } | |
| 427 | + if ( ! self::hasChartType( 'candlestick' ) ) { | |
| 428 | + $deprecated[] = 'candlestick'; | |
| 429 | + } | |
| 430 | + } | |
| 431 | + } | |
| 432 | + | |
| 433 | + if ( $deprecated ) { | |
| 434 | + foreach ( $deprecated as $type ) { | |
| 435 | + unset( $types[ $type ] ); | |
| 436 | + } | |
| 437 | + } | |
| 438 | + | |
| 371 | 439 | return $types; |
| 372 | 440 | } |
| 373 | 441 | |
| 374 | 442 | /** |
| @@ -378,9 +446,9 @@ | ||
| 378 | 446 | * @global string $pagenow The name of the current page. |
| 379 | 447 | * |
| 380 | 448 | * @access public |
| 381 | 449 | */ |
| 382 | - public function renderTempaltes() { | |
| 450 | + public function renderTemplates() { | |
| 383 | 451 | global $pagenow; |
| 384 | 452 | if ( 'post.php' != $pagenow && 'post-new.php' != $pagenow ) { |
| 385 | 453 | return; |
| 386 | 454 | } |
| @@ -414,22 +482,26 @@ | ||
| 414 | 482 | ), |
| 415 | 483 | Visualizer_Plugin::VERSION, |
| 416 | 484 | true |
| 417 | 485 | ); |
| 418 | - wp_enqueue_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true ); | |
| 419 | - wp_enqueue_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true ); | |
| 486 | + | |
| 420 | 487 | wp_enqueue_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true ); |
| 421 | - wp_enqueue_script( | |
| 422 | - 'visualizer-render', | |
| 423 | - VISUALIZER_ABSURL . 'js/render.js', | |
| 424 | - array( | |
| 425 | - 'google-jsapi-old', | |
| 426 | - 'visualizer-library', | |
| 427 | - 'visualizer-customization', | |
| 428 | - ), | |
| 429 | - Visualizer_Plugin::VERSION, | |
| 430 | - true | |
| 431 | - ); | |
| 488 | + | |
| 489 | + $query = $this->getQuery(); | |
| 490 | + while ( $query->have_posts() ) { | |
| 491 | + $chart = $query->next_post(); | |
| 492 | + $library = $this->load_chart_type( $chart->ID ); | |
| 493 | + if ( is_null( $library ) ) { | |
| 494 | + continue; | |
| 495 | + } | |
| 496 | + wp_enqueue_script( | |
| 497 | + "visualizer-render-$library", | |
| 498 | + VISUALIZER_ABSURL . 'js/render-facade.js', | |
| 499 | + apply_filters( 'visualizer_assets_render', array( 'visualizer-library', 'visualizer-customization' ), true ), | |
| 500 | + Visualizer_Plugin::VERSION, | |
| 501 | + true | |
| 502 | + ); | |
| 503 | + } | |
| 432 | 504 | } |
| 433 | 505 | } |
| 434 | 506 | |
| 435 | 507 | /** |
| @@ -462,15 +534,16 @@ | ||
| 462 | 534 | $this->_libraryPage = add_submenu_page( 'upload.php', $title, $title, 'edit_posts', Visualizer_Plugin::NAME, $callback ); |
| 463 | 535 | } |
| 464 | 536 | |
| 465 | 537 | /** |
| 466 | - * Renders visualizer library page. | |
| 467 | - * | |
| 468 | - * @since 1.0.0 | |
| 469 | - * | |
| 470 | - * @access public | |
| 538 | + * Get the instance of WP_Query that fetches the charts as per the given criteria. | |
| 471 | 539 | */ |
| 472 | - public function renderLibraryPage() { | |
| 540 | + private function getQuery() { | |
| 541 | + static $q; | |
| 542 | + if ( ! is_null( $q ) ) { | |
| 543 | + return $q; | |
| 544 | + } | |
| 545 | + | |
| 473 | 546 | // get current page |
| 474 | 547 | $page = filter_input( |
| 475 | 548 | INPUT_GET, |
| 476 | 549 | 'vpage', |
| @@ -512,31 +585,81 @@ | ||
| 512 | 585 | $meta = isset( $query_args['meta_query'] ) ? $query_args['meta_query'] : array(); |
| 513 | 586 | $meta[] = $query; |
| 514 | 587 | $query_args['meta_query'] = $meta; |
| 515 | 588 | } |
| 516 | - // Added by Ash/Upwork | |
| 517 | - // fetch charts | |
| 589 | + $q = new WP_Query( $query_args ); | |
| 590 | + return $q; | |
| 591 | + } | |
| 592 | + | |
| 593 | + /** | |
| 594 | + * Renders visualizer library page. | |
| 595 | + * | |
| 596 | + * @since 1.0.0 | |
| 597 | + * | |
| 598 | + * @access public | |
| 599 | + */ | |
| 600 | + public function renderLibraryPage() { | |
| 518 | 601 | $charts = array(); |
| 519 | - $query = new WP_Query( $query_args ); | |
| 602 | + $query = $this->getQuery(); | |
| 603 | + | |
| 604 | + // get current page | |
| 605 | + $page = filter_input( | |
| 606 | + INPUT_GET, | |
| 607 | + 'vpage', | |
| 608 | + FILTER_VALIDATE_INT, | |
| 609 | + array( | |
| 610 | + 'options' => array( | |
| 611 | + 'min_range' => 1, | |
| 612 | + 'default' => 1, | |
| 613 | + ), | |
| 614 | + ) | |
| 615 | + ); | |
| 616 | + // add chart type filter to the query arguments | |
| 617 | + $filter = filter_input( INPUT_GET, 'type' ); | |
| 618 | + if ( ! ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes() ) ) ) { | |
| 619 | + $filter = 'all'; | |
| 620 | + } | |
| 621 | + | |
| 622 | + $css = ''; | |
| 520 | 623 | while ( $query->have_posts() ) { |
| 521 | 624 | $chart = $query->next_post(); |
| 522 | 625 | |
| 523 | 626 | // if the user has updated a chart and instead of saving it, has closed the modal. If the user refreshes, they should get the original chart. |
| 524 | 627 | $chart = $this->handleExistingRevisions( $chart->ID, $chart ); |
| 628 | + // refresh a "live" db query chart. | |
| 629 | + $chart = apply_filters( 'visualizer_schedule_refresh_chart', $chart, $chart->ID, false ); | |
| 525 | 630 | |
| 631 | + $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ); | |
| 632 | + | |
| 526 | 633 | // fetch and update settings |
| 527 | 634 | $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true ); |
| 635 | + | |
| 636 | + $settings = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SETTINGS, $settings, $chart->ID, $type ); | |
| 637 | + if ( ! empty( $atts['settings'] ) ) { | |
| 638 | + $settings = apply_filters( $atts['settings'], $settings, $chart->ID, $type ); | |
| 639 | + } | |
| 640 | + | |
| 528 | 641 | unset( $settings['height'], $settings['width'] ); |
| 529 | - $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ); | |
| 530 | 642 | $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type ); |
| 531 | 643 | $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( html_entity_decode( $chart->post_content ) ), $chart->ID, $type ); |
| 644 | + | |
| 645 | + $library = $this->load_chart_type( $chart->ID ); | |
| 646 | + | |
| 647 | + $id = 'visualizer-' . $chart->ID; | |
| 648 | + $arguments = $this->get_inline_custom_css( $id, $settings ); | |
| 649 | + if ( ! empty( $arguments ) ) { | |
| 650 | + $css .= $arguments[0]; | |
| 651 | + $settings = $arguments[1]; | |
| 652 | + } | |
| 653 | + | |
| 532 | 654 | // add chart to the array |
| 533 | - $charts[ 'visualizer-' . $chart->ID ] = array( | |
| 655 | + $charts[ $id ] = array( | |
| 534 | 656 | 'id' => $chart->ID, |
| 535 | 657 | 'type' => $type, |
| 536 | 658 | 'series' => $series, |
| 537 | 659 | 'settings' => $settings, |
| 538 | 660 | 'data' => $data, |
| 661 | + 'library' => $library, | |
| 539 | 662 | ); |
| 540 | 663 | } |
| 541 | 664 | // enqueue charts array |
| 542 | 665 | $ajaxurl = admin_url( 'admin-ajax.php' ); |
| @@ -564,8 +687,9 @@ | ||
| 564 | 687 | ), |
| 565 | 688 | $ajaxurl |
| 566 | 689 | ), |
| 567 | 690 | ), |
| 691 | + 'page_type' => 'library', | |
| 568 | 692 | ) |
| 569 | 693 | ); |
| 570 | 694 | // render library page |
| 571 | 695 | $render = new Visualizer_Render_Library(); |
| @@ -570,9 +694,10 @@ | ||
| 570 | 694 | // render library page |
| 571 | 695 | $render = new Visualizer_Render_Library(); |
| 572 | 696 | $render->charts = $charts; |
| 573 | 697 | $render->type = $filter; |
| 574 | - $render->types = self::_getChartTypesLocalized(); | |
| 698 | + $render->types = self::_getChartTypesLocalized( false, false, false, true ); | |
| 699 | + $render->custom_css = $css; | |
| 575 | 700 | $render->pagination = paginate_links( |
| 576 | 701 | array( |
| 577 | 702 | 'base' => add_query_arg( 'vpage', '%#%' ), |
| 578 | 703 | 'format' => '', |