ILIAS  release_8 Revision v8.24
ilFileDataForum Class Reference

This class handles all operations on files for the forum object. More...

+ Inheritance diagram for ilFileDataForum:
+ Collaboration diagram for ilFileDataForum:

Public Member Functions

 __construct (int $a_obj_id=0, int $a_pos_id=0)
 
 getObjId ()
 
 getPosId ()
 
 setPosId (int $a_id)
 
 getForumPath ()
 
 getFilesOfPost ()
 
 ilClone (int $a_new_obj_id, int $a_new_pos_id)
 
 delete ()
 
 storeUploadedFile (array $files)
 
 unlinkFile (string $a_filename)
 
 getFileDataByMD5Filename (string $hashedFilename)
 
 unlinkFilesByMD5Filenames ($hashedFilenameOrFilenames)
 
 deliverFile (string $file)
 
 deliverZipFile ()
 
- Public Member Functions inherited from ilFileData
 __construct ()
 
 checkPath (string $a_path)
 
 getPath ()
 
- Public Member Functions inherited from ilFile
 deleteTrailingSlash (string $a_path)
 delete trailing slash of path variables More...
 

Protected Member Functions

 createZipFile ()
 

Private Member Functions

 checkForumPath ()
 
 checkReadWrite ()
 
 initDirectory ()
 
 rotateFiles (string $a_path)
 

Private Attributes

const FORUM_PATH = 'forum'
 
int $obj_id
 
int $pos_id
 
string $forum_path
 
ilErrorHandling $error
 
ilGlobalTemplateInterface $main_tpl
 

Additional Inherited Members

- Protected Attributes inherited from ilFile
string $path
 

Detailed Description

This class handles all operations on files for the forum object.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 26 of file class.ilFileDataForum.php.

Constructor & Destructor Documentation

◆ __construct()

ilFileDataForum::__construct ( int  $a_obj_id = 0,
int  $a_pos_id = 0 
)

Definition at line 36 of file class.ilFileDataForum.php.

37 {
38 global $DIC;
39 $this->main_tpl = $DIC->ui()->mainTemplate();
40
41 $this->error = $DIC['ilErr'];
42
44 $this->forum_path = $this->getPath() . '/' . self::FORUM_PATH;
45
46 if (!$this->checkForumPath()) {
47 $this->initDirectory();
48 }
49 $this->obj_id = $a_obj_id;
50 $this->pos_id = $a_pos_id;
51 }
error(string $a_errmsg)
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References $DIC, ILIAS\GlobalScreen\Provider\__construct(), checkForumPath(), error(), FORUM_PATH, ilFileData\getPath(), and initDirectory().

+ Here is the call graph for this function:

Member Function Documentation

◆ checkForumPath()

ilFileDataForum::checkForumPath ( )
private

Definition at line 270 of file class.ilFileDataForum.php.

270 : bool
271 {
272 if (!is_dir($this->getForumPath())) {
273 return false;
274 }
275 $this->checkReadWrite();
276
277 return true;
278 }

References checkReadWrite(), and getForumPath().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkReadWrite()

ilFileDataForum::checkReadWrite ( )
private

Definition at line 280 of file class.ilFileDataForum.php.

280 : void
281 {
282 if (!is_writable($this->forum_path) || !is_readable($this->forum_path)) {
283 $this->error->raiseError('Forum directory is not readable/writable by webserver', $this->error->FATAL);
284 }
285 }

References error().

Referenced by checkForumPath().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createZipFile()

ilFileDataForum::createZipFile ( )
protected

Definition at line 333 of file class.ilFileDataForum.php.

333 : ?string
334 {
335 $filesOfPost = $this->getFilesOfPost();
336 ksort($filesOfPost);
337
338 ilFileUtils::makeDirParents($this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId());
339 $tmp_dir = $this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId();
340 foreach ($filesOfPost as $file) {
341 copy($file['path'], $tmp_dir . '/' . $file['name']);
342 }
343
344 $zip_file = null;
346 $tmp_dir,
347 $this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId() . '.zip'
348 )) {
349 $zip_file = $this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId() . '.zip';
350 }
351
352 return $zip_file;
353 }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static zip(string $a_dir, string $a_file, bool $compress_content=false)
zips given directory/file into given zip.file

