/blog/wp-content/plugins/w3-total-cache/lib/W3/Plugin/TotalCache.php
PHP | 2875 lines | 1864 code | 486 blank | 525 comment | 439 complexity | 5104b3a9260136b4cc2a289c2b6b5a7b MD5 | raw file
Large files files are truncated, but you can 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
- {
- /**
- * Page tab
- * @var string
- */
- var $_tab = '';
-
- /**
- * 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 = '';
-
- /**
- * Runs plugin
- */
- function run()
- {
- register_activation_hook(W3TC_FILE, array(
- &$this,
- 'activate'
- ));
-
- register_deactivation_hook(W3TC_FILE, array(
- &$this,
- 'deactivate'
- ));
-
- add_action('admin_menu', array(
- &$this,
- 'admin_menu'
- ));
-
- 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('cdn.enabled')) {
- add_action('switch_theme', array(
- &$this,
- 'switch_theme'
- ));
-
- add_filter('update_feedback', array(
- &$this,
- 'update_feedback'
- ));
- }
-
- 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_string('common.support') == 'footer') {
- add_action('wp_footer', array(
- &$this,
- 'footer'
- ));
- }
-
- if ($this->can_modify_contents()) {
- 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 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();
- }
- }
-
- /**
- * 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];
- }
-
- /**
- * Check for buggy site-wide activation
- */
- function wpmu_check()
- {
- $sitewide_plugins = (array) @unserialize(get_site_option('active_sitewide_plugins'));
- $plugins = (array) @unserialize(get_option('active_plugins'));
- }
-
- /**
- * Activate plugin action
- */
- function activate()
- {
- 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_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 (!$this->_config->get_integer('common.install')) {
- $this->_config->set('common.install', time());
- }
-
- if (w3_is_wpmu()) {
- $this->_config->load_master();
- }
-
- if (!$this->_config->save()) {
- w3_writable_error(W3TC_CONFIG_PATH);
- }
-
- delete_option('w3tc_request_data');
- add_option('w3tc_request_data', '', null, 'no');
-
- $this->link_update();
- }
-
- /**
- * Deactivate plugin action
- * @todo Complete plugin uninstall on site wide activation
- */
- function deactivate()
- {
- $this->link_delete();
-
- delete_option('w3tc_request_data');
-
- 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_CONTENT_DIR);
- }
-
- /**
- * Init action
- */
- function init()
- {
- $this->check_request();
- }
-
- /**
- * Load action
- */
- function load()
- {
- require_once W3TC_LIB_W3_DIR . '/Request.php';
-
- $this->_tab = W3_Request::get_string('tab');
-
- switch (true) {
- case ($this->_tab == 'general'):
- case ($this->_tab == 'pgcache'):
- case ($this->_tab == 'dbcache'):
- case ($this->_tab == 'minify' && W3TC_PHP5):
- case ($this->_tab == 'cdn'):
- case ($this->_tab == 'install'):
- case ($this->_tab == 'faq'):
- case ($this->_tab == 'about'):
- case ($this->_tab == 'support'):
- break;
-
- default:
- $this->_tab = 'general';
- }
-
- /**
- * Flush all caches
- */
- if (isset($_REQUEST['flush_all'])) {
- $this->flush_memcached();
- $this->flush_opcode();
- $this->flush_file();
-
- $this->redirect(array(
- 'note' => 'flush_all'
- ), true);
- }
-
- /**
- * Flush memcached cache
- */
- if (isset($_REQUEST['flush_memcached'])) {
- $this->flush_memcached();
-
- $this->redirect(array(
- 'note' => 'flush_memcached'
- ), true);
- }
-
- /**
- * Flush APC cache
- */
- if (isset($_REQUEST['flush_opcode'])) {
- $this->flush_opcode();
-
- $this->redirect(array(
- 'note' => 'flush_opcode'
- ), true);
- }
-
- /**
- * Flush disk cache
- */
- if (isset($_REQUEST['flush_file'])) {
- $this->flush_file();
-
- $this->redirect(array(
- '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(
- 'error' => 'config_save'
- ), true);
- }
-
- $this->redirect(array(
- 'note' => 'flush_pgcache'
- ), true);
- }
-
- /**
- * Flush db cache
- */
- if (isset($_REQUEST['flush_dbcache'])) {
- $this->flush_dbcache();
-
- $this->redirect(array(
- 'note' => 'flush_dbcache'
- ), 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(
- 'error' => 'config_save'
- ), true);
- }
-
- $this->redirect(array(
- '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(
- 'error' => 'config_save'
- ), true);
- }
-
- $this->redirect(array(), true);
- }
-
- /**
- * Save config
- */
- if (isset($_REQUEST['save_config'])) {
- if ($this->_config->save()) {
- $this->redirect(array(
- 'note' => 'config_save'
- ), true);
- } else {
- $this->redirect(array(
- '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(
- 'note' => 'pgcache_write_rules_core'
- ));
- } else {
- $this->redirect(array(
- '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(
- 'note' => 'pgcache_write_rules_cache'
- ));
- } else {
- $this->redirect(array(
- 'error' => 'pgcache_write_rules_cache'
- ));
- }
- }
-
- /**
- * 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(
- 'note' => 'minify_write_rules'
- ));
- } else {
- $this->redirect(array(
- '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(
- 'error' => 'config_save'
- ));
- }
-
- $this->link_update();
-
- $this->redirect(array(
- 'note' => 'config_save'
- ));
- }
-
- /**
- * 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();
- }
- }
-
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- if ($this->_tab == 'support') {
- $this->support_request();
- } else {
- $this->options_save();
- }
- exit();
- }
-
- $this->_support_reminder = ($this->_config->get_boolean('notes.support_us') && $this->_config->get_integer('common.install') < (time() - W3TC_SUPPORT_US_TIMEOUT) && !$this->is_supported());
-
- wp_enqueue_style('w3tc-options', WP_PLUGIN_URL . '/w3-total-cache/inc/css/options.css');
- wp_enqueue_style('w3tc-lightbox', WP_PLUGIN_URL . '/w3-total-cache/inc/css/lightbox.css');
- }
-
- /**
- * 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 menu
- */
- function admin_menu()
- {
- $page = add_options_page('W3 Total Cache', 'W3 Total Cache', 'manage_options', W3TC_FILE, array(
- &$this,
- 'options'
- ));
-
- if (current_user_can('manage_options')) {
- /**
- * Only admin can modify W3TC settings
- */
- add_action('load-' . $page, array(
- &$this,
- 'load'
- ));
-
- /**
- * Only admin can see W3TC notices and errors
- */
- add_action('admin_notices', array(
- &$this,
- 'admin_notices'
- ));
- }
- }
-
- /**
- * Plugin action links filter
- *
- * @return array
- */
- function plugin_action_links($links)
- {
- array_unshift($links, '<a class="edit" href="options-general.php?page=' . W3TC_FILE . '">Settings</a>');
-
- return $links;
- }
-
- /**
- * favorite_actions filter
- */
- function favorite_actions($actions)
- {
- $actions['options-general.php?page=' . W3TC_FILE . '&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 'Hash is expired or invalid';
- }
-
- exit();
- }
- }
- }
-
- /**
- * Admin notices action
- */
- function admin_notices()
- {
- $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(W3TC_CONFIG_PATH) ? W3TC_CONFIG_PATH : WP_CONTENT_DIR),
- 'fancy_permalinks_disabled' => 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')),
- 'pgcache_write_rules_core' => sprintf('Either your .htaccess file does not exist or cannot be modified (%s.htaccess). Please run <strong>chmod 777 %s.htaccess</strong> to resolve this issue.', ABSPATH, ABSPATH),
- 'pgcache_write_rules_cache' => sprintf('The page cache rules (%s/.htaccess) could not be modified. Please run <strong>chmod 777 %s/.htaccess</strong> to resolve this issue.', W3TC_CACHE_FILE_PGCACHE_DIR, W3TC_CACHE_FILE_PGCACHE_DIR),
- 'minify_write_rules' => sprintf('The minify cache rules (%s/.htaccess) could not be modified. Please run <strong>chmod 777 %s/.htaccess</strong> to resolve this issue.', W3TC_CACHE_FILE_MINIFY_DIR, W3TC_CACHE_FILE_MINIFY_DIR),
- 'support_request_url' => 'Please enter the address of your blog in the Blog <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_type' => 'Please select request type.',
- '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.'
- );
-
- $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_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.',
- 'minify_write_rules' => 'Minify rewrite rules have been successfully written.',
- 'support_request' => 'Your support request has been successfully sent.'
- );
-
- $errors = array();
- $notes = array();
-
- require_once W3TC_LIB_W3_DIR . '/Request.php';
-
- $error = W3_Request::get_string('error');
- $note = W3_Request::get_string('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 (!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('options-general.php?page=%s&tab=%s&save_config', W3TC_FILE, $this->_tab)));
- }
-
- /**
- * CDN notifications
- */
- if ($this->_config->get_boolean('cdn.enabled') && $this->_config->get_string('cdn.engine') != 'mirror') {
- /**
- * 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('options-general.php?page=%s&tab=%s&flush_pgcache', W3TC_FILE, $this->_tab));
- }
-
- 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', sprintf('options-general.php?page=%s&tab=minify', W3TC_FILE)));
- }
-
- 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')) {
- $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('options-general.php?page=%s&tab=%s&flush_pgcache', W3TC_FILE, $this->_tab)));
- }
-
- /**
- * Show notification when minify needs to be emptied
- */
- if ($this->_config->get_boolean('minify.enabled') && $this->_config->get('notes.need_empty_minify')) {
- $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('options-general.php?page=%s&tab=%s&flush_minify', W3TC_FILE, $this->_tab)));
- }
-
- /**
- * 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);
- }
- }
-
- /**
- * Switch theme action
- */
- function switch_theme()
- {
- $this->_config->set('notes.theme_changed', true);
- $this->_config->save();
- }
-
- /**
- * WP Upgrade action hack
- *
- * @param string $message
- */
- function update_feedback($message)
- {
- if ($message == __('Upgrading database')) {
- $this->_config->set('notes.wp_upgraded', true);
- $this->_config->save();
- }
- }
-
- /**
- * 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_url_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>';
- }
- }
- }
-
- /**
- * Footer plugin action
- */
- function footer()
- {
- echo '<div style="text-align: center;">Performance Optimization <a href="http://www.w3-edge.com/wordpress-plugins/" rel="external">WordPress Plugins</a> by W3 EDGE</div>';
- }
-
- /**
- * Options page
- */
- function options()
- {
- /**
- * Check for page cache availability
- */
- if ($this->_config->get_boolean('pgcache.enabled')) {
- if (!$this->check_advanced_cache()) {
- $this->_errors[] = sprintf('Page caching is not available: advanced-cache.php is not installed. Either the <strong>%s</strong> directory is not write-able or you have another caching plugin installed. This error message will automatically disappear once the change is successfully made.', WP_CONTENT_DIR);
- } elseif (!defined('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);
- } else {
- switch ($this->_config->get_string('pgcache.engine')) {
- case 'file_pgcache':
- require_once W3TC_LIB_W3_DIR . '/Plugin/PgCache.php';
- $w3_plugin_pgcache = & W3_Plugin_PgCache::instance();
-
- if ($this->_config->get_boolean('notes.pgcache_rules_core') && !$w3_plugin_pgcache->check_rules_core()) {
- if (w3_is_wpmu()) {
- $this->_errors[] = sprintf('Enhanced mode page cache is not operational. Your .htaccess rules could not be modified. Please verify <strong>%s.htaccess</strong> has the following rules: <pre>%s</pre> %s', ABSPATH, htmlspecialchars($w3_plugin_pgcache->generate_rules_core()), $this->button_hide_note('Hide this message', 'pgcache_rules_core'));
- } else {
- $this->_errors[] = sprintf('You\'ve selected disk caching with enhanced mode however the .htaccess file is not properly configured. Please run <strong>chmod 777 %s.htaccess</strong>, then %s. To manually modify your server configuration for enhanced mode append the following code: <pre>%s</pre> and %s.', ABSPATH, $this->button_link('try again', sprintf('options-general.php?page=%s&tab=%s&pgcache_write_rules_core', W3TC_FILE, $this->_tab)), htmlspecialchars($w3_plugin_pgcache->generate_rules_core()), $this->button_hide_note('hide this message', 'pgcache_rules_core'));
- }
- }
-
- if ($this->_config->get_boolean('notes.pgcache_rules_cache') && !$w3_plugin_pgcache->check_rules_cache()) {
- $this->_errors[] = sprintf('You\'ve selected disk caching with enhanced mode however the .htaccess file is not properly configured. Please run <strong>chmod 777 %s/.htaccess</strong>, then %s. To manually modify your server configuration for enhanced mode append the following code: <pre>%s</pre> and %s.', W3TC_CACHE_FILE_PGCACHE_DIR, $this->button_link('try again', sprintf('options-general.php?page=%s&tab=%s&pgcache_write_rules_cache', W3TC_FILE, $this->_tab)), htmlspecialchars($w3_plugin_pgcache->generate_rules_cache()), $this->button_hide_note('hide this message', 'pgcache_rules_cache'));
- }
- break;
-
- case 'memcached':
- $pgcache_memcached_servers = $this->_config->get_array('pgcache.memcached.servers');
-
- if (!$this->is_memcache_available($pgcache_memcached_servers)) {
- $this->_errors[] = sprintf('Page caching is not working properly. Memcached server(s): <strong>%s</strong> may not running or not responding. This error message will automatically disappear once the issue is resolved.', implode(', ', $pgcache_memcached_servers));
- }
- break;
- }
- }
- }
-
- /**
- * Check for minify availability
- */
- if ($this->_config->get_boolean('minify.enabled')) {
- switch ($this->_config->get_string('minify.engine')) {
- case 'file':
- if (W3TC_PHP5) {
- require_once W3TC_LIB_W3_DIR . '/Plugin/Minify.php';
- $w3_plugin_minify = & W3_Plugin_Minify::instance();
-
- if ($this->_config->get_boolean('notes.minify_rules') && !$w3_plugin_minify->check_rules()) {
- $this->_errors[] = sprintf('The "Rewrite URL Structure" feature, requires rewrite rules be present. Please run <strong>chmod 777 %s/.htaccess</strong>, then %s. To manually modify your server configuration for minify append the following code: <pre>%s</pre> and %s.', W3TC_CACHE_FILE_MINIFY_DIR, $this->button_link('try again', sprintf('options-general.php?page=%s&tab=%s&minify_write_rules', W3TC_FILE, $this->_tab)), htmlspecialchars($w3_plugin_minify->generate_rules()), $this->button_hide_note('hide this message', 'minify_rules'));
- }
- }
- break;
-
- case 'memcached':
- $minify_memcached_servers = $this->_config->get_array('minify.memcached.servers');
-
- if (!$this->is_memcache_available($minify_memcached_servers)) {
- $this->_errors[] = sprintf('Minify is not working properly. Memcached server(s): <strong>%s</strong> may not running or not responding. This error message will automatically disappear once the issue is resolved.', implode(', ', $minify_memcached_servers));
- }
- break;
- }
- }
-
- /**
- * Check for database cache availability
- */
- if ($this->_config->get_boolean('dbcache.enabled')) {
- if (!$this->check_db()) {
- $this->_errors[] = sprintf('Database caching is not available: db.php is not installed. Either the <strong>%s</strong> directory is not write-able or you have another caching plugin installed. This error message will automatically disappear once the change is successfully made.', WP_CONTENT_DIR);
- } elseif ($this->_config->get_string('pgcache.engine') == 'memcached') {
- $dbcache_memcached_servers = $this->_config->get_array('dbcache.memcached.servers');
-
- if (!$this->is_memcache_available($dbcache_memcached_servers)) {
- $this->_errors[] = sprintf('Database caching is not working properly. Memcached server(s): <strong>%s</strong> may not running or not responding. This error message will automatically disappear once the issue is successfully resolved.', implode(', ', $dbcache_memcached_servers));
- }
- }
- }
-
- /**
- * Check PHP version
- */
- if (!W3TC_PHP5 && $this->_config->get_boolean('notes.php_is_old')) {
- $this->_notes[] = sprintf('Unfortunately, <strong>PHP5</strong> is required for full functionality of this plugin; incompatible features are automatically disabled. Please upgrade if possible. %s', $this->button_hide_note('Hide this message', 'php_is_old'));
- }
-
- /**
- * Check CURL extension
- */
- if ($this->_config->get_boolean('notes.no_curl') && $this->_config->get_boolean('cdn.enabled') && !function_exists('curl_init')) {
- $this->_notes[] = sprintf('The <strong>CURL PHP</strong> extension is not available. Please install it to enable S3 or CloudFront functionality. %s', $this->button_hide_note('Hide this message', 'no_curl'));
- }
-
- /**
- * Check Zlib extension
- */
- if ($this->_config->get_boolean('notes.no_zlib') && (!function_exists('gzencode') || !function_exists('gzdeflate'))) {
- $this->_notes[] = sprintf('Unfortunately the PHP installation is incomplete, the <strong>zlib module is missing</strong>. This is a core PHP module. Please notify your server administrator and ask for it to be installed. %s', $this->button_hide_note('Hide this message', 'no_zlib'));
- }
-
- /**
- * Check if Zlib output compression is enabled
- */
- if ($this->_config->get_boolean('notes.zlib_output_compression') && w3_zlib_output_compression()) {
- $this->_notes[] = sprintf('Either the PHP configuration, Web Server configuration or a script somewhere in your WordPress installation is has set <strong>zlib.output_compression</strong> to enabled.<br />Please locate and disable this setting to ensure proper HTTP compression management. %s', $this->button_hide_note('Hide this message', 'zlib_output_compression'));
- }
-
- /**
- * Show message when defaults are set
- */
- if ($this->_config->get_boolean('notes.defaults')) {
- $this->_notes[] = sprintf('The plugin is in quick setup mode, most recommended defaults are set. Satisfy any warnings customizing any settings. %s', $this->button_hide_note('Hide this message', 'defaults'));
- }
-
- /**
- * Check wp-content permissions
- */
- if (!W3TC_WIN && $this->_config->get_boolean('notes.wp_content_perms')) {
- $wp_content_stat = stat(WP_CONTENT_DIR);
- $wp_content_mode = ($wp_content_stat['mode'] & 0777);
-
- if ($wp_content_mode != 0755) {
- $this->_notes[] = sprintf('<strong>%s</strong> is write-able. If you\'ve finished installing the plugin, change the permissions back to the default: <strong>chmod 755 %s</strong>. %s', WP_CONTENT_DIR, WP_CONTENT_DIR, $this->button_hide_note('Hide this message', 'wp_content_perms'));
- }
- }
-
- /**
- * Check CDN settings
- */
- if ($this->_config->get_boolean('cdn.enabled')) {
- $cdn_engine = $this->_config->get_string('cdn.engine');
-
- switch (true) {
- case ($cdn_engine == 'mirror' && $this->_config->get_string('cdn.mirror.domain') == ''):
- $this->_errors[] = 'The <strong>"Replace default hostname with"</strong> field must be populated.';
- break;
-
- case ($cdn_engine == 'ftp' && $this->_config->get_string('cdn.ftp.domain') == ''):
- $this->_errors[] = 'The <strong>"Replace default hostname with"</strong> field must be populated. Enter the hostname of your <acronym title="Content Delivery Network">CDN</acronym> provider. <em>This is the hostname you would enter into your address bar in order to view objects in your browser.</em>';
- break;
-
- case ($cdn_engine == 's3' && ($this->_config->get_string('cdn.s3.key') == '' || $this->_config->get_string('cdn.s3.bucket') == '' || $this->_config->get_string('cdn.s3.bucket') == '')):
- $this->_errors[] = 'The <strong>"Access key", "Secret key" and "Bucket"</strong> fields must be populated.';
- break;
-
- case ($cdn_engine == 'cf' && ($this->_config->get_string('cdn.cf.key') == '' || $this->_config->get_string('cdn.cf.secret') == '' || $this->_config->get_string('cdn.cf.bucket') == '' || ($this->_config->get_string('cdn.cf.id') == '' && $this->_config->get_string('cdn.cf.cname') == ''))):
- $this->_errors[] = 'The <strong>"Access key", "Secret key", "Bucket" and "Replace default hostname with"</strong> fields must be populated.';
- break;
- }
- }
-
- /**
- * Show tab
- */
- switch ($this->_tab) {
- case 'general':
- $this->options_general();
- break;
-
- case 'pgcache':
- $this->options_pgcache();
- break;
-
- case 'dbcache':
- $this->options_dbcache();
- break;
-
- case 'minify':
- $this->options_minify();
- break;
-
- case 'cdn':
- $this->options_cdn();
- break;
-
- case 'faq':
- $this->options_faq();
- break;
-
- case 'support':
- $this->options_support();
- break;
-
- case 'install':
- $this->options_install();
- break;
-
- case 'about':
- $this->options_about();
- break;
- }
- }
-
- /**
- * General tab
- */
- function options_general()
- {
- $pgcache_enabled = $this->_config->get_boolean('pgcache.enabled');
- $dbcache_enabled = $this->_config->get_boolean('dbcache.enabled');
- $minify_enabled = $this->_config->get_boolean('minify.enabled');
- $cdn_enabled = $this->_config->get_boolean('cdn.enabled');
-
- $enabled = ($pgcache_enabled || $dbcache_enabled || $minify_enabled || $cdn_enabled);
-
- $check_apc = function_exists('apc_store');
- $check_eaccelerator = function_exists('eaccelerator_put');
- $check_xcache = function_exists('xcache_set');
- $check_curl = function_exists('curl_init');
- $check_memcached = class_exists('Memcache');
-
- $pgcache_engine = $this->_config->get_string('pgcache.engine');
- $dbcache_engine = $this->_config->get_string('dbcache.engine');
- $minify_engine = $this->_config->get_string('minify.engine');
-
- $can_empty_memcache = ($pgcache_engine == 'memcached' || $dbcache_engine == 'memcached' || $minify_engine == 'memcached');
-
- $can_empty_opcode = ($pgcache_engine == 'apc' || $pgcache_engine == 'eaccelerator' || $pgcache_engine == 'xcache');
- $can_empty_opcode = $can_empty_opcode || ($dbcache_engine == 'apc' || $dbcache_engine == 'eaccelerator' || $dbcache_engine == 'xcache');
- $can_empty_opcode = $can_empty_opcode || ($minify_engine == 'apc' || $minify_engine == 'eaccelerator' || $minify_engine == 'xcache');
-
- $can_empty_file = ($pgcache_engine == 'file' || $pgcache_engine == 'file_pgcache' || $dbcache_engine == 'file' || $minify_engine == 'file');
-
- $debug = ($this->_config->get_boolean('dbcache.debug') || $this->_config->get_boolean('pgcache.debug') || $this->_config->get_boolean('minify.debug') || $this->_config->get_boolean('cdn.debug'));
-
- $support = $this->_config->get_string('common.support');
- $supports = $this->get_supports();
-
- include W3TC_DIR . '/inc/options/general.phtml';
- }
-
- /**
- * Page cache tab
- */
- function options_pgcache()
- {
- $pgcache_enabled = $this->_config->get_boolean('pgcache.enabled');
- $pgcache_gzip = function_exists('gzencode');
- $pgcache_deflate = function_exists('gzdeflate');
-
- include W3TC_DIR . '/inc/options/pgcache.phtml';
- }
-
- /**
- * Minify tab
- */
- function options_minify()
- {
- $minify_enabled = $this->_config->get_boolean('minify.enabled');
- $minify_gzip = function_exists('gzencode');
- $minify_deflate = function_exists('gzdeflate');
-
- $groups = $this->minify_get_groups();
-
- $js_group = W3_Request::get_string('js_group', 'default');
- $js_groups = $this->_config->get_array('minify.js.groups');
-
- $css_group = W3_Request::get_string('css_group', 'default');
- $css_groups = $this->_config->get_array('minify.css.groups');
-
- include W3TC_DIR . '/inc/options/minify.phtml';
- }
-
- /**
- * Database cache tab
- */
- function options_dbcache()
- {
- $dbcache_enabled = $this->_config->get_boolean('dbcache.enabled');
-
- include W3TC_DIR . '/inc/options/dbcache.phtml';
- }
-
- /**
- * CDN tab
- */
- function options_cdn()
- {
- $cdn_enabled = $this->_config->get_boolean('cdn.enabled');
- $cdn_engine = $this->_config->get_string('cdn.engine');
- $cdn_mirror = ($cdn_engine == 'mirror');
-
- $minify_enabled = $this->_config->get_boolean('minify.enabled');
-
- include W3TC_DIR . '/inc/options/cdn.phtml';
- }
-
- /**
- * FAQ tab
- */
- function options_faq()
- {
- include W3TC_DIR . '/inc/options/faq.phtml';
- }
-
- /**
- * Support tab
- */
- function options_support()
- {
- $theme = get_theme(get_current_theme());
- $template_files = (isset($theme['Template Files']) ? (array) $theme['Template Files'] : array());
-
- $request_types = array(
- 'Bug Submission',
- 'Plugin (add-on) Request'
- );
-
- require_once W3TC_LIB_W3_DIR . '/Request.php';
-
- $user = get_user_by('login', 'admin');
-
- $url = W3_Request::get_string('url', w3_get_domain_url());
- $name = W3_Request::get_string('name', ($user ? $user->display_name : ''));
- $email = W3_Request::get_string('email', ($user ? $user->user_email : ''));
- $request_type = W3_Request::get_string('request_type');
- $description = W3_Request::get_string('description');
- $templates = W3_Request::get_array('templates');
- $wp_login = W3_Request::get_string('wp_login');
- $wp_password = W3_Request::get_string('wp_password');
- $ftp_host = W3_Request::get_string('ftp_host');
- $ftp_login = W3_Request::get_string('ftp_login');
- $ftp_password = W3_Request::get_string('ftp_password');
-
- include W3TC_DIR . '/inc/options/support.phtml';
- }
-
- /**
- * Install tab
- */
- function options_install()
- {
- include W3TC_DIR . '/inc/options/install.phtml';
- }
-
- /**
- * About tab
- */
- function options_about()
- {
- include W3TC_DIR . '/inc/options/about.phtml';
- }
-
- /**
- * Options save action
- */
- function options_save()
- {
- require_once W3TC_LIB_W3_DIR . '/Request.php';
-
- /**
- * Redirect params
- */
- $params = array();
-
- /**
- * Read config
- */
- $config = & new W3_Config();
- $config->read_request();
-
- /**
- * General tab
- …
Large files files are truncated, but you can click here to view the full file