00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00059 require_once(PATH_t3lib.'class.t3lib_browsetree.php');
00060
00061
00072 class webPageTree extends t3lib_browseTree {
00073
00074 var $ext_showPageId;
00075 var $ext_IconMode;
00076 var $ajaxStatus = false;
00077
00083 function webPageTree() {
00084 $this->init();
00085 }
00086
00094 function wrapIcon($icon,&$row) {
00095
00096 if ($lockInfo=t3lib_BEfunc::isRecordLocked('pages',$row['uid'])) {
00097 $aOnClick = 'alert('.$GLOBALS['LANG']->JScharCode($lockInfo['msg']).');return false;';
00098 $lockIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
00099 '<img'.t3lib_iconWorks::skinImg('','gfx/recordlock_warning3.gif','width="17" height="12"').' title="'.htmlspecialchars($lockInfo['msg']).'" alt="" />'.
00100 '</a>';
00101 } else $lockIcon = '';
00102
00103
00104 $thePageIcon = $this->addTagAttributes($icon, $this->titleAttrib.'="'.$this->getTitleAttrib($row).'"');
00105
00106
00107 if (!$this->ext_IconMode) {
00108 $thePageIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($thePageIcon,'pages',$row['uid'],0,'&bank='.$this->bank);
00109 } elseif (!strcmp($this->ext_IconMode,'titlelink')) {
00110 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->treeName.'\');';
00111 $thePageIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$thePageIcon.'</a>';
00112 }
00113
00114
00115 $dragDropIcon = '<span class="dragIcon" id="dragIconID_'.$row['uid'].'">'.$thePageIcon.'</span>';
00116
00117
00118 $pageIdStr = '';
00119 if ($this->ext_showPageId) { $pageIdStr = '['.$row['uid'].'] '; }
00120
00121 return $dragDropIcon.$lockIcon.$pageIdStr;
00122 }
00123
00132 function wrapStop($str,$row) {
00133 if ($row['php_tree_stop']) {
00134 $str.='<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('setTempDBmount' => $row['uid']))).'" class="typo3-red">+</a> ';
00135 }
00136 return $str;
00137 }
00138
00148 function wrapTitle($title,$row,$bank=0) {
00149 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'\','.$bank.');';
00150 $CSM = '';
00151 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler']) {
00152 $CSM = ' oncontextmenu="'.htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('','pages',$row['uid'],0,'&bank='.$this->bank,'',TRUE)).';"';
00153 }
00154 $thePageTitle='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"'.$CSM.'>'.$title.'</a>';
00155
00156
00157 return '<span class="dragTitle" id="dragTitleID_'.$row['uid'].'">'.$thePageTitle.'</span>';
00158 }
00159
00160
00167 function printTree($treeArr = '') {
00168 $titleLen = intval($this->BE_USER->uc['titleLen']);
00169 if (!is_array($treeArr)) $treeArr = $this->tree;
00170
00171 $out = '
00172 <!-- TYPO3 tree structure. -->
00173 <ul class="tree">
00174 ';
00175
00176
00177
00178 $PM = t3lib_div::_GP('PM');
00179 if(($PMpos = strpos($PM, '#')) !== false) { $PM = substr($PM, 0, $PMpos); }
00180 $PM = explode('_', $PM);
00181 if(($isAjaxCall = t3lib_div::_GP('ajax')) && is_array($PM) && count($PM)==4) {
00182 if($PM[1]) {
00183 $expandedPageUid = $PM[2];
00184 $ajaxOutput = '';
00185 $invertedDepthOfAjaxRequestedItem = 0;
00186 $doExpand = true;
00187 } else {
00188 $collapsedPageUid = $PM[2];
00189 $doCollapse = true;
00190 }
00191 }
00192
00193
00194
00195 $closeDepth = array();
00196
00197 foreach($treeArr as $k => $v) {
00198 $classAttr = $v['row']['_CSSCLASS'];
00199 $uid = $v['row']['uid'];
00200 $idAttr = htmlspecialchars($this->domIdPrefix.$this->getId($v['row']).'_'.$v['bank']);
00201 $itemHTML = '';
00202
00203
00204
00205 if($v['isFirst'] && !($doCollapse) && !($doExpand && $expandedPageUid == $uid)) {
00206 $itemHTML = '<ul>';
00207 }
00208
00209
00210 if($v['hasSub']) { $classAttr .= ($classAttr) ? ' expanded': 'expanded'; }
00211 if($v['isLast']) { $classAttr .= ($classAttr) ? ' last' : 'last'; }
00212
00213 $itemHTML .='
00214 <li id="'.$idAttr.'"'.($classAttr ? ' class="'.$classAttr.'"' : '').'>'.
00215 $v['HTML'].
00216 $this->wrapTitle($this->getTitleStr($v['row'],$titleLen),$v['row'],$v['bank'])."\n";
00217
00218
00219 if(!$v['hasSub']) { $itemHTML .= '</li>'; }
00220
00221
00222
00223 if($v['isLast'] && !($doExpand && $expandedPageUid == $uid)) { $closeDepth[$v['invertedDepth']] = 1; }
00224
00225
00226
00227
00228 if($v['isLast'] && !$v['hasSub'] && !$doCollapse && !($doExpand && $expandedPageUid == $uid)) {
00229 for ($i = $v['invertedDepth']; $closeDepth[$i] == 1; $i++) {
00230 $closeDepth[$i] = 0;
00231 $itemHTML .= '</ul></li>';
00232 }
00233 }
00234
00235
00236 if($doCollapse && $collapsedPageUid == $uid) {
00237 $this->ajaxStatus = true;
00238 return $itemHTML;
00239 }
00240
00241
00242 if($doExpand && $expandedPageUid == $uid) {
00243 $ajaxOutput .= $itemHTML;
00244 $invertedDepthOfAjaxRequestedItem = $v['invertedDepth'];
00245 } elseif($invertedDepthOfAjaxRequestedItem) {
00246 if($v['invertedDepth'] < $invertedDepthOfAjaxRequestedItem) {
00247 $ajaxOutput .= $itemHTML;
00248 } else {
00249 $this->ajaxStatus = true;
00250 return $ajaxOutput;
00251 }
00252 }
00253
00254 $out .= $itemHTML;
00255 }
00256
00257 if($ajaxOutput) {
00258 $this->ajaxStatus = true;
00259 return $ajaxOutput;
00260 }
00261
00262
00263 $out .= '</ul>';
00264 return $out;
00265 }
00266
00267
00280 function PMicon($row,$a,$c,$nextCount,$exp) {
00281 $PM = $nextCount ? ($exp ? 'minus' : 'plus') : 'join';
00282 $BTM = ($a == $c) ? 'bottom' : '';
00283 $icon = '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' alt="" />';
00284
00285 if ($nextCount) {
00286 $cmd = $this->bank.'_'.($exp?'0_':'1_').$row['uid'].'_'.$this->treeName;
00287 $icon = $this->PMiconATagWrap($icon,$cmd,!$exp);
00288 }
00289 return $icon;
00290 }
00291
00292
00301 function PMiconATagWrap($icon, $cmd, $isExpand = true) {
00302 if ($this->thisScript) {
00303
00304 $js = htmlspecialchars('Tree.load(\''.$cmd.'\', '.intval($isExpand).', this);');
00305 return '<a class="pm" onclick="'.$js.'">'.$icon.'</a>';
00306 } else {
00307 return $icon;
00308 }
00309 }
00310
00311
00318 function getBrowsableTree() {
00319
00320
00321 $this->initializePositionSaving();
00322
00323
00324 $titleLen = intval($this->BE_USER->uc['titleLen']);
00325 $treeArr = array();
00326
00327
00328 foreach($this->MOUNTS as $idx => $uid) {
00329
00330
00331 $this->bank = $idx;
00332 $isOpen = $this->stored[$idx][$uid] || $this->expandFirst;
00333
00334
00335 $curIds = $this->ids;
00336 $this->reset();
00337 $this->ids = $curIds;
00338
00339
00340 $cmd = $this->bank.'_'.($isOpen? "0_" : "1_").$uid.'_'.$this->treeName;
00341 $icon='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.($isOpen?'minus':'plus').'only.gif').' alt="" />';
00342 $firstHtml = $this->PMiconATagWrap($icon,$cmd);
00343
00344
00345 if ($uid) {
00346 $rootRec = $this->getRecord($uid);
00347 $firstHtml.=$this->getIcon($rootRec);
00348 } else {
00349
00350 $rootRec = $this->getRootRecord($uid);
00351 $firstHtml.=$this->getRootIcon($rootRec);
00352 }
00353
00354 if (is_array($rootRec)) {
00355
00356 $uid = $rootRec['uid'];
00357
00358
00359 $this->tree[] = array('HTML'=>$firstHtml, 'row'=>$rootRec, 'bank'=>$this->bank, 'hasSub'=>true, 'invertedDepth'=>1000);
00360
00361
00362 if ($isOpen) {
00363
00364 if ($this->addSelfId) { $this->ids[] = $uid; }
00365 $this->getTree($uid, 999, '', $rootRec['_SUBCSSCLASS']);
00366 }
00367
00368 $treeArr=array_merge($treeArr,$this->tree);
00369 }
00370 }
00371 return $this->printTree($treeArr);
00372 }
00373
00374
00383 function getTree($uid, $depth=999, $blankLineCode='', $subCSSclass='') {
00384
00385
00386 $this->buffer_idH = array();
00387
00388
00389 $depth = intval($depth);
00390 $HTML = '';
00391 $a = 0;
00392
00393 $res = $this->getDataInit($uid, $subCSSclass);
00394 $c = $this->getDataCount($res);
00395 $crazyRecursionLimiter = 999;
00396
00397
00398 while ($crazyRecursionLimiter > 0 && $row = $this->getDataNext($res,$subCSSclass)) {
00399 $a++;
00400 $crazyRecursionLimiter--;
00401
00402 $newID = $row['uid'];
00403 $this->tree[]=array();
00404 end($this->tree);
00405 $treeKey = key($this->tree);
00406 $LN = ($a==$c) ? 'blank' : 'line';
00407
00408
00409 if ($this->setRecs) { $this->recs[$row['uid']] = $row; }
00410
00411
00412 $this->ids[]=$idH[$row['uid']]['uid'] = $row['uid'];
00413 $this->ids_hierarchy[$depth][] = $row['uid'];
00414
00415
00416 if ($depth > 1 && $this->expandNext($newID) && !$row['php_tree_stop']) {
00417 $nextCount=$this->getTree(
00418 $newID,
00419 $depth-1,
00420 $blankLineCode.','.$LN,
00421 $row['_SUBCSSCLASS']
00422 );
00423 if (count($this->buffer_idH)) { $idH[$row['uid']]['subrow']=$this->buffer_idH; }
00424 $exp = 1;
00425 } else {
00426 $nextCount = $this->getCount($newID);
00427 $exp = 0;
00428 }
00429
00430
00431 if ($this->makeHTML) {
00432 $HTML = $this->PMicon($row,$a,$c,$nextCount,$exp);
00433 $HTML.= $this->wrapStop($this->getIcon($row),$row);
00434 }
00435
00436
00437 $this->tree[$treeKey] = array(
00438 'row' => $row,
00439 'HTML' => $HTML,
00440 'hasSub' => $nextCount&&$this->expandNext($newID),
00441 'isFirst'=> $a==1,
00442 'isLast' => false,
00443 'invertedDepth'=> $depth,
00444 'blankLineCode'=> $blankLineCode,
00445 'bank' => $this->bank
00446 );
00447 }
00448
00449 if($a) { $this->tree[$treeKey]['isLast'] = true; }
00450
00451 $this->getDataFree($res);
00452 $this->buffer_idH = $idH;
00453 return $c;
00454 }
00455 }
00456
00457 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.webpagetree.php']) {
00458 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.webpagetree.php']);
00459 }
00460 ?>