References getFilesOfPost(), getForumPath(), getObjId(), getPosId(), ilFileUtils\makeDirParents(), and ilFileUtils\zip().

Referenced by deliverZipFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete()

ilFileDataForum::delete ( )

Definition at line 168 of file class.ilFileDataForum.php.

168 : bool
169 {
170 foreach ($this->getFiles() as $file) {
171 if (is_file($this->getForumPath() . '/' . $this->getObjId() . '_' . $file['name'])) {
172 unlink($this->getForumPath() . '/' . $this->getObjId() . '_' . $file['name']);
173 }
174 }
175
176 return true;
177 }

References getForumPath(), and getObjId().

+ Here is the call graph for this function:

◆ deliverFile()

ilFileDataForum::deliverFile ( string  $file)

Definition at line 305 of file class.ilFileDataForum.php.

305 : void
306 {
307 global $DIC;
308
309 if (($path = $this->getFileDataByMD5Filename($file)) !== null) {
310 ilFileDelivery::deliverFileLegacy($path['path'], $path['clean_filename']);
311 } else {
312 $this->main_tpl->setOnScreenMessage('failure', $DIC->lanuage()->txt('error_reading_file'), true);
313 }
314 }
getFileDataByMD5Filename(string $hashedFilename)
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
string $path

References $DIC, ilFile\$path, ilFileDelivery\deliverFileLegacy(), and getFileDataByMD5Filename().

+ Here is the call graph for this function:

◆ deliverZipFile()

ilFileDataForum::deliverZipFile ( )

Definition at line 316 of file class.ilFileDataForum.php.

316 : bool
317 {
318 global $DIC;
319
320 $zip_file = $this->createZipFile();
321 if (!$zip_file) {
322 $this->main_tpl->setOnScreenMessage('failure', $DIC->language()->txt('error_reading_file'), true);
323 return false;
324 }
325
326 $post = new ilForumPost($this->getPosId());
327 ilFileDelivery::deliverFileLegacy($zip_file, $post->getSubject() . '.zip', '', false, true, false);
328 ilFileUtils::delDir($this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId());
329 $DIC->http()->close();
330 return true; // never
331 }
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
$post
Definition: ltitoken.php:49

References $DIC, $post, createZipFile(), ilFileUtils\delDir(), ilFileDelivery\deliverFileLegacy(), getForumPath(), getObjId(), and getPosId().

+ Here is the call graph for this function:

◆ getFileDataByMD5Filename()

ilFileDataForum::getFileDataByMD5Filename ( string  $hashedFilename)
Parameters
string$hashedFilename
Returns
array{path: string, filename: string, clean_filename: string}|null

Definition at line 228 of file class.ilFileDataForum.php.

228 : ?array
229 {
230 $files = ilFileUtils::getDir($this->forum_path);
231 foreach ($files as $file) {
232 if ($file['type'] === 'file' && md5($file['entry']) === $hashedFilename) {
233 return [
234 'path' => $this->forum_path . '/' . $file['entry'],
235 'filename' => $file['entry'],
236 'clean_filename' => str_replace($this->obj_id . '_' . $this->pos_id . '_', '', $file['entry'])
237 ];
238 }
239 }
240
241 return null;
242 }
static getDir(string $a_dir, bool $a_rec=false, ?string $a_sub_dir="")
get directory

References ilFileUtils\getDir().

Referenced by deliverFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFilesOfPost()

ilFileDataForum::getFilesOfPost ( )
Returns
array<string, array{path: string, md5: string, name: string, size: int, ctime: string}>

Definition at line 106 of file class.ilFileDataForum.php.

