コード例 #1
0
 /**
  * Makes get requests to url specific to a post, its permalink
  *
  * @param unknown $post_id
  * @return boolean returns true on success
  */
 public function prime_post($post_id)
 {
     $post_urls = Util_PageUrls::get_post_urls($post_id);
     // Make HTTP requests and prime cache
     foreach ($post_urls as $url) {
         $result = Util_Http::get($url, array('user-agent' => ''));
         if (is_wp_error($result)) {
             return false;
         }
     }
     return true;
 }
コード例 #2
0
 /**
  * Flush the fragments connected to a post id
  *
  * @param unknown $post_ID
  */
 function flush_post_fragment($post_ID)
 {
     $page_slug = $this->get_page_slug($post_ID);
     $urls = Util_PageUrls::get_post_urls($post_ID);
     $hooks = array('genesis_loop', 'genesis_comments', 'genesis_pings');
     foreach ($hooks as $hook) {
         $genesis_id = $page_slug;
         $genesis_id = "{$hook}_{$genesis_id}";
         w3tc_fragmentcache_flush_fragment($genesis_id, $this->_genesis_group('loop_single_logged_in'));
         w3tc_fragmentcache_flush_fragment($genesis_id, $this->_genesis_group('loop_single'));
         for ($page = 0; $page <= sizeof($urls); $page++) {
             $genesis_id = $page_slug;
             $genesis_id .= $this->get_paged_page_key($page);
             $genesis_id = "{$hook}_{$genesis_id}";
             w3tc_fragmentcache_flush_fragment($genesis_id, $this->_genesis_group('loop_single_logged_in'));
             w3tc_fragmentcache_flush_fragment($genesis_id, $this->_genesis_group('loop_single'));
         }
     }
 }
