ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilUpdateUtilsMailMigration.php
Go to the documentation of this file.
1<?php
2/*
3+-----------------------------------------------------------------------------+
4| ILIAS open source |
5+-----------------------------------------------------------------------------+
6| Copyright (c) 1998-2009 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
29{
30 public static function removeTrailingPathSeparators($path)
31 {
32 $path = preg_replace("/[\/\\\]+$/", "", $path);
33 return $path;
34 }
35
36 public static function getWebspaceDir($mode = "filesystem")
37 {
38 global $ilias;
39
40 if ($mode == "filesystem")
41 {
42 return "./".ILIAS_WEB_DIR."/".$ilias->client_id;
43 }
44 else
45 {
46 if (defined("ILIAS_MODULE"))
47 {
48 return "../".ILIAS_WEB_DIR."/".$ilias->client_id;
49 }
50 else
51 {
52 return "./".ILIAS_WEB_DIR."/".$ilias->client_id;
53 }
54 }
55
56 //return $ilias->ini->readVariable("server","webspace_dir");
57 }
58
59 public static function getDataDir()
60 {
61 return CLIENT_DATA_DIR;
62 }
63
64 public static function makeDir($a_dir)
65 {
66 $a_dir = trim($a_dir);
67
68 // remove trailing slash (bugfix for php 4.2.x)
69 if (substr($a_dir,-1) == "/")
70 {
71 $a_dir = substr($a_dir,0,-1);
72 }
73
74 // check if a_dir comes with a path
75 if (!($path = substr($a_dir,0, strrpos($a_dir,"/") - strlen($a_dir))))
76 {
77 $path = ".";
78 }
79
80 // create directory with file permissions of parent directory
81 umask(0000);
82 return @mkdir($a_dir,fileperms($path));
83 }
84
85 public static function makeDirParents($a_dir)
86 {
87 $dirs = array($a_dir);
88 $a_dir = dirname($a_dir);
89 $last_dirname = '';
90 while($last_dirname != $a_dir)
91 {
92 array_unshift($dirs, $a_dir);
93 $last_dirname = $a_dir;
94 $a_dir = dirname($a_dir);
95 }
96
97 // find the first existing dir
98 $reverse_paths = array_reverse($dirs, TRUE);
99 $found_index = -1;
100 foreach ($reverse_paths as $key => $value)
101 {
102 if ($found_index == -1)
103 {
104 if (is_dir($value))
105 {
106 $found_index = $key;
107 }
108 }
109 }
110
111 umask(0000);
112 foreach ($dirs as $dirindex => $dir)
113 {
114 // starting with the longest existing path
115 if ($dirindex >= $found_index)
116 {
117 if (! file_exists($dir))
118 {
119 if (strcmp(substr($dir,strlen($dir)-1,1),"/") == 0)
120 {
121 // on some systems there is an error when there is a slash
122 // at the end of a directory in mkdir, see Mantis #2554
123 $dir = substr($dir,0,strlen($dir)-1);
124 }
125 if (! mkdir($dir, $umask))
126 {
127 error_log("Can't make directory: $dir");
128 return false;
129 }
130 }
131 elseif (! is_dir($dir))
132 {
133 error_log("$dir is not a directory");
134 return false;
135 }
136 else
137 {
138 // get umask of the last existing parent directory
139 $umask = fileperms($dir);
140 }
141 }
142 }
143 return true;
144 }
145
146 public static function delDir($a_dir)
147 {
148 if (!is_dir($a_dir) || is_int(strpos($a_dir, "..")))
149 {
150 return;
151 }
152
153 $current_dir = opendir($a_dir);
154
155 $files = array();
156
157 // this extra loop has been necessary because of a strange bug
158 // at least on MacOS X. A looped readdir() didn't work
159 // correctly with larger directories
160 // when an unlink happened inside the loop. Getting all files
161 // into the memory first solved the problem.
162 while($entryname = readdir($current_dir))
163 {
164 $files[] = $entryname;
165 }
166
167 foreach($files as $file)
168 {
169 if(is_dir($a_dir."/".$file) and ($file != "." and $file!=".."))
170 {
171 self::delDir(${a_dir}."/".${file});
172 }
173 elseif ($file != "." and $file != "..")
174 {
175 unlink(${a_dir}."/".${file});
176 }
177 }
178
179 closedir($current_dir);
180 @rmdir(${a_dir});
181 }
182
183 public static function getDir($a_dir)
184 {
185 $current_dir = opendir($a_dir);
186
187 $dirs = array();
188 $files = array();
189 while($entry = readdir($current_dir))
190 {
191 if(is_dir($a_dir."/".$entry))
192 {
193 $dirs[$entry] = array("type" => "dir", "entry" => $entry);
194 }
195 else
196 {
197 if ($entry != "." && $entry != "..")
198 {
199 $size = filesize($a_dir."/".$entry);
200 $files[$entry] = array("type" => "file", "entry" => $entry,
201 "size" => $size);
202 }
203 }
204 }
205 ksort($dirs);
206 ksort($files);
207
208 return array_merge($dirs, $files);
209 }
210
211 public static function ilTempnam()
212 {
213 $temp_path = self::getDataDir() . "/temp";
214 if (!is_dir($temp_path))
215 {
216 self::makeDir($temp_path);
217 }
218 $temp_name = tempnam($temp_path, "tmp");
219 // --->
220 // added the following line because tempnam creates a backslash on some
221 // Windows systems which leads to problems, because the "...\tmp..." can be
222 // interpreted as "...{TAB-CHARACTER}...". The normal slash works fine
223 // even under windows (Helmut Schottmüller, 2005-08-31)
224 $temp_name = str_replace("\\", "/", $temp_name);
225 // --->
226 unlink($temp_name);
227 return $temp_name;
228 }
229
230 public static function rename($source, $target)
231 {
232 return @rename($source, $target);
233 }
234}
235?>
print $file
$size
Definition: RandomTest.php:79
$path
Definition: index.php:22
$dirs