Example #1
0
 function flush()
 {
     static $done = false;
     if ($done) {
         return false;
     }
     # can't flush if WP isn't loaded
     if (!function_exists('get_option')) {
         return false;
     }
     $done = true;
     global $wpdb;
     $this->flush = true;
     if (method_exists('static_cache', 'disable')) {
         static_cache::disable();
     }
     # flush posts
     $posts = $wpdb->get_results("SELECT ID, post_title, post_name, post_date, post_type, post_status, post_author, post_parent FROM {$wpdb->posts} WHERE post_status IN ('publish', 'private') OR post_type = 'attachment'");
     # force WP widgets to flush
     wp_cache_delete('widget_recent_posts', 'widget');
     wp_cache_delete('recent_comments', 'widget');
     wp_cache_delete('get_calendar', 'calendar');
     wp_cache_delete('wp_get_archives', 'general');
     wp_cache_delete('all_page_ids', 'posts');
     wp_cache_delete('get_pages', 'posts');
     $post_ids = array();
     foreach ($posts as $post) {
         $post_ids[] = $post->ID;
         $this->delete($post->ID, 'posts');
         $this->delete($post->ID, 'post_meta');
         clean_object_term_cache($post->ID, 'post');
         do_action('clean_post_cache', $post->ID);
         # fill a temporary bucket so as to handle permalinks
         $key = $this->key($post->ID, 'posts');
         $this->cache[$key] = $post;
         if (class_exists('sem_cache') && $post->post_type == 'post') {
             sem_cache::do_flush_author($post->post_author);
             sem_cache::do_flush_date($post->post_date);
         }
     }
     unset($posts);
     if (class_exists('sem_cache')) {
         # flush get_permalink() intensive stuff before flushing terms
         foreach ($post_ids as $post_id) {
             sem_cache::do_flush_post($post_id);
         }
         # flush home
         sem_cache::do_flush_home();
     }
     # flush terms
     $terms = $wpdb->get_results("SELECT term_id, taxonomy FROM {$wpdb->term_taxonomy} WHERE count > 0");
     $taxonomies = array();
     $term_ids = array();
     if (class_exists('sem_cache')) {
         foreach ($terms as $term) {
             sem_cache::do_flush_term($term->term_id, $term->taxonomy);
         }
     }
     foreach ($terms as $term) {
         $taxonomies[] = $term->taxonomy;
         $term_ids[] = $term->term_id;
         $this->delete($term->term_id, $term->taxonomy);
     }
     $taxonomies = array_unique($taxonomies);
     foreach ($taxonomies as $taxonomy) {
         $this->delete('all_ids', $taxonomy);
         $this->delete('get', $taxonomy);
         delete_option("{$taxonomy}_children");
         do_action('clean_term_cache', $term_ids, $taxonomy);
     }
     $this->delete('last_changed', 'terms');
     unset($terms);
     # flush users
     $user_ids = $wpdb->get_col("SELECT ID FROM {$wpdb->users}");
     foreach ($user_ids as $user_id) {
         $this->delete($user_id, 'users');
     }
     unset($user_ids);
     # backup key transients
     $transients = array('update_core', 'update_plugins', 'update_themes', 'sem_memberships', 'sem_update_plugins', 'sem_update_themes');
     $extra = array('feed_220431e2eb0959fa9c7fcb07c6e22632', 'feed_mod_220431e2eb0959fa9c7fcb07c6e22632');
     foreach (array_merge($transients, $extra) as $var) {
         ${$var} = get_transient($var);
     }
     # flush options
     $options = $wpdb->get_col("SELECT option_name FROM {$wpdb->options}");
     foreach ($options as $option) {
         if (!in_array($option, array_merge($transients, $extra))) {
             if (preg_match("/^_transient_/", $option)) {
                 delete_option($option);
             } else {
                 $this->delete($option, 'options');
             }
         }
     }
     $this->delete('notoptions', 'options');
     $this->delete('alloptions', 'options');
     unset($options);
     # restore key transients
     foreach ($transients as $var) {
         if (${$var} !== false) {
             set_transient($var, ${$var});
         }
     }
     if ($feed_220431e2eb0959fa9c7fcb07c6e22632 !== false) {
         $var = 'feed_220431e2eb0959fa9c7fcb07c6e22632';
         set_transient($var, ${$var}, min(3600, cache_timeout));
         $var = 'feed_mod_220431e2eb0959fa9c7fcb07c6e22632';
         set_transient($var, time(), min(3600, cache_timeout));
     }
     return true;
 }
