|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2010-2011 Xavier Perseguers <typo3@perseguers.ch> 00006 * (c) 2010-2011 Steffen Kamper <steffen@typo3.org> 00007 * All rights reserved 00008 * 00009 * This script is part of the TYPO3 project. The TYPO3 project is 00010 * free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * The GNU General Public License can be found at 00016 * http://www.gnu.org/copyleft/gpl.html. 00017 * A copy is found in the textfile GPL.txt and important notices to the license 00018 * from the author is found in LICENSE.txt distributed with these scripts. 00019 * 00020 * 00021 * This script is distributed in the hope that it will be useful, 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00024 * GNU General Public License for more details. 00025 * 00026 * This copyright notice MUST APPEAR in all copies of the script! 00027 ***************************************************************/ 00028 00029 /** 00030 * Contains TEMPLATE class object. 00031 * 00032 * $Id: class.tslib_content.php 7905 2010-06-13 14:42:33Z ohader $ 00033 * @author Xavier Perseguers <typo3@perseguers.ch> 00034 * @author Steffen Kamper <steffen@typo3.org> 00035 * @author Bastian Waidelich <bastian@typo3.org> 00036 */ 00037 class tslib_content_FluidTemplate extends tslib_content_Abstract { 00038 00039 /** 00040 * Rendering the cObject, FLUIDTEMPLATE 00041 * configuration properties are: 00042 * - file string+stdWrap the FLUID template file 00043 * - extbase.pluginName, extbase.controllerExtensionName, 00044 * - extbase.controllerName, extbase.controllerActionName 00045 * - layoutRootPath filepath+stdWrap by default, 00046 * - partialRootPath filepath+stdWrap the 00047 * - variables array of cObjects, the keys are the variable names in fluid 00048 * 00049 * an example would be 00050 * 10 = FLUIDTEMPLATE 00051 * 10.file = fileadmin/templates/mytemplate.html 00052 * 10.partialRootPath = fileadmin/templates/partial/ 00053 * 10.variables { 00054 * mylabel = TEXT 00055 * mylabel.value = Label from TypoScript coming 00056 * } 00057 * 00058 * @param array array of TypoScript properties 00059 * @return string the HTML output 00060 * @author Steffen Ritter <info@steffen-ritter.net> 00061 * @author Benjamin Mack <benni@typo3.org> 00062 * @author Bastian Waidelich <bastian@typo3.org> 00063 */ 00064 public function render($conf = array()) { 00065 // check if the needed extensions are installed 00066 if (!t3lib_extMgm::isLoaded('fluid')) { 00067 return 'You need to install "Fluid" in order to use the FLUIDTEMPLATE content element'; 00068 } 00069 00070 /** 00071 * 1. initializing Fluid StandaloneView and setting configuration parameters 00072 **/ 00073 $view = t3lib_div::makeInstance('Tx_Fluid_View_StandaloneView'); 00074 // fetch the Fluid template 00075 $file = isset($conf['file.']) 00076 ? $this->cObj->stdWrap($conf['file'], $conf['file.']) 00077 : $conf['file']; 00078 $templatePathAndFilename = $GLOBALS['TSFE']->tmpl->getFileName($file); 00079 $view->setTemplatePathAndFilename($templatePathAndFilename); 00080 00081 // override the default layout path via typoscript 00082 $layoutRootPath = isset($conf['layoutRootPath.']) 00083 ? $this->cObj->stdWrap($conf['layoutRootPath'], $conf['layoutRootPath.']) 00084 : $conf['layoutRootPath']; 00085 if($layoutRootPath) { 00086 $layoutRootPath = t3lib_div::getFileAbsFileName($layoutRootPath); 00087 $view->setLayoutRootPath($layoutRootPath); 00088 } 00089 00090 // override the default partials path via typoscript 00091 $partialRootPath = isset($conf['partialRootPath.']) 00092 ? $this->cObj->stdWrap($conf['partialRootPath'], $conf['partialRootPath.']) 00093 : $conf['partialRootPath']; 00094 if($partialRootPath) { 00095 $partialRootPath = t3lib_div::getFileAbsFileName($partialRootPath); 00096 $view->setPartialRootPath($partialRootPath); 00097 } 00098 00099 // override the default format 00100 $format = isset($conf['format.']) 00101 ? $this->cObj->stdWrap($conf['format'], $conf['format.']) 00102 : $conf['format']; 00103 if ($format) { 00104 $view->setFormat($format); 00105 } 00106 00107 // set some default variables for initializing Extbase 00108 $requestPluginName = isset($conf['extbase.']['pluginName.']) 00109 ? $this->cObj->stdWrap($conf['extbase.']['pluginName'], $conf['extbase.']['pluginName.']) 00110 : $conf['extbase.']['pluginName']; 00111 if($requestPluginName) { 00112 $view->getRequest()->setPluginName($requestPluginName); 00113 } 00114 00115 $requestControllerExtensionName = isset($conf['extbase.']['controllerExtensionName.']) 00116 ? $this->cObj->stdWrap($conf['extbase.']['controllerExtensionName'], $conf['extbase.']['controllerExtensionName.']) 00117 : $conf['extbase.']['controllerExtensionName']; 00118 if($requestControllerExtensionName) { 00119 $view->getRequest()->setControllerExtensionName($requestControllerExtensionName); 00120 } 00121 00122 $requestControllerName = isset($conf['extbase.']['controllerName.']) 00123 ? $this->cObj->stdWrap($conf['extbase.']['controllerName'], $conf['extbase.']['controllerName.']) 00124 : $conf['extbase.']['controllerName']; 00125 if($requestControllerName) { 00126 $view->getRequest()->setControllerName($requestControllerName); 00127 } 00128 00129 $requestControllerActionName = isset($conf['extbase.']['controllerActionName.']) 00130 ? $this->cObj->stdWrap($conf['extbase.']['controllerActionName'], $conf['extbase.']['controllerActionName.']) 00131 : $conf['extbase.']['controllerActionName']; 00132 if($requestControllerActionName) { 00133 $view->getRequest()->setControllerActionName($requestControllerActionName); 00134 } 00135 00136 /** 00137 * 2. variable assignment 00138 */ 00139 $reservedVariables = array('data', 'current'); 00140 // accumulate the variables to be replaced 00141 // and loop them through cObjGetSingle 00142 $variables = (array) $conf['variables.']; 00143 foreach ($variables as $variableName => $cObjType) { 00144 if (is_array($cObjType)) { 00145 continue; 00146 } 00147 if(!in_array($variableName, $reservedVariables)) { 00148 $view->assign($variableName, $this->cObj->cObjGetSingle($cObjType, $variables[$variableName . '.'])); 00149 } else { 00150 throw new InvalidArgumentException('Cannot use reserved name "' . $variableName . '" as variable name in FLUIDTEMPLATE.', 1288095720); 00151 } 00152 } 00153 $view->assign('data', $this->cObj->data); 00154 $view->assign('current', $this->cObj->data[$this->cObj->currentValKey]); 00155 00156 /** 00157 * 3. render the content 00158 */ 00159 $theValue = $view->render(); 00160 00161 if(isset($conf['stdWrap.'])) { 00162 $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']); 00163 } 00164 00165 return $theValue; 00166 00167 } 00168 00169 } 00170 00171 00172 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_fluidtemplate.php'])) { 00173 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_fluidtemplate.php']); 00174 } 00175 00176 ?>
1.8.0