Файловый менеджер - Редактировать - /home/tuudkjt/globeasy/wp-includes/ID3/akismet.tar
Назад
service.php 0000777 00000003536 15251460151 0006733 0 ustar 00 <?php if ( ! class_exists( 'WPCF7_Service' ) ) { return; } class WPCF7_Akismet extends WPCF7_Service { private static $instance; public static function get_instance() { if ( empty( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } public function get_title() { return __( 'Akismet', 'contact-form-7' ); } public function is_active() { return wpcf7_akismet_is_available(); } public function get_categories() { return array( 'spam_protection' ); } public function icon() { } public function link() { echo wp_kses_data( wpcf7_link( 'https://akismet.com/', 'akismet.com' ) ); } public function display( $action = '' ) { $formatter = new WPCF7_HTMLFormatter(); $formatter->append_start_tag( 'p' ); $formatter->append_preformatted( esc_html( __( 'CAPTCHAs are designed to distinguish spambots from humans, and are therefore helpless against human spammers. In contrast to CAPTCHAs, Akismet checks form submissions against the global database of spam; this means Akismet is a comprehensive solution against spam. This is why we consider Akismet to be the centerpiece of the spam prevention strategy.', 'contact-form-7' ) ) ); $formatter->end_tag( 'p' ); $formatter->append_start_tag( 'p' ); $formatter->append_start_tag( 'strong' ); $formatter->append_preformatted( wpcf7_link( __( 'https://contactform7.com/spam-filtering-with-akismet/', 'contact-form-7' ), __( 'Spam filtering with Akismet', 'contact-form-7' ) ) ); $formatter->end_tag( 'p' ); if ( $this->is_active() ) { $formatter->append_start_tag( 'p', array( 'class' => 'dashicons-before dashicons-yes', ) ); $formatter->append_preformatted( esc_html( __( 'Akismet is active on this site.', 'contact-form-7' ) ) ); $formatter->end_tag( 'p' ); } $formatter->print(); } } akismet.php 0000777 00000005305 15251460151 0006724 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.6 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.6' ); 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'; } class.akismet-rest-api.php 0000777 00000047334 15251466723 0011575 0 ustar 00 <?php class Akismet_REST_API { /** * Register the REST API routes. */ public static function init() { if ( ! function_exists( 'register_rest_route' ) ) { // The REST API wasn't integrated into core until 4.4, and we support 4.0+ (for now). return false; } register_rest_route( 'akismet/v1', '/key', array( array( 'methods' => WP_REST_Server::READABLE, 'permission_callback' => array( 'Akismet_REST_API', 'privileged_permission_callback' ), 'callback' => array( 'Akismet_REST_API', 'get_key' ), ), array( 'methods' => WP_REST_Server::EDITABLE, 'permission_callback' => array( 'Akismet_REST_API', 'privileged_permission_callback' ), 'callback' => array( 'Akismet_REST_API', 'set_key' ), 'args' => array( 'key' => array( 'required' => true, 'type' => 'string', 'sanitize_callback' => array( 'Akismet_REST_API', 'sanitize_key' ), 'description' => __( 'A 12-character Akismet API key. Available at akismet.com/account', 'akismet' ), ), ), ), array( 'methods' => WP_REST_Server::DELETABLE, 'permission_callback' => array( 'Akismet_REST_API', 'privileged_permission_callback' ), 'callback' => array( 'Akismet_REST_API', 'delete_key' ), ), ) ); register_rest_route( 'akismet/v1', '/settings/', array( array( 'methods' => WP_REST_Server::READABLE, 'permission_callback' => array( 'Akismet_REST_API', 'privileged_permission_callback' ), 'callback' => array( 'Akismet_REST_API', 'get_settings' ), ), array( 'methods' => WP_REST_Server::EDITABLE, 'permission_callback' => array( 'Akismet_REST_API', 'privileged_permission_callback' ), 'callback' => array( 'Akismet_REST_API', 'set_boolean_settings' ), 'args' => array( 'akismet_strictness' => array( 'required' => false, 'type' => 'boolean', 'description' => __( 'If true, Akismet will automatically discard the worst spam automatically rather than putting it in the spam folder.', 'akismet' ), ), 'akismet_show_user_comments_approved' => array( 'required' => false, 'type' => 'boolean', 'description' => __( 'If true, show the number of approved comments beside each comment author in the comments list page.', 'akismet' ), ), ), ), ) ); register_rest_route( 'akismet/v1', '/stats', array( 'methods' => WP_REST_Server::READABLE, 'permission_callback' => array( 'Akismet_REST_API', 'privileged_permission_callback' ), 'callback' => array( 'Akismet_REST_API', 'get_stats' ), 'args' => array( 'interval' => array( 'required' => false, 'type' => 'string', 'sanitize_callback' => array( 'Akismet_REST_API', 'sanitize_interval' ), 'description' => __( 'The time period for which to retrieve stats. Options: 60-days, 6-months, all', 'akismet' ), 'default' => 'all', ), ), ) ); register_rest_route( 'akismet/v1', '/stats/(?P<interval>[\w+])', array( 'args' => array( 'interval' => array( 'description' => __( 'The time period for which to retrieve stats. Options: 60-days, 6-months, all', 'akismet' ), 'type' => 'string', ), ), array( 'methods' => WP_REST_Server::READABLE, 'permission_callback' => array( 'Akismet_REST_API', 'privileged_permission_callback' ), 'callback' => array( 'Akismet_REST_API', 'get_stats' ), ), ) ); register_rest_route( 'akismet/v1', '/alert', array( array( 'methods' => WP_REST_Server::READABLE, 'permission_callback' => array( 'Akismet_REST_API', 'remote_call_permission_callback' ), 'callback' => array( 'Akismet_REST_API', 'get_alert' ), 'args' => array( 'key' => array( 'required' => false, 'type' => 'string', 'sanitize_callback' => array( 'Akismet_REST_API', 'sanitize_key' ), 'description' => __( 'A 12-character Akismet API key. Available at akismet.com/account', 'akismet' ), ), ), ), array( 'methods' => WP_REST_Server::EDITABLE, 'permission_callback' => array( 'Akismet_REST_API', 'remote_call_permission_callback' ), 'callback' => array( 'Akismet_REST_API', 'set_alert' ), 'args' => array( 'key' => array( 'required' => false, 'type' => 'string', 'sanitize_callback' => array( 'Akismet_REST_API', 'sanitize_key' ), 'description' => __( 'A 12-character Akismet API key. Available at akismet.com/account', 'akismet' ), ), ), ), array( 'methods' => WP_REST_Server::DELETABLE, 'permission_callback' => array( 'Akismet_REST_API', 'remote_call_permission_callback' ), 'callback' => array( 'Akismet_REST_API', 'delete_alert' ), 'args' => array( 'key' => array( 'required' => false, 'type' => 'string', 'sanitize_callback' => array( 'Akismet_REST_API', 'sanitize_key' ), 'description' => __( 'A 12-character Akismet API key. Available at akismet.com/account', 'akismet' ), ), ), ), ) ); register_rest_route( 'akismet/v1', '/webhook', array( 'methods' => WP_REST_Server::CREATABLE, 'callback' => array( 'Akismet_REST_API', 'receive_webhook' ), 'permission_callback' => array( 'Akismet_REST_API', 'remote_call_permission_callback' ), ) ); } /** * Get the current Akismet API key. * * @param WP_REST_Request $request * @return WP_Error|WP_REST_Response */ public static function get_key( $request = null ) { return rest_ensure_response( Akismet::get_api_key() ); } /** * Set the API key, if possible. * * @param WP_REST_Request $request * @return WP_Error|WP_REST_Response */ public static function set_key( $request ) { if ( defined( 'WPCOM_API_KEY' ) ) { return rest_ensure_response( new WP_Error( 'hardcoded_key', __( 'This site\'s API key is hardcoded and cannot be changed via the API.', 'akismet' ), array( 'status' => 409 ) ) ); } $new_api_key = $request->get_param( 'key' ); if ( ! self::key_is_valid( $new_api_key ) ) { return rest_ensure_response( new WP_Error( 'invalid_key', __( 'The value provided is not a valid and registered API key.', 'akismet' ), array( 'status' => 400 ) ) ); } update_option( 'wordpress_api_key', $new_api_key ); return self::get_key(); } /** * Unset the API key, if possible. * * @param WP_REST_Request $request * @return WP_Error|WP_REST_Response */ public static function delete_key( $request ) { if ( defined( 'WPCOM_API_KEY' ) ) { return rest_ensure_response( new WP_Error( 'hardcoded_key', __( 'This site\'s API key is hardcoded and cannot be deleted.', 'akismet' ), array( 'status' => 409 ) ) ); } delete_option( 'wordpress_api_key' ); return rest_ensure_response( true ); } /** * Get the Akismet settings. * * @param WP_REST_Request $request * @return WP_Error|WP_REST_Response */ public static function get_settings( $request = null ) { return rest_ensure_response( array( 'akismet_strictness' => ( get_option( 'akismet_strictness', '1' ) === '1' ), 'akismet_show_user_comments_approved' => ( get_option( 'akismet_show_user_comments_approved', '1' ) === '1' ), ) ); } /** * Update the Akismet settings. * * @param WP_REST_Request $request * @return WP_Error|WP_REST_Response */ public static function set_boolean_settings( $request ) { foreach ( array( 'akismet_strictness', 'akismet_show_user_comments_approved', ) as $setting_key ) { $setting_value = $request->get_param( $setting_key ); if ( is_null( $setting_value ) ) { // This setting was not specified. continue; } // From 4.7+, WP core will ensure that these are always boolean // values because they are registered with 'type' => 'boolean', // but we need to do this ourselves for prior versions. $setting_value = self::parse_boolean( $setting_value ); update_option( $setting_key, $setting_value ? '1' : '0' ); } return self::get_settings(); } /** * Parse a numeric or string boolean value into a boolean. * * @param mixed $value The value to convert into a boolean. * @return bool The converted value. */ public static function parse_boolean( $value ) { switch ( $value ) { case true: case 'true': case '1': case 1: return true; case false: case 'false': case '0': case 0: return false; default: return (bool) $value; } } /** * Get the Akismet stats for a given time period. * * Possible `interval` values: * - all * - 60-days * - 6-months * * @param WP_REST_Request $request * @return WP_Error|WP_REST_Response */ public static function get_stats( $request ) { $api_key = Akismet::get_api_key(); $interval = $request->get_param( 'interval' ); $stat_totals = array(); $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] ) ) { $stat_totals[ $interval ] = json_decode( $response[1] ); } return rest_ensure_response( $stat_totals ); } /** * Get the current alert code and message. Alert codes are used to notify the site owner * if there's a problem, like a connection issue between their site and the Akismet API, * invalid requests being sent, etc. * * @param WP_REST_Request $request * @return WP_Error|WP_REST_Response */ public static function get_alert( $request ) { return rest_ensure_response( array( 'code' => get_option( 'akismet_alert_code' ), 'message' => get_option( 'akismet_alert_msg' ), ) ); } /** * Update the current alert code and message by triggering a call to the Akismet server. * * @param WP_REST_Request $request * @return WP_Error|WP_REST_Response */ public static function set_alert( $request ) { delete_option( 'akismet_alert_code' ); delete_option( 'akismet_alert_msg' ); // Make a request so the most recent alert code and message are retrieved. Akismet::verify_key( Akismet::get_api_key() ); return self::get_alert( $request ); } /** * Clear the current alert code and message. * * @param WP_REST_Request $request * @return WP_Error|WP_REST_Response */ public static function delete_alert( $request ) { delete_option( 'akismet_alert_code' ); delete_option( 'akismet_alert_msg' ); return self::get_alert( $request ); } private static function key_is_valid( $key ) { $request_args = array( 'key' => $key, 'blog' => get_option( 'home' ), ); $request_args = apply_filters( 'akismet_request_args', $request_args, 'verify-key' ); $response = Akismet::http_post( Akismet::build_query( $request_args ), 'verify-key' ); if ( $response[1] == 'valid' ) { return true; } return false; } public static function privileged_permission_callback() { return current_user_can( 'manage_options' ); } /** * For calls that Akismet.com makes to the site to clear outdated alert codes, use the API key for authorization. */ public static function remote_call_permission_callback( $request ) { $local_key = Akismet::get_api_key(); return $local_key && ( strtolower( $request->get_param( 'key' ) ?? '' ) === strtolower( $local_key ) ); } public static function sanitize_interval( $interval, $request, $param ) { $interval = trim( $interval ); $valid_intervals = array( '60-days', '6-months', 'all' ); if ( ! in_array( $interval, $valid_intervals ) ) { $interval = 'all'; } return $interval; } public static function sanitize_key( $key, $request, $param ) { return trim( $key ); } /** * Process a webhook request from the Akismet servers. * * @param WP_REST_Request $request * @return WP_Error|WP_REST_Response */ public static function receive_webhook( $request ) { Akismet::log( array( 'Webhook request received', $request->get_body() ) ); /** * The request body should look like this: * array( * 'key' => '1234567890abcd', * 'endpoint' => '[comment-check|submit-ham|submit-spam]', * 'comments' => array( * array( * 'guid' => '[...]', * 'result' => '[true|false]', * 'comment_author' => '[...]', * [...] * ), * array( * 'guid' => '[...]', * [...], * ), * [...] * ) * ) * * Multiple comments can be included in each request, and the only truly required * field for each is the guid, although it would be friendly to include also * comment_post_ID, comment_parent, and comment_author_email, if possible to make * searching easier. */ // The response will include statuses for the result of each comment that was supplied. $response = array( 'comments' => array(), ); $endpoint = $request->get_param( 'endpoint' ); switch ( $endpoint ) { case 'comment-check': $webhook_comments = $request->get_param( 'comments' ); if ( ! is_array( $webhook_comments ) ) { return rest_ensure_response( new WP_Error( 'malformed_request', __( 'The \'comments\' parameter must be an array.', 'akismet' ), array( 'status' => 400 ) ) ); } foreach ( $webhook_comments as $webhook_comment ) { $guid = $webhook_comment['guid']; if ( ! $guid ) { // Without the GUID, we can't be sure that we're matching the right comment. // We'll make it a rule that any comment without a GUID is ignored intentionally. continue; } // Search on the fields that are indexed in the comments table, plus the GUID. // The GUID is the only thing we really need to search on, but comment_meta // is not indexed in a useful way if there are many many comments. This // should help narrow it down first. $queryable_fields = array( 'comment_post_ID' => 'post_id', 'comment_parent' => 'parent', 'comment_author_email' => 'author_email', ); $query_args = array(); $query_args['status'] = 'any'; $query_args['meta_key'] = 'akismet_guid'; $query_args['meta_value'] = $guid; foreach ( $queryable_fields as $queryable_field => $wp_comment_query_field ) { if ( isset( $webhook_comment[ $queryable_field ] ) ) { $query_args[ $wp_comment_query_field ] = $webhook_comment[ $queryable_field ]; } } $comments_query = new WP_Comment_Query( $query_args ); $comments = $comments_query->comments; if ( ! $comments ) { // Unexpected, although the comment could have been deleted since being submitted. Akismet::log( 'Webhook failed: no matching comment found.' ); $response['comments'][ $guid ] = array( 'status' => 'error', 'message' => __( 'Could not find matching comment.', 'akismet' ), ); continue; } if ( count( $comments ) > 1 ) { // Two comments shouldn't be able to match the same GUID. Akismet::log( 'Webhook failed: multiple matching comments found.', $comments ); $response['comments'][ $guid ] = array( 'status' => 'error', 'message' => __( 'Multiple comments matched request.', 'akismet' ), ); continue; } else { // We have one single match, as hoped for. Akismet::log( 'Found matching comment.', $comments ); $comment = $comments[0]; $current_status = wp_get_comment_status( $comment ); $result = $webhook_comment['result']; if ( 'true' == $result ) { Akismet::log( 'Comment should be spam' ); // The comment should be classified as spam. if ( 'spam' != $current_status ) { // The comment is not classified as spam. If Akismet was the one to act on it, move it to spam. if ( Akismet::last_comment_status_change_came_from_akismet( $comment->comment_ID ) ) { Akismet::log( 'Comment is not spam; marking as spam.' ); wp_spam_comment( $comment ); Akismet::update_comment_history( $comment->comment_ID, '', 'webhook-spam' ); } else { Akismet::log( 'Comment is not spam, but it has already been manually handled by some other process.' ); Akismet::update_comment_history( $comment->comment_ID, '', 'webhook-spam-noaction' ); } } } elseif ( 'false' == $result ) { Akismet::log( 'Comment should be ham' ); // The comment should be classified as ham. if ( 'spam' == $current_status ) { Akismet::log( 'Comment is spam.' ); // The comment is classified as spam. If Akismet was the one to label it as spam, unspam it. if ( Akismet::last_comment_status_change_came_from_akismet( $comment->comment_ID ) ) { Akismet::log( 'Akismet marked it as spam; unspamming.' ); wp_unspam_comment( $comment ); akismet::update_comment_history( $comment->comment_ID, '', 'webhook-ham' ); } else { Akismet::log( 'Comment is not spam, but it has already been manually handled by some other process.' ); Akismet::update_comment_history( $comment->comment_ID, '', 'webhook-ham-noaction' ); } } else if ( 'unapproved' == $current_status ) { Akismet::log( 'Comment is pending.' ); // The comment is in Pending. If Akismet was the one to put it there, approve it (but only if the site // settings dictate that). if ( Akismet::last_comment_status_change_came_from_akismet( $comment->comment_ID ) ) { Akismet::log( 'Akismet marked it as Pending; approving.' ); 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->comment_ID, 1 ); } akismet::update_comment_history( $comment->comment_ID, '', 'webhook-ham' ); } else { Akismet::log( 'Comment is not spam, but it has already been manually handled by some other process.' ); Akismet::update_comment_history( $comment->comment_ID, '', 'webhook-ham-noaction' ); } } $moderation_email_was_delayed = get_comment_meta( $comment->comment_ID, 'akismet_delayed_moderation_email', true ); if ( $moderation_email_was_delayed ) { Akismet::log( 'Moderation email was delayed for comment #' . $comment->comment_ID . '; sending now.' ); delete_comment_meta( $comment->comment_ID, 'akismet_delayed_moderation_email' ); wp_new_comment_notify_moderator( $comment->comment_ID ); wp_new_comment_notify_postauthor( $comment->comment_ID ); } delete_comment_meta( $comment->comment_ID, 'akismet_delay_moderation_email' ); } $response['comments'][ $guid ] = array( 'status' => 'success' ); } } break; case 'submit-ham': case 'submit-spam': // Nothing to do for submit-ham or submit-spam. break; default: // Unsupported endpoint. break; } /** * Allow plugins to do things with a successfully processed webhook request, like logging. * * @since 5.3.2 * * @param WP_REST_Request $request The REST request object. */ do_action( 'akismet_webhook_received', $request ); Akismet::log( 'Done processing webhook.' ); return rest_ensure_response( $response ); } } class.akismet-admin.php 0000777 00000177331 15251466723 0011142 0 ustar 00 <?php // We plan to gradually remove all of the disabled lint rules below. // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotValidated // phpcs:disable WordPress.Security.ValidatedSanitizedInput.MissingUnslash // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized // phpcs:disable Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped class Akismet_Admin { const NONCE = 'akismet-update-key'; const NOTICE_EXISTING_KEY_INVALID = 'existing-key-invalid'; private static $initiated = false; private static $notices = array(); private static $allowed = array( 'a' => array( 'href' => true, 'title' => true, ), 'b' => array(), 'code' => array(), 'del' => array( 'datetime' => true, ), 'em' => array(), 'i' => array(), 'q' => array( 'cite' => true, ), 'strike' => array(), 'strong' => array(), ); /** * List of pages where activation banner should be displayed. * * @var array */ private static $activation_banner_pages = array( 'edit-comments.php', 'options-discussion.php', 'plugins.php', ); public static function init() { if ( ! self::$initiated ) { self::init_hooks(); } if ( isset( $_POST['action'] ) && $_POST['action'] == 'enter-key' ) { self::enter_api_key(); } } public static function init_hooks() { // The standalone stats page was removed in 3.0 for an all-in-one config and stats page. // Redirect any links that might have been bookmarked or in browser history. if ( isset( $_GET['page'] ) && 'akismet-stats-display' == $_GET['page'] ) { wp_safe_redirect( esc_url_raw( self::get_page_url( 'stats' ) ), 301 ); die; } self::$initiated = true; add_action( 'admin_init', array( 'Akismet_Admin', 'admin_init' ) ); add_action( 'admin_menu', array( 'Akismet_Admin', 'admin_menu' ), 5 ); // Priority 5, so it's called before Jetpack's admin_menu. add_action( 'admin_notices', array( 'Akismet_Admin', 'display_notice' ) ); add_action( 'admin_enqueue_scripts', array( 'Akismet_Admin', 'load_resources' ) ); add_action( 'activity_box_end', array( 'Akismet_Admin', 'dashboard_stats' ) ); add_action( 'rightnow_end', array( 'Akismet_Admin', 'rightnow_stats' ) ); add_action( 'manage_comments_nav', array( 'Akismet_Admin', 'check_for_spam_button' ) ); add_action( 'admin_action_akismet_recheck_queue', array( 'Akismet_Admin', 'recheck_queue' ) ); add_action( 'wp_ajax_akismet_recheck_queue', array( 'Akismet_Admin', 'recheck_queue' ) ); add_action( 'wp_ajax_comment_author_deurl', array( 'Akismet_Admin', 'remove_comment_author_url' ) ); add_action( 'wp_ajax_comment_author_reurl', array( 'Akismet_Admin', 'add_comment_author_url' ) ); add_action( 'jetpack_auto_activate_akismet', array( 'Akismet_Admin', 'connect_jetpack_user' ) ); add_filter( 'plugin_action_links', array( 'Akismet_Admin', 'plugin_action_links' ), 10, 2 ); add_filter( 'comment_row_actions', array( 'Akismet_Admin', 'comment_row_action' ), 10, 2 ); add_filter( 'plugin_action_links_' . plugin_basename( plugin_dir_path( __FILE__ ) . 'akismet.php' ), array( 'Akismet_Admin', 'admin_plugin_settings_link' ) ); add_filter( 'wxr_export_skip_commentmeta', array( 'Akismet_Admin', 'exclude_commentmeta_from_export' ), 10, 3 ); add_filter( 'all_plugins', array( 'Akismet_Admin', 'modify_plugin_description' ) ); // priority=1 because we need ours to run before core's comment anonymizer runs, and that's registered at priority=10 add_filter( 'wp_privacy_personal_data_erasers', array( 'Akismet_Admin', 'register_personal_data_eraser' ), 1 ); } public static function admin_init() { if ( get_option( 'Activated_Akismet' ) ) { delete_option( 'Activated_Akismet' ); if ( ! headers_sent() ) { $admin_url = self::get_page_url( 'init' ); wp_redirect( $admin_url ); } } add_meta_box( 'akismet-status', __( 'Comment History', 'akismet' ), array( 'Akismet_Admin', 'comment_status_meta_box' ), 'comment', 'normal' ); if ( function_exists( 'wp_add_privacy_policy_content' ) ) { wp_add_privacy_policy_content( __( 'Akismet', 'akismet' ), __( 'We collect information about visitors who comment on Sites that use our Akismet Anti-spam service. The information we collect depends on how the User sets up Akismet for the Site, but typically includes the commenter\'s IP address, user agent, referrer, and Site URL (along with other information directly provided by the commenter such as their name, username, email address, and the comment itself).', 'akismet' ) ); } } public static function admin_menu() { if ( self::is_jetpack_active() ) { add_action( 'jetpack_admin_menu', array( 'Akismet_Admin', 'load_menu' ) ); } else { self::load_menu(); } } /** * Check if Jetpack is active. * * @return bool True if Jetpack class exists, false otherwise. */ public static function is_jetpack_active(): bool { return class_exists( 'Jetpack' ); } public static function admin_head() { if ( ! current_user_can( 'manage_options' ) ) { return; } } public static function admin_plugin_settings_link( $links ) { $settings_link = '<a href="' . esc_url( self::get_page_url() ) . '">' . __( 'Settings', 'akismet' ) . '</a>'; array_unshift( $links, $settings_link ); return $links; } public static function load_menu() { if ( self::is_jetpack_active() ) { $hook = add_submenu_page( 'jetpack', __( 'Akismet Anti-spam', 'akismet' ), __( 'Akismet Anti-spam', 'akismet' ), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) ); } else { $hook = add_options_page( __( 'Akismet Anti-spam', 'akismet' ), __( 'Akismet Anti-spam', 'akismet' ), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) ); } if ( $hook ) { add_action( "load-$hook", array( 'Akismet_Admin', 'admin_help' ) ); } } public static function load_resources() { global $hook_suffix; if ( in_array( $hook_suffix, apply_filters( 'akismet_admin_page_hook_suffixes', array_merge( array( 'index.php', // dashboard 'comment.php', 'post.php', 'settings_page_akismet-key-config', 'jetpack_page_akismet-key-config', ), self::$activation_banner_pages ) ) ) ) { $akismet_css_path = is_rtl() ? '_inc/rtl/akismet-rtl.css' : '_inc/akismet.css'; wp_register_style( 'akismet', plugin_dir_url( __FILE__ ) . $akismet_css_path, array(), self::get_asset_file_version( $akismet_css_path ) ); wp_enqueue_style( 'akismet' ); wp_register_style( 'akismet-font-inter', plugin_dir_url( __FILE__ ) . '_inc/fonts/inter.css', array(), self::get_asset_file_version( '_inc/fonts/inter.css' ) ); wp_enqueue_style( 'akismet-font-inter' ); $akismet_admin_css_path = is_rtl() ? '_inc/rtl/akismet-admin-rtl.css' : '_inc/akismet-admin.css'; wp_register_style( 'akismet-admin', plugin_dir_url( __FILE__ ) . $akismet_admin_css_path, array(), self::get_asset_file_version( $akismet_admin_css_path ) ); wp_enqueue_style( 'akismet-admin' ); wp_add_inline_style( 'akismet-admin', self::get_inline_css() ); wp_register_script( 'akismet.js', plugin_dir_url( __FILE__ ) . '_inc/akismet.js', array( 'jquery' ), self::get_asset_file_version( '_inc/akismet.js' ) ); wp_enqueue_script( 'akismet.js' ); wp_register_script( 'akismet-admin.js', plugin_dir_url( __FILE__ ) . '_inc/akismet-admin.js', array(), self::get_asset_file_version( '/_inc/akismet-admin.js' ) ); wp_enqueue_script( 'akismet-admin.js' ); $inline_js = array( 'comment_author_url_nonce' => wp_create_nonce( 'comment_author_url_nonce' ), 'strings' => array( 'Remove this URL' => __( 'Remove this URL', 'akismet' ), 'Removing...' => __( 'Removing...', 'akismet' ), 'URL removed' => __( 'URL removed', 'akismet' ), '(undo)' => __( '(undo)', 'akismet' ), 'Re-adding...' => __( 'Re-adding...', 'akismet' ), ), ); if ( isset( $_GET['akismet_recheck'] ) && wp_verify_nonce( $_GET['akismet_recheck'], 'akismet_recheck' ) ) { $inline_js['start_recheck'] = true; } if ( apply_filters( 'akismet_enable_mshots', true ) ) { $inline_js['enable_mshots'] = true; } wp_localize_script( 'akismet.js', 'WPAkismet', $inline_js ); } } /** * Add help to the Akismet page * * @return false if not the Akismet page */ public static function admin_help() { $current_screen = get_current_screen(); // Screen Content if ( current_user_can( 'manage_options' ) ) { if ( ! Akismet::get_api_key() || ( isset( $_GET['view'] ) && $_GET['view'] == 'start' ) ) { // setup page $current_screen->add_help_tab( array( 'id' => 'overview', 'title' => __( 'Overview', 'akismet' ), 'content' => '<p><strong>' . esc_html__( 'Akismet Setup', 'akismet' ) . '</strong></p>' . '<p>' . esc_html__( 'Akismet filters out spam, so you can focus on more important things.', 'akismet' ) . '</p>' . '<p>' . esc_html__( 'On this page, you are able to set up the Akismet plugin.', 'akismet' ) . '</p>', ) ); $current_screen->add_help_tab( array( 'id' => 'setup-signup', 'title' => __( 'New to Akismet', 'akismet' ), 'content' => '<p><strong>' . esc_html__( 'Akismet Setup', 'akismet' ) . '</strong></p>' . '<p>' . esc_html__( 'You need to enter an API key to activate the Akismet service on your site.', 'akismet' ) . '</p>' . /* translators: %s: a link to the signup page with the text 'Akismet.com'. */ '<p>' . sprintf( __( 'Sign up for an account on %s to get an API Key.', 'akismet' ), '<a href="https://akismet.com/pricing/?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=help_signup" target="_blank">Akismet.com</a>' ) . '</p>', ) ); $current_screen->add_help_tab( array( 'id' => 'setup-manual', 'title' => __( 'Enter an API Key', 'akismet' ), 'content' => '<p><strong>' . esc_html__( 'Akismet Setup', 'akismet' ) . '</strong></p>' . '<p>' . esc_html__( 'If you already have an API key', 'akismet' ) . '</p>' . '<ol>' . '<li>' . esc_html__( 'Copy and paste the API key into the text field.', 'akismet' ) . '</li>' . '<li>' . esc_html__( 'Click the Use this Key button.', 'akismet' ) . '</li>' . '</ol>', ) ); } elseif ( isset( $_GET['view'] ) && $_GET['view'] == 'stats' ) { // stats page $current_screen->add_help_tab( array( 'id' => 'overview', 'title' => __( 'Overview', 'akismet' ), 'content' => '<p><strong>' . esc_html__( 'Akismet Stats', 'akismet' ) . '</strong></p>' . '<p>' . esc_html__( 'Akismet filters out spam, so you can focus on more important things.', 'akismet' ) . '</p>' . '<p>' . esc_html__( 'On this page, you are able to view stats on spam filtered on your site.', 'akismet' ) . '</p>', ) ); } else { // configuration page $current_screen->add_help_tab( array( 'id' => 'overview', 'title' => __( 'Overview', 'akismet' ), 'content' => '<p><strong>' . esc_html__( 'Akismet Configuration', 'akismet' ) . '</strong></p>' . '<p>' . esc_html__( 'Akismet filters out spam, so you can focus on more important things.', 'akismet' ) . '</p>' . '<p>' . esc_html__( 'On this page, you are able to update your Akismet settings and view spam stats.', 'akismet' ) . '</p>', ) ); $current_screen->add_help_tab( array( 'id' => 'settings', 'title' => __( 'Settings', 'akismet' ), 'content' => '<p><strong>' . esc_html__( 'Akismet Configuration', 'akismet' ) . '</strong></p>' . ( Akismet::predefined_api_key() ? '' : '<p><strong>' . esc_html__( 'API Key', 'akismet' ) . '</strong> - ' . esc_html__( 'Enter/remove an API key.', 'akismet' ) . '</p>' ) . '<p><strong>' . esc_html__( 'Comments', 'akismet' ) . '</strong> - ' . esc_html__( 'Show the number of approved comments beside each comment author in the comments list page.', 'akismet' ) . '</p>' . '<p><strong>' . esc_html__( 'Strictness', 'akismet' ) . '</strong> - ' . esc_html__( 'Choose to either discard the worst spam automatically or to always put all spam in spam folder.', 'akismet' ) . '</p>', ) ); if ( ! Akismet::predefined_api_key() ) { $current_screen->add_help_tab( array( 'id' => 'account', 'title' => __( 'Account', 'akismet' ), 'content' => '<p><strong>' . esc_html__( 'Akismet Configuration', 'akismet' ) . '</strong></p>' . '<p><strong>' . esc_html__( 'Subscription Type', 'akismet' ) . '</strong> - ' . esc_html__( 'The Akismet subscription plan', 'akismet' ) . '</p>' . '<p><strong>' . esc_html__( 'Status', 'akismet' ) . '</strong> - ' . esc_html__( 'The subscription status - active, cancelled or suspended', 'akismet' ) . '</p>', ) ); } } } // Help Sidebar $current_screen->set_help_sidebar( '<p><strong>' . esc_html__( 'For more information:', 'akismet' ) . '</strong></p>' . '<p><a href="https://akismet.com/resources/?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=help_faq" target="_blank">' . esc_html__( 'Akismet FAQ', 'akismet' ) . '</a></p>' . '<p><a href="https://akismet.com/support/?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=help_support" target="_blank">' . esc_html__( 'Akismet Support', 'akismet' ) . '</a></p>' ); } public static function enter_api_key() { if ( ! current_user_can( 'manage_options' ) ) { die( __( 'Cheatin’ uh?', 'akismet' ) ); } if ( ! wp_verify_nonce( $_POST['_wpnonce'], self::NONCE ) ) { return false; } foreach ( array( 'akismet_strictness', 'akismet_show_user_comments_approved' ) as $option ) { update_option( $option, isset( $_POST[ $option ] ) && (int) $_POST[ $option ] == 1 ? '1' : '0' ); } if ( ! empty( $_POST['akismet_comment_form_privacy_notice'] ) ) { self::set_form_privacy_notice_option( $_POST['akismet_comment_form_privacy_notice'] ); } else { self::set_form_privacy_notice_option( 'hide' ); } if ( Akismet::predefined_api_key() ) { return false; // shouldn't have option to save key if already defined } $new_key = preg_replace( '/[^a-f0-9]/i', '', $_POST['key'] ); $old_key = Akismet::get_api_key(); if ( empty( $new_key ) ) { if ( ! empty( $old_key ) ) { delete_option( 'wordpress_api_key' ); self::$notices[] = 'new-key-empty'; } } elseif ( $new_key != $old_key ) { self::save_key( $new_key ); } return true; } public static function save_key( $api_key ) { $key_status = Akismet::verify_key( $api_key ); if ( $key_status == 'valid' ) { $akismet_user = self::get_akismet_user( $api_key ); if ( $akismet_user ) { if ( in_array( $akismet_user->status, array( Akismet::USER_STATUS_ACTIVE, 'active-dunning' ) ) ) { update_option( 'wordpress_api_key', $api_key ); } if ( $akismet_user->status == Akismet::USER_STATUS_ACTIVE ) { self::$notices['status'] = 'new-key-valid'; } elseif ( $akismet_user->status == Akismet::USER_STATUS_NO_SUB ) { self::$notices['status'] = 'no-sub'; } else { self::$notices['status'] = $akismet_user->status; } } else { self::$notices['status'] = 'new-key-invalid'; } } elseif ( in_array( $key_status, array( 'invalid', 'failed' ) ) ) { // When verify-key returns 'invalid', it could be truly invalid OR suspended. // Check get-subscription to distinguish between these cases. $akismet_user = self::get_akismet_user( $api_key ); if ( $akismet_user && isset( $akismet_user->status ) && $akismet_user->status === Akismet::USER_STATUS_SUSPENDED ) { self::$notices['status'] = Akismet::USER_STATUS_SUSPENDED; } else { self::$notices['status'] = 'new-key-' . $key_status; } } } public static function dashboard_stats() { if ( did_action( 'rightnow_end' ) ) { return; // We already displayed this info in the "Right Now" section } if ( ! $count = get_option( 'akismet_spam_count' ) ) { return; } global $submenu; echo '<h3>' . esc_html( _x( 'Spam', 'comments', 'akismet' ) ) . '</h3>'; echo '<p>' . sprintf( /* translators: 1: Akismet website URL, 2: Comments page URL, 3: Number of spam comments. */ _n( '<a href="%1$s">Akismet</a> has protected your site from <a href="%2$s">%3$s spam comment</a>.', '<a href="%1$s">Akismet</a> has protected your site from <a href="%2$s">%3$s spam comments</a>.', $count, 'akismet' ), 'https://akismet.com/wordpress/?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=dashboard_stats', esc_url( add_query_arg( array( 'page' => 'akismet-admin' ), admin_url( isset( $submenu['edit-comments.php'] ) ? 'edit-comments.php' : 'edit.php' ) ) ), number_format_i18n( $count ) ) . '</p>'; } // WP 2.5+ public static function rightnow_stats() { if ( $count = get_option( 'akismet_spam_count' ) ) { $intro = sprintf( /* translators: 1: Akismet website URL, 2: Number of spam comments. */ _n( '<a href="%1$s">Akismet</a> has protected your site from %2$s spam comment already. ', '<a href="%1$s">Akismet</a> has protected your site from %2$s spam comments already. ', $count, 'akismet' ), 'https://akismet.com/wordpress/?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=dashboard_stats', number_format_i18n( $count ) ); } else { /* translators: %s: Akismet website URL. */ $intro = sprintf( __( '<a href="%s">Akismet</a> blocks spam from getting to your blog. ', 'akismet' ), 'https://akismet.com/wordpress/?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=dashboard_stats' ); } $link = add_query_arg( array( 'comment_status' => 'spam' ), admin_url( 'edit-comments.php' ) ); if ( $queue_count = self::get_spam_count() ) { $queue_text = sprintf( /* translators: 1: Number of comments, 2: Comments page URL. */ _n( 'There’s <a href="%2$s">%1$s comment</a> in your spam queue right now.', 'There are <a href="%2$s">%1$s comments</a> in your spam queue right now.', $queue_count, 'akismet' ), number_format_i18n( $queue_count ), esc_url( $link ) ); } else { /* translators: %s: Comments page URL. */ $queue_text = sprintf( __( "There’s nothing in your <a href='%s'>spam queue</a> at the moment.", 'akismet' ), esc_url( $link ) ); } $text = $intro . '<br />' . $queue_text; echo "<p class='akismet-right-now'>$text</p>\n"; } public static function check_for_spam_button( $comment_status ) { // The "Check for Spam" button should only appear when the page might be showing // a comment with comment_approved=0, which means an un-trashed, un-spammed, // not-yet-moderated comment. if ( 'all' != $comment_status && 'moderated' != $comment_status ) { return; } $link = ''; $comments_count = wp_count_comments(); echo '</div>'; echo '<div class="alignleft actions">'; $classes = array( 'button-secondary', 'checkforspam', 'button-disabled', // Disable button until the page is loaded ); if ( $comments_count->moderated > 0 ) { $classes[] = 'enable-on-load'; if ( ! Akismet::get_api_key() ) { $link = self::get_page_url(); $classes[] = 'ajax-disabled'; } } echo '<a class="' . esc_attr( implode( ' ', $classes ) ) . '"' . ( ! empty( $link ) ? ' href="' . esc_url( $link ) . '"' : '' ) . /* translators: The placeholder is for showing how much of the process has completed, as a percent. e.g., "Checking for Spam (40%)" */ ' data-progress-label="' . esc_attr( __( 'Checking for Spam (%1$s%)', 'akismet' ) ) . '" data-success-url="' . esc_attr( remove_query_arg( array( 'akismet_recheck', 'akismet_recheck_error' ), add_query_arg( array( 'akismet_recheck_complete' => 1, 'recheck_count' => urlencode( '__recheck_count__' ), 'spam_count' => urlencode( '__spam_count__' ), ) ) ) ) . '" data-failure-url="' . esc_attr( remove_query_arg( array( 'akismet_recheck', 'akismet_recheck_complete' ), add_query_arg( array( 'akismet_recheck_error' => 1 ) ) ) ) . '" data-pending-comment-count="' . esc_attr( $comments_count->moderated ) . '" data-nonce="' . esc_attr( wp_create_nonce( 'akismet_check_for_spam' ) ) . '" ' . ( ! in_array( 'ajax-disabled', $classes ) ? 'onclick="return false;"' : '' ) . ' >' . esc_html__( 'Check for Spam', 'akismet' ) . '</a>'; echo '<span class="checkforspam-spinner"></span>'; } public static function recheck_queue() { global $wpdb; Akismet::fix_scheduled_recheck(); if ( ! ( isset( $_GET['recheckqueue'] ) || ( isset( $_REQUEST['action'] ) && 'akismet_recheck_queue' == $_REQUEST['action'] ) ) ) { return; } if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'akismet_check_for_spam' ) ) { wp_send_json( array( 'error' => __( 'You don’t have permission to do that.', 'akismet' ), ) ); return; } $result_counts = self::recheck_queue_portion( empty( $_POST['offset'] ) ? 0 : $_POST['offset'], empty( $_POST['limit'] ) ? 100 : $_POST['limit'] ); if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { wp_send_json( array( 'counts' => $result_counts, ) ); } else { $redirect_to = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : admin_url( 'edit-comments.php' ); wp_safe_redirect( $redirect_to ); exit; } } public static function recheck_queue_portion( $start = 0, $limit = 100 ) { global $wpdb; $paginate = ''; if ( $limit <= 0 ) { $limit = 100; } if ( $start < 0 ) { $start = 0; } $moderation = $wpdb->get_col( $wpdb->prepare( "SELECT * FROM {$wpdb->comments} WHERE comment_approved = '0' LIMIT %d OFFSET %d", $limit, $start ) ); $result_counts = array( 'processed' => is_countable( $moderation ) ? count( $moderation ) : 0, 'spam' => 0, 'ham' => 0, 'error' => 0, ); foreach ( $moderation as $comment_id ) { $api_response = Akismet::recheck_comment( $comment_id, 'recheck_queue' ); if ( 'true' === $api_response ) { ++$result_counts['spam']; } elseif ( 'false' === $api_response ) { ++$result_counts['ham']; } else { ++$result_counts['error']; } } return $result_counts; } // Adds an 'x' link next to author URLs, clicking will remove the author URL and show an undo link public static function remove_comment_author_url() { if ( ! empty( $_POST['id'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) { $comment_id = intval( $_POST['id'] ); $comment = get_comment( $comment_id, ARRAY_A ); if ( $comment && current_user_can( 'edit_comment', $comment['comment_ID'] ) ) { $comment['comment_author_url'] = ''; do_action( 'comment_remove_author_url' ); print( wp_update_comment( $comment ) ); die(); } } } public static function add_comment_author_url() { if ( ! empty( $_POST['id'] ) && ! empty( $_POST['url'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) { $comment_id = intval( $_POST['id'] ); $comment = get_comment( $comment_id, ARRAY_A ); if ( $comment && current_user_can( 'edit_comment', $comment['comment_ID'] ) ) { $comment['comment_author_url'] = esc_url( $_POST['url'] ); do_action( 'comment_add_author_url' ); print( wp_update_comment( $comment ) ); die(); } } } public static function comment_row_action( $a, $comment ) { $akismet_result = get_comment_meta( $comment->comment_ID, 'akismet_result', true ); if ( ! $akismet_result && get_comment_meta( $comment->comment_ID, 'akismet_skipped', true ) ) { $akismet_result = 'skipped'; // Akismet chose to skip the comment-check request. } $akismet_error = get_comment_meta( $comment->comment_ID, 'akismet_error', true ); $user_result = get_comment_meta( $comment->comment_ID, 'akismet_user_result', true ); $comment_status = wp_get_comment_status( $comment->comment_ID ); $desc = null; if ( $akismet_error ) { $desc = __( 'Awaiting spam check', 'akismet' ); } elseif ( ! $user_result || $user_result == $akismet_result ) { // Show the original Akismet result if the user hasn't overridden it, or if their decision was the same if ( $akismet_result == 'true' && $comment_status != 'spam' && $comment_status != 'trash' ) { $desc = __( 'Flagged as spam by Akismet', 'akismet' ); } elseif ( $akismet_result == 'false' && $comment_status == 'spam' ) { $desc = __( 'Cleared by Akismet', 'akismet' ); } } else { $who = get_comment_meta( $comment->comment_ID, 'akismet_user', true ); if ( $user_result == 'true' ) { /* translators: %s: Username. */ $desc = sprintf( __( 'Flagged as spam by %s', 'akismet' ), $who ); } else { /* translators: %s: Username. */ $desc = sprintf( __( 'Un-spammed by %s', 'akismet' ), $who ); } } // add a History item to the hover links, just after Edit if ( $akismet_result && is_array( $a ) ) { $b = array(); foreach ( $a as $k => $item ) { $b[ $k ] = $item; if ( $k == 'edit' || $k == 'unspam' ) { $b['history'] = '<a href="comment.php?action=editcomment&c=' . $comment->comment_ID . '#akismet-status" title="' . esc_attr__( 'View comment history', 'akismet' ) . '"> ' . esc_html__( 'History', 'akismet' ) . '</a>'; } } $a = $b; } if ( $desc ) { echo '<span class="akismet-status" commentid="' . $comment->comment_ID . '"><a href="comment.php?action=editcomment&c=' . $comment->comment_ID . '#akismet-status" title="' . esc_attr__( 'View comment history', 'akismet' ) . '">' . esc_html( $desc ) . '</a></span>'; } $show_user_comments_option = get_option( 'akismet_show_user_comments_approved' ); if ( $show_user_comments_option === false ) { // Default to active if the user hasn't made a decision. $show_user_comments_option = '1'; } $show_user_comments = apply_filters( 'akismet_show_user_comments_approved', $show_user_comments_option ); $show_user_comments = $show_user_comments === 'false' ? false : $show_user_comments; // option used to be saved as 'false' / 'true' if ( $show_user_comments ) { $comment_count = Akismet::get_user_comments_approved( $comment->user_id, $comment->comment_author_email, $comment->comment_author, $comment->comment_author_url ); $comment_count = intval( $comment_count ); echo '<span class="akismet-user-comment-count" commentid="' . $comment->comment_ID . '" style="display:none;"><br><span class="akismet-user-comment-counts">'; /* translators: %s: Number of comments. */ echo sprintf( esc_html( _n( '%s approved', '%s approved', $comment_count, 'akismet' ) ), number_format_i18n( $comment_count ) ) . '</span></span>'; } return $a; } public static function comment_status_meta_box( $comment ) { $history = Akismet::get_comment_history( $comment->comment_ID ); if ( $history ) { foreach ( $history as $row ) { $message = ''; if ( ! empty( $row['message'] ) ) { // Old versions of Akismet stored the message as a literal string in the commentmeta. // New versions don't do that for two reasons: // 1) Save space. // 2) The message can be translated into the current language of the blog, not stuck // in the language of the blog when the comment was made. $message = esc_html( $row['message'] ); } elseif ( ! empty( $row['event'] ) ) { // If possible, use a current translation. switch ( $row['event'] ) { case 'recheck-spam': $message = esc_html( __( 'Akismet re-checked and caught this comment as spam.', 'akismet' ) ); break; case 'check-spam': $message = esc_html( __( 'Akismet caught this comment as spam.', 'akismet' ) ); break; case 'recheck-ham': $message = esc_html( __( 'Akismet re-checked and cleared this comment.', 'akismet' ) ); break; case 'check-ham': $message = esc_html( __( 'Akismet cleared this comment.', 'akismet' ) ); break; case 'check-ham-pending': $message = esc_html( __( 'Akismet provisionally cleared this comment.', 'akismet' ) ); break; case 'wp-blacklisted': case 'wp-disallowed': $message = sprintf( /* translators: The placeholder is a WordPress PHP function name. */ esc_html( __( 'Comment was caught by %s.', 'akismet' ) ), function_exists( 'wp_check_comment_disallowed_list' ) ? '<code>wp_check_comment_disallowed_list</code>' : '<code>wp_blacklist_check</code>' ); break; case 'report-spam': if ( isset( $row['user'] ) ) { /* translators: The placeholder is a username. */ $message = esc_html( sprintf( __( '%s reported this comment as spam.', 'akismet' ), $row['user'] ) ); } elseif ( ! $message ) { $message = esc_html( __( 'This comment was reported as spam.', 'akismet' ) ); } break; case 'report-ham': if ( isset( $row['user'] ) ) { /* translators: The placeholder is a username. */ $message = esc_html( sprintf( __( '%s reported this comment as not spam.', 'akismet' ), $row['user'] ) ); } elseif ( ! $message ) { $message = esc_html( __( 'This comment was reported as not spam.', 'akismet' ) ); } break; case 'cron-retry-spam': $message = esc_html( __( 'Akismet caught this comment as spam during an automatic retry.', 'akismet' ) ); break; case 'cron-retry-ham': $message = esc_html( __( 'Akismet cleared this comment during an automatic retry.', 'akismet' ) ); break; case 'check-error': if ( isset( $row['meta'], $row['meta']['response'] ) ) { /* translators: The placeholder is an error response returned by the API server. */ $message = sprintf( esc_html( __( 'Akismet was unable to check this comment (response: %s) but will automatically retry later.', 'akismet' ) ), '<code>' . esc_html( $row['meta']['response'] ) . '</code>' ); } else { $message = esc_html( __( 'Akismet was unable to check this comment but will automatically retry later.', 'akismet' ) ); } break; case 'recheck-error': if ( isset( $row['meta'], $row['meta']['response'] ) ) { /* translators: The placeholder is an error response returned by the API server. */ $message = sprintf( esc_html( __( 'Akismet was unable to recheck this comment (response: %s).', 'akismet' ) ), '<code>' . esc_html( $row['meta']['response'] ) . '</code>' ); } else { $message = esc_html( __( 'Akismet was unable to recheck this comment.', 'akismet' ) ); } break; case 'webhook-spam': $message = esc_html( __( 'Akismet caught this comment as spam and updated its status via webhook.', 'akismet' ) ); break; case 'webhook-ham': $message = esc_html( __( 'Akismet cleared this comment and updated its status via webhook.', 'akismet' ) ); break; case 'webhook-spam-noaction': $message = esc_html( __( 'Akismet determined this comment was spam during a recheck. It did not update the comment status because it had already been modified by another user or plugin.', 'akismet' ) ); break; case 'webhook-ham-noaction': $message = esc_html( __( 'Akismet cleared this comment during a recheck. It did not update the comment status because it had already been modified by another user or plugin.', 'akismet' ) ); break; case 'akismet-skipped': $message = esc_html( __( 'This comment was not sent to Akismet when it was submitted because it was caught by something else.', 'akismet' ) ); break; case 'akismet-skipped-disallowed': $message = esc_html( __( 'This comment was not sent to Akismet when it was submitted because it was caught by the comment disallowed list.', 'akismet' ) ); break; default: if ( preg_match( '/^status-changed/', $row['event'] ) ) { // Half of these used to be saved without the dash after 'status-changed'. // See https://plugins.trac.wordpress.org/changeset/1150658/akismet/trunk $new_status = preg_replace( '/^status-changed-?/', '', $row['event'] ); /* translators: The placeholder is a short string (like 'spam' or 'approved') denoting the new comment status. */ $message = sprintf( esc_html( __( 'Comment status was changed to %s', 'akismet' ) ), '<code>' . esc_html( $new_status ) . '</code>' ); } elseif ( preg_match( '/^status-/', $row['event'] ) ) { $new_status = preg_replace( '/^status-/', '', $row['event'] ); if ( isset( $row['user'] ) ) { /* translators: %1$s is a username; %2$s is a short string (like 'spam' or 'approved') denoting the new comment status. */ $message = sprintf( esc_html( __( '%1$s changed the comment status to %2$s.', 'akismet' ) ), $row['user'], '<code>' . esc_html( $new_status ) . '</code>' ); } } break; } } if ( ! empty( $message ) ) { echo '<p>'; if ( isset( $row['time'] ) ) { $time = gmdate( 'D d M Y @ h:i:s a', (int) $row['time'] ) . ' GMT'; /* translators: The placeholder is an amount of time, like "7 seconds" or "3 days" returned by the function human_time_diff(). */ $time_html = '<span style="color: #999;" alt="' . esc_attr( $time ) . '" title="' . esc_attr( $time ) . '">' . sprintf( esc_html__( '%s ago', 'akismet' ), human_time_diff( $row['time'] ) ) . '</span>'; printf( /* translators: %1$s is a human-readable time difference, like "3 hours ago", and %2$s is an already-translated phrase describing how a comment's status changed, like "This comment was reported as spam." */ esc_html( __( '%1$s - %2$s', 'akismet' ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $time_html, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $message ); // esc_html() is done above so that we can use HTML in $message. } else { // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $message; // esc_html() is done above so that we can use HTML in $message. } echo '</p>'; } } } else { echo '<p>'; echo esc_html( __( 'No comment history.', 'akismet' ) ); echo '</p>'; } } public static function plugin_action_links( $links, $file ) { if ( $file == plugin_basename( plugin_dir_url( __FILE__ ) . '/akismet.php' ) ) { $links[] = '<a href="' . esc_url( self::get_page_url() ) . '">' . esc_html__( 'Settings', 'akismet' ) . '</a>'; } return $links; } // Total spam in queue // get_option( 'akismet_spam_count' ) is the total caught ever public static function get_spam_count( $type = false ) { global $wpdb; if ( ! $type ) { // total $count = wp_cache_get( 'akismet_spam_count', 'widget' ); if ( false === $count ) { $count = wp_count_comments(); $count = $count->spam; wp_cache_set( 'akismet_spam_count', $count, 'widget', 3600 ); } return $count; } elseif ( 'comments' == $type || 'comment' == $type ) { // comments $type = ''; } return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM {$wpdb->comments} WHERE comment_approved = 'spam' AND comment_type = %s", $type ) ); } // Check connectivity between the WordPress blog and Akismet's servers. // Returns an associative array of server IP addresses, where the key is the IP address, and value is true (available) or false (unable to connect). public static function check_server_ip_connectivity() { $servers = $ips = array(); // Some web hosts may disable this function if ( function_exists( 'gethostbynamel' ) ) { $ips = gethostbynamel( 'rest.akismet.com' ); if ( $ips && is_array( $ips ) && count( $ips ) ) { $api_key = Akismet::get_api_key(); foreach ( $ips as $ip ) { $response = Akismet::verify_key( $api_key, $ip ); // even if the key is invalid, at least we know we have connectivity if ( $response == 'valid' || $response == 'invalid' ) { $servers[ $ip ] = 'connected'; } else { $servers[ $ip ] = $response ? $response : 'unable to connect'; } } } } return $servers; } // Simpler connectivity check public static function check_server_connectivity( $cache_timeout = 86400 ) { $debug = array(); $debug['PHP_VERSION'] = PHP_VERSION; $debug['WORDPRESS_VERSION'] = $GLOBALS['wp_version']; $debug['AKISMET_VERSION'] = AKISMET_VERSION; $debug['AKISMET__PLUGIN_DIR'] = AKISMET__PLUGIN_DIR; $debug['SITE_URL'] = site_url(); $debug['HOME_URL'] = home_url(); $servers = get_option( 'akismet_available_servers' ); if ( ( time() - get_option( 'akismet_connectivity_time' ) < $cache_timeout ) && $servers !== false ) { $servers = self::check_server_ip_connectivity(); update_option( 'akismet_available_servers', $servers ); update_option( 'akismet_connectivity_time', time() ); } if ( wp_http_supports( array( 'ssl' ) ) ) { $response = wp_remote_get( 'https://rest.akismet.com/1.1/test' ); } else { $response = wp_remote_get( 'http://rest.akismet.com/1.1/test' ); } $debug['gethostbynamel'] = function_exists( 'gethostbynamel' ) ? 'exists' : 'not here'; $debug['Servers'] = $servers; $debug['Test Connection'] = $response; Akismet::log( $debug ); if ( $response && 'connected' == wp_remote_retrieve_body( $response ) ) { return true; } return false; } // Check the server connectivity and store the available servers in an option. public static function get_server_connectivity( $cache_timeout = 86400 ) { return self::check_server_connectivity( $cache_timeout ); } /** * Find out whether any comments in the Pending queue have not yet been checked by Akismet. * * @return bool */ public static function are_any_comments_waiting_to_be_checked() { return ! ! get_comments( array( // Exclude comments that are not pending. This would happen if someone manually approved or spammed a comment // that was waiting to be checked. The akismet_error meta entry will eventually be removed by the cron recheck job. 'status' => 'hold', // This is the commentmeta that is saved when a comment couldn't be checked. 'meta_key' => 'akismet_error', // We only need to know whether at least one comment is waiting for a check. 'number' => 1, ) ); } public static function get_page_url( $page = 'config' ) { $args = array( 'page' => 'akismet-key-config' ); if ( $page == 'stats' ) { $args = array( 'page' => 'akismet-key-config', 'view' => 'stats', ); } elseif ( $page == 'delete_key' ) { $args = array( 'page' => 'akismet-key-config', 'view' => 'start', 'action' => 'delete-key', '_wpnonce' => wp_create_nonce( self::NONCE ), ); } elseif ( $page === 'init' ) { $args = array( 'page' => 'akismet-key-config', 'view' => 'start', ); } return add_query_arg( $args, menu_page_url( 'akismet-key-config', false ) ); } /** * Get Akismet user subscription information. * * @param string $api_key The Akismet API key. * @return object|false Object with subscription info, or false if key is invalid or has no subscription. * * The returned object contains these properties: * - account_id (int|false): WordPress.com user ID, or false if unavailable. * - status (string): Account status - 'active', 'active-dunning', 'no-sub', 'cancelled', 'suspended', 'missing', or 'notice'. * - account_name (string): Subscription plan display name. * - account_type (string): Account type slug. * - next_billing_date (int|false): Unix timestamp of next billing date, or false if none. * - limit_reached (bool): Whether the usage limit has been reached. */ public static function get_akismet_user( $api_key ) { $request_args = array( 'key' => $api_key, 'blog' => get_option( 'home' ), ); $request_args = apply_filters( 'akismet_request_args', $request_args, 'get-subscription' ); $subscription_verification = Akismet::http_post( Akismet::build_query( $request_args ), 'get-subscription' ); $akismet_user = false; if ( ! empty( $subscription_verification[1] ) ) { if ( 'invalid' !== $subscription_verification[1] ) { $decoded = json_decode( $subscription_verification[1] ); if ( is_object( $decoded ) ) { $akismet_user = $decoded; } } } return $akismet_user; } public static function get_stats( $api_key ) { $stat_totals = array(); foreach ( array( '6-months', 'all' ) as $interval ) { $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] ) ) { $data = json_decode( $response[1] ); /* * The json decoded response should be an object. If it's not an object, something's wrong, and the data * shouldn't be added to the stats_totals array. */ if ( is_object( $data ) ) { $stat_totals[ $interval ] = $data; } } } return $stat_totals; } public static function verify_wpcom_key( $api_key, $user_id, $extra = array() ) { $request_args = array_merge( array( 'user_id' => $user_id, 'api_key' => $api_key, 'get_account_type' => 'true', ), $extra ); $request_args = apply_filters( 'akismet_request_args', $request_args, 'verify-wpcom-key' ); $akismet_account = Akismet::http_post( Akismet::build_query( $request_args ), 'verify-wpcom-key' ); if ( ! empty( $akismet_account[1] ) ) { $akismet_account = json_decode( $akismet_account[1] ); } Akismet::log( compact( 'akismet_account' ) ); return $akismet_account; } public static function connect_jetpack_user() { if ( $jetpack_user = self::get_jetpack_user() ) { if ( isset( $jetpack_user['user_id'] ) && isset( $jetpack_user['api_key'] ) ) { $akismet_user = self::verify_wpcom_key( $jetpack_user['api_key'], $jetpack_user['user_id'], array( 'action' => 'connect_jetpack_user' ) ); if ( is_object( $akismet_user ) ) { self::save_key( $akismet_user->api_key ); return in_array( $akismet_user->status, array( Akismet::USER_STATUS_ACTIVE, 'active-dunning', Akismet::USER_STATUS_NO_SUB ) ); } } } return false; } public static function display_alert() { Akismet::view( 'notice', array( 'type' => 'alert', 'code' => (int) get_option( 'akismet_alert_code' ), 'msg' => get_option( 'akismet_alert_msg' ), ) ); } public static function get_usage_limit_alert_data() { return array( 'type' => 'usage-limit', 'code' => (int) get_option( 'akismet_alert_code' ), 'msg' => get_option( 'akismet_alert_msg' ), 'api_calls' => get_option( 'akismet_alert_api_calls' ), 'usage_limit' => get_option( 'akismet_alert_usage_limit' ), 'upgrade_plan' => get_option( 'akismet_alert_upgrade_plan' ), 'upgrade_url' => get_option( 'akismet_alert_upgrade_url' ), 'upgrade_type' => get_option( 'akismet_alert_upgrade_type' ), 'upgrade_via_support' => get_option( 'akismet_alert_upgrade_via_support' ) === 'true', 'recommended_plan_name' => get_option( 'akismet_alert_recommended_plan_name' ), ); } public static function display_usage_limit_alert() { Akismet::view( 'notice', self::get_usage_limit_alert_data() ); } public static function display_spam_check_warning() { Akismet::fix_scheduled_recheck(); if ( wp_next_scheduled( 'akismet_schedule_cron_recheck' ) > time() && self::are_any_comments_waiting_to_be_checked() ) { /* * The 'akismet_display_cron_disabled_notice' filter can be used to control whether the WP-Cron disabled notice is displayed. */ if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON && apply_filters( 'akismet_display_cron_disabled_notice', true ) ) { Akismet::view( 'notice', array( 'type' => 'spam-check-cron-disabled' ) ); } else { /* translators: The Akismet configuration page URL. */ $link_text = apply_filters( 'akismet_spam_check_warning_link_text', sprintf( __( 'Please check your <a href="%s">Akismet configuration</a> and contact your web host if problems persist.', 'akismet' ), esc_url( self::get_page_url() ) ) ); Akismet::view( 'notice', array( 'type' => 'spam-check', 'link_text' => $link_text, ) ); } } } public static function display_api_key_warning() { Akismet::view( 'notice', array( 'type' => 'plugin' ) ); } public static function display_page() { if ( ! Akismet::get_api_key() || ( isset( $_GET['view'] ) && $_GET['view'] == 'start' ) ) { self::display_start_page(); } elseif ( isset( $_GET['view'] ) && $_GET['view'] == 'stats' ) { self::display_stats_page(); } else { self::display_configuration_page(); } } public static function display_start_page() { if ( isset( $_GET['action'] ) ) { if ( $_GET['action'] == 'delete-key' ) { if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], self::NONCE ) ) { delete_option( 'wordpress_api_key' ); } } } $api_key = Akismet::get_api_key(); $existing_key_is_valid = ! ( self::get_notice_by_key( 'status' ) === self::NOTICE_EXISTING_KEY_INVALID ); if ( $api_key && $existing_key_is_valid ) { self::display_configuration_page(); return; } // the user can choose to auto connect their API key by clicking a button on the akismet done page // if jetpack, get verified api key by using connected wpcom user id // if no jetpack, get verified api key by using an akismet token $akismet_user = false; if ( isset( $_GET['token'] ) && preg_match( '/^(\d+)-[0-9a-f]{20}$/', $_GET['token'] ) ) { $akismet_user = self::verify_wpcom_key( '', '', array( 'token' => $_GET['token'] ) ); } if ( false === $akismet_user ) { $jetpack_user = self::get_jetpack_user(); if ( is_array( $jetpack_user ) ) { $akismet_user = self::verify_wpcom_key( $jetpack_user['api_key'], $jetpack_user['user_id'] ); } } if ( isset( $_GET['action'] ) ) { if ( $_GET['action'] == 'save-key' ) { if ( is_object( $akismet_user ) ) { self::save_key( $akismet_user->api_key ); self::display_configuration_page(); return; } } } Akismet::view( 'start', compact( 'akismet_user' ) ); /* // To see all variants when testing. $akismet_user->status = Akismet::USER_STATUS_NO_SUB; Akismet::view( 'start', compact( 'akismet_user' ) ); $akismet_user->status = Akismet::USER_STATUS_CANCELLED; Akismet::view( 'start', compact( 'akismet_user' ) ); $akismet_user->status = Akismet::USER_STATUS_SUSPENDED; Akismet::view( 'start', compact( 'akismet_user' ) ); $akismet_user->status = 'other'; Akismet::view( 'start', compact( 'akismet_user' ) ); $akismet_user = false; */ } public static function display_stats_page() { Akismet::view( 'stats' ); } public static function display_configuration_page() { $api_key = Akismet::get_api_key(); $akismet_user = self::get_akismet_user( $api_key ); if ( ! $akismet_user ) { // This could happen if the user's key became invalid after it was previously valid and successfully set up. self::$notices['status'] = self::NOTICE_EXISTING_KEY_INVALID; self::display_start_page(); return; } $stat_totals = self::get_stats( $api_key ); // If unset, create the new strictness option using the old discard option to determine its default. // If the old option wasn't set, default to discarding the blatant spam. if ( get_option( 'akismet_strictness' ) === false ) { add_option( 'akismet_strictness', ( get_option( 'akismet_discard_month' ) === 'false' ? '0' : '1' ) ); } // Sync the local "Total spam blocked" count with the authoritative count from the server. if ( isset( $stat_totals['all'], $stat_totals['all']->spam ) ) { update_option( 'akismet_spam_count', $stat_totals['all']->spam ); } $notices = array(); if ( empty( self::$notices ) ) { if ( ! empty( $stat_totals['all'] ) && isset( $stat_totals['all']->time_saved ) && $akismet_user->status == Akismet::USER_STATUS_ACTIVE && $akismet_user->account_type == 'free-api-key' ) { $time_saved = false; if ( $stat_totals['all']->time_saved > 1800 ) { $total_in_minutes = round( $stat_totals['all']->time_saved / 60 ); $total_in_hours = round( $total_in_minutes / 60 ); $total_in_days = round( $total_in_hours / 8 ); $cleaning_up = __( 'Cleaning up spam takes time.', 'akismet' ); if ( $total_in_days > 1 ) { /* translators: %s: Number of days. */ $time_saved = $cleaning_up . ' ' . sprintf( _n( 'Akismet has saved you %s day!', 'Akismet has saved you %s days!', $total_in_days, 'akismet' ), number_format_i18n( $total_in_days ) ); } elseif ( $total_in_hours > 1 ) { /* translators: %s: Number of hours. */ $time_saved = $cleaning_up . ' ' . sprintf( _n( 'Akismet has saved you %d hour!', 'Akismet has saved you %d hours!', $total_in_hours, 'akismet' ), $total_in_hours ); } elseif ( $total_in_minutes >= 30 ) { /* translators: %s: Number of minutes. */ $time_saved = $cleaning_up . ' ' . sprintf( _n( 'Akismet has saved you %d minute!', 'Akismet has saved you %d minutes!', $total_in_minutes, 'akismet' ), $total_in_minutes ); } } $notices[] = array( 'type' => 'active-notice', 'time_saved' => $time_saved, ); } } if ( ! Akismet::predefined_api_key() && ! isset( self::$notices['status'] ) && in_array( $akismet_user->status, array( Akismet::USER_STATUS_CANCELLED, Akismet::USER_STATUS_SUSPENDED, Akismet::USER_STATUS_MISSING, Akismet::USER_STATUS_NO_SUB ) ) ) { $notices[] = array( 'type' => $akismet_user->status ); } $alert_code = get_option( 'akismet_alert_code' ); if ( isset( Akismet::$limit_notices[ $alert_code ] ) ) { $notices[] = self::get_usage_limit_alert_data(); } elseif ( $alert_code > 0 ) { $notices[] = array( 'type' => 'alert', 'code' => (int) get_option( 'akismet_alert_code' ), 'msg' => get_option( 'akismet_alert_msg' ), ); } /* * To see all variants when testing. * * You may also want to comment out the akismet_view_arguments filter in Akismet::view() * to ensure that you can see all of the notices (e.g. suspended, active-notice). */ // $notices[] = array( 'type' => 'active-notice', 'time_saved' => 'Cleaning up spam takes time. Akismet has saved you 1 minute!' ); // $notices[] = array( 'type' => 'plugin' ); // $notices[] = array( 'type' => 'notice', 'notice_header' => 'This is the notice header.', 'notice_text' => 'This is the notice text.' ); // $notices[] = array( 'type' => 'missing-functions' ); // $notices[] = array( 'type' => 'servers-be-down' ); // $notices[] = array( 'type' => 'active-dunning' ); // $notices[] = array( 'type' => Akismet::USER_STATUS_CANCELLED ); // $notices[] = array( 'type' => Akismet::USER_STATUS_SUSPENDED ); // $notices[] = array( 'type' => Akismet::USER_STATUS_MISSING ); // $notices[] = array( 'type' => Akismet::USER_STATUS_NO_SUB ); // $notices[] = array( 'type' => 'new-key-valid' ); // $notices[] = array( 'type' => 'new-key-invalid' ); // $notices[] = array( 'type' => 'existing-key-invalid' ); // $notices[] = array( 'type' => 'new-key-failed' ); // $notices[] = array( 'type' => 'usage-limit', 'api_calls' => '15000', 'usage_limit' => '10000', 'upgrade_plan' => 'Enterprise', 'upgrade_url' => 'https://akismet.com/account/', 'code' => 10502 ); // $notices[] = array( 'type' => 'usage-limit', 'api_calls' => '15000', 'usage_limit' => '10000', 'upgrade_type' => 'qty', 'upgrade_plan' => 'Business', 'upgrade_url' => 'https://akismet.com/account/', 'code' => 10504, 'recommended_plan_name' => 'Akismet Pro (500)' ); // $notices[] = array( 'type' => 'usage-limit', 'api_calls' => '15000', 'usage_limit' => '10000', 'upgrade_type' => 'qty', 'upgrade_plan' => 'Business', 'upgrade_url' => 'https://akismet.com/pricing/', 'code' => 10508 ); // $notices[] = array( 'type' => 'spam-check', 'link_text' => 'Link text.' ); // $notices[] = array( 'type' => 'spam-check-cron-disabled' ); // $notices[] = array( 'type' => 'alert', 'code' => 123 ); // $notices[] = array( 'type' => 'alert', 'code' => Akismet::ALERT_CODE_COMMERCIAL ); Akismet::log( compact( 'stat_totals', 'akismet_user' ) ); Akismet::view( 'config', compact( 'api_key', 'akismet_user', 'stat_totals', 'notices' ) ); } public static function display_notice() { global $hook_suffix; if ( in_array( $hook_suffix, array( 'jetpack_page_akismet-key-config', 'settings_page_akismet-key-config' ) ) ) { // This page manages the notices and puts them inline where they make sense. return; } // To see notice variants while testing. // Akismet::view( 'notice', array( 'type' => 'spam-check-cron-disabled' ) ); // Akismet::view( 'notice', array( 'type' => 'spam-check' ) ); // Akismet::view( 'notice', array( 'type' => 'alert', 'code' => 123, 'msg' => 'Message' ) ); // Akismet::view( 'notice', array( 'type' => 'usage-limit', 'api_calls' => '15000', 'usage_limit' => '10000', 'upgrade_plan' => 'Enterprise', 'upgrade_url' => 'https://akismet.com/account/', 'code' => 10502 ) ); // Akismet::view( 'notice', array( 'type' => 'usage-limit', 'api_calls' => '15000', 'usage_limit' => '10000', 'upgrade_type' => 'qty', 'upgrade_plan' => 'Business', 'upgrade_url' => 'https://akismet.com/account/', 'code' => 10504, 'recommended_plan_name' => 'Akismet Pro (500)' ) ); // Akismet::view( 'notice', array( 'type' => 'usage-limit', 'api_calls' => '15000', 'usage_limit' => '10000', 'upgrade_type' => 'qty', 'upgrade_plan' => 'Business', 'upgrade_url' => 'https://akismet.com/pricing/', 'code' => 10508 ) ); if ( in_array( $hook_suffix, array( 'edit-comments.php' ) ) && (int) get_option( 'akismet_alert_code' ) > 0 ) { Akismet::verify_key( Akismet::get_api_key() ); // verify that the key is still in alert state $alert_code = get_option( 'akismet_alert_code' ); if ( isset( Akismet::$limit_notices[ $alert_code ] ) ) { self::display_usage_limit_alert(); } elseif ( $alert_code > 0 ) { self::display_alert(); } } elseif ( in_array( $hook_suffix, self::$activation_banner_pages, true ) && ! Akismet::get_api_key() ) { // Show the "Set Up Akismet" banner on the comments and plugin pages if no API key has been set. self::display_api_key_warning(); } elseif ( $hook_suffix == 'edit-comments.php' && wp_next_scheduled( 'akismet_schedule_cron_recheck' ) ) { self::display_spam_check_warning(); } if ( isset( $_GET['akismet_recheck_complete'] ) ) { $recheck_count = (int) $_GET['recheck_count']; $spam_count = (int) $_GET['spam_count']; if ( $recheck_count === 0 ) { $message = __( 'There were no comments to check. Akismet will only check comments awaiting moderation.', 'akismet' ); } else { /* translators: %s: Number of comments. */ $message = sprintf( _n( 'Akismet checked %s comment.', 'Akismet checked %s comments.', $recheck_count, 'akismet' ), number_format( $recheck_count ) ); $message .= ' '; if ( $spam_count === 0 ) { $message .= __( 'No comments were caught as spam.', 'akismet' ); } else { /* translators: %s: Number of comments. */ $message .= sprintf( _n( '%s comment was caught as spam.', '%s comments were caught as spam.', $spam_count, 'akismet' ), number_format( $spam_count ) ); } } echo '<div class="notice notice-success"><p>' . esc_html( $message ) . '</p></div>'; } elseif ( isset( $_GET['akismet_recheck_error'] ) ) { echo '<div class="notice notice-error"><p>' . esc_html( __( 'Akismet could not recheck your comments for spam.', 'akismet' ) ) . '</p></div>'; } } public static function display_status() { if ( ! self::get_server_connectivity() ) { Akismet::view( 'notice', array( 'type' => 'servers-be-down' ) ); } elseif ( ! empty( self::$notices ) ) { foreach ( self::$notices as $index => $type ) { if ( is_object( $type ) ) { $notice_header = $notice_text = ''; if ( property_exists( $type, 'notice_header' ) ) { $notice_header = wp_kses( $type->notice_header, self::$allowed ); } if ( property_exists( $type, 'notice_text' ) ) { $notice_text = wp_kses( $type->notice_text, self::$allowed ); } if ( property_exists( $type, 'status' ) ) { $type = wp_kses( $type->status, self::$allowed ); Akismet::view( 'notice', compact( 'type', 'notice_header', 'notice_text' ) ); unset( self::$notices[ $index ] ); } } else { Akismet::view( 'notice', compact( 'type' ) ); unset( self::$notices[ $index ] ); } } } } /** * Gets a specific notice by key. * * @param $key * @return mixed */ private static function get_notice_by_key( $key ) { return self::$notices[ $key ] ?? null; } /** * Gets a Jetpack user. * * @return array|false */ private static function get_jetpack_user() { if ( ! self::is_jetpack_active() ) { return false; } if ( defined( 'JETPACK__VERSION' ) && version_compare( JETPACK__VERSION, '7.7', '<' ) ) { // For version of Jetpack prior to 7.7. Jetpack::load_xml_rpc_client(); } $xml = new Jetpack_IXR_ClientMulticall( array( 'user_id' => get_current_user_id() ) ); $xml->addCall( 'wpcom.getUserID' ); $xml->addCall( 'akismet.getAPIKey' ); $xml->query(); Akismet::log( compact( 'xml' ) ); if ( ! $xml->isError() ) { $responses = $xml->getResponse(); if ( ( is_countable( $responses ) ? count( $responses ) : 0 ) > 1 ) { // Due to a quirk in how Jetpack does multi-calls, the response order // can't be trusted to match the call order. It's a good thing our // return values can be mostly differentiated from each other. $first_response_value = array_shift( $responses[0] ); $second_response_value = array_shift( $responses[1] ); // If WPCOM ever reaches 100 billion users, this will fail. :-) if ( preg_match( '/^[a-f0-9]{12}$/i', $first_response_value ) ) { $api_key = $first_response_value; $user_id = (int) $second_response_value; } else { $api_key = $second_response_value; $user_id = (int) $first_response_value; } return compact( 'api_key', 'user_id' ); } } return false; } /** * Some commentmeta isn't useful in an export file. Suppress it (when supported). * * @param bool $exclude * @param string $key The meta key * @param object $meta The meta object * @return bool Whether to exclude this meta entry from the export. */ public static function exclude_commentmeta_from_export( $exclude, $key, $meta ) { if ( in_array( $key, array( 'akismet_as_submitted', 'akismet_delay_moderation_email', 'akismet_delayed_moderation_email', 'akismet_rechecking', 'akismet_schedule_approval_fallback', 'akismet_schedule_email_fallback', 'akismet_skipped_microtime', ) ) ) { return true; } return $exclude; } /** * When Akismet is active, remove the "Activate Akismet" step from the plugin description. */ public static function modify_plugin_description( $all_plugins ) { if ( isset( $all_plugins['akismet/akismet.php'] ) ) { if ( Akismet::get_api_key() ) { $all_plugins['akismet/akismet.php']['Description'] = __( 'Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from spam</strong>. Your site is fully configured and being protected, even while you sleep.', 'akismet' ); } else { $all_plugins['akismet/akismet.php']['Description'] = __( 'Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from spam</strong>. It keeps your site protected even while you sleep. To get started, just go to <a href="admin.php?page=akismet-key-config">your Akismet Settings page</a> to set up your API key.', 'akismet' ); } } return $all_plugins; } private static function set_form_privacy_notice_option( $state ) { if ( in_array( $state, array( 'display', 'hide' ) ) ) { update_option( 'akismet_comment_form_privacy_notice', $state ); } } public static function register_personal_data_eraser( $erasers ) { $erasers['akismet'] = array( 'eraser_friendly_name' => __( 'Akismet', 'akismet' ), 'callback' => array( 'Akismet_Admin', 'erase_personal_data' ), ); return $erasers; } /** * When a user requests that their personal data be removed, Akismet has a duty to discard * any personal data we store outside of the comment itself. Right now, that is limited * to the copy of the comment we store in the akismet_as_submitted commentmeta. * * FWIW, this information would be automatically deleted after 15 days. * * @param $email_address string The email address of the user who has requested erasure. * @param $page int This function can (and will) be called multiple times to prevent timeouts, * so this argument is used for pagination. * @return array * @see https://developer.wordpress.org/plugins/privacy/adding-the-personal-data-eraser-to-your-plugin/ */ public static function erase_personal_data( $email_address, $page = 1 ) { $items_removed = false; $number = 50; $page = (int) $page; $comments = get_comments( array( 'author_email' => $email_address, 'number' => $number, 'paged' => $page, 'order_by' => 'comment_ID', 'order' => 'ASC', ) ); foreach ( (array) $comments as $comment ) { $comment_as_submitted = get_comment_meta( $comment->comment_ID, 'akismet_as_submitted', true ); if ( $comment_as_submitted ) { delete_comment_meta( $comment->comment_ID, 'akismet_as_submitted' ); $items_removed = true; } } // Tell core if we have more comments to work on still $done = ( is_countable( $comments ) ? count( $comments ) : 0 ) < $number; return array( 'items_removed' => $items_removed, 'items_retained' => false, // always false in this example 'messages' => array(), // no messages in this example 'done' => $done, ); } /** * Return an array of HTML elements that are allowed in a notice. * * @return array */ public static function get_notice_kses_allowed_elements() { return self::$allowed; } /** * Return a version to append to the URL of an asset file (e.g. CSS and images). * * @param string $relative_path Relative path to asset file * @return string */ public static function get_asset_file_version( $relative_path ) { $full_path = AKISMET__PLUGIN_DIR . $relative_path; // If the AKISMET_VERSION contains a lower-case letter, it's a development version (e.g. 5.3.1a2). // Use the file modified time in development. if ( preg_match( '/[a-z]/', AKISMET_VERSION ) && file_exists( $full_path ) ) { return filemtime( $full_path ); } // Otherwise, use the AKISMET_VERSION. return AKISMET_VERSION; } /** * Return inline CSS for Akismet admin. * * @return string */ protected static function get_inline_css(): string { global $hook_suffix; // Hide excess compatible plugins when there are lots. $inline_css = ' .akismet-compatible-plugins__card:nth-child(n+' . esc_attr( Akismet_Compatible_Plugins::DEFAULT_VISIBLE_PLUGIN_COUNT + 1 ) . ') { display: none; } .akismet-compatible-plugins__list.is-expanded .akismet-compatible-plugins__card:nth-child(n+' . esc_attr( Akismet_Compatible_Plugins::DEFAULT_VISIBLE_PLUGIN_COUNT + 1 ) . ') { display: flex; } '; // Enqueue the Akismet activation banner background separately so we can // include the right path to the image. Shown on edit-comments.php and plugins.php. if ( in_array( $hook_suffix, self::$activation_banner_pages, true ) ) { $activation_banner_url = esc_url( plugin_dir_url( __FILE__ ) . '_inc/img/akismet-activation-banner-elements.png' ); $inline_css .= '.akismet-activate {' . PHP_EOL . 'background-image: url(' . $activation_banner_url . ');' . PHP_EOL . '}'; } return $inline_css; } } class.akismet-cli.php 0000777 00000011621 15251466723 0010606 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 ) ) ); } } } class.akismet-widget.php 0000777 00000010616 15251466723 0011325 0 ustar 00 <?php /** * @package Akismet */ // We plan to gradually remove all of the disabled lint rules below. // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped /** * Akismet Widget Class */ class Akismet_Widget extends WP_Widget { /** * Constructor */ function __construct() { parent::__construct( 'akismet_widget', __( 'Akismet Widget', 'akismet' ), array( 'description' => __( 'Display the number of spam comments Akismet has caught', 'akismet' ) ) ); } /** * Outputs the widget settings form * * @param array $instance The widget options */ public function form( $instance ) { if ( $instance && isset( $instance['title'] ) ) { $title = $instance['title']; } else { $title = __( 'Spam Blocked', 'akismet' ); } ?> <p> <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'akismet' ); ?></label> <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /> </p> <?php } /** * Updates the widget settings * * @param array $new_instance New widget instance * @param array $old_instance Old widget instance * @return array Updated widget instance */ public function update( $new_instance, $old_instance ) { $instance = array(); $instance['title'] = sanitize_text_field( $new_instance['title'] ); return $instance; } /** * Outputs the widget content * * @param array $args Widget arguments * @param array $instance Widget instance */ public function widget( $args, $instance ) { $count = get_option( 'akismet_spam_count' ); if ( ! isset( $instance['title'] ) ) { $instance['title'] = __( 'Spam Blocked', 'akismet' ); } echo $args['before_widget']; if ( ! empty( $instance['title'] ) ) { echo $args['before_title']; echo esc_html( $instance['title'] ); echo $args['after_title']; } ?> <style> .a-stats { --akismet-color-mid-green: #357b49; --akismet-color-white: #fff; --akismet-color-light-grey: #f6f7f7; max-width: 350px; width: auto; } .a-stats * { all: unset; box-sizing: border-box; } .a-stats strong { font-weight: 600; } .a-stats a.a-stats__link, .a-stats a.a-stats__link:visited, .a-stats a.a-stats__link:active { background: var(--akismet-color-mid-green); border: none; box-shadow: none; border-radius: 8px; color: var(--akismet-color-white); cursor: pointer; display: block; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen-Sans', 'Ubuntu', 'Cantarell', 'Helvetica Neue', sans-serif; font-weight: 500; padding: 12px; text-align: center; text-decoration: none; transition: all 0.2s ease; } /* Extra specificity to deal with TwentyTwentyOne focus style */ .widget .a-stats a.a-stats__link:focus { background: var(--akismet-color-mid-green); color: var(--akismet-color-white); text-decoration: none; } .a-stats a.a-stats__link:hover { filter: brightness(110%); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06), 0 0 2px rgba(0, 0, 0, 0.16); } .a-stats .count { color: var(--akismet-color-white); display: block; font-size: 1.5em; line-height: 1.4; padding: 0 13px; white-space: nowrap; } </style> <div class="a-stats"> <a href="https://akismet.com?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=widget_stats" class="a-stats__link" target="_blank" rel="noopener" style="background-color: var(--akismet-color-mid-green); color: var(--akismet-color-white);"> <?php echo wp_kses( sprintf( /* translators: The placeholder is the number of pieces of spam blocked by Akismet. */ _n( '<strong class="count">%1$s spam</strong> blocked by <strong>Akismet</strong>', '<strong class="count">%1$s spam</strong> blocked by <strong>Akismet</strong>', $count, 'akismet' ), number_format_i18n( $count ) ), array( 'strong' => array( 'class' => true, ), ) ); ?> </a> </div> <?php echo $args['after_widget']; } } /** * Register the Akismet widget */ function akismet_register_widgets() { register_widget( 'Akismet_Widget' ); } add_action( 'widgets_init', 'akismet_register_widgets' ); LICENSE.txt 0000777 00000043254 15251466723 0006421 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. views/compatible-plugins.php 0000777 00000010416 15251466723 0012234 0 ustar 00 <?php /** @var array|WP_Error $compatible_plugins */ $bypass_cache = ! empty( $_GET['akismet_refresh_compatible_plugins'] ); $compatible_plugins = Akismet_Compatible_Plugins::get_installed_compatible_plugins( $bypass_cache ); if ( is_array( $compatible_plugins ) ) : $compatible_plugin_count = count( $compatible_plugins ); ?> <div class="akismet-card akismet-compatible-plugins"> <div class="akismet-section-header"> <h2 class="akismet-section-header__label akismet-compatible-plugins__section-header-label" aria-label="<?php esc_attr_e( 'Compatible plugins (new feature)', 'akismet' ); ?>"> <span class="akismet-compatible-plugins__section-header-label-text"><?php esc_html_e( 'Compatible plugins', 'akismet' ); ?></span> <span class="akismet-new-feature"><?php esc_html_e( 'New', 'akismet' ); ?></span> </h2> </div> <div class="akismet-compatible-plugins__content"> <?php echo '<p>'; echo esc_html( __( 'Akismet works with other plugins to keep spam away.', 'akismet' ) ); echo '</p>'; echo '<p>'; if ( 0 === $compatible_plugin_count ) { echo '<a class="akismet-external-link" href="https://akismet.com/developers/plugins-and-libraries/?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=compatible_plugins">'; echo esc_html( __( 'See supported integrations', 'akismet' ) ); echo '</a>'; } else { echo esc_html( _n( "This plugin you've installed is compatible. Follow the documentation link to get started.", "These plugins you've installed are compatible. Follow the documentation links to get started.", $compatible_plugin_count, 'akismet' ) ); } echo '</p>'; ?> <?php if ( ! empty( $compatible_plugins ) ) : ?> <ul class="akismet-compatible-plugins__list" id="akismet-compatible-plugins__list"> <?php foreach ( $compatible_plugins as $compatible_plugin ) : if ( empty( $compatible_plugin['help_url'] ) ) { continue; } ?> <li class="akismet-compatible-plugins__card"> <?php if ( strlen( $compatible_plugin['logo'] ) > 0 ) : ?> <?php $logo_alt = sprintf( /* translators: The placeholder is the name of a plugin, like "Jetpack" . */ __( '%s logo', 'akismet' ), $compatible_plugin['name'] ); ?> <img src="<?php echo esc_url( $compatible_plugin['logo'] ); ?>" alt="<?php echo esc_attr( $logo_alt ); ?>" class="akismet-compatible-plugins__card-logo" width="55" height="55" /> <?php endif ?> <div class="akismet-compatible-plugins__card-detail"> <h3 class="akismet-compatible-plugins__card-title"><?php echo esc_html( $compatible_plugin['name'] ); ?></h3> <div class="akismet-compatible-plugins__docs"> <a class="akismet-external-link" href="<?php echo esc_url( $compatible_plugin['help_url'] ); ?>" aria-label=" <?php echo esc_attr( sprintf( /* translators: The placeholder is the name of a plugin, like "Jetpack" . */ __( 'Documentation for %s', 'akismet' ), $compatible_plugin['name'] ) ); ?> "><?php esc_html_e( 'View documentation', 'akismet' ); ?></a> </div> </div> </li> <?php endforeach; ?> </ul> <?php if ( $compatible_plugin_count > Akismet_Compatible_Plugins::DEFAULT_VISIBLE_PLUGIN_COUNT ) : ?> <button class="akismet-compatible-plugins__show-more" aria-expanded="false" aria-controls="akismet-compatible-plugins__list" data-label-closed=" <?php /* translators: %d: number of compatible plugins, which is guaranteed to be more than 1. */ echo esc_attr( sprintf( __( 'Show all %d plugins', 'akismet' ), $compatible_plugin_count ) ); ?> " data-label-open="<?php echo esc_attr( __( 'Show less', 'akismet' ) ); ?>"> <?php /* translators: %d: number of compatible plugins, which is guaranteed to be more than 1. */ echo esc_html( sprintf( __( 'Show all %d plugins', 'akismet' ), $compatible_plugin_count ) ); ?> </button> <?php endif; ?> <?php endif; ?> </div> </div> <?php endif; views/stats.php 0000777 00000002100 15251466723 0007563 0 ustar 00 <div id="akismet-plugin-container"> <div class="akismet-masthead"> <div class="akismet-masthead__inside-container"> <?php Akismet::view( 'logo', array( 'include_logo_link' => true ) ); ?> <div class="akismet-masthead__back-link-container"> <a class="akismet-masthead__back-link" href="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>"><?php esc_html_e( 'Back to settings', 'akismet' ); ?></a> </div> </div> </div> <?php /* name attribute on iframe is used as a cache-buster here to force Firefox to load the new style charts: https://bugzilla.mozilla.org/show_bug.cgi?id=356558 */ ?> <iframe id="stats-iframe" src="<?php echo esc_url( sprintf( 'https://tools.akismet.com/1.0/user-stats.php?blog=%s&token=%s&locale=%s&is_redecorated=1', urlencode( get_option( 'home' ) ), urlencode( Akismet::get_access_token() ), esc_attr( get_user_locale() ) ) ); ?>" name="<?php echo esc_attr( 'user-stats- ' . filemtime( __FILE__ ) ); ?>" width="100%" height="2500px" frameborder="0" title="<?php echo esc_attr__( 'Akismet detailed stats', 'akismet' ); ?>"></iframe> </div> views/connect-jp.php 0000777 00000000711 15251466723 0010473 0 ustar 00 <?php declare( strict_types = 1 ); //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( 'setup', array( 'use_jetpack_connection' => true ) ); ?> <?php Akismet::view( 'setup-jetpack', array( 'akismet_user' => $akismet_user ) ); ?> </div> <div class="akismet-box"> <?php Akismet::view( 'enter' ); ?> </div> views/notice.php 0000777 00000044353 15251466723 0007726 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. $kses_allow_link = array( 'a' => array( 'href' => true, 'target' => true, 'class' => true, ), ); $kses_allow_strong = array( 'strong' => true ); if ( ! isset( $type ) ) { $type = false; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited } /* * Some notices (plugin, spam-check, spam-check-cron-disabled, alert and usage-limit) are also shown elsewhere in wp-admin, so have different classes applied so that they match the standard WordPress notice format. */ ?> <?php if ( $type === 'plugin' ) : ?> <?php // Displayed on edit-comments.php to users who have not set up Akismet yet. ?> <div class="updated" id="akismet-setup-prompt"> <form name="akismet_activate" action="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>" method="post"> <div class="akismet-activate"> <input type="submit" class="akismet-activate__button akismet-button" value="<?php esc_attr_e( 'Set up your Akismet account', 'akismet' ); ?>" /> <div class="akismet-activate__description"> <?php esc_html_e( 'Almost done! Configure Akismet and say goodbye to spam', 'akismet' ); ?> </div> </div> </form> </div> <?php elseif ( $type === 'spam-check' ) : ?> <?php // This notice is only displayed on edit-comments.php. ?> <div class="notice notice-warning"> <p><strong><?php esc_html_e( 'Akismet has detected a problem.', 'akismet' ); ?></strong></p> <p><?php esc_html_e( 'Some comments have not yet been checked for spam by Akismet. They have been temporarily held for moderation and will automatically be rechecked later.', 'akismet' ); ?></p> <?php if ( ! empty( $link_text ) ) : ?> <p><?php echo wp_kses( $link_text, $kses_allow_link ); ?></p> <?php endif; ?> </div> <?php elseif ( $type === 'spam-check-cron-disabled' ) : ?> <?php // This notice is only displayed on edit-comments.php. ?> <div class="notice notice-warning"> <p><strong><?php esc_html_e( 'Akismet has detected a problem.', 'akismet' ); ?></strong></p> <p><?php esc_html_e( 'WP-Cron has been disabled using the DISABLE_WP_CRON constant. Comment rechecks may not work properly.', 'akismet' ); ?></p> </div> <?php elseif ( $type === 'alert' && $code === Akismet::ALERT_CODE_COMMERCIAL && isset( $parent_view ) && $parent_view === 'config' ) : ?> <?php // Display a different commercial warning alert on the config page ?> <div class="akismet-card akismet-alert is-commercial"> <div> <h3 class="akismet-alert-header"><?php esc_html_e( 'We detected commercial activity on your site', 'akismet' ); ?></h3> <p class="akismet-alert-info"> <?php /* translators: The placeholder is a URL. */ echo wp_kses( sprintf( __( 'Your current subscription is for <a class="akismet-external-link" href="%s">personal, non-commercial use</a>. Please upgrade your plan to continue using Akismet.', 'akismet' ), esc_url( 'https://akismet.com/support/getting-started/free-or-paid/?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=commercial_support' ) ), $kses_allow_link ); ?> </p> <p class="akismet-alert-info"> <?php /* translators: The placeholder is a URL to the contact form. */ echo wp_kses( sprintf( __( 'If you believe your site should not be classified as commercial, <a class="akismet-external-link" href="%s">please get in touch</a>', 'akismet' ), esc_url( 'https://akismet.com/contact/?purpose=commercial&utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=commercial_contact' ) ), $kses_allow_link ); ?> </p> </div> <div class="akismet-alert-button-wrapper"> <?php Akismet::view( 'get', array( 'text' => __( 'Upgrade plan', 'akismet' ), 'classes' => array( 'akismet-alert-button', 'akismet-button' ), 'redirect' => 'upgrade', 'utm_content' => 'commercial_upgrade', ) ); ?> </div> </div> <?php elseif ( $type === 'alert' ) : ?> <div class="<?php echo isset( $parent_view ) && $parent_view === 'config' ? 'akismet-alert is-bad' : 'error'; ?>"> <?php /* translators: The placeholder is an error code returned by Akismet. */ ?> <p><strong><?php printf( esc_html__( 'Akismet error code: %s', 'akismet' ), esc_html( $code ) ); ?></strong></p> <p><?php echo isset( $msg ) ? esc_html( $msg ) : ''; ?></p> <p> <?php echo wp_kses( sprintf( /* translators: the placeholder is a clickable URL that leads to more information regarding an error code. */ __( 'For more information, see the <a class="akismet-external-link" href="%s">error documentation on akismet.com</a>', 'akismet' ), esc_url( 'https://akismet.com/developers/detailed-docs/errors/akismet-error-' . absint( $code ) . '?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=error_info' ) ), $kses_allow_link ); ?> </p> </div> <?php elseif ( $type === 'notice' ) : ?> <div class="akismet-alert is-bad"> <h3 class="akismet-alert__heading"><?php echo wp_kses( $notice_header, Akismet_Admin::get_notice_kses_allowed_elements() ); ?></h3> <p> <?php echo wp_kses( $notice_text, Akismet_Admin::get_notice_kses_allowed_elements() ); ?> </p> </div> <?php elseif ( $type === 'missing-functions' ) : ?> <div class="akismet-alert is-bad"> <h3 class="akismet-alert__heading"><?php esc_html_e( 'Network functions are disabled.', 'akismet' ); ?></h3> <p> <?php echo wp_kses( __( 'Your web host or server administrator has disabled PHP’s <code>gethostbynamel</code> function.', 'akismet' ), array_merge( $kses_allow_link, $kses_allow_strong, array( 'code' => true ) ) ); ?> </p> <p> <?php /* translators: The placeholder is a URL. */ echo wp_kses( sprintf( __( 'Please contact your web host or firewall administrator and give them <a class="akismet-external-link" href="%s" target="_blank">this information about Akismet’s system requirements</a>', 'akismet' ), esc_url( 'https://akismet.com/akismet-hosting-faq/?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=hosting_faq_php' ) ), array_merge( $kses_allow_link, $kses_allow_strong, array( 'code' => true ) ) ); ?> </p> </div> <?php elseif ( $type === 'servers-be-down' ) : ?> <div class="akismet-alert is-bad"> <h3 class="akismet-alert__heading"><?php esc_html_e( 'Your site can’t connect to the Akismet servers.', 'akismet' ); ?></h3> <p> <?php /* translators: The placeholder is a URL. */ echo wp_kses( sprintf( __( 'Your firewall may be blocking Akismet from connecting to its API. Please contact your host and refer to <a class="akismet-external-link" href="%s" target="_blank">our guide about firewalls</a>', 'akismet' ), esc_url( 'https://akismet.com/akismet-hosting-faq/?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=hosting_faq_firewall' ) ), $kses_allow_link ); ?> </p> </div> <?php elseif ( $type === 'active-dunning' ) : ?> <div class="akismet-alert is-bad"> <h3 class="akismet-alert__heading"><?php esc_html_e( 'Please update your payment information.', 'akismet' ); ?></h3> <p> <?php /* translators: The placeholder is a URL. */ echo wp_kses( sprintf( __( 'We cannot process your payment. Please <a class="akismet-external-link" href="%s" target="_blank">update your payment details</a>', 'akismet' ), esc_url( 'https://wordpress.com/me/purchases/payment-methods?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=payment_update' ) ), $kses_allow_link ); ?> </p> </div> <?php elseif ( $type === 'cancelled' ) : ?> <div class="akismet-alert is-bad"> <h3 class="akismet-alert__heading"><?php esc_html_e( 'Your Akismet plan has been cancelled.', 'akismet' ); ?></h3> <p> <?php /* translators: The placeholder is a URL. */ echo wp_kses( sprintf( __( 'Please visit <a class="akismet-external-link" href="%s" target="_blank">Akismet.com</a> to purchase a new subscription.', 'akismet' ), esc_url( 'https://akismet.com/pricing/?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=pricing_cancelled' ) ), $kses_allow_link ); ?> </p> </div> <?php elseif ( $type === 'suspended' ) : ?> <div class="akismet-alert is-bad"> <h3 class="akismet-alert__heading"><?php esc_html_e( 'Your Akismet subscription is suspended.', 'akismet' ); ?></h3> <p> <?php /* translators: The placeholder is a URL. */ echo wp_kses( sprintf( __( 'Please contact <a class="akismet-external-link" href="%s" target="_blank">Akismet support</a> for assistance.', 'akismet' ), esc_url( 'https://akismet.com/contact/?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=support_suspended' ) ), $kses_allow_link ); ?> </p> </div> <?php elseif ( $type === 'active-notice' && $time_saved ) : ?> <div class="akismet-alert is-neutral"> <h3 class="akismet-alert__heading"><?php echo esc_html( $time_saved ); ?></h3> <p> <?php /* translators: the placeholder is a clickable URL to the Akismet account upgrade page. */ echo wp_kses( sprintf( __( 'You can help us fight spam and upgrade your account by <a class="akismet-external-link" href="%s" target="_blank">contributing a token amount</a>', 'akismet' ), esc_url( 'https://akismet.com/pricing?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=upgrade_contribution' ) ), $kses_allow_link ); ?> </p> </div> <?php elseif ( $type === 'missing' ) : ?> <div class="akismet-alert is-bad"> <h3 class="akismet-alert__heading"><?php esc_html_e( 'There is a problem with your API key.', 'akismet' ); ?></h3> <p> <?php /* translators: The placeholder is a URL to the Akismet contact form. */ echo wp_kses( sprintf( __( 'Please contact <a class="akismet-external-link" href="%s" target="_blank">Akismet support</a> for assistance.', 'akismet' ), esc_url( 'https://akismet.com/contact/?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=support_missing' ) ), $kses_allow_link ); ?> </p> </div> <?php elseif ( $type === 'no-sub' ) : ?> <div class="akismet-alert is-bad"> <h3 class="akismet-alert__heading"><?php esc_html_e( 'You don’t have an Akismet plan.', 'akismet' ); ?></h3> <p> <?php /* translators: the placeholder is the URL to the Akismet pricing page. */ echo wp_kses( sprintf( __( 'Please <a class="akismet-external-link" href="%s" target="_blank">choose a free or paid plan</a> so Akismet can protect your site from spam.', 'akismet' ), esc_url( 'https://akismet.com/pricing?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=choose_plan' ) ), $kses_allow_link ); ?> </p> <p><?php echo esc_html__( 'Once you\'ve chosen a plan, return here to complete your setup.', 'akismet' ); ?></p> </div> <?php elseif ( $type === 'new-key-valid' ) : ?> <?php global $wpdb; $check_pending_link = false; $at_least_one_comment_in_moderation = ! ! $wpdb->get_var( "SELECT comment_ID FROM {$wpdb->comments} WHERE comment_approved = '0' LIMIT 1" ); if ( $at_least_one_comment_in_moderation ) { $check_pending_link = 'edit-comments.php?akismet_recheck=' . wp_create_nonce( 'akismet_recheck' ); } ?> <div class="akismet-alert is-good"> <p><?php esc_html_e( 'Akismet is now protecting your site from spam.', 'akismet' ); ?></p> <?php if ( $check_pending_link ) : ?> <p> <?php echo wp_kses( sprintf( /* translators: The placeholder is a URL for checking pending comments. */ __( 'Would you like to <a href="%s">check pending comments</a>?', 'akismet' ), esc_url( $check_pending_link ) ), $kses_allow_link ); ?> </p> <?php endif; ?> </div> <?php elseif ( $type === 'new-key-invalid' ) : ?> <div class="akismet-alert is-bad"> <p><?php esc_html_e( 'The key you entered is invalid. Please double-check it.', 'akismet' ); ?></p> </div> <?php elseif ( $type === Akismet_Admin::NOTICE_EXISTING_KEY_INVALID ) : ?> <div class="akismet-alert is-bad"> <h3 class="akismet-alert__heading"><?php echo esc_html( __( 'Your API key is no longer valid.', 'akismet' ) ); ?></h3> <p> <?php echo wp_kses( sprintf( /* translators: The placeholder is a URL to the Akismet contact form. */ __( 'Please enter a new key or <a class="akismet-external-link" href="%s" target="_blank">contact Akismet support</a>', 'akismet' ), 'https://akismet.com/contact/?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=support_invalid_key' ), $kses_allow_link ); ?> </p> </div> <?php elseif ( $type === 'new-key-failed' ) : ?> <div class="akismet-alert is-bad"> <h3 class="akismet-alert__heading"><?php esc_html_e( 'The API key you entered could not be verified.', 'akismet' ); ?></h3> <p> <?php echo wp_kses( sprintf( /* translators: The placeholder is a URL. */ __( 'The connection to akismet.com could not be established. Please refer to <a class="akismet-external-link" href="%s" target="_blank">our guide about firewalls</a> and check your server configuration.', 'akismet' ), 'https://akismet.com/akismet-hosting-faq/?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=hosting_faq' ), $kses_allow_link ); ?> </p> </div> <?php elseif ( $type === 'usage-limit' && isset( Akismet::$limit_notices[ $code ] ) ) : ?> <div class="error akismet-usage-limit-alert"> <div class="akismet-usage-limit-logo"> <img src="<?php echo esc_url( plugins_url( '../_inc/img/logo-a-2x.png', __FILE__ ) ); ?>" alt="Akismet logo" /> </div> <div class="akismet-usage-limit-text"> <h3> <?php switch ( Akismet::$limit_notices[ $code ] ) { case 'FIRST_MONTH_OVER_LIMIT': case 'SECOND_MONTH_OVER_LIMIT': esc_html_e( 'Your Akismet account usage is over your plan’s limit', 'akismet' ); break; case 'THIRD_MONTH_APPROACHING_LIMIT': esc_html_e( 'Your Akismet account usage is approaching your plan’s limit', 'akismet' ); break; case 'THIRD_MONTH_OVER_LIMIT': case 'FOUR_PLUS_MONTHS_OVER_LIMIT': esc_html_e( 'Your account has been restricted', 'akismet' ); break; default: } ?> </h3> <p> <?php switch ( Akismet::$limit_notices[ $code ] ) { case 'FIRST_MONTH_OVER_LIMIT': echo esc_html( sprintf( /* translators: The first placeholder is a date, the second is a (formatted) number, the third is another formatted number. */ __( 'Since %1$s, your account made %2$s API calls, compared to your plan’s limit of %3$s.', 'akismet' ), esc_html( gmdate( 'F' ) . ' 1' ), number_format( $api_calls ), number_format( $usage_limit ) ) ); echo ' '; echo '<a class="akismet-external-link" href="https://akismet.com/support/general/akismet-api-usage-limits/?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=usage_limit_docs" target="_blank">'; echo esc_html( __( 'Learn more about usage limits', 'akismet' ) ); echo '</a>'; break; case 'SECOND_MONTH_OVER_LIMIT': echo esc_html( __( 'Your Akismet usage has been over your plan’s limit for two consecutive months. Next month, we will restrict your account after you reach the limit. Increase your limit to make sure your site stays protected from spam.', 'akismet' ) ); echo ' '; echo '<a class="akismet-external-link" href="https://akismet.com/support/general/akismet-api-usage-limits/?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=usage_limit_docs" target="_blank">'; echo esc_html( __( 'Learn more about usage limits', 'akismet' ) ); echo '</a>'; break; case 'THIRD_MONTH_APPROACHING_LIMIT': echo esc_html( __( 'Your Akismet usage is nearing your plan’s limit for the third consecutive month. We will restrict your account after you reach the limit. Increase your limit to make sure your site stays protected from spam.', 'akismet' ) ); echo ' '; echo '<a class="akismet-external-link" href="https://akismet.com/support/general/akismet-api-usage-limits/?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=usage_limit_docs" target="_blank">'; echo esc_html( __( 'Learn more about usage limits', 'akismet' ) ); echo '</a>'; break; case 'THIRD_MONTH_OVER_LIMIT': case 'FOUR_PLUS_MONTHS_OVER_LIMIT': echo esc_html( __( 'Your Akismet usage has been over your plan’s limit for three consecutive months. We have restricted your account for the rest of the month. Increase your limit to make sure your site stays protected from spam.', 'akismet' ) ); echo ' '; echo '<a class="akismet-external-link" href="https://akismet.com/support/general/akismet-api-usage-limits/?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=usage_limit_docs" target="_blank">'; echo esc_html( __( 'Learn more about usage limits', 'akismet' ) ); echo '</a>'; break; default: } ?> </p> </div> <div class="akismet-usage-limit-cta"> <a href="<?php echo esc_attr( $upgrade_url . ( strpos( $upgrade_url, '?' ) !== false ? '&' : '?' ) . 'utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=usage_limit_upgrade' ); ?>" class="button" target="_blank"> <?php if ( isset( $upgrade_via_support ) && $upgrade_via_support ) { // Direct user to contact support. esc_html_e( 'Contact Akismet support', 'akismet' ); } elseif ( ! empty( $upgrade_type ) && 'qty' === $upgrade_type ) { // If a qty upgrade is required, use recommended plan name if available. if ( ! empty( $recommended_plan_name ) && is_string( $recommended_plan_name ) ) { echo esc_html( sprintf( /* translators: The placeholder is the name of an Akismet subscription plan, like "Akismet Pro" or "Akismet Business" . */ __( 'Add an %s subscription', 'akismet' ), $recommended_plan_name ) ); } else { esc_html_e( 'Increase your limit', 'akismet' ); } } else { echo esc_html( sprintf( /* translators: The placeholder is the name of a subscription level, like "Akismet Business" or "Akismet Enterprise" . */ __( 'Upgrade to %s', 'akismet' ), $upgrade_plan ) ); } ?> </a> </div> </div> <?php endif; ?> views/setup-jetpack.php 0000777 00000010366 15251466723 0011221 0 ustar 00 <?php declare( strict_types = 1 ); //phpcs:disable VariableAnalysis // There are "undefined" variables here because they're defined in the code that includes this file as a template. $user_status = $akismet_user->status ?? null; ?> <div class="akismet-setup__connection"> <?php if ( ! empty( $akismet_user->user_email ) && ! empty( $akismet_user->user_login ) ) : ?> <div class="akismet-setup__connection-user"> <div class="akismet-setup__connection-avatar"> <?php // Decorative avatar; empty alt for screen readers. echo get_avatar( $akismet_user->user_email, 48, '', '', array( 'class' => 'akismet-setup__connection-avatar-image', 'alt' => '', ) ); ?> <div class="akismet-setup__connection-account"> <div class="akismet-setup__connection-account-name"> <?php printf( /* translators: %s is the WordPress.com username */ esc_html__( 'Signed in as %s', 'akismet' ), '<strong>' . esc_html( $akismet_user->user_login ) . '</strong>' ); ?> </div> <div class="akismet-setup__connection-account-email"><?php echo esc_html( $akismet_user->user_email ); ?></div> </div> </div> </div> <?php endif; ?> <div class="akismet-setup__connection-action"> <?php if ( in_array( $user_status, array( Akismet::USER_STATUS_CANCELLED, Akismet::USER_STATUS_MISSING, Akismet::USER_STATUS_NO_SUB ) ) ) : ?> <p class="akismet-setup__connection-action-intro"> <?php esc_html_e( "Your Jetpack account is connected, but it doesn't have an active Akismet subscription yet. To continue, please choose a plan on Akismet.com.", 'akismet' ); ?> </p> <a href="https://akismet.com/get?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=jetpack_flow_<?php echo esc_attr( str_replace( '-', '_', $user_status ) ); ?>" class="akismet-setup__connection-button akismet-button"> <?php esc_html_e( 'Choose a plan on Akismet.com', 'akismet' ); ?> </a> <p class="akismet-setup__connection-action-description"> <?php esc_html_e( "Once you've chosen a plan, return here to complete your setup.", 'akismet' ); ?> </p> <?php elseif ( $user_status === Akismet::USER_STATUS_SUSPENDED ) : ?> <p class="akismet-setup__connection-action-intro"> <?php esc_html_e( "Your Akismet account appears to be suspended. This sometimes happens if there's a billing or verification issue. Please contact our support team so we can help you get it sorted.", 'akismet' ); ?> </p> <a href="https://akismet.com/contact?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=jetpack_flow_suspended" class="akismet-setup__connection-button akismet-button"> <?php esc_html_e( 'Contact support', 'akismet' ); ?> </a> <?php else : ?> <form name="akismet_use_wpcom_key" action="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>" method="post" id="akismet-activate"> <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-setup__connection-button akismet-button" value="<?php esc_attr_e( 'Connect with Jetpack', 'akismet' ); ?>"/> </form> <p class="akismet-setup__connection-action-description"> <?php esc_html_e( "By connecting, we'll use your Jetpack account to activate Akismet on this site.", 'akismet' ); ?> </p> <?php endif; ?> <?php if ( ! in_array( $user_status, array( Akismet::USER_STATUS_CANCELLED, Akismet::USER_STATUS_MISSING, Akismet::USER_STATUS_NO_SUB ) ) ) : ?> <p class="akismet-setup__connection-action-description"> <?php echo wp_kses( sprintf( /* translators: The placeholder is a URL. */ __( 'Want to use a different account? <a href="%s" class="akismet-external-link">Visit akismet.com</a> to set it up and get your API key.', 'akismet' ), esc_url( 'https://akismet.com/get?utm_source=akismet_plugin&utm_campaign=plugin_static_link&utm_medium=in_plugin&utm_content=jetpack_flow_different_account' ) ), array( 'a' => array( 'href' => array(), 'class' => array(), ), ) ); ?> </p> <?php endif; ?> </div> </div> views/get.php 0000777 00000002371 15251466723 0007216 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. $submit_classes_attr = 'akismet-button'; if ( isset( $classes ) && ( is_countable( $classes ) ? count( $classes ) : 0 ) > 0 ) { $submit_classes_attr = implode( ' ', $classes ); } $query_args = array( 'passback_url' => Akismet_Admin::get_page_url(), 'redirect' => isset( $redirect ) ? $redirect : 'plugin-signup', ); // Set default UTM parameters, overriding with any provided values. $utm_args = array( 'utm_source' => isset( $utm_source ) ? $utm_source : 'akismet_plugin', 'utm_medium' => isset( $utm_medium ) ? $utm_medium : 'in_plugin', 'utm_campaign' => isset( $utm_campaign ) ? $utm_campaign : 'plugin_static_link', 'utm_content' => isset( $utm_content ) ? $utm_content : 'get_view_link', ); $query_args = array_merge( $query_args, $utm_args ); $url = add_query_arg( $query_args, 'https://akismet.com/get/' ); ?> <a href="<?php echo esc_url( $url ); ?>" class="<?php echo esc_attr( $submit_classes_attr ); ?>" target="_blank"> <?php echo esc_html( is_string( $text ) ? $text : '' ); ?> <span class="screen-reader-text"><?php esc_html_e( '(opens in a new tab)', 'akismet' ); ?></span> </a> views/enter.php 0000777 00000002024 15251466723 0007547 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> views/predefined.php 0000777 00000000470 15251466723 0010542 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>