/home/fresvfqn/crimescenecleaningupsuffolkcounty.com/wp-content.tar
index.php                                                                                           0000644                 00000000034 15100623270 0006355 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       <?php
// Silence is golden.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    litespeed/robots.txt                                                                                0000644                 00000000032 15100623270 0010562 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       User-agent: *
Disallow: /
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      litespeed/qc.last.vercheck                                                                          0000644                 00000000012 15100623270 0011570 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       1760779544                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      litespeed/qc.curr.vercheck                                                                          0000644                 00000000001 15100623270 0011576 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               litespeed/debug/index.php                                                                           0000644                 00000000033 15100623270 0011420 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       <?php // Silence is golden.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     plugins/akismet/class-akismet-compatible-plugins.php                                                0000644                 00000017524 15100623270 0016734 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       <?php
/**
 * Handles compatibility checks for Akismet with other plugins.
 *
 * @package Akismet
 * @since 5.4.0
 */
declare( strict_types = 1 );
// Following existing Akismet convention for file naming.
// phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
/**
 * Class for managing compatibility checks for Akismet with other plugins.
 *
 * This class includes methods for determining whether specific plugins are
 * installed and active relative to the ability to work with Akismet.
 */
class Akismet_Compatible_Plugins {
	/**
	 * The endpoint for the compatible plugins API.
	 *
	 * @var string
	 */
	protected const COMPATIBLE_PLUGIN_ENDPOINT = 'https://rest.akismet.com/1.2/compatible-plugins';
	/**
	 * The error key for the compatible plugins API error.
	 *
	 * @var string
	 */
	protected const COMPATIBLE_PLUGIN_API_ERROR = 'akismet_compatible_plugins_api_error';
	/**
	 * The valid fields for a compatible plugin object.
	 *
	 * @var array
	 */
	protected const COMPATIBLE_PLUGIN_FIELDS = array(
		'slug',
		'name',
		'logo',
		'help_url',
		'path',
	);
	/**
	 * The cache key for the compatible plugins.
	 *
	 * @var string
	 */
	protected const CACHE_KEY = 'akismet_compatible_plugin_list';
	/**
	 * The cache group for things cached in this class.
	 *
	 * @var string
	 */
	protected const CACHE_GROUP = 'akismet_compatible_plugins';
	/**
	 * How many plugins should be visible by default?
	 *
	 * @var int
	 */
	public const DEFAULT_VISIBLE_PLUGIN_COUNT = 2;
	/**
	 * Get the list of active, installed compatible plugins.
	 *
	 * @return WP_Error|array {
	 *     Array of active, installed compatible plugins with their metadata.
	 *     @type string $name     The display name of the plugin
	 *     @type string $help_url URL to the plugin's help documentation
	 *     @type string $logo     URL or path to the plugin's logo
	 * }
	 */
	public static function get_installed_compatible_plugins() {
		// Retrieve and validate the full compatible plugins list.
		$compatible_plugins = static::get_compatible_plugins();
		if ( empty( $compatible_plugins ) ) {
			return new WP_Error(
				self::COMPATIBLE_PLUGIN_API_ERROR,
				__( 'Error getting compatible plugins.', 'akismet' )
			);
		}
		// Retrieve all installed plugins once.
		$all_plugins = get_plugins();
		// Build list of compatible plugins that are both installed and active.
		$active_compatible_plugins = array();
		foreach ( $compatible_plugins as $slug => $data ) {
			$path = $data['path'];
			// Skip if not installed.
			if ( ! isset( $all_plugins[ $path ] ) ) {
				continue;
			}
			// Check activation: per-site or network-wide (multisite).
			$site_active    = is_plugin_active( $path );
			$network_active = is_multisite() && is_plugin_active_for_network( $path );
			if ( $site_active || $network_active ) {
				$active_compatible_plugins[ $slug ] = $data;
			}
		}
		return $active_compatible_plugins;
	}
	/**
	 * Initializes action hooks for the class.
	 *
	 * @return void
	 */
	public static function init(): void {
		add_action( 'activated_plugin', array( static::class, 'handle_plugin_change' ), true );
		add_action( 'deactivated_plugin', array( static::class, 'handle_plugin_change' ), true );
	}
	/**
	 * Handles plugin activation and deactivation events.
	 *
	 * @param string $plugin The path to the main plugin file from plugins directory.
	 * @return void
	 */
	public static function handle_plugin_change( string $plugin ): void {
		$cached_plugins = static::get_cached_plugins();
		/**
		 * Terminate if nothing's cached.
		 */
		if ( false === $cached_plugins ) {
			return;
		}
		$plugin_change_should_invalidate_cache = in_array( $plugin, array_column( $cached_plugins, 'path' ) );
		/**
		 * Purge the cache if the plugin is activated or deactivated.
		 */
		if ( $plugin_change_should_invalidate_cache ) {
			static::purge_cache();
		}
	}
	/**
	 * Gets plugins that are compatible with Akismet from the Akismet API.
	 *
	 * @return array
	 */
	private static function get_compatible_plugins(): array {
		// Return cached result if present (false => cache miss; empty array is valid).
		$cached_plugins = static::get_cached_plugins();
		if ( $cached_plugins ) {
			return $cached_plugins;
		}
		$response = wp_remote_get(
			self::COMPATIBLE_PLUGIN_ENDPOINT
		);
		$sanitized = static::validate_compatible_plugin_response( $response );
		if ( false === $sanitized ) {
			return array();
		}
		/**
		 * Sets local static associative array of plugin data keyed by plugin slug.
		 */
		$compatible_plugins = array();
		foreach ( $sanitized as $plugin ) {
			$compatible_plugins[ $plugin['slug'] ] = $plugin;
		}
		static::set_cached_plugins( $compatible_plugins );
		return $compatible_plugins;
	}
	/**
	 * Validates a response object from the Compatible Plugins API.
	 *
	 * @param array|WP_Error $response
	 * @return array|false
	 */
	private static function validate_compatible_plugin_response( $response ) {
		/**
		 * Terminates the function if the response is a WP_Error object.
		 */
		if ( is_wp_error( $response ) ) {
			return false;
		}
		/**
		 * The response returned is an array of header + body string data.
		 * This pops off the body string for processing.
		 */
		$response_body = wp_remote_retrieve_body( $response );
		if ( empty( $response_body ) ) {
			return false;
		}
		$plugins = json_decode( $response_body, true );
		if ( false === is_array( $plugins ) ) {
			return false;
		}
		foreach ( $plugins as $plugin ) {
			if ( ! is_array( $plugin ) ) {
				/**
				 * Skips to the next iteration if for some reason the plugin is not an array.
				 */
				continue;
			}
			// Ensure that the plugin config read in from the API has all the required fields.
			$plugin_key_count = count(
				array_intersect_key( $plugin, array_flip( static::COMPATIBLE_PLUGIN_FIELDS ) )
			);
			$does_not_have_all_required_fields = ! (
				$plugin_key_count === count( static::COMPATIBLE_PLUGIN_FIELDS )
			);
			if ( $does_not_have_all_required_fields ) {
				return false;
			}
			if ( false === static::has_valid_plugin_path( $plugin['path'] ) ) {
				return false;
			}
		}
		return static::sanitize_compatible_plugin_response( $plugins );
	}
	/**
	 * Validates a plugin path format.
	 *
	 * The path should be in the format of 'plugin-name/plugin-name.php'.
	 * Allows alphanumeric characters, dashes, underscores, and optional dots in folder names.
	 *
	 * @param string $path
	 * @return bool
	 */
	private static function has_valid_plugin_path( string $path ): bool {
		return preg_match( '/^[a-zA-Z0-9._-]+\/[a-zA-Z0-9_-]+\.php$/', $path ) === 1;
	}
	/**
	 * Sanitizes a response object from the Compatible Plugins API.
	 *
	 * @param array $plugins
	 * @return array
	 */
	private static function sanitize_compatible_plugin_response( array $plugins = array() ): array {
		foreach ( $plugins as $key => $plugin ) {
			$plugins[ $key ]             = array_map( 'sanitize_text_field', $plugin );
			$plugins[ $key ]['help_url'] = sanitize_url( $plugins[ $key ]['help_url'] );
			$plugins[ $key ]['logo']     = sanitize_url( $plugins[ $key ]['logo'] );
		}
		return $plugins;
	}
	/**
	 * @param array $plugins
	 * @return bool
	 */
	private static function set_cached_plugins( array $plugins ): bool {
		$_blog_id = (int) get_current_blog_id();
		return wp_cache_set(
			static::CACHE_KEY . "_$_blog_id",
			$plugins,
			static::CACHE_GROUP . "_$_blog_id",
			DAY_IN_SECONDS
		);
	}
	/**
	 * Attempts to get cached compatible plugins.
	 *
	 * @return mixed|false
	 */
	private static function get_cached_plugins() {
		$_blog_id = (int) get_current_blog_id();
		return wp_cache_get(
			static::CACHE_KEY . "_$_blog_id",
			static::CACHE_GROUP . "_$_blog_id"
		);
	}
	/**
	 * Purges the cache for the compatible plugins.
	 *
	 * @return bool
	 */
	private static function purge_cache(): bool {
		$_blog_id = (int) get_current_blog_id();
		return wp_cache_delete(
			static::CACHE_KEY . "_$_blog_id",
			static::CACHE_GROUP . "_$_blog_id"
		);
	}
}
                                                                                                                                                                            plugins/akismet/akismet.php                                                                         0000644                 00000005305 15100623270 0012027 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       <?php
/**
 * @package Akismet
 */
/*
Plugin Name: Akismet Anti-spam: Spam Protection
Plugin URI: https://akismet.com/
Description: Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from spam</strong>. Akismet Anti-spam keeps your site protected even while you sleep. To get started: activate the Akismet plugin and then go to your Akismet Settings page to set up your API key.
Version: 5.5
Requires at least: 5.8
Requires PHP: 7.2
Author: Automattic - Anti-spam Team
Author URI: https://automattic.com/wordpress-plugins/
License: GPLv2 or later
Text Domain: akismet
*/
/*
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.
Copyright 2005-2025 Automattic, Inc.
*/
// Make sure we don't expose any info if called directly
if ( ! function_exists( 'add_action' ) ) {
	echo 'Hi there!  I\'m just a plugin, not much I can do when called directly.';
	exit;
}
define( 'AKISMET_VERSION', '5.5' );
define( 'AKISMET__MINIMUM_WP_VERSION', '5.8' );
define( 'AKISMET__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'AKISMET_DELETE_LIMIT', 10000 );
register_activation_hook( __FILE__, array( 'Akismet', 'plugin_activation' ) );
register_deactivation_hook( __FILE__, array( 'Akismet', 'plugin_deactivation' ) );
require_once AKISMET__PLUGIN_DIR . 'class.akismet.php';
require_once AKISMET__PLUGIN_DIR . 'class.akismet-widget.php';
require_once AKISMET__PLUGIN_DIR . 'class.akismet-rest-api.php';
require_once AKISMET__PLUGIN_DIR . 'class-akismet-compatible-plugins.php';
add_action( 'init', array( 'Akismet', 'init' ) );
add_action( 'rest_api_init', array( 'Akismet_REST_API', 'init' ) );
add_action( 'init', array( 'Akismet_Compatible_Plugins', 'init' ) );
if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
	require_once AKISMET__PLUGIN_DIR . 'class.akismet-admin.php';
	add_action( 'init', array( 'Akismet_Admin', 'init' ) );
}
// add wrapper class around deprecated akismet functions that are referenced elsewhere
require_once AKISMET__PLUGIN_DIR . 'wrapper.php';
if ( defined( 'WP_CLI' ) && WP_CLI ) {
	require_once AKISMET__PLUGIN_DIR . 'class.akismet-cli.php';
}
                                                                                                                                                                                                                                                                                                                           plugins/akismet/changelog.txt                                                                       0000644                 00000055523 15100623270 0012360 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       === Akismet Anti-spam ===
