[BUGFIX] PHP 5.4 E_STRICT warning in HtmlViewHelper
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Format / HtmlViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
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 * Renders a string by passing it to a TYPO3 parseFunc.
18 * You can either specify a path to the TypoScript setting or set the parseFunc options directly.
19 * By default lib.parseFunc_RTE is used to parse the string.
20 *
21 * == Examples ==
22 *
23 * <code title="Default parameters">
24 * <f:format.html>foo <b>bar</b>. Some <LINK 1>link</LINK>.</f:format.html>
25 * </code>
26 * <output>
27 * <p class="bodytext">foo <b>bar</b>. Some <a href="index.php?id=1" >link</a>.</p>
28 * (depending on your TYPO3 setup)
29 * </output>
30 *
31 * <code title="Custom parseFunc">
32 * <f:format.html parseFuncTSPath="lib.parseFunc">foo <b>bar</b>. Some <LINK 1>link</LINK>.</f:format.html>
33 * </code>
34 * <output>
35 * foo <b>bar</b>. Some <a href="index.php?id=1" >link</a>.
36 * </output>
37 *
38 * <code title="Inline notation">
39 * {someText -> f:format.html(parseFuncTSPath: 'lib.parseFunc')}
40 * </code>
41 * <output>
42 * foo <b>bar</b>. Some <a href="index.php?id=1" >link</a>.
43 * </output>
44 *
45 * @see http://typo3.org/documentation/document-library/references/doc_core_tsref/4.2.0/view/1/5/#id4198758
46 */
47 class HtmlViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
48
49 /**
50 * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
51 */
52 protected $contentObject;
53
54 /**
55 * @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController contains a backup of the current $GLOBALS['TSFE'] if used in BE mode
56 */
57 protected $tsfeBackup;
58
59 /**
60 * If the escaping interceptor should be disabled inside this ViewHelper, then set this value to FALSE.
61 * This is internal and NO part of the API. It is very likely to change.
62 *
63 * @var boolean
64 * @internal
65 */
66 protected $escapingInterceptorEnabled = FALSE;
67
68 /**
69 * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
70 */
71 protected $configurationManager;
72
73 /**
74 * @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
75 * @return void
76 */
77 public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager) {
78 $this->configurationManager = $configurationManager;
79 $this->contentObject = $this->configurationManager->getContentObject();
80 }
81
82 /**
83 * @param string $parseFuncTSPath path to TypoScript parseFunc setup.
84 * @return string the parsed string.
85 */
86 public function render($parseFuncTSPath = 'lib.parseFunc_RTE') {
87 if (TYPO3_MODE === 'BE') {
88 $this->simulateFrontendEnvironment();
89 }
90 $value = $this->renderChildren();
91 $content = $this->contentObject->parseFunc($value, array(), '< ' . $parseFuncTSPath);
92 if (TYPO3_MODE === 'BE') {
93 $this->resetFrontendEnvironment();
94 }
95 return $content;
96 }
97
98 /**
99 * Copies the specified parseFunc configuration to $GLOBALS['TSFE']->tmpl->setup in Backend mode
100 * This somewhat hacky work around is currently needed because the parseFunc() function of tslib_cObj relies on those variables to be set
101 *
102 * @return void
103 */
104 protected function simulateFrontendEnvironment() {
105 $this->tsfeBackup = isset($GLOBALS['TSFE']) ? $GLOBALS['TSFE'] : NULL;
106 $GLOBALS['TSFE'] = new \stdClass();
107 $GLOBALS['TSFE']->tmpl = new \stdClass();
108 $GLOBALS['TSFE']->tmpl->setup = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
109 }
110
111 /**
112 * Resets $GLOBALS['TSFE'] if it was previously changed by simulateFrontendEnvironment()
113 *
114 * @return void
115 * @see simulateFrontendEnvironment()
116 */
117 protected function resetFrontendEnvironment() {
118 $GLOBALS['TSFE'] = $this->tsfeBackup;
119 }
120 }
121
122 ?>