function _cleanDir($dir, $group = false, $mode = 'ingroup')
{
if ($this->_fileNameProtection) {
$motif = $group ? 'cache_' . md5($group) . '_' : 'cache_';
} else {
$motif = $group ? 'cache_' . $group . '_' : 'cache_';
}
if ($this->_memoryCaching) {
while (list($key, ) = each($this->_memoryCachingArray)) {
if (strpos($key, $motif, 0)) {
unset($this->_memoryCachingArray[$key]);
$this->_memoryCachingCounter = $this->_memoryCachingCounter - 1;
}
}
if ($this->_onlyMemoryCaching) {
return true;
}
}
if (!($dh = opendir($dir))) {
return $this->raiseError('Cache_Lite : Unable to open cache directory !', -4);
}
$result = true;
while ($file = readdir($dh)) {
if ($file != '.' && $file != '..') {
if (substr($file, 0, 6) == 'cache_') {
$file2 = $dir . $file;
if (is_file($file2)) {
switch (substr($mode, 0, 9)) {
case 'old':
// files older than lifeTime get deleted from cache
if (!is_null($this->_lifeTime)) {
if (time() - @filemtime($file2) > $this->_lifeTime) {
$result = ($result and $this->_unlink($file2));
}
}
break;
case 'notingroup':
if (!strpos($file2, $motif, 0)) {
$result = ($result and $this->_unlink($file2));
}
break;
case 'callback_':
$func = substr($mode, 9, strlen($mode) - 9);
if ($func($file2, $group)) {
$result = ($result and $this->_unlink($file2));
}
break;
case 'ingroup':
default:
if (strpos($file2, $motif, 0)) {
$result = ($result and $this->_unlink($file2));
}
break;
}
}
if (is_dir($file2) and $this->_hashedDirectoryLevel > 0) {
$result = ($result and $this->_cleanDir($file2 . '/', $group, $mode));
}
}
}
}
return $result;
}