‪TYPO3CMS  11.5
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("' . $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: ' . $highlightColor . '; }
83  .card-login .card-footer { border-color: ' . $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  $logoAlt = trim((string)($this->backendExtensionConfiguration['loginLogoAlt'] ?? ''));
117  if ($logoAlt === '') {
118  trigger_error(
119  'Login logo without alt-text is not accessible and will fall back to "TYPO3 CMS logo" in v12. Configure alt-text in the backend extension.',
120  E_USER_DEPRECATED
121  );
122  }
123 
124  return $logoAlt;
125  }
126 
127  public function ‪getDefaultLogo(): string
128  {
129  // Use TYPO3 logo depending on highlight color
130  $logo = ((string)($this->backendExtensionConfiguration['loginHighlightColor'] ?? '') !== '')
131  ? 'EXT:core/Resources/Public/Images/typo3_black.svg'
132  : 'EXT:core/Resources/Public/Images/typo3_orange.svg';
133 
134  return $this->‪getUriForFileName($logo);
135  }
136 
137  public function ‪getDefaultLogoStyles(): string
138  {
139  return '.typo3-login-logo .typo3-login-image { max-width: 150px; height:100%;}';
140  }
141 
142  public function ‪getSupportingImages(): array
143  {
144  return [
145  'capslock' => $this->‪getUriForFileName('EXT:backend/Resources/Public/Images/icon_capslock.svg'),
146  'typo3' => $this->‪getUriForFileName('EXT:core/Resources/Public/Images/typo3_orange.svg'),
147  ];
148  }
149 
159  protected function ‪getUriForFileName(string $filename): string
160  {
161  // Check if it's already a URL
162  if (preg_match('/^(https?:)?\/\//', $filename)) {
163  return $filename;
164  }
165  $absoluteFilename = GeneralUtility::getFileAbsFileName(ltrim($filename, '/'));
166  $filename = '';
167  if ($absoluteFilename !== '' && @is_file($absoluteFilename)) {
168  $filename = ‪PathUtility::getAbsoluteWebPath($absoluteFilename);
169  }
170  return $filename;
171  }
172 }
‪TYPO3\CMS\Backend\View\AuthenticationStyleInformation\getSupportingImages
‪getSupportingImages()
Definition: AuthenticationStyleInformation.php:142
‪TYPO3\CMS\Backend\View\AuthenticationStyleInformation
Definition: AuthenticationStyleInformation.php:32
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:25
‪TYPO3\CMS\Backend\View\AuthenticationStyleInformation\getDefaultLogoStyles
‪getDefaultLogoStyles()
Definition: AuthenticationStyleInformation.php:137
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration
Definition: ExtensionConfiguration.php:45
‪TYPO3\CMS\Backend\View
Definition: ArrayBrowser.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:82
‪TYPO3\CMS\Backend\View\AuthenticationStyleInformation\getLogo
‪getLogo()
Definition: AuthenticationStyleInformation.php:97
‪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:159
‪TYPO3\CMS\Backend\View\AuthenticationStyleInformation\getDefaultLogo
‪getDefaultLogo()
Definition: AuthenticationStyleInformation.php:127
‪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\PathUtility\getAbsoluteWebPath
‪static string getAbsoluteWebPath($targetPath, bool $prefixWithSitePath=true)
Definition: PathUtility.php:51
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\View\AuthenticationStyleInformation\getFooterNote
‪getFooterNote()
Definition: AuthenticationStyleInformation.php:87