ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups 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

 ilFileDataForum ($a_obj_id=0, $a_pos_id=0)
 Constructor call base constructors checks if directory is writable and sets the optional obj_id.
 getObjId ()
 getPosId ()
 setPosId ($a_id)
 getForumPath ()
 get forum path public
 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.
 unlinkFiles ($a_filenames)
 unlink files: expects an array of filenames e.g.
 unlinkFile ($a_filename)
 unlink one uploaded file expects a filename e.g 'foo'
 getAbsolutePath ($a_path)
 get absolute path of filename
 getFileDataByMD5Filename ($a_md5_filename)
 get file data of a specific attachment
 unlinkFilesByMD5Filenames ($a_md5_filename)
 get file data of a specific attachment
 checkFilesExist ($a_files)
 check if files exist
 __checkPath ()
 __checkReadWrite ()
 check if directory is writable overwritten method from base class private
 __initDirectory ()
 init directory overwritten method public
 __rotateFiles ($a_path)
 rotate files with same name recursive method
- Public Member Functions inherited from ilFileData
 ilFileData ()
 Constructor class bas constructor and read path of directory from ilias.ini setup an mail object public.
 checkPath ($a_path)
 check if path exists and is writable
 getPath ()
 get Path public
- Public Member Functions inherited from ilFile
 ilFile ()
 Constructor get ilias object public.
 deleteTrailingSlash ($a_path)
 delete trailing slash of path variables

Data Fields

 $obj_id
 $pos_id
 $forum_path

Detailed Description

This class handles all operations on files for the forum object.

Author
Stefan Meyer smeye.nosp@m.r@da.nosp@m.tabay.nosp@m..de
Version
Id:
class.ilFileDataForum.php 21662 2009-09-14 14:26:02Z mjansen

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

Member Function Documentation

ilFileDataForum::__checkPath ( )

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

References __checkReadWrite(), and getForumPath().

Referenced by ilFileDataForum().

