ILIAS  release_7 Revision v7.30-3-g800a261c036
ilObjFileAccess Class Reference

Access class for file objects. More...

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

Public Member Functions

 canBeDelivered (ilWACPath $ilWACPath)
 
 isMigrated ()
 
 _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)
 check condition More...
 
 canBeDelivered (ilWACPath $ilWACPath)
 
Parameters
ilWACPath$ilWACPath
Returns
bool
More...
 
 canBeDelivered (ilWACPath $ilWACPath)
 

Static Public Member Functions

static _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"), ); More...
 
static _checkGoto ($a_target)
 check whether goto script will succeed More...
 
static _lookupFileData ($a_id)
 looks up the file_data for the file object with the specified object id as an associative array. More...
 
static _lookupVersion ($a_id)
 lookup version More...
 
static _lookupFileSize ($a_id)
 
static _lookupFileSizeFromFilesystem ($a_id)
 Looks up the file size by retrieving it from the filesystem. More...
 
static _lookupSuffix ($a_id)
 lookup suffix More...
 
static _lookupDiskUsage ($a_id)
 Returns the number of bytes used on the harddisk by the file object with the specified object id. 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, $a_handle_extension=false)
 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 _getCommands ()
 get commands More...
 
static _checkGoto ($a_target)
 check whether goto script will succeed More...
 
static _isOffline ($a_obj_id)
 Type-specific implementation of general status, has to be overwritten if object type does not support centralized offline handling. More...
 
static _preloadData ($a_obj_ids, $a_ref_ids)
 Preload data. 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 17 of file class.ilObjFileAccess.php.

Member Function Documentation

◆ _appendNumberOfCopyToFilename()

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

331 {
332 global $DIC;
333 $lng = $DIC['lng'];
334
335 $filenameWithoutExtension = $a_file_name;
336
337 $extension = null;
338 if ($a_handle_extension) {
339 // Get the extension and the filename without the extension
340 $extension = ilObjFileAccess::_getFileExtension($a_file_name);
341 if (strlen($extension) > 0) {
342 $extension = '.' . $extension;
343 $filenameWithoutExtension = substr($a_file_name, 0, -strlen($extension));
344 }
345 }
346
347 // create a regular expression from the language text copy_n_of_suffix, so that
348 // we can match it against $filenameWithoutExtension, and retrieve the number of the copy.
349 // for example, if copy_n_of_suffix is 'Copy (%1s)', this creates the regular
350 // expression '/ Copy \\‍([0-9]+)\\‍)$/'.
351 $nthCopyRegex = preg_replace('/([\^$.\[\]|()?*+{}])/', '\\\\${1}', ' '
352 . $lng->txt('copy_n_of_suffix'));
353 $nthCopyRegex = '/' . preg_replace('/%1\\\\\$s/', '([0-9]+)', $nthCopyRegex) . '$/';
354
355 // Get the filename without any previously added number of copy.
356 // Determine the number of copy, if it has not been specified.
357 if (preg_match($nthCopyRegex, $filenameWithoutExtension, $matches)) {
358 // this is going to be at least the third copy of the filename
359 $filenameWithoutCopy = substr($filenameWithoutExtension, 0, -strlen($matches[0]));
360 if ($nth_copy == null) {
361 $nth_copy = $matches[1] + 1;
362 }
363 } else {
364 if (substr($filenameWithoutExtension, -strlen(' ' . $lng->txt('copy_of_suffix')))
365 == ' ' . $lng->txt('copy_of_suffix')
366 ) {
367 // this is going to be the second copy of the filename
368 $filenameWithoutCopy = substr($filenameWithoutExtension, 0, -strlen(' '
369 . $lng->txt('copy_of_suffix')));
370 if ($nth_copy == null) {
371 $nth_copy = 2;
372 }
373 } else {
374 // this is going to be the first copy of the filename
375 $filenameWithoutCopy = $filenameWithoutExtension;
376 if ($nth_copy == null) {
377 $nth_copy = 1;
378 }
379 }
380 }
381
382 // Construct the new filename
383 if ($nth_copy > 1) {
384 // this is at least the second copy of the filename, append " - Copy ($nth_copy)"
385 $newFilename = $filenameWithoutCopy . sprintf(' '
386 . $lng->txt('copy_n_of_suffix'), $nth_copy)
387 . $extension;
388 } else {
389 // this is the first copy of the filename, append " - Copy"
390 $newFilename = $filenameWithoutCopy . ' ' . $lng->txt('copy_of_suffix') . $extension;
391 }
392
393 return $newFilename;
394 }
static _getFileExtension($a_file_name)
Gets the file extension of the specified file name.
global $DIC
Definition: goto.php:24
$lng

References $DIC, $lng, and _getFileExtension().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _checkGoto()

static ilObjFileAccess::_checkGoto (   $a_target)
static

check whether goto script will succeed

Reimplemented from ilObjectAccess.

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

