|
1
|
|
|
<?php |
|
2
|
|
|
namespace SKYFILLERS\SfFilecollectionGallery\ViewHelpers; |
|
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
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* ViewHelper to include a css/js file |
|
18
|
|
|
* |
|
19
|
|
|
* # Example: Basic example |
|
20
|
|
|
* <code> |
|
21
|
|
|
* <n:includeFile path="{settings.cssFile}" /> |
|
22
|
|
|
* </code> |
|
23
|
|
|
* <output> |
|
24
|
|
|
* This will include the file provided by {settings} in the header |
|
25
|
|
|
* </output> |
|
26
|
|
|
* |
|
27
|
|
|
* @author Jöran Kurschatke <[email protected]> |
|
28
|
|
|
*/ |
|
29
|
|
|
class IncludeFileViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper { |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Include a CSS/JS file |
|
33
|
|
|
* |
|
34
|
|
|
* @param string $path Path to the CSS/JS file which should be included |
|
35
|
|
|
* @param bool $compress Define if file should be compressed |
|
36
|
|
|
* |
|
37
|
|
|
* @return void |
|
38
|
|
|
*/ |
|
39
|
|
|
public function render($path, $compress = FALSE) { |
|
40
|
|
|
if (TYPO3_MODE === 'FE') { |
|
41
|
|
|
$path = $GLOBALS['TSFE']->tmpl->getFileName($path); |
|
42
|
|
|
|
|
43
|
|
|
// JS |
|
44
|
|
|
if (strtolower(substr($path, -3)) === '.js') { |
|
45
|
|
|
$GLOBALS['TSFE']->getPageRenderer()->addJsFile($path, NULL, $compress); |
|
46
|
|
|
|
|
47
|
|
|
// CSS |
|
48
|
|
|
} elseif (strtolower(substr($path, -4)) === '.css') { |
|
49
|
|
|
$GLOBALS['TSFE']->getPageRenderer()->addCssFile($path, 'stylesheet', 'all', '', $compress); |
|
50
|
|
|
} |
|
51
|
|
|
} else { |
|
52
|
|
|
$doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('template'); |
|
53
|
|
|
$pageRenderer = $doc->getPageRenderer(); |
|
54
|
|
|
|
|
55
|
|
|
// JS |
|
56
|
|
|
if (strtolower(substr($path, -3)) === '.js') { |
|
57
|
|
|
$pageRenderer->addJsFile($path, NULL, $compress); |
|
58
|
|
|
|
|
59
|
|
|
// CSS |
|
60
|
|
|
} elseif (strtolower(substr($path, -4)) === '.css') { |
|
61
|
|
|
$pageRenderer->addCssFile($path, 'stylesheet', 'all', '', $compress); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
} |