New cache system with subdirectories
This commit is contained in:
parent
e67062d9cf
commit
f17377e6de
51
boot.php
51
boot.php
|
@ -1847,3 +1847,54 @@ function random_digits($digits) {
|
|||
}
|
||||
return $rn;
|
||||
}
|
||||
|
||||
function get_cachefile($file, $writemode = true) {
|
||||
$cache = get_config("system","itemcache");
|
||||
|
||||
if ($cache == "")
|
||||
return("");
|
||||
|
||||
if (!is_dir($cache))
|
||||
return("");
|
||||
|
||||
$subfolder = $cache."/".substr($file, 0, 2);
|
||||
|
||||
$cachepath = $subfolder."/".$file;
|
||||
|
||||
if ($writemode) {
|
||||
if (!is_dir($subfolder)) {
|
||||
mkdir($subfolder);
|
||||
chmod($subfolder, 0777);
|
||||
}
|
||||
}
|
||||
|
||||
return($cachepath);
|
||||
}
|
||||
|
||||
function clear_cache($basepath = "", $path = "") {
|
||||
if ($path == "") {
|
||||
$basepath = get_config('system','itemcache');
|
||||
$path = $basepath;
|
||||
}
|
||||
|
||||
if (($path == "") OR (!is_dir($path)))
|
||||
return;
|
||||
|
||||
if (substr(realpath($path), 0, strlen($basepath)) != $basepath)
|
||||
return;
|
||||
|
||||
$cachetime = (int)get_config('system','itemcache_duration');
|
||||
if ($cachetime == 0)
|
||||
$cachetime = 86400;
|
||||
|
||||
if ($dh = opendir($path)) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
$fullpath = $path."/".$file;
|
||||
if ((filetype($fullpath) == "dir") and ($file != ".") and ($file != ".."))
|
||||
clear_cache($basepath, $fullpath);
|
||||
if ((filetype($fullpath) == "file") and filectime($fullpath) < (time() - $cachetime))
|
||||
unlink($fullpath);
|
||||
}
|
||||
closedir($dh);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -823,11 +823,9 @@ function scale_external_images($s, $include_link = true, $scale_replace = false)
|
|||
$scaled = $mtch[1];
|
||||
$i = fetch_url($scaled);
|
||||
|
||||
$cache = get_config('system','itemcache');
|
||||
if (($cache != '') and is_dir($cache)) {
|
||||
$cachefile = $cache."/".hash("md5", $scaled);
|
||||
$cachefile = get_cachefile(hash("md5", $scaled));
|
||||
if ($cachefile != '')
|
||||
file_put_contents($cachefile, $i);
|
||||
}
|
||||
|
||||
// guess mimetype from headers or filename
|
||||
$type = guess_image_type($mtch[1],true);
|
||||
|
|
|
@ -102,18 +102,8 @@ function poller_run(&$argv, &$argc){
|
|||
// clear old cache
|
||||
Cache::clear();
|
||||
|
||||
// clear item cache files if they are older than one day
|
||||
$cache = get_config('system','itemcache');
|
||||
if (($cache != '') and is_dir($cache)) {
|
||||
if ($dh = opendir($cache)) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
$fullpath = $cache."/".$file;
|
||||
if ((filetype($fullpath) == "file") and filectime($fullpath) < (time() - 86400))
|
||||
unlink($fullpath);
|
||||
}
|
||||
closedir($dh);
|
||||
}
|
||||
}
|
||||
// clear old item cache files
|
||||
clear_cache();
|
||||
|
||||
$manual_id = 0;
|
||||
$generation = 0;
|
||||
|
|
|
@ -964,11 +964,9 @@ function prepare_body($item,$attach = false) {
|
|||
$a = get_app();
|
||||
call_hooks('prepare_body_init', $item);
|
||||
|
||||
$cache = get_config('system','itemcache');
|
||||
|
||||
if (($cache != '')) {
|
||||
$cachefile = $cache."/".$item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body']);
|
||||
$cachefile = get_cachefile($item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body']));
|
||||
|
||||
if (($cachefile != '')) {
|
||||
if (file_exists($cachefile))
|
||||
$s = file_get_contents($cachefile);
|
||||
else {
|
||||
|
|
|
@ -4,30 +4,7 @@ require_once('include/security.php');
|
|||
require_once('include/Photo.php');
|
||||
|
||||
function photo_init(&$a) {
|
||||
|
||||
// To-Do:
|
||||
// - checking with realpath
|
||||
// - checking permissions
|
||||
/*
|
||||
$cache = get_config('system','itemcache');
|
||||
if (($cache != '') and is_dir($cache)) {
|
||||
$cachefile = $cache."/".$a->argc."-".$a->argv[1]."-".$a->argv[2]."-".$a->argv[3];
|
||||
if (file_exists($cachefile)) {
|
||||
$data = file_get_contents($cachefile);
|
||||
|
||||
if(function_exists('header_remove')) {
|
||||
header_remove('Pragma');
|
||||
header_remove('pragma');
|
||||
}
|
||||
|
||||
header("Content-type: image/jpeg");
|
||||
header("Expires: " . gmdate("D, d M Y H:i:s", time() + (3600*24)) . " GMT");
|
||||
header("Cache-Control: max-age=" . (3600*24));
|
||||
echo $data;
|
||||
killme();
|
||||
// NOTREACHED
|
||||
}
|
||||
}*/
|
||||
global $_SERVER;
|
||||
|
||||
$prvcachecontrol = false;
|
||||
|
||||
|
@ -50,6 +27,22 @@ function photo_init(&$a) {
|
|||
// NOTREACHED
|
||||
}
|
||||
|
||||
// strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= filemtime($localFileName)) {
|
||||
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
|
||||
header('HTTP/1.1 304 Not Modified');
|
||||
header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
|
||||
header('Etag: '.$_SERVER['HTTP_IF_NONE_MATCH']);
|
||||
header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT");
|
||||
header("Cache-Control: max-age=31536000");
|
||||
if(function_exists('header_remove')) {
|
||||
header_remove('Last-Modified');
|
||||
header_remove('Expires');
|
||||
header_remove('Cache-Control');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$default = 'images/person-175.jpg';
|
||||
|
||||
if(isset($type)) {
|
||||
|
@ -203,10 +196,10 @@ function photo_init(&$a) {
|
|||
|
||||
}
|
||||
else {
|
||||
|
||||
header("Expires: " . gmdate("D, d M Y H:i:s", time() + (3600*24)) . " GMT");
|
||||
header("Cache-Control: max-age=" . (3600*24));
|
||||
|
||||
header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
|
||||
header('Etag: "'.md5($data).'"');
|
||||
header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT");
|
||||
header("Cache-Control: max-age=31536000");
|
||||
}
|
||||
echo $data;
|
||||
killme();
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
|
||||
<h3>$header</h3>
|
||||
|
||||
<div id="prvmail-wrapper" >
|
||||
<form id="prvmail-form" action="message" method="post" >
|
||||
|
||||
$parent
|
||||
|
||||
<div id="prvmail-to-label">$to</div>
|
||||
$select
|
||||
|
||||
<div id="prvmail-subject-label">$subject</div>
|
||||
<input type="text" size="64" maxlength="255" id="prvmail-subject" name="subject" value="$subjtxt" $readonly tabindex="11" />
|
||||
|
||||
<div id="prvmail-message-label">$yourmessage</div>
|
||||
<textarea rows="8" cols="72" class="prvmail-text" id="prvmail-text" name="body" tabindex="12">$text</textarea>
|
||||
|
||||
|
||||
<div id="prvmail-submit-wrapper" >
|
||||
<input type="submit" id="prvmail-submit" name="submit" value="$submit" tabindex="13" />
|
||||
<div id="prvmail-upload-wrapper" >
|
||||
<div id="prvmail-upload" title="$upload" ><i class="icon-camera-retro icon-large"></i></div>
|
||||
</div>
|
||||
<div id="prvmail-link-wrapper" >
|
||||
<div id="prvmail-link" title="$insert" onclick="jotGetLink();" ><i class="icon-link icon-large"></i></div>
|
||||
</div>
|
||||
<div id="prvmail-rotator-wrapper" >
|
||||
<img id="prvmail-rotator" src="images/rotator.gif" alt="$wait" title="$wait" style="display: none;" />
|
||||
</div>
|
||||
</div>
|
||||
<div id="prvmail-end"></div>
|
||||
</form>
|
||||
</div>
|
|
@ -887,8 +887,8 @@ aside #search-text {
|
|||
margin: 0px 2px 2px 0px;
|
||||
}
|
||||
#contact-block .contact-block-link img {
|
||||
widht: 48px;
|
||||
height: 58px;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
}
|
||||
.group_selected {
|
||||
background: url("../../../view/theme/diabook/icons/selected.png") no-repeat left center;
|
||||
|
|
Loading…
Reference in a new issue