Documentation TYPO3 par Ameos

class.t3lib_tsparser_ext.php

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


Généré par L'expert TYPO3 avec  doxygen 1.4.6