2 /***************************************************************
5 * (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Class for displaying an array as a tree
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
34 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
37 * [CLASS/FUNCTION INDEX of SCRIPT]
41 * 77: class t3lib_arrayBrowser
42 * 96: function tree($arr, $depth_in, $depthData)
43 * 160: function wrapValue($theValue,$depth)
44 * 172: function wrapArrayKey($label,$depth,$theValue)
45 * 196: function getSearchKeys($keyArr, $depth_in, $searchString, $keyArray)
46 * 228: function fixed_lgd($string,$chars)
47 * 245: function depthKeys($arr,$settings)
50 * (This index is automatically created/updated by the extension "extdeveval")
69 * Class for displaying an array as a tree
70 * See the extension 'lowlevel' /config (Backend module 'Tools > Configuration')
72 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
75 * @see SC_mod_tools_config_index::main()
77 class t3lib_arrayBrowser
{
78 var $expAll = FALSE
; // If set, will expand all (depthKeys is obsolete then) (and no links are applied)
79 var $dontLinkVar = FALSE
; // If set, the variable keys are not linked.
80 var $depthKeys = array(); // Array defining which keys to expand. Typically set from outside from some session variable - otherwise the array will collapse.
81 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.
82 var $fixedLgd=1; // If set, the values are truncated with "..." appended if longer than a certain length.
83 var $regexMode=0; // If set, search for string with regex, otherwise stristr()
84 var $searchKeysToo=FALSE
; // If set, array keys are subject to the search too.
85 var $varName=''; // Set var name here if you want links to the variable name.
89 * 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()
91 * @param array The array to display
92 * @param string Key-position id. Build up during recursive calls - [key1].[key2].[key3] - an so on.
93 * @param string Depth-data - basically a prefix for the icons. For calling this function from outside, let it stay blank.
94 * @return string HTML for the tree
95 * @see SC_mod_tools_config_index::main()
97 function tree($arr, $depth_in, $depthData) {
101 if ($depth_in) {$depth_in = $depth_in.'.';}
105 while (list($key,)=each($arr)) {
107 $depth = $depth_in.$key;
108 $goto = substr(md5($depth),0,6);
110 $deeper = (is_array($arr[$key]) && ($this->depthKeys
[$depth] ||
$this->expAll
)) ?
1 : 0;
112 $LN = ($a==$c)?
'blank':'line';
113 $BTM = ($a==$c)?
'bottom':'';
114 $PM = is_array($arr[$key]) ?
($deeper ?
'minus':'plus') : 'join';
118 $theIcon='<img'.t3lib_iconWorks
::skinImg($GLOBALS['BACK_PATH'],'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' align="top" border="0" alt="" />';
123 ($this->expAll ?
'' : '<a name="'.$goto.'" href="'.htmlspecialchars('index.php?node['.$depth.']='.($deeper?
0:1).'#'.$goto).'">').
125 ($this->expAll ?
'' : '</a>');
129 $HTML.= $this->wrapArrayKey($label,$depth,!is_array($arr[$key]) ?
$arr[$key] : '');
131 if (!is_array($arr[$key])) {
132 $theValue = $arr[$key];
133 if ($this->fixedLgd
) {
134 $imgBlocks = ceil(1+
strlen($depthData)/77);
135 // debug($imgBlocks);
136 $lgdChars = 68-ceil(strlen('['.$key.']')*0.8)-$imgBlocks*3;
137 $theValue = $this->fixed_lgd($theValue,$lgdChars);
139 if ($this->searchKeys
[$depth]) {
140 $HTML.='=<span style="color:red;">'.$this->wrapValue($theValue,$depth).'</span>';
142 $HTML.='='.$this->wrapValue($theValue,$depth);
148 $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="" />');
155 * Wrapping the value in bold tags etc.
157 * @param string The title string
158 * @param string Depth path
159 * @return string Title string, htmlspecialchars()'ed
161 function wrapValue($theValue,$depth) {
162 return '<b>'.htmlspecialchars($theValue).'</b>';
166 * Wrapping the value in bold tags etc.
168 * @param string The title string
169 * @param string Depth path
170 * @param string The value for the array entry.
171 * @return string Title string, htmlspecialchars()'ed
173 function wrapArrayKey($label,$depth,$theValue) {
176 $label = htmlspecialchars($label);
178 // If varname is set:
179 if ($this->varName
&& !$this->dontLinkVar
) {
180 $variableName = $this->varName
.'[\''.str_replace('.','\'][\'',$depth).'\'] = '.(!t3lib_div
::testInt($theValue) ?
'\''.addslashes($theValue).'\'' : $theValue).'; ';
181 $label = '<a href="'.htmlspecialchars('index.php?varname='.$variableName.'#varname').'">'.$label.'</a>';
185 return '['.$label.']';
189 * Creates an array with "depthKeys" which will expand the array to show the search results
191 * @param array The array to search for the value
192 * @param string Depth string - blank for first call (will build up during recursive calling creating an id of the position: [key1].[key2].[key3]
193 * @param string The string to search for
194 * @param array Key array, for first call pass empty array
197 function getSearchKeys($keyArr, $depth_in, $searchString, $keyArray) {
200 if ($depth_in) {$depth_in = $depth_in.'.';}
201 while (list($key,)=each($keyArr)) {
202 $depth=$depth_in.$key;
203 $deeper = is_array($keyArr[$key]);
205 if ($this->regexMode
) {
206 if (ereg($searchString,$keyArr[$key]) ||
($this->searchKeysToo
&& ereg($searchString,$key))) { $this->searchKeys
[$depth]=1; }
208 if (stristr($keyArr[$key],$searchString) ||
($this->searchKeysToo
&& stristr($key,$searchString))) { $this->searchKeys
[$depth]=1; }
212 $cS = count($this->searchKeys
);
213 $keyArray = $this->getSearchKeys($keyArr[$key], $depth, $searchString, $keyArray);
214 if ($cS != count($this->searchKeys
)) {
223 * Fixed length function
225 * @param string String to process
226 * @param integer Max number of chars
227 * @return string Processed string
229 function fixed_lgd($string,$chars) {
231 if(strlen($string)>$chars) {
232 return substr($string, 0, $chars-3).'...';
239 * Function modifying the depthKey array
241 * @param array Array with instructions to open/close nodes.
242 * @param array Input depth_key array
243 * @return array Output depth_key array with entries added/removed based on $arr
244 * @see SC_mod_tools_config_index::main()
246 function depthKeys($arr,$settings) {
249 while(list($theK,$theV)=each($arr)) {
250 $theKeyParts = explode('.',$theK);
252 $c=count($theKeyParts);
254 while(list(,$p)=each($theKeyParts)) {
256 $depth.=($depth?
'.':'').$p;
257 $tsbrArray[$depth]= ($c==$a) ?
$theV : 1;
262 while(list($theK,$theV)=each($tsbrArray)) {
264 $settings[$theK] = 1;
266 unset($settings[$theK]);
273 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_arraybrowser.php']) {
274 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_arraybrowser.php']);