|
TYPO3 API
SVNRelease
|
00001 <?php 00002 00003 /* * 00004 * This script is part of the TYPO3 project - inspiring people to share! * 00005 * * 00006 * TYPO3 is free software; you can redistribute it and/or modify it under * 00007 * the terms of the GNU General Public License version 2 as published by * 00008 * the Free Software Foundation. * 00009 * * 00010 * This script is distributed in the hope that it will be useful, but * 00011 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- * 00012 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 00013 * Public License for more details. * 00014 * */ 00015 00016 /** 00017 */ 00018 00019 /** 00020 * Renders a string by passing it to a TYPO3 parseFunc. 00021 * You can either specify a path to the TypoScript setting or set the parseFunc options directly. 00022 * By default lib.parseFunc_RTE is used to parse the string. 00023 * 00024 * == Examples == 00025 * 00026 * <code title="Default parameters"> 00027 * <f:format.html>foo <b>bar</b>. Some <LINK 1>link</LINK>.</f:format.html> 00028 * </code> 00029 * <output> 00030 * <p class="bodytext">foo <b>bar</b>. Some <a href="index.php?id=1" >link</a>.</p> 00031 * (depending on your TYPO3 setup) 00032 * </output> 00033 * 00034 * <code title="Custom parseFunc"> 00035 * <f:format.html parseFuncTSPath="lib.parseFunc">foo <b>bar</b>. Some <LINK 1>link</LINK>.</f:format.html> 00036 * </code> 00037 * <output> 00038 * foo <b>bar</b>. Some <a href="index.php?id=1" >link</a>. 00039 * </output> 00040 * 00041 * <code title="Inline notation"> 00042 * {someText -> f:format.html(parseFuncTSPath: 'lib.parseFunc')} 00043 * </code> 00044 * <output> 00045 * foo <b>bar</b>. Some <a href="index.php?id=1" >link</a>. 00046 * </output> 00047 * 00048 * @see http://typo3.org/documentation/document-library/references/doc_core_tsref/4.2.0/view/1/5/#id4198758 00049 * 00050 */ 00051 class Tx_Fluid_ViewHelpers_Format_HtmlViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper { 00052 00053 /** 00054 * @var tslib_cObj 00055 */ 00056 protected $contentObject; 00057 00058 /** 00059 * @var t3lib_fe contains a backup of the current $GLOBALS['TSFE'] if used in BE mode 00060 */ 00061 protected $tsfeBackup; 00062 00063 /** 00064 * If the escaping interceptor should be disabled inside this ViewHelper, then set this value to FALSE. 00065 * This is internal and NO part of the API. It is very likely to change. 00066 * 00067 * @var boolean 00068 * @internal 00069 */ 00070 protected $escapingInterceptorEnabled = FALSE; 00071 00072 /** 00073 * @var Tx_Extbase_Configuration_ConfigurationManagerInterface 00074 */ 00075 protected $configurationManager; 00076 00077 /** 00078 * @param Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager 00079 * @return void 00080 */ 00081 public function injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager) { 00082 $this->configurationManager = $configurationManager; 00083 $this->contentObject = $this->configurationManager->getContentObject(); 00084 } 00085 00086 /** 00087 * @param string $parseFuncTSPath path to TypoScript parseFunc setup. 00088 * @return the parsed string. 00089 * @author Bastian Waidelich <bastian@typo3.org> 00090 * @author Niels Pardon <mail@niels-pardon.de> 00091 */ 00092 public function render($parseFuncTSPath = 'lib.parseFunc_RTE') { 00093 if (TYPO3_MODE === 'BE') { 00094 $this->simulateFrontendEnvironment(); 00095 } 00096 00097 $value = $this->renderChildren(); 00098 $content = $this->contentObject->parseFunc($value, array(), '< ' . $parseFuncTSPath); 00099 00100 if (TYPO3_MODE === 'BE') { 00101 $this->resetFrontendEnvironment(); 00102 } 00103 return $content; 00104 } 00105 00106 /** 00107 * Copies the specified parseFunc configuration to $GLOBALS['TSFE']->tmpl->setup in Backend mode 00108 * This somewhat hacky work around is currently needed because the parseFunc() function of tslib_cObj relies on those variables to be set 00109 * 00110 * @return void 00111 * @author Bastian Waidelich <bastian@typo3.org> 00112 */ 00113 protected function simulateFrontendEnvironment() { 00114 $this->tsfeBackup = isset($GLOBALS['TSFE']) ? $GLOBALS['TSFE'] : NULL; 00115 $GLOBALS['TSFE'] = new stdClass(); 00116 $GLOBALS['TSFE']->tmpl->setup = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT); 00117 } 00118 00119 /** 00120 * Resets $GLOBALS['TSFE'] if it was previously changed by simulateFrontendEnvironment() 00121 * 00122 * @return void 00123 * @author Bastian Waidelich <bastian@typo3.org> 00124 * @see simulateFrontendEnvironment() 00125 */ 00126 protected function resetFrontendEnvironment() { 00127 $GLOBALS['TSFE'] = $this->tsfeBackup; 00128 } 00129 } 00130 00131 ?>
1.8.0