== Archived Changelog Entries ==
This file contains older changelog entries, so we can keep the size of the standard WordPress readme.txt file reasonable.
For the latest changes, please see the "Changelog" section of the [readme.txt file](https://plugins.svn.wordpress.org/akismet/trunk/readme.txt).
= 4.2.5 =
*Release Date - 11 July 2022*
* Fixed a bug that added unnecessary comment history entries after comment rechecks.
* Added a notice that displays when WP-Cron is disabled and might be affecting comment rechecks.
= 4.2.4 =
*Release Date - 20 May 2022*
* Improved translator instructions for comment history.
* Bumped the "Tested up to" tag to WP 6.0.
= 4.2.3 =
*Release Date - 25 April 2022*
* Improved compatibility with Fluent Forms
* Fixed missing translation domains
* Updated stats URL.
* Improved accessibility of elements on the config page.
= 4.2.2 =
*Release Date - 24 January 2022*
* Improved compatibility with Formidable Forms
* Fixed a bug that could cause issues when multiple contact forms appear on one page.
* Updated delete_comment and deleted_comment actions to pass two arguments to match WordPress core since 4.9.0.
* Added a filter that allows comment types to be excluded when counting users' approved comments.
= 4.2.1 =
*Release Date - 1 October 2021*
* Fixed a bug causing AMP validation to fail on certain pages with forms.
= 4.2 =
*Release Date - 30 September 2021*
* Added links to additional information on API usage notifications.
* Reduced the number of network requests required for a comment page when running Akismet.
* Improved compatibility with the most popular contact form plugins.
* Improved API usage buttons for clarity on what upgrade is needed.
= 4.1.12 =
*Release Date - 3 September 2021*
* Fixed "Use of undefined constant" notice.
* Improved styling of alert notices.
= 4.1.11 =
*Release Date - 23 August 2021*
* Added support for Akismet API usage notifications on Akismet settings and edit-comments admin pages.
* Added support for the deleted_comment action when bulk-deleting comments from Spam.
= 4.1.10 =
*Release Date - 6 July 2021*
* Simplified the code around checking comments in REST API and XML-RPC requests.
* Updated Plus plan terminology in notices to match current subscription names.
* Added `rel="noopener"` to the widget link to avoid warnings in Google Lighthouse.
* Set the Akismet JavaScript as deferred instead of async to improve responsiveness.
* Improved the preloading of screenshot popups on the edit comments admin page.
= 4.1.9 =
*Release Date - 2 March 2021*
* Improved handling of pingbacks in XML-RPC multicalls
= 4.1.8 =
*Release Date - 6 January 2021*
* Fixed missing fields in submit-spam and submit-ham calls that could lead to reduced accuracy.
* Fixed usage of deprecated jQuery function.
= 4.1.7 =
*Release Date - 22 October 2020*
* Show the "Set up your Akismet account" banner on the comments admin screen, where it's relevant to mention if Akismet hasn't been configured.
* Don't use wp_blacklist_check when the new wp_check_comment_disallowed_list function is available.
= 4.1.6 =
*Release Date - 4 June 2020*
* Disable "Check for Spam" button until the page is loaded to avoid errors with clicking through to queue recheck endpoint directly.
* Added filter "akismet_enable_mshots" to allow disabling screenshot popups on the edit comments admin page.
= 4.1.5 =
*Release Date - 29 April 2020*
* Based on user feedback, we have dropped the in-admin notice explaining the availability of the "privacy notice" option in the AKismet settings screen. The option itself is available, but after displaying the notice for the last 2 years, it is now considered a known fact.
* Updated the "Requires at least" to WP 4.6, based on recommendations from https://wp-info.org/tools/checkplugini18n.php?slug=akismet
* Moved older changelog entries to a separate file to keep the size of this readme reasonable, also based on recommendations from https://wp-info.org/tools/checkplugini18n.php?slug=akismet
= 4.1.4 =
*Release Date - 17 March 2020*
* Only redirect to the Akismet setup screen upon plugin activation if the plugin was activated manually from within the plugin-related screens, to help users with non-standard install workflows, like WP-CLI.
* Update the layout of the initial setup screen to be more readable on small screens.
* If no API key has been entered, don't run code that expects an API key.
* Improve the readability of the comment history entries.
* Don't modify the comment form HTML if no API key has been set.
= 4.1.3 =
*Release Date - 31 October 2019*
* Prevented an attacker from being able to cause a user to unknowingly recheck their Pending comments for spam.
* Improved compatibility with Jetpack 7.7+.
* Updated the plugin activation page to use consistent language and markup.
* Redirecting users to the Akismet connnection/settings screen upon plugin activation, in an effort to make it easier for people to get setup.
= 4.1.2 =
*Release Date - 14 May 2019*
* Fixed a conflict between the Akismet setup banner and other plugin notices.
* Reduced the number of API requests made by the plugin when attempting to verify the API key.
* Include additional data in the pingback pre-check API request to help make the stats more accurate.
* Fixed a bug that was enabling the "Check for Spam" button when no comments were eligible to be checked.
* Improved Akismet's AMP compatibility.
= 4.1.1 =
*Release Date - 31 January 2019*
* Fixed the "Setup Akismet" notice so it resizes responsively.
* Only highlight the "Save Changes" button in the Akismet config when changes have been made.
* The count of comments in your spam queue shown on the dashboard show now always be up-to-date.
= 4.1 =
*Release Date - 12 November 2018*
* Added a WP-CLI method for retrieving stats.
* Hooked into the new "Personal Data Eraser" functionality from WordPress 4.9.6.
* Added functionality to clear outdated alerts from Akismet.com.
= 4.0.8 =
*Release Date - 19 June 2018*
* Improved the grammar and consistency of the in-admin privacy related notes (notice and config).
* Revised in-admin explanation of the comment form privacy notice to make its usage clearer.
* Added `rel="nofollow noopener"` to the comment form privacy notice to improve SEO and security.
= 4.0.7 =
*Release Date - 28 May 2018*
* Based on user feedback, the link on "Learn how your comment data is processed." in the optional privacy notice now has a `target` of `_blank` and opens in a new tab/window.
* Updated the in-admin privacy notice to use the term "comment" instead of "contact" in "Akismet can display a notice to your users under your comment forms."
* Only show in-admin privacy notice if Akismet has an API Key configured
= 4.0.6 =
*Release Date - 26 May 2018*
* Moved away from using `empty( get_option() )` to instantiating a variable to be compatible with older versions of PHP (5.3, 5.4, etc).
= 4.0.5 =
*Release Date - 26 May 2018*
* Corrected version number after tagging. Sorry...
= 4.0.4 =
*Release Date - 26 May 2018*
* Added a hook to provide Akismet-specific privacy information for a site's privacy policy.
* Added tools to control the display of a privacy related notice under comment forms.
* Fixed HTML in activation failure message to close META and HEAD tag properly.
* Fixed a bug that would sometimes prevent Akismet from being correctly auto-configured.
= 4.0.3 =
*Release Date - 19 February 2018*
* Added a scheduled task to remove entries in wp_commentmeta that no longer have corresponding comments in wp_comments.
* Added a new `akismet_batch_delete_count` action to the batch delete methods for people who'd like to keep track of the numbers of records being processed by those methods.
= 4.0.2 =
*Release Date - 18 December 2017*
* Fixed a bug that could cause Akismet to recheck a comment that has already been manually approved or marked as spam.
* Fixed a bug that could cause Akismet to claim that some comments are still waiting to be checked when no comments are waiting to be checked.
= 4.0.1 =
*Release Date - 6 November 2017*
* Fixed a bug that could prevent some users from connecting Akismet via their Jetpack connection.
* Ensured that any pending Akismet-related events are unscheduled if the plugin is deactivated.
* Allow some JavaScript to be run asynchronously to avoid affecting page render speeds.
= 4.0 =
*Release Date - 19 September 2017*
* Added REST API endpoints for configuring Akismet and retrieving stats.
* Increased the minimum supported WordPress version to 4.0.
* Added compatibility with comments submitted via the REST API.
* Improved the progress indicator on the "Check for Spam" button.
= 3.3.4 =
*Release Date - 3 August 2017*
* Disabled Akismet's debug log output by default unless AKISMET_DEBUG is defined.
* URL previews now begin preloading when the mouse moves near them in the comments section of wp-admin.
* When a comment is caught by the Comment Blacklist, Akismet will always allow it to stay in the trash even if it is spam as well.
* Fixed a bug that was preventing an error from being shown when a site can't reach Akismet's servers.
= 3.3.3 =
*Release Date - 13 July 2017*
* Reduced amount of bandwidth used by the URL Preview feature.
* Improved the admin UI when the API key is manually pre-defined for the site.
* Removed a workaround for WordPress installations older than 3.3 that will improve Akismet's compatibility with other plugins.
* The number of spam blocked that is displayed on the WordPress dashboard will now be more accurate and updated more frequently.
* Fixed a bug in the Akismet widget that could cause PHP warnings.
= 3.3.2 =
*Release Date - 10 May 2017*
* Fixed a bug causing JavaScript errors in some browsers.
= 3.3.1 =
*Release Date - 2 May 2017*
* Improve performance by only requesting the akismet_comment_nonce option when absolutely necessary.
* Fixed two bugs that could cause PHP warnings.
* Fixed a bug that was preventing the "Remove author URL" feature from working after a comment was edited using "Quick Edit."
* Fixed a bug that was preventing the URL preview feature from working after a comment was edited using "Quick Edit."
= 3.3 =
*Release Date - 23 February 2017*
* Updated the Akismet admin pages with a new clean design.
* Fixed bugs preventing the `akismet_add_comment_nonce` and `akismet_update_alert` wrapper functions from working properly.
* Fixed bug preventing the loading indicator from appearing when re-checking all comments for spam.
* Added a progress indicator to the "Check for Spam" button.
* Added a success message after manually rechecking the Pending queue for spam.
= 3.2 =
*Release Date - 6 September 2016*
* Added a WP-CLI module. You can now check comments and recheck the moderation queue from the command line.
* Stopped using the deprecated jQuery function `.live()`.
* Fixed a bug in `remove_comment_author_url()` and `add_comment_author_url()` that could generate PHP notices.
* Fixed a bug that could cause an infinite loop for sites with very very very large comment IDs.
* Fixed a bug that could cause the Akismet widget title to be blank.
= 3.1.11 =
*Release Date - 12 May 2016*
* Fixed a bug that could cause the "Check for Spam" button to skip some comments.
* Fixed a bug that could prevent some spam submissions from being sent to Akismet.
* Updated all links to use https:// when possible.
* Disabled Akismet debug logging unless WP_DEBUG and WP_DEBUG_LOG are both enabled.
= 3.1.10 =
*Release Date - 1 April 2016*
* Fixed a bug that could cause comments caught as spam to be placed in the Pending queue.
* Fixed a bug that could have resulted in comments that were caught by the core WordPress comment blacklist not to have a corresponding History entry.
* Fixed a bug that could have caused avoidable PHP warnings in the error log.
= 3.1.9 =
*Release Date - 28 March 2016*
* Add compatibility with Jetpack so that Jetpack can automatically configure Akismet settings when appropriate.
* Fixed a bug preventing some comment data from being sent to Akismet.
= 3.1.8 =
*Release Date - 4 March 2016*
* Fixed a bug preventing Akismet from being used with some plugins that rewrite admin URLs.
* Reduced the amount of bandwidth used on Akismet API calls
* Reduced the amount of space Akismet uses in the database
* Fixed a bug that could cause comments caught as spam to be placed in the Pending queue.
= 3.1.7 =
*Release Date - 4 January 2016*
* Added documentation for the 'akismet_comment_nonce' filter.
* The post-install activation button is now accessible to screen readers and keyboard-only users.
* Fixed a bug that was preventing the "Remove author URL" feature from working in WordPress 4.4
= 3.1.6 =
*Release Date - 14 December 2015*
* Improve the notices shown after activating Akismet.
* Update some strings to allow for the proper plural forms in all languages.
= 3.1.5 =
*Release Date - 13 October 2015*
* Closes a potential XSS vulnerability.
= 3.1.4 =
*Release Date - 24 September 2015*
* Fixed a bug that was preventing some users from automatically connecting using Jetpack if they didn't have a current Akismet subscription.
* Fixed a bug that could cause comments caught as spam to be placed in the Pending queue.
* Error messages and instructions have been simplified to be more understandable.
* Link previews are enabled for all links inside comments, not just the author's website link.
= 3.1.3 =
*Release Date - 6 July 2015*
* Notify users when their account status changes after previously being successfully set up. This should help any users who are seeing blank Akismet settings screens.
= 3.1.2 =
*Release Date - 7 June 2015*
* Reduced the amount of space Akismet uses in the commentmeta table.
* Fixed a bug where some comments with quotes in the author name weren't getting history entries
* Pre-emptive security improvements to ensure that the Akismet plugin can't be used by attackers to compromise a WordPress installation.
* Better UI for the key entry field: allow whitespace to be included at the beginning or end of the key and strip it out automatically when the form is submitted.
* When deactivating the plugin, notify the Akismet API so the site can be marked as inactive.
* Clearer error messages.
= 3.1.1 =
*Release Date - 17th March, 2015*
* Improvements to the "Remove comment author URL" JavaScript
* Include the pingback pre-check from the 2.6 branch.
= 3.1 =
*Release Date - 11th March, 2015*
* Use HTTPS by default for all requests to Akismet.
* Fix for a situation where Akismet might strip HTML from a comment.
= 3.0.4 =
*Release Date - 11th December, 2014*
* Fix to make .htaccess compatible with Apache 2.4.
* Fix to allow removal of https author URLs.
* Fix to avoid stripping part of the author URL when removing and re-adding.
* Removed the "Check for Spam" button from the "Trash" and "Approved" queues, where it would have no effect.
* Allow automatic API key configuration when Jetpack is installed and connected to a WordPress.com account
= 3.0.3 =
*Release Date - 3rd November, 2014*
* Fix for sending the wrong data to delete_comment action that could have prevented old spam comments from being deleted.
* Added a filter to disable logging of Akismet debugging information.
* Added a filter for the maximum comment age when deleting old spam comments.
* Added a filter for the number per batch when deleting old spam comments.
* Removed the "Check for Spam" button from the Spam folder.
= 3.0.2 =
*Release Date - 18th August, 2014*
* Performance improvements.
* Fixed a bug that could truncate the comment data being sent to Akismet for checking.
= 3.0.1 =
*Release Date - 9th July, 2014*
* Removed dependency on PHP's fsockopen function
* Fix spam/ham reports to work when reported outside of the WP dashboard, e.g., from Notifications or the WP app
* Remove jQuery dependency for comment form JavaScript
* Remove unnecessary data from some Akismet comment meta
* Suspended keys will now result in all comments being put in moderation, not spam.
= 3.0.0 =
*Release Date - 15th April, 2014*
* Move Akismet to Settings menu
* Drop Akismet Stats menu
* Add stats snapshot to Akismet settings
* Add Akismet subscription details and status to Akismet settings
* Add contextual help for each page
* Improve Akismet setup to use Jetpack to automate plugin setup
* Fix "Check for Spam" to use AJAX to avoid page timing out
* Fix Akismet settings page to be responsive
* Drop legacy code
* Tidy up CSS and Javascript
* Replace the old discard setting with a new "discard pervasive spam" feature.
= 2.6.0 =
*Release Date - 18th March, 2014*
* Add ajax paging to the check for spam button to handle large volumes of comments
* Optimize javascript and add localization support
* Fix bug in link to spam comments from right now dashboard widget
* Fix bug with deleting old comments to avoid timeouts dealing with large volumes of comments
* Include X-Pingback-Forwarded-For header in outbound WordPress pingback verifications
* Add pre-check for pingbacks, to stop spam before an outbound verification request is made
= 2.5.9 =
*Release Date - 1st August, 2013*
* Update 'Already have a key' link to redirect page rather than depend on javascript
* Fix some non-translatable strings to be translatable
* Update Activation banner in plugins page to redirect user to Akismet config page
= 2.5.8 =
*Release Date - 20th January, 2013*
* Simplify the activation process for new users
* Remove the reporter_ip parameter
* Minor preventative security improvements
= 2.5.7 =
*Release Date - 13th December, 2012*
* FireFox Stats iframe preview bug
* Fix mshots preview when using https
* Add .htaccess to block direct access to files
* Prevent some PHP notices
* Fix Check For Spam return location when referrer is empty
* Fix Settings links for network admins
* Fix prepare() warnings in WP 3.5
= 2.5.6 =
*Release Date - 26th April, 2012*
* Prevent retry scheduling problems on sites where wp_cron is misbehaving
* Preload mshot previews
* Modernize the widget code
* Fix a bug where comments were not held for moderation during an error condition
* Improve the UX and display when comments are temporarily held due to an error
* Make the Check For Spam button force a retry when comments are held due to an error
* Handle errors caused by an invalid key
* Don't retry comments that are too old
* Improve error messages when verifying an API key
= 2.5.5 =
*Release Date - 11th January, 2012*
* Add nonce check for comment author URL remove action
* Fix the settings link
= 2.5.4 =
*Release Date - 5th January, 2012*
* Limit Akismet CSS and Javascript loading in wp-admin to just the pages that need it
* Added author URL quick removal functionality
* Added mShot preview on Author URL hover
* Added empty index.php to prevent directory listing
* Move wp-admin menu items under Jetpack, if it is installed
* Purge old Akismet comment meta data, default of 15 days
= 2.5.3 =
*Release Date - 8th Febuary, 2011*
* Specify the license is GPL v2 or later
* Fix a bug that could result in orphaned commentmeta entries
* Include hotfix for WordPress 3.0.5 filter issue
= 2.5.2 =
*Release Date - 14th January, 2011*
* Properly format the comment count for author counts
* Look for super admins on multisite installs when looking up user roles
* Increase the HTTP request timeout
* Removed padding for author approved count
* Fix typo in function name
* Set Akismet stats iframe height to fixed 2500px.  Better to have one tall scroll bar than two side by side.
= 2.5.1 =
*Release Date - 17th December, 2010*
* Fix a bug that caused the "Auto delete" option to fail to discard comments correctly
* Remove the comment nonce form field from the 'Akismet Configuration' page in favor of using a filter, akismet_comment_nonce
* Fixed padding bug in "author" column of posts screen
* Added margin-top to "cleared by ..." badges on dashboard
* Fix possible error when calling akismet_cron_recheck()
* Fix more PHP warnings
* Clean up XHTML warnings for comment nonce
* Fix for possible condition where scheduled comment re-checks could get stuck
* Clean up the comment meta details after deleting a comment
* Only show the status badge if the comment status has been changed by someone/something other than Akismet
* Show a 'History' link in the row-actions
* Translation fixes
* Reduced font-size on author name
* Moved "flagged by..." notification to top right corner of comment container and removed heavy styling
* Hid "flagged by..." notification while on dashboard
= 2.5.0 =
*Release Date - 7th December, 2010*
* Track comment actions under 'Akismet Status' on the edit comment screen
* Fix a few remaining deprecated function calls ( props Mike Glendinning )
* Use HTTPS for the stats IFRAME when wp-admin is using HTTPS
* Use the WordPress HTTP class if available
* Move the admin UI code to a separate file, only loaded when needed
* Add cron retry feature, to replace the old connectivity check
* Display Akismet status badge beside each comment
* Record history for each comment, and display it on the edit page
* Record the complete comment as originally submitted in comment_meta, to use when reporting spam and ham
* Highlight links in comment content
* New option, "Show the number of comments you've approved beside each comment author."
* New option, "Use a nonce on the comment form."
= 2.4.0 =
*Release Date - 23rd August, 2010*
* Spell out that the license is GPLv2
* Fix PHP warnings
* Fix WordPress deprecated function calls
* Fire the delete_comment action when deleting comments
* Move code specific for older WP versions to legacy.php
* General code clean up
= 2.3.0 =
*Release Date - 5th June, 2010*
* Fix "Are you sure" nonce message on config screen in WPMU
* Fix XHTML compliance issue in sidebar widget
* Change author link; remove some old references to WordPress.com accounts
* Localize the widget title (core ticket #13879)
= 2.2.9 =
*Release Date - 2nd June, 2010*
* Eliminate a potential conflict with some plugins that may cause spurious reports
= 2.2.8 =
*Release Date - 27th May, 2010*
* Fix bug in initial comment check for ipv6 addresses
* Report comments as ham when they are moved from spam to moderation
* Report comments as ham when clicking undo after spam
* Use transition_comment_status action when available instead of older actions for spam/ham submissions
* Better diagnostic messages when PHP network functions are unavailable
* Better handling of comments by logged-in users
= 2.2.7 =
*Release Date - 17th December, 2009*
* Add a new AKISMET_VERSION constant
* Reduce the possibility of over-counting spam when another spam filter plugin is in use
* Disable the connectivity check when the API key is hard-coded for WPMU
= 2.2.6 =
*Release Date - 20th July, 2009*
* Fix a global warning introduced in 2.2.5
* Add changelog and additional readme.txt tags
* Fix an array conversion warning in some versions of PHP
* Support a new WPCOM_API_KEY constant for easier use with WordPress MU
= 2.2.5 =
*Release Date - 13th July, 2009*
* Include a new Server Connectivity diagnostic check, to detect problems caused by firewalls
= 2.2.4 =
*Release Date - 3rd June, 2009*
* Fixed a key problem affecting the stats feature in WordPress MU
* Provide additional blog information in Akismet API calls
                                                                                                                                                                             plugins/akismet/class.akismet.php                                                                   0000644                 00000243607 15100623270 0013144 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       <?php
// We plan to gradually remove all of the disabled lint rules below.
// phpcs:disable WordPress.Security.ValidatedSanitizedInput.MissingUnslash
// phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
// phpcs:disable WordPress.Security.NonceVerification.Missing
// phpcs:disable Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
class Akismet {
	const API_HOST                          = 'rest.akismet.com';
	const API_PORT                          = 80;
	const MAX_DELAY_BEFORE_MODERATION_EMAIL = 86400; // One day in seconds
	const ALERT_CODE_COMMERCIAL             = 30001;
	public static $limit_notices = array(
		10501 => 'FIRST_MONTH_OVER_LIMIT',
		10502 => 'SECOND_MONTH_OVER_LIMIT',
		10504 => 'THIRD_MONTH_APPROACHING_LIMIT',
		10508 => 'THIRD_MONTH_OVER_LIMIT',
		10516 => 'FOUR_PLUS_MONTHS_OVER_LIMIT',
	);
	private static $last_comment                                = '';
	private static $initiated                                   = false;
	private static $last_comment_result                         = null;
	private static $comment_as_submitted_allowed_keys           = array(
		'blog'                 => '',
		'blog_charset'         => '',
		'blog_lang'            => '',
		'blog_ua'              => '',
		'comment_agent'        => '',
		'comment_author'       => '',
		'comment_author_IP'    => '',
		'comment_author_email' => '',
		'comment_author_url'   => '',
		'comment_content'      => '',
		'comment_date_gmt'     => '',
		'comment_tags'         => '',
		'comment_type'         => '',
		'guid'                 => '',
		'is_test'              => '',
		'permalink'            => '',
		'reporter'             => '',
		'site_domain'          => '',
		'submit_referer'       => '',
		'submit_uri'           => '',
		'user_ID'              => '',
		'user_agent'           => '',
		'user_id'              => '',
		'user_ip'              => '',
	);
	public static function init() {
		if ( ! self::$initiated ) {
			self::init_hooks();
		}
	}
	/**
	 * Initializes WordPress hooks
	 */
	private static function init_hooks() {
		self::$initiated = true;
		add_action( 'wp_insert_comment', array( 'Akismet', 'auto_check_update_meta' ), 10, 2 );
		add_action( 'wp_insert_comment', array( 'Akismet', 'schedule_email_fallback' ), 10, 2 );
		add_action( 'wp_insert_comment', array( 'Akismet', 'schedule_approval_fallback' ), 10, 2 );
		add_filter( 'preprocess_comment', array( 'Akismet', 'auto_check_comment' ), 1 );
		add_filter( 'rest_pre_insert_comment', array( 'Akismet', 'rest_auto_check_comment' ), 1 );
		add_action( 'comment_form', array( 'Akismet', 'load_form_js' ) );
		add_action( 'do_shortcode_tag', array( 'Akismet', 'load_form_js_via_filter' ), 10, 4 );
		add_action( 'akismet_scheduled_delete', array( 'Akismet', 'delete_old_comments' ) );
		add_action( 'akismet_scheduled_delete', array( 'Akismet', 'delete_old_comments_meta' ) );
		add_action( 'akismet_scheduled_delete', array( 'Akismet', 'delete_orphaned_commentmeta' ) );
		add_action( 'akismet_schedule_cron_recheck', array( 'Akismet', 'cron_recheck' ) );
		add_action( 'akismet_email_fallback', array( 'Akismet', 'email_fallback' ), 10, 3 );
		add_action( 'akismet_approval_fallback', array( 'Akismet', 'approval_fallback' ), 10, 3 );
		add_action( 'comment_form', array( 'Akismet', 'add_comment_nonce' ), 1 );
		add_action( 'comment_form', array( 'Akismet', 'output_custom_form_fields' ) );
		add_filter( 'script_loader_tag', array( 'Akismet', 'set_form_js_async' ), 10, 3 );
		add_filter( 'notify_moderator', array( 'Akismet', 'disable_emails_if_unreachable' ), 1000, 2 );
		add_filter( 'notify_post_author', array( 'Akismet', 'disable_emails_if_unreachable' ), 1000, 2 );
		add_filter( 'pre_comment_approved', array( 'Akismet', 'last_comment_status' ), 10, 2 );
		add_action( 'transition_comment_status', array( 'Akismet', 'transition_comment_status' ), 10, 3 );
		// Run this early in the pingback call, before doing a remote fetch of the source uri
		add_action( 'xmlrpc_call', array( 'Akismet', 'pre_check_pingback' ), 10, 3 );
		// Jetpack compatibility
		add_filter( 'jetpack_options_whitelist', array( 'Akismet', 'add_to_jetpack_options_whitelist' ) );
		add_filter( 'jetpack_contact_form_html', array( 'Akismet', 'inject_custom_form_fields' ) );
		add_filter( 'jetpack_contact_form_akismet_values', array( 'Akismet', 'prepare_custom_form_values' ) );
		// Gravity Forms
		add_filter( 'gform_get_form_filter', array( 'Akismet', 'inject_custom_form_fields' ) );
		add_filter( 'gform_akismet_fields', array( 'Akismet', 'prepare_custom_form_values' ) );
		// Contact Form 7
		add_filter( 'wpcf7_form_elements', array( 'Akismet', 'append_custom_form_fields' ) );
		add_filter( 'wpcf7_akismet_parameters', array( 'Akismet', 'prepare_custom_form_values' ) );
		// Formidable Forms
		add_filter( 'frm_filter_final_form', array( 'Akismet', 'inject_custom_form_fields' ) );
		add_filter( 'frm_akismet_values', array( 'Akismet', 'prepare_custom_form_values' ) );
		// Fluent Forms
		/*
		 * The Fluent Forms  hook names were updated in version 5.0.0. The last version that supported
		 * the original hook names was 4.3.25, and version 4.3.25 was tested up to WordPress version 6.1.
		 *
		 * The legacy hooks are fired before the new hooks. See
		 * https://github.com/fluentform/fluentform/commit/cc45341afcae400f217470a7bbfb15efdd80454f
		 *
		 * The legacy Fluent Forms hooks will be removed when Akismet no longer supports WordPress version 6.1.
		 * This will provide compatibility with previous versions of Fluent Forms for a reasonable amount of time.
		 */
		add_filter( 'fluentform_form_element_start', array( 'Akismet', 'output_custom_form_fields' ) );
		add_filter( 'fluentform_akismet_fields', array( 'Akismet', 'prepare_custom_form_values' ), 10, 2 );
		// Current Fluent Form hooks.
		add_filter( 'fluentform/form_element_start', array( 'Akismet', 'output_custom_form_fields' ) );
		add_filter( 'fluentform/akismet_fields', array( 'Akismet', 'prepare_custom_form_values' ), 10, 2 );
		add_action( 'update_option_wordpress_api_key', array( 'Akismet', 'updated_option' ), 10, 2 );
		add_action( 'add_option_wordpress_api_key', array( 'Akismet', 'added_option' ), 10, 2 );
		add_action( 'comment_form_after', array( 'Akismet', 'display_comment_form_privacy_notice' ) );
	}
	public static function get_api_key() {
		return apply_filters( 'akismet_get_api_key', defined( 'WPCOM_API_KEY' ) ? constant( 'WPCOM_API_KEY' ) : get_option( 'wordpress_api_key' ) );
	}
	/**
	 * Exchange the API key for a token that can only be used to access stats pages.
	 *
	 * @return string
	 */
	public static function get_access_token() {
		static $access_token = null;
		if ( is_null( $access_token ) ) {
			$request_args = array( 'api_key' => self::get_api_key() );
			$request_args = apply_filters( 'akismet_request_args', $request_args, 'token' );
			$response = self::http_post( self::build_query( $request_args ), 'token' );
			$access_token = $response[1];
		}
		return $access_token;
	}
	public static function check_key_status( $key, $ip = null ) {
		$request_args = array(
			'key'  => $key,
			'blog' => get_option( 'home' ),
		);
		$request_args = apply_filters( 'akismet_request_args', $request_args, 'verify-key' );
		return self::http_post( self::build_query( $request_args ), 'verify-key', $ip );
	}
	public static function verify_key( $key, $ip = null ) {
		// Shortcut for obviously invalid keys.
		if ( strlen( $key ) != 12 ) {
			return 'invalid';
		}
		$response = self::check_key_status( $key, $ip );
		if ( $response[1] != 'valid' && $response[1] != 'invalid' ) {
			return 'failed';
		}
		return $response[1];
	}
	public static function deactivate_key( $key ) {
		$request_args = array(
			'key'  => $key,
			'blog' => get_option( 'home' ),
		);
		$request_args = apply_filters( 'akismet_request_args', $request_args, 'deactivate' );
		$response = self::http_post( self::build_query( $request_args ), 'deactivate' );
		if ( $response[1] != 'deactivated' ) {
			return 'failed';
		}
		return $response[1];
	}
	/**
	 * Add the akismet option to the Jetpack options management whitelist.
	 *
	 * @param array $options The list of whitelisted option names.
	 * @return array The updated whitelist
	 */
	public static function add_to_jetpack_options_whitelist( $options ) {
		$options[] = 'wordpress_api_key';
		return $options;
	}
	/**
	 * When the akismet option is updated, run the registration call.
	 *
	 * This should only be run when the option is updated from the Jetpack/WP.com
	 * API call, and only if the new key is different than the old key.
	 *
	 * @param mixed $old_value   The old option value.
	 * @param mixed $value       The new option value.
	 */
	public static function updated_option( $old_value, $value ) {
		// Not an API call
		if ( ! class_exists( 'WPCOM_JSON_API_Update_Option_Endpoint' ) ) {
			return;
		}
		// Only run the registration if the old key is different.
		if ( $old_value !== $value ) {
			self::verify_key( $value );
		}
	}
	/**
	 * Treat the creation of an API key the same as updating the API key to a new value.
	 *
	 * @param mixed $option_name   Will always be "wordpress_api_key", until something else hooks in here.
	 * @param mixed $value         The option value.
	 */
	public static function added_option( $option_name, $value ) {
		if ( 'wordpress_api_key' === $option_name ) {
			return self::updated_option( '', $value );
		}
	}
	public static function rest_auto_check_comment( $commentdata ) {
		return self::auto_check_comment( $commentdata, 'rest_api' );
	}
	/**
	 * Check a comment for spam.
	 *
	 * @param array  $commentdata
	 * @param string $context What kind of request triggered this comment check? Possible values are 'default', 'rest_api', and 'xml-rpc'.
	 * @return array|WP_Error Either the $commentdata array with additional entries related to its spam status
	 *                        or a WP_Error, if it's a REST API request and the comment should be discarded.
	 */
	public static function auto_check_comment( $commentdata, $context = 'default' ) {
		// If no key is configured, then there's no point in doing any of this.
		if ( ! self::get_api_key() ) {
			return $commentdata;
		}
		if ( ! isset( $commentdata['comment_meta'] ) ) {
			$commentdata['comment_meta'] = array();
		}
		self::$last_comment_result = null;
		// Skip the Akismet check if the comment matches the Disallowed Keys list.
		if ( function_exists( 'wp_check_comment_disallowed_list' ) ) {
			$comment_author       = isset( $commentdata['comment_author'] ) ? $commentdata['comment_author'] : '';
			$comment_author_email = isset( $commentdata['comment_author_email'] ) ? $commentdata['comment_author_email'] : '';
			$comment_author_url   = isset( $commentdata['comment_author_url'] ) ? $commentdata['comment_author_url'] : '';
			$comment_content      = isset( $commentdata['comment_content'] ) ? $commentdata['comment_content'] : '';
			$comment_author_ip    = isset( $commentdata['comment_author_IP'] ) ? $commentdata['comment_author_IP'] : '';
			$comment_agent        = isset( $commentdata['comment_agent'] ) ? $commentdata['comment_agent'] : '';
			if ( wp_check_comment_disallowed_list( $comment_author, $comment_author_email, $comment_author_url, $comment_content, $comment_author_ip, $comment_agent ) ) {
				$commentdata['akismet_result'] = 'skipped';
				$commentdata['comment_meta']['akismet_result'] = 'skipped';
				$commentdata['akismet_skipped_microtime'] = microtime( true );
				$commentdata['comment_meta']['akismet_skipped_microtime'] = $commentdata['akismet_skipped_microtime'];
				self::set_last_comment( $commentdata );
				return $commentdata;
			}
		}
		$comment = $commentdata;
		$comment['user_ip']      = self::get_ip_address();
		$comment['user_agent']   = self::get_user_agent();
		$comment['referrer']     = self::get_referer();
		$comment['blog']         = get_option( 'home' );
		$comment['blog_lang']    = get_locale();
		$comment['blog_charset'] = get_option( 'blog_charset' );
		$comment['permalink']    = get_permalink( $comment['comment_post_ID'] );
		if ( ! empty( $comment['user_ID'] ) ) {
			$comment['user_role'] = self::get_user_roles( $comment['user_ID'] );
		}
		/** See filter documentation in init_hooks(). */
		$akismet_nonce_option             = apply_filters( 'akismet_comment_nonce', get_option( 'akismet_comment_nonce' ) );
		$comment['akismet_comment_nonce'] = 'inactive';
		if ( $akismet_nonce_option == 'true' || $akismet_nonce_option == '' ) {
			$comment['akismet_comment_nonce'] = 'failed';
			if ( isset( $_POST['akismet_comment_nonce'] ) && wp_verify_nonce( $_POST['akismet_comment_nonce'], 'akismet_comment_nonce_' . $comment['comment_post_ID'] ) ) {
				$comment['akismet_comment_nonce'] = 'passed';
			}
			// comment reply in wp-admin
			if ( isset( $_POST['_ajax_nonce-replyto-comment'] ) && check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' ) ) {
				$comment['akismet_comment_nonce'] = 'passed';
			}
		}
		if ( self::is_test_mode() ) {
			$comment['is_test'] = 'true';
		}
		foreach ( $_POST as $key => $value ) {
			if ( is_string( $value ) ) {
				$comment[ "POST_{$key}" ] = $value;
			}
		}
		foreach ( $_SERVER as $key => $value ) {
			if ( ! is_string( $value ) ) {
				continue;
			}
			if ( preg_match( '/^HTTP_COOKIE/', $key ) ) {
				continue;
			}
			// Send any potentially useful $_SERVER vars, but avoid sending junk we don't need.
			if ( preg_match( '/^(HTTP_|REMOTE_ADDR|REQUEST_URI|DOCUMENT_URI)/', $key ) ) {
				$comment[ "$key" ] = $value;
			}
		}
		$post = get_post( $comment['comment_post_ID'] );
		if ( ! is_null( $post ) ) {
			// $post can technically be null, although in the past, it's always been an indicator of another plugin interfering.
			$comment['comment_post_modified_gmt'] = $post->post_modified_gmt;
			// Tags and categories are important context in which to consider the comment.
			$comment['comment_context'] = array();
			$tag_names = wp_get_post_tags( $post->ID, array( 'fields' => 'names' ) );
			if ( $tag_names && ! is_wp_error( $tag_names ) ) {
				foreach ( $tag_names as $tag_name ) {
					$comment['comment_context'][] = $tag_name;
				}
			}
			$category_names = wp_get_post_categories( $post->ID, array( 'fields' => 'names' ) );
			if ( $category_names && ! is_wp_error( $category_names ) ) {
				foreach ( $category_names as $category_name ) {
					$comment['comment_context'][] = $category_name;
				}
			}
		}
		// Set the webhook callback URL. The Akismet servers may make a request to this URL
		// if a comment's spam status changes.
		$comment['callback'] = get_rest_url( null, 'akismet/v1/webhook' );
		/**
		 * Filter the data that is used to generate the request body for the API call.
		 *
		 * @since 5.3.1
		 *
		 * @param array $comment An array of request data.
		 * @param string $endpoint The API endpoint being requested.
		 */
		$comment = apply_filters( 'akismet_request_args', $comment, 'comment-check' );
		$response = self::http_post( self::build_query( $comment ), 'comment-check' );
		do_action( 'akismet_comment_check_response', $response );
		$commentdata['comment_as_submitted'] = array_intersect_key( $comment, self::$comment_as_submitted_allowed_keys );
		// Also include any form fields we inject into the comment form, like ak_js
		foreach ( $_POST as $key => $value ) {
			if ( is_string( $value ) && strpos( $key, 'ak_' ) === 0 ) {
				$commentdata['comment_as_submitted'][ 'POST_' . $key ] = $value;
			}
		}
		$commentdata['akismet_result'] = $response[1];
		if ( 'true' === $response[1] || 'false' === $response[1] ) {
			$commentdata['comment_meta']['akismet_result'] = $response[1];
		} else {
			$commentdata['comment_meta']['akismet_error'] = time();
		}
		if ( isset( $response[0]['x-akismet-pro-tip'] ) ) {
			$commentdata['akismet_pro_tip'] = $response[0]['x-akismet-pro-tip'];
			$commentdata['comment_meta']['akismet_pro_tip'] = $response[0]['x-akismet-pro-tip'];
		}
		if ( isset( $response[0]['x-akismet-guid'] ) ) {
			$commentdata['akismet_guid'] = $response[0]['x-akismet-guid'];
			$commentdata['comment_meta']['akismet_guid'] = $response[0]['x-akismet-guid'];
			if ( 'false' === $response[1] ) {
				// If Akismet has indicated that there is more processing to be done before this comment
				// can be fully classified, delay moderation emails until that processing is complete.
				if ( isset( $response[0]['X-akismet-recheck-after'] ) ) {
					// Prevent this comment from reaching Active status (keep in Pending) until
					// it's finished being checked.
					$commentdata['comment_approved'] = '0';
					self::$last_comment_result = '0';
					// Indicate that we should schedule a fallback so that if the site never receives a
					// followup from Akismet, the emails will still be sent. We don't schedule it here
					// because we don't yet have the comment ID. Add an extra minute to ensure that the
					// fallback email isn't sent while the recheck or webhook call is happening.
					$delay = $response[0]['X-akismet-recheck-after'] * 2;
					$commentdata['comment_meta']['akismet_schedule_approval_fallback'] = $delay;
					// If this commentmeta is present, we'll prevent the moderation email from sending once.
					$commentdata['comment_meta']['akismet_delay_moderation_email'] = true;
					self::log( 'Delaying moderation email for comment from ' . $commentdata['comment_author'] . ' for ' . $delay . ' seconds' );
					$commentdata['comment_meta']['akismet_schedule_email_fallback'] = $delay;
				}
			}
		}
		$commentdata['comment_meta']['akismet_as_submitted'] = $commentdata['comment_as_submitted'];
		if ( isset( $response[0]['x-akismet-error'] ) ) {
			// An error occurred that we anticipated (like a suspended key) and want the user to act on.
			// Send to moderation.
			self::$last_comment_result = '0';
		} elseif ( 'true' == $response[1] ) {
			// akismet_spam_count will be incremented later by comment_is_spam()
			self::$last_comment_result = 'spam';
			$discard = ( isset( $commentdata['akismet_pro_tip'] ) && $commentdata['akismet_pro_tip'] === 'discard' && self::allow_discard() );
			do_action( 'akismet_spam_caught', $discard );
			if ( $discard ) {
				// The spam is obvious, so we're bailing out early.
				// akismet_result_spam() won't be called so bump the counter here
				if ( $incr = apply_filters( 'akismet_spam_count_incr', 1 ) ) {
					update_option( 'akismet_spam_count', get_option( 'akismet_spam_count' ) + $incr );
				}
				if ( 'rest_api' === $context ) {
					return new WP_Error( 'akismet_rest_comment_discarded', __( 'Comment discarded.', 'akismet' ) );
				} elseif ( 'xml-rpc' === $context ) {
					// If this is a pingback that we're pre-checking, the discard behavior is the same as the normal spam response behavior.
					return $commentdata;
				} else {
					// Redirect back to the previous page, or failing that, the post permalink, or failing that, the homepage of the blog.
					$redirect_to = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : ( $post ? get_permalink( $post ) : home_url() );
					wp_safe_redirect( esc_url_raw( $redirect_to ) );
					die();
				}
			} elseif ( 'rest_api' === $context ) {
				// The way the REST API structures its calls, we can set the comment_approved value right away.
				$commentdata['comment_approved'] = 'spam';
			}
		}
		// if the response is neither true nor false, hold the comment for moderation and schedule a recheck
		if ( 'true' != $response[1] && 'false' != $response[1] ) {
			if ( ! current_user_can( 'moderate_comments' ) ) {
				// Comment status should be moderated
				self::$last_comment_result = '0';
			}
			$commentdata['comment_meta']['akismet_delay_moderation_email'] = true;
			if ( ! wp_next_scheduled( 'akismet_schedule_cron_recheck' ) ) {
				wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
				do_action( 'akismet_scheduled_recheck', 'invalid-response-' . $response[1] );
			}
		}
		// Delete old comments daily
		if ( ! wp_next_scheduled( 'akismet_scheduled_delete' ) ) {
			wp_schedule_event( time(), 'daily', 'akismet_scheduled_delete' );
		}
		self::set_last_comment( $commentdata );
		self::fix_scheduled_recheck();
		return $commentdata;
	}
	public static function get_last_comment() {
		return self::$last_comment;
	}
	public static function set_last_comment( $comment ) {
		if ( is_null( $comment ) ) {
			// This never happens in our code.
			self::$last_comment = null;
		} else {
			// We filter it here so that it matches the filtered comment data that we'll have to compare against later.
			// wp_filter_comment expects comment_author_IP
			self::$last_comment = wp_filter_comment(
				array_merge(
					array( 'comment_author_IP' => self::get_ip_address() ),
					$comment
				)
			);
		}
	}
	// this fires on wp_insert_comment.  we can't update comment_meta when auto_check_comment() runs
	// because we don't know the comment ID at that point.
	public static function auto_check_update_meta( $id, $comment ) {
		// wp_insert_comment() might be called in other contexts, so make sure this is the same comment
		// as was checked by auto_check_comment
		if ( is_object( $comment ) && ! empty( self::$last_comment ) && is_array( self::$last_comment ) ) {
			if ( self::matches_last_comment_by_id( $id ) ) {
				// normal result: true or false
				if ( isset( self::$last_comment['akismet_result'] ) && self::$last_comment['akismet_result'] == 'true' ) {
					self::update_comment_history( $comment->comment_ID, '', 'check-spam' );
					if ( $comment->comment_approved != 'spam' ) {
						self::update_comment_history(
							$comment->comment_ID,
							'',
							'status-changed-' . $comment->comment_approved
						);
					}
				} elseif ( isset( self::$last_comment['akismet_result'] ) && self::$last_comment['akismet_result'] == 'false' ) {
					if ( get_comment_meta( $comment->comment_ID, 'akismet_schedule_approval_fallback', true ) ) {
						self::update_comment_history( $comment->comment_ID, '', 'check-ham-pending' );
					} else {
						self::update_comment_history( $comment->comment_ID, '', 'check-ham' );
					}
					// Status could be spam or trash, depending on the WP version and whether this change applies:
					// https://core.trac.wordpress.org/changeset/34726
					if ( $comment->comment_approved == 'spam' || $comment->comment_approved == 'trash' ) {
						if ( function_exists( 'wp_check_comment_disallowed_list' ) ) {
							if ( wp_check_comment_disallowed_list( $comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent ) ) {
								self::update_comment_history( $comment->comment_ID, '', 'wp-disallowed' );
							} else {
								self::update_comment_history( $comment->comment_ID, '', 'status-changed-' . $comment->comment_approved );
							}
						} else {
							self::update_comment_history( $comment->comment_ID, '', 'status-changed-' . $comment->comment_approved );
						}
					}
				} elseif ( isset( self::$last_comment['akismet_result'] ) && 'skipped' == self::$last_comment['akismet_result'] ) {
					// The comment wasn't sent to Akismet because it matched the disallowed comment keys.
					self::update_comment_history( $comment->comment_ID, '', 'wp-disallowed' );
					self::update_comment_history( $comment->comment_ID, '', 'akismet-skipped-disallowed' );
				} else if ( ! isset( self::$last_comment['akismet_result'] ) ) {
					// Add a generic skipped history item.
					self::update_comment_history( $comment->comment_ID, '', 'akismet-skipped' );
				} else {
					// abnormal result: error
					self::update_comment_history(
						$comment->comment_ID,
						'',
						'check-error',
						array( 'response' => substr( self::$last_comment['akismet_result'], 0, 50 ) )
					);
				}
			}
		}
	}
	/**
	 * After the comment has been inserted, we have access to the comment ID. Now, we can
	 * schedule the fallback moderation/notification emails using the comment ID instead
	 * of relying on a lookup of the GUID in the commentmeta table.
	 *
	 * @param int $id The comment ID.
	 * @param object $comment The comment object.
	 */
	public static function schedule_email_fallback( $id, $comment ) {
		self::log( 'Checking whether to schedule_email_fallback for comment #' . $id );
		// If the moderation/notification emails for this comment were delayed
		$email_delay = get_comment_meta( $id, 'akismet_schedule_email_fallback', true );
		if ( $email_delay ) {
			delete_comment_meta( $id, 'akismet_schedule_email_fallback' );
			wp_schedule_single_event( time() + $email_delay, 'akismet_email_fallback', array( $id ) );
			self::log( 'Scheduled email fallback for ' . ( time() + $email_delay ) . ' for comment #' . $id );
		} else {
			self::log( 'No need to schedule_email_fallback for comment #' . $id );
		}
	}
	/**
	 * Send out the notification emails if they were previously delayed while waiting
	 * for a recheck or webhook.
	 *
	 * @param int $comment_ID The comment ID.
	 */
	public static function email_fallback( $comment_id ) {
		self::log( 'In email fallback for comment #' . $comment_id );
		if ( get_comment_meta( $comment_id, 'akismet_delayed_moderation_email', true ) ) {
			self::log( 'Triggering notification emails for comment #' . $comment_id . '. They will be sent if comment is not spam.' );
			delete_comment_meta( $comment_id, 'akismet_delayed_moderation_email' );
			wp_new_comment_notify_moderator( $comment_id );
			wp_new_comment_notify_postauthor( $comment_id );
		} else {
			self::log( 'No need to send fallback email for comment #' . $comment_id );
		}
		delete_comment_meta( $comment_id, 'akismet_delay_moderation_email' );
	}
	/**
	 * After the comment has been inserted, we have access to the comment ID. Now, we can
	 * schedule the fallback moderation/notification emails using the comment ID instead
	 * of relying on a lookup of the GUID in the commentmeta table.
	 *
	 * @param int $id The comment ID.
	 * @param object $comment The comment object.
	 */
	public static function schedule_approval_fallback( $id, $comment ) {
		self::log( 'Checking whether to schedule_approval_fallback for comment #' . $id );
		// If the moderation/notification emails for this comment were delayed
		$approval_delay = get_comment_meta( $id, 'akismet_schedule_approval_fallback', true );
		if ( $approval_delay ) {
			delete_comment_meta( $id, 'akismet_schedule_approval_fallback' );
			wp_schedule_single_event( time() + $approval_delay, 'akismet_approval_fallback', array( $id ) );
			self::log( 'Scheduled approval fallback for ' . ( time() + $approval_delay ) . ' for comment #' . $id );
		} else {
			self::log( 'No need to schedule_approval_fallback for comment #' . $id );
		}
	}
	/**
	 * If no other process has approved or spammed this comment since it was put in pending, approve it.
	 *
	 * @param int $comment_ID The comment ID.
	 */
	public static function approval_fallback( $comment_id ) {
		self::log( 'In approval fallback for comment #' . $comment_id );
		if ( wp_get_comment_status( $comment_id ) == 'unapproved' ) {
			if ( self::last_comment_status_change_came_from_akismet( $comment_id ) ) {
				$comment = get_comment( $comment_id );
				if ( ! $comment ) {
					self::log( 'Comment #' . $comment_id . ' no longer exists.' );
				} else if ( check_comment( $comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent, $comment->comment_type ) ) {
					self::log( 'Approving comment #' . $comment_id );
					wp_set_comment_status( $comment_id, 1 );
				} else {
					self::log( 'Not approving comment #' . $comment_id . ' because it does not pass check_comment()' );
				}
				self::update_comment_history( $comment->comment_ID, '', 'check-ham' );
			} else {
				self::log( 'No need to fallback approve comment #' . $comment_id . ' because it was not last modified by Akismet.' );
				$history = self::get_comment_history( $comment_id );
				if ( ! empty( $history ) ) {
					$most_recent_history_event = $history[0];
					error_log( 'Comment history: ' . print_r( $history, true ) );
				}
			}
		} else {
			self::log( 'No need to fallback approve comment #' . $comment_id . ' because it is not pending.' );
		}
	}
	public static function delete_old_comments() {
		global $wpdb;
		/**
		 * Determines how many comments will be deleted in each batch.
		 *
		 * @param int The default, as defined by AKISMET_DELETE_LIMIT.
		 */
		$delete_limit = apply_filters( 'akismet_delete_comment_limit', defined( 'AKISMET_DELETE_LIMIT' ) ? AKISMET_DELETE_LIMIT : 10000 );
		$delete_limit = max( 1, intval( $delete_limit ) );
		/**
		 * Determines how many days a comment will be left in the Spam queue before being deleted.
		 *
		 * @param int The default number of days.
		 */
		$delete_interval = apply_filters( 'akismet_delete_comment_interval', 15 );
		$delete_interval = max( 1, intval( $delete_interval ) );
		while ( $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_id FROM {$wpdb->comments} WHERE DATE_SUB(NOW(), INTERVAL %d DAY) > comment_date_gmt AND comment_approved = 'spam' LIMIT %d", $delete_interval, $delete_limit ) ) ) {
			if ( empty( $comment_ids ) ) {
				return;
			}
			$wpdb->queries = array();
			$comments = array();
			foreach ( $comment_ids as $comment_id ) {
				$comments[ $comment_id ] = get_comment( $comment_id );
				do_action( 'delete_comment', $comment_id, $comments[ $comment_id ] );
				do_action( 'akismet_batch_delete_count', __FUNCTION__ );
			}
			// Prepared as strings since comment_id is an unsigned BIGINT, and using %d will constrain the value to the maximum signed BIGINT.
			$format_string = implode( ', ', array_fill( 0, is_countable( $comment_ids ) ? count( $comment_ids ) : 0, '%s' ) );
			$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->comments} WHERE comment_id IN ( " . $format_string . ' )', $comment_ids ) );
			$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->commentmeta} WHERE comment_id IN ( " . $format_string . ' )', $comment_ids ) );
			foreach ( $comment_ids as $comment_id ) {
				do_action( 'deleted_comment', $comment_id, $comments[ $comment_id ] );
				unset( $comments[ $comment_id ] );
			}
			clean_comment_cache( $comment_ids );
			do_action( 'akismet_delete_comment_batch', is_countable( $comment_ids ) ? count( $comment_ids ) : 0 );
		}
		if ( apply_filters( 'akismet_optimize_table', ( mt_rand( 1, 5000 ) == 11 ), $wpdb->comments ) ) { // lucky number
			$wpdb->query( "OPTIMIZE TABLE {$wpdb->comments}" );
		}
	}
	public static function delete_old_comments_meta() {
		global $wpdb;
		$interval = apply_filters( 'akismet_delete_commentmeta_interval', 15 );
		// enforce a minimum of 1 day
		$interval = absint( $interval );
		if ( $interval < 1 ) {
			$interval = 1;
		}
		// akismet_as_submitted meta values are large, so expire them
		// after $interval days regardless of the comment status
		while ( $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT m.comment_id FROM {$wpdb->commentmeta} as m INNER JOIN {$wpdb->comments} as c USING(comment_id) WHERE m.meta_key = 'akismet_as_submitted' AND DATE_SUB(NOW(), INTERVAL %d DAY) > c.comment_date_gmt LIMIT 10000", $interval ) ) ) {
			if ( empty( $comment_ids ) ) {
				return;
			}
			$wpdb->queries = array();
			foreach ( $comment_ids as $comment_id ) {
				delete_comment_meta( $comment_id, 'akismet_as_submitted' );
				do_action( 'akismet_batch_delete_count', __FUNCTION__ );
			}
			do_action( 'akismet_delete_commentmeta_batch', is_countable( $comment_ids ) ? count( $comment_ids ) : 0 );
		}
		if ( apply_filters( 'akismet_optimize_table', ( mt_rand( 1, 5000 ) == 11 ), $wpdb->commentmeta ) ) { // lucky number
			$wpdb->query( "OPTIMIZE TABLE {$wpdb->commentmeta}" );
		}
	}
	// Clear out comments meta that no longer have corresponding comments in the database
	public static function delete_orphaned_commentmeta() {
		global $wpdb;
		$last_meta_id  = 0;
		$start_time    = isset( $_SERVER['REQUEST_TIME_FLOAT'] ) ? $_SERVER['REQUEST_TIME_FLOAT'] : microtime( true );
		$max_exec_time = max( ini_get( 'max_execution_time' ) - 5, 3 );
		while ( $commentmeta_results = $wpdb->get_results( $wpdb->prepare( "SELECT m.meta_id, m.comment_id, m.meta_key FROM {$wpdb->commentmeta} as m LEFT JOIN {$wpdb->comments} as c USING(comment_id) WHERE c.comment_id IS NULL AND m.meta_id > %d ORDER BY m.meta_id LIMIT 1000", $last_meta_id ) ) ) {
			if ( empty( $commentmeta_results ) ) {
				return;
			}
			$wpdb->queries = array();
			$commentmeta_deleted = 0;
			foreach ( $commentmeta_results as $commentmeta ) {
				if ( 'akismet_' == substr( $commentmeta->meta_key, 0, 8 ) ) {
					delete_comment_meta( $commentmeta->comment_id, $commentmeta->meta_key );
					do_action( 'akismet_batch_delete_count', __FUNCTION__ );
					++$commentmeta_deleted;
				}
				$last_meta_id = $commentmeta->meta_id;
			}
			do_action( 'akismet_delete_commentmeta_batch', $commentmeta_deleted );
			// If we're getting close to max_execution_time, quit for this round.
			if ( microtime( true ) - $start_time > $max_exec_time ) {
				return;
			}
		}
		if ( apply_filters( 'akismet_optimize_table', ( mt_rand( 1, 5000 ) == 11 ), $wpdb->commentmeta ) ) { // lucky number
			$wpdb->query( "OPTIMIZE TABLE {$wpdb->commentmeta}" );
		}
	}
	// how many approved comments does this author have?
	public static function get_user_comments_approved( $user_id, $comment_author_email, $comment_author, $comment_author_url ) {
		global $wpdb;
		/**
		 * Which comment types should be ignored when counting a user's approved comments?
		 *
		 * Some plugins add entries to the comments table that are not actual
		 * comments that could have been checked by Akismet. Allow these comments
		 * to be excluded from the "approved comment count" query in order to
		 * avoid artificially inflating the approved comment count.
		 *
		 * @param array $comment_types An array of comment types that won't be considered
		 *                             when counting a user's approved comments.
		 *
		 * @since 4.2.2
		 */
		$excluded_comment_types = apply_filters( 'akismet_excluded_comment_types', array() );
		$comment_type_where = '';
		if ( is_array( $excluded_comment_types ) && ! empty( $excluded_comment_types ) ) {
			$excluded_comment_types = array_unique( $excluded_comment_types );
			foreach ( $excluded_comment_types as $excluded_comment_type ) {
				$comment_type_where .= $wpdb->prepare( ' AND comment_type <> %s ', $excluded_comment_type );
			}
		}
		if ( ! empty( $user_id ) ) {
			return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->comments} WHERE user_id = %d AND comment_approved = 1" . $comment_type_where, $user_id ) );
		}
		if ( ! empty( $comment_author_email ) ) {
			return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->comments} WHERE comment_author_email = %s AND comment_author = %s AND comment_author_url = %s AND comment_approved = 1" . $comment_type_where, $comment_author_email, $comment_author, $comment_author_url ) );
		}
		return 0;
	}
	/**
	 * Get the full comment history for a given comment, as an array in reverse chronological order.
	 * Each entry will have an 'event', a 'time', and possible a 'message' member (if the entry is old enough).
	 * Some entries will also have a 'user' or 'meta' member.
	 *
	 * @param int $comment_id The relevant comment ID.
	 * @return array|bool An array of history events, or false if there is no history.
	 */
	public static function get_comment_history( $comment_id ) {
		$history = get_comment_meta( $comment_id, 'akismet_history', false );
		if ( empty( $history ) || empty( $history[0] ) ) {
			return false;
		}
		/*
		// To see all variants when testing.
		$history[] = array( 'time' => 445856401, 'message' => 'Old versions of Akismet stored the message as a literal string in the commentmeta.', 'event' => null );
		$history[] = array( 'time' => 445856402, 'event' => 'recheck-spam' );
		$history[] = array( 'time' => 445856403, 'event' => 'check-spam' );
		$history[] = array( 'time' => 445856404, 'event' => 'recheck-ham' );
		$history[] = array( 'time' => 445856405, 'event' => 'check-ham' );
		$history[] = array( 'time' => 445856405, 'event' => 'check-ham-pending' );
		$history[] = array( 'time' => 445856406, 'event' => 'wp-blacklisted' );
		$history[] = array( 'time' => 445856406, 'event' => 'wp-disallowed' );
		$history[] = array( 'time' => 445856407, 'event' => 'report-spam' );
		$history[] = array( 'time' => 445856408, 'event' => 'report-spam', 'user' => 'sam' );
		$history[] = array( 'message' => 'sam reported this comment as spam (hardcoded message).', 'time' => 445856400, 'event' => 'report-spam', 'user' => 'sam' );
		$history[] = array( 'time' => 445856409, 'event' => 'report-ham', 'user' => 'sam' );
		$history[] = array( 'message' => 'sam reported this comment as ham (hardcoded message).', 'time' => 445856400, 'event' => 'report-ham', 'user' => 'sam' ); //
		$history[] = array( 'time' => 445856410, 'event' => 'cron-retry-spam' );
		$history[] = array( 'time' => 445856411, 'event' => 'cron-retry-ham' );
		$history[] = array( 'time' => 445856412, 'event' => 'check-error' ); //
		$history[] = array( 'time' => 445856413, 'event' => 'check-error', 'meta' => array( 'response' => 'The server was taking a nap.' ) );
		$history[] = array( 'time' => 445856414, 'event' => 'recheck-error' ); // Should not generate a message.
		$history[] = array( 'time' => 445856415, 'event' => 'recheck-error', 'meta' => array( 'response' => 'The server was taking a nap.' ) );
		$history[] = array( 'time' => 445856416, 'event' => 'status-changedtrash' );
		$history[] = array( 'time' => 445856417, 'event' => 'status-changedspam' );
		$history[] = array( 'time' => 445856418, 'event' => 'status-changedhold' );
		$history[] = array( 'time' => 445856419, 'event' => 'status-changedapprove' );
		$history[] = array( 'time' => 445856420, 'event' => 'status-changed-trash' );
		$history[] = array( 'time' => 445856421, 'event' => 'status-changed-spam' );
		$history[] = array( 'time' => 445856422, 'event' => 'status-changed-hold' );
		$history[] = array( 'time' => 445856423, 'event' => 'status-changed-approve' );
		$history[] = array( 'time' => 445856424, 'event' => 'status-trash', 'user' => 'sam' );
		$history[] = array( 'time' => 445856425, 'event' => 'status-spam', 'user' => 'sam' );
		$history[] = array( 'time' => 445856426, 'event' => 'status-hold', 'user' => 'sam' );
		$history[] = array( 'time' => 445856427, 'event' => 'status-approve', 'user' => 'sam' );
		$history[] = array( 'time' => 445856427, 'event' => 'webhook-spam' );
		$history[] = array( 'time' => 445856427, 'event' => 'webhook-ham' );
		$history[] = array( 'time' => 445856427, 'event' => 'webhook-spam-noaction' );
		$history[] = array( 'time' => 445856427, 'event' => 'webhook-ham-noaction' );
		*/
		usort( $history, array( 'Akismet', '_cmp_time' ) );
		return $history;
	}
	/**
	 * Log an event for a given comment, storing it in comment_meta.
	 *
	 * @param int    $comment_id The ID of the relevant comment.
	 * @param string $message The string description of the event. No longer used.
	 * @param string $event The event code.
	 * @param array  $meta Metadata about the history entry. e.g., the user that reported or changed the status of a given comment.
	 */
	public static function update_comment_history( $comment_id, $message, $event = null, $meta = null ) {
		global $current_user;
		$user = '';
		$event = array(
			'time'  => self::_get_microtime(),
			'event' => $event,
		);
		if ( is_object( $current_user ) && isset( $current_user->user_login ) ) {
			$event['user'] = $current_user->user_login;
		}
		if ( ! empty( $meta ) ) {
			$event['meta'] = $meta;
		}
		// $unique = false so as to allow multiple values per comment
		$r = add_comment_meta( $comment_id, 'akismet_history', $event, false );
	}
	public static function check_db_comment( $id, $recheck_reason = 'recheck_queue' ) {
		global $wpdb;
		if ( ! self::get_api_key() ) {
			return new WP_Error( 'akismet-not-configured', __( 'Akismet is not configured. Please enter an API key.', 'akismet' ) );
		}
		$c = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->comments} WHERE comment_ID = %d", $id ), ARRAY_A );
		if ( ! $c ) {
			return new WP_Error( 'invalid-comment-id', __( 'Comment not found.', 'akismet' ) );
		}
		$c['user_ip']        = $c['comment_author_IP'];
		$c['user_agent']     = $c['comment_agent'];
		$c['referrer']       = '';
		$c['blog']           = get_option( 'home' );
		$c['blog_lang']      = get_locale();
		$c['blog_charset']   = get_option( 'blog_charset' );
		$c['permalink']      = get_permalink( $c['comment_post_ID'] );
		$c['recheck_reason'] = $recheck_reason;
		$c['user_role'] = '';
		if ( ! empty( $c['user_ID'] ) ) {
			$c['user_role'] = self::get_user_roles( $c['user_ID'] );
		}
		if ( self::is_test_mode() ) {
			$c['is_test'] = 'true';
		}
		$c = apply_filters( 'akismet_request_args', $c, 'comment-check' );
		$response = self::http_post( self::build_query( $c ), 'comment-check' );
		if ( ! empty( $response[1] ) ) {
			return $response[1];
		}
		return false;
	}
	public static function recheck_comment( $id, $recheck_reason = 'recheck_queue' ) {
		add_comment_meta( $id, 'akismet_rechecking', true );
		$api_response = self::check_db_comment( $id, $recheck_reason );
		if ( is_wp_error( $api_response ) ) {
			// Invalid comment ID.
		} elseif ( 'true' === $api_response ) {
			wp_set_comment_status( $id, 'spam' );
			update_comment_meta( $id, 'akismet_result', 'true' );
			delete_comment_meta( $id, 'akismet_error' );
			delete_comment_meta( $id, 'akismet_delay_moderation_email' );
			delete_comment_meta( $id, 'akismet_delayed_moderation_email' );
			delete_comment_meta( $id, 'akismet_schedule_approval_fallback' );
			delete_comment_meta( $id, 'akismet_schedule_email_fallback' );
			self::update_comment_history( $id, '', 'recheck-spam' );
		} elseif ( 'false' === $api_response ) {
			update_comment_meta( $id, 'akismet_result', 'false' );
			delete_comment_meta( $id, 'akismet_error' );
			delete_comment_meta( $id, 'akismet_delay_moderation_email' );
			delete_comment_meta( $id, 'akismet_delayed_moderation_email' );
			delete_comment_meta( $id, 'akismet_schedule_approval_fallback' );
			delete_comment_meta( $id, 'akismet_schedule_email_fallback' );
			self::update_comment_history( $id, '', 'recheck-ham' );
		} else {
			// abnormal result: error
			update_comment_meta( $id, 'akismet_result', 'error' );
			self::update_comment_history(
				$id,
				'',
				'recheck-error',
				array( 'response' => substr( $api_response, 0, 50 ) )
			);
		}
		delete_comment_meta( $id, 'akismet_rechecking' );
		return $api_response;
	}
	public static function transition_comment_status( $new_status, $old_status, $comment ) {
		if ( $new_status == $old_status ) {
			return;
		}
		if ( 'spam' === $new_status || 'spam' === $old_status ) {
			// Clear the cache of the "X comments in your spam queue" count on the dashboard.
			wp_cache_delete( 'akismet_spam_count', 'widget' );
		}
		// we don't need to record a history item for deleted comments
		if ( $new_status == 'delete' ) {
			return;
		}
		if ( ! current_user_can( 'edit_post', $comment->comment_post_ID ) && ! current_user_can( 'moderate_comments' ) ) {
			return;
		}
		if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING == true ) {
			return;
		}
		// if this is present, it means the status has been changed by a re-check, not an explicit user action
		if ( get_comment_meta( $comment->comment_ID, 'akismet_rechecking' ) ) {
			return;
		}
		if ( function_exists( 'getallheaders' ) ) {
			$request_headers = getallheaders();
			foreach ( $request_headers as $header => $value ) {
				if ( strtolower( $header ) == 'x-akismet-webhook' ) {
					// This change is due to a webhook request.
					return;
				}
			}
		}
		// Assumption alert:
		// We want to submit comments to Akismet only when a moderator explicitly spams or approves it - not if the status
		// is changed automatically by another plugin.  Unfortunately WordPress doesn't provide an unambiguous way to
		// determine why the transition_comment_status action was triggered.  And there are several different ways by which
		// to spam and unspam comments: bulk actions, ajax, links in moderation emails, the dashboard, and perhaps others.
		// We'll assume that this is an explicit user action if certain POST/GET variables exist.
		if (
			// status=spam: Marking as spam via the REST API or...
			// status=unspam: I'm not sure. Maybe this used to be used instead of status=approved? Or the UI for removing from spam but not approving has been since removed?...
			// status=approved: Unspamming via the REST API (Calypso) or...
			( isset( $_POST['status'] ) && in_array( $_POST['status'], array( 'spam', 'unspam', 'approved' ) ) )
			// spam=1: Clicking "Spam" underneath a comment in wp-admin and allowing the AJAX request to happen.
			|| ( isset( $_POST['spam'] ) && (int) $_POST['spam'] == 1 )
			// unspam=1: Clicking "Not Spam" underneath a comment in wp-admin and allowing the AJAX request to happen. Or, clicking "Undo" after marking something as spam.
			|| ( isset( $_POST['unspam'] ) && (int) $_POST['unspam'] == 1 )
			// comment_status=spam/unspam: It's unclear where this is happening.
			|| ( isset( $_POST['comment_status'] ) && in_array( $_POST['comment_status'], array( 'spam', 'unspam' ) ) )
			// action=spam: Choosing "Mark as Spam" from the Bulk Actions dropdown in wp-admin (or the "Spam it" link in notification emails).
			// action=unspam: Choosing "Not Spam" from the Bulk Actions dropdown in wp-admin.
			// action=spamcomment: Following the "Spam" link below a comment in wp-admin (not allowing AJAX request to happen).
			// action=unspamcomment: Following the "Not Spam" link below a comment in wp-admin (not allowing AJAX request to happen).
			|| ( isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'spam', 'unspam', 'spamcomment', 'unspamcomment' ) ) )
			// action=editedcomment: Editing a comment via wp-admin (and possibly changing its status).
			|| ( isset( $_POST['action'] ) && in_array( $_POST['action'], array( 'editedcomment' ) ) )
			// for=jetpack: Moderation via the WordPress app, Calypso, anything powered by the Jetpack connection.
			|| ( isset( $_GET['for'] ) && ( 'jetpack' == $_GET['for'] ) && ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) )
			// Certain WordPress.com API requests
			|| ( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST )
			// WordPress.org REST API requests
			|| ( defined( 'REST_REQUEST' ) && REST_REQUEST )
		) {
			if ( $new_status == 'spam' && ( $old_status == 'approved' || $old_status == 'unapproved' || ! $old_status ) ) {
				return self::submit_spam_comment( $comment->comment_ID );
			} elseif ( $old_status == 'spam' && ( $new_status == 'approved' || $new_status == 'unapproved' ) ) {
				return self::submit_nonspam_comment( $comment->comment_ID );
			}
		}
		self::update_comment_history( $comment->comment_ID, '', 'status-' . $new_status );
	}
	public static function submit_spam_comment( $comment_id ) {
		global $wpdb, $current_user, $current_site;
		$comment_id = (int) $comment_id;
		$comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->comments} WHERE comment_ID = %d", $comment_id ), ARRAY_A );
		if ( ! $comment ) {
			// it was deleted
			return;
		}
		if ( 'spam' != $comment['comment_approved'] ) {
			return;
		}
		self::update_comment_history( $comment_id, '', 'report-spam' );
		// If the user hasn't configured Akismet, there's nothing else to do at this point.
		if ( ! self::get_api_key() ) {
			return;
		}
		// use the original version stored in comment_meta if available
		$as_submitted = self::sanitize_comment_as_submitted( get_comment_meta( $comment_id, 'akismet_as_submitted', true ) );
		if ( $as_submitted && is_array( $as_submitted ) && isset( $as_submitted['comment_content'] ) ) {
			$comment = array_merge( $comment, $as_submitted );
		}
		$comment['blog']         = get_option( 'home' );
		$comment['blog_lang']    = get_locale();
		$comment['blog_charset'] = get_option( 'blog_charset' );
		$comment['permalink']    = get_permalink( $comment['comment_post_ID'] );
		if ( is_object( $current_user ) ) {
			$comment['reporter'] = $current_user->user_login;
		}
		if ( is_object( $current_site ) ) {
			$comment['site_domain'] = $current_site->domain;
		}
		$comment['user_role'] = '';
		if ( ! empty( $comment['user_ID'] ) ) {
			$comment['user_role'] = self::get_user_roles( $comment['user_ID'] );
		}
		if ( self::is_test_mode() ) {
			$comment['is_test'] = 'true';
		}
		$post = get_post( $comment['comment_post_ID'] );
		if ( ! is_null( $post ) ) {
			$comment['comment_post_modified_gmt'] = $post->post_modified_gmt;
		}
		$comment['comment_check_response'] = self::last_comment_check_response( $comment_id );
		$comment = apply_filters( 'akismet_request_args', $comment, 'submit-spam' );
		$response = self::http_post( self::build_query( $comment ), 'submit-spam' );
		update_comment_meta( $comment_id, 'akismet_user_result', 'true' );
		if ( $comment['reporter'] ) {
			update_comment_meta( $comment_id, 'akismet_user', $comment['reporter'] );
		}
		do_action( 'akismet_submit_spam_comment', $comment_id, $response[1] );
	}
	public static function submit_nonspam_comment( $comment_id ) {
		global $wpdb, $current_user, $current_site;
		$comment_id = (int) $comment_id;
		$comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->comments} WHERE comment_ID = %d", $comment_id ), ARRAY_A );
		if ( ! $comment ) {
			// it was deleted
			return;
		}
		self::update_comment_history( $comment_id, '', 'report-ham' );
		// If the user hasn't configured Akismet, there's nothing else to do at this point.
		if ( ! self::get_api_key() ) {
			return;
		}
		// use the original version stored in comment_meta if available
		$as_submitted = self::sanitize_comment_as_submitted( get_comment_meta( $comment_id, 'akismet_as_submitted', true ) );
		if ( $as_submitted && is_array( $as_submitted ) && isset( $as_submitted['comment_content'] ) ) {
			$comment = array_merge( $comment, $as_submitted );
		}
		$comment['blog']         = get_option( 'home' );
		$comment['blog_lang']    = get_locale();
		$comment['blog_charset'] = get_option( 'blog_charset' );
		$comment['permalink']    = get_permalink( $comment['comment_post_ID'] );
		$comment['user_role']    = '';
		if ( is_object( $current_user ) ) {
			$comment['reporter'] = $current_user->user_login;
		}
		if ( is_object( $current_site ) ) {
			$comment['site_domain'] = $current_site->domain;
		}
		if ( ! empty( $comment['user_ID'] ) ) {
			$comment['user_role'] = self::get_user_roles( $comment['user_ID'] );
		}
		if ( self::is_test_mode() ) {
			$comment['is_test'] = 'true';
		}
		$post = get_post( $comment['comment_post_ID'] );
		if ( ! is_null( $post ) ) {
			$comment['comment_post_modified_gmt'] = $post->post_modified_gmt;
		}
		$comment['comment_check_response'] = self::last_comment_check_response( $comment_id );
		$comment = apply_filters( 'akismet_request_args', $comment, 'submit-ham' );
		$response = self::http_post( self::build_query( $comment ), 'submit-ham' );
		update_comment_meta( $comment_id, 'akismet_user_result', 'false' );
		if ( $comment['reporter'] ) {
			update_comment_meta( $comment_id, 'akismet_user', $comment['reporter'] );
		}
		do_action( 'akismet_submit_nonspam_comment', $comment_id, $response[1] );
	}
	public static function cron_recheck() {
		global $wpdb;
		$api_key = self::get_api_key();
		$status = self::verify_key( $api_key );
		if ( get_option( 'akismet_alert_code' ) || $status == 'invalid' ) {
			// since there is currently a problem with the key, reschedule a check for 6 hours hence
			wp_schedule_single_event( time() + 21600, 'akismet_schedule_cron_recheck' );
			do_action( 'akismet_scheduled_recheck', 'key-problem-' . get_option( 'akismet_alert_code' ) . '-' . $status );
			return false;
		}
		delete_option( 'akismet_available_servers' );
		$comment_errors = $wpdb->get_col( "SELECT comment_id FROM {$wpdb->commentmeta} WHERE meta_key = 'akismet_error'	LIMIT 100" );
		foreach ( (array) $comment_errors as $comment_id ) {
			// if the comment no longer exists, or is too old, remove the meta entry from the queue to avoid getting stuck
			$comment = get_comment( $comment_id );
			if (
				! $comment // Comment has been deleted
				|| strtotime( $comment->comment_date_gmt ) < strtotime( '-15 days' ) // Comment is too old.
				|| $comment->comment_approved !== '0' // Comment is no longer in the Pending queue
				) {
				delete_comment_meta( $comment_id, 'akismet_error' );
				delete_comment_meta( $comment_id, 'akismet_delay_moderation_email' );
				delete_comment_meta( $comment_id, 'akismet_delayed_moderation_email' );
				delete_comment_meta( $comment_id, 'akismet_schedule_approval_fallback' );
				delete_comment_meta( $comment_id, 'akismet_schedule_email_fallback' );
				continue;
			}
			add_comment_meta( $comment_id, 'akismet_rechecking', true );
			$status = self::check_db_comment( $comment_id, 'retry' );
			$event = '';
			if ( $status == 'true' ) {
				$event = 'cron-retry-spam';
			} elseif ( $status == 'false' ) {
				$event = 'cron-retry-ham';
			}
			// If we got back a legit response then update the comment history
			// other wise just bail now and try again later.  No point in
			// re-trying all the comments once we hit one failure.
			if ( ! empty( $event ) ) {
				delete_comment_meta( $comment_id, 'akismet_error' );
				self::update_comment_history( $comment_id, '', $event );
				update_comment_meta( $comment_id, 'akismet_result', $status );
				// make sure the comment status is still pending.  if it isn't, that means the user has already moved it elsewhere.
				$comment = get_comment( $comment_id );
				if ( $comment && 'unapproved' == wp_get_comment_status( $comment_id ) ) {
					if ( $status == 'true' ) {
						wp_spam_comment( $comment_id );
					} elseif ( $status == 'false' ) {
						// comment is good, but it's still in the pending queue.  depending on the moderation settings
						// we may need to change it to approved.
						if ( check_comment( $comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent, $comment->comment_type ) ) {
							wp_set_comment_status( $comment_id, 1 );
						} elseif ( get_comment_meta( $comment_id, 'akismet_delayed_moderation_email', true ) ) {
							wp_new_comment_notify_moderator( $comment_id );
							wp_new_comment_notify_postauthor( $comment_id );
						}
					}
				}
				delete_comment_meta( $comment_id, 'akismet_delay_moderation_email' );
				delete_comment_meta( $comment_id, 'akismet_delayed_moderation_email' );
			} else {
				// If this comment has been pending moderation for longer than MAX_DELAY_BEFORE_MODERATION_EMAIL,
				// send a moderation email now.
				if ( ( intval( gmdate( 'U' ) ) - strtotime( $comment->comment_date_gmt ) ) < self::MAX_DELAY_BEFORE_MODERATION_EMAIL ) {
					delete_comment_meta( $comment_id, 'akismet_delay_moderation_email' );
					delete_comment_meta( $comment_id, 'akismet_delayed_moderation_email' );
					wp_new_comment_notify_moderator( $comment_id );
					wp_new_comment_notify_postauthor( $comment_id );
				}
				delete_comment_meta( $comment_id, 'akismet_rechecking' );
				wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
				do_action( 'akismet_scheduled_recheck', 'check-db-comment-' . $status );
				return;
			}
			delete_comment_meta( $comment_id, 'akismet_rechecking' );
		}
		$remaining = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->commentmeta} WHERE meta_key = 'akismet_error'" );
		if ( $remaining && ! wp_next_scheduled( 'akismet_schedule_cron_recheck' ) ) {
			wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
			do_action( 'akismet_scheduled_recheck', 'remaining' );
		}
	}
	public static function fix_scheduled_recheck() {
		$future_check = wp_next_scheduled( 'akismet_schedule_cron_recheck' );
		if ( ! $future_check ) {
			return;
		}
		if ( get_option( 'akismet_alert_code' ) > 0 ) {
			return;
		}
		$check_range = time() + 1200;
		if ( $future_check > $check_range ) {
			wp_clear_scheduled_hook( 'akismet_schedule_cron_recheck' );
			wp_schedule_single_event( time() + 300, 'akismet_schedule_cron_recheck' );
			do_action( 'akismet_scheduled_recheck', 'fix-scheduled-recheck' );
		}
	}
	public static function add_comment_nonce( $post_id ) {
		/**
		 * To disable the Akismet comment nonce, add a filter for the 'akismet_comment_nonce' tag
		 * and return any string value that is not 'true' or '' (empty string).
		 *
		 * Don't return boolean false, because that implies that the 'akismet_comment_nonce' option
		 * has not been set and that Akismet should just choose the default behavior for that
		 * situation.
		 */
		if ( ! self::get_api_key() ) {
			return;
		}
		$akismet_comment_nonce_option = apply_filters( 'akismet_comment_nonce', get_option( 'akismet_comment_nonce' ) );
		if ( $akismet_comment_nonce_option == 'true' || $akismet_comment_nonce_option == '' ) {
			echo '<p style="display: none;">';
			wp_nonce_field( 'akismet_comment_nonce_' . $post_id, 'akismet_comment_nonce', false );
			echo '</p>';
		}
	}
	public static function is_test_mode() {
		return defined( 'AKISMET_TEST_MODE' ) && AKISMET_TEST_MODE;
	}
	public static function allow_discard() {
		if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
			return false;
		}
		if ( is_user_logged_in() ) {
			return false;
		}
		return ( get_option( 'akismet_strictness' ) === '1' );
	}
	public static function get_ip_address() {
		return isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : null;
	}
	/**
	 * Using the unique values that we assign, do we consider these two comments
	 * to be the same instance of a comment?
	 *
	 * The only fields that matter in $comment1 and $comment2 are akismet_guid and akismet_skipped_microtime.
	 * We set both of these during the comment-check call, and if the comment has been saved to the DB,
	 * we save them as comment meta and add them back into the comment array before comparing the comments.
	 *
	 * @param mixed $comment1 A comment object or array.
	 * @param mixed $comment2 A comment object or array.
	 * @return bool Whether the two comments should be treated as the same comment.
	 */
	private static function comments_match( $comment1, $comment2 ) {
		$comment1 = (array) $comment1;
		$comment2 = (array) $comment2;
		if ( ! empty( $comment1['akismet_guid'] ) && ! empty( $comment2['akismet_guid'] ) ) {
			// If the comment got sent to the API and got a response, it will have a GUID.
			return ( $comment1['akismet_guid'] == $comment2['akismet_guid'] );
		} else if ( ! empty( $comment1['akismet_skipped_microtime'] ) && ! empty( $comment2['akismet_skipped_microtime'] ) ) {
			// It won't have a GUID if it didn't get sent to the API because it matched the disallowed list,
			// but it should have a microtimestamp to use here for matching against the comment DB entry it matches.
			return ( strval( $comment1['akismet_skipped_microtime'] ) == strval( $comment2['akismet_skipped_microtime'] ) );
		}
		return false;
	}
	/**
	 * Does the supplied comment match the details of the one most recently stored in self::$last_comment?
	 *
	 * @param array $comment
	 * @return bool Whether the comment supplied as an argument is a match for the one we have stored in $last_comment.
	 */
	public static function matches_last_comment( $comment ) {
		if ( ! self::$last_comment ) {
			return false;
		}
		return self::comments_match( $comment, self::$last_comment );
	}
	/**
	 * Because of the order of operations, we don't always know the comment ID of the comment that we're checking,
	 * so we have to be able to match the comment we cached locally with the comment from the DB.
	 *
	 * @param int $comment_id
	 * @return bool Whether the comment represented by $comment_id is a match for the one we have stored in $last_comment.
	 */
	public static function matches_last_comment_by_id( $comment_id ) {
		return self::matches_last_comment( self::get_fields_for_comment_matching( $comment_id ) );
	}
	/**
	 * Given a comment ID, retrieve the values that we use for matching comments together.
	 *
	 * @param int $comment_id
	 * @return array An array containing akismet_guid and akismet_skipped_microtime. Either or both may be falsy, but we hope that at least one is a string.
	 */
	public static function get_fields_for_comment_matching( $comment_id ) {
		return array(
			'akismet_guid' => get_comment_meta( $comment_id, 'akismet_guid', true ),
			'akismet_skipped_microtime' => get_comment_meta( $comment_id, 'akismet_skipped_microtime', true ),
		);
	}
	private static function get_user_agent() {
		return isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : null;
	}
	private static function get_referer() {
		return isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : null;
	}
	// return a comma-separated list of role names for the given user
	public static function get_user_roles( $user_id ) {
		$comment_user = null;
		$roles        = false;
		if ( ! class_exists( 'WP_User' ) ) {
			return false;
		}
		if ( $user_id > 0 ) {
			$comment_user = new WP_User( $user_id );
			if ( isset( $comment_user->roles ) ) {
				$roles = implode( ',', $comment_user->roles );
			}
		}
		if ( is_multisite() && is_super_admin( $user_id ) ) {
			if ( empty( $roles ) ) {
				$roles = 'super_admin';
			} else {
				$comment_user->roles[] = 'super_admin';
				$roles                 = implode( ',', $comment_user->roles );
			}
		}
		return $roles;
	}
	// filter handler used to return a spam result to pre_comment_approved
	public static function last_comment_status( $approved, $comment ) {
		if ( is_null( self::$last_comment_result ) ) {
			// We didn't have reason to store the result of the last check.
			return $approved;
		}
		// Only do this if it's the correct comment.
		if ( ! self::matches_last_comment( $comment ) ) {
			self::log( "comment_is_spam mismatched comment, returning unaltered $approved" );
			return $approved;
		}
		if ( 'trash' === $approved ) {
			// If the last comment we checked has had its approval set to 'trash',
			// then it failed the comment blacklist check. Let that blacklist override
			// the spam check, since users have the (valid) expectation that when
			// they fill out their blacklists, comments that match it will always
			// end up in the trash.
			return $approved;
		}
		// bump the counter here instead of when the filter is added to reduce the possibility of overcounting
		if ( $incr = apply_filters( 'akismet_spam_count_incr', 1 ) ) {
			update_option( 'akismet_spam_count', get_option( 'akismet_spam_count' ) + $incr );
		}
		return self::$last_comment_result;
	}
	/**
	 * If Akismet is temporarily unreachable, we don't want to "spam" the blogger or post author
	 * with emails for comments that will be automatically cleared or spammed on the next retry.
	 *
	 * @param bool $maybe_notify Whether the notification email will be sent.
	 * @param int   $comment_id The ID of the relevant comment.
	 * @return bool Whether the notification email should still be sent.
	 */
	public static function disable_emails_if_unreachable( $maybe_notify, $comment_id ) {
		if ( $maybe_notify ) {
			if ( get_comment_meta( $comment_id, 'akismet_delay_moderation_email', true ) ) {
				self::log( 'Disabling notification email for comment #' . $comment_id );
				update_comment_meta( $comment_id, 'akismet_delayed_moderation_email', true );
				delete_comment_meta( $comment_id, 'akismet_delay_moderation_email' );
				// If we want to prevent the email from sending another time, we'll have to reset
				// the akismet_delay_moderation_email commentmeta.
				return false;
			}
		}
		return $maybe_notify;
	}
	public static function _cmp_time( $a, $b ) {
		return $a['time'] > $b['time'] ? -1 : 1;
	}
	public static function _get_microtime() {
		$mtime = explode( ' ', microtime() );
		return $mtime[1] + $mtime[0];
	}
	/**
	 * Make a POST request to the Akismet API.
	 *
	 * @param string $request The body of the request.
	 * @param string $path The path for the request.
	 * @param string $ip The specific IP address to hit.
	 * @return array A two-member array consisting of the headers and the response body, both empty in the case of a failure.
	 */
	public static function http_post( $request, $path, $ip = null ) {
		$akismet_ua = sprintf( 'WordPress/%s | Akismet/%s', $GLOBALS['wp_version'], constant( 'AKISMET_VERSION' ) );
		$akismet_ua = apply_filters( 'akismet_ua', $akismet_ua );
		$host    = self::API_HOST;
		$api_key = self::get_api_key();
		if ( $api_key ) {
			$request = add_query_arg( 'api_key', $api_key, $request );
		}
		$http_host = $host;
		// use a specific IP if provided
		// needed by Akismet_Admin::check_server_connectivity()
		if ( $ip && long2ip( ip2long( $ip ) ) ) {
			$http_host = $ip;
		}
		$http_args = array(
			'body'        => $request,
			'headers'     => array(
				'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ),
				'Host'         => $host,
				'User-Agent'   => $akismet_ua,
			),
			'httpversion' => '1.0',
			'timeout'     => 15,
		);
		$akismet_url = $http_akismet_url = "http://{$http_host}/1.1/{$path}";
		/**
		 * Try SSL first; if that fails, try without it and don't try it again for a while.
		 */
		$ssl = $ssl_failed = false;
		// Check if SSL requests were disabled fewer than X hours ago.
		$ssl_disabled = get_option( 'akismet_ssl_disabled' );
		if ( $ssl_disabled && $ssl_disabled < ( time() - 60 * 60 * 24 ) ) { // 24 hours
			$ssl_disabled = false;
			delete_option( 'akismet_ssl_disabled' );
		} elseif ( $ssl_disabled ) {
			do_action( 'akismet_ssl_disabled' );
		}
		if ( ! $ssl_disabled && ( $ssl = wp_http_supports( array( 'ssl' ) ) ) ) {
			$akismet_url = set_url_scheme( $akismet_url, 'https' );
			do_action( 'akismet_https_request_pre' );
		}
		$response = wp_remote_post( $akismet_url, $http_args );
		self::log( compact( 'akismet_url', 'http_args', 'response' ) );
		if ( $ssl && is_wp_error( $response ) ) {
			do_action( 'akismet_https_request_failure', $response );
			// Intermittent connection problems may cause the first HTTPS
			// request to fail and subsequent HTTP requests to succeed randomly.
			// Retry the HTTPS request once before disabling SSL for a time.
			$response = wp_remote_post( $akismet_url, $http_args );
			self::log( compact( 'akismet_url', 'http_args', 'response' ) );
			if ( is_wp_error( $response ) ) {
				$ssl_failed = true;
				do_action( 'akismet_https_request_failure', $response );
				do_action( 'akismet_http_request_pre' );
				// Try the request again without SSL.
				$response = wp_remote_post( $http_akismet_url, $http_args );
				self::log( compact( 'http_akismet_url', 'http_args', 'response' ) );
			}
		}
		if ( is_wp_error( $response ) ) {
			do_action( 'akismet_request_failure', $response );
			return array( '', '' );
		}
		if ( $ssl_failed ) {
			// The request failed when using SSL but succeeded without it. Disable SSL for future requests.
			update_option( 'akismet_ssl_disabled', time() );
			do_action( 'akismet_https_disabled' );
		}
		$simplified_response = array( $response['headers'], $response['body'] );
		$alert_code_check_paths = array(
			'verify-key',
			'comment-check',
			'get-stats',
		);
		if ( in_array( $path, $alert_code_check_paths ) ) {
			self::update_alert( $simplified_response );
		}
		return $simplified_response;
	}
	// given a response from an API call like check_key_status(), update the alert code options if an alert is present.
	public static function update_alert( $response ) {
		$alert_option_prefix = 'akismet_alert_';
		$alert_header_prefix = 'x-akismet-alert-';
		$alert_header_names  = array(
			'code',
			'msg',
			'api-calls',
			'usage-limit',
			'upgrade-plan',
			'upgrade-url',
			'upgrade-type',
			'upgrade-via-support',
		);
		foreach ( $alert_header_names as $alert_header_name ) {
			$value = null;
			if ( isset( $response[0][ $alert_header_prefix . $alert_header_name ] ) ) {
				$value = $response[0][ $alert_header_prefix . $alert_header_name ];
			}
			$option_name = $alert_option_prefix . str_replace( '-', '_', $alert_header_name );
			if ( $value != get_option( $option_name ) ) {
				if ( ! $value ) {
					delete_option( $option_name );
				} else {
					update_option( $option_name, $value );
				}
			}
		}
	}
	/**
	 * Mark akismet-frontend.js as deferred. Because nothing depends on it, it can run at any time
	 * after it's loaded, and the browser won't have to wait for it to load to continue
	 * parsing the rest of the page.
	 */
	public static function set_form_js_async( $tag, $handle, $src ) {
		if ( 'akismet-frontend' !== $handle ) {
			return $tag;
		}
		return preg_replace( '/^<script /i', '<script defer ', $tag );
	}
	public static function get_akismet_form_fields() {
		$fields = '';
		$prefix = 'ak_';
		// Contact Form 7 uses _wpcf7 as a prefix to know which fields to exclude from comment_content.
		if ( 'wpcf7_form_elements' === current_filter() ) {
			$prefix = '_wpcf7_ak_';
		}
		$fields .= '<p style="display: none !important;" class="akismet-fields-container" data-prefix="' . esc_attr( $prefix ) . '">';
		$fields .= '<label>Δ<textarea name="' . $prefix . 'hp_textarea" cols="45" rows="8" maxlength="100"></textarea></label>';
		if ( ! function_exists( 'amp_is_request' ) || ! amp_is_request() ) {
			// Keep track of how many ak_js fields are in this page so that we don't re-use
			// the same ID.
			static $field_count = 0;
			++$field_count;
			$fields .= '<input type="hidden" id="ak_js_' . $field_count . '" name="' . $prefix . 'js" value="' . mt_rand( 0, 250 ) . '"/>';
			$fields .= '<script>document.getElementById( "ak_js_' . $field_count . '" ).setAttribute( "value", ( new Date() ).getTime() );</script>';
		}
		$fields .= '</p>';
		return $fields;
	}
	public static function output_custom_form_fields( $post_id ) {
		if ( 'fluentform/form_element_start' === current_filter() && did_action( 'fluentform_form_element_start' ) ) {
			// Already did this via the legacy filter.
			return;
		}
		// phpcs:ignore WordPress.Security.EscapeOutput
		echo self::get_akismet_form_fields();
	}
	public static function inject_custom_form_fields( $html ) {
		$html = str_replace( '</form>', self::get_akismet_form_fields() . '</form>', $html );
		return $html;
	}
	public static function append_custom_form_fields( $html ) {
		$html .= self::get_akismet_form_fields();
		return $html;
	}
	/**
	 * Ensure that any Akismet-added form fields are included in the comment-check call.
	 *
	 * @param array $form
	 * @param array $data Some plugins will supply the POST data via the filter, since they don't
	 *                    read it directly from $_POST.
	 * @return array $form
	 */
	public static function prepare_custom_form_values( $form, $data = null ) {
		if ( 'fluentform/akismet_fields' === current_filter() && did_filter( 'fluentform_akismet_fields' ) ) {
			// Already updated the form fields via the legacy filter.
			return $form;
		}
		if ( is_null( $data ) ) {
			// phpcs:ignore WordPress.Security.NonceVerification.Missing
			$data = $_POST;
		}
		$prefix = 'ak_';
		// Contact Form 7 uses _wpcf7 as a prefix to know which fields to exclude from comment_content.
		if ( 'wpcf7_akismet_parameters' === current_filter() ) {
			$prefix = '_wpcf7_ak_';
		}
		foreach ( $data as $key => $val ) {
			if ( 0 === strpos( $key, $prefix ) ) {
				$form[ 'POST_ak_' . substr( $key, strlen( $prefix ) ) ] = $val;
			}
		}
		return $form;
	}
	private static function bail_on_activation( $message, $deactivate = true ) {
		?>
<!doctype html>
<html>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<style>
* {
	text-align: center;
	margin: 0;
	padding: 0;
	font-family: "Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif;
}
p {
	margin-top: 1em;
	font-size: 18px;
}
</style>
</head>
<body>
<p><?php echo esc_html( $message ); ?></p>
</body>
</html>
		<?php
		if ( $deactivate ) {
			$plugins = get_option( 'active_plugins' );
			$akismet = plugin_basename( AKISMET__PLUGIN_DIR . 'akismet.php' );
			$update  = false;
			foreach ( $plugins as $i => $plugin ) {
				if ( $plugin === $akismet ) {
					$plugins[ $i ] = false;
					$update        = true;
				}
			}
			if ( $update ) {
				update_option( 'active_plugins', array_filter( $plugins ) );
			}
		}
		exit;
	}
	public static function view( $name, array $args = array() ) {
		$args = apply_filters( 'akismet_view_arguments', $args, $name );
		foreach ( $args as $key => $val ) {
			$$key = $val;
		}
		$file = AKISMET__PLUGIN_DIR . 'views/' . basename( $name ) . '.php';
		if ( file_exists( $file ) ) {
			include $file;
		}
	}
	/**
	 * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook()
	 *
	 * @static
	 */
	public static function plugin_activation() {
		if ( version_compare( $GLOBALS['wp_version'], AKISMET__MINIMUM_WP_VERSION, '<' ) ) {
			$message = '<strong>' .
				/* translators: 1: Current Akismet version number, 2: Minimum WordPress version number required. */
				sprintf( esc_html__( 'Akismet %1$s requires WordPress %2$s or higher.', 'akismet' ), AKISMET_VERSION, AKISMET__MINIMUM_WP_VERSION ) . '</strong> ' .
				/* translators: 1: WordPress documentation URL, 2: Akismet download URL. */
				sprintf( __( 'Please <a href="%1$s">upgrade WordPress</a> to a current version, or <a href="%2$s">downgrade to version 2.4 of the Akismet plugin</a>.', 'akismet' ), 'https://codex.wordpress.org/Upgrading_WordPress', 'https://wordpress.org/plugins/akismet' );
			self::bail_on_activation( $message );
		} elseif ( ! empty( $_SERVER['SCRIPT_NAME'] ) && false !== strpos( $_SERVER['SCRIPT_NAME'], '/wp-admin/plugins.php' ) ) {
			add_option( 'Activated_Akismet', true );
		}
	}
	/**
	 * Removes all connection options
	 *
	 * @static
	 */
	public static function plugin_deactivation() {
		self::deactivate_key( self::get_api_key() );
		// Remove any scheduled cron jobs.
		$akismet_cron_events = array(
			'akismet_schedule_cron_recheck',
			'akismet_scheduled_delete',
		);
		foreach ( $akismet_cron_events as $akismet_cron_event ) {
			$timestamp = wp_next_scheduled( $akismet_cron_event );
			if ( $timestamp ) {
				wp_unschedule_event( $timestamp, $akismet_cron_event );
			}
		}
	}
	/**
	 * Essentially a copy of WP's build_query but one that doesn't expect pre-urlencoded values.
	 *
	 * @param array $args An array of key => value pairs
	 * @return string A string ready for use as a URL query string.
	 */
	public static function build_query( $args ) {
		return _http_build_query( $args, '', '&' );
	}
	/**
	 * Log debugging info to the error log.
	 *
	 * Enabled when WP_DEBUG_LOG is enabled (and WP_DEBUG, since according to
	 * core, "WP_DEBUG_DISPLAY and WP_DEBUG_LOG perform no function unless
	 * WP_DEBUG is true), but can be disabled via the akismet_debug_log filter.
	 *
	 * @param mixed $akismet_debug The data to log.
	 */
	public static function log( $akismet_debug ) {
		if ( apply_filters( 'akismet_debug_log', defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG && defined( 'AKISMET_DEBUG' ) && AKISMET_DEBUG ) ) {
			error_log( print_r( compact( 'akismet_debug' ), true ) );
		}
	}
	/**
	 * Check pingbacks for spam before they're saved to the DB.
	 *
	 * @param string           $method The XML-RPC method that was called.
	 * @param array            $args This and the $server arg are marked as optional since plugins might still be
	 *                               calling do_action( 'xmlrpc_action', [...] ) without the arguments that were added in WP 5.7.
	 * @param wp_xmlrpc_server $server
	 */
	public static function pre_check_pingback( $method, $args = array(), $server = null ) {
		if ( $method !== 'pingback.ping' ) {
			return;
		}
		/*
		 * $args looks like this:
		 *
		 * Array
		 * (
		 *     [0] => http://www.example.net/?p=1 // Site that created the pingback.
		 *     [1] => https://www.example.com/?p=2 // Post being pingback'd on this site.
		 * )
		 */
		if ( ! is_null( $server ) && ! empty( $args[1] ) ) {
			$is_multicall    = false;
			$multicall_count = 0;
			if ( 'system.multicall' === $server->message->methodName ) {
				$is_multicall    = true;
				$multicall_count = is_countable( $server->message->params ) ? count( $server->message->params ) : 0;
			}
			$post_id = url_to_postid( $args[1] );
			// If pingbacks aren't open on this post, we'll still check whether this request is part of a potential DDOS,
			// but indicate to the server that pingbacks are indeed closed so we don't include this request in the user's stats,
			// since the user has already done their part by disabling pingbacks.
			$pingbacks_closed = false;
			$post = get_post( $post_id );
			if ( ! $post || ! pings_open( $post ) ) {
				$pingbacks_closed = true;
			}
			$comment = array(
				'comment_author_url'      => $args[0],
				'comment_post_ID'         => $post_id,
				'comment_author'          => '',
				'comment_author_email'    => '',
				'comment_content'         => '',
				'comment_type'            => 'pingback',
				'akismet_pre_check'       => '1',
				'comment_pingback_target' => $args[1],
				'pingbacks_closed'        => $pingbacks_closed ? '1' : '0',
				'is_multicall'            => $is_multicall,
				'multicall_count'         => $multicall_count,
			);
			$comment = self::auto_check_comment( $comment, 'xml-rpc' );
			if ( isset( $comment['akismet_result'] ) && 'true' == $comment['akismet_result'] ) {
				// Sad: tightly coupled with the IXR classes. Unfortunately the action provides no context and no way to return anything.
				$server->error( new IXR_Error( 0, 'Invalid discovery target' ) );
				// Also note that if this was part of a multicall, a spam result will prevent the subsequent calls from being executed.
				// This is probably fine, but it raises the bar for what should be acceptable as a false positive.
			}
		}
	}
	/**
	 * Ensure that we are loading expected scalar values from akismet_as_submitted commentmeta.
	 *
	 * @param mixed $meta_value
	 * @return mixed
	 */
	private static function sanitize_comment_as_submitted( $meta_value ) {
		if ( empty( $meta_value ) ) {
			return $meta_value;
		}
		$meta_value = (array) $meta_value;
		foreach ( $meta_value as $key => $value ) {
			if ( ! is_scalar( $value ) ) {
				unset( $meta_value[ $key ] );
			} else {
				// These can change, so they're not explicitly listed in comment_as_submitted_allowed_keys.
				if ( strpos( $key, 'POST_ak_' ) === 0 ) {
					continue;
				}
				if ( ! isset( self::$comment_as_submitted_allowed_keys[ $key ] ) ) {
					unset( $meta_value[ $key ] );
				}
			}
		}
		return $meta_value;
	}
	public static function predefined_api_key() {
		if ( defined( 'WPCOM_API_KEY' ) ) {
			return true;
		}
		return apply_filters( 'akismet_predefined_api_key', false );
	}
	/**
	 * Controls the display of a privacy related notice underneath the comment
	 * form using the `akismet_comment_form_privacy_notice` option and filter
	 * respectively.
	 *
	 * Default is to not display the notice, leaving the choice to site admins,
	 * or integrators.
	 */
	public static function display_comment_form_privacy_notice() {
		if ( 'display' !== apply_filters( 'akismet_comment_form_privacy_notice', get_option( 'akismet_comment_form_privacy_notice', 'hide' ) ) ) {
			return;
		}
		echo apply_filters(
			'akismet_comment_form_privacy_notice_markup',
			'<p class="akismet_comment_form_privacy_notice">' .
				wp_kses(
					sprintf(
						/* translators: %s: Akismet privacy URL */
						__( 'This site uses Akismet to reduce spam. <a href="%s" target="_blank" rel="nofollow noopener">Learn how your comment data is processed.</a>', 'akismet' ),
						'https://akismet.com/privacy/'
					),
					array(
						'a' => array(
							'href' => array(),
							'target' => array(),
							'rel' => array(),
						),
					)
				) .
			'</p>'
		);
	}
	public static function load_form_js() {
		if (
			! is_admin()
			&& ( ! function_exists( 'amp_is_request' ) || ! amp_is_request() )
			&& self::get_api_key()
			) {
			wp_register_script( 'akismet-frontend', plugin_dir_url( __FILE__ ) . '_inc/akismet-frontend.js', array(), filemtime( plugin_dir_path( __FILE__ ) . '_inc/akismet-frontend.js' ), true );
			wp_enqueue_script( 'akismet-frontend' );
		}
	}
	/**
	 * Add the form JavaScript when we detect that a supported form shortcode is being parsed.
	 */
	public static function load_form_js_via_filter( $return_value, $tag, $attr, $m ) {
		if ( in_array( $tag, array( 'contact-form', 'gravityform', 'contact-form-7', 'formidable', 'fluentform' ) ) ) {
			self::load_form_js();
		}
		return $return_value;
	}
	/**
	 * Was the last entry in the comment history created by Akismet?
	 *
	 * @param int $comment_id The ID of the comment.
	 * @return bool
	 */
	public static function last_comment_status_change_came_from_akismet( $comment_id ) {
		$history = self::get_comment_history( $comment_id );
		if ( empty( $history ) ) {
			return false;
		}
		$most_recent_history_event = $history[0];
		if ( ! isset( $most_recent_history_event['event'] ) ) {
			return false;
		}
		$akismet_history_events = array(
			'check-error',
			'cron-retry-ham',
			'cron-retry-spam',
			'check-ham',
			'check-ham-pending',
			'check-spam',
			'recheck-error',
			'recheck-ham',
			'recheck-spam',
			'webhook-ham',
			'webhook-spam',
		);
		if ( in_array( $most_recent_history_event['event'], $akismet_history_events ) ) {
			return true;
		}
		return false;
	}
	/**
	 * Check the comment history to find out what the most recent comment-check
	 * response said about this comment.
	 *
	 * This value is then included in submit-ham and submit-spam requests to allow
	 * us to know whether the comment is actually a missed spam/ham or if it's
	 * just being reclassified after either never being checked or being mistakenly
	 * marked as ham/spam.
	 *
	 * @param int $comment_id The comment ID.
	 * @return string 'true', 'false', or an empty string if we don't have a record
	 *                of comment-check being called.
	 */
	public static function last_comment_check_response( $comment_id ) {
		$history = self::get_comment_history( $comment_id );
		if ( $history ) {
			$history = array_reverse( $history );
			foreach ( $history as $akismet_history_entry ) {
				// We've always been consistent in how history entries are formatted
				// but comment_meta is writable by everyone, so don't assume that all
				// entries contain the expected parts.
				if ( ! is_array( $akismet_history_entry ) ) {
					continue;
				}
				if ( ! isset( $akismet_history_entry['event'] ) ) {
					continue;
				}
				if ( in_array(
					$akismet_history_entry['event'],
					array(
						'recheck-spam',
						'check-spam',
						'cron-retry-spam',
						'webhook-spam',
						'webhook-spam-noaction',
					),
					true
				) ) {
					return 'true';
				} elseif ( in_array(
					$akismet_history_entry['event'],
					array(
						'recheck-ham',
						'check-ham',
						'cron-retry-ham',
						'webhook-ham',
						'webhook-ham-noaction',
					),
					true
				) ) {
					return 'false';
				}
			}
		}
		return '';
	}
}
                                                                                                                         plugins/akismet/LICENSE.txt                                                                         0000644                 00000043254 15100623270 0011511 0                                                                                                    ustar 00                                                                                                                                                                                                                                                                           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.
    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>
    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.
  <signature of Ty Coon>, 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.
                                                                                                                                                                                                                                                                                                                                                    plugins/akismet/wrapper.php                                                                         0000644                 00000014442 15100623270 0012054 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       <?php
