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