/**
  * Checks if addins in wp-content is available and correct version.
  *
  * @param unknown $config
  * @param Util_Environment_Exceptions $exs
  */
 private function create_required_files($config, $exs)
 {
     $src = W3TC_INSTALL_FILE_ADVANCED_CACHE;
     $dst = W3TC_ADDIN_FILE_ADVANCED_CACHE;
     if ($this->advanced_cache_installed()) {
         if ($this->is_advanced_cache_add_in()) {
             $script_data = @file_get_contents($dst);
             if ($script_data == @file_get_contents($src)) {
                 return;
             }
         } else {
             if (get_transient('w3tc_remove_add_in_pgcache') == 'yes') {
                 // user already manually asked to remove another plugin's add in,
                 // we should try to apply ours
                 // (in case of missing permissions deletion could fail)
             } else {
                 if (!$this->advanced_cache_check_old_add_in()) {
                     $remove_url = Util_Ui::admin_url('admin.php?page=w3tc_dashboard&w3tc_default_remove_add_in=pgcache');
                     $exs->push(new Util_WpFile_FilesystemOperationException(sprintf(__('The Page Cache add-in file advanced-cache.php is not a W3 Total Cache drop-in.
                 It should be removed. %s', 'w3-total-cache'), Util_Ui::button_link(__('Yes, remove it for me', 'w3-total-cache'), wp_nonce_url($remove_url, 'w3tc')))));
                     return;
                 }
             }
         }
     }
     try {
         Util_WpFile::copy_file($src, $dst);
     } catch (Util_WpFile_FilesystemOperationException $ex) {
         $exs->push($ex);
     }
 }
 /**
  *
  *
  * @param Config  $config
  * @return string
  */
 function notifications($config)
 {
     $config_state = Dispatcher::config_state();
     if (!$config_state->get_boolean('newrelic.hide_note_pageload_slow')) {
         $pl = get_option('w3tc_nr_frontend_response_time');
         if ($pl !== false && $pl > 0.3) {
             $nr_recommends = array();
             if (!$config->get_boolean('pgcache.enabled')) {
                 $nr_recommends[] = __('Page Cache', 'w3-total-cache');
             }
             if (!$config->get_boolean('minify.enabled')) {
                 $nr_recommends[] = __('Minify', 'w3-total-cache');
             }
             if (!$config->get_boolean('cdn.enabled')) {
                 $nr_recommends[] = __('CDN', 'w3-total-cache');
             }
             if (!$config->get_boolean('browsercache.enabled')) {
                 $nr_recommends[] = __('Browser Cache and use compression', 'w3-total-cache');
             }
             if ($nr_recommends) {
                 $message = sprintf(__('Application monitoring has detected that your page load time is higher than 300ms. It is recommended that you enable the following features: %s %s', 'w3-total-cache'), implode(', ', $nr_recommends), Util_Ui::button_link('Hide this message', Util_Ui::url(array('w3tc_default_config_state' => 'y', 'key' => 'newrelic.hide_note_pageload_slow', 'value' => 'true'))));
                 return array('newrelic_recommends' => $message);
             }
         }
     }
     return array();
 }
 public static function w3tc_notes_wordpress_seo($notes)
 {
     if (!self::show_notice()) {
         return $notes;
     }
     $extension_id = 'wordpress-seo';
     $notes[$extension_id] = sprintf(__('It appears that activating the <a href="%s">Yoast SEO</a> extension for W3 Total Cache will be helpful for your site. <a class="button" href="%s">Click here</a> to try it. %s', 'w3-total-cache'), Util_Ui::admin_url('admin.php?page=w3tc_extensions#' . $extension_id), Util_Ui::url(array('w3tc_extensions_activate' => $extension_id)), Util_Ui::button_link(__('Hide this message', 'w3-total-cache'), Util_Ui::url(array('w3tc_default_config_state' => 'y', 'key' => 'wordpress_seo.hide_note_suggest_activation', 'value' => 'true'))));
     return $notes;
 }
 public static function w3tc_notes_wpml($notes)
 {
     if (!self::show_notice()) {
         return $notes;
     }
     $extension_id = 'wpml';
     $config = Dispatcher::config();
     if (!Util_Environment::is_w3tc_pro($config)) {
         $activate_text = 'Available after <a href="#" class="button-buy-plugin">upgrade</a>. ';
     } else {
         $activate_text = sprintf('<a class="button" href="%s">Click here</a> to try it. ', Util_Ui::url(array('w3tc_extensions_activate' => $extension_id)));
     }
     $notes[$extension_id] = sprintf(__('Activating the <a href="%s">WPML</a> extension for W3 Total Cache may be helpful for your site. %s%s', 'w3-total-cache'), Util_Ui::admin_url('admin.php?page=w3tc_extensions#' . $extension_id), $activate_text, Util_Ui::button_link(__('Hide this message', 'w3-total-cache'), Util_Ui::url(array('w3tc_default_config_state' => 'y', 'key' => 'wpml.hide_note_suggest_activation', 'value' => 'true'))));
     return $notes;
 }
<?php

namespace W3TC;

if (!defined('W3TC')) {
    die;
}
?>
<p>
	<?php 
echo Util_Ui::button_link(__('purge CDN completely', 'w3-total-cache'), Util_Ui::url(array('w3tc_cdn_flush' => 'y')));
?>
</p>
<?php 
 /**
  * Creates add-in
  *
  * @throws Util_WpFile_FilesystemOperationException
  */
 private function create_addin()
 {
     $src = W3TC_INSTALL_FILE_DB;
     $dst = W3TC_ADDIN_FILE_DB;
     if ($this->db_installed()) {
         if ($this->is_dbcache_add_in()) {
             $script_data = @file_get_contents($dst);
             if ($script_data == @file_get_contents($src)) {
                 return;
             }
         } else {
             if (get_transient('w3tc_remove_add_in_dbcache') == 'yes') {
                 // user already manually asked to remove another plugin's add in,
                 // we should try to apply ours
                 // (in case of missing permissions deletion could fail)
             } else {
                 if (!$this->db_check_old_add_in()) {
                     if (isset($_GET['page'])) {
                         $url = 'admin.php?page=' . $_GET['page'] . '&amp;';
                     } else {
                         $url = basename(Util_Environment::remove_query($_SERVER['REQUEST_URI'])) . '?page=w3tc_dashboard&amp;';
                     }
                     $remove_url = Util_Ui::admin_url($url . 'w3tc_default_remove_add_in=dbcache');
                     throw new Util_WpFile_FilesystemOperationException(sprintf(__('The Database add-in file db.php is not a W3 Total Cache drop-in.
                 Remove it or disable Database Caching. %s', 'w3-total-cache'), Util_Ui::button_link(__('Remove it for me', 'w3-total-cache'), wp_nonce_url($remove_url, 'w3tc'))));
                 }
             }
         }
     }
     Util_WpFile::copy_file($src, $dst);
 }
 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;
 }
 /**
  *
  *
  * @param Config  $config
  * @return string
  */
 function w3tc_notes($notes)
 {
     $c = Dispatcher::config();
     $state = Dispatcher::config_state();
     $state_master = Dispatcher::config_state_master();
     $state_note = Dispatcher::config_state_note();
     /**
      * Check wp-content permissions
      */
     if (!W3TC_WIN && !$state_master->get_boolean('common.hide_note_wp_content_permissions')) {
         $wp_content_mode = Util_File::get_file_permissions(WP_CONTENT_DIR);
         if ($wp_content_mode > 0755) {
             $notes['generic_wp_content_writeable'] = sprintf(__('<strong>%s</strong> is write-able. When finished installing the plugin, change the permissions back to the default: <strong>chmod 755 %s</strong>. Permissions are currently %s. %s', 'w3-total-cache'), WP_CONTENT_DIR, WP_CONTENT_DIR, base_convert(Util_File::get_file_permissions(WP_CONTENT_DIR), 10, 8), Util_Ui::button_hide_note2(array('w3tc_default_config_state_master' => 'y', 'key' => 'common.hide_note_wp_content_permissions', 'value' => 'true')));
         }
     }
     /**
      * Check Zlib extension
      */
     if (!$state_master->get_boolean('common.hide_note_no_zlib') && !function_exists('gzencode')) {
         $notes['no_zlib'] = sprintf(__('Unfortunately the PHP installation is incomplete, the <strong>zlib module is missing</strong>. This is a core PHP module. Notify the server administrator. %s', 'w3-total-cache'), Util_Ui::button_hide_note2(array('w3tc_default_config_state_master' => 'y', 'key' => 'common.hide_note_no_zlib', 'value' => 'true')));
     }
     /**
      * Check if Zlib output compression is enabled
      */
     if (!$state_master->get_boolean('common.hide_note_zlib_output_compression') && Util_Environment::is_zlib_enabled()) {
         $notes['zlib_output_compression'] = sprintf(__('Either the PHP configuration, web server configuration or a script in the WordPress installation has <strong>zlib.output_compression</strong> enabled.<br />Please locate and disable this setting to ensure proper HTTP compression behavior. %s', 'w3-total-cache'), Util_Ui::button_hide_note2(array('w3tc_default_config_state_master' => 'y', 'key' => 'common.hide_note_zlib_output_compression', 'value' => 'true')));
     }
     if ($state_master->get_boolean('common.show_note.nginx_restart_required')) {
         $cf = Dispatcher::component('CacheFlush');
         $notes['nginx_restart_required'] = sprintf(__('nginx.conf rules have been updated. Please restart nginx server to provide a consistent user experience. %s', 'w3-total-cache'), Util_Ui::button_hide_note2(array('w3tc_default_config_state_master' => 'y', 'key' => 'common.show_note.nginx_restart_required', 'value' => 'false')));
     }
     /**
      * Preview mode
      */
     if ($c->is_preview()) {
         $notes['preview_mode'] = sprintf(__('Preview mode is active: Changed settings will not take effect until preview mode is %s or %s.', 'w3-total-cache'), Util_Ui::button_link(__('deploy', 'w3-total-cache'), Util_Ui::url(array('w3tc_config_preview_deploy' => 'y'))), Util_Ui::button_link(__('disable', 'w3-total-cache'), Util_Ui::url(array('w3tc_config_preview_disable' => 'y')))) . '<br /><span class="description">' . sprintf(__('To preview any changed settings (without deploying): %s', 'w3-total-cache'), Util_Ui::preview_link()) . '</span>';
     }
     /**
      * Show notification after plugin activate/deactivate
      */
     if ($state_note->get('common.show_note.plugins_updated') && !is_network_admin()) {
         $texts = array();
         if ($c->get_boolean('pgcache.enabled')) {
             $texts[] = Util_Ui::button_link(__('empty the page cache', 'w3-total-cache'), Util_Ui::url(array('w3tc_flush_posts' => 'y')));
         }
         if ($c->get_boolean('minify.enabled')) {
             $texts[] = sprintf(__('check the %s to maintain the desired user experience', 'w3-total-cache'), Util_Ui::button_link(__('minify settings', 'w3-total-cache'), Util_Ui::url(array('w3tc_default_config_state_note' => 'y', 'key' => 'common.show_note.plugins_updated', 'value' => 'false'))));
         }
         if (count($texts)) {
             $notes['some_plugins_activated'] = sprintf(__('One or more plugins have been activated or deactivated, please %s. %s', 'w3-total-cache'), implode(__(' and ', 'w3-total-cache'), $texts), Util_Ui::button_hide_note2(array('w3tc_default_config_state_note' => 'y', 'key' => 'common.show_note.plugins_updated', 'value' => 'false')));
         }
     }
     /**
      * Show notification when flush_statics needed
      */
     if ($c->get_boolean('browsercache.enabled') && $state_note->get('common.show_note.flush_statics_needed') && !is_network_admin() && !$c->is_preview()) {
         $notes['flush_statics_needed'] = sprintf(__('The setting change(s) made either invalidate the cached data or modify the behavior of the site. %s now to provide a consistent user experience. %s', 'w3-total-cache'), Util_Ui::button_link('Empty the static files cache', Util_Ui::url(array('w3tc_flush_statics' => 'y'))), Util_Ui::button_hide_note2(array('w3tc_default_config_state_note' => 'y', 'key' => 'common.show_note.flush_statics_needed', 'value' => 'false')));
     }
     /**
      * Show notification when flush_posts needed
      */
     if ($state_note->get('common.show_note.flush_posts_needed') && !is_network_admin() && !$c->is_preview() && !isset($notes['flush_statics_needed'])) {
         $cf = Dispatcher::component('CacheFlush');
         if ($cf->flushable_posts()) {
             $notes['flush_posts_needed'] = sprintf(__('The setting change(s) made either invalidate the cached data or modify the behavior of the site. %s now to provide a consistent user experience. %s', 'w3-total-cache'), Util_Ui::button_link('Empty the page cache', Util_Ui::url(array('w3tc_flush_posts' => 'y'))), Util_Ui::button_hide_note2(array('w3tc_default_config_state_note' => 'y', 'key' => 'common.show_note.flush_posts_needed', 'value' => 'false')));
         }
     }
     return $notes;
 }
 public static function w3tc_notes_genesis_theme($notes)
 {
     if (!self::show_notice()) {
         return $notes;
     }
     $extension_id = 'genesis.theme';
     $notes[$extension_id] = sprintf(__('Activating the <a href="%s">Genesis Theme</a> extension for W3 Total Cache may be helpful for your site. <a href="%s">Click here</a> to try it. %s', 'w3-total-cache'), Util_Ui::admin_url('admin.php?page=w3tc_extensions#' . $extension_id), Util_Ui::url(array('w3tc_extensions_activate' => $extension_id)), Util_Ui::button_link(__('Hide this message', 'w3-total-cache'), Util_Ui::url(array('w3tc_default_config_state' => 'y', 'key' => 'genesis.theme.hide_note_suggest_activation', 'value' => 'true'))));
     return $notes;
 }
 function w3tc_notes($notes)
 {
     $state_note = Dispatcher::config_state();
     /**
      * Show notification when minify needs to be emptied
      */
     if ($state_note->get_boolean('minify.show_note.need_flush') && !is_network_admin() && !$this->_config->is_preview()) {
         $notes['minify_flush_needed'] = sprintf(__('The setting change(s) made either invalidate the cached data or modify the behavior of the site. %s now to provide a consistent user experience.', 'w3-total-cache'), Util_Ui::button_link(__('Empty the minify cache', 'w3-total-cache'), Util_Ui::url(array('w3tc_flush_minify' => 'y'))));
     }
     return $notes;
 }
 /**
  * Admin notices action
  *
  * @return void
  */
 function admin_notices()
 {
     $cookie_domain = Util_Admin::get_cookie_domain();
     $error_messages = array('fancy_permalinks_disabled_pgcache' => sprintf(__('Fancy permalinks are disabled. Please %s it first, then re-attempt to enabling enhanced disk mode.', 'w3-total-cache'), Util_Ui::button_link('enable', 'options-permalink.php')), 'fancy_permalinks_disabled_browsercache' => sprintf(__('Fancy permalinks are disabled. Please %s it first, then re-attempt to enabling the \'Do not process 404 errors for static objects with WordPress\'.', 'w3-total-cache'), Util_Ui::button_link('enable', 'options-permalink.php')), 'support_request' => __('Failed to send support request.', 'w3-total-cache'), 'support_request_type' => __('Please select request type.', 'w3-total-cache'), 'support_request_url' => __('Please enter the address of the site in the site <acronym title="Uniform Resource Locator">URL</acronym> field.', 'w3-total-cache'), 'support_request_name' => __('Please enter your name in the Name field', 'w3-total-cache'), 'support_request_email' => __('Please enter valid email address in the E-Mail field.', 'w3-total-cache'), 'support_request_phone' => __('Please enter your phone in the phone field.', 'w3-total-cache'), 'support_request_subject' => __('Please enter subject in the subject field.', 'w3-total-cache'), 'support_request_description' => __('Please describe the issue in the issue description field.', 'w3-total-cache'), 'support_request_wp_login' => __('Please enter an administrator login. Create a temporary one just for this support case if needed.', 'w3-total-cache'), 'support_request_wp_password' => __('Please enter WP Admin password, be sure it\'s spelled correctly.', 'w3-total-cache'), 'support_request_ftp_host' => __('Please enter <acronym title="Secure Shell">SSH</acronym> or <acronym title="File Transfer Protocol">FTP</acronym> host for the site.', 'w3-total-cache'), 'support_request_ftp_login' => __('Please enter <acronym title="Secure Shell">SSH</acronym> or <acronym title="File Transfer Protocol">FTP</acronym> login for the server. Create a temporary one just for this support case if needed.', 'w3-total-cache'), 'support_request_ftp_password' => __('Please enter <acronym title="Secure Shell">SSH</acronym> or <acronym title="File Transfer Protocol">FTP</acronym> password for the <acronym title="File Transfer Protocol">FTP</acronym> account.', 'w3-total-cache'), 'support_request' => __('Unable to send the support request.', 'w3-total-cache'), 'config_import_no_file' => __('Please select config file.', 'w3-total-cache'), 'config_import_upload' => __('Unable to upload config file.', 'w3-total-cache'), 'config_import_import' => __('Configuration file could not be imported.', 'w3-total-cache'), 'config_reset' => sprintf(__('Default settings could not be restored. Please run <strong>chmod 777 %s</strong> to make the configuration file write-able, then try again.', 'w3-total-cache'), W3TC_CONFIG_DIR), 'cdn_purge_attachment' => __('Unable to purge attachment.', 'w3-total-cache'), 'pgcache_purge_post' => __('Unable to purge post.', 'w3-total-cache'), 'enable_cookie_domain' => sprintf(__('<strong>%swp-config.php</strong> could not be written, please edit config and add:<br /><strong style="color:#f00;">define(\'COOKIE_DOMAIN\', \'%s\');</strong> before <strong style="color:#f00;">require_once(ABSPATH . \'wp-settings.php\');</strong>.', 'w3-total-cache'), ABSPATH, addslashes($cookie_domain)), 'disable_cookie_domain' => sprintf(__('<strong>%swp-config.php</strong> could not be written, please edit config and add:<br /><strong style="color:#f00;">define(\'COOKIE_DOMAIN\', false);</strong> before <strong style="color:#f00;">require_once(ABSPATH . \'wp-settings.php\');</strong>.', 'w3-total-cache'), ABSPATH), 'pull_zone' => __('Pull Zone could not be automatically created.', 'w3-total-cache'));
     $note_messages = array('config_save' => __('Plugin configuration successfully updated.', 'w3-total-cache'), 'flush_all' => __('All caches successfully emptied.', 'w3-total-cache'), 'flush_memcached' => __('Memcached cache(s) successfully emptied.', 'w3-total-cache'), 'flush_opcode' => __('Opcode cache(s) successfully emptied.', 'w3-total-cache'), 'flush_file' => __('Disk cache(s) successfully emptied.', 'w3-total-cache'), 'flush_pgcache' => __('Page cache successfully emptied.', 'w3-total-cache'), 'flush_dbcache' => __('Database cache successfully emptied.', 'w3-total-cache'), 'flush_objectcache' => __('Object cache successfully emptied.', 'w3-total-cache'), 'flush_fragmentcache' => __('Fragment cache successfully emptied.', 'w3-total-cache'), 'flush_minify' => __('Minify cache successfully emptied.', 'w3-total-cache'), 'flush_browser_cache' => __('Media Query string has been successfully updated.', 'w3-total-cache'), 'flush_varnish' => __('Varnish servers successfully purged.', 'w3-total-cache'), 'flush_cdn' => __('CDN was successfully purged.', 'w3-total-cache'), 'support_request' => __('The support request has been successfully sent.', 'w3-total-cache'), 'config_import' => __('Settings successfully imported.', 'w3-total-cache'), 'config_reset' => __('Settings successfully restored.', 'w3-total-cache'), 'preview_enable' => __('Preview mode was successfully enabled', 'w3-total-cache'), 'preview_disable' => __('Preview mode was successfully disabled', 'w3-total-cache'), 'preview_deploy' => __('Preview settings successfully deployed. Preview mode remains enabled until it\'s disabled. Continue testing new settings or disable preview mode if done.', 'w3-total-cache'), 'cdn_purge_attachment' => __('Attachment successfully purged.', 'w3-total-cache'), 'pgcache_purge_post' => __('Post successfully purged.', 'w3-total-cache'), 'new_relic_save' => __('New relic settings have been updated.', 'w3-total-cache'), 'add_in_removed' => __('The add-in has been removed.', 'w3-total-cache'), 'enabled_edge' => __('Edge mode has been enabled.', 'w3-total-cache'), 'disabled_edge' => __('Edge mode has been disabled.', 'w3-total-cache'), 'pull_zone' => __('Pull Zone was automatically created.', 'w3-total-cache'));
     $errors = array();
     $notes = array();
     $environment_error_present = false;
     $error = Util_Request::get_string('w3tc_error');
     if (isset($error_messages[$error])) {
         $errors[$error] = $error_messages[$error];
     }
     $note = Util_Request::get_string('w3tc_note');
     if (isset($note_messages[$note])) {
         $notes[$note] = $note_messages[$note];
     }
     // print errors happened during last request execution,
     // when we decided to redirect with error message instead of
     // printing it directly (to avoid reexecution on refresh)
     if (!is_null($this->w3tc_message)) {
         $v = $this->w3tc_message;
         if (isset($v['errors']) && is_array($v['errors'])) {
             foreach ($v['errors'] as $error) {
                 if (isset($error_messages[$error])) {
                     $errors[] = $error_messages[$error];
                 } else {
                     $errors[] = $error;
                 }
             }
         }
         if (isset($v['notes']) && is_array($v['notes'])) {
             foreach ($v['notes'] as $note) {
                 if (isset($note_messages[$note])) {
                     $notes[] = $note_messages[$note];
                 } else {
                     $notes[] = $note;
                 }
             }
         }
     }
     /*
      * Filesystem environment fix, if needed
      */
     try {
         global $pagenow;
         if ($pagenow == 'plugins.php' || Util_Admin::is_w3tc_admin_page()) {
             $environment = Dispatcher::component('Root_Environment');
             $environment->fix_in_wpadmin($this->_config);
             if (isset($_REQUEST['upgrade'])) {
                 $notes[] = __('Required files and directories have been automatically created', 'w3-total-cache');
             }
         }
     } catch (Util_Environment_Exceptions $exs) {
         $r = Util_Activation::parse_environment_exceptions($exs);
         $n = 1;
         foreach ($r['before_errors'] as $e) {
             $errors['generic_env_' . $n] = $e;
             $n++;
         }
         if (strlen($r['required_changes']) > 0) {
             $changes_style = 'border: 1px solid black; ' . 'background: white; ' . 'margin: 10px 30px 10px 30px; ' . 'padding: 10px; display: none';
             $ftp_style = 'border: 1px solid black; background: white; ' . 'margin: 10px 30px 10px 30px; ' . 'padding: 10px; display: none';
             $ftp_form = str_replace('class="wrap"', '', $exs->credentials_form());
             $ftp_form = str_replace('<form ', '<form name="w3tc_ftp_form" ', $ftp_form);
             $ftp_form = str_replace('<fieldset>', '', $ftp_form);
             $ftp_form = str_replace('</fieldset>', '', $ftp_form);
             $ftp_form = str_replace('id="upgrade" class="button"', 'id="upgrade" class="button w3tc-button-save"', $ftp_form);
             $error = '<strong>W3 Total Cache Error:</strong> ' . 'Files and directories could not be automatically ' . 'created to complete the installation. ' . '<table>' . '<tr>' . '<td>Please execute commands manually</td>' . '<td>' . Util_Ui::button('View required changes', '', 'w3tc-show-required-changes') . '</td>' . '</tr>' . '<tr>' . '<td>or use FTP form to allow ' . '<strong>W3 Total Cache</strong> make it automatically.' . '</td>' . '<td>' . Util_Ui::button('Update via FTP', '', 'w3tc-show-ftp-form') . '</td>' . '</tr></table>' . '<div class="w3tc-required-changes" style="' . $changes_style . '">' . $r['required_changes'] . '</div>' . '<div class="w3tc-ftp-form" style="' . $ftp_style . '">' . $ftp_form . '</div>';
             $environment_error_present = true;
             $errors['generic_ftp'] = $error;
         }
         foreach ($r['later_errors'] as $e) {
             $errors['generic_env_' . $n] = $e;
             $n++;
         }
     }
     $errors = apply_filters('w3tc_errors', $errors);
     $notes = apply_filters('w3tc_notes', $notes);
     /**
      * Show messages
      */
     foreach ($notes as $key => $note) {
         echo sprintf('<div class="updated w3tc_note" id="%s"><p>%s</p></div>', $key, $note);
     }
     foreach ($errors as $key => $error) {
         echo sprintf('<div class="error w3tc_error" id="%s"><p>%s</p></div>', $key, $error);
     }
 }
            </tr>
            <tr>
                <th>Preview mode:</th>
                <td>
                    <?php 
echo Util_Ui::nonce_field('w3tc');
?>
                    <?php 
if ($this->_config->is_preview()) {
    ?>
                        <input type="submit" name="w3tc_config_preview_disable" class="button-primary" value="<?php 
    _e('Disable', 'w3-total-cache');
    ?>
" />
                        <?php 
    echo Util_Ui::button_link(__('Deploy', 'w3-total-cache'), wp_nonce_url(sprintf('admin.php?page=%s&w3tc_config_preview_deploy', $this->_page), 'w3tc'));
    ?>
                        <br /><span class="description"> <?php 
    printf(__('To preview any changed settings (without deploying): %s', 'w3-total-cache'), Util_Ui::preview_link());
    ?>
 </span>
                    <?php 
} else {
    ?>
                        <input type="submit" name="w3tc_config_preview_enable" class="button-primary" value="<?php 
    _e('Enable', 'w3-total-cache');
    ?>
" />
                    <?php 
}
?>
Example #13
0
 /**
  * Returns a preview link with current state
  *
  * @return string
  */
 public static function preview_link()
 {
     return Util_Ui::button_link(__('Preview', 'w3-total-cache'), Util_Ui::url(array('w3tc_default_previewing' => 'y')), true);
 }