apache
wp-content
mu-plugins
plugins
activitypub
audioigniter
authldap
companion-auto-update
gitium
gp-premium
jetpack-protect
menu-icons
simple-local-avatars
smtp-mailer
two-factor
w3-total-cache
extension-example
inc
ini
languages
lib
pub
vendor
wp-content
Base_Page_Settings.php
BrowserCache_ConfigLabels.php
BrowserCache_Core.php
BrowserCache_Environment.php
BrowserCache_Environment_Apache.php
BrowserCache_Environment_LiteSpeed.php
BrowserCache_Environment_Nginx.php
BrowserCache_Page.php
BrowserCache_Page_View_QuickReference.php
BrowserCache_Page_View_SectionSecurity.php
BrowserCache_Plugin.php
BrowserCache_Plugin_Admin.php
Cache.php
CacheFlush.php
CacheFlush_Locally.php
CacheGroups_Plugin_Admin.php
CacheGroups_Plugin_Admin_View.js
CacheGroups_Plugin_Admin_View.php
Cache_Apc.php
Cache_Apcu.php
Cache_Base.php
Cache_Eaccelerator.php
Cache_File.php
Cache_File_Cleaner.php
Cache_File_Cleaner_Generic.php
Cache_File_Cleaner_Generic_HardDelete.php
Cache_File_Generic.php
Cache_Memcache.php
Cache_Memcached.php
Cache_Memcached_Stats.php
Cache_Nginx_Memcached.php
Cache_Redis.php
Cache_Wincache.php
Cache_Xcache.php
CdnEngine.php
CdnEngine_Azure.php
CdnEngine_Base.php
CdnEngine_CloudFront.php
CdnEngine_Ftp.php
CdnEngine_GoogleDrive.php
CdnEngine_Mirror.php
CdnEngine_Mirror_Akamai.php
CdnEngine_Mirror_Att.php
CdnEngine_Mirror_CloudFront.php
CdnEngine_Mirror_Cotendo.php
CdnEngine_Mirror_Edgecast.php
CdnEngine_Mirror_Highwinds.php
CdnEngine_Mirror_LimeLight.php
CdnEngine_Mirror_RackSpaceCdn.php
CdnEngine_Mirror_StackPath.php
CdnEngine_Mirror_StackPath2.php
CdnEngine_RackSpaceCloudFiles.php
CdnEngine_S3.php
CdnEngine_S3_Compatible.php
Cdn_AdminActions.php
Cdn_AdminNotes.php
Cdn_CacheFlush.php
Cdn_ConfigLabels.php
Cdn_Core.php
Cdn_Core_Admin.php
Cdn_Environment.php
Cdn_Environment_LiteSpeed.php
Cdn_Environment_Nginx.php
Cdn_GeneralPage_View.php
Cdn_GoogleDrive_AdminActions.php
Cdn_GoogleDrive_Page.php
Cdn_GoogleDrive_Page_View.js
Cdn_GoogleDrive_Page_View.php
Cdn_GoogleDrive_Popup_AuthReturn.php
Cdn_GoogleDrive_Popup_AuthReturn_View.php
Cdn_Highwinds_Api.php
Cdn_Highwinds_Page.php
Cdn_Highwinds_Page_View.js
Cdn_Highwinds_Page_View.php
Cdn_Highwinds_Popup.php
Cdn_Highwinds_Popup_View_ConfigureCnamesForm.php
Cdn_Highwinds_Popup_View_Intro.php
Cdn_Highwinds_Popup_View_SelectHost.php
Cdn_Highwinds_Widget.php
Cdn_Highwinds_Widget_View.css
Cdn_Highwinds_Widget_View.js
Cdn_Highwinds_Widget_View.php
Cdn_Highwinds_Widget_View_NotConfigured.php
Cdn_LimeLight_Page.php
Cdn_LimeLight_Page_View.js
Cdn_LimeLight_Page_View.php
Cdn_LimeLight_Popup.php
Cdn_LimeLight_Popup_View_Intro.php
Cdn_LimeLight_Popup_View_Success.php
Cdn_Page.php
Cdn_Page_View_Fsd_HeaderActions.php
Cdn_Page_View_Header.php
Cdn_Plugin.php
Cdn_Plugin_Admin.php
Cdn_RackSpaceCdn_AdminActions.php
Cdn_RackSpaceCdn_Page.php
Cdn_RackSpaceCdn_Page_View.js
Cdn_RackSpaceCdn_Page_View.php
Cdn_RackSpaceCdn_Popup.php
Cdn_RackSpaceCdn_Popup_View_ConfigureDomains.php
Cdn_RackSpaceCdn_Popup_View_Intro.php
Cdn_RackSpaceCdn_Popup_View_Regions.php
Cdn_RackSpaceCdn_Popup_View_Service_Actualize.php
Cdn_RackSpaceCdn_Popup_View_Service_Create.php
Cdn_RackSpaceCdn_Popup_View_Service_Created.php
Cdn_RackSpaceCdn_Popup_View_Services.php
Cdn_RackSpaceCloudFiles_Page.php
Cdn_RackSpaceCloudFiles_Page_View.js
Cdn_RackSpaceCloudFiles_Page_View.php
Cdn_RackSpaceCloudFiles_Popup.php
Cdn_RackSpaceCloudFiles_Popup_View_Containers.php
Cdn_RackSpaceCloudFiles_Popup_View_Intro.php
Cdn_RackSpaceCloudFiles_Popup_View_Regions.php
Cdn_RackSpace_Api_CaCert-example.pem
Cdn_RackSpace_Api_Cdn.php
Cdn_RackSpace_Api_CloudFiles.php
Cdn_RackSpace_Api_CloudFilesCdn.php
Cdn_RackSpace_Api_Tokens.php
Cdn_StackPath2_Api.php
Cdn_StackPath2_Page.php
Cdn_StackPath2_Page_View.js
Cdn_StackPath2_Page_View.php
Cdn_StackPath2_Popup.php
Cdn_StackPath2_Popup_View_Intro.php
Cdn_StackPath2_Popup_View_Sites.php
Cdn_StackPath2_Popup_View_Stacks.php
Cdn_StackPath2_Popup_View_Success.php
Cdn_StackPath2_Widget.php
Cdn_StackPath2_Widget_View.css
Cdn_StackPath2_Widget_View.js
Cdn_StackPath2_Widget_View_Authorized.php
Cdn_StackPath2_Widget_View_Unauthorized.php
Cdn_StackPath_Api.php
Cdn_StackPath_Page.php
Cdn_StackPath_Page_View.js
Cdn_StackPath_Page_View.php
Cdn_StackPath_Popup.php
Cdn_StackPath_Popup_View_Intro.php
Cdn_StackPath_Popup_View_Success.php
Cdn_StackPath_Popup_View_Zone.php
Cdn_StackPath_Popup_View_Zones.php
Cdn_StackPath_Widget.php
Cdn_StackPath_Widget_View.css
Cdn_StackPath_Widget_View.js
Cdn_StackPath_Widget_View_Authorized.php
Cdn_StackPath_Widget_View_Unauthorized.php
Cdn_Util.php
Cdnfsd_CacheFlush.php
Cdnfsd_CloudFront_Engine.php
Cdnfsd_CloudFront_Page.php
Cdnfsd_CloudFront_Page_View.js
Cdnfsd_CloudFront_Page_View.php
Cdnfsd_CloudFront_Popup.php
Cdnfsd_CloudFront_Popup_View_Distribution.php
Cdnfsd_CloudFront_Popup_View_Distributions.php
Cdnfsd_CloudFront_Popup_View_Intro.php
Cdnfsd_CloudFront_Popup_View_Success.php
Cdnfsd_Core.php
Cdnfsd_GeneralPage_View.php
Cdnfsd_LimeLight_Api.php
Cdnfsd_LimeLight_Engine.php
Cdnfsd_LimeLight_Page.php
Cdnfsd_LimeLight_Page_View.js
Cdnfsd_LimeLight_Page_View.php
Cdnfsd_LimeLight_Popup.php
Cdnfsd_LimeLight_Popup_View_Intro.php
Cdnfsd_LimeLight_Popup_View_Success.php
Cdnfsd_Page_View_Header.php
Cdnfsd_Plugin.php
Cdnfsd_Plugin_Admin.php
Cdnfsd_StackPath2_Engine.php
Cdnfsd_StackPath2_Page.php
Cdnfsd_StackPath2_Page_View.js
Cdnfsd_StackPath2_Page_View.php
Cdnfsd_StackPath2_Popup.php
Cdnfsd_StackPath2_Popup_View_Intro.php
Cdnfsd_StackPath2_Popup_View_Sites.php
Cdnfsd_StackPath2_Popup_View_Stacks.php
Cdnfsd_StackPath2_Popup_View_Success.php
Cdnfsd_StackPath_Engine.php
Cdnfsd_StackPath_Page.php
Cdnfsd_StackPath_Page_View.js
Cdnfsd_StackPath_Page_View.php
Cdnfsd_StackPath_Popup.php
Cdnfsd_StackPath_Popup_View_Intro.php
Cdnfsd_StackPath_Popup_View_Success.php
Cdnfsd_StackPath_Popup_View_Zone.php
Cdnfsd_StackPath_Popup_View_Zones.php
Cdnfsd_TransparentCDN_Engine.php
Cdnfsd_TransparentCDN_Page.php
Cdnfsd_TransparentCDN_Page_View.js
Cdnfsd_TransparentCDN_Page_View.php
Cdnfsd_Util.php
Cli.php
Config.php
ConfigCache.php
ConfigCompiler.php
ConfigDbStorage.php
ConfigKeys.php
ConfigState.php
ConfigStateNote.php
ConfigUtil.php
DbCache_ConfigLabels.php
DbCache_Core.php
DbCache_Environment.php
DbCache_Page.php
DbCache_Plugin.php
DbCache_Plugin_Admin.php
DbCache_Wpdb.php
DbCache_WpdbBase.php
DbCache_WpdbInjection.php
DbCache_WpdbInjection_QueryCaching.php
DbCache_WpdbLegacy.php
DbCache_WpdbNew.php
Dispatcher.php
Enterprise_CacheFlush_MakeSnsEvent.php
Enterprise_Dbcache_WpdbInjection_Cluster.php
Enterprise_SnsBase.php
Enterprise_SnsServer.php
Extension_Amp_Page_View.php
Extension_Amp_Plugin.php
Extension_Amp_Plugin_Admin.php
Extension_CloudFlare_AdminActions.php
Extension_CloudFlare_Api.php
Extension_CloudFlare_Cdn_Page_View.php
Extension_CloudFlare_GeneralPage_View.php
Extension_CloudFlare_Page.php
Extension_CloudFlare_Page_View.js
Extension_CloudFlare_Page_View.php
Extension_CloudFlare_Plugin.php
Extension_CloudFlare_Plugin_Admin.php
Extension_CloudFlare_Popup.php
Extension_CloudFlare_Popup_View_Intro.php
Extension_CloudFlare_Popup_View_Zones.php
Extension_CloudFlare_SettingsForUi.php
Extension_CloudFlare_View_Dashboard.js
Extension_CloudFlare_Widget.php
Extension_CloudFlare_Widget_Logo.png
Extension_CloudFlare_Widget_View.css
Extension_CloudFlare_Widget_View.php
Extension_FragmentCache_Api.php
Extension_FragmentCache_Core.php
Extension_FragmentCache_Environment.php
Extension_FragmentCache_GeneralPage.php
Extension_FragmentCache_GeneralPage_View.php
Extension_FragmentCache_Page.php
Extension_FragmentCache_Page_View.php
Extension_FragmentCache_Plugin.php
Extension_FragmentCache_Plugin_Admin.php
Extension_FragmentCache_WpObjectCache.php
Extension_Genesis_Page.php
Extension_Genesis_Page_View.php
Extension_Genesis_Plugin.php
Extension_Genesis_Plugin_Admin.php
Extension_ImageService_Api.php
Extension_ImageService_Cron.php
Extension_ImageService_Environment.php
Extension_ImageService_Page_View.php
Extension_ImageService_Plugin.php
Extension_ImageService_Plugin_Admin.css
Extension_ImageService_Plugin_Admin.js
Extension_ImageService_Plugin_Admin.php
Extension_NewRelic_AdminActions.php
Extension_NewRelic_AdminNotes.php
Extension_NewRelic_Api.php
Extension_NewRelic_Core.php
Extension_NewRelic_GeneralPage.php
Extension_NewRelic_GeneralPage_View.php
Extension_NewRelic_Page.php
Extension_NewRelic_Page_View_Apm.php
Extension_NewRelic_Plugin.php
Extension_NewRelic_Plugin_Admin.php
Extension_NewRelic_Popup.php
Extension_NewRelic_Popup_View.js
Extension_NewRelic_Popup_View_Intro.php
Extension_NewRelic_Popup_View_ListApplications.php
Extension_NewRelic_Service.php
Extension_NewRelic_Widget.php
Extension_NewRelic_Widget_View.css
Extension_NewRelic_Widget_View.js
Extension_NewRelic_Widget_View_Apm.php
Extension_NewRelic_Widget_View_Browser.php
Extension_NewRelic_Widget_View_NotConfigured.php
Extension_Swarmify_AdminActions.php
Extension_Swarmify_Core.php
Extension_Swarmify_Page.php
Extension_Swarmify_Page_View.php
Extension_Swarmify_Plugin.php
Extension_Swarmify_Plugin_Admin.php
Extension_Swarmify_Widget.php
Extension_Swarmify_Widget_View.css
Extension_Swarmify_Widget_View_NotConfigured.php
Extension_WordPressSeo_Plugin.php
Extension_WordPressSeo_Plugin_Admin.php
Extension_Wpml_Plugin.php
Extension_Wpml_Plugin_Admin.php
Extensions_AdminActions.php
Extensions_Page.php
Extensions_Plugin_Admin.php
Extensions_Util.php
FeatureShowcase_Plugin_Admin.php
FeatureShowcase_Plugin_Admin_View.php
Generic_AdminActions_Config.php
Generic_AdminActions_Default.php
Generic_AdminActions_Flush.php
Generic_AdminActions_Test.php
Generic_AdminNotes.php
Generic_ConfigLabels.php
Generic_Environment.php
Generic_Faq.php
Generic_GeneralPage_View_ShowEdge.js
Generic_GeneralPage_View_ShowSupportUs.js
Generic_Page_About.php
Generic_Page_Dashboard.php
Generic_Page_Dashboard_View.css
Generic_Page_General.php
Generic_Page_Install.php
Generic_Page_PurgeLog.php
Generic_Page_PurgeLog_View.php
Generic_Plugin.php
Generic_Plugin_Admin.php
Generic_Plugin_AdminCompatibility.php
Generic_Plugin_AdminNotifications.php
Generic_Plugin_AdminRowActions.php
Generic_Plugin_Admin_View_Faq.php
Generic_Plugin_WidgetForum.php
Generic_Plugin_WidgetNews.php
Generic_WidgetBoldGrid.php
Generic_WidgetBoldGrid_AdminActions.php
Generic_WidgetBoldGrid_Logo.svg
Generic_WidgetBoldGrid_View.js
Generic_WidgetBoldGrid_View.php
Generic_WidgetCommunity.php
Generic_WidgetCommunity_View.php
Generic_WidgetServices.php
Generic_WidgetServices_View.php
Generic_WidgetSpreadTheWord.js
Generic_WidgetSpreadTheWord_Plugin.php
Generic_WidgetSpreadTheWord_View.php
LICENSE
Licensing_AdminActions.php
Licensing_Core.php
Licensing_Plugin_Admin.php
Minify_AutoCss.php
Minify_AutoJs.php
Minify_ConfigLabels.php
Minify_ContentMinifier.php
Minify_Core.php
Minify_Environment.php
Minify_Environment_LiteSpeed.php
Minify_Extract.php
Minify_GeneralPage_View_ShowHelp.js
Minify_GeneralPage_View_ShowHelpForce.js
Minify_HelpPopup_View.php
Minify_MinifiedFileRequestHandler.php
Minify_Page.php
Minify_Plugin.php
Minify_Plugin_Admin.php
Mobile_Base.php
Mobile_Redirect.php
Mobile_Referrer.php
Mobile_UserAgent.php
ModuleStatus.php
ObjectCache_ConfigLabels.php
ObjectCache_Environment.php
ObjectCache_Page.php
ObjectCache_Page_View_PurgeLog.php
ObjectCache_Plugin.php
ObjectCache_Plugin_Admin.php
ObjectCache_WpObjectCache.php
ObjectCache_WpObjectCache_Regular.php
PageSpeed_Api.php
PageSpeed_Data.php
PageSpeed_Instructions.php
PageSpeed_Page.php
PageSpeed_Page_View.css
PageSpeed_Page_View.js
PageSpeed_Page_View.php
PageSpeed_Page_View_FromAPI.php
PageSpeed_Widget.php
PageSpeed_Widget_View.css
PageSpeed_Widget_View.js
PageSpeed_Widget_View.php
PageSpeed_Widget_View_FromApi.php
PgCache_ConfigLabels.php
PgCache_ContentGrabber.php
PgCache_Environment.php
PgCache_Flush.php
PgCache_Page.php
PgCache_Page_View.js
PgCache_Plugin.php
PgCache_Plugin_Admin.php
PgCache_QsExempts.php
Root_AdminActions.php
Root_AdminActivation.php
Root_AdminMenu.php
Root_Environment.php
Root_Loader.php
SetupGuide_Plugin_Admin.php
Support_AdminActions.php
Support_Page.php
Support_Page_View_DoneContent.php
Support_Page_View_PageContent.php
SystemOpCache_AdminActions.php
SystemOpCache_Core.php
SystemOpCache_GeneralPage_View.php
SystemOpCache_Plugin_Admin.php
UsageStatistics_AdminActions.php
UsageStatistics_Core.php
UsageStatistics_GeneralPage.php
UsageStatistics_GeneralPage_View.php
UsageStatistics_Page.php
UsageStatistics_Page_DbRequests_View.php
UsageStatistics_Page_ObjectCacheLog_View.php
UsageStatistics_Page_PageCacheRequests_View.php
UsageStatistics_Page_View.css
UsageStatistics_Page_View.js
UsageStatistics_Page_View.php
UsageStatistics_Page_View_Ad.php
UsageStatistics_Page_View_Disabled.php
UsageStatistics_Page_View_Free.php
UsageStatistics_Page_View_NoDebugMode.php
UsageStatistics_Plugin.php
UsageStatistics_Plugin_Admin.php
UsageStatistics_Source_AccessLog.php
UsageStatistics_Source_DbQueriesLog.php
UsageStatistics_Source_ObjectCacheLog.php
UsageStatistics_Source_PageCacheLog.php
UsageStatistics_Source_Wpdb.php
UsageStatistics_Sources.php
UsageStatistics_Sources_Apc.php
UsageStatistics_Sources_Memcached.php
UsageStatistics_Sources_Redis.php
UsageStatistics_StorageReader.php
UsageStatistics_StorageWriter.php
UsageStatistics_Widget.php
UsageStatistics_Widget_View.js
UsageStatistics_Widget_View.php
UsageStatistics_Widget_View_Disabled.php
UserExperience_Emoji_Extension.php
UserExperience_GeneralPage.php
UserExperience_GeneralPage_View.php
UserExperience_LazyLoad_GoogleMaps_GoogleMapsEasy.php
UserExperience_LazyLoad_GoogleMaps_WPGoogleMapPlugin.php
UserExperience_LazyLoad_GoogleMaps_WPGoogleMaps.php
UserExperience_LazyLoad_Mutator.php
UserExperience_LazyLoad_Mutator_Picture.php
UserExperience_LazyLoad_Mutator_Unmutable.php
UserExperience_LazyLoad_Page_View.php
UserExperience_LazyLoad_Plugin.php
UserExperience_OEmbed_Extension.php
UserExperience_Page.php
UserExperience_Page_View.php
UserExperience_Plugin_Admin.php
UserExperience_Plugin_Jquery.php
Util_Activation.php
Util_Admin.php
Util_AttachToActions.php
Util_Bus.php
Util_ConfigLabel.php
Util_Content.php
Util_Debug.php
Util_DebugPurgeLog_Reader.php
Util_Environment.php
Util_Environment_Exception.php
Util_Environment_Exceptions.php
Util_File.php
Util_Http.php
Util_Installed.php
Util_Mime.php
Util_PageSpeed.php
Util_PageUrls.php
Util_Request.php
Util_Rule.php
Util_Theme.php
Util_Ui.php
Util_UsageStatistics.php
Util_Widget.php
Util_WpFile.php
Util_WpFile_FilesystemChmodException.php
Util_WpFile_FilesystemCopyException.php
Util_WpFile_FilesystemMkdirException.php
Util_WpFile_FilesystemModifyException.php
Util_WpFile_FilesystemOperationException.php
Util_WpFile_FilesystemRmException.php
Util_WpFile_FilesystemRmdirException.php
Util_WpFile_FilesystemWriteException.php
Util_WpmuBlogmap.php
Varnish_Flush.php
Varnish_Plugin.php
index.html
press.txt
readme.txt
w3-total-cache-api.php
w3-total-cache-old-php.php
w3-total-cache.php
wp-piwik
wp-webauthn
index.php
themes
upgrade-temp-backup
w3tc-config
index.php
.dbsetup
.gitignore
htaccess
php.ini
650 lines
12 KiB
PHP
650 lines
12 KiB
PHP
<?php
|
|
namespace W3TC;
|
|
|
|
/**
|
|
* W3 CDN Base class
|
|
*/
|
|
define( 'W3TC_CDN_RESULT_HALT', -1 );
|
|
define( 'W3TC_CDN_RESULT_ERROR', 0 );
|
|
define( 'W3TC_CDN_RESULT_OK', 1 );
|
|
define( 'W3TC_CDN_HEADER_NONE', 'none' );
|
|
define( 'W3TC_CDN_HEADER_UPLOADABLE', 'uploadable' );
|
|
define( 'W3TC_CDN_HEADER_MIRRORING', 'mirroring' );
|
|
|
|
/**
|
|
* class CdnEngine_Base
|
|
*/
|
|
class CdnEngine_Base {
|
|
/**
|
|
* Engine configuration
|
|
*
|
|
* @var array
|
|
*/
|
|
var $_config = array();
|
|
|
|
/**
|
|
* gzip extension
|
|
*
|
|
* @var string
|
|
*/
|
|
var $_gzip_extension = '.gzip';
|
|
|
|
/**
|
|
* Last error
|
|
*
|
|
* @var string
|
|
*/
|
|
var $_last_error = '';
|
|
|
|
/**
|
|
* PHP5 Constructor
|
|
*
|
|
* @param array $config
|
|
*/
|
|
function __construct( $config = array() ) {
|
|
$this->_config = array_merge( array(
|
|
'debug' => false,
|
|
'ssl' => 'auto',
|
|
'compression' => false,
|
|
'headers' => array()
|
|
), $config );
|
|
}
|
|
|
|
/**
|
|
* Upload files to CDN
|
|
*
|
|
* @param array $files takes array consisting of array(array('local_path'=>'', 'remote_path'=>''))
|
|
* @param array $results
|
|
* @param boolean $force_rewrite
|
|
* @return boolean
|
|
*/
|
|
function upload( $files, &$results, $force_rewrite = false,
|
|
$timeout_time = NULL ) {
|
|
$results = $this->_get_results( $files, W3TC_CDN_RESULT_HALT,
|
|
'Not implemented.' );
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Delete files from CDN
|
|
*
|
|
* @param array $files
|
|
* @param array $results
|
|
* @return boolean
|
|
*/
|
|
function delete( $files, &$results ) {
|
|
$results = $this->_get_results( $files, W3TC_CDN_RESULT_HALT,
|
|
'Not implemented.' );
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Purge files from CDN
|
|
*
|
|
* @param array $files
|
|
* @param array $results
|
|
* @return boolean
|
|
*/
|
|
function purge( $files, &$results ) {
|
|
return $this->upload( $files, $results, true );
|
|
}
|
|
|
|
/**
|
|
* Purge CDN completely
|
|
*
|
|
* @param unknown $results
|
|
* @return bool
|
|
*/
|
|
function purge_all( &$results ) {
|
|
$results = $this->_get_results( array(), W3TC_CDN_RESULT_HALT,
|
|
'Not implemented.' );
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Test CDN server
|
|
*
|
|
* @param string $error
|
|
* @return boolean
|
|
*/
|
|
function test( &$error ) {
|
|
if ( !$this->_test_domains( $error ) ) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Create bucket / container for some CDN engines
|
|
*/
|
|
function create_container() {
|
|
throw new \Exception( 'Not implemented.' );
|
|
}
|
|
|
|
/**
|
|
* Returns first domain
|
|
*
|
|
* @param string $path
|
|
* @return string
|
|
*/
|
|
function get_domain( $path = '' ) {
|
|
$domains = $this->get_domains();
|
|
$count = count( $domains );
|
|
|
|
if ( $count ) {
|
|
switch ( true ) {
|
|
/**
|
|
* Reserved CSS
|
|
*/
|
|
case ( isset( $domains[0] ) && $this->_is_css( $path ) ):
|
|
$domain = $domains[0];
|
|
break;
|
|
|
|
|
|
/**
|
|
* Reserved JS after body
|
|
*/
|
|
case ( isset( $domains[2] ) && $this->_is_js_body( $path ) ):
|
|
$domain = $domains[2];
|
|
break;
|
|
|
|
/**
|
|
* Reserved JS before /body
|
|
*/
|
|
case ( isset( $domains[3] ) && $this->_is_js_footer( $path ) ):
|
|
$domain = $domains[3];
|
|
break;
|
|
|
|
/**
|
|
* Reserved JS in head, moved here due to greedy regex
|
|
*/
|
|
case ( isset( $domains[1] ) && $this->_is_js( $path ) ):
|
|
$domain = $domains[1];
|
|
break;
|
|
|
|
default:
|
|
if ( !isset( $domains[0] ) ) {
|
|
$scheme = $this->_get_scheme();
|
|
if ( 'https' == $scheme && !empty( $domains['https_default'] ) ) {
|
|
return $domains['https_default'];
|
|
} else {
|
|
return isset( $domains['http_default'] ) ? $domains['http_default'] :
|
|
$domains['https_default'];
|
|
}
|
|
} elseif ( $count > 4 ) {
|
|
$domain = $this->_get_domain( array_slice( $domains, 4 ),
|
|
$path );
|
|
} else {
|
|
$domain = $this->_get_domain( $domains, $path );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Custom host for SSL
|
|
*/
|
|
list( $domain_http, $domain_https ) = array_map( 'trim',
|
|
explode( ',', $domain . ',' ) );
|
|
|
|
$scheme = $this->_get_scheme();
|
|
|
|
switch ( $scheme ) {
|
|
case 'http':
|
|
$domain = $domain_http;
|
|
break;
|
|
|
|
case 'https':
|
|
$domain = ( $domain_https ? $domain_https : $domain_http );
|
|
break;
|
|
}
|
|
|
|
return $domain;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Returns array of CDN domains
|
|
*
|
|
* @return array
|
|
*/
|
|
function get_domains() {
|
|
return array();
|
|
}
|
|
|
|
/**
|
|
* Returns via string
|
|
*
|
|
* @return string
|
|
*/
|
|
function get_via() {
|
|
$domain = $this->get_domain();
|
|
|
|
if ( $domain ) {
|
|
return $domain;
|
|
}
|
|
|
|
return 'N/A';
|
|
}
|
|
|
|
/**
|
|
* Formats URL
|
|
*
|
|
* @param string $path
|
|
* @return string
|
|
*/
|
|
function format_url( $path ) {
|
|
$url = $this->_format_url( $path );
|
|
|
|
if ( $url && $this->_config['compression'] && ( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ? stristr( sanitize_text_field( wp_unslash( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ), 'gzip' ) !== false : false ) && $this->_may_gzip( $path ) ) {
|
|
if ( ( $qpos = strpos( $url, '?' ) ) !== false ) {
|
|
$url = substr_replace( $url, $this->_gzip_extension, $qpos, 0 );
|
|
} else {
|
|
$url .= $this->_gzip_extension;
|
|
}
|
|
}
|
|
|
|
return $url;
|
|
}
|
|
|
|
/**
|
|
* Returns prepend path
|
|
*
|
|
* @param string $path
|
|
* @return string
|
|
*/
|
|
function get_prepend_path( $path ) {
|
|
$domain = $this->get_domain( $path );
|
|
|
|
if ( $domain ) {
|
|
$scheme = $this->_get_scheme();
|
|
$url = sprintf( '%s://%s', $scheme, $domain );
|
|
|
|
return $url;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Formats URL
|
|
*
|
|
* @param string $path
|
|
* @return string
|
|
*/
|
|
function _format_url( $path ) {
|
|
$domain = $this->get_domain( $path );
|
|
|
|
if ( $domain ) {
|
|
$scheme = $this->_get_scheme();
|
|
$url = sprintf( '%s://%s/%s', $scheme, $domain, $path );
|
|
|
|
return $url;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Returns results
|
|
*
|
|
* @param array $files
|
|
* @param integer $result
|
|
* @param string $error
|
|
* @return array
|
|
*/
|
|
function _get_results( $files, $result = W3TC_CDN_RESULT_OK,
|
|
$error = 'OK' ) {
|
|
$results = array();
|
|
|
|
foreach ( $files as $key => $file ) {
|
|
if ( is_array( $file ) ) {
|
|
$local_path = $file['local_path'];
|
|
$remote_path = $file['remote_path'];
|
|
} else {
|
|
$local_path = $key;
|
|
$remote_path = $file;
|
|
}
|
|
|
|
$results[] = $this->_get_result( $local_path, $remote_path, $result,
|
|
$error, $file );
|
|
}
|
|
|
|
return $results;
|
|
}
|
|
|
|
/**
|
|
* Returns file process result
|
|
*
|
|
* @param string $local_path
|
|
* @param string $remote_path
|
|
* @param integer $result
|
|
* @param string $error
|
|
* @return array
|
|
*/
|
|
function _get_result( $local_path, $remote_path,
|
|
$result = W3TC_CDN_RESULT_OK, $error = 'OK', $descriptor = null ) {
|
|
if ( $this->_config['debug'] ) {
|
|
$this->_log( $local_path, $remote_path, $error );
|
|
}
|
|
|
|
return array(
|
|
'local_path' => $local_path,
|
|
'remote_path' => $remote_path,
|
|
'result' => $result,
|
|
'error' => $error,
|
|
'descriptor' => $descriptor
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Check for errors
|
|
*
|
|
* @param array $results
|
|
* @return bool
|
|
*/
|
|
function _is_error( $results ) {
|
|
foreach ( $results as $result ) {
|
|
if ( $result['result'] != W3TC_CDN_RESULT_OK ) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Returns headers for file
|
|
*
|
|
* @param array $file CDN file array
|
|
* @param array $whitelist which expensive headers to calculate
|
|
* @return array
|
|
*/
|
|
function get_headers_for_file( $file, $whitelist = array() ) {
|
|
$local_path = $file['local_path'];
|
|
$mime_type = Util_Mime::get_mime_type( $local_path );
|
|
|
|
$link = $file['original_url'];
|
|
|
|
$headers = array(
|
|
'Content-Type' => $mime_type,
|
|
'Last-Modified' => Util_Content::http_date( time() ),
|
|
'Access-Control-Allow-Origin' => '*',
|
|
'Link' => '<' . $link .'>; rel="canonical"'
|
|
);
|
|
|
|
$section = Util_Mime::mime_type_to_section( $mime_type );
|
|
|
|
if ( isset( $this->_config['headers'][$section] ) ) {
|
|
$hc = $this->_config['headers'][$section];
|
|
|
|
if ( isset( $whitelist['ETag'] ) && $hc['etag'] ) {
|
|
$headers['ETag'] = '"' . @md5_file( $local_path ) . '"';
|
|
}
|
|
|
|
if ( $hc['expires'] ) {
|
|
$headers['Expires'] = Util_Content::http_date( time() +
|
|
$hc['lifetime'] );
|
|
$expires_set = true;
|
|
}
|
|
|
|
$headers = array_merge( $headers, $hc['static'] );
|
|
}
|
|
|
|
return $headers;
|
|
}
|
|
|
|
/**
|
|
* Use gzip compression only for text-based files
|
|
*
|
|
* @param string $file
|
|
* @return boolean
|
|
*/
|
|
function _may_gzip( $file ) {
|
|
/**
|
|
* Remove query string
|
|
*/
|
|
$file = preg_replace( '~\?.*$~', '', $file );
|
|
|
|
/**
|
|
* Check by file extension
|
|
*/
|
|
if ( preg_match( '~\.(ico|js|css|xml|xsd|xsl|svg|htm|html|txt)$~i',
|
|
$file ) ) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Test domains
|
|
*
|
|
* @param string $error
|
|
* @return boolean
|
|
*/
|
|
function _test_domains( &$error ) {
|
|
$domains = $this->get_domains();
|
|
|
|
if ( !count( $domains ) ) {
|
|
$error = 'Empty hostname / CNAME list.';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
foreach ( $domains as $domain ) {
|
|
$_domains = array_map( 'trim', explode( ',', $domain ) );
|
|
|
|
foreach ( $_domains as $_domain ) {
|
|
$matches = null;
|
|
|
|
if ( preg_match( '~^([a-z0-9\-\.]*)~i', $_domain, $matches ) ) {
|
|
$hostname = $matches[1];
|
|
} else {
|
|
$hostname = $_domain;
|
|
}
|
|
|
|
if ( empty( $hostname ) ) {
|
|
continue;
|
|
}
|
|
|
|
if ( gethostbyname( $hostname ) === $hostname ) {
|
|
$error = sprintf( 'Unable to resolve hostname: %s.',
|
|
$hostname );
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Check if css file
|
|
*
|
|
* @param string $path
|
|
* @return boolean
|
|
*/
|
|
function _is_css( $path ) {
|
|
return preg_match( '~[a-zA-Z0-9\-_]*(\.include\.[0-9]+)?\.css$~',
|
|
$path );
|
|
}
|
|
|
|
/**
|
|
* Check if JS file in heeader
|
|
*
|
|
* @param string $path
|
|
* @return boolean
|
|
*/
|
|
function _is_js( $path ) {
|
|
return preg_match( '~([a-z0-9\-_]+(\.include\.[a-z0-9]+)\.js)$~',
|
|
$path ) ||
|
|
preg_match( '~[\w\d\-_]+\.js~', $path );
|
|
}
|
|
|
|
/**
|
|
* Check if JS file after body
|
|
*
|
|
* @param string $path
|
|
* @return boolean
|
|
*/
|
|
function _is_js_body( $path ) {
|
|
return preg_match( '~[a-z0-9\-_]+(\.include-body\.[a-z0-9]+)\.js$~',
|
|
$path );
|
|
}
|
|
|
|
/**
|
|
* Check if JS file before /body
|
|
*
|
|
* @param string $path
|
|
* @return boolean
|
|
*/
|
|
function _is_js_footer( $path ) {
|
|
return preg_match( '~[a-z0-9\-_]+(\.include-footer\.[a-z0-9]+)\.js$~',
|
|
$path );
|
|
}
|
|
|
|
/**
|
|
* Returns domain for path
|
|
*
|
|
* @param array $domains
|
|
* @param string $path
|
|
* @return string
|
|
*/
|
|
function _get_domain( $domains, $path ) {
|
|
$count = count( $domains );
|
|
if ( isset( $domains['http_default'] ) )
|
|
$count--;
|
|
if ( isset( $domains['https_default'] ) )
|
|
$count--;
|
|
|
|
if ( $count ) {
|
|
/**
|
|
* Use for equal URLs same host to allow caching by browser
|
|
*/
|
|
$hash = $this->_get_hash( $path );
|
|
$domain = $domains[$hash % $count];
|
|
|
|
return $domain;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Returns integer hash for key
|
|
*
|
|
* @param string $key
|
|
* @return integer
|
|
*/
|
|
function _get_hash( $key ) {
|
|
$hash = abs( crc32( $key ) );
|
|
|
|
return $hash;
|
|
}
|
|
|
|
/**
|
|
* Returns scheme
|
|
*
|
|
* @return string
|
|
*/
|
|
function _get_scheme() {
|
|
switch ( $this->_config['ssl'] ) {
|
|
default:
|
|
case 'auto':
|
|
$scheme = ( Util_Environment::is_https() ? 'https' : 'http' );
|
|
break;
|
|
|
|
case 'enabled':
|
|
$scheme = 'https';
|
|
break;
|
|
|
|
case 'disabled':
|
|
$scheme = 'http';
|
|
break;
|
|
case 'rejected':
|
|
$scheme = 'http';
|
|
break;
|
|
}
|
|
|
|
return $scheme;
|
|
}
|
|
|
|
/**
|
|
* Write log entry
|
|
*
|
|
* @param string $local_path
|
|
* @param string $remote_path
|
|
* @param string $error
|
|
* @return bool|int
|
|
*/
|
|
function _log( $local_path, $remote_path, $error ) {
|
|
$data = sprintf( "[%s] [%s => %s] %s\n", date( 'r' ), $local_path,
|
|
$remote_path, $error );
|
|
$data = strtr( $data, '<>', '..' );
|
|
|
|
$filename = Util_Debug::log_filename( 'cdn' );
|
|
|
|
return @file_put_contents( $filename, $data, FILE_APPEND );
|
|
}
|
|
|
|
/**
|
|
* Our error handler
|
|
*
|
|
* @param integer $errno
|
|
* @param string $errstr
|
|
* @return boolean
|
|
*/
|
|
function _error_handler( $errno, $errstr ) {
|
|
$this->_last_error = $errstr;
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Returns last error
|
|
*
|
|
* @return string
|
|
*/
|
|
function _get_last_error() {
|
|
return $this->_last_error;
|
|
}
|
|
|
|
/**
|
|
* Set our error handler
|
|
*
|
|
* @return void
|
|
*/
|
|
function _set_error_handler() {
|
|
set_error_handler( array(
|
|
$this,
|
|
'_error_handler'
|
|
) );
|
|
}
|
|
|
|
/**
|
|
* Restore prev error handler
|
|
*
|
|
* @return void
|
|
*/
|
|
function _restore_error_handler() {
|
|
restore_error_handler();
|
|
}
|
|
|
|
/**
|
|
* How and if headers should be set
|
|
*
|
|
* @return string W3TC_CDN_HEADER_NONE, W3TC_CDN_HEADER_UPLOADABLE,
|
|
* W3TC_CDN_HEADER_MIRRORING
|
|
*/
|
|
function headers_support() {
|
|
return W3TC_CDN_HEADER_NONE;
|
|
}
|
|
}
|