106 : array
107 {
108 $directoryIterator = new DirectoryIterator($this->forum_path);
109 $filterIterator = new RegexIterator($directoryIterator, "/^{$this->obj_id}_{$this->getPosId()}_(.+)$/");
110
111 $files = array();
112 foreach ($filterIterator as $file) {
113 if ($file->isFile()) {
114 list($obj_id, $pos_id, $rest) = explode('_', $file->getFilename(), 3);
115 $files[$rest] = array(
116 'path' => $file->getPathname(),
117 'md5' => md5($this->obj_id . '_' . $this->pos_id . '_' . $rest),
118 'name' => $rest,
119 'size' => $file->getSize(),
120 'ctime' => date('Y-m-d H:i:s', $file->getCTime())
121 );
122 }
123 }
124
125 return $files;
126 }
$rest
Definition: goto.php:49

References $obj_id, $pos_id, and $rest.

Referenced by createZipFile(), and ilClone().

+ Here is the caller graph for this function:

◆ getForumPath()

ilFileDataForum::getForumPath ( )

Definition at line 68 of file class.ilFileDataForum.php.

68 : string
69 {
70 return $this->forum_path;
71 }

References $forum_path.

Referenced by checkForumPath(), createZipFile(), delete(), deliverZipFile(), ilClone(), and storeUploadedFile().

+ Here is the caller graph for this function:

◆ getObjId()

ilFileDataForum::getObjId ( )

Definition at line 53 of file class.ilFileDataForum.php.

53 : int
54 {
55 return $this->obj_id;
56 }

References $obj_id.

Referenced by createZipFile(), delete(), and deliverZipFile().

+ Here is the caller graph for this function:

◆ getPosId()

ilFileDataForum::getPosId ( )

Definition at line 58 of file class.ilFileDataForum.php.

58 : int
59 {
60 return $this->pos_id;
61 }

References $pos_id.

Referenced by createZipFile(), and deliverZipFile().

+ Here is the caller graph for this function:

◆ ilClone()

ilFileDataForum::ilClone ( int  $a_new_obj_id,
int  $a_new_pos_id 
)

Definition at line 157 of file class.ilFileDataForum.php.

157 : bool
158 {
159 foreach ($this->getFilesOfPost() as $file) {
160 copy(
161 $this->getForumPath() . '/' . $this->obj_id . '_' . $this->pos_id . '_' . $file['name'],
162 $this->getForumPath() . '/' . $a_new_obj_id . '_' . $a_new_pos_id . '_' . $file['name']
163 );
164 }
165 return true;
166 }

References getFilesOfPost(), and getForumPath().

+ Here is the call graph for this function:

◆ initDirectory()

ilFileDataForum::initDirectory ( )
private

Definition at line 287 of file class.ilFileDataForum.php.

287 : void
288 {
289 if (is_writable($this->getPath()) && mkdir($this->getPath() . '/' . self::FORUM_PATH) && chmod(
290 $this->getPath() . '/' . self::FORUM_PATH,
291 0755
292 )) {
293 $this->forum_path = $this->getPath() . '/' . self::FORUM_PATH;
294 }
295 }

References FORUM_PATH, and ilFileData\getPath().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rotateFiles()

ilFileDataForum::rotateFiles ( string  $a_path)
private

Definition at line 297 of file class.ilFileDataForum.php.

297 : void
298 {
299 if (is_file($a_path)) {
300 $this->rotateFiles($a_path . '.old');
301 ilFileUtils::rename($a_path, $a_path . '.old');
302 }
303 }
rotateFiles(string $a_path)
static rename(string $a_source, string $a_target)

References ilFileUtils\rename(), and rotateFiles().

Referenced by rotateFiles(), and storeUploadedFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setPosId()

ilFileDataForum::setPosId ( int  $a_id)

Definition at line 63 of file class.ilFileDataForum.php.

63 : void
64 {
65 $this->pos_id = $a_id;
66 }

◆ storeUploadedFile()

ilFileDataForum::storeUploadedFile ( array  $files)

Definition at line 179 of file class.ilFileDataForum.php.

