[BUGFIX] "template" was replaced by namespace everywhere
[Packages/TYPO3.CMS.git] / typo3 / sysext / tstemplate_ceditor / Classes / Controller / TypoScriptTemplateConstantEditorModuleFunctionController.php
1 <?php
2 namespace TYPO3\CMS\TstemplateCeditor\Controller;
3
4 /**
5 * TypoScript Constant editor
6 *
7 * Module Include-file
8 *
9 * localconf-variables:
10 * $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!
11 *
12 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
13 */
14 class TypoScriptTemplateConstantEditorModuleFunctionController extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule {
15
16 /**
17 * Initialize editor
18 *
19 * @param integer $pageId
20 * @param integer $template_uid
21 * @return integer
22 * @todo Define visibility
23 */
24 public function initialize_editor($pageId, $template_uid = 0) {
25 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
26 global $tmpl, $tplRow, $theConstants;
27 $tmpl = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\ExtendedTemplateService');
28 // Defined global here!
29 $tmpl->tt_track = 0;
30 // Do not log time-performance information
31 $tmpl->init();
32 $tmpl->ext_localGfxPrefix = \TYPO3\CMS\Core\Extension\ExtensionManager::extPath('tstemplate_ceditor');
33 $tmpl->ext_localWebGfxPrefix = $GLOBALS['BACK_PATH'] . \TYPO3\CMS\Core\Extension\ExtensionManager::extRelPath('tstemplate_ceditor');
34 // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
35 $tplRow = $tmpl->ext_getFirstTemplate($pageId, $template_uid);
36 // IF there was a template...
37 if (is_array($tplRow)) {
38 // Gets the rootLine
39 $sys_page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
40 $rootLine = $sys_page->getRootLine($pageId);
41 // This generates the constants/config + hierarchy info for the template.
42 $tmpl->runThroughTemplates($rootLine, $template_uid);
43 // The editable constants are returned in an array.
44 $theConstants = $tmpl->generateConfig_constants();
45 // The returned constants are sorted in categories, that goes into the $tmpl->categories array
46 $tmpl->ext_categorizeEditableConstants($theConstants);
47 // This array will contain key=[expanded constantname], value=linenumber in template. (after edit_divider, if any)
48 $tmpl->ext_regObjectPositions($tplRow['constants']);
49 return 1;
50 }
51 }
52
53 /**
54 * Display example
55 *
56 * @param string $theOutput
57 * @return string
58 * @todo Define visibility
59 */
60 public function displayExample($theOutput) {
61 global $tmpl;
62 if (($tmpl->helpConfig['imagetag'] || $tmpl->helpConfig['description']) || $tmpl->helpConfig['header']) {
63 $theOutput .= $this->pObj->doc->spacer(30);
64 $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>'));
65 }
66 return $theOutput;
67 }
68
69 /**
70 * Main
71 *
72 * @return string
73 * @todo Define visibility
74 */
75 public function main() {
76 global $TYPO3_CONF_VARS;
77 global $tmpl, $tplRow, $theConstants;
78 $theOutput = '';
79 // Create extension template
80 $this->pObj->createTemplate($this->pObj->id);
81 // Checking for more than one template an if, set a menu...
82 $manyTemplatesMenu = $this->pObj->templateMenu();
83 $template_uid = 0;
84 if ($manyTemplatesMenu) {
85 $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
86 }
87 // BUGBUG: Should we check if the uset may at all read and write template-records???
88 // initialize
89 $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
90 if ($existTemplate) {
91 $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
92 // Update template ?
93 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'))) {
94 $tmpl->changed = 0;
95 $tmpl->ext_procesInput(\TYPO3\CMS\Core\Utility\GeneralUtility::_POST(), array(), $theConstants, $tplRow);
96 if ($tmpl->changed) {
97 // Set the data to be saved
98 $recData = array();
99 $recData['sys_template'][$saveId]['constants'] = implode($tmpl->raw, LF);
100 // Create new tce-object
101 $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandler\\DataHandler');
102 $tce->stripslashes_values = 0;
103 $tce->start($recData, array());
104 $tce->process_datamap();
105 // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
106 $tce->clear_cacheCmd('all');
107 // re-read the template ...
108 $this->initialize_editor($this->pObj->id, $template_uid);
109 }
110 }
111 // 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.
112 $this->pObj->MOD_MENU['constant_editor_cat'] = $tmpl->ext_getCategoryLabelArray();
113 $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']);
114 // Resetting the menu (stop)
115 $content = (((\TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('sys_template', $tplRow) . '<strong>') . $this->pObj->linkWrapTemplateTitle($tplRow['title'], 'constants')) . '</strong>') . htmlspecialchars((trim($tplRow['sitetitle']) ? (' (' . $tplRow['sitetitle']) . ')' : ''));
116 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('editConstants', TRUE), $content, FALSE, TRUE);
117 if ($manyTemplatesMenu) {
118 $theOutput .= $this->pObj->doc->section('', $manyTemplatesMenu);
119 }
120 $theOutput .= $this->pObj->doc->spacer(10);
121 if (count($this->pObj->MOD_MENU['constant_editor_cat'])) {
122 $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']);
123 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('category', TRUE), ('<NOBR>' . $menu) . '</NOBR>', FALSE);
124 } else {
125 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('noConstants', TRUE), $GLOBALS['LANG']->getLL('noConstantsDescription', TRUE), FALSE, FALSE, 1);
126 }
127 $theOutput .= $this->pObj->doc->spacer(15);
128 // Category and constant editor config:
129 $category = $this->pObj->MOD_SETTINGS['constant_editor_cat'];
130 $tmpl->ext_getTSCE_config($category);
131 $printFields = trim($tmpl->ext_printFields($theConstants, $category));
132 if ($printFields) {
133 $theOutput .= $this->pObj->doc->section('', $printFields);
134 }
135 if ($BE_USER_modOptions['properties']['constantEditor.']['example'] != 'top') {
136 $theOutput = $this->displayExample($theOutput);
137 }
138 } else {
139 $theOutput .= $this->pObj->noTemplate(1);
140 }
141 return $theOutput;
142 }
143
144 }
145
146
147 ?>