ILIAS  Release_5_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.
 _preloadData ($a_obj_ids, $a_ref_ids)
 Preload data.
 _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)
 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, $a_handle_extension=false)
 Appends the text " - Copy" to a filename in the language of the current user.
static _getPermanentDownloadLink ($ref_id)
 Gets the permanent download link for the file.
static getListGUIData ($a_obj_id)
- Static Public Member Functions inherited from ilObjectAccess
static _isOffline ($a_obj_id)
 Type-specific implementation of general status, has to be overwritten.

Static Protected Attributes

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

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
Stefan Born stefa.nosp@m.n.bo.nosp@m.rn@ph.nosp@m.zh.c.nosp@m.h
Version
Id:
class.ilObjFileAccess.php 55977 2014-12-04 15:04:47Z jluetzen

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

Member Function Documentation

static ilObjFileAccess::_appendNumberOfCopyToFilename (   $a_file_name,
  $nth_copy = null,
  $a_handle_extension = false 
)
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 279 of file class.ilObjFileAccess.php.

References $lng, and _getFileExtension().

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

{
global $lng;
$filenameWithoutExtension= $a_file_name;
$extension = null;
if ($a_handle_extension)
{
// 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));
}
}
// 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 56 of file class.ilObjFileAccess.php.

References ilSharedResourceGUI\hasAccess().

{
global $ilAccess;
$t_arr = explode("_", $a_target);
// personal workspace context: do not force normal login
if(isset($t_arr[2]) && $t_arr[2] == "wsp")
{
include_once "Services/PersonalWorkspace/classes/class.ilSharedResourceGUI.php";
return ilSharedResourceGUI::hasAccess($t_arr[1]);
}
if ($t_arr[0] != "file" || ((int) $t_arr[1]) <= 0)
{
return false;
}
if ($ilAccess->checkAccess("visible", "", $t_arr[1]))
{
return true;
}
return false;
}

+ Here is the call graph for this function:

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 43 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_content");
$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 222 of file class.ilObjFileAccess.php.

Referenced by _appendNumberOfCopyToFilename(), _isFileInline(), _lookupSuffix(), ilObjFile\checkFileExtension(), ilObjFile\getFileExtension(), ilObjFileListGUI\getProperties(), ilObjFileGUI\handleFileUpload(), ilObjFileGUI\save(), and ilFilePreviewRenderer\supports().

{
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::_getPermanentDownloadLink (   $ref_id)
static

Gets the permanent download link for the file.

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

References $ref_id, and ilLink\_getStaticLink().

Referenced by ilObjFileListGUI\getCommandLink(), and ilObjFileGUI\infoScreenForward().

{
include_once("./Services/Link/classes/class.ilLink.php");
return ilLink::_getStaticLink($ref_id, "file", true, "_download");
}

+ Here is the call graph for this function:

+ 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 243 of file class.ilObjFileAccess.php.

Referenced by ilItemGroupItems\getAssignableItems(), ilObjectListGUI\getListItemHTML(), ilContainer\getSubItems(), ilObjFile\isHidden(), and ilExportSelectionTableGUI\parseContainer().

{
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 199 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 187 of file class.ilObjFileAccess.php.

References ilUtil\dirsize().

Referenced by ilObjFile\getDiskUsage().

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

+ 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 85 of file class.ilObjFileAccess.php.

References $ilDB, $row, and DB_FETCHMODE_ASSOC.

{
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;
}
ilObjFileAccess::_lookupFileSize (   $a_id)

lookup size

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

References $file, $ilDB, $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 114 of file class.ilObjFileAccess.php.

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

Referenced by ilObjectXMLWriter\__appendObjectProperties().

{
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;
}

+ Here is the caller graph for this function:

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 133 of file class.ilObjFileAccess.php.

References $file, $ilDB, $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 167 of file class.ilObjFileAccess.php.

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

Referenced by ilObjectXMLWriter\__appendObjectProperties().

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

+ Here is the caller graph for this function:

ilObjFileAccess::_lookupVersion (   $a_id)

lookup version

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

References $ilDB, $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 99 of file class.ilObjFileAccess.php.

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

Referenced by ilObjectXMLWriter\__appendObjectProperties(), _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:

ilObjFileAccess::_preloadData (   $a_obj_ids,
  $a_ref_ids 
)

Preload data.

Parameters
array$a_obj_idsarray of object ids

Reimplemented from ilObjectAccess.

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

References $ilDB, and $row.

{
global $ilDB;
self::$preload_list_gui_data = array();
$set = $ilDB->query("SELECT obj_id,max(hdate) latest".
" FROM history".
" WHERE obj_type = ".$ilDB->quote("file", "text").
" AND ".$ilDB->in("obj_id", $a_obj_ids, "", "integer").
" GROUP BY obj_id");
while($row = $ilDB->fetchAssoc($set))
{
self::$preload_list_gui_data[$row["obj_id"]]["date"] = $row["latest"];
}
$set = $ilDB->query("SELECT file_size,version,file_id".
" FROM file_data".
" WHERE ".$ilDB->in("file_id", $a_obj_ids, "", "integer"));
while($row = $ilDB->fetchAssoc($set))
{
self::$preload_list_gui_data[$row["file_id"]]["size"] = $row["file_size"];
self::$preload_list_gui_data[$row["file_id"]]["version"] = $row["version"];
}
}
static ilObjFileAccess::getListGUIData (   $a_obj_id)
static

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

Referenced by ilObjFileListGUI\getProperties().

{
if(isset(self::$preload_list_gui_data[$a_obj_id]))
{
return self::$preload_list_gui_data[$a_obj_id];
}
}

+ 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 25 of file class.ilObjFileAccess.php.

ilObjFileAccess::$preload_list_gui_data
staticprotected

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


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