[TASK] Remove unused option for "oncontextmenu"
[Packages/TYPO3.CMS.git] / typo3 / class.webpagetree.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
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.
13 *
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.
18 *
19 *
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.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Page navigation tree for the Web module
29 *
30 * Revised for TYPO3 3.6 2/2003 by Kasper Skårhøj
31 * XHTML compliant
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 * @author Benjamin Mack <bmack@xnos.org>
35 *
36 *
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
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='')
51 *
52 *
53 * TOTAL FUNCTIONS: 9
54 * (This index is automatically created/updated by the extension "extdeveval")
55 *
56 */
57
58
59 /**
60 * Extension class for the t3lib_browsetree class, specially made
61 * for browsing pages in the Web module
62 *
63 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
64 * @author Benjamin Mack <bmack@xnos.org>
65 * @package TYPO3
66 * @subpackage core
67 * @see class t3lib_browseTree
68 */
69 class webPageTree extends t3lib_browseTree {
70
71 var $ext_showPageId;
72 var $ext_IconMode;
73 var $ext_separateNotinmenuPages;
74 var $ext_alphasortNotinmenuPages;
75 var $ajaxStatus = FALSE; // Indicates, whether the ajax call was successful, i.e. the requested page has been found
76
77 /**
78 * Calls init functions
79 *
80 * @return void
81 */
82 function __construct() {
83 $this->init();
84 }
85
86 /**
87 * Compatibility constructor.
88 *
89 * @deprecated since TYPO3 4.6 and will be removed in TYPO3 4.8. Use __construct() instead.
90 */
91 public function webPageTree() {
92 t3lib_div::logDeprecatedFunction();
93 // Note: we cannot call $this->__construct() here because it would call the derived class constructor and cause recursion
94 // This code uses official PHP behavior (http://www.php.net/manual/en/language.oop5.basic.php) when $this in the
95 // statically called non-static method inherits $this from the caller's scope.
96 webPageTree::__construct();
97 }
98
99 /**
100 * Wrapping icon in browse tree
101 *
102 * @param string Icon IMG code
103 * @param array Data row for element.
104 * @return string Page icon
105 */
106 function wrapIcon($thePageIcon, &$row) {
107 // If the record is locked, present a warning sign.
108 if ($lockInfo=t3lib_BEfunc::isRecordLocked('pages',$row['uid'])) {
109 $aOnClick = 'alert('.$GLOBALS['LANG']->JScharCode($lockInfo['msg']).');return false;';
110 $lockIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
111 t3lib_iconWorks::getSpriteIcon('status-warning-in-use',array('title'=>htmlspecialchars($lockInfo['msg']))).
112 '</a>';
113 } else $lockIcon = '';
114
115 // Wrap icon in click-menu link.
116 if (!$this->ext_IconMode) {
117 $thePageIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($thePageIcon,'pages',$row['uid'],0,'&bank='.$this->bank);
118 } elseif (!strcmp($this->ext_IconMode,'titlelink')) {
119 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->treeName.'\');';
120 $thePageIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$thePageIcon.'</a>';
121 }
122
123 // Wrap icon in a drag/drop span.
124 $dragDropIcon = '<span class="dragIcon" id="dragIconID_'.$row['uid'].'">'.$thePageIcon.'</span>';
125
126 // Add Page ID:
127 $pageIdStr = '';
128 if ($this->ext_showPageId) {
129 $pageIdStr = '<span class="dragId">[' . $row['uid'] . ']</span> ';
130 }
131
132 // Call stats information hook
133 $stat = '';
134 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'])) {
135 $_params = array('pages',$row['uid']);
136 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef) {
137 $stat.=t3lib_div::callUserFunction($_funcRef,$_params,$this);
138 }
139 }
140
141 return $dragDropIcon.$lockIcon.$pageIdStr.$stat;
142 }
143
144 /**
145 * Adds a red "+" to the input string, $str, if the field "php_tree_stop" in the $row (pages) is set
146 *
147 * @param string Input string, like a page title for the tree
148 * @param array record row with "php_tree_stop" field
149 * @return string Modified string
150 * @access private
151 */
152 function wrapStop($str,$row) {
153 if ($row['php_tree_stop']) {
154 $str.='<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('setTempDBmount' => $row['uid']))).'" class="typo3-red">+</a> ';
155 }
156 return $str;
157 }
158
159 /**
160 * Wrapping $title in a-tags.
161 *
162 * @param string Title string
163 * @param string Item record
164 * @param integer Bank pointer (which mount point number)
165 * @return string
166 * @access private
167 */
168 function wrapTitle($title,$row,$bank=0) {
169 // Hook for overriding the page title
170 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.webpagetree.php']['pageTitleOverlay'])) {
171 $_params = array('title' => &$title, 'row' => &$row);
172 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.webpagetree.php']['pageTitleOverlay'] as $_funcRef) {
173 t3lib_div::callUserFunction($_funcRef, $_params, $this);
174 }
175 unset($_params);
176 }
177
178 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'\','.$bank.');';
179 $CSM = ' oncontextmenu="'.htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('','pages',$row['uid'],0,'&bank='.$this->bank,'',TRUE)).';"';
180 $thePageTitle='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"'.$CSM.'>'.$title.'</a>';
181
182 // Wrap title in a drag/drop span.
183 return '<span class="dragTitle" id="dragTitleID_'.$row['uid'].'">'.$thePageTitle.'</span>';
184 }
185
186
187 /**
188 * Compiles the HTML code for displaying the structure found inside the ->tree array
189 *
190 * @param array "tree-array" - if blank string, the internal ->tree array is used.
191 * @return string The HTML code for the tree
192 */
193 function printTree($treeArr = '') {
194 $titleLen = intval($this->BE_USER->uc['titleLen']);
195 if (!is_array($treeArr)) {
196 $treeArr = $this->tree;
197 }
198
199 $out = '
200 <!-- TYPO3 tree structure. -->
201 <ul class="tree" id="treeRoot">
202 ';
203
204 // -- evaluate AJAX request
205 // IE takes anchor as parameter
206 $PM = t3lib_div::_GP('PM');
207 if(($PMpos = strpos($PM, '#')) !== FALSE) { $PM = substr($PM, 0, $PMpos); }
208 $PM = explode('_', $PM);
209 if ((TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) && is_array($PM) && count($PM) == 4 && $PM[2] != 0) {
210 if($PM[1]) {
211 $expandedPageUid = $PM[2];
212 $ajaxOutput = '';
213 $invertedDepthOfAjaxRequestedItem = 0; // We don't know yet. Will be set later.
214 $doExpand = TRUE;
215 } else {
216 $collapsedPageUid = $PM[2];
217 $doCollapse = TRUE;
218 }
219 }
220
221 // we need to count the opened <ul>'s every time we dig into another level,
222 // so we know how many we have to close when all children are done rendering
223 $closeDepth = array();
224
225 foreach($treeArr as $k => $v) {
226 $classAttr = $v['row']['_CSSCLASS'];
227 $uid = $v['row']['uid'];
228 $idAttr = htmlspecialchars($this->domIdPrefix.$this->getId($v['row']).'_'.$v['bank']);
229 $itemHTML = '';
230
231 // if this item is the start of a new level,
232 // then a new level <ul> is needed, but not in ajax mode
233 if($v['isFirst'] && !($doCollapse) && !($doExpand && $expandedPageUid == $uid)) {
234 $itemHTML = '<ul>';
235 }
236
237 // add CSS classes to the list item
238 if($v['hasSub']) { $classAttr .= ($classAttr) ? ' expanded': 'expanded'; }
239 if($v['isLast']) { $classAttr .= ($classAttr) ? ' last' : 'last'; }
240
241 $itemHTML .='
242 <li id="'.$idAttr.'"'.($classAttr ? ' class="'.$classAttr.'"' : '').'><div class="treeLinkItem">'.
243 $v['HTML'].
244 $this->wrapTitle($this->getTitleStr($v['row'],$titleLen),$v['row'],$v['bank'])."</div>\n";
245
246
247 if(!$v['hasSub']) { $itemHTML .= '</li>'; }
248
249 // we have to remember if this is the last one
250 // on level X so the last child on level X+1 closes the <ul>-tag
251 if($v['isLast'] && !($doExpand && $expandedPageUid == $uid)) { $closeDepth[$v['invertedDepth']] = 1; }
252
253
254 // if this is the last one and does not have subitems, we need to close
255 // the tree as long as the upper levels have last items too
256 if($v['isLast'] && !$v['hasSub'] && !$doCollapse && !($doExpand && $expandedPageUid == $uid)) {
257 for ($i = $v['invertedDepth']; $closeDepth[$i] == 1; $i++) {
258 $closeDepth[$i] = 0;
259 $itemHTML .= '</ul></li>';
260 }
261 }
262
263 // ajax request: collapse
264 if($doCollapse && $collapsedPageUid == $uid) {
265 $this->ajaxStatus = TRUE;
266 return $itemHTML;
267 }
268
269 // ajax request: expand
270 if($doExpand && $expandedPageUid == $uid) {
271 $ajaxOutput .= $itemHTML;
272 $invertedDepthOfAjaxRequestedItem = $v['invertedDepth'];
273 } elseif($invertedDepthOfAjaxRequestedItem) {
274 if($v['invertedDepth'] < $invertedDepthOfAjaxRequestedItem) {
275 $ajaxOutput .= $itemHTML;
276 } else {
277 $this->ajaxStatus = TRUE;
278 return $ajaxOutput;
279 }
280 }
281
282 $out .= $itemHTML;
283 }
284
285 if($ajaxOutput) {
286 $this->ajaxStatus = TRUE;
287 return $ajaxOutput;
288 }
289
290 // finally close the first ul
291 $out .= '</ul>';
292 return $out;
293 }
294
295
296 /**
297 * Generate the plus/minus icon for the browsable tree.
298 *
299 * @param array record for the entry
300 * @param integer The current entry number
301 * @param integer The total number of entries. If equal to $a, a "bottom" element is returned.
302 * @param integer The number of sub-elements to the current element.
303 * @param boolean The element was expanded to render subelements if this flag is set.
304 * @return string Image tag with the plus/minus icon.
305 * @access private
306 * @see t3lib_pageTree::PMicon()
307 */
308 function PMicon($row,$a,$c,$nextCount,$exp) {
309 $PM = $nextCount ? ($exp ? 'minus' : 'plus') : 'join';
310 $BTM = ($a == $c) ? 'bottom' : '';
311 $icon = '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' alt="" />';
312
313 if ($nextCount) {
314 $cmd = $this->bank.'_'.($exp?'0_':'1_').$row['uid'].'_'.$this->treeName;
315 $icon = $this->PMiconATagWrap($icon,$cmd,!$exp);
316 }
317 return $icon;
318 }
319
320
321 /**
322 * Wrap the plus/minus icon in a link
323 *
324 * @param string HTML string to wrap, probably an image tag.
325 * @param string Command for 'PM' get var
326 * @return string Link-wrapped input string
327 * @access private
328 */
329 function PMiconATagWrap($icon, $cmd, $isExpand = TRUE) {
330 if ($this->thisScript) {
331 // activate dynamic ajax-based tree
332 $js = htmlspecialchars('Tree.load(\''.$cmd.'\', '.intval($isExpand).', this);');
333 return '<a class="pm" onclick="'.$js.'">'.$icon.'</a>';
334 } else {
335 return $icon;
336 }
337 }
338
339
340 /**
341 * Will create and return the HTML code for a browsable tree
342 * Is based on the mounts found in the internal array ->MOUNTS (set in the constructor)
343 *
344 * @return string HTML code for the browsable tree
345 */
346 function getBrowsableTree() {
347
348 // Get stored tree structure AND updating it if needed according to incoming PM GET var.
349 $this->initializePositionSaving();
350
351 // Init done:
352 $titleLen = intval($this->BE_USER->uc['titleLen']);
353 $treeArr = array();
354
355 // Traverse mounts:
356 foreach($this->MOUNTS as $idx => $uid) {
357
358 // Set first:
359 $this->bank = $idx;
360 $isOpen = $this->stored[$idx][$uid] || $this->expandFirst || $uid === '0';
361
362 // Save ids while resetting everything else.
363 $curIds = $this->ids;
364 $this->reset();
365 $this->ids = $curIds;
366
367 // Set PM icon for root of mount:
368 $cmd = $this->bank.'_'.($isOpen? "0_" : "1_").$uid.'_'.$this->treeName;
369 // only, if not for uid 0
370 if ($uid) {
371 $icon = '<img' . t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/' . ($isOpen ? 'minus' :'plus' ) . 'only.gif') . ' alt="" />';
372 $firstHtml = $this->PMiconATagWrap($icon, $cmd, !$isOpen);
373 }
374
375 // Preparing rootRec for the mount
376 if ($uid) {
377 $rootRec = $this->getRecord($uid);
378 $firstHtml.=$this->getIcon($rootRec);
379 } else {
380 // Artificial record for the tree root, id=0
381 $rootRec = $this->getRootRecord($uid);
382 $firstHtml.=$this->getRootIcon($rootRec);
383 }
384
385 if (is_array($rootRec)) {
386 // In case it was swapped inside getRecord due to workspaces.
387 $uid = $rootRec['uid'];
388
389 // Add the root of the mount to ->tree
390 $this->tree[] = array('HTML'=>$firstHtml, 'row'=>$rootRec, 'bank'=>$this->bank, 'hasSub'=>TRUE, 'invertedDepth'=>1000);
391
392 // If the mount is expanded, go down:
393 if ($isOpen) {
394 // Set depth:
395 if ($this->addSelfId) { $this->ids[] = $uid; }
396 $this->getTree($uid, 999, '', $rootRec['_SUBCSSCLASS']);
397 }
398 // Add tree:
399 $treeArr=array_merge($treeArr,$this->tree);
400 }
401 }
402 return $this->printTree($treeArr);
403 }
404
405
406 /**
407 * Fetches the data for the tree
408 *
409 * @param integer item id for which to select subitems (parent id)
410 * @param integer Max depth (recursivity limit)
411 * @param string ? (internal)
412 * @return integer The count of items on the level
413 */
414 function getTree($uid, $depth=999, $blankLineCode='', $subCSSclass='') {
415
416 // Buffer for id hierarchy is reset:
417 $this->buffer_idH = array();
418
419 // Init vars
420 $depth = intval($depth);
421 $HTML = '';
422 $a = 0;
423
424 $res = $this->getDataInit($uid, $subCSSclass);
425 $c = $this->getDataCount($res);
426 $crazyRecursionLimiter = 999;
427
428 $inMenuPages = array();
429 $outOfMenuPages = array();
430 $outOfMenuPagesTextIndex = array();
431 while ($crazyRecursionLimiter > 0 && $row = $this->getDataNext($res,$subCSSclass)) {
432 $crazyRecursionLimiter--;
433
434 // Not in menu:
435 if ($this->ext_separateNotinmenuPages &&
436 ($row['doktype'] == t3lib_pageSelect::DOKTYPE_BE_USER_SECTION ||
437 $row['doktype'] >= 200 || $row['nav_hide'])) {
438 $outOfMenuPages[] = $row;
439 $outOfMenuPagesTextIndex[] = ($row['doktype']>=200 ? 'zzz'.$row['doktype'].'_' : '').$row['title'];
440 } else {
441 $inMenuPages[] = $row;
442 }
443 }
444
445 $label_shownAlphabetically = "";
446 if (count($outOfMenuPages)) {
447 // Sort out-of-menu pages:
448 $outOfMenuPages_alphabetic = array();
449 if ($this->ext_alphasortNotinmenuPages) {
450 asort($outOfMenuPagesTextIndex);
451 $label_shownAlphabetically = " (alphabetic)";
452 }
453 foreach($outOfMenuPagesTextIndex as $idx => $txt) {
454 $outOfMenuPages_alphabetic[] = $outOfMenuPages[$idx];
455 }
456
457 // Merge:
458 $outOfMenuPages_alphabetic[0]['_FIRST_NOT_IN_MENU']=TRUE;
459 $allRows = array_merge($inMenuPages,$outOfMenuPages_alphabetic);
460 } else {
461 $allRows = $inMenuPages;
462 }
463
464 // Traverse the records:
465 foreach ($allRows as $row) {
466 $a++;
467
468 $newID = $row['uid'];
469 $this->tree[]=array(); // Reserve space.
470 end($this->tree);
471 $treeKey = key($this->tree); // Get the key for this space
472 $LN = ($a==$c) ? 'blank' : 'line';
473
474 // If records should be accumulated, do so
475 if ($this->setRecs) { $this->recs[$row['uid']] = $row; }
476
477 // Accumulate the id of the element in the internal arrays
478 $this->ids[]=$idH[$row['uid']]['uid'] = $row['uid'];
479 $this->ids_hierarchy[$depth][] = $row['uid'];
480
481 // Make a recursive call to the next level
482 if ($depth > 1 && $this->expandNext($newID) && !$row['php_tree_stop']) {
483 $nextCount=$this->getTree(
484 $newID,
485 $depth-1,
486 $blankLineCode.','.$LN,
487 $row['_SUBCSSCLASS']
488 );
489 if (count($this->buffer_idH)) { $idH[$row['uid']]['subrow']=$this->buffer_idH; }
490 $exp = 1; // Set "did expand" flag
491 } else {
492 $nextCount = $this->getCount($newID);
493 $exp = 0; // Clear "did expand" flag
494 }
495
496 // Set HTML-icons, if any:
497 if ($this->makeHTML) {
498 if ($row['_FIRST_NOT_IN_MENU']) {
499 $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>';
500 } else {
501 $HTML = '';
502 }
503
504 $HTML.= $this->PMicon($row,$a,$c,$nextCount,$exp);
505 $HTML.= $this->wrapStop($this->getIcon($row),$row);
506 }
507
508 // Finally, add the row/HTML content to the ->tree array in the reserved key.
509 $this->tree[$treeKey] = array(
510 'row' => $row,
511 'HTML' => $HTML,
512 'hasSub' => $nextCount&&$this->expandNext($newID),
513 'isFirst'=> $a==1,
514 'isLast' => FALSE,
515 'invertedDepth'=> $depth,
516 'blankLineCode'=> $blankLineCode,
517 'bank' => $this->bank
518 );
519 }
520
521 if($a) { $this->tree[$treeKey]['isLast'] = TRUE; }
522
523 $this->getDataFree($res);
524 $this->buffer_idH = $idH;
525 return $c;
526 }
527 }
528
529 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/class.webpagetree.php'])) {
530 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/class.webpagetree.php']);
531 }
532
533 ?>