ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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 30 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 280 of file class.ilObjFileAccess.php.

References $DIC, and $lng.

Referenced by ilContainerGUI\performPasteIntoMultipleObjectsObject().

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

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

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

◆ _checkGoto()

static ilObjFileAccess::_checkGoto ( string  $a_target)
static

check whether goto script will succeed

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

References $DIC, and ilSharedResourceGUI\hasAccess().

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

Referenced by ilObjFileListGUI\init().

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

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

◆ _getPermanentDownloadLink()

static ilObjFileAccess::_getPermanentDownloadLink ( int  $ref_id)
static

Gets the permanent download link for the file.

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

References ilLink\_getStaticLink().

Referenced by ilObjFileGUI\buildInfoScreen().

348  : string
349  {
350  return ilLink::_getStaticLink($ref_id, "file", true, "download");
351  }
$ref_id
Definition: ltiauth.php:66
+ 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 253 of file class.ilObjFileAccess.php.

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

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

◆ _lookupFileSize()

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

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

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

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

◆ _lookupOnline()

static ilObjFileAccess::_lookupOnline ( int  $a_obj_id)
static

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

363  : bool
364  {
365  return ilObjectDIC::dic()['object_properties_agregator']->getFor($a_obj_id, 'file')->getPropertyIsOnline()->getIsOnline();
366  }

◆ _preloadData()

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

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

357  : void
358  {
359  $info = new ilObjFileInfoRepository();
360  $info->preloadData($obj_ids);
361  }

◆ _shouldDownloadDirectly()

static ilObjFileAccess::_shouldDownloadDirectly ( int  $obj_id)
static

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

References $DIC, and ilObjFile\CLICK_MODE_DOWNLOAD.

Referenced by ilObjFileListGUI\getCommandLink().

196  : bool
197  {
198  global $DIC;
199 
200  $result = $DIC->database()->fetchAssoc(
201  $DIC->database()->queryF(
202  "SELECT on_click_mode FROM file_data WHERE file_id = %s;",
203  ['integer'],
204  [$obj_id]
205  )
206  );
207 
208  if (empty($result)) {
209  return false;
210  }
211 
212  return (((int) $result['on_click_mode']) === ilObjFile::CLICK_MODE_DOWNLOAD);
213  }
const CLICK_MODE_DOWNLOAD
global $DIC
Definition: shib_login.php:25
+ 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 37 of file class.ilObjFileAccess.php.

◆ $preload_list_gui_data

array ilObjFileAccess::$preload_list_gui_data = []
staticprotected

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


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