2 namespace TYPO3\CMS\Tstemplate\Controller
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Core\Utility\GeneralUtility
;
18 use TYPO3\CMS\Backend\Utility\BackendUtility
;
19 use TYPO3\CMS\Backend\Utility\IconUtility
;
22 * Module: TypoScript Tools
24 * $TYPO3_CONF_VARS["MODS"]["web_ts"]["onlineResourceDir"] = Directory of default resources. Eg. "fileadmin/res/" or so.
26 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
28 class TypoScriptTemplateModuleController
extends \TYPO3\CMS\Backend\Module\BaseScriptClass
{
53 public $textExtensions = 'html,htm,txt,css,tmpl,inc,js';
58 public $modMenu_type = '';
63 public $modMenu_dontValidateList = '';
68 public $modMenu_setDefaultList = '';
73 public $pageinfo = array();
78 public $access = FALSE;
83 public function __construct() {
84 $GLOBALS['LANG']->includeLLFile('EXT:tstemplate/ts/locallang.xlf');
85 $GLOBALS['BE_USER']->modAccess($GLOBALS['MCONF'], TRUE);
93 public function init() {
95 $this->id
= (int)GeneralUtility
::_GP('id');
96 $this->e
= GeneralUtility
::_GP('e');
97 $this->sObj
= GeneralUtility
::_GP('sObj');
98 $this->edit
= GeneralUtility
::_GP('edit');
99 $this->perms_clause
= $GLOBALS['BE_USER']->getPagePermsClause(1);
107 public function clearCache() {
108 if (GeneralUtility
::_GP('clear_all_cache')) {
109 $tce = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler
::class);
110 /** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */
111 $tce->stripslashes_values
= 0;
112 $tce->start(array(), array());
113 $tce->clear_cacheCmd('all');
122 public function main() {
131 // The page will show only if there is a valid page and if this page may be viewed by the user
132 $this->pageinfo
= BackendUtility
::readPageAccess($this->id
, $this->perms_clause
);
133 $this->access
= is_array($this->pageinfo
);
135 /** @var \TYPO3\CMS\Backend\Template\DocumentTemplate doc */
136 $this->doc
= GeneralUtility
::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate
::class);
137 $this->doc
->backPath
= $GLOBALS['BACK_PATH'];
138 $this->doc
->setModuleTemplate('EXT:tstemplate/Resources/Private/Templates/tstemplate.html');
139 $this->doc
->addStyleSheet('module', 'sysext/tstemplate/Resources/Public/Styles/styles.css');
141 if ($this->id
&& $this->access
) {
142 $urlParameters = array(
146 $aHref = BackendUtility
::getModuleUrl('web_ts', $urlParameters);
147 $this->doc
->form
= '<form action="' . htmlspecialchars($aHref) . '" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '" name="editForm">';
150 $this->doc
->JScode
= '
151 <script language="javascript" type="text/javascript">
152 function uFormUrl(aname) {
153 document.forms[0].action = ' . GeneralUtility
::quoteJSvalue(($aHref . '#'), TRUE) . '+aname;
155 function brPoint(lnumber,t) {
156 window.location.href = ' . GeneralUtility
::quoteJSvalue(($aHref . '&SET[function]=TYPO3\\CMS\\Tstemplate\\Controller\\TypoScriptTemplateObjectBrowserModuleFunctionController&SET[ts_browser_type]='), TRUE) . '+(t?"setup":"const")+"&breakPointLN="+lnumber;
161 $this->doc
->postCode
= '
162 <script language="javascript" type="text/javascript">
163 if (top.fsMod) top.fsMod.recentIds["web"] = ' . $this->id
. ';
166 $this->doc
->inDocStylesArray
[] = '
167 TABLE#typo3-objectBrowser { width: 100%; margin-bottom: 24px; }
168 TABLE#typo3-objectBrowser A { text-decoration: none; }
169 TABLE#typo3-objectBrowser .comment { color: maroon; font-weight: bold; }
170 .ts-typoscript { width: 100%; }
171 .tsob-menu-row2 {margin-top: 10px;}
172 .tsob-search-submit {margin-left: 3px; margin-right: 3px;}
173 .tst-analyzer-options { margin:5px 0; }
175 // Setting up the context sensitive menu:
176 $this->doc
->getContextMenuCode();
177 // Build the modulle content
178 $this->content
= $this->doc
->header($GLOBALS['LANG']->getLL('moduleTitle'));
179 $this->extObjContent();
180 // Setting up the buttons and markers for docheader
181 $docHeaderButtons = $this->getButtons();
182 $markers['FUNC_MENU'] = BackendUtility
::getFuncMenu($this->id
, 'SET[function]', $this->MOD_SETTINGS
['function'], $this->MOD_MENU
['function']);
183 $markers['CONTENT'] = $this->content
;
186 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('pages.uid, count(*) AS count, max(sys_template.root) AS root_max_val, min(sys_template.root) AS root_min_val', 'pages,sys_template', 'pages.uid=sys_template.pid' . BackendUtility
::deleteClause('pages') . BackendUtility
::versioningPlaceholderClause('pages') . BackendUtility
::deleteClause('sys_template') . BackendUtility
::versioningPlaceholderClause('sys_template'), 'pages.uid');
187 $templateArray = array();
189 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
190 $this->setInPageArray($pArray, BackendUtility
::BEgetRootLine($row['uid'], 'AND 1=1'), $row);
192 $GLOBALS['TYPO3_DB']->sql_free_result($res);
194 $table = '<div class="table-fit"><table class="t3-table" id="ts-overview">' .
197 '<th>' . $GLOBALS['LANG']->getLL('pageName') . '</th>' .
198 '<th>' . $GLOBALS['LANG']->getLL('templates') . '</th>' .
199 '<th>' . $GLOBALS['LANG']->getLL('isRoot') . '</th>' .
200 '<th>' . $GLOBALS['LANG']->getLL('isExt') . '</th>' .
203 '<tbody>' . implode('', $this->renderList($pArray)) . '</tbody>' .
206 $this->content
= $this->doc
->header($GLOBALS['LANG']->getLL('moduleTitle'));
207 $this->content
.= $this->doc
->section('', '<p class="lead">' . $GLOBALS['LANG']->getLL('overview') . '</p>' . $table);
209 // RENDER LIST of pages with templates, END
210 // Setting up the buttons and markers for docheader
211 $docHeaderButtons = $this->getButtons();
212 $markers['CONTENT'] = $this->content
;
215 // Build the <body> for the module
216 $this->content
= $this->doc
->moduleBody($this->pageinfo
, $docHeaderButtons, $markers);
217 // Renders the module page
218 $this->content
= $this->doc
->render('Template Tools', $this->content
);
226 public function printContent() {
231 * Create the panel of buttons for submitting the form or otherwise perform operations.
233 * @return array All available buttons as an assoc. array
235 protected function getButtons() {
246 if ($this->id
&& $this->access
) {
248 $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>';
249 if ($this->extClassConf
['name'] == 'TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController') {
251 $urlParameters = array(
254 'createExtension' => 'new'
256 $buttons['new'] = '<a href="' . htmlspecialchars(BackendUtility
::getModuleUrl('web_ts', $urlParameters)) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:db_new.php.pagetitle', TRUE) . '">' . IconUtility
::getSpriteIcon('actions-document-new') . '</a>';
257 if (!empty($this->e
) && !GeneralUtility
::_POST('saveclose')) {
258 // no NEW-button while edit
259 $buttons['new'] = '';
261 $buttons['save'] = IconUtility
::getSpriteIcon('actions-document-save', array(
262 '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) . '" ' . '/>'
264 // SAVE AND CLOSE button
265 $buttons['save_close'] = IconUtility
::getSpriteIcon('actions-document-save-close', array(
266 '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) . '" ' . '/>'
269 $url = BackendUtility
::getModuleUrl('web_ts', array('id' => $this->id
));
270 $buttons['close'] = '<a href="' . htmlspecialchars($url) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', TRUE) . '">' . IconUtility
::getSpriteIcon('actions-document-close') .'</a>';
272 } elseif ($this->extClassConf
['name'] == 'TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController' && count($this->MOD_MENU
['constant_editor_cat'])) {
274 $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) . '" ' . '/>'));
275 } elseif ($this->extClassConf
['name'] == 'TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateObjectBrowserModuleFunctionController') {
276 if (!empty($this->sObj
)) {
278 $urlParameters = array(
281 $aHref = BackendUtility
::getModuleUrl('web_ts', $urlParameters);
282 $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>';
286 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
287 $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']);
291 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
292 $buttons['shortcut'] = $this->doc
->makeShortcutIcon('id', '', $this->MCONF
['name']);
300 * Wrap title for link in template
302 * @param string $title
303 * @param string $onlyKey
306 public function linkWrapTemplateTitle($title, $onlyKey = '') {
307 $urlParameters = array(
310 $aHref = BackendUtility
::getModuleUrl('web_ts', $urlParameters);
312 $title = '<a href="' . htmlspecialchars(($aHref . '&e[' . $onlyKey . ']=1&SET[function]=TYPO3\\CMS\\Tstemplate\\Controller\\TypoScriptTemplateInformationModuleFunctionController')) . '">' . htmlspecialchars($title) . '</a>';
314 $title = '<a href="' . htmlspecialchars(($aHref . '&e[constants]=1&e[config]=1&SET[function]=TYPO3\\CMS\\Tstemplate\\Controller\\TypoScriptTemplateInformationModuleFunctionController')) . '">' . htmlspecialchars($title) . '</a>';
322 * @param int $newStandardTemplate
325 public function noTemplate($newStandardTemplate = 0) {
326 // Defined global here!
327 $tmpl = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService
::class);
328 /** @var $tmpl \TYPO3\CMS\Core\TypoScript\ExtendedTemplateService */
329 // Do not log time-performance information
330 $tmpl->tt_track
= FALSE;
333 $flashMessage = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage
::class, $GLOBALS['LANG']->getLL('noTemplateDescription') . '<br />' . $GLOBALS['LANG']->getLL('createTemplateToEditConfiguration'), $GLOBALS['LANG']->getLL('noTemplate'), \TYPO3\CMS\Core\Messaging\FlashMessage
::INFO
);
334 $theOutput .= $flashMessage->render();
336 if ($newStandardTemplate) {
337 // Hook to change output, implemented for statictemplates
339 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\\CMS\\Tstemplate\\Controller\\TypoScriptTemplateModuleController']['newStandardTemplateView']
344 'selectorHtml' => &$selector,
345 'staticsText' => &$staticsText
347 GeneralUtility
::callUserFunction(
348 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\\CMS\\Tstemplate\\Controller\\TypoScriptTemplateModuleController']['newStandardTemplateView'],
352 $selector = $reference['selectorHtml'];
353 $staticsText = $reference['staticsText'];
355 $selector = '<input type="hidden" name="createStandard" value="" />';
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);
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
);
367 $theOutput .= $this->doc
->spacer(10);
368 $urlParameters = array(
369 'id' => $first['uid']
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);
377 public function templateMenu() {
378 // Defined global here!
379 $tmpl = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService
::class);
380 /** @var $tmpl \TYPO3\CMS\Core\TypoScript\ExtendedTemplateService */
381 // Do not log time-performance information
382 $tmpl->tt_track
= FALSE;
384 $all = $tmpl->ext_getAllTemplates($this->id
, $this->perms_clause
);
386 if (count($all) > 1) {
387 $this->MOD_MENU
['templatesOnPage'] = array();
388 foreach ($all as $d) {
389 $this->MOD_MENU
['templatesOnPage'][$d['uid']] = $d['title'];
392 $this->MOD_SETTINGS
= BackendUtility
::getModuleData($this->MOD_MENU
, GeneralUtility
::_GP('SET'), $this->MCONF
['name'], $this->modMenu_type
, $this->modMenu_dontValidateList
, $this->modMenu_setDefaultList
);
393 $menu = BackendUtility
::getFuncMenu($this->id
, 'SET[templatesOnPage]', $this->MOD_SETTINGS
['templatesOnPage'], $this->MOD_MENU
['templatesOnPage']);
401 * @param int $actTemplateId
404 public function createTemplate($id, $actTemplateId = 0) {
405 if (GeneralUtility
::_GP('createExtension') || GeneralUtility
::_GP('createExtension_x')) {
406 $tce = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler
::class);
407 /** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */
408 $tce->stripslashes_values
= 0;
410 $recData['sys_template']['NEW'] = array(
411 'pid' => $actTemplateId ?
-1 * $actTemplateId : $id,
414 $tce->start($recData, array());
415 $tce->process_datamap();
416 return $tce->substNEWwithIDs
['NEW'];
417 } elseif (GeneralUtility
::_GP('newWebsite')) {
418 $tce = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler
::class);
419 /** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */
420 $tce->stripslashes_values
= 0;
422 // Hook to handle row data, implemented for statictemplates
424 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\\CMS\\Tstemplate\\Controller\\TypoScriptTemplateModuleController']['newStandardTemplateHandler']
427 'recData' => &$recData,
430 GeneralUtility
::callUserFunction(
431 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\\CMS\\Tstemplate\\Controller\\TypoScriptTemplateModuleController']['newStandardTemplateHandler'],
435 $recData = $reference['recData'];
437 $recData['sys_template']['NEW'] = array(
439 'title' => $GLOBALS['LANG']->getLL('titleNewSite'),
444 # Default PAGE object:
447 page.10.value = HELLO WORLD!
451 $tce->start($recData, array());
452 $tce->process_datamap();
453 $tce->clear_cacheCmd('all');
457 // RENDER LIST of pages with templates, BEGIN
461 * @param array $pArray
462 * @param array $rlArr
466 public function setInPageArray(&$pArray, $rlArr, $row) {
469 if (!$rlArr[0]['uid']) {
472 $cEl = current($rlArr);
473 $pArray[$cEl['uid']] = htmlspecialchars($cEl['title']);
476 if (!isset($pArray[($cEl['uid'] . '.')])) {
477 $pArray[$cEl['uid'] . '.'] = array();
479 $this->setInPageArray($pArray[$cEl['uid'] . '.'], $rlArr, $row);
481 $pArray[$cEl['uid'] . '_'] = $row;
488 * @param array $pArray
489 * @param array $lines
493 public function renderList($pArray, $lines = array(), $c = 0) {
494 if (is_array($pArray)) {
497 foreach ($pArray as $k => $v) {
498 if (\TYPO3\CMS\Core\Utility\MathUtility
::canBeInterpretedAsInteger($k)) {
499 if (isset($pArray[$k . '_'])) {
500 $lines[] = '<tr class="' . ($i++ %
2 == 0 ?
'bgColor4' : 'bgColor6') . '">
501 <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>
502 <td>' . $pArray[($k . '_')]['count'] . '</td>
503 <td>' . ($pArray[$k . '_']['root_max_val'] > 0 ? IconUtility
::getSpriteIcon('status-status-checked') : ' ') . '</td>
504 <td>' . ($pArray[$k . '_']['root_min_val'] == 0 ? IconUtility
::getSpriteIcon('status-status-checked') : ' ') . '</td>
507 $lines[] = '<tr class="' . ($i++ %
2 == 0 ?
'bgColor4' : 'bgColor6') . '">
508 <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>
514 $lines = $this->renderList($pArray[$k . '.'], $lines, $c +
1);