[TASK] Followup: Remove conf.php from ext:tstemplate
[Packages/TYPO3.CMS.git] / typo3 / sysext / tstemplate / Classes / Controller / TypoScriptTemplateConstantEditorModuleFunctionController.php
1 <?php
2 namespace TYPO3\CMS\Tstemplate\Controller;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
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.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * TypoScript Constant editor
19 *
20 * Module Include-file
21 *
22 * localconf-variables:
23 * $TYPO3_CONF_VARS['MODS']['web_ts']['onlineResourceDir'] = 'fileadmin/fonts/'; // This is the path (must be in "fileadmin/" !!) where the web_ts/constant-editor submodule fetches online resources. Put fonts (ttf) and standard images here!
24 *
25 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
26 */
27 class TypoScriptTemplateConstantEditorModuleFunctionController extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule {
28
29 /**
30 * Initialize editor
31 *
32 * @param int $pageId
33 * @param int $template_uid
34 * @return int
35 */
36 public function initialize_editor($pageId, $template_uid = 0) {
37 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
38 global $tmpl, $tplRow, $theConstants;
39 $tmpl = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class);
40 // Defined global here!
41 $tmpl->tt_track = 0;
42 // Do not log time-performance information
43 $tmpl->init();
44 $tmpl->ext_localGfxPrefix = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('tstemplate');
45 $tmpl->ext_localWebGfxPrefix = $GLOBALS['BACK_PATH'] . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('tstemplate') . 'Resources/Public/';
46 // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
47 $tplRow = $tmpl->ext_getFirstTemplate($pageId, $template_uid);
48 // IF there was a template...
49 if (is_array($tplRow)) {
50 // Gets the rootLine
51 $sys_page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
52 $rootLine = $sys_page->getRootLine($pageId);
53 // This generates the constants/config + hierarchy info for the template.
54 $tmpl->runThroughTemplates($rootLine, $template_uid);
55 // The editable constants are returned in an array.
56 $theConstants = $tmpl->generateConfig_constants();
57 // The returned constants are sorted in categories, that goes into the $tmpl->categories array
58 $tmpl->ext_categorizeEditableConstants($theConstants);
59 // This array will contain key=[expanded constantname], value=linenumber in template. (after edit_divider, if any)
60 $tmpl->ext_regObjectPositions($tplRow['constants']);
61 return 1;
62 }
63 }
64
65 /**
66 * Display example
67 *
68 * @param string $theOutput
69 * @return string
70 */
71 public function displayExample($theOutput) {
72 global $tmpl;
73 if ($tmpl->helpConfig['imagetag'] || $tmpl->helpConfig['description'] || $tmpl->helpConfig['header']) {
74 $theOutput .= $this->pObj->doc->spacer(30);
75 $theOutput .= $this->pObj->doc->section($tmpl->helpConfig['header'], '<div align="center">' . $tmpl->helpConfig['imagetag'] . '</div><BR>' . ($tmpl->helpConfig['description'] ? implode(explode('//', $tmpl->helpConfig['description']), '<BR>') . '<BR>' : '') . ($tmpl->helpConfig['bulletlist'] ? '<ul><li>' . implode(explode('//', $tmpl->helpConfig['bulletlist']), '<li>') . '</ul>' : '<BR>'));
76 }
77 return $theOutput;
78 }
79
80 /**
81 * Main
82 *
83 * @return string
84 */
85 public function main() {
86 global $tmpl, $tplRow, $theConstants;
87 $GLOBALS['LANG']->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_ceditor.xlf');
88 $theOutput = '';
89 // Create extension template
90 $this->pObj->createTemplate($this->pObj->id);
91 // Checking for more than one template an if, set a menu...
92 $manyTemplatesMenu = $this->pObj->templateMenu();
93 $template_uid = 0;
94 if ($manyTemplatesMenu) {
95 $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
96 }
97 // BUGBUG: Should we check if the user may at all read and write template-records???
98 // initialize
99 $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
100 if ($existTemplate) {
101 $this->pObj->doc->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Tstemplate/ConstantEditor');
102 $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
103 // Update template ?
104 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_POST('submit') || \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger(\TYPO3\CMS\Core\Utility\GeneralUtility::_POST('submit_x')) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger(\TYPO3\CMS\Core\Utility\GeneralUtility::_POST('submit_y'))) {
105 $tmpl->changed = 0;
106 $tmpl->ext_procesInput(\TYPO3\CMS\Core\Utility\GeneralUtility::_POST(), array(), $theConstants, $tplRow);
107 if ($tmpl->changed) {
108 // Set the data to be saved
109 $recData = array();
110 $recData['sys_template'][$saveId]['constants'] = implode($tmpl->raw, LF);
111 // Create new tce-object
112 $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
113 $tce->stripslashes_values = 0;
114 $tce->start($recData, array());
115 $tce->process_datamap();
116 // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
117 $tce->clear_cacheCmd('all');
118 // re-read the template ...
119 $this->initialize_editor($this->pObj->id, $template_uid);
120 }
121 }
122 // Resetting the menu (start). I wonder if this in any way is a violation of the menu-system. Haven't checked. But need to do it here, because the menu is dependent on the categories available.
123 $this->pObj->MOD_MENU['constant_editor_cat'] = $tmpl->ext_getCategoryLabelArray();
124 $this->pObj->MOD_SETTINGS = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleData($this->pObj->MOD_MENU, \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('SET'), $this->pObj->MCONF['name']);
125 // Resetting the menu (stop)
126 $content = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('sys_template', $tplRow) . '<strong>' . $this->pObj->linkWrapTemplateTitle($tplRow['title'], 'constants') . '</strong>' . htmlspecialchars((trim($tplRow['sitetitle']) ? ' (' . $tplRow['sitetitle'] . ')' : ''));
127 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('editConstants', TRUE), $content, FALSE, TRUE);
128 if ($manyTemplatesMenu) {
129 $theOutput .= $this->pObj->doc->section('', $manyTemplatesMenu);
130 }
131 $theOutput .= $this->pObj->doc->spacer(10);
132 if (count($this->pObj->MOD_MENU['constant_editor_cat'])) {
133 $menu = \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncMenu($this->pObj->id, 'SET[constant_editor_cat]', $this->pObj->MOD_SETTINGS['constant_editor_cat'], $this->pObj->MOD_MENU['constant_editor_cat']);
134 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('category', TRUE), '<NOBR>' . $menu . '</NOBR>', FALSE);
135 } else {
136 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('noConstants', TRUE), $GLOBALS['LANG']->getLL('noConstantsDescription', TRUE), FALSE, FALSE, 1);
137 }
138 $theOutput .= $this->pObj->doc->spacer(15);
139 // Category and constant editor config:
140 $category = $this->pObj->MOD_SETTINGS['constant_editor_cat'];
141 $tmpl->ext_getTSCE_config($category);
142
143 $printFields = trim($tmpl->ext_printFields($theConstants, $category));
144 if ($printFields) {
145 $theOutput .= $this->pObj->doc->section('', $printFields);
146 }
147 if ($BE_USER_modOptions['properties']['constantEditor.']['example'] != 'top') {
148 $theOutput = $this->displayExample($theOutput);
149 }
150 } else {
151 $theOutput .= $this->pObj->noTemplate(1);
152 }
153 return $theOutput;
154 }
155
156 }