ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
ilObjFileAccess Class Reference

Access class for file objects. More...

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

Public Member Functions

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

as an associative array. More...

 
 _lookupVersion ($a_id)
 lookup version More...
 
 _lookupSuffix ($a_id)
 lookup suffix More...
 
 _lookupDiskUsage ($a_id)
 Returns the number of bytes used on the harddisk by the file object with the specified object id. More...
 
 _preloadData ($a_obj_ids, $a_ref_ids)
 
 _lookupVersion ($a_id)
 lookup version More...
 
 _lookupFileSize ($a_id)
 lookup size More...
 
- 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) More...
 
 _checkCondition ($a_obj_id, $a_operator, $a_value, $a_usr_id=0)
 check condition More...
 
 _getCommands ()
 get commands More...
 
 _checkGoto ($a_target)
 check whether goto script will succeed More...
 
 _preloadData ($a_obj_ids, $a_ref_ids)
 Preload data. More...
 

Static Public Member Functions

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

Static Protected Attributes

static $_inlineFileExtensionsArray
 Contains an array of extensions separated by space. More...
 
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$

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

Member Function Documentation

◆ _appendNumberOfCopyToFilename()

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

References $lng, and _getFileExtension().

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

280  {
281  global $lng;
282 
283  // Get the extension and the filename without the extension
284  $extension = ilObjFileAccess::_getFileExtension($a_file_name);
285  if (strlen($extension) > 0)
286  {
287  $extension = '.'.$extension;
288  $filenameWithoutExtension= substr($a_file_name, 0, -strlen($extension));
289  }
290  else
291  {
292  $filenameWithoutExtension= $a_file_name;
293  }
294 
295  // create a regular expression from the language text copy_n_of_suffix, so that
296  // we can match it against $filenameWithoutExtension, and retrieve the number of the copy.
297  // for example, if copy_n_of_suffix is 'Copy (%1s)', this creates the regular
298  // expression '/ Copy \\([0-9]+)\\)$/'.
299  $nthCopyRegex = preg_replace('/([\^$.\[\]|()?*+{}])/','\\\\${1}', ' '.$lng->txt('copy_n_of_suffix'));
300  $nthCopyRegex = '/'.preg_replace('/%1\\\\\$s/', '([0-9]+)', $nthCopyRegex).'$/';
301 
302  // Get the filename without any previously added number of copy.
303  // Determine the number of copy, if it has not been specified.
304  if (preg_match($nthCopyRegex, $filenameWithoutExtension, $matches))
305  {
306  // this is going to be at least the third copy of the filename
307  $filenameWithoutCopy = substr($filenameWithoutExtension, 0, -strlen($matches[0]));
308  if ($nth_copy == null)
309  {
310  $nth_copy = $matches[1]+1;
311  }
312  }
313  else if (substr($filenameWithoutExtension,-strlen(' '.$lng->txt('copy_of_suffix'))) == ' '.$lng->txt('copy_of_suffix'))
314  {
315  // this is going to be the second copy of the filename
316  $filenameWithoutCopy = substr($filenameWithoutExtension, 0, -strlen(' '.$lng->txt('copy_of_suffix')));
317  if ($nth_copy == null)
318  {
319  $nth_copy = 2;
320  }
321  }
322  else
323  {
324  // this is going to be the first copy of the filename
325  $filenameWithoutCopy = $filenameWithoutExtension;
326  if ($nth_copy == null)
327  {
328  $nth_copy = 1;
329  }
330  }
331 
332 
333  // Construct the new filename
334  if ($nth_copy > 1)
335  {
336  // this is at least the second copy of the filename, append " - Copy ($nth_copy)"
337  $newFilename = $filenameWithoutCopy.sprintf(' '.$lng->txt('copy_n_of_suffix'), $nth_copy).$extension;
338  }
339  else
340  {
341  // this is the first copy of the filename, append " - Copy"
342  $newFilename = $filenameWithoutCopy.' '.$lng->txt('copy_of_suffix').$extension;
343  }
344 
345  return $newFilename;
346  }
static _getFileExtension($a_file_name)
Gets the file extension of the specified file name.
global $lng
Definition: privfeed.php:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _checkGoto()

ilObjFileAccess::_checkGoto (   $a_target)

check whether goto script will succeed

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

References ilSharedResourceGUI\hasAccess().

57  {
58  global $ilAccess;
59 
60  $t_arr = explode("_", $a_target);
61 
62  // personal workspace context: do not force normal login
63  if(isset($t_arr[2]) && $t_arr[2] == "wsp")
64  {
65  include_once "Services/PersonalWorkspace/classes/class.ilSharedResourceGUI.php";
66  return ilSharedResourceGUI::hasAccess($t_arr[1]);
67  }
68 
69  if ($t_arr[0] != "file" || ((int) $t_arr[1]) <= 0)
70  {
71  return false;
72  }
73 
74  if ($ilAccess->checkAccess("visible", "", $t_arr[1]))
75  {
76  return true;
77  }
78  return false;
79  }
static hasAccess($a_node_id, $a_is_portfolio=false)
+ Here is the call graph for this function:

