Documentation TYPO3 par Ameos

class.t3lib_arraybrowser.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00077 class t3lib_arrayBrowser        {
00078         var $expAll = FALSE;                    // If set, will expand all (depthKeys is obsolete then) (and no links are applied)
00079         var $dontLinkVar = FALSE;               // If set, the variable keys are not linked.
00080         var $depthKeys = array();               // Array defining which keys to expand. Typically set from outside from some session variable - otherwise the array will collapse.
00081         var $searchKeys = array();              // After calling the getSearchKeys function this array is populated with the key-positions in the array which contains values matching the search.
00082         var $fixedLgd=1;                                // If set, the values are truncated with "..." appended if longer than a certain length.
00083         var $regexMode=0;                               // If set, search for string with regex, otherwise stristr()
00084         var $varName='';                                // Set var name here if you want links to the variable name.
00085 
00096         function tree($arr, $depth_in, $depthData)      {
00097                 $HTML='';
00098                 $a=0;
00099 
00100                 if ($depth_in)  {$depth_in = $depth_in.'.';}
00101 
00102                 $c=count($arr);
00103                 reset($arr);
00104                 while (list($key,)=each($arr))  {
00105                         $a++;
00106                         $depth = $depth_in.$key;
00107                         $goto = substr(md5($depth),0,6);
00108 
00109                         $deeper = (is_array($arr[$key]) && ($this->depthKeys[$depth] || $this->expAll)) ? 1 : 0;
00110                         $PM = 'join';
00111                         $LN = ($a==$c)?'blank':'line';
00112                         $BTM = ($a==$c)?'bottom':'';
00113                         $PM = is_array($arr[$key]) ? ($deeper ? 'minus':'plus') : 'join';
00114 
00115 
00116                         $HTML.=$depthData;
00117                         $theIcon='<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' align="top" border="0" alt="" />';
00118                         if ($PM=='join')        {
00119                                 $HTML.=$theIcon;
00120                         } else {
00121                                 $HTML.=
00122                                         ($this->expAll ? '' : '<a name="'.$goto.'" href="'.htmlspecialchars('index.php?node['.$depth.']='.($deeper?0:1).'#'.$goto).'">').
00123                                         $theIcon.
00124                                         ($this->expAll ? '' : '</a>');
00125                         }
00126 
00127                         $label = $key;
00128                         $HTML.= $this->wrapArrayKey($label,$depth,!is_array($arr[$key]) ? $arr[$key] : '');
00129 
00130                         if (!is_array($arr[$key]))      {
00131                                 $theValue = $arr[$key];
00132                                 if ($this->fixedLgd)    {
00133                                         $imgBlocks = ceil(1+strlen($depthData)/77);
00134 //                                      debug($imgBlocks);
00135                                         $lgdChars = 68-ceil(strlen('['.$key.']')*0.8)-$imgBlocks*3;
00136                                         $theValue = $this->fixed_lgd($theValue,$lgdChars);
00137                                 }
00138                                 if ($this->searchKeys[$depth])  {
00139                                         $HTML.='=<span style="color:red;">'.$this->wrapValue($theValue,$depth).'</font>';
00140                                 } else {
00141                                         $HTML.='='.$this->wrapValue($theValue,$depth);
00142                                 }
00143                         }
00144                         $HTML.='<br />';
00145 
00146                         if ($deeper)    {
00147                                 $HTML.=$this->tree($arr[$key], $depth, $depthData.'<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/ol/'.$LN.'.gif','width="18" height="16"').' align="top" alt="" />');
00148                         }
00149                 }
00150                 return $HTML;
00151         }
00152 
00160         function wrapValue($theValue,$depth)    {
00161                 return '<b>'.htmlspecialchars($theValue).'</b>';
00162         }
00163 
00172         function wrapArrayKey($label,$depth,$theValue)  {
00173 
00174                         // Protect label:
00175                 $label = htmlspecialchars($label);
00176 
00177                         // If varname is set:
00178                 if ($this->varName && !$this->dontLinkVar) {
00179                         $variableName = $this->varName.'[\''.str_replace('.','\'][\'',$depth).'\'] = '.(!t3lib_div::testInt($theValue) ? '\''.addslashes($theValue).'\'' : $theValue).'; ';
00180                         $label = '<a href="'.htmlspecialchars('index.php?varname='.$variableName.'#varname').'">'.$label.'</a>';
00181                 }
00182 
00183                         // Return:
00184                 return '['.$label.']';
00185         }
00186 
00196         function getSearchKeys($keyArr, $depth_in, $searchString, $keyArray)            {
00197                 reset($keyArr);
00198                 $c=count($keyArr);
00199                 if ($depth_in)  {$depth_in = $depth_in.'.';}
00200                 while (list($key,)=each($keyArr))       {
00201                         $depth=$depth_in.$key;
00202                         $deeper = is_array($keyArr[$key]);
00203 
00204                         if ($this->regexMode)   {
00205                                 if (ereg($searchString,$keyArr[$key]))  {       $this->searchKeys[$depth]=1;    }
00206                         } else {
00207                                 if (stristr($keyArr[$key],$searchString))       {       $this->searchKeys[$depth]=1;    }
00208                         }
00209 
00210                         if ($deeper)    {
00211                                 $cS = count($this->searchKeys);
00212                                 $keyArray = $this->getSearchKeys($keyArr[$key], $depth, $searchString, $keyArray);
00213                                 if ($cS != count($this->searchKeys))    {
00214                                         $keyArray[$depth]=1;
00215                                 }
00216                         }
00217                 }
00218                 return $keyArray;
00219         }
00220 
00228         function fixed_lgd($string,$chars)      {
00229                 if ($chars >= 4)        {
00230                         if(strlen($string)>$chars)  {
00231                                 return substr($string, 0, $chars-3).'...';
00232                         }
00233                 }
00234                 return $string;
00235         }
00236 
00245         function depthKeys($arr,$settings)      {
00246                 $tsbrArray=array();
00247                 reset($arr);
00248                 while(list($theK,$theV)=each($arr))     {
00249                         $theKeyParts = explode('.',$theK);
00250                         $depth='';
00251                         $c=count($theKeyParts);
00252                         $a=0;
00253                         while(list(,$p)=each($theKeyParts))     {
00254                                 $a++;
00255                                 $depth.=($depth?'.':'').$p;
00256                                 $tsbrArray[$depth]= ($c==$a) ? $theV : 1;
00257                         }
00258                 }
00259                         // Modify settings
00260                 reset($tsbrArray);
00261                 while(list($theK,$theV)=each($tsbrArray))       {
00262                         if ($theV)      {
00263                                 $settings[$theK] = 1;
00264                         } else {
00265                                 unset($settings[$theK]);
00266                         }
00267                 }
00268                 return $settings;
00269         }
00270 }
00271 
00272 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_arraybrowser.php'])      {
00273         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_arraybrowser.php']);
00274 }
00275 ?>


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