diff --git a/wp-content/plugins/w3-total-cache/Cache.php b/wp-content/plugins/w3-total-cache/Cache.php index 65d5b7d9..87d72da7 100644 --- a/wp-content/plugins/w3-total-cache/Cache.php +++ b/wp-content/plugins/w3-total-cache/Cache.php @@ -1,4 +1,10 @@ available() ) { - $instances[$instance_key] = new Cache_Base( $config ); + if ( ! isset( $instances[ $instance_key ] ) || ! $instances[ $instance_key ]->available() ) { + $instances[ $instance_key ] = new Cache_Base( $config ); } } - return $instances[$instance_key]; + return $instances[ $instance_key ]; } /** * Returns caching engine name * - * @param unknown $engine - * @param unknown $module + * @param string $engine Engine key code. + * @param string $module Module. * * @return string */ - static public function engine_name( $engine, $module = '' ) { + public static function engine_name( $engine, $module = '' ) { switch ( $engine ) { - case 'memcached': - if ( class_exists( 'Memcached' ) ) - $engine_name = 'memcached'; - else - $engine_name = 'memcache'; + case 'memcached': + if ( class_exists( 'Memcached' ) ) { + $engine_name = 'Memcached'; + } else { + $engine_name = 'Memcache'; + } + break; - break; + case 'nginx_memcached': + $engine_name = 'Nginx + Memcached'; + break; - case 'nginx_memcached': - $engine_name = 'nginx + memcached'; - break; + case 'apc': + $engine_name = 'APC'; + break; - case 'apc': - $engine_name = 'apc'; - break; + case 'eaccelerator': + $engine_name = 'EAccelerator'; + break; - case 'eaccelerator': - $engine_name = 'eaccelerator'; - break; + case 'redis': + $engine_name = 'Redis'; + break; - case 'redis': - $engine_name = 'redis'; - break; + case 'xcache': + $engine_name = 'XCache'; + break; - case 'xcache': - $engine_name = 'xcache'; - break; + case 'wincache': + $engine_name = 'WinCache'; + break; - case 'wincache': - $engine_name = 'wincache'; - break; + case 'file': + if ( 'pgcache' === $module ) { + $engine_name = 'Disk: Basic'; + } else { + $engine_name = 'Disk'; + } + break; - case 'file': - if ( $module == 'pgcache' ) - $engine_name = 'disk: basic'; - else - $engine_name = 'disk'; - break; + case 'file_generic': + $engine_name = 'Disk: Enhanced'; + break; - case 'file_generic': - $engine_name = 'disk: enhanced'; - break; + case 'ftp': + $engine_name = 'Self-hosted / file transfer protocol upload'; + break; - case 'ftp': - $engine_name = 'self-hosted / file transfer protocol upload'; - break; + case 's3': + $engine_name = 'Amazon Simple Storage Service (S3)'; + break; - case 's3': - $engine_name = 'amazon simple storage service (s3)'; - break; + case 's3_compatible': + $engine_name = 'S3 compatible'; + break; - case 's3_compatible': - $engine_name = 's3 compatible'; - break; + case 'cf': + $engine_name = 'Amazon Cloudfront'; + break; - case 'cf': - $engine_name = 'amazon cloudfront'; - break; + case 'google_drive': + $engine_name = 'Google Drive'; + break; - case 'google_drive': - $engine_name = 'google drive'; - break; + case 'highwinds': + $engine_name = 'Highwinds'; + break; - case 'highwinds': - $engine_name = 'highwinds'; - break; + case 'cf2': + $engine_name = 'Amazon Cloudfront'; + break; - case 'cf2': - $engine_name = 'amazon cloudfront'; - break; + case 'rscf': + $engine_name = 'Rackspace Cloud Files'; + break; - case 'rscf': - $engine_name = 'rackspace cloud files'; - break; + case 'azure': + $engine_name = 'Microsoft Azure Storage'; + break; - case 'azure': - $engine_name = 'microsoft azure storage'; - break; + case 'edgecast': + $engine_name = 'Media Template ProCDN / EdgeCast'; + break; - case 'edgecast': - $engine_name = 'media template procdn / edgecast'; - break; + case 'att': + $engine_name = 'AT&T'; + break; - case 'att': - $engine_name = 'at&t'; - break; + case 'rackspace_cdn': + $engine_name = 'Rackspace'; + break; - case 'rackspace_cdn': - $engine_name = 'rackspace'; - break; + case 'stackpath2': + $engine_name = 'StackPath'; + break; - case 'stackpath2': - $engine_name = 'stackpath'; - break; + case 'bunnycdn': + $engine_name = 'Bunny CDN'; + break; - default: - $engine_name = $engine; - break; + case '': + $engine_name = __( 'None', 'w3-total-cache' ); + break; + + default: + $engine_name = $engine; + break; } return $engine_name; } - } diff --git a/wp-content/plugins/w3-total-cache/CacheFlush.php b/wp-content/plugins/w3-total-cache/CacheFlush.php index 80930b32..d78f86fd 100644 --- a/wp-content/plugins/w3-total-cache/CacheFlush.php +++ b/wp-content/plugins/w3-total-cache/CacheFlush.php @@ -92,11 +92,14 @@ class CacheFlush { } /** - * Purge CDN mirror cache + * Purge CDN mirror cache. + * + * @param array $extras Extra configuration. */ - function cdn_purge_all( $extras = array() ) { - if ( $this->_config->get_boolean( 'cdn.enabled' ) ) + public function cdn_purge_all( $extras = array() ) { + if ( $this->_config->get_boolean( 'cdn.enabled' ) || $this->_config->get_boolean( 'cdnfsd.enabled' ) ) { return $this->_executor->cdn_purge_all( $extras ); + } return false; } diff --git a/wp-content/plugins/w3-total-cache/CacheGroups_Plugin_Admin_View.php b/wp-content/plugins/w3-total-cache/CacheGroups_Plugin_Admin_View.php index 1cd03412..bf946be9 100644 --- a/wp-content/plugins/w3-total-cache/CacheGroups_Plugin_Admin_View.php +++ b/wp-content/plugins/w3-total-cache/CacheGroups_Plugin_Admin_View.php @@ -122,7 +122,7 @@ if ( ! defined( 'W3TC' ) ) { -
+ - + @@ -310,7 +310,7 @@ if ( ! defined( 'W3TC' ) ) { - + '', + 'storage_api_key' => '', + 'stream_api_key' => '', + 'pull_zone_id' => null, + 'domain' => '', + ), + $config + ); + + parent::__construct( $config ); + } + + /** + * Purge remote files. + * + * @since X.X.X + * + * @param array $files Local and remote file paths. + * @param array $results Results. + * @return bool + */ + public function purge( $files, &$results ) { + if ( empty( $this->_config['account_api_key'] ) ) { + $results = $this->_get_results( $files, W3TC_CDN_RESULT_HALT, \__( 'Missing account API key.', 'w3-total-cache' ) ); + + return false; + } + + if ( empty( $this->_config['cdn_hostname'] ) ) { + $results = $this->_get_results( $files, W3TC_CDN_RESULT_HALT, \__( 'Missing CDN hostname.', 'w3-total-cache' ) ); + + return false; + } + + $url_prefixes = $this->url_prefixes(); + $api = new Cdn_BunnyCdn_Api( $this->_config ); + $results = array(); + + try { + $items = array(); + + foreach ( $files as $file ) { + foreach ( $url_prefixes as $prefix ) { + $items[] = array( + 'url' => $prefix . '/' . $file['remote_path'], + 'recursive' => true, + ); + } + } + + $api->purge( array( 'items' => $items ) ); + + $results[] = $this->_get_result( '', '', W3TC_CDN_RESULT_OK, 'OK' ); + } catch ( \Exception $e ) { + $results[] = $this->_get_result( '', '', W3TC_CDN_RESULT_HALT, \__( 'Could not purge pull zone items: ', 'w3-total-cache' ) . $e->getMessage() ); + } + + return ! $this->_is_error( $results ); + } + + /** + * Purge CDN completely. + * + * @since X.X.X + * + * @param array $results Results. + * @return bool + */ + public function purge_all( &$results ) { + if ( empty( $this->_config['account_api_key'] ) ) { + $results = $this->_get_results( array(), W3TC_CDN_RESULT_HALT, __( 'Missing account API key.', 'w3-total-cache' ) ); + + return false; + } + + // Purge active pull zones: CDN & CDNFSD. + $active_zone_ids = array(); + $config = Dispatcher::config(); + $cdn_zone_id = $config->get_integer( 'cdn.bunnycdn.pull_zone_id' ); + $cdnfsd_zone_id = $config->get_integer( 'cdnfsd.bunnycdn.pull_zone_id' ); + + if ( $config->get_boolean( 'cdn.enabled' ) && 'bunnycdn' === $config->get_string( 'cdn.engine' ) && $cdn_zone_id ) { + $active_ids[] = $cdn_zone_id; + } + + if ( $config->get_boolean( 'cdnfsd.enabled' ) && 'bunnycdn' === $config->get_string( 'cdnfsd.engine' ) && $cdnfsd_zone_id ) { + $active_ids[] = $cdnfsd_zone_id; + } + + if ( empty( $active_ids ) ) { + $results = $this->_get_results( array(), W3TC_CDN_RESULT_HALT, __( 'Missing pull zone id.', 'w3-total-cache' ) ); + + return false; + } + + $results = array(); + + foreach ( $active_ids as $id ) { + $api = new Cdn_BunnyCdn_Api( array_merge( $this->_config, array( 'pull_zone_id' => $id ) ) ); + + try { + $api->purge_pull_zone(); + $results[] = $this->_get_result( '', '' ); // W3TC_CDN_RESULT_OK. + } catch ( \Exception $e ) { + $results[] = $this->_get_result( '', '', W3TC_CDN_RESULT_HALT, \__( 'Could not purge pull zone', 'w3-total-cache' ) . '; ' . $e->getMessage() ); + } + } + + return ! $this->_is_error( $results ); + } + + /** + * Get URL prefixes. + * + * If set to "auto", then add URLs for both "http" and "https". + * + * @since X.X.X + * + * @return array + */ + private function url_prefixes() { + $url_prefixes = array(); + + if ( 'auto' === $this->_config['ssl'] || 'enabled' === $this->_config['ssl'] ) { + $url_prefixes[] = 'https://' . $this->_config['cdn_hostname']; + } + if ( 'auto' === $this->_config['ssl'] || 'enabled' !== $this->_config['ssl'] ) { + $url_prefixes[] = 'http://' . $this->_config['cdn_hostname']; + } + + return $url_prefixes; + } +} diff --git a/wp-content/plugins/w3-total-cache/Cdn_AdminActions.php b/wp-content/plugins/w3-total-cache/Cdn_AdminActions.php index 268a3ad6..b33ea7f4 100644 --- a/wp-content/plugins/w3-total-cache/Cdn_AdminActions.php +++ b/wp-content/plugins/w3-total-cache/Cdn_AdminActions.php @@ -413,6 +413,7 @@ class Cdn_AdminActions { $engine == 'stackpath2' || $engine == 'rackspace_cdn' || $engine == 'rscf' || + 'bunnycdn' === $engine || $engine == 's3_compatible' ) { // those use already stored w3tc config $w3_cdn = Dispatcher::component( 'Cdn_Core' )->get_cdn(); @@ -462,46 +463,69 @@ class Cdn_AdminActions { $container_id = ''; switch ( $engine ) { - case 's3': - case 'cf': - case 'cf2': - case 'azure': - $w3_cdn = CdnEngine::instance( $engine, $config ); + case 's3': + case 'cf': + case 'cf2': + case 'azure': + $w3_cdn = CdnEngine::instance( $engine, $config ); - @set_time_limit( $this->_config->get_integer( 'timelimit.cdn_upload' ) ); + @set_time_limit( $this->_config->get_integer( 'timelimit.cdn_upload' ) ); - $result = false; - try { - $container_id = $w3_cdn->create_container(); - $result = true; - $error = __( 'Created successfully.', 'w3-total-cache' ); - } catch ( \Exception $ex ) { - $error = sprintf( __( 'Error: %s', 'w3-total-cache' ), - $ex->getMessage() ); - } + $result = false; - break; - default: - $result = false; - $error = __( 'Incorrect type.', 'w3-total-cache' ); + try { + $container_id = $w3_cdn->create_container(); + $result = true; + $error = __( 'Created successfully.', 'w3-total-cache' ); + } catch ( \Exception $ex ) { + $error = sprintf( + __( 'Error: %s', 'w3-total-cache' ), + $ex->getMessage() + ); + } + + break; + + default: + $result = false; + $error = __( 'Incorrect type.', 'w3-total-cache' ); } $response = array( - 'result' => $result, - 'error' => $error, - 'container_id' => $container_id + 'result' => $result, + 'error' => $error, + 'container_id' => $container_id, ); echo json_encode( $response ); } + /** + * Redirect to the Bunny CDN signup page. + * + * @since X.X.X + * + * @return void + */ + public function w3tc_cdn_bunnycdn_signup() { + try { + $state = Dispatcher::config_state(); + $state->set( 'track.bunnycdn_signup', time() ); + $state->save(); + } catch ( \Exception $ex ) {} // phpcs:ignore + Util_Environment::redirect( W3TC_BUNNYCDN_SIGNUP_URL ); + } - + /** + * Test CDN URL. + * + * @param string $url URL. + */ private function test_cdn_url( $url ) { $response = wp_remote_get( $url ); - if ( is_wp_error( $response ) ) + if ( is_wp_error( $response ) ) { return false; - else { + } else { $code = wp_remote_retrieve_response_code( $response ); return 200 == $code; } diff --git a/wp-content/plugins/w3-total-cache/Cdn_BunnyCdn_Api.php b/wp-content/plugins/w3-total-cache/Cdn_BunnyCdn_Api.php new file mode 100644 index 00000000..7fc0304e --- /dev/null +++ b/wp-content/plugins/w3-total-cache/Cdn_BunnyCdn_Api.php @@ -0,0 +1,552 @@ + 15, // BypassPermaCache. + 'TriggerMatchingType' => 0, // MatchAny. + 'Enabled' => true, + 'Triggers' => array( + array( + 'Type' => 3, // UrlExtension. + 'PatternMatchingType' => 0, // MatchAny. + 'PatternMatches' => array( '.zip' ), + ), + ), + 'Description' => 'Bypass PermaCache for ZIP files', + ), + array( + 'ActionType' => 3, // OverrideCacheTime. + 'TriggerMatchingType' => 0, // MatchAny. + 'ActionParameter1' => '0', + 'ActionParameter2' => '', + 'Enabled' => true, + 'Triggers' => array( + array( + 'Type' => 1, // RequestHeader. + 'PatternMatchingType' => 0, // MatchAny. + 'PatternMatches' => array( + '*wordpress_logged_in_*', + '*wordpress_sec_*', + ), + 'Parameter1' => 'Cookie', + ), + ), + 'Description' => 'Override Cache Time if logged into WordPress', + ), + array( + 'ActionType' => 15, // BypassPermaCache. + 'TriggerMatchingType' => 0, // MatchAny. + 'Enabled' => true, + 'Triggers' => array( + array( + 'Type' => 1, // RequestHeader. + 'PatternMatchingType' => 0, // MatchAny. + 'PatternMatches' => array( + '*wordpress_logged_in_*', + '*wordpress_sec_*', + ), + 'Parameter1' => 'Cookie', + ), + ), + 'Description' => 'Bypass PermaCache if logged into WordPress', + ), + array( + 'ActionType' => 16, // OverrideBrowserCacheTime. + 'TriggerMatchingType' => 0, // MatchAny. + 'ActionParameter1' => '0', + 'Enabled' => true, + 'Triggers' => array( + array( + 'Type' => 1, // RequestHeader. + 'PatternMatchingType' => 0, // MatchAny. + 'PatternMatches' => array( + '*wordpress_logged_in_*', + '*wordpress_sec_*', + ), + 'Parameter1' => 'Cookie', + ), + ), + 'Description' => 'Override Browser Cache Time if logged into WordPress', + ), + ); + + /** + * Constructor. + * + * @since X.X.X + * + * @param array $config Configuration. + */ + public function __construct( array $config ) { + $this->account_api_key = ! empty( $config['account_api_key'] ) ? $config['account_api_key'] : ''; + $this->storage_api_key = ! empty( $config['storage_api_key'] ) ? $config['storage_api_key'] : ''; + $this->stream_api_key = ! empty( $config['stream_api_key'] ) ? $config['stream_api_key'] : ''; + $this->pull_zone_id = ! empty( $config['pull_zone_id'] ) ? $config['pull_zone_id'] : ''; + } + + /** + * Increase http request timeout to 60 seconds. + * + * @since X.X.X + * + * @param int $time Timeout in seconds. + */ + public function filter_timeout_time( $time ) { + return 600; + } + + /** + * Don't check certificate, some users have limited CA list + * + * @since X.X.X + * + * @param bool $verify Always false. + */ + public function https_ssl_verify( $verify = false ) { + return false; + } + + /** + * List pull zones. + * + * @since X.X.X + * + * @link https://docs.bunny.net/reference/pullzonepublic_index + * + * @return array + */ + public function list_pull_zones() { + $this->api_type = 'account'; + + return $this->wp_remote_get( \esc_url( 'https://api.bunny.net/pullzone' ) ); + } + + /** + * Get pull zone details by pull zone id. + * + * @since X.X.X + * + * @link https://docs.bunny.net/reference/pullzonepublic_index2 + * + * @param int $id Pull zone id. + * @return array + */ + public function get_pull_zone( $id ) { + $this->api_type = 'account'; + + return $this->wp_remote_get( + \esc_url( 'https://api.bunny.net/pullzone/id' . $id ) + ); + } + + /** + * Add a pull zone. + * + * @since X.X.X + * + * @link https://docs.bunny.net/reference/pullzonepublic_add + * + * @param array $data { + * Data used to create the pull zone. + * + * @type string $Name The name/hostname for the pull zone where the files will be accessible; only letters, numbers, and dashes. + * @type string $OriginUrl Origin URL or IP (with optional port number). + * @type string $OriginHostHeader Optional: The host HTTP header that will be sent to the origin. If empty, hostname will be automatically extracted from the Origin URL. + * @type bool $AddHostHeader Optional: If enabled, the original host header of the request will be forwarded to the origin server. This should be disabled in most cases. + * } + * + * @return array + * @throws \Exception Exception. + */ + public function add_pull_zone( array $data ) { + $this->api_type = 'account'; + + if ( empty( $data['Name'] ) || ! \is_string( $data['Name'] ) ) { // A Name string is required, which is used for the CDN hostname. + throw new \Exception( \esc_html__( 'A pull zone name (string) is required.', 'w3-total-cache' ) ); + } + + if ( \preg_match( '[^\w\d-]', $data['Name'] ) ) { // Only letters, numbers, and dashes are allowed in the Name. + throw new \Exception( \esc_html__( 'A pull zone name (string) is required.', 'w3-total-cache' ) ); + } + + return $this->wp_remote_post( + 'https://api.bunny.net/pullzone', + $data + ); + } + + /** + * Update a pull zone. + * + * @since X.X.X + * + * @link https://docs.bunny.net/reference/pullzonepublic_updatepullzone + * + * @param int $id Optional pull zone ID. Can be specified in the constructor configuration array parameter. + * @param array $data Data used to update the pull zone. + * @return array + * @throws \Exception Exception. + */ + public function update_pull_zone( $id, array $data ) { + $this->api_type = 'account'; + $id = empty( $this->pull_zone_id ) ? $id : $this->pull_zone_id; + + if ( empty( $id ) || ! \is_int( $id ) ) { + throw new \Exception( \esc_html__( 'Invalid pull zone id.', 'w3-total-cache' ) ); + } + + return $this->wp_remote_post( + 'https://api.bunny.net/pullzone/' . $id, + $data + ); + } + + /** + * Delete a pull zone. + * + * @since X.X.X + * + * @link https://docs.bunny.net/reference/pullzonepublic_delete + * + * @param int $id Optional pull zone ID. Can be specified in the constructor configuration array parameter. + * @return array + * @throws \Exception Exception. + */ + public function delete_pull_zone( $id ) { + $this->api_type = 'account'; + $id = empty( $this->pull_zone_id ) ? $id : $this->pull_zone_id; + + if ( empty( $id ) || ! \is_int( $id ) ) { + throw new \Exception( \esc_html__( 'Invalid pull zone id.', 'w3-total-cache' ) ); + } + + return $this->wp_remote_post( + \esc_url( 'https://api.bunny.net/pullzone/' . $id ), + array(), + array( 'method' => 'DELETE' ) + ); + } + + /** + * Add a custom hostname to a pull zone. + * + * @since X.X.X + * + * @link https://docs.bunny.net/reference/pullzonepublic_addhostname + * + * @param string $hostname Custom hostname. + * @param int $pull_zone_id Optional pull zone ID. Can be specified in the constructor configuration array parameter. + * @return void + * @throws \Exception Exception. + */ + public function add_custom_hostname( $hostname, $pull_zone_id = null ) { + $this->api_type = 'account'; + $pull_zone_id = empty( $this->pull_zone_id ) ? $pull_zone_id : $this->pull_zone_id; + + if ( empty( $pull_zone_id ) || ! \is_int( $pull_zone_id ) ) { + throw new \Exception( \esc_html__( 'Invalid pull zone id.', 'w3-total-cache' ) ); + } + + if ( empty( $hostname ) || ! \filter_var( $hostname, FILTER_VALIDATE_DOMAIN ) ) { + throw new \Exception( \esc_html__( 'Invalid hostname', 'w3-total-cache' ) . ' "' . \esc_html( $hostname ) . '".' ); + } + + $this->wp_remote_post( + \esc_url( 'https://api.bunny.net/pullzone/' . $pull_zone_id . '/addHostname' ), + array( 'Hostname' => $hostname ) + ); + } + + /** + * Get the default edge rules. + * + * @since X.X.X + * @static + * + * @return array + */ + public static function get_default_edge_rules() { + return self::$default_edge_rules; + } + + /** + * Add/Update Edge Rule. + * + * @since X.X.X + * + * @param array $data Data. + * @param int $pull_zone_id Optional pull zone ID. Can be specified in the constructor configuration array parameter. + * @return void + * @throws \Exception Exception. + */ + public function add_edge_rule( array $data, $pull_zone_id = null ) { + $this->api_type = 'account'; + $pull_zone_id = empty( $this->pull_zone_id ) ? $pull_zone_id : $this->pull_zone_id; + + if ( empty( $pull_zone_id ) || ! \is_int( $pull_zone_id ) ) { + throw new \Exception( \esc_html__( 'Invalid pull zone id.', 'w3-total-cache' ) ); + } + + if ( ! isset( $data['ActionType'] ) || ! \is_int( $data['ActionType'] ) || $data['ActionType'] < 0 ) { + throw new \Exception( \esc_html__( 'Invalid parameter "ActionType".', 'w3-total-cache' ) ); + } + + if ( ! isset( $data['TriggerMatchingType'] ) || ! \is_int( $data['TriggerMatchingType'] ) || $data['TriggerMatchingType'] < 0 ) { + throw new \Exception( \esc_html__( 'Invalid parameter "TriggerMatchingType".', 'w3-total-cache' ) ); + } + + if ( ! isset( $data['Enabled'] ) || ! \is_bool( $data['Enabled'] ) ) { + throw new \Exception( \esc_html__( 'Missing parameter "Enabled".', 'w3-total-cache' ) ); + } + + if ( empty( $data['Triggers'] ) ) { + throw new \Exception( \esc_html__( 'Missing parameter "Triggers".', 'w3-total-cache' ) ); + } + + $this->wp_remote_post( + \esc_url( 'https://api.bunny.net/pullzone/' . $pull_zone_id . '/edgerules/addOrUpdate' ), + $data + ); + } + + /** + * Purge. + * + * @since X.X.X + * + * @param array $data Data for the POST request. + * @return array + */ + public function purge( array $data ) { + $this->api_type = 'account'; + + return $this->wp_remote_get( + \esc_url( 'https://api.bunny.net/purge' ), + $data + ); + } + + /** + * Purge an entire pull zone. + * + * @since X.X.X + * + * @param int $pull_zone_id Optional pull zone ID. Can be specified in the constructor configuration array parameter. + * @return void + * @throws \Exception Exception. + */ + public function purge_pull_zone( $pull_zone_id = null ) { + $this->api_type = 'account'; + $pull_zone_id = empty( $this->pull_zone_id ) ? $pull_zone_id : $this->pull_zone_id; + + if ( empty( $pull_zone_id ) || ! \is_int( $pull_zone_id ) ) { + throw new \Exception( \esc_html__( 'Invalid pull zone id.', 'w3-total-cache' ) ); + } + + $this->wp_remote_post( \esc_url( 'https://api.bunny.net/pullzone/' . $pull_zone_id . '/purgeCache' ) ); + } + + /** + * Get the API key by API type. + * + * API type can be passed or the class property will be used. + * + * @since X.X.X + * + * @param string $type API type: One of "account", "storage", "stream" (optional). + * @return string|null + * @throws \Exception Exception. + */ + private function get_api_key( $type = null ) { + if ( empty( $type ) ) { + $type = $this->api_type; + } + + if ( ! \in_array( $type, array( 'account', 'storage', 'stream' ), true ) ) { + throw new \Exception( \esc_html__( 'Invalid API type; must be one of "account", "storage", "stream".', 'w3-total-cache' ) ); + } + + if ( empty( $this->{$type . '_api_key'} ) ) { + throw new \Exception( \esc_html__( 'API key value is empty.', 'w3-total-cache' ) ); + } + + return $this->{$type . '_api_key'}; + } + + /** + * Decode response from a wp_remote_* call. + * + * @since X.X.X + * + * @param array|WP_Error $result Result. + * @return array + * @throws \Exception Exception. + */ + private function decode_response( $result ) { + if ( \is_wp_error( $result ) ) { + throw new \Exception( \esc_html__( 'Failed to reach API endpoint', 'w3-total-cache' ) ); + } + + $response_body = @\json_decode( $result['body'], true ); + + // Throw an exception if the response code/status is not ok. + if ( ! \in_array( $result['response']['code'], array( 200, 201, 204 ), true ) ) { + $message = isset( $response_body['Message'] ) ? $response_body['Message'] : $result['body']; + + throw new \Exception( + \esc_html( \__( 'Response code ', 'w3-total-cache' ) . $result['response']['code'] . ': ' . $message ) + ); + } + + return \is_array( $response_body ) ? $response_body : array(); + } + + /** + * Remote GET request. + * + * @since X.X.X + * + * @link https://developer.wordpress.org/reference/functions/wp_remote_get/ + * @link https://developer.wordpress.org/reference/classes/wp_http/request/ + * + * @param string $url URL address. + * @param array $data Query string data for the GET request. + * @return array + */ + private function wp_remote_get( $url, array $data = array() ) { + $api_key = $this->get_api_key(); + + \add_filter( 'http_request_timeout', array( $this, 'filter_timeout_time' ) ); + \add_filter( 'https_ssl_verify', array( $this, 'https_ssl_verify' ) ); + + $result = \wp_remote_get( + $url . ( empty( $data ) ? '' : '?' . \http_build_query( $data ) ), + array( + 'headers' => array( + 'AccessKey' => $api_key, + 'Accept' => 'application/json', + ), + ) + ); + + \remove_filter( 'https_ssl_verify', array( $this, 'https_ssl_verify' ) ); + \remove_filter( 'http_request_timeout', array( $this, 'filter_timeout_time' ) ); + + return self::decode_response( $result ); + } + + /** + * Remote POST request. + * + * @since X.X.X + * + * @link https://developer.wordpress.org/reference/functions/wp_remote_post/ + * @link https://developer.wordpress.org/reference/classes/wp_http/request/ + * + * @param string $url URL address. + * @param array $data Optional data for the POSt request. + * @param array $args Optional additional arguments for the wp_remote_port call. + * @return string + */ + private function wp_remote_post( $url, array $data = array(), array $args = array() ) { + $api_key = $this->get_api_key(); + + \add_filter( 'http_request_timeout', array( $this, 'filter_timeout_time' ) ); + \add_filter( 'https_ssl_verify', array( $this, 'https_ssl_verify' ) ); + + $result = \wp_remote_post( + $url, + \array_merge( + array( + 'headers' => array( + 'AccessKey' => $api_key, + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ), + 'body' => empty( $data ) ? null : \json_encode( $data ), + ), + $args + ) + ); + + \remove_filter( 'https_ssl_verify', array( $this, 'https_ssl_verify' ) ); + \remove_filter( 'http_request_timeout', array( $this, 'filter_timeout_time' ) ); + + return self::decode_response( $result ); + } +} diff --git a/wp-content/plugins/w3-total-cache/Cdn_BunnyCdn_Page.php b/wp-content/plugins/w3-total-cache/Cdn_BunnyCdn_Page.php new file mode 100644 index 00000000..95aadc39 --- /dev/null +++ b/wp-content/plugins/w3-total-cache/Cdn_BunnyCdn_Page.php @@ -0,0 +1,204 @@ +get_boolean( 'cdn.enabled' ); + $cdn_engine = $config->get_string( 'cdn.engine' ); + $cdn_zone_id = $config->get_integer( 'cdn.bunnycdn.pull_zone_id' ); + $cdnfsd_enabled = $config->get_boolean( 'cdnfsd.enabled' ); + $cdnfsd_engine = $config->get_string( 'cdnfsd.engine' ); + $cdnfsd_zone_id = $config->get_integer( 'cdnfsd.bunnycdn.pull_zone_id' ); + $account_api_key = $config->get_string( 'cdn.bunnycdn.account_api_key' ); + + return ( $account_api_key && + ( + ( $cdn_enabled && 'bunnycdn' === $cdn_engine && $cdn_zone_id ) || + ( $cdnfsd_enabled && 'bunnycdn' === $cdnfsd_engine && $cdnfsd_zone_id ) + ) + ); + } + + /** + * Add Dashboard actions. + * + * @since X.X.X + * @static + * + * @see self::in_active() + * + * @param array $actions Actions. + * @return array + */ + public static function w3tc_dashboard_actions( array $actions ) { + if ( self::is_active() ) { + $modules = Dispatcher::component( 'ModuleStatus' ); + $can_empty_memcache = $modules->can_empty_memcache(); + $can_empty_opcode = $modules->can_empty_opcode(); + $can_empty_file = $modules->can_empty_file(); + $can_empty_varnish = $modules->can_empty_varnish(); + + $actions[] = sprintf( + '', + esc_attr__( 'Empty All Caches Except Bunny CDN', 'w3-total-cache' ), + ( ! $can_empty_memcache && ! $can_empty_opcode && ! $can_empty_file && ! $can_empty_varnish ) ? ' disabled="disabled"' : '' + ); + } + + return $actions; + } + + /** + * Enqueue scripts. + * + * Called from plugin-admin. + * + * @since X.X.X + * @static + * + * @return void + */ + public static function admin_print_scripts_w3tc_cdn() { + $config = Dispatcher::config(); + $is_authorized = ! empty( $config->get_string( 'cdn.bunnycdn.account_api_key' ) ) && + ( $config->get_string( 'cdn.bunnycdn.pull_zone_id' ) || $config->get_string( 'cdnfsd.bunnycdn.pull_zone_id' ) ); + + \wp_register_script( + 'w3tc_cdn_bunnycdn', + \plugins_url( 'Cdn_BunnyCdn_Page_View.js', W3TC_FILE ), + array( 'jquery' ), + W3TC_VERSION + ); + + \wp_localize_script( + 'w3tc_cdn_bunnycdn', + 'W3TC_Bunnycdn', + array( + 'is_authorized' => $is_authorized, + 'lang' => array( + 'empty_url' => \esc_html__( 'No URL specified', 'w3-total-cache' ), + 'success_purging' => \esc_html__( 'Successfully purged URL', 'w3-total-cache' ), + 'error_purging' => \esc_html__( 'Error purging URL', 'w3-total-cache' ), + 'error_ajax' => \esc_html__( 'Error with AJAX', 'w3-total-cache' ), + ), + ) + ); + + \wp_enqueue_script( 'w3tc_cdn_bunnycdn' ); + } + + /** + * CDN settings. + * + * @since X.X.X + * @static + * + * @return void + */ + public static function w3tc_settings_cdn_boxarea_configuration() { + $config = Dispatcher::config(); + + include W3TC_DIR . '/Cdn_BunnyCdn_Page_View.php'; + } + + /** + * Display purge URLs page. + * + * @since X.X.X + * @static + */ + public static function w3tc_purge_urls_box() { + $config = Dispatcher::config(); + + include W3TC_DIR . '/Cdn_BunnyCdn_Page_View_Purge_Urls.php'; + } + + /** + * W3TC AJAX: Purge a URL. + * + * Purging a URL will remove the file from the CDN cache and re-download it from your origin server. + * Please enter the exact CDN URL of each individual file. + * You can also purge folders or wildcard files using * inside of the URL path. + * Wildcard values are not supported if using Perma-Cache. + * + * @since X.X.X + */ + public function w3tc_ajax_cdn_bunnycdn_purge_url() { + $url = Util_Request::get_string( 'url' ); + + // Check if URL starts with "http", starts with a valid protocol, and passes a URL validation check. + if ( 0 !== \strpos( $url, 'http' ) || ! \preg_match( '~^http(s?)://(.+)~i', $url ) || ! \filter_var( $url, FILTER_VALIDATE_URL ) ) { + \wp_send_json_error( + array( 'error_message' => \esc_html__( 'Invalid URL', 'w3-total-cache' ) ), + 400 + ); + } + + $config = Dispatcher::config(); + $account_api_key = $config->get_string( 'cdn.bunnycdn.account_api_key' ); + + $api = new Cdn_BunnyCdn_Api( array( 'account_api_key' => $account_api_key ) ); + + // Try to delete pull zone. + try { + $api->purge( + array( + 'url' => \esc_url( $url, array( 'http', 'https' ) ), + 'async' => true, + ) + ); + } catch ( \Exception $ex ) { + \wp_send_json_error( array( 'error_message' => $ex->getMessage() ), 422 ); + } + + \wp_send_json_success(); + } + + /** + * Flush all caches except Bunny CDN. + * + * @since X.X.X + */ + public function w3tc_bunnycdn_flush_all_except_bunnycdn() { + Dispatcher::component( 'CacheFlush' )->flush_all( array( 'bunnycdn' => 'skip' ) ); + Util_Admin::redirect( array( 'w3tc_note' => 'flush_all' ), true ); + } +} diff --git a/wp-content/plugins/w3-total-cache/Cdn_BunnyCdn_Page_View.js b/wp-content/plugins/w3-total-cache/Cdn_BunnyCdn_Page_View.js new file mode 100644 index 00000000..4dde97aa --- /dev/null +++ b/wp-content/plugins/w3-total-cache/Cdn_BunnyCdn_Page_View.js @@ -0,0 +1,249 @@ +/** + * File: Cdn_BunnyCdn_Page_View.js + * + * @since X.X.X + * @package W3TC + * + * @global W3TC_Bunnycdn Localization array for info and language. + */ + +jQuery(function($) { + /** + * Resize the popup modal. + * + * @param object o W3tc_Lightbox object. + */ + function w3tc_bunnycdn_resize(o) { + o.options.height = $('.w3tc_cdn_bunnycdn_form').height(); + o.resize(); + } + + // Add event handlers. + $('body') + // Load the authorization form. + .on('click', '.w3tc_cdn_bunnycdn_authorize', function() { + W3tc_Lightbox.open({ + id:'w3tc-overlay', + close: '', + width: 800, + height: 300, + url: ajaxurl + + '?action=w3tc_ajax&_wpnonce=' + + w3tc_nonce + + '&w3tc_action=cdn_bunnycdn_intro', + callback: w3tc_bunnycdn_resize + }); + }) + + // Sanitize the account API key input value. + .on('change', '#w3tc-account-api-key', function() { + var $this = $(this); + + $this.val($.trim($this.val().replace(/[^a-z0-9-]/g, ''))); + }) + + // Load the pull zone selection form. + .on('click', '.w3tc_cdn_bunnycdn_list_pull_zones', function() { + var url = ajaxurl + '?action=w3tc_ajax&_wpnonce=' + w3tc_nonce + + '&w3tc_action=cdn_bunnycdn_list_pull_zones'; + + W3tc_Lightbox.load_form(url, '.w3tc_cdn_bunnycdn_form', w3tc_bunnycdn_resize); + }) + + // Enable/disable (readonly) add pull zone form fields based on selection. + .on('change', '#w3tc-pull-zone-id', function() { + var $selected_option = $(this).find(':selected'), + $origin = $('#w3tc-origin-url'), + $name = $('#w3tc-pull-zone-name'), + $hostnames = $('#w3tc-custom-hostnames'); + + if ($(this).find(':selected').val() === '') { + // Enable the add pull zone fields with suggested or entered values. + $origin.val($origin.data('suggested')).prop('readonly', false); + $name.val($name.data('suggested')).prop('readonly', false); + $hostnames.val($hostnames.data('suggested')).prop('readonly', false); + } else { + // Disable the add pull zone fields and change values using the selected option. + $origin.prop('readonly', true).val($selected_option.data('origin')); + $name.prop('readonly', true).val($selected_option.data('name')); + $hostnames.prop('readonly', true).val($selected_option.data('custom-hostnames')); + } + + // Update the hidden input field for the selected pull zone id from the select option value. + $('[name="pull_zone_id"]').val($selected_option.val()); + + // Update the hidden input field for the selected pull zone CDN hostname from the select option value. + $('[name="cdn_hostname"]').val($selected_option.data('cdn-hostname')); + }) + + // Sanitize the origin URL/IP input value. + .on('change', '#w3tc-origin-url', function() { + var $this = $(this); + + $this.val($.trim($this.val().toLowerCase().replace(/[^a-z0-9\.:\/-]/g, ''))); + }) + + // Sanitize the pull zone name input value. + .on('change', '#w3tc-pull-zone-name', function() { + var $this = $(this); + + $this.val($.trim($this.val().toLowerCase().replace(/[^a-z0-9-]/g, ''))); + }) + + // Sanitize the CDN hostname input value. + .on('change', '#w3tc_bunnycdn_hostname', function() { + var $this = $(this); + + $this.val($.trim($this.val().toLowerCase().replace(/(^https?:|:.+$|[^a-z0-9\.-])/g, ''))); + }) + + // Configure pull zone. + .on('click', '.w3tc_cdn_bunnycdn_configure_pull_zone', function() { + var url = ajaxurl + '?action=w3tc_ajax&_wpnonce=' + w3tc_nonce + + '&w3tc_action=cdn_bunnycdn_configure_pull_zone'; + + W3tc_Lightbox.load_form(url, '.w3tc_cdn_bunnycdn_form', w3tc_bunnycdn_resize); + }) + + // Close the popup success modal. + .on('click', '.w3tc_cdn_bunnycdn_done', function() { + window.location = window.location + '&'; + }) + + // Load the deauthorize form. + .on('click', '.w3tc_cdn_bunnycdn_deauthorization', function() { + W3tc_Lightbox.open({ + id:'w3tc-overlay', + close: '', + width: 800, + height: 300, + url: ajaxurl + + '?action=w3tc_ajax&_wpnonce=' + + w3tc_nonce + + '&w3tc_action=cdn_bunnycdn_deauthorization', + callback: w3tc_bunnycdn_resize + }); + }) + + // Deauthorize and optionally delete the pull zone. + .on('click', '.w3tc_cdn_bunnycdn_deauthorize', function() { + var url = ajaxurl + '?action=w3tc_ajax&_wpnonce=' + w3tc_nonce + + '&w3tc_action=cdn_bunnycdn_deauthorize'; + + W3tc_Lightbox.load_form(url, '.w3tc_cdn_bunnycdn_form', w3tc_bunnycdn_resize); + }) + + // Sanitize the purge URL list. + .on('focusout', '#w3tc-purge-urls', function () { + // Abort if Bunny CDN is not authorized. + if (! W3TC_Bunnycdn.is_authorized) { + return; + } + + // Declare vars. + var $this = $(this), + $button = $('.w3tc_cdn_bunnycdn_purge_urls'); + + // Strip whitespace, newlines, and invalid characters. + $this.val( $this.val().replace(/^(\s)*(\r\n|\n|\r)/gm, '') ); + $this.val($.trim($this.val().replace(/[^a-z0-9\.:\/\r\n*-]/g, ''))); + + // Enable the purge button. + $button.prop('disabled', false); + }) + + // Purge URLs. + .on('click', '.w3tc_cdn_bunnycdn_purge_urls', function() { + // Abort if Bunny CDN is not authorized. + if (! W3TC_Bunnycdn.is_authorized) { + return; + } + + // Declare vars. + var urls_processed = 0, + list = $('#w3tc-purge-urls').val().split("\n").filter((v) => v != ''), + $messages = $('#w3tc-purge-messages'), + $this = $(this); + + // Disable the button clicked and show a spinner. + $this + .prop('disabled', true) + .closest('p').addClass('lightbox-loader'); + + // Clear the messages div. + $messages.empty(); + + // Abort if nothing was submitted. + if (list.length < 1) { + $('', { + class: 'error', + text: W3TC_Bunnycdn.lang.empty_url + '.' + }).appendTo($messages); + + $this.closest('p').removeClass('lightbox-loader'); + + return; + } + + list.forEach(function(url, index, array) { + $.ajax({ + method: 'POST', + url: ajaxurl, + data: { + _wpnonce: w3tc_nonce[0], + action: 'w3tc_ajax', + w3tc_action: 'cdn_bunnycdn_purge_url', + url: url + } + }) + .done(function(response) { + // Possible success. + if (typeof response.success !== 'undefined') { + if (response.success) { + // Successful. + $('', { + class: 'updated', + text: W3TC_Bunnycdn.lang.success_purging + ' "' + url + '".' + }).appendTo($messages); + } else { + // Unsucessful. + $('', { + class: 'error', + text: W3TC_Bunnycdn.lang.error_purging + ' "' + url + '"; ' + response.data.error_message + '.' + }).appendTo($messages); + } + } else { + // Unknown error. + $('', { + class: 'error', + text: W3TC_Bunnycdn.lang.error_ajax + '.' + }).appendTo($messages); + } + }) + .fail(function(response) { + // Failure; received a non-2xx/3xx HTTP status code. + if (typeof response.responseJSON !== 'undefined' && 'data' in response.responseJSON && 'error_message' in response.responseJSON.data) { + // An error message was passed in the response data. + $('', { + class: 'error', + text: W3TC_Bunnycdn.lang.error_purging + ' "' + url + '"; ' + response.responseJSON.data.error_message + '.' + }).appendTo($messages); + } else { + // Unknown error. + $('', { + class: 'error', + text: W3TC_Bunnycdn.lang.error_ajax + '.' + }).appendTo($messages); + } + }) + .complete(function() { + urls_processed++; + + // When requests are all complete, then remove the spinner. + if (urls_processed === array.length) { + $this.closest('p').removeClass('lightbox-loader'); + } + }); + }); + }); +}); diff --git a/wp-content/plugins/w3-total-cache/Cdn_BunnyCdn_Page_View.php b/wp-content/plugins/w3-total-cache/Cdn_BunnyCdn_Page_View.php new file mode 100644 index 00000000..2487789f --- /dev/null +++ b/wp-content/plugins/w3-total-cache/Cdn_BunnyCdn_Page_View.php @@ -0,0 +1,130 @@ +get_string( 'cdn.bunnycdn.account_api_key' ); +$is_authorized = ! empty( $account_api_key ) && $config->get_string( 'cdn.bunnycdn.pull_zone_id' ); +$is_unavailable = ! empty( $account_api_key ) && $config->get_string( 'cdnfsd.bunnycdn.pull_zone_id' ); // CDN is unavailable if CDN FSD is authorized for Bunny CDN. + +?> ++ + | +
+
+
+
+ />
+
+
+
+
+
+ + + + |
+
---|---|
+ | + get_string( 'cdn.bunnycdn.name' ) ); ?> + | +
+ + | ++ get_string( 'cdn.bunnycdn.origin_url' ) ); ?> + | +
+ + | +
+
+ + ', + '' + ), + array( + 'acronym' => array( + 'title' => array(), + ), + ) + ); + ?> + + |
+
+ + | +
+
+
+ + /> + +', + 'Bunny CDN', + ' ' + ), + array( + 'div' => array( + 'class' => array(), + ), + 'p' => array(), + ) + ); + else : + ?> ++ + + |
+
---|
+ ' . \__( 'CDN', 'w3-total-cache' ) . '' + ) + ); + ?> +
+ + ++ ' . \__( 'CDN', 'w3-total-cache' ) . '' + ) + ); + ?> +
+ + ++ +
+ + + ++
++ ' . \__( 'CDN', 'w3-total-cache' ) . '' + ) + ); + ?> +
+ + + + + + +', + '', + '', + '' + ), + array( + 'acronym' => array( + 'title' => array(), + ), + 'a' => array( + 'href' => array(), + 'target' => array(), + ), + ) + ); + } + $config = Dispatcher::config(); $cdn_engine = $config->get_string( 'cdn.engine' ); $cdnfsd_engine = $config->get_string( 'cdnfsd.engine' ); @@ -61,16 +85,16 @@ Util_Ui::config_overloading_button(
+ ?>
+ ?> ', diff --git a/wp-content/plugins/w3-total-cache/Cdn_Page.php b/wp-content/plugins/w3-total-cache/Cdn_Page.php index d6427b63..71c66fc3 100644 --- a/wp-content/plugins/w3-total-cache/Cdn_Page.php +++ b/wp-content/plugins/w3-total-cache/Cdn_Page.php @@ -1,11 +1,18 @@ get_string( 'cdn.engine' ); - - $cdn_enabled = $config->get_boolean( 'cdn.enabled' ); - $cdn_mirror = Cdn_Util::is_engine_mirror( $cdn_engine ); + public function view() { + $config = Dispatcher::config(); + $account_api_key = $config->get_string( 'cdn.bunnycdn.account_api_key' ); + $cdn_engine = $config->get_string( 'cdn.engine' ); + $cdn_enabled = $config->get_boolean( 'cdn.enabled' ); + $is_cdn_authorized = ! empty( $account_api_key ) && ! empty( $config->get_string( 'cdn.bunnycdn.pull_zone_id' ) ); + $cdnfsd_engine = $config->get_string( 'cdnfsd.engine' ); + $cdnfsd_enabled = $config->get_boolean( 'cdnfsd.enabled' ); + $is_cdnfsd_authorized = ! empty( $account_api_key ) && ! empty( $config->get_string( 'cdnfsd.bunnycdn.pull_zone_id' ) ); + $cdn_mirror = Cdn_Util::is_engine_mirror( $cdn_engine ); $cdn_mirror_purge_all = Cdn_Util::can_purge_all( $cdn_engine ); - $cdn_common = Dispatcher::component( 'Cdn_Core' ); - - $cdn = $cdn_common->get_cdn(); - $cdn_supports_header = $cdn->headers_support() == W3TC_CDN_HEADER_MIRRORING; - $minify_enabled = ( + $cdn_common = Dispatcher::component( 'Cdn_Core' ); + $cdn = $cdn_common->get_cdn(); + $cdn_supports_header = $cdn->headers_support() == W3TC_CDN_HEADER_MIRRORING; + $minify_enabled = ( $config->get_boolean( 'minify.enabled' ) && Util_Rule::can_check_rules() && $config->get_boolean( 'minify.rewrite' ) && - ( !$config->get_boolean( 'minify.auto' ) || - Cdn_Util::is_engine_mirror( $config->get_string( 'cdn.engine' ) ) ) ); + ( ! $config->get_boolean( 'minify.auto' ) || Cdn_Util::is_engine_mirror( $config->get_string( 'cdn.engine' ) ) ) + ); + $cookie_domain = $this->get_cookie_domain(); + $set_cookie_domain = $this->is_cookie_domain_enabled(); - $cookie_domain = $this->get_cookie_domain(); - $set_cookie_domain = $this->is_cookie_domain_enabled(); - - // Required for Update Media Query String button - $browsercache_enabled = $config->get_boolean( 'browsercache.enabled' ); + // Required for Update Media Query String button. + $browsercache_enabled = $config->get_boolean( 'browsercache.enabled' ); $browsercache_update_media_qs = ( $config->get_boolean( 'browsercache.cssjs.replace' ) || $config->get_boolean( 'browsercache.other.replace' ) ); + include W3TC_INC_DIR . '/options/cdn.php'; } /** - * Returns cookie domain + * Returns cookie domain. * * @return string */ - function get_cookie_domain() { - $site_url = get_option( 'siteurl' ); + public function get_cookie_domain() { + $site_url = get_option( 'siteurl' ); $parse_url = @parse_url( $site_url ); - if ( $parse_url && !empty( $parse_url['host'] ) ) { + if ( $parse_url && ! empty( $parse_url['host'] ) ) { return $parse_url['host']; } @@ -60,11 +70,11 @@ class Cdn_Page extends Base_Page_Settings { } /** - * Checks if COOKIE_DOMAIN is enabled + * Checks if COOKIE_DOMAIN is enabled. * * @return bool */ - function is_cookie_domain_enabled() { + public function is_cookie_domain_enabled() { $cookie_domain = $this->get_cookie_domain(); return defined( 'COOKIE_DOMAIN' ) && COOKIE_DOMAIN == $cookie_domain; diff --git a/wp-content/plugins/w3-total-cache/Cdn_Page_View_Header.php b/wp-content/plugins/w3-total-cache/Cdn_Page_View_Header.php deleted file mode 100644 index ce5679fd..00000000 --- a/wp-content/plugins/w3-total-cache/Cdn_Page_View_Header.php +++ /dev/null @@ -1,30 +0,0 @@ - - - -- ' . esc_html( Cache::engine_name( $config->get_string( 'cdn.engine' ) ) ) . '', - '' . __( 'enabled', 'w3-total-cache' ) : 'disabled">' . __( 'disabled', 'w3-total-cache' ) ) . '' - ), - array( - 'strong' => array(), - 'span' => array( - 'class' => array(), - ), - ) - ); - ?> -
diff --git a/wp-content/plugins/w3-total-cache/Cdn_Plugin_Admin.php b/wp-content/plugins/w3-total-cache/Cdn_Plugin_Admin.php index 74934528..03f789f2 100644 --- a/wp-content/plugins/w3-total-cache/Cdn_Plugin_Admin.php +++ b/wp-content/plugins/w3-total-cache/Cdn_Plugin_Admin.php @@ -1,244 +1,241 @@ get_string( 'cdn.engine' ); if ( $c->get_boolean( 'cdn.enabled' ) ) { $admin_notes = new Cdn_AdminNotes(); - add_filter( 'w3tc_notes', array( $admin_notes, 'w3tc_notes' ) ); - add_filter( 'w3tc_errors', array( $admin_notes, 'w3tc_errors' ) ); + \add_filter( 'w3tc_notes', array( $admin_notes, 'w3tc_notes' ) ); + \add_filter( 'w3tc_errors', array( $admin_notes, 'w3tc_errors' ) ); - if ( $c->get_boolean( 'cdn.admin.media_library' ) && - $c->get_boolean( 'cdn.uploads.enable' ) ) { - - add_filter( 'wp_get_attachment_url', - array( $this, 'wp_get_attachment_url' ), 0 ); - - add_filter( 'attachment_link', - array( $this, 'wp_get_attachment_url' ), 0 ); + if ( $c->get_boolean( 'cdn.admin.media_library' ) && $c->get_boolean( 'cdn.uploads.enable' ) ) { + \add_filter( 'wp_get_attachment_url', array( $this, 'wp_get_attachment_url' ), 0 ); + \add_filter( 'attachment_link', array( $this, 'wp_get_attachment_url' ), 0 ); } } - - // attach to actions without firing class loading at all without need - if ( $cdn_engine == 'google_drive' ) { - add_action( 'w3tc_settings_cdn_boxarea_configuration', array( - '\W3TC\Cdn_GoogleDrive_Page', - 'w3tc_settings_cdn_boxarea_configuration' - ) ); - } elseif ( $cdn_engine == 'highwinds' ) { - add_action( 'w3tc_ajax', array( - '\W3TC\Cdn_Highwinds_Popup', - 'w3tc_ajax' ) ); - add_action( 'admin_init_w3tc_dashboard', array( - '\W3TC\Cdn_Highwinds_Widget', - 'admin_init_w3tc_dashboard' ) ); - add_action( 'w3tc_ajax_cdn_highwinds_widgetdata', array( - '\W3TC\Cdn_Highwinds_Widget', - 'w3tc_ajax_cdn_highwinds_widgetdata' ) ); - add_action( 'w3tc_settings_cdn_boxarea_configuration', array( - '\W3TC\Cdn_Highwinds_Page', - 'w3tc_settings_cdn_boxarea_configuration' ) ); - } elseif ( $cdn_engine == 'limelight' ) { - add_action( 'w3tc_ajax', array( - '\W3TC\Cdn_LimeLight_Popup', - 'w3tc_ajax' ) ); - add_action( 'w3tc_settings_cdn_boxarea_configuration', array( - '\W3TC\Cdn_LimeLight_Page', - 'w3tc_settings_cdn_boxarea_configuration' - ) ); - } elseif ( $cdn_engine == 'rackspace_cdn' ) { - add_filter( 'w3tc_admin_actions', array( - '\W3TC\Cdn_RackSpaceCdn_Page', - 'w3tc_admin_actions' ) ); - add_action( 'w3tc_ajax', array( - '\W3TC\Cdn_RackSpaceCdn_Popup', - 'w3tc_ajax' ) ); - add_action( 'w3tc_settings_cdn_boxarea_configuration', array( - '\W3TC\Cdn_RackSpaceCdn_Page', - 'w3tc_settings_cdn_boxarea_configuration' ) ); - } elseif ( $cdn_engine == 'rscf' ) { - add_action( 'w3tc_ajax', array( - '\W3TC\Cdn_RackSpaceCloudFiles_Popup', - 'w3tc_ajax' ) ); - add_action( 'w3tc_settings_cdn_boxarea_configuration', array( - '\W3TC\Cdn_RackSpaceCloudFiles_Page', - 'w3tc_settings_cdn_boxarea_configuration' ) ); - } elseif ( $cdn_engine == 'stackpath' ) { - add_action( 'w3tc_ajax', array( - '\W3TC\Cdn_StackPath_Popup', - 'w3tc_ajax' ) ); - add_action( 'w3tc_settings_cdn_boxarea_configuration', array( - '\W3TC\Cdn_StackPath_Page', - 'w3tc_settings_cdn_boxarea_configuration' - ) ); - add_action( 'admin_init_w3tc_dashboard', array( - '\W3TC\Cdn_StackPath_Widget', - 'admin_init_w3tc_dashboard' ) ); - add_action( 'w3tc_ajax_cdn_stackpath_widgetdata', array( - '\W3TC\Cdn_StackPath_Widget', - 'w3tc_ajax_cdn_stackpath_widgetdata' ) ); - } elseif ( $cdn_engine == 'stackpath2' ) { - add_action( 'w3tc_ajax', array( - '\W3TC\Cdn_StackPath2_Popup', - 'w3tc_ajax' ) ); - add_action( 'w3tc_settings_cdn_boxarea_configuration', array( - '\W3TC\Cdn_StackPath2_Page', - 'w3tc_settings_cdn_boxarea_configuration' - ) ); - add_action( 'admin_init_w3tc_dashboard', array( - '\W3TC\Cdn_StackPath2_Widget', - 'admin_init_w3tc_dashboard' ) ); - add_action( 'w3tc_ajax_cdn_stackpath2_widgetdata', array( - '\W3TC\Cdn_StackPath2_Widget', - 'w3tc_ajax_cdn_stackpath2_widgetdata' ) ); - } else { - // default cdn widget - add_action( 'admin_init_w3tc_dashboard', array( - '\W3TC\Cdn_StackPath2_Widget', - 'admin_init_w3tc_dashboard' ) ); - add_action( 'w3tc_ajax_cdn_stackpath2_widgetdata', array( - '\W3TC\Cdn_StackPath2_Widget', - 'w3tc_ajax_cdn_stackpath2_widgetdata' ) ); + // Attach to actions without firing class loading at all without need. + switch ( $cdn_engine ) { + case 'google_drive': + \add_action( 'w3tc_settings_cdn_boxarea_configuration', array( '\W3TC\Cdn_GoogleDrive_Page', 'w3tc_settings_cdn_boxarea_configuration' ) ); + break; + case 'highwinds': + \add_action( 'w3tc_ajax', array( '\W3TC\Cdn_Highwinds_Popup', 'w3tc_ajax' ) ); + \add_action( 'admin_init_w3tc_dashboard', array( '\W3TC\Cdn_Highwinds_Widget', 'admin_init_w3tc_dashboard' ) ); + \add_action( 'w3tc_ajax_cdn_highwinds_widgetdata', array( '\W3TC\Cdn_Highwinds_Widget', 'w3tc_ajax_cdn_highwinds_widgetdata' ) ); + \add_action( 'w3tc_settings_cdn_boxarea_configuration', array( '\W3TC\Cdn_Highwinds_Page', 'w3tc_settings_cdn_boxarea_configuration' ) ); + break; + case 'limelight': + \add_action( 'w3tc_ajax', array( '\W3TC\Cdn_LimeLight_Popup', 'w3tc_ajax' ) ); + \add_action( 'w3tc_settings_cdn_boxarea_configuration', array( '\W3TC\Cdn_LimeLight_Page', 'w3tc_settings_cdn_boxarea_configuration' ) ); + break; + case 'rackspace_cdn': + \add_filter( 'w3tc_admin_actions', array( '\W3TC\Cdn_RackSpaceCdn_Page', 'w3tc_admin_actions' ) ); + \add_action( 'w3tc_ajax', array( '\W3TC\Cdn_RackSpaceCdn_Popup', 'w3tc_ajax' ) ); + \add_action( 'w3tc_settings_cdn_boxarea_configuration', array( '\W3TC\Cdn_RackSpaceCdn_Page', 'w3tc_settings_cdn_boxarea_configuration' ) ); + break; + case 'rscf': + \add_action( 'w3tc_ajax', array( '\W3TC\Cdn_RackSpaceCloudFiles_Popup', 'w3tc_ajax' ) ); + \add_action( 'w3tc_settings_cdn_boxarea_configuration', array( '\W3TC\Cdn_RackSpaceCloudFiles_Page', 'w3tc_settings_cdn_boxarea_configuration' ) ); + break; + case 'stackpath': + \add_action( 'w3tc_ajax', array( '\W3TC\Cdn_StackPath_Popup', 'w3tc_ajax' ) ); + \add_action( 'w3tc_settings_cdn_boxarea_configuration', array( '\W3TC\Cdn_StackPath_Page', 'w3tc_settings_cdn_boxarea_configuration' ) ); + \add_action( 'admin_init_w3tc_dashboard', array( '\W3TC\Cdn_StackPath_Widget', 'admin_init_w3tc_dashboard' ) ); + \add_action( 'w3tc_ajax_cdn_stackpath_widgetdata', array( '\W3TC\Cdn_StackPath_Widget', 'w3tc_ajax_cdn_stackpath_widgetdata' ) ); + break; + case 'stackpath2': + \add_action( 'w3tc_ajax', array( '\W3TC\Cdn_StackPath2_Popup', 'w3tc_ajax' ) ); + \add_action( 'w3tc_settings_cdn_boxarea_configuration', array( '\W3TC\Cdn_StackPath2_Page', 'w3tc_settings_cdn_boxarea_configuration' ) ); + \add_action( 'admin_init_w3tc_dashboard', array( '\W3TC\Cdn_StackPath2_Widget', 'admin_init_w3tc_dashboard' ) ); + \add_action( 'w3tc_ajax_cdn_stackpath2_widgetdata', array( '\W3TC\Cdn_StackPath2_Widget', 'w3tc_ajax_cdn_stackpath2_widgetdata' ) ); + break; + case 'bunnycdn': + \add_action( 'w3tc_ajax', array( '\W3TC\Cdn_BunnyCdn_Page', 'w3tc_ajax' ) ); + \add_action( 'w3tc_ajax', array( '\W3TC\Cdn_BunnyCdn_Popup', 'w3tc_ajax' ) ); + \add_action( 'w3tc_settings_cdn_boxarea_configuration', array( '\W3TC\Cdn_BunnyCdn_Page', 'w3tc_settings_cdn_boxarea_configuration' ) ); + \add_action( 'admin_init_w3tc_dashboard', array( '\W3TC\Cdn_BunnyCdn_Widget', 'admin_init_w3tc_dashboard' ) ); + \add_action( 'w3tc_ajax_cdn_bunnycdn_widgetdata', array( '\W3TC\Cdn_BunnyCdn_Widget', 'w3tc_ajax_cdn_bunnycdn_widgetdata' ) ); + \add_action( 'w3tc_purge_urls_box', array( '\W3TC\Cdn_BunnyCdn_Page', 'w3tc_purge_urls_box' ) ); + // \add_filter( 'w3tc_dashboard_actions', array( '\W3TC\Cdn_BunnyCdn_Page', 'w3tc_dashboard_actions' ) ); // @todo Revisit this item. + break; + default: + \add_action( 'admin_init_w3tc_dashboard', array( '\W3TC\Cdn_BunnyCdn_Widget', 'admin_init_w3tc_dashboard' ) ); + \add_action( 'w3tc_ajax_cdn_bunnycdn_widgetdata', array( '\W3TC\Cdn_BunnyCdn_Widget', 'w3tc_ajax_cdn_bunnycdn_widgetdata' ) ); + break; } - add_action( 'w3tc_settings_general_boxarea_cdn', array( - $this, - 'w3tc_settings_general_boxarea_cdn' - ) ); + \add_action( 'w3tc_settings_general_boxarea_cdn', array( $this, 'w3tc_settings_general_boxarea_cdn' ) ); } - - + /** + * CDN settings. + * + * @return void + */ public function w3tc_settings_general_boxarea_cdn() { - $config = Dispatcher::config(); - - $engine_optgroups = array(); - $engine_values = array(); - - $optgroup_pull = count( $engine_optgroups ); - $engine_optgroups[] = __( 'Origin Pull / Mirror:', 'w3-total-cache' ); - - $optgroup_push = count( $engine_optgroups ); - $engine_optgroups[] = __( 'Origin Push:', 'w3-total-cache' ); + $config = Dispatcher::config(); + $engine_optgroups = array(); + $engine_values = array(); + $optgroup_pull = count( $engine_optgroups ); + $engine_optgroups[] = \__( 'Origin Pull / Mirror:', 'w3-total-cache' ); + $optgroup_push = count( $engine_optgroups ); + $engine_optgroups[] = \__( 'Origin Push:', 'w3-total-cache' ); + $engine_values[''] = array( + 'label' => 'Select a provider', + ); $engine_values['akamai'] = array( - 'label' => __( 'Akamai', 'w3-total-cache' ), - 'optgroup' => $optgroup_pull + 'label' => \__( 'Akamai', 'w3-total-cache' ), + 'optgroup' => $optgroup_pull, ); + $engine_values['cf2'] = array( - 'label' => __( 'Amazon CloudFront', 'w3-total-cache' ), - 'disabled' => ( !Util_Installed::curl() ? true : null ), - 'optgroup' => $optgroup_pull + 'label' => \__( 'Amazon CloudFront', 'w3-total-cache' ), + 'disabled' => ! Util_Installed::curl() ? true : null, + 'optgroup' => $optgroup_pull, ); + $engine_values['att'] = array( - 'label' => __( 'AT&T', 'w3-total-cache' ), - 'optgroup' => $optgroup_pull + 'label' => \__( 'AT&T', 'w3-total-cache' ), + 'optgroup' => $optgroup_pull, ); + + $engine_values['bunnycdn'] = array( + 'label' => \__( 'Bunny CDN (recommended)', 'w3-total-cache' ), + 'optgroup' => $optgroup_pull, + ); + $engine_values['cotendo'] = array( - 'label' => __( 'Cotendo (Akamai)', 'w3-total-cache' ), - 'optgroup' => $optgroup_pull + 'label' => \__( 'Cotendo (Akamai)', 'w3-total-cache' ), + 'optgroup' => $optgroup_pull, ); + $engine_values['mirror'] = array( - 'label' => __( 'Generic Mirror', 'w3-total-cache' ), - 'optgroup' => $optgroup_pull + 'label' => \__( 'Generic Mirror', 'w3-total-cache' ), + 'optgroup' => $optgroup_pull, ); + $engine_values['highwinds'] = array( - 'label' => __( 'Highwinds', 'w3-total-cache' ), - 'optgroup' => $optgroup_pull + 'label' => \__( 'Highwinds', 'w3-total-cache' ), + 'optgroup' => $optgroup_pull, ); + $engine_values['limelight'] = array( - 'label' => __( 'LimeLight', 'w3-total-cache' ), - 'optgroup' => $optgroup_pull + 'label' => \__( 'LimeLight', 'w3-total-cache' ), + 'optgroup' => $optgroup_pull, ); + $engine_values['rackspace_cdn'] = array( - 'label' => __( 'RackSpace CDN', 'w3-total-cache' ), - 'optgroup' => $optgroup_pull + 'label' => \__( 'RackSpace CDN', 'w3-total-cache' ), + 'optgroup' => $optgroup_pull, ); + $engine_values['stackpath2'] = array( - 'label' => __( 'StackPath (recommended)', 'w3-total-cache' ), - 'optgroup' => $optgroup_pull + 'label' => \__( 'StackPath', 'w3-total-cache' ), + 'optgroup' => $optgroup_pull, ); + $engine_values['stackpath'] = array( - 'label' => __( 'StackPath SecureCDN (Legacy)', 'w3-total-cache' ), - 'optgroup' => $optgroup_pull + 'label' => \__( 'StackPath SecureCDN (Legacy)', 'w3-total-cache' ), + 'optgroup' => $optgroup_pull, ); + $engine_values['edgecast'] = array( - 'label' => __( 'Verizon Digital Media Services (EdgeCast) / Media Temple ProCDN', 'w3-total-cache' ), - 'optgroup' => $optgroup_pull + 'label' => \__( 'Verizon Digital Media Services (EdgeCast) / Media Temple ProCDN', 'w3-total-cache' ), + 'optgroup' => $optgroup_pull, ); + $engine_values['cf'] = array( - 'disabled' => ( !Util_Installed::curl() ? true : null ), - 'label' => __( 'Amazon CloudFront Over S3', 'w3-total-cache' ), - 'optgroup' => $optgroup_push + 'disabled' => ! Util_Installed::curl() ? true : null, + 'label' => \__( 'Amazon CloudFront Over S3', 'w3-total-cache' ), + 'optgroup' => $optgroup_push, ); + $engine_values['s3'] = array( - 'disabled' => ( !Util_Installed::curl() ? true : null ), - 'label' => __( 'Amazon Simple Storage Service (S3)', 'w3-total-cache' ), - 'optgroup' => $optgroup_push + 'disabled' => ! Util_Installed::curl() ? true : null, + 'label' => \__( 'Amazon Simple Storage Service (S3)', 'w3-total-cache' ), + 'optgroup' => $optgroup_push, ); + $engine_values['s3_compatible'] = array( - 'disabled' => ( !Util_Installed::curl() ? true : null ), - 'label' => __( 'Amazon Simple Storage Service (S3) Compatible', 'w3-total-cache' ), - 'optgroup' => $optgroup_push + 'disabled' => ! Util_Installed::curl() ? true : null, + 'label' => \__( 'Amazon Simple Storage Service (S3) Compatible', 'w3-total-cache' ), + 'optgroup' => $optgroup_push, ); + $engine_values['google_drive'] = array( - 'label' => __( 'Google Drive', 'w3-total-cache' ), - 'optgroup' => $optgroup_push + 'label' => \__( 'Google Drive', 'w3-total-cache' ), + 'optgroup' => $optgroup_push, ); + $engine_values['azure'] = array( - 'label' => __( 'Microsoft Azure Storage', 'w3-total-cache' ), - 'optgroup' => $optgroup_push + 'label' => \__( 'Microsoft Azure Storage', 'w3-total-cache' ), + 'optgroup' => $optgroup_push, ); + $engine_values['rscf'] = array( - 'disabled' => ( !Util_Installed::curl() ? true : null ), - 'label' => __( 'Rackspace Cloud Files', 'w3-total-cache' ), - 'optgroup' => $optgroup_push + 'disabled' => ! Util_Installed::curl() ? true : null, + 'label' => \__( 'Rackspace Cloud Files', 'w3-total-cache' ), + 'optgroup' => $optgroup_push, ); + $engine_values['ftp'] = array( - 'disabled' => ( !Util_Installed::ftp() ? true : null ), - 'label' => __( 'Self-hosted / File Transfer Protocol Upload', 'w3-total-cache' ), - 'optgroup' => $optgroup_push + 'disabled' => ! Util_Installed::ftp() ? true : null, + 'label' => \__( 'Self-hosted / File Transfer Protocol Upload', 'w3-total-cache' ), + 'optgroup' => $optgroup_push, ); $cdn_enabled = $config->get_boolean( 'cdn.enabled' ); - $cdn_engine = $config->get_string( 'cdn.engine' ); + $cdn_engine = $config->get_string( 'cdn.engine' ); - include W3TC_DIR . '/Cdn_GeneralPage_View.php'; + include W3TC_DIR . '/Cdn_GeneralPage_View.php'; } - - /** - * Adjusts attachment urls to cdn. This is for those who rely on - * wp_get_attachment_url() + * Adjusts attachment urls to cdn. This is for those who rely on wp_get_attachment_url(). * - * @param string $url the local url to modify - * @return string + * @param string $url The local url to modify. + * @return string */ - function wp_get_attachment_url( $url ) { + public function wp_get_attachment_url( $url ) { if ( defined( 'WP_ADMIN' ) ) { $url = trim( $url ); - if ( !empty( $url ) ) { - $parsed = parse_url( $url ); - $uri = ( isset( $parsed['path'] ) ? $parsed['path'] : '/' ) . + if ( ! empty( $url ) ) { + $parsed = \parse_url( $url ); + $uri = ( isset( $parsed['path'] ) ? $parsed['path'] : '/' ) . ( isset( $parsed['query'] ) ? '?' . $parsed['query'] : '' ); - - $wp_upload_dir = wp_upload_dir(); + $wp_upload_dir = \wp_upload_dir(); $upload_base_url = $wp_upload_dir['baseurl']; - if ( substr($url, 0, strlen( $upload_base_url ) ) == $upload_base_url ) { - $common = Dispatcher::component( 'Cdn_Core' ); + if ( \substr( $url, 0, strlen( $upload_base_url ) ) === $upload_base_url ) { + $common = Dispatcher::component( 'Cdn_Core' ); $new_url = $common->url_to_cdn_url( $url, $uri ); - if ( !is_null( $new_url ) ) { + if ( ! is_null( $new_url ) ) { $url = $new_url; } } diff --git a/wp-content/plugins/w3-total-cache/Cdn_StackPath2_Page_View.php b/wp-content/plugins/w3-total-cache/Cdn_StackPath2_Page_View.php index d8d600b6..ccb61058 100644 --- a/wp-content/plugins/w3-total-cache/Cdn_StackPath2_Page_View.php +++ b/wp-content/plugins/w3-total-cache/Cdn_StackPath2_Page_View.php @@ -1,9 +1,14 @@+ + | +
+
+
+
+ />
+
+
+
+
+
+ + + + |
+
---|---|
+ | + get_string( 'cdnfsd.bunnycdn.name' ) ); ?> + | +
+ + | ++ get_string( 'cdnfsd.bunnycdn.origin_url' ) ); ?> + | +
+ + | +
+ get_string( 'cdnfsd.bunnycdn.cdn_hostname' ) ); ?>
+ + ', + '', + '' + ), + array( + 'acronym' => array( + 'title' => array(), + ), + ) + ); + ?> + + |
+
- -
- ' . Cdnfsd_Util::engine_name( $config->get_string( 'cdnfsd.engine' ) ) . '', - '' . __( 'enabled', 'w3-total-cache' ) : 'disabled">' . __( 'disabled', 'w3-total-cache' ) ) . '' - ), - array( - 'strong' => array(), - 'span' => array( - 'class' => array(), - ), - ) - ); - ?> -
diff --git a/wp-content/plugins/w3-total-cache/Cdnfsd_Plugin_Admin.php b/wp-content/plugins/w3-total-cache/Cdnfsd_Plugin_Admin.php index 36f520a0..c6f1dc28 100644 --- a/wp-content/plugins/w3-total-cache/Cdnfsd_Plugin_Admin.php +++ b/wp-content/plugins/w3-total-cache/Cdnfsd_Plugin_Admin.php @@ -1,102 +1,108 @@ get_string( 'cdnfsd.engine' ); - // attach to actions without firing class loading at all without need - if ( $cdnfsd_engine == 'cloudfront' ) { - add_action( 'w3tc_ajax', array( - '\W3TC\Cdnfsd_CloudFront_Popup', - 'w3tc_ajax' ) ); - add_action( 'w3tc_settings_box_cdnfsd', array( - '\W3TC\Cdnfsd_CloudFront_Page', - 'w3tc_settings_box_cdnfsd' ) ); - } elseif ( $cdnfsd_engine == 'limelight' ) { - add_action( 'w3tc_ajax', array( - '\W3TC\Cdnfsd_LimeLight_Popup', - 'w3tc_ajax' ) ); - add_action( 'w3tc_settings_box_cdnfsd', array( - '\W3TC\Cdnfsd_LimeLight_Page', - 'w3tc_settings_box_cdnfsd' ) ); - } elseif ( $cdnfsd_engine == 'stackpath' ) { - add_action( 'w3tc_ajax', array( - '\W3TC\Cdnfsd_StackPath_Popup', - 'w3tc_ajax' ) ); - add_action( 'w3tc_settings_box_cdnfsd', array( - '\W3TC\Cdnfsd_StackPath_Page', - 'w3tc_settings_box_cdnfsd' ) ); - } elseif ( $cdnfsd_engine == 'stackpath2' ) { - add_action( 'w3tc_ajax', array( - '\W3TC\Cdnfsd_StackPath2_Popup', - 'w3tc_ajax' ) ); - add_action( 'w3tc_settings_box_cdnfsd', array( - '\W3TC\Cdnfsd_StackPath2_Page', - 'w3tc_settings_box_cdnfsd' ) ); - } elseif ( 'transparentcdn' === $cdnfsd_engine ){ - add_action( 'init', array( - '\W3TC\Cdnfsd_TransparentCDN_Page', - 'admin_test_api_parameters_transparentcdn' ) ); - add_action( 'w3tc_settings_box_cdnfsd', array( - '\W3TC\Cdnfsd_TransparentCDN_Page', - 'w3tc_settings_box_cdnfsd' ) ); + // Attach to actions without firing class loading at all without need. + switch ( $cdnfsd_engine ) { + case 'cloudfront': + add_action( 'w3tc_ajax', array( '\W3TC\Cdnfsd_CloudFront_Popup', 'w3tc_ajax' ) ); + add_action( 'w3tc_settings_box_cdnfsd', array( '\W3TC\Cdnfsd_CloudFront_Page', 'w3tc_settings_box_cdnfsd' ) ); + break; + case 'limelight': + add_action( 'w3tc_ajax', array( '\W3TC\Cdnfsd_LimeLight_Popup', 'w3tc_ajax' ) ); + add_action( 'w3tc_settings_box_cdnfsd', array( '\W3TC\Cdnfsd_LimeLight_Page', 'w3tc_settings_box_cdnfsd' ) ); + break; + case 'stackpath': + add_action( 'w3tc_ajax', array( '\W3TC\Cdnfsd_StackPath_Popup', 'w3tc_ajax' ) ); + add_action( 'w3tc_settings_box_cdnfsd', array( '\W3TC\Cdnfsd_StackPath_Page', 'w3tc_settings_box_cdnfsd' ) ); + break; + case 'stackpath2': + add_action( 'w3tc_ajax', array( '\W3TC\Cdnfsd_StackPath2_Popup', 'w3tc_ajax' ) ); + add_action( 'w3tc_settings_box_cdnfsd', array( '\W3TC\Cdnfsd_StackPath2_Page', 'w3tc_settings_box_cdnfsd' ) ); + break; + case 'transparentcdn': + add_action( 'init', array( '\W3TC\Cdnfsd_TransparentCDN_Page', 'admin_test_api_parameters_transparentcdn' ) ); + add_action( 'w3tc_settings_box_cdnfsd', array( '\W3TC\Cdnfsd_TransparentCDN_Page', 'w3tc_settings_box_cdnfsd' ) ); + break; + case 'bunnycdn': + add_action( 'w3tc_ajax', array( '\W3TC\Cdnfsd_BunnyCdn_Popup', 'w3tc_ajax' ) ); + add_action( 'w3tc_settings_box_cdnfsd', array( '\W3TC\Cdnfsd_BunnyCdn_Page', 'w3tc_settings_box_cdnfsd' ) ); + break; + default: + break; } - add_action( 'w3tc_settings_general_boxarea_cdn_footer', - array( $this, 'w3tc_settings_general_boxarea_cdn_footer' ) ); + add_action( 'w3tc_settings_general_boxarea_cdn_footer', array( $this, 'w3tc_settings_general_boxarea_cdn_footer' ) ); } - - + /** + * Print the general settings page CDN footer. + */ public function w3tc_settings_general_boxarea_cdn_footer() { - $config = Dispatcher::config(); - - $cdnfsd_enabled = $config->get_boolean( 'cdnfsd.enabled' ); - $cdnfsd_engine = $config->get_string( 'cdnfsd.engine' ); - - $is_pro = Util_Environment::is_w3tc_pro( $config ); - + $config = Dispatcher::config(); + $cdnfsd_enabled = $config->get_boolean( 'cdnfsd.enabled' ); + $cdnfsd_engine = $config->get_string( 'cdnfsd.engine' ); + $is_pro = Util_Environment::is_w3tc_pro( $config ); $cdnfsd_engine_values = array(); + $tag = ''; + $cdnfsd_engine_values[''] = array( 'label' => 'Select a provider', ); + + $cdnfsd_engine_values['bunnycdn'] = array( + 'label' => __( 'Bunny CDN (recommended)', 'w3-total-cache' ), + ); + $cdnfsd_engine_values['cloudfront'] = array( 'label' => __( 'Amazon CloudFront', 'w3-total-cache' ), ); + $cdnfsd_engine_values['cloudflare'] = array( 'label' => __( 'CloudFlare (extension not activated)', 'w3-total-cache' ), 'disabled' => true, ); + $cdnfsd_engine_values['limelight'] = array( 'label' => __( 'Limelight', 'w3-total-cache' ), ); + $cdnfsd_engine_values['stackpath'] = array( 'label' => __( 'StackPath SecureCDN (Legacy)', 'w3-total-cache' ), ); + $cdnfsd_engine_values['stackpath2'] = array( - 'label' => __( 'StackPath (recommended)', 'w3-total-cache' ), + 'label' => __( 'StackPath', 'w3-total-cache' ), ); + $cdnfsd_engine_values['transparentcdn'] = array( 'label' => __( 'TransparentCDN', 'w3-total-cache' ), ); - $tag = ''; - if ( $cdnfsd_engine == 'cloudfront' ) { + if ( 'cloudfront' === $cdnfsd_engine ) { $tag = 'https://api.w3-edge.com/v1/redirects/faq/cdn-fsd/cloudfront'; - } elseif ( $cdnfsd_engine == 'stackpath' || $cdnfsd_engine == 'stackpath2' ) { + } elseif ( 'stackpath' === $cdnfsd_engine || 'stackpath2' === $cdnfsd_engine ) { $tag = 'https://api.w3-edge.com/v1/redirects/faq/cdn-fsd/stackpath'; } - if ( empty( $tag ) ) { - $cdnfsd_engine_extra_description = ''; - } else { - $cdnfsd_engine_extra_description = - ' See setup instructions'; - } + $cdnfsd_engine_extra_description = empty( $tag ) ? '' : ' See setup instructions'; - include W3TC_DIR . '/Cdnfsd_GeneralPage_View.php'; + include W3TC_DIR . '/Cdnfsd_GeneralPage_View.php'; } } diff --git a/wp-content/plugins/w3-total-cache/Cdnfsd_StackPath2_Popup.php b/wp-content/plugins/w3-total-cache/Cdnfsd_StackPath2_Popup.php index 5fc2db0d..f7f07765 100644 --- a/wp-content/plugins/w3-total-cache/Cdnfsd_StackPath2_Popup.php +++ b/wp-content/plugins/w3-total-cache/Cdnfsd_StackPath2_Popup.php @@ -50,7 +50,7 @@ class Cdnfsd_StackPath2_Popup { $api = new Cdn_StackPath2_Api( $api_config ); try { - $r = $r = $api->stacks_list(); + $r = $api->stacks_list(); $stacks = $r['results']; } catch ( \Exception $ex ) { $error_message = 'Can\'t authenticate: ' . $ex->getMessage(); diff --git a/wp-content/plugins/w3-total-cache/Cdnfsd_StackPath_Engine.php b/wp-content/plugins/w3-total-cache/Cdnfsd_StackPath_Engine.php index b2a03805..c55bb3b3 100644 --- a/wp-content/plugins/w3-total-cache/Cdnfsd_StackPath_Engine.php +++ b/wp-content/plugins/w3-total-cache/Cdnfsd_StackPath_Engine.php @@ -10,6 +10,7 @@ class Cdnfsd_StackPath_Engine { function __construct( $config = array() ) { +error_log( __METHOD__ . ': ' . print_r( debug_backtrace( 0 ), true ) ); $this->api_key = $config['api_key']; $this->zone_id = $config['zone_id']; } diff --git a/wp-content/plugins/w3-total-cache/ConfigState.php b/wp-content/plugins/w3-total-cache/ConfigState.php index 80a4dc80..a51f5de3 100644 --- a/wp-content/plugins/w3-total-cache/ConfigState.php +++ b/wp-content/plugins/w3-total-cache/ConfigState.php @@ -50,6 +50,7 @@ namespace W3TC; * objectcache.show_note.flush_needed * objectcache.show_note.flush_needed.timestamp - when the note was set * extension.' . Cache::engine_name( $this->_config->get_string( 'cdn.engine' ) ) . '', - '' . esc_html__( 'enabled', 'w3-total-cache' ) : 'disabled">' . esc_html__( 'disabled', 'w3-total-cache' ) ) . '' + '' . esc_html__( 'enabled', 'w3-total-cache' ) : 'disabled">' . esc_html__( 'disabled', 'w3-total-cache' ) ) . '', + ' ' + ), + array( + 'strong' => array(), + 'span' => array( + 'class' => array(), + ), + ) + ); + ?> +
++ ' . Cache::engine_name( $this->_config->get_string( 'cdnfsd.engine' ) ) . '', + '' . esc_html__( 'enabled', 'w3-total-cache' ) : 'disabled">' . esc_html__( 'disabled', 'w3-total-cache' ) ) . '', + ' ' ), array( 'strong' => array(), @@ -42,46 +63,89 @@ require W3TC_INC_DIR . '/options/common/header.php'; ?>