TYPO3 API  SVNRelease
class.t3lib_tsparser_ext.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 1999-2011 Kasper Skårhøj (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  ***************************************************************/
00027 /**
00028  * TSParser extension class to t3lib_TStemplate
00029  *
00030  * $Id: class.t3lib_tsparser_ext.php 10121 2011-01-18 20:15:30Z ohader $
00031  * Contains functions for the TS module in TYPO3 backend
00032  *
00033  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00034  */
00035 /**
00036  * [CLASS/FUNCTION INDEX of SCRIPT]
00037  *
00038  *
00039  *
00040  *  105: class t3lib_tsparser_ext extends t3lib_TStemplate
00041  *  191:     function flattenSetup($setupArray, $prefix, $resourceFlag)
00042  *  218:     function substituteConstants($all)
00043  *  231:     function substituteConstantsCallBack($matches)
00044  *  261:     function substituteCMarkers($all)
00045  *  284:     function generateConfig_constants()
00046  *  330:     function ext_getSetup($theSetup,$theKey)
00047  *  358:     function ext_getObjTree($arr, $depth_in, $depthData, $parentType='',$parentValue='', $alphaSort='0')
00048  *  463:     function lineNumberToScript($lnArr)
00049  *  494:     function makeHtmlspecialchars($theValue)
00050  *  507:     function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray)
00051  *  562:     function ext_getRootlineNumber($pid)
00052  *  580:     function ext_getTemplateHierarchyArr($arr,$depthData, $keyArray,$first=0)
00053  *  639:     function ext_process_hierarchyInfo($depthDataArr,&$pointer)
00054  *  670:     function ext_outputTS($config, $lineNumbers=0, $comments=0, $crop=0, $syntaxHL=0, $syntaxHLBlockmode=0)
00055  *  697:     function ext_fixed_lgd($string,$chars)
00056  *  713:     function ext_lnBreakPointWrap($ln,$str)
00057  *  726:     function ext_formatTS($input, $ln, $comments=1, $crop=0)
00058  *  765:     function ext_getFirstTemplate($id,$template_uid=0)
00059  *  785:     function ext_getAllTemplates($id)
00060  *  806:     function ext_compareFlatSetups($default)
00061  *  872:     function ext_categorizeEditableConstants($editConstArray)
00062  *  895:     function ext_getCategoryLabelArray()
00063  *  912:     function ext_getTypeData($type)
00064  *  953:     function ext_getTSCE_config($category)
00065  *  992:     function ext_getKeyImage($key)
00066  * 1002:     function ext_getTSCE_config_image($imgConf)
00067  * 1026:     function ext_resourceDims()
00068  * 1056:     function ext_readDirResources($path)
00069  * 1071:     function readDirectory($path,$type='file')
00070  * 1096:     function ext_fNandV($params)
00071  * 1114:     function ext_printFields($theConstants,$category)
00072  *
00073  *            SECTION: Processing input values
00074  * 1408:     function ext_regObjectPositions($constants)
00075  * 1423:     function ext_regObjects($pre)
00076  * 1468:     function ext_putValueInConf($key, $var)
00077  * 1491:     function ext_removeValueInConf($key)
00078  * 1507:     function ext_depthKeys($arr,$settings)
00079  * 1542:     function ext_procesInput($http_post_vars,$http_post_files,$theConstants,$tplRow)
00080  * 1666:     function upload_copy_file($typeDat,&$tplRow,$theRealFileName,$tmp_name)
00081  * 1715:     function ext_prevPageWithTemplate($id,$perms_clause)
00082  * 1731:     function ext_setStar($val)
00083  * 1743:     function ext_detectAndFixExtensionPrefix($value)
00084  *
00085  * TOTAL FUNCTIONS: 41
00086  * (This index is automatically created/updated by the extension "extdeveval")
00087  *
00088  */
00089 
00090 
00091 /**
00092  * TSParser extension class to t3lib_TStemplate
00093  *
00094  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00095  * @package TYPO3
00096  * @subpackage t3lib
00097  */
00098 class t3lib_tsparser_ext extends t3lib_TStemplate {
00099 
00100     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.
00101     var $HTMLcolorList = 'aqua,beige,black,blue,brown,fuchsia,gold,gray,green,lime,maroon,navy,olive,orange,purple,red,silver,tan,teal,turquoise,yellow,white';
00102 
00103         // internal
00104     var $categories = array(
00105         '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.
00106         'menu' => array(), // Menu setup. This includes fontfiles, sizes, background images. Depending on the menutype.
00107         'content' => array(), // All constants related to the display of pagecontent elements
00108         'page' => array(), // General configuration like metatags, link targets
00109         'advanced' => array(), // Advanced functions, which are used very seldomly.
00110         'all' => array() // All constants are put here also!
00111     ); // This will be filled with the available categories of the current template.
00112     var $subCategories = array(
00113             // Standard categories:
00114         'enable' => Array('Enable features', 'a'),
00115         'dims' => Array('Dimensions, widths, heights, pixels', 'b'),
00116         'file' => Array('Files', 'c'),
00117         'typo' => Array('Typography', 'd'),
00118         'color' => Array('Colors', 'e'),
00119         'links' => Array('Links and targets', 'f'),
00120         'language' => Array('Language specific constants', 'g'),
00121 
00122             // subcategories based on the default content elements
00123         'cheader' => Array('Content: \'Header\'', 'ma'),
00124         'cheader_g' => Array('Content: \'Header\', Graphical', 'ma'),
00125         'ctext' => Array('Content: \'Text\'', 'mb'),
00126         'cimage' => Array('Content: \'Image\'', 'md'),
00127         'cbullets' => Array('Content: \'Bullet list\'', 'me'),
00128         'ctable' => Array('Content: \'Table\'', 'mf'),
00129         'cuploads' => Array('Content: \'Filelinks\'', 'mg'),
00130         'cmultimedia' => Array('Content: \'Multimedia\'', 'mh'),
00131         'cmedia' => Array('Content: \'Media\'', 'mr'),
00132         'cmailform' => Array('Content: \'Form\'', 'mi'),
00133         'csearch' => Array('Content: \'Search\'', 'mj'),
00134         'clogin' => Array('Content: \'Login\'', 'mk'),
00135         'csplash' => Array('Content: \'Textbox\'', 'ml'),
00136         'cmenu' => Array('Content: \'Menu/Sitemap\'', 'mm'),
00137         'cshortcut' => Array('Content: \'Insert records\'', 'mn'),
00138         'clist' => Array('Content: \'List of records\'', 'mo'),
00139         'cscript' => Array('Content: \'Script\'', 'mp'),
00140         'chtml' => Array('Content: \'HTML\'', 'mq')
00141     );
00142     var $resourceDimensions = array();
00143     var $dirResources = array();
00144 
00145     var $backend_info = 1;
00146 
00147         // tsconstanteditor
00148     var $ext_inBrace = 0;
00149 
00150         // tsbrowser
00151     var $tsbrowser_searchKeys = array();
00152     var $tsbrowser_depthKeys = array();
00153     var $constantMode = '';
00154     var $regexMode = '';
00155     var $fixedLgd = '';
00156     var $resourceCheck = 0;
00157     var $ext_lineNumberOffset = 0;
00158     var $ext_localGfxPrefix = '';
00159     var $ext_localWebGfxPrefix = '';
00160     var $ext_expandAllNotes = 0;
00161     var $ext_noPMicons = 0;
00162     var $ext_noSpecialCharsOnLabels = 0;
00163     var $ext_listOfTemplatesArr = array();
00164     var $ext_lineNumberOffset_mode = '';
00165     var $ext_dontCheckIssetValues = 0; // Dont change...
00166     var $ext_noCEUploadAndCopying = 0;
00167     var $ext_printAll = 0;
00168     var $ext_CEformName = 'forms[0]';
00169     var $ext_defaultOnlineResourceFlag = 0;
00170     var $doNotSortCategoriesBeforeMakingForm = FALSE;
00171 
00172         // ts analyzer
00173     var $templateTitles = array();
00174 
00175 
00176     /**
00177      * This flattens a hierarchical setuparray to $this->flatSetup
00178      * The original function fetched the resource-file if any ('file.'). This functions doesn't.
00179      *
00180      * @param   [type]      $setupArray: ...
00181      * @param   [type]      $prefix: ...
00182      * @param   [type]      $resourceFlag: ...
00183      * @return  [type]      ...
00184      */
00185     function flattenSetup($setupArray, $prefix, $resourceFlag) {
00186         if (is_array($setupArray)) {
00187             $this->getFileName_backPath = PATH_site; // Setting absolute prefixed path for relative resources.
00188             foreach ($setupArray as $key => $val) {
00189                 if ($prefix || substr($key, 0, 16) != 'TSConstantEditor') { // We don't want 'TSConstantEditor' in the flattend setup.
00190                     if (is_array($val)) {
00191                         $this->flattenSetup($val, $prefix . $key, ($key == 'file.'));
00192                     } elseif ($resourceFlag && $this->resourceCheck) {
00193                         $this->flatSetup[$prefix . $key] = $this->getFileName($val);
00194                         if ($this->removeFromGetFilePath &&
00195                             substr($this->flatSetup[$prefix . $key], 0, strlen($this->removeFromGetFilePath)) == $this->removeFromGetFilePath) {
00196                                 $this->flatSetup[$prefix . $key] = substr($this->flatSetup[$prefix . $key], strlen($this->removeFromGetFilePath));
00197                         }
00198                     } else {
00199                         $this->flatSetup[$prefix . $key] = $val;
00200                     }
00201                 }
00202             }
00203         }
00204     }
00205 
00206     /**
00207      * [Describe function...]
00208      *
00209      * @param   [type]      $all: ...
00210      * @return  [type]      ...
00211      */
00212     function substituteConstants($all) {
00213         $this->Cmarker = substr(md5(uniqid('')), 0, 6);
00214 
00215         return preg_replace_callback('/\{\$(.[^}]+)\}/', array($this, 'substituteConstantsCallBack'), $all);
00216     }
00217 
00218     /**
00219      * Call back method for preg_replace_callback in substituteConstants
00220      *
00221      * @param   array       Regular expression matches
00222      * @return  string      Replacement
00223      * @see substituteConstants()
00224      */
00225     function substituteConstantsCallBack($matches) {
00226         switch ($this->constantMode) {
00227             case 'const':
00228                 $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ?
00229                         '##' . $this->Cmarker . '_B##' . $matches[0] . '##' . $this->Cmarker . '_E##' :
00230                         $matches[0];
00231             break;
00232             case 'subst':
00233                 $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ?
00234                         '##' . $this->Cmarker . '_B##' . $this->flatSetup[$matches[1]] . '##' . $this->Cmarker . '_E##' :
00235                         $matches[0];
00236             break;
00237             case 'untouched':
00238                 $ret_val = $matches[0];
00239             break;
00240             default:
00241                 $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ?
00242                         $this->flatSetup[$matches[1]] :
00243                         $matches[0];
00244         }
00245 
00246         return $ret_val;
00247     }
00248 
00249     /**
00250      * [Describe function...]
00251      *
00252      * @param   [type]      $all: ...
00253      * @return  [type]      ...
00254      */
00255     function substituteCMarkers($all) {
00256         switch ($this->constantMode) {
00257             case 'const':
00258                 $all = str_replace('##' . $this->Cmarker . '_B##', '<font color="green"><strong>', $all);
00259                 $all = str_replace('##' . $this->Cmarker . '_E##', '</strong></font>', $all);
00260             break;
00261             case 'subst':
00262                 $all = str_replace('##' . $this->Cmarker . '_B##', '<font color="green"><strong>', $all);
00263                 $all = str_replace('##' . $this->Cmarker . '_E##', '</strong></font>', $all);
00264             break;
00265             default:
00266                 $all = $all;
00267             break;
00268         }
00269         return $all;
00270     }
00271 
00272     /**
00273      * Parses the constants in $this->const with respect to the constant-editor in this module.
00274      * In particular comments in the code are registered and the edit_divider is taken into account.
00275      *
00276      * @return  [type]      ...
00277      */
00278     function generateConfig_constants() {
00279             // These vars are also set lateron...
00280         $this->setup['resources'] = $this->resources;
00281         $this->setup['sitetitle'] = $this->sitetitle;
00282 
00283             // parse constants
00284         $constants = t3lib_div::makeInstance('t3lib_TSparser');
00285         $constants->regComments = 1; // Register comments!
00286         $constants->setup = $this->const;
00287         $constants->setup = $this->mergeConstantsFromPageTSconfig($constants->setup);
00288 
00289         /* @var $matchObj t3lib_matchCondition_frontend */
00290         $matchObj = t3lib_div::makeInstance('t3lib_matchCondition_frontend');
00291         $matchObj->setSimulateMatchResult(TRUE); // Matches ALL conditions in TypoScript
00292 
00293         $c = 0;
00294         $cc = count($this->constants);
00295         foreach ($this->constants as $str) {
00296             $c++;
00297             if ($c == $cc) {
00298                 if (strstr($str, $this->edit_divider)) {
00299                     $parts = explode($this->edit_divider, $str, 2);
00300                     $str = $parts[1];
00301                     $constants->parse($parts[0], $matchObj);
00302                 }
00303                 $this->flatSetup = Array();
00304                 $this->flattenSetup($constants->setup, '', '');
00305                 $defaultConstants = $this->flatSetup;
00306             }
00307             $constants->parse($str, $matchObj);
00308         }
00309 
00310         $this->flatSetup = Array();
00311         $this->flattenSetup($constants->setup, '', '');
00312         $this->setup['constants'] = $constants->setup;
00313 
00314         return $this->ext_compareFlatSetups($defaultConstants);
00315     }
00316 
00317     /**
00318      * [Describe function...]
00319      *
00320      * @param   [type]      $theSetup: ...
00321      * @param   [type]      $theKey: ...
00322      * @return  [type]      ...
00323      */
00324     function ext_getSetup($theSetup, $theKey) {
00325         $parts = explode('.', $theKey, 2);
00326         if (strcmp($parts[0], '') && is_array($theSetup[$parts[0] . '.'])) {
00327             if (strcmp(trim($parts[1]), '')) {
00328                 return $this->ext_getSetup($theSetup[$parts[0] . '.'], trim($parts[1]));
00329             } else {
00330                 return array($theSetup[$parts[0] . '.'], $theSetup[$parts[0]]);
00331             }
00332         } else {
00333             if (strcmp(trim($theKey), '')) {
00334                 return array(array(), $theSetup[$theKey]);
00335             } else {
00336                 return array($theSetup, '');
00337             }
00338         }
00339     }
00340 
00341     /**
00342      * [Describe function...]
00343      *
00344      * @param   [type]      $arr: ...
00345      * @param   [type]      $depth_in: ...
00346      * @param   [type]      $depthData: ...
00347      * @param   [type]      $parentType: ...
00348      * @param   [type]      $parentValue: ...
00349      * @param   boolean     $alphaSort sorts the array keys / tree by alphabet when set to 1
00350      * @return  [type]      ...
00351      */
00352     function ext_getObjTree($arr, $depth_in, $depthData, $parentType = '', $parentValue = '', $alphaSort = '0') {
00353         $HTML = '';
00354         $a = 0;
00355 
00356         if ($alphaSort == '1') {
00357             ksort($arr);
00358         }
00359         $keyArr_num = array();
00360         $keyArr_alpha = array();
00361         foreach ($arr as $key => $value) {
00362             if (substr($key, -2) != '..') { // Don't do anything with comments / linenumber registrations...
00363                 $key = preg_replace('/\.$/', '', $key);
00364                 if (substr($key, -1) != '.') {
00365                     if (t3lib_div::testInt($key)) {
00366                         $keyArr_num[$key] = $arr[$key];
00367                     } else {
00368                         $keyArr_alpha[$key] = $arr[$key];
00369                     }
00370                 }
00371             }
00372         }
00373         ksort($keyArr_num);
00374         $keyArr = $keyArr_num + $keyArr_alpha;
00375         $c = count($keyArr);
00376         if ($depth_in) {
00377             $depth_in = $depth_in . '.';
00378         }
00379 
00380         foreach ($keyArr as $key => $value) {
00381             $a++;
00382             $depth = $depth_in . $key;
00383             if ($this->bType != 'const' || substr($depth, 0, 1) != '_') { // this excludes all constants starting with '_' from being shown.
00384                 $goto = substr(md5($depth), 0, 6);
00385                 $deeper = (is_array($arr[$key . '.']) && ($this->tsbrowser_depthKeys[$depth] || $this->ext_expandAllNotes)) ? 1 : 0;
00386                 $PM = 'join';
00387                 $LN = ($a == $c) ? 'blank' : 'line';
00388                 $BTM = ($a == $c) ? 'bottom' : '';
00389                 $PM = is_array($arr[$key . '.']) && !$this->ext_noPMicons ? ($deeper ? 'minus' : 'plus') : 'join';
00390 
00391                 $HTML .= $depthData;
00392                 $theIcon = '<img src="' . $GLOBALS['BACK_PATH'] . 'gfx/ol/' . $PM . $BTM . '.gif" width="18" height="16" align="top" border="0" alt="" />';
00393                 if ($PM == 'join') {
00394                     $HTML .= $theIcon;
00395                 } else {
00396                     $aHref = 'index.php?id=' . $GLOBALS['SOBE']->id .
00397                              '&tsbr[' . $depth . ']=' . ($deeper ? 0 : 1) .
00398                              (t3lib_div::_GP("breakPointLN") ? '&breakPointLN=' . t3lib_div::_GP("breakPointLN") : '') .
00399                              '#' . $goto;
00400                     $HTML .= '<a name="' . $goto . '" href="' . htmlspecialchars($aHref) . '">' . $theIcon . '</a>';
00401                 }
00402 
00403                 $label = $key;
00404                 if (t3lib_div::inList('types,resources,sitetitle', $depth) && $this->bType == 'setup') { // Read only...
00405                     $label = '<font color="#666666">' . $label . '</font>';
00406                 } else {
00407                     if ($this->linkObjects) {
00408                         $aHref = 'index.php?id=' . $GLOBALS['SOBE']->id .
00409                                  '&sObj=' . $depth .
00410                                  (t3lib_div::_GP("breakPointLN") ? '&breakPointLN=' . t3lib_div::_GP("breakPointLN") : '');
00411                         if ($this->bType != 'const') {
00412                             $ln = is_array($arr[$key . '.ln..']) ? 'Defined in: ' . $this->lineNumberToScript($arr[$key . '.ln..']) : 'N/A';
00413                         } else {
00414                             $ln = '';
00415                         }
00416 
00417                         if ($this->tsbrowser_searchKeys[$depth] & 4) {
00418                             $label = '<strong><font color="red">' . $label . '</font></strong>';
00419                         } // The key has matched the search string
00420                         $label = '<a href="' . htmlspecialchars($aHref) . '" title="' . htmlspecialchars($ln) . '">' . $label . '</a>';
00421                     }
00422                 }
00423 
00424                 $HTML .= '[' . $label . ']';
00425 
00426                 if (isset($arr[$key])) {
00427                     $theValue = $arr[$key];
00428                     if ($this->fixedLgd) {
00429                         $imgBlocks = ceil(1 + strlen($depthData) / 77);
00430                         $lgdChars = 68 - ceil(strlen('[' . $key . ']') * 0.8) - $imgBlocks * 3;
00431                         $theValue = $this->ext_fixed_lgd($theValue, $lgdChars);
00432                     }
00433                     if ($this->tsbrowser_searchKeys[$depth] & 2) { // The value has matched the search string
00434                         $HTML .= '&nbsp;=&nbsp;<strong><font color="red">' . $this->makeHtmlspecialchars($theValue) . '</font></strong>';
00435                     } else {
00436                         $HTML .= '&nbsp;=&nbsp;<strong>' . $this->makeHtmlspecialchars($theValue) . '</strong>';
00437                     }
00438                     if ($this->ext_regComments && isset($arr[$key . '..'])) {
00439                         $comment = $arr[$key . '..'];
00440                         if (!preg_match('/### <INCLUDE_TYPOSCRIPT:.*/', $comment)) { // Skip INCLUDE_TYPOSCRIPT comments, they are almost useless
00441                             $comment = preg_replace('/[\r\n]/', ' ', $comment); // Remove linebreaks, replace with ' '
00442                             $comment = preg_replace('/[#\*]{2,}/', '', $comment); // Remove # and * if more than twice in a row
00443                             $comment = preg_replace('/^[#\*\s]+/', '# ', $comment); // Replace leading # (just if it exists) and add it again. Result: Every comment should be prefixed by a '#'.
00444                             $comment = $this->makeHtmlspecialchars($comment); // Masking HTML Tags: Replace < with &lt; and > with &gt;
00445                             $HTML .= ' <span class="comment">' . trim($comment) . '</span>';
00446                         }
00447                     }
00448                 }
00449                 $HTML .= '<br />';
00450 
00451                 if ($deeper) {
00452                     $HTML .= $this->ext_getObjTree(
00453                         $arr[$key . '.'],
00454                         $depth,
00455                         $depthData . '<img src="' . $GLOBALS['BACK_PATH'] . 'gfx/ol/' . $LN . '.gif" width="18" height="16" align="top" alt="" />',
00456                         '' /* not used: $validate_info[$key] */,
00457                         $arr[$key],
00458                         $alphaSort
00459                     );
00460                 }
00461             }
00462         }
00463         return $HTML;
00464     }
00465 
00466     /**
00467      * [Describe function...]
00468      *
00469      * @param   [type]      $lnArr: ...
00470      * @return  [type]      ...
00471      */
00472     function lineNumberToScript($lnArr) {
00473         if (!is_array($this->lnToScript)) {
00474             $this->lnToScript = array();
00475             $c = 1;
00476             $c += substr_count($GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'], LF) + 2;
00477             $this->lnToScript[$c] = '[Default]';
00478 
00479             foreach ($this->hierarchyInfoToRoot as $info) {
00480                 $c += $info['configLines'] + 1;
00481                 $this->lnToScript[$c] = $info['title'];
00482             }
00483         }
00484 
00485         foreach ($lnArr as $k => $ln) {
00486             foreach ($this->lnToScript as $endLn => $title) {
00487                 if ($endLn >= intval($ln)) {
00488                     $lnArr[$k] = '"' . $title . '", ' . $ln;
00489                     break;
00490                 }
00491             }
00492         }
00493 
00494         return implode('; ', $lnArr);
00495     }
00496 
00497     /**
00498      * [Describe function...]
00499      *
00500      * @param   [type]      $theValue: ...
00501      * @return  [type]      ...
00502      */
00503     function makeHtmlspecialchars($theValue) {
00504         return $this->ext_noSpecialCharsOnLabels ? $theValue : htmlspecialchars($theValue);
00505     }
00506 
00507     /**
00508      * [Describe function...]
00509      *
00510      * @param   [type]      $arr: ...
00511      * @param   [type]      $depth_in: ...
00512      * @param   [type]      $searchString: ...
00513      * @param   [type]      $keyArray: ...
00514      * @return  [type]      ...
00515      */
00516     function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray) {
00517         $keyArr = array();
00518         foreach ($arr as $key => $value) {
00519             $key = preg_replace('/\.$/', '', $key);
00520             if (substr($key, -1) != '.') {
00521                 $keyArr[$key] = 1;
00522             }
00523         }
00524         $c = count($keyArr);
00525         if ($depth_in) {
00526             $depth_in = $depth_in . '.';
00527         }
00528         foreach ($keyArr as $key => $value) {
00529             $depth = $depth_in . $key;
00530             $deeper = is_array($arr[$key . '.']);
00531 
00532             if ($this->regexMode) {
00533                 if (preg_match('/' . $searchString . '/', $arr[$key])) { // The value has matched
00534                     $this->tsbrowser_searchKeys[$depth] += 2;
00535                 }
00536                 if (preg_match('/' . $searchString . '/', $key)) { // The key has matched
00537                     $this->tsbrowser_searchKeys[$depth] += 4;
00538                 }
00539                 if (preg_match('/' . $searchString . '/', $depth_in)) { // Just open this subtree if the parent key has matched the search
00540                     $this->tsbrowser_searchKeys[$depth] = 1;
00541                 }
00542             } else {
00543                 if (stristr($arr[$key], $searchString)) { // The value has matched
00544                     $this->tsbrowser_searchKeys[$depth] += 2;
00545                 }
00546                 if (stristr($key, $searchString)) { // The key has matches
00547                     $this->tsbrowser_searchKeys[$depth] += 4;
00548                 }
00549                 if (stristr($depth_in, $searchString)) { // Just open this subtree if the parent key has matched the search
00550                     $this->tsbrowser_searchKeys[$depth] = 1;
00551                 }
00552             }
00553 
00554             if ($deeper) {
00555                 $cS = count($this->tsbrowser_searchKeys);
00556                 $keyArray = $this->ext_getSearchKeys($arr[$key . '.'], $depth, $searchString, $keyArray);
00557                 if ($cS != count($this->tsbrowser_searchKeys)) {
00558                     $keyArray[$depth] = 1;
00559                 }
00560             }
00561         }
00562         return $keyArray;
00563     }
00564 
00565     /**
00566      * [Describe function...]
00567      *
00568      * @param   [type]      $pid: ...
00569      * @return  [type]      ...
00570      */
00571     function ext_getRootlineNumber($pid) {
00572         if ($pid && is_array($GLOBALS['rootLine'])) {
00573             foreach ($GLOBALS['rootLine'] as $key => $val) {
00574                 if ($val['uid'] == $pid) {
00575                     return $key;
00576                 }
00577             }
00578         }
00579     }
00580 
00581     /**
00582      * [Describe function...]
00583      *
00584      * @param   [type]      $arr: ...
00585      * @param   [type]      $depthData: ...
00586      * @param   [type]      $keyArray: ...
00587      * @param   [type]      $first: ...
00588      * @return  [type]      ...
00589      */
00590     function ext_getTemplateHierarchyArr($arr, $depthData, $keyArray, $first = 0) {
00591         $keyArr = array();
00592         foreach ($arr as $key => $value) {
00593             $key = preg_replace('/\.$/', '', $key);
00594             if (substr($key, -1) != '.') {
00595                 $keyArr[$key] = 1;
00596             }
00597         }
00598         $a = 0;
00599         $c = count($keyArr);
00600         static $i = 0;
00601         foreach ($keyArr as $key => $value) {
00602             $HTML = '';
00603             $a++;
00604             $deeper = is_array($arr[$key . '.']);
00605             $row = $arr[$key];
00606 
00607             $PM = 'join';
00608             $LN = ($a == $c) ? 'blank' : 'line';
00609             $BTM = ($a == $c) ? 'top' : '';
00610             $PM = 'join';
00611 
00612             $HTML .= $depthData;
00613 
00614             $alttext = '[' . $row['templateID'] . ']';
00615             $alttext .= $row['pid'] ? ' - ' . t3lib_BEfunc::getRecordPath($row['pid'], $GLOBALS['SOBE']->perms_clause, 20) : '';
00616 
00617             $icon = (substr($row['templateID'], 0, 3) == 'sys' ?
00618                     t3lib_iconWorks::getSpriteIconForRecord('sys_template', $row, array('title' => $alttext))
00619                     : t3lib_iconWorks::getSpriteIcon('mimetypes-x-content-template-static', array('title' => $alttext))
00620             );
00621             if (in_array($row['templateID'], $this->clearList_const) || in_array($row['templateID'], $this->clearList_setup)) {
00622                 $A_B = '<a href="index.php?id=' . htmlspecialchars($GLOBALS['SOBE']->id . '&template=' . $row['templateID']) . '">';
00623                 $A_E = '</a>';
00624                 if (t3lib_div::_GP('template') == $row['templateID']) {
00625                     $A_B = '<strong>' . $A_B;
00626                     $A_E .= '</strong>';
00627                 }
00628             } else {
00629                 $A_B = '';
00630                 $A_E = '';
00631             }
00632             $HTML .= ($first ? '' : '<img src="' . $GLOBALS['BACK_PATH'] . 'gfx/ol/' . $PM . $BTM . '.gif" width="18" height="16" align="top" border="0" alt="" />') .
00633                      $icon .
00634                      $A_B . htmlspecialchars(t3lib_div::fixed_lgd_cs($row['title'], $GLOBALS['BE_USER']->uc['titleLen'])) . $A_E . '&nbsp;&nbsp;';
00635             $RL = $this->ext_getRootlineNumber($row['pid']);
00636             $keyArray[] = '<tr class="' . ($i++ % 2 == 0 ? 'bgColor4' : 'bgColor6') . '">
00637                             <td nowrap="nowrap">' . $HTML . '</td>
00638                             <td align="center">' . ($row['root'] ? t3lib_iconWorks::getSpriteIcon('status-status-checked') : '') . '&nbsp;&nbsp;</td>
00639                             <td align="center">' . ($row['clConf'] ? t3lib_iconWorks::getSpriteIcon('status-status-checked') : '') . '&nbsp;&nbsp;' . '</td>
00640                             <td align="center">' . ($row['clConst'] ? t3lib_iconWorks::getSpriteIcon('status-status-checked') : '') . '&nbsp;&nbsp;' . '</td>
00641                             <td align="center">' . ($row['pid'] ? $row['pid'] : '') . '</td>
00642                             <td align="center">' . (strcmp($RL, '') ? $RL : '') . '</td>
00643                             <td>' . ($row['next'] ? '&nbsp;' . $row['next'] . '&nbsp;&nbsp;' : '') . '</td>
00644                         </tr>';
00645             if ($deeper) {
00646                 $keyArray = $this->ext_getTemplateHierarchyArr(
00647                     $arr[$key . '.'],
00648                     $depthData . ($first ? '' : '<img src="' . $GLOBALS['BACK_PATH'] . 'gfx/ol/' . $LN . '.gif" width="18" height="16" align="top" />'),
00649                     $keyArray
00650                 );
00651             }
00652         }
00653         return $keyArray;
00654     }
00655 
00656     /**
00657      * [Describe function...]
00658      *
00659      * @param   [type]      $depthDataArr: ...
00660      * @param   [type]      $pointer: ...
00661      * @return  [type]      ...
00662      */
00663     function ext_process_hierarchyInfo($depthDataArr, &$pointer) {
00664         $parent = $this->hierarchyInfo[$pointer - 1]['templateParent'];
00665         while ($pointer > 0 && $this->hierarchyInfo[$pointer - 1]['templateParent'] == $parent) {
00666             $pointer--;
00667             $row = $this->hierarchyInfo[$pointer];
00668 
00669             $depthDataArr[$row['templateID']] = $row;
00670             $depthDataArr[$row['templateID']]['bgcolor_setup'] = isset($this->clearList_setup_temp[$row['templateID']]) ? ' class="bgColor5"' : '';
00671             $depthDataArr[$row['templateID']]['bgcolor_const'] = isset($this->clearList_const_temp[$row['templateID']]) ? ' class="bgColor5"' : '';
00672             unset($this->clearList_setup_temp[$row['templateID']]);
00673             unset($this->clearList_const_temp[$row['templateID']]);
00674             $this->templateTitles[$row['templateID']] = $row['title'];
00675 
00676             if ($row['templateID'] == $this->hierarchyInfo[$pointer - 1]['templateParent']) {
00677                 $depthDataArr[$row['templateID'] . '.'] = $this->ext_process_hierarchyInfo(array(), $pointer);
00678             }
00679         }
00680         return $depthDataArr;
00681     }
00682 
00683     /**
00684      * [Describe function...]
00685      *
00686      * @param   [type]      $config: ...
00687      * @param   [type]      $lineNumbers: ...
00688      * @param   [type]      $comments: ...
00689      * @param   [type]      $crop: ...
00690      * @param   [type]      $syntaxHL: ...
00691      * @param   [type]      $syntaxHLBlockmode: ...
00692      * @return  [type]      ...
00693      */
00694     function ext_outputTS($config, $lineNumbers = 0, $comments = 0, $crop = 0, $syntaxHL = 0, $syntaxHLBlockmode = 0) {
00695         $all = '';
00696         foreach ($config as $str) {
00697             $all .= LF . '[GLOBAL]' . LF . $str;
00698         }
00699 
00700         if ($syntaxHL) {
00701             $all = preg_replace('/^[^' . LF . ']*./', '', $all);
00702             $all = chop($all);
00703             $tsparser = t3lib_div::makeInstance('t3lib_TSparser');
00704             $tsparser->lineNumberOffset = $this->ext_lineNumberOffset + 1;
00705             $tsparser->parentObject = $this;
00706             return $tsparser->doSyntaxHighlight($all, $lineNumbers ? array($this->ext_lineNumberOffset + 1) : '', $syntaxHLBlockmode);
00707         } else {
00708             return $this->ext_formatTS($all, $lineNumbers, $comments, $crop);
00709         }
00710     }
00711 
00712     /**
00713      * Returns a new string of max. $chars lenght
00714      * If the string is longer, it will be truncated and prepended with '...'
00715      * $chars must be an integer of at least 4
00716      *
00717      * @param   [type]      $string: ...
00718      * @param   [type]      $chars: ...
00719      * @return  [type]      ...
00720      */
00721     function ext_fixed_lgd($string, $chars) {
00722         if ($chars >= 4) {
00723             if (strlen($string) > $chars) {
00724                 if (strlen($string) > 24 && substr($string, 0, 12) == '##' . $this->Cmarker . '_B##') {
00725                     return '##' . $this->Cmarker . '_B##' . t3lib_div::fixed_lgd_cs(substr($string, 12, -12), $chars - 3) . '##' . $this->Cmarker . '_E##';
00726                 } else {
00727                     return t3lib_div::fixed_lgd_cs($string, $chars - 3);
00728                 }
00729             }
00730         }
00731         return $string;
00732     }
00733 
00734     /**
00735      * [Describe function...]
00736      *
00737      * @param   [type]      $ln: ...
00738      * @param   [type]      $str: ...
00739      * @return  [type]      ...
00740      */
00741     function ext_lnBreakPointWrap($ln, $str) {
00742         return '<a href="#" onClick="return brPoint(' . $ln . ',' . ($this->ext_lineNumberOffset_mode == "setup" ? 1 : 0) . ');">' . $str . '</a>';
00743     }
00744 
00745     /**
00746      * [Describe function...]
00747      *
00748      * @param   [type]      $input: ...
00749      * @param   [type]      $ln: ...
00750      * @param   [type]      $comments: ...
00751      * @param   [type]      $crop: ...
00752      * @return  [type]      ...
00753      */
00754     function ext_formatTS($input, $ln, $comments = 1, $crop = 0) {
00755         $input = preg_replace('/^[^' . LF . ']*./', '', $input);
00756         $input = chop($input);
00757         $cArr = explode(LF, $input);
00758 
00759         $n = ceil(log10(count($cArr) + $this->ext_lineNumberOffset));
00760         $lineNum = '';
00761         foreach ($cArr as $k => $v) {
00762             $lln = $k + $this->ext_lineNumberOffset + 1;
00763             if ($ln) {
00764                 $lineNum = $this->ext_lnBreakPointWrap($lln, str_replace(' ', '&nbsp;', sprintf('% ' . $n . 'd', $lln))) . ':   ';
00765             }
00766             $v = htmlspecialchars($v);
00767             if ($crop) {
00768                 $v = $this->ext_fixed_lgd($v, ($ln ? 71 : 77));
00769             }
00770             $cArr[$k] = $lineNum . str_replace(' ', '&nbsp;', $v);
00771 
00772             $firstChar = substr(trim($v), 0, 1);
00773             if ($firstChar == '[') {
00774                 $cArr[$k] = '<font color="green"><strong>' . $cArr[$k] . '</strong></font>';
00775             } elseif ($firstChar == '/' || $firstChar == '#') {
00776                 if ($comments) {
00777                     $cArr[$k] = '<span class="typo3-dimmed">' . $cArr[$k] . '</span>';
00778                 } else {
00779                     unset($cArr[$k]);
00780                 }
00781             }
00782 
00783 
00784         }
00785         $output = implode($cArr, '<br />') . '<br />';
00786         return $output;
00787     }
00788 
00789     /**
00790      * [Describe function...]
00791      *
00792      * @param   [type]      $id: ...
00793      * @param   [type]      $template_uid: ...
00794      * @return  [type]      ...
00795      */
00796     function ext_getFirstTemplate($id, $template_uid = 0) {
00797             // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
00798         if (intval($id)) {
00799             if ($template_uid) {
00800                 $addC = ' AND uid=' . $template_uid;
00801             }
00802             $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid=' . intval($id) . $addC . ' ' . $this->whereClause, '', 'sorting', '1');
00803             $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00804             t3lib_BEfunc::workspaceOL('sys_template', $row);
00805             $GLOBALS['TYPO3_DB']->sql_free_result($res);
00806             return $row; // Returns the template row if found.
00807         }
00808     }
00809 
00810     /**
00811      * [Describe function...]
00812      *
00813      * @param   [type]      $id: ...
00814      * @return  [type]      ...
00815      */
00816     function ext_getAllTemplates($id) {
00817             // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
00818         if (intval($id)) {
00819             $outRes = array();
00820             $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid=' . intval($id) . ' ' . $this->whereClause, '', 'sorting');
00821             while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00822                 t3lib_BEfunc::workspaceOL('sys_template', $row);
00823                 if (is_array($row)) {
00824                     $outRes[] = $row;
00825                 }
00826             }
00827             $GLOBALS['TYPO3_DB']->sql_free_result($res);
00828             return $outRes; // Returns the template rows in an array.
00829         }
00830     }
00831 
00832     /**
00833      * This function compares the flattened constants (default and all).
00834      * Returns an array with the constants from the whole template which may be edited by the module.
00835      *
00836      * @param   [type]      $default: ...
00837      * @return  [type]      ...
00838      */
00839     function ext_compareFlatSetups($default) {
00840         $editableComments = array();
00841         reset($this->flatSetup);
00842         foreach ($this->flatSetup as $const => $value) {
00843             if (substr($const, -2) != '..' && isset($this->flatSetup[$const . '..'])) {
00844                 $comment = trim($this->flatSetup[$const . '..']);
00845                 $c_arr = explode(LF, $comment);
00846                 foreach ($c_arr as $k => $v) {
00847                     $line = trim(preg_replace('/^[#\/]*/', '', $v));
00848                     if ($line) {
00849                         $parts = explode(';', $line);
00850                         foreach ($parts as $par) {
00851                             if (strstr($par, '=')) {
00852                                 $keyValPair = explode('=', $par, 2);
00853                                 switch (trim(strtolower($keyValPair[0]))) {
00854                                     case 'type':
00855                                             // Type:
00856                                         $editableComments[$const]['type'] = trim($keyValPair[1]);
00857                                     break;
00858                                     case 'cat':
00859                                             // list of categories.
00860                                         $catSplit = explode('/', strtolower($keyValPair[1]));
00861                                         $editableComments[$const]['cat'] = trim($catSplit[0]);
00862                                         $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.
00863                                         if ($catSplit[1] && isset($this->subCategories[$catSplit[1]])) {
00864                                             $editableComments[$const]['subcat_name'] = $catSplit[1];
00865                                             $editableComments[$const]['subcat'] = $this->subCategories[$catSplit[1]][1] . '/' .
00866                                                                                   $catSplit[1] . '/' . trim($catSplit[2]) . 'z';
00867                                         } else {
00868                                             $editableComments[$const]['subcat'] = 'x' . '/' . trim($catSplit[2]) . 'z';
00869                                         }
00870                                     break;
00871                                     case 'label':
00872                                             // label
00873                                         $editableComments[$const]['label'] = trim($keyValPair[1]);
00874                                     break;
00875                                     case 'customsubcategory':
00876                                             // custom subCategory label
00877                                         $customSubcategory = explode('=', $keyValPair[1], 2);
00878                                         if (trim($customSubcategory[0])) {
00879                                             $subCategoryKey = strtolower($customSubcategory[0]);
00880                                             $this->subCategories[$subCategoryKey][0] = $GLOBALS['LANG']->sL($customSubcategory[1]);
00881                                         }
00882                                     break;
00883                                 }
00884                             }
00885                         }
00886                     }
00887                 }
00888             }
00889             if (isset($editableComments[$const])) {
00890                 $editableComments[$const]['name'] = $const;
00891                 $editableComments[$const]['value'] = trim($value);
00892                 if (isset($default[$const])) {
00893                     $editableComments[$const]['default_value'] = trim($default[$const]);
00894                 }
00895             }
00896         }
00897         return $editableComments;
00898     }
00899 
00900     /**
00901      * [Describe function...]
00902      *
00903      * @param   [type]      $editConstArray: ...
00904      * @return  [type]      ...
00905      */
00906     function ext_categorizeEditableConstants($editConstArray) {
00907             // Runs through the available constants and fills the $this->categories array with pointers and priority-info
00908         foreach ($editConstArray as $constName => $constData) {
00909             if (!$constData['type']) {
00910                 $constData['type'] = 'string';
00911             }
00912             $cats = explode(',', $constData['cat']);
00913             foreach ($cats as $theCat) { // if = only one category, while allows for many. We have agreed on only one category is the most basic way...
00914                 $theCat = trim($theCat);
00915                 if ($theCat) {
00916                     $this->categories[$theCat][$constName] = $constData['subcat'];
00917                 }
00918             }
00919         }
00920     }
00921 
00922     /**
00923      * [Describe function...]
00924      *
00925      * @return  [type]      ...
00926      */
00927     function ext_getCategoryLabelArray() {
00928             // Returns array used for labels in the menu.
00929         $retArr = array();
00930         foreach ($this->categories as $k => $v) {
00931             if (count($v)) {
00932                 $retArr[$k] = strtoupper($k) . ' (' . count($v) . ')';
00933             }
00934         }
00935         return $retArr;
00936     }
00937 
00938     /**
00939      * [Describe function...]
00940      *
00941      * @param   [type]      $type: ...
00942      * @return  [type]      ...
00943      */
00944     function ext_getTypeData($type) {
00945         $retArr = array();
00946         $type = trim($type);
00947         if (!$type) {
00948             $retArr['type'] = 'string';
00949         } else {
00950             $m = strcspn($type, ' [');
00951             $retArr['type'] = strtolower(substr($type, 0, $m));
00952             if (t3lib_div::inList('int,options,file,boolean,offset,user', $retArr['type'])) {
00953                 $p = trim(substr($type, $m));
00954                 $reg = array();
00955                 preg_match('/\[(.*)\]/', $p, $reg);
00956                 $p = trim($reg[1]);
00957                 if ($p) {
00958                     $retArr['paramstr'] = $p;
00959                     switch ($retArr['type']) {
00960                         case 'int':
00961                             if (substr($retArr['paramstr'], 0, 1) == '-') {
00962                                 $retArr['params'] = t3lib_div::intExplode('-', substr($retArr['paramstr'], 1));
00963                                 $retArr['params'][0] = intval('-' . $retArr['params'][0]);
00964                             } else {
00965                                 $retArr['params'] = t3lib_div::intExplode('-', $retArr['paramstr']);
00966                             }
00967                             $retArr['paramstr'] = $retArr['params'][0] . ' - ' . $retArr['params'][1];
00968                         break;
00969                         case 'options':
00970                             $retArr['params'] = explode(',', $retArr['paramstr']);
00971                         break;
00972                     }
00973                 }
00974             }
00975         }
00976         return $retArr;
00977     }
00978 
00979     /**
00980      * [Describe function...]
00981      *
00982      * @param   [type]      $category: ...
00983      * @return  [type]      ...
00984      */
00985     function ext_getTSCE_config($category) {
00986         $catConf = $this->setup['constants']['TSConstantEditor.'][$category . '.'];
00987         $out = array();
00988         if (is_array($catConf)) {
00989             foreach ($catConf as $key => $val) {
00990                 switch ($key) {
00991                     case 'image':
00992                         $out['imagetag'] = $this->ext_getTSCE_config_image($catConf['image']);
00993                     break;
00994                     case 'description':
00995                     case 'bulletlist':
00996                     case 'header':
00997                         $out[$key] = $val;
00998                     break;
00999                     default:
01000                         if (t3lib_div::testInt($key)) {
01001                             $constRefs = explode(',', $val);
01002                             foreach ($constRefs as $const) {
01003                                 $const = trim($const);
01004                                 if ($const && $const <= 20) {
01005                                     $out['constants'][$const] .= $this->ext_getKeyImage($key);
01006                                 }
01007                             }
01008                         }
01009                     break;
01010                 }
01011             }
01012         }
01013         $this->helpConfig = $out;
01014     }
01015 
01016     /**
01017      * [Describe function...]
01018      *
01019      * @param   [type]      $key: ...
01020      * @return  [type]      ...
01021      */
01022     function ext_getKeyImage($key) {
01023         return '<img src="' . $this->ext_localWebGfxPrefix . 'gfx/' . $key . '.gif" align="top" hspace=2>';
01024     }
01025 
01026     /**
01027      * [Describe function...]
01028      *
01029      * @param   [type]      $imgConf: ...
01030      * @return  [type]      ...
01031      */
01032     function ext_getTSCE_config_image($imgConf) {
01033         if (substr($imgConf, 0, 4) == 'gfx/') {
01034             $iFile = $this->ext_localGfxPrefix . $imgConf;
01035             $tFile = $this->ext_localWebGfxPrefix . $imgConf;
01036         } elseif (substr($imgConf, 0, 4) == 'EXT:') {
01037             $iFile = t3lib_div::getFileAbsFileName($imgConf);
01038             if ($iFile) {
01039                 $f = substr($iFile, strlen(PATH_site));
01040                 $tFile = $GLOBALS['BACK_PATH'] . '../' . $f;
01041             }
01042         } else {
01043             $f = 'uploads/tf/' . $this->extractFromResources($this->setup['resources'], $imgConf);
01044             $iFile = PATH_site . $f;
01045             $tFile = $GLOBALS['BACK_PATH'] . '../' . $f;
01046         }
01047         $imageInfo = @getImagesize($iFile);
01048         return '<img src="' . $tFile . '" ' . $imageInfo[3] . '>';
01049     }
01050 
01051     /**
01052      * [Describe function...]
01053      *
01054      * @return  [type]      ...
01055      */
01056     function ext_resourceDims() {
01057         if ($this->setup['resources']) {
01058             $rArr = explode(',', $this->setup['resources']);
01059             foreach ($rArr as $c => $val) {
01060                 $val = trim($val);
01061                 $theFile = PATH_site . 'uploads/tf/' . $val;
01062                 if ($val && @is_file($theFile)) {
01063                     $imgInfo = @getimagesize($theFile);
01064                 }
01065                 if (is_array($imgInfo)) {
01066                     $this->resourceDimensions[$val] = ' (' . $imgInfo[0] . 'x' . $imgInfo[1] . ')';
01067                 }
01068             }
01069         }
01070         foreach ($this->dirResources as $c => $val) {
01071             $val = trim($val);
01072             $imgInfo = @getimagesize(PATH_site . $val);
01073             if (is_array($imgInfo)) {
01074                 $this->resourceDimensions[$val] = ' (' . $imgInfo[0] . 'x' . $imgInfo[1] . ')';
01075             }
01076         }
01077     }
01078 
01079     /**
01080      * [Describe function...]
01081      *
01082      * @param   [type]      $path: ...
01083      * @return  [type]      ...
01084      */
01085     function ext_readDirResources($path) {
01086         $path = trim($path);
01087         if ($path && strstr($path, $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'])) {
01088             $path = rtrim($path, '/');
01089             $this->readDirectory(PATH_site . $path);
01090         }
01091     }
01092 
01093     /**
01094      * [Describe function...]
01095      *
01096      * @param   [type]      $path: ...
01097      * @param   [type]      $type: ...
01098      * @return  [type]      ...
01099      */
01100     function readDirectory($path, $type = 'file') {
01101         if (@is_dir($path)) {
01102             $d = @dir($path);
01103             $tempArray = Array();
01104             if (is_object($d)) {
01105                 while ($entry = $d->read()) {
01106                     if ($entry != '.' && $entry != '..') {
01107                         $wholePath = $path . '/' . $entry; // Because of odd PHP-error where  <BR>-tag is sometimes placed after a filename!!
01108                         if (file_exists($wholePath) && (!$type || filetype($wholePath) == $type)) {
01109                             $fI = t3lib_div::split_fileref($wholePath);
01110                             $this->dirResources[] = substr($wholePath, strlen(PATH_site));
01111                         }
01112                     }
01113                 }
01114                 $d->close();
01115             }
01116         }
01117     }
01118 
01119     /**
01120      * [Describe function...]
01121      *
01122      * @param   [type]      $params: ...
01123      * @return  [type]      ...
01124      */
01125     function ext_fNandV($params) {
01126         $fN = 'data[' . $params['name'] . ']';
01127         $fV = $params['value'];
01128         if (preg_match('/^{[\$][a-zA-Z0-9\.]*}$/', trim($fV), $reg)) { // Values entered from the constantsedit cannot be constants!    230502; removed \{ and set {
01129             $fV = '';
01130         }
01131         $fV = htmlspecialchars($fV);
01132 
01133         return array($fN, $fV, $params);
01134     }
01135 
01136     /**
01137      * This functions returns the HTML-code that creates the editor-layout of the module.
01138      *
01139      * @param   [type]      $theConstants: ...
01140      * @param   [type]      $category: ...
01141      * @return  [type]      ...
01142      */
01143     function ext_printFields($theConstants, $category) {
01144         reset($theConstants);
01145         $output = '<script type="text/javascript" src="' . $GLOBALS['BACK_PATH'] . 'js/constantEditor.js"></script>
01146         ';
01147         $subcat = '';
01148         if (is_array($this->categories[$category])) {
01149 
01150             $help = $this->helpConfig;
01151             $this->rArr = explode(',', $this->setup['resources'] . ',' . implode($this->dirResources, ','));
01152 
01153             if (!$this->doNotSortCategoriesBeforeMakingForm) {
01154                 asort($this->categories[$category]);
01155             }
01156             foreach ($this->categories[$category] as $name => $type) {
01157                 $params = $theConstants[$name];
01158                 if (is_array($params)) {
01159                     if ($subcat != $params['subcat_name']) {
01160                         $subcat = $params['subcat_name'];
01161                         $subcat_name = $params['subcat_name'] ? $this->subCategories[$params['subcat_name']][0] : 'Others';
01162 
01163                         $output .= '<h2 class="typo3-tstemplate-ceditor-subcat">' . $subcat_name . '</h2>';
01164                     }
01165 
01166                     $label = $GLOBALS['LANG']->sL($params['label']);
01167                     $label_parts = explode(':', $label, 2);
01168                     if (count($label_parts) == 2) {
01169                         $head = trim($label_parts[0]);
01170                         $body = trim($label_parts[1]);
01171                     } else {
01172                         $head = trim($label_parts[0]);
01173                         $body = '';
01174                     }
01175                     if (strlen($head) > 35) {
01176                         if (!$body) {
01177                             $body = $head;
01178                         }
01179                         $head = t3lib_div::fixed_lgd_cs($head, 35);
01180                     }
01181                     $typeDat = $this->ext_getTypeData($params['type']);
01182                     $checked = '';
01183                     $p_field = '';
01184                     $raname = substr(md5($params['name']), 0, 10);
01185                     $aname = '\'' . $raname . '\'';
01186 
01187                     list($fN, $fV, $params) = $this->ext_fNandV($params);
01188 
01189                     switch ($typeDat['type']) {
01190                         case 'int':
01191                         case 'int+':
01192                             $p_field = '<input id="' . $fN . '" type="text" name="' . $fN . '" value="' . $fV . '"' .
01193                                        $GLOBALS['TBE_TEMPLATE']->formWidth(5) . ' onChange="uFormUrl(' . $aname . ')" />';
01194                             if ($typeDat['paramstr']) {
01195                                 $p_field .= ' Range: ' . $typeDat['paramstr'];
01196                             } elseif ($typeDat['type'] == 'int+') {
01197                                 $p_field .= ' Range: 0 - ';
01198                             } else {
01199                                 $p_field .= ' (Integer)';
01200                             }
01201                         break;
01202                         case 'color':
01203                             $colorNames = explode(',', ',' . $this->HTMLcolorList);
01204                             $p_field = '';
01205                             foreach ($colorNames as $val) {
01206                                 $sel = '';
01207                                 if ($val == strtolower($params['value'])) {
01208                                     $sel = ' selected';
01209                                 }
01210                                 $p_field .= '<option value="' . htmlspecialchars($val) . '"' . $sel . '>' . $val . '</option>';
01211                             }
01212                             $p_field = '<select id="select-' . $fN . '" rel="' . $fN . '" name="C' . $fN .
01213                                        '" class="typo3-tstemplate-ceditor-color-select" onChange="uFormUrl(' .
01214                                        $aname . ');">' . $p_field . '</select>';
01215 
01216                             $p_field .= '<input type="text" id="input-' . $fN . '" rel="' . $fN . '" name="' . $fN .
01217                                         '" class="typo3-tstemplate-ceditor-color-input" value="' . $fV . '"' .
01218                                         $GLOBALS['TBE_TEMPLATE']->formWidth(7) . ' onChange="uFormUrl(' . $aname . ')" />';
01219                         break;
01220                         case 'wrap':
01221                             $wArr = explode('|', $fV);
01222                             $p_field = '<input type="text" id="' . $fN . '" name="' . $fN . '" value="' . $wArr[0] . '"' .
01223                                        $GLOBALS['TBE_TEMPLATE']->formWidth(29) . ' onChange="uFormUrl(' . $aname . ')" />';
01224                             $p_field .= ' | ';
01225                             $p_field .= '<input type="text" name="W' . $fN . '" value="' . $wArr[1] . '"' .
01226                                         $GLOBALS['TBE_TEMPLATE']->formWidth(15) . ' onChange="uFormUrl(' . $aname . ')" />';
01227                         break;
01228                         case 'offset':
01229                             $wArr = explode(',', $fV);
01230                             $labels = t3lib_div::trimExplode(',', $typeDat['paramstr']);
01231                             $p_field = ($labels[0] ? $labels[0] : 'x') . ':<input type="text" name="' . $fN . '" value="' . $wArr[0] . '"' .
01232                                        $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' onChange="uFormUrl(' . $aname . ')" />';
01233                             $p_field .= ' , ';
01234                             $p_field .= ($labels[1] ? $labels[1] : 'y') . ':<input type="text" name="W' . $fN . '" value="' . $wArr[1] . '"' .
01235                                         $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' onChange="uFormUrl(' . $aname . ')" />';
01236                             for ($aa = 2; $aa < count($labels); $aa++) {
01237                                 if ($labels[$aa]) {
01238                                     $p_field .= ' , ' . $labels[$aa] . ':<input type="text" name="W' . $aa . $fN . '" value="' . $wArr[$aa] . '"' .
01239                                                 $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' onChange="uFormUrl(' . $aname . ')" />';
01240                                 } else {
01241                                     $p_field .= '<input type="hidden" name="W' . $aa . $fN . '" value="' . $wArr[$aa] . '" />';
01242                                 }
01243                             }
01244                         break;
01245                         case 'options':
01246                             if (is_array($typeDat['params'])) {
01247                                 $p_field = '';
01248                                 foreach ($typeDat['params'] as $val) {
01249                                     $vParts = explode('=', $val, 2);
01250                                     $label = $vParts[0];
01251                                     $val = isset($vParts[1]) ? $vParts[1] : $vParts[0];
01252 
01253                                         // option tag:
01254                                     $sel = '';
01255                                     if ($val == $params['value']) {
01256                                         $sel = ' selected';
01257                                     }
01258                                     $p_field .= '<option value="' . htmlspecialchars($val) . '"' . $sel . '>' . $GLOBALS['LANG']->sL($label) . '</option>';
01259                                 }
01260                                 $p_field = '<select id="' . $fN . '" name="' . $fN . '" onChange="uFormUrl(' . $aname . ')">' . $p_field . '</select>';
01261                             }
01262                         break;
01263                         case 'boolean':
01264                             $p_field = '<input type="hidden" name="' . $fN . '" value="0" />';
01265                             $sel = '';
01266                             if ($fV) {
01267                                 $sel = ' checked';
01268                             }
01269                             $p_field .= '<input id="' . $fN . '" type="checkbox" name="' . $fN . '" value="' . ($typeDat['paramstr'] ? $typeDat['paramstr'] : 1) .
01270                                         '"' . $sel . ' onClick="uFormUrl(' . $aname . ')" />';
01271                         break;
01272                         case 'comment':
01273                             $p_field = '<input type="hidden" name="' . $fN . '" value="#" />';
01274                             $sel = '';
01275                             if (!$fV) {
01276                                 $sel = ' checked';
01277                             }
01278                             $p_field .= '<input id="' . $fN . '" type="checkbox" name="' . $fN . '" value=""' . $sel . ' onClick="uFormUrl(' . $aname . ')" />';
01279                         break;
01280                         case 'file':
01281                             $p_field = '<option value=""></option>';
01282                             $theImage = '';
01283                             $selectThisFile = $this->extractFromResources($this->setup['resources'], $params['value']);
01284                             if ($params['value'] && !$selectThisFile) {
01285                                 if (in_array($params['value'], $this->dirResources)) {
01286                                     $selectThisFile = $params['value'];
01287                                 }
01288                             }
01289                                 // extensionlist
01290                             $extList = $typeDat['paramstr'];
01291                             $p_field = '<option value="">(' . $extList . ')</option>';
01292                             if ($extList == 'IMAGE_EXT') {
01293                                 $extList = $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'];
01294                             }
01295                             reset($this->rArr);
01296                             $onlineResourceFlag = $this->ext_defaultOnlineResourceFlag;
01297 
01298                             foreach ($this->rArr as $c => $val) {
01299                                 $val = trim($val);
01300                                 $fI = t3lib_div::split_fileref($val);
01301                                 if ($val && (!$extList || t3lib_div::inList($extList, $fI['fileext']))) {
01302                                     if ($onlineResourceFlag <= 0 && strstr($fI['path'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'])) {
01303                                         if ($onlineResourceFlag < 0) {
01304                                             $p_field .= '<option value=""></option>';
01305                                         }
01306                                         $p_field .= '<option value="">__' . $fI['path'] . '__:</option>';
01307                                         $onlineResourceFlag = 1;
01308                                     }
01309                                     $dims = $this->resourceDimensions[$val];
01310                                     $sel = '';
01311 
01312                                         // Check if $params['value'] is in the list of resources.
01313                                     if ($selectThisFile && $selectThisFile == $val) {
01314                                         $sel = ' selected';
01315                                         if ($onlineResourceFlag <= 0) {
01316                                             $theImage = t3lib_BEfunc::thumbCode(
01317                                                 array(
01318                                                      'resources' => $selectThisFile
01319                                                 ),
01320                                                 'sys_template',
01321                                                 'resources',
01322                                                 $GLOBALS['BACK_PATH'],
01323                                                 ''
01324                                             );
01325                                         } else {
01326                                             $theImage = t3lib_BEfunc::thumbCode(
01327                                                 array(
01328                                                      'resources' => $fI['file']
01329                                                 ),
01330                                                 'sys_template',
01331                                                 'resources',
01332                                                 $GLOBALS['BACK_PATH'],
01333                                                 '',
01334                                                 $fI['path']
01335                                             );
01336                                         }
01337                                     }
01338 
01339                                     if ($onlineResourceFlag <= 0) {
01340                                         $onlineResourceFlag--;
01341                                             // Value is set with a *
01342                                         $val = $this->ext_setStar($val);
01343                                         $p_field .= '<option value="' . htmlspecialchars($val) . '"' . $sel . '>' . $val . $dims . '</option>';
01344                                     } else {
01345                                         $p_field .= '<option value="' . htmlspecialchars($val) . '"' . $sel . '>' . $fI['file'] . $dims . '</option>';
01346                                     }
01347                                 }
01348                             }
01349 
01350                             if (trim($params['value']) && !$selectThisFile) {
01351                                 $val = $params['value'];
01352                                 $p_field .= '<option value=""></option>';
01353                                 $p_field .= '<option value="' . htmlspecialchars($val) . '" selected>' . $val . '</option>';
01354                             }
01355 
01356                             $p_field = '<select id="' . $fN . '" name="' . $fN . '" onChange="uFormUrl(' . $aname . ')">' . $p_field . '</select>';
01357                             $p_field .= $theImage;
01358 
01359                             if (!$this->ext_noCEUploadAndCopying) {
01360                                     // Copy a resource
01361                                 $copyFile = $this->extractFromResources($this->setup['resources'], $params['value']);
01362                                 if (!$copyFile) {
01363                                     if ($params['value']) {
01364                                         $copyFile = PATH_site . $this->ext_detectAndFixExtensionPrefix($params['value']);
01365                                     }
01366                                 } else {
01367                                     $copyFile = '';
01368                                 }
01369 
01370                                 if ($copyFile && @is_file($copyFile)) {
01371                                     $p_field .= '<img src="clear.gif" width="20" ' . 'height="1" alt="" />' .
01372                                                 t3lib_iconWorks::getSpriteIcon('actions-edit-copy') . '<input type="checkbox" ' .
01373                                                 'name="_copyResource[' . $params['name'] . ']" value="' . htmlspecialchars($copyFile) .
01374                                                 '" onclick="uFormUrl(' . $aname . ');if (this.checked && !confirm(\'' .
01375                                                 t3lib_div::slashJS(htmlspecialchars(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_tsparser.xml:tsparser_ext.make_copy'), $params['value']))) .
01376                                                 '\')) this.checked=false;" />';
01377                                 }
01378 
01379                                     // Upload?
01380                                 $p_field .= '<br />';
01381                                 $p_field .= '<input id="' . $fN . '" type="file" name="upload_' . $fN . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth() .
01382                                             ' onChange="uFormUrl(' . $aname . ')" size="50" />';
01383                             }
01384                         break;
01385                         case 'user':
01386                             $userFunction = $typeDat['paramstr'];
01387                             $userFunctionParams = array('fieldName' => $fN, 'fieldValue' => $fV);
01388                             $p_field = t3lib_div::callUserFunction($userFunction, $userFunctionParams, $this, '');
01389                         break;
01390                         case 'small':
01391                         default:
01392                             $fwidth = $typeDat['type'] == 'small' ? 10 : 46;
01393                             $p_field = '<input id="' . $fN . '" type="text" name="' . $fN . '" value="' . $fV . '"' .
01394                                        $GLOBALS['TBE_TEMPLATE']->formWidth($fwidth) . ' onChange="uFormUrl(' . $aname . ')" />';
01395                         break;
01396                     }
01397 
01398                         // Define default names and IDs
01399                     $userTyposcriptID = 'userTS-' . $params['name'];
01400                     $defaultTyposcriptID = 'defaultTS-' . $params['name'];
01401                     $checkboxName = 'check[' . $params['name'] . ']';
01402                     $checkboxID = $checkboxName;
01403 
01404                         // Handle type=color specially
01405                     if ($typeDat['type'] == 'color' && substr($params['value'], 0, 2) != '{$') {
01406                         $color = '<div id="colorbox-' . $fN . '" class="typo3-tstemplate-ceditor-colorblock" style="background-color:' .
01407                                  $params['value'] . ';">&nbsp;</div>';
01408                     } else {
01409                         $color = '';
01410                     }
01411 
01412                     if (!$this->ext_dontCheckIssetValues) {
01413 
01414                         /* Set the default styling options */
01415                         if (isset($this->objReg[$params['name']])) {
01416                             $checkboxValue = 'checked';
01417                             $userTyposcriptStyle = '';
01418                             $defaultTyposcriptStyle = 'style="display:none;"';
01419                         } else {
01420                             $checkboxValue = '';
01421                             $userTyposcriptStyle = 'style="display:none;"';
01422                             $defaultTyposcriptStyle = '';
01423                         }
01424 
01425 
01426                         $deleteIconHTML = t3lib_iconWorks::getSpriteIcon(
01427                             'actions-edit-undo',
01428                             array(
01429                                  'class' => "typo3-tstemplate-ceditor-control undoIcon",
01430                                  'alt' => "Revert to default Constant",
01431                                  'title' => "Revert to default Constant",
01432                                  'rel' => $params['name']
01433                             )
01434                         );
01435                         $editIconHTML = t3lib_iconWorks::getSpriteIcon(
01436                             'actions-document-open',
01437                             array(
01438                                  'class' => "typo3-tstemplate-ceditor-control editIcon",
01439                                  'alt' => "Edit this Constant",
01440                                  'title' => "Edit this Constant",
01441                                  'rel' => $params['name']
01442                             )
01443                         );
01444                         $constantCheckbox = '<input type="hidden" name="' . $checkboxName . '" id="' . $checkboxID . '" value="' . $checkboxValue . '"/>';
01445 
01446                             // If there's no default value for the field, use a static label.
01447                         if (!$params['default_value']) {
01448                             $params['default_value'] = '[Empty]';
01449                         }
01450 
01451                         $constantDefaultRow = '<div class="typo3-tstemplate-ceditor-row" id="' . $defaultTyposcriptID . '" ' .
01452                                               $defaultTyposcriptStyle . '>' . $editIconHTML .
01453                                               htmlspecialchars($params['default_value']) . $color . '</div>';
01454                     }
01455 
01456                     $constantEditRow = '<div class="typo3-tstemplate-ceditor-row" id="' . $userTyposcriptID . '" ' .
01457                                        $userTyposcriptStyle . '>' . $deleteIconHTML . $p_field . $color . '</div>';
01458 
01459                     $constantLabel = '<dt class="typo3-tstemplate-ceditor-label">' . htmlspecialchars($head) . '</dt>';
01460                     $constantName = '<dt class="typo3-dimmed">[' . $params['name'] . ']</dt>';
01461                     $constantDescription = $body ? '<dd>' . htmlspecialchars($body) . '</dd>' : '';
01462                     $constantData = '<dd>' . $constantCheckbox . $constantEditRow . $constantDefaultRow . '</dd>';
01463 
01464                     $output .= '<a name="' . $raname . '"></a>' . $help['constants'][$params['name']];
01465                     $output .= '<dl class="typo3-tstemplate-ceditor-constant">' . $constantLabel . $constantName .
01466                                $constantDescription . $constantData . '</dl>';
01467                 } else {
01468                     debug('Error. Constant did not exist. Should not happen.');
01469                 }
01470             }
01471         }
01472         return $output;
01473     }
01474 
01475 
01476     /***************************
01477      *
01478      * Processing input values
01479      *
01480      ***************************/
01481 
01482     /**
01483      * @param   [type]      $constants: ...
01484      * @return  [type]      ...
01485      */
01486     function ext_regObjectPositions($constants) {
01487             // This runs through the lines of the constants-field of the active template and registers the constants-names
01488             // and linepositions in an array, $this->objReg
01489         $this->raw = explode(LF, $constants);
01490         $this->rawP = 0;
01491 
01492         $this->objReg = array(); // resetting the objReg if the divider is found!!
01493         $this->ext_regObjects('');
01494     }
01495 
01496     /**
01497      * [Describe function...]
01498      *
01499      * @param   [type]      $pre: ...
01500      * @return  [type]      ...
01501      */
01502     function ext_regObjects($pre) {
01503             // works with regObjectPositions. "expands" the names of the TypoScript objects
01504         while (isset($this->raw[$this->rawP])) {
01505             $line = ltrim($this->raw[$this->rawP]);
01506             if (strstr($line, $this->edit_divider)) {
01507                 $this->objReg = array(); // resetting the objReg if the divider is found!!
01508             }
01509             $this->rawP++;
01510             if ($line) {
01511                 if (substr($line, 0, 1) == '[') {
01512                     //                  return $line;
01513                 } elseif (strcspn($line, '}#/') != 0) {
01514                     $varL = strcspn($line, ' {=<');
01515                     $var = substr($line, 0, $varL);
01516                     $line = ltrim(substr($line, $varL));
01517                     switch (substr($line, 0, 1)) {
01518                         case '=':
01519                             $this->objReg[$pre . $var] = $this->rawP - 1;
01520                         break;
01521                         case '{':
01522                             $this->ext_inBrace++;
01523                             $this->ext_regObjects($pre . $var . '.');
01524                         break;
01525                     }
01526                     $this->lastComment = '';
01527                 } elseif (substr($line, 0, 1) == '}') {
01528                     $this->lastComment = '';
01529                     $this->ext_inBrace--;
01530                     if ($this->ext_inBrace < 0) {
01531                         $this->ext_inBrace = 0;
01532                     } else {
01533                         break;
01534                     }
01535                 }
01536             }
01537         }
01538     }
01539 
01540     /**
01541      * [Describe function...]
01542      *
01543      * @param   [type]      $key: ...
01544      * @param   [type]      $var: ...
01545      * @return  [type]      ...
01546      */
01547     function ext_putValueInConf($key, $var) {
01548             // Puts the value $var to the TypoScript value $key in the current lines of the templates.
01549             // If the $key is not found in the template constants field, a new line is inserted in the bottom.
01550         $theValue = ' ' . trim($var);
01551         if (isset($this->objReg[$key])) {
01552             $lineNum = $this->objReg[$key];
01553             $parts = explode('=', $this->raw[$lineNum], 2);
01554             if (count($parts) == 2) {
01555                 $parts[1] = $theValue;
01556             }
01557             $this->raw[$lineNum] = implode($parts, '=');
01558         } else {
01559             $this->raw[] = $key . ' =' . $theValue;
01560         }
01561         $this->changed = 1;
01562     }
01563 
01564     /**
01565      * [Describe function...]
01566      *
01567      * @param   [type]      $key: ...
01568      * @return  [type]      ...
01569      */
01570     function ext_removeValueInConf($key) {
01571             // Removes the value in the configuration
01572         if (isset($this->objReg[$key])) {
01573             $lineNum = $this->objReg[$key];
01574             unset($this->raw[$lineNum]);
01575         }
01576         $this->changed = 1;
01577     }
01578 
01579     /**
01580      * [Describe function...]
01581      *
01582      * @param   [type]      $arr: ...
01583      * @param   [type]      $settings: ...
01584      * @return  [type]      ...
01585      */
01586     function ext_depthKeys($arr, $settings) {
01587         $tsbrArray = array();
01588         foreach ($arr as $theK => $theV) {
01589             $theKeyParts = explode('.', $theK);
01590             $depth = '';
01591             $c = count($theKeyParts);
01592             $a = 0;
01593             foreach ($theKeyParts as $p) {
01594                 $a++;
01595                 $depth .= ($depth ? '.' : '') . $p;
01596                 $tsbrArray[$depth] = ($c == $a) ? $theV : 1;
01597             }
01598         }
01599             // Modify settings
01600         foreach ($tsbrArray as $theK => $theV) {
01601             if ($theV) {
01602                 $settings[$theK] = 1;
01603             } else {
01604                 unset($settings[$theK]);
01605             }
01606         }
01607         return $settings;
01608     }
01609 
01610     /**
01611      * [Describe function...]
01612      *
01613      * @param   [type]      $http_post_vars: ...
01614      * @param   [type]      $http_post_files: ...
01615      * @param   [type]      $theConstants: ...
01616      * @param   [type]      $tplRow: ...
01617      * @return  [type]      ...
01618      */
01619     function ext_procesInput($http_post_vars, $http_post_files, $theConstants, $tplRow) {
01620         $data = $http_post_vars['data'];
01621         $check = $http_post_vars['check'];
01622         $copyResource = $http_post_vars['_copyResource'];
01623         $Wdata = $http_post_vars['Wdata'];
01624         $W2data = $http_post_vars['W2data'];
01625         $W3data = $http_post_vars['W3data'];
01626         $W4data = $http_post_vars['W4data'];
01627         $W5data = $http_post_vars['W5data'];
01628 
01629         if (is_array($data)) {
01630             foreach ($data as $key => $var) {
01631                 if (isset($theConstants[$key])) {
01632                     if ($this->ext_dontCheckIssetValues || isset($check[$key])) { // If checkbox is set, update the value
01633                         list($var) = explode(LF, $var); // exploding with linebreak, just to make sure that no multiline input is given!
01634                         $typeDat = $this->ext_getTypeData($theConstants[$key]['type']);
01635                         switch ($typeDat['type']) {
01636                             case 'int':
01637                                 if ($typeDat['paramstr']) {
01638                                     $var = t3lib_div::intInRange($var, $typeDat['params'][0], $typeDat['params'][1]);
01639                                 } else {
01640                                     $var = intval($var);
01641                                 }
01642                             break;
01643                             case 'int+':
01644                                 $var = max(0, intval($var));
01645                             break;
01646                             case 'color':
01647                                 $col = array();
01648                                 if ($var && !t3lib_div::inList($this->HTMLcolorList, strtolower($var))) {
01649                                     $var = preg_replace('/[^A-Fa-f0-9]*/', '', $var);
01650                                     $useFullHex = strlen($var) > 3;
01651 
01652                                     $col[] = HexDec(substr($var, 0, 1));
01653                                     $col[] = HexDec(substr($var, 1, 1));
01654                                     $col[] = HexDec(substr($var, 2, 1));
01655 
01656                                     if ($useFullHex) {
01657                                         $col[] = HexDec(substr($var, 3, 1));
01658                                         $col[] = HexDec(substr($var, 4, 1));
01659                                         $col[] = HexDec(substr($var, 5, 1));
01660                                     }
01661 
01662                                     $var = substr('0' . DecHex($col[0]), -1) . substr('0' . DecHex($col[1]), -1) . substr('0' . DecHex($col[2]), -1);
01663                                     if ($useFullHex) {
01664                                         $var .= substr('0' . DecHex($col[3]), -1) . substr('0' . DecHex($col[4]), -1) . substr('0' . DecHex($col[5]), -1);
01665                                     }
01666 
01667                                     $var = '#' . strtoupper($var);
01668                                 }
01669                             break;
01670                             case 'comment':
01671                                 if ($var) {
01672                                     $var = '#';
01673                                 } else {
01674                                     $var = '';
01675                                 }
01676                             break;
01677                             case 'wrap':
01678                                 if (isset($Wdata[$key])) {
01679                                     $var .= '|' . $Wdata[$key];
01680                                 }
01681                             break;
01682                             case 'offset':
01683                                 if (isset($Wdata[$key])) {
01684                                     $var = intval($var) . ',' . intval($Wdata[$key]);
01685                                     if (isset($W2data[$key])) {
01686                                         $var .= ',' . intval($W2data[$key]);
01687                                         if (isset($W3data[$key])) {
01688                                             $var .= ',' . intval($W3data[$key]);
01689                                             if (isset($W4data[$key])) {
01690                                                 $var .= ',' . intval($W4data[$key]);
01691                                                 if (isset($W5data[$key])) {
01692                                                     $var .= ',' . intval($W5data[$key]);
01693                                                 }
01694                                             }
01695                                         }
01696                                     }
01697                                 }
01698                             break;
01699                             case 'boolean':
01700                                 if ($var) {
01701                                     $var = $typeDat['paramstr'] ? $typeDat['paramstr'] : 1;
01702                                 }
01703                             break;
01704                             case 'file':
01705                                 if (!$this->ext_noCEUploadAndCopying) {
01706                                     if ($http_post_files['upload_data']['name'][$key] && $http_post_files['upload_data']['tmp_name'][$key] != 'none') {
01707                                         $var = $this->upload_copy_file(
01708                                             $typeDat,
01709                                             $tplRow,
01710                                             trim($http_post_files['upload_data']['name'][$key]),
01711                                             $http_post_files['upload_data']['tmp_name'][$key]
01712                                         );
01713                                     }
01714                                     if ($copyResource[$key]) {
01715                                         $var = $this->upload_copy_file(
01716                                             $typeDat,
01717                                             $tplRow,
01718                                             basename($copyResource[$key]),
01719                                             $copyResource[$key]
01720                                         );
01721                                     }
01722                                 }
01723                             break;
01724                         }
01725                         if ($this->ext_printAll || strcmp($theConstants[$key]['value'], $var)) {
01726                             $this->ext_putValueInConf($key, $var); // Put value in, if changed.
01727                         }
01728                         unset($check[$key]); // Remove the entry because it has been "used"
01729                     } else {
01730                         $this->ext_removeValueInConf($key);
01731                     }
01732                 }
01733             }
01734         }
01735             // 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...
01736         if (!$this->ext_dontCheckIssetValues && is_array($check)) {
01737             foreach ($check as $key => $var) {
01738                 if (isset($theConstants[$key])) {
01739                     $dValue = $theConstants[$key]['default_value'];
01740                     $this->ext_putValueInConf($key, $dValue);
01741                 }
01742             }
01743         }
01744     }
01745 
01746     /**
01747      * [Describe function...]
01748      *
01749      * @param   [type]      $typeDat: ...
01750      * @param   [type]      $tplRow: ...
01751      * @param   [type]      $theRealFileName: ...
01752      * @param   [type]      $tmp_name: ...
01753      * @return  [type]      ...
01754      */
01755     function upload_copy_file($typeDat, &$tplRow, $theRealFileName, $tmp_name) {
01756 
01757             // extensions
01758         $extList = $typeDat['paramstr'];
01759         if ($extList == 'IMAGE_EXT') {
01760             $extList = $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'];
01761         }
01762         $fI = t3lib_div::split_fileref($theRealFileName);
01763         if ($theRealFileName && (!$extList || t3lib_div::inList($extList, $fI['fileext']))) {
01764             $tmp_upload_name = t3lib_div::upload_to_tempfile($tmp_name); // If there is an uploaded file, move it for the sake of safe_mode.
01765 
01766                 // Saving resource
01767             $alternativeFileName = array();
01768             $alternativeFileName[$tmp_upload_name] = $theRealFileName;
01769                 // Making list of resources
01770             $resList = $tplRow['resources'];
01771             $resList = $tmp_upload_name . ',' . $resList;
01772             $resList = implode(t3lib_div::trimExplode(',', $resList, 1), ',');
01773                 // Making data-array
01774             $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
01775 
01776             $recData = array();
01777             $recData['sys_template'][$saveId]['resources'] = $resList;
01778                 // Saving
01779             $tce = t3lib_div::makeInstance('t3lib_TCEmain');
01780             $tce->stripslashes_values = 0;
01781             $tce->alternativeFileName = $alternativeFileName;
01782             $tce->start($recData, Array());
01783             $tce->process_datamap();
01784 
01785             t3lib_div::unlink_tempfile($tmp_upload_name);
01786 
01787             $tmpRow = t3lib_BEfunc::getRecordWSOL('sys_template', $saveId, 'resources');
01788 
01789             $tplRow['resources'] = $tmpRow['resources'];
01790 
01791                 // Setting the value
01792             $var = $this->ext_setStar($theRealFileName);
01793         }
01794         return $var;
01795     }
01796 
01797     /**
01798      * [Describe function...]
01799      *
01800      * @param   [type]      $id: ...
01801      * @param   [type]      $perms_clause: ...
01802      * @return  [type]      ...
01803      */
01804     function ext_prevPageWithTemplate($id, $perms_clause) {
01805         $rootLine = t3lib_BEfunc::BEgetRootLine($id, $perms_clause ? ' AND ' . $perms_clause : '');
01806         foreach ($rootLine as $p) {
01807             if ($this->ext_getFirstTemplate($p['uid'])) {
01808                 return $p;
01809             }
01810         }
01811     }
01812 
01813     /**
01814      * [Describe function...]
01815      *
01816      * @param   [type]      $val: ...
01817      * @return  [type]      ...
01818      */
01819     function ext_setStar($val) {
01820         $fParts = explode('.', strrev($val), 2);
01821         $val = preg_replace('/_[0-9][0-9]$/', '', strrev($fParts[1])) . '*.' . strrev($fParts[0]);
01822         return $val;
01823     }
01824 
01825     /**
01826      * [Describe function...]
01827      *
01828      * @param   [type]      $value: ...
01829      * @return  [type]      ...
01830      */
01831     function ext_detectAndFixExtensionPrefix($value) {
01832         if (substr($value, 0, 4) == 'EXT:') {
01833             $parts = explode('/', substr($value, 4), 2);
01834 
01835             $extPath = t3lib_extMgm::siteRelPath($parts[0]);
01836             $value = $extPath . $parts[1];
01837             return $value;
01838         } else {
01839             return $value;
01840         }
01841     }
01842 }
01843 
01844 
01845 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php'])) {
01846     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php']);
01847 }
01848 
01849 ?>