PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.1.3
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.1.3
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
← All changes | classes/Visualizer/Module/Admin.php +200 -39 3.0.83.1.3 View file →
@@ -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,16 +212,23 @@
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 = 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 );
219 224 wp_enqueue_script( 'visualizer-media-collection', VISUALIZER_ABSURL . 'js/media/collection.js', array( 'visualizer-media-model' ), Visualizer_Plugin::VERSION, true );
220 225 wp_enqueue_script( 'visualizer-media-controller', VISUALIZER_ABSURL . 'js/media/controller.js', array( 'visualizer-media-collection' ), Visualizer_Plugin::VERSION, true );
221 226 wp_enqueue_script( 'visualizer-media-view', VISUALIZER_ABSURL . 'js/media/view.js', array( 'visualizer-media-controller' ), Visualizer_Plugin::VERSION, true );
222 227 wp_localize_script(
223 - 'visualizer-media-view', 'visualizer', array(
228 + 'visualizer-media-view',
229 + 'visualizer',
230 + array(
224 231 'i10n' => array(
225 232 'insert' => __( 'Insert', 'visualizer' ),
226 233 ),
227 234 )
@@ -275,9 +282,9 @@
275 282 * @static
276 283 * @access private
277 284 * @return array The associated array of chart types with localized names.
278 285 */
279 - public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darray = false, $add_select = false ) {
286 + public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darray = false, $add_select = false, $where = null ) {
280 287 $additional = array();
281 288 if ( $add_select ) {
282 289 $additional['select'] = array(
283 290 'name' => esc_html__( 'All', 'visualizer' ),
@@ -285,9 +292,14 @@
285 292 );
286 293 }
287 294
288 295 $types = array_merge(
289 - $additional, array(
296 + $additional,
297 + array(
298 + 'dataTable' => array(
299 + 'name' => esc_html__( 'Table (New)', 'visualizer' ),
300 + 'enabled' => true,
301 + ),
290 302 'pie' => array(
291 303 'name' => esc_html__( 'Pie', 'visualizer' ),
292 304 'enabled' => true,
293 305 ),
@@ -310,16 +322,16 @@
310 322 'column' => array(
311 323 'name' => esc_html__( 'Column', 'visualizer' ),
312 324 'enabled' => true,
313 325 ),
326 + 'scatter' => array(
327 + 'name' => esc_html__( 'Scatter', 'visualizer' ),
328 + 'enabled' => true,
329 + ),
314 330 'gauge' => array(
315 331 'name' => esc_html__( 'Gauge', 'visualizer' ),
316 332 'enabled' => true,
317 333 ),
318 - 'scatter' => array(
319 - 'name' => esc_html__( 'Scatter', 'visualizer' ),
320 - 'enabled' => true,
321 - ),
322 334 'candlestick' => array(
323 335 'name' => esc_html__( 'Candlestick', 'visualizer' ),
324 336 'enabled' => true,
325 337 ),
@@ -324,9 +336,9 @@
324 336 'enabled' => true,
325 337 ),
326 338 // pro types
327 339 'table' => array(
328 - 'name' => esc_html__( 'Table', 'visualizer' ),
340 + 'name' => esc_html__( 'Table (Deprecated)', 'visualizer' ),
329 341 'enabled' => false,
330 342 ),
331 343 'timeline' => array(
332 344 'name' => esc_html__( 'Timeline', 'visualizer' ),
@@ -364,8 +376,83 @@
364 376 }
365 377 $types = $doubleD;
366 378 }
367 379
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 +
368 455 return $types;
369 456 }
370 457
371 458 /**
@@ -375,9 +462,9 @@
375 462 * @global string $pagenow The name of the current page.
376 463 *
377 464 * @access public
378 465 */
379 - public function renderTempaltes() {
466 + public function renderTemplates() {
380 467 global $pagenow;
381 468 if ( 'post.php' != $pagenow && 'post-new.php' != $pagenow ) {
382 469 return;
383 470 }
@@ -402,21 +489,35 @@
402 489 wp_enqueue_style( 'visualizer-library', VISUALIZER_ABSURL . 'css/library.css', array(), Visualizer_Plugin::VERSION );
403 490 $this->_addFilter( 'media_upload_tabs', 'setupVisualizerTab' );
404 491 wp_enqueue_media();
405 492 wp_enqueue_script(
406 - 'visualizer-library', VISUALIZER_ABSURL . 'js/library.js', array(
493 + 'visualizer-library',
494 + VISUALIZER_ABSURL . 'js/library.js',
495 + array(
407 496 'jquery',
408 497 'media-views',
409 - ), Visualizer_Plugin::VERSION, true
498 + ),
499 + Visualizer_Plugin::VERSION,
500 + true
410 501 );
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 - );
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 + }
419 520 }
420 521 }
421 522
422 523 /**
@@ -449,18 +550,22 @@
449 550 $this->_libraryPage = add_submenu_page( 'upload.php', $title, $title, 'edit_posts', Visualizer_Plugin::NAME, $callback );
450 551 }
451 552
452 553 /**
453 - * Renders visualizer library page.
454 - *
455 - * @since 1.0.0
456 - *
457 - * @access public
554 + * Get the instance of WP_Query that fetches the charts as per the given criteria.
458 555 */
459 - public function renderLibraryPage() {
556 + private function getQuery() {
557 + static $q;
558 + if ( ! is_null( $q ) ) {
559 + return $q;
560 + }
561 +
460 562 // get current page
461 563 $page = filter_input(
462 - INPUT_GET, 'vpage', FILTER_VALIDATE_INT, array(
564 + INPUT_GET,
565 + 'vpage',
566 + FILTER_VALIDATE_INT,
567 + array(
463 568 'options' => array(
464 569 'min_range' => 1,
465 570 'default' => 1,
466 571 ),
@@ -496,37 +601,89 @@
496 601 $meta = isset( $query_args['meta_query'] ) ? $query_args['meta_query'] : array();
497 602 $meta[] = $query;
498 603 $query_args['meta_query'] = $meta;
499 604 }
500 - // Added by Ash/Upwork
501 - // fetch charts
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() {
502 617 $charts = array();
503 - $query = new WP_Query( $query_args );
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 = '';
504 639 while ( $query->have_posts() ) {
505 640 $chart = $query->next_post();
506 641
507 642 // 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.
508 643 $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 );
509 646
647 + $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
648 +
510 649 // fetch and update settings
511 650 $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 +
512 657 unset( $settings['height'], $settings['width'] );
513 - $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
514 658 $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type );
515 659 $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 +
516 670 // add chart to the array
517 - $charts[ 'visualizer-' . $chart->ID ] = array(
671 + $charts[ $id ] = array(
518 672 'id' => $chart->ID,
519 673 'type' => $type,
520 674 'series' => $series,
521 675 'settings' => $settings,
522 676 'data' => $data,
677 + 'library' => $library,
523 678 );
524 679 }
525 680 // enqueue charts array
526 681 $ajaxurl = admin_url( 'admin-ajax.php' );
527 682 wp_localize_script(
528 - 'visualizer-library', 'visualizer', array(
683 + 'visualizer-library',
684 + 'visualizer',
685 + array(
529 686 'language' => $this->get_language(),
530 687 'map_api_key' => get_option( 'visualizer-map-api-key' ),
531 688 'charts' => $charts,
532 689 'urls' => array(
@@ -535,17 +692,20 @@
535 692 array(
536 693 'action' => Visualizer_Plugin::ACTION_CREATE_CHART,
537 694 'library' => 'yes',
538 695 'type' => isset( $_GET['type'] ) ? $_GET['type'] : '',
539 - ), $ajaxurl
696 + ),
697 + $ajaxurl
540 698 ),
541 699 'edit' => add_query_arg(
542 700 array(
543 701 'action' => Visualizer_Plugin::ACTION_EDIT_CHART,
544 702 'library' => 'yes',
545 - ), $ajaxurl
703 + ),
704 + $ajaxurl
546 705 ),
547 706 ),
707 + 'page_type' => 'library',
548 708 )
549 709 );
550 710 // render library page
551 711 $render = new Visualizer_Render_Library();
@@ -550,9 +710,10 @@
550 710 // render library page
551 711 $render = new Visualizer_Render_Library();
552 712 $render->charts = $charts;
553 713 $render->type = $filter;
554 - $render->types = self::_getChartTypesLocalized();
714 + $render->types = self::_getChartTypesLocalized( false, false, false, true );
715 + $render->custom_css = $css;
555 716 $render->pagination = paginate_links(
556 717 array(
557 718 'base' => add_query_arg( 'vpage', '%#%' ),
558 719 'format' => '',