This commit is contained in:
emmymayo
2025-02-05 23:15:46 +01:00
commit 7269c99357
16995 changed files with 3389680 additions and 0 deletions
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
DENY FROM ALL
+1
View File
@@ -0,0 +1 @@
<?php // Silence is gold. ?>
+58
View File
@@ -0,0 +1,58 @@
<?php
/**
* Plugin Name: SQLite integration (Drop-in)
* Version: 1.0.0
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
*
* This file is auto-generated and copied from the sqlite plugin.
* Please don't edit this file directly.
*
* @package wp-sqlite-integration
*/
define( 'SQLITE_DB_DROPIN_VERSION', '1.8.0' );
// Tweak to allow copy-pasting the file without having to run string-replacements.
$sqlite_plugin_implementation_folder_path = realpath( __DIR__ . '/mu-plugins/sqlite-database-integration' );
if ( ! file_exists( $sqlite_plugin_implementation_folder_path ) ) { // Check that the folder exists.
$sqlite_plugin_implementation_folder_path = realpath( __DIR__ . '/plugins/sqlite-database-integration' );
}
// Bail early if the SQLite implementation was not located in the plugin.
if ( ! $sqlite_plugin_implementation_folder_path || ! file_exists( $sqlite_plugin_implementation_folder_path . '/wp-includes/sqlite/db.php' ) ) {
return;
}
// Constant for backward compatibility.
if ( ! defined( 'DATABASE_TYPE' ) ) {
define( 'DATABASE_TYPE', 'sqlite' );
}
// Define SQLite constant.
if ( ! defined( 'DB_ENGINE' ) ) {
define( 'DB_ENGINE', 'sqlite' );
}
// Require the implementation from the plugin.
require_once $sqlite_plugin_implementation_folder_path . '/wp-includes/sqlite/db.php';
// Activate the performance-lab plugin if it is not already activated.
add_action(
'admin_footer',
function() {
if ( defined( 'SQLITE_MAIN_FILE' ) ) {
return;
}
if ( ! function_exists( 'activate_plugin' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
if ( is_plugin_inactive( '{SQLITE_PLUGIN}' ) ) {
// If `activate_plugin()` returns a value other than null (like WP_Error),
// the plugin could not be found. Try with a hardcoded string,
// because that probably means the file was directly copy-pasted.
if ( null !== activate_plugin( '{SQLITE_PLUGIN}', '', false, true ) ) {
activate_plugin( 'sqlite-database-integration/load.php', '', false, true );
}
}
}
);
+113
View File
@@ -0,0 +1,113 @@
[05-Feb-2025 21:15:48 UTC] WordPress database error <div style="clear:both">&nbsp;</div>
<div class="queries" style="clear:both;margin-bottom:2px;border:red dotted thin;">
<p>MySQL query:</p>
<p>
ALTER TABLE `wp_mailpoet_statistics_clicks`
DROP INDEX `newsletter_id_subscriber_id`
</p>
<p>Queries made or created this session were:</p>
<ol>
<li>Executing: BEGIN | (no parameters)</li>
<li>Executing: DROP INDEX &quot;wp_mailpoet_statistics_clicks__newsletter_id_subscriber_id&quot;
| (no parameters)</li>
<li>Executing: ROLLBACK | (no parameters)</li>
</ol>
</div>
<div style="clear:both;margin-bottom:2px;border:red dotted thin;" class="error_message" style="border-bottom:dotted blue thin;">
Error occurred at line 4164 in Function <code>handle_error</code>. Error message was: SQLSTATE[HY000]: General error: 1 no such index: wp_mailpoet_statistics_clicks__newsletter_id_subscriber_id.
</div>
<p>Backtrace:</p>
<pre>#0 /var/www/html/wp-content/mu-plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-db.php(287): WP_SQLite_Translator->get_error_message()
#1 /var/www/html/wp-content/plugins/mailpoet/lib/Migrations/Db/Migration_20221028_105818.php(720): WP_SQLite_DB->query('\n ALTE...')
#2 /var/www/html/wp-content/plugins/mailpoet/lib/Migrations/Db/Migration_20221028_105818.php(90): MailPoet\Migrations\Db\Migration_20221028_105818->removeDeprecatedStatisticsIndexes()
#3 /var/www/html/wp-content/plugins/mailpoet/lib/Migrator/Runner.php(35): MailPoet\Migrations\Db\Migration_20221028_105818->run()
#4 /var/www/html/wp-content/plugins/mailpoet/lib/Migrator/Migrator.php(53): MailPoet\Migrator\Runner->runMigration('Migration_20221...', 'db')
#5 /var/www/html/wp-content/plugins/mailpoet/lib/Config/Activator.php(78): MailPoet\Migrator\Migrator->run()
#6 /var/www/html/wp-content/plugins/mailpoet/lib/Config/Activator.php(60): MailPoet\Config\Activator->processActivate()
#7 /var/www/html/wp-content/plugins/mailpoet/lib/Config/Initializer.php(313): MailPoet\Config\Activator->activate()
#8 /var/www/html/wp-includes/class-wp-hook.php(324): MailPoet\Config\Initializer->runActivator(false)
#9 /var/www/html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#10 /var/www/html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#11 /var/www/html/wp-admin/includes/plugin.php(703): do_action('activate_mailpo...', false)
#12 /var/www/html/wp-content/plugins/woocommerce/src/Admin/PluginsHelper.php(465): activate_plugin('mailpoet/mailpo...')
#13 /var/www/html/wp-content/plugins/woocommerce/src/Admin/PluginsHelper.php(389): Automattic\WooCommerce\Admin\PluginsHelper::activate_plugins(Array, Object(Automattic\WooCommerce\Admin\PluginsInstallLoggers\AsyncPluginsInstallLogger))
#14 /var/www/html/wp-includes/class-wp-hook.php(324): Automattic\WooCommerce\Admin\PluginsHelper::install_and_activate_plugins_async_callback(Array, '67a3d3efb9ca8')
#15 /var/www/html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#16 /var/www/html/wp-includes/plugin.php(565): WP_Hook->do_action(Array)
#17 /var/www/html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/actions/ActionScheduler_Action.php(86): do_action_ref_array('woocommerce_plu...', Array)
#18 /var/www/html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php(102): ActionScheduler_Action->execute()
#19 /var/www/html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_QueueRunner.php(188): ActionScheduler_Abstract_QueueRunner->process_action(11, 'Async Request')
#20 /var/www/html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_QueueRunner.php(158): ActionScheduler_QueueRunner->do_batch(25, 'Async Request')
#21 /var/www/html/wp-includes/class-wp-hook.php(324): ActionScheduler_QueueRunner->run('Async Request')
#22 /var/www/html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#23 /var/www/html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#24 /var/www/html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_AsyncRequest_QueueRunner.php(48): do_action('action_schedule...', 'Async Request')
#25 /var/www/html/wp-content/plugins/woocommerce/includes/libraries/wp-async-request.php(147): ActionScheduler_AsyncRequest_QueueRunner->handle()
#26 /var/www/html/wp-includes/class-wp-hook.php(324): WP_Async_Request->maybe_handle('')
#27 /var/www/html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#28 /var/www/html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#29 /var/www/html/wp-admin/admin-ajax.php(192): do_action('wp_ajax_as_asyn...')
#30 {main}</pre>
for query
ALTER TABLE `wp_mailpoet_statistics_clicks`
DROP INDEX `newsletter_id_subscriber_id`
made by do_action('wp_ajax_as_async_request_queue_runner'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Request->maybe_handle, ActionScheduler_AsyncRequest_QueueRunner->handle, do_action('action_scheduler_run_queue'), WP_Hook->do_action, WP_Hook->apply_filters, ActionScheduler_QueueRunner->run, ActionScheduler_QueueRunner->do_batch, ActionScheduler_Abstract_QueueRunner->process_action, ActionScheduler_Action->execute, do_action_ref_array('woocommerce_plugins_install_and_activate_async_callback'), WP_Hook->do_action, WP_Hook->apply_filters, Automattic\WooCommerce\Admin\PluginsHelper::install_and_activate_plugins_async_callback, Automattic\WooCommerce\Admin\PluginsHelper::activate_plugins, activate_plugin, do_action('activate_mailpoet/mailpoet.php'), WP_Hook->do_action, WP_Hook->apply_filters, MailPoet\Config\Initializer->runActivator, MailPoet\Config\Activator->activate, MailPoet\Config\Activator->processActivate, MailPoet\Migrator\Migrator->run, MailPoet\Migrator\Runner->runMigration, MailPoet\Migrations\Db\Migration_20221028_105818->run, MailPoet\Migrations\Db\Migration_20221028_105818->removeDeprecatedStatisticsIndexes, WP_SQLite_DB->query, WP_SQLite_DB->print_error
[05-Feb-2025 21:15:48 UTC] WordPress database error <div style="clear:both">&nbsp;</div>
<div class="queries" style="clear:both;margin-bottom:2px;border:red dotted thin;">
<p>MySQL query:</p>
<p>
ALTER TABLE `wp_mailpoet_statistics_opens`
DROP INDEX `newsletter_id_subscriber_id`
</p>
<p>Queries made or created this session were:</p>
<ol>
<li>Executing: BEGIN | (no parameters)</li>
<li>Executing: DROP INDEX &quot;wp_mailpoet_statistics_opens__newsletter_id_subscriber_id&quot;
| (no parameters)</li>
<li>Executing: ROLLBACK | (no parameters)</li>
</ol>
</div>
<div style="clear:both;margin-bottom:2px;border:red dotted thin;" class="error_message" style="border-bottom:dotted blue thin;">
Error occurred at line 4164 in Function <code>handle_error</code>. Error message was: SQLSTATE[HY000]: General error: 1 no such index: wp_mailpoet_statistics_opens__newsletter_id_subscriber_id.
</div>
<p>Backtrace:</p>
<pre>#0 /var/www/html/wp-content/mu-plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-db.php(287): WP_SQLite_Translator->get_error_message()
#1 /var/www/html/wp-content/plugins/mailpoet/lib/Migrations/Db/Migration_20221028_105818.php(720): WP_SQLite_DB->query('\n ALTE...')
#2 /var/www/html/wp-content/plugins/mailpoet/lib/Migrations/Db/Migration_20221028_105818.php(90): MailPoet\Migrations\Db\Migration_20221028_105818->removeDeprecatedStatisticsIndexes()
#3 /var/www/html/wp-content/plugins/mailpoet/lib/Migrator/Runner.php(35): MailPoet\Migrations\Db\Migration_20221028_105818->run()
#4 /var/www/html/wp-content/plugins/mailpoet/lib/Migrator/Migrator.php(53): MailPoet\Migrator\Runner->runMigration('Migration_20221...', 'db')
#5 /var/www/html/wp-content/plugins/mailpoet/lib/Config/Activator.php(78): MailPoet\Migrator\Migrator->run()
#6 /var/www/html/wp-content/plugins/mailpoet/lib/Config/Activator.php(60): MailPoet\Config\Activator->processActivate()
#7 /var/www/html/wp-content/plugins/mailpoet/lib/Config/Initializer.php(313): MailPoet\Config\Activator->activate()
#8 /var/www/html/wp-includes/class-wp-hook.php(324): MailPoet\Config\Initializer->runActivator(false)
#9 /var/www/html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#10 /var/www/html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#11 /var/www/html/wp-admin/includes/plugin.php(703): do_action('activate_mailpo...', false)
#12 /var/www/html/wp-content/plugins/woocommerce/src/Admin/PluginsHelper.php(465): activate_plugin('mailpoet/mailpo...')
#13 /var/www/html/wp-content/plugins/woocommerce/src/Admin/PluginsHelper.php(389): Automattic\WooCommerce\Admin\PluginsHelper::activate_plugins(Array, Object(Automattic\WooCommerce\Admin\PluginsInstallLoggers\AsyncPluginsInstallLogger))
#14 /var/www/html/wp-includes/class-wp-hook.php(324): Automattic\WooCommerce\Admin\PluginsHelper::install_and_activate_plugins_async_callback(Array, '67a3d3efb9ca8')
#15 /var/www/html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#16 /var/www/html/wp-includes/plugin.php(565): WP_Hook->do_action(Array)
#17 /var/www/html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/actions/ActionScheduler_Action.php(86): do_action_ref_array('woocommerce_plu...', Array)
#18 /var/www/html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php(102): ActionScheduler_Action->execute()
#19 /var/www/html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_QueueRunner.php(188): ActionScheduler_Abstract_QueueRunner->process_action(11, 'Async Request')
#20 /var/www/html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_QueueRunner.php(158): ActionScheduler_QueueRunner->do_batch(25, 'Async Request')
#21 /var/www/html/wp-includes/class-wp-hook.php(324): ActionScheduler_QueueRunner->run('Async Request')
#22 /var/www/html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#23 /var/www/html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#24 /var/www/html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_AsyncRequest_QueueRunner.php(48): do_action('action_schedule...', 'Async Request')
#25 /var/www/html/wp-content/plugins/woocommerce/includes/libraries/wp-async-request.php(147): ActionScheduler_AsyncRequest_QueueRunner->handle()
#26 /var/www/html/wp-includes/class-wp-hook.php(324): WP_Async_Request->maybe_handle('')
#27 /var/www/html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#28 /var/www/html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#29 /var/www/html/wp-admin/admin-ajax.php(192): do_action('wp_ajax_as_asyn...')
#30 {main}</pre>
for query
ALTER TABLE `wp_mailpoet_statistics_opens`
DROP INDEX `newsletter_id_subscriber_id`
made by do_action('wp_ajax_as_async_request_queue_runner'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Request->maybe_handle, ActionScheduler_AsyncRequest_QueueRunner->handle, do_action('action_scheduler_run_queue'), WP_Hook->do_action, WP_Hook->apply_filters, ActionScheduler_QueueRunner->run, ActionScheduler_QueueRunner->do_batch, ActionScheduler_Abstract_QueueRunner->process_action, ActionScheduler_Action->execute, do_action_ref_array('woocommerce_plugins_install_and_activate_async_callback'), WP_Hook->do_action, WP_Hook->apply_filters, Automattic\WooCommerce\Admin\PluginsHelper::install_and_activate_plugins_async_callback, Automattic\WooCommerce\Admin\PluginsHelper::activate_plugins, activate_plugin, do_action('activate_mailpoet/mailpoet.php'), WP_Hook->do_action, WP_Hook->apply_filters, MailPoet\Config\Initializer->runActivator, MailPoet\Config\Activator->activate, MailPoet\Config\Activator->processActivate, MailPoet\Migrator\Migrator->run, MailPoet\Migrator\Runner->runMigration, MailPoet\Migrations\Db\Migration_20221028_105818->run, MailPoet\Migrations\Db\Migration_20221028_105818->removeDeprecatedStatisticsIndexes, WP_SQLite_DB->query, WP_SQLite_DB->print_error
[05-Feb-2025 21:16:38 UTC] PHP Warning: dns_get_record(): dns_get_record() always returns an empty array in PHP.wasm. in /var/www/html/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-status/src/class-host.php on line 149
[05-Feb-2025 21:17:05 UTC] PHP Warning: dns_get_record(): dns_get_record() always returns an empty array in PHP.wasm. in /var/www/html/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-status/src/class-host.php on line 149
[05-Feb-2025 21:29:20 UTC] PHP Warning: dns_get_record(): dns_get_record() always returns an empty array in PHP.wasm. in /var/www/html/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-status/src/class-host.php on line 149
[05-Feb-2025 21:29:45 UTC] PHP Warning: dns_get_record(): dns_get_record() always returns an empty array in PHP.wasm. in /var/www/html/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-status/src/class-host.php on line 149
[05-Feb-2025 21:30:01 UTC] PHP Warning: dns_get_record(): dns_get_record() always returns an empty array in PHP.wasm. in /var/www/html/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-status/src/class-host.php on line 149
+2
View File
@@ -0,0 +1,2 @@
<?php
// Silence is golden.
+11
View File
@@ -0,0 +1,11 @@
<?php
define( 'DISABLE_JETPACK_WAF', false );
if ( defined( 'DISABLE_JETPACK_WAF' ) && DISABLE_JETPACK_WAF ) return;
define( 'JETPACK_WAF_MODE', 'silent' );
define( 'JETPACK_WAF_SHARE_DATA', false );
define( 'JETPACK_WAF_SHARE_DEBUG_DATA', false );
define( 'JETPACK_WAF_DIR', '/var/www/html/wp-content/jetpack-waf' );
define( 'JETPACK_WAF_WPCONFIG', '/var/www/html/wp-content/../wp-config.php' );
define( 'JETPACK_WAF_ENTRYPOINT', 'rules/rules.php' );
require_once '/var/www/html/wp-content/plugins/jetpack/vendor/autoload.php';
Automattic\Jetpack\Waf\Waf_Runner::initialize();
@@ -0,0 +1,4 @@
<?php
$waf_allow_list = array (
);
return $waf->is_ip_in_array( $waf_allow_list );
@@ -0,0 +1 @@
<?php
@@ -0,0 +1,4 @@
<?php
$waf_block_list = array (
);
return $waf->is_ip_in_array( $waf_block_list );
+1
View File
@@ -0,0 +1 @@
<?php
@@ -0,0 +1,339 @@
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.
@@ -0,0 +1,112 @@
<?php
/**
* Handle the SQLite activation.
*
* @since 1.0.0
* @package wp-sqlite-integration
*/
/**
* Redirect to the plugin's admin screen on activation.
*
* @since 1.0.0
*
* @param string $plugin The plugin basename.
*/
function sqlite_plugin_activation_redirect( $plugin ) {
if ( plugin_basename( SQLITE_MAIN_FILE ) === $plugin ) {
if ( wp_safe_redirect( admin_url( 'options-general.php?page=sqlite-integration' ) ) ) {
exit;
}
}
}
add_action( 'activated_plugin', 'sqlite_plugin_activation_redirect' );
/**
* Check the URL to ensure we're on the plugin page,
* the user has clicked the button to install SQLite,
* and the nonce is valid.
* If the above conditions are met, run the sqlite_plugin_copy_db_file() function,
* and redirect to the install screen.
*
* @since 1.0.0
*/
function sqlite_activation() {
global $current_screen;
if ( isset( $current_screen->base ) && 'settings_page_sqlite-integration' === $current_screen->base ) {
return;
}
if ( isset( $_GET['confirm-install'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'sqlite-install' ) ) {
// Handle upgrading from the performance-lab plugin.
if ( isset( $_GET['upgrade-from-pl'] ) ) {
global $wp_filesystem;
require_once ABSPATH . '/wp-admin/includes/file.php';
// Delete the previous db.php file.
$wp_filesystem->delete( WP_CONTENT_DIR . '/db.php' );
// Deactivate the performance-lab SQLite module.
$pl_option_name = defined( 'PERFLAB_MODULES_SETTING' ) ? PERFLAB_MODULES_SETTING : 'perflab_modules_settings';
$pl_option = get_option( $pl_option_name, array() );
unset( $pl_option['database/sqlite'] );
update_option( $pl_option_name, $pl_option );
}
sqlite_plugin_copy_db_file();
// WordPress will automatically redirect to the install screen here.
wp_redirect( admin_url() );
exit;
}
}
add_action( 'admin_init', 'sqlite_activation' );
// Flush the cache at the last moment before the redirect.
add_filter(
'x_redirect_by',
function ( $result ) {
wp_cache_flush();
return $result;
},
PHP_INT_MAX,
1
);
/**
* Add the db.php file in wp-content.
*
* When the plugin gets merged in wp-core, this is not to be ported.
*/
function sqlite_plugin_copy_db_file() {
// Bail early if the SQLite3 class does not exist.
if ( ! class_exists( 'SQLite3' ) ) {
return;
}
$destination = WP_CONTENT_DIR . '/db.php';
// Place database drop-in if not present yet, except in case there is
// another database drop-in present already.
if ( ! defined( 'SQLITE_DB_DROPIN_VERSION' ) && ! file_exists( $destination ) ) {
// Init the filesystem to allow copying the file.
global $wp_filesystem;
require_once ABSPATH . '/wp-admin/includes/file.php';
// Init the filesystem if needed, then copy the file, replacing contents as needed.
if ( ( $wp_filesystem || WP_Filesystem() ) && $wp_filesystem->touch( $destination ) ) {
// Get the db.copy.php file contents, replace placeholders and write it to the destination.
$file_contents = str_replace(
array(
'{SQLITE_IMPLEMENTATION_FOLDER_PATH}',
'{SQLITE_PLUGIN}',
),
array(
__DIR__,
str_replace( WP_PLUGIN_DIR . '/', '', SQLITE_MAIN_FILE ),
),
file_get_contents( __DIR__ . '/db.copy' )
);
$wp_filesystem->put_contents( $destination, $file_contents );
}
}
}
@@ -0,0 +1,76 @@
<?php
/**
* Functions to add admin notices if necessary.
*
* @since 1.0.0
* @package wp-sqlite-integration
*/
/**
* Add admin notices.
*
* When the plugin gets merged in wp-core, this is not to be ported.
*/
function sqlite_plugin_admin_notice() {
// Don't print notices in the plugin's admin screen.
global $current_screen;
if ( isset( $current_screen->base ) && 'settings_page_sqlite-integration' === $current_screen->base ) {
return;
}
// If SQLite is not detected, bail early.
if ( ! class_exists( 'SQLite3' ) ) {
printf(
'<div class="notice notice-error"><p>%s</p></div>',
esc_html__( 'The SQLite Integration plugin is active, but the SQLite3 class is missing from your server. Please make sure that SQLite is enabled in your PHP installation.', 'sqlite-database-integration' )
);
return;
}
/*
* If the SQLITE_DB_DROPIN_VERSION constant is not defined
* but there's a db.php file in the wp-content directory, then the module can't be activated.
* The module should not have been activated in the first place
* (there's a check in the can-load.php file), but this is a fallback check.
*/
if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) ) {
printf(
'<div class="notice notice-error"><p>%s</p></div>',
sprintf(
/* translators: 1: SQLITE_DB_DROPIN_VERSION constant, 2: db.php drop-in path */
__( 'The SQLite Integration module is active, but the %1$s constant is missing. It appears you already have another %2$s file present on your site. ', 'sqlite-database-integration' ),
'<code>SQLITE_DB_DROPIN_VERSION</code>',
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
)
);
return;
}
if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
return;
}
if ( ! wp_is_writable( WP_CONTENT_DIR ) ) {
printf(
'<div class="notice notice-error"><p>%s</p></div>',
esc_html__( 'The SQLite Integration plugin is active, but the wp-content/db.php file is missing and the wp-content directory is not writable. Please ensure the wp-content folder is writable, then deactivate the plugin and try again.', 'sqlite-database-integration' )
);
return;
}
// The dropin db.php is missing.
printf(
'<div class="notice notice-error"><p>%s</p></div>',
sprintf(
/* translators: 1: db.php drop-in path, 2: Admin URL to deactivate the module */
__( 'The SQLite Integration plugin is active, but the %1$s file is missing. Please <a href="%2$s">deactivate the plugin</a> and re-activate it to try again.', 'sqlite-database-integration' ),
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>',
esc_url( admin_url( 'plugins.php' ) )
)
);
}
add_action( 'admin_notices', 'sqlite_plugin_admin_notice' ); // Add the admin notices.
// Remove the PL-plugin admin notices for SQLite.
remove_action( 'admin_notices', 'perflab_sqlite_plugin_admin_notice' );
@@ -0,0 +1,149 @@
<?php
/**
* Functions for the admin page of the plugin.
*
* @since 1.0.0
* @package wp-sqlite-integration
*/
/**
* Add an admin menu page.
*
* @since 1.0.0
*/
function sqlite_add_admin_menu() {
add_options_page(
__( 'SQLite integration', 'sqlite-database-integration' ),
__( 'SQLite integration', 'sqlite-database-integration' ),
'manage_options',
'sqlite-integration',
'sqlite_integration_admin_screen'
);
}
add_action( 'admin_menu', 'sqlite_add_admin_menu' );
/**
* The admin page contents.
*/
function sqlite_integration_admin_screen() {
?>
<div class="wrap">
<h1><?php esc_html_e( 'SQLite integration.', 'sqlite-database-integration' ); ?></h1>
</div>
<!-- Set the wrapper width to 50em, to improve readability. -->
<div style="max-width:50em;">
<?php if ( defined( 'SQLITE_DB_DROPIN_VERSION' ) ) : ?>
<div class="notice notice-success">
<p><?php esc_html_e( 'SQLite is enabled.', 'sqlite-database-integration' ); ?></p>
</div>
<p>
<?php
printf(
/* translators: 1: Admin URL to deactivate the module, 2: db.php drop-in path, */
__( 'The SQLite drop-in is enabled. To disable it and get back to your previous, MySQL database, you can <a href="%1$s">deactivate the plugin</a>. Alternatively, you can manually delete the %2$s file from your server.', 'sqlite-database-integration' ),
esc_url( admin_url( 'plugins.php' ) ),
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
);
?>
</p>
<?php else : ?>
<?php if ( ! class_exists( 'SQLite3' ) ) : ?>
<div class="notice notice-error">
<p><?php esc_html_e( 'We detected that the SQLite3 class is missing from your server. Please make sure that SQLite is enabled in your PHP installation before proceeding.', 'sqlite-database-integration' ); ?></p>
</div>
<?php elseif ( ! extension_loaded( 'pdo_sqlite' ) ) : ?>
<div class="notice notice-error">
<p><?php esc_html_e( 'We detected that the PDO SQLite driver is missing from your server (the pdo_sqlite extension is not loaded). Please make sure that SQLite is enabled in your PHP installation before proceeding.', 'sqlite-database-integration' ); ?></p>
</div>
<?php elseif ( file_exists( WP_CONTENT_DIR . '/db.php' ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) ) : ?>
<?php if ( defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) ) : ?>
<div class="notice notice-warning">
<p>
<?php
printf(
/* translators: %s: db.php drop-in path */
esc_html__( 'An older %s file was detected. Please click the button below to update the file.', 'sqlite-database-integration' ),
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
);
?>
</p>
</div>
<a class="button button-primary" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin.php?page=sqlite-integration&confirm-install&upgrade-from-pl' ), 'sqlite-install' ) ); ?>">
<?php
printf(
/* translators: %s: db.php drop-in path */
esc_html__( 'Update %s file', 'sqlite-database-integration' ),
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
);
?>
</a>
<?php else : ?>
<div class="notice notice-error">
<p>
<?php
printf(
/* translators: %s: db.php drop-in path */
esc_html__( 'The SQLite plugin cannot be activated because a different %s drop-in already exists.', 'sqlite-database-integration' ),
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
);
?>
</p>
</div>
<?php endif; ?>
<?php elseif ( ! is_writable( WP_CONTENT_DIR ) ) : ?>
<div class="notice notice-error">
<p>
<?php
printf(
/* translators: %s: db.php drop-in path */
esc_html__( 'The SQLite plugin cannot be activated because the %s directory is not writable.', 'sqlite-database-integration' ),
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '</code>'
);
?>
</p>
</div>
<?php else : ?>
<div class="notice notice-success">
<p><?php esc_html_e( 'All checks completed successfully, your site can use an SQLite database. You can proceed with the installation.', 'sqlite-database-integration' ); ?></p>
</div>
<h2><?php esc_html_e( 'Important note', 'sqlite-database-integration' ); ?></h2>
<p><?php esc_html_e( 'This plugin will switch to a separate database and install WordPress in it. You will need to reconfigure your site, and start with a fresh site. Disabling the plugin you will get back to your previous MySQL database, with all your previous data intact.', 'sqlite-database-integration' ); ?></p>
<p><?php esc_html_e( 'By clicking the button below, you will be redirected to the WordPress installation screen to setup your new database', 'sqlite-database-integration' ); ?></p>
<a class="button button-primary" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin.php?page=sqlite-integration&confirm-install' ), 'sqlite-install' ) ); ?>"><?php esc_html_e( 'Install SQLite database', 'sqlite-database-integration' ); ?></a>
<?php endif; ?>
<?php endif; ?>
</div>
<?php
}
/**
* Adds a link to the admin bar.
*
* @since n.e.x.t
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param WP_Admin_Bar $admin_bar The admin bar object.
*/
function sqlite_plugin_adminbar_item( $admin_bar ) {
global $wpdb;
if ( defined( 'SQLITE_DB_DROPIN_VERSION' ) && defined( 'DB_ENGINE' ) && 'sqlite' === DB_ENGINE ) {
$title = '<span style="color:#46B450;">' . __( 'Database: SQLite', 'sqlite-database-integration' ) . '</span>';
} elseif ( stripos( $wpdb->db_server_info(), 'maria' ) !== false ) {
$title = '<span style="color:#DC3232;">' . __( 'Database: MariaDB', 'sqlite-database-integration' ) . '</span>';
} else {
$title = '<span style="color:#DC3232;">' . __( 'Database: MySQL', 'sqlite-database-integration' ) . '</span>';
}
$args = array(
'id' => 'sqlite-db-integration',
'parent' => 'top-secondary',
'title' => $title,
'href' => esc_url( admin_url( 'options-general.php?page=sqlite-integration' ) ),
'meta' => false,
);
$admin_bar->add_node( $args );
}
add_action( 'admin_bar_menu', 'sqlite_plugin_adminbar_item', 999 );
@@ -0,0 +1,53 @@
<?php
/**
* Define constants for the SQLite implementation.
*
* @since 1.0.0
* @package wp-sqlite-integration
*/
// Temporary - This will be in wp-config.php once SQLite is merged in Core.
if ( ! defined( 'DB_ENGINE' ) ) {
if ( defined( 'SQLITE_DB_DROPIN_VERSION' ) ) {
define( 'DB_ENGINE', 'sqlite' );
} elseif ( defined( 'DATABASE_ENGINE' ) ) {
// backwards compatibility with previous versions of the plugin.
define( 'DB_ENGINE', DATABASE_ENGINE );
} else {
define( 'DB_ENGINE', 'mysql' );
}
}
/**
* Notice:
* Your scripts have the permission to create directories or files on your server.
* If you write in your wp-config.php like below, we take these definitions.
* define('DB_DIR', '/full_path_to_the_database_directory/');
* define('DB_FILE', 'database_file_name');
*/
/**
* FQDBDIR is a directory where the sqlite database file is placed.
* If DB_DIR is defined, it is used as FQDBDIR.
*/
if ( ! defined( 'FQDBDIR' ) ) {
if ( defined( 'DB_DIR' ) ) {
define( 'FQDBDIR', trailingslashit( DB_DIR ) );
} elseif ( defined( 'WP_CONTENT_DIR' ) ) {
define( 'FQDBDIR', WP_CONTENT_DIR . '/database/' );
} else {
define( 'FQDBDIR', ABSPATH . 'wp-content/database/' );
}
}
/**
* FQDB is a database file name. If DB_FILE is defined, it is used
* as FQDB.
*/
if ( ! defined( 'FQDB' ) ) {
if ( defined( 'DB_FILE' ) ) {
define( 'FQDB', FQDBDIR . DB_FILE );
} else {
define( 'FQDB', FQDBDIR . '.ht.sqlite' );
}
}
@@ -0,0 +1,58 @@
<?php
/**
* Plugin Name: SQLite integration (Drop-in)
* Version: 1.0.0
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
*
* This file is auto-generated and copied from the sqlite plugin.
* Please don't edit this file directly.
*
* @package wp-sqlite-integration
*/
define( 'SQLITE_DB_DROPIN_VERSION', '1.8.0' );
// Tweak to allow copy-pasting the file without having to run string-replacements.
$sqlite_plugin_implementation_folder_path = '{SQLITE_IMPLEMENTATION_FOLDER_PATH}';
if ( ! file_exists( $sqlite_plugin_implementation_folder_path ) ) { // Check that the folder exists.
$sqlite_plugin_implementation_folder_path = realpath( __DIR__ . '/plugins/sqlite-database-integration' );
}
// Bail early if the SQLite implementation was not located in the plugin.
if ( ! $sqlite_plugin_implementation_folder_path || ! file_exists( $sqlite_plugin_implementation_folder_path . '/wp-includes/sqlite/db.php' ) ) {
return;
}
// Constant for backward compatibility.
if ( ! defined( 'DATABASE_TYPE' ) ) {
define( 'DATABASE_TYPE', 'sqlite' );
}
// Define SQLite constant.
if ( ! defined( 'DB_ENGINE' ) ) {
define( 'DB_ENGINE', 'sqlite' );
}
// Require the implementation from the plugin.
require_once $sqlite_plugin_implementation_folder_path . '/wp-includes/sqlite/db.php';
// Activate the performance-lab plugin if it is not already activated.
add_action(
'admin_footer',
function() {
if ( defined( 'SQLITE_MAIN_FILE' ) ) {
return;
}
if ( ! function_exists( 'activate_plugin' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
if ( is_plugin_inactive( '{SQLITE_PLUGIN}' ) ) {
// If `activate_plugin()` returns a value other than null (like WP_Error),
// the plugin could not be found. Try with a hardcoded string,
// because that probably means the file was directly copy-pasted.
if ( null !== activate_plugin( '{SQLITE_PLUGIN}', '', false, true ) ) {
activate_plugin( 'sqlite-database-integration/load.php', '', false, true );
}
}
}
);
@@ -0,0 +1,68 @@
<?php
/**
* Handle the SQLite deactivation.
*
* @since 1.0.0
* @package wp-sqlite-integration
*/
/**
* Delete the db.php file in wp-content.
*
* When the plugin gets merged in wp-core, this is not to be ported.
*/
function sqlite_plugin_remove_db_file() {
if ( ! defined( 'SQLITE_DB_DROPIN_VERSION' ) || ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
return;
}
global $wp_filesystem;
require_once ABSPATH . '/wp-admin/includes/file.php';
// Init the filesystem if needed, then delete custom drop-in.
if ( $wp_filesystem || WP_Filesystem() ) {
// Flush any persistent cache.
wp_cache_flush();
// Delete the drop-in.
$wp_filesystem->delete( WP_CONTENT_DIR . '/db.php' );
// Flush the cache again to mitigate a possible race condition.
wp_cache_flush();
}
// Run an action on `shutdown`, to deactivate the option in the MySQL database.
add_action(
'shutdown',
function () {
global $table_prefix;
// Get credentials for the MySQL database.
$dbuser = defined( 'DB_USER' ) ? DB_USER : '';
$dbpassword = defined( 'DB_PASSWORD' ) ? DB_PASSWORD : '';
$dbname = defined( 'DB_NAME' ) ? DB_NAME : '';
$dbhost = defined( 'DB_HOST' ) ? DB_HOST : '';
// Init a connection to the MySQL database.
$wpdb_mysql = new wpdb( $dbuser, $dbpassword, $dbname, $dbhost );
$wpdb_mysql->set_prefix( $table_prefix );
// Get the perflab options, remove the database/sqlite module and update the option.
$row = $wpdb_mysql->get_row( $wpdb_mysql->prepare( "SELECT option_value FROM $wpdb_mysql->options WHERE option_name = %s LIMIT 1", 'active_plugins' ) );
if ( is_object( $row ) ) {
$value = maybe_unserialize( $row->option_value );
if ( is_array( $value ) ) {
$value_flipped = array_flip( $value );
$items = array_reverse( explode( DIRECTORY_SEPARATOR, SQLITE_MAIN_FILE ) );
$item = $items[1] . DIRECTORY_SEPARATOR . $items[0];
unset( $value_flipped[ $item ] );
$value = array_flip( $value_flipped );
$wpdb_mysql->update( $wpdb_mysql->options, array( 'option_value' => maybe_serialize( $value ) ), array( 'option_name' => 'active_plugins' ) );
}
}
},
PHP_INT_MAX
);
// Flush any persistent cache.
wp_cache_flush();
}
register_deactivation_hook( SQLITE_MAIN_FILE, 'sqlite_plugin_remove_db_file' ); // Remove db.php file on plugin deactivation.
@@ -0,0 +1,83 @@
<?php
/**
* Tweaks for the health-check screens.
*
* @since 1.0.0
* @package wp-sqlite-integration
*/
/**
* Filter debug data in site-health screen.
*
* When the plugin gets merged in wp-core, these should be merged in src/wp-admin/includes/class-wp-debug-data.php
* See https://github.com/WordPress/wordpress-develop/pull/3220/files
*
* @param array $info The debug data.
*/
function sqlite_plugin_filter_debug_data( $info ) {
$db_engine = defined( 'DB_ENGINE' ) && 'sqlite' === DB_ENGINE ? 'sqlite' : 'mysql';
$info['wp-constants']['fields']['DB_ENGINE'] = array(
'label' => 'DB_ENGINE',
'value' => ( defined( 'DB_ENGINE' ) ? DB_ENGINE : __( 'Undefined', 'sqlite-database-integration' ) ),
'debug' => ( defined( 'DB_ENGINE' ) ? DB_ENGINE : 'undefined' ),
);
$info['wp-database']['fields']['db_engine'] = array(
'label' => __( 'Database type', 'sqlite-database-integration' ),
'value' => 'sqlite' === $db_engine ? 'SQLite' : 'MySQL/MariaDB',
);
if ( 'sqlite' === $db_engine ) {
$info['wp-database']['fields']['database_version'] = array(
'label' => __( 'SQLite version', 'sqlite-database-integration' ),
'value' => class_exists( 'SQLite3' ) ? SQLite3::version()['versionString'] : null,
);
$info['wp-database']['fields']['database_file'] = array(
'label' => __( 'Database file', 'sqlite-database-integration' ),
'value' => FQDB,
'private' => true,
);
$info['wp-database']['fields']['database_size'] = array(
'label' => __( 'Database size', 'sqlite-database-integration' ),
'value' => size_format( filesize( FQDB ) ),
);
unset( $info['wp-database']['fields']['extension'] );
unset( $info['wp-database']['fields']['server_version'] );
unset( $info['wp-database']['fields']['client_version'] );
unset( $info['wp-database']['fields']['database_host'] );
unset( $info['wp-database']['fields']['database_user'] );
unset( $info['wp-database']['fields']['database_name'] );
unset( $info['wp-database']['fields']['database_charset'] );
unset( $info['wp-database']['fields']['database_collate'] );
unset( $info['wp-database']['fields']['max_allowed_packet'] );
unset( $info['wp-database']['fields']['max_connections'] );
}
return $info;
}
add_filter( 'debug_information', 'sqlite_plugin_filter_debug_data' ); // Filter debug data in site-health screen.
/**
* Filter site_status tests in site-health screen.
*
* When the plugin gets merged in wp-core, these should be merged in src/wp-admin/includes/class-wp-site-health.php
*
* @param array $tests The tests.
* @return array
*/
function sqlite_plugin_filter_site_status_tests( $tests ) {
$db_engine = defined( 'DB_ENGINE' ) && 'sqlite' === DB_ENGINE ? 'sqlite' : 'mysql';
if ( 'sqlite' === $db_engine ) {
unset( $tests['direct']['utf8mb4_support'] );
unset( $tests['direct']['sql_server'] );
unset( $tests['direct']['persistent_object_cache'] ); // Throws an error because DB_NAME is not defined.
}
return $tests;
}
add_filter( 'site_status_tests', 'sqlite_plugin_filter_site_status_tests' );
@@ -0,0 +1,22 @@
<?php
/**
* Plugin Name: SQLite Database Integration
* Description: SQLite database driver drop-in.
* Author: The WordPress Team
* Version: 2.1.16
* Requires PHP: 7.0
* Textdomain: sqlite-database-integration
*
* This feature plugin allows WordPress to use SQLite instead of MySQL as its database.
*
* @package wp-sqlite-integration
*/
define( 'SQLITE_MAIN_FILE', __FILE__ );
require_once __DIR__ . '/php-polyfills.php';
require_once __DIR__ . '/admin-page.php';
require_once __DIR__ . '/activate.php';
require_once __DIR__ . '/deactivate.php';
require_once __DIR__ . '/admin-notices.php';
require_once __DIR__ . '/health-check.php';
@@ -0,0 +1,54 @@
<?php
/**
* Polyfills for php 7 & 8 functions
*
* @package wp-sqlite-integration
*/
if ( ! function_exists( 'str_starts_with' ) ) {
/**
* Check if a string starts with a specific substring.
*
* @param string $haystack The string to search in.
* @param string $needle The string to search for.
*
* @see https://www.php.net/manual/en/function.str-starts-with
*
* @return bool
*/
function str_starts_with( string $haystack, string $needle ) {
return empty( $needle ) || 0 === strpos( $haystack, $needle );
}
}
if ( ! function_exists( 'str_contains' ) ) {
/**
* Check if a string contains a specific substring.
*
* @param string $haystack The string to search in.
* @param string $needle The string to search for.
*
* @see https://www.php.net/manual/en/function.str-contains
*
* @return bool
*/
function str_contains( string $haystack, string $needle ) {
return empty( $needle ) || false !== strpos( $haystack, $needle );
}
}
if ( ! function_exists( 'str_ends_with' ) ) {
/**
* Check if a string ends with a specific substring.
*
* @param string $haystack The string to search in.
* @param string $needle The string to search for.
*
* @see https://www.php.net/manual/en/function.str-ends-with
*
* @return bool
*/
function str_ends_with( string $haystack, string $needle ) {
return empty( $needle ) || substr( $haystack, -strlen( $needle ) === $needle );
}
}
@@ -0,0 +1,38 @@
=== SQLite Database Integration ===
Contributors: wordpressdotorg, aristath, janjakes, zieladam, berislav.grgicak, bpayton, zaerl
Requires at least: 6.4
Tested up to: 6.6.1
Requires PHP: 7.0
Stable tag: 2.1.16
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: performance, database
SQLite integration plugin by the WordPress Team.
== Description ==
The SQLite plugin is a community, feature plugin. The intent is to allow testing an SQLite integration with WordPress and gather feedback, with the goal of eventually landing it in WordPress core.
This feature plugin includes code from the PHPMyAdmin project (specifically parts of the PHPMyAdmin/sql-parser library), licensed under the GPL v2 or later. More info on the PHPMyAdmin/sql-parser library can be found on [GitHub](https://github.com/phpmyadmin/sql-parser).
== Frequently Asked Questions ==
= What is the purpose of this plugin? =
The primary purpose of the SQLite plugin is to allow testing the use of an SQLite database, with the goal to eventually land in WordPress core.
You can read the original proposal on the [Make blog](https://make.wordpress.org/core/2022/09/12/lets-make-wordpress-officially-support-sqlite/), as well as the [call for testing](https://make.wordpress.org/core/2022/12/20/help-us-test-the-sqlite-implementation/) for more context and useful information.
= Can I use this plugin on my production site? =
Per the primary purpose of the plugin (see above), it can mostly be considered a beta testing plugin. To a degree, it should be okay to use it in production. However, as with every plugin, you are doing so at your own risk.
= Where can I submit my plugin feedback? =
Feedback is encouraged and much appreciated, especially since this plugin is a future WordPress core feature. If you need help with troubleshooting or have a question, suggestions, or requests, you can [submit them as an issue in the SQLite GitHub repository](https://github.com/wordpress/sqlite-database-integration/issues/new).
= How can I contribute to the plugin? =
Contributions are always welcome! Learn more about how to get involved in the [Core Performance Team Handbook](https://make.wordpress.org/performance/handbook/get-involved/).
@@ -0,0 +1,363 @@
<?php
/**
* Extend and replace the wpdb class.
*
* @package wp-sqlite-integration
* @since 1.0.0
*/
/**
* This class extends wpdb and replaces it.
*
* It also rewrites some methods that use mysql specific functions.
*/
class WP_SQLite_DB extends wpdb {
/**
* Database Handle
*
* @var WP_SQLite_Translator
*/
protected $dbh;
/**
* Constructor
*
* Unlike wpdb, no credentials are needed.
*/
public function __construct() {
parent::__construct( '', '', '', '' );
$this->charset = 'utf8mb4';
}
/**
* Method to set character set for the database.
*
* This overrides wpdb::set_charset(), only to dummy out the MySQL function.
*
* @see wpdb::set_charset()
*
* @param resource $dbh The resource given by mysql_connect.
* @param string $charset Optional. The character set. Default null.
* @param string $collate Optional. The collation. Default null.
*/
public function set_charset( $dbh, $charset = null, $collate = null ) {
}
/**
* Method to get the character set for the database.
* Hardcoded to utf8mb4 for now.
*
* @param string $table The table name.
* @param string $column The column name.
*
* @return string The character set.
*/
public function get_col_charset( $table, $column ) {
// Hardcoded for now.
return 'utf8mb4';
}
/**
* Method to dummy out wpdb::set_sql_mode()
*
* @see wpdb::set_sql_mode()
*
* @param array $modes Optional. A list of SQL modes to set.
*/
public function set_sql_mode( $modes = array() ) {
}
/**
* Closes the current database connection.
* Noop in SQLite.
*
* @return bool True to indicate the connection was successfully closed.
*/
public function close() {
return true;
}
/**
* Method to select the database connection.
*
* This overrides wpdb::select(), only to dummy out the MySQL function.
*
* @see wpdb::select()
*
* @param string $db MySQL database name. Not used.
* @param resource|null $dbh Optional link identifier.
*/
public function select( $db, $dbh = null ) {
$this->ready = true;
}
/**
* Method to escape characters.
*
* This overrides wpdb::_real_escape() to avoid using mysql_real_escape_string().
*
* @see wpdb::_real_escape()
*
* @param string $str The string to escape.
*
* @return string escaped
*/
public function _real_escape( $str ) {
return addslashes( $str );
}
/**
* Method to dummy out wpdb::esc_like() function.
*
* WordPress 4.0.0 introduced esc_like() function that adds backslashes to %,
* underscore and backslash, which is not interpreted as escape character
* by SQLite. So we override it and dummy out this function.
*
* @param string $text The raw text to be escaped. The input typed by the user should have no
* extra or deleted slashes.
*
* @return string Text in the form of a LIKE phrase. The output is not SQL safe. Call $wpdb::prepare()
* or real_escape next.
*/
public function esc_like( $text ) {
return $text;
}
/**
* Method to put out the error message.
*
* This overrides wpdb::print_error(), for we can't use the parent class method.
*
* @see wpdb::print_error()
*
* @global array $EZSQL_ERROR Stores error information of query and error string.
*
* @param string $str The error to display.
*
* @return bool|void False if the showing of errors is disabled.
*/
public function print_error( $str = '' ) {
global $EZSQL_ERROR;
if ( ! $str ) {
$err = $this->dbh->get_error_message() ? $this->dbh->get_error_message() : '';
$str = empty( $err ) ? '' : $err[2];
}
$EZSQL_ERROR[] = array(
'query' => $this->last_query,
'error_str' => $str,
);
if ( $this->suppress_errors ) {
return false;
}
wp_load_translations_early();
$caller = $this->get_caller();
$caller = $caller ? $caller : '(unknown)';
$error_str = sprintf(
'WordPress database error %1$s for query %2$s made by %3$s',
$str,
$this->last_query,
$caller
);
error_log( $error_str );
if ( ! $this->show_errors ) {
return false;
}
if ( is_multisite() ) {
$msg = "WordPress database error: [$str]\n{$this->last_query}\n";
if ( defined( 'ERRORLOGFILE' ) ) {
error_log( $msg, 3, ERRORLOGFILE );
}
if ( defined( 'DIEONDBERROR' ) ) {
wp_die( $msg );
}
} else {
$str = htmlspecialchars( $str, ENT_QUOTES );
$query = htmlspecialchars( $this->last_query, ENT_QUOTES );
printf(
'<div id="error"><p class="wpdberror">WordPress database error: [%1$s] %2$s</p></div>',
$str,
'<code>' . $query . '</code>'
);
}
}
/**
* Method to flush cached data.
*
* This overrides wpdb::flush(). This is not necessarily overridden, because
* $result will never be resource.
*
* @see wpdb::flush
*/
public function flush() {
$this->last_result = array();
$this->col_info = null;
$this->last_query = null;
$this->rows_affected = 0;
$this->num_rows = 0;
$this->last_error = '';
$this->result = null;
}
/**
* Method to do the database connection.
*
* This overrides wpdb::db_connect() to avoid using MySQL function.
*
* @see wpdb::db_connect()
*
* @param bool $allow_bail Not used.
* @return void
*/
public function db_connect( $allow_bail = true ) {
if ( $this->dbh ) {
return;
}
$this->init_charset();
$pdo = null;
if ( isset( $GLOBALS['@pdo'] ) ) {
$pdo = $GLOBALS['@pdo'];
}
$this->dbh = new WP_SQLite_Translator( $pdo );
$this->last_error = $this->dbh->get_error_message();
if ( $this->last_error ) {
return false;
}
$GLOBALS['@pdo'] = $this->dbh->get_pdo();
$this->ready = true;
}
/**
* Method to dummy out wpdb::check_connection()
*
* @param bool $allow_bail Not used.
*
* @return bool
*/
public function check_connection( $allow_bail = true ) {
return true;
}
/**
* Method to execute the query.
*
* This overrides wpdb::query(). In fact, this method does all the database
* access jobs.
*
* @see wpdb::query()
*
* @param string $query Database query.
*
* @return int|false Number of rows affected/selected or false on error
*/
public function query( $query ) {
if ( ! $this->ready ) {
return false;
}
$query = apply_filters( 'query', $query );
$this->flush();
$this->func_call = "\$db->query(\"$query\")";
$this->last_query = $query;
if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) {
$this->timer_start();
}
$this->result = $this->dbh->query( $query );
++$this->num_queries;
if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) {
$this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() );
}
$this->last_error = $this->dbh->get_error_message();
if ( $this->last_error ) {
$this->print_error( $this->last_error );
return false;
}
if ( preg_match( '/^\\s*(set|create|alter|truncate|drop|optimize)\\s*/i', $query ) ) {
return $this->dbh->get_return_value();
}
if ( preg_match( '/^\\s*(insert|delete|update|replace)\s/i', $query ) ) {
$this->rows_affected = $this->dbh->get_affected_rows();
if ( preg_match( '/^\s*(insert|replace)\s/i', $query ) ) {
$this->insert_id = $this->dbh->get_insert_id();
}
return $this->rows_affected;
}
$this->last_result = $this->dbh->get_query_results();
$this->num_rows = $this->dbh->get_num_rows();
return $this->num_rows;
}
/**
* Method to set the class variable $col_info.
*
* This overrides wpdb::load_col_info(), which uses a mysql function.
*
* @see wpdb::load_col_info()
*/
protected function load_col_info() {
if ( $this->col_info ) {
return;
}
$this->col_info = $this->dbh->get_columns();
}
/**
* Method to return what the database can do.
*
* This overrides wpdb::has_cap() to avoid using MySQL functions.
* SQLite supports subqueries, but not support collation, group_concat and set_charset.
*
* @see wpdb::has_cap()
*
* @param string $db_cap The feature to check for. Accepts 'collation',
* 'group_concat', 'subqueries', 'set_charset',
* 'utf8mb4', or 'utf8mb4_520'.
*
* @return bool Whether the database feature is supported, false otherwise.
*/
public function has_cap( $db_cap ) {
return 'subqueries' === strtolower( $db_cap );
}
/**
* Method to return database version number.
*
* This overrides wpdb::db_version() to avoid using MySQL function.
* It returns mysql version number, but it means nothing for SQLite.
* So it return the newest mysql version.
*
* @see wpdb::db_version()
*/
public function db_version() {
return '8.0';
}
/**
* Retrieves full database server information.
*
* @return string|false Server info on success, false on failure.
*/
public function db_server_info() {
return SQLite3::version()['versionString'];
}
}
@@ -0,0 +1,762 @@
<?php
/**
* Custom functions for the SQLite implementation.
*
* @package wp-sqlite-integration
* @since 1.0.0
*/
/**
* This class defines user defined functions(UDFs) for PDO library.
*
* These functions replace those used in the SQL statement with the PHP functions.
*
* Usage:
*
* <code>
* new WP_SQLite_PDO_User_Defined_Functions(ref_to_pdo_obj);
* </code>
*
* This automatically enables ref_to_pdo_obj to replace the function in the SQL statement
* to the ones defined here.
*/
class WP_SQLite_PDO_User_Defined_Functions {
/**
* The class constructor
*
* Initializes the use defined functions to PDO object with PDO::sqliteCreateFunction().
*
* @param PDO $pdo The PDO object.
*/
public function __construct( $pdo ) {
if ( ! $pdo ) {
wp_die( 'Database is not initialized.', 'Database Error' );
}
foreach ( $this->functions as $f => $t ) {
$pdo->sqliteCreateFunction( $f, array( $this, $t ) );
}
}
/**
* Array to define MySQL function => function defined with PHP.
*
* Replaced functions must be public.
*
* @var array
*/
private $functions = array(
'month' => 'month',
'monthnum' => 'month',
'year' => 'year',
'day' => 'day',
'hour' => 'hour',
'minute' => 'minute',
'second' => 'second',
'week' => 'week',
'weekday' => 'weekday',
'dayofweek' => 'dayofweek',
'dayofmonth' => 'dayofmonth',
'unix_timestamp' => 'unix_timestamp',
'now' => 'now',
'md5' => 'md5',
'curdate' => 'curdate',
'rand' => 'rand',
'from_unixtime' => 'from_unixtime',
'localtime' => 'now',
'localtimestamp' => 'now',
'isnull' => 'isnull',
'if' => '_if',
'regexp' => 'regexp',
'field' => 'field',
'log' => 'log',
'least' => 'least',
'greatest' => 'greatest',
'get_lock' => 'get_lock',
'release_lock' => 'release_lock',
'ucase' => 'ucase',
'lcase' => 'lcase',
'unhex' => 'unhex',
'inet_ntoa' => 'inet_ntoa',
'inet_aton' => 'inet_aton',
'datediff' => 'datediff',
'locate' => 'locate',
'utc_date' => 'utc_date',
'utc_time' => 'utc_time',
'utc_timestamp' => 'utc_timestamp',
'version' => 'version',
);
/**
* Method to return the unix timestamp.
*
* Used without an argument, it returns PHP time() function (total seconds passed
* from '1970-01-01 00:00:00' GMT). Used with the argument, it changes the value
* to the timestamp.
*
* @param string $field Representing the date formatted as '0000-00-00 00:00:00'.
*
* @return number of unsigned integer
*/
public function unix_timestamp( $field = null ) {
return is_null( $field ) ? time() : strtotime( $field );
}
/**
* Method to emulate MySQL FROM_UNIXTIME() function.
*
* @param int $field The unix timestamp.
* @param string $format Indicate the way of formatting(optional).
*
* @return string
*/
public function from_unixtime( $field, $format = null ) {
// Convert to ISO time.
$date = gmdate( 'Y-m-d H:i:s', $field );
return is_null( $format ) ? $date : $this->dateformat( $date, $format );
}
/**
* Method to emulate MySQL NOW() function.
*
* @return string representing current time formatted as '0000-00-00 00:00:00'.
*/
public function now() {
return gmdate( 'Y-m-d H:i:s' );
}
/**
* Method to emulate MySQL CURDATE() function.
*
* @return string representing current time formatted as '0000-00-00'.
*/
public function curdate() {
return gmdate( 'Y-m-d' );
}
/**
* Method to emulate MySQL MD5() function.
*
* @param string $field The string to be hashed.
*
* @return string of the md5 hash value of the argument.
*/
public function md5( $field ) {
return md5( $field );
}
/**
* Method to emulate MySQL RAND() function.
*
* SQLite does have a random generator, but it is called RANDOM() and returns random
* number between -9223372036854775808 and +9223372036854775807. So we substitute it
* with PHP random generator.
*
* This function uses mt_rand() which is four times faster than rand() and returns
* the random number between 0 and 1.
*
* @return int
*/
public function rand() {
return mt_rand( 0, 1 );
}
/**
* Method to emulate MySQL DATEFORMAT() function.
*
* @param string $date Formatted as '0000-00-00' or datetime as '0000-00-00 00:00:00'.
* @param string $format The string format.
*
* @return string formatted according to $format
*/
public function dateformat( $date, $format ) {
$mysql_php_date_formats = array(
'%a' => 'D',
'%b' => 'M',
'%c' => 'n',
'%D' => 'jS',
'%d' => 'd',
'%e' => 'j',
'%H' => 'H',
'%h' => 'h',
'%I' => 'h',
'%i' => 'i',
'%j' => 'z',
'%k' => 'G',
'%l' => 'g',
'%M' => 'F',
'%m' => 'm',
'%p' => 'A',
'%r' => 'h:i:s A',
'%S' => 's',
'%s' => 's',
'%T' => 'H:i:s',
'%U' => 'W',
'%u' => 'W',
'%V' => 'W',
'%v' => 'W',
'%W' => 'l',
'%w' => 'w',
'%X' => 'Y',
'%x' => 'o',
'%Y' => 'Y',
'%y' => 'y',
);
$time = strtotime( $date );
$format = strtr( $format, $mysql_php_date_formats );
return gmdate( $format, $time );
}
/**
* Method to extract the month value from the date.
*
* @param string $field Representing the date formatted as 0000-00-00.
*
* @return string Representing the number of the month between 1 and 12.
*/
public function month( $field ) {
/*
* From https://www.php.net/manual/en/datetime.format.php:
*
* n - Numeric representation of a month, without leading zeros.
* 1 through 12
*/
return intval( gmdate( 'n', strtotime( $field ) ) );
}
/**
* Method to extract the year value from the date.
*
* @param string $field Representing the date formatted as 0000-00-00.
*
* @return string Representing the number of the year.
*/
public function year( $field ) {
/*
* From https://www.php.net/manual/en/datetime.format.php:
*
* Y - A full numeric representation of a year, 4 digits.
*/
return intval( gmdate( 'Y', strtotime( $field ) ) );
}
/**
* Method to extract the day value from the date.
*
* @param string $field Representing the date formatted as 0000-00-00.
*
* @return string Representing the number of the day of the month from 1 and 31.
*/
public function day( $field ) {
/*
* From https://www.php.net/manual/en/datetime.format.php:
*
* j - Day of the month without leading zeros.
* 1 to 31.
*/
return intval( gmdate( 'j', strtotime( $field ) ) );
}
/**
* Method to emulate MySQL SECOND() function.
*
* @see https://www.php.net/manual/en/datetime.format.php
*
* @param string $field Representing the time formatted as '00:00:00'.
*
* @return number Unsigned integer
*/
public function second( $field ) {
/*
* From https://www.php.net/manual/en/datetime.format.php:
*
* s - Seconds, with leading zeros (00 to 59)
*/
return intval( gmdate( 's', strtotime( $field ) ) );
}
/**
* Method to emulate MySQL MINUTE() function.
*
* @param string $field Representing the time formatted as '00:00:00'.
*
* @return int
*/
public function minute( $field ) {
/*
* From https://www.php.net/manual/en/datetime.format.php:
*
* i - Minutes with leading zeros.
* 00 to 59.
*/
return intval( gmdate( 'i', strtotime( $field ) ) );
}
/**
* Method to emulate MySQL HOUR() function.
*
* Returns the hour for time, in 24-hour format, from 0 to 23.
* Importantly, midnight is 0, not 24.
*
* @param string $time Representing the time formatted, like '14:08:12'.
*
* @return int
*/
public function hour( $time ) {
/*
* From https://www.php.net/manual/en/datetime.format.php:
*
* H 24-hour format of an hour with leading zeros.
* 00 through 23.
*/
return intval( gmdate( 'H', strtotime( $time ) ) );
}
/**
* Covers MySQL WEEK() function.
*
* Always assumes $mode = 1.
*
* @TODO: Support other modes.
*
* From https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_week:
*
* > Returns the week number for date. The two-argument form of WEEK()
* > enables you to specify whether the week starts on Sunday or Monday
* > and whether the return value should be in the range from 0 to 53
* > or from 1 to 53. If the mode argument is omitted, the value of the
* > default_week_format system variable is used.
* >
* > The following table describes how the mode argument works:
* >
* > Mode First day of week Range Week 1 is the first week …
* > 0 Sunday 0-53 with a Sunday in this year
* > 1 Monday 0-53 with 4 or more days this year
* > 2 Sunday 1-53 with a Sunday in this year
* > 3 Monday 1-53 with 4 or more days this year
* > 4 Sunday 0-53 with 4 or more days this year
* > 5 Monday 0-53 with a Monday in this year
* > 6 Sunday 1-53 with 4 or more days this year
* > 7 Monday 1-53 with a Monday in this year
*
* @param string $field Representing the date.
* @param int $mode The mode argument.
*/
public function week( $field, $mode ) {
/*
* From https://www.php.net/manual/en/datetime.format.php:
*
* W - ISO-8601 week number of year, weeks starting on Monday.
* Example: 42 (the 42nd week in the year)
*
* Week 1 is the first week with a Thursday in it.
*/
return intval( gmdate( 'W', strtotime( $field ) ) );
}
/**
* Simulates WEEKDAY() function in MySQL.
*
* Returns the day of the week as an integer.
* The days of the week are numbered 0 to 6:
* * 0 for Monday
* * 1 for Tuesday
* * 2 for Wednesday
* * 3 for Thursday
* * 4 for Friday
* * 5 for Saturday
* * 6 for Sunday
*
* @param string $field Representing the date.
*
* @return int
*/
public function weekday( $field ) {
/*
* date('N') returns 1 (for Monday) through 7 (for Sunday)
* That's one more than MySQL.
* Let's subtract one to make it compatible.
*/
return intval( gmdate( 'N', strtotime( $field ) ) ) - 1;
}
/**
* Method to emulate MySQL DAYOFMONTH() function.
*
* @see https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_dayofmonth
*
* @param string $field Representing the date.
*
* @return int Returns the day of the month for date as a number in the range 1 to 31.
*/
public function dayofmonth( $field ) {
return intval( gmdate( 'j', strtotime( $field ) ) );
}
/**
* Method to emulate MySQL DAYOFWEEK() function.
*
* > Returns the weekday index for date (1 = Sunday, 2 = Monday, …, 7 = Saturday).
* > These index values correspond to the ODBC standard. Returns NULL if date is NULL.
*
* @param string $field Representing the date.
*
* @return int Returns the weekday index for date (1 = Sunday, 2 = Monday, …, 7 = Saturday).
*/
public function dayofweek( $field ) {
/**
* From https://www.php.net/manual/en/datetime.format.php:
*
* `w` Numeric representation of the day of the week
* 0 (for Sunday) through 6 (for Saturday)
*/
return intval( gmdate( 'w', strtotime( $field ) ) ) + 1;
}
/**
* Method to emulate MySQL DATE() function.
*
* @see https://www.php.net/manual/en/datetime.format.php
*
* @param string $date formatted as unix time.
*
* @return string formatted as '0000-00-00'.
*/
public function date( $date ) {
return gmdate( 'Y-m-d', strtotime( $date ) );
}
/**
* Method to emulate MySQL ISNULL() function.
*
* This function returns true if the argument is null, and true if not.
*
* @param mixed $field The field to be tested.
*
* @return boolean
*/
public function isnull( $field ) {
return is_null( $field );
}
/**
* Method to emulate MySQL IF() function.
*
* As 'IF' is a reserved word for PHP, function name must be changed.
*
* @param mixed $expression The statement to be evaluated as true or false.
* @param mixed $truthy Statement or value returned if $expression is true.
* @param mixed $falsy Statement or value returned if $expression is false.
*
* @return mixed
*/
public function _if( $expression, $truthy, $falsy ) {
return ( true === $expression ) ? $truthy : $falsy;
}
/**
* Method to emulate MySQL REGEXP() function.
*
* @param string $pattern Regular expression to match.
* @param string $field Haystack.
*
* @return integer 1 if matched, 0 if not matched.
*/
public function regexp( $pattern, $field ) {
/*
* If the original query says REGEXP BINARY
* the comparison is byte-by-byte and letter casing now
* matters since lower- and upper-case letters have different
* byte codes.
*
* The REGEXP function can't be easily made to accept two
* parameters, so we'll have to use a hack to get around this.
*
* If the first character of the pattern is a null byte, we'll
* remove it and make the comparison case-sensitive. This should
* be reasonably safe since PHP does not allow null bytes in
* regular expressions anyway.
*/
if ( "\x00" === $pattern[0] ) {
$pattern = substr( $pattern, 1 );
$flags = '';
} else {
// Otherwise, the search is case-insensitive.
$flags = 'i';
}
$pattern = str_replace( '/', '\/', $pattern );
$pattern = '/' . $pattern . '/' . $flags;
return preg_match( $pattern, $field );
}
/**
* Method to emulate MySQL FIELD() function.
*
* This function gets the list argument and compares the first item to all the others.
* If the same value is found, it returns the position of that value. If not, it
* returns 0.
*
* @return int
*/
public function field() {
$num_args = func_num_args();
if ( $num_args < 2 || is_null( func_get_arg( 0 ) ) ) {
return 0;
}
$arg_list = func_get_args();
$search_string = strtolower( array_shift( $arg_list ) );
for ( $i = 0; $i < $num_args - 1; $i++ ) {
if ( strtolower( $arg_list[ $i ] ) === $search_string ) {
return $i + 1;
}
}
return 0;
}
/**
* Method to emulate MySQL LOG() function.
*
* Used with one argument, it returns the natural logarithm of X.
* <code>
* LOG(X)
* </code>
* Used with two arguments, it returns the natural logarithm of X base B.
* <code>
* LOG(B, X)
* </code>
* In this case, it returns the value of log(X) / log(B).
*
* Used without an argument, it returns false. This returned value will be
* rewritten to 0, because SQLite doesn't understand true/false value.
*
* @return double|null
*/
public function log() {
$num_args = func_num_args();
if ( 1 === $num_args ) {
$arg1 = func_get_arg( 0 );
return log( $arg1 );
}
if ( 2 === $num_args ) {
$arg1 = func_get_arg( 0 );
$arg2 = func_get_arg( 1 );
return log( $arg1 ) / log( $arg2 );
}
return null;
}
/**
* Method to emulate MySQL LEAST() function.
*
* This function rewrites the function name to SQLite compatible function name.
*
* @return mixed
*/
public function least() {
$arg_list = func_get_args();
return min( $arg_list );
}
/**
* Method to emulate MySQL GREATEST() function.
*
* This function rewrites the function name to SQLite compatible function name.
*
* @return mixed
*/
public function greatest() {
$arg_list = func_get_args();
return max( $arg_list );
}
/**
* Method to dummy out MySQL GET_LOCK() function.
*
* This function is meaningless in SQLite, so we do nothing.
*
* @param string $name Not used.
* @param integer $timeout Not used.
*
* @return string
*/
public function get_lock( $name, $timeout ) {
return '1=1';
}
/**
* Method to dummy out MySQL RELEASE_LOCK() function.
*
* This function is meaningless in SQLite, so we do nothing.
*
* @param string $name Not used.
*
* @return string
*/
public function release_lock( $name ) {
return '1=1';
}
/**
* Method to emulate MySQL UCASE() function.
*
* This is MySQL alias for upper() function. This function rewrites it
* to SQLite compatible name upper().
*
* @param string $content String to be converted to uppercase.
*
* @return string SQLite compatible function name.
*/
public function ucase( $content ) {
return "upper($content)";
}
/**
* Method to emulate MySQL LCASE() function.
*
* This is MySQL alias for lower() function. This function rewrites it
* to SQLite compatible name lower().
*
* @param string $content String to be converted to lowercase.
*
* @return string SQLite compatible function name.
*/
public function lcase( $content ) {
return "lower($content)";
}
/**
* Method to emulate MySQL UNHEX() function.
*
* For a string argument str, UNHEX(str) interprets each pair of characters
* in the argument as a hexadecimal number and converts it to the byte represented
* by the number. The return value is a binary string.
*
* @param string $number Number to be unhexed.
*
* @return string Binary string
*/
public function unhex( $number ) {
return pack( 'H*', $number );
}
/**
* Method to emulate MySQL INET_NTOA() function.
*
* This function gets 4 or 8 bytes integer and turn it into the network address.
*
* @param integer $num Long integer.
*
* @return string
*/
public function inet_ntoa( $num ) {
return long2ip( $num );
}
/**
* Method to emulate MySQL INET_ATON() function.
*
* This function gets the network address and turns it into integer.
*
* @param string $addr Network address.
*
* @return int long integer
*/
public function inet_aton( $addr ) {
return absint( ip2long( $addr ) );
}
/**
* Method to emulate MySQL DATEDIFF() function.
*
* This function compares two dates value and returns the difference.
*
* @param string $start Start date.
* @param string $end End date.
*
* @return string
*/
public function datediff( $start, $end ) {
$start_date = new DateTime( $start );
$end_date = new DateTime( $end );
$interval = $end_date->diff( $start_date, false );
return $interval->format( '%r%a' );
}
/**
* Method to emulate MySQL LOCATE() function.
*
* This function returns the position if $substr is found in $str. If not,
* it returns 0. If mbstring extension is loaded, mb_strpos() function is
* used.
*
* @param string $substr Needle.
* @param string $str Haystack.
* @param integer $pos Position.
*
* @return integer
*/
public function locate( $substr, $str, $pos = 0 ) {
if ( ! extension_loaded( 'mbstring' ) ) {
$val = strpos( $str, $substr, $pos );
if ( false !== $val ) {
return $val + 1;
}
return 0;
}
$val = mb_strpos( $str, $substr, $pos );
if ( false !== $val ) {
return $val + 1;
}
return 0;
}
/**
* Method to return GMT date in the string format.
*
* @return string formatted GMT date 'dddd-mm-dd'
*/
public function utc_date() {
return gmdate( 'Y-m-d', time() );
}
/**
* Method to return GMT time in the string format.
*
* @return string formatted GMT time '00:00:00'
*/
public function utc_time() {
return gmdate( 'H:i:s', time() );
}
/**
* Method to return GMT time stamp in the string format.
*
* @return string formatted GMT timestamp 'yyyy-mm-dd 00:00:00'
*/
public function utc_timestamp() {
return gmdate( 'Y-m-d H:i:s', time() );
}
/**
* Method to return MySQL version.
*
* This function only returns the current newest version number of MySQL,
* because it is meaningless for SQLite database.
*
* @return string representing the version number: major_version.minor_version
*/
public function version() {
return '5.5';
}
}
@@ -0,0 +1,343 @@
<?php
/**
* Class WP_SQLite_Query_Rewriter
*
* @package wp-sqlite-integration
*/
/**
* The query rewriter class.
*/
class WP_SQLite_Query_Rewriter {
/**
* An array of input token objects.
*
* @var WP_SQLite_Token[]
*/
public $input_tokens = array();
/**
* An array of output token objects.
*
* @var WP_SQLite_Token[]
*/
public $output_tokens = array();
/**
* The current index.
*
* @var int
*/
public $index = -1;
/**
* The maximum index.
*
* @var int
*/
public $max = -1;
/**
* The call stack.
*
* @var array
*/
public $call_stack = array();
/**
* The current depth.
*
* @var int
*/
public $depth = 0;
/**
* The current token.
*
* @var WP_SQLite_Token
*/
private $token;
/**
* The last function call.
*
* @var WP_SQLite_Token
*/
private $last_function_call;
/**
* Constructor.
*
* @param WP_SQLite_Token[] $input_tokens Array of token objects.
*/
public function __construct( $input_tokens ) {
$this->input_tokens = $input_tokens;
$this->max = count( $input_tokens );
}
/**
* Returns the updated query.
*
* @return string
*/
public function get_updated_query() {
$query = '';
foreach ( $this->output_tokens as $token ) {
$query .= $token->token;
}
return $query;
}
/**
* Add a token to the output.
*
* @param WP_SQLite_Token $token Token object.
*/
public function add( $token ) {
if ( $token ) {
$this->output_tokens[] = $token;
}
}
/**
* Add multiple tokens to the output.
*
* @param WP_SQLite_Token[] $tokens Array of token objects.
*/
public function add_many( $tokens ) {
$this->output_tokens = array_merge( $this->output_tokens, $tokens );
}
/**
* Replaces all tokens.
*
* @param WP_SQLite_Token[] $tokens Array of token objects.
*/
public function replace_all( $tokens ) {
$this->output_tokens = $tokens;
}
/**
* Peek at the next tokens and return one that matches the given criteria.
*
* @param array $query Optional. Search query.
* [
* 'type' => string|null, // Token type.
* 'flags' => int|null, // Token flags.
* 'values' => string|null, // Token values.
* ].
*
* @return WP_SQLite_Token
*/
public function peek( $query = array() ) {
$type = isset( $query['type'] ) ? $query['type'] : null;
$flags = isset( $query['flags'] ) ? $query['flags'] : null;
$values = isset( $query['value'] )
? ( is_array( $query['value'] ) ? $query['value'] : array( $query['value'] ) )
: null;
$i = $this->index;
while ( ++$i < $this->max ) {
if ( $this->input_tokens[ $i ]->matches( $type, $flags, $values ) ) {
return $this->input_tokens[ $i ];
}
}
}
/**
* Move forward and return the next tokens that match the given criteria.
*
* @param int $nth The nth token to return.
*
* @return WP_SQLite_Token
*/
public function peek_nth( $nth ) {
$found = 0;
for ( $i = $this->index + 1;$i < $this->max;$i++ ) {
$token = $this->input_tokens[ $i ];
if ( ! $token->is_semantically_void() ) {
++$found;
}
if ( $found === $nth ) {
return $this->input_tokens[ $i ];
}
}
}
/**
* Consume all the tokens.
*
* @param array $query Search query.
*
* @return void
*/
public function consume_all( $query = array() ) {
while ( $this->consume( $query ) ) {
// Do nothing.
}
}
/**
* Consume the next tokens and return one that matches the given criteria.
*
* @param array $query Search query.
* [
* 'type' => null, // Optional. Token type.
* 'flags' => null, // Optional. Token flags.
* 'values' => null, // Optional. Token values.
* ].
*
* @return WP_SQLite_Token|null
*/
public function consume( $query = array() ) {
$tokens = $this->move_forward( $query );
$this->output_tokens = array_merge( $this->output_tokens, $tokens );
return $this->token;
}
/**
* Drop the last consumed token and return it.
*
* @return WP_SQLite_Token|null
*/
public function drop_last() {
return array_pop( $this->output_tokens );
}
/**
* Skip over the next tokens and return one that matches the given criteria.
*
* @param array $query Search query.
* [
* 'type' => null, // Optional. Token type.
* 'flags' => null, // Optional. Token flags.
* 'values' => null, // Optional. Token values.
* ].
*
* @return WP_SQLite_Token|null
*/
public function skip( $query = array() ) {
$this->skip_and_return_all( $query );
return $this->token;
}
/**
* Skip over the next tokens until one matches the given criteria,
* and return all the skipped tokens.
*
* @param array $query Search query.
* [
* 'type' => null, // Optional. Token type.
* 'flags' => null, // Optional. Token flags.
* 'values' => null, // Optional. Token values.
* ].
*
* @return WP_SQLite_Token[]
*/
public function skip_and_return_all( $query = array() ) {
$tokens = $this->move_forward( $query );
/*
* When skipping over whitespaces, make sure to consume
* at least one to avoid SQL syntax errors.
*/
foreach ( $tokens as $token ) {
if ( $token->matches( WP_SQLite_Token::TYPE_WHITESPACE ) ) {
$this->add( $token );
break;
}
}
return $tokens;
}
/**
* Returns the next tokens that match the given criteria.
*
* @param array $query Search query.
* [
* 'type' => string|null, // Optional. Token type.
* 'flags' => int|null, // Optional. Token flags.
* 'values' => string|null, // Optional. Token values.
* ].
*
* @return array
*/
private function move_forward( $query = array() ) {
$type = isset( $query['type'] ) ? $query['type'] : null;
$flags = isset( $query['flags'] ) ? $query['flags'] : null;
$values = isset( $query['value'] )
? ( is_array( $query['value'] ) ? $query['value'] : array( $query['value'] ) )
: null;
$depth = isset( $query['depth'] ) ? $query['depth'] : null;
$buffered = array();
while ( true ) {
if ( ++$this->index >= $this->max ) {
$this->token = null;
$this->call_stack = array();
break;
}
$this->token = $this->input_tokens[ $this->index ];
$this->update_call_stack();
$buffered[] = $this->token;
if (
( null === $depth || $this->depth === $depth )
&& $this->token->matches( $type, $flags, $values )
) {
break;
}
}
return $buffered;
}
/**
* Returns the last call stack element.
*
* @return array|null
*/
public function last_call_stack_element() {
return count( $this->call_stack ) ? $this->call_stack[ count( $this->call_stack ) - 1 ] : null;
}
/**
* Updates the call stack.
*
* @return void
*/
private function update_call_stack() {
if ( $this->token->flags & WP_SQLite_Token::FLAG_KEYWORD_FUNCTION ) {
$this->last_function_call = $this->token->value;
}
if ( WP_SQLite_Token::TYPE_OPERATOR === $this->token->type ) {
switch ( $this->token->value ) {
case '(':
if ( $this->last_function_call ) {
array_push(
$this->call_stack,
array(
'function' => $this->last_function_call,
'depth' => $this->depth,
)
);
$this->last_function_call = null;
}
++$this->depth;
break;
case ')':
--$this->depth;
$call_parent = $this->last_call_stack_element();
if (
$call_parent &&
$call_parent['depth'] === $this->depth
) {
array_pop( $this->call_stack );
}
break;
}
}
}
}
@@ -0,0 +1,327 @@
<?php
/**
* This file is a port of the Token class from the PHPMyAdmin/sql-parser library.
*
* @package wp-sqlite-integration
* @see https://github.com/phpmyadmin/sql-parser
*/
/**
* Defines a token along with a set of types and flags and utility functions.
*
* An array of tokens will result after parsing the query.
*
* A structure representing a lexeme that explicitly indicates its categorization for the purpose of parsing.
*/
class WP_SQLite_Token {
/**
* This type is used when the token is invalid or its type cannot be
* determined because of the ambiguous context. Further analysis might be
* required to detect its type.
*/
const TYPE_NONE = 0;
/**
* SQL specific keywords: SELECT, UPDATE, INSERT, etc.
*/
const TYPE_KEYWORD = 1;
/**
* Any type of legal operator.
*
* Arithmetic operators: +, -, *, /, etc.
* Logical operators: ===, <>, !==, etc.
* Bitwise operators: &, |, ^, etc.
* Assignment operators: =, +=, -=, etc.
* SQL specific operators: . (e.g. .. WHERE database.table ..),
* * (e.g. SELECT * FROM ..)
*/
const TYPE_OPERATOR = 2;
/**
* Spaces, tabs, new lines, etc.
*/
const TYPE_WHITESPACE = 3;
/**
* Any type of legal comment.
*
* Bash (#), C (/* *\/) or SQL (--) comments:
*
* -- SQL-comment
*
* #Bash-like comment
*
* /*C-like comment*\/
*
* or:
*
* /*C-like
* comment*\/
*
* Backslashes were added to respect PHP's comments syntax.
*/
const TYPE_COMMENT = 4;
/**
* Boolean values: true or false.
*/
const TYPE_BOOL = 5;
/**
* Numbers: 4, 0x8, 15.16, 23e42, etc.
*/
const TYPE_NUMBER = 6;
/**
* Literal strings: 'string', "test".
* Some of these strings are actually symbols.
*/
const TYPE_STRING = 7;
/**
* Database, table names, variables, etc.
* For example: ```SELECT `foo`, `bar` FROM `database`.`table`;```.
*/
const TYPE_SYMBOL = 8;
/**
* Delimits an unknown string.
* For example: ```SELECT * FROM test;```, `test` is a delimiter.
*/
const TYPE_DELIMITER = 9;
/**
* Labels in LOOP statement, ITERATE statement etc.
* For example (only for begin label):
* begin_label: BEGIN [statement_list] END [end_label]
* begin_label: LOOP [statement_list] END LOOP [end_label]
* begin_label: REPEAT [statement_list] ... END REPEAT [end_label]
* begin_label: WHILE ... DO [statement_list] END WHILE [end_label].
*/
const TYPE_LABEL = 10;
// Flags that describe the tokens in more detail.
// All keywords must have flag 1 so `Context::isKeyword` method doesn't
// require strict comparison.
const FLAG_KEYWORD_RESERVED = 2;
const FLAG_KEYWORD_COMPOSED = 4;
const FLAG_KEYWORD_DATA_TYPE = 8;
const FLAG_KEYWORD_KEY = 16;
const FLAG_KEYWORD_FUNCTION = 32;
// Numbers related flags.
const FLAG_NUMBER_HEX = 1;
const FLAG_NUMBER_FLOAT = 2;
const FLAG_NUMBER_APPROXIMATE = 4;
const FLAG_NUMBER_NEGATIVE = 8;
const FLAG_NUMBER_BINARY = 16;
// Strings related flags.
const FLAG_STRING_SINGLE_QUOTES = 1;
const FLAG_STRING_DOUBLE_QUOTES = 2;
// Comments related flags.
const FLAG_COMMENT_BASH = 1;
const FLAG_COMMENT_C = 2;
const FLAG_COMMENT_SQL = 4;
const FLAG_COMMENT_MYSQL_CMD = 8;
// Operators related flags.
const FLAG_OPERATOR_ARITHMETIC = 1;
const FLAG_OPERATOR_LOGICAL = 2;
const FLAG_OPERATOR_BITWISE = 4;
const FLAG_OPERATOR_ASSIGNMENT = 8;
const FLAG_OPERATOR_SQL = 16;
// Symbols related flags.
const FLAG_SYMBOL_VARIABLE = 1;
const FLAG_SYMBOL_BACKTICK = 2;
const FLAG_SYMBOL_USER = 4;
const FLAG_SYMBOL_SYSTEM = 8;
const FLAG_SYMBOL_PARAMETER = 16;
/**
* The token it its raw string representation.
*
* @var string
*/
public $token;
/**
* The value this token contains (i.e. token after some evaluation).
*
* @var mixed
*/
public $value;
/**
* The keyword value this token contains, always uppercase.
*
* @var mixed|string|null
*/
public $keyword = null;
/**
* The type of this token.
*
* @var int
*/
public $type;
/**
* The flags of this token.
*
* @var int
*/
public $flags;
/**
* The position in the initial string where this token started.
*
* The position is counted in chars, not bytes, so you should
* use mb_* functions to properly handle utf-8 multibyte chars.
*
* @var int|null
*/
public $position;
/**
* Constructor.
*
* @param string $token The value of the token.
* @param int $type The type of the token.
* @param int $flags The flags of the token.
*/
public function __construct( $token, $type = 0, $flags = 0 ) {
$this->token = $token;
$this->type = $type;
$this->flags = $flags;
$this->value = $this->extract();
}
/**
* Check if the token matches the given parameters.
*
* @param int|null $type The type of the token.
* @param int|null $flags The flags of the token.
* @param array|null $values The values of the token.
*
* @return bool
*/
public function matches( $type = null, $flags = null, $values = null ) {
if ( null === $type && null === $flags && ( null === $values || array() === $values ) ) {
return ! $this->is_semantically_void();
}
return (
( null === $type || $this->type === $type )
&& ( null === $flags || ( $this->flags & $flags ) )
&& ( null === $values || in_array( strtoupper( $this->value ?? '' ), $values, true ) )
);
}
/**
* Check if the token is semantically void (i.e. whitespace or comment).
*
* @return bool
*/
public function is_semantically_void() {
return $this->matches( self::TYPE_WHITESPACE ) || $this->matches( self::TYPE_COMMENT );
}
/**
* Does little processing to the token to extract a value.
*
* If no processing can be done it will return the initial string.
*
* @return mixed
*/
private function extract() {
switch ( $this->type ) {
case self::TYPE_KEYWORD:
$this->keyword = strtoupper( $this->token ?? '' );
if ( ! ( $this->flags & self::FLAG_KEYWORD_RESERVED ) ) {
/*
* Unreserved keywords should stay the way they are
* because they might represent field names.
*/
return $this->token;
}
return $this->keyword;
case self::TYPE_WHITESPACE:
return ' ';
case self::TYPE_BOOL:
return strtoupper( $this->token ?? '' ) === 'TRUE';
case self::TYPE_NUMBER:
$ret = str_replace( '--', '', $this->token ); // e.g. ---42 === -42.
if ( $this->flags & self::FLAG_NUMBER_HEX ) {
$ret = str_replace( array( '-', '+' ), '', $this->token );
if ( $this->flags & self::FLAG_NUMBER_NEGATIVE ) {
$ret = -hexdec( $ret );
} else {
$ret = hexdec( $ret );
}
} elseif ( ( $this->flags & self::FLAG_NUMBER_APPROXIMATE ) || ( $this->flags & self::FLAG_NUMBER_FLOAT ) ) {
$ret = (float) $ret;
} elseif ( ! ( $this->flags & self::FLAG_NUMBER_BINARY ) ) {
$ret = (int) $ret;
}
return $ret;
case self::TYPE_STRING:
// Trims quotes.
$str = $this->token;
$str = mb_substr( $str, 1, -1, 'UTF-8' );
// Removes surrounding quotes.
$quote = $this->token[0];
$str = str_replace( $quote . $quote, $quote, $str );
/*
* Finally unescapes the string.
*
* `stripcslashes` replaces escape sequences with their
* representation.
*/
$str = stripcslashes( $str );
return $str;
case self::TYPE_SYMBOL:
$str = $this->token;
if ( isset( $str[0] ) && ( '@' === $str[0] ) ) {
/*
* `mb_strlen($str)` must be used instead of `null` because
* in PHP 5.3- the `null` parameter isn't handled correctly.
*/
$str = mb_substr(
$str,
! empty( $str[1] ) && ( '@' === $str[1] ) ? 2 : 1,
mb_strlen( $str ),
'UTF-8'
);
}
if ( isset( $str[0] ) && ( ':' === $str[0] ) ) {
$str = mb_substr( $str, 1, mb_strlen( $str ), 'UTF-8' );
}
if ( isset( $str[0] ) && ( ( '`' === $str[0] ) || ( '"' === $str[0] ) || ( '\'' === $str[0] ) ) ) {
$quote = $str[0];
$str = str_replace( $quote . $quote, $quote, $str );
$str = mb_substr( $str, 1, -1, 'UTF-8' );
}
return $str;
}
return $this->token;
}
}
@@ -0,0 +1,65 @@
<?php
/**
* Main integration file.
*
* @package wp-sqlite-integration
* @since 1.0.0
*/
// Require the constants file.
require_once dirname( __DIR__, 2 ) . '/constants.php';
// Bail early if DB_ENGINE is not defined as sqlite.
if ( ! defined( 'DB_ENGINE' ) || 'sqlite' !== DB_ENGINE ) {
return;
}
if ( ! extension_loaded( 'pdo' ) ) {
wp_die(
new WP_Error(
'pdo_not_loaded',
sprintf(
'<h1>%1$s</h1><p>%2$s</p>',
'PHP PDO Extension is not loaded',
'Your PHP installation appears to be missing the PDO extension which is required for this version of WordPress and the type of database you have specified.'
)
),
'PHP PDO Extension is not loaded.'
);
}
if ( ! extension_loaded( 'pdo_sqlite' ) ) {
wp_die(
new WP_Error(
'pdo_driver_not_loaded',
sprintf(
'<h1>%1$s</h1><p>%2$s</p>',
'PDO Driver for SQLite is missing',
'Your PHP installation appears not to have the right PDO drivers loaded. These are required for this version of WordPress and the type of database you have specified.'
)
),
'PDO Driver for SQLite is missing.'
);
}
require_once __DIR__ . '/class-wp-sqlite-lexer.php';
require_once __DIR__ . '/class-wp-sqlite-query-rewriter.php';
require_once __DIR__ . '/class-wp-sqlite-translator.php';
require_once __DIR__ . '/class-wp-sqlite-token.php';
require_once __DIR__ . '/class-wp-sqlite-pdo-user-defined-functions.php';
require_once __DIR__ . '/class-wp-sqlite-db.php';
require_once __DIR__ . '/install-functions.php';
/*
* Debug: Cross-check with MySQL.
* This is for debugging purpose only and requires files
* that are present in the GitHub repository
* but not the plugin published on WordPress.org.
*/
$crosscheck_tests_file_path = dirname( __DIR__, 2 ) . '/tests/class-wp-sqlite-crosscheck-db.php';
if ( defined( 'SQLITE_DEBUG_CROSSCHECK' ) && SQLITE_DEBUG_CROSSCHECK && file_exists( $crosscheck_tests_file_path ) ) {
require_once $crosscheck_tests_file_path;
$GLOBALS['wpdb'] = new WP_SQLite_Crosscheck_DB();
} else {
$GLOBALS['wpdb'] = new WP_SQLite_DB();
}
@@ -0,0 +1,230 @@
<?php
/**
* Main integration file.
*
* @package wp-sqlite-integration
* @since 1.0.0
*/
/**
* Function to create tables according to the schemas of WordPress.
*
* This is executed only once while installation.
*
* @since 1.0.0
*
* @return boolean
*
* @throws PDOException If the database connection fails.
*/
function sqlite_make_db_sqlite() {
include_once ABSPATH . 'wp-admin/includes/schema.php';
$table_schemas = wp_get_db_schema();
$queries = explode( ';', $table_schemas );
try {
$pdo = new PDO( 'sqlite:' . FQDB, null, null, array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) ); // phpcs:ignore WordPress.DB.RestrictedClasses
} catch ( PDOException $err ) {
$err_data = $err->errorInfo; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$message = 'Database connection error!<br />';
$message .= sprintf( 'Error message is: %s', $err_data[2] );
wp_die( $message, 'Database Error!' );
}
$translator = new WP_SQLite_Translator( $pdo );
$query = null;
try {
$translator->begin_transaction();
foreach ( $queries as $query ) {
$query = trim( $query );
if ( empty( $query ) ) {
continue;
}
$result = $translator->query( $query );
if ( false === $result ) {
throw new PDOException( $translator->get_error_message() );
}
}
$translator->commit();
} catch ( PDOException $err ) {
$err_data = $err->errorInfo; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$err_code = $err_data[1];
$translator->rollback();
$message = sprintf(
'Error occurred while creating tables or indexes...<br />Query was: %s<br />',
var_export( $query, true )
);
$message .= sprintf( 'Error message is: %s', $err_data[2] );
wp_die( $message, 'Database Error!' );
}
/*
* Debug: Cross-check with MySQL.
* This is for debugging purpose only and requires files
* that are present in the GitHub repository
* but not the plugin published on WordPress.org.
*/
if ( defined( 'SQLITE_DEBUG_CROSSCHECK' ) && SQLITE_DEBUG_CROSSCHECK ) {
$host = DB_HOST;
$port = 3306;
if ( str_contains( $host, ':' ) ) {
$host_parts = explode( ':', $host );
$host = $host_parts[0];
$port = $host_parts[1];
}
$dsn = 'mysql:host=' . $host . '; port=' . $port . '; dbname=' . DB_NAME;
$pdo_mysql = new PDO( $dsn, DB_USER, DB_PASSWORD, array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) ); // phpcs:ignore WordPress.DB.RestrictedClasses.mysql__PDO
$pdo_mysql->query( 'SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";' );
$pdo_mysql->query( 'SET time_zone = "+00:00";' );
foreach ( $queries as $query ) {
$query = trim( $query );
if ( empty( $query ) ) {
continue;
}
try {
$pdo_mysql->beginTransaction();
$pdo_mysql->query( $query );
} catch ( PDOException $err ) {
$err_data = $err->errorInfo; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$err_code = $err_data[1];
// phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
if ( 5 == $err_code || 6 == $err_code ) {
// If the database is locked, commit again.
$pdo_mysql->commit();
} else {
$pdo_mysql->rollBack();
$message = sprintf(
'Error occurred while creating tables or indexes...<br />Query was: %s<br />',
var_export( $query, true )
);
$message .= sprintf( 'Error message is: %s', $err_data[2] );
wp_die( $message, 'Database Error!' );
}
}
}
}
$pdo = null;
return true;
}
if ( ! function_exists( 'wp_install' ) ) {
/**
* Installs the site.
*
* Runs the required functions to set up and populate the database,
* including primary admin user and initial options.
*
* @since 1.0.0
*
* @param string $blog_title Site title.
* @param string $user_name User's username.
* @param string $user_email User's email.
* @param bool $is_public Whether the site is public.
* @param string $deprecated Optional. Not used.
* @param string $user_password Optional. User's chosen password. Default empty (random password).
* @param string $language Optional. Language chosen. Default empty.
* @return array {
* Data for the newly installed site.
*
* @type string $url The URL of the site.
* @type int $user_id The ID of the site owner.
* @type string $password The password of the site owner, if their user account didn't already exist.
* @type string $password_message The explanatory message regarding the password.
* }
*/
function wp_install( $blog_title, $user_name, $user_email, $is_public, $deprecated = '', $user_password = '', $language = '' ) {
if ( ! empty( $deprecated ) ) {
_deprecated_argument( __FUNCTION__, '2.6.0' );
}
wp_check_mysql_version();
wp_cache_flush();
/* SQLite changes: Replace the call to make_db_current_silent() with sqlite_make_db_sqlite(). */
sqlite_make_db_sqlite(); // phpcs:ignore PHPCompatibility.Extensions.RemovedExtensions.sqliteRemoved
populate_options();
populate_roles();
update_option( 'blogname', $blog_title );
update_option( 'admin_email', $user_email );
update_option( 'blog_public', $is_public );
// Freshness of site - in the future, this could get more specific about actions taken, perhaps.
update_option( 'fresh_site', 1 );
if ( $language ) {
update_option( 'WPLANG', $language );
}
$guessurl = wp_guess_url();
update_option( 'siteurl', $guessurl );
// If not a public site, don't ping.
if ( ! $is_public ) {
update_option( 'default_pingback_flag', 0 );
}
/*
* Create default user. If the user already exists, the user tables are
* being shared among sites. Just set the role in that case.
*/
$user_id = username_exists( $user_name );
$user_password = trim( $user_password );
$email_password = false;
$user_created = false;
if ( ! $user_id && empty( $user_password ) ) {
$user_password = wp_generate_password( 12, false );
$message = __( '<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.', 'sqlite-database-integration' );
$user_id = wp_create_user( $user_name, $user_password, $user_email );
update_user_meta( $user_id, 'default_password_nag', true );
$email_password = true;
$user_created = true;
} elseif ( ! $user_id ) {
// Password has been provided.
$message = '<em>' . __( 'Your chosen password.', 'sqlite-database-integration' ) . '</em>';
$user_id = wp_create_user( $user_name, $user_password, $user_email );
$user_created = true;
} else {
$message = __( 'User already exists. Password inherited.', 'sqlite-database-integration' );
}
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
if ( $user_created ) {
$user->user_url = $guessurl;
wp_update_user( $user );
}
wp_install_defaults( $user_id );
wp_install_maybe_enable_pretty_permalinks();
flush_rewrite_rules();
wp_new_blog_notification( $blog_title, $guessurl, $user_id, ( $email_password ? $user_password : __( 'The password you chose during installation.', 'sqlite-database-integration' ) ) );
wp_cache_flush();
/**
* Fires after a site is fully installed.
*
* @since 3.9.0
*
* @param WP_User $user The site owner.
*/
do_action( 'wp_install', $user );
return array(
'url' => $guessurl,
'user_id' => $user_id,
'password' => $user_password,
'password_message' => $message,
);
}
}
+34
View File
@@ -0,0 +1,34 @@
# Only allow direct access to specific Web-available files.
# Apache 2.2
<IfModule !mod_authz_core.c>
Order Deny,Allow
Deny from all
</IfModule>
# Apache 2.4
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
# Akismet CSS and JS
<FilesMatch "^(form\.js|akismet(-frontend|-admin)?\.js|akismet(-admin)?(-rtl)?\.css|inter\.css)$">
<IfModule !mod_authz_core.c>
Allow from all
</IfModule>
<IfModule mod_authz_core.c>
Require all granted
</IfModule>
</FilesMatch>
# Akismet images
<FilesMatch "^(logo-a-2x\.png|akismet-refresh-logo\.svg|akismet-refresh-logo@2x\.png|arrow-left\.svg|icon-external\.svg|akismet-activation-banner-elements\.png)$">
<IfModule !mod_authz_core.c>
Allow from all
</IfModule>
<IfModule mod_authz_core.c>
Require all granted
</IfModule>
</FilesMatch>
+339
View File
@@ -0,0 +1,339 @@
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.
@@ -0,0 +1,483 @@
body {
--akismet-color-charcoal: #272635;
--akismet-color-light-grey: #f6f7f7;
--akismet-color-mid-grey: #a7aaad;
--akismet-color-dark-grey: #646970;
--akismet-color-grey-80: #2c3338;
--akismet-color-grey-100: #101517;
--akismet-color-white: #fff;
--akismet-color-mid-green: #357b49;
--akismet-color-mid-red: #e82c3f;
--akismet-color-light-blue: #256eff;
--akismet-color-notice-light-green: #dbf0e1;
--akismet-color-notice-dark-green: #69bf82;
--akismet-color-notice-light-red: #ffdbde;
--akismet-color-notice-dark-red: #ff6676;
--akismet-color-notice-yellow: #e5c133;
}
#akismet-plugin-container {
background-color: var(--akismet-color-light-grey);
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen-Sans', 'Ubuntu', 'Cantarell', 'Helvetica Neue', sans-serif;
}
#akismet-plugin-container a {
color: var(--akismet-color-mid-green);
}
#akismet-plugin-container a.akismet-button {
background-color: var(--akismet-color-mid-green);
color: var(--akismet-color-white);
}
#akismet-plugin-container button:focus-visible,
#akismet-plugin-container input:focus-visible,
#akismet-plugin-container a:focus-visible {
border: 0;
box-shadow: none;
outline: 2px solid var(--akismet-color-light-blue);
}
.akismet-masthead {
box-shadow: none;
}
.akismet-masthead__logo {
margin: 20px 0;
}
.akismet-section-header {
box-shadow: none;
margin-bottom: 0;
}
.akismet-section-header__label {
color: var(--akismet-color-charcoal);
font-weight: 600;
}
.akismet-button, .akismet-button:hover {
background-color: var(--akismet-color-mid-green);
border: 0;
color: #fff;
}
/* Need this specificity to override the existing header rule */
.akismet-new-snapshot h3.akismet-new-snapshot__header {
background: none;
font-size: 13px;
color: var(--akismet-color-charcoal);
text-align: left;
text-transform: none;
}
.akismet-new-snapshot .akismet-new-snapshot__number {
color: var(--akismet-color-charcoal);
letter-spacing: -1px;
text-align: left;
}
.akismet-new-snapshot li.akismet-new-snapshot__item {
color: var(--akismet-color-dark-grey);
font-size: 13px;
text-align: left;
text-transform: none;
}
.akismet-masthead__logo-link {
min-height: 50px;
}
.akismet-masthead__back-link-container {
margin-top: 16px;
margin-bottom: 2px;
}
/* Need this specificity to override the existing link rule */
#akismet-plugin-container a.akismet-masthead__back-link {
background-image: url(img/arrow-left.svg);
background-position: left;
background-repeat: no-repeat;
background-size: 16px;
color: var(--akismet-color-charcoal);
font-weight: 400;
padding-left: 20px;
text-decoration: none;
}
#akismet-plugin-container a.akismet-masthead__back-link:hover {
text-decoration: underline;
}
.akismet-new-snapshot__item {
border-top: 1px solid var(--akismet-color-light-grey);
border-left: 1px solid var(--akismet-color-light-grey);
padding: 1em;
}
.akismet-new-snapshot li:first-child {
border-left: none;
}
.akismet-new-snapshot__list {
display: flex;
margin-bottom: 0;
}
.akismet-new-snapshot__item {
flex: 1 0 33.33%;
margin-bottom: 0;
padding-left: 1.5em;
padding-right: 1.5em;
}
.akismet-new-snapshot__chart {
padding: 1em;
}
.akismet-box {
border: 0;
}
.akismet-box,
.akismet-card {
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06), 0 0 2px rgba(0, 0, 0, 0.16);
border-radius: 8px;
overflow: hidden;
}
.akismet-card {
margin: 32px auto 0 auto;
}
.akismet-lower {
padding-top: 0;
}
.akismet-lower .inside {
padding: 0;
}
.akismet-section-header__label {
margin: 0;
}
.akismet-settings__row {
border-bottom: 1px solid var(--akismet-color-light-grey);
display: block;
padding: 1em 1.5em;
}
.akismet-settings__row-input {
margin-left: auto;
}
.akismet-settings__row-title {
font-weight: 500;
font-size: 1em;
margin: 0;
margin-bottom: 1em;
}
.akismet-settings__row-description {
margin-top: 0.5em;
}
.akismet-card-actions {
display: flex;
justify-content: flex-end;
padding: 1em;
}
.akismet-card-actions__secondary-action {
align-self: center;
margin-right: auto;
}
.akismet-card-actions__secondary-action a[target="_blank"]::after {
background: url('img/icon-external.svg') no-repeat;
background-size: contain;
content: "";
display: inline-block;
height: 16px;
margin-left: 5px;
vertical-align: middle;
width: 16px;
}
.akismet-settings__row label {
padding-bottom: 1em;
}
.akismet-settings__row-note {
font-size: 0.9em;
margin-top: 0.4em;
}
.akismet-settings__row input[type="checkbox"],
.akismet-settings__row input[type="radio"] {
accent-color: var(--akismet-color-mid-green);
box-shadow: none;
flex-shrink: 0;
margin: 2px 0 0 0;
}
.akismet-settings__row input[type="checkbox"] {
margin-top: 1px;
vertical-align: top;
-webkit-appearance: checkbox;
}
.akismet-settings__row input[type="radio"] {
-webkit-appearance: radio;
}
/* Fix up misbehaving wp-admin styles in Chrome (from forms and colors stylesheets) */
.akismet-settings__row input[type="checkbox"]:checked:before {
content: '';
}
.akismet-settings__row input[type="radio"]:checked:before {
background: none;
}
.akismet-settings__row input[type="checkbox"]:checked:hover,
.akismet-settings__row input[type="radio"]:checked:hover {
accent-color: var(--akismet-color-mid-green);
}
.akismet-button:disabled {
background-color: var(--akismet-color-mid-grey);
color: var(--akismet-color-white);
cursor: arrow;
}
.akismet-awaiting-stats,
.akismet-account {
padding: 0 1rem 1rem 1rem;
margin: 0;
}
.akismet-account {
padding-bottom: 0;
}
.akismet-account th {
font-weight: 500;
padding-right: 1em;
}
.akismet-account th, .akismet-account td {
padding-bottom: 1em;
}
.akismet-settings__row-input-label {
align-items: center;
display: flex;
}
.akismet-settings__row-label-text {
padding-left: 0.5em;
margin-top: 2px;
}
.akismet-alert {
border-left: 8px solid;
border-radius: 8px;
margin: 20px 0;
padding: 0.2em 1em;
}
.akismet-alert__heading {
font-size: 1em;
}
.akismet-alert.is-good {
background-color: var(--akismet-color-notice-light-green);
border-left-color: var(--akismet-color-notice-dark-green);
}
.akismet-alert.is-neutral {
background-color: var(--akismet-color-white);
border-left-color: var(--akismet-color-dark-grey);
}
.akismet-alert.is-bad {
background-color: var(--akismet-color-notice-light-red);
border-left-color: var(--akismet-color-notice-dark-red);
}
.akismet-alert.is-commercial {
background-color: var(--akismet-color-white);
border-color: var(--akismet-color-mid-grey);
border-bottom-width: 1px;
border-left-color: var(--akismet-color-notice-yellow);
display: flex;
padding-bottom: 1em;
}
#akismet-plugin-container .akismet-alert.is-good a,
#akismet-plugin-container .akismet-alert.is-bad a {
/* For better contrast - green isn't great */
color: var(--akismet-color-grey-80);
}
.akismet-alert-header {
font-size: 16px;
margin-bottom: 0.5em;
}
.akismet-alert-button-wrapper {
align-self: center;
margin-left: 2em;
min-width: 120px;
}
.akismet-alert-info {
text-wrap: pretty;
margin: 0.5em 0;
}
/* Setup - API key input */
.akismet-enter-api-key-box {
margin: 1.5rem 0;
}
.akismet-enter-api-key-box__reveal {
background: none;
border: 0;
color: var(--akismet-color-mid-green);
cursor: pointer;
text-decoration: underline;
}
.akismet-enter-api-key-box__form-wrapper {
display: none;
margin-top: 1.5rem;
}
.akismet-enter-api-key-box__input-wrapper {
box-sizing: border-box;
display: flex;
flex-wrap: nowrap;
padding: 0 1.5rem;
width: 100%;
}
.akismet-enter-api-key-box__key-input {
flex-grow: 1;
margin-right: 1rem;
}
h3.akismet-enter-api-key-box__header {
padding-top: 0;
padding-bottom: 1em;
text-align: left;
}
/* Notices > Activation (shown on edit-comments.php) */
#akismet-setup-prompt {
background: none;
border: none;
margin: 0;
padding: 0;
width: 100%;
}
.akismet-activate {
align-items: center;
/* background-image is defined via an inline style in class.akismet-admin.php */
background-color: var(--akismet-color-light-grey);
background-position: calc(100% - 1em) center;
background-repeat: no-repeat;
background-size: 140px;
border: 1px solid var(--akismet-color-mid-green);
border-left-width: 4px;
display: flex;
justify-content: space-between;
margin: 15px 0;
min-height: 60px;
overflow: hidden;
padding: 5px 160px 5px 5px;
position: relative;
}
.akismet-activate__button,
.akismet-activate__button:hover,
.akismet-activate__button:visited {
margin: 0 1em;
}
.akismet-activate__description {
color: var(--akismet-color-charcoal);
flex-grow: 1;
font-size: 16px;
font-weight: 600;
margin: 0 auto;
text-align: center;
text-wrap: pretty;
}
/* Gutenberg medium breakpoint */
@media screen and (max-width: 782px) {
.akismet-new-snapshot__list {
display: block;
}
.akismet-new-snapshot__number {
float: right;
font-size: 20px;
font-weight: 500;
margin-top: -16px;
}
.akismet-new-snapshot__header {
font-size: 14px;
font-weight: 500;
}
.akismet-new-snapshot__text {
font-size: 12px;
}
.akismet-settings__row input[type="checkbox"],
.akismet-settings__row input[type="radio"] {
height: 24px;
width: 24px;
}
.akismet-settings__row-label-text {
padding-left: 0.8em;
}
.akismet-settings__row input[type="checkbox"],
.akismet-settings__row input[type="radio"] {
margin-top: 0;
}
.akismet-activate {
background-size: 120px;
padding-right: 134px;
}
.akismet-activate__button {
white-space: normal;
}
.akismet-activate__description {
font-size: 14px;
margin-right: 1em;
}
}
/* Gutenberg small breakpoint */
@media screen and (max-width: 600px) {
.akismet-activate__button,
.akismet-activate__button:hover {
font-size: 13px;
}
.akismet-activate__description {
display: none;
}
}
@@ -0,0 +1,7 @@
document.addEventListener( 'DOMContentLoaded', function() {
// Prevent aggressive iframe caching in Firefox
var statsIframe = document.getElementById( 'stats-iframe' );
if ( statsIframe ) {
statsIframe.contentWindow.location.href = statsIframe.src;
}
} );
@@ -0,0 +1,376 @@
/**
* Observe how the user enters content into the comment form in order to determine whether it's a bot or not.
*
* Note that no actual input is being saved here, only counts and timings between events.
*/
( function() {
// Passive event listeners are guaranteed to never call e.preventDefault(),
// but they're not supported in all browsers. Use this feature detection
// to determine whether they're available for use.
var supportsPassive = false;
try {
var opts = Object.defineProperty( {}, 'passive', {
get : function() {
supportsPassive = true;
}
} );
window.addEventListener( 'testPassive', null, opts );
window.removeEventListener( 'testPassive', null, opts );
} catch ( e ) {}
function init() {
var input_begin = '';
var keydowns = {};
var lastKeyup = null;
var lastKeydown = null;
var keypresses = [];
var modifierKeys = [];
var correctionKeys = [];
var lastMouseup = null;
var lastMousedown = null;
var mouseclicks = [];
var mousemoveTimer = null;
var lastMousemoveX = null;
var lastMousemoveY = null;
var mousemoveStart = null;
var mousemoves = [];
var touchmoveCountTimer = null;
var touchmoveCount = 0;
var lastTouchEnd = null;
var lastTouchStart = null;
var touchEvents = [];
var scrollCountTimer = null;
var scrollCount = 0;
var correctionKeyCodes = [ 'Backspace', 'Delete', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Home', 'End', 'PageUp', 'PageDown' ];
var modifierKeyCodes = [ 'Shift', 'CapsLock' ];
var forms = document.querySelectorAll( 'form[method=post]' );
for ( var i = 0; i < forms.length; i++ ) {
var form = forms[i];
var formAction = form.getAttribute( 'action' );
// Ignore forms that POST directly to other domains; these could be things like payment forms.
if ( formAction ) {
// Check that the form is posting to an external URL, not a path.
if ( formAction.indexOf( 'http://' ) == 0 || formAction.indexOf( 'https://' ) == 0 ) {
if ( formAction.indexOf( 'http://' + window.location.hostname + '/' ) != 0 && formAction.indexOf( 'https://' + window.location.hostname + '/' ) != 0 ) {
continue;
}
}
}
form.addEventListener( 'submit', function () {
var ak_bkp = prepare_timestamp_array_for_request( keypresses );
var ak_bmc = prepare_timestamp_array_for_request( mouseclicks );
var ak_bte = prepare_timestamp_array_for_request( touchEvents );
var ak_bmm = prepare_timestamp_array_for_request( mousemoves );
var input_fields = {
// When did the user begin entering any input?
'bib': input_begin,
// When was the form submitted?
'bfs': Date.now(),
// How many keypresses did they make?
'bkpc': keypresses.length,
// How quickly did they press a sample of keys, and how long between them?
'bkp': ak_bkp,
// How quickly did they click the mouse, and how long between clicks?
'bmc': ak_bmc,
// How many mouseclicks did they make?
'bmcc': mouseclicks.length,
// When did they press modifier keys (like Shift or Capslock)?
'bmk': modifierKeys.join( ';' ),
// When did they correct themselves? e.g., press Backspace, or use the arrow keys to move the cursor back
'bck': correctionKeys.join( ';' ),
// How many times did they move the mouse?
'bmmc': mousemoves.length,
// How many times did they move around using a touchscreen?
'btmc': touchmoveCount,
// How many times did they scroll?
'bsc': scrollCount,
// How quickly did they perform touch events, and how long between them?
'bte': ak_bte,
// How many touch events were there?
'btec' : touchEvents.length,
// How quickly did they move the mouse, and how long between moves?
'bmm' : ak_bmm
};
var akismet_field_prefix = 'ak_';
if ( this.getElementsByClassName ) {
// Check to see if we've used an alternate field name prefix. We store this as an attribute of the container around some of the Akismet fields.
var possible_akismet_containers = this.getElementsByClassName( 'akismet-fields-container' );
for ( var containerIndex = 0; containerIndex < possible_akismet_containers.length; containerIndex++ ) {
var container = possible_akismet_containers.item( containerIndex );
if ( container.getAttribute( 'data-prefix' ) ) {
akismet_field_prefix = container.getAttribute( 'data-prefix' );
break;
}
}
}
for ( var field_name in input_fields ) {
var field = document.createElement( 'input' );
field.setAttribute( 'type', 'hidden' );
field.setAttribute( 'name', akismet_field_prefix + field_name );
field.setAttribute( 'value', input_fields[ field_name ] );
this.appendChild( field );
}
}, supportsPassive ? { passive: true } : false );
form.addEventListener( 'keydown', function ( e ) {
// If you hold a key down, some browsers send multiple keydown events in a row.
// Ignore any keydown events for a key that hasn't come back up yet.
if ( e.key in keydowns ) {
return;
}
var keydownTime = ( new Date() ).getTime();
keydowns[ e.key ] = [ keydownTime ];
if ( ! input_begin ) {
input_begin = keydownTime;
}
// In some situations, we don't want to record an interval since the last keypress -- for example,
// on the first keypress, or on a keypress after focus has changed to another element. Normally,
// we want to record the time between the last keyup and this keydown. But if they press a
// key while already pressing a key, we want to record the time between the two keydowns.
var lastKeyEvent = Math.max( lastKeydown, lastKeyup );
if ( lastKeyEvent ) {
keydowns[ e.key ].push( keydownTime - lastKeyEvent );
}
lastKeydown = keydownTime;
}, supportsPassive ? { passive: true } : false );
form.addEventListener( 'keyup', function ( e ) {
if ( ! ( e.key in keydowns ) ) {
// This key was pressed before this script was loaded, or a mouseclick happened during the keypress, or...
return;
}
var keyupTime = ( new Date() ).getTime();
if ( 'TEXTAREA' === e.target.nodeName || 'INPUT' === e.target.nodeName ) {
if ( -1 !== modifierKeyCodes.indexOf( e.key ) ) {
modifierKeys.push( keypresses.length - 1 );
} else if ( -1 !== correctionKeyCodes.indexOf( e.key ) ) {
correctionKeys.push( keypresses.length - 1 );
} else {
// ^ Don't record timings for keys like Shift or backspace, since they
// typically get held down for longer than regular typing.
var keydownTime = keydowns[ e.key ][0];
var keypress = [];
// Keypress duration.
keypress.push( keyupTime - keydownTime );
// Amount of time between this keypress and the previous keypress.
if ( keydowns[ e.key ].length > 1 ) {
keypress.push( keydowns[ e.key ][1] );
}
keypresses.push( keypress );
}
}
delete keydowns[ e.key ];
lastKeyup = keyupTime;
}, supportsPassive ? { passive: true } : false );
form.addEventListener( "focusin", function ( e ) {
lastKeydown = null;
lastKeyup = null;
keydowns = {};
}, supportsPassive ? { passive: true } : false );
form.addEventListener( "focusout", function ( e ) {
lastKeydown = null;
lastKeyup = null;
keydowns = {};
}, supportsPassive ? { passive: true } : false );
}
document.addEventListener( 'mousedown', function ( e ) {
lastMousedown = ( new Date() ).getTime();
}, supportsPassive ? { passive: true } : false );
document.addEventListener( 'mouseup', function ( e ) {
if ( ! lastMousedown ) {
// If the mousedown happened before this script was loaded, but the mouseup happened after...
return;
}
var now = ( new Date() ).getTime();
var mouseclick = [];
mouseclick.push( now - lastMousedown );
if ( lastMouseup ) {
mouseclick.push( lastMousedown - lastMouseup );
}
mouseclicks.push( mouseclick );
lastMouseup = now;
// If the mouse has been clicked, don't record this time as an interval between keypresses.
lastKeydown = null;
lastKeyup = null;
keydowns = {};
}, supportsPassive ? { passive: true } : false );
document.addEventListener( 'mousemove', function ( e ) {
if ( mousemoveTimer ) {
clearTimeout( mousemoveTimer );
mousemoveTimer = null;
}
else {
mousemoveStart = ( new Date() ).getTime();
lastMousemoveX = e.offsetX;
lastMousemoveY = e.offsetY;
}
mousemoveTimer = setTimeout( function ( theEvent, originalMousemoveStart ) {
var now = ( new Date() ).getTime() - 500; // To account for the timer delay.
var mousemove = [];
mousemove.push( now - originalMousemoveStart );
mousemove.push(
Math.round(
Math.sqrt(
Math.pow( theEvent.offsetX - lastMousemoveX, 2 ) +
Math.pow( theEvent.offsetY - lastMousemoveY, 2 )
)
)
);
if ( mousemove[1] > 0 ) {
// If there was no measurable distance, then it wasn't really a move.
mousemoves.push( mousemove );
}
mousemoveStart = null;
mousemoveTimer = null;
}, 500, e, mousemoveStart );
}, supportsPassive ? { passive: true } : false );
document.addEventListener( 'touchmove', function ( e ) {
if ( touchmoveCountTimer ) {
clearTimeout( touchmoveCountTimer );
}
touchmoveCountTimer = setTimeout( function () {
touchmoveCount++;
}, 500 );
}, supportsPassive ? { passive: true } : false );
document.addEventListener( 'touchstart', function ( e ) {
lastTouchStart = ( new Date() ).getTime();
}, supportsPassive ? { passive: true } : false );
document.addEventListener( 'touchend', function ( e ) {
if ( ! lastTouchStart ) {
// If the touchstart happened before this script was loaded, but the touchend happened after...
return;
}
var now = ( new Date() ).getTime();
var touchEvent = [];
touchEvent.push( now - lastTouchStart );
if ( lastTouchEnd ) {
touchEvent.push( lastTouchStart - lastTouchEnd );
}
touchEvents.push( touchEvent );
lastTouchEnd = now;
// Don't record this time as an interval between keypresses.
lastKeydown = null;
lastKeyup = null;
keydowns = {};
}, supportsPassive ? { passive: true } : false );
document.addEventListener( 'scroll', function ( e ) {
if ( scrollCountTimer ) {
clearTimeout( scrollCountTimer );
}
scrollCountTimer = setTimeout( function () {
scrollCount++;
}, 500 );
}, supportsPassive ? { passive: true } : false );
}
/**
* For the timestamp data that is collected, don't send more than `limit` data points in the request.
* Choose a random slice and send those.
*/
function prepare_timestamp_array_for_request( a, limit ) {
if ( ! limit ) {
limit = 100;
}
var rv = '';
if ( a.length > 0 ) {
var random_starting_point = Math.max( 0, Math.floor( Math.random() * a.length - limit ) );
for ( var i = 0; i < limit && i < a.length; i++ ) {
rv += a[ random_starting_point + i ][0];
if ( a[ random_starting_point + i ].length >= 2 ) {
rv += "," + a[ random_starting_point + i ][1];
}
rv += ";";
}
}
return rv;
}
if ( document.readyState !== 'loading' ) {
init();
} else {
document.addEventListener( 'DOMContentLoaded', init );
}
})();
+518
View File
@@ -0,0 +1,518 @@
.wp-admin.jetpack_page_akismet-key-config, .wp-admin.settings_page_akismet-key-config {
background-color:#f3f6f8;
}
#submitted-on {
position: relative;
}
#the-comment-list .author .akismet-user-comment-count {
display: inline;
}
#the-comment-list .author a span {
text-decoration: none;
color: #999;
}
#the-comment-list .author a span.akismet-span-link {
text-decoration: inherit;
color: inherit;
}
#the-comment-list .akismet_remove_url {
margin-left: 3px;
color: #999;
padding: 2px 3px 2px 0;
}
#the-comment-list .akismet_remove_url:hover {
color: #A7301F;
font-weight: bold;
padding: 2px 2px 2px 0;
}
#dashboard_recent_comments .akismet-status {
display: none;
}
.akismet-status {
float: right;
}
.akismet-status a {
color: #AAA;
font-style: italic;
}
table.comments td.comment p a {
text-decoration: underline;
}
table.comments td.comment p a:after {
content: attr(href);
color: #aaa;
display: inline-block; /* Show the URL without the link's underline extending under it. */
padding: 0 1ex; /* Because it's inline block, we can't just use spaces in the content: attribute to separate it from the link text. */
}
.mshot-arrow {
width: 0;
height: 0;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-right: 10px solid #5C5C5C;
position: absolute;
left: -6px;
top: 91px;
}
.mshot-container {
background: #5C5C5C;
position: absolute;
top: -94px;
padding: 7px;
width: 450px;
height: 338px;
z-index: 20000;
-moz-border-radius: 6px;
border-radius: 6px;
-webkit-border-radius: 6px;
}
.akismet-mshot {
position: absolute;
z-index: 100;
}
.akismet-mshot .mshot-image {
margin: 0;
height: 338px;
width: 450px;
}
.checkforspam {
display: inline-block !important;
}
.checkforspam-spinner {
display: inline-block;
margin-top: 7px;
}
.akismet-right {
float: right;
}
.akismet-card .akismet-right {
margin: 1em 0;
}
.akismet-alert-text {
color: #dd3d36;
font-weight: bold;
font-size: 120%;
margin-top: .5rem;
}
.akismet-new-snapshot {
margin-top: 1em;
text-align: center;
background: #fff;
}
.akismet-new-snapshot h3 {
background: #f5f5f5;
color: #888;
font-size: 11px;
margin: 0;
}
.akismet-new-snapshot ul li {
color: #999;
font-size: 11px;
text-transform: uppercase;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
-ms-box-sizing: border-box;
}
.akismet-new-snapshot__number {
display: block;
font-size: 32px;
font-weight: lighter;
line-height: 1.5em;
}
.akismet-settings th:first-child {
vertical-align: top;
padding-top: 15px;
}
.akismet-settings th.akismet-api-key {
vertical-align: middle;
padding-top: 0;
}
.akismet-settings span.akismet-note {
float: left;
padding-left: 23px;
font-size: 75%;
margin-top: -10px;
}
.jetpack_page_akismet-key-config #wpcontent, .settings_page_akismet-key-config #wpcontent {
padding-left: 0;
}
.akismet-masthead {
background-color:#fff;
text-align:center;
box-shadow:0 1px 0 rgba(200,215,225,0.5),0 1px 2px #e9eff3
}
@media (max-width: 45rem) {
.akismet-masthead {
padding:0 1.25rem
}
}
.akismet-masthead__inside-container {
padding:.375rem 0;
margin:0 auto;
width:100%;
max-width:45rem;
text-align: left;
}
.akismet-masthead__logo-container {
padding:.3125rem 0 0
}
.akismet-masthead__logo-link {
display:inline-block;
outline:none;
vertical-align:middle
}
.akismet-masthead__logo-link:focus {
line-height:0;
box-shadow:0 0 0 2px #78dcfa
}
.akismet-masthead__logo-link+code {
margin:0 10px;
padding:5px 9px;
border-radius:2px;
background:#e6ecf1;
color:#647a88
}
.akismet-masthead__links {
display:-ms-flexbox;
display:flex;
-ms-flex-flow:row wrap;
flex-flow:row wrap;
-ms-flex:2 50%;
flex:2 50%;
-ms-flex-pack:end;
justify-content:flex-end;
margin:0
}
@media (max-width: 480px) {
.akismet-masthead__links {
padding-right:.625rem
}
}
.akismet-masthead__link-li {
margin:0;
padding:0
}
.akismet-masthead__link {
font-style:normal;
color:#0087be;
padding:.625rem;
display:inline-block
}
.akismet-masthead__link:visited {
color:#0087be
}
.akismet-masthead__link:active,.akismet-masthead__link:hover {
color:#00aadc
}
.akismet-masthead__link:hover {
text-decoration:underline
}
.akismet-masthead__link .dashicons {
display:none
}
@media (max-width: 480px) {
.akismet-masthead__link:hover,.akismet-masthead__link:active {
text-decoration:none
}
.akismet-masthead__link .dashicons {
display:block;
font-size:1.75rem
}
.akismet-masthead__link span+span {
display:none
}
}
.akismet-masthead__link-li:last-of-type .akismet-masthead__link {
padding-right:0
}
.akismet-lower {
margin: 0 auto;
text-align: left;
max-width: 45rem;
padding: 1.5rem;
}
.akismet-lower .notice {
margin-bottom: 2rem;
}
.akismet-card {
margin-top: 1rem;
margin-bottom: 0;
position: relative;
box-sizing: border-box;
background: white;
}
.akismet-card:after, .akismet-card .inside:after, .akismet-masthead__logo-container:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.akismet-card .inside {
padding: 1.5rem;
padding-top: 1rem;
}
.akismet-card .akismet-card-actions {
margin-top: 1rem;
}
.jetpack_page_akismet-key-config .update-nag, .settings_page_akismet-key-config .update-nag {
display: none;
}
.akismet-masthead .akismet-right {
line-height: 2.125rem;
font-size: 0.9rem;
}
.akismet-box {
box-sizing: border-box;
background: white;
border: 1px solid rgba(200, 215, 225, 0.5);
}
.akismet-box h2, .akismet-box h3 {
padding: 1.5rem 1.5rem .5rem 1.5rem;
margin: 0;
}
.akismet-box p {
padding: 0 1.5rem 1.5rem 1.5rem;
margin: 0;
}
.akismet-jetpack-email {
font-style: oblique;
}
.akismet-jetpack-gravatar {
padding: 0 0 0 1.5rem;
float: left;
margin-right: 1rem;
width: 54px;
height: 54px;
}
.akismet-box p:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.akismet-box .akismet-right {
padding-right: 1.5rem;
}
.akismet-boxes .akismet-box {
margin-bottom: 0;
padding: 0;
margin-top: -1px;
}
.akismet-boxes .akismet-box:last-child {
margin-bottom: 1.5rem;
}
.akismet-boxes .akismet-box:first-child {
margin-top: 1.5rem;
}
.akismet-box-header {
max-width: 700px;
margin: 0 auto 40px auto;
line-height: 1.5;
}
.akismet-box-header h2 {
margin: 1.5rem 10% 0;
font-size: 1.375rem;
font-weight: 700;
color: #000;
}
.akismet-box .centered {
text-align: center;
}
.akismet-box .akismet-toggles {
margin: 3rem 0;
}
.akismet-box .akismet-ak-connect, .akismet-box .toggle-jp-connect {
display: none;
}
.akismet-button, .akismet-button:hover, .akismet-button:visited {
background: white;
border-color: #c8d7e1;
border-style: solid;
border-width: 1px 1px 2px;
color: #2e4453;
cursor: pointer;
display: inline-block;
margin: 0;
outline: 0;
overflow: hidden;
font-size: 14px;
font-weight: 500;
text-overflow: ellipsis;
text-decoration: none;
vertical-align: top;
box-sizing: border-box;
font-size: 14px;
line-height: 21px;
border-radius: 4px;
padding: 7px 14px 9px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
.akismet-button:hover {
border-color: #a8bece;
}
.akismet-button:active {
border-width: 2px 1px 1px;
}
.akismet-is-primary, .akismet-is-primary:hover, .akismet-is-primary:visited {
background: #00aadc;
border-color: #0087be;
color: white;
}
.akismet-is-primary:hover, .akismet-is-primary:focus {
border-color: #005082;
}
.akismet-is-primary:hover {
border-color: #005082;
}
.akismet-section-header {
position: relative;
margin: 0 auto 0.625rem auto;
padding: 1rem;
box-sizing: border-box;
box-shadow: 0 0 0 1px rgba(200, 215, 225, 0.5), 0 1px 2px #e9eff3;
background: #ffffff;
width: 100%;
padding-top: 0.6875rem;
padding-bottom: 0.6875rem;
display: flex;
}
.akismet-section-header__label {
display: -ms-flexbox;
display: flex;
-ms-flex-align: center;
align-items: center;
-ms-flex-positive: 1;
flex-grow: 1;
line-height: 1.75rem;
position: relative;
font-size: 0.875rem;
color: #4f748e;
}
.akismet-section-header__actions {
line-height: 1.75rem;
}
.akismet-setup-instructions {
text-align: center;
}
.akismet-setup-instructions form {
padding-bottom: 1.5rem;
}
div.error.akismet-usage-limit-alert {
padding: 25px 45px 25px 15px;
display: flex;
align-items: center;
}
#akismet-plugin-container .akismet-usage-limit-alert {
margin: 0 auto 0.625rem auto;
box-sizing: border-box;
box-shadow: 0 0 0 1px rgba(200, 215, 225, 0.5), 0 1px 2px #e9eff3;
border: none;
border-left: 4px solid #d63638;
}
.akismet-usage-limit-alert .akismet-usage-limit-logo {
width: 38px;
min-width: 38px;
height: 38px;
border-radius: 20px;
margin-right: 18px;
background: black;
position: relative;
}
.akismet-usage-limit-alert .akismet-usage-limit-logo img {
position: absolute;
width: 22px;
left: 8px;
top: 10px;
}
.akismet-usage-limit-alert .akismet-usage-limit-text {
flex-grow: 1;
margin-right: 18px;
}
.akismet-usage-limit-alert h3 {
margin: 0;
}
.akismet-usage-limit-alert .akismet-usage-limit-cta {
border-color: none;
text-align: right;
}
#akismet-plugin-container .akismet-usage-limit-cta a {
color: #d63638;
}
@media (max-width: 550px) {
div.error.akismet-usage-limit-alert {
display: block;
}
.akismet-usage-limit-alert .akismet-usage-limit-logo,
.akismet-usage-limit-alert .akismet-usage-limit-text {
margin-bottom: 15px;
}
.akismet-usage-limit-alert .akismet-usage-limit-cta {
text-align: left;
}
}
+421
View File
@@ -0,0 +1,421 @@
jQuery( function ( $ ) {
var mshotRemovalTimer = null;
var mshotRetryTimer = null;
var mshotTries = 0;
var mshotRetryInterval = 1000;
var mshotEnabledLinkSelector = 'a[id^="author_comment_url"], tr.pingback td.column-author a:first-of-type, td.comment p a';
var preloadedMshotURLs = [];
$('.akismet-status').each(function () {
var thisId = $(this).attr('commentid');
$(this).prependTo('#comment-' + thisId + ' .column-comment');
});
$('.akismet-user-comment-count').each(function () {
var thisId = $(this).attr('commentid');
$(this).insertAfter('#comment-' + thisId + ' .author strong:first').show();
});
akismet_enable_comment_author_url_removal();
$( '#the-comment-list' ).on( 'click', '.akismet_remove_url', function () {
var thisId = $(this).attr('commentid');
var data = {
action: 'comment_author_deurl',
_wpnonce: WPAkismet.comment_author_url_nonce,
id: thisId
};
$.ajax({
url: ajaxurl,
type: 'POST',
data: data,
beforeSend: function () {
// Removes "x" link
$("a[commentid='"+ thisId +"']").hide();
// Show temp status
$("#author_comment_url_"+ thisId).html( $( '<span/>' ).text( WPAkismet.strings['Removing...'] ) );
},
success: function (response) {
if (response) {
// Show status/undo link
$("#author_comment_url_"+ thisId)
.attr('cid', thisId)
.addClass('akismet_undo_link_removal')
.html(
$( '<span/>' ).text( WPAkismet.strings['URL removed'] )
)
.append( ' ' )
.append(
$( '<span/>' )
.text( WPAkismet.strings['(undo)'] )
.addClass( 'akismet-span-link' )
);
}
}
});
return false;
}).on( 'click', '.akismet_undo_link_removal', function () {
var thisId = $(this).attr('cid');
var thisUrl = $(this).attr('href');
var data = {
action: 'comment_author_reurl',
_wpnonce: WPAkismet.comment_author_url_nonce,
id: thisId,
url: thisUrl
};
$.ajax({
url: ajaxurl,
type: 'POST',
data: data,
beforeSend: function () {
// Show temp status
$("#author_comment_url_"+ thisId).html( $( '<span/>' ).text( WPAkismet.strings['Re-adding...'] ) );
},
success: function (response) {
if (response) {
// Add "x" link
$("a[commentid='"+ thisId +"']").show();
// Show link. Core strips leading http://, so let's do that too.
$("#author_comment_url_"+ thisId).removeClass('akismet_undo_link_removal').text( thisUrl.replace( /^http:\/\/(www\.)?/ig, '' ) );
}
}
});
return false;
});
// Show a preview image of the hovered URL. Applies to author URLs and URLs inside the comments.
if ( "enable_mshots" in WPAkismet && WPAkismet.enable_mshots ) {
$( '#the-comment-list' ).on( 'mouseover', mshotEnabledLinkSelector, function () {
clearTimeout( mshotRemovalTimer );
if ( $( '.akismet-mshot' ).length > 0 ) {
if ( $( '.akismet-mshot:first' ).data( 'link' ) == this ) {
// The preview is already showing for this link.
return;
}
else {
// A new link is being hovered, so remove the old preview.
$( '.akismet-mshot' ).remove();
}
}
clearTimeout( mshotRetryTimer );
var linkUrl = $( this ).attr( 'href' );
if ( preloadedMshotURLs.indexOf( linkUrl ) !== -1 ) {
// This preview image was already preloaded, so begin with a retry URL so the user doesn't see the placeholder image for the first second.
mshotTries = 2;
}
else {
mshotTries = 1;
}
var mShot = $( '<div class="akismet-mshot mshot-container"><div class="mshot-arrow"></div><img src="' + akismet_mshot_url( linkUrl, mshotTries ) + '" width="450" height="338" class="mshot-image" /></div>' );
mShot.data( 'link', this );
mShot.data( 'url', linkUrl );
mShot.find( 'img' ).on( 'load', function () {
$( '.akismet-mshot' ).data( 'pending-request', false );
} );
var offset = $( this ).offset();
mShot.offset( {
left : Math.min( $( window ).width() - 475, offset.left + $( this ).width() + 10 ), // Keep it on the screen if the link is near the edge of the window.
top: offset.top + ( $( this ).height() / 2 ) - 101 // 101 = top offset of the arrow plus the top border thickness
} );
$( 'body' ).append( mShot );
mshotRetryTimer = setTimeout( retryMshotUntilLoaded, mshotRetryInterval );
} ).on( 'mouseout', 'a[id^="author_comment_url"], tr.pingback td.column-author a:first-of-type, td.comment p a', function () {
mshotRemovalTimer = setTimeout( function () {
clearTimeout( mshotRetryTimer );
$( '.akismet-mshot' ).remove();
}, 200 );
} );
var preloadDelayTimer = null;
$( window ).on( 'scroll resize', function () {
clearTimeout( preloadDelayTimer );
preloadDelayTimer = setTimeout( preloadMshotsInViewport, 500 );
} );
preloadMshotsInViewport();
}
/**
* The way mShots works is if there was no screenshot already recently generated for the URL,
* it returns a "loading..." image for the first request. Then, some subsequent request will
* receive the actual screenshot, but it's unknown how long it will take. So, what we do here
* is continually re-request the mShot, waiting a second after every response until we get the
* actual screenshot.
*/
function retryMshotUntilLoaded() {
clearTimeout( mshotRetryTimer );
var imageWidth = $( '.akismet-mshot img' ).get(0).naturalWidth;
if ( imageWidth == 0 ) {
// It hasn't finished loading yet the first time. Check again shortly.
setTimeout( retryMshotUntilLoaded, mshotRetryInterval );
}
else if ( imageWidth == 400 ) {
// It loaded the preview image.
if ( mshotTries == 20 ) {
// Give up if we've requested the mShot 20 times already.
return;
}
if ( ! $( '.akismet-mshot' ).data( 'pending-request' ) ) {
$( '.akismet-mshot' ).data( 'pending-request', true );
mshotTries++;
$( '.akismet-mshot .mshot-image' ).attr( 'src', akismet_mshot_url( $( '.akismet-mshot' ).data( 'url' ), mshotTries ) );
}
mshotRetryTimer = setTimeout( retryMshotUntilLoaded, mshotRetryInterval );
}
else {
// All done.
}
}
function preloadMshotsInViewport() {
var windowWidth = $( window ).width();
var windowHeight = $( window ).height();
$( '#the-comment-list' ).find( mshotEnabledLinkSelector ).each( function ( index, element ) {
var linkUrl = $( this ).attr( 'href' );
// Don't attempt to preload an mshot for a single link twice.
if ( preloadedMshotURLs.indexOf( linkUrl ) !== -1 ) {
// The URL is already preloaded.
return true;
}
if ( typeof element.getBoundingClientRect !== 'function' ) {
// The browser is too old. Return false to stop this preloading entirely.
return false;
}
var rect = element.getBoundingClientRect();
if ( rect.top >= 0 && rect.left >= 0 && rect.bottom <= windowHeight && rect.right <= windowWidth ) {
akismet_preload_mshot( linkUrl );
$( this ).data( 'akismet-mshot-preloaded', true );
}
} );
}
$( '.checkforspam.enable-on-load' ).on( 'click', function( e ) {
if ( $( this ).hasClass( 'ajax-disabled' ) ) {
// Akismet hasn't been configured yet. Allow the user to proceed to the button's link.
return;
}
e.preventDefault();
if ( $( this ).hasClass( 'button-disabled' ) ) {
window.location.href = $( this ).data( 'success-url' ).replace( '__recheck_count__', 0 ).replace( '__spam_count__', 0 );
return;
}
$('.checkforspam').addClass('button-disabled').addClass( 'checking' );
$('.checkforspam-spinner').addClass( 'spinner' ).addClass( 'is-active' );
akismet_check_for_spam(0, 100);
}).removeClass( 'button-disabled' );
var spam_count = 0;
var recheck_count = 0;
function akismet_check_for_spam(offset, limit) {
var check_for_spam_buttons = $( '.checkforspam' );
var nonce = check_for_spam_buttons.data( 'nonce' );
// We show the percentage complete down to one decimal point so even queues with 100k
// pending comments will show some progress pretty quickly.
var percentage_complete = Math.round( ( recheck_count / check_for_spam_buttons.data( 'pending-comment-count' ) ) * 1000 ) / 10;
// Update the progress counter on the "Check for Spam" button.
$( '.checkforspam' ).text( check_for_spam_buttons.data( 'progress-label' ).replace( '%1$s', percentage_complete ) );
$.post(
ajaxurl,
{
'action': 'akismet_recheck_queue',
'offset': offset,
'limit': limit,
'nonce': nonce
},
function(result) {
if ( 'error' in result ) {
// An error is only returned in the case of a missing nonce, so we don't need the actual error message.
window.location.href = check_for_spam_buttons.data( 'failure-url' );
return;
}
recheck_count += result.counts.processed;
spam_count += result.counts.spam;
if (result.counts.processed < limit) {
window.location.href = check_for_spam_buttons.data( 'success-url' ).replace( '__recheck_count__', recheck_count ).replace( '__spam_count__', spam_count );
}
else {
// Account for comments that were caught as spam and moved out of the queue.
akismet_check_for_spam(offset + limit - result.counts.spam, limit);
}
}
);
}
if ( "start_recheck" in WPAkismet && WPAkismet.start_recheck ) {
$( '.checkforspam' ).click();
}
if ( typeof MutationObserver !== 'undefined' ) {
// Dynamically add the "X" next the the author URL links when a comment is quick-edited.
var comment_list_container = document.getElementById( 'the-comment-list' );
if ( comment_list_container ) {
var observer = new MutationObserver( function ( mutations ) {
for ( var i = 0, _len = mutations.length; i < _len; i++ ) {
if ( mutations[i].addedNodes.length > 0 ) {
akismet_enable_comment_author_url_removal();
// Once we know that we'll have to check for new author links, skip the rest of the mutations.
break;
}
}
} );
observer.observe( comment_list_container, { attributes: true, childList: true, characterData: true } );
}
}
function akismet_enable_comment_author_url_removal() {
$( '#the-comment-list' )
.find( 'tr.comment, tr[id ^= "comment-"]' )
.find( '.column-author a[href^="http"]:first' ) // Ignore mailto: links, which would be the comment author's email.
.each(function () {
if ( $( this ).parent().find( '.akismet_remove_url' ).length > 0 ) {
return;
}
var linkHref = $(this).attr( 'href' );
// Ignore any links to the current domain, which are diagnostic tools, like the IP address link
// or any other links another plugin might add.
var currentHostParts = document.location.href.split( '/' );
var currentHost = currentHostParts[0] + '//' + currentHostParts[2] + '/';
if ( linkHref.indexOf( currentHost ) != 0 ) {
var thisCommentId = $(this).parents('tr:first').attr('id').split("-");
$(this)
.attr("id", "author_comment_url_"+ thisCommentId[1])
.after(
$( '<a href="#" class="akismet_remove_url">x</a>' )
.attr( 'commentid', thisCommentId[1] )
.attr( 'title', WPAkismet.strings['Remove this URL'] )
);
}
});
}
/**
* Generate an mShot URL if given a link URL.
*
* @param string linkUrl
* @param int retry If retrying a request, the number of the retry.
* @return string The mShot URL;
*/
function akismet_mshot_url( linkUrl, retry ) {
var mshotUrl = '//s0.wp.com/mshots/v1/' + encodeURIComponent( linkUrl ) + '?w=900';
if ( retry > 1 ) {
mshotUrl += '&r=' + encodeURIComponent( retry );
}
mshotUrl += '&source=akismet';
return mshotUrl;
}
/**
* Begin loading an mShot preview of a link.
*
* @param string linkUrl
*/
function akismet_preload_mshot( linkUrl ) {
var img = new Image();
img.src = akismet_mshot_url( linkUrl );
preloadedMshotURLs.push( linkUrl );
}
$( '.akismet-could-be-primary' ).each( function () {
var form = $( this ).closest( 'form' );
form.data( 'initial-state', form.serialize() );
form.on( 'change keyup', function () {
var self = $( this );
var submit_button = self.find( '.akismet-could-be-primary' );
if ( self.serialize() != self.data( 'initial-state' ) ) {
submit_button.addClass( 'akismet-is-primary' );
}
else {
submit_button.removeClass( 'akismet-is-primary' );
}
} );
} );
/**
* Shows the Enter API key form
*/
$( '.akismet-enter-api-key-box__reveal' ).on( 'click', function ( e ) {
e.preventDefault();
var div = $( '.akismet-enter-api-key-box__form-wrapper' );
div.show( 500 );
div.find( 'input[name=key]' ).focus();
$( this ).hide();
} );
/**
* Hides the Connect with Jetpack form | Shows the Activate Akismet Account form
*/
$( 'a.toggle-ak-connect' ).on( 'click', function ( e ) {
e.preventDefault();
$( '.akismet-ak-connect' ).slideToggle('slow');
$( 'a.toggle-ak-connect' ).hide();
$( '.akismet-jp-connect' ).hide();
$( 'a.toggle-jp-connect' ).show();
} );
/**
* Shows the Connect with Jetpack form | Hides the Activate Akismet Account form
*/
$( 'a.toggle-jp-connect' ).on( 'click', function ( e ) {
e.preventDefault();
$( '.akismet-jp-connect' ).slideToggle('slow');
$( 'a.toggle-jp-connect' ).hide();
$( '.akismet-ak-connect' ).hide();
$( 'a.toggle-ak-connect' ).show();
} );
});
@@ -0,0 +1,67 @@
@font-face {
font-family: 'Inter';
font-style: normal;
font-weight: 400;
font-display: swap;
src: url("https://s0.wp.com/i/fonts/inter/Inter-Regular.woff2?v=3.19") format("woff2"),
url("https://s0.wp.com/i/fonts/inter/Inter-Regular.woff?v=3.19") format("woff");
}
@font-face {
font-family: 'Inter';
font-style: italic;
font-weight: 400;
font-display: swap;
src: url("https://s0.wp.com/i/fonts/inter/Inter-Italic.woff2?v=3.19") format("woff2"),
url("https://s0.wp.com/i/fonts/inter/Inter-Italic.woff?v=3.19") format("woff");
}
@font-face {
font-family: 'Inter';
font-style: normal;
font-weight: 500;
font-display: swap;
src: url("https://s0.wp.com/i/fonts/inter/Inter-Medium.woff2?v=3.19") format("woff2"),
url("https://s0.wp.com/i/fonts/inter/Inter-Medium.woff?v=3.19") format("woff");
}
@font-face {
font-family: 'Inter';
font-style: italic;
font-weight: 500;
font-display: swap;
src: url("https://s0.wp.com/i/fonts/inter/Inter-MediumItalic.woff2?v=3.19") format("woff2"),
url("https://s0.wp.com/i/fonts/inter/Inter-MediumItalic.woff?v=3.19") format("woff");
}
@font-face {
font-family: 'Inter';
font-style: normal;
font-weight: 600;
font-display: swap;
src: url("https://s0.wp.com/i/fonts/inter/Inter-SemiBold.woff2?v=3.19") format("woff2"),
url("https://s0.wp.com/i/fonts/inter/Inter-SemiBold.woff?v=3.19") format("woff");
}
@font-face {
font-family: 'Inter';
font-style: italic;
font-weight: 600;
font-display: swap;
src: url("https://s0.wp.com/i/fonts/inter/Inter-SemiBoldItalic.woff2?v=3.19") format("woff2"),
url("https://s0.wp.com/i/fonts/inter/Inter-SemiBoldItalic.woff?v=3.19") format("woff");
}
@font-face {
font-family: 'Inter';
font-style: normal;
font-weight: 700;
font-display: swap;
src: url("https://s0.wp.com/i/fonts/inter/Inter-Bold.woff2?v=3.19") format("woff2"),
url("https://s0.wp.com/i/fonts/inter/Inter-Bold.woff?v=3.19") format("woff");
}
@font-face {
font-family: 'Inter';
font-style: italic;
font-weight: 700;
font-display: swap;
src: url("https://s0.wp.com/i/fonts/inter/Inter-BoldItalic.woff2?v=3.19") format("woff2"),
url("https://s0.wp.com/i/fonts/inter/Inter-BoldItalic.woff?v=3.19") format("woff");
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="M20 11.2H6.8l3.7-3.7-1-1L3.9 12l5.6 5.5 1-1-3.7-3.7H20z"></path></svg>

After

Width:  |  Height:  |  Size: 199 B

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path fill="#357b49" d="M19.5 4.5h-7V6h4.44l-5.97 5.97 1.06 1.06L18 7.06v4.44h1.5v-7Zm-13 1a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-3H17v3a.5.5 0 0 1-.5.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h3V5.5h-3Z"></path></svg>

After

Width:  |  Height:  |  Size: 350 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 904 B

@@ -0,0 +1,485 @@
/* This file was automatically generated on Nov 05 2024 03:06:40 */
body {
--akismet-color-charcoal: #272635;
--akismet-color-light-grey: #f6f7f7;
--akismet-color-mid-grey: #a7aaad;
--akismet-color-dark-grey: #646970;
--akismet-color-grey-80: #2c3338;
--akismet-color-grey-100: #101517;
--akismet-color-white: #fff;
--akismet-color-mid-green: #357b49;
--akismet-color-mid-red: #e82c3f;
--akismet-color-light-blue: #256eff;
--akismet-color-notice-light-green: #dbf0e1;
--akismet-color-notice-dark-green: #69bf82;
--akismet-color-notice-light-red: #ffdbde;
--akismet-color-notice-dark-red: #ff6676;
--akismet-color-notice-yellow: #e5c133;
}
#akismet-plugin-container {
background-color: var(--akismet-color-light-grey);
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen-Sans', 'Ubuntu', 'Cantarell', 'Helvetica Neue', sans-serif;
}
#akismet-plugin-container a {
color: var(--akismet-color-mid-green);
}
#akismet-plugin-container a.akismet-button {
background-color: var(--akismet-color-mid-green);
color: var(--akismet-color-white);
}
#akismet-plugin-container button:focus-visible,
#akismet-plugin-container input:focus-visible,
#akismet-plugin-container a:focus-visible {
border: 0;
box-shadow: none;
outline: 2px solid var(--akismet-color-light-blue);
}
.akismet-masthead {
box-shadow: none;
}
.akismet-masthead__logo {
margin: 20px 0;
}
.akismet-section-header {
box-shadow: none;
margin-bottom: 0;
}
.akismet-section-header__label {
color: var(--akismet-color-charcoal);
font-weight: 600;
}
.akismet-button, .akismet-button:hover {
background-color: var(--akismet-color-mid-green);
border: 0;
color: #fff;
}
/* Need this specificity to override the existing header rule */
.akismet-new-snapshot h3.akismet-new-snapshot__header {
background: none;
font-size: 13px;
color: var(--akismet-color-charcoal);
text-align: right;
text-transform: none;
}
.akismet-new-snapshot .akismet-new-snapshot__number {
color: var(--akismet-color-charcoal);
letter-spacing: -1px;
text-align: right;
}
.akismet-new-snapshot li.akismet-new-snapshot__item {
color: var(--akismet-color-dark-grey);
font-size: 13px;
text-align: right;
text-transform: none;
}
.akismet-masthead__logo-link {
min-height: 50px;
}
.akismet-masthead__back-link-container {
margin-top: 16px;
margin-bottom: 2px;
}
/* Need this specificity to override the existing link rule */
#akismet-plugin-container a.akismet-masthead__back-link {
background-image: url(../img/arrow-left.svg);
background-position: right;
background-repeat: no-repeat;
background-size: 16px;
color: var(--akismet-color-charcoal);
font-weight: 400;
padding-right: 20px;
text-decoration: none;
}
#akismet-plugin-container a.akismet-masthead__back-link:hover {
text-decoration: underline;
}
.akismet-new-snapshot__item {
border-top: 1px solid var(--akismet-color-light-grey);
border-right: 1px solid var(--akismet-color-light-grey);
padding: 1em;
}
.akismet-new-snapshot li:first-child {
border-right: none;
}
.akismet-new-snapshot__list {
display: flex;
margin-bottom: 0;
}
.akismet-new-snapshot__item {
flex: 1 0 33.33%;
margin-bottom: 0;
padding-right: 1.5em;
padding-left: 1.5em;
}
.akismet-new-snapshot__chart {
padding: 1em;
}
.akismet-box {
border: 0;
}
.akismet-box,
.akismet-card {
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06), 0 0 2px rgba(0, 0, 0, 0.16);
border-radius: 8px;
overflow: hidden;
}
.akismet-card {
margin: 32px auto 0 auto;
}
.akismet-lower {
padding-top: 0;
}
.akismet-lower .inside {
padding: 0;
}
.akismet-section-header__label {
margin: 0;
}
.akismet-settings__row {
border-bottom: 1px solid var(--akismet-color-light-grey);
display: block;
padding: 1em 1.5em;
}
.akismet-settings__row-input {
margin-right: auto;
}
.akismet-settings__row-title {
font-weight: 500;
font-size: 1em;
margin: 0;
margin-bottom: 1em;
}
.akismet-settings__row-description {
margin-top: 0.5em;
}
.akismet-card-actions {
display: flex;
justify-content: flex-end;
padding: 1em;
}
.akismet-card-actions__secondary-action {
align-self: center;
margin-left: auto;
}
.akismet-card-actions__secondary-action a[target="_blank"]::after {
background: url('../img/icon-external.svg') no-repeat;
background-size: contain;
content: "";
display: inline-block;
height: 16px;
margin-right: 5px;
vertical-align: middle;
width: 16px;
}
.akismet-settings__row label {
padding-bottom: 1em;
}
.akismet-settings__row-note {
font-size: 0.9em;
margin-top: 0.4em;
}
.akismet-settings__row input[type="checkbox"],
.akismet-settings__row input[type="radio"] {
accent-color: var(--akismet-color-mid-green);
box-shadow: none;
flex-shrink: 0;
margin: 2px 0 0 0;
}
.akismet-settings__row input[type="checkbox"] {
margin-top: 1px;
vertical-align: top;
-webkit-appearance: checkbox;
}
.akismet-settings__row input[type="radio"] {
-webkit-appearance: radio;
}
/* Fix up misbehaving wp-admin styles in Chrome (from forms and colors stylesheets) */
.akismet-settings__row input[type="checkbox"]:checked:before {
content: '';
}
.akismet-settings__row input[type="radio"]:checked:before {
background: none;
}
.akismet-settings__row input[type="checkbox"]:checked:hover,
.akismet-settings__row input[type="radio"]:checked:hover {
accent-color: var(--akismet-color-mid-green);
}
.akismet-button:disabled {
background-color: var(--akismet-color-mid-grey);
color: var(--akismet-color-white);
cursor: arrow;
}
.akismet-awaiting-stats,
.akismet-account {
padding: 0 1rem 1rem 1rem;
margin: 0;
}
.akismet-account {
padding-bottom: 0;
}
.akismet-account th {
font-weight: 500;
padding-left: 1em;
}
.akismet-account th, .akismet-account td {
padding-bottom: 1em;
}
.akismet-settings__row-input-label {
align-items: center;
display: flex;
}
.akismet-settings__row-label-text {
padding-right: 0.5em;
margin-top: 2px;
}
.akismet-alert {
border-right: 8px solid;
border-radius: 8px;
margin: 20px 0;
padding: 0.2em 1em;
}
.akismet-alert__heading {
font-size: 1em;
}
.akismet-alert.is-good {
background-color: var(--akismet-color-notice-light-green);
border-right-color: var(--akismet-color-notice-dark-green);
}
.akismet-alert.is-neutral {
background-color: var(--akismet-color-white);
border-right-color: var(--akismet-color-dark-grey);
}
.akismet-alert.is-bad {
background-color: var(--akismet-color-notice-light-red);
border-right-color: var(--akismet-color-notice-dark-red);
}
.akismet-alert.is-commercial {
background-color: var(--akismet-color-white);
border-color: var(--akismet-color-mid-grey);
border-bottom-width: 1px;
border-right-color: var(--akismet-color-notice-yellow);
display: flex;
padding-bottom: 1em;
}
#akismet-plugin-container .akismet-alert.is-good a,
#akismet-plugin-container .akismet-alert.is-bad a {
/* For better contrast - green isn't great */
color: var(--akismet-color-grey-80);
}
.akismet-alert-header {
font-size: 16px;
margin-bottom: 0.5em;
}
.akismet-alert-button-wrapper {
align-self: center;
margin-right: 2em;
min-width: 120px;
}
.akismet-alert-info {
text-wrap: pretty;
margin: 0.5em 0;
}
/* Setup - API key input */
.akismet-enter-api-key-box {
margin: 1.5rem 0;
}
.akismet-enter-api-key-box__reveal {
background: none;
border: 0;
color: var(--akismet-color-mid-green);
cursor: pointer;
text-decoration: underline;
}
.akismet-enter-api-key-box__form-wrapper {
display: none;
margin-top: 1.5rem;
}
.akismet-enter-api-key-box__input-wrapper {
box-sizing: border-box;
display: flex;
flex-wrap: nowrap;
padding: 0 1.5rem;
width: 100%;
}
.akismet-enter-api-key-box__key-input {
flex-grow: 1;
margin-left: 1rem;
}
h3.akismet-enter-api-key-box__header {
padding-top: 0;
padding-bottom: 1em;
text-align: right;
}
/* Notices > Activation (shown on edit-comments.php) */
#akismet-setup-prompt {
background: none;
border: none;
margin: 0;
padding: 0;
width: 100%;
}
.akismet-activate {
align-items: center;
/* background-image is defined via an inline style in class.akismet-admin.php */
background-color: var(--akismet-color-light-grey);
background-position: calc(100% - (100% - 1em)) center;
background-repeat: no-repeat;
background-size: 140px;
border: 1px solid var(--akismet-color-mid-green);
border-right-width: 4px;
display: flex;
justify-content: space-between;
margin: 15px 0;
min-height: 60px;
overflow: hidden;
padding: 5px 5px 5px 160px;
position: relative;
}
.akismet-activate__button,
.akismet-activate__button:hover,
.akismet-activate__button:visited {
margin: 0 1em;
}
.akismet-activate__description {
color: var(--akismet-color-charcoal);
flex-grow: 1;
font-size: 16px;
font-weight: 600;
margin: 0 auto;
text-align: center;
text-wrap: pretty;
}
/* Gutenberg medium breakpoint */
@media screen and (max-width: 782px) {
.akismet-new-snapshot__list {
display: block;
}
.akismet-new-snapshot__number {
float: left;
font-size: 20px;
font-weight: 500;
margin-top: -16px;
}
.akismet-new-snapshot__header {
font-size: 14px;
font-weight: 500;
}
.akismet-new-snapshot__text {
font-size: 12px;
}
.akismet-settings__row input[type="checkbox"],
.akismet-settings__row input[type="radio"] {
height: 24px;
width: 24px;
}
.akismet-settings__row-label-text {
padding-right: 0.8em;
}
.akismet-settings__row input[type="checkbox"],
.akismet-settings__row input[type="radio"] {
margin-top: 0;
}
.akismet-activate {
background-size: 120px;
padding-left: 134px;
}
.akismet-activate__button {
white-space: normal;
}
.akismet-activate__description {
font-size: 14px;
margin-left: 1em;
}
}
/* Gutenberg small breakpoint */
@media screen and (max-width: 600px) {
.akismet-activate__button,
.akismet-activate__button:hover {
font-size: 13px;
}
.akismet-activate__description {
display: none;
}
}
@@ -0,0 +1,520 @@
/* This file was automatically generated on Jul 03 2024 02:40:33 */
.wp-admin.jetpack_page_akismet-key-config, .wp-admin.settings_page_akismet-key-config {
background-color:#f3f6f8;
}
#submitted-on {
position: relative;
}
#the-comment-list .author .akismet-user-comment-count {
display: inline;
}
#the-comment-list .author a span {
text-decoration: none;
color: #999;
}
#the-comment-list .author a span.akismet-span-link {
text-decoration: inherit;
color: inherit;
}
#the-comment-list .akismet_remove_url {
margin-right: 3px;
color: #999;
padding: 2px 0 2px 3px;
}
#the-comment-list .akismet_remove_url:hover {
color: #A7301F;
font-weight: bold;
padding: 2px 0 2px 2px;
}
#dashboard_recent_comments .akismet-status {
display: none;
}
.akismet-status {
float: left;
}
.akismet-status a {
color: #AAA;
font-style: italic;
}
table.comments td.comment p a {
text-decoration: underline;
}
table.comments td.comment p a:after {
content: attr(href);
color: #aaa;
display: inline-block; /* Show the URL without the link's underline extending under it. */
padding: 0 1ex; /* Because it's inline block, we can't just use spaces in the content: attribute to separate it from the link text. */
}
.mshot-arrow {
width: 0;
height: 0;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 10px solid #5C5C5C;
position: absolute;
right: -6px;
top: 91px;
}
.mshot-container {
background: #5C5C5C;
position: absolute;
top: -94px;
padding: 7px;
width: 450px;
height: 338px;
z-index: 20000;
-moz-border-radius: 6px;
border-radius: 6px;
-webkit-border-radius: 6px;
}
.akismet-mshot {
position: absolute;
z-index: 100;
}
.akismet-mshot .mshot-image {
margin: 0;
height: 338px;
width: 450px;
}
.checkforspam {
display: inline-block !important;
}
.checkforspam-spinner {
display: inline-block;
margin-top: 7px;
}
.akismet-right {
float: left;
}
.akismet-card .akismet-right {
margin: 1em 0;
}
.akismet-alert-text {
color: #dd3d36;
font-weight: bold;
font-size: 120%;
margin-top: .5rem;
}
.akismet-new-snapshot {
margin-top: 1em;
text-align: center;
background: #fff;
}
.akismet-new-snapshot h3 {
background: #f5f5f5;
color: #888;
font-size: 11px;
margin: 0;
}
.akismet-new-snapshot ul li {
color: #999;
font-size: 11px;
text-transform: uppercase;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
-ms-box-sizing: border-box;
}
.akismet-new-snapshot__number {
display: block;
font-size: 32px;
font-weight: lighter;
line-height: 1.5em;
}
.akismet-settings th:first-child {
vertical-align: top;
padding-top: 15px;
}
.akismet-settings th.akismet-api-key {
vertical-align: middle;
padding-top: 0;
}
.akismet-settings span.akismet-note {
float: right;
padding-right: 23px;
font-size: 75%;
margin-top: -10px;
}
.jetpack_page_akismet-key-config #wpcontent, .settings_page_akismet-key-config #wpcontent {
padding-right: 0;
}
.akismet-masthead {
background-color:#fff;
text-align:center;
box-shadow:0 1px 0 rgba(200,215,225,0.5),0 1px 2px #e9eff3
}
@media (max-width: 45rem) {
.akismet-masthead {
padding:0 1.25rem
}
}
.akismet-masthead__inside-container {
padding:.375rem 0;
margin:0 auto;
width:100%;
max-width:45rem;
text-align: right;
}
.akismet-masthead__logo-container {
padding:.3125rem 0 0
}
.akismet-masthead__logo-link {
display:inline-block;
outline:none;
vertical-align:middle
}
.akismet-masthead__logo-link:focus {
line-height:0;
box-shadow:0 0 0 2px #78dcfa
}
.akismet-masthead__logo-link+code {
margin:0 10px;
padding:5px 9px;
border-radius:2px;
background:#e6ecf1;
color:#647a88
}
.akismet-masthead__links {
display:-ms-flexbox;
display:flex;
-ms-flex-flow:row wrap;
flex-flow:row wrap;
-ms-flex:2 50%;
flex:2 50%;
-ms-flex-pack:end;
justify-content:flex-end;
margin:0
}
@media (max-width: 480px) {
.akismet-masthead__links {
padding-left:.625rem
}
}
.akismet-masthead__link-li {
margin:0;
padding:0
}
.akismet-masthead__link {
font-style:normal;
color:#0087be;
padding:.625rem;
display:inline-block
}
.akismet-masthead__link:visited {
color:#0087be
}
.akismet-masthead__link:active,.akismet-masthead__link:hover {
color:#00aadc
}
.akismet-masthead__link:hover {
text-decoration:underline
}
.akismet-masthead__link .dashicons {
display:none
}
@media (max-width: 480px) {
.akismet-masthead__link:hover,.akismet-masthead__link:active {
text-decoration:none
}
.akismet-masthead__link .dashicons {
display:block;
font-size:1.75rem
}
.akismet-masthead__link span+span {
display:none
}
}
.akismet-masthead__link-li:last-of-type .akismet-masthead__link {
padding-left:0
}
.akismet-lower {
margin: 0 auto;
text-align: right;
max-width: 45rem;
padding: 1.5rem;
}
.akismet-lower .notice {
margin-bottom: 2rem;
}
.akismet-card {
margin-top: 1rem;
margin-bottom: 0;
position: relative;
box-sizing: border-box;
background: white;
}
.akismet-card:after, .akismet-card .inside:after, .akismet-masthead__logo-container:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.akismet-card .inside {
padding: 1.5rem;
padding-top: 1rem;
}
.akismet-card .akismet-card-actions {
margin-top: 1rem;
}
.jetpack_page_akismet-key-config .update-nag, .settings_page_akismet-key-config .update-nag {
display: none;
}
.akismet-masthead .akismet-right {
line-height: 2.125rem;
font-size: 0.9rem;
}
.akismet-box {
box-sizing: border-box;
background: white;
border: 1px solid rgba(200, 215, 225, 0.5);
}
.akismet-box h2, .akismet-box h3 {
padding: 1.5rem 1.5rem .5rem 1.5rem;
margin: 0;
}
.akismet-box p {
padding: 0 1.5rem 1.5rem 1.5rem;
margin: 0;
}
.akismet-jetpack-email {
font-style: oblique;
}
.akismet-jetpack-gravatar {
padding: 0 1.5rem 0 0;
float: right;
margin-left: 1rem;
width: 54px;
height: 54px;
}
.akismet-box p:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.akismet-box .akismet-right {
padding-left: 1.5rem;
}
.akismet-boxes .akismet-box {
margin-bottom: 0;
padding: 0;
margin-top: -1px;
}
.akismet-boxes .akismet-box:last-child {
margin-bottom: 1.5rem;
}
.akismet-boxes .akismet-box:first-child {
margin-top: 1.5rem;
}
.akismet-box-header {
max-width: 700px;
margin: 0 auto 40px auto;
line-height: 1.5;
}
.akismet-box-header h2 {
margin: 1.5rem 10% 0;
font-size: 1.375rem;
font-weight: 700;
color: #000;
}
.akismet-box .centered {
text-align: center;
}
.akismet-box .akismet-toggles {
margin: 3rem 0;
}
.akismet-box .akismet-ak-connect, .akismet-box .toggle-jp-connect {
display: none;
}
.akismet-button, .akismet-button:hover, .akismet-button:visited {
background: white;
border-color: #c8d7e1;
border-style: solid;
border-width: 1px 1px 2px;
color: #2e4453;
cursor: pointer;
display: inline-block;
margin: 0;
outline: 0;
overflow: hidden;
font-size: 14px;
font-weight: 500;
text-overflow: ellipsis;
text-decoration: none;
vertical-align: top;
box-sizing: border-box;
font-size: 14px;
line-height: 21px;
border-radius: 4px;
padding: 7px 14px 9px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
.akismet-button:hover {
border-color: #a8bece;
}
.akismet-button:active {
border-width: 2px 1px 1px;
}
.akismet-is-primary, .akismet-is-primary:hover, .akismet-is-primary:visited {
background: #00aadc;
border-color: #0087be;
color: white;
}
.akismet-is-primary:hover, .akismet-is-primary:focus {
border-color: #005082;
}
.akismet-is-primary:hover {
border-color: #005082;
}
.akismet-section-header {
position: relative;
margin: 0 auto 0.625rem auto;
padding: 1rem;
box-sizing: border-box;
box-shadow: 0 0 0 1px rgba(200, 215, 225, 0.5), 0 1px 2px #e9eff3;
background: #ffffff;
width: 100%;
padding-top: 0.6875rem;
padding-bottom: 0.6875rem;
display: flex;
}
.akismet-section-header__label {
display: -ms-flexbox;
display: flex;
-ms-flex-align: center;
align-items: center;
-ms-flex-positive: 1;
flex-grow: 1;
line-height: 1.75rem;
position: relative;
font-size: 0.875rem;
color: #4f748e;
}
.akismet-section-header__actions {
line-height: 1.75rem;
}
.akismet-setup-instructions {
text-align: center;
}
.akismet-setup-instructions form {
padding-bottom: 1.5rem;
}
div.error.akismet-usage-limit-alert {
padding: 25px 15px 25px 45px;
display: flex;
align-items: center;
}
#akismet-plugin-container .akismet-usage-limit-alert {
margin: 0 auto 0.625rem auto;
box-sizing: border-box;
box-shadow: 0 0 0 1px rgba(200, 215, 225, 0.5), 0 1px 2px #e9eff3;
border: none;
border-right: 4px solid #d63638;
}
.akismet-usage-limit-alert .akismet-usage-limit-logo {
width: 38px;
min-width: 38px;
height: 38px;
border-radius: 20px;
margin-left: 18px;
background: black;
position: relative;
}
.akismet-usage-limit-alert .akismet-usage-limit-logo img {
position: absolute;
width: 22px;
right: 8px;
top: 10px;
}
.akismet-usage-limit-alert .akismet-usage-limit-text {
flex-grow: 1;
margin-left: 18px;
}
.akismet-usage-limit-alert h3 {
margin: 0;
}
.akismet-usage-limit-alert .akismet-usage-limit-cta {
border-color: none;
text-align: left;
}
#akismet-plugin-container .akismet-usage-limit-cta a {
color: #d63638;
}
@media (max-width: 550px) {
div.error.akismet-usage-limit-alert {
display: block;
}
.akismet-usage-limit-alert .akismet-usage-limit-logo,
.akismet-usage-limit-alert .akismet-usage-limit-text {
margin-bottom: 15px;
}
.akismet-usage-limit-alert .akismet-usage-limit-cta {
text-align: right;
}
}
+68
View File
@@ -0,0 +1,68 @@
<?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.3.5
Requires at least: 5.8
Requires PHP: 5.6.20
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-2023 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.3.5' );
define( 'AKISMET__MINIMUM_WP_VERSION', '5.8' );
define( 'AKISMET__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'AKISMET_DELETE_LIMIT', 10000 );
register_activation_hook( __FILE__, array( 'Akismet', 'plugin_activation' ) );
register_deactivation_hook( __FILE__, array( 'Akismet', 'plugin_deactivation' ) );
require_once AKISMET__PLUGIN_DIR . 'class.akismet.php';
require_once AKISMET__PLUGIN_DIR . 'class.akismet-widget.php';
require_once AKISMET__PLUGIN_DIR . 'class.akismet-rest-api.php';
add_action( 'init', array( 'Akismet', 'init' ) );
add_action( 'rest_api_init', array( 'Akismet_REST_API', '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';
}
+509
View File
@@ -0,0 +1,509 @@
=== Akismet Anti-spam ===
== Archived Changelog Entries ==
This file contains older changelog entries, so we can keep the size of the standard WordPress readme.txt file reasonable.
For the latest changes, please see the "Changelog" section of the [readme.txt file](https://plugins.svn.wordpress.org/akismet/trunk/readme.txt).
= 4.1.12 =
*Release Date - 3 September 2021*
* Fixed "Use of undefined constant" notice.
* Improved styling of alert notices.
= 4.1.11 =
*Release Date - 23 August 2021*
* Added support for Akismet API usage notifications on Akismet settings and edit-comments admin pages.
* Added support for the deleted_comment action when bulk-deleting comments from Spam.
= 4.1.10 =
*Release Date - 6 July 2021*
* Simplified the code around checking comments in REST API and XML-RPC requests.
* Updated Plus plan terminology in notices to match current subscription names.
* Added `rel="noopener"` to the widget link to avoid warnings in Google Lighthouse.
* Set the Akismet JavaScript as deferred instead of async to improve responsiveness.
* Improved the preloading of screenshot popups on the edit comments admin page.
= 4.1.9 =
*Release Date - 2 March 2021*
* Improved handling of pingbacks in XML-RPC multicalls
= 4.1.8 =
*Release Date - 6 January 2021*
* Fixed missing fields in submit-spam and submit-ham calls that could lead to reduced accuracy.
* Fixed usage of deprecated jQuery function.
= 4.1.7 =
*Release Date - 22 October 2020*
* Show the "Set up your Akismet account" banner on the comments admin screen, where it's relevant to mention if Akismet hasn't been configured.
* Don't use wp_blacklist_check when the new wp_check_comment_disallowed_list function is available.
= 4.1.6 =
*Release Date - 4 June 2020*
* Disable "Check for Spam" button until the page is loaded to avoid errors with clicking through to queue recheck endpoint directly.
* Added filter "akismet_enable_mshots" to allow disabling screenshot popups on the edit comments admin page.
= 4.1.5 =
*Release Date - 29 April 2020*
* Based on user feedback, we have dropped the in-admin notice explaining the availability of the "privacy notice" option in the AKismet settings screen. The option itself is available, but after displaying the notice for the last 2 years, it is now considered a known fact.
* Updated the "Requires at least" to WP 4.6, based on recommendations from https://wp-info.org/tools/checkplugini18n.php?slug=akismet
* Moved older changelog entries to a separate file to keep the size of this readme reasonable, also based on recommendations from https://wp-info.org/tools/checkplugini18n.php?slug=akismet
= 4.1.4 =
*Release Date - 17 March 2020*
* Only redirect to the Akismet setup screen upon plugin activation if the plugin was activated manually from within the plugin-related screens, to help users with non-standard install workflows, like WP-CLI.
* Update the layout of the initial setup screen to be more readable on small screens.
* If no API key has been entered, don't run code that expects an API key.
* Improve the readability of the comment history entries.
* Don't modify the comment form HTML if no API key has been set.
= 4.1.3 =
*Release Date - 31 October 2019*
* Prevented an attacker from being able to cause a user to unknowingly recheck their Pending comments for spam.
* Improved compatibility with Jetpack 7.7+.
* Updated the plugin activation page to use consistent language and markup.
* Redirecting users to the Akismet connnection/settings screen upon plugin activation, in an effort to make it easier for people to get setup.
= 4.1.2 =
*Release Date - 14 May 2019*
* Fixed a conflict between the Akismet setup banner and other plugin notices.
* Reduced the number of API requests made by the plugin when attempting to verify the API key.
* Include additional data in the pingback pre-check API request to help make the stats more accurate.
* Fixed a bug that was enabling the "Check for Spam" button when no comments were eligible to be checked.
* Improved Akismet's AMP compatibility.
= 4.1.1 =
*Release Date - 31 January 2019*
* Fixed the "Setup Akismet" notice so it resizes responsively.
* Only highlight the "Save Changes" button in the Akismet config when changes have been made.
* The count of comments in your spam queue shown on the dashboard show now always be up-to-date.
= 4.1 =
*Release Date - 12 November 2018*
* Added a WP-CLI method for retrieving stats.
* Hooked into the new "Personal Data Eraser" functionality from WordPress 4.9.6.
* Added functionality to clear outdated alerts from Akismet.com.
= 4.0.8 =
*Release Date - 19 June 2018*
* Improved the grammar and consistency of the in-admin privacy related notes (notice and config).
* Revised in-admin explanation of the comment form privacy notice to make its usage clearer.
* Added `rel="nofollow noopener"` to the comment form privacy notice to improve SEO and security.
= 4.0.7 =
*Release Date - 28 May 2018*
* Based on user feedback, the link on "Learn how your comment data is processed." in the optional privacy notice now has a `target` of `_blank` and opens in a new tab/window.
* Updated the in-admin privacy notice to use the term "comment" instead of "contact" in "Akismet can display a notice to your users under your comment forms."
* Only show in-admin privacy notice if Akismet has an API Key configured
= 4.0.6 =
*Release Date - 26 May 2018*
* Moved away from using `empty( get_option() )` to instantiating a variable to be compatible with older versions of PHP (5.3, 5.4, etc).
= 4.0.5 =
*Release Date - 26 May 2018*
* Corrected version number after tagging. Sorry...
= 4.0.4 =
*Release Date - 26 May 2018*
* Added a hook to provide Akismet-specific privacy information for a site's privacy policy.
* Added tools to control the display of a privacy related notice under comment forms.
* Fixed HTML in activation failure message to close META and HEAD tag properly.
* Fixed a bug that would sometimes prevent Akismet from being correctly auto-configured.
= 4.0.3 =
*Release Date - 19 February 2018*
* Added a scheduled task to remove entries in wp_commentmeta that no longer have corresponding comments in wp_comments.
* Added a new `akismet_batch_delete_count` action to the batch delete methods for people who'd like to keep track of the numbers of records being processed by those methods.
= 4.0.2 =
*Release Date - 18 December 2017*
* Fixed a bug that could cause Akismet to recheck a comment that has already been manually approved or marked as spam.
* Fixed a bug that could cause Akismet to claim that some comments are still waiting to be checked when no comments are waiting to be checked.
= 4.0.1 =
*Release Date - 6 November 2017*
* Fixed a bug that could prevent some users from connecting Akismet via their Jetpack connection.
* Ensured that any pending Akismet-related events are unscheduled if the plugin is deactivated.
* Allow some JavaScript to be run asynchronously to avoid affecting page render speeds.
= 4.0 =
*Release Date - 19 September 2017*
* Added REST API endpoints for configuring Akismet and retrieving stats.
* Increased the minimum supported WordPress version to 4.0.
* Added compatibility with comments submitted via the REST API.
* Improved the progress indicator on the "Check for Spam" button.
= 3.3.4 =
*Release Date - 3 August 2017*
* Disabled Akismet's debug log output by default unless AKISMET_DEBUG is defined.
* URL previews now begin preloading when the mouse moves near them in the comments section of wp-admin.
* When a comment is caught by the Comment Blacklist, Akismet will always allow it to stay in the trash even if it is spam as well.
* Fixed a bug that was preventing an error from being shown when a site can't reach Akismet's servers.
= 3.3.3 =
*Release Date - 13 July 2017*
* Reduced amount of bandwidth used by the URL Preview feature.
* Improved the admin UI when the API key is manually pre-defined for the site.
* Removed a workaround for WordPress installations older than 3.3 that will improve Akismet's compatibility with other plugins.
* The number of spam blocked that is displayed on the WordPress dashboard will now be more accurate and updated more frequently.
* Fixed a bug in the Akismet widget that could cause PHP warnings.
= 3.3.2 =
*Release Date - 10 May 2017*
* Fixed a bug causing JavaScript errors in some browsers.
= 3.3.1 =
*Release Date - 2 May 2017*
* Improve performance by only requesting the akismet_comment_nonce option when absolutely necessary.
* Fixed two bugs that could cause PHP warnings.
* Fixed a bug that was preventing the "Remove author URL" feature from working after a comment was edited using "Quick Edit."
* Fixed a bug that was preventing the URL preview feature from working after a comment was edited using "Quick Edit."
= 3.3 =
*Release Date - 23 February 2017*
* Updated the Akismet admin pages with a new clean design.
* Fixed bugs preventing the `akismet_add_comment_nonce` and `akismet_update_alert` wrapper functions from working properly.
* Fixed bug preventing the loading indicator from appearing when re-checking all comments for spam.
* Added a progress indicator to the "Check for Spam" button.
* Added a success message after manually rechecking the Pending queue for spam.
= 3.2 =
*Release Date - 6 September 2016*
* Added a WP-CLI module. You can now check comments and recheck the moderation queue from the command line.
* Stopped using the deprecated jQuery function `.live()`.
* Fixed a bug in `remove_comment_author_url()` and `add_comment_author_url()` that could generate PHP notices.
* Fixed a bug that could cause an infinite loop for sites with very very very large comment IDs.
* Fixed a bug that could cause the Akismet widget title to be blank.
= 3.1.11 =
*Release Date - 12 May 2016*
* Fixed a bug that could cause the "Check for Spam" button to skip some comments.
* Fixed a bug that could prevent some spam submissions from being sent to Akismet.
* Updated all links to use https:// when possible.
* Disabled Akismet debug logging unless WP_DEBUG and WP_DEBUG_LOG are both enabled.
= 3.1.10 =
*Release Date - 1 April 2016*
* Fixed a bug that could cause comments caught as spam to be placed in the Pending queue.
* Fixed a bug that could have resulted in comments that were caught by the core WordPress comment blacklist not to have a corresponding History entry.
* Fixed a bug that could have caused avoidable PHP warnings in the error log.
= 3.1.9 =
*Release Date - 28 March 2016*
* Add compatibility with Jetpack so that Jetpack can automatically configure Akismet settings when appropriate.
* Fixed a bug preventing some comment data from being sent to Akismet.
= 3.1.8 =
*Release Date - 4 March 2016*
* Fixed a bug preventing Akismet from being used with some plugins that rewrite admin URLs.
* Reduced the amount of bandwidth used on Akismet API calls
* Reduced the amount of space Akismet uses in the database
* Fixed a bug that could cause comments caught as spam to be placed in the Pending queue.
= 3.1.7 =
*Release Date - 4 January 2016*
* Added documentation for the 'akismet_comment_nonce' filter.
* The post-install activation button is now accessible to screen readers and keyboard-only users.
* Fixed a bug that was preventing the "Remove author URL" feature from working in WordPress 4.4
= 3.1.6 =
*Release Date - 14 December 2015*
* Improve the notices shown after activating Akismet.
* Update some strings to allow for the proper plural forms in all languages.
= 3.1.5 =
*Release Date - 13 October 2015*
* Closes a potential XSS vulnerability.
= 3.1.4 =
*Release Date - 24 September 2015*
* Fixed a bug that was preventing some users from automatically connecting using Jetpack if they didn't have a current Akismet subscription.
* Fixed a bug that could cause comments caught as spam to be placed in the Pending queue.
* Error messages and instructions have been simplified to be more understandable.
* Link previews are enabled for all links inside comments, not just the author's website link.
= 3.1.3 =
*Release Date - 6 July 2015*
* Notify users when their account status changes after previously being successfully set up. This should help any users who are seeing blank Akismet settings screens.
= 3.1.2 =
*Release Date - 7 June 2015*
* Reduced the amount of space Akismet uses in the commentmeta table.
* Fixed a bug where some comments with quotes in the author name weren't getting history entries
* Pre-emptive security improvements to ensure that the Akismet plugin can't be used by attackers to compromise a WordPress installation.
* Better UI for the key entry field: allow whitespace to be included at the beginning or end of the key and strip it out automatically when the form is submitted.
* When deactivating the plugin, notify the Akismet API so the site can be marked as inactive.
* Clearer error messages.
= 3.1.1 =
*Release Date - 17th March, 2015*
* Improvements to the "Remove comment author URL" JavaScript
* Include the pingback pre-check from the 2.6 branch.
= 3.1 =
*Release Date - 11th March, 2015*
* Use HTTPS by default for all requests to Akismet.
* Fix for a situation where Akismet might strip HTML from a comment.
= 3.0.4 =
*Release Date - 11th December, 2014*
* Fix to make .htaccess compatible with Apache 2.4.
* Fix to allow removal of https author URLs.
* Fix to avoid stripping part of the author URL when removing and re-adding.
* Removed the "Check for Spam" button from the "Trash" and "Approved" queues, where it would have no effect.
* Allow automatic API key configuration when Jetpack is installed and connected to a WordPress.com account
= 3.0.3 =
*Release Date - 3rd November, 2014*
* Fix for sending the wrong data to delete_comment action that could have prevented old spam comments from being deleted.
* Added a filter to disable logging of Akismet debugging information.
* Added a filter for the maximum comment age when deleting old spam comments.
* Added a filter for the number per batch when deleting old spam comments.
* Removed the "Check for Spam" button from the Spam folder.
= 3.0.2 =
*Release Date - 18th August, 2014*
* Performance improvements.
* Fixed a bug that could truncate the comment data being sent to Akismet for checking.
= 3.0.1 =
*Release Date - 9th July, 2014*
* Removed dependency on PHP's fsockopen function
* Fix spam/ham reports to work when reported outside of the WP dashboard, e.g., from Notifications or the WP app
* Remove jQuery dependency for comment form JavaScript
* Remove unnecessary data from some Akismet comment meta
* Suspended keys will now result in all comments being put in moderation, not spam.
= 3.0.0 =
*Release Date - 15th April, 2014*
* Move Akismet to Settings menu
* Drop Akismet Stats menu
* Add stats snapshot to Akismet settings
* Add Akismet subscription details and status to Akismet settings
* Add contextual help for each page
* Improve Akismet setup to use Jetpack to automate plugin setup
* Fix "Check for Spam" to use AJAX to avoid page timing out
* Fix Akismet settings page to be responsive
* Drop legacy code
* Tidy up CSS and Javascript
* Replace the old discard setting with a new "discard pervasive spam" feature.
= 2.6.0 =
*Release Date - 18th March, 2014*
* Add ajax paging to the check for spam button to handle large volumes of comments
* Optimize javascript and add localization support
* Fix bug in link to spam comments from right now dashboard widget
* Fix bug with deleting old comments to avoid timeouts dealing with large volumes of comments
* Include X-Pingback-Forwarded-For header in outbound WordPress pingback verifications
* Add pre-check for pingbacks, to stop spam before an outbound verification request is made
= 2.5.9 =
*Release Date - 1st August, 2013*
* Update 'Already have a key' link to redirect page rather than depend on javascript
* Fix some non-translatable strings to be translatable
* Update Activation banner in plugins page to redirect user to Akismet config page
= 2.5.8 =
*Release Date - 20th January, 2013*
* Simplify the activation process for new users
* Remove the reporter_ip parameter
* Minor preventative security improvements
= 2.5.7 =
*Release Date - 13th December, 2012*
* FireFox Stats iframe preview bug
* Fix mshots preview when using https
* Add .htaccess to block direct access to files
* Prevent some PHP notices
* Fix Check For Spam return location when referrer is empty
* Fix Settings links for network admins
* Fix prepare() warnings in WP 3.5
= 2.5.6 =
*Release Date - 26th April, 2012*
* Prevent retry scheduling problems on sites where wp_cron is misbehaving
* Preload mshot previews
* Modernize the widget code
* Fix a bug where comments were not held for moderation during an error condition
* Improve the UX and display when comments are temporarily held due to an error
* Make the Check For Spam button force a retry when comments are held due to an error
* Handle errors caused by an invalid key
* Don't retry comments that are too old
* Improve error messages when verifying an API key
= 2.5.5 =
*Release Date - 11th January, 2012*
* Add nonce check for comment author URL remove action
* Fix the settings link
= 2.5.4 =
*Release Date - 5th January, 2012*
* Limit Akismet CSS and Javascript loading in wp-admin to just the pages that need it
* Added author URL quick removal functionality
* Added mShot preview on Author URL hover
* Added empty index.php to prevent directory listing
* Move wp-admin menu items under Jetpack, if it is installed
* Purge old Akismet comment meta data, default of 15 days
= 2.5.3 =
*Release Date - 8th Febuary, 2011*
* Specify the license is GPL v2 or later
* Fix a bug that could result in orphaned commentmeta entries
* Include hotfix for WordPress 3.0.5 filter issue
= 2.5.2 =
*Release Date - 14th January, 2011*
* Properly format the comment count for author counts
* Look for super admins on multisite installs when looking up user roles
* Increase the HTTP request timeout
* Removed padding for author approved count
* Fix typo in function name
* Set Akismet stats iframe height to fixed 2500px. Better to have one tall scroll bar than two side by side.
= 2.5.1 =
*Release Date - 17th December, 2010*
* Fix a bug that caused the "Auto delete" option to fail to discard comments correctly
* Remove the comment nonce form field from the 'Akismet Configuration' page in favor of using a filter, akismet_comment_nonce
* Fixed padding bug in "author" column of posts screen
* Added margin-top to "cleared by ..." badges on dashboard
* Fix possible error when calling akismet_cron_recheck()
* Fix more PHP warnings
* Clean up XHTML warnings for comment nonce
* Fix for possible condition where scheduled comment re-checks could get stuck
* Clean up the comment meta details after deleting a comment
* Only show the status badge if the comment status has been changed by someone/something other than Akismet
* Show a 'History' link in the row-actions
* Translation fixes
* Reduced font-size on author name
* Moved "flagged by..." notification to top right corner of comment container and removed heavy styling
* Hid "flagged by..." notification while on dashboard
= 2.5.0 =
*Release Date - 7th December, 2010*
* Track comment actions under 'Akismet Status' on the edit comment screen
* Fix a few remaining deprecated function calls ( props Mike Glendinning )
* Use HTTPS for the stats IFRAME when wp-admin is using HTTPS
* Use the WordPress HTTP class if available
* Move the admin UI code to a separate file, only loaded when needed
* Add cron retry feature, to replace the old connectivity check
* Display Akismet status badge beside each comment
* Record history for each comment, and display it on the edit page
* Record the complete comment as originally submitted in comment_meta, to use when reporting spam and ham
* Highlight links in comment content
* New option, "Show the number of comments you've approved beside each comment author."
* New option, "Use a nonce on the comment form."
= 2.4.0 =
*Release Date - 23rd August, 2010*
* Spell out that the license is GPLv2
* Fix PHP warnings
* Fix WordPress deprecated function calls
* Fire the delete_comment action when deleting comments
* Move code specific for older WP versions to legacy.php
* General code clean up
= 2.3.0 =
*Release Date - 5th June, 2010*
* Fix "Are you sure" nonce message on config screen in WPMU
* Fix XHTML compliance issue in sidebar widget
* Change author link; remove some old references to WordPress.com accounts
* Localize the widget title (core ticket #13879)
= 2.2.9 =
*Release Date - 2nd June, 2010*
* Eliminate a potential conflict with some plugins that may cause spurious reports
= 2.2.8 =
*Release Date - 27th May, 2010*
* Fix bug in initial comment check for ipv6 addresses
* Report comments as ham when they are moved from spam to moderation
* Report comments as ham when clicking undo after spam
* Use transition_comment_status action when available instead of older actions for spam/ham submissions
* Better diagnostic messages when PHP network functions are unavailable
* Better handling of comments by logged-in users
= 2.2.7 =
*Release Date - 17th December, 2009*
* Add a new AKISMET_VERSION constant
* Reduce the possibility of over-counting spam when another spam filter plugin is in use
* Disable the connectivity check when the API key is hard-coded for WPMU
= 2.2.6 =
*Release Date - 20th July, 2009*
* Fix a global warning introduced in 2.2.5
* Add changelog and additional readme.txt tags
* Fix an array conversion warning in some versions of PHP
* Support a new WPCOM_API_KEY constant for easier use with WordPress MU
= 2.2.5 =
*Release Date - 13th July, 2009*
* Include a new Server Connectivity diagnostic check, to detect problems caused by firewalls
= 2.2.4 =
*Release Date - 3rd June, 2009*
* Fixed a key problem affecting the stats feature in WordPress MU
* Provide additional blog information in Akismet API calls
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,186 @@
<?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 ) ) );
}
}
}
@@ -0,0 +1,584 @@
<?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/get/', '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/get/', '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/get/', '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/get/', '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 );
$current_status = wp_get_comment_status( $comments[0] );
$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( $comments[0]->comment_ID ) ) {
Akismet::log( 'Comment is not spam; marking as spam.' );
wp_spam_comment( $comments[0] );
Akismet::update_comment_history( $comments[0]->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( $comments[0]->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( $comments[0]->comment_ID ) ) {
Akismet::log( 'Akismet marked it as spam; unspamming.' );
wp_unspam_comment( $comments[0] );
akismet::update_comment_history( $comments[0]->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( $comments[0]->comment_ID, '', 'webhook-ham-noaction' );
}
}
}
$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 );
}
}
@@ -0,0 +1,140 @@
<?php
/**
* @package Akismet
*/
// We plan to gradually remove all of the disabled lint rules below.
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
class Akismet_Widget extends WP_Widget {
function __construct() {
load_plugin_textdomain( 'akismet' );
parent::__construct(
'akismet_widget',
__( 'Akismet Widget', 'akismet' ),
array( 'description' => __( 'Display the number of spam comments Akismet has caught', 'akismet' ) )
);
if ( is_active_widget( false, false, $this->id_base ) ) {
add_action( 'wp_head', array( $this, 'css' ) );
}
}
function css() {
?>
<style type="text/css">
.a-stats {
width: auto;
}
.a-stats a {
background: #7CA821;
background-image:-moz-linear-gradient(0% 100% 90deg,#5F8E14,#7CA821);
background-image:-webkit-gradient(linear,0% 0,0% 100%,from(#7CA821),to(#5F8E14));
border: 1px solid #5F8E14;
border-radius:3px;
color: #CFEA93;
cursor: pointer;
display: block;
font-weight: normal;
height: 100%;
-moz-border-radius:3px;
padding: 7px 0 8px;
text-align: center;
text-decoration: none;
-webkit-border-radius:3px;
width: 100%;
}
.a-stats a:hover {
text-decoration: none;
background-image:-moz-linear-gradient(0% 100% 90deg,#6F9C1B,#659417);
background-image:-webkit-gradient(linear,0% 0,0% 100%,from(#659417),to(#6F9C1B));
}
.a-stats .count {
color: #FFF;
display: block;
font-size: 15px;
line-height: 16px;
padding: 0 13px;
white-space: nowrap;
}
</style>
<?php
}
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 $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
</p>
<?php
}
function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = strip_tags( $new_instance['title'] );
return $instance;
}
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'];
}
?>
<div class="a-stats">
<a href="https://akismet.com" target="_blank" rel="noopener" title="">
<?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'];
}
}
function akismet_register_widgets() {
register_widget( 'Akismet_Widget' );
}
add_action( 'widgets_init', 'akismet_register_widgets' );
File diff suppressed because it is too large Load Diff
+2
View File
@@ -0,0 +1,2 @@
<?php
# Silence is golden.
+156
View File
@@ -0,0 +1,156 @@
=== Akismet Anti-spam: Spam Protection ===
Contributors: matt, ryan, andy, mdawaffe, tellyworth, josephscott, lessbloat, eoigal, cfinke, automattic, jgs, procifer, stephdau, kbrownkd, bluefuton, akismetantispam
Tags: comments, spam, antispam, anti-spam, contact form
Requires at least: 5.8
Tested up to: 6.7
Stable tag: 5.3.5
License: GPLv2 or later
The best anti-spam protection to block spam comments and spam in a contact form. The most trusted antispam solution for WordPress and WooCommerce.
== Description ==
The best anti-spam protection to block spam comments and spam in a contact form. The most trusted antispam solution for WordPress and WooCommerce.
Akismet checks your comments and contact form submissions against our global database of spam to prevent your site from publishing malicious content. You can review the comment spam it catches on your blog's "Comments" admin screen.
Major features in Akismet include:
* Automatically checks all comments and filters out the ones that look like spam.
* Each comment has a status history, so you can easily see which comments were caught or cleared by Akismet and which were spammed or unspammed by a moderator.
* URLs are shown in the comment body to reveal hidden or misleading links.
* Moderators can see the number of approved comments for each user.
* A discard feature that outright blocks the worst spam, saving you disk space and speeding up your site.
PS: You'll be prompted to get an Akismet.com API key to use it, once activated. Keys are free for personal blogs; paid subscriptions are available for businesses and commercial sites.
== Installation ==
Upload the Akismet plugin to your blog, activate it, and then enter your Akismet.com API key.
1, 2, 3: You're done!
== Changelog ==
= 5.3.5 =
*Release Date - 18 November 2024*
* Address compatibility issues with < PHP 7.3 in v5.3.4 release.
= 5.3.4 =
*Release Date - 18 November 2024*
* Improve activation notice on Comments for users who haven't set up their API key yet.
* Improve notice about commercial site status.
= 5.3.3 =
*Release Date - 10 July 2024*
* Make setup step clearer for new users.
* Remove the stats section from the configuration page if the site has been revoked from the key.
* Skip the Akismet comment check when the comment matches something in the disallowed list.
* Prompt users on legacy plans to contact Akismet support for upgrades.
= 5.3.2 =
*Release Date - 21 March 2024*
* Improve the empty state shown to new users when no spam has been caught yet.
* Update the message shown to users without a current subscription.
* Add foundations for future webhook support.
= 5.3.1 =
*Release Date - 17 January 2024*
* Make the plugin more resilient when asset files are missing (as seen in WordPress Playground).
* Add a link to the 'Account overview' page on akismet.com.
* Fix a minor error that occurs when another plugin removes all comment actions from the dashboard.
* Add the akismet_request_args filter to allow request args in Akismet API requests to be filtered.
* Fix a bug that causes some contact forms to include unnecessary data in the comment_content parameter.
= 5.3 =
*Release Date - 14 September 2023*
* Improve display of user notices.
* Add stylesheets for RTL languages.
* Remove initial disabled state from 'Save changes' button.
* Improve accessibility of API key entry form.
* Add new filter hooks for Fluent Forms.
* Fix issue with PHP 8.1 compatibility.
= 5.2 =
*Release Date - 21 June 2023*
* Visual refresh of Akismet stats.
* Improve PHP 8.1 compatibility.
* Improve appearance of plugin to match updated stats.
* Change minimum supported PHP version to 5.6 to match WordPress.
* Drop IE11 support and update minimum WordPress version to 5.8 (where IE11 support was removed from WP Core).
= 5.1 =
*Release Date - 20 March 2023*
* Removed unnecessary limit notices from admin page.
* Improved spam detection by including post taxonomies in the comment-check call.
* Removed API keys from stats iframes to avoid possible inadvertent exposure.
= 5.0.2 =
*Release Date - 1 December 2022*
* Improved compatibility with themes that hide or show UI elements based on mouse movements.
* Increased security of API keys by sending them in request bodies instead of subdomains.
= 5.0.1 =
*Release Date - 28 September 2022*
* Added an empty state for the Statistics section on the admin page.
* Fixed a bug that broke some admin page links when Jetpack plugins are active.
* Marked some event listeners as passive to improve performance in newer browsers.
* Disabled interaction observation on forms that post to other domains.
= 5.0 =
*Release Date - 26 July 2022*
* Added a new feature to catch spammers by observing how they interact with the page.
= 4.2.5 =
*Release Date - 11 July 2022*
* Fixed a bug that added unnecessary comment history entries after comment rechecks.
* Added a notice that displays when WP-Cron is disabled and might be affecting comment rechecks.
= 4.2.4 =
*Release Date - 20 May 2022*
* Improved translator instructions for comment history.
* Bumped the "Tested up to" tag to WP 6.0.
= 4.2.3 =
*Release Date - 25 April 2022*
* Improved compatibility with Fluent Forms
* Fixed missing translation domains
* Updated stats URL.
* Improved accessibility of elements on the config page.
= 4.2.2 =
*Release Date - 24 January 2022*
* Improved compatibility with Formidable Forms
* Fixed a bug that could cause issues when multiple contact forms appear on one page.
* Updated delete_comment and deleted_comment actions to pass two arguments to match WordPress core since 4.9.0.
* Added a filter that allows comment types to be excluded when counting users' approved comments.
= 4.2.1 =
*Release Date - 1 October 2021*
* Fixed a bug causing AMP validation to fail on certain pages with forms.
= 4.2 =
*Release Date - 30 September 2021*
* Added links to additional information on API usage notifications.
* Reduced the number of network requests required for a comment page when running Akismet.
* Improved compatibility with the most popular contact form plugins.
* Improved API usage buttons for clarity on what upgrade is needed.
For older changelog entries, please see the [additional changelog.txt file](https://plugins.svn.wordpress.org/akismet/trunk/changelog.txt) delivered with the plugin.
@@ -0,0 +1,8 @@
<div class="akismet-box">
<?php Akismet::view( 'title' ); ?>
<?php Akismet::view( 'setup' ); ?>
</div>
<br/>
<div class="akismet-box">
<?php Akismet::view( 'enter' ); ?>
</div>
+320
View File
@@ -0,0 +1,320 @@
<?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_href = array(
'a' => array(
'href' => true,
),
);
?>
<div id="akismet-plugin-container">
<div class="akismet-masthead">
<div class="akismet-masthead__inside-container">
<?php Akismet::view( 'logo' ); ?>
</div>
</div>
<div class="akismet-lower">
<?php if ( Akismet::get_api_key() ) { ?>
<?php Akismet_Admin::display_status(); ?>
<?php } ?>
<?php if ( ! empty( $notices ) ) { ?>
<?php foreach ( $notices as $notice ) { ?>
<?php Akismet::view( 'notice', array_merge( $notice, array( 'parent_view' => $name ) ) ); ?>
<?php } ?>
<?php } ?>
<?php if ( isset( $stat_totals['all'] ) && isset( $stat_totals['6-months'] ) ) : ?>
<div class="akismet-card">
<div class="akismet-section-header">
<h2 class="akismet-section-header__label">
<span><?php esc_html_e( 'Statistics', 'akismet' ); ?></span>
</h2>
<div class="akismet-section-header__actions">
<a href="<?php echo esc_url( Akismet_Admin::get_page_url( 'stats' ) ); ?>">
<?php esc_html_e( 'Detailed stats', 'akismet' ); ?>
</a>
</div>
</div> <!-- close akismet-section-header -->
<div class="akismet-new-snapshot">
<?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 */ ?>
<div class="akismet-new-snapshot__chart">
<iframe id="stats-iframe" allowtransparency="true" scrolling="no" frameborder="0" style="width: 100%; height: 220px; overflow: hidden;" src="<?php echo esc_url( sprintf( 'https://tools.akismet.com/1.0/snapshot.php?blog=%s&token=%s&height=200&locale=%s&is_redecorated=1', rawurlencode( get_option( 'home' ) ), rawurlencode( Akismet::get_access_token() ), get_locale() ) ); ?>" name="<?php echo esc_attr( 'snapshot-' . filemtime( __FILE__ ) ); ?>" title="<?php echo esc_attr__( 'Akismet stats' ); ?>"></iframe>
</div>
<ul class="akismet-new-snapshot__list">
<li class="akismet-new-snapshot__item">
<h3 class="akismet-new-snapshot__header"><?php esc_html_e( 'Past six months', 'akismet' ); ?></h3>
<span class="akismet-new-snapshot__number"><?php echo number_format( $stat_totals['6-months']->spam ); ?></span>
<span class="akismet-new-snapshot__text"><?php echo esc_html( _n( 'Spam blocked', 'Spam blocked', $stat_totals['6-months']->spam, 'akismet' ) ); ?></span>
</li>
<li class="akismet-new-snapshot__item">
<h3 class="akismet-new-snapshot__header"><?php esc_html_e( 'All time', 'akismet' ); ?></h3>
<span class="akismet-new-snapshot__number"><?php echo number_format( $stat_totals['all']->spam ); ?></span>
<span class="akismet-new-snapshot__text"><?php echo esc_html( _n( 'Spam blocked', 'Spam blocked', $stat_totals['all']->spam, 'akismet' ) ); ?></span>
</li>
<li class="akismet-new-snapshot__item">
<h3 class="akismet-new-snapshot__header"><?php esc_html_e( 'Accuracy', 'akismet' ); ?></h3>
<span class="akismet-new-snapshot__number"><?php echo floatval( $stat_totals['all']->accuracy ); ?>%</span>
<span class="akismet-new-snapshot__text">
<?php
/* translators: %s: number of spam missed by Akismet */
echo esc_html( sprintf( _n( '%s missed spam', '%s missed spam', $stat_totals['all']->missed_spam, 'akismet' ), number_format( $stat_totals['all']->missed_spam ) ) ) . ', ';
/* translators: %s: number of false positive spam flagged by Akismet */
echo esc_html( sprintf( _n( '%s false positive', '%s false positives', $stat_totals['all']->false_positives, 'akismet' ), number_format( $stat_totals['all']->false_positives ) ) );
?>
</span>
</li>
</ul>
</div> <!-- close akismet-new-snapshot -->
</div> <!-- close akismet-card -->
<?php endif; ?>
<?php if ( $akismet_user ) : ?>
<div class="akismet-card">
<div class="akismet-section-header">
<h2 class="akismet-section-header__label">
<span><?php esc_html_e( 'Settings', 'akismet' ); ?></span>
</h2>
</div>
<div class="inside">
<form action="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>" autocomplete="off" method="POST" id="akismet-settings-form">
<div class="akismet-settings">
<?php if ( ! Akismet::predefined_api_key() ) : ?>
<div class="akismet-settings__row">
<h3 class="akismet-settings__row-title">
<label class="akismet-settings__row-label" for="key"><?php esc_html_e( 'API key', 'akismet' ); ?></label>
</h3>
<div class="akismet-settings__row-input">
<span class="api-key"><input id="key" name="key" type="text" size="15" value="<?php echo esc_attr( get_option( 'wordpress_api_key' ) ); ?>" class="<?php echo esc_attr( 'regular-text code ' . $akismet_user->status ); ?>"></span>
</div>
</div>
<?php endif; ?>
<?php
//phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET['ssl_status'] ) ) :
?>
<div class="akismet-settings__row">
<div class="akismet-settings__row-text">
<h3 class="akismet-settings__row-title"><?php esc_html_e( 'SSL status', 'akismet' ); ?></h3>
<div class="akismet-settings__row-description">
<?php if ( ! wp_http_supports( array( 'ssl' ) ) ) : ?>
<strong><?php esc_html_e( 'Disabled.', 'akismet' ); ?></strong>
<?php esc_html_e( 'Your Web server cannot make SSL requests; contact your Web host and ask them to add support for SSL requests.', 'akismet' ); ?>
<?php else : ?>
<?php $ssl_disabled = get_option( 'akismet_ssl_disabled' ); ?>
<?php if ( $ssl_disabled ) : ?>
<strong><?php esc_html_e( 'Temporarily disabled.', 'akismet' ); ?></strong>
<?php esc_html_e( 'Akismet encountered a problem with a previous SSL request and disabled it temporarily. It will begin using SSL for requests again shortly.', 'akismet' ); ?>
<?php else : ?>
<strong><?php esc_html_e( 'Enabled.', 'akismet' ); ?></strong>
<?php esc_html_e( 'All systems functional.', 'akismet' ); ?>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
</div>
<?php endif; ?>
<div class="akismet-settings__row">
<div class="akismet-settings__row-text">
<h3 class="akismet-settings__row-title"><?php esc_html_e( 'Comments', 'akismet' ); ?></h3>
</div>
<div class="akismet-settings__row-input">
<label class="akismet-settings__row-input-label" for="akismet_show_user_comments_approved">
<input
name="akismet_show_user_comments_approved"
id="akismet_show_user_comments_approved"
value="1"
type="checkbox"
<?php
// If the option isn't set, or if it's enabled ('1'), or if it was enabled a long time ago ('true'), check the checkbox.
checked( true, ( in_array( get_option( 'akismet_show_user_comments_approved' ), array( false, '1', 'true' ), true ) ) );
?>
/>
<span class="akismet-settings__row-label-text">
<?php esc_html_e( 'Show the number of approved comments beside each comment author.', 'akismet' ); ?>
</span>
</label>
</div>
</div>
<div class="akismet-settings__row is-radio">
<div class="akismet-settings__row-text">
<h3 class="akismet-settings__row-title"><?php esc_html_e( 'Spam filtering', 'akismet' ); ?></h3>
</div>
<div class="akismet-settings__row-input">
<fieldset>
<legend class="screen-reader-text">
<span><?php esc_html_e( 'Akismet Anti-spam strictness', 'akismet' ); ?></span>
</legend>
<div>
<label class="akismet-settings__row-input-label" for="akismet_strictness_1">
<input type="radio" name="akismet_strictness" id="akismet_strictness_1" value="1" <?php checked( '1', get_option( 'akismet_strictness' ) ); ?> />
<span class="akismet-settings__row-label-text">
<?php esc_html_e( 'Silently discard the worst and most pervasive spam so I never see it.', 'akismet' ); ?>
</span>
</label>
</div>
<div>
<label class="akismet-settings__row-input-label" for="akismet_strictness_0">
<input type="radio" name="akismet_strictness" id="akismet_strictness_0" value="0" <?php checked( '0', get_option( 'akismet_strictness' ) ); ?> />
<span class="akismet-settings__row-label-text">
<?php esc_html_e( 'Always put spam in the Spam folder for review.', 'akismet' ); ?>
</span>
</label>
</div>
</fieldset>
<div class="akismet-settings__row-note">
<strong><?php esc_html_e( 'Note:', 'akismet' ); ?></strong>
<?php
$delete_interval = max( 1, intval( apply_filters( 'akismet_delete_comment_interval', 15 ) ) );
$spam_folder_link = sprintf(
'<a href="%s">%s</a>',
esc_url( admin_url( 'edit-comments.php?comment_status=spam' ) ),
esc_html__( 'spam folder', 'akismet' )
);
// The _n() needs to be on one line so the i18n tooling can extract the translator comment.
/* translators: %1$s: spam folder link, %2$d: delete interval in days */
$delete_message = _n( 'Spam in the %1$s older than %2$d day is deleted automatically.', 'Spam in the %1$s older than %2$d days is deleted automatically.', $delete_interval, 'akismet' );
printf(
wp_kses( $delete_message, $kses_allow_link_href ),
wp_kses( $spam_folder_link, $kses_allow_link_href ),
esc_html( $delete_interval )
);
?>
</div>
</div>
</div>
<div class="akismet-settings__row is-radio">
<div class="akismet-settings__row-text">
<h3 class="akismet-settings__row-title"><?php esc_html_e( 'Privacy', 'akismet' ); ?></h3>
</div>
<div class="akismet-settings__row-input">
<fieldset>
<legend class="screen-reader-text">
<span><?php esc_html_e( 'Akismet privacy notice', 'akismet' ); ?></span>
</legend>
<div>
<label class="akismet-settings__row-input-label" for="akismet_comment_form_privacy_notice_display">
<input type="radio" name="akismet_comment_form_privacy_notice" id="akismet_comment_form_privacy_notice_display" value="display" <?php checked( 'display', get_option( 'akismet_comment_form_privacy_notice' ) ); ?> />
<span class="akismet-settings__row-label-text">
<?php esc_html_e( 'Display a privacy notice under your comment forms.', 'akismet' ); ?>
</span>
</label>
</div>
<div>
<label class="akismet-settings__row-input-label" for="akismet_comment_form_privacy_notice_hide">
<input type="radio" name="akismet_comment_form_privacy_notice" id="akismet_comment_form_privacy_notice_hide" value="hide" <?php echo in_array( get_option( 'akismet_comment_form_privacy_notice' ), array( 'display', 'hide' ), true ) ? checked( 'hide', get_option( 'akismet_comment_form_privacy_notice' ), false ) : 'checked="checked"'; ?> />
<span class="akismet-settings__row-label-text">
<?php esc_html_e( 'Do not display privacy notice.', 'akismet' ); ?>
</span>
</label>
</div>
</fieldset>
<div class="akismet-settings__row-note">
<?php esc_html_e( 'To help your site with transparency under privacy laws like the GDPR, Akismet can display a notice to your users under your comment forms.', 'akismet' ); ?>
</div>
</div>
</div>
</div>
<div class="akismet-card-actions">
<?php if ( ! Akismet::predefined_api_key() ) : ?>
<div id="delete-action" class="akismet-card-actions__secondary-action">
<a class="submitdelete deletion" href="<?php echo esc_url( Akismet_Admin::get_page_url( 'delete_key' ) ); ?>"><?php esc_html_e( 'Disconnect this account', 'akismet' ); ?></a>
</div>
<?php endif; ?>
<?php wp_nonce_field( Akismet_Admin::NONCE ); ?>
<div id="publishing-action">
<input type="hidden" name="action" value="enter-key">
<input type="submit" name="submit" id="submit" class="akismet-button akismet-could-be-primary" value="<?php esc_attr_e( 'Save changes', 'akismet' ); ?>">
</div>
</div>
</form>
</div>
</div>
<?php if ( ! Akismet::predefined_api_key() ) : ?>
<div class="akismet-card">
<div class="akismet-section-header">
<h2 class="akismet-section-header__label">
<span><?php esc_html_e( 'Account', 'akismet' ); ?></span>
</h2>
</div>
<div class="inside">
<table class="akismet-account">
<tbody>
<tr>
<th scope="row"><?php esc_html_e( 'Subscription type', 'akismet' ); ?></th>
<td>
<?php echo esc_html( $akismet_user->account_name ); ?>
</td>
</tr>
<tr>
<th scope="row"><?php esc_html_e( 'Status', 'akismet' ); ?></th>
<td>
<?php
if ( 'cancelled' === $akismet_user->status ) :
esc_html_e( 'Cancelled', 'akismet' );
elseif ( 'suspended' === $akismet_user->status ) :
esc_html_e( 'Suspended', 'akismet' );
elseif ( 'missing' === $akismet_user->status ) :
esc_html_e( 'Missing', 'akismet' );
elseif ( 'no-sub' === $akismet_user->status ) :
esc_html_e( 'No subscription found', 'akismet' );
else :
esc_html_e( 'Active', 'akismet' );
endif;
?>
</td>
</tr>
<?php if ( $akismet_user->next_billing_date ) : ?>
<tr>
<th scope="row"><?php esc_html_e( 'Next billing date', 'akismet' ); ?></th>
<td>
<?php echo esc_html( gmdate( 'F j, Y', $akismet_user->next_billing_date ) ); ?>
</td>
</tr>
<?php endif; ?>
</tbody>
</table>
<div class="akismet-card-actions">
<?php if ( $akismet_user->status === 'active' ) : ?>
<div class="akismet-card-actions__secondary-action">
<a href="https://akismet.com/account" target="_blank" rel="noopener noreferrer" aria-label="Account overview on akismet.com (opens in a new window)"><?php esc_html_e( 'Account overview', 'akismet' ); ?></a>
</div>
<?php endif; ?>
<div id="publishing-action">
<?php
Akismet::view(
'get',
array(
'text' => ( $akismet_user->account_type === 'free-api-key' && $akismet_user->status === 'active' ? __( 'Upgrade', 'akismet' ) : __( 'Change', 'akismet' ) ),
'redirect' => 'upgrade',
)
);
?>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
@@ -0,0 +1,98 @@
<?php
//phpcs:disable VariableAnalysis
// There are "undefined" variables here because they're defined in the code that includes this file as a template.
?>
<div class="akismet-box">
<?php Akismet::view( 'title' ); ?>
<div class="akismet-jp-connect">
<h3><?php esc_html_e( 'Connect with Jetpack', 'akismet' ); ?></h3>
<?php if ( in_array( $akismet_user->status, array( 'no-sub', 'missing' ) ) ) { ?>
<p><?php esc_html_e( 'Use your Jetpack connection to set up Akismet.', 'akismet' ); ?></p>
<form name="akismet_activate" id="akismet_activate" action="https://akismet.com/get/" method="post" class="akismet-right" target="_blank">
<input type="hidden" name="passback_url" value="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>"/>
<input type="hidden" name="blog" value="<?php echo esc_url( get_option( 'home' ) ); ?>"/>
<input type="hidden" name="auto-connect" value="<?php echo esc_attr( $akismet_user->ID ); ?>"/>
<input type="hidden" name="redirect" value="plugin-signup"/>
<input type="submit" class="akismet-button akismet-is-primary" value="<?php esc_attr_e( 'Connect with Jetpack', 'akismet' ); ?>"/>
</form>
<?php echo get_avatar( $akismet_user->user_email, null, null, null, array( 'class' => 'akismet-jetpack-gravatar' ) ); ?>
<p>
<?php
/* translators: %s is the WordPress.com username */
printf( esc_html( __( 'You are connected as %s.', 'akismet' ) ), '<b>' . esc_html( $akismet_user->user_login ) . '</b>' );
?>
<br />
<span class="akismet-jetpack-email"><?php echo esc_html( $akismet_user->user_email ); ?></span>
</p>
<?php } elseif ( $akismet_user->status == 'cancelled' ) { ?>
<p><?php esc_html_e( 'Use your Jetpack connection to set up Akismet.', 'akismet' ); ?></p>
<form name="akismet_activate" id="akismet_activate" action="https://akismet.com/get/" method="post" class="akismet-right" target="_blank">
<input type="hidden" name="passback_url" value="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>"/>
<input type="hidden" name="blog" value="<?php echo esc_url( get_option( 'home' ) ); ?>"/>
<input type="hidden" name="user_id" value="<?php echo esc_attr( $akismet_user->ID ); ?>"/>
<input type="hidden" name="redirect" value="upgrade"/>
<input type="submit" class="akismet-button akismet-is-primary" value="<?php esc_attr_e( 'Connect with Jetpack', 'akismet' ); ?>"/>
</form>
<?php echo get_avatar( $akismet_user->user_email, null, null, null, array( 'class' => 'akismet-jetpack-gravatar' ) ); ?>
<p>
<?php
/* translators: %s is the WordPress.com email address */
echo esc_html( sprintf( __( 'Your subscription for %s is cancelled.', 'akismet' ), $akismet_user->user_email ) );
?>
<br />
<span class="akismet-jetpack-email"><?php echo esc_html( $akismet_user->user_email ); ?></span>
</p>
<?php } elseif ( $akismet_user->status == 'suspended' ) { ?>
<div class="akismet-right">
<p><a href="https://akismet.com/contact" class="akismet-button akismet-is-primary"><?php esc_html_e( 'Contact Akismet support', 'akismet' ); ?></a></p>
</div>
<p>
<span class="akismet-alert-text">
<?php
/* translators: %s is the WordPress.com email address */
echo esc_html( sprintf( __( 'Your subscription for %s is suspended.', 'akismet' ), $akismet_user->user_email ) );
?>
</span>
<?php esc_html_e( 'No worries! Get in touch and we&#8217;ll sort this out.', 'akismet' ); ?>
</p>
<?php } else { // ask do they want to use akismet account found using jetpack wpcom connection ?>
<p><?php esc_html_e( 'Use your Jetpack connection to set up Akismet.', 'akismet' ); ?></p>
<form name="akismet_use_wpcom_key" action="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>" method="post" id="akismet-activate" class="akismet-right">
<input type="hidden" name="key" value="<?php echo esc_attr( $akismet_user->api_key ); ?>"/>
<input type="hidden" name="action" value="enter-key">
<?php wp_nonce_field( Akismet_Admin::NONCE ); ?>
<input type="submit" class="akismet-button akismet-is-primary" value="<?php esc_attr_e( 'Connect with Jetpack', 'akismet' ); ?>"/>
</form>
<?php echo get_avatar( $akismet_user->user_email, null, null, null, array( 'class' => 'akismet-jetpack-gravatar' ) ); ?>
<p>
<?php
/* translators: %s is the WordPress.com username */
printf( esc_html( __( 'You are connected as %s.', 'akismet' ) ), '<b>' . esc_html( $akismet_user->user_login ) . '</b>' );
?>
<br />
<span class="akismet-jetpack-email"><?php echo esc_html( $akismet_user->user_email ); ?></span>
</p>
<?php } ?>
</div>
<div class="akismet-ak-connect">
<?php Akismet::view( 'setup' ); ?>
</div>
<div class="centered akismet-toggles">
<a href="#" class="toggle-jp-connect"><?php esc_html_e( 'Connect with Jetpack', 'akismet' ); ?></a>
<a href="#" class="toggle-ak-connect"><?php esc_html_e( 'Set up a different account', 'akismet' ); ?></a>
</div>
</div>
<br/>
<div class="akismet-box">
<?php Akismet::view( 'enter' ); ?>
</div>
@@ -0,0 +1,14 @@
<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>
+18
View File
@@ -0,0 +1,18 @@
<?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 );
}
?>
<form name="akismet_activate" action="https://akismet.com/get/" method="POST" target="_blank">
<input type="hidden" name="passback_url" value="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>"/>
<input type="hidden" name="blog" value="<?php echo esc_url( get_option( 'home' ) ); ?>"/>
<input type="hidden" name="redirect" value="<?php echo isset( $redirect ) ? $redirect : 'plugin-signup'; ?>"/>
<button type="submit" class="<?php echo esc_attr( $submit_classes_attr ); ?>" value="<?php echo esc_attr( $text ); ?>"><?php echo esc_attr( $text ) . '<span class="screen-reader-text">' . esc_html__( '(opens in a new tab)', 'akismet' ) . '</span>'; ?></button>
</form>
+13
View File
@@ -0,0 +1,13 @@
<?php
//phpcs:disable VariableAnalysis
// There are "undefined" variables here because they're defined in the code that includes this file as a template.
?>
<div class="akismet-masthead__logo-container">
<?php if ( isset( $include_logo_link ) && $include_logo_link === true ) : ?>
<a href="<?php echo esc_url( Akismet_Admin::get_page_url() ); ?>" class="akismet-masthead__logo-link">
<?php endif; ?>
<img class="akismet-masthead__logo" src="<?php echo esc_url( plugins_url( '../_inc/img/akismet-refresh-logo@2x.png', __FILE__ ) ); ?>" srcset="<?php echo esc_url( plugins_url( '../_inc/img/akismet-refresh-logo.svg', __FILE__ ) ); ?>" alt="Akismet logo" />
<?php if ( isset( $include_logo_link ) && $include_logo_link === true ) : ?>
</a>
<?php endif; ?>
</div>
+350
View File
@@ -0,0 +1,350 @@
<?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,
),
);
$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 && $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 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/' ) ), $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 href="%s">please get in touch</a>.', 'akismet' ), esc_url( 'https://akismet.com/contact/?purpose=commercial' ) ), $kses_allow_link );
?>
</p>
</div>
<div class="akismet-alert-button-wrapper">
<a href="https://akismet.com/pricing/?flow=upgrade&amp;utm_source=akismet_plugin&amp;utm_campaign=commercial_notice&amp;utm_medium=banner" class="akismet-alert-button akismet-button">
<?php esc_html_e( 'Upgrade plan' ); ?>
</a>
</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
/* translators: the placeholder is a clickable URL that leads to more information regarding an error code. */
printf( esc_html__( 'For more information: %s', 'akismet' ), '<a href="https://akismet.com/errors/' . esc_attr( $code ) . '">https://akismet.com/errors/' . esc_attr( $code ) . '</a>' );
?>
</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
/* translators: The placeholder is a URL. */
echo wp_kses( sprintf( __( 'Your web host or server administrator has disabled PHP&#8217;s <code>gethostbynamel</code> function. <strong>Akismet cannot work correctly until this is fixed.</strong> Please contact your web host or firewall administrator and give them <a href="%s" target="_blank">this information about Akismet&#8217;s system requirements</a>.', 'akismet' ), esc_url( 'https://akismet.com/akismet-hosting-faq/' ) ), 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&#8217;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 href="%s" target="_blank">our guide about firewalls</a>.', 'akismet' ), esc_url( 'https://akismet.com/akismet-hosting-faq/' ) ), $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 href="%s" target="_blank">update your payment details</a>.', 'akismet' ), esc_url( 'https://akismet.com/account/' ) ), $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 your <a href="%s" target="_blank">Akismet account page</a> to reactivate your subscription.', 'akismet' ), esc_url( 'https://akismet.com/account/' ) ), $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 href="%s" target="_blank">Akismet support</a> for assistance.', 'akismet' ), esc_url( 'https://akismet.com/contact/' ) ), $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 href="%s" target="_blank">contributing a token amount</a>.', 'akismet' ), esc_url( 'https://akismet.com/pricing' ) ), $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 href="%s" target="_blank">Akismet support</a> for assistance.', 'akismet' ), esc_url( 'https://akismet.com/contact/' ) ), $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&#8217;t have an Akismet plan.', 'akismet' ); ?></h3>
<p><?php echo esc_html__( 'Your API key must have an Akismet plan before it can protect your site from spam.', 'akismet' ); ?></p>
<p>
<?php
/* translators: the placeholder is the URL to the Akismet pricing page. */
echo wp_kses( sprintf( __( 'Please <a href="%s" target="_blank">choose a plan</a> to get started with Akismet.', 'akismet' ), esc_url( 'https://akismet.com/pricing' ) ), $kses_allow_link );
?>
</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 === '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 href="%s" target="_blank">contact Akismet support</a>.', 'akismet' ),
'https://akismet.com/contact/'
),
$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 href="%s" target="_blank">our guide about firewalls</a> and check your server configuration.', 'akismet' ),
'https://blog.akismet.com/akismet-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&#8217;s limit', 'akismet' );
break;
case 'THIRD_MONTH_APPROACHING_LIMIT':
esc_html_e( 'Your Akismet account usage is approaching your plan&#8217;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&#8217;s limit of %3$s.', 'akismet' ),
esc_html( gmdate( 'F' ) . ' 1' ),
number_format( $api_calls ),
number_format( $usage_limit )
)
);
echo '&nbsp;';
echo '<a href="https://docs.akismet.com/akismet-api-usage-limits/" 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&#8217;s limit for two consecutive months. Next month, we will restrict your account after you reach the limit. Please consider upgrading your plan.', 'akismet' ) );
echo '&nbsp;';
echo '<a href="https://docs.akismet.com/akismet-api-usage-limits/" 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&#8217;s limit for the third consecutive month. We will restrict your account after you reach the limit. Upgrade your plan so Akismet can continue blocking spam.', 'akismet' ) );
echo '&nbsp;';
echo '<a href="https://docs.akismet.com/akismet-api-usage-limits/" 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&#8217;s limit for three consecutive months. We have restricted your account for the rest of the month. Upgrade your plan so Akismet can continue blocking spam.', 'akismet' ) );
echo '&nbsp;';
echo '<a href="https://docs.akismet.com/akismet-api-usage-limits/" 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 ); ?>" 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 only a qty upgrade is required, show a more generic message.
esc_html_e( 'Upgrade your subscription level', 'akismet' );
} else {
echo esc_html(
sprintf(
/* translators: The placeholder is the name of a subscription level, like "Plus" or "Enterprise" . */
__( 'Upgrade to %s', 'akismet' ),
$upgrade_plan
)
);
}
?>
</a>
</div>
</div>
<?php endif; ?>
@@ -0,0 +1,11 @@
<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>
@@ -0,0 +1,12 @@
<div class="akismet-setup-instructions">
<p><?php esc_html_e( 'Set up your Akismet account to enable spam filtering on this site.', 'akismet' ); ?></p>
<?php
Akismet::view(
'get',
array(
'text' => __( 'Choose an Akismet plan', 'akismet' ),
'classes' => array( 'akismet-button', 'akismet-is-primary' ),
)
);
?>
</div>
@@ -0,0 +1,29 @@
<?php
//phpcs:disable VariableAnalysis
// There are "undefined" variables here because they're defined in the code that includes this file as a template.
?>
<div id="akismet-plugin-container">
<div class="akismet-masthead">
<div class="akismet-masthead__inside-container">
<?php Akismet::view( 'logo' ); ?>
</div>
</div>
<div class="akismet-lower">
<?php Akismet_Admin::display_status(); ?>
<div class="akismet-boxes">
<?php
if ( Akismet::predefined_api_key() ) {
Akismet::view( 'predefined' );
} elseif ( $akismet_user && in_array( $akismet_user->status, array( 'active', 'active-dunning', 'no-sub', 'missing', 'cancelled', 'suspended' ) ) ) {
Akismet::view( 'connect-jp', compact( 'akismet_user' ) );
} else {
Akismet::view( 'activate' );
}
?>
</div>
</div>
</div>
@@ -0,0 +1,12 @@
<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_locale() ) ) ); ?>" name="<?php echo esc_attr( 'user-stats- ' . filemtime( __FILE__ ) ); ?>" width="100%" height="2500px" frameborder="0" title="<?php echo esc_attr__( 'Akismet detailed stats' ); ?>"></iframe>
</div>
@@ -0,0 +1,3 @@
<div class="centered akismet-box-header">
<h2><?php esc_html_e( 'Eliminate spam from your site', 'akismet' ); ?></h2>
</div>
+215
View File
@@ -0,0 +1,215 @@
<?php
global $wpcom_api_key, $akismet_api_host, $akismet_api_port;
$wpcom_api_key = defined( 'WPCOM_API_KEY' ) ? constant( 'WPCOM_API_KEY' ) : '';
$akismet_api_host = Akismet::get_api_key() . '.rest.akismet.com';
$akismet_api_port = 80;
function akismet_test_mode() {
return Akismet::is_test_mode();
}
function akismet_http_post( $request, $host, $path, $port = 80, $ip = null ) {
$path = str_replace( '/1.1/', '', $path );
return Akismet::http_post( $request, $path, $ip );
}
function akismet_microtime() {
return Akismet::_get_microtime();
}
function akismet_delete_old() {
return Akismet::delete_old_comments();
}
function akismet_delete_old_metadata() {
return Akismet::delete_old_comments_meta();
}
function akismet_check_db_comment( $id, $recheck_reason = 'recheck_queue' ) {
return Akismet::check_db_comment( $id, $recheck_reason );
}
function akismet_rightnow() {
if ( ! class_exists( 'Akismet_Admin' ) ) {
return false;
}
return Akismet_Admin::rightnow_stats();
}
function akismet_admin_init() {
_deprecated_function( __FUNCTION__, '3.0' );
}
function akismet_version_warning() {
_deprecated_function( __FUNCTION__, '3.0' );
}
function akismet_load_js_and_css() {
_deprecated_function( __FUNCTION__, '3.0' );
}
function akismet_nonce_field( $action = -1 ) {
return wp_nonce_field( $action );
}
function akismet_plugin_action_links( $links, $file ) {
return Akismet_Admin::plugin_action_links( $links, $file );
}
function akismet_conf() {
_deprecated_function( __FUNCTION__, '3.0' );
}
function akismet_stats_display() {
_deprecated_function( __FUNCTION__, '3.0' );
}
function akismet_stats() {
return Akismet_Admin::dashboard_stats();
}
function akismet_admin_warnings() {
_deprecated_function( __FUNCTION__, '3.0' );
}
function akismet_comment_row_action( $a, $comment ) {
return Akismet_Admin::comment_row_actions( $a, $comment );
}
function akismet_comment_status_meta_box( $comment ) {
return Akismet_Admin::comment_status_meta_box( $comment );
}
function akismet_comments_columns( $columns ) {
_deprecated_function( __FUNCTION__, '3.0' );
return $columns;
}
function akismet_comment_column_row( $column, $comment_id ) {
_deprecated_function( __FUNCTION__, '3.0' );
}
function akismet_text_add_link_callback( $m ) {
return Akismet_Admin::text_add_link_callback( $m );
}
function akismet_text_add_link_class( $comment_text ) {
return Akismet_Admin::text_add_link_class( $comment_text );
}
function akismet_check_for_spam_button( $comment_status ) {
return Akismet_Admin::check_for_spam_button( $comment_status );
}
function akismet_submit_nonspam_comment( $comment_id ) {
return Akismet::submit_nonspam_comment( $comment_id );
}
function akismet_submit_spam_comment( $comment_id ) {
return Akismet::submit_spam_comment( $comment_id );
}
function akismet_transition_comment_status( $new_status, $old_status, $comment ) {
return Akismet::transition_comment_status( $new_status, $old_status, $comment );
}
function akismet_spam_count( $type = false ) {
return Akismet_Admin::get_spam_count( $type );
}
function akismet_recheck_queue() {
return Akismet_Admin::recheck_queue();
}
function akismet_remove_comment_author_url() {
return Akismet_Admin::remove_comment_author_url();
}
function akismet_add_comment_author_url() {
return Akismet_Admin::add_comment_author_url();
}
function akismet_check_server_connectivity() {
return Akismet_Admin::check_server_connectivity();
}
function akismet_get_server_connectivity( $cache_timeout = 86400 ) {
return Akismet_Admin::get_server_connectivity( $cache_timeout );
}
function akismet_server_connectivity_ok() {
_deprecated_function( __FUNCTION__, '3.0' );
return true;
}
function akismet_admin_menu() {
return Akismet_Admin::admin_menu();
}
function akismet_load_menu() {
return Akismet_Admin::load_menu();
}
function akismet_init() {
_deprecated_function( __FUNCTION__, '3.0' );
}
function akismet_get_key() {
return Akismet::get_api_key();
}
function akismet_check_key_status( $key, $ip = null ) {
return Akismet::check_key_status( $key, $ip );
}
function akismet_update_alert( $response ) {
return Akismet::update_alert( $response );
}
function akismet_verify_key( $key, $ip = null ) {
return Akismet::verify_key( $key, $ip );
}
function akismet_get_user_roles( $user_id ) {
return Akismet::get_user_roles( $user_id );
}
function akismet_result_spam( $approved ) {
return Akismet::comment_is_spam( $approved );
}
function akismet_result_hold( $approved ) {
return Akismet::comment_needs_moderation( $approved );
}
function akismet_get_user_comments_approved( $user_id, $comment_author_email, $comment_author, $comment_author_url ) {
return Akismet::get_user_comments_approved( $user_id, $comment_author_email, $comment_author, $comment_author_url );
}
function akismet_update_comment_history( $comment_id, $message, $event = null ) {
return Akismet::update_comment_history( $comment_id, $message, $event );
}
function akismet_get_comment_history( $comment_id ) {
return Akismet::get_comment_history( $comment_id );
}
function akismet_cmp_time( $a, $b ) {
return Akismet::_cmp_time( $a, $b );
}
function akismet_auto_check_update_meta( $id, $comment ) {
return Akismet::auto_check_update_meta( $id, $comment );
}
function akismet_auto_check_comment( $commentdata ) {
return Akismet::auto_check_comment( $commentdata );
}
function akismet_get_ip_address() {
return Akismet::get_ip_address();
}
function akismet_cron_recheck() {
return Akismet::cron_recheck();
}
function akismet_add_comment_nonce( $post_id ) {
return Akismet::add_comment_nonce( $post_id );
}
function akismet_fix_scheduled_recheck() {
return Akismet::fix_scheduled_recheck();
}
function akismet_spam_comments() {
_deprecated_function( __FUNCTION__, '3.0' );
return array();
}
function akismet_spam_totals() {
_deprecated_function( __FUNCTION__, '3.0' );
return array();
}
function akismet_manage_page() {
_deprecated_function( __FUNCTION__, '3.0' );
}
function akismet_caught() {
_deprecated_function( __FUNCTION__, '3.0' );
}
function redirect_old_akismet_urls() {
_deprecated_function( __FUNCTION__, '3.0' );
}
function akismet_kill_proxy_check( $option ) {
_deprecated_function( __FUNCTION__, '3.0' );
return 0;
}
function akismet_pingback_forwarded_for( $r, $url ) {
// This functionality is now in core.
return false;
}
function akismet_pre_check_pingback( $method ) {
return Akismet::pre_check_pingback( $method );
}
+100
View File
@@ -0,0 +1,100 @@
<?php
/**
* @package Hello_Dolly
* @version 1.7.2
*/
/*
Plugin Name: Hello Dolly
Plugin URI: http://wordpress.org/plugins/hello-dolly/
Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from <cite>Hello, Dolly</cite> in the upper right of your admin screen on every page.
Author: Matt Mullenweg
Version: 1.7.2
Author URI: http://ma.tt/
*/
function hello_dolly_get_lyric() {
/** These are the lyrics to Hello Dolly */
$lyrics = "Hello, Dolly
Well, hello, Dolly
It's so nice to have you back where you belong
You're lookin' swell, Dolly
I can tell, Dolly
You're still glowin', you're still crowin'
You're still goin' strong
I feel the room swayin'
While the band's playin'
One of our old favorite songs from way back when
So, take her wrap, fellas
Dolly, never go away again
Hello, Dolly
Well, hello, Dolly
It's so nice to have you back where you belong
You're lookin' swell, Dolly
I can tell, Dolly
You're still glowin', you're still crowin'
You're still goin' strong
I feel the room swayin'
While the band's playin'
One of our old favorite songs from way back when
So, golly, gee, fellas
Have a little faith in me, fellas
Dolly, never go away
Promise, you'll never go away
Dolly'll never go away again";
// Here we split it into lines.
$lyrics = explode( "\n", $lyrics );
// And then randomly choose a line.
return wptexturize( $lyrics[ mt_rand( 0, count( $lyrics ) - 1 ) ] );
}
// This just echoes the chosen line, we'll position it later.
function hello_dolly() {
$chosen = hello_dolly_get_lyric();
$lang = '';
if ( 'en_' !== substr( get_user_locale(), 0, 3 ) ) {
$lang = ' lang="en"';
}
printf(
'<p id="dolly"><span class="screen-reader-text">%s </span><span dir="ltr"%s>%s</span></p>',
__( 'Quote from Hello Dolly song, by Jerry Herman:' ),
$lang,
$chosen
);
}
// Now we set that function up to execute when the admin_notices action is called.
add_action( 'admin_notices', 'hello_dolly' );
// We need some CSS to position the paragraph.
function dolly_css() {
echo "
<style type='text/css'>
#dolly {
float: right;
padding: 5px 10px;
margin: 0;
font-size: 12px;
line-height: 1.6666;
}
.rtl #dolly {
float: left;
}
.block-editor-page #dolly {
display: none;
}
@media screen and (max-width: 782px) {
#dolly,
.rtl #dolly {
float: none;
padding-left: 0;
padding-right: 0;
}
}
</style>
";
}
add_action( 'admin_head', 'dolly_css' );
+2
View File
@@ -0,0 +1,2 @@
<?php
// Silence is golden.
+94
View File
@@ -0,0 +1,94 @@
<?php
/**
* Compatibility files for third-party plugins.
* This is used to improve compatibility of specific Jetpack features with third-party plugins.
*
* @package automattic/jetpack
*/
namespace Automattic\Jetpack;
use Automattic\Jetpack\Status\Host;
add_action( 'plugins_loaded', __NAMESPACE__ . '\load_3rd_party_compat_filters', 11 );
/**
* Loads the individual 3rd-party compat functions.
*
* This is a refactor of load_3rd_party() to load the individual compat files only when needed instead of universally.
*/
function load_3rd_party_compat_filters() {
// bbPress
if ( function_exists( 'bbpress' ) ) {
require_once JETPACK__PLUGIN_DIR . '/3rd-party/bbpress.php';
}
// Beaver Builder
if ( class_exists( 'FLBuilder' ) ) {
require_once JETPACK__PLUGIN_DIR . '/3rd-party/beaverbuilder.php';
}
// Bitly
if ( class_exists( 'Bitly' ) ) {
require_once JETPACK__PLUGIN_DIR . '/3rd-party/bitly.php';
}
// BuddyPress
if ( class_exists( 'BuddyPress' ) ) {
require_once JETPACK__PLUGIN_DIR . '/3rd-party/buddypress.php';
}
// AMP. AMP__DIR__ is defined in the AMP plugin since the very first version.
if ( Constants::is_defined( 'AMP__DIR__' ) ) {
require_once JETPACK__PLUGIN_DIR . '/3rd-party/amp.php';
}
// Domain Mapping. All assume multisite, so it's an easy check.
if ( Constants::is_defined( 'SUNRISE' ) ) {
require_once JETPACK__PLUGIN_DIR . '/3rd-party/class-domain-mapping.php';
}
// Debug Bar
if ( class_exists( 'Debug_Bar' ) ) {
require_once JETPACK__PLUGIN_DIR . '/3rd-party/debug-bar.php';
}
// Letting these always load since it handles somethings upon plugin activation.
require_once JETPACK__PLUGIN_DIR . '/3rd-party/creative-mail.php';
require_once JETPACK__PLUGIN_DIR . '/3rd-party/jetpack-backup.php';
require_once JETPACK__PLUGIN_DIR . '/3rd-party/jetpack-boost.php';
require_once JETPACK__PLUGIN_DIR . '/3rd-party/woocommerce-services.php';
// qTranslate. Plugin closed in 2021, but leaving support for now to allow sites to drop it.
if ( Constants::is_defined( 'QTX_VERSION' ) ) {
require_once JETPACK__PLUGIN_DIR . '/3rd-party/qtranslate-x.php';
}
// VaultPress.
if ( Constants::is_defined( 'VAULTPRESS__VERSION' ) || class_exists( 'VaultPress' ) ) {
require_once JETPACK__PLUGIN_DIR . '/3rd-party/vaultpress.php';
}
// Web Stories
if ( Constants::is_defined( 'WEBSTORIES_VERSION' ) ) {
require_once JETPACK__PLUGIN_DIR . '/3rd-party/web-stories.php';
}
// WooCommerce
if ( class_exists( 'WooCommerce' ) ) {
require_once JETPACK__PLUGIN_DIR . '/3rd-party/woocommerce.php';
}
// Atomic Weekly
if ( ( new Host() )->is_atomic_platform() ) {
require_once JETPACK__PLUGIN_DIR . '/3rd-party/atomic.php';
}
// WordPress.com Reader
require_once JETPACK__PLUGIN_DIR . '/3rd-party/wpcom-reader.php';
// WPML
if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
require_once JETPACK__PLUGIN_DIR . '/3rd-party/wpml.php';
}
}
+23
View File
@@ -0,0 +1,23 @@
<?php
/**
* This file contains compatibility features for AMP to improve Jetpack feature support.
*
* @package automattic/jetpack
*/
namespace Automattic\Jetpack;
/**
* Load Jetpack_AMP_Support.
*/
function load_3rd_party_amp_support() {
// Only load the support class when AMP actually initializes.
// This avoids calls to some slow functions if the plugin is loaded but
// 'amp_is_enabled' is used to prevent it from initializing.
require_once JETPACK__PLUGIN_DIR . '/3rd-party/class.jetpack-amp-support.php';
add_action( 'init', array( 'Jetpack_AMP_Support', 'init' ), 1 );
add_action( 'admin_init', array( 'Jetpack_AMP_Support', 'admin_init' ), 1 );
}
add_action( 'amp_init', __NAMESPACE__ . '\load_3rd_party_amp_support' );
+33
View File
@@ -0,0 +1,33 @@
<?php
/**
* Helper functions for the Atomic platform.
*
* @package automattic/jetpack
*/
namespace Automattic\Jetpack\Third_Party;
use Automattic\Jetpack\Constants;
use Automattic\Jetpack\Status\Host;
/**
* Handles suppressing development version notices on Atomic-hosted sites.
*
* @param bool $development_version Filterable value if this is a development version of Jetpack.
*
* @return bool
*/
function atomic_weekly_override( $development_version ) {
if ( ( new Host() )->is_atomic_platform() ) {
$haystack = Constants::get_constant( 'JETPACK__PLUGIN_DIR' );
$needle = '/jetpack-dev/';
if ( str_ends_with( $haystack, $needle ) ) {
return $development_version; // Returns the default response if the active Jetpack version is from the beta plugin.
}
$development_version = false; // Returns false for regular installs on Atomic.
}
return $development_version; // Return default if not on Atomic.
}
add_filter( 'jetpack_development_version', __NAMESPACE__ . '\atomic_weekly_override' );
+70
View File
@@ -0,0 +1,70 @@
<?php
/**
* Compatibility functions for bbpress.
*
* Only added if bbpress is active via function_exists( 'bbpress' ) in 3rd-party.php.
*
* @package automattic/jetpack
*/
use Automattic\Jetpack\Image_CDN\Image_CDN;
// Priority 11 needed to ensure sharing_display is loaded.
add_action( 'init', 'jetpack_bbpress_compat', 11 );
/**
* Adds Jetpack + bbPress Compatibility filters.
*
* @author Brandon Kraft
* @since 3.7.1
*/
function jetpack_bbpress_compat() {
/**
* Add compatibility layer for REST API.
*
* @since 8.5.0 Moved from root-level file and check_rest_api_compat()
*/
require_once __DIR__ . '/class-jetpack-bbpress-rest-api.php';
Jetpack_BbPress_REST_API::instance();
// Adds sharing buttons to bbPress items.
if ( function_exists( 'sharing_display' ) ) {
add_filter( 'bbp_get_topic_content', 'sharing_display', 19 );
add_action( 'bbp_template_after_single_forum', 'jetpack_sharing_bbpress' );
add_action( 'bbp_template_after_single_topic', 'jetpack_sharing_bbpress' );
}
/**
* Enable Markdown support for bbpress post types.
*
* @author Brandon Kraft
* @since 6.0.0
*/
if ( function_exists( 'bbp_get_topic_post_type' ) ) {
add_post_type_support( bbp_get_topic_post_type(), 'wpcom-markdown' );
add_post_type_support( bbp_get_reply_post_type(), 'wpcom-markdown' );
add_post_type_support( bbp_get_forum_post_type(), 'wpcom-markdown' );
}
/**
* Use Photon for all images in Topics and replies.
*
* @since 4.9.0
*/
if ( class_exists( Image_CDN::class ) && Image_CDN::is_enabled() ) {
add_filter( 'bbp_get_topic_content', array( Image_CDN::class, 'filter_the_content' ), 999999 );
add_filter( 'bbp_get_reply_content', array( Image_CDN::class, 'filter_the_content' ), 999999 );
}
}
/**
* Display Jetpack "Sharing" buttons on bbPress 2.x forums/ topics/ lead topics/ replies.
*
* Determination if the sharing buttons should display on the post type is handled within sharing_display().
*
* @author David Decker
* @since 3.7.0
*/
function jetpack_sharing_bbpress() {
sharing_display( null, true );
}
+21
View File
@@ -0,0 +1,21 @@
<?php
/**
* Beaverbuilder Compatibility.
*
* @package automattic/jetpack
*/
namespace Automattic\Jetpack\Third_Party;
use Automattic\Jetpack\Status\Host;
add_action( 'init', __NAMESPACE__ . '\beaverbuilder_refresh' );
/**
* If masterbar module is active force BeaverBuilder to refresh when publishing a layout.
*/
function beaverbuilder_refresh() {
if ( ( new Host() )->is_woa_site() ) {
add_filter( 'fl_builder_should_refresh_on_publish', '__return_true' );
}
}
+35
View File
@@ -0,0 +1,35 @@
<?php
/**
* Fixes issues with the Official Bitly for WordPress
* https://wordpress.org/plugins/bitly/
*
* @package automattic/jetpack
*/
if ( isset( $GLOBALS['bitly'] ) ) {
if ( method_exists( $GLOBALS['bitly'], 'og_tags' ) ) {
remove_action( 'wp_head', array( $GLOBALS['bitly'], 'og_tags' ) );
}
add_action( 'wp_head', 'jetpack_bitly_og_tag', 100 );
}
/**
* Adds bitly OG tags.
*/
function jetpack_bitly_og_tag() {
if ( has_filter( 'wp_head', 'jetpack_og_tags' ) === false ) {
// Add the bitly part again back if we don't have any jetpack_og_tags added.
if ( method_exists( $GLOBALS['bitly'], 'og_tags' ) ) {
$GLOBALS['bitly']->og_tags();
}
} elseif (
isset( $GLOBALS['posts'] )
&& $GLOBALS['posts'][0]->ID > 0
&& method_exists( $GLOBALS['bitly'], 'get_bitly_link_for_post_id' )
) {
printf(
"<meta property=\"bitly:url\" content=\"%s\" /> \n",
esc_attr( $GLOBALS['bitly']->get_bitly_link_for_post_id( $GLOBALS['posts'][0]->ID ) )
);
}
}
+23
View File
@@ -0,0 +1,23 @@
<?php
/**
* 3rd Party Integration for BuddyPress.
*
* @package automattic/jetpack.
*/
namespace Automattic\Jetpack\Third_Party;
add_filter( 'bp_core_pre_avatar_handle_upload', __NAMESPACE__ . '\blobphoto' );
/**
* Adds filters for skipping photon during pre_avatar_handle_upload.
*
* @param bool $bool Passthrough of filter's original content. No changes made.
*
* @return bool
*/
function blobphoto( $bool ) {
add_filter( 'jetpack_photon_skip_image', '__return_true' );
return $bool;
}
@@ -0,0 +1,160 @@
<?php
/**
* Domain Mapping 3rd Party
*
* @package automattic/jetpack
*/
namespace Automattic\Jetpack\Third_Party;
use Automattic\Jetpack\Constants;
/**
* Class Automattic\Jetpack\Third_Party\Domain_Mapping.
*
* This class contains methods that are used to provide compatibility between Jetpack sync and domain mapping plugins.
*/
class Domain_Mapping {
/**
* Singleton holder.
*
* @var Domain_Mapping
**/
private static $instance = null;
/**
* An array of methods that are used to hook the Jetpack sync filters for home_url and site_url to a mapping plugin.
*
* @var array
*/
public static $test_methods = array(
'hook_wordpress_mu_domain_mapping',
'hook_wpmu_dev_domain_mapping',
);
/**
* Singleton constructor.
*
* @return Domain_Mapping|null
*/
public static function init() {
if ( self::$instance === null ) {
self::$instance = new Domain_Mapping();
}
return self::$instance;
}
/**
* Class Automattic\Jetpack\Third_Party\Domain_Mapping constructor.
*/
private function __construct() {
add_action( 'plugins_loaded', array( $this, 'attempt_to_hook_domain_mapping_plugins' ) );
}
/**
* This function is called on the plugins_loaded action and will loop through the $test_methods
* to try and hook a domain mapping plugin to the Jetpack sync filters for the home_url and site_url callables.
*/
public function attempt_to_hook_domain_mapping_plugins() {
if ( ! Constants::is_defined( 'SUNRISE' ) ) {
return;
}
$hooked = false;
$count = count( self::$test_methods );
for ( $i = 0; $i < $count && ! $hooked; $i++ ) {
$hooked = call_user_func( array( $this, self::$test_methods[ $i ] ) );
}
}
/**
* This method will test for a constant and function that are known to be used with Donncha's WordPress MU
* Domain Mapping plugin. If conditions are met, we hook the domain_mapping_siteurl() function to Jetpack sync
* filters for home_url and site_url callables.
*
* @return bool
*/
public function hook_wordpress_mu_domain_mapping() {
if ( ! Constants::is_defined( 'SUNRISE_LOADED' ) || ! $this->function_exists( 'domain_mapping_siteurl' ) ) {
return false;
}
add_filter( 'jetpack_sync_home_url', 'domain_mapping_siteurl' );
add_filter( 'jetpack_sync_site_url', 'domain_mapping_siteurl' );
return true;
}
/**
* This method will test for a class and method known to be used in WPMU Dev's domain mapping plugin. If the
* method exists, then we'll hook the swap_to_mapped_url() to our Jetpack sync filters for home_url and site_url.
*
* @return bool
*/
public function hook_wpmu_dev_domain_mapping() {
if ( ! $this->class_exists( 'domain_map' ) || ! $this->method_exists( 'domain_map', 'utils' ) ) {
return false;
}
$utils = $this->get_domain_mapping_utils_instance();
add_filter( 'jetpack_sync_home_url', array( $utils, 'swap_to_mapped_url' ) );
add_filter( 'jetpack_sync_site_url', array( $utils, 'swap_to_mapped_url' ) );
return true;
}
/*
* Utility Methods
*
* These methods are very minimal, and in most cases, simply pass on arguments. Why create them you ask?
* So that we can test.
*/
/**
* Checks if a method exists.
*
* @param string $class Class name.
* @param string $method Method name.
*
* @return bool Returns function_exists() without modification.
*/
public function method_exists( $class, $method ) {
return method_exists( $class, $method );
}
/**
* Checks if a class exists.
*
* @param string $class Class name.
*
* @return bool Returns class_exists() without modification.
*/
public function class_exists( $class ) {
return class_exists( $class );
}
/**
* Checks if a function exists.
*
* @param string $function Function name.
*
* @return bool Returns function_exists() without modification.
*/
public function function_exists( $function ) {
return function_exists( $function );
}
/**
* Returns the Domain_Map::utils() instance.
*
* @see https://github.com/wpmudev/domain-mapping/blob/master/classes/Domainmap/Utils.php
* @return \Domainmap_Utils
*/
public function get_domain_mapping_utils_instance() {
return \domain_map::utils();
}
}
Domain_Mapping::init();
@@ -0,0 +1,161 @@
<?php
/**
* REST API Compatibility: bbPress & Jetpack
* Enables bbPress to work with the Jetpack REST API
*
* @package automattic/jetpack
*/
/**
* REST API Compatibility: bbPress.
*/
class Jetpack_BbPress_REST_API {
/**
* Singleton
*
* @var Jetpack_BbPress_REST_API
*/
private static $instance;
/**
* Returns or creates the singleton.
*
* @return Jetpack_BbPress_REST_API
*/
public static function instance() {
if ( isset( self::$instance ) ) {
return self::$instance;
}
self::$instance = new self();
}
/**
* Jetpack_BbPress_REST_API constructor.
*/
private function __construct() {
add_filter( 'rest_api_allowed_post_types', array( $this, 'allow_bbpress_post_types' ) );
add_filter( 'bbp_map_meta_caps', array( $this, 'adjust_meta_caps' ), 10, 4 );
add_filter( 'rest_api_allowed_public_metadata', array( $this, 'allow_bbpress_public_metadata' ) );
}
/**
* Adds the bbPress post types to the rest_api_allowed_post_types filter.
*
* @param array $allowed_post_types Allowed post types.
*
* @return array
*/
public function allow_bbpress_post_types( $allowed_post_types ) {
$allowed_post_types[] = 'forum';
$allowed_post_types[] = 'topic';
$allowed_post_types[] = 'reply';
return $allowed_post_types;
}
/**
* Adds the bbpress meta keys to the rest_api_allowed_public_metadata filter.
*
* @param array $allowed_meta_keys Allowed meta keys.
*
* @return array
*/
public function allow_bbpress_public_metadata( $allowed_meta_keys ) {
$allowed_meta_keys[] = '_bbp_forum_id';
$allowed_meta_keys[] = '_bbp_topic_id';
$allowed_meta_keys[] = '_bbp_status';
$allowed_meta_keys[] = '_bbp_forum_type';
$allowed_meta_keys[] = '_bbp_forum_subforum_count';
$allowed_meta_keys[] = '_bbp_reply_count';
$allowed_meta_keys[] = '_bbp_total_reply_count';
$allowed_meta_keys[] = '_bbp_topic_count';
$allowed_meta_keys[] = '_bbp_total_topic_count';
$allowed_meta_keys[] = '_bbp_topic_count_hidden';
$allowed_meta_keys[] = '_bbp_last_topic_id';
$allowed_meta_keys[] = '_bbp_last_reply_id';
$allowed_meta_keys[] = '_bbp_last_active_time';
$allowed_meta_keys[] = '_bbp_last_active_id';
$allowed_meta_keys[] = '_bbp_sticky_topics';
$allowed_meta_keys[] = '_bbp_voice_count';
$allowed_meta_keys[] = '_bbp_reply_count_hidden';
$allowed_meta_keys[] = '_bbp_anonymous_reply_count';
return $allowed_meta_keys;
}
/**
* Adds the needed caps to the bbp_map_meta_caps filter.
*
* @param array $caps Capabilities for meta capability.
* @param string $cap Capability name.
* @param int $user_id User id.
* @param array $args Arguments.
*
* @return array
*/
public function adjust_meta_caps( $caps, $cap, $user_id, $args ) {
// Return early if not a REST request or if not meta bbPress caps.
if ( $this->should_adjust_meta_caps_return_early( $caps, $cap, $user_id, $args ) ) {
return $caps;
}
// $args[0] could be a post ID or a post_type string.
if ( is_int( $args[0] ) ) {
$_post = get_post( $args[0] );
if ( ! empty( $_post ) ) {
$post_type = get_post_type_object( $_post->post_type );
}
} elseif ( is_string( $args[0] ) ) {
$post_type = get_post_type_object( $args[0] );
}
// no post type found, bail.
if ( empty( $post_type ) ) {
return $caps;
}
// reset the needed caps.
$caps = array();
// Add 'do_not_allow' cap if user is spam or deleted.
if ( bbp_is_user_inactive( $user_id ) ) {
$caps[] = 'do_not_allow';
// Moderators can always edit meta.
} elseif ( user_can( $user_id, 'moderate' ) ) { // phpcs:ignore WordPress.WP.Capabilities.Unknown
$caps[] = 'moderate';
// Unknown so map to edit_posts.
} else {
$caps[] = $post_type->cap->edit_posts;
}
return $caps;
}
/**
* Should adjust_meta_caps return early?
*
* @param array $caps Capabilities for meta capability.
* @param string $cap Capability name.
* @param int $user_id User id.
* @param array $args Arguments.
*
* @return bool
*/
private function should_adjust_meta_caps_return_early( $caps, $cap, $user_id, $args ) {
// only run for REST API requests.
if ( ! defined( 'REST_API_REQUEST' ) || ! REST_API_REQUEST ) {
return true;
}
// only modify caps for meta caps and for bbPress meta keys.
if ( ! in_array( $cap, array( 'edit_post_meta', 'delete_post_meta', 'add_post_meta' ), true ) || empty( $args[1] ) || ! str_contains( $args[1], '_bbp_' ) ) {
return true;
}
return false;
}
}
@@ -0,0 +1,539 @@
<?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
use Automattic\Jetpack\Assets;
use Automattic\Jetpack\Stats\Tracking_Pixel as Stats_Tracking_Pixel;
use Automattic\Jetpack\Sync\Functions;
/**
* Manages compatibility with the amp-wp plugin
*
* @see https://github.com/Automattic/amp-wp
*/
class Jetpack_AMP_Support {
/**
* Apply custom AMP changes on the front-end.
*/
public static function init() {
// Add Stats tracking pixel on Jetpack sites when the Stats module is active.
if (
Jetpack::is_module_active( 'stats' )
&& ! ( defined( 'IS_WPCOM' ) && IS_WPCOM )
) {
add_action( 'amp_post_template_footer', array( 'Jetpack_AMP_Support', 'add_stats_pixel' ) );
}
// Sharing.
add_filter( 'jetpack_sharing_display_markup', array( 'Jetpack_AMP_Support', 'render_sharing_html' ), 10, 2 );
add_filter( 'sharing_enqueue_scripts', array( 'Jetpack_AMP_Support', 'amp_disable_sharedaddy_css' ) );
add_action( 'wp_enqueue_scripts', array( 'Jetpack_AMP_Support', 'amp_enqueue_sharing_css' ) );
// Sharing for Reader mode.
if ( function_exists( 'jetpack_social_menu_include_svg_icons' ) ) {
add_action( 'amp_post_template_footer', 'jetpack_social_menu_include_svg_icons' );
}
add_action( 'amp_post_template_css', array( 'Jetpack_AMP_Support', 'amp_reader_sharing_css' ), 10, 0 );
// enforce freedom mode for videopress.
add_filter( 'videopress_shortcode_options', array( 'Jetpack_AMP_Support', 'videopress_enable_freedom_mode' ) );
// include Jetpack og tags when rendering native AMP head.
add_action( 'amp_post_template_head', array( 'Jetpack_AMP_Support', 'amp_post_jetpack_og_tags' ) );
// Post rendering changes for legacy AMP.
add_action( 'pre_amp_render_post', array( 'Jetpack_AMP_Support', 'amp_disable_the_content_filters' ) );
// Disable Comment Likes.
add_filter( 'jetpack_comment_likes_enabled', array( 'Jetpack_AMP_Support', 'comment_likes_enabled' ) );
// Transitional mode AMP should not have comment likes.
add_filter( 'the_content', array( 'Jetpack_AMP_Support', 'disable_comment_likes_before_the_content' ) );
// Add post template metadata for legacy AMP.
add_filter( 'amp_post_template_metadata', array( 'Jetpack_AMP_Support', 'amp_post_template_metadata' ), 10, 2 );
// Filter photon image args for AMP Stories.
add_filter( 'jetpack_photon_post_image_args', array( 'Jetpack_AMP_Support', 'filter_photon_post_image_args_for_stories' ), 10, 2 );
// Sync the amp-options.
add_filter( 'jetpack_options_whitelist', array( 'Jetpack_AMP_Support', 'filter_jetpack_options_safelist' ) );
}
/**
* Disable the Comment Likes feature on AMP views.
*
* @param bool $enabled Should comment likes be enabled.
*/
public static function comment_likes_enabled( $enabled ) {
return $enabled && ! self::is_amp_request();
}
/**
* Apply custom AMP changes in wp-admin.
*/
public static function admin_init() {
// disable Likes metabox for post editor if AMP canonical disabled.
add_filter( 'post_flair_disable', array( 'Jetpack_AMP_Support', 'is_amp_canonical' ), 99 );
}
/**
* Is the page in AMP 'canonical mode'.
* Used when themes register support for AMP with `add_theme_support( 'amp' )`.
*
* @return bool is_amp_canonical
*/
public static function is_amp_canonical() {
return function_exists( 'amp_is_canonical' ) && amp_is_canonical();
}
/**
* Is AMP available for this request
* This returns false for admin, CLI requests etc.
*
* @return bool is_amp_available
*/
public static function is_amp_available() {
return ( function_exists( 'amp_is_available' ) && amp_is_available() );
}
/**
* Does the page return AMP content.
*
* @return bool $is_amp_request Are we on am AMP view.
*/
public static function is_amp_request() {
$is_amp_request = ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() );
/**
* Returns true if the current request should return valid AMP content.
*
* @since 6.2.0
*
* @param boolean $is_amp_request Is this request supposed to return valid AMP content?
*/
return apply_filters( 'jetpack_is_amp_request', $is_amp_request );
}
/**
* Determines whether the legacy AMP post templates are being used.
*
* @since 10.6.0
*
* @return bool
*/
public static function is_amp_legacy() {
return ( function_exists( 'amp_is_legacy' ) && amp_is_legacy() );
}
/**
* Remove content filters added by Jetpack.
*/
public static function amp_disable_the_content_filters() {
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
add_filter( 'protected_embeds_use_form_post', '__return_false' );
remove_filter( 'the_title', 'widont' );
}
remove_filter( 'pre_kses', array( 'Filter_Embedded_HTML_Objects', 'filter' ), 11 );
remove_filter( 'pre_kses', array( 'Filter_Embedded_HTML_Objects', 'maybe_create_links' ), 100 );
}
/**
* Do not add comment likes on AMP requests.
*
* @param string $content Post content.
*/
public static function disable_comment_likes_before_the_content( $content ) {
if ( self::is_amp_request() ) {
remove_filter( 'comment_text', 'comment_like_button', 12 );
}
return $content;
}
/**
* Add Jetpack stats pixel.
*
* @since 6.2.1
*/
public static function add_stats_pixel() {
if ( ! has_action( 'wp_footer', array( Stats_Tracking_Pixel::class, 'add_amp_pixel' ) ) ) {
return;
}
$stats_data = Stats_Tracking_Pixel::build_view_data();
Stats_Tracking_Pixel::render_amp_footer( $stats_data );
}
/**
* Add publisher and image metadata to legacy AMP post.
*
* @since 6.2.0
*
* @param array $metadata Metadata array.
* @param WP_Post $post Post.
* @return array Modified metadata array.
*/
public static function amp_post_template_metadata( $metadata, $post ) {
if ( isset( $metadata['publisher'] ) && ! isset( $metadata['publisher']['logo'] ) ) {
$metadata = self::add_site_icon_to_metadata( $metadata );
}
if ( ! isset( $metadata['image'] ) && ! empty( $post ) ) {
$metadata = self::add_image_to_metadata( $metadata, $post );
}
return $metadata;
}
/**
* Add blavatar to legacy AMP post metadata.
*
* @since 6.2.0
*
* @param array $metadata Metadata.
*
* @return array Metadata.
*/
private static function add_site_icon_to_metadata( $metadata ) {
$size = 60;
$site_icon_url = class_exists( 'Automattic\\Jetpack\\Sync\\Functions' ) ? Functions::site_icon_url( $size ) : '';
if ( function_exists( 'blavatar_domain' ) ) {
$metadata['publisher']['logo'] = array(
'@type' => 'ImageObject',
'url' => blavatar_url( blavatar_domain( site_url() ), 'img', $size, self::staticize_subdomain( 'https://wordpress.com/i/favicons/apple-touch-icon-60x60.png' ) ),
'width' => $size,
'height' => $size,
);
} elseif ( $site_icon_url ) {
$metadata['publisher']['logo'] = array(
'@type' => 'ImageObject',
'url' => $site_icon_url,
'width' => $size,
'height' => $size,
);
}
return $metadata;
}
/**
* Add image to legacy AMP post metadata.
*
* @since 6.2.0
*
* @param array $metadata Metadata.
* @param WP_Post $post Post.
* @return array Metadata.
*/
private static function add_image_to_metadata( $metadata, $post ) {
$image = Jetpack_PostImages::get_image(
$post->ID,
array(
'fallback_to_avatars' => true,
'avatar_size' => 200,
// AMP already attempts these.
'from_thumbnail' => false,
'from_attachment' => false,
)
);
if ( empty( $image ) ) {
return self::add_fallback_image_to_metadata( $metadata );
}
if ( ! isset( $image['src_width'] ) ) {
$dimensions = self::extract_image_dimensions_from_getimagesize(
array(
$image['src'] => false,
)
);
if ( false !== $dimensions[ $image['src'] ] ) {
$image['src_width'] = $dimensions['width'];
$image['src_height'] = $dimensions['height'];
}
}
$metadata['image'] = array(
'@type' => 'ImageObject',
'url' => $image['src'],
);
if ( isset( $image['src_width'] ) ) {
$metadata['image']['width'] = $image['src_width'];
}
if ( isset( $image['src_width'] ) ) {
$metadata['image']['height'] = $image['src_height'];
}
return $metadata;
}
/**
* Add fallback image to legacy AMP post metadata.
*
* @since 6.2.0
*
* @param array $metadata Metadata.
* @return array Metadata.
*/
private static function add_fallback_image_to_metadata( $metadata ) {
/** This filter is documented in functions.opengraph.php */
$default_image = apply_filters( 'jetpack_open_graph_image_default', 'https://wordpress.com/i/blank.jpg' );
$metadata['image'] = array(
'@type' => 'ImageObject',
'url' => self::staticize_subdomain( $default_image ),
'width' => 200,
'height' => 200,
);
return $metadata;
}
/**
* Return static WordPress.com domain to use to load resources from WordPress.com.
*
* @param string $domain Asset URL.
*/
private static function staticize_subdomain( $domain ) {
// deal with WPCOM vs Jetpack.
if ( function_exists( 'staticize_subdomain' ) ) {
return staticize_subdomain( $domain );
} else {
return Assets::staticize_subdomain( $domain );
}
}
/**
* Extract image dimensions via wpcom/imagesize, only on WPCOM
*
* @since 6.2.0
*
* @param array $dimensions Dimensions.
* @return array Dimensions.
*/
private static function extract_image_dimensions_from_getimagesize( $dimensions ) {
if ( ! ( defined( 'IS_WPCOM' ) && IS_WPCOM && function_exists( 'require_lib' ) ) ) {
return $dimensions;
}
require_lib( 'wpcom/imagesize' );
foreach ( $dimensions as $url => $value ) {
if ( is_array( $value ) ) {
continue;
}
$result = wpcom_getimagesize( $url );
if ( is_array( $result ) ) {
$dimensions[ $url ] = array(
'width' => $result[0],
'height' => $result[1],
);
}
}
return $dimensions;
}
/**
* Display Open Graph Meta tags in AMP views.
*/
public static function amp_post_jetpack_og_tags() {
if ( ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ) {
Jetpack::init()->check_open_graph();
}
if ( function_exists( 'jetpack_og_tags' ) ) {
jetpack_og_tags();
}
}
/**
* Force Freedom mode in VideoPress.
*
* @param array $options Array of VideoPress shortcode options.
*/
public static function videopress_enable_freedom_mode( $options ) {
if ( self::is_amp_request() ) {
$options['freedom'] = true;
}
return $options;
}
/**
* Display custom markup for the sharing buttons when in an AMP view.
*
* @param string $markup Content markup of the Jetpack sharing links.
* @param array $sharing_enabled Array of Sharing Services currently enabled.
*/
public static function render_sharing_html( $markup, $sharing_enabled ) {
global $post;
if ( empty( $post ) ) {
return '';
}
if ( ! self::is_amp_request() ) {
return $markup;
}
remove_action( 'wp_footer', 'sharing_add_footer' );
if ( empty( $sharing_enabled ) ) {
return $markup;
}
$sharing_links = array();
foreach ( $sharing_enabled['visible'] as $service ) {
$sharing_link = $service->get_amp_display( $post );
if ( ! empty( $sharing_link ) ) {
$sharing_links[] = $sharing_link;
}
}
// Replace the existing unordered list with AMP sharing buttons.
$markup = preg_replace( '#<ul>(.+)</ul>#', implode( '', $sharing_links ), $markup );
// Remove any lingering share-end list items.
$markup = str_replace( '<li class="share-end"></li>', '', $markup );
return $markup;
}
/**
* Tells Jetpack not to enqueue CSS for share buttons.
*
* @param bool $enqueue Whether or not to enqueue.
* @return bool Whether or not to enqueue.
*/
public static function amp_disable_sharedaddy_css( $enqueue ) {
if ( self::is_amp_request() ) {
$enqueue = false;
}
return $enqueue;
}
/**
* Enqueues the AMP specific sharing styles for the sharing icons.
*/
public static function amp_enqueue_sharing_css() {
if (
Jetpack::is_module_active( 'sharedaddy' )
&& self::is_amp_request()
&& ! self::is_amp_legacy()
) {
wp_enqueue_style( 'sharedaddy-amp', plugin_dir_url( __DIR__ ) . 'modules/sharedaddy/amp-sharing.css', array( 'social-logos' ), JETPACK__VERSION );
}
}
/**
* For the AMP Reader mode template, include styles that we need.
*/
public static function amp_reader_sharing_css() {
// If sharing is not enabled, we should not proceed to render the CSS.
if ( ! defined( 'JETPACK_SOCIAL_LOGOS_DIR' ) || ! defined( 'JETPACK_SOCIAL_LOGOS_URL' ) || ! defined( 'WP_SHARING_PLUGIN_DIR' ) ) {
return;
}
/*
* We'll need to output the full contents of the 2 files
* in the head on AMP views. We can't rely on regular enqueues here.
* @todo As of AMP plugin v1.5, you can actually rely on regular enqueues thanks to https://github.com/ampproject/amp-wp/pull/4299. Once WPCOM upgrades AMP, then this method can be eliminated.
*
* phpcs:disable WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
* phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
*/
$css = file_get_contents( JETPACK_SOCIAL_LOGOS_DIR . 'social-logos.css' );
$css = preg_replace( '#(?<=url\(")(?=social-logos\.)#', JETPACK_SOCIAL_LOGOS_URL, $css ); // Make sure font files get their absolute paths.
echo $css;
echo file_get_contents( WP_SHARING_PLUGIN_DIR . 'amp-sharing.css' );
/*
* phpcs:enable WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
* phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
*/
}
/**
* Ensure proper Photon image dimensions for AMP Stories.
*
* @param array $args Array of Photon Arguments.
* @param array $details {
* Array of image details.
*
* @type string $tag Image tag (Image HTML output).
* @type string $src Image URL.
* @type string $src_orig Original Image URL.
* @type int|false $width Image width.
* @type int|false $height Image height.
* @type int|false $width_orig Original image width before constrained by content_width.
* @type int|false $height_orig Original Image height before constrained by content_width.
* @type string $transform_orig Original transform before constrained by content_width.
* }
* @return array Args.
*/
public static function filter_photon_post_image_args_for_stories( $args, $details ) {
if ( ! is_singular( 'amp_story' ) ) {
return $args;
}
// Percentage-based dimensions are not allowed in AMP, so this shouldn't happen, but short-circuit just in case.
if ( str_contains( $details['width_orig'], '%' ) || str_contains( $details['height_orig'], '%' ) ) {
return $args;
}
$max_height = 1280; // See image size with the slug \AMP_Story_Post_Type::MAX_IMAGE_SIZE_SLUG.
$transform = $details['transform_orig'];
$width = $details['width_orig'];
$height = $details['height_orig'];
// If height is available, constrain to $max_height.
if ( false !== $height ) {
if ( $height > $max_height && false !== $height ) {
$width = ( $max_height * $width ) / $height;
$height = $max_height;
} elseif ( $height > $max_height ) {
$height = $max_height;
}
}
/*
* Set a height if none is found.
* If height is set in this manner and height is available, use `fit` instead of `resize` to prevent skewing.
*/
if ( false === $height ) {
$height = $max_height;
if ( false !== $width ) {
$transform = 'fit';
}
}
// Build array of Photon args and expose to filter before passing to Photon URL function.
$args = array();
if ( false !== $width && false !== $height ) {
$args[ $transform ] = $width . ',' . $height;
} elseif ( false !== $width ) {
$args['w'] = $width;
} elseif ( false !== $height ) {
$args['h'] = $height;
}
return $args;
}
/**
* Adds amp-options to the list of options to sync, if AMP is available
*
* @param array $options_safelist Safelist of options to sync.
*
* @return array Updated options safelist
*/
public static function filter_jetpack_options_safelist( $options_safelist ) {
if ( function_exists( 'is_amp_endpoint' ) ) {
$options_safelist[] = 'amp-options';
}
return $options_safelist;
}
}
+132
View File
@@ -0,0 +1,132 @@
<?php
/**
* Compatibility functions for the Creative Mail plugin.
* https://wordpress.org/plugins/creative-mail-by-constant-contact/
*
* @since 8.9.0
*
* @package automattic/jetpack
*/
namespace Automattic\Jetpack\Creative_Mail;
use Automattic\Jetpack\Plugins_Installer;
if ( ! defined( 'ABSPATH' ) ) {
exit( 0 );
}
const PLUGIN_SLUG = 'creative-mail-by-constant-contact';
const PLUGIN_FILE = 'creative-mail-by-constant-contact/creative-mail-plugin.php';
add_action( 'jetpack_activated_plugin', __NAMESPACE__ . '\configure_plugin', 10, 2 );
// Check for the JITM action.
if ( isset( $_GET['creative-mail-action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
add_action( 'admin_init', __NAMESPACE__ . '\try_install' );
}
if ( ! empty( $_GET['creative-mail-install-error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
add_action( 'admin_notices', __NAMESPACE__ . '\error_notice' );
}
/**
* Verify the intent to install Creative Mail, and kick off installation.
*
* This works in tandem with a JITM set up in the JITM package.
*
* @return never
*/
function try_install() {
check_admin_referer( 'creative-mail-install' );
$result = false;
$redirect = admin_url( 'edit.php?post_type=feedback' );
// Attempt to install and activate the plugin.
if ( current_user_can( 'activate_plugins' ) ) {
switch ( $_GET['creative-mail-action'] ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated -- Function only hooked if set.
case 'install':
$result = install_and_activate();
break;
case 'activate':
$result = activate();
break;
}
}
if ( $result ) {
/** This action is already documented in _inc/lib/class.core-rest-api-endpoints.php */
do_action( 'jetpack_activated_plugin', PLUGIN_FILE, 'jitm' );
$redirect = admin_url( 'admin.php?page=creativemail' );
} else {
$redirect = add_query_arg( 'creative-mail-install-error', true, $redirect );
}
wp_safe_redirect( $redirect );
exit( 0 );
}
/**
* Install and activate the Creative Mail plugin.
*
* @return bool result of installation
*/
function install_and_activate() {
$result = Plugins_Installer::install_and_activate_plugin( PLUGIN_SLUG );
if ( is_wp_error( $result ) ) {
return false;
} else {
return true;
}
}
/**
* Activate the Creative Mail plugin.
*
* @return bool result of activation
*/
function activate() {
$result = activate_plugin( PLUGIN_FILE );
// Activate_plugin() returns null on success.
return $result === null;
}
/**
* Notify the user that the installation of Creative Mail failed.
*/
function error_notice() {
wp_admin_notice(
esc_html__( 'There was an error installing Creative Mail.', 'jetpack' ),
array(
'type' => 'error',
'dismissible' => true,
)
);
}
/**
* Set some options when first activating the plugin via Jetpack.
*
* @since 8.9.0
*
* @param string $plugin_file Plugin file.
* @param string $source Where did the plugin installation originate.
*/
function configure_plugin( $plugin_file, $source ) {
if ( PLUGIN_FILE !== $plugin_file ) {
return;
}
$plugin_info = array(
'plugin' => 'jetpack',
'version' => JETPACK__VERSION,
'time' => time(),
'source' => esc_attr( $source ),
);
update_option( 'ce4wp_referred_by', $plugin_info );
}
+24
View File
@@ -0,0 +1,24 @@
<?php
/**
* 3rd Party integration for Debug Bar.
*
* @package automattic/jetpack
*/
/**
* Checks if the search module is active, and if so, will initialize the singleton instance
* of Jetpack_Search_Debug_Bar and add it to the array of debug bar panels.
*
* @param array $panels The array of debug bar panels.
* @return array $panel The array of debug bar panels with our added panel.
*/
function init_jetpack_search_debug_bar( $panels ) {
if ( ! Jetpack::is_module_active( 'search' ) ) {
return $panels;
}
require_once __DIR__ . '/debug-bar/class-jetpack-search-debug-bar.php';
$panels[] = Jetpack_Search_Debug_Bar::instance();
return $panels;
}
add_filter( 'debug_bar_panels', 'init_jetpack_search_debug_bar' );
@@ -0,0 +1,192 @@
<?php
/**
* Adds a Jetpack Search debug panel to Debug Bar.
*
* @package automattic/jetpack
*/
use Automattic\Jetpack\Search as Jetpack_Search;
/**
* Singleton class instantiated by Jetpack_Searc_Debug_Bar::instance() that handles
* rendering the Jetpack Search debug bar menu item and panel.
*/
class Jetpack_Search_Debug_Bar extends Debug_Bar_Panel {
/**
* Holds singleton instance
*
* @var Jetpack_Search_Debug_Bar
*/
protected static $instance = null;
/**
* The title to use in the debug bar navigation
*
* @var string
*/
public $title;
/**
* Constructor
*/
public function __construct() {
$this->title( esc_html__( 'Jetpack Search', 'jetpack' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'login_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'enqueue_embed_scripts', array( $this, 'enqueue_scripts' ) );
}
/**
* Returns the singleton instance of Jetpack_Search_Debug_Bar
*
* @return Jetpack_Search_Debug_Bar
*/
public static function instance() {
if ( self::$instance === null ) {
self::$instance = new Jetpack_Search_Debug_Bar();
}
return self::$instance;
}
/**
* Enqueues styles for our panel in the debug bar
*
* @return void
*/
public function enqueue_scripts() {
// Do not enqueue scripts if we haven't already enqueued Debug Bar or Query Monitor styles.
if ( ! wp_style_is( 'debug-bar' ) && ! wp_style_is( 'query-monitor' ) ) {
return;
}
wp_enqueue_style(
'jetpack-search-debug-bar',
plugins_url( '3rd-party/debug-bar/debug-bar.css', JETPACK__PLUGIN_FILE ),
array(),
JETPACK__VERSION
);
wp_enqueue_script(
'jetpack-search-debug-bar',
plugins_url( '3rd-party/debug-bar/debug-bar.js', JETPACK__PLUGIN_FILE ),
array( 'jquery' ),
JETPACK__VERSION,
true
);
}
/**
* Should the Jetpack Search Debug Bar show?
*
* Since we've previously done a check for the search module being activated, let's just return true.
* Later on, we can update this to only show when `is_search()` is true.
*
* @return boolean
*/
public function is_visible() {
return true;
}
/**
* Renders the panel content
*
* @return void
*/
public function render() {
$jetpack_search = (
Jetpack_Search\Options::is_instant_enabled() ?
Jetpack_Search\Instant_Search::instance() :
Jetpack_Search\Classic_Search::instance()
);
// Search hasn't been initialized. Exit early and do not display the debug bar.
if ( ! method_exists( $jetpack_search, 'get_last_query_info' ) ) {
return;
}
$last_query_info = $jetpack_search->get_last_query_info();
// If not empty, let's reshuffle the order of some things.
if ( ! empty( $last_query_info ) ) {
$args = $last_query_info['args'];
$response = $last_query_info['response'];
$response_code = $last_query_info['response_code'];
unset( $last_query_info['args'] );
unset( $last_query_info['response'] );
unset( $last_query_info['response_code'] );
if ( $last_query_info['es_time'] === null ) {
$last_query_info['es_time'] = esc_html_x(
'cache hit',
'displayed in search results when results are cached',
'jetpack'
);
}
$temp = array_merge(
array( 'response_code' => $response_code ),
array( 'args' => $args ),
$last_query_info,
array( 'response' => $response )
);
$last_query_info = $temp;
}
?>
<div class="jetpack-search-debug-bar">
<h2><?php esc_html_e( 'Last query information:', 'jetpack' ); ?></h2>
<?php if ( empty( $last_query_info ) ) : ?>
<?php echo esc_html_x( 'None', 'Text displayed when there is no information', 'jetpack' ); ?>
<?php
else :
foreach ( $last_query_info as $key => $info ) :
?>
<h3><?php echo esc_html( $key ); ?></h3>
<?php
if ( 'response' !== $key && 'args' !== $key ) :
?>
<pre><?php print_r( esc_html( $info ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions ?></pre>
<?php
else :
$this->render_json_toggle( $info );
endif;
?>
<?php
endforeach;
endif;
?>
</div><!-- Closes .jetpack-search-debug-bar -->
<?php
}
/**
* Responsible for rendering the HTML necessary for the JSON toggle
*
* @param array $value The resonse from the API as an array.
* @return void
*/
public function render_json_toggle( $value ) {
?>
<div class="json-toggle-wrap">
<pre class="json">
<?php
// esc_html() will not double-encode entities (&amp; -> &amp;amp;).
// If any entities are part of the JSON blob, we want to re-encoode them
// (double-encode them) so that they are displayed correctly in the debug
// bar.
// Use _wp_specialchars() "manually" to ensure entities are encoded correctly.
echo _wp_specialchars( // phpcs:ignore WordPress.Security.EscapeOutput
wp_json_encode( $value ),
ENT_NOQUOTES, // Don't need to encode quotes (output is for a text node).
'UTF-8', // wp_json_encode() outputs UTF-8 (really just ASCII), not the blog's charset.
true // Do "double-encode" existing HTML entities.
);
?>
</pre>
<span class="pretty toggle"><?php echo esc_html_x( 'Pretty', 'label for formatting JSON', 'jetpack' ); ?></span>
<span class="ugly toggle"><?php echo esc_html_x( 'Minify', 'label for formatting JSON', 'jetpack' ); ?></span>
</div>
<?php
}
}
@@ -0,0 +1,56 @@
.jetpack-search-debug-bar h2,
.qm-debug-bar-output .jetpack-search-debug-bar h2 {
float: none !important;
padding: 0 !important;
text-align: left !important;
}
.qm-debug-bar-output .jetpack-search-debug-bar h2 {
margin-top: 1em !important;
}
.qm-debug-bar-output .jetpack-search-debug-bar h2:first-child {
margin-top: .5em !important;
}
.debug-menu-target h3 {
padding-top: 0
}
.jetpack-search-debug-output-toggle .print-r {
display: none;
}
.json-toggle-wrap {
position: relative;
}
.json-toggle-wrap .toggle {
position: absolute;
bottom: 10px;
right: 10px;
background: #fff;
border: 1px solid #000;
cursor: pointer;
padding: 2px 4px;
}
.json-toggle-wrap .ugly {
display: none;
}
.json-toggle-wrap.pretty .pretty {
display: none;
}
.json-toggle-wrap.pretty .ugly {
display: inline;
}
.jetpack-search-debug-bar pre {
white-space: pre-wrap;
white-space: -moz-pre-wrap;
white-space: -pre-wrap;
white-space: -o-pre-wrap;
word-wrap: break-word;
}
@@ -0,0 +1,23 @@
/* global jQuery */
/* eslint no-var: "off" */
( function ( $ ) {
$( document ).ready( function () {
$( '.jetpack-search-debug-bar .json-toggle-wrap .toggle' ).click( function () {
var t = $( this ),
wrap = t.closest( '.json-toggle-wrap' ),
pre = wrap.find( 'pre' ),
content = pre.text(),
isPretty = wrap.hasClass( 'pretty' );
if ( ! isPretty ) {
pre.text( JSON.stringify( JSON.parse( content ), null, 2 ) );
} else {
content.replace( '\t', '' ).replace( '\n', '' ).replace( ' ', '' );
pre.text( JSON.stringify( JSON.parse( content ) ) );
}
wrap.toggleClass( 'pretty' );
} );
} );
} )( jQuery );
+107
View File
@@ -0,0 +1,107 @@
<?php
/**
* Compatibility functions for the Jetpack Backup plugin.
* https://wordpress.org/plugins/jetpack-backup/
*
* @since 10.4
*
* @package automattic/jetpack
*/
namespace Automattic\Jetpack\Jetpack_Backup;
use Automattic\Jetpack\Plugins_Installer;
if ( ! defined( 'ABSPATH' ) ) {
exit( 0 );
}
const PLUGIN_SLUG = 'jetpack-backup';
const PLUGIN_FILE = 'jetpack-backup/jetpack-backup.php';
if ( isset( $_GET['jetpack-backup-install-error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
add_action( 'admin_notices', __NAMESPACE__ . '\error_notice' );
}
if ( isset( $_GET['jetpack-backup-action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
add_action( 'admin_init', __NAMESPACE__ . '\try_install' );
}
/**
* Verify the intent to install Jetpack Backup, and kick off installation.
*
* This works in tandem with a JITM set up in the JITM package.
*
* @return never
*/
function try_install() {
check_admin_referer( 'jetpack-backup-install' );
$result = false;
// If the plugin install fails, redirect to plugin install page pre-populated with jetpack-backup search term.
$redirect_on_error = admin_url( 'plugin-install.php?s=jetpack-backup&tab=search&type=term' );
// Attempt to install and activate the plugin.
if ( current_user_can( 'activate_plugins' ) ) {
switch ( $_GET['jetpack-backup-action'] ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated -- Function only hooked if set.
case 'install':
$result = install_and_activate();
break;
case 'activate':
$result = activate();
break;
}
}
if ( $result ) {
/** This action is already documented in _inc/lib/class.core-rest-api-endpoints.php */
do_action( 'jetpack_activated_plugin', PLUGIN_FILE, 'jitm' );
$redirect = admin_url( 'admin.php?page=jetpack-backup' );
} else {
$redirect = add_query_arg( 'jetpack-backup-install-error', true, $redirect_on_error );
}
wp_safe_redirect( $redirect );
exit( 0 );
}
/**
* Install and activate the Jetpack Backup plugin.
*
* @return bool result of installation
*/
function install_and_activate() {
$result = Plugins_Installer::install_and_activate_plugin( PLUGIN_SLUG );
if ( is_wp_error( $result ) ) {
return false;
} else {
return true;
}
}
/**
* Activate the Jetpack Backup plugin.
*
* @return bool result of activation
*/
function activate() {
$result = activate_plugin( PLUGIN_FILE );
// Activate_plugin() returns null on success.
return $result === null;
}
/**
* Notify the user that the installation of Jetpack Backup failed.
*/
function error_notice() {
wp_admin_notice(
esc_html__( 'There was an error installing Jetpack Backup. Please try again.', 'jetpack' ),
array(
'type' => 'error',
'dismissible' => true,
)
);
}
+112
View File
@@ -0,0 +1,112 @@
<?php
/**
* Compatibility functions for the Jetpack Boost plugin.
* https://wordpress.org/plugins/jetpack-boost/
*
* @since 10.4
*
* @package automattic/jetpack
*/
namespace Automattic\Jetpack\Jetpack_Boost;
use Automattic\Jetpack\Plugins_Installer;
if ( ! defined( 'ABSPATH' ) ) {
exit( 0 );
}
const PLUGIN_SLUG = 'jetpack-boost';
const PLUGIN_FILE = 'jetpack-boost/jetpack-boost.php';
if ( isset( $_GET['jetpack-boost-install-error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
add_action( 'admin_notices', __NAMESPACE__ . '\error_notice' );
}
if ( isset( $_GET['jetpack-boost-action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
add_action( 'admin_init', __NAMESPACE__ . '\try_install' );
}
/**
* Verify the intent to install Jetpack Boost, and kick off installation.
*
* This works in tandem with a JITM set up in the JITM package.
*/
function try_install() {
if ( ! isset( $_GET['jetpack-boost-action'] ) ) {
return;
}
check_admin_referer( 'jetpack-boost-install' );
$result = false;
// If the plugin install fails, redirect to plugin install page pre-populated with jetpack-boost search term.
$redirect_on_error = admin_url( 'plugin-install.php?s=jetpack-boost&tab=search&type=term' );
// Attempt to install and activate the plugin.
if ( current_user_can( 'activate_plugins' ) ) {
switch ( $_GET['jetpack-boost-action'] ) {
case 'install':
$result = install_and_activate();
break;
case 'activate':
$result = activate();
break;
}
}
if ( $result ) {
/** This action is already documented in _inc/lib/class.core-rest-api-endpoints.php */
do_action( 'jetpack_activated_plugin', PLUGIN_FILE, 'jitm' );
$redirect = admin_url( 'admin.php?page=jetpack-boost' );
} else {
$redirect = add_query_arg( 'jetpack-boost-install-error', true, $redirect_on_error );
}
wp_safe_redirect( $redirect );
exit( 0 );
}
/**
* Install and activate the Jetpack Boost plugin.
*
* @return bool result of installation
*/
function install_and_activate() {
$result = Plugins_Installer::install_and_activate_plugin( PLUGIN_SLUG );
if ( is_wp_error( $result ) ) {
return false;
} else {
return true;
}
}
/**
* Activate the Jetpack Boost plugin.
*
* @return bool result of activation
*/
function activate() {
$result = activate_plugin( PLUGIN_FILE );
// Activate_plugin() returns null on success.
return $result === null;
}
/**
* Notify the user that the installation of Jetpack Boost failed.
*/
function error_notice() {
if ( empty( $_GET['jetpack-boost-install-error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return;
}
wp_admin_notice(
esc_html__( 'There was an error installing Jetpack Boost. Please try again.', 'jetpack' ),
array(
'type' => 'error',
'dismissible' => true,
)
);
}
+25
View File
@@ -0,0 +1,25 @@
<?php
/**
* 3rd party integration for qTranslate.
*
* @package automattic/jetpack
*/
/**
* Prevent qTranslate X from redirecting REST calls.
*
* @since 5.3
*
* @param string $url_lang Language URL to redirect to.
* @param string $url_orig Original URL.
* @param array $url_info Pieces of original URL.
*
* @return bool
*/
function jetpack_no_qtranslate_rest_url_redirect( $url_lang, $url_orig, $url_info ) {
if ( str_contains( $url_info['wp-path'], 'wp-json/jetpack' ) ) {
return false;
}
return $url_lang;
}
add_filter( 'qtranslate_language_detect_redirect', 'jetpack_no_qtranslate_rest_url_redirect', 10, 3 );
+71
View File
@@ -0,0 +1,71 @@
<?php
/**
* Handles VaultPress->Rewind transition by deactivating VaultPress when needed.
*
* @package automattic/jetpack
*/
use Automattic\Jetpack\Redirect;
/**
* Notify user that VaultPress has been disabled. Hide VaultPress notice that requested attention.
*
* @since 5.8
*/
function jetpack_vaultpress_rewind_enabled_notice() {
// The deactivation is performed here because there may be pages that admin_init runs on,
// such as admin_ajax, that could deactivate the plugin without showing this notification.
deactivate_plugins( 'vaultpress/vaultpress.php' );
// Remove WP core notice that says that the plugin was activated.
unset( $_GET['activate'] ); // phpcs:ignore WordPress.Security.NonceVerification
$message = sprintf(
wp_kses(
/* Translators: first variable is the full URL to the new dashboard */
__( '<p style="margin-bottom: 0.25em;"><strong>Jetpack is now handling your backups.</strong></p><p>VaultPress is no longer needed and has been deactivated. You can access your backups at <a href="%3$s" target="_blank" rel="noopener noreferrer">this dashboard</a>.</p>', 'jetpack' ),
array(
'a' => array(
'href' => array(),
'target' => array(),
'rel' => array(),
),
'p' => array(
'style' => array(),
),
'strong' => array(),
)
),
esc_url( Redirect::get_url( 'calypso-backups' ) )
);
wp_admin_notice(
$message,
array(
'type' => 'success',
'dismissible' => true,
'additional_classes' => array( 'vp-deactivated' ),
'paragraph_wrap' => false,
)
);
?>
<style>#vp-notice{display:none;}</style>
<?php
}
/**
* If Backup & Scan is enabled, remove its entry in sidebar, deactivate VaultPress, and show a notification.
*
* @since 5.8
*/
function jetpack_vaultpress_rewind_check() {
if (
Jetpack::is_connection_ready() &&
Jetpack::is_plugin_active( 'vaultpress/vaultpress.php' ) &&
Jetpack::is_rewind_enabled()
) {
remove_submenu_page( 'jetpack', 'vaultpress' );
add_action( 'admin_notices', 'jetpack_vaultpress_rewind_enabled_notice' );
}
}
add_action( 'admin_init', 'jetpack_vaultpress_rewind_check', 11 );
+36
View File
@@ -0,0 +1,36 @@
<?php
/**
* Compatibility functions for the Web Stories plugin.
* https://wordpress.org/plugins/web-stories/
*
* @since 9.2.0
*
* @package automattic/jetpack
*/
namespace Automattic\Jetpack\Web_Stories;
if ( ! defined( 'ABSPATH' ) ) {
exit( 0 );
}
/**
* Filter to enable web stories built in open graph data from being output.
* If Jetpack is already handling Open Graph Meta Tags, the Web Stories plugin will not output any.
*
* @param bool $enabled If web stories open graph data is enabled.
*
* @return bool
*/
function maybe_disable_open_graph( $enabled ) {
/** This filter is documented in class.jetpack.php */
$jetpack_enabled = apply_filters( 'jetpack_enable_open_graph', false );
if ( $jetpack_enabled ) {
$enabled = false;
}
return $enabled;
}
add_filter( 'web_stories_enable_open_graph_metadata', __NAMESPACE__ . '\maybe_disable_open_graph' );
add_filter( 'web_stories_enable_twitter_metadata', __NAMESPACE__ . '\maybe_disable_open_graph' );
@@ -0,0 +1,151 @@
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
use Automattic\Jetpack\Plugins_Installer;
if ( ! defined( 'ABSPATH' ) ) {
exit( 0 );
}
/**
* Installs and activates the WooCommerce Services plugin.
*/
class WC_Services_Installer {
/**
* The instance of the Jetpack class.
*
* @var Jetpack
*/
private $jetpack;
/**
* The singleton instance of this class.
*
* @var WC_Services_Installer
*/
private static $instance = null;
/**
* Returns the singleton instance of this class.
*
* @return object The WC_Services_Installer object.
*/
public static function init() {
if ( self::$instance === null ) {
self::$instance = new WC_Services_Installer();
}
return self::$instance;
}
/**
* Constructor
*/
public function __construct() {
add_action( 'jetpack_loaded', array( $this, 'on_jetpack_loaded' ) );
if ( ! empty( $_GET['wc-services-install-error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
add_action( 'admin_notices', array( $this, 'error_notice' ) );
}
if ( isset( $_GET['wc-services-action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
add_action( 'admin_init', array( $this, 'try_install' ) );
}
}
/**
* Runs on Jetpack being ready to load its packages.
*
* @param Jetpack $jetpack object.
*/
public function on_jetpack_loaded( $jetpack ) {
$this->jetpack = $jetpack;
}
/**
* Verify the intent to install WooCommerce Services, and kick off installation.
*/
public function try_install() {
if ( ! isset( $_GET['wc-services-action'] ) ) {
return;
}
check_admin_referer( 'wc-services-install' );
$result = false;
switch ( $_GET['wc-services-action'] ) {
case 'install':
if ( current_user_can( 'install_plugins' ) ) {
$this->jetpack->stat( 'jitm', 'wooservices-install-' . JETPACK__VERSION );
$result = $this->install();
if ( $result ) {
$result = $this->activate();
}
}
break;
case 'activate':
if ( current_user_can( 'activate_plugins' ) ) {
$this->jetpack->stat( 'jitm', 'wooservices-activate-' . JETPACK__VERSION );
$result = $this->activate();
}
break;
}
if ( isset( $_GET['redirect'] ) ) {
$redirect = home_url( esc_url_raw( wp_unslash( $_GET['redirect'] ) ) );
} else {
$redirect = admin_url();
}
if ( $result ) {
$this->jetpack->stat( 'jitm', 'wooservices-activated-' . JETPACK__VERSION );
} else {
$redirect = add_query_arg( 'wc-services-install-error', true, $redirect );
}
wp_safe_redirect( $redirect );
exit( 0 );
}
/**
* Notify the user that the installation of WooCommerce Services failed.
*/
public function error_notice() {
wp_admin_notice(
esc_html__( 'There was an error installing WooCommerce Services.', 'jetpack' ),
array(
'type' => 'error',
'dismissible' => true,
)
);
}
/**
* Download and install the WooCommerce Services plugin.
*
* @return bool result of installation
*/
private function install() {
$result = Plugins_Installer::install_plugin( 'woocommerce-services' );
if ( is_wp_error( $result ) ) {
return false;
} else {
return true;
}
}
/**
* Activate the WooCommerce Services plugin.
*
* @return bool result of activation
*/
private function activate() {
$result = activate_plugin( 'woocommerce-services/woocommerce-services.php' );
// Activate_plugin() returns null on success.
return $result === null;
}
}
WC_Services_Installer::init();
+136
View File
@@ -0,0 +1,136 @@
<?php
/**
* This file contains compatibility functions for WooCommerce to improve Jetpack feature support.
*
* @package automattic/jetpack
*/
add_action( 'woocommerce_init', 'jetpack_woocommerce_integration' );
/**
* Loads JP+WC integration.
*
* Fires on `woocommerce_init` hook
*/
function jetpack_woocommerce_integration() {
/**
* Double check WooCommerce exists - unlikely to fail due to the hook being used but better safe than sorry.
*/
if ( ! class_exists( 'WooCommerce' ) ) {
return;
}
add_action( 'woocommerce_share', 'jetpack_woocommerce_social_share_icons', 10 );
/**
* Add product post type to Jetpack sitemap while skipping hidden products.
*/
add_filter( 'jetpack_sitemap_post_types', 'jetpack_woocommerce_add_to_sitemap' );
add_filter( 'jetpack_sitemap_skip_post', 'jetpack_woocommerce_skip_hidden_products_in_sitemap', 10, 2 );
/**
* Wrap in function exists check since this requires WooCommerce 3.3+.
*/
if ( function_exists( 'wc_get_default_products_per_row' ) ) {
add_filter( 'infinite_scroll_render_callbacks', 'jetpack_woocommerce_infinite_scroll_render_callback', 10 );
add_action( 'wp_enqueue_scripts', 'jetpack_woocommerce_infinite_scroll_style', 10 );
}
}
/**
* Add product post type to sitemap if Woocommerce is present.
*
* @param array $post_types Array of post types included in sitemap.
*/
function jetpack_woocommerce_add_to_sitemap( $post_types ) {
$post_types[] = 'product';
return $post_types;
}
/**
* Skip hidden products when generating the sitemap.
*
* @param bool $skip Whether to skip the post.
* @param WP_Post $post The post object.
*/
function jetpack_woocommerce_skip_hidden_products_in_sitemap( $skip, $post ) {
if ( $post !== null && $post->post_type === 'product' ) {
$product = wc_get_product( $post->ID );
if ( $product ) {
$skip = ! $product->is_visible();
}
}
return $skip;
}
/**
* Make sure the social sharing icons show up under the product's short description
*/
function jetpack_woocommerce_social_share_icons() {
if ( function_exists( 'sharing_display' ) ) {
remove_filter( 'the_content', 'sharing_display', 19 );
remove_filter( 'the_excerpt', 'sharing_display', 19 );
sharing_display( '', true );
}
}
/**
* Remove sharing display from account, cart, and checkout pages in WooCommerce.
*/
function jetpack_woocommerce_remove_share() {
/**
* Double check WooCommerce exists - unlikely to fail due to the hook being used but better safe than sorry.
*/
if ( ! class_exists( 'WooCommerce' ) ) {
return;
}
if ( is_cart() || is_checkout() || is_account_page() ) {
remove_filter( 'the_content', 'sharing_display', 19 );
if ( class_exists( 'Jetpack_Likes' ) ) {
remove_filter( 'the_content', array( Jetpack_Likes::init(), 'post_likes' ), 30 );
}
}
}
add_action( 'loop_start', 'jetpack_woocommerce_remove_share' );
/**
* Add a callback for WooCommerce product rendering in infinite scroll.
*
* @param array $callbacks Array of render callpacks for IS.
* @return array
*/
function jetpack_woocommerce_infinite_scroll_render_callback( $callbacks ) {
$callbacks[] = 'jetpack_woocommerce_infinite_scroll_render';
return $callbacks;
}
/**
* Add a default renderer for WooCommerce products within infinite scroll.
*/
function jetpack_woocommerce_infinite_scroll_render() {
if ( ! is_shop() && ! is_product_taxonomy() && ! is_product_category() && ! is_product_tag() ) {
return;
}
woocommerce_product_loop_start();
while ( have_posts() ) {
the_post();
wc_get_template_part( 'content', 'product' );
}
woocommerce_product_loop_end();
}
/**
* Basic styling when infinite scroll is active only.
*/
function jetpack_woocommerce_infinite_scroll_style() {
$custom_css = '
.infinite-scroll .woocommerce-pagination {
display: none;
}';
wp_add_inline_style( 'woocommerce-layout', $custom_css );
}
+66
View File
@@ -0,0 +1,66 @@
<?php
/**
* This provides minor tweaks to improve the experience for Jetpack feed in the WordPress.com Reader.
*
* This does not make sites available in the Reader—that depends on the public access to /feed/ as a method on the WP.com side
* to check if a site is public. It also does not add any content to the feed. Any content that should not be displayed in the Reader
* or other RSS readers should be filtered out elsewhere.
*
* These hooks were originally part of the now-deprecated Enhanced Distribution.
*
* @since 13.3
* @package Automattic/jetpack
*/
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Status;
use Automattic\Jetpack\Status\Host;
foreach ( array( 'rss_head', 'rss1_head', 'rss2_head' ) as $rss_head_action ) {
add_action( $rss_head_action, 'jetpack_wpcomreader_feed_id' );
}
foreach ( array( 'rss_item', 'rss1_item', 'rss2_item' ) as $rss_item_action ) {
add_action( $rss_item_action, 'jetpack_wpcomreader_post_id' );
}
/**
* Output feed identifier based on blog ID.
*
* @return void
*/
function jetpack_wpcomreader_feed_id() {
if (
( new Host() )->is_wpcom_simple()
|| (
( new Connection_Manager() )->is_connected()
&& ! ( new Status() )->is_offline_mode()
)
) {
$blog_id = Connection_Manager::get_site_id( true ); // Silence since we're not wanting to handle the error state.
if ( ! $blog_id ) {
return;
}
printf(
'<site xmlns="com-wordpress:feed-additions:1">%d</site>',
(int) $blog_id
);
}
}
/**
* Output feed item identifier based on current post ID.
*
* @return void
*/
function jetpack_wpcomreader_post_id() {
$id = get_the_ID();
if ( ! $id ) {
return;
}
printf(
'<post-id xmlns="com-wordpress:feed-additions:1">%d</post-id>',
(int) $id
);
}
+61
View File
@@ -0,0 +1,61 @@
<?php
/**
* Only load these if WPML plugin is installed and active.
*
* @package automattic/jetpack
*/
/**
* Load routines only if WPML is loaded.
*
* @since 4.4.0
*/
function wpml_jetpack_init() {
add_action( 'jetpack_widget_get_top_posts', 'wpml_jetpack_widget_get_top_posts', 10, 3 );
add_filter( 'grunion_contact_form_field_html', 'grunion_contact_form_field_html_filter', 10, 3 );
}
add_action( 'wpml_loaded', 'wpml_jetpack_init' );
/**
* Filter the Top Posts and Pages by language.
*
* @param array $posts Array of the most popular posts.
*
* @return array
*/
function wpml_jetpack_widget_get_top_posts( $posts ) {
global $sitepress;
foreach ( $posts as $k => $post ) {
$lang_information = wpml_get_language_information( $post['post_id'] );
if ( ! is_wp_error( $lang_information ) ) {
$post_language = substr( $lang_information['locale'], 0, 2 );
if ( $post_language !== $sitepress->get_current_language() ) {
unset( $posts[ $k ] );
}
}
}
return $posts;
}
/**
* Filter the HTML of the Contact Form and output the one requested by language.
*
* @param string $r Contact Form HTML output.
* @param string $field_label Field label.
*
* @return string
*/
function grunion_contact_form_field_html_filter( $r, $field_label ) {
global $sitepress;
if ( function_exists( 'icl_translate' ) ) {
if ( $sitepress->get_current_language() !== $sitepress->get_default_language() ) {
$label_translation = icl_translate( 'jetpack ', $field_label . '_label', $field_label );
$r = str_replace( $field_label, $label_translation, $r );
}
}
return $r;
}
File diff suppressed because it is too large Load Diff
+357
View File
@@ -0,0 +1,357 @@
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===================================
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<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.
+47
View File
@@ -0,0 +1,47 @@
# Security Policy
Full details of the Automattic Security Policy can be found on [automattic.com](https://automattic.com/security/).
## Supported Versions
Generally, only the latest version of Jetpack and its associated plugins have continued support. If a critical vulnerability is found in the current version of a plugin, we may opt to backport any patches to previous versions.
## Reporting a Vulnerability
Our HackerOne program covers the below plugin software, as well as a variety of related projects and infrastructure:
* [Jetpack](https://jetpack.com/)
* Jetpack Backup
* Jetpack Boost
* Jetpack CRM
* Jetpack Protect
* Jetpack Search
* Jetpack Social
* Jetpack VideoPress
**For responsible disclosure of security issues and to be eligible for our bug bounty program, please submit your report via the [HackerOne](https://hackerone.com/automattic) portal.**
Our most critical targets are:
* Jetpack and the Jetpack composer packages (all within this repo)
* Jetpack.com -- the primary marketing site.
* cloud.jetpack.com -- a management site.
* wordpress.com -- the shared management site for both Jetpack and WordPress.com sites.
For more targets, see the `In Scope` section on [HackerOne](https://hackerone.com/automattic).
_Please note that the **WordPress software is a separate entity** from Automattic. Please report vulnerabilities for WordPress through [the WordPress Foundation's HackerOne page](https://hackerone.com/wordpress)._
## Guidelines
We're committed to working with security researchers to resolve the vulnerabilities they discover. You can help us by following these guidelines:
* Follow [HackerOne's disclosure guidelines](https://www.hackerone.com/disclosure-guidelines).
* Pen-testing Production:
* Please **setup a local environment** instead whenever possible. Most of our code is open source (see above).
* If that's not possible, **limit any data access/modification** to the bare minimum necessary to reproduce a PoC.
* **_Don't_ automate form submissions!** That's very annoying for us, because it adds extra work for the volunteers who manage those systems, and reduces the signal/noise ratio in our communication channels.
* To be eligible for a bounty, all of these guidelines must be followed.
* Be Patient - Give us a reasonable time to correct the issue before you disclose the vulnerability.
We also expect you to comply with all applicable laws. You're responsible to pay any taxes associated with your bounties.
@@ -0,0 +1,19 @@
var keyboardNavigation = false,
keyboardNavigationKeycodes = [ 9, 32, 37, 38, 39, 40 ]; // keyCodes for tab, space, left, up, right, down respectively
document.addEventListener( 'keydown', function ( event ) {
if ( keyboardNavigation ) {
return;
}
if ( keyboardNavigationKeycodes.indexOf( event.keyCode ) !== -1 ) {
keyboardNavigation = true;
document.documentElement.classList.add( 'accessible-focus' );
}
} );
document.addEventListener( 'mouseup', function () {
if ( ! keyboardNavigation ) {
return;
}
keyboardNavigation = false;
document.documentElement.classList.remove( 'accessible-focus' );
} );
File diff suppressed because one or more lines are too long
@@ -0,0 +1,61 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "jetpack/ai-assistant",
"title": "AI Assistant",
"description": "Elevate your content creation with our AI-powered Gutenberg Block, offering seamless customization and generation. Bear in mind that, as an evolving tool, occasional imprecision may occur.",
"keywords": [
"AI",
"GPT",
"AL",
"Magic",
"help",
"assistant"
],
"version": "12.5.0",
"textdomain": "jetpack",
"category": "text",
"icon": "<svg viewBox='0 0 32 32' width='32' height='32' xmlns='http://www.w3.org/2000/svg'><path d='M9.33301 5.33325L10.4644 8.20188L13.333 9.33325L10.4644 10.4646L9.33301 13.3333L8.20164 10.4646L5.33301 9.33325L8.20164 8.20188L9.33301 5.33325Z'/><path d='M21.3333 5.33333L22.8418 9.15817L26.6667 10.6667L22.8418 12.1752L21.3333 16L19.8248 12.1752L16 10.6667L19.8248 9.15817L21.3333 5.33333Z'/><path d='M14.6667 13.3333L16.5523 18.1144L21.3333 20L16.5523 21.8856L14.6667 26.6667L12.781 21.8856L8 20L12.781 18.1144L14.6667 13.3333Z'/></svg>",
"supports": {
"html": false,
"multiple": true,
"reusable": false
},
"attributes": {
"content": {
"type": "string"
},
"originalContent": {
"type": "string"
},
"promptType": {
"type": "string"
},
"originalMessages": {
"type": "array",
"default": []
},
"messages": {
"type": "array",
"default": []
},
"userPrompt": {
"type": "string",
"default": ""
},
"requestingState": {
"type": "string",
"default": "init"
},
"preTransformAction": {
"type": "string",
"default": null
}
},
"example": {
"attributes": {
"content": "With **Jetpack AI Assistant**, you can provide a prompt, and it will generate high-quality blog posts, informative pages, well-organized lists, and thorough tables that meet your specific requirements.\n\nTo start using the **Jetpack AI Assistant**, type `/AI` in the block editor."
}
},
"editorScript": "jetpack-blocks-editor"
}

Some files were not shown because too many files have changed in this diff Show More