TYPO3 CMS  TYPO3_6-2
TypoScriptTemplateConstantEditorModuleFunctionController.php
Go to the documentation of this file.
1 <?php
3 
28 
37  public function initialize_editor($pageId, $template_uid = 0) {
38  // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
39  global $tmpl, $tplRow, $theConstants;
40  $tmpl = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\ExtendedTemplateService');
41  // Defined global here!
42  $tmpl->tt_track = 0;
43  // Do not log time-performance information
44  $tmpl->init();
45  $tmpl->ext_localGfxPrefix = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('tstemplate');
46  $tmpl->ext_localWebGfxPrefix = $GLOBALS['BACK_PATH'] . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('tstemplate') . 'Resources/Public/';
47  // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
48  $tplRow = $tmpl->ext_getFirstTemplate($pageId, $template_uid);
49  // IF there was a template...
50  if (is_array($tplRow)) {
51  // Gets the rootLine
52  $sys_page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
53  $rootLine = $sys_page->getRootLine($pageId);
54  // This generates the constants/config + hierarchy info for the template.
55  $tmpl->runThroughTemplates($rootLine, $template_uid);
56  // The editable constants are returned in an array.
57  $theConstants = $tmpl->generateConfig_constants();
58  // The returned constants are sorted in categories, that goes into the $tmpl->categories array
59  $tmpl->ext_categorizeEditableConstants($theConstants);
60  // This array will contain key=[expanded constantname], value=linenumber in template. (after edit_divider, if any)
61  $tmpl->ext_regObjectPositions($tplRow['constants']);
62  return 1;
63  }
64  }
65 
73  public function displayExample($theOutput) {
74  global $tmpl;
75  if ($tmpl->helpConfig['imagetag'] || $tmpl->helpConfig['description'] || $tmpl->helpConfig['header']) {
76  $theOutput .= $this->pObj->doc->spacer(30);
77  $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>'));
78  }
79  return $theOutput;
80  }
81 
88  public function main() {
89  global $TYPO3_CONF_VARS;
90  global $tmpl, $tplRow, $theConstants;
91  $GLOBALS['LANG']->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_ceditor.xlf');
92  $theOutput = '';
93  // Create extension template
94  $this->pObj->createTemplate($this->pObj->id);
95  // Checking for more than one template an if, set a menu...
96  $manyTemplatesMenu = $this->pObj->templateMenu();
97  $template_uid = 0;
98  if ($manyTemplatesMenu) {
99  $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
100  }
101  // BUGBUG: Should we check if the user may at all read and write template-records???
102  // initialize
103  $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
104  if ($existTemplate) {
105  $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
106  // Update template ?
107  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'))) {
108  $tmpl->changed = 0;
109  $tmpl->ext_procesInput(\TYPO3\CMS\Core\Utility\GeneralUtility::_POST(), array(), $theConstants, $tplRow);
110  if ($tmpl->changed) {
111  // Set the data to be saved
112  $recData = array();
113  $recData['sys_template'][$saveId]['constants'] = implode($tmpl->raw, LF);
114  // Create new tce-object
115  $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
116  $tce->stripslashes_values = 0;
117  $tce->start($recData, array());
118  $tce->process_datamap();
119  // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
120  $tce->clear_cacheCmd('all');
121  // re-read the template ...
122  $this->initialize_editor($this->pObj->id, $template_uid);
123  }
124  }
125  // 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.
126  $this->pObj->MOD_MENU['constant_editor_cat'] = $tmpl->ext_getCategoryLabelArray();
127  $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']);
128  // Resetting the menu (stop)
129  $content = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('sys_template', $tplRow) . '<strong>' . $this->pObj->linkWrapTemplateTitle($tplRow['title'], 'constants') . '</strong>' . htmlspecialchars((trim($tplRow['sitetitle']) ? ' (' . $tplRow['sitetitle'] . ')' : ''));
130  $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('editConstants', TRUE), $content, FALSE, TRUE);
131  if ($manyTemplatesMenu) {
132  $theOutput .= $this->pObj->doc->section('', $manyTemplatesMenu);
133  }
134  $theOutput .= $this->pObj->doc->spacer(10);
135  if (count($this->pObj->MOD_MENU['constant_editor_cat'])) {
136  $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']);
137  $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('category', TRUE), '<NOBR>' . $menu . '</NOBR>', FALSE);
138  } else {
139  $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('noConstants', TRUE), $GLOBALS['LANG']->getLL('noConstantsDescription', TRUE), FALSE, FALSE, 1);
140  }
141  $theOutput .= $this->pObj->doc->spacer(15);
142  // Category and constant editor config:
143  $category = $this->pObj->MOD_SETTINGS['constant_editor_cat'];
144  $tmpl->ext_getTSCE_config($category);
145  $printFields = trim($tmpl->ext_printFields($theConstants, $category));
146  if ($printFields) {
147  $theOutput .= $this->pObj->doc->section('', $printFields);
148  }
149  if ($BE_USER_modOptions['properties']['constantEditor.']['example'] != 'top') {
150  $theOutput = $this->displayExample($theOutput);
151  }
152  } else {
153  $theOutput .= $this->pObj->noTemplate(1);
154  }
155  return $theOutput;
156  }
157 
158 }
$TYPO3_CONF_VARS['SYS']['contentTable']
static getSpriteIconForRecord($table, array $row, array $options=array())
static getModuleData($MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='')
static getFuncMenu($mainParams, $elementName, $currentValue, $menuItems, $script='', $addparams='')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]