PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.1.3
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.1.3
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 +159 -6 3.0.83.1.3 View file →
@@ -252,26 +252,31 @@
252 252 * @param array $rows The array of data.
253 253 * @param string $filename The name of the file to use.
254 254 */
255 255 private function _getExcel( $rows, $filename ) {
256 - // PHPExcel does not like sheet names longer than 31 characters.
256 + // PHPExcel did not like sheet names longer than 31 characters and we will assume the same with PhpSpreadsheet
257 257 $chart = substr( $filename, 0, 30 );
258 258 $filename .= '.xlsx';
259 259
260 + $vendor_file = VISUALIZER_ABSPATH . '/vendor/autoload.php';
261 + if ( is_readable( $vendor_file ) ) {
262 + include_once( $vendor_file );
263 + }
264 +
260 265 $xlsData = '';
261 - if ( class_exists( 'PHPExcel' ) ) {
262 - $doc = new PHPExcel();
266 + if ( class_exists( 'PhpOffice\PhpSpreadsheet\Spreadsheet' ) ) {
267 + $doc = new PhpOffice\PhpSpreadsheet\Spreadsheet();
263 268 $doc->getActiveSheet()->fromArray( $rows, null, 'A1' );
264 269 $doc->getActiveSheet()->setTitle( sanitize_title( $chart ) );
265 270 $doc = apply_filters( 'visualizer_excel_doc', $doc );
266 - $writer = PHPExcel_IOFactory::createWriter( $doc, 'Excel2007' );
271 + $writer = PhpOffice\PhpSpreadsheet\IOFactory::createWriter( $doc, 'Xlsx' );
267 272 ob_start();
268 273 $writer->save( 'php://output' );
269 274 $xlsData = ob_get_contents();
270 275 ob_end_clean();
271 276 } else {
272 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'Class PHPExcel does not exist!', 'error', __FILE__, __LINE__ );
273 - error_log( 'Class PHPExcel does not exist!' );
277 + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'Class PhpOffice\PhpSpreadsheet\Spreadsheet does not exist!', 'error', __FILE__, __LINE__ );
278 + error_log( 'Class PhpOffice\PhpSpreadsheet\Spreadsheet does not exist!' );
274 279 }
275 280 return array(
276 281 'csv' => 'data:application/vnd.ms-excel;base64,' . base64_encode( $xlsData ),
277 282 'name' => $filename,
@@ -392,7 +397,155 @@
392 397 if ( count( $array ) < 2 ) {
393 398 return '';
394 399 }
395 400 return reset( $array );
401 + }
402 +
403 + /**
404 + * Gets/creates the JS where user-specific customizations can be/have been added.
405 + */
406 + protected function get_user_customization_js() {
407 + // use this as the JS file in case we are not able to create the file in uploads.
408 + $default = VISUALIZER_ABSURL . 'js/customization.js';
409 +
410 + $uploads = wp_get_upload_dir();
411 + $specific = $uploads['baseurl'] . '/visualizer/customization.js';
412 +
413 + // for testing on user sites (before we send them the correctly customized file).
414 + if ( VISUALIZER_TEST_JS_CUSTOMIZATION ) {
415 + return $default;
416 + }
417 +
418 + require_once( ABSPATH . 'wp-admin/includes/file.php' );
419 + WP_Filesystem();
420 + global $wp_filesystem;
421 +
422 + $dir = $wp_filesystem->wp_content_dir() . 'uploads/visualizer';
423 + $file = $wp_filesystem->wp_content_dir() . 'uploads/visualizer/customization.js';
424 +
425 + if ( $wp_filesystem->is_readable( $file ) ) {
426 + return $specific;
427 + }
428 +
429 + if ( $wp_filesystem->exists( $file ) && ! $wp_filesystem->is_readable( $file ) ) {
430 + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to read file %s', $file ), 'error', __FILE__, __LINE__ );
431 + return $default;
432 + }
433 +
434 + if ( ! $wp_filesystem->exists( $dir ) ) {
435 + if ( ( $done = $wp_filesystem->mkdir( $dir ) ) === false ) {
436 + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to create directory %s', $dir ), 'error', __FILE__, __LINE__ );
437 + return $default;
438 + }
439 + }
440 +
441 + // if file does not exist, copy.
442 + if ( ! $wp_filesystem->exists( $file ) ) {
443 + $src = str_replace( ABSPATH, $wp_filesystem->abspath(), VISUALIZER_ABSPATH . '/js/customization.js' );
444 + if ( ( $done = $wp_filesystem->copy( $src, $file ) ) === false ) {
445 + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to copy file %s to %s', $src, $file ), 'error', __FILE__, __LINE__ );
446 + return $default;
447 + }
448 + }
449 +
450 + return $specific;
451 + }
452 +
453 + /**
454 + * Load the class for the given chart's chart type so that its assets can be loaded.
455 + */
456 + protected function load_chart_type( $chart_id ) {
457 + $type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true );
458 + $name = 'Visualizer_Render_Sidebar_Type_' . ucwords( $type );
459 + $class = null;
460 + if ( class_exists( $name ) || true === apply_filters( 'visualizer_load_chart', false, $name ) ) {
461 + $class = new $name;
462 + }
463 +
464 + if ( is_null( $class ) && VISUALIZER_PRO ) {
465 + // lets see if this type exists in pro. New Lite(3.1.0+) & old Pro(1.8.0-).
466 + $class = apply_filters( 'visualizer_pro_chart_type_sidebar', null, array( 'type' => $type, 'settings' => get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true ) ) );
467 + }
468 +
469 + return is_null( $class ) ? null : $class->getLibrary();
470 + }
471 +
472 + /**
473 + * Generates the inline CSS to apply to the chart and adds these classes to the settings.
474 + *
475 + * @access public
476 + * @param int $id The id of the chart.
477 + * @param array $settings The settings of the chart.
478 + */
479 + protected function get_inline_custom_css( $id, $settings ) {
480 + $css = '';
481 +
482 + $arguments = array( '', $settings );
483 + if ( ! isset( $settings['customcss'] ) ) {
484 + return $arguments;
485 + }
486 +
487 + $classes = array();
488 + $css = '<style type="text/css" name="visualizer-custom-css" id="customcss-' . $id . '">';
489 + foreach ( $settings['customcss'] as $name => $element ) {
490 + $attributes = array();
491 + foreach ( $element as $property => $value ) {
492 + $attributes[] = $this->handle_css_property( $property, $value );
493 + }
494 + $class_name = $id . $name;
495 + $properties = implode( '; ', array_filter( $attributes ) );
496 + if ( ! empty( $properties ) ) {
497 + $css .= '.' . $class_name . ' {' . $properties . ' !important;}';
498 + $classes[ $name ] = $class_name;
499 + }
500 + }
501 + $css .= '</style>';
502 +
503 + $settings['cssClassNames'] = $classes;
504 +
505 + $arguments = array( $css, $settings );
506 + apply_filters_ref_array( 'visualizer_inline_css', array( &$arguments ) );
507 +
508 + return $arguments;
509 + }
510 +
511 + /**
512 + * Handles CSS properties that might need special syntax.
513 + *
514 + * @access private
515 + * @param string $property The name of the css property.
516 + * @param string $value The value of the css property.
517 + */
518 + private function handle_css_property( $property, $value ) {
519 + if ( empty( $property ) || empty( $value ) ) {
520 + return '';
521 + }
522 +
523 + switch ( $property ) {
524 + case 'transform':
525 + $value = 'rotate(' . $value . 'deg)';
526 + break;
527 + }
528 + return $property . ': ' . $value;
529 + }
530 +
531 + /**
532 + * Determines if charts have been created of the particular chart type.
533 + */
534 + protected static function hasChartType( $type ) {
535 + $args = array(
536 + 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
537 + 'fields' => 'ids',
538 + 'post_status' => 'publish',
539 + 'meta_query' => array(
540 + array(
541 + 'key' => Visualizer_Plugin::CF_CHART_TYPE,
542 + 'value' => $type,
543 + ),
544 + ),
545 + );
546 +
547 + $q = new WP_Query( $args );
548 + return $q->found_posts > 0;
396 549 }
397 550
398 551 }