1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13: if (!defined('FRAMEWORKS_ART_FUNCTIONS_CACHE')):
14: define('FRAMEWORKS_ART_FUNCTIONS_CACHE', true);
15:
16: 17: 18: 19: 20:
21: function mod_generateCacheId_byGroup($groups = null)
22: {
23: global $xoopsUser;
24:
25: if (!empty($groups) && is_array($groups)) {
26: } elseif (is_object($xoopsUser)) {
27: $groups = $xoopsUser->getGroups();
28: }
29: if (!empty($groups) && is_array($groups)) {
30: sort($groups);
31: $contentCacheId = substr(md5(implode(',', $groups) . XOOPS_DB_PASS . XOOPS_DB_NAME), 0, strlen(XOOPS_DB_USER) * 2);
32: } else {
33: $contentCacheId = XOOPS_GROUP_ANONYMOUS;
34: }
35:
36: return $contentCacheId;
37: }
38:
39: 40: 41: 42: 43:
44: function mod_generateCacheId($groups = null)
45: {
46: return mod_generateCacheId_byGroup($groups);
47: }
48:
49: 50: 51: 52: 53: 54: 55: 56:
57: function mod_createFile($data, $name = null, $dirname = null, $root_path = XOOPS_CACHE_PATH)
58: {
59: global $xoopsModule;
60:
61: $name = $name ? : (string)time();
62: $dirname = $dirname ? : (is_object($xoopsModule) ? $xoopsModule->getVar('dirname', 'n') : 'system');
63:
64: xoops_load('XoopsCache');
65: $key = "{$dirname}_{$name}";
66:
67: return XoopsCache::write($key, $data);
68: }
69:
70: 71: 72: 73: 74: 75: 76:
77: function mod_createCacheFile($data, $name = null, $dirname = null)
78: {
79: return mod_createFile($data, $name, $dirname);
80: }
81:
82: 83: 84: 85: 86: 87: 88: 89:
90: function mod_createCacheFile_byGroup($data, $name = null, $dirname = null, $groups = null)
91: {
92: $name .= mod_generateCacheId_byGroup();
93:
94: return mod_createCacheFile($data, $name, $dirname);
95: }
96:
97: 98: 99: 100: 101: 102: 103:
104: function mod_loadFile($name, $dirname = null, $root_path = XOOPS_CACHE_PATH)
105: {
106: global $xoopsModule;
107:
108: $data = null;
109:
110: if (empty($name)) {
111: return $data;
112: }
113: $dirname = $dirname ? : (is_object($xoopsModule) ? $xoopsModule->getVar('dirname', 'n') : 'system');
114: xoops_load('XoopsCache');
115: $key = "{$dirname}_{$name}";
116:
117: return XoopsCache::read($key);
118: }
119:
120: 121: 122: 123: 124: 125:
126: function mod_loadCacheFile($name, $dirname = null)
127: {
128: $data = mod_loadFile($name, $dirname);
129:
130: return $data;
131: }
132:
133: 134: 135: 136: 137: 138: 139:
140: function mod_loadCacheFile_byGroup($name, $dirname = null, $groups = null)
141: {
142: $name .= mod_generateCacheId_byGroup();
143: $data = mod_loadFile($name, $dirname);
144:
145: return $data;
146: }
147:
148:
149:
150: 151: 152: 153: 154: 155: 156:
157: function mod_clearFile($name = '', $dirname = null, $root_path = XOOPS_CACHE_PATH)
158: {
159: if (empty($dirname)) {
160: $pattern = $dirname ? "{$dirname}_{$name}.*\.php" : "[^_]+_{$name}.*\.php";
161: if ($handle = opendir($root_path)) {
162: while (false !== ($file = readdir($handle))) {
163: if (is_file($root_path . '/' . $file) && preg_match("/{$pattern}$/", $file)) {
164: @unlink($root_path . '/' . $file);
165: }
166: }
167: closedir($handle);
168: }
169: } else {
170: $files = (array)glob($root_path . "/*{$dirname}_{$name}*.php");
171: foreach ($files as $file) {
172: @unlink($file);
173: }
174: }
175:
176: return true;
177: }
178:
179: 180: 181: 182: 183: 184:
185: function mod_clearCacheFile($name = '', $dirname = null)
186: {
187: return mod_clearFile($name, $dirname);
188: }
189:
190: 191: 192: 193: 194:
195: function mod_clearSmartyCache($pattern = '')
196: {
197: global $xoopsModule;
198:
199: if (empty($pattern)) {
200: $dirname = (is_object($xoopsModule) ? $xoopsModule->getVar('dirname', 'n') : 'system');
201: $pattern = "/(^{$dirname}\^.*\.html$|blk_{$dirname}_.*[^\.]*\.html$)/";
202: }
203: if ($handle = opendir(XOOPS_CACHE_PATH)) {
204: while (false !== ($file = readdir($handle))) {
205: if (is_file(XOOPS_CACHE_PATH . '/' . $file) && preg_match($pattern, $file)) {
206: @unlink(XOOPS_CACHE_PATH . '/' . $file);
207: }
208: }
209: closedir($handle);
210: }
211:
212: return true;
213: }
214:
215: endif;
216: