ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilObjFileAccess Class Reference

Access class for file objects. More...

+ Inheritance diagram for ilObjFileAccess:
+ Collaboration diagram for ilObjFileAccess:

Public Member Functions

 _getCommands ()
 get commands
 _checkGoto ($a_target)
 check whether goto script will succeed
 _lookupFileData ($a_id)
 
looks up the file_data for the file object with the specified object id

as an associative array.

 _lookupVersion ($a_id)
 lookup version
 _lookupSuffix ($a_id)
 lookup suffix
 _lookupDiskUsage ($a_id)
 Returns the number of bytes used on the harddisk by the file object with the specified object id.
 _lookupVersion ($a_id)
 lookup version
 _lookupFileSize ($a_id)
 lookup size
- Public Member Functions inherited from ilObjectAccess
 _checkAccess ($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id="")
 Checks wether a user may invoke a command or not (this method is called by ilAccessHandler::checkAccess)
 _checkCondition ($a_obj_id, $a_operator, $a_value, $a_usr_id=0)
 check condition

Static Public Member Functions

static _lookupFileSize ($a_id)
 Quickly looks up the file size from the database and returns the number of bytes.
static _lookupFileSizeFromFilesystem ($a_id)
 Looks up the file size by retrieving it from the filesystem.
static _isFileInline ($a_file_name)
 Returns true, if the specified file shall be displayed inline in the browser.
static _getFileExtension ($a_file_name)
 Gets the file extension of the specified file name.
static _isFileHidden ($a_file_name)
 Returns true, if a file with the specified name, is usually hidden from the user.
static _appendNumberOfCopyToFilename ($a_file_name, $nth_copy=null)
 Appends the text " - Copy" to a filename in the language of the current user.

Static Protected Attributes

static $_inlineFileExtensionsArray
 Contains an array of extensions separated by space.

Detailed Description

Access class for file objects.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
Id:
class.ilObjFileAccess.php 23288 2010-03-19 11:37:01Z smeyer

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

Member Function Documentation

static ilObjFileAccess::_appendNumberOfCopyToFilename (   $a_file_name,
  $nth_copy = null 
)
static

Appends the text " - Copy" to a filename in the language of the current user.

If the provided $nth_copy parameter is greater than 1, then is appended in round brackets. If $nth_copy parameter is null, then the function determines the copy number on its own.

If this function detects, that the filename already ends with " - Copy", or with "- Copy ($nth_copy), it only appends the number of the copy to the filename.

This function retains the extension of the filename.

Examples:

  • Calling ilObjFileAccess::_appendCopyToTitle('Hello.txt', 1) returns: "Hello - Copy.txt".
  • Calling ilObjFileAccess::_appendCopyToTitle('Hello.txt', 2) returns: "Hello - Copy (2).txt".
  • Calling ilObjFileAccess::_appendCopyToTitle('Hello - Copy (3).txt', 2) returns: "Hello - Copy (2).txt".
  • Calling ilObjFileAccess::_appendCopyToTitle('Hello - Copy (3).txt', null) returns: "Hello - Copy (4).txt".

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

References $lng, and _getFileExtension().

Referenced by ilObject\appendCopyInfo(), and ilContainerGUI\pasteObject().

