ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 ($a_obj_id=0, $a_pos_id=0)
 Constructor call base constructors checks if directory is writable and sets the optional obj_id. More...
 
 getObjId ()
 
 getPosId ()
 
 setPosId ($a_id)
 
 getForumPath ()
 get forum path @access public More...
 
 ilClone ($a_new_obj_id, $a_new_pos_id)
 
 delete ()
 
 storeUploadedFile ($files)
 Store uploaded files in filesystem. More...
 
 unlinkFiles ($a_filenames)
 unlink files: expects an array of filenames e.g. More...
 
 unlinkFile ($a_filename)
 unlink one uploaded file expects a filename e.g 'foo' More...
 
 getAbsolutePath ($a_path)
 get absolute path of filename More...
 
 getFileDataByMD5Filename ($a_md5_filename)
 get file data of a specific attachment More...
 
 unlinkFilesByMD5Filenames ($a_md5_filename)
 get file data of a specific attachment More...
 
 checkFilesExist ($a_files)
 check if files exist More...
 
 __checkPath ()
 
 __checkReadWrite ()
 check if directory is writable overwritten method from base class @access private More...
 
 __initDirectory ()
 init directory overwritten method @access public More...
 
 __rotateFiles ($a_path)
 rotate files with same name recursive method More...
 
 deliverFile ($file)
 
 deliverZipFile ()
 
- Public Member Functions inherited from ilFileData
 __construct ()
 Constructor class bas constructor and read path of directory from ilias.ini setup an mail object @access public. More...
 
 checkPath ($a_path)
 check if path exists and is writable More...
 
 getPath ()
 get Path @access public More...
 
- Public Member Functions inherited from ilFile
 __construct ()
 Constructor get ilias object @access public. More...
 
 deleteTrailingSlash ($a_path)
 delete trailing slash of path variables More...
 

Data Fields

 $obj_id
 
 $pos_id
 
 $forum_path
 
- Data Fields inherited from ilFile
 $path
 
 $ilias
 

Protected Member Functions

 createZipFile ()
 

Private Attributes

 $error
 

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
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

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

Constructor call base constructors checks if directory is writable and sets the optional obj_id.

Parameters
integeregerobj_id @access public

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

39 {
40 global $DIC;
41 $this->error = $DIC['ilErr'];
42
43 define('FORUM_PATH', 'forum');
45 $this->forum_path = parent::getPath() . "/" . FORUM_PATH;
46
47 // IF DIRECTORY ISN'T CREATED CREATE IT
48 if (!$this->__checkPath()) {
49 $this->__initDirectory();
50 }
51 $this->obj_id = $a_obj_id;
52 $this->pos_id = $a_pos_id;
53 }
error($a_errmsg)
set error message @access public
__initDirectory()
init directory overwritten method @access public
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$DIC
Definition: xapitoken.php:46

References $DIC, __checkPath(), ILIAS\GlobalScreen\Provider\__construct(), __initDirectory(), and error().

+ Here is the call graph for this function:

Member Function Documentation

◆ __checkPath()

ilFileDataForum::__checkPath ( )

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

353 {
354 if (!@file_exists($this->getForumPath())) {
355 return false;
356 }
357 $this->__checkReadWrite();
358
359 return true;
360 }
getForumPath()
get forum path @access public
__checkReadWrite()
check if directory is writable overwritten method from base class @access private

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 ( )

check if directory is writable overwritten method from base class @access private

Returns
bool

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

368 {
369 if (is_writable($this->forum_path) && is_readable($this->forum_path)) {
370 return true;
371 } else {
372 $this->error->raiseError("Forum directory is not readable/writable by webserver", $this->error->FATAL);
373 }
374 }

References error().

Referenced by __checkPath().

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

◆ __initDirectory()

ilFileDataForum::__initDirectory ( )

init directory overwritten method @access public

Returns
string path

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

382 {
383 if (is_writable($this->getPath())) {
384 if (mkdir($this->getPath() . '/' . FORUM_PATH)) {
385 if (chmod($this->getPath() . '/' . FORUM_PATH, 0755)) {
386 $this->forum_path = $this->getPath() . '/' . FORUM_PATH;
387 return true;
388 }
389 }
390 }
391 return false;
392 }
getPath()
get Path @access public

References ilFileData\getPath().

Referenced by __construct().

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

◆ __rotateFiles()

ilFileDataForum::__rotateFiles (   $a_path)

rotate files with same name recursive method

Parameters
stringfilename @access private
Returns
bool

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

401 {
402 if (file_exists($a_path)) {
403 $this->__rotateFiles($a_path . ".old");
404 return \ilFileUtils::rename($a_path, $a_path . '.old');
405 }
406 return true;
407 }
__rotateFiles($a_path)
rotate files with same name recursive method

References __rotateFiles().

Referenced by __rotateFiles(), and storeUploadedFile().

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