179 : bool
180 {
181 if (isset($files['name']) && is_array($files['name'])) {
182 foreach ($files['name'] as $index => $name) {
183 $name = rtrim($name, '/');
185 $temp_name = $files['tmp_name'][$index];
186 $error = $files['error'][$index];
187
188 if ($filename !== '' && $temp_name !== '' && (int) $error === 0) {
189 $path = $this->getForumPath() . '/' . $this->obj_id . '_' . $this->pos_id . '_' . $filename;
190
191 $this->rotateFiles($path);
193 }
194 }
195
196 return true;
197 }
198
199 if (isset($files['name']) && is_string($files['name'])) {
200 $files['name'] = rtrim($files['name'], '/');
202 $temp_name = $files['tmp_name'];
203
204 $path = $this->getForumPath() . '/' . $this->obj_id . '_' . $this->pos_id . '_' . $filename;
205
206 $this->rotateFiles($path);
208
209 return true;
210 }
211
212 return false;
213 }
$filename
Definition: buildRTE.php:78
ilErrorHandling $error
static _sanitizeFilemame(string $a_filename)
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
if($format !==null) $name
Definition: metadata.php:247
$index
Definition: metadata.php:145

References $error, $filename, $index, $name, ilFile\$path, ilFileUtils\_sanitizeFilemame(), getForumPath(), ilFileUtils\moveUploadedFile(), and rotateFiles().

+ Here is the call graph for this function:

◆ unlinkFile()

ilFileDataForum::unlinkFile ( string  $a_filename)

Definition at line 215 of file class.ilFileDataForum.php.

215 : bool
216 {
217 if (is_file($this->forum_path . '/' . $this->obj_id . '_' . $this->pos_id . '_' . $a_filename)) {
218 return unlink($this->forum_path . '/' . $this->obj_id . '_' . $this->pos_id . '_' . $a_filename);
219 }
220
221 return false;
222 }

◆ unlinkFilesByMD5Filenames()

ilFileDataForum::unlinkFilesByMD5Filenames (   $hashedFilenameOrFilenames)
Parameters
string | string[]$hashedFilenameOrFilenames
Returns
bool

Definition at line 248 of file class.ilFileDataForum.php.

248 : bool
249 {
250 $files = ilFileUtils::getDir($this->forum_path);
251 if (is_array($hashedFilenameOrFilenames)) {
252 foreach ($files as $file) {
253 if ($file['type'] === 'file' && in_array(md5($file['entry']), $hashedFilenameOrFilenames, true)) {
254 unlink($this->forum_path . '/' . $file['entry']);
255 }
256 }
257
258 return true;
259 }
260
261 foreach ($files as $file) {
262 if ($file['type'] === 'file' && md5($file['entry']) === $hashedFilenameOrFilenames) {
263 return unlink($this->forum_path . '/' . $file['entry']);
264 }
265 }
266
267 return false;
268 }

References ilFileUtils\getDir().

+ Here is the call graph for this function:

Field Documentation

◆ $error

ilErrorHandling ilFileDataForum::$error
private

Definition at line 33 of file class.ilFileDataForum.php.

Referenced by storeUploadedFile().

◆ $forum_path

string ilFileDataForum::$forum_path
private

Definition at line 32 of file class.ilFileDataForum.php.

Referenced by getForumPath().

◆ $main_tpl

ilGlobalTemplateInterface ilFileDataForum::$main_tpl
private

Definition at line 34 of file class.ilFileDataForum.php.

◆ $obj_id

int ilFileDataForum::$obj_id
private

Definition at line 30 of file class.ilFileDataForum.php.

Referenced by getFilesOfPost(), and getObjId().

◆ $pos_id

int ilFileDataForum::$pos_id
private

Definition at line 31 of file class.ilFileDataForum.php.

Referenced by getFilesOfPost(), and getPosId().

◆ FORUM_PATH

const ilFileDataForum::FORUM_PATH = 'forum'
private

Definition at line 28 of file class.ilFileDataForum.php.

Referenced by __construct(), and initDirectory().


The documentation for this class was generated from the following file: