ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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...
 
- Public Member Functions inherited from ilFileData
 ilFileData ()
 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
 ilFile ()
 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
 

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

References __checkReadWrite(), and getForumPath().

Referenced by __construct().

390  {
391  if(!@file_exists($this->getForumPath()))
392  {
393  return false;
394  }
395  $this->__checkReadWrite();
396 
397  return true;
398  }
__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 405 of file class.ilFileDataForum.php.

Referenced by __checkPath().

406  {
407  if(is_writable($this->forum_path) && is_readable($this->forum_path))
408  {
409  return true;
410  }
411  else
412  {
413  $this->ilias->raiseError("Forum directory is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
414  }
415  }
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 422 of file class.ilFileDataForum.php.

References ilFileData\getPath().

Referenced by __construct().

423  {
424  if(is_writable($this->getPath()))
425  {
426  if(mkdir($this->getPath().'/'.FORUM_PATH))
427  {
428  if(chmod($this->getPath().'/'.FORUM_PATH,0755))
429  {
430  $this->forum_path = $this->getPath().'/'.FORUM_PATH;
431  return true;
432  }
433  }
434  }
435  return false;
436  }
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 444 of file class.ilFileDataForum.php.

Referenced by storeUploadedFile().

445  {
446  if(file_exists($a_path))
447  {
448  $this->__rotateFiles($a_path.".old");
449  return \ilFileUtils::rename($a_path, $a_path . '.old');
450  }
451  return true;
452  }
__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 372 of file class.ilFileDataForum.php.

References $file.

373  {
374  if($a_files)
375  {
376  foreach($a_files as $file)
377  {
378  if(!file_exists($this->forum_path.'/'.$this->obj_id.'_'.$this->pos_id.'_'.$file))
379  {
380  return false;
381  }
382  }
383  return true;
384  }
385  return true;
386  }
print $file

◆ delete()

ilFileDataForum::delete ( )

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

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

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  }
print $file
getForumPath()
get forum path public
+ 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 302 of file class.ilFileDataForum.php.

303  {
304  return $this->forum_path.'/'.$this->obj_id.'_'.$this->pos_id."_".$a_path;
305  }

◆ getFileDataByMD5Filename()

ilFileDataForum::getFileDataByMD5Filename (   $a_md5_filename)

get file data of a specific attachment

Parameters
stringmd5 encrypted filename public
Returns
array filedata

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

References $file, and ilUtil\getDir().

314  {
315  $files = ilUtil::getDir( $this->forum_path );
316  foreach((array)$files as $file)
317  {
318  if($file['type'] == 'file' && md5($file['entry']) == $a_md5_filename)
319  {
320  return array(
321  'path' => $this->forum_path.'/'.$file['entry'],
322  'filename' => $file['entry'],
323  'clean_filename' => str_replace($this->obj_id.'_'.$this->pos_id.'_', '', $file['entry'])
324  );
325  }
326  }
327 
328  return false;
329  }
print $file
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
+ Here is the call 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, $forum_path, $rest, ilFormat\formatDate(), getPosId(), and ilFileUtils\rename().

Referenced by __checkPath(), delete(), 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 delete().

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 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  }
print $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 $filename, ilFile\$path, __rotateFiles(), ilUtil\_sanitizeFilemame(), getForumPath(), and ilUtil\moveUploadedFile().

Referenced by ilObjForumGUI\setTopicCreateDefaultValues().

218  {
219  if(isset($files['name']) && is_array($files['name']))
220  {
221  foreach($files['name'] as $index => $name)
222  {
223  // remove trailing '/'
224  while(substr($name, -1) == '/')
225  {
226  $name = substr($name, 0, -1);
227  }
229  $temp_name = $files['tmp_name'][$index];
230  $error = $files['error'][$index];
231 
232  if(strlen($filename) && strlen($temp_name) && $error == 0)
233  {
234  $path = $this->getForumPath().'/'.$this->obj_id.'_'.$this->pos_id.'_'.$filename;
235 
236  $this->__rotateFiles($path);
238  }
239  }
240 
241  return true;
242  }
243  else if(isset($files['name']) && is_string($files['name']))
244  {
245  // remove trailing '/'
246  while(substr($files['name'], -1) == '/')
247  {
248  $files['name'] = substr($files['name'], 0, -1);
249  }
250  $filename = ilUtil::_sanitizeFilemame($files['name']);
251  $temp_name = $files['tmp_name'];
252 
253  $path = $this->getForumPath().'/'.$this->obj_id.'_'.$this->pos_id.'_'.$filename;
254 
255  $this->__rotateFiles($path);
257 
258  return true;
259  }
260 
261  return false;
262  }
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 289 of file class.ilFileDataForum.php.

Referenced by unlinkFiles().

290  {
291  if(file_exists($this->forum_path.'/'.$this->obj_id.'_'.$this->pos_id.'_'.$a_filename))
292  {
293  return unlink($this->forum_path.'/'.$this->obj_id.'_'.$this->pos_id."_".$a_filename);
294  }
295  }
+ 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 269 of file class.ilFileDataForum.php.

References $file, and unlinkFile().

270  {
271  if(is_array($a_filenames))
272  {
273  foreach($a_filenames as $file)
274  {
275  if(!$this->unlinkFile($file))
276  {
277  return $file;
278  }
279  }
280  }
281  return '';
282  }
print $file
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 337 of file class.ilFileDataForum.php.

References $file, and ilUtil\getDir().

338  {
339  $files = ilUtil::getDir( $this->forum_path );
340  if(is_array($a_md5_filename))
341  {
342  foreach((array)$files as $file)
343  {
344  if($file['type'] == 'file' && in_array(md5($file['entry']), $a_md5_filename))
345  {
346  unlink( $this->forum_path.'/'.$file['entry'] );
347  }
348  }
349 
350  return true;
351  }
352  else
353  {
354  foreach((array)$files as $file)
355  {
356  if($file['type'] == 'file' && md5($file['entry']) == $a_md5_filename)
357  {
358  return unlink( $this->forum_path.'/'.$file['entry'] );
359  }
360  }
361  }
362 
363  return false;
364  }
print $file
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
+ 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: