PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 4.0.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v4.0.0
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.php +73 -59 3.11.154.0.0 View file →
@@ -67,10 +67,9 @@
67 67 $this->_addFilter( Visualizer_Plugin::FILTER_UNDO_REVISIONS, 'undoRevisions', 10, 2 );
68 68 $this->_addFilter( Visualizer_Plugin::FILTER_HANDLE_REVISIONS, 'handleExistingRevisions', 10, 2 );
69 69 $this->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_DATA_AS, 'getDataAs', 10, 3 );
70 70 $this->_addAction( 'pre_get_posts', 'PreGetPosts' );
71 - register_shutdown_function( array($this, 'onShutdown') );
72 -
71 + register_shutdown_function( array( $this, 'onShutdown' ) );
73 72 }
74 73
75 74 /**
76 75 * Register a shutdown hook to catch fatal errors.
@@ -113,18 +112,18 @@
113 112 * @access public
114 113 * @param string $tag The name of the AJAX action to which the $method is hooked.
115 114 * @param string $method Optional. The name of the method to be called. If the name of the method is not provided, tag name will be used as method name.
116 115 * @param bool $methodClass The root of the method.
117 - * @param boolean $private Optional. Determines if we should register hook for logged in users.
118 - * @param boolean $public Optional. Determines if we should register hook for not logged in users.
116 + * @param boolean $logged_in Optional. Determines if we should register hook for logged in users.
117 + * @param boolean $logged_out Optional. Determines if we should register hook for not logged in users.
119 118 * @return Visualizer_Module
120 119 */
121 - protected function _addAjaxAction( $tag, $method = '', $methodClass = null, $private = true, $public = false ) {
122 - if ( $private ) {
120 + protected function _addAjaxAction( $tag, $method = '', $methodClass = null, $logged_in = true, $logged_out = false ) {
121 + if ( $logged_in ) {
123 122 $this->_addAction( 'wp_ajax_' . $tag, $method, $methodClass );
124 123 }
125 124
126 - if ( $public ) {
125 + if ( $logged_out ) {
127 126 $this->_addAction( 'wp_ajax_nopriv_' . $tag, $method, $methodClass );
128 127 }
129 128
130 129 return $this;
@@ -168,9 +167,9 @@
168 167 * A wrapper around the actual function _getDataAs. This function is invoked as a filter.
169 168 *
170 169 * @since 3.2.0
171 170 */
172 - public function getDataAs( $final, $chart_id, $type ) {
171 + public function getDataAs( $data, $chart_id, $type ) {
173 172 return $this->_getDataAs( $chart_id, $type );
174 173 }
175 174
176 175 /**
@@ -269,14 +268,17 @@
269 268
270 269 $bom = chr( 0xEF ) . chr( 0xBB ) . chr( 0xBF );
271 270 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
272 271 $fp = function_exists( 'tmpfile' ) ? @tmpfile() : null;
273 - if ( null === $fp ) {
272 + if ( ! $fp ) {
274 273 if ( ! function_exists( 'wp_tempnam' ) ) {
275 274 require_once ABSPATH . 'wp-admin/includes/file.php';
276 275 }
277 276 $fp = fopen( wp_tempnam(), 'w+' );
278 277 }
278 + if ( ! $fp ) {
279 + return array( 'csv' => '', 'name' => $filename, 'string' => '' );
280 + }
279 281 if ( ! apply_filters( 'vizualizer_export_include_series_type', true ) ) {
280 282 unset( $rows[1] );
281 283 $rows = array_values( $rows );
282 284 }
@@ -286,10 +288,10 @@
286 288 fputcsv( $fp, $row );
287 289 }
288 290 rewind( $fp );
289 291 $csv = '';
290 - // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
291 - while ( ( $array = fgetcsv( $fp ) ) !== false ) {
292 + $array = fgetcsv( $fp );
293 + while ( $array !== false ) {
292 294 if ( strlen( $csv ) > 0 ) {
293 295 $csv .= PHP_EOL;
294 296 }
295 297 // if enclosure is required, check every item of this line
@@ -303,9 +305,10 @@
303 305 $temp_array[] = $item;
304 306 }
305 307 $array = $temp_array;
306 308 }
307 - $csv .= implode( ',', $array );
309 + $csv .= implode( ',', $array );
310 + $array = fgetcsv( $fp );
308 311 }
309 312 fclose( $fp );
310 313
311 314 return array(
@@ -329,9 +332,9 @@
329 332 if ( ! apply_filters( 'vizualizer_export_include_series_type', true ) ) {
330 333 unset( $rows[1] );
331 334 $rows = array_values( $rows );
332 335 $rows = array_map(
333 - function( $r ) {
336 + function ( $r ) {
334 337 return array_map( 'strval', $r );
335 338 },
336 339 $rows
337 340 );
@@ -401,9 +404,9 @@
401 404 $index = 0;
402 405 foreach ( $rows as $row ) {
403 406 // skip the data type row.
404 407 if ( 1 === $index ) {
405 - $index++;
408 + ++$index;
406 409 continue;
407 410 }
408 411
409 412 $table .= '<tr>';
@@ -414,9 +417,9 @@
414 417 $table .= '<td>' . $col . '</td>';
415 418 }
416 419 }
417 420 $table .= '</tr>';
418 - $index++;
421 + ++$index;
419 422 }
420 423 $table .= '</table>';
421 424
422 425 $html .= apply_filters( 'visualizer_print_table', $table ) . '
@@ -429,11 +432,11 @@
429 432
430 433 /**
431 434 * Disable revisions temporarily for visualizer post type.
432 435 */
433 - protected final function disableRevisionsTemporarily() {
436 + final protected function disableRevisionsTemporarily() {
434 437 add_filter(
435 - 'wp_revisions_to_keep', function( $num, $post ) {
438 + 'wp_revisions_to_keep', function ( $num, $post ) {
436 439 if ( $post->post_type === Visualizer_Plugin::CPT_VISUALIZER ) {
437 440 return 0;
438 441 }
439 442 return $num;
@@ -445,9 +448,9 @@
445 448 * Undo revisions for the chart, and if necessary, restore the earliest version.
446 449 *
447 450 * @return bool If any revisions were found.
448 451 */
449 - public final function undoRevisions( $chart_id, $restore = false ) {
452 + final public function undoRevisions( $chart_id, $restore = false ) {
450 453 do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'undoRevisions for %d with%s restore', $chart_id, ( $restore ? '' : 'out' ) ), 'debug', __FILE__, __LINE__ );
451 454 if ( get_post_type( $chart_id ) !== Visualizer_Plugin::CPT_VISUALIZER ) {
452 455 return false;
453 456 }
@@ -477,14 +480,19 @@
477 480
478 481 /**
479 482 * If existing revisions exist for the chart, restore the earliest version and then create a new revision to initiate editing.
480 483 */
481 - public final function handleExistingRevisions( $chart_id, $chart ) {
484 + final public function handleExistingRevisions( $chart_id, $chart ) {
482 485
483 486 do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'handleExistingRevisions for %d', $chart_id ), 'debug', __FILE__, __LINE__ );
484 487 if ( get_post_type( $chart_id ) !== Visualizer_Plugin::CPT_VISUALIZER ) {
485 488 return $chart_id;
486 489 }
490 + // AI Builder (D3) charts use their own publish flow — skip the classic revision-restore
491 + // mechanism, which would otherwise overwrite the saved title and settings.
492 + if ( 'd3' === get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, true ) ) {
493 + return $chart;
494 + }
487 495 // undo revisions.
488 496 $revisions_found = $this->undoRevisions( $chart_id, true );
489 497
490 498 // create revision for the edit action.
@@ -528,52 +536,55 @@
528 536 if ( VISUALIZER_TEST_JS_CUSTOMIZATION ) {
529 537 return $default;
530 538 }
531 539
532 - require_once( ABSPATH . 'wp-admin/includes/file.php' );
533 - WP_Filesystem();
534 - global $wp_filesystem;
535 - if ( ! is_a( $wp_filesystem, 'WP_Filesystem_Base' ) ) {
536 - $creds = request_filesystem_credentials( site_url() );
537 - wp_filesystem( $creds );
538 - }
540 + try {
541 + require_once ABSPATH . 'wp-admin/includes/file.php';
542 + WP_Filesystem();
543 + global $wp_filesystem;
544 + if ( ! is_a( $wp_filesystem, 'WP_Filesystem_Base' ) ) {
545 + return $default;
546 + }
539 547
540 - $multisite_arg = '/';
541 - if ( is_multisite() && ! is_main_site() ) {
542 - $multisite_arg = '/sites/' . get_current_blog_id() . '/';
543 - }
548 + $multisite_arg = '/';
549 + if ( is_multisite() && ! is_main_site() ) {
550 + $multisite_arg = '/sites/' . get_current_blog_id() . '/';
551 + }
544 552
545 - $dir = $wp_filesystem->wp_content_dir() . 'uploads' . $multisite_arg . 'visualizer';
546 - $file = $wp_filesystem->wp_content_dir() . 'uploads' . $multisite_arg . 'visualizer/customization.js';
553 + $dir = $wp_filesystem->wp_content_dir() . 'uploads' . $multisite_arg . 'visualizer';
554 + $file = $wp_filesystem->wp_content_dir() . 'uploads' . $multisite_arg . 'visualizer/customization.js';
547 555
548 - if ( $wp_filesystem->is_readable( $file ) ) {
549 - return $specific;
550 - }
556 + if ( $wp_filesystem->is_readable( $file ) ) {
557 + return $specific;
558 + }
551 559
552 - if ( $wp_filesystem->exists( $file ) && ! $wp_filesystem->is_readable( $file ) ) {
553 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to read file %s', $file ), 'error', __FILE__, __LINE__ );
554 - return $default;
555 - }
560 + if ( $wp_filesystem->exists( $file ) && ! $wp_filesystem->is_readable( $file ) ) {
561 + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to read file %s', $file ), 'error', __FILE__, __LINE__ );
562 + return $default;
563 + }
556 564
557 - if ( ! $wp_filesystem->exists( $dir ) ) {
558 - // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
559 - if ( ( $done = $wp_filesystem->mkdir( $dir ) ) === false ) {
560 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to create directory %s', $dir ), 'error', __FILE__, __LINE__ );
561 - return $default;
565 + if ( ! $wp_filesystem->exists( $dir ) ) {
566 + $done = $wp_filesystem->mkdir( $dir );
567 + if ( $done === false ) {
568 + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to create directory %s', $dir ), 'error', __FILE__, __LINE__ );
569 + return $default;
570 + }
562 571 }
563 - }
564 572
565 - // if file does not exist, copy.
566 - if ( ! $wp_filesystem->exists( $file ) ) {
567 - $src = str_replace( ABSPATH, $wp_filesystem->abspath(), VISUALIZER_ABSPATH . '/js/customization.js' );
568 - // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
569 - if ( ( $done = $wp_filesystem->copy( $src, $file ) ) === false ) {
570 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to copy file %s to %s', $src, $file ), 'error', __FILE__, __LINE__ );
571 - return $default;
573 + // if file does not exist, copy.
574 + if ( ! $wp_filesystem->exists( $file ) ) {
575 + $src = str_replace( ABSPATH, $wp_filesystem->abspath(), VISUALIZER_ABSPATH . '/js/customization.js' );
576 + $done = $wp_filesystem->copy( $src, $file );
577 + if ( $done === false ) {
578 + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to copy file %s to %s', $src, $file ), 'error', __FILE__, __LINE__ );
579 + return $default;
580 + }
572 581 }
582 +
583 + return $specific;
584 + } catch ( \Throwable $e ) {
585 + return $default;
573 586 }
574 -
575 - return $specific;
576 587 }
577 588
578 589 /**
579 590 * Load the class for the given chart's chart type so that its assets can be loaded.
@@ -578,15 +589,18 @@
578 589 /**
579 590 * Load the class for the given chart's chart type so that its assets can be loaded.
580 591 */
581 592 protected function load_chart_type( $chart_id ) {
593 + // D3/AI charts have no traditional type class — return the library string directly.
594 + $lib = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, true );
595 + if ( 'd3' === $lib ) {
596 + return 'd3';
597 + }
598 +
582 599 $name = $this->load_chart_class_name( $chart_id );
583 600 $class = null;
584 601 if ( class_exists( $name ) || true === apply_filters( 'visualizer_load_chart', false, $name ) ) {
585 - if ( 'Visualizer_Render_Sidebar_Type_DataTable_DataTable' === $name ) {
586 - $name = 'Visualizer_Render_Sidebar_Type_DataTable_Tabular';
587 - }
588 - $class = new $name;
602 + $class = new $name();
589 603 }
590 604
591 605 if ( is_null( $class ) && Visualizer_Module::is_pro() ) {
592 606 // lets see if this type exists in pro. New Lite(3.1.0+) & old Pro(1.8.0-).
@@ -745,9 +759,9 @@
745 759
746 760 /**
747 761 * Gets the features for the provided license type.
748 762 */
749 - public static final function get_features_for_license( $plan ) {
763 + final public static function get_features_for_license( $plan ) {
750 764 $is_new_personal = apply_filters( 'visualizer_is_new_personal', false );
751 765 switch ( $plan ) {
752 766 case 1:
753 767 $features = array( 'import-wp', 'import-wc-report', 'import-file', 'import-url' );