PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.11.7
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.11.7
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.php +39 -21 3.10.153.11.7 View file →
@@ -137,9 +137,9 @@
137 137 * @uses add_filter() To register filter hook.
138 138 *
139 139 * @access protected
140 140 * @param string $tag The name of the filter to hook the $method to.
141 - * @param type $method The name of the method to be called when the filter is applied.
141 + * @param string $method The name of the method to be called when the filter is applied.
142 142 * @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.
143 143 * @param int $accepted_args optional. The number of arguments the function accept (default 1).
144 144 * @return Visualizer_Module
145 145 */
@@ -234,9 +234,8 @@
234 234 $title = 'visualizer#' . $chart_id;
235 235 }
236 236
237 237 $filename = $title;
238 -
239 238 switch ( $type ) {
240 239 case 'csv':
241 240 $final = $this->_getCSV( $rows, $filename, false );
242 241 break;
@@ -323,11 +322,11 @@
323 322 * @param array $rows The array of data.
324 323 * @param string $filename The name of the file to use.
325 324 */
326 325 private function _getExcel( $rows, $filename ) {
327 - // PHPExcel did not like sheet names longer than 31 characters and we will assume the same with PhpSpreadsheet
328 - $chart = substr( $filename, 0, 30 );
329 - $filename .= '.xlsx';
326 + // OpenSpout allows for long sheet names, but let's keep the same limit for compatibility.
327 + $chart = substr( $filename, 0, 30 );
328 + $filename .= '.xlsx';
330 329 if ( ! apply_filters( 'vizualizer_export_include_series_type', true ) ) {
331 330 unset( $rows[1] );
332 331 $rows = array_values( $rows );
333 332 $rows = array_map(
@@ -338,24 +337,34 @@
338 337 );
339 338 }
340 339 $vendor_file = VISUALIZER_ABSPATH . '/vendor/autoload.php';
341 340 if ( is_readable( $vendor_file ) ) {
342 - include_once( $vendor_file );
341 + include_once $vendor_file;
343 342 }
344 - $xlsData = '';
345 - if ( class_exists( 'PhpOffice\PhpSpreadsheet\Spreadsheet' ) ) {
346 - $doc = new PhpOffice\PhpSpreadsheet\Spreadsheet();
347 - $doc->getActiveSheet()->fromArray( $rows, null, 'A1' );
348 - $doc->getActiveSheet()->setTitle( sanitize_title( $chart ) );
349 - $doc = apply_filters( 'visualizer_excel_doc', $doc );
350 - $writer = PhpOffice\PhpSpreadsheet\IOFactory::createWriter( $doc, 'Xlsx' );
351 - ob_start();
352 - $writer->save( 'php://output' );
353 - $xlsData = ob_get_contents();
354 - ob_end_clean();
343 + $xlsData = '';
344 + if ( class_exists( 'OpenSpout\Writer\Common\Creator\WriterEntityFactory' ) ) {
345 + try {
346 + // Use OpenSpout to create the XLSX file in memory.
347 + $writer = \OpenSpout\Writer\Common\Creator\WriterEntityFactory::createXLSXWriter();
348 + $writer->openToFile( 'php://output' ); // Open to output instead of a file.
349 + $writer->getCurrentSheet()->setName( sanitize_title( $chart ) );
350 +
351 + // Write rows.
352 + foreach ( $rows as $row ) {
353 + $rowFromValues = \OpenSpout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray( $row );
354 + $writer->addRow( $rowFromValues );
355 + }
356 +
357 + ob_start();
358 + $writer->close(); // Saves and closes the file in the output buffer.
359 + $xlsData = ob_get_clean();
360 + } catch ( Exception $e ) {
361 + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'OpenSpout writer error: ' . $e->getMessage(), 'error', __FILE__, __LINE__ );
362 + error_log( 'OpenSpout writer error: ' . $e->getMessage() );
363 + }
355 364 } else {
356 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'Class PhpOffice\PhpSpreadsheet\Spreadsheet does not exist!', 'error', __FILE__, __LINE__ );
357 - error_log( 'Class PhpOffice\PhpSpreadsheet\Spreadsheet does not exist!' );
365 + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'Class OpenSpout\Writer\Common\Creator\WriterEntityFactory does not exist!', 'error', __FILE__, __LINE__ );
366 + error_log( 'Class OpenSpout\Writer\Common\Creator\WriterEntityFactory does not exist!' );
358 367 }
359 368 return array(
360 369 'csv' => 'data:application/vnd.ms-excel;base64,' . base64_encode( $xlsData ),
361 370 'name' => $filename,
@@ -737,13 +746,22 @@
737 746 /**
738 747 * Gets the features for the provided license type.
739 748 */
740 749 public static final function get_features_for_license( $plan ) {
750 + $is_new_personal = apply_filters( 'visualizer_is_new_personal', false );
741 751 switch ( $plan ) {
742 752 case 1:
743 - return array( 'import-wp', 'db-query', 'import-wc-report' );
753 + $features = array( 'import-wp', 'import-wc-report', 'import-file', 'import-url' );
754 + if ( ! $is_new_personal ) {
755 + $features[] = 'db-query';
756 + }
757 + return $features;
744 758 case 2:
745 - return array( 'schedule-chart', 'chart-permissions', 'import-chart', 'manual-data', 'data-filter-configuration', 'frontend-actions' );
759 + $features = array( 'schedule-chart', 'chart-permissions', 'import-chart', 'data-filter-configuration', 'frontend-actions' );
760 + if ( $is_new_personal ) {
761 + $features[] = 'db-query';
762 + }
763 + return $features;
746 764 }
747 765 }
748 766
749 767 /**