global $wpcom_api_key, $akismet_api_host, $akismet_api_port;
$wpcom_api_key    = defined( 'WPCOM_API_KEY' ) ? constant( 'WPCOM_API_KEY' ) : '';
$akismet_api_host = Akismet::get_api_key() . '.rest.akismet.com';
$akismet_api_port = 80;
function akismet_test_mode() {
	return Akismet::is_test_mode();
}
function akismet_http_post( $request, $host, $path, $port = 80, $ip = null ) {
	$path = str_replace( '/1.1/', '', $path );
	return Akismet::http_post( $request, $path, $ip );
}
function akismet_microtime() {
	return Akismet::_get_microtime();
}
function akismet_delete_old() {
	return Akismet::delete_old_comments();
}
function akismet_delete_old_metadata() {
	return Akismet::delete_old_comments_meta();
}
function akismet_check_db_comment( $id, $recheck_reason = 'recheck_queue' ) {
	return Akismet::check_db_comment( $id, $recheck_reason );
}
function akismet_rightnow() {
	if ( ! class_exists( 'Akismet_Admin' ) ) {
		return false;
	}
	return Akismet_Admin::rightnow_stats();
}
function akismet_admin_init() {
	_deprecated_function( __FUNCTION__, '3.0' );
}
function akismet_version_warning() {
	_deprecated_function( __FUNCTION__, '3.0' );
}
function akismet_load_js_and_css() {
	_deprecated_function( __FUNCTION__, '3.0' );
}
function akismet_nonce_field( $action = -1 ) {
	return wp_nonce_field( $action );
}
function akismet_plugin_action_links( $links, $file ) {
	return Akismet_Admin::plugin_action_links( $links, $file );
}
function akismet_conf() {
	_deprecated_function( __FUNCTION__, '3.0' );
}
function akismet_stats_display() {
	_deprecated_function( __FUNCTION__, '3.0' );
}
function akismet_stats() {
	return Akismet_Admin::dashboard_stats();
}
function akismet_admin_warnings() {
	_deprecated_function( __FUNCTION__, '3.0' );
}
function akismet_comment_row_action( $a, $comment ) {
	return Akismet_Admin::comment_row_actions( $a, $comment );
}
function akismet_comment_status_meta_box( $comment ) {
	return Akismet_Admin::comment_status_meta_box( $comment );
}
function akismet_comments_columns( $columns ) {
	_deprecated_function( __FUNCTION__, '3.0' );
	return $columns;
}
function akismet_comment_column_row( $column, $comment_id ) {
	_deprecated_function( __FUNCTION__, '3.0' );
}
function akismet_text_add_link_callback( $m ) {
	return Akismet_Admin::text_add_link_callback( $m );
}
function akismet_text_add_link_class( $comment_text ) {
	return Akismet_Admin::text_add_link_class( $comment_text );
}
function akismet_check_for_spam_button( $comment_status ) {
	return Akismet_Admin::check_for_spam_button( $comment_status );
}
function akismet_submit_nonspam_comment( $comment_id ) {
	return Akismet::submit_nonspam_comment( $comment_id );
}
function akismet_submit_spam_comment( $comment_id ) {
	return Akismet::submit_spam_comment( $comment_id );
}
function akismet_transition_comment_status( $new_status, $old_status, $comment ) {
	return Akismet::transition_comment_status( $new_status, $old_status, $comment );
}
function akismet_spam_count( $type = false ) {
	return Akismet_Admin::get_spam_count( $type );
}
function akismet_recheck_queue() {
	return Akismet_Admin::recheck_queue();
}
function akismet_remove_comment_author_url() {
	return Akismet_Admin::remove_comment_author_url();
}
function akismet_add_comment_author_url() {
	return Akismet_Admin::add_comment_author_url();
}
function akismet_check_server_connectivity() {
	return Akismet_Admin::check_server_connectivity();
}
function akismet_get_server_connectivity( $cache_timeout = 86400 ) {
	return Akismet_Admin::get_server_connectivity( $cache_timeout );
}
function akismet_server_connectivity_ok() {
	_deprecated_function( __FUNCTION__, '3.0' );
	return true;
}
function akismet_admin_menu() {
	return Akismet_Admin::admin_menu();
}
function akismet_load_menu() {
	return Akismet_Admin::load_menu();
}
function akismet_init() {
	_deprecated_function( __FUNCTION__, '3.0' );
}
function akismet_get_key() {
	return Akismet::get_api_key();
}
function akismet_check_key_status( $key, $ip = null ) {
	return Akismet::check_key_status( $key, $ip );
}
function akismet_update_alert( $response ) {
	return Akismet::update_alert( $response );
}
function akismet_verify_key( $key, $ip = null ) {
	return Akismet::verify_key( $key, $ip );
}
function akismet_get_user_roles( $user_id ) {
	return Akismet::get_user_roles( $user_id );
}
function akismet_result_spam( $approved ) {
	return Akismet::comment_is_spam( $approved );
}
function akismet_result_hold( $approved ) {
	return Akismet::comment_needs_moderation( $approved );
}
function akismet_get_user_comments_approved( $user_id, $comment_author_email, $comment_author, $comment_author_url ) {
	return Akismet::get_user_comments_approved( $user_id, $comment_author_email, $comment_author, $comment_author_url );
}
function akismet_update_comment_history( $comment_id, $message, $event = null ) {
	return Akismet::update_comment_history( $comment_id, $message, $event );
}
function akismet_get_comment_history( $comment_id ) {
	return Akismet::get_comment_history( $comment_id );
}
function akismet_cmp_time( $a, $b ) {
	return Akismet::_cmp_time( $a, $b );
}
function akismet_auto_check_update_meta( $id, $comment ) {
	return Akismet::auto_check_update_meta( $id, $comment );
}
function akismet_auto_check_comment( $commentdata ) {
	return Akismet::auto_check_comment( $commentdata );
}
function akismet_get_ip_address() {
	return Akismet::get_ip_address();
}
function akismet_cron_recheck() {
	return Akismet::cron_recheck();
}
function akismet_add_comment_nonce( $post_id ) {
	return Akismet::add_comment_nonce( $post_id );
}
function akismet_fix_scheduled_recheck() {
	return Akismet::fix_scheduled_recheck();
}
function akismet_spam_comments() {
	_deprecated_function( __FUNCTION__, '3.0' );
	return array();
}
function akismet_spam_totals() {
	_deprecated_function( __FUNCTION__, '3.0' );
	return array();
}
function akismet_manage_page() {
	_deprecated_function( __FUNCTION__, '3.0' );
}
function akismet_caught() {
	_deprecated_function( __FUNCTION__, '3.0' );
}
function redirect_old_akismet_urls() {
	_deprecated_function( __FUNCTION__, '3.0' );
}
function akismet_kill_proxy_check( $option ) {
	_deprecated_function( __FUNCTION__, '3.0' );
	return 0;
}
function akismet_pingback_forwarded_for( $r, $url ) {
	// This functionality is now in core.
	return false;
}
function akismet_pre_check_pingback( $method ) {
	return Akismet::pre_check_pingback( $method );
}
                                                                                                                                                                                                                              plugins/akismet/index.php                                                                           0000644                 00000000072 15100623270 0011475 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       <?php
