2 /***************************************************************
5 * (c) 1999-2006 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 * Page navigation tree for the Web module
30 * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
33 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
34 * @author Benjamin Mack <bmack@xnos.org>
37 * [CLASS/FUNCTION INDEX of SCRIPT]
41 * 71: class webPageTree extends t3lib_browseTree
42 * 81: function webPageTree()
43 * 92: function wrapIcon($icon,&$row)
44 * 130: function wrapStop($str,$row)
45 * 146: function wrapTitle($title,$row,$bank=0)
46 * 165: function printTree($treeArr = '')
47 * 271: function PMicon($row,$a,$c,$nextCount,$exp)
48 * 292: function PMiconATagWrap($icon, $cmd, $isExpand = true)
49 * 309: function getBrowsableTree()
50 * 377: function getTree($uid, $depth=999, $depthData='',$blankLineCode='',$subCSSclass='')
54 * (This index is automatically created/updated by the extension "extdeveval")
59 require_once(PATH_t3lib
.'class.t3lib_browsetree.php');
63 * Extension class for the t3lib_browsetree class, specially made
64 * for browsing pages in the Web module
66 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
67 * @author Benjamin Mack <bmack@xnos.org>
70 * @see class t3lib_browseTree
72 class webPageTree
extends t3lib_browseTree
{
76 var $ajaxStatus = false
; // Indicates, whether the ajax call was successful, i.e. the requested page has been found
79 * Calls init functions
83 function webPageTree() {
88 * Wrapping icon in browse tree
90 * @param string Icon IMG code
91 * @param array Data row for element.
92 * @return string Page icon
94 function wrapIcon($icon,&$row) {
95 // If the record is locked, present a warning sign.
96 if ($lockInfo=t3lib_BEfunc
::isRecordLocked('pages',$row['uid'])) {
97 $aOnClick = 'alert('.$GLOBALS['LANG']->JScharCode($lockInfo['msg']).');return false;';
98 $lockIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
99 '<img'.t3lib_iconWorks
::skinImg('','gfx/recordlock_warning3.gif','width="17" height="12"').' title="'.htmlspecialchars($lockInfo['msg']).'" alt="" />'.
101 } else $lockIcon = '';
103 // Add title attribute to input icon tag
104 $thePageIcon = $this->addTagAttributes($icon, $this->titleAttrib
.'="'.$this->getTitleAttrib($row).'"');
106 // Wrap icon in click-menu link.
107 if (!$this->ext_IconMode
) {
108 $thePageIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($thePageIcon,'pages',$row['uid'],0,'&bank='.$this->bank
);
109 } elseif (!strcmp($this->ext_IconMode
,'titlelink')) {
110 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->treeName
.'\');';
111 $thePageIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$thePageIcon.'</a>';
114 // Wrap icon in a drag/drop span.
115 $dragDropIcon = '<span class="dragIcon" id="dragIconID_'.$row['uid'].'">'.$thePageIcon.'</span>';
119 if ($this->ext_showPageId
) { $pageIdStr = '['.$row['uid'].'] '; }
121 return $dragDropIcon.$lockIcon.$pageIdStr;
125 * Adds a red "+" to the input string, $str, if the field "php_tree_stop" in the $row (pages) is set
127 * @param string Input string, like a page title for the tree
128 * @param array record row with "php_tree_stop" field
129 * @return string Modified string
132 function wrapStop($str,$row) {
133 if ($row['php_tree_stop']) {
134 $str.='<a href="'.htmlspecialchars(t3lib_div
::linkThisScript(array('setTempDBmount' => $row['uid']))).'" class="typo3-red">+</a> ';
140 * Wrapping $title in a-tags.
142 * @param string Title string
143 * @param string Item record
144 * @param integer Bank pointer (which mount point number)
148 function wrapTitle($title,$row,$bank=0) {
149 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix
.$this->getId($row).'\','.$bank.');';
151 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler']) {
152 $CSM = ' oncontextmenu="'.htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('','pages',$row['uid'],0,'&bank='.$this->bank
,'',TRUE
)).';"';
154 $thePageTitle='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"'.$CSM.'>'.$title.'</a>';
156 // Wrap title in a drag/drop span.
157 return '<span class="dragTitle" id="dragTitleID_'.$row['uid'].'">'.$thePageTitle.'</span>';
162 * Compiles the HTML code for displaying the structure found inside the ->tree array
164 * @param array "tree-array" - if blank string, the internal ->tree array is used.
165 * @return string The HTML code for the tree
167 function printTree($treeArr = '') {
168 $titleLen = intval($this->BE_USER
->uc
['titleLen']);
169 if (!is_array($treeArr)) $treeArr = $this->tree
;
172 <!-- TYPO3 tree structure. -->
176 // -- evaluate AJAX request
177 // IE takes anchor as parameter
178 $PM = t3lib_div
::_GP('PM');
179 if(($PMpos = strpos($PM, '#')) !== false
) { $PM = substr($PM, 0, $PMpos); }
180 $PM = explode('_', $PM);
181 if(($isAjaxCall = t3lib_div
::_GP('ajax')) && is_array($PM) && count($PM)==4) {
183 $expandedPageUid = $PM[2];
185 $invertedDepthOfAjaxRequestedItem = 0; // We don't know yet. Will be set later.
188 $collapsedPageUid = $PM[2];
193 // we need to count the opened <ul>'s every time we dig into another level,
194 // so we know how many we have to close when all children are done rendering
195 $closeDepth = array();
197 foreach($treeArr as $k => $v) {
198 $classAttr = $v['row']['_CSSCLASS'];
199 $uid = $v['row']['uid'];
200 $idAttr = htmlspecialchars($this->domIdPrefix
.$this->getId($v['row']).'_'.$v['bank']);
203 // if this item is the start of a new level,
204 // then a new level <ul> is needed, but not in ajax mode
205 if($v['isFirst'] && !($doCollapse) && !($doExpand && $expandedPageUid == $uid)) {
209 // add CSS classes to the list item
210 if($v['hasSub']) { $classAttr .= ($classAttr) ?
' expanded': 'expanded'; }
211 if($v['isLast']) { $classAttr .= ($classAttr) ?
' last' : 'last'; }
214 <li id="'.$idAttr.'"'.($classAttr ?
' class="'.$classAttr.'"' : '').'>'.
216 $this->wrapTitle($this->getTitleStr($v['row'],$titleLen),$v['row'],$v['bank'])."\n";
219 if(!$v['hasSub']) { $itemHTML .= '</li>'; }
221 // we have to remember if this is the last one
222 // on level X so the last child on level X+1 closes the <ul>-tag
223 if($v['isLast'] && !($doExpand && $expandedPageUid == $uid)) { $closeDepth[$v['invertedDepth']] = 1; }
226 // if this is the last one and does not have subitems, we need to close
227 // the tree as long as the upper levels have last items too
228 if($v['isLast'] && !$v['hasSub'] && !$doCollapse && !($doExpand && $expandedPageUid == $uid)) {
229 for ($i = $v['invertedDepth']; $closeDepth[$i] == 1; $i++
) {
231 $itemHTML .= '</ul></li>';
235 // ajax request: collapse
236 if($doCollapse && $collapsedPageUid == $uid) {
237 $this->ajaxStatus
= true
;
241 // ajax request: expand
242 if($doExpand && $expandedPageUid == $uid) {
243 $ajaxOutput .= $itemHTML;
244 $invertedDepthOfAjaxRequestedItem = $v['invertedDepth'];
245 } elseif($invertedDepthOfAjaxRequestedItem) {
246 if($v['invertedDepth'] < $invertedDepthOfAjaxRequestedItem) {
247 $ajaxOutput .= $itemHTML;
249 $this->ajaxStatus
= true
;
258 $this->ajaxStatus
= true
;
262 // finally close the first ul
269 * Generate the plus/minus icon for the browsable tree.
271 * @param array record for the entry
272 * @param integer The current entry number
273 * @param integer The total number of entries. If equal to $a, a "bottom" element is returned.
274 * @param integer The number of sub-elements to the current element.
275 * @param boolean The element was expanded to render subelements if this flag is set.
276 * @return string Image tag with the plus/minus icon.
278 * @see t3lib_pageTree::PMicon()
280 function PMicon($row,$a,$c,$nextCount,$exp) {
281 $PM = $nextCount ?
($exp ?
'minus' : 'plus') : 'join';
282 $BTM = ($a == $c) ?
'bottom' : '';
283 $icon = '<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' alt="" />';
286 $cmd = $this->bank
.'_'.($exp?
'0_':'1_').$row['uid'].'_'.$this->treeName
;
287 $icon = $this->PMiconATagWrap($icon,$cmd,!$exp);
294 * Wrap the plus/minus icon in a link
296 * @param string HTML string to wrap, probably an image tag.
297 * @param string Command for 'PM' get var
298 * @return string Link-wrapped input string
301 function PMiconATagWrap($icon, $cmd, $isExpand = true
) {
302 if ($this->thisScript
) {
303 // activate dynamic ajax-based tree
304 $js = htmlspecialchars('Tree.load(\''.$cmd.'\', '.intval($isExpand).', this);');
305 return '<a class="pm" onclick="'.$js.'">'.$icon.'</a>';
313 * Will create and return the HTML code for a browsable tree
314 * Is based on the mounts found in the internal array ->MOUNTS (set in the constructor)
316 * @return string HTML code for the browsable tree
318 function getBrowsableTree() {
320 // Get stored tree structure AND updating it if needed according to incoming PM GET var.
321 $this->initializePositionSaving();
324 $titleLen = intval($this->BE_USER
->uc
['titleLen']);
328 foreach($this->MOUNTS
as $idx => $uid) {
332 $isOpen = $this->stored
[$idx][$uid] ||
$this->expandFirst
;
334 // Save ids while resetting everything else.
335 $curIds = $this->ids
;
337 $this->ids
= $curIds;
339 // Set PM icon for root of mount:
340 $cmd = $this->bank
.'_'.($isOpen?
"0_" : "1_").$uid.'_'.$this->treeName
;
341 $icon='<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.($isOpen?
'minus':'plus').'only.gif').' alt="" />';
342 $firstHtml = $this->PMiconATagWrap($icon,$cmd);
344 // Preparing rootRec for the mount
346 $rootRec = $this->getRecord($uid);
347 $firstHtml.=$this->getIcon($rootRec);
349 // Artificial record for the tree root, id=0
350 $rootRec = $this->getRootRecord($uid);
351 $firstHtml.=$this->getRootIcon($rootRec);
354 if (is_array($rootRec)) {
355 // In case it was swapped inside getRecord due to workspaces.
356 $uid = $rootRec['uid'];
358 // Add the root of the mount to ->tree
359 $this->tree
[] = array('HTML'=>$firstHtml, 'row'=>$rootRec, 'bank'=>$this->bank
, 'hasSub'=>true
, 'invertedDepth'=>1000);
361 // If the mount is expanded, go down:
364 if ($this->addSelfId
) { $this->ids
[] = $uid; }
365 $this->getTree($uid, 999, '', $rootRec['_SUBCSSCLASS']);
368 $treeArr=array_merge($treeArr,$this->tree
);
371 return $this->printTree($treeArr);
376 * Fetches the data for the tree
378 * @param integer item id for which to select subitems (parent id)
379 * @param integer Max depth (recursivity limit)
380 * @param string ? (internal)
381 * @return integer The count of items on the level
383 function getTree($uid, $depth=999, $blankLineCode='', $subCSSclass='') {
385 // Buffer for id hierarchy is reset:
386 $this->buffer_idH
= array();
389 $depth = intval($depth);
393 $res = $this->getDataInit($uid, $subCSSclass);
394 $c = $this->getDataCount($res);
395 $crazyRecursionLimiter = 999;
397 // Traverse the records:
398 while ($crazyRecursionLimiter > 0 && $row = $this->getDataNext($res,$subCSSclass)) {
400 $crazyRecursionLimiter--;
402 $newID = $row['uid'];
403 $this->tree
[]=array(); // Reserve space.
405 $treeKey = key($this->tree
); // Get the key for this space
406 $LN = ($a==$c) ?
'blank' : 'line';
408 // If records should be accumulated, do so
409 if ($this->setRecs
) { $this->recs
[$row['uid']] = $row; }
411 // Accumulate the id of the element in the internal arrays
412 $this->ids
[]=$idH[$row['uid']]['uid'] = $row['uid'];
413 $this->ids_hierarchy
[$depth][] = $row['uid'];
415 // Make a recursive call to the next level
416 if ($depth > 1 && $this->expandNext($newID) && !$row['php_tree_stop']) {
417 $nextCount=$this->getTree(
420 $blankLineCode.','.$LN,
423 if (count($this->buffer_idH
)) { $idH[$row['uid']]['subrow']=$this->buffer_idH
; }
424 $exp = 1; // Set "did expand" flag
426 $nextCount = $this->getCount($newID);
427 $exp = 0; // Clear "did expand" flag
430 // Set HTML-icons, if any:
431 if ($this->makeHTML
) {
432 $HTML = $this->PMicon($row,$a,$c,$nextCount,$exp);
433 $HTML.= $this->wrapStop($this->getIcon($row),$row);
436 // Finally, add the row/HTML content to the ->tree array in the reserved key.
437 $this->tree
[$treeKey] = array(
440 'hasSub' => $nextCount&&$this->expandNext($newID),
443 'invertedDepth'=> $depth,
444 'blankLineCode'=> $blankLineCode,
445 'bank' => $this->bank
449 if($a) { $this->tree
[$treeKey]['isLast'] = true
; }
451 $this->getDataFree($res);
452 $this->buffer_idH
= $idH;
457 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/class.webpagetree.php']) {
458 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/class.webpagetree.php']);