/** * Returns debug info * * @return string */ function _get_debug_info() { $debug_info = "<!-- W3 Total Cache: Db cache debug info:\r\n"; $debug_info .= sprintf("%s%s\r\n", str_pad('Engine: ', 20), w3_get_engine_name($this->_config->get_string('dbcache.engine'))); $debug_info .= sprintf("%s%d\r\n", str_pad('Total queries: ', 20), $this->query_total); $debug_info .= sprintf("%s%d\r\n", str_pad('Cached queries: ', 20), $this->query_hits); $debug_info .= sprintf("%s%.4f\r\n", str_pad('Total query time: ', 20), $this->time_total); if (count($this->query_stats)) { $debug_info .= "SQL info:\r\n"; $debug_info .= sprintf("%s | %s | %s | % s | %s | %s\r\n", str_pad('#', 5, ' ', STR_PAD_LEFT), str_pad('Time (s)', 8, ' ', STR_PAD_LEFT), str_pad('Caching (Reject reason)', 30, ' ', STR_PAD_BOTH), str_pad('Status', 10, ' ', STR_PAD_BOTH), str_pad('Data size (b)', 13, ' ', STR_PAD_LEFT), 'Query'); foreach ($this->query_stats as $index => $query) { $debug_info .= sprintf("%s | %s | %s | %s | %s | %s\r\n", str_pad($index + 1, 5, ' ', STR_PAD_LEFT), str_pad(round($query['time_total'], 4), 8, ' ', STR_PAD_LEFT), str_pad($query['caching'] ? 'enabled' : sprintf('disabled (%s)', $query['reason']), 30, ' ', STR_PAD_BOTH), str_pad($query['cached'] ? 'cached' : 'not cached', 10, ' ', STR_PAD_BOTH), str_pad($query['data_size'], 13, ' ', STR_PAD_LEFT), w3_escape_comment(trim($query['query']))); } } $debug_info .= '-->'; return $debug_info; }
/** * Returns debug info * * @return string */ function get_debug_info() { $debug_info = "<!-- W3 Total Cache: Minify debug info:\r\n"; $debug_info .= sprintf("%s%s\r\n", str_pad('Engine: ', 20), w3_get_engine_name($this->_config->get_string('minify.engine'))); $debug_info .= sprintf("%s%s\r\n", str_pad('Theme: ', 20), $this->get_theme()); $debug_info .= sprintf("%s%s\r\n", str_pad('Template: ', 20), $this->get_template()); if ($this->minify_reject_reason) { $debug_info .= sprintf("%s%s\r\n", str_pad('Reject reason: ', 20), $this->minify_reject_reason); } if ($this->error) { $debug_info .= sprintf("%s%s\r\n", str_pad('Errors: ', 20), $this->error); } if (count($this->replaced_styles)) { $debug_info .= "\r\nReplaced CSS files:\r\n"; foreach ($this->replaced_styles as $index => $file) { $debug_info .= sprintf("%d. %s\r\n", $index + 1, w3_escape_comment($file)); } } if (count($this->replaced_scripts)) { $debug_info .= "\r\nReplaced JavaScript files:\r\n"; foreach ($this->replaced_scripts as $index => $file) { $debug_info .= sprintf("%d. %s\r\n", $index + 1, w3_escape_comment($file)); } } $debug_info .= '-->'; return $debug_info; }
/** * 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; }
/** * Returns debug info * * @param boolean $cache * @param string $reason * @param boolean $status * @param double $time * @return string */ function _get_debug_info($cache, $reason, $status, $time) { $engine = $this->_config->get_string('pgcache.engine'); $debug_info = "<!-- W3 Total Cache: Page cache debug info:\r\n"; $debug_info .= sprintf("%s%s\r\n", str_pad('Engine: ', 20), w3_get_engine_name($engine)); $debug_info .= sprintf("%s%s\r\n", str_pad('Cache key: ', 20), $this->_page_key); $debug_info .= sprintf("%s%s\r\n", str_pad('Caching: ', 20), $cache ? 'enabled' : 'disabled'); if (!$cache) { $debug_info .= sprintf("%s%s\r\n", str_pad('Reject reason: ', 20), $reason); } if ($engine != 'file_generic') { $debug_info .= sprintf("%s%s\r\n", str_pad('Status: ', 20), $status ? 'cached' : 'not cached'); } $debug_info .= sprintf("%s%.3fs\r\n", str_pad('Creation Time: ', 20), $time); $headers = $this->_get_response_headers(); if (count($headers)) { $debug_info .= "Header info:\r\n"; foreach ($headers as $header_name => $header_value) { $debug_info .= sprintf("%s%s\r\n", str_pad($header_name . ': ', 20), w3_escape_comment($header_value)); } } $debug_info .= '-->'; return $debug_info; }
/** * Returns debug info * * @return string */ function get_debug_info() { $debug_info = "<!-- W3 Total Cache: CDN debug info:\r\n"; $debug_info .= sprintf("%s%s\r\n", str_pad('Engine: ', 20), $this->_config->get_string('cdn.engine')); if ($this->cdn_reject_reason) { $debug_info .= sprintf("%s%s\r\n", str_pad('Reject reason: ', 20), $this->cdn_reject_reason); } if (count($this->replaced_urls)) { $debug_info .= "\r\nReplaced URLs:\r\n"; foreach ($this->replaced_urls as $old_url => $new_url) { $debug_info .= sprintf("%s => %s\r\n", w3_escape_comment($old_url), w3_escape_comment($new_url)); } } $debug_info .= '-->'; return $debug_info; }
/** * Output buffering callback * * @param string $buffer * @return string */ function ob_callback(&$buffer) { global $wpdb; if ($buffer != '' && w3_is_xml($buffer)) { if (w3_is_database_error($buffer)) { @header('HTTP/1.1 503 Service Unavailable'); } else { /** * Replace links for preview mode */ if (w3_is_preview_mode() && isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT'] != W3TC_POWERED_BY) { $domain_url_regexp = w3_get_domain_url_regexp(); $buffer = preg_replace_callback('~(href|src|action)=([\'"])(' . $domain_url_regexp . ')?(/[^\'"]*)~', array(&$this, 'link_replace_callback'), $buffer); } /** * Add footer comment */ $date = date_i18n('Y-m-d H:i:s'); $host = !empty($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost'; if ($this->is_supported()) { $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')) { require_once W3TC_LIB_W3_DIR . '/Plugin/Minify.php'; $w3_plugin_minify =& W3_Plugin_Minify::instance(); $strings[] = sprintf("Minified using %s%s", 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')) { require_once W3TC_LIB_W3_DIR . '/PgCache.php'; $w3_pgcache =& W3_PgCache::instance(); $strings[] = sprintf("Page Caching using %s%s", 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') && is_a($wpdb, 'W3_Db')) { $append = is_user_logged_in() ? ' (user is logged in)' : ''; if ($wpdb->query_hits) { $strings[] = sprintf("Database Caching %d/%d queries in %.3f seconds using %s%s", $wpdb->query_hits, $wpdb->query_total, $wpdb->time_total, w3_get_engine_name($this->_config->get_string('dbcache.engine')), $append); } else { $strings[] = sprintf("Database Caching using %s%s", w3_get_engine_name($this->_config->get_string('dbcache.engine')), $append); } } if ($this->_config->get_boolean('objectcache.enabled') && !$this->_config->get_boolean('objectcache.debug')) { require_once W3TC_LIB_W3_DIR . '/ObjectCache.php'; $w3_objectcache =& W3_ObjectCache::instance(); $strings[] = sprintf("Object Caching %d/%d objects using %s", $w3_objectcache->cache_hits, $w3_objectcache->cache_total, w3_get_engine_name($this->_config->get_string('objectcache.engine'))); } if ($this->_config->get_boolean('cdn.enabled') && !$this->_config->get_boolean('cdn.debug')) { require_once W3TC_LIB_W3_DIR . '/Plugin/Cdn.php'; $w3_plugin_cdn =& W3_Plugin_Cdn::instance(); $cdn =& $w3_plugin_cdn->get_cdn(); $via = $cdn->get_via(); $strings[] = sprintf("Content Delivery Network via %s%s", $via ? $via : 'N/A', $w3_plugin_cdn->cdn_reject_reason != '' ? sprintf(' (%s)', $w3_plugin_cdn->cdn_reject_reason) : ''); } $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\nServed from: %s @ %s -->", w3_escape_comment($host), $date); } } } return $buffer; }
/** * Output buffering callback * * @param string $buffer * @return string */ function ob_callback(&$buffer) { global $wpdb; if ($buffer != '' && w3_is_xml($buffer)) { if (w3_is_database_error($buffer)) { status_header(503); } else { /** * Replace links for preview mode */ if (w3_is_preview_mode() && isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT'] != W3TC_POWERED_BY) { $domain_url_regexp = w3_get_domain_url_regexp(); $buffer = preg_replace_callback('~(href|src|action)=([\'"])(' . $domain_url_regexp . ')?(/[^\'"]*)~', array(&$this, 'link_replace_callback'), $buffer); } /** * Add footer comment */ $date = date_i18n('Y-m-d H:i:s'); $host = !empty($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost'; 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_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_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')) { $db = w3_instance('W3_DbCache'); $append = !is_null($db->cache_reject_reason) ? sprintf(' (%s)', $db->cache_reject_reason) : ''; if ($db->query_hits) { $strings[] = sprintf("Database Caching %d/%d queries in %.3f seconds using %s%s", $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_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')) { $w3_objectcache = w3_instance('W3_ObjectCache'); $append = $w3_objectcache->cache_reject_reason != '' ? sprintf(' (%s)', $w3_objectcache->cache_reject_reason) : ''; $strings[] = sprintf("Object Caching %d/%d objects using %s%s", $w3_objectcache->cache_hits, $w3_objectcache->cache_total, w3_get_engine_name($this->_config->get_string('objectcache.engine')), $append); } 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_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", $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 ($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(); } } } } return $buffer; }