ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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)
 
 deliverZipFile ()
 
- 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 ()
 

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 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 41 of file class.ilFileDataForum.php.

References $DIC, __checkPath(), and __initDirectory().

42  {
43  global $DIC;
44  $this->error = $DIC['ilErr'];
45 
46  define('FORUM_PATH', 'forum');
47  parent::__construct();
48  $this->forum_path = parent::getPath() . "/" . FORUM_PATH;
49 
50  // IF DIRECTORY ISN'T CREATED CREATE IT
51  if (!$this->__checkPath()) {
52  $this->__initDirectory();
53  }
54  $this->obj_id = $a_obj_id;
55  $this->pos_id = $a_pos_id;
56  }
global $DIC
Definition: saml.php:7
__initDirectory()
init directory overwritten method public
+ Here is the call graph for this function:

Member Function Documentation

◆ __checkPath()

ilFileDataForum::__checkPath ( )

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

References __checkReadWrite(), and getForumPath().

Referenced by __construct().

356  {
357  if (!@file_exists($this->getForumPath())) {
358  return false;
359  }
360  $this->__checkReadWrite();
361 
362  return true;
363  }
__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 370 of file class.ilFileDataForum.php.

Referenced by __checkPath().

371  {
372  if (is_writable($this->forum_path) && is_readable($this->forum_path)) {
373  return true;
374  } else {
375  $this->error->raiseError("Forum directory is not readable/writable by webserver", $this->error->FATAL);
376  }
377  }
+ Here is the caller graph for this function:

◆ __initDirectory()

ilFileDataForum::__initDirectory ( )

init directory overwritten method public

Returns
string path

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

References ilFileData\getPath().

Referenced by __construct().

385  {
386  if (is_writable($this->getPath())) {
387  if (mkdir($this->getPath() . '/' . FORUM_PATH)) {
388  if (chmod($this->getPath() . '/' . FORUM_PATH, 0755)) {
389  $this->forum_path = $this->getPath() . '/' . FORUM_PATH;
390  return true;
391  }
392  }
393  }
394  return false;
395  }
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 403 of file class.ilFileDataForum.php.

Referenced by storeUploadedFile().

404  {
405  if (file_exists($a_path)) {
406  $this->__rotateFiles($a_path . ".old");
407  return \ilFileUtils::rename($a_path, $a_path . '.old');
408  }
409  return true;
410  }
__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 341 of file class.ilFileDataForum.php.

References $file.

342  {
343  if ($a_files) {
344  foreach ($a_files as $file) {
345  if (!file_exists($this->forum_path . '/' . $this->obj_id . '_' . $this->pos_id . '_' . $file)) {
346  return false;
347  }
348  }
349  return true;
350  }
351  return true;
352  }
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file

◆ createZipFile()

ilFileDataForum::createZipFile ( )
protected
Returns
null|string

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

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

Referenced by deliverZipFile().

448  {
449  $filesOfPost = $this->getFilesOfPost();
450  ksort($filesOfPost);
451 
452  ilUtil::makeDirParents($this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId());
453  $tmp_dir = $this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId();
454  foreach ($filesOfPost as $file) {
455  @copy($file['path'], $tmp_dir . '/' . $file['name']);
456  }
457 
458  $zip_file = null;
459  if (ilUtil::zip($tmp_dir, $this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId() . '.zip')) {
460  $zip_file = $this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId() . '.zip';
461  }
462 
463  return $zip_file;
464  }
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 189 of file class.ilFileDataForum.php.

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

Referenced by ilObjForumGUI\publishDraftObject().

190  {
191  foreach ($this->getFiles() as $file) {
192  if (file_exists($this->getForumPath() . "/" . $this->getObjId() . "_" . $file["name"])) {
193  unlink($this->getForumPath() . "/" . $this->getObjId() . "_" . $file["name"]);
194  }
195  }
196  return true;
197  }
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 416 of file class.ilFileDataForum.php.

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

417  {
418  if (!$path = $this->getFileDataByMD5Filename($file)) {
419  return ilUtil::sendFailure($this->lng->txt('error_reading_file'), true);
420  } else {
421  return ilUtil::deliverFile($path['path'], $path['clean_filename']);
422  }
423  }
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
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
+ Here is the call graph for this function:

◆ deliverZipFile()

ilFileDataForum::deliverZipFile ( )

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

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

429  {
430  global $DIC;
431 
432  $zip_file = $this->createZipFile();
433  if (!$zip_file) {
434  ilUtil::sendFailure($DIC->language()->txt('error_reading_file'), true);
435  return false;
436  } else {
437  $post = new ilForumPost($this->getPosId());
438  ilUtil::deliverFile($zip_file, $post->getSubject() . '.zip', '', false, true, false);
439  ilUtil::delDir($this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId());
440  exit();
441  }
442  }
global $DIC
Definition: saml.php:7
$post
Definition: post.php:34
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
getForumPath()
get forum path public
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
+ 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 280 of file class.ilFileDataForum.php.

