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 bgcolor="#D9D5C9" width="1%">';
00043 $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>';
00044 $ret.='</td><td bgcolor="#D9D5C9" width="1%"><b>'.$label.' </b></td><td bgcolor="#D9D5C9" 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 src="'.$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
00144
00145 $POST = t3lib_div::_POST();
00146 if ($POST["submit"]) {
00147 require_once (PATH_t3lib."class.t3lib_tcemain.php");
00148
00149 $recData=array();
00150 $alternativeFileName=array();
00151 $resList = $tplRow["resources"];
00152
00153 $tmp_upload_name = '';
00154 $tmp_newresource_name = '';
00155
00156 if (is_array($POST["data"])) {
00157 while(list($field,$val)=each($POST["data"])) {
00158 switch($field) {
00159 case "constants":
00160 case "config":
00161 case "title":
00162 case "sitetitle":
00163 case "description":
00164 $recData["sys_template"][$tplRow[uid]][$field] = $val;
00165 break;
00166 case "resources":
00167 $tmp_upload_name = t3lib_div::upload_to_tempfile($_FILES["resources"]["tmp_name"]);
00168 if ($tmp_upload_name) {
00169 if ($tmp_upload_name!="none" && $_FILES["resources"]["name"]) {
00170 $alternativeFileName[$tmp_upload_name] = trim($_FILES["resources"]["name"]);
00171 $resList = $tmp_upload_name.",".$resList;
00172 }
00173 }
00174 break;
00175 case "new_resource":
00176 $newName = trim(t3lib_div::_GP("new_resource"));
00177 if ($newName) {
00178 $newName.=".".t3lib_div::_GP("new_resource_ext");
00179 $tmp_newresource_name = t3lib_div::tempnam("new_resource_");
00180 $alternativeFileName[$tmp_newresource_name] = $newName;
00181 $resList = $tmp_newresource_name.",".$resList;
00182 }
00183 break;
00184 case "makecopy_resource":
00185 if (is_array($val)) {
00186 reset($val);
00187 $resList=",".$resList.",";
00188 while(list($k,$file)=each($val)) {
00189 $tmp_name = PATH_site.$TCA["sys_template"]["columns"]["resources"]["config"]["uploadfolder"]."/".$file;
00190
00191 $resList = $tmp_name.",".$resList;
00192 }
00193 }
00194 break;
00195 case "remove_resource":
00196 if (is_array($val)) {
00197 reset($val);
00198 $resList=",".$resList.",";
00199 while(list($k,$file)=each($val)) {
00200 $resList = str_replace(",".$file.",", ",", $resList);
00201 }
00202 }
00203 break;
00204 case "totop_resource":
00205 if (is_array($val)) {
00206 reset($val);
00207 $resList=",".$resList.",";
00208 while(list($k,$file)=each($val)) {
00209 $resList = str_replace(",".$file.",", ",", $resList);
00210 $resList = ",".$file.$resList;
00211 }
00212 }
00213
00214 break;
00215 }
00216 }
00217 }
00218 $resList=implode(t3lib_div::trimExplode(",",$resList,1),",");
00219 if (strcmp($resList,$tplRow["resources"])) {
00220 $recData["sys_template"][$tplRow["uid"]]["resources"] = $resList;
00221
00222 }
00223 if (count($recData)) {
00224
00225 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
00226 $tce->stripslashes_values=0;
00227 $tce->alternativeFileName = $alternativeFileName;
00228
00229
00230 $tce->start($recData,Array());
00231
00232 $tce->process_datamap();
00233
00234 $tce->clear_cacheCmd("all");
00235
00236
00237 $this->initialize_editor($this->pObj->id,$template_uid);
00238 }
00239
00240
00241 t3lib_div::unlink_tempfile($tmp_upload_name);
00242 t3lib_div::unlink_tempfile($tmp_newresource_name);
00243
00244
00245 if (is_array($edit)) {
00246 if ($edit["filename"] && $tplRow["resources"] && t3lib_div::inList($tplRow["resources"], $edit["filename"])) {
00247 $path = PATH_site.$TCA["sys_template"]["columns"]["resources"]["config"]["uploadfolder"]."/".$edit["filename"];
00248 $fI=t3lib_div::split_fileref($edit["filename"]);
00249 if (@is_file($path) && t3lib_div::getFileAbsFileName($path) && t3lib_div::inList($this->pObj->textExtensions,$fI["fileext"])) {
00250 if (filesize($path)<(30*1024)) {
00251 t3lib_div::writeFile($path,$edit['file']);
00252
00253 $theOutput.=$this->pObj->doc->spacer(10);
00254 $theOutput.=$this->pObj->doc->section("<font color=red>FILE CHANGED</font>","Resource '".$edit["filename"]."' has been updated.",0,0,0,1);
00255
00256
00257 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
00258 $tce->stripslashes_values=0;
00259 $tce->start(Array(),Array());
00260 $tce->clear_cacheCmd("all");
00261 }
00262 }
00263 }
00264 }
00265 }
00266
00267 $theOutput.=$this->pObj->doc->spacer(5);
00268 $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);
00269 if ($manyTemplatesMenu) {
00270 $theOutput.=$this->pObj->doc->section("",$manyTemplatesMenu);
00271 $theOutput.=$this->pObj->doc->divider(5);
00272 }
00273
00274
00275
00276
00277
00278
00279 #$numberOfRows= t3lib_div::intInRange($this->pObj->MOD_SETTINGS["ts_template_editor_TArows"],0,150);
00280 #if (!$numberOfRows)
00281 $numberOfRows = 35;
00282
00283 if (t3lib_div::_POST('abort')) {unset($e);}
00284
00285 if (is_array($e)) {
00286 $theOutput.=$this->pObj->doc->section("",'<BR><input type="Submit" name="submit" value="Update"> <input type="Submit" name="abort" value="Cancel">');
00287 }
00288 if ($e["title"]) {
00289 $outCode='<input type="Text" name="data[title]" value="'.htmlspecialchars($tplRow[title]).'"'.$this->pObj->doc->formWidth().'>';
00290 $outCode.='<input type="Hidden" name="e[title]" value="1">';
00291 $theOutput.=$this->pObj->doc->spacer(15);
00292 $theOutput.=$this->pObj->doc->section("Title:",$outCode);
00293 }
00294 if ($e["sitetitle"]) {
00295 $outCode='<input type="Text" name="data[sitetitle]" value="'.htmlspecialchars($tplRow[sitetitle]).'"'.$this->pObj->doc->formWidth().'>';
00296 $outCode.='<input type="Hidden" name="e[sitetitle]" value="1">';
00297 $theOutput.=$this->pObj->doc->spacer(15);
00298 $theOutput.=$this->pObj->doc->section("Sitetitle:",$outCode);
00299 }
00300 if ($e["description"]) {
00301 $outCode='<textarea name="data[description]" rows="5" '.$this->pObj->doc->formWidthText(48,"","").'>'.t3lib_div::formatForTextarea($tplRow[description]).'</textarea>';
00302 $outCode.='<input type="Hidden" name="e[description]" value="1">';
00303 $theOutput.=$this->pObj->doc->spacer(15);
00304 $theOutput.=$this->pObj->doc->section("Description:",$outCode);
00305 }
00306 if ($e["resources"]) {
00307
00308 $outCode='<input type="File" name="resources"'.$this->pObj->doc->formWidth().' size="50">';
00309 $outCode.='<input type="Hidden" name="data[resources]" value="1">';
00310 $outCode.='<input type="Hidden" name="e[resources]" value="1">';
00311 $outCode.='<BR>Allowed extensions: <b>'.$TCA["sys_template"]["columns"]["resources"]["config"]["allowed"].'</b>';
00312 $outCode.='<BR>Max file size: <b>'.t3lib_div::formatSize($TCA["sys_template"]["columns"]["resources"]["config"]["max_size"]*1024).'</b>';
00313 $theOutput.=$this->pObj->doc->spacer(15);
00314 $theOutput.=$this->pObj->doc->section("Upload resource:",$outCode);
00315
00316
00317 $opt=explode(",",$this->pObj->textExtensions);
00318 $optTags="";
00319 while(list(,$extVal)=each($opt)) {
00320 $optTags.='<option value="'.$extVal.'">.'.$extVal.'</option>';
00321 }
00322 $outCode='<input type="text" name="new_resource"'.$this->pObj->doc->formWidth(20).'>
00323 <select name="new_resource_ext">'.$optTags.'</select>';
00324 $outCode.='<input type="Hidden" name="data[new_resource]" value="1">';
00325 $theOutput.=$this->pObj->doc->spacer(15);
00326 $theOutput.=$this->pObj->doc->section("New text resource (enter name):",$outCode);
00327
00328
00329 $rL = $this->resourceListForCopy($this->pObj->id,$template_uid);
00330 if ($rL) {
00331 $theOutput.=$this->pObj->doc->spacer(20);
00332 $theOutput.=$this->pObj->doc->section("Make a copy of resource:",$rL);
00333 }
00334
00335
00336 $rL = $this->procesResources($tplRow["resources"],1);
00337 if ($rL) {
00338 $theOutput.=$this->pObj->doc->spacer(20);
00339 $theOutput.=$this->pObj->doc->section("Update resource list:",$rL);
00340 }
00341 }
00342 if ($e["constants"]) {
00343 $outCode='<textarea name="data[constants]" rows="'.$numberOfRows.'" wrap="off"'.$this->pObj->doc->formWidthText(48,"width:98%;height:70%","off").'>'.t3lib_div::formatForTextarea($tplRow["constants"]).'</textarea>';
00344 $outCode.='<input type="Hidden" name="e[constants]" value="1">';
00345 $theOutput.=$this->pObj->doc->spacer(15);
00346 $theOutput.=$this->pObj->doc->section("Constants:","");
00347 $theOutput.=$this->pObj->doc->sectionEnd().$outCode;
00348 }
00349 if ($e["file"]) {
00350 $path = PATH_site.$TCA["sys_template"]["columns"]["resources"]["config"]["uploadfolder"]."/".$e[file];
00351
00352 $fI=t3lib_div::split_fileref($e[file]);
00353 if (@is_file($path) && t3lib_div::inList($this->pObj->textExtensions,$fI["fileext"])) {
00354 if (filesize($path)<(30*1024)) {
00355 $fileContent = t3lib_div::getUrl($path);
00356 $outCode='File: <b>'.$e[file].'</b><BR>';
00357 $outCode.='<textarea name="edit[file]" rows="'.$numberOfRows.'" wrap="off"'.$this->pObj->doc->formWidthText(48,"width:98%;height:70%","off").'>'.t3lib_div::formatForTextarea($fileContent).'</textarea>';
00358 $outCode.='<input type="Hidden" name="edit[filename]" value="'.$e[file].'">';
00359 $outCode.='<input type="Hidden" name="e[file]" value="'.htmlspecialchars($e[file]).'">';
00360 $theOutput.=$this->pObj->doc->spacer(15);
00361 $theOutput.=$this->pObj->doc->section("Edit Resource:","");
00362 $theOutput.=$this->pObj->doc->sectionEnd().$outCode;
00363 } else {
00364 $theOutput.=$this->pObj->doc->spacer(15);
00365 $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);
00366 }
00367 }
00368 }
00369 if ($e["config"]) {
00370 $outCode='<textarea name="data[config]" rows="'.$numberOfRows.'" wrap="off"'.$this->pObj->doc->formWidthText(48,"width:98%;height:70%","off").'>'.t3lib_div::formatForTextarea($tplRow["config"]).'</textarea>';
00371
00372 if (t3lib_extMgm::isLoaded("tsconfig_help")) {
00373 $url=$BACK_PATH."wizard_tsconfig.php?mode=tsref";
00374 $params=array();
00375 $params["formName"]="editForm";
00376 $params["itemName"]="data[config]";
00377 $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>';
00378 }
00379
00380 $outCode.='<input type="Hidden" name="e[config]" value="1">';
00381 $theOutput.=$this->pObj->doc->spacer(15);
00382 $theOutput.=$this->pObj->doc->section("Setup:","");
00383 $theOutput.=$this->pObj->doc->sectionEnd().$outCode;
00384 }
00385 if (is_array($e)) {
00386 $theOutput.=$this->pObj->doc->section("",'<BR><input type="Submit" name="submit" value="Update"> <input type="Submit" name="abort" value="Cancel">');
00387 }
00388
00389
00390
00391 $outCode="";
00392 $outCode.=$this->tableRow("Title:",htmlspecialchars($tplRow["title"]),"title");
00393 $outCode.=$this->tableRow("Sitetitle:",htmlspecialchars($tplRow["sitetitle"]),"sitetitle");
00394 $outCode.=$this->tableRow("Description:",nl2br(htmlspecialchars($tplRow["description"])),"description");
00395 $outCode.=$this->tableRow("Resources:",$this->procesResources($tplRow["resources"]),"resources");
00396 $outCode.=$this->tableRow("Constants:","(edit to view, ".(trim($tplRow[constants]) ? count(explode(chr(10), $tplRow[constants])):0)." lines)","constants");
00397 $outCode.=$this->tableRow("Setup:","(edit to view, ".(trim($tplRow[config]) ? count(explode(chr(10), $tplRow[config])):0)." lines)","config");
00398 $outCode='<table border=0 cellpadding=1 cellspacing=1 width="100%">'.$outCode.'</table>';
00399
00400 $outCode='<table border=0 cellpadding=0 cellspacing=0>
00401 <tr><td class="bgColor2">'.$outCode.'<img src=clear.gif width=465 height=1></td></tr>
00402 </table>';
00403
00404
00405 $outCode.='<BR><a href="#" onClick="'.t3lib_BEfunc::editOnClick("&edit[sys_template][".$tplRow["uid"]."]=edit",$BACK_PATH,"").'"><strong>Click here to edit whole template record</strong></a>';
00406
00407 $theOutput.=$this->pObj->doc->spacer(25);
00408 $theOutput.=$this->pObj->doc->section("",$outCode);
00409
00410 $theOutput.=$this->pObj->doc->spacer(10);
00411 $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>
00412 Status: '.$this->pObj->getCountCacheTables(1),0,1);
00413
00414 // $theOutput.=$this->pObj->doc->divider(5);
00415 # $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"]);
00416 # $theOutput.=$this->pObj->doc->section("CONFIG:",$menu,0,1);
00417 } else {
00418 $theOutput.=$this->pObj->noTemplate(1);
00419 }
00420 return $theOutput;
00421 }
00422 }
00423
00424 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate_info/class.tx_tstemplateinfo.php"]) {
00425 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate_info/class.tx_tstemplateinfo.php"]);
00426 }
00427
00428 ?>