Ejemplo n.º 1
0
 /**
  * Flushes post cache
  *
  * @param integer $post_id
  * @return boolean
  */
 function flush_post($post_id = null)
 {
     if (!$post_id) {
         $post_id = $this->_detect_post_id();
     }
     if ($post_id) {
         $uris = array();
         $domain_url = w3_get_domain_url();
         $feeds = $this->_config->get_array('pgcache.purge.feed.types');
         if ($this->_config->get_boolean('pgcache.purge.terms') || $this->_config->get_boolean('pgcache.purge.feed.terms')) {
             $taxonomies = get_post_taxonomies($post_id);
             $terms = wp_get_post_terms($post_id, $taxonomies);
         }
         switch (true) {
             case $this->_config->get_boolean('pgcache.purge.author'):
             case $this->_config->get_boolean('pgcache.purge.archive.daily'):
             case $this->_config->get_boolean('pgcache.purge.archive.monthly'):
             case $this->_config->get_boolean('pgcache.purge.archive.yearly'):
             case $this->_config->get_boolean('pgcache.purge.feed.author'):
                 $post = get_post($post_id);
         }
         /**
          * Home URL
          */
         if ($this->_config->get_boolean('pgcache.purge.home')) {
             $home_path = w3_get_home_path();
             $site_path = w3_get_site_path();
             $uris[] = $home_path;
             if ($site_path != $home_path) {
                 $uris[] = $site_path;
             }
         }
         /**
          * Post URL
          */
         if ($this->_config->get_boolean('pgcache.purge.post')) {
             $post_link = post_permalink($post_id);
             $post_uri = str_replace($domain_url, '', $post_link);
             $uris[] = $post_uri;
         }
         /**
          * Post comments URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.comments') && function_exists('get_comments_pagenum_link')) {
             $comments_number = get_comments_number($post_id);
             $comments_per_page = get_option('comments_per_page');
             $comments_pages_number = @ceil($comments_number / $comments_per_page);
             for ($pagenum = 1; $pagenum <= $comments_pages_number; $pagenum++) {
                 $comments_pagenum_link = $this->_get_comments_pagenum_link($post_id, $pagenum);
                 $comments_pagenum_uri = str_replace($domain_url, '', $comments_pagenum_link);
                 $uris[] = $comments_pagenum_uri;
             }
         }
         /**
          * Post author URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.author') && $post) {
             $posts_number = count_user_posts($post->post_author);
             $posts_per_page = get_option('posts_per_page');
             $posts_pages_number = @ceil($posts_number / $posts_per_page);
             $author_link = get_author_link(false, $post->post_author);
             $author_uri = str_replace($domain_url, '', $author_link);
             for ($pagenum = 1; $pagenum <= $posts_pages_number; $pagenum++) {
                 $author_pagenum_link = $this->_get_pagenum_link($author_uri, $pagenum);
                 $author_pagenum_uri = str_replace($domain_url, '', $author_pagenum_link);
                 $uris[] = $author_pagenum_uri;
             }
         }
         /**
          * Post terms URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.terms')) {
             $posts_per_page = get_option('posts_per_page');
             foreach ($terms as $term) {
                 $term_link = get_term_link($term, $term->taxonomy);
                 $term_uri = str_replace($domain_url, '', $term_link);
                 $posts_pages_number = @ceil($term->count / $posts_per_page);
                 for ($pagenum = 1; $pagenum <= $posts_pages_number; $pagenum++) {
                     $term_pagenum_link = $this->_get_pagenum_link($term_uri, $pagenum);
                     $term_pagenum_uri = str_replace($domain_url, '', $term_pagenum_link);
                     $uris[] = $term_pagenum_uri;
                 }
             }
         }
         /**
          * Daily archive URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.archive.daily') && $post) {
             $post_date = strtotime($post->post_date);
             $post_year = gmdate('Y', $post_date);
             $post_month = gmdate('m', $post_date);
             $post_day = gmdate('d', $post_date);
             $posts_per_page = get_option('posts_per_page');
             $posts_number = $this->_get_archive_posts_count($post_year, $post_month, $post_day);
             $posts_pages_number = @ceil($posts_number / $posts_per_page);
             $day_link = get_day_link($post_year, $post_month, $post_day);
             $day_uri = str_replace($domain_url, '', $day_link);
             for ($pagenum = 1; $pagenum <= $posts_pages_number; $pagenum++) {
                 $day_pagenum_link = $this->_get_pagenum_link($day_uri, $pagenum);
                 $day_pagenum_uri = str_replace($domain_url, '', $day_pagenum_link);
                 $uris[] = $day_pagenum_uri;
             }
         }
         /**
          * Monthly archive URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.archive.monthly') && $post) {
             $post_date = strtotime($post->post_date);
             $post_year = gmdate('Y', $post_date);
             $post_month = gmdate('m', $post_date);
             $posts_per_page = get_option('posts_per_page');
             $posts_number = $this->_get_archive_posts_count($post_year, $post_month);
             $posts_pages_number = @ceil($posts_number / $posts_per_page);
             $month_link = get_month_link($post_year, $post_month);
             $month_uri = str_replace($domain_url, '', $month_link);
             for ($pagenum = 1; $pagenum <= $posts_pages_number; $pagenum++) {
                 $month_pagenum_link = $this->_get_pagenum_link($month_uri, $pagenum);
                 $month_pagenum_uri = str_replace($domain_url, '', $month_pagenum_link);
                 $uris[] = $month_pagenum_uri;
             }
         }
         /**
          * Yearly archive URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.archive.yearly') && $post) {
             $post_date = strtotime($post->post_date);
             $post_year = gmdate('Y', $post_date);
             $posts_per_page = get_option('posts_per_page');
             $posts_number = $this->_get_archive_posts_count($post_year);
             $posts_pages_number = @ceil($posts_number / $posts_per_page);
             $year_link = get_year_link($post_year);
             $year_uri = str_replace($domain_url, '', $year_link);
             for ($pagenum = 1; $pagenum <= $posts_pages_number; $pagenum++) {
                 $year_pagenum_link = $this->_get_pagenum_link($year_uri, $pagenum);
                 $year_pagenum_uri = str_replace($domain_url, '', $year_pagenum_link);
                 $uris[] = $year_pagenum_uri;
             }
         }
         /**
          * Feed URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.feed.blog')) {
             foreach ($feeds as $feed) {
                 $feed_link = get_feed_link($feed);
                 $feed_uri = str_replace($domain_url, '', $feed_link);
                 $uris[] = $feed_uri;
             }
         }
         if ($this->_config->get_boolean('pgcache.purge.feed.comments')) {
             foreach ($feeds as $feed) {
                 $post_comments_feed_link = get_post_comments_feed_link($post_id, $feed);
                 $post_comments_feed_uri = str_replace($domain_url, '', $post_comments_feed_link);
                 $uris[] = $post_comments_feed_uri;
             }
         }
         if ($this->_config->get_boolean('pgcache.purge.feed.author') && $post) {
             foreach ($feeds as $feed) {
                 $author_feed_link = get_author_feed_link($post->post_author, $feed);
                 $author_feed_uri = str_replace($domain_url, '', $author_feed_link);
                 $uris[] = $author_feed_uri;
             }
         }
         if ($this->_config->get_boolean('pgcache.purge.feed.terms')) {
             foreach ($terms as $term) {
                 foreach ($feeds as $feed) {
                     $term_feed_link = get_term_feed_link($term->term_id, $term->taxonomy, $feed);
                     $term_feed_uri = str_replace($domain_url, '', $term_feed_link);
                     $uris[] = $term_feed_uri;
                 }
             }
         }
         /**
          * Flush cache
          */
         if (count($uris)) {
             $cache =& $this->_get_cache();
             $mobile_groups = $this->_get_mobile_groups();
             $referrer_groups = $this->_get_referrer_groups();
             $encryptions = $this->_get_encryptions();
             $compressions = $this->_get_compressions();
             foreach ($uris as $uri) {
                 foreach ($mobile_groups as $mobile_group) {
                     foreach ($referrer_groups as $referrer_group) {
                         foreach ($encryptions as $encryption) {
                             foreach ($compressions as $compression) {
                                 $page_key = $this->_get_page_key($uri, $mobile_group, $referrer_group, $encryption, $compression);
                                 $cache->delete($page_key);
                             }
                         }
                     }
                 }
             }
             /**
              * Purge varnish servers
              */
             if ($this->_config->get_boolean('varnish.enabled')) {
                 require_once W3TC_LIB_W3_DIR . '/Varnish.php';
                 $varnish =& W3_Varnish::instance();
                 foreach ($uris as $uri) {
                     $varnish->purge($uri);
                 }
             }
         }
         return true;
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * Purges files from CDN
  *
  * @param array $files
  * @param boolean $queue_failed
  * @param array $results
  * @return boolean
  */
 function purge($files, $queue_failed, &$results)
 {
     /**
      * Purge varnish servers before mirror purging
      */
     if (w3_is_cdn_mirror($this->_config->get_string('cdn_engine')) && $this->_config->get_boolean('varnish.enabled')) {
         require_once W3TC_LIB_W3_DIR . '/Varnish.php';
         $varnish =& W3_Varnish::instance();
         foreach ($files as $remote_path) {
             $varnish->purge($remote_path);
         }
     }
     /**
      * Purge CDN
      */
     $cdn =& $this->get_cdn();
     @set_time_limit($this->_config->get_integer('timelimit.cdn_purge'));
     $return = $cdn->purge($files, $results);
     if (!$return && $queue_failed) {
         foreach ($results as $result) {
             if ($result['result'] != W3TC_CDN_RESULT_OK) {
                 $this->queue_add($result['local_path'], $result['remote_path'], W3TC_CDN_COMMAND_PURGE, $result['error']);
             }
         }
     }
     return $return;
 }