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 +274 -44 3.0.73.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,16 +213,23 @@
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 );
160 228 wp_localize_script(
161 - 'visualizer-media-view', 'visualizer', array(
229 + 'visualizer-media-view',
230 + 'visualizer',
231 + array(
162 232 'i10n' => array(
163 233 'insert' => __( 'Insert', 'visualizer' ),
164 234 ),
165 235 )
@@ -213,9 +283,9 @@
213 283 * @static
214 284 * @access private
215 285 * @return array The associated array of chart types with localized names.
216 286 */
217 - 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 ) {
218 288 $additional = array();
219 289 if ( $add_select ) {
220 290 $additional['select'] = array(
221 291 'name' => esc_html__( 'All', 'visualizer' ),
@@ -223,9 +293,14 @@
223 293 );
224 294 }
225 295
226 296 $types = array_merge(
227 - $additional, array(
297 + $additional,
298 + array(
299 + 'dataTable' => array(
300 + 'name' => esc_html__( 'Table (New)', 'visualizer' ),
301 + 'enabled' => true,
302 + ),
228 303 'pie' => array(
229 304 'name' => esc_html__( 'Pie', 'visualizer' ),
230 305 'enabled' => true,
231 306 ),
@@ -248,16 +323,16 @@
248 323 'column' => array(
249 324 'name' => esc_html__( 'Column', 'visualizer' ),
250 325 'enabled' => true,
251 326 ),
327 + 'scatter' => array(
328 + 'name' => esc_html__( 'Scatter', 'visualizer' ),
329 + 'enabled' => true,
330 + ),
252 331 'gauge' => array(
253 332 'name' => esc_html__( 'Gauge', 'visualizer' ),
254 333 'enabled' => true,
255 334 ),
256 - 'scatter' => array(
257 - 'name' => esc_html__( 'Scatter', 'visualizer' ),
258 - 'enabled' => true,
259 - ),
260 335 'candlestick' => array(
261 336 'name' => esc_html__( 'Candlestick', 'visualizer' ),
262 337 'enabled' => true,
263 338 ),
@@ -262,9 +337,9 @@
262 337 'enabled' => true,
263 338 ),
264 339 // pro types
265 340 'table' => array(
266 - 'name' => esc_html__( 'Table', 'visualizer' ),
341 + 'name' => esc_html__( 'Table (Deprecated)', 'visualizer' ),
267 342 'enabled' => false,
268 343 ),
269 344 'timeline' => array(
270 345 'name' => esc_html__( 'Timeline', 'visualizer' ),
@@ -302,8 +377,83 @@
302 377 }
303 378 $types = $doubleD;
304 379 }
305 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 +
306 456 return $types;
307 457 }
308 458
309 459 /**
@@ -313,11 +463,11 @@
313 463 * @global string $pagenow The name of the current page.
314 464 *
315 465 * @access public
316 466 */
317 - public function renderTempaltes() {
467 + public function renderTemplates() {
318 468 global $pagenow;
319 - if ( 'post.php' != $pagenow && 'post-new.php' != $pagenow ) {
469 + if ( 'post.php' !== $pagenow && 'post-new.php' !== $pagenow ) {
320 470 return;
321 471 }
322 472 $render = new Visualizer_Render_Templates();
323 473 $render->render();
@@ -335,26 +485,40 @@
335 485 *
336 486 * @param string $suffix The current page suffix.
337 487 */
338 488 public function enqueueLibraryScripts( $suffix ) {
339 - if ( $suffix == $this->_libraryPage ) {
489 + if ( $suffix === $this->_libraryPage ) {
340 490 wp_enqueue_style( 'visualizer-library', VISUALIZER_ABSURL . 'css/library.css', array(), Visualizer_Plugin::VERSION );
341 491 $this->_addFilter( 'media_upload_tabs', 'setupVisualizerTab' );
342 492 wp_enqueue_media();
343 493 wp_enqueue_script(
344 - 'visualizer-library', VISUALIZER_ABSURL . 'js/library.js', array(
494 + 'visualizer-library',
495 + VISUALIZER_ABSURL . 'js/library.js',
496 + array(
345 497 'jquery',
346 498 'media-views',
347 - ), Visualizer_Plugin::VERSION, true
499 + ),
500 + Visualizer_Plugin::VERSION,
501 + true
348 502 );
349 - wp_enqueue_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true );
350 - wp_enqueue_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true );
351 - wp_enqueue_script(
352 - 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array(
353 - 'google-jsapi-old',
354 - 'visualizer-library',
355 - ), Visualizer_Plugin::VERSION, true
356 - );
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 + }
357 521 }
358 522 }
359 523
360 524 /**
@@ -387,18 +551,22 @@
387 551 $this->_libraryPage = add_submenu_page( 'upload.php', $title, $title, 'edit_posts', Visualizer_Plugin::NAME, $callback );
388 552 }
389 553
390 554 /**
391 - * Renders visualizer library page.
392 - *
393 - * @since 1.0.0
394 - *
395 - * @access public
555 + * Get the instance of WP_Query that fetches the charts as per the given criteria.
396 556 */
397 - public function renderLibraryPage() {
557 + private function getQuery() {
558 + static $q;
559 + if ( ! is_null( $q ) ) {
560 + return $q;
561 + }
562 +
398 563 // get current page
399 564 $page = filter_input(
400 - INPUT_GET, 'vpage', FILTER_VALIDATE_INT, array(
565 + INPUT_GET,
566 + 'vpage',
567 + FILTER_VALIDATE_INT,
568 + array(
401 569 'options' => array(
402 570 'min_range' => 1,
403 571 'default' => 1,
404 572 ),
@@ -411,9 +579,9 @@
411 579 'paged' => $page,
412 580 );
413 581 // add chart type filter to the query arguments
414 582 $filter = filter_input( INPUT_GET, 'type' );
415 - if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes() ) ) {
583 + if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes(), true ) ) {
416 584 $query_args['meta_query'] = array(
417 585 array(
418 586 'key' => Visualizer_Plugin::CF_CHART_TYPE,
419 587 'value' => $filter,
@@ -434,33 +602,89 @@
434 602 $meta = isset( $query_args['meta_query'] ) ? $query_args['meta_query'] : array();
435 603 $meta[] = $query;
436 604 $query_args['meta_query'] = $meta;
437 605 }
438 - // Added by Ash/Upwork
439 - // 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() {
440 618 $charts = array();
441 - $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 = '';
442 640 while ( $query->have_posts() ) {
443 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 +
444 650 // fetch and update settings
445 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 +
446 658 unset( $settings['height'], $settings['width'] );
447 - $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
448 659 $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type );
449 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 +
450 671 // add chart to the array
451 - $charts[ 'visualizer-' . $chart->ID ] = array(
672 + $charts[ $id ] = array(
452 673 'id' => $chart->ID,
453 674 'type' => $type,
454 675 'series' => $series,
455 676 'settings' => $settings,
456 677 'data' => $data,
678 + 'library' => $library,
457 679 );
458 680 }
459 681 // enqueue charts array
460 682 $ajaxurl = admin_url( 'admin-ajax.php' );
461 683 wp_localize_script(
462 - 'visualizer-library', 'visualizer', array(
684 + 'visualizer-library',
685 + 'visualizer',
686 + array(
463 687 'language' => $this->get_language(),
464 688 'map_api_key' => get_option( 'visualizer-map-api-key' ),
465 689 'charts' => $charts,
466 690 'urls' => array(
@@ -468,17 +692,22 @@
468 692 'create' => add_query_arg(
469 693 array(
470 694 'action' => Visualizer_Plugin::ACTION_CREATE_CHART,
471 695 'library' => 'yes',
472 - ), $ajaxurl
696 + 'type' => isset( $_GET['type'] ) ? $_GET['type'] : '',
697 + ),
698 + $ajaxurl
473 699 ),
474 700 'edit' => add_query_arg(
475 701 array(
476 702 'action' => Visualizer_Plugin::ACTION_EDIT_CHART,
477 703 'library' => 'yes',
478 - ), $ajaxurl
704 + ),
705 + $ajaxurl
479 706 ),
480 707 ),
708 + 'page_type' => 'library',
709 + 'is_front' => false,
481 710 )
482 711 );
483 712 // render library page
484 713 $render = new Visualizer_Render_Library();
@@ -483,9 +712,10 @@
483 712 // render library page
484 713 $render = new Visualizer_Render_Library();
485 714 $render->charts = $charts;
486 715 $render->type = $filter;
487 - $render->types = self::_getChartTypesLocalized();
716 + $render->types = self::_getChartTypesLocalized( false, false, false, true );
717 + $render->custom_css = $css;
488 718 $render->pagination = paginate_links(
489 719 array(
490 720 'base' => add_query_arg( 'vpage', '%#%' ),
491 721 'format' => '',
@@ -509,9 +739,9 @@
509 739 *
510 740 * @return array Updated array of action links.
511 741 */
512 742 public function getPluginActionLinks( $links, $file ) {
513 - if ( $file == plugin_basename( VISUALIZER_BASEFILE ) ) {
743 + if ( $file === plugin_basename( VISUALIZER_BASEFILE ) ) {
514 744 array_unshift(
515 745 $links,
516 746 sprintf(
517 747 '<a href="%s">%s</a>',
@@ -536,9 +766,9 @@
536 766 *
537 767 * @return array Updated array of plugin meta links.
538 768 */
539 769 public function getPluginMetaLinks( $plugin_meta, $plugin_file ) {
540 - if ( $plugin_file == plugin_basename( VISUALIZER_BASEFILE ) ) {
770 + if ( $plugin_file === plugin_basename( VISUALIZER_BASEFILE ) ) {
541 771 // knowledge base link
542 772 $plugin_meta[] = sprintf(
543 773 '<a href="https://github.com/codeinwp/visualizer/wiki" target="_blank">%s</a>',
544 774 esc_html__( 'Knowledge Base', 'visualizer' )