~ubuntu-branches/ubuntu/maverick/ilohamail/maverick

« back to all changes in this revision

Viewing changes to IlohaMail/include/cache.FS.inc

  • Committer: Bazaar Package Importer
  • Author(s): Joerg Jaspert
  • Date: 2004-02-04 13:44:37 UTC
  • Revision ID: james.westby@ubuntu.com-20040204134437-kz8j3ui2qa7oq8z2
Tags: upstream-0.8.12
ImportĀ upstreamĀ versionĀ 0.8.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/////////////////////////////////////////////////////////
 
3
//      
 
4
//      include/cache.FS.inc
 
5
//
 
6
//      (C)Copyright 2003 Ryo Chijiiwa <Ryo@IlohaMail.org>
 
7
//
 
8
//      This file is part of IlohaMail, and released under GPL.
 
9
//      See COPYING, or http://www.fsf.org/copyleft/gpl.html
 
10
//
 
11
/////////////////////////////////////////////////////////
 
12
/********************************************************
 
13
        PURPOSE: Unified interface to read/write cache
 
14
 
 
15
********************************************************/
 
16
 
 
17
function cache_read($user, $host, $key){
 
18
        global $CACHE_DIR;
 
19
        
 
20
        //check if file is there
 
21
        $user_dir = ereg_replace("[\\/]", "", $user.".".$host);
 
22
        $path = $CACHE_DIR.$user_dir."/".$key;
 
23
        if (!@file_exists(realpath($path))) return false;
 
24
        
 
25
        //open file
 
26
        $fp = fopen($path, "r");
 
27
        if (!$fp) return false;
 
28
        
 
29
        //read data
 
30
        $data = false;
 
31
        $data = fread($fp, filesize($path));
 
32
        if ($data) $data = unserialize($data);
 
33
        
 
34
        fclose($fp);
 
35
        
 
36
        return $data;
 
37
}
 
38
 
 
39
function cache_write($user, $host, $key, $data){
 
40
        global $CACHE_DIR;
 
41
        
 
42
        //open file for writing
 
43
        $user_dir = ereg_replace("[\\/]", "", $user.".".$host);
 
44
        $path = $CACHE_DIR.$user_dir."/".$key;
 
45
        $fp = @fopen($path, "w");
 
46
        if (!$fp) return false;
 
47
        
 
48
        //write data
 
49
        fputs($fp, serialize($data));
 
50
        
 
51
        fclose($fp);
 
52
        
 
53
        return true;
 
54
}
 
55
 
 
56
function cache_clear($user, $host, $key){
 
57
        global $CACHE_DIR;
 
58
        
 
59
        //check if file is there
 
60
        $user_dir = ereg_replace("[\\/]", "", $user.".".$host);
 
61
        $path = $CACHE_DIR.$user_dir."/".$key;
 
62
        if (!@file_exists(realpath($path))) return false;
 
63
        else return unlink($path);
 
64
}
 
65
 
 
66
function cache_clear_all($user, $host){
 
67
        global $CACHE_DIR;
 
68
        
 
69
        //delete cache files
 
70
        $cacheDir = $CACHE_DIR.ereg_replace("[\\/]", "", $user.".".$host);
 
71
        if (@is_dir(realpath($cacheDir))){
 
72
                if ($handle = opendir($cacheDir)) {
 
73
                        while (false !== ($file = readdir($handle))) { 
 
74
                                if ($file != "." && $file != "..") { 
 
75
                                        $file_path = $cacheDir."/".$file;
 
76
                                        unlink($file_path);
 
77
                                } 
 
78
                        }
 
79
                        closedir($handle); 
 
80
                }
 
81
        }
 
82
}
 
83
 
 
84
?>