‪TYPO3CMS  ‪main
AuthenticationStyleInformation.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Log\LoggerAwareInterface;
21 use Psr\Log\LoggerAwareTrait;
25 
31 class ‪AuthenticationStyleInformation implements LoggerAwareInterface
32 {
33  use LoggerAwareTrait;
34 
36 
37  public function ‪__construct(‪ExtensionConfiguration $extensionConfiguration)
38  {
39  $this->backendExtensionConfiguration = (array)$extensionConfiguration->‪get('backend');
40  }
41 
42  public function ‪getBackgroundImageStyles(): string
43  {
44  $backgroundImage = (string)($this->backendExtensionConfiguration['loginBackgroundImage'] ?? '');
45  if ($backgroundImage === '') {
46  return '';
47  }
48 
49  $backgroundImageUri = $this->‪getUriForFileName($backgroundImage);
50  if ($backgroundImageUri === '') {
51  $this->logger->warning('The configured TYPO3 backend login background image "{image_url}" can\'t be resolved. Please check if the file exists and the extension is activated.', [
52  'image_url' => $backgroundImageUri,
53  ]);
54  return '';
55  }
56 
57  return '
58  .typo3-login-carousel-control.right,
59  .typo3-login-carousel-control.left,
60  .card-login { border: 0; }
61  .typo3-login { background-image: url("' . GeneralUtility::sanitizeCssVariableValue($backgroundImageUri) . '"); }
62  .typo3-login-footnote { background-color: #000000; color: #ffffff; opacity: 0.5; }
63  ';
64  }
65 
66  public function ‪getHighlightColorStyles(): string
67  {
68  $highlightColor = (string)($this->backendExtensionConfiguration['loginHighlightColor'] ?? '');
69  if ($highlightColor === '') {
70  return '';
71  }
72 
73  return '
74  .btn-login.disabled, .btn-login[disabled], fieldset[disabled] .btn-login,
75  .btn-login.disabled:hover, .btn-login[disabled]:hover, fieldset[disabled] .btn-login:hover,
76  .btn-login.disabled:focus, .btn-login[disabled]:focus, fieldset[disabled] .btn-login:focus,
77  .btn-login.disabled.focus, .btn-login[disabled].focus, fieldset[disabled] .btn-login.focus,
78  .btn-login.disabled:active, .btn-login[disabled]:active, fieldset[disabled] .btn-login:active,
79  .btn-login.disabled.active, .btn-login[disabled].active, fieldset[disabled] .btn-login.active,
80  .btn-login:hover, .btn-login:focus, .btn-login:active,
81  .btn-login:active:hover, .btn-login:active:focus,
82  .btn-login { background-color: ' . GeneralUtility::sanitizeCssVariableValue($highlightColor) . '; }
83  .card-login .card-footer { border-color: ' . GeneralUtility::sanitizeCssVariableValue($highlightColor) . '; }
84  ';
85  }
86 
87  public function ‪getFooterNote(): string
88  {
89  $footerNote = (string)($this->backendExtensionConfiguration['loginFootnote'] ?? '');
90  if ($footerNote === '') {
91  return '';
92  }
93 
94  return strip_tags(trim($footerNote));
95  }
96 
97  public function ‪getLogo(): string
98  {
99  $logo = ($this->backendExtensionConfiguration['loginLogo'] ?? '');
100  if ($logo === '') {
101  return '';
102  }
103  $logoUri = $this->‪getUriForFileName($logo);
104  if ($logoUri === '') {
105  $this->logger->warning('The configured TYPO3 backend login logo "{logo_url}" can\'t be resolved. Please check if the file exists and the extension is activated.', [
106  'logo_url' => $logoUri,
107  ]);
108  return '';
109  }
110 
111  return $logoUri;
112  }
113 
114  public function ‪getLogoAlt(): string
115  {
116  return trim((string)($this->backendExtensionConfiguration['loginLogoAlt'] ?? ''));
117  }
118 
119  public function ‪getDefaultLogo(): string
120  {
121  // Use TYPO3 logo depending on highlight color
122  $logo = ((string)($this->backendExtensionConfiguration['loginHighlightColor'] ?? '') !== '')
123  ? 'EXT:core/Resources/Public/Images/typo3_black.svg'
124  : 'EXT:core/Resources/Public/Images/typo3_orange.svg';
125 
126  return $this->‪getUriForFileName($logo);
127  }
128 
129  public function ‪getDefaultLogoStyles(): string
130  {
131  return '.typo3-login-logo .typo3-login-image { max-width: 150px; height:100%;}';
132  }
133 
134  public function ‪getSupportingImages(): array
135  {
136  return [
137  'capslock' => $this->‪getUriForFileName('EXT:backend/Resources/Public/Images/icon_capslock.svg'),
138  'typo3' => $this->‪getUriForFileName('EXT:core/Resources/Public/Images/typo3_orange.svg'),
139  ];
140  }
141 
151  protected function ‪getUriForFileName(string $filename): string
152  {
153  // Check if it's already a URL
154  if (preg_match('/^(https?:)?\/\//', $filename)) {
155  return $filename;
156  }
157  $absoluteFilename = GeneralUtility::getFileAbsFileName(ltrim($filename, '/'));
158  $filename = '';
159  if ($absoluteFilename !== '' && @is_file($absoluteFilename)) {
160  $filename = ‪PathUtility::getAbsoluteWebPath($absoluteFilename);
161  }
162  return $filename;
163  }
164 }
‪TYPO3\CMS\Backend\View\AuthenticationStyleInformation\getSupportingImages
‪getSupportingImages()
Definition: AuthenticationStyleInformation.php:134
‪TYPO3\CMS\Backend\View\AuthenticationStyleInformation
Definition: AuthenticationStyleInformation.php:32
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:27
‪TYPO3\CMS\Backend\View\AuthenticationStyleInformation\getDefaultLogoStyles
‪getDefaultLogoStyles()
Definition: AuthenticationStyleInformation.php:129
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration
Definition: ExtensionConfiguration.php:47
‪TYPO3\CMS\Backend\View
Definition: AuthenticationStyleInformation.php:18
‪TYPO3\CMS\Backend\View\AuthenticationStyleInformation\getHighlightColorStyles
‪getHighlightColorStyles()
Definition: AuthenticationStyleInformation.php:66
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration\get
‪mixed get(string $extension, string $path='')
Definition: ExtensionConfiguration.php:84
‪TYPO3\CMS\Backend\View\AuthenticationStyleInformation\getLogo
‪getLogo()
Definition: AuthenticationStyleInformation.php:97
‪TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath
‪static string getAbsoluteWebPath(string $targetPath, bool $prefixWithSitePath=true)
Definition: PathUtility.php:52
‪TYPO3\CMS\Backend\View\AuthenticationStyleInformation\getLogoAlt
‪getLogoAlt()
Definition: AuthenticationStyleInformation.php:114
‪TYPO3\CMS\Backend\View\AuthenticationStyleInformation\__construct
‪__construct(ExtensionConfiguration $extensionConfiguration)
Definition: AuthenticationStyleInformation.php:37
‪TYPO3\CMS\Backend\View\AuthenticationStyleInformation\getUriForFileName
‪string getUriForFileName(string $filename)
Definition: AuthenticationStyleInformation.php:151
‪TYPO3\CMS\Backend\View\AuthenticationStyleInformation\getDefaultLogo
‪getDefaultLogo()
Definition: AuthenticationStyleInformation.php:119
‪TYPO3\CMS\Backend\View\AuthenticationStyleInformation\getBackgroundImageStyles
‪getBackgroundImageStyles()
Definition: AuthenticationStyleInformation.php:42
‪TYPO3\CMS\Backend\View\AuthenticationStyleInformation\$backendExtensionConfiguration
‪array $backendExtensionConfiguration
Definition: AuthenticationStyleInformation.php:35
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\View\AuthenticationStyleInformation\getFooterNote
‪getFooterNote()
Definition: AuthenticationStyleInformation.php:87