2023-06-05 11:23:16 +00:00
|
|
|
<?php
|
2023-12-08 23:23:32 +00:00
|
|
|
/**
|
|
|
|
* File: Cdn_Plugin_Admin.php
|
|
|
|
*
|
|
|
|
* @since X.X.X
|
|
|
|
*
|
|
|
|
* @package W3TC
|
|
|
|
*/
|
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
namespace W3TC;
|
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
/**
|
|
|
|
* Class: Cdn_Plugin_Admin
|
|
|
|
*/
|
2023-06-05 11:23:16 +00:00
|
|
|
class Cdn_Plugin_Admin {
|
2023-12-08 23:23:32 +00:00
|
|
|
/**
|
|
|
|
* Run.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function run() {
|
2023-06-05 11:23:16 +00:00
|
|
|
$config_labels = new Cdn_ConfigLabels();
|
2023-12-08 23:23:32 +00:00
|
|
|
\add_filter( 'w3tc_config_labels', array( $config_labels, 'config_labels' ) );
|
2023-06-05 11:23:16 +00:00
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
$c = Dispatcher::config();
|
2023-06-05 11:23:16 +00:00
|
|
|
$cdn_engine = $c->get_string( 'cdn.engine' );
|
|
|
|
|
|
|
|
if ( $c->get_boolean( 'cdn.enabled' ) ) {
|
|
|
|
$admin_notes = new Cdn_AdminNotes();
|
2023-12-08 23:23:32 +00:00
|
|
|
\add_filter( 'w3tc_notes', array( $admin_notes, 'w3tc_notes' ) );
|
|
|
|
\add_filter( 'w3tc_errors', array( $admin_notes, 'w3tc_errors' ) );
|
2023-06-05 11:23:16 +00:00
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
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 );
|
2023-06-05 11:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-28 09:40:06 +00:00
|
|
|
// Always show the Bunny CDN widget on dashboard.
|
|
|
|
\add_action( 'admin_init_w3tc_dashboard', array( '\W3TC\Cdn_BunnyCdn_Widget', 'admin_init_w3tc_dashboard' ) );
|
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
// 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( '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' ) );
|
|
|
|
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' ) );
|
|
|
|
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( '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' ) );
|
|
|
|
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;
|
2023-06-05 11:23:16 +00:00
|
|
|
}
|
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
\add_action( 'w3tc_settings_general_boxarea_cdn', array( $this, 'w3tc_settings_general_boxarea_cdn' ) );
|
2023-06-05 11:23:16 +00:00
|
|
|
}
|
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
/**
|
|
|
|
* CDN settings.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2023-06-05 11:23:16 +00:00
|
|
|
public function w3tc_settings_general_boxarea_cdn() {
|
2023-12-08 23:23:32 +00:00
|
|
|
$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' );
|
2023-06-05 11:23:16 +00:00
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
$engine_values[''] = array(
|
|
|
|
'label' => 'Select a provider',
|
|
|
|
);
|
2023-06-05 11:23:16 +00:00
|
|
|
|
|
|
|
$engine_values['akamai'] = array(
|
2023-12-08 23:23:32 +00:00
|
|
|
'label' => \__( 'Akamai', 'w3-total-cache' ),
|
|
|
|
'optgroup' => $optgroup_pull,
|
2023-06-05 11:23:16 +00:00
|
|
|
);
|
2023-12-08 23:23:32 +00:00
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
$engine_values['cf2'] = array(
|
2023-12-08 23:23:32 +00:00
|
|
|
'label' => \__( 'Amazon CloudFront', 'w3-total-cache' ),
|
|
|
|
'disabled' => ! Util_Installed::curl() ? true : null,
|
|
|
|
'optgroup' => $optgroup_pull,
|
2023-06-05 11:23:16 +00:00
|
|
|
);
|
2023-12-08 23:23:32 +00:00
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
$engine_values['att'] = array(
|
2023-12-08 23:23:32 +00:00
|
|
|
'label' => \__( 'AT&T', 'w3-total-cache' ),
|
|
|
|
'optgroup' => $optgroup_pull,
|
|
|
|
);
|
|
|
|
|
|
|
|
$engine_values['bunnycdn'] = array(
|
|
|
|
'label' => \__( 'Bunny CDN (recommended)', 'w3-total-cache' ),
|
|
|
|
'optgroup' => $optgroup_pull,
|
2023-06-05 11:23:16 +00:00
|
|
|
);
|
2023-12-08 23:23:32 +00:00
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
$engine_values['cotendo'] = array(
|
2023-12-08 23:23:32 +00:00
|
|
|
'label' => \__( 'Cotendo (Akamai)', 'w3-total-cache' ),
|
|
|
|
'optgroup' => $optgroup_pull,
|
2023-06-05 11:23:16 +00:00
|
|
|
);
|
2023-12-08 23:23:32 +00:00
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
$engine_values['mirror'] = array(
|
2023-12-08 23:23:32 +00:00
|
|
|
'label' => \__( 'Generic Mirror', 'w3-total-cache' ),
|
|
|
|
'optgroup' => $optgroup_pull,
|
2023-06-05 11:23:16 +00:00
|
|
|
);
|
2023-12-08 23:23:32 +00:00
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
$engine_values['highwinds'] = array(
|
2023-12-08 23:23:32 +00:00
|
|
|
'label' => \__( 'Highwinds', 'w3-total-cache' ),
|
|
|
|
'optgroup' => $optgroup_pull,
|
2023-06-05 11:23:16 +00:00
|
|
|
);
|
2023-12-08 23:23:32 +00:00
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
$engine_values['limelight'] = array(
|
2023-12-08 23:23:32 +00:00
|
|
|
'label' => \__( 'LimeLight', 'w3-total-cache' ),
|
|
|
|
'optgroup' => $optgroup_pull,
|
2023-06-05 11:23:16 +00:00
|
|
|
);
|
2023-12-08 23:23:32 +00:00
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
$engine_values['rackspace_cdn'] = array(
|
2023-12-08 23:23:32 +00:00
|
|
|
'label' => \__( 'RackSpace CDN', 'w3-total-cache' ),
|
|
|
|
'optgroup' => $optgroup_pull,
|
2023-06-05 11:23:16 +00:00
|
|
|
);
|
2023-12-08 23:23:32 +00:00
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
$engine_values['stackpath2'] = array(
|
2023-12-08 23:23:32 +00:00
|
|
|
'label' => \__( 'StackPath', 'w3-total-cache' ),
|
|
|
|
'optgroup' => $optgroup_pull,
|
2023-06-05 11:23:16 +00:00
|
|
|
);
|
2023-12-08 23:23:32 +00:00
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
$engine_values['stackpath'] = array(
|
2023-12-08 23:23:32 +00:00
|
|
|
'label' => \__( 'StackPath SecureCDN (Legacy)', 'w3-total-cache' ),
|
|
|
|
'optgroup' => $optgroup_pull,
|
2023-06-05 11:23:16 +00:00
|
|
|
);
|
2023-12-08 23:23:32 +00:00
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
$engine_values['edgecast'] = array(
|
2023-12-08 23:23:32 +00:00
|
|
|
'label' => \__( 'Verizon Digital Media Services (EdgeCast) / Media Temple ProCDN', 'w3-total-cache' ),
|
|
|
|
'optgroup' => $optgroup_pull,
|
2023-06-05 11:23:16 +00:00
|
|
|
);
|
2023-12-08 23:23:32 +00:00
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
$engine_values['cf'] = array(
|
2023-12-08 23:23:32 +00:00
|
|
|
'disabled' => ! Util_Installed::curl() ? true : null,
|
|
|
|
'label' => \__( 'Amazon CloudFront Over S3', 'w3-total-cache' ),
|
|
|
|
'optgroup' => $optgroup_push,
|
2023-06-05 11:23:16 +00:00
|
|
|
);
|
2023-12-08 23:23:32 +00:00
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
$engine_values['s3'] = array(
|
2023-12-08 23:23:32 +00:00
|
|
|
'disabled' => ! Util_Installed::curl() ? true : null,
|
|
|
|
'label' => \__( 'Amazon Simple Storage Service (S3)', 'w3-total-cache' ),
|
|
|
|
'optgroup' => $optgroup_push,
|
2023-06-05 11:23:16 +00:00
|
|
|
);
|
2023-12-08 23:23:32 +00:00
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
$engine_values['s3_compatible'] = array(
|
2023-12-08 23:23:32 +00:00
|
|
|
'disabled' => ! Util_Installed::curl() ? true : null,
|
|
|
|
'label' => \__( 'Amazon Simple Storage Service (S3) Compatible', 'w3-total-cache' ),
|
|
|
|
'optgroup' => $optgroup_push,
|
2023-06-05 11:23:16 +00:00
|
|
|
);
|
2023-12-08 23:23:32 +00:00
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
$engine_values['google_drive'] = array(
|
2023-12-08 23:23:32 +00:00
|
|
|
'label' => \__( 'Google Drive', 'w3-total-cache' ),
|
|
|
|
'optgroup' => $optgroup_push,
|
2023-06-05 11:23:16 +00:00
|
|
|
);
|
2023-12-08 23:23:32 +00:00
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
$engine_values['azure'] = array(
|
2023-12-08 23:23:32 +00:00
|
|
|
'label' => \__( 'Microsoft Azure Storage', 'w3-total-cache' ),
|
|
|
|
'optgroup' => $optgroup_push,
|
2023-06-05 11:23:16 +00:00
|
|
|
);
|
2023-12-08 23:23:32 +00:00
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
$engine_values['rscf'] = array(
|
2023-12-08 23:23:32 +00:00
|
|
|
'disabled' => ! Util_Installed::curl() ? true : null,
|
|
|
|
'label' => \__( 'Rackspace Cloud Files', 'w3-total-cache' ),
|
|
|
|
'optgroup' => $optgroup_push,
|
2023-06-05 11:23:16 +00:00
|
|
|
);
|
2023-12-08 23:23:32 +00:00
|
|
|
|
2023-06-05 11:23:16 +00:00
|
|
|
$engine_values['ftp'] = array(
|
2023-12-08 23:23:32 +00:00
|
|
|
'disabled' => ! Util_Installed::ftp() ? true : null,
|
|
|
|
'label' => \__( 'Self-hosted / File Transfer Protocol Upload', 'w3-total-cache' ),
|
|
|
|
'optgroup' => $optgroup_push,
|
2023-06-05 11:23:16 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$cdn_enabled = $config->get_boolean( 'cdn.enabled' );
|
2023-12-08 23:23:32 +00:00
|
|
|
$cdn_engine = $config->get_string( 'cdn.engine' );
|
2023-06-05 11:23:16 +00:00
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
include W3TC_DIR . '/Cdn_GeneralPage_View.php';
|
2023-06-05 11:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-12-08 23:23:32 +00:00
|
|
|
* Adjusts attachment urls to cdn. This is for those who rely on wp_get_attachment_url().
|
2023-06-05 11:23:16 +00:00
|
|
|
*
|
2023-12-08 23:23:32 +00:00
|
|
|
* @param string $url The local url to modify.
|
|
|
|
* @return string
|
2023-06-05 11:23:16 +00:00
|
|
|
*/
|
2023-12-08 23:23:32 +00:00
|
|
|
public function wp_get_attachment_url( $url ) {
|
2023-06-05 11:23:16 +00:00
|
|
|
if ( defined( 'WP_ADMIN' ) ) {
|
|
|
|
$url = trim( $url );
|
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
if ( ! empty( $url ) ) {
|
|
|
|
$parsed = \parse_url( $url );
|
|
|
|
$uri = ( isset( $parsed['path'] ) ? $parsed['path'] : '/' ) .
|
2023-06-05 11:23:16 +00:00
|
|
|
( isset( $parsed['query'] ) ? '?' . $parsed['query'] : '' );
|
2023-12-08 23:23:32 +00:00
|
|
|
$wp_upload_dir = \wp_upload_dir();
|
2023-06-05 11:23:16 +00:00
|
|
|
$upload_base_url = $wp_upload_dir['baseurl'];
|
|
|
|
|
2023-12-08 23:23:32 +00:00
|
|
|
if ( \substr( $url, 0, strlen( $upload_base_url ) ) === $upload_base_url ) {
|
|
|
|
$common = Dispatcher::component( 'Cdn_Core' );
|
2023-06-05 11:23:16 +00:00
|
|
|
$new_url = $common->url_to_cdn_url( $url, $uri );
|
2023-12-08 23:23:32 +00:00
|
|
|
if ( ! is_null( $new_url ) ) {
|
2023-06-05 11:23:16 +00:00
|
|
|
$url = $new_url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
}
|