Documentation TYPO3 par Ameos

class.t3lib_tsparser_ext.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2005 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 ***************************************************************/
00089 require_once(PATH_t3lib."class.t3lib_tstemplate.php");
00090 
00091 
00092 
00093 
00094 
00095 
00096 
00104 class t3lib_tsparser_ext extends t3lib_TStemplate       {
00105 
00106         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.
00107         var $HTMLcolorList = "aqua,black,blue,fuchsia,gray,green,lime,maroon,navy,olive,purple,red,silver,teal,yellow,white";
00108 
00109                 // internal
00110         var $categories = array(
00111                 "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.
00112                 "menu" => array(),              // Menu setup. This includes fontfiles, sizes, background images. Depending on the menutype.
00113                 "content" => array(),   // All constants related to the display of pagecontent elements
00114                 "page" => array(),              // General configuration like metatags, link targets
00115                 "advanced" => array(),  // Advanced functions, which are used very seldomly.
00116                 "all" => array()                // All constants are put here also!
00117         );              // This will be filled with the available categories of the current template.
00118         var $subCategories = array(
00119         // Standard categories:
00120                 "enable" => Array("Enable features", "a"),
00121                 "dims" => Array("Dimensions, widths, heights, pixels", "b"),
00122                 "file" => Array("Files", "c"),
00123                 "typo"  => Array("Typography", "d"),
00124                 "color" => Array("Colors", "e"),
00125                 "links" => Array("Links and targets", "f"),
00126                 "language" => Array("Language specific constants", "g"),
00127 
00128         // subcategories based on the default content elements
00129                 "cheader" => Array("Content: 'Header'", "ma"),
00130                 "cheader_g" => Array("Content: 'Header', Graphical", "ma"),
00131                 "ctext" => Array("Content: 'Text'", "mb"),
00132 //              "ctextpic" =>
00133                 "cimage" => Array("Content: 'Image'", "md"),
00134                 "cbullets" => Array("Content: 'Bullet list'", "me"),
00135                 "ctable" => Array("Content: 'Table'", "mf"),
00136                 "cuploads" => Array("Content: 'Filelinks'", "mg"),
00137                 "cmultimedia" => Array("Content: 'Multimedia'", "mh"),
00138                 "cmailform" => Array("Content: 'Form'", "mi"),
00139                 "csearch" => Array("Content: 'Search'", "mj"),
00140                 "clogin" => Array("Content: 'Login'", "mk"),
00141                 "csplash" => Array("Content: 'Textbox'", "ml"),
00142                 "cmenu" => Array("Content: 'Menu/Sitemap'", "mm"),
00143                 "cshortcut" => Array("Content: 'Insert records'", "mn"),
00144                 "clist" => Array("Content: 'List of records'", "mo"),
00145                 "cscript" => Array("Content: 'Script'", "mp"),
00146                 "chtml" => Array("Content: 'HTML'", "mq")
00147         );
00148         var $resourceDimensions = array();
00149         var $dirResources = array();
00150 
00151 //      var $matchAll = 0;              // If set, all conditions are matched!
00152 
00153         var $backend_info=1;
00154 
00155                 // tsconstanteditor
00156         var $ext_inBrace=0;
00157 
00158                 // tsbrowser
00159         var $tsbrowser_searchKeys = array();
00160         var $tsbrowser_depthKeys = array();
00161         var $constantMode="";
00162         var $regexMode="";
00163         var $fixedLgd="";
00164         var $resourceCheck=0;
00165         var $ext_lineNumberOffset=0;
00166         var $ext_localGfxPrefix="";
00167         var $ext_localWebGfxPrefix="";
00168         var $ext_expandAllNotes=0;
00169         var $ext_noPMicons=0;
00170         var $ext_noSpecialCharsOnLabels=0;
00171         var $ext_listOfTemplatesArr=array();
00172         var $ext_lineNumberOffset_mode="";
00173         var $ext_dontCheckIssetValues=0;        // Dont change...
00174         var $ext_noCEUploadAndCopying=0;
00175         var $ext_printAll=0;
00176         var $ext_CEformName="forms[0]";
00177         var $ext_defaultOnlineResourceFlag=0;
00178         var $doNotSortCategoriesBeforeMakingForm = FALSE;
00179 
00180                 // ts analyzer
00181         var $templateTitles=array();
00182 
00183 
00193         function flattenSetup($setupArray, $prefix, $resourceFlag)      {
00194                 if (is_array($setupArray))      {
00195                         $this->getFileName_backPath=PATH_site;          // Setting absolute prefixed path for relative resources.
00196                         reset($setupArray);
00197                         while(list($key,$val)=each($setupArray))        {
00198                                 if ($prefix || substr($key,0,16)!="TSConstantEditor")   {               // We don't want "TSConstantEditor" in the flattend setup.
00199                                         if (is_array($val))     {
00200                                                 $this->flattenSetup($val,$prefix.$key, ($key=="file."));
00201                                         } elseif ($resourceFlag && $this->resourceCheck) {
00202                                                 $this->flatSetup[$prefix.$key] = $this->getFileName($val);
00203                                                 if ($this->removeFromGetFilePath && substr($this->flatSetup[$prefix.$key],0,strlen($this->removeFromGetFilePath))==$this->removeFromGetFilePath)        {
00204                                                         $this->flatSetup[$prefix.$key] = substr($this->flatSetup[$prefix.$key],strlen($this->removeFromGetFilePath));
00205                                                 }
00206                                         } else {
00207                                                 $this->flatSetup[$prefix.$key] = $val;
00208                                         }
00209                                 }
00210                         }
00211                 }
00212         }
00213 
00220         function substituteConstants($all)      {
00221                 $this->Cmarker=substr(md5(uniqid("")),0,6);
00222                 reset($this->flatSetup);
00223                 while (list($const,$val)=each($this->flatSetup))        {
00224                         if (!is_array($val))    {
00225                                 switch($this->constantMode)     {
00226                                         case "const":
00227                                                 $all = str_replace('{$'.$const.'}','##'.$this->Cmarker.'_B##{$'.$const.'}##'.$this->Cmarker.'_E##',$all);
00228                                         break;
00229                                         case "subst":
00230                                                 $all = str_replace('{$'.$const.'}','##'.$this->Cmarker.'_B##'.$val.'##'.$this->Cmarker.'_E##',$all);
00231                                         break;
00232                                         case "untouched":
00233                                         break;
00234                                         default:
00235                                                 $all = str_replace('{$'.$const.'}',$val,$all);
00236                                         break;
00237                                 }
00238                         }
00239                 }
00240                 return $all;
00241         }
00242 
00249         function substituteCMarkers($all)       {
00250                 switch($this->constantMode)     {
00251                         case "const":
00252                                 $all = str_replace('##'.$this->Cmarker.'_B##', '<font color="green"><B>', $all);
00253                                 $all = str_replace('##'.$this->Cmarker.'_E##', '</b></font>', $all);
00254                         break;
00255                         case "subst":
00256                                 $all = str_replace('##'.$this->Cmarker.'_B##', '<font color="green"><B>', $all);
00257                                 $all = str_replace('##'.$this->Cmarker.'_E##', '</b></font>', $all);
00258                         break;
00259                         default:
00260                                 $all = $all;
00261                         break;
00262                 }
00263                 return $all;
00264         }
00265 
00271         function generateConfig_constants()     {
00272                         // Parses the constants in $this->const with respect to the constant-editor in this module.
00273                         // In particular comments in the code are registered and the edit_divider is taken into account.
00274                         // These vars are also set lateron...
00275                 $this->setup["resources"]= $this->resources;
00276                 $this->setup["sitetitle"]= $this->sitetitle;
00277 
00278                         // parse constants
00279                 $constants = t3lib_div::makeInstance("t3lib_TSparser");
00280                 $constants->regComments=1;              // Register comments!
00281                 $constants->setup = $this->const;
00282                 $constants->setup = $this->mergeConstantsFromPageTSconfig($constants->setup);
00283 
00284                 $matchObj = t3lib_div::makeInstance("t3lib_matchCondition");
00285 //              $matchObj->matchAlternative = array("[globalString =  page | title = *test*]");
00286                 $matchObj->matchAll=1;          // Matches ALL conditions in TypoScript
00287 
00288                 $c=0;
00289                 $cc=count($this->constants);
00290                 reset($this->constants);
00291                 while (list(,$str)=each($this->constants))      {
00292                         $c++;
00293                         if ($c==$cc)    {
00294                                 if (strstr($str,$this->edit_divider))   {
00295                                         $parts = explode($this->edit_divider,$str,2);
00296                                         $str=$parts[1];
00297                                         $constants->parse($parts[0],$matchObj);
00298                                 }
00299                                 $this->flatSetup = Array();
00300                                 $this->flattenSetup($constants->setup,"","");
00301                                 $defaultConstants=$this->flatSetup;
00302                         }
00303                         $constants->parse($str,$matchObj);
00304                 }
00305 
00306                 $this->flatSetup = Array();
00307                 $this->flattenSetup($constants->setup,"","");
00308                 $this->setup["constants"] = $constants->setup;
00309 
00310                 return $this->ext_compareFlatSetups($defaultConstants);
00311         }
00312 
00320         function ext_getSetup($theSetup,$theKey)        {
00321                 $parts = explode(".",$theKey,2);
00322 //              debug("-----------",1);
00323 //              debug($theKey,1);
00324                 if (strcmp($parts[0],"") && is_array($theSetup[$parts[0]."."])) {
00325 //                      debug(trim($parts[1]),1);
00326                         if (strcmp(trim($parts[1]),"")) {
00327 //                      debug(trim($parts[1]),1);
00328                                 return $this->ext_getSetup($theSetup[$parts[0]."."],trim($parts[1]));
00329                         } else {
00330                                 return array($theSetup[$parts[0]."."], $theSetup[$parts[0]]);
00331                         }
00332                 } else {
00333                         if (strcmp(trim($theKey),""))   {
00334                                 return array(array(),$theSetup[$theKey]);
00335                         } else {
00336                                 return array($theSetup,"");
00337                         }
00338                 }
00339         }
00340 
00351         function ext_getObjTree($arr, $depth_in, $depthData, $parentType="",$parentValue="")    {
00352                 $HTML="";
00353                 $a=0;
00354 
00355                 reset($arr);
00356                 $keyArr_num=array();
00357                 $keyArr_alpha=array();
00358                 while (list($key,)=each($arr))  {
00359                         if (substr($key,-2)!="..")      {       // Don't do anything with comments / linenumber registrations...
00360                                 $key=ereg_replace("\.$","",$key);
00361                                 if (substr($key,-1)!=".")       {
00362                                         if (t3lib_div::testInt($key))   {
00363                                                 $keyArr_num[$key]=$arr[$key];
00364                                         } else {
00365                                                 $keyArr_alpha[$key]=$arr[$key];
00366                                         }
00367                                 }
00368                         }
00369                 }
00370                 ksort($keyArr_num);
00371                 $keyArr=$keyArr_num+$keyArr_alpha;
00372                 reset($keyArr);
00373                 $c=count($keyArr);
00374                 if ($depth_in)  {$depth_in = $depth_in.".";}
00375 
00376 //              $validate_info= verify_TSobjects($keyArr,$parentType,$parentValue);
00377 //              debug($validate_info);
00378 
00379                 while (list($key,)=each($keyArr))       {
00380                         $a++;
00381                         $depth=$depth_in.$key;
00382                         if ($this->bType!="const" || substr($depth,0,1)!="_")   {               // this excludes all constants starting with "_" from being shown.
00383                                 $goto = substr(md5($depth),0,6);
00384         //                      debug($depth);
00385                                 $deeper = (is_array($arr[$key."."]) && ($this->tsbrowser_depthKeys[$depth] || $this->ext_expandAllNotes)) ? 1 : 0;
00386                                 $PM = "join";
00387                                 $LN = ($a==$c)?"blank":"line";
00388                                 $BTM = ($a==$c)?"bottom":"";
00389                                 $PM = is_array($arr[$key."."]) && !$this->ext_noPMicons ? ($deeper ? "minus":"plus") : "join";
00390 
00391                                 $HTML.=$depthData;
00392                                 $theIcon='<img src="'.$GLOBALS["BACK_PATH"].'t3lib/gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top" border="0" alt="" />';
00393                                 if ($PM=="join")        {
00394                                         $HTML.=$theIcon;
00395                                 } else {
00396                                         $aHref='index.php?id='.$GLOBALS["SOBE"]->id.'&tsbr['.$depth.']='.($deeper?0:1).'#'.$goto;
00397                                         $HTML.='<a name="'.$goto.'" href="'.htmlspecialchars($aHref).'">'.$theIcon.'</a>';
00398                                 }
00399 
00400                                 $label = $key;
00401                                 if (t3lib_div::inList("types,resources,sitetitle",$depth) && $this->bType=="setup")     {               // Read only...
00402                                         $label='<font color="#666666">'.$label.'</font>';
00403                                 } else {
00404                                         if ($this->linkObjects) {
00405                                                 $aHref = 'index.php?id='.$GLOBALS["SOBE"]->id.'&sObj='.$depth;
00406                                                 if ($this->bType!="const")      {
00407                                                         $ln = is_array($arr[$key.'.ln..']) ? 'Defined in: '.$this->lineNumberToScript($arr[$key.'.ln..']) : 'N/A';
00408                                                 } else {
00409                                                         $ln = '';
00410                                                 }
00411                                                 $label = '<a href="'.htmlspecialchars($aHref).'" title="'.htmlspecialchars($ln).'">'.$label.'</a>';
00412                                         }
00413                                 }
00414 
00415                                 $HTML.="[".$label."]";
00416 
00417                                 if (isset($arr[$key]))  {
00418                                         $theValue = $arr[$key];
00419                                         if ($this->fixedLgd)    {
00420                                                 $imgBlocks = ceil(1+strlen($depthData)/77);
00421                                                 $lgdChars = 68-ceil(strlen("[".$key."]")*0.8)-$imgBlocks*3;
00422                                                 $theValue = $this->ext_fixed_lgd($theValue,$lgdChars);
00423                                         }
00424                                         if ($this->tsbrowser_searchKeys[$depth])        {
00425                                                 $HTML.='=<b><font color="red">'.$this->makeHtmlspecialchars($theValue).'</font></b>';
00426                                         } else {
00427                                                 $HTML.="=<b>".$this->makeHtmlspecialchars($theValue)."</b>";
00428                                         }
00429                                 }
00430                                 $HTML.="<br />";
00431 
00432                                 if ($deeper)    {
00433                                         $HTML.=$this->ext_getObjTree($arr[$key."."], $depth, $depthData.'<img src="'.$GLOBALS["BACK_PATH"].'t3lib/gfx/ol/'.$LN.'.gif" width="18" height="16" align="top" alt="" />', $validate_info[$key], $arr[$key]);
00434                                 }
00435                         }
00436                 }
00437                 return $HTML;
00438         }
00439 
00446         function lineNumberToScript($lnArr)     {
00447                 if (!is_array($this->lnToScript))       {
00448                         $this->lnToScript = array();
00449                         $c=1;
00450                         $c+=substr_count($GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'],chr(10))+2;
00451                         $this->lnToScript[$c] = '[Default]';
00452 
00453                         foreach($this->hierarchyInfoToRoot as $info)    {
00454                                 $c+=$info['configLines']+1;
00455                                 $this->lnToScript[$c] = $info['title'];
00456                         }
00457                 }
00458 
00459                 foreach($lnArr as $k => $ln)    {
00460                         foreach($this->lnToScript as $endLn => $title)  {
00461                                 if ($endLn >= intval($ln))      {
00462                                         $lnArr[$k] = '"'.$title.'", '.$ln;
00463                                         break;
00464                                 }
00465                         }
00466                 }
00467 
00468                 return implode('; ',$lnArr);
00469         }
00470 
00477         function makeHtmlspecialchars($theValue){
00478                 return $this->ext_noSpecialCharsOnLabels ? $theValue : htmlspecialchars($theValue);
00479         }
00480 
00490         function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray)           {
00491                 reset($arr);
00492                 $keyArr=array();
00493                 while (list($key,)=each($arr))  {
00494                         $key=ereg_replace("\.$","",$key);
00495                         if (substr($key,-1)!=".")       {
00496                                 $keyArr[$key]=1;
00497                         }
00498                 }
00499                 reset($keyArr);
00500 //              asort($keyArr);
00501                 $c=count($keyArr);
00502                 if ($depth_in)  {$depth_in = $depth_in.".";}
00503                 while (list($key,)=each($keyArr))       {
00504                         $depth=$depth_in.$key;
00505                         $deeper = is_array($arr[$key."."]);
00506 
00507                         if ($this->regexMode)   {
00508                                 if (ereg($searchString,$arr[$key]))     {       $this->tsbrowser_searchKeys[$depth]=1;  }
00509                         } else {
00510                                 if (stristr($arr[$key],$searchString))  {       $this->tsbrowser_searchKeys[$depth]=1;  }
00511                         }
00512 
00513                         if ($deeper)    {
00514                                 $cS = count($this->tsbrowser_searchKeys);
00515                                 $keyArray = $this->ext_getSearchKeys($arr[$key."."], $depth, $searchString, $keyArray);
00516                                 if ($cS != count($this->tsbrowser_searchKeys))  {
00517                                         $keyArray[$depth]=1;
00518                                 }
00519                         }
00520                 }
00521                 return $keyArray;
00522         }
00523 
00530         function ext_getRootlineNumber($pid)    {
00531                 if ($pid && is_array($GLOBALS["rootLine"]))     {
00532                         reset($GLOBALS["rootLine"]);
00533                         while(list($key,$val)=each($GLOBALS["rootLine"]))       {
00534                                 if ($val['uid']==$pid)  return $key;
00535                         }
00536                 }
00537         }
00538 
00548         function ext_getTemplateHierarchyArr($arr,$depthData, $keyArray,$first=0)       {
00549                 reset($arr);
00550                 $keyArr=array();
00551                 while (list($key,)=each($arr))  {
00552                         $key=ereg_replace("\.$","",$key);
00553                         if (substr($key,-1)!=".")       {
00554                                 $keyArr[$key]=1;
00555                         }
00556                 }
00557                 reset($keyArr);
00558                 $a=0;
00559                 $c=count($keyArr);
00560                 while (list($key,)=each($keyArr))       {
00561                         $HTML="";
00562                         $a++;
00563                         $deeper = is_array($arr[$key."."]);
00564                         $row=$arr[$key];
00565 
00566                         $PM = "join";
00567                         $LN = ($a==$c)?"blank":"line";
00568                         $BTM = ($a==$c)?"top":"";
00569                         $PM = "join";
00570 
00571                         $HTML.=$depthData;
00572                         $icon = substr($row["templateID"],0,3)=="sys" ? t3lib_iconWorks::getIcon("sys_template",array("root"=>$row["root"])) :
00573                                                         (substr($row["templateID"],0,6)=="static" ? t3lib_iconWorks::getIcon("static_template",array()) : 'gfx/i/default.gif');
00574                         $alttext= "[".$row['templateID']."]";
00575                         $alttext.= $row['pid'] ? " - ".t3lib_BEfunc::getRecordPath($row['pid'],$GLOBALS["SOBE"]->perms_clause,20) : "";
00576                         if (in_array($row['templateID'],$this->clearList_const) || in_array($row['templateID'],$this->clearList_setup)) {
00577                                 $A_B='<a href="index.php?id='.$GLOBALS["SOBE"]->id.'&template='.$row['templateID'].'">';
00578                                 $A_E="</A>";
00579                         } else {
00580                                 $A_B="";
00581                                 $A_E="";
00582                         }
00583                         $HTML.=($first?'':'<IMG src="'.$GLOBALS["BACK_PATH"].'t3lib/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;";
00584                         $RL = $this->ext_getRootlineNumber($row['pid']);
00585                         $keyArray[] = '<tr>
00586                                                         <td nowrap>'.$HTML.'</td>
00587                                                         <td align=center>'.($row["root"]?"<b>X</b>":"").'&nbsp;&nbsp;</td>
00588                                                         <td align=center'.$row["bgcolor_setup"].'>'.fw(($row["clConf"]?"<b>X</b>":"")."&nbsp;&nbsp;").'</td>
00589                                                         <td align=center'.$row["bgcolor_const"].'>'.fw(($row["clConst"]?"<b>X</b>":"")."&nbsp;&nbsp;").'</td>
00590                                                         <td>'.($row["pid"]?"&nbsp;".$row["pid"].(strcmp($RL,"")?" (".$RL.")":"")."&nbsp;&nbsp;":"").'</td>
00591                                                         <td>'.($row["next"]?"&nbsp;".$row["next"]."&nbsp;&nbsp;":"").'</td>
00592                                                 </tr>';
00593                         if ($deeper)    {
00594                                 $keyArray = $this->ext_getTemplateHierarchyArr($arr[$key."."], $depthData.($first?'':'<IMG src="'.$GLOBALS["BACK_PATH"].'t3lib/gfx/ol/'.$LN.'.gif" width="18" height="16" align="top">'), $keyArray);
00595                         }
00596                 }
00597                 return $keyArray;
00598         }
00599 
00607         function ext_process_hierarchyInfo($depthDataArr,&$pointer)     {
00608                 $parent = $this->hierarchyInfo[$pointer-1]['templateParent'];
00609                 while ($pointer>0 && $this->hierarchyInfo[$pointer-1]['templateParent']==$parent)       {
00610                         $pointer--;
00611                         $row = $this->hierarchyInfo[$pointer];
00612 
00613                         $depthDataArr[$row['templateID']]=$row;
00614                         $depthDataArr[$row['templateID']]["bgcolor_setup"] = isset($this->clearList_setup_temp[$row['templateID']])?' class="bgColor5"':'';
00615                         $depthDataArr[$row['templateID']]["bgcolor_const"] = isset($this->clearList_const_temp[$row['templateID']])?' class="bgColor5"':'';
00616                         unset($this->clearList_setup_temp[$row['templateID']]);
00617                         unset($this->clearList_const_temp[$row['templateID']]);
00618                         $this->templateTitles[$row['templateID']]=$row["title"];
00619 
00620                         if ($row['templateID']==$this->hierarchyInfo[$pointer-1]['templateParent'])     {
00621                                 $depthDataArr[$row['templateID']."."] = $this->ext_process_hierarchyInfo(array(), $pointer);
00622                         }
00623                 }
00624                 return $depthDataArr;
00625         }
00626 
00638         function ext_outputTS($config, $lineNumbers=0, $comments=0, $crop=0, $syntaxHL=0, $syntaxHLBlockmode=0) {
00639                 $all="";
00640                 reset($config);
00641                 while (list(,$str)=each($config))       {
00642                         $all.="\n[GLOBAL]\n".$str;
00643                 }
00644 
00645                 if ($syntaxHL)  {
00646                         $all = ereg_replace("^[^".chr(10)."]*.","",$all);
00647                         $all = chop($all);
00648                         $tsparser = t3lib_div::makeInstance("t3lib_TSparser");
00649                         $tsparser->lineNumberOffset=$this->ext_lineNumberOffset+1;
00650                         return $tsparser->doSyntaxHighlight($all,$lineNumbers?array($this->ext_lineNumberOffset+1):'',$syntaxHLBlockmode);
00651                 } else {
00652                         return $this->ext_formatTS($all,$lineNumbers,$comments,$crop);
00653                 }
00654         }
00655 
00665         function ext_fixed_lgd($string,$chars)  {
00666                 if ($chars >= 4)        {
00667                         if(strlen($string)>$chars)  {
00668                                 return substr($string, 0, $chars-3)."...";
00669                         }
00670                 }
00671                 return $string;
00672         }
00673 
00681         function ext_lnBreakPointWrap($ln,$str) {
00682                 return '<A href="#" onClick="return brPoint('.$ln.','.($this->ext_lineNumberOffset_mode=="setup"?1:0).');">'.$str.'</a>';
00683         }
00684 
00694         function ext_formatTS($input, $ln, $comments=1, $crop=0)        {
00695                 $input = ereg_replace("^[^".chr(10)."]*.","",$input);
00696                 $input = chop($input);
00697                 $cArr = explode(chr(10),$input);
00698 
00699                 reset($cArr);
00700                 $n = ceil(log10(count($cArr)+$this->ext_lineNumberOffset));
00701                 $lineNum="";
00702                 while(list($k,$v)=each($cArr))  {
00703                         $lln=$k+$this->ext_lineNumberOffset+1;
00704                         if ($ln)        $lineNum = $this->ext_lnBreakPointWrap($lln,str_replace(" ",'&nbsp;',sprintf("% ".$n."d",$lln))).":   ";
00705                         $v=htmlspecialchars($v);
00706                         if ($crop)      {$v=$this->ext_fixed_lgd($v,($ln?71:77));}
00707                         $cArr[$k] = $lineNum.str_replace(" ",'&nbsp;',$v);
00708 
00709                         $firstChar = substr(trim($v),0,1);
00710                         if ($firstChar=="[")    {
00711                                 $cArr[$k] = '<font color="green"><b>'.$cArr[$k].'</b></font>';
00712                         } elseif ($firstChar=="/" || $firstChar=="#")   {
00713                                 if ($comments)  {
00714                                         $cArr[$k] = '<span class="typo3-dimmed">'.$cArr[$k].'</span>';
00715                                 } else {
00716                                         unset($cArr[$k]);
00717                                 }
00718                         }
00719 
00720 
00721                 }
00722                 $output = implode($cArr, "<BR>")."<BR>";
00723                 return $output;
00724         }
00725 
00733         function ext_getFirstTemplate($id,$template_uid=0)              {
00734                         // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
00735                 if (intval($id))        {
00736                         if ($template_uid)      {
00737                                 $addC = " AND uid=".$template_uid;
00738                         }
00739                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).$addC.' '.$this->whereClause, '', 'sorting', '1');
00740                         $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00741                         $GLOBALS['TYPO3_DB']->sql_free_result($res);
00742                         return $row;    // Returns the template row if found.
00743                 }
00744         }
00745 
00752         function ext_getAllTemplates($id)               {
00753                         // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
00754                 if (intval($id))        {
00755                         $outRes=array();
00756                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).' '.$this->whereClause, '', 'sorting');
00757                         while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00758                                 $outRes[] = $row;
00759                         }
00760                         $GLOBALS['TYPO3_DB']->sql_free_result($res);
00761                         return $outRes; // Returns the template rows in an array.
00762                 }
00763         }
00764 
00772         function ext_compareFlatSetups($default)        {
00773                 $editableComments=array();
00774                 reset($this->flatSetup);
00775                 while(list($const,$value)=each($this->flatSetup))       {
00776                         if (substr($const,-2)!=".." && isset($this->flatSetup[$const.".."]))    {
00777                                 $comment = trim($this->flatSetup[$const.".."]);
00778                                 $c_arr = explode(chr(10),$comment);
00779                                 while(list($k,$v)=each($c_arr)) {
00780                                         $line=trim(ereg_replace("^[#\/]*","",$v));
00781                                         if ($line)      {
00782                                                 $parts = explode(";", $line);
00783                                                 while(list(,$par)=each($parts))         {
00784                                                         if (strstr($par,"="))   {
00785                                                                 $keyValPair =explode("=",$par,2);
00786                                                                 switch(trim(strtolower($keyValPair[0])))        {
00787                                                                         case "type":
00788                                                                                         // Type:
00789                                                                                         /*
00790         int (range; low-high, list: item,item,item = selector),
00791         boolean (check),
00792         string (default),
00793         wrap,
00794         html-color ...,
00795         file
00796                                                                                         */
00797                                                                                 $editableComments[$const]["type"] = trim($keyValPair[1]);
00798                                                                         break;
00799                                                                         case "cat":
00800                                                                                         // list of categories.
00801                                                                                 $catSplit=explode("/",strtolower($keyValPair[1]));
00802                                                                                 $editableComments[$const]["cat"] = trim($catSplit[0]);
00803                                                                                 $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.
00804                                                                                 if ($catSplit[1] && isset($this->subCategories[$catSplit[1]]))  {
00805                                                                                         $editableComments[$const]["subcat_name"]=$catSplit[1];
00806                                                                                         $editableComments[$const]["subcat"]=$this->subCategories[$catSplit[1]][1]."/".$catSplit[1]."/".trim($catSplit[2])."z";
00807                                                                                 } else {
00808                                                                                         $editableComments[$const]["subcat"]="x"."/".trim($catSplit[2])."z";
00809                                                                                 }
00810                                                                         break;
00811                                                                         case "label":
00812                                                                                         // label
00813                                                                                 $editableComments[$const]["label"] = trim($keyValPair[1]);
00814                                                                         break;
00815                                                                 }
00816                                                         }
00817                                                 }
00818                                         }
00819                                 }
00820                         }
00821                         if (isset($editableComments[$const]))   {
00822                                 $editableComments[$const]["name"]=$const;
00823                                 $editableComments[$const]["value"]=trim($value);
00824                                 if (isset($default[$const]))    {
00825                                         $editableComments[$const]["default_value"]=trim($default[$const]);
00826                                 }
00827                         }
00828                 }
00829                 return $editableComments;
00830         }
00831 
00838         function ext_categorizeEditableConstants($editConstArray)       {
00839                 // Runs through the available constants and fills the $this->categories array with pointers and priority-info
00840                 reset($editConstArray);
00841                 while(list($constName,$constData)=each($editConstArray))        {
00842                         if (!$constData["type"])        {$constData["type"]="string";}
00843                         $cats = explode(",",$constData["cat"]);
00844                         reset($cats);
00845                         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...
00846                                 $theCat=trim($theCat);
00847                                 if ($theCat)    {
00848                                         $this->categories[$theCat][$constName]=$constData["subcat"];
00849 //                                      $this->categories["all"][$constName]=$constData["subcat"];
00850                                 }
00851                         }
00852                 }
00853 //              debug($this->categories);
00854         }
00855 
00861         function ext_getCategoryLabelArray()    {
00862                 // Returns array used for labels in the menu.
00863                 $retArr = array();
00864                 while(list($k,$v)=each($this->categories))      {
00865                         if (count($v))  {
00866                                 $retArr[$k]=strtoupper($k)." (".count($v).")";
00867                         }
00868                 }
00869                 return $retArr;
00870         }
00871 
00878         function ext_getTypeData($type) {
00879                 $retArr = array();
00880                 $type=trim($type);
00881                 if (!$type)     {
00882                         $retArr["type"]="string";
00883                 } else {
00884                         $m=strcspn ($type," [");
00885                         $retArr["type"]=strtolower(substr($type,0,$m));
00886                         if (t3lib_div::inList("int,options,file,boolean,offset",$retArr["type"]))       {
00887                                 $p=trim(substr($type,$m));
00888                                 ereg("\[(.*)\]",$p,$reg);
00889                                 $p=trim($reg[1]);
00890                                 if ($p) {
00891                                         $retArr["paramstr"]=$p;
00892                                         switch($retArr["type"]) {
00893                                                 case "int":
00894                                                         if (substr($retArr["paramstr"],0,1)=="-")       {
00895                                                                 $retArr["params"]=t3lib_div::intExplode("-",substr($retArr["paramstr"],1));
00896                                                                 $retArr["params"][0]=intval("-".$retArr["params"][0]);
00897                                                         } else {
00898                                                                 $retArr["params"]=t3lib_div::intExplode("-",$retArr["paramstr"]);
00899                                                         }
00900                                                         $retArr["paramstr"]=$retArr["params"][0]." - ".$retArr["params"][1];
00901                                                 break;
00902                                                 case "options":
00903                                                         $retArr["params"]=explode(",",$retArr["paramstr"]);
00904                                                 break;
00905                                         }
00906                                 }
00907                         }
00908                 }
00909 //              debug($retArr);
00910                 return $retArr;
00911         }
00912 
00919         function ext_getTSCE_config($category)  {
00920                 $catConf=$this->setup["constants"]["TSConstantEditor."][$category."."];
00921                 $out=array();
00922                 if (is_array($catConf)) {
00923                         reset($catConf);
00924                         while(list($key,$val)=each($catConf))   {
00925                                 switch($key)    {
00926                                         case "image":
00927                                                 $out["imagetag"] = $this->ext_getTSCE_config_image($catConf["image"]);
00928                                         break;
00929                                         case "description":
00930                                         case "bulletlist":
00931                                         case "header":
00932                                                 $out[$key] = $val;
00933                                         break;
00934                                         default:
00935                                                 if (t3lib_div::testInt($key))   {
00936                                                         $constRefs = explode(",",$val);
00937                                                         reset($constRefs);
00938                                                         while(list(,$const)=each($constRefs))   {
00939                                                                 $const=trim($const);
00940                                                                 if ($const && $const<=20)       {
00941                                                                         $out["constants"][$const].=$this->ext_getKeyImage($key);
00942                                                                 }
00943                                                         }
00944                                                 }
00945                                         break;
00946                                 }
00947                         }
00948                 }
00949                 $this->helpConfig=$out;
00950         }
00951 
00958         function ext_getKeyImage($key)  {
00959                 return '<img src="'.$this->ext_localWebGfxPrefix.'gfx/'.$key.'.gif" align="top" hspace=2>';
00960         }
00961 
00968         function ext_getTSCE_config_image($imgConf)     {
00969                 if (substr($imgConf,0,4)=="gfx/")       {
00970                         $iFile=$this->ext_localGfxPrefix.$imgConf;
00971                         $tFile=$this->ext_localWebGfxPrefix.$imgConf;
00972                 } elseif (substr($imgConf,0,4)=='EXT:') {
00973                         $iFile = t3lib_div::getFileAbsFileName($imgConf);
00974                         if ($iFile)     {
00975                                 $f = substr($iFile,strlen(PATH_site));
00976                                 $tFile=$GLOBALS["BACK_PATH"]."../".$f;
00977                         }
00978                 } else {
00979                         $f = "uploads/tf/".$this->extractFromResources($this->setup["resources"],$imgConf);
00980                         $iFile=PATH_site.$f;
00981                         $tFile=$GLOBALS["BACK_PATH"]."../".$f;
00982                 }
00983                 $imageInfo=@getImagesize($iFile);
00984                 return '<img src="'.$tFile.'" '.$imageInfo[3].'>';
00985         }
00986 
00992         function ext_resourceDims()     {
00993                 if ($this->setup["resources"])  {
00994                         $rArr=explode(",",$this->setup["resources"]);
00995                         while(list($c,$val)=each($rArr))        {
00996                                 $val=trim($val);
00997                                 $theFile = PATH_site."uploads/tf/".$val;
00998                                 if ($val && @is_file($theFile)) {
00999                                         $imgInfo = @getimagesize($theFile);
01000                                 }
01001                                 if (is_array($imgInfo)) {
01002                                         $this->resourceDimensions[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
01003                                 }
01004                         }
01005                 }
01006                 reset($this->dirResources);
01007                 while(list($c,$val)=each($this->dirResources))  {
01008                         $val=trim($val);
01009                         $imgInfo = @getimagesize(PATH_site.$val);
01010                         if (is_array($imgInfo)) {
01011                                 $this->resourceDimensions[$val]=" (".$imgInfo[0]."x".$imgInfo[1].")";
01012                         }
01013                 }
01014         }
01015 
01022         function ext_readDirResources($path)    {
01023                 $path=trim($path);
01024                 if ($path && substr($path,0,10)=="fileadmin/")  {
01025                         $path = ereg_replace("\/$","",$path);
01026                         $this->readDirectory(PATH_site.$path);
01027                 }
01028         }
01029 
01037         function readDirectory($path,$type="file")      {
01038                 if(@is_dir($path))      {
01039                         $d = @dir($path);
01040                         $tempArray=Array();
01041                         if (is_object($d))      {
01042                                 while($entry=$d->read()) {
01043                                         if ($entry!="." && $entry!="..")        {
01044                                                 $wholePath = $path."/".$entry;          // Because of odd PHP-error where  <BR>-tag is sometimes placed after a filename!!
01045                                                 if (@file_exists($wholePath) && (!$type || filetype($wholePath)==$type))        {
01046                                                         $fI = t3lib_div::split_fileref($wholePath);
01047                                                         $this->dirResources[]=substr($wholePath,strlen(PATH_site));
01048                                                 }
01049                                         }
01050                                 }
01051                                 $d->close();
01052                         }
01053                 }
01054         }
01055 
01062         function ext_fNandV($params)    {
01063                 $fN='data['.$params["name"].']';
01064                 $fV=$params["value"];
01065                 if (ereg("^{[\$][a-zA-Z0-9\.]*}$",trim($fV),$reg))      {               // Values entered from the constantsedit cannot be constants!   230502; removed \{ and set {
01066                         $fV="";
01067                 }
01068                 $fV=htmlspecialchars($fV);
01069 
01070                 return array($fN,$fV,$params);
01071         }
01072 
01080         function ext_printFields($theConstants,$category)       {
01081                         // This functions returns the HTML-code that creates the editor-layout of the module.
01082                 reset($theConstants);
01083                 $output="";
01084                 $subcat="";
01085                 if (is_array($this->categories[$category]))     {
01086 
01087                         $help=$this->helpConfig;
01088                         $this->rArr=explode(",",$this->setup["resources"].",".implode($this->dirResources,","));
01089 
01090                         if (!$this->doNotSortCategoriesBeforeMakingForm) asort($this->categories[$category]);
01091                         while(list($name,$type)=each($this->categories[$category]))     {
01092                                 $params = $theConstants[$name];
01093                                 if (is_array($params))  {
01094                                         if ($subcat!=$params["subcat_name"])    {
01095                                                 $subcat=$params["subcat_name"];
01096                                                 $subcat_name = $params["subcat_name"] ? $this->subCategories[$params["subcat_name"]][0] : "Others";
01097                                                 $output.='<tr>';
01098                                                 $output.='<td colspan=2 class="bgColor4"><div align="center"><b>'.$subcat_name.'</b></div></td>';
01099                                                 $output.='</tr>';
01100                                         }
01101 
01102                         //              if (substr($params["value"],0,2)!='{$') {
01103                                                 $label=$GLOBALS["LANG"]->sL($params["label"]);
01104                                                 $label_parts = explode(":",$label,2);
01105                                                 if (count($label_parts)==2)     {
01106                                                         $head=trim($label_parts[0]);
01107                                                         $body=trim($label_parts[1]);
01108                                                 } else {
01109                                                         $head=trim($label_parts[0]);
01110                                                         $body="";
01111                                                 }
01112                                                 if (strlen($head)>35)   {
01113                                                         if (!$body) {$body=$head;}
01114                                                         $head=t3lib_div::fixed_lgd_cs($head,35);
01115                                                 }
01116                                                 $typeDat=$this->ext_getTypeData($params["type"]);
01117                                                 $checked="";
01118                                                 $p_field="";
01119                                                 $raname = substr(md5($params["name"]),0,10);
01120                                                 $aname="'".$raname."'";
01121                                                 if ($this->ext_dontCheckIssetValues || isset($this->objReg[$params["name"]]))   {
01122                                                         $checked=" checked";
01123                                                         list($fN,$fV,$params)=$this->ext_fNandV($params);
01124 
01125                                                         switch($typeDat["type"])        {
01126                                                                 case "int":
01127                                                                 case "int+":
01128                                                                         $p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(5).' onChange="uFormUrl('.$aname.')">';
01129                                                                         if ($typeDat["paramstr"])       {
01130                                                                                 $p_field.=' Range: '.$typeDat["paramstr"];
01131                                                                         } elseif ($typeDat["type"]=="int+") {
01132                                                                                 $p_field.=' Range: 0 - ';
01133                                                                         } else {
01134                                                                                 $p_field.=' (Integer)';
01135                                                                         }
01136                                                                 break;
01137                                                                 case "color":
01138                                                                         $colorNames=explode(",",",".$this->HTMLcolorList);
01139                                                                         $p_field="";
01140                                                                         while(list(,$val)=each($colorNames))    {
01141                                                                                 $sel="";
01142                                                                                 if ($val==strtolower($params["value"])) {$sel=" selected";}
01143                                                                                 $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.'</option>';
01144                                                                         }
01145                                                                         $p_field='<select name="C'.$fN.'" onChange="document.'.$this->ext_CEformName.'[\''.$fN.'\'].value=this.options[this.selectedIndex].value; uFormUrl('.$aname.');">'.$p_field.'</select>';
01146 
01147                                                                         $p_field.='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(7).' onChange="uFormUrl('.$aname.')">';
01148                                                                 break;
01149                                                                 case "wrap":
01150                                                                         $wArr = explode("|",$fV);
01151                                                                         $p_field='<input type="text" name="'.$fN.'" value="'.$wArr[0].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(29).' onChange="uFormUrl('.$aname.')">';
01152                                                                         $p_field.=' | ';
01153                                                                         $p_field.='<input type="text" name="W'.$fN.'" value="'.$wArr[1].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(15).' onChange="uFormUrl('.$aname.')">';
01154                                                                 break;
01155                                                                 case "offset":
01156                                                                         $wArr = explode(",",$fV);
01157                                                                         $labels = t3lib_div::trimExplode(",",$typeDat["paramstr"]);
01158                                                                         $p_field=($labels[0]?$labels[0]:"x").':<input type="text" name="'.$fN.'" value="'.$wArr[0].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
01159                                                                         $p_field.=' , ';
01160                                                                         $p_field.=($labels[1]?$labels[1]:"y").':<input type="text" name="W'.$fN.'" value="'.$wArr[1].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
01161                                                                         for ($aa=2;$aa<count($labels);$aa++)    {
01162                                                                                 if ($labels[$aa])       {
01163                                                                                         $p_field.=' , '.$labels[$aa].':<input type="text" name="W'.$aa.$fN.'" value="'.$wArr[$aa].'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(4).' onChange="uFormUrl('.$aname.')">';
01164                                                                                 } else {
01165                                                                                         $p_field.='<input type="hidden" name="W'.$aa.$fN.'" value="'.$wArr[$aa].'">';
01166                                                                                 }
01167                                                                         }
01168                                                                 break;
01169                                                                 case "options":
01170                                                                         if (is_array($typeDat["params"]))       {
01171                                                                                 $p_field="";
01172                                                                                 while(list(,$val)=each($typeDat["params"]))     {
01173                                                                                         $vParts = explode("=",$val,2);
01174                                                                                         $label = $vParts[0];
01175                                                                                         $val = isset($vParts[1]) ? $vParts[1] : $vParts[0];
01176 
01177                                                                                                 // option tag:
01178                                                                                         $sel="";
01179                                                                                         if ($val==$params["value"])     {$sel=" selected";}
01180                                                                                         $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$GLOBALS["LANG"]->sL($label).'</option>';
01181                                                                                 }
01182                                                                                 $p_field='<select name="'.$fN.'" onChange="uFormUrl('.$aname.')">'.$p_field.'</select>';
01183                                                                         }
01184                                                                 break;
01185                                                                 case "boolean":
01186                                                                         $p_field='<input type="Hidden" name="'.$fN.'" value="0">';
01187                                                                         $sel=""; if ($fV)       {$sel=" checked";}
01188                                                                         $p_field.='<input type="Checkbox" name="'.$fN.'" value="'.($typeDat["paramstr"]?$typeDat["paramstr"]:1).'"'.$sel.' onClick="uFormUrl('.$aname.')">';
01189                                                                 break;
01190                                                                 case "comment":
01191                                                                         $p_field='<input type="Hidden" name="'.$fN.'" value="#">';
01192                                                                         $sel=""; if (!$fV)      {$sel=" checked";}
01193                                                                         $p_field.='<input type="Checkbox" name="'.$fN.'" value=""'.$sel.' onClick="uFormUrl('.$aname.')">';
01194                                                                 break;
01195                                                                 case "file":
01196                                                                         $p_field='<option value=""></option>';
01197 //                                                                      debug($params["value"]);
01198                                                                         $theImage="";
01199 //                                                                      if ($this->)    {
01200                                                                                 $selectThisFile = $this->extractFromResources($this->setup["resources"],$params["value"]);
01201                                                                                 if ($params["value"] && !$selectThisFile)       {
01202                                                                                         if (in_array($params["value"],$this->dirResources))     {
01203                                                                                                 $selectThisFile=$params["value"];
01204                                                                                         }
01205                                                                                 }
01206 //                                                                              debug($selectThisFile);
01207                                                                                         // extensionlist
01208                                                                                 $extList = $typeDat["paramstr"];
01209                                                                                 $p_field='<option value="">('.$extList.')</option>';
01210                                                                                 if ($extList=="IMAGE_EXT")      {
01211                                                                                         $extList = $GLOBALS["TYPO3_CONF_VARS"]["GFX"]["imagefile_ext"];
01212                                                                                 }
01213                                                                                 reset($this->rArr);
01214                                                                                 $onlineResourceFlag=$this->ext_defaultOnlineResourceFlag;
01215 
01216                                                                                 while(list($c,$val)=each($this->rArr))  {
01217                                                                                         $val=trim($val);
01218                                                                                         $fI=t3lib_div::split_fileref($val);
01219 //                                                                                      debug($fI);
01220                                                                                         if ($val && (!$extList || t3lib_div::inList($extList,$fI["fileext"])))  {
01221                                                                                                 if ($onlineResourceFlag<=0 && substr($fI["path"],0,10)=="fileadmin/")   {
01222                                                                                                         if ($onlineResourceFlag<0)      {
01223                                                                                                                 $p_field.='<option value=""></option>';
01224                                                                                                         }
01225                                                                                                         $p_field.='<option value="">__'.$fI["path"].'__:</option>';
01226                                                                                                         $onlineResourceFlag=1;
01227                                                                                                 }
01228                                                                                                 $dims=$this->resourceDimensions[$val];
01229                                                                                                 $sel="";
01230 
01231                                                                                                         // Check if $params["value"] is in the list of resources.
01232                                                                                                 if ($selectThisFile && $selectThisFile==$val)   {
01233                                                                                                         $sel=" selected";
01234                                                                                                         if ($onlineResourceFlag<=0)     {
01235                                                                                                                 $theImage=t3lib_BEfunc::thumbCode(array("resources"=>$selectThisFile),"sys_template","resources",$GLOBALS["BACK_PATH"],"");
01236                                                                                                         } else {
01237                                                                                                                 $theImage=t3lib_BEfunc::thumbCode(array("resources"=>$fI["file"]),"sys_template","resources",$GLOBALS["BACK_PATH"],"",$fI["path"]);
01238                                                                                                         }
01239                                                                                                 }
01240 
01241                                                                                                 if ($onlineResourceFlag<=0)     {
01242                                                                                                         $onlineResourceFlag--;
01243                                                                                                                 // Value is set with a *
01244                                                                                                         $val = $this->ext_setStar($val);
01245                                                                                                         $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.$dims.'</option>';
01246                                                                                                 } else {
01247                                                                                                         $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$fI["file"].$dims.'</option>';
01248                                                                                                 }
01249                                                                                         }
01250                                                                                 }
01251                                                                                 if (trim($params["value"]) && !$selectThisFile) {
01252                                                                                         $val = $params["value"];
01253                                                                                         $p_field.='<option value=""></option>';
01254                                                                                         $p_field.='<option value="'.htmlspecialchars($val).'" selected>'.$val.'</option>';
01255                                                                                 }
01256         //                                                              }
01257                                                                         $p_field='<select name="'.$fN.'" onChange="uFormUrl('.$aname.')">'.$p_field.'</select>';
01258                                                                         $p_field.=$theImage;
01259 
01260                                                                         if (!$this->ext_noCEUploadAndCopying)   {
01261                                                                                         // Copy a resource
01262                                                                                 $copyFile = $this->extractFromResources($this->setup["resources"],$params["value"]);
01263                                                                                 if (!$copyFile) {
01264                                                                                         if ($params["value"])   {
01265                                                                                                 $copyFile=PATH_site.$this->ext_detectAndFixExtensionPrefix($params["value"]);
01266                                                                                         }
01267                                                                                 } else {
01268         //                                                                              $copyFile=PATH_site."uploads/tf/".$copyFile;
01269                                                                                         $copyFile="";
01270                                                                                 }
01271 #debug($copyFile);
01272                                                                                 if ($copyFile && @is_file($copyFile))   {
01273                                                                                         $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"])).'\'));}">';
01274                                                                                 }
01275                                                                                         // Upload?
01276                                                                                 $p_field.='<BR>';
01277                                                                                 $p_field.='<input type="file" name="upload_'.$fN.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth().' onChange="uFormUrl('.$aname.')" size="50" />';
01278                                                                         }
01279                                                                 break;
01280                                                                 case 'small':
01281                                                                 default:
01282                                                                         $fwidth= $typeDat["type"]=="small" ? 10 : 46;
01283                                                                         $p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth($fwidth).' onChange="uFormUrl('.$aname.')">';
01284                                                                 break;
01285                                                         }
01286                                                 }
01287                                                 if (!$this->ext_dontCheckIssetValues)   $p_field='<input type="Checkbox" name="check['.$params["name"].']" value="1"'.$checked.' onClick="uFormUrl('.$aname.')">'.$p_field;
01288                                                 if ($typeDat["type"]=="color" && substr($params["value"],0,2)!='{$')    {
01289                                                         $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>';
01290                                                 } else {
01291                                                         $p_field='<span class="nobr">'.$p_field.'</span><br />';
01292                                                 }
01293 
01294                                                 $p_name = '<span class="typo3-dimmed">['.$params["name"].']</span><BR>';
01295                                                 $p_dlabel='<span class="typo3-dimmed"><b>Default:</b> '.htmlspecialchars($params["default_value"]).'</span><BR>';
01296                                                 $p_label = '<b>'.htmlspecialchars($head).'</b>';
01297                                                 $p_descrip = $body ? htmlspecialchars($body)."<BR>" : "";
01298 
01299                                                 $output.='<tr>';
01300                                                 $output.='<td valign=top nowrap><a name="'.$raname.'"></a>'.$help["constants"][$params["name"]].$p_label.'</td>';
01301                                                 $output.='<td valign=top align="right">'.$p_name.'</td>';
01302                                                 $output.='</tr>';
01303                                                 $output.='<tr>';
01304                                                 $output.='<td colspan=2>'.$p_descrip.$p_field.$p_dlabel.'<br></td>';
01305                                                 $output.='</tr>';
01306                         //              }
01307                                 } else {
01308                                         debug("Error. Constant did not exits. Should not happen.");
01309                                 }
01310                         }
01311                         $output='<table border=0 cellpadding=0 cellspacing=0>'.$output.'</table>';
01312                 }
01313                 return $output;
01314         }
01315 
01316 
01317 
01318 
01319 
01320 
01321 
01322 
01323 
01324 
01325 
01326 
01327         /***************************
01328          *
01329          * Processing input values
01330          *
01331          ***************************/
01332 
01337         function ext_regObjectPositions($constants)     {
01338                         // 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
01339                 $this->raw = explode(chr(10),$constants);
01340                 $this->rawP=0;
01341 
01342                 $this->objReg=array();          // resetting the objReg if the divider is found!!
01343                 $this->ext_regObjects("");
01344         }
01345 
01352         function ext_regObjects($pre)   {
01353                         // works with regObjectPositions. "expands" the names of the TypoScript objects
01354                 while (isset($this->raw[$this->rawP]))  {
01355                         $line = ltrim($this->raw[$this->rawP]);
01356                         if (strstr($line,$this->edit_divider))  {
01357                                 $this->objReg=array();          // resetting the objReg if the divider is found!!
01358                         }
01359                         $this->rawP++;
01360                         if ($line)      {
01361                                 if (substr($line,0,1)=="[")     {
01362 //                                      return $line;
01363                                 } elseif (strcspn($line,"}#/")!=0)      {
01364                                         $varL = strcspn($line," {=<");
01365                                         $var=substr($line,0,$varL);
01366                                         $line = ltrim(substr($line,$varL));
01367                                         switch(substr($line,0,1))       {
01368                                                 case "=":
01369                                                         $this->objReg[$pre.$var]=$this->rawP-1;
01370                                                 break;
01371                                                 case "{":
01372                                                         $this->ext_inBrace++;
01373                                                         $this->ext_regObjects($pre.$var.".");
01374                                                 break;
01375                                         }
01376                                         $this->lastComment="";
01377                                 } elseif (substr($line,0,1)=="}")       {
01378                                         $this->lastComment="";
01379                                         $this->ext_inBrace--;
01380                                         if ($this->ext_inBrace<0)       {
01381                                                 $this->ext_inBrace=0;
01382                                         } else {
01383                                                 break;
01384                                         }
01385                                 }
01386                         }
01387                 }
01388         }
01389 
01397         function ext_putValueInConf($key, $var) {
01398                         // Puts the value $var to the TypoScript value $key in the current lines of the templates.
01399                         // If the $key is not found in the template constants field, a new line is inserted in the bottom.
01400                 $theValue = " ".trim($var);
01401                 if (isset($this->objReg[$key])) {
01402                         $lineNum = $this->objReg[$key];
01403                         $parts = explode("=",$this->raw[$lineNum],2);
01404                         if (count($parts)==2)   {
01405                                 $parts[1]= $theValue;
01406                         }
01407                         $this->raw[$lineNum]=implode($parts,"=");
01408                 } else {
01409                         $this->raw[]=$key." =".$theValue;
01410                 }
01411                 $this->changed=1;
01412         }
01413 
01420         function ext_removeValueInConf($key)    {
01421                         // Removes the value in the configuration
01422                 if (isset($this->objReg[$key])) {
01423                         $lineNum = $this->objReg[$key];
01424                         unset($this->raw[$lineNum]);
01425                 }
01426                 $this->changed=1;
01427         }
01428 
01436         function ext_depthKeys($arr,$settings)  {
01437                 reset($arr);
01438                 $tsbrArray=array();
01439                 while(list($theK,$theV)=each($arr))     {
01440                         $theKeyParts = explode(".",$theK);
01441                         $depth="";
01442                         $c=count($theKeyParts);
01443                         $a=0;
01444                         while(list(,$p)=each($theKeyParts))     {
01445                                 $a++;
01446                                 $depth.=($depth?".":"").$p;
01447                                 $tsbrArray[$depth]= ($c==$a) ? $theV : 1;
01448                         }
01449                 }
01450                         // Modify settings
01451                 reset($tsbrArray);
01452                 while(list($theK,$theV)=each($tsbrArray))       {
01453                         if ($theV)      {
01454                                 $settings[$theK] = 1;
01455                         } else {
01456                                 unset($settings[$theK]);
01457                         }
01458                 }
01459                 return $settings;
01460         }
01461 
01471         function ext_procesInput($http_post_vars,$http_post_files,$theConstants,$tplRow)        {
01472                 $data=$http_post_vars["data"];
01473                 $check=$http_post_vars["check"];
01474                 $copyResource=$http_post_vars["_copyResource"];
01475                 $Wdata=$http_post_vars["Wdata"];
01476                 $W2data=$http_post_vars["W2data"];
01477                 $W3data=$http_post_vars["W3data"];
01478                 $W4data=$http_post_vars["W4data"];
01479                 $W5data=$http_post_vars["W5data"];
01480 
01481                 if (is_array($data))    {
01482                         reset($data);
01483                         while(list($key,$var)=each($data))      {
01484                                 if (isset($theConstants[$key])) {
01485                                         if ($this->ext_dontCheckIssetValues || isset($check[$key]))     {               // If checkbox is set, update the value
01486                                                 list($var) = explode(chr(10),$var);     // exploding with linebreak, just to make sure that no multiline input is given!
01487                                                 $typeDat=$this->ext_getTypeData($theConstants[$key]["type"]);
01488                                                 switch($typeDat["type"])        {
01489                                                         case "int":
01490                                                                 if ($typeDat["paramstr"])       {
01491                                                                         $var=t3lib_div::intInRange($var,$typeDat["params"][0],$typeDat["params"][1]);
01492                                                                 } else {
01493                                                                         $var=intval($var);
01494                                                                 }
01495                                                         break;
01496                                                         case "int+":
01497                                                                 $var=t3lib_div::intInRange($var,0,10000);
01498                                                         break;
01499                                                         case "color":
01500                                                                 $col=array();
01501                                                                 if($var && !t3lib_div::inList($this->HTMLcolorList,strtolower($var)))   {
01502                                                                         $var = ereg_replace("[^A-Fa-f0-9]*","",$var);
01503                                                                         $col[]=HexDec(substr($var,0,2));
01504                                                                         $col[]=HexDec(substr($var,2,2));
01505                                                                         $col[]=HexDec(substr($var,4,2));
01506                                                                         $var="#".strtoupper(substr("0".DecHex($col[0]),-2).substr("0".DecHex($col[1]),-2).substr("0".DecHex($col[2]),-2));
01507                                                                 }
01508                                                         break;
01509                                                         case "comment":
01510                                                                 if ($val)       {
01511                                                                         $val="#";
01512                                                                 } else {
01513                                                                         $val="";
01514                                                                 }
01515                                                         break;
01516                                                         case "wrap":
01517                                                                 if (isset($Wdata[$key]))        {
01518                                                                         $var.="|".$Wdata[$key];
01519                                                                 }
01520                                                         break;
01521                                                         case "offset":
01522                                                                 if (isset($Wdata[$key]))        {
01523                                                                         $var=intval($var).",".intval($Wdata[$key]);
01524                                                                         if (isset($W2data[$key]))       {
01525                                                                                 $var.=",".intval($W2data[$key]);
01526                                                                                 if (isset($W3data[$key]))       {
01527                                                                                         $var.=",".intval($W3data[$key]);
01528                                                                                         if (isset($W4data[$key]))       {
01529                                                                                                 $var.=",".intval($W4data[$key]);
01530                                                                                                 if (isset($W5data[$key]))       {
01531                                                                                                         $var.=",".intval($W5data[$key]);
01532                                                                                                 }
01533                                                                                         }
01534                                                                                 }
01535                                                                         }
01536                                                                 }
01537                                                         break;
01538                                                         case "boolean":
01539                                                                 if ($var)       {
01540                                                                         $var = $typeDat["paramstr"] ? $typeDat["paramstr"] : 1;
01541                                                                 }
01542                                                         break;
01543                                                         case "file":
01544                                                                 if (!$this->ext_noCEUploadAndCopying)   {
01545                                                                         if ($http_post_files["upload_data"]["name"][$key] && $http_post_files["upload_data"]["tmp_name"][$key]!="none") {
01546                                                                                 $var = $this->upload_copy_file(
01547                                                                                         $typeDat,
01548                                                                                         $tplRow,
01549                                                                                         trim($http_post_files["upload_data"]["name"][$key]),
01550                                                                                         $http_post_files["upload_data"]["tmp_name"][$key]
01551                                                                                 );
01552                                                                         }
01553                                                                         if ($copyResource[$key])        {
01554                                                                                 $var = $this->upload_copy_file(
01555                                                                                         $typeDat,
01556                                                                                         $tplRow,
01557                                                                                         basename($copyResource[$key]),
01558                                                                                         $copyResource[$key]
01559                                                                                 );
01560                                                                         }
01561                                                                 }
01562                                                         break;
01563                                                 }
01564                                                 if ($this->ext_printAll || strcmp($theConstants[$key]["value"],$var))   {
01565                                                         $this->ext_putValueInConf($key, $var);          // Put value in, if changed.
01566                                                 }
01567                                                 unset($check[$key]);            // Remove the entry because it has been "used"
01568                                         } else {
01569                                                 $this->ext_removeValueInConf($key);
01570                                         }
01571                                 }
01572                         }
01573                 }
01574                         // 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...
01575                 if (!$this->ext_dontCheckIssetValues && is_array($check))       {
01576                         reset($check);
01577                         while(list($key,$var)=each($check))     {
01578                                 if (isset($theConstants[$key])) {
01579                                         $dValue = $theConstants[$key]["default_value"];
01580 //                                      debug($dValue);
01581                                         $this->ext_putValueInConf($key, $dValue);
01582 //                                      debug($key,1);
01583                                 }
01584                         }
01585                 }
01586 //              debug($this->objReg);
01587         }
01588 
01598         function upload_copy_file($typeDat,&$tplRow,$theRealFileName,$tmp_name) {
01599 
01600                         // extensions
01601                 $extList = $typeDat["paramstr"];
01602                 if ($extList=="IMAGE_EXT")      {
01603                         $extList = $GLOBALS["TYPO3_CONF_VARS"]["GFX"]["imagefile_ext"];
01604                 }
01605                 $fI=t3lib_div::split_fileref($theRealFileName);
01606                 if ($theRealFileName && (!$extList || t3lib_div::inList($extList,$fI["fileext"])))      {
01607                         $tmp_upload_name = t3lib_div::upload_to_tempfile($tmp_name);    // If there is an uploaded file, move it for the sake of safe_mode.
01608 
01609                                 // Saving resource
01610                         $alternativeFileName=array();
01611                         $alternativeFileName[$tmp_upload_name] = $theRealFileName;
01612                                 // Making list of resources
01613                         $resList = $tplRow["resources"];
01614                         $resList = $tmp_upload_name.",".$resList;
01615                         $resList=implode(t3lib_div::trimExplode(",",$resList,1),",");
01616                                 // Making data-array
01617                         $recData=array();
01618                         $recData["sys_template"][$tplRow["uid"]]["resources"] = $resList;
01619                                 // Saving
01620                         $tce = t3lib_div::makeInstance("t3lib_TCEmain");
01621                         $tce->stripslashes_values=0;
01622                         $tce->alternativeFileName = $alternativeFileName;
01623                         $tce->start($recData,Array());
01624                         $tce->process_datamap();
01625 
01626                         t3lib_div::unlink_tempfile($tmp_upload_name);
01627 
01628                         $tmpRow = t3lib_BEfunc::getRecord("sys_template",$tplRow["uid"],"resources");
01629                         $tplRow["resources"] = $tmpRow["resources"];
01630 
01631                                 // Setting the value
01632                         $var = $this->ext_setStar($theRealFileName);
01633                 }
01634                 return $var;
01635         }
01636 
01644         function ext_prevPageWithTemplate($id,$perms_clause)    {
01645                 $rootLine = t3lib_BEfunc::BEgetRootLine($id,$perms_clause?" AND ".$perms_clause:"");
01646                 reset($rootLine);
01647                 while(list(,$p)=each($rootLine))        {
01648                         if ($this->ext_getFirstTemplate($p["uid"]))     {
01649                                 return $p;
01650                         }
01651                 }
01652         }
01653 
01660         function ext_setStar($val)      {
01661                 $fParts = explode(".",strrev($val),2);
01662                 $val=ereg_replace("_[0-9][0-9]$","",strrev($fParts[1]))."*.".strrev($fParts[0]);
01663                 return $val;
01664         }
01665 
01672         function ext_detectAndFixExtensionPrefix($value)        {
01673                 if (substr($value,0,4)=="EXT:") {
01674                         $parts = explode("/",substr($value,4),2);
01675 #debug($parts);
01676                         $extPath = t3lib_extMgm::siteRelPath($parts[0]);
01677                         $value = $extPath.$parts[1];
01678                         return $value;
01679                 } else {
01680                         return $value;
01681                 }
01682         }
01683 }
01684 
01685 
01686 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php'])      {
01687         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php']);
01688 }
01689 ?>


Généré par Les experts TYPO3 avec  doxygen 1.4.6