[TASK][WIP] Move non class code back to source files
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Format / HtmlViewHelper.php
1 <?php
2 /* *
3 * This script is part of the TYPO3 project - inspiring people to share! *
4 * *
5 * TYPO3 is free software; you can redistribute it and/or modify it under *
6 * the terms of the GNU General Public License version 2 as published by *
7 * the Free Software Foundation. *
8 * *
9 * This script is distributed in the hope that it will be useful, but *
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
11 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
12 * Public License for more details. *
13 * */
14 /**
15
16 */
17 /**
18 * Renders a string by passing it to a TYPO3 parseFunc.
19 * You can either specify a path to the TypoScript setting or set the parseFunc options directly.
20 * By default lib.parseFunc_RTE is used to parse the string.
21 *
22 * == Examples ==
23 *
24 * <code title="Default parameters">
25 * <f:format.html>foo <b>bar</b>. Some <LINK 1>link</LINK>.</f:format.html>
26 * </code>
27 * <output>
28 * <p class="bodytext">foo <b>bar</b>. Some <a href="index.php?id=1" >link</a>.</p>
29 * (depending on your TYPO3 setup)
30 * </output>
31 *
32 * <code title="Custom parseFunc">
33 * <f:format.html parseFuncTSPath="lib.parseFunc">foo <b>bar</b>. Some <LINK 1>link</LINK>.</f:format.html>
34 * </code>
35 * <output>
36 * foo <b>bar</b>. Some <a href="index.php?id=1" >link</a>.
37 * </output>
38 *
39 * <code title="Inline notation">
40 * {someText -> f:format.html(parseFuncTSPath: 'lib.parseFunc')}
41 * </code>
42 * <output>
43 * foo <b>bar</b>. Some <a href="index.php?id=1" >link</a>.
44 * </output>
45 *
46 * @see http://typo3.org/documentation/document-library/references/doc_core_tsref/4.2.0/view/1/5/#id4198758
47 */
48 class Tx_Fluid_ViewHelpers_Format_HtmlViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
49
50 /**
51 * @var tslib_cObj
52 */
53 protected $contentObject;
54
55 /**
56 * @var t3lib_fe contains a backup of the current $GLOBALS['TSFE'] if used in BE mode
57 */
58 protected $tsfeBackup;
59
60 /**
61 * If the escaping interceptor should be disabled inside this ViewHelper, then set this value to FALSE.
62 * This is internal and NO part of the API. It is very likely to change.
63 *
64 * @var boolean
65 * @internal
66 */
67 protected $escapingInterceptorEnabled = FALSE;
68
69 /**
70 * @var Tx_Extbase_Configuration_ConfigurationManagerInterface
71 */
72 protected $configurationManager;
73
74 /**
75 * @param Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager
76 * @return void
77 */
78 public function injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager) {
79 $this->configurationManager = $configurationManager;
80 $this->contentObject = $this->configurationManager->getContentObject();
81 }
82
83 /**
84 * @param string $parseFuncTSPath path to TypoScript parseFunc setup.
85 * @return the parsed string.
86 */
87 public function render($parseFuncTSPath = 'lib.parseFunc_RTE') {
88 if (TYPO3_MODE === 'BE') {
89 $this->simulateFrontendEnvironment();
90 }
91 $value = $this->renderChildren();
92 $content = $this->contentObject->parseFunc($value, array(), '< ' . $parseFuncTSPath);
93 if (TYPO3_MODE === 'BE') {
94 $this->resetFrontendEnvironment();
95 }
96 return $content;
97 }
98
99 /**
100 * Copies the specified parseFunc configuration to $GLOBALS['TSFE']->tmpl->setup in Backend mode
101 * This somewhat hacky work around is currently needed because the parseFunc() function of tslib_cObj relies on those variables to be set
102 *
103 * @return void
104 */
105 protected function simulateFrontendEnvironment() {
106 $this->tsfeBackup = isset($GLOBALS['TSFE']) ? $GLOBALS['TSFE'] : NULL;
107 $GLOBALS['TSFE'] = new stdClass();
108 $GLOBALS['TSFE']->tmpl->setup = $this->configurationManager->getConfiguration(Tx_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
123 ?>