[!!!][-FEATURE] Remove resources from TypoScript records
[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 $GLOBALS['LANG']->includeLLFile('EXT:tstemplate_ceditor/locallang.xml');
29
30 /**
31 * TypoScript Constant editor
32 *
33 * Module Include-file
34 *
35 * localconf-variables:
36 * $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!
37 *
38 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
39 */
40 class tx_tstemplateceditor extends t3lib_extobjbase {
41 /**
42 * Initialize editor
43 *
44 * @param integer $pageId
45 * @param integer $template_uid
46 * @return integer
47 */
48 function initialize_editor($pageId, $template_uid=0) {
49 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
50 global $tmpl,$tplRow,$theConstants;
51
52 $tmpl = t3lib_div::makeInstance('t3lib_tsparser_ext'); // Defined global here!
53 $tmpl->tt_track = 0; // Do not log time-performance information
54 $tmpl->init();
55
56 $tmpl->ext_localGfxPrefix = t3lib_extMgm::extPath('tstemplate_ceditor');
57 $tmpl->ext_localWebGfxPrefix = $GLOBALS['BACK_PATH'] . t3lib_extMgm::extRelPath('tstemplate_ceditor');
58 // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
59 $tplRow = $tmpl->ext_getFirstTemplate($pageId, $template_uid);
60 // IF there was a template...
61 if (is_array($tplRow)) {
62 // Gets the rootLine
63 $sys_page = t3lib_div::makeInstance('t3lib_pageSelect');
64 $rootLine = $sys_page->getRootLine($pageId);
65 // This generates the constants/config + hierarchy info for the template.
66 $tmpl->runThroughTemplates($rootLine, $template_uid);
67 // The editable constants are returned in an array.
68 $theConstants = $tmpl->generateConfig_constants();
69 // The returned constants are sorted in categories, that goes into the $tmpl->categories array
70 $tmpl->ext_categorizeEditableConstants($theConstants);
71 // This array will contain key=[expanded constantname], value=linenumber in template. (after edit_divider, if any)
72 $tmpl->ext_regObjectPositions($tplRow['constants']);
73 return 1;
74 }
75 }
76
77 /**
78 * Display example
79 *
80 * @param string $theOutput
81 * @return string
82 */
83 function displayExample($theOutput) {
84 global $tmpl;
85 if ($tmpl->helpConfig['imagetag'] || $tmpl->helpConfig['description'] || $tmpl->helpConfig['header']) {
86 $theOutput .= $this->pObj->doc->spacer(30);
87 $theOutput .= $this->pObj->doc->section($tmpl->helpConfig['header'],
88 '<div align="center">' . $tmpl->helpConfig['imagetag'] . '</div><BR>' .
89 ($tmpl->helpConfig['description'] ? implode(explode('//', $tmpl->helpConfig['description']), '<BR>') . '<BR>' : '') .
90 ($tmpl->helpConfig['bulletlist'] ? '<ul><li>' . implode(explode('//', $tmpl->helpConfig['bulletlist']), '<li>') . '</ul>' : '<BR>')
91 );
92 }
93 return $theOutput;
94 }
95
96 /**
97 * Main
98 *
99 * @return string
100 */
101 function main() {
102 global $TYPO3_CONF_VARS;
103 global $tmpl, $tplRow, $theConstants;
104
105 $theOutput = '';
106
107 // Create extension template
108 $this->pObj->createTemplate($this->pObj->id);
109
110 // Checking for more than one template an if, set a menu...
111 $manyTemplatesMenu = $this->pObj->templateMenu();
112 $template_uid = 0;
113 if ($manyTemplatesMenu) {
114 $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
115 }
116
117 // BUGBUG: Should we check if the uset may at all read and write template-records???
118 // initialize
119 $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
120
121 if ($existTemplate) {
122 $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
123
124 // Update template ?
125 if (t3lib_div::_POST('submit') || (t3lib_utility_Math::canBeInterpretedAsInteger(t3lib_div::_POST('submit_x')) && t3lib_utility_Math::canBeInterpretedAsInteger(t3lib_div::_POST('submit_y')))) {
126 $tmpl->changed = 0;
127 $tmpl->ext_procesInput(t3lib_div::_POST(), array(), $theConstants, $tplRow);
128 if ($tmpl->changed) {
129 // Set the data to be saved
130 $recData = array();
131 $recData['sys_template'][$saveId]['constants'] = implode($tmpl->raw, LF);
132 // Create new tce-object
133 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
134 $tce->stripslashes_values = 0;
135 $tce->start($recData, Array());
136 $tce->process_datamap();
137 // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
138 $tce->clear_cacheCmd('all');
139
140 // re-read the template ...
141 $this->initialize_editor($this->pObj->id, $template_uid);
142 }
143 }
144
145 // 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.
146 $this->pObj->MOD_MENU['constant_editor_cat'] = $tmpl->ext_getCategoryLabelArray();
147
148 $this->pObj->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->pObj->MOD_MENU, t3lib_div::_GP('SET'), $this->pObj->MCONF['name']);
149 // Resetting the menu (stop)
150
151 $content = t3lib_iconWorks::getSpriteIconForRecord('sys_template', $tplRow) . '<strong>' . $this->pObj->linkWrapTemplateTitle($tplRow['title'], 'constants') . '</strong>' .
152 htmlspecialchars(trim($tplRow['sitetitle']) ? ' (' . $tplRow['sitetitle'] . ')' : '');
153 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('editConstants', TRUE), $content, FALSE, TRUE);
154
155 if ($manyTemplatesMenu) {
156 $theOutput .= $this->pObj->doc->section('', $manyTemplatesMenu);
157 }
158
159 $theOutput .= $this->pObj->doc->spacer(10);
160
161 if (count($this->pObj->MOD_MENU['constant_editor_cat'])) {
162 $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']);
163 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('category', TRUE), '<NOBR>' . $menu . '</NOBR>', FALSE);
164 } else {
165 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('noConstants', TRUE), $GLOBALS['LANG']->getLL('noConstantsDescription', TRUE), FALSE, FALSE, 1);
166 }
167 $theOutput .= $this->pObj->doc->spacer(15);
168
169
170 // Category and constant editor config:
171 $category = $this->pObj->MOD_SETTINGS['constant_editor_cat'];
172 $tmpl->ext_getTSCE_config($category);
173
174 $printFields = trim($tmpl->ext_printFields($theConstants, $category));
175 if ($printFields) {
176 $theOutput .= $this->pObj->doc->section('', $printFields);
177 }
178
179 if ($BE_USER_modOptions['properties']['constantEditor.']['example'] != 'top') {
180 $theOutput=$this->displayExample($theOutput);
181 }
182 } else {
183 $theOutput .= $this->pObj->noTemplate(1);
184 }
185 return $theOutput;
186 }
187 }
188 ?>