Added feature #14465: Make use of the new sprite API through the TYPO3 core (thanks...
[Packages/TYPO3.CMS.git] / typo3 / sysext / tstemplate_ceditor / class.tx_tstemplateceditor.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2009 Kasper Skaarhoj (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 $SOBE,$tmpl;
66 if ($tmpl->helpConfig["imagetag"] || $tmpl->helpConfig["description"] || $tmpl->helpConfig["header"]) {
67 // $theOutput.=$this->pObj->doc->divider(20);
68 $theOutput.=$this->pObj->doc->spacer(30);
69 $theOutput.=$this->pObj->doc->section($tmpl->helpConfig["header"],
70 '<div align="center">'.$tmpl->helpConfig["imagetag"].'</div><BR>'.
71 ($tmpl->helpConfig["description"] ? implode(explode("//",$tmpl->helpConfig["description"]),"<BR>")."<BR>" : "").
72 ($tmpl->helpConfig["bulletlist"] ? "<ul><li>".implode(explode("//",$tmpl->helpConfig["bulletlist"]),"<li>")."</ul>" : "<BR>")
73 );
74 }
75 return $theOutput;
76 }
77
78 function main() {
79 global $SOBE,$BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
80 global $tmpl,$tplRow,$theConstants;
81
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_div::testInt(t3lib_div::_POST('submit_x')) && t3lib_div::testInt(t3lib_div::_POST('submit_y')))) {
114 $tmpl->changed=0;
115 $tmpl->ext_procesInput(t3lib_div::_POST(),$_FILES,$theConstants,$tplRow);
116 // debug($tmpl->changed);
117 // debug($tmpl->raw);
118 // $tmpl->changed=0;
119 if ($tmpl->changed) {
120 // Set the data to be saved
121 $recData=array();
122 $recData["sys_template"][$saveId]["constants"] = implode($tmpl->raw,LF);
123 // Create new tce-object
124 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
125 $tce->stripslashes_values=0;
126 // Initialize
127 $tce->start($recData,Array());
128 // Saved the stuff
129 $tce->process_datamap();
130 // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
131 $tce->clear_cacheCmd("all");
132
133 // re-read the template ...
134 $this->initialize_editor($this->pObj->id,$template_uid);
135 }
136 }
137
138 // Output edit form
139 $tmpl->ext_readDirResources($TYPO3_CONF_VARS["MODS"]["web_ts"]["onlineResourceDir"]);
140 $tmpl->ext_resourceDims();
141
142 // 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.
143 $this->pObj->MOD_MENU["constant_editor_cat"] = $tmpl->ext_getCategoryLabelArray();
144
145 $this->pObj->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->pObj->MOD_MENU, t3lib_div::_GP("SET"), $this->pObj->MCONF["name"]);
146 // Resetting the menu (stop)
147
148 $theOutput.=$this->pObj->doc->spacer(5);
149 $theOutput.=$this->pObj->doc->section($GLOBALS['LANG']->getLL('editConstants', true),t3lib_iconWorks::getSpriteIconForRecord('sys_template', $tplRow).'<b>'.$this->pObj->linkWrapTemplateTitle($tplRow["title"],"constants").'</b>'.htmlspecialchars(trim($tplRow["sitetitle"])?' - ('.$tplRow["sitetitle"].')':''),0,1);
150
151 if ($manyTemplatesMenu) {
152 $theOutput.=$this->pObj->doc->section("",$manyTemplatesMenu);
153 $theOutput.=$this->pObj->doc->divider(5);
154 }
155
156 $theOutput.=$this->pObj->doc->spacer(5);
157 if (count($this->pObj->MOD_MENU["constant_editor_cat"])) {
158 $menu = $GLOBALS['LANG']->getLL('category', true)." ".t3lib_BEfunc::getFuncMenu($this->pObj->id,"SET[constant_editor_cat]",$this->pObj->MOD_SETTINGS["constant_editor_cat"],$this->pObj->MOD_MENU["constant_editor_cat"]);
159 $theOutput.=$this->pObj->doc->section("",'<NOBR>'.$menu.'</NOBR>');
160 } else {
161 $theOutput.=$this->pObj->doc->section($GLOBALS['LANG']->getLL('noConstants', true),$GLOBALS['LANG']->getLL('noConstantsDescription', true),1,0,1);
162 }
163
164
165 // Category and constant editor config:
166 $category = $this->pObj->MOD_SETTINGS["constant_editor_cat"];
167 /* $TSCE_tmpl = t3lib_div::makeInstance("t3lib_tsparser_ext"); // Defined global here!
168 $TSCE_tmpl->tt_track = 0; // Do not log time-performance information
169 $TSCE_tmpl->init();
170 $TSCE_tmpl->constants=array($tplRow["constants"]);
171 debug($tplRow);
172 $TSCE_tmpl->generateConfig_constants();
173 debug($TSCE_tmpl->setup);
174 */
175 $tmpl->ext_getTSCE_config($category);
176
177 # NOT WORKING:
178 if ($BE_USER_modOptions["properties"]["constantEditor."]["example"]=="top") {
179 $theOutput=$this->displayExample($theOutput);
180 }
181
182 $printFields = trim($tmpl->ext_printFields($theConstants,$category));
183 if ($printFields) {
184 $theOutput.=$this->pObj->doc->spacer(20);
185 $theOutput.=$this->pObj->doc->section("",$printFields);
186 }
187
188 if ($BE_USER_modOptions["properties"]["constantEditor."]["example"]!="top") {
189 $theOutput=$this->displayExample($theOutput);
190 }
191 } else {
192 $theOutput.=$this->pObj->noTemplate(1);
193 }
194 return $theOutput;
195 }
196 }
197
198 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate_ceditor/class.tx_tstemplateceditor.php"]) {
199 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate_ceditor/class.tx_tstemplateceditor.php"]);
200 }
201
202 ?>