2 /***************************************************************
5 * (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
31 require_once(PATH_t3lib
."class.t3lib_extobjbase.php");
33 class tx_tstemplateinfo
extends t3lib_extobjbase
{
38 #"ts_template_editor_TArows" => ""
41 function tableRow($label,$data,$field) {
42 $ret='<tr><td bgcolor="#D9D5C9" 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 bgcolor="#D9D5C9" width="1%"><b>'.$label.' </b></td><td bgcolor="#D9D5C9" width="99%">'.$data.' </td></tr>';
47 function procesResources($resources,$func=0) {
48 $arr = t3lib_div
::trimExplode(",",$resources.",,",1);
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;
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>';
64 $thumb=t3lib_BEfunc
::thumbCode(array("resources"=>$v),"sys_template","resources",$GLOBALS["BACK_PATH"],"");
65 $out.='<tr><td'.$bgcol.' nowrap>'.$v.' </td><td'.$bgcol.' nowrap> '.t3lib_div
::formatSize(@filesize
($path)).' </td>'.$functions.'<td'.$bgcol.'>'.trim($thumb).'</td></tr>';
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>
74 $out = '<table border=0 cellpadding=0 cellspacing=0>'.$out.'</table>';
79 function resourceListForCopy($id,$template_uid) {
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);
86 while(list($k,$v)=each($theResources)) {
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.' </td><td'.$bgcol.' nowrap> '.t3lib_div
::formatSize(@filesize
($path)).' </td><td'.$bgcol.'>'.trim($thumb).'</td><td><input type="Checkbox" name="data[makecopy_resource]['.$k.']" value="'.htmlspecialchars($v).'"></td></tr>';
94 $out = $out ?
'<table border=0 cellpadding=0 cellspacing=0>'.$out.'</table>' : "";
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;
101 $tmpl = t3lib_div
::makeInstance("t3lib_tsparser_ext"); // Defined global here!
102 $tmpl->tt_track
= 0; // Do not log time-performance information
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)) {
111 global $SOBE,$BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
112 global $tmpl,$tplRow,$theConstants;
114 $edit = $this->pObj
->edit
;
117 t3lib_div
::loadTCA("sys_template");
119 // **************************
120 // Create extension template
121 // **************************
122 $this->pObj
->createTemplate($this->pObj
->id
);
125 // **************************
126 // Checking for more than one template an if, set a menu...
127 // **************************
128 $manyTemplatesMenu = $this->pObj
->templateMenu();
130 if ($manyTemplatesMenu) {
131 $template_uid = $this->pObj
->MOD_SETTINGS
["templatesOnPage"];
138 // **************************
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'];
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
151 $alternativeFileName=array();
152 $resList = $tplRow["resources"];
154 $tmp_upload_name = '';
155 $tmp_newresource_name = ''; // Set this to blank
157 if (is_array($POST["data"])) {
158 while(list($field,$val)=each($POST["data"])) {
165 $recData["sys_template"][$saveId][$field] = $val;
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;
177 $newName = trim(t3lib_div
::_GP("new_resource"));
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;
185 case "makecopy_resource":
186 if (is_array($val)) {
188 $resList=",".$resList.",";
189 while(list($k,$file)=each($val)) {
190 $tmp_name = PATH_site
.$TCA["sys_template"]["columns"]["resources"]["config"]["uploadfolder"]."/".$file;
192 $resList = $tmp_name.",".$resList;
196 case "remove_resource":
197 if (is_array($val)) {
199 $resList=",".$resList.",";
200 while(list($k,$file)=each($val)) {
201 $resList = str_replace(",".$file.",", ",", $resList);
205 case "totop_resource":
206 if (is_array($val)) {
208 $resList=",".$resList.",";
209 while(list($k,$file)=each($val)) {
210 $resList = str_replace(",".$file.",", ",", $resList);
211 $resList = ",".$file.$resList;
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);
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;
231 $tce->start($recData,Array());
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");
237 // re-read the template ...
238 $this->initialize_editor($this->pObj
->id
,$template_uid);
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);
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']);
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);
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");
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);
280 #$numberOfRows= t3lib_div::intInRange($this->pObj->MOD_SETTINGS["ts_template_editor_TArows"],0,150);
284 if (t3lib_div
::_POST('abort')) {unset($e);} // If abort pressed, nothing should be edited.
287 $theOutput.=$this->pObj
->doc
->section("",'<BR><input type="Submit" name="submit" value="Update"> <input type="Submit" name="abort" value="Cancel">');
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);
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);
301 if ($e["description"]) {
302 $outCode='<textarea name="data[description]" rows="5" '.$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);
307 if ($e["resources"]) {
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);
318 $opt=explode(",",$this->pObj
->textExtensions
);
320 while(list(,$extVal)=each($opt)) {
321 $optTags.='<option value="'.$extVal.'">.'.$extVal.'</option>';
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);
330 $rL = $this->resourceListForCopy($this->pObj
->id
,$template_uid);
332 $theOutput.=$this->pObj
->doc
->spacer(20);
333 $theOutput.=$this->pObj
->doc
->section("Make a copy of resource:",$rL);
336 // Update resource list
337 $rL = $this->procesResources($tplRow["resources"],1);
339 $theOutput.=$this->pObj
->doc
->spacer(20);
340 $theOutput.=$this->pObj
->doc
->section("Update resource list:",$rL);
343 if ($e["constants"]) {
344 $outCode='<textarea name="data[constants]" rows="'.$numberOfRows.'" wrap="off"'.$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;
351 $path = PATH_site
.$TCA["sys_template"]["columns"]["resources"]["config"]["uploadfolder"]."/".$e[file
];
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)<(30*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"'.$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;
365 $theOutput.=$this->pObj
->doc
->spacer(15);
366 $theOutput.=$this->pObj
->doc
->section('<font color=red>Filesize exceeded 30 Kbytes</font>','Files larger than 30 KByes are not allowed to be edited.',0,0,0,1);
371 $outCode='<textarea name="data[config]" rows="'.$numberOfRows.'" wrap="off"'.$this->pObj
->doc
->formWidthText(48,"width:98%;height:70%","off").' class="fixed-font">'.t3lib_div
::formatForTextarea($tplRow["config"]).'</textarea>';
373 if (t3lib_extMgm
::isLoaded("tsconfig_help")) {
374 $url=$BACK_PATH."wizard_tsconfig.php?mode=tsref";
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>';
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;
387 $theOutput.=$this->pObj
->doc
->section("",'<BR><input type="Submit" name="submit" value="Update"> <input type="Submit" name="abort" value="Cancel">');
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>';
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>
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>';
408 $theOutput.=$this->pObj
->doc
->spacer(25);
409 $theOutput.=$this->pObj
->doc
->section("",$outCode);
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);
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);
419 $theOutput.=$this->pObj
->noTemplate(1);
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"]);