[TASK] Fix CGL violations against DoubleQuoteUsage
[Packages/TYPO3.CMS.git] / typo3 / sysext / tstemplate_ceditor / class.tx_tstemplateceditor.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * TypoScript Constant editor
29 *
30 * Module Include-file
31 *
32 * localconf-variables:
33 * $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!
34 *
35 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 */
37
38 $GLOBALS['LANG']->includeLLFile('EXT:tstemplate_ceditor/locallang.xml');
39
40 class tx_tstemplateceditor extends t3lib_extobjbase {
41 function initialize_editor($pageId, $template_uid=0) {
42 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
43 global $tmpl,$tplRow,$theConstants;
44
45 $tmpl = t3lib_div::makeInstance('t3lib_tsparser_ext'); // Defined global here!
46 $tmpl->tt_track = 0; // Do not log time-performance information
47 $tmpl->init();
48
49 $tmpl->ext_localGfxPrefix = t3lib_extMgm::extPath('tstemplate_ceditor');
50 $tmpl->ext_localWebGfxPrefix = $GLOBALS['BACK_PATH'] . t3lib_extMgm::extRelPath('tstemplate_ceditor');
51
52 $tplRow = $tmpl->ext_getFirstTemplate($pageId, $template_uid); // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
53 if (is_array($tplRow)) { // IF there was a template...
54 // Gets the rootLine
55 $sys_page = t3lib_div::makeInstance('t3lib_pageSelect');
56 $rootLine = $sys_page->getRootLine($pageId);
57 $tmpl->runThroughTemplates($rootLine, $template_uid); // This generates the constants/config + hierarchy info for the template.
58 $theConstants = $tmpl->generateConfig_constants(); // The editable constants are returned in an array.
59 $tmpl->ext_categorizeEditableConstants($theConstants); // The returned constants are sorted in categories, that goes into the $tmpl->categories array
60 $tmpl->ext_regObjectPositions($tplRow['constants']); // This array will contain key=[expanded constantname], value=linenumber in template. (after edit_divider, if any)
61 return 1;
62 }
63 }
64 function displayExample($theOutput) {
65 global $tmpl;
66 if ($tmpl->helpConfig['imagetag'] || $tmpl->helpConfig['description'] || $tmpl->helpConfig['header']) {
67 $theOutput .= $this->pObj->doc->spacer(30);
68 $theOutput .= $this->pObj->doc->section($tmpl->helpConfig['header'],
69 '<div align="center">' . $tmpl->helpConfig['imagetag'] . '</div><BR>' .
70 ($tmpl->helpConfig['description'] ? implode(explode('//', $tmpl->helpConfig['description']), '<BR>') . '<BR>' : '') .
71 ($tmpl->helpConfig['bulletlist'] ? '<ul><li>' . implode(explode('//', $tmpl->helpConfig['bulletlist']), '<li>') . '</ul>' : '<BR>')
72 );
73 }
74 return $theOutput;
75 }
76
77 function main() {
78 global $TYPO3_CONF_VARS;
79 global $tmpl, $tplRow, $theConstants;
80
81 $theOutput = '';
82
83 // **************************
84 // Create extension template
85 // **************************
86 $this->pObj->createTemplate($this->pObj->id);
87
88
89
90
91 // **************************
92 // Checking for more than one template an if, set a menu...
93 // **************************
94 $manyTemplatesMenu = $this->pObj->templateMenu();
95 $template_uid = 0;
96 if ($manyTemplatesMenu) {
97 $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
98 }
99
100
101
102 // **************************
103 // Main
104 // **************************
105
106 // BUGBUG: Should we check if the uset may at all read and write template-records???
107 $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid); // initialize
108
109 if ($existTemplate) {
110 $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
111
112 // Update template ?
113 if (t3lib_div::_POST('submit') || (t3lib_utility_Math::canBeInterpretedAsInteger(t3lib_div::_POST('submit_x')) && t3lib_utility_Math::canBeInterpretedAsInteger(t3lib_div::_POST('submit_y')))) {
114 $tmpl->changed = 0;
115 $tmpl->ext_procesInput(t3lib_div::_POST(), $_FILES, $theConstants, $tplRow);
116 if ($tmpl->changed) {
117 // Set the data to be saved
118 $recData = array();
119 $recData['sys_template'][$saveId]['constants'] = implode($tmpl->raw, LF);
120 // Create new tce-object
121 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
122 $tce->stripslashes_values = 0;
123 // Initialize
124 $tce->start($recData, Array());
125 // Saved the stuff
126 $tce->process_datamap();
127 // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
128 $tce->clear_cacheCmd('all');
129
130 // re-read the template ...
131 $this->initialize_editor($this->pObj->id, $template_uid);
132 }
133 }
134
135 // Output edit form
136 $tmpl->ext_readDirResources($TYPO3_CONF_VARS['MODS']['web_ts']['onlineResourceDir']);
137 $tmpl->ext_resourceDims();
138
139 // 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.
140 $this->pObj->MOD_MENU['constant_editor_cat'] = $tmpl->ext_getCategoryLabelArray();
141
142 $this->pObj->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->pObj->MOD_MENU, t3lib_div::_GP('SET'), $this->pObj->MCONF['name']);
143 // Resetting the menu (stop)
144
145 $content = t3lib_iconWorks::getSpriteIconForRecord('sys_template', $tplRow) . '<strong>' . $this->pObj->linkWrapTemplateTitle($tplRow['title'], 'constants') . '</strong>' .
146 htmlspecialchars(trim($tplRow['sitetitle']) ? ' (' . $tplRow['sitetitle'] . ')' : '');
147 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('editConstants', TRUE), $content, FALSE, TRUE);
148
149 if ($manyTemplatesMenu) {
150 $theOutput .= $this->pObj->doc->section('', $manyTemplatesMenu);
151 }
152
153 $theOutput .= $this->pObj->doc->spacer(10);
154
155 if (count($this->pObj->MOD_MENU['constant_editor_cat'])) {
156 $menu = t3lib_BEfunc::getFuncMenu($this->pObj->id, 'SET[constant_editor_cat]', $this->pObj->MOD_SETTINGS['constant_editor_cat'], $this->pObj->MOD_MENU['constant_editor_cat']);
157 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('category', TRUE), '<NOBR>' . $menu . '</NOBR>', FALSE);
158 } else {
159 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('noConstants', TRUE), $GLOBALS['LANG']->getLL('noConstantsDescription', TRUE), FALSE, FALSE, 1);
160 }
161 $theOutput .= $this->pObj->doc->spacer(15);
162
163
164 // Category and constant editor config:
165 $category = $this->pObj->MOD_SETTINGS['constant_editor_cat'];
166 $tmpl->ext_getTSCE_config($category);
167
168 // NOT WORKING:
169 if ($BE_USER_modOptions['properties']['constantEditor.']['example'] == 'top') {
170 $theOutput = $this->displayExample($theOutput);
171 }
172
173 $printFields = trim($tmpl->ext_printFields($theConstants, $category));
174 if ($printFields) {
175 $theOutput .= $this->pObj->doc->section('', $printFields);
176 }
177
178 if ($BE_USER_modOptions['properties']['constantEditor.']['example'] != 'top') {
179 $theOutput=$this->displayExample($theOutput);
180 }
181 } else {
182 $theOutput .= $this->pObj->noTemplate(1);
183 }
184 return $theOutput;
185 }
186 }
187 ?>