declare( strict_types = 1 );
// Silence is golden.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                      plugins/akismet/class.akismet-cli.php                                                               0000644                 00000011621 15100623270 0013676 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       <?php
WP_CLI::add_command( 'akismet', 'Akismet_CLI' );
/**
 * Filter spam comments.
 */
class Akismet_CLI extends WP_CLI_Command {
	/**
	 * Checks one or more comments against the Akismet API.
	 *
	 * ## OPTIONS
	 * <comment_id>...
	 * : The ID(s) of the comment(s) to check.
	 *
	 * [--noaction]
	 * : Don't change the status of the comment. Just report what Akismet thinks it is.
	 *
	 * ## EXAMPLES
	 *
	 *     wp akismet check 12345
	 *
	 * @alias comment-check
	 */
	public function check( $args, $assoc_args ) {
		foreach ( $args as $comment_id ) {
			if ( isset( $assoc_args['noaction'] ) ) {
				// Check the comment, but don't reclassify it.
				$api_response = Akismet::check_db_comment( $comment_id, 'wp-cli' );
			} else {
				$api_response = Akismet::recheck_comment( $comment_id, 'wp-cli' );
			}
			if ( 'true' === $api_response ) {
				/* translators: %d: Comment ID. */
				WP_CLI::line( sprintf( __( 'Comment #%d is spam.', 'akismet' ), $comment_id ) );
			} elseif ( 'false' === $api_response ) {
				/* translators: %d: Comment ID. */
				WP_CLI::line( sprintf( __( 'Comment #%d is not spam.', 'akismet' ), $comment_id ) );
			} elseif ( false === $api_response ) {
				/* translators: %d: Comment ID. */
				WP_CLI::error( __( 'Failed to connect to Akismet.', 'akismet' ) );
			} elseif ( is_wp_error( $api_response ) ) {
				/* translators: %d: Comment ID. */
				WP_CLI::warning( sprintf( __( 'Comment #%d could not be checked.', 'akismet' ), $comment_id ) );
			}
		}
	}
	/**
	 * Recheck all comments in the Pending queue.
	 *
	 * ## EXAMPLES
	 *
	 *     wp akismet recheck_queue
	 *
	 * @alias recheck-queue
	 */
	public function recheck_queue() {
		$batch_size = 100;
		$start      = 0;
		$total_counts = array();
		do {
			$result_counts = Akismet_Admin::recheck_queue_portion( $start, $batch_size );
			if ( $result_counts['processed'] > 0 ) {
				foreach ( $result_counts as $key => $count ) {
					if ( ! isset( $total_counts[ $key ] ) ) {
						$total_counts[ $key ] = $count;
					} else {
						$total_counts[ $key ] += $count;
					}
				}
				$start += $batch_size;
				$start -= $result_counts['spam']; // These comments will have been removed from the queue.
			}
		} while ( $result_counts['processed'] > 0 );
		/* translators: %d: Number of comments. */
		WP_CLI::line( sprintf( _n( 'Processed %d comment.', 'Processed %d comments.', $total_counts['processed'], 'akismet' ), number_format( $total_counts['processed'] ) ) );
		/* translators: %d: Number of comments. */
		WP_CLI::line( sprintf( _n( '%d comment moved to Spam.', '%d comments moved to Spam.', $total_counts['spam'], 'akismet' ), number_format( $total_counts['spam'] ) ) );
		if ( $total_counts['error'] ) {
			/* translators: %d: Number of comments. */
			WP_CLI::line( sprintf( _n( '%d comment could not be checked.', '%d comments could not be checked.', $total_counts['error'], 'akismet' ), number_format( $total_counts['error'] ) ) );
		}
	}
	/**
	 * Fetches stats from the Akismet API.
	 *
	 * ## OPTIONS
	 *
	 * [<interval>]
	 * : The time period for which to retrieve stats.
	 * ---
	 * default: all
	 * options:
	 *  - days
	 *  - months
	 *  - all
	 * ---
	 *
	 * [--format=<format>]
	 * : Allows overriding the output of the command when listing connections.
	 * ---
	 * default: table
	 * options:
	 *  - table
	 *  - json
	 *  - csv
	 *  - yaml
	 *  - count
	 * ---
	 *
	 * [--summary]
	 * : When set, will display a summary of the stats.
	 *
	 * ## EXAMPLES
	 *
	 * wp akismet stats
	 * wp akismet stats all
	 * wp akismet stats days
	 * wp akismet stats months
	 * wp akismet stats all --summary
	 */
	public function stats( $args, $assoc_args ) {
		$api_key = Akismet::get_api_key();
		if ( empty( $api_key ) ) {
			WP_CLI::error( __( 'API key must be set to fetch stats.', 'akismet' ) );
		}
		switch ( $args[0] ) {
			case 'days':
				$interval = '60-days';
				break;
			case 'months':
				$interval = '6-months';
				break;
			default:
				$interval = 'all';
				break;
		}
		$request_args = array(
			'blog' => get_option( 'home' ),
			'key'  => $api_key,
			'from' => $interval,
		);
		$request_args = apply_filters( 'akismet_request_args', $request_args, 'get-stats' );
		$response = Akismet::http_post( Akismet::build_query( $request_args ), 'get-stats' );
		if ( empty( $response[1] ) ) {
			WP_CLI::error( __( 'Currently unable to fetch stats. Please try again.', 'akismet' ) );
		}
		$response_body = json_decode( $response[1], true );
		if ( is_null( $response_body ) ) {
			WP_CLI::error( __( 'Stats response could not be decoded.', 'akismet' ) );
		}
		if ( isset( $assoc_args['summary'] ) ) {
			$keys = array(
				'spam',
				'ham',
				'missed_spam',
				'false_positives',
				'accuracy',
				'time_saved',
			);
			WP_CLI\Utils\format_items( $assoc_args['format'], array( $response_body ), $keys );
		} else {
			$stats = $response_body['breakdown'];
			WP_CLI\Utils\format_items( $assoc_args['format'], $stats, array_keys( end( $stats ) ) );
		}
	}
}
                                                                                                               plugins/akismet/views/enter.php                                                                     0000644                 00000002024 15100623270 0012637 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       <div class="akismet-enter-api-key-box centered">
	<button class="akismet-enter-api-key-box__reveal"><?php esc_html_e( 'Manually enter an API key', 'akismet' ); ?></button>
	<div class="akismet-enter-api-key-box__form-wrapper">
		<form action="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>" method="post">
			<?php wp_nonce_field( Akismet_Admin::NONCE ); ?>
			<input type="hidden" name="action" value="enter-key">
			<h3 class="akismet-enter-api-key-box__header" id="akismet-enter-api-key-box__header"><?php esc_html_e( 'Enter your API key', 'akismet' ); ?></h3>
			<div class="akismet-enter-api-key-box__input-wrapper">
				<input id="key" name="key" type="text" size="15" value="" placeholder="<?php esc_attr_e( 'API key', 'akismet' ); ?>" class="akismet-enter-api-key-box__key-input regular-text code" aria-labelledby="akismet-enter-api-key-box__header">
				<input type="submit" name="submit" id="submit" class="akismet-button" value="<?php esc_attr_e( 'Connect with API key', 'akismet' ); ?>">
			</div>
		</form>
	</div>
