1 | <?php |
---|
2 | |
---|
3 | if(!function_exists("xpress_cache_found")): |
---|
4 | function xpress_cache_found($filename) |
---|
5 | { |
---|
6 | $cache_time = 0; |
---|
7 | // if (file_exists($filename) && ((time() - filemtime($filename)) < $cache_time)) { |
---|
8 | if (file_exists($filename)) { |
---|
9 | return true; |
---|
10 | } else { |
---|
11 | return false; |
---|
12 | } |
---|
13 | } |
---|
14 | endif; |
---|
15 | |
---|
16 | if(!function_exists("xpress_cache_read")): |
---|
17 | function xpress_cache_read($mydirname,$collation_key) |
---|
18 | { |
---|
19 | global $xoops_config; |
---|
20 | if(defined('XOOPS_ROOT_PATH')){ |
---|
21 | $cache_dir = XOOPS_ROOT_PATH . '/cache/'; |
---|
22 | } else { |
---|
23 | $cache_dir = $xoops_config->xoops_root_path . '/cache/'; |
---|
24 | } |
---|
25 | $filename = $cache_dir .$mydirname . '_' . $collation_key; |
---|
26 | if (xpress_cache_found($filename)) { |
---|
27 | return file_get_contents($filename); |
---|
28 | } else { |
---|
29 | return ''; |
---|
30 | } |
---|
31 | } |
---|
32 | endif; |
---|
33 | |
---|
34 | if(!function_exists("xpress_cache_write")): |
---|
35 | function xpress_cache_write($mydirname,$collation_key,$content) |
---|
36 | { |
---|
37 | global $xoops_config; |
---|
38 | $cache_dir = $xoops_config->xoops_root_path . '/cache/'; |
---|
39 | $cache_time = 0; |
---|
40 | |
---|
41 | $filename = $cache_dir .$mydirname . '_' . $collation_key; |
---|
42 | // if ((time() - @filemtime($filename)) > $cache_time) { |
---|
43 | $fp = fopen($filename, "w"); |
---|
44 | flock($fp, 2); |
---|
45 | fputs($fp, $content); |
---|
46 | fclose($fp); |
---|
47 | // } |
---|
48 | } |
---|
49 | endif; |
---|
50 | |
---|
51 | if(!function_exists("xpress_block_cache_clear")): |
---|
52 | function xpress_cache_clear($mydirname) |
---|
53 | { |
---|
54 | global $xoops_config; |
---|
55 | $cache_dir = $xoops_config->xoops_root_path . '/cache/'; |
---|
56 | $cache_time = 0; |
---|
57 | if ($dh = opendir($cache_dir)) { |
---|
58 | while (($file = readdir($dh)) !== false) { |
---|
59 | if (preg_match('/^' . preg_quote($mydirname) . '/', $file)) { |
---|
60 | unlink($cache_dir.$file); |
---|
61 | } |
---|
62 | } |
---|
63 | closedir($dh); |
---|
64 | } |
---|
65 | } |
---|
66 | endif; |
---|
67 | |
---|
68 | ?> |
---|