diff --git a/README.md b/README.md index b22209a..22c118e 100644 --- a/README.md +++ b/README.md @@ -27,12 +27,10 @@ Some parts of the UI are React and can be built with: `yarn build` -To use in development mode then set `SEARCHREGEX_DEV_MODE` to true in PHP, and run: +To use in development mode run: `yarn start` -This will start Webpack in hot-reload mode, and you can make changes to JS files and have them auto-loaded. - ### Releasing Finally, to produce a release copy: diff --git a/includes/api/class-route.php b/includes/api/class-route.php index 62922a8..a54c14a 100644 --- a/includes/api/class-route.php +++ b/includes/api/class-route.php @@ -67,8 +67,7 @@ * @apiSuccess {Object[]} totals The totals for this search * @apiSuccess {Integer} totals.current The current search offset * @apiSuccess {Integer} totals.rows The total number of rows for the source, including non-matches - * @apiSuccess {Integer} totals.matched_rows The number of matched rows if known, or `-1` if a regular expression match and unknown - * @apiSuccess {Integer} totals.matched_phrases The number of matched phraes if known, or `-1` if a regular expression match and unknown + * @apiSuccess {Integer} totals.matched_rows The number of matched rows if known, or 0 if a regular expression match and unknown * @apiSuccess {Object[]} progress The current search progress, and the previous and next set of results * @apiSuccess {Integer} progress.current The current search offset * @apiSuccess {Integer} progress.rows The number of rows contained within this result set diff --git a/includes/search/class-search.php b/includes/search/class-search.php index 86286af..a05cddd 100644 --- a/includes/search/class-search.php +++ b/includes/search/class-search.php @@ -88,22 +88,13 @@ public function get_search_results( Action\Action $action, $offset, $per_page, $ // Calculate the prev/next pages of results $previous = max( 0, $offset - $per_page ); - $next = $totals->get_next_page( $offset + $per_page ); - - // We always go in $per_page groups, but we need to limit if we only need a few more to fill a result set - if ( $limit > 0 && $limit < count( $results ) ) { - $next = min( $offset + $limit, $next ); - $results = array_slice( $results, 0, $limit ); - } - - if ( $next === $offset ) { - $next = false; - } if ( $previous === $offset ) { $previous = false; } + list( $next, $results ) = $this->get_next_results( $totals, $offset, $per_page, $limit, $results ); + return [ 'results' => $action->should_save() ? [] : $results, 'totals' => $totals->to_json(), @@ -116,6 +107,54 @@ public function get_search_results( Action\Action $action, $offset, $per_page, $ ]; } + /** + * Get the results and next position. For advanced searches this may be a smaller set if we have a limit value + * + * @param Totals $totals Totals. + * @param int $offset Current page offset. + * @param int $per_page Per page limit. + * @param int $limit Max number of results. + * @param Array $results Result array. + * @return Array + */ + private function get_next_results( $totals, $offset, $per_page, $limit, $results ) { + $next = $totals->get_next_page( $offset + $per_page ); + + // We always go in $per_page groups, but we need to limit if we only need a few more to fill a result set + if ( $limit > 0 && $limit < count( $results ) ) { + $new_results = []; + $new_offset = $offset; + + foreach ( $results as $result ) { + if ( $result ) { + $new_results[] = $result; + } + + $new_offset++; + + if ( count( $new_results ) === $limit ) { + break; + } + } + + $results = $new_results; + $next = min( $new_offset, $next ); + } else { + $results = array_filter( $results, function( $item ) { + return $item !== false; + } ); + } + + if ( $next === $offset ) { + $next = false; + } + + return [ + $next, + $results, + ]; + } + /** * Get totals for source * @@ -213,9 +252,9 @@ public function convert_rows_to_results( array $source_results, Action\Action $a return $saved; } } - - $results[] = $result; } + + $results[] = $result; } } diff --git a/includes/sql/select/class-select.php b/includes/sql/select/class-select.php index 9aac9c6..b431614 100644 --- a/includes/sql/select/class-select.php +++ b/includes/sql/select/class-select.php @@ -5,7 +5,6 @@ use SearchRegex\Sql; require_once __DIR__ . '/class-column.php'; -require_once __DIR__ . '/class-sum.php'; /** * SQL SELECT diff --git a/includes/sql/select/class-sum.php b/includes/sql/select/class-sum.php deleted file mode 100644 index 4a0da28..0000000 --- a/includes/sql/select/class-sum.php +++ /dev/null @@ -1,74 +0,0 @@ -values = [ - [ - 'column' => $column->get_column(), - 'value' => $alias->get_value(), - ], - ]; - } - } - - public function get_as_sql() { - return ''; - } - - /** - * Add - * - * @param Select_Phrases $phrase Phrase. - * @return void - */ - public function add_sum( Select_Phrases $phrase ) { - $this->values = array_merge( $this->values, $phrase->values ); - } - - /** - * Get SELECT - * - * @return string - */ - public function get_select_sql() { - global $wpdb; - - $sum = []; - - foreach ( $this->values as $item ) { - $column = $item['column']; - $value = $item['value']; - $cropped = mb_substr( $value, 0, mb_strlen( $value, 'UTF-8' ) - 1, 'UTF-8' ); - - // phpcs:ignore - $sum[] = $wpdb->prepare( "SUM(CHAR_LENGTH($column) - CHAR_LENGTH(REPLACE(UPPER($column), UPPER(%s), UPPER(%s))))", $value, $cropped ); - } - - return implode( ' + ', $sum ) . ( $this->alias ? ' as ' . $this->alias : '' ); - } -} diff --git a/package.json b/package.json index 1d8bfef..f6cac10 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "search-regex", - "version": "3.0.5", + "version": "3.0.6", "description": "Adds search and replace functionality across posts, pages, comments, and meta-data, with full regular expression support", "main": "search-regex.php", "sideEffects": true, @@ -38,8 +38,8 @@ }, "homepage": "https://github.com/johngodley/search-regex", "devDependencies": { - "@types/jest": "^28.1.8", - "@types/react": "^18.0.17", + "@types/jest": "^29.0.0", + "@types/react": "^18.0.18", "@types/react-dom": "^18.0.6", "@types/react-highlight-words": "^0.16.4", "@types/react-redux": "^7.1.24", @@ -56,20 +56,20 @@ "gulp-po2json": "^1.0.0", "gulp-zip": "^5.1.0", "he": "^1.2.0", - "jest": "^29.0.0", - "jest-environment-jsdom": "^29.0.0", + "jest": "^29.0.1", + "jest-environment-jsdom": "^29.0.1", "mocha": "^10.0.0", "node-fetch": "2", "path": "^0.12.7", "prettier": "npm:wp-prettier@2.6.2", - "release-it": "^15.4.0", + "release-it": "^15.4.1", "request": "^2.88.2", "through": "^2.3.8", "through2": "^4.0.2", "webpack-shell-plugin-next": "^2.2.2" }, "dependencies": { - "@emotion/react": "^11.10.0", + "@emotion/react": "^11.10.4", "@redux-devtools/extension": "^3.2.3", "@wordpress/element": "^4.14.0", "@wordpress/i18n": "^4.16.0", @@ -92,9 +92,9 @@ "react-textarea-autosize": "^8.3.4", "redux": "^4.2.0", "redux-thunk": "^2.4.1", - "typescript": "^4.7.4", + "typescript": "^4.8.2", "url": "^0.11.0", - "use-debounce": "^8.0.3" + "use-debounce": "^8.0.4" }, "apidoc": { "name": "Search Regex REST API", diff --git a/readme.txt b/readme.txt index 47f03bf..80b599b 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: johnny5 Donate link: http://searchregex.com/donation/ Tags: search, replace, regex, regular expression, database, post, page Requires at least: 5.6 -Tested up to: 6.0.1 +Tested up to: 6.0.2 Stable tag: trunk Requires PHP: 5.6 License: GPLv3 @@ -113,6 +113,11 @@ Full documentation can be found on the [Search Regex](http://searchregex.com/) s == Changelog == += 3.0.6 - September 5th 2022 = +* Fix incorrect pagination +* Fix incorrect page reload +* Fix export missing a page of data + = 3.0.5 - August 25th 2022 = * Fix empty replacement string when saving a preset * Fix preset being saved from search preset dropdown diff --git a/search-regex.php b/search-regex.php index 1ff0f13..4df3e29 100644 --- a/search-regex.php +++ b/search-regex.php @@ -3,7 +3,7 @@ Plugin Name: Search Regex Plugin URI: https://searchregex.com/ Description: Adds search and replace functionality across posts, pages, comments, and meta-data, with full regular expression support -Version: 3.0.5 +Version: 3.0.6 Author: John Godley Text Domain: search-regex Domain Path: /locale @@ -21,7 +21,6 @@ */ define( 'SEARCHREGEX_FILE', __FILE__ ); -define( 'SEARCHREGEX_DEV_MODE', false ); // This file must support PHP < 5.6 so as not to crash if ( version_compare( phpversion(), '5.6' ) < 0 ) { diff --git a/src/app.js b/src/app.js index a308106..dc85949 100644 --- a/src/app.js +++ b/src/app.js @@ -14,6 +14,13 @@ import { getInitialState } from './state/initial'; import Home from './page/home'; import { apiFetch } from '@wp-plugin-lib'; +// Validate the locale works with the browser +try { + new Intl.NumberFormat( window.SearchRegexi10n.locale ); +} catch { + window.SearchRegexi10n.locale = 'en-US'; +} + // Set API nonce and root URL apiFetch.resetMiddlewares(); apiFetch.use( apiFetch.createRootURLMiddleware( SearchRegexi10n?.api?.WP_API_root ?? '/wp-json/' ) ); diff --git a/src/component/replace-progress/index.js b/src/component/replace-progress/index.js index 0cadbf5..27924b3 100644 --- a/src/component/replace-progress/index.js +++ b/src/component/replace-progress/index.js @@ -49,7 +49,7 @@ function Totals( { totals, current } ) { function ReplaceProgress( props ) { const { progress, totals, requestCount, onNext, status, onClear, isAdvanced, onError } = props; const total = getTotal( isAdvanced, totals ); - const { current = 0, next = 0 } = progress; + const { current = 0, next = 0, rows = 0 } = progress; const percent = Math.min( 100, status === STATUS_IN_PROGRESS ? getPercent( next === false ? total : next, total ) : 100 ); const canLoad = progress.next !== false && status === STATUS_IN_PROGRESS; @@ -68,7 +68,7 @@ function ReplaceProgress( props ) {
- + { status === STATUS_COMPLETE && (