Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00037 class ilUpdateUtils
00038 {
00039
00040 function removeTrailingPathSeparators($path)
00041 {
00042 $path = preg_replace("/[\/\\\]+$/", "", $path);
00043 return $path;
00044 }
00045
00046
00047
00055 function getWebspaceDir($mode = "filesystem")
00056 {
00057 global $ilias;
00058
00059 if ($mode == "filesystem")
00060 {
00061 return "./".ILIAS_WEB_DIR."/".$ilias->client_id;
00062 }
00063 else
00064 {
00065 if (defined("ILIAS_MODULE"))
00066 {
00067 return "../".ILIAS_WEB_DIR."/".$ilias->client_id;
00068 }
00069 else
00070 {
00071 return "./".ILIAS_WEB_DIR."/".$ilias->client_id;
00072 }
00073 }
00074
00075
00076 }
00077
00081 function getDataDir()
00082 {
00083 return CLIENT_DATA_DIR;
00084
00085
00086
00087 }
00088
00103 function makeDir($a_dir)
00104 {
00105 $a_dir = trim($a_dir);
00106
00107
00108 if (substr($a_dir,-1) == "/")
00109 {
00110 $a_dir = substr($a_dir,0,-1);
00111 }
00112
00113
00114 if (!($path = substr($a_dir,0, strrpos($a_dir,"/") - strlen($a_dir))))
00115 {
00116 $path = ".";
00117 }
00118
00119
00120 umask(0000);
00121 return @mkdir($a_dir,fileperms($path));
00122 }
00123
00124
00137 function makeDirParents($a_dir)
00138 {
00139 $dirs = array($a_dir);
00140 $a_dir = dirname($a_dir);
00141 $last_dirname = '';
00142 while($last_dirname != $a_dir)
00143 {
00144 array_unshift($dirs, $a_dir);
00145 $last_dirname = $a_dir;
00146 $a_dir = dirname($a_dir);
00147 }
00148
00149
00150 $reverse_paths = array_reverse($dirs, TRUE);
00151 $found_index = -1;
00152 foreach ($reverse_paths as $key => $value)
00153 {
00154 if ($found_index == -1)
00155 {
00156 if (is_dir($value))
00157 {
00158 $found_index = $key;
00159 }
00160 }
00161 }
00162
00163 umask(0000);
00164 foreach ($dirs as $dirindex => $dir)
00165 {
00166
00167 if ($dirindex >= $found_index)
00168 {
00169 if (! file_exists($dir))
00170 {
00171 if (strcmp(substr($dir,strlen($dir)-1,1),"/") == 0)
00172 {
00173
00174
00175 $dir = substr($dir,0,strlen($dir)-1);
00176 }
00177
00178 if (! mkdir($dir, $umask))
00179 {
00180 error_log("Can't make directory: $dir");
00181 return false;
00182 }
00183 }
00184 elseif (! is_dir($dir))
00185 {
00186 error_log("$dir is not a directory");
00187 return false;
00188 }
00189 else
00190 {
00191
00192 $umask = fileperms($dir);
00193 }
00194 }
00195 }
00196 return true;
00197 }
00198
00206 function delDir($a_dir)
00207 {
00208 if (!is_dir($a_dir) || is_int(strpos($a_dir, "..")))
00209 {
00210 return;
00211 }
00212
00213 $current_dir = opendir($a_dir);
00214
00215 $files = array();
00216
00217
00218
00219
00220
00221
00222 while($entryname = readdir($current_dir))
00223 {
00224 $files[] = $entryname;
00225 }
00226
00227 foreach($files as $file)
00228 {
00229 if(is_dir($a_dir."/".$file) and ($file != "." and $file!=".."))
00230 {
00231 ilUtil::delDir(${a_dir}."/".${file});
00232 }
00233 elseif ($file != "." and $file != "..")
00234 {
00235 unlink(${a_dir}."/".${file});
00236 }
00237 }
00238
00239 closedir($current_dir);
00240 rmdir(${a_dir});
00241 }
00242
00243
00247 function getDir($a_dir)
00248 {
00249 $current_dir = opendir($a_dir);
00250
00251 $dirs = array();
00252 $files = array();
00253 while($entry = readdir($current_dir))
00254 {
00255 if(is_dir($a_dir."/".$entry))
00256 {
00257 $dirs[$entry] = array("type" => "dir", "entry" => $entry);
00258 }
00259 else
00260 {
00261 $size = filesize($a_dir."/".$entry);
00262 $files[$entry] = array("type" => "file", "entry" => $entry,
00263 "size" => $size);
00264 }
00265 }
00266 ksort($dirs);
00267 ksort($files);
00268
00269 return array_merge($dirs, $files);
00270 }
00271
00272
00273
00274
00275 }
00276
00277
00278 ?>