Merge "[TASK] Increase version number"
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Format / HtmlViewHelper.php
1 <?php
2
3 /* *
4 * This script is part of the TYPO3 project - inspiring people to share! *
5 * *
6 * TYPO3 is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU General Public License version 2 as published by *
8 * the Free Software Foundation. *
9 * *
10 * This script is distributed in the hope that it will be useful, but *
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
12 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
13 * Public License for more details. *
14 * */
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 */
51 class Tx_Fluid_ViewHelpers_Format_HtmlViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
52
53 /**
54 * @var tslib_cObj
55 */
56 protected $contentObject;
57
58 /**
59 * @var t3lib_fe contains a backup of the current $GLOBALS['TSFE'] if used in BE mode
60 */
61 protected $tsfeBackup;
62
63 /**
64 * If the escaping interceptor should be disabled inside this ViewHelper, then set this value to FALSE.
65 * This is internal and NO part of the API. It is very likely to change.
66 *
67 * @var boolean
68 * @internal
69 */
70 protected $escapingInterceptorEnabled = FALSE;
71
72 /**
73 * @var Tx_Extbase_Configuration_ConfigurationManagerInterface
74 */
75 protected $configurationManager;
76
77 /**
78 * @param Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager
79 * @return void
80 */
81 public function injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager) {
82 $this->configurationManager = $configurationManager;
83 $this->contentObject = $this->configurationManager->getContentObject();
84 }
85
86 /**
87 * @param string $parseFuncTSPath path to TypoScript parseFunc setup.
88 * @return the parsed string.
89 */
90 public function render($parseFuncTSPath = 'lib.parseFunc_RTE') {
91 if (TYPO3_MODE === 'BE') {
92 $this->simulateFrontendEnvironment();
93 }
94
95 $value = $this->renderChildren();
96 $content = $this->contentObject->parseFunc($value, array(), '< ' . $parseFuncTSPath);
97
98 if (TYPO3_MODE === 'BE') {
99 $this->resetFrontendEnvironment();
100 }
101 return $content;
102 }
103
104 /**
105 * Copies the specified parseFunc configuration to $GLOBALS['TSFE']->tmpl->setup in Backend mode
106 * This somewhat hacky work around is currently needed because the parseFunc() function of tslib_cObj relies on those variables to be set
107 *
108 * @return void
109 */
110 protected function simulateFrontendEnvironment() {
111 $this->tsfeBackup = isset($GLOBALS['TSFE']) ? $GLOBALS['TSFE'] : NULL;
112 $GLOBALS['TSFE'] = new stdClass();
113 $GLOBALS['TSFE']->tmpl->setup = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
114 }
115
116 /**
117 * Resets $GLOBALS['TSFE'] if it was previously changed by simulateFrontendEnvironment()
118 *
119 * @return void
120 * @see simulateFrontendEnvironment()
121 */
122 protected function resetFrontendEnvironment() {
123 $GLOBALS['TSFE'] = $this->tsfeBackup;
124 }
125 }
126
127 ?>