diff --git a/build/active-filters-frontend.asset.php b/build/active-filters-frontend.asset.php index 8f70f0585d1..172d5c378c7 100644 --- a/build/active-filters-frontend.asset.php +++ b/build/active-filters-frontend.asset.php @@ -1 +1 @@ - array('wc-blocks-components', 'wc-blocks-data-store', 'wc-price-format', 'wc-settings', 'wp-data', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-is-shallow-equal', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => '7f19935b45ec0abc002a'); + array('wc-blocks-components', 'wc-blocks-data-store', 'wc-price-format', 'wc-settings', 'wp-blocks', 'wp-data', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-is-shallow-equal', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => '586faa575a1175d4a2aa'); diff --git a/build/all-products-frontend.asset.php b/build/all-products-frontend.asset.php index 9dec0d9041c..a663105cbcc 100644 --- a/build/all-products-frontend.asset.php +++ b/build/all-products-frontend.asset.php @@ -1 +1 @@ - array('lodash', 'react', 'wc-blocks-checkout', 'wc-blocks-components', 'wc-blocks-data-store', 'wc-blocks-registry', 'wc-blocks-shared-context', 'wc-blocks-shared-hocs', 'wc-price-format', 'wc-settings', 'wp-a11y', 'wp-api-fetch', 'wp-autop', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-is-shallow-equal', 'wp-polyfill', 'wp-primitives', 'wp-style-engine', 'wp-url', 'wp-warning', 'wp-wordcount'), 'version' => 'a7c0f8ce99c348d7cdd3'); + array('lodash', 'react', 'wc-blocks-checkout', 'wc-blocks-components', 'wc-blocks-data-store', 'wc-blocks-registry', 'wc-blocks-shared-context', 'wc-blocks-shared-hocs', 'wc-price-format', 'wc-settings', 'wp-a11y', 'wp-api-fetch', 'wp-autop', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-is-shallow-equal', 'wp-polyfill', 'wp-primitives', 'wp-style-engine', 'wp-url', 'wp-warning', 'wp-wordcount'), 'version' => 'a3fde745134c9c5b057a'); diff --git a/build/attribute-filter-frontend.asset.php b/build/attribute-filter-frontend.asset.php index 26bad5305ac..c24192c0c5d 100644 --- a/build/attribute-filter-frontend.asset.php +++ b/build/attribute-filter-frontend.asset.php @@ -1 +1 @@ - array('lodash', 'react', 'wc-blocks-components', 'wc-blocks-data-store', 'wc-settings', 'wp-a11y', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-is-shallow-equal', 'wp-keycodes', 'wp-polyfill', 'wp-primitives', 'wp-url', 'wp-warning'), 'version' => 'f920c3b56ef5b551b1b3'); + array('lodash', 'react', 'wc-blocks-components', 'wc-blocks-data-store', 'wc-settings', 'wp-a11y', 'wp-blocks', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-is-shallow-equal', 'wp-keycodes', 'wp-polyfill', 'wp-primitives', 'wp-url', 'wp-warning'), 'version' => 'ab250cb514804a67b68d'); diff --git a/build/cart-frontend.asset.php b/build/cart-frontend.asset.php index 256870be1f6..05b088d6697 100644 --- a/build/cart-frontend.asset.php +++ b/build/cart-frontend.asset.php @@ -1 +1 @@ - array('lodash', 'react', 'wc-blocks-checkout', 'wc-blocks-components', 'wc-blocks-data-store', 'wc-blocks-registry', 'wc-blocks-shared-context', 'wc-blocks-shared-hocs', 'wc-price-format', 'wc-settings', 'wp-a11y', 'wp-api-fetch', 'wp-autop', 'wp-blocks', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-is-shallow-equal', 'wp-keycodes', 'wp-plugins', 'wp-polyfill', 'wp-primitives', 'wp-style-engine', 'wp-url', 'wp-warning', 'wp-wordcount'), 'version' => '69b8f99d41b5535c5b89'); + array('lodash', 'react', 'wc-blocks-checkout', 'wc-blocks-components', 'wc-blocks-data-store', 'wc-blocks-registry', 'wc-blocks-shared-context', 'wc-blocks-shared-hocs', 'wc-price-format', 'wc-settings', 'wp-a11y', 'wp-api-fetch', 'wp-autop', 'wp-blocks', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-is-shallow-equal', 'wp-keycodes', 'wp-plugins', 'wp-polyfill', 'wp-primitives', 'wp-style-engine', 'wp-url', 'wp-warning', 'wp-wordcount'), 'version' => '2f98da0ce00e5dbf403f'); diff --git a/build/checkout-frontend.asset.php b/build/checkout-frontend.asset.php index 4f5a3307f16..eecd3e59186 100644 --- a/build/checkout-frontend.asset.php +++ b/build/checkout-frontend.asset.php @@ -1 +1 @@ - array('lodash', 'react', 'wc-blocks-checkout', 'wc-blocks-components', 'wc-blocks-data-store', 'wc-blocks-registry', 'wc-blocks-shared-hocs', 'wc-price-format', 'wc-settings', 'wp-a11y', 'wp-api-fetch', 'wp-autop', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-is-shallow-equal', 'wp-keycodes', 'wp-plugins', 'wp-polyfill', 'wp-primitives', 'wp-url', 'wp-warning', 'wp-wordcount'), 'version' => '6e750dac151a4f39ba64'); + array('lodash', 'react', 'wc-blocks-checkout', 'wc-blocks-components', 'wc-blocks-data-store', 'wc-blocks-registry', 'wc-blocks-shared-hocs', 'wc-price-format', 'wc-settings', 'wp-a11y', 'wp-api-fetch', 'wp-autop', 'wp-blocks', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-is-shallow-equal', 'wp-keycodes', 'wp-plugins', 'wp-polyfill', 'wp-primitives', 'wp-url', 'wp-warning', 'wp-wordcount'), 'version' => 'f134ba84cc64bebb3b5e'); diff --git a/build/collection-price-filter-frontend.asset.php b/build/collection-price-filter-frontend.asset.php index acd57203885..e49861d878c 100644 --- a/build/collection-price-filter-frontend.asset.php +++ b/build/collection-price-filter-frontend.asset.php @@ -1 +1 @@ - array('wc-interactivity', 'wc-price-format', 'wp-polyfill'), 'version' => '163385c1d8278d2e0fc4'); + array('wc-interactivity', 'wc-price-format', 'wp-polyfill'), 'version' => '32e431d3b4997ae67449'); diff --git a/build/filter-wrapper-frontend.asset.php b/build/filter-wrapper-frontend.asset.php index 5c645ad4154..373fe634ce5 100644 --- a/build/filter-wrapper-frontend.asset.php +++ b/build/filter-wrapper-frontend.asset.php @@ -1 +1 @@ - array('lodash', 'react', 'wc-blocks-checkout', 'wc-blocks-components', 'wc-blocks-data-store', 'wc-blocks-registry', 'wc-price-format', 'wc-settings', 'wp-a11y', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-is-shallow-equal', 'wp-keycodes', 'wp-polyfill', 'wp-primitives', 'wp-style-engine', 'wp-url', 'wp-warning'), 'version' => 'd5947ab32f460fff899d'); + array('lodash', 'react', 'wc-blocks-checkout', 'wc-blocks-components', 'wc-blocks-data-store', 'wc-blocks-registry', 'wc-price-format', 'wc-settings', 'wp-a11y', 'wp-blocks', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-is-shallow-equal', 'wp-keycodes', 'wp-polyfill', 'wp-primitives', 'wp-style-engine', 'wp-url', 'wp-warning'), 'version' => '72133cbf8e571fd38ba7'); diff --git a/build/mini-cart-component-frontend.asset.php b/build/mini-cart-component-frontend.asset.php index d7c673858ea..762e583a21c 100644 --- a/build/mini-cart-component-frontend.asset.php +++ b/build/mini-cart-component-frontend.asset.php @@ -1 +1 @@ - array('lodash', 'react', 'wc-blocks-checkout', 'wc-blocks-components', 'wc-blocks-data-store', 'wc-blocks-registry', 'wc-price-format', 'wc-settings', 'wp-a11y', 'wp-autop', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-is-shallow-equal', 'wp-keycodes', 'wp-polyfill', 'wp-primitives', 'wp-style-engine', 'wp-url', 'wp-warning', 'wp-wordcount'), 'version' => 'e9b2e4691cc86be6723b'); + array('lodash', 'react', 'wc-blocks-checkout', 'wc-blocks-components', 'wc-blocks-data-store', 'wc-blocks-registry', 'wc-price-format', 'wc-settings', 'wp-a11y', 'wp-autop', 'wp-blocks', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-is-shallow-equal', 'wp-keycodes', 'wp-polyfill', 'wp-primitives', 'wp-style-engine', 'wp-url', 'wp-warning', 'wp-wordcount'), 'version' => 'de743c5a63bc108ddd3c'); diff --git a/build/mini-cart-frontend.asset.php b/build/mini-cart-frontend.asset.php index b146502827e..4a752962279 100644 --- a/build/mini-cart-frontend.asset.php +++ b/build/mini-cart-frontend.asset.php @@ -1 +1 @@ - array('wc-price-format', 'wc-settings', 'wp-api-fetch', 'wp-i18n', 'wp-polyfill'), 'version' => '61e99d9cd2611bcf7267'); + array('wc-price-format', 'wc-settings', 'wp-api-fetch', 'wp-i18n', 'wp-polyfill'), 'version' => 'a8fa59ddbb25d3de8b51'); diff --git a/build/price-filter-frontend.asset.php b/build/price-filter-frontend.asset.php index 17b5d5e0260..cdcd3b7abe8 100644 --- a/build/price-filter-frontend.asset.php +++ b/build/price-filter-frontend.asset.php @@ -1 +1 @@ - array('react', 'wc-blocks-components', 'wc-blocks-data-store', 'wc-price-format', 'wc-settings', 'wp-data', 'wp-element', 'wp-i18n', 'wp-is-shallow-equal', 'wp-polyfill', 'wp-url'), 'version' => 'dd4e55aad706b6d82855'); + array('react', 'wc-blocks-components', 'wc-blocks-data-store', 'wc-price-format', 'wc-settings', 'wp-blocks', 'wp-data', 'wp-element', 'wp-i18n', 'wp-is-shallow-equal', 'wp-polyfill', 'wp-url'), 'version' => 'ba92fc54573241d857f4'); diff --git a/build/product-button-interactivity-frontend.asset.php b/build/product-button-interactivity-frontend.asset.php index 2b2c87f4374..f4b6dbaaf9e 100644 --- a/build/product-button-interactivity-frontend.asset.php +++ b/build/product-button-interactivity-frontend.asset.php @@ -1 +1 @@ - array('lodash', 'wc-blocks-data-store', 'wc-interactivity', 'wp-a11y', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-primitives', 'wp-warning'), 'version' => '13791a2a13bd09d17cdc'); + array('lodash', 'wc-blocks-data-store', 'wc-interactivity', 'wp-a11y', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-i18n', 'wp-is-shallow-equal', 'wp-polyfill', 'wp-primitives', 'wp-warning'), 'version' => 'afff2bf96f8f4d37f370'); diff --git a/build/product-gallery-frontend.asset.php b/build/product-gallery-frontend.asset.php index ef5d72339f8..56c0efaec61 100644 --- a/build/product-gallery-frontend.asset.php +++ b/build/product-gallery-frontend.asset.php @@ -1 +1 @@ - array('wc-interactivity', 'wp-polyfill'), 'version' => '23d0ec57da7bfd423d1e'); + array('wc-interactivity', 'wp-polyfill'), 'version' => '5d4d2ec2fa00200d594e'); diff --git a/build/product-gallery-large-image-frontend.asset.php b/build/product-gallery-large-image-frontend.asset.php index dcab92a9155..7c197ebc778 100644 --- a/build/product-gallery-large-image-frontend.asset.php +++ b/build/product-gallery-large-image-frontend.asset.php @@ -1 +1 @@ - array('wc-interactivity', 'wp-polyfill'), 'version' => '75eae3707d0c9dadf2c4'); + array('wc-interactivity', 'wp-polyfill'), 'version' => '4a1295ffc7d0bf840568'); diff --git a/build/rating-filter-frontend.asset.php b/build/rating-filter-frontend.asset.php index a7a671009a9..6edb3434b1c 100644 --- a/build/rating-filter-frontend.asset.php +++ b/build/rating-filter-frontend.asset.php @@ -1 +1 @@ - array('lodash', 'react', 'wc-blocks-components', 'wc-blocks-data-store', 'wc-settings', 'wp-a11y', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-i18n', 'wp-is-shallow-equal', 'wp-keycodes', 'wp-polyfill', 'wp-primitives', 'wp-url', 'wp-warning'), 'version' => '7815828d17e2da65d6d7'); + array('lodash', 'react', 'wc-blocks-components', 'wc-blocks-data-store', 'wc-settings', 'wp-a11y', 'wp-blocks', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-i18n', 'wp-is-shallow-equal', 'wp-keycodes', 'wp-polyfill', 'wp-primitives', 'wp-url', 'wp-warning'), 'version' => '9f221d1a4bb68b616f11'); diff --git a/build/reviews-frontend.asset.php b/build/reviews-frontend.asset.php index 2cdf42e75f6..6b5d52e0708 100644 --- a/build/reviews-frontend.asset.php +++ b/build/reviews-frontend.asset.php @@ -1 +1 @@ - array('wc-settings', 'wp-a11y', 'wp-api-fetch', 'wp-compose', 'wp-element', 'wp-i18n', 'wp-is-shallow-equal', 'wp-polyfill'), 'version' => '48f4e2a59ddf8a675ce0'); + array('wc-settings', 'wp-a11y', 'wp-api-fetch', 'wp-blocks', 'wp-compose', 'wp-element', 'wp-i18n', 'wp-is-shallow-equal', 'wp-polyfill'), 'version' => 'e91d7c137c9f3becc3f8'); diff --git a/build/stock-filter-frontend.asset.php b/build/stock-filter-frontend.asset.php index 222a01ea802..983b93ab582 100644 --- a/build/stock-filter-frontend.asset.php +++ b/build/stock-filter-frontend.asset.php @@ -1 +1 @@ - array('lodash', 'react', 'wc-blocks-components', 'wc-blocks-data-store', 'wc-settings', 'wp-a11y', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-is-shallow-equal', 'wp-keycodes', 'wp-polyfill', 'wp-primitives', 'wp-url', 'wp-warning'), 'version' => 'e4069417fcbb0f97d59b'); + array('lodash', 'react', 'wc-blocks-components', 'wc-blocks-data-store', 'wc-settings', 'wp-a11y', 'wp-blocks', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-is-shallow-equal', 'wp-keycodes', 'wp-polyfill', 'wp-primitives', 'wp-url', 'wp-warning'), 'version' => '0796987775b0f46e05af'); diff --git a/vendor/autoload.php b/vendor/autoload.php new file mode 100644 index 00000000000..0f1ff43b7c1 --- /dev/null +++ b/vendor/autoload.php @@ -0,0 +1,25 @@ + +Copyright (C) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + +Gnomovision version 69, Copyright (C) year name of author +Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. +This is free software, and you are welcome to redistribute it +under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in the program +`Gnomovision' (which makes passes at compilers) written by James Hacker. + +, 1 April 1989 +Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/vendor/automattic/jetpack-a8c-mc-stats/README.md b/vendor/automattic/jetpack-a8c-mc-stats/README.md new file mode 100644 index 00000000000..c4f01ccdc90 --- /dev/null +++ b/vendor/automattic/jetpack-a8c-mc-stats/README.md @@ -0,0 +1,48 @@ +# Jetpack Stats + +Used to record internal usage stats for Automattic. Not visible to site owners. + +## Usage + +```php +$stats = new Automattic\Jetpack\A8c_Mc_Stats(); + +$stats->add( 'group', 'name' ); + +$stats->do_stats(); + +// or + +$stats->do_server_side_stats(); + +``` + +Create an instance of the class and use the `add()` method to store stats that will be processed later with `do_stats()` or `do_server_side_stats()`; + +`do_stats()` will output one `img` tag with the tracking gif for each group stored using `add()`. + +`do_server_side_stats()` will directly ping the server, with no output, for each group stored using `add()`. + +## Options + +By default, this uses `b.gif`, which is a transparent pixel. If you want to use a tiny little smiley icon instead, initialize the class with `false`. + +```php +$stats = new Automattic\Jetpack\A8c_Mc_Stats( false ); +``` + +or set the property at any time: +```php +$stats->use_transparent_pixel = false; +``` +## Using this package in your WordPress plugin + +If you plan on using this package in your WordPress plugin, we would recommend that you use [Jetpack Autoloader](https://packagist.org/packages/automattic/jetpack-autoloader) as your autoloader. This will allow for maximum interoperability with other plugins that use this package as well. + +## Security + +Need to report a security vulnerability? Go to [https://automattic.com/security/](https://automattic.com/security/) or directly to our security bug bounty site [https://hackerone.com/automattic](https://hackerone.com/automattic). + +## License + +jetpack-a8c-mc-stats is licensed under [GNU General Public License v2 (or later)](./LICENSE.txt) diff --git a/vendor/automattic/jetpack-a8c-mc-stats/SECURITY.md b/vendor/automattic/jetpack-a8c-mc-stats/SECURITY.md new file mode 100644 index 00000000000..b4b46c0ee23 --- /dev/null +++ b/vendor/automattic/jetpack-a8c-mc-stats/SECURITY.md @@ -0,0 +1,38 @@ +# Security Policy + +Full details of the Automattic Security Policy can be found on [automattic.com](https://automattic.com/security/). + +## Supported Versions + +Generally, only the latest version of Jetpack has continued support. If a critical vulnerability is found in the current version of Jetpack, we may opt to backport any patches to previous versions. + +## Reporting a Vulnerability + +[Jetpack](https://jetpack.com/) is an open-source plugin for WordPress. Our HackerOne program covers the plugin software, as well as a variety of related projects and infrastructure. + +**For responsible disclosure of security issues and to be eligible for our bug bounty program, please submit your report via the [HackerOne](https://hackerone.com/automattic) portal.** + +Our most critical targets are: + +* Jetpack and the Jetpack composer packages (all within this repo) +* Jetpack.com -- the primary marketing site. +* cloud.jetpack.com -- a management site. +* wordpress.com -- the shared management site for both Jetpack and WordPress.com sites. + +For more targets, see the `In Scope` section on [HackerOne](https://hackerone.com/automattic). + +_Please note that the **WordPress software is a separate entity** from Automattic. Please report vulnerabilities for WordPress through [the WordPress Foundation's HackerOne page](https://hackerone.com/wordpress)._ + +## Guidelines + +We're committed to working with security researchers to resolve the vulnerabilities they discover. You can help us by following these guidelines: + +* Follow [HackerOne's disclosure guidelines](https://www.hackerone.com/disclosure-guidelines). +* Pen-testing Production: + * Please **setup a local environment** instead whenever possible. Most of our code is open source (see above). + * If that's not possible, **limit any data access/modification** to the bare minimum necessary to reproduce a PoC. + * **_Don't_ automate form submissions!** That's very annoying for us, because it adds extra work for the volunteers who manage those systems, and reduces the signal/noise ratio in our communication channels. + * To be eligible for a bounty, all of these guidelines must be followed. +* Be Patient - Give us a reasonable time to correct the issue before you disclose the vulnerability. + +We also expect you to comply with all applicable laws. You're responsible to pay any taxes associated with your bounties. diff --git a/vendor/automattic/jetpack-a8c-mc-stats/composer.json b/vendor/automattic/jetpack-a8c-mc-stats/composer.json new file mode 100644 index 00000000000..8931f63405b --- /dev/null +++ b/vendor/automattic/jetpack-a8c-mc-stats/composer.json @@ -0,0 +1,39 @@ +{ + "name": "automattic/jetpack-a8c-mc-stats", + "description": "Used to record internal usage stats for Automattic. Not visible to site owners.", + "type": "jetpack-library", + "license": "GPL-2.0-or-later", + "require": {}, + "require-dev": { + "yoast/phpunit-polyfills": "1.1.0", + "automattic/jetpack-changelogger": "^3.3.9" + }, + "suggest": { + "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "scripts": { + "phpunit": [ + "./vendor/phpunit/phpunit/phpunit --colors=always" + ], + "test-php": [ + "@composer phpunit" + ] + }, + "minimum-stability": "dev", + "prefer-stable": true, + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-a8c-mc-stats", + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-a8c-mc-stats/compare/v${old}...v${new}" + }, + "branch-alias": { + "dev-trunk": "1.4.x-dev" + } + } +} diff --git a/vendor/automattic/jetpack-a8c-mc-stats/src/class-a8c-mc-stats.php b/vendor/automattic/jetpack-a8c-mc-stats/src/class-a8c-mc-stats.php new file mode 100644 index 00000000000..9e573cd7b15 --- /dev/null +++ b/vendor/automattic/jetpack-a8c-mc-stats/src/class-a8c-mc-stats.php @@ -0,0 +1,181 @@ +use_transparent_pixel = $use_transparent_pixel; + } + + /** + * Store a stat for later output. + * + * @param string $group The stat group. + * @param string $name The stat name to bump. + * + * @return boolean true if stat successfully added + */ + public function add( $group, $name ) { + + if ( ! \is_string( $group ) || ! \is_string( $name ) ) { + return false; + } + + if ( ! isset( $this->stats[ $group ] ) ) { + $this->stats[ $group ] = array(); + } + + if ( \in_array( $name, $this->stats[ $group ], true ) ) { + return false; + } + + $this->stats[ $group ][] = $name; + + return true; + } + + /** + * Gets current stats stored to be processed + * + * @return array $stats + */ + public function get_current_stats() { + return $this->stats; + } + + /** + * Return the stats from a group in an array ready to be added as parameters in a query string + * + * @param string $group_name The name of the group to retrieve. + * @return array Array with one item, where the key is the prefixed group and the value are all stats concatenated with a comma. If group not found, an empty array will be returned + */ + public function get_group_query_args( $group_name ) { + $stats = $this->get_current_stats(); + if ( isset( $stats[ $group_name ] ) && ! empty( $stats[ $group_name ] ) ) { + return array( "x_jetpack-{$group_name}" => implode( ',', $stats[ $group_name ] ) ); + } + return array(); + } + + /** + * Gets a list of trac URLs for every stored URL + * + * @return array An array of URLs + */ + public function get_stats_urls() { + + $urls = array(); + + foreach ( $this->get_current_stats() as $group => $stat ) { + $group_query_string = $this->get_group_query_args( $group ); + $urls[] = $this->build_stats_url( $group_query_string ); + } + + return $urls; + } + + /** + * Outputs the tracking pixels for the current stats and empty the stored stats from the object + * + * @return void + */ + public function do_stats() { + $urls = $this->get_stats_urls(); + foreach ( $urls as $url ) { + echo ''; + } + $this->stats = array(); + } + + /** + * Pings the stats server for the current stats and empty the stored stats from the object + * + * @return void + */ + public function do_server_side_stats() { + $urls = $this->get_stats_urls(); + foreach ( $urls as $url ) { + $this->do_server_side_stat( $url ); + } + $this->stats = array(); + } + + /** + * Runs stats code for a one-off, server-side. + * + * @param string $url string The URL to be pinged. Should include `x_jetpack-{$group}={$stats}` or whatever we want to store. + * + * @return bool If it worked. + */ + public function do_server_side_stat( $url ) { + $response = wp_remote_get( esc_url_raw( $url ) ); + if ( is_wp_error( $response ) ) { + return false; + } + + if ( 200 !== wp_remote_retrieve_response_code( $response ) ) { + return false; + } + + return true; + } + + /** + * Builds the stats url. + * + * @param array $args array|string The arguments to append to the URL. + * + * @return string The URL to be pinged. + */ + public function build_stats_url( $args ) { + $defaults = array( + 'v' => 'wpcom2', + 'rand' => md5( wp_rand( 0, 999 ) . time() ), + ); + $args = wp_parse_args( $args, $defaults ); + $gifname = true === $this->use_transparent_pixel ? 'b.gif' : 'g.gif'; + + /** + * Filter the URL used as the Stats tracking pixel. + * + * @since-jetpack 2.3.2 + * @since 1.0.0 + * + * @param string $url Base URL used as the Stats tracking pixel. + */ + $base_url = apply_filters( + 'jetpack_stats_base_url', + 'https://pixel.wp.com/' . $gifname + ); + $url = add_query_arg( $args, $base_url ); + return $url; + } +} diff --git a/vendor/automattic/jetpack-admin-ui/.phpcs.dir.xml b/vendor/automattic/jetpack-admin-ui/.phpcs.dir.xml new file mode 100644 index 00000000000..8ebbc7cd35a --- /dev/null +++ b/vendor/automattic/jetpack-admin-ui/.phpcs.dir.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vendor/automattic/jetpack-admin-ui/CHANGELOG.md b/vendor/automattic/jetpack-admin-ui/CHANGELOG.md new file mode 100644 index 00000000000..5a2ca3cb073 --- /dev/null +++ b/vendor/automattic/jetpack-admin-ui/CHANGELOG.md @@ -0,0 +1,147 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.2.23] - 2023-09-19 +### Changed +- Updated Jetpack submenu sort order so individual features are alpha-sorted. [#32958] + +## [0.2.22] - 2023-09-11 +### Fixed +- Akismet: update naming to common form [#32908] + +## [0.2.21] - 2023-08-23 +### Changed +- Updated package dependencies. [#32605] + +## [0.2.20] - 2023-04-25 +### Fixed +- Avoid errors when used in combination with an older version of the Logo package. [#30136] + +## [0.2.19] - 2023-04-10 +### Added +- Add Jetpack Autoloader package suggestion. [#29988] + +## [0.2.18] - 2023-04-04 +### Changed +- Menu icon: update to latest version of the Jetpack logo [#29418] + +## [0.2.17] - 2023-02-20 +### Changed +- Minor internal updates. + +## [0.2.16] - 2023-01-25 +### Changed +- Minor internal updates. + +## [0.2.15] - 2023-01-11 +### Changed +- Updated package dependencies. + +## [0.2.14] - 2022-12-02 +### Changed +- Updated package dependencies. [#27688] + +## [0.2.13] - 2022-11-22 +### Changed +- Updated package dependencies. [#27043] + +## [0.2.12] - 2022-09-20 +### Changed +- Updated package dependencies. + +## [0.2.11] - 2022-07-26 +### Changed +- Updated package dependencies. [#25158] + +## [0.2.10] - 2022-07-12 +### Changed +- Updated package dependencies. + +## [0.2.9] - 2022-06-21 +### Changed +- Renaming master to trunk. + +## [0.2.8] - 2022-06-14 +### Changed +- Updated package dependencies. + +## [0.2.7] - 2022-04-26 +### Changed +- Update package.json metadata. + +## [0.2.6] - 2022-04-05 +### Changed +- Updated package dependencies. + +## [0.2.5] - 2022-03-08 +### Fixed +- Do not handle Akismet submenu if Jetpack plugin is present + +## [0.2.4] - 2022-02-09 +### Added +- Support for akismet menu with stand-alone plugins + +### Fixed +- Fixes menu order working around a bug in add_submenu_page + +## [0.2.3] - 2022-01-25 +### Changed +- Updated package dependencies. + +## [0.2.2] - 2022-01-18 +### Changed +- General: update required node version to v16.13.2 + +## [0.2.1] - 2022-01-04 +### Changed +- Switch to pcov for code coverage. +- Updated package dependencies + +## [0.2.0] - 2021-12-14 +### Added +- New method to get the top level menu item + +## [0.1.1] - 2021-11-17 +### Changed +- Set `convertDeprecationsToExceptions` true in PHPUnit config. +- Update PHPUnit configs to include just what needs coverage rather than include everything then try to exclude stuff that doesn't. + +## 0.1.0 - 2021-10-13 +### Added +- Created the package. + +### Changed +- Updated package dependencies. + +### Fixed +- Fixing menu visibility issues. + +[0.2.23]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.22...0.2.23 +[0.2.22]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.21...0.2.22 +[0.2.21]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.20...0.2.21 +[0.2.20]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.19...0.2.20 +[0.2.19]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.18...0.2.19 +[0.2.18]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.17...0.2.18 +[0.2.17]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.16...0.2.17 +[0.2.16]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.15...0.2.16 +[0.2.15]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.14...0.2.15 +[0.2.14]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.13...0.2.14 +[0.2.13]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.12...0.2.13 +[0.2.12]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.11...0.2.12 +[0.2.11]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.10...0.2.11 +[0.2.10]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.9...0.2.10 +[0.2.9]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.8...0.2.9 +[0.2.8]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.7...0.2.8 +[0.2.7]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.6...0.2.7 +[0.2.6]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.5...0.2.6 +[0.2.5]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.4...0.2.5 +[0.2.4]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.3...0.2.4 +[0.2.3]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.2...0.2.3 +[0.2.2]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.1...0.2.2 +[0.2.1]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.0...0.2.1 +[0.2.0]: https://github.com/Automattic/jetpack-admin-ui/compare/0.1.1...0.2.0 +[0.1.1]: https://github.com/Automattic/jetpack-admin-ui/compare/0.1.0...0.1.1 diff --git a/vendor/automattic/jetpack-admin-ui/LICENSE.txt b/vendor/automattic/jetpack-admin-ui/LICENSE.txt new file mode 100644 index 00000000000..e82774c1bd5 --- /dev/null +++ b/vendor/automattic/jetpack-admin-ui/LICENSE.txt @@ -0,0 +1,357 @@ +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +=================================== + + +GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + + Preamble + +The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + +We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + +Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and +modification follow. + +GNU GENERAL PUBLIC LICENSE +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + +a) You must cause the modified files to carry prominent notices +stating that you changed the files and the date of any change. + +b) You must cause any work that you distribute or publish, that in +whole or in part contains or is derived from the Program or any +part thereof, to be licensed as a whole at no charge to all third +parties under the terms of this License. + +c) If the modified program normally reads commands interactively +when run, you must cause it, when started running for such +interactive use in the most ordinary way, to print or display an +announcement including an appropriate copyright notice and a +notice that there is no warranty (or else, saying that you provide +a warranty) and that users may redistribute the program under +these conditions, and telling the user how to view a copy of this +License. (Exception: if the Program itself is interactive but +does not normally print such an announcement, your work based on +the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + +a) Accompany it with the complete corresponding machine-readable +source code, which must be distributed under the terms of Sections +1 and 2 above on a medium customarily used for software interchange; or, + +b) Accompany it with a written offer, valid for at least three +years, to give any third party, for a charge no more than your +cost of physically performing source distribution, a complete +machine-readable copy of the corresponding source code, to be +distributed under the terms of Sections 1 and 2 above on a medium +customarily used for software interchange; or, + +c) Accompany it with the information you received as to the offer +to distribute corresponding source code. (This alternative is +allowed only for noncommercial distribution and only if you +received the program in object code or executable form with such +an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + +5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + +7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + +10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + +Copyright (C) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + +Gnomovision version 69, Copyright (C) year name of author +Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. +This is free software, and you are welcome to redistribute it +under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in the program +`Gnomovision' (which makes passes at compilers) written by James Hacker. + +, 1 April 1989 +Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/vendor/automattic/jetpack-admin-ui/README.md b/vendor/automattic/jetpack-admin-ui/README.md new file mode 100644 index 00000000000..a91f37ccfbc --- /dev/null +++ b/vendor/automattic/jetpack-admin-ui/README.md @@ -0,0 +1,37 @@ +# admin-ui + +Generic Jetpack wp-admin UI elements +## How to use +### Menu Registration + +Use the Admin_Menu class to add your plugin under the Jetpack top level menu in WP-Admin. + +This package will make sure to register the top level menu, if not registered yet, and will add the new menu(s) item(s) under it. + +Use the `add_menu` to register your menu, no need to do it inside the `admin_menu` hook. You can do it in your plugin initialization. + +The parameters this method gets are the same parameters `add_submenu_page` gets, except that you don't need to inform `parent` menu. + +Example: + +```PHP +use Automattic\Jetpack\Admin_UI\Admin_Menu; + +$page_suffix = Admin_Menu::add_menu( + __( 'My Awesome plugin', 'my-awesome-plugin' ), + __( 'My Awesome plugin', 'my-awesome-plugin' ), + 'manage_options', + 'my-awesome-plugin', + '__my_plugin_page_callback' +); +add_action( 'load-' . $page_suffix, 'my_plugin_do_stuff_on_page_load' ); + +``` +## Security + +Need to report a security vulnerability? Go to [https://automattic.com/security/](https://automattic.com/security/) or directly to our security bug bounty site [https://hackerone.com/automattic](https://hackerone.com/automattic). + +## License + +admin-ui is licensed under [GNU General Public License v2 (or later)](./LICENSE.txt) + diff --git a/vendor/automattic/jetpack-admin-ui/SECURITY.md b/vendor/automattic/jetpack-admin-ui/SECURITY.md new file mode 100644 index 00000000000..b4b46c0ee23 --- /dev/null +++ b/vendor/automattic/jetpack-admin-ui/SECURITY.md @@ -0,0 +1,38 @@ +# Security Policy + +Full details of the Automattic Security Policy can be found on [automattic.com](https://automattic.com/security/). + +## Supported Versions + +Generally, only the latest version of Jetpack has continued support. If a critical vulnerability is found in the current version of Jetpack, we may opt to backport any patches to previous versions. + +## Reporting a Vulnerability + +[Jetpack](https://jetpack.com/) is an open-source plugin for WordPress. Our HackerOne program covers the plugin software, as well as a variety of related projects and infrastructure. + +**For responsible disclosure of security issues and to be eligible for our bug bounty program, please submit your report via the [HackerOne](https://hackerone.com/automattic) portal.** + +Our most critical targets are: + +* Jetpack and the Jetpack composer packages (all within this repo) +* Jetpack.com -- the primary marketing site. +* cloud.jetpack.com -- a management site. +* wordpress.com -- the shared management site for both Jetpack and WordPress.com sites. + +For more targets, see the `In Scope` section on [HackerOne](https://hackerone.com/automattic). + +_Please note that the **WordPress software is a separate entity** from Automattic. Please report vulnerabilities for WordPress through [the WordPress Foundation's HackerOne page](https://hackerone.com/wordpress)._ + +## Guidelines + +We're committed to working with security researchers to resolve the vulnerabilities they discover. You can help us by following these guidelines: + +* Follow [HackerOne's disclosure guidelines](https://www.hackerone.com/disclosure-guidelines). +* Pen-testing Production: + * Please **setup a local environment** instead whenever possible. Most of our code is open source (see above). + * If that's not possible, **limit any data access/modification** to the bare minimum necessary to reproduce a PoC. + * **_Don't_ automate form submissions!** That's very annoying for us, because it adds extra work for the volunteers who manage those systems, and reduces the signal/noise ratio in our communication channels. + * To be eligible for a bounty, all of these guidelines must be followed. +* Be Patient - Give us a reasonable time to correct the issue before you disclose the vulnerability. + +We also expect you to comply with all applicable laws. You're responsible to pay any taxes associated with your bounties. diff --git a/vendor/automattic/jetpack-admin-ui/composer.json b/vendor/automattic/jetpack-admin-ui/composer.json new file mode 100644 index 00000000000..aaf83ff362d --- /dev/null +++ b/vendor/automattic/jetpack-admin-ui/composer.json @@ -0,0 +1,52 @@ +{ + "name": "automattic/jetpack-admin-ui", + "description": "Generic Jetpack wp-admin UI elements", + "type": "jetpack-library", + "license": "GPL-2.0-or-later", + "require": {}, + "require-dev": { + "yoast/phpunit-polyfills": "1.1.0", + "automattic/jetpack-changelogger": "^3.3.9", + "automattic/jetpack-logo": "^1.6.3", + "automattic/wordbless": "dev-master" + }, + "suggest": { + "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "scripts": { + "phpunit": [ + "./vendor/phpunit/phpunit/phpunit --colors=always" + ], + "test-php": [ + "@composer phpunit" + ], + "post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy", + "post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy" + }, + "minimum-stability": "dev", + "prefer-stable": true, + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-admin-ui", + "textdomain": "jetpack-admin-ui", + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-admin-ui/compare/${old}...${new}" + }, + "branch-alias": { + "dev-trunk": "0.2.x-dev" + }, + "version-constants": { + "::PACKAGE_VERSION": "src/class-admin-menu.php" + } + }, + "config": { + "allow-plugins": { + "roots/wordpress-core-installer": true + } + } +} diff --git a/vendor/automattic/jetpack-admin-ui/src/class-admin-menu.php b/vendor/automattic/jetpack-admin-ui/src/class-admin-menu.php new file mode 100644 index 00000000000..55d44ffc242 --- /dev/null +++ b/vendor/automattic/jetpack-admin-ui/src/class-admin-menu.php @@ -0,0 +1,207 @@ +get_base64_logo() + : 'dashicons-admin-plugins'; + + if ( ! $jetpack_plugin_present ) { + add_menu_page( + 'Jetpack', + 'Jetpack', + 'read', + 'jetpack', + '__return_null', + $icon, + 3 + ); + + // If Jetpack plugin is not present, user will only be able to see this menu if they have enough capability to at least one of the sub menus being added. + $can_see_toplevel_menu = false; + } + + /** + * The add_sub_menu function has a bug and will not keep the right order of menu items. + * + * @see https://core.trac.wordpress.org/ticket/52035 + * Let's order the items before registering them. + * Since this all happens after the Jetpack plugin menu items were added, all items will be added after Jetpack plugin items - unless position is very low number (smaller than the number of menu items present in Jetpack plugin). + */ + usort( + self::$menu_items, + function ( $a, $b ) { + $position_a = empty( $a['position'] ) ? 0 : $a['position']; + $position_b = empty( $b['position'] ) ? 0 : $b['position']; + $result = $position_a - $position_b; + + if ( 0 === $result ) { + $result = strcmp( $a['menu_title'], $b['menu_title'] ); + } + + return $result; + } + ); + + foreach ( self::$menu_items as $menu_item ) { + if ( ! current_user_can( $menu_item['capability'] ) ) { + continue; + } + + $can_see_toplevel_menu = true; + + add_submenu_page( + 'jetpack', + $menu_item['page_title'], + $menu_item['menu_title'], + $menu_item['capability'], + $menu_item['menu_slug'], + $menu_item['function'], + $menu_item['position'] + ); + } + + if ( ! $jetpack_plugin_present ) { + remove_submenu_page( 'jetpack', 'jetpack' ); + } + + if ( ! $can_see_toplevel_menu ) { + remove_menu_page( 'jetpack' ); + } + } + + /** + * Adds a new submenu to the Jetpack Top level menu + * + * The parameters this method accepts are the same as @see add_submenu_page. This class will + * aggreagate all menu items registered by stand-alone plugins and make sure they all go under the same + * Jetpack top level menu. It will also handle the top level menu registration in case the Jetpack plugin is not present. + * + * @param string $page_title The text to be displayed in the title tags of the page when the menu + * is selected. + * @param string $menu_title The text to be used for the menu. + * @param string $capability The capability required for this menu to be displayed to the user. + * @param string $menu_slug The slug name to refer to this menu by. Should be unique for this menu + * and only include lowercase alphanumeric, dashes, and underscores characters + * to be compatible with sanitize_key(). + * @param callable $function The function to be called to output the content for this page. + * @param int $position The position in the menu order this item should appear. Leave empty typically. + * + * @return string The resulting page's hook_suffix + */ + public static function add_menu( $page_title, $menu_title, $capability, $menu_slug, $function, $position = null ) { + self::init(); + self::$menu_items[] = compact( 'page_title', 'menu_title', 'capability', 'menu_slug', 'function', 'position' ); + + /** + * Let's return the page hook so consumers can use. + * We know all pages will be under Jetpack top level menu page, so we can hardcode the first part of the string. + * Using get_plugin_page_hookname here won't work because the top level page is not registered yet. + */ + return 'jetpack_page_' . $menu_slug; + } + + /** + * Gets the slug for the first item under the Jetpack top level menu + * + * @return string|null + */ + public static function get_top_level_menu_item_slug() { + global $submenu; + if ( ! empty( $submenu['jetpack'] ) ) { + $item = reset( $submenu['jetpack'] ); + if ( isset( $item[2] ) ) { + return $item[2]; + } + } + } + + /** + * Gets the URL for the first item under the Jetpack top level menu + * + * @param string $fallback If Jetpack menu is not there or no children is found, return this fallback instead. Default to admin_url(). + * @return string + */ + public static function get_top_level_menu_item_url( $fallback = false ) { + $slug = self::get_top_level_menu_item_slug(); + + if ( $slug ) { + $url = menu_page_url( $slug, false ); + return $url; + } + + $url = $fallback ? $fallback : admin_url(); + return $url; + } +} diff --git a/vendor/automattic/jetpack-autoloader/.gitignore b/vendor/automattic/jetpack-autoloader/.gitignore new file mode 100644 index 00000000000..54c2987d03c --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/.gitignore @@ -0,0 +1 @@ +tests/php/tmp diff --git a/vendor/automattic/jetpack-autoloader/.phpcs.dir.phpcompatibility.xml b/vendor/automattic/jetpack-autoloader/.phpcs.dir.phpcompatibility.xml new file mode 100644 index 00000000000..d054bba4332 --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/.phpcs.dir.phpcompatibility.xml @@ -0,0 +1,4 @@ + + + + diff --git a/vendor/automattic/jetpack-autoloader/.phpcs.dir.xml b/vendor/automattic/jetpack-autoloader/.phpcs.dir.xml new file mode 100644 index 00000000000..72a9c61d3f1 --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/.phpcs.dir.xml @@ -0,0 +1,4 @@ + + + + diff --git a/vendor/automattic/jetpack-autoloader/CHANGELOG.md b/vendor/automattic/jetpack-autoloader/CHANGELOG.md new file mode 100644 index 00000000000..afad1247798 --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/CHANGELOG.md @@ -0,0 +1,404 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [2.12.0] - 2023-09-28 +### Added +- Add an `AutoloadGenerator::VERSION` constant, and use that for the autoloader's version in preference to whatever Composer has. [#33156] + +## [2.11.23] - 2023-09-19 + +- Minor internal updates. + +## [2.11.22] - 2023-08-23 +### Changed +- Updated package dependencies. [#32605] + +## [2.11.21] - 2023-05-22 +### Added +- Set keywords in `composer.json`. [#30756] + +## [2.11.20] - 2023-05-11 + +- Updated package dependencies + +## [2.11.19] - 2023-04-25 +### Fixed +- Fix example in README [#30225] + +## [2.11.18] - 2023-03-28 +### Changed +- Minor internal updates. + +## [2.11.17] - 2023-03-27 +### Fixed +- Don't error when processing packages specifying missing PSR paths. [#29669] + +## [2.11.16] - 2023-02-20 +### Changed +- Minor internal updates. + +## [2.11.15] - 2023-01-11 +### Changed +- Updated package dependencies. + +## [2.11.14] - 2022-12-19 +### Changed +- Use `Composer\ClassMapGenerator\ClassMapGenerator` when available (i.e. with composer 2.4). [#27812] + +### Fixed +- Declare fields for PHP 8.2 compatibility. [#27949] + +## [2.11.13] - 2022-12-02 +### Changed +- Updated package dependencies. [#27688] + +## [2.11.12] - 2022-11-22 +### Changed +- Updated package dependencies. [#27043] + +## [2.11.11] - 2022-10-25 +### Changed +- Sort data in generated `vendor/composer/jetpack_autoload_classmap.php` to avoid spurious diffs. [#26929] + +## [2.11.10] - 2022-10-05 + +- Tests: Clear `COMPOSER_AUTH` environment variable when running Composer for tests. [#26404] + +## [2.11.9] - 2022-09-27 +### Fixed +- Tests: Clear `COMPOSER_AUTH` environment variable when running Composer for tests. [#26404] + +## [2.11.8] - 2022-09-20 +### Fixed +- Tests: skip test if it requires a version of Composer not compatible with the running version of PHP. [#26143] + +## [2.11.7] - 2022-07-26 +### Changed +- Updated package dependencies. [#25158] + +## [2.11.6] - 2022-06-21 +### Changed +- Renaming `master` to `trunk`. + +## [2.11.5] - 2022-05-18 +### Fixed +- Fix new PHPCS sniffs. [#24366] + +## [2.11.4] - 2022-04-26 +### Changed +- Updated package dependencies. + +## [2.11.3] - 2022-04-19 +### Changed +- PHPCS: Fix `WordPress.Security.ValidatedSanitizedInput` + +## [2.11.2] - 2022-03-29 +### Changed +- Microperformance: Use === null instead of is_null + +## [2.11.1] - 2022-03-08 +### Removed +- Removed the Upgrade Handler. + +## [2.11.0] - 2022-03-08 +### Added +- On plugin update, pre-load all (non-PSR-4) classes from the plugin to avoid mid-upgrade fatals. + +## [2.10.13] - 2022-03-01 +### Fixed +- Fix tests for upstream phpunit change. + +## [2.10.12] - 2022-01-25 +### Changed +- Updated package dependencies. + +## [2.10.11] - 2022-01-04 +### Changed +- Switch to pcov for code coverage. +- Updated package dependencies + +## [2.10.10] - 2021-11-16 +### Added +- Soft return if autoloader chain is not available. + +## [2.10.9] - 2021-11-02 +### Changed +- Set `convertDeprecationsToExceptions` true in PHPUnit config. + +## [2.10.8] - 2021-10-13 +### Changed +- Updated package dependencies. + +## [2.10.7] - 2021-10-07 +### Changed +- Updated package dependencies + +## [2.10.6] - 2021-09-28 +### Changed +- Updated package dependencies. + +## [2.10.5] - 2021-08-31 +### Changed +- Run composer update on test-php command instead of phpunit +- Tests: update PHPUnit polyfills dependency (yoast/phpunit-polyfills). + +## [2.10.4] - 2021-08-10 +### Changed +- Updated package dependencies. + +## [2.10.3] - 2021-05-25 +### Changed +- Updated package dependencies. + +## [2.10.2] - 2021-04-27 +### Changed +- Updated package dependencies. + +## [2.10.1] - 2021-03-30 +### Added +- Composer alias for dev-master, to improve dependencies +- Tests: Added code coverage transformation + +### Changed +- Update package dependencies. + +### Fixed +- Fix coverage test +- Fix uninstallation fatal +- Update tests for changed composer 2.0.9 hash. +- Use `composer update` rather than `install` in scripts, as composer.lock isn't checked in. + +## [2.10.0] - 2021-02-09 + +- Autoloader: test suite refactor + +## [2.9.1] - 2021-02-05 + +- CI: Make tests more generic +- Autoloader: stricter type-checking on WP functions +- Autoloader: prevent transitive plugin execution + +## [2.9.0] - 2021-01-25 + +- Autoloader: revised latest autoloader inclusion semantics +- Add mirror-repo information to all current composer packages +- Monorepo: Reorganize all projects +- Autoloader: Don't cache deactivating plugins + +## [2.8.0] - 2020-12-18 + +## [2.7.1] - 2020-12-18 + +- Autoloader: Added realpath resolution to plugin paths + +## [2.7.0] - 2020-12-08 + +- Autoloader: Preemptively load unknown plugins from cache +- Removed unwanted dot +- Pin dependencies +- Packages: Update for PHP 8 testing + +## [2.6.0] - 2020-11-19 + +- Autoloader: AutoloadGenerator no longer extends Composer's AutoloadGenerator class +- Autoloader: Reuse an existing autoloader suffix if available +- Updated PHPCS: Packages and Debugger + +## [2.5.0] - 2020-10-08 + +- Autoloader: remove the defined('JETPACK_AUTOLOAD_DEV') checks from the tests + +## [2.4.0] - 2020-09-28 + +- Autoloader: remove the plugins_loaded bullet point from the README +- Packages: avoid PHPCS warnings +- Autoloader: add PSR-0 support +- Autoloader: Detect filtering of active_plugins +- Autoloader: Support unoptimized PSR-4 + +## [2.3.0] - 2020-08-21 + +- Autoloader: remove the plugin update hook + +## [2.2.0] - 2020-08-14 + +- Autoloader: don't reset the autoloader version during plugin update +- CI: Try collect js coverage + +## [2.1.0] - 2020-07-27 + +- Autoloader: convert '\' directory separators to '/' in plugin paths +- Autoloader: Avoid a PHP warning when an empty string is passed to `is_directory_plugin()`. +- Autoloader: Tests: Use a string with define + +## [2.0.2] - 2020-07-09 + +- Autoloader: Avoid a PHP warning when an empty string is passed to `is_directory_plugin()`. + +## [2.0.1] - 2020-07-02 + +- Autoloader: Tests: Use a string with define + +## [2.0.0] - 2020-06-29 + +## [2.0.0-beta] - 2020-06-29 + +- Autoloader: Support Composer v2.0 +- Autoloader: use paths to identify plugins instead of the directories +- Autoloader: fix the fatal that occurs during plugin update +- Autoloader: add fallback check for plugin path in mu-plugins +- Autoloader: use JETPACK__PLUGIN_DIR when looking for the jetpack plugin directory. +- Feature Branch: Update the Autoloader +- PHPCS: Clean up the packages +- PHPCS Updates after WPCS 2.3 + +## [1.7.0] - 2020-04-23 + +- Jetpack: Move comment notification override back to the constructor + +## [1.6.0] - 2020-03-26 + +- Autoloader: Remove file check to improve performance. + +## [1.5.0] - 2020-02-25 + +- Jetpack: instantiate manager object if it's null + +## [1.4.1] - 2020-02-14 + +- Autoloader: Load only latest version of autoload files to avoid conflicts. + +## [1.4.0] - 2020-01-23 + +- Autoloader: Remove the ignored classes + +## [1.3.8] - 2020-01-14 + +- Trying to add deterministic initialization. +- Autoloader: Remove Manager_Interface and Plugin\Tracking from ignored list +- Autoloader: Remove Jetpack_IXR_Client from ignore list + +## [1.3.7] - 2019-12-10 + +## [1.3.6] - 2019-12-09 + +- Autoloader: Use long-form sytax for array + +## [1.3.5] - 2019-11-26 + +- Fix/php notice status + +## [1.3.4] - 2019-11-08 + +- Deprecate Jetpack::is_development_mode() in favor of the packaged Status()->is_development_mode() + +## [1.3.3] - 2019-10-28 + +- Packages: Add gitattributes files to all packages that need th… + +## [1.3.2] - 2019-09-24 + +- Autoloader: Cover scenarios where composer/autoload_files.php… + +## [1.3.1] - 2019-09-20 + +- Docs: Unify usage of @package phpdoc tags + +## [1.3.0] - 2019-09-14 + +- Fix for empty namespaces. #13459 +- Connection: Move the Jetpack IXR client to the package +- Adds full connection cycle capability to the Connection package. +- Jetpack 7.5: Back compatibility package + +## [1.2.0] - 2019-06-24 + +- Jetpack DNA: Add full classmap support to Autoloader +- Move Jetpack_Sync_Main from legacy to PSR-4 + +## [1.1.0] - 2019-06-19 + +- Packages: Move autoloader tests to the package +- DNA: Move Jetpack Usage tracking to its own file +- Jetpack DNA: More isolation of Tracks Package +- Autoloader: Ignore XMLRPC_Connector if called too early +- Autoloader: Ignore Jetpack_Signature if called too early + +## 1.0.0 - 2019-06-11 + +- Add Custom Autoloader + +[2.12.0]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.23...v2.12.0 +[2.11.23]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.22...v2.11.23 +[2.11.22]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.21...v2.11.22 +[2.11.21]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.20...v2.11.21 +[2.11.20]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.19...v2.11.20 +[2.11.19]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.18...v2.11.19 +[2.11.18]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.17...v2.11.18 +[2.11.17]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.16...v2.11.17 +[2.11.16]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.15...v2.11.16 +[2.11.15]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.14...v2.11.15 +[2.11.14]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.13...v2.11.14 +[2.11.13]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.12...v2.11.13 +[2.11.12]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.11...v2.11.12 +[2.11.11]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.10...v2.11.11 +[2.11.10]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.9...v2.11.10 +[2.11.9]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.8...v2.11.9 +[2.11.8]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.7...v2.11.8 +[2.11.7]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.6...v2.11.7 +[2.11.6]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.5...v2.11.6 +[2.11.5]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.4...v2.11.5 +[2.11.4]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.3...v2.11.4 +[2.11.3]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.2...v2.11.3 +[2.11.2]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.1...v2.11.2 +[2.11.1]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.0...v2.11.1 +[2.11.0]: https://github.com/Automattic/jetpack-autoloader/compare/v2.10.13...v2.11.0 +[2.10.13]: https://github.com/Automattic/jetpack-autoloader/compare/v2.10.12...v2.10.13 +[2.10.12]: https://github.com/Automattic/jetpack-autoloader/compare/v2.10.11...v2.10.12 +[2.10.11]: https://github.com/Automattic/jetpack-autoloader/compare/v2.10.10...v2.10.11 +[2.10.10]: https://github.com/Automattic/jetpack-autoloader/compare/v2.10.9...v2.10.10 +[2.10.9]: https://github.com/Automattic/jetpack-autoloader/compare/v2.10.8...v2.10.9 +[2.10.8]: https://github.com/Automattic/jetpack-autoloader/compare/v2.10.7...v2.10.8 +[2.10.7]: https://github.com/Automattic/jetpack-autoloader/compare/v2.10.6...v2.10.7 +[2.10.6]: https://github.com/Automattic/jetpack-autoloader/compare/v2.10.5...v2.10.6 +[2.10.5]: https://github.com/Automattic/jetpack-autoloader/compare/v2.10.4...v2.10.5 +[2.10.4]: https://github.com/Automattic/jetpack-autoloader/compare/v2.10.3...v2.10.4 +[2.10.3]: https://github.com/Automattic/jetpack-autoloader/compare/v2.10.2...v2.10.3 +[2.10.2]: https://github.com/Automattic/jetpack-autoloader/compare/v2.10.1...v2.10.2 +[2.10.1]: https://github.com/Automattic/jetpack-autoloader/compare/v2.10.0...v2.10.1 +[2.10.0]: https://github.com/Automattic/jetpack-autoloader/compare/v2.9.1...v2.10.0 +[2.9.1]: https://github.com/Automattic/jetpack-autoloader/compare/v2.9.0...v2.9.1 +[2.9.0]: https://github.com/Automattic/jetpack-autoloader/compare/v2.8.0...v2.9.0 +[2.8.0]: https://github.com/Automattic/jetpack-autoloader/compare/v2.7.1...v2.8.0 +[2.7.1]: https://github.com/Automattic/jetpack-autoloader/compare/v2.7.0...v2.7.1 +[2.7.0]: https://github.com/Automattic/jetpack-autoloader/compare/v2.6.0...v2.7.0 +[2.6.0]: https://github.com/Automattic/jetpack-autoloader/compare/v2.5.0...v2.6.0 +[2.5.0]: https://github.com/Automattic/jetpack-autoloader/compare/v2.4.0...v2.5.0 +[2.4.0]: https://github.com/Automattic/jetpack-autoloader/compare/v2.3.0...v2.4.0 +[2.3.0]: https://github.com/Automattic/jetpack-autoloader/compare/v2.2.0...v2.3.0 +[2.2.0]: https://github.com/Automattic/jetpack-autoloader/compare/v2.1.0...v2.2.0 +[2.1.0]: https://github.com/Automattic/jetpack-autoloader/compare/v2.0.2...v2.1.0 +[2.0.2]: https://github.com/Automattic/jetpack-autoloader/compare/v2.0.1...v2.0.2 +[2.0.1]: https://github.com/Automattic/jetpack-autoloader/compare/v2.0.0...v2.0.1 +[2.0.0]: https://github.com/Automattic/jetpack-autoloader/compare/v2.0.0-beta...v2.0.0 +[2.0.0-beta]: https://github.com/Automattic/jetpack-autoloader/compare/v1.7.0...v2.0.0-beta +[1.7.0]: https://github.com/Automattic/jetpack-autoloader/compare/v1.6.0...v1.7.0 +[1.6.0]: https://github.com/Automattic/jetpack-autoloader/compare/v1.5.0...v1.6.0 +[1.5.0]: https://github.com/Automattic/jetpack-autoloader/compare/v1.4.1...v1.5.0 +[1.4.1]: https://github.com/Automattic/jetpack-autoloader/compare/v1.4.0...v1.4.1 +[1.4.0]: https://github.com/Automattic/jetpack-autoloader/compare/v1.3.8...v1.4.0 +[1.3.8]: https://github.com/Automattic/jetpack-autoloader/compare/v1.3.7...v1.3.8 +[1.3.7]: https://github.com/Automattic/jetpack-autoloader/compare/v1.3.6...v1.3.7 +[1.3.6]: https://github.com/Automattic/jetpack-autoloader/compare/v1.3.5...v1.3.6 +[1.3.5]: https://github.com/Automattic/jetpack-autoloader/compare/v1.3.4...v1.3.5 +[1.3.4]: https://github.com/Automattic/jetpack-autoloader/compare/v1.3.3...v1.3.4 +[1.3.3]: https://github.com/Automattic/jetpack-autoloader/compare/v1.3.2...v1.3.3 +[1.3.2]: https://github.com/Automattic/jetpack-autoloader/compare/v1.3.1...v1.3.2 +[1.3.1]: https://github.com/Automattic/jetpack-autoloader/compare/v1.3.0...v1.3.1 +[1.3.0]: https://github.com/Automattic/jetpack-autoloader/compare/v1.2.0...v1.3.0 +[1.2.0]: https://github.com/Automattic/jetpack-autoloader/compare/v1.1.0...v1.2.0 +[1.1.0]: https://github.com/Automattic/jetpack-autoloader/compare/v1.0.0...v1.1.0 diff --git a/vendor/automattic/jetpack-autoloader/LICENSE.txt b/vendor/automattic/jetpack-autoloader/LICENSE.txt new file mode 100644 index 00000000000..e82774c1bd5 --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/LICENSE.txt @@ -0,0 +1,357 @@ +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +=================================== + + +GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + + Preamble + +The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + +We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + +Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and +modification follow. + +GNU GENERAL PUBLIC LICENSE +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + +a) You must cause the modified files to carry prominent notices +stating that you changed the files and the date of any change. + +b) You must cause any work that you distribute or publish, that in +whole or in part contains or is derived from the Program or any +part thereof, to be licensed as a whole at no charge to all third +parties under the terms of this License. + +c) If the modified program normally reads commands interactively +when run, you must cause it, when started running for such +interactive use in the most ordinary way, to print or display an +announcement including an appropriate copyright notice and a +notice that there is no warranty (or else, saying that you provide +a warranty) and that users may redistribute the program under +these conditions, and telling the user how to view a copy of this +License. (Exception: if the Program itself is interactive but +does not normally print such an announcement, your work based on +the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + +a) Accompany it with the complete corresponding machine-readable +source code, which must be distributed under the terms of Sections +1 and 2 above on a medium customarily used for software interchange; or, + +b) Accompany it with a written offer, valid for at least three +years, to give any third party, for a charge no more than your +cost of physically performing source distribution, a complete +machine-readable copy of the corresponding source code, to be +distributed under the terms of Sections 1 and 2 above on a medium +customarily used for software interchange; or, + +c) Accompany it with the information you received as to the offer +to distribute corresponding source code. (This alternative is +allowed only for noncommercial distribution and only if you +received the program in object code or executable form with such +an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + +5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + +7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + +10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + +Copyright (C) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + +Gnomovision version 69, Copyright (C) year name of author +Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. +This is free software, and you are welcome to redistribute it +under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in the program +`Gnomovision' (which makes passes at compilers) written by James Hacker. + +, 1 April 1989 +Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/vendor/automattic/jetpack-autoloader/README.md b/vendor/automattic/jetpack-autoloader/README.md new file mode 100644 index 00000000000..a064cb9ff60 --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/README.md @@ -0,0 +1,75 @@ +A custom autoloader for Composer +===================================== + +This is a custom autoloader generator that uses a classmap to always load the latest version of a class. + +The problem this autoloader is trying to solve is conflicts that arise when two or more plugins use the same package, but one of the plugins uses an older version of said package. + +This is solved by keeping an in memory map of all the different classes that can be loaded, and updating the map with the path to the latest version of the package for the autoloader to find when we instantiate the class. + +It diverges from the default Composer autoloader setup in the following ways: + +* It creates `jetpack_autoload_classmap.php` and `jetpack_autoload_filemap.php` files in the `vendor/composer` directory. +* This file includes the version numbers from each package that is used. +* The autoloader will only load the latest version of the package no matter what plugin loads the package. This behavior is guaranteed only when every plugin that uses the package uses this autoloader. If any plugin that requires the package uses a different autoloader, this autoloader may not be able to control which version of the package is loaded. + +Usage +----- + +In your project's `composer.json`, add the following lines: + +```json +{ + "require": { + "automattic/jetpack-autoloader": "^2" + } +} +``` + +Your project must use the default composer vendor directory, `vendor`. + +After the next update/install, you will have a `vendor/autoload_packages.php` file. +Load the file in your plugin via main plugin file. + +In the main plugin you will also need to include the files like this. +```php +require_once plugin_dir_path( __FILE__ ) . '/vendor/autoload_packages.php'; +``` + +Working with Development Versions of Packages +----- + +The autoloader will attempt to use the package with the latest semantic version. + +During development, you can force the autoloader to use development package versions by setting the `JETPACK_AUTOLOAD_DEV` constant to true. When `JETPACK_AUTOLOAD_DEV` is true, the autoloader will prefer the following versions over semantic versions: + - `9999999-dev` + - Versions with a `dev-` prefix. + + +Autoloading Standards +---- + +All new Jetpack package development should use classmap autoloading, which allows the class and file names to comply with the WordPress Coding Standards. + +### Optimized Autoloader + +An optimized autoloader is generated when: + * `composer install` or `composer update` is called with `-o` or `--optimize-autoloader` + * `composer dump-autoload` is called with `-o` or `--optimize` + +PSR-4 and PSR-0 namespaces are converted to classmaps. + +### Unoptimized Autoloader + +Supports PSR-4 autoloading. PSR-0 namespaces are converted to classmaps. + + +Autoloader Limitations +----- + +Plugin Updates + +When moving a package class file, renaming a package class file, or changing a package class namespace, make sure that the class will not be loaded after a plugin update. + +The autoloader builds the in memory classmap as soon as the autoloader is loaded. The package class file paths in the map are not updated after a plugin update. If a plugins's package class files are moved during a plugin update and a moved file is autoloaded after the update, an error will occur. + diff --git a/vendor/automattic/jetpack-autoloader/SECURITY.md b/vendor/automattic/jetpack-autoloader/SECURITY.md new file mode 100644 index 00000000000..b4b46c0ee23 --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/SECURITY.md @@ -0,0 +1,38 @@ +# Security Policy + +Full details of the Automattic Security Policy can be found on [automattic.com](https://automattic.com/security/). + +## Supported Versions + +Generally, only the latest version of Jetpack has continued support. If a critical vulnerability is found in the current version of Jetpack, we may opt to backport any patches to previous versions. + +## Reporting a Vulnerability + +[Jetpack](https://jetpack.com/) is an open-source plugin for WordPress. Our HackerOne program covers the plugin software, as well as a variety of related projects and infrastructure. + +**For responsible disclosure of security issues and to be eligible for our bug bounty program, please submit your report via the [HackerOne](https://hackerone.com/automattic) portal.** + +Our most critical targets are: + +* Jetpack and the Jetpack composer packages (all within this repo) +* Jetpack.com -- the primary marketing site. +* cloud.jetpack.com -- a management site. +* wordpress.com -- the shared management site for both Jetpack and WordPress.com sites. + +For more targets, see the `In Scope` section on [HackerOne](https://hackerone.com/automattic). + +_Please note that the **WordPress software is a separate entity** from Automattic. Please report vulnerabilities for WordPress through [the WordPress Foundation's HackerOne page](https://hackerone.com/wordpress)._ + +## Guidelines + +We're committed to working with security researchers to resolve the vulnerabilities they discover. You can help us by following these guidelines: + +* Follow [HackerOne's disclosure guidelines](https://www.hackerone.com/disclosure-guidelines). +* Pen-testing Production: + * Please **setup a local environment** instead whenever possible. Most of our code is open source (see above). + * If that's not possible, **limit any data access/modification** to the bare minimum necessary to reproduce a PoC. + * **_Don't_ automate form submissions!** That's very annoying for us, because it adds extra work for the volunteers who manage those systems, and reduces the signal/noise ratio in our communication channels. + * To be eligible for a bounty, all of these guidelines must be followed. +* Be Patient - Give us a reasonable time to correct the issue before you disclose the vulnerability. + +We also expect you to comply with all applicable laws. You're responsible to pay any taxes associated with your bounties. diff --git a/vendor/automattic/jetpack-autoloader/composer.json b/vendor/automattic/jetpack-autoloader/composer.json new file mode 100644 index 00000000000..ff497f38da1 --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/composer.json @@ -0,0 +1,53 @@ +{ + "name": "automattic/jetpack-autoloader", + "description": "Creates a custom autoloader for a plugin or theme.", + "type": "composer-plugin", + "license": "GPL-2.0-or-later", + "keywords": [ + "autoload", + "autoloader", + "composer", + "plugin", + "jetpack", + "wordpress" + ], + "require": { + "composer-plugin-api": "^1.1 || ^2.0" + }, + "require-dev": { + "yoast/phpunit-polyfills": "1.1.0", + "automattic/jetpack-changelogger": "^3.3.11" + }, + "autoload": { + "classmap": [ + "src/AutoloadGenerator.php" + ], + "psr-4": { + "Automattic\\Jetpack\\Autoloader\\": "src" + } + }, + "scripts": { + "phpunit": [ + "./vendor/phpunit/phpunit/phpunit --colors=always" + ], + "test-php": [ + "@composer phpunit" + ] + }, + "minimum-stability": "dev", + "prefer-stable": true, + "extra": { + "autotagger": true, + "class": "Automattic\\Jetpack\\Autoloader\\CustomAutoloaderPlugin", + "mirror-repo": "Automattic/jetpack-autoloader", + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-autoloader/compare/v${old}...v${new}" + }, + "version-constants": { + "::VERSION": "src/AutoloadGenerator.php" + }, + "branch-alias": { + "dev-trunk": "2.12.x-dev" + } + } +} diff --git a/vendor/automattic/jetpack-autoloader/src/AutoloadFileWriter.php b/vendor/automattic/jetpack-autoloader/src/AutoloadFileWriter.php new file mode 100644 index 00000000000..9a27a53e6ee --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/src/AutoloadFileWriter.php @@ -0,0 +1,99 @@ + '../autoload_packages.php', + ); + $ignoreList = array( + 'AutoloadGenerator.php', + 'AutoloadProcessor.php', + 'CustomAutoloaderPlugin.php', + 'ManifestGenerator.php', + 'AutoloadFileWriter.php', + ); + + // Copy all of the autoloader files. + $files = scandir( __DIR__ ); + foreach ( $files as $file ) { + // Only PHP files will be copied. + if ( substr( $file, -4 ) !== '.php' ) { + continue; + } + + if ( in_array( $file, $ignoreList, true ) ) { + continue; + } + + $newFile = isset( $renameList[ $file ] ) ? $renameList[ $file ] : $file; + $content = self::prepareAutoloaderFile( $file, $suffix ); + + $written = file_put_contents( $outDir . '/' . $newFile, $content ); + if ( $io ) { + if ( $written ) { + $io->writeError( " Generated: $newFile" ); + } else { + $io->writeError( " Error: $newFile" ); + } + } + } + } + + /** + * Prepares an autoloader file to be written to the destination. + * + * @param String $filename a file to prepare. + * @param String $suffix Unique suffix used in the namespace. + * + * @return string + */ + private static function prepareAutoloaderFile( $filename, $suffix ) { + $header = self::COMMENT; + $header .= PHP_EOL; + if ( $suffix === 'Current' ) { + // Unit testing. + $header .= 'namespace Automattic\Jetpack\Autoloader\jpCurrent;'; + } else { + $header .= 'namespace Automattic\Jetpack\Autoloader\jp' . $suffix . '\al' . preg_replace( '/[^0-9a-zA-Z]/', '_', AutoloadGenerator::VERSION ) . ';'; + } + $header .= PHP_EOL . PHP_EOL; + + $sourceLoader = fopen( __DIR__ . '/' . $filename, 'r' ); + $file_contents = stream_get_contents( $sourceLoader ); + return str_replace( + '/* HEADER */', + $header, + $file_contents + ); + } +} diff --git a/vendor/automattic/jetpack-autoloader/src/AutoloadGenerator.php b/vendor/automattic/jetpack-autoloader/src/AutoloadGenerator.php new file mode 100644 index 00000000000..f89e2443cc5 --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/src/AutoloadGenerator.php @@ -0,0 +1,403 @@ +io = $io; + $this->filesystem = new Filesystem(); + } + + /** + * Dump the Jetpack autoloader files. + * + * @param Composer $composer The Composer object. + * @param Config $config Config object. + * @param InstalledRepositoryInterface $localRepo Installed Repository object. + * @param PackageInterface $mainPackage Main Package object. + * @param InstallationManager $installationManager Manager for installing packages. + * @param string $targetDir Path to the current target directory. + * @param bool $scanPsrPackages Whether or not PSR packages should be converted to a classmap. + * @param string $suffix The autoloader suffix. + */ + public function dump( + Composer $composer, + Config $config, + InstalledRepositoryInterface $localRepo, + PackageInterface $mainPackage, + InstallationManager $installationManager, + $targetDir, + $scanPsrPackages = false, + $suffix = null + ) { + $this->filesystem->ensureDirectoryExists( $config->get( 'vendor-dir' ) ); + + $packageMap = $composer->getAutoloadGenerator()->buildPackageMap( $installationManager, $mainPackage, $localRepo->getCanonicalPackages() ); + $autoloads = $this->parseAutoloads( $packageMap, $mainPackage ); + + // Convert the autoloads into a format that the manifest generator can consume more easily. + $basePath = $this->filesystem->normalizePath( realpath( getcwd() ) ); + $vendorPath = $this->filesystem->normalizePath( realpath( $config->get( 'vendor-dir' ) ) ); + $processedAutoloads = $this->processAutoloads( $autoloads, $scanPsrPackages, $vendorPath, $basePath ); + unset( $packageMap, $autoloads ); + + // Make sure none of the legacy files remain that can lead to problems with the autoloader. + $this->removeLegacyFiles( $vendorPath ); + + // Write all of the files now that we're done. + $this->writeAutoloaderFiles( $vendorPath . '/jetpack-autoloader/', $suffix ); + $this->writeManifests( $vendorPath . '/' . $targetDir, $processedAutoloads ); + + if ( ! $scanPsrPackages ) { + $this->io->writeError( 'You are generating an unoptimized autoloader. If this is a production build, consider using the -o option.' ); + } + } + + /** + * Compiles an ordered list of namespace => path mappings + * + * @param array $packageMap Array of array(package, installDir-relative-to-composer.json). + * @param PackageInterface $mainPackage Main package instance. + * + * @return array The list of path mappings. + */ + public function parseAutoloads( array $packageMap, PackageInterface $mainPackage ) { + $rootPackageMap = array_shift( $packageMap ); + + $sortedPackageMap = $this->sortPackageMap( $packageMap ); + $sortedPackageMap[] = $rootPackageMap; + array_unshift( $packageMap, $rootPackageMap ); + + $psr0 = $this->parseAutoloadsType( $packageMap, 'psr-0', $mainPackage ); + $psr4 = $this->parseAutoloadsType( $packageMap, 'psr-4', $mainPackage ); + $classmap = $this->parseAutoloadsType( array_reverse( $sortedPackageMap ), 'classmap', $mainPackage ); + $files = $this->parseAutoloadsType( $sortedPackageMap, 'files', $mainPackage ); + + krsort( $psr0 ); + krsort( $psr4 ); + + return array( + 'psr-0' => $psr0, + 'psr-4' => $psr4, + 'classmap' => $classmap, + 'files' => $files, + ); + } + + /** + * Sorts packages by dependency weight + * + * Packages of equal weight retain the original order + * + * @param array $packageMap The package map. + * + * @return array + */ + protected function sortPackageMap( array $packageMap ) { + $packages = array(); + $paths = array(); + + foreach ( $packageMap as $item ) { + list( $package, $path ) = $item; + $name = $package->getName(); + $packages[ $name ] = $package; + $paths[ $name ] = $path; + } + + $sortedPackages = PackageSorter::sortPackages( $packages ); + + $sortedPackageMap = array(); + + foreach ( $sortedPackages as $package ) { + $name = $package->getName(); + $sortedPackageMap[] = array( $packages[ $name ], $paths[ $name ] ); + } + + return $sortedPackageMap; + } + + /** + * Returns the file identifier. + * + * @param PackageInterface $package The package instance. + * @param string $path The path. + */ + protected function getFileIdentifier( PackageInterface $package, $path ) { + return md5( $package->getName() . ':' . $path ); + } + + /** + * Returns the path code for the given path. + * + * @param Filesystem $filesystem The filesystem instance. + * @param string $basePath The base path. + * @param string $vendorPath The vendor path. + * @param string $path The path. + * + * @return string The path code. + */ + protected function getPathCode( Filesystem $filesystem, $basePath, $vendorPath, $path ) { + if ( ! $filesystem->isAbsolutePath( $path ) ) { + $path = $basePath . '/' . $path; + } + $path = $filesystem->normalizePath( $path ); + + $baseDir = ''; + if ( 0 === strpos( $path . '/', $vendorPath . '/' ) ) { + $path = substr( $path, strlen( $vendorPath ) ); + $baseDir = '$vendorDir'; + + if ( false !== $path ) { + $baseDir .= ' . '; + } + } else { + $path = $filesystem->normalizePath( $filesystem->findShortestPath( $basePath, $path, true ) ); + if ( ! $filesystem->isAbsolutePath( $path ) ) { + $baseDir = '$baseDir . '; + $path = '/' . $path; + } + } + + if ( strpos( $path, '.phar' ) !== false ) { + $baseDir = "'phar://' . " . $baseDir; + } + + // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export + return $baseDir . ( ( false !== $path ) ? var_export( $path, true ) : '' ); + } + + /** + * This function differs from the composer parseAutoloadsType in that beside returning the path. + * It also return the path and the version of a package. + * + * Supports PSR-4, PSR-0, and classmap parsing. + * + * @param array $packageMap Map of all the packages. + * @param string $type Type of autoloader to use. + * @param PackageInterface $mainPackage Instance of the Package Object. + * + * @return array + */ + protected function parseAutoloadsType( array $packageMap, $type, PackageInterface $mainPackage ) { + $autoloads = array(); + + foreach ( $packageMap as $item ) { + list($package, $installPath) = $item; + $autoload = $package->getAutoload(); + $version = $package->getVersion(); // Version of the class comes from the package - should we try to parse it? + + // Store our own actual package version, not "dev-trunk" or whatever. + if ( $package->getName() === 'automattic/jetpack-autoloader' ) { + $version = self::VERSION; + } + + if ( $package === $mainPackage ) { + $autoload = array_merge_recursive( $autoload, $package->getDevAutoload() ); + } + + if ( null !== $package->getTargetDir() && $package !== $mainPackage ) { + $installPath = substr( $installPath, 0, -strlen( '/' . $package->getTargetDir() ) ); + } + + if ( in_array( $type, array( 'psr-4', 'psr-0' ), true ) && isset( $autoload[ $type ] ) && is_array( $autoload[ $type ] ) ) { + foreach ( $autoload[ $type ] as $namespace => $paths ) { + $paths = is_array( $paths ) ? $paths : array( $paths ); + foreach ( $paths as $path ) { + $relativePath = empty( $installPath ) ? ( empty( $path ) ? '.' : $path ) : $installPath . '/' . $path; + $autoloads[ $namespace ][] = array( + 'path' => $relativePath, + 'version' => $version, + ); + } + } + } + + if ( 'classmap' === $type && isset( $autoload['classmap'] ) && is_array( $autoload['classmap'] ) ) { + foreach ( $autoload['classmap'] as $paths ) { + $paths = is_array( $paths ) ? $paths : array( $paths ); + foreach ( $paths as $path ) { + $relativePath = empty( $installPath ) ? ( empty( $path ) ? '.' : $path ) : $installPath . '/' . $path; + $autoloads[] = array( + 'path' => $relativePath, + 'version' => $version, + ); + } + } + } + if ( 'files' === $type && isset( $autoload['files'] ) && is_array( $autoload['files'] ) ) { + foreach ( $autoload['files'] as $paths ) { + $paths = is_array( $paths ) ? $paths : array( $paths ); + foreach ( $paths as $path ) { + $relativePath = empty( $installPath ) ? ( empty( $path ) ? '.' : $path ) : $installPath . '/' . $path; + $autoloads[ $this->getFileIdentifier( $package, $path ) ] = array( + 'path' => $relativePath, + 'version' => $version, + ); + } + } + } + } + + return $autoloads; + } + + /** + * Given Composer's autoloads this will convert them to a version that we can use to generate the manifests. + * + * When the $scanPsrPackages argument is true, PSR-4 namespaces are converted to classmaps. When $scanPsrPackages + * is false, PSR-4 namespaces are not converted to classmaps. + * + * PSR-0 namespaces are always converted to classmaps. + * + * @param array $autoloads The autoloads we want to process. + * @param bool $scanPsrPackages Whether or not PSR-4 packages should be converted to a classmap. + * @param string $vendorPath The path to the vendor directory. + * @param string $basePath The path to the current directory. + * + * @return array $processedAutoloads + */ + private function processAutoloads( $autoloads, $scanPsrPackages, $vendorPath, $basePath ) { + $processor = new AutoloadProcessor( + function ( $path, $excludedClasses, $namespace ) use ( $basePath ) { + $dir = $this->filesystem->normalizePath( + $this->filesystem->isAbsolutePath( $path ) ? $path : $basePath . '/' . $path + ); + + // Composer 2.4 changed the name of the class. + if ( class_exists( \Composer\ClassMapGenerator\ClassMapGenerator::class ) ) { + if ( ! is_dir( $dir ) && ! is_file( $dir ) ) { + return array(); + } + $generator = new \Composer\ClassMapGenerator\ClassMapGenerator(); + $generator->scanPaths( $dir, $excludedClasses, 'classmap', empty( $namespace ) ? null : $namespace ); + return $generator->getClassMap()->getMap(); + } + + return \Composer\Autoload\ClassMapGenerator::createMap( + $dir, + $excludedClasses, + null, // Don't pass the IOInterface since the normal autoload generation will have reported already. + empty( $namespace ) ? null : $namespace + ); + }, + function ( $path ) use ( $basePath, $vendorPath ) { + return $this->getPathCode( $this->filesystem, $basePath, $vendorPath, $path ); + } + ); + + return array( + 'psr-4' => $processor->processPsr4Packages( $autoloads, $scanPsrPackages ), + 'classmap' => $processor->processClassmap( $autoloads, $scanPsrPackages ), + 'files' => $processor->processFiles( $autoloads ), + ); + } + + /** + * Removes all of the legacy autoloader files so they don't cause any problems. + * + * @param string $outDir The directory legacy files are written to. + */ + private function removeLegacyFiles( $outDir ) { + $files = array( + 'autoload_functions.php', + 'class-autoloader-handler.php', + 'class-classes-handler.php', + 'class-files-handler.php', + 'class-plugins-handler.php', + 'class-version-selector.php', + ); + foreach ( $files as $file ) { + $this->filesystem->remove( $outDir . '/' . $file ); + } + } + + /** + * Writes all of the autoloader files to disk. + * + * @param string $outDir The directory to write to. + * @param string $suffix The unique autoloader suffix. + */ + private function writeAutoloaderFiles( $outDir, $suffix ) { + $this->io->writeError( "Generating jetpack autoloader ($outDir)" ); + + // We will remove all autoloader files to generate this again. + $this->filesystem->emptyDirectory( $outDir ); + + // Write the autoloader files. + AutoloadFileWriter::copyAutoloaderFiles( $this->io, $outDir, $suffix ); + } + + /** + * Writes all of the manifest files to disk. + * + * @param string $outDir The directory to write to. + * @param array $processedAutoloads The processed autoloads. + */ + private function writeManifests( $outDir, $processedAutoloads ) { + $this->io->writeError( "Generating jetpack autoloader manifests ($outDir)" ); + + $manifestFiles = array( + 'classmap' => 'jetpack_autoload_classmap.php', + 'psr-4' => 'jetpack_autoload_psr4.php', + 'files' => 'jetpack_autoload_filemap.php', + ); + + foreach ( $manifestFiles as $key => $file ) { + // Make sure the file doesn't exist so it isn't there if we don't write it. + $this->filesystem->remove( $outDir . '/' . $file ); + if ( empty( $processedAutoloads[ $key ] ) ) { + continue; + } + + $content = ManifestGenerator::buildManifest( $key, $file, $processedAutoloads[ $key ] ); + if ( empty( $content ) ) { + continue; + } + + if ( file_put_contents( $outDir . '/' . $file, $content ) ) { + $this->io->writeError( " Generated: $file" ); + } else { + $this->io->writeError( " Error: $file" ); + } + } + } +} diff --git a/vendor/automattic/jetpack-autoloader/src/AutoloadProcessor.php b/vendor/automattic/jetpack-autoloader/src/AutoloadProcessor.php new file mode 100644 index 00000000000..3d2134b75fc --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/src/AutoloadProcessor.php @@ -0,0 +1,175 @@ +classmapScanner = $classmapScanner; + $this->pathCodeTransformer = $pathCodeTransformer; + } + + /** + * Processes the classmap autoloads into a relative path format including the version for each file. + * + * @param array $autoloads The autoloads we are processing. + * @param bool $scanPsrPackages Whether or not PSR packages should be converted to a classmap. + * + * @return array $processed + */ + public function processClassmap( $autoloads, $scanPsrPackages ) { + // We can't scan PSR packages if we don't actually have any. + if ( empty( $autoloads['psr-4'] ) ) { + $scanPsrPackages = false; + } + + if ( empty( $autoloads['classmap'] ) && ! $scanPsrPackages ) { + return null; + } + + $excludedClasses = null; + if ( ! empty( $autoloads['exclude-from-classmap'] ) ) { + $excludedClasses = '{(' . implode( '|', $autoloads['exclude-from-classmap'] ) . ')}'; + } + + $processed = array(); + + if ( $scanPsrPackages ) { + foreach ( $autoloads['psr-4'] as $namespace => $sources ) { + $namespace = empty( $namespace ) ? null : $namespace; + + foreach ( $sources as $source ) { + $classmap = call_user_func( $this->classmapScanner, $source['path'], $excludedClasses, $namespace ); + + foreach ( $classmap as $class => $path ) { + $processed[ $class ] = array( + 'version' => $source['version'], + 'path' => call_user_func( $this->pathCodeTransformer, $path ), + ); + } + } + } + } + + /* + * PSR-0 namespaces are converted to classmaps for both optimized and unoptimized autoloaders because any new + * development should use classmap or PSR-4 autoloading. + */ + if ( ! empty( $autoloads['psr-0'] ) ) { + foreach ( $autoloads['psr-0'] as $namespace => $sources ) { + $namespace = empty( $namespace ) ? null : $namespace; + + foreach ( $sources as $source ) { + $classmap = call_user_func( $this->classmapScanner, $source['path'], $excludedClasses, $namespace ); + foreach ( $classmap as $class => $path ) { + $processed[ $class ] = array( + 'version' => $source['version'], + 'path' => call_user_func( $this->pathCodeTransformer, $path ), + ); + } + } + } + } + + if ( ! empty( $autoloads['classmap'] ) ) { + foreach ( $autoloads['classmap'] as $package ) { + $classmap = call_user_func( $this->classmapScanner, $package['path'], $excludedClasses, null ); + + foreach ( $classmap as $class => $path ) { + $processed[ $class ] = array( + 'version' => $package['version'], + 'path' => call_user_func( $this->pathCodeTransformer, $path ), + ); + } + } + } + + ksort( $processed ); + + return $processed; + } + + /** + * Processes the PSR-4 autoloads into a relative path format including the version for each file. + * + * @param array $autoloads The autoloads we are processing. + * @param bool $scanPsrPackages Whether or not PSR packages should be converted to a classmap. + * + * @return array $processed + */ + public function processPsr4Packages( $autoloads, $scanPsrPackages ) { + if ( $scanPsrPackages || empty( $autoloads['psr-4'] ) ) { + return null; + } + + $processed = array(); + + foreach ( $autoloads['psr-4'] as $namespace => $packages ) { + $namespace = empty( $namespace ) ? null : $namespace; + $paths = array(); + + foreach ( $packages as $package ) { + $paths[] = call_user_func( $this->pathCodeTransformer, $package['path'] ); + } + + $processed[ $namespace ] = array( + 'version' => $package['version'], + 'path' => $paths, + ); + } + + return $processed; + } + + /** + * Processes the file autoloads into a relative format including the version for each file. + * + * @param array $autoloads The autoloads we are processing. + * + * @return array|null $processed + */ + public function processFiles( $autoloads ) { + if ( empty( $autoloads['files'] ) ) { + return null; + } + + $processed = array(); + + foreach ( $autoloads['files'] as $file_id => $package ) { + $processed[ $file_id ] = array( + 'version' => $package['version'], + 'path' => call_user_func( $this->pathCodeTransformer, $package['path'] ), + ); + } + + return $processed; + } +} diff --git a/vendor/automattic/jetpack-autoloader/src/CustomAutoloaderPlugin.php b/vendor/automattic/jetpack-autoloader/src/CustomAutoloaderPlugin.php new file mode 100644 index 00000000000..a3f0dbf7b71 --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/src/CustomAutoloaderPlugin.php @@ -0,0 +1,188 @@ +composer = $composer; + $this->io = $io; + } + + /** + * Do nothing. + * phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + * + * @param Composer $composer Composer object. + * @param IOInterface $io IO object. + */ + public function deactivate( Composer $composer, IOInterface $io ) { + /* + * Intentionally left empty. This is a PluginInterface method. + * phpcs:enable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + */ + } + + /** + * Do nothing. + * phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + * + * @param Composer $composer Composer object. + * @param IOInterface $io IO object. + */ + public function uninstall( Composer $composer, IOInterface $io ) { + /* + * Intentionally left empty. This is a PluginInterface method. + * phpcs:enable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + */ + } + + /** + * Tell composer to listen for events and do something with them. + * + * @return array List of subscribed events. + */ + public static function getSubscribedEvents() { + return array( + ScriptEvents::POST_AUTOLOAD_DUMP => 'postAutoloadDump', + ); + } + + /** + * Generate the custom autolaoder. + * + * @param Event $event Script event object. + */ + public function postAutoloadDump( Event $event ) { + // When the autoloader is not required by the root package we don't want to execute it. + // This prevents unwanted transitive execution that generates unused autoloaders or + // at worst throws fatal executions. + if ( ! $this->isRequiredByRoot() ) { + return; + } + + $config = $this->composer->getConfig(); + + if ( 'vendor' !== $config->raw()['config']['vendor-dir'] ) { + $this->io->writeError( "\nAn error occurred while generating the autoloader files:", true ); + $this->io->writeError( 'The project\'s composer.json or composer environment set a non-default vendor directory.', true ); + $this->io->writeError( 'The default composer vendor directory must be used.', true ); + exit(); + } + + $installationManager = $this->composer->getInstallationManager(); + $repoManager = $this->composer->getRepositoryManager(); + $localRepo = $repoManager->getLocalRepository(); + $package = $this->composer->getPackage(); + $optimize = $event->getFlags()['optimize']; + $suffix = $this->determineSuffix(); + + $generator = new AutoloadGenerator( $this->io ); + $generator->dump( $this->composer, $config, $localRepo, $package, $installationManager, 'composer', $optimize, $suffix ); + } + + /** + * Determine the suffix for the autoloader class. + * + * Reuses an existing suffix from vendor/autoload_packages.php or vendor/autoload.php if possible. + * + * @return string Suffix. + */ + private function determineSuffix() { + $config = $this->composer->getConfig(); + $vendorPath = $config->get( 'vendor-dir' ); + + // Command line. + $suffix = $config->get( 'autoloader-suffix' ); + if ( $suffix ) { + return $suffix; + } + + // Reuse our own suffix, if any. + if ( is_readable( $vendorPath . '/autoload_packages.php' ) ) { + $content = file_get_contents( $vendorPath . '/autoload_packages.php' ); + if ( preg_match( '/^namespace Automattic\\\\Jetpack\\\\Autoloader\\\\jp([^;\s]+?)(?:\\\\al[^;\s]+)?;/m', $content, $match ) ) { + return $match[1]; + } + } + + // Reuse Composer's suffix, if any. + if ( is_readable( $vendorPath . '/autoload.php' ) ) { + $content = file_get_contents( $vendorPath . '/autoload.php' ); + if ( preg_match( '{ComposerAutoloaderInit([^:\s]+)::}', $content, $match ) ) { + return $match[1]; + } + } + + // Generate a random suffix. + return md5( uniqid( '', true ) ); + } + + /** + * Checks to see whether or not the root package is the one that required the autoloader. + * + * @return bool + */ + private function isRequiredByRoot() { + $package = $this->composer->getPackage(); + $requires = $package->getRequires(); + if ( ! is_array( $requires ) ) { + $requires = array(); + } + $devRequires = $package->getDevRequires(); + if ( ! is_array( $devRequires ) ) { + $devRequires = array(); + } + $requires = array_merge( $requires, $devRequires ); + + if ( empty( $requires ) ) { + $this->io->writeError( "\nThe package is not required and this should never happen?", true ); + exit(); + } + + foreach ( $requires as $require ) { + if ( 'automattic/jetpack-autoloader' === $require->getTarget() ) { + return true; + } + } + + return false; + } +} diff --git a/vendor/automattic/jetpack-autoloader/src/ManifestGenerator.php b/vendor/automattic/jetpack-autoloader/src/ManifestGenerator.php new file mode 100644 index 00000000000..254d46a5919 --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/src/ManifestGenerator.php @@ -0,0 +1,115 @@ + $data ) { + $key = var_export( $key, true ); + $versionCode = var_export( $data['version'], true ); + $fileContent .= << array( + 'version' => $versionCode, + 'path' => {$data['path']} + ), +MANIFEST_CODE; + $fileContent .= PHP_EOL; + } + + return self::buildFile( $fileName, $fileContent ); + } + + /** + * Builds the contents for the PSR-4 manifest file. + * + * @param string $fileName The filename we are building. + * @param array $namespaces The formatted PSR-4 data for the manifest. + * + * @return string|null $manifestFile + */ + private static function buildPsr4Manifest( $fileName, $namespaces ) { + $fileContent = PHP_EOL; + foreach ( $namespaces as $namespace => $data ) { + $namespaceCode = var_export( $namespace, true ); + $versionCode = var_export( $data['version'], true ); + $pathCode = 'array( ' . implode( ', ', $data['path'] ) . ' )'; + $fileContent .= << array( + 'version' => $versionCode, + 'path' => $pathCode + ), +MANIFEST_CODE; + $fileContent .= PHP_EOL; + } + + return self::buildFile( $fileName, $fileContent ); + } + + /** + * Generate the PHP that will be used in the file. + * + * @param string $fileName The filename we are building. + * @param string $content The content to be written into the file. + * + * @return string $fileContent + */ + private static function buildFile( $fileName, $content ) { + return <<php_autoloader = $php_autoloader; + $this->hook_manager = $hook_manager; + $this->manifest_reader = $manifest_reader; + $this->version_selector = $version_selector; + } + + /** + * Checks to see whether or not an autoloader is currently in the process of initializing. + * + * @return bool + */ + public function is_initializing() { + // If no version has been set it means that no autoloader has started initializing yet. + global $jetpack_autoloader_latest_version; + if ( ! isset( $jetpack_autoloader_latest_version ) ) { + return false; + } + + // When the version is set but the classmap is not it ALWAYS means that this is the + // latest autoloader and is being included by an older one. + global $jetpack_packages_classmap; + if ( empty( $jetpack_packages_classmap ) ) { + return true; + } + + // Version 2.4.0 added a new global and altered the reset semantics. We need to check + // the other global as well since it may also point at initialization. + // Note: We don't need to check for the class first because every autoloader that + // will set the latest version global requires this class in the classmap. + $replacing_version = $jetpack_packages_classmap[ AutoloadGenerator::class ]['version']; + if ( $this->version_selector->is_dev_version( $replacing_version ) || version_compare( $replacing_version, '2.4.0.0', '>=' ) ) { + global $jetpack_autoloader_loader; + if ( ! isset( $jetpack_autoloader_loader ) ) { + return true; + } + } + + return false; + } + + /** + * Activates an autoloader using the given plugins and activates it. + * + * @param string[] $plugins The plugins to initialize the autoloader for. + */ + public function activate_autoloader( $plugins ) { + global $jetpack_packages_psr4; + $jetpack_packages_psr4 = array(); + $this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_psr4.php', $jetpack_packages_psr4 ); + + global $jetpack_packages_classmap; + $jetpack_packages_classmap = array(); + $this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_classmap.php', $jetpack_packages_classmap ); + + global $jetpack_packages_filemap; + $jetpack_packages_filemap = array(); + $this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_filemap.php', $jetpack_packages_filemap ); + + $loader = new Version_Loader( + $this->version_selector, + $jetpack_packages_classmap, + $jetpack_packages_psr4, + $jetpack_packages_filemap + ); + + $this->php_autoloader->register_autoloader( $loader ); + + // Now that the autoloader is active we can load the filemap. + $loader->load_filemap(); + } + + /** + * Resets the active autoloader and all related global state. + */ + public function reset_autoloader() { + $this->php_autoloader->unregister_autoloader(); + $this->hook_manager->reset(); + + // Clear all of the autoloader globals so that older autoloaders don't do anything strange. + global $jetpack_autoloader_latest_version; + $jetpack_autoloader_latest_version = null; + + global $jetpack_packages_classmap; + $jetpack_packages_classmap = array(); // Must be array to avoid exceptions in old autoloaders! + + global $jetpack_packages_psr4; + $jetpack_packages_psr4 = array(); // Must be array to avoid exceptions in old autoloaders! + + global $jetpack_packages_filemap; + $jetpack_packages_filemap = array(); // Must be array to avoid exceptions in old autoloaders! + } +} diff --git a/vendor/automattic/jetpack-autoloader/src/class-autoloader-locator.php b/vendor/automattic/jetpack-autoloader/src/class-autoloader-locator.php new file mode 100644 index 00000000000..828fe25b9e6 --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/src/class-autoloader-locator.php @@ -0,0 +1,82 @@ +version_selector = $version_selector; + } + + /** + * Finds the path to the plugin with the latest autoloader. + * + * @param array $plugin_paths An array of plugin paths. + * @param string $latest_version The latest version reference. + * + * @return string|null + */ + public function find_latest_autoloader( $plugin_paths, &$latest_version ) { + $latest_plugin = null; + + foreach ( $plugin_paths as $plugin_path ) { + $version = $this->get_autoloader_version( $plugin_path ); + if ( ! $this->version_selector->is_version_update_required( $latest_version, $version ) ) { + continue; + } + + $latest_version = $version; + $latest_plugin = $plugin_path; + } + + return $latest_plugin; + } + + /** + * Gets the path to the autoloader. + * + * @param string $plugin_path The path to the plugin. + * + * @return string + */ + public function get_autoloader_path( $plugin_path ) { + return trailingslashit( $plugin_path ) . 'vendor/autoload_packages.php'; + } + + /** + * Gets the version for the autoloader. + * + * @param string $plugin_path The path to the plugin. + * + * @return string|null + */ + public function get_autoloader_version( $plugin_path ) { + $classmap = trailingslashit( $plugin_path ) . 'vendor/composer/jetpack_autoload_classmap.php'; + if ( ! file_exists( $classmap ) ) { + return null; + } + + $classmap = require $classmap; + if ( isset( $classmap[ AutoloadGenerator::class ] ) ) { + return $classmap[ AutoloadGenerator::class ]['version']; + } + + return null; + } +} diff --git a/vendor/automattic/jetpack-autoloader/src/class-autoloader.php b/vendor/automattic/jetpack-autoloader/src/class-autoloader.php new file mode 100644 index 00000000000..1668dfa3699 --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/src/class-autoloader.php @@ -0,0 +1,82 @@ +get( Autoloader_Handler::class ); + + // If the autoloader is already initializing it means that it has included us as the latest. + $was_included_by_autoloader = $autoloader_handler->is_initializing(); + + /** @var Plugin_Locator $plugin_locator */ + $plugin_locator = $container->get( Plugin_Locator::class ); + + /** @var Plugins_Handler $plugins_handler */ + $plugins_handler = $container->get( Plugins_Handler::class ); + + // The current plugin is the one that we are attempting to initialize here. + $current_plugin = $plugin_locator->find_current_plugin(); + + // The active plugins are those that we were able to discover on the site. This list will not + // include mu-plugins, those activated by code, or those who are hidden by filtering. We also + // want to take care to not consider the current plugin unknown if it was included by an + // autoloader. This avoids the case where a plugin will be marked "active" while deactivated + // due to it having the latest autoloader. + $active_plugins = $plugins_handler->get_active_plugins( true, ! $was_included_by_autoloader ); + + // The cached plugins are all of those that were active or discovered by the autoloader during a previous request. + // Note that it's possible this list will include plugins that have since been deactivated, but after a request + // the cache should be updated and the deactivated plugins will be removed. + $cached_plugins = $plugins_handler->get_cached_plugins(); + + // We combine the active list and cached list to preemptively load classes for plugins that are + // presently unknown but will be loaded during the request. While this may result in us considering packages in + // deactivated plugins there shouldn't be any problems as a result and the eventual consistency is sufficient. + $all_plugins = array_merge( $active_plugins, $cached_plugins ); + + // In particular we also include the current plugin to address the case where it is the latest autoloader + // but also unknown (and not cached). We don't want it in the active list because we don't know that it + // is active but we need it in the all plugins list so that it is considered by the autoloader. + $all_plugins[] = $current_plugin; + + // We require uniqueness in the array to avoid processing the same plugin more than once. + $all_plugins = array_values( array_unique( $all_plugins ) ); + + /** @var Latest_Autoloader_Guard $guard */ + $guard = $container->get( Latest_Autoloader_Guard::class ); + if ( $guard->should_stop_init( $current_plugin, $all_plugins, $was_included_by_autoloader ) ) { + return; + } + + // Initialize the autoloader using the handler now that we're ready. + $autoloader_handler->activate_autoloader( $all_plugins ); + + /** @var Hook_Manager $hook_manager */ + $hook_manager = $container->get( Hook_Manager::class ); + + // Register a shutdown handler to clean up the autoloader. + $hook_manager->add_action( 'shutdown', new Shutdown_Handler( $plugins_handler, $cached_plugins, $was_included_by_autoloader ) ); + + // phpcs:enable Generic.Commenting.DocComment.MissingShort + } +} diff --git a/vendor/automattic/jetpack-autoloader/src/class-container.php b/vendor/automattic/jetpack-autoloader/src/class-container.php new file mode 100644 index 00000000000..19ea95cb0eb --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/src/class-container.php @@ -0,0 +1,142 @@ + 'Hook_Manager', + ); + + /** + * A map of all the dependencies we've registered with the container and created. + * + * @var array + */ + protected $dependencies; + + /** + * The constructor. + */ + public function __construct() { + $this->dependencies = array(); + + $this->register_shared_dependencies(); + $this->register_dependencies(); + $this->initialize_globals(); + } + + /** + * Gets a dependency out of the container. + * + * @param string $class The class to fetch. + * + * @return mixed + * @throws \InvalidArgumentException When a class that isn't registered with the container is fetched. + */ + public function get( $class ) { + if ( ! isset( $this->dependencies[ $class ] ) ) { + throw new \InvalidArgumentException( "Class '$class' is not registered with the container." ); + } + + return $this->dependencies[ $class ]; + } + + /** + * Registers all of the dependencies that are shared between all instances of the autoloader. + */ + private function register_shared_dependencies() { + global $jetpack_autoloader_container_shared; + if ( ! isset( $jetpack_autoloader_container_shared ) ) { + $jetpack_autoloader_container_shared = array(); + } + + $key = self::SHARED_DEPENDENCY_KEYS[ Hook_Manager::class ]; + if ( ! isset( $jetpack_autoloader_container_shared[ $key ] ) ) { + require_once __DIR__ . '/class-hook-manager.php'; + $jetpack_autoloader_container_shared[ $key ] = new Hook_Manager(); + } + $this->dependencies[ Hook_Manager::class ] = &$jetpack_autoloader_container_shared[ $key ]; + } + + /** + * Registers all of the dependencies with the container. + */ + private function register_dependencies() { + require_once __DIR__ . '/class-path-processor.php'; + $this->dependencies[ Path_Processor::class ] = new Path_Processor(); + + require_once __DIR__ . '/class-plugin-locator.php'; + $this->dependencies[ Plugin_Locator::class ] = new Plugin_Locator( + $this->get( Path_Processor::class ) + ); + + require_once __DIR__ . '/class-version-selector.php'; + $this->dependencies[ Version_Selector::class ] = new Version_Selector(); + + require_once __DIR__ . '/class-autoloader-locator.php'; + $this->dependencies[ Autoloader_Locator::class ] = new Autoloader_Locator( + $this->get( Version_Selector::class ) + ); + + require_once __DIR__ . '/class-php-autoloader.php'; + $this->dependencies[ PHP_Autoloader::class ] = new PHP_Autoloader(); + + require_once __DIR__ . '/class-manifest-reader.php'; + $this->dependencies[ Manifest_Reader::class ] = new Manifest_Reader( + $this->get( Version_Selector::class ) + ); + + require_once __DIR__ . '/class-plugins-handler.php'; + $this->dependencies[ Plugins_Handler::class ] = new Plugins_Handler( + $this->get( Plugin_Locator::class ), + $this->get( Path_Processor::class ) + ); + + require_once __DIR__ . '/class-autoloader-handler.php'; + $this->dependencies[ Autoloader_Handler::class ] = new Autoloader_Handler( + $this->get( PHP_Autoloader::class ), + $this->get( Hook_Manager::class ), + $this->get( Manifest_Reader::class ), + $this->get( Version_Selector::class ) + ); + + require_once __DIR__ . '/class-latest-autoloader-guard.php'; + $this->dependencies[ Latest_Autoloader_Guard::class ] = new Latest_Autoloader_Guard( + $this->get( Plugins_Handler::class ), + $this->get( Autoloader_Handler::class ), + $this->get( Autoloader_Locator::class ) + ); + + // Register any classes that we will use elsewhere. + require_once __DIR__ . '/class-version-loader.php'; + require_once __DIR__ . '/class-shutdown-handler.php'; + } + + /** + * Initializes any of the globals needed by the autoloader. + */ + private function initialize_globals() { + /* + * This global was retired in version 2.9. The value is set to 'false' to maintain + * compatibility with older versions of the autoloader. + */ + global $jetpack_autoloader_including_latest; + $jetpack_autoloader_including_latest = false; + + // Not all plugins can be found using the locator. In cases where a plugin loads the autoloader + // but was not discoverable, we will record them in this array to track them as "active". + global $jetpack_autoloader_activating_plugins_paths; + if ( ! isset( $jetpack_autoloader_activating_plugins_paths ) ) { + $jetpack_autoloader_activating_plugins_paths = array(); + } + } +} diff --git a/vendor/automattic/jetpack-autoloader/src/class-hook-manager.php b/vendor/automattic/jetpack-autoloader/src/class-hook-manager.php new file mode 100644 index 00000000000..1d64c756bfb --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/src/class-hook-manager.php @@ -0,0 +1,68 @@ +registered_hooks = array(); + } + + /** + * Adds an action to WordPress and registers it internally. + * + * @param string $tag The name of the action which is hooked. + * @param callable $callable The function to call. + * @param int $priority Used to specify the priority of the action. + * @param int $accepted_args Used to specify the number of arguments the callable accepts. + */ + public function add_action( $tag, $callable, $priority = 10, $accepted_args = 1 ) { + $this->registered_hooks[ $tag ][] = array( + 'priority' => $priority, + 'callable' => $callable, + ); + + add_action( $tag, $callable, $priority, $accepted_args ); + } + + /** + * Adds a filter to WordPress and registers it internally. + * + * @param string $tag The name of the filter which is hooked. + * @param callable $callable The function to call. + * @param int $priority Used to specify the priority of the filter. + * @param int $accepted_args Used to specify the number of arguments the callable accepts. + */ + public function add_filter( $tag, $callable, $priority = 10, $accepted_args = 1 ) { + $this->registered_hooks[ $tag ][] = array( + 'priority' => $priority, + 'callable' => $callable, + ); + + add_filter( $tag, $callable, $priority, $accepted_args ); + } + + /** + * Removes all of the registered hooks. + */ + public function reset() { + foreach ( $this->registered_hooks as $tag => $hooks ) { + foreach ( $hooks as $hook ) { + remove_filter( $tag, $hook['callable'], $hook['priority'] ); + } + } + $this->registered_hooks = array(); + } +} diff --git a/vendor/automattic/jetpack-autoloader/src/class-latest-autoloader-guard.php b/vendor/automattic/jetpack-autoloader/src/class-latest-autoloader-guard.php new file mode 100644 index 00000000000..54edfc87c23 --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/src/class-latest-autoloader-guard.php @@ -0,0 +1,78 @@ +plugins_handler = $plugins_handler; + $this->autoloader_handler = $autoloader_handler; + $this->autoloader_locator = $autoloader_locator; + } + + /** + * Indicates whether or not the autoloader should be initialized. Note that this function + * has the side-effect of actually loading the latest autoloader in the event that this + * is not it. + * + * @param string $current_plugin The current plugin we're checking. + * @param string[] $plugins The active plugins to check for autoloaders in. + * @param bool $was_included_by_autoloader Indicates whether or not this autoloader was included by another. + * + * @return bool True if we should stop initialization, otherwise false. + */ + public function should_stop_init( $current_plugin, $plugins, $was_included_by_autoloader ) { + global $jetpack_autoloader_latest_version; + + // We need to reset the autoloader when the plugins change because + // that means the autoloader was generated with a different list. + if ( $this->plugins_handler->have_plugins_changed( $plugins ) ) { + $this->autoloader_handler->reset_autoloader(); + } + + // When the latest autoloader has already been found we don't need to search for it again. + // We should take care however because this will also trigger if the autoloader has been + // included by an older one. + if ( isset( $jetpack_autoloader_latest_version ) && ! $was_included_by_autoloader ) { + return true; + } + + $latest_plugin = $this->autoloader_locator->find_latest_autoloader( $plugins, $jetpack_autoloader_latest_version ); + if ( isset( $latest_plugin ) && $latest_plugin !== $current_plugin ) { + require $this->autoloader_locator->get_autoloader_path( $latest_plugin ); + return true; + } + + return false; + } +} diff --git a/vendor/automattic/jetpack-autoloader/src/class-manifest-reader.php b/vendor/automattic/jetpack-autoloader/src/class-manifest-reader.php new file mode 100644 index 00000000000..8eb4825fb2d --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/src/class-manifest-reader.php @@ -0,0 +1,91 @@ +version_selector = $version_selector; + } + + /** + * Reads all of the manifests in the given plugin paths. + * + * @param array $plugin_paths The paths to the plugins we're loading the manifest in. + * @param string $manifest_path The path that we're loading the manifest from in each plugin. + * @param array $path_map The path map to add the contents of the manifests to. + * + * @return array $path_map The path map we've built using the manifests in each plugin. + */ + public function read_manifests( $plugin_paths, $manifest_path, &$path_map ) { + $file_paths = array_map( + function ( $path ) use ( $manifest_path ) { + return trailingslashit( $path ) . $manifest_path; + }, + $plugin_paths + ); + + foreach ( $file_paths as $path ) { + $this->register_manifest( $path, $path_map ); + } + + return $path_map; + } + + /** + * Registers a plugin's manifest file with the path map. + * + * @param string $manifest_path The absolute path to the manifest that we're loading. + * @param array $path_map The path map to add the contents of the manifest to. + */ + protected function register_manifest( $manifest_path, &$path_map ) { + if ( ! is_readable( $manifest_path ) ) { + return; + } + + $manifest = require $manifest_path; + if ( ! is_array( $manifest ) ) { + return; + } + + foreach ( $manifest as $key => $data ) { + $this->register_record( $key, $data, $path_map ); + } + } + + /** + * Registers an entry from the manifest in the path map. + * + * @param string $key The identifier for the entry we're registering. + * @param array $data The data for the entry we're registering. + * @param array $path_map The path map to add the contents of the manifest to. + */ + protected function register_record( $key, $data, &$path_map ) { + if ( isset( $path_map[ $key ]['version'] ) ) { + $selected_version = $path_map[ $key ]['version']; + } else { + $selected_version = null; + } + + if ( $this->version_selector->is_version_update_required( $selected_version, $data['version'] ) ) { + $path_map[ $key ] = array( + 'version' => $data['version'], + 'path' => $data['path'], + ); + } + } +} diff --git a/vendor/automattic/jetpack-autoloader/src/class-path-processor.php b/vendor/automattic/jetpack-autoloader/src/class-path-processor.php new file mode 100644 index 00000000000..bc480c60b05 --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/src/class-path-processor.php @@ -0,0 +1,186 @@ +get_normalized_constants(); + foreach ( $constants as $constant => $constant_path ) { + $len = strlen( $constant_path ); + if ( substr( $path, 0, $len ) !== $constant_path ) { + continue; + } + + return substr_replace( $path, '{{' . $constant . '}}', 0, $len ); + } + + return $path; + } + + /** + * Given a path this will replace any of the path constant tokens with the expanded path. + * + * @param string $tokenized_path The path we want to process. + * + * @return string The expanded path. + */ + public function untokenize_path_constants( $tokenized_path ) { + $tokenized_path = wp_normalize_path( $tokenized_path ); + + $constants = $this->get_normalized_constants(); + foreach ( $constants as $constant => $constant_path ) { + $constant = '{{' . $constant . '}}'; + + $len = strlen( $constant ); + if ( substr( $tokenized_path, 0, $len ) !== $constant ) { + continue; + } + + return $this->get_real_path( substr_replace( $tokenized_path, $constant_path, 0, $len ) ); + } + + return $tokenized_path; + } + + /** + * Given a file and an array of places it might be, this will find the absolute path and return it. + * + * @param string $file The plugin or theme file to resolve. + * @param array $directories_to_check The directories we should check for the file if it isn't an absolute path. + * + * @return string|false Returns the absolute path to the directory, otherwise false. + */ + public function find_directory_with_autoloader( $file, $directories_to_check ) { + $file = wp_normalize_path( $file ); + + if ( ! $this->is_absolute_path( $file ) ) { + $file = $this->find_absolute_plugin_path( $file, $directories_to_check ); + if ( ! isset( $file ) ) { + return false; + } + } + + // We need the real path for consistency with __DIR__ paths. + $file = $this->get_real_path( $file ); + + // phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged + $directory = @is_file( $file ) ? dirname( $file ) : $file; + if ( ! @is_file( $directory . '/vendor/composer/jetpack_autoload_classmap.php' ) ) { + return false; + } + // phpcs:enable WordPress.PHP.NoSilencedErrors.Discouraged + + return $directory; + } + + /** + * Fetches an array of normalized paths keyed by the constant they came from. + * + * @return string[] The normalized paths keyed by the constant. + */ + private function get_normalized_constants() { + $raw_constants = array( + // Order the constants from most-specific to least-specific. + 'WP_PLUGIN_DIR', + 'WPMU_PLUGIN_DIR', + 'WP_CONTENT_DIR', + 'ABSPATH', + ); + + $constants = array(); + foreach ( $raw_constants as $raw ) { + if ( ! defined( $raw ) ) { + continue; + } + + $path = wp_normalize_path( constant( $raw ) ); + if ( isset( $path ) ) { + $constants[ $raw ] = $path; + } + } + + return $constants; + } + + /** + * Indicates whether or not a path is absolute. + * + * @param string $path The path to check. + * + * @return bool True if the path is absolute, otherwise false. + */ + private function is_absolute_path( $path ) { + if ( 0 === strlen( $path ) || '.' === $path[0] ) { + return false; + } + + // Absolute paths on Windows may begin with a drive letter. + if ( preg_match( '/^[a-zA-Z]:[\/\\\\]/', $path ) ) { + return true; + } + + // A path starting with / or \ is absolute; anything else is relative. + return ( '/' === $path[0] || '\\' === $path[0] ); + } + + /** + * Given a file and a list of directories to check, this method will try to figure out + * the absolute path to the file in question. + * + * @param string $normalized_path The normalized path to the plugin or theme file to resolve. + * @param array $directories_to_check The directories we should check for the file if it isn't an absolute path. + * + * @return string|null The absolute path to the plugin file, otherwise null. + */ + private function find_absolute_plugin_path( $normalized_path, $directories_to_check ) { + // We're only able to find the absolute path for plugin/theme PHP files. + if ( ! is_string( $normalized_path ) || '.php' !== substr( $normalized_path, -4 ) ) { + return null; + } + + foreach ( $directories_to_check as $directory ) { + $normalized_check = wp_normalize_path( trailingslashit( $directory ) ) . $normalized_path; + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged + if ( @is_file( $normalized_check ) ) { + return $normalized_check; + } + } + + return null; + } + + /** + * Given a path this will figure out the real path that we should be using. + * + * @param string $path The path to resolve. + * + * @return string The resolved path. + */ + private function get_real_path( $path ) { + // We want to resolve symbolic links for consistency with __DIR__ paths. + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged + $real_path = @realpath( $path ); + if ( false === $real_path ) { + // Let the autoloader deal with paths that don't exist. + $real_path = $path; + } + + // Using realpath will make it platform-specific so we must normalize it after. + if ( $path !== $real_path ) { + $real_path = wp_normalize_path( $real_path ); + } + + return $real_path; + } +} diff --git a/vendor/automattic/jetpack-autoloader/src/class-php-autoloader.php b/vendor/automattic/jetpack-autoloader/src/class-php-autoloader.php new file mode 100644 index 00000000000..727a269ca97 --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/src/class-php-autoloader.php @@ -0,0 +1,85 @@ +unregister_autoloader(); + + // Set the global so that it can be used to load classes. + global $jetpack_autoloader_loader; + $jetpack_autoloader_loader = $version_loader; + + // Ensure that the autoloader is first to avoid contention with others. + spl_autoload_register( array( self::class, 'load_class' ), true, true ); + } + + /** + * Unregisters the active autoloader so that it will no longer autoload classes. + */ + public function unregister_autoloader() { + // Remove any v2 autoloader that we've already registered. + $autoload_chain = spl_autoload_functions(); + if ( ! $autoload_chain ) { + return; + } + foreach ( $autoload_chain as $autoloader ) { + // We can identify a v2 autoloader using the namespace. + $namespace_check = null; + + // Functions are recorded as strings. + if ( is_string( $autoloader ) ) { + $namespace_check = $autoloader; + } elseif ( is_array( $autoloader ) && is_string( $autoloader[0] ) ) { + // Static method calls have the class as the first array element. + $namespace_check = $autoloader[0]; + } else { + // Since the autoloader has only ever been a function or a static method we don't currently need to check anything else. + continue; + } + + // Check for the namespace without the generated suffix. + if ( 'Automattic\\Jetpack\\Autoloader\\jp' === substr( $namespace_check, 0, 32 ) ) { + spl_autoload_unregister( $autoloader ); + } + } + + // Clear the global now that the autoloader has been unregistered. + global $jetpack_autoloader_loader; + $jetpack_autoloader_loader = null; + } + + /** + * Loads a class file if one could be found. + * + * Note: This function is static so that the autoloader can be easily unregistered. If + * it was a class method we would have to unwrap the object to check the namespace. + * + * @param string $class_name The name of the class to autoload. + * + * @return bool Indicates whether or not a class file was loaded. + */ + public static function load_class( $class_name ) { + global $jetpack_autoloader_loader; + if ( ! isset( $jetpack_autoloader_loader ) ) { + return; + } + + $file = $jetpack_autoloader_loader->find_class_file( $class_name ); + if ( ! isset( $file ) ) { + return false; + } + + require $file; + return true; + } +} diff --git a/vendor/automattic/jetpack-autoloader/src/class-plugin-locator.php b/vendor/automattic/jetpack-autoloader/src/class-plugin-locator.php new file mode 100644 index 00000000000..3a784c808d8 --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/src/class-plugin-locator.php @@ -0,0 +1,145 @@ +path_processor = $path_processor; + } + + /** + * Finds the path to the current plugin. + * + * @return string $path The path to the current plugin. + * + * @throws \RuntimeException If the current plugin does not have an autoloader. + */ + public function find_current_plugin() { + // Escape from `vendor/__DIR__` to root plugin directory. + $plugin_directory = dirname( dirname( __DIR__ ) ); + + // Use the path processor to ensure that this is an autoloader we're referencing. + $path = $this->path_processor->find_directory_with_autoloader( $plugin_directory, array() ); + if ( false === $path ) { + throw new \RuntimeException( 'Failed to locate plugin ' . $plugin_directory ); + } + + return $path; + } + + /** + * Checks a given option for plugin paths. + * + * @param string $option_name The option that we want to check for plugin information. + * @param bool $site_option Indicates whether or not we want to check the site option. + * + * @return array $plugin_paths The list of absolute paths we've found. + */ + public function find_using_option( $option_name, $site_option = false ) { + $raw = $site_option ? get_site_option( $option_name ) : get_option( $option_name ); + if ( false === $raw ) { + return array(); + } + + return $this->convert_plugins_to_paths( $raw ); + } + + /** + * Checks for plugins in the `action` request parameter. + * + * @param string[] $allowed_actions The actions that we're allowed to return plugins for. + * + * @return array $plugin_paths The list of absolute paths we've found. + */ + public function find_using_request_action( $allowed_actions ) { + /** + * Note: we're not actually checking the nonce here because it's too early + * in the execution. The pluggable functions are not yet loaded to give + * plugins a chance to plug their versions. Therefore we're doing the bare + * minimum: checking whether the nonce exists and it's in the right place. + * The request will fail later if the nonce doesn't pass the check. + */ + if ( empty( $_REQUEST['_wpnonce'] ) ) { + return array(); + } + + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Validated just below. + $action = isset( $_REQUEST['action'] ) ? wp_unslash( $_REQUEST['action'] ) : false; + if ( ! in_array( $action, $allowed_actions, true ) ) { + return array(); + } + + $plugin_slugs = array(); + switch ( $action ) { + case 'activate': + case 'deactivate': + if ( empty( $_REQUEST['plugin'] ) ) { + break; + } + + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Validated by convert_plugins_to_paths. + $plugin_slugs[] = wp_unslash( $_REQUEST['plugin'] ); + break; + + case 'activate-selected': + case 'deactivate-selected': + if ( empty( $_REQUEST['checked'] ) ) { + break; + } + + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Validated by convert_plugins_to_paths. + $plugin_slugs = wp_unslash( $_REQUEST['checked'] ); + break; + } + + return $this->convert_plugins_to_paths( $plugin_slugs ); + } + + /** + * Given an array of plugin slugs or paths, this will convert them to absolute paths and filter + * out the plugins that are not directory plugins. Note that array keys will also be included + * if they are plugin paths! + * + * @param string[] $plugins Plugin paths or slugs to filter. + * + * @return string[] + */ + private function convert_plugins_to_paths( $plugins ) { + if ( ! is_array( $plugins ) || empty( $plugins ) ) { + return array(); + } + + // We're going to look for plugins in the standard directories. + $path_constants = array( WP_PLUGIN_DIR, WPMU_PLUGIN_DIR ); + + $plugin_paths = array(); + foreach ( $plugins as $key => $value ) { + $path = $this->path_processor->find_directory_with_autoloader( $key, $path_constants ); + if ( $path ) { + $plugin_paths[] = $path; + } + + $path = $this->path_processor->find_directory_with_autoloader( $value, $path_constants ); + if ( $path ) { + $plugin_paths[] = $path; + } + } + + return $plugin_paths; + } +} diff --git a/vendor/automattic/jetpack-autoloader/src/class-plugins-handler.php b/vendor/automattic/jetpack-autoloader/src/class-plugins-handler.php new file mode 100644 index 00000000000..dd00ac12192 --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/src/class-plugins-handler.php @@ -0,0 +1,156 @@ +plugin_locator = $plugin_locator; + $this->path_processor = $path_processor; + } + + /** + * Gets all of the active plugins we can find. + * + * @param bool $include_deactivating When true, plugins deactivating this request will be considered active. + * @param bool $record_unknown When true, the current plugin will be marked as active and recorded when unknown. + * + * @return string[] + */ + public function get_active_plugins( $include_deactivating, $record_unknown ) { + global $jetpack_autoloader_activating_plugins_paths; + + // We're going to build a unique list of plugins from a few different sources + // to find all of our "active" plugins. While we need to return an integer + // array, we're going to use an associative array internally to reduce + // the amount of time that we're going to spend checking uniqueness + // and merging different arrays together to form the output. + $active_plugins = array(); + + // Make sure that plugins which have activated this request are considered as "active" even though + // they probably won't be present in any option. + if ( is_array( $jetpack_autoloader_activating_plugins_paths ) ) { + foreach ( $jetpack_autoloader_activating_plugins_paths as $path ) { + $active_plugins[ $path ] = $path; + } + } + + // This option contains all of the plugins that have been activated. + $plugins = $this->plugin_locator->find_using_option( 'active_plugins' ); + foreach ( $plugins as $path ) { + $active_plugins[ $path ] = $path; + } + + // This option contains all of the multisite plugins that have been activated. + if ( is_multisite() ) { + $plugins = $this->plugin_locator->find_using_option( 'active_sitewide_plugins', true ); + foreach ( $plugins as $path ) { + $active_plugins[ $path ] = $path; + } + } + + // These actions contain plugins that are being activated/deactivated during this request. + $plugins = $this->plugin_locator->find_using_request_action( array( 'activate', 'activate-selected', 'deactivate', 'deactivate-selected' ) ); + foreach ( $plugins as $path ) { + $active_plugins[ $path ] = $path; + } + + // When the current plugin isn't considered "active" there's a problem. + // Since we're here, the plugin is active and currently being loaded. + // We can support this case (mu-plugins and non-standard activation) + // by adding the current plugin to the active list and marking it + // as an unknown (activating) plugin. This also has the benefit + // of causing a reset because the active plugins list has + // been changed since it was saved in the global. + $current_plugin = $this->plugin_locator->find_current_plugin(); + if ( $record_unknown && ! in_array( $current_plugin, $active_plugins, true ) ) { + $active_plugins[ $current_plugin ] = $current_plugin; + $jetpack_autoloader_activating_plugins_paths[] = $current_plugin; + } + + // When deactivating plugins aren't desired we should entirely remove them from the active list. + if ( ! $include_deactivating ) { + // These actions contain plugins that are being deactivated during this request. + $plugins = $this->plugin_locator->find_using_request_action( array( 'deactivate', 'deactivate-selected' ) ); + foreach ( $plugins as $path ) { + unset( $active_plugins[ $path ] ); + } + } + + // Transform the array so that we don't have to worry about the keys interacting with other array types later. + return array_values( $active_plugins ); + } + + /** + * Gets all of the cached plugins if there are any. + * + * @return string[] + */ + public function get_cached_plugins() { + $cached = get_transient( self::TRANSIENT_KEY ); + if ( ! is_array( $cached ) || empty( $cached ) ) { + return array(); + } + + // We need to expand the tokens to an absolute path for this webserver. + return array_map( array( $this->path_processor, 'untokenize_path_constants' ), $cached ); + } + + /** + * Saves the plugin list to the cache. + * + * @param array $plugins The plugin list to save to the cache. + */ + public function cache_plugins( $plugins ) { + // We store the paths in a tokenized form so that that webservers with different absolute paths don't break. + $plugins = array_map( array( $this->path_processor, 'tokenize_path_constants' ), $plugins ); + + set_transient( self::TRANSIENT_KEY, $plugins ); + } + + /** + * Checks to see whether or not the plugin list given has changed when compared to the + * shared `$jetpack_autoloader_cached_plugin_paths` global. This allows us to deal + * with cases where the active list may change due to filtering.. + * + * @param string[] $plugins The plugins list to check against the global cache. + * + * @return bool True if the plugins have changed, otherwise false. + */ + public function have_plugins_changed( $plugins ) { + global $jetpack_autoloader_cached_plugin_paths; + + if ( $jetpack_autoloader_cached_plugin_paths !== $plugins ) { + $jetpack_autoloader_cached_plugin_paths = $plugins; + return true; + } + + return false; + } +} diff --git a/vendor/automattic/jetpack-autoloader/src/class-shutdown-handler.php b/vendor/automattic/jetpack-autoloader/src/class-shutdown-handler.php new file mode 100644 index 00000000000..198b19c6f55 --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/src/class-shutdown-handler.php @@ -0,0 +1,84 @@ +plugins_handler = $plugins_handler; + $this->cached_plugins = $cached_plugins; + $this->was_included_by_autoloader = $was_included_by_autoloader; + } + + /** + * Handles the shutdown of the autoloader. + */ + public function __invoke() { + // Don't save a broken cache if an error happens during some plugin's initialization. + if ( ! did_action( 'plugins_loaded' ) ) { + // Ensure that the cache is emptied to prevent consecutive failures if the cache is to blame. + if ( ! empty( $this->cached_plugins ) ) { + $this->plugins_handler->cache_plugins( array() ); + } + + return; + } + + // Load the active plugins fresh since the list we pulled earlier might not contain + // plugins that were activated but did not reset the autoloader. This happens + // when a plugin is in the cache but not "active" when the autoloader loads. + // We also want to make sure that plugins which are deactivating are not + // considered "active" so that they will be removed from the cache now. + try { + $active_plugins = $this->plugins_handler->get_active_plugins( false, ! $this->was_included_by_autoloader ); + } catch ( \Exception $ex ) { + // When the package is deleted before shutdown it will throw an exception. + // In the event this happens we should erase the cache. + if ( ! empty( $this->cached_plugins ) ) { + $this->plugins_handler->cache_plugins( array() ); + } + return; + } + + // The paths should be sorted for easy comparisons with those loaded from the cache. + // Note we don't need to sort the cached entries because they're already sorted. + sort( $active_plugins ); + + // We don't want to waste time saving a cache that hasn't changed. + if ( $this->cached_plugins === $active_plugins ) { + return; + } + + $this->plugins_handler->cache_plugins( $active_plugins ); + } +} diff --git a/vendor/automattic/jetpack-autoloader/src/class-version-loader.php b/vendor/automattic/jetpack-autoloader/src/class-version-loader.php new file mode 100644 index 00000000000..a1169ced924 --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/src/class-version-loader.php @@ -0,0 +1,156 @@ +version_selector = $version_selector; + $this->classmap = $classmap; + $this->psr4_map = $psr4_map; + $this->filemap = $filemap; + } + + /** + * Finds the file path for the given class. + * + * @param string $class_name The class to find. + * + * @return string|null $file_path The path to the file if found, null if no class was found. + */ + public function find_class_file( $class_name ) { + $data = $this->select_newest_file( + isset( $this->classmap[ $class_name ] ) ? $this->classmap[ $class_name ] : null, + $this->find_psr4_file( $class_name ) + ); + if ( ! isset( $data ) ) { + return null; + } + + return $data['path']; + } + + /** + * Load all of the files in the filemap. + */ + public function load_filemap() { + if ( empty( $this->filemap ) ) { + return; + } + + foreach ( $this->filemap as $file_identifier => $file_data ) { + if ( empty( $GLOBALS['__composer_autoload_files'][ $file_identifier ] ) ) { + require_once $file_data['path']; + + $GLOBALS['__composer_autoload_files'][ $file_identifier ] = true; + } + } + } + + /** + * Compares different class sources and returns the newest. + * + * @param array|null $classmap_data The classmap class data. + * @param array|null $psr4_data The PSR-4 class data. + * + * @return array|null $data + */ + private function select_newest_file( $classmap_data, $psr4_data ) { + if ( ! isset( $classmap_data ) ) { + return $psr4_data; + } elseif ( ! isset( $psr4_data ) ) { + return $classmap_data; + } + + if ( $this->version_selector->is_version_update_required( $classmap_data['version'], $psr4_data['version'] ) ) { + return $psr4_data; + } + + return $classmap_data; + } + + /** + * Finds the file for a given class in a PSR-4 namespace. + * + * @param string $class_name The class to find. + * + * @return array|null $data The version and path path to the file if found, null otherwise. + */ + private function find_psr4_file( $class_name ) { + if ( ! isset( $this->psr4_map ) ) { + return null; + } + + // Don't bother with classes that have no namespace. + $class_index = strrpos( $class_name, '\\' ); + if ( ! $class_index ) { + return null; + } + $class_for_path = str_replace( '\\', '/', $class_name ); + + // Search for the namespace by iteratively cutting off the last segment until + // we find a match. This allows us to check the most-specific namespaces + // first as well as minimize the amount of time spent looking. + for ( + $class_namespace = substr( $class_name, 0, $class_index ); + ! empty( $class_namespace ); + $class_namespace = substr( $class_namespace, 0, strrpos( $class_namespace, '\\' ) ) + ) { + $namespace = $class_namespace . '\\'; + if ( ! isset( $this->psr4_map[ $namespace ] ) ) { + continue; + } + $data = $this->psr4_map[ $namespace ]; + + foreach ( $data['path'] as $path ) { + $path .= '/' . substr( $class_for_path, strlen( $namespace ) ) . '.php'; + if ( file_exists( $path ) ) { + return array( + 'version' => $data['version'], + 'path' => $path, + ); + } + } + } + + return null; + } +} diff --git a/vendor/automattic/jetpack-autoloader/src/class-version-selector.php b/vendor/automattic/jetpack-autoloader/src/class-version-selector.php new file mode 100644 index 00000000000..5b201ff9200 --- /dev/null +++ b/vendor/automattic/jetpack-autoloader/src/class-version-selector.php @@ -0,0 +1,61 @@ +is_dev_version( $selected_version ) ) { + return false; + } + + if ( $this->is_dev_version( $compare_version ) ) { + if ( $use_dev_versions ) { + return true; + } else { + return false; + } + } + + if ( version_compare( $selected_version, $compare_version, '<' ) ) { + return true; + } + + return false; + } + + /** + * Checks whether the given package version is a development version. + * + * @param String $version The package version. + * + * @return bool True if the version is a dev version, else false. + */ + public function is_dev_version( $version ) { + if ( 'dev-' === substr( $version, 0, 4 ) || '9999999-dev' === $version ) { + return true; + } + + return false; + } +} diff --git a/vendor/automattic/jetpack-config/CHANGELOG.md b/vendor/automattic/jetpack-config/CHANGELOG.md new file mode 100644 index 00000000000..313afad7e86 --- /dev/null +++ b/vendor/automattic/jetpack-config/CHANGELOG.md @@ -0,0 +1,230 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [1.15.4] - 2023-09-19 +- Minor internal updates. + +## [1.15.3] - 2023-06-26 +### Changed +- Blaze can now be loaded as a module, instead of relying on the Config package. [#31479] + +## [1.15.2] - 2023-04-10 +### Added +- Add Jetpack Autoloader package suggestion. [#29988] + +## [1.15.1] - 2023-03-28 +### Changed +- Minor internal updates. + +## [1.15.0] - 2023-03-27 +### Added +- Initialize yoast promo package in jetpack plugin [#29641] + +## [1.14.0] - 2023-02-20 +### Added +- Added the Import package. [#28824] + +## [1.13.0] - 2023-01-02 +### Added +- Blaze package: Add config initialization, initialization checks for loading. [#28077] + +## [1.12.0] - 2022-12-12 +### Added +- Config: add option to init stats-admin [#27565] + +## [1.11.1] - 2022-11-22 +### Changed +- Updated package dependencies. [#27043] + +## [1.11.0] - 2022-10-11 +### Changed +- Integrate Stats package in Jetpack plugin [#26640] + +## [1.10.0] - 2022-09-27 +### Added +- Social: Added the option to configure if the plan information should be refreshed as the package is enabled. [#26294] + +## [1.9.6] - 2022-08-26 +### Changed +- Call ensure_options_$feature methods before the initialization + +## [1.9.5] - 2022-08-23 +### Changed +- Initialize VideoPress admin UI from the package [#25692] + +## [1.9.4] - 2022-08-09 +### Changed +- Initialize VideoPress package from the Config pkg [#25385] + +## [1.9.3] - 2022-07-26 +### Changed +- Updated package dependencies. [#25158] + +## [1.9.2] - 2022-06-29 + +- Updated package dependencies. + +## [1.9.1] - 2022-06-21 +### Changed +- Renaming master to trunk. + +## [1.9.0] - 2022-05-18 +### Added +- Configuration for waf package [#24153] + +## [1.8.0] - 2022-04-26 +### Added +- Added the publicize package to be configured via the config package. + +### Changed +- Updated package dependencies. + +## [1.7.2] - 2022-04-19 +### Added +- Enable WordAds from Config class + +## [1.7.1] - 2022-04-06 +### Removed +- Removed tracking dependency. + +## [1.7.0] - 2022-03-23 +### Added +- Search: added search initialization + +## [1.6.1] - 2022-02-09 +### Added +- Allow sync package consumers to provide custom data settings. + +## [1.6.0] - 2022-01-04 +### Added +- Accept options for the IDC package. + +### Changed +- Updated package textdomain from `jetpack` to `jetpack-config`. + +## [1.5.4] - 2021-12-14 +### Changed +- Updated package dependencies. + +## [1.5.3] - 2021-10-13 +### Changed +- Updated package dependencies. + +## [1.5.2] - 2021-10-12 +### Added +- Add support for the identity-crisis package + +## [1.5.1] - 2021-09-28 +### Changed +- Updated package dependencies. + +## [1.5.0] - 2021-09-22 +### Added +- Allow for enabling and initializing new Post_List package from Config package. + +## [1.4.7] - 2021-08-31 +### Changed +- updates annotations versions. + +## [1.4.6] - 2021-05-25 +### Changed +- Updated package dependencies. + +## [1.4.5] - 2021-04-27 +### Changed +- Updated package dependencies. + +## [1.4.4] - 2021-03-30 +### Added +- Composer alias for dev-master, to improve dependencies + +### Changed +- Update package dependencies. + +## [1.4.3] - 2021-01-19 + +- Add mirror-repo information to all current composer packages +- Monorepo: Reorganize all projects + +## [1.4.2] - 2020-10-28 + +- Updated PHPCS: Packages and Debugger +- Config: remove tos and tracking features +- Config: add info about the package dependencies to the package docs + +## [1.4.1] - 2020-09-15 + +- Config: remove tos and tracking features + +## [1.4.0] - 2020-08-26 + +- Config: Remove composer dependencies +- Config: Add connection status check + +## [1.3.0] - 2020-06-26 + +- Config: check for both JITM namespaces + +## [1.2.0] - 2020-05-20 + +- Store the list of active plugins that uses connection in an option +- Implement pre-connection JITMs +- Connection Package: Handle disconnections gracefully + +## [1.1.0] - 2020-01-23 + +- Moved JITM initialization to plugins_loaded. + +## [1.0.1] - 2020-01-20 + +- Move connection manager related logic to after plugins_loaded. + +## 1.0.0 - 2020-01-14 + +- Trying to add deterministic initialization. + +[1.15.4]: https://github.com/Automattic/jetpack-config/compare/v1.15.3...v1.15.4 +[1.15.3]: https://github.com/Automattic/jetpack-config/compare/v1.15.2...v1.15.3 +[1.15.2]: https://github.com/Automattic/jetpack-config/compare/v1.15.1...v1.15.2 +[1.15.1]: https://github.com/Automattic/jetpack-config/compare/v1.15.0...v1.15.1 +[1.15.0]: https://github.com/Automattic/jetpack-config/compare/v1.14.0...v1.15.0 +[1.14.0]: https://github.com/Automattic/jetpack-config/compare/v1.13.0...v1.14.0 +[1.13.0]: https://github.com/Automattic/jetpack-config/compare/v1.12.0...v1.13.0 +[1.12.0]: https://github.com/Automattic/jetpack-config/compare/v1.11.1...v1.12.0 +[1.11.1]: https://github.com/Automattic/jetpack-config/compare/v1.11.0...v1.11.1 +[1.11.0]: https://github.com/Automattic/jetpack-config/compare/v1.10.0...v1.11.0 +[1.10.0]: https://github.com/Automattic/jetpack-config/compare/v1.9.6...v1.10.0 +[1.9.6]: https://github.com/Automattic/jetpack-config/compare/v1.9.5...v1.9.6 +[1.9.5]: https://github.com/Automattic/jetpack-config/compare/v1.9.4...v1.9.5 +[1.9.4]: https://github.com/Automattic/jetpack-config/compare/v1.9.3...v1.9.4 +[1.9.3]: https://github.com/Automattic/jetpack-config/compare/v1.9.2...v1.9.3 +[1.9.2]: https://github.com/Automattic/jetpack-config/compare/v1.9.1...v1.9.2 +[1.9.1]: https://github.com/Automattic/jetpack-config/compare/v1.9.0...v1.9.1 +[1.9.0]: https://github.com/Automattic/jetpack-config/compare/v1.8.0...v1.9.0 +[1.8.0]: https://github.com/Automattic/jetpack-config/compare/v1.7.2...v1.8.0 +[1.7.2]: https://github.com/Automattic/jetpack-config/compare/v1.7.1...v1.7.2 +[1.7.1]: https://github.com/Automattic/jetpack-config/compare/v1.7.0...v1.7.1 +[1.7.0]: https://github.com/Automattic/jetpack-config/compare/v1.6.1...v1.7.0 +[1.6.1]: https://github.com/Automattic/jetpack-config/compare/v1.6.0...v1.6.1 +[1.6.0]: https://github.com/Automattic/jetpack-config/compare/v1.5.4...v1.6.0 +[1.5.4]: https://github.com/Automattic/jetpack-config/compare/v1.5.3...v1.5.4 +[1.5.3]: https://github.com/Automattic/jetpack-config/compare/v1.5.2...v1.5.3 +[1.5.2]: https://github.com/Automattic/jetpack-config/compare/v1.5.1...v1.5.2 +[1.5.1]: https://github.com/Automattic/jetpack-config/compare/v1.5.0...v1.5.1 +[1.5.0]: https://github.com/Automattic/jetpack-config/compare/v1.4.7...v1.5.0 +[1.4.7]: https://github.com/Automattic/jetpack-config/compare/v1.4.6...v1.4.7 +[1.4.6]: https://github.com/Automattic/jetpack-config/compare/v1.4.5...v1.4.6 +[1.4.5]: https://github.com/Automattic/jetpack-config/compare/v1.4.4...v1.4.5 +[1.4.4]: https://github.com/Automattic/jetpack-config/compare/v1.4.3...v1.4.4 +[1.4.3]: https://github.com/Automattic/jetpack-config/compare/v1.4.2...v1.4.3 +[1.4.2]: https://github.com/Automattic/jetpack-config/compare/v1.4.1...v1.4.2 +[1.4.1]: https://github.com/Automattic/jetpack-config/compare/v1.4.0...v1.4.1 +[1.4.0]: https://github.com/Automattic/jetpack-config/compare/v1.3.0...v1.4.0 +[1.3.0]: https://github.com/Automattic/jetpack-config/compare/v1.2.0...v1.3.0 +[1.2.0]: https://github.com/Automattic/jetpack-config/compare/v1.1.0...v1.2.0 +[1.1.0]: https://github.com/Automattic/jetpack-config/compare/v1.0.1...v1.1.0 +[1.0.1]: https://github.com/Automattic/jetpack-config/compare/v1.0.0...v1.0.1 diff --git a/vendor/automattic/jetpack-config/LICENSE.txt b/vendor/automattic/jetpack-config/LICENSE.txt new file mode 100644 index 00000000000..e82774c1bd5 --- /dev/null +++ b/vendor/automattic/jetpack-config/LICENSE.txt @@ -0,0 +1,357 @@ +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +=================================== + + +GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + + Preamble + +The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + +We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + +Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and +modification follow. + +GNU GENERAL PUBLIC LICENSE +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + +a) You must cause the modified files to carry prominent notices +stating that you changed the files and the date of any change. + +b) You must cause any work that you distribute or publish, that in +whole or in part contains or is derived from the Program or any +part thereof, to be licensed as a whole at no charge to all third +parties under the terms of this License. + +c) If the modified program normally reads commands interactively +when run, you must cause it, when started running for such +interactive use in the most ordinary way, to print or display an +announcement including an appropriate copyright notice and a +notice that there is no warranty (or else, saying that you provide +a warranty) and that users may redistribute the program under +these conditions, and telling the user how to view a copy of this +License. (Exception: if the Program itself is interactive but +does not normally print such an announcement, your work based on +the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + +a) Accompany it with the complete corresponding machine-readable +source code, which must be distributed under the terms of Sections +1 and 2 above on a medium customarily used for software interchange; or, + +b) Accompany it with a written offer, valid for at least three +years, to give any third party, for a charge no more than your +cost of physically performing source distribution, a complete +machine-readable copy of the corresponding source code, to be +distributed under the terms of Sections 1 and 2 above on a medium +customarily used for software interchange; or, + +c) Accompany it with the information you received as to the offer +to distribute corresponding source code. (This alternative is +allowed only for noncommercial distribution and only if you +received the program in object code or executable form with such +an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + +5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + +7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + +10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + +Copyright (C) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + +Gnomovision version 69, Copyright (C) year name of author +Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. +This is free software, and you are welcome to redistribute it +under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in the program +`Gnomovision' (which makes passes at compilers) written by James Hacker. + +, 1 April 1989 +Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/vendor/automattic/jetpack-config/README.md b/vendor/automattic/jetpack-config/README.md new file mode 100644 index 00000000000..d794fd5a09c --- /dev/null +++ b/vendor/automattic/jetpack-config/README.md @@ -0,0 +1,163 @@ +# Jetpack Configuration + +Allows for enabling and initializing of Jetpack features provided by +other packages. + +# Usage + +Add this package as a dependency to your project: + +``` +composer require automattic/jetpack-config +``` + +Add every other package you're planning to configure: + +``` +composer require automattic/jetpack-sync +composer require automattic/jetpack-options +composer require automattic/jetpack-my-jetpack +``` + +In your code initialize the configuration package at or before +plugins_loaded priority 1: + +``` +use Automattic/Jetpack/Config; + +// Configuring Jetpack as early as plugins_loaded priority 1 +// to make sure every action handler gets properly set. +add_action( 'plugins_loaded', 'configure_jetpack', 1 ); + +function configure_jetpack() { + $config = new Config(); + + foreach ( + array( + 'sync', + 'tracking', + 'tos', + ) + as $feature + ) { + $config->ensure( $feature ); + } +} +``` + +# Adding your package to the config class + +You can have your package initialized using the Config class by +adding several things. + +## The configure method + +It's better to have one static configure method in your package +class. That method will be called early on the `plugins_loaded` +hook. This way you can add your own `plugins_loaded` handlers with +standard priority and they will get executed: + +``` +class Configurable_Package { + + public static function configure() { + add_action( 'plugins_loaded', array( __CLASS__, 'on_plugins_loaded' ); + } + + public static function on_plugins_loaded() { + self::do_interesting_stuff(); + } + +} +``` + +## The feature enabling method + +An enabling method should be added to the Config class and should only contain your configuration method call. + +``` + +public function enable_configurable_package() { + Configurable_Package::configure(); + + return true; +} +``` + +Note that the method name should use the feature slug, in this case +your feature slug is `configurable_package` for the sake of +simplicity. When you're adding your feature it should be unique and +recognizable, like `sync` or `tracking`. + +## The feature slug + +To make sure the feature is supported by the Config class, you need to +add its slug to the config class property: + +``` + /** + * The initial setting values. + * + * @var Array + */ + protected $config = array( + // ... + 'configurable_package' => false, + // ... + ); +``` + +## The ensure_options call + +Each consumer will initialize your package from its own instance of the `Config` class, and each consumer can call `$config->ensure( 'your-feature', $options )` passing different options. + +Your package will need to handle these options and decide what to do with them when different consumers pass diferent options. + +You do that by creating a `ensure_options_{$package_slug}` method to the `Config` class. For example: + +``` + +public function ensure_options_configurable_package() { + $options = $this->get_feature_options( 'configurable_package' ); + Configurable_Package::handle_initialization_options( $options ); + return true; +} +``` + +This method will be called every time a different consumer "ensures" your feature and pass some options. It will run BEFORE the `enable_$feature` method is called, so your package must be prepare to receive and treat this options before it is initialized. By the time it is initialized, it should have received all the different options consumers have passed and decided what to do with them. + +## The ensure call + +Finally you need to add a block that will check if your package is +loaded and mark it to be initialized: + +``` +if ( $this->config['configurable_package'] ) { + $this->ensure_class( 'Configurable_Package' ) && $this->ensure_feature( 'configurable_package' ); +} +``` + +This code does three things: it checks whether the current setup has +requested your package to be loaded. Next it checks if the class that +you need for the package to run is present, and then it adds the hook +handlers that initialize your class. After that you can use the config +package's interface in a Jetpack package consumer application and load +your package as shown in the first section of this README. + +# Config Package Dependencies + +The Config package does not have any composer package dependencies. The consumer plugins must require the packages that they need. + +Before using a package class, the Config package will verify that the class exists using the `Config::ensure_class()` method. This allows the consumer plugins to use the Config package to enable and initialize Jetpack features while requiring only the packages that they need. + +## Using this package in your WordPress plugin + +If you plan on using this package in your WordPress plugin, we would recommend that you use [Jetpack Autoloader](https://packagist.org/packages/automattic/jetpack-autoloader) as your autoloader. This will allow for maximum interoperability with other plugins that use this package as well. + +## Security + +Need to report a security vulnerability? Go to [https://automattic.com/security/](https://automattic.com/security/) or directly to our security bug bounty site [https://hackerone.com/automattic](https://hackerone.com/automattic). + +## License + +jetpack-config is licensed under [GNU General Public License v2 (or later)](./LICENSE.txt) diff --git a/vendor/automattic/jetpack-config/SECURITY.md b/vendor/automattic/jetpack-config/SECURITY.md new file mode 100644 index 00000000000..b4b46c0ee23 --- /dev/null +++ b/vendor/automattic/jetpack-config/SECURITY.md @@ -0,0 +1,38 @@ +# Security Policy + +Full details of the Automattic Security Policy can be found on [automattic.com](https://automattic.com/security/). + +## Supported Versions + +Generally, only the latest version of Jetpack has continued support. If a critical vulnerability is found in the current version of Jetpack, we may opt to backport any patches to previous versions. + +## Reporting a Vulnerability + +[Jetpack](https://jetpack.com/) is an open-source plugin for WordPress. Our HackerOne program covers the plugin software, as well as a variety of related projects and infrastructure. + +**For responsible disclosure of security issues and to be eligible for our bug bounty program, please submit your report via the [HackerOne](https://hackerone.com/automattic) portal.** + +Our most critical targets are: + +* Jetpack and the Jetpack composer packages (all within this repo) +* Jetpack.com -- the primary marketing site. +* cloud.jetpack.com -- a management site. +* wordpress.com -- the shared management site for both Jetpack and WordPress.com sites. + +For more targets, see the `In Scope` section on [HackerOne](https://hackerone.com/automattic). + +_Please note that the **WordPress software is a separate entity** from Automattic. Please report vulnerabilities for WordPress through [the WordPress Foundation's HackerOne page](https://hackerone.com/wordpress)._ + +## Guidelines + +We're committed to working with security researchers to resolve the vulnerabilities they discover. You can help us by following these guidelines: + +* Follow [HackerOne's disclosure guidelines](https://www.hackerone.com/disclosure-guidelines). +* Pen-testing Production: + * Please **setup a local environment** instead whenever possible. Most of our code is open source (see above). + * If that's not possible, **limit any data access/modification** to the bare minimum necessary to reproduce a PoC. + * **_Don't_ automate form submissions!** That's very annoying for us, because it adds extra work for the volunteers who manage those systems, and reduces the signal/noise ratio in our communication channels. + * To be eligible for a bounty, all of these guidelines must be followed. +* Be Patient - Give us a reasonable time to correct the issue before you disclose the vulnerability. + +We also expect you to comply with all applicable laws. You're responsible to pay any taxes associated with your bounties. diff --git a/vendor/automattic/jetpack-config/composer.json b/vendor/automattic/jetpack-config/composer.json new file mode 100644 index 00000000000..5179574d1fd --- /dev/null +++ b/vendor/automattic/jetpack-config/composer.json @@ -0,0 +1,31 @@ +{ + "name": "automattic/jetpack-config", + "description": "Jetpack configuration package that initializes other packages and configures Jetpack's functionality. Can be used as a base for all variants of Jetpack package usage.", + "type": "jetpack-library", + "license": "GPL-2.0-or-later", + "require": {}, + "require-dev": { + "automattic/jetpack-changelogger": "^3.3.9" + }, + "suggest": { + "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "minimum-stability": "dev", + "prefer-stable": true, + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-config", + "textdomain": "jetpack-config", + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-config/compare/v${old}...v${new}" + }, + "branch-alias": { + "dev-trunk": "1.15.x-dev" + } + } +} diff --git a/vendor/automattic/jetpack-config/src/class-config.php b/vendor/automattic/jetpack-config/src/class-config.php new file mode 100644 index 00000000000..9856e1f38d8 --- /dev/null +++ b/vendor/automattic/jetpack-config/src/class-config.php @@ -0,0 +1,454 @@ + false, + 'connection' => false, + 'sync' => false, + 'post_list' => false, + 'identity_crisis' => false, + 'search' => false, + 'publicize' => false, + 'wordads' => false, + 'waf' => false, + 'videopress' => false, + 'stats' => false, + 'stats_admin' => false, + 'yoast_promo' => false, + 'import' => false, + ); + + /** + * Initialization options stored here. + * + * @var array + */ + protected $feature_options = array(); + + /** + * Creates the configuration class instance. + */ + public function __construct() { + /** + * Adding the config handler to run on priority 2 because the class itself is + * being constructed on priority 1. + */ + add_action( 'plugins_loaded', array( $this, 'on_plugins_loaded' ), 2 ); + } + + /** + * Require a feature to be initialized. It's up to the package consumer to actually add + * the package to their composer project. Declaring a requirement using this method + * instructs the class to initialize it. + * + * Run the options method (if exists) every time the method is called. + * + * @param String $feature the feature slug. + * @param array $options Additional options, optional. + */ + public function ensure( $feature, array $options = array() ) { + $this->config[ $feature ] = true; + + $this->set_feature_options( $feature, $options ); + + $method_options = 'ensure_options_' . $feature; + if ( method_exists( $this, $method_options ) ) { + $this->{ $method_options }(); + } + } + + /** + * Runs on plugins_loaded hook priority with priority 2. + * + * @action plugins_loaded + */ + public function on_plugins_loaded() { + if ( $this->config['connection'] ) { + $this->ensure_class( 'Automattic\Jetpack\Connection\Manager' ) + && $this->ensure_feature( 'connection' ); + } + + if ( $this->config['sync'] ) { + $this->ensure_class( 'Automattic\Jetpack\Sync\Main' ) + && $this->ensure_feature( 'sync' ); + } + + if ( $this->config['jitm'] ) { + // Check for the JITM class in both namespaces. The namespace was changed in jetpack-jitm v1.6. + ( $this->ensure_class( 'Automattic\Jetpack\JITMS\JITM', false ) + || $this->ensure_class( 'Automattic\Jetpack\JITM' ) ) + && $this->ensure_feature( 'jitm' ); + } + + if ( $this->config['post_list'] ) { + $this->ensure_class( 'Automattic\Jetpack\Post_List\Post_List' ) + && $this->ensure_feature( 'post_list' ); + } + + if ( $this->config['identity_crisis'] ) { + $this->ensure_class( 'Automattic\Jetpack\Identity_Crisis' ) + && $this->ensure_feature( 'identity_crisis' ); + } + + if ( $this->config['search'] ) { + $this->ensure_class( 'Automattic\Jetpack\Search\Initializer' ) + && $this->ensure_feature( 'search' ); + } + + if ( $this->config['publicize'] ) { + $this->ensure_class( 'Automattic\Jetpack\Publicize\Publicize_UI' ) && $this->ensure_class( 'Automattic\Jetpack\Publicize\Publicize' ) + && $this->ensure_feature( 'publicize' ); + } + + if ( $this->config['wordads'] ) { + $this->ensure_class( 'Automattic\Jetpack\WordAds\Initializer' ) + && $this->ensure_feature( 'wordads' ); + } + + if ( $this->config['waf'] ) { + $this->ensure_class( 'Automattic\Jetpack\Waf\Waf_Initializer' ) + && $this->ensure_feature( 'waf' ); + } + + if ( $this->config['videopress'] ) { + $this->ensure_class( 'Automattic\Jetpack\VideoPress\Initializer' ) && $this->ensure_feature( 'videopress' ); + } + if ( $this->config['stats'] ) { + $this->ensure_class( 'Automattic\Jetpack\Stats\Main' ) && $this->ensure_feature( 'stats' ); + } + if ( $this->config['stats_admin'] ) { + $this->ensure_class( 'Automattic\Jetpack\Stats_Admin\Main' ) && $this->ensure_feature( 'stats_admin' ); + } + + if ( $this->config['yoast_promo'] ) { + $this->ensure_class( 'Automattic\Jetpack\Yoast_Promo' ) && $this->ensure_feature( 'yoast_promo' ); + } + + if ( $this->config['import'] ) { + $this->ensure_class( 'Automattic\Jetpack\Import\Main' ) + && $this->ensure_feature( 'import' ); + } + } + + /** + * Returns true if the required class is available and alerts the user if it's not available + * in case the site is in debug mode. + * + * @param String $classname a fully qualified class name. + * @param Boolean $log_notice whether the E_USER_NOTICE should be generated if the class is not found. + * + * @return Boolean whether the class is available. + */ + protected function ensure_class( $classname, $log_notice = true ) { + $available = class_exists( $classname ); + + if ( $log_notice && ! $available && defined( 'WP_DEBUG' ) && WP_DEBUG ) { + trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error + sprintf( + /* translators: %1$s is a PHP class name. */ + esc_html__( + 'Unable to load class %1$s. Please add the package that contains it using composer and make sure you are requiring the Jetpack autoloader', + 'jetpack-config' + ), + esc_html( $classname ) + ), + E_USER_NOTICE + ); + } + + return $available; + } + + /** + * Ensures a feature is enabled, sets it up if it hasn't already been set up. + * + * @param String $feature slug of the feature. + * @return Integer either FEATURE_ENSURED, FEATURE_ALREADY_ENSURED or FEATURE_NOT_AVAILABLE constants. + */ + protected function ensure_feature( $feature ) { + $method = 'enable_' . $feature; + if ( ! method_exists( $this, $method ) ) { + return self::FEATURE_NOT_AVAILABLE; + } + + if ( did_action( 'jetpack_feature_' . $feature . '_enabled' ) ) { + return self::FEATURE_ALREADY_ENSURED; + } + + $this->{ $method }(); + + /** + * Fires when a specific Jetpack package feature is initalized using the Config package. + * + * @since 1.1.0 + */ + do_action( 'jetpack_feature_' . $feature . '_enabled' ); + + return self::FEATURE_ENSURED; + } + + /** + * Enables the JITM feature. + */ + protected function enable_jitm() { + if ( class_exists( 'Automattic\Jetpack\JITMS\JITM' ) ) { + JITMS_JITM::configure(); + } else { + // Provides compatibility with jetpack-jitm get_feature_options( 'publicize' ); + + if ( ! empty( $options['force_refresh'] ) ) { + Publicize_Setup::$refresh_plan_info = true; + } + } + + /** + * Enables WordAds. + */ + protected function enable_wordads() { + Jetpack_WordAds_Main::init(); + } + + /** + * Enables Waf. + */ + protected function enable_waf() { + Jetpack_Waf_Main::init(); + + return true; + } + + /** + * Enables VideoPress. + */ + protected function enable_videopress() { + VideoPress_Pkg_Initializer::init(); + return true; + } + + /** + * Enables Stats. + */ + protected function enable_stats() { + Stats_Main::init(); + return true; + } + + /** + * Enables Stats Admin. + */ + protected function enable_stats_admin() { + Stats_Admin_Main::init(); + return true; + } + + /** + * Handles VideoPress options + */ + protected function ensure_options_videopress() { + $options = $this->get_feature_options( 'videopress' ); + if ( ! empty( $options ) ) { + VideoPress_Pkg_Initializer::update_init_options( $options ); + } + return true; + } + + /** + * Enables Yoast Promo. + */ + protected function enable_yoast_promo() { + Yoast_Promo::init(); + return true; + } + + /** + * Enables the Import feature. + */ + protected function enable_import() { + Import_Main::configure(); + + return true; + } + + /** + * Setup the Connection options. + */ + protected function ensure_options_connection() { + $options = $this->get_feature_options( 'connection' ); + + if ( ! empty( $options['slug'] ) ) { + // The `slug` and `name` are removed from the options because they need to be passed as arguments. + $slug = $options['slug']; + unset( $options['slug'] ); + + $name = $slug; + if ( ! empty( $options['name'] ) ) { + $name = $options['name']; + unset( $options['name'] ); + } + + ( new Plugin( $slug ) )->add( $name, $options ); + } + + return true; + } + + /** + * Setup the Identity Crisis options. + * + * @return bool + */ + protected function ensure_options_identity_crisis() { + $options = $this->get_feature_options( 'identity_crisis' ); + + if ( is_array( $options ) && count( $options ) ) { + add_filter( + 'jetpack_idc_consumers', + function ( $consumers ) use ( $options ) { + $consumers[] = $options; + return $consumers; + } + ); + } + + return true; + } + + /** + * Setup the Sync options. + */ + protected function ensure_options_sync() { + $options = $this->get_feature_options( 'sync' ); + if ( method_exists( 'Automattic\Jetpack\Sync\Main', 'set_sync_data_options' ) ) { + Sync_Main::set_sync_data_options( $options ); + } + + return true; + } + + /** + * Temporary save initialization options for a feature. + * + * @param string $feature The feature slug. + * @param array $options The options. + * + * @return bool + */ + protected function set_feature_options( $feature, array $options ) { + if ( $options ) { + $this->feature_options[ $feature ] = $options; + } + + return true; + } + + /** + * Get initialization options for a feature from the temporary storage. + * + * @param string $feature The feature slug. + * + * @return array + */ + protected function get_feature_options( $feature ) { + return empty( $this->feature_options[ $feature ] ) ? array() : $this->feature_options[ $feature ]; + } +} diff --git a/vendor/automattic/jetpack-connection/CHANGELOG.md b/vendor/automattic/jetpack-connection/CHANGELOG.md new file mode 100644 index 00000000000..8a24847fe4d --- /dev/null +++ b/vendor/automattic/jetpack-connection/CHANGELOG.md @@ -0,0 +1,1058 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [1.58.1] - 2023-10-10 +### Changed +- Updated package dependencies. [#33428] + +## [1.58.0] - 2023-09-25 +### Added +- Disallow private IP addresses for site connection. [#32898] + +## [1.57.5] - 2023-09-19 + +- Minor internal updates. + +## [1.57.4] - 2023-09-13 +### Fixed +- Use JS to check if initial state is already rendered. [#32932] + +## [1.57.3] - 2023-09-11 +### Changed +- General: remove WP 6.1 backwards compatibility checks [#32772] + +## [1.57.2] - 2023-09-04 +### Changed +- Updated package dependencies. [#32803] + +## [1.57.1] - 2023-08-23 +### Changed +- Updated package dependencies. [#32605] + +## [1.57.0] - 2023-08-21 +### Added +- Better way to render initial state. [#32499] + +## [1.56.1] - 2023-08-09 +### Changed +- Updated package dependencies. [#32166] + +### Removed +- Tests: remove invalid tests for WP 6.3 [#32353] + +## [1.56.0] - 2023-08-01 +### Added +- Add a filter to modify response for the `jetpack.idcUrlValidation` endpoint, add unit test. [#32005] + +## [1.55.0] - 2023-07-25 +### Added +- Connection: lock tokens to prevent IDC during AIOWPM export. [#31883] + +## [1.54.1] - 2023-07-18 +### Fixed +- Pass Calypso environment during connection to redirect users to proper Calypso URL. [#31906] + +## [1.54.0] - 2023-07-17 +### Added +- Restore invalid connection owner ID. [#31618] + +## [1.53.3] - 2023-07-11 +### Changed +- Updated package dependencies. [#31785] + +## [1.53.2] - 2023-07-05 +### Changed +- Updated package dependencies. [#31659] + +## [1.53.1] - 2023-06-23 +### Changed +- Updated package dependencies. [#31468] + +## [1.53.0] - 2023-06-19 +### Changed +- Do not disconnect sites on WPCOM in Offline Mode. [#31305] + +## [1.52.2] - 2023-06-06 +### Changed +- Updated package dependencies. [#31129] + +## [1.52.1] - 2023-05-29 +### Added +- Include the user's email in data returned from WordPress.com Connected User data query [#30990] + +## [1.52.0] - 2023-05-22 +### Added +- Add Offline Mode flag into initial state. [#30570] + +## [1.51.10] - 2023-05-18 +### Changed +- PHP8 compatibility updates, mostly focusing on Jetpack. [#30714] + +## [1.51.9] - 2023-05-15 +### Changed +- Internal updates. + +## [1.51.8] - 2023-05-02 +### Changed +- Updated package dependencies. [#30375] + +## [1.51.7] - 2023-04-10 +### Added +- Add Jetpack Autoloader package suggestion. [#29988] + +## [1.51.6] - 2023-04-04 +### Changed +- Updated package dependencies. [#29854] + +### Removed +- Do not attempt to load non minified files since they are not shipped with the package anymore. [#29864] + +## [1.51.5] - 2023-03-29 +### Changed +- Minor internal updates. + +## [1.51.4] - 2023-03-28 +### Changed +- Minor internal updates. + +## [1.51.3] - 2023-03-27 +### Fixed +- Fix redirect allow-list for Calypso domain names. [#29671] + +## [1.51.2] - 2023-03-20 +### Changed +- Updated package dependencies. [#29471] + +## [1.51.1] - 2023-03-08 +### Changed +- Improve JS code in the connection owner removal notice. [#29087] +- Updated package dependencies. [#29216] + +## [1.51.0] - 2023-02-20 +### Changed +- Moving deleting connection owner notice from JITM to Connection package. [#28516] + +## [1.50.1] - 2023-02-15 +### Changed +- Update to React 18. [#28710] + +## [1.50.0] - 2023-02-07 +### Added +- Call the Licensing package for license verification. + +## [1.49.1] - 2023-01-25 +### Changed +- Minor internal updates. + +## [1.49.0] - 2023-01-11 +### Added +- Add new method to get a connected site's blog ID. [#28208] + +## [1.48.1] - 2022-12-27 +### Removed +- Remove src/js files from final bundle [#27931] + +## [1.48.0] - 2022-12-19 +### Changed +- Provide user locale when fetching info about connected WordPress.com user. [#27928] +- Update for PHP 8.2 compatibility. [#27949] + +### Fixed +- Declare fields for PHP 8.2 compatibility. [#27968] + +## [1.47.1] - 2022-12-02 +### Changed +- Updated package dependencies. [#27696] + +## [1.47.0] - 2022-11-30 +### Added +- Added full response logging for failed Sync data requests. [#27644] + +## [1.46.4] - 2022-11-22 +### Changed +- Updated package dependencies. [#27043] + +## [1.46.3] - 2022-11-08 +### Changed +- Updated package dependencies. [#27289] + +## [1.46.2] - 2022-11-07 +### Changed +- Updated package dependencies. [#27278] + +## [1.46.1] - 2022-11-01 +### Changed +- Updated package dependencies. + +## [1.46.0] - 2022-10-25 +### Changed +- Use blog token to unlink users from WPCOM. [#26705] + +## [1.45.5] - 2022-10-25 +### Added +- Connection: expose BlogId in the global state [#26978] + +## [1.45.4] - 2022-10-13 +### Changed +- Updated package dependencies. [#26791] + +## [1.45.3] - 2022-10-05 +### Changed +- Updated package dependencies. [#26568] + +### Fixed +- Clean connection errors after successful blog token restore. [#26489] + +## [1.45.2] - 2022-09-21 +### Fixed +- Check request body error type before creating wp error. [#26304] + +## [1.45.1] - 2022-09-20 +### Fixed +- Rename the initial state key to ensure compatibility with the JS package. [#26259] + +## [1.45.0] - 2022-09-08 +### Changed +- Add option to JP options [#25979] + +## [1.44.0] - 2022-08-29 +### Added +- Connection: verify REST API errors. + +## [1.43.1] - 2022-08-25 +### Changed +- Updated package dependencies. [#25814] + +## [1.43.0] - 2022-08-23 +### Added +- Added verified errors to the React initial state. [#25628] + +### Fixed +- Improved docs. [#25703] + +## [1.42.0] - 2022-08-03 +### Changed +- Refactoring to remove usage of deprecated methods and method arguments. [#25315] + +### Deprecated +- Removed deprecated method calls [#25300] + +## [1.41.8] - 2022-07-29 + +- Updated package dependencies + +## [1.41.7] - 2022-07-26 +### Changed +- Updated package dependencies. [#25158] + +### Fixed +- Tokens: edit return doc to highlight possibility of returning WP_Error. [#25127] + +## [1.41.6] - 2022-07-19 +### Changed +- Updated package dependencies. + +## [1.41.5] - 2022-07-12 +### Changed +- Updated package dependencies. + +## [1.41.4] - 2022-06-29 + +- Updated package dependencies. + +## [1.41.3] - 2022-06-28 +### Fixed +- Connection: fix fatal error due to undefined constant in remote_provision() + +## [1.41.2] - 2022-06-28 +### Removed +- Removed use of autounit tag [#24845] + +## [1.41.1] - 2022-06-21 +### Changed +- Renaming master to trunk. +- Renaming `master` references to `trunk` + +## [1.41.0] - 2022-06-14 +### Changed +- Updated package dependencies. [#24529] + +### Fixed +- Fixed old tk_ai regex to accurately match tk_ai ids. [#24697] +- Moved the connection_url_redirect action handling to the connection package. [#24529] + +## [1.40.5] - 2022-06-08 +### Changed +- Reorder JS imports for `import/order` eslint rule. [#24601] + +## [1.40.4] - 2022-05-24 +### Added +- Allow plugins to filter the list of available modules. Only activate and consider active modules that are available [#24454] + +## [1.40.3] - 2022-05-19 +### Added +- PHPCS updates. [#24418] + +## [1.40.2] - 2022-05-18 +### Changed +- Updated package dependencies [#24372] + +### Fixed +- Fix new PHPCS sniffs. [#24366] + +## [1.40.1] - 2022-05-10 +### Added +- Bundle and transpile JavaScript with Webpack. [#24216] + +### Changed +- Deprecate soft disconnect [#24105] + +## [1.40.0] - 2022-05-04 +### Added +- Connection: Expose wpVersion and siteSuffix in the global initial state var [#24137] + +### Deprecated +- Moved the options class into Connection. [#24095] + +## [1.39.2] - 2022-05-19 +### Added +- PHPCS updates. + +## [1.39.1] - 2022-04-27 +### Fixed +- Reverts soft disconnect deprecation + +## [1.39.0] - 2022-04-26 +### Changed +- Make remove_connection a proxy method to ensure all trackings are triggered +- Updated package dependencies. + +### Deprecated +- Removed Heartbeat by hoisting it into Connection. + +### Removed +- Deprecated Soft disconnect + +## [1.38.0] - 2022-04-19 +### Added +- Added list of connected list to the connection initial state +- Add token lock functionality. + +### Changed +- PHPCS: Fix `WordPress.Security.ValidatedSanitizedInput` + +### Deprecated +- Deprecated in-place connection. + +## [1.37.6] - 2022-04-12 +### Changed +- Updated package dependencies. + +## [1.37.5] - 2022-04-06 +### Removed +- Removed tracking dependency. + +## [1.37.4] - 2022-04-05 +### Changed +- Updated package dependencies. + +## [1.37.3] - 2022-03-29 +### Changed +- Microperformance: Use === null instead of is_null + +### Fixed +- Fix regression added to Jetpack webhooks handling + +## [1.37.2] - 2022-03-23 +### Changed +- Jetpack now relies on Connection Webooks for authorize and authorize_redirect actions + +### Removed +- Removed a reference to the terms-of-service package. + +## [1.37.1] - 2022-03-15 +### Added +- Handle the Authorization Redirect from the Connection package + +## [1.37.0] - 2022-03-02 +### Added +- Moved the ToS package to Connection. + +## [1.36.4] - 2022-02-22 +### Changed +- Updated package dependencies. + +## [1.36.3] - 2022-02-16 +### Added +- Add the 'jetpack_site_before_disconnected' action hook. + +## [1.36.2] - 2022-02-09 +### Fixed +- Fixed some new PHPCS warnings. + +## [1.36.1] - 2022-01-25 +### Changed +- Updated package dependencies. + +## [1.36.0] - 2022-01-18 +### Added +- Debugging: Add a filter to add XDEBUG_PROFILE to requests made to the sandbox. + +## [1.35.0] - 2022-01-13 +### Changed +- Added user data to initial state + +## [1.34.0] - 2022-01-04 +### Added +- Jetpack Connection: Added fallback for keeping `jetpack_connection_active_plugins` consistent on WPCOM when Sync is not present. + +### Changed +- Switch to pcov for code coverage. +- Updated package dependencies +- Updated package textdomain from `jetpack` to `jetpack-connection`. + +## [1.33.0] - 2021-12-14 +### Changed +- Jetpack Connection: handle package versions on site registration. + +## [1.32.0] - 2021-11-30 +### Added +- Added a way to set the has_seen_wc_connection_modal option from the API +- Provides an Initial State that can be used by JS packages + +### Changed +- Updated package dependencies. + +## [1.31.0] - 2021-11-22 +### Added +- Added plugin_slug parameter to the v4/register endpoint + +### Changed +- Updated package dependencies + +## [1.30.13] - 2021-11-09 +### Fixed +- Fix PHP 8.1 deprecation warning. + +## [1.30.12] - 2021-11-02 +### Added +- Client: add IDC query args to remote requests + +### Changed +- Set `convertDeprecationsToExceptions` true in PHPUnit config. +- Update PHPUnit configs to include just what needs coverage rather than include everything then try to exclude stuff that doesn't. + +## [1.30.11] - 2021-10-26 +### Changed +- Change the error code returned when a remoteRegister XMLRPC call is executed to the more helpful "already_registered" when the blog is already registered +- Updated package dependencies. + +## [1.30.10] - 2021-10-19 +### Deprecated +- General: remove numerous long-deprecated functions. + +### Fixed +- Fix permission check for authorization_url endpoint. + +## [1.30.9] - 2021-10-13 +### Changed +- Updated package dependencies. + +## [1.30.8] - 2021-10-12 +### Added +- Add a new action to the Client::remote_request method, jetpack_received_remote_request_response + +### Changed +- Updated package dependencies + +## [1.30.7] - 2021-10-04 +### Added +- Sandbox Server: add the sandbox-server class to the connection package. + +## [1.30.6] - 2021-09-30 +### Changed +- Moved the Package Tracker execution to the shutdown hook for performance improvement. + +## [1.30.5] - 2021-09-28 +### Changed +- Package Version Tracker: send package versions to wpcom on the init hook instead of plugins_loaded +- Updated package dependencies. + +### Fixed +- Load WordPress's IXR classes on demand. + +## [1.30.4] - 2021-09-02 +### Fixed +- Remove invalid user token before reconnect. + +## [1.30.3] - 2021-08-30 +### Added +- Limit repeated failed attempts to update remote DNA package versions. + +### Changed +- Make sure generated secrets have the required length +- Remove tracked package versions when disconnecting the site. +- Run composer update on test-php command instead of phpunit +- Tests: update PHPUnit polyfills dependency (yoast/phpunit-polyfills). +- update annotations versions + +## [1.30.2] - 2021-08-12 +### Added +- Add package version tracking. + +## [1.30.1] - 2021-07-27 +### Added +- Add a package version constant. + +### Changed +- Move connection/data endpoint to Connection package. +- Move site disconnection endpoint to Connection package. + +### Fixed +- Fix `@covers` directives in tests. + +## [1.30.0] - 2021-07-13 +### Added +- Added second parameter to Tokens::get_connected_users to allow any connected user to be returned. + +### Changed +- Moved the get_connected_users logic back to the Manager class + +## [1.29.0] - 2021-06-29 +### Changed +- Implement disconnect_site function. +- Updated package dependencies. + +## [1.28.0] - 2021-06-15 +### Added +- Added Urls class, migrated from Sync Functions. +- Adding new REST endpoint /jetpack/v4/user-token that allows us to add/update user tokens remotely. +- Add new 'connection/authorize_url' endpoint. +- Adds information received from the server to the register_site REST response. +- Enable site-level authentication (blog token) for REST API endpoints. +- Move 'connection/owner' endpoint to Connection package. + +## [1.27.0] - 2021-05-25 +### Added +- Add "isUserConnected" to the connection status data. +- Connection: add the default value of JETPACK__WPCOM_JSON_API_BASE to the Connection Utils class. + +### Changed +- Connection package independence: Move a Jetpack specfic connection routine out of the package and into the plugin +- Package Independence: Add a filter to the remote_uri returned by remote_register XMLRPC method + +### Removed +- Removed "user-less" jargon from code +- Remove do_post_authorization routine and add a hook instead +- Remove onboarding_token logic in the Remote provision XMLRPC method from the Connection package and add it to the Jetpack plugin + +### Fixed +- Disconnection flow: disconnect users from WordPress.com before to delete data locally. + +## [1.26.0] - 2021-04-27 +### Added +- Adds segmentation "from" parameter to the registration flow +- Connection: moving the registration REST endpoint to the package. + +### Changed +- Added "userless" parameter to the authorization URL. +- Updated package dependencies. + +## [1.25.2] - 2021-04-13 +### Fixed +- Connection: nonce cleanup safeguard against accidental option removal. + +## [1.25.1] - 2021-04-08 +### Fixed +- Avoid determine_current_user going through infinite loops +- Tokens: Fix token validation logic. + +## [1.25.0] - 2021-03-30 +### Added +- Add new test for blog token health to support user-less sites +- Composer alias for dev-master, to improve dependencies + +### Changed +- API Nonces: performance optimization and refactoring +- Replace is_active usage towards gradually deprecating it. +- Do not use is_active to determine the XMLRPC methods that should be registered +- Make connected_plugins REST endpoint available for the Jetpack Debugger +- Move Jetpack specific XMLRPC methods from the Connection package into the plugin +- Update package dependencies. +- User-less connection: Reconnect without asking the user to connect their WPCOM account + +### Deprecated +- add deprecation notice and remove user-less check in is_active + +### Fixed +- Only check offline mode when needed in map_meta_cap filters +- Use `composer update` rather than `install` in scripts, as composer.lock isn't checked in. + +## [1.24.0] - 2021-02-23 + +- Refactor secrets and tokens +- User-less connection: Restrict first connection to admins only +- Connection: Prevent pointless calls to the test API +- CI: Make tests more generic +- Connection: extracting the Jetpack's authorization webhook +- codesniffer: Update mediawiki-codesniffer dep to v35.0 + +## [1.23.2] - 2021-02-08 + +- Connection: Prevent pointless calls to the test API + +## [1.23.1] - 2021-01-28 + +- Update dependencies to latest stable + +## [1.23.0] - 2021-01-26 + +- Sync Concurrency / Race Conditions +- Add mirror-repo information to all current composer packages +- Mirroring: Fix auth, attempt 2 +- Monorepo: Reorganize all projects + +## [1.22.0] - 2021-01-05 + +- Connection: setting valid connection owner. +- userless testing mode: do not discard user tokens +- Pin dependencies +- Packages: Update for PHP 8 testing +- Connection: New methods and tests to the manager +- Connection: refreshing connected plugin storage on multisite networks +- Build: migrate from Travis to GH Actions +- fix typos and add section to error handling docs + +## [1.21.1] - 2020-11-24 + +- Version packages for release + +## [1.21.0] - 2020-11-24 + +- Handle empty SERVER_PORT information on signature checks +- Fix remaining phpcs warnings in most of requirelist +- Add the no_user_testing mode +- Clarified error message for non-writable options table. +- Pass HTTP POST when making a wp.com api request + +## [1.20.0] - 2020-10-29 + +- Connection: Plugin Tracking +- Connection Package: Ensure a text/xml header is set +- Updated PHPCS: Packages and Debugger + +## [1.19.2] - 2020-11-05 + +- Pass HTTP POST when making a wp.com api request + +## [1.19.1] - 2020-10-29 + +- Connection: Plugin Tracking + +## [1.19.0] - 2020-10-27 + +- Connection Errors: Tracking additional error data +- Replaced intval() with (int) as part of issue #17432. +- Replaced strval() with type casting (string) as part of issue #17432. +- Connection: Add wp.com function +- Instagram oEmbed: Simplify +- Client: Extract `validate_args_for_wpcom_json_api_request` helper. +- Connection: add the constant filter hooks directly +- Make XMLRPC methods available for blog token +- API Nonces: Revert of the Runtime Cleanup. +- PHPCS: Update directory structure, and modernize class usage +- deprecates JETPACK_MASTER_USER and adds linter +- API: Remove the constant `JETPACK_CLIENT__HTTPS`. + +## [1.18.4] - 2020-10-14 + +- Connection: Add wp.com function + +## [1.18.3] - 2020-10-09 + +- Connection: add the constant filter hooks directly + +## [1.18.2] - 2020-10-06 + +- API Nonces: Revert of the Runtime Cleanup. + +## [1.18.1] - 2020-10-01 + +- deprecates JETPACK_MASTER_USER and adds linter + +## [1.18.0] - 2020-09-29 + +- API Nonces: Runtime cleanup +- Packages: update list of files distributed in production packages +- Connection: Add success message on completed partial reconnection +- Jetpack_IXR_ClientMulticall: Fix sort_calls() producing undefined relative order between equal items +- Connection: Initializing default constants for the REST authorization. +- Trigger action jetpack_user_authorize after we save the token +- Partial reconnect: Cleanup redundant actions +- Signature Class: Adds support for nested query strings + +## [1.17.2] - 2020-09-16 + +- Connection: Initializing default constants for the REST authorization. + +## [1.17.1] - 2020-09-09 + +- Update dependencies to latest stable + +## [1.17.0] - 2020-08-26 + +- Connection: move the rest authentication methods to the connection package +- Connection: use heartbeat to send connected plugins info +- clear xmlrpc error on site disconnect +- add new features to debug helper +- remove no longer needed check +- disable xmlrpc errors out of JP dashboard +- Connection REST API: Unit test for the `remote_authorize` request. +- Simplify error notices for broken connections +- Unit Tests: Fixing a failing `remote_authorize` test. +- Reconnect Process: Partial Reconnect +- Packages: Update filenames after #16810 +- CI: Try collect js coverage +- Docker: Add package testing shortcut +- Remove usages of removed HTTP_RAW_POST_DATA +- adds tracking for deleted but active master users +- New class to handle async XML-RPC requests +- Connection Register: Add current user email to connection register request + +## [1.15.2] - 2020-08-10 + +- Connection Register: Add current user email to connection register request + +## [1.15.1] - 2020-08-10 + +- adds tracking for deleted but active master users + +## [1.15.0] - 2020-07-28 + +- Core Compat: Site Environment +- Reconnect Notice: In-place Reconnect +- add messages for some common connection errors +- REST API: Move some endpoints to `jetpack-connection` package. +- REST API: Add permission callback to all that lack one. +- Secondary user in-place connection flow +- Tests: Update WorDBless location +- Connection Errors: Clear when there's a successful request to /sites +- Connection: add unit tests for is_registered +- only display connection errors to allowed users + +## [1.14.2] - 2020-07-06 + +- Connection Errors: Clear when there's a successful request to /sites + +## [1.14.1] - 2020-07-01 + +- only display connection errors to allowed users + +## [1.14.0] - 2020-06-30 + +- Jetpack_XMLRPC_Server: set up jsonAPI and testConnection endpoint when Jetpack is active +- Connection Error Handling +- Connection: Update XMLRPC overload +- Connection: move connection custom caps to the Connection package +- Connection package: Don't throw warnings if the database is corrupted somehow +- Check blog token when computing is_registered +- Connection: add the api_constant filter before setup_xmlrpc_handlers is called +- Connection Package: Soft Disconnects +- Remove usage of the Jetpack_Error class in the connection package +- Connection: Fix issue where ABSPATH not included with register + +## [1.13.1] - 2020-06-01 + +- Connection: Fix issue where ABSPATH not included with register + +## [1.13.0] - 2020-05-26 + +- Store the list of active plugins that uses connection in an option +- Connection: increase timeout on the token request +- Connection Package: Handle disconnections gracefully + +## [1.12.0] - 2020-04-28 + +- Correct inline documentation "Array" type +- Use jp.com redirect in all links +- Docs: Update the Connection Manager namespace, a minor typo +- Connection: add a filter for setting Jetpack api constants + +## [1.11.0] - 2020-03-31 + +- Update dependencies to latest stable + +## [1.10.0] - 2020-03-31 + +- Connection: move post authorization work to package + +## [1.9.0] - 2020-02-25 + +## [1.8.3] - 2020-02-14 + +## [1.8.2] - 2020-02-12 + +## [1.8.1] - 2020-02-12 + +- Added a specific filter to enable iframe authorization API URL. +- Added better defaults for the connection package. + +## [1.8.0] - 2020-01-27 + +- Connection\Utils: Add a new function which provides the Jetpack API version +- Connection\Manager: Use jetpack_master_user class constant + +## [1.7.2] - 2020-01-20 + +- Move connection manager related logic to after plugins_loaded. + +## [1.7.1] - 2020-01-14 + +- Packages: Various improvements for wp.com or self-contained consumers + +## [1.7.0] - 2019-11-26 + +- Connection package: Add new methods to for disconnecting/delet… + +## [1.6.1] - 2019-11-25 + +- Connection: Loose Comparison for Port Number in Signatures + +## [1.6.0] - 2019-11-19 + +## [1.5.0] - 2019-11-15 + +- Removed Jetpack references in the IXR client. +- Connection: Move get_token() to Connection package + +## [1.4.0] - 2019-11-15 + +- Add connection authentication URL. +- Connection: Move the authorize() method to the connection package +- Connection: Move update_user_token to the Connection package +- Connection: Set the value of user_id in Manager::generate_secrets + +## [1.3.1] - 2019-11-08 + +- Packages: Use classmap instead of PSR-4 +- Moved tracking code to the Tracking file. + +## [1.3.0] - 2019-11-08 + +- Move fix_url_for_bad_hosts from Jetpack class to Connection pa… + +## [1.2.0] - 2019-11-07 + +- Connection: call verify_secrets() in verify_action() + +## [1.1.0] - 2019-10-31 + +- Adds filter capability to the api_url method. + +## [1.0.7] - 2019-10-28 + +- Packages: Add gitattributes files to all packages that need th… +- Replace parse_url with wp_parse_url + +## [1.0.6] - 2019-10-07 + +- Update dependency phpcompatibility/phpcompatibility-wp to v2.1.0 + +## [1.0.5] - 2019-09-26 + +- XMLRPC: Fires clean_nonce action in all cases + +## [1.0.4] - 2019-09-24 + +- Connection: Make sure port is an integer + +## [1.0.3] - 2019-09-23 + +- Moves unreachable code to where it would be run. +- Connection: Deprecate Manager interface + +## [1.0.2] - 2019-09-23 + +- Connection: Fix all PHPCS errors in the connection package + +## [1.0.1] - 2019-09-20 + +- Various: Remove pre-PHP 5.6 shims and fallbacks +- Store "Assumed site creation date" in transient +- Sync: Move sync_object XML-RPC method from connection to sync +- Connection: Fix PHPCS errors in Jetpack_Signature +- Docs: Unify usage of @package phpdoc tags +- Janitorial: Remove the leading backslash from namespaces + +## 1.0.0 - 2019-09-14 + +- Separate the connection library into its own package. + +[1.58.1]: https://github.com/Automattic/jetpack-connection/compare/v1.58.0...v1.58.1 +[1.58.0]: https://github.com/Automattic/jetpack-connection/compare/v1.57.5...v1.58.0 +[1.57.5]: https://github.com/Automattic/jetpack-connection/compare/v1.57.4...v1.57.5 +[1.57.4]: https://github.com/Automattic/jetpack-connection/compare/v1.57.3...v1.57.4 +[1.57.3]: https://github.com/Automattic/jetpack-connection/compare/v1.57.2...v1.57.3 +[1.57.2]: https://github.com/Automattic/jetpack-connection/compare/v1.57.1...v1.57.2 +[1.57.1]: https://github.com/Automattic/jetpack-connection/compare/v1.57.0...v1.57.1 +[1.57.0]: https://github.com/Automattic/jetpack-connection/compare/v1.56.1...v1.57.0 +[1.56.1]: https://github.com/Automattic/jetpack-connection/compare/v1.56.0...v1.56.1 +[1.56.0]: https://github.com/Automattic/jetpack-connection/compare/v1.55.0...v1.56.0 +[1.55.0]: https://github.com/Automattic/jetpack-connection/compare/v1.54.1...v1.55.0 +[1.54.1]: https://github.com/Automattic/jetpack-connection/compare/v1.54.0...v1.54.1 +[1.54.0]: https://github.com/Automattic/jetpack-connection/compare/v1.53.3...v1.54.0 +[1.53.3]: https://github.com/Automattic/jetpack-connection/compare/v1.53.2...v1.53.3 +[1.53.2]: https://github.com/Automattic/jetpack-connection/compare/v1.53.1...v1.53.2 +[1.53.1]: https://github.com/Automattic/jetpack-connection/compare/v1.53.0...v1.53.1 +[1.53.0]: https://github.com/Automattic/jetpack-connection/compare/v1.52.2...v1.53.0 +[1.52.2]: https://github.com/Automattic/jetpack-connection/compare/v1.52.1...v1.52.2 +[1.52.1]: https://github.com/Automattic/jetpack-connection/compare/v1.52.0...v1.52.1 +[1.52.0]: https://github.com/Automattic/jetpack-connection/compare/v1.51.10...v1.52.0 +[1.51.10]: https://github.com/Automattic/jetpack-connection/compare/v1.51.9...v1.51.10 +[1.51.9]: https://github.com/Automattic/jetpack-connection/compare/v1.51.8...v1.51.9 +[1.51.8]: https://github.com/Automattic/jetpack-connection/compare/v1.51.7...v1.51.8 +[1.51.7]: https://github.com/Automattic/jetpack-connection/compare/v1.51.6...v1.51.7 +[1.51.6]: https://github.com/Automattic/jetpack-connection/compare/v1.51.5...v1.51.6 +[1.51.5]: https://github.com/Automattic/jetpack-connection/compare/v1.51.4...v1.51.5 +[1.51.4]: https://github.com/Automattic/jetpack-connection/compare/v1.51.3...v1.51.4 +[1.51.3]: https://github.com/Automattic/jetpack-connection/compare/v1.51.2...v1.51.3 +[1.51.2]: https://github.com/Automattic/jetpack-connection/compare/v1.51.1...v1.51.2 +[1.51.1]: https://github.com/Automattic/jetpack-connection/compare/v1.51.0...v1.51.1 +[1.51.0]: https://github.com/Automattic/jetpack-connection/compare/v1.50.1...v1.51.0 +[1.50.1]: https://github.com/Automattic/jetpack-connection/compare/v1.50.0...v1.50.1 +[1.50.0]: https://github.com/Automattic/jetpack-connection/compare/v1.49.1...v1.50.0 +[1.49.1]: https://github.com/Automattic/jetpack-connection/compare/v1.49.0...v1.49.1 +[1.49.0]: https://github.com/Automattic/jetpack-connection/compare/v1.48.1...v1.49.0 +[1.48.1]: https://github.com/Automattic/jetpack-connection/compare/v1.48.0...v1.48.1 +[1.48.0]: https://github.com/Automattic/jetpack-connection/compare/v1.47.1...v1.48.0 +[1.47.1]: https://github.com/Automattic/jetpack-connection/compare/v1.47.0...v1.47.1 +[1.47.0]: https://github.com/Automattic/jetpack-connection/compare/v1.46.4...v1.47.0 +[1.46.4]: https://github.com/Automattic/jetpack-connection/compare/v1.46.3...v1.46.4 +[1.46.3]: https://github.com/Automattic/jetpack-connection/compare/v1.46.2...v1.46.3 +[1.46.2]: https://github.com/Automattic/jetpack-connection/compare/v1.46.1...v1.46.2 +[1.46.1]: https://github.com/Automattic/jetpack-connection/compare/v1.46.0...v1.46.1 +[1.46.0]: https://github.com/Automattic/jetpack-connection/compare/v1.45.5...v1.46.0 +[1.45.5]: https://github.com/Automattic/jetpack-connection/compare/v1.45.4...v1.45.5 +[1.45.4]: https://github.com/Automattic/jetpack-connection/compare/v1.45.3...v1.45.4 +[1.45.3]: https://github.com/Automattic/jetpack-connection/compare/v1.45.2...v1.45.3 +[1.45.2]: https://github.com/Automattic/jetpack-connection/compare/v1.45.1...v1.45.2 +[1.45.1]: https://github.com/Automattic/jetpack-connection/compare/v1.45.0...v1.45.1 +[1.45.0]: https://github.com/Automattic/jetpack-connection/compare/v1.44.0...v1.45.0 +[1.44.0]: https://github.com/Automattic/jetpack-connection/compare/v1.43.1...v1.44.0 +[1.43.1]: https://github.com/Automattic/jetpack-connection/compare/v1.43.0...v1.43.1 +[1.43.0]: https://github.com/Automattic/jetpack-connection/compare/v1.42.0...v1.43.0 +[1.42.0]: https://github.com/Automattic/jetpack-connection/compare/v1.41.8...v1.42.0 +[1.41.8]: https://github.com/Automattic/jetpack-connection/compare/v1.41.7...v1.41.8 +[1.41.7]: https://github.com/Automattic/jetpack-connection/compare/v1.41.6...v1.41.7 +[1.41.6]: https://github.com/Automattic/jetpack-connection/compare/v1.41.5...v1.41.6 +[1.41.5]: https://github.com/Automattic/jetpack-connection/compare/v1.41.4...v1.41.5 +[1.41.4]: https://github.com/Automattic/jetpack-connection/compare/v1.41.3...v1.41.4 +[1.41.3]: https://github.com/Automattic/jetpack-connection/compare/v1.41.2...v1.41.3 +[1.41.2]: https://github.com/Automattic/jetpack-connection/compare/v1.41.1...v1.41.2 +[1.41.1]: https://github.com/Automattic/jetpack-connection/compare/v1.41.0...v1.41.1 +[1.41.0]: https://github.com/Automattic/jetpack-connection/compare/v1.40.5...v1.41.0 +[1.40.5]: https://github.com/Automattic/jetpack-connection/compare/v1.40.4...v1.40.5 +[1.40.4]: https://github.com/Automattic/jetpack-connection/compare/v1.40.3...v1.40.4 +[1.40.3]: https://github.com/Automattic/jetpack-connection/compare/v1.40.2...v1.40.3 +[1.40.2]: https://github.com/Automattic/jetpack-connection/compare/v1.40.1...v1.40.2 +[1.40.1]: https://github.com/Automattic/jetpack-connection/compare/v1.40.0...v1.40.1 +[1.40.0]: https://github.com/Automattic/jetpack-connection/compare/v1.39.1...v1.40.0 +[1.39.2]: https://github.com/Automattic/jetpack-connection/compare/v1.39.1...v1.39.2 +[1.39.1]: https://github.com/Automattic/jetpack-connection/compare/v1.39.0...v1.39.1 +[1.39.0]: https://github.com/Automattic/jetpack-connection/compare/v1.38.0...v1.39.0 +[1.38.0]: https://github.com/Automattic/jetpack-connection/compare/v1.37.6...v1.38.0 +[1.37.6]: https://github.com/Automattic/jetpack-connection/compare/v1.37.5...v1.37.6 +[1.37.5]: https://github.com/Automattic/jetpack-connection/compare/v1.37.4...v1.37.5 +[1.37.4]: https://github.com/Automattic/jetpack-connection/compare/v1.37.3...v1.37.4 +[1.37.3]: https://github.com/Automattic/jetpack-connection/compare/v1.37.2...v1.37.3 +[1.37.2]: https://github.com/Automattic/jetpack-connection/compare/v1.37.1...v1.37.2 +[1.37.1]: https://github.com/Automattic/jetpack-connection/compare/v1.37.0...v1.37.1 +[1.37.0]: https://github.com/Automattic/jetpack-connection/compare/v1.36.4...v1.37.0 +[1.36.4]: https://github.com/Automattic/jetpack-connection/compare/v1.36.3...v1.36.4 +[1.36.3]: https://github.com/Automattic/jetpack-connection/compare/v1.36.2...v1.36.3 +[1.36.2]: https://github.com/Automattic/jetpack-connection/compare/v1.36.1...v1.36.2 +[1.36.1]: https://github.com/Automattic/jetpack-connection/compare/v1.36.0...v1.36.1 +[1.36.0]: https://github.com/Automattic/jetpack-connection/compare/v1.35.0...v1.36.0 +[1.35.0]: https://github.com/Automattic/jetpack-connection/compare/v1.34.0...v1.35.0 +[1.34.0]: https://github.com/Automattic/jetpack-connection/compare/v1.33.0...v1.34.0 +[1.33.0]: https://github.com/Automattic/jetpack-connection/compare/v1.32.0...v1.33.0 +[1.32.0]: https://github.com/Automattic/jetpack-connection/compare/v1.31.0...v1.32.0 +[1.31.0]: https://github.com/Automattic/jetpack-connection/compare/v1.30.13...v1.31.0 +[1.30.13]: https://github.com/Automattic/jetpack-connection/compare/v1.30.12...v1.30.13 +[1.30.12]: https://github.com/Automattic/jetpack-connection/compare/v1.30.11...v1.30.12 +[1.30.11]: https://github.com/Automattic/jetpack-connection/compare/v1.30.10...v1.30.11 +[1.30.10]: https://github.com/Automattic/jetpack-connection/compare/v1.30.9...v1.30.10 +[1.30.9]: https://github.com/Automattic/jetpack-connection/compare/v1.30.8...v1.30.9 +[1.30.8]: https://github.com/Automattic/jetpack-connection/compare/v1.30.7...v1.30.8 +[1.30.7]: https://github.com/Automattic/jetpack-connection/compare/v1.30.6...v1.30.7 +[1.30.6]: https://github.com/Automattic/jetpack-connection/compare/v1.30.5...v1.30.6 +[1.30.5]: https://github.com/Automattic/jetpack-connection/compare/v1.30.4...v1.30.5 +[1.30.4]: https://github.com/Automattic/jetpack-connection/compare/v1.30.3...v1.30.4 +[1.30.3]: https://github.com/Automattic/jetpack-connection/compare/v1.30.2...v1.30.3 +[1.30.2]: https://github.com/Automattic/jetpack-connection/compare/v1.30.1...v1.30.2 +[1.30.1]: https://github.com/Automattic/jetpack-connection/compare/v1.30.0...v1.30.1 +[1.30.0]: https://github.com/Automattic/jetpack-connection/compare/v1.29.0...v1.30.0 +[1.29.0]: https://github.com/Automattic/jetpack-connection/compare/v1.28.0...v1.29.0 +[1.28.0]: https://github.com/Automattic/jetpack-connection/compare/v1.27.0...v1.28.0 +[1.27.0]: https://github.com/Automattic/jetpack-connection/compare/v1.26.0...v1.27.0 +[1.26.0]: https://github.com/Automattic/jetpack-connection/compare/v1.25.2...v1.26.0 +[1.25.2]: https://github.com/Automattic/jetpack-connection/compare/v1.25.1...v1.25.2 +[1.25.1]: https://github.com/Automattic/jetpack-connection/compare/v1.25.0...v1.25.1 +[1.25.0]: https://github.com/Automattic/jetpack-connection/compare/v1.24.0...v1.25.0 +[1.24.0]: https://github.com/Automattic/jetpack-connection/compare/v1.23.2...v1.24.0 +[1.23.2]: https://github.com/Automattic/jetpack-connection/compare/v1.23.1...v1.23.2 +[1.23.1]: https://github.com/Automattic/jetpack-connection/compare/v1.23.0...v1.23.1 +[1.23.0]: https://github.com/Automattic/jetpack-connection/compare/v1.22.0...v1.23.0 +[1.22.0]: https://github.com/Automattic/jetpack-connection/compare/v1.21.1...v1.22.0 +[1.21.1]: https://github.com/Automattic/jetpack-connection/compare/v1.21.0...v1.21.1 +[1.21.0]: https://github.com/Automattic/jetpack-connection/compare/v1.20.0...v1.21.0 +[1.20.0]: https://github.com/Automattic/jetpack-connection/compare/v1.19.2...v1.20.0 +[1.19.2]: https://github.com/Automattic/jetpack-connection/compare/v1.19.1...v1.19.2 +[1.19.1]: https://github.com/Automattic/jetpack-connection/compare/v1.19.0...v1.19.1 +[1.19.0]: https://github.com/Automattic/jetpack-connection/compare/v1.18.4...v1.19.0 +[1.18.4]: https://github.com/Automattic/jetpack-connection/compare/v1.18.3...v1.18.4 +[1.18.3]: https://github.com/Automattic/jetpack-connection/compare/v1.18.2...v1.18.3 +[1.18.2]: https://github.com/Automattic/jetpack-connection/compare/v1.18.1...v1.18.2 +[1.18.1]: https://github.com/Automattic/jetpack-connection/compare/v1.18.0...v1.18.1 +[1.18.0]: https://github.com/Automattic/jetpack-connection/compare/v1.17.2...v1.18.0 +[1.17.2]: https://github.com/Automattic/jetpack-connection/compare/v1.17.1...v1.17.2 +[1.17.1]: https://github.com/Automattic/jetpack-connection/compare/v1.17.0...v1.17.1 +[1.17.0]: https://github.com/Automattic/jetpack-connection/compare/v1.15.2...v1.17.0 +[1.15.2]: https://github.com/Automattic/jetpack-connection/compare/v1.15.1...v1.15.2 +[1.15.1]: https://github.com/Automattic/jetpack-connection/compare/v1.15.0...v1.15.1 +[1.15.0]: https://github.com/Automattic/jetpack-connection/compare/v1.14.2...v1.15.0 +[1.14.2]: https://github.com/Automattic/jetpack-connection/compare/v1.14.1...v1.14.2 +[1.14.1]: https://github.com/Automattic/jetpack-connection/compare/v1.14.0...v1.14.1 +[1.14.0]: https://github.com/Automattic/jetpack-connection/compare/v1.13.1...v1.14.0 +[1.13.1]: https://github.com/Automattic/jetpack-connection/compare/v1.13.0...v1.13.1 +[1.13.0]: https://github.com/Automattic/jetpack-connection/compare/v1.12.0...v1.13.0 +[1.12.0]: https://github.com/Automattic/jetpack-connection/compare/v1.11.0...v1.12.0 +[1.11.0]: https://github.com/Automattic/jetpack-connection/compare/1.10.0...v1.11.0 +[1.10.0]: https://github.com/Automattic/jetpack-connection/compare/v1.9.0...1.10.0 +[1.9.0]: https://github.com/Automattic/jetpack-connection/compare/v1.8.3...v1.9.0 +[1.8.3]: https://github.com/Automattic/jetpack-connection/compare/v1.8.2...v1.8.3 +[1.8.2]: https://github.com/Automattic/jetpack-connection/compare/v1.8.1...v1.8.2 +[1.8.1]: https://github.com/Automattic/jetpack-connection/compare/v1.8.0...v1.8.1 +[1.8.0]: https://github.com/Automattic/jetpack-connection/compare/v1.7.2...v1.8.0 +[1.7.2]: https://github.com/Automattic/jetpack-connection/compare/v1.7.1...v1.7.2 +[1.7.1]: https://github.com/Automattic/jetpack-connection/compare/v1.7.0...v1.7.1 +[1.7.0]: https://github.com/Automattic/jetpack-connection/compare/v1.6.1...v1.7.0 +[1.6.1]: https://github.com/Automattic/jetpack-connection/compare/v1.6.0...v1.6.1 +[1.6.0]: https://github.com/Automattic/jetpack-connection/compare/v1.5.0...v1.6.0 +[1.5.0]: https://github.com/Automattic/jetpack-connection/compare/v1.4.0...v1.5.0 +[1.4.0]: https://github.com/Automattic/jetpack-connection/compare/v1.3.1...v1.4.0 +[1.3.1]: https://github.com/Automattic/jetpack-connection/compare/v1.3.0...v1.3.1 +[1.3.0]: https://github.com/Automattic/jetpack-connection/compare/v1.2.0...v1.3.0 +[1.2.0]: https://github.com/Automattic/jetpack-connection/compare/v1.1.0...v1.2.0 +[1.1.0]: https://github.com/Automattic/jetpack-connection/compare/v1.0.7...v1.1.0 +[1.0.7]: https://github.com/Automattic/jetpack-connection/compare/v1.0.6...v1.0.7 +[1.0.6]: https://github.com/Automattic/jetpack-connection/compare/v1.0.5...v1.0.6 +[1.0.5]: https://github.com/Automattic/jetpack-connection/compare/v1.0.4...v1.0.5 +[1.0.4]: https://github.com/Automattic/jetpack-connection/compare/v1.0.3...v1.0.4 +[1.0.3]: https://github.com/Automattic/jetpack-connection/compare/v1.0.2...v1.0.3 +[1.0.2]: https://github.com/Automattic/jetpack-connection/compare/v1.0.1...v1.0.2 +[1.0.1]: https://github.com/Automattic/jetpack-connection/compare/v1.0.0...v1.0.1 diff --git a/vendor/automattic/jetpack-connection/LICENSE.txt b/vendor/automattic/jetpack-connection/LICENSE.txt new file mode 100644 index 00000000000..e82774c1bd5 --- /dev/null +++ b/vendor/automattic/jetpack-connection/LICENSE.txt @@ -0,0 +1,357 @@ +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +=================================== + + +GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + + Preamble + +The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + +We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + +Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and +modification follow. + +GNU GENERAL PUBLIC LICENSE +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + +a) You must cause the modified files to carry prominent notices +stating that you changed the files and the date of any change. + +b) You must cause any work that you distribute or publish, that in +whole or in part contains or is derived from the Program or any +part thereof, to be licensed as a whole at no charge to all third +parties under the terms of this License. + +c) If the modified program normally reads commands interactively +when run, you must cause it, when started running for such +interactive use in the most ordinary way, to print or display an +announcement including an appropriate copyright notice and a +notice that there is no warranty (or else, saying that you provide +a warranty) and that users may redistribute the program under +these conditions, and telling the user how to view a copy of this +License. (Exception: if the Program itself is interactive but +does not normally print such an announcement, your work based on +the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + +a) Accompany it with the complete corresponding machine-readable +source code, which must be distributed under the terms of Sections +1 and 2 above on a medium customarily used for software interchange; or, + +b) Accompany it with a written offer, valid for at least three +years, to give any third party, for a charge no more than your +cost of physically performing source distribution, a complete +machine-readable copy of the corresponding source code, to be +distributed under the terms of Sections 1 and 2 above on a medium +customarily used for software interchange; or, + +c) Accompany it with the information you received as to the offer +to distribute corresponding source code. (This alternative is +allowed only for noncommercial distribution and only if you +received the program in object code or executable form with such +an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + +5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + +7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + +10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + +Copyright (C) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + +Gnomovision version 69, Copyright (C) year name of author +Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. +This is free software, and you are welcome to redistribute it +under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in the program +`Gnomovision' (which makes passes at compilers) written by James Hacker. + +, 1 April 1989 +Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/vendor/automattic/jetpack-connection/README.md b/vendor/automattic/jetpack-connection/README.md new file mode 100644 index 00000000000..6be8594d95e --- /dev/null +++ b/vendor/automattic/jetpack-connection/README.md @@ -0,0 +1,35 @@ +# Jetpack Connection Package + +Let's talk to wordpress.com! + +## Get Started + +Package is published in [Packagist](https://packagist.org/packages/automattic/jetpack-connection). We recommend using the latest version there, or you can also test with the latest development versions like below: + +``` +"require": { + "automattic/jetpack-autoloader": "dev-trunk", + "automattic/jetpack-config": "dev-trunk", + "automattic/jetpack-connection": "dev-trunk" +} +``` + +## Guides +* [Connection package guide](docs/register-site.md) + +## Tools + +1. [Making Authenticated async XML-RPC calls](docs/xmlrpc-async-calls.md) +1. [Customizing error messages](docs/error-handling.md) + +## Using this package in your WordPress plugin + +If you plan on using this package in your WordPress plugin, we would recommend that you use [Jetpack Autoloader](https://packagist.org/packages/automattic/jetpack-autoloader) as your autoloader. This will allow for maximum interoperability with other plugins that use this package as well. + +## Security + +Need to report a security vulnerability? Go to [https://automattic.com/security/](https://automattic.com/security/) or directly to our security bug bounty site [https://hackerone.com/automattic](https://hackerone.com/automattic). + +## License + +jetpack-connection is licensed under [GNU General Public License v2 (or later)](./LICENSE.txt) diff --git a/vendor/automattic/jetpack-connection/SECURITY.md b/vendor/automattic/jetpack-connection/SECURITY.md new file mode 100644 index 00000000000..b4b46c0ee23 --- /dev/null +++ b/vendor/automattic/jetpack-connection/SECURITY.md @@ -0,0 +1,38 @@ +# Security Policy + +Full details of the Automattic Security Policy can be found on [automattic.com](https://automattic.com/security/). + +## Supported Versions + +Generally, only the latest version of Jetpack has continued support. If a critical vulnerability is found in the current version of Jetpack, we may opt to backport any patches to previous versions. + +## Reporting a Vulnerability + +[Jetpack](https://jetpack.com/) is an open-source plugin for WordPress. Our HackerOne program covers the plugin software, as well as a variety of related projects and infrastructure. + +**For responsible disclosure of security issues and to be eligible for our bug bounty program, please submit your report via the [HackerOne](https://hackerone.com/automattic) portal.** + +Our most critical targets are: + +* Jetpack and the Jetpack composer packages (all within this repo) +* Jetpack.com -- the primary marketing site. +* cloud.jetpack.com -- a management site. +* wordpress.com -- the shared management site for both Jetpack and WordPress.com sites. + +For more targets, see the `In Scope` section on [HackerOne](https://hackerone.com/automattic). + +_Please note that the **WordPress software is a separate entity** from Automattic. Please report vulnerabilities for WordPress through [the WordPress Foundation's HackerOne page](https://hackerone.com/wordpress)._ + +## Guidelines + +We're committed to working with security researchers to resolve the vulnerabilities they discover. You can help us by following these guidelines: + +* Follow [HackerOne's disclosure guidelines](https://www.hackerone.com/disclosure-guidelines). +* Pen-testing Production: + * Please **setup a local environment** instead whenever possible. Most of our code is open source (see above). + * If that's not possible, **limit any data access/modification** to the bare minimum necessary to reproduce a PoC. + * **_Don't_ automate form submissions!** That's very annoying for us, because it adds extra work for the volunteers who manage those systems, and reduces the signal/noise ratio in our communication channels. + * To be eligible for a bounty, all of these guidelines must be followed. +* Be Patient - Give us a reasonable time to correct the issue before you disclose the vulnerability. + +We also expect you to comply with all applicable laws. You're responsible to pay any taxes associated with your bounties. diff --git a/vendor/automattic/jetpack-connection/TRACKING.md b/vendor/automattic/jetpack-connection/TRACKING.md new file mode 100644 index 00000000000..06754b3e7f9 --- /dev/null +++ b/vendor/automattic/jetpack-connection/TRACKING.md @@ -0,0 +1,122 @@ +# Jetpack Tracking package + +A package containing functionality to track events to the a8c Tracks system + +## Usage + +There are several ways to track events using this package. + +* Ajax: Probably the easiest one. You can simply add a class to a link and it will be tracked or you can make your own ajax call +* PHP: Track an event on the backend +* Tracking pixel: An alternative way to track events by dynamically adding a pixel to the DOM + +### Tracking via Ajax + +This is useful to track simple click events without the need of any additional js. Just add the appropriate class to your links and it will be tracked. + +#### 1. enqueue script + +Note: Not needed if you are using the Jetpack plugin in the admin context as the script is already loaded by Jetpack. + +See `Automattic\Jetpack\Tracking::enqueue_tracks_scripts()` + +```PHP +add_action( 'admin_enqueue_scripts', array( new Tracking( 'plugin-slug' ), 'enqueue_tracks_scripts' ) ); +``` + +#### 2. Add the class and the event attributes. + +Add the `jptracks` class to any `a` element or to its parent element. + +The event needs a name. This can be informed with the `data-jptracks-name` attritbute. + +```HTML +Click me +``` + +And that's it. Your event will be tracked. Every time this element is clicked an ajax call will be triggered to the Tracking package and it will send it to wpcom. + +**Note:** Event name will be automatically prefixed with `jetpack_`. + +#### 3. Additional parameters + +You can also inform additional parameters to your event using the `data-jptracks-prop` attribute. Anything in this attr will be stored in the `clicked` attribute in the event. + +#### 4. Making your own ajax calls + +In your JS you can set up your own ajax calls. Example: + +```JS +window.jpTracksAJAX.record_ajax_event( 'my_event_name', 'click', { prop1: value1, prop2: value2 } ); +``` + +**Note:** Event name will be automatically prefixed with `jetpack_`. + +##### Waiting for the ajax call to complete before doing anything else + +If you need to do a subsequent action but wants to wait for this event to be tracked, you can do the following: + +```JS +window.jpTracksAJAX + .record_ajax_event( 'my_event_name', 'click', { prop1: value1, prop2: value2 } ) + .always( function() { + // do something + } ); +``` + +### Tracking in PHP + +Use `Automattic\Jetpack\Tracking::record_user_event()` to track events on the backend. + +```PHP +$connection_manager = new Automattic\Jetpack\Connection\Manager( 'plugin-slug' ); +$tracking = new Tracking( 'plugin-slug', $connection_manager ); +$tracking->record_user_event( + $event_name, + array( + 'property_key' => 'value', + ) +); +``` + +### Tracking pixel + +This approach to track events uses `//stats.wp.com/w.js` and dynamically adds a tracking pixel to the DOM to do the tracking. + +#### 1. Enqueue the scripts + +```PHP +Tracking::register_tracks_functions_scripts( true ); +``` + +#### 2. Inform the user data + +```PHP +wp_localize_script( + 'my_script', + 'varname', + array( + 'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(), + ) +); +``` + +#### 3. Track! + +In your JS: + +```JS +var tracksUser = varname.tracksUserData; + +analytics.initialize( tracksUser.userid, tracksUser.username ); + +analytics.tracks.recordEvent( 'jetpack_my_event_name', { prop1: value1, prop2: value2 } ); +``` + +## Debugging + +You can watch your events being tracked in the browser console. In order to activate that, run the following command in the console: + +```JS +localStorage.setItem( 'debug', 'dops:analytics*' ); +``` diff --git a/vendor/automattic/jetpack-connection/composer.json b/vendor/automattic/jetpack-connection/composer.json new file mode 100644 index 00000000000..33d9965f88c --- /dev/null +++ b/vendor/automattic/jetpack-connection/composer.json @@ -0,0 +1,67 @@ +{ + "name": "automattic/jetpack-connection", + "description": "Everything needed to connect to the Jetpack infrastructure", + "type": "jetpack-library", + "license": "GPL-2.0-or-later", + "require": { + "automattic/jetpack-a8c-mc-stats": "^1.4.22", + "automattic/jetpack-admin-ui": "^0.2.23", + "automattic/jetpack-constants": "^1.6.23", + "automattic/jetpack-roles": "^1.4.25", + "automattic/jetpack-status": "^1.18.5", + "automattic/jetpack-redirect": "^1.7.27" + }, + "require-dev": { + "automattic/wordbless": "@dev", + "yoast/phpunit-polyfills": "1.1.0", + "brain/monkey": "2.6.1", + "automattic/jetpack-changelogger": "^3.3.11" + }, + "suggest": { + "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." + }, + "autoload": { + "classmap": [ + "legacy", + "src/", + "src/webhooks" + ] + }, + "scripts": { + "build-production": [ + "pnpm run build-production" + ], + "build-development": [ + "pnpm run build" + ], + "phpunit": [ + "./vendor/phpunit/phpunit/phpunit --colors=always" + ], + "post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy", + "post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy", + "test-php": [ + "@composer phpunit" + ] + }, + "minimum-stability": "dev", + "prefer-stable": true, + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-connection", + "textdomain": "jetpack-connection", + "version-constants": { + "::PACKAGE_VERSION": "src/class-package-version.php" + }, + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-connection/compare/v${old}...v${new}" + }, + "branch-alias": { + "dev-trunk": "1.58.x-dev" + } + }, + "config": { + "allow-plugins": { + "roots/wordpress-core-installer": true + } + } +} diff --git a/vendor/automattic/jetpack-connection/dist/tracks-ajax.asset.php b/vendor/automattic/jetpack-connection/dist/tracks-ajax.asset.php new file mode 100644 index 00000000000..e354ece038b --- /dev/null +++ b/vendor/automattic/jetpack-connection/dist/tracks-ajax.asset.php @@ -0,0 +1 @@ + array(), 'version' => '2c644cc46566ed615c42'); diff --git a/vendor/automattic/jetpack-connection/dist/tracks-ajax.js b/vendor/automattic/jetpack-connection/dist/tracks-ajax.js new file mode 100644 index 00000000000..7b63022223d --- /dev/null +++ b/vendor/automattic/jetpack-connection/dist/tracks-ajax.js @@ -0,0 +1 @@ +!function(t,a){window.jpTracksAJAX=window.jpTracksAJAX||{};const c="dops:analytics"===localStorage.getItem("debug");window.jpTracksAJAX.record_ajax_event=function(n,e,r){const o={tracksNonce:a.jpTracksAJAX_nonce,action:"jetpack_tracks",tracksEventType:e,tracksEventName:n,tracksEventProp:r||!1};return t.ajax({type:"POST",url:a.ajaxurl,data:o,success:function(t){c&&console.log("AJAX tracks event recorded: ",o,t)}})},t(document).ready((function(){t("body").on("click",".jptracks a, a.jptracks",(function(a){const c=t(a.target),n=c.closest(".jptracks"),e=n.attr("data-jptracks-name");if(void 0===e)return;const r=n.attr("data-jptracks-prop")||!1,o=c.attr("href"),s=c.get(0).target;let i=null;o&&s&&"_self"!==s&&(i=window.open("",s),i.opener=null),a.preventDefault(),window.jpTracksAJAX.record_ajax_event(e,"click",r).always((function(){if(o&&!c.hasClass("thickbox")){if(i)return void(i.location=o);window.location=o}}))}))}))}(jQuery,jpTracksAJAX); \ No newline at end of file diff --git a/vendor/automattic/jetpack-connection/dist/tracks-callables.asset.php b/vendor/automattic/jetpack-connection/dist/tracks-callables.asset.php new file mode 100644 index 00000000000..20fd33c93e2 --- /dev/null +++ b/vendor/automattic/jetpack-connection/dist/tracks-callables.asset.php @@ -0,0 +1 @@ + array(), 'version' => 'a96178e4d62fb695caa0'); diff --git a/vendor/automattic/jetpack-connection/dist/tracks-callables.js b/vendor/automattic/jetpack-connection/dist/tracks-callables.js new file mode 100644 index 00000000000..fe1068ce243 --- /dev/null +++ b/vendor/automattic/jetpack-connection/dist/tracks-callables.js @@ -0,0 +1 @@ +!function(){var e={775:function(e){let n;window._tkq=window._tkq||[];const t=console.error;const o={initialize:function(e,n){o.setUser(e,n),o.identifyUser()},mc:{bumpStat:function(e,n){const t=function(e,n){let t="";if("object"==typeof e)for(const n in e)t+="&x_"+encodeURIComponent(n)+"="+encodeURIComponent(e[n]);else t="&x_"+encodeURIComponent(e)+"="+encodeURIComponent(n);return t}(e,n);(new Image).src=document.location.protocol+"//pixel.wp.com/g.gif?v=wpcom-no-pv"+t+"&t="+Math.random()}},tracks:{recordEvent:function(e,n){n=n||{},0===e.indexOf("jetpack_")?window._tkq.push(["recordEvent",e,n]):t('- Event name must be prefixed by "jetpack_"')},recordPageView:function(e){o.tracks.recordEvent("jetpack_page_view",{path:e})}},setUser:function(e,t){n={ID:e,username:t}},identifyUser:function(){n&&window._tkq.push(["identifyUser",n.ID,n.username])},clearedIdentity:function(){window._tkq.push(["clearIdentity"])}};e.exports=o}},n={};var t=function t(o){var r=n[o];if(void 0!==r)return r.exports;var i=n[o]={exports:{}};return e[o](i,i.exports,t),i.exports}(775);window.analytics=t}(); \ No newline at end of file diff --git a/vendor/automattic/jetpack-connection/legacy/class-jetpack-ixr-client.php b/vendor/automattic/jetpack-connection/legacy/class-jetpack-ixr-client.php new file mode 100644 index 00000000000..10796274b57 --- /dev/null +++ b/vendor/automattic/jetpack-connection/legacy/class-jetpack-ixr-client.php @@ -0,0 +1,180 @@ + $connection->xmlrpc_api_url(), + 'user_id' => 0, + 'headers' => array(), + ); + + $args = wp_parse_args( $args, $defaults ); + $args['headers'] = array_merge( array( 'Content-Type' => 'text/xml' ), (array) $args['headers'] ); + + $this->jetpack_args = $args; + + $this->IXR_Client( $args['url'], $path, $port, $timeout ); + } + + /** + * Perform the IXR request. + * + * @param string[] ...$args IXR args. + * + * @return bool True if request succeeded, false otherwise. + */ + public function query( ...$args ) { + $method = array_shift( $args ); + $request = new IXR_Request( $method, $args ); + $xml = trim( $request->getXml() ); + + $response = Client::remote_request( $this->jetpack_args, $xml ); + + // Store response headers. + $this->response_headers = wp_remote_retrieve_headers( $response ); + + $this->last_response = $response; + if ( is_array( $this->last_response ) && isset( $this->last_response['http_response'] ) ) { + // If the expected array response is received, format the data as plain arrays. + $this->last_response = $this->last_response['http_response']->to_array(); + $this->last_response['headers'] = $this->last_response['headers']->getAll(); + } + + if ( is_wp_error( $response ) ) { + $this->error = new IXR_Error( -10520, sprintf( 'Jetpack: [%s] %s', $response->get_error_code(), $response->get_error_message() ) ); + return false; + } + + if ( ! $response ) { + $this->error = new IXR_Error( -10520, 'Jetpack: Unknown Error' ); + return false; + } + + if ( 200 !== wp_remote_retrieve_response_code( $response ) ) { + $this->error = new IXR_Error( -32300, 'transport error - HTTP status code was not 200' ); + return false; + } + + $content = wp_remote_retrieve_body( $response ); + + // Now parse what we've got back. + $this->message = new IXR_Message( $content ); + if ( ! $this->message->parse() ) { + // XML error. + $this->error = new IXR_Error( -32700, 'parse error. not well formed' ); + return false; + } + + // Is the message a fault? + if ( 'fault' === $this->message->messageType ) { + $this->error = new IXR_Error( $this->message->faultCode, $this->message->faultString ); + return false; + } + + // Message must be OK. + return true; + } + + /** + * Retrieve the Jetpack error from the result of the last request. + * + * @param int $fault_code Fault code. + * @param string $fault_string Fault string. + * @return WP_Error Error object. + */ + public function get_jetpack_error( $fault_code = null, $fault_string = null ) { + if ( $fault_code === null ) { + $fault_code = $this->error->code; + } + + if ( $fault_string === null ) { + $fault_string = $this->error->message; + } + + if ( preg_match( '#jetpack:\s+\[(\w+)\]\s*(.*)?$#i', $fault_string, $match ) ) { + $code = $match[1]; + $message = $match[2]; + $status = $fault_code; + return new \WP_Error( $code, $message, $status ); + } + + return new \WP_Error( "IXR_{$fault_code}", $fault_string ); + } + + /** + * Retrieve a response header if set. + * + * @param string $name header name. + * @return string|bool Header value if set, false if not set. + */ + public function get_response_header( $name ) { + if ( isset( $this->response_headers[ $name ] ) ) { + return $this->response_headers[ $name ]; + } + // case-insensitive header names: http://www.ietf.org/rfc/rfc2616.txt. + if ( isset( $this->response_headers[ strtolower( $name ) ] ) ) { + return $this->response_headers[ strtolower( $name ) ]; + } + return false; + } + + /** + * Retrieve the raw response for the last query() call. + * + * @return null|array|WP_Error + */ + public function get_last_response() { + return $this->last_response; + } +} diff --git a/vendor/automattic/jetpack-connection/legacy/class-jetpack-ixr-clientmulticall.php b/vendor/automattic/jetpack-connection/legacy/class-jetpack-ixr-clientmulticall.php new file mode 100644 index 00000000000..3c52f05d4ce --- /dev/null +++ b/vendor/automattic/jetpack-connection/legacy/class-jetpack-ixr-clientmulticall.php @@ -0,0 +1,74 @@ + $method_name, + 'params' => $args, + ); + $this->calls[] = $struct; + } + + /** + * Perform the IXR multicall request. + * + * @param string[] ...$args IXR args. + * + * @return bool True if request succeeded, false otherwise. + */ + public function query( ...$args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + $this->calls = $this->sort_calls( $this->calls ); + + // Prepare multicall, then call the parent::query() method. + return parent::query( 'system.multicall', $this->calls ); + } + + /** + * Sort the IXR calls. + * Make sure syncs are always done first preserving relative order. + * + * @param array $calls Calls to sort. + * @return array Sorted calls. + */ + public function sort_calls( $calls ) { + $sync_calls = array(); + $other_calls = array(); + + foreach ( $calls as $call ) { + if ( 'jetpack.syncContent' === $call['methodName'] ) { + $sync_calls[] = $call; + } else { + $other_calls[] = $call; + } + } + + return array_merge( $sync_calls, $other_calls ); + } +} diff --git a/vendor/automattic/jetpack-connection/legacy/class-jetpack-options.php b/vendor/automattic/jetpack-connection/legacy/class-jetpack-options.php new file mode 100644 index 00000000000..6ba242eb85c --- /dev/null +++ b/vendor/automattic/jetpack-connection/legacy/class-jetpack-options.php @@ -0,0 +1,694 @@ + 'jetpack_options', + 'private' => 'jetpack_private_options', + ); + + /** + * Returns an array of option names for a given type. + * + * @param string $type The type of option to return. Defaults to 'compact'. + * + * @return array + */ + public static function get_option_names( $type = 'compact' ) { + switch ( $type ) { + case 'non-compact': + case 'non_compact': + return array( + 'activated', + 'active_modules', + 'active_modules_initialized', // (bool) used to determine that all the default modules were activated, so we know how to act on a reconnection. + 'allowed_xsite_search_ids', // (array) Array of WP.com blog ids that are allowed to search the content of this site + 'available_modules', + 'do_activate', + 'edit_links_calypso_redirect', // (bool) Whether post/page edit links on front end should point to Calypso. + 'log', + 'slideshow_background_color', + 'widget_twitter', + 'wpcc_options', + 'relatedposts', + 'file_data', + 'autoupdate_plugins', // (array) An array of plugin ids ( eg. jetpack/jetpack ) that should be autoupdated + 'autoupdate_plugins_translations', // (array) An array of plugin ids ( eg. jetpack/jetpack ) that should be autoupdated translation files. + 'autoupdate_themes', // (array) An array of theme ids ( eg. twentyfourteen ) that should be autoupdated + 'autoupdate_themes_translations', // (array) An array of theme ids ( eg. twentyfourteen ) that should autoupdated translation files. + 'autoupdate_core', // (bool) Whether or not to autoupdate core + 'autoupdate_translations', // (bool) Whether or not to autoupdate all translations + 'json_api_full_management', // (bool) Allow full management (eg. Activate, Upgrade plugins) of the site via the JSON API. + 'sync_non_public_post_stati', // (bool) Allow synchronisation of posts and pages with non-public status. + 'site_icon_url', // (string) url to the full site icon + 'site_icon_id', // (int) Attachment id of the site icon file + 'dismissed_manage_banner', // (bool) Dismiss Jetpack manage banner allows the user to dismiss the banner permanently + 'unique_connection', // (array) A flag to determine a unique connection to wordpress.com two values "connected" and "disconnected" with values for how many times each has occured + 'unique_registrations', // (integer) A counter of how many times the site was registered + 'protect_whitelist', // (array) IP Address for the Protect module to ignore + 'sync_error_idc', // (bool|array) false or array containing the site's home and siteurl at time of IDC error + 'sync_health_status', // (bool|array) An array of data relating to Jetpack's sync health. + 'safe_mode_confirmed', // (bool) True if someone confirms that this site was correctly put into safe mode automatically after an identity crisis is discovered. + 'migrate_for_idc', // (bool) True if someone confirms that this site should migrate stats and subscribers from its previous URL + 'dismissed_connection_banner', // (bool) True if the connection banner has been dismissed + 'ab_connect_banner_green_bar', // (int) Version displayed of the A/B test for the green bar at the top of the connect banner. + 'onboarding', // (string) Auth token to be used in the onboarding connection flow + 'tos_agreed', // (bool) Whether or not the TOS for connection has been agreed upon. + 'static_asset_cdn_files', // (array) An nested array of files that we can swap out for cdn versions. + 'mapbox_api_key', // (string) Mapbox API Key, for use with Map block. + 'mailchimp', // (string) Mailchimp keyring data, for mailchimp block. + 'xmlrpc_errors', // (array) Keys are XML-RPC signature error codes. Values are truthy. + 'dismissed_wizard_banner', // (int) (DEPRECATED) True if the Wizard banner has been dismissed. + ); + + case 'private': + return array( + 'blog_token', // (string) The Client Secret/Blog Token of this site. + 'user_token', // (string) The User Token of this site. (deprecated) + 'user_tokens', // (array) User Tokens for each user of this site who has connected to jetpack.wordpress.com. + 'purchase_token', // (string) Token for logged out user purchases. + 'token_lock', // (string) Token lock in format `expiration_date|||site_url`. + ); + + case 'network': + return array( + 'onboarding', // (string) Auth token to be used in the onboarding connection flow + 'file_data', // (array) List of absolute paths to all Jetpack modules + ); + } + + return array( + 'id', // (int) The Client ID/WP.com Blog ID of this site. + 'publicize_connections', // (array) An array of Publicize connections from WordPress.com. + 'master_user', // (int) The local User ID of the user who connected this site to jetpack.wordpress.com. + 'version', // (string) Used during upgrade procedure to auto-activate new modules. version:time. + 'old_version', // (string) Used to determine which modules are the most recently added. previous_version:time. + 'fallback_no_verify_ssl_certs', // (int) Flag for determining if this host must skip SSL Certificate verification due to misconfigured SSL. + 'time_diff', // (int) Offset between Jetpack server's clocks and this server's clocks. Jetpack Server Time = time() + (int) Jetpack_Options::get_option( 'time_diff' ) + 'public', // (int|bool) If we think this site is public or not (1, 0), false if we haven't yet tried to figure it out. + 'videopress', // (array) VideoPress options array. + 'is_network_site', // (int|bool) If we think this site is a network or a single blog (1, 0), false if we haven't yet tried to figue it out. + 'social_links', // (array) The specified links for each social networking site. + 'identity_crisis_whitelist', // (array) An array of options, each having an array of the values whitelisted for it. + 'gplus_authors', // (array) The Google+ authorship information for connected users. + 'last_heartbeat', // (int) The timestamp of the last heartbeat that fired. + 'hide_jitm', // (array) A list of just in time messages that we should not show because they have been dismissed by the user. + 'custom_css_4.7_migration', // (bool) Whether Custom CSS has scanned for and migrated any legacy CSS CPT entries to the new Core format. + 'image_widget_migration', // (bool) Whether any legacy Image Widgets have been converted to the new Core widget. + 'gallery_widget_migration', // (bool) Whether any legacy Gallery Widgets have been converted to the new Core widget. + 'sso_first_login', // (bool) Is this the first time the user logins via SSO. + 'dismissed_hints', // (array) Part of Plugin Search Hints. List of cards that have been dismissed. + 'first_admin_view', // (bool) Set to true the first time the user views the admin. Usually after the initial connection. + 'setup_wizard_questionnaire', // (array) (DEPRECATED) List of user choices from the setup wizard. + 'setup_wizard_status', // (string) (DEPRECATED) Status of the setup wizard. + 'licensing_error', // (string) Last error message occurred while attaching licenses that is yet to be surfaced to the user. + 'recommendations_banner_dismissed', // (bool) Determines if the recommendations dashboard banner is dismissed or not. + 'recommendations_banner_enabled', // (bool) Whether the recommendations are enabled or not. + 'recommendations_data', // (array) The user choice and other data for the recommendations. + 'recommendations_step', // (string) The current step of the recommendations. + 'recommendations_conditional', // (array) An array of action-based recommendations. + 'licensing_activation_notice_dismiss', // (array) The `last_detached_count` and the `last_dismissed_time` for the user-license activation notice. + 'has_seen_wc_connection_modal', // (bool) Whether the site has displayed the WooCommerce Connection modal + 'partner_coupon', // (string) A Jetpack partner issued coupon to promote a sale together with Jetpack. + 'partner_coupon_added', // (string) A date for when `partner_coupon` was added, so we can auto-purge after a certain time interval. + 'dismissed_backup_review_restore', // (bool) Determines if the component review request is dismissed for successful restore requests. + 'dismissed_backup_review_backups', // (bool) Determines if the component review request is dismissed for successful backup requests. + 'identity_crisis_url_secret', // (array) The IDC URL secret and its expiration date. + ); + } + + /** + * Is the option name valid? + * + * @param string $name The name of the option. + * @param string|null $group The name of the group that the option is in. Default to null, which will search non_compact. + * + * @return bool Is the option name valid? + */ + public static function is_valid( $name, $group = null ) { + if ( is_array( $name ) ) { + $compact_names = array(); + foreach ( array_keys( self::$grouped_options ) as $_group ) { + $compact_names = array_merge( $compact_names, self::get_option_names( $_group ) ); + } + + $result = array_diff( $name, self::get_option_names( 'non_compact' ), $compact_names ); + + return empty( $result ); + } + + if ( $group === null || 'non_compact' === $group ) { + if ( in_array( $name, self::get_option_names( $group ), true ) ) { + return true; + } + } + + foreach ( array_keys( self::$grouped_options ) as $_group ) { + if ( $group === null || $group === $_group ) { + if ( in_array( $name, self::get_option_names( $_group ), true ) ) { + return true; + } + } + } + + return false; + } + + /** + * Checks if an option must be saved for the whole network in WP Multisite + * + * @param string $option_name Option name. It must come _without_ `jetpack_%` prefix. The method will prefix the option name. + * + * @return bool + */ + public static function is_network_option( $option_name ) { + if ( ! is_multisite() ) { + return false; + } + return in_array( $option_name, self::get_option_names( 'network' ), true ); + } + + /** + * Filters the requested option. + * This is a wrapper around `get_option_from_database` so that we can filter the option. + * + * @param string $name Option name. It must come _without_ `jetpack_%` prefix. The method will prefix the option name. + * @param mixed $default (optional). + * + * @return mixed + */ + public static function get_option( $name, $default = false ) { + /** + * Filter Jetpack Options. + * Can be useful in environments when Jetpack is running with a different setup + * + * @since 1.7.0 + * + * @param string $value The value from the database. + * @param string $name Option name, _without_ `jetpack_%` prefix. + * @return string $value, unless the filters modify it. + */ + return apply_filters( 'jetpack_options', self::get_option_from_database( $name, $default ), $name ); + } + + /** + * Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate. + * + * @param string $name Option name. It must come _without_ `jetpack_%` prefix. The method will prefix the option name. + * @param mixed $default (optional). + * + * @return mixed + */ + private static function get_option_from_database( $name, $default = false ) { + if ( self::is_valid( $name, 'non_compact' ) ) { + if ( self::is_network_option( $name ) ) { + return get_site_option( "jetpack_$name", $default ); + } + + return get_option( "jetpack_$name", $default ); + } + + foreach ( array_keys( self::$grouped_options ) as $group ) { + if ( self::is_valid( $name, $group ) ) { + return self::get_grouped_option( $group, $name, $default ); + } + } + + trigger_error( sprintf( 'Invalid Jetpack option name: %s', esc_html( $name ) ), E_USER_WARNING ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error -- Don't wish to change legacy behavior. + + return $default; + } + + /** + * Returns the requested option, and ensures it's autoloaded in the future. + * This does _not_ adjust the prefix in any way (does not prefix jetpack_%) + * + * @param string $name Option name. + * @param mixed $default (optional). + * + * @return mixed + */ + public static function get_option_and_ensure_autoload( $name, $default ) { + // In this function the name is not adjusted by prefixing jetpack_ + // so if it has already prefixed, we'll replace it and then + // check if the option name is a network option or not. + $jetpack_name = preg_replace( '/^jetpack_/', '', $name, 1 ); + $is_network_option = self::is_network_option( $jetpack_name ); + $value = $is_network_option ? get_site_option( $name ) : get_option( $name ); + + if ( false === $value && false !== $default ) { + if ( $is_network_option ) { + add_site_option( $name, $default ); + } else { + add_option( $name, $default ); + } + $value = $default; + } + + return $value; + } + + /** + * Update grouped option + * + * @param string $group Options group. + * @param string $name Options name. + * @param mixed $value Options value. + * + * @return bool Success or failure. + */ + private static function update_grouped_option( $group, $name, $value ) { + $options = get_option( self::$grouped_options[ $group ] ); + if ( ! is_array( $options ) ) { + $options = array(); + } + $options[ $name ] = $value; + + return update_option( self::$grouped_options[ $group ], $options ); + } + + /** + * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate. + * + * @param string $name Option name. It must come _without_ `jetpack_%` prefix. The method will prefix the option name. + * @param mixed $value Option value. + * @param string $autoload If not compact option, allows specifying whether to autoload or not. + * + * @return bool Was the option successfully updated? + */ + public static function update_option( $name, $value, $autoload = null ) { + /** + * Fires before Jetpack updates a specific option. + * + * @since 1.1.2 + * @since-jetpack 3.0.0 + * + * @param str $name The name of the option being updated. + * @param mixed $value The new value of the option. + */ + do_action( 'pre_update_jetpack_option_' . $name, $name, $value ); + if ( self::is_valid( $name, 'non_compact' ) ) { + if ( self::is_network_option( $name ) ) { + return update_site_option( "jetpack_$name", $value ); + } + + return update_option( "jetpack_$name", $value, $autoload ); + + } + + foreach ( array_keys( self::$grouped_options ) as $group ) { + if ( self::is_valid( $name, $group ) ) { + return self::update_grouped_option( $group, $name, $value ); + } + } + + trigger_error( sprintf( 'Invalid Jetpack option name: %s', esc_html( $name ) ), E_USER_WARNING ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error -- Don't want to change legacy behavior. + + return false; + } + + /** + * Updates the multiple given options. Updates jetpack_options and/or jetpack_$name as appropriate. + * + * @param array $array array( option name => option value, ... ). + */ + public static function update_options( $array ) { + $names = array_keys( $array ); + + foreach ( array_diff( $names, self::get_option_names(), self::get_option_names( 'non_compact' ), self::get_option_names( 'private' ) ) as $unknown_name ) { + trigger_error( sprintf( 'Invalid Jetpack option name: %s', esc_html( $unknown_name ) ), E_USER_WARNING ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error -- Don't change legacy behavior. + unset( $array[ $unknown_name ] ); + } + + foreach ( $names as $name ) { + self::update_option( $name, $array[ $name ] ); + } + } + + /** + * Deletes the given option. May be passed multiple option names as an array. + * Updates jetpack_options and/or deletes jetpack_$name as appropriate. + * + * @param string|array $names Option names. They must come _without_ `jetpack_%` prefix. The method will prefix the option names. + * + * @return bool Was the option successfully deleted? + */ + public static function delete_option( $names ) { + $result = true; + $names = (array) $names; + + if ( ! self::is_valid( $names ) ) { + // phpcs:disable -- This line triggers a handful of errors; ignoring to avoid changing legacy behavior. + trigger_error( sprintf( 'Invalid Jetpack option names: %s', print_r( $names, 1 ) ), E_USER_WARNING ); + // phpcs:enable + return false; + } + + foreach ( array_intersect( $names, self::get_option_names( 'non_compact' ) ) as $name ) { + if ( self::is_network_option( $name ) ) { + $result = delete_site_option( "jetpack_$name" ); + } else { + $result = delete_option( "jetpack_$name" ); + } + } + + foreach ( array_keys( self::$grouped_options ) as $group ) { + if ( ! self::delete_grouped_option( $group, $names ) ) { + $result = false; + } + } + + return $result; + } + + /** + * Get group option. + * + * @param string $group Option group name. + * @param string $name Option name. + * @param mixed $default Default option value. + * + * @return mixed Option. + */ + private static function get_grouped_option( $group, $name, $default ) { + $options = get_option( self::$grouped_options[ $group ] ); + if ( is_array( $options ) && isset( $options[ $name ] ) ) { + return $options[ $name ]; + } + + return $default; + } + + /** + * Delete grouped option. + * + * @param string $group Option group name. + * @param array $names Option names. + * + * @return bool Success or failure. + */ + private static function delete_grouped_option( $group, $names ) { + $options = get_option( self::$grouped_options[ $group ], array() ); + + $to_delete = array_intersect( $names, self::get_option_names( $group ), array_keys( $options ) ); + if ( $to_delete ) { + foreach ( $to_delete as $name ) { + unset( $options[ $name ] ); + } + + return update_option( self::$grouped_options[ $group ], $options ); + } + + return true; + } + + /* + * Raw option methods allow Jetpack to get / update / delete options via direct DB queries, including options + * that are not created by the Jetpack plugin. This is helpful only in rare cases when we need to bypass + * cache and filters. + */ + + /** + * Deletes an option via $wpdb query. + * + * @param string $name Option name. + * + * @return bool Is the option deleted? + */ + public static function delete_raw_option( $name ) { + if ( self::bypass_raw_option( $name ) ) { + return delete_option( $name ); + } + global $wpdb; + $result = $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name = %s", $name ) ); + return $result; + } + + /** + * Updates an option via $wpdb query. + * + * @param string $name Option name. + * @param mixed $value Option value. + * @param bool $autoload Specifying whether to autoload or not. + * + * @return bool Is the option updated? + */ + public static function update_raw_option( $name, $value, $autoload = false ) { + if ( self::bypass_raw_option( $name ) ) { + return update_option( $name, $value, $autoload ); + } + global $wpdb; + $autoload_value = $autoload ? 'yes' : 'no'; + + $old_value = $wpdb->get_var( + $wpdb->prepare( + "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", + $name + ) + ); + if ( $old_value === $value ) { + return false; + } + + $serialized_value = maybe_serialize( $value ); + // below we used "insert ignore" to at least suppress the resulting error. + $updated_num = $wpdb->query( + $wpdb->prepare( + "UPDATE $wpdb->options SET option_value = %s WHERE option_name = %s", + $serialized_value, + $name + ) + ); + + // Try inserting the option if the value doesn't exits. + if ( ! $updated_num ) { + $updated_num = $wpdb->query( + $wpdb->prepare( + "INSERT IGNORE INTO $wpdb->options ( option_name, option_value, autoload ) VALUES ( %s, %s, %s )", + $name, + $serialized_value, + $autoload_value + ) + ); + } + return (bool) $updated_num; + } + + /** + * Gets an option via $wpdb query. + * + * @since 1.1.2 + * @since-jetpack 5.4.0 + * + * @param string $name Option name. + * @param mixed $default Default option value if option is not found. + * + * @return mixed Option value, or null if option is not found and default is not specified. + */ + public static function get_raw_option( $name, $default = null ) { + if ( self::bypass_raw_option( $name ) ) { + return get_option( $name, $default ); + } + + global $wpdb; + $value = $wpdb->get_var( + $wpdb->prepare( + "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", + $name + ) + ); + $value = maybe_unserialize( $value ); + + if ( null === $value && null !== $default ) { + return $default; + } + + return $value; + } + + /** + * This function checks for a constant that, if present, will disable direct DB queries Jetpack uses to manage certain options and force Jetpack to always use Options API instead. + * Options can be selectively managed via a blocklist by filtering option names via the jetpack_disabled_raw_option filter. + * + * @param string $name Option name. + * + * @return bool + */ + public static function bypass_raw_option( $name ) { + + if ( Constants::get_constant( 'JETPACK_DISABLE_RAW_OPTIONS' ) ) { + return true; + } + /** + * Allows to disable particular raw options. + * + * @since 1.1.2 + * @since-jetpack 5.5.0 + * + * @param array $disabled_raw_options An array of option names that you can selectively blocklist from being managed via direct database queries. + */ + $disabled_raw_options = apply_filters( 'jetpack_disabled_raw_options', array() ); + return isset( $disabled_raw_options[ $name ] ); + } + + /** + * Gets all known options that are used by Jetpack and managed by Jetpack_Options. + * + * @since 1.1.2 + * @since-jetpack 5.4.0 + * + * @param boolean $strip_unsafe_options If true, and by default, will strip out options necessary for the connection to WordPress.com. + * @return array An array of all options managed via the Jetpack_Options class. + */ + public static function get_all_jetpack_options( $strip_unsafe_options = true ) { + $jetpack_options = self::get_option_names(); + $jetpack_options_non_compat = self::get_option_names( 'non_compact' ); + $jetpack_options_private = self::get_option_names( 'private' ); + + $all_jp_options = array_merge( $jetpack_options, $jetpack_options_non_compat, $jetpack_options_private ); + + if ( $strip_unsafe_options ) { + // Flag some Jetpack options as unsafe. + $unsafe_options = array( + 'id', // (int) The Client ID/WP.com Blog ID of this site. + 'master_user', // (int) The local User ID of the user who connected this site to jetpack.wordpress.com. + 'version', // (string) Used during upgrade procedure to auto-activate new modules. version:time + + // non_compact. + 'activated', + + // private. + 'register', + 'blog_token', // (string) The Client Secret/Blog Token of this site. + 'user_token', // (string) The User Token of this site. (deprecated) + 'user_tokens', + ); + + // Remove the unsafe Jetpack options. + foreach ( $unsafe_options as $unsafe_option ) { + $key = array_search( $unsafe_option, $all_jp_options, true ); + if ( false !== $key ) { + unset( $all_jp_options[ $key ] ); + } + } + } + + return $all_jp_options; + } + + /** + * Get all options that are not managed by the Jetpack_Options class that are used by Jetpack. + * + * @since 1.1.2 + * @since-jetpack 5.4.0 + * + * @return array + */ + public static function get_all_wp_options() { + // A manual build of the wp options. + return array( + 'sharing-options', + 'disabled_likes', + 'disabled_reblogs', + 'jetpack_comments_likes_enabled', + 'stats_options', + 'stats_dashboard_widget', + 'safecss_preview_rev', + 'safecss_rev', + 'safecss_revision_migrated', + 'nova_menu_order', + 'jetpack_portfolio', + 'jetpack_portfolio_posts_per_page', + 'jetpack_testimonial', + 'jetpack_testimonial_posts_per_page', + 'sharedaddy_disable_resources', + 'sharing-options', + 'sharing-services', + 'site_icon_temp_data', + 'featured-content', + 'site_logo', + 'jetpack_dismissed_notices', + 'jetpack-twitter-cards-site-tag', + 'jetpack-sitemap-state', + 'jetpack_sitemap_post_types', + 'jetpack_sitemap_location', + 'jetpack_protect_key', + 'jetpack_protect_blocked_attempts', + 'jetpack_protect_activating', + 'jetpack_connection_banner_ab', + 'jetpack_active_plan', + 'jetpack_activation_source', + 'jetpack_site_products', + 'jetpack_sso_match_by_email', + 'jetpack_sso_require_two_step', + 'jetpack_sso_remove_login_form', + 'jetpack_last_connect_url_check', + 'jpo_business_address', + 'jpo_site_type', + 'jpo_homepage_format', + 'jpo_contact_page', + 'jetpack_excluded_extensions', + ); + } + + /** + * Gets all options that can be safely reset by CLI. + * + * @since 1.1.2 + * @since-jetpack 5.4.0 + * + * @return array array Associative array containing jp_options which are managed by the Jetpack_Options class and wp_options which are not. + */ + public static function get_options_for_reset() { + $all_jp_options = self::get_all_jetpack_options(); + + $wp_options = self::get_all_wp_options(); + + $options = array( + 'jp_options' => $all_jp_options, + 'wp_options' => $wp_options, + ); + + return $options; + } + + /** + * Delete all known options + * + * @since 1.1.2 + * @since-jetpack 5.4.0 + * + * @return void + */ + public static function delete_all_known_options() { + // Delete all compact options. + foreach ( (array) self::$grouped_options as $option_name ) { + delete_option( $option_name ); + } + + // Delete all non-compact Jetpack options. + foreach ( (array) self::get_option_names( 'non-compact' ) as $option_name ) { + self::delete_option( $option_name ); + } + + // Delete all options that can be reset via CLI, that aren't Jetpack options. + foreach ( (array) self::get_all_wp_options() as $option_name ) { + delete_option( $option_name ); + } + } +} diff --git a/vendor/automattic/jetpack-connection/legacy/class-jetpack-signature.php b/vendor/automattic/jetpack-connection/legacy/class-jetpack-signature.php new file mode 100644 index 00000000000..eb319441217 --- /dev/null +++ b/vendor/automattic/jetpack-connection/legacy/class-jetpack-signature.php @@ -0,0 +1,409 @@ +token = $secret[0]; + $this->secret = $secret[1]; + $this->time_diff = $time_diff; + } + + /** + * Sign the current request. + * + * @todo Implement a proper nonce verification. + * + * @param array $override Optional arguments to override the ones from the current request. + * @return string|WP_Error Request signature, or a WP_Error on failure. + */ + public function sign_current_request( $override = array() ) { + if ( isset( $override['scheme'] ) ) { + $scheme = $override['scheme']; + if ( ! in_array( $scheme, array( 'http', 'https' ), true ) ) { + return new WP_Error( 'invalid_scheme', 'Invalid URL scheme' ); + } + } elseif ( is_ssl() ) { + $scheme = 'https'; + } else { + $scheme = 'http'; + } + + $port = $this->get_current_request_port(); + + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidatedNotSanitized -- Sniff misses the esc_url_raw wrapper. + $this->current_request_url = esc_url_raw( wp_unslash( "{$scheme}://{$_SERVER['HTTP_HOST']}:{$port}" . ( isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '' ) ) ); + + if ( array_key_exists( 'body', $override ) && ! empty( $override['body'] ) ) { + $body = $override['body']; + } elseif ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === strtoupper( $_SERVER['REQUEST_METHOD'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- This is validating. + $body = isset( $GLOBALS['HTTP_RAW_POST_DATA'] ) ? $GLOBALS['HTTP_RAW_POST_DATA'] : null; + + // Convert the $_POST to the body, if the body was empty. This is how arrays are hashed + // and encoded on the Jetpack side. + if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { + // phpcs:ignore WordPress.Security.NonceVerification.Missing + if ( empty( $body ) && is_array( $_POST ) && $_POST !== array() ) { + $body = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing + } + } + } elseif ( isset( $_SERVER['REQUEST_METHOD'] ) && 'PUT' === strtoupper( $_SERVER['REQUEST_METHOD'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- This is validating. + // This is a little strange-looking, but there doesn't seem to be another way to get the PUT body. + $raw_put_data = file_get_contents( 'php://input' ); + parse_str( $raw_put_data, $body ); + + if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { + $put_data = json_decode( $raw_put_data, true ); + if ( is_array( $put_data ) && $put_data !== array() ) { + $body = $put_data; + } + } + } else { + $body = null; + } + + if ( empty( $body ) ) { + $body = null; + } + + $a = array(); + foreach ( array( 'token', 'timestamp', 'nonce', 'body-hash' ) as $parameter ) { + if ( isset( $override[ $parameter ] ) ) { + $a[ $parameter ] = $override[ $parameter ]; + } else { + // phpcs:ignore WordPress.Security.NonceVerification.Recommended + $a[ $parameter ] = isset( $_GET[ $parameter ] ) ? filter_var( wp_unslash( $_GET[ $parameter ] ) ) : ''; + } + } + + $method = isset( $override['method'] ) ? $override['method'] : ( isset( $_SERVER['REQUEST_METHOD'] ) ? filter_var( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) : null ); + return $this->sign_request( $a['token'], $a['timestamp'], $a['nonce'], $a['body-hash'], $method, $this->current_request_url, $body, true ); + } + + /** + * Sign a specified request. + * + * @todo Having body_hash v. body-hash is annoying. Refactor to accept an array? + * @todo Use wp_json_encode() instead of json_encode()? + * + * @param string $token Request token. + * @param int $timestamp Timestamp of the request. + * @param string $nonce Request nonce. + * @param string $body_hash Request body hash. + * @param string $method Request method. + * @param string $url Request URL. + * @param mixed $body Request body. + * @param bool $verify_body_hash Whether to verify the body hash against the body. + * @return string|WP_Error Request signature, or a WP_Error on failure. + */ + public function sign_request( $token = '', $timestamp = 0, $nonce = '', $body_hash = '', $method = '', $url = '', $body = null, $verify_body_hash = true ) { + if ( ! $this->secret ) { + return new WP_Error( 'invalid_secret', 'Invalid secret' ); + } + + if ( ! $this->token ) { + return new WP_Error( 'invalid_token', 'Invalid token' ); + } + + list( $token ) = explode( '.', $token ); + + $signature_details = compact( 'token', 'timestamp', 'nonce', 'body_hash', 'method', 'url' ); + + if ( 0 !== strpos( $token, "$this->token:" ) ) { + return new WP_Error( 'token_mismatch', 'Incorrect token', compact( 'signature_details' ) ); + } + + // If we got an array at this point, let's encode it, so we can see what it looks like as a string. + if ( is_array( $body ) ) { + if ( $body !== array() ) { + // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode + $body = json_encode( $body ); + + } else { + $body = ''; + } + } + + $required_parameters = array( 'token', 'timestamp', 'nonce', 'method', 'url' ); + if ( $body !== null ) { + $required_parameters[] = 'body_hash'; + if ( ! is_string( $body ) ) { + return new WP_Error( 'invalid_body', 'Body is malformed.', compact( 'signature_details' ) ); + } + } + + foreach ( $required_parameters as $required ) { + if ( ! is_scalar( $$required ) ) { + return new WP_Error( 'invalid_signature', sprintf( 'The required "%s" parameter is malformed.', str_replace( '_', '-', $required ) ), compact( 'signature_details' ) ); + } + + if ( ! strlen( $$required ) ) { + return new WP_Error( 'invalid_signature', sprintf( 'The required "%s" parameter is missing.', str_replace( '_', '-', $required ) ), compact( 'signature_details' ) ); + } + } + + if ( empty( $body ) ) { + if ( $body_hash ) { + return new WP_Error( 'invalid_body_hash', 'Invalid body hash for empty body.', compact( 'signature_details' ) ); + } + } else { + $connection = new Connection_Manager(); + if ( $verify_body_hash && $connection->sha1_base64( $body ) !== $body_hash ) { + return new WP_Error( 'invalid_body_hash', 'The body hash does not match.', compact( 'signature_details' ) ); + } + } + + $parsed = wp_parse_url( $url ); + if ( ! isset( $parsed['host'] ) ) { + return new WP_Error( 'invalid_signature', sprintf( 'The required "%s" parameter is malformed.', 'url' ), compact( 'signature_details' ) ); + } + + if ( ! empty( $parsed['port'] ) ) { + $port = $parsed['port']; + } elseif ( 'http' === $parsed['scheme'] ) { + $port = 80; + } elseif ( 'https' === $parsed['scheme'] ) { + $port = 443; + } else { + return new WP_Error( 'unknown_scheme_port', "The scheme's port is unknown", compact( 'signature_details' ) ); + } + + if ( ! ctype_digit( "$timestamp" ) || 10 < strlen( $timestamp ) ) { // If Jetpack is around in 275 years, you can blame mdawaffe for the bug. + return new WP_Error( 'invalid_signature', sprintf( 'The required "%s" parameter is malformed.', 'timestamp' ), compact( 'signature_details' ) ); + } + + $local_time = $timestamp - $this->time_diff; + if ( $local_time < time() - 600 || $local_time > time() + 300 ) { + return new WP_Error( 'invalid_signature', 'The timestamp is too old.', compact( 'signature_details' ) ); + } + + if ( 12 < strlen( $nonce ) || preg_match( '/[^a-zA-Z0-9]/', $nonce ) ) { + return new WP_Error( 'invalid_signature', sprintf( 'The required "%s" parameter is malformed.', 'nonce' ), compact( 'signature_details' ) ); + } + + $normalized_request_pieces = array( + $token, + $timestamp, + $nonce, + $body_hash, + strtoupper( $method ), + strtolower( $parsed['host'] ), + $port, + empty( $parsed['path'] ) ? '' : $parsed['path'], + // Normalized Query String. + ); + + $normalized_request_pieces = array_merge( $normalized_request_pieces, $this->normalized_query_parameters( isset( $parsed['query'] ) ? $parsed['query'] : '' ) ); + $flat_normalized_request_pieces = array(); + foreach ( $normalized_request_pieces as $piece ) { + if ( is_array( $piece ) ) { + foreach ( $piece as $subpiece ) { + $flat_normalized_request_pieces[] = $subpiece; + } + } else { + $flat_normalized_request_pieces[] = $piece; + } + } + $normalized_request_pieces = $flat_normalized_request_pieces; + + $normalized_request_string = implode( "\n", $normalized_request_pieces ) . "\n"; + + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode + return base64_encode( hash_hmac( 'sha1', $normalized_request_string, $this->secret, true ) ); + } + + /** + * Retrieve and normalize the parameters from a query string. + * + * @param string $query_string Query string. + * @return array Normalized query string parameters. + */ + public function normalized_query_parameters( $query_string ) { + parse_str( $query_string, $array ); + + unset( $array['signature'] ); + + $names = array_keys( $array ); + $values = array_values( $array ); + + $names = array_map( array( $this, 'encode_3986' ), $names ); + $values = array_map( array( $this, 'encode_3986' ), $values ); + + $pairs = array_map( array( $this, 'join_with_equal_sign' ), $names, $values ); + + sort( $pairs ); + + return $pairs; + } + + /** + * Encodes a string or array of strings according to RFC 3986. + * + * @param string|array $string_or_array String or array to encode. + * @return string|array URL-encoded string or array. + */ + public function encode_3986( $string_or_array ) { + if ( is_array( $string_or_array ) ) { + return array_map( array( $this, 'encode_3986' ), $string_or_array ); + } + + return rawurlencode( $string_or_array ); + } + + /** + * Concatenates a parameter name and a parameter value with an equals sign between them. + * + * @param string $name Parameter name. + * @param string|array $value Parameter value. + * @return string|array A string pair (e.g. `name=value`) or an array of string pairs. + */ + public function join_with_equal_sign( $name, $value ) { + if ( is_array( $value ) ) { + return $this->join_array_with_equal_sign( $name, $value ); + } + return "{$name}={$value}"; + } + + /** + * Helper function for join_with_equal_sign for handling arrayed values. + * Explicitly supports nested arrays. + * + * @param string $name Parameter name. + * @param array $value Parameter value. + * @return array An array of string pairs (e.g. `[ name[example]=value ]`). + */ + private function join_array_with_equal_sign( $name, $value ) { + $result = array(); + foreach ( $value as $value_key => $value_value ) { + $joined_value = $this->join_with_equal_sign( $name . '[' . $value_key . ']', $value_value ); + if ( is_array( $joined_value ) ) { + foreach ( array_values( $joined_value ) as $individual_joined_value ) { + $result[] = $individual_joined_value; + } + } elseif ( is_string( $joined_value ) ) { + $result[] = $joined_value; + } + } + + sort( $result ); + return $result; + } + + /** + * Gets the port that should be considered to sign the current request. + * + * It will analyze the current request, as well as some Jetpack constants, to return the string + * to be concatenated in the URL representing the port of the current request. + * + * @since 1.8.4 + * + * @return string The port to be used in the signature + */ + public function get_current_request_port() { + $host_port = isset( $_SERVER['HTTP_X_FORWARDED_PORT'] ) ? $this->sanitize_host_post( $_SERVER['HTTP_X_FORWARDED_PORT'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- This is validating. + if ( '' === $host_port && isset( $_SERVER['SERVER_PORT'] ) ) { + $host_port = $this->sanitize_host_post( $_SERVER['SERVER_PORT'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- This is validating. + } + + /** + * Note: This port logic is tested in the Jetpack_Cxn_Tests->test__server_port_value() test. + * Please update the test if any changes are made in this logic. + */ + if ( is_ssl() ) { + // 443: Standard Port + // 80: Assume we're behind a proxy without X-Forwarded-Port. Hardcoding "80" here means most sites + // with SSL termination proxies (self-served, Cloudflare, etc.) don't need to fiddle with + // the JETPACK_SIGNATURE__HTTPS_PORT constant. The code also implies we can't talk to a + // site at https://example.com:80/ (which would be a strange configuration). + // JETPACK_SIGNATURE__HTTPS_PORT: Set this constant in wp-config.php to the back end webserver's port + // if the site is behind a proxy running on port 443 without + // X-Forwarded-Port and the back end's port is *not* 80. It's better, + // though, to configure the proxy to send X-Forwarded-Port. + $https_port = defined( 'JETPACK_SIGNATURE__HTTPS_PORT' ) ? $this->sanitize_host_post( JETPACK_SIGNATURE__HTTPS_PORT ) : '443'; + $port = in_array( $host_port, array( '443', '80', $https_port ), true ) ? '' : $host_port; + } else { + // 80: Standard Port + // JETPACK_SIGNATURE__HTTPS_PORT: Set this constant in wp-config.php to the back end webserver's port + // if the site is behind a proxy running on port 80 without + // X-Forwarded-Port. It's better, though, to configure the proxy to + // send X-Forwarded-Port. + $http_port = defined( 'JETPACK_SIGNATURE__HTTP_PORT' ) ? $this->sanitize_host_post( JETPACK_SIGNATURE__HTTP_PORT ) : '80'; + $port = in_array( $host_port, array( '80', $http_port ), true ) ? '' : $host_port; + } + return (string) $port; + } + + /** + * Sanitizes a variable checking if it's a valid port number, which can be an integer or a numeric string + * + * @since 1.8.4 + * + * @param mixed $port_number Variable representing a port number. + * @return string Always a string with a valid port number, or an empty string if input is invalid + */ + public function sanitize_host_post( $port_number ) { + + if ( ! is_int( $port_number ) && ! is_string( $port_number ) ) { + return ''; + } + if ( is_string( $port_number ) && ! ctype_digit( $port_number ) ) { + return ''; + } + + if ( 0 >= (int) $port_number || 65535 < $port_number ) { + return ''; + } + return (string) $port_number; + } +} diff --git a/vendor/automattic/jetpack-connection/legacy/class-jetpack-tracks-client.php b/vendor/automattic/jetpack-connection/legacy/class-jetpack-tracks-client.php new file mode 100644 index 00000000000..4161c4138f5 --- /dev/null +++ b/vendor/automattic/jetpack-connection/legacy/class-jetpack-tracks-client.php @@ -0,0 +1,230 @@ + $event_name, // required + '_ui' => $user_id, // required unless _ul is provided + '_ul' => $user_login, // required unless _ui is provided + + // Optional, but recommended + '_ts' => $ts_in_ms, // Default: now + '_via_ip' => $client_ip, // we use it for geo, etc. + + // Possibly useful to set some context for the event + '_via_ua' => $client_user_agent, + '_via_url' => $client_url, + '_via_ref' => $client_referrer, + + // For user-targeted tests + 'abtest_name' => $abtest_name, + 'abtest_variation' => $abtest_variation, + + // Your application-specific properties + 'custom_property' => $some_value, + ) ); + + if ( is_wp_error( $result ) ) { + // Handle the error in your app + } +``` + */ +class Jetpack_Tracks_Client { + const PIXEL = 'https://pixel.wp.com/t.gif'; + const BROWSER_TYPE = 'php-agent'; + const USER_AGENT_SLUG = 'tracks-client'; + const VERSION = '0.3'; + + /** + * Stores the Terms of Service Object Reference. + * + * @var null + */ + private static $terms_of_service = null; + + /** + * Record an event. + * + * @param mixed $event Event object to send to Tracks. An array will be cast to object. Required. + * Properties are included directly in the pixel query string after light validation. + * @return mixed True on success, WP_Error on failure + */ + public static function record_event( $event ) { + if ( ! self::$terms_of_service ) { + self::$terms_of_service = new \Automattic\Jetpack\Terms_Of_Service(); + } + + // Don't track users who have opted out or not agreed to our TOS, or are not running an active Jetpack. + if ( ! self::$terms_of_service->has_agreed() || ! empty( $_COOKIE['tk_opt-out'] ) ) { + return false; + } + + if ( ! $event instanceof Jetpack_Tracks_Event ) { + $event = new Jetpack_Tracks_Event( $event ); + } + if ( is_wp_error( $event ) ) { + return $event; + } + + $pixel = $event->build_pixel_url( $event ); + + if ( ! $pixel ) { + return new WP_Error( 'invalid_pixel', 'cannot generate tracks pixel for given input', 400 ); + } + + return self::record_pixel( $pixel ); + } + + /** + * Synchronously request the pixel. + * + * @param string $pixel The wp.com tracking pixel. + * @return array|bool|WP_Error True if successful. wp_remote_get response or WP_Error if not. + */ + public static function record_pixel( $pixel ) { + // Add the Request Timestamp and URL terminator just before the HTTP request. + $pixel .= '&_rt=' . self::build_timestamp() . '&_=_'; + + $response = wp_remote_get( + $pixel, + array( + 'blocking' => true, // The default, but being explicit here :). + 'timeout' => 1, + 'redirection' => 2, + 'httpversion' => '1.1', + 'user-agent' => self::get_user_agent(), + ) + ); + + if ( is_wp_error( $response ) ) { + return $response; + } + + $code = isset( $response['response']['code'] ) ? $response['response']['code'] : 0; + + if ( 200 !== $code ) { + return new WP_Error( 'request_failed', 'Tracks pixel request failed', $code ); + } + + return true; + } + + /** + * Get the user agent. + * + * @return string The user agent. + */ + public static function get_user_agent() { + return self::USER_AGENT_SLUG . '-v' . self::VERSION; + } + + /** + * Build an event and return its tracking URL + * + * @deprecated Call the `build_pixel_url` method on a Jetpack_Tracks_Event object instead. + * @param array $event Event keys and values. + * @return string URL of a tracking pixel. + */ + public static function build_pixel_url( $event ) { + $_event = new Jetpack_Tracks_Event( $event ); + return $_event->build_pixel_url(); + } + + /** + * Validate input for a tracks event. + * + * @deprecated Instantiate a Jetpack_Tracks_Event object instead + * @param array $event Event keys and values. + * @return mixed Validated keys and values or WP_Error on failure + */ + private static function validate_and_sanitize( $event ) { + $_event = new Jetpack_Tracks_Event( $event ); + if ( is_wp_error( $_event ) ) { + return $_event; + } + return get_object_vars( $_event ); + } + + /** + * Builds a timestamp. + * + * Milliseconds since 1970-01-01. + * + * @return string + */ + public static function build_timestamp() { + $ts = round( microtime( true ) * 1000 ); + return number_format( $ts, 0, '', '' ); + } + + /** + * Grabs the user's anon id from cookies, or generates and sets a new one + * + * @return string An anon id for the user + */ + public static function get_anon_id() { + static $anon_id = null; + + if ( ! isset( $anon_id ) ) { + + // Did the browser send us a cookie? + if ( isset( $_COOKIE['tk_ai'] ) && preg_match( '#^[a-z]+:[A-Za-z0-9+/=]{24}$#', $_COOKIE['tk_ai'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- This is validating. + $anon_id = $_COOKIE['tk_ai']; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- This is validating. + } else { + + $binary = ''; + + // Generate a new anonId and try to save it in the browser's cookies. + // Note that base64-encoding an 18 character string generates a 24-character anon id. + for ( $i = 0; $i < 18; ++$i ) { + $binary .= chr( wp_rand( 0, 255 ) ); + } + + $anon_id = 'jetpack:' . base64_encode( $binary ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode + + if ( ! headers_sent() + && ! ( defined( 'REST_REQUEST' ) && REST_REQUEST ) + && ! ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) + ) { + setcookie( 'tk_ai', $anon_id, 0, COOKIEPATH, COOKIE_DOMAIN, is_ssl(), false ); // phpcs:ignore Jetpack.Functions.SetCookie -- This is a random value and should be fine. + } + } + } + + return $anon_id; + } + + /** + * Gets the WordPress.com user's Tracks identity, if connected. + * + * @return array|bool + */ + public static function get_connected_user_tracks_identity() { + $user_data = ( new Manager() )->get_connected_user_data(); + if ( ! $user_data ) { + return false; + } + + return array( + 'blogid' => Jetpack_Options::get_option( 'id', 0 ), + 'email' => $user_data['email'], + 'userid' => $user_data['ID'], + 'username' => $user_data['login'], + 'user_locale' => $user_data['user_locale'], + ); + } +} diff --git a/vendor/automattic/jetpack-connection/legacy/class-jetpack-tracks-event.php b/vendor/automattic/jetpack-connection/legacy/class-jetpack-tracks-event.php new file mode 100644 index 00000000000..6627d0aaa62 --- /dev/null +++ b/vendor/automattic/jetpack-connection/legacy/class-jetpack-tracks-event.php @@ -0,0 +1,188 @@ + $event_name, // required + '_ui' => $user_id, // required unless _ul is provided + '_ul' => $user_login, // required unless _ui is provided + + // Optional, but recommended + '_via_ip' => $client_ip, // for geo, etc. + + // Possibly useful to set some context for the event + '_via_ua' => $client_user_agent, + '_via_url' => $client_url, + '_via_ref' => $client_referrer, + + // For user-targeted tests + 'abtest_name' => $abtest_name, + 'abtest_variation' => $abtest_variation, + + // Your application-specific properties + 'custom_property' => $some_value, + ) ); + + if ( is_wp_error( $event->error ) ) { + // Handle the error in your app + } + + $bump_and_redirect_pixel = $event->build_signed_pixel_url(); +``` + */ + +/** + * Class Jetpack_Tracks_Event + */ +#[AllowDynamicProperties] +class Jetpack_Tracks_Event { + const EVENT_NAME_REGEX = '/^(([a-z0-9]+)_){2}([a-z0-9_]+)$/'; + const PROP_NAME_REGEX = '/^[a-z_][a-z0-9_]*$/'; + + /** + * Tracks Event Error. + * + * @var mixed Error. + */ + public $error; + + /** + * Jetpack_Tracks_Event constructor. + * + * @param object $event Tracks event. + */ + public function __construct( $event ) { + $_event = self::validate_and_sanitize( $event ); + if ( is_wp_error( $_event ) ) { + $this->error = $_event; + return; + } + + foreach ( $_event as $key => $value ) { + $this->{$key} = $value; + } + } + + /** + * Record a track event. + */ + public function record() { + return Jetpack_Tracks_Client::record_event( $this ); + } + + /** + * Annotate the event with all relevant info. + * + * @param mixed $event Object or (flat) array. + * @return mixed The transformed event array or WP_Error on failure. + */ + public static function validate_and_sanitize( $event ) { + $event = (object) $event; + + // Required. + if ( ! $event->_en ) { + return new WP_Error( 'invalid_event', 'A valid event must be specified via `_en`', 400 ); + } + + // delete non-routable addresses otherwise geoip will discard the record entirely. + if ( property_exists( $event, '_via_ip' ) && preg_match( '/^192\.168|^10\./', $event->_via_ip ) ) { + unset( $event->_via_ip ); + } + + $validated = array( + 'browser_type' => Jetpack_Tracks_Client::BROWSER_TYPE, + '_aua' => Jetpack_Tracks_Client::get_user_agent(), + ); + + $_event = (object) array_merge( (array) $event, $validated ); + + // If you want to block property names, do it here. + + // Make sure we have an event timestamp. + if ( ! isset( $_event->_ts ) ) { + $_event->_ts = Jetpack_Tracks_Client::build_timestamp(); + } + + return $_event; + } + + /** + * Build a pixel URL that will send a Tracks event when fired. + * On error, returns an empty string (''). + * + * @return string A pixel URL or empty string ('') if there were invalid args. + */ + public function build_pixel_url() { + if ( $this->error ) { + return ''; + } + + $args = get_object_vars( $this ); + + // Request Timestamp and URL Terminator must be added just before the HTTP request or not at all. + unset( $args['_rt'] ); + unset( $args['_'] ); + + $validated = self::validate_and_sanitize( $args ); + + if ( is_wp_error( $validated ) ) { + return ''; + } + + return Jetpack_Tracks_Client::PIXEL . '?' . http_build_query( $validated ); + } + + /** + * Validate the event name. + * + * @param string $name Event name. + * @return false|int + */ + public static function event_name_is_valid( $name ) { + return preg_match( self::EVENT_NAME_REGEX, $name ); + } + + /** + * Validates prop name + * + * @param string $name Property name. + * + * @return false|int Truthy value. + */ + public static function prop_name_is_valid( $name ) { + return preg_match( self::PROP_NAME_REGEX, $name ); + } + + /** + * Scrutinize event name. + * + * @param object $event Tracks event. + */ + public static function scrutinize_event_names( $event ) { + if ( ! self::event_name_is_valid( $event->_en ) ) { + return; + } + + $whitelisted_key_names = array( + 'anonId', + 'Browser_Type', + ); + + foreach ( array_keys( (array) $event ) as $key ) { + if ( in_array( $key, $whitelisted_key_names, true ) ) { + continue; + } + if ( ! self::prop_name_is_valid( $key ) ) { + return; + } + } + } +} diff --git a/vendor/automattic/jetpack-connection/legacy/class-jetpack-xmlrpc-server.php b/vendor/automattic/jetpack-connection/legacy/class-jetpack-xmlrpc-server.php new file mode 100644 index 00000000000..7b8ca0a4b7d --- /dev/null +++ b/vendor/automattic/jetpack-connection/legacy/class-jetpack-xmlrpc-server.php @@ -0,0 +1,877 @@ +connection = new Connection_Manager(); + } + + /** + * Whitelist of the XML-RPC methods available to the Jetpack Server. If the + * user is not authenticated (->login()) then the methods are never added, + * so they will get a "does not exist" error. + * + * @param array $core_methods Core XMLRPC methods. + */ + public function xmlrpc_methods( $core_methods ) { + $jetpack_methods = array( + 'jetpack.verifyAction' => array( $this, 'verify_action' ), + 'jetpack.idcUrlValidation' => array( $this, 'validate_urls_for_idc_mitigation' ), + 'jetpack.unlinkUser' => array( $this, 'unlink_user' ), + 'jetpack.testConnection' => array( $this, 'test_connection' ), + ); + + $jetpack_methods = array_merge( $jetpack_methods, $this->provision_xmlrpc_methods() ); + + $this->user = $this->login(); + + if ( $this->user ) { + $jetpack_methods = array_merge( + $jetpack_methods, + array( + 'jetpack.testAPIUserCode' => array( $this, 'test_api_user_code' ), + ) + ); + + if ( isset( $core_methods['metaWeblog.editPost'] ) ) { + $jetpack_methods['metaWeblog.newMediaObject'] = $core_methods['metaWeblog.newMediaObject']; + $jetpack_methods['jetpack.updateAttachmentParent'] = array( $this, 'update_attachment_parent' ); + } + + /** + * Filters the XML-RPC methods available to Jetpack for authenticated users. + * + * @since 1.7.0 + * @since-jetpack 1.1.0 + * + * @param array $jetpack_methods XML-RPC methods available to the Jetpack Server. + * @param array $core_methods Available core XML-RPC methods. + * @param \WP_User $user Information about the user authenticated in the request. + */ + $jetpack_methods = apply_filters( 'jetpack_xmlrpc_methods', $jetpack_methods, $core_methods, $this->user ); + } + + /** + * Filters the XML-RPC methods available to Jetpack for requests signed both with a blog token or a user token. + * + * @since 1.7.0 + * @since 1.9.5 Introduced the $user parameter. + * @since-jetpack 3.0.0 + * + * @param array $jetpack_methods XML-RPC methods available to the Jetpack Server. + * @param array $core_methods Available core XML-RPC methods. + * @param \WP_User|bool $user Information about the user authenticated in the request. False if authenticated with blog token. + */ + return apply_filters( 'jetpack_xmlrpc_unauthenticated_methods', $jetpack_methods, $core_methods, $this->user ); + } + + /** + * Whitelist of the bootstrap XML-RPC methods + */ + public function bootstrap_xmlrpc_methods() { + return array( + 'jetpack.remoteAuthorize' => array( $this, 'remote_authorize' ), + 'jetpack.remoteRegister' => array( $this, 'remote_register' ), + ); + } + + /** + * Additional method needed for authorization calls. + */ + public function authorize_xmlrpc_methods() { + return array( + 'jetpack.remoteAuthorize' => array( $this, 'remote_authorize' ), + 'jetpack.remoteRegister' => array( $this, 'remote_already_registered' ), + ); + } + + /** + * Remote provisioning methods. + */ + public function provision_xmlrpc_methods() { + return array( + 'jetpack.remoteRegister' => array( $this, 'remote_register' ), + 'jetpack.remoteProvision' => array( $this, 'remote_provision' ), + 'jetpack.remoteConnect' => array( $this, 'remote_connect' ), + 'jetpack.getUser' => array( $this, 'get_user' ), + ); + } + + /** + * Used to verify whether a local user exists and what role they have. + * + * @param int|string|array $request One of: + * int|string The local User's ID, username, or email address. + * array A request array containing: + * 0: int|string The local User's ID, username, or email address. + * + * @return array|\IXR_Error Information about the user, or error if no such user found: + * roles: string[] The user's rols. + * login: string The user's username. + * email_hash string[] The MD5 hash of the user's normalized email address. + * caps string[] The user's capabilities. + * allcaps string[] The user's granular capabilities, merged from role capabilities. + * token_key string The Token Key of the user's Jetpack token. Empty string if none. + */ + public function get_user( $request ) { + $user_id = is_array( $request ) ? $request[0] : $request; + + if ( ! $user_id ) { + return $this->error( + new \WP_Error( + 'invalid_user', + __( 'Invalid user identifier.', 'jetpack-connection' ), + 400 + ), + 'get_user' + ); + } + + $user = $this->get_user_by_anything( $user_id ); + + if ( ! $user ) { + return $this->error( + new \WP_Error( + 'user_unknown', + __( 'User not found.', 'jetpack-connection' ), + 404 + ), + 'get_user' + ); + } + + $user_token = ( new Tokens() )->get_access_token( $user->ID ); + + if ( $user_token ) { + list( $user_token_key ) = explode( '.', $user_token->secret ); + if ( $user_token_key === $user_token->secret ) { + $user_token_key = ''; + } + } else { + $user_token_key = ''; + } + + return array( + 'id' => $user->ID, + 'login' => $user->user_login, + 'email_hash' => md5( strtolower( trim( $user->user_email ) ) ), + 'roles' => $user->roles, + 'caps' => $user->caps, + 'allcaps' => $user->allcaps, + 'token_key' => $user_token_key, + ); + } + + /** + * Remote authorization XMLRPC method handler. + * + * @param array $request the request. + */ + public function remote_authorize( $request ) { + $user = get_user_by( 'id', $request['state'] ); + + /** + * Happens on various request handling events in the Jetpack XMLRPC server. + * The action combines several types of events: + * - remote_authorize + * - remote_provision + * - get_user. + * + * @since 1.7.0 + * @since-jetpack 8.0.0 + * + * @param String $action the action name, i.e., 'remote_authorize'. + * @param String $stage the execution stage, can be 'begin', 'success', 'error', etc. + * @param array $parameters extra parameters from the event. + * @param WP_User $user the acting user. + */ + do_action( 'jetpack_xmlrpc_server_event', 'remote_authorize', 'begin', array(), $user ); + + foreach ( array( 'secret', 'state', 'redirect_uri', 'code' ) as $required ) { + if ( ! isset( $request[ $required ] ) || empty( $request[ $required ] ) ) { + return $this->error( + new \WP_Error( 'missing_parameter', 'One or more parameters is missing from the request.', 400 ), + 'remote_authorize' + ); + } + } + + if ( ! $user ) { + return $this->error( new \WP_Error( 'user_unknown', 'User not found.', 404 ), 'remote_authorize' ); + } + + if ( $this->connection->has_connected_owner() && $this->connection->is_user_connected( $request['state'] ) ) { + return $this->error( new \WP_Error( 'already_connected', 'User already connected.', 400 ), 'remote_authorize' ); + } + + $verified = $this->verify_action( array( 'authorize', $request['secret'], $request['state'] ) ); + + if ( is_a( $verified, 'IXR_Error' ) ) { + return $this->error( $verified, 'remote_authorize' ); + } + + wp_set_current_user( $request['state'] ); + + $result = $this->connection->authorize( $request ); + + if ( is_wp_error( $result ) ) { + return $this->error( $result, 'remote_authorize' ); + } + + // This action is documented in class.jetpack-xmlrpc-server.php. + do_action( 'jetpack_xmlrpc_server_event', 'remote_authorize', 'success' ); + + return array( + 'result' => $result, + ); + } + + /** + * This XML-RPC method is called from the /jpphp/provision endpoint on WPCOM in order to + * register this site so that a plan can be provisioned. + * + * @param array $request An array containing at minimum nonce and local_user keys. + * + * @return \WP_Error|array + */ + public function remote_register( $request ) { + // This action is documented in class.jetpack-xmlrpc-server.php. + do_action( 'jetpack_xmlrpc_server_event', 'remote_register', 'begin', array() ); + + $user = $this->fetch_and_verify_local_user( $request ); + + if ( ! $user ) { + return $this->error( + new WP_Error( 'input_error', __( 'Valid user is required', 'jetpack-connection' ), 400 ), + 'remote_register' + ); + } + + if ( is_wp_error( $user ) || is_a( $user, 'IXR_Error' ) ) { + return $this->error( $user, 'remote_register' ); + } + + if ( empty( $request['nonce'] ) ) { + return $this->error( + new \WP_Error( + 'nonce_missing', + __( 'The required "nonce" parameter is missing.', 'jetpack-connection' ), + 400 + ), + 'remote_register' + ); + } + + $nonce = sanitize_text_field( $request['nonce'] ); + unset( $request['nonce'] ); + + $api_url = $this->connection->api_url( 'partner_provision_nonce_check' ); + $response = Client::_wp_remote_request( + esc_url_raw( add_query_arg( 'nonce', $nonce, $api_url ) ), + array( 'method' => 'GET' ), + true + ); + + if ( + 200 !== wp_remote_retrieve_response_code( $response ) || + 'OK' !== trim( wp_remote_retrieve_body( $response ) ) + ) { + return $this->error( + new \WP_Error( + 'invalid_nonce', + __( 'There was an issue validating this request.', 'jetpack-connection' ), + 400 + ), + 'remote_register' + ); + } + + if ( ! Jetpack_Options::get_option( 'id' ) || ! ( new Tokens() )->get_access_token() || ! empty( $request['force'] ) ) { + wp_set_current_user( $user->ID ); + + // This code mostly copied from Jetpack::admin_page_load. + if ( isset( $request['from'] ) ) { + $this->connection->add_register_request_param( 'from', (string) $request['from'] ); + } + $registered = $this->connection->try_registration(); + if ( is_wp_error( $registered ) ) { + return $this->error( $registered, 'remote_register' ); + } elseif ( ! $registered ) { + return $this->error( + new \WP_Error( + 'registration_error', + __( 'There was an unspecified error registering the site', 'jetpack-connection' ), + 400 + ), + 'remote_register' + ); + } + } + + // This action is documented in class.jetpack-xmlrpc-server.php. + do_action( 'jetpack_xmlrpc_server_event', 'remote_register', 'success' ); + + return array( + 'client_id' => Jetpack_Options::get_option( 'id' ), + ); + } + + /** + * This is a substitute for remote_register() when the blog is already registered which returns an error code + * signifying that state. + * This is an unauthorized call and we should not be responding with any data other than the error code. + * + * @return \IXR_Error + */ + public function remote_already_registered() { + return $this->error( + new \WP_Error( 'already_registered', __( 'Blog is already registered', 'jetpack-connection' ), 400 ), + 'remote_register' + ); + } + + /** + * This XML-RPC method is called from the /jpphp/provision endpoint on WPCOM in order to + * register this site so that a plan can be provisioned. + * + * @param array $request An array containing at minimum a nonce key and a local_username key. + * + * @return \WP_Error|array + */ + public function remote_provision( $request ) { + $user = $this->fetch_and_verify_local_user( $request ); + + if ( ! $user ) { + return $this->error( + new WP_Error( 'input_error', __( 'Valid user is required', 'jetpack-connection' ), 400 ), + 'remote_provision' + ); + } + + if ( is_wp_error( $user ) || is_a( $user, 'IXR_Error' ) ) { + return $this->error( $user, 'remote_provision' ); + } + + $site_icon = get_site_icon_url(); + + /** + * Filters the Redirect URI returned by the remote_register XMLRPC method + * + * @param string $redirect_uri The Redirect URI + * + * @since 1.9.7 + */ + $redirect_uri = apply_filters( 'jetpack_xmlrpc_remote_register_redirect_uri', admin_url() ); + + // Generate secrets. + $roles = new Roles(); + $role = $roles->translate_user_to_role( $user ); + $secrets = ( new Secrets() )->generate( 'authorize', $user->ID ); + + $response = array( + 'jp_version' => Constants::get_constant( 'JETPACK__VERSION' ), + 'redirect_uri' => $redirect_uri, + 'user_id' => $user->ID, + 'user_email' => $user->user_email, + 'user_login' => $user->user_login, + 'scope' => $this->connection->sign_role( $role, $user->ID ), + 'secret' => $secrets['secret_1'], + 'is_active' => $this->connection->has_connected_owner(), + ); + + if ( $site_icon ) { + $response['site_icon'] = $site_icon; + } + + /** + * Filters the response of the remote_provision XMLRPC method + * + * @param array $response The response. + * @param array $request An array containing at minimum a nonce key and a local_username key. + * @param \WP_User $user The local authenticated user. + * + * @since 1.9.7 + */ + $response = apply_filters( 'jetpack_remote_xmlrpc_provision_response', $response, $request, $user ); + + return $response; + } + + /** + * Given an array containing a local user identifier and a nonce, will attempt to fetch and set + * an access token for the given user. + * + * @param array $request An array containing local_user and nonce keys at minimum. + * @param \IXR_Client $ixr_client The client object, optional. + * @return mixed + */ + public function remote_connect( $request, $ixr_client = false ) { + if ( $this->connection->has_connected_owner() ) { + return $this->error( + new WP_Error( + 'already_connected', + __( 'Jetpack is already connected.', 'jetpack-connection' ), + 400 + ), + 'remote_connect' + ); + } + + $user = $this->fetch_and_verify_local_user( $request ); + + if ( ! $user || is_wp_error( $user ) || is_a( $user, 'IXR_Error' ) ) { + return $this->error( + new WP_Error( + 'input_error', + __( 'Valid user is required.', 'jetpack-connection' ), + 400 + ), + 'remote_connect' + ); + } + + if ( empty( $request['nonce'] ) ) { + return $this->error( + new WP_Error( + 'input_error', + __( 'A non-empty nonce must be supplied.', 'jetpack-connection' ), + 400 + ), + 'remote_connect' + ); + } + + if ( ! $ixr_client ) { + $ixr_client = new Jetpack_IXR_Client(); + } + // TODO: move this query into the Tokens class? + $ixr_client->query( + 'jetpack.getUserAccessToken', + array( + 'nonce' => sanitize_text_field( $request['nonce'] ), + 'external_user_id' => $user->ID, + ) + ); + + $token = $ixr_client->isError() ? false : $ixr_client->getResponse(); + if ( empty( $token ) ) { + return $this->error( + new WP_Error( + 'token_fetch_failed', + __( 'Failed to fetch user token from WordPress.com.', 'jetpack-connection' ), + 400 + ), + 'remote_connect' + ); + } + $token = sanitize_text_field( $token ); + + ( new Tokens() )->update_user_token( $user->ID, sprintf( '%s.%d', $token, $user->ID ), true ); + + /** + * Hook fired at the end of the jetpack.remoteConnect XML-RPC callback + * + * @since 1.9.7 + */ + do_action( 'jetpack_remote_connect_end' ); + + return $this->connection->has_connected_owner(); + } + + /** + * Getter for the local user to act as. + * + * @param array $request the current request data. + */ + private function fetch_and_verify_local_user( $request ) { + if ( empty( $request['local_user'] ) ) { + return $this->error( + new \WP_Error( + 'local_user_missing', + __( 'The required "local_user" parameter is missing.', 'jetpack-connection' ), + 400 + ), + 'remote_provision' + ); + } + + // Local user is used to look up by login, email or ID. + $local_user_info = $request['local_user']; + + return $this->get_user_by_anything( $local_user_info ); + } + + /** + * Gets the user object by its data. + * + * @param string $user_id can be any identifying user data. + */ + private function get_user_by_anything( $user_id ) { + $user = get_user_by( 'login', $user_id ); + + if ( ! $user ) { + $user = get_user_by( 'email', $user_id ); + } + + if ( ! $user ) { + $user = get_user_by( 'ID', $user_id ); + } + + return $user; + } + + /** + * Possible error_codes: + * + * - verify_secret_1_missing + * - verify_secret_1_malformed + * - verify_secrets_missing: verification secrets are not found in database + * - verify_secrets_incomplete: verification secrets are only partially found in database + * - verify_secrets_expired: verification secrets have expired + * - verify_secrets_mismatch: stored secret_1 does not match secret_1 sent by Jetpack.WordPress.com + * - state_missing: required parameter of state not found + * - state_malformed: state is not a digit + * - invalid_state: state in request does not match the stored state + * + * The 'authorize' and 'register' actions have additional error codes + * + * state_missing: a state ( user id ) was not supplied + * state_malformed: state is not the correct data type + * invalid_state: supplied state does not match the stored state + * + * @param array $params action An array of 3 parameters: + * [0]: string action. Possible values are `authorize`, `publicize` and `register`. + * [1]: string secret_1. + * [2]: int state. + * @return \IXR_Error|string IXR_Error on failure, secret_2 on success. + */ + public function verify_action( $params ) { + $action = isset( $params[0] ) ? $params[0] : ''; + $verify_secret = isset( $params[1] ) ? $params[1] : ''; + $state = isset( $params[2] ) ? $params[2] : ''; + + $result = ( new Secrets() )->verify( $action, $verify_secret, $state ); + + if ( is_wp_error( $result ) ) { + return $this->error( $result ); + } + + return $result; + } + + /** + * Wrapper for wp_authenticate( $username, $password ); + * + * @return \WP_User|bool + */ + public function login() { + $this->connection->require_jetpack_authentication(); + $user = wp_authenticate( 'username', 'password' ); + if ( is_wp_error( $user ) ) { + if ( 'authentication_failed' === $user->get_error_code() ) { // Generic error could mean most anything. + $this->error = new \WP_Error( 'invalid_request', 'Invalid Request', 403 ); + } else { + $this->error = $user; + } + return false; + } elseif ( ! $user ) { // Shouldn't happen. + $this->error = new \WP_Error( 'invalid_request', 'Invalid Request', 403 ); + return false; + } + + wp_set_current_user( $user->ID ); + + return $user; + } + + /** + * Returns the current error as an \IXR_Error + * + * @param \WP_Error|\IXR_Error $error The error object, optional. + * @param string $event_name The event name. + * @param \WP_User $user The user object. + * @return bool|\IXR_Error + */ + public function error( $error = null, $event_name = null, $user = null ) { + if ( null !== $event_name ) { + // This action is documented in class.jetpack-xmlrpc-server.php. + do_action( 'jetpack_xmlrpc_server_event', $event_name, 'fail', $error, $user ); + } + + if ( $error !== null ) { + $this->error = $error; + } + + if ( is_wp_error( $this->error ) ) { + $code = $this->error->get_error_data(); + if ( ! $code ) { + $code = -10520; + } + $message = sprintf( 'Jetpack: [%s] %s', $this->error->get_error_code(), $this->error->get_error_message() ); + if ( ! class_exists( \IXR_Error::class ) ) { + require_once ABSPATH . WPINC . '/class-IXR.php'; + } + return new \IXR_Error( $code, $message ); + } elseif ( is_a( $this->error, 'IXR_Error' ) ) { + return $this->error; + } + + return false; + } + + /* API Methods */ + + /** + * Just authenticates with the given Jetpack credentials. + * + * @return string A success string. The Jetpack plugin filters it and make it return the Jetpack plugin version. + */ + public function test_connection() { + /** + * Filters the successful response of the XMLRPC test_connection method + * + * @param string $response The response string. + */ + return apply_filters( 'jetpack_xmlrpc_test_connection_response', 'success' ); + } + + /** + * Test the API user code. + * + * @param array $args arguments identifying the test site. + */ + public function test_api_user_code( $args ) { + $client_id = (int) $args[0]; + $user_id = (int) $args[1]; + $nonce = (string) $args[2]; + $verify = (string) $args[3]; + + if ( ! $client_id || ! $user_id || ! strlen( $nonce ) || 32 !== strlen( $verify ) ) { + return false; + } + + $user = get_user_by( 'id', $user_id ); + if ( ! $user || is_wp_error( $user ) ) { + return false; + } + + /* phpcs:ignore + debugging + error_log( "CLIENT: $client_id" ); + error_log( "USER: $user_id" ); + error_log( "NONCE: $nonce" ); + error_log( "VERIFY: $verify" ); + */ + + $jetpack_token = ( new Tokens() )->get_access_token( $user_id ); + + $api_user_code = get_user_meta( $user_id, "jetpack_json_api_$client_id", true ); + if ( ! $api_user_code ) { + return false; + } + + $hmac = hash_hmac( + 'md5', + json_encode( // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode + (object) array( + 'client_id' => (int) $client_id, + 'user_id' => (int) $user_id, + 'nonce' => (string) $nonce, + 'code' => (string) $api_user_code, + ) + ), + $jetpack_token->secret + ); + + if ( ! hash_equals( $hmac, $verify ) ) { + return false; + } + + return $user_id; + } + + /** + * Unlink a user from WordPress.com + * + * When the request is done without any parameter, this XMLRPC callback gets an empty array as input. + * + * If $user_id is not provided, it will try to disconnect the current logged in user. This will fail if called by the Master User. + * + * If $user_id is is provided, it will try to disconnect the informed user, even if it's the Master User. + * + * @param mixed $user_id The user ID to disconnect from this site. + */ + public function unlink_user( $user_id = array() ) { + $user_id = (int) $user_id; + if ( $user_id < 1 ) { + $user_id = null; + } + /** + * Fired when we want to log an event to the Jetpack event log. + * + * @since 1.7.0 + * @since-jetpack 7.7.0 + * + * @param string $code Unique name for the event. + * @param string $data Optional data about the event. + */ + do_action( 'jetpack_event_log', 'unlink' ); + return $this->connection->disconnect_user( + $user_id, + (bool) $user_id + ); + } + + /** + * Returns the home URL, site URL, and URL secret for the current site which can be used on the WPCOM side for + * IDC mitigation to decide whether sync should be allowed if the home and siteurl values differ between WPCOM + * and the remote Jetpack site. + * + * @since 1.56.0 Additional data may be added via filter `jetpack_connection_validate_urls_for_idc_mitigation_response`. + * + * @return array + */ + public function validate_urls_for_idc_mitigation() { + $response = array( + 'home' => Urls::home_url(), + 'siteurl' => Urls::site_url(), + ); + + /** + * Allows modifying the response. + * + * @since 1.56.0 + * + * @param array $response + */ + return apply_filters( 'jetpack_connection_validate_urls_for_idc_mitigation_response', $response ); + } + + /** + * Updates the attachment parent object. + * + * @param array $args attachment and parent identifiers. + */ + public function update_attachment_parent( $args ) { + $attachment_id = (int) $args[0]; + $parent_id = (int) $args[1]; + + return wp_update_post( + array( + 'ID' => $attachment_id, + 'post_parent' => $parent_id, + ) + ); + } + + /** + * Deprecated: This method is no longer part of the Connection package and now lives on the Jetpack plugin. + * + * Disconnect this blog from the connected wordpress.com account + * + * @deprecated since 1.25.0 + * @see Jetpack_XMLRPC_Methods::disconnect_blog() in the Jetpack plugin + * + * @return boolean + */ + public function disconnect_blog() { + _deprecated_function( __METHOD__, '1.25.0', 'Jetpack_XMLRPC_Methods::disconnect_blog()' ); + if ( class_exists( 'Jetpack_XMLRPC_Methods' ) ) { + return Jetpack_XMLRPC_Methods::disconnect_blog(); + } + return false; + } + + /** + * Deprecated: This method is no longer part of the Connection package and now lives on the Jetpack plugin. + * + * Returns what features are available. Uses the slug of the module files. + * + * @deprecated since 1.25.0 + * @see Jetpack_XMLRPC_Methods::features_available() in the Jetpack plugin + * + * @return array + */ + public function features_available() { + _deprecated_function( __METHOD__, '1.25.0', 'Jetpack_XMLRPC_Methods::features_available()' ); + if ( class_exists( 'Jetpack_XMLRPC_Methods' ) ) { + return Jetpack_XMLRPC_Methods::features_available(); + } + return array(); + } + + /** + * Deprecated: This method is no longer part of the Connection package and now lives on the Jetpack plugin. + * + * Returns what features are enabled. Uses the slug of the modules files. + * + * @deprecated since 1.25.0 + * @see Jetpack_XMLRPC_Methods::features_enabled() in the Jetpack plugin + * + * @return array + */ + public function features_enabled() { + _deprecated_function( __METHOD__, '1.25.0', 'Jetpack_XMLRPC_Methods::features_enabled()' ); + if ( class_exists( 'Jetpack_XMLRPC_Methods' ) ) { + return Jetpack_XMLRPC_Methods::features_enabled(); + } + return array(); + } + + /** + * Deprecated: This method is no longer part of the Connection package and now lives on the Jetpack plugin. + * + * Serve a JSON API request. + * + * @deprecated since 1.25.0 + * @see Jetpack_XMLRPC_Methods::json_api() in the Jetpack plugin + * + * @param array $args request arguments. + */ + public function json_api( $args = array() ) { + _deprecated_function( __METHOD__, '1.25.0', 'Jetpack_XMLRPC_Methods::json_api()' ); + if ( class_exists( 'Jetpack_XMLRPC_Methods' ) ) { + return Jetpack_XMLRPC_Methods::json_api( $args ); + } + return array(); + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-client.php b/vendor/automattic/jetpack-connection/src/class-client.php new file mode 100644 index 00000000000..cfb0e50826f --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-client.php @@ -0,0 +1,497 @@ +check_api_response_for_errors( + $response, + $result['auth'], + empty( $args['url'] ) ? '' : $args['url'], + empty( $args['method'] ) ? 'POST' : $args['method'], + 'rest' + ); + + /** + * Fired when the remote request response has been received. + * + * @since 1.30.8 + * + * @param array|WP_Error The HTTP response. + */ + do_action( 'jetpack_received_remote_request_response', $response ); + + return $response; + } + + /** + * Adds authorization signature to a remote request using Jetpack_Signature + * + * @param array $args the arguments for the remote request. + * @param array|String $body the request body. + * @return WP_Error|array { + * An array containing URL and request items. + * + * @type String $url The request URL. + * @type array $request Request arguments. + * @type array $auth Authorization data. + * } + */ + public static function build_signed_request( $args, $body = null ) { + add_filter( + 'jetpack_constant_default_value', + __NAMESPACE__ . '\Utils::jetpack_api_constant_filter', + 10, + 2 + ); + + $defaults = array( + 'url' => '', + 'user_id' => 0, + 'blog_id' => 0, + 'auth_location' => Constants::get_constant( 'JETPACK_CLIENT__AUTH_LOCATION' ), + 'method' => 'POST', + 'timeout' => 10, + 'redirection' => 0, + 'headers' => array(), + 'stream' => false, + 'filename' => null, + 'sslverify' => true, + ); + + $args = wp_parse_args( $args, $defaults ); + + $args['blog_id'] = (int) $args['blog_id']; + + if ( 'header' !== $args['auth_location'] ) { + $args['auth_location'] = 'query_string'; + } + + $token = ( new Tokens() )->get_access_token( $args['user_id'] ); + if ( ! $token ) { + return new \WP_Error( 'missing_token' ); + } + + $method = strtoupper( $args['method'] ); + + $timeout = (int) $args['timeout']; + + $redirection = $args['redirection']; + $stream = $args['stream']; + $filename = $args['filename']; + $sslverify = $args['sslverify']; + + $request = compact( 'method', 'body', 'timeout', 'redirection', 'stream', 'filename', 'sslverify' ); + + @list( $token_key, $secret ) = explode( '.', $token->secret ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged + if ( empty( $token ) || empty( $secret ) ) { + return new \WP_Error( 'malformed_token' ); + } + + $token_key = sprintf( + '%s:%d:%d', + $token_key, + Constants::get_constant( 'JETPACK__API_VERSION' ), + $token->external_user_id + ); + + $time_diff = (int) \Jetpack_Options::get_option( 'time_diff' ); + $jetpack_signature = new \Jetpack_Signature( $token->secret, $time_diff ); + + $timestamp = time() + $time_diff; + + if ( function_exists( 'wp_generate_password' ) ) { + $nonce = wp_generate_password( 10, false ); + } else { + $nonce = substr( sha1( wp_rand( 0, 1000000 ) ), 0, 10 ); + } + + // Kind of annoying. Maybe refactor Jetpack_Signature to handle body-hashing. + if ( $body === null ) { + $body_hash = ''; + + } else { + // Allow arrays to be used in passing data. + $body_to_hash = $body; + + if ( is_array( $body ) ) { + // We cast this to a new variable, because the array form of $body needs to be + // maintained so it can be passed into the request later on in the code. + if ( array() !== $body ) { + $body_to_hash = wp_json_encode( self::_stringify_data( $body ) ); + } else { + $body_to_hash = ''; + } + } + + if ( ! is_string( $body_to_hash ) ) { + return new \WP_Error( 'invalid_body', 'Body is malformed.' ); + } + + $body_hash = base64_encode( sha1( $body_to_hash, true ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode + } + + $auth = array( + 'token' => $token_key, + 'timestamp' => $timestamp, + 'nonce' => $nonce, + 'body-hash' => $body_hash, + ); + + if ( false !== strpos( $args['url'], 'xmlrpc.php' ) ) { + $url_args = array( + 'for' => 'jetpack', + 'wpcom_blog_id' => \Jetpack_Options::get_option( 'id' ), + ); + } else { + $url_args = array(); + } + + if ( 'header' !== $args['auth_location'] ) { + $url_args += $auth; + } + + $url = add_query_arg( urlencode_deep( $url_args ), $args['url'] ); + + $signature = $jetpack_signature->sign_request( $token_key, $timestamp, $nonce, $body_hash, $method, $url, $body, false ); + + if ( ! $signature || is_wp_error( $signature ) ) { + return $signature; + } + + // Send an Authorization header so various caches/proxies do the right thing. + $auth['signature'] = $signature; + $auth['version'] = Constants::get_constant( 'JETPACK__VERSION' ); + $header_pieces = array(); + foreach ( $auth as $key => $value ) { + $header_pieces[] = sprintf( '%s="%s"', $key, $value ); + } + $request['headers'] = array_merge( + $args['headers'], + array( + 'Authorization' => 'X_JETPACK ' . implode( ' ', $header_pieces ), + ) + ); + + if ( 'header' !== $args['auth_location'] ) { + $url = add_query_arg( 'signature', rawurlencode( $signature ), $url ); + } + + return compact( 'url', 'request', 'auth' ); + } + + /** + * Wrapper for wp_remote_request(). Turns off SSL verification for certain SSL errors. + * This is lame, but many, many, many hosts have misconfigured SSL. + * + * When Jetpack is registered, the jetpack_fallback_no_verify_ssl_certs option is set to the current time if: + * 1. a certificate error is found AND + * 2. not verifying the certificate works around the problem. + * + * The option is checked on each request. + * + * @internal + * + * @param String $url the request URL. + * @param array $args request arguments. + * @param Boolean $set_fallback whether to allow flagging this request to use a fallback certficate override. + * @return array|WP_Error WP HTTP response on success + */ + public static function _wp_remote_request( $url, $args, $set_fallback = false ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore + $fallback = \Jetpack_Options::get_option( 'fallback_no_verify_ssl_certs' ); + if ( false === $fallback ) { + \Jetpack_Options::update_option( 'fallback_no_verify_ssl_certs', 0 ); + } + + /** + * SSL verification (`sslverify`) for the JetpackClient remote request + * defaults to off, use this filter to force it on. + * + * Return `true` to ENABLE SSL verification, return `false` + * to DISABLE SSL verification. + * + * @since 1.7.0 + * @since-jetpack 3.6.0 + * + * @param bool Whether to force `sslverify` or not. + */ + if ( apply_filters( 'jetpack_client_verify_ssl_certs', false ) ) { + return wp_remote_request( $url, $args ); + } + + if ( (int) $fallback ) { + // We're flagged to fallback. + $args['sslverify'] = false; + } + + $response = wp_remote_request( $url, $args ); + + if ( + ! $set_fallback // We're not allowed to set the flag on this request, so whatever happens happens. + || + isset( $args['sslverify'] ) && ! $args['sslverify'] // No verification - no point in doing it again. + || + ! is_wp_error( $response ) // Let it ride. + ) { + self::set_time_diff( $response, $set_fallback ); + return $response; + } + + // At this point, we're not flagged to fallback and we are allowed to set the flag on this request. + + $message = $response->get_error_message(); + + // Is it an SSL Certificate verification error? + if ( + false === strpos( $message, '14090086' ) // OpenSSL SSL3 certificate error. + && + false === strpos( $message, '1407E086' ) // OpenSSL SSL2 certificate error. + && + false === strpos( $message, 'error setting certificate verify locations' ) // cURL CA bundle not found. + && + false === strpos( $message, 'Peer certificate cannot be authenticated with' ) // cURL CURLE_SSL_CACERT: CA bundle found, but not helpful + // Different versions of curl have different error messages + // this string should catch them all. + && + false === strpos( $message, 'Problem with the SSL CA cert' ) // cURL CURLE_SSL_CACERT_BADFILE: probably access rights. + ) { + // No, it is not. + return $response; + } + + // Redo the request without SSL certificate verification. + $args['sslverify'] = false; + $response = wp_remote_request( $url, $args ); + + if ( ! is_wp_error( $response ) ) { + // The request went through this time, flag for future fallbacks. + \Jetpack_Options::update_option( 'fallback_no_verify_ssl_certs', time() ); + self::set_time_diff( $response, $set_fallback ); + } + + return $response; + } + + /** + * Sets the time difference for correct signature computation. + * + * @param HTTP_Response $response the response object. + * @param Boolean $force_set whether to force setting the time difference. + */ + public static function set_time_diff( &$response, $force_set = false ) { + $code = wp_remote_retrieve_response_code( $response ); + + // Only trust the Date header on some responses. + if ( 200 != $code && 304 != $code && 400 != $code && 401 != $code ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual + return; + } + + $date = wp_remote_retrieve_header( $response, 'date' ); + if ( ! $date ) { + return; + } + + $time = (int) strtotime( $date ); + if ( 0 >= $time ) { + return; + } + + $time_diff = $time - time(); + + if ( $force_set ) { // During register. + \Jetpack_Options::update_option( 'time_diff', $time_diff ); + } else { // Otherwise. + $old_diff = \Jetpack_Options::get_option( 'time_diff' ); + if ( false === $old_diff || abs( $time_diff - (int) $old_diff ) > 10 ) { + \Jetpack_Options::update_option( 'time_diff', $time_diff ); + } + } + } + + /** + * Validate and build arguments for a WordPress.com REST API request. + * + * @param string $path REST API path. + * @param string $version REST API version. Default is `2`. + * @param array $args Arguments to {@see WP_Http}. Default is `array()`. + * @param string $base_api_path REST API root. Default is `wpcom`. + * + * @return array|WP_Error $response Response data, else {@see WP_Error} on failure. + */ + public static function validate_args_for_wpcom_json_api_request( + $path, + $version = '2', + $args = array(), + $base_api_path = 'wpcom' + ) { + $base_api_path = trim( $base_api_path, '/' ); + $version = ltrim( $version, 'v' ); + $path = ltrim( $path, '/' ); + + $filtered_args = array_intersect_key( + $args, + array( + 'headers' => 'array', + 'method' => 'string', + 'timeout' => 'int', + 'redirection' => 'int', + 'stream' => 'boolean', + 'filename' => 'string', + 'sslverify' => 'boolean', + ) + ); + + // Use GET by default whereas `remote_request` uses POST. + $request_method = isset( $filtered_args['method'] ) ? strtoupper( $filtered_args['method'] ) : 'GET'; + + $url = sprintf( + '%s/%s/v%s/%s', + Constants::get_constant( 'JETPACK__WPCOM_JSON_API_BASE' ), + $base_api_path, + $version, + $path + ); + + $validated_args = array_merge( + $filtered_args, + array( + 'url' => $url, + 'method' => $request_method, + ) + ); + + return $validated_args; + } + + /** + * Queries the WordPress.com REST API with a user token. + * + * @param string $path REST API path. + * @param string $version REST API version. Default is `2`. + * @param array $args Arguments to {@see WP_Http}. Default is `array()`. + * @param string $body Body passed to {@see WP_Http}. Default is `null`. + * @param string $base_api_path REST API root. Default is `wpcom`. + * + * @return array|WP_Error $response Response data, else {@see WP_Error} on failure. + */ + public static function wpcom_json_api_request_as_user( + $path, + $version = '2', + $args = array(), + $body = null, + $base_api_path = 'wpcom' + ) { + $args = self::validate_args_for_wpcom_json_api_request( $path, $version, $args, $base_api_path ); + $args['user_id'] = get_current_user_id(); + + if ( isset( $body ) && ! isset( $args['headers'] ) && in_array( $args['method'], array( 'POST', 'PUT', 'PATCH' ), true ) ) { + $args['headers'] = array( 'Content-Type' => 'application/json' ); + } + + if ( isset( $body ) && ! is_string( $body ) ) { + $body = wp_json_encode( $body ); + } + + return self::remote_request( $args, $body ); + } + + /** + * Query the WordPress.com REST API using the blog token + * + * @param String $path The API endpoint relative path. + * @param String $version The API version. + * @param array $args Request arguments. + * @param String $body Request body. + * @param String $base_api_path (optional) the API base path override, defaults to 'rest'. + * @return array|WP_Error $response Data. + */ + public static function wpcom_json_api_request_as_blog( + $path, + $version = self::WPCOM_JSON_API_VERSION, + $args = array(), + $body = null, + $base_api_path = 'rest' + ) { + $validated_args = self::validate_args_for_wpcom_json_api_request( $path, $version, $args, $base_api_path ); + $validated_args['blog_id'] = (int) \Jetpack_Options::get_option( 'id' ); + + // For Simple sites get the response directly without any HTTP requests. + if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { + add_filter( 'is_jetpack_authorized_for_site', '__return_true' ); + require_lib( 'wpcom-api-direct' ); + return \WPCOM_API_Direct::do_request( $validated_args, $body ); + } + + return self::remote_request( $validated_args, $body ); + } + + /** + * Takes an array or similar structure and recursively turns all values into strings. This is used to + * make sure that body hashes are made ith the string version, which is what will be seen after a + * server pulls up the data in the $_POST array. + * + * @param array|Mixed $data the data that needs to be stringified. + * + * @return array|string + */ + public static function _stringify_data( $data ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore + + // Booleans are special, lets just makes them and explicit 1/0 instead of the 0 being an empty string. + if ( is_bool( $data ) ) { + return $data ? '1' : '0'; + } + + // Cast objects into arrays. + if ( is_object( $data ) ) { + $data = (array) $data; + } + + // Non arrays at this point should be just converted to strings. + if ( ! is_array( $data ) ) { + return (string) $data; + } + + foreach ( $data as &$value ) { + $value = self::_stringify_data( $value ); + } + + return $data; + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-connection-notice.php b/vendor/automattic/jetpack-connection/src/class-connection-notice.php new file mode 100644 index 00000000000..eaaebc1a358 --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-connection-notice.php @@ -0,0 +1,243 @@ +id, + array( + 'jetpack_page_akismet-key-config', + 'admin_page_jetpack_modules', + ), + true + ) ) { + add_action( 'admin_notices', array( $this, 'delete_user_update_connection_owner_notice' ) ); + } + } + + /** + * This is an entire admin notice dedicated to messaging and handling of the case where a user is trying to delete + * the connection owner. + */ + public function delete_user_update_connection_owner_notice() { + global $current_screen; + + /* + * phpcs:disable WordPress.Security.NonceVerification.Recommended + * + * This function is firing within wp-admin and checks (below) if it is in the midst of a deletion on the users + * page. Nonce will be already checked by WordPress, so we do not need to check ourselves. + */ + + if ( ! isset( $current_screen->base ) || 'users' !== $current_screen->base ) { + return; + } + + if ( ! isset( $_REQUEST['action'] ) || 'delete' !== $_REQUEST['action'] ) { + return; + } + + // Get connection owner or bail. + $connection_manager = new Manager(); + $connection_owner_id = $connection_manager->get_connection_owner_id(); + if ( ! $connection_owner_id ) { + return; + } + $connection_owner_userdata = get_userdata( $connection_owner_id ); + + // Bail if we're not trying to delete connection owner. + $user_ids_to_delete = array(); + if ( isset( $_REQUEST['users'] ) ) { + $user_ids_to_delete = array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['users'] ) ); + } elseif ( isset( $_REQUEST['user'] ) ) { + $user_ids_to_delete[] = sanitize_text_field( wp_unslash( $_REQUEST['user'] ) ); + } + + // phpcs:enable + $user_ids_to_delete = array_map( 'absint', $user_ids_to_delete ); + $deleting_connection_owner = in_array( $connection_owner_id, (array) $user_ids_to_delete, true ); + if ( ! $deleting_connection_owner ) { + return; + } + + // Bail if they're trying to delete themselves to avoid confusion. + if ( get_current_user_id() === $connection_owner_id ) { + return; + } + + $tracking = new Tracking(); + + // Track it! + if ( method_exists( $tracking, 'record_user_event' ) ) { + $tracking->record_user_event( 'delete_connection_owner_notice_view' ); + } + + $connected_admins = $connection_manager->get_connected_users( 'jetpack_disconnect' ); + $user = is_a( $connection_owner_userdata, 'WP_User' ) ? esc_html( $connection_owner_userdata->data->user_login ) : ''; + + echo "
"; + echo '

' . esc_html__( 'Important notice about your Jetpack connection:', 'jetpack-connection' ) . '

'; + echo '

' . sprintf( + /* translators: WordPress User, if available. */ + esc_html__( 'Warning! You are about to delete the Jetpack connection owner (%s) for this site, which may cause some of your Jetpack features to stop working.', 'jetpack-connection' ), + esc_html( $user ) + ) . '

'; + + if ( ! empty( $connected_admins ) && count( $connected_admins ) > 1 ) { + echo '
'; + echo "'; + + $connected_admin_ids = array_map( + function ( $connected_admin ) { + return $connected_admin->ID; + }, + $connected_admins + ); + + wp_dropdown_users( + array( + 'name' => 'owner', + 'include' => array_diff( $connected_admin_ids, array( $connection_owner_id ) ), + 'show' => 'display_name_with_login', + ) + ); + + echo '

'; + submit_button( esc_html__( 'Set new connection owner', 'jetpack-connection' ), 'primary', 'jp-switch-connection-owner-submit', false ); + echo '

'; + + echo "
"; + echo '
'; + ?> + + ' . esc_html__( 'Every Jetpack site needs at least one connected admin for the features to work properly. Please connect to your WordPress.com account via the button below. Once you connect, you may refresh this page to see an option to change the connection owner.', 'jetpack-connection' ) . '

'; + $connect_url = $connection_manager->get_authorization_url(); + $connect_url = add_query_arg( 'from', 'delete_connection_owner_notice', $connect_url ); + echo "" . esc_html__( 'Connect to WordPress.com', 'jetpack-connection' ) . ''; + } + + echo '

'; + printf( + wp_kses( + /* translators: URL to Jetpack support doc regarding the primary user. */ + __( "Learn more about the connection owner and what will break if you do not have one.", 'jetpack-connection' ), + array( + 'a' => array( + 'href' => true, + 'target' => true, + 'rel' => true, + ), + ) + ), + esc_url( Redirect::get_url( 'jetpack-support-primary-user' ) ) + ); + echo '

'; + echo '

'; + printf( + wp_kses( + /* translators: URL to contact Jetpack support. */ + __( 'As always, feel free to contact our support team if you have any questions.', 'jetpack-connection' ), + array( + 'a' => array( + 'href' => true, + 'target' => true, + 'rel' => true, + ), + ) + ), + esc_url( Redirect::get_url( 'jetpack-contact-support' ) ) + ); + echo '

'; + echo '
'; + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-error-handler.php b/vendor/automattic/jetpack-connection/src/class-error-handler.php new file mode 100644 index 00000000000..b06904385d2 --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-error-handler.php @@ -0,0 +1,775 @@ + [ + * $user_id => [ + * $error_details + * ] + * ] + * ] + * + * For each error code we store a maximum of 5 errors for 5 different user ids. + * + * An user ID can be + * * 0 for blog tokens + * * positive integer for user tokens + * * 'invalid' for malformed tokens + * + * @since 1.14.2 + */ +class Error_Handler { + + /** + * The name of the option that stores the errors + * + * @since 1.14.2 + * + * @var string + */ + const STORED_ERRORS_OPTION = 'jetpack_connection_xmlrpc_errors'; + + /** + * The name of the option that stores the errors + * + * @since 1.14.2 + * + * @var string + */ + const STORED_VERIFIED_ERRORS_OPTION = 'jetpack_connection_xmlrpc_verified_errors'; + + /** + * The prefix of the transient that controls the gate for each error code + * + * @since 1.14.2 + * + * @var string + */ + const ERROR_REPORTING_GATE = 'jetpack_connection_error_reporting_gate_'; + + /** + * Time in seconds a test should live in the database before being discarded + * + * @since 1.14.2 + */ + const ERROR_LIFE_TIME = DAY_IN_SECONDS; + + /** + * The error code for event tracking purposes. + * If there are many, only the first error code will be tracked. + * + * @var string + */ + private $error_code; + + /** + * List of known errors. Only error codes in this list will be handled + * + * @since 1.14.2 + * + * @var array + */ + public $known_errors = array( + 'malformed_token', + 'malformed_user_id', + 'unknown_user', + 'no_user_tokens', + 'empty_master_user_option', + 'no_token_for_user', + 'token_malformed', + 'user_id_mismatch', + 'no_possible_tokens', + 'no_valid_user_token', + 'no_valid_blog_token', + 'unknown_token', + 'could_not_sign', + 'invalid_scheme', + 'invalid_secret', + 'invalid_token', + 'token_mismatch', + 'invalid_body', + 'invalid_signature', + 'invalid_body_hash', + 'invalid_nonce', + 'signature_mismatch', + 'invalid_connection_owner', + ); + + /** + * Holds the instance of this singleton class + * + * @since 1.14.2 + * + * @var Error_Handler $instance + */ + public static $instance = null; + + /** + * Initialize instance, hookds and load verified errors handlers + * + * @since 1.14.2 + */ + private function __construct() { + defined( 'JETPACK__ERRORS_PUBLIC_KEY' ) || define( 'JETPACK__ERRORS_PUBLIC_KEY', 'KdZY80axKX+nWzfrOcizf0jqiFHnrWCl9X8yuaClKgM=' ); + + add_action( 'rest_api_init', array( $this, 'register_verify_error_endpoint' ) ); + + $this->handle_verified_errors(); + + // If the site gets reconnected, clear errors. + add_action( 'jetpack_site_registered', array( $this, 'delete_all_errors' ) ); + add_action( 'jetpack_get_site_data_success', array( $this, 'delete_all_api_errors' ) ); + add_filter( 'jetpack_connection_disconnect_site_wpcom', array( $this, 'delete_all_errors_and_return_unfiltered_value' ) ); + add_filter( 'jetpack_connection_delete_all_tokens', array( $this, 'delete_all_errors_and_return_unfiltered_value' ) ); + add_action( 'jetpack_unlinked_user', array( $this, 'delete_all_errors' ) ); + add_action( 'jetpack_updated_user_token', array( $this, 'delete_all_errors' ) ); + } + + /** + * Gets the list of verified errors and act upon them + * + * @since 1.14.2 + * + * @return void + */ + public function handle_verified_errors() { + $verified_errors = $this->get_verified_errors(); + foreach ( array_keys( $verified_errors ) as $error_code ) { + switch ( $error_code ) { + case 'malformed_token': + case 'token_malformed': + case 'no_possible_tokens': + case 'no_valid_user_token': + case 'no_valid_blog_token': + case 'unknown_token': + case 'could_not_sign': + case 'invalid_token': + case 'token_mismatch': + case 'invalid_signature': + case 'signature_mismatch': + case 'no_user_tokens': + case 'no_token_for_user': + case 'invalid_connection_owner': + add_action( 'admin_notices', array( $this, 'generic_admin_notice_error' ) ); + add_action( 'react_connection_errors_initial_state', array( $this, 'jetpack_react_dashboard_error' ) ); + $this->error_code = $error_code; + + // Since we are only generically handling errors, we don't need to trigger error messages for each one of them. + break 2; + } + } + } + + /** + * Gets the instance of this singleton class + * + * @since 1.14.2 + * + * @return Error_Handler $instance + */ + public static function get_instance() { + if ( self::$instance === null ) { + self::$instance = new self(); + } + return self::$instance; + } + + /** + * Keep track of a connection error that was encountered + * + * @param \WP_Error $error The error object. + * @param boolean $force Force the report, even if should_report_error is false. + * @param boolean $skip_wpcom_verification Set to 'true' to verify the error locally and skip the WP.com verification. + * + * @return void + * @since 1.14.2 + */ + public function report_error( \WP_Error $error, $force = false, $skip_wpcom_verification = false ) { + if ( in_array( $error->get_error_code(), $this->known_errors, true ) && $this->should_report_error( $error ) || $force ) { + $stored_error = $this->store_error( $error ); + if ( $stored_error ) { + $skip_wpcom_verification ? $this->verify_error( $stored_error ) : $this->send_error_to_wpcom( $stored_error ); + } + } + } + + /** + * Checks the status of the gate + * + * This protects the site (and WPCOM) against over loads. + * + * @since 1.14.2 + * + * @param \WP_Error $error the error object. + * @return boolean $should_report True if gate is open and the error should be reported. + */ + public function should_report_error( \WP_Error $error ) { + if ( defined( 'JETPACK_DEV_DEBUG' ) && JETPACK_DEV_DEBUG ) { + return true; + } + + /** + * Whether to bypass the gate for the error handling + * + * By default, we only process errors once an hour for each error code. + * This is done to avoid overflows. If you need to disable this gate, you can set this variable to true. + * + * This filter is useful for unit testing + * + * @since 1.14.2 + * + * @param boolean $bypass_gate whether to bypass the gate. Default is false, do not bypass. + */ + $bypass_gate = apply_filters( 'jetpack_connection_bypass_error_reporting_gate', false ); + if ( true === $bypass_gate ) { + return true; + } + + $transient = self::ERROR_REPORTING_GATE . $error->get_error_code(); + + if ( get_transient( $transient ) ) { + return false; + } + + set_transient( $transient, true, HOUR_IN_SECONDS ); + return true; + } + + /** + * Stores the error in the database so we know there is an issue and can inform the user + * + * @since 1.14.2 + * + * @param \WP_Error $error the error object. + * @return boolean|array False if stored errors were not updated and the error array if it was successfully stored. + */ + public function store_error( \WP_Error $error ) { + + $stored_errors = $this->get_stored_errors(); + $error_array = $this->wp_error_to_array( $error ); + $error_code = $error->get_error_code(); + $user_id = $error_array['user_id']; + + if ( ! isset( $stored_errors[ $error_code ] ) || ! is_array( $stored_errors[ $error_code ] ) ) { + $stored_errors[ $error_code ] = array(); + } + + $stored_errors[ $error_code ][ $user_id ] = $error_array; + + // Let's store a maximum of 5 different user ids for each error code. + $error_code_count = is_countable( $stored_errors[ $error_code ] ) ? count( $stored_errors[ $error_code ] ) : 0; + if ( $error_code_count > 5 ) { + // array_shift will destroy keys here because they are numeric, so manually remove first item. + $keys = array_keys( $stored_errors[ $error_code ] ); + unset( $stored_errors[ $error_code ][ $keys[0] ] ); + } + + if ( update_option( self::STORED_ERRORS_OPTION, $stored_errors ) ) { + return $error_array; + } + + return false; + } + + /** + * Converts a WP_Error object in the array representation we store in the database + * + * @since 1.14.2 + * + * @param \WP_Error $error the error object. + * @return boolean|array False if error is invalid or the error array + */ + public function wp_error_to_array( \WP_Error $error ) { + + $data = $error->get_error_data(); + + if ( ! isset( $data['signature_details'] ) || ! is_array( $data['signature_details'] ) ) { + return false; + } + + $signature_details = $data['signature_details']; + + if ( ! isset( $signature_details['token'] ) ) { + return false; + } + + $user_id = $this->get_user_id_from_token( $signature_details['token'] ); + + $error_array = array( + 'error_code' => $error->get_error_code(), + 'user_id' => $user_id, + 'error_message' => $error->get_error_message(), + 'error_data' => $signature_details, + 'timestamp' => time(), + 'nonce' => wp_generate_password( 10, false ), + 'error_type' => empty( $data['error_type'] ) ? '' : $data['error_type'], + ); + + return $error_array; + } + + /** + * Sends the error to WP.com to be verified + * + * @since 1.14.2 + * + * @param array $error_array The array representation of the error as it is stored in the database. + * @return bool + */ + public function send_error_to_wpcom( $error_array ) { + + $blog_id = \Jetpack_Options::get_option( 'id' ); + + $encrypted_data = $this->encrypt_data_to_wpcom( $error_array ); + + if ( false === $encrypted_data ) { + return false; + } + + $args = array( + 'body' => array( + 'error_data' => $encrypted_data, + ), + ); + + // send encrypted data to WP.com Public-API v2. + wp_remote_post( "https://public-api.wordpress.com/wpcom/v2/sites/{$blog_id}/jetpack-report-error/", $args ); + return true; + } + + /** + * Encrypt data to be sent over to WP.com + * + * @since 1.14.2 + * + * @param array|string $data the data to be encoded. + * @return boolean|string The encoded string on success, false on failure + */ + public function encrypt_data_to_wpcom( $data ) { + + try { + // phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode + // phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode + $encrypted_data = base64_encode( sodium_crypto_box_seal( wp_json_encode( $data ), base64_decode( JETPACK__ERRORS_PUBLIC_KEY ) ) ); + // phpcs:enable WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode + // phpcs:enable WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode + } catch ( \SodiumException $e ) { + // error encrypting data. + return false; + } + + return $encrypted_data; + } + + /** + * Extracts the user ID from a token + * + * @since 1.14.2 + * + * @param string $token the token used to make the request. + * @return string $the user id or `invalid` if user id not present. + */ + public function get_user_id_from_token( $token ) { + $user_id = 'invalid'; + + if ( $token ) { + $parsed_token = explode( ':', wp_unslash( $token ) ); + + if ( isset( $parsed_token[2] ) && ctype_digit( $parsed_token[2] ) ) { + $user_id = $parsed_token[2]; + } + } + + return $user_id; + } + + /** + * Gets the reported errors stored in the database + * + * @since 1.14.2 + * + * @return array $errors + */ + public function get_stored_errors() { + + $stored_errors = get_option( self::STORED_ERRORS_OPTION ); + + if ( ! is_array( $stored_errors ) ) { + $stored_errors = array(); + } + + $stored_errors = $this->garbage_collector( $stored_errors ); + + return $stored_errors; + } + + /** + * Gets the verified errors stored in the database + * + * @since 1.14.2 + * + * @return array $errors + */ + public function get_verified_errors() { + + $verified_errors = get_option( self::STORED_VERIFIED_ERRORS_OPTION ); + + if ( ! is_array( $verified_errors ) ) { + $verified_errors = array(); + } + + $verified_errors = $this->garbage_collector( $verified_errors ); + + return $verified_errors; + } + + /** + * Removes expired errors from the array + * + * This method is called by get_stored_errors and get_verified errors and filters their result + * Whenever a new error is stored to the database or verified, this will be triggered and the + * expired error will be permantently removed from the database + * + * @since 1.14.2 + * + * @param array $errors array of errors as stored in the database. + * @return array + */ + private function garbage_collector( $errors ) { + foreach ( $errors as $error_code => $users ) { + foreach ( $users as $user_id => $error ) { + if ( self::ERROR_LIFE_TIME < time() - (int) $error['timestamp'] ) { + unset( $errors[ $error_code ][ $user_id ] ); + } + } + } + // Clear empty error codes. + $errors = array_filter( + $errors, + function ( $user_errors ) { + return ! empty( $user_errors ); + } + ); + return $errors; + } + + /** + * Delete all stored and verified errors from the database + * + * @since 1.14.2 + * + * @return void + */ + public function delete_all_errors() { + $this->delete_stored_errors(); + $this->delete_verified_errors(); + } + + /** + * Delete all stored and verified API errors from the database, leave the non-API errors intact. + * + * @since 1.54.0 + * + * @return void + */ + public function delete_all_api_errors() { + $type_filter = function ( $errors ) { + if ( is_array( $errors ) ) { + foreach ( $errors as $key => $error ) { + if ( ! empty( $error['error_type'] ) && in_array( $error['error_type'], array( 'xmlrpc', 'rest' ), true ) ) { + unset( $errors[ $key ] ); + } + } + } + + return count( $errors ) ? $errors : null; + }; + + $stored_errors = $this->get_stored_errors(); + if ( is_array( $stored_errors ) && count( $stored_errors ) ) { + $stored_errors = array_filter( array_map( $type_filter, $stored_errors ) ); + if ( count( $stored_errors ) ) { + update_option( static::STORED_ERRORS_OPTION, $stored_errors ); + } else { + delete_option( static::STORED_ERRORS_OPTION ); + } + } + + $verified_errors = $this->get_verified_errors(); + if ( is_array( $verified_errors ) && count( $verified_errors ) ) { + $verified_errors = array_filter( array_map( $type_filter, $verified_errors ) ); + if ( count( $verified_errors ) ) { + update_option( static::STORED_VERIFIED_ERRORS_OPTION, $verified_errors ); + } else { + delete_option( static::STORED_VERIFIED_ERRORS_OPTION ); + } + } + } + + /** + * Delete all stored and verified errors from the database and returns unfiltered value + * + * This is used to hook into a couple of filters that expect true to not short circuit the disconnection flow + * + * @since 8.9.0 + * + * @param mixed $check The input sent by the filter. + * @return boolean + */ + public function delete_all_errors_and_return_unfiltered_value( $check ) { + $this->delete_all_errors(); + return $check; + } + + /** + * Delete the reported errors stored in the database + * + * @since 1.14.2 + * + * @return boolean True, if option is successfully deleted. False on failure. + */ + public function delete_stored_errors() { + return delete_option( self::STORED_ERRORS_OPTION ); + } + + /** + * Delete the verified errors stored in the database + * + * @since 1.14.2 + * + * @return boolean True, if option is successfully deleted. False on failure. + */ + public function delete_verified_errors() { + return delete_option( self::STORED_VERIFIED_ERRORS_OPTION ); + } + + /** + * Gets an error based on the nonce + * + * Receives a nonce and finds the related error. + * + * @since 1.14.2 + * + * @param string $nonce The nonce created for the error we want to get. + * @return null|array Returns the error array representation or null if error not found. + */ + public function get_error_by_nonce( $nonce ) { + $errors = $this->get_stored_errors(); + foreach ( $errors as $user_group ) { + foreach ( $user_group as $error ) { + if ( $error['nonce'] === $nonce ) { + return $error; + } + } + } + return null; + } + + /** + * Adds an error to the verified error list + * + * @since 1.14.2 + * + * @param array $error The error array, as it was saved in the unverified errors list. + * @return void + */ + public function verify_error( $error ) { + + $verified_errors = $this->get_verified_errors(); + $error_code = $error['error_code']; + $user_id = $error['user_id']; + + if ( ! isset( $verified_errors[ $error_code ] ) ) { + $verified_errors[ $error_code ] = array(); + } + + $verified_errors[ $error_code ][ $user_id ] = $error; + + update_option( self::STORED_VERIFIED_ERRORS_OPTION, $verified_errors ); + } + + /** + * Register REST API end point for error hanlding. + * + * @since 1.14.2 + * + * @return void + */ + public function register_verify_error_endpoint() { + register_rest_route( + 'jetpack/v4', + '/verify_xmlrpc_error', + array( + 'methods' => \WP_REST_Server::CREATABLE, + 'callback' => array( $this, 'verify_xml_rpc_error' ), + 'permission_callback' => '__return_true', + 'args' => array( + 'nonce' => array( + 'required' => true, + 'type' => 'string', + ), + ), + ) + ); + } + + /** + * Handles verification that a xml rpc error is legit and came from WordPres.com + * + * @since 1.14.2 + * + * @param \WP_REST_Request $request The request sent to the WP REST API. + * + * @return boolean + */ + public function verify_xml_rpc_error( \WP_REST_Request $request ) { + $error = $this->get_error_by_nonce( $request['nonce'] ); + + if ( $error ) { + $this->verify_error( $error ); + return new \WP_REST_Response( true, 200 ); + } + + return new \WP_REST_Response( false, 200 ); + } + + /** + * Prints a generic error notice for all connection errors + * + * @since 8.9.0 + * + * @return void + */ + public function generic_admin_notice_error() { + // do not add admin notice to the jetpack dashboard. + global $pagenow; + if ( 'admin.php' === $pagenow || isset( $_GET['page'] ) && 'jetpack' === $_GET['page'] ) { // phpcs:ignore + return; + } + + if ( ! current_user_can( 'jetpack_connect' ) ) { + return; + } + + /** + * Filters the message to be displayed in the admin notices area when there's a connection error. + * + * By default we don't display any errors. + * + * Return an empty value to disable the message. + * + * @since 8.9.0 + * + * @param string $message The error message. + * @param array $errors The array of errors. See Automattic\Jetpack\Connection\Error_Handler for details on the array structure. + */ + $message = apply_filters( 'jetpack_connection_error_notice_message', '', $this->get_verified_errors() ); + + /** + * Fires inside the admin_notices hook just before displaying the error message for a broken connection. + * + * If you want to disable the default message from being displayed, return an emtpy value in the jetpack_connection_error_notice_message filter. + * + * @since 8.9.0 + * + * @param array $errors The array of errors. See Automattic\Jetpack\Connection\Error_Handler for details on the array structure. + */ + do_action( 'jetpack_connection_error_notice', $this->get_verified_errors() ); + + if ( empty( $message ) ) { + return; + } + + ?> + + 'connection_error', + 'message' => __( 'Your connection with WordPress.com seems to be broken. If you\'re experiencing issues, please try reconnecting.', 'jetpack-connection' ), + 'action' => 'reconnect', + 'data' => array( 'api_error_code' => $this->error_code ), + ); + return $errors; + } + + /** + * Check REST API response for errors, and report them to WP.com if needed. + * + * @see wp_remote_request() For more information on the $http_response array format. + * @param array|\WP_Error $http_response The response or WP_Error on failure. + * @param array $auth_data Auth data, allowed keys: `token`, `timestamp`, `nonce`, `body-hash`. + * @param string $url Request URL. + * @param string $method Request method. + * @param string $error_type The source of an error: 'xmlrpc' or 'rest'. + * + * @return void + */ + public function check_api_response_for_errors( $http_response, $auth_data, $url, $method, $error_type ) { + if ( 200 === wp_remote_retrieve_response_code( $http_response ) || ! is_array( $auth_data ) || ! $url || ! $method ) { + return; + } + + $body_raw = wp_remote_retrieve_body( $http_response ); + if ( ! $body_raw ) { + return; + } + + $body = json_decode( $body_raw, true ); + if ( empty( $body['error'] ) || ( ! is_string( $body['error'] ) && ! is_int( $body['error'] ) ) ) { + return; + } + + $error = new \WP_Error( + $body['error'], + empty( $body['message'] ) ? '' : $body['message'], + array( + 'signature_details' => array( + 'token' => empty( $auth_data['token'] ) ? '' : $auth_data['token'], + 'timestamp' => empty( $auth_data['timestamp'] ) ? '' : $auth_data['timestamp'], + 'nonce' => empty( $auth_data['nonce'] ) ? '' : $auth_data['nonce'], + 'body_hash' => empty( $auth_data['body_hash'] ) ? '' : $auth_data['body_hash'], + 'method' => $method, + 'url' => $url, + ), + 'error_type' => in_array( $error_type, array( 'xmlrpc', 'rest' ), true ) ? $error_type : '', + ) + ); + + $this->report_error( $error, false, true ); + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-heartbeat.php b/vendor/automattic/jetpack-connection/src/class-heartbeat.php new file mode 100644 index 00000000000..b5d9a1a4839 --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-heartbeat.php @@ -0,0 +1,252 @@ +cron_name, array( $this, 'cron_exec' ) ); + + if ( ! wp_next_scheduled( $this->cron_name ) ) { + // Deal with the old pre-3.0 weekly one. + $timestamp = wp_next_scheduled( 'jetpack_heartbeat' ); + if ( $timestamp ) { + wp_unschedule_event( $timestamp, 'jetpack_heartbeat' ); + } + + wp_schedule_event( time(), 'daily', $this->cron_name ); + } + + add_filter( 'jetpack_xmlrpc_unauthenticated_methods', array( __CLASS__, 'jetpack_xmlrpc_methods' ) ); + + if ( defined( 'WP_CLI' ) && WP_CLI ) { + WP_CLI::add_command( 'jetpack-heartbeat', array( $this, 'cli_callback' ) ); + } + } + + /** + * Method that gets executed on the wp-cron call + * + * @since 1.0.0 + * @since-jetpack 2.3.3 + * @global string $wp_version + */ + public function cron_exec() { + + $a8c_mc_stats = new A8c_Mc_Stats(); + + /* + * This should run daily. Figuring in for variances in + * WP_CRON, don't let it run more than every 23 hours at most. + * + * i.e. if it ran less than 23 hours ago, fail out. + */ + $last = (int) Jetpack_Options::get_option( 'last_heartbeat' ); + if ( $last && ( $last + DAY_IN_SECONDS - HOUR_IN_SECONDS > time() ) ) { + return; + } + + /* + * Check for an identity crisis + * + * If one exists: + * - Bump stat for ID crisis + * - Email site admin about potential ID crisis + */ + + // Coming Soon! + + foreach ( self::generate_stats_array( 'v2-' ) as $key => $value ) { + if ( is_array( $value ) ) { + foreach ( $value as $v ) { + $a8c_mc_stats->add( $key, (string) $v ); + } + } else { + $a8c_mc_stats->add( $key, (string) $value ); + } + } + + Jetpack_Options::update_option( 'last_heartbeat', time() ); + + $a8c_mc_stats->do_server_side_stats(); + + /** + * Fires when we synchronize all registered options on heartbeat. + * + * @since 3.3.0 + */ + do_action( 'jetpack_heartbeat' ); + } + + /** + * Generates heartbeat stats data. + * + * @param string $prefix Prefix to add before stats identifier. + * + * @return array The stats array. + */ + public static function generate_stats_array( $prefix = '' ) { + + /** + * This filter is used to build the array of stats that are bumped once a day by Jetpack Heartbeat. + * + * Filter the array and add key => value pairs where + * * key is the stat group name + * * value is the stat name. + * + * Example: + * add_filter( 'jetpack_heartbeat_stats_array', function( $stats ) { + * $stats['is-https'] = is_ssl() ? 'https' : 'http'; + * }); + * + * This will bump the stats for the 'is-https/https' or 'is-https/http' stat. + * + * @param array $stats The stats to be filtered. + * @param string $prefix The prefix that will automatically be added at the begining at each stat group name. + */ + $stats = apply_filters( 'jetpack_heartbeat_stats_array', array(), $prefix ); + $return = array(); + + // Apply prefix to stats. + foreach ( $stats as $stat => $value ) { + $return[ "$prefix$stat" ] = $value; + } + + return $return; + } + + /** + * Registers jetpack.getHeartbeatData xmlrpc method + * + * @param array $methods The list of methods to be filtered. + * @return array $methods + */ + public static function jetpack_xmlrpc_methods( $methods ) { + $methods['jetpack.getHeartbeatData'] = array( __CLASS__, 'xmlrpc_data_response' ); + return $methods; + } + + /** + * Handles the response for the jetpack.getHeartbeatData xmlrpc method + * + * @param array $params The parameters received in the request. + * @return array $params all the stats that heartbeat handles. + */ + public static function xmlrpc_data_response( $params = array() ) { + // The WordPress XML-RPC server sets a default param of array() + // if no argument is passed on the request and the method handlers get this array in $params. + // generate_stats_array() needs a string as first argument. + $params = empty( $params ) ? '' : $params; + return self::generate_stats_array( $params ); + } + + /** + * Clear scheduled events + * + * @return void + */ + public function deactivate() { + // Deal with the old pre-3.0 weekly one. + $timestamp = wp_next_scheduled( 'jetpack_heartbeat' ); + if ( $timestamp ) { + wp_unschedule_event( $timestamp, 'jetpack_heartbeat' ); + } + + $timestamp = wp_next_scheduled( $this->cron_name ); + wp_unschedule_event( $timestamp, $this->cron_name ); + } + + /** + * Interact with the Heartbeat + * + * ## OPTIONS + * + * inspect (default): Gets the list of data that is going to be sent in the heartbeat and the date/time of the last heartbeat + * + * @param array $args Arguments passed via CLI. + * + * @return void + */ + public function cli_callback( $args ) { + + $allowed_args = array( + 'inspect', + ); + + if ( isset( $args[0] ) && ! in_array( $args[0], $allowed_args, true ) ) { + /* translators: %s is a command like "prompt" */ + WP_CLI::error( sprintf( __( '%s is not a valid command.', 'jetpack-connection' ), $args[0] ) ); + } + + $stats = self::generate_stats_array(); + $formatted_stats = array(); + + foreach ( $stats as $stat_name => $bin ) { + $formatted_stats[] = array( + 'Stat name' => $stat_name, + 'Bin' => $bin, + ); + } + + WP_CLI\Utils\format_items( 'table', $formatted_stats, array( 'Stat name', 'Bin' ) ); + + $last_heartbeat = Jetpack_Options::get_option( 'last_heartbeat' ); + + if ( $last_heartbeat ) { + $last_date = gmdate( 'Y-m-d H:i:s', $last_heartbeat ); + /* translators: %s is the full datetime of the last heart beat e.g. 2020-01-01 12:21:23 */ + WP_CLI::line( sprintf( __( 'Last heartbeat sent at: %s', 'jetpack-connection' ), $last_date ) ); + } + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-initial-state.php b/vendor/automattic/jetpack-connection/src/class-initial-state.php new file mode 100644 index 00000000000..5d23562d916 --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-initial-state.php @@ -0,0 +1,61 @@ + esc_url_raw( rest_url() ), + 'apiNonce' => wp_create_nonce( 'wp_rest' ), + 'registrationNonce' => wp_create_nonce( 'jetpack-registration-nonce' ), + 'connectionStatus' => REST_Connector::connection_status( false ), + 'userConnectionData' => REST_Connector::get_user_connection_data( false ), + 'connectedPlugins' => REST_Connector::get_connection_plugins( false ), + 'wpVersion' => $wp_version, + 'siteSuffix' => $status->get_site_suffix(), + 'connectionErrors' => Error_Handler::get_instance()->get_verified_errors(), + 'isOfflineMode' => $status->is_offline_mode(), + 'calypsoEnv' => ( new Status\Host() )->get_calypso_env(), + ); + } + + /** + * Render the initial state into a JavaScript variable. + * + * @return string + */ + public static function render() { + return 'var JP_CONNECTION_INITIAL_STATE; typeof JP_CONNECTION_INITIAL_STATE === "object" || (JP_CONNECTION_INITIAL_STATE = JSON.parse(decodeURIComponent("' . rawurlencode( wp_json_encode( self::get_data() ) ) . '")));'; + } + + /** + * Render the initial state using an inline script. + * + * @param string $handle The JS script handle. + * + * @return void + */ + public static function render_script( $handle ) { + wp_add_inline_script( $handle, static::render(), 'before' ); + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-manager.php b/vendor/automattic/jetpack-connection/src/class-manager.php new file mode 100644 index 00000000000..88622e79592 --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-manager.php @@ -0,0 +1,2561 @@ +set_plugin_instance( new Plugin( $plugin_slug ) ); + } + } + + /** + * Initializes required listeners. This is done separately from the constructors + * because some objects sometimes need to instantiate separate objects of this class. + * + * @todo Implement a proper nonce verification. + */ + public static function configure() { + $manager = new self(); + + add_filter( + 'jetpack_constant_default_value', + __NAMESPACE__ . '\Utils::jetpack_api_constant_filter', + 10, + 2 + ); + + $manager->setup_xmlrpc_handlers( + $_GET, // phpcs:ignore WordPress.Security.NonceVerification.Recommended + $manager->has_connected_owner(), + $manager->verify_xml_rpc_signature() + ); + + $manager->error_handler = Error_Handler::get_instance(); + + if ( $manager->is_connected() ) { + add_filter( 'xmlrpc_methods', array( $manager, 'public_xmlrpc_methods' ) ); + add_filter( 'shutdown', array( new Package_Version_Tracker(), 'maybe_update_package_versions' ) ); + } + + add_action( 'rest_api_init', array( $manager, 'initialize_rest_api_registration_connector' ) ); + + ( new Nonce_Handler() )->init_schedule(); + + add_action( 'plugins_loaded', __NAMESPACE__ . '\Plugin_Storage::configure', 100 ); + + add_filter( 'map_meta_cap', array( $manager, 'jetpack_connection_custom_caps' ), 1, 4 ); + + Heartbeat::init(); + add_filter( 'jetpack_heartbeat_stats_array', array( $manager, 'add_stats_to_heartbeat' ) ); + + Webhooks::init( $manager ); + + // Set up package version hook. + add_filter( 'jetpack_package_versions', __NAMESPACE__ . '\Package_Version::send_package_version_to_tracker' ); + + if ( defined( 'JETPACK__SANDBOX_DOMAIN' ) && JETPACK__SANDBOX_DOMAIN ) { + ( new Server_Sandbox() )->init(); + } + + // Initialize connection notices. + new Connection_Notice(); + + // Initialize token locks. + new Tokens_Locks(); + } + + /** + * Sets up the XMLRPC request handlers. + * + * @since 1.25.0 Deprecate $is_active param. + * + * @param array $request_params incoming request parameters. + * @param bool $has_connected_owner Whether the site has a connected owner. + * @param bool $is_signed whether the signature check has been successful. + * @param \Jetpack_XMLRPC_Server $xmlrpc_server (optional) an instance of the server to use instead of instantiating a new one. + */ + public function setup_xmlrpc_handlers( + $request_params, + $has_connected_owner, + $is_signed, + \Jetpack_XMLRPC_Server $xmlrpc_server = null + ) { + add_filter( 'xmlrpc_blog_options', array( $this, 'xmlrpc_options' ), 1000, 2 ); + + if ( + ! isset( $request_params['for'] ) + || 'jetpack' !== $request_params['for'] + ) { + return false; + } + + // Alternate XML-RPC, via ?for=jetpack&jetpack=comms. + if ( + isset( $request_params['jetpack'] ) + && 'comms' === $request_params['jetpack'] + ) { + if ( ! Constants::is_defined( 'XMLRPC_REQUEST' ) ) { + // Use the real constant here for WordPress' sake. + define( 'XMLRPC_REQUEST', true ); + } + + add_action( 'template_redirect', array( $this, 'alternate_xmlrpc' ) ); + + add_filter( 'xmlrpc_methods', array( $this, 'remove_non_jetpack_xmlrpc_methods' ), 1000 ); + } + + if ( ! Constants::get_constant( 'XMLRPC_REQUEST' ) ) { + return false; + } + // Display errors can cause the XML to be not well formed. + @ini_set( 'display_errors', false ); // phpcs:ignore + + if ( $xmlrpc_server ) { + $this->xmlrpc_server = $xmlrpc_server; + } else { + $this->xmlrpc_server = new \Jetpack_XMLRPC_Server(); + } + + $this->require_jetpack_authentication(); + + if ( $is_signed ) { + // If the site is connected either at a site or user level and the request is signed, expose the methods. + // The callback is responsible to determine whether the request is signed with blog or user token and act accordingly. + // The actual API methods. + $callback = array( $this->xmlrpc_server, 'xmlrpc_methods' ); + + // Hack to preserve $HTTP_RAW_POST_DATA. + add_filter( 'xmlrpc_methods', array( $this, 'xmlrpc_methods' ) ); + + } elseif ( $has_connected_owner && ! $is_signed ) { + // The jetpack.authorize method should be available for unauthenticated users on a site with an + // active Jetpack connection, so that additional users can link their account. + $callback = array( $this->xmlrpc_server, 'authorize_xmlrpc_methods' ); + } else { + // Any other unsigned request should expose the bootstrap methods. + $callback = array( $this->xmlrpc_server, 'bootstrap_xmlrpc_methods' ); + new XMLRPC_Connector( $this ); + } + + add_filter( 'xmlrpc_methods', $callback ); + + // Now that no one can authenticate, and we're whitelisting all XML-RPC methods, force enable_xmlrpc on. + add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); + return true; + } + + /** + * Initializes the REST API connector on the init hook. + */ + public function initialize_rest_api_registration_connector() { + new REST_Connector( $this ); + } + + /** + * Since a lot of hosts use a hammer approach to "protecting" WordPress sites, + * and just blanket block all requests to /xmlrpc.php, or apply other overly-sensitive + * security/firewall policies, we provide our own alternate XML RPC API endpoint + * which is accessible via a different URI. Most of the below is copied directly + * from /xmlrpc.php so that we're replicating it as closely as possible. + * + * @todo Tighten $wp_xmlrpc_server_class a bit to make sure it doesn't do bad things. + */ + public function alternate_xmlrpc() { + // Some browser-embedded clients send cookies. We don't want them. + $_COOKIE = array(); + + include_once ABSPATH . 'wp-admin/includes/admin.php'; + include_once ABSPATH . WPINC . '/class-IXR.php'; + include_once ABSPATH . WPINC . '/class-wp-xmlrpc-server.php'; + + /** + * Filters the class used for handling XML-RPC requests. + * + * @since 1.7.0 + * @since-jetpack 3.1.0 + * + * @param string $class The name of the XML-RPC server class. + */ + $wp_xmlrpc_server_class = apply_filters( 'wp_xmlrpc_server_class', 'wp_xmlrpc_server' ); + $wp_xmlrpc_server = new $wp_xmlrpc_server_class(); + + // Fire off the request. + nocache_headers(); + $wp_xmlrpc_server->serve_request(); + + exit; + } + + /** + * Removes all XML-RPC methods that are not `jetpack.*`. + * Only used in our alternate XML-RPC endpoint, where we want to + * ensure that Core and other plugins' methods are not exposed. + * + * @param array $methods a list of registered WordPress XMLRPC methods. + * @return array filtered $methods + */ + public function remove_non_jetpack_xmlrpc_methods( $methods ) { + $jetpack_methods = array(); + + foreach ( $methods as $method => $callback ) { + if ( 0 === strpos( $method, 'jetpack.' ) ) { + $jetpack_methods[ $method ] = $callback; + } + } + + return $jetpack_methods; + } + + /** + * Removes all other authentication methods not to allow other + * methods to validate unauthenticated requests. + */ + public function require_jetpack_authentication() { + // Don't let anyone authenticate. + $_COOKIE = array(); + remove_all_filters( 'authenticate' ); + remove_all_actions( 'wp_login_failed' ); + + if ( $this->is_connected() ) { + // Allow Jetpack authentication. + add_filter( 'authenticate', array( $this, 'authenticate_jetpack' ), 10, 3 ); + } + } + + /** + * Authenticates XML-RPC and other requests from the Jetpack Server + * + * @param WP_User|Mixed $user user object if authenticated. + * @param String $username username. + * @param String $password password string. + * @return WP_User|Mixed authenticated user or error. + */ + public function authenticate_jetpack( $user, $username, $password ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + if ( is_a( $user, '\\WP_User' ) ) { + return $user; + } + + $token_details = $this->verify_xml_rpc_signature(); + + if ( ! $token_details ) { + return $user; + } + + if ( 'user' !== $token_details['type'] ) { + return $user; + } + + if ( ! $token_details['user_id'] ) { + return $user; + } + + nocache_headers(); + + return new \WP_User( $token_details['user_id'] ); + } + + /** + * Verifies the signature of the current request. + * + * @return false|array + */ + public function verify_xml_rpc_signature() { + if ( $this->xmlrpc_verification === null ) { + $this->xmlrpc_verification = $this->internal_verify_xml_rpc_signature(); + + if ( is_wp_error( $this->xmlrpc_verification ) ) { + /** + * Action for logging XMLRPC signature verification errors. This data is sensitive. + * + * @since 1.7.0 + * @since-jetpack 7.5.0 + * + * @param WP_Error $signature_verification_error The verification error + */ + do_action( 'jetpack_verify_signature_error', $this->xmlrpc_verification ); + + Error_Handler::get_instance()->report_error( $this->xmlrpc_verification ); + + } + } + + return is_wp_error( $this->xmlrpc_verification ) ? false : $this->xmlrpc_verification; + } + + /** + * Verifies the signature of the current request. + * + * This function has side effects and should not be used. Instead, + * use the memoized version `->verify_xml_rpc_signature()`. + * + * @internal + * @todo Refactor to use proper nonce verification. + */ + private function internal_verify_xml_rpc_signature() { + // phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + // It's not for us. + if ( ! isset( $_GET['token'] ) || empty( $_GET['signature'] ) ) { + return false; + } + + $signature_details = array( + 'token' => isset( $_GET['token'] ) ? wp_unslash( $_GET['token'] ) : '', + 'timestamp' => isset( $_GET['timestamp'] ) ? wp_unslash( $_GET['timestamp'] ) : '', + 'nonce' => isset( $_GET['nonce'] ) ? wp_unslash( $_GET['nonce'] ) : '', + 'body_hash' => isset( $_GET['body-hash'] ) ? wp_unslash( $_GET['body-hash'] ) : '', + 'method' => isset( $_SERVER['REQUEST_METHOD'] ) ? wp_unslash( $_SERVER['REQUEST_METHOD'] ) : null, + 'url' => wp_unslash( ( isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : null ) . ( isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : null ) ), // Temp - will get real signature URL later. + 'signature' => isset( $_GET['signature'] ) ? wp_unslash( $_GET['signature'] ) : '', + ); + + $error_type = 'xmlrpc'; + + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged + @list( $token_key, $version, $user_id ) = explode( ':', wp_unslash( $_GET['token'] ) ); + // phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + + $jetpack_api_version = Constants::get_constant( 'JETPACK__API_VERSION' ); + + if ( + empty( $token_key ) + || + empty( $version ) || (string) $jetpack_api_version !== $version ) { + return new \WP_Error( 'malformed_token', 'Malformed token in request', compact( 'signature_details', 'error_type' ) ); + } + + if ( '0' === $user_id ) { + $token_type = 'blog'; + $user_id = 0; + } else { + $token_type = 'user'; + if ( empty( $user_id ) || ! ctype_digit( $user_id ) ) { + return new \WP_Error( + 'malformed_user_id', + 'Malformed user_id in request', + compact( 'signature_details', 'error_type' ) + ); + } + $user_id = (int) $user_id; + + $user = new \WP_User( $user_id ); + if ( ! $user || ! $user->exists() ) { + return new \WP_Error( + 'unknown_user', + sprintf( 'User %d does not exist', $user_id ), + compact( 'signature_details', 'error_type' ) + ); + } + } + + $token = $this->get_tokens()->get_access_token( $user_id, $token_key, false ); + if ( is_wp_error( $token ) ) { + $token->add_data( compact( 'signature_details', 'error_type' ) ); + return $token; + } elseif ( ! $token ) { + return new \WP_Error( + 'unknown_token', + sprintf( 'Token %s:%s:%d does not exist', $token_key, $version, $user_id ), + compact( 'signature_details', 'error_type' ) + ); + } + + $jetpack_signature = new \Jetpack_Signature( $token->secret, (int) \Jetpack_Options::get_option( 'time_diff' ) ); + // phpcs:disable WordPress.Security.NonceVerification.Missing + if ( isset( $_POST['_jetpack_is_multipart'] ) ) { + $post_data = $_POST; + $file_hashes = array(); + foreach ( $post_data as $post_data_key => $post_data_value ) { + if ( 0 !== strpos( $post_data_key, '_jetpack_file_hmac_' ) ) { + continue; + } + $post_data_key = substr( $post_data_key, strlen( '_jetpack_file_hmac_' ) ); + $file_hashes[ $post_data_key ] = $post_data_value; + } + + foreach ( $file_hashes as $post_data_key => $post_data_value ) { + unset( $post_data[ "_jetpack_file_hmac_{$post_data_key}" ] ); + $post_data[ $post_data_key ] = $post_data_value; + } + + ksort( $post_data ); + + $body = http_build_query( stripslashes_deep( $post_data ) ); + } elseif ( $this->raw_post_data === null ) { + $body = file_get_contents( 'php://input' ); + } else { + $body = null; + } + // phpcs:enable + + $signature = $jetpack_signature->sign_current_request( + array( 'body' => $body === null ? $this->raw_post_data : $body ) + ); + + $signature_details['url'] = $jetpack_signature->current_request_url; + + if ( ! $signature ) { + return new \WP_Error( + 'could_not_sign', + 'Unknown signature error', + compact( 'signature_details', 'error_type' ) + ); + } elseif ( is_wp_error( $signature ) ) { + return $signature; + } + + // phpcs:disable WordPress.Security.NonceVerification.Recommended + $timestamp = (int) $_GET['timestamp']; + $nonce = wp_unslash( (string) $_GET['nonce'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- WP Core doesn't sanitize nonces either. + // phpcs:enable WordPress.Security.NonceVerification.Recommended + + // Use up the nonce regardless of whether the signature matches. + if ( ! ( new Nonce_Handler() )->add( $timestamp, $nonce ) ) { + return new \WP_Error( + 'invalid_nonce', + 'Could not add nonce', + compact( 'signature_details', 'error_type' ) + ); + } + + // Be careful about what you do with this debugging data. + // If a malicious requester has access to the expected signature, + // bad things might be possible. + $signature_details['expected'] = $signature; + + // phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( ! hash_equals( $signature, wp_unslash( $_GET['signature'] ) ) ) { + return new \WP_Error( + 'signature_mismatch', + 'Signature mismatch', + compact( 'signature_details', 'error_type' ) + ); + } + + /** + * Action for additional token checking. + * + * @since 1.7.0 + * @since-jetpack 7.7.0 + * + * @param array $post_data request data. + * @param array $token_data token data. + */ + return apply_filters( + 'jetpack_signature_check_token', + array( + 'type' => $token_type, + 'token_key' => $token_key, + 'user_id' => $token->external_user_id, + ), + $token, + $this->raw_post_data + ); + } + + /** + * Returns true if the current site is connected to WordPress.com and has the minimum requirements to enable Jetpack UI. + * + * This method is deprecated since version 1.25.0 of this package. Please use has_connected_owner instead. + * + * Since this method has a wide spread use, we decided not to throw any deprecation warnings for now. + * + * @deprecated 1.25.0 + * @see Manager::has_connected_owner + * @return Boolean is the site connected? + */ + public function is_active() { + return (bool) $this->get_tokens()->get_access_token( true ); + } + + /** + * Obtains an instance of the Tokens class. + * + * @return Tokens the Tokens object + */ + public function get_tokens() { + return new Tokens(); + } + + /** + * Returns true if the site has both a token and a blog id, which indicates a site has been registered. + * + * @access public + * @deprecated 1.12.1 Use is_connected instead + * @see Manager::is_connected + * + * @return bool + */ + public function is_registered() { + _deprecated_function( __METHOD__, '1.12.1' ); + return $this->is_connected(); + } + + /** + * Returns true if the site has both a token and a blog id, which indicates a site has been connected. + * + * @access public + * @since 1.21.1 + * + * @return bool + */ + public function is_connected() { + $has_blog_id = (bool) \Jetpack_Options::get_option( 'id' ); + $has_blog_token = (bool) $this->get_tokens()->get_access_token(); + return $has_blog_id && $has_blog_token; + } + + /** + * Returns true if the site has at least one connected administrator. + * + * @access public + * @since 1.21.1 + * + * @return bool + */ + public function has_connected_admin() { + return (bool) count( $this->get_connected_users( 'manage_options' ) ); + } + + /** + * Returns true if the site has any connected user. + * + * @access public + * @since 1.21.1 + * + * @return bool + */ + public function has_connected_user() { + return (bool) count( $this->get_connected_users( 'any', 1 ) ); + } + + /** + * Returns an array of users that have user tokens for communicating with wpcom. + * Able to select by specific capability. + * + * @since 9.9.1 Added $limit parameter. + * + * @param string $capability The capability of the user. + * @param int|null $limit How many connected users to get before returning. + * @return WP_User[] Array of WP_User objects if found. + */ + public function get_connected_users( $capability = 'any', $limit = null ) { + $connected_users = array(); + $user_tokens = $this->get_tokens()->get_user_tokens(); + + if ( ! is_array( $user_tokens ) || empty( $user_tokens ) ) { + return $connected_users; + } + $connected_user_ids = array_keys( $user_tokens ); + + if ( ! empty( $connected_user_ids ) ) { + foreach ( $connected_user_ids as $id ) { + // Check for capability. + if ( 'any' !== $capability && ! user_can( $id, $capability ) ) { + continue; + } + + $user_data = get_userdata( $id ); + if ( $user_data instanceof \WP_User ) { + $connected_users[] = $user_data; + if ( $limit && count( $connected_users ) >= $limit ) { + return $connected_users; + } + } + } + } + + return $connected_users; + } + + /** + * Returns true if the site has a connected Blog owner (master_user). + * + * @access public + * @since 1.21.1 + * + * @return bool + */ + public function has_connected_owner() { + return (bool) $this->get_connection_owner_id(); + } + + /** + * Returns true if the site is connected only at a site level. + * + * Note that we are explicitly checking for the existence of the master_user option in order to account for cases where we don't have any user tokens (user-level connection) but the master_user option is set, which could be the result of a problematic user connection. + * + * @access public + * @since 1.25.0 + * @deprecated 1.27.0 + * + * @return bool + */ + public function is_userless() { + _deprecated_function( __METHOD__, '1.27.0', 'Automattic\\Jetpack\\Connection\\Manager::is_site_connection' ); + return $this->is_site_connection(); + } + + /** + * Returns true if the site is connected only at a site level. + * + * Note that we are explicitly checking for the existence of the master_user option in order to account for cases where we don't have any user tokens (user-level connection) but the master_user option is set, which could be the result of a problematic user connection. + * + * @access public + * @since 1.27.0 + * + * @return bool + */ + public function is_site_connection() { + return $this->is_connected() && ! $this->has_connected_user() && ! \Jetpack_Options::get_option( 'master_user' ); + } + + /** + * Checks to see if the connection owner of the site is missing. + * + * @return bool + */ + public function is_missing_connection_owner() { + $connection_owner = $this->get_connection_owner_id(); + if ( ! get_user_by( 'id', $connection_owner ) ) { + return true; + } + + return false; + } + + /** + * Returns true if the user with the specified identifier is connected to + * WordPress.com. + * + * @param int $user_id the user identifier. Default is the current user. + * @return bool Boolean is the user connected? + */ + public function is_user_connected( $user_id = false ) { + $user_id = false === $user_id ? get_current_user_id() : absint( $user_id ); + if ( ! $user_id ) { + return false; + } + + return (bool) $this->get_tokens()->get_access_token( $user_id ); + } + + /** + * Returns the local user ID of the connection owner. + * + * @return bool|int Returns the ID of the connection owner or False if no connection owner found. + */ + public function get_connection_owner_id() { + $owner = $this->get_connection_owner(); + return $owner instanceof \WP_User ? $owner->ID : false; + } + + /** + * Get the wpcom user data of the current|specified connected user. + * + * @todo Refactor to properly load the XMLRPC client independently. + * + * @param Integer $user_id the user identifier. + * @return bool|array An array with the WPCOM user data on success, false otherwise. + */ + public function get_connected_user_data( $user_id = null ) { + if ( ! $user_id ) { + $user_id = get_current_user_id(); + } + + // Check if the user is connected and return false otherwise. + if ( ! $this->is_user_connected( $user_id ) ) { + return false; + } + + $transient_key = "jetpack_connected_user_data_$user_id"; + $cached_user_data = get_transient( $transient_key ); + + if ( $cached_user_data ) { + return $cached_user_data; + } + + $xml = new Jetpack_IXR_Client( + array( + 'user_id' => $user_id, + ) + ); + $xml->query( 'wpcom.getUser' ); + + if ( ! $xml->isError() ) { + $user_data = $xml->getResponse(); + set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS ); + return $user_data; + } + + return false; + } + + /** + * Returns a user object of the connection owner. + * + * @return WP_User|false False if no connection owner found. + */ + public function get_connection_owner() { + + $user_id = \Jetpack_Options::get_option( 'master_user' ); + + if ( ! $user_id ) { + return false; + } + + // Make sure user is connected. + $user_token = $this->get_tokens()->get_access_token( $user_id ); + + $connection_owner = false; + + if ( $user_token && is_object( $user_token ) && isset( $user_token->external_user_id ) ) { + $connection_owner = get_userdata( $user_token->external_user_id ); + } + + if ( $connection_owner === false ) { + Error_Handler::get_instance()->report_error( + new WP_Error( + 'invalid_connection_owner', + 'Invalid connection owner', + array( + 'user_id' => $user_id, + 'has_user_token' => (bool) $user_token, + 'error_type' => 'connection', + 'signature_details' => array( + 'token' => '', + ), + ) + ), + false, + true + ); + } + + return $connection_owner; + } + + /** + * Returns true if the provided user is the Jetpack connection owner. + * If user ID is not specified, the current user will be used. + * + * @param Integer|Boolean $user_id the user identifier. False for current user. + * @return Boolean True the user the connection owner, false otherwise. + */ + public function is_connection_owner( $user_id = false ) { + if ( ! $user_id ) { + $user_id = get_current_user_id(); + } + + return ( (int) $user_id ) === $this->get_connection_owner_id(); + } + + /** + * Connects the user with a specified ID to a WordPress.com user using the + * remote login flow. + * + * @access public + * + * @param Integer $user_id (optional) the user identifier, defaults to current user. + * @param String $redirect_url the URL to redirect the user to for processing, defaults to + * admin_url(). + * @return WP_Error only in case of a failed user lookup. + */ + public function connect_user( $user_id = null, $redirect_url = null ) { + $user = null; + if ( null === $user_id ) { + $user = wp_get_current_user(); + } else { + $user = get_user_by( 'ID', $user_id ); + } + + if ( empty( $user ) ) { + return new \WP_Error( 'user_not_found', 'Attempting to connect a non-existent user.' ); + } + + if ( null === $redirect_url ) { + $redirect_url = admin_url(); + } + + // Using wp_redirect intentionally because we're redirecting outside. + wp_redirect( $this->get_authorization_url( $user, $redirect_url ) ); // phpcs:ignore WordPress.Security.SafeRedirect + exit(); + } + + /** + * Unlinks the current user from the linked WordPress.com user. + * + * @access public + * @static + * + * @todo Refactor to properly load the XMLRPC client independently. + * + * @param Integer $user_id the user identifier. + * @param bool $can_overwrite_primary_user Allow for the primary user to be disconnected. + * @param bool $force_disconnect_locally Disconnect user locally even if we were unable to disconnect them from WP.com. + * @return Boolean Whether the disconnection of the user was successful. + */ + public function disconnect_user( $user_id = null, $can_overwrite_primary_user = false, $force_disconnect_locally = false ) { + $user_id = empty( $user_id ) ? get_current_user_id() : (int) $user_id; + $is_primary_user = Jetpack_Options::get_option( 'master_user' ) === $user_id; + + if ( $is_primary_user && ! $can_overwrite_primary_user ) { + return false; + } + + // Attempt to disconnect the user from WordPress.com. + $is_disconnected_from_wpcom = $this->unlink_user_from_wpcom( $user_id ); + + $is_disconnected_locally = false; + if ( $is_disconnected_from_wpcom || $force_disconnect_locally ) { + // Disconnect the user locally. + $is_disconnected_locally = $this->get_tokens()->disconnect_user( $user_id ); + + if ( $is_disconnected_locally ) { + // Delete cached connected user data. + $transient_key = "jetpack_connected_user_data_$user_id"; + delete_transient( $transient_key ); + + /** + * Fires after the current user has been unlinked from WordPress.com. + * + * @since 1.7.0 + * @since-jetpack 4.1.0 + * + * @param int $user_id The current user's ID. + */ + do_action( 'jetpack_unlinked_user', $user_id ); + + if ( $is_primary_user ) { + Jetpack_Options::delete_option( 'master_user' ); + } + } + } + + return $is_disconnected_from_wpcom && $is_disconnected_locally; + } + + /** + * Request to wpcom for a user to be unlinked from their WordPress.com account + * + * @param int $user_id The user identifier. + * + * @return bool Whether the disconnection of the user was successful. + */ + public function unlink_user_from_wpcom( $user_id ) { + // Attempt to disconnect the user from WordPress.com. + $xml = new Jetpack_IXR_Client(); + + $xml->query( 'jetpack.unlink_user', $user_id ); + if ( $xml->isError() ) { + return false; + } + + return (bool) $xml->getResponse(); + } + + /** + * Update the connection owner. + * + * @since 1.29.0 + * + * @param Integer $new_owner_id The ID of the user to become the connection owner. + * + * @return true|WP_Error True if owner successfully changed, WP_Error otherwise. + */ + public function update_connection_owner( $new_owner_id ) { + $roles = new Roles(); + if ( ! user_can( $new_owner_id, $roles->translate_role_to_cap( 'administrator' ) ) ) { + return new WP_Error( + 'new_owner_not_admin', + __( 'New owner is not admin', 'jetpack-connection' ), + array( 'status' => 400 ) + ); + } + + $old_owner_id = $this->get_connection_owner_id(); + + if ( $old_owner_id === $new_owner_id ) { + return new WP_Error( + 'new_owner_is_existing_owner', + __( 'New owner is same as existing owner', 'jetpack-connection' ), + array( 'status' => 400 ) + ); + } + + if ( ! $this->is_user_connected( $new_owner_id ) ) { + return new WP_Error( + 'new_owner_not_connected', + __( 'New owner is not connected', 'jetpack-connection' ), + array( 'status' => 400 ) + ); + } + + // Notify WPCOM about the connection owner change. + $owner_updated_wpcom = $this->update_connection_owner_wpcom( $new_owner_id ); + + if ( $owner_updated_wpcom ) { + // Update the connection owner in Jetpack only if they were successfully updated on WPCOM. + // This will ensure consistency with WPCOM. + \Jetpack_Options::update_option( 'master_user', $new_owner_id ); + + // Track it. + ( new Tracking() )->record_user_event( 'set_connection_owner_success' ); + + return true; + } + return new WP_Error( + 'error_setting_new_owner', + __( 'Could not confirm new owner.', 'jetpack-connection' ), + array( 'status' => 500 ) + ); + } + + /** + * Request to WPCOM to update the connection owner. + * + * @since 1.29.0 + * + * @param Integer $new_owner_id The ID of the user to become the connection owner. + * + * @return Boolean Whether the ownership transfer was successful. + */ + public function update_connection_owner_wpcom( $new_owner_id ) { + // Notify WPCOM about the connection owner change. + $xml = new Jetpack_IXR_Client( + array( + 'user_id' => get_current_user_id(), + ) + ); + $xml->query( + 'jetpack.switchBlogOwner', + array( + 'new_blog_owner' => $new_owner_id, + ) + ); + if ( $xml->isError() ) { + return false; + } + + return (bool) $xml->getResponse(); + } + + /** + * Returns the requested Jetpack API URL. + * + * @param String $relative_url the relative API path. + * @return String API URL. + */ + public function api_url( $relative_url ) { + $api_base = Constants::get_constant( 'JETPACK__API_BASE' ); + $api_version = '/' . Constants::get_constant( 'JETPACK__API_VERSION' ) . '/'; + + /** + * Filters the API URL that Jetpack uses for server communication. + * + * @since 1.7.0 + * @since-jetpack 8.0.0 + * + * @param String $url the generated URL. + * @param String $relative_url the relative URL that was passed as an argument. + * @param String $api_base the API base string that is being used. + * @param String $api_version the API version string that is being used. + */ + return apply_filters( + 'jetpack_api_url', + rtrim( $api_base . $relative_url, '/\\' ) . $api_version, + $relative_url, + $api_base, + $api_version + ); + } + + /** + * Returns the Jetpack XMLRPC WordPress.com API endpoint URL. + * + * @return String XMLRPC API URL. + */ + public function xmlrpc_api_url() { + $base = preg_replace( + '#(https?://[^?/]+)(/?.*)?$#', + '\\1', + Constants::get_constant( 'JETPACK__API_BASE' ) + ); + return untrailingslashit( $base ) . '/xmlrpc.php'; + } + + /** + * Attempts Jetpack registration which sets up the site for connection. Should + * remain public because the call to action comes from the current site, not from + * WordPress.com. + * + * @param String $api_endpoint (optional) an API endpoint to use, defaults to 'register'. + * @return true|WP_Error The error object. + */ + public function register( $api_endpoint = 'register' ) { + // Clean-up leftover tokens just in-case. + // This fixes an edge case that was preventing users to register when the blog token was missing but + // there were still leftover user tokens present. + $this->delete_all_connection_tokens( true ); + + add_action( 'pre_update_jetpack_option_register', array( '\\Jetpack_Options', 'delete_option' ) ); + $secrets = ( new Secrets() )->generate( 'register', get_current_user_id(), 600 ); + + if ( false === $secrets ) { + return new WP_Error( 'cannot_save_secrets', __( 'Jetpack experienced an issue trying to save options (cannot_save_secrets). We suggest that you contact your hosting provider, and ask them for help checking that the options table is writable on your site.', 'jetpack-connection' ) ); + } + + if ( + empty( $secrets['secret_1'] ) || + empty( $secrets['secret_2'] ) || + empty( $secrets['exp'] ) + ) { + return new \WP_Error( 'missing_secrets' ); + } + + // Better to try (and fail) to set a higher timeout than this system + // supports than to have register fail for more users than it should. + $timeout = $this->set_min_time_limit( 60 ) / 2; + + $gmt_offset = get_option( 'gmt_offset' ); + if ( ! $gmt_offset ) { + $gmt_offset = 0; + } + + $stats_options = get_option( 'stats_options' ); + $stats_id = isset( $stats_options['blog_id'] ) + ? $stats_options['blog_id'] + : null; + + /* This action is documented in src/class-package-version-tracker.php */ + $package_versions = apply_filters( 'jetpack_package_versions', array() ); + + $active_plugins_using_connection = Plugin_Storage::get_all(); + + /** + * Filters the request body for additional property addition. + * + * @since 1.7.0 + * @since-jetpack 7.7.0 + * + * @param array $post_data request data. + * @param Array $token_data token data. + */ + $body = apply_filters( + 'jetpack_register_request_body', + array_merge( + array( + 'siteurl' => Urls::site_url(), + 'home' => Urls::home_url(), + 'gmt_offset' => $gmt_offset, + 'timezone_string' => (string) get_option( 'timezone_string' ), + 'site_name' => (string) get_option( 'blogname' ), + 'secret_1' => $secrets['secret_1'], + 'secret_2' => $secrets['secret_2'], + 'site_lang' => get_locale(), + 'timeout' => $timeout, + 'stats_id' => $stats_id, + 'state' => get_current_user_id(), + 'site_created' => $this->get_assumed_site_creation_date(), + 'jetpack_version' => Constants::get_constant( 'JETPACK__VERSION' ), + 'ABSPATH' => Constants::get_constant( 'ABSPATH' ), + 'current_user_email' => wp_get_current_user()->user_email, + 'connect_plugin' => $this->get_plugin() ? $this->get_plugin()->get_slug() : null, + 'package_versions' => $package_versions, + 'active_connected_plugins' => $active_plugins_using_connection, + ), + self::$extra_register_params + ) + ); + + $args = array( + 'method' => 'POST', + 'body' => $body, + 'headers' => array( + 'Accept' => 'application/json', + ), + 'timeout' => $timeout, + ); + + $args['body'] = static::apply_activation_source_to_args( $args['body'] ); + + // TODO: fix URLs for bad hosts. + $response = Client::_wp_remote_request( + $this->api_url( $api_endpoint ), + $args, + true + ); + + // Make sure the response is valid and does not contain any Jetpack errors. + $registration_details = $this->validate_remote_register_response( $response ); + + if ( is_wp_error( $registration_details ) ) { + return $registration_details; + } elseif ( ! $registration_details ) { + return new \WP_Error( + 'unknown_error', + 'Unknown error registering your Jetpack site.', + wp_remote_retrieve_response_code( $response ) + ); + } + + if ( empty( $registration_details->jetpack_secret ) || ! is_string( $registration_details->jetpack_secret ) ) { + return new \WP_Error( + 'jetpack_secret', + 'Unable to validate registration of your Jetpack site.', + wp_remote_retrieve_response_code( $response ) + ); + } + + if ( isset( $registration_details->jetpack_public ) ) { + $jetpack_public = (int) $registration_details->jetpack_public; + } else { + $jetpack_public = false; + } + + \Jetpack_Options::update_options( + array( + 'id' => (int) $registration_details->jetpack_id, + 'public' => $jetpack_public, + ) + ); + + update_option( Package_Version_Tracker::PACKAGE_VERSION_OPTION, $package_versions ); + + $this->get_tokens()->update_blog_token( (string) $registration_details->jetpack_secret ); + + $alternate_authorization_url = isset( $registration_details->alternate_authorization_url ) ? $registration_details->alternate_authorization_url : ''; + + add_filter( + 'jetpack_register_site_rest_response', + function ( $response ) use ( $alternate_authorization_url ) { + $response['alternateAuthorizeUrl'] = $alternate_authorization_url; + return $response; + } + ); + + /** + * Fires when a site is registered on WordPress.com. + * + * @since 1.7.0 + * @since-jetpack 3.7.0 + * + * @param int $json->jetpack_id Jetpack Blog ID. + * @param string $json->jetpack_secret Jetpack Blog Token. + * @param int|bool $jetpack_public Is the site public. + */ + do_action( + 'jetpack_site_registered', + $registration_details->jetpack_id, + $registration_details->jetpack_secret, + $jetpack_public + ); + + if ( isset( $registration_details->token ) ) { + /** + * Fires when a user token is sent along with the registration data. + * + * @since 1.7.0 + * @since-jetpack 7.6.0 + * + * @param object $token the administrator token for the newly registered site. + */ + do_action( 'jetpack_site_registered_user_token', $registration_details->token ); + } + + return true; + } + + /** + * Attempts Jetpack registration. + * + * @param bool $tos_agree Whether the user agreed to TOS. + * + * @return bool|WP_Error + */ + public function try_registration( $tos_agree = true ) { + if ( $tos_agree ) { + $terms_of_service = new Terms_Of_Service(); + $terms_of_service->agree(); + } + + /** + * Action fired when the user attempts the registration. + * + * @since 1.26.0 + */ + $pre_register = apply_filters( 'jetpack_pre_register', null ); + + if ( is_wp_error( $pre_register ) ) { + return $pre_register; + } + + $tracking_data = array(); + + if ( null !== $this->get_plugin() ) { + $tracking_data['plugin_slug'] = $this->get_plugin()->get_slug(); + } + + $tracking = new Tracking(); + $tracking->record_user_event( 'jpc_register_begin', $tracking_data ); + + add_filter( 'jetpack_register_request_body', array( Utils::class, 'filter_register_request_body' ) ); + + $result = $this->register(); + + remove_filter( 'jetpack_register_request_body', array( Utils::class, 'filter_register_request_body' ) ); + + // If there was an error with registration and the site was not registered, record this so we can show a message. + if ( ! $result || is_wp_error( $result ) ) { + return $result; + } + + return true; + } + + /** + * Adds a parameter to the register request body + * + * @since 1.26.0 + * + * @param string $name The name of the parameter to be added. + * @param string $value The value of the parameter to be added. + * + * @throws \InvalidArgumentException If supplied arguments are not strings. + * @return void + */ + public function add_register_request_param( $name, $value ) { + if ( ! is_string( $name ) || ! is_string( $value ) ) { + throw new \InvalidArgumentException( 'name and value must be strings' ); + } + self::$extra_register_params[ $name ] = $value; + } + + /** + * Takes the response from the Jetpack register new site endpoint and + * verifies it worked properly. + * + * @since 1.7.0 + * @since-jetpack 2.6.0 + * + * @param Mixed $response the response object, or the error object. + * @return string|WP_Error A JSON object on success or WP_Error on failures + **/ + protected function validate_remote_register_response( $response ) { + if ( is_wp_error( $response ) ) { + return new \WP_Error( + 'register_http_request_failed', + $response->get_error_message() + ); + } + + $code = wp_remote_retrieve_response_code( $response ); + $entity = wp_remote_retrieve_body( $response ); + + if ( $entity ) { + $registration_response = json_decode( $entity ); + } else { + $registration_response = false; + } + + $code_type = (int) ( $code / 100 ); + if ( 5 === $code_type ) { + return new \WP_Error( 'wpcom_5??', $code ); + } elseif ( 408 === $code ) { + return new \WP_Error( 'wpcom_408', $code ); + } elseif ( ! empty( $registration_response->error ) ) { + if ( + 'xml_rpc-32700' === $registration_response->error + && ! function_exists( 'xml_parser_create' ) + ) { + $error_description = __( "PHP's XML extension is not available. Jetpack requires the XML extension to communicate with WordPress.com. Please contact your hosting provider to enable PHP's XML extension.", 'jetpack-connection' ); + } else { + $error_description = isset( $registration_response->error_description ) + ? (string) $registration_response->error_description + : ''; + } + + return new \WP_Error( + (string) $registration_response->error, + $error_description, + $code + ); + } elseif ( 200 !== $code ) { + return new \WP_Error( 'wpcom_bad_response', $code ); + } + + // Jetpack ID error block. + if ( empty( $registration_response->jetpack_id ) ) { + return new \WP_Error( + 'jetpack_id', + /* translators: %s is an error message string */ + sprintf( __( 'Error Details: Jetpack ID is empty. Do not publicly post this error message! %s', 'jetpack-connection' ), $entity ), + $entity + ); + } elseif ( ! is_scalar( $registration_response->jetpack_id ) ) { + return new \WP_Error( + 'jetpack_id', + /* translators: %s is an error message string */ + sprintf( __( 'Error Details: Jetpack ID is not a scalar. Do not publicly post this error message! %s', 'jetpack-connection' ), $entity ), + $entity + ); + } elseif ( preg_match( '/[^0-9]/', $registration_response->jetpack_id ) ) { + return new \WP_Error( + 'jetpack_id', + /* translators: %s is an error message string */ + sprintf( __( 'Error Details: Jetpack ID begins with a numeral. Do not publicly post this error message! %s', 'jetpack-connection' ), $entity ), + $entity + ); + } + + return $registration_response; + } + + /** + * Adds a used nonce to a list of known nonces. + * + * @param int $timestamp the current request timestamp. + * @param string $nonce the nonce value. + * @return bool whether the nonce is unique or not. + * + * @deprecated since 1.24.0 + * @see Nonce_Handler::add() + */ + public function add_nonce( $timestamp, $nonce ) { + _deprecated_function( __METHOD__, '1.24.0', 'Automattic\\Jetpack\\Connection\\Nonce_Handler::add' ); + return ( new Nonce_Handler() )->add( $timestamp, $nonce ); + } + + /** + * Cleans nonces that were saved when calling ::add_nonce. + * + * @todo Properly prepare the query before executing it. + * + * @param bool $all whether to clean even non-expired nonces. + * + * @deprecated since 1.24.0 + * @see Nonce_Handler::clean_all() + */ + public function clean_nonces( $all = false ) { + _deprecated_function( __METHOD__, '1.24.0', 'Automattic\\Jetpack\\Connection\\Nonce_Handler::clean_all' ); + ( new Nonce_Handler() )->clean_all( $all ? PHP_INT_MAX : ( time() - Nonce_Handler::LIFETIME ) ); + } + + /** + * Sets the Connection custom capabilities. + * + * @param string[] $caps Array of the user's capabilities. + * @param string $cap Capability name. + * @param int $user_id The user ID. + * @param array $args Adds the context to the cap. Typically the object ID. + */ + public function jetpack_connection_custom_caps( $caps, $cap, $user_id, $args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + switch ( $cap ) { + case 'jetpack_connect': + case 'jetpack_reconnect': + $is_offline_mode = ( new Status() )->is_offline_mode(); + if ( $is_offline_mode ) { + $caps = array( 'do_not_allow' ); + break; + } + // Pass through. If it's not offline mode, these should match disconnect. + // Let users disconnect if it's offline mode, just in case things glitch. + case 'jetpack_disconnect': + /** + * Filters the jetpack_disconnect capability. + * + * @since 1.14.2 + * + * @param array An array containing the capability name. + */ + $caps = apply_filters( 'jetpack_disconnect_cap', array( 'manage_options' ) ); + break; + case 'jetpack_connect_user': + $is_offline_mode = ( new Status() )->is_offline_mode(); + if ( $is_offline_mode ) { + $caps = array( 'do_not_allow' ); + break; + } + // With site connections in mind, non-admin users can connect their account only if a connection owner exists. + $caps = $this->has_connected_owner() ? array( 'read' ) : array( 'manage_options' ); + break; + } + return $caps; + } + + /** + * Builds the timeout limit for queries talking with the wpcom servers. + * + * Based on local php max_execution_time in php.ini + * + * @since 1.7.0 + * @since-jetpack 5.4.0 + * @return int + **/ + public function get_max_execution_time() { + $timeout = (int) ini_get( 'max_execution_time' ); + + // Ensure exec time set in php.ini. + if ( ! $timeout ) { + $timeout = 30; + } + return $timeout; + } + + /** + * Sets a minimum request timeout, and returns the current timeout + * + * @since 1.7.0 + * @since-jetpack 5.4.0 + * @param Integer $min_timeout the minimum timeout value. + **/ + public function set_min_time_limit( $min_timeout ) { + $timeout = $this->get_max_execution_time(); + if ( $timeout < $min_timeout ) { + $timeout = $min_timeout; + set_time_limit( $timeout ); + } + return $timeout; + } + + /** + * Get our assumed site creation date. + * Calculated based on the earlier date of either: + * - Earliest admin user registration date. + * - Earliest date of post of any post type. + * + * @since 1.7.0 + * @since-jetpack 7.2.0 + * + * @return string Assumed site creation date and time. + */ + public function get_assumed_site_creation_date() { + $cached_date = get_transient( 'jetpack_assumed_site_creation_date' ); + if ( ! empty( $cached_date ) ) { + return $cached_date; + } + + $earliest_registered_users = get_users( + array( + 'role' => 'administrator', + 'orderby' => 'user_registered', + 'order' => 'ASC', + 'fields' => array( 'user_registered' ), + 'number' => 1, + ) + ); + $earliest_registration_date = $earliest_registered_users[0]->user_registered; + + $earliest_posts = get_posts( + array( + 'posts_per_page' => 1, + 'post_type' => 'any', + 'post_status' => 'any', + 'orderby' => 'date', + 'order' => 'ASC', + ) + ); + + // If there are no posts at all, we'll count only on user registration date. + if ( $earliest_posts ) { + $earliest_post_date = $earliest_posts[0]->post_date; + } else { + $earliest_post_date = PHP_INT_MAX; + } + + $assumed_date = min( $earliest_registration_date, $earliest_post_date ); + set_transient( 'jetpack_assumed_site_creation_date', $assumed_date ); + + return $assumed_date; + } + + /** + * Adds the activation source string as a parameter to passed arguments. + * + * @todo Refactor to use rawurlencode() instead of urlencode(). + * + * @param array $args arguments that need to have the source added. + * @return array $amended arguments. + */ + public static function apply_activation_source_to_args( $args ) { + list( $activation_source_name, $activation_source_keyword ) = get_option( 'jetpack_activation_source' ); + + if ( $activation_source_name ) { + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode + $args['_as'] = urlencode( $activation_source_name ); + } + + if ( $activation_source_keyword ) { + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode + $args['_ak'] = urlencode( $activation_source_keyword ); + } + + return $args; + } + + /** + * Generates two secret tokens and the end of life timestamp for them. + * + * @param String $action The action name. + * @param Integer $user_id The user identifier. + * @param Integer $exp Expiration time in seconds. + */ + public function generate_secrets( $action, $user_id = false, $exp = 600 ) { + return ( new Secrets() )->generate( $action, $user_id, $exp ); + } + + /** + * Returns two secret tokens and the end of life timestamp for them. + * + * @deprecated 1.24.0 Use Automattic\Jetpack\Connection\Secrets->get() instead. + * + * @param String $action The action name. + * @param Integer $user_id The user identifier. + * @return string|array an array of secrets or an error string. + */ + public function get_secrets( $action, $user_id ) { + _deprecated_function( __METHOD__, '1.24.0', 'Automattic\\Jetpack\\Connection\\Secrets->get' ); + return ( new Secrets() )->get( $action, $user_id ); + } + + /** + * Deletes secret tokens in case they, for example, have expired. + * + * @deprecated 1.24.0 Use Automattic\Jetpack\Connection\Secrets->delete() instead. + * + * @param String $action The action name. + * @param Integer $user_id The user identifier. + */ + public function delete_secrets( $action, $user_id ) { + _deprecated_function( __METHOD__, '1.24.0', 'Automattic\\Jetpack\\Connection\\Secrets->delete' ); + ( new Secrets() )->delete( $action, $user_id ); + } + + /** + * Deletes all connection tokens and transients from the local Jetpack site. + * If the plugin object has been provided in the constructor, the function first checks + * whether it's the only active connection. + * If there are any other connections, the function will do nothing and return `false` + * (unless `$ignore_connected_plugins` is set to `true`). + * + * @param bool $ignore_connected_plugins Delete the tokens even if there are other connected plugins. + * + * @return bool True if disconnected successfully, false otherwise. + */ + public function delete_all_connection_tokens( $ignore_connected_plugins = false ) { + // refuse to delete if we're not the last Jetpack plugin installed. + if ( ! $ignore_connected_plugins && null !== $this->plugin && ! $this->plugin->is_only() ) { + return false; + } + + /** + * Fires upon the disconnect attempt. + * Return `false` to prevent the disconnect. + * + * @since 1.14.2 + */ + if ( ! apply_filters( 'jetpack_connection_delete_all_tokens', true ) ) { + return false; + } + + \Jetpack_Options::delete_option( + array( + 'master_user', + 'time_diff', + 'fallback_no_verify_ssl_certs', + ) + ); + + ( new Secrets() )->delete_all(); + $this->get_tokens()->delete_all(); + + // Delete cached connected user data. + $transient_key = 'jetpack_connected_user_data_' . get_current_user_id(); + delete_transient( $transient_key ); + + // Delete all XML-RPC errors. + Error_Handler::get_instance()->delete_all_errors(); + + return true; + } + + /** + * Tells WordPress.com to disconnect the site and clear all tokens from cached site. + * If the plugin object has been provided in the constructor, the function first check + * whether it's the only active connection. + * If there are any other connections, the function will do nothing and return `false` + * (unless `$ignore_connected_plugins` is set to `true`). + * + * @param bool $ignore_connected_plugins Delete the tokens even if there are other connected plugins. + * + * @return bool True if disconnected successfully, false otherwise. + */ + public function disconnect_site_wpcom( $ignore_connected_plugins = false ) { + if ( ! $ignore_connected_plugins && null !== $this->plugin && ! $this->plugin->is_only() ) { + return false; + } + + if ( ( new Status() )->is_offline_mode() && ! apply_filters( 'jetpack_connection_disconnect_site_wpcom_offline_mode', false ) ) { + // Prevent potential disconnect of the live site by removing WPCOM tokens. + return false; + } + + /** + * Fires upon the disconnect attempt. + * Return `false` to prevent the disconnect. + * + * @since 1.14.2 + */ + if ( ! apply_filters( 'jetpack_connection_disconnect_site_wpcom', true, $this ) ) { + return false; + } + + $xml = new Jetpack_IXR_Client(); + $xml->query( 'jetpack.deregister', get_current_user_id() ); + + return true; + } + + /** + * Disconnect the plugin and remove the tokens. + * This function will automatically perform "soft" or "hard" disconnect depending on whether other plugins are using the connection. + * This is a proxy method to simplify the Connection package API. + * + * @see Manager::disconnect_site() + * + * @param boolean $disconnect_wpcom Should disconnect_site_wpcom be called. + * @param bool $ignore_connected_plugins Delete the tokens even if there are other connected plugins. + * @return bool + */ + public function remove_connection( $disconnect_wpcom = true, $ignore_connected_plugins = false ) { + + $this->disconnect_site( $disconnect_wpcom, $ignore_connected_plugins ); + + return true; + } + + /** + * Completely clearing up the connection, and initiating reconnect. + * + * @return true|WP_Error True if reconnected successfully, a `WP_Error` object otherwise. + */ + public function reconnect() { + ( new Tracking() )->record_user_event( 'restore_connection_reconnect' ); + + $this->disconnect_site_wpcom( true ); + + return $this->register(); + } + + /** + * Validate the tokens, and refresh the invalid ones. + * + * @return string|bool|WP_Error True if connection restored or string indicating what's to be done next. A `WP_Error` object or false otherwise. + */ + public function restore() { + // If this is a site connection we need to trigger a full reconnection as our only secure means of + // communication with WPCOM, aka the blog token, is compromised. + if ( $this->is_site_connection() ) { + return $this->reconnect(); + } + + $validate_tokens_response = $this->get_tokens()->validate(); + + // If token validation failed, trigger a full reconnection. + if ( is_array( $validate_tokens_response ) && + isset( $validate_tokens_response['blog_token']['is_healthy'] ) && + isset( $validate_tokens_response['user_token']['is_healthy'] ) ) { + $blog_token_healthy = $validate_tokens_response['blog_token']['is_healthy']; + $user_token_healthy = $validate_tokens_response['user_token']['is_healthy']; + } else { + $blog_token_healthy = false; + $user_token_healthy = false; + } + + // Tokens are both valid, or both invalid. We can't fix the problem we don't see, so the full reconnection is needed. + if ( $blog_token_healthy === $user_token_healthy ) { + $result = $this->reconnect(); + return ( true === $result ) ? 'authorize' : $result; + } + + if ( ! $blog_token_healthy ) { + return $this->refresh_blog_token(); + } + + if ( ! $user_token_healthy ) { + return ( true === $this->refresh_user_token() ) ? 'authorize' : false; + } + + return false; + } + + /** + * Responds to a WordPress.com call to register the current site. + * Should be changed to protected. + * + * @param array $registration_data Array of [ secret_1, user_id ]. + */ + public function handle_registration( array $registration_data ) { + list( $registration_secret_1, $registration_user_id ) = $registration_data; + if ( empty( $registration_user_id ) ) { + return new \WP_Error( 'registration_state_invalid', __( 'Invalid Registration State', 'jetpack-connection' ), 400 ); + } + + return ( new Secrets() )->verify( 'register', $registration_secret_1, (int) $registration_user_id ); + } + + /** + * Perform the API request to validate the blog and user tokens. + * + * @deprecated 1.24.0 Use Automattic\Jetpack\Connection\Tokens->validate_tokens() instead. + * + * @param int|null $user_id ID of the user we need to validate token for. Current user's ID by default. + * + * @return array|false|WP_Error The API response: `array( 'blog_token_is_healthy' => true|false, 'user_token_is_healthy' => true|false )`. + */ + public function validate_tokens( $user_id = null ) { + _deprecated_function( __METHOD__, '1.24.0', 'Automattic\\Jetpack\\Connection\\Tokens->validate' ); + return $this->get_tokens()->validate( $user_id ); + } + + /** + * Verify a Previously Generated Secret. + * + * @deprecated 1.24.0 Use Automattic\Jetpack\Connection\Secrets->verify() instead. + * + * @param string $action The type of secret to verify. + * @param string $secret_1 The secret string to compare to what is stored. + * @param int $user_id The user ID of the owner of the secret. + * @return \WP_Error|string WP_Error on failure, secret_2 on success. + */ + public function verify_secrets( $action, $secret_1, $user_id ) { + _deprecated_function( __METHOD__, '1.24.0', 'Automattic\\Jetpack\\Connection\\Secrets->verify' ); + return ( new Secrets() )->verify( $action, $secret_1, $user_id ); + } + + /** + * Responds to a WordPress.com call to authorize the current user. + * Should be changed to protected. + */ + public function handle_authorization() { + } + + /** + * Obtains the auth token. + * + * @param array $data The request data. + * @return object|\WP_Error Returns the auth token on success. + * Returns a \WP_Error on failure. + */ + public function get_token( $data ) { + return $this->get_tokens()->get( $data, $this->api_url( 'token' ) ); + } + + /** + * Builds a URL to the Jetpack connection auth page. + * + * @param WP_User $user (optional) defaults to the current logged in user. + * @param String $redirect (optional) a redirect URL to use instead of the default. + * @return string Connect URL. + */ + public function get_authorization_url( $user = null, $redirect = null ) { + if ( empty( $user ) ) { + $user = wp_get_current_user(); + } + + $roles = new Roles(); + $role = $roles->translate_user_to_role( $user ); + $signed_role = $this->get_tokens()->sign_role( $role ); + + /** + * Filter the URL of the first time the user gets redirected back to your site for connection + * data processing. + * + * @since 1.7.0 + * @since-jetpack 8.0.0 + * + * @param string $redirect_url Defaults to the site admin URL. + */ + $processing_url = apply_filters( 'jetpack_connect_processing_url', admin_url( 'admin.php' ) ); + + /** + * Filter the URL to redirect the user back to when the authorization process + * is complete. + * + * @since 1.7.0 + * @since-jetpack 8.0.0 + * + * @param string $redirect_url Defaults to the site URL. + */ + $redirect = apply_filters( 'jetpack_connect_redirect_url', $redirect ); + + $secrets = ( new Secrets() )->generate( 'authorize', $user->ID, 2 * HOUR_IN_SECONDS ); + + /** + * Filter the type of authorization. + * 'calypso' completes authorization on wordpress.com/jetpack/connect + * while 'jetpack' ( or any other value ) completes the authorization at jetpack.wordpress.com. + * + * @since 1.7.0 + * @since-jetpack 4.3.3 + * + * @param string $auth_type Defaults to 'calypso', can also be 'jetpack'. + */ + $auth_type = apply_filters( 'jetpack_auth_type', 'calypso' ); + + /** + * Filters the user connection request data for additional property addition. + * + * @since 1.7.0 + * @since-jetpack 8.0.0 + * + * @param array $request_data request data. + */ + $body = apply_filters( + 'jetpack_connect_request_body', + array( + 'response_type' => 'code', + 'client_id' => \Jetpack_Options::get_option( 'id' ), + 'redirect_uri' => add_query_arg( + array( + 'handler' => 'jetpack-connection-webhooks', + 'action' => 'authorize', + '_wpnonce' => wp_create_nonce( "jetpack-authorize_{$role}_{$redirect}" ), + 'redirect' => $redirect ? rawurlencode( $redirect ) : false, + ), + esc_url( $processing_url ) + ), + 'state' => $user->ID, + 'scope' => $signed_role, + 'user_email' => $user->user_email, + 'user_login' => $user->user_login, + 'is_active' => $this->has_connected_owner(), // TODO Deprecate this. + 'jp_version' => (string) Constants::get_constant( 'JETPACK__VERSION' ), + 'auth_type' => $auth_type, + 'secret' => $secrets['secret_1'], + 'blogname' => get_option( 'blogname' ), + 'site_url' => Urls::site_url(), + 'home_url' => Urls::home_url(), + 'site_icon' => get_site_icon_url(), + 'site_lang' => get_locale(), + 'site_created' => $this->get_assumed_site_creation_date(), + 'allow_site_connection' => ! $this->has_connected_owner(), + 'calypso_env' => ( new Host() )->get_calypso_env(), + ) + ); + + $body = static::apply_activation_source_to_args( urlencode_deep( $body ) ); + + $api_url = $this->api_url( 'authorize' ); + + return add_query_arg( $body, $api_url ); + } + + /** + * Authorizes the user by obtaining and storing the user token. + * + * @param array $data The request data. + * @return string|\WP_Error Returns a string on success. + * Returns a \WP_Error on failure. + */ + public function authorize( $data = array() ) { + /** + * Action fired when user authorization starts. + * + * @since 1.7.0 + * @since-jetpack 8.0.0 + */ + do_action( 'jetpack_authorize_starting' ); + + $roles = new Roles(); + $role = $roles->translate_current_user_to_role(); + + if ( ! $role ) { + return new \WP_Error( 'no_role', 'Invalid request.', 400 ); + } + + $cap = $roles->translate_role_to_cap( $role ); + if ( ! $cap ) { + return new \WP_Error( 'no_cap', 'Invalid request.', 400 ); + } + + if ( ! empty( $data['error'] ) ) { + return new \WP_Error( $data['error'], 'Error included in the request.', 400 ); + } + + if ( ! isset( $data['state'] ) ) { + return new \WP_Error( 'no_state', 'Request must include state.', 400 ); + } + + if ( ! ctype_digit( $data['state'] ) ) { + return new \WP_Error( $data['error'], 'State must be an integer.', 400 ); + } + + $current_user_id = get_current_user_id(); + if ( $current_user_id !== (int) $data['state'] ) { + return new \WP_Error( 'wrong_state', 'State does not match current user.', 400 ); + } + + if ( empty( $data['code'] ) ) { + return new \WP_Error( 'no_code', 'Request must include an authorization code.', 400 ); + } + + $token = $this->get_tokens()->get( $data, $this->api_url( 'token' ) ); + + if ( is_wp_error( $token ) ) { + $code = $token->get_error_code(); + if ( empty( $code ) ) { + $code = 'invalid_token'; + } + return new \WP_Error( $code, $token->get_error_message(), 400 ); + } + + if ( ! $token ) { + return new \WP_Error( 'no_token', 'Error generating token.', 400 ); + } + + $is_connection_owner = ! $this->has_connected_owner(); + + $this->get_tokens()->update_user_token( $current_user_id, sprintf( '%s.%d', $token, $current_user_id ), $is_connection_owner ); + + /** + * Fires after user has successfully received an auth token. + * + * @since 1.7.0 + * @since-jetpack 3.9.0 + */ + do_action( 'jetpack_user_authorized' ); + + if ( ! $is_connection_owner ) { + /** + * Action fired when a secondary user has been authorized. + * + * @since 1.7.0 + * @since-jetpack 8.0.0 + */ + do_action( 'jetpack_authorize_ending_linked' ); + return 'linked'; + } + + /** + * Action fired when the master user has been authorized. + * + * @since 1.7.0 + * @since-jetpack 8.0.0 + * + * @param array $data The request data. + */ + do_action( 'jetpack_authorize_ending_authorized', $data ); + + \Jetpack_Options::delete_raw_option( 'jetpack_last_connect_url_check' ); + + ( new Nonce_Handler() )->reschedule(); + + return 'authorized'; + } + + /** + * Disconnects from the Jetpack servers. + * Forgets all connection details and tells the Jetpack servers to do the same. + * + * @param boolean $disconnect_wpcom Should disconnect_site_wpcom be called. + * @param bool $ignore_connected_plugins Delete the tokens even if there are other connected plugins. + */ + public function disconnect_site( $disconnect_wpcom = true, $ignore_connected_plugins = true ) { + if ( ! $ignore_connected_plugins && null !== $this->plugin && ! $this->plugin->is_only() ) { + return false; + } + + wp_clear_scheduled_hook( 'jetpack_clean_nonces' ); + + ( new Nonce_Handler() )->clean_all(); + + /** + * Fires when a site is disconnected. + * + * @since 1.36.3 + */ + do_action( 'jetpack_site_before_disconnected' ); + + // If the site is in an IDC because sync is not allowed, + // let's make sure to not disconnect the production site. + if ( $disconnect_wpcom ) { + $tracking = new Tracking(); + $tracking->record_user_event( 'disconnect_site', array() ); + + $this->disconnect_site_wpcom( $ignore_connected_plugins ); + } + + $this->delete_all_connection_tokens( $ignore_connected_plugins ); + + // Remove tracked package versions, since they depend on the Jetpack Connection. + delete_option( Package_Version_Tracker::PACKAGE_VERSION_OPTION ); + + $jetpack_unique_connection = \Jetpack_Options::get_option( 'unique_connection' ); + if ( $jetpack_unique_connection ) { + // Check then record unique disconnection if site has never been disconnected previously. + if ( - 1 === $jetpack_unique_connection['disconnected'] ) { + $jetpack_unique_connection['disconnected'] = 1; + } else { + if ( 0 === $jetpack_unique_connection['disconnected'] ) { + $a8c_mc_stats_instance = new A8c_Mc_Stats(); + $a8c_mc_stats_instance->add( 'connections', 'unique-disconnect' ); + $a8c_mc_stats_instance->do_server_side_stats(); + } + // increment number of times disconnected. + $jetpack_unique_connection['disconnected'] += 1; + } + + \Jetpack_Options::update_option( 'unique_connection', $jetpack_unique_connection ); + } + + /** + * Fires when a site is disconnected. + * + * @since 1.30.1 + */ + do_action( 'jetpack_site_disconnected' ); + } + + /** + * The Base64 Encoding of the SHA1 Hash of the Input. + * + * @param string $text The string to hash. + * @return string + */ + public function sha1_base64( $text ) { + return base64_encode( sha1( $text, true ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode + } + + /** + * This function mirrors Jetpack_Data::is_usable_domain() in the WPCOM codebase. + * + * @param string $domain The domain to check. + * + * @return bool|WP_Error + */ + public function is_usable_domain( $domain ) { + + // If it's empty, just fail out. + if ( ! $domain ) { + return new \WP_Error( + 'fail_domain_empty', + /* translators: %1$s is a domain name. */ + sprintf( __( 'Domain `%1$s` just failed is_usable_domain check as it is empty.', 'jetpack-connection' ), $domain ) + ); + } + + /** + * Skips the usuable domain check when connecting a site. + * + * Allows site administrators with domains that fail gethostname-based checks to pass the request to WP.com + * + * @since 1.7.0 + * @since-jetpack 4.1.0 + * + * @param bool If the check should be skipped. Default false. + */ + if ( apply_filters( 'jetpack_skip_usuable_domain_check', false ) ) { + return true; + } + + // None of the explicit localhosts. + $forbidden_domains = array( + 'wordpress.com', + 'localhost', + 'localhost.localdomain', + 'local.wordpress.test', // VVV pattern. + 'local.wordpress-trunk.test', // VVV pattern. + 'src.wordpress-develop.test', // VVV pattern. + 'build.wordpress-develop.test', // VVV pattern. + ); + if ( in_array( $domain, $forbidden_domains, true ) ) { + return new \WP_Error( + 'fail_domain_forbidden', + sprintf( + /* translators: %1$s is a domain name. */ + __( + 'Domain `%1$s` just failed is_usable_domain check as it is in the forbidden array.', + 'jetpack-connection' + ), + $domain + ) + ); + } + + // No .test or .local domains. + if ( preg_match( '#\.(test|local)$#i', $domain ) ) { + return new \WP_Error( + 'fail_domain_tld', + sprintf( + /* translators: %1$s is a domain name. */ + __( + 'Domain `%1$s` just failed is_usable_domain check as it uses an invalid top level domain.', + 'jetpack-connection' + ), + $domain + ) + ); + } + + // No WPCOM subdomains. + if ( preg_match( '#\.WordPress\.com$#i', $domain ) ) { + return new \WP_Error( + 'fail_subdomain_wpcom', + sprintf( + /* translators: %1$s is a domain name. */ + __( + 'Domain `%1$s` just failed is_usable_domain check as it is a subdomain of WordPress.com.', + 'jetpack-connection' + ), + $domain + ) + ); + } + + // If PHP was compiled without support for the Filter module (very edge case). + if ( ! function_exists( 'filter_var' ) ) { + // Just pass back true for now, and let wpcom sort it out. + return true; + } + + $domain = preg_replace( '#^https?://#', '', untrailingslashit( $domain ) ); + + if ( filter_var( $domain, FILTER_VALIDATE_IP ) + && ! filter_var( $domain, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) + ) { + return new \WP_Error( + 'fail_ip_forbidden', + sprintf( + /* translators: %1$s is a domain name. */ + __( + 'IP address `%1$s` just failed is_usable_domain check as it is in the private network.', + 'jetpack-connection' + ), + $domain + ) + ); + } + + return true; + } + + /** + * Gets the requested token. + * + * @deprecated 1.24.0 Use Automattic\Jetpack\Connection\Tokens->get_access_token() instead. + * + * @param int|false $user_id false: Return the Blog Token. int: Return that user's User Token. + * @param string|false $token_key If provided, check that the token matches the provided input. + * @param bool|true $suppress_errors If true, return a falsy value when the token isn't found; When false, return a descriptive WP_Error when the token isn't found. + * + * @return object|false + * + * @see $this->get_tokens()->get_access_token() + */ + public function get_access_token( $user_id = false, $token_key = false, $suppress_errors = true ) { + _deprecated_function( __METHOD__, '1.24.0', 'Automattic\\Jetpack\\Connection\\Tokens->get_access_token' ); + return $this->get_tokens()->get_access_token( $user_id, $token_key, $suppress_errors ); + } + + /** + * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths + * since it is passed by reference to various methods. + * Capture it here so we can verify the signature later. + * + * @param array $methods an array of available XMLRPC methods. + * @return array the same array, since this method doesn't add or remove anything. + */ + public function xmlrpc_methods( $methods ) { + $this->raw_post_data = isset( $GLOBALS['HTTP_RAW_POST_DATA'] ) ? $GLOBALS['HTTP_RAW_POST_DATA'] : null; + return $methods; + } + + /** + * Resets the raw post data parameter for testing purposes. + */ + public function reset_raw_post_data() { + $this->raw_post_data = null; + } + + /** + * Registering an additional method. + * + * @param array $methods an array of available XMLRPC methods. + * @return array the amended array in case the method is added. + */ + public function public_xmlrpc_methods( $methods ) { + if ( array_key_exists( 'wp.getOptions', $methods ) ) { + $methods['wp.getOptions'] = array( $this, 'jetpack_get_options' ); + } + return $methods; + } + + /** + * Handles a getOptions XMLRPC method call. + * + * @param array $args method call arguments. + * @return an amended XMLRPC server options array. + */ + public function jetpack_get_options( $args ) { + global $wp_xmlrpc_server; + + $wp_xmlrpc_server->escape( $args ); + + $username = $args[1]; + $password = $args[2]; + + $user = $wp_xmlrpc_server->login( $username, $password ); + if ( ! $user ) { + return $wp_xmlrpc_server->error; + } + + $options = array(); + $user_data = $this->get_connected_user_data(); + if ( is_array( $user_data ) ) { + $options['jetpack_user_id'] = array( + 'desc' => __( 'The WP.com user ID of the connected user', 'jetpack-connection' ), + 'readonly' => true, + 'value' => $user_data['ID'], + ); + $options['jetpack_user_login'] = array( + 'desc' => __( 'The WP.com username of the connected user', 'jetpack-connection' ), + 'readonly' => true, + 'value' => $user_data['login'], + ); + $options['jetpack_user_email'] = array( + 'desc' => __( 'The WP.com user email of the connected user', 'jetpack-connection' ), + 'readonly' => true, + 'value' => $user_data['email'], + ); + $options['jetpack_user_site_count'] = array( + 'desc' => __( 'The number of sites of the connected WP.com user', 'jetpack-connection' ), + 'readonly' => true, + 'value' => $user_data['site_count'], + ); + } + $wp_xmlrpc_server->blog_options = array_merge( $wp_xmlrpc_server->blog_options, $options ); + $args = stripslashes_deep( $args ); + return $wp_xmlrpc_server->wp_getOptions( $args ); + } + + /** + * Adds Jetpack-specific options to the output of the XMLRPC options method. + * + * @param array $options standard Core options. + * @return array amended options. + */ + public function xmlrpc_options( $options ) { + $jetpack_client_id = false; + if ( $this->is_connected() ) { + $jetpack_client_id = \Jetpack_Options::get_option( 'id' ); + } + $options['jetpack_version'] = array( + 'desc' => __( 'Jetpack Plugin Version', 'jetpack-connection' ), + 'readonly' => true, + 'value' => Constants::get_constant( 'JETPACK__VERSION' ), + ); + + $options['jetpack_client_id'] = array( + 'desc' => __( 'The Client ID/WP.com Blog ID of this site', 'jetpack-connection' ), + 'readonly' => true, + 'value' => $jetpack_client_id, + ); + return $options; + } + + /** + * Resets the saved authentication state in between testing requests. + */ + public function reset_saved_auth_state() { + $this->xmlrpc_verification = null; + } + + /** + * Sign a user role with the master access token. + * If not specified, will default to the current user. + * + * @access public + * + * @param string $role User role. + * @param int $user_id ID of the user. + * @return string Signed user role. + */ + public function sign_role( $role, $user_id = null ) { + return $this->get_tokens()->sign_role( $role, $user_id ); + } + + /** + * Set the plugin instance. + * + * @param Plugin $plugin_instance The plugin instance. + * + * @return $this + */ + public function set_plugin_instance( Plugin $plugin_instance ) { + $this->plugin = $plugin_instance; + + return $this; + } + + /** + * Retrieve the plugin management object. + * + * @return Plugin|null + */ + public function get_plugin() { + return $this->plugin; + } + + /** + * Get all connected plugins information, excluding those disconnected by user. + * WARNING: the method cannot be called until Plugin_Storage::configure is called, which happens on plugins_loaded + * Even if you don't use Jetpack Config, it may be introduced later by other plugins, + * so please make sure not to run the method too early in the code. + * + * @return array|WP_Error + */ + public function get_connected_plugins() { + $maybe_plugins = Plugin_Storage::get_all(); + + if ( $maybe_plugins instanceof WP_Error ) { + return $maybe_plugins; + } + + return $maybe_plugins; + } + + /** + * Force plugin disconnect. After its called, the plugin will not be allowed to use the connection. + * Note: this method does not remove any access tokens. + * + * @deprecated since 1.39.0 + * @return bool + */ + public function disable_plugin() { + return null; + } + + /** + * Force plugin reconnect after user-initiated disconnect. + * After its called, the plugin will be allowed to use the connection again. + * Note: this method does not initialize access tokens. + * + * @deprecated since 1.39.0. + * @return bool + */ + public function enable_plugin() { + return null; + } + + /** + * Whether the plugin is allowed to use the connection, or it's been disconnected by user. + * If no plugin slug was passed into the constructor, always returns true. + * + * @deprecated 1.42.0 This method no longer has a purpose after the removal of the soft disconnect feature. + * + * @return bool + */ + public function is_plugin_enabled() { + return true; + } + + /** + * Perform the API request to refresh the blog token. + * Note that we are making this request on behalf of the Jetpack master user, + * given they were (most probably) the ones that registered the site at the first place. + * + * @return WP_Error|bool The result of updating the blog_token option. + */ + public function refresh_blog_token() { + ( new Tracking() )->record_user_event( 'restore_connection_refresh_blog_token' ); + + $blog_id = \Jetpack_Options::get_option( 'id' ); + if ( ! $blog_id ) { + return new WP_Error( 'site_not_registered', 'Site not registered.' ); + } + + $url = sprintf( + '%s/%s/v%s/%s', + Constants::get_constant( 'JETPACK__WPCOM_JSON_API_BASE' ), + 'wpcom', + '2', + 'sites/' . $blog_id . '/jetpack-refresh-blog-token' + ); + $method = 'POST'; + $user_id = get_current_user_id(); + + $response = Client::remote_request( compact( 'url', 'method', 'user_id' ) ); + + if ( is_wp_error( $response ) ) { + return new WP_Error( 'refresh_blog_token_http_request_failed', $response->get_error_message() ); + } + + $code = wp_remote_retrieve_response_code( $response ); + $entity = wp_remote_retrieve_body( $response ); + + if ( $entity ) { + $json = json_decode( $entity ); + } else { + $json = false; + } + + if ( 200 !== $code ) { + if ( empty( $json->code ) ) { + return new WP_Error( 'unknown', '', $code ); + } + + /* translators: Error description string. */ + $error_description = isset( $json->message ) ? sprintf( __( 'Error Details: %s', 'jetpack-connection' ), (string) $json->message ) : ''; + + return new WP_Error( (string) $json->code, $error_description, $code ); + } + + if ( empty( $json->jetpack_secret ) || ! is_scalar( $json->jetpack_secret ) ) { + return new WP_Error( 'jetpack_secret', '', $code ); + } + + Error_Handler::get_instance()->delete_all_errors(); + + return $this->get_tokens()->update_blog_token( (string) $json->jetpack_secret ); + } + + /** + * Disconnect the user from WP.com, and initiate the reconnect process. + * + * @return bool + */ + public function refresh_user_token() { + ( new Tracking() )->record_user_event( 'restore_connection_refresh_user_token' ); + $this->disconnect_user( null, true, true ); + return true; + } + + /** + * Fetches a signed token. + * + * @deprecated 1.24.0 Use Automattic\Jetpack\Connection\Tokens->get_signed_token() instead. + * + * @param object $token the token. + * @return WP_Error|string a signed token + */ + public function get_signed_token( $token ) { + _deprecated_function( __METHOD__, '1.24.0', 'Automattic\\Jetpack\\Connection\\Tokens->get_signed_token' ); + return $this->get_tokens()->get_signed_token( $token ); + } + + /** + * If the site-level connection is active, add the list of plugins using connection to the heartbeat (except Jetpack itself) + * + * @param array $stats The Heartbeat stats array. + * @return array $stats + */ + public function add_stats_to_heartbeat( $stats ) { + + if ( ! $this->is_connected() ) { + return $stats; + } + + $active_plugins_using_connection = Plugin_Storage::get_all(); + foreach ( array_keys( $active_plugins_using_connection ) as $plugin_slug ) { + if ( 'jetpack' !== $plugin_slug ) { + $stats_group = isset( $active_plugins_using_connection['jetpack'] ) ? 'combined-connection' : 'standalone-connection'; + $stats[ $stats_group ][] = $plugin_slug; + } + } + return $stats; + } + + /** + * Get the WPCOM or self-hosted site ID. + * + * @return int|WP_Error + */ + public static function get_site_id() { + $is_wpcom = ( defined( 'IS_WPCOM' ) && IS_WPCOM ); + $site_id = $is_wpcom ? get_current_blog_id() : \Jetpack_Options::get_option( 'id' ); + if ( ! $site_id ) { + return new \WP_Error( + 'unavailable_site_id', + __( 'Sorry, something is wrong with your Jetpack connection.', 'jetpack-connection' ), + 403 + ); + } + return (int) $site_id; + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-nonce-handler.php b/vendor/automattic/jetpack-connection/src/class-nonce-handler.php new file mode 100644 index 00000000000..48e14a15b8a --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-nonce-handler.php @@ -0,0 +1,212 @@ +db = $wpdb; + } + + /** + * Scheduling the WP-cron cleanup event. + */ + public function init_schedule() { + add_action( 'jetpack_clean_nonces', array( __CLASS__, 'clean_scheduled' ) ); + if ( ! wp_next_scheduled( 'jetpack_clean_nonces' ) ) { + wp_schedule_event( time(), 'hourly', 'jetpack_clean_nonces' ); + } + } + + /** + * Reschedule the WP-cron cleanup event to make it start sooner. + */ + public function reschedule() { + wp_clear_scheduled_hook( 'jetpack_clean_nonces' ); + wp_schedule_event( time(), 'hourly', 'jetpack_clean_nonces' ); + } + + /** + * Adds a used nonce to a list of known nonces. + * + * @param int $timestamp the current request timestamp. + * @param string $nonce the nonce value. + * + * @return bool whether the nonce is unique or not. + */ + public function add( $timestamp, $nonce ) { + if ( isset( static::$nonces_used_this_request[ "$timestamp:$nonce" ] ) ) { + return static::$nonces_used_this_request[ "$timestamp:$nonce" ]; + } + + // This should always have gone through Jetpack_Signature::sign_request() first to check $timestamp and $nonce. + $timestamp = (int) $timestamp; + $nonce = esc_sql( $nonce ); + + // Raw query so we can avoid races: add_option will also update. + $show_errors = $this->db->hide_errors(); + + // Running `try...finally` to make sure that we re-enable errors in case of an exception. + try { + $old_nonce = $this->db->get_row( + $this->db->prepare( "SELECT 1 FROM `{$this->db->options}` WHERE option_name = %s", "jetpack_nonce_{$timestamp}_{$nonce}" ) + ); + + if ( $old_nonce === null ) { + $return = (bool) $this->db->query( + $this->db->prepare( + "INSERT INTO `{$this->db->options}` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s)", + "jetpack_nonce_{$timestamp}_{$nonce}", + time(), + 'no' + ) + ); + } else { + $return = false; + } + } finally { + $this->db->show_errors( $show_errors ); + } + + static::$nonces_used_this_request[ "$timestamp:$nonce" ] = $return; + + return $return; + } + + /** + * Removing all existing nonces, or at least as many as possible. + * Capped at 20 seconds to avoid breaking the site. + * + * @param int $cutoff_timestamp All nonces added before this timestamp will be removed. + * @param int $time_limit How long the cleanup can run (in seconds). + * + * @return true + */ + public function clean_all( $cutoff_timestamp = PHP_INT_MAX, $time_limit = 20 ) { + // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed + for ( $end_time = time() + $time_limit; time() < $end_time; ) { + $result = $this->delete( static::CLEAN_ALL_LIMIT_PER_BATCH, $cutoff_timestamp ); + + if ( ! $result ) { + break; + } + } + + return true; + } + + /** + * Scheduled clean up of the expired nonces. + */ + public static function clean_scheduled() { + /** + * Adjust the time limit for the scheduled cleanup. + * + * @since 9.5.0 + * + * @param int $time_limit How long the cleanup can run (in seconds). + */ + $time_limit = apply_filters( 'jetpack_connection_nonce_cleanup_runtime_limit', static::SCHEDULED_CLEANUP_TIME_LIMIT ); + + ( new static() )->clean_all( time() - static::LIFETIME, $time_limit ); + } + + /** + * Delete the nonces. + * + * @param int $limit How many nonces to delete. + * @param null|int $cutoff_timestamp All nonces added before this timestamp will be removed. + * + * @return int|false Number of removed nonces, or `false` if nothing to remove (or in case of a database error). + */ + public function delete( $limit = 10, $cutoff_timestamp = null ) { + global $wpdb; + + $ids = $wpdb->get_col( + $wpdb->prepare( + "SELECT option_id FROM `{$wpdb->options}`" + . " WHERE `option_name` >= 'jetpack_nonce_' AND `option_name` < %s" + . ' LIMIT %d', + 'jetpack_nonce_' . $cutoff_timestamp, + $limit + ) + ); + + if ( ! is_array( $ids ) ) { + // There's an error and we can't proceed. + return false; + } + + // Removing zeroes in case AUTO_INCREMENT of the options table is broken, and all ID's are zeroes. + $ids = array_filter( $ids ); + + if ( array() === $ids ) { + // There's nothing to remove. + return false; + } + + $ids_fill = implode( ', ', array_fill( 0, count( $ids ), '%d' ) ); + + $args = $ids; + $args[] = 'jetpack_nonce_%'; + + // The Code Sniffer is unable to understand what's going on... + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber + return $wpdb->query( $wpdb->prepare( "DELETE FROM `{$wpdb->options}` WHERE `option_id` IN ( {$ids_fill} ) AND option_name LIKE %s", $args ) ); + } + + /** + * Clean the cached nonces valid during the current request, therefore making them invalid. + * + * @return bool + */ + public static function invalidate_request_nonces() { + static::$nonces_used_this_request = array(); + + return true; + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-package-version-tracker.php b/vendor/automattic/jetpack-connection/src/class-package-version-tracker.php new file mode 100644 index 00000000000..697f67230eb --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-package-version-tracker.php @@ -0,0 +1,111 @@ + $version ) { + if ( ! is_string( $package ) || ! is_string( $version ) ) { + unset( $filter_versions[ $package ] ); + } + } + + if ( ! is_array( $option_versions ) + || count( array_diff_assoc( $filter_versions, $option_versions ) ) + || count( array_diff_assoc( $option_versions, $filter_versions ) ) + ) { + $this->update_package_versions_option( $filter_versions ); + } + } + + /** + * Updates the package versions: + * - Sends the updated package versions to wpcom. + * - Updates the 'jetpack_package_versions' option. + * + * @param array $package_versions The package versions. + */ + protected function update_package_versions_option( $package_versions ) { + $connection = new Manager(); + if ( ! $connection->is_connected() ) { + return; + } + + $site_id = \Jetpack_Options::get_option( 'id' ); + + $last_failed_attempt_within_hour = get_transient( self::CACHED_FAILED_REQUEST_KEY ); + + if ( $last_failed_attempt_within_hour ) { + return; + } + + $body = wp_json_encode( + array( + 'package_versions' => $package_versions, + ) + ); + + $response = Client::wpcom_json_api_request_as_blog( + sprintf( '/sites/%d/jetpack-package-versions', $site_id ), + '2', + array( + 'headers' => array( 'content-type' => 'application/json' ), + 'method' => 'POST', + ), + $body, + 'wpcom' + ); + + if ( 200 === wp_remote_retrieve_response_code( $response ) ) { + update_option( self::PACKAGE_VERSION_OPTION, $package_versions ); + } else { + set_transient( self::CACHED_FAILED_REQUEST_KEY, time(), self::CACHED_FAILED_REQUEST_EXPIRATION ); + } + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-package-version.php b/vendor/automattic/jetpack-connection/src/class-package-version.php new file mode 100644 index 00000000000..8dcde61af76 --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-package-version.php @@ -0,0 +1,30 @@ +is_connected() ) { + return; + } + + $site_id = \Jetpack_Options::get_option( 'id' ); + + $body = wp_json_encode( + array( + 'active_connected_plugins' => self::$plugins, + ) + ); + + Client::wpcom_json_api_request_as_blog( + sprintf( '/sites/%d/jetpack-active-connected-plugins', $site_id ), + '2', + array( + 'headers' => array( 'content-type' => 'application/json' ), + 'method' => 'POST', + ), + $body, + 'wpcom' + ); + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-plugin.php b/vendor/automattic/jetpack-connection/src/class-plugin.php new file mode 100644 index 00000000000..10b5c7b9a68 --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-plugin.php @@ -0,0 +1,122 @@ +slug = $slug; + } + + /** + * Get the plugin slug. + * + * @return string + */ + public function get_slug() { + return $this->slug; + } + + /** + * Add the plugin connection info into Jetpack. + * + * @param string $name Plugin name, required. + * @param array $args Plugin arguments, optional. + * + * @return $this + * @see $this->arguments_whitelist + */ + public function add( $name, array $args = array() ) { + $args = compact( 'name' ) + array_intersect_key( $args, array_flip( $this->arguments_whitelist ) ); + + Plugin_Storage::upsert( $this->slug, $args ); + + return $this; + } + + /** + * Remove the plugin connection info from Jetpack. + * + * @return $this + */ + public function remove() { + Plugin_Storage::delete( $this->slug ); + + return $this; + } + + /** + * Determine if this plugin connection is the only one active at the moment, if any. + * + * @return bool + */ + public function is_only() { + $plugins = Plugin_Storage::get_all(); + + return ! $plugins || ( array_key_exists( $this->slug, $plugins ) && 1 === count( $plugins ) ); + } + + /** + * Add the plugin to the set of disconnected ones. + * + * @deprecated since 1.39.0. + * + * @return bool + */ + public function disable() { + return true; + } + + /** + * Remove the plugin from the set of disconnected ones. + * + * @deprecated since 1.39.0. + * + * @return bool + */ + public function enable() { + return true; + } + + /** + * Whether this plugin is allowed to use the connection. + * + * @deprecated since 11.0 + * @return bool + */ + public function is_enabled() { + return true; + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-rest-authentication.php b/vendor/automattic/jetpack-connection/src/class-rest-authentication.php new file mode 100644 index 00000000000..c5a89f53638 --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-rest-authentication.php @@ -0,0 +1,220 @@ +connection_manager = new Manager(); + } + + /** + * Controls the single instance of this class. + * + * @static + */ + public static function init() { + if ( ! self::$instance ) { + self::$instance = new self(); + + add_filter( 'determine_current_user', array( self::$instance, 'wp_rest_authenticate' ) ); + add_filter( 'rest_authentication_errors', array( self::$instance, 'wp_rest_authentication_errors' ) ); + } + + return self::$instance; + } + + /** + * Authenticates requests from Jetpack server to WP REST API endpoints. + * Uses the existing XMLRPC request signing implementation. + * + * @param int|bool $user User ID if one has been determined, false otherwise. + * + * @return int|null The user id or null if the request was authenticated via blog token, or not authenticated at all. + */ + public function wp_rest_authenticate( $user ) { + if ( $this->doing_determine_current_user_filter ) { + return $user; + } + + $this->doing_determine_current_user_filter = true; + + try { + if ( ! empty( $user ) ) { + // Another authentication method is in effect. + return $user; + } + + add_filter( + 'jetpack_constant_default_value', + __NAMESPACE__ . '\Utils::jetpack_api_constant_filter', + 10, + 2 + ); + + // phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( ! isset( $_GET['_for'] ) || 'jetpack' !== $_GET['_for'] ) { + // Nothing to do for this authentication method. + return null; + } + + // phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( ! isset( $_GET['token'] ) && ! isset( $_GET['signature'] ) ) { + // Nothing to do for this authentication method. + return null; + } + + if ( ! isset( $_SERVER['REQUEST_METHOD'] ) ) { + $this->rest_authentication_status = new \WP_Error( + 'rest_invalid_request', + __( 'The request method is missing.', 'jetpack-connection' ), + array( 'status' => 400 ) + ); + return null; + } + + // Only support specific request parameters that have been tested and + // are known to work with signature verification. A different method + // can be passed to the WP REST API via the '?_method=' parameter if + // needed. + if ( 'GET' !== $_SERVER['REQUEST_METHOD'] && 'POST' !== $_SERVER['REQUEST_METHOD'] ) { + $this->rest_authentication_status = new \WP_Error( + 'rest_invalid_request', + __( 'This request method is not supported.', 'jetpack-connection' ), + array( 'status' => 400 ) + ); + return null; + } + if ( 'POST' !== $_SERVER['REQUEST_METHOD'] && ! empty( file_get_contents( 'php://input' ) ) ) { + $this->rest_authentication_status = new \WP_Error( + 'rest_invalid_request', + __( 'This request method does not support body parameters.', 'jetpack-connection' ), + array( 'status' => 400 ) + ); + return null; + } + + $verified = $this->connection_manager->verify_xml_rpc_signature(); + + if ( + $verified && + isset( $verified['type'] ) && + 'blog' === $verified['type'] + ) { + // Site-level authentication successful. + $this->rest_authentication_status = true; + $this->rest_authentication_type = 'blog'; + return null; + } + + if ( + $verified && + isset( $verified['type'] ) && + 'user' === $verified['type'] && + ! empty( $verified['user_id'] ) + ) { + // User-level authentication successful. + $this->rest_authentication_status = true; + $this->rest_authentication_type = 'user'; + return $verified['user_id']; + } + + // Something else went wrong. Probably a signature error. + $this->rest_authentication_status = new \WP_Error( + 'rest_invalid_signature', + __( 'The request is not signed correctly.', 'jetpack-connection' ), + array( 'status' => 400 ) + ); + return null; + } finally { + $this->doing_determine_current_user_filter = false; + } + } + + /** + * Report authentication status to the WP REST API. + * + * @param WP_Error|mixed $value Error from another authentication handler, null if we should handle it, or another value if not. + * @return WP_Error|boolean|null {@see WP_JSON_Server::check_authentication} + */ + public function wp_rest_authentication_errors( $value ) { + if ( null !== $value ) { + return $value; + } + return $this->rest_authentication_status; + } + + /** + * Resets the saved authentication state in between testing requests. + */ + public function reset_saved_auth_state() { + $this->rest_authentication_status = null; + $this->connection_manager->reset_saved_auth_state(); + } + + /** + * Whether the request was signed with a blog token. + * + * @since 1.29.0 + * + * @return bool True if the request was signed with a valid blog token, false otherwise. + */ + public static function is_signed_with_blog_token() { + $instance = self::init(); + + return true === $instance->rest_authentication_status && 'blog' === $instance->rest_authentication_type; + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-rest-connector.php b/vendor/automattic/jetpack-connection/src/class-rest-connector.php new file mode 100644 index 00000000000..5b04eb934b6 --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-rest-connector.php @@ -0,0 +1,850 @@ +connection = $connection; + + self::$user_permissions_error_msg = esc_html__( + 'You do not have the correct user permissions to perform this action. + Please contact your site admin if you think this is a mistake.', + 'jetpack-connection' + ); + + $jp_version = Constants::get_constant( 'JETPACK__VERSION' ); + + if ( ! $this->connection->has_connected_owner() ) { + // Register a site. + register_rest_route( + 'jetpack/v4', + '/verify_registration', + array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => array( $this, 'verify_registration' ), + 'permission_callback' => '__return_true', + ) + ); + } + + // Authorize a remote user. + register_rest_route( + 'jetpack/v4', + '/remote_authorize', + array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => __CLASS__ . '::remote_authorize', + 'permission_callback' => '__return_true', + ) + ); + + // Get current connection status of Jetpack. + register_rest_route( + 'jetpack/v4', + '/connection', + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => __CLASS__ . '::connection_status', + 'permission_callback' => '__return_true', + ) + ); + + // Disconnect site. + register_rest_route( + 'jetpack/v4', + '/connection', + array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => __CLASS__ . '::disconnect_site', + 'permission_callback' => __CLASS__ . '::disconnect_site_permission_check', + 'args' => array( + 'isActive' => array( + 'description' => __( 'Set to false will trigger the site to disconnect.', 'jetpack-connection' ), + 'validate_callback' => function ( $value ) { + if ( false !== $value ) { + return new WP_Error( + 'rest_invalid_param', + __( 'The isActive argument should be set to false.', 'jetpack-connection' ), + array( 'status' => 400 ) + ); + } + + return true; + }, + 'required' => true, + ), + ), + ) + ); + + // We are only registering this route if Jetpack-the-plugin is not active or it's version is ge 10.0-alpha. + // The reason for doing so is to avoid conflicts between the Connection package and + // older versions of Jetpack, registering the same route twice. + if ( empty( $jp_version ) || version_compare( $jp_version, '10.0-alpha', '>=' ) ) { + // Get current user connection data. + register_rest_route( + 'jetpack/v4', + '/connection/data', + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => __CLASS__ . '::get_user_connection_data', + 'permission_callback' => __CLASS__ . '::user_connection_data_permission_check', + ) + ); + } + + // Get list of plugins that use the Jetpack connection. + register_rest_route( + 'jetpack/v4', + '/connection/plugins', + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( __CLASS__, 'get_connection_plugins' ), + 'permission_callback' => __CLASS__ . '::connection_plugins_permission_check', + ) + ); + + // Full or partial reconnect in case of connection issues. + register_rest_route( + 'jetpack/v4', + '/connection/reconnect', + array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => array( $this, 'connection_reconnect' ), + 'permission_callback' => __CLASS__ . '::jetpack_reconnect_permission_check', + ) + ); + + // Register the site (get `blog_token`). + register_rest_route( + 'jetpack/v4', + '/connection/register', + array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => array( $this, 'connection_register' ), + 'permission_callback' => __CLASS__ . '::jetpack_register_permission_check', + 'args' => array( + 'from' => array( + 'description' => __( 'Indicates where the registration action was triggered for tracking/segmentation purposes', 'jetpack-connection' ), + 'type' => 'string', + ), + 'registration_nonce' => array( + 'description' => __( 'The registration nonce', 'jetpack-connection' ), + 'type' => 'string', + 'required' => true, + ), + 'redirect_uri' => array( + 'description' => __( 'URI of the admin page where the user should be redirected after connection flow', 'jetpack-connection' ), + 'type' => 'string', + ), + 'plugin_slug' => array( + 'description' => __( 'Indicates from what plugin the request is coming from', 'jetpack-connection' ), + 'type' => 'string', + ), + ), + ) + ); + + // Get authorization URL. + register_rest_route( + 'jetpack/v4', + '/connection/authorize_url', + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'connection_authorize_url' ), + 'permission_callback' => __CLASS__ . '::user_connection_data_permission_check', + 'args' => array( + 'redirect_uri' => array( + 'description' => __( 'URI of the admin page where the user should be redirected after connection flow', 'jetpack-connection' ), + 'type' => 'string', + ), + ), + ) + ); + + register_rest_route( + 'jetpack/v4', + '/user-token', + array( + array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => array( static::class, 'update_user_token' ), + 'permission_callback' => array( static::class, 'update_user_token_permission_check' ), + 'args' => array( + 'user_token' => array( + 'description' => __( 'New user token', 'jetpack-connection' ), + 'type' => 'string', + 'required' => true, + ), + 'is_connection_owner' => array( + 'description' => __( 'Is connection owner', 'jetpack-connection' ), + 'type' => 'boolean', + ), + ), + ), + ) + ); + + // Set the connection owner. + register_rest_route( + 'jetpack/v4', + '/connection/owner', + array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => array( static::class, 'set_connection_owner' ), + 'permission_callback' => array( static::class, 'set_connection_owner_permission_check' ), + 'args' => array( + 'owner' => array( + 'description' => __( 'New owner', 'jetpack-connection' ), + 'type' => 'integer', + 'required' => true, + ), + ), + ) + ); + } + + /** + * Handles verification that a site is registered. + * + * @since 1.7.0 + * @since-jetpack 5.4.0 + * + * @param WP_REST_Request $request The request sent to the WP REST API. + * + * @return string|WP_Error + */ + public function verify_registration( WP_REST_Request $request ) { + $registration_data = array( $request['secret_1'], $request['state'] ); + + return $this->connection->handle_registration( $registration_data ); + } + + /** + * Handles verification that a site is registered + * + * @since 1.7.0 + * @since-jetpack 5.4.0 + * + * @param WP_REST_Request $request The request sent to the WP REST API. + * + * @return array|wp-error + */ + public static function remote_authorize( $request ) { + $xmlrpc_server = new Jetpack_XMLRPC_Server(); + $result = $xmlrpc_server->remote_authorize( $request ); + + if ( is_a( $result, 'IXR_Error' ) ) { + $result = new WP_Error( $result->code, $result->message ); + } + + return $result; + } + + /** + * Get connection status for this Jetpack site. + * + * @since 1.7.0 + * @since-jetpack 4.3.0 + * + * @param bool $rest_response Should we return a rest response or a simple array. Default to rest response. + * + * @return WP_REST_Response|array Connection information. + */ + public static function connection_status( $rest_response = true ) { + $status = new Status(); + $connection = new Manager(); + + $connection_status = array( + 'isActive' => $connection->has_connected_owner(), // TODO deprecate this. + 'isStaging' => $status->is_staging_site(), + 'isRegistered' => $connection->is_connected(), + 'isUserConnected' => $connection->is_user_connected(), + 'hasConnectedOwner' => $connection->has_connected_owner(), + 'offlineMode' => array( + 'isActive' => $status->is_offline_mode(), + 'constant' => defined( 'JETPACK_DEV_DEBUG' ) && JETPACK_DEV_DEBUG, + 'url' => $status->is_local_site(), + /** This filter is documented in packages/status/src/class-status.php */ + 'filter' => ( apply_filters( 'jetpack_development_mode', false ) || apply_filters( 'jetpack_offline_mode', false ) ), // jetpack_development_mode is deprecated. + 'wpLocalConstant' => defined( 'WP_LOCAL_DEV' ) && WP_LOCAL_DEV, + ), + 'isPublic' => '1' == get_option( 'blog_public' ), // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual + ); + + /** + * Filters the connection status data. + * + * @since 1.25.0 + * + * @param array An array containing the connection status data. + */ + $connection_status = apply_filters( 'jetpack_connection_status', $connection_status ); + + if ( $rest_response ) { + return rest_ensure_response( + $connection_status + ); + } else { + return $connection_status; + } + } + + /** + * Get plugins connected to the Jetpack. + * + * @param bool $rest_response Should we return a rest response or a simple array. Default to rest response. + * + * @since 1.13.1 + * @since 1.38.0 Added $rest_response param. + * + * @return WP_REST_Response|WP_Error Response or error object, depending on the request result. + */ + public static function get_connection_plugins( $rest_response = true ) { + $plugins = ( new Manager() )->get_connected_plugins(); + + if ( is_wp_error( $plugins ) ) { + return $plugins; + } + + array_walk( + $plugins, + function ( &$data, $slug ) { + $data['slug'] = $slug; + } + ); + + if ( $rest_response ) { + return rest_ensure_response( array_values( $plugins ) ); + } + + return array_values( $plugins ); + } + + /** + * Verify that user can view Jetpack admin page and can activate plugins. + * + * @since 1.15.0 + * + * @return bool|WP_Error Whether user has the capability 'activate_plugins'. + */ + public static function activate_plugins_permission_check() { + if ( current_user_can( 'activate_plugins' ) ) { + return true; + } + + return new WP_Error( 'invalid_user_permission_activate_plugins', self::get_user_permissions_error_msg(), array( 'status' => rest_authorization_required_code() ) ); + } + + /** + * Permission check for the connection_plugins endpoint + * + * @return bool|WP_Error + */ + public static function connection_plugins_permission_check() { + if ( true === static::activate_plugins_permission_check() ) { + return true; + } + + if ( true === static::is_request_signed_by_jetpack_debugger() ) { + return true; + } + + return new WP_Error( 'invalid_user_permission_activate_plugins', self::get_user_permissions_error_msg(), array( 'status' => rest_authorization_required_code() ) ); + } + + /** + * Permission check for the disconnect site endpoint. + * + * @since 1.30.1 + * + * @return bool|WP_Error True if user is able to disconnect the site. + */ + public static function disconnect_site_permission_check() { + if ( current_user_can( 'jetpack_disconnect' ) ) { + return true; + } + + return new WP_Error( + 'invalid_user_permission_jetpack_disconnect', + self::get_user_permissions_error_msg(), + array( 'status' => rest_authorization_required_code() ) + ); + } + + /** + * Get miscellaneous user data related to the connection. Similar data available in old "My Jetpack". + * Information about the master/primary user. + * Information about the current user. + * + * @param bool $rest_response Should we return a rest response or a simple array. Default to rest response. + * + * @since 1.30.1 + * + * @return \WP_REST_Response|array + */ + public static function get_user_connection_data( $rest_response = true ) { + $blog_id = \Jetpack_Options::get_option( 'id' ); + + $connection = new Manager(); + + $current_user = wp_get_current_user(); + $connection_owner = $connection->get_connection_owner(); + + $owner_display_name = false === $connection_owner ? null : $connection_owner->display_name; + + $is_user_connected = $connection->is_user_connected(); + $is_master_user = false === $connection_owner ? false : ( $current_user->ID === $connection_owner->ID ); + $wpcom_user_data = $connection->get_connected_user_data(); + + // Add connected user gravatar to the returned wpcom_user_data. + // Probably we shouldn't do this when $wpcom_user_data is false, but we have been since 2016 so + // clients probably expect that by now. + if ( false === $wpcom_user_data ) { + $wpcom_user_data = array(); + } + $wpcom_user_data['avatar'] = ( ! empty( $wpcom_user_data['email'] ) ? + get_avatar_url( + $wpcom_user_data['email'], + array( + 'size' => 64, + 'default' => 'mysteryman', + ) + ) + : false ); + + $current_user_connection_data = array( + 'isConnected' => $is_user_connected, + 'isMaster' => $is_master_user, + 'username' => $current_user->user_login, + 'id' => $current_user->ID, + 'blogId' => $blog_id, + 'wpcomUser' => $wpcom_user_data, + 'gravatar' => get_avatar_url( $current_user->ID, 64, 'mm', '', array( 'force_display' => true ) ), + 'permissions' => array( + 'connect' => current_user_can( 'jetpack_connect' ), + 'connect_user' => current_user_can( 'jetpack_connect_user' ), + 'disconnect' => current_user_can( 'jetpack_disconnect' ), + ), + ); + + /** + * Filters the current user connection data. + * + * @since 1.30.1 + * + * @param array An array containing the current user connection data. + */ + $current_user_connection_data = apply_filters( 'jetpack_current_user_connection_data', $current_user_connection_data ); + + $response = array( + 'currentUser' => $current_user_connection_data, + 'connectionOwner' => $owner_display_name, + ); + + if ( $rest_response ) { + return rest_ensure_response( $response ); + } + + return $response; + } + + /** + * Permission check for the connection/data endpoint + * + * @return bool|WP_Error + */ + public static function user_connection_data_permission_check() { + if ( current_user_can( 'jetpack_connect_user' ) ) { + return true; + } + + return new WP_Error( + 'invalid_user_permission_user_connection_data', + self::get_user_permissions_error_msg(), + array( 'status' => rest_authorization_required_code() ) + ); + } + + /** + * Verifies if the request was signed with the Jetpack Debugger key + * + * @param string|null $pub_key The public key used to verify the signature. Default is the Jetpack Debugger key. This is used for testing purposes. + * + * @return bool + */ + public static function is_request_signed_by_jetpack_debugger( $pub_key = null ) { + // phpcs:disable WordPress.Security.NonceVerification.Recommended + if ( ! isset( $_GET['signature'] ) || ! isset( $_GET['timestamp'] ) || ! isset( $_GET['url'] ) || ! isset( $_GET['rest_route'] ) ) { + return false; + } + + // signature timestamp must be within 5min of current time. + if ( abs( time() - (int) $_GET['timestamp'] ) > 300 ) { + return false; + } + + $signature = base64_decode( filter_var( wp_unslash( $_GET['signature'] ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode + + $signature_data = wp_json_encode( + array( + 'rest_route' => filter_var( wp_unslash( $_GET['rest_route'] ) ), + 'timestamp' => (int) $_GET['timestamp'], + 'url' => filter_var( wp_unslash( $_GET['url'] ) ), + ) + ); + + if ( + ! function_exists( 'openssl_verify' ) + || 1 !== openssl_verify( + $signature_data, + $signature, + $pub_key ? $pub_key : static::JETPACK__DEBUGGER_PUBLIC_KEY + ) + ) { + return false; + } + + // phpcs:enable WordPress.Security.NonceVerification.Recommended + + return true; + } + + /** + * Verify that user is allowed to disconnect Jetpack. + * + * @since 1.15.0 + * + * @return bool|WP_Error Whether user has the capability 'jetpack_disconnect'. + */ + public static function jetpack_reconnect_permission_check() { + if ( current_user_can( 'jetpack_reconnect' ) ) { + return true; + } + + return new WP_Error( 'invalid_user_permission_jetpack_disconnect', self::get_user_permissions_error_msg(), array( 'status' => rest_authorization_required_code() ) ); + } + + /** + * Returns generic error message when user is not allowed to perform an action. + * + * @return string The error message. + */ + public static function get_user_permissions_error_msg() { + return self::$user_permissions_error_msg; + } + + /** + * The endpoint tried to partially or fully reconnect the website to WP.com. + * + * @since 1.15.0 + * + * @return \WP_REST_Response|WP_Error + */ + public function connection_reconnect() { + $response = array(); + + $next = null; + + $result = $this->connection->restore(); + + if ( is_wp_error( $result ) ) { + $response = $result; + } elseif ( is_string( $result ) ) { + $next = $result; + } else { + $next = true === $result ? 'completed' : 'failed'; + } + + switch ( $next ) { + case 'authorize': + $response['status'] = 'in_progress'; + $response['authorizeUrl'] = $this->connection->get_authorization_url(); + break; + case 'completed': + $response['status'] = 'completed'; + /** + * Action fired when reconnection has completed successfully. + * + * @since 1.18.1 + */ + do_action( 'jetpack_reconnection_completed' ); + break; + case 'failed': + $response = new WP_Error( 'Reconnect failed' ); + break; + } + + return rest_ensure_response( $response ); + } + + /** + * Verify that user is allowed to connect Jetpack. + * + * @since 1.26.0 + * + * @return bool|WP_Error Whether user has the capability 'jetpack_connect'. + */ + public static function jetpack_register_permission_check() { + if ( current_user_can( 'jetpack_connect' ) ) { + return true; + } + + return new WP_Error( 'invalid_user_permission_jetpack_connect', self::get_user_permissions_error_msg(), array( 'status' => rest_authorization_required_code() ) ); + } + + /** + * The endpoint tried to partially or fully reconnect the website to WP.com. + * + * @since 1.7.0 + * @since-jetpack 7.7.0 + * + * @param \WP_REST_Request $request The request sent to the WP REST API. + * + * @return \WP_REST_Response|WP_Error + */ + public function connection_register( $request ) { + if ( ! wp_verify_nonce( $request->get_param( 'registration_nonce' ), 'jetpack-registration-nonce' ) ) { + return new WP_Error( 'invalid_nonce', __( 'Unable to verify your request.', 'jetpack-connection' ), array( 'status' => 403 ) ); + } + + if ( isset( $request['from'] ) ) { + $this->connection->add_register_request_param( 'from', (string) $request['from'] ); + } + + if ( ! empty( $request['plugin_slug'] ) ) { + // If `plugin_slug` matches a plugin using the connection, let's inform the plugin that is establishing the connection. + $connected_plugin = Plugin_Storage::get_one( (string) $request['plugin_slug'] ); + if ( ! is_wp_error( $connected_plugin ) && ! empty( $connected_plugin ) ) { + $this->connection->set_plugin_instance( new Plugin( (string) $request['plugin_slug'] ) ); + } + } + + $result = $this->connection->try_registration(); + + if ( is_wp_error( $result ) ) { + return $result; + } + + $redirect_uri = $request->get_param( 'redirect_uri' ) ? admin_url( $request->get_param( 'redirect_uri' ) ) : null; + + if ( class_exists( 'Jetpack' ) ) { + $authorize_url = \Jetpack::build_authorize_url( $redirect_uri ); + } else { + $authorize_url = $this->connection->get_authorization_url( null, $redirect_uri ); + } + + /** + * Filters the response of jetpack/v4/connection/register endpoint + * + * @param array $response Array response + * @since 1.27.0 + */ + $response_body = apply_filters( + 'jetpack_register_site_rest_response', + array() + ); + + // We manipulate the alternate URLs after the filter is applied, so they can not be overwritten. + $response_body['authorizeUrl'] = $authorize_url; + if ( ! empty( $response_body['alternateAuthorizeUrl'] ) ) { + $response_body['alternateAuthorizeUrl'] = Redirect::get_url( $response_body['alternateAuthorizeUrl'] ); + } + + return rest_ensure_response( $response_body ); + } + + /** + * Get the authorization URL. + * + * @since 1.27.0 + * + * @param \WP_REST_Request $request The request sent to the WP REST API. + * + * @return \WP_REST_Response|WP_Error + */ + public function connection_authorize_url( $request ) { + $redirect_uri = $request->get_param( 'redirect_uri' ) ? admin_url( $request->get_param( 'redirect_uri' ) ) : null; + $authorize_url = $this->connection->get_authorization_url( null, $redirect_uri ); + + return rest_ensure_response( + array( + 'authorizeUrl' => $authorize_url, + ) + ); + } + + /** + * The endpoint tried to partially or fully reconnect the website to WP.com. + * + * @since 1.29.0 + * + * @param \WP_REST_Request $request The request sent to the WP REST API. + * + * @return \WP_REST_Response|WP_Error + */ + public static function update_user_token( $request ) { + $token_parts = explode( '.', $request['user_token'] ); + + if ( count( $token_parts ) !== 3 || ! (int) $token_parts[2] || ! ctype_digit( $token_parts[2] ) ) { + return new WP_Error( 'invalid_argument_user_token', esc_html__( 'Invalid user token is provided', 'jetpack-connection' ) ); + } + + $user_id = (int) $token_parts[2]; + + if ( false === get_userdata( $user_id ) ) { + return new WP_Error( 'invalid_argument_user_id', esc_html__( 'Invalid user id is provided', 'jetpack-connection' ) ); + } + + $connection = new Manager(); + + if ( ! $connection->is_connected() ) { + return new WP_Error( 'site_not_connected', esc_html__( 'Site is not connected', 'jetpack-connection' ) ); + } + + $is_connection_owner = isset( $request['is_connection_owner'] ) + ? (bool) $request['is_connection_owner'] + : ( new Manager() )->get_connection_owner_id() === $user_id; + + ( new Tokens() )->update_user_token( $user_id, $request['user_token'], $is_connection_owner ); + + /** + * Fires when the user token gets successfully replaced. + * + * @since 1.29.0 + * + * @param int $user_id User ID. + * @param string $token New user token. + */ + do_action( 'jetpack_updated_user_token', $user_id, $request['user_token'] ); + + return rest_ensure_response( + array( + 'success' => true, + ) + ); + } + + /** + * Disconnects Jetpack from the WordPress.com Servers + * + * @since 1.30.1 + * + * @return bool|WP_Error True if Jetpack successfully disconnected. + */ + public static function disconnect_site() { + $connection = new Manager(); + + if ( $connection->is_connected() ) { + $connection->disconnect_site(); + return rest_ensure_response( array( 'code' => 'success' ) ); + } + + return new WP_Error( + 'disconnect_failed', + esc_html__( 'Failed to disconnect the site as it appears already disconnected.', 'jetpack-connection' ), + array( 'status' => 400 ) + ); + } + + /** + * Verify that the API client is allowed to replace user token. + * + * @since 1.29.0 + * + * @return bool|WP_Error. + */ + public static function update_user_token_permission_check() { + return Rest_Authentication::is_signed_with_blog_token() + ? true + : new WP_Error( 'invalid_permission_update_user_token', self::get_user_permissions_error_msg(), array( 'status' => rest_authorization_required_code() ) ); + } + + /** + * Change the connection owner. + * + * @since 1.29.0 + * + * @param WP_REST_Request $request The request sent to the WP REST API. + * + * @return \WP_REST_Response|WP_Error + */ + public static function set_connection_owner( $request ) { + $new_owner_id = $request['owner']; + + $owner_set = ( new Manager() )->update_connection_owner( $new_owner_id ); + + if ( is_wp_error( $owner_set ) ) { + return $owner_set; + } + + return rest_ensure_response( + array( + 'code' => 'success', + ) + ); + } + + /** + * Check that user has permission to change the master user. + * + * @since 1.7.0 + * @since-jetpack 6.2.0 + * @since-jetpack 7.7.0 Update so that any user with jetpack_disconnect privs can set owner. + * + * @return bool|WP_Error True if user is able to change master user. + */ + public static function set_connection_owner_permission_check() { + if ( current_user_can( 'jetpack_disconnect' ) ) { + return true; + } + + return new WP_Error( 'invalid_user_permission_set_connection_owner', self::get_user_permissions_error_msg(), array( 'status' => rest_authorization_required_code() ) ); + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-secrets.php b/vendor/automattic/jetpack-connection/src/class-secrets.php new file mode 100644 index 00000000000..81e725006d4 --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-secrets.php @@ -0,0 +1,281 @@ + time() + ) { + return $secrets[ $secret_name ]; + } + + $secret_value = array( + 'secret_1' => call_user_func( $callable ), + 'secret_2' => call_user_func( $callable ), + 'exp' => time() + $exp, + ); + + $secrets[ $secret_name ] = $secret_value; + + $res = Jetpack_Options::update_raw_option( self::LEGACY_SECRETS_OPTION_NAME, $secrets ); + return $res ? $secrets[ $secret_name ] : false; + } + + /** + * Returns two secret tokens and the end of life timestamp for them. + * + * @param String $action The action name. + * @param Integer $user_id The user identifier. + * @return string|array an array of secrets or an error string. + */ + public function get( $action, $user_id ) { + $secret_name = 'jetpack_' . $action . '_' . $user_id; + $secrets = Jetpack_Options::get_raw_option( + self::LEGACY_SECRETS_OPTION_NAME, + array() + ); + + if ( ! isset( $secrets[ $secret_name ] ) ) { + return self::SECRETS_MISSING; + } + + if ( $secrets[ $secret_name ]['exp'] < time() ) { + $this->delete( $action, $user_id ); + return self::SECRETS_EXPIRED; + } + + return $secrets[ $secret_name ]; + } + + /** + * Deletes secret tokens in case they, for example, have expired. + * + * @param String $action The action name. + * @param Integer $user_id The user identifier. + */ + public function delete( $action, $user_id ) { + $secret_name = 'jetpack_' . $action . '_' . $user_id; + $secrets = Jetpack_Options::get_raw_option( + self::LEGACY_SECRETS_OPTION_NAME, + array() + ); + if ( isset( $secrets[ $secret_name ] ) ) { + unset( $secrets[ $secret_name ] ); + Jetpack_Options::update_raw_option( self::LEGACY_SECRETS_OPTION_NAME, $secrets ); + } + } + + /** + * Verify a Previously Generated Secret. + * + * @param string $action The type of secret to verify. + * @param string $secret_1 The secret string to compare to what is stored. + * @param int $user_id The user ID of the owner of the secret. + * @return WP_Error|string WP_Error on failure, secret_2 on success. + */ + public function verify( $action, $secret_1, $user_id ) { + $allowed_actions = array( 'register', 'authorize', 'publicize' ); + if ( ! in_array( $action, $allowed_actions, true ) ) { + return new WP_Error( 'unknown_verification_action', 'Unknown Verification Action', 400 ); + } + + $user = get_user_by( 'id', $user_id ); + + /** + * We've begun verifying the previously generated secret. + * + * @since 1.7.0 + * @since-jetpack 7.5.0 + * + * @param string $action The type of secret to verify. + * @param \WP_User $user The user object. + */ + do_action( 'jetpack_verify_secrets_begin', $action, $user ); + + $return_error = function ( WP_Error $error ) use ( $action, $user ) { + /** + * Verifying of the previously generated secret has failed. + * + * @since 1.7.0 + * @since-jetpack 7.5.0 + * + * @param string $action The type of secret to verify. + * @param \WP_User $user The user object. + * @param WP_Error $error The error object. + */ + do_action( 'jetpack_verify_secrets_fail', $action, $user, $error ); + + return $error; + }; + + $stored_secrets = $this->get( $action, $user_id ); + $this->delete( $action, $user_id ); + + $error = null; + if ( empty( $secret_1 ) ) { + $error = $return_error( + new WP_Error( + 'verify_secret_1_missing', + /* translators: "%s" is the name of a paramter. It can be either "secret_1" or "state". */ + sprintf( __( 'The required "%s" parameter is missing.', 'jetpack-connection' ), 'secret_1' ), + 400 + ) + ); + } elseif ( ! is_string( $secret_1 ) ) { + $error = $return_error( + new WP_Error( + 'verify_secret_1_malformed', + /* translators: "%s" is the name of a paramter. It can be either "secret_1" or "state". */ + sprintf( __( 'The required "%s" parameter is malformed.', 'jetpack-connection' ), 'secret_1' ), + 400 + ) + ); + } elseif ( empty( $user_id ) ) { + // $user_id is passed around during registration as "state". + $error = $return_error( + new WP_Error( + 'state_missing', + /* translators: "%s" is the name of a paramter. It can be either "secret_1" or "state". */ + sprintf( __( 'The required "%s" parameter is missing.', 'jetpack-connection' ), 'state' ), + 400 + ) + ); + } elseif ( ! ctype_digit( (string) $user_id ) ) { + $error = $return_error( + new WP_Error( + 'state_malformed', + /* translators: "%s" is the name of a paramter. It can be either "secret_1" or "state". */ + sprintf( __( 'The required "%s" parameter is malformed.', 'jetpack-connection' ), 'state' ), + 400 + ) + ); + } elseif ( self::SECRETS_MISSING === $stored_secrets ) { + $error = $return_error( + new WP_Error( + 'verify_secrets_missing', + __( 'Verification secrets not found', 'jetpack-connection' ), + 400 + ) + ); + } elseif ( self::SECRETS_EXPIRED === $stored_secrets ) { + $error = $return_error( + new WP_Error( + 'verify_secrets_expired', + __( 'Verification took too long', 'jetpack-connection' ), + 400 + ) + ); + } elseif ( ! $stored_secrets ) { + $error = $return_error( + new WP_Error( + 'verify_secrets_empty', + __( 'Verification secrets are empty', 'jetpack-connection' ), + 400 + ) + ); + } elseif ( is_wp_error( $stored_secrets ) ) { + $stored_secrets->add_data( 400 ); + $error = $return_error( $stored_secrets ); + } elseif ( empty( $stored_secrets['secret_1'] ) || empty( $stored_secrets['secret_2'] ) || empty( $stored_secrets['exp'] ) ) { + $error = $return_error( + new WP_Error( + 'verify_secrets_incomplete', + __( 'Verification secrets are incomplete', 'jetpack-connection' ), + 400 + ) + ); + } elseif ( ! hash_equals( $secret_1, $stored_secrets['secret_1'] ) ) { + $error = $return_error( + new WP_Error( + 'verify_secrets_mismatch', + __( 'Secret mismatch', 'jetpack-connection' ), + 400 + ) + ); + } + + // Something went wrong during the checks, returning the error. + if ( ! empty( $error ) ) { + return $error; + } + + /** + * We've succeeded at verifying the previously generated secret. + * + * @since 1.7.0 + * @since-jetpack 7.5.0 + * + * @param string $action The type of secret to verify. + * @param \WP_User $user The user object. + */ + do_action( 'jetpack_verify_secrets_success', $action, $user ); + + return $stored_secrets['secret_2']; + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-server-sandbox.php b/vendor/automattic/jetpack-connection/src/class-server-sandbox.php new file mode 100644 index 00000000000..711480bbc92 --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-server-sandbox.php @@ -0,0 +1,243 @@ + new URL, 'host' => new Host, 'new_signature => New signature if url was changed ] + */ + public function server_sandbox_request_parameters( $sandbox, $url, $headers, $data = null, $method = 'GET' ) { + $host = ''; + $new_signature = ''; + + if ( ! is_string( $sandbox ) || ! is_string( $url ) ) { + return array( + 'url' => $url, + 'host' => $host, + 'new_signature' => $new_signature, + ); + } + + $url_host = wp_parse_url( $url, PHP_URL_HOST ); + + switch ( $url_host ) { + case 'public-api.wordpress.com': + case 'jetpack.wordpress.com': + case 'jetpack.com': + case 'dashboard.wordpress.com': + $host = isset( $headers['Host'] ) ? $headers['Host'] : $url_host; + $original_url = $url; + $url = preg_replace( + '@^(https?://)' . preg_quote( $url_host, '@' ) . '(?=[/?#].*|$)@', + '${1}' . $sandbox, + $url, + 1 + ); + + /** + * Whether to add the X Debug query parameter to the request made to the Sandbox + * + * @since 1.36.0 + * + * @param bool $add_parameter Whether to add the parameter to the request or not. Default is to false. + * @param string $url The URL of the request being made. + * @param string $host The host of the request being made. + */ + if ( apply_filters( 'jetpack_sandbox_add_profile_parameter', false, $url, $host ) ) { + $url = add_query_arg( 'XDEBUG_PROFILE', 1, $url ); + + // URL has been modified since the signature was created. We'll need a new one. + $original_url = add_query_arg( 'XDEBUG_PROFILE', 1, $original_url ); + $new_signature = $this->get_new_signature( $original_url, $headers, $data, $method ); + + } + } + + return compact( 'url', 'host', 'new_signature' ); + } + + /** + * Gets a new signature for the request + * + * @param string $url The new URL to be signed. + * @param array $headers The headers of the request about to be made. + * @param string $data The body of request about to be made. + * @param string $method The method of the request about to be made. + * @return string|null + */ + private function get_new_signature( $url, $headers, $data, $method ) { + + if ( ! empty( $headers['Authorization'] ) ) { + $a_headers = $this->extract_authorization_headers( $headers ); + if ( ! empty( $a_headers ) ) { + $token_details = explode( ':', $a_headers['token'] ); + + if ( count( $token_details ) === 3 ) { + $user_id = $token_details[2]; + $token = ( new Tokens() )->get_access_token( $user_id ); + $time_diff = (int) \Jetpack_Options::get_option( 'time_diff' ); + $jetpack_signature = new \Jetpack_Signature( $token->secret, $time_diff ); + + $signature = $jetpack_signature->sign_request( + $a_headers['token'], + $a_headers['timestamp'], + $a_headers['nonce'], + $a_headers['body-hash'], + $method, + $url, + $data, + false + ); + + if ( $signature && ! is_wp_error( $signature ) ) { + return $signature; + } elseif ( is_wp_error( $signature ) ) { + $this->log_new_signature_error( $signature->get_error_message() ); + } + } else { + $this->log_new_signature_error( 'Malformed token on Authorization Header' ); + } + } else { + $this->log_new_signature_error( 'Error extracting Authorization Header' ); + } + } else { + $this->log_new_signature_error( 'Empty Authorization Header' ); + } + } + + /** + * Logs error if the attempt to create a new signature fails + * + * @param string $message The error message. + * @return void + */ + private function log_new_signature_error( $message ) { + if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { + error_log( sprintf( "SANDBOXING: Error re-signing the request. '%s'", $message ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log + } + } + + /** + * Extract the values in the Authorization header into an array + * + * @param array $headers The headers of the request about to be made. + * @return array|null + */ + public function extract_authorization_headers( $headers ) { + if ( ! empty( $headers['Authorization'] ) && is_string( $headers['Authorization'] ) ) { + $header = str_replace( 'X_JETPACK ', '', $headers['Authorization'] ); + $vars = explode( ' ', $header ); + $result = array(); + foreach ( $vars as $var ) { + $elements = explode( '"', $var ); + if ( count( $elements ) === 3 ) { + $result[ substr( $elements[0], 0, -1 ) ] = $elements[1]; + } + } + return $result; + } + } + + /** + * Modifies parameters of request in order to send the request to the + * server specified by `JETPACK__SANDBOX_DOMAIN`. + * + * Attached to the `requests-requests.before_request` filter. + * + * @param string $url URL of request about to be made. + * @param array $headers Headers of request about to be made. + * @param array|string $data Data of request about to be made. + * @param string $type Type of request about to be made. + * @return void + */ + public function server_sandbox( &$url, &$headers, &$data = null, &$type = null ) { + if ( ! Constants::get_constant( 'JETPACK__SANDBOX_DOMAIN' ) ) { + return; + } + + $original_url = $url; + + $request_parameters = $this->server_sandbox_request_parameters( Constants::get_constant( 'JETPACK__SANDBOX_DOMAIN' ), $url, $headers, $data, $type ); + + $url = $request_parameters['url']; + + if ( $request_parameters['host'] ) { + $headers['Host'] = $request_parameters['host']; + + if ( $request_parameters['new_signature'] ) { + $headers['Authorization'] = preg_replace( '/signature=\"[^\"]+\"/', 'signature="' . $request_parameters['new_signature'] . '"', $headers['Authorization'] ); + } + + if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { + error_log( sprintf( "SANDBOXING via '%s': '%s'", Constants::get_constant( 'JETPACK__SANDBOX_DOMAIN' ), $original_url ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log + } + } + } + + /** + * Adds a "Jetpack API Sandboxed" item to the admin bar if the JETPACK__SANDBOX_DOMAIN + * constant is set. + * + * Attached to the `admin_bar_menu` action. + * + * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. + */ + public function admin_bar_add_sandbox_item( $wp_admin_bar ) { + if ( ! Constants::get_constant( 'JETPACK__SANDBOX_DOMAIN' ) ) { + return; + } + + $node = array( + 'id' => 'jetpack-connection-api-sandbox', + 'title' => 'Jetpack API Sandboxed', + 'meta' => array( + 'title' => 'Sandboxing via ' . Constants::get_constant( 'JETPACK__SANDBOX_DOMAIN' ), + ), + ); + + $wp_admin_bar->add_menu( $node ); + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-terms-of-service.php b/vendor/automattic/jetpack-connection/src/class-terms-of-service.php new file mode 100644 index 00000000000..b208123f0ea --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-terms-of-service.php @@ -0,0 +1,111 @@ +set_agree(); + /** + * Acton fired when the master user has agreed to the terms of service. + * + * @since 1.0.4 + * @since-jetpack 7.9.0 + */ + do_action( 'jetpack_agreed_to_terms_of_service' ); + } + + /** + * Allow the site to reject to the terms of service. + */ + public function reject() { + $this->set_reject(); + /** + * Acton fired when the master user has revoked their agreement to the terms of service. + * + * @since 1.0.4 + * @since-jetpack 7.9.1 + */ + do_action( 'jetpack_reject_terms_of_service' ); + } + + /** + * Returns whether the master user has agreed to the terms of service. + * + * The following conditions have to be met in order to agree to the terms of service. + * 1. The master user has gone though the connect flow. + * 2. The site is not in dev mode. + * 3. The master user of the site is still connected (deprecated @since 1.4.0). + * + * @return bool + */ + public function has_agreed() { + if ( $this->is_offline_mode() ) { + return false; + } + /** + * Before 1.4.0 we used to also check if the master user of the site is connected + * by calling the Connection related `is_active` method. + * As of 1.4.0 we have removed this check in order to resolve the + * circular dependencies it was introducing to composer packages. + * + * @since 1.4.0 + */ + return $this->get_raw_has_agreed(); + } + + /** + * Abstracted for testing purposes. + * Tells us if the site is in dev mode. + * + * @return bool + */ + protected function is_offline_mode() { + return ( new Status() )->is_offline_mode(); + } + + /** + * Gets just the Jetpack Option that contains the terms of service state. + * Abstracted for testing purposes. + * + * @return bool + */ + protected function get_raw_has_agreed() { + return \Jetpack_Options::get_option( self::OPTION_NAME, false ); + } + + /** + * Sets the correct Jetpack Option to mark the that the site has agreed to the terms of service. + * Abstracted for testing purposes. + */ + protected function set_agree() { + \Jetpack_Options::update_option( self::OPTION_NAME, true ); + } + + /** + * Sets the correct Jetpack Option to mark that the site has rejected the terms of service. + * Abstracted for testing purposes. + */ + protected function set_reject() { + \Jetpack_Options::update_option( self::OPTION_NAME, false ); + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-tokens-locks.php b/vendor/automattic/jetpack-connection/src/class-tokens-locks.php new file mode 100644 index 00000000000..e6819a7c92e --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-tokens-locks.php @@ -0,0 +1,76 @@ +init_aiowpm(); + + static::$is_initialized = true; + } + + /** + * Set the token lock for AIOWPM plugin export. + * + * @param array $params The filter parameters. + * + * @return array + */ + public function aiowpm_set_lock( $params ) { + ( new Tokens() )->set_lock(); + return $params; + } + + /** + * Remove the token lock for AIOWPM plugin export. + * + * @param array $params The filter parameters. + * + * @return array + */ + public function aiowpm_remove_lock( $params ) { + ( new Tokens() )->remove_lock(); + return $params; + } + + /** + * Initialize the All-in-One-WP-Migration plugin hooks. + * + * @return void + */ + private function init_aiowpm() { + add_filter( 'ai1wm_export', array( $this, 'aiowpm_set_lock' ), 180 ); + add_filter( 'ai1wm_export', array( $this, 'aiowpm_remove_lock' ), 250 ); + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-tokens.php b/vendor/automattic/jetpack-connection/src/class-tokens.php new file mode 100644 index 00000000000..1b10356da56 --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-tokens.php @@ -0,0 +1,687 @@ +remove_lock(); + } + + /** + * Perform the API request to validate the blog and user tokens. + * + * @param int|null $user_id ID of the user we need to validate token for. Current user's ID by default. + * + * @return array|false|WP_Error The API response: `array( 'blog_token_is_healthy' => true|false, 'user_token_is_healthy' => true|false )`. + */ + public function validate( $user_id = null ) { + $blog_id = Jetpack_Options::get_option( 'id' ); + if ( ! $blog_id ) { + return new WP_Error( 'site_not_registered', 'Site not registered.' ); + } + $url = sprintf( + '%s/%s/v%s/%s', + Constants::get_constant( 'JETPACK__WPCOM_JSON_API_BASE' ), + 'wpcom', + '2', + 'sites/' . $blog_id . '/jetpack-token-health' + ); + + $user_token = $this->get_access_token( $user_id ? $user_id : get_current_user_id() ); + $blog_token = $this->get_access_token(); + + // Cannot validate non-existent tokens. + if ( false === $user_token || false === $blog_token ) { + return false; + } + + $method = 'POST'; + $body = array( + 'user_token' => $this->get_signed_token( $user_token ), + 'blog_token' => $this->get_signed_token( $blog_token ), + ); + $response = Client::_wp_remote_request( $url, compact( 'body', 'method' ) ); + + if ( is_wp_error( $response ) || ! wp_remote_retrieve_body( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { + return false; + } + + $body = json_decode( wp_remote_retrieve_body( $response ), true ); + + return $body ? $body : false; + } + + /** + * Perform the API request to validate only the blog. + * + * @return bool|WP_Error Boolean with the test result. WP_Error if test cannot be performed. + */ + public function validate_blog_token() { + $blog_id = Jetpack_Options::get_option( 'id' ); + if ( ! $blog_id ) { + return new WP_Error( 'site_not_registered', 'Site not registered.' ); + } + $url = sprintf( + '%s/%s/v%s/%s', + Constants::get_constant( 'JETPACK__WPCOM_JSON_API_BASE' ), + 'wpcom', + '2', + 'sites/' . $blog_id . '/jetpack-token-health/blog' + ); + + $method = 'GET'; + $response = Client::remote_request( compact( 'url', 'method' ) ); + + if ( is_wp_error( $response ) || ! wp_remote_retrieve_body( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { + return false; + } + + $body = json_decode( wp_remote_retrieve_body( $response ), true ); + + return is_array( $body ) && isset( $body['is_healthy'] ) && true === $body['is_healthy']; + } + + /** + * Obtains the auth token. + * + * @param array $data The request data. + * @param string $token_api_url The URL of the Jetpack "token" API. + * @return object|WP_Error Returns the auth token on success. + * Returns a WP_Error on failure. + */ + public function get( $data, $token_api_url ) { + $roles = new Roles(); + $role = $roles->translate_current_user_to_role(); + + if ( ! $role ) { + return new WP_Error( 'role', __( 'An administrator for this blog must set up the Jetpack connection.', 'jetpack-connection' ) ); + } + + $client_secret = $this->get_access_token(); + if ( ! $client_secret ) { + return new WP_Error( 'client_secret', __( 'You need to register your Jetpack before connecting it.', 'jetpack-connection' ) ); + } + + /** + * Filter the URL of the first time the user gets redirected back to your site for connection + * data processing. + * + * @since 1.7.0 + * @since-jetpack 8.0.0 + * + * @param string $redirect_url Defaults to the site admin URL. + */ + $processing_url = apply_filters( 'jetpack_token_processing_url', admin_url( 'admin.php' ) ); + + $redirect = isset( $data['redirect'] ) ? esc_url_raw( (string) $data['redirect'] ) : ''; + + /** + * Filter the URL to redirect the user back to when the authentication process + * is complete. + * + * @since 1.7.0 + * @since-jetpack 8.0.0 + * + * @param string $redirect_url Defaults to the site URL. + */ + $redirect = apply_filters( 'jetpack_token_redirect_url', $redirect ); + + $redirect_uri = ( 'calypso' === $data['auth_type'] ) + ? $data['redirect_uri'] + : add_query_arg( + array( + 'handler' => 'jetpack-connection-webhooks', + 'action' => 'authorize', + '_wpnonce' => wp_create_nonce( "jetpack-authorize_{$role}_{$redirect}" ), + 'redirect' => $redirect ? rawurlencode( $redirect ) : false, + ), + esc_url( $processing_url ) + ); + + /** + * Filters the token request data. + * + * @since 1.7.0 + * @since-jetpack 8.0.0 + * + * @param array $request_data request data. + */ + $body = apply_filters( + 'jetpack_token_request_body', + array( + 'client_id' => Jetpack_Options::get_option( 'id' ), + 'client_secret' => $client_secret->secret, + 'grant_type' => 'authorization_code', + 'code' => $data['code'], + 'redirect_uri' => $redirect_uri, + ) + ); + + $args = array( + 'method' => 'POST', + 'body' => $body, + 'headers' => array( + 'Accept' => 'application/json', + ), + ); + add_filter( 'http_request_timeout', array( $this, 'return_30' ), PHP_INT_MAX - 1 ); + $response = Client::_wp_remote_request( $token_api_url, $args ); + remove_filter( 'http_request_timeout', array( $this, 'return_30' ), PHP_INT_MAX - 1 ); + + if ( is_wp_error( $response ) ) { + return new WP_Error( 'token_http_request_failed', $response->get_error_message() ); + } + + $code = wp_remote_retrieve_response_code( $response ); + $entity = wp_remote_retrieve_body( $response ); + + if ( $entity ) { + $json = json_decode( $entity ); + } else { + $json = false; + } + + if ( 200 !== $code || ! empty( $json->error ) ) { + if ( empty( $json->error ) ) { + return new WP_Error( 'unknown', '', $code ); + } + + /* translators: Error description string. */ + $error_description = isset( $json->error_description ) ? sprintf( __( 'Error Details: %s', 'jetpack-connection' ), (string) $json->error_description ) : ''; + + return new WP_Error( (string) $json->error, $error_description, $code ); + } + + if ( empty( $json->access_token ) || ! is_scalar( $json->access_token ) ) { + return new WP_Error( 'access_token', '', $code ); + } + + if ( empty( $json->token_type ) || 'X_JETPACK' !== strtoupper( $json->token_type ) ) { + return new WP_Error( 'token_type', '', $code ); + } + + if ( empty( $json->scope ) ) { + return new WP_Error( 'scope', 'No Scope', $code ); + } + + // TODO: get rid of the error silencer. + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged + @list( $role, $hmac ) = explode( ':', $json->scope ); + if ( empty( $role ) || empty( $hmac ) ) { + return new WP_Error( 'scope', 'Malformed Scope', $code ); + } + + if ( $this->sign_role( $role ) !== $json->scope ) { + return new WP_Error( 'scope', 'Invalid Scope', $code ); + } + + $cap = $roles->translate_role_to_cap( $role ); + if ( ! $cap ) { + return new WP_Error( 'scope', 'No Cap', $code ); + } + + if ( ! current_user_can( $cap ) ) { + return new WP_Error( 'scope', 'current_user_cannot', $code ); + } + + return (string) $json->access_token; + } + + /** + * Enters a user token into the user_tokens option + * + * @param int $user_id The user id. + * @param string $token The user token. + * @param bool $is_master_user Whether the user is the master user. + * @return bool + */ + public function update_user_token( $user_id, $token, $is_master_user ) { + // Not designed for concurrent updates. + $user_tokens = $this->get_user_tokens(); + if ( ! is_array( $user_tokens ) ) { + $user_tokens = array(); + } + $user_tokens[ $user_id ] = $token; + if ( $is_master_user ) { + $master_user = $user_id; + $options = compact( 'user_tokens', 'master_user' ); + } else { + $options = compact( 'user_tokens' ); + } + return Jetpack_Options::update_options( $options ); + } + + /** + * Sign a user role with the master access token. + * If not specified, will default to the current user. + * + * @access public + * + * @param string $role User role. + * @param int $user_id ID of the user. + * @return string Signed user role. + */ + public function sign_role( $role, $user_id = null ) { + if ( empty( $user_id ) ) { + $user_id = (int) get_current_user_id(); + } + + if ( ! $user_id ) { + return false; + } + + $token = $this->get_access_token(); + if ( ! $token || is_wp_error( $token ) ) { + return false; + } + + return $role . ':' . hash_hmac( 'md5', "{$role}|{$user_id}", $token->secret ); + } + + /** + * Increases the request timeout value to 30 seconds. + * + * @return int Returns 30. + */ + public function return_30() { + return 30; + } + + /** + * Gets the requested token. + * + * Tokens are one of two types: + * 1. Blog Tokens: These are the "main" tokens. Each site typically has one Blog Token, + * though some sites can have multiple "Special" Blog Tokens (see below). These tokens + * are not associated with a user account. They represent the site's connection with + * the Jetpack servers. + * 2. User Tokens: These are "sub-"tokens. Each connected user account has one User Token. + * + * All tokens look like "{$token_key}.{$private}". $token_key is a public ID for the + * token, and $private is a secret that should never be displayed anywhere or sent + * over the network; it's used only for signing things. + * + * Blog Tokens can be "Normal" or "Special". + * * Normal: The result of a normal connection flow. They look like + * "{$random_string_1}.{$random_string_2}" + * That is, $token_key and $private are both random strings. + * Sites only have one Normal Blog Token. Normal Tokens are found in either + * Jetpack_Options::get_option( 'blog_token' ) (usual) or the JETPACK_BLOG_TOKEN + * constant (rare). + * * Special: A connection token for sites that have gone through an alternative + * connection flow. They look like: + * ";{$special_id}{$special_version};{$wpcom_blog_id};.{$random_string}" + * That is, $private is a random string and $token_key has a special structure with + * lots of semicolons. + * Most sites have zero Special Blog Tokens. Special tokens are only found in the + * JETPACK_BLOG_TOKEN constant. + * + * In particular, note that Normal Blog Tokens never start with ";" and that + * Special Blog Tokens always do. + * + * When searching for a matching Blog Tokens, Blog Tokens are examined in the following + * order: + * 1. Defined Special Blog Tokens (via the JETPACK_BLOG_TOKEN constant) + * 2. Stored Normal Tokens (via Jetpack_Options::get_option( 'blog_token' )) + * 3. Defined Normal Tokens (via the JETPACK_BLOG_TOKEN constant) + * + * @param int|false $user_id false: Return the Blog Token. int: Return that user's User Token. + * @param string|false $token_key If provided, check that the token matches the provided input. + * @param bool|true $suppress_errors If true, return a falsy value when the token isn't found; When false, return a descriptive WP_Error when the token isn't found. + * + * @return object|false|WP_Error + */ + public function get_access_token( $user_id = false, $token_key = false, $suppress_errors = true ) { + if ( $this->is_locked() ) { + $this->delete_all(); + return false; + } + + $possible_special_tokens = array(); + $possible_normal_tokens = array(); + $user_tokens = $this->get_user_tokens(); + + if ( $user_id ) { + if ( ! $user_tokens ) { + return $suppress_errors ? false : new WP_Error( 'no_user_tokens', __( 'No user tokens found', 'jetpack-connection' ) ); + } + if ( true === $user_id ) { // connection owner. + $user_id = Jetpack_Options::get_option( 'master_user' ); + if ( ! $user_id ) { + return $suppress_errors ? false : new WP_Error( 'empty_master_user_option', __( 'No primary user defined', 'jetpack-connection' ) ); + } + } + if ( ! isset( $user_tokens[ $user_id ] ) || ! $user_tokens[ $user_id ] ) { + // translators: %s is the user ID. + return $suppress_errors ? false : new WP_Error( 'no_token_for_user', sprintf( __( 'No token for user %d', 'jetpack-connection' ), $user_id ) ); + } + $user_token_chunks = explode( '.', $user_tokens[ $user_id ] ); + if ( empty( $user_token_chunks[1] ) || empty( $user_token_chunks[2] ) ) { + // translators: %s is the user ID. + return $suppress_errors ? false : new WP_Error( 'token_malformed', sprintf( __( 'Token for user %d is malformed', 'jetpack-connection' ), $user_id ) ); + } + if ( $user_token_chunks[2] !== (string) $user_id ) { + // translators: %1$d is the ID of the requested user. %2$d is the user ID found in the token. + return $suppress_errors ? false : new WP_Error( 'user_id_mismatch', sprintf( __( 'Requesting user_id %1$d does not match token user_id %2$d', 'jetpack-connection' ), $user_id, $user_token_chunks[2] ) ); + } + $possible_normal_tokens[] = "{$user_token_chunks[0]}.{$user_token_chunks[1]}"; + } else { + $stored_blog_token = Jetpack_Options::get_option( 'blog_token' ); + if ( $stored_blog_token ) { + $possible_normal_tokens[] = $stored_blog_token; + } + + $defined_tokens_string = Constants::get_constant( 'JETPACK_BLOG_TOKEN' ); + + if ( $defined_tokens_string ) { + $defined_tokens = explode( ',', $defined_tokens_string ); + foreach ( $defined_tokens as $defined_token ) { + if ( ';' === $defined_token[0] ) { + $possible_special_tokens[] = $defined_token; + } else { + $possible_normal_tokens[] = $defined_token; + } + } + } + } + + if ( self::MAGIC_NORMAL_TOKEN_KEY === $token_key ) { + $possible_tokens = $possible_normal_tokens; + } else { + $possible_tokens = array_merge( $possible_special_tokens, $possible_normal_tokens ); + } + + if ( ! $possible_tokens ) { + // If no user tokens were found, it would have failed earlier, so this is about blog token. + return $suppress_errors ? false : new WP_Error( 'no_possible_tokens', __( 'No blog token found', 'jetpack-connection' ) ); + } + + $valid_token = false; + + if ( false === $token_key ) { + // Use first token. + $valid_token = $possible_tokens[0]; + } elseif ( self::MAGIC_NORMAL_TOKEN_KEY === $token_key ) { + // Use first normal token. + $valid_token = $possible_tokens[0]; // $possible_tokens only contains normal tokens because of earlier check. + } else { + // Use the token matching $token_key or false if none. + // Ensure we check the full key. + $token_check = rtrim( $token_key, '.' ) . '.'; + + foreach ( $possible_tokens as $possible_token ) { + if ( hash_equals( substr( $possible_token, 0, strlen( $token_check ) ), $token_check ) ) { + $valid_token = $possible_token; + break; + } + } + } + + if ( ! $valid_token ) { + if ( $user_id ) { + // translators: %d is the user ID. + return $suppress_errors ? false : new WP_Error( 'no_valid_user_token', sprintf( __( 'Invalid token for user %d', 'jetpack-connection' ), $user_id ) ); + } else { + return $suppress_errors ? false : new WP_Error( 'no_valid_blog_token', __( 'Invalid blog token', 'jetpack-connection' ) ); + } + } + + return (object) array( + 'secret' => $valid_token, + 'external_user_id' => (int) $user_id, + ); + } + + /** + * Updates the blog token to a new value. + * + * @access public + * + * @param string $token the new blog token value. + * @return Boolean Whether updating the blog token was successful. + */ + public function update_blog_token( $token ) { + return Jetpack_Options::update_option( 'blog_token', $token ); + } + + /** + * Unlinks the current user from the linked WordPress.com user. + * + * @access public + * @static + * + * @todo Refactor to properly load the XMLRPC client independently. + * + * @param int $user_id The user identifier. + * + * @return bool Whether the disconnection of the user was successful. + */ + public function disconnect_user( $user_id ) { + $tokens = $this->get_user_tokens(); + if ( ! $tokens ) { + return false; + } + + if ( ! isset( $tokens[ $user_id ] ) ) { + return false; + } + + unset( $tokens[ $user_id ] ); + + $this->update_user_tokens( $tokens ); + + return true; + } + + /** + * Returns an array of user_id's that have user tokens for communicating with wpcom. + * Able to select by specific capability. + * + * @deprecated 1.30.0 + * @see Manager::get_connected_users + * + * @param string $capability The capability of the user. + * @param int|null $limit How many connected users to get before returning. + * @return array Array of WP_User objects if found. + */ + public function get_connected_users( $capability = 'any', $limit = null ) { + _deprecated_function( __METHOD__, '1.30.0' ); + return ( new Manager( 'jetpack' ) )->get_connected_users( $capability, $limit ); + } + + /** + * Fetches a signed token. + * + * @param object $token the token. + * @return WP_Error|string a signed token + */ + public function get_signed_token( $token ) { + if ( ! isset( $token->secret ) || empty( $token->secret ) ) { + return new WP_Error( 'invalid_token' ); + } + + list( $token_key, $token_secret ) = explode( '.', $token->secret ); + + $token_key = sprintf( + '%s:%d:%d', + $token_key, + Constants::get_constant( 'JETPACK__API_VERSION' ), + $token->external_user_id + ); + + $timestamp = time(); + + if ( function_exists( 'wp_generate_password' ) ) { + $nonce = wp_generate_password( 10, false ); + } else { + $nonce = substr( sha1( wp_rand( 0, 1000000 ) ), 0, 10 ); + } + + $normalized_request_string = implode( + "\n", + array( + $token_key, + $timestamp, + $nonce, + ) + ) . "\n"; + + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode + $signature = base64_encode( hash_hmac( 'sha1', $normalized_request_string, $token_secret, true ) ); + + $auth = array( + 'token' => $token_key, + 'timestamp' => $timestamp, + 'nonce' => $nonce, + 'signature' => $signature, + ); + + $header_pieces = array(); + foreach ( $auth as $key => $value ) { + $header_pieces[] = sprintf( '%s="%s"', $key, $value ); + } + + return implode( ' ', $header_pieces ); + } + + /** + * Gets the list of user tokens + * + * @since 1.30.0 + * + * @return bool|array An array of user tokens where keys are user IDs and values are the tokens. False if no user token is found. + */ + public function get_user_tokens() { + return Jetpack_Options::get_option( 'user_tokens' ); + } + + /** + * Updates the option that stores the user tokens + * + * @since 1.30.0 + * + * @param array $tokens An array of user tokens where keys are user IDs and values are the tokens. + * @return bool Was the option successfully updated? + * + * @todo add validate the input. + */ + public function update_user_tokens( $tokens ) { + return Jetpack_Options::update_option( 'user_tokens', $tokens ); + } + + /** + * Lock the tokens to the current site URL. + * + * @param int $timespan How long the tokens should be locked, in seconds. + * + * @return bool + */ + public function set_lock( $timespan = HOUR_IN_SECONDS ) { + try { + $expires = ( new DateTime() )->add( DateInterval::createFromDateString( (int) $timespan . ' seconds' ) ); + } catch ( Exception $e ) { + return false; + } + + if ( false === $expires ) { + return false; + } + + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode + return Jetpack_Options::update_option( 'token_lock', $expires->format( static::DATE_FORMAT_ATOM ) . '|||' . base64_encode( Urls::site_url() ) ); + } + + /** + * Remove the site lock from tokens. + * + * @return bool + */ + public function remove_lock() { + Jetpack_Options::delete_option( 'token_lock' ); + + return true; + } + + /** + * Check if the domain is locked, remove the lock if needed. + * Possible scenarios: + * - lock expired, site URL matches the lock URL: remove the lock, return false. + * - lock not expired, site URL matches the lock URL: return false. + * - site URL does not match the lock URL (expiration date is ignored): return true, do not remove the lock. + * + * @return bool + */ + public function is_locked() { + $the_lock = Jetpack_Options::get_option( 'token_lock' ); + if ( ! $the_lock ) { + // Not locked. + return false; + } + + $the_lock = explode( '|||', $the_lock, 2 ); + if ( count( $the_lock ) !== 2 ) { + // Something's wrong with the lock. + $this->remove_lock(); + return false; + } + + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode + $locked_site_url = base64_decode( $the_lock[1] ); + $expires = $the_lock[0]; + + $expiration_date = DateTime::createFromFormat( static::DATE_FORMAT_ATOM, $expires ); + if ( false === $expiration_date || ! $locked_site_url ) { + // Something's wrong with the lock. + $this->remove_lock(); + return false; + } + + if ( Urls::site_url() === $locked_site_url ) { + if ( new DateTime() > $expiration_date ) { + // Site lock expired. + // Site URL matches, removing the lock. + $this->remove_lock(); + } + + return false; + } + + // Site URL doesn't match. + return true; + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-tracking.php b/vendor/automattic/jetpack-connection/src/class-tracking.php new file mode 100644 index 00000000000..1ff9f06c3ca --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-tracking.php @@ -0,0 +1,318 @@ +product_name = $product_name; + $this->connection = $connection; + if ( $this->connection === null ) { + // TODO We should always pass a Connection. + $this->connection = new Connection\Manager(); + } + + if ( ! did_action( 'jetpack_set_tracks_ajax_hook' ) ) { + add_action( 'wp_ajax_jetpack_tracks', array( $this, 'ajax_tracks' ) ); + + /** + * Fires when the Tracking::ajax_tracks() callback has been hooked to the + * wp_ajax_jetpack_tracks action. This action is used to ensure that + * the callback is hooked only once. + * + * @since 1.13.11 + */ + do_action( 'jetpack_set_tracks_ajax_hook' ); + } + } + + /** + * Universal method for for all tracking events triggered via the JavaScript client. + * + * @access public + */ + public function ajax_tracks() { + // Check for nonce. + if ( + empty( $_REQUEST['tracksNonce'] ) + || ! wp_verify_nonce( $_REQUEST['tracksNonce'], 'jp-tracks-ajax-nonce' ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- WP core doesn't pre-sanitize nonces either. + ) { + wp_send_json_error( + __( 'You aren’t authorized to do that.', 'jetpack-connection' ), + 403 + ); + } + + if ( ! isset( $_REQUEST['tracksEventName'] ) || ! isset( $_REQUEST['tracksEventType'] ) ) { + wp_send_json_error( + __( 'No valid event name or type.', 'jetpack-connection' ), + 403 + ); + } + + $tracks_data = array(); + if ( 'click' === $_REQUEST['tracksEventType'] && isset( $_REQUEST['tracksEventProp'] ) ) { + if ( is_array( $_REQUEST['tracksEventProp'] ) ) { + $tracks_data = array_map( 'filter_var', wp_unslash( $_REQUEST['tracksEventProp'] ) ); + } else { + $tracks_data = array( 'clicked' => filter_var( wp_unslash( $_REQUEST['tracksEventProp'] ) ) ); + } + } + + $this->record_user_event( filter_var( wp_unslash( $_REQUEST['tracksEventName'] ) ), $tracks_data, null, false ); + + wp_send_json_success(); + } + + /** + * Register script necessary for tracking. + * + * @param boolean $enqueue Also enqueue? defaults to false. + */ + public static function register_tracks_functions_scripts( $enqueue = false ) { + + // Register jp-tracks as it is a dependency. + wp_register_script( + 'jp-tracks', + '//stats.wp.com/w.js', + array(), + gmdate( 'YW' ), + true + ); + + Assets::register_script( + 'jp-tracks-functions', + '../dist/tracks-callables.js', + __FILE__, + array( + 'dependencies' => array( 'jp-tracks' ), + 'enqueue' => $enqueue, + 'in_footer' => true, + ) + ); + } + + /** + * Enqueue script necessary for tracking. + */ + public function enqueue_tracks_scripts() { + Assets::register_script( + 'jptracks', + '../dist/tracks-ajax.js', + __FILE__, + array( + 'dependencies' => array( 'jquery' ), + 'enqueue' => true, + 'in_footer' => true, + ) + ); + + wp_localize_script( + 'jptracks', + 'jpTracksAJAX', + array( + 'ajaxurl' => admin_url( 'admin-ajax.php' ), + 'jpTracksAJAX_nonce' => wp_create_nonce( 'jp-tracks-ajax-nonce' ), + ) + ); + } + + /** + * Send an event in Tracks. + * + * @param string $event_type Type of the event. + * @param array $data Data to send with the event. + * @param mixed $user Username, user_id, or WP_user object. + * @param bool $use_product_prefix Whether to use the object's product name as a prefix to the event type. If + * set to false, the prefix will be 'jetpack_'. + */ + public function record_user_event( $event_type, $data = array(), $user = null, $use_product_prefix = true ) { + if ( ! $user ) { + $user = wp_get_current_user(); + } + $site_url = get_option( 'siteurl' ); + + $data['_via_ua'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? filter_var( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : ''; + $data['_via_ip'] = isset( $_SERVER['REMOTE_ADDR'] ) ? filter_var( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : ''; + $data['_lg'] = isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ? filter_var( wp_unslash( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) : ''; + $data['blog_url'] = $site_url; + $data['blog_id'] = \Jetpack_Options::get_option( 'id' ); + + // Top level events should not be namespaced. + if ( '_aliasUser' !== $event_type ) { + $prefix = $use_product_prefix ? $this->product_name : 'jetpack'; + $event_type = $prefix . '_' . $event_type; + } + + $data['jetpack_version'] = defined( 'JETPACK__VERSION' ) ? JETPACK__VERSION : '0'; + + return $this->tracks_record_event( $user, $event_type, $data ); + } + + /** + * Record an event in Tracks - this is the preferred way to record events from PHP. + * + * @param mixed $user username, user_id, or WP_user object. + * @param string $event_name The name of the event. + * @param array $properties Custom properties to send with the event. + * @param int $event_timestamp_millis The time in millis since 1970-01-01 00:00:00 when the event occurred. + * + * @return bool true for success | \WP_Error if the event pixel could not be fired + */ + public function tracks_record_event( $user, $event_name, $properties = array(), $event_timestamp_millis = false ) { + + // We don't want to track user events during unit tests/CI runs. + if ( $user instanceof \WP_User && 'wptests_capabilities' === $user->cap_key ) { + return false; + } + $terms_of_service = new Terms_Of_Service(); + $status = new Status(); + // Don't track users who have not agreed to our TOS. + if ( ! $this->should_enable_tracking( $terms_of_service, $status ) ) { + return false; + } + + $event_obj = $this->tracks_build_event_obj( $user, $event_name, $properties, $event_timestamp_millis ); + + if ( is_wp_error( $event_obj->error ) ) { + return $event_obj->error; + } + + return $event_obj->record(); + } + + /** + * Determines whether tracking should be enabled. + * + * @param Automattic\Jetpack\Terms_Of_Service $terms_of_service A Terms_Of_Service object. + * @param Automattic\Jetpack\Status $status A Status object. + * + * @return boolean True if tracking should be enabled, else false. + */ + public function should_enable_tracking( $terms_of_service, $status ) { + if ( $status->is_offline_mode() ) { + return false; + } + + return $terms_of_service->has_agreed() || $this->connection->is_user_connected(); + } + + /** + * Procedurally build a Tracks Event Object. + * NOTE: Use this only when the simpler Automattic\Jetpack\Tracking->jetpack_tracks_record_event() function won't work for you. + * + * @param WP_user $user WP_user object. + * @param string $event_name The name of the event. + * @param array $properties Custom properties to send with the event. + * @param int $event_timestamp_millis The time in millis since 1970-01-01 00:00:00 when the event occurred. + * + * @return \Jetpack_Tracks_Event|\WP_Error + */ + private function tracks_build_event_obj( $user, $event_name, $properties = array(), $event_timestamp_millis = false ) { + $identity = $this->tracks_get_identity( $user->ID ); + + $properties['user_lang'] = $user->get( 'WPLANG' ); + + $blog_details = array( + 'blog_lang' => isset( $properties['blog_lang'] ) ? $properties['blog_lang'] : get_bloginfo( 'language' ), + ); + + $timestamp = ( false !== $event_timestamp_millis ) ? $event_timestamp_millis : round( microtime( true ) * 1000 ); + $timestamp_string = is_string( $timestamp ) ? $timestamp : number_format( $timestamp, 0, '', '' ); + + return new \Jetpack_Tracks_Event( + array_merge( + $blog_details, + (array) $properties, + $identity, + array( + '_en' => $event_name, + '_ts' => $timestamp_string, + ) + ) + ); + } + + /** + * Get the identity to send to tracks. + * + * @param int $user_id The user id of the local user. + * + * @return array $identity + */ + public function tracks_get_identity( $user_id ) { + + // Meta is set, and user is still connected. Use WPCOM ID. + $wpcom_id = get_user_meta( $user_id, 'jetpack_tracks_wpcom_id', true ); + if ( $wpcom_id && $this->connection->is_user_connected( $user_id ) ) { + return array( + '_ut' => 'wpcom:user_id', + '_ui' => $wpcom_id, + ); + } + + // User is connected, but no meta is set yet. Use WPCOM ID and set meta. + if ( $this->connection->is_user_connected( $user_id ) ) { + $wpcom_user_data = $this->connection->get_connected_user_data( $user_id ); + update_user_meta( $user_id, 'jetpack_tracks_wpcom_id', $wpcom_user_data['ID'] ); + + return array( + '_ut' => 'wpcom:user_id', + '_ui' => $wpcom_user_data['ID'], + ); + } + + // User isn't linked at all. Fall back to anonymous ID. + $anon_id = get_user_meta( $user_id, 'jetpack_tracks_anon_id', true ); + if ( ! $anon_id ) { + $anon_id = \Jetpack_Tracks_Client::get_anon_id(); + add_user_meta( $user_id, 'jetpack_tracks_anon_id', $anon_id, false ); + } + + if ( ! isset( $_COOKIE['tk_ai'] ) && ! headers_sent() ) { + setcookie( 'tk_ai', $anon_id, 0, COOKIEPATH, COOKIE_DOMAIN, is_ssl(), false ); // phpcs:ignore Jetpack.Functions.SetCookie -- This is a random string and should be fine. + } + + return array( + '_ut' => 'anon', + '_ui' => $anon_id, + ); + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-urls.php b/vendor/automattic/jetpack-connection/src/class-urls.php new file mode 100644 index 00000000000..00ac5cca405 --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-urls.php @@ -0,0 +1,186 @@ +update_user_token() instead. + * + * @param int $user_id The user id. + * @param string $token The user token. + * @param bool $is_master_user Whether the user is the master user. + * @return bool + */ + public static function update_user_token( $user_id, $token, $is_master_user ) { + _deprecated_function( __METHOD__, '1.24.0', 'Automattic\\Jetpack\\Connection\\Tokens->update_user_token' ); + return ( new Tokens() )->update_user_token( $user_id, $token, $is_master_user ); + } + + /** + * Filters the value of the api constant. + * + * @param String $constant_value The constant value. + * @param String $constant_name The constant name. + * @return mixed | null + */ + public static function jetpack_api_constant_filter( $constant_value, $constant_name ) { + if ( $constant_value !== null ) { + // If the constant value was already set elsewhere, use that value. + return $constant_value; + } + + if ( defined( "self::DEFAULT_$constant_name" ) ) { + return constant( "self::DEFAULT_$constant_name" ); + } + + return null; + } + + /** + * Add a filter to initialize default values of the constants. + */ + public static function init_default_constants() { + add_filter( + 'jetpack_constant_default_value', + array( __CLASS__, 'jetpack_api_constant_filter' ), + 10, + 2 + ); + } + + /** + * Filters the registration request body to include tracking properties. + * + * @param array $properties Already prepared tracking properties. + * @return array amended properties. + */ + public static function filter_register_request_body( $properties ) { + $tracking = new Tracking(); + $tracks_identity = $tracking->tracks_get_identity( get_current_user_id() ); + + return array_merge( + $properties, + array( + '_ui' => $tracks_identity['_ui'], + '_ut' => $tracks_identity['_ut'], + ) + ); + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-webhooks.php b/vendor/automattic/jetpack-connection/src/class-webhooks.php new file mode 100644 index 00000000000..8d57421b4b9 --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-webhooks.php @@ -0,0 +1,211 @@ +connection = $connection; + } + + /** + * Initialize the webhooks. + * + * @param Manager $connection The Connection Manager object. + */ + public static function init( $connection ) { + $webhooks = new static( $connection ); + + add_action( 'init', array( $webhooks, 'controller' ) ); + add_action( 'load-toplevel_page_jetpack', array( $webhooks, 'fallback_jetpack_controller' ) ); + } + + /** + * Jetpack plugin used to trigger this webhooks in Jetpack::admin_page_load() + * + * The Jetpack toplevel menu is still accessible for stand-alone plugins, and while there's no content for that page, there are still + * actions from Calypso and WPCOM that reach that route regardless of the site having the Jetpack plugin or not. That's why we are still handling it here. + */ + public function fallback_jetpack_controller() { + $this->controller( true ); + } + + /** + * The "controller" decides which handler we need to run. + * + * @param bool $force Do not check if it's a webhook request and just run the controller. + */ + public function controller( $force = false ) { + if ( ! $force ) { + // The nonce is verified in specific handlers. + // phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( empty( $_GET['handler'] ) || 'jetpack-connection-webhooks' !== $_GET['handler'] ) { + return; + } + } + + // phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( isset( $_GET['connect_url_redirect'] ) ) { + $this->handle_connect_url_redirect(); + } + + // phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( empty( $_GET['action'] ) ) { + return; + } + + // The nonce is verified in specific handlers. + // phpcs:ignore WordPress.Security.NonceVerification.Recommended + switch ( $_GET['action'] ) { + case 'authorize': + $this->handle_authorize(); + $this->do_exit(); + break; + case 'authorize_redirect': + $this->handle_authorize_redirect(); + $this->do_exit(); + break; + // Class Jetpack::admin_page_load() still handles other cases. + } + } + + /** + * Perform the authorization action. + */ + public function handle_authorize() { + if ( $this->connection->is_connected() && $this->connection->is_user_connected() ) { + $redirect_url = apply_filters( 'jetpack_client_authorize_already_authorized_url', admin_url() ); + wp_safe_redirect( $redirect_url ); + + return; + } + do_action( 'jetpack_client_authorize_processing' ); + + $data = stripslashes_deep( $_GET ); + $data['auth_type'] = 'client'; + $roles = new Roles(); + $role = $roles->translate_current_user_to_role(); + $redirect = isset( $data['redirect'] ) ? esc_url_raw( (string) $data['redirect'] ) : ''; + + check_admin_referer( "jetpack-authorize_{$role}_{$redirect}" ); + + $tracking = new Tracking(); + + $result = $this->connection->authorize( $data ); + + if ( is_wp_error( $result ) ) { + do_action( 'jetpack_client_authorize_error', $result ); + + $tracking->record_user_event( + 'jpc_client_authorize_fail', + array( + 'error_code' => $result->get_error_code(), + 'error_message' => $result->get_error_message(), + ) + ); + } else { + /** + * Fires after the Jetpack client is authorized to communicate with WordPress.com. + * + * @param int Jetpack Blog ID. + * + * @since 1.7.0 + * @since-jetpack 4.2.0 + */ + do_action( 'jetpack_client_authorized', Jetpack_Options::get_option( 'id' ) ); + + $tracking->record_user_event( 'jpc_client_authorize_success' ); + } + + $fallback_redirect = apply_filters( 'jetpack_client_authorize_fallback_url', admin_url() ); + $redirect = wp_validate_redirect( $redirect ) ? $redirect : $fallback_redirect; + + wp_safe_redirect( $redirect ); + } + + /** + * The authorhize_redirect webhook handler + */ + public function handle_authorize_redirect() { + $authorize_redirect_handler = new Webhooks\Authorize_Redirect( $this->connection ); + $authorize_redirect_handler->handle(); + } + + /** + * The `exit` is wrapped into a method so we could mock it. + */ + protected function do_exit() { + exit; + } + + /** + * Handle the `connect_url_redirect` action, + * which is usually called to repeat an attempt for user to authorize the connection. + * + * @return void + */ + public function handle_connect_url_redirect() { + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no site changes. + $from = ! empty( $_GET['from'] ) ? sanitize_text_field( wp_unslash( $_GET['from'] ) ) : 'iframe'; + + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- no site changes, sanitization happens in get_authorization_url() + $redirect = ! empty( $_GET['redirect_after_auth'] ) ? wp_unslash( $_GET['redirect_after_auth'] ) : false; + + add_filter( 'allowed_redirect_hosts', array( Host::class, 'allow_wpcom_environments' ) ); + + if ( ! $this->connection->is_user_connected() ) { + if ( ! $this->connection->is_connected() ) { + $this->connection->register(); + } + + $connect_url = add_query_arg( 'from', $from, $this->connection->get_authorization_url( null, $redirect ) ); + + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no site changes. + if ( isset( $_GET['notes_iframe'] ) ) { + $connect_url .= '¬es_iframe'; + } + wp_safe_redirect( $connect_url ); + $this->do_exit(); + } elseif ( ! isset( $_GET['calypso_env'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no site changes. + ( new CookieState() )->state( 'message', 'already_authorized' ); + wp_safe_redirect( $redirect ); + $this->do_exit(); + } else { + $connect_url = add_query_arg( + array( + 'from' => $from, + 'already_authorized' => true, + ), + $this->connection->get_authorization_url() + ); + wp_safe_redirect( $connect_url ); + $this->do_exit(); + } + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-xmlrpc-async-call.php b/vendor/automattic/jetpack-connection/src/class-xmlrpc-async-call.php new file mode 100644 index 00000000000..815c3287932 --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-xmlrpc-async-call.php @@ -0,0 +1,105 @@ + [ + * $user_id => [ + * arrat of Jetpack_IXR_ClientMulticall + * ] + * ] + * ] + * + * @var array + */ + public static $clients = array(); + + /** + * Adds a new XMLRPC call to the queue to be processed on shutdown + * + * @param string $method The XML-RPC method. + * @param integer $user_id The user ID used to make the request (will use this user's token); Use 0 for the blog token. + * @param mixed ...$args This function accepts any number of additional arguments, that will be passed to the call. + * @return void + */ + public static function add_call( $method, $user_id = 0, ...$args ) { + global $blog_id; + + $client_blog_id = is_multisite() ? $blog_id : 0; + + if ( ! isset( self::$clients[ $client_blog_id ] ) ) { + self::$clients[ $client_blog_id ] = array(); + } + + if ( ! isset( self::$clients[ $client_blog_id ][ $user_id ] ) ) { + self::$clients[ $client_blog_id ][ $user_id ] = new Jetpack_IXR_ClientMulticall( array( 'user_id' => $user_id ) ); + } + + if ( function_exists( 'ignore_user_abort' ) ) { + ignore_user_abort( true ); + } + + array_unshift( $args, $method ); + + call_user_func_array( array( self::$clients[ $client_blog_id ][ $user_id ], 'addCall' ), $args ); + + if ( false === has_action( 'shutdown', array( 'Automattic\Jetpack\Connection\XMLRPC_Async_Call', 'do_calls' ) ) ) { + add_action( 'shutdown', array( 'Automattic\Jetpack\Connection\XMLRPC_Async_Call', 'do_calls' ) ); + } + } + + /** + * Trigger the calls at shutdown + * + * @return void + */ + public static function do_calls() { + foreach ( self::$clients as $client_blog_id => $blog_clients ) { + if ( $client_blog_id > 0 ) { + $switch_success = switch_to_blog( $client_blog_id ); + + if ( ! $switch_success ) { + continue; + } + } + + foreach ( $blog_clients as $client ) { + if ( empty( $client->calls ) ) { + continue; + } + + flush(); + $client->query(); + } + + if ( $client_blog_id > 0 ) { + restore_current_blog(); + } + } + } +} diff --git a/vendor/automattic/jetpack-connection/src/class-xmlrpc-connector.php b/vendor/automattic/jetpack-connection/src/class-xmlrpc-connector.php new file mode 100644 index 00000000000..c3d786d8880 --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/class-xmlrpc-connector.php @@ -0,0 +1,83 @@ +connection = $connection; + + // Adding the filter late to avoid being overwritten by Jetpack's XMLRPC server. + add_filter( 'xmlrpc_methods', array( $this, 'xmlrpc_methods' ), 20 ); + } + + /** + * Attached to the `xmlrpc_methods` filter. + * + * @param array $methods The already registered XML-RPC methods. + * @return array + */ + public function xmlrpc_methods( $methods ) { + return array_merge( + $methods, + array( + 'jetpack.verifyRegistration' => array( $this, 'verify_registration' ), + ) + ); + } + + /** + * Handles verification that a site is registered. + * + * @param array $registration_data The data sent by the XML-RPC client: + * [ $secret_1, $user_id ]. + * + * @return string|IXR_Error + */ + public function verify_registration( $registration_data ) { + return $this->output( $this->connection->handle_registration( $registration_data ) ); + } + + /** + * Normalizes output for XML-RPC. + * + * @param mixed $data The data to output. + */ + private function output( $data ) { + if ( is_wp_error( $data ) ) { + $code = $data->get_error_data(); + if ( ! $code ) { + $code = -10520; + } + + if ( ! class_exists( \IXR_Error::class ) ) { + require_once ABSPATH . WPINC . '/class-IXR.php'; + } + return new \IXR_Error( + $code, + sprintf( 'Jetpack: [%s] %s', $data->get_error_code(), $data->get_error_message() ) + ); + } + + return $data; + } +} diff --git a/vendor/automattic/jetpack-connection/src/interface-manager.php b/vendor/automattic/jetpack-connection/src/interface-manager.php new file mode 100644 index 00000000000..804f38481cc --- /dev/null +++ b/vendor/automattic/jetpack-connection/src/interface-manager.php @@ -0,0 +1,17 @@ +connection = $connection; + } + + /** + * Handle the webhook + * + * This method implements what's in Jetpack::admin_page_load when the Jetpack plugin is not present + */ + public function handle() { + + add_filter( + 'allowed_redirect_hosts', + function ( $domains ) { + $domains[] = 'jetpack.com'; + $domains[] = 'jetpack.wordpress.com'; + $domains[] = 'wordpress.com'; + // Calypso envs. + $domains[] = 'calypso.localhost'; + $domains[] = 'wpcalypso.wordpress.com'; + $domains[] = 'horizon.wordpress.com'; + return array_unique( $domains ); + } + ); + + // phpcs:ignore WordPress.Security.NonceVerification.Recommended + $dest_url = empty( $_GET['dest_url'] ) ? null : esc_url_raw( wp_unslash( $_GET['dest_url'] ) ); + + if ( ! $dest_url || ( 0 === stripos( $dest_url, 'https://jetpack.com/' ) && 0 === stripos( $dest_url, 'https://wordpress.com/' ) ) ) { + // The destination URL is missing or invalid, nothing to do here. + exit; + } + + // The user is either already connected, or finished the connection process. + if ( $this->connection->is_connected() && $this->connection->is_user_connected() ) { + if ( class_exists( '\Automattic\Jetpack\Licensing' ) && method_exists( '\Automattic\Jetpack\Licensing', 'handle_user_connected_redirect' ) ) { + Licensing::instance()->handle_user_connected_redirect( $dest_url ); + } + + wp_safe_redirect( $dest_url ); + exit; + } elseif ( ! empty( $_GET['done'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + // The user decided not to proceed with setting up the connection. + + wp_safe_redirect( Admin_Menu::get_top_level_menu_item_url() ); + exit; + } + + $redirect_args = array( + 'page' => 'jetpack', + 'action' => 'authorize_redirect', + 'dest_url' => rawurlencode( $dest_url ), + 'done' => '1', + ); + + // phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( ! empty( $_GET['from'] ) && 'jetpack_site_only_checkout' === $_GET['from'] ) { + $redirect_args['from'] = 'jetpack_site_only_checkout'; + } + + wp_safe_redirect( $this->build_authorize_url( add_query_arg( $redirect_args, admin_url( 'admin.php' ) ) ) ); + exit; + } + + /** + * Create the Jetpack authorization URL. Copied from Jetpack class. + * + * @param bool|string $redirect URL to redirect to. + * + * @todo Update default value for redirect since the called function expects a string. + * + * @return mixed|void + */ + public function build_authorize_url( $redirect = false ) { + + add_filter( 'jetpack_connect_request_body', array( __CLASS__, 'filter_connect_request_body' ) ); + add_filter( 'jetpack_connect_redirect_url', array( __CLASS__, 'filter_connect_redirect_url' ) ); + + $url = $this->connection->get_authorization_url( wp_get_current_user(), $redirect ); + + remove_filter( 'jetpack_connect_request_body', array( __CLASS__, 'filter_connect_request_body' ) ); + remove_filter( 'jetpack_connect_redirect_url', array( __CLASS__, 'filter_connect_redirect_url' ) ); + + /** + * This filter is documented in plugins/jetpack/class-jetpack.php + */ + return apply_filters( 'jetpack_build_authorize_url', $url ); + } + + /** + * Filters the redirection URL that is used for connect requests. The redirect + * URL should return the user back to the Jetpack console. + * Copied from Jetpack class. + * + * @param String $redirect the default redirect URL used by the package. + * @return String the modified URL. + */ + public static function filter_connect_redirect_url( $redirect ) { + $jetpack_admin_page = esc_url_raw( admin_url( 'admin.php?page=jetpack' ) ); + $redirect = $redirect + ? wp_validate_redirect( esc_url_raw( $redirect ), $jetpack_admin_page ) + : $jetpack_admin_page; + + // phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( isset( $_REQUEST['is_multisite'] ) ) { + $redirect = Jetpack_Network::init()->get_url( 'network_admin_page' ); + } + + return $redirect; + } + + /** + * Filters the connection URL parameter array. + * Copied from Jetpack class. + * + * @param array $args default URL parameters used by the package. + * @return array the modified URL arguments array. + */ + public static function filter_connect_request_body( $args ) { + if ( + Constants::is_defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) + && include_once Constants::get_constant( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) + ) { + $gp_locale = GP_Locales::by_field( 'wp_locale', get_locale() ); + $args['locale'] = isset( $gp_locale ) && isset( $gp_locale->slug ) + ? $gp_locale->slug + : ''; + } + + $tracking = new Tracking(); + $tracks_identity = $tracking->tracks_get_identity( $args['state'] ); + + $args = array_merge( + $args, + array( + '_ui' => $tracks_identity['_ui'], + '_ut' => $tracks_identity['_ut'], + ) + ); + + $calypso_env = self::get_calypso_env(); + + if ( ! empty( $calypso_env ) ) { + $args['calypso_env'] = $calypso_env; + } + + return $args; + } + + /** + * Return Calypso environment value; used for developing Jetpack and pairing + * it with different Calypso enrionments, such as localhost. + * Copied from Jetpack class. + * + * @since 1.37.1 + * + * @return string Calypso environment + */ + public static function get_calypso_env() { + // phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( isset( $_GET['calypso_env'] ) ) { + // phpcs:ignore WordPress.Security.NonceVerification.Recommended + return sanitize_key( $_GET['calypso_env'] ); + } + + if ( getenv( 'CALYPSO_ENV' ) ) { + return sanitize_key( getenv( 'CALYPSO_ENV' ) ); + } + + if ( defined( 'CALYPSO_ENV' ) && CALYPSO_ENV ) { + return sanitize_key( CALYPSO_ENV ); + } + + return ''; + } +} diff --git a/vendor/automattic/jetpack-constants/CHANGELOG.md b/vendor/automattic/jetpack-constants/CHANGELOG.md new file mode 100644 index 00000000000..f81ab442f0c --- /dev/null +++ b/vendor/automattic/jetpack-constants/CHANGELOG.md @@ -0,0 +1,189 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [1.6.23] - 2023-08-23 +### Changed +- Updated package dependencies. [#32605] + +## [1.6.22] - 2023-04-10 +### Added +- Add Jetpack Autoloader package suggestion. [#29988] + +## [1.6.21] - 2023-02-20 +### Changed +- Minor internal updates. + +## [1.6.20] - 2022-12-02 +### Changed +- Updated package dependencies. [#27688] + +## [1.6.19] - 2022-11-22 +### Changed +- Updated package dependencies. [#27043] + +## [1.6.18] - 2022-07-26 +### Changed +- Updated package dependencies. [#25158] + +## [1.6.17] - 2022-06-21 +### Changed +- Renaming master to trunk. + +## [1.6.16] - 2022-04-26 +### Changed +- Updated package dependencies. + +## [1.6.15] - 2022-01-25 +### Changed +- Updated package dependencies. + +## [1.6.14] - 2022-01-04 +### Changed +- Switch to pcov for code coverage. +- Updated package dependencies + +## [1.6.13] - 2021-12-14 +### Changed +- Updated package dependencies. + +## [1.6.12] - 2021-11-22 +### Changed +- Updated package dependencies + +## [1.6.11] - 2021-11-02 +### Changed +- Set `convertDeprecationsToExceptions` true in PHPUnit config. +- Update PHPUnit configs to include just what needs coverage rather than include everything then try to exclude stuff that doesn't. + +## [1.6.10] - 2021-10-26 +### Fixed +- Updated is_true docblock to be more accurate. + +## [1.6.9] - 2021-10-13 +### Changed +- Updated package dependencies. + +## [1.6.8] - 2021-10-06 +### Changed +- Updated package dependencies + +## [1.6.7] - 2021-09-28 +### Changed +- Updated package dependencies. + +## [1.6.6] - 2021-08-30 +### Changed +- Run composer update on test-php command instead of phpunit +- Tests: update PHPUnit polyfills dependency (yoast/phpunit-polyfills). +- Updated versions in annotations + +## [1.6.5] - 2021-05-25 +### Changed +- Updated package dependencies. + +## [1.6.4] - 2021-04-08 +### Changed +- Packaging and build changes, no change to the package itself. + +## [1.6.3] - 2021-03-30 +### Added +- Composer alias for dev-master, to improve dependencies + +### Changed +- Update package dependencies. + +### Fixed +- Use `composer update` rather than `install` in scripts, as composer.lock isn't checked in. + +## [1.6.2] - 2021-02-05 + +- CI: Make tests more generic + +## [1.6.1] - 2021-01-19 + +- Add mirror-repo information to all current composer packages +- Monorepo: Reorganize all projects + +## [1.6.0] - 2020-12-14 + +- Update dependency brain/monkey to v2.6.0 +- Pin dependencies +- Packages: Update for PHP 8 testing + +## [1.5.1] - 2020-10-28 + +- Updated PHPCS: Packages and Debugger + +## [1.5.0] - 2020-08-13 + +- CI: Try collect js coverage +- Docker: Add package testing shortcut + +## [1.4.0] - 2020-07-01 + +- Package Unit tests: update test file names to make sure they runs in Travis + +## [1.3.0] - 2020-06-22 + +- PHPCS: Clean up the packages + +## [1.2.0] - 2020-04-15 + +- Use jp.com redirect in all links +- Connection: add a filter for setting Jetpack api constants + +## [1.1.3] - 2019-11-08 + +- Packages: Use classmap instead of PSR-4 + +## [1.1.2] - 2019-10-28 + +- Packages: Add gitattributes files to all packages that need th… + +## [1.1.1] - 2019-09-20 + +- Docs: Unify usage of @package phpdoc tags + +## [1.1.0] - 2019-09-14 + +## 1.0.0 - 2019-07-09 + +- Packages: Finish the constants package + +[1.6.23]: https://github.com/Automattic/jetpack-constants/compare/v1.6.22...v1.6.23 +[1.6.22]: https://github.com/Automattic/jetpack-constants/compare/v1.6.21...v1.6.22 +[1.6.21]: https://github.com/Automattic/jetpack-constants/compare/v1.6.20...v1.6.21 +[1.6.20]: https://github.com/Automattic/jetpack-constants/compare/v1.6.19...v1.6.20 +[1.6.19]: https://github.com/Automattic/jetpack-constants/compare/v1.6.18...v1.6.19 +[1.6.18]: https://github.com/Automattic/jetpack-constants/compare/v1.6.17...v1.6.18 +[1.6.17]: https://github.com/Automattic/jetpack-constants/compare/v1.6.16...v1.6.17 +[1.6.16]: https://github.com/Automattic/jetpack-constants/compare/v1.6.15...v1.6.16 +[1.6.15]: https://github.com/Automattic/jetpack-constants/compare/v1.6.14...v1.6.15 +[1.6.14]: https://github.com/Automattic/jetpack-constants/compare/v1.6.13...v1.6.14 +[1.6.13]: https://github.com/Automattic/jetpack-constants/compare/v1.6.12...v1.6.13 +[1.6.12]: https://github.com/Automattic/jetpack-constants/compare/v1.6.11...v1.6.12 +[1.6.11]: https://github.com/Automattic/jetpack-constants/compare/v1.6.10...v1.6.11 +[1.6.10]: https://github.com/Automattic/jetpack-constants/compare/v1.6.9...v1.6.10 +[1.6.9]: https://github.com/Automattic/jetpack-constants/compare/v1.6.8...v1.6.9 +[1.6.8]: https://github.com/Automattic/jetpack-constants/compare/v1.6.7...v1.6.8 +[1.6.7]: https://github.com/Automattic/jetpack-constants/compare/v1.6.6...v1.6.7 +[1.6.6]: https://github.com/Automattic/jetpack-constants/compare/v1.6.5...v1.6.6 +[1.6.5]: https://github.com/Automattic/jetpack-constants/compare/v1.6.4...v1.6.5 +[1.6.4]: https://github.com/Automattic/jetpack-constants/compare/v1.6.3...v1.6.4 +[1.6.3]: https://github.com/Automattic/jetpack-constants/compare/v1.6.2...v1.6.3 +[1.6.2]: https://github.com/Automattic/jetpack-constants/compare/v1.6.1...v1.6.2 +[1.6.1]: https://github.com/Automattic/jetpack-constants/compare/v1.6.0...v1.6.1 +[1.6.0]: https://github.com/Automattic/jetpack-constants/compare/v1.5.1...v1.6.0 +[1.5.1]: https://github.com/Automattic/jetpack-constants/compare/v1.5.0...v1.5.1 +[1.5.0]: https://github.com/Automattic/jetpack-constants/compare/v1.4.0...v1.5.0 +[1.4.0]: https://github.com/Automattic/jetpack-constants/compare/v1.3.0...v1.4.0 +[1.3.0]: https://github.com/Automattic/jetpack-constants/compare/v1.2.0...v1.3.0 +[1.2.0]: https://github.com/Automattic/jetpack-constants/compare/v1.1.3...v1.2.0 +[1.1.3]: https://github.com/Automattic/jetpack-constants/compare/v1.1.2...v1.1.3 +[1.1.2]: https://github.com/Automattic/jetpack-constants/compare/v1.1.1...v1.1.2 +[1.1.1]: https://github.com/Automattic/jetpack-constants/compare/v1.1.0...v1.1.1 +[1.1.0]: https://github.com/Automattic/jetpack-constants/compare/v1.0.0...v1.1.0 diff --git a/vendor/automattic/jetpack-constants/LICENSE.txt b/vendor/automattic/jetpack-constants/LICENSE.txt new file mode 100644 index 00000000000..e82774c1bd5 --- /dev/null +++ b/vendor/automattic/jetpack-constants/LICENSE.txt @@ -0,0 +1,357 @@ +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +=================================== + + +GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + + Preamble + +The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + +We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + +Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and +modification follow. + +GNU GENERAL PUBLIC LICENSE +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + +a) You must cause the modified files to carry prominent notices +stating that you changed the files and the date of any change. + +b) You must cause any work that you distribute or publish, that in +whole or in part contains or is derived from the Program or any +part thereof, to be licensed as a whole at no charge to all third +parties under the terms of this License. + +c) If the modified program normally reads commands interactively +when run, you must cause it, when started running for such +interactive use in the most ordinary way, to print or display an +announcement including an appropriate copyright notice and a +notice that there is no warranty (or else, saying that you provide +a warranty) and that users may redistribute the program under +these conditions, and telling the user how to view a copy of this +License. (Exception: if the Program itself is interactive but +does not normally print such an announcement, your work based on +the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + +a) Accompany it with the complete corresponding machine-readable +source code, which must be distributed under the terms of Sections +1 and 2 above on a medium customarily used for software interchange; or, + +b) Accompany it with a written offer, valid for at least three +years, to give any third party, for a charge no more than your +cost of physically performing source distribution, a complete +machine-readable copy of the corresponding source code, to be +distributed under the terms of Sections 1 and 2 above on a medium +customarily used for software interchange; or, + +c) Accompany it with the information you received as to the offer +to distribute corresponding source code. (This alternative is +allowed only for noncommercial distribution and only if you +received the program in object code or executable form with such +an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + +5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + +7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + +10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + +Copyright (C) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + +Gnomovision version 69, Copyright (C) year name of author +Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. +This is free software, and you are welcome to redistribute it +under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in the program +`Gnomovision' (which makes passes at compilers) written by James Hacker. + +, 1 April 1989 +Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/vendor/automattic/jetpack-constants/README.md b/vendor/automattic/jetpack-constants/README.md new file mode 100644 index 00000000000..ed216f5ba69 --- /dev/null +++ b/vendor/automattic/jetpack-constants/README.md @@ -0,0 +1,67 @@ +# Jetpack Constants + +A simple constant manager for Jetpack. + +Testing constants is hard. Once you define a constant in PHP, it's defined. Constants Manager is an abstraction layer so that unit tests can set constants for tests. + +### Usage + +Retrieve the value of a constant `CONSTANT_NAME` (returns `null` if it's not defined): + +```php +use Automattic\Jetpack\Constants; + +$constant_value = Constants::get_constant( 'CONSTANT_NAME' ); +``` + +Set the value of a constant `CONSTANT_NAME` to a particular value: + +```php +use Automattic\Jetpack\Constants; + +$value = 'some value'; +Constants::set_constant( 'CONSTANT_NAME', $value ); +``` + +Check whether a constant `CONSTANT_NAME` is defined: + +```php +use Automattic\Jetpack\Constants; + +$defined = Constants::is_defined( 'CONSTANT_NAME' ); +``` + +Check whether a constant `CONSTANT_NAME` is truthy: + +```php +use Automattic\Jetpack\Constants; + +$is_truthy = Constants::is_true( 'CONSTANT_NAME' ); +``` + +Delete the `CONSTANT_NAME` constant: + +```php +use Automattic\Jetpack\Constants; + +Constants::clear_single_constant( 'CONSTANT_NAME' ); +``` + +Delete all known constants: + +```php +use Automattic\Jetpack\Constants; + +Constants::clear_constants(); +``` +## Using this package in your WordPress plugin + +If you plan on using this package in your WordPress plugin, we would recommend that you use [Jetpack Autoloader](https://packagist.org/packages/automattic/jetpack-autoloader) as your autoloader. This will allow for maximum interoperability with other plugins that use this package as well. + +## Security + +Need to report a security vulnerability? Go to [https://automattic.com/security/](https://automattic.com/security/) or directly to our security bug bounty site [https://hackerone.com/automattic](https://hackerone.com/automattic). + +## License + +jetpack-constants is licensed under [GNU General Public License v2 (or later)](./LICENSE.txt) diff --git a/vendor/automattic/jetpack-constants/SECURITY.md b/vendor/automattic/jetpack-constants/SECURITY.md new file mode 100644 index 00000000000..b4b46c0ee23 --- /dev/null +++ b/vendor/automattic/jetpack-constants/SECURITY.md @@ -0,0 +1,38 @@ +# Security Policy + +Full details of the Automattic Security Policy can be found on [automattic.com](https://automattic.com/security/). + +## Supported Versions + +Generally, only the latest version of Jetpack has continued support. If a critical vulnerability is found in the current version of Jetpack, we may opt to backport any patches to previous versions. + +## Reporting a Vulnerability + +[Jetpack](https://jetpack.com/) is an open-source plugin for WordPress. Our HackerOne program covers the plugin software, as well as a variety of related projects and infrastructure. + +**For responsible disclosure of security issues and to be eligible for our bug bounty program, please submit your report via the [HackerOne](https://hackerone.com/automattic) portal.** + +Our most critical targets are: + +* Jetpack and the Jetpack composer packages (all within this repo) +* Jetpack.com -- the primary marketing site. +* cloud.jetpack.com -- a management site. +* wordpress.com -- the shared management site for both Jetpack and WordPress.com sites. + +For more targets, see the `In Scope` section on [HackerOne](https://hackerone.com/automattic). + +_Please note that the **WordPress software is a separate entity** from Automattic. Please report vulnerabilities for WordPress through [the WordPress Foundation's HackerOne page](https://hackerone.com/wordpress)._ + +## Guidelines + +We're committed to working with security researchers to resolve the vulnerabilities they discover. You can help us by following these guidelines: + +* Follow [HackerOne's disclosure guidelines](https://www.hackerone.com/disclosure-guidelines). +* Pen-testing Production: + * Please **setup a local environment** instead whenever possible. Most of our code is open source (see above). + * If that's not possible, **limit any data access/modification** to the bare minimum necessary to reproduce a PoC. + * **_Don't_ automate form submissions!** That's very annoying for us, because it adds extra work for the volunteers who manage those systems, and reduces the signal/noise ratio in our communication channels. + * To be eligible for a bounty, all of these guidelines must be followed. +* Be Patient - Give us a reasonable time to correct the issue before you disclose the vulnerability. + +We also expect you to comply with all applicable laws. You're responsible to pay any taxes associated with your bounties. diff --git a/vendor/automattic/jetpack-constants/composer.json b/vendor/automattic/jetpack-constants/composer.json new file mode 100644 index 00000000000..1205619b8e0 --- /dev/null +++ b/vendor/automattic/jetpack-constants/composer.json @@ -0,0 +1,40 @@ +{ + "name": "automattic/jetpack-constants", + "description": "A wrapper for defining constants in a more testable way.", + "type": "jetpack-library", + "license": "GPL-2.0-or-later", + "require": {}, + "require-dev": { + "brain/monkey": "2.6.1", + "yoast/phpunit-polyfills": "1.1.0", + "automattic/jetpack-changelogger": "^3.3.8" + }, + "suggest": { + "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "scripts": { + "phpunit": [ + "./vendor/phpunit/phpunit/phpunit --colors=always" + ], + "test-php": [ + "@composer phpunit" + ] + }, + "minimum-stability": "dev", + "prefer-stable": true, + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-constants", + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-constants/compare/v${old}...v${new}" + }, + "branch-alias": { + "dev-trunk": "1.6.x-dev" + } + } +} diff --git a/vendor/automattic/jetpack-constants/src/class-constants.php b/vendor/automattic/jetpack-constants/src/class-constants.php new file mode 100644 index 00000000000..eaad50be8bc --- /dev/null +++ b/vendor/automattic/jetpack-constants/src/class-constants.php @@ -0,0 +1,124 @@ + +Copyright (C) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + +Gnomovision version 69, Copyright (C) year name of author +Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. +This is free software, and you are welcome to redistribute it +under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in the program +`Gnomovision' (which makes passes at compilers) written by James Hacker. + +, 1 April 1989 +Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/vendor/automattic/jetpack-redirect/README.md b/vendor/automattic/jetpack-redirect/README.md new file mode 100644 index 00000000000..5d65e016d39 --- /dev/null +++ b/vendor/automattic/jetpack-redirect/README.md @@ -0,0 +1,24 @@ +# Jetpack Redirect package + +A package containing functionality to generate URLs to the jetpack.com/redirect/ service + +### Usage TODO + +See `Automattic\Jetpack\Redirect::get_url()` documentation. + +### Testing + +```bash +$ composer run phpunit +``` +## Using this package in your WordPress plugin + +If you plan on using this package in your WordPress plugin, we would recommend that you use [Jetpack Autoloader](https://packagist.org/packages/automattic/jetpack-autoloader) as your autoloader. This will allow for maximum interoperability with other plugins that use this package as well. + +## Security + +Need to report a security vulnerability? Go to [https://automattic.com/security/](https://automattic.com/security/) or directly to our security bug bounty site [https://hackerone.com/automattic](https://hackerone.com/automattic). + +## License + +jetpack-redirect is licensed under [GNU General Public License v2 (or later)](./LICENSE.txt) diff --git a/vendor/automattic/jetpack-redirect/SECURITY.md b/vendor/automattic/jetpack-redirect/SECURITY.md new file mode 100644 index 00000000000..b4b46c0ee23 --- /dev/null +++ b/vendor/automattic/jetpack-redirect/SECURITY.md @@ -0,0 +1,38 @@ +# Security Policy + +Full details of the Automattic Security Policy can be found on [automattic.com](https://automattic.com/security/). + +## Supported Versions + +Generally, only the latest version of Jetpack has continued support. If a critical vulnerability is found in the current version of Jetpack, we may opt to backport any patches to previous versions. + +## Reporting a Vulnerability + +[Jetpack](https://jetpack.com/) is an open-source plugin for WordPress. Our HackerOne program covers the plugin software, as well as a variety of related projects and infrastructure. + +**For responsible disclosure of security issues and to be eligible for our bug bounty program, please submit your report via the [HackerOne](https://hackerone.com/automattic) portal.** + +Our most critical targets are: + +* Jetpack and the Jetpack composer packages (all within this repo) +* Jetpack.com -- the primary marketing site. +* cloud.jetpack.com -- a management site. +* wordpress.com -- the shared management site for both Jetpack and WordPress.com sites. + +For more targets, see the `In Scope` section on [HackerOne](https://hackerone.com/automattic). + +_Please note that the **WordPress software is a separate entity** from Automattic. Please report vulnerabilities for WordPress through [the WordPress Foundation's HackerOne page](https://hackerone.com/wordpress)._ + +## Guidelines + +We're committed to working with security researchers to resolve the vulnerabilities they discover. You can help us by following these guidelines: + +* Follow [HackerOne's disclosure guidelines](https://www.hackerone.com/disclosure-guidelines). +* Pen-testing Production: + * Please **setup a local environment** instead whenever possible. Most of our code is open source (see above). + * If that's not possible, **limit any data access/modification** to the bare minimum necessary to reproduce a PoC. + * **_Don't_ automate form submissions!** That's very annoying for us, because it adds extra work for the volunteers who manage those systems, and reduces the signal/noise ratio in our communication channels. + * To be eligible for a bounty, all of these guidelines must be followed. +* Be Patient - Give us a reasonable time to correct the issue before you disclose the vulnerability. + +We also expect you to comply with all applicable laws. You're responsible to pay any taxes associated with your bounties. diff --git a/vendor/automattic/jetpack-redirect/composer.json b/vendor/automattic/jetpack-redirect/composer.json new file mode 100644 index 00000000000..429ff92ef8b --- /dev/null +++ b/vendor/automattic/jetpack-redirect/composer.json @@ -0,0 +1,42 @@ +{ + "name": "automattic/jetpack-redirect", + "description": "Utilities to build URLs to the jetpack.com/redirect/ service", + "type": "jetpack-library", + "license": "GPL-2.0-or-later", + "require": { + "automattic/jetpack-status": "^1.18.4" + }, + "require-dev": { + "brain/monkey": "2.6.1", + "yoast/phpunit-polyfills": "1.1.0", + "automattic/jetpack-changelogger": "^3.3.9" + }, + "suggest": { + "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "scripts": { + "phpunit": [ + "./vendor/phpunit/phpunit/phpunit --colors=always" + ], + "test-php": [ + "@composer phpunit" + ] + }, + "minimum-stability": "dev", + "prefer-stable": true, + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-redirect", + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-redirect/compare/v${old}...v${new}" + }, + "branch-alias": { + "dev-trunk": "1.7.x-dev" + } + } +} diff --git a/vendor/automattic/jetpack-redirect/src/class-redirect.php b/vendor/automattic/jetpack-redirect/src/class-redirect.php new file mode 100644 index 00000000000..da5979b386d --- /dev/null +++ b/vendor/automattic/jetpack-redirect/src/class-redirect.php @@ -0,0 +1,79 @@ +get_site_suffix(); + $args = wp_parse_args( $args, array( 'site' => $site_suffix ) ); + + $source_key = 'source'; + + if ( 0 === strpos( $source, 'https://' ) ) { + $source_key = 'url'; + $source_url = \wp_parse_url( $source ); + + // discard any query and fragments. + $source = 'https://' . $source_url['host'] . ( isset( $source_url['path'] ) ? $source_url['path'] : '' ); + } + + $to_be_added = array( + $source_key => rawurlencode( $source ), + ); + + foreach ( $args as $arg_name => $arg_value ) { + + if ( empty( $arg_value ) ) { + continue; + } + + $to_be_added[ $arg_name ] = rawurlencode( $arg_value ); + + } + + if ( ! empty( $to_be_added ) ) { + $url = add_query_arg( $to_be_added, $url ); + } + + return $url; + } +} diff --git a/vendor/automattic/jetpack-roles/CHANGELOG.md b/vendor/automattic/jetpack-roles/CHANGELOG.md new file mode 100644 index 00000000000..c2415de81d2 --- /dev/null +++ b/vendor/automattic/jetpack-roles/CHANGELOG.md @@ -0,0 +1,189 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [1.4.25] - 2023-09-19 +- Minor internal updates. + +## [1.4.24] - 2023-08-23 +### Changed +- Updated package dependencies. [#32605] + +## [1.4.23] - 2023-04-10 +### Added +- Add Jetpack Autoloader package suggestion. [#29988] + +## [1.4.22] - 2023-02-20 +### Changed +- Minor internal updates. + +## [1.4.21] - 2023-01-11 +### Changed +- Updated package dependencies. + +## [1.4.20] - 2022-12-19 +### Changed +- Updated package dependencies. + +## [1.4.19] - 2022-12-02 +### Changed +- Updated package dependencies. [#27688] + +## [1.4.18] - 2022-11-22 +### Changed +- Updated package dependencies. [#27043] + +## [1.4.17] - 2022-07-26 +### Changed +- Updated package dependencies. [#25158] + +## [1.4.16] - 2022-06-21 +### Changed +- Renaming master to trunk. + +## [1.4.15] - 2022-04-26 +### Changed +- Updated package dependencies. + +## [1.4.14] - 2022-01-25 +### Changed +- Updated package dependencies. + +## [1.4.13] - 2022-01-04 +### Changed +- Switch to pcov for code coverage. +- Updated package dependencies + +## [1.4.12] - 2021-12-14 +### Changed +- Updated package dependencies. + +## [1.4.11] - 2021-11-22 +### Changed +- Updated package dependencies + +## [1.4.10] - 2021-11-02 +### Changed +- Set `convertDeprecationsToExceptions` true in PHPUnit config. +- Update PHPUnit configs to include just what needs coverage rather than include everything then try to exclude stuff that doesn't. + +## [1.4.9] - 2021-10-13 +### Changed +- Updated package dependencies. + +## [1.4.8] - 2021-10-12 +### Changed +- Updated package dependencies + +## [1.4.7] - 2021-09-28 +### Changed +- Updated package dependencies. + +## [1.4.6] - 2021-08-30 +### Changed +- Run composer update on test-php command instead of phpunit +- Tests: update PHPUnit polyfills dependency (yoast/phpunit-polyfills). + +## [1.4.5] - 2021-05-25 +### Changed +- Updated package dependencies. + +## [1.4.4] - 2021-04-08 +### Changed +- Packaging and build changes, no change to the package itself. + +## [1.4.3] - 2021-03-30 +### Added +- Composer alias for dev-master, to improve dependencies + +### Changed +- Update package dependencies. + +### Fixed +- Use `composer update` rather than `install` in scripts, as composer.lock isn't checked in. + +## [1.4.2] - 2021-02-05 + +- CI: Make tests more generic + +## [1.4.1] - 2021-01-20 + +- Add mirror-repo information to all current composer packages +- Monorepo: Reorganize all projects + +## [1.4.0] - 2020-12-14 + +- Update dependency brain/monkey to v2.6.0 +- Pin dependencies +- Packages: Update for PHP 8 testing + +## [1.3.1] - 2020-10-28 + +- Updated PHPCS: Packages and Debugger + +## [1.3.0] - 2020-08-13 + +- CI: Try collect js coverage +- Docker: Add package testing shortcut + +## [1.2.0] - 2020-07-01 + +- Package Unit tests: update test file names to make sure they runs in Travis + +## [1.1.0] - 2020-06-22 + +- PHPCS: Clean up the packages +- PHPCS Updates after WPCS 2.3 + +## [1.0.4] - 2019-11-08 + +- Packages: Use classmap instead of PSR-4 + +## [1.0.2] - 2019-10-28 + +- Packages: Add gitattributes files to all packages that need th… + +## [1.0.1] - 2019-09-20 + +- Docs: Unify usage of @package phpdoc tags + +## 1.0.0 - 2019-09-14 + +- Jetpack DNA: Introduce a Roles package + +[1.4.25]: https://github.com/Automattic/jetpack-roles/compare/v1.4.24...v1.4.25 +[1.4.24]: https://github.com/Automattic/jetpack-roles/compare/v1.4.23...v1.4.24 +[1.4.23]: https://github.com/Automattic/jetpack-roles/compare/v1.4.22...v1.4.23 +[1.4.22]: https://github.com/Automattic/jetpack-roles/compare/v1.4.21...v1.4.22 +[1.4.21]: https://github.com/Automattic/jetpack-roles/compare/v1.4.20...v1.4.21 +[1.4.20]: https://github.com/Automattic/jetpack-roles/compare/v1.4.19...v1.4.20 +[1.4.19]: https://github.com/Automattic/jetpack-roles/compare/v1.4.18...v1.4.19 +[1.4.18]: https://github.com/Automattic/jetpack-roles/compare/v1.4.17...v1.4.18 +[1.4.17]: https://github.com/Automattic/jetpack-roles/compare/v1.4.16...v1.4.17 +[1.4.16]: https://github.com/Automattic/jetpack-roles/compare/v1.4.15...v1.4.16 +[1.4.15]: https://github.com/Automattic/jetpack-roles/compare/v1.4.14...v1.4.15 +[1.4.14]: https://github.com/Automattic/jetpack-roles/compare/v1.4.13...v1.4.14 +[1.4.13]: https://github.com/Automattic/jetpack-roles/compare/v1.4.12...v1.4.13 +[1.4.12]: https://github.com/Automattic/jetpack-roles/compare/v1.4.11...v1.4.12 +[1.4.11]: https://github.com/Automattic/jetpack-roles/compare/v1.4.10...v1.4.11 +[1.4.10]: https://github.com/Automattic/jetpack-roles/compare/v1.4.9...v1.4.10 +[1.4.9]: https://github.com/Automattic/jetpack-roles/compare/v1.4.8...v1.4.9 +[1.4.8]: https://github.com/Automattic/jetpack-roles/compare/v1.4.7...v1.4.8 +[1.4.7]: https://github.com/Automattic/jetpack-roles/compare/v1.4.6...v1.4.7 +[1.4.6]: https://github.com/Automattic/jetpack-roles/compare/v1.4.5...v1.4.6 +[1.4.5]: https://github.com/Automattic/jetpack-roles/compare/v1.4.4...v1.4.5 +[1.4.4]: https://github.com/Automattic/jetpack-roles/compare/v1.4.3...v1.4.4 +[1.4.3]: https://github.com/Automattic/jetpack-roles/compare/v1.4.2...v1.4.3 +[1.4.2]: https://github.com/Automattic/jetpack-roles/compare/v1.4.1...v1.4.2 +[1.4.1]: https://github.com/Automattic/jetpack-roles/compare/v1.4.0...v1.4.1 +[1.4.0]: https://github.com/Automattic/jetpack-roles/compare/v1.3.1...v1.4.0 +[1.3.1]: https://github.com/Automattic/jetpack-roles/compare/v1.3.0...v1.3.1 +[1.3.0]: https://github.com/Automattic/jetpack-roles/compare/v1.2.0...v1.3.0 +[1.2.0]: https://github.com/Automattic/jetpack-roles/compare/v1.1.0...v1.2.0 +[1.1.0]: https://github.com/Automattic/jetpack-roles/compare/v1.0.4...v1.1.0 +[1.0.4]: https://github.com/Automattic/jetpack-roles/compare/v1.0.2...v1.0.4 +[1.0.2]: https://github.com/Automattic/jetpack-roles/compare/v1.0.1...v1.0.2 +[1.0.1]: https://github.com/Automattic/jetpack-roles/compare/v1.0.0...v1.0.1 diff --git a/vendor/automattic/jetpack-roles/LICENSE.txt b/vendor/automattic/jetpack-roles/LICENSE.txt new file mode 100644 index 00000000000..e82774c1bd5 --- /dev/null +++ b/vendor/automattic/jetpack-roles/LICENSE.txt @@ -0,0 +1,357 @@ +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +=================================== + + +GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + + Preamble + +The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + +We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + +Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and +modification follow. + +GNU GENERAL PUBLIC LICENSE +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + +a) You must cause the modified files to carry prominent notices +stating that you changed the files and the date of any change. + +b) You must cause any work that you distribute or publish, that in +whole or in part contains or is derived from the Program or any +part thereof, to be licensed as a whole at no charge to all third +parties under the terms of this License. + +c) If the modified program normally reads commands interactively +when run, you must cause it, when started running for such +interactive use in the most ordinary way, to print or display an +announcement including an appropriate copyright notice and a +notice that there is no warranty (or else, saying that you provide +a warranty) and that users may redistribute the program under +these conditions, and telling the user how to view a copy of this +License. (Exception: if the Program itself is interactive but +does not normally print such an announcement, your work based on +the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + +a) Accompany it with the complete corresponding machine-readable +source code, which must be distributed under the terms of Sections +1 and 2 above on a medium customarily used for software interchange; or, + +b) Accompany it with a written offer, valid for at least three +years, to give any third party, for a charge no more than your +cost of physically performing source distribution, a complete +machine-readable copy of the corresponding source code, to be +distributed under the terms of Sections 1 and 2 above on a medium +customarily used for software interchange; or, + +c) Accompany it with the information you received as to the offer +to distribute corresponding source code. (This alternative is +allowed only for noncommercial distribution and only if you +received the program in object code or executable form with such +an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + +5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + +7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + +10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + +Copyright (C) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + +Gnomovision version 69, Copyright (C) year name of author +Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. +This is free software, and you are welcome to redistribute it +under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in the program +`Gnomovision' (which makes passes at compilers) written by James Hacker. + +, 1 April 1989 +Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/vendor/automattic/jetpack-roles/README.md b/vendor/automattic/jetpack-roles/README.md new file mode 100644 index 00000000000..65f9f9359fd --- /dev/null +++ b/vendor/automattic/jetpack-roles/README.md @@ -0,0 +1,47 @@ +# Jetpack Roles + +A user roles class for Jetpack. + +Contains utilities for translating user roles to capabilities and vice versa. + +### Usage + +Get the role of the current user: + +```php +use Automattic\Jetpack\Roles; + +$roles = new Roles(); +$current_user_role = $roles->translate_current_user_to_role(); +``` + +Get the role of a particular user: + +```php +use Automattic\Jetpack\Roles; + +$roles = new Roles(); +$user = get_user_by( 'contact@yourjetpack.blog' ); +$user_role = $roles->translate_user_to_role( $user ); +``` + +Get the capability we require for a role: + +```php +use Automattic\Jetpack\Roles; + +$roles = new Roles(); +$capability = $roles->translate_role_to_cap( 'administrator' ); +``` + +## Using this package in your WordPress plugin + +If you plan on using this package in your WordPress plugin, we would recommend that you use [Jetpack Autoloader](https://packagist.org/packages/automattic/jetpack-autoloader) as your autoloader. This will allow for maximum interoperability with other plugins that use this package as well. + +## Security + +Need to report a security vulnerability? Go to [https://automattic.com/security/](https://automattic.com/security/) or directly to our security bug bounty site [https://hackerone.com/automattic](https://hackerone.com/automattic). + +## License + +jetpack-roles is licensed under [GNU General Public License v2 (or later)](./LICENSE.txt) diff --git a/vendor/automattic/jetpack-roles/SECURITY.md b/vendor/automattic/jetpack-roles/SECURITY.md new file mode 100644 index 00000000000..b4b46c0ee23 --- /dev/null +++ b/vendor/automattic/jetpack-roles/SECURITY.md @@ -0,0 +1,38 @@ +# Security Policy + +Full details of the Automattic Security Policy can be found on [automattic.com](https://automattic.com/security/). + +## Supported Versions + +Generally, only the latest version of Jetpack has continued support. If a critical vulnerability is found in the current version of Jetpack, we may opt to backport any patches to previous versions. + +## Reporting a Vulnerability + +[Jetpack](https://jetpack.com/) is an open-source plugin for WordPress. Our HackerOne program covers the plugin software, as well as a variety of related projects and infrastructure. + +**For responsible disclosure of security issues and to be eligible for our bug bounty program, please submit your report via the [HackerOne](https://hackerone.com/automattic) portal.** + +Our most critical targets are: + +* Jetpack and the Jetpack composer packages (all within this repo) +* Jetpack.com -- the primary marketing site. +* cloud.jetpack.com -- a management site. +* wordpress.com -- the shared management site for both Jetpack and WordPress.com sites. + +For more targets, see the `In Scope` section on [HackerOne](https://hackerone.com/automattic). + +_Please note that the **WordPress software is a separate entity** from Automattic. Please report vulnerabilities for WordPress through [the WordPress Foundation's HackerOne page](https://hackerone.com/wordpress)._ + +## Guidelines + +We're committed to working with security researchers to resolve the vulnerabilities they discover. You can help us by following these guidelines: + +* Follow [HackerOne's disclosure guidelines](https://www.hackerone.com/disclosure-guidelines). +* Pen-testing Production: + * Please **setup a local environment** instead whenever possible. Most of our code is open source (see above). + * If that's not possible, **limit any data access/modification** to the bare minimum necessary to reproduce a PoC. + * **_Don't_ automate form submissions!** That's very annoying for us, because it adds extra work for the volunteers who manage those systems, and reduces the signal/noise ratio in our communication channels. + * To be eligible for a bounty, all of these guidelines must be followed. +* Be Patient - Give us a reasonable time to correct the issue before you disclose the vulnerability. + +We also expect you to comply with all applicable laws. You're responsible to pay any taxes associated with your bounties. diff --git a/vendor/automattic/jetpack-roles/composer.json b/vendor/automattic/jetpack-roles/composer.json new file mode 100644 index 00000000000..0a5b8aed15b --- /dev/null +++ b/vendor/automattic/jetpack-roles/composer.json @@ -0,0 +1,40 @@ +{ + "name": "automattic/jetpack-roles", + "description": "Utilities, related with user roles and capabilities.", + "type": "jetpack-library", + "license": "GPL-2.0-or-later", + "require": {}, + "require-dev": { + "brain/monkey": "2.6.1", + "yoast/phpunit-polyfills": "1.1.0", + "automattic/jetpack-changelogger": "^3.3.9" + }, + "suggest": { + "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "scripts": { + "phpunit": [ + "./vendor/phpunit/phpunit/phpunit --colors=always" + ], + "test-php": [ + "@composer phpunit" + ] + }, + "minimum-stability": "dev", + "prefer-stable": true, + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-roles", + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-roles/compare/v${old}...v${new}" + }, + "branch-alias": { + "dev-trunk": "1.4.x-dev" + } + } +} diff --git a/vendor/automattic/jetpack-roles/src/class-roles.php b/vendor/automattic/jetpack-roles/src/class-roles.php new file mode 100644 index 00000000000..7bce34625b2 --- /dev/null +++ b/vendor/automattic/jetpack-roles/src/class-roles.php @@ -0,0 +1,81 @@ + 'manage_options', + 'editor' => 'edit_others_posts', + 'author' => 'publish_posts', + 'contributor' => 'edit_posts', + 'subscriber' => 'read', + ); + + /** + * Get the role of the current user. + * + * @access public + * + * @return string|boolean Current user's role, false if not enough capabilities for any of the roles. + */ + public function translate_current_user_to_role() { + foreach ( $this->capability_translations as $role => $cap ) { + if ( current_user_can( $role ) || current_user_can( $cap ) ) { + return $role; + } + } + + return false; + } + + /** + * Get the role of a particular user. + * + * @access public + * + * @param \WP_User $user User object. + * @return string|boolean User's role, false if not enough capabilities for any of the roles. + */ + public function translate_user_to_role( $user ) { + foreach ( $this->capability_translations as $role => $cap ) { + if ( user_can( $user, $role ) || user_can( $user, $cap ) ) { + return $role; + } + } + + return false; + } + + /** + * Get the minimum capability for a role. + * + * @access public + * + * @param string $role Role name. + * @return string|boolean Capability, false if role isn't mapped to any capabilities. + */ + public function translate_role_to_cap( $role ) { + if ( ! isset( $this->capability_translations[ $role ] ) ) { + return false; + } + + return $this->capability_translations[ $role ]; + } +} diff --git a/vendor/automattic/jetpack-status/CHANGELOG.md b/vendor/automattic/jetpack-status/CHANGELOG.md new file mode 100644 index 00000000000..caba85ae214 --- /dev/null +++ b/vendor/automattic/jetpack-status/CHANGELOG.md @@ -0,0 +1,351 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [1.18.5] - 2023-09-25 +### Changed +- Add 127.0.0.1 into the list of known local domains. [#32898] +- WP.com Compatibility: Abort out early checking if Protect is active. WP.com's protection is not site option based. [#33196] + +## [1.18.4] - 2023-09-19 + +- Minor internal updates. + +## [1.18.3] - 2023-09-11 +### Changed +- General: remove backwards-compatibility function checks now that the package supports WP 6.2. [#32772] + +## [1.18.2] - 2023-09-04 +### Fixed +- Exclude domains starting with live from known Pantheon staging domains [#32789] + +## [1.18.1] - 2023-08-23 +### Changed +- Updated package dependencies. [#32605] + +## [1.18.0] - 2023-07-18 +### Added +- Transferred 'get_calypso_env()' method from Jetpack plugin. [#31906] + +## [1.17.2] - 2023-06-19 +### Changed +- Use Plans package to detect feature support. [#31213] + +## [1.17.1] - 2023-05-11 +### Changed +- PHP 8.1 compatibility updates [#30517] + +## [1.17.0] - 2023-04-17 +### Changed +- When Jetpack is available, `Modules::get()` no longer translates `module_tags`. Use Jetpack's `jetpack_get_module_i18n_tag()` function if you need translations. [#30067] + +## [1.16.4] - 2023-04-10 +### Added +- Add Jetpack Autoloader package suggestion. [#29988] + +## [1.16.3] - 2023-03-28 +### Changed +- Move brute force protection into WAF package. [#28401] + +## [1.16.2] - 2023-02-20 +### Changed +- Minor internal updates. + +## [1.16.1] - 2023-01-23 +### Added +- Add new filters for the latest status methods [#28328] + +## [1.16.0] - 2023-01-16 +### Added +- Add 2 new methods to detect whether a site is private or not. [#28322] + +## [1.15.4] - 2023-01-11 +### Changed +- Modules: Allow for deactivating multiple plugins when activating a module. [#28181] + +## [1.15.3] - 2022-12-19 +### Changed +- Updated package dependencies. + +## [1.15.2] - 2022-12-02 +### Changed +- Updated package dependencies. [#27688] + +## [1.15.1] - 2022-11-22 +### Changed +- Updated package dependencies. [#27043] + +## [1.15.0] - 2022-11-07 +### Added +- WordPress.com: add checks for Simple or either Simple/WoA. [#27278] + +## [1.14.3] - 2022-07-26 +### Changed +- Updated package dependencies. [#25158] + +## [1.14.2] - 2022-07-19 +### Changed +- Update logic in `is_woa_site` function for host changes [#25067] + +## [1.14.1] - 2022-06-21 +### Changed +- Renaming master to trunk. + +## [1.14.0] - 2022-06-14 +### Fixed +- Moved the connection_url_redirect action handling to the connection package. [#24529] + +## [1.13.6] - 2022-05-24 +### Added +- Allow plugins to filter the list of available modules. Only activate and consider active modules that are available [#24454] + +## [1.13.5] - 2022-05-20 +### Changed +- Modules: Make activate() method Jetpack plugin agnostic. Allowing standalone plugins to use it without Jetpack. + +## [1.13.4] - 2022-05-19 +### Added +- PHPCS updates. [#24418] + +## [1.13.3] - 2022-05-10 + +## [1.13.2] - 2022-04-26 +### Changed +- Updated package dependencies. + +## [1.13.1] - 2022-04-19 +### Changed +- PHPCS: Fix `WordPress.Security.ValidatedSanitizedInput` + +## [1.13.0] - 2022-04-05 +### Added +- Created Modules and File modules for managing those resources + +## [1.12.0] - 2022-03-02 +### Added +- Cache return values (per blog) from various status methods. + +## [1.11.2] - 2022-02-28 +### Fixed +- Re-doing 1.11.1 to fixup a bad release. + +## [1.11.1] - 2022-02-28 +### Fixed +- Remove trailing semicolor form site suffix. + +## [1.11.0] - 2022-02-22 +### Added +- Add methods to distinguish Newspack and VIP sites. + +## [1.10.0] - 2022-01-25 +### Added +- Added Visitor class for status regarding the site visitor. + +## [1.9.5] - 2022-01-04 +### Changed +- Switch to pcov for code coverage. +- Updated package dependencies + +## [1.9.4] - 2021-12-14 +### Changed +- Updated package dependencies. + +## [1.9.3] - 2021-11-22 +### Changed +- Updated package dependencies + +## [1.9.2] - 2021-11-16 +### Changed +- Add a function_exists check before calling wp_get_environment_type + +## [1.9.1] - 2021-11-02 +### Changed +- Set `convertDeprecationsToExceptions` true in PHPUnit config. +- Update PHPUnit configs to include just what needs coverage rather than include everything then try to exclude stuff that doesn't. + +## [1.9.0] - 2021-10-26 +### Added +- Added Host class for reporting known hosting environment information. + +## [1.8.4] - 2021-10-13 +### Changed +- Updated package dependencies. + +## [1.8.3] - 2021-10-12 +### Changed +- Updated package dependencies + +## [1.8.2] - 2021-09-28 +### Changed +- Updated package dependencies. + +## [1.8.1] - 2021-08-30 +### Changed +- Run composer update on test-php command instead of phpunit +- Tests: update PHPUnit polyfills dependency (yoast/phpunit-polyfills). +- update annotations versions + +## [1.8.0] - 2021-06-15 +### Changed +- Update callback to Jetpack to new Identity_Crisis class. + +## [1.7.6] - 2021-05-25 +### Changed +- Updated package dependencies. + +## [1.7.5] - 2021-04-27 +### Deprecated +- Deprecates is_no_user_testing_mode + +## [1.7.4] - 2021-04-08 +### Changed +- Packaging and build changes, no change to the package itself. + +## [1.7.3] - 2021-03-30 +### Added +- Composer alias for dev-master, to improve dependencies + +### Changed +- Update package dependencies. + +### Fixed +- Use `composer update` rather than `install` in scripts, as composer.lock isn't checked in. + +## [1.7.2] - 2021-02-05 + +- CI: Make tests more generic + +## [1.7.1] - 2021-01-20 + +- Add mirror-repo information to all current composer packages +- Monorepo: Reorganize all projects + +## [1.7.0] - 2020-12-14 + +- Update dependency brain/monkey to v2.6.0 +- Pin dependencies +- Packages: Update for PHP 8 testing + +## [1.6.0] - 2020-11-23 + +- Status: Introduce get_site_suffix method +- Status: Fix test failure +- Status: Improve the staging site detection +- General: update minimum required version to WordPress 5.5 +- Add the no_user_testing mode +- Status: Add a couple of test cases for staging site detection +- Update dependency brain/monkey to v2.5.0 +- Updated PHPCS: Packages and Debugger + +## [1.5.0] - 2020-10-13 + +- Also use Core `wp_get_environment_type` for local + +## [1.4.0] - 2020-08-13 + +- CI: Try collect js coverage + +## [1.3.0] - 2020-07-28 + +- Core Compat: Site Environment + +## [1.2.0] - 2020-06-22 + +- PHPCS: Clean up the packages +- Staging Sites: add newspack staging to the list of known providers + +## [1.1.1] - 2020-01-27 + +- Pin dependency brain/monkey to 2.4.0 + +## [1.1.0] - 2020-01-14 + +- Packages: Various improvements for wp.com or self-contained consumers + +## [1.0.4] - 2019-11-08 + +- Packages: Use classmap instead of PSR-4 + +## [1.0.3] - 2019-10-28 + +- Packages: Add gitattributes files to all packages that need th… + +## [1.0.2] - 2019-10-23 + +- Use spread operator instead of func_get_args + +## [1.0.1] - 2019-09-20 + +- Docs: Unify usage of @package phpdoc tags + +## 1.0.0 - 2019-09-14 + +- Packages: Introduce a status package + +[1.18.5]: https://github.com/Automattic/jetpack-status/compare/v1.18.4...v1.18.5 +[1.18.4]: https://github.com/Automattic/jetpack-status/compare/v1.18.3...v1.18.4 +[1.18.3]: https://github.com/Automattic/jetpack-status/compare/v1.18.2...v1.18.3 +[1.18.2]: https://github.com/Automattic/jetpack-status/compare/v1.18.1...v1.18.2 +[1.18.1]: https://github.com/Automattic/jetpack-status/compare/v1.18.0...v1.18.1 +[1.18.0]: https://github.com/Automattic/jetpack-status/compare/v1.17.2...v1.18.0 +[1.17.2]: https://github.com/Automattic/jetpack-status/compare/v1.17.1...v1.17.2 +[1.17.1]: https://github.com/Automattic/jetpack-status/compare/v1.17.0...v1.17.1 +[1.17.0]: https://github.com/Automattic/jetpack-status/compare/v1.16.4...v1.17.0 +[1.16.4]: https://github.com/Automattic/jetpack-status/compare/v1.16.3...v1.16.4 +[1.16.3]: https://github.com/Automattic/jetpack-status/compare/v1.16.2...v1.16.3 +[1.16.2]: https://github.com/Automattic/jetpack-status/compare/v1.16.1...v1.16.2 +[1.16.1]: https://github.com/Automattic/jetpack-status/compare/v1.16.0...v1.16.1 +[1.16.0]: https://github.com/Automattic/jetpack-status/compare/v1.15.4...v1.16.0 +[1.15.4]: https://github.com/Automattic/jetpack-status/compare/v1.15.3...v1.15.4 +[1.15.3]: https://github.com/Automattic/jetpack-status/compare/v1.15.2...v1.15.3 +[1.15.2]: https://github.com/Automattic/jetpack-status/compare/v1.15.1...v1.15.2 +[1.15.1]: https://github.com/Automattic/jetpack-status/compare/v1.15.0...v1.15.1 +[1.15.0]: https://github.com/Automattic/jetpack-status/compare/v1.14.3...v1.15.0 +[1.14.3]: https://github.com/Automattic/jetpack-status/compare/v1.14.2...v1.14.3 +[1.14.2]: https://github.com/Automattic/jetpack-status/compare/v1.14.1...v1.14.2 +[1.14.1]: https://github.com/Automattic/jetpack-status/compare/v1.14.0...v1.14.1 +[1.14.0]: https://github.com/Automattic/jetpack-status/compare/v1.13.6...v1.14.0 +[1.13.6]: https://github.com/Automattic/jetpack-status/compare/v1.13.5...v1.13.6 +[1.13.5]: https://github.com/Automattic/jetpack-status/compare/v1.13.4...v1.13.5 +[1.13.4]: https://github.com/Automattic/jetpack-status/compare/v1.13.3...v1.13.4 +[1.13.3]: https://github.com/Automattic/jetpack-status/compare/v1.13.2...v1.13.3 +[1.13.2]: https://github.com/Automattic/jetpack-status/compare/v1.13.1...v1.13.2 +[1.13.1]: https://github.com/Automattic/jetpack-status/compare/v1.13.0...v1.13.1 +[1.13.0]: https://github.com/Automattic/jetpack-status/compare/v1.12.0...v1.13.0 +[1.12.0]: https://github.com/Automattic/jetpack-status/compare/v1.11.2...v1.12.0 +[1.11.2]: https://github.com/Automattic/jetpack-status/compare/v1.11.1...v1.11.2 +[1.11.1]: https://github.com/Automattic/jetpack-status/compare/v1.11.0...v1.11.1 +[1.11.0]: https://github.com/Automattic/jetpack-status/compare/v1.10.0...v1.11.0 +[1.10.0]: https://github.com/Automattic/jetpack-status/compare/v1.9.5...v1.10.0 +[1.9.5]: https://github.com/Automattic/jetpack-status/compare/v1.9.4...v1.9.5 +[1.9.4]: https://github.com/Automattic/jetpack-status/compare/v1.9.3...v1.9.4 +[1.9.3]: https://github.com/Automattic/jetpack-status/compare/v1.9.2...v1.9.3 +[1.9.2]: https://github.com/Automattic/jetpack-status/compare/v1.9.1...v1.9.2 +[1.9.1]: https://github.com/Automattic/jetpack-status/compare/v1.9.0...v1.9.1 +[1.9.0]: https://github.com/Automattic/jetpack-status/compare/v1.8.4...v1.9.0 +[1.8.4]: https://github.com/Automattic/jetpack-status/compare/v1.8.3...v1.8.4 +[1.8.3]: https://github.com/Automattic/jetpack-status/compare/v1.8.2...v1.8.3 +[1.8.2]: https://github.com/Automattic/jetpack-status/compare/v1.8.1...v1.8.2 +[1.8.1]: https://github.com/Automattic/jetpack-status/compare/v1.8.0...v1.8.1 +[1.8.0]: https://github.com/Automattic/jetpack-status/compare/v1.7.6...v1.8.0 +[1.7.6]: https://github.com/Automattic/jetpack-status/compare/v1.7.5...v1.7.6 +[1.7.5]: https://github.com/Automattic/jetpack-status/compare/v1.7.4...v1.7.5 +[1.7.4]: https://github.com/Automattic/jetpack-status/compare/v1.7.3...v1.7.4 +[1.7.3]: https://github.com/Automattic/jetpack-status/compare/v1.7.2...v1.7.3 +[1.7.2]: https://github.com/Automattic/jetpack-status/compare/v1.7.1...v1.7.2 +[1.7.1]: https://github.com/Automattic/jetpack-status/compare/v1.7.0...v1.7.1 +[1.7.0]: https://github.com/Automattic/jetpack-status/compare/v1.6.0...v1.7.0 +[1.6.0]: https://github.com/Automattic/jetpack-status/compare/v1.5.0...v1.6.0 +[1.5.0]: https://github.com/Automattic/jetpack-status/compare/v1.4.0...v1.5.0 +[1.4.0]: https://github.com/Automattic/jetpack-status/compare/v1.3.0...v1.4.0 +[1.3.0]: https://github.com/Automattic/jetpack-status/compare/v1.2.0...v1.3.0 +[1.2.0]: https://github.com/Automattic/jetpack-status/compare/v1.1.1...v1.2.0 +[1.1.1]: https://github.com/Automattic/jetpack-status/compare/v1.1.0...v1.1.1 +[1.1.0]: https://github.com/Automattic/jetpack-status/compare/v1.0.4...v1.1.0 +[1.0.4]: https://github.com/Automattic/jetpack-status/compare/v1.0.3...v1.0.4 +[1.0.3]: https://github.com/Automattic/jetpack-status/compare/v1.0.2...v1.0.3 +[1.0.2]: https://github.com/Automattic/jetpack-status/compare/v1.0.1...v1.0.2 +[1.0.1]: https://github.com/Automattic/jetpack-status/compare/v1.0.0...v1.0.1 diff --git a/vendor/automattic/jetpack-status/LICENSE.txt b/vendor/automattic/jetpack-status/LICENSE.txt new file mode 100644 index 00000000000..e82774c1bd5 --- /dev/null +++ b/vendor/automattic/jetpack-status/LICENSE.txt @@ -0,0 +1,357 @@ +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +=================================== + + +GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + + Preamble + +The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + +We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + +Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and +modification follow. + +GNU GENERAL PUBLIC LICENSE +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + +a) You must cause the modified files to carry prominent notices +stating that you changed the files and the date of any change. + +b) You must cause any work that you distribute or publish, that in +whole or in part contains or is derived from the Program or any +part thereof, to be licensed as a whole at no charge to all third +parties under the terms of this License. + +c) If the modified program normally reads commands interactively +when run, you must cause it, when started running for such +interactive use in the most ordinary way, to print or display an +announcement including an appropriate copyright notice and a +notice that there is no warranty (or else, saying that you provide +a warranty) and that users may redistribute the program under +these conditions, and telling the user how to view a copy of this +License. (Exception: if the Program itself is interactive but +does not normally print such an announcement, your work based on +the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + +a) Accompany it with the complete corresponding machine-readable +source code, which must be distributed under the terms of Sections +1 and 2 above on a medium customarily used for software interchange; or, + +b) Accompany it with a written offer, valid for at least three +years, to give any third party, for a charge no more than your +cost of physically performing source distribution, a complete +machine-readable copy of the corresponding source code, to be +distributed under the terms of Sections 1 and 2 above on a medium +customarily used for software interchange; or, + +c) Accompany it with the information you received as to the offer +to distribute corresponding source code. (This alternative is +allowed only for noncommercial distribution and only if you +received the program in object code or executable form with such +an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + +5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + +7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + +10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + +Copyright (C) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + +Gnomovision version 69, Copyright (C) year name of author +Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. +This is free software, and you are welcome to redistribute it +under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in the program +`Gnomovision' (which makes passes at compilers) written by James Hacker. + +, 1 April 1989 +Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/vendor/automattic/jetpack-status/README.md b/vendor/automattic/jetpack-status/README.md new file mode 100644 index 00000000000..369baf02d1d --- /dev/null +++ b/vendor/automattic/jetpack-status/README.md @@ -0,0 +1,45 @@ +# Jetpack Status + +A status class for Jetpack. + +Used to retrieve information about the current status of Jetpack and the site overall. + +### Usage + +Find out whether the site is in offline mode: + +```php +use Automattic\Jetpack\Status; + +$status = new Status(); +$is_offline_mode = $status->is_offline_mode(); +``` + +Find out whether this is a system with multiple networks: + +```php +use Automattic\Jetpack\Status; + +$status = new Status(); +$is_multi_network = $status->is_multi_network(); +``` + +Find out whether this site is a single user site: + +```php +use Automattic\Jetpack\Status; + +$status = new Status(); +$is_single_user_site = $status->is_single_user_site(); +``` +## Using this package in your WordPress plugin + +If you plan on using this package in your WordPress plugin, we would recommend that you use [Jetpack Autoloader](https://packagist.org/packages/automattic/jetpack-autoloader) as your autoloader. This will allow for maximum interoperability with other plugins that use this package as well. + +## Security + +Need to report a security vulnerability? Go to [https://automattic.com/security/](https://automattic.com/security/) or directly to our security bug bounty site [https://hackerone.com/automattic](https://hackerone.com/automattic). + +## License + +jetpack-status is licensed under [GNU General Public License v2 (or later)](./LICENSE.txt) diff --git a/vendor/automattic/jetpack-status/SECURITY.md b/vendor/automattic/jetpack-status/SECURITY.md new file mode 100644 index 00000000000..b4b46c0ee23 --- /dev/null +++ b/vendor/automattic/jetpack-status/SECURITY.md @@ -0,0 +1,38 @@ +# Security Policy + +Full details of the Automattic Security Policy can be found on [automattic.com](https://automattic.com/security/). + +## Supported Versions + +Generally, only the latest version of Jetpack has continued support. If a critical vulnerability is found in the current version of Jetpack, we may opt to backport any patches to previous versions. + +## Reporting a Vulnerability + +[Jetpack](https://jetpack.com/) is an open-source plugin for WordPress. Our HackerOne program covers the plugin software, as well as a variety of related projects and infrastructure. + +**For responsible disclosure of security issues and to be eligible for our bug bounty program, please submit your report via the [HackerOne](https://hackerone.com/automattic) portal.** + +Our most critical targets are: + +* Jetpack and the Jetpack composer packages (all within this repo) +* Jetpack.com -- the primary marketing site. +* cloud.jetpack.com -- a management site. +* wordpress.com -- the shared management site for both Jetpack and WordPress.com sites. + +For more targets, see the `In Scope` section on [HackerOne](https://hackerone.com/automattic). + +_Please note that the **WordPress software is a separate entity** from Automattic. Please report vulnerabilities for WordPress through [the WordPress Foundation's HackerOne page](https://hackerone.com/wordpress)._ + +## Guidelines + +We're committed to working with security researchers to resolve the vulnerabilities they discover. You can help us by following these guidelines: + +* Follow [HackerOne's disclosure guidelines](https://www.hackerone.com/disclosure-guidelines). +* Pen-testing Production: + * Please **setup a local environment** instead whenever possible. Most of our code is open source (see above). + * If that's not possible, **limit any data access/modification** to the bare minimum necessary to reproduce a PoC. + * **_Don't_ automate form submissions!** That's very annoying for us, because it adds extra work for the volunteers who manage those systems, and reduces the signal/noise ratio in our communication channels. + * To be eligible for a bounty, all of these guidelines must be followed. +* Be Patient - Give us a reasonable time to correct the issue before you disclose the vulnerability. + +We also expect you to comply with all applicable laws. You're responsible to pay any taxes associated with your bounties. diff --git a/vendor/automattic/jetpack-status/composer.json b/vendor/automattic/jetpack-status/composer.json new file mode 100644 index 00000000000..94ec5d09160 --- /dev/null +++ b/vendor/automattic/jetpack-status/composer.json @@ -0,0 +1,43 @@ +{ + "name": "automattic/jetpack-status", + "description": "Used to retrieve information about the current status of Jetpack and the site overall.", + "type": "jetpack-library", + "license": "GPL-2.0-or-later", + "require": { + "automattic/jetpack-constants": "^1.6.23" + }, + "require-dev": { + "brain/monkey": "2.6.1", + "yoast/phpunit-polyfills": "1.1.0", + "automattic/jetpack-changelogger": "^3.3.10", + "automattic/jetpack-ip": "^0.1.6" + }, + "suggest": { + "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "scripts": { + "phpunit": [ + "./vendor/phpunit/phpunit/phpunit --colors=always" + ], + "test-php": [ + "@composer phpunit" + ] + }, + "minimum-stability": "dev", + "prefer-stable": true, + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-status", + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-status/compare/v${old}...v${new}" + }, + "branch-alias": { + "dev-trunk": "1.18.x-dev" + } + } +} diff --git a/vendor/automattic/jetpack-status/src/class-cache.php b/vendor/automattic/jetpack-status/src/class-cache.php new file mode 100644 index 00000000000..54fa80d8f04 --- /dev/null +++ b/vendor/automattic/jetpack-status/src/class-cache.php @@ -0,0 +1,54 @@ +admin_url(); + $bits = wp_parse_url( $admin_url ); + + if ( is_array( $bits ) ) { + $path = ( isset( $bits['path'] ) ) ? dirname( $bits['path'] ) : null; + $domain = ( isset( $bits['host'] ) ) ? $bits['host'] : null; + } else { + $path = null; + $domain = null; + } + } + + // Extract state from cookies and delete cookies. + if ( isset( $_COOKIE['jetpackState'] ) && is_array( $_COOKIE['jetpackState'] ) ) { + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- User should sanitize if necessary. + $yum = wp_unslash( $_COOKIE['jetpackState'] ); + unset( $_COOKIE['jetpackState'] ); + foreach ( $yum as $k => $v ) { + if ( strlen( $v ) ) { + $state[ $k ] = $v; + } + setcookie( "jetpackState[$k]", false, 0, $path, $domain, is_ssl(), true ); + } + } + + if ( $restate ) { + foreach ( $state as $k => $v ) { + setcookie( "jetpackState[$k]", $v, 0, $path, $domain, is_ssl(), true ); + } + return; + } + + // Get a state variable. + if ( isset( $key ) && ! isset( $value ) ) { + if ( array_key_exists( $key, $state ) ) { + return $state[ $key ]; + } + return null; + } + + // Set a state variable. + if ( isset( $key ) && isset( $value ) ) { + if ( is_array( $value ) && isset( $value[0] ) ) { + $value = $value[0]; + } + $state[ $key ] = $value; + if ( ! headers_sent() ) { + if ( $this->should_set_cookie( $key ) ) { + setcookie( "jetpackState[$key]", $value, 0, $path, $domain, is_ssl(), true ); + } + } + } + } + + /** + * Determines whether the jetpackState[$key] value should be added to the + * cookie. + * + * @param string $key The state key. + * + * @return boolean Whether the value should be added to the cookie. + */ + public function should_set_cookie( $key ) { + global $current_screen; + $page = isset( $current_screen->base ) ? $current_screen->base : null; + + if ( 'toplevel_page_jetpack' === $page && 'display_update_modal' === $key ) { + return false; + } + + return true; + } +} diff --git a/vendor/automattic/jetpack-status/src/class-errors.php b/vendor/automattic/jetpack-status/src/class-errors.php new file mode 100644 index 00000000000..342f1759f34 --- /dev/null +++ b/vendor/automattic/jetpack-status/src/class-errors.php @@ -0,0 +1,43 @@ +is_atomic_platform() && Constants::is_true( 'WPCOMSH__PLUGIN_FILE' ); + Cache::set( 'is_woa_site', $ret ); + } + return $ret; + } + + /** + * Determine if the site is hosted on the Atomic hosting platform. + * + * @since 1.9.0 + * + * @return bool; + */ + public function is_atomic_platform() { + return Constants::is_true( 'ATOMIC_SITE_ID' ) && Constants::is_true( 'ATOMIC_CLIENT_ID' ); + } + + /** + * Determine if this is a Newspack site. + * + * @return bool + */ + public function is_newspack_site() { + return Constants::is_defined( 'NEWSPACK_PLUGIN_FILE' ); + } + + /** + * Determine if this is a VIP-hosted site. + * + * @return bool + */ + public function is_vip_site() { + return Constants::is_defined( 'WPCOM_IS_VIP_ENV' ) && true === Constants::get_constant( 'WPCOM_IS_VIP_ENV' ); + } + + /** + * Determine if this is a Simple platform site. + * + * @return bool + */ + public function is_wpcom_simple() { + return Constants::is_defined( 'IS_WPCOM' ) && true === Constants::get_constant( 'IS_WPCOM' ); + } + + /** + * Determine if this is a WordPress.com site. + * + * Includes both Simple and WoA platforms. + * + * @return bool + */ + public function is_wpcom_platform() { + return $this->is_wpcom_simple() || $this->is_woa_site(); + } + + /** + * Add all wordpress.com environments to the safe redirect allowed list. + * + * To be used with a filter of allowed domains for a redirect. + * + * @param array $domains Allowed WP.com Environments. + */ + public static function allow_wpcom_environments( $domains ) { + $domains[] = 'wordpress.com'; + $domains[] = 'jetpack.wordpress.com'; + $domains[] = 'wpcalypso.wordpress.com'; + $domains[] = 'horizon.wordpress.com'; + $domains[] = 'calypso.localhost'; + return $domains; + } + + /** + * Return Calypso environment value; used for developing Jetpack and pairing + * it with different Calypso environments, such as localhost. + * + * @since 1.18.0 + * + * @return string Calypso environment + */ + public function get_calypso_env() { + // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Nonce is not required; only used for changing environments. + if ( isset( $_GET['calypso_env'] ) ) { + return sanitize_key( $_GET['calypso_env'] ); + } + // phpcs:enable WordPress.Security.NonceVerification.Recommended + + if ( getenv( 'CALYPSO_ENV' ) ) { + return sanitize_key( getenv( 'CALYPSO_ENV' ) ); + } + + if ( defined( 'CALYPSO_ENV' ) && CALYPSO_ENV ) { + return sanitize_key( CALYPSO_ENV ); + } + + return ''; + } +} diff --git a/vendor/automattic/jetpack-status/src/class-modules.php b/vendor/automattic/jetpack-status/src/class-modules.php new file mode 100644 index 00000000000..fc2ed6fbe8c --- /dev/null +++ b/vendor/automattic/jetpack-status/src/class-modules.php @@ -0,0 +1,600 @@ +get_path( $this->get_slug( $module ) ); + + if ( isset( $modules_details[ $module ] ) ) { + $mod = $modules_details[ $module ]; + } else { + $mod = jetpack_get_module_info( $module ); + + if ( null === $mod ) { + // Try to get the module info from the file as a fallback. + $mod = $this->get_file_data( $file, jetpack_get_all_module_header_names() ); + + if ( empty( $mod['name'] ) ) { + // No info for this module. + return false; + } + } + + $mod['sort'] = empty( $mod['sort'] ) ? 10 : (int) $mod['sort']; + $mod['recommendation_order'] = empty( $mod['recommendation_order'] ) ? 20 : (int) $mod['recommendation_order']; + $mod['deactivate'] = empty( $mod['deactivate'] ); + $mod['free'] = empty( $mod['free'] ); + $mod['requires_connection'] = ( ! empty( $mod['requires_connection'] ) && 'No' === $mod['requires_connection'] ) ? false : true; + $mod['requires_user_connection'] = ( empty( $mod['requires_user_connection'] ) || 'No' === $mod['requires_user_connection'] ) ? false : true; + + if ( empty( $mod['auto_activate'] ) || ! in_array( strtolower( $mod['auto_activate'] ), array( 'yes', 'no', 'public' ), true ) ) { + $mod['auto_activate'] = 'No'; + } else { + $mod['auto_activate'] = (string) $mod['auto_activate']; + } + + if ( $mod['module_tags'] ) { + $mod['module_tags'] = explode( ',', $mod['module_tags'] ); + $mod['module_tags'] = array_map( 'trim', $mod['module_tags'] ); + } else { + $mod['module_tags'] = array( 'Other' ); + } + + if ( $mod['plan_classes'] ) { + $mod['plan_classes'] = explode( ',', $mod['plan_classes'] ); + $mod['plan_classes'] = array_map( 'strtolower', array_map( 'trim', $mod['plan_classes'] ) ); + } else { + $mod['plan_classes'] = array( 'free' ); + } + + if ( $mod['feature'] ) { + $mod['feature'] = explode( ',', $mod['feature'] ); + $mod['feature'] = array_map( 'trim', $mod['feature'] ); + } else { + $mod['feature'] = array( 'Other' ); + } + + $modules_details[ $module ] = $mod; + + } + + /** + * Filters the feature array on a module. + * + * This filter allows you to control where each module is filtered: Recommended, + * and the default "Other" listing. + * + * @since-jetpack 3.5.0 + * + * @param array $mod['feature'] The areas to feature this module: + * 'Recommended' shows on the main Jetpack admin screen. + * 'Other' should be the default if no other value is in the array. + * @param string $module The slug of the module, e.g. sharedaddy. + * @param array $mod All the currently assembled module data. + */ + $mod['feature'] = apply_filters( 'jetpack_module_feature', $mod['feature'], $module, $mod ); + + /** + * Filter the returned data about a module. + * + * This filter allows overriding any info about Jetpack modules. It is dangerous, + * so please be careful. + * + * @since-jetpack 3.6.0 + * + * @param array $mod The details of the requested module. + * @param string $module The slug of the module, e.g. sharedaddy + * @param string $file The path to the module source file. + */ + return apply_filters( 'jetpack_get_module', $mod, $module, $file ); + } + + /** + * Like core's get_file_data implementation, but caches the result. + * + * @param string $file Absolute path to the file. + * @param array $headers List of headers, in the format array( 'HeaderKey' => 'Header Name' ). + */ + public function get_file_data( $file, $headers ) { + // Get just the filename from $file (i.e. exclude full path) so that a consistent hash is generated. + $file_name = basename( $file ); + + if ( ! Constants::is_defined( 'JETPACK__VERSION' ) ) { + return get_file_data( $file, $headers ); + } + + $cache_key = 'jetpack_file_data_' . JETPACK__VERSION; + + $file_data_option = get_transient( $cache_key ); + + if ( ! is_array( $file_data_option ) ) { + delete_transient( $cache_key ); + $file_data_option = false; + } + + if ( false === $file_data_option ) { + $file_data_option = array(); + } + + $key = md5( $file_name . maybe_serialize( $headers ) ); + $refresh_cache = is_admin() && isset( $_GET['page'] ) && 'jetpack' === substr( $_GET['page'], 0, 7 ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput + + // If we don't need to refresh the cache, and already have the value, short-circuit! + if ( ! $refresh_cache && isset( $file_data_option[ $key ] ) ) { + return $file_data_option[ $key ]; + } + + $data = get_file_data( $file, $headers ); + + $file_data_option[ $key ] = $data; + + set_transient( $cache_key, $file_data_option, 29 * DAY_IN_SECONDS ); + + return $data; + } + + /** + * Get a list of activated modules as an array of module slugs. + */ + public function get_active() { + $active = \Jetpack_Options::get_option( 'active_modules' ); + + if ( ! is_array( $active ) ) { + $active = array(); + } + + if ( class_exists( 'VaultPress' ) || function_exists( 'vaultpress_contact_service' ) ) { + $active[] = 'vaultpress'; + } else { + $active = array_diff( $active, array( 'vaultpress' ) ); + } + + // If protect is active on the main site of a multisite, it should be active on all sites. Doesn't apply to WP.com. + if ( ! in_array( 'protect', $active, true ) + && ! ( new Host() )->is_wpcom_simple() + && is_multisite() + && get_site_option( 'jetpack_protect_active' ) ) { + $active[] = 'protect'; + } + + // If it's not available, it shouldn't be active. + // We don't delete it from the options though, as it will be active again when a plugin gets reactivated. + $active = array_intersect( $active, $this->get_available() ); + + /** + * Allow filtering of the active modules. + * + * Gives theme and plugin developers the power to alter the modules that + * are activated on the fly. + * + * @since-jetpack 5.8.0 + * + * @param array $active Array of active module slugs. + */ + $active = apply_filters( 'jetpack_active_modules', $active ); + + return array_unique( $active ); + } + + /** + * Extract a module's slug from its full path. + * + * @param string $file Full path to a file. + * + * @return string Module slug. + */ + public function get_slug( $file ) { + return str_replace( '.php', '', basename( $file ) ); + } + + /** + * List available Jetpack modules. Simply lists .php files in /modules/. + * Make sure to tuck away module "library" files in a sub-directory. + * + * @param bool|string $min_version Only return modules introduced in this version or later. Default is false, do not filter. + * @param bool|string $max_version Only return modules introduced before this version. Default is false, do not filter. + * @param bool|null $requires_connection Pass a boolean value to only return modules that require (or do not require) a connection. + * @param bool|null $requires_user_connection Pass a boolean value to only return modules that require (or do not require) a user connection. + * + * @return array $modules Array of module slugs + */ + public function get_available( $min_version = false, $max_version = false, $requires_connection = null, $requires_user_connection = null ) { + static $modules = null; + + if ( ! class_exists( 'Jetpack' ) || ! Constants::is_defined( 'JETPACK__VERSION' ) || ! Constants::is_defined( 'JETPACK__PLUGIN_DIR' ) ) { + return array_unique( + /** + * Stand alone plugins need to use this filter to register the modules they interact with. + * This will allow them to activate and deactivate these modules even when Jetpack is not present. + * Note: Standalone plugins can only interact with modules that also exist in the Jetpack plugin, otherwise they'll lose the ability to control it if Jetpack is activated. + * + * @since 1.13.6 + * + * @param array $modules The list of available modules as an array of slugs. + * @param bool $requires_connection Whether to list only modules that require a connection to work. + * @param bool $requires_user_connection Whether to list only modules that require a user connection to work. + */ + apply_filters( 'jetpack_get_available_standalone_modules', array(), $requires_connection, $requires_user_connection ) + ); + } + + if ( ! isset( $modules ) ) { + $available_modules_option = \Jetpack_Options::get_option( 'available_modules', array() ); + // Use the cache if we're on the front-end and it's available... + if ( ! is_admin() && ! empty( $available_modules_option[ JETPACK__VERSION ] ) ) { + $modules = $available_modules_option[ JETPACK__VERSION ]; + } else { + $files = ( new Files() )->glob_php( JETPACK__PLUGIN_DIR . 'modules' ); + + $modules = array(); + + foreach ( $files as $file ) { + $slug = $this->get_slug( $file ); + $headers = $this->get( $slug ); + + if ( ! $headers ) { + continue; + } + + $modules[ $slug ] = $headers['introduced']; + } + + \Jetpack_Options::update_option( + 'available_modules', + array( + JETPACK__VERSION => $modules, + ) + ); + } + } + + /** + * Filters the array of modules available to be activated. + * + * @since 2.4.0 + * + * @param array $modules Array of available modules. + * @param string $min_version Minimum version number required to use modules. + * @param string $max_version Maximum version number required to use modules. + * @param bool|null $requires_connection Value of the Requires Connection filter. + * @param bool|null $requires_user_connection Value of the Requires User Connection filter. + */ + $mods = apply_filters( 'jetpack_get_available_modules', $modules, $min_version, $max_version, $requires_connection, $requires_user_connection ); + + if ( ! $min_version && ! $max_version && $requires_connection === null && $requires_user_connection === null ) { + return array_keys( $mods ); + } + + $r = array(); + foreach ( $mods as $slug => $introduced ) { + if ( $min_version && version_compare( $min_version, $introduced, '>=' ) ) { + continue; + } + + if ( $max_version && version_compare( $max_version, $introduced, '<' ) ) { + continue; + } + + $mod_details = $this->get( $slug ); + + if ( null !== $requires_connection && (bool) $requires_connection !== $mod_details['requires_connection'] ) { + continue; + } + + if ( null !== $requires_user_connection && (bool) $requires_user_connection !== $mod_details['requires_user_connection'] ) { + continue; + } + + $r[] = $slug; + } + + return $r; + } + + /** + * Is slug a valid module. + * + * @param string $module Module slug. + * + * @return bool + */ + public function is_module( $module ) { + return ! empty( $module ) && ! validate_file( $module, $this->get_available() ); + } + + /** + * Update module status. + * + * @param string $module - module slug. + * @param boolean $active - true to activate, false to deactivate. + * @param bool $exit Should exit be called after deactivation. + * @param bool $redirect Should there be a redirection after activation. + */ + public function update_status( $module, $active, $exit = true, $redirect = true ) { + return $active ? $this->activate( $module, $exit, $redirect ) : $this->deactivate( $module ); + } + + /** + * Activate a module. + * + * @param string $module Module slug. + * @param bool $exit Should exit be called after deactivation. + * @param bool $redirect Should there be a redirection after activation. + * + * @return bool|void + */ + public function activate( $module, $exit = true, $redirect = true ) { + /** + * Fires before a module is activated. + * + * @since 2.6.0 + * + * @param string $module Module slug. + * @param bool $exit Should we exit after the module has been activated. Default to true. + * @param bool $redirect Should the user be redirected after module activation? Default to true. + */ + do_action( 'jetpack_pre_activate_module', $module, $exit, $redirect ); + + if ( ! strlen( $module ) ) { + return false; + } + + // If it's already active, then don't do it again. + $active = $this->get_active(); + foreach ( $active as $act ) { + if ( $act === $module ) { + return true; + } + } + + if ( ! $this->is_module( $module ) ) { + return false; + } + + // Jetpack plugin only + if ( class_exists( 'Jetpack' ) ) { + + $module_data = $this->get( $module ); + + $status = new Status(); + $state = new CookieState(); + + if ( ! \Jetpack::is_connection_ready() ) { + if ( ! $status->is_offline_mode() && ! $status->is_onboarding() ) { + return false; + } + + // If we're not connected but in offline mode, make sure the module doesn't require a connection. + if ( $status->is_offline_mode() && $module_data['requires_connection'] ) { + return false; + } + } + + if ( class_exists( 'Jetpack_Client_Server' ) ) { + $jetpack = \Jetpack::init(); + + // Check and see if the old plugin is active. + if ( isset( $jetpack->plugins_to_deactivate[ $module ] ) ) { + // Deactivate the old plugins. + $deactivated = array(); + foreach ( $jetpack->plugins_to_deactivate[ $module ] as $idx => $deactivate_me ) { + if ( \Jetpack_Client_Server::deactivate_plugin( $deactivate_me[0], $deactivate_me[1] ) ) { + // If we deactivated the old plugin, remembere that with ::state() and redirect back to this page to activate the module + // We can't activate the module on this page load since the newly deactivated old plugin is still loaded on this page load. + $deactivated[] = "$module:$idx"; + } + } + if ( $deactivated ) { + $state->state( 'deactivated_plugins', implode( ',', $deactivated ) ); + wp_safe_redirect( add_query_arg( 'jetpack_restate', 1 ) ); + exit; + } + } + } + + // Protect won't work with mis-configured IPs. + if ( 'protect' === $module ) { + if ( ! IP_Utils::get_ip() ) { + $state->state( 'message', 'protect_misconfigured_ip' ); + return false; + } + } + + if ( ! Jetpack_Plan::supports( $module ) ) { + return false; + } + + // Check the file for fatal errors, a la wp-admin/plugins.php::activate. + $errors = new Errors(); + $state->state( 'module', $module ); + $state->state( 'error', 'module_activation_failed' ); // we'll override this later if the plugin can be included without fatal error. + $errors->catch_errors( true ); + + ob_start(); + $module_path = $this->get_path( $module ); + if ( file_exists( $module_path ) ) { + require $this->get_path( $module ); // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.NotAbsolutePath + } + + $active[] = $module; + $this->update_active( $active ); + + $state->state( 'error', false ); // the override. + ob_end_clean(); + $errors->catch_errors( false ); + } else { // Not a Jetpack plugin. + $active[] = $module; + $this->update_active( $active ); + } + + if ( $redirect ) { + wp_safe_redirect( ( new Paths() )->admin_url( 'page=jetpack' ) ); + } + if ( $exit ) { + exit; + } + return true; + } + + /** + * Deactivate module. + * + * @param string $module Module slug. + * + * @return bool + */ + public function deactivate( $module ) { + /** + * Fires when a module is deactivated. + * + * @since 1.9.0 + * + * @param string $module Module slug. + */ + do_action( 'jetpack_pre_deactivate_module', $module ); + + $active = $this->get_active(); + $new = array_filter( array_diff( $active, (array) $module ) ); + + return $this->update_active( $new ); + } + + /** + * Generate a module's path from its slug. + * + * @param string $slug Module slug. + */ + public function get_path( $slug ) { + if ( ! Constants::is_defined( 'JETPACK__PLUGIN_DIR' ) ) { + return ''; + } + /** + * Filters the path of a modules. + * + * @since 7.4.0 + * + * @param array $return The absolute path to a module's root php file + * @param string $slug The module slug + */ + return apply_filters( 'jetpack_get_module_path', JETPACK__PLUGIN_DIR . "modules/$slug.php", $slug ); + } + + /** + * Saves all the currently active modules to options. + * Also fires Action hooks for each newly activated and deactivated module. + * + * @param array $modules Array of active modules to be saved in options. + * + * @return $success bool true for success, false for failure. + */ + public function update_active( $modules ) { + $current_modules = \Jetpack_Options::get_option( 'active_modules', array() ); + $active_modules = $this->get_active(); + $new_active_modules = array_diff( $modules, $current_modules ); + $new_inactive_modules = array_diff( $active_modules, $modules ); + $new_current_modules = array_diff( array_merge( $current_modules, $new_active_modules ), $new_inactive_modules ); + $reindexed_modules = array_values( $new_current_modules ); + $success = \Jetpack_Options::update_option( 'active_modules', array_unique( $reindexed_modules ) ); + // Let's take `pre_update_option_jetpack_active_modules` filter into account + // and actually decide for which modules we need to fire hooks by comparing + // the 'active_modules' option before and after the update. + $current_modules_post_update = \Jetpack_Options::get_option( 'active_modules', array() ); + + $new_inactive_modules = array_diff( $current_modules, $current_modules_post_update ); + $new_inactive_modules = array_unique( $new_inactive_modules ); + $new_inactive_modules = array_values( $new_inactive_modules ); + + $new_active_modules = array_diff( $current_modules_post_update, $current_modules ); + $new_active_modules = array_unique( $new_active_modules ); + $new_active_modules = array_values( $new_active_modules ); + + foreach ( $new_active_modules as $module ) { + /** + * Fires when a specific module is activated. + * + * @since 1.9.0 + * + * @param string $module Module slug. + * @param boolean $success whether the module was activated. @since 4.2 + */ + do_action( 'jetpack_activate_module', $module, $success ); + /** + * Fires when a module is activated. + * The dynamic part of the filter, $module, is the module slug. + * + * @since 1.9.0 + * + * @param string $module Module slug. + */ + do_action( "jetpack_activate_module_$module", $module ); + } + + foreach ( $new_inactive_modules as $module ) { + /** + * Fired after a module has been deactivated. + * + * @since 4.2.0 + * + * @param string $module Module slug. + * @param boolean $success whether the module was deactivated. + */ + do_action( 'jetpack_deactivate_module', $module, $success ); + /** + * Fires when a module is deactivated. + * The dynamic part of the filter, $module, is the module slug. + * + * @since 1.9.0 + * + * @param string $module Module slug. + */ + do_action( "jetpack_deactivate_module_$module", $module ); + } + + return $success; + } +} diff --git a/vendor/automattic/jetpack-status/src/class-paths.php b/vendor/automattic/jetpack-status/src/class-paths.php new file mode 100644 index 00000000000..a3313c6626f --- /dev/null +++ b/vendor/automattic/jetpack-status/src/class-paths.php @@ -0,0 +1,28 @@ + 'jetpack' ) ); + $url = add_query_arg( $args, admin_url( 'admin.php' ) ); + return $url; + } +} diff --git a/vendor/automattic/jetpack-status/src/class-status.php b/vendor/automattic/jetpack-status/src/class-status.php new file mode 100644 index 00000000000..b6d4a1e25bb --- /dev/null +++ b/vendor/automattic/jetpack-status/src/class-status.php @@ -0,0 +1,414 @@ +is_offline_mode(). + * + * @return bool Whether Jetpack's offline mode is active. + */ + public function is_development_mode() { + _deprecated_function( __FUNCTION__, '1.3.0', 'Automattic\Jetpack\Status->is_offline_mode' ); + return $this->is_offline_mode(); + } + + /** + * Is Jetpack in offline mode? + * + * This was formerly called "Development Mode", but sites "in development" aren't always offline/localhost. + * + * @since 1.3.0 + * + * @return bool Whether Jetpack's offline mode is active. + */ + public function is_offline_mode() { + $cached = Cache::get( 'is_offline_mode' ); + if ( null !== $cached ) { + return $cached; + } + + $offline_mode = false; + + if ( defined( '\\JETPACK_DEV_DEBUG' ) ) { + $offline_mode = constant( '\\JETPACK_DEV_DEBUG' ); + } elseif ( defined( '\\WP_LOCAL_DEV' ) ) { + $offline_mode = constant( '\\WP_LOCAL_DEV' ); + } elseif ( $this->is_local_site() ) { + $offline_mode = true; + } + + /** + * Filters Jetpack's offline mode. + * + * @see https://jetpack.com/support/development-mode/ + * @todo Update documentation ^^. + * + * @since 1.1.1 + * @since-jetpack 2.2.1 + * @deprecated 1.3.0 + * + * @param bool $offline_mode Is Jetpack's offline mode active. + */ + $offline_mode = (bool) apply_filters_deprecated( 'jetpack_development_mode', array( $offline_mode ), '1.3.0', 'jetpack_offline_mode' ); + + /** + * Filters Jetpack's offline mode. + * + * @see https://jetpack.com/support/development-mode/ + * @todo Update documentation ^^. + * + * @since 1.3.0 + * + * @param bool $offline_mode Is Jetpack's offline mode active. + */ + $offline_mode = (bool) apply_filters( 'jetpack_offline_mode', $offline_mode ); + + Cache::set( 'is_offline_mode', $offline_mode ); + return $offline_mode; + } + + /** + * Is Jetpack in "No User test mode"? + * + * This will make Jetpack act as if there were no connected users, but only a site connection (aka blog token) + * + * @since 1.6.0 + * @deprecated 1.7.5 Since this version, Jetpack connection is considered active after registration, making no_user_testing_mode obsolete. + * + * @return bool Whether Jetpack's No User Testing Mode is active. + */ + public function is_no_user_testing_mode() { + _deprecated_function( __METHOD__, '1.7.5' ); + return true; + } + + /** + * Whether this is a system with a multiple networks. + * Implemented since there is no core is_multi_network function. + * Right now there is no way to tell which network is the dominant network on the system. + * + * @return boolean + */ + public function is_multi_network() { + global $wpdb; + + $cached = Cache::get( 'is_multi_network' ); + if ( null !== $cached ) { + return $cached; + } + + // If we don't have a multi site setup no need to do any more. + if ( ! is_multisite() ) { + Cache::set( 'is_multi_network', false ); + return false; + } + + $num_sites = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->site}" ); + if ( $num_sites > 1 ) { + Cache::set( 'is_multi_network', true ); + return true; + } + + Cache::set( 'is_multi_network', false ); + return false; + } + + /** + * Whether the current site is single user site. + * + * @return bool + */ + public function is_single_user_site() { + global $wpdb; + + $ret = Cache::get( 'is_single_user_site' ); + if ( null === $ret ) { + $some_users = get_transient( 'jetpack_is_single_user' ); + if ( false === $some_users ) { + $some_users = $wpdb->get_var( "SELECT COUNT(*) FROM (SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '{$wpdb->prefix}capabilities' LIMIT 2) AS someusers" ); + set_transient( 'jetpack_is_single_user', (int) $some_users, 12 * HOUR_IN_SECONDS ); + } + $ret = 1 === (int) $some_users; + Cache::set( 'is_single_user_site', $ret ); + } + return $ret; + } + + /** + * If the site is a local site. + * + * @since 1.3.0 + * + * @return bool + */ + public function is_local_site() { + $cached = Cache::get( 'is_local_site' ); + if ( null !== $cached ) { + return $cached; + } + + $site_url = site_url(); + + // Check for localhost and sites using an IP only first. + $is_local = $site_url && false === strpos( $site_url, '.' ); + + // Use Core's environment check, if available. + if ( 'local' === wp_get_environment_type() ) { + $is_local = true; + } + + // Then check for usual usual domains used by local dev tools. + $known_local = array( + '#\.local$#i', + '#\.localhost$#i', + '#\.test$#i', + '#\.docksal$#i', // Docksal. + '#\.docksal\.site$#i', // Docksal. + '#\.dev\.cc$#i', // ServerPress. + '#\.lndo\.site$#i', // Lando. + '#^https?://127\.0\.0\.1$#', + ); + + if ( ! $is_local ) { + foreach ( $known_local as $url ) { + if ( preg_match( $url, $site_url ) ) { + $is_local = true; + break; + } + } + } + + /** + * Filters is_local_site check. + * + * @since 1.3.0 + * + * @param bool $is_local If the current site is a local site. + */ + $is_local = apply_filters( 'jetpack_is_local_site', $is_local ); + + Cache::set( 'is_local_site', $is_local ); + return $is_local; + } + + /** + * If is a staging site. + * + * @todo Add IDC detection to a package. + * + * @return bool + */ + public function is_staging_site() { + $cached = Cache::get( 'is_staging_site' ); + if ( null !== $cached ) { + return $cached; + } + + /* + * Core's wp_get_environment_type allows for a few specific options. + * We should default to bowing out gracefully for anything other than production or local. + */ + $is_staging = ! in_array( wp_get_environment_type(), array( 'production', 'local' ), true ); + + $known_staging = array( + 'urls' => array( + '#\.staging\.wpengine\.com$#i', // WP Engine. This is their legacy staging URL structure. Their new platform does not have a common URL. https://github.com/Automattic/jetpack/issues/21504 + '#\.staging\.kinsta\.com$#i', // Kinsta.com. + '#\.kinsta\.cloud$#i', // Kinsta.com. + '#\.stage\.site$#i', // DreamPress. + '#\.newspackstaging\.com$#i', // Newspack. + '#^(?!live-)([a-zA-Z0-9-]+)\.pantheonsite\.io$#i', // Pantheon. + '#\.flywheelsites\.com$#i', // Flywheel. + '#\.flywheelstaging\.com$#i', // Flywheel. + '#\.cloudwaysapps\.com$#i', // Cloudways. + '#\.azurewebsites\.net$#i', // Azure. + '#\.wpserveur\.net$#i', // WPServeur. + '#\-liquidwebsites\.com$#i', // Liquidweb. + ), + 'constants' => array( + 'IS_WPE_SNAPSHOT', // WP Engine. This is used on their legacy staging environment. Their new platform does not have a constant. https://github.com/Automattic/jetpack/issues/21504 + 'KINSTA_DEV_ENV', // Kinsta.com. + 'WPSTAGECOACH_STAGING', // WP Stagecoach. + 'JETPACK_STAGING_MODE', // Generic. + 'WP_LOCAL_DEV', // Generic. + ), + ); + /** + * Filters the flags of known staging sites. + * + * @since 1.1.1 + * @since-jetpack 3.9.0 + * + * @param array $known_staging { + * An array of arrays that each are used to check if the current site is staging. + * @type array $urls URLs of staging sites in regex to check against site_url. + * @type array $constants PHP constants of known staging/developement environments. + * } + */ + $known_staging = apply_filters( 'jetpack_known_staging', $known_staging ); + + if ( isset( $known_staging['urls'] ) ) { + $site_url = site_url(); + foreach ( $known_staging['urls'] as $url ) { + if ( preg_match( $url, wp_parse_url( $site_url, PHP_URL_HOST ) ) ) { + $is_staging = true; + break; + } + } + } + + if ( isset( $known_staging['constants'] ) ) { + foreach ( $known_staging['constants'] as $constant ) { + if ( defined( $constant ) && constant( $constant ) ) { + $is_staging = true; + } + } + } + + // Last, let's check if sync is erroring due to an IDC. If so, set the site to staging mode. + if ( ! $is_staging && method_exists( 'Automattic\\Jetpack\\Identity_Crisis', 'validate_sync_error_idc_option' ) && \Automattic\Jetpack\Identity_Crisis::validate_sync_error_idc_option() ) { + $is_staging = true; + } + + /** + * Filters is_staging_site check. + * + * @since 1.1.1 + * @since-jetpack 3.9.0 + * + * @param bool $is_staging If the current site is a staging site. + */ + $is_staging = apply_filters( 'jetpack_is_staging_site', $is_staging ); + + Cache::set( 'is_staging_site', $is_staging ); + return $is_staging; + } + + /** + * Whether the site is currently onboarding or not. + * A site is considered as being onboarded if it currently has an onboarding token. + * + * @since-jetpack 5.8 + * + * @access public + * @static + * + * @return bool True if the site is currently onboarding, false otherwise + */ + public function is_onboarding() { + return \Jetpack_Options::get_option( 'onboarding' ) !== false; + } + + /** + * Whether the site is currently private or not. + * On WordPress.com and WoA, sites can be marked as private + * + * @since 1.16.0 + * + * @return bool True if the site is private. + */ + public function is_private_site() { + $ret = Cache::get( 'is_private_site' ); + if ( null === $ret ) { + $is_private_site = '-1' === get_option( 'blog_public' ); + + /** + * Filters the is_private_site check. + * + * @since 1.16.1 + * + * @param bool $is_private_site True if the site is private. + */ + $is_private_site = apply_filters( 'jetpack_is_private_site', $is_private_site ); + + Cache::set( 'is_private_site', $is_private_site ); + return $is_private_site; + } + return $ret; + } + + /** + * Whether the site is currently unlaunched or not. + * On WordPress.com and WoA, sites can be marked as "coming soon", aka unlaunched + * + * @since 1.16.0 + * + * @return bool True if the site is not launched. + */ + public function is_coming_soon() { + $ret = Cache::get( 'is_coming_soon' ); + if ( null === $ret ) { + $is_coming_soon = (bool) ( function_exists( 'site_is_coming_soon' ) && \site_is_coming_soon() ) + || get_option( 'wpcom_public_coming_soon' ); + + /** + * Filters the is_coming_soon check. + * + * @since 1.16.1 + * + * @param bool $is_coming_soon True if the site is coming soon (i.e. unlaunched). + */ + $is_coming_soon = apply_filters( 'jetpack_is_coming_soon', $is_coming_soon ); + + Cache::set( 'is_coming_soon', $is_coming_soon ); + return $is_coming_soon; + } + return $ret; + } + + /** + * Returns the site slug suffix to be used as part of Calypso URLs. + * + * Strips http:// or https:// from a url, replaces forward slash with ::. + * + * @since 1.6.0 + * + * @param string $url Optional. URL to build the site suffix from. Default: Home URL. + * + * @return string + */ + public function get_site_suffix( $url = '' ) { + // On WordPress.com, site suffixes are a bit different. + if ( method_exists( 'WPCOM_Masterbar', 'get_calypso_site_slug' ) ) { + return WPCOM_Masterbar::get_calypso_site_slug( get_current_blog_id() ); + } + + // Grab the 'site_url' option for WoA sites to avoid plugins to interfere with the site + // identifier (e.g. i18n plugins may change the main url to '/', but we + // want to exclude the locale since it's not part of the site suffix). + if ( ( new Host() )->is_woa_site() ) { + $url = \site_url(); + } + + if ( empty( $url ) ) { + // WordPress can be installed in subdirectories (e.g. make.wordpress.org/plugins) + // where the 'site_url' option points to the root domain (e.g. make.wordpress.org) + // which could collide with another site in the same domain but with WordPress + // installed in a different subdirectory (e.g. make.wordpress.org/core). To avoid + // such collision, we identify the site with the 'home_url' option. + $url = \home_url(); + } + + $url = preg_replace( '#^.*?://#', '', $url ); + $url = str_replace( '/', '::', $url ); + + return rtrim( $url, ':' ); + } +} diff --git a/vendor/automattic/jetpack-status/src/class-visitor.php b/vendor/automattic/jetpack-status/src/class-visitor.php new file mode 100644 index 00000000000..518e5029945 --- /dev/null +++ b/vendor/automattic/jetpack-status/src/class-visitor.php @@ -0,0 +1,43 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Autoload; + +/** + * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. + * + * $loader = new \Composer\Autoload\ClassLoader(); + * + * // register classes with namespaces + * $loader->add('Symfony\Component', __DIR__.'/component'); + * $loader->add('Symfony', __DIR__.'/framework'); + * + * // activate the autoloader + * $loader->register(); + * + * // to enable searching the include path (eg. for PEAR packages) + * $loader->setUseIncludePath(true); + * + * In this example, if you try to use a class in the Symfony\Component + * namespace or one of its children (Symfony\Component\Console for instance), + * the autoloader will first look for the class under the component/ + * directory, and it will then fallback to the framework/ directory if not + * found before giving up. + * + * This class is loosely based on the Symfony UniversalClassLoader. + * + * @author Fabien Potencier + * @author Jordi Boggiano + * @see https://www.php-fig.org/psr/psr-0/ + * @see https://www.php-fig.org/psr/psr-4/ + */ +class ClassLoader +{ + /** @var \Closure(string):void */ + private static $includeFile; + + /** @var string|null */ + private $vendorDir; + + // PSR-4 + /** + * @var array> + */ + private $prefixLengthsPsr4 = array(); + /** + * @var array> + */ + private $prefixDirsPsr4 = array(); + /** + * @var list + */ + private $fallbackDirsPsr4 = array(); + + // PSR-0 + /** + * List of PSR-0 prefixes + * + * Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2'))) + * + * @var array>> + */ + private $prefixesPsr0 = array(); + /** + * @var list + */ + private $fallbackDirsPsr0 = array(); + + /** @var bool */ + private $useIncludePath = false; + + /** + * @var array + */ + private $classMap = array(); + + /** @var bool */ + private $classMapAuthoritative = false; + + /** + * @var array + */ + private $missingClasses = array(); + + /** @var string|null */ + private $apcuPrefix; + + /** + * @var array + */ + private static $registeredLoaders = array(); + + /** + * @param string|null $vendorDir + */ + public function __construct($vendorDir = null) + { + $this->vendorDir = $vendorDir; + self::initializeIncludeClosure(); + } + + /** + * @return array> + */ + public function getPrefixes() + { + if (!empty($this->prefixesPsr0)) { + return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); + } + + return array(); + } + + /** + * @return array> + */ + public function getPrefixesPsr4() + { + return $this->prefixDirsPsr4; + } + + /** + * @return list + */ + public function getFallbackDirs() + { + return $this->fallbackDirsPsr0; + } + + /** + * @return list + */ + public function getFallbackDirsPsr4() + { + return $this->fallbackDirsPsr4; + } + + /** + * @return array Array of classname => path + */ + public function getClassMap() + { + return $this->classMap; + } + + /** + * @param array $classMap Class to filename map + * + * @return void + */ + public function addClassMap(array $classMap) + { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } else { + $this->classMap = $classMap; + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, either + * appending or prepending to the ones previously set for this prefix. + * + * @param string $prefix The prefix + * @param list|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories + * + * @return void + */ + public function add($prefix, $paths, $prepend = false) + { + $paths = (array) $paths; + if (!$prefix) { + if ($prepend) { + $this->fallbackDirsPsr0 = array_merge( + $paths, + $this->fallbackDirsPsr0 + ); + } else { + $this->fallbackDirsPsr0 = array_merge( + $this->fallbackDirsPsr0, + $paths + ); + } + + return; + } + + $first = $prefix[0]; + if (!isset($this->prefixesPsr0[$first][$prefix])) { + $this->prefixesPsr0[$first][$prefix] = $paths; + + return; + } + if ($prepend) { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $paths, + $this->prefixesPsr0[$first][$prefix] + ); + } else { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $this->prefixesPsr0[$first][$prefix], + $paths + ); + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, either + * appending or prepending to the ones previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param list|string $paths The PSR-4 base directories + * @param bool $prepend Whether to prepend the directories + * + * @throws \InvalidArgumentException + * + * @return void + */ + public function addPsr4($prefix, $paths, $prepend = false) + { + $paths = (array) $paths; + if (!$prefix) { + // Register directories for the root namespace. + if ($prepend) { + $this->fallbackDirsPsr4 = array_merge( + $paths, + $this->fallbackDirsPsr4 + ); + } else { + $this->fallbackDirsPsr4 = array_merge( + $this->fallbackDirsPsr4, + $paths + ); + } + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { + // Register directories for a new namespace. + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = $paths; + } elseif ($prepend) { + // Prepend directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $paths, + $this->prefixDirsPsr4[$prefix] + ); + } else { + // Append directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $this->prefixDirsPsr4[$prefix], + $paths + ); + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, + * replacing any others previously set for this prefix. + * + * @param string $prefix The prefix + * @param list|string $paths The PSR-0 base directories + * + * @return void + */ + public function set($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr0 = (array) $paths; + } else { + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, + * replacing any others previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param list|string $paths The PSR-4 base directories + * + * @throws \InvalidArgumentException + * + * @return void + */ + public function setPsr4($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr4 = (array) $paths; + } else { + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } + } + + /** + * Turns on searching the include path for class files. + * + * @param bool $useIncludePath + * + * @return void + */ + public function setUseIncludePath($useIncludePath) + { + $this->useIncludePath = $useIncludePath; + } + + /** + * Can be used to check if the autoloader uses the include path to check + * for classes. + * + * @return bool + */ + public function getUseIncludePath() + { + return $this->useIncludePath; + } + + /** + * Turns off searching the prefix and fallback directories for classes + * that have not been registered with the class map. + * + * @param bool $classMapAuthoritative + * + * @return void + */ + public function setClassMapAuthoritative($classMapAuthoritative) + { + $this->classMapAuthoritative = $classMapAuthoritative; + } + + /** + * Should class lookup fail if not found in the current class map? + * + * @return bool + */ + public function isClassMapAuthoritative() + { + return $this->classMapAuthoritative; + } + + /** + * APCu prefix to use to cache found/not-found classes, if the extension is enabled. + * + * @param string|null $apcuPrefix + * + * @return void + */ + public function setApcuPrefix($apcuPrefix) + { + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; + } + + /** + * The APCu prefix in use, or null if APCu caching is not enabled. + * + * @return string|null + */ + public function getApcuPrefix() + { + return $this->apcuPrefix; + } + + /** + * Registers this instance as an autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not + * + * @return void + */ + public function register($prepend = false) + { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + + if (null === $this->vendorDir) { + return; + } + + if ($prepend) { + self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders; + } else { + unset(self::$registeredLoaders[$this->vendorDir]); + self::$registeredLoaders[$this->vendorDir] = $this; + } + } + + /** + * Unregisters this instance as an autoloader. + * + * @return void + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + + if (null !== $this->vendorDir) { + unset(self::$registeredLoaders[$this->vendorDir]); + } + } + + /** + * Loads the given class or interface. + * + * @param string $class The name of the class + * @return true|null True if loaded, null otherwise + */ + public function loadClass($class) + { + if ($file = $this->findFile($class)) { + $includeFile = self::$includeFile; + $includeFile($file); + + return true; + } + + return null; + } + + /** + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * + * @return string|false The path if found, false otherwise + */ + public function findFile($class) + { + // class map lookup + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { + return false; + } + if (null !== $this->apcuPrefix) { + $file = apcu_fetch($this->apcuPrefix.$class, $hit); + if ($hit) { + return $file; + } + } + + $file = $this->findFileWithExtension($class, '.php'); + + // Search for Hack files if we are running on HHVM + if (false === $file && defined('HHVM_VERSION')) { + $file = $this->findFileWithExtension($class, '.hh'); + } + + if (null !== $this->apcuPrefix) { + apcu_add($this->apcuPrefix.$class, $file); + } + + if (false === $file) { + // Remember that this class does not exist. + $this->missingClasses[$class] = true; + } + + return $file; + } + + /** + * Returns the currently registered loaders keyed by their corresponding vendor directories. + * + * @return array + */ + public static function getRegisteredLoaders() + { + return self::$registeredLoaders; + } + + /** + * @param string $class + * @param string $ext + * @return string|false + */ + private function findFileWithExtension($class, $ext) + { + // PSR-4 lookup + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; + + $first = $class[0]; + if (isset($this->prefixLengthsPsr4[$first])) { + $subPath = $class; + while (false !== $lastPos = strrpos($subPath, '\\')) { + $subPath = substr($subPath, 0, $lastPos); + $search = $subPath . '\\'; + if (isset($this->prefixDirsPsr4[$search])) { + $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); + foreach ($this->prefixDirsPsr4[$search] as $dir) { + if (file_exists($file = $dir . $pathEnd)) { + return $file; + } + } + } + } + } + + // PSR-4 fallback dirs + foreach ($this->fallbackDirsPsr4 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + return $file; + } + } + + // PSR-0 lookup + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); + } else { + // PEAR-like class name + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; + } + + if (isset($this->prefixesPsr0[$first])) { + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + } + } + } + + // PSR-0 fallback dirs + foreach ($this->fallbackDirsPsr0 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + + // PSR-0 include paths. + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { + return $file; + } + + return false; + } + + /** + * @return void + */ + private static function initializeIncludeClosure() + { + if (self::$includeFile !== null) { + return; + } + + /** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + * + * @param string $file + * @return void + */ + self::$includeFile = \Closure::bind(static function($file) { + include $file; + }, null, null); + } +} diff --git a/vendor/composer/InstalledVersions.php b/vendor/composer/InstalledVersions.php new file mode 100644 index 00000000000..51e734a774b --- /dev/null +++ b/vendor/composer/InstalledVersions.php @@ -0,0 +1,359 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer; + +use Composer\Autoload\ClassLoader; +use Composer\Semver\VersionParser; + +/** + * This class is copied in every Composer installed project and available to all + * + * See also https://getcomposer.org/doc/07-runtime.md#installed-versions + * + * To require its presence, you can require `composer-runtime-api ^2.0` + * + * @final + */ +class InstalledVersions +{ + /** + * @var mixed[]|null + * @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array}|array{}|null + */ + private static $installed; + + /** + * @var bool|null + */ + private static $canGetVendors; + + /** + * @var array[] + * @psalm-var array}> + */ + private static $installedByVendor = array(); + + /** + * Returns a list of all package names which are present, either by being installed, replaced or provided + * + * @return string[] + * @psalm-return list + */ + public static function getInstalledPackages() + { + $packages = array(); + foreach (self::getInstalled() as $installed) { + $packages[] = array_keys($installed['versions']); + } + + if (1 === \count($packages)) { + return $packages[0]; + } + + return array_keys(array_flip(\call_user_func_array('array_merge', $packages))); + } + + /** + * Returns a list of all package names with a specific type e.g. 'library' + * + * @param string $type + * @return string[] + * @psalm-return list + */ + public static function getInstalledPackagesByType($type) + { + $packagesByType = array(); + + foreach (self::getInstalled() as $installed) { + foreach ($installed['versions'] as $name => $package) { + if (isset($package['type']) && $package['type'] === $type) { + $packagesByType[] = $name; + } + } + } + + return $packagesByType; + } + + /** + * Checks whether the given package is installed + * + * This also returns true if the package name is provided or replaced by another package + * + * @param string $packageName + * @param bool $includeDevRequirements + * @return bool + */ + public static function isInstalled($packageName, $includeDevRequirements = true) + { + foreach (self::getInstalled() as $installed) { + if (isset($installed['versions'][$packageName])) { + return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false; + } + } + + return false; + } + + /** + * Checks whether the given package satisfies a version constraint + * + * e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call: + * + * Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3') + * + * @param VersionParser $parser Install composer/semver to have access to this class and functionality + * @param string $packageName + * @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package + * @return bool + */ + public static function satisfies(VersionParser $parser, $packageName, $constraint) + { + $constraint = $parser->parseConstraints((string) $constraint); + $provided = $parser->parseConstraints(self::getVersionRanges($packageName)); + + return $provided->matches($constraint); + } + + /** + * Returns a version constraint representing all the range(s) which are installed for a given package + * + * It is easier to use this via isInstalled() with the $constraint argument if you need to check + * whether a given version of a package is installed, and not just whether it exists + * + * @param string $packageName + * @return string Version constraint usable with composer/semver + */ + public static function getVersionRanges($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + $ranges = array(); + if (isset($installed['versions'][$packageName]['pretty_version'])) { + $ranges[] = $installed['versions'][$packageName]['pretty_version']; + } + if (array_key_exists('aliases', $installed['versions'][$packageName])) { + $ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']); + } + if (array_key_exists('replaced', $installed['versions'][$packageName])) { + $ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']); + } + if (array_key_exists('provided', $installed['versions'][$packageName])) { + $ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']); + } + + return implode(' || ', $ranges); + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @param string $packageName + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present + */ + public static function getVersion($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + if (!isset($installed['versions'][$packageName]['version'])) { + return null; + } + + return $installed['versions'][$packageName]['version']; + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @param string $packageName + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present + */ + public static function getPrettyVersion($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + if (!isset($installed['versions'][$packageName]['pretty_version'])) { + return null; + } + + return $installed['versions'][$packageName]['pretty_version']; + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @param string $packageName + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference + */ + public static function getReference($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + if (!isset($installed['versions'][$packageName]['reference'])) { + return null; + } + + return $installed['versions'][$packageName]['reference']; + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @param string $packageName + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path. + */ + public static function getInstallPath($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null; + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @return array + * @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool} + */ + public static function getRootPackage() + { + $installed = self::getInstalled(); + + return $installed[0]['root']; + } + + /** + * Returns the raw installed.php data for custom implementations + * + * @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect. + * @return array[] + * @psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} + */ + public static function getRawData() + { + @trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED); + + if (null === self::$installed) { + // only require the installed.php file if this file is loaded from its dumped location, + // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 + if (substr(__DIR__, -8, 1) !== 'C') { + self::$installed = include __DIR__ . '/installed.php'; + } else { + self::$installed = array(); + } + } + + return self::$installed; + } + + /** + * Returns the raw data of all installed.php which are currently loaded for custom implementations + * + * @return array[] + * @psalm-return list}> + */ + public static function getAllRawData() + { + return self::getInstalled(); + } + + /** + * Lets you reload the static array from another file + * + * This is only useful for complex integrations in which a project needs to use + * this class but then also needs to execute another project's autoloader in process, + * and wants to ensure both projects have access to their version of installed.php. + * + * A typical case would be PHPUnit, where it would need to make sure it reads all + * the data it needs from this class, then call reload() with + * `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure + * the project in which it runs can then also use this class safely, without + * interference between PHPUnit's dependencies and the project's dependencies. + * + * @param array[] $data A vendor/composer/installed.php data set + * @return void + * + * @psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} $data + */ + public static function reload($data) + { + self::$installed = $data; + self::$installedByVendor = array(); + } + + /** + * @return array[] + * @psalm-return list}> + */ + private static function getInstalled() + { + if (null === self::$canGetVendors) { + self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders'); + } + + $installed = array(); + + if (self::$canGetVendors) { + foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) { + if (isset(self::$installedByVendor[$vendorDir])) { + $installed[] = self::$installedByVendor[$vendorDir]; + } elseif (is_file($vendorDir.'/composer/installed.php')) { + /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} $required */ + $required = require $vendorDir.'/composer/installed.php'; + $installed[] = self::$installedByVendor[$vendorDir] = $required; + if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) { + self::$installed = $installed[count($installed) - 1]; + } + } + } + } + + if (null === self::$installed) { + // only require the installed.php file if this file is loaded from its dumped location, + // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 + if (substr(__DIR__, -8, 1) !== 'C') { + /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} $required */ + $required = require __DIR__ . '/installed.php'; + self::$installed = $required; + } else { + self::$installed = array(); + } + } + + if (self::$installed !== array()) { + $installed[] = self::$installed; + } + + return $installed; + } +} diff --git a/vendor/composer/LICENSE b/vendor/composer/LICENSE new file mode 100644 index 00000000000..f27399a042d --- /dev/null +++ b/vendor/composer/LICENSE @@ -0,0 +1,21 @@ + +Copyright (c) Nils Adermann, Jordi Boggiano + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php new file mode 100644 index 00000000000..8cee87cd9b1 --- /dev/null +++ b/vendor/composer/autoload_classmap.php @@ -0,0 +1,59 @@ + $vendorDir . '/automattic/jetpack-a8c-mc-stats/src/class-a8c-mc-stats.php', + 'Automattic\\Jetpack\\Admin_UI\\Admin_Menu' => $vendorDir . '/automattic/jetpack-admin-ui/src/class-admin-menu.php', + 'Automattic\\Jetpack\\Autoloader\\AutoloadGenerator' => $vendorDir . '/automattic/jetpack-autoloader/src/AutoloadGenerator.php', + 'Automattic\\Jetpack\\Config' => $vendorDir . '/automattic/jetpack-config/src/class-config.php', + 'Automattic\\Jetpack\\Connection\\Client' => $vendorDir . '/automattic/jetpack-connection/src/class-client.php', + 'Automattic\\Jetpack\\Connection\\Connection_Notice' => $vendorDir . '/automattic/jetpack-connection/src/class-connection-notice.php', + 'Automattic\\Jetpack\\Connection\\Error_Handler' => $vendorDir . '/automattic/jetpack-connection/src/class-error-handler.php', + 'Automattic\\Jetpack\\Connection\\Initial_State' => $vendorDir . '/automattic/jetpack-connection/src/class-initial-state.php', + 'Automattic\\Jetpack\\Connection\\Manager' => $vendorDir . '/automattic/jetpack-connection/src/class-manager.php', + 'Automattic\\Jetpack\\Connection\\Manager_Interface' => $vendorDir . '/automattic/jetpack-connection/src/interface-manager.php', + 'Automattic\\Jetpack\\Connection\\Nonce_Handler' => $vendorDir . '/automattic/jetpack-connection/src/class-nonce-handler.php', + 'Automattic\\Jetpack\\Connection\\Package_Version' => $vendorDir . '/automattic/jetpack-connection/src/class-package-version.php', + 'Automattic\\Jetpack\\Connection\\Package_Version_Tracker' => $vendorDir . '/automattic/jetpack-connection/src/class-package-version-tracker.php', + 'Automattic\\Jetpack\\Connection\\Plugin' => $vendorDir . '/automattic/jetpack-connection/src/class-plugin.php', + 'Automattic\\Jetpack\\Connection\\Plugin_Storage' => $vendorDir . '/automattic/jetpack-connection/src/class-plugin-storage.php', + 'Automattic\\Jetpack\\Connection\\REST_Connector' => $vendorDir . '/automattic/jetpack-connection/src/class-rest-connector.php', + 'Automattic\\Jetpack\\Connection\\Rest_Authentication' => $vendorDir . '/automattic/jetpack-connection/src/class-rest-authentication.php', + 'Automattic\\Jetpack\\Connection\\Secrets' => $vendorDir . '/automattic/jetpack-connection/src/class-secrets.php', + 'Automattic\\Jetpack\\Connection\\Server_Sandbox' => $vendorDir . '/automattic/jetpack-connection/src/class-server-sandbox.php', + 'Automattic\\Jetpack\\Connection\\Tokens' => $vendorDir . '/automattic/jetpack-connection/src/class-tokens.php', + 'Automattic\\Jetpack\\Connection\\Tokens_Locks' => $vendorDir . '/automattic/jetpack-connection/src/class-tokens-locks.php', + 'Automattic\\Jetpack\\Connection\\Urls' => $vendorDir . '/automattic/jetpack-connection/src/class-urls.php', + 'Automattic\\Jetpack\\Connection\\Utils' => $vendorDir . '/automattic/jetpack-connection/src/class-utils.php', + 'Automattic\\Jetpack\\Connection\\Webhooks' => $vendorDir . '/automattic/jetpack-connection/src/class-webhooks.php', + 'Automattic\\Jetpack\\Connection\\Webhooks\\Authorize_Redirect' => $vendorDir . '/automattic/jetpack-connection/src/webhooks/class-authorize-redirect.php', + 'Automattic\\Jetpack\\Connection\\XMLRPC_Async_Call' => $vendorDir . '/automattic/jetpack-connection/src/class-xmlrpc-async-call.php', + 'Automattic\\Jetpack\\Connection\\XMLRPC_Connector' => $vendorDir . '/automattic/jetpack-connection/src/class-xmlrpc-connector.php', + 'Automattic\\Jetpack\\Constants' => $vendorDir . '/automattic/jetpack-constants/src/class-constants.php', + 'Automattic\\Jetpack\\CookieState' => $vendorDir . '/automattic/jetpack-status/src/class-cookiestate.php', + 'Automattic\\Jetpack\\Errors' => $vendorDir . '/automattic/jetpack-status/src/class-errors.php', + 'Automattic\\Jetpack\\Files' => $vendorDir . '/automattic/jetpack-status/src/class-files.php', + 'Automattic\\Jetpack\\Heartbeat' => $vendorDir . '/automattic/jetpack-connection/src/class-heartbeat.php', + 'Automattic\\Jetpack\\Modules' => $vendorDir . '/automattic/jetpack-status/src/class-modules.php', + 'Automattic\\Jetpack\\Paths' => $vendorDir . '/automattic/jetpack-status/src/class-paths.php', + 'Automattic\\Jetpack\\Redirect' => $vendorDir . '/automattic/jetpack-redirect/src/class-redirect.php', + 'Automattic\\Jetpack\\Roles' => $vendorDir . '/automattic/jetpack-roles/src/class-roles.php', + 'Automattic\\Jetpack\\Status' => $vendorDir . '/automattic/jetpack-status/src/class-status.php', + 'Automattic\\Jetpack\\Status\\Cache' => $vendorDir . '/automattic/jetpack-status/src/class-cache.php', + 'Automattic\\Jetpack\\Status\\Host' => $vendorDir . '/automattic/jetpack-status/src/class-host.php', + 'Automattic\\Jetpack\\Status\\Visitor' => $vendorDir . '/automattic/jetpack-status/src/class-visitor.php', + 'Automattic\\Jetpack\\Terms_Of_Service' => $vendorDir . '/automattic/jetpack-connection/src/class-terms-of-service.php', + 'Automattic\\Jetpack\\Tracking' => $vendorDir . '/automattic/jetpack-connection/src/class-tracking.php', + 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', + 'Jetpack_IXR_Client' => $vendorDir . '/automattic/jetpack-connection/legacy/class-jetpack-ixr-client.php', + 'Jetpack_IXR_ClientMulticall' => $vendorDir . '/automattic/jetpack-connection/legacy/class-jetpack-ixr-clientmulticall.php', + 'Jetpack_Options' => $vendorDir . '/automattic/jetpack-connection/legacy/class-jetpack-options.php', + 'Jetpack_Signature' => $vendorDir . '/automattic/jetpack-connection/legacy/class-jetpack-signature.php', + 'Jetpack_Tracks_Client' => $vendorDir . '/automattic/jetpack-connection/legacy/class-jetpack-tracks-client.php', + 'Jetpack_Tracks_Event' => $vendorDir . '/automattic/jetpack-connection/legacy/class-jetpack-tracks-event.php', + 'Jetpack_XMLRPC_Server' => $vendorDir . '/automattic/jetpack-connection/legacy/class-jetpack-xmlrpc-server.php', +); diff --git a/vendor/composer/autoload_files.php b/vendor/composer/autoload_files.php new file mode 100644 index 00000000000..de9c4642a4d --- /dev/null +++ b/vendor/composer/autoload_files.php @@ -0,0 +1,11 @@ + $baseDir . '/src/StoreApi/deprecated.php', + 'd0f16a186498c2ba04f1d0064fecf9cf' => $baseDir . '/src/StoreApi/functions.php', +); diff --git a/vendor/composer/autoload_namespaces.php b/vendor/composer/autoload_namespaces.php new file mode 100644 index 00000000000..15a2ff3ad6d --- /dev/null +++ b/vendor/composer/autoload_namespaces.php @@ -0,0 +1,9 @@ + array($vendorDir . '/composer/installers/src/Composer/Installers'), + 'Automattic\\WooCommerce\\StoreApi\\' => array($baseDir . '/src/StoreApi'), + 'Automattic\\WooCommerce\\Blocks\\' => array($baseDir . '/src'), + 'Automattic\\Jetpack\\Autoloader\\' => array($vendorDir . '/automattic/jetpack-autoloader/src'), +); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php new file mode 100644 index 00000000000..bde89d258c3 --- /dev/null +++ b/vendor/composer/autoload_real.php @@ -0,0 +1,48 @@ +register(true); + + $filesToLoad = \Composer\Autoload\ComposerStaticInita6bdab1bc9adbc0f5ee69199fa6cade3::$files; + $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { + if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { + $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; + + require $file; + } + }, null, null); + foreach ($filesToLoad as $fileIdentifier => $file) { + $requireFile($fileIdentifier, $file); + } + + return $loader; + } +} diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php new file mode 100644 index 00000000000..9080178d715 --- /dev/null +++ b/vendor/composer/autoload_static.php @@ -0,0 +1,108 @@ + __DIR__ . '/../..' . '/src/StoreApi/deprecated.php', + 'd0f16a186498c2ba04f1d0064fecf9cf' => __DIR__ . '/../..' . '/src/StoreApi/functions.php', + ); + + public static $prefixLengthsPsr4 = array ( + 'C' => + array ( + 'Composer\\Installers\\' => 20, + ), + 'A' => + array ( + 'Automattic\\WooCommerce\\StoreApi\\' => 32, + 'Automattic\\WooCommerce\\Blocks\\' => 30, + 'Automattic\\Jetpack\\Autoloader\\' => 30, + ), + ); + + public static $prefixDirsPsr4 = array ( + 'Composer\\Installers\\' => + array ( + 0 => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers', + ), + 'Automattic\\WooCommerce\\StoreApi\\' => + array ( + 0 => __DIR__ . '/../..' . '/src/StoreApi', + ), + 'Automattic\\WooCommerce\\Blocks\\' => + array ( + 0 => __DIR__ . '/../..' . '/src', + ), + 'Automattic\\Jetpack\\Autoloader\\' => + array ( + 0 => __DIR__ . '/..' . '/automattic/jetpack-autoloader/src', + ), + ); + + public static $classMap = array ( + 'Automattic\\Jetpack\\A8c_Mc_Stats' => __DIR__ . '/..' . '/automattic/jetpack-a8c-mc-stats/src/class-a8c-mc-stats.php', + 'Automattic\\Jetpack\\Admin_UI\\Admin_Menu' => __DIR__ . '/..' . '/automattic/jetpack-admin-ui/src/class-admin-menu.php', + 'Automattic\\Jetpack\\Autoloader\\AutoloadGenerator' => __DIR__ . '/..' . '/automattic/jetpack-autoloader/src/AutoloadGenerator.php', + 'Automattic\\Jetpack\\Config' => __DIR__ . '/..' . '/automattic/jetpack-config/src/class-config.php', + 'Automattic\\Jetpack\\Connection\\Client' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-client.php', + 'Automattic\\Jetpack\\Connection\\Connection_Notice' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-connection-notice.php', + 'Automattic\\Jetpack\\Connection\\Error_Handler' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-error-handler.php', + 'Automattic\\Jetpack\\Connection\\Initial_State' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-initial-state.php', + 'Automattic\\Jetpack\\Connection\\Manager' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-manager.php', + 'Automattic\\Jetpack\\Connection\\Manager_Interface' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/interface-manager.php', + 'Automattic\\Jetpack\\Connection\\Nonce_Handler' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-nonce-handler.php', + 'Automattic\\Jetpack\\Connection\\Package_Version' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-package-version.php', + 'Automattic\\Jetpack\\Connection\\Package_Version_Tracker' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-package-version-tracker.php', + 'Automattic\\Jetpack\\Connection\\Plugin' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-plugin.php', + 'Automattic\\Jetpack\\Connection\\Plugin_Storage' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-plugin-storage.php', + 'Automattic\\Jetpack\\Connection\\REST_Connector' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-rest-connector.php', + 'Automattic\\Jetpack\\Connection\\Rest_Authentication' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-rest-authentication.php', + 'Automattic\\Jetpack\\Connection\\Secrets' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-secrets.php', + 'Automattic\\Jetpack\\Connection\\Server_Sandbox' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-server-sandbox.php', + 'Automattic\\Jetpack\\Connection\\Tokens' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-tokens.php', + 'Automattic\\Jetpack\\Connection\\Tokens_Locks' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-tokens-locks.php', + 'Automattic\\Jetpack\\Connection\\Urls' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-urls.php', + 'Automattic\\Jetpack\\Connection\\Utils' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-utils.php', + 'Automattic\\Jetpack\\Connection\\Webhooks' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-webhooks.php', + 'Automattic\\Jetpack\\Connection\\Webhooks\\Authorize_Redirect' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/webhooks/class-authorize-redirect.php', + 'Automattic\\Jetpack\\Connection\\XMLRPC_Async_Call' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-xmlrpc-async-call.php', + 'Automattic\\Jetpack\\Connection\\XMLRPC_Connector' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-xmlrpc-connector.php', + 'Automattic\\Jetpack\\Constants' => __DIR__ . '/..' . '/automattic/jetpack-constants/src/class-constants.php', + 'Automattic\\Jetpack\\CookieState' => __DIR__ . '/..' . '/automattic/jetpack-status/src/class-cookiestate.php', + 'Automattic\\Jetpack\\Errors' => __DIR__ . '/..' . '/automattic/jetpack-status/src/class-errors.php', + 'Automattic\\Jetpack\\Files' => __DIR__ . '/..' . '/automattic/jetpack-status/src/class-files.php', + 'Automattic\\Jetpack\\Heartbeat' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-heartbeat.php', + 'Automattic\\Jetpack\\Modules' => __DIR__ . '/..' . '/automattic/jetpack-status/src/class-modules.php', + 'Automattic\\Jetpack\\Paths' => __DIR__ . '/..' . '/automattic/jetpack-status/src/class-paths.php', + 'Automattic\\Jetpack\\Redirect' => __DIR__ . '/..' . '/automattic/jetpack-redirect/src/class-redirect.php', + 'Automattic\\Jetpack\\Roles' => __DIR__ . '/..' . '/automattic/jetpack-roles/src/class-roles.php', + 'Automattic\\Jetpack\\Status' => __DIR__ . '/..' . '/automattic/jetpack-status/src/class-status.php', + 'Automattic\\Jetpack\\Status\\Cache' => __DIR__ . '/..' . '/automattic/jetpack-status/src/class-cache.php', + 'Automattic\\Jetpack\\Status\\Host' => __DIR__ . '/..' . '/automattic/jetpack-status/src/class-host.php', + 'Automattic\\Jetpack\\Status\\Visitor' => __DIR__ . '/..' . '/automattic/jetpack-status/src/class-visitor.php', + 'Automattic\\Jetpack\\Terms_Of_Service' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-terms-of-service.php', + 'Automattic\\Jetpack\\Tracking' => __DIR__ . '/..' . '/automattic/jetpack-connection/src/class-tracking.php', + 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', + 'Jetpack_IXR_Client' => __DIR__ . '/..' . '/automattic/jetpack-connection/legacy/class-jetpack-ixr-client.php', + 'Jetpack_IXR_ClientMulticall' => __DIR__ . '/..' . '/automattic/jetpack-connection/legacy/class-jetpack-ixr-clientmulticall.php', + 'Jetpack_Options' => __DIR__ . '/..' . '/automattic/jetpack-connection/legacy/class-jetpack-options.php', + 'Jetpack_Signature' => __DIR__ . '/..' . '/automattic/jetpack-connection/legacy/class-jetpack-signature.php', + 'Jetpack_Tracks_Client' => __DIR__ . '/..' . '/automattic/jetpack-connection/legacy/class-jetpack-tracks-client.php', + 'Jetpack_Tracks_Event' => __DIR__ . '/..' . '/automattic/jetpack-connection/legacy/class-jetpack-tracks-event.php', + 'Jetpack_XMLRPC_Server' => __DIR__ . '/..' . '/automattic/jetpack-connection/legacy/class-jetpack-xmlrpc-server.php', + ); + + public static function getInitializer(ClassLoader $loader) + { + return \Closure::bind(function () use ($loader) { + $loader->prefixLengthsPsr4 = ComposerStaticInita6bdab1bc9adbc0f5ee69199fa6cade3::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInita6bdab1bc9adbc0f5ee69199fa6cade3::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInita6bdab1bc9adbc0f5ee69199fa6cade3::$classMap; + + }, null, ClassLoader::class); + } +} diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json new file mode 100644 index 00000000000..7747aa48f98 --- /dev/null +++ b/vendor/composer/installed.json @@ -0,0 +1,658 @@ +{ + "packages": [ + { + "name": "automattic/jetpack-a8c-mc-stats", + "version": "v1.4.22", + "version_normalized": "1.4.22.0", + "source": { + "type": "git", + "url": "https://github.com/Automattic/jetpack-a8c-mc-stats.git", + "reference": "d7fdf2fc7ae33d75e24e82d81269e33ec718446f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Automattic/jetpack-a8c-mc-stats/zipball/d7fdf2fc7ae33d75e24e82d81269e33ec718446f", + "reference": "d7fdf2fc7ae33d75e24e82d81269e33ec718446f", + "shasum": "" + }, + "require-dev": { + "automattic/jetpack-changelogger": "^3.3.9", + "yoast/phpunit-polyfills": "1.1.0" + }, + "suggest": { + "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." + }, + "time": "2023-09-19T18:18:33+00:00", + "type": "jetpack-library", + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-a8c-mc-stats", + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-a8c-mc-stats/compare/v${old}...v${new}" + }, + "branch-alias": { + "dev-trunk": "1.4.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "description": "Used to record internal usage stats for Automattic. Not visible to site owners.", + "support": { + "source": "https://github.com/Automattic/jetpack-a8c-mc-stats/tree/v1.4.22" + }, + "install-path": "../automattic/jetpack-a8c-mc-stats" + }, + { + "name": "automattic/jetpack-admin-ui", + "version": "v0.2.23", + "version_normalized": "0.2.23.0", + "source": { + "type": "git", + "url": "https://github.com/Automattic/jetpack-admin-ui.git", + "reference": "2684f3ee3b458074d95e727e70ae994802501688" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Automattic/jetpack-admin-ui/zipball/2684f3ee3b458074d95e727e70ae994802501688", + "reference": "2684f3ee3b458074d95e727e70ae994802501688", + "shasum": "" + }, + "require-dev": { + "automattic/jetpack-changelogger": "^3.3.9", + "automattic/jetpack-logo": "^1.6.3", + "automattic/wordbless": "dev-master", + "yoast/phpunit-polyfills": "1.1.0" + }, + "suggest": { + "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." + }, + "time": "2023-09-19T18:19:10+00:00", + "type": "jetpack-library", + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-admin-ui", + "textdomain": "jetpack-admin-ui", + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-admin-ui/compare/${old}...${new}" + }, + "branch-alias": { + "dev-trunk": "0.2.x-dev" + }, + "version-constants": { + "::PACKAGE_VERSION": "src/class-admin-menu.php" + } + }, + "installation-source": "dist", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "description": "Generic Jetpack wp-admin UI elements", + "support": { + "source": "https://github.com/Automattic/jetpack-admin-ui/tree/v0.2.23" + }, + "install-path": "../automattic/jetpack-admin-ui" + }, + { + "name": "automattic/jetpack-autoloader", + "version": "v2.12.0", + "version_normalized": "2.12.0.0", + "source": { + "type": "git", + "url": "https://github.com/Automattic/jetpack-autoloader.git", + "reference": "632b69cfc73ed5505f2b03165e7f68d414d0da12" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Automattic/jetpack-autoloader/zipball/632b69cfc73ed5505f2b03165e7f68d414d0da12", + "reference": "632b69cfc73ed5505f2b03165e7f68d414d0da12", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.1 || ^2.0" + }, + "require-dev": { + "automattic/jetpack-changelogger": "^3.3.11", + "yoast/phpunit-polyfills": "1.1.0" + }, + "time": "2023-09-28T18:33:34+00:00", + "type": "composer-plugin", + "extra": { + "autotagger": true, + "class": "Automattic\\Jetpack\\Autoloader\\CustomAutoloaderPlugin", + "mirror-repo": "Automattic/jetpack-autoloader", + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-autoloader/compare/v${old}...v${new}" + }, + "version-constants": { + "::VERSION": "src/AutoloadGenerator.php" + }, + "branch-alias": { + "dev-trunk": "2.12.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Automattic\\Jetpack\\Autoloader\\": "src" + }, + "classmap": [ + "src/AutoloadGenerator.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "description": "Creates a custom autoloader for a plugin or theme.", + "keywords": [ + "autoload", + "autoloader", + "composer", + "jetpack", + "plugin", + "wordpress" + ], + "support": { + "source": "https://github.com/Automattic/jetpack-autoloader/tree/v2.12.0" + }, + "install-path": "../automattic/jetpack-autoloader" + }, + { + "name": "automattic/jetpack-config", + "version": "v1.15.4", + "version_normalized": "1.15.4.0", + "source": { + "type": "git", + "url": "https://github.com/Automattic/jetpack-config.git", + "reference": "6cf8d61a972530322c9b62f7375fff83342c38f9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Automattic/jetpack-config/zipball/6cf8d61a972530322c9b62f7375fff83342c38f9", + "reference": "6cf8d61a972530322c9b62f7375fff83342c38f9", + "shasum": "" + }, + "require-dev": { + "automattic/jetpack-changelogger": "^3.3.9" + }, + "suggest": { + "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." + }, + "time": "2023-09-19T18:18:30+00:00", + "type": "jetpack-library", + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-config", + "textdomain": "jetpack-config", + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-config/compare/v${old}...v${new}" + }, + "branch-alias": { + "dev-trunk": "1.15.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "description": "Jetpack configuration package that initializes other packages and configures Jetpack's functionality. Can be used as a base for all variants of Jetpack package usage.", + "support": { + "source": "https://github.com/Automattic/jetpack-config/tree/v1.15.4" + }, + "install-path": "../automattic/jetpack-config" + }, + { + "name": "automattic/jetpack-connection", + "version": "v1.58.1", + "version_normalized": "1.58.1.0", + "source": { + "type": "git", + "url": "https://github.com/Automattic/jetpack-connection.git", + "reference": "f578d8fe7ef6fdb9ecd60c64645cac8bc6809a89" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Automattic/jetpack-connection/zipball/f578d8fe7ef6fdb9ecd60c64645cac8bc6809a89", + "reference": "f578d8fe7ef6fdb9ecd60c64645cac8bc6809a89", + "shasum": "" + }, + "require": { + "automattic/jetpack-a8c-mc-stats": "^1.4.22", + "automattic/jetpack-admin-ui": "^0.2.23", + "automattic/jetpack-constants": "^1.6.23", + "automattic/jetpack-redirect": "^1.7.27", + "automattic/jetpack-roles": "^1.4.25", + "automattic/jetpack-status": "^1.18.5" + }, + "require-dev": { + "automattic/jetpack-changelogger": "^3.3.11", + "automattic/wordbless": "@dev", + "brain/monkey": "2.6.1", + "yoast/phpunit-polyfills": "1.1.0" + }, + "suggest": { + "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." + }, + "time": "2023-10-10T18:50:27+00:00", + "type": "jetpack-library", + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-connection", + "textdomain": "jetpack-connection", + "version-constants": { + "::PACKAGE_VERSION": "src/class-package-version.php" + }, + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-connection/compare/v${old}...v${new}" + }, + "branch-alias": { + "dev-trunk": "1.58.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "classmap": [ + "legacy", + "src/", + "src/webhooks" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "description": "Everything needed to connect to the Jetpack infrastructure", + "support": { + "source": "https://github.com/Automattic/jetpack-connection/tree/v1.58.1" + }, + "install-path": "../automattic/jetpack-connection" + }, + { + "name": "automattic/jetpack-constants", + "version": "v1.6.23", + "version_normalized": "1.6.23.0", + "source": { + "type": "git", + "url": "https://github.com/Automattic/jetpack-constants.git", + "reference": "0825fb1fa94956f26adebc01be0d716a0fd3ade0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Automattic/jetpack-constants/zipball/0825fb1fa94956f26adebc01be0d716a0fd3ade0", + "reference": "0825fb1fa94956f26adebc01be0d716a0fd3ade0", + "shasum": "" + }, + "require-dev": { + "automattic/jetpack-changelogger": "^3.3.8", + "brain/monkey": "2.6.1", + "yoast/phpunit-polyfills": "1.1.0" + }, + "suggest": { + "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." + }, + "time": "2023-08-23T17:56:35+00:00", + "type": "jetpack-library", + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-constants", + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-constants/compare/v${old}...v${new}" + }, + "branch-alias": { + "dev-trunk": "1.6.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "description": "A wrapper for defining constants in a more testable way.", + "support": { + "source": "https://github.com/Automattic/jetpack-constants/tree/v1.6.23" + }, + "install-path": "../automattic/jetpack-constants" + }, + { + "name": "automattic/jetpack-redirect", + "version": "v1.7.27", + "version_normalized": "1.7.27.0", + "source": { + "type": "git", + "url": "https://github.com/Automattic/jetpack-redirect.git", + "reference": "43dd3ae2bef71281fe70f62733bfaa44c988f1b1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Automattic/jetpack-redirect/zipball/43dd3ae2bef71281fe70f62733bfaa44c988f1b1", + "reference": "43dd3ae2bef71281fe70f62733bfaa44c988f1b1", + "shasum": "" + }, + "require": { + "automattic/jetpack-status": "^1.18.4" + }, + "require-dev": { + "automattic/jetpack-changelogger": "^3.3.9", + "brain/monkey": "2.6.1", + "yoast/phpunit-polyfills": "1.1.0" + }, + "suggest": { + "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." + }, + "time": "2023-09-19T18:19:22+00:00", + "type": "jetpack-library", + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-redirect", + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-redirect/compare/v${old}...v${new}" + }, + "branch-alias": { + "dev-trunk": "1.7.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "description": "Utilities to build URLs to the jetpack.com/redirect/ service", + "support": { + "source": "https://github.com/Automattic/jetpack-redirect/tree/v1.7.27" + }, + "install-path": "../automattic/jetpack-redirect" + }, + { + "name": "automattic/jetpack-roles", + "version": "v1.4.25", + "version_normalized": "1.4.25.0", + "source": { + "type": "git", + "url": "https://github.com/Automattic/jetpack-roles.git", + "reference": "708b33f16a879fc2ab5939a972c968c9aeefbe38" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Automattic/jetpack-roles/zipball/708b33f16a879fc2ab5939a972c968c9aeefbe38", + "reference": "708b33f16a879fc2ab5939a972c968c9aeefbe38", + "shasum": "" + }, + "require-dev": { + "automattic/jetpack-changelogger": "^3.3.9", + "brain/monkey": "2.6.1", + "yoast/phpunit-polyfills": "1.1.0" + }, + "suggest": { + "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." + }, + "time": "2023-09-19T18:18:38+00:00", + "type": "jetpack-library", + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-roles", + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-roles/compare/v${old}...v${new}" + }, + "branch-alias": { + "dev-trunk": "1.4.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "description": "Utilities, related with user roles and capabilities.", + "support": { + "source": "https://github.com/Automattic/jetpack-roles/tree/v1.4.25" + }, + "install-path": "../automattic/jetpack-roles" + }, + { + "name": "automattic/jetpack-status", + "version": "v1.18.5", + "version_normalized": "1.18.5.0", + "source": { + "type": "git", + "url": "https://github.com/Automattic/jetpack-status.git", + "reference": "fe08772e2005b8cd78ec5e0d416b73a04ae57c10" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Automattic/jetpack-status/zipball/fe08772e2005b8cd78ec5e0d416b73a04ae57c10", + "reference": "fe08772e2005b8cd78ec5e0d416b73a04ae57c10", + "shasum": "" + }, + "require": { + "automattic/jetpack-constants": "^1.6.23" + }, + "require-dev": { + "automattic/jetpack-changelogger": "^3.3.10", + "automattic/jetpack-ip": "^0.1.6", + "brain/monkey": "2.6.1", + "yoast/phpunit-polyfills": "1.1.0" + }, + "suggest": { + "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." + }, + "time": "2023-09-25T19:07:29+00:00", + "type": "jetpack-library", + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-status", + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-status/compare/v${old}...v${new}" + }, + "branch-alias": { + "dev-trunk": "1.18.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "description": "Used to retrieve information about the current status of Jetpack and the site overall.", + "support": { + "source": "https://github.com/Automattic/jetpack-status/tree/v1.18.5" + }, + "install-path": "../automattic/jetpack-status" + }, + { + "name": "composer/installers", + "version": "v1.12.0", + "version_normalized": "1.12.0.0", + "source": { + "type": "git", + "url": "https://github.com/composer/installers.git", + "reference": "d20a64ed3c94748397ff5973488761b22f6d3f19" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/installers/zipball/d20a64ed3c94748397ff5973488761b22f6d3f19", + "reference": "d20a64ed3c94748397ff5973488761b22f6d3f19", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0" + }, + "replace": { + "roundcube/plugin-installer": "*", + "shama/baton": "*" + }, + "require-dev": { + "composer/composer": "1.6.* || ^2.0", + "composer/semver": "^1 || ^3", + "phpstan/phpstan": "^0.12.55", + "phpstan/phpstan-phpunit": "^0.12.16", + "symfony/phpunit-bridge": "^4.2 || ^5", + "symfony/process": "^2.3" + }, + "time": "2021-09-13T08:19:44+00:00", + "type": "composer-plugin", + "extra": { + "class": "Composer\\Installers\\Plugin", + "branch-alias": { + "dev-main": "1.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Composer\\Installers\\": "src/Composer/Installers" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kyle Robinson Young", + "email": "kyle@dontkry.com", + "homepage": "https://github.com/shama" + } + ], + "description": "A multi-framework Composer library installer", + "homepage": "https://composer.github.io/installers/", + "keywords": [ + "Craft", + "Dolibarr", + "Eliasis", + "Hurad", + "ImageCMS", + "Kanboard", + "Lan Management System", + "MODX Evo", + "MantisBT", + "Mautic", + "Maya", + "OXID", + "Plentymarkets", + "Porto", + "RadPHP", + "SMF", + "Starbug", + "Thelia", + "Whmcs", + "WolfCMS", + "agl", + "aimeos", + "annotatecms", + "attogram", + "bitrix", + "cakephp", + "chef", + "cockpit", + "codeigniter", + "concrete5", + "croogo", + "dokuwiki", + "drupal", + "eZ Platform", + "elgg", + "expressionengine", + "fuelphp", + "grav", + "installer", + "itop", + "joomla", + "known", + "kohana", + "laravel", + "lavalite", + "lithium", + "magento", + "majima", + "mako", + "mediawiki", + "miaoxing", + "modulework", + "modx", + "moodle", + "osclass", + "pantheon", + "phpbb", + "piwik", + "ppi", + "processwire", + "puppet", + "pxcms", + "reindex", + "roundcube", + "shopware", + "silverstripe", + "sydes", + "sylius", + "symfony", + "tastyigniter", + "typo3", + "wordpress", + "yawik", + "zend", + "zikula" + ], + "support": { + "issues": "https://github.com/composer/installers/issues", + "source": "https://github.com/composer/installers/tree/v1.12.0" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "install-path": "./installers" + } + ], + "dev": false, + "dev-package-names": [] +} diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php new file mode 100644 index 00000000000..92dde64e815 --- /dev/null +++ b/vendor/composer/installed.php @@ -0,0 +1,125 @@ + array( + 'name' => 'woocommerce/woocommerce-blocks', + 'pretty_version' => '11.4.0', + 'version' => '11.4.0.0', + 'reference' => NULL, + 'type' => 'wordpress-plugin', + 'install_path' => __DIR__ . '/../../', + 'aliases' => array(), + 'dev' => false, + ), + 'versions' => array( + 'automattic/jetpack-a8c-mc-stats' => array( + 'pretty_version' => 'v1.4.22', + 'version' => '1.4.22.0', + 'reference' => 'd7fdf2fc7ae33d75e24e82d81269e33ec718446f', + 'type' => 'jetpack-library', + 'install_path' => __DIR__ . '/../automattic/jetpack-a8c-mc-stats', + 'aliases' => array(), + 'dev_requirement' => false, + ), + 'automattic/jetpack-admin-ui' => array( + 'pretty_version' => 'v0.2.23', + 'version' => '0.2.23.0', + 'reference' => '2684f3ee3b458074d95e727e70ae994802501688', + 'type' => 'jetpack-library', + 'install_path' => __DIR__ . '/../automattic/jetpack-admin-ui', + 'aliases' => array(), + 'dev_requirement' => false, + ), + 'automattic/jetpack-autoloader' => array( + 'pretty_version' => 'v2.12.0', + 'version' => '2.12.0.0', + 'reference' => '632b69cfc73ed5505f2b03165e7f68d414d0da12', + 'type' => 'composer-plugin', + 'install_path' => __DIR__ . '/../automattic/jetpack-autoloader', + 'aliases' => array(), + 'dev_requirement' => false, + ), + 'automattic/jetpack-config' => array( + 'pretty_version' => 'v1.15.4', + 'version' => '1.15.4.0', + 'reference' => '6cf8d61a972530322c9b62f7375fff83342c38f9', + 'type' => 'jetpack-library', + 'install_path' => __DIR__ . '/../automattic/jetpack-config', + 'aliases' => array(), + 'dev_requirement' => false, + ), + 'automattic/jetpack-connection' => array( + 'pretty_version' => 'v1.58.1', + 'version' => '1.58.1.0', + 'reference' => 'f578d8fe7ef6fdb9ecd60c64645cac8bc6809a89', + 'type' => 'jetpack-library', + 'install_path' => __DIR__ . '/../automattic/jetpack-connection', + 'aliases' => array(), + 'dev_requirement' => false, + ), + 'automattic/jetpack-constants' => array( + 'pretty_version' => 'v1.6.23', + 'version' => '1.6.23.0', + 'reference' => '0825fb1fa94956f26adebc01be0d716a0fd3ade0', + 'type' => 'jetpack-library', + 'install_path' => __DIR__ . '/../automattic/jetpack-constants', + 'aliases' => array(), + 'dev_requirement' => false, + ), + 'automattic/jetpack-redirect' => array( + 'pretty_version' => 'v1.7.27', + 'version' => '1.7.27.0', + 'reference' => '43dd3ae2bef71281fe70f62733bfaa44c988f1b1', + 'type' => 'jetpack-library', + 'install_path' => __DIR__ . '/../automattic/jetpack-redirect', + 'aliases' => array(), + 'dev_requirement' => false, + ), + 'automattic/jetpack-roles' => array( + 'pretty_version' => 'v1.4.25', + 'version' => '1.4.25.0', + 'reference' => '708b33f16a879fc2ab5939a972c968c9aeefbe38', + 'type' => 'jetpack-library', + 'install_path' => __DIR__ . '/../automattic/jetpack-roles', + 'aliases' => array(), + 'dev_requirement' => false, + ), + 'automattic/jetpack-status' => array( + 'pretty_version' => 'v1.18.5', + 'version' => '1.18.5.0', + 'reference' => 'fe08772e2005b8cd78ec5e0d416b73a04ae57c10', + 'type' => 'jetpack-library', + 'install_path' => __DIR__ . '/../automattic/jetpack-status', + 'aliases' => array(), + 'dev_requirement' => false, + ), + 'composer/installers' => array( + 'pretty_version' => 'v1.12.0', + 'version' => '1.12.0.0', + 'reference' => 'd20a64ed3c94748397ff5973488761b22f6d3f19', + 'type' => 'composer-plugin', + 'install_path' => __DIR__ . '/./installers', + 'aliases' => array(), + 'dev_requirement' => false, + ), + 'roundcube/plugin-installer' => array( + 'dev_requirement' => false, + 'replaced' => array( + 0 => '*', + ), + ), + 'shama/baton' => array( + 'dev_requirement' => false, + 'replaced' => array( + 0 => '*', + ), + ), + 'woocommerce/woocommerce-blocks' => array( + 'pretty_version' => '11.4.0', + 'version' => '11.4.0.0', + 'reference' => NULL, + 'type' => 'wordpress-plugin', + 'install_path' => __DIR__ . '/../../', + 'aliases' => array(), + 'dev_requirement' => false, + ), + ), +); diff --git a/vendor/composer/installers/.github/workflows/continuous-integration.yml b/vendor/composer/installers/.github/workflows/continuous-integration.yml new file mode 100644 index 00000000000..34b8f91fcef --- /dev/null +++ b/vendor/composer/installers/.github/workflows/continuous-integration.yml @@ -0,0 +1,76 @@ +name: "Continuous Integration" + +on: + - push + - pull_request + +env: + COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist" + SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT: "1" + +jobs: + tests: + name: "CI" + + runs-on: ubuntu-latest + + strategy: + matrix: + php-version: + - "5.3" + - "5.4" + - "5.5" + - "5.6" + - "7.0" + - "7.1" + - "7.2" + - "7.3" + - "7.4" + - "8.0" + - "8.1" + dependencies: [locked] + include: + - php-version: "5.3" + dependencies: lowest + - php-version: "8.1" + dependencies: lowest + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + tools: composer:snapshot + + - name: Get composer cache directory + id: composercache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composercache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - name: "Handle lowest dependencies update" + if: "contains(matrix.dependencies, 'lowest')" + run: "echo \"COMPOSER_FLAGS=$COMPOSER_FLAGS --prefer-lowest\" >> $GITHUB_ENV" + + - name: "Upgrade phpunit-bridge if needed for php 8 lowest build" + if: "contains(matrix.php-version, '8.')" + run: | + composer require symfony/phpunit-bridge:^5.3.3 --dev --no-update + + - name: "Install latest dependencies" + run: | + # Remove PHPStan as it requires a newer PHP + composer remove phpstan/phpstan phpstan/phpstan-phpunit --dev --no-update + composer update ${{ env.COMPOSER_FLAGS }} + + - name: "Run tests" + run: "vendor/bin/simple-phpunit --verbose" diff --git a/vendor/composer/installers/.github/workflows/lint.yml b/vendor/composer/installers/.github/workflows/lint.yml new file mode 100644 index 00000000000..81a1ac4d4bc --- /dev/null +++ b/vendor/composer/installers/.github/workflows/lint.yml @@ -0,0 +1,30 @@ +name: "PHP Lint" + +on: + - push + - pull_request + +jobs: + tests: + name: "Lint" + + runs-on: ubuntu-latest + + strategy: + matrix: + php-version: + - "5.3" + - "8.0" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + + - name: "Lint PHP files" + run: "find src/ -type f -name '*.php' -print0 | xargs -0 -L1 -P4 -- php -l -f" diff --git a/vendor/composer/installers/.github/workflows/phpstan.yml b/vendor/composer/installers/.github/workflows/phpstan.yml new file mode 100644 index 00000000000..ac4c4a92c4c --- /dev/null +++ b/vendor/composer/installers/.github/workflows/phpstan.yml @@ -0,0 +1,51 @@ +name: "PHPStan" + +on: + - push + - pull_request + +env: + COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist" + SYMFONY_PHPUNIT_VERSION: "" + +jobs: + tests: + name: "PHPStan" + + runs-on: ubuntu-latest + + strategy: + matrix: + php-version: + # pinned to 7.4 because we need PHPUnit 7.5 which does not support PHP 8 + - "7.4" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + + - name: Get composer cache directory + id: composercache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composercache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - name: "Install latest dependencies" + run: "composer update ${{ env.COMPOSER_FLAGS }}" + + - name: Run PHPStan + # Locked to phpunit 7.5 here as newer ones have void return types which break inheritance + run: | + composer require --dev phpunit/phpunit:^7.5.20 --with-all-dependencies ${{ env.COMPOSER_FLAGS }} + vendor/bin/phpstan analyse diff --git a/vendor/composer/installers/LICENSE b/vendor/composer/installers/LICENSE new file mode 100644 index 00000000000..85f97fc7951 --- /dev/null +++ b/vendor/composer/installers/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2012 Kyle Robinson Young + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/vendor/composer/installers/composer.json b/vendor/composer/installers/composer.json new file mode 100644 index 00000000000..4a7fd3c3106 --- /dev/null +++ b/vendor/composer/installers/composer.json @@ -0,0 +1,122 @@ +{ + "name": "composer/installers", + "type": "composer-plugin", + "license": "MIT", + "description": "A multi-framework Composer library installer", + "keywords": [ + "installer", + "Aimeos", + "AGL", + "AnnotateCms", + "Attogram", + "Bitrix", + "CakePHP", + "Chef", + "Cockpit", + "CodeIgniter", + "concrete5", + "Craft", + "Croogo", + "DokuWiki", + "Dolibarr", + "Drupal", + "Elgg", + "Eliasis", + "ExpressionEngine", + "eZ Platform", + "FuelPHP", + "Grav", + "Hurad", + "ImageCMS", + "iTop", + "Joomla", + "Kanboard", + "Known", + "Kohana", + "Lan Management System", + "Laravel", + "Lavalite", + "Lithium", + "Magento", + "majima", + "Mako", + "MantisBT", + "Mautic", + "Maya", + "MODX", + "MODX Evo", + "MediaWiki", + "Miaoxing", + "OXID", + "osclass", + "MODULEWork", + "Moodle", + "Pantheon", + "Piwik", + "pxcms", + "phpBB", + "Plentymarkets", + "PPI", + "Puppet", + "Porto", + "ProcessWire", + "RadPHP", + "ReIndex", + "Roundcube", + "shopware", + "SilverStripe", + "SMF", + "Starbug", + "SyDES", + "Sylius", + "symfony", + "TastyIgniter", + "Thelia", + "TYPO3", + "WHMCS", + "WolfCMS", + "WordPress", + "YAWIK", + "Zend", + "Zikula" + ], + "homepage": "https://composer.github.io/installers/", + "authors": [ + { + "name": "Kyle Robinson Young", + "email": "kyle@dontkry.com", + "homepage": "https://github.com/shama" + } + ], + "autoload": { + "psr-4": { "Composer\\Installers\\": "src/Composer/Installers" } + }, + "autoload-dev": { + "psr-4": { "Composer\\Installers\\Test\\": "tests/Composer/Installers/Test" } + }, + "extra": { + "class": "Composer\\Installers\\Plugin", + "branch-alias": { + "dev-main": "1.x-dev" + } + }, + "replace": { + "shama/baton": "*", + "roundcube/plugin-installer": "*" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0" + }, + "require-dev": { + "composer/composer": "1.6.* || ^2.0", + "composer/semver": "^1 || ^3", + "symfony/phpunit-bridge": "^4.2 || ^5", + "phpstan/phpstan": "^0.12.55", + "symfony/process": "^2.3", + "phpstan/phpstan-phpunit": "^0.12.16" + }, + "scripts": { + "test": "SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT=1 vendor/bin/simple-phpunit", + "phpstan": "vendor/bin/phpstan analyse" + } +} diff --git a/vendor/composer/installers/phpstan.neon.dist b/vendor/composer/installers/phpstan.neon.dist new file mode 100644 index 00000000000..8e3d81e9a19 --- /dev/null +++ b/vendor/composer/installers/phpstan.neon.dist @@ -0,0 +1,10 @@ +parameters: + level: 5 + paths: + - src + - tests + excludes_analyse: + - tests/Composer/Installers/Test/PolyfillTestCase.php + +includes: + - vendor/phpstan/phpstan-phpunit/extension.neon diff --git a/vendor/composer/installers/src/Composer/Installers/AglInstaller.php b/vendor/composer/installers/src/Composer/Installers/AglInstaller.php new file mode 100644 index 00000000000..01b8a416592 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/AglInstaller.php @@ -0,0 +1,21 @@ + 'More/{$name}/', + ); + + /** + * Format package name to CamelCase + */ + public function inflectPackageVars($vars) + { + $vars['name'] = preg_replace_callback('/(?:^|_|-)(.?)/', function ($matches) { + return strtoupper($matches[1]); + }, $vars['name']); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/AimeosInstaller.php b/vendor/composer/installers/src/Composer/Installers/AimeosInstaller.php new file mode 100644 index 00000000000..79a0e958fd4 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/AimeosInstaller.php @@ -0,0 +1,9 @@ + 'ext/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/AnnotateCmsInstaller.php b/vendor/composer/installers/src/Composer/Installers/AnnotateCmsInstaller.php new file mode 100644 index 00000000000..89d7ad9057d --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/AnnotateCmsInstaller.php @@ -0,0 +1,11 @@ + 'addons/modules/{$name}/', + 'component' => 'addons/components/{$name}/', + 'service' => 'addons/services/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/AsgardInstaller.php b/vendor/composer/installers/src/Composer/Installers/AsgardInstaller.php new file mode 100644 index 00000000000..22dad1b9a01 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/AsgardInstaller.php @@ -0,0 +1,49 @@ + 'Modules/{$name}/', + 'theme' => 'Themes/{$name}/' + ); + + /** + * Format package name. + * + * For package type asgard-module, cut off a trailing '-plugin' if present. + * + * For package type asgard-theme, cut off a trailing '-theme' if present. + * + */ + public function inflectPackageVars($vars) + { + if ($vars['type'] === 'asgard-module') { + return $this->inflectPluginVars($vars); + } + + if ($vars['type'] === 'asgard-theme') { + return $this->inflectThemeVars($vars); + } + + return $vars; + } + + protected function inflectPluginVars($vars) + { + $vars['name'] = preg_replace('/-module$/', '', $vars['name']); + $vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']); + $vars['name'] = str_replace(' ', '', ucwords($vars['name'])); + + return $vars; + } + + protected function inflectThemeVars($vars) + { + $vars['name'] = preg_replace('/-theme$/', '', $vars['name']); + $vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']); + $vars['name'] = str_replace(' ', '', ucwords($vars['name'])); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/AttogramInstaller.php b/vendor/composer/installers/src/Composer/Installers/AttogramInstaller.php new file mode 100644 index 00000000000..d62fd8fd1e1 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/AttogramInstaller.php @@ -0,0 +1,9 @@ + 'modules/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/BaseInstaller.php b/vendor/composer/installers/src/Composer/Installers/BaseInstaller.php new file mode 100644 index 00000000000..70dde907ed3 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/BaseInstaller.php @@ -0,0 +1,137 @@ +composer = $composer; + $this->package = $package; + $this->io = $io; + } + + /** + * Return the install path based on package type. + * + * @param PackageInterface $package + * @param string $frameworkType + * @return string + */ + public function getInstallPath(PackageInterface $package, $frameworkType = '') + { + $type = $this->package->getType(); + + $prettyName = $this->package->getPrettyName(); + if (strpos($prettyName, '/') !== false) { + list($vendor, $name) = explode('/', $prettyName); + } else { + $vendor = ''; + $name = $prettyName; + } + + $availableVars = $this->inflectPackageVars(compact('name', 'vendor', 'type')); + + $extra = $package->getExtra(); + if (!empty($extra['installer-name'])) { + $availableVars['name'] = $extra['installer-name']; + } + + if ($this->composer->getPackage()) { + $extra = $this->composer->getPackage()->getExtra(); + if (!empty($extra['installer-paths'])) { + $customPath = $this->mapCustomInstallPaths($extra['installer-paths'], $prettyName, $type, $vendor); + if ($customPath !== false) { + return $this->templatePath($customPath, $availableVars); + } + } + } + + $packageType = substr($type, strlen($frameworkType) + 1); + $locations = $this->getLocations(); + if (!isset($locations[$packageType])) { + throw new \InvalidArgumentException(sprintf('Package type "%s" is not supported', $type)); + } + + return $this->templatePath($locations[$packageType], $availableVars); + } + + /** + * For an installer to override to modify the vars per installer. + * + * @param array $vars This will normally receive array{name: string, vendor: string, type: string} + * @return array + */ + public function inflectPackageVars($vars) + { + return $vars; + } + + /** + * Gets the installer's locations + * + * @return array map of package types => install path + */ + public function getLocations() + { + return $this->locations; + } + + /** + * Replace vars in a path + * + * @param string $path + * @param array $vars + * @return string + */ + protected function templatePath($path, array $vars = array()) + { + if (strpos($path, '{') !== false) { + extract($vars); + preg_match_all('@\{\$([A-Za-z0-9_]*)\}@i', $path, $matches); + if (!empty($matches[1])) { + foreach ($matches[1] as $var) { + $path = str_replace('{$' . $var . '}', $$var, $path); + } + } + } + + return $path; + } + + /** + * Search through a passed paths array for a custom install path. + * + * @param array $paths + * @param string $name + * @param string $type + * @param string $vendor = NULL + * @return string|false + */ + protected function mapCustomInstallPaths(array $paths, $name, $type, $vendor = NULL) + { + foreach ($paths as $path => $names) { + $names = (array) $names; + if (in_array($name, $names) || in_array('type:' . $type, $names) || in_array('vendor:' . $vendor, $names)) { + return $path; + } + } + + return false; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/BitrixInstaller.php b/vendor/composer/installers/src/Composer/Installers/BitrixInstaller.php new file mode 100644 index 00000000000..e80cd1e109f --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/BitrixInstaller.php @@ -0,0 +1,126 @@ +.`. + * - `bitrix-d7-component` — copy the component to directory `bitrix/components//`. + * - `bitrix-d7-template` — copy the template to directory `bitrix/templates/_`. + * + * You can set custom path to directory with Bitrix kernel in `composer.json`: + * + * ```json + * { + * "extra": { + * "bitrix-dir": "s1/bitrix" + * } + * } + * ``` + * + * @author Nik Samokhvalov + * @author Denis Kulichkin + */ +class BitrixInstaller extends BaseInstaller +{ + protected $locations = array( + 'module' => '{$bitrix_dir}/modules/{$name}/', // deprecated, remove on the major release (Backward compatibility will be broken) + 'component' => '{$bitrix_dir}/components/{$name}/', // deprecated, remove on the major release (Backward compatibility will be broken) + 'theme' => '{$bitrix_dir}/templates/{$name}/', // deprecated, remove on the major release (Backward compatibility will be broken) + 'd7-module' => '{$bitrix_dir}/modules/{$vendor}.{$name}/', + 'd7-component' => '{$bitrix_dir}/components/{$vendor}/{$name}/', + 'd7-template' => '{$bitrix_dir}/templates/{$vendor}_{$name}/', + ); + + /** + * @var array Storage for informations about duplicates at all the time of installation packages. + */ + private static $checkedDuplicates = array(); + + /** + * {@inheritdoc} + */ + public function inflectPackageVars($vars) + { + if ($this->composer->getPackage()) { + $extra = $this->composer->getPackage()->getExtra(); + + if (isset($extra['bitrix-dir'])) { + $vars['bitrix_dir'] = $extra['bitrix-dir']; + } + } + + if (!isset($vars['bitrix_dir'])) { + $vars['bitrix_dir'] = 'bitrix'; + } + + return parent::inflectPackageVars($vars); + } + + /** + * {@inheritdoc} + */ + protected function templatePath($path, array $vars = array()) + { + $templatePath = parent::templatePath($path, $vars); + $this->checkDuplicates($templatePath, $vars); + + return $templatePath; + } + + /** + * Duplicates search packages. + * + * @param string $path + * @param array $vars + */ + protected function checkDuplicates($path, array $vars = array()) + { + $packageType = substr($vars['type'], strlen('bitrix') + 1); + $localDir = explode('/', $vars['bitrix_dir']); + array_pop($localDir); + $localDir[] = 'local'; + $localDir = implode('/', $localDir); + + $oldPath = str_replace( + array('{$bitrix_dir}', '{$name}'), + array($localDir, $vars['name']), + $this->locations[$packageType] + ); + + if (in_array($oldPath, static::$checkedDuplicates)) { + return; + } + + if ($oldPath !== $path && file_exists($oldPath) && $this->io && $this->io->isInteractive()) { + + $this->io->writeError(' Duplication of packages:'); + $this->io->writeError(' Package ' . $oldPath . ' will be called instead package ' . $path . ''); + + while (true) { + switch ($this->io->ask(' Delete ' . $oldPath . ' [y,n,?]? ', '?')) { + case 'y': + $fs = new Filesystem(); + $fs->removeDirectory($oldPath); + break 2; + + case 'n': + break 2; + + case '?': + default: + $this->io->writeError(array( + ' y - delete package ' . $oldPath . ' and to continue with the installation', + ' n - don\'t delete and to continue with the installation', + )); + $this->io->writeError(' ? - print help'); + break; + } + } + } + + static::$checkedDuplicates[] = $oldPath; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/BonefishInstaller.php b/vendor/composer/installers/src/Composer/Installers/BonefishInstaller.php new file mode 100644 index 00000000000..da3aad2a3bf --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/BonefishInstaller.php @@ -0,0 +1,9 @@ + 'Packages/{$vendor}/{$name}/' + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/CakePHPInstaller.php b/vendor/composer/installers/src/Composer/Installers/CakePHPInstaller.php new file mode 100644 index 00000000000..1e2ddd022cf --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/CakePHPInstaller.php @@ -0,0 +1,66 @@ + 'Plugin/{$name}/', + ); + + /** + * Format package name to CamelCase + */ + public function inflectPackageVars($vars) + { + if ($this->matchesCakeVersion('>=', '3.0.0')) { + return $vars; + } + + $nameParts = explode('/', $vars['name']); + foreach ($nameParts as &$value) { + $value = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $value)); + $value = str_replace(array('-', '_'), ' ', $value); + $value = str_replace(' ', '', ucwords($value)); + } + $vars['name'] = implode('/', $nameParts); + + return $vars; + } + + /** + * Change the default plugin location when cakephp >= 3.0 + */ + public function getLocations() + { + if ($this->matchesCakeVersion('>=', '3.0.0')) { + $this->locations['plugin'] = $this->composer->getConfig()->get('vendor-dir') . '/{$vendor}/{$name}/'; + } + return $this->locations; + } + + /** + * Check if CakePHP version matches against a version + * + * @param string $matcher + * @param string $version + * @return bool + * @phpstan-param Constraint::STR_OP_* $matcher + */ + protected function matchesCakeVersion($matcher, $version) + { + $repositoryManager = $this->composer->getRepositoryManager(); + if (! $repositoryManager) { + return false; + } + + $repos = $repositoryManager->getLocalRepository(); + if (!$repos) { + return false; + } + + return $repos->findPackage('cakephp/cakephp', new Constraint($matcher, $version)) !== null; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/ChefInstaller.php b/vendor/composer/installers/src/Composer/Installers/ChefInstaller.php new file mode 100644 index 00000000000..ab2f9aad807 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/ChefInstaller.php @@ -0,0 +1,11 @@ + 'Chef/{$vendor}/{$name}/', + 'role' => 'Chef/roles/{$name}/', + ); +} + diff --git a/vendor/composer/installers/src/Composer/Installers/CiviCrmInstaller.php b/vendor/composer/installers/src/Composer/Installers/CiviCrmInstaller.php new file mode 100644 index 00000000000..6673aea94ba --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/CiviCrmInstaller.php @@ -0,0 +1,9 @@ + 'ext/{$name}/' + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/ClanCatsFrameworkInstaller.php b/vendor/composer/installers/src/Composer/Installers/ClanCatsFrameworkInstaller.php new file mode 100644 index 00000000000..c887815c95a --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/ClanCatsFrameworkInstaller.php @@ -0,0 +1,10 @@ + 'CCF/orbit/{$name}/', + 'theme' => 'CCF/app/themes/{$name}/', + ); +} \ No newline at end of file diff --git a/vendor/composer/installers/src/Composer/Installers/CockpitInstaller.php b/vendor/composer/installers/src/Composer/Installers/CockpitInstaller.php new file mode 100644 index 00000000000..053f3ffd764 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/CockpitInstaller.php @@ -0,0 +1,32 @@ + 'cockpit/modules/addons/{$name}/', + ); + + /** + * Format module name. + * + * Strip `module-` prefix from package name. + * + * {@inheritDoc} + */ + public function inflectPackageVars($vars) + { + if ($vars['type'] == 'cockpit-module') { + return $this->inflectModuleVars($vars); + } + + return $vars; + } + + public function inflectModuleVars($vars) + { + $vars['name'] = ucfirst(preg_replace('/cockpit-/i', '', $vars['name'])); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/CodeIgniterInstaller.php b/vendor/composer/installers/src/Composer/Installers/CodeIgniterInstaller.php new file mode 100644 index 00000000000..3b4a4ece11a --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/CodeIgniterInstaller.php @@ -0,0 +1,11 @@ + 'application/libraries/{$name}/', + 'third-party' => 'application/third_party/{$name}/', + 'module' => 'application/modules/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/Concrete5Installer.php b/vendor/composer/installers/src/Composer/Installers/Concrete5Installer.php new file mode 100644 index 00000000000..5c01bafd777 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/Concrete5Installer.php @@ -0,0 +1,13 @@ + 'concrete/', + 'block' => 'application/blocks/{$name}/', + 'package' => 'packages/{$name}/', + 'theme' => 'application/themes/{$name}/', + 'update' => 'updates/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/CraftInstaller.php b/vendor/composer/installers/src/Composer/Installers/CraftInstaller.php new file mode 100644 index 00000000000..d37a77ae2b7 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/CraftInstaller.php @@ -0,0 +1,35 @@ + 'craft/plugins/{$name}/', + ); + + /** + * Strip `craft-` prefix and/or `-plugin` suffix from package names + * + * @param array $vars + * + * @return array + */ + final public function inflectPackageVars($vars) + { + return $this->inflectPluginVars($vars); + } + + private function inflectPluginVars($vars) + { + $vars['name'] = preg_replace('/-' . self::NAME_SUFFIX . '$/i', '', $vars['name']); + $vars['name'] = preg_replace('/^' . self::NAME_PREFIX . '-/i', '', $vars['name']); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/CroogoInstaller.php b/vendor/composer/installers/src/Composer/Installers/CroogoInstaller.php new file mode 100644 index 00000000000..d94219d3a45 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/CroogoInstaller.php @@ -0,0 +1,21 @@ + 'Plugin/{$name}/', + 'theme' => 'View/Themed/{$name}/', + ); + + /** + * Format package name to CamelCase + */ + public function inflectPackageVars($vars) + { + $vars['name'] = strtolower(str_replace(array('-', '_'), ' ', $vars['name'])); + $vars['name'] = str_replace(' ', '', ucwords($vars['name'])); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/DecibelInstaller.php b/vendor/composer/installers/src/Composer/Installers/DecibelInstaller.php new file mode 100644 index 00000000000..f4837a6c18d --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/DecibelInstaller.php @@ -0,0 +1,10 @@ + 'app/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/DframeInstaller.php b/vendor/composer/installers/src/Composer/Installers/DframeInstaller.php new file mode 100644 index 00000000000..70788163a11 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/DframeInstaller.php @@ -0,0 +1,10 @@ + 'modules/{$vendor}/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/DokuWikiInstaller.php b/vendor/composer/installers/src/Composer/Installers/DokuWikiInstaller.php new file mode 100644 index 00000000000..cfd638d5f5f --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/DokuWikiInstaller.php @@ -0,0 +1,50 @@ + 'lib/plugins/{$name}/', + 'template' => 'lib/tpl/{$name}/', + ); + + /** + * Format package name. + * + * For package type dokuwiki-plugin, cut off a trailing '-plugin', + * or leading dokuwiki_ if present. + * + * For package type dokuwiki-template, cut off a trailing '-template' if present. + * + */ + public function inflectPackageVars($vars) + { + + if ($vars['type'] === 'dokuwiki-plugin') { + return $this->inflectPluginVars($vars); + } + + if ($vars['type'] === 'dokuwiki-template') { + return $this->inflectTemplateVars($vars); + } + + return $vars; + } + + protected function inflectPluginVars($vars) + { + $vars['name'] = preg_replace('/-plugin$/', '', $vars['name']); + $vars['name'] = preg_replace('/^dokuwiki_?-?/', '', $vars['name']); + + return $vars; + } + + protected function inflectTemplateVars($vars) + { + $vars['name'] = preg_replace('/-template$/', '', $vars['name']); + $vars['name'] = preg_replace('/^dokuwiki_?-?/', '', $vars['name']); + + return $vars; + } + +} diff --git a/vendor/composer/installers/src/Composer/Installers/DolibarrInstaller.php b/vendor/composer/installers/src/Composer/Installers/DolibarrInstaller.php new file mode 100644 index 00000000000..21f7e8e8016 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/DolibarrInstaller.php @@ -0,0 +1,16 @@ + + */ +class DolibarrInstaller extends BaseInstaller +{ + //TODO: Add support for scripts and themes + protected $locations = array( + 'module' => 'htdocs/custom/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/DrupalInstaller.php b/vendor/composer/installers/src/Composer/Installers/DrupalInstaller.php new file mode 100644 index 00000000000..73282392286 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/DrupalInstaller.php @@ -0,0 +1,22 @@ + 'core/', + 'module' => 'modules/{$name}/', + 'theme' => 'themes/{$name}/', + 'library' => 'libraries/{$name}/', + 'profile' => 'profiles/{$name}/', + 'database-driver' => 'drivers/lib/Drupal/Driver/Database/{$name}/', + 'drush' => 'drush/{$name}/', + 'custom-theme' => 'themes/custom/{$name}/', + 'custom-module' => 'modules/custom/{$name}/', + 'custom-profile' => 'profiles/custom/{$name}/', + 'drupal-multisite' => 'sites/{$name}/', + 'console' => 'console/{$name}/', + 'console-language' => 'console/language/{$name}/', + 'config' => 'config/sync/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/ElggInstaller.php b/vendor/composer/installers/src/Composer/Installers/ElggInstaller.php new file mode 100644 index 00000000000..c0bb609f4fe --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/ElggInstaller.php @@ -0,0 +1,9 @@ + 'mod/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/EliasisInstaller.php b/vendor/composer/installers/src/Composer/Installers/EliasisInstaller.php new file mode 100644 index 00000000000..6f3dc97b11a --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/EliasisInstaller.php @@ -0,0 +1,12 @@ + 'components/{$name}/', + 'module' => 'modules/{$name}/', + 'plugin' => 'plugins/{$name}/', + 'template' => 'templates/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/ExpressionEngineInstaller.php b/vendor/composer/installers/src/Composer/Installers/ExpressionEngineInstaller.php new file mode 100644 index 00000000000..d5321a8ca10 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/ExpressionEngineInstaller.php @@ -0,0 +1,29 @@ + 'system/expressionengine/third_party/{$name}/', + 'theme' => 'themes/third_party/{$name}/', + ); + + private $ee3Locations = array( + 'addon' => 'system/user/addons/{$name}/', + 'theme' => 'themes/user/{$name}/', + ); + + public function getInstallPath(PackageInterface $package, $frameworkType = '') + { + + $version = "{$frameworkType}Locations"; + $this->locations = $this->$version; + + return parent::getInstallPath($package, $frameworkType); + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/EzPlatformInstaller.php b/vendor/composer/installers/src/Composer/Installers/EzPlatformInstaller.php new file mode 100644 index 00000000000..f30ebcc775c --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/EzPlatformInstaller.php @@ -0,0 +1,10 @@ + 'web/assets/ezplatform/', + 'assets' => 'web/assets/ezplatform/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/FuelInstaller.php b/vendor/composer/installers/src/Composer/Installers/FuelInstaller.php new file mode 100644 index 00000000000..6eba2e34f2f --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/FuelInstaller.php @@ -0,0 +1,11 @@ + 'fuel/app/modules/{$name}/', + 'package' => 'fuel/packages/{$name}/', + 'theme' => 'fuel/app/themes/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/FuelphpInstaller.php b/vendor/composer/installers/src/Composer/Installers/FuelphpInstaller.php new file mode 100644 index 00000000000..29d980b30da --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/FuelphpInstaller.php @@ -0,0 +1,9 @@ + 'components/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/GravInstaller.php b/vendor/composer/installers/src/Composer/Installers/GravInstaller.php new file mode 100644 index 00000000000..dbe63e07ec2 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/GravInstaller.php @@ -0,0 +1,30 @@ + 'user/plugins/{$name}/', + 'theme' => 'user/themes/{$name}/', + ); + + /** + * Format package name + * + * @param array $vars + * + * @return array + */ + public function inflectPackageVars($vars) + { + $restrictedWords = implode('|', array_keys($this->locations)); + + $vars['name'] = strtolower($vars['name']); + $vars['name'] = preg_replace('/^(?:grav-)?(?:(?:'.$restrictedWords.')-)?(.*?)(?:-(?:'.$restrictedWords.'))?$/ui', + '$1', + $vars['name'] + ); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/HuradInstaller.php b/vendor/composer/installers/src/Composer/Installers/HuradInstaller.php new file mode 100644 index 00000000000..8fe017f0f74 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/HuradInstaller.php @@ -0,0 +1,25 @@ + 'plugins/{$name}/', + 'theme' => 'plugins/{$name}/', + ); + + /** + * Format package name to CamelCase + */ + public function inflectPackageVars($vars) + { + $nameParts = explode('/', $vars['name']); + foreach ($nameParts as &$value) { + $value = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $value)); + $value = str_replace(array('-', '_'), ' ', $value); + $value = str_replace(' ', '', ucwords($value)); + } + $vars['name'] = implode('/', $nameParts); + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/ImageCMSInstaller.php b/vendor/composer/installers/src/Composer/Installers/ImageCMSInstaller.php new file mode 100644 index 00000000000..5e2142ea577 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/ImageCMSInstaller.php @@ -0,0 +1,11 @@ + 'templates/{$name}/', + 'module' => 'application/modules/{$name}/', + 'library' => 'application/libraries/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/Installer.php b/vendor/composer/installers/src/Composer/Installers/Installer.php new file mode 100644 index 00000000000..9c9c24f7f2e --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/Installer.php @@ -0,0 +1,298 @@ + 'AimeosInstaller', + 'asgard' => 'AsgardInstaller', + 'attogram' => 'AttogramInstaller', + 'agl' => 'AglInstaller', + 'annotatecms' => 'AnnotateCmsInstaller', + 'bitrix' => 'BitrixInstaller', + 'bonefish' => 'BonefishInstaller', + 'cakephp' => 'CakePHPInstaller', + 'chef' => 'ChefInstaller', + 'civicrm' => 'CiviCrmInstaller', + 'ccframework' => 'ClanCatsFrameworkInstaller', + 'cockpit' => 'CockpitInstaller', + 'codeigniter' => 'CodeIgniterInstaller', + 'concrete5' => 'Concrete5Installer', + 'craft' => 'CraftInstaller', + 'croogo' => 'CroogoInstaller', + 'dframe' => 'DframeInstaller', + 'dokuwiki' => 'DokuWikiInstaller', + 'dolibarr' => 'DolibarrInstaller', + 'decibel' => 'DecibelInstaller', + 'drupal' => 'DrupalInstaller', + 'elgg' => 'ElggInstaller', + 'eliasis' => 'EliasisInstaller', + 'ee3' => 'ExpressionEngineInstaller', + 'ee2' => 'ExpressionEngineInstaller', + 'ezplatform' => 'EzPlatformInstaller', + 'fuel' => 'FuelInstaller', + 'fuelphp' => 'FuelphpInstaller', + 'grav' => 'GravInstaller', + 'hurad' => 'HuradInstaller', + 'tastyigniter' => 'TastyIgniterInstaller', + 'imagecms' => 'ImageCMSInstaller', + 'itop' => 'ItopInstaller', + 'joomla' => 'JoomlaInstaller', + 'kanboard' => 'KanboardInstaller', + 'kirby' => 'KirbyInstaller', + 'known' => 'KnownInstaller', + 'kodicms' => 'KodiCMSInstaller', + 'kohana' => 'KohanaInstaller', + 'lms' => 'LanManagementSystemInstaller', + 'laravel' => 'LaravelInstaller', + 'lavalite' => 'LavaLiteInstaller', + 'lithium' => 'LithiumInstaller', + 'magento' => 'MagentoInstaller', + 'majima' => 'MajimaInstaller', + 'mantisbt' => 'MantisBTInstaller', + 'mako' => 'MakoInstaller', + 'maya' => 'MayaInstaller', + 'mautic' => 'MauticInstaller', + 'mediawiki' => 'MediaWikiInstaller', + 'miaoxing' => 'MiaoxingInstaller', + 'microweber' => 'MicroweberInstaller', + 'modulework' => 'MODULEWorkInstaller', + 'modx' => 'ModxInstaller', + 'modxevo' => 'MODXEvoInstaller', + 'moodle' => 'MoodleInstaller', + 'october' => 'OctoberInstaller', + 'ontowiki' => 'OntoWikiInstaller', + 'oxid' => 'OxidInstaller', + 'osclass' => 'OsclassInstaller', + 'pxcms' => 'PxcmsInstaller', + 'phpbb' => 'PhpBBInstaller', + 'pimcore' => 'PimcoreInstaller', + 'piwik' => 'PiwikInstaller', + 'plentymarkets'=> 'PlentymarketsInstaller', + 'ppi' => 'PPIInstaller', + 'puppet' => 'PuppetInstaller', + 'radphp' => 'RadPHPInstaller', + 'phifty' => 'PhiftyInstaller', + 'porto' => 'PortoInstaller', + 'processwire' => 'ProcessWireInstaller', + 'quicksilver' => 'PantheonInstaller', + 'redaxo' => 'RedaxoInstaller', + 'redaxo5' => 'Redaxo5Installer', + 'reindex' => 'ReIndexInstaller', + 'roundcube' => 'RoundcubeInstaller', + 'shopware' => 'ShopwareInstaller', + 'sitedirect' => 'SiteDirectInstaller', + 'silverstripe' => 'SilverStripeInstaller', + 'smf' => 'SMFInstaller', + 'starbug' => 'StarbugInstaller', + 'sydes' => 'SyDESInstaller', + 'sylius' => 'SyliusInstaller', + 'symfony1' => 'Symfony1Installer', + 'tao' => 'TaoInstaller', + 'thelia' => 'TheliaInstaller', + 'tusk' => 'TuskInstaller', + 'typo3-cms' => 'TYPO3CmsInstaller', + 'typo3-flow' => 'TYPO3FlowInstaller', + 'userfrosting' => 'UserFrostingInstaller', + 'vanilla' => 'VanillaInstaller', + 'whmcs' => 'WHMCSInstaller', + 'winter' => 'WinterInstaller', + 'wolfcms' => 'WolfCMSInstaller', + 'wordpress' => 'WordPressInstaller', + 'yawik' => 'YawikInstaller', + 'zend' => 'ZendInstaller', + 'zikula' => 'ZikulaInstaller', + 'prestashop' => 'PrestashopInstaller' + ); + + /** + * Installer constructor. + * + * Disables installers specified in main composer extra installer-disable + * list + * + * @param IOInterface $io + * @param Composer $composer + * @param string $type + * @param Filesystem|null $filesystem + * @param BinaryInstaller|null $binaryInstaller + */ + public function __construct( + IOInterface $io, + Composer $composer, + $type = 'library', + Filesystem $filesystem = null, + BinaryInstaller $binaryInstaller = null + ) { + parent::__construct($io, $composer, $type, $filesystem, + $binaryInstaller); + $this->removeDisabledInstallers(); + } + + /** + * {@inheritDoc} + */ + public function getInstallPath(PackageInterface $package) + { + $type = $package->getType(); + $frameworkType = $this->findFrameworkType($type); + + if ($frameworkType === false) { + throw new \InvalidArgumentException( + 'Sorry the package type of this package is not yet supported.' + ); + } + + $class = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType]; + $installer = new $class($package, $this->composer, $this->getIO()); + + return $installer->getInstallPath($package, $frameworkType); + } + + public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) + { + $installPath = $this->getPackageBasePath($package); + $io = $this->io; + $outputStatus = function () use ($io, $installPath) { + $io->write(sprintf('Deleting %s - %s', $installPath, !file_exists($installPath) ? 'deleted' : 'not deleted')); + }; + + $promise = parent::uninstall($repo, $package); + + // Composer v2 might return a promise here + if ($promise instanceof PromiseInterface) { + return $promise->then($outputStatus); + } + + // If not, execute the code right away as parent::uninstall executed synchronously (composer v1, or v2 without async) + $outputStatus(); + + return null; + } + + /** + * {@inheritDoc} + */ + public function supports($packageType) + { + $frameworkType = $this->findFrameworkType($packageType); + + if ($frameworkType === false) { + return false; + } + + $locationPattern = $this->getLocationPattern($frameworkType); + + return preg_match('#' . $frameworkType . '-' . $locationPattern . '#', $packageType, $matches) === 1; + } + + /** + * Finds a supported framework type if it exists and returns it + * + * @param string $type + * @return string|false + */ + protected function findFrameworkType($type) + { + krsort($this->supportedTypes); + + foreach ($this->supportedTypes as $key => $val) { + if ($key === substr($type, 0, strlen($key))) { + return substr($type, 0, strlen($key)); + } + } + + return false; + } + + /** + * Get the second part of the regular expression to check for support of a + * package type + * + * @param string $frameworkType + * @return string + */ + protected function getLocationPattern($frameworkType) + { + $pattern = false; + if (!empty($this->supportedTypes[$frameworkType])) { + $frameworkClass = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType]; + /** @var BaseInstaller $framework */ + $framework = new $frameworkClass(null, $this->composer, $this->getIO()); + $locations = array_keys($framework->getLocations()); + $pattern = $locations ? '(' . implode('|', $locations) . ')' : false; + } + + return $pattern ? : '(\w+)'; + } + + /** + * Get I/O object + * + * @return IOInterface + */ + private function getIO() + { + return $this->io; + } + + /** + * Look for installers set to be disabled in composer's extra config and + * remove them from the list of supported installers. + * + * Globals: + * - true, "all", and "*" - disable all installers. + * - false - enable all installers (useful with + * wikimedia/composer-merge-plugin or similar) + * + * @return void + */ + protected function removeDisabledInstallers() + { + $extra = $this->composer->getPackage()->getExtra(); + + if (!isset($extra['installer-disable']) || $extra['installer-disable'] === false) { + // No installers are disabled + return; + } + + // Get installers to disable + $disable = $extra['installer-disable']; + + // Ensure $disabled is an array + if (!is_array($disable)) { + $disable = array($disable); + } + + // Check which installers should be disabled + $all = array(true, "all", "*"); + $intersect = array_intersect($all, $disable); + if (!empty($intersect)) { + // Disable all installers + $this->supportedTypes = array(); + } else { + // Disable specified installers + foreach ($disable as $key => $installer) { + if (is_string($installer) && key_exists($installer, $this->supportedTypes)) { + unset($this->supportedTypes[$installer]); + } + } + } + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/ItopInstaller.php b/vendor/composer/installers/src/Composer/Installers/ItopInstaller.php new file mode 100644 index 00000000000..c6c1b337460 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/ItopInstaller.php @@ -0,0 +1,9 @@ + 'extensions/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/JoomlaInstaller.php b/vendor/composer/installers/src/Composer/Installers/JoomlaInstaller.php new file mode 100644 index 00000000000..9ee7759651a --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/JoomlaInstaller.php @@ -0,0 +1,15 @@ + 'components/{$name}/', + 'module' => 'modules/{$name}/', + 'template' => 'templates/{$name}/', + 'plugin' => 'plugins/{$name}/', + 'library' => 'libraries/{$name}/', + ); + + // TODO: Add inflector for mod_ and com_ names +} diff --git a/vendor/composer/installers/src/Composer/Installers/KanboardInstaller.php b/vendor/composer/installers/src/Composer/Installers/KanboardInstaller.php new file mode 100644 index 00000000000..9cb7b8cdbff --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/KanboardInstaller.php @@ -0,0 +1,18 @@ + 'plugins/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/KirbyInstaller.php b/vendor/composer/installers/src/Composer/Installers/KirbyInstaller.php new file mode 100644 index 00000000000..36b2f84a761 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/KirbyInstaller.php @@ -0,0 +1,11 @@ + 'site/plugins/{$name}/', + 'field' => 'site/fields/{$name}/', + 'tag' => 'site/tags/{$name}/' + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/KnownInstaller.php b/vendor/composer/installers/src/Composer/Installers/KnownInstaller.php new file mode 100644 index 00000000000..c5d08c5f9a1 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/KnownInstaller.php @@ -0,0 +1,11 @@ + 'IdnoPlugins/{$name}/', + 'theme' => 'Themes/{$name}/', + 'console' => 'ConsolePlugins/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/KodiCMSInstaller.php b/vendor/composer/installers/src/Composer/Installers/KodiCMSInstaller.php new file mode 100644 index 00000000000..7143e232bc3 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/KodiCMSInstaller.php @@ -0,0 +1,10 @@ + 'cms/plugins/{$name}/', + 'media' => 'cms/media/vendor/{$name}/' + ); +} \ No newline at end of file diff --git a/vendor/composer/installers/src/Composer/Installers/KohanaInstaller.php b/vendor/composer/installers/src/Composer/Installers/KohanaInstaller.php new file mode 100644 index 00000000000..dcd6d26322a --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/KohanaInstaller.php @@ -0,0 +1,9 @@ + 'modules/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/LanManagementSystemInstaller.php b/vendor/composer/installers/src/Composer/Installers/LanManagementSystemInstaller.php new file mode 100644 index 00000000000..903143a558e --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/LanManagementSystemInstaller.php @@ -0,0 +1,27 @@ + 'plugins/{$name}/', + 'template' => 'templates/{$name}/', + 'document-template' => 'documents/templates/{$name}/', + 'userpanel-module' => 'userpanel/modules/{$name}/', + ); + + /** + * Format package name to CamelCase + */ + public function inflectPackageVars($vars) + { + $vars['name'] = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $vars['name'])); + $vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']); + $vars['name'] = str_replace(' ', '', ucwords($vars['name'])); + + return $vars; + } + +} diff --git a/vendor/composer/installers/src/Composer/Installers/LaravelInstaller.php b/vendor/composer/installers/src/Composer/Installers/LaravelInstaller.php new file mode 100644 index 00000000000..be4d53a7bd3 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/LaravelInstaller.php @@ -0,0 +1,9 @@ + 'libraries/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/LavaLiteInstaller.php b/vendor/composer/installers/src/Composer/Installers/LavaLiteInstaller.php new file mode 100644 index 00000000000..412c0b5c0b6 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/LavaLiteInstaller.php @@ -0,0 +1,10 @@ + 'packages/{$vendor}/{$name}/', + 'theme' => 'public/themes/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/LithiumInstaller.php b/vendor/composer/installers/src/Composer/Installers/LithiumInstaller.php new file mode 100644 index 00000000000..47bbd4cabeb --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/LithiumInstaller.php @@ -0,0 +1,10 @@ + 'libraries/{$name}/', + 'source' => 'libraries/_source/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/MODULEWorkInstaller.php b/vendor/composer/installers/src/Composer/Installers/MODULEWorkInstaller.php new file mode 100644 index 00000000000..9c2e9fb40c3 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/MODULEWorkInstaller.php @@ -0,0 +1,9 @@ + 'modules/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/MODXEvoInstaller.php b/vendor/composer/installers/src/Composer/Installers/MODXEvoInstaller.php new file mode 100644 index 00000000000..5a664608df9 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/MODXEvoInstaller.php @@ -0,0 +1,16 @@ + 'assets/snippets/{$name}/', + 'plugin' => 'assets/plugins/{$name}/', + 'module' => 'assets/modules/{$name}/', + 'template' => 'assets/templates/{$name}/', + 'lib' => 'assets/lib/{$name}/' + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/MagentoInstaller.php b/vendor/composer/installers/src/Composer/Installers/MagentoInstaller.php new file mode 100644 index 00000000000..cf18e9478ce --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/MagentoInstaller.php @@ -0,0 +1,11 @@ + 'app/design/frontend/{$name}/', + 'skin' => 'skin/frontend/default/{$name}/', + 'library' => 'lib/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/MajimaInstaller.php b/vendor/composer/installers/src/Composer/Installers/MajimaInstaller.php new file mode 100644 index 00000000000..e463756faa9 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/MajimaInstaller.php @@ -0,0 +1,37 @@ + 'plugins/{$name}/', + ); + + /** + * Transforms the names + * @param array $vars + * @return array + */ + public function inflectPackageVars($vars) + { + return $this->correctPluginName($vars); + } + + /** + * Change hyphenated names to camelcase + * @param array $vars + * @return array + */ + private function correctPluginName($vars) + { + $camelCasedName = preg_replace_callback('/(-[a-z])/', function ($matches) { + return strtoupper($matches[0][1]); + }, $vars['name']); + $vars['name'] = ucfirst($camelCasedName); + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/MakoInstaller.php b/vendor/composer/installers/src/Composer/Installers/MakoInstaller.php new file mode 100644 index 00000000000..ca3cfacb49a --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/MakoInstaller.php @@ -0,0 +1,9 @@ + 'app/packages/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/MantisBTInstaller.php b/vendor/composer/installers/src/Composer/Installers/MantisBTInstaller.php new file mode 100644 index 00000000000..dadb1dbbcf6 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/MantisBTInstaller.php @@ -0,0 +1,23 @@ + 'plugins/{$name}/', + ); + + /** + * Format package name to CamelCase + */ + public function inflectPackageVars($vars) + { + $vars['name'] = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $vars['name'])); + $vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']); + $vars['name'] = str_replace(' ', '', ucwords($vars['name'])); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/MauticInstaller.php b/vendor/composer/installers/src/Composer/Installers/MauticInstaller.php new file mode 100644 index 00000000000..c3dd2b6f963 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/MauticInstaller.php @@ -0,0 +1,48 @@ + 'plugins/{$name}/', + 'theme' => 'themes/{$name}/', + 'core' => 'app/', + ); + + private function getDirectoryName() + { + $extra = $this->package->getExtra(); + if (!empty($extra['install-directory-name'])) { + return $extra['install-directory-name']; + } + + return $this->toCamelCase($this->package->getPrettyName()); + } + + /** + * @param string $packageName + * + * @return string + */ + private function toCamelCase($packageName) + { + return str_replace(' ', '', ucwords(str_replace('-', ' ', basename($packageName)))); + } + + /** + * Format package name of mautic-plugins to CamelCase + */ + public function inflectPackageVars($vars) + { + + if ($vars['type'] == 'mautic-plugin' || $vars['type'] == 'mautic-theme') { + $directoryName = $this->getDirectoryName(); + $vars['name'] = $directoryName; + } + + return $vars; + } + +} diff --git a/vendor/composer/installers/src/Composer/Installers/MayaInstaller.php b/vendor/composer/installers/src/Composer/Installers/MayaInstaller.php new file mode 100644 index 00000000000..30a91676d73 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/MayaInstaller.php @@ -0,0 +1,33 @@ + 'modules/{$name}/', + ); + + /** + * Format package name. + * + * For package type maya-module, cut off a trailing '-module' if present. + * + */ + public function inflectPackageVars($vars) + { + if ($vars['type'] === 'maya-module') { + return $this->inflectModuleVars($vars); + } + + return $vars; + } + + protected function inflectModuleVars($vars) + { + $vars['name'] = preg_replace('/-module$/', '', $vars['name']); + $vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']); + $vars['name'] = str_replace(' ', '', ucwords($vars['name'])); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/MediaWikiInstaller.php b/vendor/composer/installers/src/Composer/Installers/MediaWikiInstaller.php new file mode 100644 index 00000000000..f5a8957ef0d --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/MediaWikiInstaller.php @@ -0,0 +1,51 @@ + 'core/', + 'extension' => 'extensions/{$name}/', + 'skin' => 'skins/{$name}/', + ); + + /** + * Format package name. + * + * For package type mediawiki-extension, cut off a trailing '-extension' if present and transform + * to CamelCase keeping existing uppercase chars. + * + * For package type mediawiki-skin, cut off a trailing '-skin' if present. + * + */ + public function inflectPackageVars($vars) + { + + if ($vars['type'] === 'mediawiki-extension') { + return $this->inflectExtensionVars($vars); + } + + if ($vars['type'] === 'mediawiki-skin') { + return $this->inflectSkinVars($vars); + } + + return $vars; + } + + protected function inflectExtensionVars($vars) + { + $vars['name'] = preg_replace('/-extension$/', '', $vars['name']); + $vars['name'] = str_replace('-', ' ', $vars['name']); + $vars['name'] = str_replace(' ', '', ucwords($vars['name'])); + + return $vars; + } + + protected function inflectSkinVars($vars) + { + $vars['name'] = preg_replace('/-skin$/', '', $vars['name']); + + return $vars; + } + +} diff --git a/vendor/composer/installers/src/Composer/Installers/MiaoxingInstaller.php b/vendor/composer/installers/src/Composer/Installers/MiaoxingInstaller.php new file mode 100644 index 00000000000..66d8369c4fe --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/MiaoxingInstaller.php @@ -0,0 +1,10 @@ + 'plugins/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/MicroweberInstaller.php b/vendor/composer/installers/src/Composer/Installers/MicroweberInstaller.php new file mode 100644 index 00000000000..b7d970392ab --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/MicroweberInstaller.php @@ -0,0 +1,119 @@ + 'userfiles/modules/{$install_item_dir}/', + 'module-skin' => 'userfiles/modules/{$install_item_dir}/templates/', + 'template' => 'userfiles/templates/{$install_item_dir}/', + 'element' => 'userfiles/elements/{$install_item_dir}/', + 'vendor' => 'vendor/{$install_item_dir}/', + 'components' => 'components/{$install_item_dir}/' + ); + + /** + * Format package name. + * + * For package type microweber-module, cut off a trailing '-module' if present + * + * For package type microweber-template, cut off a trailing '-template' if present. + * + */ + public function inflectPackageVars($vars) + { + + + if ($this->package->getTargetDir()) { + $vars['install_item_dir'] = $this->package->getTargetDir(); + } else { + $vars['install_item_dir'] = $vars['name']; + if ($vars['type'] === 'microweber-template') { + return $this->inflectTemplateVars($vars); + } + if ($vars['type'] === 'microweber-templates') { + return $this->inflectTemplatesVars($vars); + } + if ($vars['type'] === 'microweber-core') { + return $this->inflectCoreVars($vars); + } + if ($vars['type'] === 'microweber-adapter') { + return $this->inflectCoreVars($vars); + } + if ($vars['type'] === 'microweber-module') { + return $this->inflectModuleVars($vars); + } + if ($vars['type'] === 'microweber-modules') { + return $this->inflectModulesVars($vars); + } + if ($vars['type'] === 'microweber-skin') { + return $this->inflectSkinVars($vars); + } + if ($vars['type'] === 'microweber-element' or $vars['type'] === 'microweber-elements') { + return $this->inflectElementVars($vars); + } + } + + + return $vars; + } + + protected function inflectTemplateVars($vars) + { + $vars['install_item_dir'] = preg_replace('/-template$/', '', $vars['install_item_dir']); + $vars['install_item_dir'] = preg_replace('/template-$/', '', $vars['install_item_dir']); + + return $vars; + } + + protected function inflectTemplatesVars($vars) + { + $vars['install_item_dir'] = preg_replace('/-templates$/', '', $vars['install_item_dir']); + $vars['install_item_dir'] = preg_replace('/templates-$/', '', $vars['install_item_dir']); + + return $vars; + } + + protected function inflectCoreVars($vars) + { + $vars['install_item_dir'] = preg_replace('/-providers$/', '', $vars['install_item_dir']); + $vars['install_item_dir'] = preg_replace('/-provider$/', '', $vars['install_item_dir']); + $vars['install_item_dir'] = preg_replace('/-adapter$/', '', $vars['install_item_dir']); + + return $vars; + } + + protected function inflectModuleVars($vars) + { + $vars['install_item_dir'] = preg_replace('/-module$/', '', $vars['install_item_dir']); + $vars['install_item_dir'] = preg_replace('/module-$/', '', $vars['install_item_dir']); + + return $vars; + } + + protected function inflectModulesVars($vars) + { + $vars['install_item_dir'] = preg_replace('/-modules$/', '', $vars['install_item_dir']); + $vars['install_item_dir'] = preg_replace('/modules-$/', '', $vars['install_item_dir']); + + return $vars; + } + + protected function inflectSkinVars($vars) + { + $vars['install_item_dir'] = preg_replace('/-skin$/', '', $vars['install_item_dir']); + $vars['install_item_dir'] = preg_replace('/skin-$/', '', $vars['install_item_dir']); + + return $vars; + } + + protected function inflectElementVars($vars) + { + $vars['install_item_dir'] = preg_replace('/-elements$/', '', $vars['install_item_dir']); + $vars['install_item_dir'] = preg_replace('/elements-$/', '', $vars['install_item_dir']); + $vars['install_item_dir'] = preg_replace('/-element$/', '', $vars['install_item_dir']); + $vars['install_item_dir'] = preg_replace('/element-$/', '', $vars['install_item_dir']); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/ModxInstaller.php b/vendor/composer/installers/src/Composer/Installers/ModxInstaller.php new file mode 100644 index 00000000000..0ee140abfe5 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/ModxInstaller.php @@ -0,0 +1,12 @@ + 'core/packages/{$name}/' + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/MoodleInstaller.php b/vendor/composer/installers/src/Composer/Installers/MoodleInstaller.php new file mode 100644 index 00000000000..05317995f42 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/MoodleInstaller.php @@ -0,0 +1,59 @@ + 'mod/{$name}/', + 'admin_report' => 'admin/report/{$name}/', + 'atto' => 'lib/editor/atto/plugins/{$name}/', + 'tool' => 'admin/tool/{$name}/', + 'assignment' => 'mod/assignment/type/{$name}/', + 'assignsubmission' => 'mod/assign/submission/{$name}/', + 'assignfeedback' => 'mod/assign/feedback/{$name}/', + 'auth' => 'auth/{$name}/', + 'availability' => 'availability/condition/{$name}/', + 'block' => 'blocks/{$name}/', + 'booktool' => 'mod/book/tool/{$name}/', + 'cachestore' => 'cache/stores/{$name}/', + 'cachelock' => 'cache/locks/{$name}/', + 'calendartype' => 'calendar/type/{$name}/', + 'fileconverter' => 'files/converter/{$name}/', + 'format' => 'course/format/{$name}/', + 'coursereport' => 'course/report/{$name}/', + 'customcertelement' => 'mod/customcert/element/{$name}/', + 'datafield' => 'mod/data/field/{$name}/', + 'datapreset' => 'mod/data/preset/{$name}/', + 'editor' => 'lib/editor/{$name}/', + 'enrol' => 'enrol/{$name}/', + 'filter' => 'filter/{$name}/', + 'gradeexport' => 'grade/export/{$name}/', + 'gradeimport' => 'grade/import/{$name}/', + 'gradereport' => 'grade/report/{$name}/', + 'gradingform' => 'grade/grading/form/{$name}/', + 'local' => 'local/{$name}/', + 'logstore' => 'admin/tool/log/store/{$name}/', + 'ltisource' => 'mod/lti/source/{$name}/', + 'ltiservice' => 'mod/lti/service/{$name}/', + 'message' => 'message/output/{$name}/', + 'mnetservice' => 'mnet/service/{$name}/', + 'plagiarism' => 'plagiarism/{$name}/', + 'portfolio' => 'portfolio/{$name}/', + 'qbehaviour' => 'question/behaviour/{$name}/', + 'qformat' => 'question/format/{$name}/', + 'qtype' => 'question/type/{$name}/', + 'quizaccess' => 'mod/quiz/accessrule/{$name}/', + 'quiz' => 'mod/quiz/report/{$name}/', + 'report' => 'report/{$name}/', + 'repository' => 'repository/{$name}/', + 'scormreport' => 'mod/scorm/report/{$name}/', + 'search' => 'search/engine/{$name}/', + 'theme' => 'theme/{$name}/', + 'tinymce' => 'lib/editor/tinymce/plugins/{$name}/', + 'profilefield' => 'user/profile/field/{$name}/', + 'webservice' => 'webservice/{$name}/', + 'workshopallocation' => 'mod/workshop/allocation/{$name}/', + 'workshopeval' => 'mod/workshop/eval/{$name}/', + 'workshopform' => 'mod/workshop/form/{$name}/' + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/OctoberInstaller.php b/vendor/composer/installers/src/Composer/Installers/OctoberInstaller.php new file mode 100644 index 00000000000..489ef02ab1a --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/OctoberInstaller.php @@ -0,0 +1,48 @@ + 'modules/{$name}/', + 'plugin' => 'plugins/{$vendor}/{$name}/', + 'theme' => 'themes/{$vendor}-{$name}/' + ); + + /** + * Format package name. + * + * For package type october-plugin, cut off a trailing '-plugin' if present. + * + * For package type october-theme, cut off a trailing '-theme' if present. + * + */ + public function inflectPackageVars($vars) + { + if ($vars['type'] === 'october-plugin') { + return $this->inflectPluginVars($vars); + } + + if ($vars['type'] === 'october-theme') { + return $this->inflectThemeVars($vars); + } + + return $vars; + } + + protected function inflectPluginVars($vars) + { + $vars['name'] = preg_replace('/^oc-|-plugin$/', '', $vars['name']); + $vars['vendor'] = preg_replace('/[^a-z0-9_]/i', '', $vars['vendor']); + + return $vars; + } + + protected function inflectThemeVars($vars) + { + $vars['name'] = preg_replace('/^oc-|-theme$/', '', $vars['name']); + $vars['vendor'] = preg_replace('/[^a-z0-9_]/i', '', $vars['vendor']); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/OntoWikiInstaller.php b/vendor/composer/installers/src/Composer/Installers/OntoWikiInstaller.php new file mode 100644 index 00000000000..5dd3438d90b --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/OntoWikiInstaller.php @@ -0,0 +1,24 @@ + 'extensions/{$name}/', + 'theme' => 'extensions/themes/{$name}/', + 'translation' => 'extensions/translations/{$name}/', + ); + + /** + * Format package name to lower case and remove ".ontowiki" suffix + */ + public function inflectPackageVars($vars) + { + $vars['name'] = strtolower($vars['name']); + $vars['name'] = preg_replace('/.ontowiki$/', '', $vars['name']); + $vars['name'] = preg_replace('/-theme$/', '', $vars['name']); + $vars['name'] = preg_replace('/-translation$/', '', $vars['name']); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/OsclassInstaller.php b/vendor/composer/installers/src/Composer/Installers/OsclassInstaller.php new file mode 100644 index 00000000000..3ca7954c9ea --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/OsclassInstaller.php @@ -0,0 +1,14 @@ + 'oc-content/plugins/{$name}/', + 'theme' => 'oc-content/themes/{$name}/', + 'language' => 'oc-content/languages/{$name}/', + ); + +} diff --git a/vendor/composer/installers/src/Composer/Installers/OxidInstaller.php b/vendor/composer/installers/src/Composer/Installers/OxidInstaller.php new file mode 100644 index 00000000000..1797a22cf1b --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/OxidInstaller.php @@ -0,0 +1,59 @@ +.+)\/.+/'; + + protected $locations = array( + 'module' => 'modules/{$name}/', + 'theme' => 'application/views/{$name}/', + 'out' => 'out/{$name}/', + ); + + /** + * getInstallPath + * + * @param PackageInterface $package + * @param string $frameworkType + * @return string + */ + public function getInstallPath(PackageInterface $package, $frameworkType = '') + { + $installPath = parent::getInstallPath($package, $frameworkType); + $type = $this->package->getType(); + if ($type === 'oxid-module') { + $this->prepareVendorDirectory($installPath); + } + return $installPath; + } + + /** + * prepareVendorDirectory + * + * Makes sure there is a vendormetadata.php file inside + * the vendor folder if there is a vendor folder. + * + * @param string $installPath + * @return void + */ + protected function prepareVendorDirectory($installPath) + { + $matches = ''; + $hasVendorDirectory = preg_match(self::VENDOR_PATTERN, $installPath, $matches); + if (!$hasVendorDirectory) { + return; + } + + $vendorDirectory = $matches['vendor']; + $vendorPath = getcwd() . '/modules/' . $vendorDirectory; + if (!file_exists($vendorPath)) { + mkdir($vendorPath, 0755, true); + } + + $vendorMetaDataPath = $vendorPath . '/vendormetadata.php'; + touch($vendorMetaDataPath); + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/PPIInstaller.php b/vendor/composer/installers/src/Composer/Installers/PPIInstaller.php new file mode 100644 index 00000000000..170136f9840 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/PPIInstaller.php @@ -0,0 +1,9 @@ + 'modules/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/PantheonInstaller.php b/vendor/composer/installers/src/Composer/Installers/PantheonInstaller.php new file mode 100644 index 00000000000..439f61a0391 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/PantheonInstaller.php @@ -0,0 +1,12 @@ + */ + protected $locations = array( + 'script' => 'web/private/scripts/quicksilver/{$name}', + 'module' => 'web/private/scripts/quicksilver/{$name}', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/PhiftyInstaller.php b/vendor/composer/installers/src/Composer/Installers/PhiftyInstaller.php new file mode 100644 index 00000000000..4e59a8a74f7 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/PhiftyInstaller.php @@ -0,0 +1,11 @@ + 'bundles/{$name}/', + 'library' => 'libraries/{$name}/', + 'framework' => 'frameworks/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/PhpBBInstaller.php b/vendor/composer/installers/src/Composer/Installers/PhpBBInstaller.php new file mode 100644 index 00000000000..deb2b77a67e --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/PhpBBInstaller.php @@ -0,0 +1,11 @@ + 'ext/{$vendor}/{$name}/', + 'language' => 'language/{$name}/', + 'style' => 'styles/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/PimcoreInstaller.php b/vendor/composer/installers/src/Composer/Installers/PimcoreInstaller.php new file mode 100644 index 00000000000..4781fa6d107 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/PimcoreInstaller.php @@ -0,0 +1,21 @@ + 'plugins/{$name}/', + ); + + /** + * Format package name to CamelCase + */ + public function inflectPackageVars($vars) + { + $vars['name'] = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $vars['name'])); + $vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']); + $vars['name'] = str_replace(' ', '', ucwords($vars['name'])); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/PiwikInstaller.php b/vendor/composer/installers/src/Composer/Installers/PiwikInstaller.php new file mode 100644 index 00000000000..c17f4572b32 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/PiwikInstaller.php @@ -0,0 +1,32 @@ + 'plugins/{$name}/', + ); + + /** + * Format package name to CamelCase + * @param array $vars + * + * @return array + */ + public function inflectPackageVars($vars) + { + $vars['name'] = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $vars['name'])); + $vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']); + $vars['name'] = str_replace(' ', '', ucwords($vars['name'])); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/PlentymarketsInstaller.php b/vendor/composer/installers/src/Composer/Installers/PlentymarketsInstaller.php new file mode 100644 index 00000000000..903e55f62c1 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/PlentymarketsInstaller.php @@ -0,0 +1,29 @@ + '{$name}/' + ); + + /** + * Remove hyphen, "plugin" and format to camelcase + * @param array $vars + * + * @return array + */ + public function inflectPackageVars($vars) + { + $vars['name'] = explode("-", $vars['name']); + foreach ($vars['name'] as $key => $name) { + $vars['name'][$key] = ucfirst($vars['name'][$key]); + if (strcasecmp($name, "Plugin") == 0) { + unset($vars['name'][$key]); + } + } + $vars['name'] = implode("",$vars['name']); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/Plugin.php b/vendor/composer/installers/src/Composer/Installers/Plugin.php new file mode 100644 index 00000000000..e60da0e7f19 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/Plugin.php @@ -0,0 +1,27 @@ +installer = new Installer($io, $composer); + $composer->getInstallationManager()->addInstaller($this->installer); + } + + public function deactivate(Composer $composer, IOInterface $io) + { + $composer->getInstallationManager()->removeInstaller($this->installer); + } + + public function uninstall(Composer $composer, IOInterface $io) + { + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/PortoInstaller.php b/vendor/composer/installers/src/Composer/Installers/PortoInstaller.php new file mode 100644 index 00000000000..dbf85e635e8 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/PortoInstaller.php @@ -0,0 +1,9 @@ + 'app/Containers/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/PrestashopInstaller.php b/vendor/composer/installers/src/Composer/Installers/PrestashopInstaller.php new file mode 100644 index 00000000000..4c8421e3640 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/PrestashopInstaller.php @@ -0,0 +1,10 @@ + 'modules/{$name}/', + 'theme' => 'themes/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/ProcessWireInstaller.php b/vendor/composer/installers/src/Composer/Installers/ProcessWireInstaller.php new file mode 100644 index 00000000000..e6834a0ca55 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/ProcessWireInstaller.php @@ -0,0 +1,22 @@ + 'site/modules/{$name}/', + ); + + /** + * Format package name to CamelCase + */ + public function inflectPackageVars($vars) + { + $vars['name'] = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $vars['name'])); + $vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']); + $vars['name'] = str_replace(' ', '', ucwords($vars['name'])); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/PuppetInstaller.php b/vendor/composer/installers/src/Composer/Installers/PuppetInstaller.php new file mode 100644 index 00000000000..77cc3dd8777 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/PuppetInstaller.php @@ -0,0 +1,11 @@ + 'modules/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/PxcmsInstaller.php b/vendor/composer/installers/src/Composer/Installers/PxcmsInstaller.php new file mode 100644 index 00000000000..65510580e13 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/PxcmsInstaller.php @@ -0,0 +1,63 @@ + 'app/Modules/{$name}/', + 'theme' => 'themes/{$name}/', + ); + + /** + * Format package name. + * + * @param array $vars + * + * @return array + */ + public function inflectPackageVars($vars) + { + if ($vars['type'] === 'pxcms-module') { + return $this->inflectModuleVars($vars); + } + + if ($vars['type'] === 'pxcms-theme') { + return $this->inflectThemeVars($vars); + } + + return $vars; + } + + /** + * For package type pxcms-module, cut off a trailing '-plugin' if present. + * + * return string + */ + protected function inflectModuleVars($vars) + { + $vars['name'] = str_replace('pxcms-', '', $vars['name']); // strip out pxcms- just incase (legacy) + $vars['name'] = str_replace('module-', '', $vars['name']); // strip out module- + $vars['name'] = preg_replace('/-module$/', '', $vars['name']); // strip out -module + $vars['name'] = str_replace('-', '_', $vars['name']); // make -'s be _'s + $vars['name'] = ucwords($vars['name']); // make module name camelcased + + return $vars; + } + + + /** + * For package type pxcms-module, cut off a trailing '-plugin' if present. + * + * return string + */ + protected function inflectThemeVars($vars) + { + $vars['name'] = str_replace('pxcms-', '', $vars['name']); // strip out pxcms- just incase (legacy) + $vars['name'] = str_replace('theme-', '', $vars['name']); // strip out theme- + $vars['name'] = preg_replace('/-theme$/', '', $vars['name']); // strip out -theme + $vars['name'] = str_replace('-', '_', $vars['name']); // make -'s be _'s + $vars['name'] = ucwords($vars['name']); // make module name camelcased + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/RadPHPInstaller.php b/vendor/composer/installers/src/Composer/Installers/RadPHPInstaller.php new file mode 100644 index 00000000000..0f78b5ca649 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/RadPHPInstaller.php @@ -0,0 +1,24 @@ + 'src/{$name}/' + ); + + /** + * Format package name to CamelCase + */ + public function inflectPackageVars($vars) + { + $nameParts = explode('/', $vars['name']); + foreach ($nameParts as &$value) { + $value = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $value)); + $value = str_replace(array('-', '_'), ' ', $value); + $value = str_replace(' ', '', ucwords($value)); + } + $vars['name'] = implode('/', $nameParts); + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/ReIndexInstaller.php b/vendor/composer/installers/src/Composer/Installers/ReIndexInstaller.php new file mode 100644 index 00000000000..252c7339f92 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/ReIndexInstaller.php @@ -0,0 +1,10 @@ + 'themes/{$name}/', + 'plugin' => 'plugins/{$name}/' + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/Redaxo5Installer.php b/vendor/composer/installers/src/Composer/Installers/Redaxo5Installer.php new file mode 100644 index 00000000000..23a20347eff --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/Redaxo5Installer.php @@ -0,0 +1,10 @@ + 'redaxo/src/addons/{$name}/', + 'bestyle-plugin' => 'redaxo/src/addons/be_style/plugins/{$name}/' + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/RedaxoInstaller.php b/vendor/composer/installers/src/Composer/Installers/RedaxoInstaller.php new file mode 100644 index 00000000000..09544576b20 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/RedaxoInstaller.php @@ -0,0 +1,10 @@ + 'redaxo/include/addons/{$name}/', + 'bestyle-plugin' => 'redaxo/include/addons/be_style/plugins/{$name}/' + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/RoundcubeInstaller.php b/vendor/composer/installers/src/Composer/Installers/RoundcubeInstaller.php new file mode 100644 index 00000000000..d8d795be097 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/RoundcubeInstaller.php @@ -0,0 +1,22 @@ + 'plugins/{$name}/', + ); + + /** + * Lowercase name and changes the name to a underscores + * + * @param array $vars + * @return array + */ + public function inflectPackageVars($vars) + { + $vars['name'] = strtolower(str_replace('-', '_', $vars['name'])); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/SMFInstaller.php b/vendor/composer/installers/src/Composer/Installers/SMFInstaller.php new file mode 100644 index 00000000000..1acd3b14c38 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/SMFInstaller.php @@ -0,0 +1,10 @@ + 'Sources/{$name}/', + 'theme' => 'Themes/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/ShopwareInstaller.php b/vendor/composer/installers/src/Composer/Installers/ShopwareInstaller.php new file mode 100644 index 00000000000..7d20d27a228 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/ShopwareInstaller.php @@ -0,0 +1,60 @@ + 'engine/Shopware/Plugins/Local/Backend/{$name}/', + 'core-plugin' => 'engine/Shopware/Plugins/Local/Core/{$name}/', + 'frontend-plugin' => 'engine/Shopware/Plugins/Local/Frontend/{$name}/', + 'theme' => 'templates/{$name}/', + 'plugin' => 'custom/plugins/{$name}/', + 'frontend-theme' => 'themes/Frontend/{$name}/', + ); + + /** + * Transforms the names + * @param array $vars + * @return array + */ + public function inflectPackageVars($vars) + { + if ($vars['type'] === 'shopware-theme') { + return $this->correctThemeName($vars); + } + + return $this->correctPluginName($vars); + } + + /** + * Changes the name to a camelcased combination of vendor and name + * @param array $vars + * @return array + */ + private function correctPluginName($vars) + { + $camelCasedName = preg_replace_callback('/(-[a-z])/', function ($matches) { + return strtoupper($matches[0][1]); + }, $vars['name']); + + $vars['name'] = ucfirst($vars['vendor']) . ucfirst($camelCasedName); + + return $vars; + } + + /** + * Changes the name to a underscore separated name + * @param array $vars + * @return array + */ + private function correctThemeName($vars) + { + $vars['name'] = str_replace('-', '_', $vars['name']); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/SilverStripeInstaller.php b/vendor/composer/installers/src/Composer/Installers/SilverStripeInstaller.php new file mode 100644 index 00000000000..81910e9f162 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/SilverStripeInstaller.php @@ -0,0 +1,35 @@ + '{$name}/', + 'theme' => 'themes/{$name}/', + ); + + /** + * Return the install path based on package type. + * + * Relies on built-in BaseInstaller behaviour with one exception: silverstripe/framework + * must be installed to 'sapphire' and not 'framework' if the version is <3.0.0 + * + * @param PackageInterface $package + * @param string $frameworkType + * @return string + */ + public function getInstallPath(PackageInterface $package, $frameworkType = '') + { + if ( + $package->getName() == 'silverstripe/framework' + && preg_match('/^\d+\.\d+\.\d+/', $package->getVersion()) + && version_compare($package->getVersion(), '2.999.999') < 0 + ) { + return $this->templatePath($this->locations['module'], array('name' => 'sapphire')); + } + + return parent::getInstallPath($package, $frameworkType); + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/SiteDirectInstaller.php b/vendor/composer/installers/src/Composer/Installers/SiteDirectInstaller.php new file mode 100644 index 00000000000..762d94c687d --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/SiteDirectInstaller.php @@ -0,0 +1,25 @@ + 'modules/{$vendor}/{$name}/', + 'plugin' => 'plugins/{$vendor}/{$name}/' + ); + + public function inflectPackageVars($vars) + { + return $this->parseVars($vars); + } + + protected function parseVars($vars) + { + $vars['vendor'] = strtolower($vars['vendor']) == 'sitedirect' ? 'SiteDirect' : $vars['vendor']; + $vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']); + $vars['name'] = str_replace(' ', '', ucwords($vars['name'])); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/StarbugInstaller.php b/vendor/composer/installers/src/Composer/Installers/StarbugInstaller.php new file mode 100644 index 00000000000..a31c9fda0f4 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/StarbugInstaller.php @@ -0,0 +1,12 @@ + 'modules/{$name}/', + 'theme' => 'themes/{$name}/', + 'custom-module' => 'app/modules/{$name}/', + 'custom-theme' => 'app/themes/{$name}/' + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/SyDESInstaller.php b/vendor/composer/installers/src/Composer/Installers/SyDESInstaller.php new file mode 100644 index 00000000000..8626a9bc2c9 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/SyDESInstaller.php @@ -0,0 +1,47 @@ + 'app/modules/{$name}/', + 'theme' => 'themes/{$name}/', + ); + + /** + * Format module name. + * + * Strip `sydes-` prefix and a trailing '-theme' or '-module' from package name if present. + * + * {@inerhitDoc} + */ + public function inflectPackageVars($vars) + { + if ($vars['type'] == 'sydes-module') { + return $this->inflectModuleVars($vars); + } + + if ($vars['type'] === 'sydes-theme') { + return $this->inflectThemeVars($vars); + } + + return $vars; + } + + public function inflectModuleVars($vars) + { + $vars['name'] = preg_replace('/(^sydes-|-module$)/i', '', $vars['name']); + $vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']); + $vars['name'] = str_replace(' ', '', ucwords($vars['name'])); + + return $vars; + } + + protected function inflectThemeVars($vars) + { + $vars['name'] = preg_replace('/(^sydes-|-theme$)/', '', $vars['name']); + $vars['name'] = strtolower($vars['name']); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/SyliusInstaller.php b/vendor/composer/installers/src/Composer/Installers/SyliusInstaller.php new file mode 100644 index 00000000000..4357a35bb55 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/SyliusInstaller.php @@ -0,0 +1,9 @@ + 'themes/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/Symfony1Installer.php b/vendor/composer/installers/src/Composer/Installers/Symfony1Installer.php new file mode 100644 index 00000000000..1675c4f213b --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/Symfony1Installer.php @@ -0,0 +1,26 @@ + + */ +class Symfony1Installer extends BaseInstaller +{ + protected $locations = array( + 'plugin' => 'plugins/{$name}/', + ); + + /** + * Format package name to CamelCase + */ + public function inflectPackageVars($vars) + { + $vars['name'] = preg_replace_callback('/(-[a-z])/', function ($matches) { + return strtoupper($matches[0][1]); + }, $vars['name']); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/TYPO3CmsInstaller.php b/vendor/composer/installers/src/Composer/Installers/TYPO3CmsInstaller.php new file mode 100644 index 00000000000..b1663e84369 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/TYPO3CmsInstaller.php @@ -0,0 +1,16 @@ + + */ +class TYPO3CmsInstaller extends BaseInstaller +{ + protected $locations = array( + 'extension' => 'typo3conf/ext/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/TYPO3FlowInstaller.php b/vendor/composer/installers/src/Composer/Installers/TYPO3FlowInstaller.php new file mode 100644 index 00000000000..42572f44f56 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/TYPO3FlowInstaller.php @@ -0,0 +1,38 @@ + 'Packages/Application/{$name}/', + 'framework' => 'Packages/Framework/{$name}/', + 'plugin' => 'Packages/Plugins/{$name}/', + 'site' => 'Packages/Sites/{$name}/', + 'boilerplate' => 'Packages/Boilerplates/{$name}/', + 'build' => 'Build/{$name}/', + ); + + /** + * Modify the package name to be a TYPO3 Flow style key. + * + * @param array $vars + * @return array + */ + public function inflectPackageVars($vars) + { + $autoload = $this->package->getAutoload(); + if (isset($autoload['psr-0']) && is_array($autoload['psr-0'])) { + $namespace = key($autoload['psr-0']); + $vars['name'] = str_replace('\\', '.', $namespace); + } + if (isset($autoload['psr-4']) && is_array($autoload['psr-4'])) { + $namespace = key($autoload['psr-4']); + $vars['name'] = rtrim(str_replace('\\', '.', $namespace), '.'); + } + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/TaoInstaller.php b/vendor/composer/installers/src/Composer/Installers/TaoInstaller.php new file mode 100644 index 00000000000..4f79a45f9cb --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/TaoInstaller.php @@ -0,0 +1,30 @@ + '{$name}' + ); + + public function inflectPackageVars($vars) + { + $extra = $this->package->getExtra(); + + if (array_key_exists(self::EXTRA_TAO_EXTENSION_NAME, $extra)) { + $vars['name'] = $extra[self::EXTRA_TAO_EXTENSION_NAME]; + return $vars; + } + + $vars['name'] = str_replace('extension-', '', $vars['name']); + $vars['name'] = str_replace('-', ' ', $vars['name']); + $vars['name'] = lcfirst(str_replace(' ', '', ucwords($vars['name']))); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/TastyIgniterInstaller.php b/vendor/composer/installers/src/Composer/Installers/TastyIgniterInstaller.php new file mode 100644 index 00000000000..e20e65b8371 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/TastyIgniterInstaller.php @@ -0,0 +1,32 @@ + 'extensions/{$vendor}/{$name}/', + 'theme' => 'themes/{$name}/', + ); + + /** + * Format package name. + * + * Cut off leading 'ti-ext-' or 'ti-theme-' if present. + * Strip vendor name of characters that is not alphanumeric or an underscore + * + */ + public function inflectPackageVars($vars) + { + if ($vars['type'] === 'tastyigniter-extension') { + $vars['vendor'] = preg_replace('/[^a-z0-9_]/i', '', $vars['vendor']); + $vars['name'] = preg_replace('/^ti-ext-/', '', $vars['name']); + } + + if ($vars['type'] === 'tastyigniter-theme') { + $vars['name'] = preg_replace('/^ti-theme-/', '', $vars['name']); + } + + return $vars; + } +} \ No newline at end of file diff --git a/vendor/composer/installers/src/Composer/Installers/TheliaInstaller.php b/vendor/composer/installers/src/Composer/Installers/TheliaInstaller.php new file mode 100644 index 00000000000..158af52610b --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/TheliaInstaller.php @@ -0,0 +1,12 @@ + 'local/modules/{$name}/', + 'frontoffice-template' => 'templates/frontOffice/{$name}/', + 'backoffice-template' => 'templates/backOffice/{$name}/', + 'email-template' => 'templates/email/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/TuskInstaller.php b/vendor/composer/installers/src/Composer/Installers/TuskInstaller.php new file mode 100644 index 00000000000..7c0113b85a6 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/TuskInstaller.php @@ -0,0 +1,14 @@ + + */ + class TuskInstaller extends BaseInstaller + { + protected $locations = array( + 'task' => '.tusk/tasks/{$name}/', + 'command' => '.tusk/commands/{$name}/', + 'asset' => 'assets/tusk/{$name}/', + ); + } diff --git a/vendor/composer/installers/src/Composer/Installers/UserFrostingInstaller.php b/vendor/composer/installers/src/Composer/Installers/UserFrostingInstaller.php new file mode 100644 index 00000000000..fcb414ab715 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/UserFrostingInstaller.php @@ -0,0 +1,9 @@ + 'app/sprinkles/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/VanillaInstaller.php b/vendor/composer/installers/src/Composer/Installers/VanillaInstaller.php new file mode 100644 index 00000000000..24ca645129b --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/VanillaInstaller.php @@ -0,0 +1,10 @@ + 'plugins/{$name}/', + 'theme' => 'themes/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/VgmcpInstaller.php b/vendor/composer/installers/src/Composer/Installers/VgmcpInstaller.php new file mode 100644 index 00000000000..7d90c5e6e3f --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/VgmcpInstaller.php @@ -0,0 +1,49 @@ + 'src/{$vendor}/{$name}/', + 'theme' => 'themes/{$name}/' + ); + + /** + * Format package name. + * + * For package type vgmcp-bundle, cut off a trailing '-bundle' if present. + * + * For package type vgmcp-theme, cut off a trailing '-theme' if present. + * + */ + public function inflectPackageVars($vars) + { + if ($vars['type'] === 'vgmcp-bundle') { + return $this->inflectPluginVars($vars); + } + + if ($vars['type'] === 'vgmcp-theme') { + return $this->inflectThemeVars($vars); + } + + return $vars; + } + + protected function inflectPluginVars($vars) + { + $vars['name'] = preg_replace('/-bundle$/', '', $vars['name']); + $vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']); + $vars['name'] = str_replace(' ', '', ucwords($vars['name'])); + + return $vars; + } + + protected function inflectThemeVars($vars) + { + $vars['name'] = preg_replace('/-theme$/', '', $vars['name']); + $vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']); + $vars['name'] = str_replace(' ', '', ucwords($vars['name'])); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/WHMCSInstaller.php b/vendor/composer/installers/src/Composer/Installers/WHMCSInstaller.php new file mode 100644 index 00000000000..b65dbbafd36 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/WHMCSInstaller.php @@ -0,0 +1,21 @@ + 'modules/addons/{$vendor}_{$name}/', + 'fraud' => 'modules/fraud/{$vendor}_{$name}/', + 'gateways' => 'modules/gateways/{$vendor}_{$name}/', + 'notifications' => 'modules/notifications/{$vendor}_{$name}/', + 'registrars' => 'modules/registrars/{$vendor}_{$name}/', + 'reports' => 'modules/reports/{$vendor}_{$name}/', + 'security' => 'modules/security/{$vendor}_{$name}/', + 'servers' => 'modules/servers/{$vendor}_{$name}/', + 'social' => 'modules/social/{$vendor}_{$name}/', + 'support' => 'modules/support/{$vendor}_{$name}/', + 'templates' => 'templates/{$vendor}_{$name}/', + 'includes' => 'includes/{$vendor}_{$name}/' + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/WinterInstaller.php b/vendor/composer/installers/src/Composer/Installers/WinterInstaller.php new file mode 100644 index 00000000000..cff1bf19dea --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/WinterInstaller.php @@ -0,0 +1,58 @@ + 'modules/{$name}/', + 'plugin' => 'plugins/{$vendor}/{$name}/', + 'theme' => 'themes/{$name}/' + ); + + /** + * Format package name. + * + * For package type winter-plugin, cut off a trailing '-plugin' if present. + * + * For package type winter-theme, cut off a trailing '-theme' if present. + * + */ + public function inflectPackageVars($vars) + { + if ($vars['type'] === 'winter-module') { + return $this->inflectModuleVars($vars); + } + + if ($vars['type'] === 'winter-plugin') { + return $this->inflectPluginVars($vars); + } + + if ($vars['type'] === 'winter-theme') { + return $this->inflectThemeVars($vars); + } + + return $vars; + } + + protected function inflectModuleVars($vars) + { + $vars['name'] = preg_replace('/^wn-|-module$/', '', $vars['name']); + + return $vars; + } + + protected function inflectPluginVars($vars) + { + $vars['name'] = preg_replace('/^wn-|-plugin$/', '', $vars['name']); + $vars['vendor'] = preg_replace('/[^a-z0-9_]/i', '', $vars['vendor']); + + return $vars; + } + + protected function inflectThemeVars($vars) + { + $vars['name'] = preg_replace('/^wn-|-theme$/', '', $vars['name']); + + return $vars; + } +} diff --git a/vendor/composer/installers/src/Composer/Installers/WolfCMSInstaller.php b/vendor/composer/installers/src/Composer/Installers/WolfCMSInstaller.php new file mode 100644 index 00000000000..cb387881dc9 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/WolfCMSInstaller.php @@ -0,0 +1,9 @@ + 'wolf/plugins/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/WordPressInstaller.php b/vendor/composer/installers/src/Composer/Installers/WordPressInstaller.php new file mode 100644 index 00000000000..91c46ad9961 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/WordPressInstaller.php @@ -0,0 +1,12 @@ + 'wp-content/plugins/{$name}/', + 'theme' => 'wp-content/themes/{$name}/', + 'muplugin' => 'wp-content/mu-plugins/{$name}/', + 'dropin' => 'wp-content/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/YawikInstaller.php b/vendor/composer/installers/src/Composer/Installers/YawikInstaller.php new file mode 100644 index 00000000000..27f429ff218 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/YawikInstaller.php @@ -0,0 +1,32 @@ + 'module/{$name}/', + ); + + /** + * Format package name to CamelCase + * @param array $vars + * + * @return array + */ + public function inflectPackageVars($vars) + { + $vars['name'] = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $vars['name'])); + $vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']); + $vars['name'] = str_replace(' ', '', ucwords($vars['name'])); + + return $vars; + } +} \ No newline at end of file diff --git a/vendor/composer/installers/src/Composer/Installers/ZendInstaller.php b/vendor/composer/installers/src/Composer/Installers/ZendInstaller.php new file mode 100644 index 00000000000..bde9bc8c848 --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/ZendInstaller.php @@ -0,0 +1,11 @@ + 'library/{$name}/', + 'extra' => 'extras/library/{$name}/', + 'module' => 'module/{$name}/', + ); +} diff --git a/vendor/composer/installers/src/Composer/Installers/ZikulaInstaller.php b/vendor/composer/installers/src/Composer/Installers/ZikulaInstaller.php new file mode 100644 index 00000000000..56cdf5da75d --- /dev/null +++ b/vendor/composer/installers/src/Composer/Installers/ZikulaInstaller.php @@ -0,0 +1,10 @@ + 'modules/{$vendor}-{$name}/', + 'theme' => 'themes/{$vendor}-{$name}/' + ); +} diff --git a/vendor/composer/installers/src/bootstrap.php b/vendor/composer/installers/src/bootstrap.php new file mode 100644 index 00000000000..0de276ee26c --- /dev/null +++ b/vendor/composer/installers/src/bootstrap.php @@ -0,0 +1,13 @@ + array( + 'version' => '1.4.22.0', + 'path' => $vendorDir . '/automattic/jetpack-a8c-mc-stats/src/class-a8c-mc-stats.php' + ), + 'Automattic\\Jetpack\\Admin_UI\\Admin_Menu' => array( + 'version' => '0.2.23.0', + 'path' => $vendorDir . '/automattic/jetpack-admin-ui/src/class-admin-menu.php' + ), + 'Automattic\\Jetpack\\Autoloader\\AutoloadGenerator' => array( + 'version' => '2.12.0', + 'path' => $vendorDir . '/automattic/jetpack-autoloader/src/AutoloadGenerator.php' + ), + 'Automattic\\Jetpack\\Config' => array( + 'version' => '1.15.4.0', + 'path' => $vendorDir . '/automattic/jetpack-config/src/class-config.php' + ), + 'Automattic\\Jetpack\\Connection\\Client' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-client.php' + ), + 'Automattic\\Jetpack\\Connection\\Connection_Notice' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-connection-notice.php' + ), + 'Automattic\\Jetpack\\Connection\\Error_Handler' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-error-handler.php' + ), + 'Automattic\\Jetpack\\Connection\\Initial_State' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-initial-state.php' + ), + 'Automattic\\Jetpack\\Connection\\Manager' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-manager.php' + ), + 'Automattic\\Jetpack\\Connection\\Manager_Interface' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/interface-manager.php' + ), + 'Automattic\\Jetpack\\Connection\\Nonce_Handler' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-nonce-handler.php' + ), + 'Automattic\\Jetpack\\Connection\\Package_Version' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-package-version.php' + ), + 'Automattic\\Jetpack\\Connection\\Package_Version_Tracker' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-package-version-tracker.php' + ), + 'Automattic\\Jetpack\\Connection\\Plugin' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-plugin.php' + ), + 'Automattic\\Jetpack\\Connection\\Plugin_Storage' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-plugin-storage.php' + ), + 'Automattic\\Jetpack\\Connection\\REST_Connector' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-rest-connector.php' + ), + 'Automattic\\Jetpack\\Connection\\Rest_Authentication' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-rest-authentication.php' + ), + 'Automattic\\Jetpack\\Connection\\Secrets' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-secrets.php' + ), + 'Automattic\\Jetpack\\Connection\\Server_Sandbox' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-server-sandbox.php' + ), + 'Automattic\\Jetpack\\Connection\\Tokens' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-tokens.php' + ), + 'Automattic\\Jetpack\\Connection\\Tokens_Locks' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-tokens-locks.php' + ), + 'Automattic\\Jetpack\\Connection\\Urls' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-urls.php' + ), + 'Automattic\\Jetpack\\Connection\\Utils' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-utils.php' + ), + 'Automattic\\Jetpack\\Connection\\Webhooks' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-webhooks.php' + ), + 'Automattic\\Jetpack\\Connection\\Webhooks\\Authorize_Redirect' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/webhooks/class-authorize-redirect.php' + ), + 'Automattic\\Jetpack\\Connection\\XMLRPC_Async_Call' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-xmlrpc-async-call.php' + ), + 'Automattic\\Jetpack\\Connection\\XMLRPC_Connector' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-xmlrpc-connector.php' + ), + 'Automattic\\Jetpack\\Constants' => array( + 'version' => '1.6.23.0', + 'path' => $vendorDir . '/automattic/jetpack-constants/src/class-constants.php' + ), + 'Automattic\\Jetpack\\CookieState' => array( + 'version' => '1.18.5.0', + 'path' => $vendorDir . '/automattic/jetpack-status/src/class-cookiestate.php' + ), + 'Automattic\\Jetpack\\Errors' => array( + 'version' => '1.18.5.0', + 'path' => $vendorDir . '/automattic/jetpack-status/src/class-errors.php' + ), + 'Automattic\\Jetpack\\Files' => array( + 'version' => '1.18.5.0', + 'path' => $vendorDir . '/automattic/jetpack-status/src/class-files.php' + ), + 'Automattic\\Jetpack\\Heartbeat' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-heartbeat.php' + ), + 'Automattic\\Jetpack\\Modules' => array( + 'version' => '1.18.5.0', + 'path' => $vendorDir . '/automattic/jetpack-status/src/class-modules.php' + ), + 'Automattic\\Jetpack\\Paths' => array( + 'version' => '1.18.5.0', + 'path' => $vendorDir . '/automattic/jetpack-status/src/class-paths.php' + ), + 'Automattic\\Jetpack\\Redirect' => array( + 'version' => '1.7.27.0', + 'path' => $vendorDir . '/automattic/jetpack-redirect/src/class-redirect.php' + ), + 'Automattic\\Jetpack\\Roles' => array( + 'version' => '1.4.25.0', + 'path' => $vendorDir . '/automattic/jetpack-roles/src/class-roles.php' + ), + 'Automattic\\Jetpack\\Status' => array( + 'version' => '1.18.5.0', + 'path' => $vendorDir . '/automattic/jetpack-status/src/class-status.php' + ), + 'Automattic\\Jetpack\\Status\\Cache' => array( + 'version' => '1.18.5.0', + 'path' => $vendorDir . '/automattic/jetpack-status/src/class-cache.php' + ), + 'Automattic\\Jetpack\\Status\\Host' => array( + 'version' => '1.18.5.0', + 'path' => $vendorDir . '/automattic/jetpack-status/src/class-host.php' + ), + 'Automattic\\Jetpack\\Status\\Visitor' => array( + 'version' => '1.18.5.0', + 'path' => $vendorDir . '/automattic/jetpack-status/src/class-visitor.php' + ), + 'Automattic\\Jetpack\\Terms_Of_Service' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-terms-of-service.php' + ), + 'Automattic\\Jetpack\\Tracking' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/src/class-tracking.php' + ), + 'Jetpack_IXR_Client' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/legacy/class-jetpack-ixr-client.php' + ), + 'Jetpack_IXR_ClientMulticall' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/legacy/class-jetpack-ixr-clientmulticall.php' + ), + 'Jetpack_Options' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/legacy/class-jetpack-options.php' + ), + 'Jetpack_Signature' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/legacy/class-jetpack-signature.php' + ), + 'Jetpack_Tracks_Client' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/legacy/class-jetpack-tracks-client.php' + ), + 'Jetpack_Tracks_Event' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/legacy/class-jetpack-tracks-event.php' + ), + 'Jetpack_XMLRPC_Server' => array( + 'version' => '1.58.1.0', + 'path' => $vendorDir . '/automattic/jetpack-connection/legacy/class-jetpack-xmlrpc-server.php' + ), +); diff --git a/vendor/composer/jetpack_autoload_filemap.php b/vendor/composer/jetpack_autoload_filemap.php new file mode 100644 index 00000000000..c81be8875b0 --- /dev/null +++ b/vendor/composer/jetpack_autoload_filemap.php @@ -0,0 +1,17 @@ + array( + 'version' => '11.4.0.0', + 'path' => $baseDir . '/src/StoreApi/deprecated.php' + ), + 'd0f16a186498c2ba04f1d0064fecf9cf' => array( + 'version' => '11.4.0.0', + 'path' => $baseDir . '/src/StoreApi/functions.php' + ), +); diff --git a/vendor/composer/jetpack_autoload_psr4.php b/vendor/composer/jetpack_autoload_psr4.php new file mode 100644 index 00000000000..c4d27c4300c --- /dev/null +++ b/vendor/composer/jetpack_autoload_psr4.php @@ -0,0 +1,29 @@ + array( + 'version' => '1.12.0.0', + 'path' => array( $vendorDir . '/composer/installers/src/Composer/Installers' ) + ), + 'Automattic\\WooCommerce\\StoreApi\\' => array( + 'version' => '11.4.0.0', + 'path' => array( $baseDir . '/src/StoreApi' ) + ), + 'Automattic\\WooCommerce\\Blocks\\Tests\\' => array( + 'version' => '11.4.0.0', + 'path' => array( $baseDir . '/tests/php' ) + ), + 'Automattic\\WooCommerce\\Blocks\\' => array( + 'version' => '11.4.0.0', + 'path' => array( $baseDir . '/src' ) + ), + 'Automattic\\Jetpack\\Autoloader\\' => array( + 'version' => '2.12.0', + 'path' => array( $vendorDir . '/automattic/jetpack-autoloader/src' ) + ), +); diff --git a/vendor/jetpack-autoloader/class-autoloader-handler.php b/vendor/jetpack-autoloader/class-autoloader-handler.php new file mode 100644 index 00000000000..945b219d19a --- /dev/null +++ b/vendor/jetpack-autoloader/class-autoloader-handler.php @@ -0,0 +1,147 @@ +php_autoloader = $php_autoloader; + $this->hook_manager = $hook_manager; + $this->manifest_reader = $manifest_reader; + $this->version_selector = $version_selector; + } + + /** + * Checks to see whether or not an autoloader is currently in the process of initializing. + * + * @return bool + */ + public function is_initializing() { + // If no version has been set it means that no autoloader has started initializing yet. + global $jetpack_autoloader_latest_version; + if ( ! isset( $jetpack_autoloader_latest_version ) ) { + return false; + } + + // When the version is set but the classmap is not it ALWAYS means that this is the + // latest autoloader and is being included by an older one. + global $jetpack_packages_classmap; + if ( empty( $jetpack_packages_classmap ) ) { + return true; + } + + // Version 2.4.0 added a new global and altered the reset semantics. We need to check + // the other global as well since it may also point at initialization. + // Note: We don't need to check for the class first because every autoloader that + // will set the latest version global requires this class in the classmap. + $replacing_version = $jetpack_packages_classmap[ AutoloadGenerator::class ]['version']; + if ( $this->version_selector->is_dev_version( $replacing_version ) || version_compare( $replacing_version, '2.4.0.0', '>=' ) ) { + global $jetpack_autoloader_loader; + if ( ! isset( $jetpack_autoloader_loader ) ) { + return true; + } + } + + return false; + } + + /** + * Activates an autoloader using the given plugins and activates it. + * + * @param string[] $plugins The plugins to initialize the autoloader for. + */ + public function activate_autoloader( $plugins ) { + global $jetpack_packages_psr4; + $jetpack_packages_psr4 = array(); + $this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_psr4.php', $jetpack_packages_psr4 ); + + global $jetpack_packages_classmap; + $jetpack_packages_classmap = array(); + $this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_classmap.php', $jetpack_packages_classmap ); + + global $jetpack_packages_filemap; + $jetpack_packages_filemap = array(); + $this->manifest_reader->read_manifests( $plugins, 'vendor/composer/jetpack_autoload_filemap.php', $jetpack_packages_filemap ); + + $loader = new Version_Loader( + $this->version_selector, + $jetpack_packages_classmap, + $jetpack_packages_psr4, + $jetpack_packages_filemap + ); + + $this->php_autoloader->register_autoloader( $loader ); + + // Now that the autoloader is active we can load the filemap. + $loader->load_filemap(); + } + + /** + * Resets the active autoloader and all related global state. + */ + public function reset_autoloader() { + $this->php_autoloader->unregister_autoloader(); + $this->hook_manager->reset(); + + // Clear all of the autoloader globals so that older autoloaders don't do anything strange. + global $jetpack_autoloader_latest_version; + $jetpack_autoloader_latest_version = null; + + global $jetpack_packages_classmap; + $jetpack_packages_classmap = array(); // Must be array to avoid exceptions in old autoloaders! + + global $jetpack_packages_psr4; + $jetpack_packages_psr4 = array(); // Must be array to avoid exceptions in old autoloaders! + + global $jetpack_packages_filemap; + $jetpack_packages_filemap = array(); // Must be array to avoid exceptions in old autoloaders! + } +} diff --git a/vendor/jetpack-autoloader/class-autoloader-locator.php b/vendor/jetpack-autoloader/class-autoloader-locator.php new file mode 100644 index 00000000000..5b0214c51da --- /dev/null +++ b/vendor/jetpack-autoloader/class-autoloader-locator.php @@ -0,0 +1,90 @@ +version_selector = $version_selector; + } + + /** + * Finds the path to the plugin with the latest autoloader. + * + * @param array $plugin_paths An array of plugin paths. + * @param string $latest_version The latest version reference. + * + * @return string|null + */ + public function find_latest_autoloader( $plugin_paths, &$latest_version ) { + $latest_plugin = null; + + foreach ( $plugin_paths as $plugin_path ) { + $version = $this->get_autoloader_version( $plugin_path ); + if ( ! $this->version_selector->is_version_update_required( $latest_version, $version ) ) { + continue; + } + + $latest_version = $version; + $latest_plugin = $plugin_path; + } + + return $latest_plugin; + } + + /** + * Gets the path to the autoloader. + * + * @param string $plugin_path The path to the plugin. + * + * @return string + */ + public function get_autoloader_path( $plugin_path ) { + return trailingslashit( $plugin_path ) . 'vendor/autoload_packages.php'; + } + + /** + * Gets the version for the autoloader. + * + * @param string $plugin_path The path to the plugin. + * + * @return string|null + */ + public function get_autoloader_version( $plugin_path ) { + $classmap = trailingslashit( $plugin_path ) . 'vendor/composer/jetpack_autoload_classmap.php'; + if ( ! file_exists( $classmap ) ) { + return null; + } + + $classmap = require $classmap; + if ( isset( $classmap[ AutoloadGenerator::class ] ) ) { + return $classmap[ AutoloadGenerator::class ]['version']; + } + + return null; + } +} diff --git a/vendor/jetpack-autoloader/class-autoloader.php b/vendor/jetpack-autoloader/class-autoloader.php new file mode 100644 index 00000000000..11dce58d550 --- /dev/null +++ b/vendor/jetpack-autoloader/class-autoloader.php @@ -0,0 +1,90 @@ +get( Autoloader_Handler::class ); + + // If the autoloader is already initializing it means that it has included us as the latest. + $was_included_by_autoloader = $autoloader_handler->is_initializing(); + + /** @var Plugin_Locator $plugin_locator */ + $plugin_locator = $container->get( Plugin_Locator::class ); + + /** @var Plugins_Handler $plugins_handler */ + $plugins_handler = $container->get( Plugins_Handler::class ); + + // The current plugin is the one that we are attempting to initialize here. + $current_plugin = $plugin_locator->find_current_plugin(); + + // The active plugins are those that we were able to discover on the site. This list will not + // include mu-plugins, those activated by code, or those who are hidden by filtering. We also + // want to take care to not consider the current plugin unknown if it was included by an + // autoloader. This avoids the case where a plugin will be marked "active" while deactivated + // due to it having the latest autoloader. + $active_plugins = $plugins_handler->get_active_plugins( true, ! $was_included_by_autoloader ); + + // The cached plugins are all of those that were active or discovered by the autoloader during a previous request. + // Note that it's possible this list will include plugins that have since been deactivated, but after a request + // the cache should be updated and the deactivated plugins will be removed. + $cached_plugins = $plugins_handler->get_cached_plugins(); + + // We combine the active list and cached list to preemptively load classes for plugins that are + // presently unknown but will be loaded during the request. While this may result in us considering packages in + // deactivated plugins there shouldn't be any problems as a result and the eventual consistency is sufficient. + $all_plugins = array_merge( $active_plugins, $cached_plugins ); + + // In particular we also include the current plugin to address the case where it is the latest autoloader + // but also unknown (and not cached). We don't want it in the active list because we don't know that it + // is active but we need it in the all plugins list so that it is considered by the autoloader. + $all_plugins[] = $current_plugin; + + // We require uniqueness in the array to avoid processing the same plugin more than once. + $all_plugins = array_values( array_unique( $all_plugins ) ); + + /** @var Latest_Autoloader_Guard $guard */ + $guard = $container->get( Latest_Autoloader_Guard::class ); + if ( $guard->should_stop_init( $current_plugin, $all_plugins, $was_included_by_autoloader ) ) { + return; + } + + // Initialize the autoloader using the handler now that we're ready. + $autoloader_handler->activate_autoloader( $all_plugins ); + + /** @var Hook_Manager $hook_manager */ + $hook_manager = $container->get( Hook_Manager::class ); + + // Register a shutdown handler to clean up the autoloader. + $hook_manager->add_action( 'shutdown', new Shutdown_Handler( $plugins_handler, $cached_plugins, $was_included_by_autoloader ) ); + + // phpcs:enable Generic.Commenting.DocComment.MissingShort + } +} diff --git a/vendor/jetpack-autoloader/class-container.php b/vendor/jetpack-autoloader/class-container.php new file mode 100644 index 00000000000..edee190e36e --- /dev/null +++ b/vendor/jetpack-autoloader/class-container.php @@ -0,0 +1,150 @@ + 'Hook_Manager', + ); + + /** + * A map of all the dependencies we've registered with the container and created. + * + * @var array + */ + protected $dependencies; + + /** + * The constructor. + */ + public function __construct() { + $this->dependencies = array(); + + $this->register_shared_dependencies(); + $this->register_dependencies(); + $this->initialize_globals(); + } + + /** + * Gets a dependency out of the container. + * + * @param string $class The class to fetch. + * + * @return mixed + * @throws \InvalidArgumentException When a class that isn't registered with the container is fetched. + */ + public function get( $class ) { + if ( ! isset( $this->dependencies[ $class ] ) ) { + throw new \InvalidArgumentException( "Class '$class' is not registered with the container." ); + } + + return $this->dependencies[ $class ]; + } + + /** + * Registers all of the dependencies that are shared between all instances of the autoloader. + */ + private function register_shared_dependencies() { + global $jetpack_autoloader_container_shared; + if ( ! isset( $jetpack_autoloader_container_shared ) ) { + $jetpack_autoloader_container_shared = array(); + } + + $key = self::SHARED_DEPENDENCY_KEYS[ Hook_Manager::class ]; + if ( ! isset( $jetpack_autoloader_container_shared[ $key ] ) ) { + require_once __DIR__ . '/class-hook-manager.php'; + $jetpack_autoloader_container_shared[ $key ] = new Hook_Manager(); + } + $this->dependencies[ Hook_Manager::class ] = &$jetpack_autoloader_container_shared[ $key ]; + } + + /** + * Registers all of the dependencies with the container. + */ + private function register_dependencies() { + require_once __DIR__ . '/class-path-processor.php'; + $this->dependencies[ Path_Processor::class ] = new Path_Processor(); + + require_once __DIR__ . '/class-plugin-locator.php'; + $this->dependencies[ Plugin_Locator::class ] = new Plugin_Locator( + $this->get( Path_Processor::class ) + ); + + require_once __DIR__ . '/class-version-selector.php'; + $this->dependencies[ Version_Selector::class ] = new Version_Selector(); + + require_once __DIR__ . '/class-autoloader-locator.php'; + $this->dependencies[ Autoloader_Locator::class ] = new Autoloader_Locator( + $this->get( Version_Selector::class ) + ); + + require_once __DIR__ . '/class-php-autoloader.php'; + $this->dependencies[ PHP_Autoloader::class ] = new PHP_Autoloader(); + + require_once __DIR__ . '/class-manifest-reader.php'; + $this->dependencies[ Manifest_Reader::class ] = new Manifest_Reader( + $this->get( Version_Selector::class ) + ); + + require_once __DIR__ . '/class-plugins-handler.php'; + $this->dependencies[ Plugins_Handler::class ] = new Plugins_Handler( + $this->get( Plugin_Locator::class ), + $this->get( Path_Processor::class ) + ); + + require_once __DIR__ . '/class-autoloader-handler.php'; + $this->dependencies[ Autoloader_Handler::class ] = new Autoloader_Handler( + $this->get( PHP_Autoloader::class ), + $this->get( Hook_Manager::class ), + $this->get( Manifest_Reader::class ), + $this->get( Version_Selector::class ) + ); + + require_once __DIR__ . '/class-latest-autoloader-guard.php'; + $this->dependencies[ Latest_Autoloader_Guard::class ] = new Latest_Autoloader_Guard( + $this->get( Plugins_Handler::class ), + $this->get( Autoloader_Handler::class ), + $this->get( Autoloader_Locator::class ) + ); + + // Register any classes that we will use elsewhere. + require_once __DIR__ . '/class-version-loader.php'; + require_once __DIR__ . '/class-shutdown-handler.php'; + } + + /** + * Initializes any of the globals needed by the autoloader. + */ + private function initialize_globals() { + /* + * This global was retired in version 2.9. The value is set to 'false' to maintain + * compatibility with older versions of the autoloader. + */ + global $jetpack_autoloader_including_latest; + $jetpack_autoloader_including_latest = false; + + // Not all plugins can be found using the locator. In cases where a plugin loads the autoloader + // but was not discoverable, we will record them in this array to track them as "active". + global $jetpack_autoloader_activating_plugins_paths; + if ( ! isset( $jetpack_autoloader_activating_plugins_paths ) ) { + $jetpack_autoloader_activating_plugins_paths = array(); + } + } +} diff --git a/vendor/jetpack-autoloader/class-hook-manager.php b/vendor/jetpack-autoloader/class-hook-manager.php new file mode 100644 index 00000000000..b18fc2efca5 --- /dev/null +++ b/vendor/jetpack-autoloader/class-hook-manager.php @@ -0,0 +1,76 @@ +registered_hooks = array(); + } + + /** + * Adds an action to WordPress and registers it internally. + * + * @param string $tag The name of the action which is hooked. + * @param callable $callable The function to call. + * @param int $priority Used to specify the priority of the action. + * @param int $accepted_args Used to specify the number of arguments the callable accepts. + */ + public function add_action( $tag, $callable, $priority = 10, $accepted_args = 1 ) { + $this->registered_hooks[ $tag ][] = array( + 'priority' => $priority, + 'callable' => $callable, + ); + + add_action( $tag, $callable, $priority, $accepted_args ); + } + + /** + * Adds a filter to WordPress and registers it internally. + * + * @param string $tag The name of the filter which is hooked. + * @param callable $callable The function to call. + * @param int $priority Used to specify the priority of the filter. + * @param int $accepted_args Used to specify the number of arguments the callable accepts. + */ + public function add_filter( $tag, $callable, $priority = 10, $accepted_args = 1 ) { + $this->registered_hooks[ $tag ][] = array( + 'priority' => $priority, + 'callable' => $callable, + ); + + add_filter( $tag, $callable, $priority, $accepted_args ); + } + + /** + * Removes all of the registered hooks. + */ + public function reset() { + foreach ( $this->registered_hooks as $tag => $hooks ) { + foreach ( $hooks as $hook ) { + remove_filter( $tag, $hook['callable'], $hook['priority'] ); + } + } + $this->registered_hooks = array(); + } +} diff --git a/vendor/jetpack-autoloader/class-latest-autoloader-guard.php b/vendor/jetpack-autoloader/class-latest-autoloader-guard.php new file mode 100644 index 00000000000..c8e33ee978b --- /dev/null +++ b/vendor/jetpack-autoloader/class-latest-autoloader-guard.php @@ -0,0 +1,86 @@ +plugins_handler = $plugins_handler; + $this->autoloader_handler = $autoloader_handler; + $this->autoloader_locator = $autoloader_locator; + } + + /** + * Indicates whether or not the autoloader should be initialized. Note that this function + * has the side-effect of actually loading the latest autoloader in the event that this + * is not it. + * + * @param string $current_plugin The current plugin we're checking. + * @param string[] $plugins The active plugins to check for autoloaders in. + * @param bool $was_included_by_autoloader Indicates whether or not this autoloader was included by another. + * + * @return bool True if we should stop initialization, otherwise false. + */ + public function should_stop_init( $current_plugin, $plugins, $was_included_by_autoloader ) { + global $jetpack_autoloader_latest_version; + + // We need to reset the autoloader when the plugins change because + // that means the autoloader was generated with a different list. + if ( $this->plugins_handler->have_plugins_changed( $plugins ) ) { + $this->autoloader_handler->reset_autoloader(); + } + + // When the latest autoloader has already been found we don't need to search for it again. + // We should take care however because this will also trigger if the autoloader has been + // included by an older one. + if ( isset( $jetpack_autoloader_latest_version ) && ! $was_included_by_autoloader ) { + return true; + } + + $latest_plugin = $this->autoloader_locator->find_latest_autoloader( $plugins, $jetpack_autoloader_latest_version ); + if ( isset( $latest_plugin ) && $latest_plugin !== $current_plugin ) { + require $this->autoloader_locator->get_autoloader_path( $latest_plugin ); + return true; + } + + return false; + } +} diff --git a/vendor/jetpack-autoloader/class-manifest-reader.php b/vendor/jetpack-autoloader/class-manifest-reader.php new file mode 100644 index 00000000000..e2a6240f3b1 --- /dev/null +++ b/vendor/jetpack-autoloader/class-manifest-reader.php @@ -0,0 +1,99 @@ +version_selector = $version_selector; + } + + /** + * Reads all of the manifests in the given plugin paths. + * + * @param array $plugin_paths The paths to the plugins we're loading the manifest in. + * @param string $manifest_path The path that we're loading the manifest from in each plugin. + * @param array $path_map The path map to add the contents of the manifests to. + * + * @return array $path_map The path map we've built using the manifests in each plugin. + */ + public function read_manifests( $plugin_paths, $manifest_path, &$path_map ) { + $file_paths = array_map( + function ( $path ) use ( $manifest_path ) { + return trailingslashit( $path ) . $manifest_path; + }, + $plugin_paths + ); + + foreach ( $file_paths as $path ) { + $this->register_manifest( $path, $path_map ); + } + + return $path_map; + } + + /** + * Registers a plugin's manifest file with the path map. + * + * @param string $manifest_path The absolute path to the manifest that we're loading. + * @param array $path_map The path map to add the contents of the manifest to. + */ + protected function register_manifest( $manifest_path, &$path_map ) { + if ( ! is_readable( $manifest_path ) ) { + return; + } + + $manifest = require $manifest_path; + if ( ! is_array( $manifest ) ) { + return; + } + + foreach ( $manifest as $key => $data ) { + $this->register_record( $key, $data, $path_map ); + } + } + + /** + * Registers an entry from the manifest in the path map. + * + * @param string $key The identifier for the entry we're registering. + * @param array $data The data for the entry we're registering. + * @param array $path_map The path map to add the contents of the manifest to. + */ + protected function register_record( $key, $data, &$path_map ) { + if ( isset( $path_map[ $key ]['version'] ) ) { + $selected_version = $path_map[ $key ]['version']; + } else { + $selected_version = null; + } + + if ( $this->version_selector->is_version_update_required( $selected_version, $data['version'] ) ) { + $path_map[ $key ] = array( + 'version' => $data['version'], + 'path' => $data['path'], + ); + } + } +} diff --git a/vendor/jetpack-autoloader/class-path-processor.php b/vendor/jetpack-autoloader/class-path-processor.php new file mode 100644 index 00000000000..93791d65f5b --- /dev/null +++ b/vendor/jetpack-autoloader/class-path-processor.php @@ -0,0 +1,194 @@ +get_normalized_constants(); + foreach ( $constants as $constant => $constant_path ) { + $len = strlen( $constant_path ); + if ( substr( $path, 0, $len ) !== $constant_path ) { + continue; + } + + return substr_replace( $path, '{{' . $constant . '}}', 0, $len ); + } + + return $path; + } + + /** + * Given a path this will replace any of the path constant tokens with the expanded path. + * + * @param string $tokenized_path The path we want to process. + * + * @return string The expanded path. + */ + public function untokenize_path_constants( $tokenized_path ) { + $tokenized_path = wp_normalize_path( $tokenized_path ); + + $constants = $this->get_normalized_constants(); + foreach ( $constants as $constant => $constant_path ) { + $constant = '{{' . $constant . '}}'; + + $len = strlen( $constant ); + if ( substr( $tokenized_path, 0, $len ) !== $constant ) { + continue; + } + + return $this->get_real_path( substr_replace( $tokenized_path, $constant_path, 0, $len ) ); + } + + return $tokenized_path; + } + + /** + * Given a file and an array of places it might be, this will find the absolute path and return it. + * + * @param string $file The plugin or theme file to resolve. + * @param array $directories_to_check The directories we should check for the file if it isn't an absolute path. + * + * @return string|false Returns the absolute path to the directory, otherwise false. + */ + public function find_directory_with_autoloader( $file, $directories_to_check ) { + $file = wp_normalize_path( $file ); + + if ( ! $this->is_absolute_path( $file ) ) { + $file = $this->find_absolute_plugin_path( $file, $directories_to_check ); + if ( ! isset( $file ) ) { + return false; + } + } + + // We need the real path for consistency with __DIR__ paths. + $file = $this->get_real_path( $file ); + + // phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged + $directory = @is_file( $file ) ? dirname( $file ) : $file; + if ( ! @is_file( $directory . '/vendor/composer/jetpack_autoload_classmap.php' ) ) { + return false; + } + // phpcs:enable WordPress.PHP.NoSilencedErrors.Discouraged + + return $directory; + } + + /** + * Fetches an array of normalized paths keyed by the constant they came from. + * + * @return string[] The normalized paths keyed by the constant. + */ + private function get_normalized_constants() { + $raw_constants = array( + // Order the constants from most-specific to least-specific. + 'WP_PLUGIN_DIR', + 'WPMU_PLUGIN_DIR', + 'WP_CONTENT_DIR', + 'ABSPATH', + ); + + $constants = array(); + foreach ( $raw_constants as $raw ) { + if ( ! defined( $raw ) ) { + continue; + } + + $path = wp_normalize_path( constant( $raw ) ); + if ( isset( $path ) ) { + $constants[ $raw ] = $path; + } + } + + return $constants; + } + + /** + * Indicates whether or not a path is absolute. + * + * @param string $path The path to check. + * + * @return bool True if the path is absolute, otherwise false. + */ + private function is_absolute_path( $path ) { + if ( 0 === strlen( $path ) || '.' === $path[0] ) { + return false; + } + + // Absolute paths on Windows may begin with a drive letter. + if ( preg_match( '/^[a-zA-Z]:[\/\\\\]/', $path ) ) { + return true; + } + + // A path starting with / or \ is absolute; anything else is relative. + return ( '/' === $path[0] || '\\' === $path[0] ); + } + + /** + * Given a file and a list of directories to check, this method will try to figure out + * the absolute path to the file in question. + * + * @param string $normalized_path The normalized path to the plugin or theme file to resolve. + * @param array $directories_to_check The directories we should check for the file if it isn't an absolute path. + * + * @return string|null The absolute path to the plugin file, otherwise null. + */ + private function find_absolute_plugin_path( $normalized_path, $directories_to_check ) { + // We're only able to find the absolute path for plugin/theme PHP files. + if ( ! is_string( $normalized_path ) || '.php' !== substr( $normalized_path, -4 ) ) { + return null; + } + + foreach ( $directories_to_check as $directory ) { + $normalized_check = wp_normalize_path( trailingslashit( $directory ) ) . $normalized_path; + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged + if ( @is_file( $normalized_check ) ) { + return $normalized_check; + } + } + + return null; + } + + /** + * Given a path this will figure out the real path that we should be using. + * + * @param string $path The path to resolve. + * + * @return string The resolved path. + */ + private function get_real_path( $path ) { + // We want to resolve symbolic links for consistency with __DIR__ paths. + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged + $real_path = @realpath( $path ); + if ( false === $real_path ) { + // Let the autoloader deal with paths that don't exist. + $real_path = $path; + } + + // Using realpath will make it platform-specific so we must normalize it after. + if ( $path !== $real_path ) { + $real_path = wp_normalize_path( $real_path ); + } + + return $real_path; + } +} diff --git a/vendor/jetpack-autoloader/class-php-autoloader.php b/vendor/jetpack-autoloader/class-php-autoloader.php new file mode 100644 index 00000000000..843306891e0 --- /dev/null +++ b/vendor/jetpack-autoloader/class-php-autoloader.php @@ -0,0 +1,93 @@ +unregister_autoloader(); + + // Set the global so that it can be used to load classes. + global $jetpack_autoloader_loader; + $jetpack_autoloader_loader = $version_loader; + + // Ensure that the autoloader is first to avoid contention with others. + spl_autoload_register( array( self::class, 'load_class' ), true, true ); + } + + /** + * Unregisters the active autoloader so that it will no longer autoload classes. + */ + public function unregister_autoloader() { + // Remove any v2 autoloader that we've already registered. + $autoload_chain = spl_autoload_functions(); + if ( ! $autoload_chain ) { + return; + } + foreach ( $autoload_chain as $autoloader ) { + // We can identify a v2 autoloader using the namespace. + $namespace_check = null; + + // Functions are recorded as strings. + if ( is_string( $autoloader ) ) { + $namespace_check = $autoloader; + } elseif ( is_array( $autoloader ) && is_string( $autoloader[0] ) ) { + // Static method calls have the class as the first array element. + $namespace_check = $autoloader[0]; + } else { + // Since the autoloader has only ever been a function or a static method we don't currently need to check anything else. + continue; + } + + // Check for the namespace without the generated suffix. + if ( 'Automattic\\Jetpack\\Autoloader\\jp' === substr( $namespace_check, 0, 32 ) ) { + spl_autoload_unregister( $autoloader ); + } + } + + // Clear the global now that the autoloader has been unregistered. + global $jetpack_autoloader_loader; + $jetpack_autoloader_loader = null; + } + + /** + * Loads a class file if one could be found. + * + * Note: This function is static so that the autoloader can be easily unregistered. If + * it was a class method we would have to unwrap the object to check the namespace. + * + * @param string $class_name The name of the class to autoload. + * + * @return bool Indicates whether or not a class file was loaded. + */ + public static function load_class( $class_name ) { + global $jetpack_autoloader_loader; + if ( ! isset( $jetpack_autoloader_loader ) ) { + return; + } + + $file = $jetpack_autoloader_loader->find_class_file( $class_name ); + if ( ! isset( $file ) ) { + return false; + } + + require $file; + return true; + } +} diff --git a/vendor/jetpack-autoloader/class-plugin-locator.php b/vendor/jetpack-autoloader/class-plugin-locator.php new file mode 100644 index 00000000000..f5beee388ab --- /dev/null +++ b/vendor/jetpack-autoloader/class-plugin-locator.php @@ -0,0 +1,153 @@ +path_processor = $path_processor; + } + + /** + * Finds the path to the current plugin. + * + * @return string $path The path to the current plugin. + * + * @throws \RuntimeException If the current plugin does not have an autoloader. + */ + public function find_current_plugin() { + // Escape from `vendor/__DIR__` to root plugin directory. + $plugin_directory = dirname( dirname( __DIR__ ) ); + + // Use the path processor to ensure that this is an autoloader we're referencing. + $path = $this->path_processor->find_directory_with_autoloader( $plugin_directory, array() ); + if ( false === $path ) { + throw new \RuntimeException( 'Failed to locate plugin ' . $plugin_directory ); + } + + return $path; + } + + /** + * Checks a given option for plugin paths. + * + * @param string $option_name The option that we want to check for plugin information. + * @param bool $site_option Indicates whether or not we want to check the site option. + * + * @return array $plugin_paths The list of absolute paths we've found. + */ + public function find_using_option( $option_name, $site_option = false ) { + $raw = $site_option ? get_site_option( $option_name ) : get_option( $option_name ); + if ( false === $raw ) { + return array(); + } + + return $this->convert_plugins_to_paths( $raw ); + } + + /** + * Checks for plugins in the `action` request parameter. + * + * @param string[] $allowed_actions The actions that we're allowed to return plugins for. + * + * @return array $plugin_paths The list of absolute paths we've found. + */ + public function find_using_request_action( $allowed_actions ) { + /** + * Note: we're not actually checking the nonce here because it's too early + * in the execution. The pluggable functions are not yet loaded to give + * plugins a chance to plug their versions. Therefore we're doing the bare + * minimum: checking whether the nonce exists and it's in the right place. + * The request will fail later if the nonce doesn't pass the check. + */ + if ( empty( $_REQUEST['_wpnonce'] ) ) { + return array(); + } + + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Validated just below. + $action = isset( $_REQUEST['action'] ) ? wp_unslash( $_REQUEST['action'] ) : false; + if ( ! in_array( $action, $allowed_actions, true ) ) { + return array(); + } + + $plugin_slugs = array(); + switch ( $action ) { + case 'activate': + case 'deactivate': + if ( empty( $_REQUEST['plugin'] ) ) { + break; + } + + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Validated by convert_plugins_to_paths. + $plugin_slugs[] = wp_unslash( $_REQUEST['plugin'] ); + break; + + case 'activate-selected': + case 'deactivate-selected': + if ( empty( $_REQUEST['checked'] ) ) { + break; + } + + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Validated by convert_plugins_to_paths. + $plugin_slugs = wp_unslash( $_REQUEST['checked'] ); + break; + } + + return $this->convert_plugins_to_paths( $plugin_slugs ); + } + + /** + * Given an array of plugin slugs or paths, this will convert them to absolute paths and filter + * out the plugins that are not directory plugins. Note that array keys will also be included + * if they are plugin paths! + * + * @param string[] $plugins Plugin paths or slugs to filter. + * + * @return string[] + */ + private function convert_plugins_to_paths( $plugins ) { + if ( ! is_array( $plugins ) || empty( $plugins ) ) { + return array(); + } + + // We're going to look for plugins in the standard directories. + $path_constants = array( WP_PLUGIN_DIR, WPMU_PLUGIN_DIR ); + + $plugin_paths = array(); + foreach ( $plugins as $key => $value ) { + $path = $this->path_processor->find_directory_with_autoloader( $key, $path_constants ); + if ( $path ) { + $plugin_paths[] = $path; + } + + $path = $this->path_processor->find_directory_with_autoloader( $value, $path_constants ); + if ( $path ) { + $plugin_paths[] = $path; + } + } + + return $plugin_paths; + } +} diff --git a/vendor/jetpack-autoloader/class-plugins-handler.php b/vendor/jetpack-autoloader/class-plugins-handler.php new file mode 100644 index 00000000000..2c7ea0f524d --- /dev/null +++ b/vendor/jetpack-autoloader/class-plugins-handler.php @@ -0,0 +1,164 @@ +plugin_locator = $plugin_locator; + $this->path_processor = $path_processor; + } + + /** + * Gets all of the active plugins we can find. + * + * @param bool $include_deactivating When true, plugins deactivating this request will be considered active. + * @param bool $record_unknown When true, the current plugin will be marked as active and recorded when unknown. + * + * @return string[] + */ + public function get_active_plugins( $include_deactivating, $record_unknown ) { + global $jetpack_autoloader_activating_plugins_paths; + + // We're going to build a unique list of plugins from a few different sources + // to find all of our "active" plugins. While we need to return an integer + // array, we're going to use an associative array internally to reduce + // the amount of time that we're going to spend checking uniqueness + // and merging different arrays together to form the output. + $active_plugins = array(); + + // Make sure that plugins which have activated this request are considered as "active" even though + // they probably won't be present in any option. + if ( is_array( $jetpack_autoloader_activating_plugins_paths ) ) { + foreach ( $jetpack_autoloader_activating_plugins_paths as $path ) { + $active_plugins[ $path ] = $path; + } + } + + // This option contains all of the plugins that have been activated. + $plugins = $this->plugin_locator->find_using_option( 'active_plugins' ); + foreach ( $plugins as $path ) { + $active_plugins[ $path ] = $path; + } + + // This option contains all of the multisite plugins that have been activated. + if ( is_multisite() ) { + $plugins = $this->plugin_locator->find_using_option( 'active_sitewide_plugins', true ); + foreach ( $plugins as $path ) { + $active_plugins[ $path ] = $path; + } + } + + // These actions contain plugins that are being activated/deactivated during this request. + $plugins = $this->plugin_locator->find_using_request_action( array( 'activate', 'activate-selected', 'deactivate', 'deactivate-selected' ) ); + foreach ( $plugins as $path ) { + $active_plugins[ $path ] = $path; + } + + // When the current plugin isn't considered "active" there's a problem. + // Since we're here, the plugin is active and currently being loaded. + // We can support this case (mu-plugins and non-standard activation) + // by adding the current plugin to the active list and marking it + // as an unknown (activating) plugin. This also has the benefit + // of causing a reset because the active plugins list has + // been changed since it was saved in the global. + $current_plugin = $this->plugin_locator->find_current_plugin(); + if ( $record_unknown && ! in_array( $current_plugin, $active_plugins, true ) ) { + $active_plugins[ $current_plugin ] = $current_plugin; + $jetpack_autoloader_activating_plugins_paths[] = $current_plugin; + } + + // When deactivating plugins aren't desired we should entirely remove them from the active list. + if ( ! $include_deactivating ) { + // These actions contain plugins that are being deactivated during this request. + $plugins = $this->plugin_locator->find_using_request_action( array( 'deactivate', 'deactivate-selected' ) ); + foreach ( $plugins as $path ) { + unset( $active_plugins[ $path ] ); + } + } + + // Transform the array so that we don't have to worry about the keys interacting with other array types later. + return array_values( $active_plugins ); + } + + /** + * Gets all of the cached plugins if there are any. + * + * @return string[] + */ + public function get_cached_plugins() { + $cached = get_transient( self::TRANSIENT_KEY ); + if ( ! is_array( $cached ) || empty( $cached ) ) { + return array(); + } + + // We need to expand the tokens to an absolute path for this webserver. + return array_map( array( $this->path_processor, 'untokenize_path_constants' ), $cached ); + } + + /** + * Saves the plugin list to the cache. + * + * @param array $plugins The plugin list to save to the cache. + */ + public function cache_plugins( $plugins ) { + // We store the paths in a tokenized form so that that webservers with different absolute paths don't break. + $plugins = array_map( array( $this->path_processor, 'tokenize_path_constants' ), $plugins ); + + set_transient( self::TRANSIENT_KEY, $plugins ); + } + + /** + * Checks to see whether or not the plugin list given has changed when compared to the + * shared `$jetpack_autoloader_cached_plugin_paths` global. This allows us to deal + * with cases where the active list may change due to filtering.. + * + * @param string[] $plugins The plugins list to check against the global cache. + * + * @return bool True if the plugins have changed, otherwise false. + */ + public function have_plugins_changed( $plugins ) { + global $jetpack_autoloader_cached_plugin_paths; + + if ( $jetpack_autoloader_cached_plugin_paths !== $plugins ) { + $jetpack_autoloader_cached_plugin_paths = $plugins; + return true; + } + + return false; + } +} diff --git a/vendor/jetpack-autoloader/class-shutdown-handler.php b/vendor/jetpack-autoloader/class-shutdown-handler.php new file mode 100644 index 00000000000..91fec5a1c87 --- /dev/null +++ b/vendor/jetpack-autoloader/class-shutdown-handler.php @@ -0,0 +1,92 @@ +plugins_handler = $plugins_handler; + $this->cached_plugins = $cached_plugins; + $this->was_included_by_autoloader = $was_included_by_autoloader; + } + + /** + * Handles the shutdown of the autoloader. + */ + public function __invoke() { + // Don't save a broken cache if an error happens during some plugin's initialization. + if ( ! did_action( 'plugins_loaded' ) ) { + // Ensure that the cache is emptied to prevent consecutive failures if the cache is to blame. + if ( ! empty( $this->cached_plugins ) ) { + $this->plugins_handler->cache_plugins( array() ); + } + + return; + } + + // Load the active plugins fresh since the list we pulled earlier might not contain + // plugins that were activated but did not reset the autoloader. This happens + // when a plugin is in the cache but not "active" when the autoloader loads. + // We also want to make sure that plugins which are deactivating are not + // considered "active" so that they will be removed from the cache now. + try { + $active_plugins = $this->plugins_handler->get_active_plugins( false, ! $this->was_included_by_autoloader ); + } catch ( \Exception $ex ) { + // When the package is deleted before shutdown it will throw an exception. + // In the event this happens we should erase the cache. + if ( ! empty( $this->cached_plugins ) ) { + $this->plugins_handler->cache_plugins( array() ); + } + return; + } + + // The paths should be sorted for easy comparisons with those loaded from the cache. + // Note we don't need to sort the cached entries because they're already sorted. + sort( $active_plugins ); + + // We don't want to waste time saving a cache that hasn't changed. + if ( $this->cached_plugins === $active_plugins ) { + return; + } + + $this->plugins_handler->cache_plugins( $active_plugins ); + } +} diff --git a/vendor/jetpack-autoloader/class-version-loader.php b/vendor/jetpack-autoloader/class-version-loader.php new file mode 100644 index 00000000000..10a95fcc593 --- /dev/null +++ b/vendor/jetpack-autoloader/class-version-loader.php @@ -0,0 +1,164 @@ +version_selector = $version_selector; + $this->classmap = $classmap; + $this->psr4_map = $psr4_map; + $this->filemap = $filemap; + } + + /** + * Finds the file path for the given class. + * + * @param string $class_name The class to find. + * + * @return string|null $file_path The path to the file if found, null if no class was found. + */ + public function find_class_file( $class_name ) { + $data = $this->select_newest_file( + isset( $this->classmap[ $class_name ] ) ? $this->classmap[ $class_name ] : null, + $this->find_psr4_file( $class_name ) + ); + if ( ! isset( $data ) ) { + return null; + } + + return $data['path']; + } + + /** + * Load all of the files in the filemap. + */ + public function load_filemap() { + if ( empty( $this->filemap ) ) { + return; + } + + foreach ( $this->filemap as $file_identifier => $file_data ) { + if ( empty( $GLOBALS['__composer_autoload_files'][ $file_identifier ] ) ) { + require_once $file_data['path']; + + $GLOBALS['__composer_autoload_files'][ $file_identifier ] = true; + } + } + } + + /** + * Compares different class sources and returns the newest. + * + * @param array|null $classmap_data The classmap class data. + * @param array|null $psr4_data The PSR-4 class data. + * + * @return array|null $data + */ + private function select_newest_file( $classmap_data, $psr4_data ) { + if ( ! isset( $classmap_data ) ) { + return $psr4_data; + } elseif ( ! isset( $psr4_data ) ) { + return $classmap_data; + } + + if ( $this->version_selector->is_version_update_required( $classmap_data['version'], $psr4_data['version'] ) ) { + return $psr4_data; + } + + return $classmap_data; + } + + /** + * Finds the file for a given class in a PSR-4 namespace. + * + * @param string $class_name The class to find. + * + * @return array|null $data The version and path path to the file if found, null otherwise. + */ + private function find_psr4_file( $class_name ) { + if ( ! isset( $this->psr4_map ) ) { + return null; + } + + // Don't bother with classes that have no namespace. + $class_index = strrpos( $class_name, '\\' ); + if ( ! $class_index ) { + return null; + } + $class_for_path = str_replace( '\\', '/', $class_name ); + + // Search for the namespace by iteratively cutting off the last segment until + // we find a match. This allows us to check the most-specific namespaces + // first as well as minimize the amount of time spent looking. + for ( + $class_namespace = substr( $class_name, 0, $class_index ); + ! empty( $class_namespace ); + $class_namespace = substr( $class_namespace, 0, strrpos( $class_namespace, '\\' ) ) + ) { + $namespace = $class_namespace . '\\'; + if ( ! isset( $this->psr4_map[ $namespace ] ) ) { + continue; + } + $data = $this->psr4_map[ $namespace ]; + + foreach ( $data['path'] as $path ) { + $path .= '/' . substr( $class_for_path, strlen( $namespace ) ) . '.php'; + if ( file_exists( $path ) ) { + return array( + 'version' => $data['version'], + 'path' => $path, + ); + } + } + } + + return null; + } +} diff --git a/vendor/jetpack-autoloader/class-version-selector.php b/vendor/jetpack-autoloader/class-version-selector.php new file mode 100644 index 00000000000..3291db71d86 --- /dev/null +++ b/vendor/jetpack-autoloader/class-version-selector.php @@ -0,0 +1,69 @@ +is_dev_version( $selected_version ) ) { + return false; + } + + if ( $this->is_dev_version( $compare_version ) ) { + if ( $use_dev_versions ) { + return true; + } else { + return false; + } + } + + if ( version_compare( $selected_version, $compare_version, '<' ) ) { + return true; + } + + return false; + } + + /** + * Checks whether the given package version is a development version. + * + * @param String $version The package version. + * + * @return bool True if the version is a dev version, else false. + */ + public function is_dev_version( $version ) { + if ( 'dev-' === substr( $version, 0, 4 ) || '9999999-dev' === $version ) { + return true; + } + + return false; + } +}