ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 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 private More...
 
 __initDirectory ()
 init directory overwritten method public More...
 
 __rotateFiles ($a_path)
 rotate files with same name recursive method More...
 
 deliverFile ($file)
 
- Public Member Functions inherited from ilFileData
 __construct ()
 Constructor class bas constructor and read path of directory from ilias.ini setup an mail object public. More...
 
 checkPath ($a_path)
 check if path exists and is writable More...
 
 getPath ()
 get Path public More...
 
- Public Member Functions inherited from ilFile
 __construct ()
 Constructor get ilias object 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 ()
 

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 15 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 public

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

References __checkPath(), and __initDirectory().

40  {
41  define('FORUM_PATH', 'forum');
42  parent::__construct();
43  $this->forum_path = parent::getPath()."/".FORUM_PATH;
44 
45  // IF DIRECTORY ISN'T CREATED CREATE IT
46  if(!$this->__checkPath())
47  {
48  $this->__initDirectory();
49  }
50  $this->obj_id = $a_obj_id;
51  $this->pos_id = $a_pos_id;
52  }
__initDirectory()
init directory overwritten method public
+ Here is the call graph for this function:

Member Function Documentation

◆ __checkPath()

ilFileDataForum::__checkPath ( )

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

References __checkReadWrite(), and getForumPath().

Referenced by __construct().

386  {
387  if(!@file_exists($this->getForumPath()))
388  {
389  return false;
390  }
391  $this->__checkReadWrite();
392 
393  return true;
394  }
__checkReadWrite()
check if directory is writable overwritten method from base class private
getForumPath()
get forum path public
+ 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 private

Returns
bool

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

Referenced by __checkPath().