{
if(!@file_exists($this->getForumPath()))
{
return false;
}
$this->__checkReadWrite();
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilFileDataForum::__checkReadWrite ( )

check if directory is writable overwritten method from base class private

Returns
bool

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

Referenced by __checkPath().

{
if(is_writable($this->forum_path) && is_readable($this->forum_path))
{
return true;
}
else
{
$this->ilias->raiseError("Forum directory is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
}
}

+ Here is the caller graph for this function:

ilFileDataForum::__initDirectory ( )

init directory overwritten method public

Returns
string path

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

References ilFileData\getPath().

Referenced by ilFileDataForum().

{
if(is_writable($this->getPath()))
{
if(mkdir($this->getPath().'/'.FORUM_PATH))
{
if(chmod($this->getPath().'/'.FORUM_PATH,0755))
{
$this->forum_path = $this->getPath().'/'.FORUM_PATH;
return true;
}
}
}
return false;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilFileDataForum::__rotateFiles (   $a_path)

rotate files with same name recursive method

Parameters
stringfilename private
Returns
bool

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

Referenced by storeUploadedFile().

{
if(file_exists($a_path))
{
$this->__rotateFiles($a_path.".old");
return rename($a_path,$a_path.'.old');
}
return true;
}

+ Here is the caller graph for this function:

ilFileDataForum::checkFilesExist (   $a_files)

check if files exist

Parameters
arrayfilenames to check public
Returns
bool

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

References $file.

{
if($a_files)
{
foreach($a_files as $file)
{
if(!file_exists($this->forum_path.'/'.$this->obj_id.'_'.$this->pos_id.'_'.$file))
{
return false;
}
}
return true;
}
return true;
}
ilFileDataForum::delete ( )

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

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

{
foreach($this->getFiles() as $file)
{
if(file_exists($this->getForumPath()."/".$this->getObjId()."_".$file["name"]))
{
unlink($this->getForumPath()."/".$this->getObjId()."_".$file["name"]);
}
}
return true;
}

+ Here is the call graph for this function:

ilFileDataForum::getAbsolutePath (   $a_path)

get absolute path of filename

Parameters
stringrelative path public
Returns
string absolute path

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

{
return $this->forum_path.'/'.$this->obj_id.'_'.$this->pos_id."_".$a_path;
}
ilFileDataForum::getFileDataByMD5Filename (   $a_md5_filename)

get file data of a specific attachment

Parameters
stringmd5 encrypted filename public
Returns
array filedata

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

References $file, $files, and ilUtil\getDir().

{
$files = ilUtil::getDir( $this->forum_path );
foreach((array)$files as $file)
{
if($file['type'] == 'file' && md5($file['entry']) == $a_md5_filename)
{
return array(
'path' => $this->forum_path.'/'.$file['entry'],
'filename' => $file['entry'],
'clean_filename' => str_replace($this->obj_id.'_'.$this->pos_id.'_', '', $file['entry'])
);
}
}
return false;
}

+ Here is the call graph for this function:

ilFileDataForum::getFiles ( )

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

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

Referenced by delete().

{
$files = array();
$dp = opendir($this->forum_path);
while($file = readdir($dp))
{
if(is_dir($file))
{
continue;
}
list($obj_id,$rest) = split('_',$file,2);
if($obj_id == $this->obj_id)
{
if(!is_dir($this->forum_path.'/'.$file))
{
$files[] = array(
'md5' => md5($this->obj_id.'_'.$this->pos_id.'_'.$rest),
'name' => $rest,
'size' => filesize($this->forum_path.'/'.$file),
'ctime' => ilFormat::formatDate(date('Y-m-d H:i:s',filectime($this->forum_path.'/'.$file))));
}
}
}
closedir($dp);
return $files;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilFileDataForum::getFilesOfPost ( )

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

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

Referenced by ilClone().

{
$files = array();
$dp = opendir($this->forum_path);
while($file = readdir($dp))
{
if(is_dir($file))
{
continue;
}
list($obj_id,$rest) = split('_',$file,2);
if($obj_id == $this->obj_id)
{
list($pos_id,$rest) = split('_',$rest,2);
if($pos_id == $this->getPosId())
{
if(!is_dir($this->forum_path.'/'.$file))
{
$files[] = array(
'md5' => md5($this->obj_id.'_'.$this->pos_id.'_'.$rest),
'name' => $rest,
'size' => filesize($this->forum_path.'/'.$file),
'ctime' => ilFormat::formatDate(date('Y-m-d H:i:s',filectime($this->forum_path.'/'.$file))));
}
}
}
}
closedir($dp);
return $files;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilFileDataForum::getForumPath ( )

get forum path public

Returns
string path

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

References $forum_path.

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

{
}

+ Here is the caller graph for this function:

ilFileDataForum::getObjId ( )

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

References $obj_id.

Referenced by delete().

{
return $this->obj_id;
}

+ Here is the caller graph for this function:

ilFileDataForum::getPosId ( )

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

References $pos_id.

Referenced by getFilesOfPost(), and moveFilesOfPost().

{
return $this->pos_id;
}

+ Here is the caller graph for this function:

ilFileDataForum::ilClone (   $a_new_obj_id,
  $a_new_pos_id 
)

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

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

{
foreach($this->getFilesOfPost() as $file)
{
@copy($this->getForumPath()."/".$this->obj_id."_".$this->pos_id."_".$file["name"],
$this->getForumPath()."/".$a_new_obj_id."_".$a_new_pos_id."_".$file["name"]);
}
return true;
}

+ Here is the call graph for this function:

ilFileDataForum::ilFileDataForum (   $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 58 of file class.ilFileDataForum.php.

References __checkPath(), __initDirectory(), ilFileData\getPath(), and ilFileData\ilFileData().

{
define('FORUM_PATH', 'forum');
$this->forum_path = parent::getPath()."/".FORUM_PATH;
// IF DIRECTORY ISN'T CREATED CREATE IT
if(!$this->__checkPath())
{
$this->__initDirectory();
}
$this->obj_id = $a_obj_id;
$this->pos_id = $a_pos_id;
}

+ Here is the call graph for this function:

ilFileDataForum::moveFilesOfPost (   $a_new_frm_id = 0)

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

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

{
if((int)$a_new_frm_id)
{
$dp = opendir($this->forum_path);
while($file = readdir($dp))
{
if(is_dir($file))
{
continue;
}
list($obj_id,$rest) = split('_',$file,2);
if($obj_id == $this->obj_id)
{
list($pos_id,$rest) = split('_',$rest,2);
if($pos_id == $this->getPosId())
{
if(!is_dir($this->forum_path.'/'.$file))
{
@rename($this->forum_path.'/'.$file, $this->forum_path.'/'.$a_new_frm_id.'_'.$this->pos_id.'_'.$rest);
}
}
}
}
closedir($dp);
return true;
}
return false;
}

+ Here is the call graph for this function:

ilFileDataForum::setPosId (   $a_id)

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

{
$this->pos_id = $a_id;
}
ilFileDataForum::storeUploadedFile (   $files)

Store uploaded files in filesystem.

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

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

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

Referenced by ilObjForumGUI\addThreadObject().

{
if(isset($files['name']) && is_array($files['name']))
{
foreach($files['name'] as $index => $name)
{
// remove trailing '/'
while(substr($name, -1) == '/')
{
$name = substr($name, 0, -1);
}
$temp_name = $files['tmp_name'][$index];
$error = $files['error'][$index];
if(strlen($filename) && strlen($temp_name) && $error == 0)
{
$path = $this->getForumPath().'/'.$this->obj_id.'_'.$this->pos_id.'_'.$filename;
}
}
return true;
}
else if(isset($files['name']) && is_string($files['name']))
{
// remove trailing '/'
while(substr($files['name'], -1) == '/')
{
$files['name'] = substr($files['name'], 0, -1);
}
$temp_name = $files['tmp_name'];
$path = $this->getForumPath().'/'.$this->obj_id.'_'.$this->pos_id.'_'.$filename;
return true;
}
return false;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilFileDataForum::unlinkFile (   $a_filename)

unlink one uploaded file expects a filename e.g 'foo'

Parameters
stringfilename to delete public
Returns
bool

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

Referenced by unlinkFiles().

{
if(file_exists($this->forum_path.'/'.$this->obj_id.'_'.$this->pos_id.'_'.$a_filename))
{
return unlink($this->forum_path.'/'.$this->obj_id.'_'.$this->pos_id."_".$a_filename);
}
}

+ Here is the caller graph for this function:

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

References $file, and unlinkFile().

{
if(is_array($a_filenames))
{
foreach($a_filenames as $file)
{
if(!$this->unlinkFile($file))
{
return $file;
}
}
}
return '';
}

+ Here is the call graph for this function:

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

References $file, $files, and ilUtil\getDir().

{
$files = ilUtil::getDir( $this->forum_path );
if(is_array($a_md5_filename))
{
foreach((array)$files as $file)
{
if($file['type'] == 'file' && in_array(md5($file['entry']), $a_md5_filename))
{
unlink( $this->forum_path.'/'.$file['entry'] );
}
}
return true;
}
else
{
foreach((array)$files as $file)
{
if($file['type'] == 'file' && md5($file['entry']) == $a_md5_filename)
{
return unlink( $this->forum_path.'/'.$file['entry'] );
}
}
}
return false;
}

+ Here is the call graph for this function:

Field Documentation

ilFileDataForum::$forum_path

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

Referenced by getForumPath().

ilFileDataForum::$obj_id

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

Referenced by getFiles(), getFilesOfPost(), getObjId(), and moveFilesOfPost().

ilFileDataForum::$pos_id

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

Referenced by getFilesOfPost(), getPosId(), and moveFilesOfPost().


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