Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.VaultFile.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Retrieve and store file in Vault
9  *
10  * @author Anakeen 2004
11  * @version $Id: Class.VaultFile.php,v 1.23 2008/05/27 12:46:06 marc Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  */
15 /**
16  */
17 
18 include_once ("VAULT/Class.VaultDiskStorage.php");
19 include_once ("Class.Log.php");
20 define("VAULT_FMODE", 0600);
21 define("VAULT_DMODE", 0700);
22 
23 class VaultFile
24 {
25 
26  function __construct($access, $vaultname = "Sample", $idf = - 1)
27  {
28 
29  if (!isset($chrono)) $this->chrono = FALSE;
30  else $this->chrono = $chrono;
31  $this->idf = $idf;
32  $this->name = $vaultname;
33  $this->logger = new Log("", "vault", $this->name);
34  if ($this->chrono) $this->logger->warning("Running with chrono !!!!");
35  $this->dbaccess = $access;
36 
37  $this->u_owner = HTTP_USER;
38  $this->g_owner = HTTP_USER;
39  $this->f_mode = 0600;
40  $this->d_mode = 0700;
41  $this->type = "fs";
42  $this->use_cache = TRUE;
43  switch ($this->type) {
44  case "fs":
45  $this->use_cache = FALSE;
46  $this->logger->debug("Set Storage Type to FS");
47  $this->storage = new VaultDiskStorage($access, $fs);
48  break;
49 
50  default:
51  // Not implemented yet
52 
53  }
54 }
55 // ---------------------------------------------------------
56 function Show($id_file, &$infos, $teng_lname = "")
57 {
58  // ---------------------------------------------------------
59  if ($this->chrono) $this->logger->start("Show");
60  $msg = $this->storage->Show($id_file, $infos, $teng_lname);
61  if ($msg != '') $this->logger->error($msg);
62  if ($this->chrono) $this->logger->end("Show");
63  return ($msg);
64 }
65 // ---------------------------------------------------------
66 function Retrieve($id_file, &$infos)
67 {
68  // ---------------------------------------------------------
69  if ($this->chrono) $this->logger->start("Retrieve");
70  if (isset($info)) unset($infos);
71  if ($this->use_cache) {
72  $msg = $this->cache->Show($id_file, $infosC);
73  if ($msg != '') {
74  $msg = $this->storage->Show($id_file, $infosS);
75  if ($msg != '') {
76  $msg = $this->cache->StoreIn($id_file, $info["path"], $info["size"]);
77  if ($msg == '') {
78  $msg = $this->cache->Show($id_file, $infosC);
79  $info = $infoC;
80  return '';
81  } else {
82  $this->logger->warning("Cache insertion failure [$msg].");
83  $info = $infoS;
84  return '';
85  }
86  } else {
87  $this->logger->error($msg);
88  $info = NULL;
89  return ($msg);
90  }
91  } else {
92  $info = $infosC;
93  return ('');
94  }
95  } else {
96  $infos = new stdClass();
97  $msg = $this->storage->Show($id_file, $infos);
98 
99  if ($msg != '') $this->logger->error($msg);
100  if ($this->chrono) $this->logger->end("Retrieve");
101  return ($msg);
102  }
103 }
104 // ---------------------------------------------------------
105 function Store($infile, $public_access, &$id, $fsname = "", $te_name = "", $te_id_file = 0)
106 {
107  // ---------------------------------------------------------
108  if ($this->chrono) $this->logger->start("Store");
109  $id = - 1;
110  if (!file_exists($infile) || !is_readable($infile) || !is_file($infile)) {
111  $this->logger->error("Can't access file [" . $infile . "].");
112  $msg = _("can't access file");
113  } else {
114  if (!is_bool($public_access)) {
115  $public_access = FALSE;
116  $this->logger->warning("Access mode forced to RESTRICTED for " . $infile . "].");
117  }
118  $msg = $this->storage->Store($infile, $public_access, $id, $fsname, $te_name, $te_id_file);
119  if ($msg) $this->logger->error($msg);
120  }
121  if ($this->chrono) $this->logger->end("Store");
122  return ($msg);
123 }
124 // ---------------------------------------------------------
125 function Save($infile, $public_access, $id)
126 {
127  // ---------------------------------------------------------
128  if ($this->chrono) $this->logger->start("Save");
129 
130  if (!is_bool($public_access)) {
131  $public_access = FALSE;
132  $this->logger->warning("Access mode forced to RESTRICTED for " . $infile . "].");
133  }
134 
135  $msg = $this->storage->Save($infile, $public_access, $id);
136  if ($msg) $this->logger->error($msg);
137 
138  $this->storage->mime_t = getTextMimeFile($infile);
139  $this->storage->mime_s = getSysMimeFile($infile, $this->storage->name);
140  $msg = $this->storage->Modify();
141  if ($this->chrono) $this->logger->end("Save");
142  return ($msg);
143 }
144 /**
145  * Modification of properties if file
146  */
147 function Rename($id_file, $newname)
148 {
149  // ---------------------------------------------------------
150  if ($this->chrono) $this->logger->start("Rename");
151 
152  if ($newname != "") {
153  $nn = str_replace(array(
154  '/',
155  '\\',
156  '?',
157  '*',
158  ':'
159  ) , '-', $newname);
160  if ($nn != $newname) {
161  addWarningMsg(sprintf(_("Some characters are not authorized for file name %s. They are replaced by -") , $nn));
162  $newname = $nn;
163  }
164 
165  include_once ("WHAT/Lib.FileMime.php");
166  $infile = $this->storage->getPath();
167  $oldname = $this->storage->name;
168  $msg = $this->storage->Show($id_file, $infos);
169  $this->storage->name = $newname;
170  $this->storage->mime_t = getTextMimeFile($infile, $this->storage->name);
171  $this->storage->mime_s = getSysMimeFile($infile, $this->storage->name);
172  $msg = $this->storage->Modify();
173  if ($msg == "") {
174  $pio = pathinfo($oldname);
175  $pin = pathinfo($newname);
176  $epio = $pio['extension'];
177  if ($epio == "") $epio = "nop";
178  $epin = $pin['extension'];
179  if ($epin == "") $epin = "nop";
180  if ($epio != $epin) {
181  // need rename physically file
182  $path = pathinfo($infos->path);
183  if (preg_match("|(.*)/([0-9]+)\.[^\.]*|", $infos->path, $reg)) {
184  $newpath = $reg[1] . "/" . $reg[2] . "." . $epin;
185  rename($infos->path, $newpath);
186  }
187  }
188  }
189  if ($msg) $this->logger->error($msg);
190  }
191 
192  if ($this->chrono) $this->logger->end("Rename");
193  return ($msg);
194 }
195 // ---------------------------------------------------------
196 function Stats(&$s)
197 {
198  // ---------------------------------------------------------
199  if ($this->chrono) $this->logger->start("Stats");
200  $this->storage->Stats($s);
201  if ($this->chrono) $this->logger->end("Stats");
202  return '';
203 }
204 // ---------------------------------------------------------
205 function ListFiles(&$s)
206 {
207  // ---------------------------------------------------------
208  if ($this->chrono) $this->logger->start("ListFiles");
209  $this->storage->ListFiles($s);
210  if ($this->chrono) $this->logger->end("ListFiles");
211  return '';
212 }
213 // ---------------------------------------------------------
214 function Destroy($id)
215 {
216  // ---------------------------------------------------------
217  if ($this->chrono) $this->logger->start("Destroy");
218  if ($this->use_cache) $this->cache->Delete($id);
219  $msg = $this->storage->Destroy($id);
220  if ($msg != '') $this->logger->error($msg);
221  if ($this->chrono) $this->logger->end("Destroy");
222  return $msg;
223 }
224 }
225 ?>
← centre documentaire © anakeen - published under CC License - Dynacase