/**
  * Flush varnish cache
  */
 function flush()
 {
     if (!is_network_admin()) {
         $this->_purge(w3_get_home_url() . '/.*');
     } else {
         global $wpdb;
         $protocall = w3_is_https() ? 'https://' : 'http://';
         // If WPMU Domain Mapping plugin is installed and active
         if (defined('SUNRISE_LOADED') && SUNRISE_LOADED && isset($wpdb->dmtable) && !empty($wpdb->dmtable)) {
             $blogs = $wpdb->get_results("SELECT {$wpdb->blogs}.domain, {$wpdb->blogs}.path, {$wpdb->dmtable}.domain AS mapped_domain\n                                    FROM {$wpdb->dmtable}\n                                    RIGHT JOIN {$wpdb->blogs} ON {$wpdb->dmtable}.blog_id = {$wpdb->blogs}.blog_id\n                                    WHERE site_id = {$wpdb->siteid}\n                                    AND spam = 0\n                                    AND deleted = 0\n                                    AND archived = '0'\n                                   ");
             foreach ($blogs as $blog) {
                 if (!isset($blog->mapped_domain)) {
                     $url = $protocall . $blog->domain . (strlen($blog->path) > 1 ? '/' . trim($blog->path, '/') : '') . '/.*';
                 } else {
                     $url = $protocall . $blog->mapped_domain . '/.*';
                 }
                 $this->_purge($url);
             }
         } else {
             if (!w3_is_subdomain_install()) {
                 $this->_purge(w3_get_home_url() . '/.*');
             } else {
                 $blogs = $wpdb->get_results("\n                                        SELECT domain, path\n                                        FROM {$wpdb->blogs}\n                                        WHERE site_id = '{$wpdb->siteid}'\n                                        AND spam = 0\n                                        AND deleted = 0\n                                        AND archived = '0'\n                                    ");
                 foreach ($blogs as $blog) {
                     $url = $protocall . $blog->domain . (strlen($blog->path) > 1 ? '/' . trim($blog->path, '/') : '') . '/.*';
                     $this->_purge($url);
                 }
             }
         }
     }
 }
Beispiel #2
0
/**
 * Downloads URL into a file
 *
 * @param string $url
 * @param string $file
 * @return boolean
 */
function w3_download($url, $file)
{
    if (strpos($url, '//') === 0) {
        $url = (w3_is_https() ? 'https:' : 'http:') . $url;
    }
    $response = w3_http_get($url);
    if (!is_wp_error($response) && $response['response']['code'] == 200) {
        return @file_put_contents($file, $response['body']);
    }
    return false;
}
Beispiel #3
0
 /**
  * Prints latest widget contents
  *
  * @return void
  */
 function action_widget_latest_ajax()
 {
     // load content of feed
     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);
         }
     }
     // Removes feedburner tracking images when site is https
     if (w3_is_https()) {
         $total = sizeof($items);
         for ($i = 0; $i < $total; $i++) {
             if (isset($items[$i]['description'])) {
                 $items[$i]['description'] = preg_replace('/<img[^>]+src[^>]+W3TOTALCACHE[^>]+>/', '', $items[$i]['description']);
             }
         }
     }
     ob_start();
     include W3TC_INC_DIR . '/widget/latest_ajax.php';
     // Default lifetime in cache of 12 hours (same as the feeds)
     set_transient($this->_widget_latest_cache_key(), ob_get_flush(), 43200);
     die;
 }
Beispiel #4
0
/**
 * Returns SSL URL if current connection is https
 * @param string $url
 * @return string
 */
function w3_get_url_ssl($url)
{
    if (w3_is_https()) {
        $url = str_replace('http://', 'https://', $url);
    }
    return $url;
}
Beispiel #5
0
/**
 * Downloads data to a file
 *
 * @param string $url
 * @param string $file
 * @return boolean
 */
function w3_download($url, $file)
{
    if (strpos($url, '//') === 0) {
        $url = (w3_is_https() ? 'https:' : 'http:') . $url;
    }
    $data = w3_http_get($url);
    if ($data !== false) {
        return @file_put_contents($file, $data);
    }
    return false;
}
Beispiel #6
0
 /**
  * Returns scheme
  *
  * @return string
  */
 function _get_scheme()
 {
     switch ($this->_config['ssl']) {
         default:
         case 'auto':
             $scheme = w3_is_https() ? 'https' : 'http';
             break;
         case 'enabled':
             $scheme = 'https';
             break;
         case 'disabled':
             $scheme = 'http';
             break;
         case 'rejected':
             $scheme = 'http';
             break;
     }
     return $scheme;
 }
Beispiel #7
0
 /**
  * Returns current encryption
  *
  * @return string
  */
 function _get_encryption()
 {
     if (w3_is_https()) {
         return 'ssl';
     }
     return '';
 }
Beispiel #8
0
 /**
  * Check if we can do CDN logic
  * @return boolean
  */
 function can_cdn()
 {
     /**
      * Skip if admin
      */
     if (defined('WP_ADMIN')) {
         $this->cdn_reject_reason = 'wp-admin';
         return false;
     }
     /**
      * Check for WPMU's and WP's 3.0 short init
      */
     if (defined('SHORTINIT') && SHORTINIT) {
         $this->cdn_reject_reason = 'Short init';
         return false;
     }
     /**
      * Check User agent
      */
     if (!$this->check_ua()) {
         $this->cdn_reject_reason = 'user agent is rejected';
         return false;
     }
     /**
      * Check request URI
      */
     if (!$this->check_request_uri()) {
         $this->cdn_reject_reason = 'request URI is rejected';
         return false;
     }
     /**
      * Do not replace urls if SSL and SSL support is do not replace
      */
     if (w3_is_https() && $this->_config->get_boolean('cdn.reject.ssl')) {
         $this->cdn_reject_reason = 'SSL is rejected';
         return false;
     }
     return true;
 }
Beispiel #9
0
/**
 * Returns SSL site url
 *
 * @return string
 */
function w3_get_site_url_ssl()
{
    $site_url = w3_get_site_url();
    if (w3_is_https()) {
        $site_url = str_replace('http:', 'https:', $site_url);
    }
    return $site_url;
}
Beispiel #10
0
 /**
  * Formats object URL
  *
  * @param string $path
  * @return string
  */
 function format_url($path)
 {
     $domain = $this->get_domain();
     if ($domain) {
         $url = sprintf('%s://%s%s', w3_is_https() ? 'https' : 'http', $domain, $path);
         return $url;
     }
     return false;
 }