Пример #1
0
 /**
  * Output buffering callback
  *
  * @param string $buffer
  * @return string
  */
 function ob_callback($buffer)
 {
     global $wpdb;
     if ($buffer != '' && w3_is_xml($buffer)) {
         $date = date('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 -->", $host, $date);
         } else {
             $buffer .= "\r\n<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/\r\n\r\n";
             if ($this->_config->get_boolean('minify.enabled')) {
                 require_once W3TC_LIB_W3_DIR . '/Plugin/Minify.php';
                 $w3_plugin_minify =& W3_Plugin_Minify::instance();
                 $buffer .= sprintf("Minified using %s%s\r\n", 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')) {
                 require_once W3TC_LIB_W3_DIR . '/PgCache.php';
                 $w3_pgcache =& W3_PgCache::instance();
                 $buffer .= sprintf("Page Caching using %s%s\r\n", 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') && is_a($wpdb, 'W3_Db')) {
                 $append = is_user_logged_in() ? ' (user is logged in)' : '';
                 if ($wpdb->query_hits) {
                     $buffer .= sprintf("Database Caching %d/%d queries in %.3f seconds using %s%s\r\n", $wpdb->query_hits, $wpdb->query_total, $wpdb->time_total, w3_get_engine_name($this->_config->get_string('dbcache.engine')), $append);
                 } else {
                     $buffer .= sprintf("Database Caching using %s%s\r\n", w3_get_engine_name($this->_config->get_string('dbcache.engine')), $append);
                 }
             }
             if ($this->_config->get_boolean('cdn.enabled')) {
                 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();
                 $buffer .= sprintf("Content Delivery Network via %s%s\r\n", $via ? $via : 'N/A', $w3_plugin_cdn->cdn_reject_reason != '' ? sprintf(' (%s)', $w3_plugin_cdn->cdn_reject_reason) : '');
             }
             $buffer .= sprintf("\r\nServed from: %s @ %s -->", $host, $date);
         }
     }
     return $buffer;
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
function rewrite_url_to_cdn_url($url)
{
    // check if W3 Total Cache is installed
    if (class_exists('W3_Plugin_Cdn')) {
        $w3tc_instance = new W3_Plugin_Cdn();
        $path = str_replace(site_url() . '/', '', $url);
        $cdn = $w3tc_instance->_get_common()->get_cdn();
        $remote_path = $w3tc_instance->_get_common()->uri_to_cdn_uri($path);
        $new_url = $cdn->format_url($remote_path);
    } else {
        $new_url = $url;
    }
    return $new_url;
}