ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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 284 of file class.ilObjFileAccess.php.

References $DIC, $lng, and null.

Referenced by ilContainerGUI\performPasteIntoMultipleObjectsObject().

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

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

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

◆ _checkGoto()

static ilObjFileAccess::_checkGoto ( string  $a_target)
static

check whether goto script will succeed

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

References $DIC, and ilSharedResourceGUI\hasAccess().

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

Referenced by ilObjFileListGUI\init().

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

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

◆ _getPermanentDownloadLink()

static ilObjFileAccess::_getPermanentDownloadLink ( int  $ref_id)
static

Gets the permanent download link for the file.

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

References ilLink\_getStaticLink().

Referenced by ilObjFileGUI\buildInfoScreen().

352  : string
353  {
354  return ilLink::_getStaticLink($ref_id, "file", true, "download");
355  }
$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 257 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().

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

◆ _lookupFileSize()

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

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

References $info.

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

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

◆ _lookupOnline()

static ilObjFileAccess::_lookupOnline ( int  $a_obj_id)
static

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

367  : bool
368  {
369  // TODO: remove this call to LocalDIC, since this is an internal class, see https://mantis.ilias.de/view.php?id=45558
370  return LocalDIC::dic()['properties.aggregator']->getFor($a_obj_id, 'file')->getPropertyIsOnline()->getIsOnline();
371  }

◆ _preloadData()

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

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

References $info.

361  : void
362  {
364  $info->preloadData($obj_ids);
365  }
$info
Definition: entry_point.php:21

◆ _shouldDownloadDirectly()

static ilObjFileAccess::_shouldDownloadDirectly ( int  $obj_id)
static

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

References $DIC, and ilObjFile\CLICK_MODE_DOWNLOAD.

Referenced by ilObjFileListGUI\getCommandLink().

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

◆ canBeDelivered()

ilObjFileAccess::canBeDelivered ( ilWACPath  $ilWACPath)

Implements ilWACCheckingClass.

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

58  : bool
59  {
60  return false;
61  }

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: