[TASK] Replace Space Indent into Tab indent (CGL Cleanup)
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / content / class.tslib_content_fluidtemplate.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Xavier Perseguers <typo3@perseguers.ch>
6 * (c) 2010-2011 Steffen Kamper <steffen@typo3.org>
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
19 *
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28
29 /**
30 * Contains TEMPLATE class object.
31 *
32 * @author Xavier Perseguers <typo3@perseguers.ch>
33 * @author Steffen Kamper <steffen@typo3.org>
34 * @author Bastian Waidelich <bastian@typo3.org>
35 */
36 class tslib_content_FluidTemplate extends tslib_content_Abstract {
37
38 /**
39 * Rendering the cObject, FLUIDTEMPLATE
40 * configuration properties are:
41 * - file string+stdWrap the FLUID template file
42 * - extbase.pluginName, extbase.controllerExtensionName,
43 * - extbase.controllerName, extbase.controllerActionName
44 * - layoutRootPath filepath+stdWrap by default,
45 * - partialRootPath filepath+stdWrap the
46 * - variables array of cObjects, the keys are the variable names in fluid
47 *
48 * an example would be
49 * 10 = FLUIDTEMPLATE
50 * 10.file = fileadmin/templates/mytemplate.html
51 * 10.partialRootPath = fileadmin/templates/partial/
52 * 10.variables {
53 * mylabel = TEXT
54 * mylabel.value = Label from TypoScript coming
55 * }
56 *
57 * @param array array of TypoScript properties
58 * @return string the HTML output
59 * @author Steffen Ritter <info@steffen-ritter.net>
60 * @author Benjamin Mack <benni@typo3.org>
61 * @author Bastian Waidelich <bastian@typo3.org>
62 */
63 public function render($conf = array()) {
64 // check if the needed extensions are installed
65 if (!t3lib_extMgm::isLoaded('fluid')) {
66 return 'You need to install "Fluid" in order to use the FLUIDTEMPLATE content element';
67 }
68
69 /**
70 * 1. initializing Fluid StandaloneView and setting configuration parameters
71 **/
72 $view = t3lib_div::makeInstance('Tx_Fluid_View_StandaloneView');
73 // fetch the Fluid template
74 $file = isset($conf['file.'])
75 ? $this->cObj->stdWrap($conf['file'], $conf['file.'])
76 : $conf['file'];
77 $templatePathAndFilename = $GLOBALS['TSFE']->tmpl->getFileName($file);
78 $view->setTemplatePathAndFilename($templatePathAndFilename);
79
80 // override the default layout path via typoscript
81 $layoutRootPath = isset($conf['layoutRootPath.'])
82 ? $this->cObj->stdWrap($conf['layoutRootPath'], $conf['layoutRootPath.'])
83 : $conf['layoutRootPath'];
84 if($layoutRootPath) {
85 $layoutRootPath = t3lib_div::getFileAbsFileName($layoutRootPath);
86 $view->setLayoutRootPath($layoutRootPath);
87 }
88
89 // override the default partials path via typoscript
90 $partialRootPath = isset($conf['partialRootPath.'])
91 ? $this->cObj->stdWrap($conf['partialRootPath'], $conf['partialRootPath.'])
92 : $conf['partialRootPath'];
93 if($partialRootPath) {
94 $partialRootPath = t3lib_div::getFileAbsFileName($partialRootPath);
95 $view->setPartialRootPath($partialRootPath);
96 }
97
98 // override the default format
99 $format = isset($conf['format.'])
100 ? $this->cObj->stdWrap($conf['format'], $conf['format.'])
101 : $conf['format'];
102 if ($format) {
103 $view->setFormat($format);
104 }
105
106 // set some default variables for initializing Extbase
107 $requestPluginName = isset($conf['extbase.']['pluginName.'])
108 ? $this->cObj->stdWrap($conf['extbase.']['pluginName'], $conf['extbase.']['pluginName.'])
109 : $conf['extbase.']['pluginName'];
110 if($requestPluginName) {
111 $view->getRequest()->setPluginName($requestPluginName);
112 }
113
114 $requestControllerExtensionName = isset($conf['extbase.']['controllerExtensionName.'])
115 ? $this->cObj->stdWrap($conf['extbase.']['controllerExtensionName'], $conf['extbase.']['controllerExtensionName.'])
116 : $conf['extbase.']['controllerExtensionName'];
117 if($requestControllerExtensionName) {
118 $view->getRequest()->setControllerExtensionName($requestControllerExtensionName);
119 }
120
121 $requestControllerName = isset($conf['extbase.']['controllerName.'])
122 ? $this->cObj->stdWrap($conf['extbase.']['controllerName'], $conf['extbase.']['controllerName.'])
123 : $conf['extbase.']['controllerName'];
124 if($requestControllerName) {
125 $view->getRequest()->setControllerName($requestControllerName);
126 }
127
128 $requestControllerActionName = isset($conf['extbase.']['controllerActionName.'])
129 ? $this->cObj->stdWrap($conf['extbase.']['controllerActionName'], $conf['extbase.']['controllerActionName.'])
130 : $conf['extbase.']['controllerActionName'];
131 if($requestControllerActionName) {
132 $view->getRequest()->setControllerActionName($requestControllerActionName);
133 }
134
135 /**
136 * 2. variable assignment
137 */
138 $reservedVariables = array('data', 'current');
139 // accumulate the variables to be replaced
140 // and loop them through cObjGetSingle
141 $variables = (array) $conf['variables.'];
142 foreach ($variables as $variableName => $cObjType) {
143 if (is_array($cObjType)) {
144 continue;
145 }
146 if(!in_array($variableName, $reservedVariables)) {
147 $view->assign($variableName, $this->cObj->cObjGetSingle($cObjType, $variables[$variableName . '.']));
148 } else {
149 throw new InvalidArgumentException('Cannot use reserved name "' . $variableName . '" as variable name in FLUIDTEMPLATE.', 1288095720);
150 }
151 }
152 $view->assign('data', $this->cObj->data);
153 $view->assign('current', $this->cObj->data[$this->cObj->currentValKey]);
154
155 /**
156 * 3. render the content
157 */
158 $theValue = $view->render();
159
160 if(isset($conf['stdWrap.'])) {
161 $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']);
162 }
163
164 return $theValue;
165
166 }
167
168 }
169 ?>