ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilUpdateUtils.php
Go to the documentation of this file.
1<?php
2/*
3+-----------------------------------------------------------------------------+
4| ILIAS open source |
5+-----------------------------------------------------------------------------+
6| Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7| |
8| This program is free software; you can redistribute it and/or |
9| modify it under the terms of the GNU General Public License |
10| as published by the Free Software Foundation; either version 2 |
11| of the License, or (at your option) any later version. |
12| |
13| This program is distributed in the hope that it will be useful, |
14| but WITHOUT ANY WARRANTY; without even the implied warranty of |
15| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16| GNU General Public License for more details. |
17| |
18| You should have received a copy of the GNU General Public License |
19| along with this program; if not, write to the Free Software |
20| Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21+-----------------------------------------------------------------------------+
22*/
23
38{
39
41 {
42 $path = preg_replace("/[\/\\\]+$/", "", $path);
43 return $path;
44 }
45
46
47
55 function getWebspaceDir($mode = "filesystem")
56 {
57 global $ilias;
58
59 if ($mode == "filesystem")
60 {
61 return "./".ILIAS_WEB_DIR."/".$ilias->client_id;
62 }
63 else
64 {
65 if (defined("ILIAS_MODULE"))
66 {
67 return "../".ILIAS_WEB_DIR."/".$ilias->client_id;
68 }
69 else
70 {
71 return "./".ILIAS_WEB_DIR."/".$ilias->client_id;
72 }
73 }
74
75 //return $ilias->ini->readVariable("server","webspace_dir");
76 }
77
81 function getDataDir()
82 {
83 return CLIENT_DATA_DIR;
84 //global $ilias;
85
86 //return $ilias->ini->readVariable("server", "data_dir");
87 }
88
103 function makeDir($a_dir)
104 {
105 $a_dir = trim($a_dir);
106
107 // remove trailing slash (bugfix for php 4.2.x)
108 if (substr($a_dir,-1) == "/")
109 {
110 $a_dir = substr($a_dir,0,-1);
111 }
112
113 // check if a_dir comes with a path
114 if (!($path = substr($a_dir,0, strrpos($a_dir,"/") - strlen($a_dir))))
115 {
116 $path = ".";
117 }
118
119 // create directory with file permissions of parent directory
120 umask(0000);
121 return @mkdir($a_dir,fileperms($path));
122 }
123
124
137 function makeDirParents($a_dir)
138 {
139 $dirs = array($a_dir);
140 $a_dir = dirname($a_dir);
141 $last_dirname = '';
142 while($last_dirname != $a_dir)
143 {
144 array_unshift($dirs, $a_dir);
145 $last_dirname = $a_dir;
146 $a_dir = dirname($a_dir);
147 }
148
149 // find the first existing dir
150 $reverse_paths = array_reverse($dirs, TRUE);
151 $found_index = -1;
152 foreach ($reverse_paths as $key => $value)
153 {
154 if ($found_index == -1)
155 {
156 if (is_dir($value))
157 {
158 $found_index = $key;
159 }
160 }
161 }
162
163 umask(0000);
164 foreach ($dirs as $dirindex => $dir)
165 {
166 // starting with the longest existing path
167 if ($dirindex >= $found_index)
168 {
169 if (! file_exists($dir))
170 {
171 if (strcmp(substr($dir,strlen($dir)-1,1),"/") == 0)
172 {
173 // on some systems there is an error when there is a slash
174 // at the end of a directory in mkdir, see Mantis #2554
175 $dir = substr($dir,0,strlen($dir)-1);
176 }
177
178 if (! mkdir($dir, $umask))
179 {
180 error_log("Can't make directory: $dir");
181 return false;
182 }
183 }
184 elseif (! is_dir($dir))
185 {
186 error_log("$dir is not a directory");
187 return false;
188 }
189 else
190 {
191 // get umask of the last existing parent directory
192 $umask = fileperms($dir);
193 }
194 }
195 }
196 return true;
197 }
198
206 function delDir($a_dir)
207 {
208 if (!is_dir($a_dir) || is_int(strpos($a_dir, "..")))
209 {
210 return;
211 }
212
213 $current_dir = opendir($a_dir);
214
215 $files = array();
216
217 // this extra loop has been necessary because of a strange bug
218 // at least on MacOS X. A looped readdir() didn't work
219 // correctly with larger directories
220 // when an unlink happened inside the loop. Getting all files
221 // into the memory first solved the problem.
222 while($entryname = readdir($current_dir))
223 {
224 $files[] = $entryname;
225 }
226
227 foreach($files as $file)
228 {
229 if(is_dir($a_dir."/".$file) and ($file != "." and $file!=".."))
230 {
231 ilUtil::delDir(${a_dir}."/".${file});
232 }
233 elseif ($file != "." and $file != "..")
234 {
235 unlink(${a_dir}."/".${file});
236 }
237 }
238
239 closedir($current_dir);
240 rmdir(${a_dir});
241 }
242
243
247 function getDir($a_dir)
248 {
249 $current_dir = opendir($a_dir);
250
251 $dirs = array();
252 $files = array();
253 while($entry = readdir($current_dir))
254 {
255 if(is_dir($a_dir."/".$entry))
256 {
257 $dirs[$entry] = array("type" => "dir", "entry" => $entry);
258 }
259 else
260 {
261 $size = filesize($a_dir."/".$entry);
262 $files[$entry] = array("type" => "file", "entry" => $entry,
263 "size" => $size);
264 }
265 }
266 ksort($dirs);
267 ksort($files);
268
269 return array_merge($dirs, $files);
270 }
271
272
273
274
275} // END class.ilUtil
276
277
278?>
print $file
$size
Definition: RandomTest.php:79
util class various functions, usage as namespace
removeTrailingPathSeparators($path)
makeDirParents($a_dir)
Create a new directory and all parent directories.
makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
getWebspaceDir($mode="filesystem")
get webspace directory
delDir($a_dir)
removes a dir and all its content (subdirs and files) recursively
getDir($a_dir)
get directory
getDataDir()
get data directory (outside webspace)
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
$path
Definition: index.php:22
$dirs