Documentation TYPO3 par Ameos

class.t3lib_tsparser_ext.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
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###";          // This string is used to indicate the point in a template from where the editable constants are listed. Any vars before this point (if it exists though) is regarded as default values.
00108         var $HTMLcolorList = "aqua,black,blue,fuchsia,gray,green,lime,maroon,navy,olive,purple,red,silver,teal,yellow,white";
00109 
00110                 // internal
00111         var $categories = array(
00112                 "basic" => array(),             // Constants of superior importance for the template-layout. This is dimensions, imagefiles and enabling of various features. The most basic constants, which you would almost always want to configure.
00113                 "menu" => array(),              // Menu setup. This includes fontfiles, sizes, background images. Depending on the menutype.
00114                 "content" => array(),   // All constants related to the display of pagecontent elements
00115                 "page" => array(),              // General configuration like metatags, link targets
00116                 "advanced" => array(),  // Advanced functions, which are used very seldomly.
00117                 "all" => array()                // All constants are put here also!
00118         );              // This will be filled with the available categories of the current template.
00119         var $subCategories = array(
00120         // Standard categories:
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         // subcategories based on the default content elements
00130                 "cheader" => Array("Content: 'Header'", "ma"),
00131                 "cheader_g" => Array("Content: 'Header', Graphical", "ma"),
00132                 "ctext" => Array("Content: 'Text'", "mb"),
00133 //              "ctextpic" =>
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 //      var $matchAll = 0;              // If set, all conditions are matched!
00153 
00154         var $backend_info=1;
00155 
00156                 // tsconstanteditor
00157         var $ext_inBrace=0;
00158 
00159                 // tsbrowser
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;        // Dont change...
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                 // ts analyzer
00182         var $templateTitles=array();
00183 
00184 
00194         function flattenSetup($setupArray, $prefix, $resourceFlag)      {
00195                 if (is_array($setupArray))      {
00196                         $this->getFileName_backPath=PATH_site;          // Setting absolute prefixed path for relative resources.
00197                         reset($setupArray);
00198                         while(list($key,$val)=each($setupArray))        {
00199                                 if ($prefix || substr($key,0,16)!="TSConstantEditor")   {               // We don't want "TSConstantEditor" in the flattend setup.
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                         // Parses the constants in $this->const with respect to the constant-editor in this module.
00288                         // In particular comments in the code are registered and the edit_divider is taken into account.
00289                         // These vars are also set lateron...
00290                 $this->setup["resources"]= $this->resources;
00291                 $this->setup["sitetitle"]= $this->sitetitle;
00292 
00293                         // parse constants
00294                 $constants = t3lib_div::makeInstance("t3lib_TSparser");
00295                 $constants->regComments=1;              // Register comments!
00296                 $constants->setup = $this->const;
00297                 $constants->setup = $this->mergeConstantsFromPageTSconfig($constants->setup);
00298 
00299                 $matchObj = t3lib_div::makeInstance("t3lib_matchCondition");
00300 //              $matchObj->matchAlternative = array("[globalString =  page | title = *test*]");
00301                 $matchObj->matchAll=1;          // Matches ALL conditions in TypoScript
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 //              debug("-----------",1);
00338 //              debug($theKey,1);
00339                 if (strcmp($parts[0],"") && is_array($theSetup[$parts[0]."."])) {
00340 //                      debug(trim($parts[1]),1);
00341                         if (strcmp(trim($parts[1]),"")) {
00342 //                      debug(trim($parts[1]),1);
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 
00366         function ext_getObjTree($arr, $depth_in, $depthData, $parentType="",$parentValue="")    {
00367                 $HTML="";
00368                 $a=0;
00369 
00370                 reset($arr);
00371                 $keyArr_num=array();
00372                 $keyArr_alpha=array();
00373                 while (list($key,)=each($arr))  {
00374                         if (substr($key,-2)!="..")      {       // Don't do anything with comments / linenumber registrations...
00375                                 $key=ereg_replace("\.$","",$key);
00376                                 if (substr($key,-1)!=".")       {
00377                                         if (t3lib_div::testInt($key))   {
00378                                                 $keyArr_num[$key]=$arr[$key];
00379                                         } else {
00380                                                 $keyArr_alpha[$key]=$arr[$key];
00381                                         }
00382                                 }
00383                         }
00384                 }
00385                 ksort($keyArr_num);
00386                 $keyArr=$keyArr_num+$keyArr_alpha;
00387                 reset($keyArr);
00388                 $c=count($keyArr);
00389                 if ($depth_in)  {$depth_in = $depth_in.".";}
00390 
00391 //              $validate_info= verify_TSobjects($keyArr,$parentType,$parentValue);
00392 //              debug($validate_info);
00393 
00394                 while (list($key,)=each($keyArr))       {
00395                         $a++;
00396                         $depth=$depth_in.$key;
00397                         if ($this->bType!="const" || substr($depth,0,1)!="_")   {               // this excludes all constants starting with "_" from being shown.
00398                                 $goto = substr(md5($depth),0,6);
00399         //                      debug($depth);
00400                                 $deeper = (is_array($arr[$key."."]) && ($this->tsbrowser_depthKeys[$depth] || $this->ext_expandAllNotes)) ? 1 : 0;
00401                                 $PM = "join";
00402                                 $LN = ($a==$c)?"blank":"line";
00403                                 $BTM = ($a==$c)?"bottom":"";
00404                                 $PM = is_array($arr[$key."."]) && !$this->ext_noPMicons ? ($deeper ? "minus":"plus") : "join";
00405 
00406                                 $HTML.=$depthData;
00407                                 $theIcon='<img src="'.$GLOBALS["BACK_PATH"].'gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top" border="0" alt="" />';
00408                                 if ($PM=="join")        {
00409                                         $HTML.=$theIcon;
00410                                 } else {
00411                                         $aHref='index.php?id='.$GLOBALS["SOBE"]->id.'&tsbr['.$depth.']='.($deeper?0:1).'#'.$goto;
00412                                         $HTML.='<a name="'.$goto.'" href="'.htmlspecialchars($aHref).'">'.$theIcon.'</a>';
00413                                 }
00414 
00415                                 $label = $key;
00416                                 if (t3lib_div::inList("types,resources,sitetitle",$depth) && $this->bType=="setup")     {               // Read only...
00417                                         $label='<font color="#666666">'.$label.'</font>';
00418                                 } else {
00419                                         if ($this->linkObjects) {
00420                                                 $aHref = 'index.php?id='.$GLOBALS["SOBE"]->id.'&sObj='.$depth;
00421                                                 if ($this->bType!="const")      {
00422                                                         $ln = is_array($arr[$key.'.ln..']) ? 'Defined in: '.$this->lineNumberToScript($arr[$key.'.ln..']) : 'N/A';
00423                                                 } else {
00424                                                         $ln = '';
00425                                                 }
00426 
00427                                                 if ($this->tsbrowser_searchKeys[$depth] & 4)    { $label = '<b><font color="red">'.$label.'</font></b>'; }      // The key has matched the search string
00428                                                 $label = '<a href="'.htmlspecialchars($aHref).'" title="'.htmlspecialchars($ln).'">'.$label.'</a>';
00429                                         }
00430                                 }
00431 
00432                                 $HTML.="[".$label."]";
00433 
00434                                 if (isset($arr[$key]))  {
00435                                         $theValue = $arr[$key];
00436                                         if ($this->fixedLgd)    {
00437                                                 $imgBlocks = ceil(1+strlen($depthData)/77);
00438                                                 $lgdChars = 68-ceil(strlen("[".$key."]")*0.8)-$imgBlocks*3;
00439                                                 $theValue = $this->ext_fixed_lgd($theValue,$lgdChars);
00440                                         }
00441                                         if ($this->tsbrowser_searchKeys[$depth] & 2)    {       // The value has matched the search string
00442                                                 $HTML.='=<b><font color="red">'.$this->makeHtmlspecialchars($theValue).'</font></b>';
00443                                         } else {
00444                                                 $HTML.="=<b>".$this->makeHtmlspecialchars($theValue)."</b>";
00445                                         }
00446                                 }
00447                                 $HTML.="<br />";
00448 
00449                                 if ($deeper)    {
00450                                         $HTML.=$this->ext_getObjTree($arr[$key."."], $depth, $depthData.'<img src="'.$GLOBALS["BACK_PATH"].'gfx/ol/'.$LN.'.gif" width="18" height="16" align="top" alt="" />', '' /* not used: $validate_info[$key] */, $arr[$key]);
00451                                 }
00452                         }
00453                 }
00454                 return $HTML;
00455         }
00456 
00463         function lineNumberToScript($lnArr)     {
00464                 if (!is_array($this->lnToScript))       {
00465                         $this->lnToScript = array();
00466                         $c=1;
00467                         $c+=substr_count($GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'],chr(10))+2;
00468                         $this->lnToScript[$c] = '[Default]';
00469 
00470                         foreach($this->hierarchyInfoToRoot as $info)    {
00471                                 $c+=$info['configLines']+1;
00472                                 $this->lnToScript[$c] = $info['title'];
00473                         }
00474                 }
00475 
00476                 foreach($lnArr as $k => $ln)    {
00477                         foreach($this->lnToScript as $endLn => $title)  {
00478                                 if ($endLn >= intval($ln))      {
00479                                         $lnArr[$k] = '"'.$title.'", '.$ln;
00480                                         break;
00481                                 }
00482                         }
00483                 }
00484 
00485                 return implode('; ',$lnArr);
00486         }
00487 
00494         function makeHtmlspecialchars($theValue){
00495                 return $this->ext_noSpecialCharsOnLabels ? $theValue : htmlspecialchars($theValue);
00496         }
00497 
00507         function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray)           {
00508                 reset($arr);
00509                 $keyArr=array();
00510                 while (list($key,)=each($arr))  {
00511                         $key=ereg_replace('\.$','',$key);
00512                         if (substr($key,-1)!='.')       {
00513                                 $keyArr[$key]=1;
00514                         }
00515                 }
00516                 reset($keyArr);
00517 //              asort($keyArr);
00518                 $c=count($keyArr);
00519                 if ($depth_in)  { $depth_in = $depth_in.'.'; }
00520                 while (list($key,)=each($keyArr))       {
00521                         $depth=$depth_in.$key;
00522                         $deeper = is_array($arr[$key."."]);
00523 
00524                         if ($this->regexMode)   {
00525                                 if (ereg($searchString,$arr[$key]))     {       // The value has matched
00526                                         $this->tsbrowser_searchKeys[$depth]+=2;
00527                                 }
00528                                 if (ereg($searchString,$key))   {               // The key has matched
00529                                         $this->tsbrowser_searchKeys[$depth]+=4;
00530                                 }
00531                                 if (ereg($searchString,$depth_in))      {       // Just open this subtree if the parent key has matched the search
00532                                         $this->tsbrowser_searchKeys[$depth]=1;
00533                                 }
00534                         } else {
00535                                 if (stristr($arr[$key],$searchString))  {       // The value has matched
00536                                         $this->tsbrowser_searchKeys[$depth]+=2;
00537                                 }
00538                                 if (stristr($key,$searchString))        {       // The key has matches
00539                                         $this->tsbrowser_searchKeys[$depth]+=4;
00540                                 }
00541                                 if (stristr($depth_in,$searchString))   {       // Just open this subtree if the parent key has matched the search
00542                                         $this->tsbrowser_searchKeys[$depth]=1;
00543                                 }
00544                         }
00545 
00546                         if ($deeper)    {
00547                                 $cS = count($this->tsbrowser_searchKeys);
00548                                 $keyArray = $this->ext_getSearchKeys($arr[$key.'.'], $depth, $searchString, $keyArray);
00549                                 if ($cS != count($this->tsbrowser_searchKeys))  {
00550                                         $keyArray[$depth]=1;
00551                                 }
00552                         }
00553                 }
00554                 return $keyArray;
00555         }
00556 
00563         function ext_getRootlineNumber($pid)    {
00564                 if ($pid && is_array($GLOBALS["rootLine"]))     {
00565                         reset($GLOBALS["rootLine"]);
00566                         while(list($key,$val)=each($GLOBALS["rootLine"]))       {
00567                                 if ($val['uid']==$pid)  return $key;
00568                         }
00569                 }
00570         }
00571 
00581         function ext_getTemplateHierarchyArr($arr,$depthData, $keyArray,$first=0)       {
00582                 reset($arr);
00583                 $keyArr=array();
00584                 while (list($key,)=each($arr))  {
00585                         $key=ereg_replace("\.$","",$key);
00586                         if (substr($key,-1)!=".")       {
00587                                 $keyArr[$key]=1;
00588                         }
00589                 }
00590                 reset($keyArr);
00591                 $a=0;
00592                 $c=count($keyArr);
00593                 while (list($key,)=each($keyArr))       {
00594                         $HTML="";
00595                         $a++;
00596                         $deeper = is_array($arr[$key."."]);
00597                         $row=$arr[$key];
00598 
00599                         $PM = "join";
00600                         $LN = ($a==$c)?"blank":"line";
00601                         $BTM = ($a==$c)?"top":"";
00602                         $PM = "join";
00603 
00604                         $HTML.=$depthData;
00605                         $icon = substr($row["templateID"],0,3)=="sys" ? t3lib_iconWorks::getIcon("sys_template",array("root"=>$row["root"])) :
00606                                                         (substr($row["templateID"],0,6)=="static" ? t3lib_iconWorks::getIcon("static_template",array()) : 'gfx/i/default.gif');
00607                         $alttext= "[".$row['templateID']."]";
00608                         $alttext.= $row['pid'] ? " - ".t3lib_BEfunc::getRecordPath($row['pid'],$GLOBALS["SOBE"]->perms_clause,20) : "";
00609                         if (in_array($row['templateID'],$this->clearList_const) || in_array($row['templateID'],$this->clearList_setup)) {
00610                                 $A_B='<a href="index.php?id='.$GLOBALS["SOBE"]->id.'&template='.$row['templateID'].'">';
00611                                 $A_E="</A>";
00612                         } else {
00613                                 $A_B="";
00614                                 $A_E="";
00615                         }
00616                         $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."&nbsp;&nbsp;";
00617                         $RL = $this->ext_getRootlineNumber($row['pid']);
00618                         $keyArray[] = '<tr>
00619                                                         <td nowrap>'.$HTML.'</td>
00620                                                         <td align=center>'.($row["root"]?"<b>X</b>":"").'&nbsp;&nbsp;</td>
00621                                                         <td align=center'.$row["bgcolor_setup"].'>'.fw(($row["clConf"]?"<b>X</b>":"")."&nbsp;&nbsp;").'</td>
00622                                                         <td align=center'.$row["bgcolor_const"].'>'.fw(($row["clConst"]?"<b>X</b>":"")."&nbsp;&nbsp;").'</td>
00623                                                         <td>'.($row["pid"]?"&nbsp;".$row["pid"].(strcmp($RL,"")?" (".$RL.")":"")."&nbsp;&nbsp;":"").'</td>
00624                                                         <td>'.($row["next"]?"&nbsp;".$row["next"]."&nbsp;&nbsp;":"").'</td>
00625                                                 </tr>';
00626                         if ($deeper)    {
00627                                 $keyArray = $this->ext_getTemplateHierarchyArr($arr[$key."."], $depthData.($first?'':'<IMG src="'.$GLOBALS["BACK_PATH"].'gfx/ol/'.$LN.'.gif" width="18" height="16" align="top">'), $keyArray);
00628                         }
00629                 }
00630                 return $keyArray;
00631         }
00632 
00640         function ext_process_hierarchyInfo($depthDataArr,&$pointer)     {
00641                 $parent = $this->hierarchyInfo[$pointer-1]['templateParent'];
00642                 while ($pointer>0 && $this->hierarchyInfo[$pointer-1]['templateParent']==$parent)       {
00643                         $pointer--;
00644                         $row = $this->hierarchyInfo[$pointer];
00645 
00646                         $depthDataArr[$row['templateID']]=$row;
00647                         $depthDataArr[$row['templateID']]["bgcolor_setup"] = isset($this->clearList_setup_temp[$row['templateID']])?' class="bgColor5"':'';
00648                         $depthDataArr[$row['templateID']]["bgcolor_const"] = isset($this->clearList_const_temp[$row['templateID']])?' class="bgColor5"':'';
00649                         unset($this->clearList_setup_temp[$row['templateID']]);
00650                         unset($this->clearList_const_temp[$row['templateID']]);
00651                         $this->templateTitles[$row['templateID']]=$row["title"];
00652 
00653                         if ($row['templateID']==$this->hierarchyInfo[$pointer-1]['templateParent'])     {
00654                                 $depthDataArr[$row['templateID']."."] = $this->ext_process_hierarchyInfo(array(), $pointer);
00655                         }
00656                 }
00657                 return $depthDataArr;
00658         }
00659 
00671         function ext_outputTS($config, $lineNumbers=0, $comments=0, $crop=0, $syntaxHL=0, $syntaxHLBlockmode=0) {
00672                 $all="";
00673                 reset($config);
00674                 while (list(,$str)=each($config))       {
00675                         $all.="\n[GLOBAL]\n".$str;
00676                 }
00677 
00678                 if ($syntaxHL)  {
00679                         $all = ereg_replace("^[^".chr(10)."]*.","",$all);
00680                         $all = chop($all);
00681                         $tsparser = t3lib_div::makeInstance("t3lib_TSparser");
00682                         $tsparser->lineNumberOffset=$this->ext_lineNumberOffset+1;
00683                         return $tsparser->doSyntaxHighlight($all,$lineNumbers?array($this->ext_lineNumberOffset+1):'',$syntaxHLBlockmode);
00684                 } else {
00685                         return $this->ext_formatTS($all,$lineNumbers,$comments,$crop);
00686                 }
00687         }
00688 
00698         function ext_fixed_lgd($string,$chars)  {
00699                 if ($chars >= 4)        {
00700                         if(strlen($string)>$chars)  {
00701                                 return substr($string, 0, $chars-3)."...";
00702                         }
00703                 }
00704                 return $string;
00705         }
00706 
00714         function ext_lnBreakPointWrap($ln,$str) {
00715                 return '<A href="#" onClick="return brPoint('.$ln.','.($this->ext_lineNumberOffset_mode=="setup"?1:0).');">'.$str.'</a>';
00716         }
00717 
00727         function ext_formatTS($input, $ln, $comments=1, $crop=0)        {
00728                 $input = ereg_replace("^[^".chr(10)."]*.","",$input);
00729                 $input = chop($input);
00730                 $cArr = explode(chr(10),$input);
00731 
00732                 reset($cArr);
00733                 $n = ceil(log10(count($cArr)+$this->ext_lineNumberOffset));
00734                 $lineNum="";
00735                 while(list($k,$v)=each($cArr))  {
00736                         $lln=$k+$this->ext_lineNumberOffset+1;
00737                         if ($ln)        $lineNum = $this->ext_lnBreakPointWrap($lln,str_replace(" ",'&nbsp;',sprintf("% ".$n."d",$lln))).":   ";
00738                         $v=htmlspecialchars($v);
00739                         if ($crop)      {$v=$this->ext_fixed_lgd($v,($ln?71:77));}
00740                         $cArr[$k] = $lineNum.str_replace(" ",'&nbsp;',$v);
00741 
00742                         $firstChar = substr(trim($v),0,1);
00743                         if ($firstChar=="[")    {
00744                                 $cArr[$k] = '<font color="green"><b>'.$cArr[$k].'</b></font>';
00745                         } elseif ($firstChar=="/" || $firstChar=="#")   {
00746                                 if ($comments)  {
00747                                         $cArr[$k] = '<span class="typo3-dimmed">'.$cArr[$k].'</span>';
00748                                 } else {
00749                                         unset($cArr[$k]);
00750                                 }
00751                         }
00752 
00753 
00754                 }
00755                 $output = implode($cArr, "<BR>")."<BR>";
00756                 return $output;
00757         }
00758 
00766         function ext_getFirstTemplate($id,$template_uid=0)              {
00767                         // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
00768                 if (intval($id))        {
00769                         if ($template_uid)      {
00770                                 $addC = " AND uid=".$template_uid;
00771                         }
00772                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).$addC.' '.$this->whereClause, '', 'sorting', '1');
00773                         $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00774                         t3lib_BEfunc::workspaceOL('sys_template',$row);
00775                         $GLOBALS['TYPO3_DB']->sql_free_result($res);
00776                         return $row;    // Returns the template row if found.
00777                 }
00778         }
00779 
00786         function ext_getAllTemplates($id)               {
00787                         // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
00788                 if (intval($id))        {
00789                         $outRes=array();
00790                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).' '.$this->whereClause, '', 'sorting');
00791                         while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00792                                 t3lib_BEfunc::workspaceOL('sys_template',$row);
00793                                 if (is_array($row))             $outRes[] = $row;
00794                         }
00795                         $GLOBALS['TYPO3_DB']->sql_free_result($res);
00796                         return $outRes; // Returns the template rows in an array.
00797                 }
00798         }
00799 
00807         function ext_compareFlatSetups($default)        {
00808                 $editableComments=array();
00809                 reset($this->flatSetup);
00810                 while(list($const,$value)=each($this->flatSetup))       {
00811                         if (substr($const,-2)!=".." && isset($this->flatSetup[$const.".."]))    {
00812                                 $comment = trim($this->flatSetup[$const.".."]);
00813                                 $c_arr = explode(chr(10),$comment);
00814                                 while(list($k,$v)=each($c_arr)) {
00815                                         $line=trim(ereg_replace("^[#\/]*","",$v));
00816                                         if ($line)      {
00817                                                 $parts = explode(";", $line);
00818                                                 while(list(,$par)=each($parts))         {
00819                                                         if (strstr($par,"="))   {
00820                                                                 $keyValPair =explode("=",$par,2);
00821                                                                 switch(trim(strtolower($keyValPair[0])))        {
00822                                                                         case "type":
00823                                                                                         // Type:
00824                                                                                         /*
00825         int (range; low-high, list: item,item,item = selector),
00826         boolean (check),
00827         string (default),
00828         wrap,
00829         html-color ...,
00830         file
00831                                                                                         */
00832                                                                                 $editableComments[$const]["type"] = trim($keyValPair[1]);
00833                                                                         break;
00834                                                                         case "cat":
00835                                                                                         // list of categories.
00836                                                                                 $catSplit=explode("/",strtolower($keyValPair[1]));
00837                                                                                 $editableComments[$const]["cat"] = trim($catSplit[0]);
00838                                                                                 $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.
00839                                                                                 if ($catSplit[1] && isset($this->subCategories[$catSplit[1]]))  {
00840                                                                                         $editableComments[$const]["subcat_name"]=$catSplit[1];
00841                                                                                         $editableComments[$const]["subcat"]=$this->subCategories[$catSplit[1]][1]."/".$catSplit[1]."/".trim($catSplit[2])."z";
00842                                                                                 } else {
00843                                                                                         $editableComments[$const]["subcat"]="x"."/".trim($catSplit[2])."z";
00844                                                                                 }
00845                                                                         break;
00846                                                                         case "label":
00847                                                                                         // label
00848                                                                                 $editableComments[$const]["label"] = trim($keyValPair[1]);
00849                                                                         break;
00850                                                                 }
00851                                                         }
00852                                                 }
00853                                         }
00854                                 }
00855                         }
00856                         if (isset($editableComments[$const]))   {
00857                                 $editableComments[$const]["name"]=$const;
00858                                 $editableComments[$const]["value"]=trim($value);
00859                                 if (isset($default[$const]))    {
00860                                         $editableComments[$const]["default_value"]=trim($default[$const]);
00861                                 }
00862                         }
00863                 }
00864                 return $editableComments;
00865         }
00866 
00873         function ext_categorizeEditableConstants($editConstArray)       {
00874                 // Runs through the available constants and fills the $this->categories array with pointers and priority-info
00875                 reset($editConstArray);
00876                 while(list($constName,$constData)=each($editConstArray))        {
00877                         if (!$constData["type"])        {$constData["type"]="string";}
00878                         $cats = explode(",",$constData["cat"]);
00879                         reset($cats);
00880                         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...
00881                                 $theCat=trim($theCat);
00882                                 if ($theCat)    {
00883                                         $this->categories[$theCat][$constName]=$constData["subcat"];
00884 //                                      $this->categories["all"][$constName]=$constData["subcat"];
00885                                 }
00886                         }
00887                 }
00888 //              debug($this->categories);
00889         }
00890 
00896         function ext_getCategoryLabelArray()    {
00897                 // Returns array used for labels in the menu.
00898                 $retArr = array();
00899                 while(list($k,$v)=each($this->categories))      {
00900                         if (count($v))  {
00901                                 $retArr[$k]=strtoupper($k)." (".count($v).")";
00902                         }
00903                 }
00904                 return $retArr;
00905         }
00906 
00913         function ext_getTypeData($type) {
00914                 $retArr = array();
00915                 $type=trim($type);
00916                 if (!$type)     {
00917                         $retArr["type"]="string";
00918                 } else {
00919                         $m=strcspn ($type," [");
00920                         $retArr["type"]=strtolower(substr($type,0,$m));
00921                         if (t3lib_div::inList("int,options,file,boolean,offset",$retArr["type"]))       {
00922                                 $p=trim(substr($type,$m));
00923                                 $reg = array();
00924                                 ereg("\[(.*)\]",$p,$reg);
00925                                 $p=trim($reg[1]);
00926                                 if ($p) {
00927                                         $retArr["paramstr"]=$p;
00928                                         switch($retArr["type"]) {
00929                                                 case "int":
00930                                                         if (substr($retArr["paramstr"],0,1)=="-")       {
00931                                                                 $retArr["params"]=t3lib_div::intExplode("-",substr($retArr["paramstr"],1));
00932                                                                 $retArr["params"][0]=intval("-".$retArr["params"][0]);
00933                                                         } else {
00934                                                                 $retArr["params"]=t3lib_div::intExplode("-",$retArr["paramstr"]);
00935                                                         }
00936                                                         $retArr["paramstr"]=$retArr["params"][0]." - ".$retArr["params"][1];
00937                                                 break;
00938                                                 case "options":
00939                                                         $retArr["params"]=explode(",",$retArr["paramstr"]);
00940                                                 break;
00941                                         }
00942                                 }
00943                         }
00944                 }
00945 //              debug($retArr);
00946                 return $retArr;
00947         }
00948 
00955         function ext_getTSCE_config($category)  {
00956                 $catConf=$this->setup["constants"]["TSConstantEditor."][$category."."];
00957                 $out=array();
00958                 if (is_array($catConf)) {
00959                         reset($catConf);
00960                         while(list($key,$val)=each($catConf))   {
00961                                 switch($key)    {
00962                                         case "image":
00963                                                 $out["imagetag"] = $this->ext_getTSCE_config_image($catConf["image"]);
00964                                         break;
00965                                         case "description":
00966                                         case "bulletlist":
00967                                         case "header":
00968                                                 $out[$key] = $val;
00969                                         break;
00970                                         default:
00971                                                 if (t3lib_div::testInt($key))   {
00972                                                         $constRefs = explode(",",$val);
00973                                                         reset($constRefs);
00974                                                         while(list(,$const)=each($constRefs))   {
00975                                                                 $const=trim($const);
00976                                                                 if ($const && $const<=20)       {
00977                                                                         $out["constants"][$const].=$this->ext_getKeyImage($key);
00978                                                                 }
00979                                                         }
00980                                                 }
00981                                         break;
00982                                 }
00983                         }
00984                 }
00985                 $this->helpConfig=$out;
00986         }
00987 
00994         function ext_getKeyImage($key)  {
00995                 return '<img src="'.$this->ext_localWebGfxPrefix.'gfx/'.$key.'.gif" align="top" hspace=2>';
00996         }
00997 
01004         function ext_getTSCE_config_image($imgConf)     {
01005                 if (substr($imgConf,0,4)=="gfx/")       {
01006                         $iFile=$this->ext_localGfxPrefix.$imgConf;
01007                         $tFile=$this->ext_localWebGfxPrefix.$imgConf;
01008                 } elseif (substr($imgConf,0,4)=='EXT:') {
01009                         $iFile = t3lib_div::getFileAbsFileName($imgConf);
01010                         if ($iFile)     {
01011                                 $f = substr($iFile,strlen(PATH_site));
01012                                 $tFile=$GLOBALS["BACK_PATH"]."../".$f;
01013                         }
01014                 } else {
01015                         $f = "uploads/tf/".$this->extractFromResources($this->setup["resources"],$imgConf);
01016                         $iFile=PATH_site.$f;
01017                         $tFile=$GLOBALS["BACK_PATH"]."../".$f;
01018                 }
01019                 $imageInfo=@getImagesize($iFile);
01020                 return '<img src="'.$tFile.'" '.$imageInfo[3].'>';
01021         }
01022 
01028         function ext_resourceDims()     {
01029                 if ($this->setup["resources"])  {
01030                         $rArr=explode(",",$this->setup["resources"]);
01031                         while(list($c,$val)=each($rArr))        {
01032                                 $val=trim($val);
01033                                 $theFile = PATH_site."uploads/tf/".$val;
01034                                 if ($val && @is_file($theFile)) {
01035                                         $imgInfo = @getimagesize($theFile);
01036                                 }
01037                                 if (is_array($imgInfo)) {
01038                                         $this->resourceDimensions[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
01039                                 }
01040                         }
01041                 }
01042                 reset($this->dirResources);
01043                 while(list($c,$val)=each($this->dirResources))  {
01044                         $val=trim($val);
01045                         $imgInfo = @getimagesize(PATH_site.$val);
01046                         if (is_array($imgInfo)) {
01047                                 $this->resourceDimensions[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
01048                         }
01049                 }
01050         }
01051 
01058         function ext_readDirResources($path)    {
01059                 $path=trim($path);
01060                 if ($path && substr($path,0,10)=="fileadmin/")  {
01061                         $path = ereg_replace("\/$","",$path);
01062                         $this->readDirectory(PATH_site.$path);
01063                 }
01064         }
01065 
01073         function readDirectory($path,$type="file")      {
01074                 if(@is_dir($path))      {
01075                         $d = @dir($path);
01076                         $tempArray=Array();
01077                         if (is_object($d))      {
01078                                 while($entry=$d->read()) {
01079                                         if ($entry!="." && $entry!="..")        {
01080                                                 $wholePath = $path."/".$entry;          // Because of odd PHP-error where  <BR>-tag is sometimes placed after a filename!!
01081                                                 if (@file_exists($wholePath) && (!$type || filetype($wholePath)==$type))        {
01082                                                         $fI = t3lib_div::split_fileref($wholePath);
01083                                                         $this->dirResources[]=substr($wholePath,strlen(PATH_site));
01084                                                 }
01085                                         }
01086                                 }
01087                                 $d->close();
01088                         }
01089                 }
01090         }
01091 
01098         function ext_fNandV($params)    {
01099                 $fN='data['.$params["name"].']';
01100                 $fV=$params["value"];
01101                 if (ereg("^{[\$][a-zA-Z0-9\.]*}$",trim($fV),$reg))      {               // Values entered from the constantsedit cannot be constants!   230502; removed \{ and set {
01102                         $fV="";
01103                 }
01104                 $fV=htmlspecialchars($fV);
01105 
01106                 return array($fN,$fV,$params);
01107         }
01108 
01116         function ext_printFields($theConstants,$category)       {
01117                         // This functions returns the HTML-code that creates the editor-layout of the module.
01118                 reset($theConstants);
01119                 $output="";
01120                 $subcat="";
01121                 if (is_array($this->categories[$category]))     {
01122 
01123                         $help=$this->helpConfig;
01124                         $this->rArr=explode(",",$this->setup["resources"].",".implode($this->dirResources,","));
01125 
01126                         if (!$this->doNotSortCategoriesBeforeMakingForm) asort($this->categories[$category]);
01127                         while(list($name,$type)=each($this->categories[$category]))     {
01128                                 $params = $theConstants[$name];
01129                                 if (is_array($params))  {
01130                                         if ($subcat!=$params["subcat_name"])    {
01131                                                 $subcat=$params["subcat_name"];
01132                                                 $subcat_name = $params["subcat_name"] ? $this->subCategories[$params["subcat_name"]][0] : "Others";
01133                                                 $output.='<tr>';
01134                                                 $output.='<td colspan=2 class="bgColor4"><div align="center"><b>'.$subcat_name.'</b></div></td>';
01135                                                 $output.='</tr>';
01136                                         }
01137 
01138                         //              if (substr($params["value"],0,2)!='{$') {
01139                                                 $label=$GLOBALS["LANG"]->sL($params["label"]);
01140                                                 $label_parts = explode(":",$label,2);
01141                                                 if (count($label_parts)==2)     {
01142                                                         $head=trim($label_parts[0]);
01143                                                         $body=trim($label_parts[1]);
01144                                                 } else {
01145                                                         $head=trim($label_parts[0]);
01146                                                         $body="";
01147                                                 }
01148                                                 if (strlen($head)>35)   {
01149                                                         if (!$body) {$body=$head;}
01150                                                         $head=t3lib_div::fixed_lgd_cs($head,35);
01151                                                 }
01152                                                 $typeDat=$this->ext_getTypeData($params["type"]);
01153                                                 $checked="";
01154                                                 $p_field="";
01155                                                 $raname = substr(md5($params["name"]),0,10);
01156                                                 $aname="'".$raname."'";
01157                                                 if ($this->ext_dontCheckIssetValues || isset($this->objReg[$params["name"]]))   {
01158                                                         $checked=" checked";
01159                                                         list($fN,$fV,$params)=$this->ext_fNandV($params);
01160 
01161                                                         switch($typeDat["type"])        {
01162                                                                 case "int":
01163                                                                 case "int+":
01164                                                                         $p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(5).' onChange="uFormUrl('.$aname.')">';
01165                                                                         if ($typeDat["paramstr"])       {
01166                                                                                 $p_field.=' Range: '.$typeDat["paramstr"];
01167                                                                         } elseif ($typeDat["type"]=="int+") {
01168                                                                                 $p_field.=' Range: 0 - ';
01169                                                                         } else {
01170                                                                                 $p_field.=' (Integer)';
01171                                                                         }
01172                                                                 break;
01173                                                                 case "color":
01174                                                                         $colorNames=explode(",",",".$this->HTMLcolorList);
01175                                                                         $p_field="";
01176                                                                         while(list(,$val)=each($colorNames))    {
01177                                                                                 $sel="";
01178                                                                                 if ($val==strtolower($params["value"])) {$sel=" selected";}
01179                                                                                 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.'</option>';
01180                                                                         }
01181                                                                         $p_field='<select name="C'.$fN.'" onChange="document.'.$this->ext_CEformName.'[\''.$fN.'\'].value=this.options[this.selectedIndex].value; uFormUrl('.$aname.');">'.$p_field.'</select>';
01182 
01183                                                                         $p_field.='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(7).' onChange="uFormUrl('.$aname.')">';
01184                                                                 break;
01185                                                                 case "wrap":
01186                                                                         $wArr = explode("|",$fV);
01187                                                                         $p_field='<input type="text" name="'.$fN.'" value="'.$wArr[0].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(29).' onChange="uFormUrl('.$aname.')">';
01188                                                                         $p_field.=' | ';
01189                                                                         $p_field.='<input type="text" name="W'.$fN.'" value="'.$wArr[1].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(15).' onChange="uFormUrl('.$aname.')">';
01190                                                                 break;
01191                                                                 case "offset":
01192                                                                         $wArr = explode(",",$fV);
01193                                                                         $labels = t3lib_div::trimExplode(",",$typeDat["paramstr"]);
01194                                                                         $p_field=($labels[0]?$labels[0]:"x").':<input type="text" name="'.$fN.'" value="'.$wArr[0].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
01195                                                                         $p_field.=' , ';
01196                                                                         $p_field.=($labels[1]?$labels[1]:"y").':<input type="text" name="W'.$fN.'" value="'.$wArr[1].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
01197                                                                         for ($aa=2;$aa<count($labels);$aa++)    {
01198                                                                                 if ($labels[$aa])       {
01199                                                                                         $p_field.=' , '.$labels[$aa].':<input type="text" name="W'.$aa.$fN.'" value="'.$wArr[$aa].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
01200                                                                                 } else {
01201                                                                                         $p_field.='<input type="hidden" name="W'.$aa.$fN.'" value="'.$wArr[$aa].'">';
01202                                                                                 }
01203                                                                         }
01204                                                                 break;
01205                                                                 case "options":
01206                                                                         if (is_array($typeDat["params"]))       {
01207                                                                                 $p_field="";
01208                                                                                 while(list(,$val)=each($typeDat["params"]))     {
01209                                                                                         $vParts = explode("=",$val,2);
01210                                                                                         $label = $vParts[0];
01211                                                                                         $val = isset($vParts[1]) ? $vParts[1] : $vParts[0];
01212 
01213                                                                                                 // option tag:
01214                                                                                         $sel="";
01215                                                                                         if ($val==$params["value"])     {$sel=" selected";}
01216                                                                                         $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$GLOBALS["LANG"]->sL($label).'</option>';
01217                                                                                 }
01218                                                                                 $p_field='<select name="'.$fN.'" onChange="uFormUrl('.$aname.')">'.$p_field.'</select>';
01219                                                                         }
01220                                                                 break;
01221                                                                 case "boolean":
01222                                                                         $p_field='<input type="Hidden" name="'.$fN.'" value="0">';
01223                                                                         $sel=""; if ($fV)       {$sel=" checked";}
01224                                                                         $p_field.='<input type="Checkbox" name="'.$fN.'" value="'.($typeDat["paramstr"]?$typeDat["paramstr"]:1).'"'.$sel.' onClick="uFormUrl('.$aname.')">';
01225                                                                 break;
01226                                                                 case "comment":
01227                                                                         $p_field='<input type="Hidden" name="'.$fN.'" value="#">';
01228                                                                         $sel=""; if (!$fV)      {$sel=" checked";}
01229                                                                         $p_field.='<input type="Checkbox" name="'.$fN.'" value=""'.$sel.' onClick="uFormUrl('.$aname.')">';
01230                                                                 break;
01231                                                                 case "file":
01232                                                                         $p_field='<option value=""></option>';
01233 //                                                                      debug($params["value"]);
01234                                                                         $theImage="";
01235 //                                                                      if ($this->)    {
01236                                                                                 $selectThisFile = $this->extractFromResources($this->setup["resources"],$params["value"]);
01237                                                                                 if ($params["value"] && !$selectThisFile)       {
01238                                                                                         if (in_array($params["value"],$this->dirResources))     {
01239                                                                                                 $selectThisFile=$params["value"];
01240                                                                                         }
01241                                                                                 }
01242 //                                                                              debug($selectThisFile);
01243                                                                                         // extensionlist
01244                                                                                 $extList = $typeDat["paramstr"];
01245                                                                                 $p_field='<option value="">('.$extList.')</option>';
01246                                                                                 if ($extList=="IMAGE_EXT")      {
01247                                                                                         $extList = $GLOBALS["TYPO3_CONF_VARS"]["GFX"]["imagefile_ext"];
01248                                                                                 }
01249                                                                                 reset($this->rArr);
01250                                                                                 $onlineResourceFlag=$this->ext_defaultOnlineResourceFlag;
01251 
01252                                                                                 while(list($c,$val)=each($this->rArr))  {
01253                                                                                         $val=trim($val);
01254                                                                                         $fI=t3lib_div::split_fileref($val);
01255 //                                                                                      debug($fI);
01256                                                                                         if ($val && (!$extList || t3lib_div::inList($extList,$fI["fileext"])))  {
01257                                                                                                 if ($onlineResourceFlag<=0 && substr($fI["path"],0,10)=="fileadmin/")   {
01258                                                                                                         if ($onlineResourceFlag<0)      {
01259                                                                                                                 $p_field.='<option value=""></option>';
01260                                                                                                         }
01261                                                                                                         $p_field.='<option value="">__'.$fI["path"].'__:</option>';
01262                                                                                                         $onlineResourceFlag=1;
01263                                                                                                 }
01264                                                                                                 $dims=$this->resourceDimensions[$val];
01265                                                                                                 $sel="";
01266 
01267                                                                                                         // Check if $params["value"] is in the list of resources.
01268                                                                                                 if ($selectThisFile && $selectThisFile==$val)   {
01269                                                                                                         $sel=" selected";
01270                                                                                                         if ($onlineResourceFlag<=0)     {
01271                                                                                                                 $theImage=t3lib_BEfunc::thumbCode(array("resources"=>$selectThisFile),"sys_template","resources",$GLOBALS["BACK_PATH"],"");
01272                                                                                                         } else {
01273                                                                                                                 $theImage=t3lib_BEfunc::thumbCode(array("resources"=>$fI["file"]),"sys_template","resources",$GLOBALS["BACK_PATH"],"",$fI["path"]);
01274                                                                                                         }
01275                                                                                                 }
01276 
01277                                                                                                 if ($onlineResourceFlag<=0)     {
01278                                                                                                         $onlineResourceFlag--;
01279                                                                                                                 // Value is set with a *
01280                                                                                                         $val = $this->ext_setStar($val);
01281                                                                                                         $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.$dims.'</option>';
01282                                                                                                 } else {
01283                                                                                                         $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$fI["file"].$dims.'</option>';
01284                                                                                                 }
01285                                                                                         }
01286                                                                                 }
01287                                                                                 if (trim($params["value"]) && !$selectThisFile) {
01288                                                                                         $val = $params["value"];
01289                                                                                         $p_field.='<option value=""></option>';
01290                                                                                         $p_field.='<option value="'.htmlspecialchars($val).'" selected>'.$val.'</option>';
01291                                                                                 }
01292         //                                                              }
01293                                                                         $p_field='<select name="'.$fN.'" onChange="uFormUrl('.$aname.')">'.$p_field.'</select>';
01294                                                                         $p_field.=$theImage;
01295 
01296                                                                         if (!$this->ext_noCEUploadAndCopying)   {
01297                                                                                         // Copy a resource
01298                                                                                 $copyFile = $this->extractFromResources($this->setup["resources"],$params["value"]);
01299                                                                                 if (!$copyFile) {
01300                                                                                         if ($params["value"])   {
01301                                                                                                 $copyFile=PATH_site.$this->ext_detectAndFixExtensionPrefix($params["value"]);
01302                                                                                         }
01303                                                                                 } else {
01304         //                                                                              $copyFile=PATH_site."uploads/tf/".$copyFile;
01305                                                                                         $copyFile="";
01306                                                                                 }
01307 #debug($copyFile);
01308                                                                                 if ($copyFile && @is_file($copyFile))   {
01309                                                                                         $p_field.='<img src="clear.gif" width="20" height="1" alt="" /><img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/clip_copy.gif','width="12" height="12"').' border="0" alt="" /><input type="Checkbox" name="_copyResource['.$params["name"].']" value="'.htmlspecialchars($copyFile).'" onClick="uFormUrl('.$aname.');if (this.checked) {alert(unescape(\''.rawurlencode(sprintf("This will make a copy of the current file, '%s'. Do you really want that?",$params["value"])).'\'));}">';
01310                                                                                 }
01311                                                                                         // Upload?
01312                                                                                 $p_field.='<BR>';
01313                                                                                 $p_field.='<input type="file" name="upload_'.$fN.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth().' onChange="uFormUrl('.$aname.')" size="50" />';
01314                                                                         }
01315                                                                 break;
01316                                                                 case 'small':
01317                                                                 default:
01318                                                                         $fwidth= $typeDat["type"]=="small" ? 10 : 46;
01319                                                                         $p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth($fwidth).' onChange="uFormUrl('.$aname.')">';
01320                                                                 break;
01321                                                         }
01322                                                 }
01323                                                 if (!$this->ext_dontCheckIssetValues)   $p_field='<input type="Checkbox" name="check['.$params["name"].']" value="1"'.$checked.' onClick="uFormUrl('.$aname.')">'.$p_field;
01324                                                 if ($typeDat["type"]=="color" && substr($params["value"],0,2)!='{$')    {
01325                                                         $p_field='<table border=0 cellpadding=0 cellspacing=0><tr><td nowrap>'.$p_field.'</td><td>&nbsp;</td><td bgcolor="'.$params["value"].'"><img src="clear.gif" width=50 height=10></td></tr></table>';
01326                                                 } else {
01327                                                         $p_field='<span class="nobr">'.$p_field.'</span><br />';
01328                                                 }
01329 
01330                                                 $p_name = '<span class="typo3-dimmed">['.$params["name"].']</span><BR>';
01331                                                 $p_dlabel='<span class="typo3-dimmed"><b>Default:</b> '.htmlspecialchars($params["default_value"]).'</span><BR>';
01332                                                 $p_label = '<b>'.htmlspecialchars($head).'</b>';
01333                                                 $p_descrip = $body ? htmlspecialchars($body)."<BR>" : "";
01334 
01335                                                 $output.='<tr>';
01336                                                 $output.='<td valign=top nowrap><a name="'.$raname.'"></a>'.$help["constants"][$params["name"]].$p_label.'</td>';
01337                                                 $output.='<td valign=top align="right">'.$p_name.'</td>';
01338                                                 $output.='</tr>';
01339                                                 $output.='<tr>';
01340                                                 $output.='<td colspan=2>'.$p_descrip.$p_field.$p_dlabel.'<br></td>';
01341                                                 $output.='</tr>';
01342                         //              }
01343                                 } else {
01344                                         debug("Error. Constant did not exits. Should not happen.");
01345                                 }
01346                         }
01347                         $output='<table border=0 cellpadding=0 cellspacing=0>'.$output.'</table>';
01348                 }
01349                 return $output;
01350         }
01351 
01352 
01353 
01354 
01355 
01356 
01357 
01358 
01359 
01360 
01361 
01362 
01363         /***************************
01364          *
01365          * Processing input values
01366          *
01367          ***************************/
01368 
01373         function ext_regObjectPositions($constants)     {
01374                         // This runs through the lines of the constants-field of the active template and registers the constants-names and linepositions in an array, $this->objReg
01375                 $this->raw = explode(chr(10),$constants);
01376                 $this->rawP=0;
01377 
01378                 $this->objReg=array();          // resetting the objReg if the divider is found!!
01379                 $this->ext_regObjects("");
01380         }
01381 
01388         function ext_regObjects($pre)   {
01389                         // works with regObjectPositions. "expands" the names of the TypoScript objects
01390                 while (isset($this->raw[$this->rawP]))  {
01391                         $line = ltrim($this->raw[$this->rawP]);
01392                         if (strstr($line,$this->edit_divider))  {
01393                                 $this->objReg=array();          // resetting the objReg if the divider is found!!
01394                         }
01395                         $this->rawP++;
01396                         if ($line)      {
01397                                 if (substr($line,0,1)=="[")     {
01398 //                                      return $line;
01399                                 } elseif (strcspn($line,"}#/")!=0)      {
01400                                         $varL = strcspn($line," {=<");
01401                                         $var=substr($line,0,$varL);
01402                                         $line = ltrim(substr($line,$varL));
01403                                         switch(substr($line,0,1))       {
01404                                                 case "=":
01405                                                         $this->objReg[$pre.$var]=$this->rawP-1;
01406                                                 break;
01407                                                 case "{":
01408                                                         $this->ext_inBrace++;
01409                                                         $this->ext_regObjects($pre.$var.".");
01410                                                 break;
01411                                         }
01412                                         $this->lastComment="";
01413                                 } elseif (substr($line,0,1)=="}")       {
01414                                         $this->lastComment="";
01415                                         $this->ext_inBrace--;
01416                                         if ($this->ext_inBrace<0)       {
01417                                                 $this->ext_inBrace=0;
01418                                         } else {
01419                                                 break;
01420                                         }
01421                                 }
01422                         }
01423                 }
01424         }
01425 
01433         function ext_putValueInConf($key, $var) {
01434                         // Puts the value $var to the TypoScript value $key in the current lines of the templates.
01435                         // If the $key is not found in the template constants field, a new line is inserted in the bottom.
01436                 $theValue = " ".trim($var);
01437                 if (isset($this->objReg[$key])) {
01438                         $lineNum = $this->objReg[$key];
01439                         $parts = explode("=",$this->raw[$lineNum],2);
01440                         if (count($parts)==2)   {
01441                                 $parts[1]= $theValue;
01442                         }
01443                         $this->raw[$lineNum]=implode($parts,"=");
01444                 } else {
01445                         $this->raw[]=$key." =".$theValue;
01446                 }
01447                 $this->changed=1;
01448         }
01449 
01456         function ext_removeValueInConf($key)    {
01457                         // Removes the value in the configuration
01458                 if (isset($this->objReg[$key])) {
01459                         $lineNum = $this->objReg[$key];
01460                         unset($this->raw[$lineNum]);
01461                 }
01462                 $this->changed=1;
01463         }
01464 
01472         function ext_depthKeys($arr,$settings)  {
01473                 reset($arr);
01474                 $tsbrArray=array();
01475                 while(list($theK,$theV)=each($arr))     {
01476                         $theKeyParts = explode(".",$theK);
01477                         $depth="";
01478                         $c=count($theKeyParts);
01479                         $a=0;
01480                         while(list(,$p)=each($theKeyParts))     {
01481                                 $a++;
01482                                 $depth.=($depth?".":"").$p;
01483                                 $tsbrArray[$depth]= ($c==$a) ? $theV : 1;
01484                         }
01485                 }
01486                         // Modify settings
01487                 reset($tsbrArray);
01488                 while(list($theK,$theV)=each($tsbrArray))       {
01489                         if ($theV)      {
01490                                 $settings[$theK] = 1;
01491                         } else {
01492                                 unset($settings[$theK]);
01493                         }
01494                 }
01495                 return $settings;
01496         }
01497 
01507         function ext_procesInput($http_post_vars,$http_post_files,$theConstants,$tplRow)        {
01508                 $data=$http_post_vars["data"];
01509                 $check=$http_post_vars["check"];
01510                 $copyResource=$http_post_vars["_copyResource"];
01511                 $Wdata=$http_post_vars["Wdata"];
01512                 $W2data=$http_post_vars["W2data"];
01513                 $W3data=$http_post_vars["W3data"];
01514                 $W4data=$http_post_vars["W4data"];
01515                 $W5data=$http_post_vars["W5data"];
01516 
01517                 if (is_array($data))    {
01518                         reset($data);
01519                         while(list($key,$var)=each($data))      {
01520                                 if (isset($theConstants[$key])) {
01521                                         if ($this->ext_dontCheckIssetValues || isset($check[$key]))     {               // If checkbox is set, update the value
01522                                                 list($var) = explode(chr(10),$var);     // exploding with linebreak, just to make sure that no multiline input is given!
01523                                                 $typeDat=$this->ext_getTypeData($theConstants[$key]["type"]);
01524                                                 switch($typeDat["type"])        {
01525                                                         case "int":
01526                                                                 if ($typeDat["paramstr"])       {
01527                                                                         $var=t3lib_div::intInRange($var,$typeDat["params"][0],$typeDat["params"][1]);
01528                                                                 } else {
01529                                                                         $var=intval($var);
01530                                                                 }
01531                                                         break;
01532                                                         case "int+":
01533                                                                 $var=t3lib_div::intInRange($var,0,10000);
01534                                                         break;
01535                                                         case "color":
01536                                                                 $col=array();
01537                                                                 if($var && !t3lib_div::inList($this->HTMLcolorList,strtolower($var)))   {
01538                                                                         $var = ereg_replace("[^A-Fa-f0-9]*","",$var);
01539                                                                         $col[]=HexDec(substr($var,0,2));
01540                                                                         $col[]=HexDec(substr($var,2,2));
01541                                                                         $col[]=HexDec(substr($var,4,2));
01542                                                                         $var="#".strtoupper(substr("0".DecHex($col[0]),-2).substr("0".DecHex($col[1]),-2).substr("0".DecHex($col[2]),-2));
01543                                                                 }
01544                                                         break;
01545                                                         case "comment":
01546                                                                 if ($var)       {
01547                                                                         $var="#";
01548                                                                 } else {
01549                                                                         $var="";
01550                                                                 }
01551                                                         break;
01552                                                         case "wrap":
01553                                                                 if (isset($Wdata[$key]))        {
01554                                                                         $var.="|".$Wdata[$key];
01555                                                                 }
01556                                                         break;
01557                                                         case "offset":
01558                                                                 if (isset($Wdata[$key]))        {
01559                                                                         $var=intval($var).",".intval($Wdata[$key]);
01560                                                                         if (isset($W2data[$key]))       {
01561                                                                                 $var.=",".intval($W2data[$key]);
01562                                                                                 if (isset($W3data[$key]))       {
01563                                                                                         $var.=",".intval($W3data[$key]);
01564                                                                                         if (isset($W4data[$key]))       {
01565                                                                                                 $var.=",".intval($W4data[$key]);
01566                                                                                                 if (isset($W5data[$key]))       {
01567                                                                                                         $var.=",".intval($W5data[$key]);
01568                                                                                                 }
01569                                                                                         }
01570                                                                                 }
01571                                                                         }
01572                                                                 }
01573                                                         break;
01574                                                         case "boolean":
01575                                                                 if ($var)       {
01576                                                                         $var = $typeDat["paramstr"] ? $typeDat["paramstr"] : 1;
01577                                                                 }
01578                                                         break;
01579                                                         case "file":
01580                                                                 if (!$this->ext_noCEUploadAndCopying)   {
01581                                                                         if ($http_post_files["upload_data"]["name"][$key] && $http_post_files["upload_data"]["tmp_name"][$key]!="none") {
01582                                                                                 $var = $this->upload_copy_file(
01583                                                                                         $typeDat,
01584                                                                                         $tplRow,
01585                                                                                         trim($http_post_files["upload_data"]["name"][$key]),
01586                                                                                         $http_post_files["upload_data"]["tmp_name"][$key]
01587                                                                                 );
01588                                                                         }
01589                                                                         if ($copyResource[$key])        {
01590                                                                                 $var = $this->upload_copy_file(
01591                                                                                         $typeDat,
01592                                                                                         $tplRow,
01593                                                                                         basename($copyResource[$key]),
01594                                                                                         $copyResource[$key]
01595                                                                                 );
01596                                                                         }
01597                                                                 }
01598                                                         break;
01599                                                 }
01600                                                 if ($this->ext_printAll || strcmp($theConstants[$key]["value"],$var))   {
01601                                                         $this->ext_putValueInConf($key, $var);          // Put value in, if changed.
01602                                                 }
01603                                                 unset($check[$key]);            // Remove the entry because it has been "used"
01604                                         } else {
01605                                                 $this->ext_removeValueInConf($key);
01606                                         }
01607                                 }
01608                         }
01609                 }
01610                         // Remaining keys in $check indicates fields that are just clicked "on" to be edited. Therefore we get the default value and puts that in the template as a start...
01611                 if (!$this->ext_dontCheckIssetValues && is_array($check))       {
01612                         reset($check);
01613                         while(list($key,$var)=each($check))     {
01614                                 if (isset($theConstants[$key])) {
01615                                         $dValue = $theConstants[$key]["default_value"];
01616 //                                      debug($dValue);
01617                                         $this->ext_putValueInConf($key, $dValue);
01618 //                                      debug($key,1);
01619                                 }
01620                         }
01621                 }
01622 //              debug($this->objReg);
01623         }
01624 
01634         function upload_copy_file($typeDat,&$tplRow,$theRealFileName,$tmp_name) {
01635 
01636                         // extensions
01637                 $extList = $typeDat["paramstr"];
01638                 if ($extList=="IMAGE_EXT")      {
01639                         $extList = $GLOBALS["TYPO3_CONF_VARS"]["GFX"]["imagefile_ext"];
01640                 }
01641                 $fI=t3lib_div::split_fileref($theRealFileName);
01642                 if ($theRealFileName && (!$extList || t3lib_div::inList($extList,$fI["fileext"])))      {
01643                         $tmp_upload_name = t3lib_div::upload_to_tempfile($tmp_name);    // If there is an uploaded file, move it for the sake of safe_mode.
01644 
01645                                 // Saving resource
01646                         $alternativeFileName=array();
01647                         $alternativeFileName[$tmp_upload_name] = $theRealFileName;
01648                                 // Making list of resources
01649                         $resList = $tplRow["resources"];
01650                         $resList = $tmp_upload_name.",".$resList;
01651                         $resList=implode(t3lib_div::trimExplode(",",$resList,1),",");
01652                                 // Making data-array
01653                         $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
01654 // debug($saveId);
01655                         $recData=array();
01656                         $recData["sys_template"][$saveId]["resources"] = $resList;
01657                                 // Saving
01658                         $tce = t3lib_div::makeInstance("t3lib_TCEmain");
01659                         $tce->stripslashes_values=0;
01660                         $tce->alternativeFileName = $alternativeFileName;
01661                         $tce->start($recData,Array());
01662                         $tce->process_datamap();
01663 
01664                         t3lib_div::unlink_tempfile($tmp_upload_name);
01665 
01666                         $tmpRow = t3lib_BEfunc::getRecordWSOL("sys_template",$saveId,"resources");
01667 
01668                         $tplRow["resources"] = $tmpRow["resources"];
01669 
01670                                 // Setting the value
01671                         $var = $this->ext_setStar($theRealFileName);
01672                 }
01673                 return $var;
01674         }
01675 
01683         function ext_prevPageWithTemplate($id,$perms_clause)    {
01684                 $rootLine = t3lib_BEfunc::BEgetRootLine($id,$perms_clause?" AND ".$perms_clause:"");
01685                 reset($rootLine);
01686                 while(list(,$p)=each($rootLine))        {
01687                         if ($this->ext_getFirstTemplate($p["uid"]))     {
01688                                 return $p;
01689                         }
01690                 }
01691         }
01692 
01699         function ext_setStar($val)      {
01700                 $fParts = explode(".",strrev($val),2);
01701                 $val=ereg_replace("_[0-9][0-9]$","",strrev($fParts[1]))."*.".strrev($fParts[0]);
01702                 return $val;
01703         }
01704 
01711         function ext_detectAndFixExtensionPrefix($value)        {
01712                 if (substr($value,0,4)=="EXT:") {
01713                         $parts = explode("/",substr($value,4),2);
01714 #debug($parts);
01715                         $extPath = t3lib_extMgm::siteRelPath($parts[0]);
01716                         $value = $extPath.$parts[1];
01717                         return $value;
01718                 } else {
01719                         return $value;
01720                 }
01721         }
01722 }
01723 
01724 
01725 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php'])      {
01726         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php']);
01727 }
01728 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6