ILIAS  release_4-4 Revision
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...
 
 getFiles ()
 
 getFilesOfPost ()
 
 moveFilesOfPost ($a_new_frm_id=0)
 
 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 14 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 __checkPath(), and __initDirectory().

39  {
40  define('FORUM_PATH', 'forum');
41  parent::__construct();
42  $this->forum_path = parent::getPath()."/".FORUM_PATH;
43 
44  // IF DIRECTORY ISN'T CREATED CREATE IT
45  if(!$this->__checkPath())
46  {
47  $this->__initDirectory();
48  }
49  $this->obj_id = $a_obj_id;
50  $this->pos_id = $a_pos_id;
51  }
__initDirectory()
init directory overwritten method public
+ Here is the call graph for this function:

Member Function Documentation

◆ __checkPath()

ilFileDataForum::__checkPath ( )

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

References __checkReadWrite(), and getForumPath().

Referenced by __construct().

371  {
372  if(!@file_exists($this->getForumPath()))
373  {
374  return false;
375  }
376  $this->__checkReadWrite();
377 
378  return true;
379  }
__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 386 of file class.ilFileDataForum.php.

Referenced by __checkPath().

387  {
388  if(is_writable($this->forum_path) && is_readable($this->forum_path))
389  {
390  return true;
391  }
392  else
393  {
394  $this->ilias->raiseError("Forum directory is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
395  }
396  }
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 403 of file class.ilFileDataForum.php.

References ilFileData\getPath().

Referenced by __construct().

404  {
405  if(is_writable($this->getPath()))
406  {
407  if(mkdir($this->getPath().'/'.FORUM_PATH))
408  {
409  if(chmod($this->getPath().'/'.FORUM_PATH,0755))
410  {
411  $this->forum_path = $this->getPath().'/'.FORUM_PATH;
412  return true;
413  }
414  }
415  }
416  return false;
417  }
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 425 of file class.ilFileDataForum.php.

Referenced by storeUploadedFile().

426  {
427  if(file_exists($a_path))
428  {
429  $this->__rotateFiles($a_path.".old");
430  return rename($a_path,$a_path.'.old');
431  }
432  return true;
433  }
__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 353 of file class.ilFileDataForum.php.

References $file.

354  {
355  if($a_files)
356  {
357  foreach($a_files as $file)
358  {
359  if(!file_exists($this->forum_path.'/'.$this->obj_id.'_'.$this->pos_id.'_'.$file))
360  {
361  return false;
362  }
363  }
364  return true;
365  }
366  return true;
367  }
print $file

◆ delete()

ilFileDataForum::delete ( )

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

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

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

284  {
285  return $this->forum_path.'/'.$this->obj_id.'_'.$this->pos_id."_".$a_path;
286  }

◆ getFileDataByMD5Filename()

ilFileDataForum::getFileDataByMD5Filename (   $a_md5_filename)

get file data of a specific attachment

Parameters
stringmd5 encrypted filename public
Returns
array filedata

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

References $file, and ilUtil\getDir().

295  {
296  $files = ilUtil::getDir( $this->forum_path );
297  foreach((array)$files as $file)
298  {
299  if($file['type'] == 'file' && md5($file['entry']) == $a_md5_filename)
300  {
301  return array(
302  'path' => $this->forum_path.'/'.$file['entry'],
303  'filename' => $file['entry'],
304  'clean_filename' => str_replace($this->obj_id.'_'.$this->pos_id.'_', '', $file['entry'])
305  );
306  }
307  }
308 
309  return false;
310  }
print $file
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
+ Here is the call graph for this function:

◆ getFiles()

ilFileDataForum::getFiles ( )

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

References $file, $rest, and ilFormat\formatDate().

Referenced by delete().

76  {
77  $files = array();
78  $dp = opendir($this->forum_path);
79 
80  while($file = readdir($dp))
81  {
82  if(is_dir($file))
83  {
84  continue;
85  }
86  list($obj_id,$rest) = split('_',$file,2);
87  if($obj_id == $this->obj_id)
88  {
89  if(!is_dir($this->forum_path.'/'.$file))
90  {
91  $files[] = array(
92  'path' => $this->forum_path.'/'.$file,
93  'md5' => md5($this->obj_id.'_'.$this->pos_id.'_'.$rest),
94  'name' => $rest,
95  'size' => filesize($this->forum_path.'/'.$file),
96  'ctime' => ilFormat::formatDate(date('Y-m-d H:i:s',filectime($this->forum_path.'/'.$file))));
97  }
98  }
99  }
100  closedir($dp);
101  return $files;
102  }
print $file
$rest
Definition: goto.php:85
formatDate($a_date, $a_mode="datetime", $a_omit_seconds=false, $a_relative=TRUE)
format a date according to the user language shortcut for Format::fmtDateTime public ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFilesOfPost()

ilFileDataForum::getFilesOfPost ( )

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

References $file, $rest, ilFormat\formatDate(), and getPosId().

Referenced by ilClone().

104  {
105  $files = array();
106  $dp = opendir($this->forum_path);
107 
108  while($file = readdir($dp))
109  {
110  if(is_dir($file))
111  {
112  continue;
113  }
114  list($obj_id,$rest) = split('_',$file,2);
115  if($obj_id == $this->obj_id)
116  {
117  list($pos_id,$rest) = split('_',$rest,2);
118  if($pos_id == $this->getPosId())
119  {
120  if(!is_dir($this->forum_path.'/'.$file))
121  {
122  $files[] = array(
123  'path' => $this->forum_path.'/'.$file,
124  'md5' => md5($this->obj_id.'_'.$this->pos_id.'_'.$rest),
125  'name' => $rest,
126  'size' => filesize($this->forum_path.'/'.$file),
127  'ctime' => ilFormat::formatDate(date('Y-m-d H:i:s',filectime($this->forum_path.'/'.$file))));
128  }
129  }
130  }
131  }
132  closedir($dp);
133  return $files;
134  }
print $file
$rest
Definition: goto.php:85
formatDate($a_date, $a_mode="datetime", $a_omit_seconds=false, $a_relative=TRUE)
format a date according to the user language shortcut for Format::fmtDateTime public ...
+ 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 70 of file class.ilFileDataForum.php.

References $forum_path.

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

71  {
72  return $this->forum_path;
73  }
+ Here is the caller graph for this function:

◆ getObjId()

ilFileDataForum::getObjId ( )

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

References $obj_id.

Referenced by delete().

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

◆ getPosId()

ilFileDataForum::getPosId ( )

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

References $pos_id.

Referenced by getFilesOfPost(), and moveFilesOfPost().

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

◆ ilClone()

ilFileDataForum::ilClone (   $a_new_obj_id,
  $a_new_pos_id 
)

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

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

169  {
170  foreach($this->getFilesOfPost() as $file)
171  {
172  @copy($this->getForumPath()."/".$this->obj_id."_".$this->pos_id."_".$file["name"],
173  $this->getForumPath()."/".$a_new_obj_id."_".$a_new_pos_id."_".$file["name"]);
174  }
175  return true;
176  }
print $file
getForumPath()
get forum path public
+ Here is the call graph for this function:

◆ moveFilesOfPost()

ilFileDataForum::moveFilesOfPost (   $a_new_frm_id = 0)

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

References $file, $rest, and getPosId().

137  {
138  if((int)$a_new_frm_id)
139  {
140  $dp = opendir($this->forum_path);
141 
142  while($file = readdir($dp))
143  {
144  if(is_dir($file))
145  {
146  continue;
147  }
148  list($obj_id,$rest) = split('_',$file,2);
149  if($obj_id == $this->obj_id)
150  {
151  list($pos_id,$rest) = split('_',$rest,2);
152  if($pos_id == $this->getPosId())
153  {
154  if(!is_dir($this->forum_path.'/'.$file))
155  {
156  @rename($this->forum_path.'/'.$file, $this->forum_path.'/'.$a_new_frm_id.'_'.$this->pos_id.'_'.$rest);
157  }
158  }
159  }
160  }
161  closedir($dp);
162  return true;
163  }
164 
165  return false;
166  }
print $file
$rest
Definition: goto.php:85
+ Here is the call graph for this function:

◆ setPosId()

ilFileDataForum::setPosId (   $a_id)

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

62  {
63  $this->pos_id = $a_id;
64  }

◆ storeUploadedFile()

ilFileDataForum::storeUploadedFile (   $files)

Store uploaded files in filesystem.

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

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

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

Referenced by ilObjForumGUI\setTopicCreateDefaultValues().

199  {
200  if(isset($files['name']) && is_array($files['name']))
201  {
202  foreach($files['name'] as $index => $name)
203  {
204  // remove trailing '/'
205  while(substr($name, -1) == '/')
206  {
207  $name = substr($name, 0, -1);
208  }
210  $temp_name = $files['tmp_name'][$index];
211  $error = $files['error'][$index];
212 
213  if(strlen($filename) && strlen($temp_name) && $error == 0)
214  {
215  $path = $this->getForumPath().'/'.$this->obj_id.'_'.$this->pos_id.'_'.$filename;
216 
217  $this->__rotateFiles($path);
219  }
220  }
221 
222  return true;
223  }
224  else if(isset($files['name']) && is_string($files['name']))
225  {
226  // remove trailing '/'
227  while(substr($files['name'], -1) == '/')
228  {
229  $files['name'] = substr($files['name'], 0, -1);
230  }
231  $filename = ilUtil::_sanitizeFilemame($files['name']);
232  $temp_name = $files['tmp_name'];
233 
234  $path = $this->getForumPath().'/'.$this->obj_id.'_'.$this->pos_id.'_'.$filename;
235 
236  $this->__rotateFiles($path);
238 
239  return true;
240  }
241 
242  return false;
243  }
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 270 of file class.ilFileDataForum.php.

Referenced by unlinkFiles().

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

References $file, and unlinkFile().

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

References $file, and ilUtil\getDir().

319  {
320  $files = ilUtil::getDir( $this->forum_path );
321  if(is_array($a_md5_filename))
322  {
323  foreach((array)$files as $file)
324  {
325  if($file['type'] == 'file' && in_array(md5($file['entry']), $a_md5_filename))
326  {
327  unlink( $this->forum_path.'/'.$file['entry'] );
328  }
329  }
330 
331  return true;
332  }
333  else
334  {
335  foreach((array)$files as $file)
336  {
337  if($file['type'] == 'file' && md5($file['entry']) == $a_md5_filename)
338  {
339  return unlink( $this->forum_path.'/'.$file['entry'] );
340  }
341  }
342  }
343 
344  return false;
345  }
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 29 of file class.ilFileDataForum.php.

Referenced by getForumPath().

◆ $obj_id

ilFileDataForum::$obj_id

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

Referenced by getObjId().

◆ $pos_id

ilFileDataForum::$pos_id

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

Referenced by getPosId().


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