Template tools (Web>Template) had hard-coded background colours
[Packages/TYPO3.CMS.git] / typo3 / sysext / tstemplate_info / class.tx_tstemplateinfo.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 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 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
29 */
30
31 require_once(PATH_t3lib."class.t3lib_extobjbase.php");
32
33 class tx_tstemplateinfo extends t3lib_extobjbase {
34 function modMenu() {
35 global $LANG;
36
37 return Array (
38 #"ts_template_editor_TArows" => ""
39 );
40 }
41 function tableRow($label,$data,$field) {
42 $ret='<tr><td class="bgColor4" width="1%">';
43 $ret.='<a href="index.php?id='.$this->pObj->id.'&e['.$field.']=1"><img src="'.$GLOBALS["BACK_PATH"].'gfx/edit2.gif" width=11 height=12 hspace=3 border=0 title="Edit field"></a>';
44 $ret.='</td><td class="bgColor4" width="1%"><b>'.$label.'&nbsp;&nbsp;</b></td><td class="bgColor4" width="99%">'.$data.'&nbsp;</td></tr>';
45 return $ret;
46 }
47 function procesResources($resources,$func=0) {
48 $arr = t3lib_div::trimExplode(",",$resources.",,",1);
49 $out="";
50 if ($func) {$bgcol=' class="bgColor4"';} else {$bgcol="";}
51 while(list($k,$v)=each($arr)) {
52 $path = PATH_site.$GLOBALS["TCA"]["sys_template"]["columns"]["resources"]["config"]["uploadfolder"]."/".$v;
53 $functions="";
54 if ($func) {
55 $functions='<td bgcolor=red nowrap>Delete: <input type="Checkbox" name="data[remove_resource]['.$k.']" value="'.htmlspecialchars($v).'"></td>';
56 $functions.='<td'.$bgcol.' nowrap>To top: <input type="Checkbox" name="data[totop_resource]['.$k.']" value="'.htmlspecialchars($v).'"></td>';
57 $functions.='<td'.$bgcol.' nowrap>';
58 $fI=t3lib_div::split_fileref($v);
59 if (t3lib_div::inList($this->pObj->textExtensions,$fI["fileext"])) {
60 $functions.='<a href="index.php?id='.$this->pObj->id.'&e[file]='.rawurlencode($v).'"><img src="'.$GLOBALS["BACK_PATH"].'gfx/edit2.gif" width=11 height=12 hspace=3 border=0 title="Edit file"></a>';
61 }
62 $functions.='</td>';
63 }
64 $thumb=t3lib_BEfunc::thumbCode(array("resources"=>$v),"sys_template","resources",$GLOBALS["BACK_PATH"],"");
65 $out.='<tr><td'.$bgcol.' nowrap>'.$v.'&nbsp;&nbsp;</td><td'.$bgcol.' nowrap>&nbsp;'.t3lib_div::formatSize(@filesize($path)).'&nbsp;</td>'.$functions.'<td'.$bgcol.'>'.trim($thumb).'</td></tr>';
66 }
67 if ($out) {
68 if ($func) {
69 $out = '<table border=0 cellpadding=1 cellspacing=1 width="100%">'.$out.'</table>';
70 $out='<table border=0 cellpadding=0 cellspacing=0>
71 <tr><td class="bgColor2">'.$out.'<img src=clear.gif width=465 height=1></td></tr>
72 </table>';
73 } else {
74 $out = '<table border=0 cellpadding=0 cellspacing=0>'.$out.'</table>';
75 }
76 }
77 return $out;
78 }
79 function resourceListForCopy($id,$template_uid) {
80 global $tmpl;
81 $sys_page = t3lib_div::makeInstance("t3lib_pageSelect");
82 $rootLine = $sys_page->getRootLine($id);
83 $tmpl->runThroughTemplates($rootLine,$template_uid); // This generates the constants/config + hierarchy info for the template.
84 $theResources = t3lib_div::trimExplode(",",$tmpl->resources,1);
85 reset($theResources);
86 while(list($k,$v)=each($theResources)) {
87 $fI=pathinfo($v);
88 if (t3lib_div::inList($this->pObj->textExtensions,strtolower($fI["extension"]))) {
89 $path = PATH_site.$GLOBALS["TCA"]["sys_template"]["columns"]["resources"]["config"]["uploadfolder"]."/".$v;
90 $thumb=t3lib_BEfunc::thumbCode(array("resources"=>$v),"sys_template","resources",$GLOBALS["BACK_PATH"],"");
91 $out.='<tr><td'.$bgcol.' nowrap>'.$v.'&nbsp;&nbsp;</td><td'.$bgcol.' nowrap>&nbsp;'.t3lib_div::formatSize(@filesize($path)).'&nbsp;</td><td'.$bgcol.'>'.trim($thumb).'</td><td><input type="Checkbox" name="data[makecopy_resource]['.$k.']" value="'.htmlspecialchars($v).'"></td></tr>';
92 }
93 }
94 $out = $out ? '<table border=0 cellpadding=0 cellspacing=0>'.$out.'</table>' : "";
95 return $out;
96 }
97 function initialize_editor($pageId,$template_uid=0) {
98 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
99 global $tmpl,$tplRow,$theConstants;
100
101 $tmpl = t3lib_div::makeInstance("t3lib_tsparser_ext"); // Defined global here!
102 $tmpl->tt_track = 0; // Do not log time-performance information
103 $tmpl->init();
104
105 $tplRow = $tmpl->ext_getFirstTemplate($pageId,$template_uid); // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
106 if (is_array($tplRow)) {
107 return 1;
108 }
109 }
110 function main() {
111 global $SOBE,$BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
112 global $tmpl,$tplRow,$theConstants;
113
114 $edit = $this->pObj->edit;
115 $e = $this->pObj->e;
116
117 t3lib_div::loadTCA("sys_template");
118
119 // **************************
120 // Create extension template
121 // **************************
122 $this->pObj->createTemplate($this->pObj->id);
123
124
125 // **************************
126 // Checking for more than one template an if, set a menu...
127 // **************************
128 $manyTemplatesMenu = $this->pObj->templateMenu();
129 $template_uid = 0;
130 if ($manyTemplatesMenu) {
131 $template_uid = $this->pObj->MOD_SETTINGS["templatesOnPage"];
132 }
133
134
135
136
137
138 // **************************
139 // Initialize
140 // **************************
141 $existTemplate = $this->initialize_editor($this->pObj->id,$template_uid); // initialize
142 if ($existTemplate) {
143 $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
144
145 // Update template ?
146 $POST = t3lib_div::_POST();
147 if ($POST["submit"]) {
148 require_once (PATH_t3lib."class.t3lib_tcemain.php");
149 // Set the data to be saved
150 $recData=array();
151 $alternativeFileName=array();
152 $resList = $tplRow["resources"];
153
154 $tmp_upload_name = '';
155 $tmp_newresource_name = ''; // Set this to blank
156
157 if (is_array($POST["data"])) {
158 while(list($field,$val)=each($POST["data"])) {
159 switch($field) {
160 case "constants":
161 case "config":
162 case "title":
163 case "sitetitle":
164 case "description":
165 $recData["sys_template"][$saveId][$field] = $val;
166 break;
167 case "resources":
168 $tmp_upload_name = t3lib_div::upload_to_tempfile($_FILES["resources"]["tmp_name"]); // If there is an uploaded file, move it for the sake of safe_mode.
169 if ($tmp_upload_name) {
170 if ($tmp_upload_name!="none" && $_FILES["resources"]["name"]) {
171 $alternativeFileName[$tmp_upload_name] = trim($_FILES["resources"]["name"]);
172 $resList = $tmp_upload_name.",".$resList;
173 }
174 }
175 break;
176 case "new_resource":
177 $newName = trim(t3lib_div::_GP("new_resource"));
178 if ($newName) {
179 $newName.=".".t3lib_div::_GP("new_resource_ext");
180 $tmp_newresource_name = t3lib_div::tempnam("new_resource_");
181 $alternativeFileName[$tmp_newresource_name] = $newName;
182 $resList = $tmp_newresource_name.",".$resList;
183 }
184 break;
185 case "makecopy_resource":
186 if (is_array($val)) {
187 reset($val);
188 $resList=",".$resList.",";
189 while(list($k,$file)=each($val)) {
190 $tmp_name = PATH_site.$TCA["sys_template"]["columns"]["resources"]["config"]["uploadfolder"]."/".$file;
191 // debug($tmp_name);
192 $resList = $tmp_name.",".$resList;
193 }
194 }
195 break;
196 case "remove_resource":
197 if (is_array($val)) {
198 reset($val);
199 $resList=",".$resList.",";
200 while(list($k,$file)=each($val)) {
201 $resList = str_replace(",".$file.",", ",", $resList);
202 }
203 }
204 break;
205 case "totop_resource":
206 if (is_array($val)) {
207 reset($val);
208 $resList=",".$resList.",";
209 while(list($k,$file)=each($val)) {
210 $resList = str_replace(",".$file.",", ",", $resList);
211 $resList = ",".$file.$resList;
212 }
213 }
214 // debug($resList);
215 break;
216 }
217 }
218 }
219 $resList=implode(t3lib_div::trimExplode(",",$resList,1),",");
220 if (strcmp($resList,$tplRow["resources"])) {
221 $recData["sys_template"][$saveId]["resources"] = $resList;
222 // debug("update resource - ".$resList);
223 }
224 if (count($recData)) {
225 // Create new tce-object
226 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
227 $tce->stripslashes_values=0;
228 $tce->alternativeFileName = $alternativeFileName;
229 // Initialize
230 // debug($recData);
231 $tce->start($recData,Array());
232 // Saved the stuff
233 $tce->process_datamap();
234 // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
235 $tce->clear_cacheCmd("all");
236
237 // re-read the template ...
238 $this->initialize_editor($this->pObj->id,$template_uid);
239 }
240
241 // Unlink any uploaded/new temp files there was:
242 t3lib_div::unlink_tempfile($tmp_upload_name);
243 t3lib_div::unlink_tempfile($tmp_newresource_name);
244
245 // If files has been edited:
246 if (is_array($edit)) {
247 if ($edit["filename"] && $tplRow["resources"] && t3lib_div::inList($tplRow["resources"], $edit["filename"])) { // Check if there are resources, and that the file is in the resourcelist.
248 $path = PATH_site.$TCA["sys_template"]["columns"]["resources"]["config"]["uploadfolder"]."/".$edit["filename"];
249 $fI=t3lib_div::split_fileref($edit["filename"]);
250 if (@is_file($path) && t3lib_div::getFileAbsFileName($path) && t3lib_div::inList($this->pObj->textExtensions,$fI["fileext"])) { // checks that have already been done.. Just to make sure
251 if (filesize($path)<(30*1024)) { // checks that have already been done.. Just to make sure
252 t3lib_div::writeFile($path,$edit['file']);
253
254 $theOutput.=$this->pObj->doc->spacer(10);
255 $theOutput.=$this->pObj->doc->section("<font color=red>FILE CHANGED</font>","Resource '".$edit["filename"]."' has been updated.",0,0,0,1);
256
257 // Clear cache - the file has probably affected the template setup
258 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
259 $tce->stripslashes_values=0;
260 $tce->start(Array(),Array());
261 $tce->clear_cacheCmd("all");
262 }
263 }
264 }
265 }
266 }
267
268 $theOutput.=$this->pObj->doc->spacer(5);
269 $theOutput.=$this->pObj->doc->section("Template information:",'<img src="'.$BACK_PATH.t3lib_iconWorks::getIcon("sys_template",$tplRow).'" width=18 height=16 align=top><b>'.htmlspecialchars($tplRow["title"]).'</b>'.htmlspecialchars(trim($tplRow["sitetitle"])?' - ('.$tplRow["sitetitle"].')':''),0,1);
270 if ($manyTemplatesMenu) {
271 $theOutput.=$this->pObj->doc->section("",$manyTemplatesMenu);
272 $theOutput.=$this->pObj->doc->divider(5);
273 }
274
275 /* $e[constants]=1;
276 $e[config]=1;
277 $e[title]=1;
278 $e[sitetitle]=1;
279 */
280 #$numberOfRows= t3lib_div::intInRange($this->pObj->MOD_SETTINGS["ts_template_editor_TArows"],0,150);
281 #if (!$numberOfRows)
282 $numberOfRows = 35;
283
284 if (t3lib_div::_POST('abort')) {unset($e);} // If abort pressed, nothing should be edited.
285
286 if (is_array($e)) {
287 $theOutput.=$this->pObj->doc->section("",'<BR><input type="Submit" name="submit" value="Update"> <input type="Submit" name="abort" value="Cancel">');
288 }
289 if ($e["title"]) {
290 $outCode='<input type="Text" name="data[title]" value="'.htmlspecialchars($tplRow[title]).'"'.$this->pObj->doc->formWidth().'>';
291 $outCode.='<input type="Hidden" name="e[title]" value="1">';
292 $theOutput.=$this->pObj->doc->spacer(15);
293 $theOutput.=$this->pObj->doc->section("Title:",$outCode);
294 }
295 if ($e["sitetitle"]) {
296 $outCode='<input type="Text" name="data[sitetitle]" value="'.htmlspecialchars($tplRow[sitetitle]).'"'.$this->pObj->doc->formWidth().'>';
297 $outCode.='<input type="Hidden" name="e[sitetitle]" value="1">';
298 $theOutput.=$this->pObj->doc->spacer(15);
299 $theOutput.=$this->pObj->doc->section("Sitetitle:",$outCode);
300 }
301 if ($e["description"]) {
302 $outCode='<textarea name="data[description]" rows="5" class="fixed-font enable-tab"'.$this->pObj->doc->formWidthText(48,"","").'>'.t3lib_div::formatForTextarea($tplRow[description]).'</textarea>';
303 $outCode.='<input type="Hidden" name="e[description]" value="1">';
304 $theOutput.=$this->pObj->doc->spacer(15);
305 $theOutput.=$this->pObj->doc->section("Description:",$outCode);
306 }
307 if ($e["resources"]) {
308 // Upload
309 $outCode='<input type="File" name="resources"'.$this->pObj->doc->formWidth().' size="50">';
310 $outCode.='<input type="Hidden" name="data[resources]" value="1">';
311 $outCode.='<input type="Hidden" name="e[resources]" value="1">';
312 $outCode.='<BR>Allowed extensions: <b>'.$TCA["sys_template"]["columns"]["resources"]["config"]["allowed"].'</b>';
313 $outCode.='<BR>Max file size: <b>'.t3lib_div::formatSize($TCA["sys_template"]["columns"]["resources"]["config"]["max_size"]*1024).'</b>';
314 $theOutput.=$this->pObj->doc->spacer(15);
315 $theOutput.=$this->pObj->doc->section("Upload resource:",$outCode);
316
317 // New
318 $opt=explode(",",$this->pObj->textExtensions);
319 $optTags="";
320 while(list(,$extVal)=each($opt)) {
321 $optTags.='<option value="'.$extVal.'">.'.$extVal.'</option>';
322 }
323 $outCode='<input type="text" name="new_resource"'.$this->pObj->doc->formWidth(20).'>
324 <select name="new_resource_ext">'.$optTags.'</select>';
325 $outCode.='<input type="Hidden" name="data[new_resource]" value="1">';
326 $theOutput.=$this->pObj->doc->spacer(15);
327 $theOutput.=$this->pObj->doc->section("New text resource (enter name):",$outCode);
328
329 // Make copy
330 $rL = $this->resourceListForCopy($this->pObj->id,$template_uid);
331 if ($rL) {
332 $theOutput.=$this->pObj->doc->spacer(20);
333 $theOutput.=$this->pObj->doc->section("Make a copy of resource:",$rL);
334 }
335
336 // Update resource list
337 $rL = $this->procesResources($tplRow["resources"],1);
338 if ($rL) {
339 $theOutput.=$this->pObj->doc->spacer(20);
340 $theOutput.=$this->pObj->doc->section("Update resource list:",$rL);
341 }
342 }
343 if ($e["constants"]) {
344 $outCode='<textarea name="data[constants]" rows="'.$numberOfRows.'" wrap="off" class="fixed-font enable-tab"'.$this->pObj->doc->formWidthText(48,"width:98%;height:70%","off").' class="fixed-font">'.t3lib_div::formatForTextarea($tplRow["constants"]).'</textarea>';
345 $outCode.='<input type="Hidden" name="e[constants]" value="1">';
346 $theOutput.=$this->pObj->doc->spacer(15);
347 $theOutput.=$this->pObj->doc->section("Constants:","");
348 $theOutput.=$this->pObj->doc->sectionEnd().$outCode;
349 }
350 if ($e["file"]) {
351 $path = PATH_site.$TCA["sys_template"]["columns"]["resources"]["config"]["uploadfolder"]."/".$e[file];
352
353 $fI=t3lib_div::split_fileref($e[file]);
354 if (@is_file($path) && t3lib_div::inList($this->pObj->textExtensions,$fI["fileext"])) {
355 if (filesize($path)<($TCA['sys_template']['columns']['resources']['config']['max_size']*1024)) {
356 $fileContent = t3lib_div::getUrl($path);
357 $outCode='File: <b>'.$e[file].'</b><BR>';
358 $outCode.='<textarea name="edit[file]" rows="'.$numberOfRows.'" wrap="off" class="fixed-font enable-tab"'.$this->pObj->doc->formWidthText(48,"width:98%;height:70%","off").' class="fixed-font">'.t3lib_div::formatForTextarea($fileContent).'</textarea>';
359 $outCode.='<input type="Hidden" name="edit[filename]" value="'.$e[file].'">';
360 $outCode.='<input type="Hidden" name="e[file]" value="'.htmlspecialchars($e[file]).'">';
361 $theOutput.=$this->pObj->doc->spacer(15);
362 $theOutput.=$this->pObj->doc->section("Edit Resource:","");
363 $theOutput.=$this->pObj->doc->sectionEnd().$outCode;
364 } else {
365 $theOutput.=$this->pObj->doc->spacer(15);
366 $theOutput.=$this->pObj->doc->section('<font color=red>Filesize exceeded '.$TCA['sys_template']['columns']['resources']['config']['max_size'].' Kbytes</font>','Files larger than '.$TCA['sys_template']['columns']['resources']['config']['max_size'].' KByes are not allowed to be edited.',0,0,0,1);
367 }
368 }
369 }
370 if ($e["config"]) {
371 $outCode='<textarea name="data[config]" rows="'.$numberOfRows.'" wrap="off" class="fixed-font enable-tab"'.$this->pObj->doc->formWidthText(48,"width:98%;height:70%","off").' class="fixed-font">'.t3lib_div::formatForTextarea($tplRow["config"]).'</textarea>';
372
373 if (t3lib_extMgm::isLoaded("tsconfig_help")) {
374 $url=$BACK_PATH."wizard_tsconfig.php?mode=tsref";
375 $params=array();
376 $params["formName"]="editForm";
377 $params["itemName"]="data[config]";
378 $outCode.='<a href="#" onClick="vHWin=window.open(\''.$url.t3lib_div::implodeArrayForUrl("",array("P"=>$params)).'\',\'popUp'.$md5ID.'\',\'height=500,width=780,status=0,menubar=0,scrollbars=1\');vHWin.focus();return false;"><img src="'.$BACK_PATH.'gfx/wizard_tsconfig.gif" width="22" height="27" border="0" title="TSref reference"></a>';
379 }
380
381 $outCode.='<input type="Hidden" name="e[config]" value="1">';
382 $theOutput.=$this->pObj->doc->spacer(15);
383 $theOutput.=$this->pObj->doc->section("Setup:","");
384 $theOutput.=$this->pObj->doc->sectionEnd().$outCode;
385 }
386 if (is_array($e)) {
387 $theOutput.=$this->pObj->doc->section("",'<BR><input type="Submit" name="submit" value="Update"> <input type="Submit" name="abort" value="Cancel">');
388 }
389
390 // Processing:
391 // debug($tplRow);
392 $outCode="";
393 $outCode.=$this->tableRow("Title:",htmlspecialchars($tplRow["title"]),"title");
394 $outCode.=$this->tableRow("Sitetitle:",htmlspecialchars($tplRow["sitetitle"]),"sitetitle");
395 $outCode.=$this->tableRow("Description:",nl2br(htmlspecialchars($tplRow["description"])),"description");
396 $outCode.=$this->tableRow("Resources:",$this->procesResources($tplRow["resources"]),"resources");
397 $outCode.=$this->tableRow("Constants:","(edit to view, ".(trim($tplRow[constants]) ? count(explode(chr(10), $tplRow[constants])):0)." lines)","constants");
398 $outCode.=$this->tableRow("Setup:","(edit to view, ".(trim($tplRow[config]) ? count(explode(chr(10), $tplRow[config])):0)." lines)","config");
399 $outCode='<table border=0 cellpadding=1 cellspacing=1 width="100%">'.$outCode.'</table>';
400
401 $outCode='<table border=0 cellpadding=0 cellspacing=0>
402 <tr><td class="bgColor2">'.$outCode.'<img src=clear.gif width=465 height=1></td></tr>
403 </table>';
404
405 // Edit all icon:
406 $outCode.='<BR><a href="#" onClick="'.t3lib_BEfunc::editOnClick(rawurlencode('&createExtension=0').'&edit[sys_template]['.$tplRow['uid'].']=edit',$BACK_PATH,'').'"><strong>Click here to edit whole template record</strong></a>';
407
408 $theOutput.=$this->pObj->doc->spacer(25);
409 $theOutput.=$this->pObj->doc->section("",$outCode);
410
411 $theOutput.=$this->pObj->doc->spacer(10);
412 $theOutput.=$this->pObj->doc->section("Cache",'Click here to <a href="index.php?id='.$this->pObj->id.'&clear_all_cache=1"><strong>clear all cache</strong></a>.<BR><br>
413 Status: '.$this->pObj->getCountCacheTables(1),0,1);
414
415 // $theOutput.=$this->pObj->doc->divider(5);
416 # $menu = htmlspecialchars("Rows in <TEXTAREA> fields: ").t3lib_BEfunc::getFuncInput($this->pObj->id,"SET[ts_template_editor_TArows]",$this->pObj->MOD_SETTINGS["ts_template_editor_TArows"]);
417 # $theOutput.=$this->pObj->doc->section("CONFIG:",$menu,0,1);
418 } else {
419 $theOutput.=$this->pObj->noTemplate(1);
420 }
421 return $theOutput;
422 }
423 }
424
425 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate_info/class.tx_tstemplateinfo.php"]) {
426 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate_info/class.tx_tstemplateinfo.php"]);
427 }
428
429 ?>