108 {
109 global $DIC;
110 $ilAccess = $DIC['ilAccess'];
111
112 $t_arr = explode("_", $a_target);
113
114 // personal workspace context: do not force normal login
115 if (isset($t_arr[2]) && $t_arr[2] == "wsp") {
116 include_once "Services/PersonalWorkspace/classes/class.ilSharedResourceGUI.php";
117
118 return ilSharedResourceGUI::hasAccess($t_arr[1]);
119 }
120
121 if ($t_arr[0] != "file" || ((int) $t_arr[1]) <= 0) {
122 return false;
123 }
124
125 if ($ilAccess->checkAccess("visible", "", $t_arr[1])
126 || $ilAccess->checkAccess("read", "", $t_arr[1])
127 ) {
128 return true;
129 }
130
131 return false;
132 }
static hasAccess($a_node_id, $a_is_portfolio=false)

References $DIC, and ilSharedResourceGUI\hasAccess().

+ Here is the call graph for this function:

◆ _getCommands()

static ilObjFileAccess::_getCommands ( )
static

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

82 {
83 $commands = array();
84 $commands[] = array(
85 "permission" => "read",
86 "cmd" => "sendfile",
87 "lang_var" => "download",
88 "default" => true,
89 );
90 $commands[] = array(
91 "permission" => "write",
92 "cmd" => "versions",
93 "lang_var" => "versions",
94 );
95 $commands[] = array(
96 "permission" => "write",
97 "cmd" => "edit",
98 "lang_var" => "settings",
99 );
100
101 return $commands;
102 }

Referenced by ilObjFileListGUI\init().

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

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

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

+ Here is the caller graph for this function:

◆ _getPermanentDownloadLink()

static ilObjFileAccess::_getPermanentDownloadLink (   $ref_id)
static

Gets the permanent download link for the file.

Parameters
int$ref_id
Returns
string

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

402 {
403 return ilLink::_getStaticLink($ref_id, "file", true, "_download");
404 }

References ilLink\_getStaticLink().

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

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

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

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

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

259 {
260 if (self::$_inlineFileExtensionsArray
261 === null
262 ) { // the === makes a huge difference, if the array is empty
263 $settings = new ilSetting('file_access');
264 self::$_inlineFileExtensionsArray = preg_split('/ /', $settings->get('inline_file_extensions'), -1,
265 PREG_SPLIT_NO_EMPTY);
266 }
267 $extension = self::_getFileExtension($a_file_name);
268
269 return in_array($extension, self::$_inlineFileExtensionsArray);
270 }
ILIAS Setting Class.

References _getFileExtension().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _lookupDiskUsage()

static ilObjFileAccess::_lookupDiskUsage (   $a_id)
static

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

245 {
246 include_once('Modules/File/classes/class.ilFSStorageFile.php');
247 $fileStorage = new ilFSStorageFile($a_id);
248 $dir = $fileStorage->getAbsolutePath();
249
250 return ilUtil::dirsize($dir);
251 }
Class ilFSStorageFile.
static dirsize($directory)
get size of a directory or a file.

References ilUtil\dirsize().

+ Here is the call graph for this function:

◆ _lookupFileData()

static ilObjFileAccess::_lookupFileData (   $a_id)
static

looks up the file_data for the file object with the specified object id as an associative array.

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

139 {
140 global $DIC;
141 $ilDB = $DIC['ilDB'];
142
143 $q = "SELECT * FROM file_data WHERE file_id = " . $ilDB->quote($a_id, 'integer');
144 $r = $ilDB->query($q);
145 $row = $r->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
146
147 return $row;
148 }
global $ilDB

References $DIC, $ilDB, and ilDBConstants\FETCHMODE_ASSOC.

Referenced by ilFilePreviewRenderer\supports().

+ Here is the caller graph for this function:

◆ _lookupFileSize() [1/2]

static ilObjFileAccess::_lookupFileSize (   $a_id)
static
Parameters
$a_id
Returns
int
Deprecated:

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

173 {
174 global $DIC;
175 $ilDB = $DIC['ilDB'];
176
177 $q = "SELECT file_size FROM file_data WHERE file_id = " . $ilDB->quote($a_id, 'integer');
178 $r = $ilDB->query($q);
179 $row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
180
181 $size = $row->file_size;
182
183 return $size;
184 }
$size
Definition: RandomTest.php:84

References $DIC, $ilDB, $size, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by ilObjectXMLWriter\__appendObjectProperties(), ilPageObject\addFileSizes(), ilCheckSumOfFileSizesJob\calculateRecursive(), ilCheckSumOfWorkspaceFileSizesJob\calculateRecursive(), and ilObjFileGUI\infoScreenForward().

+ Here is the caller graph for this function:

◆ _lookupFileSize() [2/2]

ilObjFileAccess::_lookupFileSize (   $a_id)