{
global $lng;
// Get the extension and the filename without the extension
$extension = ilObjFileAccess::_getFileExtension($a_file_name);
if (strlen($extension) > 0)
{
$extension = '.'.$extension;
$filenameWithoutExtension= substr($a_file_name, 0, -strlen($extension));
}
else
{
$filenameWithoutExtension= $a_file_name;
}
// create a regular expression from the language text copy_n_of_suffix, so that
// we can match it against $filenameWithoutExtension, and retrieve the number of the copy.
// for example, if copy_n_of_suffix is 'Copy (%1s)', this creates the regular
// expression '/ Copy \\([0-9]+)\\)$/'.
$nthCopyRegex = preg_replace('/([\^$.\[\]|()?*+{}])/','\\\\${1}', ' '.$lng->txt('copy_n_of_suffix'));
$nthCopyRegex = '/'.preg_replace('/%1\\\\\$s/', '([0-9]+)', $nthCopyRegex).'$/';
// Get the filename without any previously added number of copy.
// Determine the number of copy, if it has not been specified.
if (preg_match($nthCopyRegex, $filenameWithoutExtension, $matches))
{
// this is going to be at least the third copy of the filename
$filenameWithoutCopy = substr($filenameWithoutExtension, 0, -strlen($matches[0]));
if ($nth_copy == null)
{
$nth_copy = $matches[1]+1;
}
}
else if (substr($filenameWithoutExtension,-strlen(' '.$lng->txt('copy_of_suffix'))) == ' '.$lng->txt('copy_of_suffix'))
{
// this is going to be the second copy of the filename
$filenameWithoutCopy = substr($filenameWithoutExtension, 0, -strlen(' '.$lng->txt('copy_of_suffix')));
if ($nth_copy == null)
{
$nth_copy = 2;
}
}
else
{
// this is going to be the first copy of the filename
$filenameWithoutCopy = $filenameWithoutExtension;
if ($nth_copy == null)
{
$nth_copy = 1;
}
}
// Construct the new filename
if ($nth_copy > 1)
{
// this is at least the second copy of the filename, append " - Copy ($nth_copy)"
$newFilename = $filenameWithoutCopy.sprintf(' '.$lng->txt('copy_n_of_suffix'), $nth_copy).$extension;
}
else
{
// this is the first copy of the filename, append " - Copy"
$newFilename = $filenameWithoutCopy.' '.$lng->txt('copy_of_suffix').$extension;
}
return $newFilename;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilObjFileAccess::_checkGoto (   $a_target)

check whether goto script will succeed

Reimplemented from ilObjectAccess.

Definition at line 72 of file class.ilObjFileAccess.php.

{
global $ilAccess;
$t_arr = explode("_", $a_target);
if ($t_arr[0] != "file" || ((int) $t_arr[1]) <= 0)
{
return false;
}
if ($ilAccess->checkAccess("visible", "", $t_arr[1]))
{
return true;
}
return false;
}
ilObjFileAccess::_getCommands ( )

get commands

this method returns an array of all possible commands/permission combinations

example: $commands = array ( array("permission" => "read", "cmd" => "view", "lang_var" => "show"), array("permission" => "write", "cmd" => "edit", "lang_var" => "edit"), );

Reimplemented from ilObjectAccess.

Definition at line 59 of file class.ilObjFileAccess.php.

Referenced by ilObjFileListGUI\init().

{
$commands = array();
$commands[] = array("permission" => "read", "cmd" => "sendfile", "lang_var" => "download","default" => true);
$commands[] = array("permission" => "write", "cmd" => "edit", "lang_var" => "edit");
$commands[] = array("permission" => "write", "cmd" => "versions", "lang_var" => "versions");
return $commands;
}

+ Here is the caller graph for this function:

static ilObjFileAccess::_getFileExtension (   $a_file_name)
static

Gets the file extension of the specified file name.

The file name extension is converted to lower case before it is returned.

For example, for the file name "HELLO.MP3", this function returns "mp3".

A file name extension can have multiple parts. For the file name "hello.tar.gz", this function returns "gz".

Parameters
string$a_file_nameThe file name

Definition at line 231 of file class.ilObjFileAccess.php.

Referenced by _appendNumberOfCopyToFilename(), _isFileInline(), _lookupSuffix(), ilObjFile\checkFileExtension(), ilObjFile\getFileExtension(), ilObjFileListGUI\getProperties(), and ilObjFileGUI\saveObject().

{
if (preg_match('/\.([a-z0-9]+)\z/i',$a_file_name,$matches) == 1)
{
return strtolower($matches[1]);
}
else
{
return '';
}
}

+ Here is the caller graph for this function:

static ilObjFileAccess::_isFileHidden (   $a_file_name)
static

Returns true, if a file with the specified name, is usually hidden from the user.

  • Filenames starting with '.' are hidden Unix files
  • Filenames ending with '~' are temporary Unix files
  • Filenames starting with '~$' are temporary Windows files
  • The file "Thumbs.db" is a hidden Windows file

Definition at line 252 of file class.ilObjFileAccess.php.

Referenced by ilCourseContentGUI\displayRow(), ilContainer\getSubItems(), and ilObjFile\isHidden().

{
return substr($a_file_name,0,1) == '.' ||
substr($a_file_name,-1,1) == '~' ||
substr($a_file_name,0,2) == '~$' ||
$a_file_name == 'Thumbs.db';
}

+ Here is the caller graph for this function:

static ilObjFileAccess::_isFileInline (   $a_file_name)
static

Returns true, if the specified file shall be displayed inline in the browser.

Definition at line 208 of file class.ilObjFileAccess.php.

References _getFileExtension().

Referenced by ilObjFileListGUI\getCommandFrame(), ilObjFileListGUI\getIconImageType(), and ilObjFile\isInline().

{
if (self::$_inlineFileExtensionsArray === null) // the === makes a huge difference, if the array is empty
{
require_once 'Services/Administration/classes/class.ilSetting.php';
$settings = new ilSetting('file_access');
self::$_inlineFileExtensionsArray = preg_split('/ /', $settings->get('inline_file_extensions'), -1, PREG_SPLIT_NO_EMPTY);
}
$extension = self::_getFileExtension($a_file_name);
return in_array($extension, self::$_inlineFileExtensionsArray);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilObjFileAccess::_lookupDiskUsage (   $a_id)

Returns the number of bytes used on the harddisk by the file object with the specified object id.

Parameters
intobject id of a file object.

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

References $dir, and ilUtil\dirsize().

Referenced by ilObjFile\getDiskUsage().

{
include_once('Modules/File/classes/class.ilFSStorageFile.php');
$fileStorage = new ilFSStorageFile($a_id);
$dir = $fileStorage->getAbsolutePath();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilObjFileAccess::_lookupFileData (   $a_id)

looks up the file_data for the file object with the specified object id

as an associative array.

Definition at line 94 of file class.ilObjFileAccess.php.

References $ilDB, $q, $row, and DB_FETCHMODE_ASSOC.

Referenced by ilObjFileListGUI\getProperties().

{
global $ilDB;
$q = "SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($a_id ,'integer');
$r = $ilDB->query($q);
$row = $r->fetchRow(DB_FETCHMODE_ASSOC);
return $row;
}

+ Here is the caller graph for this function:

ilObjFileAccess::_lookupFileSize (   $a_id)

lookup size

Definition at line 44 of file class.ilObjFileAccess.php.

References $file, $ilDB, $q, $row, $size, _lookupVersion(), and DB_FETCHMODE_OBJECT.

{
global $ilDB;
$q = "SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($a_id);
$r = $ilDB->query($q);
$row = $r->fetchRow(DB_FETCHMODE_OBJECT);
include_once('Services/Migration/DBUpdate_904/classes/class.ilFSStorageFile.php');
$fss = new ilFSStorageFile($a_id);
$file = $fss->getAbsolutePath().'/'.$row->file_name;
if (@!is_file($file))
{
$version_subdir = "/".sprintf("%03d", ilObjFileAccess::_lookupVersion($a_id));
$file = $fss->getAbsolutePath().'/'.$version_subdir.'/'.$row->file_name;
}
if (is_file($file))
{
$size = filesize($file);
}
else
{
$size = 0;
}
return $size;
}

+ Here is the call graph for this function:

static ilObjFileAccess::_lookupFileSize (   $a_id)
static

Quickly looks up the file size from the database and returns the number of bytes.

Definition at line 123 of file class.ilObjFileAccess.php.

References $ilDB, $q, $row, $size, and DB_FETCHMODE_OBJECT.

{
global $ilDB;
$q = "SELECT file_size FROM file_data WHERE file_id = ".$ilDB->quote($a_id ,'integer');
$r = $ilDB->query($q);
$row = $r->fetchRow(DB_FETCHMODE_OBJECT);
$size = $row->file_size;
return $size;
}
static ilObjFileAccess::_lookupFileSizeFromFilesystem (   $a_id)
static

Looks up the file size by retrieving it from the filesystem.

This function runs much slower than _lookupFileSize()! Use this function only, to update the data in the database. For example, if the file size in the database has become inconsistent for some reason.

Definition at line 142 of file class.ilObjFileAccess.php.

References $file, $ilDB, $q, $row, $size, _lookupVersion(), and DB_FETCHMODE_OBJECT.

{
global $ilDB;
$q = "SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($a_id ,'integer');
$r = $ilDB->query($q);
$row = $r->fetchRow(DB_FETCHMODE_OBJECT);
require_once('Modules/File/classes/class.ilFSStorageFile.php');
$fss = new ilFSStorageFile($a_id);
$file = $fss->getAbsolutePath().'/'.$row->file_name;
if (@!is_file($file))
{
$version_subdir = "/".sprintf("%03d", ilObjFileAccess::_lookupVersion($a_id));
$file = $fss->getAbsolutePath().'/'.$version_subdir.'/'.$row->file_name;
}
if (is_file($file))
{
$size = filesize($file);
}
else
{
$size = 0;
}
return $size;
}

+ Here is the call graph for this function:

ilObjFileAccess::_lookupSuffix (   $a_id)

lookup suffix

Definition at line 176 of file class.ilObjFileAccess.php.

References $ilDB, $q, $row, _getFileExtension(), and DB_FETCHMODE_OBJECT.

{
include_once('Modules/File/classes/class.ilFSStorageFile.php');
global $ilDB;
// BEGIN WebDAV: Filename suffix is determined by file title
$q = "SELECT * FROM object_data WHERE obj_id = ".$ilDB->quote($a_id ,'integer');
$r = $ilDB->query($q);
$row = $r->fetchRow(DB_FETCHMODE_OBJECT);
require_once 'Modules/File/classes/class.ilObjFile.php';
return self::_getFileExtension($row->title);
// END WebDAV: Filename suffix is determined by file title
}

+ Here is the call graph for this function:

ilObjFileAccess::_lookupVersion (   $a_id)

lookup version

Definition at line 30 of file class.ilObjFileAccess.php.

References $ilDB, $q, $row, and DB_FETCHMODE_OBJECT.

{
global $ilDB;
$q = "SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($a_id);
$r = $ilDB->query($q);
$row = $r->fetchRow(DB_FETCHMODE_OBJECT);
return $row->version;
}
ilObjFileAccess::_lookupVersion (   $a_id)

lookup version

Definition at line 108 of file class.ilObjFileAccess.php.

References $ilDB, $q, $row, DB_FETCHMODE_OBJECT, and ilUtil\stripSlashes().

Referenced by _lookupFileSize(), and _lookupFileSizeFromFilesystem().

{
global $ilDB;
$q = "SELECT version FROM file_data WHERE file_id = ".$ilDB->quote($a_id ,'integer');
$r = $ilDB->query($q);
$row = $r->fetchRow(DB_FETCHMODE_OBJECT);
return ilUtil::stripSlashes($row->version);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

ilObjFileAccess::$_inlineFileExtensionsArray
staticprotected

Contains an array of extensions separated by space.

Since this array is needed for every file object displayed on a repository page, we only create it once, and cache it here.

See Also
function _isFileInline

Definition at line 43 of file class.ilObjFileAccess.php.


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