| @@ -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', 'renderTemplates' ); | |
| 56 | + $this->_addAction( 'admin_footer', 'renderTempaltes' ); | |
| 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,23 +212,16 @@ | ||
| 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 | - | |
| 217 | - // Load all the assets for the different libraries we support. | |
| 218 | - $deps = array( | |
| 219 | - Visualizer_Render_Sidebar_Google::enqueue_assets( array( 'media-editor' ) ), | |
| 220 | - Visualizer_Render_Sidebar_Type_DataTable::enqueue_assets( array( 'media-editor' ) ), | |
| 221 | - ); | |
| 222 | - | |
| 223 | - wp_enqueue_script( 'visualizer-media-model', VISUALIZER_ABSURL . 'js/media/model.js', $deps, Visualizer_Plugin::VERSION, true ); | |
| 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 ); | |
| 224 | 219 | wp_enqueue_script( 'visualizer-media-collection', VISUALIZER_ABSURL . 'js/media/collection.js', array( 'visualizer-media-model' ), Visualizer_Plugin::VERSION, true ); |
| 225 | 220 | wp_enqueue_script( 'visualizer-media-controller', VISUALIZER_ABSURL . 'js/media/controller.js', array( 'visualizer-media-collection' ), Visualizer_Plugin::VERSION, true ); |
| 226 | 221 | wp_enqueue_script( 'visualizer-media-view', VISUALIZER_ABSURL . 'js/media/view.js', array( 'visualizer-media-controller' ), Visualizer_Plugin::VERSION, true ); |
| 227 | 222 | wp_localize_script( |
| 228 | - 'visualizer-media-view', | |
| 229 | - 'visualizer', | |
| 230 | - array( | |
| 223 | + 'visualizer-media-view', 'visualizer', array( | |
| 231 | 224 | 'i10n' => array( |
| 232 | 225 | 'insert' => __( 'Insert', 'visualizer' ), |
| 233 | 226 | ), |
| 234 | 227 | ) |
| @@ -282,9 +275,9 @@ | ||
| 282 | 275 | * @static |
| 283 | 276 | * @access private |
| 284 | 277 | * @return array The associated array of chart types with localized names. |
| 285 | 278 | */ |
| 286 | - public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darray = false, $add_select = false, $where = null ) { | |
| 279 | + public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darray = false, $add_select = false ) { | |
| 287 | 280 | $additional = array(); |
| 288 | 281 | if ( $add_select ) { |
| 289 | 282 | $additional['select'] = array( |
| 290 | 283 | 'name' => esc_html__( 'All', 'visualizer' ), |
| @@ -292,14 +285,9 @@ | ||
| 292 | 285 | ); |
| 293 | 286 | } |
| 294 | 287 | |
| 295 | 288 | $types = array_merge( |
| 296 | - $additional, | |
| 297 | - array( | |
| 298 | - 'dataTable' => array( | |
| 299 | - 'name' => esc_html__( 'Table (New)', 'visualizer' ), | |
| 300 | - 'enabled' => true, | |
| 301 | - ), | |
| 289 | + $additional, array( | |
| 302 | 290 | 'pie' => array( |
| 303 | 291 | 'name' => esc_html__( 'Pie', 'visualizer' ), |
| 304 | 292 | 'enabled' => true, |
| 305 | 293 | ), |
| @@ -322,16 +310,16 @@ | ||
| 322 | 310 | 'column' => array( |
| 323 | 311 | 'name' => esc_html__( 'Column', 'visualizer' ), |
| 324 | 312 | 'enabled' => true, |
| 325 | 313 | ), |
| 314 | + 'gauge' => array( | |
| 315 | + 'name' => esc_html__( 'Gauge', 'visualizer' ), | |
| 316 | + 'enabled' => true, | |
| 317 | + ), | |
| 326 | 318 | 'scatter' => array( |
| 327 | 319 | 'name' => esc_html__( 'Scatter', 'visualizer' ), |
| 328 | 320 | 'enabled' => true, |
| 329 | 321 | ), |
| 330 | - 'gauge' => array( | |
| 331 | - 'name' => esc_html__( 'Gauge', 'visualizer' ), | |
| 332 | - 'enabled' => true, | |
| 333 | - ), | |
| 334 | 322 | 'candlestick' => array( |
| 335 | 323 | 'name' => esc_html__( 'Candlestick', 'visualizer' ), |
| 336 | 324 | 'enabled' => true, |
| 337 | 325 | ), |
| @@ -336,9 +324,9 @@ | ||
| 336 | 324 | 'enabled' => true, |
| 337 | 325 | ), |
| 338 | 326 | // pro types |
| 339 | 327 | 'table' => array( |
| 340 | - 'name' => esc_html__( 'Table (Deprecated)', 'visualizer' ), | |
| 328 | + 'name' => esc_html__( 'Table', 'visualizer' ), | |
| 341 | 329 | 'enabled' => false, |
| 342 | 330 | ), |
| 343 | 331 | 'timeline' => array( |
| 344 | 332 | 'name' => esc_html__( 'Timeline', 'visualizer' ), |
| @@ -376,83 +364,8 @@ | ||
| 376 | 364 | } |
| 377 | 365 | $types = $doubleD; |
| 378 | 366 | } |
| 379 | 367 | |
| 380 | - return self::handleDeprecatedCharts( $types, $enabledOnly, $get2Darray, $where ); | |
| 381 | - } | |
| 382 | - | |
| 383 | - /** | |
| 384 | - * Handle (soon-to-be) deprecated charts. | |
| 385 | - */ | |
| 386 | - private static function handleDeprecatedCharts( $types, $enabledOnly, $get2Darray, $where ) { | |
| 387 | - $deprecated = array(); | |
| 388 | - | |
| 389 | - switch ( $where ) { | |
| 390 | - case 'library': | |
| 391 | - // if the user has a Google Table chart, show it as deprecated otherwise remove the option from the library. | |
| 392 | - if ( ! self::hasChartType( 'table' ) ) { | |
| 393 | - $deprecated[] = 'table'; | |
| 394 | - if ( $get2Darray ) { | |
| 395 | - $types['dataTable'] = esc_html__( 'Table', 'visualizer' ); | |
| 396 | - } else { | |
| 397 | - $types['dataTable']['name'] = esc_html__( 'Table', 'visualizer' ); | |
| 398 | - } | |
| 399 | - } | |
| 400 | - | |
| 401 | - // if a user has a Gauge/Candlestick chart, then let them keep using it. | |
| 402 | - if ( ! VISUALIZER_PRO ) { | |
| 403 | - if ( ! self::hasChartType( 'gauge' ) ) { | |
| 404 | - if ( $get2Darray ) { | |
| 405 | - $deprecated[] = 'gauge'; | |
| 406 | - } else { | |
| 407 | - $types['gauge']['enabled'] = false; | |
| 408 | - } | |
| 409 | - } | |
| 410 | - if ( ! self::hasChartType( 'candlestick' ) ) { | |
| 411 | - if ( $get2Darray ) { | |
| 412 | - $deprecated[] = 'candlestick'; | |
| 413 | - } else { | |
| 414 | - $types['candlestick']['enabled'] = false; | |
| 415 | - } | |
| 416 | - } | |
| 417 | - } | |
| 418 | - break; | |
| 419 | - default: | |
| 420 | - // remove the option to create a Google Table chart. | |
| 421 | - $deprecated[] = 'table'; | |
| 422 | - | |
| 423 | - // rename the new table chart type. | |
| 424 | - if ( $get2Darray ) { | |
| 425 | - $types['dataTable'] = esc_html__( 'Table', 'visualizer' ); | |
| 426 | - } else { | |
| 427 | - $types['dataTable']['name'] = esc_html__( 'Table', 'visualizer' ); | |
| 428 | - } | |
| 429 | - | |
| 430 | - // if a user has a Gauge/Candlestick chart, then let them keep using it. | |
| 431 | - if ( ! VISUALIZER_PRO ) { | |
| 432 | - if ( ! self::hasChartType( 'gauge' ) ) { | |
| 433 | - if ( $get2Darray ) { | |
| 434 | - $deprecated[] = 'gauge'; | |
| 435 | - } else { | |
| 436 | - $types['gauge']['enabled'] = false; | |
| 437 | - } | |
| 438 | - } | |
| 439 | - if ( ! self::hasChartType( 'candlestick' ) ) { | |
| 440 | - if ( $get2Darray ) { | |
| 441 | - $deprecated[] = 'candlestick'; | |
| 442 | - } else { | |
| 443 | - $types['candlestick']['enabled'] = false; | |
| 444 | - } | |
| 445 | - } | |
| 446 | - } | |
| 447 | - } | |
| 448 | - | |
| 449 | - if ( $deprecated ) { | |
| 450 | - foreach ( $deprecated as $type ) { | |
| 451 | - unset( $types[ $type ] ); | |
| 452 | - } | |
| 453 | - } | |
| 454 | - | |
| 455 | 368 | return $types; |
| 456 | 369 | } |
| 457 | 370 | |
| 458 | 371 | /** |
| @@ -462,9 +375,9 @@ | ||
| 462 | 375 | * @global string $pagenow The name of the current page. |
| 463 | 376 | * |
| 464 | 377 | * @access public |
| 465 | 378 | */ |
| 466 | - public function renderTemplates() { | |
| 379 | + public function renderTempaltes() { | |
| 467 | 380 | global $pagenow; |
| 468 | 381 | if ( 'post.php' != $pagenow && 'post-new.php' != $pagenow ) { |
| 469 | 382 | return; |
| 470 | 383 | } |
| @@ -489,35 +402,21 @@ | ||
| 489 | 402 | wp_enqueue_style( 'visualizer-library', VISUALIZER_ABSURL . 'css/library.css', array(), Visualizer_Plugin::VERSION ); |
| 490 | 403 | $this->_addFilter( 'media_upload_tabs', 'setupVisualizerTab' ); |
| 491 | 404 | wp_enqueue_media(); |
| 492 | 405 | wp_enqueue_script( |
| 493 | - 'visualizer-library', | |
| 494 | - VISUALIZER_ABSURL . 'js/library.js', | |
| 495 | - array( | |
| 406 | + 'visualizer-library', VISUALIZER_ABSURL . 'js/library.js', array( | |
| 496 | 407 | 'jquery', |
| 497 | 408 | 'media-views', |
| 498 | - ), | |
| 499 | - Visualizer_Plugin::VERSION, | |
| 500 | - true | |
| 409 | + ), Visualizer_Plugin::VERSION, true | |
| 501 | 410 | ); |
| 502 | - | |
| 503 | - wp_enqueue_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true ); | |
| 504 | - | |
| 505 | - $query = $this->getQuery(); | |
| 506 | - while ( $query->have_posts() ) { | |
| 507 | - $chart = $query->next_post(); | |
| 508 | - $library = $this->load_chart_type( $chart->ID ); | |
| 509 | - if ( is_null( $library ) ) { | |
| 510 | - continue; | |
| 511 | - } | |
| 512 | - wp_enqueue_script( | |
| 513 | - "visualizer-render-$library", | |
| 514 | - VISUALIZER_ABSURL . 'js/render-facade.js', | |
| 515 | - apply_filters( 'visualizer_assets_render', array( 'visualizer-library', 'visualizer-customization' ), true ), | |
| 516 | - Visualizer_Plugin::VERSION, | |
| 517 | - true | |
| 518 | - ); | |
| 519 | - } | |
| 411 | + wp_enqueue_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true ); | |
| 412 | + wp_enqueue_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true ); | |
| 413 | + wp_enqueue_script( | |
| 414 | + 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( | |
| 415 | + 'google-jsapi-old', | |
| 416 | + 'visualizer-library', | |
| 417 | + ), Visualizer_Plugin::VERSION, true | |
| 418 | + ); | |
| 520 | 419 | } |
| 521 | 420 | } |
| 522 | 421 | |
| 523 | 422 | /** |
| @@ -550,22 +449,18 @@ | ||
| 550 | 449 | $this->_libraryPage = add_submenu_page( 'upload.php', $title, $title, 'edit_posts', Visualizer_Plugin::NAME, $callback ); |
| 551 | 450 | } |
| 552 | 451 | |
| 553 | 452 | /** |
| 554 | - * Get the instance of WP_Query that fetches the charts as per the given criteria. | |
| 453 | + * Renders visualizer library page. | |
| 454 | + * | |
| 455 | + * @since 1.0.0 | |
| 456 | + * | |
| 457 | + * @access public | |
| 555 | 458 | */ |
| 556 | - private function getQuery() { | |
| 557 | - static $q; | |
| 558 | - if ( ! is_null( $q ) ) { | |
| 559 | - return $q; | |
| 560 | - } | |
| 561 | - | |
| 459 | + public function renderLibraryPage() { | |
| 562 | 460 | // get current page |
| 563 | 461 | $page = filter_input( |
| 564 | - INPUT_GET, | |
| 565 | - 'vpage', | |
| 566 | - FILTER_VALIDATE_INT, | |
| 567 | - array( | |
| 462 | + INPUT_GET, 'vpage', FILTER_VALIDATE_INT, array( | |
| 568 | 463 | 'options' => array( |
| 569 | 464 | 'min_range' => 1, |
| 570 | 465 | 'default' => 1, |
| 571 | 466 | ), |
| @@ -601,89 +496,37 @@ | ||
| 601 | 496 | $meta = isset( $query_args['meta_query'] ) ? $query_args['meta_query'] : array(); |
| 602 | 497 | $meta[] = $query; |
| 603 | 498 | $query_args['meta_query'] = $meta; |
| 604 | 499 | } |
| 605 | - $q = new WP_Query( $query_args ); | |
| 606 | - return $q; | |
| 607 | - } | |
| 608 | - | |
| 609 | - /** | |
| 610 | - * Renders visualizer library page. | |
| 611 | - * | |
| 612 | - * @since 1.0.0 | |
| 613 | - * | |
| 614 | - * @access public | |
| 615 | - */ | |
| 616 | - public function renderLibraryPage() { | |
| 500 | + // Added by Ash/Upwork | |
| 501 | + // fetch charts | |
| 617 | 502 | $charts = array(); |
| 618 | - $query = $this->getQuery(); | |
| 619 | - | |
| 620 | - // get current page | |
| 621 | - $page = filter_input( | |
| 622 | - INPUT_GET, | |
| 623 | - 'vpage', | |
| 624 | - FILTER_VALIDATE_INT, | |
| 625 | - array( | |
| 626 | - 'options' => array( | |
| 627 | - 'min_range' => 1, | |
| 628 | - 'default' => 1, | |
| 629 | - ), | |
| 630 | - ) | |
| 631 | - ); | |
| 632 | - // add chart type filter to the query arguments | |
| 633 | - $filter = filter_input( INPUT_GET, 'type' ); | |
| 634 | - if ( ! ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes() ) ) ) { | |
| 635 | - $filter = 'all'; | |
| 636 | - } | |
| 637 | - | |
| 638 | - $css = ''; | |
| 503 | + $query = new WP_Query( $query_args ); | |
| 639 | 504 | while ( $query->have_posts() ) { |
| 640 | 505 | $chart = $query->next_post(); |
| 641 | 506 | |
| 642 | 507 | // 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. |
| 643 | 508 | $chart = $this->handleExistingRevisions( $chart->ID, $chart ); |
| 644 | - // refresh a "live" db query chart. | |
| 645 | - $chart = apply_filters( 'visualizer_schedule_refresh_chart', $chart, $chart->ID, false ); | |
| 646 | 509 | |
| 647 | - $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ); | |
| 648 | - | |
| 649 | 510 | // fetch and update settings |
| 650 | 511 | $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true ); |
| 651 | - | |
| 652 | - $settings = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SETTINGS, $settings, $chart->ID, $type ); | |
| 653 | - if ( ! empty( $atts['settings'] ) ) { | |
| 654 | - $settings = apply_filters( $atts['settings'], $settings, $chart->ID, $type ); | |
| 655 | - } | |
| 656 | - | |
| 657 | 512 | unset( $settings['height'], $settings['width'] ); |
| 513 | + $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ); | |
| 658 | 514 | $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type ); |
| 659 | 515 | $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( html_entity_decode( $chart->post_content ) ), $chart->ID, $type ); |
| 660 | - | |
| 661 | - $library = $this->load_chart_type( $chart->ID ); | |
| 662 | - | |
| 663 | - $id = 'visualizer-' . $chart->ID; | |
| 664 | - $arguments = $this->get_inline_custom_css( $id, $settings ); | |
| 665 | - if ( ! empty( $arguments ) ) { | |
| 666 | - $css .= $arguments[0]; | |
| 667 | - $settings = $arguments[1]; | |
| 668 | - } | |
| 669 | - | |
| 670 | 516 | // add chart to the array |
| 671 | - $charts[ $id ] = array( | |
| 517 | + $charts[ 'visualizer-' . $chart->ID ] = array( | |
| 672 | 518 | 'id' => $chart->ID, |
| 673 | 519 | 'type' => $type, |
| 674 | 520 | 'series' => $series, |
| 675 | 521 | 'settings' => $settings, |
| 676 | 522 | 'data' => $data, |
| 677 | - 'library' => $library, | |
| 678 | 523 | ); |
| 679 | 524 | } |
| 680 | 525 | // enqueue charts array |
| 681 | 526 | $ajaxurl = admin_url( 'admin-ajax.php' ); |
| 682 | 527 | wp_localize_script( |
| 683 | - 'visualizer-library', | |
| 684 | - 'visualizer', | |
| 685 | - array( | |
| 528 | + 'visualizer-library', 'visualizer', array( | |
| 686 | 529 | 'language' => $this->get_language(), |
| 687 | 530 | 'map_api_key' => get_option( 'visualizer-map-api-key' ), |
| 688 | 531 | 'charts' => $charts, |
| 689 | 532 | 'urls' => array( |
| @@ -692,20 +535,17 @@ | ||
| 692 | 535 | array( |
| 693 | 536 | 'action' => Visualizer_Plugin::ACTION_CREATE_CHART, |
| 694 | 537 | 'library' => 'yes', |
| 695 | 538 | 'type' => isset( $_GET['type'] ) ? $_GET['type'] : '', |
| 696 | - ), | |
| 697 | - $ajaxurl | |
| 539 | + ), $ajaxurl | |
| 698 | 540 | ), |
| 699 | 541 | 'edit' => add_query_arg( |
| 700 | 542 | array( |
| 701 | 543 | 'action' => Visualizer_Plugin::ACTION_EDIT_CHART, |
| 702 | 544 | 'library' => 'yes', |
| 703 | - ), | |
| 704 | - $ajaxurl | |
| 545 | + ), $ajaxurl | |
| 705 | 546 | ), |
| 706 | 547 | ), |
| 707 | - 'page_type' => 'library', | |
| 708 | 548 | ) |
| 709 | 549 | ); |
| 710 | 550 | // render library page |
| 711 | 551 | $render = new Visualizer_Render_Library(); |
| @@ -710,10 +550,9 @@ | ||
| 710 | 550 | // render library page |
| 711 | 551 | $render = new Visualizer_Render_Library(); |
| 712 | 552 | $render->charts = $charts; |
| 713 | 553 | $render->type = $filter; |
| 714 | - $render->types = self::_getChartTypesLocalized( false, false, false, true ); | |
| 715 | - $render->custom_css = $css; | |
| 554 | + $render->types = self::_getChartTypesLocalized(); | |
| 716 | 555 | $render->pagination = paginate_links( |
| 717 | 556 | array( |
| 718 | 557 | 'base' => add_query_arg( 'vpage', '%#%' ), |
| 719 | 558 | 'format' => '', |