ILIAS  Release_3_10_x_branch Revision 61812
 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 ($a_http_post_file)
 store uploaded file 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

Static Public Member Functions

static _getDiskSpaceUsedBy ($user_id, $as_string=false)
 Returns the number of bytes used on the harddisk for forum attachments, by the user with the specified user id.

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 20451 2009-07-07 10:30:26Z mjansen

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

Member Function Documentation

ilFileDataForum::__checkPath ( )

Definition at line 359 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 375 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 392 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 414 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:

static ilFileDataForum::_getDiskSpaceUsedBy (   $user_id,
  $as_string = false 
)
static

Returns the number of bytes used on the harddisk for forum attachments, by the user with the specified user id.

Parameters
intuser id.

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

References $lng, $size, ilObjFileAccess\_sizeToString(), DB_FETCHMODE_ASSOC, ilUtil\getDataDir(), and ilFileDataForum().

{
// XXX - This method is extremely slow. We should
// use a cache to speed it up, for example, we should
// store the disk space used in table forum_attachment.
global $ilDB, $lng;
$mail_data_dir = ilUtil::getDataDir('filesystem').DIRECTORY_SEPARATOR."forum";
$q = "SELECT top_frm_fk, pos_pk ".
"FROM frm_posts AS p ".
"JOIN frm_data AS d ON d.top_pk=p.pos_top_fk ".
"WHERE p.pos_usr_id = ".$ilDB->quote($user_id);
$result_set = $ilDB->query($q);
$size = 0;
$count = 0;
while($row = $result_set->fetchRow(DB_FETCHMODE_ASSOC))
{
$fileDataForum = new ilFileDataForum($row['top_frm_fk'],$row['pos_pk']);
$filesOfPost = $fileDataForum->getFilesOfPost();
foreach ($filesOfPost as $attachment)
{
$size += $attachment['size'];
$count++;
}
unset($fileDataForum);
unset($filesOfPost);
}
include_once("Modules/File/classes/class.ilObjFileAccess.php");
return ($as_string) ?
$count.' '.$lng->txt('forum_attachments').', '.ilObjFileAccess::_sizeToString($size) :
}

+ Here is the call graph for this function:

ilFileDataForum::checkFilesExist (   $a_files)

check if files exist

Parameters
arrayfilenames to check public
Returns
bool

Definition at line 342 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 272 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 283 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().

Referenced by _getDiskSpaceUsedBy().

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

+ Here is the caller 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 (   $a_http_post_file)

store uploaded file in filesystem

Parameters
arrayHTTP_POST_FILES public
Returns
bool

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

References __rotateFiles(), ilUtil\_sanitizeFilemame(), getForumPath(), and ilUtil\moveUploadedFile().

Referenced by ilObjForumGUI\addThreadObject(), and ilObjForumGUI\viewThreadObject().

{
// TODO:
// CHECK UPLOAD LIMIT
//
if(isset($a_http_post_file) && $a_http_post_file['size'])
{
$a_http_post_file['name'] = ilUtil::_sanitizeFilemame($a_http_post_file['name']);
// CHECK IF FILE WITH SAME NAME EXISTS
$this->__rotateFiles($this->getForumPath().'/'.$this->obj_id.'_'.$this->pos_id."_".$a_http_post_file['name']);
ilUtil::moveUploadedFile($a_http_post_file['tmp_name'], $a_http_post_file['name'],
$this->getForumPath().'/'.$this->obj_id.'_'.$this->pos_id."_".
$a_http_post_file['name']);
//move_uploaded_file($a_http_post_file['tmp_name'],$this->getForumPath().'/'.$this->obj_id.'_'.$this->pos_id."_".
// $a_http_post_file['name']);
}
return true;
}

+ 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 259 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 239 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 307 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: