$smallsize = "?imgmax=160"; // small image size $max_height = 600; // max image height $cache_directory = "/home/mathzqy/domains/zhiqiang.org/public_html/blog/wp-content/themes/yuewei/cache/"; // cache directory $snoopy_file = "/home/mathzqy/public_html/blog/wp-includes/class-snoopy.php"; $picasa_uri = "http://zhiqiang.org/blog/wp-content/themes/yuewei/webpicasa.php"; // input $albumid = isset($_REQUEST['albumid']) ? $_REQUEST['albumid'] : ''; $np = isset($_REQUEST['np']) ? (int) $_REQUEST['np'] : 0; if (isset($_REQUEST['json'])) { get_json_content(true); exit; } elseif (isset($_REQUEST['update'])) { generate_cache(); exit; } function get_cache_date() { global $albumid, $cache_directory; $rss_uri = get_rss_uri(); $rss_hash = md5($rss_uri) . ".xml"; $cache_rss_path = $cache_directory . $rss_hash; if (is_file($cache_rss_path)) { return date("Y-m-d", filemtime($cache_rss_path)); } else { return "0000-00-00"; } } function generate_cache()
function cache_parse($threshold = 100){ $log_file = CONTENT_DIR . 'render/render_log'; if($fh = @fopen($log_file, 'r')){ while (!feof($fh)){ $line = fgets($fh); $line = str_replace("\n", "", $line); $line_data = split(' ', $line); if(count($line_data) == 3){ if(isset($data[$line_data[0]][$line_data[1]][$line_data[2]])){ $data[$line_data[0]][$line_data[1]][$line_data[2]]++; //Count how many times that content/width/height set apperas } else { $data[$line_data[0]][$line_data[1]][$line_data[2]] = 1; } } } fclose($fh); unset($fh); } if(!isset($data)){ //Nothing has been viewed/logged. Do no more thinking return true; } //Now we find those entries that are worthy of a cache foreach($data as $file_path => $details){ foreach($details as $width => $h_details){ foreach($h_details as $height => $count){ if($count > $threshold){ // The content has been called enough we should cache it generate_cache($file_path, $width, $height); } } } } //Then empty the log file @system("rm $log_file"); }