2 /***************************************************************
5 * (c) 1999-2009 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 $ext_separateNotinmenuPages;
77 var $ext_alphasortNotinmenuPages;
78 var $ajaxStatus = false; // Indicates, whether the ajax call was successful, i.e. the requested page has been found
81 * Calls init functions
85 function webPageTree() {
90 * Wrapping icon in browse tree
92 * @param string Icon IMG code
93 * @param array Data row for element.
94 * @return string Page icon
96 function wrapIcon($icon,&$row) {
97 // If the record is locked, present a warning sign.
98 if ($lockInfo=t3lib_BEfunc
::isRecordLocked('pages',$row['uid'])) {
99 $aOnClick = 'alert('.$GLOBALS['LANG']->JScharCode($lockInfo['msg']).');return false;';
100 $lockIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
101 '<img'.t3lib_iconWorks
::skinImg('','gfx/recordlock_warning3.gif','width="17" height="12"').' title="'.htmlspecialchars($lockInfo['msg']).'" alt="" />'.
103 } else $lockIcon = '';
105 // Add title attribute to input icon tag
106 $thePageIcon = $this->addTagAttributes($icon, $this->titleAttrib
.'="'.$this->getTitleAttrib($row).'"');
108 // Wrap icon in click-menu link.
109 if (!$this->ext_IconMode
) {
110 $thePageIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($thePageIcon,'pages',$row['uid'],0,'&bank='.$this->bank
);
111 } elseif (!strcmp($this->ext_IconMode
,'titlelink')) {
112 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->treeName
.'\');';
113 $thePageIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$thePageIcon.'</a>';
116 // Wrap icon in a drag/drop span.
117 $dragDropIcon = '<span class="dragIcon" id="dragIconID_'.$row['uid'].'">'.$thePageIcon.'</span>';
121 if ($this->ext_showPageId
) { $pageIdStr = '['.$row['uid'].'] '; }
123 // Call stats information hook
125 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'])) {
126 $_params = array('pages',$row['uid']);
127 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef) {
128 $stat.=t3lib_div
::callUserFunction($_funcRef,$_params,$this);
132 return $dragDropIcon.$lockIcon.$pageIdStr.$stat;
136 * Adds a red "+" to the input string, $str, if the field "php_tree_stop" in the $row (pages) is set
138 * @param string Input string, like a page title for the tree
139 * @param array record row with "php_tree_stop" field
140 * @return string Modified string
143 function wrapStop($str,$row) {
144 if ($row['php_tree_stop']) {
145 $str.='<a href="'.htmlspecialchars(t3lib_div
::linkThisScript(array('setTempDBmount' => $row['uid']))).'" class="typo3-red">+</a> ';
151 * Wrapping $title in a-tags.
153 * @param string Title string
154 * @param string Item record
155 * @param integer Bank pointer (which mount point number)
159 function wrapTitle($title,$row,$bank=0) {
160 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.webPageTree.php']['pageTitleOverlay'])) {
161 $_params = array('title' => &$title, 'row' => &$row);
162 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.webPageTree.php']['pageTitleOverlay'] as $_funcRef) {
163 t3lib_div
::callUserFunction($_funcRef, $_params, $this);
167 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix
.$this->getId($row).'\','.$bank.');';
169 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler']) {
170 $CSM = ' oncontextmenu="'.htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('','pages',$row['uid'],0,'&bank='.$this->bank
,'',TRUE)).';"';
172 $thePageTitle='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"'.$CSM.'>'.$title.'</a>';
174 // Wrap title in a drag/drop span.
175 return '<span class="dragTitle" id="dragTitleID_'.$row['uid'].'">'.$thePageTitle.'</span>';
180 * Compiles the HTML code for displaying the structure found inside the ->tree array
182 * @param array "tree-array" - if blank string, the internal ->tree array is used.
183 * @return string The HTML code for the tree
185 function printTree($treeArr = '') {
186 $titleLen = intval($this->BE_USER
->uc
['titleLen']);
187 if (!is_array($treeArr)) {
188 $treeArr = $this->tree
;
192 <!-- TYPO3 tree structure. -->
193 <ul class="tree" id="treeRoot">
196 // -- evaluate AJAX request
197 // IE takes anchor as parameter
198 $PM = t3lib_div
::_GP('PM');
199 if(($PMpos = strpos($PM, '#')) !== false) { $PM = substr($PM, 0, $PMpos); }
200 $PM = explode('_', $PM);
201 if((TYPO3_REQUESTTYPE
& TYPO3_REQUESTTYPE_AJAX
) && is_array($PM) && count($PM)==4) {
203 $expandedPageUid = $PM[2];
205 $invertedDepthOfAjaxRequestedItem = 0; // We don't know yet. Will be set later.
208 $collapsedPageUid = $PM[2];
213 // we need to count the opened <ul>'s every time we dig into another level,
214 // so we know how many we have to close when all children are done rendering
215 $closeDepth = array();
217 foreach($treeArr as $k => $v) {
218 $classAttr = $v['row']['_CSSCLASS'];
219 $uid = $v['row']['uid'];
220 $idAttr = htmlspecialchars($this->domIdPrefix
.$this->getId($v['row']).'_'.$v['bank']);
223 // if this item is the start of a new level,
224 // then a new level <ul> is needed, but not in ajax mode
225 if($v['isFirst'] && !($doCollapse) && !($doExpand && $expandedPageUid == $uid)) {
226 $itemHTML = '</div><ul>';
229 // add CSS classes to the list item
230 if($v['hasSub']) { $classAttr .= ($classAttr) ?
' expanded': 'expanded'; }
231 if($v['isLast']) { $classAttr .= ($classAttr) ?
' last' : 'last'; }
234 <li id="'.$idAttr.'"'.($classAttr ?
' class="'.$classAttr.'"' : '').'><div class="treeLinkItem">'.
236 $this->wrapTitle($this->getTitleStr($v['row'],$titleLen),$v['row'],$v['bank'])."\n";
239 if(!$v['hasSub']) { $itemHTML .= '</div></li>'; }
241 // we have to remember if this is the last one
242 // on level X so the last child on level X+1 closes the <ul>-tag
243 if($v['isLast'] && !($doExpand && $expandedPageUid == $uid)) { $closeDepth[$v['invertedDepth']] = 1; }
246 // if this is the last one and does not have subitems, we need to close
247 // the tree as long as the upper levels have last items too
248 if($v['isLast'] && !$v['hasSub'] && !$doCollapse && !($doExpand && $expandedPageUid == $uid)) {
249 for ($i = $v['invertedDepth']; $closeDepth[$i] == 1; $i++
) {
251 $itemHTML .= '</ul></li>';
255 // ajax request: collapse
256 if($doCollapse && $collapsedPageUid == $uid) {
257 $this->ajaxStatus
= true;
261 // ajax request: expand
262 if($doExpand && $expandedPageUid == $uid) {
263 $ajaxOutput .= $itemHTML;
264 $invertedDepthOfAjaxRequestedItem = $v['invertedDepth'];
265 } elseif($invertedDepthOfAjaxRequestedItem) {
266 if($v['invertedDepth'] < $invertedDepthOfAjaxRequestedItem) {
267 $ajaxOutput .= $itemHTML;
269 $this->ajaxStatus
= true;
278 $this->ajaxStatus
= true;
282 // finally close the first ul
289 * Generate the plus/minus icon for the browsable tree.
291 * @param array record for the entry
292 * @param integer The current entry number
293 * @param integer The total number of entries. If equal to $a, a "bottom" element is returned.
294 * @param integer The number of sub-elements to the current element.
295 * @param boolean The element was expanded to render subelements if this flag is set.
296 * @return string Image tag with the plus/minus icon.
298 * @see t3lib_pageTree::PMicon()
300 function PMicon($row,$a,$c,$nextCount,$exp) {
301 $PM = $nextCount ?
($exp ?
'minus' : 'plus') : 'join';
302 $BTM = ($a == $c) ?
'bottom' : '';
303 $icon = '<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' alt="" />';
306 $cmd = $this->bank
.'_'.($exp?
'0_':'1_').$row['uid'].'_'.$this->treeName
;
307 $icon = $this->PMiconATagWrap($icon,$cmd,!$exp);
314 * Wrap the plus/minus icon in a link
316 * @param string HTML string to wrap, probably an image tag.
317 * @param string Command for 'PM' get var
318 * @return string Link-wrapped input string
321 function PMiconATagWrap($icon, $cmd, $isExpand = true) {
322 if ($this->thisScript
) {
323 // activate dynamic ajax-based tree
324 $js = htmlspecialchars('Tree.load(\''.$cmd.'\', '.intval($isExpand).', this);');
325 return '<a class="pm" onclick="'.$js.'">'.$icon.'</a>';
333 * Will create and return the HTML code for a browsable tree
334 * Is based on the mounts found in the internal array ->MOUNTS (set in the constructor)
336 * @return string HTML code for the browsable tree
338 function getBrowsableTree() {
340 // Get stored tree structure AND updating it if needed according to incoming PM GET var.
341 $this->initializePositionSaving();
344 $titleLen = intval($this->BE_USER
->uc
['titleLen']);
348 foreach($this->MOUNTS
as $idx => $uid) {
352 $isOpen = $this->stored
[$idx][$uid] ||
$this->expandFirst
;
354 // Save ids while resetting everything else.
355 $curIds = $this->ids
;
357 $this->ids
= $curIds;
359 // Set PM icon for root of mount:
360 $cmd = $this->bank
.'_'.($isOpen?
"0_" : "1_").$uid.'_'.$this->treeName
;
361 $icon='<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.($isOpen?
'minus':'plus').'only.gif').' alt="" />';
362 $firstHtml = $this->PMiconATagWrap($icon,$cmd,!$isOpen);
364 // Preparing rootRec for the mount
366 $rootRec = $this->getRecord($uid);
367 $firstHtml.=$this->getIcon($rootRec);
369 // Artificial record for the tree root, id=0
370 $rootRec = $this->getRootRecord($uid);
371 $firstHtml.=$this->getRootIcon($rootRec);
374 if (is_array($rootRec)) {
375 // In case it was swapped inside getRecord due to workspaces.
376 $uid = $rootRec['uid'];
378 // Add the root of the mount to ->tree
379 $this->tree
[] = array('HTML'=>$firstHtml, 'row'=>$rootRec, 'bank'=>$this->bank
, 'hasSub'=>true, 'invertedDepth'=>1000);
381 // If the mount is expanded, go down:
384 if ($this->addSelfId
) { $this->ids
[] = $uid; }
385 $this->getTree($uid, 999, '', $rootRec['_SUBCSSCLASS']);
388 $treeArr=array_merge($treeArr,$this->tree
);
391 return $this->printTree($treeArr);
396 * Fetches the data for the tree
398 * @param integer item id for which to select subitems (parent id)
399 * @param integer Max depth (recursivity limit)
400 * @param string ? (internal)
401 * @return integer The count of items on the level
403 function getTree($uid, $depth=999, $blankLineCode='', $subCSSclass='') {
405 // Buffer for id hierarchy is reset:
406 $this->buffer_idH
= array();
409 $depth = intval($depth);
413 $res = $this->getDataInit($uid, $subCSSclass);
414 $c = $this->getDataCount($res);
415 $crazyRecursionLimiter = 999;
417 $inMenuPages = array();
418 $outOfMenuPages = array();
419 $outOfMenuPagesTextIndex = array();
420 while ($crazyRecursionLimiter > 0 && $row = $this->getDataNext($res,$subCSSclass)) {
421 $crazyRecursionLimiter--;
424 // @TODO: RFC #7370: doktype 2&5 are deprecated since TYPO3 4.2-beta1
425 if ($this->ext_separateNotinmenuPages
&& (t3lib_div
::inList('5,6',$row['doktype']) ||
$row['doktype']>=200 ||
$row['nav_hide'])) {
426 $outOfMenuPages[] = $row;
427 $outOfMenuPagesTextIndex[] = ($row['doktype']>=200 ?
'zzz'.$row['doktype'].'_' : '').$row['title'];
429 $inMenuPages[] = $row;
433 $label_shownAlphabetically = "";
434 if (count($outOfMenuPages)) {
435 // Sort out-of-menu pages:
436 $outOfMenuPages_alphabetic = array();
437 if ($this->ext_alphasortNotinmenuPages
) {
438 asort($outOfMenuPagesTextIndex);
439 $label_shownAlphabetically = " (alphabetic)";
441 foreach($outOfMenuPagesTextIndex as $idx => $txt) {
442 $outOfMenuPages_alphabetic[] = $outOfMenuPages[$idx];
446 $outOfMenuPages_alphabetic[0]['_FIRST_NOT_IN_MENU']=TRUE;
447 $allRows = array_merge($inMenuPages,$outOfMenuPages_alphabetic);
449 $allRows = $inMenuPages;
452 // Traverse the records:
453 foreach ($allRows as $row) {
456 $newID = $row['uid'];
457 $this->tree
[]=array(); // Reserve space.
459 $treeKey = key($this->tree
); // Get the key for this space
460 $LN = ($a==$c) ?
'blank' : 'line';
462 // If records should be accumulated, do so
463 if ($this->setRecs
) { $this->recs
[$row['uid']] = $row; }
465 // Accumulate the id of the element in the internal arrays
466 $this->ids
[]=$idH[$row['uid']]['uid'] = $row['uid'];
467 $this->ids_hierarchy
[$depth][] = $row['uid'];
469 // Make a recursive call to the next level
470 if ($depth > 1 && $this->expandNext($newID) && !$row['php_tree_stop']) {
471 $nextCount=$this->getTree(
474 $blankLineCode.','.$LN,
477 if (count($this->buffer_idH
)) { $idH[$row['uid']]['subrow']=$this->buffer_idH
; }
478 $exp = 1; // Set "did expand" flag
480 $nextCount = $this->getCount($newID);
481 $exp = 0; // Clear "did expand" flag
484 // Set HTML-icons, if any:
485 if ($this->makeHTML
) {
486 if ($row['_FIRST_NOT_IN_MENU']) {
487 $HTML = '<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/line.gif').' alt="" /><br/><img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/line.gif').' alt="" /><i>Not shown in menu'.$label_shownAlphabetically.':</i><br>';
492 $HTML.= $this->PMicon($row,$a,$c,$nextCount,$exp);
493 $HTML.= $this->wrapStop($this->getIcon($row),$row);
496 // Finally, add the row/HTML content to the ->tree array in the reserved key.
497 $this->tree
[$treeKey] = array(
500 'hasSub' => $nextCount&&$this->expandNext($newID),
503 'invertedDepth'=> $depth,
504 'blankLineCode'=> $blankLineCode,
505 'bank' => $this->bank
509 if($a) { $this->tree
[$treeKey]['isLast'] = true; }
511 $this->getDataFree($res);
512 $this->buffer_idH
= $idH;
517 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/class.webpagetree.php']) {
518 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/class.webpagetree.php']);