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