ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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{
40 {
41 $path = preg_replace("/[\/\\\]+$/", "", $path);
42 return $path;
43 }
44
45
46
54 public function getWebspaceDir($mode = "filesystem")
55 {
56 global $ilias;
57
58 if ($mode == "filesystem") {
59 return "./" . ILIAS_WEB_DIR . "/" . $ilias->client_id;
60 } else {
61 if (defined("ILIAS_MODULE")) {
62 return "../" . ILIAS_WEB_DIR . "/" . $ilias->client_id;
63 } else {
64 return "./" . ILIAS_WEB_DIR . "/" . $ilias->client_id;
65 }
66 }
67
68 //return $ilias->ini->readVariable("server","webspace_dir");
69 }
70
74 public function getDataDir()
75 {
76 return CLIENT_DATA_DIR;
77 //global $ilias;
78
79 //return $ilias->ini->readVariable("server", "data_dir");
80 }
81
96 public function makeDir($a_dir)
97 {
98 $a_dir = trim($a_dir);
99
100 // remove trailing slash (bugfix for php 4.2.x)
101 if (substr($a_dir, -1) == "/") {
102 $a_dir = substr($a_dir, 0, -1);
103 }
104
105 // check if a_dir comes with a path
106 if (!($path = substr($a_dir, 0, strrpos($a_dir, "/") - strlen($a_dir)))) {
107 $path = ".";
108 }
109
110 // create directory with file permissions of parent directory
111 umask(0000);
112 return @mkdir($a_dir, fileperms($path));
113 }
114
115
128 public function makeDirParents($a_dir)
129 {
130 $dirs = array($a_dir);
131 $a_dir = dirname($a_dir);
132 $last_dirname = '';
133 while ($last_dirname != $a_dir) {
134 array_unshift($dirs, $a_dir);
135 $last_dirname = $a_dir;
136 $a_dir = dirname($a_dir);
137 }
138
139 // find the first existing dir
140 $reverse_paths = array_reverse($dirs, true);
141 $found_index = -1;
142 foreach ($reverse_paths as $key => $value) {
143 if ($found_index == -1) {
144 if (is_dir($value)) {
145 $found_index = $key;
146 }
147 }
148 }
149
150 umask(0000);
151 foreach ($dirs as $dirindex => $dir) {
152 // starting with the longest existing path
153 if ($dirindex >= $found_index) {
154 if (!file_exists($dir)) {
155 if (strcmp(substr($dir, strlen($dir) - 1, 1), "/") == 0) {
156 // on some systems there is an error when there is a slash
157 // at the end of a directory in mkdir, see Mantis #2554
158 $dir = substr($dir, 0, strlen($dir) - 1);
159 }
160
161 if (!mkdir($dir, $umask)) {
162 error_log("Can't make directory: $dir");
163 return false;
164 }
165 } elseif (!is_dir($dir)) {
166 error_log("$dir is not a directory");
167 return false;
168 } else {
169 // get umask of the last existing parent directory
170 $umask = fileperms($dir);
171 }
172 }
173 }
174 return true;
175 }
176
184 public function delDir($a_dir)
185 {
186 if (!is_dir($a_dir) || is_int(strpos($a_dir, ".."))) {
187 return;
188 }
189
190 $current_dir = opendir($a_dir);
191
192 $files = array();
193
194 // this extra loop has been necessary because of a strange bug
195 // at least on MacOS X. A looped readdir() didn't work
196 // correctly with larger directories
197 // when an unlink happened inside the loop. Getting all files
198 // into the memory first solved the problem.
199 while ($entryname = readdir($current_dir)) {
200 $files[] = $entryname;
201 }
202
203 foreach ($files as $file) {
204 if (is_dir($a_dir . "/" . $file) and ($file != "." and $file != "..")) {
205 ilUtil::delDir(${a_dir} . "/" . ${file});
206 } elseif ($file != "." and $file != "..") {
207 unlink(${a_dir} . "/" . ${file});
208 }
209 }
210
211 closedir($current_dir);
212 rmdir(${a_dir});
213 }
214
215
219 public function getDir($a_dir)
220 {
221 $current_dir = opendir($a_dir);
222
223 $dirs = array();
224 $files = array();
225 while ($entry = readdir($current_dir)) {
226 if (is_dir($a_dir . "/" . $entry)) {
227 $dirs[$entry] = array("type" => "dir", "entry" => $entry);
228 } else {
229 $size = filesize($a_dir . "/" . $entry);
230 $files[$entry] = array("type" => "file", "entry" => $entry,
231 "size" => $size);
232 }
233 }
234 ksort($dirs);
235 ksort($files);
236
237 return array_merge($dirs, $files);
238 }
239} // END class.ilUtil
$size
Definition: RandomTest.php:84
$path
Definition: aliased.php:25
An exception for terminatinating execution or to throw for unit testing.
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
$key
Definition: croninfo.php:18
$files
Definition: metarefresh.php:49