Revert "[CLEANUP] Rework/simplify copyright header and remove @package"
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Uri / ResourceViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Uri;
3
4 /* *
5 * This script is part of the TYPO3 project - inspiring people to share! *
6 * *
7 * TYPO3 is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU General Public License version 2 as published by *
9 * the Free Software Foundation. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
14 * Public License for more details. *
15 * */
16 /**
17 * A view helper for creating URIs to resources.
18 *
19 * = Examples =
20 *
21 * <code title="Defaults">
22 * <link href="{f:uri.resource(path:'css/stylesheet.css')}" rel="stylesheet" />
23 * </code>
24 * <output>
25 * <link href="Resources/Packages/MyPackage/stylesheet.css" rel="stylesheet" />
26 * (depending on current package)
27 * </output>
28 */
29 class ResourceViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
30
31 /**
32 * Render the URI to the resource. The filename is used from child content.
33 *
34 * @param string $path The path and filename of the resource (relative to Public resource directory of the extension).
35 * @param string $extensionName Target extension name. If not set, the current extension name will be used
36 * @param boolean $absolute If set, an absolute URI is rendered
37 * @return string The URI to the resource
38 * @api
39 */
40 public function render($path, $extensionName = NULL, $absolute = FALSE) {
41 if ($extensionName === NULL) {
42 $extensionName = $this->controllerContext->getRequest()->getControllerExtensionName();
43 }
44 $uri = 'EXT:' . \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName) . '/Resources/Public/' . $path;
45 $uri = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($uri);
46 $uri = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($uri);
47 if (TYPO3_MODE === 'BE' && $absolute === FALSE && $uri !== FALSE) {
48 $uri = '../' . $uri;
49 }
50 if ($absolute === TRUE) {
51 $uri = $this->controllerContext->getRequest()->getBaseURI() . $uri;
52 }
53 return $uri;
54 }
55 }