[TASK] Move config.beLoginLinkIPList to compat7
[Packages/TYPO3.CMS.git] / typo3 / sysext / compatibility7 / Classes / Hooks / BackendLoginLinkHook.php
1 <?php
2 namespace TYPO3\CMS\Compatibility7\Hooks;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
19
20 /**
21 * Hook to validate the TypoScript option
22 * config.beLoginLinkIPList, config beLoginLinkIPList_login and config.beLoginLinkIPList_logout
23 */
24 class BackendLoginLinkHook
25 {
26 /**
27 * Echoes a link to the BE login screen with redirect to the front-end
28 * if the option config.beLoginLinkIPList is set.
29 *
30 * @param array $parameters left empty, not in use
31 * @param TypoScriptFrontendController $parentObject
32 */
33 public function renderBackendLoginLink(array $parameters, TypoScriptFrontendController $parentObject)
34 {
35 if (empty($parentObject->config['config']['beLoginLinkIPList'])) {
36 return;
37 }
38 if (!GeneralUtility::cmpIP(GeneralUtility::getIndpEnv('REMOTE_ADDR'), $parentObject->config['config']['beLoginLinkIPList'])) {
39 return;
40 }
41 $label = !$parentObject->isBackendUserLoggedIn() ? $parentObject->config['config']['beLoginLinkIPList_login'] : $parentObject->config['config']['beLoginLinkIPList_logout'];
42 if ($label) {
43 if (!$parentObject->isBackendUserLoggedIn()) {
44 $link = '<a href="' . htmlspecialchars((TYPO3_mainDir . 'index.php?redirect_url=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI')))) . '">' . $label . '</a>';
45 } else {
46 $link = '<a href="' . htmlspecialchars((TYPO3_mainDir . 'index.php?L=OUT&redirect_url=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI')))) . '">' . $label . '</a>';
47 }
48 echo $link;
49 }
50 }
51 }