0 && strstr($uri, $expr)) return true; } return false; } function wp_cache_user_agent_is_rejected() { global $cache_rejected_user_agent; if (!function_exists('apache_request_headers')) return false; $headers = apache_request_headers(); echo "****".$headers."*****"; if (!isset($headers["User-Agent"])) return false; foreach ($cache_rejected_user_agent as $expr) { if (strlen($expr) > 0 && stristr($headers["User-Agent"], $expr)) return true; } return false; } function wp_cache_mutex_init() { global $use_flock, $mutex, $cache_path, $mutex_filename, $sem_id; if(!is_bool($use_flock)) { if(function_exists('sem_get')) $use_flock = false; else $use_flock = true; } if ($use_flock) $mutex = fopen($cache_path . $mutex_filename, 'w'); else $mutex = sem_get($sem_id, 1, 0644 | IPC_CREAT, 1); } function wp_cache_writers_entry() { global $use_flock, $mutex, $cache_path, $mutex_filename; if ($use_flock) flock($mutex, LOCK_EX); else sem_acquire($mutex); } function wp_cache_writers_exit() { global $use_flock, $mutex, $cache_path, $mutex_filename; if ($use_flock) flock($mutex, LOCK_UN); else sem_release($mutex); } function wp_cache_ob_callback($buffer) { global $cache_path, $cache_filename, $meta_file, $wp_start_time; global $new_cache, $meta_object, $file_expired; /* Mode paranoic, the html has have de closing body an html tags * we avoid caching incomplete html */ if (!preg_match('/<\/body>[^<>]*<\/html>/i',$buffer) ) { $new_cache = false; return $buffer; } $meta_object = new CacheMeta; $meta_object->uri = $_SERVER['REQUEST_URI']; $meta_object->post = wp_cache_post_id(); $duration = wp_cache_microtime_diff($wp_start_time, microtime()); $duration = sprintf("%0.3f", $duration); $buffer .= "\n\n"; wp_cache_writers_entry(); $mtime = @filemtime($cache_path . $cache_filename); /* Return if: the file didn't exist before but it does exist now (another connection created) OR the file was expired and its mtime is less than 5 seconds */ if( !((!$file_expired && $mtime) || ($mtime && $file_expired && (time() - $mtime) < 5)) ) { $fr = fopen($cache_path . $cache_filename, 'w'); if (!$fr) $buffer = "Couldn't write to: " . $cache_path . $cache_filename . "\n"; if (preg_match('/(.*?)|is', "\n\n", $buffer); $store = preg_replace('|(.*?)|is', "\n\n", $store); $meta_object->dynamic = true; /* Clean function calls in tag */ $buffer = preg_replace('||is', '', $buffer); $buffer = preg_replace('||is', '', $buffer); fputs($fr, $store); } else { fputs($fr, $buffer); } $new_cache = true; fclose($fr); } wp_cache_writers_exit(); // WP does not set content size $content_size = strlen($buffer); header("Content-Size: $content_size"); return $buffer; } function wp_cache_phase2_clean_cache($file_prefix) { global $cache_path; wp_cache_writers_entry(); if ( ($handle = opendir( $cache_path )) ) { while ( false !== ($file = readdir($handle))) { if ( preg_match("/^$file_prefix/", $file) ) { unlink($cache_path . $file); } } closedir($handle); } wp_cache_writers_exit(); } function wp_cache_phase2_clean_expired($file_prefix) { global $cache_path, $cache_max_time; clearstatcache(); wp_cache_writers_entry(); $now = time(); if ( ($handle = opendir( $cache_path )) ) { while ( false !== ($file = readdir($handle))) { if ( preg_match("/^$file_prefix/", $file) && (filemtime($cache_path . $file) + $cache_max_time) <= $now ) { unlink($cache_path . $file); } } closedir($handle); } wp_cache_writers_exit(); } function wp_cache_ob_end() { global $cache_path, $cache_max_time, $file_expired, $file_prefix, $meta_file, $new_cache, $known_headers; global $meta_object; ob_end_clean(); $content_type_found = false; if ($new_cache) { /* Preparing... with PHP5 is straightforward, use headers_list() */ if(function_exists('apache_response_headers') ) { /* function_exists('headers_list')) future? */ $response = apache_response_headers(); foreach ($known_headers as $key) { if(isset($response{$key})) { array_push($meta_object->headers, "$key: " . $response{$key}); if (eregi("Content-Type", $key)) $content_type_found = true; } } } if (!$content_type_found) { /* Workaround for some buggy installation */ $content = "Content-Type: text/html; charset=\"" . get_settings('blog_charset') . "\"\n"; array_push($meta_object->headers, $content); } $serial = serialize($meta_object); wp_cache_writers_entry(); $fr = fopen($cache_path . $meta_file, 'w'); fputs($fr, $serial); fclose($fr); wp_cache_writers_exit(); } if ($file_expired == false) { return; } // we delete expired files flush(); //Ensure we send data to the client wp_cache_phase2_clean_expired($file_prefix); } function wp_cache_post_change($id) { $post_id = wp_cache_post_id(); wp_cache_post_change_process_post($post_id); return $id; } function wp_cache_post_change_scs($id) { $comment = get_commentdata($id, 1, true); $post_id = $comment['comment_post_ID']; return wp_cache_post_change_process_post($post_id); } function wp_cache_post_change_process_post($post_id) { global $file_prefix; global $cache_path; $meta = new CacheMeta; $matches = array(); wp_cache_writers_entry(); if ( ($handle = opendir( $cache_path )) ) { while ( false !== ($file = readdir($handle))) { if ( preg_match("/^($file_prefix.*)\.meta/", $file, $matches) ) { $meta_pathname = $cache_path . $file; $content_pathname = $cache_path . $matches[1] . ".html"; if ($post_id > 0 && ($meta = unserialize(@file_get_contents($meta_pathname))) ) { if ( !$meta->post || $meta->post == $post_id ) { unlink($meta_pathname); unlink($content_pathname); } } else { unlink($meta_pathname); unlink($content_pathname); } } } closedir($handle); } wp_cache_writers_exit(); } function wp_cache_microtime_diff($a, $b) { list($a_dec, $a_sec) = explode(' ', $a); list($b_dec, $b_sec) = explode(' ', $b); return $b_sec - $a_sec + $b_dec - $a_dec; } function wp_cache_post_id() { global $posts, $comment_post_ID, $post_ID; // We try hard all options. More frequent first. if ($post_ID > 0 ) return $post_ID; if ($comment_post_ID > 0 ) return $comment_post_ID; if (is_single() || is_page()) return $posts[0]->ID; if ($_GET['p'] > 0) return $_GET['p']; return 0; } ?>