00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00031 require_once(PATH_t3lib."class.t3lib_extobjbase.php");
00032
00033 class tx_tstemplateinfo extends t3lib_extobjbase {
00034 function modMenu() {
00035 global $LANG;
00036
00037 return Array (
00038 #"ts_template_editor_TArows" => ""
00039 );
00040 }
00041 function tableRow($label,$data,$field) {
00042 $ret='<tr><td class="bgColor4" width="1%">';
00043 $ret.='<a href="index.php?id='.$this->pObj->id.'&e['.$field.']=1"><img '.t3lib_iconWorks::skinImg($GLOBALS["BACK_PATH"],'gfx/edit2.gif').' width=11 height=12 hspace=3 border=0 title="Edit field"></a>';
00044 $ret.='</td><td class="bgColor4" width="1%"><b>'.$label.' </b></td><td class="bgColor4" width="99%">'.$data.' </td></tr>';
00045 return $ret;
00046 }
00047 function procesResources($resources,$func=0) {
00048 $arr = t3lib_div::trimExplode(",",$resources.",,",1);
00049 $out="";
00050 if ($func) {$bgcol=' class="bgColor4"';} else {$bgcol="";}
00051 while(list($k,$v)=each($arr)) {
00052 $path = PATH_site.$GLOBALS["TCA"]["sys_template"]["columns"]["resources"]["config"]["uploadfolder"]."/".$v;
00053 $functions="";
00054 if ($func) {
00055 $functions='<td bgcolor=red nowrap>Delete: <input type="Checkbox" name="data[remove_resource]['.$k.']" value="'.htmlspecialchars($v).'"></td>';
00056 $functions.='<td'.$bgcol.' nowrap>To top: <input type="Checkbox" name="data[totop_resource]['.$k.']" value="'.htmlspecialchars($v).'"></td>';
00057 $functions.='<td'.$bgcol.' nowrap>';
00058 $fI=t3lib_div::split_fileref($v);
00059 if (t3lib_div::inList($this->pObj->textExtensions,$fI["fileext"])) {
00060 $functions.='<a href="index.php?id='.$this->pObj->id.'&e[file]='.rawurlencode($v).'"><img '.t3lib_iconWorks::skinImg($GLOBALS["BACK_PATH"],'gfx/edit2.gif').' width=11 height=12 hspace=3 border=0 title="Edit file"></a>';
00061 }
00062 $functions.='</td>';
00063 }
00064 $thumb=t3lib_BEfunc::thumbCode(array("resources"=>$v),"sys_template","resources",$GLOBALS["BACK_PATH"],"");
00065 $out.='<tr><td'.$bgcol.' nowrap>'.$v.' </td><td'.$bgcol.' nowrap> '.t3lib_div::formatSize(@filesize($path)).' </td>'.$functions.'<td'.$bgcol.'>'.trim($thumb).'</td></tr>';
00066 }
00067 if ($out) {
00068 if ($func) {
00069 $out = '<table border=0 cellpadding=1 cellspacing=1 width="100%">'.$out.'</table>';
00070 $out='<table border=0 cellpadding=0 cellspacing=0>
00071 <tr><td class="bgColor2">'.$out.'<img src=clear.gif width=465 height=1></td></tr>
00072 </table>';
00073 } else {
00074 $out = '<table border=0 cellpadding=0 cellspacing=0>'.$out.'</table>';
00075 }
00076 }
00077 return $out;
00078 }
00079 function resourceListForCopy($id,$template_uid) {
00080 global $tmpl;
00081 $sys_page = t3lib_div::makeInstance("t3lib_pageSelect");
00082 $rootLine = $sys_page->getRootLine($id);
00083 $tmpl->runThroughTemplates($rootLine,$template_uid);
00084 $theResources = t3lib_div::trimExplode(",",$tmpl->resources,1);
00085 reset($theResources);
00086 while(list($k,$v)=each($theResources)) {
00087 $fI=pathinfo($v);
00088 if (t3lib_div::inList($this->pObj->textExtensions,strtolower($fI["extension"]))) {
00089 $path = PATH_site.$GLOBALS["TCA"]["sys_template"]["columns"]["resources"]["config"]["uploadfolder"]."/".$v;
00090 $thumb=t3lib_BEfunc::thumbCode(array("resources"=>$v),"sys_template","resources",$GLOBALS["BACK_PATH"],"");
00091 $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>';
00092 }
00093 }
00094 $out = $out ? '<table border=0 cellpadding=0 cellspacing=0>'.$out.'</table>' : "";
00095 return $out;
00096 }
00097 function initialize_editor($pageId,$template_uid=0) {
00098
00099 global $tmpl,$tplRow,$theConstants;
00100
00101 $tmpl = t3lib_div::makeInstance("t3lib_tsparser_ext");
00102 $tmpl->tt_track = 0;
00103 $tmpl->init();
00104
00105 $tplRow = $tmpl->ext_getFirstTemplate($pageId,$template_uid);
00106 if (is_array($tplRow)) {
00107 return 1;
00108 }
00109 }
00110 function main() {
00111 global $SOBE,$BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
00112 global $tmpl,$tplRow,$theConstants;
00113
00114 $edit = $this->pObj->edit;
00115 $e = $this->pObj->e;
00116
00117 t3lib_div::loadTCA("sys_template");
00118
00119
00120
00121
00122 $this->pObj->createTemplate($this->pObj->id);
00123
00124
00125
00126
00127
00128 $manyTemplatesMenu = $this->pObj->templateMenu();
00129 $template_uid = 0;
00130 if ($manyTemplatesMenu) {
00131 $template_uid = $this->pObj->MOD_SETTINGS["templatesOnPage"];
00132 }
00133
00134
00135
00136
00137
00138
00139
00140
00141 $existTemplate = $this->initialize_editor($this->pObj->id,$template_uid);
00142 if ($existTemplate) {
00143 $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
00144
00145
00146 $POST = t3lib_div::_POST();
00147 if ($POST["submit"]) {
00148 require_once (PATH_t3lib."class.t3lib_tcemain.php");
00149
00150 $recData=array();
00151 $alternativeFileName=array();
00152 $resList = $tplRow["resources"];
00153
00154 $tmp_upload_name = '';
00155 $tmp_newresource_name = '';
00156
00157 if (is_array($POST["data"])) {
00158 while(list($field,$val)=each($POST["data"])) {
00159 switch($field) {
00160 case "constants":
00161 case "config":
00162 case "title":
00163 case "sitetitle":
00164 case "description":
00165 $recData["sys_template"][$saveId][$field] = $val;
00166 break;
00167 case "resources":
00168 $tmp_upload_name = t3lib_div::upload_to_tempfile($_FILES["resources"]["tmp_name"]);
00169 if ($tmp_upload_name) {
00170 if ($tmp_upload_name!="none" && $_FILES["resources"]["name"]) {
00171 $alternativeFileName[$tmp_upload_name] = trim($_FILES["resources"]["name"]);
00172 $resList = $tmp_upload_name.",".$resList;
00173 }
00174 }
00175 break;
00176 case "new_resource":
00177 $newName = trim(t3lib_div::_GP("new_resource"));
00178 if ($newName) {
00179 $newName.=".".t3lib_div::_GP("new_resource_ext");
00180 $tmp_newresource_name = t3lib_div::tempnam("new_resource_");
00181 $alternativeFileName[$tmp_newresource_name] = $newName;
00182 $resList = $tmp_newresource_name.",".$resList;
00183 }
00184 break;
00185 case "makecopy_resource":
00186 if (is_array($val)) {
00187 reset($val);
00188 $resList=",".$resList.",";
00189 while(list($k,$file)=each($val)) {
00190 $tmp_name = PATH_site.$TCA["sys_template"]["columns"]["resources"]["config"]["uploadfolder"]."/".$file;
00191
00192 $resList = $tmp_name.",".$resList;
00193 }
00194 }
00195 break;
00196 case "remove_resource":
00197 if (is_array($val)) {
00198 reset($val);
00199 $resList=",".$resList.",";
00200 while(list($k,$file)=each($val)) {
00201 $resList = str_replace(",".$file.",", ",", $resList);
00202 }
00203 }
00204 break;
00205 case "totop_resource":
00206 if (is_array($val)) {
00207 reset($val);
00208 $resList=",".$resList.",";
00209 while(list($k,$file)=each($val)) {
00210 $resList = str_replace(",".$file.",", ",", $resList);
00211 $resList = ",".$file.$resList;
00212 }
00213 }
00214
00215 break;
00216 }
00217 }
00218 }
00219 $resList=implode(t3lib_div::trimExplode(",",$resList,1),",");
00220 if (strcmp($resList,$tplRow["resources"])) {
00221 $recData["sys_template"][$saveId]["resources"] = $resList;
00222
00223 }
00224 if (count($recData)) {
00225
00226 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
00227 $tce->stripslashes_values=0;
00228 $tce->alternativeFileName = $alternativeFileName;
00229
00230
00231 $tce->start($recData,Array());
00232
00233 $tce->process_datamap();
00234
00235 $tce->clear_cacheCmd("all");
00236
00237
00238 $this->initialize_editor($this->pObj->id,$template_uid);
00239 }
00240
00241
00242 t3lib_div::unlink_tempfile($tmp_upload_name);
00243 t3lib_div::unlink_tempfile($tmp_newresource_name);
00244
00245
00246 if (is_array($edit)) {
00247 if ($edit["filename"] && $tplRow["resources"] && t3lib_div::inList($tplRow["resources"], $edit["filename"])) {
00248 $path = PATH_site.$TCA["sys_template"]["columns"]["resources"]["config"]["uploadfolder"]."/".$edit["filename"];
00249 $fI=t3lib_div::split_fileref($edit["filename"]);
00250 if (@is_file($path) && t3lib_div::getFileAbsFileName($path) && t3lib_div::inList($this->pObj->textExtensions,$fI["fileext"])) {
00251 if (filesize($path)<(30*1024)) {
00252 t3lib_div::writeFile($path,$edit['file']);
00253
00254 $theOutput.=$this->pObj->doc->spacer(10);
00255 $theOutput.=$this->pObj->doc->section("<font color=red>FILE CHANGED</font>","Resource '".$edit["filename"]."' has been updated.",0,0,0,1);
00256
00257
00258 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
00259 $tce->stripslashes_values=0;
00260 $tce->start(Array(),Array());
00261 $tce->clear_cacheCmd("all");
00262 }
00263 }
00264 }
00265 }
00266 }
00267
00268 $theOutput.=$this->pObj->doc->spacer(5);
00269 $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);
00270 if ($manyTemplatesMenu) {
00271 $theOutput.=$this->pObj->doc->section("",$manyTemplatesMenu);
00272 $theOutput.=$this->pObj->doc->divider(5);
00273 }
00274
00275
00276
00277
00278
00279
00280 #$numberOfRows= t3lib_div::intInRange($this->pObj->MOD_SETTINGS["ts_template_editor_TArows"],0,150);
00281 #if (!$numberOfRows)
00282 $numberOfRows = 35;
00283
00284 if (t3lib_div::_POST('abort')) {unset($e);}
00285
00286 if (is_array($e)) {
00287 $theOutput.=$this->pObj->doc->section("",'<BR><input type="Submit" name="submit" value="Update"> <input type="Submit" name="abort" value="Cancel">');
00288 }
00289 if ($e["title"]) {
00290 $outCode='<input type="Text" name="data[title]" value="'.htmlspecialchars($tplRow[title]).'"'.$this->pObj->doc->formWidth().'>';
00291 $outCode.='<input type="Hidden" name="e[title]" value="1">';
00292 $theOutput.=$this->pObj->doc->spacer(15);
00293 $theOutput.=$this->pObj->doc->section("Title:",$outCode);
00294 }
00295 if ($e["sitetitle"]) {
00296 $outCode='<input type="Text" name="data[sitetitle]" value="'.htmlspecialchars($tplRow[sitetitle]).'"'.$this->pObj->doc->formWidth().'>';
00297 $outCode.='<input type="Hidden" name="e[sitetitle]" value="1">';
00298 $theOutput.=$this->pObj->doc->spacer(15);
00299 $theOutput.=$this->pObj->doc->section("Sitetitle:",$outCode);
00300 }
00301 if ($e["description"]) {
00302 $outCode='<textarea name="data[description]" rows="5" class="fixed-font enable-tab"'.$this->pObj->doc->formWidthText(48,"","").'>'.t3lib_div::formatForTextarea($tplRow[description]).'</textarea>';
00303 $outCode.='<input type="Hidden" name="e[description]" value="1">';
00304 $theOutput.=$this->pObj->doc->spacer(15);
00305 $theOutput.=$this->pObj->doc->section("Description:",$outCode);
00306 }
00307 if ($e["resources"]) {
00308
00309 $outCode='<input type="File" name="resources"'.$this->pObj->doc->formWidth().' size="50">';
00310 $outCode.='<input type="Hidden" name="data[resources]" value="1">';
00311 $outCode.='<input type="Hidden" name="e[resources]" value="1">';
00312 $outCode.='<BR>Allowed extensions: <b>'.$TCA["sys_template"]["columns"]["resources"]["config"]["allowed"].'</b>';
00313 $outCode.='<BR>Max file size: <b>'.t3lib_div::formatSize($TCA["sys_template"]["columns"]["resources"]["config"]["max_size"]*1024).'</b>';
00314 $theOutput.=$this->pObj->doc->spacer(15);
00315 $theOutput.=$this->pObj->doc->section("Upload resource:",$outCode);
00316
00317
00318 $opt=explode(",",$this->pObj->textExtensions);
00319 $optTags="";
00320 while(list(,$extVal)=each($opt)) {
00321 $optTags.='<option value="'.$extVal.'">.'.$extVal.'</option>';
00322 }
00323 $outCode='<input type="text" name="new_resource"'.$this->pObj->doc->formWidth(20).'>
00324 <select name="new_resource_ext">'.$optTags.'</select>';
00325 $outCode.='<input type="Hidden" name="data[new_resource]" value="1">';
00326 $theOutput.=$this->pObj->doc->spacer(15);
00327 $theOutput.=$this->pObj->doc->section("New text resource (enter name):",$outCode);
00328
00329
00330 $rL = $this->resourceListForCopy($this->pObj->id,$template_uid);
00331 if ($rL) {
00332 $theOutput.=$this->pObj->doc->spacer(20);
00333 $theOutput.=$this->pObj->doc->section("Make a copy of resource:",$rL);
00334 }
00335
00336
00337 $rL = $this->procesResources($tplRow["resources"],1);
00338 if ($rL) {
00339 $theOutput.=$this->pObj->doc->spacer(20);
00340 $theOutput.=$this->pObj->doc->section("Update resource list:",$rL);
00341 }
00342 }
00343 if ($e["constants"]) {
00344 $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>';
00345 $outCode.='<input type="Hidden" name="e[constants]" value="1">';
00346 $theOutput.=$this->pObj->doc->spacer(15);
00347 $theOutput.=$this->pObj->doc->section("Constants:","");
00348 $theOutput.=$this->pObj->doc->sectionEnd().$outCode;
00349 }
00350 if ($e["file"]) {
00351 $path = PATH_site.$TCA["sys_template"]["columns"]["resources"]["config"]["uploadfolder"]."/".$e[file];
00352
00353 $fI=t3lib_div::split_fileref($e[file]);
00354 if (@is_file($path) && t3lib_div::inList($this->pObj->textExtensions,$fI["fileext"])) {
00355 if (filesize($path)<($TCA['sys_template']['columns']['resources']['config']['max_size']*1024)) {
00356 $fileContent = t3lib_div::getUrl($path);
00357 $outCode='File: <b>'.$e[file].'</b><BR>';
00358 $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>';
00359 $outCode.='<input type="Hidden" name="edit[filename]" value="'.$e[file].'">';
00360 $outCode.='<input type="Hidden" name="e[file]" value="'.htmlspecialchars($e[file]).'">';
00361 $theOutput.=$this->pObj->doc->spacer(15);
00362 $theOutput.=$this->pObj->doc->section("Edit Resource:","");
00363 $theOutput.=$this->pObj->doc->sectionEnd().$outCode;
00364 } else {
00365 $theOutput.=$this->pObj->doc->spacer(15);
00366 $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);
00367 }
00368 }
00369 }
00370 if ($e["config"]) {
00371 $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>';
00372
00373 if (t3lib_extMgm::isLoaded("tsconfig_help")) {
00374 $url=$BACK_PATH."wizard_tsconfig.php?mode=tsref";
00375 $params=array();
00376 $params["formName"]="editForm";
00377 $params["itemName"]="data[config]";
00378 $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 '.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/wizard_tsconfig.gif').' width="22" height="27" border="0" title="TSref reference"></a>';
00379 }
00380
00381 $outCode.='<input type="Hidden" name="e[config]" value="1">';
00382 $theOutput.=$this->pObj->doc->spacer(15);
00383 $theOutput.=$this->pObj->doc->section("Setup:","");
00384 $theOutput.=$this->pObj->doc->sectionEnd().$outCode;
00385 }
00386 if (is_array($e)) {
00387 $theOutput.=$this->pObj->doc->section("",'<BR><input type="Submit" name="submit" value="Update"> <input type="Submit" name="abort" value="Cancel">');
00388 }
00389
00390
00391
00392 $outCode="";
00393 $outCode.=$this->tableRow("Title:",htmlspecialchars($tplRow["title"]),"title");
00394 $outCode.=$this->tableRow("Sitetitle:",htmlspecialchars($tplRow["sitetitle"]),"sitetitle");
00395 $outCode.=$this->tableRow("Description:",nl2br(htmlspecialchars($tplRow["description"])),"description");
00396 $outCode.=$this->tableRow("Resources:",$this->procesResources($tplRow["resources"]),"resources");
00397 $outCode.=$this->tableRow("Constants:","(edit to view, ".(trim($tplRow[constants]) ? count(explode(chr(10), $tplRow[constants])):0)." lines)","constants");
00398 $outCode.=$this->tableRow("Setup:","(edit to view, ".(trim($tplRow[config]) ? count(explode(chr(10), $tplRow[config])):0)." lines)","config");
00399 $outCode='<table border=0 cellpadding=1 cellspacing=1 width="100%">'.$outCode.'</table>';
00400
00401 $outCode='<table border=0 cellpadding=0 cellspacing=0>
00402 <tr><td class="bgColor2">'.$outCode.'<img src=clear.gif width=465 height=1></td></tr>
00403 </table>';
00404
00405
00406 $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>';
00407
00408 $theOutput.=$this->pObj->doc->spacer(25);
00409 $theOutput.=$this->pObj->doc->section("",$outCode);
00410
00411 $theOutput.=$this->pObj->doc->spacer(10);
00412 $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>
00413 Status: '.$this->pObj->getCountCacheTables(1),0,1);
00414
00415 // $theOutput.=$this->pObj->doc->divider(5);
00416 # $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"]);
00417 # $theOutput.=$this->pObj->doc->section("CONFIG:",$menu,0,1);
00418 } else {
00419 $theOutput.=$this->pObj->noTemplate(1);
00420 }
00421 return $theOutput;
00422 }
00423 }
00424
00425 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate_info/class.tx_tstemplateinfo.php"]) {
00426 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate_info/class.tx_tstemplateinfo.php"]);
00427 }
00428
00429 ?>