You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
<?phpdefined( 'ABSPATH' ) ordie( 'Cheatin\' uh?' );
/** * CloudFlare API */class WP_Rocket_CloudFlareAPI
{
// The URL of the APIprivate$api_endpoint = 'https://www.cloudflare.com/api_json.html';
// The URL of Spam APIprivate$spam_endpoint = 'https://www.cloudflare.com/ajax/external-event.html';
// Timeout for the API requests in secondsconstTIMEOUT = 5;
// Stores the api keyprivate$api_key;
// Stores the email loginprivate$email;
/** * @var The single instance of the class */protectedstatic$_instance = null;
/** * Make a new instance of the API client */publicfunction__construct( $email, $api_key )
{
$this->email = $email;
$this->api_key = $api_key;
}
/** * Main WP_Rocket_CloudFlareAPI Instance * * Ensures only one instance of class is loaded or can be loaded. * * @static * @return Main instance */publicstaticfunctioninstance( $email, $api_key ) {
if ( is_null( self::$_instance ) ) {
self::$_instance = newself( $email, $api_key );
}
returnself::$_instance;
}
/** * Retrieve A List Of The Domains * This lists all domains in a CloudFlare account along with other data. */publicfunctionzone_load_multi()
{
$data = array(
'a' => 'zone_load_multi'
);
return$this->http_post( $data );
}
/** * List All The Current Settings * This function retrieves all the current settings for a given domain. */publicfunctionzone_settings( $domain )
{
$data = array(
'a' => 'zone_settings',
'z' => $domain
);
return$this->http_post( $data );
}
/** * Set The Cache Level * This function sets the Caching Level to Aggressive or Basic. * The switches are: (agg|basic). */publicfunctioncache_lvl( $domain, $mode )
{
$data = array(
'a' => 'cache_lvl',
'z' => $domain,
'v' => (strtolower($mode) == 'agg') ? 'agg' : 'basic'
);
return$this->http_post( $data );
}
/** * Toggling Development Mode * This function allows you to toggle Development Mode on or off for a particular domain. * When Development Mode is on the cache is bypassed. * Development mode remains on for 3 hours or until when it is toggled back off. */publicfunctiondevmode( $domain, $mode )
{
$data = array(
'a' => 'devmode',
'z' => $domain,
'v' => ($mode == true) ? 1 : 0
);
return$this->http_post( $data );
}
/** * Clear CloudFlare's Cache * This function will purge CloudFlare of any cached files. * It may take up to 48 hours for the cache to rebuild and optimum performance to be achieved. * This function should be used sparingly. */publicfunctionfpurge_ts( $domain )
{
$data = array(
'a' => 'fpurge_ts',
'z' => $domain,
'v' => 1
);
return$this->http_post( $data );
}
/** * Purge A Single File In CloudFlare's Cache * This function will purge a single file from CloudFlare's cache. */publicfunctionzone_file_purge( $domain, $url )
{
$data = array(
'a' => 'zone_file_purge',
'z' => $domain,
'url' => $url
);
return$this->http_post( $data );
}
/** * Set Rocket Loader * This function changes Rocket Loader setting. */publicfunctionasync( $domain, $mode )
{
$data = array(
'a' => 'async',
'z' => $domain,
'v' => $mode
);
return$this->http_post( $data );
}
/** * Set Minification * This function changes minification settings. */publicfunctionminify( $domain, $mode )
{
$data = array(
'a' => 'minify',
'z' => $domain,
'v' => $mode
);
return$this->http_post( $data );
}
/** * GLOBAL API CALL * HTTP POST a specific task with the supplied data */privatefunctionhttp_post( $data )
{
$data['u'] = $this->email;
$data['tkn'] = $this->api_key;
$response = wp_remote_post( $this->api_endpoint, array(
'timeout' => self::TIMEOUT,
'headers' => array(),
'body' => $data,
'cookies' => array()
));
if ( is_wp_error( $response ) ) {
return$response->get_error_message();
} else {
returnjson_decode( wp_remote_retrieve_body( $response ) );
}
}
// Reporting Spam IP to CloudFlarepublicfunctionreporting_spam_ip( $payload ) {
$response = wp_remote_get(
sprintf( '%s?evnt_v=%s&u=%s&tkn=%s&evnt_t=%s', $this->spam_endpoint, $payload, $this->email, $this->api_key, 'WP_SPAM' ),
array(
'method' => 'GET',
'timeout' => self::TIMEOUT,
'sslverify' => true,
'user-agent' => 'CloudFlare/WordPress/' . WP_ROCKET_VERSION,
)
);
if ( is_wp_error( $response ) ) {
return$response->get_error_message();
} else {
returnjson_decode( wp_remote_retrieve_body( $response ) );
}
}
}
The text was updated successfully, but these errors were encountered:
What can we quickly reuse?
The text was updated successfully, but these errors were encountered: