ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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...
 
 getFilesOfPost ()
 
 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(), ILIAS\GlobalScreen\Provider\__construct(), and __initDirectory().

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  }
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
__initDirectory()
init directory overwritten method public
+ Here is the call graph for this function:

Member Function Documentation

◆ __checkPath()

ilFileDataForum::__checkPath ( )

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

References __checkReadWrite(), and getForumPath().

Referenced by __construct().

342  {
343  if (!@file_exists($this->getForumPath())) {
344  return false;
345  }
346  $this->__checkReadWrite();
347 
348  return true;
349  }
__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 356 of file class.ilFileDataForum.php.

Referenced by __checkPath().

357  {
358  if (is_writable($this->forum_path) && is_readable($this->forum_path)) {
359  return true;
360  } else {
361  $this->error->raiseError("Forum directory is not readable/writable by webserver", $this->error->FATAL);
362  }
363  }
+ Here is the caller graph for this function:

◆ __initDirectory()

ilFileDataForum::__initDirectory ( )

init directory overwritten method public

Returns
string path

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

References ilFileData\getPath().

Referenced by __construct().

371  {
372  if (is_writable($this->getPath())) {
373  if (mkdir($this->getPath() . '/' . FORUM_PATH)) {
374  if (chmod($this->getPath() . '/' . FORUM_PATH, 0755)) {
375  $this->forum_path = $this->getPath() . '/' . FORUM_PATH;
376  return true;
377  }
378  }
379  }
380  return false;
381  }
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 389 of file class.ilFileDataForum.php.

Referenced by storeUploadedFile().

390  {
391  if (file_exists($a_path)) {
392  $this->__rotateFiles($a_path . ".old");
393  return \ilFileUtils::rename($a_path, $a_path . '.old');
394  }
395  return true;
396  }
__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 327 of file class.ilFileDataForum.php.

328  {
329  if ($a_files) {
330  foreach ($a_files as $file) {
331  if (!file_exists($this->forum_path . '/' . $this->obj_id . '_' . $this->pos_id . '_' . $file)) {
332  return false;
333  }
334  }
335  return true;
336  }
337  return true;
338  }

◆ createZipFile()

ilFileDataForum::createZipFile ( )
protected
Returns
null|string

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

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

Referenced by deliverZipFile().

434  {
435  $filesOfPost = $this->getFilesOfPost();
436  ksort($filesOfPost);
437 
438  ilUtil::makeDirParents($this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId());
439  $tmp_dir = $this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId();
440  foreach ($filesOfPost as $file) {
441  @copy($file['path'], $tmp_dir . '/' . $file['name']);
442  }
443 
444  $zip_file = null;
445  if (ilUtil::zip($tmp_dir, $this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId() . '.zip')) {
446  $zip_file = $this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId() . '.zip';
447  }
448 
449  return $zip_file;
450  }
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 175 of file class.ilFileDataForum.php.

References getForumPath(), and getObjId().

Referenced by ilObjForumGUI\publishDraftObject().

176  {
177  foreach ($this->getFiles() as $file) {
178  if (file_exists($this->getForumPath() . "/" . $this->getObjId() . "_" . $file["name"])) {
179  unlink($this->getForumPath() . "/" . $this->getObjId() . "_" . $file["name"]);
180  }
181  }
182  return true;
183  }
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 402 of file class.ilFileDataForum.php.

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

403  {
404  if (!$path = $this->getFileDataByMD5Filename($file)) {
405  return ilUtil::sendFailure($this->lng->txt('error_reading_file'), true);
406  } else {
407  return ilUtil::deliverFile($path['path'], $path['clean_filename']);
408  }
409  }
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 414 of file class.ilFileDataForum.php.

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

415  {
416  global $DIC;
417 
418  $zip_file = $this->createZipFile();
419  if (!$zip_file) {
420  ilUtil::sendFailure($DIC->language()->txt('error_reading_file'), true);
421  return false;
422  } else {
423  $post = new ilForumPost($this->getPosId());
424  ilUtil::deliverFile($zip_file, $post->getSubject() . '.zip', '', false, true, false);
425  ilUtil::delDir($this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId());
426  $DIC->http()->close();
427  }
428  }
global $DIC
Definition: goto.php:24
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 266 of file class.ilFileDataForum.php.

267  {
268  return $this->forum_path . '/' . $this->obj_id . '_' . $this->pos_id . "_" . $a_path;
269  }

◆ getFileDataByMD5Filename()

