1<?php
2
3/*
4 * This file is part of the TYPO3 CMS project.
5 *
6 * It is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License, either version 2
8 * of the License, or any later version.
9 *
10 * For the full copyright and license information, please read the
11 * LICENSE.txt file that was distributed with this source code.
12 *
13 * The TYPO3 project - inspiring people to share!
14 */
15
16namespace TYPO3\CMS\Fluid\ViewHelpers;
17
18use TYPO3\CMS\Core\Http\ApplicationType;
19use TYPO3\CMS\Core\Http\NormalizedParams;
20use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
21use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
22use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
23
24/**
25 * ViewHelper which creates a :html:`<base href="..."></base>` tag.
26 *
27 * The Base URI is taken from the current request.
28 *
29 * Examples
30 * ========
31 *
32 * Example::
33 *
34 *    <f:base />
35 *
36 * Output::
37 *
38 *    <base href="http://yourdomain.tld/" />
39 *
40 * Depending on your domain.
41 *
42 * @deprecated since v11, will be removed in v12.
43 */
44class BaseViewHelper extends AbstractViewHelper
45{
46    use CompileWithRenderStatic;
47
48    /**
49     * As this ViewHelper renders HTML, the output must not be escaped.
50     *
51     * @var bool
52     */
53    protected $escapeOutput = false;
54
55    /**
56     * Render the "Base" tag by outputting site URL
57     *
58     * Note: renders as <base></base>, because IE6 will else refuse to display
59     * the page...
60     *
61     * @param array $arguments
62     * @param \Closure $renderChildrenClosure
63     * @param RenderingContextInterface $renderingContext
64     *
65     * @return string "base"-Tag.
66     */
67    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
68    {
69        trigger_error(__CLASS__ . ' will be removed in TYPO3 v12.', E_USER_DEPRECATED);
70        $request = $renderingContext->getRequest();
71        /** @var NormalizedParams $normalizedParams */
72        $normalizedParams = $request->getAttribute('normalizedParams');
73        $baseUri = $normalizedParams->getSiteUrl();
74        if (ApplicationType::fromRequest($request)->isBackend()) {
75            $baseUri .= TYPO3_mainDir;
76        }
77        return '<base href="' . htmlspecialchars($baseUri) . '" />';
78    }
79}
80