Esempio n. 1
0
 /**
  * Fixes environment once event occurs
  *
  * @param Config  $config
  * @param string  $event
  * @param Config|null $old_config
  * @throws Util_Environment_Exceptions
  */
 public function fix_on_event($config, $event, $old_config = null)
 {
     if ($config->get_boolean('cdn.enabled') && !Cdn_Util::is_engine_mirror($config->get_string('cdn.engine'))) {
         if ($old_config != null && $config->get_integer('cdn.queue.interval') != $old_config->get_integer('cdn.queue.interval')) {
             $this->unschedule_queue_process();
         }
         if (!wp_next_scheduled('w3_cdn_cron_queue_process')) {
             wp_schedule_event(time(), 'w3_cdn_cron_queue_process', 'w3_cdn_cron_queue_process');
         }
     } else {
         $this->unschedule_queue_process();
     }
     if ($config->get_boolean('cdn.enabled') && $config->get_boolean('cdn.autoupload.enabled') && !Cdn_Util::is_engine_mirror($config->get_string('cdn.engine'))) {
         if ($old_config != null && $config->get_integer('cdn.autoupload.interval') != $old_config->get_integer('cdn.autoupload.interval')) {
             $this->unschedule_upload();
         }
         if (!wp_next_scheduled('w3_cdn_cron_upload')) {
             wp_schedule_event(time(), 'w3_cdn_cron_upload', 'w3_cdn_cron_upload');
         }
     } else {
         $this->unschedule_upload();
     }
     $exs = new Util_Environment_Exceptions();
     if ($config->get_boolean('cdn.enabled')) {
         try {
             $this->table_create($event == 'activate');
         } catch (\Exception $ex) {
             $exs->push($ex);
         }
     }
     if (count($exs->exceptions()) > 0) {
         throw $exs;
     }
 }
 /**
  * General tab
  *
  * @return void
  */
 function view()
 {
     global $current_user;
     $config_master = $this->_config_master;
     /**
      *
      *
      * @var $modules W3_ModuleStatus
      */
     $modules = Dispatcher::component('ModuleStatus');
     $pgcache_enabled = $modules->is_enabled('pgcache');
     $dbcache_enabled = $modules->is_enabled('dbcache');
     $objectcache_enabled = $modules->is_enabled('objectcache');
     $browsercache_enabled = $modules->is_enabled('browsercache');
     $minify_enabled = $modules->is_enabled('minify');
     $cdn_enabled = $modules->is_enabled('cdn');
     $varnish_enabled = $modules->is_enabled('varnish');
     $enabled = $modules->plugin_is_enabled();
     $enabled_checkbox = $modules->all_modules_enabled();
     $check_rules = Util_Rule::can_check_rules();
     $disc_enhanced_enabled = !(!$check_rules || !$this->is_master() && Util_Environment::is_wpmu() && $config_master->get_string('pgcache.engine') != 'file_generic');
     $can_empty_file = $modules->can_empty_file();
     $can_empty_varnish = $modules->can_empty_varnish();
     $cdn_mirror_purge = Cdn_Util::can_purge_all($modules->get_module_engine('cdn'));
     $file_nfs = $this->_config->get_boolean('pgcache.file.nfs') || $this->_config->get_boolean('minify.file.nfs');
     $file_locking = $this->_config->get_boolean('dbcache.file.locking') || $this->_config->get_boolean('objectcache.file.locking') || $this->_config->get_boolean('pgcache.file.locking') || $this->_config->get_boolean('minify.file.locking');
     $licensing_visible = (!Util_Environment::is_wpmu() || is_network_admin()) && !ini_get('w3tc.license_key') && get_transient('w3tc_license_status') != 'host_valid';
     $custom_areas = apply_filters("w3tc_settings_general_anchors", array());
     include W3TC_INC_DIR . '/options/general.php';
 }
Esempio n. 3
0
 /**
  * Page cache tab
  *
  * @return void
  */
 function view()
 {
     global $wp_rewrite;
     $feeds = $wp_rewrite->feeds;
     $feed_key = array_search('feed', $feeds);
     if ($feed_key !== false) {
         unset($feeds[$feed_key]);
     }
     $default_feed = get_default_feed();
     $pgcache_enabled = $this->_config->get_boolean('pgcache.enabled');
     $permalink_structure = get_option('permalink_structure');
     $varnish_enabled = $this->_config->get_boolean('varnish.enabled');
     $cdn_mirror_purge_enabled = Cdn_Util::is_engine_fsd($this->_config->get_string('cdn.engine')) && $this->_config->get_boolean('cdn.enabled');
     include W3TC_INC_DIR . '/options/pgcache.php';
 }
