ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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...
 
 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...
 
- Public Member Functions inherited from ilFileData
 ilFileData ()
 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
 ilFile ()
 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
 

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 @access public

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

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 @access public

References __checkPath(), and __initDirectory().

+ Here is the call graph for this function:

Member Function Documentation

◆ __checkPath()

ilFileDataForum::__checkPath ( )

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

386 {
387 if(!@file_exists($this->getForumPath()))
388 {
389 return false;
390 }
391 $this->__checkReadWrite();
392
393 return true;
394 }
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 401 of file class.ilFileDataForum.php.

402 {
403 if(is_writable($this->forum_path) && is_readable($this->forum_path))
404 {
405 return true;
406 }
407 else
408 {
409 $this->ilias->raiseError("Forum directory is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
410 }
411 }
redirection script todo: (a better solution should control the processing via a xml file)

Referenced by __checkPath().

+ Here is the caller graph for this function:

◆ __initDirectory()

ilFileDataForum::__initDirectory ( )

init directory overwritten method @access public

Returns
string path

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

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

441 {
442 if(file_exists($a_path))
443 {
444 $this->__rotateFiles($a_path.".old");
445 return rename($a_path,$a_path.'.old');
446 }
447 return true;
448 }
__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 368 of file class.ilFileDataForum.php.

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

References $file.

◆ delete()

ilFileDataForum::delete ( )

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

193 {
194 foreach($this->getFiles() as $file)
195 {
196 if(file_exists($this->getForumPath()."/".$this->getObjId()."_".$file["name"]))
197 {
198 unlink($this->getForumPath()."/".$this->getObjId()."_".$file["name"]);
199 }
200 }
201 return true;
202 }

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

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

299 {
300 return $this->forum_path.'/'.$this->obj_id.'_'.$this->pos_id."_".$a_path;
301 }

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

310 {
311 $files = ilUtil::getDir( $this->forum_path );
312 foreach((array)$files as $file)
313 {
314 if($file['type'] == 'file' && md5($file['entry']) == $a_md5_filename)
315 {
316 return array(
317 'path' => $this->forum_path.'/'.$file['entry'],
318 'filename' => $file['entry'],
319 'clean_filename' => str_replace($this->obj_id.'_'.$this->pos_id.'_', '', $file['entry'])
320 );
321 }
322 }
323
324 return false;
325 }
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory

References $file, and ilUtil\getDir().

+ Here is the call graph for this function:

◆ getForumPath()

ilFileDataForum::getForumPath ( )

get forum path @access public

Returns
string path

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

References $forum_path.

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

+ Here is the caller graph for this function:

◆ getObjId()

ilFileDataForum::getObjId ( )

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

54 {
55 return $this->obj_id;
56 }

References $obj_id.

Referenced by delete().

+ Here is the caller graph for this function:

◆ getPosId()

ilFileDataForum::getPosId ( )

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

58 {
59 return $this->pos_id;
60 }

References $pos_id.

◆ ilClone()

ilFileDataForum::ilClone (   $a_new_obj_id,
  $a_new_pos_id 
)

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

184 {
185 foreach($this->getFilesOfPost() as $file)
186 {
187 @copy($this->getForumPath()."/".$this->obj_id."_".$this->pos_id."_".$file["name"],
188 $this->getForumPath()."/".$a_new_obj_id."_".$a_new_pos_id."_".$file["name"]);
189 }
190 return true;
191 }

References $file, and getForumPath().

+ 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, @access public
Returns
bool

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

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

References $filename, 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 285 of file class.ilFileDataForum.php.

286 {
287 if(file_exists($this->forum_path.'/'.$this->obj_id.'_'.$this->pos_id.'_'.$a_filename))
288 {
289 return unlink($this->forum_path.'/'.$this->obj_id.'_'.$this->pos_id."_".$a_filename);
290 }
291 }

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

266 {
267 if(is_array($a_filenames))
268 {
269 foreach($a_filenames as $file)
270 {
271 if(!$this->unlinkFile($file))
272 {
273 return $file;
274 }
275 }
276 }
277 return '';
278 }
unlinkFile($a_filename)
unlink one uploaded file expects a filename e.g 'foo'

References $file, and 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 333 of file class.ilFileDataForum.php.

334 {
335 $files = ilUtil::getDir( $this->forum_path );
336 if(is_array($a_md5_filename))
337 {
338 foreach((array)$files as $file)
339 {
340 if($file['type'] == 'file' && in_array(md5($file['entry']), $a_md5_filename))
341 {
342 unlink( $this->forum_path.'/'.$file['entry'] );
343 }
344 }
345
346 return true;
347 }
348 else
349 {
350 foreach((array)$files as $file)
351 {
352 if($file['type'] == 'file' && md5($file['entry']) == $a_md5_filename)
353 {
354 return unlink( $this->forum_path.'/'.$file['entry'] );
355 }
356 }
357 }
358
359 return false;
360 }

References $file, and ilUtil\getDir().

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