</div>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            plugins/akismet/views/connect-jp.php                                                                0000644                 00000011741 15100623270 0013570 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       <?php
//phpcs:disable VariableAnalysis
// There are "undefined" variables here because they're defined in the code that includes this file as a template.
?>
<div class="akismet-box">
	<?php Akismet::view( 'title' ); ?>
	<div class="akismet-jp-connect">
		<h3><?php esc_html_e( 'Connect with Jetpack', 'akismet' ); ?></h3>
		<?php if ( in_array( $akismet_user->status, array( 'no-sub', 'missing' ) ) ) { ?>
			<p><?php esc_html_e( 'Use your Jetpack connection to set up Akismet.', 'akismet' ); ?></p>
			<form name="akismet_activate" id="akismet_activate" action="https://akismet.com/get/" method="post" class="akismet-right" target="_blank">
				<input type="hidden" name="passback_url" value="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>"/>
				<input type="hidden" name="blog" value="<?php echo esc_url( get_option( 'home' ) ); ?>"/>
				<input type="hidden" name="auto-connect" value="<?php echo esc_attr( $akismet_user->ID ); ?>"/>
				<input type="hidden" name="redirect" value="plugin-signup"/>
				<input type="submit" class="akismet-button akismet-is-primary" value="<?php esc_attr_e( 'Connect with Jetpack', 'akismet' ); ?>"/>
			</form>
			<?php echo get_avatar( $akismet_user->user_email, null, null, null, array( 'class' => 'akismet-jetpack-gravatar' ) ); ?>
			<p>
				<?php
				/* translators: %s is the WordPress.com username */
				printf( esc_html( __( 'You are connected as %s.', 'akismet' ) ), '<b>' . esc_html( $akismet_user->user_login ) . '</b>' );
				?>
				<br />
				<span class="akismet-jetpack-email"><?php echo esc_html( $akismet_user->user_email ); ?></span>
			</p>
		<?php } elseif ( $akismet_user->status == 'cancelled' ) { ?>
			<p><?php esc_html_e( 'Use your Jetpack connection to set up Akismet.', 'akismet' ); ?></p>
			<form name="akismet_activate" id="akismet_activate" action="https://akismet.com/get/" method="post" class="akismet-right" target="_blank">
				<input type="hidden" name="passback_url" value="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>"/>
				<input type="hidden" name="blog" value="<?php echo esc_url( get_option( 'home' ) ); ?>"/>
				<input type="hidden" name="user_id" value="<?php echo esc_attr( $akismet_user->ID ); ?>"/>
				<input type="hidden" name="redirect" value="upgrade"/>
				<input type="submit" class="akismet-button akismet-is-primary" value="<?php esc_attr_e( 'Connect with Jetpack', 'akismet' ); ?>"/>
			</form>
			<?php echo get_avatar( $akismet_user->user_email, null, null, null, array( 'class' => 'akismet-jetpack-gravatar' ) ); ?>
			<p>
				<?php
				/* translators: %s is the WordPress.com email address */
				echo esc_html( sprintf( __( 'Your subscription for %s is cancelled.', 'akismet' ), $akismet_user->user_email ) );
				?>
				<br />
				<span class="akismet-jetpack-email"><?php echo esc_html( $akismet_user->user_email ); ?></span>
			</p>
		<?php } elseif ( $akismet_user->status == 'suspended' ) { ?>
			<div class="akismet-right">
				<p><a href="https://akismet.com/contact" class="akismet-button akismet-is-primary"><?php esc_html_e( 'Contact Akismet support', 'akismet' ); ?></a></p>
			</div>
			<p>
				<span class="akismet-alert-text">
					<?php
					/* translators: %s is the WordPress.com email address */
					echo esc_html( sprintf( __( 'Your subscription for %s is suspended.', 'akismet' ), $akismet_user->user_email ) );
					?>
				</span>
				<?php esc_html_e( 'No worries! Get in touch and we’ll sort this out.', 'akismet' ); ?>
			</p>
		<?php } else { // ask do they want to use akismet account found using jetpack wpcom connection ?>
			<p><?php esc_html_e( 'Use your Jetpack connection to set up Akismet.', 'akismet' ); ?></p>
			<form name="akismet_use_wpcom_key" action="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>" method="post" id="akismet-activate" class="akismet-right">
				<input type="hidden" name="key" value="<?php echo esc_attr( $akismet_user->api_key ); ?>"/>
				<input type="hidden" name="action" value="enter-key">
				<?php wp_nonce_field( Akismet_Admin::NONCE ); ?>
				<input type="submit" class="akismet-button akismet-is-primary" value="<?php esc_attr_e( 'Connect with Jetpack', 'akismet' ); ?>"/>
			</form>
			<?php echo get_avatar( $akismet_user->user_email, null, null, null, array( 'class' => 'akismet-jetpack-gravatar' ) ); ?>
			<p>
				<?php
				/* translators: %s is the WordPress.com username */
				printf( esc_html( __( 'You are connected as %s.', 'akismet' ) ), '<b>' . esc_html( $akismet_user->user_login ) . '</b>' );
				?>
				<br />
				<span class="akismet-jetpack-email"><?php echo esc_html( $akismet_user->user_email ); ?></span>
			</p>
		<?php } ?>
	</div>
	<div class="akismet-ak-connect">
		<?php Akismet::view( 'setup' ); ?>
	</div>
	<div class="centered akismet-toggles">
		<a href="#" class="toggle-jp-connect"><?php esc_html_e( 'Connect with Jetpack', 'akismet' ); ?></a>
		<a href="#" class="toggle-ak-connect"><?php esc_html_e( 'Set up a different account', 'akismet' ); ?></a>
	</div>
</div>
<br/>
<div class="akismet-box">
	<?php Akismet::view( 'enter' ); ?>
</div>
                               plugins/akismet/views/predefined.php                                                                0000644                 00000000470 15100623270 0013632 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       <div class="akismet-box">
	<h2><?php esc_html_e( 'Manual Configuration', 'akismet' ); ?></h2>
	<p>
		<?php
		/* translators: %s is the wp-config.php file */
		printf( esc_html__( 'An Akismet API key has been defined in the %s file for this site.', 'akismet' ), '<code>wp-config.php</code>' );
		?>
	</p>
</div>