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
00090 require_once(PATH_t3lib."class.t3lib_tstemplate.php");
00091
00092
00093
00094
00095
00096
00097
00105 class t3lib_tsparser_ext extends t3lib_TStemplate {
00106
00107 var $edit_divider = "###MOD_TS:EDITABLE_CONSTANTS###";
00108 var $HTMLcolorList = "aqua,black,blue,fuchsia,gray,green,lime,maroon,navy,olive,purple,red,silver,teal,yellow,white";
00109
00110
00111 var $categories = array(
00112 "basic" => array(),
00113 "menu" => array(),
00114 "content" => array(),
00115 "page" => array(),
00116 "advanced" => array(),
00117 "all" => array()
00118 );
00119 var $subCategories = array(
00120
00121 "enable" => Array("Enable features", "a"),
00122 "dims" => Array("Dimensions, widths, heights, pixels", "b"),
00123 "file" => Array("Files", "c"),
00124 "typo" => Array("Typography", "d"),
00125 "color" => Array("Colors", "e"),
00126 "links" => Array("Links and targets", "f"),
00127 "language" => Array("Language specific constants", "g"),
00128
00129
00130 "cheader" => Array("Content: 'Header'", "ma"),
00131 "cheader_g" => Array("Content: 'Header', Graphical", "ma"),
00132 "ctext" => Array("Content: 'Text'", "mb"),
00133
00134 "cimage" => Array("Content: 'Image'", "md"),
00135 "cbullets" => Array("Content: 'Bullet list'", "me"),
00136 "ctable" => Array("Content: 'Table'", "mf"),
00137 "cuploads" => Array("Content: 'Filelinks'", "mg"),
00138 "cmultimedia" => Array("Content: 'Multimedia'", "mh"),
00139 "cmailform" => Array("Content: 'Form'", "mi"),
00140 "csearch" => Array("Content: 'Search'", "mj"),
00141 "clogin" => Array("Content: 'Login'", "mk"),
00142 "csplash" => Array("Content: 'Textbox'", "ml"),
00143 "cmenu" => Array("Content: 'Menu/Sitemap'", "mm"),
00144 "cshortcut" => Array("Content: 'Insert records'", "mn"),
00145 "clist" => Array("Content: 'List of records'", "mo"),
00146 "cscript" => Array("Content: 'Script'", "mp"),
00147 "chtml" => Array("Content: 'HTML'", "mq")
00148 );
00149 var $resourceDimensions = array();
00150 var $dirResources = array();
00151
00152
00153
00154 var $backend_info=1;
00155
00156
00157 var $ext_inBrace=0;
00158
00159
00160 var $tsbrowser_searchKeys = array();
00161 var $tsbrowser_depthKeys = array();
00162 var $constantMode="";
00163 var $regexMode="";
00164 var $fixedLgd="";
00165 var $resourceCheck=0;
00166 var $ext_lineNumberOffset=0;
00167 var $ext_localGfxPrefix="";
00168 var $ext_localWebGfxPrefix="";
00169 var $ext_expandAllNotes=0;
00170 var $ext_noPMicons=0;
00171 var $ext_noSpecialCharsOnLabels=0;
00172 var $ext_listOfTemplatesArr=array();
00173 var $ext_lineNumberOffset_mode="";
00174 var $ext_dontCheckIssetValues=0;
00175 var $ext_noCEUploadAndCopying=0;
00176 var $ext_printAll=0;
00177 var $ext_CEformName="forms[0]";
00178 var $ext_defaultOnlineResourceFlag=0;
00179 var $doNotSortCategoriesBeforeMakingForm = FALSE;
00180
00181
00182 var $templateTitles=array();
00183
00184
00194 function flattenSetup($setupArray, $prefix, $resourceFlag) {
00195 if (is_array($setupArray)) {
00196 $this->getFileName_backPath=PATH_site;
00197 reset($setupArray);
00198 while(list($key,$val)=each($setupArray)) {
00199 if ($prefix || substr($key,0,16)!="TSConstantEditor") {
00200 if (is_array($val)) {
00201 $this->flattenSetup($val,$prefix.$key, ($key=="file."));
00202 } elseif ($resourceFlag && $this->resourceCheck) {
00203 $this->flatSetup[$prefix.$key] = $this->getFileName($val);
00204 if ($this->removeFromGetFilePath && substr($this->flatSetup[$prefix.$key],0,strlen($this->removeFromGetFilePath))==$this->removeFromGetFilePath) {
00205 $this->flatSetup[$prefix.$key] = substr($this->flatSetup[$prefix.$key],strlen($this->removeFromGetFilePath));
00206 }
00207 } else {
00208 $this->flatSetup[$prefix.$key] = $val;
00209 }
00210 }
00211 }
00212 }
00213 }
00214
00221 function substituteConstants($all) {
00222 $this->Cmarker = substr(md5(uniqid("")),0,6);
00223
00224 return preg_replace_callback('/\{\$(.[^}]+)\}/', array($this, 'substituteConstantsCallBack'), $all);
00225 }
00226
00234 function substituteConstantsCallBack($matches) {
00235 switch($this->constantMode) {
00236 case 'const':
00237 $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ?
00238 '##'.$this->Cmarker.'_B##'.$matches[0].'##'.$this->Cmarker.'_E##' :
00239 $matches[0];
00240 break;
00241 case 'subst':
00242 $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ?
00243 '##'.$this->Cmarker.'_B##'.$this->flatSetup[$matches[1]].'##'.$this->Cmarker.'_E##' :
00244 $matches[0];
00245 break;
00246 case 'untouched':
00247 $ret_val = $matches[0];
00248 break;
00249 default:
00250 $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ?
00251 $this->flatSetup[$matches[1]] :
00252 $matches[0];
00253 }
00254
00255 return $ret_val;
00256 }
00257
00264 function substituteCMarkers($all) {
00265 switch($this->constantMode) {
00266 case "const":
00267 $all = str_replace('##'.$this->Cmarker.'_B##', '<font color="green"><B>', $all);
00268 $all = str_replace('##'.$this->Cmarker.'_E##', '</b></font>', $all);
00269 break;
00270 case "subst":
00271 $all = str_replace('##'.$this->Cmarker.'_B##', '<font color="green"><B>', $all);
00272 $all = str_replace('##'.$this->Cmarker.'_E##', '</b></font>', $all);
00273 break;
00274 default:
00275 $all = $all;
00276 break;
00277 }
00278 return $all;
00279 }
00280
00286 function generateConfig_constants() {
00287
00288
00289
00290 $this->setup["resources"]= $this->resources;
00291 $this->setup["sitetitle"]= $this->sitetitle;
00292
00293
00294 $constants = t3lib_div::makeInstance("t3lib_TSparser");
00295 $constants->regComments=1;
00296 $constants->setup = $this->const;
00297 $constants->setup = $this->mergeConstantsFromPageTSconfig($constants->setup);
00298
00299 $matchObj = t3lib_div::makeInstance("t3lib_matchCondition");
00300
00301 $matchObj->matchAll=1;
00302
00303 $c=0;
00304 $cc=count($this->constants);
00305 reset($this->constants);
00306 while (list(,$str)=each($this->constants)) {
00307 $c++;
00308 if ($c==$cc) {
00309 if (strstr($str,$this->edit_divider)) {
00310 $parts = explode($this->edit_divider,$str,2);
00311 $str=$parts[1];
00312 $constants->parse($parts[0],$matchObj);
00313 }
00314 $this->flatSetup = Array();
00315 $this->flattenSetup($constants->setup,"","");
00316 $defaultConstants=$this->flatSetup;
00317 }
00318 $constants->parse($str,$matchObj);
00319 }
00320
00321 $this->flatSetup = Array();
00322 $this->flattenSetup($constants->setup,"","");
00323 $this->setup["constants"] = $constants->setup;
00324
00325 return $this->ext_compareFlatSetups($defaultConstants);
00326 }
00327
00335 function ext_getSetup($theSetup,$theKey) {
00336 $parts = explode(".",$theKey,2);
00337
00338
00339 if (strcmp($parts[0],"") && is_array($theSetup[$parts[0]."."])) {
00340
00341 if (strcmp(trim($parts[1]),"")) {
00342
00343 return $this->ext_getSetup($theSetup[$parts[0]."."],trim($parts[1]));
00344 } else {
00345 return array($theSetup[$parts[0]."."], $theSetup[$parts[0]]);
00346 }
00347 } else {
00348 if (strcmp(trim($theKey),"")) {
00349 return array(array(),$theSetup[$theKey]);
00350 } else {
00351 return array($theSetup,"");
00352 }
00353 }
00354 }
00355
00367 function ext_getObjTree($arr, $depth_in, $depthData, $parentType='',$parentValue='', $alphaSort='0') {
00368 $HTML="";
00369 $a=0;
00370
00371 reset($arr);
00372 if($alphaSort == '1') {
00373 ksort($arr);
00374 }
00375 $keyArr_num=array();
00376 $keyArr_alpha=array();
00377 while (list($key,)=each($arr)) {
00378 if (substr($key,-2)!="..") {
00379 $key=ereg_replace("\.$","",$key);
00380 if (substr($key,-1)!=".") {
00381 if (t3lib_div::testInt($key)) {
00382 $keyArr_num[$key]=$arr[$key];
00383 } else {
00384 $keyArr_alpha[$key]=$arr[$key];
00385 }
00386 }
00387 }
00388 }
00389 ksort($keyArr_num);
00390 $keyArr=$keyArr_num+$keyArr_alpha;
00391 reset($keyArr);
00392 $c=count($keyArr);
00393 if ($depth_in) {$depth_in = $depth_in.".";}
00394
00395
00396
00397
00398 while (list($key,)=each($keyArr)) {
00399 $a++;
00400 $depth=$depth_in.$key;
00401 if ($this->bType!="const" || substr($depth,0,1)!="_") {
00402 $goto = substr(md5($depth),0,6);
00403
00404 $deeper = (is_array($arr[$key."."]) && ($this->tsbrowser_depthKeys[$depth] || $this->ext_expandAllNotes)) ? 1 : 0;
00405 $PM = "join";
00406 $LN = ($a==$c)?"blank":"line";
00407 $BTM = ($a==$c)?"bottom":"";
00408 $PM = is_array($arr[$key."."]) && !$this->ext_noPMicons ? ($deeper ? "minus":"plus") : "join";
00409
00410 $HTML.=$depthData;
00411 $theIcon='<img src="'.$GLOBALS["BACK_PATH"].'gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top" border="0" alt="" />';
00412 if ($PM=="join") {
00413 $HTML.=$theIcon;
00414 } else {
00415 $aHref='index.php?id='.$GLOBALS["SOBE"]->id.'&tsbr['.$depth.']='.($deeper?0:1).'#'.$goto;
00416 $HTML.='<a name="'.$goto.'" href="'.htmlspecialchars($aHref).'">'.$theIcon.'</a>';
00417 }
00418
00419 $label = $key;
00420 if (t3lib_div::inList("types,resources,sitetitle",$depth) && $this->bType=="setup") {
00421 $label='<font color="#666666">'.$label.'</font>';
00422 } else {
00423 if ($this->linkObjects) {
00424 $aHref = 'index.php?id='.$GLOBALS["SOBE"]->id.'&sObj='.$depth;
00425 if ($this->bType!="const") {
00426 $ln = is_array($arr[$key.'.ln..']) ? 'Defined in: '.$this->lineNumberToScript($arr[$key.'.ln..']) : 'N/A';
00427 } else {
00428 $ln = '';
00429 }
00430
00431 if ($this->tsbrowser_searchKeys[$depth] & 4) { $label = '<b><font color="red">'.$label.'</font></b>'; }
00432 $label = '<a href="'.htmlspecialchars($aHref).'" title="'.htmlspecialchars($ln).'">'.$label.'</a>';
00433 }
00434 }
00435
00436 $HTML.="[".$label."]";
00437
00438 if (isset($arr[$key])) {
00439 $theValue = $arr[$key];
00440 if ($this->fixedLgd) {
00441 $imgBlocks = ceil(1+strlen($depthData)/77);
00442 $lgdChars = 68-ceil(strlen("[".$key."]")*0.8)-$imgBlocks*3;
00443 $theValue = $this->ext_fixed_lgd($theValue,$lgdChars);
00444 }
00445 if ($this->tsbrowser_searchKeys[$depth] & 2) {
00446 $HTML.='=<b><font color="red">'.$this->makeHtmlspecialchars($theValue).'</font></b>';
00447 } else {
00448 $HTML.="=<b>".$this->makeHtmlspecialchars($theValue)."</b>";
00449 }
00450 }
00451 $HTML.="<br />";
00452
00453 if ($deeper) {
00454 $HTML.=$this->ext_getObjTree($arr[$key."."], $depth, $depthData.'<img src="'.$GLOBALS["BACK_PATH"].'gfx/ol/'.$LN.'.gif" width="18" height="16" align="top" alt="" />', '' , $arr[$key], $alphaSort);
00455 }
00456 }
00457 }
00458 return $HTML;
00459 }
00460
00467 function lineNumberToScript($lnArr) {
00468 if (!is_array($this->lnToScript)) {
00469 $this->lnToScript = array();
00470 $c=1;
00471 $c+=substr_count($GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'],chr(10))+2;
00472 $this->lnToScript[$c] = '[Default]';
00473
00474 foreach($this->hierarchyInfoToRoot as $info) {
00475 $c+=$info['configLines']+1;
00476 $this->lnToScript[$c] = $info['title'];
00477 }
00478 }
00479
00480 foreach($lnArr as $k => $ln) {
00481 foreach($this->lnToScript as $endLn => $title) {
00482 if ($endLn >= intval($ln)) {
00483 $lnArr[$k] = '"'.$title.'", '.$ln;
00484 break;
00485 }
00486 }
00487 }
00488
00489 return implode('; ',$lnArr);
00490 }
00491
00498 function makeHtmlspecialchars($theValue){
00499 return $this->ext_noSpecialCharsOnLabels ? $theValue : htmlspecialchars($theValue);
00500 }
00501
00511 function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray) {
00512 reset($arr);
00513 $keyArr=array();
00514 while (list($key,)=each($arr)) {
00515 $key=ereg_replace('\.$','',$key);
00516 if (substr($key,-1)!='.') {
00517 $keyArr[$key]=1;
00518 }
00519 }
00520 reset($keyArr);
00521 // asort($keyArr);
00522 $c=count($keyArr);
00523 if ($depth_in) { $depth_in = $depth_in.'.'; }
00524 while (list($key,)=each($keyArr)) {
00525 $depth=$depth_in.$key;
00526 $deeper = is_array($arr[$key."."]);
00527
00528 if ($this->regexMode) {
00529 if (ereg($searchString,$arr[$key])) { // The value has matched
00530 $this->tsbrowser_searchKeys[$depth]+=2;
00531 }
00532 if (ereg($searchString,$key)) { // The key has matched
00533 $this->tsbrowser_searchKeys[$depth]+=4;
00534 }
00535 if (ereg($searchString,$depth_in)) { // Just open this subtree if the parent key has matched the search
00536 $this->tsbrowser_searchKeys[$depth]=1;
00537 }
00538 } else {
00539 if (stristr($arr[$key],$searchString)) { // The value has matched
00540 $this->tsbrowser_searchKeys[$depth]+=2;
00541 }
00542 if (stristr($key,$searchString)) { // The key has matches
00543 $this->tsbrowser_searchKeys[$depth]+=4;
00544 }
00545 if (stristr($depth_in,$searchString)) { // Just open this subtree if the parent key has matched the search
00546 $this->tsbrowser_searchKeys[$depth]=1;
00547 }
00548 }
00549
00550 if ($deeper) {
00551 $cS = count($this->tsbrowser_searchKeys);
00552 $keyArray = $this->ext_getSearchKeys($arr[$key.'.'], $depth, $searchString, $keyArray);
00553 if ($cS != count($this->tsbrowser_searchKeys)) {
00554 $keyArray[$depth]=1;
00555 }
00556 }
00557 }
00558 return $keyArray;
00559 }
00560
00567 function ext_getRootlineNumber($pid) {
00568 if ($pid && is_array($GLOBALS["rootLine"])) {
00569 reset($GLOBALS["rootLine"]);
00570 while(list($key,$val)=each($GLOBALS["rootLine"])) {
00571 if ($val['uid']==$pid) return $key;
00572 }
00573 }
00574 }
00575
00585 function ext_getTemplateHierarchyArr($arr,$depthData, $keyArray,$first=0) {
00586 reset($arr);
00587 $keyArr=array();
00588 while (list($key,)=each($arr)) {
00589 $key=ereg_replace("\.$","",$key);
00590 if (substr($key,-1)!=".") {
00591 $keyArr[$key]=1;
00592 }
00593 }
00594 reset($keyArr);
00595 $a=0;
00596 $c=count($keyArr);
00597 while (list($key,)=each($keyArr)) {
00598 $HTML="";
00599 $a++;
00600 $deeper = is_array($arr[$key."."]);
00601 $row=$arr[$key];
00602
00603 $PM = "join";
00604 $LN = ($a==$c)?"blank":"line";
00605 $BTM = ($a==$c)?"top":"";
00606 $PM = "join";
00607
00608 $HTML.=$depthData;
00609 $icon = substr($row["templateID"],0,3)=="sys" ? t3lib_iconWorks::getIcon("sys_template",array("root"=>$row["root"])) :
00610 (substr($row["templateID"],0,6)=="static" ? t3lib_iconWorks::getIcon("static_template",array()) : 'gfx/i/default.gif');
00611 $alttext= "[".$row['templateID']."]";
00612 $alttext.= $row['pid'] ? " - ".t3lib_BEfunc::getRecordPath($row['pid'],$GLOBALS["SOBE"]->perms_clause,20) : "";
00613 if (in_array($row['templateID'],$this->clearList_const) || in_array($row['templateID'],$this->clearList_setup)) {
00614 $A_B='<a href="index.php?id='.$GLOBALS["SOBE"]->id.'&template='.$row['templateID'].'">';
00615 $A_E="</A>";
00616 } else {
00617 $A_B="";
00618 $A_E="";
00619 }
00620 $HTML.=($first?'':'<IMG src="'.$GLOBALS["BACK_PATH"].'gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top" border=0>').'<IMG src="'.$GLOBALS["BACK_PATH"].$icon.'" width="18" height="16" align="top" title="'.$alttext.'">'.$A_B.t3lib_div::fixed_lgd_cs($row['title'],$GLOBALS["BE_USER"]->uc["titleLen"]).$A_E." ";
00621 $RL = $this->ext_getRootlineNumber($row['pid']);
00622 $keyArray[] = '<tr>
00623 <td nowrap>'.$HTML.'</td>
00624 <td align=center>'.($row["root"]?"<b>X</b>":"").' </td>
00625 <td align=center'.$row["bgcolor_setup"].'>'.fw(($row["clConf"]?"<b>X</b>":"")." ").'</td>
00626 <td align=center'.$row["bgcolor_const"].'>'.fw(($row["clConst"]?"<b>X</b>":"")." ").'</td>
00627 <td>'.($row["pid"]?" ".$row["pid"].(strcmp($RL,"")?" (".$RL.")":"")." ":"").'</td>
00628 <td>'.($row["next"]?" ".$row["next"]." ":"").'</td>
00629 </tr>';
00630 if ($deeper) {
00631 $keyArray = $this->ext_getTemplateHierarchyArr($arr[$key."."], $depthData.($first?'':'<IMG src="'.$GLOBALS["BACK_PATH"].'gfx/ol/'.$LN.'.gif" width="18" height="16" align="top">'), $keyArray);
00632 }
00633 }
00634 return $keyArray;
00635 }
00636
00644 function ext_process_hierarchyInfo($depthDataArr,&$pointer) {
00645 $parent = $this->hierarchyInfo[$pointer-1]['templateParent'];
00646 while ($pointer>0 && $this->hierarchyInfo[$pointer-1]['templateParent']==$parent) {
00647 $pointer--;
00648 $row = $this->hierarchyInfo[$pointer];
00649
00650 $depthDataArr[$row['templateID']]=$row;
00651 $depthDataArr[$row['templateID']]["bgcolor_setup"] = isset($this->clearList_setup_temp[$row['templateID']])?' class="bgColor5"':'';
00652 $depthDataArr[$row['templateID']]["bgcolor_const"] = isset($this->clearList_const_temp[$row['templateID']])?' class="bgColor5"':'';
00653 unset($this->clearList_setup_temp[$row['templateID']]);
00654 unset($this->clearList_const_temp[$row['templateID']]);
00655 $this->templateTitles[$row['templateID']]=$row["title"];
00656
00657 if ($row['templateID']==$this->hierarchyInfo[$pointer-1]['templateParent']) {
00658 $depthDataArr[$row['templateID']."."] = $this->ext_process_hierarchyInfo(array(), $pointer);
00659 }
00660 }
00661 return $depthDataArr;
00662 }
00663
00675 function ext_outputTS($config, $lineNumbers=0, $comments=0, $crop=0, $syntaxHL=0, $syntaxHLBlockmode=0) {
00676 $all="";
00677 reset($config);
00678 while (list(,$str)=each($config)) {
00679 $all.="\n[GLOBAL]\n".$str;
00680 }
00681
00682 if ($syntaxHL) {
00683 $all = ereg_replace("^[^".chr(10)."]*.","",$all);
00684 $all = chop($all);
00685 $tsparser = t3lib_div::makeInstance("t3lib_TSparser");
00686 $tsparser->lineNumberOffset=$this->ext_lineNumberOffset+1;
00687 return $tsparser->doSyntaxHighlight($all,$lineNumbers?array($this->ext_lineNumberOffset+1):'',$syntaxHLBlockmode);
00688 } else {
00689 return $this->ext_formatTS($all,$lineNumbers,$comments,$crop);
00690 }
00691 }
00692
00702 function ext_fixed_lgd($string,$chars) {
00703 if ($chars >= 4) {
00704 if(strlen($string)>$chars) {
00705 return substr($string, 0, $chars-3)."...";
00706 }
00707 }
00708 return $string;
00709 }
00710
00718 function ext_lnBreakPointWrap($ln,$str) {
00719 return '<A href="#" onClick="return brPoint('.$ln.','.($this->ext_lineNumberOffset_mode=="setup"?1:0).');">'.$str.'</a>';
00720 }
00721
00731 function ext_formatTS($input, $ln, $comments=1, $crop=0) {
00732 $input = ereg_replace("^[^".chr(10)."]*.","",$input);
00733 $input = chop($input);
00734 $cArr = explode(chr(10),$input);
00735
00736 reset($cArr);
00737 $n = ceil(log10(count($cArr)+$this->ext_lineNumberOffset));
00738 $lineNum="";
00739 while(list($k,$v)=each($cArr)) {
00740 $lln=$k+$this->ext_lineNumberOffset+1;
00741 if ($ln) $lineNum = $this->ext_lnBreakPointWrap($lln,str_replace(" ",' ',sprintf("% ".$n."d",$lln))).": ";
00742 $v=htmlspecialchars($v);
00743 if ($crop) {$v=$this->ext_fixed_lgd($v,($ln?71:77));}
00744 $cArr[$k] = $lineNum.str_replace(" ",' ',$v);
00745
00746 $firstChar = substr(trim($v),0,1);
00747 if ($firstChar=="[") {
00748 $cArr[$k] = '<font color="green"><b>'.$cArr[$k].'</b></font>';
00749 } elseif ($firstChar=="/" || $firstChar=="#") {
00750 if ($comments) {
00751 $cArr[$k] = '<span class="typo3-dimmed">'.$cArr[$k].'</span>';
00752 } else {
00753 unset($cArr[$k]);
00754 }
00755 }
00756
00757
00758 }
00759 $output = implode($cArr, "<BR>")."<BR>";
00760 return $output;
00761 }
00762
00770 function ext_getFirstTemplate($id,$template_uid=0) {
00771 // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
00772 if (intval($id)) {
00773 if ($template_uid) {
00774 $addC = " AND uid=".$template_uid;
00775 }
00776 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).$addC.' '.$this->whereClause, '', 'sorting', '1');
00777 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00778 t3lib_BEfunc::workspaceOL('sys_template',$row);
00779 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00780 return $row; // Returns the template row if found.
00781 }
00782 }
00783
00790 function ext_getAllTemplates($id) {
00791 // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
00792 if (intval($id)) {
00793 $outRes=array();
00794 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).' '.$this->whereClause, '', 'sorting');
00795 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00796 t3lib_BEfunc::workspaceOL('sys_template',$row);
00797 if (is_array($row)) $outRes[] = $row;
00798 }
00799 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00800 return $outRes; // Returns the template rows in an array.
00801 }
00802 }
00803
00811 function ext_compareFlatSetups($default) {
00812 $editableComments=array();
00813 reset($this->flatSetup);
00814 while(list($const,$value)=each($this->flatSetup)) {
00815 if (substr($const,-2)!=".." && isset($this->flatSetup[$const.".."])) {
00816 $comment = trim($this->flatSetup[$const.".."]);
00817 $c_arr = explode(chr(10),$comment);
00818 while(list($k,$v)=each($c_arr)) {
00819 $line=trim(ereg_replace("^[#\/]*","",$v));
00820 if ($line) {
00821 $parts = explode(";", $line);
00822 while(list(,$par)=each($parts)) {
00823 if (strstr($par,"=")) {
00824 $keyValPair =explode("=",$par,2);
00825 switch(trim(strtolower($keyValPair[0]))) {
00826 case "type":
00827 // Type:
00828 /*
00829 int (range; low-high, list: item,item,item = selector),
00830 boolean (check),
00831 string (default),
00832 wrap,
00833 html-color ...,
00834 file
00835 */
00836 $editableComments[$const]["type"] = trim($keyValPair[1]);
00837 break;
00838 case "cat":
00839 // list of categories.
00840 $catSplit=explode("/",strtolower($keyValPair[1]));
00841 $editableComments[$const]["cat"] = trim($catSplit[0]);
00842 $catSplit[1]=trim($catSplit[1]); // This is the subcategory. Must be a key in $this->subCategories[]. catSplit[2] represents the search-order within the subcat.
00843 if ($catSplit[1] && isset($this->subCategories[$catSplit[1]])) {
00844 $editableComments[$const]["subcat_name"]=$catSplit[1];
00845 $editableComments[$const]["subcat"]=$this->subCategories[$catSplit[1]][1]."/".$catSplit[1]."/".trim($catSplit[2])."z";
00846 } else {
00847 $editableComments[$const]["subcat"]="x"."/".trim($catSplit[2])."z";
00848 }
00849 break;
00850 case "label":
00851 // label
00852 $editableComments[$const]["label"] = trim($keyValPair[1]);
00853 break;
00854 }
00855 }
00856 }
00857 }
00858 }
00859 }
00860 if (isset($editableComments[$const])) {
00861 $editableComments[$const]["name"]=$const;
00862 $editableComments[$const]["value"]=trim($value);
00863 if (isset($default[$const])) {
00864 $editableComments[$const]["default_value"]=trim($default[$const]);
00865 }
00866 }
00867 }
00868 return $editableComments;
00869 }
00870
00877 function ext_categorizeEditableConstants($editConstArray) {
00878 // Runs through the available constants and fills the $this->categories array with pointers and priority-info
00879 reset($editConstArray);
00880 while(list($constName,$constData)=each($editConstArray)) {
00881 if (!$constData["type"]) {$constData["type"]="string";}
00882 $cats = explode(",",$constData["cat"]);
00883 reset($cats);
00884 while (list(,$theCat)=each($cats)) { // if = only one category, while allows for many. We have agreed on only one category is the most basic way...
00885 $theCat=trim($theCat);
00886 if ($theCat) {
00887 $this->categories[$theCat][$constName]=$constData["subcat"];
00888 // $this->categories["all"][$constName]=$constData["subcat"];
00889 }
00890 }
00891 }
00892 // debug($this->categories);
00893 }
00894
00900 function ext_getCategoryLabelArray() {
00901 // Returns array used for labels in the menu.
00902 $retArr = array();
00903 while(list($k,$v)=each($this->categories)) {
00904 if (count($v)) {
00905 $retArr[$k]=strtoupper($k)." (".count($v).")";
00906 }
00907 }
00908 return $retArr;
00909 }
00910
00917 function ext_getTypeData($type) {
00918 $retArr = array();
00919 $type=trim($type);
00920 if (!$type) {
00921 $retArr["type"]="string";
00922 } else {
00923 $m=strcspn ($type," [");
00924 $retArr["type"]=strtolower(substr($type,0,$m));
00925 if (t3lib_div::inList("int,options,file,boolean,offset",$retArr["type"])) {
00926 $p=trim(substr($type,$m));
00927 $reg = array();
00928 ereg("\[(.*)\]",$p,$reg);
00929 $p=trim($reg[1]);
00930 if ($p) {
00931 $retArr["paramstr"]=$p;
00932 switch($retArr["type"]) {
00933 case "int":
00934 if (substr($retArr["paramstr"],0,1)=="-") {
00935 $retArr["params"]=t3lib_div::intExplode("-",substr($retArr["paramstr"],1));
00936 $retArr["params"][0]=intval("-".$retArr["params"][0]);
00937 } else {
00938 $retArr["params"]=t3lib_div::intExplode("-",$retArr["paramstr"]);
00939 }
00940 $retArr["paramstr"]=$retArr["params"][0]." - ".$retArr["params"][1];
00941 break;
00942 case "options":
00943 $retArr["params"]=explode(",",$retArr["paramstr"]);
00944 break;
00945 }
00946 }
00947 }
00948 }
00949 // debug($retArr);
00950 return $retArr;
00951 }
00952
00959 function ext_getTSCE_config($category) {
00960 $catConf=$this->setup["constants"]["TSConstantEditor."][$category."."];
00961 $out=array();
00962 if (is_array($catConf)) {
00963 reset($catConf);
00964 while(list($key,$val)=each($catConf)) {
00965 switch($key) {
00966 case "image":
00967 $out["imagetag"] = $this->ext_getTSCE_config_image($catConf["image"]);
00968 break;
00969 case "description":
00970 case "bulletlist":
00971 case "header":
00972 $out[$key] = $val;
00973 break;
00974 default:
00975 if (t3lib_div::testInt($key)) {
00976 $constRefs = explode(",",$val);
00977 reset($constRefs);
00978 while(list(,$const)=each($constRefs)) {
00979 $const=trim($const);
00980 if ($const && $const<=20) {
00981 $out["constants"][$const].=$this->ext_getKeyImage($key);
00982 }
00983 }
00984 }
00985 break;
00986 }
00987 }
00988 }
00989 $this->helpConfig=$out;
00990 }
00991
00998 function ext_getKeyImage($key) {
00999 return '<img src="'.$this->ext_localWebGfxPrefix.'gfx/'.$key.'.gif" align="top" hspace=2>';
01000 }
01001
01008 function ext_getTSCE_config_image($imgConf) {
01009 if (substr($imgConf,0,4)=="gfx/") {
01010 $iFile=$this->ext_localGfxPrefix.$imgConf;
01011 $tFile=$this->ext_localWebGfxPrefix.$imgConf;
01012 } elseif (substr($imgConf,0,4)=='EXT:') {
01013 $iFile = t3lib_div::getFileAbsFileName($imgConf);
01014 if ($iFile) {
01015 $f = substr($iFile,strlen(PATH_site));
01016 $tFile=$GLOBALS["BACK_PATH"]."../".$f;
01017 }
01018 } else {
01019 $f = "uploads/tf/".$this->extractFromResources($this->setup["resources"],$imgConf);
01020 $iFile=PATH_site.$f;
01021 $tFile=$GLOBALS["BACK_PATH"]."../".$f;
01022 }
01023 $imageInfo=@getImagesize($iFile);
01024 return '<img src="'.$tFile.'" '.$imageInfo[3].'>';
01025 }
01026
01032 function ext_resourceDims() {
01033 if ($this->setup["resources"]) {
01034 $rArr=explode(",",$this->setup["resources"]);
01035 while(list($c,$val)=each($rArr)) {
01036 $val=trim($val);
01037 $theFile = PATH_site."uploads/tf/".$val;
01038 if ($val && @is_file($theFile)) {
01039 $imgInfo = @getimagesize($theFile);
01040 }
01041 if (is_array($imgInfo)) {
01042 $this->resourceDimensions[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
01043 }
01044 }
01045 }
01046 reset($this->dirResources);
01047 while(list($c,$val)=each($this->dirResources)) {
01048 $val=trim($val);
01049 $imgInfo = @getimagesize(PATH_site.$val);
01050 if (is_array($imgInfo)) {
01051 $this->resourceDimensions[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
01052 }
01053 }
01054 }
01055
01062 function ext_readDirResources($path) {
01063 $path=trim($path);
01064 if ($path && substr($path,0,10)=="fileadmin/") {
01065 $path = ereg_replace("\/$","",$path);
01066 $this->readDirectory(PATH_site.$path);
01067 }
01068 }
01069
01077 function readDirectory($path,$type="file") {
01078 if(@is_dir($path)) {
01079 $d = @dir($path);
01080 $tempArray=Array();
01081 if (is_object($d)) {
01082 while($entry=$d->read()) {
01083 if ($entry!="." && $entry!="..") {
01084 $wholePath = $path."/".$entry; // Because of odd PHP-error where <BR>-tag is sometimes placed after a filename!!
01085 if (@file_exists($wholePath) && (!$type || filetype($wholePath)==$type)) {
01086 $fI = t3lib_div::split_fileref($wholePath);
01087 $this->dirResources[]=substr($wholePath,strlen(PATH_site));
01088 }
01089 }
01090 }
01091 $d->close();
01092 }
01093 }
01094 }
01095
01102 function ext_fNandV($params) {
01103 $fN='data['.$params["name"].']';
01104 $fV=$params["value"];
01105 if (ereg("^{[\$][a-zA-Z0-9\.]*}$",trim($fV),$reg)) { // Values entered from the constantsedit cannot be constants! 230502; removed \{ and set {
01106 $fV="";
01107 }
01108 $fV=htmlspecialchars($fV);
01109
01110 return array($fN,$fV,$params);
01111 }
01112
01120 function ext_printFields($theConstants,$category) {
01121 // This functions returns the HTML-code that creates the editor-layout of the module.
01122 reset($theConstants);
01123 $output="";
01124 $subcat="";
01125 if (is_array($this->categories[$category])) {
01126
01127 $help=$this->helpConfig;
01128 $this->rArr=explode(",",$this->setup["resources"].",".implode($this->dirResources,","));
01129
01130 if (!$this->doNotSortCategoriesBeforeMakingForm) asort($this->categories[$category]);
01131 while(list($name,$type)=each($this->categories[$category])) {
01132 $params = $theConstants[$name];
01133 if (is_array($params)) {
01134 if ($subcat!=$params["subcat_name"]) {
01135 $subcat=$params["subcat_name"];
01136 $subcat_name = $params["subcat_name"] ? $this->subCategories[$params["subcat_name"]][0] : "Others";
01137 $output.='<tr>';
01138 $output.='<td colspan=2 class="bgColor4"><div align="center"><b>'.$subcat_name.'</b></div></td>';
01139 $output.='</tr>';
01140 }
01141
01142 // if (substr($params["value"],0,2)!='{$') {
01143 $label=$GLOBALS["LANG"]->sL($params["label"]);
01144 $label_parts = explode(":",$label,2);
01145 if (count($label_parts)==2) {
01146 $head=trim($label_parts[0]);
01147 $body=trim($label_parts[1]);
01148 } else {
01149 $head=trim($label_parts[0]);
01150 $body="";
01151 }
01152 if (strlen($head)>35) {
01153 if (!$body) {$body=$head;}
01154 $head=t3lib_div::fixed_lgd_cs($head,35);
01155 }
01156 $typeDat=$this->ext_getTypeData($params["type"]);
01157 $checked="";
01158 $p_field="";
01159 $raname = substr(md5($params["name"]),0,10);
01160 $aname="'".$raname."'";
01161 if ($this->ext_dontCheckIssetValues || isset($this->objReg[$params["name"]])) {
01162 $checked=" checked";
01163 list($fN,$fV,$params)=$this->ext_fNandV($params);
01164
01165 switch($typeDat["type"]) {
01166 case "int":
01167 case "int+":
01168 $p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(5).' onChange="uFormUrl('.$aname.')">';
01169 if ($typeDat["paramstr"]) {
01170 $p_field.=' Range: '.$typeDat["paramstr"];
01171 } elseif ($typeDat["type"]=="int+") {
01172 $p_field.=' Range: 0 - ';
01173 } else {
01174 $p_field.=' (Integer)';
01175 }
01176 break;
01177 case "color":
01178 $colorNames=explode(",",",".$this->HTMLcolorList);
01179 $p_field="";
01180 while(list(,$val)=each($colorNames)) {
01181 $sel="";
01182 if ($val==strtolower($params["value"])) {$sel=" selected";}
01183 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.'</option>';
<