1: <?php
2: /**
3: *
4: * @package Legacy
5: * @version $Id: Legacy_CacheInformation.class.php,v 1.4 2008/09/25 15:12:00 kilica Exp $
6: * @copyright Copyright 2005-2007 XOOPS Cube Project <https://github.com/xoopscube/legacy>
7: * @license https://github.com/xoopscube/legacy/blob/master/docs/GPL_V2.txt GNU GENERAL PUBLIC LICENSE Version 2
8: *
9: */
10:
11: if (!defined('XOOPS_ROOT_PATH')) exit();
12:
13: /**
14: * The structure which have a policy and an information of a module, which
15: * Legacy_Controller must know. In the later version, this class may be
16: * replaced with just array.
17: *
18: * For a performance, this class has reset() to reuse a object.
19: */
20: class Legacy_AbstractCacheInformation
21: {
22: /**
23: * Array of uid. This is an information for cache store program to generate
24: * an unique file name. Uid isn't must. Sets identity data.
25: *
26: * @access public
27: * @var Array of uid
28: */
29: var $mIdentityArr = array();
30:
31: /**
32: * Array of groupid. This is an information for cache store program to
33: * generate an unique file name.
34: *
35: * @access public
36: * @var Array of groupid
37: */
38: var $mGroupArr = array();
39:
40: /**
41: * Boolean flag indicating whether this object asks caching to the
42: * controller.
43: *
44: * @access private
45: * @var bool
46: */
47: var $_mEnableCache = false;
48:
49: /**
50: * For a special cache mechanism, free to use hashmap.
51: *
52: * @access public
53: * @var array
54: */
55: var $mAttributes = array();
56:
57: function Legacy_AbstractCacheInformation()
58: {
59: }
60:
61: /**
62: * Gets a value indicating whether someone has tried to set a flag to this
63: * object.
64: * @return bool
65: */
66: function hasSetEnable()
67: {
68: return $this->_mEnableCache !== false;
69: }
70:
71: /**
72: * Sets a flag indicating whether this object decides executing cache.
73: * @param bool $flag
74: */
75: function setEnableCache($flag)
76: {
77: $this->_mEnableCache = $flag;
78: }
79:
80: /**
81: * Gets a flag indicating whether this object decides executing cache.
82: * @return bool
83: */
84: function isEnableCache()
85: {
86: return $this->_mEnableCache;
87: }
88:
89: /**
90: * Resets member properties to reuse this object.
91: */
92: function reset()
93: {
94: $this->mIdentityArr = array();
95: $this->mGroupArr = array();
96: $this->_mEnableCache = null;
97: }
98:
99: function getCacheFilePath()
100: {
101: }
102: }
103:
104: class Legacy_ModuleCacheInformation extends Legacy_AbstractCacheInformation
105: {
106: /**
107: * [READ ONLY] Xoops Module Object.
108: *
109: * @access protected
110: * @var XoopsModule
111: */
112: var $mModule = null;
113:
114: /**
115: * The current URL used as a base for a cache file name. This should be
116: * modified by modules to not make extra cache files.
117: *
118: * @access public
119: * @var string
120: */
121: var $mURL = null;
122:
123: /**
124: * @var XCube_Delegate
125: */
126: var $mGetCacheFilePath = null;
127:
128: function Legacy_ModuleCacheInformation()
129: {
130: parent::Legacy_AbstractCacheInformation();
131: $this->mGetCacheFilePath = new XCube_Delegate();
132: $this->mGetCacheFilePath->register('Legacy_ModuleCacheInformation.GetCacheFilePath');
133: }
134:
135: /**
136: * Sets a module object.
137: * @param XoopsModule $module
138: */
139: function setModule(&$module)
140: {
141: $this->mModule =& $module;
142: }
143:
144: function reset()
145: {
146: parent::reset();
147: $this->mModule = null;
148: $this->mURL = null;
149: }
150:
151: /**
152: * Gets a file path of a cache file for module contents.
153: * @param Legacy_ModuleCacheInformation $cacheInfo
154: * @return string
155: */
156: function getCacheFilePath()
157: {
158: $filepath = null;
159: $this->mGetCacheFilePath->call(new XCube_Ref($filepath), $this);
160:
161: if (!$filepath) {
162: $id = md5(XOOPS_SALT . $this->mURL . "(" . implode("_", $this->mIdentityArr) . ")" . implode("_", $this->mGroupArr));
163: $filepath = XOOPS_CACHE_PATH . "/" . $id . ".cache.html";
164: }
165:
166: return $filepath;
167: }
168: }
169:
170: class Legacy_BlockCacheInformation extends Legacy_AbstractCacheInformation
171: {
172: /**
173: * [READ ONLY] Xoops Block Object.
174: *
175: * @access protected
176: * @var XoopsBlock
177: */
178: var $mBlock = null;
179:
180: /**
181: * @var XCube_Delegate
182: */
183: var $mGetCacheFilePath = null;
184:
185: function Legacy_BlockCacheInformation()
186: {
187: parent::Legacy_AbstractCacheInformation();
188: $this->mGetCacheFilePath = new XCube_Delegate();
189: $this->mGetCacheFilePath->register('Legacy_BlockCachInformation.getCacheFilePath');
190: }
191:
192: /**
193: * Sets a block object.
194: *
195: * @param Legacy_AbstractBlockProcedure $blockProcedure
196: */
197: function setBlock(&$blockProcedure)
198: {
199: $this->mBlock =& $blockProcedure->_mBlock;
200: }
201:
202: function reset()
203: {
204: parent::reset();
205: $this->mBlock = null;
206: }
207:
208: /**
209: * Gets a file path of a cache file for module contents.
210: * @param Legacy_BlockCacheInformation $cacheInfo
211: * @return string
212: */
213: function getCacheFilePath()
214: {
215: $filepath = null;
216: $this->mGetCacheFilePath->call(new XCube_Ref($filepath), $this);
217:
218: if (!$filepath) {
219: $id = md5(XOOPS_SALT . '(' . implode('_', $this->mIdentityArr) . ')' . implode('_', $this->mGroupArr));
220: $filepath = $this->getCacheFileBase($this->mBlock->get('bid'), $id);
221: }
222: return $filepath;
223: }
224:
225: static function getCacheFileBase($bid, $context) {
226: return XOOPS_CACHE_PATH . '/' . urlencode(XOOPS_URL) . '_bid'. $bid . '_' . $context . '.cache.html';
227: }
228: }
229:
230: ?>
231: