Cleanup: Updated copyright comments
[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 * $Id: class.tslib_content.php 7905 2010-06-13 14:42:33Z ohader $
33 * @author Xavier Perseguers <typo3@perseguers.ch>
34 * @author Steffen Kamper <steffen@typo3.org>
35 * @author Bastian Waidelich <bastian@typo3.org>
36 */
37 class tslib_content_FluidTemplate extends tslib_content_Abstract {
38
39 /**
40 * Rendering the cObject, FLUIDTEMPLATE
41 * configuration properties are:
42 * - file string+stdWrap the FLUID template file
43 * - extbase.pluginName, extbase.controllerExtensionName,
44 * - extbase.controllerName, extbase.controllerActionName
45 * - layoutRootPath filepath+stdWrap by default,
46 * - partialRootPath filepath+stdWrap the
47 * - variables array of cObjects, the keys are the variable names in fluid
48 *
49 * an example would be
50 * 10 = FLUIDTEMPLATE
51 * 10.file = fileadmin/templates/mytemplate.html
52 * 10.partialRootPath = fileadmin/templates/partial/
53 * 10.variables {
54 * mylabel = TEXT
55 * mylabel.value = Label from TypoScript coming
56 * }
57 *
58 * @param array array of TypoScript properties
59 * @return string the HTML output
60 * @author Steffen Ritter <info@steffen-ritter.net>
61 * @author Benjamin Mack <benni@typo3.org>
62 * @author Bastian Waidelich <bastian@typo3.org>
63 */
64 public function render($conf = array()) {
65 // check if the needed extensions are installed
66 if (!t3lib_extMgm::isLoaded('fluid')) {
67 return 'You need to install "Fluid" in order to use the FLUIDTEMPLATE content element';
68 }
69
70 /**
71 * 1. initializing Fluid StandaloneView and setting configuration parameters
72 **/
73 $view = t3lib_div::makeInstance('Tx_Fluid_View_StandaloneView');
74 // fetch the Fluid template
75 $file = isset($conf['file.'])
76 ? $this->cObj->stdWrap($conf['file'], $conf['file.'])
77 : $conf['file'];
78 $templatePathAndFilename = $GLOBALS['TSFE']->tmpl->getFileName($file);
79 $view->setTemplatePathAndFilename($templatePathAndFilename);
80
81 // override the default layout path via typoscript
82 $layoutRootPath = isset($conf['layoutRootPath.'])
83 ? $this->cObj->stdWrap($conf['layoutRootPath'], $conf['layoutRootPath.'])
84 : $conf['layoutRootPath'];
85 if($layoutRootPath) {
86 $layoutRootPath = t3lib_div::getFileAbsFileName($layoutRootPath);
87 $view->setLayoutRootPath($layoutRootPath);
88 }
89
90 // override the default partials path via typoscript
91 $partialRootPath = isset($conf['partialRootPath.'])
92 ? $this->cObj->stdWrap($conf['partialRootPath'], $conf['partialRootPath.'])
93 : $conf['partialRootPath'];
94 if($partialRootPath) {
95 $partialRootPath = t3lib_div::getFileAbsFileName($partialRootPath);
96 $view->setPartialRootPath($partialRootPath);
97 }
98
99 // override the default format
100 $format = isset($conf['format.'])
101 ? $this->cObj->stdWrap($conf['format'], $conf['format.'])
102 : $conf['format'];
103 if ($format) {
104 $view->setFormat($format);
105 }
106
107 // set some default variables for initializing Extbase
108 $requestPluginName = isset($conf['extbase.']['pluginName.'])
109 ? $this->cObj->stdWrap($conf['extbase.']['pluginName'], $conf['extbase.']['pluginName.'])
110 : $conf['extbase.']['pluginName'];
111 if($requestPluginName) {
112 $view->getRequest()->setPluginName($requestPluginName);
113 }
114
115 $requestControllerExtensionName = isset($conf['extbase.']['controllerExtensionName.'])
116 ? $this->cObj->stdWrap($conf['extbase.']['controllerExtensionName'], $conf['extbase.']['controllerExtensionName.'])
117 : $conf['extbase.']['controllerExtensionName'];
118 if($requestControllerExtensionName) {
119 $view->getRequest()->setControllerExtensionName($requestControllerExtensionName);
120 }
121
122 $requestControllerName = isset($conf['extbase.']['controllerName.'])
123 ? $this->cObj->stdWrap($conf['extbase.']['controllerName'], $conf['extbase.']['controllerName.'])
124 : $conf['extbase.']['controllerName'];
125 if($requestControllerName) {
126 $view->getRequest()->setControllerName($requestControllerName);
127 }
128
129 $requestControllerActionName = isset($conf['extbase.']['controllerActionName.'])
130 ? $this->cObj->stdWrap($conf['extbase.']['controllerActionName'], $conf['extbase.']['controllerActionName.'])
131 : $conf['extbase.']['controllerActionName'];
132 if($requestControllerActionName) {
133 $view->getRequest()->setControllerActionName($requestControllerActionName);
134 }
135
136 /**
137 * 2. variable assignment
138 */
139 $reservedVariables = array('data', 'current');
140 // accumulate the variables to be replaced
141 // and loop them through cObjGetSingle
142 $variables = (array) $conf['variables.'];
143 foreach ($variables as $variableName => $cObjType) {
144 if (is_array($cObjType)) {
145 continue;
146 }
147 if(!in_array($variableName, $reservedVariables)) {
148 $view->assign($variableName, $this->cObj->cObjGetSingle($cObjType, $variables[$variableName . '.']));
149 } else {
150 throw new InvalidArgumentException('Cannot use reserved name "' . $variableName . '" as variable name in FLUIDTEMPLATE.', 1288095720);
151 }
152 }
153 $view->assign('data', $this->cObj->data);
154 $view->assign('current', $this->cObj->data[$this->cObj->currentValKey]);
155
156 /**
157 * 3. render the content
158 */
159 $theValue = $view->render();
160
161 if(isset($conf['stdWrap.'])) {
162 $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']);
163 }
164
165 return $theValue;
166
167 }
168
169 }
170
171
172 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_fluidtemplate.php'])) {
173 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_fluidtemplate.php']);
174 }
175
176 ?>