コード例 #3
0
 /**
  * Flushes varnish post cache
  *
  * @param integer $post_id
  * @return boolean
  */
 function flush_post($post_id)
 {
     if (!$post_id) {
         $post_id = Util_Environment::detect_post_id();
     }
     if ($post_id) {
         $full_urls = array();
         $post = null;
         $terms = array();
         $feeds = $this->_config->get_array('pgcache.purge.feed.types');
         $limit_post_pages = $this->_config->get_integer('pgcache.purge.postpages_limit');
         if ($this->_config->get_boolean('pgcache.purge.terms') || $this->_config->get_boolean('varnish.pgcache.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);
         }
         $front_page = get_option('show_on_front');
         /**
          * Home (Frontpage) URL
          */
         if ($this->_config->get_boolean('pgcache.purge.home') && $front_page == 'posts' || $this->_config->get_boolean('pgcache.purge.front_page')) {
             $full_urls = array_merge($full_urls, Util_PageUrls::get_frontpage_urls($limit_post_pages));
         }
         /**
          * Home (Post page) URL
          */
         if ($this->_config->get_boolean('pgcache.purge.home') && $front_page != 'posts') {
             $full_urls = array_merge($full_urls, Util_PageUrls::get_postpage_urls($limit_post_pages));
         }
         /**
          * Post URL
          */
         if ($this->_config->get_boolean('pgcache.purge.post')) {
             $full_urls = array_merge($full_urls, Util_PageUrls::get_post_urls($post_id));
         }
         /**
          * Post comments URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.comments') && function_exists('get_comments_pagenum_link')) {
             $full_urls = array_merge($full_urls, Util_PageUrls::get_post_comments_urls($post_id));
         }
         /**
          * Post author URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.author') && $post) {
             $full_urls = array_merge($full_urls, Util_PageUrls::get_post_author_urls($post->post_author, $limit_post_pages));
         }
         /**
          * Post terms URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.terms')) {
             $full_urls = array_merge($full_urls, Util_PageUrls::get_post_terms_urls($terms, $limit_post_pages));
         }
         /**
          * Daily archive URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.archive.daily') && $post) {
             $full_urls = array_merge($full_urls, Util_PageUrls::get_daily_archive_urls($post, $limit_post_pages));
         }
         /**
          * Monthly archive URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.archive.monthly') && $post) {
             $full_urls = array_merge($full_urls, Util_PageUrls::get_monthly_archive_urls($post, $limit_post_pages));
         }
         /**
          * Yearly archive URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.archive.yearly') && $post) {
             $full_urls = array_merge($full_urls, Util_PageUrls::get_yearly_archive_urls($post, $limit_post_pages));
         }
         /**
          * Feed URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.feed.blog')) {
             $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_urls($feeds));
         }
         if ($this->_config->get_boolean('pgcache.purge.feed.comments')) {
             $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_comments_urls($post_id, $feeds));
         }
         if ($this->_config->get_boolean('pgcache.purge.feed.author') && $post) {
             $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_author_urls($post->post_author, $feeds));
         }
         if ($this->_config->get_boolean('pgcache.purge.feed.terms')) {
             $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_terms_urls($terms, $feeds));
         }
         /**
          * Purge selected pages
          */
         if ($this->_config->get_array('pgcache.purge.pages')) {
             $pages = $this->_config->get_array('pgcache.purge.pages');
             $full_urls = array_merge($full_urls, Util_PageUrls::get_pages_urls($pages));
         }
         if ($this->_config->get_string('pgcache.purge.sitemap_regex')) {
             $sitemap_regex = $this->_config->get_string('pgcache.purge.sitemap_regex');
             $full_urls[] = Util_Environment::home_domain_root_url() . '/' . trim($sitemap_regex, "^\$");
         }
         /**
          * Queue flush
          */
         if (count($full_urls)) {
             foreach ($full_urls as $url) {
                 $this->queued_urls[$url] = '*';
             }
             // add mirror urls
             $this->queued_urls = Util_PageUrls::complement_with_mirror_urls($this->queued_urls);
         }
         return true;
     }
     return false;
 }
コード例 #4
0
 /**
  * Purges cdn's post cache
  *
  * @param integer $post_id
  * @return boolean
  */
 public static function w3tc_flush_post($post_id)
 {
     if (!$post_id) {
         $post_id = Util_Environment::detect_post_id();
     }
     if (!$post_id) {
         return false;
     }
     $config = Dispatcher::config();
     $full_urls = array();
     $post = null;
     $terms = array();
     $feeds = $config->get_array('pgcache.purge.feed.types');
     $limit_post_pages = $config->get_integer('pgcache.purge.postpages_limit');
     if ($config->get_boolean('pgcache.purge.terms') || $config->get_boolean('varnish.pgcache.feed.terms')) {
         $taxonomies = get_post_taxonomies($post_id);
         $terms = wp_get_post_terms($post_id, $taxonomies);
     }
     switch (true) {
         case $config->get_boolean('pgcache.purge.author'):
         case $config->get_boolean('pgcache.purge.archive.daily'):
         case $config->get_boolean('pgcache.purge.archive.monthly'):
         case $config->get_boolean('pgcache.purge.archive.yearly'):
         case $config->get_boolean('pgcache.purge.feed.author'):
             $post = get_post($post_id);
     }
     $front_page = get_option('show_on_front');
     /**
      * Home (Frontpage) URL
      */
     if ($config->get_boolean('pgcache.purge.home') && $front_page == 'posts' || $config->get_boolean('pgcache.purge.front_page')) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_frontpage_urls($limit_post_pages));
     }
     /**
      * Home (Post page) URL
      */
     if ($config->get_boolean('pgcache.purge.home') && $front_page != 'posts') {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_postpage_urls($limit_post_pages));
     }
     /**
      * Post URL
      */
     if ($config->get_boolean('pgcache.purge.post')) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_post_urls($post_id));
     }
     /**
      * Post comments URLs
      */
     if ($config->get_boolean('pgcache.purge.comments') && function_exists('get_comments_pagenum_link')) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_post_comments_urls($post_id));
     }
     /**
      * Post author URLs
      */
     if ($config->get_boolean('pgcache.purge.author') && $post) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_post_author_urls($post->post_author, $limit_post_pages));
     }
     /**
      * Post terms URLs
      */
     if ($config->get_boolean('pgcache.purge.terms')) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_post_terms_urls($terms, $limit_post_pages));
     }
     /**
      * Daily archive URLs
      */
     if ($config->get_boolean('pgcache.purge.archive.daily') && $post) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_daily_archive_urls($post, $limit_post_pages));
     }
     /**
      * Monthly archive URLs
      */
     if ($config->get_boolean('pgcache.purge.archive.monthly') && $post) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_monthly_archive_urls($post, $limit_post_pages));
     }
     /**
      * Yearly archive URLs
      */
     if ($config->get_boolean('pgcache.purge.archive.yearly') && $post) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_yearly_archive_urls($post, $limit_post_pages));
     }
     /**
      * Feed URLs
      */
     if ($config->get_boolean('pgcache.purge.feed.blog')) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_urls($feeds));
     }
     if ($config->get_boolean('pgcache.purge.feed.comments')) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_comments_urls($post_id, $feeds));
     }
     if ($config->get_boolean('pgcache.purge.feed.author') && $post) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_author_urls($post->post_author, $feeds));
     }
     if ($config->get_boolean('pgcache.purge.feed.terms')) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_terms_urls($terms, $feeds));
     }
     /**
      * Purge selected pages
      */
     if ($config->get_array('pgcache.purge.pages')) {
         $pages = $config->get_array('pgcache.purge.pages');
         $full_urls = array_merge($full_urls, Util_PageUrls::get_pages_urls($pages));
     }
     /**
      * Queue flush
      */
     if (count($full_urls)) {
         $o = Dispatcher::component('Cdn_Fsd_CacheFlush');
         foreach ($full_urls as $url) {
             $o->queued_urls[$url] = '*';
         }
     }
     return true;
 }
