1: <?php
2:
3: if (!defined('XOOPS_ROOT_PATH')) exit();
4:
5: class Stdcache_CacheclearBlock extends Legacy_BlockProcedure
6: {
7: var $_mFilePath = null;
8:
9: function prepare()
10: {
11: $this->_mFilePath = XOOPS_CACHE_PATH . "/" . md5(XOOPS_SALT) . ".cache.html";
12: return parent::prepare();
13: }
14:
15: function execute()
16: {
17: $root =& XCube_Root::getSingleton();
18:
19: if (!$root->mController->isEnableCacheFeature()) {
20: return false;
21: }
22:
23:
24:
25:
26: $options = explode('|', $this->_mBlock->get('options'));
27: if (!file_exists($this->_mFilePath)) {
28: $this->updateTimer();
29: }
30:
31: if (filemtime($this->_mFilePath) < time() - intval($options[0]) * 60) {
32: if($handler = opendir(XOOPS_CACHE_PATH)) {
33: while(($file = readdir($handler)) !== false) {
34: if(preg_match("/\w+\.cache\.html$/", $file, $matches)) {
35: @unlink(XOOPS_CACHE_PATH . "/" . $matches[0]);
36: }
37: }
38: closedir($handler);
39: }
40:
41: $this->updateTimer();
42: }
43: }
44:
45: function updateTimer()
46: {
47: $fp = fopen($this->_mFilePath, "wb");
48: fclose ($fp);
49: }
50:
51: function isDisplay()
52: {
53: return false;
54: }
55:
56: function getOptionForm()
57: {
58: $options = explode('|', $this->_mBlock->get('options'));
59:
60: $root =& XCube_Root::getSingleton();
61: $renderSystem =& $root->getRenderSystem('Legacy_AdminRenderSystem');
62: $renderTarget =& $renderSystem->createRenderTarget();
63:
64: $renderTarget->setAttribute('legacy_module', 'stdCache');
65: $renderTarget->setTemplateName('block_cacheclear_option.html');
66: $renderTarget->setAttribute('timer', $options[0]);
67:
68: $renderSystem->render($renderTarget);
69: return $renderTarget->getResult();
70: }
71: }
72:
73: ?>