◆ _getCommands()

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"), );

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

Referenced by ilObjFileListGUI\init().

44  {
45  $commands = array();
46  $commands[] = array("permission" => "read", "cmd" => "sendfile", "lang_var" => "download","default" => true);
47  $commands[] = array("permission" => "write", "cmd" => "edit", "lang_var" => "edit_content");
48  $commands[] = array("permission" => "write", "cmd" => "versions", "lang_var" => "versions");
49 
50  return $commands;
51  }
+ Here is the caller graph for this function:

◆ _getFileExtension()

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(), ilObjFile\checkFileExtension(), ilObjFile\getFileExtension(), ilObjFileListGUI\getProperties(), ilObjFileGUI\handleFileUpload(), ilObjFileGUI\save(), and ilFilePreviewRenderer\supports().

223  {
224  if (preg_match('/\.([a-z0-9]+)\z/i',$a_file_name,$matches) == 1)
225  {
226  return strtolower($matches[1]);
227  }
228  else
229  {
230  return '';
231  }
232  }
+ Here is the caller graph for this function:

◆ _getPermanentDownloadLink()

static ilObjFileAccess::_getPermanentDownloadLink (   $ref_id)
static

Gets the permanent download link for the file.

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

References $ref_id, and ilLink\_getStaticLink().

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

352  {
353  include_once("./Services/Link/classes/class.ilLink.php");
354  return ilLink::_getStaticLink($ref_id, "file", true, "_download");
355  }
$ref_id
Definition: sahs_server.php:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _isFileHidden()

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(), and ilObjFile\isHidden().

244  {
245  return substr($a_file_name,0,1) == '.' ||
246  substr($a_file_name,-1,1) == '~' ||
247  substr($a_file_name,0,2) == '~$' ||
248  $a_file_name == 'Thumbs.db';
249  }
+ Here is the caller graph for this function:

◆ _isFileInline()

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.

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

200  {
201  if (self::$_inlineFileExtensionsArray === null) // the === makes a huge difference, if the array is empty
202  {
203  require_once 'Services/Administration/classes/class.ilSetting.php';
204  $settings = new ilSetting('file_access');
205  self::$_inlineFileExtensionsArray = preg_split('/ /', $settings->get('inline_file_extensions'), -1, PREG_SPLIT_NO_EMPTY);
206  }
207  $extension = self::_getFileExtension($a_file_name);
208  return in_array($extension, self::$_inlineFileExtensionsArray);
209  }
ILIAS Setting Class.
+ Here is the caller graph for this function:

◆ _lookupDiskUsage()

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().

188  {
189  include_once('Modules/File/classes/class.ilFSStorageFile.php');
190  $fileStorage = new ilFSStorageFile($a_id);
191  $dir = $fileStorage->getAbsolutePath();
192  return ilUtil::dirsize($dir);
193  }
static dirsize($directory)
get size of a directory or a file.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _lookupFileData()

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 $r, $row, and DB_FETCHMODE_ASSOC.

86  {
87  global $ilDB;
88 
89  $q = "SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($a_id ,'integer');
90  $r = $ilDB->query($q);
91  $row = $r->fetchRow(DB_FETCHMODE_ASSOC);
92 
93  return $row;
94  }
const DB_FETCHMODE_ASSOC
Definition: class.ilDB.php:10
$r

◆ _lookupFileSize() [1/2]

ilObjFileAccess::_lookupFileSize (   $a_id)

lookup size

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

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

45  {
46  global $ilDB;
47 
48  $q = "SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($a_id);
49  $r = $ilDB->query($q);
50  $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
51 
52  include_once('Services/Migration/DBUpdate_904/classes/class.ilFSStorageFile.php');
53  $fss = new ilFSStorageFile($a_id);
54  $file = $fss->getAbsolutePath().'/'.$row->file_name;
55 
56  if (@!is_file($file))
57  {
58  $version_subdir = "/".sprintf("%03d", ilObjFileAccess::_lookupVersion($a_id));
59  $file = $fss->getAbsolutePath().'/'.$version_subdir.'/'.$row->file_name;
60 
61  }
62 
63  if (is_file($file))
64  {
65  $size = filesize($file);
66  }
67  else
68  {
69  $size = 0;
70  }
71 
72  return $size;
73  }
print $file
$size
Definition: RandomTest.php:79
_lookupVersion($a_id)
lookup version
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
$r
+ Here is the call graph for this function:

◆ _lookupFileSize() [2/2]

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 $r, $row, $size, and DB_FETCHMODE_OBJECT.

Referenced by ilObjectXMLWriter\__appendObjectProperties(), and ilObjFile\_lookupFileSize().