コード例 #5
0
 /**
  * Flushes post cache
  *
  * @param integer $post_id
  * @return boolean
  */
 function flush_post($post_id = null)
 {
     if (!$post_id) {
         $post_id = Util_Environment::detect_post_id();
     }
     if (!$post_id) {
         return false;
     }
     $full_urls = array();
     $post = null;
     $terms = array();
     $feeds = $this->_config->get_array('pgcache.purge.feed.types');
     $limit_post_pages = $this->_config->get_integer('pgcache.purge.postpages_limit');
     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);
         $terms = $this->_append_parent_terms($terms, $terms);
     }
     $post = get_post($post_id);
     $post_type = in_array($post->post_type, array('post', 'page', 'attachment', 'revision')) ? null : $post->post_type;
     $front_page = get_option('show_on_front');
     /**
      * Home (Frontpage) URL
      */
     if ($this->_config->get_boolean('pgcache.purge.home') && $front_page == 'posts' || $this->_config->get_boolean('pgcache.purge.front_page')) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_frontpage_urls($limit_post_pages));
     }
     /**
      * Home (Post page) URL
      */
     if ($this->_config->get_boolean('pgcache.purge.home') && $front_page != 'posts') {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_postpage_urls($limit_post_pages));
     }
     /**
      * Post URL
      */
     if ($this->_config->get_boolean('pgcache.purge.post')) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_post_urls($post_id));
     }
     /**
      * Post comments URLs
      */
     if ($this->_config->get_boolean('pgcache.purge.comments') && function_exists('get_comments_pagenum_link')) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_post_comments_urls($post_id));
     }
     /**
      * Post author URLs
      */
     if ($this->_config->get_boolean('pgcache.purge.author')) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_post_author_urls($post->post_author, $limit_post_pages));
     }
     /**
      * Post terms URLs
      */
     if ($this->_config->get_boolean('pgcache.purge.terms')) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_post_terms_urls($terms, $limit_post_pages));
     }
     /**
      * Daily archive URLs
      */
     if ($this->_config->get_boolean('pgcache.purge.archive.daily') && $post) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_daily_archive_urls($post, $limit_post_pages));
     }
     /**
      * Monthly archive URLs
      */
     if ($this->_config->get_boolean('pgcache.purge.archive.monthly') && $post) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_monthly_archive_urls($post, $limit_post_pages));
     }
     /**
      * Yearly archive URLs
      */
     if ($this->_config->get_boolean('pgcache.purge.archive.yearly') && $post) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_yearly_archive_urls($post, $limit_post_pages));
     }
     /**
      * Feed URLs
      */
     if ($this->_config->get_boolean('pgcache.purge.feed.blog')) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_urls($feeds, $post_type));
     }
     if ($this->_config->get_boolean('pgcache.purge.feed.comments')) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_comments_urls($post_id, $feeds));
     }
     if ($this->_config->get_boolean('pgcache.purge.feed.author')) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_author_urls($post->post_author, $feeds));
     }
     if ($this->_config->get_boolean('pgcache.purge.feed.terms')) {
         $full_urls = array_merge($full_urls, Util_PageUrls::get_feed_terms_urls($terms, $feeds));
     }
     /**
      * Purge selected pages
      */
     if ($this->_config->get_array('pgcache.purge.pages')) {
         $pages = $this->_config->get_array('pgcache.purge.pages');
         $full_urls = array_merge($full_urls, Util_PageUrls::get_pages_urls($pages));
     }
     /**
      * Queue flush
      */
     if (count($full_urls)) {
         foreach ($full_urls as $url) {
             $this->queued_urls[$url] = '*';
         }
     }
     // add mirror urls
     $this->queued_urls = Util_PageUrls::complement_with_mirror_urls($this->queued_urls);
     return true;
 }