Skip to content

Commit 81f0299

Browse files
release: fixes
- Updated dependencies - Enhanced security
2 parents b1c71ac + 8609f98 commit 81f0299

File tree

19 files changed

+6488
-13834
lines changed

19 files changed

+6488
-13834
lines changed

.distignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ artifact
1717
composer.json
1818
composer.lock
1919
package-lock.json
20-
vendor/phpoffice/phpspreadsheet/samples
21-
vendor/phpoffice/phpspreadsheet/docs
20+
vendor/openspout/openspout/LICENSE-for-*
21+
vendor/openspout/openspout/UPGRADE-3.0.md
22+
vendor/openspout/openspout/README.md
2223
cypress
2324
cypress.json
2425
.github

classes/Visualizer/Gutenberg/build/block.css

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

classes/Visualizer/Gutenberg/build/block.js

Lines changed: 1 addition & 259 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

classes/Visualizer/Gutenberg/build/handsontable.css

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

classes/Visualizer/Gutenberg/build/handsontable.js

Lines changed: 1 addition & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

classes/Visualizer/Gutenberg/package-lock.json

Lines changed: 6063 additions & 12678 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

classes/Visualizer/Gutenberg/package.json

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,34 @@
1515
"handsontable": "^5.0.2",
1616
"is-plain-object": "^2.0.4",
1717
"merge": "^1.2.1",
18-
"react": "16.4.1",
18+
"react": "18.3.1",
19+
"react-dom": "^18.3.1",
1920
"react-google-charts": "^3.0.8",
2021
"react-json-editor-ajrm": "^2.5.8",
2122
"sprintf-js": "^1.1.2",
22-
"uuid": "^3.3.3"
23+
"uuid": "^8.3.2"
2324
},
2425
"devDependencies": {
25-
"@babel/core": "^7.1.6",
26+
"@babel/core": "^7.21.0",
2627
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
2728
"@babel/plugin-transform-async-to-generator": "^7.1.0",
2829
"@babel/plugin-transform-react-jsx": "^7.1.6",
2930
"@babel/preset-env": "^7.1.6",
30-
"autoprefixer": "^9.3.1",
31-
"babel-loader": "^8.0.4",
32-
"cross-env": "3.2.4",
33-
"css-loader": "^1.0.1",
34-
"eslint": "^5.7.0",
31+
"autoprefixer": "^10.4.0",
32+
"babel-loader": "^9.1.0",
33+
"cross-env": "7.0.3",
34+
"css-loader": "^6.5.0",
35+
"eslint": "^6.0.0",
3536
"eslint-config-wordpress": "^2.0.0",
36-
"eslint-loader": "^2.1.1",
37-
"eslint-plugin-react": "^7.11.1",
38-
"file-loader": "^4.0.0",
39-
"mini-css-extract-plugin": "^0.4.4",
40-
"node-sass": "^4.10.0",
41-
"postcss-loader": "^3.0.0",
42-
"sass-loader": "^7.1.0",
43-
"webpack": "^4.25.1",
44-
"webpack-cli": "^3.1.2"
37+
"eslint-loader": "^4.0.0",
38+
"eslint-plugin-react": "^7.30.0",
39+
"file-loader": "^6.0.0",
40+
"mini-css-extract-plugin": "^2.4.5",
41+
"node-sass": "^7.0.0",
42+
"postcss-loader": "^6.2.1",
43+
"sass-loader": "^12.0.0",
44+
"webpack": "^5.74.0",
45+
"webpack-cli": "^4.10.0",
46+
"terser-webpack-plugin": "^5.3.10"
4547
}
4648
}

classes/Visualizer/Gutenberg/src/Components/DataTable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* External dependencies
33
*/
4-
import uuidv4 from 'uuid';
4+
import { v4 as uuidv4 } from 'uuid';
55

