<?php

if (!defined('XOOPS_ROOT_PATH')) exit();

class Stdcache_CacheclearBlock extends Legacy_BlockProcedure
{
	function execute()
	{
		$root =& XCube_Root::getSingleton();
	
		if (!$root->mController->isEnableCacheFeature()) {
			return false;
		}
		
		if($handler = opendir(XOOPS_CACHE_PATH)) {
			while(($file = readdir($handler)) !== false) {
				if(preg_match("/\w+\.cache\.html$/", $file, $matches)) {
					@unlink(XOOPS_CACHE_PATH . "/" . $matches[0]);
				}
			}
			closedir($handler);
		}
	}
	
	function isDisplay()
	{
		return false;
	}
}

function Stdcache_cacheclear_show()
{
	$root =& XCube_Root::getSingleton();
	
	if (!$root->mController->isEnableCacheFeature()) {
		return false;
	}
	
	if($handler = opendir(XOOPS_CACHE_PATH)) {
		while(($file = readdir($handler)) !== false) {
			if(preg_match("/\w+\.cache\.html$/", $file, $matches)) {
				@unlink(XOOPS_CACHE_PATH . "/" . $matches[0]);
			}
		}
		closedir($handler);
	}
	
	$block['dmy'] = true;
	return $block;
}

?>