/wp-content/plugins/w3-total-cache/lib/W3/Plugin/TotalCache.php
https://bitbucket.org/openfarmtech/weblog-content · PHP · 5050 lines · 3283 code · 821 blank · 946 comment · 733 complexity · d8b0c6e9afec0c08f466a53d99353015 MD5 · raw file
Large files are truncated click here to view the full file
- <?php
-
- /**
- * W3 Total Cache plugin
- */
- require_once W3TC_LIB_W3_DIR . '/Plugin.php';
-
- /**
- * Class W3_Plugin_TotalCache
- */
- class W3_Plugin_TotalCache 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' => '<15 Minute Email Support Response (M-F 9AM - 5PM EDT): $75 USD',
- 'phone_support' => '<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
- */
- 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('init', array(
- &$this,
- 'init'
- ));
-
- add_action('in_plugin_update_message-' . W3TC_FILE, array(
- &$this,
- 'in_plugin_update_message'
- ));
-
- if ($this->_config->get_boolean('widget.latest.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') && $this->_config->get_string('cdn.engine') != 'mirror') {
- add_filter('media_row_actions', array(
- &$this,
- 'media_row_actions'
- ), null, 2);
- }
-
- if ($this->_config->get_boolean('pgcache.enabled')) {
- add_filter('post_row_actions', array(
- &$this,
- 'post_row_actions'
- ), null, 2);
- }
-
- if (isset($_REQUEST['w3tc_theme']) && isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT'] == W3TC_POWERED_BY) {
- add_filter('template', array(
- &$this,
- 'template_preview'
- ));
-
- add_filter('stylesheet', array(
- &$this,
- 'stylesheet_preview'
- ));
- } elseif ($this->_config->get_boolean('mobile.enabled')) {
- add_filter('template', array(
- &$this,
- 'template'
- ));
-
- add_filter('stylesheet', array(
- &$this,
- 'stylesheet'
- ));
- }
-
- if ($this->_config->get_string('common.support') == 'footer') {
- add_action('wp_footer', array(
- &$this,
- 'footer'
- ));
- }
-
- ob_start(array(
- &$this,
- 'ob_callback'
- ));
-
- /**
- * Run DbCache plugin
- */
- require_once W3TC_DIR . '/lib/W3/Plugin/DbCache.php';
- $w3_plugin_dbcache = & W3_Plugin_DbCache::instance();
- $w3_plugin_dbcache->run();
-
- /**
- * Run ObjectCache plugin
- */
- require_once W3TC_DIR . '/lib/W3/Plugin/ObjectCache.php';
- $w3_plugin_objectcache = & W3_Plugin_ObjectCache::instance();
- $w3_plugin_objectcache->run();
-
- /**
- * Run PgCache plugin
- */
- require_once W3TC_DIR . '/lib/W3/Plugin/PgCache.php';
- $w3_plugin_pgcache = & W3_Plugin_PgCache::instance();
- $w3_plugin_pgcache->run();
-
- /**
- * Run CDN plugin
- */
- require_once W3TC_DIR . '/lib/W3/Plugin/Cdn.php';
- $w3_plugin_cdn = & W3_Plugin_Cdn::instance();
- $w3_plugin_cdn->run();
-
- /**
- * Run Minify plugin
- */
- if (W3TC_PHP5) {
- require_once W3TC_DIR . '/lib/W3/Plugin/Minify.php';
- $w3_plugin_minify = & W3_Plugin_Minify::instance();
- $w3_plugin_minify->run();
- }
-
- /**
- * Run BrowserCache plugin
- */
- require_once W3TC_DIR . '/lib/W3/Plugin/BrowserCache.php';
- $w3_plugin_browsercache = & W3_Plugin_BrowserCache::instance();
- $w3_plugin_browsercache->run();
- }
-
- /**
- * Returns plugin instance
- *
- * @return W3_Plugin_TotalCache
- */
- function &instance()
- {
- static $instances = array();
-
- if (!isset($instances[0])) {
- $class = __CLASS__;
- $instances[0] = & new $class();
- }
-
- return $instances[0];
- }
-
- /**
- * Activate plugin action
- */
- function activate()
- {
- $files = array(
- W3TC_INSTALL_DIR . '/db.php',
- W3TC_INSTALL_DIR . '/advanced-cache.php',
- W3TC_INSTALL_DIR . '/object-cache.php'
- );
-
- $nonexistent_files = array();
-
- foreach ($files as $file) {
- if (!file_exists($file)) {
- $nonexistent_files[] = $file;
- }
- }
-
- if (count($nonexistent_files)) {
- $error = sprintf('Unfortunately core file(s): (<strong>%s</strong>) are missing, so activation will fail. Please re-start the installation process from the beginning.', implode(', ', $nonexistent_files));
-
- w3_activate_error($error);
- }
-
- if (!@is_dir(W3TC_CONTENT_DIR)) {
- if (@mkdir(W3TC_CONTENT_DIR, 0755)) {
- @chmod(W3TC_CONTENT_DIR, 0755);
- } else {
- w3_writable_error(W3TC_CONTENT_DIR);
- }
- }
-
- if (!@is_dir(W3TC_CACHE_FILE_DBCACHE_DIR)) {
- if (@mkdir(W3TC_CACHE_FILE_DBCACHE_DIR, 0755)) {
- @chmod(W3TC_CACHE_FILE_DBCACHE_DIR, 0755);
- } else {
- w3_writable_error(W3TC_CACHE_FILE_DBCACHE_DIR);
- }
- }
-
- if (!@is_dir(W3TC_CACHE_FILE_OBJECTCACHE_DIR)) {
- if (@mkdir(W3TC_CACHE_FILE_OBJECTCACHE_DIR, 0755)) {
- @chmod(W3TC_CACHE_FILE_OBJECTCACHE_DIR, 0755);
- } else {
- w3_writable_error(W3TC_CACHE_FILE_OBJECTCACHE_DIR);
- }
- }
-
- if (!@is_dir(W3TC_CACHE_FILE_PGCACHE_DIR)) {
- if (@mkdir(W3TC_CACHE_FILE_PGCACHE_DIR, 0755)) {
- @chmod(W3TC_CACHE_FILE_PGCACHE_DIR, 0755);
- } else {
- w3_writable_error(W3TC_CACHE_FILE_PGCACHE_DIR);
- }
- }
-
- if (!@is_dir(W3TC_CACHE_FILE_MINIFY_DIR)) {
- if (@mkdir(W3TC_CACHE_FILE_MINIFY_DIR, 0755)) {
- @chmod(W3TC_CACHE_FILE_MINIFY_DIR, 0755);
- } else {
- w3_writable_error(W3TC_CACHE_FILE_MINIFY_DIR);
- }
- }
-
- if (!@is_dir(W3TC_LOG_DIR)) {
- if (@mkdir(W3TC_LOG_DIR, 0755)) {
- @chmod(W3TC_LOG_DIR, 0755);
- } else {
- w3_writable_error(W3TC_LOG_DIR);
- }
- }
-
- if (!@is_dir(W3TC_TMP_DIR)) {
- if (@mkdir(W3TC_TMP_DIR, 0755)) {
- @chmod(W3TC_TMP_DIR, 0755);
- } else {
- w3_writable_error(W3TC_TMP_DIR);
- }
- }
-
- if (w3_is_multisite() && file_exists(W3TC_CONFIG_MASTER_PATH)) {
- /**
- * For multisite load master config
- */
- $this->_config->load_master();
-
- if (!$this->_config->save(false)) {
- w3_writable_error(W3TC_CONFIG_PATH);
- }
- } elseif (!file_exists(W3TC_CONFIG_PATH)) {
- /**
- * Set default settings
- */
- $this->_config->set_defaults();
-
- /**
- * If config doesn't exist enable preview mode
- */
- if (!$this->_config->save(true)) {
- w3_writable_error(W3TC_CONFIG_PREVIEW_PATH);
- }
- }
-
- /**
- * Save blognames into file
- */
- if (w3_is_multisite() && !w3_is_vhost()) {
- if (!w3_save_blognames()) {
- w3_writable_error(W3TC_BLOGNAMES_PATH);
- }
- }
-
- delete_option('w3tc_request_data');
- add_option('w3tc_request_data', '', null, 'no');
-
- $this->link_update();
- }
-
- /**
- * Deactivate plugin action
- */
- function deactivate()
- {
- $this->link_delete();
-
- delete_option('w3tc_request_data');
-
- // keep for other blogs
- if (!$this->locked()) {
- @unlink(W3TC_BLOGNAMES_PATH);
- }
-
- @unlink(W3TC_CONFIG_PREVIEW_PATH);
-
- w3_rmdir(W3TC_TMP_DIR);
- w3_rmdir(W3TC_LOG_DIR);
- w3_rmdir(W3TC_CACHE_FILE_MINIFY_DIR);
- w3_rmdir(W3TC_CACHE_FILE_PGCACHE_DIR);
- w3_rmdir(W3TC_CACHE_FILE_DBCACHE_DIR);
- w3_rmdir(W3TC_CACHE_FILE_OBJECTCACHE_DIR);
- w3_rmdir(W3TC_CONTENT_DIR);
- }
-
- /**
- * Init action
- */
- function init()
- {
- $this->check_request();
- }
-
- /**
- * Load action
- */
- 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_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';
- }
-
- /**
- * Flush all caches
- */
- if (isset($_REQUEST['flush_all'])) {
- $this->flush_all();
-
- $this->redirect(array(
- 'w3tc_note' => 'flush_all'
- ), true);
- }
-
- /**
- * Flush memcached cache
- */
- if (isset($_REQUEST['flush_memcached'])) {
- $this->flush_memcached();
-
- $this->redirect(array(
- 'w3tc_note' => 'flush_memcached'
- ), true);
- }
-
- /**
- * Flush APC cache
- */
- if (isset($_REQUEST['flush_opcode'])) {
- $this->flush_opcode();
-
- $this->redirect(array(
- 'w3tc_note' => 'flush_opcode'
- ), true);
- }
-
- /**
- * Flush disk cache
- */
- if (isset($_REQUEST['flush_file'])) {
- $this->flush_file();
-
- $this->redirect(array(
- 'w3tc_note' => 'flush_file'
- ), true);
- }
-
- /**
- * Flush page cache
- */
- if (isset($_REQUEST['flush_pgcache'])) {
- $this->flush_pgcache();
-
- $this->_config->set('notes.need_empty_pgcache', false);
- $this->_config->set('notes.plugins_updated', false);
-
- if (!$this->_config->save()) {
- $this->redirect(array(
- 'w3tc_error' => 'config_save'
- ), true);
- }
-
- $this->redirect(array(
- 'w3tc_note' => 'flush_pgcache'
- ), true);
- }
-
- /**
- * Flush db cache
- */
- if (isset($_REQUEST['flush_dbcache'])) {
- $this->flush_dbcache();
-
- $this->redirect(array(
- 'w3tc_note' => 'flush_dbcache'
- ), true);
- }
-
- /**
- * Flush object cache
- */
- if (isset($_REQUEST['flush_objectcache'])) {
- $this->flush_objectcache();
-
- $this->redirect(array(
- 'w3tc_note' => 'flush_objectcache'
- ), true);
- }
-
- /**
- * Flush minify cache
- */
- if (isset($_REQUEST['flush_minify'])) {
- $this->flush_minify();
-
- $this->_config->set('notes.need_empty_minify', false);
-
- if (!$this->_config->save()) {
- $this->redirect(array(
- 'w3tc_error' => 'config_save'
- ), true);
- }
-
- $this->redirect(array(
- 'w3tc_note' => 'flush_minify'
- ), true);
- }
-
- /**
- * Hide notes
- */
- if (isset($_REQUEST['hide_note'])) {
- $setting = sprintf('notes.%s', W3_Request::get_string('hide_note'));
-
- $this->_config->set($setting, false);
-
- if (!$this->_config->save()) {
- $this->redirect(array(
- 'w3tc_error' => 'config_save'
- ), true);
- }
-
- $this->redirect(array(), true);
- }
-
- /**
- * Save config
- */
- if (isset($_REQUEST['save_config'])) {
- if ($this->_config->save()) {
- $this->redirect(array(
- 'w3tc_note' => 'config_save'
- ), true);
- } else {
- $this->redirect(array(
- 'w3tc_error' => 'config_save'
- ), true);
- }
- }
-
- /**
- * Write page cache rules
- */
- if (isset($_REQUEST['pgcache_write_rules_core'])) {
- require_once W3TC_LIB_W3_DIR . '/Plugin/PgCache.php';
- $w3_plugin_pgcache = & W3_Plugin_PgCache::instance();
-
- if ($w3_plugin_pgcache->write_rules_core()) {
- $this->redirect(array(
- 'w3tc_note' => 'pgcache_write_rules_core'
- ));
- } else {
- $this->redirect(array(
- 'w3tc_error' => 'pgcache_write_rules_core'
- ));
- }
- }
-
- if (isset($_REQUEST['pgcache_write_rules_cache'])) {
- require_once W3TC_LIB_W3_DIR . '/Plugin/PgCache.php';
- $w3_plugin_pgcache = & W3_Plugin_PgCache::instance();
-
- if ($w3_plugin_pgcache->write_rules_cache()) {
- $this->redirect(array(
- 'w3tc_note' => 'pgcache_write_rules_cache'
- ));
- } else {
- $this->redirect(array(
- 'w3tc_error' => 'pgcache_write_rules_cache'
- ));
- }
- }
-
- /**
- * Write browser cache rules
- */
- if (isset($_REQUEST['browsercache_write_rules_cache'])) {
- require_once W3TC_LIB_W3_DIR . '/Plugin/BrowserCache.php';
- $w3_plugin_browsercache = & W3_Plugin_BrowserCache::instance();
-
- if ($w3_plugin_browsercache->write_rules_cache()) {
- $this->redirect(array(
- 'w3tc_note' => 'browsercache_write_rules_cache'
- ));
- } else {
- $this->redirect(array(
- 'w3tc_error' => 'browsercache_write_rules_cache'
- ));
- }
- }
-
- if (isset($_REQUEST['browsercache_write_rules_no404wp'])) {
- require_once W3TC_LIB_W3_DIR . '/Plugin/BrowserCache.php';
- $w3_plugin_browsercache = & W3_Plugin_BrowserCache::instance();
-
- if ($w3_plugin_browsercache->write_rules_no404wp()) {
- $this->redirect(array(
- 'w3tc_note' => 'browsercache_write_rules_no404wp'
- ));
- } else {
- $this->redirect(array(
- 'w3tc_error' => 'browsercache_write_rules_no404wp'
- ));
- }
- }
-
- /**
- * Write minify rules
- */
- if (W3TC_PHP5 && isset($_REQUEST['minify_write_rules'])) {
- require_once W3TC_LIB_W3_DIR . '/Plugin/Minify.php';
- $w3_plugin_minify = & W3_Plugin_Minify::instance();
-
- if ($w3_plugin_minify->write_rules()) {
- $this->redirect(array(
- 'w3tc_note' => 'minify_write_rules'
- ));
- } else {
- $this->redirect(array(
- 'w3tc_error' => 'minify_write_rules'
- ));
- }
- }
-
- /**
- * Save support us options
- */
- if (isset($_REQUEST['save_support_us'])) {
- $support = W3_Request::get_string('support');
-
- $this->_config->set('common.support', $support);
-
- if (!$this->_config->save()) {
- $this->redirect(array(
- 'w3tc_error' => 'config_save'
- ));
- }
-
- $this->link_update();
-
- $this->redirect(array(
- 'w3tc_note' => 'config_save'
- ));
- }
-
- /**
- * Import config action
- */
- if (isset($_REQUEST['config_import'])) {
- $this->config_import();
- }
-
- /**
- * Export config action
- */
- if (isset($_REQUEST['config_export'])) {
- $this->config_export();
- }
-
- /**
- * Reset config action
- */
- if (isset($_REQUEST['config_reset'])) {
- $this->config_reset();
- }
-
- /**
- * Support select action
- */
- if (isset($_REQUEST['support_select'])) {
- $this->support_select();
- }
-
- /**
- * Deploy preview settings
- */
- if (isset($_REQUEST['preview_deploy'])) {
- $this->preview_deploy();
- }
-
- /**
- * Run plugin action
- */
- if (isset($_REQUEST['w3tc_action'])) {
- $action = trim($_REQUEST['w3tc_action']);
-
- if (method_exists($this, $action)) {
- call_user_func(array(
- &$this,
- $action
- ));
- exit();
- }
- }
-
- /**
- * Save options
- */
- if (isset($_REQUEST['options_save'])) {
- $this->options_save();
- }
-
- /**
- * Save preview mode
- */
- if (isset($_REQUEST['preview_save'])) {
- $this->preview_save();
- }
-
- /**
- * Support request
- */
- if (isset($_REQUEST['support_request'])) {
- $this->support_request();
- }
-
- /**
- * CDN Purge
- */
- if (isset($_REQUEST['cdn_purge_attachment'])) {
- $this->cdn_purge_attachment();
- }
-
- /**
- * PgCache purge
- */
- if (isset($_REQUEST['pgcache_purge_post'])) {
- $this->pgcache_purge_post();
- }
-
- $this->_support_reminder = ($this->_config->get_boolean('notes.support_us') && $this->_config->get_integer('common.install') < (time() - W3TC_SUPPORT_US_TIMEOUT) && !$this->is_supported());
- }
-
- /**
- * Dashboard setup action
- */
- function wp_dashboard_setup()
- {
- wp_add_dashboard_widget('w3tc_latest', 'The Latest from W3 EDGE', array(
- &$this,
- 'widget_latest'
- ), array(
- &$this,
- 'widget_latest_control'
- ));
- }
-
- /**
- * Prints latest widget contents
- */
- function widget_latest()
- {
- global $wp_version;
-
- $items = array();
- $items_count = $this->_config->get_integer('widget.latest.items');
-
- if ($wp_version >= 2.8) {
- include_once (ABSPATH . WPINC . '/feed.php');
- $feed = fetch_feed(W3TC_FEED_URL);
-
- if (!is_wp_error($feed)) {
- $feed_items = $feed->get_items(0, $items_count);
-
- foreach ($feed_items as $feed_item) {
- $items[] = array(
- 'link' => $feed_item->get_link(),
- 'title' => $feed_item->get_title(),
- 'description' => $feed_item->get_description()
- );
- }
- }
- } else {
- include_once (ABSPATH . WPINC . '/rss.php');
- $rss = fetch_rss(W3TC_FEED_URL);
-
- if (is_object($rss)) {
- $items = array_slice($rss->items, 0, $items_count);
- }
- }
-
- include W3TC_DIR . '/inc/widget/latest.phtml';
- }
-
- /**
- * Latest widget control
- */
- function widget_latest_control($widget_id, $form_inputs = array())
- {
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- require_once W3TC_LIB_W3_DIR . '/Request.php';
-
- $this->_config->set('widget.latest.items', W3_Request::get_integer('w3tc_latest_items', 3));
- $this->_config->save();
- } else {
- include W3TC_DIR . '/inc/widget/latest_control.phtml';
- }
- }
-
- /**
- * Admin init
- */
- function admin_init()
- {
- wp_register_style('w3tc-options', WP_PLUGIN_URL . '/w3-total-cache/inc/css/options.css');
- wp_register_style('w3tc-lightbox', WP_PLUGIN_URL . '/w3-total-cache/inc/css/lightbox.css');
-
- wp_register_script('w3tc-options', WP_PLUGIN_URL . '/w3-total-cache/inc/js/options.js');
- wp_register_script('w3tc-lightbox', WP_PLUGIN_URL . '/w3-total-cache/inc/js/lightbox.js');
- }
-
- /**
- * Admin menu
- */
- 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_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['minify']);
- }
-
- add_menu_page('Performance', 'Performance', 'manage_options', 'w3tc_general', '', plugins_url('w3-total-cache/inc/images/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
- */
- function admin_print_styles()
- {
- wp_enqueue_style('w3tc-options');
- wp_enqueue_style('w3tc-lightbox');
- }
-
- /**
- * Print scripts
- */
- function admin_print_scripts()
- {
- wp_enqueue_script('w3tc-options');
- wp_enqueue_script('w3tc-lightbox');
-
- switch ($this->_page) {
- case 'w3tc_minify':
- case 'w3tc_mobile':
- 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_DIR . '/inc/options/common/help.phtml';
- $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
- *
- * @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
- */
- function favorite_actions($actions)
- {
- $actions['admin.php?page=w3tc_general&flush_all'] = array(
- 'Empty Caches',
- 'manage_options'
- );
-
- return $actions;
- }
-
- /**
- * Check request and handle w3tc_request_data requests
- */
- function check_request()
- {
- $pos = strpos($_SERVER['REQUEST_URI'], '/w3tc_request_data/');
-
- if ($pos !== false) {
- $hash = substr($_SERVER['REQUEST_URI'], $pos + 19, 32);
-
- if (strlen($hash) == 32) {
- $request_data = (array) get_option('w3tc_request_data');
-
- if (isset($request_data[$hash])) {
- echo '<pre>';
- foreach ($request_data[$hash] as $key => $value) {
- printf("%s: %s\n", $key, $value);
- }
- echo '</pre>';
-
- unset($request_data[$hash]);
- update_option('w3tc_request_data', $request_data);
- } else {
- echo 'Requested hash expired or invalid';
- }
-
- exit();
- }
- }
- }
-
- /**
- * Admin notices action
- */
- function admin_notices()
- {
- $home_root = w3_get_home_root();
- $document_root = w3_get_document_root();
- $config_path = (w3_is_preview_config() ? W3TC_CONFIG_PREVIEW_PATH : W3TC_CONFIG_PATH);
-
- $pgcache_rules_core_path = $home_root . '/.htaccess';
- $pgcache_rules_cache_path = W3TC_CACHE_FILE_PGCACHE_DIR . '/.htaccess';
- $browsercache_rules_cache_path = $document_root . '/.htaccess';
- $browsercache_rules_no404wp_path = $home_root . '/.htaccess';
- $minify_rules_path = W3TC_CACHE_FILE_MINIFY_DIR . '/.htaccess';
-
- $error_messages = array(
- 'config_save' => sprintf('The settings could not be saved because the config 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 the 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('Either your .htaccess file does not exist or cannot be modified (%s). Please run <strong>chmod 777 %s</strong> to resolve this issue.', $pgcache_rules_core_path, (file_exists($pgcache_rules_core_path) ? $pgcache_rules_core_path : dirname($pgcache_rules_core_path))),
- 'pgcache_write_rules_cache' => sprintf('The page cache rules (%s) could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', $pgcache_rules_cache_path, (file_exists($pgcache_rules_cache_path) ? $pgcache_rules_cache_path : dirname($pgcache_rules_cache_path))),
- 'browsercache_write_rules_cache' => sprintf('The browser cache rules (%s) could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', $browsercache_rules_cache_path, (file_exists($browsercache_rules_cache_path) ? $browsercache_rules_cache_path : dirname($browsercache_rules_cache_path))),
- 'browsercache_write_rules_no404wp' => sprintf('The browser cache rules (%s) could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', $browsercache_rules_no404wp_path, (file_exists($browsercache_rules_no404wp_path) ? $browsercache_rules_no404wp_path : dirname($browsercache_rules_no404wp_path))),
- 'browsercache_write_rules_cdn' => sprintf('The browser cache rules for CDN could not be modified. Please check CDN settings.'),
- 'minify_write_rules' => sprintf('The minify cache rules (%s) could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', $minify_rules_path, (file_exists($minify_rules_path) ? $minify_rules_path : dirname($minify_rules_path))),
- 'support_request_type' => 'Please select request type.',
- 'support_request_url' => 'Please enter the address of your 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. Remember you can create a temporary one just for this support case.',
- '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 your site.',
- 'support_request_ftp_login' => 'Please enter <acronym title="Secure Shell">SSH</acronym> or <acronym title="File Transfer Protocol">FTP</acronym> login for your server. Remember you can create a temporary one just for this support case.',
- 'support_request_ftp_password' => 'Please enter <acronym title="Secure Shell">SSH</acronym> or <acronym title="File Transfer Protocol">FTP</acronym> password for your <acronym title="File Transfer Protocol">FTP</acronym> account.',
- 'support_request' => 'Unable to send your support request.',
- 'config_import_no_file' => 'Please select config file.',
- 'config_import_upload' => 'Unable to upload config file.',
- 'config_import_import' => sprintf('Configuration file could not be imported. 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))),
- '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.'
- );
-
- $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 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.',
- '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' => 'Minify rewrite rules have been successfully written.',
- 'support_request' => 'Your 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.'
- );
-
- $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 your settings', sprintf('admin.php?page=%s&save_config', $this->_page)));
- }
-
- /**
- * CDN notifications
- */
- if ($this->_config->get_boolean('cdn.enabled') && !in_array($this->_config->get_string('cdn.engine'), array(
- 'mirror',
- 'netdna'
- ))) {
- /**
- * Show notification after theme change
- */
- if ($this->_config->get_boolean('notes.theme_changed')) {
- $notes[] = sprintf('Your 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('Have you 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')) {
- $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');
- }
-
- $notes[] = sprintf('Make sure to %s and upload your %s, files to the CDN to ensure proper operation. %s', $this->button_popup('export your media library', 'cdn_export_library'), implode(', ', $cdn_upload_buttons), $this->button_hide_note('Hide this message', 'cdn_upload'));
- }
- }
-
- /**
- * 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', sprintf('admin.php?page=%s&flush_pgcache', $this->_page));
- }
-
- if ($this->_config->get_boolean('minify.enabled')) {
- $texts[] = sprintf('check your %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 your cached data or modify the behavior of your site. %s now to provide a consistent user experience.', $this->button_link('Empty the page cache', sprintf('admin.php?page=%s&flush_pgcache', $this->_page)));
- }
-
- /**
- * 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: Some files were unavailable, please check your settings to ensure your site is working as intended. %s', $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 your cached data or modify the behavior of your site. %s now to provide a consistent user experience.', $this->button_link('Empty the minify cache', sprintf('admin.php?page=%s&flush_minify', $this->_page)));
- }
- }
-
- /**
- * 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);
- }
- }
-
- /**
- * Active plugins pre update option filter
- */
- 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
- */
- function in_plugin_update_message()
- {
- $data = w3_http_get(W3TC_README_URL);
-
- if ($data) {
- $matches = null;
- if (preg_match('~==\s*Changelog\s*==\s*=\s*[0-9.]+\s*=(.*)(=\s*[0-9.]+\s*=|$)~Uis', $data, $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
- */
- function media_row_actions($actions, $post)
- {
- $actions = array_merge($actions, array(
- 'cdn_purge' => sprintf('<a href="admin.php?page=w3tc_general&cdn_purge_attachment&attachment_id=%d">Purge from CDN</a>', $post->ID)
- ));
-
- return $actions;
- }
-
- /**
- * post_row_actions filter
- */
- function post_row_actions($actions, $post)
- {
- $actions = array_merge($actions, array(
- 'pgcache_purge' => sprintf('<a href="admin.php?page=w3tc_general&pgcache_purge_post&post_id=%d">Purge from Page Cache</a>', $post->ID)
- ));
-
- return $actions;
- }
-
- /**
- * Template filter
- *
- * @param $template
- * @return string
- */
- function template($template)
- {
- require_once W3TC_LIB_W3_DIR . '/Mobile.php';
- $w3_mobile = & W3_Mobile::instance();
-
- $mobile_template = $w3_mobile->get_template();
-
- if ($mobile_template) {
- return $mobile_template;
- }
-
- return $template;
- }
-
- /**
- * Stylesheet filter
- *
- * @param $stylesheet
- * @return string
- */
- function stylesheet($stylesheet)
- {
- require_once W3TC_LIB_W3_DIR . '/Mobile.php';
- $w3_mobile = & W3_Mobile::instance();
-
- $mobile_stylesheet = $w3_mobile->get_stylesheet();
-
- if ($mobile_styleshee…