1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
|
<?php
/***************************************************************
* Copyright notice
*
* (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Class for displaying an array as a tree
*
* $Id: class.t3lib_arraybrowser.php 1421 2006-04-10 09:27:15Z mundaun $
* Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
* XHTML compliant
*
* @author Kasper Skaarhoj <kasperYYYY@typo3.com>
*/
/**
* [CLASS/FUNCTION INDEX of SCRIPT]
*
*
*
* 77: class t3lib_arrayBrowser
* 96: function tree($arr, $depth_in, $depthData)
* 160: function wrapValue($theValue,$depth)
* 172: function wrapArrayKey($label,$depth,$theValue)
* 196: function getSearchKeys($keyArr, $depth_in, $searchString, $keyArray)
* 228: function fixed_lgd($string,$chars)
* 245: function depthKeys($arr,$settings)
*
* TOTAL FUNCTIONS: 6
* (This index is automatically created/updated by the extension "extdeveval")
*
*/
/**
* Class for displaying an array as a tree
* See the extension 'lowlevel' /config (Backend module 'Tools > Configuration')
*
* @author Kasper Skaarhoj <kasperYYYY@typo3.com>
* @package TYPO3
* @subpackage t3lib
* @see SC_mod_tools_config_index::main()
*/
class t3lib_arrayBrowser {
var $expAll = FALSE; // If set, will expand all (depthKeys is obsolete then) (and no links are applied)
var $dontLinkVar = FALSE; // If set, the variable keys are not linked.
var $depthKeys = array(); // Array defining which keys to expand. Typically set from outside from some session variable - otherwise the array will collapse.
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.
var $fixedLgd=1; // If set, the values are truncated with "..." appended if longer than a certain length.
var $regexMode=0; // If set, search for string with regex, otherwise stristr()
var $varName=''; // Set var name here if you want links to the variable name.
/**
* Make browsable tree
* Before calling this function you may want to set some of the internal vars like depthKeys, regexMode and fixedLgd. For examples see SC_mod_tools_config_index::main()
*
* @param array The array to display
* @param string Key-position id. Build up during recursive calls - [key1].[key2].[key3] - an so on.
* @param string Depth-data - basically a prefix for the icons. For calling this function from outside, let it stay blank.
* @return string HTML for the tree
* @see SC_mod_tools_config_index::main()
*/
function tree($arr, $depth_in, $depthData) {
$HTML='';
$a=0;
if ($depth_in) {$depth_in = $depth_in.'.';}
$c=count($arr);
reset($arr);
while (list($key,)=each($arr)) {
$a++;
$depth = $depth_in.$key;
$goto = substr(md5($depth),0,6);
$deeper = (is_array($arr[$key]) && ($this->depthKeys[$depth] || $this->expAll)) ? 1 : 0;
$PM = 'join';
$LN = ($a==$c)?'blank':'line';
$BTM = ($a==$c)?'bottom':'';
$PM = is_array($arr[$key]) ? ($deeper ? 'minus':'plus') : 'join';
$HTML.=$depthData;
$theIcon='<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' align="top" border="0" alt="" />';
if ($PM=='join') {
$HTML.=$theIcon;
} else {
$HTML.=
($this->expAll ? '' : '<a name="'.$goto.'" href="'.htmlspecialchars('index.php?node['.$depth.']='.($deeper?0:1).'#'.$goto).'">').
$theIcon.
($this->expAll ? '' : '</a>');
}
$label = $key;
$HTML.= $this->wrapArrayKey($label,$depth,!is_array($arr[$key]) ? $arr[$key] : '');
if (!is_array($arr[$key])) {
$theValue = $arr[$key];
if ($this->fixedLgd) {
$imgBlocks = ceil(1+strlen($depthData)/77);
// debug($imgBlocks);
$lgdChars = 68-ceil(strlen('['.$key.']')*0.8)-$imgBlocks*3;
$theValue = $this->fixed_lgd($theValue,$lgdChars);
}
if ($this->searchKeys[$depth]) {
$HTML.='=<span style="color:red;">'.$this->wrapValue($theValue,$depth).'</font>';
} else {
$HTML.='='.$this->wrapValue($theValue,$depth);
}
}
$HTML.='<br />';
if ($deeper) {
$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="" />');
}
}
return $HTML;
}
/**
* Wrapping the value in bold tags etc.
*
* @param string The title string
* @param string Depth path
* @return string Title string, htmlspecialchars()'ed
*/
function wrapValue($theValue,$depth) {
return '<b>'.htmlspecialchars($theValue).'</b>';
}
/**
* Wrapping the value in bold tags etc.
*
* @param string The title string
* @param string Depth path
* @param string The value for the array entry.
* @return string Title string, htmlspecialchars()'ed
*/
function wrapArrayKey($label,$depth,$theValue) {
// Protect label:
$label = htmlspecialchars($label);
// If varname is set:
if ($this->varName && !$this->dontLinkVar) {
$variableName = $this->varName.'[\''.str_replace('.','\'][\'',$depth).'\'] = '.(!t3lib_div::testInt($theValue) ? '\''.addslashes($theValue).'\'' : $theValue).'; ';
$label = '<a href="'.htmlspecialchars('index.php?varname='.$variableName.'#varname').'">'.$label.'</a>';
}
// Return:
return '['.$label.']';
}
/**
* Creates an array with "depthKeys" which will expand the array to show the search results
*
* @param array The array to search for the value
* @param string Depth string - blank for first call (will build up during recursive calling creating an id of the position: [key1].[key2].[key3]
* @param string The string to search for
* @param array Key array, for first call pass empty array
* @return array
*/
function getSearchKeys($keyArr, $depth_in, $searchString, $keyArray) {
reset($keyArr);
$c=count($keyArr);
if ($depth_in) {$depth_in = $depth_in.'.';}
while (list($key,)=each($keyArr)) {
$depth=$depth_in.$key;
$deeper = is_array($keyArr[$key]);
if ($this->regexMode) {
if (ereg($searchString,$keyArr[$key])) { $this->searchKeys[$depth]=1; }
} else {
if (stristr($keyArr[$key],$searchString)) { $this->searchKeys[$depth]=1; }
}
if ($deeper) {
$cS = count($this->searchKeys);
$keyArray = $this->getSearchKeys($keyArr[$key], $depth, $searchString, $keyArray);
if ($cS != count($this->searchKeys)) {
$keyArray[$depth]=1;
}
}
}
return $keyArray;
}
/**
* Fixed length function
*
* @param string String to process
* @param integer Max number of chars
* @return string Processed string
*/
function fixed_lgd($string,$chars) {
if ($chars >= 4) {
if(strlen($string)>$chars) {
return substr($string, 0, $chars-3).'...';
}
}
return $string;
}
/**
* Function modifying the depthKey array
*
* @param array Array with instructions to open/close nodes.
* @param array Input depth_key array
* @return array Output depth_key array with entries added/removed based on $arr
* @see SC_mod_tools_config_index::main()
*/
function depthKeys($arr,$settings) {
$tsbrArray=array();
reset($arr);
while(list($theK,$theV)=each($arr)) {
$theKeyParts = explode('.',$theK);
$depth='';
$c=count($theKeyParts);
$a=0;
while(list(,$p)=each($theKeyParts)) {
$a++;
$depth.=($depth?'.':'').$p;
$tsbrArray[$depth]= ($c==$a) ? $theV : 1;
}
}
// Modify settings
reset($tsbrArray);
while(list($theK,$theV)=each($tsbrArray)) {
if ($theV) {
$settings[$theK] = 1;
} else {
unset($settings[$theK]);
}
}
return $settings;
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_arraybrowser.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_arraybrowser.php']);
}
?>
|