Example #2
0
 /**
  * start()
  *
  * @return void
  **/
 static function start()
 {
     # some things can be taken care of at all times
     switch (basename($_SERVER['REQUEST_URI'])) {
         case 'favicon.ico':
             # bypass WP entirely on favicon.ico
             $protocol = $_SERVER["SERVER_PROTOCOL"];
             if ('HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol) {
                 $protocol = 'HTTP/1.0';
             }
             $headers = array("{$protocol} 404 Not Found", 'Expires: Wed, 11 Jan 1984 05:00:00 GMT', 'Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT', 'Cache-Control: no-cache, must-revalidate, max-age=0', 'Pragma: no-cache', 'Content-Type: image/x-icon');
             foreach ($headers as $header) {
                 header($header, true);
             }
             die;
         case 'sitemap.xml':
         case 'sitemap.xml.gz':
             # let xml sitemap plugins cache themselves
             return;
     }
     global $sem_cache_cookies;
     if (!defined('WP_CACHE') || !WP_CACHE || isset($_GET['action']) || isset($_GET['doing_wp_cron']) || isset($_GET['debug']) || isset($_GET['preview']) || defined('WP_INSTALLING') && WP_INSTALLING || defined('WP_ADMIN') && WP_ADMIN || defined('DOING_CRON') && DOING_CRON || defined('DOING_AJAX') && DOING_AJAX || $_POST || !$sem_cache_cookies || array_intersect(array_keys($_COOKIE), (array) $sem_cache_cookies) || self::$nocache) {
         return;
     }
     global $sem_mobile_agents;
     $mobile_agents = $sem_mobile_agents;
     //		$mobile_agents = array_map('preg_quote', (array) $mobile_agents);
     $mobile_agents = implode("|", $mobile_agents);
     if (preg_match("{({$mobile_agents})}i", $_SERVER['HTTP_USER_AGENT'])) {
         return;
     }
     if (preg_match("/(?=.*?\\bandroid\\b)(?=.*?\\bmobile\\b).*\$/i", $_SERVER['HTTP_USER_AGENT'])) {
         return;
     }
     #header("Content-Type: text/plain");
     #var_dump($_SERVER);
     #die;
     # kill static cache on multisite installs
     self::$static &= !(function_exists('is_multisite') && is_multisite());
     if (self::$started || headers_sent() || !self::$static && !self::$memory) {
         return;
     }
     if (isset($_SERVER['HTTPS']) && ('on' == strtolower($_SERVER['HTTPS']) || '1' == $_SERVER['HTTPS']) || isset($_SERVER['SERVER_PORT']) && '443' == $_SERVER['SERVER_PORT']) {
         self::$host = 'https://' . $_SERVER['HTTP_HOST'];
     } else {
         self::$host = 'http://' . $_SERVER['HTTP_HOST'];
     }
     $cache_id = self::$host . preg_replace("/#.*/", '', $_SERVER['REQUEST_URI']);
     $cache_id = md5($cache_id);
     if (self::$memory) {
         $headers = wp_cache_get($cache_id, 'cached_headers');
         if ($headers !== false) {
             self::send_headers($headers);
             $buffer = wp_cache_get($cache_id, 'cached_buffers');
             if ($buffer) {
                 echo $buffer;
             }
             die;
         }
     } elseif (!(function_exists('is_multisite') && is_multisite())) {
         # poor man's memcached
         $headers = '/semi-static/' . $cache_id . '.meta';
         if (cache_fs::exists($headers, cache_timeout)) {
             $headers = unserialize(cache_fs::get_contents($headers));
             self::send_headers($headers);
             $buffer = '/semi-static/' . $cache_id . '.html';
             if (cache_fs::exists($buffer)) {
                 cache_fs::readfile($buffer);
             }
             die;
         }
     }
     self::$started = true;
     ob_start(array('static_cache', 'ob_callback'));
 }