◆ checkFilesExist()

ilFileDataForum::checkFilesExist (   $a_files)

check if files exist

Parameters
arrayfilenames to check @access public
Returns
bool

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

339 {
340 if ($a_files) {
341 foreach ($a_files as $file) {
342 if (!file_exists($this->forum_path . '/' . $this->obj_id . '_' . $this->pos_id . '_' . $file)) {
343 return false;
344 }
345 }
346 return true;
347 }
348 return true;
349 }

◆ createZipFile()

ilFileDataForum::createZipFile ( )
protected
Returns
null|string

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

445 {
446 $filesOfPost = $this->getFilesOfPost();
447 ksort($filesOfPost);
448
449 ilUtil::makeDirParents($this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId());
450 $tmp_dir = $this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId();
451 foreach ($filesOfPost as $file) {
452 @copy($file['path'], $tmp_dir . '/' . $file['name']);
453 }
454
455 $zip_file = null;
456 if (ilUtil::zip($tmp_dir, $this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId() . '.zip')) {
457 $zip_file = $this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId() . '.zip';
458 }
459
460 return $zip_file;
461 }
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
static makeDirParents($a_dir)
Create a new directory and all parent directories.

References getForumPath(), getObjId(), getPosId(), ilUtil\makeDirParents(), and ilUtil\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 186 of file class.ilFileDataForum.php.

187 {
188 foreach ($this->getFiles() as $file) {
189 if (file_exists($this->getForumPath() . "/" . $this->getObjId() . "_" . $file["name"])) {
190 unlink($this->getForumPath() . "/" . $this->getObjId() . "_" . $file["name"]);
191 }
192 }
193 return true;
194 }

References getForumPath(), and getObjId().

+ Here is the call graph for this function:

◆ deliverFile()

ilFileDataForum::deliverFile (   $file)
Parameters
$file
Returns
bool|void

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

414 {
415 if (!$path = $this->getFileDataByMD5Filename($file)) {
416 return ilUtil::sendFailure($this->lng->txt('error_reading_file'), true);
417 } else {
418 return ilUtil::deliverFile($path['path'], $path['clean_filename']);
419 }
420 }
getFileDataByMD5Filename($a_md5_filename)
get file data of a specific attachment
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.

References ilFile\$path, ilUtil\deliverFile(), getFileDataByMD5Filename(), and ilUtil\sendFailure().

+ Here is the call graph for this function:

◆ deliverZipFile()

ilFileDataForum::deliverZipFile ( )

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

426 {
427 global $DIC;
428
429 $zip_file = $this->createZipFile();
430 if (!$zip_file) {
431 ilUtil::sendFailure($DIC->language()->txt('error_reading_file'), true);
432 return false;
433 } else {
434 $post = new ilForumPost($this->getPosId());
435 ilUtil::deliverFile($zip_file, $post->getSubject() . '.zip', '', false, true, false);
436 ilUtil::delDir($this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId());
437 exit();
438 }
439 }
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
exit
Definition: login.php:29

References $DIC, createZipFile(), ilUtil\delDir(), ilUtil\deliverFile(), exit, getForumPath(), getObjId(), getPosId(), and ilUtil\sendFailure().

+ Here is the call graph for this function:

◆ getAbsolutePath()

ilFileDataForum::getAbsolutePath (   $a_path)

get absolute path of filename

Parameters
stringrelative path @access public
Returns
string absolute path

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

278 {
279 return $this->forum_path . '/' . $this->obj_id . '_' . $this->pos_id . "_" . $a_path;
280 }

◆ getFileDataByMD5Filename()

ilFileDataForum::getFileDataByMD5Filename (   $a_md5_filename)

get file data of a specific attachment

Parameters
stringmd5 encrypted filename @access public
Returns
array filedata

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

289 {
290 $files = ilUtil::getDir($this->forum_path);
291 foreach ((array) $files as $file) {
292 if ($file['type'] == 'file' && md5($file['entry']) == $a_md5_filename) {
293 return array(
294 'path' => $this->forum_path . '/' . $file['entry'],
295 'filename' => $file['entry'],
296 'clean_filename' => str_replace($this->obj_id . '_' . $this->pos_id . '_', '', $file['entry'])
297 );
298 }
299 }
300
301 return false;
302 }
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory

References ilUtil\getDir().

Referenced by deliverFile().

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

◆ getForumPath()

ilFileDataForum::getForumPath ( )

get forum path @access public

Returns
string path

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

References $forum_path.

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

+ Here is the caller graph for this function:

◆ getObjId()

ilFileDataForum::getObjId ( )

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

56 {
57 return $this->obj_id;
58 }

References $obj_id.

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

+ Here is the caller graph for this function:

◆ getPosId()

ilFileDataForum::getPosId ( )

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

60 {
61 return $this->pos_id;
62 }

References $pos_id.

