00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00077 class t3lib_arrayBrowser {
00078 var $expAll = FALSE;
00079 var $dontLinkVar = FALSE;
00080 var $depthKeys = array();
00081 var $searchKeys = array();
00082 var $fixedLgd=1;
00083 var $regexMode=0;
00084 var $varName='';
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
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
00175 $label = htmlspecialchars($label);
00176
00177
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
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
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 ?>