/wp-content/plugins/w3-total-cache/lib/W3/Plugin/TotalCacheAdmin.php
PHP | 5766 lines | 3630 code | 933 blank | 1203 comment | 819 complexity | 095cd23987932df7138737a51680e544 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-3.0, Apache-2.0, GPL-2.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?php
-
- /**
- * W3 Total Cache Admin plugin
- */
- if (!defined('W3TC')) {
- die();
- }
-
- define('W3TC_PLUGIN_TOTALCACHE_REGEXP_COOKIEDOMAIN', '~define\s*\(\s*[\'"]COOKIE_DOMAIN[\'"]\s*,.*?\)~is');
-
- require_once W3TC_INC_DIR . '/functions/rule.php';
- require_once W3TC_INC_DIR . '/functions/http.php';
- require_once W3TC_LIB_W3_DIR . '/Plugin.php';
-
- /**
- * Class W3_Plugin_TotalCacheAdmin
- */
- class W3_Plugin_TotalCacheAdmin extends W3_Plugin {
- /**
- * Current page
- *
- * @var string
- */
- var $_page = 'w3tc_general';
-
- /**
- * Notes
- *
- * @var array
- */
- var $_notes = array();
-
- /**
- * Errors
- *
- * @var array
- */
- var $_errors = array();
-
- /**
- * Show support reminder flag
- *
- * @var boolean
- */
- var $_support_reminder = false;
-
- /**
- * Used in PHPMailer init function
- *
- * @var string
- */
- var $_phpmailer_sender = '';
-
- /**
- * Array of request types
- *
- * @var array
- */
- var $_request_types = array(
- 'bug_report' => 'Submit a Bug Report',
- 'new_feature' => 'Suggest a New Feature',
- 'email_support' => 'Less than 15 Minute Email Support Response (M-F 9AM - 5PM EDT): $75 USD',
- 'phone_support' => 'Less than 15 Minute Phone Support Response (M-F 9AM - 5PM EDT): $150 USD',
- 'plugin_config' => 'Professional Plugin Configuration: Starting @ $100 USD',
- 'theme_config' => 'Theme Performance Optimization & Plugin Configuration: Starting @ $150 USD',
- 'linux_config' => 'Linux Server Optimization & Plugin Configuration: Starting @ $200 USD'
- );
-
- /**
- * Array of request groups
- *
- * @var array
- */
- var $_request_groups = array(
- 'General Support' => array(
- 'bug_report',
- 'new_feature'
- ),
- 'Professional Services (per site pricing)' => array(
- 'email_support',
- 'phone_support',
- 'plugin_config',
- 'theme_config',
- 'linux_config'
- )
- );
-
- /**
- * Request price list
- *
- * @var array
- */
- var $_request_prices = array(
- 'email_support' => 75,
- 'phone_support' => 150,
- 'plugin_config' => 100,
- 'theme_config' => 150,
- 'linux_config' => 200
- );
-
- /**
- * Runs plugin
- *
- * @return void
- */
- function run() {
- register_activation_hook(W3TC_FILE, array(
- &$this,
- 'activate'
- ));
-
- register_deactivation_hook(W3TC_FILE, array(
- &$this,
- 'deactivate'
- ));
-
- add_action('admin_init', array(
- &$this,
- 'admin_init'
- ));
-
- add_action('admin_menu', array(
- &$this,
- 'admin_menu'
- ));
-
- add_filter('contextual_help_list', array(
- &$this,
- 'contextual_help_list'
- ));
-
- add_filter('plugin_action_links_' . W3TC_FILE, array(
- &$this,
- 'plugin_action_links'
- ));
-
- add_filter('favorite_actions', array(
- &$this,
- 'favorite_actions'
- ));
-
- add_action('in_plugin_update_message-' . W3TC_FILE, array(
- &$this,
- 'in_plugin_update_message'
- ));
-
- if ($this->_config->get_boolean('widget.latest.enabled') || $this->_config->get_boolean('widget.pagespeed.enabled')) {
- add_action('wp_dashboard_setup', array(
- &$this,
- 'wp_dashboard_setup'
- ));
- }
-
- if ($this->_config->get_boolean('pgcache.enabled') || $this->_config->get_boolean('minify.enabled')) {
- add_filter('pre_update_option_active_plugins', array(
- &$this,
- 'pre_update_option_active_plugins'
- ));
- }
-
- if ($this->_config->get_boolean('cdn.enabled') && w3_can_cdn_purge($this->_config->get_string('cdn.engine'))) {
- add_filter('media_row_actions', array(
- &$this,
- 'media_row_actions'
- ), 0, 2);
- }
-
- if ($this->_config->get_boolean('pgcache.enabled')) {
- add_filter('post_row_actions', array(
- &$this,
- 'post_row_actions'
- ), 0, 2);
-
- add_filter('page_row_actions', array(
- &$this,
- 'page_row_actions'
- ), 0, 2);
- }
- }
-
- /**
- * Activate plugin action
- *
- * @return void
- */
- function activate() {
- $this->link_update();
- }
-
- /**
- * Deactivate plugin action
- *
- * @return void
- */
- function deactivate() {
- $this->link_delete();
- }
-
- /**
- * Load action
- *
- * @return void
- */
- function load() {
- require_once W3TC_LIB_W3_DIR . '/Request.php';
-
- $this->_page = W3_Request::get_string('page');
-
- switch (true) {
- case ($this->_page == 'w3tc_general'):
- case ($this->_page == 'w3tc_pgcache'):
- case ($this->_page == 'w3tc_minify' && W3TC_PHP5):
- case ($this->_page == 'w3tc_dbcache'):
- case ($this->_page == 'w3tc_objectcache'):
- case ($this->_page == 'w3tc_browsercache'):
- case ($this->_page == 'w3tc_mobile'):
- case ($this->_page == 'w3tc_referrer'):
- case ($this->_page == 'w3tc_cdn'):
- case ($this->_page == 'w3tc_install'):
- case ($this->_page == 'w3tc_faq'):
- case ($this->_page == 'w3tc_about'):
- case ($this->_page == 'w3tc_support'):
- break;
-
- default:
- $this->_page = 'w3tc_general';
- }
-
- $this->_support_reminder = ($this->_config->get_boolean('notes.support_us') && $this->_config->get_integer('common.install') < (time() - W3TC_SUPPORT_US_TIMEOUT) && $this->_config->get_string('common.support') == '' && !$this->_config->get_boolean('common.tweeted'));
-
- /**
- * Run plugin action
- */
- $action = false;
-
- foreach ($_REQUEST as $key => $value) {
- if (strpos($key, 'w3tc_') === 0) {
- $action = 'action_' . substr($key, 5);
- break;
- }
- }
-
- if ($action && method_exists($this, $action)) {
- check_admin_referer('w3tc');
- call_user_func(array(
- &$this,
- $action
- ));
- exit();
- }
- }
-
- /**
- * Admin init
- *
- * @return void
- */
- function admin_init() {
- wp_register_style('w3tc-options', plugins_url('pub/css/options.css', W3TC_FILE));
- wp_register_style('w3tc-lightbox', plugins_url('pub/css/lightbox.css', W3TC_FILE));
- wp_register_style('w3tc-widget', plugins_url('pub/css/widget.css', W3TC_FILE));
-
- wp_register_script('w3tc-metadata', plugins_url('pub/js/metadata.js', W3TC_FILE));
- wp_register_script('w3tc-options', plugins_url('pub/js/options.js', W3TC_FILE));
- wp_register_script('w3tc-lightbox', plugins_url('pub/js/lightbox.js', W3TC_FILE));
- wp_register_script('w3tc-widget', plugins_url('pub/js/widget.js', W3TC_FILE));
- }
-
- /**
- * Admin menu
- *
- * @return void
- */
- function admin_menu() {
- $pages = array(
- 'w3tc_general' => array(
- 'General Settings',
- 'General Settings'
- ),
- 'w3tc_pgcache' => array(
- 'Page Cache',
- 'Page Cache'
- ),
- 'w3tc_minify' => array(
- 'Minify',
- 'Minify'
- ),
- 'w3tc_dbcache' => array(
- 'Database Cache',
- 'Database Cache'
- ),
- 'w3tc_objectcache' => array(
- 'Object Cache',
- 'Object Cache'
- ),
- 'w3tc_browsercache' => array(
- 'Browser Cache',
- 'Browser Cache'
- ),
- 'w3tc_mobile' => array(
- 'User Agent Groups',
- 'User Agent Groups'
- ),
- 'w3tc_referrer' => array(
- 'Referrer Groups',
- 'Referrer Groups'
- ),
- 'w3tc_cdn' => array(
- 'Content Delivery Network',
- '<acronym title="Content Delivery Network">CDN</acronym>'
- ),
- 'w3tc_faq' => array(
- 'FAQ',
- 'FAQ'
- ),
- 'w3tc_support' => array(
- 'Support',
- '<span style="color: red;">Support</span>'
- ),
- 'w3tc_install' => array(
- 'Install',
- 'Install'
- ),
- 'w3tc_about' => array(
- 'About',
- 'About'
- )
- );
-
- if (!W3TC_PHP5) {
- unset($pages['w3tc_minify']);
- }
-
- add_menu_page('Performance', 'Performance', 'manage_options', 'w3tc_general', '', plugins_url('w3-total-cache/pub/img/logo_small.png'));
-
- $submenu_pages = array();
-
- foreach ($pages as $slug => $titles) {
- $submenu_pages[] = add_submenu_page('w3tc_general', $titles[0] . ' | W3 Total Cache', $titles[1], 'manage_options', $slug, array(
- &$this,
- 'options'
- ));
- }
-
- if (current_user_can('manage_options')) {
- /**
- * Only admin can modify W3TC settings
- */
- foreach ($submenu_pages as $submenu_page) {
- add_action('load-' . $submenu_page, array(
- &$this,
- 'load'
- ));
-
- add_action('admin_print_styles-' . $submenu_page, array(
- &$this,
- 'admin_print_styles'
- ));
-
- add_action('admin_print_scripts-' . $submenu_page, array(
- &$this,
- 'admin_print_scripts'
- ));
- }
-
- /**
- * Only admin can see W3TC notices and errors
- */
- add_action('admin_notices', array(
- &$this,
- 'admin_notices'
- ));
- }
- }
-
- /**
- * Print styles
- *
- * @return void
- */
- function admin_print_styles() {
- wp_enqueue_style('w3tc-options');
- wp_enqueue_style('w3tc-lightbox');
- }
-
- /**
- * Print scripts
- *
- * @return void
- */
- function admin_print_scripts() {
- wp_enqueue_script('w3tc-metadata');
- wp_enqueue_script('w3tc-options');
- wp_enqueue_script('w3tc-lightbox');
-
- switch ($this->_page) {
- case 'w3tc_minify':
- case 'w3tc_mobile':
- case 'w3tc_referrer':
- case 'w3tc_cdn':
- wp_enqueue_script('jquery-ui-sortable');
- break;
- }
- }
-
- /**
- * Contextual help list filter
- *
- * @param string $list
- * @return string
- */
- function contextual_help_list($list) {
- $faq = $this->parse_faq();
-
- if (isset($faq['Usage'])) {
- $columns = array_chunk($faq['Usage'], ceil(count($faq['Usage']) / 3));
-
- ob_start();
- include W3TC_INC_DIR . '/options/common/help.php';
- $help = ob_get_contents();
- ob_end_clean();
-
- $hook = get_plugin_page_hookname($this->_page, 'w3tc_general');
-
- $list[$hook] = $help;
- }
-
- return $list;
- }
-
- /**
- * Plugin action links filter
- *
- * @param array $links
- * @return array
- */
- function plugin_action_links($links) {
- array_unshift($links, '<a class="edit" href="admin.php?page=w3tc_general">Settings</a>');
-
- return $links;
- }
-
- /**
- * favorite_actions filter
- *
- * @param array $actions
- * @return void
- */
- function favorite_actions($actions) {
- $actions[wp_nonce_url(admin_url('admin.php?page=w3tc_general&w3tc_flush_all'), 'w3tc')] = array(
- 'Empty Caches',
- 'manage_options'
- );
-
- return $actions;
- }
-
- /**
- * Active plugins pre update option filter
- *
- * @param string $new_value
- * @return string
- */
- function pre_update_option_active_plugins($new_value) {
- $old_value = (array) get_option('active_plugins');
-
- if ($new_value !== $old_value && in_array(W3TC_FILE, (array) $new_value) && in_array(W3TC_FILE, (array) $old_value)) {
- $this->_config->set('notes.plugins_updated', true);
- $this->_config->save();
- }
-
- return $new_value;
- }
-
- /**
- * Show plugin changes
- *
- * @return void
- */
- function in_plugin_update_message() {
- $response = w3_http_get(W3TC_README_URL);
-
- if (!is_wp_error($response) && $response['response']['code'] == 200) {
- $matches = null;
- $regexp = '~==\s*Changelog\s*==\s*=\s*[0-9.]+\s*=(.*)(=\s*' . preg_quote(W3TC_VERSION) . '\s*=|$)~Uis';
-
- if (preg_match($regexp, $response['body'], $matches)) {
- $changelog = (array) preg_split('~[\r\n]+~', trim($matches[1]));
-
- echo '<div style="color: #f00;">Take a minute to update, here\'s why:</div><div style="font-weight: normal;">';
- $ul = false;
-
- foreach ($changelog as $index => $line) {
- if (preg_match('~^\s*\*\s*~', $line)) {
- if (!$ul) {
- echo '<ul style="list-style: disc; margin-left: 20px;">';
- $ul = true;
- }
- $line = preg_replace('~^\s*\*\s*~', '', htmlspecialchars($line));
- echo '<li style="width: 50%; margin: 0; float: left; ' . ($index % 2 == 0 ? 'clear: left;' : '') . '">' . $line . '</li>';
- } else {
- if ($ul) {
- echo '</ul><div style="clear: left;"></div>';
- $ul = false;
- }
- echo '<p style="margin: 5px 0;">' . htmlspecialchars($line) . '</p>';
- }
- }
-
- if ($ul) {
- echo '</ul><div style="clear: left;"></div>';
- }
-
- echo '</div>';
- }
- }
- }
-
- /**
- * media_row_actions filter
- *
- * @param array $actions
- * @param object $post
- * @return array
- */
- function media_row_actions($actions, $post) {
- $actions = array_merge($actions, array(
- 'cdn_purge' => sprintf('<a href="%s">Purge from CDN</a>', wp_nonce_url(sprintf('admin.php?page=w3tc_general&w3tc_cdn_purge_attachment&attachment_id=%d', $post->ID), 'w3tc'))
- ));
-
- return $actions;
- }
-
- /**
- * post_row_actions filter
- *
- * @param array $actions
- * @param object $post
- * @return array
- */
- function post_row_actions($actions, $post) {
- $actions = array_merge($actions, array(
- 'pgcache_purge' => sprintf('<a href="%s">Purge from Page Cache</a>', wp_nonce_url(sprintf('admin.php?page=w3tc_general&w3tc_pgcache_purge_post&post_id=%d', $post->ID), 'w3tc'))
- ));
-
- return $actions;
- }
-
- /**
- * page_row_actions filter
- *
- * @param array $actions
- * @param object $post
- * @return array
- */
- function page_row_actions($actions, $post) {
- $actions = array_merge($actions, array(
- 'pgcache_purge' => sprintf('<a href="%s">Purge from Page Cache</a>', wp_nonce_url(sprintf('admin.php?page=w3tc_general&w3tc_pgcache_purge_page&post_id=%d', $post->ID), 'w3tc'))
- ));
-
- return $actions;
- }
-
- /**
- * Dashboard setup action
- *
- * @return void
- */
- function wp_dashboard_setup() {
- wp_enqueue_style('w3tc-widget');
- wp_enqueue_script('w3tc-metadata');
- wp_enqueue_script('w3tc-widget');
-
- if ($this->_config->get_boolean('widget.latest.enabled')) {
- wp_add_dashboard_widget('w3tc_latest', 'The Latest from W3 EDGE', array(
- &$this,
- 'widget_latest'
- ), array(
- &$this,
- 'widget_latest_control'
- ));
- }
-
- if ($this->_config->get_boolean('widget.pagespeed.enabled')) {
- wp_add_dashboard_widget('w3tc_pagespeed', 'W3 Total Cache: Google Page Speed Report', array(
- &$this,
- 'widget_pagespeed'
- ), array(
- &$this,
- 'widget_pagespeed_control'
- ));
- }
- }
-
- /**
- * Admin notices action
- *
- * @return void
- */
- function admin_notices() {
- $config_path = (w3_is_preview_config() ? W3TC_CONFIG_PREVIEW_PATH : W3TC_CONFIG_PATH);
-
- $pgcache_rules_core_path = w3_get_pgcache_rules_core_path();
- $pgcache_rules_cache_path = w3_get_pgcache_rules_cache_path();
- $browsercache_rules_cache_path = w3_get_browsercache_rules_cache_path();
- $browsercache_rules_no404wp_path = w3_get_browsercache_rules_no404wp_path();
- $minify_rules_core_path = w3_get_minify_rules_core_path();
- $minify_rules_cache_path = w3_get_minify_rules_cache_path();
- $cookie_domain = $this->get_cookie_domain();
-
- $error_messages = array(
- 'config_save' => sprintf('The settings could not be saved because the configuration file is not write-able. Please run <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($config_path) ? $config_path : dirname($config_path))),
- 'fancy_permalinks_disabled_pgcache' => sprintf('Fancy permalinks are disabled. Please %s it first, then re-attempt to enabling enhanced disk mode.', $this->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\'.', $this->button_link('enable', 'options-permalink.php')),
- 'pgcache_write_rules_core' => sprintf('The page cache rules could not be modified. Please %srun <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($pgcache_rules_core_path) ? '' : sprintf('create an empty file in <strong>%s</strong> and ', $pgcache_rules_core_path)), $pgcache_rules_core_path),
- 'pgcache_write_rules_cache' => sprintf('The page cache rules could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($pgcache_rules_cache_path) ? $pgcache_rules_cache_path : dirname($pgcache_rules_cache_path))),
- 'pgcache_remove_rules_legacy' => sprintf('The legacy page cache rules could not be removed. Please run <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($pgcache_rules_cache_path) ? $pgcache_rules_cache_path : dirname($pgcache_rules_cache_path))),
- 'pgcache_remove_rules_wpsc' => sprintf('The WP Super Cache rules could not be removed. Please run <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($pgcache_rules_cache_path) ? $pgcache_rules_cache_path : dirname($pgcache_rules_cache_path))),
- 'browsercache_write_rules_cache' => sprintf('The browser cache rules could not be modified. Please %srun <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($browsercache_rules_cache_path) ? '' : sprintf('create an empty file in <strong>%s</strong> and ', $browsercache_rules_cache_path)), $browsercache_rules_cache_path),
- 'browsercache_write_rules_no404wp' => sprintf('The browser cache rules could not be modified. Please %srun <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($browsercache_rules_no404wp_path) ? '' : sprintf('create an empty file in <strong>%s</strong> and ', $browsercache_rules_no404wp_path)), $browsercache_rules_no404wp_path),
- 'browsercache_write_rules_cdn' => sprintf('The browser cache rules for <acronym title="Content Delivery Network">CDN</acronym> could not be modified. Please check <acronym title="Content Delivery Network">CDN</acronym> settings.'),
- 'minify_write_rules_core' => sprintf('The minify rules could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($minify_rules_core_path) ? $minify_rules_core_path : dirname($minify_rules_core_path))),
- 'minify_write_rules_cache' => sprintf('The minify rules could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($minify_rules_cache_path) ? $minify_rules_cache_path : dirname($minify_rules_cache_path))),
- 'minify_remove_rules_legacy' => sprintf('The legacy minify rules could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($minify_rules_cache_path) ? $minify_rules_cache_path : dirname($minify_rules_cache_path))),
- 'support_request_type' => 'Please select request type.',
- 'support_request_url' => 'Please enter the address of the site in the site <acronym title="Uniform Resource Locator">URL</acronym> field.',
- 'support_request_name' => 'Please enter your name in the Name field',
- 'support_request_email' => 'Please enter valid email address in the E-Mail field.',
- 'support_request_phone' => 'Please enter your phone in the phone field.',
- 'support_request_subject' => 'Please enter subject in the subject field.',
- 'support_request_description' => 'Please describe the issue in the issue description field.',
- 'support_request_wp_login' => 'Please enter an administrator login. Create a temporary one just for this support case if needed.',
- 'support_request_wp_password' => 'Please enter WP Admin password, be sure it\'s spelled correctly.',
- 'support_request_ftp_host' => 'Please enter <acronym title="Secure Shell">SSH</acronym> or <acronym title="File Transfer Protocol">FTP</acronym> host for the site.',
- '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.',
- '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.',
- 'support_request' => 'Unable to send the support request.',
- 'config_import_no_file' => 'Please select config file.',
- 'config_import_upload' => 'Unable to upload config file.',
- 'config_import_import' => 'Configuration file could not be imported.',
- '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.', (file_exists(W3TC_CONFIG_PREVIEW_PATH) ? W3TC_CONFIG_PREVIEW_PATH : W3TC_CONFIG_PREVIEW_PATH)),
- 'preview_enable' => sprintf('Preview mode could not be enabled. Please run <strong>chmod 777 %s</strong> to make the configuration file write-able, then try again.', (file_exists(W3TC_CONFIG_PREVIEW_PATH) ? W3TC_CONFIG_PREVIEW_PATH : dirname(W3TC_CONFIG_PREVIEW_PATH))),
- 'preview_disable' => sprintf('Preview mode could not be disabled. Please run <strong>chmod 777 %s</strong> to make the configuration file write-able, then try again.', (file_exists($config_path) ? $config_path : dirname($config_path))),
- 'preview_deploy' => sprintf('Preview settings could not be deployed. Please run <strong>chmod 777 %s</strong> to make the configuration file write-able, then try again.', (file_exists(W3TC_CONFIG_PATH) ? W3TC_CONFIG_PATH : dirname(W3TC_CONFIG_PATH))),
- 'cdn_purge_attachment' => 'Unable to purge attachment.',
- 'pgcache_purge_post' => 'Unable to purge post.',
- 'pgcache_purge_page' => 'Unable to purge page.',
- '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>.', 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>.', ABSPATH),
- 'cloudflare_api_request' => 'Unable to make CloudFlare API request.'
- );
-
- $note_messages = array(
- 'config_save' => 'Plugin configuration successfully updated.',
- 'flush_all' => 'All caches successfully emptied.',
- 'flush_memcached' => 'Memcached cache(s) successfully emptied.',
- 'flush_opcode' => 'Opcode cache(s) successfully emptied.',
- 'flush_file' => 'Disk cache(s) successfully emptied.',
- 'flush_pgcache' => 'Page cache successfully emptied.',
- 'flush_dbcache' => 'Database cache successfully emptied.',
- 'flush_objectcache' => 'Object cache successfully emptied.',
- 'flush_minify' => 'Minify cache successfully emptied.',
- 'pgcache_write_rules_core' => 'Page cache rewrite rules have been successfully written.',
- 'pgcache_write_rules_cache' => 'Page cache rewrite rules have been successfully written.',
- 'pgcache_remove_rules_legacy' => 'Legacy page cache configuration settings have been successfully removed.',
- 'pgcache_remove_rules_wpsc' => 'WP Super Cache configuration settings have been successfully removed.',
- 'browsercache_write_rules_cache' => 'Browser cache directives have been successfully written.',
- 'browsercache_write_rules_no404wp' => 'Browser cache directives have been successfully written.',
- 'minify_write_rules_core' => 'Minify rewrite rules have been successfully written.',
- 'minify_write_rules_cache' => 'Minify rewrite rules have been successfully written.',
- 'minify_remove_rules_legacy' => 'Legacy minify configuration settings have been successfuly removed.',
- 'support_request' => 'The support request has been successfully sent.',
- 'config_import' => 'Settings successfully imported.',
- 'config_reset' => 'Settings successfully restored.',
- 'preview_enable' => 'Preview mode was successfully enabled',
- 'preview_disable' => 'Preview mode was successfully disabled',
- 'preview_deploy' => 'Preview settings successfully deployed.',
- 'cdn_purge_attachment' => 'Attachment successfully purged.',
- 'pgcache_purge_post' => 'Post successfully purged.',
- 'pgcache_purge_page' => 'Page successfully purged.'
- );
-
- $errors = array();
- $notes = array();
-
- require_once W3TC_LIB_W3_DIR . '/Request.php';
-
- $error = W3_Request::get_string('w3tc_error');
- $note = W3_Request::get_string('w3tc_note');
-
- /**
- * Handle messages from reqeust
- */
- if (isset($error_messages[$error])) {
- $errors[] = $error_messages[$error];
- }
-
- if (isset($note_messages[$note])) {
- $notes[] = $note_messages[$note];
- }
-
- /**
- * Check config file
- */
- if (!w3_is_preview_config() && !file_exists(W3TC_CONFIG_PATH)) {
- $errors[] = sprintf('<strong>W3 Total Cache Error:</strong> Default settings are in use. The configuration file could not be read or doesn\'t exist. Please %s to create the file.', $this->button_link('save the settings', wp_nonce_url(sprintf('admin.php?page=%s&w3tc_save_config', $this->_page), 'w3tc')));
- }
-
- /**
- * CDN notifications
- */
- if ($this->_config->get_boolean('cdn.enabled') && !w3_is_cdn_mirror($this->_config->get_string('cdn.engine'))) {
- /**
- * Show notification after theme change
- */
- if ($this->_config->get_boolean('notes.theme_changed')) {
- $notes[] = sprintf('The active theme has changed, please %s now to ensure proper operation. %s', $this->button_popup('upload active theme files', 'cdn_export', 'cdn_export_type=theme'), $this->button_hide_note('Hide this message', 'theme_changed'));
- }
-
- /**
- * Show notification after WP upgrade
- */
- if ($this->_config->get_boolean('notes.wp_upgraded')) {
- $notes[] = sprintf('Upgraded WordPress? Please %s files now to ensure proper operation. %s', $this->button_popup('upload wp-includes', 'cdn_export', 'cdn_export_type=includes'), $this->button_hide_note('Hide this message', 'wp_upgraded'));
- }
-
- /**
- * Show notification after CDN enable
- */
- if ($this->_config->get_boolean('notes.cdn_upload') || $this->_config->get_boolean('notes.cdn_reupload')) {
- $cdn_upload_buttons = array();
-
- if ($this->_config->get_boolean('cdn.includes.enable')) {
- $cdn_upload_buttons[] = $this->button_popup('wp-includes', 'cdn_export', 'cdn_export_type=includes');
- }
-
- if ($this->_config->get_boolean('cdn.theme.enable')) {
- $cdn_upload_buttons[] = $this->button_popup('theme files', 'cdn_export', 'cdn_export_type=theme');
- }
-
- if ($this->_config->get_boolean('minify.enabled') && $this->_config->get_boolean('cdn.minify.enable')) {
- $cdn_upload_buttons[] = $this->button_popup('minify files', 'cdn_export', 'cdn_export_type=minify');
- }
-
- if ($this->_config->get_boolean('cdn.custom.enable')) {
- $cdn_upload_buttons[] = $this->button_popup('custom files', 'cdn_export', 'cdn_export_type=custom');
- }
-
- if ($this->_config->get_boolean('notes.cdn_upload')) {
- $notes[] = sprintf('Make sure to %s and upload the %s, files to the <acronym title="Content Delivery Network">CDN</acronym> to ensure proper operation. %s', $this->button_popup('export the media library', 'cdn_export_library'), implode(', ', $cdn_upload_buttons), $this->button_hide_note('Hide this message', 'cdn_upload'));
- }
-
- if ($this->_config->get_boolean('notes.cdn_reupload')) {
- $notes[] = sprintf('Settings that effect Browser Cache settings for files hosted by the CDN have been changed. To apply the new settings %s and %s. %s', $this->button_popup('export the media library', 'cdn_export_library'), implode(', ', $cdn_upload_buttons), $this->button_hide_note('Hide this message', 'cdn_reupload'));
- }
- }
-
- /**
- * Show notification if upload queue is not empty
- */
- if (!$this->is_queue_empty()) {
- $errors[] = sprintf('The %s has unresolved errors. Empty the queue to restore normal operation.', $this->button_popup('unsuccessful transfer queue', 'cdn_queue'));
- }
- }
-
- /**
- * Show notification after plugin activate/deactivate
- */
- if ($this->_config->get_boolean('notes.plugins_updated')) {
- $texts = array();
-
- if ($this->_config->get_boolean('pgcache.enabled')) {
- $texts[] = $this->button_link('empty the page cache', wp_nonce_url(sprintf('admin.php?page=%s&w3tc_flush_pgcache', $this->_page), 'w3tc'));
- }
-
- if ($this->_config->get_boolean('minify.enabled')) {
- $texts[] = sprintf('check the %s to maintain the desired user experience', $this->button_hide_note('minify settings', 'plugins_updated', 'admin.php?page=w3tc_minify'));
- }
-
- if (count($texts)) {
- $notes[] = sprintf('One or more plugins have been activated or deactivated, please %s. %s', implode(' and ', $texts), $this->button_hide_note('Hide this message', 'plugins_updated'));
- }
- }
-
- /**
- * Show notification when page cache needs to be emptied
- */
- if ($this->_config->get_boolean('pgcache.enabled') && $this->_config->get('notes.need_empty_pgcache') && !w3_is_preview_config()) {
- $notes[] = 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.', $this->button_link('Empty the page cache', wp_nonce_url(sprintf('admin.php?page=%s&w3tc_flush_pgcache', $this->_page), 'w3tc')));
- }
-
- /**
- * Show notification when object cache needs to be emptied
- */
- if ($this->_config->get_boolean('objectcache.enabled') && $this->_config->get('notes.need_empty_objectcache') && !w3_is_preview_config()) {
- $notes[] = 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.', $this->button_link('Empty the object cache', wp_nonce_url(sprintf('admin.php?page=%s&w3tc_flush_objectcache', $this->_page), 'w3tc')));
- }
-
- /**
- * Minify notifications
- */
- if ($this->_config->get_boolean('minify.enabled')) {
- /**
- * Minify error occured
- */
- if ($this->_config->get('notes.minify_error')) {
- $errors[] = sprintf('Recently an error occurred while creating the CSS / JS minify cache: %s. %s', $this->_config->get_string('minify.error.last'), $this->button_hide_note('Hide this message', 'minify_error'));
- }
-
- /**
- * Show notification when minify needs to be emptied
- */
- if ($this->_config->get('notes.need_empty_minify') && !w3_is_preview_config()) {
- $notes[] = 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.', $this->button_link('Empty the minify cache', wp_nonce_url(sprintf('admin.php?page=%s&w3tc_flush_minify', $this->_page), 'w3tc')));
- }
- }
-
- /**
- * Show messages
- */
- foreach ($errors as $error) {
- echo sprintf('<div class="error"><p>%s</p></div>', $error);
- }
-
- foreach ($notes as $note) {
- echo sprintf('<div class="updated fade"><p>%s</p></div>', $note);
- }
- }
-
- /**
- * Options page
- *
- * @return void
- */
- function options() {
- /**
- * Check for page cache availability
- */
- if ($this->_config->get_boolean('pgcache.enabled')) {
- if (!$this->advanced_cache_installed()) {
- $this->_errors[] = sprintf('Page caching is not available: %s is not installed. Either the <strong>%s</strong> directory is not write-able or another caching plugin installed. This error message will automatically disappear once the change is successfully made.', W3TC_ADDIN_FILE_ADVANCED_CACHE, WP_CONTENT_DIR);
- } elseif (!$this->advanced_cache_check()) {
- $this->_errors[] = sprintf('Page caching is not available. The current add-in %s is either an incorrect file or an old version. De-activate the plugin, remove the file, then activate the plugin again.', W3TC_ADDIN_FILE_ADVANCED_CACHE);
- } elseif (!defined('WP_CACHE') || !WP_CACHE) {
- $this->_errors[] = sprintf('Page caching is not available: please add: <strong>define(\'WP_CACHE\', true);</strong> to <strong>%swp-config.php</strong>. This error message will automatically disappear once the change is successfully made.', ABSPATH);
- } elseif ($this->_config->get_string('pgcache.engine') == 'file_generic' && $this->_config->get_boolean('config.check') && w3_can_check_rules()) {
- $w3_plugin_pgcache = & w3_instance('W3_Plugin_PgCacheAdmin');
-
- if ($w3_plugin_pgcache->check_rules_core()) {
- if (!$this->test_rewrite_pgcache()) {
- $this->_errors[] = 'It appears Page Cache <acronym title="Uniform Resource Locator">URL</acronym> rewriting is not working. If using apache, verify that the server configuration allows .htaccess or if using nginx verify all configuration files are included in the configuration.';
- }
- } elseif ($this->_config->get_boolean('notes.pgcache_rules_core')) {
- $this->_errors[] = sprintf('Disk enhanced page caching is not active. To enable it, add the following rules into the server configuration file (<strong>%s</strong>) of the site above the WordPress directives %s <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>. Or if permission allow this can be done automatically, by clicking here: %s. %s', w3_get_pgcache_rules_core_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_pgcache->generate_rules_core()), $this->button_link('auto-install', wp_nonce_url(sprintf('admin.php?page=%s&w3tc_pgcache_write_rules_core', $this->_page), 'w3tc')), $this->button_hide_note('Hide this message', 'pgcache_rules_core'));
- }
-
- if ($this->_config->get_boolean('notes.pgcache_rules_legacy') && $w3_plugin_pgcache->check_rules_legacy()) {
- $this->_errors[] = sprintf('Legacy Page Cache rewrite rules have been found. To remove them manually, edit the configuration file (<strong>%s</strong>) and remove all lines between and including <strong>%s</strong> and <strong>%s</strong> markers inclusive. Or if permission allow this can be done automatically, by clicking here: %s. %s', w3_get_pgcache_rules_core_path(), W3TC_MARKER_BEGIN_PGCACHE_LEGACY, W3TC_MARKER_END_PGCACHE_LEGACY, $this->button_link('auto-remove', wp_nonce_url(sprintf('admin.php?page=%s&w3tc_pgcache_remove_rules_legacy', $this->_page), 'w3tc')), $this->button_hide_note('Hide this message', 'pgcache_rules_legacy'));
- }
-
- if ($this->_config->get_boolean('notes.pgcache_rules_wpsc') && $w3_plugin_pgcache->check_rules_wpsc()) {
- $this->_errors[] = sprintf('WP Super Cache rewrite rules have been found. To remove them manually, edit the configuration file (<strong>%s</strong>) and remove all lines between and including <strong>%s</strong> and <strong>%s</strong> markers inclusive. Or if permission allow this can be done automatically, by clicking here: %s. %s', w3_get_pgcache_rules_core_path(), W3TC_MARKER_BEGIN_PGCACHE_WPSC, W3TC_MARKER_END_PGCACHE_WPSC, $this->button_link('auto-remove', wp_nonce_url(sprintf('admin.php?page=%s&w3tc_pgcache_remove_rules_wpsc', $this->_page), 'w3tc')), $this->button_hide_note('Hide this message', 'pgcache_rules_wpsc'));
- }
-
- if ($this->_config->get_boolean('notes.pgcache_rules_cache') && !$w3_plugin_pgcache->check_rules_cache()) {
- $this->_errors[] = sprintf('Disk enhanced page caching is not active. To enable it, add the following rules into the server configuration file (<strong>%s</strong>) of the site %s <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>. This can be done automatically, by clicking here: %s. %s', w3_get_pgcache_rules_cache_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_pgcache->generate_rules_cache()), $this->button_link('auto-install', wp_nonce_url(sprintf('admin.php?page=%s&w3tc_pgcache_write_rules_cache', $this->_page), 'w3tc')), $this->button_hide_note('Hide this message', 'pgcache_rules_cache'));
- }
- }
- }
-
- /**
- * Check for browser cache availability
- */
- if ($this->_config->get_boolean('browsercache.enabled') && $this->_config->get_boolean('config.check') && w3_can_check_rules()) {
- $w3_plugin_browsercache = & w3_instance('W3_Plugin_BrowserCacheAdmin');
-
- if ($this->_config->get_boolean('notes.browsercache_rules_cache') && !$w3_plugin_browsercache->check_rules_cache()) {
- $this->_errors[] = sprintf('Browser caching is not active. To enable it, add the following rules into the server configuration file (<strong>%s</strong>) of the site %s <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>. Or if permission allow this can be done automatically, by clicking here: %s. %s', w3_get_browsercache_rules_cache_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_browsercache->generate_rules_cache()), $this->button_link('auto-install', wp_nonce_url(sprintf('admin.php?page=%s&w3tc_browsercache_write_rules_cache', $this->_page), 'w3tc')), $this->button_hide_note('Hide this message', 'browsercache_rules_cache'));
- }
-
- if ($this->_config->get_boolean('notes.browsercache_rules_no404wp') && $this->_config->get_boolean('browsercache.no404wp') && !$w3_plugin_browsercache->check_rules_no404wp()) {
- $this->_errors[] = sprintf('"Do not process 404 errors for static objects with WordPress" feature is not active. To enable it, add the following rules into the server configuration file (<strong>%s</strong>) of the site %s <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>. Or if permission allow this can be done automatically, by clicking here: %s. %s', w3_get_browsercache_rules_no404wp_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_browsercache->generate_rules_no404wp()), $this->button_link('auto-install', wp_nonce_url(sprintf('admin.php?page=%s&w3tc_browsercache_write_rules_no404wp', $this->_page), 'w3tc')), $this->button_hide_note('Hide this message', 'browsercache_rules_no404wp'));
- }
- }
-
- /**
- * Check for minify availability
- */
- if ($this->_config->get_boolean('minify.enabled')) {
- if ($this->_config->get_boolean('minify.rewrite') && $this->_config->get_boolean('config.check') && w3_can_check_rules()) {
- $w3_plugin_minify = & w3_instance('W3_Plugin_MinifyAdmin');
-
- if ($w3_plugin_minify->check_rules_core()) {
- if (!$this->test_rewrite_minify()) {
- $this->_errors[] = 'It appears Minify <acronym title="Uniform Resource Locator">URL</acronym> rewriting is not working. If using apache, verify that the server configuration allows .htaccess or if using nginx verify all configuration files are included in the configuration.';
- }
- } elseif ($this->_config->get_boolean('notes.minify_rules_core')) {
- $this->_errors[] = sprintf('Minify is not active. To enable it, add the following rules into the server configuration file (<strong>%s</strong>) of the site %s <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>. This can be done automatically, by clicking here: %s. %s', w3_get_minify_rules_core_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_minify->generate_rules_core()), $this->button_link('auto-install', wp_nonce_url(sprintf('admin.php?page=%s&w3tc_minify_write_rules_core', $this->_page), 'w3tc')), $this->button_hide_note('Hide this message', 'minify_rules_core'));
- }
-
- if ($this->_config->get_boolean('notes.minify_rules_legacy') && $w3_plugin_minify->check_rules_legacy()) {
- $this->_errors[] = sprintf('Legacy Minify rewrite rules have been found. To remove them manually, edit the configuration file (<strong>%s</strong>) and remove all lines between and including <strong>%s</strong> and <strong>%s</strong> markers inclusive. Or if permission allow this can be done automatically, by clicking here: %s. %s', w3_get_minify_rules_core_path(), W3TC_MARKER_BEGIN_MINIFY_LEGACY, W3TC_MARKER_END_MINIFY_LEGACY, $this->button_link('auto-remove', wp_nonce_url(sprintf('admin.php?page=%s&w3tc_minify_remove_rules_legacy', $this->_page), 'w3tc')), $this->button_hide_note('Hide this message', 'minify_rules_legacy'));
- }
-
- if ($this->_config->get_string('minify.engine') == 'file' && $this->_config->get_boolean('notes.minify_rules_cache') && !$w3_plugin_minify->check_rules_cache()) {
- $this->_errors[] = sprintf('Minify is not active. To enable it, add the following rules into the server configuration file (<strong>%s</strong>) of the site %s <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>. This can be done automatically, by clicking here: %s. %s', w3_get_minify_rules_cache_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_minify->generate_rules_cache()), $this->button_link('auto-install', wp_nonce_url(sprintf('admin.php?page=%s&w3tc_minify_write_rules_cache', $this->_page), 'w3tc')), $this->button_hide_note('Hide this message', 'minify_rules_cache'));
- }
- }
-
- /**
- * Minifiers availability error handling
- */
- $minifiers_errors = array();
-
- if ($this->_config->get_string('minify.js.engine') == 'yuijs') {
- $path_java = $this->_config->get_string('minify.yuijs.path.java');
- $path_jar = $this->_config->get_string('minify.yuijs.path.jar');
-
- if (!file_exists($path_java)) {
- $minifiers_errors[] = sprintf('YUI Compressor (JS): JAVA executable path was not found. The default minifier JSMin will be used instead.');
- } elseif (!file_exists($path_jar)) {
- $minifiers_errors[] = sprintf('YUI Compressor (JS): JAR file path was not found. The default minifier JSMin will be used instead.');
- }
- }
-
- if ($this->_config->get_string('minify.css.engine') == 'yuicss') {
- $path_java = $this->_config->get_string('minify.yuicss.path.java');
- $path_jar = $this->_config->get_string('minify.yuicss.path.jar');
-
- if (!file_exists($path_java)) {
- $minifiers_errors[] = sprintf('YUI Compressor (CSS): JAVA executable path was not found. The default CSS minifier will be used instead.');
- } elseif (!file_exists($path_jar)) {
- $minifiers_errors[] = sprintf('YUI Compressor (CSS): JAR file path was not found. The default CSS minifier will be used instead.');
- }
- }
-
- if ($this->_config->get_string('minify.js.engine') == 'ccjs') {
- $path_java = $this->_config->get_string('minify.ccjs.path.java');
- $path_jar = $this->_config->get_string('minify.ccjs.path.jar');
-
- if (!file_exists($path_java)) {
- $minifiers_errors[] = sprintf('Closure Compiler: JAVA executable path was not found. The default minifier JSMin will be used instead.');
- } elseif (!file_exists($path_jar)) {
- $minifiers_errors[] = sprintf('Closure Compiler: JAR file path was not found. The default minifier JSMin will be used instead.');
- }
- }
-
- if (count($minifiers_errors)) {
- $minify_error = 'The following minifiers cannot be found or are no longer working:</p><ul>';
-
- foreach ($minifiers_errors as $minifiers_error) {
- $minify_error .= '<li>' . $minifiers_error . '</li>';
- }
-
- $minify_error .= '</ul><p>This message will automatically disappear once the issue is resolved.';
-
- $this->_errors[] = $minify_error;
- }
- }
-
- /**
- * Check for database cache availability
- */
- if ($this->_config->get_boolean('dbcache.enabled')) {
- if (!$this->db_installed()) {
- $this->_errors[] = sprintf('Database caching is not available: %s is not installed. Either the <strong>%s</strong> directory is not write-able or another caching plugin is installed. This error message will automatically disappear once the change is successfully made.', W3TC_ADDIN_FILE_DB, WP_CONTENT_DIR);
- } elseif (!$this->db_check()) {
- $this->_errors[] = sprintf('Database caching is not avail…
Large files files are truncated, but you can click here to view the full file