initial commit
|
@ -0,0 +1 @@
|
|||
12
|
|
@ -0,0 +1 @@
|
|||
12
|
|
@ -0,0 +1,334 @@
|
|||
<?php
|
||||
/**
|
||||
* The class that exposes hooks for recommend.
|
||||
*
|
||||
* @package ThemeIsleSDK
|
||||
* @subpackage Rollback
|
||||
* @copyright Copyright (c) 2017, Marius Cristea
|
||||
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace ThemeisleSDK\Modules;
|
||||
|
||||
// Exit if accessed directly.
|
||||
use ThemeisleSDK\Common\Abstract_Module;
|
||||
use ThemeisleSDK\Product;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose endpoints for ThemeIsle SDK.
|
||||
*/
|
||||
class Recommendation extends Abstract_Module {
|
||||
|
||||
|
||||
/**
|
||||
* Load module logic.
|
||||
*
|
||||
* @param Product $product Product to load.
|
||||
*/
|
||||
public function load( $product ) {
|
||||
$this->product = $product;
|
||||
$this->setup_hooks();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup endpoints.
|
||||
*/
|
||||
private function setup_hooks() {
|
||||
add_action( $this->product->get_key() . '_recommend_products', array( $this, 'render_products_box' ), 10, 4 );
|
||||
add_action( 'admin_head', array( $this, 'enqueue' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we should load the module for this product.
|
||||
*
|
||||
* @param Product $product Product data.
|
||||
*
|
||||
* @return bool Should we load the module?
|
||||
*/
|
||||
public function can_load( $product ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render products box content.
|
||||
*
|
||||
* @param array $plugins_list - list of useful plugins (in slug => nicename format).
|
||||
* @param array $themes_list - list of useful themes (in slug => nicename format).
|
||||
* @param array $strings - list of translated strings.
|
||||
* @param array $preferences - list of preferences.
|
||||
*/
|
||||
public function render_products_box( $plugins_list, $themes_list, $strings, $preferences = array() ) {
|
||||
|
||||
if ( empty( $plugins_list ) && empty( $themes_list ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! empty( $plugins_list ) && ! current_user_can( 'install_plugins' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! empty( $themes_list ) && ! current_user_can( 'install_themes' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_thickbox();
|
||||
|
||||
if ( ! empty( $themes_list ) ) {
|
||||
$list = $this->get_themes( $themes_list, $preferences );
|
||||
|
||||
if ( has_action( $this->product->get_key() . '_recommend_products_theme_template' ) ) {
|
||||
do_action( $this->product->get_key() . '_recommend_products_theme_template', $list, $strings, $preferences );
|
||||
} else {
|
||||
echo '<div class="recommend-product">';
|
||||
|
||||
foreach ( $list as $theme ) {
|
||||
echo '<div class="plugin_box">';
|
||||
echo ' <img class="theme-banner" src="' . esc_url( $theme->screenshot_url ) . '">';
|
||||
echo ' <div class="title-action-wrapper">';
|
||||
echo ' <span class="plugin-name">' . esc_html( $theme->custom_name ) . '</span>';
|
||||
if ( ! isset( $preferences['description'] ) || ( isset( $preferences['description'] ) && $preferences['description'] ) ) {
|
||||
echo '<span class="plugin-desc">' . esc_html( substr( $theme->description, 0, strpos( $theme->description, '.' ) ) ) . '.</span>';
|
||||
}
|
||||
echo ' </div>';
|
||||
echo '<div class="plugin-box-footer">';
|
||||
echo ' <div class="button-wrap">';
|
||||
echo ' <a class="button button-primary " href="' . esc_url( $theme->custom_url ) . '"><span class="dashicons dashicons-external"></span>' . esc_html( $strings['install'] ) . '</a>';
|
||||
echo ' </div>';
|
||||
echo ' </div>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
if ( ! empty( $plugins_list ) ) {
|
||||
$list = $this->get_plugins( $plugins_list, $preferences );
|
||||
|
||||
if ( has_action( $this->product->get_key() . '_recommend_products_plugin_template' ) ) {
|
||||
do_action( $this->product->get_key() . '_recommend_products_plugin_template', $list, $strings, $preferences );
|
||||
} else {
|
||||
echo '<div class="recommend-product">';
|
||||
|
||||
foreach ( $list as $current_plugin ) {
|
||||
echo '<div class="plugin_box">';
|
||||
echo ' <img class="plugin-banner" src="' . esc_url( $current_plugin->custom_image ) . '">';
|
||||
echo ' <div class="title-action-wrapper">';
|
||||
echo ' <span class="plugin-name">' . esc_html( $current_plugin->custom_name ) . '</span>';
|
||||
if ( ! isset( $preferences['description'] ) || ( isset( $preferences['description'] ) && $preferences['description'] ) ) {
|
||||
echo '<span class="plugin-desc">' . esc_html( substr( $current_plugin->short_description, 0, strpos( $current_plugin->short_description, '.' ) ) ) . '. </span>';
|
||||
}
|
||||
echo ' </div>';
|
||||
echo ' <div class="plugin-box-footer">';
|
||||
echo ' <a class="button button-primary thickbox open-plugin-details-modal" href="' . esc_url( $current_plugin->custom_url ) . '"><span class="dashicons dashicons-external"></span>' . esc_html( $strings['install'] ) . '</a>';
|
||||
echo ' </div>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect all the information for the themes list.
|
||||
*
|
||||
* @param array $themes_list - list of useful themes (in slug => nicename format).
|
||||
* @param array $preferences - list of preferences.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_themes( $themes_list, $preferences ) {
|
||||
$list = array();
|
||||
foreach ( $themes_list as $slug => $nicename ) {
|
||||
$theme = $this->call_theme_api( $slug );
|
||||
if ( ! $theme ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$url = add_query_arg(
|
||||
array(
|
||||
'theme' => $theme->slug,
|
||||
),
|
||||
network_admin_url( 'theme-install.php' )
|
||||
);
|
||||
|
||||
$name = empty( $nicename ) ? $theme->name : $nicename;
|
||||
|
||||
$theme->custom_url = $url;
|
||||
$theme->custom_name = $name;
|
||||
|
||||
$list[] = $theme;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call theme api
|
||||
*
|
||||
* @param string $slug theme slug.
|
||||
*
|
||||
* @return array|mixed|object
|
||||
*/
|
||||
private function call_theme_api( $slug ) {
|
||||
$theme = get_transient( 'ti_theme_info_' . $slug );
|
||||
|
||||
if ( false !== $theme ) {
|
||||
return $theme;
|
||||
}
|
||||
|
||||
$products = $this->safe_get(
|
||||
'https://api.wordpress.org/themes/info/1.1/?action=query_themes&request[theme]=' . $slug . '&request[per_page]=1'
|
||||
);
|
||||
$products = json_decode( wp_remote_retrieve_body( $products ) );
|
||||
if ( is_object( $products ) ) {
|
||||
$theme = $products->themes[0];
|
||||
set_transient( 'ti_theme_info_' . $slug, $theme, 6 * HOUR_IN_SECONDS );
|
||||
}
|
||||
|
||||
return $theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect all the information for the plugins list.
|
||||
*
|
||||
* @param array $plugins_list - list of useful plugins (in slug => nicename format).
|
||||
* @param array $preferences - list of preferences.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_plugins( $plugins_list, $preferences ) {
|
||||
$list = array();
|
||||
foreach ( $plugins_list as $plugin => $nicename ) {
|
||||
$current_plugin = $this->call_plugin_api( $plugin );
|
||||
|
||||
$name = empty( $nicename ) ? $current_plugin->name : $nicename;
|
||||
|
||||
$image = $current_plugin->banners['low'];
|
||||
if ( isset( $preferences['image'] ) && 'icon' === $preferences['image'] ) {
|
||||
$image = $current_plugin->icons['1x'];
|
||||
}
|
||||
|
||||
$url = add_query_arg(
|
||||
array(
|
||||
'tab' => 'plugin-information',
|
||||
'plugin' => $current_plugin->slug,
|
||||
'TB_iframe' => true,
|
||||
'width' => 800,
|
||||
'height' => 800,
|
||||
),
|
||||
network_admin_url( 'plugin-install.php' )
|
||||
);
|
||||
|
||||
$current_plugin->custom_url = $url;
|
||||
$current_plugin->custom_name = $name;
|
||||
$current_plugin->custom_image = $image;
|
||||
|
||||
$list[] = $current_plugin;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load css and scripts for the plugin recommend page.
|
||||
*/
|
||||
public function enqueue() {
|
||||
$screen = get_current_screen();
|
||||
|
||||
if ( ! isset( $screen->id ) ) {
|
||||
return;
|
||||
}
|
||||
if ( false === apply_filters( $this->product->get_key() . '_enqueue_recommend', false, $screen->id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
?>
|
||||
<style type="text/css">
|
||||
.recommend-product {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.recommend-product .theme-banner {
|
||||
width: 200px;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.recommend-product .plugin-banner {
|
||||
width: 100px;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.recommend-product .plugin_box .button span {
|
||||
|
||||
margin-top: 2px;
|
||||
margin-right: 7px;
|
||||
}
|
||||
|
||||
.recommend-product .plugin_box .button {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.recommend-product .plugin_box {
|
||||
margin-bottom: 20px;
|
||||
padding-top: 5px;
|
||||
display: flex;
|
||||
box-shadow: 0px 0px 10px -5px rgba(0, 0, 0, 0.55);
|
||||
background: #fff;
|
||||
border-radius: 5px;
|
||||
flex-direction: column;
|
||||
justify-content: flex-start;
|
||||
width: 95%;
|
||||
}
|
||||
|
||||
.recommend-product .title-action-wrapper {
|
||||
padding: 15px 20px 5px 20px;
|
||||
}
|
||||
|
||||
.recommend-product .plugin-name {
|
||||
font-size: 18px;
|
||||
display: block;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
margin-bottom: 10px;
|
||||
overflow: hidden;
|
||||
line-height: normal;
|
||||
}
|
||||
|
||||
|
||||
.recommend-product .plugin-desc {
|
||||
display: block;
|
||||
margin-bottom: 10px;
|
||||
font-size: 13px;
|
||||
color: #777;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.recommend-product .button-wrap > div {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.plugin-box-footer {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
vertical-align: middle;
|
||||
align-items: center;
|
||||
padding: 0px 10px 5px;
|
||||
flex: 1;
|
||||
margin-top: auto;
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 42 KiB |
After Width: | Height: | Size: 4.8 KiB |
|
@ -0,0 +1,2 @@
|
|||
<?php
|
||||
// Silence is golden
|
After Width: | Height: | Size: 26 KiB |
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
/**
|
||||
* The module factory class.
|
||||
*
|
||||
* @package ThemeIsleSDK
|
||||
* @subpackage Loader
|
||||
* @copyright Copyright (c) 2017, Marius Cristea
|
||||
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
namespace ThemeisleSDK\Common;
|
||||
|
||||
use ThemeisleSDK\Product;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Job_Factory
|
||||
*
|
||||
* @package ThemeisleSDK\Common
|
||||
*/
|
||||
class Module_Factory {
|
||||
/**
|
||||
* Partners slugs.
|
||||
*
|
||||
* @var array $SLUGS Partners product slugs.
|
||||
*/
|
||||
public static $slugs = [
|
||||
'zermatt' => true,
|
||||
'neto' => true,
|
||||
'olsen' => true,
|
||||
'benson' => true,
|
||||
'romero' => true,
|
||||
'carmack' => true,
|
||||
'puzzle' => true,
|
||||
'broadsheet' => true,
|
||||
'girlywp' => true,
|
||||
'veggie' => true,
|
||||
'zeko' => true,
|
||||
'maishawp' => true,
|
||||
'didi' => true,
|
||||
'liber' => true,
|
||||
'medicpress-pt' => true,
|
||||
'adrenaline-pt' => true,
|
||||
'consultpress-pt' => true,
|
||||
'legalpress-pt' => true,
|
||||
'gympress-pt' => true,
|
||||
'readable-pt' => true,
|
||||
'bolts-pt' => true,
|
||||
];
|
||||
/**
|
||||
* Partners domains.
|
||||
*
|
||||
* @var array $DOMAINS Partners domains.
|
||||
*/
|
||||
public static $domains = [
|
||||
'proteusthemes.com',
|
||||
'anarieldesign.com',
|
||||
'prothemedesign.com',
|
||||
'cssigniter.com',
|
||||
];
|
||||
/**
|
||||
* Map which contains all the modules loaded for each product.
|
||||
*
|
||||
* @var array Mapping array.
|
||||
*/
|
||||
private static $modules_attached = [];
|
||||
|
||||
/**
|
||||
* Load availabe modules for the selected product.
|
||||
*
|
||||
* @param Product $product Loaded product.
|
||||
* @param array $modules List of modules.
|
||||
*/
|
||||
public static function attach( $product, $modules ) {
|
||||
|
||||
if ( ! isset( self::$modules_attached[ $product->get_slug() ] ) ) {
|
||||
self::$modules_attached[ $product->get_slug() ] = [];
|
||||
}
|
||||
|
||||
foreach ( $modules as $module ) {
|
||||
$class = 'ThemeisleSDK\\Modules\\' . ucwords( $module, '_' );
|
||||
/**
|
||||
* Module object.
|
||||
*
|
||||
* @var Abstract_Module $module_object Module instance.
|
||||
*/
|
||||
$module_object = new $class( $product );
|
||||
|
||||
if ( ! $module_object->can_load( $product ) ) {
|
||||
continue;
|
||||
}
|
||||
self::$modules_attached[ $product->get_slug() ][ $module ] = $module_object->load( $product );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Products/Modules loaded map.
|
||||
*
|
||||
* @return array Modules map.
|
||||
*/
|
||||
public static function get_modules_map() {
|
||||
return self::$modules_attached;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
/**
|
||||
* The Review model class for ThemeIsle SDK
|
||||
*
|
||||
* @package ThemeIsleSDK
|
||||
* @subpackage Modules
|
||||
* @copyright Copyright (c) 2017, Marius Cristea
|
||||
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace ThemeisleSDK\Modules;
|
||||
|
||||
use ThemeisleSDK\Common\Abstract_Module;
|
||||
use ThemeisleSDK\Product;
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Review module for ThemeIsle SDK.
|
||||
*/
|
||||
class Review extends Abstract_Module {
|
||||
|
||||
/**
|
||||
* Check if we should load module for this.
|
||||
*
|
||||
* @param Product $product Product to check.
|
||||
*
|
||||
* @return bool Should load ?
|
||||
*/
|
||||
public function can_load( $product ) {
|
||||
if ( $this->is_from_partner( $product ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( ! $product->is_wordpress_available() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return apply_filters( $product->get_slug() . '_sdk_should_review', true );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add notification to queue.
|
||||
*
|
||||
* @param array $all_notifications Previous notification.
|
||||
*
|
||||
* @return array All notifications.
|
||||
*/
|
||||
public function add_notification( $all_notifications ) {
|
||||
|
||||
$developers = [
|
||||
'Bogdan',
|
||||
'Marius',
|
||||
'Hardeep',
|
||||
'Rodica',
|
||||
'Stefan',
|
||||
'Uriahs',
|
||||
'Madalin',
|
||||
'Cristi',
|
||||
'Silviu',
|
||||
'Andrei',
|
||||
];
|
||||
|
||||
$link = 'https://wordpress.org/support/' . $this->product->get_type() . '/' . $this->product->get_slug() . '/reviews/#wporg-footer';
|
||||
|
||||
$message = apply_filters( $this->product->get_key() . '_feedback_review_message', '<p>Hey, it\'s great to see you have <b>{product}</b> active for a few days now. How is everything going? If you can spare a few moments to rate it on WordPress.org it would help us a lot (and boost my motivation). Cheers! <br/> <br/>~ {developer}, developer of {product}</p>' );
|
||||
|
||||
$button_submit = apply_filters( $this->product->get_key() . '_feedback_review_button_do', 'Ok, I will gladly help.' );
|
||||
$button_cancel = apply_filters( $this->product->get_key() . '_feedback_review_button_cancel', 'No, thanks.' );
|
||||
$message = str_replace(
|
||||
[ '{product}', '{developer}' ],
|
||||
[
|
||||
$this->product->get_friendly_name(),
|
||||
$developers[ strlen( get_site_url() ) % 10 ],
|
||||
],
|
||||
$message
|
||||
);
|
||||
|
||||
$all_notifications[] = [
|
||||
'id' => $this->product->get_key() . '_review_flag',
|
||||
'message' => $message,
|
||||
'ctas' => [
|
||||
'confirm' => [
|
||||
'link' => $link,
|
||||
'text' => $button_submit,
|
||||
],
|
||||
'cancel' => [
|
||||
'link' => '#',
|
||||
'text' => $button_cancel,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return $all_notifications;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load module logic.
|
||||
*
|
||||
* @param Product $product Product to load.
|
||||
*
|
||||
* @return Review Module instance.
|
||||
*/
|
||||
public function load( $product ) {
|
||||
|
||||
$this->product = $product;
|
||||
|
||||
add_filter( 'themeisle_sdk_registered_notifications', [ $this, 'add_notification' ] );
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. 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
|
||||
them 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 prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. 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.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey 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;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If 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 convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU 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 that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
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.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
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.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
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
|
||||
state 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
{project} Copyright (C) {year} {fullname}
|
||||
This program 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, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU 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. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 2.6 KiB |
|
@ -0,0 +1,675 @@
|
|||
#wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-container.bullet-green .ab-icon::before,
|
||||
#wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-container.bullet-green:hover .ab-icon::before {
|
||||
content: "\f176";
|
||||
color: #02ca02;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
#wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-container.bullet-red .ab-icon::before,
|
||||
#wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-container.bullet-red:hover .ab-icon::before {
|
||||
content: "\f176";
|
||||
color: #d40000;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.main_section input[type=text],
|
||||
.main_section input[type=password],
|
||||
.main_section input[type=email],
|
||||
.main_section select {
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.main_section .description.highlighted {
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.swcfpc_sidebar_widget .button,
|
||||
#swcfpc_main_content .button {
|
||||
transition: all 0.5s;
|
||||
}
|
||||
|
||||
.swcfpc_tab {
|
||||
display: none;
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
.swcfpc_tab.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.swcfpc_tab .main_section .right_column p:first-of-type {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
#swcfpc_tab_links {
|
||||
margin-top: 20px;
|
||||
border-bottom: 1px solid #333;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#swcfpc_tab_links .nav-tab:focus,
|
||||
#swcfpc_tab_links .nav-tab:hover,
|
||||
#swcfpc_tab_links .nav-tab.nav-tab-active {
|
||||
background: #f38020;
|
||||
color: #fff;
|
||||
border: 1px solid #f38020;
|
||||
margin-top: 0;
|
||||
padding-top: 8px;
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
|
||||
#swcfpc_tab_links .nav-tab.nav-tab-active {
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
#swcfpc_tab_links .nav-tab.green {
|
||||
background: #7fbf2d !important;
|
||||
border-color: #7fbf2d !important;
|
||||
}
|
||||
|
||||
|
||||
#swcfpc_tab_links .nav-tab {
|
||||
background: #333;
|
||||
color: #fff;
|
||||
border: 1px solid #333;
|
||||
border-top-left-radius: 7px;
|
||||
border-top-right-radius: 7px;
|
||||
cursor: pointer;
|
||||
min-width: 80px;
|
||||
text-align: center;
|
||||
margin-top: 6px;
|
||||
padding-top: 5px;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.settings_page_wp-cloudflare-super-page-cache-index #wpcontent {
|
||||
background: #fff !important;
|
||||
}
|
||||
|
||||
.ui-dialog .ui-widget-header {
|
||||
border: 1px solid #f38020 !important;
|
||||
background: #f38020 !important;
|
||||
color: #fff !important;
|
||||
}
|
||||
|
||||
.ui-dialog {
|
||||
z-index: 1001;
|
||||
}
|
||||
|
||||
.swcfpc_please_wait {
|
||||
/*margin-top: 30px;*/
|
||||
width: 100%;
|
||||
/*height: 100%;*/
|
||||
background: #fff url('../img/please_wait.gif') center center;
|
||||
background-repeat: no-repeat;
|
||||
position: fixed;
|
||||
z-index: 99999;
|
||||
opacity: 0.9;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.swcfpc_plugin_active {
|
||||
background: #47a700;
|
||||
float: right;
|
||||
padding: 0 5px;
|
||||
letter-spacing: 1px;
|
||||
border: 1px solid #47a700;
|
||||
border-radius: 3px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.swcfpc_plugin_inactive {
|
||||
background: #e60303;
|
||||
float: right;
|
||||
padding: 0 5px;
|
||||
letter-spacing: 1px;
|
||||
border: 1px solid #e60303;
|
||||
border-radius: 3px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.pro_version_badge_header {
|
||||
background: #ffe000;
|
||||
float: right;
|
||||
padding: 0 5px;
|
||||
letter-spacing: 1px;
|
||||
border: 1px solid #ffe000;
|
||||
border-radius: 3px;
|
||||
font-size: 12px;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.pro_version_only_badge {
|
||||
background: #ffe000;
|
||||
padding: 0 5px;
|
||||
letter-spacing: 1px;
|
||||
border: 1px solid #ffe000;
|
||||
border-radius: 5px;
|
||||
font-size: 12px;
|
||||
color: #000;
|
||||
display: inline-block;
|
||||
margin-bottom: 10px;
|
||||
width: auto;
|
||||
text-transform: uppercase;
|
||||
padding: 4px 5px;
|
||||
}
|
||||
|
||||
.step {
|
||||
width: 100%;
|
||||
margin-top: 50px;
|
||||
margin-bottom: 40px;
|
||||
box-sizing: border-box;
|
||||
font-size: 16px;
|
||||
line-height: 20px;
|
||||
box-shadow: 0px 3px 3px 3px #dedede;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.step li {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.step_counter {
|
||||
background: #ffffff;
|
||||
color: #949494b0;
|
||||
padding: 20px 0;
|
||||
font-size: 18px;
|
||||
text-align: center;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.step_number {
|
||||
float: left;
|
||||
width: 33.33%;
|
||||
}
|
||||
|
||||
.step_number span {
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 50%;
|
||||
padding: 10px 15px;
|
||||
}
|
||||
|
||||
.step_number.step_active {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.step_number.step_active span {
|
||||
border: 1px solid #f38020;
|
||||
border-radius: 50%;
|
||||
padding: 10px 15px;
|
||||
background: #f38020;
|
||||
}
|
||||
|
||||
.step h2 {
|
||||
color: #f38020;
|
||||
font-size: 22px;
|
||||
line-height: 30px;
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.step p {
|
||||
font-size: 16px;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.step form .submit {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.green_button {
|
||||
background: #85B730 !important;
|
||||
border-color: #85B730 !important;
|
||||
text-shadow: none !important;
|
||||
box-shadow: 0 1px 0 #3E6300 !important;
|
||||
color: #fff !important;
|
||||
}
|
||||
|
||||
.red_button {
|
||||
background: #dc3232 !important;
|
||||
border-color: #dc3232 !important;
|
||||
text-shadow: none !important;
|
||||
box-shadow: 0 1px 0 #7B0000 !important;
|
||||
color: #fff !important;
|
||||
}
|
||||
|
||||
#swcfpc_sidebar {
|
||||
float: left;
|
||||
width: 25%;
|
||||
padding-top: 50px;
|
||||
}
|
||||
|
||||
.swcfpc_sidebar_widget {
|
||||
box-shadow: 0px 3px 3px 3px #dedede;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.swcfpc_sidebar_widget h3 {
|
||||
border-bottom: 2px solid #f38020;
|
||||
padding-bottom: 8px;
|
||||
text-align: center;
|
||||
font-size: 18px;
|
||||
line-height: 25px;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
#swcfpc_sidebar img {
|
||||
margin: 10px auto 20px;
|
||||
max-width: 170px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
#swcfpc_main_content.width_sidebar {
|
||||
float: left;
|
||||
width: 75%;
|
||||
box-sizing: border-box;
|
||||
padding-right: 20px;
|
||||
}
|
||||
|
||||
.swcfpc_sidebar_widget .button {
|
||||
display: block;
|
||||
margin: 20px auto 0 auto;
|
||||
max-width: 170px;
|
||||
}
|
||||
|
||||
.swcfpc_sidebar_widget .button,
|
||||
#swcfpc_main_content .button {
|
||||
min-width: 170px;
|
||||
padding: 5px 8px;
|
||||
text-shadow: none !important;
|
||||
font-size: 13px;
|
||||
text-transform: uppercase;
|
||||
font-weight: 600;
|
||||
border-radius: 5px;
|
||||
background: #f38020;
|
||||
color: #ffffff;
|
||||
border-color: #f38020;
|
||||
box-shadow: inset 0 0px 2px rgba(113, 113, 113, 0.3), 0 1px rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.swcfpc_sidebar_widget .button:hover,
|
||||
#swcfpc_main_content .button:hover {
|
||||
background: #333333;
|
||||
color: #fff;
|
||||
border-color: #333;
|
||||
}
|
||||
|
||||
#swcfpc_actions {
|
||||
text-align: center;
|
||||
margin-top: 30px;
|
||||
box-shadow: 0px 3px 3px 3px #dedede;
|
||||
padding: 20px 20px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
#swcfpc_actions form {
|
||||
display: inline-flex;
|
||||
margin: 0 10px;
|
||||
}
|
||||
|
||||
#swcfpc_actions p.submit {
|
||||
margin-top: 0 !important;
|
||||
margin-bottom: 0 !important;
|
||||
padding: 10px 0 !important;
|
||||
}
|
||||
|
||||
#swcfpc_purge_cache_everything {
|
||||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.orange_color {
|
||||
color: #f38020;
|
||||
}
|
||||
|
||||
.main_section_header {
|
||||
background: #333;
|
||||
border-bottom-color: transparent !important;
|
||||
position: relative;
|
||||
top: -1px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
.main_section_header.first_section {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.main_section_header h3 {
|
||||
box-shadow: -3px 0 0 0 #f38020;
|
||||
color: #fff;
|
||||
font-size: 15px;
|
||||
font-weight: 400;
|
||||
padding: 15px 20px;
|
||||
letter-spacing: 2px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.main_section {
|
||||
border-bottom: 1px solid #ebecec;
|
||||
padding: 15px 0;
|
||||
display: block;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.description_section {
|
||||
font-size: 15px;
|
||||
line-height: 23px;
|
||||
margin-bottom: 30px;
|
||||
background: #f3f3f3;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
|
||||
.main_section.sublevel {
|
||||
margin-left: 30px;
|
||||
background: #dce7f7;
|
||||
padding: 10px;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
.main_section label {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.main_section .description {
|
||||
font-weight: 100;
|
||||
font-size: 14px;
|
||||
line-height: 20px;
|
||||
text-shadow: none !important;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.main_section .description_pro {
|
||||
font-weight: 100;
|
||||
font-size: 14px;
|
||||
line-height: 20px;
|
||||
text-shadow: none!important;
|
||||
width: 100%;
|
||||
background: #ffe000;
|
||||
padding: 8px;
|
||||
color: #000;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.main_section .description.highlighted {
|
||||
background: #ffe000;
|
||||
padding: 8px;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.description_section.highlighted {
|
||||
background: #ffe000;
|
||||
padding: 8px;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
|
||||
.main_section input[type=text],
|
||||
.main_section input[type=password],
|
||||
.main_section input[type=email],
|
||||
.main_section select {
|
||||
padding: 5px 10px;
|
||||
min-width: 200px;
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
border: 1px solid #dfdfdf;
|
||||
}
|
||||
|
||||
.main_section textarea {
|
||||
min-height: 100px;
|
||||
width: 100%;
|
||||
border: 1px solid #dfdfdf;
|
||||
padding: 5px 10px;
|
||||
}
|
||||
|
||||
.main_section .left_column {
|
||||
width: 38%;
|
||||
float: left;
|
||||
vertical-align: middle;
|
||||
padding: 5px 0;
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
color: #39464e;
|
||||
margin-right: 4%;
|
||||
}
|
||||
|
||||
|
||||
.main_section .left_column label {
|
||||
cursor: default !important;
|
||||
font-size: 16px;
|
||||
margin-bottom: 10px;
|
||||
display: block;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.main_section .right_column {
|
||||
float: left;
|
||||
width: 58%;
|
||||
}
|
||||
|
||||
.swcfpc_hide {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
#swcfpc_main_content.backend_log {
|
||||
float: none;
|
||||
width: 100%;
|
||||
border-right: none;
|
||||
}
|
||||
|
||||
#swcfpc_main_content .log_date {
|
||||
width: 15%;
|
||||
display: table-cell;
|
||||
}
|
||||
|
||||
#swcfpc_main_content .log_identifier {
|
||||
width: 30%;
|
||||
display: table-cell;
|
||||
}
|
||||
|
||||
#swcfpc_main_content .log_msg {
|
||||
display: table-cell;
|
||||
width: 54%;
|
||||
}
|
||||
|
||||
#swcfpc_main_content h1 {
|
||||
text-align: center;
|
||||
font-weight: 600;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.right_column input[type=checkbox]:checked::before {
|
||||
content: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH5AQZFQEsqL5x2AAAARhJREFUOMuVkqFLQ1EUxn/3sZXBDQNF295fILIklgVhbQarYDKqMLBZjtFgMi+4YFMwmEQwCMMgsmw5VTQIz7hgOQ8Oc9u7u+185/u+e853b2DJU0i+BpwCLeChtqS4Azw76DUkCgE2gLGDD6PoICSKG8APUDdYoug5QOoEb0Dbysco2i17WYK478S/QNemYuEERloBvhy8DYyiaLWBmYyALStvouj+NCeUt3lXu30XuHfcOjDxPJ9Bs5B8XEjeA0qzoeMdR9F/YoBQSH4AXDtsB9gELq3+jqKr89bMgPcp7MmJAY586vMy2ANuZ/Q/o+j6oqAz2/kOuJrRP6v6J5l7hRPgwzej6KDKoFambnv2gAtgArykfPM/mQ1VPd59seUAAAAASUVORK5CYII=);
|
||||
margin: 1px 0 0;
|
||||
height: 16px;
|
||||
width: 16px;
|
||||
}
|
||||
|
||||
.right_column input[type="checkbox"] {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
margin: 0 5px 5px;
|
||||
border: 1px solid #dfdfdf;
|
||||
}
|
||||
|
||||
.right_column input[type=checkbox]:focus,
|
||||
.right_column input[type=color]:focus,
|
||||
.right_column input[type=date]:focus,
|
||||
.right_column input[type=datetime-local]:focus,
|
||||
.right_column input[type=datetime]:focus,
|
||||
.right_column input[type=email]:focus,
|
||||
.right_column input[type=month]:focus,
|
||||
.right_column input[type=number]:focus,
|
||||
.right_column input[type=password]:focus,
|
||||
.right_column input[type=radio]:focus,
|
||||
.right_column input[type=search]:focus,
|
||||
.right_column input[type=tel]:focus,
|
||||
.right_column input[type=text]:focus,
|
||||
.right_column input[type=time]:focus,
|
||||
.right_column input[type=url]:focus,
|
||||
.right_column input[type=week]:focus,
|
||||
.right_column select:focus,
|
||||
.right_column textarea:focus {
|
||||
border-color: #f38020;
|
||||
box-shadow: 0 0 0 1px #f38020;
|
||||
outline: 1px solid transparent;
|
||||
}
|
||||
|
||||
#swcfpc_cache_mbox select {
|
||||
display: block;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#swcfpc_main_content .itemDetail {
|
||||
background: #fff;
|
||||
width: 250px;
|
||||
min-height: 290px;
|
||||
border: 1px solid #ccc;
|
||||
float: left;
|
||||
padding: 15px;
|
||||
position: relative;
|
||||
margin: 0 10px 10px 0;
|
||||
}
|
||||
|
||||
#swcfpc_main_content .itemTitle {
|
||||
margin-top:0px;
|
||||
margin-bottom:10px;
|
||||
}
|
||||
|
||||
#swcfpc_main_content .itemImage {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#swcfpc_main_content .itemImage img {
|
||||
max-width: 95%;
|
||||
max-height: 150px;
|
||||
}
|
||||
|
||||
#swcfpc_main_content .itemDescription {
|
||||
margin-bottom:30px;
|
||||
}
|
||||
|
||||
#swcfpc_main_content .itemButtonRow {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
right: 10px;
|
||||
width:100%;
|
||||
}
|
||||
|
||||
#swcfpc_main_content .itemButton {
|
||||
float:right;
|
||||
}
|
||||
|
||||
#swcfpc_main_content .itemButton a {
|
||||
text-decoration: none;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
#swcfpc_main_content .itemButton a:hover {
|
||||
text-decoration: none;
|
||||
color: #23282d;
|
||||
}
|
||||
|
||||
.swcfpc_faq_accordion .swcfpc_faq_question {
|
||||
background: #ebebeb;
|
||||
color: #333;
|
||||
display: block;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
margin: 2px 0 0 0;
|
||||
padding: .5em .5em .5em .7em;
|
||||
min-height: 0;
|
||||
font-size: 14px;
|
||||
border-radius: 4px;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.swcfpc_faq_accordion .swcfpc_faq_question.active,
|
||||
.swcfpc_faq_accordion .swcfpc_faq_question:hover {
|
||||
background: #f38020;
|
||||
color: #fff;
|
||||
border-color: #f38020;
|
||||
}
|
||||
|
||||
.swcfpc_faq_accordion .swcfpc_faq_answer {
|
||||
padding: 15px 20px;
|
||||
height: auto!important;
|
||||
border: 1px solid #ebebeb;
|
||||
margin-bottom: 5px;
|
||||
box-sizing: border-box;
|
||||
background: #fff;
|
||||
border-top: 0;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.swcfpc_faq_accordion .swcfpc_faq_answer ul {
|
||||
list-style: revert;
|
||||
margin-left: 2em;
|
||||
}
|
||||
|
||||
/* SWITCH - START */
|
||||
|
||||
.switch-field {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.switch-title {
|
||||
margin-bottom: 6px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.switch-field input {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.switch-field label {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.switch-field label {
|
||||
display: inline-block;
|
||||
width: 100px;
|
||||
background-color: #f9f9f9;
|
||||
color: rgba(0, 0, 0, 0.6);
|
||||
font-size: 14px;
|
||||
font-weight: normal;
|
||||
text-align: center;
|
||||
text-shadow: none;
|
||||
padding: 10px 14px;
|
||||
border: 1px solid rgba(0, 0, 0, 0.2);
|
||||
-webkit-box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px rgba(255, 255, 255, 0.1);
|
||||
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px rgba(255, 255, 255, 0.1);
|
||||
-webkit-transition: all 0.1s ease-in-out;
|
||||
-moz-transition: all 0.1s ease-in-out;
|
||||
-ms-transition: all 0.1s ease-in-out;
|
||||
-o-transition: all 0.1s ease-in-out;
|
||||
transition: all 0.1s ease-in-out;
|
||||
}
|
||||
|
||||
.switch-field label:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.switch-field input:checked + label {
|
||||
background-color: #f38020;
|
||||
color: #fff;
|
||||
-webkit-box-shadow: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.switch-field label:first-of-type {
|
||||
border-radius: 4px 0 0 4px;
|
||||
}
|
||||
|
||||
.switch-field label:last-of-type {
|
||||
border-radius: 0 4px 4px 0;
|
||||
}
|
||||
|
||||
/* SWITCH - END */
|
|
@ -0,0 +1,937 @@
|
|||
// Worker version: 2.8.0
|
||||
// Default cookie prefixes for cache bypassing
|
||||
const DEFAULT_BYPASS_COOKIES = [
|
||||
'wordpress_logged_in_',
|
||||
'comment_',
|
||||
'woocommerce_',
|
||||
'wordpressuser_',
|
||||
'wordpresspass_',
|
||||
'wordpress_sec_',
|
||||
'yith_wcwl_products',
|
||||
'edd_items_in_cart',
|
||||
'it_exchange_session_',
|
||||
'comment_author',
|
||||
'dshack_level',
|
||||
'auth',
|
||||
'noaffiliate_',
|
||||
'mp_session',
|
||||
'mp_globalcart_',
|
||||
'xf_'
|
||||
]
|
||||
|
||||
// Third party query parameter that we need to ignore in a URL
|
||||
const THIRD_PARTY_QUERY_PARAMETERS = [
|
||||
'Browser',
|
||||
'C',
|
||||
'GCCON',
|
||||
'MCMP',
|
||||
'MarketPlace',
|
||||
'PD',
|
||||
'Refresh',
|
||||
'Sens',
|
||||
'ServiceVersion',
|
||||
'Source',
|
||||
'Topic',
|
||||
'__WB_REVISION__',
|
||||
'__cf_chl_jschl_tk__',
|
||||
'__d',
|
||||
'__hsfp',
|
||||
'__hssc',
|
||||
'__hstc',
|
||||
'__s',
|
||||
'_branch_match_id',
|
||||
'_bta_c',
|
||||
'_bta_tid',
|
||||
'_com',
|
||||
'_escaped_fragment_',
|
||||
'_ga',
|
||||
'_ga-ft',
|
||||
'_gl',
|
||||
'_hsmi',
|
||||
'_ke',
|
||||
'_kx',
|
||||
'_paged',
|
||||
'_sm_byp',
|
||||
'_sp',
|
||||
'_szp',
|
||||
'3x',
|
||||
'a',
|
||||
'a_k',
|
||||
'ac',
|
||||
'acpage',
|
||||
'action-box',
|
||||
'action_object_map',
|
||||
'action_ref_map',
|
||||
'action_type_map',
|
||||
'activecampaign_id',
|
||||
'ad',
|
||||
'ad_frame_full',
|
||||
'ad_frame_root',
|
||||
'ad_name',
|
||||
'adclida',
|
||||
'adid',
|
||||
'adlt',
|
||||
'adsafe_ip',
|
||||
'adset_name',
|
||||
'advid',
|
||||
'aff_sub2',
|
||||
'afftrack',
|
||||
'afterload',
|
||||
'ak_action',
|
||||
'alt_id',
|
||||
'am',
|
||||
'amazingmurphybeds',
|
||||
'amp;',
|
||||
'amp;amp',
|
||||
'amp;amp;amp',
|
||||
'amp;amp;amp;amp',
|
||||
'amp;utm_campaign',
|
||||
'amp;utm_medium',
|
||||
'amp;utm_source',
|
||||
'ampStoryAutoAnalyticsLinker',
|
||||
'ampstoryautoanalyticslinke',
|
||||
'an',
|
||||
'ap',
|
||||
'ap_id',
|
||||
'apif',
|
||||
'apipage',
|
||||
'as_occt',
|
||||
'as_q',
|
||||
'as_qdr',
|
||||
'askid',
|
||||
'atFileReset',
|
||||
'atfilereset',
|
||||
'aucid',
|
||||
'auct',
|
||||
'audience',
|
||||
'author',
|
||||
'awt_a',
|
||||
'awt_l',
|
||||
'awt_m',
|
||||
'b2w',
|
||||
'back',
|
||||
'bannerID',
|
||||
'blackhole',
|
||||
'blockedAdTracking',
|
||||
'blog-reader-used',
|
||||
'blogger',
|
||||
'br',
|
||||
'bsft_aaid',
|
||||
'bsft_clkid',
|
||||
'bsft_eid',
|
||||
'bsft_ek',
|
||||
'bsft_lx',
|
||||
'bsft_mid',
|
||||
'bsft_mime_type',
|
||||
'bsft_tv',
|
||||
'bsft_uid',
|
||||
'bvMethod',
|
||||
'bvTime',
|
||||
'bvVersion',
|
||||
'bvb64',
|
||||
'bvb64resp',
|
||||
'bvplugname',
|
||||
'bvprms',
|
||||
'bvprmsmac',
|
||||
'bvreqmerge',
|
||||
'cacheburst',
|
||||
'campaign',
|
||||
'campaign_id',
|
||||
'campaign_name',
|
||||
'campid',
|
||||
'catablog-gallery',
|
||||
'channel',
|
||||
'checksum',
|
||||
'ck_subscriber_id',
|
||||
'cmplz_region_redirect',
|
||||
'cmpnid',
|
||||
'cn-reloaded',
|
||||
'code',
|
||||
'comment',
|
||||
'content_ad_widget',
|
||||
'cost',
|
||||
'cr',
|
||||
'crl8_id',
|
||||
'crlt.pid',
|
||||
'crlt_pid',
|
||||
'crrelr',
|
||||
'crtvid',
|
||||
'ct',
|
||||
'cuid',
|
||||
'daksldlkdsadas',
|
||||
'dcc',
|
||||
'dfp',
|
||||
'dm_i',
|
||||
'domain',
|
||||
'dosubmit',
|
||||
'dsp_caid',
|
||||
'dsp_crid',
|
||||
'dsp_insertion_order_id',
|
||||
'dsp_pub_id',
|
||||
'dsp_tracker_token',
|
||||
'dt',
|
||||
'dur',
|
||||
'durs',
|
||||
'e',
|
||||
'ee',
|
||||
'ef_id',
|
||||
'el',
|
||||
'env',
|
||||
'erprint',
|
||||
'et_blog',
|
||||
'exch',
|
||||
'externalid',
|
||||
'fb_action_ids',
|
||||
'fb_action_types',
|
||||
'fb_ad',
|
||||
'fb_source',
|
||||
'fbclid',
|
||||
'fbzunique',
|
||||
'fg-aqp',
|
||||
'fireglass_rsn',
|
||||
'fo',
|
||||
'fp_sid',
|
||||
'fpa',
|
||||
'fref',
|
||||
'fs',
|
||||
'furl',
|
||||
'fwp_lunch_restrictions',
|
||||
'ga_action',
|
||||
'gclid',
|
||||
'gclsrc',
|
||||
'gdffi',
|
||||
'gdfms',
|
||||
'gdftrk',
|
||||
'gf_page',
|
||||
'gidzl',
|
||||
'goal',
|
||||
'gooal',
|
||||
'gpu',
|
||||
'gtVersion',
|
||||
'haibwc',
|
||||
'hash',
|
||||
'hc_location',
|
||||
'hemail',
|
||||
'hid',
|
||||
'highlight',
|
||||
'hl',
|
||||
'home',
|
||||
'hsa_acc',
|
||||
'hsa_ad',
|
||||
'hsa_cam',
|
||||
'hsa_grp',
|
||||
'hsa_kw',
|
||||
'hsa_mt',
|
||||
'hsa_net',
|
||||
'hsa_src',
|
||||
'hsa_tgt',
|
||||
'hsa_ver',
|
||||
'ias_campId',
|
||||
'ias_chanId',
|
||||
'ias_dealId',
|
||||
'ias_dspId',
|
||||
'ias_impId',
|
||||
'ias_placementId',
|
||||
'ias_pubId',
|
||||
'ical',
|
||||
'ict',
|
||||
'ie',
|
||||
'igshid',
|
||||
'im',
|
||||
'ipl',
|
||||
'jw_start',
|
||||
'jwsource',
|
||||
'k',
|
||||
'key1',
|
||||
'key2',
|
||||
'klaviyo',
|
||||
'ksconf',
|
||||
'ksref',
|
||||
'l',
|
||||
'label',
|
||||
'lang',
|
||||
'ldtag_cl',
|
||||
'level1',
|
||||
'level2',
|
||||
'level3',
|
||||
'level4',
|
||||
'limit',
|
||||
'lng',
|
||||
'load_all_comments',
|
||||
'lt',
|
||||
'ltclid',
|
||||
'ltd',
|
||||
'lucky',
|
||||
'm',
|
||||
'm?sales_kw',
|
||||
'matomo_campaign',
|
||||
'matomo_cid',
|
||||
'matomo_content',
|
||||
'matomo_group',
|
||||
'matomo_keyword',
|
||||
'matomo_medium',
|
||||
'matomo_placement',
|
||||
'matomo_source',
|
||||
'max-results',
|
||||
'mc_cid',
|
||||
'mc_eid',
|
||||
'mdrv',
|
||||
'mediaserver',
|
||||
'memset',
|
||||
'mibextid',
|
||||
'mkcid',
|
||||
'mkevt',
|
||||
'mkrid',
|
||||
'mkwid',
|
||||
'ml_subscriber',
|
||||
'ml_subscriber_hash',
|
||||
'mobileOn',
|
||||
'mode',
|
||||
'month',
|
||||
'msID',
|
||||
'msclkid',
|
||||
'msg',
|
||||
'mtm_campaign',
|
||||
'mtm_cid',
|
||||
'mtm_content',
|
||||
'mtm_group',
|
||||
'mtm_keyword',
|
||||
'mtm_medium',
|
||||
'mtm_placement',
|
||||
'mtm_source',
|
||||
'murphybedstoday',
|
||||
'mwprid',
|
||||
'n',
|
||||
'native_client',
|
||||
'navua',
|
||||
'nb',
|
||||
'nb_klid',
|
||||
'o',
|
||||
'okijoouuqnqq',
|
||||
'org',
|
||||
'pa_service_worker',
|
||||
'partnumber',
|
||||
'pcmtid',
|
||||
'pcode',
|
||||
'pcrid',
|
||||
'pfstyle',
|
||||
'phrase',
|
||||
'pid',
|
||||
'piwik_campaign',
|
||||
'piwik_keyword',
|
||||
'piwik_kwd',
|
||||
'pk_campaign',
|
||||
'pk_keyword',
|
||||
'pk_kwd',
|
||||
'placement',
|
||||
'plat',
|
||||
'platform',
|
||||
'playsinline',
|
||||
'pp',
|
||||
'pr',
|
||||
'prid',
|
||||
'print',
|
||||
'q',
|
||||
'q1',
|
||||
'qsrc',
|
||||
'r',
|
||||
'rd',
|
||||
'rdt_cid',
|
||||
'redig',
|
||||
'redir',
|
||||
'ref',
|
||||
'reftok',
|
||||
'relatedposts_hit',
|
||||
'relatedposts_origin',
|
||||
'relatedposts_position',
|
||||
'remodel',
|
||||
'replytocom',
|
||||
'reverse-paginate',
|
||||
'rid',
|
||||
'rnd',
|
||||
'rndnum',
|
||||
'robots_txt',
|
||||
'rq',
|
||||
'rsd',
|
||||
's_kwcid',
|
||||
'sa',
|
||||
'safe',
|
||||
'said',
|
||||
'sales_cat',
|
||||
'sales_kw',
|
||||
'sb_referer_host',
|
||||
'scrape',
|
||||
'script',
|
||||
'scrlybrkr',
|
||||
'search',
|
||||
'sellid',
|
||||
'sersafe',
|
||||
'sfn_data',
|
||||
'sfn_trk',
|
||||
'sfns',
|
||||
'sfw',
|
||||
'sha1',
|
||||
'share',
|
||||
'shared',
|
||||
'showcomment',
|
||||
'si',
|
||||
'sid',
|
||||
'sid1',
|
||||
'sid2',
|
||||
'sidewalkShow',
|
||||
'sig',
|
||||
'site',
|
||||
'site_id',
|
||||
'siteid',
|
||||
'slicer1',
|
||||
'slicer2',
|
||||
'source',
|
||||
'spref',
|
||||
'spvb',
|
||||
'sra',
|
||||
'src',
|
||||
'srk',
|
||||
'srp',
|
||||
'ssp_iabi',
|
||||
'ssts',
|
||||
'stylishmurphybeds',
|
||||
'subId1 ',
|
||||
'subId2 ',
|
||||
'subId3',
|
||||
'subid',
|
||||
'swcfpc',
|
||||
'tail',
|
||||
'teaser',
|
||||
'test',
|
||||
'timezone',
|
||||
'toWww',
|
||||
'triplesource',
|
||||
'trk_contact',
|
||||
'trk_module',
|
||||
'trk_msg',
|
||||
'trk_sid',
|
||||
'tsig',
|
||||
'turl',
|
||||
'u',
|
||||
'up_auto_log',
|
||||
'upage',
|
||||
'updated-max',
|
||||
'uptime',
|
||||
'us_privacy',
|
||||
'usegapi',
|
||||
'usqp',
|
||||
'utm',
|
||||
'utm_campa',
|
||||
'utm_campaign',
|
||||
'utm_content',
|
||||
'utm_expid',
|
||||
'utm_id',
|
||||
'utm_medium',
|
||||
'utm_reader',
|
||||
'utm_referrer',
|
||||
'utm_source',
|
||||
'utm_sq',
|
||||
'utm_ter',
|
||||
'utm_term',
|
||||
'v',
|
||||
'vc',
|
||||
'vf',
|
||||
'vgo_ee',
|
||||
'vp',
|
||||
'vrw',
|
||||
'vz',
|
||||
'wbraid',
|
||||
'webdriver',
|
||||
'wing',
|
||||
'wpdParentID',
|
||||
'wpmp_switcher',
|
||||
'wref',
|
||||
'wswy',
|
||||
'wtime',
|
||||
'x',
|
||||
'zMoatImpID',
|
||||
'zarsrc',
|
||||
'zeffdn'
|
||||
]
|
||||
|
||||
// List of Static File Extensions for which we don't need to run the whole logic
|
||||
// Just fetch them and send the response
|
||||
const STATIC_FILE_EXTENSIONS = [
|
||||
'.jpg', '.jpeg', '.png', '.gif', '.svg', '.webp', '.avif', '.tiff', '.ico', '.3gp', '.wmv', '.avi', '.asf', '.asx', '.mpg', '.mpeg', '.webm', '.ogg', '.ogv', '.mp4', '.mkv', '.pls', '.mp3', '.mid', '.wav', '.swf', '.flv', '.exe', '.zip', '.tar', '.rar', '.gz', '.tgz', '.bz2', '.uha', '.7z', '.doc', '.docx', '.pdf', '.iso', '.test', '.bin', '.js', '.json', '.css', '.eot', '.ttf', '.woff', '.woff2', '.webmanifest'
|
||||
]
|
||||
|
||||
/**
|
||||
* Function to check if the response status code is within the range
|
||||
* of 3XX, 4XX, 5XX and if so, then return TRUE else FALSE
|
||||
*
|
||||
* @param {Response} response - The origin server response
|
||||
* @return {Boolean} has_unusual_response_code - If the response has a status code is
|
||||
* within the defined list then return TRUE else FALSE
|
||||
*/
|
||||
function has_unusual_origin_server_response_code(response) {
|
||||
const responseStatusCode = String( response?.status )
|
||||
|
||||
if( responseStatusCode.startsWith( '3' ) || responseStatusCode.startsWith( '4' ) || responseStatusCode.startsWith( '5' ) ) {
|
||||
response.headers?.set('x-wp-cf-super-cache-worker-origin-response', responseStatusCode)
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to normalize the URL by removing promotional query parameters from the URL and cache the original URL
|
||||
* @param {Object} event - Event Object
|
||||
* @return {URL} reqURL - Request URL without promotional query strings
|
||||
*/
|
||||
function url_normalize(event) {
|
||||
try {
|
||||
// Fetch the Request URL from the event
|
||||
// Parse the URL for better handling
|
||||
const reqURL = new URL(event?.request?.url)
|
||||
|
||||
// Loop through the promo queries (THIRD_PARTY_QUERY_PARAMETERS) and see if we have any of these queries present in the URL, if so remove them
|
||||
for ( let i = 0; i < THIRD_PARTY_QUERY_PARAMETERS.length; i++ ) {
|
||||
|
||||
// Create the REGEX to text the URL with our desired parameters
|
||||
const promoUrlQuery = new RegExp( '(&?)(' + THIRD_PARTY_QUERY_PARAMETERS[i] + '=\\S+)', 'g' )
|
||||
|
||||
// Check if the reqURL.search has these search query parameters
|
||||
if(promoUrlQuery.test( reqURL.search )) {
|
||||
|
||||
// The URL has promo query parameters that we need to remove
|
||||
const urlSearchParams = reqURL.searchParams
|
||||
|
||||
urlSearchParams.delete( THIRD_PARTY_QUERY_PARAMETERS[i] )
|
||||
}
|
||||
}
|
||||
|
||||
return reqURL
|
||||
|
||||
} catch (err) {
|
||||
return {
|
||||
error: true,
|
||||
errorMessage: `URL Handling Error: ${err.message}`,
|
||||
errorStatusCode: 400
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to check if the current request should be BYPASSed or Cached based on exclusion cookies
|
||||
* entered by the user in the plugin settings
|
||||
* @param {String} cookieHeader - The cookie header of the current request
|
||||
* @param {Array} cookies_list - List of cookies which should not be cached
|
||||
* @return {Boolean} blackListedCookieExists - If blacklisted cookie exists in the current request
|
||||
*/
|
||||
function are_blacklisted_cookies(cookieHeader, cookies_list) {
|
||||
let blackListedCookieExists = false
|
||||
|
||||
// Make sure both cookieHeader & cookies_list are defined & the length of both cookieHeader & cookies_list > 0
|
||||
if (
|
||||
cookieHeader?.length > 0 &&
|
||||
cookies_list?.length > 0
|
||||
) {
|
||||
// Split the received request cookie header by semicolon to an Array
|
||||
const cookies = cookieHeader.split(';')
|
||||
|
||||
// Loop through the cookies in the request header and check if there is any cookie present there
|
||||
// which is also mentioned in our bypassed cookies array
|
||||
// if there is then set blackListedCookieExists as true and break out of the loops
|
||||
for ( let i = 0; i < cookies.length; i++ ) {
|
||||
|
||||
for ( let j = 0; j < cookies_list.length; j++ ) {
|
||||
|
||||
if (cookies[i].trim().includes(cookies_list[j].trim())) {
|
||||
blackListedCookieExists = true
|
||||
|
||||
// Found item. Break out from the loop
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Check if blackListedCookieExists is true then break out of this loop. Else continue the loop
|
||||
if( blackListedCookieExists ) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return blackListedCookieExists // value -> TRUE | FALSE
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to add extra response headers for BYPASSed Requests
|
||||
* @param {Response} res - The response object
|
||||
* @param {String} reason - The string that hold the bypass reason
|
||||
*/
|
||||
function add_bypass_custom_headers(res, reason) {
|
||||
if (res && (reason?.length > 0)) {
|
||||
// BYPASS the request and add our custom headers
|
||||
res?.headers?.set('x-wp-cf-super-cache-worker-status', 'bypass')
|
||||
res?.headers?.set('x-wp-cf-super-cache-worker-bypass-reason', reason)
|
||||
res?.headers?.set('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The function that handles the Request
|
||||
* @param {Object} event - Received Event object
|
||||
* @return {Response} response - Response object that is being returned to the user
|
||||
*/
|
||||
async function handleRequest(event) {
|
||||
|
||||
const request = event?.request
|
||||
const requestURL = url_normalize(event)
|
||||
|
||||
// Check if we have received any error in the url_normalize() call, if so return that error message
|
||||
if( requestURL?.error ) {
|
||||
return new Response(
|
||||
requestURL.errorMessage,
|
||||
{ status: requestURL.errorStatusCode, statusText: requestURL.errorMessage }
|
||||
)
|
||||
}
|
||||
|
||||
let response = false
|
||||
let bypassCache = false
|
||||
const bypassReason = {
|
||||
'req_method': false,
|
||||
'admin_req': false,
|
||||
'file_path_ext': false,
|
||||
'page_excluded': false,
|
||||
'file_excluded': false,
|
||||
'cookie': false
|
||||
}
|
||||
let bypassReasonDetails = ''
|
||||
const cookieHeader = request?.headers?.get('cookie')
|
||||
const reqDetails = {
|
||||
'contentTypeHTML': false
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// Check - If the request is for an static file,
|
||||
// then no need to go further, just fetch the file and return
|
||||
// ---------------------------------------------------------
|
||||
const requestPath = requestURL?.pathname
|
||||
let isStaticFile = false
|
||||
|
||||
// Loop through the STATIC_FILE_EXTENSIONS and check if the request path has any of the extensions
|
||||
for ( let i = 0; i < STATIC_FILE_EXTENSIONS.length; i++ ) {
|
||||
if( requestPath.endsWith( STATIC_FILE_EXTENSIONS[i] ) ) {
|
||||
// Set isStaticFile to TRUE and break out of the loop
|
||||
isStaticFile = true
|
||||
|
||||
// Found item. Break out from the loop
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if( isStaticFile ) {
|
||||
let staticFileResponse
|
||||
|
||||
try {
|
||||
staticFileResponse = await fetch(request)
|
||||
} catch (err) {
|
||||
return new Response(
|
||||
`Error: ${err.message}`,
|
||||
{ status: 500, statusText: "Unable to fetch the static file from the origin server" }
|
||||
)
|
||||
}
|
||||
|
||||
return new Response(staticFileResponse?.body, staticFileResponse)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// Check - Bypass Request ? - Only Based on Request Headers
|
||||
// ---------------------------------------------------------
|
||||
|
||||
// 1. BYPASS any requests whose request method is not GET or HEAD
|
||||
const allowedReqMethods = ['GET', 'HEAD']
|
||||
if (!bypassCache && request) {
|
||||
if (!allowedReqMethods.includes(request?.method)) {
|
||||
bypassCache = true
|
||||
bypassReason.req_method = true
|
||||
bypassReasonDetails = `Caching not possible for req method ${request.method}`
|
||||
}
|
||||
}
|
||||
|
||||
// 2. BYPASS the cache for WP Admin HTML Requests & Any File That has /wp-admin/ in it & API endpoints
|
||||
// Get the Accept header of the request being received by the CF Worker
|
||||
const accept = request?.headers?.get('Accept')
|
||||
|
||||
if (!bypassCache && accept) {
|
||||
|
||||
// List of path regex that we will BYPASS caching
|
||||
// Path includes - WP Admin Paths, WP REST API, WooCommerce API, EDD API Endpoints
|
||||
const bypass_admin_path = new RegExp(/(\/(wp-admin)(\/?))/g)
|
||||
const bypass_cache_paths = new RegExp(/(\/((wp-admin)|(wc-api)|(edd-api))(\/?))/g)
|
||||
|
||||
// List of file extensions to be BYPASSed
|
||||
const bypass_file_ext = new RegExp(/\.(xsl|xml)$/)
|
||||
|
||||
// Check if the request is for WP Admin endpoint & accept type includes text/html i.e. the main HTML request
|
||||
if ( accept?.includes('text/html') ) {
|
||||
reqDetails.contentTypeHTML = true
|
||||
}
|
||||
|
||||
// Check if the request URL is an admin URL for HTML type requests
|
||||
if ( reqDetails.contentTypeHTML && bypass_admin_path.test(requestPath) ) {
|
||||
bypassCache = true
|
||||
bypassReason.admin_req = true
|
||||
bypassReasonDetails = 'WP Admin HTML request'
|
||||
|
||||
} else if ( bypass_cache_paths.test(requestPath) || bypass_file_ext.test(requestPath) ) {
|
||||
// This is for files which starts with /wp-admin/ but not supposed to be cached
|
||||
// E.g. /wp-admin/load-styles.php || /wp-admin/admin-ajax.php
|
||||
// Also API endpoints and xml/xsl files to ensure sitemap isn't cached
|
||||
|
||||
bypassCache = true
|
||||
bypassReason.file_path_ext = true
|
||||
bypassReasonDetails = 'Dynamic File'
|
||||
}
|
||||
}
|
||||
|
||||
// 3. BYPASS the cache if DEFAULT_BYPASS_COOKIES is present in the request
|
||||
// AND also only for the HTML type requests
|
||||
if (
|
||||
!bypassCache &&
|
||||
reqDetails.contentTypeHTML &&
|
||||
cookieHeader?.length > 0 &&
|
||||
DEFAULT_BYPASS_COOKIES.length > 0
|
||||
) {
|
||||
|
||||
// Separate the request cookies by semicolon and create an Array
|
||||
const cookies = cookieHeader.split(';')
|
||||
|
||||
// Loop through the cookies Array to see if there is any cookies present that is present in DEFAULT_BYPASS_COOKIES
|
||||
let foundDefaultBypassCookie = false
|
||||
|
||||
for ( let i = 0; i < cookies.length; i++ ) {
|
||||
|
||||
for ( let j = 0; j < DEFAULT_BYPASS_COOKIES.length; j++ ) {
|
||||
|
||||
if ( cookies[i].trim().startsWith( DEFAULT_BYPASS_COOKIES[j].trim() ) ) {
|
||||
bypassCookieName = cookies[i].trim().split('=')
|
||||
bypassCache = true
|
||||
bypassReason.cookie = true
|
||||
bypassReasonDetails = `Default Bypass Cookie [${bypassCookieName[0]}] Present`
|
||||
foundDefaultBypassCookie = true
|
||||
|
||||
// Stop the loop
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Stop the loop if foundDefaultBypassCookie is TRUE else continue
|
||||
if( foundDefaultBypassCookie ) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the Request has been Bypassed so far.
|
||||
* If not, then check if the request exists in CF Edge Cache & if it does, send it
|
||||
* If it does not exists in CF Edge Cache, then check if the request needs to be Bypassed based on the headers
|
||||
* present in the Response.
|
||||
*/
|
||||
if (!bypassCache) { // bypassCache is still FALSE
|
||||
|
||||
// Check if the Request present in the CF Edge Cache
|
||||
const cacheKey = new Request(requestURL, request)
|
||||
const cache = caches?.default // Get global CF cache object for this zone
|
||||
|
||||
// Try to Get this request from this zone's cache
|
||||
try {
|
||||
response = await cache?.match(cacheKey)
|
||||
} catch (err) {
|
||||
return new Response(
|
||||
`Error: ${err.message}`,
|
||||
{ status: 500, statusText: "Unable to fetch cache from Cloudflare" }
|
||||
)
|
||||
}
|
||||
|
||||
if (response) { // Cache is present for this request in the CF Edge. Nothing special needs to be done.
|
||||
|
||||
// This request is already cached in the CF Edge. So, simply create a response and set custom headers
|
||||
response = new Response(response?.body, response)
|
||||
response?.headers?.set('x-wp-cf-super-cache-worker-status', 'hit')
|
||||
|
||||
} else { // Cache not present in CF Edge. Check if Req needs to be Bypassed or Cached based on Response header data
|
||||
|
||||
// Fetch the response of this given request normally without any special parameters
|
||||
// so that we can use the response headers set by the plugin at the server level
|
||||
let fetchedResponse
|
||||
try {
|
||||
fetchedResponse = await fetch(request)
|
||||
} catch(err) {
|
||||
return new Response(
|
||||
`Error: ${err.message}`,
|
||||
{ status: 500, statusText: "Unable to fetch content from the origin server" }
|
||||
)
|
||||
}
|
||||
|
||||
// If the above if check fails that means we have a good response and lets proceed
|
||||
response = new Response(fetchedResponse.body, fetchedResponse)
|
||||
|
||||
// Check if the response has any unusual origin server response code & if so then return the response
|
||||
if( has_unusual_origin_server_response_code(response) ) {
|
||||
return response
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// Check - Bypass Request ? - Based on RESPONSE Headers
|
||||
// ---------------------------------------------------------
|
||||
|
||||
// 4. BYPASS the HTML page requests which are excluded from caching (via WP Admin plugin settings or page level settings)
|
||||
if (
|
||||
!bypassCache &&
|
||||
response?.headers?.get('content-type')?.includes('text/html') &&
|
||||
!response?.headers?.has('x-wp-cf-super-cache-active')
|
||||
) {
|
||||
bypassCache = true
|
||||
bypassReason.page_excluded = true
|
||||
bypassReasonDetails = 'This page is excluded from caching'
|
||||
}
|
||||
|
||||
// 5. BYPASS the static files (non HTML) which has x-wp-cf-super-cache response header set to no-cache
|
||||
if (!bypassCache &&
|
||||
!response?.headers?.get('content-type')?.includes('text/html') &&
|
||||
(response?.headers?.get('x-wp-cf-super-cache') === 'no-cache')
|
||||
) {
|
||||
bypassCache = true
|
||||
bypassReason.file_excluded = true
|
||||
bypassReasonDetails = 'This file is excluded from caching'
|
||||
}
|
||||
|
||||
// 6. BYPASS cache if any custom cookie mentioned by the user in the plugin settings is present in the request
|
||||
// Check only for HTML type requests
|
||||
if (
|
||||
!bypassCache &&
|
||||
cookieHeader?.length > 0 &&
|
||||
response?.headers?.get('content-type')?.includes('text/html') &&
|
||||
response?.headers?.has('x-wp-cf-super-cache-cookies-bypass')
|
||||
) {
|
||||
// Make sure the feature is enabled first
|
||||
if (response?.headers?.get('x-wp-cf-super-cache-cookies-bypass') !== 'swfpc-feature-not-enabled') {
|
||||
|
||||
// Get the list of cookie names entered by the user in the plugin settings
|
||||
let cookies_blacklist = response?.headers?.get('x-wp-cf-super-cache-cookies-bypass')
|
||||
|
||||
if (cookies_blacklist?.length > 0) {
|
||||
|
||||
// Split the received cookie list with | separated and make an Array
|
||||
cookies_blacklist = cookies_blacklist.split('|')
|
||||
|
||||
if (are_blacklisted_cookies(cookieHeader, cookies_blacklist)) {
|
||||
bypassCache = true
|
||||
bypassReason.cookie = true
|
||||
bypassReasonDetails = 'User provided excluded cookies present in request'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------
|
||||
// Check if the request needs to be BYPASSed or Cached
|
||||
//-----------------------------------------------------
|
||||
if (!bypassCache) { // bypassCache is still FALSE. Cache the item in the CF Edge
|
||||
|
||||
// Check if the response status code is not 206 or request method is not HEAD to cache using cache.put(),
|
||||
// as any request with status code === 206 or req.method HEAD cache.put() will not work.
|
||||
// More info: https://developers.cloudflare.com/workers/runtime-apis/cache#put
|
||||
if (response.status !== 206 || request?.method !== 'HEAD') {
|
||||
|
||||
// If the response header has x-wp-cf-super-cache-active overwrite the cache-control header provided by the server value with x-wp-cf-super-cache-active value just to be safe
|
||||
if (response.headers?.has('x-wp-cf-super-cache-active')) {
|
||||
response.headers?.set('Cache-Control', response.headers?.get('x-wp-cf-super-cache-cache-control'))
|
||||
}
|
||||
|
||||
// Set the worker status as miss and put the item in CF cache
|
||||
response.headers?.set('x-wp-cf-super-cache-worker-status', 'miss')
|
||||
|
||||
// Add page in cache using cache.put()
|
||||
try {
|
||||
event.waitUntil( cache.put( cacheKey, response.clone() ) )
|
||||
} catch (err) {
|
||||
return new Response(
|
||||
`Cache Put Error: ${err.message}`,
|
||||
{ status: 500, statusText: `Cache Put Error: ${err.message}` }
|
||||
)
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// Try to fetch this request again with cacheEverything set to TRUE as that is the only way to cache it
|
||||
// More info: https://developers.cloudflare.com/workers/runtime-apis/request#requestinitcfproperties
|
||||
try {
|
||||
response = await fetch(request, { cf: { cacheEverything: true } })
|
||||
} catch (err) {
|
||||
return new Response(
|
||||
`Error: ${err.message}`,
|
||||
{ status: 500, statusText: "Unable to fetch content from the origin server with cacheEverything flag" }
|
||||
)
|
||||
}
|
||||
|
||||
response = new Response(response.body, response)
|
||||
|
||||
// Check if the response has any unusual origin server response code & if so then return the response
|
||||
if( has_unusual_origin_server_response_code(response) ) {
|
||||
return response
|
||||
}
|
||||
|
||||
// Set the worker status as miss and put the item in CF cache
|
||||
response.headers?.set('x-wp-cf-super-cache-worker-status', 'miss')
|
||||
|
||||
}
|
||||
} else { // bypassCache -> TRUE || Bypass the Request
|
||||
|
||||
// BYPASS the request and add our custom headers
|
||||
add_bypass_custom_headers(response, bypassReasonDetails)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else { // bypassCache -> TRUE
|
||||
|
||||
// Fetch the request from the origin server and send it by adding our custom bypass headers
|
||||
let bypassedResponse
|
||||
try {
|
||||
bypassedResponse = await fetch(request)
|
||||
} catch (err) {
|
||||
return new Response(
|
||||
`Error: ${err.message}`,
|
||||
{ status: 500, statusText: "Unable to fetch the bypassed content from the origin server" }
|
||||
)
|
||||
}
|
||||
|
||||
response = new Response(bypassedResponse?.body, bypassedResponse)
|
||||
|
||||
// Check if the response has any unusual origin server response code & if so then return the response
|
||||
if( has_unusual_origin_server_response_code(response) ) {
|
||||
return response
|
||||
}
|
||||
|
||||
// BYPASS the request and add our custom headers
|
||||
add_bypass_custom_headers(response, bypassReasonDetails)
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
/**
|
||||
* Adding event lister to the fetch event to catch the requests and manage them accordingly
|
||||
* @param {Object} event
|
||||
*/
|
||||
addEventListener('fetch', event => {
|
||||
try {
|
||||
return event.respondWith(handleRequest(event))
|
||||
} catch (err) {
|
||||
return event.respondWith(
|
||||
new Response(
|
||||
`Error thrown: ${err.message}`,
|
||||
{ status: 500, statusText: `Error thrown: ${err.message}` }
|
||||
)
|
||||
)
|
||||
}
|
||||
})
|
|
@ -0,0 +1,918 @@
|
|||
<?php
|
||||
/**
|
||||
* The translate model class for ThemeIsle SDK
|
||||
*
|
||||
* @package ThemeIsleSDK
|
||||
* @subpackage Modules
|
||||
* @copyright Copyright (c) 2017, Marius Cristea
|
||||
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace ThemeisleSDK\Modules;
|
||||
|
||||
use ThemeisleSDK\Common\Abstract_Module;
|
||||
use ThemeisleSDK\Product;
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate module for ThemeIsle SDK.
|
||||
*/
|
||||
class Translate extends Abstract_Module {
|
||||
/**
|
||||
* List of available locales.
|
||||
*
|
||||
* @var array Array of available locals.
|
||||
*/
|
||||
private static $locales = array(
|
||||
'af' => array(
|
||||
'slug' => 'af',
|
||||
'name' => 'Afrikaans',
|
||||
),
|
||||
'ak' => array(
|
||||
'slug' => 'ak',
|
||||
'name' => 'Akan',
|
||||
),
|
||||
'am' => array(
|
||||
'slug' => 'am',
|
||||
'name' => 'Amharic',
|
||||
),
|
||||
'ar' => array(
|
||||
'slug' => 'ar',
|
||||
'name' => 'Arabic',
|
||||
),
|
||||
'arq' => array(
|
||||
'slug' => 'arq',
|
||||
'name' => 'Algerian Arabic',
|
||||
),
|
||||
'ary' => array(
|
||||
'slug' => 'ary',
|
||||
'name' => 'Moroccan Arabic',
|
||||
),
|
||||
'as' => array(
|
||||
'slug' => 'as',
|
||||
'name' => 'Assamese',
|
||||
),
|
||||
'ast' => array(
|
||||
'slug' => 'ast',
|
||||
'name' => 'Asturian',
|
||||
),
|
||||
'az' => array(
|
||||
'slug' => 'az',
|
||||
'name' => 'Azerbaijani',
|
||||
),
|
||||
'azb' => array(
|
||||
'slug' => 'azb',
|
||||
'name' => 'South Azerbaijani',
|
||||
),
|
||||
'az_TR' => array(
|
||||
'slug' => 'az-tr',
|
||||
'name' => 'Azerbaijani (Turkey)',
|
||||
),
|
||||
'ba' => array(
|
||||
'slug' => 'ba',
|
||||
'name' => 'Bashkir',
|
||||
),
|
||||
'bal' => array(
|
||||
'slug' => 'bal',
|
||||
'name' => 'Catalan (Balear)',
|
||||
),
|
||||
'bcc' => array(
|
||||
'slug' => 'bcc',
|
||||
'name' => 'Balochi Southern',
|
||||
),
|
||||
'bel' => array(
|
||||
'slug' => 'bel',
|
||||
'name' => 'Belarusian',
|
||||
),
|
||||
'bg_BG' => array(
|
||||
'slug' => 'bg',
|
||||
'name' => 'Bulgarian',
|
||||
),
|
||||
'bn_BD' => array(
|
||||
'slug' => 'bn',
|
||||
'name' => 'Bengali',
|
||||
),
|
||||
'bo' => array(
|
||||
'slug' => 'bo',
|
||||
'name' => 'Tibetan',
|
||||
),
|
||||
'bre' => array(
|
||||
'slug' => 'br',
|
||||
'name' => 'Breton',
|
||||
),
|
||||
'bs_BA' => array(
|
||||
'slug' => 'bs',
|
||||
'name' => 'Bosnian',
|
||||
),
|
||||
'ca' => array(
|
||||
'slug' => 'ca',
|
||||
'name' => 'Catalan',
|
||||
),
|
||||
'ceb' => array(
|
||||
'slug' => 'ceb',
|
||||
'name' => 'Cebuano',
|
||||
),
|
||||
'ckb' => array(
|
||||
'slug' => 'ckb',
|
||||
'name' => 'Kurdish (Sorani)',
|
||||
),
|
||||
'co' => array(
|
||||
'slug' => 'co',
|
||||
'name' => 'Corsican',
|
||||
),
|
||||
'cs_CZ' => array(
|
||||
'slug' => 'cs',
|
||||
'name' => 'Czech',
|
||||
),
|
||||
'cy' => array(
|
||||
'slug' => 'cy',
|
||||
'name' => 'Welsh',
|
||||
),
|
||||
'da_DK' => array(
|
||||
'slug' => 'da',
|
||||
'name' => 'Danish',
|
||||
),
|
||||
'de_DE' => array(
|
||||
'slug' => 'de',
|
||||
'name' => 'German',
|
||||
),
|
||||
'de_CH' => array(
|
||||
'slug' => 'de-ch',
|
||||
'name' => 'German (Switzerland)',
|
||||
),
|
||||
'dv' => array(
|
||||
'slug' => 'dv',
|
||||
'name' => 'Dhivehi',
|
||||
),
|
||||
'dzo' => array(
|
||||
'slug' => 'dzo',
|
||||
'name' => 'Dzongkha',
|
||||
),
|
||||
'el' => array(
|
||||
'slug' => 'el',
|
||||
'name' => 'Greek',
|
||||
),
|
||||
'art_xemoji' => array(
|
||||
'slug' => 'art-xemoji',
|
||||
'name' => 'Emoji',
|
||||
),
|
||||
'en_US' => array(
|
||||
'slug' => 'en',
|
||||
'name' => 'English',
|
||||
),
|
||||
'en_AU' => array(
|
||||
'slug' => 'en-au',
|
||||
'name' => 'English (Australia)',
|
||||
),
|
||||
'en_CA' => array(
|
||||
'slug' => 'en-ca',
|
||||
'name' => 'English (Canada)',
|
||||
),
|
||||
'en_GB' => array(
|
||||
'slug' => 'en-gb',
|
||||
'name' => 'English (UK)',
|
||||
),
|
||||
'en_NZ' => array(
|
||||
'slug' => 'en-nz',
|
||||
'name' => 'English (New Zealand)',
|
||||
),
|
||||
'en_ZA' => array(
|
||||
'slug' => 'en-za',
|
||||
'name' => 'English (South Africa)',
|
||||
),
|
||||
'eo' => array(
|
||||
'slug' => 'eo',
|
||||
'name' => 'Esperanto',
|
||||
),
|
||||
'es_ES' => array(
|
||||
'slug' => 'es',
|
||||
'name' => 'Spanish (Spain)',
|
||||
),
|
||||
'es_AR' => array(
|
||||
'slug' => 'es-ar',
|
||||
'name' => 'Spanish (Argentina)',
|
||||
),
|
||||
'es_CL' => array(
|
||||
'slug' => 'es-cl',
|
||||
'name' => 'Spanish (Chile)',
|
||||
),
|
||||
'es_CO' => array(
|
||||
'slug' => 'es-co',
|
||||
'name' => 'Spanish (Colombia)',
|
||||
),
|
||||
'es_CR' => array(
|
||||
'slug' => 'es-cr',
|
||||
'name' => 'Spanish (Costa Rica)',
|
||||
),
|
||||
'es_GT' => array(
|
||||
'slug' => 'es-gt',
|
||||
'name' => 'Spanish (Guatemala)',
|
||||
),
|
||||
'es_MX' => array(
|
||||
'slug' => 'es-mx',
|
||||
'name' => 'Spanish (Mexico)',
|
||||
),
|
||||
'es_PE' => array(
|
||||
'slug' => 'es-pe',
|
||||
'name' => 'Spanish (Peru)',
|
||||
),
|
||||
'es_PR' => array(
|
||||
'slug' => 'es-pr',
|
||||
'name' => 'Spanish (Puerto Rico)',
|
||||
),
|
||||
'es_VE' => array(
|
||||
'slug' => 'es-ve',
|
||||
'name' => 'Spanish (Venezuela)',
|
||||
),
|
||||
'et' => array(
|
||||
'slug' => 'et',
|
||||
'name' => 'Estonian',
|
||||
),
|
||||
'eu' => array(
|
||||
'slug' => 'eu',
|
||||
'name' => 'Basque',
|
||||
),
|
||||
'fa_IR' => array(
|
||||
'slug' => 'fa',
|
||||
'name' => 'Persian',
|
||||
),
|
||||
'fa_AF' => array(
|
||||
'slug' => 'fa-af',
|
||||
'name' => 'Persian (Afghanistan)',
|
||||
),
|
||||
'fuc' => array(
|
||||
'slug' => 'fuc',
|
||||
'name' => 'Fulah',
|
||||
),
|
||||
'fi' => array(
|
||||
'slug' => 'fi',
|
||||
'name' => 'Finnish',
|
||||
),
|
||||
'fo' => array(
|
||||
'slug' => 'fo',
|
||||
'name' => 'Faroese',
|
||||
),
|
||||
'fr_FR' => array(
|
||||
'slug' => 'fr',
|
||||
'name' => 'French (France)',
|
||||
),
|
||||
'fr_BE' => array(
|
||||
'slug' => 'fr-be',
|
||||
'name' => 'French (Belgium)',
|
||||
),
|
||||
'fr_CA' => array(
|
||||
'slug' => 'fr-ca',
|
||||
'name' => 'French (Canada)',
|
||||
),
|
||||
'frp' => array(
|
||||
'slug' => 'frp',
|
||||
'name' => 'Arpitan',
|
||||
),
|
||||
'fur' => array(
|
||||
'slug' => 'fur',
|
||||
'name' => 'Friulian',
|
||||
),
|
||||
'fy' => array(
|
||||
'slug' => 'fy',
|
||||
'name' => 'Frisian',
|
||||
),
|
||||
'ga' => array(
|
||||
'slug' => 'ga',
|
||||
'name' => 'Irish',
|
||||
),
|
||||
'gd' => array(
|
||||
'slug' => 'gd',
|
||||
'name' => 'Scottish Gaelic',
|
||||
),
|
||||
'gl_ES' => array(
|
||||
'slug' => 'gl',
|
||||
'name' => 'Galician',
|
||||
),
|
||||
'gn' => array(
|
||||
'slug' => 'gn',
|
||||
'name' => 'Guarani',
|
||||
),
|
||||
'gsw' => array(
|
||||
'slug' => 'gsw',
|
||||
'name' => 'Swiss German',
|
||||
),
|
||||
'gu' => array(
|
||||
'slug' => 'gu',
|
||||
'name' => 'Gujarati',
|
||||
),
|
||||
'hat' => array(
|
||||
'slug' => 'hat',
|
||||
'name' => 'Haitian Creole',
|
||||
),
|
||||
'hau' => array(
|
||||
'slug' => 'hau',
|
||||
'name' => 'Hausa',
|
||||
),
|
||||
'haw_US' => array(
|
||||
'slug' => 'haw',
|
||||
'name' => 'Hawaiian',
|
||||
),
|
||||
'haz' => array(
|
||||
'slug' => 'haz',
|
||||
'name' => 'Hazaragi',
|
||||
),
|
||||
'he_IL' => array(
|
||||
'slug' => 'he',
|
||||
'name' => 'Hebrew',
|
||||
),
|
||||
'hi_IN' => array(
|
||||
'slug' => 'hi',
|
||||
'name' => 'Hindi',
|
||||
),
|
||||
'hr' => array(
|
||||
'slug' => 'hr',
|
||||
'name' => 'Croatian',
|
||||
),
|
||||
'hu_HU' => array(
|
||||
'slug' => 'hu',
|
||||
'name' => 'Hungarian',
|
||||
),
|
||||
'hy' => array(
|
||||
'slug' => 'hy',
|
||||
'name' => 'Armenian',
|
||||
),
|
||||
'id_ID' => array(
|
||||
'slug' => 'id',
|
||||
'name' => 'Indonesian',
|
||||
),
|
||||
'ido' => array(
|
||||
'slug' => 'ido',
|
||||
'name' => 'Ido',
|
||||
),
|
||||
'is_IS' => array(
|
||||
'slug' => 'is',
|
||||
'name' => 'Icelandic',
|
||||
),
|
||||
'it_IT' => array(
|
||||
'slug' => 'it',
|
||||
'name' => 'Italian',
|
||||
),
|
||||
'ja' => array(
|
||||
'slug' => 'ja',
|
||||
'name' => 'Japanese',
|
||||
),
|
||||
'jv_ID' => array(
|
||||
'slug' => 'jv',
|
||||
'name' => 'Javanese',
|
||||
),
|
||||
'ka_GE' => array(
|
||||
'slug' => 'ka',
|
||||
'name' => 'Georgian',
|
||||
),
|
||||
'kab' => array(
|
||||
'slug' => 'kab',
|
||||
'name' => 'Kabyle',
|
||||
),
|
||||
'kal' => array(
|
||||
'slug' => 'kal',
|
||||
'name' => 'Greenlandic',
|
||||
),
|
||||
'kin' => array(
|
||||
'slug' => 'kin',
|
||||
'name' => 'Kinyarwanda',
|
||||
),
|
||||
'kk' => array(
|
||||
'slug' => 'kk',
|
||||
'name' => 'Kazakh',
|
||||
),
|
||||
'km' => array(
|
||||
'slug' => 'km',
|
||||
'name' => 'Khmer',
|
||||
),
|
||||
'kn' => array(
|
||||
'slug' => 'kn',
|
||||
'name' => 'Kannada',
|
||||
),
|
||||
'ko_KR' => array(
|
||||
'slug' => 'ko',
|
||||
'name' => 'Korean',
|
||||
),
|
||||
'kir' => array(
|
||||
'slug' => 'kir',
|
||||
'name' => 'Kyrgyz',
|
||||
),
|
||||
'lb_LU' => array(
|
||||
'slug' => 'lb',
|
||||
'name' => 'Luxembourgish',
|
||||
),
|
||||
'li' => array(
|
||||
'slug' => 'li',
|
||||
'name' => 'Limburgish',
|
||||
),
|
||||
'lin' => array(
|
||||
'slug' => 'lin',
|
||||
'name' => 'Lingala',
|
||||
),
|
||||
'lo' => array(
|
||||
'slug' => 'lo',
|
||||
'name' => 'Lao',
|
||||
),
|
||||
'lt_LT' => array(
|
||||
'slug' => 'lt',
|
||||
'name' => 'Lithuanian',
|
||||
),
|
||||
'lv' => array(
|
||||
'slug' => 'lv',
|
||||
'name' => 'Latvian',
|
||||
),
|
||||
'me_ME' => array(
|
||||
'slug' => 'me',
|
||||
'name' => 'Montenegrin',
|
||||
),
|
||||
'mg_MG' => array(
|
||||
'slug' => 'mg',
|
||||
'name' => 'Malagasy',
|
||||
),
|
||||
'mk_MK' => array(
|
||||
'slug' => 'mk',
|
||||
'name' => 'Macedonian',
|
||||
),
|
||||
'ml_IN' => array(
|
||||
'slug' => 'ml',
|
||||
'name' => 'Malayalam',
|
||||
),
|
||||
'mlt' => array(
|
||||
'slug' => 'mlt',
|
||||
'name' => 'Maltese',
|
||||
),
|
||||
'mn' => array(
|
||||
'slug' => 'mn',
|
||||
'name' => 'Mongolian',
|
||||
),
|
||||
'mr' => array(
|
||||
'slug' => 'mr',
|
||||
'name' => 'Marathi',
|
||||
),
|
||||
'mri' => array(
|
||||
'slug' => 'mri',
|
||||
'name' => 'Maori',
|
||||
),
|
||||
'ms_MY' => array(
|
||||
'slug' => 'ms',
|
||||
'name' => 'Malay',
|
||||
),
|
||||
'my_MM' => array(
|
||||
'slug' => 'mya',
|
||||
'name' => 'Myanmar (Burmese)',
|
||||
),
|
||||
'ne_NP' => array(
|
||||
'slug' => 'ne',
|
||||
'name' => 'Nepali',
|
||||
),
|
||||
'nb_NO' => array(
|
||||
'slug' => 'nb',
|
||||
'name' => 'Norwegian (Bokmal)',
|
||||
),
|
||||
'nl_NL' => array(
|
||||
'slug' => 'nl',
|
||||
'name' => 'Dutch',
|
||||
),
|
||||
'nl_BE' => array(
|
||||
'slug' => 'nl-be',
|
||||
'name' => 'Dutch (Belgium)',
|
||||
),
|
||||
'nn_NO' => array(
|
||||
'slug' => 'nn',
|
||||
'name' => 'Norwegian (Nynorsk)',
|
||||
),
|
||||
'oci' => array(
|
||||
'slug' => 'oci',
|
||||
'name' => 'Occitan',
|
||||
),
|
||||
'ory' => array(
|
||||
'slug' => 'ory',
|
||||
'name' => 'Oriya',
|
||||
),
|
||||
'os' => array(
|
||||
'slug' => 'os',
|
||||
'name' => 'Ossetic',
|
||||
),
|
||||
'pa_IN' => array(
|
||||
'slug' => 'pa',
|
||||
'name' => 'Punjabi',
|
||||
),
|
||||
'pl_PL' => array(
|
||||
'slug' => 'pl',
|
||||
'name' => 'Polish',
|
||||
),
|
||||
'pt_BR' => array(
|
||||
'slug' => 'pt-br',
|
||||
'name' => 'Portuguese (Brazil)',
|
||||
),
|
||||
'pt_PT' => array(
|
||||
'slug' => 'pt',
|
||||
'name' => 'Portuguese (Portugal)',
|
||||
),
|
||||
'ps' => array(
|
||||
'slug' => 'ps',
|
||||
'name' => 'Pashto',
|
||||
),
|
||||
'rhg' => array(
|
||||
'slug' => 'rhg',
|
||||
'name' => 'Rohingya',
|
||||
),
|
||||
'ro_RO' => array(
|
||||
'slug' => 'ro',
|
||||
'name' => 'Romanian',
|
||||
),
|
||||
'roh' => array(
|
||||
'slug' => 'roh',
|
||||
'name' => 'Romansh',
|
||||
),
|
||||
'ru_RU' => array(
|
||||
'slug' => 'ru',
|
||||
'name' => 'Russian',
|
||||
),
|
||||
'rue' => array(
|
||||
'slug' => 'rue',
|
||||
'name' => 'Rusyn',
|
||||
),
|
||||
'rup_MK' => array(
|
||||
'slug' => 'rup',
|
||||
'name' => 'Aromanian',
|
||||
),
|
||||
'sah' => array(
|
||||
'slug' => 'sah',
|
||||
'name' => 'Sakha',
|
||||
),
|
||||
'sa_IN' => array(
|
||||
'slug' => 'sa-in',
|
||||
'name' => 'Sanskrit',
|
||||
),
|
||||
'scn' => array(
|
||||
'slug' => 'scn',
|
||||
'name' => 'Sicilian',
|
||||
),
|
||||
'si_LK' => array(
|
||||
'slug' => 'si',
|
||||
'name' => 'Sinhala',
|
||||
),
|
||||
'sk_SK' => array(
|
||||
'slug' => 'sk',
|
||||
'name' => 'Slovak',
|
||||
),
|
||||
'sl_SI' => array(
|
||||
'slug' => 'sl',
|
||||
'name' => 'Slovenian',
|
||||
),
|
||||
'sna' => array(
|
||||
'slug' => 'sna',
|
||||
'name' => 'Shona',
|
||||
),
|
||||
'snd' => array(
|
||||
'slug' => 'snd',
|
||||
'name' => 'Sindhi',
|
||||
),
|
||||
'so_SO' => array(
|
||||
'slug' => 'so',
|
||||
'name' => 'Somali',
|
||||
),
|
||||
'sq' => array(
|
||||
'slug' => 'sq',
|
||||
'name' => 'Albanian',
|
||||
),
|
||||
'sq_XK' => array(
|
||||
'slug' => 'sq-xk',
|
||||
'name' => 'Shqip (Kosovo)',
|
||||
),
|
||||
'sr_RS' => array(
|
||||
'slug' => 'sr',
|
||||
'name' => 'Serbian',
|
||||
),
|
||||
'srd' => array(
|
||||
'slug' => 'srd',
|
||||
'name' => 'Sardinian',
|
||||
),
|
||||
'su_ID' => array(
|
||||
'slug' => 'su',
|
||||
'name' => 'Sundanese',
|
||||
),
|
||||
'sv_SE' => array(
|
||||
'slug' => 'sv',
|
||||
'name' => 'Swedish',
|
||||
),
|
||||
'sw' => array(
|
||||
'slug' => 'sw',
|
||||
'name' => 'Swahili',
|
||||
),
|
||||
'syr' => array(
|
||||
'slug' => 'syr',
|
||||
'name' => 'Syriac',
|
||||
),
|
||||
'szl' => array(
|
||||
'slug' => 'szl',
|
||||
'name' => 'Silesian',
|
||||
),
|
||||
'ta_IN' => array(
|
||||
'slug' => 'ta',
|
||||
'name' => 'Tamil',
|
||||
),
|
||||
'ta_LK' => array(
|
||||
'slug' => 'ta-lk',
|
||||
'name' => 'Tamil (Sri Lanka)',
|
||||
),
|
||||
'tah' => array(
|
||||
'slug' => 'tah',
|
||||
'name' => 'Tahitian',
|
||||
),
|
||||
'te' => array(
|
||||
'slug' => 'te',
|
||||
'name' => 'Telugu',
|
||||
),
|
||||
'tg' => array(
|
||||
'slug' => 'tg',
|
||||
'name' => 'Tajik',
|
||||
),
|
||||
'th' => array(
|
||||
'slug' => 'th',
|
||||
'name' => 'Thai',
|
||||
),
|
||||
'tir' => array(
|
||||
'slug' => 'tir',
|
||||
'name' => 'Tigrinya',
|
||||
),
|
||||
'tl' => array(
|
||||
'slug' => 'tl',
|
||||
'name' => 'Tagalog',
|
||||
),
|
||||
'tr_TR' => array(
|
||||
'slug' => 'tr',
|
||||
'name' => 'Turkish',
|
||||
),
|
||||
'tt_RU' => array(
|
||||
'slug' => 'tt',
|
||||
'name' => 'Tatar',
|
||||
),
|
||||
'tuk' => array(
|
||||
'slug' => 'tuk',
|
||||
'name' => 'Turkmen',
|
||||
),
|
||||
'twd' => array(
|
||||
'slug' => 'twd',
|
||||
'name' => 'Tweants',
|
||||
),
|
||||
'tzm' => array(
|
||||
'slug' => 'tzm',
|
||||
'name' => 'Tamazight (Central Atlas)',
|
||||
),
|
||||
'ug_CN' => array(
|
||||
'slug' => 'ug',
|
||||
'name' => 'Uighur',
|
||||
),
|
||||
'uk' => array(
|
||||
'slug' => 'uk',
|
||||
'name' => 'Ukrainian',
|
||||
),
|
||||
'ur' => array(
|
||||
'slug' => 'ur',
|
||||
'name' => 'Urdu',
|
||||
),
|
||||
'uz_UZ' => array(
|
||||
'slug' => 'uz',
|
||||
'name' => 'Uzbek',
|
||||
),
|
||||
'vi' => array(
|
||||
'slug' => 'vi',
|
||||
'name' => 'Vietnamese',
|
||||
),
|
||||
'wa' => array(
|
||||
'slug' => 'wa',
|
||||
'name' => 'Walloon',
|
||||
),
|
||||
'xho' => array(
|
||||
'slug' => 'xho',
|
||||
'name' => 'Xhosa',
|
||||
),
|
||||
'xmf' => array(
|
||||
'slug' => 'xmf',
|
||||
'name' => 'Mingrelian',
|
||||
),
|
||||
'yor' => array(
|
||||
'slug' => 'yor',
|
||||
'name' => 'Yoruba',
|
||||
),
|
||||
'zh_CN' => array(
|
||||
'slug' => 'zh-cn',
|
||||
'name' => 'Chinese (China)',
|
||||
),
|
||||
'zh_HK' => array(
|
||||
'slug' => 'zh-hk',
|
||||
'name' => 'Chinese (Hong Kong)',
|
||||
),
|
||||
'zh_TW' => array(
|
||||
'slug' => 'zh-tw',
|
||||
'name' => 'Chinese (Taiwan)',
|
||||
),
|
||||
'de_DE_formal' => array(
|
||||
'slug' => 'de/formal',
|
||||
'name' => 'German (Formal)',
|
||||
),
|
||||
'nl_NL_formal' => array(
|
||||
'slug' => 'nl/formal',
|
||||
'name' => 'Dutch (Formal)',
|
||||
),
|
||||
'de_CH_informal' => array(
|
||||
'slug' => 'de-ch/informal',
|
||||
'name' => 'Chinese (Taiwan)',
|
||||
),
|
||||
'pt_PT_ao90' => array(
|
||||
'slug' => 'pt/ao90',
|
||||
'name' => 'Portuguese (Portugal, AO90)',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Check if we should load module for this.
|
||||
*
|
||||
* @param Product $product Product to check.
|
||||
*
|
||||
* @return bool Should load ?
|
||||
*/
|
||||
public function can_load( $product ) {
|
||||
if ( $this->is_from_partner( $product ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( ! $product->is_wordpress_available() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$lang = $this->get_user_locale();
|
||||
|
||||
if ( 'en_US' === $lang ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$languages = $this->get_translations( $product );
|
||||
|
||||
if ( ! is_array( $languages ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! isset( $languages['translations'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$languages = $languages['translations'];
|
||||
|
||||
$available = wp_list_pluck( $languages, 'language' );
|
||||
|
||||
if ( in_array( $lang, $available ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! isset( self::$locales[ $lang ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return apply_filters( $product->get_slug() . '_sdk_enable_translate', true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user's locale.
|
||||
*/
|
||||
private function get_user_locale() {
|
||||
global $wp_version;
|
||||
if ( version_compare( $wp_version, '4.7.0', '>=' ) ) {
|
||||
return get_user_locale();
|
||||
}
|
||||
$user = wp_get_current_user();
|
||||
if ( $user ) {
|
||||
$locale = $user->locale;
|
||||
}
|
||||
|
||||
return $locale ? $locale : get_locale();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch translations from api.
|
||||
*
|
||||
* @param Product $product Product to check.
|
||||
*
|
||||
* @return mixed Translation array.
|
||||
*/
|
||||
private function get_translations( $product ) {
|
||||
$cache_key = $product->get_key() . '_all_languages';
|
||||
$translations = get_transient( $cache_key );
|
||||
|
||||
if ( false === $translations ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
|
||||
$translations = translations_api(
|
||||
$product->get_type() . 's',
|
||||
array(
|
||||
'slug' => $product->get_slug(),
|
||||
'version' => $product->get_version(),
|
||||
)
|
||||
);
|
||||
set_transient( $cache_key, $translations, WEEK_IN_SECONDS );
|
||||
}
|
||||
|
||||
return $translations;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add notification to queue.
|
||||
*
|
||||
* @param array $all_notifications Previous notification.
|
||||
*
|
||||
* @return array All notifications.
|
||||
*/
|
||||
public function add_notification( $all_notifications ) {
|
||||
|
||||
$lang = $this->get_user_locale();
|
||||
$link = $this->get_locale_paths( $lang );
|
||||
$language_meta = self::$locales[ $lang ];
|
||||
|
||||
$heading = apply_filters( $this->product->get_key() . '_feedback_translate_heading', 'Improve {product}' );
|
||||
$heading = str_replace(
|
||||
array( '{product}' ),
|
||||
$this->product->get_friendly_name(),
|
||||
$heading
|
||||
);
|
||||
$message = apply_filters(
|
||||
$this->product->get_key() . '_feedback_translation',
|
||||
'Translating <b>{product}</b> into as many languages as possible is a huge project. We still need help with a lot of them, so if you are good at translating into <b>{language}</b>, it would be greatly appreciated.
|
||||
The process is easy, and you can join by following the link below!'
|
||||
);
|
||||
|
||||
$message = str_replace(
|
||||
[ '{product}', '{language}' ],
|
||||
[
|
||||
$this->product->get_friendly_name(),
|
||||
$language_meta['name'],
|
||||
],
|
||||
$message
|
||||
);
|
||||
|
||||
$button_submit = apply_filters( $this->product->get_key() . '_feedback_translate_button_do', 'Ok, I will gladly help.' );
|
||||
$button_cancel = apply_filters( $this->product->get_key() . '_feedback_translate_button_cancel', 'No, thanks.' );
|
||||
|
||||
$all_notifications[] = [
|
||||
'id' => $this->product->get_key() . '_translate_flag',
|
||||
'heading' => $heading,
|
||||
'message' => $message,
|
||||
'ctas' => [
|
||||
'confirm' => [
|
||||
'link' => $link,
|
||||
'text' => $button_submit,
|
||||
],
|
||||
'cancel' => [
|
||||
'link' => '#',
|
||||
'text' => $button_cancel,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return $all_notifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the locale path.
|
||||
*
|
||||
* @param string $locale Locale code.
|
||||
*
|
||||
* @return string Locale path.
|
||||
*/
|
||||
private function get_locale_paths( $locale ) {
|
||||
if ( empty( $locale ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$slug = isset( self::$locales[ $locale ] ) ? self::$locales[ $locale ]['slug'] : '';
|
||||
if ( empty( $slug ) ) {
|
||||
return '';
|
||||
}
|
||||
if ( strpos( $slug, '/' ) === false ) {
|
||||
$slug .= '/default';
|
||||
}
|
||||
$url = 'https://translate.wordpress.org/projects/wp-' . $this->product->get_type() . 's/' . $this->product->get_slug() . '/' . ( $this->product->get_type() === 'plugin' ? 'dev/' : '' ) . $slug . '?filters%5Bstatus%5D=untranslated&sort%5Bby%5D=random';
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load module logic.
|
||||
*
|
||||
* @param Product $product Product to load.
|
||||
*
|
||||
* @return Translate Module instance.
|
||||
*/
|
||||
public function load( $product ) {
|
||||
|
||||
$this->product = $product;
|
||||
|
||||
add_filter( 'themeisle_sdk_registered_notifications', [ $this, 'add_notification' ] );
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,221 @@
|
|||
<?php
|
||||
/**
|
||||
* The abstract class for module definition.
|
||||
*
|
||||
* @package ThemeIsleSDK
|
||||
* @subpackage Loader
|
||||
* @copyright Copyright (c) 2017, Marius Cristea
|
||||
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
namespace ThemeisleSDK\Common;
|
||||
|
||||
use ThemeisleSDK\Product;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Abstract_Module.
|
||||
*
|
||||
* @package ThemeisleSDK\Common
|
||||
*/
|
||||
abstract class Abstract_Module {
|
||||
/**
|
||||
* Plugin paths.
|
||||
*
|
||||
* @var string[] $plugin_paths Plugin paths.
|
||||
*/
|
||||
private $plugin_paths = [
|
||||
'otter-blocks' => 'otter-blocks/otter-blocks.php',
|
||||
'optimole-wp' => 'optimole-wp/optimole-wp.php',
|
||||
'tweet-old-post' => 'tweet-old-post/tweet-old-post.php',
|
||||
'feedzy-rss-feeds' => 'feedzy-rss-feeds/feedzy-rss-feed.php',
|
||||
'woocommerce-product-addon' => 'woocommerce-product-addon/woocommerce-product-addon.php',
|
||||
'visualizer' => 'visualizer/index.php',
|
||||
'wp-landing-kit' => 'wp-landing-kit/wp-landing-kit.php',
|
||||
'multiple-pages-generator-by-porthas' => 'multiple-pages-generator-by-porthas/porthas-multi-pages-generator.php',
|
||||
'sparks-for-woocommerce' => 'sparks-for-woocommerce/sparks-for-woocommerce.php',
|
||||
'templates-patterns-collection' => 'templates-patterns-collection/templates-patterns-collection.php',
|
||||
];
|
||||
|
||||
/**
|
||||
* Product which use the module.
|
||||
*
|
||||
* @var Product $product Product object.
|
||||
*/
|
||||
protected $product = null;
|
||||
|
||||
/**
|
||||
* Can load the module for the selected product.
|
||||
*
|
||||
* @param Product $product Product data.
|
||||
*
|
||||
* @return bool Should load module?
|
||||
*/
|
||||
abstract public function can_load( $product );
|
||||
|
||||
/**
|
||||
* Bootstrap the module.
|
||||
*
|
||||
* @param Product $product Product object.
|
||||
*/
|
||||
abstract public function load( $product );
|
||||
|
||||
/**
|
||||
* Check if the product is from partner.
|
||||
*
|
||||
* @param Product $product Product data.
|
||||
*
|
||||
* @return bool Is product from partner.
|
||||
*/
|
||||
public function is_from_partner( $product ) {
|
||||
foreach ( Module_Factory::$domains as $partner_domain ) {
|
||||
if ( strpos( $product->get_store_url(), $partner_domain ) !== false ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return array_key_exists( $product->get_slug(), Module_Factory::$slugs );
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for wp_remote_get on VIP environments.
|
||||
*
|
||||
* @param string $url Url to check.
|
||||
* @param array $args Option params.
|
||||
*
|
||||
* @return array|\WP_Error
|
||||
*/
|
||||
public function safe_get( $url, $args = array() ) {
|
||||
return function_exists( 'vip_safe_wp_remote_get' )
|
||||
? vip_safe_wp_remote_get( $url )
|
||||
: wp_remote_get( //phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get, Already used.
|
||||
$url,
|
||||
$args
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SDK base url.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_sdk_uri() {
|
||||
global $themeisle_sdk_max_path;
|
||||
|
||||
/**
|
||||
* $themeisle_sdk_max_path can point to the theme when the theme version is higher.
|
||||
* hence we also need to check that the path does not point to the theme else this will break the URL.
|
||||
* References: https://github.com/Codeinwp/neve-pro-addon/issues/2403
|
||||
*/
|
||||
if ( $this->product->is_plugin() && false === strpos( $themeisle_sdk_max_path, get_template_directory() ) ) {
|
||||
return plugins_url( '/', $themeisle_sdk_max_path . '/themeisle-sdk/' );
|
||||
};
|
||||
|
||||
return get_template_directory_uri() . '/vendor/codeinwp/themeisle-sdk/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Call plugin api
|
||||
*
|
||||
* @param string $slug plugin slug.
|
||||
*
|
||||
* @return array|mixed|object
|
||||
*/
|
||||
public function call_plugin_api( $slug ) {
|
||||
include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
|
||||
|
||||
$call_api = get_transient( 'ti_plugin_info_' . $slug );
|
||||
|
||||
if ( false === $call_api ) {
|
||||
$call_api = plugins_api(
|
||||
'plugin_information',
|
||||
array(
|
||||
'slug' => $slug,
|
||||
'fields' => array(
|
||||
'downloaded' => false,
|
||||
'rating' => false,
|
||||
'description' => false,
|
||||
'short_description' => true,
|
||||
'donate_link' => false,
|
||||
'tags' => false,
|
||||
'sections' => true,
|
||||
'homepage' => true,
|
||||
'added' => false,
|
||||
'last_updated' => false,
|
||||
'compatibility' => false,
|
||||
'tested' => false,
|
||||
'requires' => false,
|
||||
'downloadlink' => false,
|
||||
'icons' => true,
|
||||
'banners' => true,
|
||||
),
|
||||
)
|
||||
);
|
||||
set_transient( 'ti_plugin_info_' . $slug, $call_api, 30 * MINUTE_IN_SECONDS );
|
||||
}
|
||||
|
||||
return $call_api;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plugin status.
|
||||
*
|
||||
* @param string $plugin Plugin slug.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_plugin_installed( $plugin ) {
|
||||
if ( ! isset( $this->plugin_paths[ $plugin ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( file_exists( WP_CONTENT_DIR . '/plugins/' . $this->plugin_paths[ $plugin ] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plugin activation link.
|
||||
*
|
||||
* @param string $slug The plugin slug.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_plugin_activation_link( $slug ) {
|
||||
$reference_key = $slug === 'otter-blocks' ? 'reference_key' : 'optimole_reference_key';
|
||||
$plugin = isset( $this->plugin_paths[ $slug ] ) ? $this->plugin_paths[ $slug ] : $slug . '/' . $slug . '.php';
|
||||
|
||||
return add_query_arg(
|
||||
array(
|
||||
'plugin_status' => 'all',
|
||||
'paged' => '1',
|
||||
'action' => 'activate',
|
||||
$reference_key => $this->product->get_key(),
|
||||
'plugin' => rawurlencode( $plugin ),
|
||||
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $plugin ),
|
||||
),
|
||||
admin_url( 'plugins.php' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a plugin is active.
|
||||
*
|
||||
* @param string $plugin plugin slug.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_plugin_active( $plugin ) {
|
||||
include_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
|
||||
$plugin = isset( $this->plugin_paths[ $plugin ] ) ? $this->plugin_paths[ $plugin ] : $plugin . '/' . $plugin . '.php';
|
||||
|
||||
return is_plugin_active( $plugin );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="robots" content="noindex">
|
||||
<title>This is a Test Page</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Test cache WP Cloudflare Super Page Cache</h1>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
|
||||
|
||||
if( class_exists('WP_Background_Process') ) {
|
||||
|
||||
class SWCFPC_Preloader_Process extends WP_Background_Process
|
||||
{
|
||||
|
||||
protected $action = 'swcfpc_cache_preloader_background_process';
|
||||
private $main_instance = null;
|
||||
|
||||
function __construct( $main_instance )
|
||||
{
|
||||
|
||||
$this->main_instance = $main_instance;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
protected function task($item)
|
||||
{
|
||||
|
||||
$objects = $this->main_instance->get_objects();
|
||||
|
||||
if( !isset($item['url']) ) {
|
||||
$objects['logs']->add_log( 'preloader::task', 'Unable to find a valid URL to preload. Exit.' );
|
||||
return false;
|
||||
}
|
||||
|
||||
$objects['logs']->add_log( 'preloader::task', 'Preloading URL '.esc_url_raw( $item['url'] ) );
|
||||
|
||||
$args = array(
|
||||
'timeout' => defined('SWCFPC_CURL_TIMEOUT') ? SWCFPC_CURL_TIMEOUT : 10,
|
||||
'blocking' => true,
|
||||
'user-agent' => 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0',
|
||||
'sslverify' => false,
|
||||
'headers' => array(
|
||||
'Accept' => 'text/html'
|
||||
)
|
||||
);
|
||||
|
||||
$response = wp_remote_get( esc_url_raw( $item['url'] ), $args );
|
||||
|
||||
//$objects['logs']->add_log( 'preloader::task', 'Response headers for URL '.esc_url_raw( $item['url'] ).': '.print_r( wp_remote_retrieve_headers($response), true) );
|
||||
|
||||
// Sleep 2 seconds before to remove the item from queue and preload next url
|
||||
sleep(2);
|
||||
|
||||
// Return false to remove item from the queue. If not, the process enter in loop
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
protected function complete()
|
||||
{
|
||||
|
||||
$objects = $this->main_instance->get_objects();
|
||||
|
||||
// Unlock preloader
|
||||
$objects['cache_controller']->unlock_preloader();
|
||||
|
||||
// Log preloading complete
|
||||
$objects['logs']->add_log( 'preloader::task', 'Preloading complete' );
|
||||
|
||||
parent::complete();
|
||||
|
||||
}
|
||||
|
||||
public function is_process_running()
|
||||
{
|
||||
return parent::is_process_running();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,504 @@
|
|||
<?php
|
||||
/**
|
||||
* The blog dashboard model class for ThemeIsle SDK
|
||||
*
|
||||
* @package ThemeIsleSDK
|
||||
* @subpackage Modules
|
||||
* @copyright Copyright (c) 2017, Marius Cristea
|
||||
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace ThemeisleSDK\Modules;
|
||||
|
||||
use ThemeisleSDK\Common\Abstract_Module;
|
||||
use ThemeisleSDK\Product;
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blog dashboard widget module for ThemeIsle SDK.
|
||||
*/
|
||||
class Dashboard_Widget extends Abstract_Module {
|
||||
|
||||
/**
|
||||
* Fetched feeds items.
|
||||
*
|
||||
* @var array Feed items.
|
||||
*/
|
||||
private $items = array();
|
||||
|
||||
/**
|
||||
* Dashboard widget title.
|
||||
*
|
||||
* @var string $dashboard_name Dashboard name.
|
||||
*/
|
||||
private $dashboard_name = '';
|
||||
|
||||
/**
|
||||
* Dashboard widget feed sources.
|
||||
*
|
||||
* @var array $feeds Feed url.
|
||||
*/
|
||||
private $feeds = [];
|
||||
|
||||
/**
|
||||
* Should we load this module.
|
||||
*
|
||||
* @param Product $product Product object.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function can_load( $product ) {
|
||||
if ( $this->is_from_partner( $product ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! apply_filters( $product->get_slug() . '_load_dashboard_widget', true ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the hooks.
|
||||
*
|
||||
* @param Product $product Product to load.
|
||||
*
|
||||
* @return Dashboard_Widget Module instance.
|
||||
*/
|
||||
public function load( $product ) {
|
||||
if ( apply_filters( 'themeisle_sdk_hide_dashboard_widget', false ) ) {
|
||||
return;
|
||||
}
|
||||
$this->product = $product;
|
||||
$this->dashboard_name = apply_filters( 'themeisle_sdk_dashboard_widget_name', 'WordPress Guides/Tutorials' );
|
||||
$this->feeds = apply_filters(
|
||||
'themeisle_sdk_dashboard_widget_feeds',
|
||||
[
|
||||
'https://themeisle.com/blog/feed',
|
||||
'https://www.codeinwp.com/blog/feed',
|
||||
'https://wpshout.com/feed',
|
||||
]
|
||||
);
|
||||
add_action( 'wp_dashboard_setup', array( &$this, 'add_widget' ) );
|
||||
add_action( 'wp_network_dashboard_setup', array( &$this, 'add_widget' ) );
|
||||
add_filter( 'themeisle_sdk_recommend_plugin_or_theme', array( &$this, 'recommend_plugin_or_theme' ) );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add widget to the dashboard
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
public function add_widget() {
|
||||
global $wp_meta_boxes;
|
||||
if ( isset( $wp_meta_boxes['dashboard']['normal']['core']['themeisle'] ) ) {
|
||||
return;
|
||||
}
|
||||
wp_add_dashboard_widget(
|
||||
'themeisle',
|
||||
$this->dashboard_name,
|
||||
[
|
||||
$this,
|
||||
'render_dashboard_widget',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render widget content
|
||||
*/
|
||||
public function render_dashboard_widget() {
|
||||
$this->setup_feeds();
|
||||
if ( empty( $this->items ) || ! is_array( $this->items ) ) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<style type="text/css">
|
||||
#themeisle ul li.ti-dw-recommend-item {
|
||||
padding-left: 7px;
|
||||
border-top: 1px solid #eee;
|
||||
margin-bottom: 0px;
|
||||
padding-top: 6px;
|
||||
}
|
||||
|
||||
#themeisle h2.hndle {
|
||||
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABbCAMAAADncTNAAAAAtFBMVEVHcEyAgIB/f3+xsbGgoaGBgYGCgoKKioqAgIC1tbW5ubnFx8iAgIDU1taBgYGCgoKAgIC0tLXW19jW2NiAgIC3uLiBgYHLzMy4uLhycnLW19d/f3/T1NW0tLTX19mVlZWvr6+BgYHl5eWKiottbW5JSUnW2Nm5ubnh4eHT1NWVlZVjY2N4eHh9fX6pqqq+v79PT0/39/fu7u7Nzc7Z2ttYWFgBAQHDw8P////JysoZGRk0NTZqJc/sAAAAIXRSTlMA0FL7/oEnEPL6eibivm9gwJya76/enFq2CXI+2lFAyM8GATmPAAADj0lEQVR4Xu2YaW/iOhSGAwRCWDosnXa6znjJvm8svf//f12TuARyhiR2pfnUR6gSEnr0+uT4xK7yRb755pvhHePli5K7Bfpkuhoq8ozRJdMH+WWha6Z3sqYparCSLRJqspjImVbANJU03cNMMpofAwQZCGsmpQYyFvVM0Q00OQ9koMl5IPcCoro+RA1Dt2Ea9n9eZ0+YHJLkgIlkDywQx00wCTyaReiKH8LbNU9ybJOdkchV6QFxyCFLbVvdfaREqgUWg/tx2UbqIcK2Hex2TdGLwFTjIj3XP3YfCZFsb23KRZn/3263oymSFI0/a5S4PqUBjoBIJBDjeEhCN0wxQSRybIxtJ3K5SGzuE/vAwIQc8ZmMMJFAIM4oikZItfEFtorGgoE43FObwqHU68OtPCnOz8KZ2Jbl5LgkSW0Tc7YyIz/EFWmS4jMbiZU5mJOmKRaJpKGGyLZtDJh3iyaNUu/3+xyKnrtFL71EG+FTiMpENhQtxUQ8kSOXCIr2tnCNhg/gTX0SHYFp0t7TCwQZ7U841yoHrW6rtGroUwTWVnLMssxx+H4bgZcSOFf5MYx0Ae8FghomMDyC2EBNImBywPkNTDNqGLQpIg2TjUNU8tBy9DQMo0DAZF16rAi7vJAtFTIYFAHUc6hIRW6OuOhJgaCSwmDEAYK4oa7ro+qIEyJU/US7KTJKPNSFT9tFgVFBu0SF1y7yjX4masRA9Da7EFGj28R/BkQz6xGIOurkx38T/bKs9Uk8aIiMwm/Jw0VP1yLrJwt13xAxvABBgsK4KWLov35DkRF7ZaqgzuZ7MQ8MOntmVYyAqKTwaICKqvSUFnVccMN5sziEP/5+xGDTahbH5Q3ZB76zr8fI+nJtvUUU3t3ml5GKviK/npCg3CGodnuJ4JVkfRFJYGVDBZrqKnn9RLf+CzDTS5PaN5J38+auzX4ykU4Qoj0rdKfcYs5ijfo9OL/uRUgZyQr7NCWtWwiUSLc4arfJa7lpszTA1OJZAQ8w8dXFrR5YHzCWSnS3pZ18tOi4Ps4vl/c7i/6qomjRecN+UubrPyPGn/VEMU3T0UFHkaPzpgjxmJsnjmrtionlMDZiog0TsY/DPtn8SXtlBvbtxKtwopy7lqW3smQO+yoGE1Uu55GJ3pmI8ygoejZNnqj0vnIRCyTKfLstRdtStGQi09myUsvwvlkuzSUXbV+Xz5ryBebV33fln/A/moud69FZiEYAAAAASUVORK5CYII=');
|
||||
background-repeat: no-repeat;
|
||||
background-position: 2% 50%;
|
||||
background-size: 25px;
|
||||
padding-left: 39px;
|
||||
}
|
||||
|
||||
#themeisle .inside {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.ti-feed-list {
|
||||
padding: 0 12px 5px;
|
||||
margin-bottom: 10px;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
|
||||
.ti-dw-feed-item a {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 5px;
|
||||
padding: 5px;
|
||||
transition: .2s ease;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.ti-dw-feed-item a:hover {
|
||||
background-color: #f8f8f8;
|
||||
}
|
||||
|
||||
.ti-dw-feed-item a:hover .ti-dw-date-container {
|
||||
opacity: .9;
|
||||
}
|
||||
|
||||
.ti-dw-feed-item .ti-dw-month-container {
|
||||
margin-top: -5px;
|
||||
text-transform: uppercase;
|
||||
font-size: 10px;
|
||||
letter-spacing: 1px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.ti-dw-feed-item .ti-dw-date-container {
|
||||
border-radius: 3px;
|
||||
transition: .2s ease;
|
||||
min-height: 35px;
|
||||
margin-right: 5px;
|
||||
min-width: 35px;
|
||||
text-align: center;
|
||||
border: 1px solid #2a6f97;
|
||||
color: #fff;
|
||||
background: #2ea2cc;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.ti-dw-footer {
|
||||
padding: 0 12px 5px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.ti-dw-recommend-item {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.ti-dw-recommend-item span {
|
||||
color: #72777c;
|
||||
}
|
||||
|
||||
.ti-dw-powered-by {
|
||||
font-size: 11px;
|
||||
margin-top: 3px;
|
||||
display: block;
|
||||
color: #72777c;
|
||||
}
|
||||
|
||||
.ti-dw-powered-by span {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
</style>
|
||||
<?php do_action( 'themeisle_sdk_dashboard_widget_before', $this->product ); ?>
|
||||
|
||||
<ul class="ti-feed-list">
|
||||
<?php
|
||||
|
||||
foreach ( $this->items as $item ) {
|
||||
?>
|
||||
<li class="ti-dw-feed-item">
|
||||
<a href="
|
||||
<?php
|
||||
echo esc_url(
|
||||
add_query_arg(
|
||||
array(
|
||||
'utm_source' => 'wpadmin',
|
||||
'utm_campaign' => 'feed',
|
||||
'utm_medium' => 'dashboard_widget',
|
||||
),
|
||||
$item['link']
|
||||
)
|
||||
);
|
||||
?>
|
||||
" target="_blank">
|
||||
<span class="ti-dw-date-container"><span
|
||||
class="ti-dw-day-container"><?php echo esc_attr( gmdate( 'd', $item['date'] ) ); ?></span> <span
|
||||
class="ti-dw-month-container"><?php echo esc_attr( substr( gmdate( 'M', $item['date'] ), 0, 3 ) ); ?></span></span><?php echo esc_attr( $item['title'] ); ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
<?php
|
||||
$recommend = apply_filters( 'themeisle_sdk_recommend_plugin_or_theme', array() );
|
||||
if ( ! is_array( $recommend ) || empty( $recommend ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$type = $recommend['type'];
|
||||
|
||||
if ( ( 'theme' === $type && ! current_user_can( 'install_themes' ) ) ) {
|
||||
return;
|
||||
}
|
||||
if ( ( 'plugin' === $type && ! current_user_can( 'install_plugins' ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_thickbox();
|
||||
$url = add_query_arg(
|
||||
[
|
||||
'theme' => $recommend['slug'],
|
||||
],
|
||||
network_admin_url( 'theme-install.php' )
|
||||
);
|
||||
|
||||
if ( 'plugin' === $type ) {
|
||||
|
||||
$url = add_query_arg(
|
||||
array(
|
||||
'tab' => 'plugin-information',
|
||||
'plugin' => $recommend['slug'],
|
||||
),
|
||||
network_admin_url( 'plugin-install.php' )
|
||||
);
|
||||
}
|
||||
?>
|
||||
<div class="ti-dw-footer">
|
||||
<span class="ti-dw-recommend-item ">
|
||||
<span class="ti-dw-recommend"><?php echo esc_attr( apply_filters( 'themeisle_sdk_dashboard_popular_label', sprintf( 'Popular %s', ucwords( $type ) ) ) ); ?>
|
||||
: </span>
|
||||
<?php
|
||||
echo esc_attr(
|
||||
trim(
|
||||
str_replace(
|
||||
array(
|
||||
'lite',
|
||||
'Lite',
|
||||
'(Lite)',
|
||||
'(lite)',
|
||||
),
|
||||
'',
|
||||
$recommend['name']
|
||||
)
|
||||
)
|
||||
);
|
||||
?>
|
||||
(<a class="thickbox open-plugin-details-modal"
|
||||
href="<?php echo esc_url( $url . '&TB_iframe=true&width=600&height=500' ); ?>"><?php echo esc_attr( apply_filters( 'themeisle_sdk_dashboard_install_label', 'Install' ) ); ?></a>)
|
||||
</span>
|
||||
<span class="ti-dw-powered-by"><span><?php echo esc_attr( apply_filters( 'themeisle_sdk_dashboard_widget_powered_by', sprintf( 'Powered by %s', $this->product->get_friendly_name() ) ) ); ?></span></span>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup feed items.
|
||||
*/
|
||||
private function setup_feeds() {
|
||||
if ( false === ( $items_normalized = get_transient( 'themeisle_sdk_feed_items' ) ) ) { //phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
|
||||
// Do not force the feed for the items in the sdk feeds list.
|
||||
// this prevents showing notices if another plugin will force all SimplePie feeds to load, instead it will
|
||||
// use the regular SimplePie validation and abort early if the feed is not valid.
|
||||
$sdk_feeds = $this->feeds;
|
||||
add_action(
|
||||
'wp_feed_options',
|
||||
function ( $feed, $url ) use ( $sdk_feeds ) {
|
||||
if ( defined( 'TI_SDK_PHPUNIT' ) && true === TI_SDK_PHPUNIT ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! is_string( $url ) && in_array( $url, $sdk_feeds, true ) ) {
|
||||
$feed->force_feed( false );
|
||||
return;
|
||||
}
|
||||
if ( is_array( $url ) ) {
|
||||
foreach ( $url as $feed_url ) {
|
||||
if ( in_array( $feed_url, $sdk_feeds, true ) ) {
|
||||
$feed->force_feed( false );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
PHP_INT_MAX,
|
||||
2
|
||||
);
|
||||
// Load SimplePie Instance.
|
||||
$feed = fetch_feed( $sdk_feeds );
|
||||
// TODO report error when is an error loading the feed.
|
||||
if ( is_wp_error( $feed ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$items = $feed->get_items( 0, 5 );
|
||||
$items = is_array( $items ) ? $items : [];
|
||||
|
||||
$items_normalized = [];
|
||||
|
||||
foreach ( $items as $item ) {
|
||||
$items_normalized[] = array(
|
||||
'title' => $item->get_title(),
|
||||
'date' => $item->get_date( 'U' ),
|
||||
'link' => $item->get_permalink(),
|
||||
);
|
||||
}
|
||||
set_transient( 'themeisle_sdk_feed_items', $items_normalized, 48 * HOUR_IN_SECONDS );
|
||||
}
|
||||
$this->items = $items_normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Either the current product is installed or not.
|
||||
*
|
||||
* @param array $val The current recommended product.
|
||||
*
|
||||
* @return bool Either we should exclude the plugin or not.
|
||||
*/
|
||||
public function remove_current_products( $val ) {
|
||||
if ( 'theme' === $val['type'] ) {
|
||||
$exist = wp_get_theme( $val['slug'] );
|
||||
|
||||
return ! $exist->exists();
|
||||
} else {
|
||||
$all_plugins = array_keys( get_plugins() );
|
||||
foreach ( $all_plugins as $slug ) {
|
||||
if ( strpos( $slug, $val['slug'] ) !== false ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Contact the API and fetch the recommended plugins/themes
|
||||
*/
|
||||
public function recommend_plugin_or_theme() {
|
||||
$products = $this->get_product_from_api();
|
||||
if ( ! is_array( $products ) ) {
|
||||
$products = array();
|
||||
}
|
||||
$products = array_filter( $products, array( $this, 'remove_current_products' ) );
|
||||
$products = array_merge( $products );
|
||||
if ( count( $products ) > 1 ) {
|
||||
shuffle( $products );
|
||||
$products = array_slice( $products, 0, 1 );
|
||||
}
|
||||
$to_recommend = isset( $products[0] ) ? $products[0] : $products;
|
||||
|
||||
return $to_recommend;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch products from the recomended section.
|
||||
*
|
||||
* @return array|mixed The list of products to use in recomended section.
|
||||
*/
|
||||
public function get_product_from_api() {
|
||||
if ( false === ( $products = get_transient( 'themeisle_sdk_products' ) ) ) { //phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
|
||||
$products = array();
|
||||
$all_themes = $this->get_themes_from_wporg( 'themeisle' );
|
||||
$all_plugins = $this->get_plugins_from_wporg( 'themeisle' );
|
||||
static $allowed_products = [
|
||||
'hestia' => true,
|
||||
'neve' => true,
|
||||
'visualizer' => true,
|
||||
'feedzy-rss-feeds' => true,
|
||||
'wp-product-review' => true,
|
||||
'otter-blocks' => true,
|
||||
'themeisle-companion' => true,
|
||||
];
|
||||
foreach ( $all_themes as $theme ) {
|
||||
if ( $theme->active_installs < 4999 ) {
|
||||
continue;
|
||||
}
|
||||
if ( ! isset( $allowed_products[ $theme->slug ] ) ) {
|
||||
continue;
|
||||
}
|
||||
$products[] = array(
|
||||
'name' => $theme->name,
|
||||
'type' => 'theme',
|
||||
'slug' => $theme->slug,
|
||||
'installs' => $theme->active_installs,
|
||||
);
|
||||
}
|
||||
foreach ( $all_plugins as $plugin ) {
|
||||
if ( $plugin->active_installs < 4999 ) {
|
||||
continue;
|
||||
}
|
||||
if ( ! isset( $allowed_products[ $plugin->slug ] ) ) {
|
||||
continue;
|
||||
}
|
||||
$products[] = array(
|
||||
'name' => $plugin->name,
|
||||
'type' => 'plugin',
|
||||
'slug' => $plugin->slug,
|
||||
'installs' => $plugin->active_installs,
|
||||
);
|
||||
}
|
||||
set_transient( 'themeisle_sdk_products', $products, 6 * HOUR_IN_SECONDS );
|
||||
}
|
||||
|
||||
return $products;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch themes from wporg api.
|
||||
*
|
||||
* @param string $author The author name.
|
||||
*
|
||||
* @return array The list of themes.
|
||||
*/
|
||||
public function get_themes_from_wporg( $author ) {
|
||||
$products = $this->safe_get(
|
||||
'https://api.wordpress.org/themes/info/1.1/?action=query_themes&request[author]=' . $author . '&request[per_page]=30&request[fields][active_installs]=true'
|
||||
);
|
||||
$products = json_decode( wp_remote_retrieve_body( $products ) );
|
||||
if ( is_object( $products ) ) {
|
||||
$products = isset( $products->themes ) ? $products->themes : array();
|
||||
} else {
|
||||
$products = array();
|
||||
}
|
||||
|
||||
return (array) $products;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch plugin from wporg api.
|
||||
*
|
||||
* @param string $author The author slug.
|
||||
*
|
||||
* @return array The list of plugins for the selected author.
|
||||
*/
|
||||
public function get_plugins_from_wporg( $author ) {
|
||||
$products = $this->safe_get(
|
||||
'https://api.wordpress.org/plugins/info/1.1/?action=query_plugins&request[author]=' . $author . '&request[per_page]=40&request[fields][active_installs]=true'
|
||||
);
|
||||
$products = json_decode( wp_remote_retrieve_body( $products ) );
|
||||
if ( is_object( $products ) ) {
|
||||
$products = isset( $products->plugins ) ? $products->plugins : array();
|
||||
} else {
|
||||
$products = array();
|
||||
}
|
||||
|
||||
return (array) $products;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
// autoload_static.php @generated by Composer
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit718cd62be4fc0d1c7deeabef60d4e8b7
|
||||
{
|
||||
public static $files = array (
|
||||
'f3e742daca6ecc1d4ff0a2b5cf792c05' => __DIR__ . '/..' . '/codeinwp/themeisle-sdk/load.php',
|
||||
);
|
||||
|
||||
public static $classMap = array (
|
||||
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
|
||||
'WP_Async_Request' => __DIR__ . '/..' . '/deliciousbrains/wp-background-processing/classes/wp-async-request.php',
|
||||
'WP_Background_Process' => __DIR__ . '/..' . '/deliciousbrains/wp-background-processing/classes/wp-background-process.php',
|
||||
);
|
||||
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->classMap = ComposerStaticInit718cd62be4fc0d1c7deeabef60d4e8b7::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 88 KiB |
|
@ -0,0 +1,181 @@
|
|||
<?php
|
||||
/**
|
||||
* WP Async Request
|
||||
*
|
||||
* @package WP-Background-Processing
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract WP_Async_Request class.
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
abstract class WP_Async_Request {
|
||||
|
||||
/**
|
||||
* Prefix
|
||||
*
|
||||
* (default value: 'wp')
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $prefix = 'wp';
|
||||
|
||||
/**
|
||||
* Action
|
||||
*
|
||||
* (default value: 'async_request')
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $action = 'async_request';
|
||||
|
||||
/**
|
||||
* Identifier
|
||||
*
|
||||
* @var mixed
|
||||
* @access protected
|
||||
*/
|
||||
protected $identifier;
|
||||
|
||||
/**
|
||||
* Data
|
||||
*
|
||||
* (default value: array())
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
protected $data = array();
|
||||
|
||||
/**
|
||||
* Initiate new async request
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->identifier = $this->prefix . '_' . $this->action;
|
||||
|
||||
add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) );
|
||||
add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set data used during the request
|
||||
*
|
||||
* @param array $data Data.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function data( $data ) {
|
||||
$this->data = $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch the async request
|
||||
*
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
public function dispatch() {
|
||||
$url = add_query_arg( $this->get_query_args(), $this->get_query_url() );
|
||||
$args = $this->get_post_args();
|
||||
|
||||
return wp_remote_post( esc_url_raw( $url ), $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get query args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_query_args() {
|
||||
if ( property_exists( $this, 'query_args' ) ) {
|
||||
return $this->query_args;
|
||||
}
|
||||
|
||||
$args = array(
|
||||
'action' => $this->identifier,
|
||||
'nonce' => wp_create_nonce( $this->identifier ),
|
||||
);
|
||||
|
||||
/**
|
||||
* Filters the post arguments used during an async request.
|
||||
*
|
||||
* @param array $url
|
||||
*/
|
||||
return apply_filters( $this->identifier . '_query_args', $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get query URL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_query_url() {
|
||||
if ( property_exists( $this, 'query_url' ) ) {
|
||||
return $this->query_url;
|
||||
}
|
||||
|
||||
$url = admin_url( 'admin-ajax.php' );
|
||||
|
||||
/**
|
||||
* Filters the post arguments used during an async request.
|
||||
*
|
||||
* @param string $url
|
||||
*/
|
||||
return apply_filters( $this->identifier . '_query_url', $url );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get post args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_post_args() {
|
||||
if ( property_exists( $this, 'post_args' ) ) {
|
||||
return $this->post_args;
|
||||
}
|
||||
|
||||
$args = array(
|
||||
'timeout' => 0.01,
|
||||
'blocking' => false,
|
||||
'body' => $this->data,
|
||||
'cookies' => $_COOKIE,
|
||||
'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
|
||||
);
|
||||
|
||||
/**
|
||||
* Filters the post arguments used during an async request.
|
||||
*
|
||||
* @param array $args
|
||||
*/
|
||||
return apply_filters( $this->identifier . '_post_args', $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe handle
|
||||
*
|
||||
* Check for correct nonce and pass to handler.
|
||||
*/
|
||||
public function maybe_handle() {
|
||||
// Don't lock up other requests while processing
|
||||
session_write_close();
|
||||
|
||||
check_ajax_referer( $this->identifier, 'nonce' );
|
||||
|
||||
$this->handle();
|
||||
|
||||
wp_die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle
|
||||
*
|
||||
* Override this method to perform any actions required
|
||||
* during the async request.
|
||||
*/
|
||||
abstract protected function handle();
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
<div class="wrap">
|
||||
|
||||
<div id="swcfpc_main_content">
|
||||
|
||||
<h1><?php _e('Super Page Cache for Cloudflare - Nginx Settings', 'wp-cloudflare-page-cache'); ?></h1>
|
||||
|
||||
<?php if( $this->main_instance->get_single_config('cf_cache_control_htaccess', 0) > 0 ): ?>
|
||||
|
||||
<div class="blocco_dati_header">
|
||||
<h3><?php echo __( 'Overwrite the cache-control header', 'wp-cloudflare-page-cache' ); ?></h3>
|
||||
</div>
|
||||
|
||||
<p><?php echo __( 'Edit the main Nginx configuration file, usually /etc/nginx.conf, and enter these rules immediately after opening the http block:', 'wp-cloudflare-page-cache' ); ?></p>
|
||||
|
||||
<strong><pre>
|
||||
map $upstream_http_x_wp_cf_super_cache_active $wp_cf_super_cache_active {
|
||||
default 'no-cache, no-store, must-revalidate, max-age=0';
|
||||
'1' '<?php echo $this->objects['cache_controller']->get_cache_control_value(); ?>';
|
||||
}
|
||||
</pre></strong>
|
||||
|
||||
<p><?php echo __( 'Now open the configuration file of your domain and add the following rules inside the block that deals with the management of PHP pages:', 'wp-cloudflare-page-cache' ); ?></p>
|
||||
|
||||
<strong><pre>
|
||||
more_clear_headers 'Pragma';
|
||||
more_clear_headers 'Expires';
|
||||
more_clear_headers 'Cache-Control';
|
||||
add_header Cache-Control $wp_cf_super_cache_active;
|
||||
</pre></strong>
|
||||
|
||||
<p><?php echo __( 'Save and restart Nginx.', 'wp-cloudflare-page-cache' ); ?></p>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if( count($nginx_lines) > 0 ): ?>
|
||||
|
||||
<div class="blocco_dati_header">
|
||||
<h3><?php echo __( 'Browser caching rules', 'wp-cloudflare-page-cache' ); ?></h3>
|
||||
</div>
|
||||
|
||||
<p><?php echo __( 'Open the configuration file of your domain and add the following rules:', 'wp-cloudflare-page-cache' ); ?></p>
|
||||
|
||||
<strong><pre>
|
||||
<?php foreach ($nginx_lines as $single_nginx_line) echo "{$single_nginx_line}\n"; ?>
|
||||
</pre></strong>
|
||||
|
||||
<p><?php echo __( 'Save and restart Nginx.', 'wp-cloudflare-page-cache' ); ?></p>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
|
@ -0,0 +1 @@
|
|||
let _allowQueryString,_allowExternalLinks,_useWhitelist,_lastTouchTimestamp,_mouseoverTimer,_chromiumMajorVersionInUserAgent=null,_delayOnHover=65,_preloadedList=new Set;const DELAY_TO_NOT_BE_CONSIDERED_A_TOUCH_INITIATED_ACTION=1111;function init(){if(!document.createElement("link").relList.supports("prefetch"))return;const e="instantVaryAccept"in document.body.dataset||"Shopify"in window,t=navigator.userAgent.indexOf("Chrome/");if(t>-1&&(_chromiumMajorVersionInUserAgent=parseInt(navigator.userAgent.substring(t+"Chrome/".length))),e&&_chromiumMajorVersionInUserAgent&&_chromiumMajorVersionInUserAgent<110)return;const n="instantMousedownShortcut"in document.body.dataset;_allowQueryString="instantAllowQueryString"in document.body.dataset,_allowExternalLinks="instantAllowExternalLinks"in document.body.dataset,_useWhitelist="instantWhitelist"in document.body.dataset;const o={capture:!0,passive:!0};let r=!1,i=!1,s=!1;if("instantIntensity"in document.body.dataset){const e=document.body.dataset.instantIntensity;if(e.startsWith("mousedown"))r=!0,"mousedown-only"==e&&(i=!0);else if(e.startsWith("viewport")){const t=navigator.connection&&navigator.connection.saveData,n=navigator.connection&&navigator.connection.effectiveType&&navigator.connection.effectiveType.includes("2g");t||n||("viewport"==e?document.documentElement.clientWidth*document.documentElement.clientHeight<45e4&&(s=!0):"viewport-all"==e&&(s=!0))}else{const t=parseInt(e);isNaN(t)||(_delayOnHover=t)}}if(i||document.addEventListener("touchstart",touchstartListener,o),r?n||document.addEventListener("mousedown",mousedownListener,o):document.addEventListener("mouseover",mouseoverListener,o),n&&document.addEventListener("mousedown",mousedownShortcutListener,o),s){let e=window.requestIdleCallback;e||(e=e=>{e()}),e((function(){const e=new IntersectionObserver((t=>{t.forEach((t=>{if(t.isIntersecting){const n=t.target;e.unobserve(n),preload(n.href)}}))}));document.querySelectorAll("a").forEach((t=>{isPreloadable(t)&&e.observe(t)}))}),{timeout:1500})}}function touchstartListener(e){_lastTouchTimestamp=performance.now();const t=e.target.closest("a");isPreloadable(t)&&preload(t.href,"high")}function mouseoverListener(e){if(performance.now()-_lastTouchTimestamp<1111)return;if(!("closest"in e.target))return;const t=e.target.closest("a");isPreloadable(t)&&(t.addEventListener("mouseout",mouseoutListener,{passive:!0}),_mouseoverTimer=setTimeout((()=>{preload(t.href,"high"),_mouseoverTimer=void 0}),_delayOnHover))}function mousedownListener(e){const t=e.target.closest("a");isPreloadable(t)&&preload(t.href,"high")}function mouseoutListener(e){e.relatedTarget&&e.target.closest("a")==e.relatedTarget.closest("a")||_mouseoverTimer&&(clearTimeout(_mouseoverTimer),_mouseoverTimer=void 0)}function mousedownShortcutListener(e){if(performance.now()-_lastTouchTimestamp<1111)return;const t=e.target.closest("a");if(e.which>1||e.metaKey||e.ctrlKey)return;if(!t)return;t.addEventListener("click",(function(e){1337!=e.detail&&e.preventDefault()}),{capture:!0,passive:!1,once:!0});const n=new MouseEvent("click",{view:window,bubbles:!0,cancelable:!1,detail:1337});t.dispatchEvent(n)}function isPreloadable(e){if(e&&e.href&&(!_useWhitelist||"instant"in e.dataset)){if(e.origin!=location.origin){if(!(_allowExternalLinks||"instant"in e.dataset)||!_chromiumMajorVersionInUserAgent)return}if(["http:","https:"].includes(e.protocol)&&("http:"!=e.protocol||"https:"!=location.protocol)&&(_allowQueryString||!e.search||"instant"in e.dataset)&&!(e.hash&&e.pathname+e.search==location.pathname+location.search||"noInstant"in e.dataset))return!0}}function preload(e,t="auto"){if(_preloadedList.has(e))return;if("function"==typeof swcfpc_can_url_be_prefetched&&!1===swcfpc_can_url_be_prefetched(e.split("#")[0]))return;const n=document.createElement("link");n.rel="prefetch",n.href=e,n.fetchPriority=t,n.as="document",document.head.appendChild(n),_preloadedList.add(e)}init();
|
|
@ -0,0 +1,412 @@
|
|||
<?php
|
||||
/**
|
||||
* The about page model class for ThemeIsle SDK
|
||||
*
|
||||
* Here's how to hook it in your plugin:
|
||||
*
|
||||
* add_filter( <product_slug>_about_us_metadata', 'add_about_meta' );
|
||||
*
|
||||
* function add_about_meta($data) {
|
||||
* return [
|
||||
* 'location' => <top level page - e.g. themes.php>,
|
||||
* 'logo' => <logo url>,
|
||||
* 'page_menu' => [['text' => '', 'url' => '']], // optional
|
||||
* 'has_upgrade_menu' => <condition>,
|
||||
* 'upgrade_link' => <url>,
|
||||
* 'upgrade_text' => 'Get Pro Version',
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* @package ThemeIsleSDK
|
||||
* @subpackage Modules
|
||||
* @copyright Copyright (c) 2023, Andrei Baicus
|
||||
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
|
||||
* @since 3.2.42
|
||||
*/
|
||||
|
||||
namespace ThemeisleSDK\Modules;
|
||||
|
||||
use ThemeisleSDK\Common\Abstract_Module;
|
||||
use ThemeisleSDK\Product;
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Promotions module for ThemeIsle SDK.
|
||||
*/
|
||||
class About_Us extends Abstract_Module {
|
||||
/**
|
||||
* About data.
|
||||
*
|
||||
* @var array $about_data About page data, received from the filter.
|
||||
*
|
||||
* Shape of the $about_data property array:
|
||||
* [
|
||||
* 'location' => 'top level page',
|
||||
* 'logo' => 'logo path',
|
||||
* 'page_menu' => [['text' => '', 'url' => '']], // Optional
|
||||
* 'has_upgrade_menu' => !defined('NEVE_PRO_VERSION'),
|
||||
* 'upgrade_link' => 'upgrade url',
|
||||
* 'upgrade_text' => 'Get Pro Version',
|
||||
* ]
|
||||
*/
|
||||
private $about_data = array();
|
||||
|
||||
/**
|
||||
* Should we load this module.
|
||||
*
|
||||
* @param Product $product Product object.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function can_load( $product ) {
|
||||
if ( $this->is_from_partner( $product ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->about_data = apply_filters( $product->get_key() . '_about_us_metadata', array() );
|
||||
|
||||
return ! empty( $this->about_data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the hooks.
|
||||
*
|
||||
* @param Product $product Product to load.
|
||||
*/
|
||||
public function load( $product ) {
|
||||
$this->product = $product;
|
||||
|
||||
add_action( 'admin_menu', [ $this, 'add_submenu_pages' ] );
|
||||
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_about_page_script' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds submenu pages.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_submenu_pages() {
|
||||
if ( ! isset( $this->about_data['location'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_submenu_page(
|
||||
$this->about_data['location'],
|
||||
__( 'About Us', 'textdomain' ),
|
||||
__( 'About Us', 'textdomain' ),
|
||||
'manage_options',
|
||||
$this->get_about_page_slug(),
|
||||
array( $this, 'render_about_us_page' ),
|
||||
100
|
||||
);
|
||||
|
||||
if ( ! isset( $this->about_data['has_upgrade_menu'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $this->about_data['has_upgrade_menu'] !== true ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! isset( $this->about_data['upgrade_link'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! isset( $this->about_data['upgrade_text'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_submenu_page(
|
||||
$this->about_data['location'],
|
||||
$this->about_data['upgrade_text'],
|
||||
$this->about_data['upgrade_text'],
|
||||
'manage_options',
|
||||
$this->about_data['upgrade_link'],
|
||||
'',
|
||||
101
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render page content.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render_about_us_page() {
|
||||
echo '<div id="ti-sdk-about"></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue scripts & styles.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enqueue_about_page_script() {
|
||||
$current_screen = get_current_screen();
|
||||
|
||||
if ( ! isset( $current_screen->id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( strpos( $current_screen->id, $this->get_about_page_slug() ) === false ) {
|
||||
return;
|
||||
}
|
||||
global $themeisle_sdk_max_path;
|
||||
$handle = 'ti-sdk-about-' . $this->product->get_key();
|
||||
$asset_file = require $themeisle_sdk_max_path . '/assets/js/build/about/about.asset.php';
|
||||
$deps = array_merge( $asset_file['dependencies'], [ 'updates' ] );
|
||||
|
||||
wp_register_script( $handle, $this->get_sdk_uri() . 'assets/js/build/about/about.js', $deps, $asset_file['version'], true );
|
||||
wp_localize_script( $handle, 'tiSDKAboutData', $this->get_about_localization_data() );
|
||||
|
||||
wp_enqueue_script( $handle );
|
||||
wp_enqueue_style( $handle, $this->get_sdk_uri() . 'assets/js/build/about/about.css', [ 'wp-components' ], $asset_file['version'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get localized data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_about_localization_data() {
|
||||
$links = isset( $this->about_data['page_menu'] ) ? $this->about_data['page_menu'] : [];
|
||||
$product_pages = isset( $this->about_data['product_pages'] ) ? $this->about_data['product_pages'] : [];
|
||||
return [
|
||||
'links' => $links,
|
||||
'logoUrl' => $this->about_data['logo'],
|
||||
'productPages' => $this->get_product_pages_data( $product_pages ),
|
||||
'products' => $this->get_other_products_data(),
|
||||
'homeUrl' => esc_url( home_url() ),
|
||||
'pageSlug' => $this->get_about_page_slug(),
|
||||
'currentProduct' => [
|
||||
'slug' => $this->product->get_key(),
|
||||
'name' => $this->product->get_name(),
|
||||
],
|
||||
'teamImage' => $this->get_sdk_uri() . 'assets/images/team.jpg',
|
||||
'strings' => [
|
||||
'aboutUs' => __( 'About us', 'textdomain' ),
|
||||
'heroHeader' => __( 'Our Story', 'textdomain' ),
|
||||
'heroTextFirst' => __( 'Themeisle was founded in 2012 by a group of passionate developers who wanted to create beautiful and functional WordPress themes and plugins. Since then, we have grown into a team of over 20 dedicated professionals who are committed to delivering the best possible products to our customers.', 'textdomain' ),
|
||||
'heroTextSecond' => __( 'At Themeisle, we offer a wide range of WordPress themes and plugins that are designed to meet the needs of both beginners and advanced users. Our products are feature-rich, easy to use, and are designed to help you create beautiful and functional websites.', 'textdomain' ),
|
||||
'teamImageCaption' => __( 'Our team in WCEU2022 in Portugal', 'textdomain' ),
|
||||
'newsHeading' => __( 'Stay connected for news & updates!', 'textdomain' ),
|
||||
'emailPlaceholder' => __( 'Your email address', 'textdomain' ),
|
||||
'signMeUp' => __( 'Sign me up', 'textdomain' ),
|
||||
'installNow' => __( 'Install Now', 'textdomain' ),
|
||||
'activate' => __( 'Activate', 'textdomain' ),
|
||||
'learnMore' => __( 'Learn More', 'textdomain' ),
|
||||
'installed' => __( 'Installed', 'textdomain' ),
|
||||
'notInstalled' => __( 'Not Installed', 'textdomain' ),
|
||||
'active' => __( 'Active', 'textdomain' ),
|
||||
],
|
||||
'canInstallPlugins' => current_user_can( 'install_plugins' ),
|
||||
'canActivatePlugins' => current_user_can( 'activate_plugins' ),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get product pages data.
|
||||
*
|
||||
* @param array $product_pages Product pages.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_product_pages_data( $product_pages ) {
|
||||
|
||||
$otter_slug = 'otter-blocks';
|
||||
$otter_plugin = [
|
||||
'status' => 'not-installed',
|
||||
];
|
||||
$otter_plugin['status'] = $this->is_plugin_installed( $otter_slug ) ? 'installed' : 'not-installed';
|
||||
$otter_plugin['status'] = $this->is_plugin_active( $otter_slug ) ? 'active' : $otter_plugin['status'];
|
||||
$otter_plugin['activationLink'] = $this->get_plugin_activation_link( $otter_slug );
|
||||
|
||||
$pages = [
|
||||
'otter-page' => [
|
||||
'name' => 'Otter Blocks',
|
||||
'hash' => '#otter-page',
|
||||
'product' => $otter_slug,
|
||||
'plugin' => $otter_plugin,
|
||||
'strings' => [
|
||||
'heading' => __( 'Build innovative layouts with Otter Blocks and Gutenberg', 'textdomain' ),
|
||||
'text' => __( 'Otter is a lightweight, dynamic collection of page building blocks and templates for the WordPress block editor.', 'textdomain' ),
|
||||
'buttons' => [
|
||||
'install_otter_free' => __( "Install Otter - It's free!", 'textdomain' ),
|
||||
'install_now' => __( 'Install Now', 'textdomain' ),
|
||||
'learn_more' => __( 'Learn More', 'textdomain' ),
|
||||
'learn_more_link' => tsdk_utmify( 'https://themeisle.com/plugins/otter-blocks/', 'otter-page', 'about-us' ),
|
||||
],
|
||||
'features' => [
|
||||
'advancedTitle' => __( 'Advanced Features', 'textdomain' ),
|
||||
'advancedDesc' => __( 'Add features such as Custom CSS, Animations & Visibility Conditions to all blocks.', 'textdomain' ),
|
||||
'fastTitle' => __( 'Lightweight and Fast', 'textdomain' ),
|
||||
'fastDesc' => __( 'Otter enhances WordPress site building experience without impacting site speed.', 'textdomain' ),
|
||||
'mobileTitle' => __( 'Mobile-Friendly', 'textdomain' ),
|
||||
'mobileDesc' => __( 'Each block can be tweaked to provide a consistent experience across all devices.', 'textdomain' ),
|
||||
],
|
||||
'details' => [
|
||||
's1Image' => $this->get_sdk_uri() . 'assets/images/otter/otter-builder.png',
|
||||
's1Title' => __( 'A Better Page Building Experience', 'textdomain' ),
|
||||
's1Text' => __( 'Otter can be used to build everything from a personal blog to an e-commerce site without losing the personal touch. Otter’s ease of use transforms basic blocks into expressive layouts in seconds.', 'textdomain' ),
|
||||
's2Image' => $this->get_sdk_uri() . 'assets/images/otter/otter-patterns.png',
|
||||
's2Title' => __( 'A New Collection of Patterns', 'textdomain' ),
|
||||
's2Text' => __( 'A New Patterns Library, containing a range of different elements in a variety of styles to help you build great pages. All of your website’s most important areas are covered: headers, testimonials, pricing tables, sections and more.', 'textdomain' ),
|
||||
's3Image' => $this->get_sdk_uri() . 'assets/images/otter/otter-library.png',
|
||||
's3Title' => __( 'Advanced Blocks', 'textdomain' ),
|
||||
's3Text' => __( 'Enhance your website’s design with powerful blocks, like the Add to Cart, Business Hours, Review Comparison, and dozens of WooCommerce blocks.', 'textdomain' ),
|
||||
],
|
||||
'testimonials' => [
|
||||
'heading' => __( 'Trusted by more than 300K website owners', 'textdomain' ),
|
||||
'users' => [
|
||||
[
|
||||
'avatar' => 'https://mllj2j8xvfl0.i.optimole.com/cb:3970~373ad/w:80/h:80/q:mauto/https://themeisle.com/wp-content/uploads/2021/05/avatar-03.png',
|
||||
'name' => 'Michael Burry',
|
||||
'text' => 'Loved the collection of blocks. If you want to create nice Gutenberg Pages, this plugin will be very handy and useful.',
|
||||
],
|
||||
[
|
||||
'avatar' => 'https://mllj2j8xvfl0.i.optimole.com/cb:3970~373ad/w:80/h:80/q:mauto/https://themeisle.com/wp-content/uploads/2022/04/avatar-04.png',
|
||||
'name' => 'Maria Gonzales',
|
||||
'text' => 'I am very satisfied with Otter – a fantastic collection of blocks. And the plugin is perfectly integrated with Gutenberg and complete enough for my needs. ',
|
||||
],
|
||||
[
|
||||
'avatar' => 'https://mllj2j8xvfl0.i.optimole.com/cb:3970~373ad/w:80/h:80/q:mauto/https://themeisle.com/wp-content/uploads/2022/04/avatar-05.png',
|
||||
'name' => 'Florian Henckel',
|
||||
'text' => 'Otter Blocks work really well and I like the customization options. Easy to use and format to fit in with my site theme – and I’ve not encountered any compatibility or speed issues.',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return array_filter(
|
||||
$pages,
|
||||
function ( $page_data, $page_key ) use ( $product_pages ) {
|
||||
return in_array( $page_key, $product_pages, true ) &&
|
||||
isset( $page_data['plugin']['status'] ) &&
|
||||
$page_data['plugin']['status'] === 'not-installed';
|
||||
},
|
||||
ARRAY_FILTER_USE_BOTH
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get products data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_other_products_data() {
|
||||
$products = [
|
||||
'optimole-wp' => [
|
||||
'name' => 'Optimole',
|
||||
'description' => 'Optimole is an image optimization service that automatically optimizes your images and serves them to your visitors via a global CDN, making your website lighter, faster and helping you reduce your bandwidth usage.',
|
||||
],
|
||||
'neve' => [
|
||||
'skip_api' => true,
|
||||
'name' => 'Neve',
|
||||
'description' => __( 'A fast, lightweight, customizable WordPress theme offering responsive design, speed, and flexibility for various website types.', 'textdomain' ),
|
||||
'icon' => $this->get_sdk_uri() . 'assets/images/neve.png',
|
||||
],
|
||||
'otter-blocks' => [
|
||||
'name' => 'Otter',
|
||||
],
|
||||
'tweet-old-post' => [
|
||||
'name' => 'Revive Old Post',
|
||||
],
|
||||
'feedzy-rss-feeds' => [
|
||||
'name' => 'Feedzy',
|
||||
],
|
||||
'woocommerce-product-addon' => [
|
||||
'name' => 'PPOM',
|
||||
'condition' => class_exists( 'WooCommerce', false ),
|
||||
],
|
||||
'visualizer' => [
|
||||
'name' => 'Visualizer',
|
||||
],
|
||||
'wp-landing-kit' => [
|
||||
'skip_api' => true,
|
||||
'premiumUrl' => tsdk_utmify( 'https://themeisle.com/plugins/wp-landing-kit', $this->get_about_page_slug() ),
|
||||
'name' => 'WP Landing Kit',
|
||||
'description' => __( 'Turn WordPress into a landing page powerhouse with Landing Kit, map domains to pages or any other published resource.', 'textdomain' ),
|
||||
'icon' => $this->get_sdk_uri() . 'assets/images/wplk.png',
|
||||
],
|
||||
'multiple-pages-generator-by-porthas' => [
|
||||
'name' => 'MPG',
|
||||
],
|
||||
'sparks-for-woocommerce' => [
|
||||
'skip_api' => true,
|
||||
'premiumUrl' => tsdk_utmify( 'https://themeisle.com/plugins/sparks-for-woocommerce', $this->get_about_page_slug() ),
|
||||
'name' => 'Sparks',
|
||||
'description' => __( 'Extend your store functionality with 8 ultra-performant features like product comparisons, variation swatches, wishlist, and more.', 'textdomain' ),
|
||||
'icon' => $this->get_sdk_uri() . 'assets/images/sparks.png',
|
||||
'condition' => class_exists( 'WooCommerce', false ),
|
||||
],
|
||||
'templates-patterns-collection' => [
|
||||
'name' => 'Templates Cloud',
|
||||
'description' => __( 'Design, save, and revisit your templates anytime with your personal vault on Templates Cloud.', 'textdomain' ),
|
||||
],
|
||||
];
|
||||
|
||||
foreach ( $products as $slug => $product ) {
|
||||
if ( isset( $product['condition'] ) && ! $product['condition'] ) {
|
||||
unset( $products[ $slug ] );
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $slug === 'neve' ) {
|
||||
$theme = get_template();
|
||||
$themes = wp_get_themes();
|
||||
|
||||
$products[ $slug ]['status'] = isset( $themes['neve'] ) ? 'installed' : 'not-installed';
|
||||
$products[ $slug ]['status'] = $theme === 'neve' ? 'active' : $products[ $slug ]['status'];
|
||||
|
||||
$products[ $slug ]['activationLink'] = add_query_arg(
|
||||
[
|
||||
'stylesheet' => 'neve',
|
||||
'action' => 'activate',
|
||||
'_wpnonce' => wp_create_nonce( 'switch-theme_neve' ),
|
||||
],
|
||||
admin_url( 'themes.php' )
|
||||
);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$products[ $slug ]['status'] = $this->is_plugin_installed( $slug ) ? 'installed' : 'not-installed';
|
||||
$products[ $slug ]['status'] = $this->is_plugin_active( $slug ) ? 'active' : $products[ $slug ]['status'];
|
||||
$products[ $slug ]['activationLink'] = $this->get_plugin_activation_link( $slug );
|
||||
|
||||
|
||||
if ( isset( $product['skip_api'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$api_data = $this->call_plugin_api( $slug );
|
||||
|
||||
if ( ! isset( $product['icon'] ) ) {
|
||||
$products[ $slug ]['icon'] = isset( $api_data->icons['2x'] ) ? $api_data->icons['2x'] : $api_data->icons['1x'];
|
||||
}
|
||||
if ( ! isset( $product['description'] ) ) {
|
||||
$products[ $slug ]['description'] = $api_data->short_description;
|
||||
}
|
||||
if ( ! isset( $product['name'] ) ) {
|
||||
$products[ $slug ]['name'] = $api_data->name;
|
||||
}
|
||||
}
|
||||
|
||||
return $products;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the page slug.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_about_page_slug() {
|
||||
return 'ti-about-' . $this->product->get_key();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/**
|
||||
* File responsible for sdk files loading.
|
||||
*
|
||||
* @package ThemeIsleSDK
|
||||
* @copyright Copyright (c) 2017, Marius Cristea
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 1.1.0
|
||||
*/
|
||||
|
||||
namespace ThemeisleSDK;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
$products = apply_filters( 'themeisle_sdk_products', array() );
|
||||
$themeisle_library_path = dirname( __FILE__ );
|
||||
$files_to_load = [
|
||||
$themeisle_library_path . '/src/Loader.php',
|
||||
$themeisle_library_path . '/src/Product.php',
|
||||
|
||||
$themeisle_library_path . '/src/Common/Abstract_module.php',
|
||||
$themeisle_library_path . '/src/Common/Module_factory.php',
|
||||
|
||||
$themeisle_library_path . '/src/Modules/Script_loader.php',
|
||||
$themeisle_library_path . '/src/Modules/Dashboard_widget.php',
|
||||
$themeisle_library_path . '/src/Modules/Rollback.php',
|
||||
$themeisle_library_path . '/src/Modules/Uninstall_feedback.php',
|
||||
$themeisle_library_path . '/src/Modules/Licenser.php',
|
||||
$themeisle_library_path . '/src/Modules/Endpoint.php',
|
||||
$themeisle_library_path . '/src/Modules/Notification.php',
|
||||
$themeisle_library_path . '/src/Modules/Logger.php',
|
||||
$themeisle_library_path . '/src/Modules/Translate.php',
|
||||
$themeisle_library_path . '/src/Modules/Review.php',
|
||||
$themeisle_library_path . '/src/Modules/Recommendation.php',
|
||||
$themeisle_library_path . '/src/Modules/Promotions.php',
|
||||
$themeisle_library_path . '/src/Modules/Welcome.php',
|
||||
$themeisle_library_path . '/src/Modules/Compatibilities.php',
|
||||
$themeisle_library_path . '/src/Modules/About_us.php',
|
||||
$themeisle_library_path . '/src/Modules/Announcements.php',
|
||||
];
|
||||
|
||||
$files_to_load = array_merge( $files_to_load, apply_filters( 'themeisle_sdk_required_files', [] ) );
|
||||
|
||||
foreach ( $files_to_load as $file ) {
|
||||
if ( is_file( $file ) ) {
|
||||
require_once $file;
|
||||
}
|
||||
}
|
||||
Loader::init();
|
||||
|
||||
foreach ( $products as $product ) {
|
||||
Loader::add_product( $product );
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
Copyright (c) Nils Adermann, Jordi Boggiano
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
// autoload_namespaces.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(__DIR__);
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
);
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
add_thickbox(); ?>
|
||||
|
||||
<div id="swcfpc_sidebar">
|
||||
|
||||
<div class="swcfpc_sidebar_widget">
|
||||
|
||||
<h3><?php _e( 'Our Products', 'wp-cloudflare-page-cache' ); ?></h3>
|
||||
|
||||
<p><?php _e( 'Extend your website perfomance with more free products from our portofolio:', 'wp-cloudflare-page-cache' ); ?></p>
|
||||
<h4 style="font-size:20px; ">
|
||||
Optimole <?php _e( 'plugin', 'wp-cloudflare-page-cache' ); ?>
|
||||
</h4>
|
||||
<ul style="list-style: circle;margin-left: 30px;">
|
||||
<li><?php _e( 'Cloud based image optimization service', 'wp-cloudflare-page-cache' ); ?></li>
|
||||
<li><?php _e( 'Smart Lazyload ( background images included )', 'wp-cloudflare-page-cache' ); ?></li>
|
||||
<li><?php _e( 'Auto Scaled Images', 'wp-cloudflare-page-cache' ); ?></li>
|
||||
<li><?php _e( 'Machine Learning(ML) compression.', 'wp-cloudflare-page-cache' ); ?></li>
|
||||
<li><?php _e( 'Automatically convert to best format(WebP, AVIF)', 'wp-cloudflare-page-cache' ); ?></li>
|
||||
<li><?php echo sprintf( __( 'Deliver via CDN - AWS CloudFront ( %s+ locations )', 'wp-cloudflare-page-cache' ), '300'); ?></li>
|
||||
<li><?php _e( 'Unmetered Bandwidth', 'wp-cloudflare-page-cache' ); ?></li>
|
||||
<li><?php _e( 'Dozens of compatibilities with 3rd party plugins', 'wp-cloudflare-page-cache' ); ?></li>
|
||||
</ul>
|
||||
<a href="<?php
|
||||
$url = add_query_arg(
|
||||
array(
|
||||
'tab' => 'plugin-information',
|
||||
'plugin' => 'optimole-wp',
|
||||
'TB_iframe' => 'true',
|
||||
'width' => '600',
|
||||
'height' => '500'
|
||||
),
|
||||
network_admin_url( 'plugin-install.php' )
|
||||
);
|
||||
echo esc_url( $url );
|
||||
?>" style="text-align: center; padding: 0 10px;" class="button button-primary thickbox "
|
||||
target="_blank"><?php _e( 'Install', 'wp-cloudflare-page-cache' ); ?> </a>
|
||||
<h4 style="font-size:20px;">
|
||||
Neve <?php _e( 'theme', 'wp-cloudflare-page-cache' ); ?>
|
||||
</h4>
|
||||
<ul style="list-style: circle;margin-left: 30px;">
|
||||
<li><?php _e( 'Lightweight, 25kB in page-weight', 'wp-cloudflare-page-cache' ); ?></li>
|
||||
<li><?php _e( 'Perfomance built-in', 'wp-cloudflare-page-cache' ); ?></li>
|
||||
<li><?php _e( 'Ready to use Starter Sites available', 'wp-cloudflare-page-cache' ); ?></li>
|
||||
<li><?php _e( 'AMP/Mobile ready.', 'wp-cloudflare-page-cache' ); ?></li>
|
||||
<li><?php _e( 'Dozens of ecommerce extra features', 'wp-cloudflare-page-cache' ); ?></li>
|
||||
<li><?php _e( 'Lots of customizations options', 'wp-cloudflare-page-cache' ); ?></li>
|
||||
</ul>
|
||||
<a style="text-align: center; padding: 0 10px;" href="https://themeisle.com/themes/neve/" target="_blank"
|
||||
class="button button-primary"><?php _e( 'View more', 'wp-cloudflare-page-cache' ); ?></a>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit718cd62be4fc0d1c7deeabef60d4e8b7
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
public static function loadClassLoader($class)
|
||||
{
|
||||
if ('Composer\Autoload\ClassLoader' === $class) {
|
||||
require __DIR__ . '/ClassLoader.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Composer\Autoload\ClassLoader
|
||||
*/
|
||||
public static function getLoader()
|
||||
{
|
||||
if (null !== self::$loader) {
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit718cd62be4fc0d1c7deeabef60d4e8b7', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit718cd62be4fc0d1c7deeabef60d4e8b7', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit718cd62be4fc0d1c7deeabef60d4e8b7::getInitializer($loader));
|
||||
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit718cd62be4fc0d1c7deeabef60d4e8b7::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
||||
require $file;
|
||||
}
|
||||
}, null, null);
|
||||
foreach ($filesToLoad as $fileIdentifier => $file) {
|
||||
$requireFile($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,336 @@
|
|||
/* instant.page v5.2.0 - (C) 2019-2023 Alexandre Dieulot - https://instant.page/license */
|
||||
/* Custom modified version created for Super page Cache for Cloudflare plugin - Saumya Majumder */
|
||||
|
||||
let _chromiumMajorVersionInUserAgent = null
|
||||
, _allowQueryString
|
||||
, _allowExternalLinks
|
||||
, _useWhitelist
|
||||
, _delayOnHover = 65
|
||||
, _lastTouchTimestamp
|
||||
, _mouseoverTimer
|
||||
, _preloadedList = new Set()
|
||||
|
||||
const DELAY_TO_NOT_BE_CONSIDERED_A_TOUCH_INITIATED_ACTION = 1111
|
||||
|
||||
init()
|
||||
|
||||
function init() {
|
||||
const isSupported = document.createElement('link').relList.supports('prefetch')
|
||||
// instant.page is meant to be loaded with <script type=module>
|
||||
// (though sometimes webmasters load it as a regular script).
|
||||
// So it’s normally executed (and must not cause JavaScript errors) in:
|
||||
// - Chromium 61+
|
||||
// - Gecko in Firefox 60+
|
||||
// - WebKit in Safari 10.1+ (iOS 10.3+, macOS 10.10+)
|
||||
//
|
||||
// The check above used to check for IntersectionObserverEntry.isIntersecting
|
||||
// but module scripts support implies this compatibility — except in Safari
|
||||
// 10.1–12.0, but this prefetch check takes care of it.
|
||||
|
||||
if (!isSupported) {
|
||||
return
|
||||
}
|
||||
|
||||
const handleVaryAcceptHeader = 'instantVaryAccept' in document.body.dataset || 'Shopify' in window
|
||||
// The `Vary: Accept` header when received in Chromium 79–109 makes prefetches
|
||||
// unusable, as Chromium used to send a different `Accept` header.
|
||||
// It’s applied on all Shopify sites by default, as Shopify is very popular
|
||||
// and is the main source of this problem.
|
||||
// `window.Shopify` only exists on “classic” Shopify sites. Those using
|
||||
// Hydrogen (Remix SPA) aren’t concerned.
|
||||
|
||||
const chromiumUserAgentIndex = navigator.userAgent.indexOf('Chrome/')
|
||||
if (chromiumUserAgentIndex > -1) {
|
||||
_chromiumMajorVersionInUserAgent = parseInt(navigator.userAgent.substring(chromiumUserAgentIndex + 'Chrome/'.length))
|
||||
}
|
||||
// The user agent client hints API is a theoretically more reliable way to
|
||||
// get Chromium’s version… but it’s not available in Samsung Internet 20.
|
||||
// It also requires a secure context, which would make debugging harder,
|
||||
// and is only available in recent Chromium versions.
|
||||
// In practice, Chromium browsers never shy from announcing "Chrome" in
|
||||
// their regular user agent string, as that maximizes their compatibility.
|
||||
|
||||
if (handleVaryAcceptHeader && _chromiumMajorVersionInUserAgent && _chromiumMajorVersionInUserAgent < 110) {
|
||||
return
|
||||
}
|
||||
|
||||
const mousedownShortcut = 'instantMousedownShortcut' in document.body.dataset
|
||||
_allowQueryString = 'instantAllowQueryString' in document.body.dataset
|
||||
_allowExternalLinks = 'instantAllowExternalLinks' in document.body.dataset
|
||||
_useWhitelist = 'instantWhitelist' in document.body.dataset
|
||||
|
||||
const eventListenersOptions = {
|
||||
capture: true,
|
||||
passive: true,
|
||||
}
|
||||
|
||||
let useMousedown = false
|
||||
let useMousedownOnly = false
|
||||
let useViewport = false
|
||||
if ('instantIntensity' in document.body.dataset) {
|
||||
const intensity = document.body.dataset.instantIntensity
|
||||
|
||||
if (intensity.startsWith('mousedown')) {
|
||||
useMousedown = true
|
||||
if (intensity == 'mousedown-only') {
|
||||
useMousedownOnly = true
|
||||
}
|
||||
}
|
||||
else if (intensity.startsWith('viewport')) {
|
||||
const isNavigatorConnectionSaveDataEnabled = navigator.connection && navigator.connection.saveData
|
||||
const isNavigatorConnectionLike2g = navigator.connection && navigator.connection.effectiveType && navigator.connection.effectiveType.includes('2g')
|
||||
if (!isNavigatorConnectionSaveDataEnabled && !isNavigatorConnectionLike2g) {
|
||||
if (intensity == "viewport") {
|
||||
if (document.documentElement.clientWidth * document.documentElement.clientHeight < 450000) {
|
||||
useViewport = true
|
||||
// Smartphones are the most likely to have a slow connection, and
|
||||
// their small screen size limits the number of links (and thus
|
||||
// server load).
|
||||
//
|
||||
// Foldable phones (being expensive as of 2023), tablets and PCs
|
||||
// generally have a decent connection, and a big screen displaying
|
||||
// more links that would put more load on the server.
|
||||
//
|
||||
// iPhone 14 Pro Max (want): 430×932 = 400 760
|
||||
// Samsung Galaxy S22 Ultra with display size set to 80% (want):
|
||||
// 450×965 = 434 250
|
||||
// Small tablet (don’t want): 600×960 = 576 000
|
||||
// Those number are virtual screen size, the viewport (used for
|
||||
// the check above) will be smaller with the browser’s interface.
|
||||
}
|
||||
}
|
||||
else if (intensity == "viewport-all") {
|
||||
useViewport = true
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const milliseconds = parseInt(intensity)
|
||||
if (!isNaN(milliseconds)) {
|
||||
_delayOnHover = milliseconds
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!useMousedownOnly) {
|
||||
document.addEventListener('touchstart', touchstartListener, eventListenersOptions)
|
||||
}
|
||||
|
||||
if (!useMousedown) {
|
||||
document.addEventListener('mouseover', mouseoverListener, eventListenersOptions)
|
||||
}
|
||||
else if (!mousedownShortcut) {
|
||||
document.addEventListener('mousedown', mousedownListener, eventListenersOptions)
|
||||
}
|
||||
|
||||
if (mousedownShortcut) {
|
||||
document.addEventListener('mousedown', mousedownShortcutListener, eventListenersOptions)
|
||||
}
|
||||
|
||||
if (useViewport) {
|
||||
let requestIdleCallbackOrFallback = window.requestIdleCallback
|
||||
// Safari has no support as of 16.3: https://webkit.org/b/164193
|
||||
if (!requestIdleCallbackOrFallback) {
|
||||
requestIdleCallbackOrFallback = (callback) => {
|
||||
callback()
|
||||
// A smarter fallback like setTimeout is not used because devices that
|
||||
// may eventually be eligible to a Safari version supporting prefetch
|
||||
// will be very powerful.
|
||||
// The weakest devices that could be eligible are the 2017 iPad and
|
||||
// the 2016 MacBook.
|
||||
}
|
||||
}
|
||||
|
||||
requestIdleCallbackOrFallback(function observeIntersection() {
|
||||
const intersectionObserver = new IntersectionObserver((entries) => {
|
||||
entries.forEach((entry) => {
|
||||
if (entry.isIntersecting) {
|
||||
const anchorElement = entry.target
|
||||
intersectionObserver.unobserve(anchorElement)
|
||||
preload(anchorElement.href)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
document.querySelectorAll('a').forEach((anchorElement) => {
|
||||
if (isPreloadable(anchorElement)) {
|
||||
intersectionObserver.observe(anchorElement)
|
||||
}
|
||||
})
|
||||
}, {
|
||||
timeout: 1500,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function touchstartListener(event) {
|
||||
_lastTouchTimestamp = performance.now()
|
||||
// Chrome on Android triggers mouseover before touchcancel, so
|
||||
// `_lastTouchTimestamp` must be assigned on touchstart to be measured
|
||||
// on mouseover.
|
||||
|
||||
const anchorElement = event.target.closest('a')
|
||||
|
||||
if (!isPreloadable(anchorElement)) {
|
||||
return
|
||||
}
|
||||
|
||||
preload(anchorElement.href, 'high')
|
||||
}
|
||||
|
||||
function mouseoverListener(event) {
|
||||
if (performance.now() - _lastTouchTimestamp < DELAY_TO_NOT_BE_CONSIDERED_A_TOUCH_INITIATED_ACTION) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!('closest' in event.target)) {
|
||||
return
|
||||
// Without this check sometimes an error “event.target.closest is not a function” is thrown, for unknown reasons
|
||||
// That error denotes that `event.target` isn’t undefined. My best guess is that it’s the Document.
|
||||
//
|
||||
// Details could be gleaned from throwing such an error:
|
||||
//throw new TypeError(`instant.page non-element event target: timeStamp=${~~event.timeStamp}, type=${event.type}, typeof=${typeof event.target}, nodeType=${event.target.nodeType}, nodeName=${event.target.nodeName}, viewport=${innerWidth}x${innerHeight}, coords=${event.clientX}x${event.clientY}, scroll=${scrollX}x${scrollY}`)
|
||||
}
|
||||
const anchorElement = event.target.closest('a')
|
||||
|
||||
if (!isPreloadable(anchorElement)) {
|
||||
return
|
||||
}
|
||||
|
||||
anchorElement.addEventListener('mouseout', mouseoutListener, {passive: true})
|
||||
|
||||
_mouseoverTimer = setTimeout(() => {
|
||||
preload(anchorElement.href, 'high')
|
||||
_mouseoverTimer = undefined
|
||||
}, _delayOnHover)
|
||||
}
|
||||
|
||||
function mousedownListener(event) {
|
||||
const anchorElement = event.target.closest('a')
|
||||
|
||||
if (!isPreloadable(anchorElement)) {
|
||||
return
|
||||
}
|
||||
|
||||
preload(anchorElement.href, 'high')
|
||||
}
|
||||
|
||||
function mouseoutListener(event) {
|
||||
if (event.relatedTarget && event.target.closest('a') == event.relatedTarget.closest('a')) {
|
||||
return
|
||||
}
|
||||
|
||||
if (_mouseoverTimer) {
|
||||
clearTimeout(_mouseoverTimer)
|
||||
_mouseoverTimer = undefined
|
||||
}
|
||||
}
|
||||
|
||||
function mousedownShortcutListener(event) {
|
||||
if (performance.now() - _lastTouchTimestamp < DELAY_TO_NOT_BE_CONSIDERED_A_TOUCH_INITIATED_ACTION) {
|
||||
return
|
||||
}
|
||||
|
||||
const anchorElement = event.target.closest('a')
|
||||
|
||||
if (event.which > 1 || event.metaKey || event.ctrlKey) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!anchorElement) {
|
||||
return
|
||||
}
|
||||
|
||||
anchorElement.addEventListener('click', function (event) {
|
||||
if (event.detail == 1337) {
|
||||
return
|
||||
}
|
||||
|
||||
event.preventDefault()
|
||||
}, {capture: true, passive: false, once: true})
|
||||
|
||||
const customEvent = new MouseEvent('click', {view: window, bubbles: true, cancelable: false, detail: 1337})
|
||||
anchorElement.dispatchEvent(customEvent)
|
||||
}
|
||||
|
||||
function isPreloadable(anchorElement) {
|
||||
if (!anchorElement || !anchorElement.href) {
|
||||
return
|
||||
}
|
||||
|
||||
if (_useWhitelist && !('instant' in anchorElement.dataset)) {
|
||||
return
|
||||
}
|
||||
|
||||
if (anchorElement.origin != location.origin) {
|
||||
let allowed = _allowExternalLinks || 'instant' in anchorElement.dataset
|
||||
if (!allowed || !_chromiumMajorVersionInUserAgent) {
|
||||
// Chromium-only: see comment on “restrictive prefetch”
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (!['http:', 'https:'].includes(anchorElement.protocol)) {
|
||||
return
|
||||
}
|
||||
|
||||
if (anchorElement.protocol == 'http:' && location.protocol == 'https:') {
|
||||
return
|
||||
}
|
||||
|
||||
if (!_allowQueryString && anchorElement.search && !('instant' in anchorElement.dataset)) {
|
||||
return
|
||||
}
|
||||
|
||||
if (anchorElement.hash && anchorElement.pathname + anchorElement.search == location.pathname + location.search) {
|
||||
return
|
||||
}
|
||||
|
||||
if ('noInstant' in anchorElement.dataset) {
|
||||
return
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
function preload(url, fetchPriority = 'auto') {
|
||||
if (_preloadedList.has(url)) {
|
||||
return
|
||||
}
|
||||
|
||||
// Custom check added by Super Page Cache for Cloudflare plugin
|
||||
if( typeof swcfpc_can_url_be_prefetched === 'function' && swcfpc_can_url_be_prefetched(url.split("#")[0]) === false ) {
|
||||
return
|
||||
}
|
||||
|
||||
const linkElement = document.createElement('link')
|
||||
linkElement.rel = 'prefetch'
|
||||
linkElement.href = url
|
||||
|
||||
linkElement.fetchPriority = fetchPriority
|
||||
// By default, a prefetch is loaded with a low priority.
|
||||
// When there’s a fair chance that this prefetch is going to be used in the
|
||||
// near term (= after a touch/mouse event), giving it a high priority helps
|
||||
// make the page load faster in case there are other resources loading.
|
||||
// Prioritizing it implicitly means deprioritizing every other resource
|
||||
// that’s loading on the page. Due to HTML documents usually being much
|
||||
// smaller than other resources (notably images and JavaScript), and
|
||||
// prefetches happening once the initial page is sufficiently loaded,
|
||||
// this theft of bandwidth should rarely be detrimental.
|
||||
|
||||
linkElement.as = 'document'
|
||||
// as=document is Chromium-only and allows cross-origin prefetches to be
|
||||
// usable for navigation. They call it “restrictive prefetch” and intend
|
||||
// to remove it: https://crbug.com/1352371
|
||||
//
|
||||
// This document from the Chrome team dated 2022-08-10
|
||||
// https://docs.google.com/document/d/1x232KJUIwIf-k08vpNfV85sVCRHkAxldfuIA5KOqi6M
|
||||
// claims (I haven’t tested) that data- and battery-saver modes as well as
|
||||
// the setting to disable preloading do not disable restrictive prefetch,
|
||||
// unlike regular prefetch. That’s good for prefetching on a touch/mouse
|
||||
// event, but might be bad when prefetching every link in the viewport.
|
||||
|
||||
document.head.appendChild(linkElement)
|
||||
|
||||
_preloadedList.add(url)
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
<?php return array('dependencies' => array(), 'version' => '7eac74bcd8abf2e43780');
|
|
@ -0,0 +1,280 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110, 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 Library 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
|
|
@ -0,0 +1,12 @@
|
|||
/**
|
||||
* Initialize the formbricks survey.
|
||||
*
|
||||
* @see https://github.com/formbricks/setup-examples/tree/main/html
|
||||
*/
|
||||
window.addEventListener('themeisle:survey:loaded', function () {
|
||||
window?.tsdk_formbricks?.init?.({
|
||||
environmentId: "clt8lntxw0zbu5zwkn3q2ybkq",
|
||||
apiHost: "https://app.formbricks.com",
|
||||
...(window?.swcfpcSurveyData ?? {}),
|
||||
});
|
||||
});
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
/**
|
||||
* WP-Background Processing
|
||||
*
|
||||
* @package WP-Background-Processing
|
||||
*/
|
||||
|
||||
/*
|
||||
Plugin Name: WP Background Processing
|
||||
Plugin URI: https://github.com/A5hleyRich/wp-background-processing
|
||||
Description: Asynchronous requests and background processing in WordPress.
|
||||
Author: Delicious Brains Inc.
|
||||
Version: 1.0
|
||||
Author URI: https://deliciousbrains.com/
|
||||
GitHub Plugin URI: https://github.com/A5hleyRich/wp-background-processing
|
||||
GitHub Branch: master
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'WP_Async_Request' ) ) {
|
||||
require_once plugin_dir_path( __FILE__ ) . 'classes/wp-async-request.php';
|
||||
}
|
||||
if ( ! class_exists( 'WP_Background_Process' ) ) {
|
||||
require_once plugin_dir_path( __FILE__ ) . 'classes/wp-background-process.php';
|
||||
}
|
|
@ -0,0 +1,211 @@
|
|||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
|
||||
|
||||
class SWCFPC_WP_CLI extends WP_CLI_Command
|
||||
{
|
||||
|
||||
private $main_instance = null;
|
||||
private $objects = false;
|
||||
|
||||
function __construct($main_instance)
|
||||
{
|
||||
|
||||
$this->main_instance = $main_instance;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show current Super Page Cache for Cloudflare version
|
||||
*
|
||||
* @when after_wp_load
|
||||
*/
|
||||
function version()
|
||||
{
|
||||
WP_CLI::line( 'Super Page Cache for Cloudflare v' . get_option('swcfpc_version', false));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Purge whole caches
|
||||
*
|
||||
* @when after_wp_load
|
||||
*/
|
||||
function purge_cache()
|
||||
{
|
||||
|
||||
$this->objects = $this->main_instance->get_objects();
|
||||
|
||||
if ($this->objects['cache_controller']->purge_all())
|
||||
WP_CLI::success( __('Cache purged successfully', 'wp-cloudflare-page-cache') );
|
||||
else
|
||||
WP_CLI::error( __('An error occurred while purging the cache', 'wp-cloudflare-page-cache') );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Purge the whole Cloudflare cache only
|
||||
*
|
||||
* @when after_wp_load
|
||||
*/
|
||||
function purge_cf_cache()
|
||||
{
|
||||
|
||||
$this->objects = $this->main_instance->get_objects();
|
||||
$error = '';
|
||||
|
||||
if( ! $this->objects['cloudflare']->purge_cache($error) ) {
|
||||
WP_CLI::error($error);
|
||||
}
|
||||
|
||||
WP_CLI::success( __('Cache purged successfully', 'wp-cloudflare-page-cache') );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Purge the whole Varnish cache only
|
||||
*
|
||||
* @when after_wp_load
|
||||
*/
|
||||
function purge_varnish_cache()
|
||||
{
|
||||
|
||||
$this->objects = $this->main_instance->get_objects();
|
||||
$error = '';
|
||||
|
||||
if( ! $this->objects['varnish']->purge_whole_cache($error) ) {
|
||||
WP_CLI::error($error);
|
||||
}
|
||||
|
||||
WP_CLI::success( __('Cache purged successfully', 'wp-cloudflare-page-cache') );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Purge the whole OPcache cache only
|
||||
*
|
||||
* @when after_wp_load
|
||||
*/
|
||||
function purge_opcache_cache()
|
||||
{
|
||||
|
||||
$this->objects = $this->main_instance->get_objects();
|
||||
$this->objects['cache_controller']->purge_opcache();
|
||||
|
||||
WP_CLI::success( __('Cache purged successfully', 'wp-cloudflare-page-cache') );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Purge the whole Fallback cache only
|
||||
*
|
||||
* @when after_wp_load
|
||||
*/
|
||||
function purge_fallback_cache()
|
||||
{
|
||||
|
||||
$this->objects = $this->main_instance->get_objects();
|
||||
$this->objects['fallback_cache']->fallback_cache_purge_all();
|
||||
|
||||
WP_CLI::success( __('Cache purged successfully', 'wp-cloudflare-page-cache') );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enable Cloudflare page cache
|
||||
*
|
||||
* @when after_wp_load
|
||||
*/
|
||||
function enable_cf_cache()
|
||||
{
|
||||
|
||||
$this->objects = $this->main_instance->get_objects();
|
||||
$error = '';
|
||||
|
||||
if( ! $this->objects['cloudflare']->enable_page_cache($error) ) {
|
||||
WP_CLI::error($error);
|
||||
}
|
||||
|
||||
WP_CLI::success( __('Cache enabled successfully', 'wp-cloudflare-page-cache') );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Disable Cloudflare page cache
|
||||
*
|
||||
* @when after_wp_load
|
||||
*/
|
||||
function disable_cf_cache()
|
||||
{
|
||||
|
||||
$this->objects = $this->main_instance->get_objects();
|
||||
$error = '';
|
||||
|
||||
if( ! $this->objects['cloudflare']->disable_page_cache($error) ) {
|
||||
WP_CLI::error($error);
|
||||
}
|
||||
|
||||
WP_CLI::success( __('Cache enabled successfully', 'wp-cloudflare-page-cache') );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test Cloudflare page cache
|
||||
*
|
||||
* @when after_wp_load
|
||||
*/
|
||||
function test_cf_cache()
|
||||
{
|
||||
|
||||
$this->objects = $this->main_instance->get_objects();
|
||||
$error_dynamic = '';
|
||||
$error_static = '';
|
||||
|
||||
$url_static_resource = SWCFPC_PLUGIN_URL.'assets/testcache.html';
|
||||
$url_dynamic_resource = home_url();
|
||||
|
||||
$return_array['static_resource_url'] = $url_static_resource;
|
||||
$return_array['dynamic_resource_url'] = $url_dynamic_resource;
|
||||
|
||||
$headers_dyamic_resource = $this->objects['cloudflare']->page_cache_test( $url_dynamic_resource, $error_dynamic );
|
||||
|
||||
if( ! $headers_dyamic_resource ) {
|
||||
|
||||
$headers_static_resource = $this->objects['cloudflare']->page_cache_test($url_static_resource, $error_static, true);
|
||||
$error = '';
|
||||
|
||||
// Error on both dynamic and static test
|
||||
if (!$headers_static_resource) {
|
||||
|
||||
$error .= __('Page caching seems not working for both dynamic and static pages.', 'wp-cloudflare-page-cache');
|
||||
$error .= '<br/><br/>';
|
||||
$error .= sprintf( __('Error on dynamic page (%1$s): %2$s', 'wp-cloudflare-page-cache'), $url_dynamic_resource, $error_dynamic);
|
||||
$error .= '<br/><br/>';
|
||||
$error .= sprintf( __('Error on static resource (%1$s): %2$s', 'wp-cloudflare-page-cache'), $url_static_resource, $error_static);
|
||||
|
||||
} // Error on dynamic test only
|
||||
else {
|
||||
|
||||
$error .= sprintf( __('Page caching is working for static page (%s) but seems not working for dynamic pages.', 'wp-cloudflare-page-cache'), $url_static_resource);
|
||||
$error .= '<br/><br/>';
|
||||
$error .= sprintf( __('Error on dynamic page (%1$s): %2$s', 'wp-cloudflare-page-cache'), $url_dynamic_resource, $error_dynamic);
|
||||
|
||||
}
|
||||
|
||||
WP_CLI::error($error);
|
||||
|
||||
}
|
||||
|
||||
WP_CLI::success( __('Page caching is working properly', 'wp-cloudflare-page-cache') );
|
||||
|
||||
}
|
||||
|
||||
}
|
After Width: | Height: | Size: 4.7 KiB |
|
@ -0,0 +1,505 @@
|
|||
<?php
|
||||
/**
|
||||
* WP Background Process
|
||||
*
|
||||
* @package WP-Background-Processing
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract WP_Background_Process class.
|
||||
*
|
||||
* @abstract
|
||||
* @extends WP_Async_Request
|
||||
*/
|
||||
abstract class WP_Background_Process extends WP_Async_Request {
|
||||
|
||||
/**
|
||||
* Action
|
||||
*
|
||||
* (default value: 'background_process')
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $action = 'background_process';
|
||||
|
||||
/**
|
||||
* Start time of current process.
|
||||
*
|
||||
* (default value: 0)
|
||||
*
|
||||
* @var int
|
||||
* @access protected
|
||||
*/
|
||||
protected $start_time = 0;
|
||||
|
||||
/**
|
||||
* Cron_hook_identifier
|
||||
*
|
||||
* @var mixed
|
||||
* @access protected
|
||||
*/
|
||||
protected $cron_hook_identifier;
|
||||
|
||||
/**
|
||||
* Cron_interval_identifier
|
||||
*
|
||||
* @var mixed
|
||||
* @access protected
|
||||
*/
|
||||
protected $cron_interval_identifier;
|
||||
|
||||
/**
|
||||
* Initiate new background process
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->cron_hook_identifier = $this->identifier . '_cron';
|
||||
$this->cron_interval_identifier = $this->identifier . '_cron_interval';
|
||||
|
||||
add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) );
|
||||
add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function dispatch() {
|
||||
// Schedule the cron healthcheck.
|
||||
$this->schedule_event();
|
||||
|
||||
// Perform remote post.
|
||||
return parent::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Push to queue
|
||||
*
|
||||
* @param mixed $data Data.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function push_to_queue( $data ) {
|
||||
$this->data[] = $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save queue
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function save() {
|
||||
$key = $this->generate_key();
|
||||
|
||||
if ( ! empty( $this->data ) ) {
|
||||
update_site_option( $key, $this->data );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update queue
|
||||
*
|
||||
* @param string $key Key.
|
||||
* @param array $data Data.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function update( $key, $data ) {
|
||||
if ( ! empty( $data ) ) {
|
||||
update_site_option( $key, $data );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete queue
|
||||
*
|
||||
* @param string $key Key.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function delete( $key ) {
|
||||
delete_site_option( $key );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate key
|
||||
*
|
||||
* Generates a unique key based on microtime. Queue items are
|
||||
* given a unique key so that they can be merged upon save.
|
||||
*
|
||||
* @param int $length Length.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generate_key( $length = 64 ) {
|
||||
$unique = md5( microtime() . rand() );
|
||||
$prepend = $this->identifier . '_batch_';
|
||||
|
||||
return substr( $prepend . $unique, 0, $length );
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe process queue
|
||||
*
|
||||
* Checks whether data exists within the queue and that
|
||||
* the process is not already running.
|
||||
*/
|
||||
public function maybe_handle() {
|
||||
// Don't lock up other requests while processing
|
||||
session_write_close();
|
||||
|
||||
if ( $this->is_process_running() ) {
|
||||
// Background process already running.
|
||||
wp_die();
|
||||
}
|
||||
|
||||
if ( $this->is_queue_empty() ) {
|
||||
// No data to process.
|
||||
wp_die();
|
||||
}
|
||||
|
||||
check_ajax_referer( $this->identifier, 'nonce' );
|
||||
|
||||
$this->handle();
|
||||
|
||||
wp_die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is queue empty
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_queue_empty() {
|
||||
global $wpdb;
|
||||
|
||||
$table = $wpdb->options;
|
||||
$column = 'option_name';
|
||||
|
||||
if ( is_multisite() ) {
|
||||
$table = $wpdb->sitemeta;
|
||||
$column = 'meta_key';
|
||||
}
|
||||
|
||||
$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
|
||||
|
||||
$count = $wpdb->get_var( $wpdb->prepare( "
|
||||
SELECT COUNT(*)
|
||||
FROM {$table}
|
||||
WHERE {$column} LIKE %s
|
||||
", $key ) );
|
||||
|
||||
return ( $count > 0 ) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is process running
|
||||
*
|
||||
* Check whether the current process is already running
|
||||
* in a background process.
|
||||
*/
|
||||
protected function is_process_running() {
|
||||
if ( get_site_transient( $this->identifier . '_process_lock' ) ) {
|
||||
// Process already running.
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock process
|
||||
*
|
||||
* Lock the process so that multiple instances can't run simultaneously.
|
||||
* Override if applicable, but the duration should be greater than that
|
||||
* defined in the time_exceeded() method.
|
||||
*/
|
||||
protected function lock_process() {
|
||||
$this->start_time = time(); // Set start time of current process.
|
||||
|
||||
$lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 60; // 1 minute
|
||||
$lock_duration = apply_filters( $this->identifier . '_queue_lock_time', $lock_duration );
|
||||
|
||||
set_site_transient( $this->identifier . '_process_lock', microtime(), $lock_duration );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock process
|
||||
*
|
||||
* Unlock the process so that other instances can spawn.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function unlock_process() {
|
||||
delete_site_transient( $this->identifier . '_process_lock' );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get batch
|
||||
*
|
||||
* @return stdClass Return the first batch from the queue
|
||||
*/
|
||||
protected function get_batch() {
|
||||
global $wpdb;
|
||||
|
||||
$table = $wpdb->options;
|
||||
$column = 'option_name';
|
||||
$key_column = 'option_id';
|
||||
$value_column = 'option_value';
|
||||
|
||||
if ( is_multisite() ) {
|
||||
$table = $wpdb->sitemeta;
|
||||
$column = 'meta_key';
|
||||
$key_column = 'meta_id';
|
||||
$value_column = 'meta_value';
|
||||
}
|
||||
|
||||
$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
|
||||
|
||||
$query = $wpdb->get_row( $wpdb->prepare( "
|
||||
SELECT *
|
||||
FROM {$table}
|
||||
WHERE {$column} LIKE %s
|
||||
ORDER BY {$key_column} ASC
|
||||
LIMIT 1
|
||||
", $key ) );
|
||||
|
||||
$batch = new stdClass();
|
||||
$batch->key = $query->$column;
|
||||
$batch->data = maybe_unserialize( $query->$value_column );
|
||||
|
||||
return $batch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle
|
||||
*
|
||||
* Pass each queue item to the task handler, while remaining
|
||||
* within server memory and time limit constraints.
|
||||
*/
|
||||
protected function handle() {
|
||||
$this->lock_process();
|
||||
|
||||
do {
|
||||
$batch = $this->get_batch();
|
||||
|
||||
foreach ( $batch->data as $key => $value ) {
|
||||
$task = $this->task( $value );
|
||||
|
||||
if ( false !== $task ) {
|
||||
$batch->data[ $key ] = $task;
|
||||
} else {
|
||||
unset( $batch->data[ $key ] );
|
||||
}
|
||||
|
||||
if ( $this->time_exceeded() || $this->memory_exceeded() ) {
|
||||
// Batch limits reached.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Update or delete current batch.
|
||||
if ( ! empty( $batch->data ) ) {
|
||||
$this->update( $batch->key, $batch->data );
|
||||
} else {
|
||||
$this->delete( $batch->key );
|
||||
}
|
||||
} while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() );
|
||||
|
||||
$this->unlock_process();
|
||||
|
||||
// Start next batch or complete process.
|
||||
if ( ! $this->is_queue_empty() ) {
|
||||
$this->dispatch();
|
||||
} else {
|
||||
$this->complete();
|
||||
}
|
||||
|
||||
wp_die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Memory exceeded
|
||||
*
|
||||
* Ensures the batch process never exceeds 90%
|
||||
* of the maximum WordPress memory.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function memory_exceeded() {
|
||||
$memory_limit = $this->get_memory_limit() * 0.9; // 90% of max memory
|
||||
$current_memory = memory_get_usage( true );
|
||||
$return = false;
|
||||
|
||||
if ( $current_memory >= $memory_limit ) {
|
||||
$return = true;
|
||||
}
|
||||
|
||||
return apply_filters( $this->identifier . '_memory_exceeded', $return );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get memory limit
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function get_memory_limit() {
|
||||
if ( function_exists( 'ini_get' ) ) {
|
||||
$memory_limit = ini_get( 'memory_limit' );
|
||||
} else {
|
||||
// Sensible default.
|
||||
$memory_limit = '128M';
|
||||
}
|
||||
|
||||
if ( ! $memory_limit || - 1 === intval( $memory_limit ) ) {
|
||||
// Unlimited, set to 32GB.
|
||||
$memory_limit = '32000M';
|
||||
}
|
||||
|
||||
return wp_convert_hr_to_bytes( $memory_limit );
|
||||
}
|
||||
|
||||
/**
|
||||
* Time exceeded.
|
||||
*
|
||||
* Ensures the batch never exceeds a sensible time limit.
|
||||
* A timeout limit of 30s is common on shared hosting.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function time_exceeded() {
|
||||
$finish = $this->start_time + apply_filters( $this->identifier . '_default_time_limit', 20 ); // 20 seconds
|
||||
$return = false;
|
||||
|
||||
if ( time() >= $finish ) {
|
||||
$return = true;
|
||||
}
|
||||
|
||||
return apply_filters( $this->identifier . '_time_exceeded', $return );
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete.
|
||||
*
|
||||
* Override if applicable, but ensure that the below actions are
|
||||
* performed, or, call parent::complete().
|
||||
*/
|
||||
protected function complete() {
|
||||
// Unschedule the cron healthcheck.
|
||||
$this->clear_scheduled_event();
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule cron healthcheck
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param mixed $schedules Schedules.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function schedule_cron_healthcheck( $schedules ) {
|
||||
$interval = apply_filters( $this->identifier . '_cron_interval', 5 );
|
||||
|
||||
if ( property_exists( $this, 'cron_interval' ) ) {
|
||||
$interval = apply_filters( $this->identifier . '_cron_interval', $this->cron_interval );
|
||||
}
|
||||
|
||||
// Adds every 5 minutes to the existing schedules.
|
||||
$schedules[ $this->identifier . '_cron_interval' ] = array(
|
||||
'interval' => MINUTE_IN_SECONDS * $interval,
|
||||
'display' => sprintf( __( 'Every %d Minutes' ), $interval ),
|
||||
);
|
||||
|
||||
return $schedules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle cron healthcheck
|
||||
*
|
||||
* Restart the background process if not already running
|
||||
* and data exists in the queue.
|
||||
*/
|
||||
public function handle_cron_healthcheck() {
|
||||
if ( $this->is_process_running() ) {
|
||||
// Background process already running.
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( $this->is_queue_empty() ) {
|
||||
// No data to process.
|
||||
$this->clear_scheduled_event();
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->handle();
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule event
|
||||
*/
|
||||
protected function schedule_event() {
|
||||
if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) {
|
||||
wp_schedule_event( time(), $this->cron_interval_identifier, $this->cron_hook_identifier );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear scheduled event
|
||||
*/
|
||||
protected function clear_scheduled_event() {
|
||||
$timestamp = wp_next_scheduled( $this->cron_hook_identifier );
|
||||
|
||||
if ( $timestamp ) {
|
||||
wp_unschedule_event( $timestamp, $this->cron_hook_identifier );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel Process
|
||||
*
|
||||
* Stop processing queue items, clear cronjob and delete batch.
|
||||
*
|
||||
*/
|
||||
public function cancel_process() {
|
||||
if ( ! $this->is_queue_empty() ) {
|
||||
$batch = $this->get_batch();
|
||||
|
||||
$this->delete( $batch->key );
|
||||
|
||||
wp_clear_scheduled_hook( $this->cron_hook_identifier );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Task
|
||||
*
|
||||
* Override this method to perform any actions required on each
|
||||
* queue item. Return the modified item for further processing
|
||||
* in the next pass through. Or, return false to remove the
|
||||
* item from the queue.
|
||||
*
|
||||
* @param mixed $item Queue item to iterate over.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function task( $item );
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
<?php return array('dependencies' => array(), 'version' => 'bacc1f000efc9f479fc0');
|
|
@ -0,0 +1,860 @@
|
|||
<?php
|
||||
/**
|
||||
* The deactivate feedback model class for ThemeIsle SDK
|
||||
*
|
||||
* @package ThemeIsleSDK
|
||||
* @subpackage Feedback
|
||||
* @copyright Copyright (c) 2017, Marius Cristea
|
||||
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace ThemeisleSDK\Modules;
|
||||
|
||||
use ThemeisleSDK\Common\Abstract_Module;
|
||||
use ThemeisleSDK\Product;
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall feedback module for ThemeIsle SDK.
|
||||
*/
|
||||
class Uninstall_Feedback extends Abstract_Module {
|
||||
/**
|
||||
* How many seconds before the deactivation window is triggered for themes?
|
||||
*
|
||||
* @var int Number of days.
|
||||
*/
|
||||
const AUTO_TRIGGER_DEACTIVATE_WINDOW_SECONDS = 3;
|
||||
/**
|
||||
* How many days before the deactivation window pops up again for the theme?
|
||||
*
|
||||
* @var int Number of days.
|
||||
*/
|
||||
const PAUSE_DEACTIVATE_WINDOW_DAYS = 100;
|
||||
/**
|
||||
* Where to send the data.
|
||||
*
|
||||
* @var string Endpoint url.
|
||||
*/
|
||||
const FEEDBACK_ENDPOINT = 'https://api.themeisle.com/tracking/uninstall';
|
||||
|
||||
/**
|
||||
* Default options for plugins.
|
||||
*
|
||||
* @var array $options_plugin The main options list for plugins.
|
||||
*/
|
||||
private $options_plugin = array(
|
||||
'I found a better plugin' => array(
|
||||
'id' => 3,
|
||||
'type' => 'text',
|
||||
'placeholder' => 'What\'s the plugin\'s name?',
|
||||
),
|
||||
'I could not get the plugin to work' => array(
|
||||
'type' => 'textarea',
|
||||
'placeholder' => 'What problem are you experiencing?',
|
||||
'id' => 4,
|
||||
),
|
||||
'I no longer need the plugin' => array(
|
||||
'id' => 5,
|
||||
'type' => 'textarea',
|
||||
'placeholder' => 'If you could improve one thing about our product, what would it be?',
|
||||
),
|
||||
'It\'s a temporary deactivation. I\'m just debugging an issue.' => array(
|
||||
'type' => 'textarea',
|
||||
'placeholder' => 'What problem are you experiencing?',
|
||||
'id' => 6,
|
||||
),
|
||||
);
|
||||
/**
|
||||
* Default options for theme.
|
||||
*
|
||||
* @var array $options_theme The main options list for themes.
|
||||
*/
|
||||
private $options_theme = array(
|
||||
'I don\'t know how to make it look like demo' => array(
|
||||
'id' => 7,
|
||||
),
|
||||
'It lacks options' => array(
|
||||
'placeholder' => 'What option is missing?',
|
||||
'type' => 'text',
|
||||
'id' => 8,
|
||||
),
|
||||
'Is not working with a plugin that I need' => array(
|
||||
'id' => 9,
|
||||
'type' => 'text',
|
||||
'placeholder' => 'What is the name of the plugin',
|
||||
),
|
||||
'I want to try a new design, I don\'t like {theme} style' => array(
|
||||
'id' => 10,
|
||||
),
|
||||
);
|
||||
/**
|
||||
* Default other option.
|
||||
*
|
||||
* @var array $other The other option
|
||||
*/
|
||||
private $other = array(
|
||||
'Other' => array(
|
||||
'id' => 999,
|
||||
'type' => 'textarea',
|
||||
'placeholder' => 'What can we do better?',
|
||||
),
|
||||
);
|
||||
/**
|
||||
* Default heading for plugin.
|
||||
*
|
||||
* @var string $heading_plugin The heading of the modal
|
||||
*/
|
||||
private $heading_plugin = 'What\'s wrong?';
|
||||
/**
|
||||
* Default heading for theme.
|
||||
*
|
||||
* @var string $heading_theme The heading of the modal
|
||||
*/
|
||||
private $heading_theme = 'What does not work for you in {theme}?';
|
||||
/**
|
||||
* Default submit button action text.
|
||||
*
|
||||
* @var string $button_submit The text of the deactivate button
|
||||
*/
|
||||
private $button_submit = 'Submit & Deactivate';
|
||||
/**
|
||||
* Default cancel button.
|
||||
*
|
||||
* @var string $button_cancel The text of the cancel button
|
||||
*/
|
||||
private $button_cancel = 'Skip & Deactivate';
|
||||
|
||||
/**
|
||||
* Loads the additional resources
|
||||
*/
|
||||
public function load_resources() {
|
||||
$screen = get_current_screen();
|
||||
|
||||
if ( ! $screen || ! in_array( $screen->id, array( 'theme-install', 'plugins' ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->add_feedback_popup_style();
|
||||
|
||||
if ( $this->product->get_type() === 'theme' ) {
|
||||
$this->add_theme_feedback_drawer_js();
|
||||
$this->render_theme_feedback_popup();
|
||||
|
||||
return;
|
||||
}
|
||||
$this->add_plugin_feedback_popup_js();
|
||||
$this->render_plugin_feedback_popup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render theme feedback drawer.
|
||||
*/
|
||||
private function render_theme_feedback_popup() {
|
||||
$heading = str_replace( '{theme}', $this->product->get_name(), $this->heading_theme );
|
||||
$button_submit = apply_filters( $this->product->get_key() . '_feedback_deactivate_button_submit', 'Submit' );
|
||||
$options = $this->options_theme;
|
||||
$options = $this->randomize_options( apply_filters( $this->product->get_key() . '_feedback_deactivate_options', $options ) );
|
||||
$info_disclosure_link = '<a href="#" class="info-disclosure-link">' . apply_filters( $this->product->get_slug() . '_themeisle_sdk_info_collect_cta', 'What info do we collect?' ) . '</a>';
|
||||
|
||||
$options += $this->other;
|
||||
|
||||
?>
|
||||
<div class="ti-theme-uninstall-feedback-drawer ti-feedback">
|
||||
<div class="popup--header">
|
||||
<h5><?php echo wp_kses( $heading, array( 'span' => true ) ); ?> </h5>
|
||||
<button class="toggle"><span>×</span></button>
|
||||
</div><!--/.popup--header-->
|
||||
<div class="popup--body">
|
||||
<?php $this->render_options_list( $options ); ?>
|
||||
</div><!--/.popup--body-->
|
||||
<div class="popup--footer">
|
||||
<div class="actions">
|
||||
<?php
|
||||
echo wp_kses_post( $info_disclosure_link );
|
||||
echo wp_kses_post( $this->get_disclosure_labels() );
|
||||
echo '<div class="buttons">';
|
||||
echo get_submit_button( //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, Function has an internal sanitization.
|
||||
$button_submit,
|
||||
'secondary',
|
||||
$this->product->get_key() . 'ti-deactivate-yes',
|
||||
false,
|
||||
array(
|
||||
'data-after-text' => $button_submit,
|
||||
'disabled' => true,
|
||||
)
|
||||
);
|
||||
echo '</div>';
|
||||
?>
|
||||
</div><!--/.actions-->
|
||||
</div><!--/.popup--footer-->
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Add feedback styles.
|
||||
*/
|
||||
private function add_feedback_popup_style() {
|
||||
?>
|
||||
<style>
|
||||
.ti-feedback {
|
||||
background: #fff;
|
||||
max-width: 400px;
|
||||
z-index: 10000;
|
||||
box-shadow: 0 0 15px -5px rgba(0, 0, 0, .5);
|
||||
transition: all .3s ease-out;
|
||||
}
|
||||
|
||||
|
||||
.ti-feedback .popup--header {
|
||||
position: relative;
|
||||
background-color: #23A1CE;
|
||||
}
|
||||
|
||||
.ti-feedback .popup--header h5 {
|
||||
margin: 0;
|
||||
font-size: 16px;
|
||||
padding: 15px;
|
||||
color: #fff;
|
||||
font-weight: 600;
|
||||
text-align: center;
|
||||
letter-spacing: .3px;
|
||||
}
|
||||
|
||||
.ti-feedback .popup--body {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.ti-feedback .popup--form {
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.ti-feedback .popup--form input[type="radio"] {
|
||||
<?php echo is_rtl() ? 'margin: 0 0 0 10px;' : 'margin: 0 10px 0 0;'; ?>
|
||||
}
|
||||
|
||||
.ti-feedback .popup--form input[type="radio"]:checked ~ textarea {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.ti-feedback .popup--form textarea {
|
||||
width: 100%;
|
||||
margin: 10px 0 0;
|
||||
display: none;
|
||||
max-height: 150px;
|
||||
}
|
||||
|
||||
.ti-feedback li {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.ti-feedback li label {
|
||||
max-width: 90%;
|
||||
}
|
||||
|
||||
.ti-feedback li:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.ti-feedback .popup--footer {
|
||||
padding: 0 15px 15px;
|
||||
}
|
||||
|
||||
.ti-feedback .actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.info-disclosure-link {
|
||||
width: 100%;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.ti-feedback .info-disclosure-content {
|
||||
max-height: 0;
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
transition: .3s ease;
|
||||
}
|
||||
|
||||
.ti-feedback .info-disclosure-content.active {
|
||||
max-height: 300px;
|
||||
}
|
||||
|
||||
.ti-feedback .info-disclosure-content p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.ti-feedback .info-disclosure-content ul {
|
||||
margin: 10px 0;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.ti-feedback .info-disclosure-content ul li {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 0;
|
||||
padding: 5px 0;
|
||||
border-bottom: 1px solid #ccc;
|
||||
}
|
||||
|
||||
.ti-feedback .buttons {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.ti-feedback .buttons input:last-child {
|
||||
<?php echo is_rtl() ? 'margin-right: auto;' : 'margin-left: auto;'; ?>
|
||||
}
|
||||
|
||||
.ti-theme-uninstall-feedback-drawer {
|
||||
border-top-left-radius: 5px;
|
||||
position: fixed;
|
||||
top: 100%;
|
||||
right: 15px;
|
||||
}
|
||||
|
||||
.ti-theme-uninstall-feedback-drawer.active {
|
||||
transform: translateY(-100%);
|
||||
}
|
||||
|
||||
.ti-theme-uninstall-feedback-drawer .popup--header {
|
||||
border-top-left-radius: 5px;
|
||||
}
|
||||
|
||||
.ti-theme-uninstall-feedback-drawer .popup--header .toggle {
|
||||
position: absolute;
|
||||
padding: 3px 0;
|
||||
width: 30px;
|
||||
top: -26px;
|
||||
right: 0;
|
||||
cursor: pointer;
|
||||
border-top-left-radius: 5px;
|
||||
border-top-right-radius: 5px;
|
||||
font-size: 20px;
|
||||
background-color: #23A1CE;
|
||||
color: #fff;
|
||||
border: none;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.ti-theme-uninstall-feedback-drawer .toggle span {
|
||||
margin: 0;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.ti-theme-uninstall-feedback-drawer:not(.active) .toggle span {
|
||||
transform: rotate(45deg);
|
||||
}
|
||||
|
||||
.ti-theme-uninstall-feedback-drawer .popup--header .toggle:hover {
|
||||
background-color: #1880a5;
|
||||
}
|
||||
|
||||
|
||||
.ti-plugin-uninstall-feedback-popup .popup--header:before {
|
||||
content: "";
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
<?php
|
||||
echo is_rtl() ?
|
||||
'right: -10px;
|
||||
border-top: 20px solid transparent;
|
||||
border-left: 20px solid #23A1CE;
|
||||
border-bottom: 20px solid transparent;' :
|
||||
'left: -10px;
|
||||
border-top: 20px solid transparent;
|
||||
border-right: 20px solid #23A1CE;
|
||||
border-bottom: 20px solid transparent;';
|
||||
?>
|
||||
}
|
||||
|
||||
.ti-plugin-uninstall-feedback-popup {
|
||||
display: none;
|
||||
position: absolute;
|
||||
white-space: normal;
|
||||
width: 400px;
|
||||
<?php echo is_rtl() ? 'right: calc( 100% + 15px );' : 'left: calc( 100% + 15px );'; ?>
|
||||
top: -15px;
|
||||
}
|
||||
|
||||
.ti-plugin-uninstall-feedback-popup.sending-feedback .popup--body i {
|
||||
animation: rotation 2s infinite linear;
|
||||
display: block;
|
||||
float: none;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
margin: 0 auto;
|
||||
height: 100%;
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.ti-plugin-uninstall-feedback-popup.sending-feedback .popup--body i:before {
|
||||
padding: 0;
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
color: #b4b9be
|
||||
}
|
||||
|
||||
|
||||
.ti-plugin-uninstall-feedback-popup.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
tr[data-plugin^="<?php echo esc_attr( $this->product->get_slug() ); ?>"] .deactivate {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
body.ti-feedback-open .ti-feedback-overlay {
|
||||
content: "";
|
||||
display: block;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
left: 0;
|
||||
z-index: 10000;
|
||||
position: fixed;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.ti-plugin-uninstall-feedback-popup {
|
||||
position: fixed;
|
||||
max-width: 100%;
|
||||
margin: 0 auto;
|
||||
left: 50%;
|
||||
top: 50px;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
.ti-plugin-uninstall-feedback-popup .popup--header:before {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme feedback drawer JS.
|
||||
*/
|
||||
private function add_theme_feedback_drawer_js() {
|
||||
$key = $this->product->get_key();
|
||||
?>
|
||||
<script type="text/javascript" id="ti-deactivate-js">
|
||||
(function ($) {
|
||||
$(document).ready(function () {
|
||||
setTimeout(function () {
|
||||
$('.ti-theme-uninstall-feedback-drawer').addClass('active');
|
||||
}, <?php echo absint( self::AUTO_TRIGGER_DEACTIVATE_WINDOW_SECONDS * 1000 ); ?> );
|
||||
|
||||
$('.ti-theme-uninstall-feedback-drawer .toggle').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
$('.ti-theme-uninstall-feedback-drawer').toggleClass('active');
|
||||
});
|
||||
|
||||
$('.info-disclosure-link').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
$('.info-disclosure-content').toggleClass('active');
|
||||
});
|
||||
|
||||
$('.ti-theme-uninstall-feedback-drawer input[type="radio"]').on('change', function () {
|
||||
var radio = $(this);
|
||||
if (radio.parent().find('textarea').length > 0 &&
|
||||
radio.parent().find('textarea').val().length === 0) {
|
||||
$('#<?php echo esc_attr( $key ); ?>ti-deactivate-yes').attr('disabled', 'disabled');
|
||||
radio.parent().find('textarea').on('keyup', function (e) {
|
||||
if ($(this).val().length === 0) {
|
||||
$('#<?php echo esc_attr( $key ); ?>ti-deactivate-yes').attr('disabled', 'disabled');
|
||||
} else {
|
||||
$('#<?php echo esc_attr( $key ); ?>ti-deactivate-yes').removeAttr('disabled');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$('#<?php echo esc_attr( $key ); ?>ti-deactivate-yes').removeAttr('disabled');
|
||||
}
|
||||
});
|
||||
|
||||
$('#<?php echo esc_attr( $key ); ?>ti-deactivate-yes').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
var selectedOption = $(
|
||||
'.ti-theme-uninstall-feedback-drawer input[name="ti-deactivate-option"]:checked');
|
||||
$.post(ajaxurl, {
|
||||
'action': '<?php echo esc_attr( $key ) . '_uninstall_feedback'; ?>',
|
||||
'nonce': '<?php echo esc_attr( wp_create_nonce( (string) __CLASS__ ) ); ?>',
|
||||
'id': selectedOption.parent().attr('ti-option-id'),
|
||||
'msg': selectedOption.parent().find('textarea').val(),
|
||||
'type': 'theme',
|
||||
'key': '<?php echo esc_attr( $key ); ?>'
|
||||
});
|
||||
$('.ti-theme-uninstall-feedback-drawer').fadeOut();
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
||||
|
||||
</script>
|
||||
<?php
|
||||
do_action( $this->product->get_key() . '_uninstall_feedback_after_js' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the options list.
|
||||
*
|
||||
* @param array $options the options for the feedback form.
|
||||
*/
|
||||
private function render_options_list( $options ) {
|
||||
$key = $this->product->get_key();
|
||||
$inputs_row_map = [
|
||||
'text' => 1,
|
||||
'textarea' => 2,
|
||||
];
|
||||
?>
|
||||
<ul class="popup--form">
|
||||
<?php foreach ( $options as $title => $attributes ) { ?>
|
||||
<li ti-option-id="<?php echo esc_attr( $attributes['id'] ); ?>">
|
||||
<input type="radio" name="ti-deactivate-option" id="<?php echo esc_attr( $key . $attributes['id'] ); ?>">
|
||||
<label for="<?php echo esc_attr( $key . $attributes['id'] ); ?>">
|
||||
<?php echo esc_attr( str_replace( '{theme}', $this->product->get_name(), $title ) ); ?>
|
||||
</label>
|
||||
<?php
|
||||
if ( array_key_exists( 'type', $attributes ) ) {
|
||||
$placeholder = array_key_exists( 'placeholder', $attributes ) ? $attributes['placeholder'] : '';
|
||||
echo '<textarea width="100%" rows="' . esc_attr( $inputs_row_map[ $attributes['type'] ] ) . '" name="comments" placeholder="' . esc_attr( $placeholder ) . '"></textarea>';
|
||||
}
|
||||
?>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render plugin feedback popup.
|
||||
*/
|
||||
private function render_plugin_feedback_popup() {
|
||||
$button_cancel = apply_filters( $this->product->get_key() . '_feedback_deactivate_button_cancel', $this->button_cancel );
|
||||
$button_submit = apply_filters( $this->product->get_key() . '_feedback_deactivate_button_submit', $this->button_submit );
|
||||
$options = $this->randomize_options( apply_filters( $this->product->get_key() . '_feedback_deactivate_options', $this->options_plugin ) );
|
||||
$info_disclosure_link = '<a href="#" class="info-disclosure-link">' . apply_filters( $this->product->get_slug() . '_themeisle_sdk_info_collect_cta', 'What info do we collect?' ) . '</a>';
|
||||
|
||||
$options += $this->other;
|
||||
?>
|
||||
<div class="ti-plugin-uninstall-feedback-popup ti-feedback" id="<?php echo esc_attr( $this->product->get_slug() . '_uninstall_feedback_popup' ); ?>">
|
||||
<div class="popup--header">
|
||||
<h5><?php echo wp_kses( $this->heading_plugin, array( 'span' => true ) ); ?> </h5>
|
||||
</div><!--/.popup--header-->
|
||||
<div class="popup--body">
|
||||
<?php $this->render_options_list( $options ); ?>
|
||||
</div><!--/.popup--body-->
|
||||
<div class="popup--footer">
|
||||
<div class="actions">
|
||||
<?php
|
||||
echo wp_kses_post( $info_disclosure_link );
|
||||
echo wp_kses_post( $this->get_disclosure_labels() );
|
||||
echo '<div class="buttons">';
|
||||
echo get_submit_button( //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, Function internals are escaped.
|
||||
$button_cancel,
|
||||
'secondary',
|
||||
$this->product->get_key() . 'ti-deactivate-no',
|
||||
false
|
||||
);
|
||||
echo get_submit_button( //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, Function internals are escaped.
|
||||
$button_submit,
|
||||
'primary',
|
||||
$this->product->get_key() . 'ti-deactivate-yes',
|
||||
false,
|
||||
array(
|
||||
'data-after-text' => $button_submit,
|
||||
'disabled' => true,
|
||||
)
|
||||
);
|
||||
echo '</div>';
|
||||
?>
|
||||
</div><!--/.actions-->
|
||||
</div><!--/.popup--footer-->
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Add plugin feedback popup JS
|
||||
*/
|
||||
private function add_plugin_feedback_popup_js() {
|
||||
$popup_id = '#' . $this->product->get_slug() . '_uninstall_feedback_popup';
|
||||
$key = $this->product->get_key();
|
||||
?>
|
||||
<script type="text/javascript" id="ti-deactivate-js">
|
||||
(function ($) {
|
||||
$(document).ready(function () {
|
||||
var targetElement = 'tr[data-plugin^="<?php echo esc_attr( $this->product->get_slug() ); ?>/"] span.deactivate a';
|
||||
var redirectUrl = $(targetElement).attr('href');
|
||||
if ($('.ti-feedback-overlay').length === 0) {
|
||||
$('body').prepend('<div class="ti-feedback-overlay"></div>');
|
||||
}
|
||||
$('<?php echo esc_attr( $popup_id ); ?> ').appendTo($(targetElement).parent());
|
||||
|
||||
$(targetElement).on('click', function (e) {
|
||||
e.preventDefault();
|
||||
$('<?php echo esc_attr( $popup_id ); ?> ').addClass('active');
|
||||
$('body').addClass('ti-feedback-open');
|
||||
$('.ti-feedback-overlay').on('click', function () {
|
||||
$('<?php echo esc_attr( $popup_id ); ?> ').removeClass('active');
|
||||
$('body').removeClass('ti-feedback-open');
|
||||
});
|
||||
});
|
||||
|
||||
$('<?php echo esc_attr( $popup_id ); ?> .info-disclosure-link').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
$(this).parent().find('.info-disclosure-content').toggleClass('active');
|
||||
});
|
||||
|
||||
$('<?php echo esc_attr( $popup_id ); ?> input[type="radio"]').on('change', function () {
|
||||
var radio = $(this);
|
||||
if (radio.parent().find('textarea').length > 0 &&
|
||||
radio.parent().find('textarea').val().length === 0) {
|
||||
$('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-yes').attr('disabled', 'disabled');
|
||||
radio.parent().find('textarea').on('keyup', function (e) {
|
||||
if ($(this).val().length === 0) {
|
||||
$('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-yes').attr('disabled', 'disabled');
|
||||
} else {
|
||||
$('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-yes').removeAttr('disabled');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-yes').removeAttr('disabled');
|
||||
}
|
||||
});
|
||||
|
||||
$('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-no').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
$(targetElement).unbind('click');
|
||||
$('body').removeClass('ti-feedback-open');
|
||||
$('<?php echo esc_attr( $popup_id ); ?>').remove();
|
||||
if (redirectUrl !== '') {
|
||||
location.href = redirectUrl;
|
||||
}
|
||||
});
|
||||
|
||||
$('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-yes').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
$(targetElement).unbind('click');
|
||||
var selectedOption = $(
|
||||
'<?php echo esc_attr( $popup_id ); ?> input[name="ti-deactivate-option"]:checked');
|
||||
var data = {
|
||||
'action': '<?php echo esc_attr( $key ) . '_uninstall_feedback'; ?>',
|
||||
'nonce': '<?php echo esc_attr( wp_create_nonce( (string) __CLASS__ ) ); ?>',
|
||||
'id': selectedOption.parent().attr('ti-option-id'),
|
||||
'msg': selectedOption.parent().find('textarea').val(),
|
||||
'type': 'plugin',
|
||||
'key': '<?php echo esc_attr( $key ); ?>'
|
||||
};
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: ajaxurl,
|
||||
data: data,
|
||||
complete() {
|
||||
$('body').removeClass('ti-feedback-open');
|
||||
$('<?php echo esc_attr( $popup_id ); ?>').remove();
|
||||
if (redirectUrl !== '') {
|
||||
location.href = redirectUrl;
|
||||
}
|
||||
},
|
||||
beforeSend() {
|
||||
$('<?php echo esc_attr( $popup_id ); ?>').addClass('sending-feedback');
|
||||
$('<?php echo esc_attr( $popup_id ); ?> .popup--footer').remove();
|
||||
$('<?php echo esc_attr( $popup_id ); ?> .popup--body').html('<i class="dashicons dashicons-update-alt"></i>');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
||||
|
||||
</script>
|
||||
<?php
|
||||
do_action( $this->product->get_key() . '_uninstall_feedback_after_js' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the disclosure labels markup.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_disclosure_labels() {
|
||||
$disclosure_new_labels = apply_filters( $this->product->get_slug() . '_themeisle_sdk_disclosure_content_labels', [], $this->product );
|
||||
$disclosure_labels = array_merge(
|
||||
[
|
||||
'title' => 'Below is a detailed view of all data that ThemeIsle will receive if you fill in this survey. No email address or IP addresses are transmitted after you submit the survey.',
|
||||
'items' => [
|
||||
sprintf( '%s %s version %s %s %s %s', '<strong>', ucwords( $this->product->get_type() ), '</strong>', '<code>', $this->product->get_version(), '</code>' ),
|
||||
sprintf( '%sCurrent website:%s %s %s %s', '<strong>', '</strong>', '<code>', get_site_url(), '</code>' ),
|
||||
sprintf( '%sUsage time:%s %s %s%s', '<strong>', '</strong>', '<code>', ( time() - $this->product->get_install_time() ), 's</code>' ),
|
||||
sprintf( '%s Uninstall reason %s %s Selected reason from the above survey %s ', '<strong>', '</strong>', '<i>', '</i>' ),
|
||||
],
|
||||
],
|
||||
$disclosure_new_labels
|
||||
);
|
||||
|
||||
$info_disclosure_content = '<div class="info-disclosure-content"><p>' . wp_kses_post( $disclosure_labels['title'] ) . '</p><ul>';
|
||||
foreach ( $disclosure_labels['items'] as $disclosure_item ) {
|
||||
$info_disclosure_content .= sprintf( '<li>%s</li>', wp_kses_post( $disclosure_item ) );
|
||||
}
|
||||
$info_disclosure_content .= '</ul></div>';
|
||||
|
||||
return $info_disclosure_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Randomizes the options array.
|
||||
*
|
||||
* @param array $options The options array.
|
||||
*/
|
||||
public function randomize_options( $options ) {
|
||||
$new = array();
|
||||
$keys = array_keys( $options );
|
||||
shuffle( $keys );
|
||||
|
||||
foreach ( $keys as $key ) {
|
||||
$new[ $key ] = $options[ $key ];
|
||||
}
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the deactivate button is clicked.
|
||||
*/
|
||||
public function post_deactivate() {
|
||||
check_ajax_referer( (string) __CLASS__, 'nonce' );
|
||||
|
||||
$this->post_deactivate_or_cancel();
|
||||
|
||||
if ( empty( $_POST['id'] ) ) {
|
||||
|
||||
wp_send_json( [] );
|
||||
|
||||
return;
|
||||
}
|
||||
$this->call_api(
|
||||
array(
|
||||
'type' => 'deactivate',
|
||||
'id' => sanitize_key( $_POST['id'] ),
|
||||
'comment' => isset( $_POST['msg'] ) ? sanitize_textarea_field( $_POST['msg'] ) : '',
|
||||
)
|
||||
);
|
||||
wp_send_json( [] );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the deactivate/cancel button is clicked.
|
||||
*/
|
||||
private function post_deactivate_or_cancel() {
|
||||
if ( ! isset( $_POST['type'] ) || ! isset( $_POST['key'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing, Nonce already present in caller function.
|
||||
return;
|
||||
}
|
||||
if ( 'theme' !== $_POST['type'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing, Nonce already present in caller function.
|
||||
return;
|
||||
}
|
||||
|
||||
set_transient( 'ti_sdk_pause_' . sanitize_text_field( $_POST['key'] ), true, self::PAUSE_DEACTIVATE_WINDOW_DAYS * DAY_IN_SECONDS );//phpcs:ignore WordPress.Security.NonceVerification.Missing, Nonce already present in caller function.
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the API
|
||||
*
|
||||
* @param array $attributes The attributes of the post body.
|
||||
*
|
||||
* @return bool Is the request succesfull?
|
||||
*/
|
||||
protected function call_api( $attributes ) {
|
||||
$slug = $this->product->get_slug();
|
||||
$version = $this->product->get_version();
|
||||
$attributes['slug'] = $slug;
|
||||
$attributes['version'] = $version;
|
||||
$attributes['url'] = get_site_url();
|
||||
$attributes['active_time'] = ( time() - $this->product->get_install_time() );
|
||||
|
||||
$response = wp_remote_post(
|
||||
self::FEEDBACK_ENDPOINT,
|
||||
array(
|
||||
'body' => $attributes,
|
||||
)
|
||||
);
|
||||
|
||||
return is_wp_error( $response );
|
||||
}
|
||||
|
||||
/**
|
||||
* Should we load this object?.
|
||||
*
|
||||
* @param Product $product Product object.
|
||||
*
|
||||
* @return bool Should we load the module?
|
||||
*/
|
||||
public function can_load( $product ) {
|
||||
if ( $this->is_from_partner( $product ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( $product->is_theme() && ( false !== get_transient( 'ti_sdk_pause_' . $product->get_key(), false ) ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
|
||||
return true;
|
||||
}
|
||||
global $pagenow;
|
||||
|
||||
if ( ! isset( $pagenow ) || empty( $pagenow ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $product->is_plugin() && 'plugins.php' !== $pagenow ) {
|
||||
return false;
|
||||
|
||||
}
|
||||
if ( $product->is_theme() && 'theme-install.php' !== $pagenow ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads module hooks.
|
||||
*
|
||||
* @param Product $product Product details.
|
||||
*
|
||||
* @return Uninstall_Feedback Current module instance.
|
||||
*/
|
||||
public function load( $product ) {
|
||||
|
||||
if ( apply_filters( $product->get_key() . '_hide_uninstall_feedback', false ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->product = $product;
|
||||
add_action( 'admin_head', array( $this, 'load_resources' ) );
|
||||
add_action( 'wp_ajax_' . $this->product->get_key() . '_uninstall_feedback', array( $this, 'post_deactivate' ) );
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,400 @@
|
|||
<?php
|
||||
/**
|
||||
* The rollback class for ThemeIsle SDK.
|
||||
*
|
||||
* @package ThemeIsleSDK
|
||||
* @subpackage Rollback
|
||||
* @copyright Copyright (c) 2017, Marius Cristea
|
||||
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace ThemeisleSDK\Modules;
|
||||
|
||||
// Exit if accessed directly.
|
||||
use ThemeisleSDK\Common\Abstract_Module;
|
||||
use ThemeisleSDK\Product;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rollback for ThemeIsle SDK.
|
||||
*/
|
||||
class Rollback extends Abstract_Module {
|
||||
|
||||
/**
|
||||
* Add js scripts for themes rollback.
|
||||
*/
|
||||
public function add_footer() {
|
||||
$screen = get_current_screen();
|
||||
if ( ! isset( $screen->parent_file ) ) {
|
||||
return;
|
||||
}
|
||||
if ( 'themes.php' !== $screen->parent_file ) {
|
||||
return;
|
||||
}
|
||||
if ( ! $this->product->is_theme() ) {
|
||||
return;
|
||||
}
|
||||
$version = $this->get_rollback();
|
||||
if ( empty( $version ) ) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function ($) {
|
||||
setInterval(checkTheme, 500);
|
||||
|
||||
function checkTheme() {
|
||||
var theme = '<?php echo esc_attr( $this->product->get_slug() ); ?>-action';
|
||||
|
||||
if (jQuery('#' + theme).length > 0) {
|
||||
if (jQuery('.theme-overlay.active').is(':visible')) {
|
||||
if (jQuery('#' + theme + '-rollback').length === 0) {
|
||||
jQuery('.theme-actions .active-theme').prepend('<a class="button" style="float:left" id="' + theme + '-rollback" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin-post.php?action=' . $this->product->get_key() . '_rollback' ), $this->product->get_key() . '_rollback' ) ); ?>">Rollback to v<?php echo esc_attr( $version['version'] ); ?></a>')
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
</script>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last rollback for this product.
|
||||
*
|
||||
* @return array The rollback version.
|
||||
*/
|
||||
public function get_rollback() {
|
||||
$rollback = array();
|
||||
$versions = $this->get_api_versions();
|
||||
$versions = apply_filters( $this->product->get_key() . '_rollbacks', $versions );
|
||||
if ( empty( $versions ) ) {
|
||||
return $rollback;
|
||||
}
|
||||
if ( $versions ) {
|
||||
usort( $versions, array( $this, 'sort_rollback_array' ) );
|
||||
foreach ( $versions as $version ) {
|
||||
if ( isset( $version['version'] ) && isset( $version['url'] ) && version_compare( $this->product->get_version(), $version['version'], '>' ) ) {
|
||||
$rollback = $version;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $rollback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get versions array from wp.org
|
||||
*
|
||||
* @return array Array of versions.
|
||||
*/
|
||||
private function get_api_versions() {
|
||||
|
||||
$cache_key = $this->product->get_cache_key();
|
||||
$cache_versions = get_transient( $cache_key );
|
||||
if ( false === $cache_versions ) {
|
||||
$versions = $this->get_remote_versions();
|
||||
set_transient( $cache_key, $versions, 5 * DAY_IN_SECONDS );
|
||||
} else {
|
||||
$versions = is_array( $cache_versions ) ? $cache_versions : array();
|
||||
}
|
||||
|
||||
return $versions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get remote versions zips.
|
||||
*
|
||||
* @return array Array of available versions.
|
||||
*/
|
||||
private function get_remote_versions() {
|
||||
$url = $this->get_versions_api_url();
|
||||
if ( empty( $url ) ) {
|
||||
return [];
|
||||
}
|
||||
$response = function_exists( 'wp_remote_get_wp_remote_get' )
|
||||
? wp_remote_get_wp_remote_get( $url )
|
||||
: wp_remote_get( $url ); //phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return array();
|
||||
}
|
||||
$response = wp_remote_retrieve_body( $response );
|
||||
|
||||
if ( is_serialized( $response ) ) {
|
||||
$response = maybe_unserialize( $response );
|
||||
} else {
|
||||
$response = json_decode( $response );
|
||||
}
|
||||
|
||||
if ( ! is_object( $response ) ) {
|
||||
return array();
|
||||
}
|
||||
if ( ! isset( $response->versions ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$versions = array();
|
||||
foreach ( $response->versions as $key => $value ) {
|
||||
$versions[] = array(
|
||||
'version' => is_object( $value ) ? $value->version : $key,
|
||||
'url' => is_object( $value ) ? $value->file : $value,
|
||||
);
|
||||
}
|
||||
|
||||
return $versions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return url where to check for versions.
|
||||
*
|
||||
* @return string Url where to check for versions.
|
||||
*/
|
||||
private function get_versions_api_url() {
|
||||
if ( $this->product->is_wordpress_available() && $this->product->is_plugin() ) {
|
||||
return sprintf( 'https://api.wordpress.org/plugins/info/1.0/%s', $this->product->get_slug() );
|
||||
}
|
||||
if ( $this->product->is_wordpress_available() && $this->product->is_theme() ) {
|
||||
return sprintf( 'https://api.wordpress.org/themes/info/1.1/?action=theme_information&request[slug]=%s&request[fields][versions]=true', $this->product->get_slug() );
|
||||
}
|
||||
$license = $this->product->get_license();
|
||||
if ( $this->product->requires_license() && strlen( $license ) < 10 ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return sprintf( '%slicense/versions/%s/%s/%s/%s', Product::API_URL, rawurlencode( $this->product->get_name() ), $license, urlencode( get_site_url() ), $this->product->get_version() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the rollback links in the plugin page.
|
||||
*
|
||||
* @param array $links Plugin links.
|
||||
*
|
||||
* @return array $links Altered links.
|
||||
*/
|
||||
public function add_rollback_link( $links ) {
|
||||
$version = $this->get_rollback();
|
||||
if ( empty( $version ) ) {
|
||||
return $links;
|
||||
}
|
||||
$links[] = '<a href="' . wp_nonce_url( admin_url( 'admin-post.php?action=' . $this->product->get_key() . '_rollback' ), $this->product->get_key() . '_rollback' ) . '">' . sprintf( apply_filters( $this->product->get_key() . '_rollback_label', 'Rollback to v%s' ), $version['version'] ) . '</a>';
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the rollback operation.
|
||||
*/
|
||||
public function start_rollback() {
|
||||
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], $this->product->get_key() . '_rollback' ) ) { //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
wp_nonce_ays( '' );
|
||||
}
|
||||
|
||||
if ( $this->product->is_plugin() ) {
|
||||
$this->start_rollback_plugin();
|
||||
|
||||
return;
|
||||
}
|
||||
if ( $this->product->is_theme() ) {
|
||||
$this->start_rollback_theme();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the rollback operation for the plugin.
|
||||
*/
|
||||
private function start_rollback_plugin() {
|
||||
$rollback = $this->get_rollback();
|
||||
$plugin_transient = get_site_transient( 'update_plugins' );
|
||||
$plugin_folder = $this->product->get_slug();
|
||||
$plugin_file = $this->product->get_file();
|
||||
$version = $rollback['version'];
|
||||
$temp_array = array(
|
||||
'slug' => $plugin_folder,
|
||||
'new_version' => $version,
|
||||
'package' => $rollback['url'],
|
||||
);
|
||||
|
||||
$temp_object = (object) $temp_array;
|
||||
$plugin_transient->response[ $plugin_folder . '/' . $plugin_file ] = $temp_object;
|
||||
set_site_transient( 'update_plugins', $plugin_transient );
|
||||
|
||||
$transient = get_transient( $this->product->get_key() . '_warning_rollback' );
|
||||
|
||||
// Style fix for the api link that gets outside the content.
|
||||
echo '<style>body#error-page{word-break:break-word;}</style>';
|
||||
|
||||
if ( false === $transient ) {
|
||||
set_transient( $this->product->get_key() . '_warning_rollback', 'in progress', 30 );
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
||||
$title = sprintf( apply_filters( $this->product->get_key() . '_rollback_message', 'Rolling back %s to v%s' ), $this->product->get_name(), $version );
|
||||
$plugin = $plugin_folder . '/' . $plugin_file;
|
||||
$nonce = 'upgrade-plugin_' . $plugin;
|
||||
$url = 'update.php?action=upgrade-plugin&plugin=' . urlencode( $plugin );
|
||||
$upgrader_skin = new \Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'plugin' ) );
|
||||
$upgrader = new \Plugin_Upgrader( $upgrader_skin );
|
||||
$upgrader->upgrade( $plugin );
|
||||
delete_transient( $this->product->get_key() . '_warning_rollback' );
|
||||
wp_die(
|
||||
'',
|
||||
esc_attr( $title ),
|
||||
array(
|
||||
'response' => 200,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the rollback operation for the theme.
|
||||
*/
|
||||
private function start_rollback_theme() {
|
||||
add_filter( 'update_theme_complete_actions', array( $this, 'alter_links_theme_upgrade' ) );
|
||||
$rollback = $this->get_rollback();
|
||||
$transient = get_site_transient( 'update_themes' );
|
||||
$folder = $this->product->get_slug();
|
||||
$version = $rollback['version'];
|
||||
$temp_array = array(
|
||||
'new_version' => $version,
|
||||
'package' => $rollback['url'],
|
||||
);
|
||||
|
||||
$transient->response[ $folder . '/style.css' ] = $temp_array;
|
||||
set_site_transient( 'update_themes', $transient );
|
||||
|
||||
$transient = get_transient( $this->product->get_key() . '_warning_rollback' );
|
||||
|
||||
// Style fix for the api link that gets outside the content.
|
||||
echo '<style>body#error-page{word-break:break-word;}</style>';
|
||||
|
||||
if ( false === $transient ) {
|
||||
set_transient( $this->product->get_key() . '_warning_rollback', 'in progress', 30 );
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
||||
$title = sprintf( apply_filters( $this->product->get_key() . '_rollback_message', 'Rolling back %s to v%s' ), $this->product->get_name(), $version );
|
||||
$theme = $folder . '/style.css';
|
||||
$nonce = 'upgrade-theme_' . $theme;
|
||||
$url = 'update.php?action=upgrade-theme&theme=' . urlencode( $theme );
|
||||
|
||||
$upgrader = new \Theme_Upgrader( new \Theme_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'theme' ) ) );
|
||||
$upgrader->upgrade( $theme );
|
||||
delete_transient( $this->product->get_key() . '_warning_rollback' );
|
||||
wp_die(
|
||||
'',
|
||||
esc_attr( $title ),
|
||||
array(
|
||||
'response' => 200,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter links and remove duplicate customize message.
|
||||
*
|
||||
* @param array $links Array of old links.
|
||||
*
|
||||
* @return mixed Array of links.
|
||||
*/
|
||||
public function alter_links_theme_upgrade( $links ) {
|
||||
if ( isset( $links['preview'] ) ) {
|
||||
$links['preview'] = str_replace( '<span aria-hidden="true">Customize</span>', '', $links['preview'] );
|
||||
}
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads product object.
|
||||
*
|
||||
* @param Product $product Product object.
|
||||
*
|
||||
* @return bool Should we load the module?
|
||||
*/
|
||||
public function can_load( $product ) {
|
||||
if ( $this->is_from_partner( $product ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( $product->is_theme() && ! current_user_can( 'switch_themes' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $product->is_plugin() && ! current_user_can( 'install_plugins' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the rollbacks array in descending order.
|
||||
*
|
||||
* @param mixed $a First version to compare.
|
||||
* @param mixed $b Second version to compare.
|
||||
*
|
||||
* @return bool Which version is greater?
|
||||
*/
|
||||
public function sort_rollback_array( $a, $b ) {
|
||||
return version_compare( $b['version'], $a['version'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load module logic.
|
||||
*
|
||||
* @param Product $product Product object.
|
||||
*
|
||||
* @return $this Module object.
|
||||
*/
|
||||
public function load( $product ) {
|
||||
$this->product = $product;
|
||||
$this->show_link();
|
||||
$this->add_hooks();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* If product can be rolled back, show the link to rollback.
|
||||
*/
|
||||
private function show_link() {
|
||||
add_filter(
|
||||
'plugin_action_links_' . plugin_basename( $this->product->get_basefile() ),
|
||||
array(
|
||||
$this,
|
||||
'add_rollback_link',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires after the option has been updated.
|
||||
*
|
||||
* @param mixed $old_value The old option value.
|
||||
* @param mixed $value The new option value.
|
||||
* @param string $option Option name.
|
||||
*/
|
||||
public function update_active_plugins_action( $old_value, $value, $option ) {
|
||||
delete_site_transient( 'update_plugins' );
|
||||
wp_cache_delete( 'plugins', 'plugins' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rollback hook. Strangely, this does not work if placed in the ThemeIsle_SDK_Rollback class, so it is being called from there instead.
|
||||
*/
|
||||
public function add_hooks() {
|
||||
add_action( 'admin_post_' . $this->product->get_key() . '_rollback', array( $this, 'start_rollback' ) );
|
||||
add_action( 'admin_footer', array( $this, 'add_footer' ) );
|
||||
|
||||
// This hook will be invoked after the plugin activation.
|
||||
// We use this to force an update of the cache so that Update is present immediate after a rollback.
|
||||
add_action( 'update_option_active_plugins', array( $this, 'update_active_plugins_action' ), 10, 3 );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,515 @@
|
|||
<?php
|
||||
/**
|
||||
* The notification model class for ThemeIsle SDK
|
||||
*
|
||||
* @package ThemeIsleSDK
|
||||
* @subpackage Modules
|
||||
* @copyright Copyright (c) 2017, Marius Cristea
|
||||
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace ThemeisleSDK\Modules;
|
||||
|
||||
use ThemeisleSDK\Common\Abstract_Module;
|
||||
use ThemeisleSDK\Product;
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notification module for ThemeIsle SDK.
|
||||
*/
|
||||
class Notification extends Abstract_Module {
|
||||
/**
|
||||
* Show notifications only after the user has the product installed after this amount of time, in hours.
|
||||
*/
|
||||
const MIN_INSTALL_TIME = 100;
|
||||
/**
|
||||
* How much time should we show the notification, in days.
|
||||
*/
|
||||
const MAX_TIME_TO_LIVE = 7;
|
||||
|
||||
/**
|
||||
* Number of days between notifications.
|
||||
*/
|
||||
const TIME_BETWEEN_NOTIFICATIONS = 5;
|
||||
|
||||
/**
|
||||
* Holds a possible notification list.
|
||||
*
|
||||
* @var array Notifications list.
|
||||
*/
|
||||
private static $notifications = [];
|
||||
|
||||
/**
|
||||
* Show notification data.
|
||||
*/
|
||||
public static function show_notification() {
|
||||
|
||||
$current_notification = self::get_last_notification();
|
||||
|
||||
$notification_details = [];
|
||||
// Check if the saved notification is still present among the possible ones.
|
||||
if ( ! empty( $current_notification ) ) {
|
||||
$notification_details = self::get_notification_details( $current_notification );
|
||||
if ( empty( $notification_details ) ) {
|
||||
$current_notification = [];
|
||||
}
|
||||
}
|
||||
// Check if the notificatin is expired.
|
||||
if ( ! empty( $current_notification ) && self::is_notification_expired( $current_notification ) ) {
|
||||
update_option( $current_notification['id'], 'no' );
|
||||
self::set_last_active_notification_timestamp();
|
||||
$current_notification = [];
|
||||
}
|
||||
// If we don't have any saved notification, get a new one.
|
||||
if ( empty( $current_notification ) ) {
|
||||
$notification_details = self::get_random_notification();
|
||||
if ( empty( $notification_details ) ) {
|
||||
return;
|
||||
}
|
||||
self::set_active_notification(
|
||||
[
|
||||
'id' => $notification_details['id'],
|
||||
'display_at' => time(),
|
||||
]
|
||||
);
|
||||
}
|
||||
if ( empty( $notification_details ) ) {
|
||||
return;
|
||||
}
|
||||
$notification_html = self::get_notification_html( $notification_details );
|
||||
do_action( $notification_details['id'] . '_before_render' );
|
||||
|
||||
echo $notification_html; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, already escaped internally.
|
||||
|
||||
do_action( $notification_details['id'] . '_after_render' );
|
||||
self::render_snippets();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last notification details.
|
||||
*
|
||||
* @return array Last notification details.
|
||||
*/
|
||||
private static function get_last_notification() {
|
||||
$notification = self::get_notifications_metadata();
|
||||
|
||||
return isset( $notification['last_notification'] ) ? $notification['last_notification'] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get notification center details.
|
||||
*
|
||||
* @return array Notification center details.
|
||||
*/
|
||||
private static function get_notifications_metadata() {
|
||||
|
||||
$data = get_option(
|
||||
'themeisle_sdk_notifications',
|
||||
[
|
||||
'last_notification' => [],
|
||||
'last_notification_active' => 0,
|
||||
]
|
||||
);
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the notification is still possible.
|
||||
*
|
||||
* @param array $notification Notification to check.
|
||||
*
|
||||
* @return array Either is still active or not.
|
||||
*/
|
||||
private static function get_notification_details( $notification ) {
|
||||
$notifications = array_filter(
|
||||
self::$notifications,
|
||||
function ( $value ) use ( $notification ) {
|
||||
if ( isset( $value['id'] ) && isset( $notification['id'] ) && $value['id'] === $notification['id'] ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
return ! empty( $notifications ) ? reset( $notifications ) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the notification is expired.
|
||||
*
|
||||
* @param array $notification Notification to check.
|
||||
*
|
||||
* @return bool Either the notification is due.
|
||||
*/
|
||||
private static function is_notification_expired( $notification ) {
|
||||
if ( ! isset( $notification['display_at'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$notifications = array_filter(
|
||||
self::$notifications,
|
||||
function ( $value ) use ( $notification ) {
|
||||
if ( isset( $value['id'] ) && isset( $notification['id'] ) && $value['id'] === $notification['id'] ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
if ( empty( $notifications ) ) {
|
||||
return true;
|
||||
}
|
||||
$notification_definition = reset( $notifications );
|
||||
|
||||
$when_to_expire = isset( $notification_definition['expires_at'] )
|
||||
? $notification_definition['expires_at'] :
|
||||
( isset( $notification_definition['expires'] )
|
||||
? ( $notification['display_at'] + $notification_definition['expires'] ) :
|
||||
( $notification['display_at'] + self::MAX_TIME_TO_LIVE * DAY_IN_SECONDS )
|
||||
);
|
||||
|
||||
return ( $when_to_expire - time() ) < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set last notification details.
|
||||
*/
|
||||
private static function set_last_active_notification_timestamp() {
|
||||
$metadata = self::get_notifications_metadata();
|
||||
$metadata['last_notification_active'] = time();
|
||||
update_option( 'themeisle_sdk_notifications', $metadata );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return notification to show.
|
||||
*
|
||||
* @return array Notification data.
|
||||
*/
|
||||
public static function get_random_notification() {
|
||||
if ( ( time() - self::get_last_active_notification_timestamp() ) < self::TIME_BETWEEN_NOTIFICATIONS * DAY_IN_SECONDS ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$notifications = self::$notifications;
|
||||
$notifications = array_filter(
|
||||
$notifications,
|
||||
function ( $value ) {
|
||||
if ( isset( $value['sticky'] ) && true === $value['sticky'] ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
// No priority notifications, use all.
|
||||
if ( empty( $notifications ) ) {
|
||||
$notifications = self::$notifications;
|
||||
}
|
||||
if ( empty( $notifications ) ) {
|
||||
return [];
|
||||
}
|
||||
$notifications = array_values( $notifications );
|
||||
|
||||
return $notifications[ array_rand( $notifications, 1 ) ];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last notification details.
|
||||
*
|
||||
* @return int Last notification details.
|
||||
*/
|
||||
private static function get_last_active_notification_timestamp() {
|
||||
$notification = self::get_notifications_metadata();
|
||||
|
||||
return isset( $notification['last_notification_active'] ) ? $notification['last_notification_active'] : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last notification details.
|
||||
*
|
||||
* @param array $notification Notification data.
|
||||
*/
|
||||
private static function set_active_notification( $notification ) {
|
||||
$metadata = self::get_notifications_metadata();
|
||||
$metadata['last_notification'] = $notification;
|
||||
update_option( 'themeisle_sdk_notifications', $metadata );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get notification html.
|
||||
*
|
||||
* @param array $notification_details Notification details.
|
||||
*
|
||||
* @return string Html for notice.
|
||||
*/
|
||||
public static function get_notification_html( $notification_details ) {
|
||||
$default = [
|
||||
'id' => '',
|
||||
'heading' => '',
|
||||
'img_src' => '',
|
||||
'message' => '',
|
||||
'ctas' => [
|
||||
'confirm' => [
|
||||
'link' => '#',
|
||||
'text' => '',
|
||||
],
|
||||
'cancel' => [
|
||||
'link' => '#',
|
||||
'text' => '',
|
||||
],
|
||||
],
|
||||
'type' => 'success',
|
||||
];
|
||||
$notification_details = wp_parse_args( $notification_details, $default );
|
||||
global $pagenow;
|
||||
$type = in_array( $notification_details['type'], [ 'success', 'info', 'warning', 'error' ], true ) ? $notification_details['type'] : 'success';
|
||||
$notification_details['ctas']['cancel']['link'] = wp_nonce_url( add_query_arg( [ 'nid' => $notification_details['id'] ], admin_url( $pagenow ) ), $notification_details['id'], 'tsdk_dismiss_nonce' );
|
||||
$notification_html = '<div class="notice notice-' . $type . ' is-dismissible themeisle-sdk-notice" data-notification-id="' . esc_attr( $notification_details['id'] ) . '" id="' . esc_attr( $notification_details['id'] ) . '-notification"> <div class="themeisle-sdk-notification-box">';
|
||||
|
||||
if ( ! empty( $notification_details['heading'] ) ) {
|
||||
$notification_html .= sprintf( '<h4>%s</h4>', wp_kses_post( $notification_details['heading'] ) );
|
||||
}
|
||||
if ( ! empty( $notification_details['img_src'] ) ) {
|
||||
$notification_html .= '<div class="wrap-flex">';
|
||||
$notification_html .= sprintf( '<img src="%s" alt="%s" />', esc_attr( $notification_details['img_src'] ), esc_attr( $notification_details['heading'] ) );
|
||||
}
|
||||
if ( ! empty( $notification_details['message'] ) ) {
|
||||
$notification_html .= wp_kses_post( $notification_details['message'] );
|
||||
if ( ! empty( $notification_details['img_src'] ) ) {
|
||||
$notification_html .= '</div>';
|
||||
}
|
||||
}
|
||||
$notification_html .= '<div class="actions">';
|
||||
|
||||
if ( ! empty( $notification_details['ctas']['confirm']['text'] ) ) {
|
||||
$notification_html .= sprintf(
|
||||
'<a href="%s" target="_blank" class=" button button-primary %s" data-confirm="yes" >%s</a>',
|
||||
esc_url( $notification_details['ctas']['confirm']['link'] ),
|
||||
esc_attr( $notification_details['id'] . '_confirm' ),
|
||||
wp_kses_post( $notification_details['ctas']['confirm']['text'] )
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $notification_details['ctas']['cancel']['text'] ) ) {
|
||||
$notification_html .= sprintf(
|
||||
'<a href="%s" class=" button %s" data-confirm="no">%s</a>',
|
||||
esc_url( $notification_details['ctas']['cancel']['link'] ),
|
||||
esc_attr( $notification_details['id'] ) . '_cancel',
|
||||
wp_kses_post( $notification_details['ctas']['cancel']['text'] )
|
||||
);
|
||||
}
|
||||
|
||||
$notification_html .= '</div>';
|
||||
$notification_html .= ' </div>';
|
||||
$notification_html .= ' </div>';
|
||||
|
||||
return $notification_html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds js snippet for hiding the notice.
|
||||
*/
|
||||
public static function render_snippets() {
|
||||
|
||||
?>
|
||||
<style type="text/css">
|
||||
.themeisle-sdk-notification-box {
|
||||
padding: 3px;
|
||||
}
|
||||
|
||||
.themeisle-sdk-notification-box .wrap-flex {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: start;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.themeisle-sdk-notification-box .wrap-flex img {
|
||||
width: 42px;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.themeisle-sdk-notification-box .actions {
|
||||
margin-top: 6px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.themeisle-sdk-notification-box .button {
|
||||
margin-right: 5px;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
(function ($) {
|
||||
$(document).ready(function () {
|
||||
$('#wpbody-content').on('click', ".themeisle-sdk-notice a.button, .themeisle-sdk-notice .notice-dismiss", function (e) {
|
||||
|
||||
var container = $('.themeisle-sdk-notice');
|
||||
var link = $(this);
|
||||
var notification_id = container.attr('data-notification-id');
|
||||
var confirm = link.attr('data-confirm');
|
||||
if (typeof confirm === "undefined") {
|
||||
confirm = 'no';
|
||||
}
|
||||
$.post(
|
||||
ajaxurl,
|
||||
{
|
||||
'nonce': '<?php echo esc_attr( wp_create_nonce( (string) __CLASS__ ) ); ?>',
|
||||
'action': 'themeisle_sdk_dismiss_notice',
|
||||
'id': notification_id,
|
||||
'confirm': confirm,
|
||||
},
|
||||
).fail(function() {
|
||||
location.href = encodeURI(link.attr('href'));
|
||||
});
|
||||
if (confirm === 'yes') {
|
||||
$(this).trigger('themeisle-sdk:confirmed');
|
||||
} else {
|
||||
$(this).trigger('themeisle-sdk:canceled');
|
||||
}
|
||||
container.hide();
|
||||
if (confirm === 'no' || link.attr('href') === '#') {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Dismiss the notification.
|
||||
*/
|
||||
public static function dismiss() {
|
||||
check_ajax_referer( (string) __CLASS__, 'nonce' );
|
||||
|
||||
$id = isset( $_POST['id'] ) ? sanitize_text_field( $_POST['id'] ) : '';
|
||||
$confirm = isset( $_POST['confirm'] ) ? sanitize_text_field( $_POST['confirm'] ) : 'no';
|
||||
|
||||
if ( empty( $id ) ) {
|
||||
wp_send_json( [] );
|
||||
}
|
||||
self::setup_notifications();
|
||||
$ids = wp_list_pluck( self::$notifications, 'id' );
|
||||
if ( ! in_array( $id, $ids, true ) ) {
|
||||
wp_send_json( [] );
|
||||
}
|
||||
self::set_last_active_notification_timestamp();
|
||||
update_option( $id, $confirm );
|
||||
do_action( $id . '_process_confirm', $confirm );
|
||||
wp_send_json( [] );
|
||||
}
|
||||
/**
|
||||
* Dismiss the notification.
|
||||
*/
|
||||
public static function dismiss_get() {
|
||||
$is_nonce_dismiss = sanitize_text_field( isset( $_GET['tsdk_dismiss_nonce'] ) ? $_GET['tsdk_dismiss_nonce'] : '' );
|
||||
if ( strlen( $is_nonce_dismiss ) < 5 ) {
|
||||
return;
|
||||
}
|
||||
$id = sanitize_text_field( isset( $_GET['nid'] ) ? $_GET['nid'] : '' );
|
||||
if ( empty( $id ) ) {
|
||||
return;
|
||||
}
|
||||
$nonce = wp_verify_nonce( sanitize_text_field( $_GET['tsdk_dismiss_nonce'] ), $id );
|
||||
if ( $nonce !== 1 ) {
|
||||
return;
|
||||
}
|
||||
$ids = wp_list_pluck( self::$notifications, 'id' );
|
||||
if ( ! in_array( $id, $ids, true ) ) {
|
||||
return;
|
||||
}
|
||||
$confirm = 'no';
|
||||
self::set_last_active_notification_timestamp();
|
||||
update_option( $id, $confirm );
|
||||
do_action( $id . '_process_confirm', $confirm );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we should load the notification module.
|
||||
*
|
||||
* @param Product $product Product to check.
|
||||
*
|
||||
* @return bool Should we load this?
|
||||
*/
|
||||
public function can_load( $product ) {
|
||||
|
||||
if ( $this->is_from_partner( $product ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( ( time() - $product->get_install_time() ) < ( self::MIN_INSTALL_TIME * HOUR_IN_SECONDS ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup notifications queue.
|
||||
*/
|
||||
public static function setup_notifications() {
|
||||
$notifications = apply_filters( 'themeisle_sdk_registered_notifications', [] );
|
||||
$notifications = array_filter(
|
||||
$notifications,
|
||||
function ( $value ) {
|
||||
if ( ! isset( $value['id'] ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( get_option( $value['id'], '' ) !== '' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return apply_filters( $value['id'] . '_should_show', true );
|
||||
}
|
||||
);
|
||||
self::$notifications = $notifications;
|
||||
}
|
||||
/**
|
||||
* Load the module logic.
|
||||
*
|
||||
* @param Product $product Product to load the module for.
|
||||
*
|
||||
* @return Notification Module instance.
|
||||
*/
|
||||
public function load( $product ) {
|
||||
if ( apply_filters( 'themeisle_sdk_hide_notifications', false ) ) {
|
||||
return;
|
||||
}
|
||||
$this->product = $product;
|
||||
|
||||
$notifications = apply_filters( 'themeisle_sdk_registered_notifications', [] );
|
||||
$notifications = array_filter(
|
||||
$notifications,
|
||||
function ( $value ) {
|
||||
if ( ! isset( $value['id'] ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( get_option( $value['id'], '' ) !== '' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return apply_filters( $value['id'] . '_should_show', true );
|
||||
}
|
||||
);
|
||||
self::$notifications = $notifications;
|
||||
add_action( 'admin_notices', array( __CLASS__, 'show_notification' ) );
|
||||
add_action( 'wp_ajax_themeisle_sdk_dismiss_notice', array( __CLASS__, 'dismiss' ) );
|
||||
add_action( 'admin_head', array( __CLASS__, 'dismiss_get' ) );
|
||||
add_action( 'admin_head', array( __CLASS__, 'setup_notifications' ) );
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 173 KiB |
|
@ -0,0 +1,579 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
* Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
/**
|
||||
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
|
||||
*
|
||||
* $loader = new \Composer\Autoload\ClassLoader();
|
||||
*
|
||||
* // register classes with namespaces
|
||||
* $loader->add('Symfony\Component', __DIR__.'/component');
|
||||
* $loader->add('Symfony', __DIR__.'/framework');
|
||||
*
|
||||
* // activate the autoloader
|
||||
* $loader->register();
|
||||
*
|
||||
* // to enable searching the include path (eg. for PEAR packages)
|
||||
* $loader->setUseIncludePath(true);
|
||||
*
|
||||
* In this example, if you try to use a class in the Symfony\Component
|
||||
* namespace or one of its children (Symfony\Component\Console for instance),
|
||||
* the autoloader will first look for the class under the component/
|
||||
* directory, and it will then fallback to the framework/ directory if not
|
||||
* found before giving up.
|
||||
*
|
||||
* This class is loosely based on the Symfony UniversalClassLoader.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @see https://www.php-fig.org/psr/psr-0/
|
||||
* @see https://www.php-fig.org/psr/psr-4/
|
||||
*/
|
||||
class ClassLoader
|
||||
{
|
||||
/** @var \Closure(string):void */
|
||||
private static $includeFile;
|
||||
|
||||
/** @var string|null */
|
||||
private $vendorDir;
|
||||
|
||||
// PSR-4
|
||||
/**
|
||||
* @var array<string, array<string, int>>
|
||||
*/
|
||||
private $prefixLengthsPsr4 = array();
|
||||
/**
|
||||
* @var array<string, list<string>>
|
||||
*/
|
||||
private $prefixDirsPsr4 = array();
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
private $fallbackDirsPsr4 = array();
|
||||
|
||||
// PSR-0
|
||||
/**
|
||||
* List of PSR-0 prefixes
|
||||
*
|
||||
* Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2')))
|
||||
*
|
||||
* @var array<string, array<string, list<string>>>
|
||||
*/
|
||||
private $prefixesPsr0 = array();
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
private $fallbackDirsPsr0 = array();
|
||||
|
||||
/** @var bool */
|
||||
private $useIncludePath = false;
|
||||
|
||||
/**
|
||||
* @var array<string, string>
|
||||
*/
|
||||
private $classMap = array();
|
||||
|
||||
/** @var bool */
|
||||
private $classMapAuthoritative = false;
|
||||
|
||||
/**
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
private $missingClasses = array();
|
||||
|
||||
/** @var string|null */
|
||||
private $apcuPrefix;
|
||||
|
||||
/**
|
||||
* @var array<string, self>
|
||||
*/
|
||||
private static $registeredLoaders = array();
|
||||
|
||||
/**
|
||||
* @param string|null $vendorDir
|
||||
*/
|
||||
public function __construct($vendorDir = null)
|
||||
{
|
||||
$this->vendorDir = $vendorDir;
|
||||
self::initializeIncludeClosure();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, list<string>>
|
||||
*/
|
||||
public function getPrefixes()
|
||||
{
|
||||
if (!empty($this->prefixesPsr0)) {
|
||||
return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, list<string>>
|
||||
*/
|
||||
public function getPrefixesPsr4()
|
||||
{
|
||||
return $this->prefixDirsPsr4;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
public function getFallbackDirs()
|
||||
{
|
||||
return $this->fallbackDirsPsr0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
public function getFallbackDirsPsr4()
|
||||
{
|
||||
return $this->fallbackDirsPsr4;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string> Array of classname => path
|
||||
*/
|
||||
public function getClassMap()
|
||||
{
|
||||
return $this->classMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $classMap Class to filename map
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addClassMap(array $classMap)
|
||||
{
|
||||
if ($this->classMap) {
|
||||
$this->classMap = array_merge($this->classMap, $classMap);
|
||||
} else {
|
||||
$this->classMap = $classMap;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-0 directories for a given prefix, either
|
||||
* appending or prepending to the ones previously set for this prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
* @param list<string>|string $paths The PSR-0 root directories
|
||||
* @param bool $prepend Whether to prepend the directories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add($prefix, $paths, $prepend = false)
|
||||
{
|
||||
$paths = (array) $paths;
|
||||
if (!$prefix) {
|
||||
if ($prepend) {
|
||||
$this->fallbackDirsPsr0 = array_merge(
|
||||
$paths,
|
||||
$this->fallbackDirsPsr0
|
||||
);
|
||||
} else {
|
||||
$this->fallbackDirsPsr0 = array_merge(
|
||||
$this->fallbackDirsPsr0,
|
||||
$paths
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$first = $prefix[0];
|
||||
if (!isset($this->prefixesPsr0[$first][$prefix])) {
|
||||
$this->prefixesPsr0[$first][$prefix] = $paths;
|
||||
|
||||
return;
|
||||
}
|
||||
if ($prepend) {
|
||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||
$paths,
|
||||
$this->prefixesPsr0[$first][$prefix]
|
||||
);
|
||||
} else {
|
||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||
$this->prefixesPsr0[$first][$prefix],
|
||||
$paths
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-4 directories for a given namespace, either
|
||||
* appending or prepending to the ones previously set for this namespace.
|
||||
*
|
||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||
* @param list<string>|string $paths The PSR-4 base directories
|
||||
* @param bool $prepend Whether to prepend the directories
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addPsr4($prefix, $paths, $prepend = false)
|
||||
{
|
||||
$paths = (array) $paths;
|
||||
if (!$prefix) {
|
||||
// Register directories for the root namespace.
|
||||
if ($prepend) {
|
||||
$this->fallbackDirsPsr4 = array_merge(
|
||||
$paths,
|
||||
$this->fallbackDirsPsr4
|
||||
);
|
||||
} else {
|
||||
$this->fallbackDirsPsr4 = array_merge(
|
||||
$this->fallbackDirsPsr4,
|
||||
$paths
|
||||
);
|
||||
}
|
||||
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
|
||||
// Register directories for a new namespace.
|
||||
$length = strlen($prefix);
|
||||
if ('\\' !== $prefix[$length - 1]) {
|
||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||
}
|
||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||
$this->prefixDirsPsr4[$prefix] = $paths;
|
||||
} elseif ($prepend) {
|
||||
// Prepend directories for an already registered namespace.
|
||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||
$paths,
|
||||
$this->prefixDirsPsr4[$prefix]
|
||||
);
|
||||
} else {
|
||||
// Append directories for an already registered namespace.
|
||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||
$this->prefixDirsPsr4[$prefix],
|
||||
$paths
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-0 directories for a given prefix,
|
||||
* replacing any others previously set for this prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
* @param list<string>|string $paths The PSR-0 base directories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set($prefix, $paths)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$this->fallbackDirsPsr0 = (array) $paths;
|
||||
} else {
|
||||
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-4 directories for a given namespace,
|
||||
* replacing any others previously set for this namespace.
|
||||
*
|
||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||
* @param list<string>|string $paths The PSR-4 base directories
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setPsr4($prefix, $paths)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$this->fallbackDirsPsr4 = (array) $paths;
|
||||
} else {
|
||||
$length = strlen($prefix);
|
||||
if ('\\' !== $prefix[$length - 1]) {
|
||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||
}
|
||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||
$this->prefixDirsPsr4[$prefix] = (array) $paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns on searching the include path for class files.
|
||||
*
|
||||
* @param bool $useIncludePath
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUseIncludePath($useIncludePath)
|
||||
{
|
||||
$this->useIncludePath = $useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to check if the autoloader uses the include path to check
|
||||
* for classes.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getUseIncludePath()
|
||||
{
|
||||
return $this->useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns off searching the prefix and fallback directories for classes
|
||||
* that have not been registered with the class map.
|
||||
*
|
||||
* @param bool $classMapAuthoritative
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setClassMapAuthoritative($classMapAuthoritative)
|
||||
{
|
||||
$this->classMapAuthoritative = $classMapAuthoritative;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should class lookup fail if not found in the current class map?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isClassMapAuthoritative()
|
||||
{
|
||||
return $this->classMapAuthoritative;
|
||||
}
|
||||
|
||||
/**
|
||||
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
|
||||
*
|
||||
* @param string|null $apcuPrefix
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setApcuPrefix($apcuPrefix)
|
||||
{
|
||||
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The APCu prefix in use, or null if APCu caching is not enabled.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getApcuPrefix()
|
||||
{
|
||||
return $this->apcuPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers this instance as an autoloader.
|
||||
*
|
||||
* @param bool $prepend Whether to prepend the autoloader or not
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
||||
|
||||
if (null === $this->vendorDir) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($prepend) {
|
||||
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
|
||||
} else {
|
||||
unset(self::$registeredLoaders[$this->vendorDir]);
|
||||
self::$registeredLoaders[$this->vendorDir] = $this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters this instance as an autoloader.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unregister()
|
||||
{
|
||||
spl_autoload_unregister(array($this, 'loadClass'));
|
||||
|
||||
if (null !== $this->vendorDir) {
|
||||
unset(self::$registeredLoaders[$this->vendorDir]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the given class or interface.
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
* @return true|null True if loaded, null otherwise
|
||||
*/
|
||||
public function loadClass($class)
|
||||
{
|
||||
if ($file = $this->findFile($class)) {
|
||||
$includeFile = self::$includeFile;
|
||||
$includeFile($file);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the path to the file where the class is defined.
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
*
|
||||
* @return string|false The path if found, false otherwise
|
||||
*/
|
||||
public function findFile($class)
|
||||
{
|
||||
// class map lookup
|
||||
if (isset($this->classMap[$class])) {
|
||||
return $this->classMap[$class];
|
||||
}
|
||||
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
|
||||
return false;
|
||||
}
|
||||
if (null !== $this->apcuPrefix) {
|
||||
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
|
||||
if ($hit) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
$file = $this->findFileWithExtension($class, '.php');
|
||||
|
||||
// Search for Hack files if we are running on HHVM
|
||||
if (false === $file && defined('HHVM_VERSION')) {
|
||||
$file = $this->findFileWithExtension($class, '.hh');
|
||||
}
|
||||
|
||||
if (null !== $this->apcuPrefix) {
|
||||
apcu_add($this->apcuPrefix.$class, $file);
|
||||
}
|
||||
|
||||
if (false === $file) {
|
||||
// Remember that this class does not exist.
|
||||
$this->missingClasses[$class] = true;
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently registered loaders keyed by their corresponding vendor directories.
|
||||
*
|
||||
* @return array<string, self>
|
||||
*/
|
||||
public static function getRegisteredLoaders()
|
||||
{
|
||||
return self::$registeredLoaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @param string $ext
|
||||
* @return string|false
|
||||
*/
|
||||
private function findFileWithExtension($class, $ext)
|
||||
{
|
||||
// PSR-4 lookup
|
||||
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
|
||||
|
||||
$first = $class[0];
|
||||
if (isset($this->prefixLengthsPsr4[$first])) {
|
||||
$subPath = $class;
|
||||
while (false !== $lastPos = strrpos($subPath, '\\')) {
|
||||
$subPath = substr($subPath, 0, $lastPos);
|
||||
$search = $subPath . '\\';
|
||||
if (isset($this->prefixDirsPsr4[$search])) {
|
||||
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
|
||||
foreach ($this->prefixDirsPsr4[$search] as $dir) {
|
||||
if (file_exists($file = $dir . $pathEnd)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-4 fallback dirs
|
||||
foreach ($this->fallbackDirsPsr4 as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 lookup
|
||||
if (false !== $pos = strrpos($class, '\\')) {
|
||||
// namespaced class name
|
||||
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
|
||||
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
|
||||
} else {
|
||||
// PEAR-like class name
|
||||
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
|
||||
}
|
||||
|
||||
if (isset($this->prefixesPsr0[$first])) {
|
||||
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
|
||||
if (0 === strpos($class, $prefix)) {
|
||||
foreach ($dirs as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 fallback dirs
|
||||
foreach ($this->fallbackDirsPsr0 as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 include paths.
|
||||
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private static function initializeIncludeClosure()
|
||||
{
|
||||
if (self::$includeFile !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope isolated include.
|
||||
*
|
||||
* Prevents access to $this/self from included files.
|
||||
*
|
||||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
self::$includeFile = \Closure::bind(static function($file) {
|
||||
include $file;
|
||||
}, null, null);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
|
||||
|
||||
class SWCFPC_Installer
|
||||
{
|
||||
|
||||
function __construct(){}
|
||||
|
||||
|
||||
function start() {
|
||||
|
||||
$this->create_mysql_tables();
|
||||
|
||||
}
|
||||
|
||||
function create_mysql_tables() {
|
||||
|
||||
/*
|
||||
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$charset_collate = $wpdb->get_charset_collate();
|
||||
|
||||
$sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}swcfpc_logs (";
|
||||
$sql .= 'id bigint NOT NULL AUTO_INCREMENT,';
|
||||
$sql .= 'date datetime NOT NULL,';
|
||||
$sql .= 'log_identifier varchar(150) NOT NULL,';
|
||||
$sql .= 'log_msg longtext NOT NULL,';
|
||||
$sql .= 'PRIMARY KEY (id)';
|
||||
$sql .= ") {$charset_collate}";
|
||||
|
||||
dbDelta( $sql );
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,414 @@
|
|||
##### [Version 3.3.14](https://github.com/Codeinwp/themeisle-sdk/compare/v3.3.13...v3.3.14) (2024-02-27)
|
||||
|
||||
- Add Announcement Module
|
||||
- Add Script Loader Module
|
||||
|
||||
##### [Version 3.3.13](https://github.com/Codeinwp/themeisle-sdk/compare/v3.3.12...v3.3.13) (2024-02-01)
|
||||
|
||||
- Updated nonce check
|
||||
|
||||
##### [Version 3.3.12](https://github.com/Codeinwp/themeisle-sdk/compare/v3.3.11...v3.3.12) (2024-01-31)
|
||||
|
||||
- fix: prevent reference key set for users with no capability
|
||||
|
||||
##### [Version 3.3.11](https://github.com/Codeinwp/themeisle-sdk/compare/v3.3.10...v3.3.11) (2023-12-12)
|
||||
|
||||
- fix: cached requests for wp options
|
||||
- fix: php notice on failed xml feed
|
||||
|
||||
##### [Version 3.3.10](https://github.com/Codeinwp/themeisle-sdk/compare/v3.3.9...v3.3.10) (2023-12-11)
|
||||
|
||||
feat: add new filter for tsdk_utmify query arguments
|
||||
|
||||
##### [Version 3.3.9](https://github.com/Codeinwp/themeisle-sdk/compare/v3.3.8...v3.3.9) (2023-11-16)
|
||||
|
||||
- Fix: a debugging error when you activate Neve Pro after installing Otter & Otter Pro without the license.
|
||||
|
||||
##### [Version 3.3.8](https://github.com/Codeinwp/themeisle-sdk/compare/v3.3.7...v3.3.8) (2023-11-14)
|
||||
|
||||
- Add Product Telemetry
|
||||
|
||||
##### [Version 3.3.7](https://github.com/Codeinwp/themeisle-sdk/compare/v3.3.6...v3.3.7) (2023-10-31)
|
||||
|
||||
- fix: deprecating notice in Dashboard Widget
|
||||
|
||||
##### [Version 3.3.6](https://github.com/Codeinwp/themeisle-sdk/compare/v3.3.5...v3.3.6) (2023-10-05)
|
||||
|
||||
- Fix duplicate notification in Neve FSE
|
||||
- Fix SDK breaking Enfold theme builder
|
||||
|
||||
##### [Version 3.3.5](https://github.com/Codeinwp/themeisle-sdk/compare/v3.3.4...v3.3.5) (2023-09-29)
|
||||
|
||||
Fix TPC message.
|
||||
Fix TPC typo.
|
||||
|
||||
##### [Version 3.3.4](https://github.com/Codeinwp/themeisle-sdk/compare/v3.3.3...v3.3.4) (2023-09-18)
|
||||
|
||||
- Allow users to activate plugins from the About page
|
||||
|
||||
##### [Version 3.3.3](https://github.com/Codeinwp/themeisle-sdk/compare/v3.3.2...v3.3.3) (2023-08-22)
|
||||
|
||||
- Disable install buttons on the About page if users can not install plugins
|
||||
|
||||
##### [Version 3.3.2](https://github.com/Codeinwp/themeisle-sdk/compare/v3.3.1...v3.3.2) (2023-08-02)
|
||||
|
||||
- Added a new product page for Otter
|
||||
|
||||
##### [Version 3.3.1](https://github.com/Codeinwp/themeisle-sdk/compare/v3.3.0...v3.3.1) (2023-06-21)
|
||||
|
||||
- Fix Neve FSE promo typo
|
||||
|
||||
#### [Version 3.3.0](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.41...v3.3.0) (2023-05-30)
|
||||
|
||||
- Adds About Page Integration
|
||||
- Adds promos for Neve FSE, Sparks & PPOM
|
||||
|
||||
##### [Version 3.2.41](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.40...v3.2.41) (2023-05-10)
|
||||
|
||||
- Delay product recommendation mentions
|
||||
- Allow upselling notifications for new users
|
||||
|
||||
##### [Version 3.2.40](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.39...v3.2.40) (2023-03-30)
|
||||
|
||||
- Add ROP upsell to all products
|
||||
|
||||
##### [Version 3.2.39](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.38...v3.2.39) (2023-03-17)
|
||||
|
||||
* Adds direct utility function for a direct support link.
|
||||
|
||||
##### [Version 3.2.38](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.37...v3.2.38) (2023-03-10)
|
||||
|
||||
Fix promotions path-breaking
|
||||
|
||||
##### [Version 3.2.37](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.36...v3.2.37) (2023-03-01)
|
||||
|
||||
Fix array casting
|
||||
|
||||
##### [Version 3.2.36](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.35...v3.2.36) (2023-03-01)
|
||||
|
||||
fix perfomance issues on attachments count https://github.com/Codeinwp/themeisle-sdk/issues/159
|
||||
|
||||
##### [Version 3.2.35](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.34...v3.2.35) (2023-02-22)
|
||||
|
||||
Added Codeinwp and wpshout feeds to dashboard widget
|
||||
|
||||
##### [Version 3.2.34](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.33...v3.2.34) (2023-01-31)
|
||||
|
||||
Improve promotions
|
||||
|
||||
##### [Version 3.2.33](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.32...v3.2.33) (2023-01-30)
|
||||
|
||||
* Adds PHP 8.2 compatibility
|
||||
* Update promotions
|
||||
|
||||
##### [Version 3.2.32](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.31...v3.2.32) (2022-11-30)
|
||||
|
||||
Release
|
||||
|
||||
##### [Version 3.2.31](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.30...v3.2.31) (2022-11-23)
|
||||
|
||||
- improve the promotions module
|
||||
|
||||
##### [Version 3.2.30](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.29...v3.2.30) (2022-09-15)
|
||||
|
||||
- fix filesystem wrong use - ref [#138](https://github.com/Codeinwp/themeisle-sdk/issues/138), props [@ethanclevenger91](https://github.com/ethanclevenger91) for reporting
|
||||
|
||||
##### [Version 3.2.29](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.28...v3.2.29) (2022-09-08)
|
||||
|
||||
* Adds compatibility mechanism
|
||||
* Adds content utms
|
||||
* Adds usage time on uninstall feedback
|
||||
|
||||
##### [Version 3.2.28](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.27...v3.2.28) (2022-08-30)
|
||||
|
||||
* Adds utm handler
|
||||
* Improve promotions
|
||||
|
||||
##### [Version 3.2.27](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.26...v3.2.27) (2022-08-23)
|
||||
|
||||
- Add Promotion Module
|
||||
Add the Promotion module for free plugins
|
||||
|
||||
##### [Version 3.2.26](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.25...v3.2.26) (2022-05-12)
|
||||
|
||||
- [Fix] Solve rollback sometimes not available
|
||||
|
||||
##### [Version 3.2.25](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.24...v3.2.25) (2022-03-28)
|
||||
|
||||
- Force update request after rollback
|
||||
|
||||
##### [Version 3.2.24](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.23...v3.2.24) (2022-02-09)
|
||||
|
||||
Fix edge case issue on dismiss
|
||||
Avoid issues with open_basedir restrictions
|
||||
|
||||
##### [Version 3.2.23](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.22...v3.2.23) (2022-02-02)
|
||||
|
||||
Fix php 8.1 issues
|
||||
Fix edge case when update_themes site transient was empty and a fatal error was thrown
|
||||
|
||||
##### [Version 3.2.22](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.21...v3.2.22) (2021-10-27)
|
||||
|
||||
Fix edge case when reset failed checks was not working properly
|
||||
|
||||
##### [Version 3.2.21](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.20...v3.2.21) (2021-06-30)
|
||||
|
||||
review and improve compatibility with auto-updates on custom updates endpoint
|
||||
|
||||
##### [Version 3.2.20](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.19...v3.2.20) (2021-03-30)
|
||||
|
||||
add wp-config support
|
||||
|
||||
##### [Version 3.2.19](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.18...v3.2.19) (2021-03-12)
|
||||
|
||||
* Adds compatibility with latest PHPCS coding standards.
|
||||
* Adds compatibility with core auto-update.
|
||||
|
||||
##### [Version 3.2.18](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.17...v3.2.18) (2021-03-04)
|
||||
|
||||
* Fix regression on rollback order
|
||||
|
||||
##### [Version 3.2.17](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.16...v3.2.17) (2021-03-04)
|
||||
|
||||
* Fix compatibility with PHP 8 due to usort
|
||||
|
||||
##### [Version 3.2.16](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.15...v3.2.16) (2020-11-17)
|
||||
|
||||
* Fix long texts on rollback.
|
||||
* Fix RTL mode for uninstall feedback.
|
||||
|
||||
##### [Version 3.2.15](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.14...v3.2.15) (2020-07-23)
|
||||
|
||||
* remove no redundant module
|
||||
|
||||
##### [Version 3.2.14](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.13...v3.2.14) (2020-06-10)
|
||||
|
||||
> Things are getting better every day. 🚀
|
||||
|
||||
##### [Version 3.2.13](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.12...v3.2.13) (2020-06-10)
|
||||
|
||||
Adds plan logic and expiration
|
||||
|
||||
##### [Version 3.2.12](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.11...v3.2.12) (2020-06-10)
|
||||
|
||||
Adds key filter
|
||||
|
||||
##### [Version 3.2.11](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.10...v3.2.11) (2020-06-04)
|
||||
|
||||
* remove non-printable chars
|
||||
|
||||
##### [Version 3.2.10](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.9...v3.2.10) (2020-05-28)
|
||||
|
||||
* Remove extra files on export
|
||||
|
||||
##### [Version 3.2.9](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.8...v3.2.9) (2020-05-18)
|
||||
|
||||
adds new endpoints
|
||||
|
||||
##### [Version 3.2.8](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.7...v3.2.8) (2020-03-24)
|
||||
|
||||
* change license handler method access
|
||||
|
||||
##### [Version 3.2.7](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.6...v3.2.7) (2020-03-24)
|
||||
|
||||
* fix callback for license processing hook
|
||||
|
||||
##### [Version 3.2.6](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.5...v3.2.6) (2020-03-23)
|
||||
|
||||
* Fix notice on license deactivation
|
||||
|
||||
##### [Version 3.2.5](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.4...v3.2.5) (2020-03-23)
|
||||
|
||||
* always load notification manager last
|
||||
|
||||
##### [Version 3.2.4](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.3...v3.2.4) (2020-03-21)
|
||||
|
||||
* Cast version response to array for icons
|
||||
|
||||
##### [Version 3.2.3](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.2...v3.2.3) (2020-03-21)
|
||||
|
||||
* use product slug instead of the one from api
|
||||
|
||||
##### [Version 3.2.2](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.1...v3.2.2) (2020-03-13)
|
||||
|
||||
* improve notice dismiss mechanism
|
||||
|
||||
##### [Version 3.2.1](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.0...v3.2.1) (2020-03-05)
|
||||
|
||||
Fix rollback call for private products
|
||||
|
||||
#### [Version 3.2.0](https://github.com/Codeinwp/themeisle-sdk/compare/v3.1.9...v3.2.0) (2020-03-04)
|
||||
|
||||
* adds license activation/deactivation handlers for wp cli
|
||||
* adds compatibility with the newest license API
|
||||
|
||||
##### [Version 3.1.9](https://github.com/Codeinwp/themeisle-sdk/compare/v3.1.8...v3.1.9) (2020-02-24)
|
||||
|
||||
* Add integration with GitHub actions
|
||||
|
||||
## [3.1.8](https://github.com/Codeinwp/themeisle-sdk/compare/v3.1.7...v3.1.8) (2019-11-18)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* update developers name ([6aca63e](https://github.com/Codeinwp/themeisle-sdk/commit/6aca63e))
|
||||
|
||||
## [3.1.7](https://github.com/Codeinwp/themeisle-sdk/compare/v3.1.6...v3.1.7) (2019-11-07)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* license field style on wp5.3 ([0239997](https://github.com/Codeinwp/themeisle-sdk/commit/0239997))
|
||||
* license field style on wp5.3 ([86d3a1b](https://github.com/Codeinwp/themeisle-sdk/commit/86d3a1b))
|
||||
|
||||
## [3.1.6](https://github.com/Codeinwp/themeisle-sdk/compare/v3.1.5...v3.1.6) (2019-09-24)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* remove license related options when deactivated ([02cd6ce](https://github.com/Codeinwp/themeisle-sdk/commit/02cd6ce))
|
||||
* remove license related options when deactivated ([d3c1a1f](https://github.com/Codeinwp/themeisle-sdk/commit/d3c1a1f))
|
||||
|
||||
## [3.1.5](https://github.com/Codeinwp/themeisle-sdk/compare/v3.1.4...v3.1.5) (2019-09-11)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* allow unloading certain module features ([2a2559a](https://github.com/Codeinwp/themeisle-sdk/commit/2a2559a))
|
||||
* license activation workflow, show error message when failed to a… ([ade795c](https://github.com/Codeinwp/themeisle-sdk/commit/ade795c))
|
||||
* license activation workflow, show error message when failed to activate ([2f5cbae](https://github.com/Codeinwp/themeisle-sdk/commit/2f5cbae))
|
||||
|
||||
## [3.1.4](https://github.com/Codeinwp/themeisle-sdk/compare/v3.1.3...v3.1.4) (2019-08-23)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* license key was missing on get_version call ([365cde6](https://github.com/Codeinwp/themeisle-sdk/commit/365cde6))
|
||||
* license key was missing on get_version call ([c02f225](https://github.com/Codeinwp/themeisle-sdk/commit/c02f225))
|
||||
|
||||
## [3.1.3](https://github.com/Codeinwp/themeisle-sdk/compare/v3.1.2...v3.1.3) (2019-08-20)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* license deactivation behaviour https://github.com/Codeinwp/visua… ([59c4afe](https://github.com/Codeinwp/themeisle-sdk/commit/59c4afe))
|
||||
* license deactivation behaviour https://github.com/Codeinwp/visualizer-pro/issues/192 ([f641e18](https://github.com/Codeinwp/themeisle-sdk/commit/f641e18))
|
||||
|
||||
## [3.1.2](https://github.com/Codeinwp/themeisle-sdk/compare/v3.1.1...v3.1.2) (2019-08-12)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* phpunit test case ([efe851c](https://github.com/Codeinwp/themeisle-sdk/commit/efe851c))
|
||||
* url format for license endpoint, improve changelog handling and license checks ([a492c68](https://github.com/Codeinwp/themeisle-sdk/commit/a492c68))
|
||||
|
||||
## [3.1.1](https://github.com/Codeinwp/themeisle-sdk/compare/v3.1.0...v3.1.1) (2019-08-08)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* adds is_file for file existence check ([d1205c4](https://github.com/Codeinwp/themeisle-sdk/commit/d1205c4))
|
||||
* adds is_file for file existence check ([be119c1](https://github.com/Codeinwp/themeisle-sdk/commit/be119c1))
|
||||
|
||||
# [3.1.0](https://github.com/Codeinwp/themeisle-sdk/compare/v3.0.10...v3.1.0) (2019-08-05)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* adds extra comments for rest of the options, fix [#64](https://github.com/Codeinwp/themeisle-sdk/issues/64) ([018b22f](https://github.com/Codeinwp/themeisle-sdk/commit/018b22f))
|
||||
* hide license key when active under a password mask, fix [#67](https://github.com/Codeinwp/themeisle-sdk/issues/67) ([c0633c2](https://github.com/Codeinwp/themeisle-sdk/commit/c0633c2))
|
||||
* new uninstall feedback popup issues ([5bda4bd](https://github.com/Codeinwp/themeisle-sdk/commit/5bda4bd))
|
||||
* phpcs indentation errors ([d59ed4f](https://github.com/Codeinwp/themeisle-sdk/commit/d59ed4f))
|
||||
* undefined notices on license check, fix [#60](https://github.com/Codeinwp/themeisle-sdk/issues/60) ([7f56a97](https://github.com/Codeinwp/themeisle-sdk/commit/7f56a97))
|
||||
* uninstall feedback popup placement [[#61](https://github.com/Codeinwp/themeisle-sdk/issues/61)] ([1102d6c](https://github.com/Codeinwp/themeisle-sdk/commit/1102d6c))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* new product feedback popup ([f0dbab3](https://github.com/Codeinwp/themeisle-sdk/commit/f0dbab3))
|
||||
* new uninstall feedback form for themes ([8a29f21](https://github.com/Codeinwp/themeisle-sdk/commit/8a29f21))
|
||||
|
||||
## [3.0.10](https://github.com/Codeinwp/themeisle-sdk/compare/v3.0.9...v3.0.10) (2019-07-16)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* compatibility with lower PHP versions ([065ac8e](https://github.com/Codeinwp/themeisle-sdk/commit/065ac8e))
|
||||
* not loading licenser when SDK comes from theme [[#62](https://github.com/Codeinwp/themeisle-sdk/issues/62)] ([b706ca7](https://github.com/Codeinwp/themeisle-sdk/commit/b706ca7))
|
||||
* not loading licenser when SDK comes from theme [[#65](https://github.com/Codeinwp/themeisle-sdk/issues/65) ([419d8e6](https://github.com/Codeinwp/themeisle-sdk/commit/419d8e6))
|
||||
* preserve loaded when adding the licenser one ([cd50434](https://github.com/Codeinwp/themeisle-sdk/commit/cd50434))
|
||||
|
||||
## [3.0.9](https://github.com/Codeinwp/themeisle-sdk/compare/v3.0.8...v3.0.9) (2019-06-26)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* adds new icon for dashboard widget ([de78068](https://github.com/Codeinwp/themeisle-sdk/commit/de78068))
|
||||
* anchor element on license activation message which should link to the license field, fix [#57](https://github.com/Codeinwp/themeisle-sdk/issues/57) ([2e78856](https://github.com/Codeinwp/themeisle-sdk/commit/2e78856))
|
||||
* change uninstall feedback logo with new version, fix [#58](https://github.com/Codeinwp/themeisle-sdk/issues/58) ([2554a4f](https://github.com/Codeinwp/themeisle-sdk/commit/2554a4f))
|
||||
* remove soon to expire notice, fix https://github.com/Codeinwp/themeisle/issues/752 ([a126225](https://github.com/Codeinwp/themeisle-sdk/commit/a126225))
|
||||
|
||||
## [3.0.8](https://github.com/Codeinwp/themeisle-sdk/compare/v3.0.7...v3.0.8) (2019-05-28)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* undefined class on diff module which should check the class on global namespace ([df6bb12](https://github.com/Codeinwp/themeisle-sdk/commit/df6bb12))
|
||||
|
||||
## [3.0.7](https://github.com/Codeinwp/themeisle-sdk/compare/v3.0.6...v3.0.7) (2019-05-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* change store url with the new domain ([6bdbe1e](https://github.com/Codeinwp/themeisle-sdk/commit/6bdbe1e))
|
||||
|
||||
## [3.0.6](https://github.com/Codeinwp/themeisle-sdk/compare/v3.0.5...v3.0.6) (2019-05-21)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* build php version for deployment stage ([a785699](https://github.com/Codeinwp/themeisle-sdk/commit/a785699))
|
||||
* uninstall feedback should load only on the proper pages ([259e78f](https://github.com/Codeinwp/themeisle-sdk/commit/259e78f))
|
||||
|
||||
## [3.0.5](https://github.com/Codeinwp/themeisle-sdk/compare/v3.0.4...v3.0.5) (2019-03-07)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* dashboard widget issues and recommended module inconsistency fix [#50](https://github.com/Codeinwp/themeisle-sdk/issues/50), [#49](https://github.com/Codeinwp/themeisle-sdk/issues/49), [#47](https://github.com/Codeinwp/themeisle-sdk/issues/47) ([757eb02](https://github.com/Codeinwp/themeisle-sdk/commit/757eb02))
|
||||
|
||||
## [3.0.4](https://github.com/Codeinwp/themeisle-sdk/compare/v3.0.3...v3.0.4) (2019-01-28)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* uninstall feedback disclosure issues when one of the feedback fields is open ([4631eef](https://github.com/Codeinwp/themeisle-sdk/commit/4631eef))
|
||||
|
||||
## [3.0.3](https://github.com/Codeinwp/themeisle-sdk/compare/v3.0.2...v3.0.3) (2019-01-07)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **build:** fix exit code when is running outside wordpress context ([d298bb5](https://github.com/Codeinwp/themeisle-sdk/commit/d298bb5))
|
||||
|
||||
## [3.0.2](https://github.com/Codeinwp/themeisle-sdk/compare/v3.0.1...v3.0.2) (2018-12-28)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* remove composer/installers from package requirements ([a0ad543](https://github.com/Codeinwp/themeisle-sdk/commit/a0ad543))
|
||||
|
||||
## [3.0.1](https://github.com/Codeinwp/themeisle-sdk/compare/v3.0.0...v3.0.1) (2018-12-24)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* notifications setup triggers after all products register their n… ([999a944](https://github.com/Codeinwp/themeisle-sdk/commit/999a944))
|
||||
* notifications setup triggers after all products register their notices ([ec3cacc](https://github.com/Codeinwp/themeisle-sdk/commit/ec3cacc))
|
||||
|
||||
# 1.0.0 (2018-12-21)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* adds uninstall feedback privacy policy info ([ed17943](https://github.com/Codeinwp/themeisle-sdk/commit/ed17943))
|
|
@ -0,0 +1,236 @@
|
|||
<?php
|
||||
/**
|
||||
* The compatibilities model class for ThemeIsle SDK
|
||||
*
|
||||
* @package ThemeIsleSDK
|
||||
* @subpackage Modules
|
||||
* @copyright Copyright (c) 2017, Marius Cristea
|
||||
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace ThemeisleSDK\Modules;
|
||||
|
||||
use ThemeisleSDK\Common\Abstract_Module;
|
||||
use ThemeisleSDK\Product;
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Promotions module for ThemeIsle SDK.
|
||||
*/
|
||||
class Compatibilities extends Abstract_Module {
|
||||
const REQUIRED = 'required';
|
||||
const TESTED_UP = 'tested_up';
|
||||
|
||||
/**
|
||||
* Should we load this module.
|
||||
*
|
||||
* @param Product $product Product object.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function can_load( $product ) {
|
||||
if ( $this->is_from_partner( $product ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( $product->is_theme() && ! current_user_can( 'switch_themes' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $product->is_plugin() && ! current_user_can( 'install_plugins' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the hooks.
|
||||
*
|
||||
* @param Product $product Product to load.
|
||||
*
|
||||
* @throws \Exception If the configuration is invalid.
|
||||
*
|
||||
* @return Compatibilities Module instance.
|
||||
*/
|
||||
public function load( $product ) {
|
||||
|
||||
|
||||
$this->product = $product;
|
||||
|
||||
$compatibilities = apply_filters( 'themeisle_sdk_compatibilities/' . $this->product->get_slug(), [] );
|
||||
if ( empty( $compatibilities ) ) {
|
||||
return $this;
|
||||
}
|
||||
$requirement = null;
|
||||
$check_type = null;
|
||||
foreach ( $compatibilities as $compatibility ) {
|
||||
|
||||
if ( empty( $compatibility['basefile'] ) ) {
|
||||
return $this;
|
||||
}
|
||||
$requirement = new Product( $compatibility['basefile'] );
|
||||
$tested_up = isset( $compatibility[ self::TESTED_UP ] ) ? $compatibility[ self::TESTED_UP ] : '999';
|
||||
$required = $compatibility[ self::REQUIRED ];
|
||||
if ( ! version_compare( $required, $tested_up, '<' ) ) {
|
||||
throw new \Exception( sprintf( 'Invalid required/tested_up configuration. Required version %s should be lower than tested_up %s.', $required, $tested_up ) );
|
||||
}
|
||||
$check_type = self::REQUIRED;
|
||||
if ( ! version_compare( $requirement->get_version(), $required, '<' ) ) {
|
||||
$check_type = self::TESTED_UP;
|
||||
if ( version_compare( $requirement->get_version(), $tested_up . '.9999', '<' ) ) {
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
if ( empty( $requirement ) ) {
|
||||
return $this;
|
||||
}
|
||||
if ( $check_type === self::REQUIRED ) {
|
||||
$this->mark_required( $product, $requirement );
|
||||
}
|
||||
if ( $check_type === self::TESTED_UP ) {
|
||||
$this->mark_testedup( $product, $requirement );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the product tested up.
|
||||
*
|
||||
* @param Product $product Product object.
|
||||
* @param Product $requirement Requirement object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function mark_testedup( $product, $requirement ) {
|
||||
add_action(
|
||||
'admin_head',
|
||||
function () use ( $product, $requirement ) {
|
||||
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : '';
|
||||
|
||||
if ( empty( $screen ) || ! isset( $screen->id ) ) {
|
||||
return;
|
||||
}
|
||||
if ( $requirement->is_theme() && $screen->id === 'themes' ) {
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function ($) {
|
||||
setInterval(checkTheme, 500);
|
||||
function checkTheme() {
|
||||
var theme = jQuery( '.theme.active[data-slug="<?php echo esc_attr( $requirement->get_slug() ); ?>"]' );
|
||||
var notice_id = 'testedup<?php echo esc_attr( $requirement->get_slug() . $product->get_slug() ); ?>';
|
||||
var product_name = '<?php echo esc_attr( $product->get_friendly_name() ); ?>';
|
||||
if (theme.length > 0 && jQuery('#' + notice_id).length === 0) {
|
||||
theme.find('.theme-id-container').prepend('<div style="bottom:100%;top:auto;" id="'+notice_id+'" class="notice notice-warning"><strong>Warning:</strong> This theme has not been tested with your current version of <strong>' + product_name +'</strong>. Please update '+product_name+' plugin.</div>');
|
||||
}
|
||||
if (theme.length > 0 && jQuery('#' + notice_id + 'overlay').length === 0) {
|
||||
jQuery('.theme-overlay.active .theme-author').after('<div style="bottom:100%;top:auto;" id="'+notice_id+'overlay" class="notice notice-warning"><p><strong>Warning:</strong> This theme has not been tested with your current version of <strong>' + product_name +'</strong>. Please update '+product_name+' plugin.</p></div>');
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
if ( $requirement->is_plugin() && $screen->id === 'plugins' ) {
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function ($) {
|
||||
setInterval(checkPlugin, 500);
|
||||
function checkPlugin() {
|
||||
var plugin = jQuery( '.plugins .active[data-slug="<?php echo esc_attr( $requirement->get_slug() ); ?>"]' );
|
||||
var notice_id = 'testedup<?php echo esc_attr( $requirement->get_slug() . $product->get_slug() ); ?>';
|
||||
var product_name = '<?php echo esc_attr( $product->get_friendly_name() ); ?>';
|
||||
var product_type = '<?php echo ( $product->is_plugin() ? 'plugin' : 'theme' ); ?>';
|
||||
if (plugin.length > 0 && jQuery('#' + notice_id).length === 0) {
|
||||
plugin.find('.column-description').append('<div style="bottom:100%;top:auto;" id="'+notice_id+'" class="notice notice-warning notice-alt notice-inline"><strong>Warning:</strong> This plugin has not been tested with your current version of <strong>' + product_name +'</strong>. Please update '+product_name+' '+product_type+'.</div>');
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the product requirements.
|
||||
*
|
||||
* @param Product $product Product object.
|
||||
* @param Product $requirement Requirement object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function mark_required( $product, $requirement ) {
|
||||
add_filter(
|
||||
'upgrader_pre_download',
|
||||
function ( $return, $package, $upgrader ) use ( $product, $requirement ) {
|
||||
/**
|
||||
* Upgrader object.
|
||||
*
|
||||
* @var \WP_Upgrader $upgrader Upgrader object.
|
||||
*/
|
||||
$should_block = false;
|
||||
if ( $product->is_theme()
|
||||
&& property_exists( $upgrader, 'skin' )
|
||||
&& property_exists( $upgrader->skin, 'theme_info' )
|
||||
&& $upgrader->skin->theme_info->template === $product->get_slug() ) {
|
||||
$should_block = true;
|
||||
|
||||
}
|
||||
if ( ! $should_block && $product->is_plugin()
|
||||
&& property_exists( $upgrader, 'skin' )
|
||||
&& property_exists( $upgrader->skin, 'plugin_info' )
|
||||
&& $upgrader->skin->plugin_info['Name'] === $product->get_name() ) {
|
||||
$should_block = true;
|
||||
}
|
||||
if ( $should_block ) {
|
||||
echo( sprintf(
|
||||
'%s update requires a newer version of %s. Please %supdate%s %s %s.',
|
||||
esc_attr( $product->get_friendly_name() ),
|
||||
esc_attr( $requirement->get_friendly_name() ),
|
||||
'<a href="' . esc_url( admin_url( $requirement->is_theme() ? 'themes.php' : 'plugins.php' ) ) . '">',
|
||||
'</a>',
|
||||
esc_attr( $requirement->get_friendly_name() ),
|
||||
esc_attr( $requirement->is_theme() ? 'theme' : 'plugin' )
|
||||
) );
|
||||
$upgrader->maintenance_mode( false );
|
||||
die();
|
||||
}
|
||||
|
||||
return $return;
|
||||
},
|
||||
10,
|
||||
3
|
||||
);
|
||||
|
||||
add_action(
|
||||
'admin_notices',
|
||||
function () use ( $product, $requirement ) {
|
||||
echo '<div class="notice notice-error "><p>';
|
||||
echo( sprintf(
|
||||
'%s requires a newer version of %s. Please %supdate%s %s %s to the latest version.',
|
||||
'<strong>' . esc_attr( $product->get_friendly_name() ) . '</strong>',
|
||||
'<strong>' . esc_attr( $requirement->get_friendly_name() ) . '</strong>',
|
||||
'<a href="' . esc_url( admin_url( $requirement->is_theme() ? 'themes.php' : 'plugins.php' ) ) . '">',
|
||||
'</a>',
|
||||
'<strong>' . esc_attr( $requirement->get_friendly_name() ) . '</strong>',
|
||||
esc_attr( $requirement->is_theme() ? 'theme' : 'plugin' )
|
||||
) );
|
||||
echo '</p></div>';
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 210 KiB |
|
@ -0,0 +1,959 @@
|
|||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
|
||||
define( 'SWCFPC_ADVANCED_CACHE', true );
|
||||
|
||||
if( !swcfpc_is_this_page_cachable() )
|
||||
return;
|
||||
|
||||
if( isset( $_SERVER['REQUEST_METHOD'] ) && strcasecmp($_SERVER['REQUEST_METHOD'], "GET") != 0 )
|
||||
return;
|
||||
|
||||
$swcfpc_fallback_cache_config_path = WP_CONTENT_DIR . "/wp-cloudflare-super-page-cache/{$_SERVER['HTTP_HOST']}/";
|
||||
$swcfpc_fallback_cache_path = WP_CONTENT_DIR . "/wp-cloudflare-super-page-cache/{$_SERVER['HTTP_HOST']}/fallback_cache/";
|
||||
$swcfpc_fallback_cache_key = swcfpc_fallback_cache_get_current_page_cache_key();
|
||||
|
||||
if( !file_exists("{$swcfpc_fallback_cache_config_path}main_config.php") )
|
||||
return;
|
||||
|
||||
include( "{$swcfpc_fallback_cache_config_path}main_config.php" );
|
||||
|
||||
$swcfpc_config = json_decode( stripslashes($swcfpc_config), true );
|
||||
|
||||
if( !is_array($swcfpc_config) )
|
||||
return;
|
||||
|
||||
if( swcfpc_fallback_cache_is_url_to_exclude() )
|
||||
return;
|
||||
|
||||
if( swcfpc_fallback_cache_is_cookie_to_exclude() )
|
||||
return;
|
||||
|
||||
if( swcfpc_fallback_cache_is_cookie_to_exclude_cf_worker() )
|
||||
return;
|
||||
|
||||
if( file_exists($swcfpc_fallback_cache_path . $swcfpc_fallback_cache_key) && !swcfpc_fallback_cache_is_expired_page( $swcfpc_fallback_cache_key ) ) {
|
||||
|
||||
$cache_controller = "s-maxage={$swcfpc_config['cf_maxage']}, max-age={$swcfpc_config['cf_browser_maxage']}";
|
||||
$stored_headers = swcfpc_fallback_cache_get_stored_headers($swcfpc_fallback_cache_path, $swcfpc_fallback_cache_key);
|
||||
|
||||
if( (int) $swcfpc_config['cf_maxage'] > 0 ) {
|
||||
header_remove('Set-Cookie');
|
||||
}
|
||||
|
||||
header_remove('Pragma');
|
||||
header_remove('Expires');
|
||||
header_remove('Cache-Control');
|
||||
header("Cache-Control: {$cache_controller}");
|
||||
header('X-WP-CF-Super-Cache: cache');
|
||||
header('X-WP-CF-Super-Cache-Active: 1');
|
||||
header('X-WP-CF-Fallback-Cache: 1');
|
||||
header("X-WP-CF-Super-Cache-Cache-Control: {$cache_controller}");
|
||||
|
||||
if( isset($swcfpc_config['cf_woker_enabled']) && $swcfpc_config['cf_woker_enabled'] > 0 && isset($swcfpc_config['cf_worker_bypass_cookies']) && is_array($swcfpc_config['cf_worker_bypass_cookies']) && count($swcfpc_config['cf_worker_bypass_cookies']) > 0 ) {
|
||||
header( 'X-WP-CF-Super-Cache-Cookies-Bypass: ' . trim( implode( '|', $swcfpc_config['cf_worker_bypass_cookies'] ) ) );
|
||||
}
|
||||
|
||||
if( $stored_headers ) {
|
||||
|
||||
foreach($stored_headers as $single_header) {
|
||||
header($single_header, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
die( file_get_contents($swcfpc_fallback_cache_path . $swcfpc_fallback_cache_key).'<!-- ADVANCED CACHE -->');
|
||||
|
||||
}
|
||||
|
||||
ob_start( 'swcfpc_fallback_cache_end' );
|
||||
|
||||
|
||||
function swcfpc_is_this_page_cachable() {
|
||||
|
||||
if(
|
||||
swcfpc_is_api_request() ||
|
||||
( isset( $GLOBALS['pagenow'] ) && in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) ) ||
|
||||
( isset( $_SERVER['REQUEST_URI'] ) && substr( $_SERVER['REQUEST_URI'], 0, 16 ) == '/wp-register.php' ) ||
|
||||
( isset( $_SERVER['REQUEST_URI'] ) && substr( $_SERVER['REQUEST_URI'], 0, 13 ) == '/wp-login.php' ) ||
|
||||
( isset( $_SERVER['REQUEST_METHOD'] ) && strcasecmp( $_SERVER['REQUEST_METHOD'], 'GET' ) != 0 ) ||
|
||||
( !defined('SWCFPC_CACHE_BUSTER' ) && isset( $_GET['swcfpc'] ) ) ||
|
||||
( defined( 'SWCFPC_CACHE_BUSTER' ) && isset( $_GET[SWCFPC_CACHE_BUSTER] ) ) ||
|
||||
is_admin() ||
|
||||
( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ) ||
|
||||
( defined( 'DOING_AJAX' ) && DOING_AJAX ) ||
|
||||
( defined( 'WP_CLI' ) && WP_CLI ) ||
|
||||
( defined( 'DOING_CRON' ) && DOING_CRON )
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function swcfpc_is_api_request() {
|
||||
|
||||
// Wordpress standard API
|
||||
if( (defined('REST_REQUEST') && REST_REQUEST) || strcasecmp( substr($_SERVER['REQUEST_URI'], 0, 8), '/wp-json' ) == 0 )
|
||||
return true;
|
||||
|
||||
// WooCommerce standard API
|
||||
if( strcasecmp( substr($_SERVER['REQUEST_URI'], 0, 8), '/wc-api/' ) == 0 )
|
||||
return true;
|
||||
|
||||
// WooCommerce standard API
|
||||
if( strcasecmp( substr($_SERVER['REQUEST_URI'], 0, 9), '/edd-api/' ) == 0 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function swcfpc_fallback_cache_end( $html ) {
|
||||
|
||||
global $sw_cloudflare_pagecache;
|
||||
|
||||
if( strlen( trim($html) ) == 0 )
|
||||
return $html;
|
||||
|
||||
if( !is_object($sw_cloudflare_pagecache) )
|
||||
return $html;
|
||||
|
||||
$swcfpc_objects = $sw_cloudflare_pagecache->get_objects();
|
||||
|
||||
if( $sw_cloudflare_pagecache->get_single_config('cf_fallback_cache', 0) == 0 )
|
||||
return $html;
|
||||
|
||||
if( $swcfpc_objects['cache_controller']->is_cache_enabled() && !$swcfpc_objects['cache_controller']->is_url_to_bypass() && !$swcfpc_objects['cache_controller']->can_i_bypass_cache() && isset( $_SERVER['REQUEST_METHOD'] ) && strcasecmp($_SERVER['REQUEST_METHOD'], 'GET') == 0 ) {
|
||||
|
||||
if (isset($_SERVER['HTTP_USER_AGENT']) && strcasecmp($_SERVER['HTTP_USER_AGENT'], 'ua-swcfpc-fc') == 0)
|
||||
return $html;
|
||||
|
||||
$cache_path = $swcfpc_objects['fallback_cache']->fallback_cache_init_directory();
|
||||
$cache_key = swcfpc_fallback_cache_get_current_page_cache_key();
|
||||
|
||||
if (!file_exists($cache_path . $cache_key) || $swcfpc_objects['fallback_cache']->fallback_cache_is_expired_page($cache_key)) {
|
||||
|
||||
if ($sw_cloudflare_pagecache->get_single_config('cf_fallback_cache_ttl', 0) == 0) {
|
||||
$ttl = 0;
|
||||
} else {
|
||||
$ttl = time() + $sw_cloudflare_pagecache->get_single_config('cf_fallback_cache_ttl', 0);
|
||||
}
|
||||
|
||||
if( $ttl > 0 ) {
|
||||
$html .= "\n<!-- Page retrieved from Super Page Cache for Cloudflare's fallback cache - page generated @ " . date('Y-m-d H:i:s') . ' - fallback cache expiration @ ' . date('Y-m-d H:i:s', $ttl) . " - cache key {$cache_key} -->";
|
||||
} else {
|
||||
$html .= "\n<!-- Page retrieved from Super Page Cache for Cloudflare's fallback cache - page generated @ " . date('Y-m-d H:i:s') . " - fallback cache expiration @ never expires - cache key {$cache_key} -->";
|
||||
}
|
||||
|
||||
// Provide a filter to modify the HTML before it is cached
|
||||
$html = apply_filters( 'swcfpc_normal_fallback_cache_html', $html );
|
||||
|
||||
file_put_contents($cache_path . $cache_key, $html);
|
||||
|
||||
// Update TTL
|
||||
$swcfpc_objects['fallback_cache']->fallback_cache_set_single_ttl($cache_key, $ttl);
|
||||
$swcfpc_objects['fallback_cache']->fallback_cache_update_ttl_registry();
|
||||
|
||||
// Store headers
|
||||
if ($sw_cloudflare_pagecache->get_single_config('cf_fallback_cache_save_headers', 0) > 0) {
|
||||
swcfpc_fallback_cache_save_headers($cache_path, $cache_key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $html;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function swcfpc_fallback_cache_get_current_page_cache_key( $url=null ) {
|
||||
|
||||
$replacements = array( '://', '/', '?', '#', '&', '.', ',', '@', '-', '\'', '"', '%', ' ', '\\', '=' );
|
||||
|
||||
if( !is_null($url) ) {
|
||||
|
||||
$parts = parse_url( strtolower($url) );
|
||||
|
||||
if( !$parts )
|
||||
return false;
|
||||
|
||||
$current_uri = isset($parts['path']) ? $parts['path'] : '/';
|
||||
|
||||
if( isset($parts['query']) )
|
||||
$current_uri .= "?{$parts['query']}";
|
||||
|
||||
if( $current_uri == '/' )
|
||||
$current_uri = $parts['host'];
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
$current_uri = $_SERVER['REQUEST_URI'];
|
||||
|
||||
if( $current_uri == '/' ) {
|
||||
$current_uri = $_SERVER['HTTP_HOST'];
|
||||
}
|
||||
}
|
||||
|
||||
if( substr($current_uri, 0, 1) == '/' )
|
||||
$current_uri = substr($current_uri, 1);
|
||||
|
||||
if( substr($current_uri, -1, 1) == '/' )
|
||||
$current_uri = substr($current_uri, 0, -1);
|
||||
|
||||
if( has_filter( 'swcfpc_fc_modify_current_url' ) ) {
|
||||
|
||||
// Modify the current URL by yourself to remove the query string or any other unwanted characters
|
||||
$current_uri = apply_filters( 'swcfpc_fc_modify_current_url', $current_uri );
|
||||
|
||||
$cache_key = str_replace( $replacements, '_', $current_uri );
|
||||
|
||||
} else {
|
||||
|
||||
$cache_key = str_replace( $replacements, '_', swcfpc_fallback_cache_remove_url_parameters($current_uri) );
|
||||
}
|
||||
|
||||
|
||||
// Fix error fnmatch(): Filename exceeds the maximum allowed length
|
||||
$cache_key = sha1( $cache_key );
|
||||
|
||||
/*
|
||||
if( strlen($cache_key) > 250 ) {
|
||||
$cache_key = substr($cache_key, 0, -32);
|
||||
$cache_key .= md5( $current_uri );
|
||||
}
|
||||
*/
|
||||
|
||||
$cache_key .= '.html';
|
||||
|
||||
return $cache_key;
|
||||
|
||||
}
|
||||
|
||||
function swcfpc_get_unparsed_url( $parsed_url ) {
|
||||
// PHP_URL_SCHEME
|
||||
$scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
|
||||
$host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
|
||||
$port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
|
||||
$user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
|
||||
$pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
|
||||
$pass = ($user || $pass) ? "$pass@" : '';
|
||||
$path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
|
||||
$query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
|
||||
$fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
|
||||
return "{$scheme}{$user}{$pass}{$host}{$port}{$path}{$query}{$fragment}";
|
||||
}
|
||||
|
||||
function swcfpc_fallback_cache_remove_url_parameters( $url ) {
|
||||
|
||||
$url_parsed = parse_url( $url );
|
||||
$url_query_params = [];
|
||||
|
||||
if( array_key_exists( 'query', $url_parsed ) ) {
|
||||
|
||||
if( $url_parsed[ 'query' ] === '' ) {
|
||||
|
||||
// this means the URL ends with just ? i.e. /example-page/? - so just remove the last character ? from the URL
|
||||
$url = substr( trim( $url ), 0, -1 );
|
||||
|
||||
} else {
|
||||
|
||||
// Set the ignored query param array
|
||||
$ignored_query_params = [
|
||||
'Browser',
|
||||
'C',
|
||||
'GCCON',
|
||||
'MCMP',
|
||||
'MarketPlace',
|
||||
'PD',
|
||||
'Refresh',
|
||||
'Sens',
|
||||
'ServiceVersion',
|
||||
'Source',
|
||||
'Topic',
|
||||
'__WB_REVISION__',
|
||||
'__cf_chl_jschl_tk__',
|
||||
'__d',
|
||||
'__hsfp',
|
||||
'__hssc',
|
||||
'__hstc',
|
||||
'__s',
|
||||
'_branch_match_id',
|
||||
'_bta_c',
|
||||
'_bta_tid',
|
||||
'_com',
|
||||
'_escaped_fragment_',
|
||||
'_ga',
|
||||
'_ga-ft',
|
||||
'_gl',
|
||||
'_hsmi',
|
||||
'_ke',
|
||||
'_kx',
|
||||
'_paged',
|
||||
'_sm_byp',
|
||||
'_sp',
|
||||
'_szp',
|
||||
'_thumbnail_id',
|
||||
'3x',
|
||||
'a',
|
||||
'a_k',
|
||||
'ac',
|
||||
'acpage',
|
||||
'action-box',
|
||||
'action_object_map',
|
||||
'action_ref_map',
|
||||
'action_type_map',
|
||||
'activecampaign_id',
|
||||
'ad',
|
||||
'ad_frame_full',
|
||||
'ad_frame_root',
|
||||
'ad_name',
|
||||
'adclida',
|
||||
'adid',
|
||||
'adlt',
|
||||
'adsafe_ip',
|
||||
'adset_name',
|
||||
'advid',
|
||||
'aff_sub2',
|
||||
'afftrack',
|
||||
'afterload',
|
||||
'ak_action',
|
||||
'alt_id',
|
||||
'am',
|
||||
'amazingmurphybeds',
|
||||
'amp;',
|
||||
'amp;amp',
|
||||
'amp;amp;amp',
|
||||
'amp;amp;amp;amp',
|
||||
'amp;utm_campaign',
|
||||
'amp;utm_medium',
|
||||
'amp;utm_source',
|
||||
'amp%3Butm_content',
|
||||
'ampStoryAutoAnalyticsLinker',
|
||||
'ampstoryautoanalyticslinke',
|
||||
'an',
|
||||
'ap',
|
||||
'ap_id',
|
||||
'apif',
|
||||
'apipage',
|
||||
'as_occt',
|
||||
'as_q',
|
||||
'as_qdr',
|
||||
'askid',
|
||||
'atFileReset',
|
||||
'atfilereset',
|
||||
'aucid',
|
||||
'auct',
|
||||
'audience',
|
||||
'author',
|
||||
'awt_a',
|
||||
'awt_l',
|
||||
'awt_m',
|
||||
'b2w',
|
||||
'back',
|
||||
'bannerID',
|
||||
'blackhole',
|
||||
'blockedAdTracking',
|
||||
'blog-reader-used',
|
||||
'blogger',
|
||||
'body',
|
||||
'br',
|
||||
'bsft_aaid',
|
||||
'bsft_clkid',
|
||||
'bsft_eid',
|
||||
'bsft_ek',
|
||||
'bsft_lx',
|
||||
'bsft_mid',
|
||||
'bsft_mime_type',
|
||||
'bsft_tv',
|
||||
'bsft_uid',
|
||||
'bvMethod',
|
||||
'bvTime',
|
||||
'bvVersion',
|
||||
'bvb64',
|
||||
'bvb64resp',
|
||||
'bvplugname',
|
||||
'bvprms',
|
||||
'bvprmsmac',
|
||||
'bvreqmerge',
|
||||
'cacheburst',
|
||||
'campaign',
|
||||
'campaign_id',
|
||||
'campaign_name',
|
||||
'campid',
|
||||
'catablog-gallery',
|
||||
'channel',
|
||||
'checksum',
|
||||
'ck_subscriber_id',
|
||||
'cmplz_region_redirect',
|
||||
'cmpnid',
|
||||
'cn-reloaded',
|
||||
'code',
|
||||
'comment',
|
||||
'content_ad_widget',
|
||||
'cost',
|
||||
'cr',
|
||||
'crl8_id',
|
||||
'crlt.pid',
|
||||
'crlt_pid',
|
||||
'crrelr',
|
||||
'crtvid',
|
||||
'ct',
|
||||
'cuid',
|
||||
'daksldlkdsadas',
|
||||
'dcc',
|
||||
'dfp',
|
||||
'dm_i',
|
||||
'domain',
|
||||
'dosubmit',
|
||||
'dsp_caid',
|
||||
'dsp_crid',
|
||||
'dsp_insertion_order_id',
|
||||
'dsp_pub_id',
|
||||
'dsp_tracker_token',
|
||||
'dt',
|
||||
'dur',
|
||||
'durs',
|
||||
'e',
|
||||
'ee',
|
||||
'ef_id',
|
||||
'el',
|
||||
'emailID',
|
||||
'env',
|
||||
'epik',
|
||||
'erprint',
|
||||
'et_blog',
|
||||
'exch',
|
||||
'externalid',
|
||||
'fb_action_ids',
|
||||
'fb_action_types',
|
||||
'fb_ad',
|
||||
'fb_source',
|
||||
'fbclid',
|
||||
'fbzunique',
|
||||
'fg-aqp',
|
||||
'fireglass_rsn',
|
||||
'firstName',
|
||||
'fo',
|
||||
'fp_sid',
|
||||
'fpa',
|
||||
'fref',
|
||||
'fs',
|
||||
'furl',
|
||||
'fwp_lunch_restrictions',
|
||||
'ga_action',
|
||||
'gclid',
|
||||
'gclsrc',
|
||||
'gdffi',
|
||||
'gdfms',
|
||||
'gdftrk',
|
||||
'gf_page',
|
||||
'gidzl',
|
||||
'goal',
|
||||
'gooal',
|
||||
'gpu',
|
||||
'gtVersion',
|
||||
'haibwc',
|
||||
'hash',
|
||||
'hc_location',
|
||||
'hemail',
|
||||
'hid',
|
||||
'highlight',
|
||||
'hl',
|
||||
'home',
|
||||
'hsa_acc',
|
||||
'hsa_ad',
|
||||
'hsa_cam',
|
||||
'hsa_grp',
|
||||
'hsa_kw',
|
||||
'hsa_mt',
|
||||
'hsa_net',
|
||||
'hsa_src',
|
||||
'hsa_tgt',
|
||||
'hsa_ver',
|
||||
'ias_campId',
|
||||
'ias_chanId',
|
||||
'ias_dealId',
|
||||
'ias_dspId',
|
||||
'ias_impId',
|
||||
'ias_placementId',
|
||||
'ias_pubId',
|
||||
'ical',
|
||||
'ict',
|
||||
'ie',
|
||||
'igshid',
|
||||
'im',
|
||||
'ipl',
|
||||
'jw_start',
|
||||
'jwsource',
|
||||
'k',
|
||||
'key1',
|
||||
'key2',
|
||||
'klaviyo',
|
||||
'ksconf',
|
||||
'ksref',
|
||||
'l',
|
||||
'label',
|
||||
'lang',
|
||||
'ldtag_cl',
|
||||
'level1',
|
||||
'level2',
|
||||
'level3',
|
||||
'level4',
|
||||
'limit',
|
||||
'lng',
|
||||
'load_all_comments',
|
||||
'lt',
|
||||
'ltclid',
|
||||
'ltd',
|
||||
'lucky',
|
||||
'm',
|
||||
'm?sales_kw',
|
||||
'matomo_campaign',
|
||||
'matomo_cid',
|
||||
'matomo_content',
|
||||
'matomo_group',
|
||||
'matomo_keyword',
|
||||
'matomo_medium',
|
||||
'matomo_placement',
|
||||
'matomo_source',
|
||||
'max-results',
|
||||
'mc_cid',
|
||||
'mc_eid',
|
||||
'mdrv',
|
||||
'mediaserver',
|
||||
'memset',
|
||||
'mibextid',
|
||||
'mkcid',
|
||||
'mkevt',
|
||||
'mkrid',
|
||||
'mkwid',
|
||||
'mkt_tok',
|
||||
'ml_subscriber',
|
||||
'ml_subscriber_hash',
|
||||
'mobileOn',
|
||||
'mode',
|
||||
'moderation-hash',
|
||||
'modernpatio',
|
||||
'month',
|
||||
'msID',
|
||||
'msclkid',
|
||||
'msg',
|
||||
'mtm_campaign',
|
||||
'mtm_cid',
|
||||
'mtm_content',
|
||||
'mtm_group',
|
||||
'mtm_keyword',
|
||||
'mtm_medium',
|
||||
'mtm_placement',
|
||||
'mtm_source',
|
||||
'murphybedstoday',
|
||||
'mwprid',
|
||||
'n',
|
||||
'name',
|
||||
'native_client',
|
||||
'navua',
|
||||
'nb',
|
||||
'nb_klid',
|
||||
'nowprocketcache',
|
||||
'o',
|
||||
'okijoouuqnqq',
|
||||
'org',
|
||||
'pa_service_worker',
|
||||
'partnumber',
|
||||
'pcmtid',
|
||||
'pcode',
|
||||
'pcrid',
|
||||
'pfstyle',
|
||||
'phrase',
|
||||
'pid',
|
||||
'piwik_campaign',
|
||||
'piwik_keyword',
|
||||
'piwik_kwd',
|
||||
'pk_campaign',
|
||||
'pk_keyword',
|
||||
'pk_kwd',
|
||||
'placement',
|
||||
'plat',
|
||||
'platform',
|
||||
'playsinline',
|
||||
'position',
|
||||
'pp',
|
||||
'pr',
|
||||
'preview',
|
||||
'preview_id',
|
||||
'preview_nonce',
|
||||
'prid',
|
||||
'print',
|
||||
'q',
|
||||
'q1',
|
||||
'qsrc',
|
||||
'r',
|
||||
'rd',
|
||||
'rdt_cid',
|
||||
'redig',
|
||||
'redir',
|
||||
'ref',
|
||||
'reftok',
|
||||
'relatedposts_hit',
|
||||
'relatedposts_origin',
|
||||
'relatedposts_position',
|
||||
'remodel',
|
||||
'replytocom',
|
||||
'rest_route',
|
||||
'reverse-paginate',
|
||||
'rid',
|
||||
'rnd',
|
||||
'rndnum',
|
||||
'robots_txt',
|
||||
'rq',
|
||||
'rsd',
|
||||
's_kwcid',
|
||||
'sa',
|
||||
'safe',
|
||||
'said',
|
||||
'sales_cat',
|
||||
'sales_kw',
|
||||
'sb_referer_host',
|
||||
'scrape',
|
||||
'script',
|
||||
'scrlybrkr',
|
||||
'search',
|
||||
'sellid',
|
||||
'sersafe',
|
||||
'sfn_data',
|
||||
'sfn_trk',
|
||||
'sfns',
|
||||
'sfw',
|
||||
'sha1',
|
||||
'share',
|
||||
'shared',
|
||||
'showcomment',
|
||||
'showComment',
|
||||
'si',
|
||||
'sid',
|
||||
'sid1',
|
||||
'sid2',
|
||||
'sidewalkShow',
|
||||
'sig',
|
||||
'site',
|
||||
'site_id',
|
||||
'siteid',
|
||||
'slicer1',
|
||||
'slicer2',
|
||||
'source',
|
||||
'spref',
|
||||
'spvb',
|
||||
'sra',
|
||||
'src',
|
||||
'srk',
|
||||
'srp',
|
||||
'ssp_iabi',
|
||||
'ssts',
|
||||
'stylishmurphybeds',
|
||||
'subId1 ',
|
||||
'subId2 ',
|
||||
'subId3',
|
||||
'subid',
|
||||
'swcfpc',
|
||||
'tail',
|
||||
'teaser',
|
||||
'test',
|
||||
'timezone',
|
||||
'toWww',
|
||||
'triplesource',
|
||||
'trk_contact',
|
||||
'trk_module',
|
||||
'trk_msg',
|
||||
'trk_sid',
|
||||
'tsig',
|
||||
'turl',
|
||||
'u',
|
||||
'unapproved',
|
||||
'up_auto_log',
|
||||
'upage',
|
||||
'updated-max',
|
||||
'uptime',
|
||||
'us_privacy',
|
||||
'usegapi',
|
||||
'userConsent',
|
||||
'usqp',
|
||||
'utm',
|
||||
'utm_campa',
|
||||
'utm_campaign',
|
||||
'utm_content',
|
||||
'utm_expid',
|
||||
'utm_id',
|
||||
'utm_medium',
|
||||
'utm_reader',
|
||||
'utm_referrer',
|
||||
'utm_source',
|
||||
'utm_sq',
|
||||
'utm_ter',
|
||||
'utm_term',
|
||||
'v',
|
||||
'vc',
|
||||
'vf',
|
||||
'vgo_ee',
|
||||
'vp',
|
||||
'vrw',
|
||||
'vz',
|
||||
'wbraid',
|
||||
'webdriver',
|
||||
'wing',
|
||||
'wpdParentID',
|
||||
'wpmp_switcher',
|
||||
'wref',
|
||||
'wswy',
|
||||
'wtime',
|
||||
'x',
|
||||
'zMoatImpID',
|
||||
'zarsrc',
|
||||
'zeffdn'
|
||||
];
|
||||
|
||||
// First parse the query params to an array to manage it better
|
||||
parse_str( $url_parsed[ 'query' ], $url_query_params );
|
||||
|
||||
// Loop though $ignored_query_params
|
||||
foreach( $ignored_query_params as $ignored_query_param ) {
|
||||
|
||||
// Check if that query param is present in $url_query_params
|
||||
if( array_key_exists( $ignored_query_param, $url_query_params ) ) {
|
||||
|
||||
// The ignored query param is present in the $url_query_params. So, unset it from there
|
||||
unset( $url_query_params[ $ignored_query_param ] );
|
||||
}
|
||||
}
|
||||
|
||||
// Now lets check if we have any query params left in $url_query_params
|
||||
if( count( $url_query_params ) > 0 ) {
|
||||
|
||||
$new_url_query_params = http_build_query( $url_query_params );
|
||||
$url_parsed[ 'query' ] = $new_url_query_params;
|
||||
|
||||
} else {
|
||||
// Remove the query section from parsed URL
|
||||
unset( $url_parsed[ 'query' ] );
|
||||
}
|
||||
|
||||
// Get the new current URL without the marketing query params
|
||||
$url = swcfpc_get_unparsed_url( $url_parsed );
|
||||
}
|
||||
}
|
||||
|
||||
return $url;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function swcfpc_fallback_cache_is_expired_page( $cache_key ) {
|
||||
|
||||
$config_path = WP_CONTENT_DIR . "/wp-cloudflare-super-page-cache/{$_SERVER['HTTP_HOST']}/";
|
||||
|
||||
if( !file_exists("{$config_path}ttl_registry.json") )
|
||||
return false;
|
||||
|
||||
$swcfpc_ttl_registry = json_decode( file_get_contents( "{$config_path}ttl_registry.json" ), true );
|
||||
$current_ttl = 0;
|
||||
|
||||
if( !is_array($swcfpc_ttl_registry) || !isset($swcfpc_ttl_registry[$cache_key]) )
|
||||
$current_ttl = 0;
|
||||
else if( is_array($swcfpc_ttl_registry[$cache_key]))
|
||||
$current_ttl = $swcfpc_ttl_registry[$cache_key];
|
||||
else
|
||||
$current_ttl = (int) $swcfpc_ttl_registry[$cache_key];
|
||||
|
||||
if( $current_ttl > 0 && time() > $current_ttl )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function swcfpc_fallback_cache_is_cookie_to_exclude() {
|
||||
|
||||
global $swcfpc_config;
|
||||
|
||||
if( count($_COOKIE) == 0 )
|
||||
return false;
|
||||
|
||||
if( is_array($swcfpc_config) && !isset($swcfpc_config['cf_fallback_cache_excluded_cookies']) )
|
||||
return false;
|
||||
|
||||
$excluded_cookies = $swcfpc_config['cf_fallback_cache_excluded_cookies'];
|
||||
|
||||
if( count($excluded_cookies) == 0 )
|
||||
return false;
|
||||
|
||||
$cookies = array_keys( $_COOKIE );
|
||||
|
||||
foreach ($excluded_cookies as $single_cookie) {
|
||||
|
||||
if( count( preg_grep("#{$single_cookie}#", $cookies) ) > 0 )
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function swcfpc_fallback_cache_is_cookie_to_exclude_cf_worker() {
|
||||
|
||||
global $swcfpc_config;
|
||||
|
||||
if( count($_COOKIE) == 0 )
|
||||
return false;
|
||||
|
||||
if( !is_array($swcfpc_config) )
|
||||
return false;
|
||||
|
||||
if( !isset($swcfpc_config['cf_worker_bypass_cookies']) || !isset($swcfpc_config['cf_woker_enabled']) )
|
||||
return false;
|
||||
|
||||
if( (int) $swcfpc_config['cf_woker_enabled'] == 0 )
|
||||
return false;
|
||||
|
||||
$excluded_cookies = $swcfpc_config['cf_worker_bypass_cookies'];
|
||||
|
||||
if( count($excluded_cookies) == 0 )
|
||||
return false;
|
||||
|
||||
$cookies = array_keys( $_COOKIE );
|
||||
|
||||
foreach ($excluded_cookies as $single_cookie) {
|
||||
|
||||
if( count( preg_grep("#{$single_cookie}#", $cookies) ) > 0 )
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function swcfpc_fallback_cache_is_url_to_exclude($url=false) {
|
||||
|
||||
global $swcfpc_config;
|
||||
|
||||
if( is_array($swcfpc_config) && isset($swcfpc_config['cf_fallback_cache_prevent_cache_urls_without_trailing_slash']) && $swcfpc_config['cf_fallback_cache_prevent_cache_urls_without_trailing_slash'] > 0 && !preg_match('/\/$/', $_SERVER['REQUEST_URI']) )
|
||||
return true;
|
||||
|
||||
if( is_array($swcfpc_config) && !isset($swcfpc_config['cf_fallback_cache_excluded_urls']) )
|
||||
return false;
|
||||
|
||||
$excluded_urls = $swcfpc_config['cf_fallback_cache_excluded_urls'];
|
||||
|
||||
if( is_array($excluded_urls) && count($excluded_urls) > 0 ) {
|
||||
|
||||
if( $url === false ) {
|
||||
|
||||
$current_url = $_SERVER['REQUEST_URI'];
|
||||
|
||||
if( isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0 )
|
||||
$current_url .= "?{$_SERVER['QUERY_STRING']}";
|
||||
|
||||
}
|
||||
else {
|
||||
$current_url = $url;
|
||||
}
|
||||
|
||||
foreach( $excluded_urls as $url_to_exclude ) {
|
||||
|
||||
if( swcfpc_wildcard_match($url_to_exclude, $current_url) )
|
||||
return true;
|
||||
|
||||
/*
|
||||
if( fnmatch($url_to_exclude, $current_url, FNM_CASEFOLD) ) {
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function swcfpc_fallback_cache_save_headers( $fallback_cache_path, $cache_key ) {
|
||||
|
||||
$headers_file = "{$fallback_cache_path}{$cache_key}.headers.json";
|
||||
|
||||
$headers_list = headers_list();
|
||||
$headers_count = count( $headers_list );
|
||||
|
||||
for( $i=0; $i<$headers_count; ++$i ) {
|
||||
|
||||
list($header_name, $header_value) = explode(':', $headers_list[$i]);
|
||||
|
||||
if(
|
||||
strcasecmp($header_name, 'cache-control') == 0 ||
|
||||
strcasecmp($header_name, 'set-cookie') == 0 ||
|
||||
strcasecmp( substr($header_name, 0, 19), 'X-WP-CF-Super-Cache' ) == 0
|
||||
) {
|
||||
unset($headers_list[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if( count($headers_list) == 0 ) {
|
||||
|
||||
if( file_exists($headers_file) )
|
||||
@unlink($headers_file);
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
file_put_contents( $headers_file, json_encode($headers_list) );
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function swcfpc_fallback_cache_get_stored_headers( $fallback_cache_path, $cache_key ) {
|
||||
|
||||
$headers_file = "{$fallback_cache_path}{$cache_key}.headers.json";
|
||||
|
||||
if( file_exists($headers_file) ) {
|
||||
|
||||
$swcfpc_headers = json_decode( file_get_contents( $headers_file ), true );
|
||||
|
||||
if( is_array($swcfpc_headers) && count($swcfpc_headers) > 0 )
|
||||
return $swcfpc_headers;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function swcfpc_wildcard_match($pattern, $subject) {
|
||||
|
||||
$pattern = '#^'.preg_quote($pattern).'$#i'; // Case insensitive
|
||||
$pattern = str_replace('\*', '.*', $pattern);
|
||||
//$pattern = str_replace('\.', '.', $pattern);
|
||||
|
||||
if(!preg_match($pattern, $subject, $regs))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. 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
|
||||
them 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 prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. 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.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey 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;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If 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 convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU 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 that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
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.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
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.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
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
|
||||
state 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 3 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, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
WP Cloudflare Super Page Cache Copyright (C) 2020 Salvatore Fresta
|
||||
This program 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, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU 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. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
@ -0,0 +1,222 @@
|
|||
<?php
|
||||
/**
|
||||
* Loader for the ThemeIsleSDK
|
||||
*
|
||||
* Logic for loading always the latest SDK from the installed themes/plugins.
|
||||
*
|
||||
* @package ThemeIsleSDK
|
||||
* @copyright Copyright (c) 2017, Marius Cristea
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 1.1.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
return;
|
||||
}
|
||||
// Current SDK version and path.
|
||||
$themeisle_sdk_version = '3.3.14';
|
||||
$themeisle_sdk_path = dirname( __FILE__ );
|
||||
|
||||
global $themeisle_sdk_max_version;
|
||||
global $themeisle_sdk_max_path;
|
||||
|
||||
// If this is the latest SDK and it comes from a theme, we should load licenser separately.
|
||||
$themeisle_sdk_relative_licenser_path = '/src/Modules/Licenser.php';
|
||||
|
||||
global $themeisle_sdk_abs_licenser_path;
|
||||
if ( ! is_file( $themeisle_sdk_path . $themeisle_sdk_relative_licenser_path ) && ! empty( $themeisle_sdk_max_path ) && is_file( $themeisle_sdk_max_path . $themeisle_sdk_relative_licenser_path ) ) {
|
||||
$themeisle_sdk_abs_licenser_path = $themeisle_sdk_max_path . $themeisle_sdk_relative_licenser_path;
|
||||
add_filter( 'themeisle_sdk_required_files', 'themeisle_sdk_load_licenser_if_present' );
|
||||
}
|
||||
|
||||
if ( ( is_null( $themeisle_sdk_max_path ) || version_compare( $themeisle_sdk_version, $themeisle_sdk_max_version ) == 0 ) &&
|
||||
apply_filters( 'themeisle_sdk_should_overwrite_path', false, $themeisle_sdk_path, $themeisle_sdk_max_path ) ) {
|
||||
$themeisle_sdk_max_path = $themeisle_sdk_path;
|
||||
}
|
||||
|
||||
if ( is_null( $themeisle_sdk_max_version ) || version_compare( $themeisle_sdk_version, $themeisle_sdk_max_version ) > 0 ) {
|
||||
$themeisle_sdk_max_version = $themeisle_sdk_version;
|
||||
$themeisle_sdk_max_path = $themeisle_sdk_path;
|
||||
}
|
||||
|
||||
// load the latest sdk version from the active Themeisle products.
|
||||
if ( ! function_exists( 'themeisle_sdk_load_licenser_if_present' ) ) :
|
||||
/**
|
||||
* Always load the licenser, if present.
|
||||
*
|
||||
* @param array $to_load Previously files to load.
|
||||
*/
|
||||
function themeisle_sdk_load_licenser_if_present( $to_load ) {
|
||||
global $themeisle_sdk_abs_licenser_path;
|
||||
$to_load[] = $themeisle_sdk_abs_licenser_path;
|
||||
|
||||
return $to_load;
|
||||
}
|
||||
endif;
|
||||
|
||||
// load the latest sdk version from the active Themeisle products.
|
||||
if ( ! function_exists( 'themeisle_sdk_load_latest' ) ) :
|
||||
/**
|
||||
* Always load the latest sdk version.
|
||||
*/
|
||||
function themeisle_sdk_load_latest() {
|
||||
/**
|
||||
* Don't load the library if we are on < 5.4.
|
||||
*/
|
||||
if ( version_compare( PHP_VERSION, '5.4.32', '<' ) ) {
|
||||
return;
|
||||
}
|
||||
global $themeisle_sdk_max_path;
|
||||
require_once $themeisle_sdk_max_path . '/start.php';
|
||||
}
|
||||
endif;
|
||||
add_action( 'init', 'themeisle_sdk_load_latest' );
|
||||
|
||||
if ( ! function_exists( 'tsdk_utmify' ) ) {
|
||||
/**
|
||||
* Utmify a link.
|
||||
*
|
||||
* @param string $url URL to add utms.
|
||||
* @param string $area Area in page where this is used ( CTA, image, section name).
|
||||
* @param string $location Location, such as customizer, about page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function tsdk_utmify( $url, $area, $location = null ) {
|
||||
static $current_page = null;
|
||||
if ( $location === null && $current_page === null ) {
|
||||
global $pagenow;
|
||||
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : $pagenow;
|
||||
$current_page = isset( $screen->id ) ? $screen->id : ( ( $screen === null ) ? 'non-admin' : $screen );
|
||||
$current_page = sanitize_key( str_replace( '.php', '', $current_page ) );
|
||||
}
|
||||
$location = $location === null ? $current_page : $location;
|
||||
$content = sanitize_key(
|
||||
trim(
|
||||
str_replace(
|
||||
[
|
||||
'https://',
|
||||
'themeisle.com',
|
||||
'/themes/',
|
||||
'/plugins/',
|
||||
'/upgrade',
|
||||
],
|
||||
'',
|
||||
$url
|
||||
),
|
||||
'/'
|
||||
)
|
||||
);
|
||||
$filter_key = sanitize_key( $content );
|
||||
$url_args = [
|
||||
'utm_source' => 'wpadmin',
|
||||
'utm_medium' => $location,
|
||||
'utm_campaign' => $area,
|
||||
'utm_content' => $content,
|
||||
];
|
||||
$query_arguments = apply_filters( 'tsdk_utmify_' . $filter_key, $url_args, $url );
|
||||
$utmify_url = esc_url_raw(
|
||||
add_query_arg(
|
||||
$query_arguments,
|
||||
$url
|
||||
)
|
||||
);
|
||||
return apply_filters( 'tsdk_utmify_url_' . $filter_key, $utmify_url, $url );
|
||||
}
|
||||
|
||||
add_filter( 'tsdk_utmify', 'tsdk_utmify', 10, 3 );
|
||||
}
|
||||
|
||||
|
||||
if ( ! function_exists( 'tsdk_lstatus' ) ) {
|
||||
/**
|
||||
* Check license status.
|
||||
*
|
||||
* @param string $file Product basefile.
|
||||
*
|
||||
* @return string Status.
|
||||
*/
|
||||
function tsdk_lstatus( $file ) {
|
||||
return \ThemeisleSDK\Modules\Licenser::status( $file );
|
||||
}
|
||||
}
|
||||
if ( ! function_exists( 'tsdk_lis_valid' ) ) {
|
||||
/**
|
||||
* Check if license is valid.
|
||||
*
|
||||
* @param string $file Product basefile.
|
||||
*
|
||||
* @return bool Validness.
|
||||
*/
|
||||
function tsdk_lis_valid( $file ) {
|
||||
return \ThemeisleSDK\Modules\Licenser::is_valid( $file );
|
||||
}
|
||||
}
|
||||
if ( ! function_exists( 'tsdk_lplan' ) ) {
|
||||
/**
|
||||
* Get license plan.
|
||||
*
|
||||
* @param string $file Product basefile.
|
||||
*
|
||||
* @return string Plan.
|
||||
*/
|
||||
function tsdk_lplan( $file ) {
|
||||
return \ThemeisleSDK\Modules\Licenser::plan( $file );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'tsdk_lkey' ) ) {
|
||||
/**
|
||||
* Get license key.
|
||||
*
|
||||
* @param string $file Product basefile.
|
||||
*
|
||||
* @return string Key.
|
||||
*/
|
||||
function tsdk_lkey( $file ) {
|
||||
return \ThemeisleSDK\Modules\Licenser::key( $file );
|
||||
}
|
||||
}
|
||||
if ( ! function_exists( 'tsdk_support_link' ) ) {
|
||||
|
||||
/**
|
||||
* Get Themeisle Support URL.
|
||||
*
|
||||
* @param string $file Product basefile.
|
||||
*
|
||||
* @return false|string Return support URL or false if no license is active.
|
||||
*/
|
||||
function tsdk_support_link( $file ) {
|
||||
|
||||
if ( ! did_action( 'init' ) ) {
|
||||
_doing_it_wrong( __FUNCTION__, 'tsdk_support_link() should not be called before the init action.', '3.2.39' );
|
||||
}
|
||||
$params = [];
|
||||
if ( ! tsdk_lis_valid( $file ) ) {
|
||||
return false;
|
||||
}
|
||||
$product = \ThemeisleSDK\Product::get( $file );
|
||||
if ( ! $product->requires_license() ) {
|
||||
return false;
|
||||
}
|
||||
static $site_params = null;
|
||||
if ( $site_params === null ) {
|
||||
if ( is_user_logged_in() && function_exists( 'wp_get_current_user' ) ) {
|
||||
$current_user = wp_get_current_user();
|
||||
$site_params['semail'] = urlencode( $current_user->user_email );
|
||||
}
|
||||
$site_params['swb'] = urlencode( home_url() );
|
||||
global $wp_version;
|
||||
$site_params['snv'] = urlencode( sprintf( 'WP-%s-PHP-%s', $wp_version, ( PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION ) ) );
|
||||
}
|
||||
$params['slkey'] = tsdk_lkey( $file );
|
||||
$params['sprd'] = urlencode( $product->get_name() );
|
||||
$params['svrs'] = urlencode( $product->get_version() );
|
||||
|
||||
|
||||
return add_query_arg(
|
||||
array_merge( $site_params, $params ),
|
||||
'https://store.themeisle.com/direct-support/'
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,151 @@
|
|||
<?php
|
||||
/**
|
||||
* The main loader class for ThemeIsle SDK
|
||||
*
|
||||
* @package ThemeIsleSDK
|
||||
* @subpackage Loader
|
||||
* @copyright Copyright (c) 2017, Marius Cristea
|
||||
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace ThemeisleSDK;
|
||||
|
||||
use ThemeisleSDK\Common\Module_Factory;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Singleton loader for ThemeIsle SDK.
|
||||
*/
|
||||
final class Loader {
|
||||
/**
|
||||
* Singleton instance.
|
||||
*
|
||||
* @var Loader instance The singleton instance
|
||||
*/
|
||||
private static $instance;
|
||||
/**
|
||||
* Current loader version.
|
||||
*
|
||||
* @var string $version The class version.
|
||||
*/
|
||||
private static $version = '2.0.0';
|
||||
/**
|
||||
* Holds registered products.
|
||||
*
|
||||
* @var array The products which use the SDK.
|
||||
*/
|
||||
private static $products = [];
|
||||
/**
|
||||
* Holds available modules to load.
|
||||
*
|
||||
* @var array The modules which SDK will be using.
|
||||
*/
|
||||
private static $available_modules = [
|
||||
'script_loader',
|
||||
'dashboard_widget',
|
||||
'rollback',
|
||||
'uninstall_feedback',
|
||||
'licenser',
|
||||
'logger',
|
||||
'translate',
|
||||
'review',
|
||||
'recommendation',
|
||||
'notification',
|
||||
'promotions',
|
||||
'welcome',
|
||||
'compatibilities',
|
||||
'about_us',
|
||||
'announcements',
|
||||
];
|
||||
|
||||
/**
|
||||
* Initialize the sdk logic.
|
||||
*/
|
||||
public static function init() {
|
||||
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Loader ) ) {
|
||||
self::$instance = new Loader();
|
||||
$modules = array_merge( self::$available_modules, apply_filters( 'themeisle_sdk_modules', [] ) );
|
||||
foreach ( $modules as $key => $module ) {
|
||||
if ( ! class_exists( 'ThemeisleSDK\\Modules\\' . ucwords( $module, '_' ) ) ) {
|
||||
unset( $modules[ $key ] );
|
||||
}
|
||||
}
|
||||
self::$available_modules = $modules;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cache token used in API requests.
|
||||
*
|
||||
* @return string Cache token.
|
||||
*/
|
||||
public static function get_cache_token() {
|
||||
$cache_token = get_transient( 'themeisle_sdk_cache_token' );
|
||||
if ( false === $cache_token ) {
|
||||
$cache_token = wp_generate_password( 6, false );
|
||||
set_transient( $cache_token, WEEK_IN_SECONDS );
|
||||
}
|
||||
|
||||
return $cache_token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear cache token.
|
||||
*/
|
||||
public static function clear_cache_token() {
|
||||
delete_transient( 'themeisle_sdk_cache_token' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register product into SDK.
|
||||
*
|
||||
* @param string $base_file The product base file.
|
||||
*
|
||||
* @return Loader The singleton object.
|
||||
*/
|
||||
public static function add_product( $base_file ) {
|
||||
|
||||
if ( ! is_file( $base_file ) ) {
|
||||
return self::$instance;
|
||||
}
|
||||
$product = new Product( $base_file );
|
||||
|
||||
Module_Factory::attach( $product, self::get_modules() );
|
||||
|
||||
self::$products[ $product->get_slug() ] = $product;
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all registered modules by the SDK.
|
||||
*
|
||||
* @return array Modules available.
|
||||
*/
|
||||
public static function get_modules() {
|
||||
return self::$available_modules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all products using the SDK.
|
||||
*
|
||||
* @return array Products available.
|
||||
*/
|
||||
public static function get_products() {
|
||||
return self::$products;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the version of the SDK.
|
||||
*
|
||||
* @return string The version.
|
||||
*/
|
||||
public static function get_version() {
|
||||
return self::$version;
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 8.7 KiB |
After Width: | Height: | Size: 1.6 KiB |
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
// autoload_classmap.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(__DIR__);
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
|
||||
'WP_Async_Request' => $vendorDir . '/deliciousbrains/wp-background-processing/classes/wp-async-request.php',
|
||||
'WP_Background_Process' => $vendorDir . '/deliciousbrains/wp-background-processing/classes/wp-background-process.php',
|
||||
);
|
|
@ -0,0 +1,379 @@
|
|||
<?php
|
||||
/**
|
||||
* File responsible for announcements.
|
||||
*
|
||||
* This is used to display information about limited events, such as Black Friday.
|
||||
*
|
||||
* @package ThemeIsleSDK
|
||||
* @subpackage Modules
|
||||
* @copyright Copyright (c) 2017, Marius Cristea
|
||||
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
|
||||
* @since 3.3.0
|
||||
*/
|
||||
namespace ThemeisleSDK\Modules;
|
||||
|
||||
use ThemeisleSDK\Common\Abstract_Module;
|
||||
use ThemeisleSDK\Loader;
|
||||
use ThemeisleSDK\Product;
|
||||
|
||||
/**
|
||||
* Announcement module for the ThemeIsle SDK.
|
||||
*/
|
||||
class Announcements extends Abstract_Module {
|
||||
|
||||
/**
|
||||
* Holds the timeline for the announcements.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $timeline = array(
|
||||
'black_friday' => array(
|
||||
'start' => '2024-11-25 00:00:00',
|
||||
'end' => '2024-12-03 23:59:59',
|
||||
'rendered' => false,
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Holds the option prefix for the announcements.
|
||||
*
|
||||
* This is used to store the dismiss date for each announcement.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $option_prefix = 'themeisle_sdk_announcement_';
|
||||
|
||||
/**
|
||||
* Holds the time for the current request.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $time = '';
|
||||
|
||||
/**
|
||||
* Check if the module can be loaded.
|
||||
*
|
||||
* @param Product $product Product data.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function can_load( $product ) {
|
||||
if ( $this->is_from_partner( $product ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the module for the selected product.
|
||||
*
|
||||
* @param Product $product Product data.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function load( $product ) {
|
||||
if ( ! current_user_can( 'install_plugins' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->product = $product;
|
||||
|
||||
add_action( 'admin_init', array( $this, 'load_announcements' ) );
|
||||
add_filter( 'themeisle_sdk_active_announcements', array( $this, 'get_active_announcements' ) );
|
||||
add_filter( 'themeisle_sdk_announcements', array( $this, 'get_announcements_for_plugins' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all valid announcements.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function load_announcements() {
|
||||
$active = $this->get_active_announcements();
|
||||
|
||||
if ( empty( $active ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $active as $announcement ) {
|
||||
|
||||
$method = $announcement . '_notice_render';
|
||||
|
||||
if ( method_exists( $this, $method ) ) {
|
||||
add_action( 'admin_notices', array( $this, $method ) );
|
||||
}
|
||||
}
|
||||
|
||||
// Load the ajax handler.
|
||||
add_action( 'wp_ajax_themeisle_sdk_dismiss_announcement', array( $this, 'disable_notification_ajax' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all active announcements.
|
||||
*
|
||||
* @return array List of active announcements.
|
||||
*/
|
||||
public function get_active_announcements() {
|
||||
$active = array();
|
||||
|
||||
foreach ( self::$timeline as $announcement_slug => $dates ) {
|
||||
if ( $this->is_active( $dates ) && $this->can_show( $announcement_slug, $dates ) ) {
|
||||
$active[] = $announcement_slug;
|
||||
}
|
||||
}
|
||||
|
||||
return $active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all announcements along with plugin specific data.
|
||||
*
|
||||
* @return array List of announcements.
|
||||
*/
|
||||
public function get_announcements_for_plugins() {
|
||||
|
||||
$announcements = array();
|
||||
|
||||
foreach ( self::$timeline as $announcement => $dates ) {
|
||||
$announcements[ $announcement ] = $dates;
|
||||
|
||||
if ( false !== strpos( $announcement, 'black_friday' ) ) {
|
||||
$announcements[ $announcement ]['active'] = $this->is_active( $dates );
|
||||
|
||||
// Dashboard banners URLs.
|
||||
$announcements[ $announcement ]['feedzy_dashboard_url'] = tsdk_utmify( 'https://themeisle.com/plugins/feedzy-rss-feeds/blackfriday/', 'bfcm24', 'dashboard' );
|
||||
$announcements[ $announcement ]['neve_dashboard_url'] = tsdk_utmify( 'https://themeisle.com/themes/neve/blackfriday/', 'bfcm24', 'dashboard' );
|
||||
$announcements[ $announcement ]['otter_dashboard_url'] = tsdk_utmify( 'https://themeisle.com/plugins/otter-blocks/blackfriday/', 'bfcm24', 'dashboard' );
|
||||
|
||||
// Customizer banners URLs.
|
||||
$announcements[ $announcement ]['hestia_customizer_url'] = tsdk_utmify( 'https://themeisle.com/black-friday/', 'bfcm24', 'hestiacustomizer' );
|
||||
$announcements[ $announcement ]['neve_customizer_url'] = tsdk_utmify( 'https://themeisle.com/black-friday/', 'bfcm24', 'nevecustomizer' );
|
||||
|
||||
// Banners urgency text.
|
||||
$remaining_time = $this->get_remaining_time_for_event( $dates['end'] );
|
||||
$announcements[ $announcement ]['remaining_time'] = $remaining_time;
|
||||
$announcements[ $announcement ]['urgency_text'] = ! empty( $remaining_time ) ? 'Hurry up! Only ' . $remaining_time . ' left.' : '';
|
||||
}
|
||||
}
|
||||
|
||||
return apply_filters( 'themeisle_sdk_announcements_data', $announcements );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the announcement data.
|
||||
*
|
||||
* @param string $announcement The announcement to get the data for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_announcement_data( $announcement ) {
|
||||
return ! empty( $announcement ) && is_string( $announcement ) && isset( self::$timeline[ $announcement ] ) ? self::$timeline[ $announcement ] : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the announcement has an active timeline.
|
||||
*
|
||||
* @param array $dates The announcement to check.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_active( $dates ) {
|
||||
|
||||
if ( empty( $this->time ) ) {
|
||||
$this->time = current_time( 'Y-m-d' );
|
||||
}
|
||||
|
||||
$start = isset( $dates['start'] ) ? $dates['start'] : null;
|
||||
$end = isset( $dates['end'] ) ? $dates['end'] : null;
|
||||
|
||||
if ( $start && $end ) {
|
||||
return $start <= $this->time && $this->time <= $end;
|
||||
} elseif ( $start ) {
|
||||
return $this->time >= $start;
|
||||
} elseif ( $end ) {
|
||||
return $this->time <= $end;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the remaining time for the event in a human readable format.
|
||||
*
|
||||
* @param string $end_date The end date for event.
|
||||
* @return string Remaining time for the event.
|
||||
*/
|
||||
public function get_remaining_time_for_event( $end_date ) {
|
||||
if ( empty( $end_date ) || ! is_string( $end_date ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
try {
|
||||
$end_date = new \DateTime( $end_date, new \DateTimeZone( 'GMT' ) );
|
||||
$current_date = new \DateTime( 'now', new \DateTimeZone( 'GMT' ) );
|
||||
$diff = $end_date->diff( $current_date );
|
||||
|
||||
if ( $diff->days > 0 ) {
|
||||
return $diff->days === 1 ? $diff->format( '%a day' ) : $diff->format( '%a days' );
|
||||
}
|
||||
|
||||
if ( $diff->h > 0 ) {
|
||||
return $diff->h === 1 ? $diff->format( '%h hour' ) : $diff->format( '%h hours' );
|
||||
}
|
||||
|
||||
if ( $diff->i > 0 ) {
|
||||
return $diff->i === 1 ? $diff->format( '%i minute' ) : $diff->format( '%i minutes' );
|
||||
}
|
||||
|
||||
return $diff->s === 1 ? $diff->format( '%s second' ) : $diff->format( '%s seconds' );
|
||||
} catch ( \Exception $e ) {
|
||||
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
|
||||
error_log( $e->getMessage() ); // phpcs:ignore
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the announcement can be shown.
|
||||
*
|
||||
* @param string $announcement_slug The announcement to check.
|
||||
* @param array $dates The announcement to check.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function can_show( $announcement_slug, $dates ) {
|
||||
$dismiss_date = get_option( $this->option_prefix . $announcement_slug, false );
|
||||
|
||||
if ( false === $dismiss_date ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If the start date is after the dismiss date, show the notice.
|
||||
$start = isset( $dates['start'] ) ? $dates['start'] : null;
|
||||
if ( $start && $dismiss_date < $start ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the notification via ajax.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disable_notification_ajax() {
|
||||
if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'dismiss_themeisle_event_notice' ) ) {
|
||||
wp_die( 'Invalid nonce! Refresh the page and try again.' );
|
||||
}
|
||||
|
||||
if ( ! isset( $_POST['announcement'] ) || ! is_string( $_POST['announcement'] ) ) {
|
||||
wp_die( 'Invalid announcement! Refresh the page and try again.' );
|
||||
}
|
||||
|
||||
$announcement = sanitize_key( $_POST['announcement'] );
|
||||
|
||||
update_option( $this->option_prefix . $announcement, current_time( 'Y-m-d' ) );
|
||||
wp_die( 'success' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the Black Friday notice.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function black_friday_notice_render() {
|
||||
|
||||
// Prevent the notice from being rendered twice.
|
||||
if ( self::$timeline['black_friday']['rendered'] ) {
|
||||
return;
|
||||
}
|
||||
self::$timeline['black_friday']['rendered'] = true;
|
||||
|
||||
$product_names = array();
|
||||
|
||||
foreach ( Loader::get_products() as $product ) {
|
||||
$slug = $product->get_slug();
|
||||
|
||||
// Do not add if the contains the string 'pro'.
|
||||
if ( strpos( $slug, 'pro' ) !== false ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$product_names[] = $product->get_name();
|
||||
}
|
||||
|
||||
// Randomize the products and get only 4.
|
||||
shuffle( $product_names );
|
||||
$product_names = array_slice( $product_names, 0, 4 );
|
||||
|
||||
?>
|
||||
<style>
|
||||
.themeisle-sale {
|
||||
display: flex;
|
||||
}
|
||||
</style>
|
||||
<div class="themeisle-sale notice notice-info is-dismissible" data-announcement="black_friday">
|
||||
<img src="<?php echo esc_url_raw( $this->get_sdk_uri() . 'assets/images/themeisle-logo.svg' ); ?>" />
|
||||
<p>
|
||||
<strong>Themeisle Black Friday Sale is Live!</strong> - Enjoy Maximum Savings on <?php echo esc_html( implode( ', ', $product_names ) ); ?>.
|
||||
<a href="<?php echo esc_url_raw( tsdk_utmify( 'https://themeisle.com/blackfriday/', 'bfcm24', 'globalnotice' ) ); ?>" target="_blank">Learn more</a>
|
||||
<span class="themeisle-sale-error"></span>
|
||||
</p>
|
||||
</div>
|
||||
<script type="text/javascript" data-origin="themeisle-sdk">
|
||||
window.document.addEventListener('DOMContentLoaded', () => {
|
||||
const observer = new MutationObserver((mutationsList, observer) => {
|
||||
for(let mutation of mutationsList) {
|
||||
if (mutation.type === 'childList') {
|
||||
const container = document.querySelector('.themeisle-sale.notice');
|
||||
const button = container?.querySelector('button');
|
||||
if ( button ) {
|
||||
button.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
fetch('<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
action: 'themeisle_sdk_dismiss_announcement',
|
||||
nonce: '<?php echo esc_attr( wp_create_nonce( 'dismiss_themeisle_event_notice' ) ); ?>',
|
||||
announcement: container.dataset.announcement
|
||||
})
|
||||
})
|
||||
.then(response => response.text())
|
||||
.then(response => {
|
||||
if (!response?.includes('success')) {
|
||||
document.querySelector('.themeisle-sale-error').innerHTML = response;
|
||||
return;
|
||||
}
|
||||
|
||||
document.querySelectorAll('.themeisle-sale.notice').forEach(el => {
|
||||
el.classList.add('hidden');
|
||||
setTimeout(() => {
|
||||
el.remove();
|
||||
}, 800);
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
document.querySelector('.themeisle-sale-error').innerHTML = error;
|
||||
});
|
||||
});
|
||||
observer.disconnect();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}
|
|
@ -0,0 +1,145 @@
|
|||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
|
||||
|
||||
class SWCFPC_Logs
|
||||
{
|
||||
|
||||
private $main_instance = null;
|
||||
|
||||
private $is_logging_enabled = false;
|
||||
private $log_file_path = false;
|
||||
private $log_file_url = false;
|
||||
|
||||
private $verbosity = 1; // 1: standard, 2: high
|
||||
|
||||
function __construct($log_file_path, $log_file_url, $logging_enabled, $max_file_size, $main_instance)
|
||||
{
|
||||
|
||||
$this->log_file_path = $log_file_path;
|
||||
$this->log_file_url = $log_file_url;
|
||||
$this->is_logging_enabled = $logging_enabled;
|
||||
$this->main_instance = $main_instance;
|
||||
|
||||
// Reset log if it exceeded the max file size
|
||||
if( $max_file_size > 0 && file_exists($log_file_path) && ( filesize($log_file_path) / 1024 / 1024 ) >= $max_file_size )
|
||||
$this->reset_log();
|
||||
|
||||
$this->actions();
|
||||
|
||||
}
|
||||
|
||||
|
||||
function actions() {
|
||||
|
||||
// Ajax clear logs
|
||||
add_action( 'wp_ajax_swcfpc_clear_logs', array($this, 'ajax_clear_logs') );
|
||||
|
||||
// Download logs
|
||||
add_action( 'init', array($this, 'download_logs') );
|
||||
|
||||
}
|
||||
|
||||
|
||||
function enable_logging() {
|
||||
$this->is_logging_enabled = true;
|
||||
}
|
||||
|
||||
|
||||
function disable_logging() {
|
||||
$this->is_logging_enabled = false;
|
||||
}
|
||||
|
||||
|
||||
function set_verbosity($verbosity) {
|
||||
|
||||
$verbosity = (int) $verbosity;
|
||||
|
||||
if( $verbosity != SWCFPC_LOGS_STANDARD_VERBOSITY && $verbosity != SWCFPC_LOGS_HIGH_VERBOSITY )
|
||||
$verbosity = SWCFPC_LOGS_STANDARD_VERBOSITY;
|
||||
|
||||
$this->verbosity = $verbosity;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function get_verbosity() {
|
||||
return $this->verbosity;
|
||||
}
|
||||
|
||||
|
||||
function add_log($identifier, $message) {
|
||||
|
||||
if( $this->is_logging_enabled && $this->log_file_path ) {
|
||||
|
||||
$log = sprintf('[%s] [%s] %s', current_time('Y-m-d H:i:s'), $identifier, $message) . PHP_EOL;
|
||||
|
||||
error_log($log, 3, $this->log_file_path);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function get_logs() {
|
||||
|
||||
$log = '';
|
||||
|
||||
if( $this->log_file_path )
|
||||
$log = file_get_contents( $this->log_file_path );
|
||||
|
||||
return $log;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function reset_log() {
|
||||
|
||||
if( $this->log_file_path )
|
||||
file_put_contents( $this->log_file_path, '' );
|
||||
|
||||
}
|
||||
|
||||
|
||||
function download_logs() {
|
||||
|
||||
if( isset($_GET['swcfpc_download_log']) && file_exists($this->log_file_path) && current_user_can('manage_options') ) {
|
||||
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename=debug.log');
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Connection: Keep-Alive');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0, s-maxage=0');
|
||||
header('Pragma: public');
|
||||
header('Content-Length: ' . filesize($this->log_file_path));
|
||||
readfile($this->log_file_path);
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function ajax_clear_logs() {
|
||||
|
||||
check_ajax_referer( 'ajax-nonce-string', 'security' );
|
||||
|
||||
$return_array = array('status' => 'ok');
|
||||
|
||||
if( !current_user_can('manage_options') ) {
|
||||
$return_array['status'] = 'error';
|
||||
$return_array['error'] = __('Permission denied', 'wp-cloudflare-page-cache');
|
||||
die(json_encode($return_array));
|
||||
}
|
||||
|
||||
$this->reset_log();
|
||||
|
||||
$return_array['success_msg'] = __('Log cleaned successfully', 'wp-cloudflare-page-cache');
|
||||
|
||||
die(json_encode($return_array));
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,279 @@
|
|||
<?php
|
||||
/**
|
||||
* The logger model class for ThemeIsle SDK
|
||||
*
|
||||
* @package ThemeIsleSDK
|
||||
* @subpackage Modules
|
||||
* @copyright Copyright (c) 2017, Marius Cristea
|
||||
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace ThemeisleSDK\Modules;
|
||||
|
||||
use ThemeisleSDK\Common\Abstract_Module;
|
||||
use ThemeisleSDK\Loader;
|
||||
use ThemeisleSDK\Product;
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logger module for ThemeIsle SDK.
|
||||
*/
|
||||
class Logger extends Abstract_Module {
|
||||
/**
|
||||
* Endpoint where to collect logs.
|
||||
*/
|
||||
const TRACKING_ENDPOINT = 'https://api.themeisle.com/tracking/log';
|
||||
|
||||
/**
|
||||
* Endpoint where to collect telemetry.
|
||||
*/
|
||||
const TELEMETRY_ENDPOINT = 'https://api.themeisle.com/tracking/events';
|
||||
|
||||
|
||||
/**
|
||||
* Check if we should load the module for this product.
|
||||
*
|
||||
* @param Product $product Product to load the module for.
|
||||
*
|
||||
* @return bool Should we load ?
|
||||
*/
|
||||
public function can_load( $product ) {
|
||||
return apply_filters( $product->get_slug() . '_sdk_enable_logger', true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load module logic.
|
||||
*
|
||||
* @param Product $product Product to load.
|
||||
*
|
||||
* @return Logger Module object.
|
||||
*/
|
||||
public function load( $product ) {
|
||||
$this->product = $product;
|
||||
$this->setup_notification();
|
||||
$this->setup_actions();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup notification on admin.
|
||||
*/
|
||||
public function setup_notification() {
|
||||
if ( ! $this->product->is_wordpress_available() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_filter( 'themeisle_sdk_registered_notifications', [ $this, 'add_notification' ] );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup tracking actions.
|
||||
*/
|
||||
public function setup_actions() {
|
||||
if ( ! $this->is_logger_active() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$can_load_telemetry = apply_filters( 'themeisle_sdk_enable_telemetry', false );
|
||||
|
||||
if ( $can_load_telemetry ) {
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'load_telemetry' ) );
|
||||
}
|
||||
|
||||
$action_key = $this->product->get_key() . '_log_activity';
|
||||
if ( ! wp_next_scheduled( $action_key ) ) {
|
||||
wp_schedule_single_event( time() + ( wp_rand( 1, 24 ) * 3600 ), $action_key );
|
||||
}
|
||||
add_action( $action_key, array( $this, 'send_log' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the logger is active.
|
||||
*
|
||||
* @return bool Is logger active?
|
||||
*/
|
||||
private function is_logger_active() {
|
||||
$default = 'no';
|
||||
|
||||
if ( ! $this->product->is_wordpress_available() ) {
|
||||
$default = 'yes';
|
||||
} else {
|
||||
$pro_slug = $this->product->get_pro_slug();
|
||||
|
||||
if ( ! empty( $pro_slug ) ) {
|
||||
$all_products = Loader::get_products();
|
||||
if ( isset( $all_products[ $pro_slug ] ) ) {
|
||||
$default = 'yes';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ( get_option( $this->product->get_key() . '_logger_flag', $default ) === 'yes' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add notification to queue.
|
||||
*
|
||||
* @param array $all_notifications Previous notification.
|
||||
*
|
||||
* @return array All notifications.
|
||||
*/
|
||||
public function add_notification( $all_notifications ) {
|
||||
|
||||
$message = apply_filters( $this->product->get_key() . '_logger_heading', 'Do you enjoy <b>{product}</b>? Become a contributor by opting in to our anonymous data tracking. We guarantee no sensitive data is collected.' );
|
||||
|
||||
$message = str_replace(
|
||||
array( '{product}' ),
|
||||
$this->product->get_friendly_name(),
|
||||
$message
|
||||
);
|
||||
$button_submit = apply_filters( $this->product->get_key() . '_logger_button_submit', 'Sure, I would love to help.' );
|
||||
$button_cancel = apply_filters( $this->product->get_key() . '_logger_button_cancel', 'No, thanks.' );
|
||||
|
||||
$all_notifications[] = [
|
||||
'id' => $this->product->get_key() . '_logger_flag',
|
||||
'message' => $message,
|
||||
'ctas' => [
|
||||
'confirm' => [
|
||||
'link' => '#',
|
||||
'text' => $button_submit,
|
||||
],
|
||||
'cancel' => [
|
||||
'link' => '#',
|
||||
'text' => $button_cancel,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return $all_notifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the statistics to the api endpoint.
|
||||
*/
|
||||
public function send_log() {
|
||||
$environment = array();
|
||||
$theme = wp_get_theme();
|
||||
$environment['theme'] = array();
|
||||
$environment['theme']['name'] = $theme->get( 'Name' );
|
||||
$environment['theme']['author'] = $theme->get( 'Author' );
|
||||
$environment['theme']['parent'] = $theme->parent() !== false ? $theme->parent()->get( 'Name' ) : $theme->get( 'Name' );
|
||||
$environment['plugins'] = get_option( 'active_plugins' );
|
||||
global $wp_version;
|
||||
wp_remote_post(
|
||||
self::TRACKING_ENDPOINT,
|
||||
array(
|
||||
'method' => 'POST',
|
||||
'timeout' => 3,
|
||||
'redirection' => 5,
|
||||
'body' => array(
|
||||
'site' => get_site_url(),
|
||||
'slug' => $this->product->get_slug(),
|
||||
'version' => $this->product->get_version(),
|
||||
'wp_version' => $wp_version,
|
||||
'locale' => get_locale(),
|
||||
'data' => apply_filters( $this->product->get_key() . '_logger_data', array() ),
|
||||
'environment' => $environment,
|
||||
'license' => apply_filters( $this->product->get_key() . '_license_status', '' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load telemetry.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function load_telemetry() {
|
||||
// See which products have telemetry enabled.
|
||||
try {
|
||||
$products_with_telemetry = array();
|
||||
$all_products = Loader::get_products();
|
||||
$all_products[ $this->product->get_slug() ] = $this->product; // Add current product to the list of products to check for telemetry.
|
||||
|
||||
foreach ( $all_products as $product_slug => $product ) {
|
||||
|
||||
// Ignore pro products.
|
||||
if ( false !== strstr( $product_slug, 'pro' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$default = 'no';
|
||||
|
||||
if ( ! $product->is_wordpress_available() ) {
|
||||
$default = 'yes';
|
||||
} else {
|
||||
$pro_slug = $product->get_pro_slug();
|
||||
|
||||
if ( ! empty( $pro_slug ) && isset( $all_products[ $pro_slug ] ) ) {
|
||||
$default = 'yes';
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'yes' === get_option( $product->get_key() . '_logger_flag', $default ) ) {
|
||||
|
||||
$main_slug = explode( '-', $product_slug );
|
||||
$main_slug = $main_slug[0];
|
||||
$pro_slug = $product->get_pro_slug();
|
||||
$track_hash = Licenser::create_license_hash( str_replace( '-', '_', ! empty( $pro_slug ) ? $pro_slug : $product_slug ) );
|
||||
|
||||
// Check if product was already tracked.
|
||||
$active_telemetry = false;
|
||||
foreach ( $products_with_telemetry as &$product_with_telemetry ) {
|
||||
if ( $product_with_telemetry['slug'] === $main_slug ) {
|
||||
$active_telemetry = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $active_telemetry ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$products_with_telemetry[] = array(
|
||||
'slug' => $main_slug,
|
||||
'trackHash' => $track_hash ? $track_hash : 'free',
|
||||
'consent' => true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$products_with_telemetry = apply_filters( 'themeisle_sdk_telemetry_products', $products_with_telemetry );
|
||||
|
||||
if ( 0 === count( $products_with_telemetry ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$tracking_handler = apply_filters( 'themeisle_sdk_dependency_script_handler', 'tracking' );
|
||||
if ( ! empty( $tracking_handler ) ) {
|
||||
do_action( 'themeisle_sdk_dependency_enqueue_script', 'tracking' );
|
||||
wp_localize_script(
|
||||
$tracking_handler,
|
||||
'tiTelemetry',
|
||||
array(
|
||||
'products' => $products_with_telemetry,
|
||||
'endpoint' => self::TELEMETRY_ENDPOINT,
|
||||
)
|
||||
);
|
||||
}
|
||||
} catch ( \Exception $e ) {
|
||||
if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
|
||||
error_log( $e->getMessage() ); // phpcs:ignore
|
||||
}
|
||||
} catch ( \Error $e ) {
|
||||
if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
|
||||
error_log( $e->getMessage() ); // phpcs:ignore
|
||||
}
|
||||
} finally {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?php return array(
|
||||
'root' => array(
|
||||
'name' => 'codeinwp/wp-cloudflare-super-page-cache',
|
||||
'pretty_version' => 'v4.7.7',
|
||||
'version' => '4.7.7.0',
|
||||
'reference' => '6bd071a3922831eedcdceb0056a286228c8ffbdf',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'dev' => false,
|
||||
),
|
||||
'versions' => array(
|
||||
'codeinwp/themeisle-sdk' => array(
|
||||
'pretty_version' => '3.3.14',
|
||||
'version' => '3.3.14.0',
|
||||
'reference' => '662952078c57b12e4d3af9bc98ef847ea3500206',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../codeinwp/themeisle-sdk',
|
||||
'aliases' => array(),
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'codeinwp/wp-cloudflare-super-page-cache' => array(
|
||||
'pretty_version' => 'v4.7.7',
|
||||
'version' => '4.7.7.0',
|
||||
'reference' => '6bd071a3922831eedcdceb0056a286228c8ffbdf',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'deliciousbrains/wp-background-processing' => array(
|
||||
'pretty_version' => '1.0.2',
|
||||
'version' => '1.0.2.0',
|
||||
'reference' => '2cbee1abd1b49e1133cd8f611df4d4fc5a8b9800',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../deliciousbrains/wp-background-processing',
|
||||
'aliases' => array(),
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
),
|
||||
);
|
|
@ -0,0 +1,30 @@
|
|||
<div class="wrap">
|
||||
|
||||
<div id="swcfpc_main_content">
|
||||
|
||||
<h1><?php _e('Super Page Cache for Cloudflare - Cached HTML pages', 'wp-cloudflare-page-cache'); ?></h1>
|
||||
|
||||
|
||||
<?php if( count($cached_html_pages_list) > 0 ): ?>
|
||||
|
||||
<p><strong><?php printf( __('There are %d cached pages in list:', 'wp-cloudflare-page-cache'), count($cached_html_pages_list) ); ?></strong></p>
|
||||
|
||||
<ul>
|
||||
|
||||
<?php foreach($cached_html_pages_list as $url): ?>
|
||||
|
||||
<li><?php echo $url; ?></li>
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
||||
</ul>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<p><?php echo __( 'There are no cached HTML pages right now.', 'wp-cloudflare-page-cache' ); ?></p>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
|
@ -0,0 +1 @@
|
|||
<?php return array('dependencies' => array('wp-components', 'wp-element'), 'version' => '35f2cdc94ec1bd5b9745');
|
After Width: | Height: | Size: 1.9 KiB |
|
@ -0,0 +1,142 @@
|
|||
<?php
|
||||
/**
|
||||
* The dependency model class for ThemeIsle SDK
|
||||
*
|
||||
* @package ThemeIsleSDK
|
||||
* @subpackage Modules
|
||||
* @copyright Copyright (c) 2017, Marius Cristea
|
||||
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
|
||||
* @since 3.3
|
||||
*/
|
||||
|
||||
namespace ThemeisleSDK\Modules;
|
||||
|
||||
use ThemeisleSDK\Common\Abstract_Module;
|
||||
use ThemeisleSDK\Product;
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Script loader module for ThemeIsle SDK.
|
||||
*/
|
||||
class Script_Loader extends Abstract_Module {
|
||||
/**
|
||||
* Check if we should load the module for this product.
|
||||
*
|
||||
* @param Product $product Product to load the module for.
|
||||
*
|
||||
* @return bool Should we load ?
|
||||
*/
|
||||
public function can_load( $product ) {
|
||||
if ( apply_filters( 'themeisle_sdk_ran_promos', false ) === true ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $this->is_from_partner( $product ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load module logic.
|
||||
*
|
||||
* @param Product $product Product to load.
|
||||
*
|
||||
* @return Dependancy Module object.
|
||||
*/
|
||||
public function load( $product ) {
|
||||
$this->product = $product;
|
||||
$this->setup_actions();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup actions.
|
||||
*/
|
||||
private function setup_actions() {
|
||||
add_filter( 'themeisle_sdk_dependency_script_handler', [ $this, 'get_script_handler' ], 10, 1 );
|
||||
add_action( 'themeisle_sdk_dependency_enqueue_script', [ $this, 'enqueue_script' ], 10, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script handler.
|
||||
*
|
||||
* @param string $slug The slug of the script.
|
||||
*
|
||||
* @return string The script handler. Empty if slug is not a string or not implemented.
|
||||
*/
|
||||
public function get_script_handler( $slug ) {
|
||||
if ( ! is_string( $slug ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( 'tracking' !== $slug && 'survey' !== $slug ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return apply_filters( 'themeisle_sdk_dependency_script_handler_name', 'themeisle_sdk_' . $slug . '_script', $slug );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue the script.
|
||||
*
|
||||
* @param string $slug The slug of the script.
|
||||
*/
|
||||
public function enqueue_script( $slug ) {
|
||||
$handler = apply_filters( 'themeisle_sdk_dependency_script_handler', $slug );
|
||||
if ( empty( $handler ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'tracking' === $slug ) {
|
||||
$this->load_tracking( $handler );
|
||||
} elseif ( 'survey' === $slug ) {
|
||||
$this->load_survey( $handler );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the survey script.
|
||||
*
|
||||
* @param string $handler The script handler.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function load_survey( $handler ) {
|
||||
global $themeisle_sdk_max_path;
|
||||
$asset_file = require $themeisle_sdk_max_path . '/assets/js/build/survey/survey_deps.asset.php';
|
||||
|
||||
wp_enqueue_script(
|
||||
$handler,
|
||||
$this->get_sdk_uri() . 'assets/js/build/survey/survey_deps.js',
|
||||
$asset_file['dependencies'],
|
||||
$asset_file['version'],
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the tracking script.
|
||||
*
|
||||
* @param string $handler The script handler.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function load_tracking( $handler ) {
|
||||
global $themeisle_sdk_max_path;
|
||||
$asset_file = require $themeisle_sdk_max_path . '/assets/js/build/tracking/tracking.asset.php';
|
||||
|
||||
wp_enqueue_script(
|
||||
$handler,
|
||||
$this->get_sdk_uri() . 'assets/js/build/tracking/tracking.js',
|
||||
$asset_file['dependencies'],
|
||||
$asset_file['version'],
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
<?php return array('dependencies' => array('wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-hooks', 'wp-plugins'), 'version' => 'bae1a40c3811e093a7be');
|
|
@ -0,0 +1,338 @@
|
|||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
|
||||
|
||||
class SWCFPC_Html_Cache
|
||||
{
|
||||
|
||||
private $main_instance = null;
|
||||
private $objects = false;
|
||||
private $current_page_can_be_cached = false;
|
||||
|
||||
function __construct( $main_instance )
|
||||
{
|
||||
|
||||
$this->main_instance = $main_instance;
|
||||
|
||||
$this->actions();
|
||||
|
||||
}
|
||||
|
||||
|
||||
function actions() {
|
||||
|
||||
if( $this->main_instance->get_single_config('cf_purge_only_html', 0) > 0 && !is_admin() && !$this->main_instance->is_login_page() )
|
||||
add_action('shutdown', array($this, 'add_current_url_to_cache'), PHP_INT_MAX);
|
||||
|
||||
add_action( 'admin_menu', array($this, 'add_admin_menu_pages') );
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function add_admin_menu_pages() {
|
||||
|
||||
add_submenu_page(
|
||||
'',
|
||||
__( 'Super Page Cache for Cloudflare cached HTML pages', 'wp-cloudflare-page-cache' ),
|
||||
__( 'Super Page Cache for Cloudflare cached HTML pages', 'wp-cloudflare-page-cache' ),
|
||||
'manage_options',
|
||||
'wp-cloudflare-super-page-cache-cached-html-pages',
|
||||
array($this, 'admin_menu_page_cached_html_pages')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function cache_current_page() {
|
||||
$this->current_page_can_be_cached = true;
|
||||
}
|
||||
|
||||
|
||||
function do_not_cache_current_page() {
|
||||
$this->current_page_can_be_cached = false;
|
||||
}
|
||||
|
||||
|
||||
private function add_url_to_cache($url) {
|
||||
|
||||
$cache_path = $this->init_directory();
|
||||
$cache_key = $this->get_cache_key($url);
|
||||
|
||||
$filename = $cache_path.$cache_key;
|
||||
$file_content = "{$url}|".time();
|
||||
|
||||
file_put_contents($cache_path.$cache_key, $file_content);
|
||||
|
||||
return $filename;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function add_current_url_to_cache() {
|
||||
|
||||
global $wp_query;
|
||||
|
||||
$this->objects = $this->main_instance->get_objects();
|
||||
|
||||
// First check for WP CLI as $_SERVER is not available for WP_CLI
|
||||
if( defined( 'WP_CLI' ) && WP_CLI === true ) {
|
||||
|
||||
if( is_object($this->objects['logs']) && $this->objects['logs']->get_verbosity() == SWCFPC_LOGS_HIGH_VERBOSITY )
|
||||
$this->objects['logs']->add_log('html_cache::add_current_url_to_cache', 'The URL cannot be cached due to WP CLI.' );
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
$parts = parse_url( home_url() );
|
||||
$current_url = "{$parts['scheme']}://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
|
||||
|
||||
if( isset($wp_query) && function_exists('is_404') && is_404() ) {
|
||||
|
||||
if( $this->objects['logs']->get_verbosity() == SWCFPC_LOGS_HIGH_VERBOSITY )
|
||||
$this->objects['logs']->add_log('html_cache::add_current_url_to_cache', "The URL {$current_url} cannot be cached because it returns 404." );
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if( $this->current_page_can_be_cached == false ) {
|
||||
|
||||
if( is_object($this->objects['logs']) && $this->objects['logs']->get_verbosity() == SWCFPC_LOGS_HIGH_VERBOSITY )
|
||||
$this->objects['logs']->add_log('html_cache::add_current_url_to_cache', "The URL {$current_url} cannot be cached due to caching rules." );
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if( strcasecmp($_SERVER['HTTP_HOST'], $parts['host']) != 0 ) {
|
||||
|
||||
if( $this->objects['logs']->get_verbosity() == SWCFPC_LOGS_HIGH_VERBOSITY )
|
||||
$this->objects['logs']->add_log('html_cache::add_current_url_to_cache', "The URL {$current_url} cannot be cached because the host does not match with the one of home_url() function ({$parts['host']})." );
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Now check if the $current_url has any unwanted query parameters like (v=, ref=, aff=, utm_*=)
|
||||
* If the URL has such things, then don't add them to the html_cache as html_cache should only hold
|
||||
* proper URLs like /example-car/ and not /example-car/?v=123&aff=123&ref=h65
|
||||
*/
|
||||
$current_url_parsed = parse_url( $current_url );
|
||||
$current_url_query_params = [];
|
||||
|
||||
if( array_key_exists( 'query', $current_url_parsed ) ) {
|
||||
|
||||
if( $current_url_parsed[ 'query' ] === '' ) {
|
||||
|
||||
if( $this->objects['logs']->get_verbosity() == SWCFPC_LOGS_HIGH_VERBOSITY ) {
|
||||
$this->objects['logs']->add_log('html_cache::add_current_url_to_cache', "This URL {$current_url} cannot be cached because the URL has no query param but has the question mark at the end of the URL without actually having any query params. It makes no sense to cache this page as the proper version of the URL will be considered for caching." );
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
} else {
|
||||
|
||||
// First parse the query params to an array to manage it better
|
||||
parse_str( $current_url_parsed[ 'query' ], $current_url_query_params );
|
||||
|
||||
// Get the array of query params that would be ignored
|
||||
$ignored_query_params = $this->main_instance->get_ignored_query_params();
|
||||
|
||||
// Loop though $ignored_query_params
|
||||
foreach( $ignored_query_params as $ignored_query_param ) {
|
||||
|
||||
// Check if that query param is present in $current_url_query_params
|
||||
if( array_key_exists( $ignored_query_param, $current_url_query_params ) ) {
|
||||
|
||||
// The ignored query param is present in the $current_url_query_params. So, unset it from there
|
||||
unset( $current_url_query_params[ $ignored_query_param ] );
|
||||
}
|
||||
}
|
||||
|
||||
// Now lets check if we have any query params left in $current_url_query_params
|
||||
if( count( $current_url_query_params ) > 0 ) {
|
||||
|
||||
$new_current_url_query_params = http_build_query( $current_url_query_params );
|
||||
$current_url_parsed[ 'query' ] = $new_current_url_query_params;
|
||||
|
||||
} else {
|
||||
// Remove the query section from parsed URL
|
||||
unset( $current_url_parsed[ 'query' ] );
|
||||
}
|
||||
|
||||
// Get the new current URL without the marketing query params
|
||||
$current_url = $this->main_instance->get_unparsed_url( $current_url_parsed );
|
||||
}
|
||||
}
|
||||
|
||||
// Time to add the URL to HTML cache
|
||||
$filename = $this->add_url_to_cache( $current_url );
|
||||
|
||||
if( $this->objects['logs']->get_verbosity() == SWCFPC_LOGS_HIGH_VERBOSITY ) {
|
||||
$this->objects['logs']->add_log('html_cache::add_current_url_to_cache', "Created the file {$filename} for the URL {$current_url}" );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function get_cache_key( $url ) {
|
||||
|
||||
$cache_key = sha1( $url );
|
||||
$cache_key .= '.tmp';
|
||||
|
||||
return $cache_key;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function init_directory() {
|
||||
|
||||
$cache_path = $this->main_instance->get_plugin_wp_content_directory().'/cached_html_pages/';
|
||||
|
||||
if( ! file_exists($cache_path) )
|
||||
wp_mkdir_p($cache_path);
|
||||
|
||||
if( file_exists($cache_path) && !file_exists("{$cache_path}index.php") )
|
||||
file_put_contents( "{$cache_path}index.php", '<?php // Silence is golden');
|
||||
|
||||
return $cache_path;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function delete_all_cached_urls() {
|
||||
|
||||
$cache_path = $this->init_directory();
|
||||
|
||||
//Get a list of all of the file names in the folder.
|
||||
$files = glob($cache_path . '/*.tmp');
|
||||
|
||||
foreach($files as $single_file) {
|
||||
|
||||
if( is_file($single_file) )
|
||||
@unlink($single_file);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function get_cached_urls() {
|
||||
|
||||
$cache_path = $this->init_directory();
|
||||
$urls = array();
|
||||
|
||||
//Get a list of all of the file names in the folder.
|
||||
$files = glob($cache_path . '/*.tmp');
|
||||
|
||||
foreach($files as $single_file) {
|
||||
|
||||
if( is_file($single_file) ) {
|
||||
|
||||
list($single_url, $single_timestamp) = explode('|', file_get_contents($single_file));
|
||||
|
||||
if( strlen($single_url) > 1 )
|
||||
$urls[] = $single_url;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $urls;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function get_cached_urls_by_timestamp($timestamp) {
|
||||
|
||||
$cache_path = $this->init_directory();
|
||||
$urls = array();
|
||||
|
||||
//Get a list of all of the file names in the folder.
|
||||
$files = glob($cache_path . '/*.tmp');
|
||||
|
||||
foreach($files as $single_file) {
|
||||
|
||||
if( is_file($single_file) ) {
|
||||
|
||||
list($single_url, $single_timestamp) = explode('|', file_get_contents($single_file));
|
||||
|
||||
if( $single_timestamp <= $timestamp && strlen($single_url) > 1 )
|
||||
$urls[] = $single_url;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $urls;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function delete_cached_urls_by_timestamp($timestamp) {
|
||||
|
||||
$cache_path = $this->init_directory();
|
||||
|
||||
//Get a list of all of the file names in the folder.
|
||||
$files = glob($cache_path . '/*.tmp');
|
||||
|
||||
foreach($files as $single_file) {
|
||||
|
||||
if( is_file($single_file) ) {
|
||||
|
||||
list($single_url, $single_timestamp) = explode('|', file_get_contents($single_file));
|
||||
|
||||
if( $single_timestamp <= $timestamp )
|
||||
unlink( $single_file );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function delete_cached_urls_by_urls_list($urls) {
|
||||
|
||||
if( !is_array($urls) )
|
||||
return false;
|
||||
|
||||
$cache_path = $this->init_directory();
|
||||
|
||||
//Get a list of all of the file names in the folder.
|
||||
$files = glob($cache_path . '/*.tmp');
|
||||
|
||||
foreach($files as $single_file) {
|
||||
|
||||
if( is_file($single_file) ) {
|
||||
|
||||
list($single_url, $single_timestamp) = explode('|', file_get_contents($single_file));
|
||||
|
||||
if( in_array($single_url, $urls) )
|
||||
unlink( $single_file );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function admin_menu_page_cached_html_pages() {
|
||||
|
||||
if( !current_user_can('manage_options') ) {
|
||||
die( __('Permission denied', 'wp-cloudflare-page-cache') );
|
||||
}
|
||||
|
||||
$cached_html_pages_list = $this->get_cached_urls();
|
||||
|
||||
require_once SWCFPC_PLUGIN_PATH . 'libs/views/cached_html_pages.php';
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
{
|
||||
"packages": [
|
||||
{
|
||||
"name": "codeinwp/themeisle-sdk",
|
||||
"version": "3.3.14",
|
||||
"version_normalized": "3.3.14.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Codeinwp/themeisle-sdk.git",
|
||||
"reference": "662952078c57b12e4d3af9bc98ef847ea3500206"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Codeinwp/themeisle-sdk/zipball/662952078c57b12e4d3af9bc98ef847ea3500206",
|
||||
"reference": "662952078c57b12e4d3af9bc98ef847ea3500206",
|
||||
"shasum": ""
|
||||
},
|
||||
"require-dev": {
|
||||
"codeinwp/phpcs-ruleset": "dev-main"
|
||||
},
|
||||
"time": "2024-02-27T17:30:04+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"GPL-2.0+"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "ThemeIsle team",
|
||||
"email": "friends@themeisle.com",
|
||||
"homepage": "https://themeisle.com"
|
||||
}
|
||||
],
|
||||
"description": "ThemeIsle SDK",
|
||||
"homepage": "https://github.com/Codeinwp/themeisle-sdk",
|
||||
"keywords": [
|
||||
"wordpress"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/Codeinwp/themeisle-sdk/issues",
|
||||
"source": "https://github.com/Codeinwp/themeisle-sdk/tree/v3.3.14"
|
||||
},
|
||||
"install-path": "../codeinwp/themeisle-sdk"
|
||||
},
|
||||
{
|
||||
"name": "deliciousbrains/wp-background-processing",
|
||||
"version": "1.0.2",
|
||||
"version_normalized": "1.0.2.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/deliciousbrains/wp-background-processing.git",
|
||||
"reference": "2cbee1abd1b49e1133cd8f611df4d4fc5a8b9800"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/deliciousbrains/wp-background-processing/zipball/2cbee1abd1b49e1133cd8f611df4d4fc5a8b9800",
|
||||
"reference": "2cbee1abd1b49e1133cd8f611df4d4fc5a8b9800",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.2"
|
||||
},
|
||||
"suggest": {
|
||||
"coenjacobs/mozart": "Easily wrap this library with your own prefix, to prevent collisions when multiple plugins use this library"
|
||||
},
|
||||
"time": "2020-07-31T07:00:11+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"classes/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"GPL-2.0-or-later"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Delicious Brains",
|
||||
"email": "nom@deliciousbrains.com"
|
||||
}
|
||||
],
|
||||
"description": "WP Background Processing can be used to fire off non-blocking asynchronous requests or as a background processing tool, allowing you to queue tasks.",
|
||||
"support": {
|
||||
"issues": "https://github.com/deliciousbrains/wp-background-processing/issues",
|
||||
"source": "https://github.com/deliciousbrains/wp-background-processing/tree/master"
|
||||
},
|
||||
"install-path": "../deliciousbrains/wp-background-processing"
|
||||
}
|
||||
],
|
||||
"dev": false,
|
||||
"dev-package-names": []
|
||||
}
|
After Width: | Height: | Size: 669 KiB |
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
|
||||
// if uninstall.php is not called by WordPress, die
|
||||
if (!defined('WP_UNINSTALL_PLUGIN')) {
|
||||
die;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
|
||||
delete_option('swcfpc_config');
|
||||
delete_option('swcfpc_version');
|
||||
delete_option('swcfpc_preloader_lock');
|
||||
delete_option('swcfpc_purge_cache_lock');
|
||||
delete_option('swcfpc_fc_ttl_registry');
|
||||
|
||||
$parts = parse_url( home_url() );
|
||||
|
||||
if( file_exists(WP_CONTENT_DIR . "/wp-cloudflare-super-page-cache/{$parts['host']}/debug.log" ) )
|
||||
@unlink( WP_CONTENT_DIR . "/wp-cloudflare-super-page-cache/{$parts['host']}/debug.log" );
|
||||
|
||||
if( defined('SWCFPC_ADVANCED_CACHE') )
|
||||
@unlink(WP_CONTENT_DIR . '/advanced-cache.php');
|
||||
|
||||
$config_file_path = ABSPATH.'wp-config.php';
|
||||
|
||||
$parts = parse_url( home_url() );
|
||||
$plugin_storage_main_path = WP_CONTENT_DIR . '/wp-cloudflare-super-page-cache/';
|
||||
$plugin_storage_path = $plugin_storage_main_path.$parts['host'];
|
||||
|
||||
if( file_exists($config_file_path) && is_writable($config_file_path) ) {
|
||||
|
||||
// Get content of the config file.
|
||||
$config_file = explode("\n", file_get_contents($config_file_path));
|
||||
$config_file_count = count($config_file);
|
||||
$last_line = '';
|
||||
|
||||
for($i=0; $i<$config_file_count; ++$i) {
|
||||
|
||||
// Remove double empty line
|
||||
if( $i>0 && trim($config_file[$i]) == '' && $last_line == '' ) {
|
||||
unset($config_file[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$last_line = trim($config_file[$i]);
|
||||
|
||||
if ( ! preg_match( '/^define\(\s*\'([A-Z_]+)\',(.*)\)/', $config_file[$i], $match ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( 'WP_CACHE' === $match[1] && strpos($config_file[$i], 'Added by WP Cloudflare Super Page Cache') !== false ) {
|
||||
unset($config_file[$i]);
|
||||
$last_line = '';
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if( trim($config_file[ $config_file_count-1 ]) == '' )
|
||||
unset( $config_file[ $config_file_count-1 ] );
|
||||
|
||||
// Insert the constant in wp-config.php file.
|
||||
$handle = @fopen($config_file_path, 'w');
|
||||
|
||||
foreach ($config_file as $line) {
|
||||
@fwrite($handle, $line . "\n");
|
||||
}
|
||||
|
||||
@fclose($handle);
|
||||
|
||||
}
|
||||
|
||||
$timestamp = wp_next_scheduled( 'swcfpc_cache_purge_cron' );
|
||||
wp_unschedule_event( $timestamp, 'swcfpc_cache_purge_cron' );
|
||||
|
||||
if( file_exists($plugin_storage_path) ) {
|
||||
delete_directory_recursive( $plugin_storage_path );
|
||||
}
|
||||
|
||||
if( file_exists($plugin_storage_main_path) && is_directory_empty($plugin_storage_main_path) )
|
||||
rmdir( $plugin_storage_main_path );
|
||||
|
||||
function delete_directory_recursive($dir) {
|
||||
|
||||
if( !class_exists('RecursiveDirectoryIterator') || !class_exists('RecursiveIteratorIterator') )
|
||||
return false;
|
||||
|
||||
$it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
$files = new RecursiveIteratorIterator($it,RecursiveIteratorIterator::CHILD_FIRST);
|
||||
|
||||
foreach($files as $file) {
|
||||
|
||||
if ($file->isDir())
|
||||
rmdir($file->getRealPath());
|
||||
else
|
||||
unlink($file->getRealPath());
|
||||
|
||||
}
|
||||
|
||||
rmdir($dir);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function is_directory_empty($dir) {
|
||||
|
||||
$handle = opendir($dir);
|
||||
|
||||
while (false !== ($entry = readdir($handle))) {
|
||||
if ($entry != '.' && $entry != '..') {
|
||||
closedir($handle);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
closedir($handle);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
After Width: | Height: | Size: 36 KiB |
|
@ -0,0 +1,460 @@
|
|||
<?php
|
||||
/**
|
||||
* The product model class for ThemeIsle SDK
|
||||
*
|
||||
* @package ThemeIsleSDK
|
||||
* @subpackage Product
|
||||
* @copyright Copyright (c) 2017, Marius Cristea
|
||||
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace ThemeisleSDK;
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Product model for ThemeIsle SDK.
|
||||
*/
|
||||
class Product {
|
||||
/**
|
||||
* Define plugin type string.
|
||||
*/
|
||||
const PLUGIN_TYPE = 'plugin';
|
||||
/**
|
||||
* Define theme type string.
|
||||
*/
|
||||
const THEME_TYPE = 'theme';
|
||||
/**
|
||||
* If the product has a pro version, contains the pro slug.
|
||||
*
|
||||
* @var string $pro_slug Pro slug, if available.
|
||||
*/
|
||||
public $pro_slug;
|
||||
/**
|
||||
* Current product slug.
|
||||
*
|
||||
* @var string $slug THe product slug.
|
||||
*/
|
||||
private $slug;
|
||||
/**
|
||||
* Product basefile, with the proper metadata.
|
||||
*
|
||||
* @var string $basefile The file with headers.
|
||||
*/
|
||||
private $basefile;
|
||||
/**
|
||||
* Type of the product.
|
||||
*
|
||||
* @var string $type The product type ( plugin | theme ).
|
||||
*/
|
||||
private $type;
|
||||
/**
|
||||
* The file name.
|
||||
*
|
||||
* @var string $file The file name.
|
||||
*/
|
||||
private $file;
|
||||
/**
|
||||
* Product name, fetched from the file headers.
|
||||
*
|
||||
* @var string $name The product name.
|
||||
*/
|
||||
private $name;
|
||||
/**
|
||||
* Product normalized key.
|
||||
*
|
||||
* @var string $key The product ready key.
|
||||
*/
|
||||
private $key;
|
||||
/**
|
||||
* Author URL
|
||||
*
|
||||
* @var string $author_url The author url.
|
||||
*/
|
||||
private $author_url;
|
||||
/**
|
||||
* Product store url.
|
||||
*
|
||||
* @var string $store_url The store url.
|
||||
*/
|
||||
private $store_url;
|
||||
/**
|
||||
* Product install timestamp.
|
||||
*
|
||||
* @var int $install The date of install.
|
||||
*/
|
||||
private $install;
|
||||
/**
|
||||
* Product store/author name.
|
||||
*
|
||||
* @var string $store_name The store name.
|
||||
*/
|
||||
private $store_name;
|
||||
/**
|
||||
* Does the product requires license.
|
||||
*
|
||||
* @var bool $requires_license Either user needs to activate it with license.
|
||||
*/
|
||||
private $requires_license;
|
||||
/**
|
||||
* Is the product available on wordpress.org
|
||||
*
|
||||
* @var bool $wordpress_available Either is available on WordPress or not.
|
||||
*/
|
||||
private $wordpress_available;
|
||||
/**
|
||||
* Current version of the product.
|
||||
*
|
||||
* @var string $version The product version.
|
||||
*/
|
||||
private $version;
|
||||
/**
|
||||
* Holds a map of loaded products objects.
|
||||
*
|
||||
* @var array Array of loaded products.
|
||||
*/
|
||||
private static $cached_products = [];
|
||||
/**
|
||||
* Root api endpoint.
|
||||
*/
|
||||
const API_URL = 'https://api.themeisle.com/';
|
||||
|
||||
/**
|
||||
* ThemeIsle_SDK_Product constructor.
|
||||
*
|
||||
* @param string $basefile Product basefile.
|
||||
*/
|
||||
public function __construct( $basefile ) {
|
||||
if ( ! empty( $basefile ) ) {
|
||||
if ( is_file( $basefile ) ) {
|
||||
$this->basefile = $basefile;
|
||||
$this->setup_from_path();
|
||||
$this->setup_from_fileheaders();
|
||||
}
|
||||
}
|
||||
$install = get_option( $this->get_key() . '_install', 0 );
|
||||
if ( 0 === $install ) {
|
||||
$install = time();
|
||||
update_option( $this->get_key() . '_install', time() );
|
||||
}
|
||||
$this->install = $install;
|
||||
self::$cached_products[ crc32( $basefile ) ] = $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a product.
|
||||
*
|
||||
* @param string $basefile Product basefile.
|
||||
*
|
||||
* @return Product Product Object.
|
||||
*/
|
||||
public static function get( $basefile ) {
|
||||
$key = crc32( $basefile );
|
||||
if ( isset( self::$cached_products[ $key ] ) ) {
|
||||
return self::$cached_products[ $key ];
|
||||
}
|
||||
self::$cached_products[ $key ] = new Product( $basefile );
|
||||
|
||||
return self::$cached_products[ $key ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup props from path.
|
||||
*/
|
||||
public function setup_from_path() {
|
||||
$this->file = basename( $this->basefile );
|
||||
$dir = dirname( $this->basefile );
|
||||
$this->slug = basename( $dir );
|
||||
$exts = explode( '.', $this->basefile );
|
||||
$ext = $exts[ count( $exts ) - 1 ];
|
||||
if ( 'css' === $ext ) {
|
||||
$this->type = 'theme';
|
||||
}
|
||||
if ( 'php' === $ext ) {
|
||||
$this->type = 'plugin';
|
||||
}
|
||||
$this->key = self::key_ready_name( $this->slug );
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize string.
|
||||
*
|
||||
* @param string $string the String to be normalized for cron handler.
|
||||
*
|
||||
* @return string $name The normalized string.
|
||||
*/
|
||||
public static function key_ready_name( $string ) {
|
||||
return str_replace( '-', '_', strtolower( trim( $string ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup props from fileheaders.
|
||||
*/
|
||||
public function setup_from_fileheaders() {
|
||||
$file_headers = array(
|
||||
'Requires License' => 'Requires License',
|
||||
'WordPress Available' => 'WordPress Available',
|
||||
'Pro Slug' => 'Pro Slug',
|
||||
'Version' => 'Version',
|
||||
);
|
||||
if ( 'plugin' === $this->type ) {
|
||||
$file_headers['Name'] = 'Plugin Name';
|
||||
$file_headers['AuthorName'] = 'Author';
|
||||
$file_headers['AuthorURI'] = 'Author URI';
|
||||
}
|
||||
if ( 'theme' === $this->type ) {
|
||||
$file_headers['Name'] = 'Theme Name';
|
||||
$file_headers['AuthorName'] = 'Author';
|
||||
$file_headers['AuthorURI'] = 'Author URI';
|
||||
}
|
||||
$file_headers = get_file_data( $this->basefile, $file_headers );
|
||||
|
||||
$this->name = $file_headers['Name'];
|
||||
$this->store_name = $file_headers['AuthorName'];
|
||||
$this->author_url = $file_headers['AuthorURI'];
|
||||
$this->store_url = $file_headers['AuthorURI'];
|
||||
|
||||
$this->requires_license = ( 'yes' === $file_headers['Requires License'] ) ? true : false;
|
||||
$this->wordpress_available = ( 'yes' === $file_headers['WordPress Available'] ) ? true : false;
|
||||
$this->pro_slug = ! empty( $file_headers['Pro Slug'] ) ? $file_headers['Pro Slug'] : '';
|
||||
$this->version = $file_headers['Version'];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the product key.
|
||||
*
|
||||
* @return string The product key.
|
||||
*/
|
||||
public function get_key() {
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the product is either theme or plugin.
|
||||
*
|
||||
* @return string Product type.
|
||||
*/
|
||||
public function get_type() {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if the product is used as a plugin.
|
||||
*
|
||||
* @return bool Is plugin?
|
||||
*/
|
||||
public function is_plugin() {
|
||||
return self::PLUGIN_TYPE === $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if the product is used as a theme.
|
||||
*
|
||||
* @return bool Is theme ?
|
||||
*/
|
||||
public function is_theme() {
|
||||
return self::THEME_TYPE === $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the product slug.
|
||||
*
|
||||
* @return string The product slug.
|
||||
*/
|
||||
public function get_slug() {
|
||||
return $this->slug;
|
||||
}
|
||||
|
||||
/**
|
||||
* The magic var_dump info method.
|
||||
*
|
||||
* @return array Debug info.
|
||||
*/
|
||||
public function __debugInfo() {
|
||||
return array(
|
||||
'name' => $this->name,
|
||||
'slug' => $this->slug,
|
||||
'version' => $this->version,
|
||||
'basefile' => $this->basefile,
|
||||
'key' => $this->key,
|
||||
'type' => $this->type,
|
||||
'store_name' => $this->store_name,
|
||||
'store_url' => $this->store_url,
|
||||
'wordpress_available' => $this->wordpress_available,
|
||||
'requires_license' => $this->requires_license,
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for product version.
|
||||
*
|
||||
* @return string The product version.
|
||||
*/
|
||||
public function get_version() {
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current product license, if available.
|
||||
*
|
||||
* @return string Return license key, if available.
|
||||
*/
|
||||
public function get_license() {
|
||||
|
||||
if ( ! $this->requires_license() && ! $this->is_wordpress_available() ) {
|
||||
return 'free';
|
||||
}
|
||||
$license_data = get_option( $this->get_key() . '_license_data', '' );
|
||||
|
||||
if ( empty( $license_data ) ) {
|
||||
return get_option( $this->get_key() . '_license', '' );
|
||||
}
|
||||
if ( ! isset( $license_data->key ) ) {
|
||||
return get_option( $this->get_key() . '_license', '' );
|
||||
}
|
||||
|
||||
return $license_data->key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Either the product requires license or not.
|
||||
*
|
||||
* @return bool Either requires license or not.
|
||||
*/
|
||||
public function requires_license() {
|
||||
return $this->requires_license;
|
||||
}
|
||||
|
||||
/**
|
||||
* If product is available on wordpress.org or not.
|
||||
*
|
||||
* @return bool Either is wp available or not.
|
||||
*/
|
||||
public function is_wordpress_available() {
|
||||
return $this->wordpress_available;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return friendly name.
|
||||
*
|
||||
* @return string Friendly name.
|
||||
*/
|
||||
public function get_friendly_name() {
|
||||
$name = apply_filters( $this->get_key() . '_friendly_name', trim( str_replace( 'Lite', '', $this->get_name() ) ) );
|
||||
$name = rtrim( $name, '- ()' );
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the product version cache key.
|
||||
*
|
||||
* @return string The product version cache key.
|
||||
*/
|
||||
public function get_cache_key() {
|
||||
return $this->get_key() . '_' . preg_replace( '/[^0-9a-zA-Z ]/m', '', $this->get_version() ) . 'versions';
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for product name.
|
||||
*
|
||||
* @return string The product name.
|
||||
*/
|
||||
public function get_name() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Store name.
|
||||
*
|
||||
* @return string Store name.
|
||||
*/
|
||||
public function get_store_name() {
|
||||
return $this->store_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the store url.
|
||||
*
|
||||
* @return string The store url.
|
||||
*/
|
||||
public function get_store_url() {
|
||||
|
||||
if ( strpos( $this->store_url, '/themeisle.com' ) !== false ) {
|
||||
return 'https://store.themeisle.com/';
|
||||
}
|
||||
|
||||
return $this->store_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns product basefile, which holds the metaheaders.
|
||||
*
|
||||
* @return string The product basefile.
|
||||
*/
|
||||
public function get_basefile() {
|
||||
return $this->basefile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get changelog url.
|
||||
*
|
||||
* @return string Changelog url.
|
||||
*/
|
||||
public function get_changelog() {
|
||||
return add_query_arg(
|
||||
[
|
||||
'name' => rawurlencode( $this->get_name() ),
|
||||
'edd_action' => 'view_changelog',
|
||||
],
|
||||
$this->get_store_url()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns product filename.
|
||||
*
|
||||
* @return string The product filename.
|
||||
*/
|
||||
public function get_file() {
|
||||
return $this->file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pro slug, if available.
|
||||
*
|
||||
* @return string The pro slug.
|
||||
*/
|
||||
public function get_pro_slug() {
|
||||
return $this->pro_slug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the install timestamp.
|
||||
*
|
||||
* @return int The install timestamp.
|
||||
*/
|
||||
public function get_install_time() {
|
||||
return $this->install;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL of the product base file.
|
||||
*
|
||||
* @param string $path The path to the file.
|
||||
*
|
||||
* @return string The URL of the product base file.
|
||||
*/
|
||||
public function get_base_url( $path = '/' ) {
|
||||
if ( $this->type ) {
|
||||
return plugins_url( $path, $this->basefile );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
After Width: | Height: | Size: 6.3 KiB |
|
@ -0,0 +1,883 @@
|
|||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
|
||||
|
||||
class SWCFPC_Fallback_Cache
|
||||
{
|
||||
|
||||
private $main_instance = null;
|
||||
private $objects = false;
|
||||
private $fallback_cache_ttl_registry = false;
|
||||
private $fallback_cache = false;
|
||||
|
||||
function __construct( $main_instance )
|
||||
{
|
||||
|
||||
$this->main_instance = $main_instance;
|
||||
|
||||
if( $this->main_instance->get_single_config('cf_fallback_cache', 0) > 0 ) {
|
||||
|
||||
if ( !$this->fallback_cache_init_ttl_registry() ) {
|
||||
$this->fallback_cache_ttl_registry = array();
|
||||
$this->fallback_cache_update_ttl_registry();
|
||||
}
|
||||
|
||||
if( $this->main_instance->get_single_config('cf_fallback_cache_ttl', 0) > 0 )
|
||||
$this->fallback_cache_delete_expired_pages();
|
||||
|
||||
}
|
||||
|
||||
if( $this->main_instance->get_single_config('cf_cache_enabled', 0) == 0 || $this->main_instance->get_single_config('cf_fallback_cache', 0) == 0 || ($this->main_instance->get_single_config('cf_fallback_cache', 0) > 0 && $this->main_instance->get_single_config('cf_fallback_cache_curl', 0) > 0) )
|
||||
$this->fallback_cache_advanced_cache_disable();
|
||||
|
||||
if( $this->main_instance->get_single_config('cf_cache_enabled', 0) > 0 && $this->main_instance->get_single_config('cf_fallback_cache', 0) > 0 && $this->main_instance->get_single_config('cf_fallback_cache_curl', 0) == 0 )
|
||||
$this->fallback_cache_advanced_cache_enable();
|
||||
|
||||
$this->actions();
|
||||
|
||||
}
|
||||
|
||||
|
||||
function actions() {
|
||||
|
||||
// Ajax clear whole fallback cache
|
||||
add_action( 'wp_ajax_swcfpc_purge_fallback_page_cache', array($this, 'ajax_purge_whole_fallback_page_cache') );
|
||||
|
||||
if( $this->main_instance->get_single_config('cf_fallback_cache', 0) > 0 && !is_admin() && !$this->main_instance->is_login_page() && $this->main_instance->get_single_config('cf_fallback_cache_curl', 0) > 0 ) {
|
||||
add_action('shutdown', array($this, 'fallback_cache_add_current_url_to_cache'), PHP_INT_MAX);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_enable() {
|
||||
$this->fallback_cache = true;
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_disable() {
|
||||
$this->fallback_cache = false;
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_save_config() {
|
||||
|
||||
$cache_path = $this->main_instance->get_plugin_wp_content_directory().'/';
|
||||
|
||||
file_put_contents( "{$cache_path}main_config.php", '<?php $swcfpc_config=\''.addslashes( json_encode($this->main_instance->get_config()) ).'\'; ?>');
|
||||
|
||||
if( is_array($this->fallback_cache_ttl_registry) ) {
|
||||
file_put_contents( "{$cache_path}ttl_registry.json", json_encode( $this->fallback_cache_ttl_registry ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_delete_config() {
|
||||
|
||||
$cache_path = $this->main_instance->get_plugin_wp_content_directory().'/';
|
||||
|
||||
if( file_exists("{$cache_path}ttl_registry.json") ) {
|
||||
@unlink("{$cache_path}ttl_registry.json");
|
||||
}
|
||||
|
||||
if( file_exists("{$cache_path}ttl_registry.php") ) {
|
||||
@unlink("{$cache_path}ttl_registry.php");
|
||||
}
|
||||
|
||||
if( file_exists("{$cache_path}main_config.php") ) {
|
||||
@unlink("{$cache_path}main_config.php");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_advanced_cache_enable($force_wp_cache=false) {
|
||||
|
||||
$this->objects = $this->main_instance->get_objects();
|
||||
$this->fallback_cache_init_directory();
|
||||
|
||||
$advanced_cache_dest = WP_CONTENT_DIR.'/advanced-cache.php';
|
||||
|
||||
if( !defined('SWCFPC_ADVANCED_CACHE') || !file_exists($advanced_cache_dest) ) {
|
||||
|
||||
$advanced_cache_source = SWCFPC_PLUGIN_PATH.'assets/advanced-cache.php';
|
||||
|
||||
if( file_exists($advanced_cache_dest) && !@unlink($advanced_cache_dest) ) {
|
||||
$this->objects['logs']->add_log('fallback_cache::fallback_cache_advanced_cache_enable', 'Unable to remove the old advanced-cache.php from wp-content directory' );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( file_put_contents($advanced_cache_dest, file_get_contents($advanced_cache_source)) === false ) {
|
||||
//if ( !copy($advanced_cache_source, $advanced_cache_dest) ) {
|
||||
$this->objects['logs']->add_log('fallback_cache::fallback_cache_advanced_cache_enable', 'Unable to copy advanced-cache.php to wp-content directory' );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( $force_wp_cache || !defined('WP_CACHE') || (defined('WP_CACHE') && WP_CACHE === false) ) {
|
||||
|
||||
if( ! $this->fallback_cache_add_define_cache_wp_config() )
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
$this->fallback_cache_save_config();
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
$this->fallback_cache_save_config();
|
||||
|
||||
if( !defined('WP_CACHE') || (defined('WP_CACHE') && WP_CACHE === false) ) {
|
||||
|
||||
if( ! $this->fallback_cache_add_define_cache_wp_config() )
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_advanced_cache_disable() {
|
||||
|
||||
if( defined('SWCFPC_ADVANCED_CACHE') ) {
|
||||
|
||||
if( file_exists(WP_CONTENT_DIR.'/advanced-cache.php') )
|
||||
@unlink(WP_CONTENT_DIR.'/advanced-cache.php');
|
||||
|
||||
$this->fallback_cache_delete_config();
|
||||
|
||||
if( !is_multisite() && defined('WP_CACHE') )
|
||||
$this->fallback_cache_add_define_cache_wp_config( false );
|
||||
|
||||
$this->fallback_cache_purge_all();
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_add_define_cache_wp_config( $turn_it_on = true ) {
|
||||
|
||||
$this->objects = $this->main_instance->get_objects();
|
||||
|
||||
if( $turn_it_on && defined( 'WP_CACHE' ) && WP_CACHE ) {
|
||||
$this->objects['logs']->add_log('fallback_cache::fallback_cache_add_define_cache_wp_config', 'WP_CACHE already defined' );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( defined( 'IS_PRESSABLE' ) && IS_PRESSABLE ) {
|
||||
$this->objects['logs']->add_log('fallback_cache::fallback_cache_add_define_cache_wp_config', 'IS_PRESSABLE defined' );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$config_file_path = ABSPATH.'wp-config.php';
|
||||
|
||||
if ( ! file_exists($config_file_path) ) {
|
||||
$this->objects['logs']->add_log('fallback_cache::fallback_cache_add_define_cache_wp_config', 'Unable to find wp-config.php' );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( ! $this->fallback_cache_is_wp_config_writable() ) {
|
||||
$this->objects['logs']->add_log('fallback_cache::fallback_cache_add_define_cache_wp_config', 'wp-config.php is not writable' );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get content of the config file.
|
||||
$config_file = explode("\n", file_get_contents( $config_file_path ));
|
||||
$config_file_count = count($config_file);
|
||||
|
||||
// Get the value of WP_CACHE constant.
|
||||
$turn_it_on = $turn_it_on ? 'true' : 'false';
|
||||
|
||||
/**
|
||||
* Filter allow to change the value of WP_CACHE constant
|
||||
*
|
||||
* @since 2.1
|
||||
*
|
||||
* @param string $turn_it_on The value of WP_CACHE constant.
|
||||
*/
|
||||
$turn_it_on = apply_filters( 'swcfpc_set_wp_cache_define', $turn_it_on );
|
||||
|
||||
// Lets find out if the constant WP_CACHE is defined or not.
|
||||
$is_wp_cache_exist = false;
|
||||
|
||||
// Get WP_CACHE constant define.
|
||||
$constant = "define('WP_CACHE', {$turn_it_on}); // Added by WP Cloudflare Super Page Cache";
|
||||
$last_line = '';
|
||||
|
||||
for($i=0; $i < $config_file_count; ++$i) {
|
||||
|
||||
// Remove double empty line
|
||||
if( $i>0 && trim($config_file[$i]) == '' && $last_line == '' ) {
|
||||
unset($config_file[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$last_line = trim($config_file[$i]);
|
||||
|
||||
if ( ! preg_match( '/^define\(\s*\'([A-Z_]+)\',(.*)\)/', $config_file[$i], $match ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( 'WP_CACHE' === $match[1] ) {
|
||||
|
||||
$is_wp_cache_exist = true;
|
||||
|
||||
if( $turn_it_on == 'true' ) {
|
||||
$config_file[$i] = $constant;
|
||||
}
|
||||
else {
|
||||
unset($config_file[$i]);
|
||||
$last_line = '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// If the constant does not exist, create it.
|
||||
if ( $is_wp_cache_exist === false ) {
|
||||
array_shift( $config_file );
|
||||
array_unshift( $config_file, "<?php\r\n", $constant );
|
||||
$this->objects['logs']->add_log('fallback_cache::fallback_cache_add_define_cache_wp_config', 'Constant WP_CACHE does not exists. I will try to add in into wp-config.php' );
|
||||
}
|
||||
|
||||
if( isset($config_file[ $config_file_count-1 ]) && trim($config_file[ $config_file_count-1 ]) == '' )
|
||||
unset( $config_file[ $config_file_count-1 ] );
|
||||
|
||||
// Insert the constant in wp-config.php file.
|
||||
$handle = @fopen( $config_file_path, 'w' );
|
||||
$config_file = array_values( $config_file );
|
||||
$config_file_count = count( $config_file );
|
||||
|
||||
for($i=0; $i<$config_file_count; ++$i) {
|
||||
|
||||
$line = trim($config_file[$i]);
|
||||
|
||||
if( $i < ($config_file_count-1) )
|
||||
$line .= "\n";
|
||||
|
||||
@fwrite( $handle, $line );
|
||||
|
||||
}
|
||||
|
||||
@fclose( $handle );
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_is_wp_config_writable() {
|
||||
|
||||
$config_file_path = ABSPATH.'wp-config.php';
|
||||
|
||||
return is_writable( $config_file_path );
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_is_wp_content_writable() {
|
||||
|
||||
return is_writable( WP_CONTENT_DIR );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
function fallback_cache_start_caching_via_hook() {
|
||||
|
||||
$this->objects = $this->main_instance->get_objects();
|
||||
|
||||
if( $this->objects['cache_controller']->is_cache_enabled() && !$this->objects['cache_controller']->is_url_to_bypass() && !$this->objects['cache_controller']->can_i_bypass_cache() )
|
||||
$this->fallback_cache_enable();
|
||||
else
|
||||
$this->fallback_cache_disable();
|
||||
|
||||
if( $this->fallback_cache == true && isset( $_SERVER['REQUEST_METHOD'] ) && strcasecmp($_SERVER['REQUEST_METHOD'], 'GET') == 0 ) {
|
||||
|
||||
if (isset($_SERVER['HTTP_USER_AGENT']) && strcasecmp($_SERVER['HTTP_USER_AGENT'], 'ua-swcfpc-fc') == 0)
|
||||
return;
|
||||
|
||||
$cache_path = $this->fallback_cache_init_directory();
|
||||
$cache_key = $this->fallback_cache_get_current_page_cache_key();
|
||||
|
||||
if (!file_exists($cache_path . $cache_key) || $this->fallback_cache_is_expired_page($cache_key)) {
|
||||
|
||||
ob_start(array($this, 'fallback_cache_end_caching_via_hook') );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_end_caching_via_hook( $html ) {
|
||||
|
||||
$cache_path = $this->fallback_cache_init_directory();
|
||||
$cache_key = $this->fallback_cache_get_current_page_cache_key();
|
||||
|
||||
if ($this->main_instance->get_single_config('cf_fallback_cache_ttl', 0) == 0)
|
||||
$ttl = 0;
|
||||
else
|
||||
$ttl = time() + $this->main_instance->get_single_config('cf_fallback_cache_ttl', 0);
|
||||
|
||||
if( $ttl > 0 )
|
||||
$html .= "\n<!-- Page retrieved from WP Cloudflare Super Page Cache's fallback cache - page generated @ " . date('Y-m-d H:i:s') . ' - fallback cache expiration @ ' . date('Y-m-d H:i:s', $ttl) . ' -->';
|
||||
else
|
||||
$html .= "\n<!-- Page retrieved from WP Cloudflare Super Page Cache's fallback cache - page generated @ " . date('Y-m-d H:i:s') . ' - fallback cache expiration @ never expires -->';
|
||||
|
||||
file_put_contents($cache_path . $cache_key, $html);
|
||||
|
||||
// Update TTL
|
||||
$this->fallback_cache_set_single_ttl($cache_key, $ttl);
|
||||
$this->fallback_cache_update_ttl_registry();
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
function fallback_cache_add_current_url_to_cache() {
|
||||
|
||||
if( $this->fallback_cache == true && $this->fallback_cache_is_url_to_exclude() == false && isset( $_SERVER['REQUEST_METHOD'] ) && strcasecmp($_SERVER['REQUEST_METHOD'], 'GET') == 0 ) {
|
||||
|
||||
if( isset($_SERVER['HTTP_USER_AGENT']) && strcasecmp($_SERVER['HTTP_USER_AGENT'], 'ua-swcfpc-fc') == 0 )
|
||||
return;
|
||||
|
||||
$cache_path = $this->fallback_cache_init_directory();
|
||||
$cache_key = $this->fallback_cache_get_current_page_cache_key();
|
||||
|
||||
if ( !file_exists($cache_path . $cache_key) || $this->fallback_cache_is_expired_page( $cache_key ) ) {
|
||||
|
||||
// absolute URI in multisite aware environment
|
||||
$parts = parse_url(home_url());
|
||||
$current_uri = "{$parts['scheme']}://{$parts['host']}" . add_query_arg(NULL, NULL);
|
||||
|
||||
$response = wp_remote_get($current_uri, array(
|
||||
'timeout' => defined('SWCFPC_CURL_TIMEOUT') ? SWCFPC_CURL_TIMEOUT : 10,
|
||||
'sslverify' => false,
|
||||
'user-agent' => 'ua-swcfpc-fc'
|
||||
));
|
||||
|
||||
if (!is_wp_error($response)) {
|
||||
|
||||
$response_code = wp_remote_retrieve_response_code($response);
|
||||
|
||||
if( $response_code == 200 ) {
|
||||
|
||||
if ($this->main_instance->get_single_config('cf_fallback_cache_ttl', 0) == 0) {
|
||||
$ttl = 0;
|
||||
} else {
|
||||
$ttl = time() + $this->main_instance->get_single_config('cf_fallback_cache_ttl', 0);
|
||||
}
|
||||
|
||||
$body = wp_remote_retrieve_body($response);
|
||||
|
||||
if( $ttl > 0 ) {
|
||||
$body .= "\n<!-- Page retrieved from Super Page Cache for Cloudflare's fallback cache via cURL - page generated @ " . date('Y-m-d H:i:s') . ' - fallback cache expiration @ ' . date('Y-m-d H:i:s', $ttl) . " - cache key {$cache_key} -->";
|
||||
} else {
|
||||
$body .= "\n<!-- Page retrieved from Super Page Cache for Cloudflare's fallback cache via cURL - page generated @ " . date('Y-m-d H:i:s') . " - fallback cache expiration @ never expires - cache key {$cache_key} -->";
|
||||
}
|
||||
|
||||
// Provide a filter to modify the HTML before it is cached
|
||||
$body = apply_filters('swcfpc_curl_fallback_cache_html', $body);
|
||||
|
||||
file_put_contents($cache_path . $cache_key, $body);
|
||||
|
||||
// Update TTL
|
||||
$this->fallback_cache_set_single_ttl($cache_key, $ttl);
|
||||
$this->fallback_cache_update_ttl_registry();
|
||||
|
||||
// Store headers
|
||||
if( $this->main_instance->get_single_config('cf_fallback_cache_save_headers', 0) > 0 ) {
|
||||
$this->fallback_cache_save_headers( $cache_path, $cache_key );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_remove_url_parameters( $url ) {
|
||||
|
||||
$url_parsed = parse_url( $url );
|
||||
$url_query_params = [];
|
||||
|
||||
if( array_key_exists( 'query', $url_parsed ) ) {
|
||||
|
||||
if( $url_parsed[ 'query' ] === '' ) {
|
||||
|
||||
// this means the URL ends with just ? i.e. /example-page/? - so just remove the last character ? from the URL
|
||||
$url = substr( trim( $url ), 0, -1 );
|
||||
|
||||
} else {
|
||||
|
||||
// First parse the query params to an array to manage it better
|
||||
parse_str( $url_parsed[ 'query' ], $url_query_params );
|
||||
|
||||
// Get the array of query params that would be ignored
|
||||
$ignored_query_params = $this->main_instance->get_ignored_query_params();
|
||||
|
||||
// Loop though $ignored_query_params
|
||||
foreach( $ignored_query_params as $ignored_query_param ) {
|
||||
|
||||
// Check if that query param is present in $url_query_params
|
||||
if( array_key_exists( $ignored_query_param, $url_query_params ) ) {
|
||||
|
||||
// The ignored query param is present in the $url_query_params. So, unset it from there
|
||||
unset( $url_query_params[ $ignored_query_param ] );
|
||||
}
|
||||
}
|
||||
|
||||
// Now lets check if we have any query params left in $url_query_params
|
||||
if( count( $url_query_params ) > 0 ) {
|
||||
|
||||
$new_url_query_params = http_build_query( $url_query_params );
|
||||
$url_parsed[ 'query' ] = $new_url_query_params;
|
||||
|
||||
} else {
|
||||
// Remove the query section from parsed URL
|
||||
unset( $url_parsed[ 'query' ] );
|
||||
}
|
||||
|
||||
// Get the new current URL without the marketing query params
|
||||
$url = $this->main_instance->get_unparsed_url( $url_parsed );
|
||||
}
|
||||
}
|
||||
|
||||
return $url;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_get_current_page_cache_key( $url=null ) {
|
||||
|
||||
$replacements = array( '://', '/', '?', '#', '&', '.', ',', '@', '-', '\'', '"', '%', ' ', '\\', '=' );
|
||||
|
||||
if( !is_null($url) ) {
|
||||
|
||||
$parts = parse_url( strtolower($url) );
|
||||
|
||||
if( !$parts )
|
||||
return false;
|
||||
|
||||
$current_uri = isset($parts['path']) ? $parts['path'] : '/';
|
||||
|
||||
if( isset($parts['query']) )
|
||||
$current_uri .= "?{$parts['query']}";
|
||||
|
||||
if( $current_uri == '/' )
|
||||
$current_uri = $parts['host'];
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
$current_uri = add_query_arg( NULL, NULL );
|
||||
|
||||
if( $current_uri == '/' ) {
|
||||
$parts = parse_url( home_url() );
|
||||
$current_uri = $parts['host'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if( substr($current_uri, 0, 1) == '/' )
|
||||
$current_uri = substr($current_uri, 1);
|
||||
|
||||
if( substr($current_uri, -1, 1) == '/' )
|
||||
$current_uri = substr($current_uri, 0, -1);
|
||||
|
||||
$cache_key = str_replace( $replacements, '_', $this->fallback_cache_remove_url_parameters($current_uri) );
|
||||
|
||||
// Fix error fnmatch(): Filename exceeds the maximum allowed length
|
||||
$cache_key = sha1( $cache_key );
|
||||
|
||||
/*
|
||||
if( strlen($cache_key) > 250 ) {
|
||||
$cache_key = substr($cache_key, 0, -32);
|
||||
$cache_key .= md5( $current_uri );
|
||||
}*/
|
||||
|
||||
$cache_key .= '.html';
|
||||
|
||||
return $cache_key;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_init_directory() {
|
||||
|
||||
$cache_path = $this->main_instance->get_plugin_wp_content_directory().'/fallback_cache/';
|
||||
|
||||
if( ! file_exists($cache_path) )
|
||||
wp_mkdir_p($cache_path);
|
||||
|
||||
if( file_exists($cache_path) && !file_exists( "{$cache_path}index.php" ) )
|
||||
file_put_contents( "{$cache_path}index.php", '<?php // Silence is golden');
|
||||
|
||||
return $cache_path;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_init_ttl_registry() {
|
||||
|
||||
$this->fallback_cache_ttl_registry = get_option( 'swcfpc_fc_ttl_registry', false );
|
||||
|
||||
if( !$this->fallback_cache_ttl_registry )
|
||||
return false;
|
||||
|
||||
// If the option exists, return true
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_update_ttl_registry() {
|
||||
|
||||
update_option( 'swcfpc_fc_ttl_registry', $this->fallback_cache_ttl_registry );
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_set_single_ttl($name, $value) {
|
||||
|
||||
if( !is_array($this->fallback_cache_ttl_registry) )
|
||||
$this->fallback_cache_ttl_registry = array();
|
||||
|
||||
if( is_array($value) )
|
||||
$this->fallback_cache_ttl_registry[trim($name)] = $value;
|
||||
else
|
||||
$this->fallback_cache_ttl_registry[trim($name)] = (int) $value;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_get_single_ttl($name, $default=false) {
|
||||
|
||||
if( !is_array($this->fallback_cache_ttl_registry) || !isset($this->fallback_cache_ttl_registry[$name]) )
|
||||
return $default;
|
||||
|
||||
if( is_array($this->fallback_cache_ttl_registry[$name]))
|
||||
return $this->fallback_cache_ttl_registry[$name];
|
||||
|
||||
return (int) $this->fallback_cache_ttl_registry[$name];
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_is_expired_page( $cache_key ) {
|
||||
|
||||
$current_ttl = $this->fallback_cache_get_single_ttl( $cache_key, 0 );
|
||||
|
||||
if( $current_ttl > 0 && time() > $current_ttl )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_delete_expired_pages() {
|
||||
|
||||
if( is_array($this->fallback_cache_ttl_registry) ) {
|
||||
|
||||
$cache_path = $this->fallback_cache_init_directory();
|
||||
|
||||
foreach( $this->fallback_cache_ttl_registry as $cache_key => $ttl ) {
|
||||
|
||||
if( $this->fallback_cache_is_expired_page( $cache_key ) && file_exists($cache_path.$cache_key) ) {
|
||||
@unlink( $cache_path.$cache_key );
|
||||
unset($this->fallback_cache_ttl_registry[$cache_key]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->fallback_cache_update_ttl_registry();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_purge_all() {
|
||||
|
||||
$cache_path = $this->fallback_cache_init_directory();
|
||||
|
||||
//Get a list of all of the file names in the folder.
|
||||
$files = glob($cache_path . '/*');
|
||||
|
||||
foreach($files as $file) {
|
||||
|
||||
if(is_file($file))
|
||||
@unlink($file);
|
||||
|
||||
}
|
||||
|
||||
$this->fallback_cache_ttl_registry = array();
|
||||
$this->fallback_cache_update_ttl_registry();
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_purge_urls( $urls ) {
|
||||
|
||||
$cache_path = $this->fallback_cache_init_directory();
|
||||
|
||||
if( is_array($urls) ) {
|
||||
|
||||
foreach ($urls as $single_url) {
|
||||
|
||||
$cache_key = $this->fallback_cache_get_current_page_cache_key($single_url);
|
||||
$headers_file = "{$cache_path}{$cache_key}.headers.json";
|
||||
|
||||
if (file_exists($cache_path . $cache_key)) {
|
||||
@unlink($cache_path . $cache_key);
|
||||
unset($this->fallback_cache_ttl_registry[$cache_key]);
|
||||
}
|
||||
|
||||
if (file_exists($headers_file)) {
|
||||
@unlink($headers_file);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->fallback_cache_update_ttl_registry();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_retrive_current_page() {
|
||||
|
||||
$cache_path = $this->fallback_cache_init_directory();
|
||||
$cache_key = $this->fallback_cache_get_current_page_cache_key();
|
||||
|
||||
if( $this->main_instance->get_single_config('cf_fallback_cache_prevent_cache_urls_without_trailing_slash', 1) > 0 && $this->main_instance->does_current_url_have_trailing_slash() == false )
|
||||
return false;
|
||||
|
||||
if( $this->fallback_cache_is_cookie_to_exclude() )
|
||||
return false;
|
||||
|
||||
if( $this->fallback_cache_is_cookie_to_exclude_cf_worker() )
|
||||
return false;
|
||||
|
||||
if( file_exists($cache_path.$cache_key) && !$this->fallback_cache_is_expired_page( $cache_key ) ) {
|
||||
|
||||
$this->objects = $this->main_instance->get_objects();
|
||||
$stored_headers = $this->fallback_cache_get_stored_headers( $cache_path, $cache_key );
|
||||
|
||||
if( $this->main_instance->get_single_config('cf_strip_cookies', 0) > 0 ) {
|
||||
header_remove('Set-Cookie');
|
||||
}
|
||||
|
||||
header_remove('Pragma');
|
||||
header_remove('Expires');
|
||||
header_remove('Cache-Control');
|
||||
header('Cache-Control: '.$this->objects['cache_controller']->get_cache_control_value());
|
||||
header('X-WP-CF-Super-Cache: cache');
|
||||
header('X-WP-CF-Super-Cache-Active: 1');
|
||||
header('X-WP-CF-Fallback-Cache: 1');
|
||||
header('X-WP-CF-Super-Cache-Cache-Control: '.$this->objects['cache_controller']->get_cache_control_value());
|
||||
header('X-WP-CF-Super-Cache-Cookies-Bypass: '.$this->objects['cache_controller']->get_cookies_to_bypass_in_worker_mode());
|
||||
|
||||
if( $stored_headers ) {
|
||||
|
||||
foreach($stored_headers as $single_header) {
|
||||
header($single_header, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
die( file_get_contents($cache_path . $cache_key) );
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_save_headers($cache_path, $cache_key) {
|
||||
|
||||
$headers_file = "{$cache_path}{$cache_key}.headers.json";
|
||||
|
||||
$headers_list = headers_list();
|
||||
$headers_count = count( $headers_list );
|
||||
|
||||
for( $i=0; $i<$headers_count; ++$i ) {
|
||||
|
||||
list($header_name, $header_value) = explode(':', $headers_list[$i]);
|
||||
|
||||
if(
|
||||
strcasecmp($header_name, 'cache-control') == 0 ||
|
||||
strcasecmp($header_name, 'set-cookie') == 0 ||
|
||||
strcasecmp( substr($header_name, 0, 19), 'X-WP-CF-Super-Cache' ) == 0
|
||||
) {
|
||||
unset($headers_list[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if( count($headers_list) == 0 ) {
|
||||
|
||||
if( file_exists($headers_file) )
|
||||
@unlink($headers_file);
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
file_put_contents( $headers_file, json_encode($headers_list) );
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_get_stored_headers($cache_path, $cache_key) {
|
||||
|
||||
$headers_file = "{$cache_path}{$cache_key}.headers.json";
|
||||
|
||||
if( file_exists($headers_file) ) {
|
||||
|
||||
$swcfpc_headers = json_decode( file_get_contents( $headers_file ), true );
|
||||
|
||||
if( is_array($swcfpc_headers) && count($swcfpc_headers) > 0 )
|
||||
return $swcfpc_headers;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_is_cookie_to_exclude() {
|
||||
|
||||
if( count($_COOKIE) == 0 )
|
||||
return false;
|
||||
|
||||
$excluded_cookies = $this->main_instance->get_single_config('cf_fallback_cache_excluded_cookies', array());
|
||||
|
||||
if( count($excluded_cookies) == 0 )
|
||||
return false;
|
||||
|
||||
$cookies = array_keys( $_COOKIE );
|
||||
|
||||
foreach ($excluded_cookies as $single_cookie) {
|
||||
|
||||
if( count( preg_grep("#{$single_cookie}#", $cookies) ) > 0 )
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_is_cookie_to_exclude_cf_worker() {
|
||||
|
||||
if( count($_COOKIE) == 0 )
|
||||
return false;
|
||||
|
||||
if( $this->main_instance->get_single_config('cf_woker_enabled', 0) == 0 )
|
||||
return false;
|
||||
|
||||
$excluded_cookies = $this->main_instance->get_single_config('cf_fallback_cache_excluded_cookies', array());
|
||||
|
||||
if( count($excluded_cookies) == 0 )
|
||||
return false;
|
||||
|
||||
$cookies = array_keys( $_COOKIE );
|
||||
|
||||
foreach ($excluded_cookies as $single_cookie) {
|
||||
|
||||
if( count( preg_grep("#{$single_cookie}#", $cookies) ) > 0 )
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fallback_cache_is_url_to_exclude($url=false) {
|
||||
|
||||
if( $this->main_instance->get_single_config('cf_fallback_cache_prevent_cache_urls_without_trailing_slash', 1) > 0 && $this->main_instance->does_current_url_have_trailing_slash() == false )
|
||||
return true;
|
||||
|
||||
$excluded_urls = $this->main_instance->get_single_config('cf_fallback_cache_excluded_urls', array());
|
||||
|
||||
if( is_array($excluded_urls) && count($excluded_urls) > 0 ) {
|
||||
|
||||
if( $url === false ) {
|
||||
|
||||
$current_url = $_SERVER['REQUEST_URI'];
|
||||
|
||||
if( isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0 )
|
||||
$current_url .= "?{$_SERVER['QUERY_STRING']}";
|
||||
|
||||
}
|
||||
else {
|
||||
$current_url = $url;
|
||||
}
|
||||
|
||||
foreach( $excluded_urls as $url_to_exclude ) {
|
||||
|
||||
if( $this->main_instance->wildcard_match($url_to_exclude, $current_url) )
|
||||
return true;
|
||||
|
||||
/*
|
||||
if( fnmatch($url_to_exclude, $current_url, FNM_CASEFOLD) ) {
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function ajax_purge_whole_fallback_page_cache() {
|
||||
|
||||
check_ajax_referer( 'ajax-nonce-string', 'security' );
|
||||
|
||||
$return_array = array('status' => 'ok');
|
||||
|
||||
$this->fallback_cache_purge_all();
|
||||
|
||||
$this->objects = $this->main_instance->get_objects();
|
||||
$this->objects['logs']->add_log('cache_controller::ajax_purge_whole_fallback_page_cache', 'Purge whole fallback page cache' );
|
||||
|
||||
$return_array['success_msg'] = __('Fallback cache purged successfully!', 'wp-cloudflare-page-cache');
|
||||
|
||||
die(json_encode($return_array));
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,193 @@
|
|||
<?php
|
||||
/**
|
||||
* The welcome model class for ThemeIsle SDK
|
||||
*
|
||||
* Here's how to hook it in your plugin or theme:
|
||||
* ```php
|
||||
* add_filter( '<product_slug>_welcome_metadata', function() {
|
||||
* return [
|
||||
* 'is_enabled' => <condition_if_pro_available>,
|
||||
* 'pro_name' => 'Product PRO name',
|
||||
* 'logo' => '<path_to_logo>',
|
||||
* 'cta_link' => tsdk_utmify( 'https://link_to_upgrade.with/?discount=<discountCode>')
|
||||
* ];
|
||||
* } );
|
||||
* ```
|
||||
*
|
||||
* @package ThemeIsleSDK
|
||||
* @subpackage Modules
|
||||
* @copyright Copyright (c) 2023, Bogdan Preda
|
||||
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace ThemeisleSDK\Modules;
|
||||
|
||||
// Exit if accessed directly.
|
||||
use ThemeisleSDK\Common\Abstract_Module;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Promotions module for ThemeIsle SDK.
|
||||
*/
|
||||
class Welcome extends Abstract_Module {
|
||||
|
||||
/**
|
||||
* Debug mode.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $debug = false;
|
||||
|
||||
/**
|
||||
* Welcome metadata.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $welcome_discounts = array();
|
||||
|
||||
/**
|
||||
* Check that we can load this module.
|
||||
*
|
||||
* @param \ThemeisleSDK\Product $product The product.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function can_load( $product ) {
|
||||
$this->debug = apply_filters( 'themeisle_sdk_welcome_debug', $this->debug );
|
||||
$welcome_metadata = apply_filters( $product->get_key() . '_welcome_metadata', array() );
|
||||
|
||||
$is_welcome_enabled = $this->is_welcome_meta_valid( $welcome_metadata );
|
||||
|
||||
if ( $is_welcome_enabled ) {
|
||||
$this->welcome_discounts[ $product->get_key() ] = $welcome_metadata;
|
||||
}
|
||||
|
||||
return $this->debug || $is_welcome_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the metadata is valid and the welcome is enabled.
|
||||
*
|
||||
* @param array $welcome_metadata The metadata to validate.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_welcome_meta_valid( $welcome_metadata ) {
|
||||
return ! empty( $welcome_metadata ) && isset( $welcome_metadata['is_enabled'] ) && $welcome_metadata['is_enabled'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the module.
|
||||
*
|
||||
* @param \ThemeisleSDK\Product $product The product.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function load( $product ) {
|
||||
if ( ! current_user_can( 'install_plugins' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->product = $product;
|
||||
if ( ! $this->is_time_to_show_welcome() && $this->debug === false ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_filter( 'themeisle_sdk_registered_notifications', [ $this, 'add_notification' ], 99, 1 );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if it's time to show the welcome.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_time_to_show_welcome() {
|
||||
// if 7 days from install have not passed, don't show the welcome.
|
||||
if ( $this->product->get_install_time() + 7 * DAY_IN_SECONDS > time() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// if 12 days from install have passed, don't show the welcome ( after 7 days for 5 days ).
|
||||
if ( $this->product->get_install_time() + 12 * DAY_IN_SECONDS < time() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the welcome notification.
|
||||
* Will block all other notifications if a welcome notification is present.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_notification( $all_notifications ) {
|
||||
if ( empty( $this->welcome_discounts ) ) {
|
||||
return $all_notifications;
|
||||
}
|
||||
|
||||
if ( ! isset( $this->welcome_discounts[ $this->product->get_key() ] ) ) {
|
||||
return $all_notifications;
|
||||
}
|
||||
|
||||
// filter out the notifications that are not welcome upsells
|
||||
// if we arrived here we will have at least one welcome upsell
|
||||
$all_notifications = array_filter(
|
||||
$all_notifications,
|
||||
function( $notification ) {
|
||||
return strpos( $notification['id'], '_welcome_upsell_flag' ) !== false;
|
||||
}
|
||||
);
|
||||
|
||||
$offer = $this->welcome_discounts[ $this->product->get_key() ];
|
||||
|
||||
$response = [];
|
||||
$logo = isset( $offer['logo'] ) ? $offer['logo'] : '';
|
||||
$pro_name = isset( $offer['pro_name'] ) ? $offer['pro_name'] : $this->product->get_friendly_name() . ' PRO';
|
||||
|
||||
$link = $offer['cta_link'];
|
||||
|
||||
$message = apply_filters( $this->product->get_key() . '_welcome_upsell_message', '<p>You\'ve been using <b>{product}</b> for 7 days now and we appreciate your loyalty! We also want to make sure you\'re getting the most out of our product. That\'s why we\'re offering you a special deal - upgrade to <b>{pro_product}</b> in the next 5 days and receive a discount of <b>up to 30%</b>. <a href="{cta_link}" target="_blank">Upgrade now</a> and unlock all the amazing features of <b>{pro_product}</b>!</p>' );
|
||||
|
||||
$button_submit = apply_filters( $this->product->get_key() . '_feedback_review_button_do', 'Upgrade Now!' );
|
||||
$button_cancel = apply_filters( $this->product->get_key() . '_feedback_review_button_cancel', 'No, thanks.' );
|
||||
$message = str_replace(
|
||||
[ '{product}', '{pro_product}', '{cta_link}' ],
|
||||
[
|
||||
$this->product->get_friendly_name(),
|
||||
$pro_name,
|
||||
$link,
|
||||
],
|
||||
$message
|
||||
);
|
||||
|
||||
$all_notifications[] = [
|
||||
'id' => $this->product->get_key() . '_welcome_upsell_flag',
|
||||
'message' => $message,
|
||||
'img_src' => $logo,
|
||||
'ctas' => [
|
||||
'confirm' => [
|
||||
'link' => $link,
|
||||
'text' => $button_submit,
|
||||
],
|
||||
'cancel' => [
|
||||
'link' => '#',
|
||||
'text' => $button_cancel,
|
||||
],
|
||||
],
|
||||
'type' => 'info',
|
||||
];
|
||||
|
||||
$key = array_rand( $all_notifications );
|
||||
$response[] = $all_notifications[ $key ];
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
// autoload_files.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(__DIR__);
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'f3e742daca6ecc1d4ff0a2b5cf792c05' => $vendorDir . '/codeinwp/themeisle-sdk/load.php',
|
||||
);
|
|
@ -0,0 +1,224 @@
|
|||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
|
||||
|
||||
class SWCFPC_Varnish
|
||||
{
|
||||
|
||||
private $main_instance = null;
|
||||
private $objects = false;
|
||||
private $hostname = 'localhost';
|
||||
private $port = 6081;
|
||||
private $single_purge_method = 'PURGE';
|
||||
private $whole_purge_method = 'PURGE';
|
||||
private $provider = '';
|
||||
|
||||
function __construct( $main_instance )
|
||||
{
|
||||
|
||||
$this->main_instance = $main_instance;
|
||||
|
||||
$this->hostname = $this->main_instance->get_single_config('cf_varnish_hostname', 'localhost');
|
||||
$this->port = $this->main_instance->get_single_config('cf_varnish_port', 6081);
|
||||
$this->single_purge_method = $this->main_instance->get_single_config('cf_varnish_purge_method', 'PURGE');
|
||||
$this->whole_purge_method = $this->main_instance->get_single_config('cf_varnish_purge_all_method', 'PURGE');
|
||||
|
||||
if( $this->main_instance->get_single_config('cf_varnish_cw', 0) > 0 )
|
||||
$this->provider = 'cloudways';
|
||||
|
||||
$this->actions();
|
||||
|
||||
}
|
||||
|
||||
|
||||
function actions() {
|
||||
|
||||
// Ajax clear whole fallback cache
|
||||
add_action( 'wp_ajax_swcfpc_purge_varnish_cache', array($this, 'ajax_purge_whole_varnish_cache') );
|
||||
|
||||
}
|
||||
|
||||
|
||||
function purge_urls( $urls ) {
|
||||
|
||||
$error = '';
|
||||
|
||||
if( is_array($urls) && count($urls) > 0 ) {
|
||||
|
||||
foreach($urls as $single_url)
|
||||
$this->purge_single_url_cache( $single_url, $error );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function purge_single_url_cache( $url, &$error, $purge_all=false ) {
|
||||
|
||||
$this->objects = $this->main_instance->get_objects();
|
||||
|
||||
if( $this->hostname == null || $this->port == null ) {
|
||||
$this->objects['logs']->add_log('varnish::purge_single_url_cache', 'Invalid hostname or port' );
|
||||
$error = __('Invalid hostname or port', 'wp-cloudflare-page-cache');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Varnish purge request on Cloudways
|
||||
if( $this->provider == 'cloudways' ) {
|
||||
|
||||
$this->single_purge_method = 'URLPURGE';
|
||||
$this->whole_purge_method = 'PURGE';
|
||||
|
||||
}
|
||||
|
||||
$parseUrl = $purge_all ? parse_url( site_url() ) : parse_url($url);
|
||||
|
||||
// Determine the schema
|
||||
$schema = 'http://';
|
||||
if (isset($parseUrl['scheme'])) {
|
||||
$schema = "{$parseUrl['scheme']}://";
|
||||
}
|
||||
|
||||
if ($purge_all) {
|
||||
|
||||
if( $this->provider == 'cloudways' ) {
|
||||
$finalURL = sprintf('%s%s%s', $schema, $this->hostname, '/.*');
|
||||
}
|
||||
else {
|
||||
$finalURL = sprintf('%s%s:%d%s', $schema, $this->hostname, $this->port, '/*');
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// Determine the path
|
||||
$path = '';
|
||||
if (isset($parseUrl['path'])) {
|
||||
$path = $parseUrl['path'];
|
||||
}
|
||||
|
||||
if( $this->provider == 'cloudways' ) {
|
||||
$finalURL = sprintf('%s%s%s', $schema, $this->hostname, $path);
|
||||
}
|
||||
else {
|
||||
$finalURL = sprintf('%s%s:%d%s', $schema, $this->hostname, $this->port, $path);
|
||||
}
|
||||
|
||||
if (!empty($parseUrl['query'])) {
|
||||
$finalURL .= "?{$parseUrl['query']}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$request_args = array(
|
||||
'method' => $purge_all ? $this->whole_purge_method : $this->single_purge_method,
|
||||
'headers' => array(
|
||||
'Host' => $parseUrl['host'],
|
||||
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
|
||||
),
|
||||
'sslverify' => false,
|
||||
);
|
||||
|
||||
$this->objects['logs']->add_log('varnish::purge_single_url_cache', "Send purging request to {$finalURL}");
|
||||
|
||||
if( $this->objects['logs']->get_verbosity() == SWCFPC_LOGS_HIGH_VERBOSITY )
|
||||
$this->objects['logs']->add_log('varnish::purge_single_url_cache', 'Request args '.print_r($request_args, true));
|
||||
|
||||
// Send purge request to Varnish
|
||||
$response = wp_remote_request($finalURL, $request_args);
|
||||
|
||||
if( $this->objects['logs']->get_verbosity() == SWCFPC_LOGS_HIGH_VERBOSITY )
|
||||
$this->objects['logs']->add_log('varnish::purge_single_url_cache', 'Response: '.print_r($response, true));
|
||||
|
||||
if ( is_wp_error($response) || $response['response']['code'] != '200' ) {
|
||||
|
||||
if ($schema === 'https://') {
|
||||
$schema = 'http://';
|
||||
} else {
|
||||
$schema = 'https://';
|
||||
}
|
||||
|
||||
if( is_wp_error($response) )
|
||||
$this->objects['logs']->add_log('varnish::purge_single_url_cache', 'Error: ' . $response->get_error_message() . " - Retry using {$schema}");
|
||||
else
|
||||
$this->objects['logs']->add_log('varnish::purge_single_url_cache', "Response code {$response['response']['code']} - Retry using {$schema}");
|
||||
|
||||
if ($purge_all) {
|
||||
|
||||
if( $this->provider == 'cloudways' ) {
|
||||
$finalURL = sprintf('%s%s%s', $schema, $this->hostname, '/.*');
|
||||
}
|
||||
else {
|
||||
$finalURL = sprintf('%s%s:%d%s', $schema, $this->hostname, $this->port, '/*');
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if( $this->provider == 'cloudways' ) {
|
||||
$finalURL = sprintf('%s%s%s', $schema, $this->hostname, $path);
|
||||
}
|
||||
else {
|
||||
$finalURL = sprintf('%s%s:%d%s', $schema, $this->hostname, $this->port, $path);
|
||||
}
|
||||
|
||||
if (!empty($parseUrl['query'])) {
|
||||
$finalURL .= "?{$parseUrl['query']}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->objects['logs']->add_log('varnish::purge_single_url_cache', "Send purging request to {$finalURL}");
|
||||
|
||||
if( $this->objects['logs']->get_verbosity() == SWCFPC_LOGS_HIGH_VERBOSITY )
|
||||
$this->objects['logs']->add_log('varnish::purge_single_url_cache', 'Request args '.print_r($request_args, true));
|
||||
|
||||
// Send new purge request to Varnish
|
||||
$response = wp_remote_request($finalURL, $request_args);
|
||||
|
||||
if( $this->objects['logs']->get_verbosity() == SWCFPC_LOGS_HIGH_VERBOSITY )
|
||||
$this->objects['logs']->add_log('varnish::purge_single_url_cache', 'Response: '.print_r($response, true));
|
||||
|
||||
if (is_wp_error($response)) {
|
||||
$error = $response->get_error_message();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->objects['logs']->add_log('varnish::purge_single_url_cache', "Cache purged for URL {$url}" );
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function purge_whole_cache( &$error ) {
|
||||
|
||||
$error = '';
|
||||
|
||||
return $this->purge_single_url_cache( '', $error, true );
|
||||
|
||||
}
|
||||
|
||||
|
||||
function ajax_purge_whole_varnish_cache() {
|
||||
|
||||
check_ajax_referer( 'ajax-nonce-string', 'security' );
|
||||
|
||||
$return_array = array('status' => 'ok');
|
||||
$error = '';
|
||||
|
||||
if( ! $this->purge_whole_cache( $error) ) {
|
||||
$return_array['status'] = 'error';
|
||||
$return_array['error'] = $error;
|
||||
die(json_encode($return_array));
|
||||
}
|
||||
|
||||
$this->objects['logs']->add_log('varnish::ajax_purge_whole_varnish_cache', 'Purge whole Varnish cache' );
|
||||
|
||||
$return_array['success_msg'] = __('Varnish cache purged successfully!', 'wp-cloudflare-page-cache');
|
||||
|
||||
die(json_encode($return_array));
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
const wpPreset = require( '@wordpress/postcss-plugins-preset' );
|
||||
|
||||
module.exports = {
|
||||
plugins: [
|
||||
...wpPreset,
|
||||
require( 'postcss-custom-media' )(), // Custom media queries: https://www.npmjs.com/package/postcss-custom-media
|
||||
require( 'postcss-combine-media-query' )(), // Combine media queries: https://www.npmjs.com/package/postcss-combine-media-query
|
||||
require( 'postcss-sort-media-queries' )() // Sort media queries: https://www.npmjs.com/package/postcss-sort-media-queries
|
||||
]
|
||||
};
|
After Width: | Height: | Size: 4.0 KiB |
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
// autoload.php @generated by Composer
|
||||
|
||||
if (PHP_VERSION_ID < 50600) {
|
||||
if (!headers_sent()) {
|
||||
header('HTTP/1.1 500 Internal Server Error');
|
||||
}
|
||||
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
|
||||
if (!ini_get('display_errors')) {
|
||||
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
|
||||
fwrite(STDERR, $err);
|
||||
} elseif (!headers_sent()) {
|
||||
echo $err;
|
||||
}
|
||||
}
|
||||
trigger_error(
|
||||
$err,
|
||||
E_USER_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit718cd62be4fc0d1c7deeabef60d4e8b7::getLoader();
|
|
@ -0,0 +1 @@
|
|||
<?php // Silence is golden
|
|
@ -0,0 +1,942 @@
|
|||
"use strict"
|
||||
|
||||
let swcfpc_toolbar_cache_status_tries = 0;
|
||||
let swcfpc_toolbar_cache_status_interval = null;
|
||||
|
||||
function swcfpc_handle_conditional_settings(mainOption) {
|
||||
// Check if the checked option has value > 0 i.e. YES || Enable selected
|
||||
if (parseInt(mainOption.value) > 0) {
|
||||
// True value is selected
|
||||
// Show the items with the class name present in `data-mainoption`
|
||||
if (document.querySelectorAll(`.${mainOption.dataset.mainoption}`).length > 0) {
|
||||
document.querySelectorAll(`.${mainOption.dataset.mainoption}`).forEach((item) => {
|
||||
if (item.classList.contains('swcfpc_hide')) {
|
||||
item.classList.remove('swcfpc_hide')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Hide all the options that should be hidden when the main option is TRUE
|
||||
// i.e. Hide all items with `data-mainoption_not` in them
|
||||
if (document.querySelectorAll(`.${mainOption.dataset.mainoption}_not`).length > 0) {
|
||||
// Loop through the items and show all the other settings are should be shown when the main item is not enabled
|
||||
document.querySelectorAll(`.${mainOption.dataset.mainoption}_not`).forEach((item) => {
|
||||
item.classList.add('swcfpc_hide')
|
||||
})
|
||||
}
|
||||
|
||||
} else { // FALSE value is selected
|
||||
// Hide the items with class name = `data-mainoption`
|
||||
if (document.querySelectorAll(`.${mainOption.dataset.mainoption}`).length > 0) {
|
||||
document.querySelectorAll(`.${mainOption.dataset.mainoption}`).forEach((item) => {
|
||||
item.classList.add('swcfpc_hide')
|
||||
})
|
||||
}
|
||||
|
||||
// Show the items with class = `data-mainoption_not`
|
||||
if (document.querySelectorAll(`.${mainOption.dataset.mainoption}_not`).length > 0) {
|
||||
document.querySelectorAll(`.${mainOption.dataset.mainoption}_not`).forEach((item) => {
|
||||
if (item.classList.contains('swcfpc_hide')) {
|
||||
item.classList.remove('swcfpc_hide')
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function swcfpc_lock_screen() {
|
||||
if (!document.querySelector('.swcfpc_please_wait')) {
|
||||
const inputTypeSubmit = document.querySelectorAll('input[type=submit]')
|
||||
const inputTypeBtn = document.querySelectorAll('input[type=submit]')
|
||||
const anchorTags = document.querySelectorAll('a')
|
||||
|
||||
inputTypeSubmit.forEach((item) => {
|
||||
item.classList.add('swcfpc_hide')
|
||||
})
|
||||
|
||||
inputTypeBtn.forEach((item) => {
|
||||
item.classList.add('swcfpc_hide')
|
||||
})
|
||||
|
||||
anchorTags.forEach((item) => {
|
||||
item.classList.add('swcfpc_hide')
|
||||
})
|
||||
|
||||
const waitDiv = document.createElement('div')
|
||||
waitDiv.classList.add('swcfpc_please_wait')
|
||||
document.body.prepend(waitDiv)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function swcfpc_unlock_screen() {
|
||||
const inputTypeSubmit = document.querySelectorAll('input[type=submit]')
|
||||
const inputTypeBtn = document.querySelectorAll('input[type=submit]')
|
||||
const anchorTags = document.querySelectorAll('a')
|
||||
|
||||
inputTypeSubmit.forEach((item) => {
|
||||
item.classList.remove('swcfpc_hide')
|
||||
})
|
||||
|
||||
inputTypeBtn.forEach((item) => {
|
||||
item.classList.remove('swcfpc_hide')
|
||||
})
|
||||
|
||||
anchorTags.forEach((item) => {
|
||||
item.classList.remove('swcfpc_hide')
|
||||
})
|
||||
|
||||
document.querySelector('.swcfpc_please_wait').remove()
|
||||
}
|
||||
|
||||
|
||||
function swcfpc_redirect_to_page(url) {
|
||||
window.location = url
|
||||
}
|
||||
|
||||
|
||||
function swcfpc_refresh_page() {
|
||||
window.location.reload()
|
||||
}
|
||||
|
||||
|
||||
function swcfpc_display_ok_dialog(title, content, width, height, type, subtitle, button_name, callback, callback_first_parameter) {
|
||||
|
||||
width = (typeof width === "undefined" || width == null) ? 350 : parseInt(width)
|
||||
height = (typeof height === "undefined" || height == null) ? 300 : parseInt(height)
|
||||
type = (typeof type === "undefined") ? null : type
|
||||
subtitle = (typeof subtitle === "undefined") ? null : subtitle
|
||||
button_name = (typeof button_name === "undefined") ? "Close" : button_name
|
||||
callback = (typeof callback === "undefined") ? null : callback
|
||||
callback_first_parameter = (typeof callback_first_parameter === "undefined") ? null : callback_first_parameter
|
||||
|
||||
let icon = "success"
|
||||
|
||||
if (type === "warning")
|
||||
icon = "warning"
|
||||
else if (type === "error")
|
||||
icon = "error"
|
||||
else if (type === "info")
|
||||
icon = "info"
|
||||
else if (type === "question")
|
||||
icon = "question"
|
||||
|
||||
if (callback == null) {
|
||||
|
||||
Swal.fire({
|
||||
title: (subtitle !== null) ? subtitle : '',
|
||||
html: content,
|
||||
icon: icon,
|
||||
confirmButtonText: button_name
|
||||
})
|
||||
|
||||
} else {
|
||||
|
||||
Swal.fire({
|
||||
title: (subtitle !== null) ? subtitle : '',
|
||||
html: content,
|
||||
icon: icon,
|
||||
confirmButtonText: button_name,
|
||||
willClose: () => {
|
||||
|
||||
if (callback_first_parameter != null) {
|
||||
callback(callback_first_parameter)
|
||||
}
|
||||
else {
|
||||
callback()
|
||||
}
|
||||
|
||||
}
|
||||
}).then((result) => {
|
||||
|
||||
if (result.isConfirmed) {
|
||||
|
||||
if (callback_first_parameter != null) {
|
||||
callback(callback_first_parameter)
|
||||
}
|
||||
else {
|
||||
callback()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
async function swcfpc_purge_varnish_cache() {
|
||||
try {
|
||||
const ajax_nonce = document.getElementById('swcfpc-ajax-nonce').innerText
|
||||
|
||||
swcfpc_lock_screen()
|
||||
|
||||
const response = await fetch(swcfpc_ajax_url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
|
||||
},
|
||||
body: `action=swcfpc_purge_varnish_cache&security=${ajax_nonce}`,
|
||||
credentials: 'same-origin',
|
||||
timeout: 10000
|
||||
})
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
swcfpc_unlock_screen()
|
||||
|
||||
if (data.status === 'ok') {
|
||||
swcfpc_display_ok_dialog("Success", `${data.success_msg}`, null, null, "success")
|
||||
} else {
|
||||
swcfpc_display_ok_dialog("Error", `${data.error}`, null, null, "error")
|
||||
}
|
||||
} else {
|
||||
console.error(`Error: ${response.status} ${response.statusText}`)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
} catch (err) {
|
||||
alert(`Error: ${err.status} ${err.message}`)
|
||||
console.error(err)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function swcfpc_purge_fallback_page_cache() {
|
||||
try {
|
||||
const ajax_nonce = document.getElementById('swcfpc-ajax-nonce').innerText
|
||||
swcfpc_lock_screen()
|
||||
|
||||
const response = await fetch(swcfpc_ajax_url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
|
||||
},
|
||||
body: `action=swcfpc_purge_fallback_page_cache&security=${ajax_nonce}`,
|
||||
credentials: 'same-origin',
|
||||
timeout: 10000
|
||||
})
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
swcfpc_unlock_screen()
|
||||
|
||||
if (data.status === 'ok') {
|
||||
swcfpc_display_ok_dialog("Success", `${data.success_msg}`, null, null, "success")
|
||||
} else {
|
||||
swcfpc_display_ok_dialog("Error", `${data.error}`, null, null, "error")
|
||||
}
|
||||
} else {
|
||||
console.error(`Error: ${response.status} ${response.statusText}`)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
} catch (err) {
|
||||
alert(`Error: ${err.status} ${err.message}`)
|
||||
console.error(err)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function swcfpc_force_purge_everything() {
|
||||
try {
|
||||
const ajax_nonce = document.getElementById('swcfpc-ajax-nonce').innerText
|
||||
swcfpc_lock_screen()
|
||||
|
||||
const response = await fetch(swcfpc_ajax_url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
|
||||
},
|
||||
body: `action=swcfpc_purge_everything&security=${ajax_nonce}`,
|
||||
credentials: 'same-origin',
|
||||
timeout: 10000
|
||||
})
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
swcfpc_unlock_screen()
|
||||
|
||||
if (data.status === 'ok') {
|
||||
swcfpc_display_ok_dialog("Success", `${data.success_msg}`, null, null, "success")
|
||||
} else {
|
||||
swcfpc_display_ok_dialog("Error", `${data.error}`, null, null, "error")
|
||||
}
|
||||
} else {
|
||||
console.error(`Error: ${response.status} ${response.statusText}`)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
} catch (err) {
|
||||
alert(`Error: ${err.status} ${err.message}`)
|
||||
console.error(err)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function swcfpc_purge_whole_cache() {
|
||||
try {
|
||||
const ajax_nonce = document.getElementById('swcfpc-ajax-nonce').innerText
|
||||
swcfpc_lock_screen()
|
||||
|
||||
const response = await fetch(swcfpc_ajax_url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
|
||||
},
|
||||
body: `action=swcfpc_purge_whole_cache&security=${ajax_nonce}`,
|
||||
credentials: 'same-origin',
|
||||
timeout: 10000
|
||||
})
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
swcfpc_unlock_screen()
|
||||
|
||||
if (data.status === 'ok') {
|
||||
swcfpc_display_ok_dialog("Success", `${data.success_msg}`, null, null, "success")
|
||||
} else {
|
||||
swcfpc_display_ok_dialog("Error", `${data.error}`, null, null, "error")
|
||||
}
|
||||
} else {
|
||||
console.error(`Error: ${response.status} ${response.statusText}`)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
} catch (err) {
|
||||
alert(`Error: ${err.status} ${err.message}`)
|
||||
console.error(err)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function swcfpc_import_config_file(config_file) {
|
||||
try {
|
||||
const ajax_nonce = document.getElementById('swcfpc-ajax-nonce').innerText
|
||||
const dataJSON = encodeURIComponent(JSON.stringify({
|
||||
"config_file": config_file
|
||||
}))
|
||||
|
||||
swcfpc_lock_screen()
|
||||
|
||||
const response = await fetch(swcfpc_ajax_url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
|
||||
},
|
||||
body: `action=swcfpc_import_config_file&security=${ajax_nonce}&data=${dataJSON}`,
|
||||
credentials: 'same-origin',
|
||||
timeout: 10000
|
||||
})
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
swcfpc_unlock_screen()
|
||||
|
||||
if (data.status === 'ok') {
|
||||
swcfpc_display_ok_dialog("Success", `${data.success_msg}`, null, null, "success", null, "Ok", swcfpc_refresh_page)
|
||||
} else {
|
||||
swcfpc_display_ok_dialog("Error", `${data.error}`, null, null, "error")
|
||||
}
|
||||
} else {
|
||||
console.error(`Error: ${response.status} ${response.statusText}`)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
} catch (err) {
|
||||
alert(`Error: ${err.status} ${err.message}`)
|
||||
console.error(err)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function swcfpc_purge_single_post_cache(post_id) {
|
||||
try {
|
||||
const ajax_nonce = document.getElementById('swcfpc-ajax-nonce').innerText
|
||||
const dataJSON = encodeURIComponent(JSON.stringify({
|
||||
"post_id": post_id
|
||||
}))
|
||||
|
||||
swcfpc_lock_screen()
|
||||
|
||||
const response = await fetch(swcfpc_ajax_url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
|
||||
},
|
||||
body: `action=swcfpc_purge_single_post_cache&security=${ajax_nonce}&data=${dataJSON}`,
|
||||
credentials: 'same-origin',
|
||||
timeout: 10000
|
||||
})
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
swcfpc_unlock_screen()
|
||||
|
||||
if (data.status === 'ok') {
|
||||
swcfpc_display_ok_dialog("Success", `${data.success_msg}`, null, null, "success")
|
||||
} else {
|
||||
swcfpc_display_ok_dialog("Error", `${data.error}`, null, null, "error")
|
||||
}
|
||||
} else {
|
||||
console.error(`Error: ${response.status} ${response.statusText}`)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
} catch (err) {
|
||||
alert(`Error: ${err.status} ${err.message}`)
|
||||
console.error(err)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function swcfpc_test_page_cache() {
|
||||
try {
|
||||
const ajax_nonce = document.getElementById('swcfpc-ajax-nonce').innerText
|
||||
swcfpc_lock_screen()
|
||||
|
||||
const response = await fetch(swcfpc_ajax_url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
|
||||
},
|
||||
body: `action=swcfpc_test_page_cache&security=${ajax_nonce}`,
|
||||
credentials: 'same-origin',
|
||||
timeout: 10000
|
||||
})
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
swcfpc_unlock_screen()
|
||||
|
||||
if (data.status === 'ok') {
|
||||
swcfpc_display_ok_dialog("Success", `${data.success_msg}`, null, null, "success")
|
||||
} else {
|
||||
swcfpc_display_ok_dialog("Error", `${data.error}`, null, null, "error")
|
||||
}
|
||||
} else {
|
||||
console.error(`Error: ${response.status} ${response.statusText}`)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
} catch (err) {
|
||||
alert(`Error: ${err.status} ${err.message}`)
|
||||
console.error(err)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function swcfpc_enable_page_cache() {
|
||||
try {
|
||||
const ajax_nonce = document.getElementById('swcfpc-ajax-nonce').innerText
|
||||
swcfpc_lock_screen()
|
||||
|
||||
const response = await fetch(swcfpc_ajax_url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
|
||||
},
|
||||
body: `action=swcfpc_enable_page_cache&security=${ajax_nonce}`,
|
||||
credentials: 'same-origin',
|
||||
timeout: 10000
|
||||
})
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
swcfpc_unlock_screen()
|
||||
|
||||
if (data.status === 'ok') {
|
||||
swcfpc_display_ok_dialog("Success", `${data.success_msg}`, null, null, "success", null, "Ok", swcfpc_refresh_page)
|
||||
} else {
|
||||
swcfpc_display_ok_dialog("Error", `${data.error}`, null, null, "error")
|
||||
}
|
||||
} else {
|
||||
console.error(`Error: ${response.status} ${response.statusText}`)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
} catch (err) {
|
||||
alert(`Error: ${err.status} ${err.message}`)
|
||||
console.error(err)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function swcfpc_disable_page_cache() {
|
||||
try {
|
||||
const ajax_nonce = document.getElementById('swcfpc-ajax-nonce').innerText
|
||||
swcfpc_lock_screen()
|
||||
|
||||
const response = await fetch(swcfpc_ajax_url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
|
||||
},
|
||||
body: `action=swcfpc_disable_page_cache&security=${ajax_nonce}`,
|
||||
credentials: 'same-origin',
|
||||
timeout: 10000
|
||||
})
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
swcfpc_unlock_screen()
|
||||
|
||||
if (data.status === 'ok') {
|
||||
swcfpc_display_ok_dialog("Success", `${data.success_msg}`, null, null, "success", null, "Ok", swcfpc_refresh_page)
|
||||
} else {
|
||||
swcfpc_display_ok_dialog("Error", `${data.error}`, null, null, "error")
|
||||
}
|
||||
} else {
|
||||
console.error(`Error: ${response.status} ${response.statusText}`)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
} catch (err) {
|
||||
alert(`Error: ${err.status} ${err.message}`)
|
||||
console.error(err)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function swcfpc_reset_all() {
|
||||
try {
|
||||
const ajax_nonce = document.getElementById('swcfpc-ajax-nonce').innerText
|
||||
swcfpc_lock_screen()
|
||||
|
||||
const response = await fetch(swcfpc_ajax_url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
|
||||
},
|
||||
body: `action=swcfpc_reset_all&security=${ajax_nonce}`,
|
||||
credentials: 'same-origin',
|
||||
timeout: 10000
|
||||
})
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
swcfpc_unlock_screen()
|
||||
|
||||
if (data.status === 'ok') {
|
||||
swcfpc_display_ok_dialog("Success", `${data.success_msg}`, null, null, "success", null, "Ok", swcfpc_refresh_page)
|
||||
} else {
|
||||
swcfpc_display_ok_dialog("Error", `${data.error}`, null, null, "error")
|
||||
}
|
||||
} else {
|
||||
console.error(`Error: ${response.status} ${response.statusText}`)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
} catch (err) {
|
||||
alert(`Error: ${err.status} ${err.message}`)
|
||||
console.error(err)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function swcfpc_clear_logs() {
|
||||
try {
|
||||
const ajax_nonce = document.getElementById('swcfpc-ajax-nonce').innerText
|
||||
swcfpc_lock_screen()
|
||||
|
||||
const response = await fetch(swcfpc_ajax_url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
|
||||
},
|
||||
body: `action=swcfpc_clear_logs&security=${ajax_nonce}`,
|
||||
credentials: 'same-origin',
|
||||
timeout: 10000
|
||||
})
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
swcfpc_unlock_screen()
|
||||
|
||||
if (data.status === 'ok') {
|
||||
swcfpc_display_ok_dialog("Success", `${data.success_msg}`, null, null, "success")
|
||||
} else {
|
||||
swcfpc_display_ok_dialog("Error", `${data.error}`, null, null, "error")
|
||||
}
|
||||
} else {
|
||||
console.error(`Error: ${response.status} ${response.statusText}`)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
} catch (err) {
|
||||
alert(`Error: ${err.status} ${err.message}`)
|
||||
console.error(err)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function swcfpc_start_preloader() {
|
||||
try {
|
||||
const ajax_nonce = document.getElementById('swcfpc-ajax-nonce').innerText
|
||||
swcfpc_lock_screen()
|
||||
|
||||
const response = await fetch(swcfpc_ajax_url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
|
||||
},
|
||||
body: `action=swcfpc_preloader_start&security=${ajax_nonce}`,
|
||||
credentials: 'same-origin',
|
||||
timeout: 10000
|
||||
})
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
swcfpc_unlock_screen()
|
||||
|
||||
if (data.status === 'ok') {
|
||||
swcfpc_display_ok_dialog("Success", `${data.success_msg}`, null, null, "success")
|
||||
} else {
|
||||
swcfpc_display_ok_dialog("Error", `${data.error}`, null, null, "error")
|
||||
}
|
||||
} else {
|
||||
console.error(`Error: ${response.status} ${response.statusText}`)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
} catch (err) {
|
||||
alert(`Error: ${err.status} ${err.message}`)
|
||||
console.error(err)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function swcfpc_unlock_preloader() {
|
||||
try {
|
||||
const ajax_nonce = document.getElementById('swcfpc-ajax-nonce').innerText
|
||||
swcfpc_lock_screen()
|
||||
|
||||
const response = await fetch(swcfpc_ajax_url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
|
||||
},
|
||||
body: `action=swcfpc_preloader_unlock&security=${ajax_nonce}`,
|
||||
credentials: 'same-origin',
|
||||
timeout: 10000
|
||||
})
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
swcfpc_unlock_screen()
|
||||
|
||||
if (data.status === 'ok') {
|
||||
swcfpc_display_ok_dialog("Success", `${data.success_msg}`, null, null, "success")
|
||||
} else {
|
||||
swcfpc_display_ok_dialog("Error", `${data.error}`, null, null, "error")
|
||||
}
|
||||
} else {
|
||||
console.error(`Error: ${response.status} ${response.statusText}`)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
} catch (err) {
|
||||
alert(`Error: ${err.status} ${err.message}`)
|
||||
console.error(err)
|
||||
swcfpc_unlock_screen()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Handling the Nav Tabs inside settings page
|
||||
**/
|
||||
// Checking if selector exists
|
||||
if (document.querySelector('#swcfpc_tab_links .nav-tab:not(.swcfpc-external)')) {
|
||||
// Fetch all the selectors with same target
|
||||
const navTabs = document.querySelectorAll('#swcfpc_tab_links .nav-tab:not(.swcfpc-external)')
|
||||
|
||||
// Start forEach loop on all the nodes selected
|
||||
navTabs.forEach((navItem) => {
|
||||
// Add click event listener on all the items
|
||||
navItem.addEventListener('click', (e) => {
|
||||
e.preventDefault()
|
||||
|
||||
const id = e.target.dataset.tab
|
||||
|
||||
if (typeof id === undefined) {
|
||||
return true
|
||||
}
|
||||
|
||||
// Loop again through the selected nodes to remove .nav-tab-active if it exists anywhere
|
||||
navTabs.forEach((navItem) => {
|
||||
if (navItem.classList.contains('nav-tab-active')) {
|
||||
navItem.classList.remove('nav-tab-active')
|
||||
}
|
||||
})
|
||||
|
||||
// Add .nav-tab-active to the clicked Item
|
||||
e.target.classList.add('nav-tab-active')
|
||||
|
||||
// Loop through all items with .swcfpc_tab and if any of those items has .active, remove that
|
||||
document.querySelectorAll('.swcfpc_tab').forEach((item) => {
|
||||
if (item.classList.contains('active')) {
|
||||
item.classList.remove('active')
|
||||
}
|
||||
})
|
||||
|
||||
// Add .swcfpc_tab to the id selected
|
||||
document.getElementById(id).classList.add('active')
|
||||
|
||||
const generalSubmitBtn = document.querySelector('input[name=swcfpc_submit_general]')
|
||||
|
||||
if (id === 'faq') {
|
||||
generalSubmitBtn.classList.add('swcfpc_hide')
|
||||
} else if (generalSubmitBtn.classList.contains('swcfpc_hide')) {
|
||||
generalSubmitBtn.classList.remove('swcfpc_hide')
|
||||
}
|
||||
|
||||
// Add the id value to the hidden input field
|
||||
document.querySelector('input[name=swcfpc_tab]').value = id
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function swcfpc_init_accordions() {
|
||||
|
||||
const acc = document.getElementsByClassName("swcfpc_faq_question");
|
||||
|
||||
for (let i = 0; i < acc.length; i++) {
|
||||
acc[i].addEventListener("click", function () {
|
||||
/* Toggle between adding and removing the "active" class,
|
||||
to highlight the button that controls the panel */
|
||||
this.classList.toggle("active");
|
||||
|
||||
/* Toggle between hiding and showing the active panel */
|
||||
const panel = this.nextElementSibling;
|
||||
if (panel.style.display === "block") {
|
||||
panel.style.display = "none";
|
||||
} else {
|
||||
panel.style.display = "block";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function swcfpc_update_toolbar_cache_status() {
|
||||
|
||||
if (document.getElementById('wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-container') != null) {
|
||||
|
||||
if (swcfpc_cache_enabled == 0) {
|
||||
document.getElementById('wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-container').classList.remove('bullet-green');
|
||||
document.getElementById('wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-container').classList.add('bullet-red');
|
||||
}
|
||||
else {
|
||||
document.getElementById('wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-container').classList.remove('bullet-red');
|
||||
document.getElementById('wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-container').classList.add('bullet-green');
|
||||
}
|
||||
|
||||
clearInterval(swcfpc_toolbar_cache_status_interval);
|
||||
|
||||
} else {
|
||||
|
||||
swcfpc_toolbar_cache_status_tries++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
document.addEventListener('DOMContentLoaded', (event) => {
|
||||
|
||||
if (typeof swcfpc_cache_enabled == 'undefined') {
|
||||
let swcfpc_cache_enabled = 0;
|
||||
}
|
||||
|
||||
if (document.getElementById("swcfpc_main_content") !== null) {
|
||||
|
||||
swcfpc_cache_enabled = parseInt(document.getElementById("swcfpc_main_content").getAttribute("data-cache_enabled"));
|
||||
|
||||
if (swcfpc_cache_enabled == null || isNaN(swcfpc_cache_enabled))
|
||||
swcfpc_cache_enabled = 0;
|
||||
|
||||
}
|
||||
|
||||
if (document.getElementById('swcfpc_clear_logs')) {
|
||||
document.getElementById('swcfpc_clear_logs').addEventListener('click', (e) => {
|
||||
e.preventDefault()
|
||||
swcfpc_clear_logs()
|
||||
})
|
||||
}
|
||||
|
||||
if (document.getElementById('swcfpc_start_preloader')) {
|
||||
document.getElementById('swcfpc_start_preloader').addEventListener('click', (e) => {
|
||||
e.preventDefault()
|
||||
swcfpc_start_preloader()
|
||||
})
|
||||
}
|
||||
|
||||
if (document.getElementById('swcfpc_unlock_preloader')) {
|
||||
document.getElementById('swcfpc_unlock_preloader').addEventListener('click', (e) => {
|
||||
e.preventDefault()
|
||||
swcfpc_unlock_preloader()
|
||||
})
|
||||
}
|
||||
|
||||
if (document.querySelector('#swcfpc_import_config_start')) {
|
||||
document.querySelector('#swcfpc_import_config_start').addEventListener('click', (e) => {
|
||||
e.preventDefault()
|
||||
const config_file = document.querySelector('#swcfpc_import_config_content').value
|
||||
swcfpc_import_config_file(config_file)
|
||||
})
|
||||
}
|
||||
|
||||
if (document.getElementById('swcfpc_fallback_page_cache_purge')) {
|
||||
document.getElementById('swcfpc_fallback_page_cache_purge').addEventListener('click', (e) => {
|
||||
e.preventDefault()
|
||||
swcfpc_purge_fallback_page_cache()
|
||||
})
|
||||
}
|
||||
|
||||
if (document.querySelector('#wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-purge-all a')) {
|
||||
document.querySelector('#wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-purge-all a').addEventListener('click', (e) => {
|
||||
e.preventDefault()
|
||||
swcfpc_purge_whole_cache()
|
||||
})
|
||||
}
|
||||
|
||||
if (document.querySelector('#wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-purge-single a')) {
|
||||
document.querySelector('#wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-purge-single a').addEventListener('click', (e) => {
|
||||
e.preventDefault()
|
||||
const post_id = e.target.hash.replace('#', '')
|
||||
swcfpc_purge_single_post_cache(post_id)
|
||||
})
|
||||
}
|
||||
|
||||
if (document.querySelector('.swcfpc_action_row_single_post_cache_purge')) {
|
||||
document.querySelectorAll('.swcfpc_action_row_single_post_cache_purge').forEach((item) => {
|
||||
item.addEventListener('click', (e) => {
|
||||
e.preventDefault()
|
||||
const post_id = e.target.dataset.post_id
|
||||
swcfpc_purge_single_post_cache(post_id)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
if (document.getElementById('swcfpc_varnish_cache_purge')) {
|
||||
document.getElementById('swcfpc_varnish_cache_purge').addEventListener('click', (e) => {
|
||||
e.preventDefault()
|
||||
swcfpc_purge_varnish_cache()
|
||||
})
|
||||
}
|
||||
|
||||
if (document.getElementById('swcfpc_form_purge_cache')) {
|
||||
document.getElementById('swcfpc_form_purge_cache').addEventListener('submit', (e) => {
|
||||
e.preventDefault()
|
||||
swcfpc_purge_whole_cache()
|
||||
})
|
||||
}
|
||||
|
||||
if (document.getElementById('swcfpc_purge_cache_everything')) {
|
||||
document.getElementById('swcfpc_purge_cache_everything').addEventListener('click', (e) => {
|
||||
e.preventDefault()
|
||||
swcfpc_force_purge_everything()
|
||||
})
|
||||
}
|
||||
|
||||
if (document.querySelector('#wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-force-purge-everything a')) {
|
||||
document.querySelector('#wp-admin-bar-wp-cloudflare-super-page-cache-toolbar-force-purge-everything a').addEventListener('click', (e) => {
|
||||
e.preventDefault()
|
||||
swcfpc_force_purge_everything()
|
||||
})
|
||||
}
|
||||
|
||||
if (document.getElementById('swcfpc_form_test_cache')) {
|
||||
document.getElementById('swcfpc_form_test_cache').addEventListener('submit', (e) => {
|
||||
e.preventDefault()
|
||||
swcfpc_test_page_cache()
|
||||
})
|
||||
}
|
||||
|
||||
if (document.getElementById('swcfpc_form_enable_cache')) {
|
||||
document.getElementById('swcfpc_form_enable_cache').addEventListener('submit', (e) => {
|
||||
e.preventDefault()
|
||||
swcfpc_enable_page_cache()
|
||||
})
|
||||
}
|
||||
|
||||
if (document.getElementById('swcfpc_form_disable_cache')) {
|
||||
document.getElementById('swcfpc_form_disable_cache').addEventListener('submit', (e) => {
|
||||
e.preventDefault()
|
||||
swcfpc_disable_page_cache()
|
||||
})
|
||||
}
|
||||
|
||||
if (document.getElementById('swcfpc_form_reset_all')) {
|
||||
document.getElementById('swcfpc_form_reset_all').addEventListener('submit', (e) => {
|
||||
e.preventDefault()
|
||||
|
||||
if (confirm("Are you sure you want reset all?"))
|
||||
swcfpc_reset_all()
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
if (document.querySelector('select[name=swcfpc_cf_auth_mode]')) {
|
||||
document.querySelector('select[name=swcfpc_cf_auth_mode]').addEventListener('change', (e) => {
|
||||
e.preventDefault()
|
||||
|
||||
const method = e.target.value
|
||||
|
||||
if (method === '0') { // API Key
|
||||
document.querySelectorAll('.api_token_method').forEach((item) => {
|
||||
item.classList.add('swcfpc_hide')
|
||||
})
|
||||
document.querySelectorAll('.api_key_method').forEach((item) => {
|
||||
item.classList.remove('swcfpc_hide')
|
||||
})
|
||||
} else { // API Token
|
||||
document.querySelectorAll('.api_token_method').forEach((item) => {
|
||||
item.classList.remove('swcfpc_hide')
|
||||
})
|
||||
document.querySelectorAll('.api_key_method').forEach((item) => {
|
||||
item.classList.add('swcfpc_hide')
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Handling how the option shows based on selected option
|
||||
// Checking if there is any item with .conditional_item to begin with
|
||||
if (document.querySelectorAll('.conditional_item').length > 0) {
|
||||
// Select all the items with .conditional_item & loop through them
|
||||
document.querySelectorAll('.conditional_item').forEach((mainItem) => {
|
||||
// Run on first load after DOM is loaded
|
||||
// Check if the item is checked as on the loaded event we are only setting style based on the data we got from server
|
||||
if (mainItem.checked) {
|
||||
swcfpc_handle_conditional_settings(mainItem)
|
||||
}
|
||||
|
||||
// Add click add event listener to each mainItem so in future when a user clicks on them we can handle it accordingly
|
||||
mainItem.addEventListener('click', (e) => {
|
||||
swcfpc_handle_conditional_settings(e.target)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
if (document.querySelector('.swcfpc_faq_accordion')) {
|
||||
swcfpc_init_accordions();
|
||||
}
|
||||
|
||||
if (document.querySelector('#swcfpc_tab_links .nav-tab-active')) {
|
||||
const active_tab_id = document.querySelector('#swcfpc_tab_links .nav-tab-active').dataset.tab
|
||||
|
||||
if (typeof active_tab_id !== undefined) {
|
||||
document.querySelector('input[name=swcfpc_tab]').value = active_tab_id
|
||||
}
|
||||
}
|
||||
|
||||
swcfpc_toolbar_cache_status_interval = window.setInterval(swcfpc_update_toolbar_cache_status, 2000);
|
||||
|
||||
})
|
|
@ -0,0 +1 @@
|
|||
.ti-sdk-om-notice{--wp-admin-theme-color: #3858E9;--wp-admin-theme-color-darker-10: #2e47ba;position:relative;padding:0;border-left-color:#3858e9}.ti-sdk-om-notice .content{background:rgba(255,255,255,.75);display:flex;align-items:center;padding:15px 20px}.ti-sdk-om-notice img{max-width:100px;margin-right:20px;display:none}.ti-sdk-om-notice .description{font-size:14px;margin-bottom:20px;color:#000}.ti-sdk-om-notice .actions{margin-top:auto;display:flex;margin-bottom:0;gap:20px}.ti-sdk-om-notice form{display:flex;align-items:center;gap:10px}.ti-sdk-om-notice .form-wrap{display:grid}.ti-sdk-om-notice .form-wrap span:not(.dashicons){margin-bottom:5px;font-weight:500}.ti-sdk-om-notice input{border-radius:0;min-width:250px}.ti-sdk-om-notice a.components-button{display:flex;align-items:center;justify-content:center}.ti-sdk-om-notice .is-link{text-decoration:none;display:flex;align-items:center}.ti-sdk-om-notice .is-link span{line-height:normal}.ti-sdk-om-notice .dashicons{margin-right:2px;text-decoration:none}.ti-sdk-om-notice .done{display:flex;flex-direction:column;align-items:flex-start}.ti-sdk-om-notice .done a{width:auto}.compat-field-optimole th{display:none !important}.compat-field-optimole td{width:100% !important}.compat-field-optimole .ti-sdk-om-notice{margin:0}.om-notice-dismiss{right:10px;top:10px;text-decoration:none !important;position:absolute}.om-notice-dismiss:before{content:none}.ti-om-stack-wrap .om-stack-notice{--wp-admin-theme-color: #3858E9;--wp-admin-theme-color-darker-10: #2e47ba;display:flex;flex-direction:column;align-items:center;position:relative;text-align:center;padding:20px 10px}.ti-om-stack-wrap .om-stack-notice>span{display:none}.ti-om-stack-wrap .om-stack-notice img{max-width:90px !important}.ti-om-stack-wrap .om-stack-notice h2{font-size:18px;margin:30px auto 10px;font-weight:600}.ti-om-stack-wrap .om-stack-notice p{font-size:13px;max-width:250px;margin:0 auto;line-height:17px}.ti-om-stack-wrap .om-stack-notice i{margin-top:10px;font-size:12px;color:#757575}.ti-om-stack-wrap .om-stack-notice .cta{margin:20px auto 0;padding:10px 25px !important}.ti-om-stack-wrap .om-stack-notice .om-notice-dismiss{color:inherit}.ti-om-stack-wrap .om-stack-notice input{border-radius:0}.ti-om-stack-wrap .om-stack-notice form{place-items:center;width:75%;display:grid;margin-top:10px;gap:10px}.ti-om-stack-wrap .om-stack-notice .done{margin-top:15px;display:grid;gap:10px}.ti-om-stack-wrap .om-stack-notice .done p{font-size:15px;font-weight:500}.ti-om-stack-wrap .om-stack-notice .om-progress{margin:20px 0}.block-editor-block-inspector .ti-om-stack-wrap{border-top:1px solid #e0e0e0}.om-progress{gap:5px;font-size:14px;display:flex;align-items:center}.om-progress .spin{animation:om-rotation 2s infinite linear}@keyframes om-rotation{0%{transform:rotate(0deg)}100%{transform:rotate(359deg)}}.ti-sdk-om-promo.hidden{display:none}.media-sidebar .ti-sdk-om-notice input{min-width:unset;flex-grow:1}.media-sidebar .ti-sdk-om-notice .description{margin-bottom:10px}.media-sidebar .ti-sdk-om-notice .content{padding:15px 10px}.media-sidebar .ti-sdk-om-notice .actions{gap:10px}.media-sidebar .ti-sdk-om-notice form{flex-wrap:wrap;justify-content:center}.attachment-info .ti-sdk-om-notice input{min-width:unset;flex-grow:1}.attachment-info .ti-sdk-om-notice form{flex-wrap:wrap;justify-content:center}.ti-sdk-rop-notice{position:relative;padding:10px}.ti-sdk-rop-notice .rop-notice-actions{display:flex;gap:10px}.ti-sdk-rop-notice p{padding:0 10px 0 0}.ti-sdk-neve-fse-notice{position:relative;padding:10px}.ti-sdk-neve-fse-notice .neve-fse-notice-actions{display:flex;gap:10px}.ti-sdk-neve-fse-notice .neve-fse-notice-actions a{text-decoration:none}.ti-sdk-neve-fse-notice .neve-fse-notice-actions a span:not(.dashicons){text-decoration:underline}.ti-sdk-neve-fse-notice p{padding:0 10px 0 0;font-size:14px}@media screen and (min-width: 768px){.ti-sdk-om-notice img{display:block}}@media screen and (min-width: 1200px){.attachment-info .ti-sdk-om-notice form{flex-wrap:unset}}
|