115  {
116  global $ilDB;
117 
118  $q = "SELECT file_size FROM file_data WHERE file_id = ".$ilDB->quote($a_id ,'integer');
119  $r = $ilDB->query($q);
120  $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
121 
122  $size = $row->file_size;
123 
124  return $size;
125  }
$size
Definition: RandomTest.php:79
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
$r
+ Here is the caller graph for this function:

◆ _lookupFileSizeFromFilesystem()

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, $r, $row, $size, _lookupVersion(), and DB_FETCHMODE_OBJECT.

134  {
135  global $ilDB;
136 
137  $q = "SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($a_id ,'integer');
138  $r = $ilDB->query($q);
139  $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
140 
141  require_once('Modules/File/classes/class.ilFSStorageFile.php');
142  $fss = new ilFSStorageFile($a_id);
143  $file = $fss->getAbsolutePath().'/'.$row->file_name;
144 
145  if (@!is_file($file))
146  {
147  $version_subdir = "/".sprintf("%03d", ilObjFileAccess::_lookupVersion($a_id));
148  $file = $fss->getAbsolutePath().'/'.$version_subdir.'/'.$row->file_name;
149  }
150 
151  if (is_file($file))
152  {
153  $size = filesize($file);
154  }
155  else
156  {
157  $size = 0;
158  }
159 
160  return $size;
161  }
print $file
$size
Definition: RandomTest.php:79
_lookupVersion($a_id)
lookup version
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
$r
+ Here is the call graph for this function:

◆ _lookupSuffix()

ilObjFileAccess::_lookupSuffix (   $a_id)

lookup suffix

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

References $r, $row, and DB_FETCHMODE_OBJECT.

Referenced by ilObjectXMLWriter\__appendObjectProperties().

168  {
169  include_once('Modules/File/classes/class.ilFSStorageFile.php');
170 
171  global $ilDB;
172 
173  // BEGIN WebDAV: Filename suffix is determined by file title
174  $q = "SELECT * FROM object_data WHERE obj_id = ".$ilDB->quote($a_id ,'integer');
175  $r = $ilDB->query($q);
176  $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
177  require_once 'Modules/File/classes/class.ilObjFile.php';
178  return self::_getFileExtension($row->title);
179  // END WebDAV: Filename suffix is determined by file title
180  }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
$r
+ Here is the caller graph for this function:

◆ _lookupVersion() [1/2]

ilObjFileAccess::_lookupVersion (   $a_id)

lookup version

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

References $r, $row, and DB_FETCHMODE_OBJECT.

31  {
32  global $ilDB;
33 
34  $q = "SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($a_id);
35  $r = $ilDB->query($q);
36  $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
37 
38  return $row->version;
39  }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
$r

◆ _lookupVersion() [2/2]

ilObjFileAccess::_lookupVersion (   $a_id)

lookup version

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

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

Referenced by ilObjectXMLWriter\__appendObjectProperties(), _lookupFileSize(), _lookupFileSizeFromFilesystem(), and ilObjFile\_lookupVersion().

100  {
101  global $ilDB;
102 
103  $q = "SELECT version FROM file_data WHERE file_id = ".$ilDB->quote($a_id ,'integer');
104  $r = $ilDB->query($q);
105  $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
106 
107  return ilUtil::stripSlashes($row->version);
108  }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
$r
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _preloadData()

ilObjFileAccess::_preloadData (   $a_obj_ids,
  $a_ref_ids 
)

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

References $row.

358  {
359  global $ilDB;
360 
361  self::$preload_list_gui_data = array();
362 
363  $set = $ilDB->query("SELECT obj_id,max(hdate) latest".
364  " FROM history".
365  " WHERE obj_type = ".$ilDB->quote("file", "text").
366  " AND ".$ilDB->in("obj_id", $a_obj_ids, "", "integer").
367  " GROUP BY obj_id");
368  while($row = $ilDB->fetchAssoc($set))
369  {
370  self::$preload_list_gui_data[$row["obj_id"]]["date"] = $row["latest"];
371  }
372 
373  $set = $ilDB->query("SELECT file_size,version,file_id".
374  " FROM file_data".
375  " WHERE ".$ilDB->in("file_id", $a_obj_ids, "", "integer"));
376  while($row = $ilDB->fetchAssoc($set))
377  {
378  self::$preload_list_gui_data[$row["file_id"]]["size"] = $row["file_size"];
379  self::$preload_list_gui_data[$row["file_id"]]["version"] = $row["version"];
380  }
381  }

◆ getListGUIData()

static ilObjFileAccess::getListGUIData (   $a_obj_id)
static

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

Referenced by ilObjFileListGUI\getProperties().

384  {
385  if(isset(self::$preload_list_gui_data[$a_obj_id]))
386  {
387  return self::$preload_list_gui_data[$a_obj_id];
388  }
389  }
+ Here is the caller graph for this function:

Field Documentation

◆ $_inlineFileExtensionsArray

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.

◆ $preload_list_gui_data

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