Referenced by createZipFile(), and deliverZipFile().

+ Here is the caller graph for this function:

◆ ilClone()

ilFileDataForum::ilClone (   $a_new_obj_id,
  $a_new_pos_id 
)

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

177 {
178 foreach ($this->getFilesOfPost() as $file) {
179 @copy(
180 $this->getForumPath() . "/" . $this->obj_id . "_" . $this->pos_id . "_" . $file["name"],
181 $this->getForumPath() . "/" . $a_new_obj_id . "_" . $a_new_pos_id . "_" . $file["name"]
182 );
183 }
184 return true;
185 }

References getForumPath().

+ Here is the call graph for this function:

◆ setPosId()

ilFileDataForum::setPosId (   $a_id)

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

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

◆ storeUploadedFile()

ilFileDataForum::storeUploadedFile (   $files)

Store uploaded files in filesystem.

Parameters
array$filesCopy of $_FILES array, @access public
Returns
bool

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

206 {
207 if (isset($files['name']) && is_array($files['name'])) {
208 foreach ($files['name'] as $index => $name) {
209 // remove trailing '/'
210 $name = rtrim($name, '/');
211
213 $temp_name = $files['tmp_name'][$index];
214 $error = $files['error'][$index];
215
216 if (strlen($filename) && strlen($temp_name) && $error == 0) {
217 $path = $this->getForumPath() . '/' . $this->obj_id . '_' . $this->pos_id . '_' . $filename;
218
219 $this->__rotateFiles($path);
221 }
222 }
223
224 return true;
225 } elseif (isset($files['name']) && is_string($files['name'])) {
226 // remove trailing '/'
227 $files['name'] = rtrim($files['name'], '/');
228
229 $filename = ilUtil::_sanitizeFilemame($files['name']);
230 $temp_name = $files['tmp_name'];
231
232 $path = $this->getForumPath() . '/' . $this->obj_id . '_' . $this->pos_id . '_' . $filename;
233
234 $this->__rotateFiles($path);
236
237 return true;
238 }
239
240 return false;
241 }
$filename
Definition: buildRTE.php:89
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static _sanitizeFilemame($a_filename)
if($format !==null) $name
Definition: metadata.php:230
$index
Definition: metadata.php:128

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

+ Here is the call graph for this function:

◆ unlinkFile()

ilFileDataForum::unlinkFile (   $a_filename)

unlink one uploaded file expects a filename e.g 'foo'

Parameters
stringfilename to delete @access public
Returns
bool

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

266 {
267 if (file_exists($this->forum_path . '/' . $this->obj_id . '_' . $this->pos_id . '_' . $a_filename)) {
268 return unlink($this->forum_path . '/' . $this->obj_id . '_' . $this->pos_id . "_" . $a_filename);
269 }
270 }

Referenced by unlinkFiles().

+ Here is the caller graph for this function:

◆ unlinkFiles()

ilFileDataForum::unlinkFiles (   $a_filenames)

unlink files: expects an array of filenames e.g.

array('foo','bar')

Parameters
arrayfilenames to delete @access public
Returns
string error message with filename that couldn't be deleted

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

249 {
250 if (is_array($a_filenames)) {
251 foreach ($a_filenames as $file) {
252 if (!$this->unlinkFile($file)) {
253 return $file;
254 }
255 }
256 }
257 return '';
258 }
unlinkFile($a_filename)
unlink one uploaded file expects a filename e.g 'foo'

References unlinkFile().

+ Here is the call graph for this function:

◆ unlinkFilesByMD5Filenames()

ilFileDataForum::unlinkFilesByMD5Filenames (   $a_md5_filename)

get file data of a specific attachment

Parameters
string|arraymd5 encrypted filename or array of multiple md5 encrypted files @access public
Returns
boolean status

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

311 {
312 $files = ilUtil::getDir($this->forum_path);
313 if (is_array($a_md5_filename)) {
314 foreach ((array) $files as $file) {
315 if ($file['type'] == 'file' && in_array(md5($file['entry']), $a_md5_filename)) {
316 unlink($this->forum_path . '/' . $file['entry']);
317 }
318 }
319
320 return true;
321 } else {
322 foreach ((array) $files as $file) {
323 if ($file['type'] == 'file' && md5($file['entry']) == $a_md5_filename) {
324 return unlink($this->forum_path . '/' . $file['entry']);
325 }
326 }
327 }
328
329 return false;
330 }

References ilUtil\getDir().

+ Here is the call graph for this function:

Field Documentation

◆ $error

ilFileDataForum::$error
private

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

Referenced by storeUploadedFile().

◆ $forum_path

ilFileDataForum::$forum_path

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

Referenced by getForumPath().

◆ $obj_id

ilFileDataForum::$obj_id

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

Referenced by getObjId().

◆ $pos_id

ilFileDataForum::$pos_id

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

Referenced by getPosId().


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