281  {
282  return $this->forum_path . '/' . $this->obj_id . '_' . $this->pos_id . "_" . $a_path;
283  }

◆ getFileDataByMD5Filename()

ilFileDataForum::getFileDataByMD5Filename (   $a_md5_filename)

get file data of a specific attachment

Parameters
stringmd5 encrypted filename public
Returns
array filedata

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

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

Referenced by deliverFile().

292  {
293  $files = ilUtil::getDir($this->forum_path);
294  foreach ((array) $files as $file) {
295  if ($file['type'] == 'file' && md5($file['entry']) == $a_md5_filename) {
296  return array(
297  'path' => $this->forum_path . '/' . $file['entry'],
298  'filename' => $file['entry'],
299  'clean_filename' => str_replace($this->obj_id . '_' . $this->pos_id . '_', '', $file['entry'])
300  );
301  }
302  }
303 
304  return false;
305  }
$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 75 of file class.ilFileDataForum.php.

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

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

76  {
77  return $this->forum_path;
78  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getObjId()

ilFileDataForum::getObjId ( )

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

References $obj_id.

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

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

◆ getPosId()

ilFileDataForum::getPosId ( )

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

References $pos_id.

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

63  {
64  return $this->pos_id;
65  }
+ Here is the caller graph for this function:

◆ ilClone()

ilFileDataForum::ilClone (   $a_new_obj_id,
  $a_new_pos_id 
)

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

References $file, and getForumPath().

180  {
181  foreach ($this->getFilesOfPost() as $file) {
182  @copy(
183  $this->getForumPath() . "/" . $this->obj_id . "_" . $this->pos_id . "_" . $file["name"],
184  $this->getForumPath() . "/" . $a_new_obj_id . "_" . $a_new_pos_id . "_" . $file["name"]
185  );
186  }
187  return true;
188  }
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 66 of file class.ilFileDataForum.php.

67  {
68  $this->pos_id = $a_id;
69  }

◆ storeUploadedFile()

ilFileDataForum::storeUploadedFile (   $files)

Store uploaded files in filesystem.

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

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

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

Referenced by ilObjForumGUI\addThreadObject(), ilObjForumGUI\publishDraftObject(), and ilObjForumGUI\publishThreadDraftObject().

209  {
210  if (isset($files['name']) && is_array($files['name'])) {
211  foreach ($files['name'] as $index => $name) {
212  // remove trailing '/'
213  $name = rtrim($name, '/');
214 
216  $temp_name = $files['tmp_name'][$index];
217  $error = $files['error'][$index];
218 
219  if (strlen($filename) && strlen($temp_name) && $error == 0) {
220  $path = $this->getForumPath() . '/' . $this->obj_id . '_' . $this->pos_id . '_' . $filename;
221 
222  $this->__rotateFiles($path);
223  ilUtil::moveUploadedFile($temp_name, $filename, $path);
224  }
225  }
226 
227  return true;
228  } elseif (isset($files['name']) && is_string($files['name'])) {
229  // remove trailing '/'
230  $files['name'] = rtrim($files['name'], '/');
231 
233  $temp_name = $files['tmp_name'];
234 
235  $path = $this->getForumPath() . '/' . $this->obj_id . '_' . $this->pos_id . '_' . $filename;
236 
237  $this->__rotateFiles($path);
238  ilUtil::moveUploadedFile($temp_name, $filename, $path);
239 
240  return true;
241  }
242 
243  return false;
244  }
$files
Definition: add-vimline.php:18
$index
Definition: metadata.php:60
static _sanitizeFilemame($a_filename)
if($format !==null) $name
Definition: metadata.php:146
__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 268 of file class.ilFileDataForum.php.

Referenced by unlinkFiles().

269  {
270  if (file_exists($this->forum_path . '/' . $this->obj_id . '_' . $this->pos_id . '_' . $a_filename)) {
271  return unlink($this->forum_path . '/' . $this->obj_id . '_' . $this->pos_id . "_" . $a_filename);
272  }
273  }
+ 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 251 of file class.ilFileDataForum.php.

References $file, and unlinkFile().

252  {
253  if (is_array($a_filenames)) {
254  foreach ($a_filenames as $file) {
255  if (!$this->unlinkFile($file)) {
256  return $file;
257  }
258  }
259  }
260  return '';
261  }
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 313 of file class.ilFileDataForum.php.

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

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

◆ $error

ilFileDataForum::$error
private

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

Referenced by storeUploadedFile().

◆ $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 getForumPath(), and getObjId().

◆ $pos_id

ilFileDataForum::$pos_id

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

Referenced by getForumPath(), and getPosId().


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