diff --git a/.github/workflows/codequality.yml b/.github/workflows/codequality.yml index 719cd8b9a..ec4cd55ce 100644 --- a/.github/workflows/codequality.yml +++ b/.github/workflows/codequality.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: - php: [7.3.9] + php: [7.3.25, 7.4.13] name: PHP-${{ matrix.php }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 16b8c24ab..1f4848485 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ -## WP2Static 7.1.3 +## WP2Static 7.1.5 - - TBD + - fix PHP version check to 7.3>= + - fix errors during sitemap detection (thanks @fromcouch) + - fix errors during cache table initialisation + - fix pagination URLs not using correct schema + - fix CLI command registration issue ## WP2Static 7.1.2 diff --git a/README.md b/README.md index db4a1e575..dfc0b3a80 100755 --- a/README.md +++ b/README.md @@ -2,13 +2,13 @@ A WordPress plugin for static site generation and deployment. -Official homepage/docs: [https://wp2static.com](https://wp2static.com) +![codequality](https://github.com/leonstafford/wp2static/workflows/codequality/badge.svg?branch=master) +[![Packagist](https://img.shields.io/packagist/v/leonstafford/wp2static.svg?color=239922&style=popout)](https://packagist.org/packages/leonstafford/wp2static) +[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-239922)](https://github.com/phpstan/phpstan) -__Looking for the older style plugin? It's been renamed and improved as [Static HTML Output](https://github.com/WP2Static/static-html-output-plugin).__ -`develop` (bleeding edge): ![codequality](https://github.com/wp2static/wp2static/workflows/codequality/badge.svg?branch=develop) +__Looking for the older style plugin? It's been renamed and improved as [Static HTML Output](https://github.com/WP2Static/static-html-output-plugin).__ -`master` (stable): ![codequality](https://github.com/wp2static/wp2static/workflows/codequality/badge.svg?branch=master) ## Open Source over profits @@ -22,3 +22,83 @@ WP2Static is an open source project, maintained by many generous developers over Read about WP2Static's [developers, contributors, supporters](https://wp2static.com/contributors). +## Versioning & branches + +`develop` branch is considered unstable with latest code changes (current build status: ![codequality](https://github.com/leonstafford/wp2static/workflows/codequality/badge.svg?branch=develop)). `develop` branch should always have a `-dev` WordPress plugin version, ie `7.1.1-dev`. + +`master` branch should always reflect a stable release, such as `7.1.1`, which should have a matching tag. + +## Beginner-friendly contributing + +Please don't be intimidated to contribute code to this project. I welcome code + in any way you're comfortable to contribute it (email, forum, diff). If you're + new to GitHub and this kind of thing, the below guide may help you. + +1. Fork project with button in top of WP2static github [home page](https://github.com/leonstafford/wp2static) +2. Clone your project to your development computer (please, change by your account name): +
``git clone https://github.com//wp2static.git`` +3. Make your new branch from **develop** naming with: + 1. If you want add new feature: feature-\ + 2. If you want to fix a bug: bug-\ +
+ ``git checkout -b feature-myfeature`` +4. Do your commits +5. Push to your repository
+ ``git push origin feature-myfeature`` +6. Then go to your https://github.com//wp2static site and create a pull request:
+In base repository choose _leonstafford/wp2static_ and choose _development_ branch. +7. After Pull Request is approved you need to sync repositories. +8. In your local development add **upstream** branch:
+``git remote add upstream https://github.com/leonstafford/wp2static`` +9. Fetch **upstream**
+``git fetch upstream`` +10. Checkout your local branch: +``git checkout develop`` +11. Merge **upstream** with your local: +``git merge upstream/develop`` +12. You can now make new branches. + +### Working example + +#### Preparing Repository + +Fork project WP2static [home page](https://github.com/leonstafford/wp2static) + +``git clone https://github.com/ebavs/wp2static.git #clone repository (please,change ebavs by yours, this is only an example)`` + +Then add WP2Static remote + +``git remote add upstream https://github.com/leonstafford/wp2static #add remote`` + +#### Working and Commiting + +``git checkout -b feature-newdocumentation #create new branch to do changes`` + +``git commit -am "my new commits #send new changes`` + +``git push origin feature-myfeature #push to your repository`` + +Then **Pull Request** in WP2Static + +#### Sync Repository + +``git fetch upstream #download commits from wp2static repo`` + +``git checkout develop #change to local develop branch`` + +``git merge upstream/develop #merge with wpstatic develop branch`` + +### Publishing a new release + +This is currently done by @leonstafford and involves these steps: + + - test code in `develop` branch + - set a new dev version if needed, ie `7.1.1-dev` + - merge `develop` branch to `master` + - adjust `wp2static.php` version to non-dev, ie `7.1.1` + - update `CHANGELOG.md` + - create new git tag with matching version + - push `master` branch and tag to GitHub + - create new Release in GitHub with same notes as CHANGELOG + - build zip installer and publish to wp2static.com with MD5 hash + diff --git a/composer.json b/composer.json index 0f0e5875b..9036a4635 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "require": { "php": ">=7.3", "wa72/url": "^0.7.1", - "vipnytt/sitemapparser": "^1.0" + "vipnytt/sitemapparser": "^1.1.3" }, "require-dev": { "phpstan/phpstan": "*", @@ -47,9 +47,6 @@ } }, "config": { - "platform": { - "php": "7.3" - }, "preferred-install": { "*": "dist" }, @@ -59,7 +56,8 @@ "phpstan": "php -d memory_limit=-1 ./vendor/bin/phpstan analyse", "phpcbf": "vendor/bin/phpcbf --standard=./tools/phpcs.xml --ignore=*/js/*,*/tests/phpstan/*,*/admin/*,*/coverage/*,*.js,*/vendor/*,*/views/*.php ./", "phpcs": "vendor/bin/phpcs -s --standard=./tools/phpcs.xml --ignore=*/tests/phpstan/*,*/admin/*,**/coverage/*,*.js,*/vendor/*,*/views/*.php ./", - "phpcompat": "vendor/bin/phpcs --standard=PHPCompatibility --runtime-set testVersion 7.3 --ignore=*/tests/*,*/admin/*,**/coverage/*,*.js,*/vendor/*,*/views/*.php ./", + "php73": "vendor/bin/phpcs --standard=PHPCompatibility --runtime-set testVersion 7.3 --ignore=*/tests/*,*/admin/*,**/coverage/*,*.js,*/vendor/*,*/views/*.php ./", + "php74": "vendor/bin/phpcs --standard=PHPCompatibility --runtime-set testVersion 7.4 --ignore=*/tests/*,*/admin/*,**/coverage/*,*.js,*/vendor/*,*/views/*.php ./", "phpunit": "vendor/bin/phpunit ./tests/unit/", "coverage": "vendor/bin/phpunit tests/unit --coverage-html coverage --whitelist src/", "lint": "vendor/bin/parallel-lint --exclude vendor .", @@ -67,7 +65,8 @@ "composer validate --strict", "@lint", "@phpcs", - "@phpcompat", + "@php73", + "@php74", "@phpstan", "@phpunit" ], diff --git a/composer.lock b/composer.lock index b16584ac0..d5e4dd4b7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0b91e2b7a974b7ad09ed071b0e5bacda", + "content-hash": "5e4b78b9eef932069277717d55742b87", "packages": [ { "name": "guzzlehttp/guzzle", @@ -665,36 +665,31 @@ }, { "name": "doctrine/instantiator", - "version": "1.3.1", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "f350df0268e904597e3bd9c4685c53e0e333feea" + "reference": "d56bf6102915de5702778fe20f2de3b2fe570b5b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/f350df0268e904597e3bd9c4685c53e0e333feea", - "reference": "f350df0268e904597e3bd9c4685c53e0e333feea", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/d56bf6102915de5702778fe20f2de3b2fe570b5b", + "reference": "d56bf6102915de5702778fe20f2de3b2fe570b5b", "shasum": "" }, "require": { "php": "^7.1 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^6.0", + "doctrine/coding-standard": "^8.0", "ext-pdo": "*", "ext-phar": "*", - "phpbench/phpbench": "^0.13", - "phpstan/phpstan-phpunit": "^0.11", - "phpstan/phpstan-shim": "^0.11", - "phpunit/phpunit": "^7.0" + "phpbench/phpbench": "^0.13 || 1.0.0-alpha2", + "phpstan/phpstan": "^0.12", + "phpstan/phpstan-phpunit": "^0.12", + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, "autoload": { "psr-4": { "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" @@ -708,7 +703,7 @@ { "name": "Marco Pivetta", "email": "ocramius@gmail.com", - "homepage": "http://ocramius.github.com/" + "homepage": "https://ocramius.github.io/" } ], "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", @@ -719,7 +714,7 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/1.3.x" + "source": "https://github.com/doctrine/instantiator/tree/1.4.0" }, "funding": [ { @@ -735,7 +730,7 @@ "type": "tidelift" } ], - "time": "2020-05-29T17:27:14+00:00" + "time": "2020-11-10T18:47:58+00:00" }, { "name": "hamcrest/hamcrest-php", @@ -913,16 +908,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.10.1", + "version": "1.10.2", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "969b211f9a51aa1f6c01d1d2aef56d3bd91598e5" + "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/969b211f9a51aa1f6c01d1d2aef56d3bd91598e5", - "reference": "969b211f9a51aa1f6c01d1d2aef56d3bd91598e5", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/776f831124e9c62e1a2c601ecc52e776d8bb7220", + "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220", "shasum": "" }, "require": { @@ -959,7 +954,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.x" + "source": "https://github.com/myclabs/DeepCopy/tree/1.10.2" }, "funding": [ { @@ -967,20 +962,20 @@ "type": "tidelift" } ], - "time": "2020-06-29T13:22:24+00:00" + "time": "2020-11-13T09:40:50+00:00" }, { "name": "nikic/php-parser", - "version": "v4.10.2", + "version": "v4.10.3", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "658f1be311a230e0907f5dfe0213742aff0596de" + "reference": "dbe56d23de8fcb157bbc0cfb3ad7c7de0cfb0984" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/658f1be311a230e0907f5dfe0213742aff0596de", - "reference": "658f1be311a230e0907f5dfe0213742aff0596de", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/dbe56d23de8fcb157bbc0cfb3ad7c7de0cfb0984", + "reference": "dbe56d23de8fcb157bbc0cfb3ad7c7de0cfb0984", "shasum": "" }, "require": { @@ -1021,9 +1016,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.10.2" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.10.3" }, - "time": "2020-09-26T10:30:38+00:00" + "time": "2020-12-03T17:45:45+00:00" }, { "name": "phar-io/manifest", @@ -1087,16 +1082,16 @@ }, { "name": "phar-io/version", - "version": "3.0.2", + "version": "3.0.3", "source": { "type": "git", "url": "https://github.com/phar-io/version.git", - "reference": "c6bb6825def89e0a32220f88337f8ceaf1975fa0" + "reference": "726c026815142e4f8677b7cb7f2249c9ffb7ecae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/version/zipball/c6bb6825def89e0a32220f88337f8ceaf1975fa0", - "reference": "c6bb6825def89e0a32220f88337f8ceaf1975fa0", + "url": "https://api.github.com/repos/phar-io/version/zipball/726c026815142e4f8677b7cb7f2249c9ffb7ecae", + "reference": "726c026815142e4f8677b7cb7f2249c9ffb7ecae", "shasum": "" }, "require": { @@ -1132,9 +1127,9 @@ "description": "Library for handling version information and constraints", "support": { "issues": "https://github.com/phar-io/version/issues", - "source": "https://github.com/phar-io/version/tree/master" + "source": "https://github.com/phar-io/version/tree/3.0.3" }, - "time": "2020-06-27T14:39:04+00:00" + "time": "2020-11-30T09:21:21+00:00" }, { "name": "php-parallel-lint/php-parallel-lint", @@ -1526,16 +1521,16 @@ }, { "name": "phpstan/phpstan", - "version": "0.12.54", + "version": "0.12.58", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "45c7b999a4b7dd9ac5558bdaaf23dcebbef88223" + "reference": "2a4847df6047b30af28854ed9dc95304cdb56ae5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/45c7b999a4b7dd9ac5558bdaaf23dcebbef88223", - "reference": "45c7b999a4b7dd9ac5558bdaaf23dcebbef88223", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/2a4847df6047b30af28854ed9dc95304cdb56ae5", + "reference": "2a4847df6047b30af28854ed9dc95304cdb56ae5", "shasum": "" }, "require": { @@ -1566,7 +1561,7 @@ "description": "PHPStan - PHP Static Analysis Tool", "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/0.12.54" + "source": "https://github.com/phpstan/phpstan/tree/0.12.58" }, "funding": [ { @@ -1582,20 +1577,20 @@ "type": "tidelift" } ], - "time": "2020-11-05T13:36:26+00:00" + "time": "2020-11-29T13:32:03+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.3", + "version": "9.2.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "6b20e2055f7c29b56cb3870b3de7cc463d7add41" + "reference": "f3e026641cc91909d421802dd3ac7827ebfd97e1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/6b20e2055f7c29b56cb3870b3de7cc463d7add41", - "reference": "6b20e2055f7c29b56cb3870b3de7cc463d7add41", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f3e026641cc91909d421802dd3ac7827ebfd97e1", + "reference": "f3e026641cc91909d421802dd3ac7827ebfd97e1", "shasum": "" }, "require": { @@ -1609,7 +1604,7 @@ "sebastian/code-unit-reverse-lookup": "^2.0.2", "sebastian/complexity": "^2.0", "sebastian/environment": "^5.1.2", - "sebastian/lines-of-code": "^1.0", + "sebastian/lines-of-code": "^1.0.3", "sebastian/version": "^3.0.1", "theseer/tokenizer": "^1.2.0" }, @@ -1651,7 +1646,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.3" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.5" }, "funding": [ { @@ -1659,7 +1654,7 @@ "type": "github" } ], - "time": "2020-10-30T10:46:41+00:00" + "time": "2020-11-28T06:44:49+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1904,16 +1899,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.4.2", + "version": "9.5.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "3866b2eeeed21b1b099c4bc0b7a1690ac6fd5baa" + "reference": "8e16c225d57c3d6808014df6b1dd7598d0a5bbbe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3866b2eeeed21b1b099c4bc0b7a1690ac6fd5baa", - "reference": "3866b2eeeed21b1b099c4bc0b7a1690ac6fd5baa", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/8e16c225d57c3d6808014df6b1dd7598d0a5bbbe", + "reference": "8e16c225d57c3d6808014df6b1dd7598d0a5bbbe", "shasum": "" }, "require": { @@ -1929,7 +1924,7 @@ "phar-io/version": "^3.0.2", "php": ">=7.3", "phpspec/prophecy": "^1.12.1", - "phpunit/php-code-coverage": "^9.2", + "phpunit/php-code-coverage": "^9.2.3", "phpunit/php-file-iterator": "^3.0.5", "phpunit/php-invoker": "^3.1.1", "phpunit/php-text-template": "^2.0.3", @@ -1960,7 +1955,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "9.4-dev" + "dev-master": "9.5-dev" } }, "autoload": { @@ -1991,7 +1986,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.4.2" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.0" }, "funding": [ { @@ -2003,7 +1998,7 @@ "type": "github" } ], - "time": "2020-10-19T09:23:29+00:00" + "time": "2020-12-04T05:05:53+00:00" }, { "name": "sebastian/cli-parser", @@ -2575,16 +2570,16 @@ }, { "name": "sebastian/lines-of-code", - "version": "1.0.2", + "version": "1.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/lines-of-code.git", - "reference": "acf76492a65401babcf5283296fa510782783a7a" + "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/acf76492a65401babcf5283296fa510782783a7a", - "reference": "acf76492a65401babcf5283296fa510782783a7a", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/c1c2e997aa3146983ed888ad08b15470a2e22ecc", + "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc", "shasum": "" }, "require": { @@ -2620,7 +2615,7 @@ "homepage": "https://github.com/sebastianbergmann/lines-of-code", "support": { "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", - "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.2" + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.3" }, "funding": [ { @@ -2628,7 +2623,7 @@ "type": "github" } ], - "time": "2020-10-26T17:03:56+00:00" + "time": "2020-11-28T06:42:11+00:00" }, { "name": "sebastian/object-enumerator", @@ -3466,8 +3461,5 @@ "php": ">=7.3" }, "platform-dev": [], - "platform-overrides": { - "php": "7.3" - }, "plugin-api-version": "2.0.0" } diff --git a/phpstan.neon b/phpstan.neon index ba358f7c5..3fea4335b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,6 +7,7 @@ parameters: inferPrivatePropertyTypeFromConstructor: true paths: - %currentWorkingDirectory%/src/ + - %currentWorkingDirectory%/wp2static.php scanFiles: - %currentWorkingDirectory%/tests/phpstan/bootstrap.php # TODO Use https://github.com/php-stubs/wp-cli-stubs @@ -23,3 +24,4 @@ parameters: - message: '#^In method "WP2Static\\\S+::\S+", you should not use the \$_(GET|POST) superglobal#' path: src/ViewRenderer.php count: 32 + - '/^Parameter #2 \$callable of static method WP_CLI::add_command\(\) expects callable\(\): mixed, \S+ given\.$/' diff --git a/src/Addons.php b/src/Addons.php index 144de3fda..56d9bb79c 100755 --- a/src/Addons.php +++ b/src/Addons.php @@ -98,12 +98,14 @@ public static function truncate() : void { * Get enabled deployer * * "There can be only one!" + * + * @return string|bool deployment add-on slug or false */ - public static function getDeployer() : string { + public static function getDeployer() { $addons = self::getType( 'deploy' ); if ( empty( $addons ) ) { - return 'no-enabled-deployment-addons'; + return false; } return $addons[0]->slug; diff --git a/src/CLI.php b/src/CLI.php index 7aac4f73a..df563800c 100755 --- a/src/CLI.php +++ b/src/CLI.php @@ -106,12 +106,14 @@ public function deploy( array $args, array $assoc_args ) : void { - if ( Addons::getDeployer() === 'no-enabled-deployment-addons' ) { + $deployer = Addons::getDeployer(); + + if ( ! $deployer ) { WP_CLI::line( 'No deployment add-ons are enabled, skipping deployment.' ); } else { WsLog::l( 'Starting deployment' ); - do_action( 'wp2static_deploy', ProcessedSite::getPath(), Addons::getDeployer() ); - do_action( 'wp2static_post_deploy_trigger', Addons::getDeployer() ); + do_action( 'wp2static_deploy', ProcessedSite::getPath(), $deployer ); + do_action( 'wp2static_post_deploy_trigger', $deployer ); } } @@ -231,7 +233,6 @@ public function wp2static_cli_options_set_detect_common() : void { $detections = [ 'detectArchives', - 'detectAttachments', 'detectCategoryPagination', 'detectChildTheme', 'detectCustomPostTypes', @@ -257,7 +258,6 @@ public function wp2static_cli_options_set_detect_homepage_only() : void { $detections = [ 'detectArchives', - 'detectAttachments', 'detectCategoryPagination', 'detectChildTheme', 'detectCommentPagination', @@ -291,7 +291,6 @@ public function wp2static_cli_options_set_detect_maximum() : void { $detections = [ 'detectArchives', - 'detectAttachments', 'detectCategoryPagination', 'detectChildTheme', 'detectCommentPagination', diff --git a/src/Controller.php b/src/Controller.php index 00112420d..3d4ba65b4 100755 --- a/src/Controller.php +++ b/src/Controller.php @@ -590,18 +590,20 @@ public static function wp2staticProcessQueue() : void { WsLog::l( 'Post-processing completed' ); break; case 'deploy': - if ( Addons::getDeployer() === 'no-enabled-deployment-addons' ) { + $deployer = Addons::getDeployer(); + + if ( ! $deployer ) { WsLog::l( 'No deployment add-ons are enabled, skipping deployment.' ); } else { WsLog::l( 'Starting deployment' ); do_action( 'wp2static_deploy', ProcessedSite::getPath(), - Addons::getDeployer() + $deployer ); } WsLog::l( 'Starting post-deployment actions' ); - do_action( 'wp2static_post_deploy_trigger', Addons::getDeployer() ); + do_action( 'wp2static_post_deploy_trigger', $deployer ); break; default: @@ -628,14 +630,20 @@ public static function wp2staticHeadless() : void { $post_processor->processStaticSite( StaticSite::getPath() ); WsLog::l( 'Post-processing completed' ); - if ( Addons::getDeployer() === 'no-enabled-deployment-addons' ) { + $deployer = Addons::getDeployer(); + + if ( ! $deployer ) { WsLog::l( 'No deployment add-ons are enabled, skipping deployment.' ); } else { WsLog::l( 'Starting deployment' ); - do_action( 'wp2static_deploy', ProcessedSite::getPath(), Addons::getDeployer() ); + do_action( + 'wp2static_deploy', + ProcessedSite::getPath(), + $deployer + ); } WsLog::l( 'Starting post-deployment actions' ); - do_action( 'wp2static_post_deploy_trigger', Addons::getDeployer() ); + do_action( 'wp2static_post_deploy_trigger', $deployer ); } public static function invalidateSingleURLCache( diff --git a/src/CrawlCache.php b/src/CrawlCache.php index eedb1eaac..1e67de494 100644 --- a/src/CrawlCache.php +++ b/src/CrawlCache.php @@ -11,14 +11,26 @@ public static function createTable() : void { $charset_collate = $wpdb->get_charset_collate(); - // @todo We can remove this eventually - // If the ID column is missing, just remove the table and start again because - // dbDelta isn't adding it correctly - $id_row = $wpdb->get_row( "SHOW COLUMNS FROM $table_name WHERE Field = 'id'" ); - if ( ! $id_row ) { - $wpdb->query( - "DROP TABLE IF EXISTS $table_name;" + $check_table_query = + $wpdb->prepare( + 'SHOW TABLES LIKE %s', + $wpdb->esc_like( $table_name ) ); + + // if table exists, check structure + if ( $wpdb->get_var( $check_table_query ) === $table_name ) { + // @todo We can remove this eventually + // If the ID column is missing, just remove the table and start + // again because dbDelta isn't adding it correctly + $id_row = $wpdb->get_row( + "SHOW COLUMNS FROM $table_name WHERE Field = 'id'" + ); + + if ( ! $id_row ) { + $wpdb->query( + "DROP TABLE IF EXISTS $table_name;" + ); + } } $sql = "CREATE TABLE $table_name ( diff --git a/src/DeployCache.php b/src/DeployCache.php index 285e06512..5adfee735 100644 --- a/src/DeployCache.php +++ b/src/DeployCache.php @@ -13,14 +13,26 @@ public static function createTable() : void { $charset_collate = $wpdb->get_charset_collate(); - // @todo We can remove this eventually - // If the ID column is missing, just remove the table and start again because - // dbDelta isn't adding it correctly - $id_row = $wpdb->get_row( "SHOW COLUMNS FROM $table_name WHERE Field = 'id'" ); - if ( ! $id_row ) { - $wpdb->query( - "DROP TABLE IF EXISTS $table_name;" + $check_table_query = + $wpdb->prepare( + 'SHOW TABLES LIKE %s', + $wpdb->esc_like( $table_name ) ); + + // if table exists, check structure + if ( $wpdb->get_var( $check_table_query ) === $table_name ) { + // @todo We can remove this eventually + // If the ID column is missing, just remove the table and start + // again because dbDelta isn't adding it correctly + $id_row = $wpdb->get_row( + "SHOW COLUMNS FROM $table_name WHERE Field = 'id'" + ); + + if ( ! $id_row ) { + $wpdb->query( + "DROP TABLE IF EXISTS $table_name;" + ); + } } $sql = "CREATE TABLE $table_name ( diff --git a/src/DetectAttachmentURLs.php b/src/DetectAttachmentURLs.php deleted file mode 100755 index 41fa0f7e9..000000000 --- a/src/DetectAttachmentURLs.php +++ /dev/null @@ -1,35 +0,0 @@ -get_col( - "SELECT ID - FROM {$wpdb->posts} - WHERE post_type = 'attachment'" - ); - - foreach ( $post_ids as $post_id ) { - $permalink = get_attachment_link( $post_id ); - - if ( strpos( $permalink, '?post_type' ) !== false ) { - continue; - } - - $post_urls[] = $permalink; - } - - return $post_urls; - } -} diff --git a/src/DetectSitemapsURLs.php b/src/DetectSitemapsURLs.php index d5c9de4f5..9a90f60cb 100644 --- a/src/DetectSitemapsURLs.php +++ b/src/DetectSitemapsURLs.php @@ -25,27 +25,34 @@ public static function detect( string $wp_site_url ) : array { try { $sitemaps = []; - // if robots exits we parse looking for sitemaps + // if robots exists, parse for possible sitemaps if ( $robots_exits === true ) { $parser->parseRecursive( $wp_site_url . 'robots.txt' ); $sitemaps = $parser->getSitemaps(); } - // if no sitemaps I'm adding knowing sitemaps + // if no sitemaps add known sitemaps if ( count( $sitemaps ) === 0 ) { $sitemaps = [ - $wp_site_url . 'sitemap.xml', // normal sitemap - $wp_site_url . 'sitemap_index.xml', // yoast sitemap - $wp_site_url . 'wp_sitemap.xml', // wp 5.5 sitemap + // we're assigning empty arrays to match sitemaps library + $wp_site_url . 'sitemap.xml' => [], // normal sitemap + $wp_site_url . 'sitemap_index.xml' => [], // yoast sitemap + $wp_site_url . 'wp_sitemap.xml' => [], // wp 5.5 sitemap ]; } - foreach ( $sitemaps as $sitemap ) { + // TODO: a more elegant mapping + foreach ( $sitemaps as $sitemap => $unused ) { + if ( ! is_string( $sitemap ) ) { + continue; + } + $response = $request->getResponseCode( $sitemap ); + if ( $response === 200 ) { $parser->parse( $sitemap ); - $sitemaps_urls [] = '/' . str_replace( + $sitemaps_urls[] = '/' . str_replace( $wp_site_url, '', $sitemap @@ -60,7 +67,7 @@ public static function detect( string $wp_site_url ) : array { $url ); - $sitemaps_urls [] = '/' . $sitemap_url; + $sitemaps_urls[] = '/' . $sitemap_url; } } } diff --git a/src/URLDetector.php b/src/URLDetector.php index df178b7c9..db4429123 100755 --- a/src/URLDetector.php +++ b/src/URLDetector.php @@ -43,9 +43,6 @@ public static function detectURLs() : string { - sitemaps */ - // if ( CoreOptions::getValue('detectAttachments') ) { - // $arrays_to_merge[] = DetectAttachmentURLs::detect(); - // } if ( CoreOptions::getValue( 'detectPosts' ) ) { $arrays_to_merge[] = DetectPostURLs::detect(); diff --git a/src/URLHelper.php b/src/URLHelper.php index 510b9df65..1c47b57e3 100755 --- a/src/URLHelper.php +++ b/src/URLHelper.php @@ -5,13 +5,18 @@ use Exception; class URLHelper { + public static function isSecure() : bool { + return ( ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off' ) || + $_SERVER['SERVER_PORT'] == 443; + } + /* * Returns the current full URL including querystring * * @return string */ public static function getCurrent() : string { - $scheme = $_SERVER['HTTPS'] === 'on' ? 'http' : 'https'; + $scheme = self::isSecure() ? 'https' : 'http'; $url = $scheme . '://' . $_SERVER['HTTP_HOST']; // Only include port number if needed diff --git a/src/ViewRenderer.php b/src/ViewRenderer.php index b2832c78d..251c529cd 100644 --- a/src/ViewRenderer.php +++ b/src/ViewRenderer.php @@ -32,7 +32,7 @@ public static function renderDiagnosticsPage() : void { $view['memoryLimit'] = ini_get( 'memory_limit' ); $view['coreOptions'] = CoreOptions::getAll(); $view['site_info'] = SiteInfo::getAllInfo(); - $view['phpOutOfDate'] = PHP_VERSION < 7.4; + $view['phpOutOfDate'] = PHP_VERSION < 7.3; $view['uploadsWritable'] = SiteInfo::isUploadsWritable(); $view['maxExecutionTime'] = ini_get( 'max_execution_time' ); $view['curlSupported'] = SiteInfo::hasCURLSupport(); diff --git a/tests/unit/DetectAttachmentURLsTest.php b/tests/unit/DetectAttachmentURLsTest.php deleted file mode 100644 index 3f32e91a1..000000000 --- a/tests/unit/DetectAttachmentURLsTest.php +++ /dev/null @@ -1,44 +0,0 @@ -shouldReceive( 'get_col' ) - ->once() - ->andReturn( [ 1, 2, 3 ] ); - $wpdb->posts = 'wp_posts'; - - // And URLs for them - for ( $i = 1; $i <= 3; $i++ ) { - \WP_Mock::userFunction( - 'get_attachment_link', - [ - 'times' => 1, - 'args' => [ $i ], - 'return' => "{$site_url}attachment-{$i}/", - ] - ); - } - - $expected = [ - "{$site_url}attachment-1/", - "{$site_url}attachment-2/", - "{$site_url}attachment-3/", - ]; - $actual = DetectAttachmentURLs::detect(); - $this->assertEquals( $expected, $actual ); - } -} diff --git a/wp2static.php b/wp2static.php index c37d83e3b..45dac4b33 100755 --- a/wp2static.php +++ b/wp2static.php @@ -3,7 +3,7 @@ * Plugin Name: WP2Static * Plugin URI: https://wp2static.com * Description: Static site generator functionality for WordPress. - * Version: 7.1.4 + * Version: 7.1.5 * Author: WP2Static * Author URI: https://wp2static.com * Text Domain: wp2static @@ -11,19 +11,37 @@ * @package WP2Static */ -if ( ! defined( 'WPINC' ) ) { +if ( ! defined( 'ABSPATH' ) ) { die; } -define( 'WP2STATIC_VERSION', '7.1.4' ); +define( 'WP2STATIC_VERSION', '7.1.5' ); define( 'WP2STATIC_PATH', plugin_dir_path( __FILE__ ) ); if ( file_exists( WP2STATIC_PATH . 'vendor/autoload.php' ) ) { require_once WP2STATIC_PATH . 'vendor/autoload.php'; } +if ( ! class_exists( 'WP2Static\Controller' ) ) { + if ( file_exists( WP2STATIC_PATH . 'src/WP2StaticException.php' ) ) { + require_once WP2STATIC_PATH . 'src/WP2StaticException.php'; + + throw new WP2Static\WP2StaticException( + 'Looks like you\'re trying to activate WP2Static from source code' . + ', without compiling it first. Please see' . + ' https://wp2static.com/compiling-from-source for assistance.' + ); + } +} + WP2Static\Controller::init( __FILE__ ); +/** + * Define Settings link for plugin + * + * @param string[] $links array of links + * @return string[] modified array of links + */ function plugin_action_links( $links ) { $settings_link = '' . @@ -40,7 +58,11 @@ function plugin_action_links( $links ) { 'plugin_action_links' ); -function wp2static_deregister_scripts() { +/** + * Prevent WP scripts from loading which aren't useful + * on a statically exported site + */ +function wp2static_deregister_scripts() : void { wp_deregister_script( 'wp-embed' ); wp_deregister_script( 'comment-reply' ); } @@ -53,7 +75,6 @@ function wp2static_deregister_scripts() { remove_action( 'wp_print_styles', 'print_emoji_styles' ); if ( defined( 'WP_CLI' ) ) { - WP_CLI::add_command( 'wp2static', 'WP2Static\CLI' ); - WP_CLI::add_command( 'wp2static options', [ 'WP2Static\CLI', 'options' ] ); + WP_CLI::add_command( 'wp2static', WP2Static\CLI::class ); }