TYPO3 CMS  TYPO3_6-2
TypoScriptTemplateInformationModuleFunctionController.php
Go to the documentation of this file.
1 <?php
3 
19 
26 
32  public $tce_processed = FALSE;
33 
43  public function tableRow($label, $data, $field) {
44  $ret = '<tr><td>';
45  $urlParameters = array(
46  'id' => $this->pObj->id
47  );
48  $aHref = BackendUtility::getModuleUrl('web_ts', $urlParameters);
49  $ret .= '<a href="' . htmlspecialchars(($aHref . '&e[' . $field . ']=1')) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-open', array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:editField', TRUE))) . '<strong>' . $label . '</strong></a>';
50  $ret .= '</td><td width="80%" class="bgColor4">' . $data . '&nbsp;</td></tr>';
51  return $ret;
52  }
53 
62  public function procesResources($resources, $func = FALSE) {
63  $arr = GeneralUtility::trimExplode(',', $resources . ',,', TRUE);
64  $out = '';
65  $bgcol = $func ? ' class="bgColor4"' : '';
66  foreach ($arr as $k => $v) {
67  $path = PATH_site . $GLOBALS['TCA']['sys_template']['columns']['resources']['config']['uploadfolder'] . '/' . $v;
68  $functions = '';
69  if ($func) {
70  $functions = '<td bgcolor="red" nowrap="nowrap">' . $GLOBALS['LANG']->getLL('delete') . ' <input type="checkbox" name="data[remove_resource][' . $k . ']" value="' . htmlspecialchars($v) . '" /></td>';
71  $functions .= '<td' . $bgcol . ' nowrap="nowrap">' . $GLOBALS['LANG']->getLL('toTop') . ' <input type="checkbox" name="data[totop_resource][' . $k . ']" value="' . htmlspecialchars($v) . '" /></td>';
72  $functions .= '<td' . $bgcol . ' nowrap="nowrap">';
74  if (GeneralUtility::inList($this->pObj->textExtensions, $fI['fileext'])) {
75  $urlParameters = array(
76  'id' => $this->pObj->id
77  );
78  $aHref = BackendUtility::getModuleUrl('web_ts', $urlParameters);
79  $functions .= '<a href="' . htmlspecialchars(($aHref . '&e[file]=' . rawurlencode($v))) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-open', array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:editFile', TRUE))) . '</a>';
80  }
81  $functions .= '</td>';
82  }
83  $thumb = BackendUtility::thumbCode(array('resources' => $v), 'sys_template', 'resources', $GLOBALS['BACK_PATH'], '');
84  $out .= '<tr><td' . $bgcol . ' nowrap="nowrap">' . $v . '&nbsp;&nbsp;</td><td' . $bgcol . ' nowrap="nowrap">&nbsp;' . GeneralUtility::formatSize(@filesize($path)) . '&nbsp;</td>' . $functions . '<td' . $bgcol . '>' . trim($thumb) . '</td></tr>';
85  }
86  if ($out) {
87  if ($func) {
88  $out = '<table border="0" cellpadding="1" cellspacing="1" width="100%">' . $out . '</table>';
89  $out = '<table border="0" cellpadding="0" cellspacing="0">
90  <tr><td class="bgColor2">' . $out . '<img src="clear.gif" width="465px" height="1px"></td></tr>
91  </table>';
92  } else {
93  $out = '<table border="0" cellpadding="0" cellspacing="0">' . $out . '</table>';
94  }
95  }
96  return $out;
97  }
98 
107  public function resourceListForCopy($id, $template_uid) {
108  global $tmpl;
109  $sys_page = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
110  $rootLine = $sys_page->getRootLine($id);
111  // This generates the constants/config + hierarchy info for the template.
112  $tmpl->runThroughTemplates($rootLine, $template_uid);
113  $theResources = GeneralUtility::trimExplode(',', $tmpl->resources, TRUE);
114  foreach ($theResources as $k => $v) {
115  $fI = pathinfo($v);
116  if (GeneralUtility::inList($this->pObj->textExtensions, strtolower($fI['extension']))) {
117  $path = PATH_site . $GLOBALS['TCA']['sys_template']['columns']['resources']['config']['uploadfolder'] . '/' . $v;
118  $thumb = BackendUtility::thumbCode(array('resources' => $v), 'sys_template', 'resources', $GLOBALS['BACK_PATH'], '');
119  $out .= '<tr><td' . $bgcol . ' nowrap="nowrap">' . $v . '&nbsp;&nbsp;</td><td' . $bgcol . ' nowrap="nowrap">&nbsp;' . GeneralUtility::formatSize(@filesize($path)) . '&nbsp;</td><td' . $bgcol . '>' . trim($thumb) . '</td><td><input type="Checkbox" name="data[makecopy_resource][' . $k . ']" value="' . htmlspecialchars($v) . '"></td></tr>';
120  }
121  }
122  $out = $out ? '<table border="0" cellpadding="0" cellspacing="0">' . $out . '</table>' : '';
123  return $out;
124  }
125 
136  public function initialize_editor($pageId, $template_uid = 0) {
137  // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
138  global $tmpl, $tplRow, $theConstants;
139  // Defined global here!
140  $tmpl = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\ExtendedTemplateService');
141  // Do not log time-performance information
142  $tmpl->tt_track = 0;
143  $tmpl->init();
144  // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
145  $tplRow = $tmpl->ext_getFirstTemplate($pageId, $template_uid);
146  if (is_array($tplRow)) {
147  $tplRow = $this->processTemplateRowAfterLoading($tplRow);
148  return TRUE;
149  }
150  return FALSE;
151  }
152 
161  public function processTemplateRowAfterLoading(array $tplRow) {
162  if ($this->pObj->MOD_SETTINGS['includeTypoScriptFileContent']) {
163  // Let the recursion detection counter start at 91, so that only 10 recursive calls will be resolved
164  // Otherwise the editor will be bloated with way to many lines making it hard the break the cyclic recursion.
165  $tplRow['config'] = \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines($tplRow['config'], 91);
166  $tplRow['constants'] = \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines($tplRow['constants'], 91);
167  }
168  return $tplRow;
169  }
170 
179  public function processTemplateRowBeforeSaving(array $tplRow) {
180  if ($this->pObj->MOD_SETTINGS['includeTypoScriptFileContent']) {
182  }
183  return $tplRow;
184  }
185 
192  public function main() {
193  global $BACK_PATH;
194  global $tmpl, $tplRow, $theConstants;
195  $GLOBALS['LANG']->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_info.xlf');
196  $this->pObj->MOD_MENU['includeTypoScriptFileContent'] = TRUE;
197  $edit = $this->pObj->edit;
198  $e = $this->pObj->e;
199  // Checking for more than one template an if, set a menu...
200  $manyTemplatesMenu = $this->pObj->templateMenu();
201  $template_uid = 0;
202  if ($manyTemplatesMenu) {
203  $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
204  }
205  // Initialize
206  $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
207  if ($existTemplate) {
208  $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
209  }
210  // Create extension template
211  $newId = $this->pObj->createTemplate($this->pObj->id, $saveId);
212  if ($newId) {
213  // Switch to new template
214  $urlParameters = array(
215  'id' => $this->pObj->id,
216  'SET[templatesOnPage]' => $newId
217  );
218  $aHref = BackendUtility::getModuleUrl('web_ts', $urlParameters);
220  }
221  if ($existTemplate) {
222  // Update template ?
223  $POST = GeneralUtility::_POST();
224  if ($POST['submit'] || \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($POST['submit_x']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($POST['submit_y']) || $POST['saveclose'] || \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($POST['saveclose_x']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($POST['saveclose_y'])) {
225  // Set the data to be saved
226  $recData = array();
227  $alternativeFileName = array();
228  $tmp_upload_name = '';
229  // Set this to blank
230  $tmp_newresource_name = '';
231  if (is_array($POST['data'])) {
232  foreach ($POST['data'] as $field => $val) {
233  switch ($field) {
234  case 'constants':
235 
236  case 'config':
237 
238  case 'title':
239 
240  case 'sitetitle':
241 
242  case 'description':
243  $recData['sys_template'][$saveId][$field] = $val;
244  break;
245  }
246  }
247  }
248  if (count($recData)) {
249  $recData['sys_template'][$saveId] = $this->processTemplateRowBeforeSaving($recData['sys_template'][$saveId]);
250  // Create new tce-object
251  $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
252  $tce->stripslashes_values = 0;
253  $tce->alternativeFileName = $alternativeFileName;
254  // Initialize
255  $tce->start($recData, array());
256  // Saved the stuff
257  $tce->process_datamap();
258  // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
259  $tce->clear_cacheCmd('all');
260  // tce were processed successfully
261  $this->tce_processed = TRUE;
262  // re-read the template ...
263  $this->initialize_editor($this->pObj->id, $template_uid);
264  // reload template menu
265  $manyTemplatesMenu = $this->pObj->templateMenu();
266  }
267  // If files has been edited:
268  if (is_array($edit)) {
269  if ($edit['filename'] && $tplRow['resources'] && GeneralUtility::inList($tplRow['resources'], $edit['filename'])) {
270  // Check if there are resources, and that the file is in the resourcelist.
271  $path = PATH_site . $GLOBALS['TCA']['sys_template']['columns']['resources']['config']['uploadfolder'] . '/' . $edit['filename'];
272  $fI = GeneralUtility::split_fileref($edit['filename']);
273  if (@is_file($path) && GeneralUtility::getFileAbsFileName($path) && GeneralUtility::inList($this->pObj->textExtensions, $fI['fileext'])) {
274  // checks that have already been done.. Just to make sure
275  // @TODO: Check if the hardcorded value already has a config member, otherwise create one
276  // Checks that have already been done.. Just to make sure
277  if (filesize($path) < 30720) {
278  GeneralUtility::writeFile($path, $edit['file']);
279  $theOutput .= $this->pObj->doc->spacer(10);
280  $theOutput .= $this->pObj->doc->section('<font color=red>' . $GLOBALS['LANG']->getLL('fileChanged') . '</font>', sprintf($GLOBALS['LANG']->getLL('resourceUpdated'), $edit['filename']), 0, 0, 0, 1);
281  // Clear cache - the file has probably affected the template setup
282  // @TODO: Check if the edited file really had something to do with cached data and prevent this clearing if possible!
284  $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
285  $tce->stripslashes_values = 0;
286  $tce->start(array(), array());
287  $tce->clear_cacheCmd('all');
288  }
289  }
290  }
291  }
292  }
293  // Hook post updating template/TCE processing
294  if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postTCEProcessingHook'])) {
295  $postTCEProcessingHook = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postTCEProcessingHook'];
296  if (is_array($postTCEProcessingHook)) {
297  $hookParameters = array(
298  'POST' => $POST,
299  'tce' => $tce
300  );
301  foreach ($postTCEProcessingHook as $hookFunction) {
302  GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
303  }
304  }
305  }
306  $content = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('sys_template', $tplRow, array('oncontextmenu' => "this.click();return false;", 'onclick' => "Clickmenu.show('sys_template', '" . $tplRow['uid'] . "', '1', '','', ''); return false;")) . '<strong>' . htmlspecialchars($tplRow['title']) . '</strong>' . htmlspecialchars((trim($tplRow['sitetitle']) ? ' (' . $tplRow['sitetitle'] . ')' : ''));
307  $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('templateInformation'), $content, 0, 1);
308  if ($manyTemplatesMenu) {
309  $theOutput .= $this->pObj->doc->section('', $manyTemplatesMenu);
310  }
311  $theOutput .= $this->pObj->doc->spacer(10);
312  $numberOfRows = 35;
313  // If abort pressed, nothing should be edited:
314  if ($POST['abort'] || \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($POST['abort_x']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($POST['abort_y']) || $POST['saveclose'] || \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($POST['saveclose_x']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($POST['saveclose_y'])) {
315  unset($e);
316  }
317  if ($e['title']) {
318  $outCode = '<input type="Text" name="data[title]" value="' . htmlspecialchars($tplRow['title']) . '"' . $this->pObj->doc->formWidth() . '>';
319  $outCode .= '<input type="Hidden" name="e[title]" value="1">';
320  $theOutput .= $this->pObj->doc->spacer(15);
321  $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('title'), $outCode, TRUE);
322  }
323  if ($e['sitetitle']) {
324  $outCode = '<input type="Text" name="data[sitetitle]" value="' . htmlspecialchars($tplRow['sitetitle']) . '"' . $this->pObj->doc->formWidth() . '>';
325  $outCode .= '<input type="Hidden" name="e[sitetitle]" value="1">';
326  $theOutput .= $this->pObj->doc->spacer(15);
327  $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('sitetitle'), $outCode, TRUE);
328  }
329  if ($e['description']) {
330  $outCode = '<textarea name="data[description]" rows="5" class="fixed-font enable-tab"' . $this->pObj->doc->formWidth(48) . '>' . GeneralUtility::formatForTextarea($tplRow['description']) . '</textarea>';
331  $outCode .= '<input type="Hidden" name="e[description]" value="1">';
332  $theOutput .= $this->pObj->doc->spacer(15);
333  $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('description'), $outCode, TRUE);
334  }
335  if ($e['constants']) {
336  $outCode = '<textarea name="data[constants]" rows="' . $numberOfRows . '" wrap="off" class="fixed-font enable-tab"' . $this->pObj->doc->formWidth(48, TRUE, 'width:98%;height:70%') . ' class="fixed-font">' . GeneralUtility::formatForTextarea($tplRow['constants']) . '</textarea>';
337  $outCode .= '<input type="Hidden" name="e[constants]" value="1">';
338  // Display "Include TypoScript file content?" checkbox
339  $outCode .= BackendUtility::getFuncCheck($this->pObj->id, 'SET[includeTypoScriptFileContent]', $this->pObj->MOD_SETTINGS['includeTypoScriptFileContent'], '', '&e[constants]=1', 'id="checkIncludeTypoScriptFileContent"');
340  $outCode .= '<label for="checkIncludeTypoScriptFileContent">' . $GLOBALS['LANG']->getLL('includeTypoScriptFileContent') . '</label><br />';
341  $theOutput .= $this->pObj->doc->spacer(15);
342  $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('constants'), '', TRUE);
343  $theOutput .= $this->pObj->doc->sectionEnd() . $outCode;
344  }
345  if ($e['file']) {
346  $path = PATH_site . $GLOBALS['TCA']['sys_template']['columns']['resources']['config']['uploadfolder'] . '/' . $e[file];
347  $fI = GeneralUtility::split_fileref($e[file]);
348  if (@is_file($path) && GeneralUtility::inList($this->pObj->textExtensions, $fI['fileext'])) {
349  if (filesize($path) < $GLOBALS['TCA']['sys_template']['columns']['resources']['config']['max_size'] * 1024) {
350  $fileContent = GeneralUtility::getUrl($path);
351  $outCode = $GLOBALS['LANG']->getLL('file') . ' <strong>' . $e[file] . '</strong><BR>';
352  $outCode .= '<textarea name="edit[file]" rows="' . $numberOfRows . '" wrap="off" class="fixed-font enable-tab"' . $this->pObj->doc->formWidth(48, TRUE, 'width:98%;height:70%') . ' class="fixed-font">' . GeneralUtility::formatForTextarea($fileContent) . '</textarea>';
353  $outCode .= '<input type="Hidden" name="edit[filename]" value="' . $e[file] . '">';
354  $outCode .= '<input type="Hidden" name="e[file]" value="' . htmlspecialchars($e[file]) . '">';
355  $theOutput .= $this->pObj->doc->spacer(15);
356  $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('editResource'), '');
357  $theOutput .= $this->pObj->doc->sectionEnd() . $outCode;
358  } else {
359  $theOutput .= $this->pObj->doc->spacer(15);
360  $fileToBig = sprintf($GLOBALS['LANG']->getLL('filesizeExceeded'), $GLOBALS['TCA']['sys_template']['columns']['resources']['config']['max_size']);
361  $filesizeNotAllowed = sprintf($GLOBALS['LANG']->getLL('notAllowed'), $GLOBALS['TCA']['sys_template']['columns']['resources']['config']['max_size']);
362  $theOutput .= $this->pObj->doc->section('<font color=red>' . $fileToBig . '</font>', $filesizeNotAllowed, 0, 0, 0, 1);
363  }
364  }
365  }
366  if ($e['config']) {
367  $outCode = '<textarea name="data[config]" rows="' . $numberOfRows . '" wrap="off" class="fixed-font enable-tab"' . $this->pObj->doc->formWidth(48, TRUE, 'width:98%;height:70%') . ' class="fixed-font">' . GeneralUtility::formatForTextarea($tplRow['config']) . '</textarea>';
368  $outCode .= '<input type="Hidden" name="e[config]" value="1">';
369  // Display "Include TypoScript file content?" checkbox
370  $outCode .= BackendUtility::getFuncCheck($this->pObj->id, 'SET[includeTypoScriptFileContent]', $this->pObj->MOD_SETTINGS['includeTypoScriptFileContent'], '', '&e[config]=1', 'id="checkIncludeTypoScriptFileContent"');
371  $outCode .= '<label for="checkIncludeTypoScriptFileContent">' . $GLOBALS['LANG']->getLL('includeTypoScriptFileContent') . '</label><br />';
372  $theOutput .= $this->pObj->doc->spacer(15);
373  $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('setup'), '', TRUE);
374  $theOutput .= $this->pObj->doc->sectionEnd() . $outCode;
375  }
376  // Processing:
377  $outCode = '';
378  $outCode .= $this->tableRow($GLOBALS['LANG']->getLL('title'), htmlspecialchars($tplRow['title']), 'title');
379  $outCode .= $this->tableRow($GLOBALS['LANG']->getLL('sitetitle'), htmlspecialchars($tplRow['sitetitle']), 'sitetitle');
380  $outCode .= $this->tableRow($GLOBALS['LANG']->getLL('description'), nl2br(htmlspecialchars($tplRow['description'])), 'description');
381  $outCode .= $this->tableRow($GLOBALS['LANG']->getLL('constants'), sprintf($GLOBALS['LANG']->getLL('editToView'), trim($tplRow[constants]) ? count(explode(LF, $tplRow[constants])) : 0), 'constants');
382  $outCode .= $this->tableRow($GLOBALS['LANG']->getLL('setup'), sprintf($GLOBALS['LANG']->getLL('editToView'), trim($tplRow[config]) ? count(explode(LF, $tplRow[config])) : 0), 'config');
383  $outCode = '<table class="t3-table">' . $outCode . '</table>';
384  // Edit all icon:
385  $outCode .= '<br /><a href="#" onClick="' . BackendUtility::editOnClick((rawurlencode('&createExtension=0') . '&amp;edit[sys_template][' . $tplRow['uid'] . ']=edit'), $BACK_PATH, '') . '"><strong>' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-open', array('title' => $GLOBALS['LANG']->getLL('editTemplateRecord'))) . $GLOBALS['LANG']->getLL('editTemplateRecord') . '</strong></a>';
386  $theOutput .= $this->pObj->doc->section('', $outCode);
387  // hook after compiling the output
388  if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postOutputProcessingHook'])) {
389  $postOutputProcessingHook = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postOutputProcessingHook'];
390  if (is_array($postOutputProcessingHook)) {
391  $hookParameters = array(
392  'theOutput' => &$theOutput,
393  'POST' => $POST,
394  'e' => $e,
395  'tplRow' => $tplRow,
396  'numberOfRows' => $numberOfRows
397  );
398  foreach ($postOutputProcessingHook as $hookFunction) {
399  GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
400  }
401  }
402  }
403  } else {
404  $theOutput .= $this->pObj->noTemplate(1);
405  }
406  return $theOutput;
407  }
408 
409 }
static getFuncCheck($mainParams, $elementName, $currentValue, $script='', $addParams='', $tagParams='')
static writeFile($file, $content, $changePermissions=FALSE)
static editOnClick($params, $backPath='', $requestUri='')
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
static checkIncludeLines($string, $cycle_counter=1, $returnFiles=FALSE, $parentFilenameOrPath='')
static callUserFunction($funcName, &$params, &$ref, $checkPrefix='', $errorMode=0)
static getSpriteIconForRecord($table, array $row, array $options=array())
static getModuleUrl($moduleName, $urlParameters=array(), $backPathOverride=FALSE, $returnAbsoluteUrl=FALSE)
static split_fileref($fileNameWithPath)
$BACK_PATH
Definition: conf.php:3
static getUrl($url, $includeHeader=0, $requestHeaders=FALSE, &$report=NULL)
static getSpriteIcon($iconName, array $options=array(), array $overlays=array())
static formatSize($sizeInBytes, $labels='')
static redirect($url, $httpStatus=self::HTTP_STATUS_303)
Definition: HttpUtility.php:76
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static getFileAbsFileName($filename, $onlyRelative=TRUE, $relToTYPO3_mainDir=FALSE)