ilFileDataForum::getFileDataByMD5Filename (   $a_md5_filename)

get file data of a specific attachment

Parameters
stringmd5 encrypted filename public
Returns
array filedata

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

References ilUtil\getDir().

Referenced by deliverFile().

278  {
279  $files = ilUtil::getDir($this->forum_path);
280  foreach ((array) $files as $file) {
281  if ($file['type'] == 'file' && md5($file['entry']) == $a_md5_filename) {
282  return array(
283  'path' => $this->forum_path . '/' . $file['entry'],
284  'filename' => $file['entry'],
285  'clean_filename' => str_replace($this->obj_id . '_' . $this->pos_id . '_', '', $file['entry'])
286  );
287  }
288  }
289 
290  return false;
291  }
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:

◆ getFilesOfPost()

ilFileDataForum::getFilesOfPost ( )
Returns
array

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

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

Referenced by createZipFile(), ilClone(), ilObjForumNotificationDataProvider\readAttachments(), and ilObjForumGUI\renderPostContent().

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

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

73  {
74  return $this->forum_path;
75  }
+ 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 getFilesOfPost().

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

References getFilesOfPost(), and getForumPath().

166  {
167  foreach ($this->getFilesOfPost() as $file) {
168  @copy(
169  $this->getForumPath() . "/" . $this->obj_id . "_" . $this->pos_id . "_" . $file["name"],
170  $this->getForumPath() . "/" . $a_new_obj_id . "_" . $a_new_pos_id . "_" . $file["name"]
171  );
172  }
173  return true;
174  }
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 194 of file class.ilFileDataForum.php.

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

Referenced by ilObjForumGUI\publishDraftObject().

195  {
196  if (isset($files['name']) && is_array($files['name'])) {
197  foreach ($files['name'] as $index => $name) {
198  // remove trailing '/'
199  $name = rtrim($name, '/');
200 
202  $temp_name = $files['tmp_name'][$index];
203  $error = $files['error'][$index];
204 
205  if (strlen($filename) && strlen($temp_name) && $error == 0) {
206  $path = $this->getForumPath() . '/' . $this->obj_id . '_' . $this->pos_id . '_' . $filename;
207 
208  $this->__rotateFiles($path);
210  }
211  }
212 
213  return true;
214  } elseif (isset($files['name']) && is_string($files['name'])) {
215  // remove trailing '/'
216  $files['name'] = rtrim($files['name'], '/');
217 
218  $filename = ilUtil::_sanitizeFilemame($files['name']);
219  $temp_name = $files['tmp_name'];
220 
221  $path = $this->getForumPath() . '/' . $this->obj_id . '_' . $this->pos_id . '_' . $filename;
222 
223  $this->__rotateFiles($path);
225 
226  return true;
227  }
228 
229  return false;
230  }
$index
Definition: metadata.php:128
if($format !==null) $name
Definition: metadata.php:230
static _sanitizeFilemame($a_filename)
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
$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 254 of file class.ilFileDataForum.php.

Referenced by unlinkFiles().

255  {
256  if (file_exists($this->forum_path . '/' . $this->obj_id . '_' . $this->pos_id . '_' . $a_filename)) {
257  return unlink($this->forum_path . '/' . $this->obj_id . '_' . $this->pos_id . "_" . $a_filename);
258  }
259  }
+ 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 237 of file class.ilFileDataForum.php.

References unlinkFile().

238  {
239  if (is_array($a_filenames)) {
240  foreach ($a_filenames as $file) {
241  if (!$this->unlinkFile($file)) {
242  return $file;
243  }
244  }
245  }
246  return '';
247  }
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 299 of file class.ilFileDataForum.php.

References ilUtil\getDir().

300  {
301  $files = ilUtil::getDir($this->forum_path);
302  if (is_array($a_md5_filename)) {
303  foreach ((array) $files as $file) {
304  if ($file['type'] == 'file' && in_array(md5($file['entry']), $a_md5_filename)) {
305  unlink($this->forum_path . '/' . $file['entry']);
306  }
307  }
308 
309  return true;
310  } else {
311  foreach ((array) $files as $file) {
312  if ($file['type'] == 'file' && md5($file['entry']) == $a_md5_filename) {
313  return unlink($this->forum_path . '/' . $file['entry']);
314  }
315  }
316  }
317 
318  return false;
319  }
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 getFilesOfPost(), getForumPath(), and getObjId().

◆ $pos_id

ilFileDataForum::$pos_id

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

Referenced by getFilesOfPost(), and getPosId().


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