ILIAS  release_7 Revision v7.30-3-g800a261c036
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...
 
 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 @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
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

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

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

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 }

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

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

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

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

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 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 getFilesOfPost(), 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 175 of file class.ilFileDataForum.php.

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 }

References getForumPath(), and getObjId().

+ Here is the call graph for this function:

◆ deliverFile()

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

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

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

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 }
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively

References $DIC, createZipFile(), ilUtil\delDir(), ilUtil\deliverFile(), 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 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 @access public
Returns
array filedata

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

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

References ilUtil\getDir().

Referenced by deliverFile().

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

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

References $obj_id, $pos_id, and $rest.

Referenced by createZipFile(), and ilClone().

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

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 }

References getFilesOfPost(), and 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 194 of file class.ilFileDataForum.php.

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

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 }

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

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'

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

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 }

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 getFilesOfPost(), 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: