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 +282 -43 3.0.63.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 );
@@ -61,17 +61,80 @@
61 61 $this->_addFilter( 'visualizer_logger_data', 'getLoggerData' );
62 62 $this->_addFilter( 'visualizer_get_chart_counts', 'getChartCountsByTypeAndMeta' );
63 63 $this->_addFilter( 'visualizer_feedback_review_trigger', 'feedbackReviewTrigger' );
64 64
65 + // revision support.
66 + $this->_addFilter( 'wp_revisions_to_keep', 'limitRevisions', null, 10, 2 );
67 + $this->_addAction( '_wp_put_post_revision', 'addRevision', null, 10, 1 );
68 + $this->_addAction( 'wp_restore_post_revision', 'restoreRevision', null, 10, 2 );
69 +
65 70 $this->_addAction( 'admin_init', 'init' );
66 71 }
67 72
68 73 /**
74 + * No limits on revisions.
75 + */
76 + public function limitRevisions( $num, $post ) {
77 + if ( Visualizer_Plugin::CPT_VISUALIZER === $post->post_type ) {
78 + return -1;
79 + }
80 + return $num;
81 + }
82 +
83 + /**
84 + * Add a revision.
85 + */
86 + public function addRevision( $revision_id ) {
87 + $parent_id = wp_is_post_revision( $revision_id );
88 + if ( Visualizer_Plugin::CPT_VISUALIZER === get_post_type( $parent_id ) ) {
89 + // add the meta data to this revision.
90 + $meta = get_post_meta( $parent_id, '', true );
91 +
92 + if ( $meta ) {
93 + foreach ( $meta as $key => $value ) {
94 + if ( 0 === strpos( $key, 'visualizer' ) ) {
95 + add_metadata( 'post', $revision_id, $key, maybe_unserialize( $value[0] ) );
96 + }
97 + }
98 + }
99 + }
100 + }
101 +
102 + /**
103 + * Restore a revision.
104 + */
105 + public function restoreRevision( $post_id, $revision_id ) {
106 + if ( Visualizer_Plugin::CPT_VISUALIZER === get_post_type( $post_id ) ) {
107 + // get the meta information from the revision.
108 + $meta = get_metadata( 'post', $revision_id, '', true );
109 +
110 + // delete all meta information from the post before adding.
111 + $post_meta = get_post_meta( $post_id, '', true );
112 + if ( $post_meta ) {
113 + foreach ( $meta as $key => $value ) {
114 + if ( 0 === strpos( $key, 'visualizer' ) ) {
115 + delete_post_meta( $post_id, $key );
116 + }
117 + }
118 + }
119 +
120 + if ( $meta ) {
121 + foreach ( $meta as $key => $value ) {
122 + if ( 0 === strpos( $key, 'visualizer' ) ) {
123 + add_post_meta( $post_id, $key, maybe_unserialize( $value[0] ) );
124 + }
125 + }
126 + }
127 + }
128 + }
129 +
130 + /**
69 131 * Admin init.
70 132 *
71 133 * @access public
72 134 */
73 135 public function init() {
136 + // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
74 137 if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) && 'true' == get_user_option( 'rich_editing' ) ) {
75 138 $this->_addFilter( 'mce_external_languages', 'add_tinymce_lang', 10, 1 );
76 139 $this->_addFilter( 'mce_external_plugins', 'tinymce_plugin', 10, 1 );
77 140 $this->_addFilter( 'mce_buttons', 'register_mce_button', 10, 1 );
@@ -150,14 +213,28 @@
150 213 public function enqueueMediaScripts() {
151 214 global $typenow;
152 215 if ( post_type_supports( $typenow, 'editor' ) ) {
153 216 wp_enqueue_style( 'visualizer-media', VISUALIZER_ABSURL . 'css/media.css', array( 'media-views' ), Visualizer_Plugin::VERSION );
154 - wp_enqueue_script( 'visualizer-google-jsapi-new', '//www.gstatic.com/charts/loader.js', array( 'media-editor' ), null, true );
155 - wp_enqueue_script( 'visualizer-google-jsapi-old', '//www.google.com/jsapi', array( 'visualizer-google-jsapi-new' ), null, true );
156 - 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 );
157 225 wp_enqueue_script( 'visualizer-media-collection', VISUALIZER_ABSURL . 'js/media/collection.js', array( 'visualizer-media-model' ), Visualizer_Plugin::VERSION, true );
158 226 wp_enqueue_script( 'visualizer-media-controller', VISUALIZER_ABSURL . 'js/media/controller.js', array( 'visualizer-media-collection' ), Visualizer_Plugin::VERSION, true );
159 227 wp_enqueue_script( 'visualizer-media-view', VISUALIZER_ABSURL . 'js/media/view.js', array( 'visualizer-media-controller' ), Visualizer_Plugin::VERSION, true );
228 + wp_localize_script(
229 + 'visualizer-media-view',
230 + 'visualizer',
231 + array(
232 + 'i10n' => array(
233 + 'insert' => __( 'Insert', 'visualizer' ),
234 + ),
235 + )
236 + );
160 237 wp_enqueue_script( 'visualizer-media-toolbar', VISUALIZER_ABSURL . 'js/media/toolbar.js', array( 'visualizer-media-view' ), Visualizer_Plugin::VERSION, true );
161 238 wp_enqueue_script( 'visualizer-media', VISUALIZER_ABSURL . 'js/media.js', array( 'visualizer-media-toolbar' ), Visualizer_Plugin::VERSION, true );
162 239 }
163 240 }
@@ -206,9 +283,9 @@
206 283 * @static
207 284 * @access private
208 285 * @return array The associated array of chart types with localized names.
209 286 */
210 - 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 ) {
211 288 $additional = array();
212 289 if ( $add_select ) {
213 290 $additional['select'] = array(
214 291 'name' => esc_html__( 'All', 'visualizer' ),
@@ -216,9 +293,14 @@
216 293 );
217 294 }
218 295
219 296 $types = array_merge(
220 - $additional, array(
297 + $additional,
298 + array(
299 + 'dataTable' => array(
300 + 'name' => esc_html__( 'Table (New)', 'visualizer' ),
301 + 'enabled' => true,
302 + ),
221 303 'pie' => array(
222 304 'name' => esc_html__( 'Pie', 'visualizer' ),
223 305 'enabled' => true,
224 306 ),
@@ -241,16 +323,16 @@
241 323 'column' => array(
242 324 'name' => esc_html__( 'Column', 'visualizer' ),
243 325 'enabled' => true,
244 326 ),
327 + 'scatter' => array(
328 + 'name' => esc_html__( 'Scatter', 'visualizer' ),
329 + 'enabled' => true,
330 + ),
245 331 'gauge' => array(
246 332 'name' => esc_html__( 'Gauge', 'visualizer' ),
247 333 'enabled' => true,
248 334 ),
249 - 'scatter' => array(
250 - 'name' => esc_html__( 'Scatter', 'visualizer' ),
251 - 'enabled' => true,
252 - ),
253 335 'candlestick' => array(
254 336 'name' => esc_html__( 'Candlestick', 'visualizer' ),
255 337 'enabled' => true,
256 338 ),
@@ -255,9 +337,9 @@
255 337 'enabled' => true,
256 338 ),
257 339 // pro types
258 340 'table' => array(
259 - 'name' => esc_html__( 'Table', 'visualizer' ),
341 + 'name' => esc_html__( 'Table (Deprecated)', 'visualizer' ),
260 342 'enabled' => false,
261 343 ),
262 344 'timeline' => array(
263 345 'name' => esc_html__( 'Timeline', 'visualizer' ),
@@ -295,8 +377,83 @@
295 377 }
296 378 $types = $doubleD;
297 379 }
298 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 +
299 456 return $types;
300 457 }
301 458
302 459 /**
@@ -306,11 +463,11 @@
306 463 * @global string $pagenow The name of the current page.
307 464 *
308 465 * @access public
309 466 */
310 - public function renderTempaltes() {
467 + public function renderTemplates() {
311 468 global $pagenow;
312 - if ( 'post.php' != $pagenow && 'post-new.php' != $pagenow ) {
469 + if ( 'post.php' !== $pagenow && 'post-new.php' !== $pagenow ) {
313 470 return;
314 471 }
315 472 $render = new Visualizer_Render_Templates();
316 473 $render->render();
@@ -328,26 +485,40 @@
328 485 *
329 486 * @param string $suffix The current page suffix.
330 487 */
331 488 public function enqueueLibraryScripts( $suffix ) {
332 - if ( $suffix == $this->_libraryPage ) {
489 + if ( $suffix === $this->_libraryPage ) {
333 490 wp_enqueue_style( 'visualizer-library', VISUALIZER_ABSURL . 'css/library.css', array(), Visualizer_Plugin::VERSION );
334 491 $this->_addFilter( 'media_upload_tabs', 'setupVisualizerTab' );
335 492 wp_enqueue_media();
336 493 wp_enqueue_script(
337 - 'visualizer-library', VISUALIZER_ABSURL . 'js/library.js', array(
494 + 'visualizer-library',
495 + VISUALIZER_ABSURL . 'js/library.js',
496 + array(
338 497 'jquery',
339 498 'media-views',
340 - ), Visualizer_Plugin::VERSION, true
499 + ),
500 + Visualizer_Plugin::VERSION,
501 + true
341 502 );
342 - wp_enqueue_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true );
343 - wp_enqueue_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true );
344 - wp_enqueue_script(
345 - 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array(
346 - 'google-jsapi-old',
347 - 'visualizer-library',
348 - ), Visualizer_Plugin::VERSION, true
349 - );
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 + }
350 521 }
351 522 }
352 523
353 524 /**
@@ -380,18 +551,22 @@
380 551 $this->_libraryPage = add_submenu_page( 'upload.php', $title, $title, 'edit_posts', Visualizer_Plugin::NAME, $callback );
381 552 }
382 553
383 554 /**
384 - * Renders visualizer library page.
385 - *
386 - * @since 1.0.0
387 - *
388 - * @access public
555 + * Get the instance of WP_Query that fetches the charts as per the given criteria.
389 556 */
390 - public function renderLibraryPage() {
557 + private function getQuery() {
558 + static $q;
559 + if ( ! is_null( $q ) ) {
560 + return $q;
561 + }
562 +
391 563 // get current page
392 564 $page = filter_input(
393 - INPUT_GET, 'vpage', FILTER_VALIDATE_INT, array(
565 + INPUT_GET,
566 + 'vpage',
567 + FILTER_VALIDATE_INT,
568 + array(
394 569 'options' => array(
395 570 'min_range' => 1,
396 571 'default' => 1,
397 572 ),
@@ -404,9 +579,9 @@
404 579 'paged' => $page,
405 580 );
406 581 // add chart type filter to the query arguments
407 582 $filter = filter_input( INPUT_GET, 'type' );
408 - if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes() ) ) {
583 + if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes(), true ) ) {
409 584 $query_args['meta_query'] = array(
410 585 array(
411 586 'key' => Visualizer_Plugin::CF_CHART_TYPE,
412 587 'value' => $filter,
@@ -427,33 +602,91 @@
427 602 $meta = isset( $query_args['meta_query'] ) ? $query_args['meta_query'] : array();
428 603 $meta[] = $query;
429 604 $query_args['meta_query'] = $meta;
430 605 }
431 - // Added by Ash/Upwork
432 - // 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() {
433 618 $charts = array();
434 - $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 = '';
435 640 while ( $query->have_posts() ) {
436 641 $chart = $query->next_post();
642 +
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.
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 );
647 +
648 + $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
649 +
437 650 // fetch and update settings
438 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 +
439 658 unset( $settings['height'], $settings['width'] );
440 - $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
441 659 $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type );
442 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 +
443 671 // add chart to the array
444 - $charts[ 'visualizer-' . $chart->ID ] = array(
672 + $charts[ $id ] = array(
445 673 'id' => $chart->ID,
446 674 'type' => $type,
447 675 'series' => $series,
448 676 'settings' => $settings,
449 677 'data' => $data,
678 + 'library' => $library,
450 679 );
451 680 }
452 681 // enqueue charts array
453 682 $ajaxurl = admin_url( 'admin-ajax.php' );
454 683 wp_localize_script(
455 - 'visualizer-library', 'visualizer', array(
684 + 'visualizer-library',
685 + 'visualizer',
686 + array(
687 + 'language' => $this->get_language(),
688 + 'map_api_key' => get_option( 'visualizer-map-api-key' ),
456 689 'charts' => $charts,
457 690 'urls' => array(
458 691 'base' => add_query_arg( 'vpage', false ),
459 692 'create' => add_query_arg(
@@ -459,17 +692,22 @@
459 692 'create' => add_query_arg(
460 693 array(
461 694 'action' => Visualizer_Plugin::ACTION_CREATE_CHART,
462 695 'library' => 'yes',
463 - ), $ajaxurl
696 + 'type' => isset( $_GET['type'] ) ? $_GET['type'] : '',
697 + ),
698 + $ajaxurl
464 699 ),
465 700 'edit' => add_query_arg(
466 701 array(
467 702 'action' => Visualizer_Plugin::ACTION_EDIT_CHART,
468 703 'library' => 'yes',
469 - ), $ajaxurl
704 + ),
705 + $ajaxurl
470 706 ),
471 707 ),
708 + 'page_type' => 'library',
709 + 'is_front' => false,
472 710 )
473 711 );
474 712 // render library page
475 713 $render = new Visualizer_Render_Library();
@@ -474,9 +712,10 @@
474 712 // render library page
475 713 $render = new Visualizer_Render_Library();
476 714 $render->charts = $charts;
477 715 $render->type = $filter;
478 - $render->types = self::_getChartTypesLocalized();
716 + $render->types = self::_getChartTypesLocalized( false, false, false, true );
717 + $render->custom_css = $css;
479 718 $render->pagination = paginate_links(
480 719 array(
481 720 'base' => add_query_arg( 'vpage', '%#%' ),
482 721 'format' => '',
@@ -500,9 +739,9 @@
500 739 *
501 740 * @return array Updated array of action links.
502 741 */
503 742 public function getPluginActionLinks( $links, $file ) {
504 - if ( $file == plugin_basename( VISUALIZER_BASEFILE ) ) {
743 + if ( $file === plugin_basename( VISUALIZER_BASEFILE ) ) {
505 744 array_unshift(
506 745 $links,
507 746 sprintf(
508 747 '<a href="%s">%s</a>',
@@ -527,9 +766,9 @@
527 766 *
528 767 * @return array Updated array of plugin meta links.
529 768 */
530 769 public function getPluginMetaLinks( $plugin_meta, $plugin_file ) {
531 - if ( $plugin_file == plugin_basename( VISUALIZER_BASEFILE ) ) {
770 + if ( $plugin_file === plugin_basename( VISUALIZER_BASEFILE ) ) {
532 771 // knowledge base link
533 772 $plugin_meta[] = sprintf(
534 773 '<a href="https://github.com/codeinwp/visualizer/wiki" target="_blank">%s</a>',
535 774 esc_html__( 'Knowledge Base', 'visualizer' )