Skip to content

Commit f819c97

Browse files
authored
Merge pull request #71 from sectsect/update-dependencies
build(deps): update composer dependencies to resolve security alert
2 parents b0d0e10 + 52fbf93 commit f819c97

14 files changed

Lines changed: 590 additions & 483 deletions

.github/workflows/phpunit.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ jobs:
1616
phpunit:
1717
runs-on: ubuntu-latest
1818

19+
services:
20+
mariadb:
21+
image: mariadb:lts
22+
env:
23+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
24+
ports:
25+
- 3306:3306
26+
options: >-
27+
--health-cmd="healthcheck.sh --connect --innodb_initialized"
28+
--health-interval=10s
29+
--health-timeout=5s
30+
--health-retries=3
31+
1932
strategy:
2033
fail-fast: false
2134
matrix:
@@ -35,9 +48,7 @@ jobs:
3548
uses: shivammathur/setup-php@v2
3649
with:
3750
php-version: ${{ matrix.php-versions }}
38-
39-
- name: Setup Database
40-
uses: getong/mariadb-action@v1.1
51+
coverage: none
4152

4253
- name: Check PHP Version
4354
run: php -v

.github/workflows/plugin-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ jobs:
1919
uses: wordpress/plugin-check-action@v1
2020
with:
2121
exclude-checks: 'trademarks,file_type,plugin_readme'
22-
exclude-directories: '.github,bin,vendor'
22+
exclude-directories: '.github,bin,vendor,tests'

admin/class-recursivetable.php

Lines changed: 69 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
declare(strict_types=1);
1616

