[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 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 /**
18 * A view helper for creating URIs to resources.
19 *
20 * = Examples =
21 *
22 * <code title="Defaults">
23 * <link href="{f:uri.resource(path:'css/stylesheet.css')}" rel="stylesheet" />
24 * </code>
25 * <output>
26 * <link href="Resources/Packages/MyPackage/stylesheet.css" rel="stylesheet" />
27 * (depending on current package)
28 * </output>
29 */
30 class ResourceViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
31
32 /**
33 * Render the URI to the resource. The filename is used from child content.
34 *
35 * @param string $path The path and filename of the resource (relative to Public resource directory of the extension).
36 * @param string $extensionName Target extension name. If not set, the current extension name will be used
37 * @param boolean $absolute If set, an absolute URI is rendered
38 * @return string The URI to the resource
39 * @api
40 */
41 public function render($path, $extensionName = NULL, $absolute = FALSE) {
42 if ($extensionName === NULL) {
43 $extensionName = $this->controllerContext->getRequest()->getControllerExtensionName();
44 }
45 $uri = 'EXT:' . \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName) . '/Resources/Public/' . $path;
46 $uri = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($uri);
47 $uri = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($uri);
48 if (TYPO3_MODE === 'BE' && $absolute === FALSE && $uri !== FALSE) {
49 $uri = '../' . $uri;
50 }
51 if ($absolute === TRUE) {
52 $uri = $this->controllerContext->getRequest()->getBaseURI() . $uri;
53 }
54 return $uri;
55 }
56 }