Esempio n. 4
0
 /**
  * CDN tab
  *
  * @return void
  */
 function view()
 {
     $config = Dispatcher::config();
     $cdn_engine = $config->get_string('cdn.engine');
     if (Cdn_Util::is_engine_fsd($cdn_engine)) {
         do_action('w3tc_settings_cdn');
         return;
     }
     $cdn_enabled = $config->get_boolean('cdn.enabled');
     $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 = $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')));
     $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');
     $browsercache_update_media_qs = $config->get_boolean('browsercache.cssjs.replace') || $config->get_boolean('browsercache.other.replace');
     if (in_array($cdn_engine, array('netdna', 'maxcdn'))) {
         $pull_zones = array();
         $authorization_key = $config->get_string("cdn.{$cdn_engine}.authorization_key");
         $zone_id = $config->get_integer("cdn.{$cdn_engine}.zone_id");
         $alias = $consumerkey = $consumersecret = '';
         if ($authorization_key) {
             $keys = explode('+', $authorization_key);
             if (sizeof($keys) == 3) {
                 list($alias, $consumerkey, $consumersecret) = $keys;
             }
         }
         $authorized = $authorization_key != '' && $alias && $consumerkey && $consumersecret;
         $have_zone = $zone_id != 0;
         if ($authorized) {
             require_once W3TC_LIB_NETDNA_DIR . '/NetDNA.php';
             try {
                 $api = new \NetDNA($alias, $consumerkey, $consumersecret);
                 $pull_zones = $api->get_zones_by_url(get_home_url());
             } catch (\Exception $ex) {
                 Util_Ui::error_box('<p>There is an error with your CDN settings: ' . $ex->getMessage() . '</p>');
             }
         }
     }
     include W3TC_INC_DIR . '/options/cdn.php';
 }
 /**
  * Dashboard tab
  */
 function view()
 {
     $module_status = Dispatcher::component('ModuleStatus');
     Util_Widget::setup();
     global $current_user;
     $config_master = $this->_config_master;
     $browsercache_enabled = $module_status->is_enabled('browsercache');
     $enabled = $module_status->plugin_is_enabled();
     $can_empty_memcache = $module_status->can_empty_memcache();
     $can_empty_opcode = $module_status->can_empty_opcode();
     $can_empty_file = $module_status->can_empty_file();
     $can_empty_varnish = $module_status->can_empty_varnish();
     $cdn_enabled = $module_status->is_enabled('cdn');
     $cdn_mirror_purge = Cdn_Util::can_purge_all($module_status->get_module_engine('cdn'));
     // Required for Update Media Query String button
     $browsercache_update_media_qs = $this->_config->get_boolean('browsercache.cssjs.replace') || $this->_config->get_boolean('browsercache.other.replace');
     include W3TC_INC_DIR . '/options/dashboard.php';
 }
 function run()
 {
     $config_labels = new Cdn_ConfigLabels();
     add_filter('w3tc_config_labels', array($config_labels, 'config_labels'));
     $c = Dispatcher::config();
     $cdn_engine = $c->get_string('cdn.engine');
     if ($c->get_boolean('cdn.enabled') && !Cdn_Util::is_engine_fsd($cdn_engine)) {
         $admin_notes = new Cdn_AdminNotes();
         add_filter('w3tc_notes', array($admin_notes, 'w3tc_notes'));
         add_filter('w3tc_errors', array($admin_notes, 'w3tc_errors'));
     }
     // attach to actions without firing class loading at all without need
     if ($cdn_engine == 'cloudfront_fsd') {
         add_action('admin_print_scripts-performance_page_w3tc_cdn', array('\\W3TC\\Cdn_CloudFrontFsd_Page', 'admin_print_scripts_w3tc_cdn'));
         add_action('w3tc_ajax', array('\\W3TC\\Cdn_CloudFrontFsd_Popup', 'w3tc_ajax'));
         add_action('w3tc_settings_cdn', array('\\W3TC\\Cdn_CloudFrontFsd_Page', 'w3tc_settings_cdn'));
     } elseif ($cdn_engine == 'google_drive') {
         add_action('admin_print_scripts-performance_page_w3tc_cdn', array('\\W3TC\\Cdn_GoogleDrive_Page', 'admin_print_scripts_w3tc_cdn'));
         add_action('w3tc_settings_cdn_boxarea_configuration', array('\\W3TC\\Cdn_GoogleDrive_Page', 'w3tc_settings_cdn_boxarea_configuration'));
     } elseif ($cdn_engine == 'highwinds') {
         add_action('admin_print_scripts-performance_page_w3tc_cdn', array('\\W3TC\\Cdn_Highwinds_Page', 'admin_print_scripts_w3tc_cdn'));
         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 == 'maxcdn_fsd') {
         add_action('admin_print_scripts-performance_page_w3tc_cdn', array('\\W3TC\\Cdn_MaxCdnFsd_Page', 'admin_print_scripts_w3tc_cdn'));
         add_action('w3tc_ajax', array('\\W3TC\\Cdn_MaxCdnFsd_Popup', 'w3tc_ajax'));
         add_action('w3tc_settings_cdn', array('\\W3TC\\Cdn_MaxCdnFsd_Page', 'w3tc_settings_cdn'));
     } elseif ($cdn_engine == 'rackspace_cdn') {
         add_filter('w3tc_admin_actions', array('\\W3TC\\Cdn_RackSpaceCdn_Page', 'w3tc_admin_actions'));
         add_action('admin_print_scripts-performance_page_w3tc_cdn', array('\\W3TC\\Cdn_RackSpaceCdn_Page', 'admin_print_scripts_w3tc_cdn'));
         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('admin_print_scripts-performance_page_w3tc_cdn', array('\\W3TC\\Cdn_RackSpaceCloudFiles_Page', 'admin_print_scripts_w3tc_cdn'));
         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'));
     }
     add_action('w3tc_settings_general_boxarea_cdn', array($this, 'w3tc_settings_general_boxarea_cdn'));
 }
<?php

namespace W3TC;