lookup size

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

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(ilDBConstants::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 $version_subdir = "/" . sprintf("%03d", ilObjFileAccess::_lookupVersion($a_id));
58 $file = $fss->getAbsolutePath() . '/' . $version_subdir . '/' . $row->file_name;
59 }
60
61 if (is_file($file)) {
62 $size = filesize($file);
63 } else {
64 $size = 0;
65 }
66
67 return $size;
68 }
static _lookupVersion($a_id)
lookup version

References $ilDB, $size, _lookupVersion(), and ilDBConstants\FETCHMODE_OBJECT.

+ Here is the call 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 192 of file class.ilObjFileAccess.php.

193 {
194 global $DIC;
195 $ilDB = $DIC['ilDB'];
196
197 $q = "SELECT * FROM file_data WHERE file_id = " . $ilDB->quote($a_id, 'integer');
198 $r = $ilDB->query($q);
199 $row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
200
201 require_once('Modules/File/classes/class.ilFSStorageFile.php');
202 $fss = new ilFSStorageFile($a_id);
203 $file = $fss->getAbsolutePath() . '/' . $row->file_name;
204
205 if (@!is_file($file)) {
206 $version_subdir = "/" . sprintf("%03d", ilObjFileAccess::_lookupVersion($a_id));
207 $file = $fss->getAbsolutePath() . '/' . $version_subdir . '/' . $row->file_name;
208 }
209
210 if (is_file($file)) {
211 $size = filesize($file);
212 } else {
213 $size = 0;
214 }
215
216 return $size;
217 }

References $DIC, $ilDB, $size, _lookupVersion(), and ilDBConstants\FETCHMODE_OBJECT.

+ Here is the call graph for this function:

◆ _lookupSuffix()

static ilObjFileAccess::_lookupSuffix (   $a_id)
static

lookup suffix

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

223 {
224 include_once('Modules/File/classes/class.ilFSStorageFile.php');
225
226 global $DIC;
227 $ilDB = $DIC['ilDB'];
228
229 // BEGIN WebDAV: Filename suffix is determined by file title
230 $q = "SELECT * FROM object_data WHERE obj_id = " . $ilDB->quote($a_id, 'integer');
231 $r = $ilDB->query($q);
232 $row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
233 require_once 'Modules/File/classes/class.ilObjFile.php';
234
235 return self::_getFileExtension($row->title);
236 // END WebDAV: Filename suffix is determined by file title
237 }

References $DIC, $ilDB, _getFileExtension(), and ilDBConstants\FETCHMODE_OBJECT.

Referenced by ilObjectXMLWriter\__appendObjectProperties().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _lookupVersion() [1/2]

static ilObjFileAccess::_lookupVersion (   $a_id)
static

lookup version

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

154 {
155 global $DIC;
156 $ilDB = $DIC['ilDB'];
157
158 $q = "SELECT version FROM file_data WHERE file_id = " . $ilDB->quote($a_id, 'integer');
159 $r = $ilDB->query($q);
160 $row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
161
162 $striped = ilUtil::stripSlashes($row->version);
163
164 return $striped > 0 ? $striped : 1;
165 }
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled

References $DIC, $ilDB, ilDBConstants\FETCHMODE_OBJECT, and ilUtil\stripSlashes().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _lookupVersion() [2/2]

ilObjFileAccess::_lookupVersion (   $a_id)

lookup version

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

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(ilDBConstants::FETCHMODE_OBJECT);
37
38 return $row->version;
39 }

References $ilDB, and ilDBConstants\FETCHMODE_OBJECT.

◆ canBeDelivered()

ilObjFileAccess::canBeDelivered ( ilWACPath  $ilWACPath)
Parameters
\ilWACPath$ilWACPath
Returns
bool

Reimplemented from ilObjectAccess.

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

45 {
46 switch ($ilWACPath->getSecurePathId()) {
47 case 'previews':
48 $re = '/\/previews\/[\d\/]{0,}\/preview_([\d]{0,})\//uU';
49 break;
50 }
51 preg_match($re, $ilWACPath->getPath(), $matches);
52
53 return $this->checkAccessToObjectId($matches[1]);
54 }

References ilWACPath\getPath(), and ilWACPath\getSecurePathId().

+ Here is the call graph for this function:

◆ getListGUIData()

static ilObjFileAccess::getListGUIData (   $a_obj_id)
static
Parameters
$a_obj_id
Returns
array

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

464 {
465 if (isset(self::$preload_list_gui_data[$a_obj_id])) {
466 return self::$preload_list_gui_data[$a_obj_id];
467 }
468 }

Referenced by ilObjFileListGUI\getProperties().

+ Here is the caller graph for this function:

◆ isMigrated()

ilObjFileAccess::isMigrated ( )

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

272 :bool
273 {
274
275 }

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

◆ $preload_list_gui_data

ilObjFileAccess::$preload_list_gui_data
staticprotected

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


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