TYPO3 CMS  TYPO3_6-2
TypoScriptTemplateModuleController.php
Go to the documentation of this file.
1 <?php
3 
20 
29 
33  public $perms_clause;
34 
38  public $e;
39 
43  public $sObj;
44 
48  public $edit;
49 
53  public $textExtensions = 'html,htm,txt,css,tmpl,inc,js';
54 
58  public $modMenu_type = '';
59 
64 
69 
73  public function __construct() {
74  $GLOBALS['LANG']->includeLLFile('EXT:tstemplate/ts/locallang.xlf');
75  $GLOBALS['BE_USER']->modAccess($GLOBALS['MCONF'], TRUE);
76  }
77 
84  public function init() {
85  parent::init();
86  $this->id = (int)GeneralUtility::_GP('id');
87  $this->e = GeneralUtility::_GP('e');
88  $this->sObj = GeneralUtility::_GP('sObj');
89  $this->edit = GeneralUtility::_GP('edit');
90  $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
91  }
92 
99  public function clearCache() {
100  if (GeneralUtility::_GP('clear_all_cache')) {
101  $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
103  $tce->stripslashes_values = 0;
104  $tce->start(array(), array());
105  $tce->clear_cacheCmd('all');
106  }
107  }
108 
115  public function main() {
116  // Template markers
117  $markers = array(
118  'CSH' => '',
119  'FUNC_MENU' => '',
120  'CONTENT' => ''
121  );
122 
123  // Access check...
124  // The page will show only if there is a valid page and if this page may be viewed by the user
125  $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
126  $this->access = is_array($this->pageinfo) ? 1 : 0;
127  $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
128  $this->doc->backPath = $GLOBALS['BACK_PATH'];
129  $this->doc->setModuleTemplate('EXT:tstemplate/Resources/Private/Templates/tstemplate.html');
130 
131  if ($this->id && $this->access) {
132  $urlParameters = array(
133  'id' => $this->id,
134  'template' => 'all'
135  );
136  $aHref = BackendUtility::getModuleUrl('web_ts', $urlParameters);
137  $this->doc->form = '<form action="' . htmlspecialchars($aHref) . '" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '" name="editForm">';
138 
139  // JavaScript
140  $this->doc->JScode = '
141  <script language="javascript" type="text/javascript">
142  function uFormUrl(aname) {
143  document.forms[0].action = ' . GeneralUtility::quoteJSvalue(($aHref . '#'), TRUE) . '+aname;
144  }
145  function brPoint(lnumber,t) {
146  window.location.href = ' . GeneralUtility::quoteJSvalue(($aHref . '&SET[function]=TYPO3\\CMS\\Tstemplate\\Controller\\TypoScriptTemplateObjectBrowserModuleFunctionController&SET[ts_browser_type]='), TRUE) . '+(t?"setup":"const")+"&breakPointLN="+lnumber;
147  return false;
148  }
149  </script>
150  ';
151  $this->doc->postCode = '
152  <script language="javascript" type="text/javascript">
153  if (top.fsMod) top.fsMod.recentIds["web"] = ' . $this->id . ';
154  </script>
155  ';
156  $this->doc->inDocStylesArray[] = '
157  TABLE#typo3-objectBrowser { width: 100%; margin-bottom: 24px; }
158  TABLE#typo3-objectBrowser A { text-decoration: none; }
159  TABLE#typo3-objectBrowser .comment { color: maroon; font-weight: bold; }
160  .ts-typoscript { width: 100%; }
161  .tsob-menu label, .tsob-menu-row2 label, .tsob-conditions label { padding: 0 5px 0 0; vertical-align: text-top;}
162  .tsob-menu-row2 {margin-top: 10px;}
163  .tsob-conditions {padding: 1px 2px;}
164  .tsob-search-submit {margin-left: 3px; margin-right: 3px;}
165  .tst-analyzer-options { margin:5px 0; }
166  .tst-analyzer-options label {padding-left:5px; vertical-align:text-top; }
167  ';
168  // Setting up the context sensitive menu:
169  $this->doc->getContextMenuCode();
170  // Build the modulle content
171  $this->content = $this->doc->header($GLOBALS['LANG']->getLL('moduleTitle'));
172  $this->extObjContent();
173  // Setting up the buttons and markers for docheader
174  $docHeaderButtons = $this->getButtons();
175  $markers['FUNC_MENU'] = BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']);
176  $markers['CONTENT'] = $this->content;
177  } else {
178  // Template pages:
179  $records = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
180  'pages.uid, count(*) AS count, max(sys_template.root) AS root_max_val, min(sys_template.root) AS root_min_val',
181  'pages,sys_template',
182  'pages.uid=sys_template.pid'
185  . BackendUtility::deleteClause('sys_template')
187  'pages.uid',
188  'pages.pid, pages.sorting'
189  );
190  $pArray = array();
191  foreach ($records as $record) {
192  $this->setInPageArray($pArray, BackendUtility::BEgetRootLine($record['uid'], 'AND 1=1'), $record);
193  }
194 
195  $table = '<table class="t3-table" id="ts-overview">' .
196  '<thead>' .
197  '<tr>' .
198  '<th>' . $GLOBALS['LANG']->getLL('pageName') . '</th>' .
199  '<th>' . $GLOBALS['LANG']->getLL('templates') . '</th>' .
200  '<th>' . $GLOBALS['LANG']->getLL('isRoot') . '</th>' .
201  '<th>' . $GLOBALS['LANG']->getLL('isExt') . '</th>' .
202  '</tr>' .
203  '</thead>' .
204  '<tbody>' . implode('', $this->renderList($pArray)) . '</tbody>' .
205  '</table>';
206 
207  $this->content = $this->doc->header($GLOBALS['LANG']->getLL('moduleTitle'));
208  $this->content .= $this->doc->section('', '<p class="lead">' . $GLOBALS['LANG']->getLL('overview') . '</p>' . $table);
209 
210  // RENDER LIST of pages with templates, END
211  // Setting up the buttons and markers for docheader
212  $docHeaderButtons = $this->getButtons();
213  $markers['CONTENT'] = $this->content;
214  }
215 
216  // Build the <body> for the module
217  $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
218  // Renders the module page
219  $this->content = $this->doc->render('Template Tools', $this->content);
220  }
221 
228  public function printContent() {
229  echo $this->content;
230  }
231 
237  protected function getButtons() {
238  $buttons = array(
239  'back' => '',
240  'close' => '',
241  'new' => '',
242  'save' => '',
243  'save_close' => '',
244  'view' => '',
245  'shortcut' => ''
246  );
247 
248  if ($this->id && $this->access) {
249  // View page
250  $buttons['view'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::viewOnClick($this->pageinfo['uid'], $GLOBALS['BACK_PATH'], BackendUtility::BEgetRootLine($this->pageinfo['uid']))) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-view') . '</a>';
251  if ($this->extClassConf['name'] == 'TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController') {
252  // NEW button
253  $buttons['new'] = '<input type="image" class="c-inputButton" name="createExtension" value="New"' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/new_el.gif', '') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:db_new.php.pagetitle', TRUE) . '" />';
254  if (!empty($this->e) && !GeneralUtility::_POST('abort') && !GeneralUtility::_POST('saveclose')) {
255  // no NEW-button while edit
256  $buttons['new'] = '';
257  // SAVE button
258  $buttons['save'] = IconUtility::getSpriteIcon('actions-document-save', array(
259  'html' => '<input type="image" class="c-inputButton" name="submit" src="clear.gif" ' . 'title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '" ' . 'value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '" ' . '/>'
260  ));
261  // SAVE AND CLOSE button
262  $buttons['save_close'] = IconUtility::getSpriteIcon('actions-document-save-close', array(
263  'html' => '<input type="image" class="c-inputButton" name="saveclose" src="clear.gif" ' . 'title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', TRUE) . '" ' . 'value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', TRUE) . '" ' . '/>'
264  ));
265  // CLOSE button
266  $buttons['close'] = IconUtility::getSpriteIcon('actions-document-close', array(
267  'html' => '<input type="image" class="c-inputButton" name="abort" src="clear.gif" ' . 'title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', TRUE) . '" ' . 'value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', TRUE) . '" ' . '/>'
268  ));
269  }
270  } elseif ($this->extClassConf['name'] == 'TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController' && count($this->MOD_MENU['constant_editor_cat'])) {
271  // SAVE button
272  $buttons['save'] = IconUtility::getSpriteIcon('actions-document-save', array('html' => '<input type="image" class="c-inputButton" name="submit" src="clear.gif" ' . 'title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '" ' . 'value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '" ' . '/>'));
273  } elseif ($this->extClassConf['name'] == 'TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateObjectBrowserModuleFunctionController') {
274  if (!empty($this->sObj)) {
275  // BACK
276  $urlParameters = array(
277  'id' => $this->id
278  );
279  $aHref = BackendUtility::getModuleUrl('web_ts', $urlParameters);
280  $buttons['back'] = '<a href="' . htmlspecialchars($aHref) . '" class="typo3-goBack" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', TRUE) . '">' . IconUtility::getSpriteIcon('actions-view-go-back') . '</a>';
281  }
282  }
283  // Shortcut
284  if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
285  $buttons['shortcut'] = $this->doc->makeShortcutIcon('id, edit_record, pointer, new_unique_uid, search_field, search_levels, showLimit', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name']);
286  }
287  } else {
288  // Shortcut
289  if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
290  $buttons['shortcut'] = $this->doc->makeShortcutIcon('id', '', $this->MCONF['name']);
291  }
292  }
293  return $buttons;
294  }
295 
296  // OTHER FUNCTIONS:
305  public function linkWrapTemplateTitle($title, $onlyKey = '') {
306  $urlParameters = array(
307  'id' => $this->id
308  );
309  $aHref = BackendUtility::getModuleUrl('web_ts', $urlParameters);
310  if ($onlyKey) {
311  $title = '<a href="' . htmlspecialchars(($aHref . '&e[' . $onlyKey . ']=1&SET[function]=TYPO3\\CMS\\Tstemplate\\Controller\\TypoScriptTemplateInformationModuleFunctionController')) . '">' . htmlspecialchars($title) . '</a>';
312  } else {
313  $title = '<a href="' . htmlspecialchars(($aHref . '&e[constants]=1&e[config]=1&SET[function]=TYPO3\\CMS\\Tstemplate\\Controller\\TypoScriptTemplateInformationModuleFunctionController')) . '">' . htmlspecialchars($title) . '</a>';
314  }
315  return $title;
316  }
317 
325  public function noTemplate($newStandardTemplate = 0) {
326  // Defined global here!
327  $tmpl = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\ExtendedTemplateService');
329  // Do not log time-performance information
330  $tmpl->tt_track = FALSE;
331  $tmpl->init();
332  $theOutput = '';
333  $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('noTemplateDescription') . '<br />' . $GLOBALS['LANG']->getLL('createTemplateToEditConfiguration'), $GLOBALS['LANG']->getLL('noTemplate'), \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
334  $theOutput .= $flashMessage->render();
335  // New standard?
336  if ($newStandardTemplate) {
337  // Hook to change output, implemented for statictemplates
338  if (isset(
339  $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\\CMS\\Tstemplate\\Controller\\TypoScriptTemplateModuleController']['newStandardTemplateView']
340  )) {
341  $selector = '';
342  $staticsText = '';
343  $reference = array(
344  'selectorHtml' => &$selector,
345  'staticsText' => &$staticsText
346  );
348  $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\\CMS\\Tstemplate\\Controller\\TypoScriptTemplateModuleController']['newStandardTemplateView'],
349  $reference,
350  $this
351  );
352  $selector = $reference['selectorHtml'];
353  $staticsText = $reference['staticsText'];
354  } else {
355  $selector = '<input type="hidden" name="createStandard" value="" />';
356  $staticsText = '';
357  }
358  // Extension?
359  $theOutput .= $this->doc->section($GLOBALS['LANG']->getLL('newWebsite') . $staticsText, $GLOBALS['LANG']->getLL('newWebsiteDescription') . '<br /><br />' . $selector . '<input type="Submit" name="newWebsite" value="' . $GLOBALS['LANG']->getLL('newWebsiteAction') . '" />', 0, 1);
360  }
361  // Extension?
362  $theOutput .= $this->doc->spacer(10);
363  $theOutput .= $this->doc->section($GLOBALS['LANG']->getLL('extTemplate'), $GLOBALS['LANG']->getLL('extTemplateDescription') . '<br /><br />' . '<input type="submit" name="createExtension" value="' . $GLOBALS['LANG']->getLL('extTemplateAction') . '" />', 0, 1);
364  // Go to first appearing...
365  $first = $tmpl->ext_prevPageWithTemplate($this->id, $this->perms_clause);
366  if ($first) {
367  $theOutput .= $this->doc->spacer(10);
368  $urlParameters = array(
369  'id' => $first['uid']
370  );
371  $aHref = BackendUtility::getModuleUrl('web_ts', $urlParameters);
372  $theOutput .= $this->doc->section($GLOBALS['LANG']->getLL('goToClosest'), sprintf($GLOBALS['LANG']->getLL('goToClosestDescription') . '<br /><br />%s<strong>' . $GLOBALS['LANG']->getLL('goToClosestAction') . '</strong>%s', htmlspecialchars($first['title']), $first['uid'], '<a href="' . htmlspecialchars($aHref) . '">', '</a>'), 0, 1);
373  }
374  return $theOutput;
375  }
376 
380  public function templateMenu() {
381  // Defined global here!
382  $tmpl = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\ExtendedTemplateService');
384  // Do not log time-performance information
385  $tmpl->tt_track = FALSE;
386  $tmpl->init();
387  $all = $tmpl->ext_getAllTemplates($this->id, $this->perms_clause);
388  $menu = '';
389  if (count($all) > 1) {
390  $this->MOD_MENU['templatesOnPage'] = array();
391  foreach ($all as $d) {
392  $this->MOD_MENU['templatesOnPage'][$d['uid']] = $d['title'];
393  }
394  }
395  $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->MCONF['name'], $this->modMenu_type, $this->modMenu_dontValidateList, $this->modMenu_setDefaultList);
396  $menu = BackendUtility::getFuncMenu($this->id, 'SET[templatesOnPage]', $this->MOD_SETTINGS['templatesOnPage'], $this->MOD_MENU['templatesOnPage']);
397  return $menu;
398  }
399 
408  public function createTemplate($id, $actTemplateId = 0) {
409  $recData = array();
411  $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
412  $tce->stripslashes_values = FALSE;
413 
414  if (GeneralUtility::_GP('createExtension') || GeneralUtility::_GP('createExtension_x')) {
415  $recData['sys_template']['NEW'] = array(
416  'pid' => $actTemplateId ? -1 * $actTemplateId : $id,
417  'title' => '+ext'
418  );
419  $tce->start($recData, array());
420  $tce->process_datamap();
421  } elseif (GeneralUtility::_GP('newWebsite')) {
422  // Hook to handle row data, implemented for statictemplates
423  if (isset(
424  $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\\CMS\\Tstemplate\\Controller\\TypoScriptTemplateModuleController']['newStandardTemplateHandler']
425  )) {
426  $reference = array(
427  'recData' => &$recData,
428  'id' => $id,
429  );
431  $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\\CMS\\Tstemplate\\Controller\\TypoScriptTemplateModuleController']['newStandardTemplateHandler'],
432  $reference,
433  $this
434  );
435  $recData = $reference['recData'];
436  } else {
437  $recData['sys_template']['NEW'] = array(
438  'pid' => $id,
439  'title' => $GLOBALS['LANG']->getLL('titleNewSite'),
440  'sorting' => 0,
441  'root' => 1,
442  'clear' => 3,
443  'config' => '
444 # Default PAGE object:
445 page = PAGE
446 page.10 = TEXT
447 page.10.value = HELLO WORLD!
448 '
449  );
450  }
451  $tce->start($recData, array());
452  $tce->process_datamap();
453  $tce->clear_cacheCmd('all');
454  }
455  return $tce->substNEWwithIDs['NEW'];
456  }
457 
458  // RENDER LIST of pages with templates, BEGIN
468  public function setInPageArray(&$pArray, $rlArr, $row) {
469  ksort($rlArr);
470  reset($rlArr);
471  if (!$rlArr[0]['uid']) {
472  array_shift($rlArr);
473  }
474  $cEl = current($rlArr);
475  $pArray[$cEl['uid']] = htmlspecialchars($cEl['title']);
476  array_shift($rlArr);
477  if (count($rlArr)) {
478  if (!isset($pArray[($cEl['uid'] . '.')])) {
479  $pArray[$cEl['uid'] . '.'] = array();
480  }
481  $this->setInPageArray($pArray[$cEl['uid'] . '.'], $rlArr, $row);
482  } else {
483  $pArray[$cEl['uid'] . '_'] = $row;
484  }
485  }
486 
496  public function renderList($pArray, $lines = array(), $c = 0) {
497  if (is_array($pArray)) {
498  reset($pArray);
499  static $i;
500  foreach ($pArray as $k => $v) {
501  if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($k)) {
502  if (isset($pArray[$k . '_'])) {
503  $lines[] = '<tr class="' . ($i++ % 2 == 0 ? 'bgColor4' : 'bgColor6') . '">
504  <td nowrap><img src="clear.gif" width="1" height="1" hspace=' . $c * 10 . ' align="top">' . '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('id' => $k))) . '">' . IconUtility::getSpriteIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $k), array('title' => ('ID: ' . $k))) . GeneralUtility::fixed_lgd_cs($pArray[$k], 30) . '</a></td>
505  <td>' . $pArray[($k . '_')]['count'] . '</td>
506  <td>' . ($pArray[$k . '_']['root_max_val'] > 0 ? IconUtility::getSpriteIcon('status-status-checked') : '&nbsp;') . '</td>
507  <td>' . ($pArray[$k . '_']['root_min_val'] == 0 ? IconUtility::getSpriteIcon('status-status-checked') : '&nbsp;') . '</td>
508  </tr>';
509  } else {
510  $lines[] = '<tr class="' . ($i++ % 2 == 0 ? 'bgColor4' : 'bgColor6') . '">
511  <td nowrap ><img src="clear.gif" width="1" height="1" hspace=' . $c * 10 . ' align=top>' . IconUtility::getSpriteIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $k)) . GeneralUtility::fixed_lgd_cs($pArray[$k], 30) . '</td>
512  <td></td>
513  <td></td>
514  <td></td>
515  </tr>';
516  }
517  $lines = $this->renderList($pArray[$k . '.'], $lines, $c + 1);
518  }
519  }
520  }
521  return $lines;
522  }
523 
524 }
static skinImg($backPath, $src, $wHattribs='', $outputMode=0)
static getRecordWSOL($table, $uid, $fields=' *', $where='', $useDeleteClause=TRUE, $unsetMovePointers=FALSE)
static readPageAccess($id, $perms_clause)
static BEgetRootLine($uid, $clause='', $workspaceOL=FALSE)
static callUserFunction($funcName, &$params, &$ref, $checkPrefix='', $errorMode=0)
static viewOnClick($pageUid, $backPath='', $rootLine='', $anchorSection='', $alternativeUrl='', $additionalGetVars='', $switchFocus=TRUE)
static getSpriteIconForRecord($table, array $row, array $options=array())
static getModuleUrl($moduleName, $urlParameters=array(), $backPathOverride=FALSE, $returnAbsoluteUrl=FALSE)
static linkThisScript(array $getParams=array())
static getModuleData($MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='')
static getSpriteIcon($iconName, array $options=array(), array $overlays=array())
static getFuncMenu($mainParams, $elementName, $currentValue, $menuItems, $script='', $addparams='')
static fixed_lgd_cs($string, $chars, $appendString='...')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static deleteClause($table, $tableAlias='')