ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilObjFileAccess Class Reference

Access class for file objects. More...

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

Public Member Functions

 canBeDelivered (ilWACPath $ilWACPath)
 
 _checkAccess (string $cmd, string $permission, int $ref_id, int $obj_id, ?int $user_id=null)
 checks whether a user may invoke a command or not (this method is called by ilAccessHandler::checkAccess) More...
 
- Public Member Functions inherited from ilObjectAccess
 _checkAccess (string $cmd, string $permission, int $ref_id, int $obj_id, ?int $user_id=null)
 Checks whether a user may invoke a command or not (this method is called by ilAccessHandler::checkAccess) 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 (string $a_target)
 check whether goto script will succeed More...
 
static _shouldDownloadDirectly (int $obj_id)
 
static _lookupFileSize (int $a_id, bool $by_reference=true)
 
static _getFileExtension (string $a_file_name)
 Gets the file extension of the specified file name. More...
 
static _isFileHidden (string $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 (int $ref_id)
 Gets the permanent download link for the file. More...
 
static _preloadData (array $obj_ids, array $ref_ids)
 
static _lookupOnline (int $a_obj_id)
 
- Static Public Member Functions inherited from ilObjectAccess
static _getCommands ()
 get commands More...
 
static _checkGoto (string $target)
 check whether goto script will succeed More...
 
static _isOffline (int $obj_id)
 Type-specific implementation of general status, has to be overwritten if object type does not support centralized offline handling. More...
 
static _preloadData (array $obj_ids, array $ref_ids)
 Preload data. More...
 

Static Protected Attributes

static array $inline_file_extensions = []
 Contains an array of extensions separated by space. More...
 
static array $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 29 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 283 of file class.ilObjFileAccess.php.

References $DIC, $lng, and null.

Referenced by ilContainerGUI\performPasteIntoMultipleObjectsObject().

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

◆ _checkAccess()

ilObjFileAccess::_checkAccess ( string  $cmd,
string  $permission,
int  $ref_id,
int  $obj_id,
?int  $user_id = null 
)

checks whether a user may invoke a command or not (this method is called by ilAccessHandler::checkAccess)

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

References $DIC, $lng, $user_id, ilAccessInfo\IL_NO_OBJECT_ACCESS, and ilAccessInfo\IL_STATUS_MESSAGE.

126  : bool
127  {
128  global $DIC;
129  $ilUser = $DIC['ilUser'];
130  $lng = $DIC['lng'];
131  $rbacsystem = $DIC['rbacsystem'];
132  $ilAccess = $DIC['ilAccess'];
133  if (is_null($user_id)) {
134  $user_id = $ilUser->getId();
135  }
136 
137  switch ($cmd) {
138  case "view":
139  if (!self::_lookupOnline($obj_id)
140  && !$rbacsystem->checkAccessOfUser($user_id, 'write', $ref_id)
141  ) {
142  $ilAccess->addInfoItem(ilAccessInfo::IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
143 
144  return false;
145  }
146  break;
147  // for permission query feature
148  case Capabilities::INFO_PAGE->value:
149  if (!self::_lookupOnline($obj_id)) {
150  $ilAccess->addInfoItem(ilAccessInfo::IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
151  } else {
152  $ilAccess->addInfoItem(ilAccessInfo::IL_STATUS_MESSAGE, $lng->txt("online"));
153  }
154  break;
155  }
156  switch ($permission) {
157  case "read":
158  case "visible":
159  if (!self::_lookupOnline($obj_id)
160  && (!$rbacsystem->checkAccessOfUser($user_id, 'write', $ref_id))
161  ) {
162  $ilAccess->addInfoItem(ilAccessInfo::IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
163 
164  return false;
165  }
166  break;
167  }
168 
169  return true;
170  }
$ref_id
Definition: ltiauth.php:65
global $DIC
Definition: shib_login.php:22
global $lng
Definition: privfeed.php:31

◆ _checkGoto()

static ilObjFileAccess::_checkGoto ( string  $a_target)
static

check whether goto script will succeed

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

References $DIC, and ilSharedResourceGUI\hasAccess().

176  : bool
177  {
178  global $DIC;
179  $ilAccess = $DIC['ilAccess'];
180 
181  $t_arr = explode("_", $a_target);
182 
183  // personal workspace context: do not force normal login
184  if (isset($t_arr[2]) && $t_arr[2] === "wsp") {
185  return ilSharedResourceGUI::hasAccess($t_arr[1]);
186  }
187  if ($t_arr[0] !== "file") {
188  return false;
189  }
190  if (((int) $t_arr[1]) <= 0) {
191  return false;
192  }
193  if ($ilAccess->checkAccess("visible", "", $t_arr[1])) {
194  return true;
195  }
196  return (bool) $ilAccess->checkAccess("read", "", $t_arr[1]);
197  }
global $DIC
Definition: shib_login.php:22
static hasAccess(int $a_node_id, bool $a_is_portfolio=false)
+ 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"), );

Returns
array<int, mixed[]>

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

Referenced by ilObjFileListGUI\init().

74  : array
75  {
76  return [
77  [
78  "permission" => Permissions::READ->value,
79  "cmd" => Capabilities::DOWNLOAD->value,
80  "lang_var" => "download",
81  // "default" => true, // we decide the best matching capability later in ListGUI
82  ],
83  [
84  "permission" => Permissions::VISIBLE->value,
85  "cmd" => Capabilities::INFO_PAGE->value,
86  "lang_var" => "info",
87  ],
88  [
89  "permission" => Permissions::VISIBLE->value,
90  "cmd" => Capabilities::FORCED_INFO_PAGE->value,
91  "lang_var" => "info",
92  ],
93  [
94  "permission" => Permissions::WRITE->value,
95  "cmd" => Capabilities::UNZIP->value,
96  "lang_var" => "unzip",
97  ],
98  [
99  "permission" => Permissions::EDIT_CONTENT->value,
100  "cmd" => Capabilities::EDIT_EXTERNAL->value,
101  "lang_var" => "open_external_editor",
102  ],
103  [
104  "permission" => Permissions::VIEW_CONTENT->value,
105  "cmd" => Capabilities::VIEW_EXTERNAL->value,
106  "lang_var" => "open_external_viewer",
107  ],
108  [
109  "permission" => Permissions::WRITE->value,
110  "cmd" => Capabilities::MANAGE_VERSIONS->value,
111  "lang_var" => "versions",
112  ],
113  [
114  "permission" => Permissions::WRITE->value,
115  "cmd" => Capabilities::EDIT_SETTINGS->value,
116  "lang_var" => "settings"
117  ]
118  ];
119  }
+ Here is the caller graph for this function:

◆ _getFileExtension()

static ilObjFileAccess::_getFileExtension ( string  $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".

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

240  : string
241  {
242  if (preg_match('/\.([a-z0-9]+)\z/i', $a_file_name, $matches) == 1) {
243  return strtolower($matches[1]);
244  }
245  return '';
246  }

◆ _getPermanentDownloadLink()

static ilObjFileAccess::_getPermanentDownloadLink ( int  $ref_id)
static

Gets the permanent download link for the file.

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

References ilLink\_getStaticLink().

Referenced by ilObjFileGUI\buildInfoScreen().

351  : string
352  {
353  return ilLink::_getStaticLink($ref_id, "file", true, "download");
354  }
$ref_id
Definition: ltiauth.php:65
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _isFileHidden()

static ilObjFileAccess::_isFileHidden ( string  $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 256 of file class.ilObjFileAccess.php.

Referenced by ilItemGroupItems\getAssignableItems(), ILIAS\Export\ExportHandler\Manager\Handler\getObjectIdCollectionBuilderFrom(), ilContainer\getSubItems(), ILIAS\UI\Component\Legacy\Content\ItemSetManager\groupItems(), ilObjFile\isHidden(), and ilExportSelectionTableGUI\parseContainer().

256  : bool
257  {
258  return str_starts_with($a_file_name, '.') || str_ends_with($a_file_name, '~')
259  || str_starts_with($a_file_name, '~$')
260  || $a_file_name === 'Thumbs.db';
261  }
+ Here is the caller graph for this function:

◆ _lookupFileSize()

static ilObjFileAccess::_lookupFileSize ( int  $a_id,
bool  $by_reference = true 
)
static
Deprecated:

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

Referenced by ilCheckSumOfWorkspaceFileSizesJob\calculateRecursive(), and ilCheckSumOfFileSizesJob\calculateRecursive().

221  : int
222  {
223  try {
224  $info_repo = new ilObjFileInfoRepository();
225  $info = $by_reference ? $info_repo->getByRefId($a_id) : $info_repo->getByObjectId($a_id);
226 
227  return (int) $info->getFileSize()->inBytes();
228  } catch (Throwable) {
229  return 0;
230  }
231  }
+ Here is the caller graph for this function:

◆ _lookupOnline()

static ilObjFileAccess::_lookupOnline ( int  $a_obj_id)
static

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

366  : bool
367  {
368  $file_obj = new ilObjFile($a_obj_id, false);
369  return $file_obj->getObjectProperties()->getPropertyIsOnline()->getIsOnline();
370  }
Class ilObjFile.

◆ _preloadData()

static ilObjFileAccess::_preloadData ( array  $obj_ids,
array  $ref_ids 
)
static
Parameters
int[]$obj_ids
int[]$ref_ids

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

360  : void
361  {
362  $info = new ilObjFileInfoRepository();
363  $info->preloadData($obj_ids);
364  }

◆ _shouldDownloadDirectly()

static ilObjFileAccess::_shouldDownloadDirectly ( int  $obj_id)
static

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

References $DIC, and ilObjFile\CLICK_MODE_DOWNLOAD.

Referenced by ilObjFileListGUI\getCommandLink().

199  : bool
200  {
201  global $DIC;
202 
203  $result = $DIC->database()->fetchAssoc(
204  $DIC->database()->queryF(
205  "SELECT on_click_mode FROM file_data WHERE file_id = %s;",
206  ['integer'],
207  [$obj_id]
208  )
209  );
210 
211  if (empty($result)) {
212  return false;
213  }
214 
215  return (((int) $result['on_click_mode']) === ilObjFile::CLICK_MODE_DOWNLOAD);
216  }
const CLICK_MODE_DOWNLOAD
global $DIC
Definition: shib_login.php:22
+ Here is the caller graph for this function:

◆ canBeDelivered()

ilObjFileAccess::canBeDelivered ( ilWACPath  $ilWACPath)

Implements ilWACCheckingClass.

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

57  : bool
58  {
59  return false;
60  }

Field Documentation

◆ $inline_file_extensions

array ilObjFileAccess::$inline_file_extensions = []
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.

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

◆ $preload_list_gui_data

array ilObjFileAccess::$preload_list_gui_data = []
staticprotected

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


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