Documentation TYPO3 par Ameos

class.t3lib_arraybrowser.php

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


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