if (!defined('W3TC')) {
    die;
}
Util_Ui::postbox_header(__('<acronym title="Content Delivery Network">CDN</acronym>', 'w3-total-cache'), '', 'cdn');
Util_Ui::config_overloading_button(array('key' => 'cdn.configuration_overloaded'));
?>
<p><?php 
_e('Host static files with your content delivery network provider to reduce page load time.', 'w3-total-cache');
if (!$cdn_enabled) {
    printf(__('If you do not have a <acronym title="Content Delivery Network">CDN</acronym> provider try MaxCDN. <a href="%s" target="_blank">Sign up and save 25&#37;</a>.', 'w3-total-cache'), wp_nonce_url(Util_Ui::admin_url('admin.php?page=w3tc_dashboard&w3tc_cdn_maxcdn_signup'), 'w3tc'));
}
?>
</p>
<table class="form-table">
    <?php 
Util_Ui::config_item(array('key' => 'cdn.enabled', 'control' => 'checkbox', 'checkbox_label' => __('Enable', 'w3-total-cache'), 'description' => __('Theme files, media library attachments, <acronym title="Cascading Style Sheet">CSS</acronym>, <acronym title="JavaScript">JS</acronym> files etc will appear to load instantly for site visitors.', 'w3-total-cache')));
Util_Ui::config_item(array('key' => 'cdn.engine', 'control' => 'selectbox', 'selectbox_values' => $engine_values, 'selectbox_optgroups' => $engine_optgroups, 'description' => __('Select the <acronym title="Content Delivery Network">CDN</acronym> type you wish to use.', 'w3-total-cache') . $cdn_engine_extra_description));
?>
</table>

