Documentation TYPO3 par Ameos

class.webpagetree.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
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; // Indicates, whether the ajax call was successful, i.e. the requested page has been found
00077 
00083         function webPageTree() {
00084                 $this->init();
00085         }
00086 
00094         function wrapIcon($icon,&$row)  {
00095                         // If the record is locked, present a warning sign.
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                         // Add title attribute to input icon tag
00104                 $thePageIcon = $this->addTagAttributes($icon, $this->titleAttrib.'="'.$this->getTitleAttrib($row).'"');
00105 
00106                         // Wrap icon in click-menu link.
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                         // Wrap icon in a drag/drop span.
00115                 $dragDropIcon = '<span class="dragIcon" id="dragIconID_'.$row['uid'].'">'.$thePageIcon.'</span>';
00116 
00117                         // Add Page ID:
00118                 $pageIdStr = '';
00119                 if ($this->ext_showPageId) { $pageIdStr = '['.$row['uid'].']&nbsp;'; }
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                         // Wrap title in a drag/drop span.
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                         // -- evaluate AJAX request
00177                         // IE takes anchor as parameter
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; // We don't know yet. Will be set later.
00186                                 $doExpand = true;
00187                         } else  {
00188                                 $collapsedPageUid = $PM[2];
00189                                 $doCollapse = true;
00190                         }
00191                 }
00192 
00193                 // we need to count the opened <ul>'s every time we dig into another level, 
00194                 // so we know how many we have to close when all children are done rendering
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                         // if this item is the start of a new level, 
00204                         // then a new level <ul> is needed, but not in ajax mode
00205                         if($v['isFirst'] && !($doCollapse) && !($doExpand && $expandedPageUid == $uid)) {
00206                                 $itemHTML = '<ul>';
00207                         }
00208 
00209                         // add CSS classes to the list item
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                         // we have to remember if this is the last one
00222                         // on level X so the last child on level X+1 closes the <ul>-tag
00223                         if($v['isLast'] && !($doExpand && $expandedPageUid == $uid)) { $closeDepth[$v['invertedDepth']] = 1; }
00224 
00225 
00226                         // if this is the last one and does not have subitems, we need to close
00227                         // the tree as long as the upper levels have last items too
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                         // ajax request: collapse
00236                         if($doCollapse && $collapsedPageUid == $uid) {
00237                                 $this->ajaxStatus = true;
00238                                 return $itemHTML;
00239                         }
00240 
00241                         // ajax request: expand
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                 // finally close the first ul
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                                 // activate dynamic ajax-based tree
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                         // Get stored tree structure AND updating it if needed according to incoming PM GET var.
00321                 $this->initializePositionSaving();
00322 
00323                         // Init done:
00324                 $titleLen = intval($this->BE_USER->uc['titleLen']);
00325                 $treeArr = array();
00326                 
00327                         // Traverse mounts:
00328                 foreach($this->MOUNTS as $idx => $uid)  {
00329 
00330                                 // Set first:
00331                         $this->bank = $idx;
00332                         $isOpen = $this->stored[$idx][$uid] || $this->expandFirst;
00333 
00334                                 // Save ids while resetting everything else.
00335                         $curIds = $this->ids;
00336                         $this->reset();
00337                         $this->ids = $curIds;
00338 
00339                                 // Set PM icon for root of mount:
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                                 // Preparing rootRec for the mount
00345                         if ($uid)   {
00346                                 $rootRec = $this->getRecord($uid);
00347                                 $firstHtml.=$this->getIcon($rootRec);
00348                         } else {
00349                                 // Artificial record for the tree root, id=0
00350                                 $rootRec = $this->getRootRecord($uid);
00351                                 $firstHtml.=$this->getRootIcon($rootRec);
00352                         }
00353 
00354                         if (is_array($rootRec)) {
00355                                         // In case it was swapped inside getRecord due to workspaces.
00356                                 $uid = $rootRec['uid'];
00357 
00358                                         // Add the root of the mount to ->tree
00359                                 $this->tree[] = array('HTML'=>$firstHtml, 'row'=>$rootRec, 'bank'=>$this->bank, 'hasSub'=>true, 'invertedDepth'=>1000);
00360 
00361                                         // If the mount is expanded, go down:
00362                                 if ($isOpen)    {
00363                                                 // Set depth:
00364                                         if ($this->addSelfId) { $this->ids[] = $uid; }
00365                                         $this->getTree($uid, 999, '', $rootRec['_SUBCSSCLASS']);
00366                                 }
00367                                         // Add tree:
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                         // Buffer for id hierarchy is reset:
00386                 $this->buffer_idH = array();
00387 
00388                         // Init vars
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                         // Traverse the records:
00398                 while ($crazyRecursionLimiter > 0 && $row = $this->getDataNext($res,$subCSSclass))      {
00399                         $a++;
00400                         $crazyRecursionLimiter--;
00401                         
00402                         $newID = $row['uid'];
00403                         $this->tree[]=array();    // Reserve space.
00404                         end($this->tree);
00405                         $treeKey = key($this->tree);    // Get the key for this space
00406                         $LN = ($a==$c) ? 'blank' : 'line';
00407 
00408                                 // If records should be accumulated, do so
00409                         if ($this->setRecs) { $this->recs[$row['uid']] = $row; }
00410 
00411                                 // Accumulate the id of the element in the internal arrays
00412                         $this->ids[]=$idH[$row['uid']]['uid'] = $row['uid'];
00413                         $this->ids_hierarchy[$depth][] = $row['uid'];
00414 
00415                                 // Make a recursive call to the next level
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; // Set "did expand" flag
00425                         } else {
00426                                 $nextCount = $this->getCount($newID);
00427                                 $exp = 0; // Clear "did expand" flag
00428                         }
00429 
00430                                 // Set HTML-icons, if any:
00431                         if ($this->makeHTML)    {
00432                                 $HTML = $this->PMicon($row,$a,$c,$nextCount,$exp);
00433                                 $HTML.= $this->wrapStop($this->getIcon($row),$row);
00434                         }
00435 
00436                                 // Finally, add the row/HTML content to the ->tree array in the reserved key.
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 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6