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