17+
if ( ! defined( 'ABSPATH' ) ) {
18+
exit;
19+
}
20+
1721
/**
1822
* The core plugin class.
1923
*
@@ -63,15 +67,15 @@
6367
</th>
6468
<td>
6569
<?php
66-
$types = array(
70+
$google_ss2db_types = array(
6771
'json' => 'json_encode',
6872
'json-unescp' => 'json_encode (JSON_UNESCAPED_UNICODE)',
6973
);
7074
?>
7175
<select id="google_ss2db_dataformat" name="google_ss2db_dataformat" style="font-size: 11px; width: 330px;">
72-
<?php foreach ( $types as $key => $type ) : ?>
73-
<?php $selected = ( get_option( 'google_ss2db_dataformat' ) === $key ) ? 'selected' : ''; ?>
74-
<option value="<?php echo esc_attr( $key ); ?>" <?php echo esc_attr( $selected ); ?>><?php echo esc_html( $type ); ?></option>
76+
<?php foreach ( $google_ss2db_types as $google_ss2db_key => $type ) : ?>
77+
<?php $google_ss2db_selected = ( get_option( 'google_ss2db_dataformat' ) === $google_ss2db_key ) ? 'selected' : ''; ?>
78+
<option value="<?php echo esc_attr( $google_ss2db_key ); ?>" <?php echo esc_attr( $google_ss2db_selected ); ?>><?php echo esc_html( $type ); ?></option>
7579
<?php endforeach; ?>
7680
</select>
7781
</td>
@@ -157,25 +161,25 @@
157161
<p><?php echo esc_html__( 'This process may takes a few minutes.', 'google-spreadsheet-to-db' ); ?></p>
158162
<?php wp_nonce_field( 'google_ss2db', 'nonce' ); ?>
159163
<?php
160-
$text = esc_html__( 'Import from Google Spreadsheet', 'google-spreadsheet-to-db' );
161-
submit_button( $text, 'primary', 'save-spreadsheet', false );
164+
$google_ss2db_text = esc_html__( 'Import from Google Spreadsheet', 'google-spreadsheet-to-db' );
165+
submit_button( $google_ss2db_text, 'primary', 'save-spreadsheet', false );
162166
?>
163167
</form>
164168
</section>
165169
<?php
166170
global $wpdb;
167-
$table = GOOGLE_SS2DB_TABLE_NAME;
171+
$google_ss2db_table = GOOGLE_SS2DB_TABLE_NAME;
168172

169173
// Get sort parameters.
170-
$orderby = filter_input( INPUT_GET, 'orderby', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
171-
$order = filter_input( INPUT_GET, 'order', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
174+
$google_ss2db_orderby = filter_input( INPUT_GET, 'orderby', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
175+
$google_ss2db_order = filter_input( INPUT_GET, 'order', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
172176

173177
// Default sort settings.
174-
$default_orderby = 'date';
175-
$default_order = 'DESC';
178+
$google_ss2db_default_orderby = 'date';
179+
$google_ss2db_default_order = 'DESC';
176180

177181
// Allowed sort columns.
178-
$allowed_orderby = array(
182+
$google_ss2db_allowed_orderby = array(
179183
'id' => 'id',
180184
'worksheet_id' => 'worksheet_id',
181185
'worksheet_name' => 'worksheet_name',
@@ -185,44 +189,44 @@
185189
);
186190

187191
// Sort column validation.
188-
$order = $order ?? $default_order;
189-
$orderby = isset( $allowed_orderby[ $orderby ] ) ? $orderby : $default_orderby;
190-
$order = in_array( strtoupper( $order ), array( 'ASC', 'DESC' ), true ) ? strtoupper( $order ) : $default_order;
192+
$google_ss2db_order = $google_ss2db_order ?? $google_ss2db_default_order;
193+
$google_ss2db_orderby = isset( $google_ss2db_allowed_orderby[ $google_ss2db_orderby ] ) ? $google_ss2db_orderby : $google_ss2db_default_orderby;
194+
$google_ss2db_order = in_array( strtoupper( $google_ss2db_order ), array( 'ASC', 'DESC' ), true ) ? strtoupper( $google_ss2db_order ) : $google_ss2db_default_order;
191195

192-
$paged = filter_input( INPUT_GET, 'paged', FILTER_VALIDATE_INT );
193-
$nonce = filter_input( INPUT_GET, 'nonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
196+
$google_ss2db_paged = filter_input( INPUT_GET, 'paged', FILTER_VALIDATE_INT );
197+
$google_ss2db_nonce = filter_input( INPUT_GET, 'nonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
194198

195199
// Verify pagination nonce.
196-
if ( $paged && ! wp_verify_nonce( $nonce, 'google_ss2db_pagination' ) ) {
197-
$paged = 1;
200+
if ( $google_ss2db_paged && ! wp_verify_nonce( $google_ss2db_nonce, 'google_ss2db_pagination' ) ) {
201+
$google_ss2db_paged = 1;
198202
}
199203

200-
$paged = $paged ? $paged : 1;
201-
$limit = 24;
202-
$offset = ( $paged - 1 ) * $limit;
204+
$google_ss2db_paged = $google_ss2db_paged ? $google_ss2db_paged : 1;
205+
$google_ss2db_limit = 24;
206+
$google_ss2db_offset = ( $google_ss2db_paged - 1 ) * $google_ss2db_limit;
203207

204208
// SQL with sorting.
205-
$countsql = "SELECT * FROM {$table} ORDER BY {$orderby} {$order}";
206-
$allrows = count( $wpdb->get_results( $countsql ) ); // phpcs:ignore
207-
$max_num_pages = ceil( $allrows / $limit );
209+
$google_ss2db_countsql = "SELECT * FROM {$google_ss2db_table} ORDER BY {$google_ss2db_orderby} {$google_ss2db_order}";
210+
$google_ss2db_allrows = count( $wpdb->get_results( $google_ss2db_countsql ) ); // phpcs:ignore
211+
$google_ss2db_max_num_pages = ceil( $google_ss2db_allrows / $google_ss2db_limit );
208212

209-
$sql = "SELECT * FROM {$table} ORDER BY {$orderby} {$order} LIMIT %d OFFSET %d";
210-
$prepared = $wpdb->prepare(
211-
$sql, // phpcs:ignore
212-
$limit,
213-
$offset
213+
$google_ss2db_sql = "SELECT * FROM {$google_ss2db_table} ORDER BY {$google_ss2db_orderby} {$google_ss2db_order} LIMIT %d OFFSET %d";
214+
$google_ss2db_prepared = $wpdb->prepare(
215+
$google_ss2db_sql, // phpcs:ignore
216+
$google_ss2db_limit,
217+
$google_ss2db_offset
214218
);
215219

216-
$myrows = $wpdb->get_results( $prepared ); // phpcs:ignore
217-
$count = count( $myrows );
220+
$google_ss2db_myrows = $wpdb->get_results( $google_ss2db_prepared ); // phpcs:ignore
221+
$google_ss2db_count = count( $google_ss2db_myrows );
218222

219223
/**
220224
* Generate sort URLs for table columns.
221225
*
222226
* @param string $column The column to generate sort URL for.
223227
* @return string The generated sort URL.
224228
*/
225-
function get_sort_url( string $column ): string {
229+
function google_ss2db_get_sort_url( string $column ): string {
226230
$current_page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
227231
$current_orderby = filter_input( INPUT_GET, 'orderby', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
228232
$current_orderby = $current_orderby ? $current_orderby : 'date';
@@ -241,45 +245,45 @@ function get_sort_url( string $column ): string {
241245
return esc_url( add_query_arg( $url_params ) );
242246
}
243247

244-
if ( 0 < $count ) :
248+
if ( 0 < $google_ss2db_count ) :
245249
?>
246250
<section id="list">
247251
<hr />
248252
<table class="wp-list-table widefat fixed striped">
249253
<thead>
250254
<tr>
251-
<th scope="col" class="manage-column sortable <?php echo esc_attr( 'id' === $orderby ? 'sorted ' . strtolower( $order ) : '' ); ?>">
252-
<a href="<?php echo esc_url( get_sort_url( 'id' ) ); ?>">
255+
<th scope="col" class="manage-column sortable <?php echo esc_attr( 'id' === $google_ss2db_orderby ? 'sorted ' . strtolower( $google_ss2db_order ) : '' ); ?>">
256+
<a href="<?php echo esc_url( google_ss2db_get_sort_url( 'id' ) ); ?>">
253257
<span>ID</span>
254258
<span class="sorting-indicator"></span>
255259
</a>
256260
</th>
257-
<th scope="col" class="manage-column sortable <?php echo esc_attr( 'worksheet_id' === $orderby ? 'sorted ' . strtolower( $order ) : '' ); ?>">
258-
<a href="<?php echo esc_url( get_sort_url( 'worksheet_id' ) ); ?>">
261+
<th scope="col" class="manage-column sortable <?php echo esc_attr( 'worksheet_id' === $google_ss2db_orderby ? 'sorted ' . strtolower( $google_ss2db_order ) : '' ); ?>">
262+
<a href="<?php echo esc_url( google_ss2db_get_sort_url( 'worksheet_id' ) ); ?>">
259263
<span>Worksheet ID</span>
260264
<span class="sorting-indicator"></span>
261265
</a>
262266
</th>
263-
<th scope="col" class="manage-column sortable <?php echo esc_attr( 'worksheet_name' === $orderby ? 'sorted ' . strtolower( $order ) : '' ); ?>">
264-
<a href="<?php echo esc_url( get_sort_url( 'worksheet_name' ) ); ?>">
267+
<th scope="col" class="manage-column sortable <?php echo esc_attr( 'worksheet_name' === $google_ss2db_orderby ? 'sorted ' . strtolower( $google_ss2db_order ) : '' ); ?>">
268+
<a href="<?php echo esc_url( google_ss2db_get_sort_url( 'worksheet_name' ) ); ?>">
265269
<span>Worksheet Name</span>
266270
<span class="sorting-indicator"></span>
267271
</a>
268272
</th>
269-
<th scope="col" class="manage-column sortable <?php echo esc_attr( 'sheet_name' === $orderby ? 'sorted ' . strtolower( $order ) : '' ); ?>">
270-
<a href="<?php echo esc_url( get_sort_url( 'sheet_name' ) ); ?>">
273+
<th scope="col" class="manage-column sortable <?php echo esc_attr( 'sheet_name' === $google_ss2db_orderby ? 'sorted ' . strtolower( $google_ss2db_order ) : '' ); ?>">
274+
<a href="<?php echo esc_url( google_ss2db_get_sort_url( 'sheet_name' ) ); ?>">
271275
<span>Sheet Name</span>
272276
<span class="sorting-indicator"></span>
273277
</a>
274278
</th>
275-
<th scope="col" class="manage-column sortable <?php echo esc_attr( 'title' === $orderby ? 'sorted ' . strtolower( $order ) : '' ); ?>">
276-
<a href="<?php echo esc_url( get_sort_url( 'title' ) ); ?>">
279+
<th scope="col" class="manage-column sortable <?php echo esc_attr( 'title' === $google_ss2db_orderby ? 'sorted ' . strtolower( $google_ss2db_order ) : '' ); ?>">
280+
<a href="<?php echo esc_url( google_ss2db_get_sort_url( 'title' ) ); ?>">
277281
<span>Title</span>
278282
<span class="sorting-indicator"></span>
279283
</a>
280284
</th>
281-
<th scope="col" class="manage-column sortable <?php echo esc_attr( 'date' === $orderby ? 'sorted ' . strtolower( $order ) : '' ); ?>">
282-
<a href="<?php echo esc_url( get_sort_url( 'date' ) ); ?>">
285+
<th scope="col" class="manage-column sortable <?php echo esc_attr( 'date' === $google_ss2db_orderby ? 'sorted ' . strtolower( $google_ss2db_order ) : '' ); ?>">
286+
<a href="<?php echo esc_url( google_ss2db_get_sort_url( 'date' ) ); ?>">
283287
<span>Date</span>
284288
<span class="sorting-indicator"></span>
285289
</a>
@@ -288,31 +292,31 @@ function get_sort_url( string $column ): string {
288292
</tr>
289293
</thead>
290294
<tbody>
291-
<?php foreach ( $myrows as $row ) : ?>
292-
<tr data-id="<?php echo esc_attr( $row->id ); ?>">
293-
<td><?php echo esc_html( $row->id ); ?></td>
294-
<td><?php echo esc_html( google_ss2db_truncate_middle( $row->worksheet_id ?? '(no ID)' ) ); ?></td>
295-
<td><?php echo esc_html( $row->worksheet_name ); ?></td>
296-
<td><?php echo esc_html( $row->sheet_name ); ?></td>
297-
<td style="color: <?php echo $row->title ? 'inherit' : '#aaa'; ?>">
298-
<?php echo esc_html( $row->title ? $row->title : '(no title)' ); ?>
295+
<?php foreach ( $google_ss2db_myrows as $google_ss2db_row ) : ?>
296+
<tr data-id="<?php echo esc_attr( $google_ss2db_row->id ); ?>">
297+
<td><?php echo esc_html( $google_ss2db_row->id ); ?></td>
298+
<td><?php echo esc_html( google_ss2db_truncate_middle( $google_ss2db_row->worksheet_id ?? '(no ID)' ) ); ?></td>
299+
<td><?php echo esc_html( $google_ss2db_row->worksheet_name ); ?></td>
300+
<td><?php echo esc_html( $google_ss2db_row->sheet_name ); ?></td>
301+
<td style="color: <?php echo $google_ss2db_row->title ? 'inherit' : '#aaa'; ?>">
302+
<?php echo esc_html( $google_ss2db_row->title ? $google_ss2db_row->title : '(no title)' ); ?>
299303
</td>
300304
<td>
301305
<?php
302-
$date = new DateTime( $row->date );
303-
$date_format = is_string( get_option( 'date_format' ) ) ? get_option( 'date_format' ) : 'Y-m-d';
304-
$time_format = is_string( get_option( 'time_format' ) ) ? get_option( 'time_format' ) : 'H:i:s';
305-
echo esc_html( date_i18n( $date_format . ' ' . $time_format, $date->getTimestamp() ) );
306+
$google_ss2db_date = new DateTime( $google_ss2db_row->date );
307+
$google_ss2db_date_format = is_string( get_option( 'date_format' ) ) ? get_option( 'date_format' ) : 'Y-m-d';
308+
$google_ss2db_time_format = is_string( get_option( 'time_format' ) ) ? get_option( 'time_format' ) : 'H:i:s';
309+
echo esc_html( date_i18n( $google_ss2db_date_format . ' ' . $google_ss2db_time_format, $google_ss2db_date->getTimestamp() ) );
306310
?>
307311
</td>
308312
<td>
309-
<button class="button view-details" data-id="<?php echo esc_attr( $row->id ); ?>">
313+
<button class="button view-details" data-id="<?php echo esc_attr( $google_ss2db_row->id ); ?>">
310314
<?php echo esc_html__( 'Details', 'google-spreadsheet-to-db' ); ?>
311315
</button>
312-
<button class="button view-raw-data" data-id="<?php echo esc_attr( $row->id ); ?>">
316+
<button class="button view-raw-data" data-id="<?php echo esc_attr( $google_ss2db_row->id ); ?>">
313317
<?php echo esc_html__( 'Raw Data', 'google-spreadsheet-to-db' ); ?>
314318
</button>
315-
<button class="button delete-entry" data-id="<?php echo esc_attr( $row->id ); ?>">
319+
<button class="button delete-entry" data-id="<?php echo esc_attr( $google_ss2db_row->id ); ?>">
316320
<?php echo esc_html__( 'Delete', 'google-spreadsheet-to-db' ); ?>
317321
</button>
318322
</td>
@@ -322,13 +326,13 @@ function get_sort_url( string $column ): string {
322326
</table>
323327

324328
<?php
325-
$pagination_nonce = esc_attr( wp_create_nonce( 'google_ss2db_pagination' ) );
329+
$google_ss2db_pagination_nonce = esc_attr( wp_create_nonce( 'google_ss2db_pagination' ) );
326330
if ( function_exists( 'google_ss2db_options_pagination' ) ) {
327331
google_ss2db_options_pagination(
328-
$paged,
329-
(int) $max_num_pages,
332+
$google_ss2db_paged,
333+
(int) $google_ss2db_max_num_pages,
330334
2,
331-
$pagination_nonce
335+
$google_ss2db_pagination_nonce
332336
);
333337
}
334338
?>

bin/install-wp-tests.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ install_wp() {
9292
tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR
9393
fi
9494

95-
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
9695
}
9796

9897
install_test_suite() {

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
"allow-plugins": {
3636
"dealerdirect/phpcodesniffer-composer-installer": true,
3737
"phpstan/extension-installer": true
38+
},
39+
"platform": {
40+
"php": "8.1.0"
3841
}
3942
},
4043
"scripts": {

0 commit comments

Comments
 (0)