66
/**
77
* WordPress dependencies
Lines changed: 93 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,108 @@
1-
const webpack = require( 'webpack' );
1+
const webpack = require('webpack');
22
const NODE_ENV = process.env.NODE_ENV || 'development';
3-
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
3+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
4+
const TerserPlugin = require('terser-webpack-plugin');
45

56
module.exports = {
6-
externals: {
7+
externals: {
78
'lodash': 'lodash'
89
},
9-
mode: NODE_ENV,
10-
entry: './src/index.js',
11-
output: {
12-
path: __dirname,
13-
filename: './build/block.js',
14-
chunkFilename: './build/[name].js'
15-
},
16-
module: {
17-
rules: [
18-
{
19-
test: /.js?$/,
20-
use: [ {
21-
loader: 'babel-loader',
22-
options: {
23-
presets: [ '@babel/preset-env' ],
24-
plugins: [
25-
'@babel/plugin-transform-async-to-generator',
26-
'@babel/plugin-proposal-object-rest-spread',
27-
[
28-
'@babel/plugin-transform-react-jsx', {
29-
'pragma': 'wp.element.createElement'
30-
}
31-
]
32-
]
33-
}
34-
},
35-
'eslint-loader' ],
36-
exclude: /node_modules/
37-
},
38-
{
39-
test: /\.(css|scss)$/,
40-
use: [ {
41-
loader: MiniCssExtractPlugin.loader
42-
},
43-
'css-loader',
44-
{
45-
loader: 'postcss-loader',
46-
options: {
47-
plugins: [
48-
require( 'autoprefixer' )
49-
]
50-
}
51-
},
52-
{
53-
loader: 'sass-loader',
54-
query: {
55-
outputStyle:
56-
'production' === process.env.NODE_ENV ? 'compressed' : 'nested'
57-
}
58-
} ]
59-
},
60-
{
61-
test: /\.(png|jpe?g|gif)$/,
62-
use: [
63-
{
64-
loader: 'file-loader',
65-
options: {
66-
name: './[name].[ext]'
67-
}
68-
}
69-
]
70-
}
71-
]
72-
},
73-
optimization: {
10+
mode: NODE_ENV,
11+
entry: {
12+
block: './src/index.js'
13+
},
14+
output: {
15+
path: __dirname,
16+
filename: './build/[name].js'
17+
},
18+
module: {
19+
rules: [
20+
{
21+
test: /\.js$/,
22+
use: {
23+
loader: 'babel-loader',
24+
options: {
25+
presets: ['@babel/preset-env'],
26+
plugins: [
27+
'@babel/plugin-transform-async-to-generator',
28+
'@babel/plugin-proposal-object-rest-spread',
29+
[
30+
'@babel/plugin-transform-react-jsx', {
31+
'pragma': 'wp.element.createElement'
32+
}
33+
]
34+
]
35+
}
36+
},
37+
exclude: /node_modules/
38+
},
39+
{
40+
test: /\.(css|scss)$/,
41+
use: [
42+
{
43+
loader: MiniCssExtractPlugin.loader
44+
},
45+
'css-loader',
46+
{
47+
loader: 'postcss-loader',
48+
options: {
49+
postcssOptions: {
50+
plugins: [
51+
require('autoprefixer')
52+
]
53+
}
54+
}
55+
},
56+
{
57+
loader: 'sass-loader',
58+
options: {
59+
implementation: require('sass'),
60+
sassOptions: {
61+
outputStyle: NODE_ENV === 'production' ? 'compressed' : 'expanded'
62+
}
63+
}
64+
}
65+
]
66+
},
67+
{
68+
test: /\.(png|jpe?g|gif)$/,
69+
use: [
70+
{
71+
loader: 'file-loader',
72+
options: {
73+
name: './[name].[ext]'
74+
}
75+
}
76+
]
77+
}
78+
]
79+
},
80+
optimization: {
7481
splitChunks: {
7582
cacheGroups: {
7683
handsontable: {
7784
name: 'handsontable',
7885
test: /[\\/]node_modules[\\/]handsontable/,
79-
chunks: 'all'
86+
chunks: 'all',
87+
enforce: true
8088
}
8189
}
8290
}
8391
},
84-
plugins: [
85-
new webpack.DefinePlugin({
86-
'process.env.NODE_ENV': JSON.stringify( NODE_ENV )
87-
}),
88-
new MiniCssExtractPlugin({
89-
filename: './build/block.css',
90-
chunkFilename: './build/[name].css'
91-
})
92-
]
92+
plugins: [
93+
new webpack.DefinePlugin({
94+
'process.env.NODE_ENV': JSON.stringify(NODE_ENV)
95+
}),
96+
new MiniCssExtractPlugin({
97+
filename: './build/[name].css'
98+
}),
99+
new TerserPlugin({
100+
terserOptions: {
101+
format: {
102+
comments: false // Disable comments
103+
}
104+
},
105+
extractComments: false // Prevents LICENSE.txt generation
106+
})
107+
]
93108
};

classes/Visualizer/Module.php

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ public function _getDataAs( $chart_id, $type ) {
235235
}
236236

237237
$filename = $title;
238-
239238
switch ( $type ) {
240239
case 'csv':
241240
$final = $this->_getCSV( $rows, $filename, false );
@@ -324,9 +323,9 @@ private function _getCSV( $rows, $filename, $enclose ) {
324323
* @param string $filename The name of the file to use.
325324
*/
326325
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';
330329
if ( ! apply_filters( 'vizualizer_export_include_series_type', true ) ) {
331330
unset( $rows[1] );
332331
$rows = array_values( $rows );
@@ -339,22 +338,32 @@ function( $r ) {
339338
}
340339
$vendor_file = VISUALIZER_ABSPATH . '/vendor/autoload.php';
341340
if ( is_readable( $vendor_file ) ) {
342-
include_once( $vendor_file );
343-
}
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();
341+
include_once $vendor_file;
342+
}
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+
}
355364
} 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!' );
358367
}
359368
return array(
360369
'csv' => 'data:application/vnd.ms-excel;base64,' . base64_encode( $xlsData ),

0 commit comments

Comments
 (0)