PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.5.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.5.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 +101 -210 4.0.43.5.0 View file →
@@ -66,10 +66,10 @@
66 66
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 - $this->_addAction( 'pre_get_posts', 'PreGetPosts' );
71 - register_shutdown_function( array( $this, 'onShutdown' ) );
70 + register_shutdown_function( array($this, 'onShutdown') );
71 +
72 72 }
73 73
74 74 /**
75 75 * Register a shutdown hook to catch fatal errors.
@@ -112,18 +112,18 @@
112 112 * @access public
113 113 * @param string $tag The name of the AJAX action to which the $method is hooked.
114 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.
115 115 * @param bool $methodClass The root of the method.
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.
116 + * @param boolean $private Optional. Determines if we should register hook for logged in users.
117 + * @param boolean $public Optional. Determines if we should register hook for not logged in users.
118 118 * @return Visualizer_Module
119 119 */
120 - protected function _addAjaxAction( $tag, $method = '', $methodClass = null, $logged_in = true, $logged_out = false ) {
121 - if ( $logged_in ) {
120 + protected function _addAjaxAction( $tag, $method = '', $methodClass = null, $private = true, $public = false ) {
121 + if ( $private ) {
122 122 $this->_addAction( 'wp_ajax_' . $tag, $method, $methodClass );
123 123 }
124 124
125 - if ( $logged_out ) {
125 + if ( $public ) {
126 126 $this->_addAction( 'wp_ajax_nopriv_' . $tag, $method, $methodClass );
127 127 }
128 128
129 129 return $this;
@@ -136,9 +136,9 @@
136 136 * @uses add_filter() To register filter hook.
137 137 *
138 138 * @access protected
139 139 * @param string $tag The name of the filter to hook the $method to.
140 - * @param string $method The name of the method to be called when the filter is applied.
140 + * @param type $method The name of the method to be called when the filter is applied.
141 141 * @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
142 142 * @param int $accepted_args optional. The number of arguments the function accept (default 1).
143 143 * @return Visualizer_Module
144 144 */
@@ -167,9 +167,9 @@
167 167 * A wrapper around the actual function _getDataAs. This function is invoked as a filter.
168 168 *
169 169 * @since 3.2.0
170 170 */
171 - public function getDataAs( $data, $chart_id, $type ) {
171 + public function getDataAs( $final, $chart_id, $type ) {
172 172 return $this->_getDataAs( $chart_id, $type );
173 173 }
174 174
175 175 /**
@@ -233,8 +233,9 @@
233 233 $title = 'visualizer#' . $chart_id;
234 234 }
235 235
236 236 $filename = $title;
237 +
237 238 switch ( $type ) {
238 239 case 'csv':
239 240 $final = $this->_getCSV( $rows, $filename, false );
240 241 break;
@@ -246,11 +247,8 @@
246 247 break;
247 248 case 'print':
248 249 $final = $this->_getHTML( $rows );
249 250 break;
250 - case 'image':
251 - $final = $this->_getImage( $chart );
252 - break;
253 251 }
254 252 }
255 253 return $final;
256 254 }
@@ -266,19 +264,9 @@
266 264 private function _getCSV( $rows, $filename, $enclose ) {
267 265 $filename .= '.csv';
268 266
269 267 $bom = chr( 0xEF ) . chr( 0xBB ) . chr( 0xBF );
270 - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
271 - $fp = function_exists( 'tmpfile' ) ? @tmpfile() : null;
272 - if ( ! $fp ) {
273 - if ( ! function_exists( 'wp_tempnam' ) ) {
274 - require_once ABSPATH . 'wp-admin/includes/file.php';
275 - }
276 - $fp = fopen( wp_tempnam(), 'w+' );
277 - }
278 - if ( ! $fp ) {
279 - return array( 'csv' => '', 'name' => $filename, 'string' => '' );
280 - }
268 + $fp = tmpfile();
281 269 if ( ! apply_filters( 'vizualizer_export_include_series_type', true ) ) {
282 270 unset( $rows[1] );
283 271 $rows = array_values( $rows );
284 272 }
@@ -288,10 +276,10 @@
288 276 fputcsv( $fp, $row );
289 277 }
290 278 rewind( $fp );
291 279 $csv = '';
292 - $array = fgetcsv( $fp );
293 - while ( $array !== false ) {
280 + // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
281 + while ( ( $array = fgetcsv( $fp ) ) !== false ) {
294 282 if ( strlen( $csv ) > 0 ) {
295 283 $csv .= PHP_EOL;
296 284 }
297 285 // if enclosure is required, check every item of this line
@@ -305,10 +293,9 @@
305 293 $temp_array[] = $item;
306 294 }
307 295 $array = $temp_array;
308 296 }
309 - $csv .= implode( ',', $array );
310 - $array = fgetcsv( $fp );
297 + $csv .= implode( ',', $array );
311 298 }
312 299 fclose( $fp );
313 300
314 301 return array(
@@ -325,16 +312,16 @@
325 312 * @param array $rows The array of data.
326 313 * @param string $filename The name of the file to use.
327 314 */
328 315 private function _getExcel( $rows, $filename ) {
329 - // OpenSpout allows for long sheet names, but let's keep the same limit for compatibility.
330 - $chart = substr( $filename, 0, 30 );
331 - $filename .= '.xlsx';
316 + // PHPExcel did not like sheet names longer than 31 characters and we will assume the same with PhpSpreadsheet
317 + $chart = substr( $filename, 0, 30 );
318 + $filename .= '.xlsx';
332 319 if ( ! apply_filters( 'vizualizer_export_include_series_type', true ) ) {
333 320 unset( $rows[1] );
334 321 $rows = array_values( $rows );
335 322 $rows = array_map(
336 - function ( $r ) {
323 + function( $r ) {
337 324 return array_map( 'strval', $r );
338 325 },
339 326 $rows
340 327 );
@@ -340,34 +327,24 @@
340 327 );
341 328 }
342 329 $vendor_file = VISUALIZER_ABSPATH . '/vendor/autoload.php';
343 330 if ( is_readable( $vendor_file ) ) {
344 - include_once $vendor_file;
331 + include_once( $vendor_file );
345 332 }
346 - $xlsData = '';
347 - if ( class_exists( 'OpenSpout\Writer\Common\Creator\WriterEntityFactory' ) ) {
348 - try {
349 - // Use OpenSpout to create the XLSX file in memory.
350 - $writer = \OpenSpout\Writer\Common\Creator\WriterEntityFactory::createXLSXWriter();
351 - $writer->openToFile( 'php://output' ); // Open to output instead of a file.
352 - $writer->getCurrentSheet()->setName( sanitize_title( $chart ) );
353 -
354 - // Write rows.
355 - foreach ( $rows as $row ) {
356 - $rowFromValues = \OpenSpout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray( $row );
357 - $writer->addRow( $rowFromValues );
358 - }
359 -
360 - ob_start();
361 - $writer->close(); // Saves and closes the file in the output buffer.
362 - $xlsData = ob_get_clean();
363 - } catch ( Exception $e ) {
364 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'OpenSpout writer error: ' . $e->getMessage(), 'error', __FILE__, __LINE__ );
365 - error_log( 'OpenSpout writer error: ' . $e->getMessage() );
366 - }
333 + $xlsData = '';
334 + if ( class_exists( 'PhpOffice\PhpSpreadsheet\Spreadsheet' ) ) {
335 + $doc = new PhpOffice\PhpSpreadsheet\Spreadsheet();
336 + $doc->getActiveSheet()->fromArray( $rows, null, 'A1' );
337 + $doc->getActiveSheet()->setTitle( sanitize_title( $chart ) );
338 + $doc = apply_filters( 'visualizer_excel_doc', $doc );
339 + $writer = PhpOffice\PhpSpreadsheet\IOFactory::createWriter( $doc, 'Xlsx' );
340 + ob_start();
341 + $writer->save( 'php://output' );
342 + $xlsData = ob_get_contents();
343 + ob_end_clean();
367 344 } else {
368 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'Class OpenSpout\Writer\Common\Creator\WriterEntityFactory does not exist!', 'error', __FILE__, __LINE__ );
369 - error_log( 'Class OpenSpout\Writer\Common\Creator\WriterEntityFactory does not exist!' );
345 + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'Class PhpOffice\PhpSpreadsheet\Spreadsheet does not exist!', 'error', __FILE__, __LINE__ );
346 + error_log( 'Class PhpOffice\PhpSpreadsheet\Spreadsheet does not exist!' );
370 347 }
371 348 return array(
372 349 'csv' => 'data:application/vnd.ms-excel;base64,' . base64_encode( $xlsData ),
373 350 'name' => $filename,
@@ -404,9 +381,9 @@
404 381 $index = 0;
405 382 foreach ( $rows as $row ) {
406 383 // skip the data type row.
407 384 if ( 1 === $index ) {
408 - ++$index;
385 + $index++;
409 386 continue;
410 387 }
411 388
412 389 $table .= '<tr>';
@@ -417,9 +394,9 @@
417 394 $table .= '<td>' . $col . '</td>';
418 395 }
419 396 }
420 397 $table .= '</tr>';
421 - ++$index;
398 + $index++;
422 399 }
423 400 $table .= '</table>';
424 401
425 402 $html .= apply_filters( 'visualizer_print_table', $table ) . '
@@ -432,11 +409,11 @@
432 409
433 410 /**
434 411 * Disable revisions temporarily for visualizer post type.
435 412 */
436 - final protected function disableRevisionsTemporarily() {
413 + protected final function disableRevisionsTemporarily() {
437 414 add_filter(
438 - 'wp_revisions_to_keep', function ( $num, $post ) {
415 + 'wp_revisions_to_keep', function( $num, $post ) {
439 416 if ( $post->post_type === Visualizer_Plugin::CPT_VISUALIZER ) {
440 417 return 0;
441 418 }
442 419 return $num;
@@ -448,9 +425,9 @@
448 425 * Undo revisions for the chart, and if necessary, restore the earliest version.
449 426 *
450 427 * @return bool If any revisions were found.
451 428 */
452 - final public function undoRevisions( $chart_id, $restore = false ) {
429 + public final function undoRevisions( $chart_id, $restore = false ) {
453 430 do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'undoRevisions for %d with%s restore', $chart_id, ( $restore ? '' : 'out' ) ), 'debug', __FILE__, __LINE__ );
454 431 if ( get_post_type( $chart_id ) !== Visualizer_Plugin::CPT_VISUALIZER ) {
455 432 return false;
456 433 }
@@ -480,19 +457,14 @@
480 457
481 458 /**
482 459 * If existing revisions exist for the chart, restore the earliest version and then create a new revision to initiate editing.
483 460 */
484 - final public function handleExistingRevisions( $chart_id, $chart ) {
461 + public final function handleExistingRevisions( $chart_id, $chart ) {
485 462
486 463 do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'handleExistingRevisions for %d', $chart_id ), 'debug', __FILE__, __LINE__ );
487 464 if ( get_post_type( $chart_id ) !== Visualizer_Plugin::CPT_VISUALIZER ) {
488 465 return $chart_id;
489 466 }
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 - }
495 467 // undo revisions.
496 468 $revisions_found = $this->undoRevisions( $chart_id, true );
497 469
498 470 // create revision for the edit action.
@@ -536,55 +508,48 @@
536 508 if ( VISUALIZER_TEST_JS_CUSTOMIZATION ) {
537 509 return $default;
538 510 }
539 511
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 - }
512 + require_once( ABSPATH . 'wp-admin/includes/file.php' );
513 + WP_Filesystem();
514 + global $wp_filesystem;
547 515
548 - $multisite_arg = '/';
549 - if ( is_multisite() && ! is_main_site() ) {
550 - $multisite_arg = '/sites/' . get_current_blog_id() . '/';
551 - }
516 + $multisite_arg = '/';
517 + if ( is_multisite() && ! is_main_site() ) {
518 + $multisite_arg = '/sites/' . get_current_blog_id() . '/';
519 + }
552 520
553 - $dir = $wp_filesystem->wp_content_dir() . 'uploads' . $multisite_arg . 'visualizer';
554 - $file = $wp_filesystem->wp_content_dir() . 'uploads' . $multisite_arg . 'visualizer/customization.js';
521 + $dir = $wp_filesystem->wp_content_dir() . 'uploads' . $multisite_arg . 'visualizer';
522 + $file = $wp_filesystem->wp_content_dir() . 'uploads' . $multisite_arg . 'visualizer/customization.js';
555 523
556 - if ( $wp_filesystem->is_readable( $file ) ) {
557 - return $specific;
558 - }
524 + if ( $wp_filesystem->is_readable( $file ) ) {
525 + return $specific;
526 + }
559 527
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__ );
528 + if ( $wp_filesystem->exists( $file ) && ! $wp_filesystem->is_readable( $file ) ) {
529 + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to read file %s', $file ), 'error', __FILE__, __LINE__ );
530 + return $default;
531 + }
532 +
533 + if ( ! $wp_filesystem->exists( $dir ) ) {
534 + // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
535 + if ( ( $done = $wp_filesystem->mkdir( $dir ) ) === false ) {
536 + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to create directory %s', $dir ), 'error', __FILE__, __LINE__ );
562 537 return $default;
563 538 }
539 + }
564 540
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 - }
541 + // if file does not exist, copy.
542 + if ( ! $wp_filesystem->exists( $file ) ) {
543 + $src = str_replace( ABSPATH, $wp_filesystem->abspath(), VISUALIZER_ABSPATH . '/js/customization.js' );
544 + // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
545 + if ( ( $done = $wp_filesystem->copy( $src, $file ) ) === false ) {
546 + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to copy file %s to %s', $src, $file ), 'error', __FILE__, __LINE__ );
547 + return $default;
571 548 }
549 + }
572 550
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 - }
581 - }
582 -
583 - return $specific;
584 - } catch ( \Throwable $e ) {
585 - return $default;
586 - }
551 + return $specific;
587 552 }
588 553
589 554 /**
590 555 * Load the class for the given chart's chart type so that its assets can be loaded.
@@ -589,18 +554,15 @@
589 554 /**
590 555 * Load the class for the given chart's chart type so that its assets can be loaded.
591 556 */
592 557 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 -
599 558 $name = $this->load_chart_class_name( $chart_id );
600 559 $class = null;
601 560 if ( class_exists( $name ) || true === apply_filters( 'visualizer_load_chart', false, $name ) ) {
602 - $class = new $name();
561 + if ( 'Visualizer_Render_Sidebar_Type_DataTable_DataTable' === $name ) {
562 + $name = 'Visualizer_Render_Sidebar_Type_DataTable_Tabular';
563 + }
564 + $class = new $name;
603 565 }
604 566
605 567 if ( is_null( $class ) && Visualizer_Module::is_pro() ) {
606 568 // lets see if this type exists in pro. New Lite(3.1.0+) & old Pro(1.8.0-).
@@ -638,31 +600,32 @@
638 600 */
639 601 protected function get_inline_custom_css( $id, $settings ) {
640 602 $css = '';
641 603
604 + $arguments = array( '', $settings );
605 + if ( ! isset( $settings['customcss'] ) ) {
606 + return $arguments;
607 + }
608 +
642 609 $classes = array();
643 610 $css = '<style type="text/css" name="visualizer-custom-css" id="customcss-' . $id . '">';
644 - if ( ! empty( $settings['customcss'] ) ) {
645 - foreach ( $settings['customcss'] as $name => $element ) {
646 - $attributes = array();
647 - foreach ( $element as $property => $value ) {
648 - $attributes[] = $this->handle_css_property( $property, $value );
649 - }
650 - $class_name = $id . $name;
651 - $properties = implode( ' !important; ', array_filter( $attributes ) );
652 - if ( ! empty( $properties ) ) {
653 - $css .= '.' . $class_name . ' {' . $properties . ' !important;}';
654 - $classes[ $name ] = $class_name;
655 - }
611 + foreach ( $settings['customcss'] as $name => $element ) {
612 + $attributes = array();
613 + foreach ( $element as $property => $value ) {
614 + $attributes[] = $this->handle_css_property( $property, $value );
656 615 }
657 - $settings['cssClassNames'] = $classes;
616 + $class_name = $id . $name;
617 + $properties = implode( ' !important; ', array_filter( $attributes ) );
618 + if ( ! empty( $properties ) ) {
619 + $css .= '.' . $class_name . ' {' . $properties . ' !important;}';
620 + $classes[ $name ] = $class_name;
621 + }
658 622 }
623 + $css .= '</style>';
659 624
660 - $img_path = VISUALIZER_ABSURL . 'images';
661 - $css .= ".locker,.locker-loader{position:absolute;top:0;left:0;width:100%;height:100%}.locker{z-index:1000;opacity:.8;background-color:#fff;-ms-filter:\"progid:DXImageTransform.Microsoft.Alpha(Opacity=80)\";filter:alpha(opacity=80)}.locker-loader{z-index:1001;background:url($img_path/ajax-loader.gif) no-repeat center center}.dt-button{display:none!important}.visualizer-front-container.visualizer-lazy-render{content-visibility: auto;}.google-visualization-controls-categoryfilter label.google-visualization-controls-label {vertical-align: middle;}.google-visualization-controls-categoryfilter li.goog-inline-block {margin: 0 0.2em;}.google-visualization-controls-categoryfilter li {padding: 0 0.2em;}.visualizer-front-container .dataTables_scrollHeadInner{margin: 0 auto;}";
662 - $css .= '</style>';
625 + $settings['cssClassNames'] = $classes;
663 626
664 - $arguments = array( $css, $settings );
627 + $arguments = array( $css, $settings );
665 628 apply_filters_ref_array( 'visualizer_inline_css', array( &$arguments ) );
666 629
667 630 return $arguments;
668 631 }
@@ -759,23 +722,14 @@
759 722
760 723 /**
761 724 * Gets the features for the provided license type.
762 725 */
763 - final public static function get_features_for_license( $plan ) {
764 - $is_new_personal = apply_filters( 'visualizer_is_new_personal', false );
726 + public static final function get_features_for_license( $plan ) {
765 727 switch ( $plan ) {
766 728 case 1:
767 - $features = array( 'import-wp', 'import-wc-report', 'import-file', 'import-url' );
768 - if ( ! $is_new_personal ) {
769 - $features[] = 'db-query';
770 - }
771 - return $features;
729 + return array( 'import-wp', 'db-query' );
772 730 case 2:
773 - $features = array( 'schedule-chart', 'chart-permissions', 'import-chart', 'data-filter-configuration', 'frontend-actions' );
774 - if ( $is_new_personal ) {
775 - $features[] = 'db-query';
776 - }
777 - return $features;
731 + return array( 'schedule-chart', 'chart-permissions' );
778 732 }
779 733 }
780 734
781 735 /**
@@ -782,30 +736,18 @@
782 736 * Gets the chart content after common manipulations.
783 737 */
784 738 public static function get_chart_data( $chart, $type, $run_filter = true ) {
785 739 // change HTML entities
786 - $post_content = html_entity_decode( htmlentities( $chart->post_content ) );
787 - $post_content = preg_replace_callback(
788 - '!s:(\d+):"(.*?)";!s',
789 - function ( $matches ) {
790 - if ( isset( $matches[2] ) ) {
791 - return 's:' . strlen( $matches[2] ) . ':"' . $matches[2] . '";';
792 - }
793 - },
794 - $post_content
795 - );
796 - $data = unserialize( $post_content );
740 + $data = unserialize( html_entity_decode( $chart->post_content ) );
797 741 $altered = array();
798 - if ( ! empty( $data ) ) {
799 - foreach ( $data as $index => $array ) {
800 - if ( ! is_array( $index ) && is_array( $array ) ) {
801 - foreach ( $array as &$datum ) {
802 - if ( is_string( $datum ) ) {
803 - $datum = stripslashes( $datum );
804 - }
742 + foreach ( $data as $index => $array ) {
743 + if ( ! is_array( $index ) && is_array( $array ) ) {
744 + foreach ( $array as &$datum ) {
745 + if ( is_string( $datum ) ) {
746 + $datum = stripslashes( $datum );
805 747 }
806 - $altered[ $index ] = $array;
807 748 }
749 + $altered[ $index ] = $array;
808 750 }
809 751 }
810 752 // if something goes wrong and the end result is empty, be safe and use the original data
811 753 if ( empty( $altered ) ) {
@@ -814,57 +756,6 @@
814 756 if ( $run_filter ) {
815 757 return apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, $altered, $chart->ID, $type );
816 758 }
817 759 return $altered;
818 - }
819 -
820 - /**
821 - * Get chart image.
822 - *
823 - * @param object $chart Chart data.
824 - * @return string
825 - */
826 - public function _getImage( $chart = null ) {
827 - $image = '';
828 - if ( $chart ) {
829 - $chart_image = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_IMAGE, true );
830 - if ( ! empty( $chart_image ) ) {
831 - $image = wp_get_attachment_image( $chart_image, 'full' );
832 - }
833 - }
834 - return array(
835 - 'csv' => $image,
836 - );
837 - }
838 -
839 - /**
840 - * Filter chart title if visualizer post type.
841 - *
842 - * @param object $query WP Query object.
843 - * @return void
844 - */
845 - public function PreGetPosts( $query ) {
846 - if ( ! $query->is_main_query() ) {
847 - $post_type = $query->get( 'post_type' );
848 - if ( 'visualizer' === $post_type ) {
849 - $this->_addFilter( Visualizer_Plugin::FILTER_CHART_TITLE, 'filterChartTitle', 10, 2 );
850 - }
851 - }
852 - }
853 -
854 - /**
855 - * Filter chart title.
856 - *
857 - * @access public
858 - * @param string $post_title Post title.
859 - * @param int $post_id Post ID.
860 - * @return string
861 - */
862 - public function filterChartTitle( $post_title, $post_id ) {
863 - $post_type = get_post_type( $post_id );
864 - $post_title = trim( $post_title );
865 - if ( 'visualizer' === $post_type && 'Visualization' === $post_title ) {
866 - return sprintf( '%s #%d', $post_title, $post_id );
867 - }
868 - return $post_title;
869 760 }
870 761 }