XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/include/xpress_cache.php @ 852

Last change on this file since 852 was 719, checked in by toemon, 13 years ago

Windows フィルシステムでディレクトリのis_writable()が正常に取得できないので代替え処理を行う

File size: 2.1 KB
Line 
1<?php
2       
3// is_writable() doesn't operate normally on the windows filesystem
4if(!function_exists("cache_is_writable")):
5        function cache_is_writable(){
6                global $xoops_config;
7                $cache_dir = $xoops_config->xoops_cache_path . '/';
8                $filename = $cache_dir .'xpress_cache_test.txt';
9                $fp = @fopen($filename, "w");
10                if ($fp == false) return false;
11                fclose($fp);
12                return true;
13        }
14endif;
15
16if(!function_exists("xpress_cache_found")):
17    function xpress_cache_found($filename)
18    {
19                $cache_time = 0;
20//        if (file_exists($filename) && ((time() - filemtime($filename)) < $cache_time)) {
21        if (file_exists($filename)) {
22            return true;
23       } else {
24                        return false;
25                }
26    }
27endif;
28
29if(!function_exists("xpress_cache_read")):
30    function xpress_cache_read($mydirname,$collation_key)
31    {
32        global $xoops_config;
33       
34        $cache_dir = $xoops_config->xoops_cache_path . '/';
35        $filename = $cache_dir .$mydirname . '_' . $collation_key;
36        if (xpress_cache_found($filename)) {
37            return file_get_contents($filename);
38       } else {
39                        return '';
40                }
41    }
42endif;
43
44if(!function_exists("xpress_cache_write")):
45    function xpress_cache_write($mydirname,$collation_key,$content)
46    {
47                global $xoops_config;
48                $cache_dir = $xoops_config->xoops_cache_path . '/';
49                $cache_time = 0;
50
51        $filename = $cache_dir .$mydirname . '_' . $collation_key;
52//        if ((time() - @filemtime($filename)) > $cache_time) {
53            $fp = fopen($filename, "w");
54            flock($fp, 2);
55            fputs($fp, $content);
56            fclose($fp);
57 //       }
58    }
59endif;
60
61if(!function_exists("xpress_block_cache_clear")):
62    function xpress_cache_clear($mydirname)
63    {
64                global $xoops_config;
65                $cache_dir = $xoops_config->xoops_cache_path . '/';
66                $cache_time = 0;
67        if ($dh = opendir($cache_dir)) {
68            while (($file = readdir($dh)) !== false) {
69                if (preg_match('/^' . preg_quote($mydirname) . '/', $file)) {
70                    unlink($cache_dir.$file);
71                }
72            }
73            closedir($dh);
74        }
75    }
76endif;
77
78?>
Note: See TracBrowser for help on using the repository browser.