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