XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
functions.cache.php
Go to the documentation of this file.
1 <?php
14 if (!defined("FRAMEWORKS_ART_FUNCTIONS_CACHE")):
15 define("FRAMEWORKS_ART_FUNCTIONS_CACHE", true);
16 
18 {
19  global $xoopsUser;
20 
21  if (!empty($groups) && is_array($groups)) {
22  } elseif (is_object( $xoopsUser )) {
23  $groups = $xoopsUser->getGroups();
24  }
25  if (!empty($groups) && is_array($groups)) {
26  sort($groups);
27  $contentCacheId = substr( md5(implode(",", $groups).XOOPS_DB_PASS.XOOPS_DB_NAME), 0, strlen(XOOPS_DB_USER) * 2 );
28  } else {
29  $contentCacheId = XOOPS_GROUP_ANONYMOUS;
30  }
31 
32  return $contentCacheId;
33 }
34 
35 function mod_generateCacheId($groups = null)
36 {
38 }
39 
40 function mod_createFile($data, $name = null, $dirname = null, $root_path = XOOPS_CACHE_PATH)
41 {
42  global $xoopsModule;
43 
44  $name = ($name) ? $name : strval(time());
45  $dirname = ($dirname) ? $dirname : (is_object($xoopsModule) ? $xoopsModule->getVar("dirname", "n") : "system");
46 
47  xoops_load('XoopsCache');
48  $key = "{$dirname}_{$name}";
49  return XoopsCache::write($key, $data);
50 }
51 
52 function mod_createCacheFile($data, $name = null, $dirname = null)
53 {
54  return mod_createFile($data, $name, $dirname);
55 }
56 
57 function mod_createCacheFile_byGroup($data, $name = null, $dirname = null, $groups = null)
58 {
59  $name .= mod_generateCacheId_byGroup();
60  return mod_createCacheFile($data, $name, $dirname);
61 }
62 
63 function mod_loadFile($name, $dirname = null, $root_path = XOOPS_CACHE_PATH)
64 {
65  global $xoopsModule;
66 
67  $data = null;
68 
69  if (empty($name)) return $data;
70  $dirname = ($dirname) ? $dirname : (is_object($xoopsModule) ? $xoopsModule->getVar("dirname", "n") : "system");
71  xoops_load('XoopsCache');
72  $key = "{$dirname}_{$name}";
73  return XoopsCache::read($key);
74 }
75 
76 function mod_loadCacheFile($name, $dirname = null)
77 {
78  $data = mod_loadFile($name, $dirname);
79  return $data;
80 }
81 
82 function mod_loadCacheFile_byGroup($name, $dirname = null, $groups = null)
83 {
84  $name .= mod_generateCacheId_byGroup();
85  $data = mod_loadFile($name, $dirname);
86  return $data;
87 }
88 
89 /* Shall we use the function of glob for better performance ? */
90 
91 function mod_clearFile($name = "", $dirname = null, $root_path = XOOPS_CACHE_PATH)
92 {
93  if (empty($dirname)) {
94  $pattern = ($dirname) ? "{$dirname}_{$name}.*\.php" : "[^_]+_{$name}.*\.php";
95  if ($handle = opendir($root_path)) {
96  while (false !== ($file = readdir($handle))) {
97  if (is_file($root_path . '/' . $file) && preg_match("/{$pattern}$/", $file)) {
98  @unlink($root_path . '/' . $file);
99  }
100  }
101  closedir($handle);
102  }
103  } else {
104  $files = (array) glob($root_path . "/*{$dirname}_{$name}*.php");
105  foreach ($files as $file) {
106  @unlink($file);
107  }
108  }
109  return true;
110 }
111 
112 function mod_clearCacheFile($name = "", $dirname = null)
113 {
114  return mod_clearFile($name, $dirname);
115 }
116 
117 function mod_clearSmartyCache($pattern = "")
118 {
119  global $xoopsModule;
120 
121  if (empty($pattern)) {
122  $dirname = (is_object($xoopsModule) ? $xoopsModule->getVar("dirname", "n") : "system");
123  $pattern = "/(^{$dirname}\^.*\.html$|blk_{$dirname}_.*[^\.]*\.html$)/";
124  }
125  if ($handle = opendir(XOOPS_CACHE_PATH)) {
126  while (false !== ($file = readdir($handle))) {
127  if (is_file(XOOPS_CACHE_PATH . '/' . $file) && preg_match($pattern, $file)) {
128  @unlink(XOOPS_CACHE_PATH . '/' . $file);
129  }
130  }
131  closedir($handle);
132  }
133  return true;
134 }
135 
137 ?>