function run() { add_action('w3tc_register_fragment_groups', array($this, 'register_groups')); $this->_config = w3_instance('W3_Config'); if ((w3_is_pro($this->_config) || w3_is_enterprise($this->_config)) && $this->_config->get_boolean('fragmentcache.enabled')) { if (!is_admin()) { /** * Register the caching of content to specific hooks */ foreach (array('genesis_header', 'genesis_footer', 'genesis_sidebar', 'genesis_loop', 'wp_head', 'wp_footer', 'genesis_comments', 'genesis_pings') as $hook) { add_action($hook, array($this, 'cache_genesis_start'), -999999999); add_action($hook, array($this, 'cache_genesis_end'), 999999999); } foreach (array('genesis_do_subnav', 'genesis_do_nav') as $filter) { add_filter($filter, array($this, 'cache_genesis_filter_start'), -999999999); add_filter($filter, array($this, 'cache_genesis_filter_end'), 999999999); } } /** * Since posts pages etc are cached individually need to be able to flush just those and not all fragment */ add_action('clean_post_cache', array($this, 'flush_post_fragment')); add_action('clean_post_cache', array($this, 'flush_terms_fragment'), 0, 0); $this->_request_uri = $_SERVER['REQUEST_URI']; } }
function __construct() { $this->_config = w3_instance('W3_Config'); $this->_plugins = array(array('class_name' => 'W3_Plugin_TotalCache', 'enable_options' => null), array('class_name' => 'W3_Plugin_DbCache', 'enable_options' => 'dbcache.enabled'), array('class_name' => 'W3_Plugin_ObjectCache', 'enable_options' => 'objectcache.enabled'), array('class_name' => 'W3_Pro_Plugin_FragmentCache', 'enable_options' => 'fragmentcache.enabled'), array('class_name' => 'W3_Plugin_PgCache', 'enable_options' => 'pgcache.enabled'), array('class_name' => 'W3_Plugin_Cdn', 'enable_options' => 'cdn.enabled'), array('class_name' => 'W3_Plugin_BrowserCache', 'enable_options' => 'browsercache.enabled'), array('class_name' => 'W3_Plugin_Minify', 'enable_options' => 'minify.enabled'), array('class_name' => 'W3_Plugin_Varnish', 'enable_options' => 'varnish.enabled'), array('class_name' => 'W3_Plugin_NewRelic', 'enable_options' => 'newrelic.enabled')); if (w3tc_edge_mode() && (w3_is_pro($this->_config) || w3_is_enterprise()) && w3tc_cdn_supports_realtime_purge($this->_config->get_string('cdn.engine'))) { $this->_plugins[] = array('class_name' => 'W3_Plugin_CdnCache', 'enable_options' => array('cdn.enabled', 'cdncache.enabled')); } if (is_admin()) { $this->_plugins[] = array('class_name' => 'W3_Plugin_TotalCacheAdmin', 'enable_options' => null); $this->_plugins[] = array('class_name' => 'W3_Plugin_PgCacheAdmin', 'enable_options' => 'pgcache.enabled'); $this->_plugins[] = array('class_name' => 'W3_Plugin_MinifyAdmin', 'enable_options' => array('minify.enabled', 'minify.auto')); $this->_plugins[] = array('class_name' => 'W3_Plugin_NewRelicAdmin', 'enable_options' => null); $this->_plugins[] = array('class_name' => 'W3_Widget_Services', 'enable_options' => null); $this->_plugins[] = array('class_name' => 'W3_Widget_SpreadTheWord', 'enable_options' => null); $this->_plugins[] = array('class_name' => 'W3_Widget_News', 'enable_options' => null); $this->_plugins[] = array('class_name' => 'W3_Widget_Forum', 'enable_options' => null); $this->_plugins[] = array('class_name' => 'W3_Widget_MaxCDN', 'enable_options' => array(array('cdn.engine', '==', 'maxcdn'), '||', array('cdn.engine', '!=', 'netdna'))); $this->_plugins[] = array('class_name' => 'W3_Widget_NetDNA', 'enable_options' => array(array('cdn.engine', '==', 'netdna'))); $this->_plugins[] = array('class_name' => 'W3_Widget_NewRelic', 'enable_options' => null); $this->_plugins[] = array('class_name' => 'W3_Widget_PageSpeed', 'enable_options' => 'widget.pagespeed.enabled'); $this->_plugins[] = array('class_name' => 'W3_AdminCompatibility', 'enable_options' => null); if (!(defined('W3TC_PRO') || w3_is_enterprise())) { $this->_plugins[] = array('class_name' => 'W3_Licensing', 'enable_options' => null); } $this->_plugins[] = array('class_name' => 'W3_Plugin_DefaultSettings', 'enable_options' => null); $this->_plugins[] = array('class_name' => 'W3_GeneralActions', 'enable_options' => array('pgcache.enabled', '||', 'varnish.enabled', '||', array('cdn.enabled', 'cdncache.enabled'))); $this->_plugins[] = array('class_name' => 'W3_Plugin_ExtensionsAdmin', 'enable_options' => null); $this->_plugins[] = array('class_name' => 'W3_Plugin_NotificationsAdmin', 'enable_options' => null); } $this->_load_plugins(); register_activation_hook(W3TC_FILE, array(&$this, 'activate')); register_deactivation_hook(W3TC_FILE, array(&$this, 'deactivate')); }
function __construct() { $this->_config = w3_instance('W3_Config'); $this->_caches['objectcache'] = w3_instance('W3_ObjectCache'); if (w3_is_pro($this->_config) || w3_is_enterprise($this->_config)) { if ($this->_config->get_boolean('fragmentcache.enabled')) { $this->_caches['fragmentcache'] = w3_instance('W3_Pro_FragmentCache'); } } }
function generate_menu_array() { $pages = array('w3tc_dashboard' => array(__('Dashboard', 'w3-total-cache'), __('Dashboard', 'w3-total-cache'), 'network_show' => true), 'w3tc_general' => array(__('General Settings', 'w3-total-cache'), __('General Settings', 'w3-total-cache'), 'network_show' => false), 'w3tc_pgcache' => array(__('Page Cache', 'w3-total-cache'), __('Page Cache', 'w3-total-cache'), 'network_show' => false), 'w3tc_minify' => array(__('Minify', 'w3-total-cache'), __('Minify', 'w3-total-cache'), 'network_show' => false), 'w3tc_dbcache' => array(__('Database Cache', 'w3-total-cache'), __('Database Cache', 'w3-total-cache'), 'network_show' => false), 'w3tc_objectcache' => array(__('Object Cache', 'w3-total-cache'), __('Object Cache', 'w3-total-cache'), 'network_show' => false)); if (w3_is_pro($this->_config) || w3_is_enterprise($this->_config)) { $pages['w3tc_fragmentcache'] = array(__('Fragment Cache', 'w3-total-cache'), __('Fragment Cache', 'w3-total-cache'), 'network_show' => false); } $pages = array_merge($pages, array('w3tc_browsercache' => array(__('Browser Cache', 'w3-total-cache'), __('Browser Cache', 'w3-total-cache'), 'network_show' => false), 'w3tc_mobile' => array(__('User Agent Groups', 'w3-total-cache'), __('User Agent Groups', 'w3-total-cache'), 'network_show' => false), 'w3tc_referrer' => array(__('Referrer Groups', 'w3-total-cache'), __('Referrer Groups', 'w3-total-cache'), 'network_show' => false), 'w3tc_cdn' => array(__('Content Delivery Network', 'w3-total-cache'), __('<acronym title="Content Delivery Network">CDN</acronym>', 'w3-total-cache'), 'network_show' => $this->_config->get_boolean('cdn.enabled')), 'w3tc_monitoring' => array(__('Monitoring', 'w3-total-cache'), __('Monitoring', 'w3-total-cache'), 'network_show' => false))); $pages_tail = array('w3tc_faq' => array(__('FAQ', 'w3-total-cache'), __('FAQ', 'w3-total-cache'), 'network_show' => true), 'w3tc_support' => array(__('Support', 'w3-total-cache'), __('<span style="color: red;">Support</span>', 'w3-total-cache'), 'network_show' => true), 'w3tc_install' => array(__('Install', 'w3-total-cache'), __('Install', 'w3-total-cache'), 'network_show' => false), 'w3tc_about' => array(__('About', 'w3-total-cache'), __('About', 'w3-total-cache'), 'network_show' => true)); $pages = apply_filters('w3tc_menu', $pages, $this->_config, $this->_config_admin); $pages = array_merge($pages, $pages_tail); return $pages; }
/** * Page cache tab * * @return void */ function view() { global $wp_rewrite; $feeds = $wp_rewrite->feeds; $feed_key = array_search('feed', $feeds); if ($feed_key !== false) { unset($feeds[$feed_key]); } $default_feed = get_default_feed(); $pgcache_enabled = $this->_config->get_boolean('pgcache.enabled'); $permalink_structure = get_option('permalink_structure'); $varnish_enabled = $this->_config->get_boolean('varnish.enabled'); $cdn_mirror_purge_enabled = w3_is_cdn_mirror($this->_config->get_string('cdn.engine')) && $this->_config->get_string('cdn.engine') != 'mirror' && $this->_config->get_boolean('cdncache.enabled') && w3tc_edge_mode() && w3_is_pro($this->_config) || w3_is_enterprise(); $disable_check_domain = w3_is_multisite() && w3_force_master(); include W3TC_INC_DIR . '/options/pgcache.php'; }
function generate() { $pages = array('w3tc_dashboard' => array(__('Dashboard', 'w3-total-cache'), __('Dashboard', 'w3-total-cache'), 'network_show' => true), 'w3tc_general' => array(__('General Settings', 'w3-total-cache'), __('General Settings', 'w3-total-cache'), 'network_show' => false), 'w3tc_pgcache' => array(__('Page Cache', 'w3-total-cache'), __('Page Cache', 'w3-total-cache'), 'network_show' => false), 'w3tc_minify' => array(__('Minify', 'w3-total-cache'), __('Minify', 'w3-total-cache'), 'network_show' => false), 'w3tc_dbcache' => array(__('Database Cache', 'w3-total-cache'), __('Database Cache', 'w3-total-cache'), 'network_show' => false), 'w3tc_objectcache' => array(__('Object Cache', 'w3-total-cache'), __('Object Cache', 'w3-total-cache'), 'network_show' => false)); if (w3_is_pro($this->_config) || w3_is_enterprise($this->_config)) { $pages['w3tc_fragmentcache'] = array(__('Fragment Cache', 'w3-total-cache'), __('Fragment Cache', 'w3-total-cache'), 'network_show' => false); } $pages = array_merge($pages, array('w3tc_browsercache' => array(__('Browser Cache', 'w3-total-cache'), __('Browser Cache', 'w3-total-cache'), 'network_show' => false), 'w3tc_mobile' => array(__('User Agent Groups', 'w3-total-cache'), __('User Agent Groups', 'w3-total-cache'), 'network_show' => false), 'w3tc_referrer' => array(__('Referrer Groups', 'w3-total-cache'), __('Referrer Groups', 'w3-total-cache'), 'network_show' => false), 'w3tc_cdn' => array(__('Content Delivery Network', 'w3-total-cache'), __('<acronym title="Content Delivery Network">CDN</acronym>', 'w3-total-cache'), 'network_show' => $this->_config->get_boolean('cdn.enabled')), 'w3tc_monitoring' => array(__('Monitoring', 'w3-total-cache'), __('Monitoring', 'w3-total-cache'), 'network_show' => false))); $pages_tail = array('w3tc_faq' => array(__('FAQ', 'w3-total-cache'), __('FAQ', 'w3-total-cache'), 'network_show' => true), 'w3tc_support' => array(__('Support', 'w3-total-cache'), __('<span style="color: red;">Support</span>', 'w3-total-cache'), 'network_show' => true), 'w3tc_install' => array(__('Install', 'w3-total-cache'), __('Install', 'w3-total-cache'), 'network_show' => false), 'w3tc_about' => array(__('About', 'w3-total-cache'), __('About', 'w3-total-cache'), 'network_show' => true)); $pages = apply_filters('w3tc_menu', $pages, $this->_config, $this->_config_admin); $pages = array_merge($pages, $pages_tail); add_menu_page(__('Performance', 'w3-total-cache'), __('Performance', 'w3-total-cache'), 'manage_options', 'w3tc_dashboard', '', 'div'); $submenu_pages = array(); foreach ($pages as $slug => $titles) { if ($this->_config_admin->get_boolean('common.visible_by_master_only') && $titles['network_show'] || (!$this->_config_admin->get_boolean('common.visible_by_master_only') || is_super_admin() && (!w3_force_master() || is_network_admin()))) { $submenu_pages[] = add_submenu_page('w3tc_dashboard', $titles[0] . ' | W3 Total Cache', $titles[1], 'manage_options', $slug, array(&$this, 'options')); } } return $submenu_pages; }
/** * Returns plugin-related environment handlers * @param W3_Config $config * @return array */ private function get_handlers($config) { $a = array(w3_instance('W3_GenericAdminEnvironment'), w3_instance('W3_MinifyAdminEnvironment'), w3_instance('W3_PgCacheAdminEnvironment'), w3_instance('W3_BrowserCacheAdminEnvironment'), w3_instance('W3_ObjectCacheAdminEnvironment'), w3_instance('W3_DbCacheAdminEnvironment'), w3_instance('W3_CdnAdminEnvironment'), w3_instance('W3_NewRelicAdminEnvironment')); if (w3_is_pro($config) || w3_is_enterprise($config)) { array_push($a, w3_instance('W3_Pro_FragmentCacheAdminEnvironment')); } return $a; }
/** * Send support request action * * @return void */ function action_support_request() { w3_require_once(W3TC_LIB_W3_DIR . '/Request.php'); $request_type = W3_Request::get_string('request_type'); $payment = W3_Request::get_boolean('payment'); $request_id = W3_Request::get_string('request_id'); $url = W3_Request::get_string('url'); $name = W3_Request::get_string('name'); $email = W3_Request::get_string('email'); $twitter = W3_Request::get_string('twitter'); $phone = W3_Request::get_string('phone'); $subject = W3_Request::get_string('subject'); $description = W3_Request::get_string('description'); $templates = W3_Request::get_array('templates'); $forum_url = W3_Request::get_string('forum_url'); $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'); $subscribe_releases = W3_Request::get_string('subscribe_releases'); $subscribe_customer = W3_Request::get_string('subscribe_customer'); $params = array('request_type' => $request_type, 'payment' => $payment, 'url' => $url, 'name' => $name, 'email' => $email, 'twitter' => $twitter, 'phone' => $phone, 'subject' => $subject, 'description' => $description, 'forum_url' => $forum_url, 'wp_login' => $wp_login, 'wp_password' => $wp_password, 'ftp_host' => $ftp_host, 'ftp_login' => $ftp_login, 'ftp_password' => $ftp_password, 'subscribe_releases' => $subscribe_releases, 'subscribe_customer' => $subscribe_customer); $post = $params; foreach ($templates as $template_index => $template) { $template_key = sprintf('templates[%d]', $template_index); $params[$template_key] = $template; } if (!isset($this->_request_types[$request_type])) { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_type')), false); } $required = array('bug_report' => 'url,name,email,subject,description', 'new_feature' => 'url,name,email,subject,description', 'email_support' => 'url,name,email,subject,description', 'phone_support' => 'url,name,email,subject,description,phone', 'plugin_config' => 'url,name,email,subject,description,wp_login,wp_password', 'theme_config' => 'url,name,email,subject,description,wp_login,wp_password,ftp_host,ftp_login,ftp_password', 'linux_config' => 'url,name,email,subject,description,wp_login,wp_password,ftp_host,ftp_login,ftp_password'); if (strstr($required[$request_type], 'url') !== false && $url == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_url')), false); } if (strstr($required[$request_type], 'name') !== false && $name == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_name')), false); } if (strstr($required[$request_type], 'email') !== false && !preg_match('~^[a-z0-9_\\-\\.]+@[a-z0-9-\\.]+\\.[a-z]{2,5}$~', $email)) { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_email')), false); } if (strstr($required[$request_type], 'phone') !== false && !preg_match('~^[0-9\\-\\.\\ \\(\\)\\+]+$~', $phone)) { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_phone')), false); } if (strstr($required[$request_type], 'subject') !== false && $subject == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_subject')), false); } if (strstr($required[$request_type], 'description') !== false && $description == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_description')), false); } if (strstr($required[$request_type], 'wp_login') !== false && $wp_login == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_wp_login')), false); } if (strstr($required[$request_type], 'wp_password') !== false && $wp_password == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_wp_password')), false); } if (strstr($required[$request_type], 'ftp_host') !== false && $ftp_host == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_host')), false); } if (strstr($required[$request_type], 'ftp_login') !== false && $ftp_login == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_login')), false); } if (strstr($required[$request_type], 'ftp_password') !== false && $ftp_password == '') { w3_admin_redirect(array_merge($params, array('w3tc_error' => 'support_request_ftp_password')), false); } /** * Add attachments */ $attachments = array(); $attach_files = array(w3_get_wp_config_path(), w3_cache_blog_dir('log') . '/minify.log', w3_get_pgcache_rules_core_path(), w3_get_pgcache_rules_cache_path(), w3_get_browsercache_rules_cache_path(), w3_get_browsercache_rules_no404wp_path(), w3_get_minify_rules_core_path(), w3_get_minify_rules_cache_path()); /** * Attach config files */ if ($handle = opendir(W3TC_CONFIG_DIR)) { while (($entry = @readdir($handle)) !== false) { if ($entry == '.' || $entry == '..' || $entry == 'index.html') { continue; } $attachments[] = W3TC_CONFIG_DIR . '/' . $entry; } closedir($handle); } foreach ($attach_files as $attach_file) { if ($attach_file && file_exists($attach_file) && !in_array($attach_file, $attachments)) { $attachments[] = $attach_file; } } /** * Attach server info */ $server_info = print_r($this->get_server_info(), true); $server_info = str_replace("\n", "\r\n", $server_info); $server_info_path = W3TC_CACHE_TMP_DIR . '/server_info.txt'; if (@file_put_contents($server_info_path, $server_info)) { $attachments[] = $server_info_path; } /** * Attach phpinfo */ ob_start(); phpinfo(); $php_info = ob_get_contents(); ob_end_clean(); $php_info_path = W3TC_CACHE_TMP_DIR . '/php_info.html'; if (@file_put_contents($php_info_path, $php_info)) { $attachments[] = $php_info_path; } /** * Attach self-test */ ob_start(); $this->action_self_test(); $self_test = ob_get_contents(); ob_end_clean(); $self_test_path = W3TC_CACHE_TMP_DIR . '/self_test.html'; if (@file_put_contents($self_test_path, $self_test)) { $attachments[] = $self_test_path; } /** * Attach templates */ foreach ($templates as $template) { if (!empty($template)) { $attachments[] = $template; } } /** * Attach other files */ if (!empty($_FILES['files'])) { $files = (array) $_FILES['files']; for ($i = 0, $l = count($files); $i < $l; $i++) { if (isset($files['tmp_name'][$i]) && isset($files['name'][$i]) && isset($files['error'][$i]) && $files['error'][$i] == UPLOAD_ERR_OK) { $path = W3TC_CACHE_TMP_DIR . '/' . $files['name'][$i]; if (@move_uploaded_file($files['tmp_name'][$i], $path)) { $attachments[] = $path; } } } } $data = array(); if (!empty($wp_login) && !empty($wp_password)) { $data['WP Admin login'] = $wp_login; $data['WP Admin password'] = $wp_password; } if (!empty($ftp_host) && !empty($ftp_login) && !empty($ftp_password)) { $data['SSH / FTP host'] = $ftp_host; $data['SSH / FTP login'] = $ftp_login; $data['SSH / FTP password'] = $ftp_password; } /** * Store request data for future access */ if (count($data)) { $hash = md5(microtime()); $request_data = get_option('w3tc_request_data', array()); $request_data[$hash] = $data; update_option('w3tc_request_data', $request_data); $request_data_url = sprintf('%s/w3tc_request_data/%s', w3_get_home_url(), $hash); } else { $request_data_url = ''; } $nonce = wp_create_nonce('w3tc_support_request'); if (is_network_admin()) { update_site_option('w3tc_support_request', $nonce); } else { update_option('w3tc_support_request', $nonce); } $file_access = WP_PLUGIN_URL . '/' . dirname(W3TC_FILE) . '/pub/files.php'; if (w3_get_domain(w3_get_home_url()) != w3_get_domain(w3_get_site_url())) { $file_access = str_replace(w3_get_domain(w3_get_home_url()), w3_get_domain(w3_get_site_url()), $file_access); } $post['file_access'] = $file_access; $post['nonce'] = $nonce; $post['request_data_url'] = $request_data_url; $post['ip'] = $_SERVER['REMOTE_ADDR']; $post['user_agent'] = $_SERVER['HTTP_USER_AGENT']; $post['version'] = W3TC_VERSION; $post['plugin'] = 'W3 Total Cache'; $post['request_id'] = $request_id; $license_level = 'community'; if (w3_is_pro($this->_config)) { $license_level = 'pro'; } elseif (w3_is_enterprise($this->_config)) { $license_level = 'enterprise'; } $post['license_level'] = $license_level; $unset = array('wp_login', 'wp_password', 'ftp_host', 'ftp_login', 'ftp_password'); foreach ($unset as $key) { unset($post[$key]); } foreach ($attachments as $attachment) { if (is_network_admin()) { update_site_option('attachment_' . md5($attachment), $attachment); } else { update_option('attachment_' . md5($attachment), $attachment); } } $post = array_merge($post, array('files' => $attachments)); if (defined('W3_SUPPORT_DEBUG') && W3_SUPPORT_DEBUG) { $data = sprintf("[%s] Post support request\n", date('r')); foreach ($post as $key => $value) { $data .= sprintf("%s => %s\n", $key, is_array($value) ? implode(',', $value) : $value); } $filename = w3_cache_blog_dir('log') . '/support.log'; if (!is_dir(dirname($filename))) { w3_mkdir_from(dirname($filename), W3TC_CACHE_DIR); } @file_put_contents($filename, $data, FILE_APPEND); } $response = wp_remote_post(W3TC_SUPPORT_REQUEST_URL, array('body' => $post, 'timeout' => $this->_config->get_integer('timelimit.email_send'))); if (defined('W3_SUPPORT_DEBUG') && W3_SUPPORT_DEBUG) { $filename = w3_cache_blog_dir('log') . '/support.log'; $data = sprintf("[%s] Post response \n%s\n", date('r'), print_r($response, true)); @file_put_contents($filename, $data, FILE_APPEND); } if (!is_wp_error($response)) { $result = $response['response']['code'] == 200 && $response['body'] == 'Ok'; } else { $result = false; } /** * Remove temporary files */ foreach ($attachments as $attachment) { if (strstr($attachment, W3TC_CACHE_TMP_DIR) !== false) { @unlink($attachment); } if (is_network_admin()) { delete_site_option('attachment_' . md5($attachment)); } else { delete_option('attachment_' . md5($attachment)); } } if (is_network_admin()) { delete_site_option('w3tc_support_request'); } else { delete_option('w3tc_support_request'); } if ($result) { w3_admin_redirect(array('tab' => 'general', 'w3tc_note' => 'support_request'), false); } else { w3_admin_redirect(array_merge($params, array('request_type' => $request_type, 'w3tc_error' => 'support_request')), false); } }
/** * Output buffering callback * * @param string $buffer * @return string */ function ob_callback($buffer) { global $wpdb; if ($buffer != '') { if (w3_is_database_error($buffer)) { status_header(503); } else { if (w3_can_print_comment($buffer)) { /** * Add footer comment */ $date = date_i18n('Y-m-d H:i:s'); $host = !empty($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost'; if (w3_is_preview_mode()) { $buffer .= "\r\n<!-- W3 Total Cache used in preview mode -->"; } if ($this->_config->get_string('common.support') != '' || $this->_config->get_boolean('common.tweeted')) { $buffer .= sprintf("\r\n<!-- Served from: %s @ %s by W3 Total Cache -->", w3_escape_comment($host), $date); } else { $strings = array(); if ($this->_config->get_boolean('minify.enabled') && !$this->_config->get_boolean('minify.debug')) { $w3_plugin_minify = w3_instance('W3_Plugin_Minify'); $strings[] = sprintf(__('Minified using %s%s', 'w3-total-cache'), w3_get_engine_name($this->_config->get_string('minify.engine')), $w3_plugin_minify->minify_reject_reason != '' ? sprintf(' (%s)', $w3_plugin_minify->minify_reject_reason) : ''); } if ($this->_config->get_boolean('pgcache.enabled') && !$this->_config->get_boolean('pgcache.debug')) { $w3_pgcache = w3_instance('W3_PgCache'); $strings[] = sprintf(__('Page Caching using %s%s', 'w3-total-cache'), w3_get_engine_name($this->_config->get_string('pgcache.engine')), $w3_pgcache->cache_reject_reason != '' ? sprintf(' (%s)', $w3_pgcache->cache_reject_reason) : ''); } if ($this->_config->get_boolean('dbcache.enabled') && !$this->_config->get_boolean('dbcache.debug')) { /** * @var W3_DbCache $db */ $db = w3_instance('W3_DbCache'); $append = ($reason = $db->get_reject_reason()) ? sprintf(' (%s)', $reason) : ''; if ($db->query_hits) { $strings[] = sprintf(__('Database Caching %d/%d queries in %.3f seconds using %s%s', 'w3-total-cache'), $db->query_hits, $db->query_total, $db->time_total, w3_get_engine_name($this->_config->get_string('dbcache.engine')), $append); } else { $strings[] = sprintf(__('Database Caching using %s%s', 'w3-total-cache'), w3_get_engine_name($this->_config->get_string('dbcache.engine')), $append); } } if (w3_is_dbcluster()) { $db_cluster = w3_instance('W3_Enterprise_DbCluster'); $strings[] = $db_cluster->status_message(); } if ($this->_config->get_boolean('objectcache.enabled') && !$this->_config->get_boolean('objectcache.debug')) { /** * @var W3_ObjectCache $w3_objectcache */ $w3_objectcache = w3_instance('W3_ObjectCache'); $append = ($reason = $w3_objectcache->get_reject_reason()) ? sprintf(' (%s)', $reason) : ''; $strings[] = sprintf(__('Object Caching %d/%d objects using %s%s', 'w3-total-cache'), $w3_objectcache->cache_hits, $w3_objectcache->cache_total, w3_get_engine_name($this->_config->get_string('objectcache.engine')), $append); } if (w3_is_pro($this->_config) || w3_is_enterprise($this->_config)) { if ($this->_config->get_boolean('fragmentcache.enabled') && !$this->_config->get_boolean('fragmentcache.debug')) { $w3_fragmentcache = w3_instance('W3_Pro_FragmentCache'); $append = $w3_fragmentcache->cache_reject_reason != '' ? sprintf(' (%s)', $w3_fragmentcache->cache_reject_reason) : ''; $strings[] = sprintf(__('Fragment Caching %d/%d fragments using %s%s', 'w3-total-cache'), $w3_fragmentcache->cache_hits, $w3_fragmentcache->cache_total, w3_get_engine_name($this->_config->get_string('fragmentcache.engine')), $append); } } if ($this->_config->get_boolean('cdn.enabled') && !$this->_config->get_boolean('cdn.debug')) { $w3_plugin_cdn = w3_instance('W3_Plugin_Cdn'); $w3_plugin_cdncommon = w3_instance('W3_Plugin_CdnCommon'); $cdn = $w3_plugin_cdncommon->get_cdn(); $via = $cdn->get_via(); $strings[] = sprintf(__('Content Delivery Network via %s%s', 'w3-total-cache'), $via ? $via : 'N/A', $w3_plugin_cdn->cdn_reject_reason != '' ? sprintf(' (%s)', $w3_plugin_cdn->cdn_reject_reason) : ''); } if ($this->_config->get_boolean('newrelic.enabled')) { $w3_newrelic = w3_instance('W3_Plugin_NewRelic'); $append = $w3_newrelic->newrelic_reject_reason != '' ? sprintf(' (%s)', $w3_newrelic->newrelic_reject_reason) : ''; $strings[] = sprintf(__("Application Monitoring using New Relic%s", 'w3-total-cache'), $append); } $buffer .= "\r\n<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/\r\n"; if (count($strings)) { $buffer .= "\r\n" . implode("\r\n", $strings) . "\r\n"; } $buffer .= sprintf("\r\n Served from: %s @ %s by W3 Total Cache -->", w3_escape_comment($host), $date); } if ($this->is_debugging()) { if ($this->_config->get_boolean('dbcache.enabled') && $this->_config->get_boolean('dbcache.debug')) { $db = w3_instance('W3_DbCache'); $buffer .= "\r\n\r\n" . $db->_get_debug_info(); } if ($this->_config->get_boolean('objectcache.enabled') && $this->_config->get_boolean('objectcache.debug')) { $w3_objectcache = w3_instance('W3_ObjectCache'); $buffer .= "\r\n\r\n" . $w3_objectcache->_get_debug_info(); } if (w3_is_pro($this->_config) || w3_is_enterprise($this->_config)) { if ($this->_config->get_boolean('fragmentcache.enabled') && $this->_config->get_boolean('fragmentcache.debug')) { $w3_fragmentcache = w3_instance('W3_Pro_FragmentCache'); $buffer .= "\r\n\r\n" . $w3_fragmentcache->_get_debug_info(); } } } } $buffer = w3tc_do_ob_callbacks(array('minify', 'newrelic', 'cdn', 'browsercache', 'pagecache'), $buffer); } } return $buffer; }
/** * @param $extensions * @param W3_Config $config * @return mixed */ function extension($extensions, $config) { $fc_enabled = (w3_is_pro($config) || w3_is_enterprise($config)) && $config->get_boolean('fragmentcache.enabled'); $activation_enabled = $fc_enabled && defined('PARENT_THEME_NAME') && PARENT_THEME_NAME == 'Genesis' && defined('PARENT_THEME_VERSION') && version_compare(PARENT_THEME_VERSION, '1.9.0') >= 0; $message = array(); if (is_network_admin()) { w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/themes.php'); $themes = w3tc_get_themes(); $exists = false; foreach ($themes as $theme) { if (strtolower($theme->Template) == 'genesis') { $exists = true; } } if (!$exists) { $message[] = 'Genesis Framework'; } } elseif (!(defined('PARENT_THEME_NAME') && PARENT_THEME_NAME == 'Genesis')) { $message[] = 'Genesis Framework version >= 1.9.0'; } if (!$fc_enabled) { $message[] = 'Fragment Cache (W3 Total Cache Pro)'; } $extensions['genesis.theme'] = array('name' => 'Genesis Framework', 'author' => 'W3 EDGE', 'description' => 'Provides 30-60% improvement in page generation time for the Genesis Framework by Copyblogger Media.', 'author uri' => 'http://www.w3-edge.com/', 'extension uri' => 'http://www.w3-edge.com/', 'extension id' => 'genesis.theme', 'version' => '0.1', 'enabled' => $activation_enabled, 'requirements' => implode(', ', $message), 'path' => 'w3-total-cache/extensions/Genesis.php'); return $extensions; }
<?php $this->checkbox_debug('cdn.debug'); ?> <?php _e('<acronym title="Content Delivery Network">CDN</acronym>', 'w3-total-cache'); ?> </label><br /> <?php $this->checkbox_debug('varnish.debug'); ?> <?php _e('Reverse Proxy', 'w3-total-cache'); ?> </label><br /> <?php if (w3_is_enterprise()) { ?> <?php $this->checkbox_debug('cluster.messagebus.debug'); ?> <?php _e('Amazon <acronym title="Simple Notification Service">SNS</acronym>', 'w3-total-cache'); ?> </label><br /> <?php } ?> <span class="description"><?php _e('If selected, detailed caching information will be appear at the end of each page in a <acronym title="Hypertext Markup Language">HTML</acronym> comment. View a page\'s source code to review.', 'w3-total-cache'); ?> </span>
/** * @var W3_Config $config * @return string */ function w3_w3tc_release_version($config = null) { if (w3_is_enterprise($config)) { return 'enterprise'; } if (w3_is_pro($config) && w3tc_is_pro_dev_mode()) { return 'pro development'; } if (w3_is_pro($config)) { return 'pro'; } return 'community'; }
/** * Admin bar menu * * @return void */ function admin_bar_menu() { global $wp_admin_bar; if (current_user_can('manage_options')) { /** * @var $modules W3_ModuleStatus */ $modules = w3_instance('W3_ModuleStatus'); $can_empty_memcache = $modules->can_empty_memcache(); $can_empty_opcode = $modules->can_empty_opcode(); $can_empty_file = $modules->can_empty_file(); $can_empty_varnish = $modules->can_empty_varnish(); $browsercache_update_media_qs = $this->_config->get_boolean('browsercache.cssjs.replace') || $this->_config->get_boolean('browsercache.other.replace'); //$cdn_enabled = $modules->is_enabled('cdn'); $cdn_engine = $modules->get_module_engine('cdn'); $cdn_mirror = w3_is_cdn_mirror($cdn_engine); $menu_items = array(array('id' => 'w3tc', 'title' => 'Performance', 'href' => admin_url('admin.php?page=w3tc_dashboard'))); if ($modules->is_enabled('pgcache') && w3_detect_post_id() && (!defined('DOING_AJAX') || !DOING_AJAX)) { $menu_items[] = array('id' => 'w3tc-pgcache-purge-post', 'parent' => 'w3tc', 'title' => 'Purge From Cache', 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_pgcache_purge_post&post_id=' . $this->_detect_post_id()), 'w3tc')); } if ($can_empty_file && ($can_empty_opcode || $can_empty_memcache)) { $menu_items[] = array('id' => 'w3tc-flush-file', 'parent' => 'w3tc-empty-caches', 'title' => 'Empty Disc Cache(s)', 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_file'), 'w3tc')); } if ($can_empty_opcode && ($can_empty_file || $can_empty_memcache)) { $menu_items[] = array('id' => 'w3tc-flush-opcode', 'parent' => 'w3tc-empty-caches', 'title' => 'Empty Opcode Cache', 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_opcode'), 'w3tc')); } if ($can_empty_memcache && ($can_empty_file || $can_empty_opcode)) { $menu_items[] = array('id' => 'w3tc-flush-memcached', 'parent' => 'w3tc-empty-caches', 'title' => 'Empty Memcached Cache(s)', 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_memcached'), 'w3tc')); } if ($modules->is_enabled('browsercache') && $browsercache_update_media_qs) { $menu_items[] = array('id' => 'w3tc-update-media-qs', 'parent' => 'w3tc', 'title' => 'Update Media Query String', 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_browser_cache'), 'w3tc')); } if ($modules->plugin_is_enabled()) { $menu_items[] = array('id' => 'w3tc-empty-caches', 'parent' => 'w3tc', 'title' => 'Empty All Caches', 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_all'), 'w3tc')); $menu_items[] = array('id' => 'w3tc-modules', 'parent' => 'w3tc', 'title' => 'Empty Modules'); } if ($modules->is_enabled('pgcache')) { $menu_items[] = array('id' => 'w3tc-flush-pgcache', 'parent' => 'w3tc-modules', 'title' => 'Empty Page Cache', 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_pgcache'), 'w3tc')); } if ($modules->is_enabled('minify')) { $menu_items[] = array('id' => 'w3tc-flush-minify', 'parent' => 'w3tc-modules', 'title' => 'Empty Minify Cache', 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_minify'), 'w3tc')); } if ($modules->is_enabled('dbcache')) { $menu_items[] = array('id' => 'w3tc-flush-dbcache', 'parent' => 'w3tc-modules', 'title' => 'Empty Database Cache', 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_dbcache'), 'w3tc')); } if ($modules->is_enabled('objectcache')) { $menu_items[] = array('id' => 'w3tc-flush-objectcache', 'parent' => 'w3tc-modules', 'title' => 'Empty Object Cache', 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_objectcache'), 'w3tc')); } if (w3_is_pro() || w3_is_enterprise()) { if ($modules->is_enabled('fragmentcache')) { $menu_items[] = array('id' => 'w3tc-flush-fragmentcache', 'parent' => 'w3tc-modules', 'title' => 'Empty Fragment Cache', 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_fragmentcache'), 'w3tc')); } } if ($modules->is_enabled('varnish')) { $menu_items[] = array('id' => 'w3tc-flush-varnish', 'parent' => 'w3tc-modules', 'title' => 'Purge Varnish Cache', 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_dashboard&w3tc_flush_varnish'), 'w3tc')); } if ($modules->is_enabled('cdn')) { if (w3_can_cdn_purge($cdn_engine)) { $menu_items[] = array('id' => 'w3tc-cdn-purge', 'parent' => 'w3tc', 'title' => 'Purge CDN', 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_cdn&w3tc_cdn_purge'), 'w3tc'), 'meta' => array('onclick' => "w3tc_popupadmin_bar(this.href); return false")); } if (w3_cdn_can_purge_all($cdn_engine)) { $menu_items[] = array('id' => 'w3tc-cdn-purge-full', 'parent' => 'w3tc', 'title' => 'Purge CDN Completely', 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_cdn&w3tc_flush_cdn'), 'w3tc')); } if (!$cdn_mirror) { $menu_items[] = array('id' => 'w3tc-cdn-queue', 'parent' => 'w3tc', 'title' => 'Unsuccessfull file transfers', 'href' => wp_nonce_url(admin_url('admin.php?page=w3tc_cdn&w3tc_cdn_queue'), 'w3tc'), 'meta' => array('onclick' => "w3tc_popupadmin_bar(this.href); return false")); } } $menu_items = array_merge($menu_items, array(array('id' => 'w3tc-faq', 'parent' => 'w3tc', 'title' => 'FAQ', 'href' => admin_url('admin.php?page=w3tc_faq')), array('id' => 'w3tc-support', 'parent' => 'w3tc', 'title' => '<span style="color: red; background: none;">Support</span>', 'href' => admin_url('admin.php?page=w3tc_support')))); if ($modules->is_enabled('cloudflare')) { $menu_items = array_merge($menu_items, array(array('id' => 'cloudflare', 'title' => 'CloudFlare', 'href' => 'https://www.cloudflare.com'), array('id' => 'cloudflare-my-websites', 'parent' => 'cloudflare', 'title' => 'My Websites', 'href' => 'https://www.cloudflare.com/my-websites.html'), array('id' => 'cloudflare-analytics', 'parent' => 'cloudflare', 'title' => 'Analytics', 'href' => 'https://www.cloudflare.com/analytics.html'), array('id' => 'cloudflare-account', 'parent' => 'cloudflare', 'title' => 'Account', 'href' => 'https://www.cloudflare.com/my-account.html'))); } foreach ($menu_items as $menu_item) { $wp_admin_bar->add_menu($menu_item); } } }
<th colspan="2"> <?php $this->checkbox('cdn.import.external'); ?> <?php w3_e_config_label('cdn.import.external'); ?> </label><br /> <span class="description"><?php _e('Download attachments hosted elsewhere into your media library and deliver them via <acronym title="Content Delivery Network">CDN</acronym>.', 'w3-total-cache'); ?> </span> </th> </tr> <?php if (w3tc_edge_mode() && w3_is_pro($this->_config) || w3_is_enterprise()) { ?> <tr> <th colspan="2"> <?php $this->checkbox('cdncache.enabled', !$cdn_supports_full_page_mirroring); ?> <?php w3_e_config_label('cdncache.enabled'); ?> </label><br/> <span class="description"> <?php echo sprintf(__('Enabling this option allows the <acronym title="Content Delivery Network">CDN</acronym> to handle requests for unauthenticated pages thereby reducing the traffic load on the origin server(s). Purge policies are set on the <a href="%s">Page Cache settings</a> tab.', 'w3-total-cache'), network_admin_url('admin.php?page=w3tc_pgcache#purge_policy')); ?> </span>
/** * Save support us action * * @return void */ function action_config_save_support_us() { $support = W3_Request::get_string('support'); $tweeted = W3_Request::get_boolean('tweeted'); $signmeup = W3_Request::get_boolean('signmeup'); $this->_config->set('common.support', $support); $this->_config->set('common.tweeted', $tweeted); if ($signmeup) { if (w3_is_pro($this->_config)) { $license = 'pro'; } elseif (w3_is_enterprise()) { $license = 'enterprise'; } else { $license = 'community'; } $email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL); wp_remote_post(W3TC_MAILLINGLIST_SIGNUP_URL, array('body' => array('email' => $email, 'license' => $license))); } $this->_config->save(); w3_instance('W3_AdminLinks')->link_update($this->_config); w3_admin_redirect(array('w3tc_note' => 'config_save')); }
/** * Admin menu * * @return void */ function admin_menu() { $pages = array('w3tc_dashboard' => array(__('Dashboard', 'w3-total-cache'), __('Dashboard', 'w3-total-cache'), 'network_show' => true), 'w3tc_general' => array(__('General Settings', 'w3-total-cache'), __('General Settings', 'w3-total-cache'), 'network_show' => false), 'w3tc_pgcache' => array(__('Page Cache', 'w3-total-cache'), __('Page Cache', 'w3-total-cache'), 'network_show' => false), 'w3tc_minify' => array(__('Minify', 'w3-total-cache'), __('Minify', 'w3-total-cache'), 'network_show' => false), 'w3tc_dbcache' => array(__('Database Cache', 'w3-total-cache'), __('Database Cache', 'w3-total-cache'), 'network_show' => false), 'w3tc_objectcache' => array(__('Object Cache', 'w3-total-cache'), __('Object Cache', 'w3-total-cache'), 'network_show' => false)); if (w3_is_pro() || w3_is_enterprise()) { $pages['w3tc_fragmentcache'] = array(__('Fragment Cache', 'w3-total-cache'), __('Fragment Cache', 'w3-total-cache'), 'network_show' => false); } $pages = array_merge($pages, array('w3tc_browsercache' => array(__('Browser Cache', 'w3-total-cache'), __('Browser Cache', 'w3-total-cache'), 'network_show' => false), 'w3tc_mobile' => array(__('User Agent Groups', 'w3-total-cache'), __('User Agent Groups', 'w3-total-cache'), 'network_show' => false), 'w3tc_referrer' => array(__('Referrer Groups', 'w3-total-cache'), __('Referrer Groups', 'w3-total-cache'), 'network_show' => false), 'w3tc_cdn' => array(__('Content Delivery Network', 'w3-total-cache'), __('<acronym title="Content Delivery Network">CDN</acronym>', 'w3-total-cache'), 'network_show' => $this->_config->get_boolean('cdn.enabled')), 'w3tc_monitoring' => array(__('Monitoring', 'w3-total-cache'), __('Monitoring', 'w3-total-cache'), 'network_show' => false), 'w3tc_faq' => array(__('FAQ', 'w3-total-cache'), __('FAQ', 'w3-total-cache'), 'network_show' => true), 'w3tc_support' => array(__('Support', 'w3-total-cache'), __('<span style="color: red;">Support</span>', 'w3-total-cache'), 'network_show' => true), 'w3tc_install' => array(__('Install', 'w3-total-cache'), __('Install', 'w3-total-cache'), 'network_show' => false), 'w3tc_about' => array(__('About', 'w3-total-cache'), __('About', 'w3-total-cache'), 'network_show' => true))); add_menu_page(__('Performance', 'w3-total-cache'), __('Performance', 'w3-total-cache'), 'manage_options', 'w3tc_dashboard', '', 'div'); $submenu_pages = array(); foreach ($pages as $slug => $titles) { if ($this->_config_admin->get_boolean('common.visible_by_master_only') && $titles['network_show'] || (!$this->_config_admin->get_boolean('common.visible_by_master_only') || is_super_admin() && (!w3_force_master() || is_network_admin()))) { $submenu_pages[] = add_submenu_page('w3tc_dashboard', $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')); } global $pagenow; if ($pagenow == 'plugins.php') { add_action('admin_print_scripts', array($this, 'load_plugins_page_js')); add_action('admin_print_styles', array($this, 'print_plugins_page_css')); } /** * Only admin can see W3TC notices and errors */ add_action('admin_notices', array(&$this, 'admin_notices')); add_action('network_admin_notices', array(&$this, 'admin_notices')); } }
/** * @return string */ function w3_w3tc_release_version($config = null) { if (w3_is_enterprise($config)) { return 'enterprise'; } if (w3_is_pro($config)) { return 'pro'; } return 'community'; }