ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 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 public

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

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

39  {
40  global $DIC;
41  $this->error = $DIC['ilErr'];
42 
43  define('FORUM_PATH', 'forum');
44  parent::__construct();
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  }
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 352 of file class.ilFileDataForum.php.

References __checkReadWrite(), and getForumPath().

Referenced by __construct().

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

Referenced by __checkPath().

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  }
+ Here is the caller graph for this function:

◆ __initDirectory()

ilFileDataForum::__initDirectory ( )

init directory overwritten method public

Returns
string path

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

References ilFileData\getPath().

Referenced by __construct().

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

Referenced by storeUploadedFile().

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
+ 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 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.

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

Referenced by deliverZipFile().

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

References getForumPath(), and getObjId().

Referenced by ilObjForumGUI\publishDraftObject().

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

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

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  }
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
getFileDataByMD5Filename($a_md5_filename)
get file data of a specific attachment
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 425 of file class.ilFileDataForum.php.

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

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  }
global $DIC
Definition: saml.php:7
$post
Definition: post.php:34
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
exit
Definition: backend.php:16
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 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 public
Returns
array filedata

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

References $files, and ilUtil\getDir().

Referenced by deliverFile().

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  }
$files
Definition: metarefresh.php:49
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
+ 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 72 of file class.ilFileDataForum.php.

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

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

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

◆ getObjId()

ilFileDataForum::getObjId ( )

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

References $obj_id.

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

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

◆ getPosId()

ilFileDataForum::getPosId ( )

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

References $pos_id.

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

60  {
61  return $this->pos_id;
62  }
+ 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.

References getForumPath().

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  }
getForumPath()
get forum path public
+ 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, public
Returns
bool

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

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

Referenced by ilObjForumGUI\publishDraftObject().

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);
220  ilUtil::moveUploadedFile($temp_name, $filename, $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 
230  $temp_name = $files['tmp_name'];
231 
232  $path = $this->getForumPath() . '/' . $this->obj_id . '_' . $this->pos_id . '_' . $filename;
233 
234  $this->__rotateFiles($path);
235  ilUtil::moveUploadedFile($temp_name, $filename, $path);
236 
237  return true;
238  }
239 
240  return false;
241  }
$files
Definition: metarefresh.php:49
$index
Definition: metadata.php:60
static _sanitizeFilemame($a_filename)
$filename
Definition: buildRTE.php:89
__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 265 of file class.ilFileDataForum.php.

Referenced by unlinkFiles().

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  }
+ 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 248 of file class.ilFileDataForum.php.

References unlinkFile().

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'
+ 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 310 of file class.ilFileDataForum.php.

References $files, and ilUtil\getDir().

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  }
$files
Definition: metarefresh.php:49
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
+ 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 getForumPath(), and getObjId().

◆ $pos_id

ilFileDataForum::$pos_id

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

Referenced by getForumPath(), and getPosId().


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