ILIAS  release_8 Revision v8.19
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

 canBeDelivered (ilWACPath $ilWACPath)
 
- 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 _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, $a_handle_extension=false)
 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 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,
  $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 209 of file class.ilObjFileAccess.php.

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

Referenced by ilContainerGUI\performPasteIntoMultipleObjectsObject().

209  : string
210  {
211  global $DIC;
212  $lng = $DIC['lng'];
213 
214  $filenameWithoutExtension = $a_file_name;
215 
216  $extension = null;
217  if ($a_handle_extension) {
218  // Get the extension and the filename without the extension
219  $extension = ilObjFileAccess::_getFileExtension($a_file_name);
220  if (strlen($extension) > 0) {
221  $extension = '.' . $extension;
222  $filenameWithoutExtension = substr($a_file_name, 0, -strlen($extension));
223  }
224  }
225 
226  // create a regular expression from the language text copy_n_of_suffix, so that
227  // we can match it against $filenameWithoutExtension, and retrieve the number of the copy.
228  // for example, if copy_n_of_suffix is 'Copy (%1s)', this creates the regular
229  // expression '/ Copy \\([0-9]+)\\)$/'.
230  $nthCopyRegex = preg_replace('/([\^$.\[\]|()?*+{}])/', '\\\\${1}', ' '
231  . $lng->txt('copy_n_of_suffix'));
232  $nthCopyRegex = '/' . preg_replace('/%1\\\\\$s/', '([0-9]+)', $nthCopyRegex) . '$/';
233 
234  // Get the filename without any previously added number of copy.
235  // Determine the number of copy, if it has not been specified.
236  if (preg_match($nthCopyRegex, $filenameWithoutExtension, $matches)) {
237  // this is going to be at least the third copy of the filename
238  $filenameWithoutCopy = substr($filenameWithoutExtension, 0, -strlen($matches[0]));
239  if ($nth_copy == null) {
240  $nth_copy = $matches[1] + 1;
241  }
242  } else {
243  if (substr($filenameWithoutExtension, -strlen(' ' . $lng->txt('copy_of_suffix')))
244  == ' ' . $lng->txt('copy_of_suffix')
245  ) {
246  // this is going to be the second copy of the filename
247  $filenameWithoutCopy = substr($filenameWithoutExtension, 0, -strlen(' '
248  . $lng->txt('copy_of_suffix')));
249  if ($nth_copy == null) {
250  $nth_copy = 2;
251  }
252  } else {
253  // this is going to be the first copy of the filename
254  $filenameWithoutCopy = $filenameWithoutExtension;
255  if ($nth_copy == null) {
256  $nth_copy = 1;
257  }
258  }
259  }
260 
261  // Construct the new filename
262  if ($nth_copy > 1) {
263  // this is at least the second copy of the filename, append " - Copy ($nth_copy)"
264  $newFilename = $filenameWithoutCopy . sprintf(' '
265  . $lng->txt('copy_n_of_suffix'), $nth_copy)
266  . $extension;
267  } else {
268  // this is the first copy of the filename, append " - Copy"
269  $newFilename = $filenameWithoutCopy . ' ' . $lng->txt('copy_of_suffix') . $extension;
270  }
271 
272  return $newFilename;
273  }
$lng
global $DIC
Definition: feed.php:28
static _getFileExtension(string $a_file_name)
Gets the file extension of the specified file name.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _checkGoto()

static ilObjFileAccess::_checkGoto ( string  $a_target)
static

check whether goto script will succeed

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

References $DIC, $ref_id, $type, ilSharedResourceGUI\hasAccess(), and ILIAS\Repository\int().

116  : bool
117  {
118  global $DIC;
119  $access = $DIC['ilAccess'];
120 
121  $target_parts = explode("_", $a_target);
122 
123  // personal workspace context: do not force normal login
124  if (isset($target_parts[2]) && $target_parts[2] === "wsp") {
125  return ilSharedResourceGUI::hasAccess($target_parts[1]);
126  }
127 
128  $type = $target_parts[0]??null;
129  $ref_id = (int) ($target_parts[1] ?? 0);
130  if ($type !== "file" || $ref_id <= 0) {
131  return false;
132  }
133  return $access->checkAccess("visible", "", $ref_id)
134  || $access->checkAccess("read", "", $ref_id);
135  }
$type
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
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 85 of file class.ilObjFileAccess.php.

References ilFileVersionsGUI\CMD_UNZIP_CURRENT_REVISION.

Referenced by ilObjFileListGUI\init().

85  : array
86  {
87  $commands = array();
88  $commands[] = array(
89  "permission" => "read",
90  "cmd" => "sendfile",
91  "lang_var" => "download",
92  "default" => true,
93  );
94  $commands[] = array(
95  "permission" => "write",
97  "lang_var" => "unzip",
98  );
99  $commands[] = array(
100  "permission" => "write",
101  "cmd" => "versions",
102  "lang_var" => "versions",
103  );
104  $commands[] = array(
105  "permission" => "write",
106  "cmd" => "edit",
107  "lang_var" => "settings",
108  );
109 
110  return $commands;
111  }
+ 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 165 of file class.ilObjFileAccess.php.

Referenced by _appendNumberOfCopyToFilename(), and ilFilePreviewRenderer\supports().

165  : string
166  {
167  if (preg_match('/\.([a-z0-9]+)\z/i', $a_file_name, $matches) == 1) {
168  return strtolower($matches[1]);
169  } else {
170  return '';
171  }
172  }
+ Here is the caller graph for this function:

◆ _getPermanentDownloadLink()

static ilObjFileAccess::_getPermanentDownloadLink ( int  $ref_id)
static

Gets the permanent download link for the file.

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

References ilLink\_getStaticLink().

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

278  : string
279  {
280  return ilLink::_getStaticLink($ref_id, "file", true, "_download");
281  }
$ref_id
Definition: ltiauth.php:67
+ 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 182 of file class.ilObjFileAccess.php.

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

182  : bool
183  {
184  return substr($a_file_name, 0, 1) == '.' || substr($a_file_name, -1, 1) == '~'
185  || substr($a_file_name, 0, 2) == '~$'
186  || $a_file_name == 'Thumbs.db';
187  }
+ Here is the caller graph for this function:

◆ _lookupFileSize()

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

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

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

141  : int
142  {
143  try {
144  $info_repo = new ilObjFileInfoRepository();
145  if ($by_reference) {
146  $info = $info_repo->getByRefId($a_id);
147  } else {
148  $info = $info_repo->getByObjectId($a_id);
149  }
150 
151  return (int) $info->getFileSize()->inBytes();
152  } catch (Throwable $t) {
153  return 0;
154  }
155  }
+ Here is the caller graph for this function:

◆ _preloadData()

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

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

287  : void
288  {
289  $info = new ilObjFileInfoRepository();
290  $info->preloadData($obj_ids);
291  }

◆ canBeDelivered()

ilObjFileAccess::canBeDelivered ( ilWACPath  $ilWACPath)

Implements ilWACCheckingClass.

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

References ilWACPath\getPath(), ilWACPath\getSecurePathId(), and ILIAS\Repository\int().

57  : bool
58  {
59  switch ($ilWACPath->getSecurePathId()) {
60  case 'previews':
61  preg_match('/\/previews\/[\d\/]{0,}\/preview_([\d]{0,})\//uU', $ilWACPath->getPath(), $matches);
62  $obj_id = (int) $matches[1];
63  break;
64  default:
65  $obj_id = -1;
66  break;
67  }
68 
69  return $this->checkAccessToObjectId($obj_id);
70  }
+ Here is the call graph for this function:

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: