ILIAS  release_8 Revision v8.24
class.ilFileServicesPolicy.php
Go to the documentation of this file.
1<?php
2
23
30{
31 private array $umlaut_mapping = [
32 "Ä" => "Ae",
33 "Ö" => "Oe",
34 "Ü" => "Ue",
35 "ä" => "ae",
36 "ö" => "oe",
37 "ü" => "ue",
38 "é" => "e",
39 "è" => "e",
40 "é" => "e",
41 "ê" => "e",
42 "ß" => "ss"
43 ];
44 protected int $file_admin_ref_id;
45 protected bool $as_ascii = true;
48 protected ?bool $bypass = null;
49
51 {
52 $this->settings = $settings;
53 parent::__construct($this->settings->getBlackListedSuffixes(), $this->settings->getWhiteListedSuffixes());
54 $this->sanitizer = new ilFileServicesFilenameSanitizer($this->settings);
55 $this->as_ascii = $this->settings->isASCIIConvertionEnabled();
56 }
57
58 public function prepareFileNameForConsumer(string $filename_with_extension): string
59 {
60 $filename = $this->sanitizer->sanitize(basename($filename_with_extension));
61 if ($this->as_ascii) {
62 $filename = $this->ascii($filename);
63 }
64 // remove all control characters, see https://mantis.ilias.de/view.php?id=34975
65 $filename = preg_replace('/&#.*;/U', '_', $filename, 1);
66
67 return $filename;
68 }
69
70 public function ascii(string $filename): string
71 {
72 foreach ($this->umlaut_mapping as $src => $tgt) {
73 $filename = str_replace($src, $tgt, $filename);
74 }
75
76 $ascii_filename = htmlentities($filename, ENT_NOQUOTES, 'UTF-8');
77 $ascii_filename = preg_replace('/\&(.)[^;]*;/', '\\1', $ascii_filename);
78 $ascii_filename = preg_replace('/[\x7f-\xff]/', '_', $ascii_filename);
79
80 // OS do not allow the following characters in filenames: \/:*?"<>|
81 $ascii_filename = preg_replace(
82 '/[:\x5c\/\*\?\"<>\|]/',
83 '_',
85 );
86 return $ascii_filename;
87 }
88
89 public function isBlockedExtension(string $extension): bool
90 {
91 if ($this->settings->isByPassAllowedForCurrentUser()) {
92 return false;
93 }
94 return parent::isBlockedExtension($extension);
95 }
96}
$filename
Definition: buildRTE.php:78
Class ilFileServicesFilenameSanitizer.
Class ilFileServicesPolicy.
prepareFileNameForConsumer(string $filename_with_extension)
ilFileServicesFilenameSanitizer $sanitizer
ilFileServicesSettings $settings
isBlockedExtension(string $extension)
__construct(ilFileServicesSettings $settings)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ascii_filename
Definition: metadata.php:378
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc