ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
trait.ilObjFileSecureString.php
Go to the documentation of this file.
1 <?php
2 
20 
26 {
27  use SecureString;
28 
29  protected function extractSuffixFromFilename(string $filename): string
30  {
31  if (!preg_match('/^(.+?)(?<!\s)\.([^.]*$|$)/', $filename, $matches)) {
32  return '';
33  }
34  return $this->secure($matches[2]);
35  }
36 
37  protected function stripSuffix(string $title, ?string $suffix = null): string
38  {
39  $suffix = $suffix ?? $this->extractSuffixFromFilename($title);
40 
41  if ($suffix !== null && ($length = strrpos($title, "." . $suffix)) > 0) {
42  $title = substr($title, 0, $length);
43  }
44 
45  return $this->secure($title);
46  }
47 
48  protected function ensureSuffix(string $title, ?string $suffix = null): string
49  {
50  $title = $this->stripSuffix($title, $suffix);
51  $suffix = $suffix ?? $this->extractSuffixFromFilename($title);
52 
53  if ($suffix !== null && strrpos($title, "." . $suffix) === false) {
54  $title .= "." . $suffix;
55  }
56 
57  return $this->secure(rtrim($title, "."));
58  }
59 
60  protected function ensureSuffixInBrackets(string $title, ?string $suffix = null): string
61  {
62  $title = $this->stripSuffix($title, $suffix);
63  $suffix = $suffix ?? $this->extractSuffixFromFilename($title);
64 
65  if ($suffix !== null && strrpos($title, "." . $suffix) === false) {
66  $title .= " (" . $suffix . ")";
67  }
68 
69  return $this->secure($title);
70  }
71 }
ensureSuffixInBrackets(string $title, ?string $suffix=null)
extractSuffixFromFilename(string $filename)
$filename
Definition: buildRTE.php:78
stripSuffix(string $title, ?string $suffix=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ensureSuffix(string $title, ?string $suffix=null)