<?php 
Util_Ui::button_config_save('general_cdn', '<input id="cdn_purge" type="button" value="' . __('Empty cache', 'w3-total-cache') . '" ' . ($cdn_enabled && Cdn_Util::can_purge_all($config->get_string('cdn.engine')) ? '' : ' disabled="disabled" ') . ' class="button {nonce: \'' . wp_create_nonce('w3tc') . '\'}" />');
Util_Ui::postbox_footer();
Esempio n. 8
0
 function w3tc_errors($errors)
 {
     $c = Dispatcher::config();
     $state = Dispatcher::config_state();
     $cdn_engine = $c->get_string('cdn.engine');
     if (Cdn_Util::is_engine_push($cdn_engine)) {
         /**
          * Show notification if upload queue is not empty
          */
         try {
             if (!($error = get_transient('w3tc_cdn_error')) && !$this->_is_queue_empty()) {
                 $errors['cdn_unsuccessful_queue'] = sprintf(__('The %s has unresolved errors. Empty the queue to restore normal operation.', 'w3-total-cache'), Util_Ui::button_popup(__('unsuccessful transfer queue', 'w3-total-cache'), 'cdn_queue'));
             } elseif ($error) {
                 $errors['cdn_generic'] = $error;
             }
         } catch (\Exception $ex) {
             $errors[] = $ex->getMessage();
             set_transient('w3tc_cdn_error', $ex->getMessage(), 30);
         }
         /**
          * Check upload settings
          */
         $upload_info = Util_Http::upload_info();
         if (!$upload_info) {
             $upload_path = get_option('upload_path');
             $upload_path = trim($upload_path);
             if (empty($upload_path)) {
                 $upload_path = WP_CONTENT_DIR . '/uploads';
                 $errors['cdn_uploads_folder_empty'] = sprintf(__('The uploads directory is not available. Default WordPress directories will be created: <strong>%s</strong>.', 'w3-total-cache'), $upload_path);
             }
             if (!Util_Environment::is_wpmu()) {
                 $errors['cdn_uploads_folder_not_found'] = sprintf(__('The uploads path found in the database (%s) is inconsistent with the actual path. Please manually adjust the upload path either in miscellaneous settings or if not using a custom path %s automatically to resolve the issue.', 'w3-total-cache'), $upload_path, Util_Ui::button_link(__('update the path', 'w3-total-cache'), Util_Ui::url(array('w3tc_config_update_upload_path' => 'y'))));
             }
         }
     }
     /**
      * Check CDN settings
      */
     $error = '';
     switch (true) {
         case $cdn_engine == 'ftp' && !count($c->get_array('cdn.ftp.domain')):
             $errors['cdn_ftp_empty'] = __('A configuration issue prevents <acronym title="Content Delivery Network">CDN</acronym> from working:
                                     The <strong>"Replace default hostname with"</strong>
                                     field cannot be empty. Enter <acronym
                                     title="Content Delivery Network">CDN</acronym>
                                     provider hostname <a href="?page=w3tc_cdn#configuration">here</a>.
                                     <em>(This is the hostname used in order to view objects
                                     in a browser.)</em>', 'w3-total-cache');
             break;
         case $cdn_engine == 's3' && ($c->get_string('cdn.s3.key') == '' || $c->get_string('cdn.s3.secret') == '' || $c->get_string('cdn.s3.bucket') == ''):
             $error = __('The <strong>"Access key", "Secret key" and "Bucket"</strong> fields cannot be empty.', 'w3-total-cache');
             break;
         case $cdn_engine == 'cf' && ($c->get_string('cdn.cf.key') == '' || $c->get_string('cdn.cf.secret') == '' || $c->get_string('cdn.cf.bucket') == '' || $c->get_string('cdn.cf.id') == '' && !count($c->get_array('cdn.cf.cname'))):
             $error = __('The <strong>"Access key", "Secret key", "Bucket" and "Replace default hostname with"</strong> fields cannot be empty.', 'w3-total-cache');
             break;
         case $cdn_engine == 'cf2' && ($c->get_string('cdn.cf2.key') == '' || $c->get_string('cdn.cf2.secret') == '' || $c->get_string('cdn.cf2.id') == '' && !count($c->get_array('cdn.cf2.cname'))):
             $error = __('The <strong>"Access key", "Secret key" and "Replace default hostname with"</strong> fields cannot be empty.', 'w3-total-cache');
             break;
         case $cdn_engine == 'rscf' && ($c->get_string('cdn.rscf.user') == '' || $c->get_string('cdn.rscf.key') == '' || $c->get_string('cdn.rscf.container') == ''):
             $error = __('The <strong>"Username", "API key", "Container" and "Replace default hostname with"</strong> fields cannot be empty.', 'w3-total-cache');
             break;
         case $cdn_engine == 'azure' && ($c->get_string('cdn.azure.user') == '' || $c->get_string('cdn.azure.key') == '' || $c->get_string('cdn.azure.container') == ''):
             $error = __('The <strong>"Account name", "Account key" and "Container"</strong> fields cannot be empty.', 'w3-total-cache');
             break;
         case $cdn_engine == 'mirror' && !count($c->get_array('cdn.mirror.domain')):
             $error = __('The <strong>"Replace default hostname with"</strong> field cannot be empty.', 'w3-total-cache');
             break;
         case $cdn_engine == 'netdna':
             $fields = array();
             if ($c->get_string('cdn.netdna.authorization_key') == '') {
                 $fields[] = '"' . __('Authorization key', 'w3-total-cache') . '"';
             }
             if (!count($c->get_array('cdn.netdna.domain'))) {
                 $fields[] = '"' . __('Replace default hostname with', 'w3-total-cache') . '"';
             }
             if ($fields) {
                 $error = sprintf(__('The <strong>%s</strong> field(s) cannot be empty.', 'w3-total-cache'), implode(__(' and ', 'w3-total-cache'), $fields));
             }
             if ($c->get_string('cdn.netdna.authorization_key') != '' && sizeof(explode('+', $c->get_string('cdn.netdna.authorization_key'))) != 3) {
                 $error .= __('The <strong>"Authorization key"</strong> is not correct.', 'w3-total-cache');
             } elseif ($c->get_integer('cdn.netdna.zone_id', 0) <= 0) {
                 $error .= __('You need to select / create a pull zone.', 'w3-total-cache');
             }
             break;
         case $cdn_engine == 'maxcdn':
             $fields = array();
             if ($c->get_string('cdn.maxcdn.authorization_key') == '') {
                 $fields[] = '"' . __('Authorization key', 'w3-total-cache') . '"';
             }
             if (!count($c->get_array('cdn.maxcdn.domain'))) {
                 $fields[] = '"' . __('Replace default hostname with', 'w3-total-cache') . '"';
             }
             if ($fields) {
                 $error = sprintf(__('The <strong>%s</strong> field(s) cannot be empty.', 'w3-total-cache'), implode(__(' and ', 'w3-total-cache'), $fields));
             }
             if ($c->get_string('cdn.maxcdn.authorization_key') != '' && sizeof(explode('+', $c->get_string('cdn.maxcdn.authorization_key'))) != 3) {
                 $error .= __('The <strong>"Authorization key"</strong> is not correct.', 'w3-total-cache');
             } elseif ($c->get_integer('cdn.maxcdn.zone_id', 0) <= 0) {
                 $error .= __('You need to select / create a pull zone.', 'w3-total-cache');
             }
             break;
         case $cdn_engine == 'cotendo' && !count($c->get_array('cdn.cotendo.domain')):
             $error = __('The <strong>"Replace default hostname with"</strong> field cannot be empty.', 'w3-total-cache');
             break;
         case $cdn_engine == 'edgecast' && !count($c->get_array('cdn.edgecast.domain')):
             $error = __('The <strong>"Replace default hostname with"</strong> field cannot be empty.', 'w3-total-cache');
             break;
         case $cdn_engine == 'att' && !count($c->get_array('cdn.att.domain')):
             $error = __('The <strong>"Replace default hostname with"</strong> field cannot be empty.', 'w3-total-cache');
             break;
         case $cdn_engine == 'akamai' && !count($c->get_array('cdn.akamai.domain')):
             $error = 'The <strong>"Replace default hostname with"</strong> field cannot be empty.';
             break;
     }
     if ($error) {
         $errors['cdn_not_configured'] = __('A configuration issue prevents <acronym title="Content Delivery Network">CDN</acronym> from working: ', 'w3-total-cache') . $error . __(' <a href="?page=w3tc_cdn#configuration">Specify it here</a>.', 'w3-total-cache');
     }
     return $errors;
 }
Esempio n. 9
0
		<?php 
Util_Ui::button_config_save('cdn_general');
?>
		<?php 
Util_Ui::postbox_footer();
?>

		<?php 
Util_Ui::postbox_header(__('Configuration', 'w3-total-cache'), '', 'configuration');
?>
		<table class="form-table">
			<?php 
if ($cdn_engine == 'google_drive' || $cdn_engine == 'highwinds' || $cdn_engine == 'rackspace_cdn' || $cdn_engine == 'rscf') {
    do_action('w3tc_settings_cdn_boxarea_configuration');
} else {
    if (Cdn_Util::is_engine($cdn_engine)) {
        include W3TC_INC_DIR . '/options/cdn/' . $cdn_engine . '.php';
    }
}
?>
		</table>

		<?php 
Util_Ui::button_config_save('cdn_configuration');
?>
		<?php 
Util_Ui::postbox_footer();
?>

		<?php 
Util_Ui::postbox_header(__('Advanced', 'w3-total-cache'), '', 'advanced');
Esempio n. 10
0
 /**
  * CDN Test action
  *
  * @return void
  */
 function w3tc_cdn_test()
 {
     $engine = Util_Request::get_string('engine');
     $config = Util_Request::get_array('config');
     //TODO: Workaround to support test case cdn/a04
     if ($engine == 'ftp' && !isset($config['host'])) {
         $config = Util_Request::get_string('config');
         $config = json_decode($config, true);
     }
     $config = array_merge($config, array('debug' => false));
     if (isset($config['domain']) && !is_array($config['domain'])) {
         $config['domain'] = explode(',', $config['domain']);
     }
     if (Cdn_Util::is_engine($engine)) {
         $result = true;
         $error = null;
     } else {
         $result = false;
         $error = __('Incorrect engine ' . $engine, 'w3-total-cache');
     }
     if (!isset($config['docroot'])) {
         $config['docroot'] = Util_Environment::document_root();
     }
     if ($result) {
         if ($engine == 'google_drive' || $engine == 'highwinds' || $engine == 'rackspace_cdn' || $engine == 'rscf' || $engine == 's3_compatible') {
             // those use already stored w3tc config
             $w3_cdn = Dispatcher::component('Cdn_Core')->get_cdn();
         } else {
             // those use dynamic config from the page
             $w3_cdn = CdnEngine::instance($engine, $config);
         }
         @set_time_limit($this->_config->get_integer('timelimit.cdn_test'));
         if ($w3_cdn->test($error)) {
             $result = true;
             $error = __('Test passed', 'w3-total-cache');
         } else {
             $result = false;
             $error = sprintf(__('Error: %s', 'w3-total-cache'), $error);
         }
     }
     $response = array('result' => $result, 'error' => $error);
     echo json_encode($response);
 }
Esempio n. 11
0
 /**
  * Convert local uri path to CDN type specific path
  *
  * @param unknown $local_uri_path
  * @return string
  */
 function uri_to_cdn_uri($local_uri)
 {
     $local_uri = ltrim($local_uri, '/');
     $remote_uri = $local_uri;
     if (Util_Environment::is_wpmu() && defined('DOMAIN_MAPPING') && DOMAIN_MAPPING) {
         $remote_uri = str_replace(site_url(), '', $local_uri);
     }
     $engine = $this->_config->get_string('cdn.engine');
     if (Cdn_Util::is_engine_mirror($engine)) {
         if (Util_Environment::is_wpmu() && strpos($local_uri, 'files') === 0) {
             $upload_dir = Util_Environment::wp_upload_dir();
             $remote_uri = $this->abspath_to_relative_path(dirname($upload_dir['basedir'])) . '/' . $local_uri;
         }
     } elseif (Util_Environment::is_wpmu() && !Util_Environment::is_wpmu_subdomain() && Util_Environment::is_using_master_config() && Cdn_Util::is_engine_push($engine)) {
         // in common config files are uploaded for network home url
         // so mirror will not contain /subblog/ path in uri
         $home = trim(home_url('', 'relative'), '/') . '/';
         $network_home = trim(network_home_url('', 'relative'), '/') . '/';
         if ($home != $network_home && substr($local_uri, 0, strlen($home)) == $home) {
             $remote_uri = $network_home . substr($local_uri, strlen($home));
         }
     }
     return ltrim($remote_uri, '/');
 }
Esempio n. 12
0
 /**
  * Link replace callback, url replacement using cdn engine
  *
  * @param string  $match
  * @param string  $quote
  * @param string  $url
  * @param string  $path
  * @return null|string
  */
 function _link_replace_callback_ask_cdn($match, $quote, $url, $path)
 {
     $common = Dispatcher::component('Cdn_Core');
     $cdn = $common->get_cdn();
     $remote_path = $common->uri_to_cdn_uri($path);
     $new_url = $cdn->format_url($remote_path);
     if ($new_url) {
         $is_engine_mirror = Cdn_Util::is_engine_mirror($this->_config->get_string('cdn.engine'));
         $new_url = apply_filters('w3tc_cdn_url', $new_url, $url, $is_engine_mirror);
         $this->replaced_urls[$url] = $new_url;
         return $quote . $new_url;
     }
     return $match;
 }
Esempio n. 13
0
 /**
  * Save config, can't decline save process. (difference from action_save)
  *
  * Do some actions on config keys update
  * Used in several places such as:
  *
  * 1. common config save
  * 2. import settings
  *
  * @param Config  $current_config
  * @param Config  $new_config
  * @return bool
  * @throws Exception
  */
 public static function config_save($current_config, $new_config)
 {
     $master_config = $new_config->is_master() ? $new_config : Dispatcher::config_master();
     if ($master_config->get_integer('common.instance_id', 0) == 0) {
         $master_config->set('common.instance_id', mt_rand());
         if (!$new_config->is_master()) {
             $master_config->save();
         }
     }
     $old_config = new Config();
     $browsercache_dependencies = array();
     if ($new_config->get_boolean('browsercache.enabled')) {
         $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.rewrite', 'browsercache.cssjs.replace', 'browsercache.html.replace', 'browsercache.other.replace'));
         if ($new_config->get_boolean('browsercache.cssjs.replace')) {
             $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.cssjs.compression', 'browsercache.cssjs.expires', 'browsercache.cssjs.lifetime', 'browsercache.cssjs.cache.control', 'browsercache.cssjs.cache.policy', 'browsercache.cssjs.etag', 'browsercache.cssjs.w3tc'));
         }
         if ($new_config->get_boolean('browsercache.html.replace')) {
             $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.html.compression', 'browsercache.html.expires', 'browsercache.html.lifetime', 'browsercache.html.cache.control', 'browsercache.html.cache.policy', 'browsercache.html.etag', 'browsercache.html.w3tc'));
         }
         if ($new_config->get_boolean('browsercache.other.replace')) {
             $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.other.compression', 'browsercache.other.expires', 'browsercache.other.lifetime', 'browsercache.other.cache.control', 'browsercache.other.cache.policy', 'browsercache.other.etag', 'browsercache.other.w3tc'));
         }
         $old_bc_dependencies_values = array();
         $new_bc_dependencies_values = array();
         foreach ($browsercache_dependencies as $key) {
             $old_bc_dependencies_values[] = $old_config->get($key);
             $new_bc_dependencies_values[] = $new_config->get($key);
         }
         if (serialize($old_bc_dependencies_values) != serialize($new_bc_dependencies_values)) {
             $state_note = Dispatcher::config_state_note();
             $state_note->set('common.show_note.flush_statics_needed', true);
         }
     }
     /**
      * Show need empty page cache notification
      */
     $cache_flush = Dispatcher::component('CacheFlush');
     if ($cache_flush->flushable_posts()) {
         $pgcache_dependencies = array_merge($browsercache_dependencies, array('pgcache.debug', 'pgcache.cache.query', 'pgcache.cache.home', 'pgcache.cache.feed', 'pgcache.cache.nginx_handle_xml', 'pgcache.cache.ssl', 'pgcache.cache.404', 'pgcache.cache.headers', 'pgcache.compatibility', 'pgcache.remove_charset', 'pgcache.accept.uri', 'pgcache.accept.files', 'pgcache.accept.qs', 'pgcache.late_init', 'pgcache.mirrors.enabled', 'pgcache.reject.front_page', 'pgcache.reject.logged', 'pgcache.reject.logged_roles', 'pgcache.reject.uri', 'pgcache.reject.ua', 'pgcache.reject.cookie', 'pgcache.reject.request_head', 'dbcache.enabled', 'objectcache.enabled', 'minify.enabled', 'mobile.enabled', 'referrer.enabled'));
         if ($new_config->get_boolean('pgcache.mirrors.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('pgcache.mirrors.home_urls'));
         }
         if ($new_config->get_boolean('dbcache.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('dbcache.debug'));
         }
         if ($new_config->get_boolean('objectcache.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('objectcache.debug'));
         }
         if ($new_config->get_boolean('minify.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('minify.auto', 'minify.debug', 'minify.rewrite', 'minify.html.enable', 'minify.html.engine', 'minify.html.inline.css', 'minify.html.inline.js', 'minify.html.strip.crlf', 'minify.html.comments.ignore', 'minify.css.enable', 'minify.css.engine', 'minify.css.groups', 'minify.js.enable', 'minify.js.engine', 'minify.js.groups', 'minify.htmltidy.options.clean', 'minify.htmltidy.options.hide-comments', 'minify.htmltidy.options.wrap', 'minify.reject.logged', 'minify.reject.ua', 'minify.reject.uri'));
         }
         /**
          *
          *
          * @var W3_ModuleStatus $modules
          */
         $modules = Dispatcher::component('ModuleStatus');
         if ($modules->is_running('cdn')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('cdn.enabled', 'cdn.debug', 'cdn.engine', 'cdn.uploads.enable', 'cdn.includes.enable', 'cdn.includes.files', 'cdn.theme.enable', 'cdn.theme.files', 'cdn.minify.enable', 'cdn.custom.enable', 'cdn.custom.files', 'cdn.ftp.domain', 'cdn.ftp.ssl', 'cdn.s3.cname', 'cdn.s3.ssl', 'cdn.cf.cname', 'cdn.cf.ssl', 'cdn.cf2.cname', 'cdn.cf2.ssl', 'cdn.rscf.cname', 'cdn.rscf.ssl', 'cdn.azure.cname', 'cdn.azure.ssl', 'cdn.mirror.domain', 'cdn.mirror.ssl', 'cdn.netdna.domain', 'cdn.netdna.ssl', 'cdn.cotendo.domain', 'cdn.cotendo.ssl', 'cdn.edgecast.domain', 'cdn.edgecast.ssl', 'cdn.att.domain', 'cdn.att.ssl', 'cdn.reject.logged_roles', 'cdn.reject.roles', 'cdn.reject.ua', 'cdn.reject.uri', 'cdn.reject.files'));
         } elseif ($old_config->get_boolean('cdn.enabled') && !$new_config->get_boolean('cdn.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('cdn.enabled'));
         }
         if ($new_config->get_boolean('mobile.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('mobile.rgroups'));
         }
         if ($new_config->get_boolean('referrer.enabled')) {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('referrer.rgroups'));
         }
         if ($new_config->get_boolean('browsercache.enabled') && $new_config->get_string('pgcache.engine') == 'file_generic') {
             $pgcache_dependencies = array_merge($pgcache_dependencies, array('browsercache.html.last_modified', 'browsercache.other.last_modified'));
         }
         $old_pgcache_dependencies_values = array();
         $new_pgcache_dependencies_values = array();
         foreach ($pgcache_dependencies as $pgcache_dependency) {
             $old_pgcache_dependencies_values[] = $old_config->get($pgcache_dependency);
             $new_pgcache_dependencies_values[] = $new_config->get($pgcache_dependency);
         }
         if (serialize($old_pgcache_dependencies_values) != serialize($new_pgcache_dependencies_values)) {
             $state_note = Dispatcher::config_state_note();
             $state_note->set('common.show_note.flush_posts_needed', true);
         }
     }
     /**
      * Show need empty minify notification
      */
     if ($current_config->get_boolean('minify.enabled') && $new_config->get_boolean('minify.enabled') && ($new_config->get_boolean('minify.css.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.css.groups'))) || $new_config->get_boolean('minify.js.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.js.groups'))))) {
         $minify_dependencies = array_merge($browsercache_dependencies, array('minify.auto', 'minify.debug', 'minify.options', 'minify.symlinks', 'minify.css.enable', 'minify.js.enable'));
         if ($new_config->get_boolean('minify.css.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.css.groups')))) {
             $minify_dependencies = array_merge($minify_dependencies, array('minify.css.engine', 'minify.css.combine', 'minify.css.strip.comments', 'minify.css.strip.crlf', 'minify.css.imports', 'minify.css.groups', 'minify.yuicss.path.java', 'minify.yuicss.path.jar', 'minify.yuicss.options.line-break', 'minify.csstidy.options.remove_bslash', 'minify.csstidy.options.compress_colors', 'minify.csstidy.options.compress_font-weight', 'minify.csstidy.options.lowercase_s', 'minify.csstidy.options.optimise_shorthands', 'minify.csstidy.options.remove_last_;', 'minify.csstidy.options.case_properties', 'minify.csstidy.options.sort_properties', 'minify.csstidy.options.sort_selectors', 'minify.csstidy.options.merge_selectors', 'minify.csstidy.options.discard_invalid_properties', 'minify.csstidy.options.css_level', 'minify.csstidy.options.preserve_css', 'minify.csstidy.options.timestamp', 'minify.csstidy.options.template'));
         }
         if ($new_config->get_boolean('minify.js.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.js.groups')))) {
             $minify_dependencies = array_merge($minify_dependencies, array('minify.js.engine', 'minify.js.combine.header', 'minify.js.combine.body', 'minify.js.combine.footer', 'minify.js.strip.comments', 'minify.js.strip.crlf', 'minify.js.groups', 'minify.yuijs.path.java', 'minify.yuijs.path.jar', 'minify.yuijs.options.line-break', 'minify.yuijs.options.nomunge', 'minify.yuijs.options.preserve-semi', 'minify.yuijs.options.disable-optimizations', 'minify.ccjs.path.java', 'minify.ccjs.path.jar', 'minify.ccjs.options.compilation_level', 'minify.ccjs.options.formatting'));
         }
         /**
          *
          *
          * @var W3_ModuleStatus $modules
          */
         $modules = Dispatcher::component('ModuleStatus');
         if ($modules->is_running('cdn')) {
             $minify_dependencies = array_merge($minify_dependencies, array('cdn.engine', 'cdn.enabled'));
         } elseif ($old_config->get_boolean('cdn.enabled') && !$new_config->get_boolean('cdn.enabled')) {
             $minify_dependencies = array_merge($minify_dependencies, array('cdn.enabled'));
         }
         $old_minify_dependencies_values = array();
         $new_minify_dependencies_values = array();
         foreach ($minify_dependencies as $minify_dependency) {
             $old_minify_dependencies_values[] = $old_config->get($minify_dependency);
             $new_minify_dependencies_values[] = $new_config->get($minify_dependency);
         }
         if (serialize($old_minify_dependencies_values) != serialize($new_minify_dependencies_values)) {
             $state_note = Dispatcher::config_state_note();
             $state_note->set('minify.show_note.need_flush', true);
         }
     }
     if ($new_config->get_boolean('cdn.enabled') && !Cdn_Util::is_engine_mirror($new_config->get_string('cdn.engine'))) {
         /**
          * Show notification when CDN enabled
          */
         if (!$old_config->get_boolean('cdn.enabled')) {
             $state = Dispatcher::config_state();
             $state->set('cdn.show_note_cdn_upload', true);
             $state->save();
         }
         /**
          * Show notification when Browser Cache settings changes
          */
         $cdn_dependencies = array('browsercache.enabled');
         if ($new_config->get_boolean('cdn.enabled')) {
             $cdn_dependencies = array('browsercache.cssjs.compression', 'browsercache.cssjs.expires', 'browsercache.cssjs.lifetime', 'browsercache.cssjs.cache.control', 'browsercache.cssjs.cache.policy', 'browsercache.cssjs.etag', 'browsercache.cssjs.w3tc', 'browsercache.html.compression', 'browsercache.html.expires', 'browsercache.html.lifetime', 'browsercache.html.cache.control', 'browsercache.html.cache.policy', 'browsercache.html.etag', 'browsercache.html.w3tc', 'browsercache.other.compression', 'browsercache.other.expires', 'browsercache.other.lifetime', 'browsercache.other.cache.control', 'browsercache.other.cache.policy', 'browsercache.other.etag', 'browsercache.other.w3tc');
         }
         $old_cdn_dependencies_values = array();
         $new_cdn_dependencies_values = array();
         foreach ($cdn_dependencies as $cdn_dependency) {
             $old_cdn_dependencies_values[] = $old_config->get($cdn_dependency);
             $new_cdn_dependencies_values[] = $new_config->get($cdn_dependency);
         }
         if (serialize($old_cdn_dependencies_values) != serialize($new_cdn_dependencies_values)) {
             $state = Dispatcher::config_state();
             $state->set('cdn.show_note_cdn_reupload', true);
             $state->save();
         }
     }
     /**
      * Show need empty object cache notification
      */
     if ($current_config->get_boolean('objectcache.enabled')) {
         $objectcache_dependencies = array('objectcache.groups.global', 'objectcache.groups.nonpersistent');
         $old_objectcache_dependencies_values = array();
         $new_objectcache_dependencies_values = array();
         foreach ($objectcache_dependencies as $objectcache_dependency) {
             $old_objectcache_dependencies_values[] = $old_config->get($objectcache_dependency);
             $new_objectcache_dependencies_values[] = $new_config->get($objectcache_dependency);
         }
         if (serialize($old_objectcache_dependencies_values) != serialize($new_objectcache_dependencies_values)) {
             $state_note = Dispatcher::config_state_note();
             $state_note->set('objectcache.show_note.flush_needed', true);
         }
     }
     do_action('w3tc_saved_options', $new_config);
     /**
      * Save config
      */
     try {
         $new_config->save();
     } catch (\Exception $ex) {
         // try to fix environment, it potentially can be fixed silently
         // dont show error here, it will be called again later
         // in admin_notices
         try {
             $environment = Dispatcher::component('Root_Environment');
             $environment->fix_in_wpadmin($new_config);
         } catch (\Exception $ex) {
         }
         // retry save process and complain now on failure
         try {
             $new_config->save();
         } catch (\Exception $ex) {
             throw new \Exception('<strong>Can\'t change configuration</strong>: ' . $ex->getMessage());
         }
     }
     $w3_plugin_cdn = Dispatcher::component('Cdn_Core_Admin');
     /**
      * Empty caches on engine change or cache enable/disable
      */
     if ($old_config->get_string('pgcache.engine') != $new_config->get_string('pgcache.engine') || $old_config->get_string('pgcache.enabled') != $new_config->get_string('pgcache.enabled')) {
         $pgcacheflush = Dispatcher::component('PgCache_Flush');
         $v = $pgcacheflush->flush();
     }
     if ($old_config->get_string('dbcache.engine') != $new_config->get_string('dbcache.engine') || $old_config->get_string('dbcache.enabled') != $new_config->get_string('dbcache.enabled')) {
         w3tc_dbcache_flush();
     }
     if ($old_config->get_string('objectcache.engine') != $new_config->get_string('objectcache.engine') || $old_config->get_string('objectcache.enabled') != $new_config->get_string('objectcache.enabled')) {
         w3tc_objectcache_flush();
     }
     if ($old_config->get_string('minify.engine') != $new_config->get_string('minify.engine') || $old_config->get_string('minify.enabled') != $new_config->get_string('minify.enabled')) {
         w3tc_minify_flush();
     }
     /**
      * Update CloudFront CNAMEs
      */
     $update_cf_cnames = false;
     if ($new_config->get_boolean('cdn.enabled') && in_array($new_config->get_string('cdn.engine'), array('cf', 'cf2'))) {
         if ($new_config->get_string('cdn.engine') == 'cf') {
             $old_cnames = $old_config->get_array('cdn.cf.cname');
             $new_cnames = $new_config->get_array('cdn.cf.cname');
         } else {
             $old_cnames = $old_config->get_array('cdn.cf2.cname');
             $new_cnames = $new_config->get_array('cdn.cf2.cname');
         }
         if (count($old_cnames) != count($new_cnames) || count(array_diff($old_cnames, $new_cnames))) {
             $update_cf_cnames = true;
         }
     }
     /**
      * Refresh config
      */
     $current_config->load();
     /**
      * React to config changes
      */
     $environment = Dispatcher::component('Root_Environment');
     $environment->fix_on_event($new_config, 'config_change', $old_config);
     /**
      * Update support us option
      */
     Generic_AdminLinks::link_update($current_config);
     /**
      * Auto upload browsercache files to CDN
      */
     if ($new_config->get_boolean('cdn.enabled') && $new_config->get_string('cdn.engine') == 'ftp') {
         Util_Admin::cdn_delete_browsercache($current_config);
         Util_Admin::cdn_upload_browsercache($current_config);
     }
     /**
      * Update CloudFront CNAMEs
      */
     if ($update_cf_cnames) {
         $error = null;
         $w3_plugin_cdn->update_cnames($error);
     }
     return true;
 }