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
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 require_once (PATH_t3lib.'class.t3lib_iconworks.php');
00102 require_once (PATH_t3lib.'class.t3lib_befunc.php');
00103 require_once (PATH_t3lib.'class.t3lib_div.php');
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 class t3lib_treeView {
00116
00117
00118 var $expandFirst=0;
00119 var $expandAll=0;
00120 var $thisScript='';
00121 var $titleAttrib = 'title';
00122 var $ext_IconMode = false;
00123 var $addSelfId = 0;
00124 var $title='no title';
00125 var $showDefaultTitleAttribute = FALSE;
00126 var $highlightPagesWithVersions = TRUE;
00127
00128
00129
00130
00131
00132
00133
00134 var $BE_USER='';
00135
00136
00137
00138
00139
00140
00141 var $MOUNTS='';
00142
00143
00144
00145
00146
00147
00148
00149 var $table='';
00150
00151
00152
00153
00154 var $parentField='pid';
00155
00156
00157
00158
00159
00160
00161 var $clause='';
00162
00163
00164
00165
00166
00167
00168 var $orderByFields='';
00169
00170
00171
00172
00173
00174
00175 var $fieldArray = Array('uid','title');
00176
00177
00178
00179
00180
00181 var $defaultList = 'uid,pid,tstamp,sorting,deleted,perms_userid,perms_groupid,perms_user,perms_group,perms_everybody,crdate,cruser_id';
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 var $treeName = '';
00192
00193
00194
00195
00196
00197
00198
00199 var $domIdPrefix = 'row';
00200
00201
00202
00203
00204 var $backPath;
00205
00206
00207
00208
00209 var $iconPath = '';
00210
00211
00212
00213
00214
00215 var $iconName = 'default.gif';
00216
00217
00218
00219
00220
00221 var $makeHTML=1;
00222
00223
00224
00225
00226 var $setRecs = 0;
00227
00228
00229
00230
00231
00232 var $subLevelID = '_SUB_LEVEL';
00233
00234
00235
00236
00237
00238
00239
00240
00241 var $ids = Array();
00242 var $ids_hierarchy = array();
00243 var $orig_ids_hierarchy = array();
00244 var $buffer_idH = array();
00245
00246
00247 var $specUIDmap=array();
00248
00249
00250 var $data = false;
00251 var $dataLookup = false;
00252
00253
00254 var $tree = Array();
00255 var $stored = array();
00256 var $bank=0;
00257 var $recs = array();
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273 function init($clause='', $orderByFields='') {
00274 $this->BE_USER = $GLOBALS['BE_USER'];
00275 $this->titleAttrib = 'title';
00276 $this->backPath = $GLOBALS['BACK_PATH'];
00277
00278 if ($clause) $this->clause = $clause;
00279 if ($orderByFields) $this->orderByFields = $orderByFields;
00280
00281 if (!is_array($this->MOUNTS)) {
00282 $this->MOUNTS = array(0 => 0);
00283 }
00284
00285 $this->setTreeName();
00286
00287 if($this->table) {
00288 t3lib_div::loadTCA($this->table);
00289 }
00290
00291
00292 $this->data = false;
00293 $this->dataLookup = false;
00294 }
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 function setTreeName($treeName='') {
00305 $this->treeName = $treeName ? $treeName : $this->treeName;
00306 $this->treeName = $this->treeName ? $this->treeName : $this->table;
00307 $this->treeName = str_replace('_','',$this->treeName);
00308 }
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318 function addField($field,$noCheck=0) {
00319 global $TCA;
00320 if ($noCheck || is_array($TCA[$this->table]['columns'][$field]) || t3lib_div::inList($this->defaultList,$field)) {
00321 $this->fieldArray[]=$field;
00322 }
00323 }
00324
00325
00326
00327
00328
00329
00330
00331
00332 function reset() {
00333 $this->tree = array();
00334 $this->recs = array();
00335 $this->ids = array();
00336 $this->ids_hierarchy = array();
00337 $this->orig_ids_hierarchy = array();
00338 }
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353 function getBrowsableTree() {
00354
00355
00356 $this->initializePositionSaving();
00357
00358
00359 $titleLen=intval($this->BE_USER->uc['titleLen']);
00360 $treeArr=array();
00361
00362
00363 foreach($this->MOUNTS as $idx => $uid) {
00364
00365
00366 $this->bank=$idx;
00367 $isOpen = $this->stored[$idx][$uid] || $this->expandFirst;
00368
00369
00370 $curIds = $this->ids;
00371 $this->reset();
00372 $this->ids = $curIds;
00373
00374
00375 $cmd=$this->bank.'_'.($isOpen?"0_":"1_").$uid.'_'.$this->treeName;
00376 $icon='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.($isOpen?'minus':'plus').'only.gif','width="18" height="16"').' alt="" />';
00377 $firstHtml= $this->PM_ATagWrap($icon,$cmd);
00378
00379
00380 if ($uid) {
00381 $rootRec = $this->getRecord($uid);
00382 $firstHtml.=$this->getIcon($rootRec);
00383 } else {
00384
00385 $rootRec = $this->getRootRecord($uid);
00386 $firstHtml.=$this->getRootIcon($rootRec);
00387 }
00388
00389 if (is_array($rootRec)) {
00390 $uid = $rootRec['uid'];
00391
00392
00393 $this->tree[]=array('HTML'=>$firstHtml, 'row'=>$rootRec, 'bank'=>$this->bank);
00394
00395
00396 if ($isOpen) {
00397
00398 $depthD='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/blank.gif','width="18" height="16"').' alt="" />';
00399 if ($this->addSelfId) $this->ids[] = $uid;
00400 $this->getTree($uid,999,$depthD,'',$rootRec['_SUBCSSCLASS']);
00401 }
00402
00403
00404 $treeArr=array_merge($treeArr,$this->tree);
00405 }
00406 }
00407 return $this->printTree($treeArr);
00408 }
00409
00410
00411
00412
00413
00414
00415
00416 function printTree($treeArr='') {
00417 $titleLen=intval($this->BE_USER->uc['titleLen']);
00418 if (!is_array($treeArr)) $treeArr=$this->tree;
00419 $out='';
00420
00421
00422
00423
00424 $out .= '
00425
00426 <!--
00427 TYPO3 tree structure.
00428 -->
00429 <table cellpadding="0" cellspacing="0" border="0" id="typo3-tree">';
00430
00431 foreach($treeArr as $k => $v) {
00432 $idAttr = htmlspecialchars($this->domIdPrefix.$this->getId($v['row']).'_'.$v['bank']);
00433
00434 $out.='
00435 <tr>
00436 <td id="'.$idAttr.'"'.
00437 ($v['row']['_CSSCLASS'] ? ' class="'.$v['row']['_CSSCLASS'].'"' : '').'>'.
00438 $v['HTML'].
00439 $this->wrapTitle($this->getTitleStr($v['row'],$titleLen),$v['row'],$v['bank']).
00440 '</td>
00441 </tr>
00442 ';
00443 }
00444 $out .= '
00445 </table>';
00446 return $out;
00447 }
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471 function PMicon($row,$a,$c,$nextCount,$exp) {
00472 $PM = $nextCount ? ($exp?'minus':'plus') : 'join';
00473 $BTM = ($a==$c)?'bottom':'';
00474 $icon = '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' alt="" />';
00475
00476 if ($nextCount) {
00477 $cmd=$this->bank.'_'.($exp?'0_':'1_').$row['uid'].'_'.$this->treeName;
00478 $bMark=($this->bank.'_'.$row['uid']);
00479 $icon = $this->PM_ATagWrap($icon,$cmd,$bMark);
00480 }
00481 return $icon;
00482 }
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493 function PM_ATagWrap($icon,$cmd,$bMark='') {
00494 if ($this->thisScript) {
00495 if ($bMark) {
00496 $anchor = '#'.$bMark;
00497 $name=' name="'.$bMark.'"';
00498 }
00499 $aUrl = $this->thisScript.'?PM='.$cmd.$anchor;
00500 return '<a href="'.htmlspecialchars($aUrl).'"'.$name.'>'.$icon.'</a>';
00501 } else {
00502 return $icon;
00503 }
00504 }
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515 function wrapTitle($title,$row,$bank=0) {
00516 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'\','.$bank.');';
00517 return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$title.'</a>';
00518 }
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528 function wrapIcon($icon,$row) {
00529 return $icon;
00530 }
00531
00532
00533
00534
00535
00536
00537
00538
00539 function addTagAttributes($icon,$attr) {
00540 return ereg_replace(' ?\/?>$','',$icon).' '.$attr.' />';
00541 }
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551 function wrapStop($str,$row) {
00552 if ($row['php_tree_stop']) {
00553 $str.='<span class="typo3-red">+ </span>';
00554 }
00555 return $str;
00556 }
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579 function expandNext($id) {
00580 return ($this->stored[$this->bank][$id] || $this->expandAll)? 1 : 0;
00581 }
00582
00583
00584
00585
00586
00587
00588
00589 function initializePositionSaving() {
00590
00591 $this->stored=unserialize($this->BE_USER->uc['browseTrees'][$this->treeName]);
00592
00593
00594
00595 $PM = explode('_',t3lib_div::_GP('PM'));
00596 if (count($PM)==4 && $PM[3]==$this->treeName) {
00597 if (isset($this->MOUNTS[$PM[0]])) {
00598 if ($PM[1]) {
00599 $this->stored[$PM[0]][$PM[2]]=1;
00600 $this->savePosition();
00601 } else {
00602 unset($this->stored[$PM[0]][$PM[2]]);
00603 $this->savePosition();
00604 }
00605 }
00606 }
00607 }
00608
00609
00610
00611
00612
00613
00614
00615
00616 function savePosition() {
00617 $this->BE_USER->uc['browseTrees'][$this->treeName] = serialize($this->stored);
00618 $this->BE_USER->writeUC();
00619 }
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645 function getRootIcon($rec) {
00646 return $this->wrapIcon('<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/i/_icon_website.gif','width="18" height="16"').' alt="" />',$rec);
00647 }
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658 function getIcon($row) {
00659 if ($this->iconPath && $this->iconName) {
00660 $icon = '<img'.t3lib_iconWorks::skinImg('',$this->iconPath.$this->iconName,'width="18" height="16"').' alt=""'.($this->showDefaultTitleAttribute ? ' title="UID: '.$row['uid'].'"':'').' />';
00661 } else {
00662 $icon = t3lib_iconWorks::getIconImage($this->table,$row,$this->backPath,'align="top" class="c-recIcon"'.($this->showDefaultTitleAttribute ? ' title="UID: '.$row['uid'].'"':''));
00663 }
00664
00665 return $this->wrapIcon($icon,$row);
00666 }
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677 function getTitleStr($row,$titleLen=30) {
00678 if ($this->ext_showNavTitle && strlen(trim($row['nav_title'])) > 0) {
00679 $title = '<span title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_tca.xml:title',1).' '.htmlspecialchars(trim($row['title'])).'">'.htmlspecialchars(t3lib_div::fixed_lgd_cs($row['nav_title'],$titleLen)).'</span>';
00680 } else {
00681 $title = htmlspecialchars(t3lib_div::fixed_lgd_cs($row['title'],$titleLen));
00682 if (strlen(trim($row['nav_title'])) > 0) {
00683 $title = '<span title="'.$GLOBALS['LANG']->sL('LLL:EXT:cms/locallang_tca.xml:pages.nav_title',1).' '.htmlspecialchars(trim($row['nav_title'])).'">'.$title.'</span>';
00684 }
00685 $title = (strlen(trim($row['title'])) == 0) ? '<em>['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title',1).']</em>' : $title;
00686 }
00687
00688 return $title;
00689 }
00690
00691
00692
00693
00694
00695
00696
00697
00698 function getTitleAttrib($row) {
00699 return htmlspecialchars($row['title']);
00700 }
00701
00702
00703
00704
00705
00706
00707
00708 function getId($row) {
00709 return $row['uid'];
00710 }
00711
00712
00713
00714
00715
00716
00717
00718 function getJumpToParam($row) {
00719 return $this->getId($row);
00720 }
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752 function getTree($uid, $depth=999, $depthData='',$blankLineCode='',$subCSSclass='') {
00753
00754
00755 $this->buffer_idH=array();
00756
00757
00758 $depth=intval($depth);
00759 $HTML='';
00760 $a=0;
00761
00762 $res = $this->getDataInit($uid,$subCSSclass);
00763 $c = $this->getDataCount($res);
00764 $crazyRecursionLimiter = 999;
00765
00766
00767 while ($crazyRecursionLimiter>0 && $row = $this->getDataNext($res,$subCSSclass)) {
00768 $a++;
00769 $crazyRecursionLimiter--;
00770
00771 $newID = $row['uid'];
00772
00773 if ($newID==0) {
00774 t3lib_BEfunc::typo3PrintError ('Endless recursion detected', 'TYPO3 has detected an error in the database. Please fix it manually (e.g. using phpMyAdmin) and change the UID of '.$this->table.':0 to a new value.<br /><br />See <a href="http://bugs.typo3.org/view.php?id=3495" target="_blank">bugs.typo3.org/view.php?id=3495</a> to get more information about a possible cause.',0);
00775 exit;
00776 }
00777
00778 $this->tree[]=array();
00779 end($this->tree);
00780 $treeKey = key($this->tree);
00781 $LN = ($a==$c)?'blank':'line';
00782
00783
00784 if ($this->setRecs) {
00785 $this->recs[$row['uid']] = $row;
00786 }
00787
00788
00789 $this->ids[] = $idH[$row['uid']]['uid'] = $row['uid'];
00790 $this->ids_hierarchy[$depth][] = $row['uid'];
00791 $this->orig_ids_hierarchy[$depth][] = $row['_ORIG_uid'] ? $row['_ORIG_uid'] : $row['uid'];
00792
00793
00794 $HTML_depthData = $depthData.'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$LN.'.gif','width="18" height="16"').' alt="" />';
00795 if ($depth>1 && $this->expandNext($newID) && !$row['php_tree_stop']) {
00796 $nextCount=$this->getTree(
00797 $newID,
00798 $depth-1,
00799 $this->makeHTML ? $HTML_depthData : '',
00800 $blankLineCode.','.$LN,
00801 $row['_SUBCSSCLASS']
00802 );
00803 if (count($this->buffer_idH)) $idH[$row['uid']]['subrow']=$this->buffer_idH;
00804 $exp=1;
00805 } else {
00806 $nextCount=$this->getCount($newID);
00807 $exp=0;
00808 }
00809
00810
00811 if ($this->makeHTML) {
00812 $HTML = $depthData.$this->PMicon($row,$a,$c,$nextCount,$exp);
00813 $HTML.=$this->wrapStop($this->getIcon($row),$row);
00814 # $HTML.=$this->wrapStop($this->wrapIcon($this->getIcon($row),$row),$row);
00815 }
00816
00817
00818 $this->tree[$treeKey] = Array(
00819 'row'=>$row,
00820 'HTML'=>$HTML,
00821 'HTML_depthData' => $this->makeHTML==2 ? $HTML_depthData : '',
00822 'invertedDepth'=>$depth,
00823 'blankLineCode'=>$blankLineCode,
00824 'bank' => $this->bank
00825 );
00826 }
00827
00828 $this->getDataFree($res);
00829 $this->buffer_idH=$idH;
00830 return $c;
00831 }
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858 function getCount($uid) {
00859 if (is_array($this->data)) {
00860 $res = $this->getDataInit($uid);
00861 return $this->getDataCount($res);
00862 } else {
00863 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00864 'count(*)',
00865 $this->table,
00866 $this->parentField.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($uid, $this->table).
00867 t3lib_BEfunc::deleteClause($this->table).
00868 t3lib_BEfunc::versioningPlaceholderClause($this->table).
00869 $this->clause
00870 );
00871 $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00872 return $row[0];
00873 }
00874 }
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884 function getRootRecord($uid) {
00885 return array('title' => $this->title, 'uid' => 0);
00886 }
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897 function getRecord($uid) {
00898 if (is_array($this->data)) {
00899 return $this->dataLookup[$uid];
00900 } else {
00901 return t3lib_BEfunc::getRecordWSOL($this->table, $uid);
00902 }
00903 }
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915 function getDataInit($parentId,$subCSSclass='') {
00916 if (is_array($this->data)) {
00917 if (!is_array($this->dataLookup[$parentId][$this->subLevelID])) {
00918 $parentId = -1;
00919 } else {
00920 reset($this->dataLookup[$parentId][$this->subLevelID]);
00921 }
00922 return $parentId;
00923 } else {
00924 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00925 implode(',',$this->fieldArray),
00926 $this->table,
00927 $this->parentField.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($parentId, $this->table).
00928 t3lib_BEfunc::deleteClause($this->table).
00929 t3lib_BEfunc::versioningPlaceholderClause($this->table).
00930 $this->clause,
00931 '',
00932 $this->orderByFields
00933 );
00934 return $res;
00935 }
00936 }
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946 function getDataCount(&$res) {
00947 if (is_array($this->data)) {
00948 return count($this->dataLookup[$res][$this->subLevelID]);
00949 } else {
00950 $c = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
00951 return $c;
00952 }
00953 }
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964 function getDataNext(&$res,$subCSSclass='') {
00965 if (is_array($this->data)) {
00966 if ($res<0) {
00967 $row=FALSE;
00968 } else {
00969 list(,$row) = each($this->dataLookup[$res][$this->subLevelID]);
00970
00971
00972 if (is_array($row) && $subCSSclass!=='') {
00973 $row['_CSSCLASS'] = $row['_SUBCSSCLASS'] = $subCSSclass;
00974 }
00975 }
00976 return $row;
00977 } else {
00978 while($row = @$GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00979 t3lib_BEfunc::workspaceOL($this->table, $row, $this->BE_USER->workspace, TRUE);
00980 if (is_array($row)) break;
00981 }
00982
00983
00984 if (is_array($row) && $subCSSclass!=='') {
00985
00986 if ($this->table==='pages' && $this->highlightPagesWithVersions && !isset($row['_CSSCLASS']) && count(t3lib_BEfunc::countVersionsOfRecordsOnPage($this->BE_USER->workspace, $row['uid'], TRUE))) {
00987 $row['_CSSCLASS'] = 'ver-versions';
00988 }
00989
00990 if (!isset($row['_CSSCLASS'])) $row['_CSSCLASS'] = $subCSSclass;
00991 if (!isset($row['_SUBCSSCLASS'])) $row['_SUBCSSCLASS'] = $subCSSclass;
00992 }
00993
00994 return $row;
00995 }
00996 }
00997
00998
00999
01000
01001
01002
01003
01004
01005 function getDataFree(&$res) {
01006 if (!is_array($this->data)) {
01007 $GLOBALS['TYPO3_DB']->sql_free_result($res);
01008 }
01009 }
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023 function setDataFromArray(&$dataArr,$traverse=FALSE,$pid=0) {
01024 if (!$traverse) {
01025 $this->data = &$dataArr;
01026 $this->dataLookup=array();
01027
01028 $this->dataLookup[0][$this->subLevelID]=&$dataArr;
01029 }
01030
01031 foreach($dataArr as $uid => $val) {
01032
01033 $dataArr[$uid]['uid']=$uid;
01034 $dataArr[$uid]['pid']=$pid;
01035
01036
01037 $this->dataLookup[$uid] = &$dataArr[$uid];
01038
01039 if (is_array($val[$this->subLevelID])) {
01040 $this->setDataFromArray($dataArr[$uid][$this->subLevelID],TRUE,$uid);
01041 }
01042 }
01043 }
01044
01045
01046
01047
01048
01049
01050
01051
01052 function setDataFromTreeArray(&$treeArr, &$treeLookupArr) {
01053 $this->data = &$treeArr;
01054 $this->dataLookup=&$treeLookupArr;
01055 }
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094 }
01095
01096
01097 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_treeview.php']) {
01098 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_treeview.php']);
01099 }
01100
01101 ?>