402  {
403  if(is_writable($this->forum_path) && is_readable($this->forum_path))
404  {
405  return true;
406  }
407  else
408  {
409  $this->ilias->raiseError("Forum directory is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
410  }
411  }
redirection script todo: (a better solution should control the processing via a xml file) ...
+ Here is the caller graph for this function:

◆ __initDirectory()

ilFileDataForum::__initDirectory ( )

init directory overwritten method public

Returns
string path

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

References ilFileData\getPath().

Referenced by __construct().

419  {
420  if(is_writable($this->getPath()))
421  {
422  if(mkdir($this->getPath().'/'.FORUM_PATH))
423  {
424  if(chmod($this->getPath().'/'.FORUM_PATH,0755))
425  {
426  $this->forum_path = $this->getPath().'/'.FORUM_PATH;
427  return true;
428  }
429  }
430  }
431  return false;
432  }
getPath()
get Path public
+ 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 private
Returns
bool

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

Referenced by storeUploadedFile().

441  {
442  if(file_exists($a_path))
443  {
444  $this->__rotateFiles($a_path.".old");
445  return \ilFileUtils::rename($a_path, $a_path . '.old');
446  }
447  return true;
448  }
__rotateFiles($a_path)
rotate files with same name recursive method
+ Here is the caller graph for this function:

◆ checkFilesExist()

ilFileDataForum::checkFilesExist (   $a_files)

check if files exist

Parameters
arrayfilenames to check public
Returns
bool

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

References $file.

369  {
370  if($a_files)
371  {
372  foreach($a_files as $file)
373  {
374  if(!file_exists($this->forum_path.'/'.$this->obj_id.'_'.$this->pos_id.'_'.$file))
375  {
376  return false;
377  }
378  }
379  return true;
380  }
381  return true;
382  }
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file

◆ createZipFile()

ilFileDataForum::createZipFile ( )
protected
Returns
null|string

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

References $file, getForumPath(), getObjId(), getPosId(), ilUtil\makeDirParents(), and ilUtil\zip().

Referenced by deliverFile().

495  {
496  $filesOfPost = $this->getFilesOfPost();
497  ksort($filesOfPost);
498 
499  ilUtil::makeDirParents($this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId());
500  $tmp_dir = $this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId();
501  foreach($filesOfPost as $file)
502  {
503  @copy($file['path'], $tmp_dir . '/' . $file['name']);
504  }
505 
506  $zip_file = null;
507  if(ilUtil::zip($tmp_dir, $this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId() . '.zip'))
508  {
509  $zip_file = $this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId() . '.zip';
510  }
511 
512  return $zip_file;
513  }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
getForumPath()
get forum path public
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete()

ilFileDataForum::delete ( )

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

References $file, getForumPath(), and getObjId().

Referenced by ilObjForumGUI\publishDraftObject().

197  {
198  foreach($this->getFiles() as $file)
199  {
200  if(file_exists($this->getForumPath()."/".$this->getObjId()."_".$file["name"]))
201  {
202  unlink($this->getForumPath()."/".$this->getObjId()."_".$file["name"]);
203  }
204  }
205  return true;
206  }
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
getForumPath()
get forum path public
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deliverFile()

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

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

References $file, $lng, ilFile\$path, createZipFile(), ilUtil\delDir(), ilUtil\deliverFile(), exit, getFileDataByMD5Filename(), getForumPath(), getObjId(), getPosId(), and ilUtil\sendFailure().

455  {
456  if(!$path = $this->getFileDataByMD5Filename($file))
457  {
458  return ilUtil::sendFailure($this->lng->txt('error_reading_file'), true);
459  }
460  else
461  {
462  return ilUtil::deliverFile($path['path'], $path['clean_filename']);
463  }
464  }
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
getFileDataByMD5Filename($a_md5_filename)
get file data of a specific attachment
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the call graph for this function:

◆ getAbsolutePath()

ilFileDataForum::getAbsolutePath (   $a_path)

get absolute path of filename

Parameters
stringrelative path public
Returns
string absolute path

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

299  {
300  return $this->forum_path.'/'.$this->obj_id.'_'.$this->pos_id."_".$a_path;
301  }

◆ getFileDataByMD5Filename()

ilFileDataForum::getFileDataByMD5Filename (   $a_md5_filename)

get file data of a specific attachment

Parameters
stringmd5 encrypted filename public
Returns
array filedata

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

References $file, $files, array, and ilUtil\getDir().

Referenced by deliverFile().

310  {
311  $files = ilUtil::getDir( $this->forum_path );
312  foreach((array)$files as $file)
313  {
314  if($file['type'] == 'file' && md5($file['entry']) == $a_md5_filename)
315  {
316  return array(
317  'path' => $this->forum_path.'/'.$file['entry'],
318  'filename' => $file['entry'],
319  'clean_filename' => str_replace($this->obj_id.'_'.$this->pos_id.'_', '', $file['entry'])
320  );
321  }
322  }
323 
324  return false;
325  }
$files
Definition: add-vimline.php:18
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
Create styles array
The data for the language used.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getForumPath()

ilFileDataForum::getForumPath ( )

get forum path public

Returns
string path

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

References $file, $files, $forum_path, $rest, array, date, getPosId(), and ilFileUtils\rename().

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

72  {
73  return $this->forum_path;
74  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getObjId()

ilFileDataForum::getObjId ( )

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

References $obj_id.

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

55  {
56  return $this->obj_id;
57  }
+ Here is the caller graph for this function:

◆ getPosId()

ilFileDataForum::getPosId ( )

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

References $pos_id.

Referenced by createZipFile(), deliverFile(), and getForumPath().

59  {
60  return $this->pos_id;
61  }
+ Here is the caller graph for this function:

◆ ilClone()

ilFileDataForum::ilClone (   $a_new_obj_id,
  $a_new_pos_id 
)

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

References $file, and getForumPath().

188  {
189  foreach($this->getFilesOfPost() as $file)
190  {
191  @copy($this->getForumPath()."/".$this->obj_id."_".$this->pos_id."_".$file["name"],
192  $this->getForumPath()."/".$a_new_obj_id."_".$a_new_pos_id."_".$file["name"]);
193  }
194  return true;
195  }
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
getForumPath()
get forum path public
+ Here is the call graph for this function:

◆ setPosId()

ilFileDataForum::setPosId (   $a_id)

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

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

◆ storeUploadedFile()

ilFileDataForum::storeUploadedFile (   $files)

Store uploaded files in filesystem.

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

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

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

Referenced by ilObjForumGUI\createThreadObject(), and ilObjForumGUI\publishDraftObject().

218  {
219  if(isset($files['name']) && is_array($files['name']))
220  {
221  foreach($files['name'] as $index => $name)
222  {
223  // remove trailing '/'
224  $name = rtrim($name, '/');
225 
227  $temp_name = $files['tmp_name'][$index];
228  $error = $files['error'][$index];
229 
230  if(strlen($filename) && strlen($temp_name) && $error == 0)
231  {
232  $path = $this->getForumPath().'/'.$this->obj_id.'_'.$this->pos_id.'_'.$filename;
233 
234  $this->__rotateFiles($path);
236  }
237  }
238 
239  return true;
240  }
241  else if(isset($files['name']) && is_string($files['name']))
242  {
243  // remove trailing '/'
244  $files['name'] = rtrim($files['name'], '/');
245 
247  $temp_name = $files['tmp_name'];
248 
249  $path = $this->getForumPath().'/'.$this->obj_id.'_'.$this->pos_id.'_'.$filename;
250 
251  $this->__rotateFiles($path);
253 
254  return true;
255  }
256 
257  return false;
258  }
$files
Definition: add-vimline.php:18
$error
Definition: Error.php:17
static _sanitizeFilemame($a_filename)
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
__rotateFiles($a_path)
rotate files with same name recursive method
getForumPath()
get forum path public
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unlinkFile()

ilFileDataForum::unlinkFile (   $a_filename)

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

Parameters
stringfilename to delete public
Returns
bool

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

Referenced by unlinkFiles().

286  {
287  if(file_exists($this->forum_path.'/'.$this->obj_id.'_'.$this->pos_id.'_'.$a_filename))
288  {
289  return unlink($this->forum_path.'/'.$this->obj_id.'_'.$this->pos_id."_".$a_filename);
290  }
291  }
+ 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 public
Returns
string error message with filename that couldn't be deleted

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

References $file, and unlinkFile().

266  {
267  if(is_array($a_filenames))
268  {
269  foreach($a_filenames as $file)
270  {
271  if(!$this->unlinkFile($file))
272  {
273  return $file;
274  }
275  }
276  }
277  return '';
278  }
unlinkFile($a_filename)
unlink one uploaded file expects a filename e.g 'foo'
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ 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 public
Returns
boolean status

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

References $file, $files, array, and ilUtil\getDir().

334  {
335  $files = ilUtil::getDir( $this->forum_path );
336  if(is_array($a_md5_filename))
337  {
338  foreach((array)$files as $file)
339  {
340  if($file['type'] == 'file' && in_array(md5($file['entry']), $a_md5_filename))
341  {
342  unlink( $this->forum_path.'/'.$file['entry'] );
343  }
344  }
345 
346  return true;
347  }
348  else
349  {
350  foreach((array)$files as $file)
351  {
352  if($file['type'] == 'file' && md5($file['entry']) == $a_md5_filename)
353  {
354  return unlink( $this->forum_path.'/'.$file['entry'] );
355  }
356  }
357  }
358 
359  return false;
360  }
$files
Definition: add-vimline.php:18
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
Create styles array
The data for the language used.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the call graph for this function:

Field Documentation

◆ $forum_path

ilFileDataForum::$forum_path

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

Referenced by getForumPath().

◆ $obj_id

ilFileDataForum::$obj_id

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

Referenced by getObjId().

◆ $pos_id

ilFileDataForum::$pos_id

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

Referenced by getPosId().


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