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 $depthKeys = array();
00079 var $searchKeys = array();
00080 var $fixedLgd=1;
00081 var $regexMode=0;
00082 var $varName='';
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
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
00170 $label = htmlspecialchars($label);
00171
00172
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
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
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 ?>