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