|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2011 Kasper Skårhøj (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 ***************************************************************/ 00027 /** 00028 * Contains base class for creating a browsable array/page/folder tree in HTML 00029 * 00030 * $Id: class.t3lib_treeview.php 10121 2011-01-18 20:15:30Z ohader $ 00031 * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj 00032 * 00033 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00034 * @coauthor René Fritz <r.fritz@colorcube.de> 00035 */ 00036 /** 00037 * [CLASS/FUNCTION INDEX of SCRIPT] 00038 * 00039 * 00040 * 00041 * 115: class t3lib_treeView 00042 * 270: function init($clause='', $orderByFields='') 00043 * 301: function setTreeName($treeName='') 00044 * 315: function addField($field,$noCheck=0) 00045 * 329: function reset() 00046 * 00047 * SECTION: output 00048 * 349: function getBrowsableTree() 00049 * 412: function printTree($treeArr='') 00050 * 00051 * SECTION: rendering parts 00052 * 467: function PMicon($row,$a,$c,$nextCount,$exp) 00053 * 489: function PM_ATagWrap($icon,$cmd,$bMark='') 00054 * 511: function wrapTitle($title,$row,$bank=0) 00055 * 524: function wrapIcon($icon,$row) 00056 * 535: function addTagAttributes($icon,$attr) 00057 * 547: function wrapStop($str,$row) 00058 * 00059 * SECTION: tree handling 00060 * 575: function expandNext($id) 00061 * 585: function initializePositionSaving() 00062 * 612: function savePosition() 00063 * 00064 * SECTION: Functions that might be overwritten by extended classes 00065 * 641: function getRootIcon($rec) 00066 * 654: function getIcon($row) 00067 * 673: function getTitleStr($row,$titleLen=30) 00068 * 685: function getTitleAttrib($row) 00069 * 695: function getId($row) 00070 * 705: function getJumpToParam($row) 00071 * 00072 * SECTION: tree data buidling 00073 * 739: function getTree($uid, $depth=999, $depthData='',$blankLineCode='',$subCSSclass='') 00074 * 00075 * SECTION: Data handling 00076 * 839: function getCount($uid) 00077 * 865: function getRootRecord($uid) 00078 * 878: function getRecord($uid) 00079 * 898: function getDataInit($parentId,$subCSSclass='') 00080 * 929: function getDataCount(&$res) 00081 * 947: function getDataNext(&$res,$subCSSclass='') 00082 * 986: function getDataFree(&$res) 00083 * 1006: function setDataFromArray(&$dataArr,$traverse=FALSE,$pid=0) 00084 * 1035: function setDataFromTreeArray(&$treeArr, &$treeLookupArr) 00085 * 00086 * TOTAL FUNCTIONS: 31 00087 * (This index is automatically created/updated by the extension "extdeveval") 00088 * 00089 */ 00090 00091 00092 /** 00093 * Base class for creating a browsable array/page/folder tree in HTML 00094 * 00095 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00096 * @coauthor René Fritz <r.fritz@colorcube.de> 00097 * @package TYPO3 00098 * @subpackage t3lib 00099 * @see t3lib_browsetree, t3lib_pagetree, t3lib_foldertree 00100 */ 00101 class t3lib_treeView { 00102 00103 // EXTERNAL, static: 00104 var $expandFirst = 0; // If set, the first element in the tree is always expanded. 00105 var $expandAll = 0; // If set, then ALL items will be expanded, regardless of stored settings. 00106 var $thisScript = ''; // Holds the current script to reload to. 00107 var $titleAttrib = 'title'; // Which HTML attribute to use: alt/title. See init(). 00108 var $ext_IconMode = FALSE; // If true, no context menu is rendered on icons. If set to "titlelink" the icon is linked as the title is. 00109 var $addSelfId = 0; // If set, the id of the mounts will be added to the internal ids array 00110 var $title = 'no title'; // Used if the tree is made of records (not folders for ex.) 00111 var $showDefaultTitleAttribute = FALSE; // If true, a default title attribute showing the UID of the record is shown. This cannot be enabled by default because it will destroy many applications where another title attribute is in fact applied later. 00112 var $highlightPagesWithVersions = TRUE; // If true, pages containing child records which has versions will be highlighted in yellow. This might be too expensive in terms of processing power. 00113 00114 /** 00115 * Needs to be initialized with $GLOBALS['BE_USER'] 00116 * Done by default in init() 00117 * 00118 * @var t3lib_beUserAuth 00119 */ 00120 var $BE_USER = ''; 00121 00122 /** 00123 * Needs to be initialized with e.g. $GLOBALS['WEBMOUNTS'] 00124 * Default setting in init() is 0 => 0 00125 * The keys are mount-ids (can be anything basically) and the values are the ID of the root element (COULD be zero or anything else. For pages that would be the uid of the page, zero for the pagetree root.) 00126 */ 00127 var $MOUNTS = ''; 00128 00129 00130 /** 00131 * Database table to get the tree data from. 00132 * Leave blank if data comes from an array. 00133 */ 00134 var $table = ''; 00135 00136 /** 00137 * Defines the field of $table which is the parent id field (like pid for table pages). 00138 */ 00139 var $parentField = 'pid'; 00140 00141 /** 00142 * WHERE clause used for selecting records for the tree. Is set by function init. 00143 * Only makes sense when $this->table is set. 00144 * @see init() 00145 */ 00146 var $clause = ''; 00147 00148 /** 00149 * Field for ORDER BY. Is set by function init. 00150 * Only makes sense when $this->table is set. 00151 * @see init() 00152 */ 00153 var $orderByFields = ''; 00154 00155 /** 00156 * Default set of fields selected from the tree table. 00157 * Make SURE that these fields names listed herein are actually possible to select from $this->table (if that variable is set to a TCA table name) 00158 * @see addField() 00159 */ 00160 var $fieldArray = array('uid', 'title'); 00161 00162 /** 00163 * List of other fields which are ALLOWED to set (here, based on the "pages" table!) 00164 * @see addField() 00165 */ 00166 var $defaultList = 'uid,pid,tstamp,sorting,deleted,perms_userid,perms_groupid,perms_user,perms_group,perms_everybody,crdate,cruser_id'; 00167 00168 00169 /** 00170 * Unique name for the tree. 00171 * Used as key for storing the tree into the BE users settings. 00172 * Used as key to pass parameters in links. 00173 * MUST NOT contain underscore chars. 00174 * etc. 00175 */ 00176 var $treeName = ''; 00177 00178 /** 00179 * A prefix for table cell id's which will be wrapped around an item. 00180 * Can be used for highlighting by JavaScript. 00181 * Needs to be unique if multiple trees are on one HTML page. 00182 * @see printTree() 00183 */ 00184 var $domIdPrefix = 'row'; 00185 00186 /** 00187 * Back path for icons 00188 */ 00189 var $backPath; 00190 00191 /** 00192 * Icon file path. 00193 */ 00194 var $iconPath = ''; 00195 00196 00197 /** 00198 * Icon file name for item icons. 00199 */ 00200 var $iconName = 'default.gif'; 00201 00202 /** 00203 * If true, HTML code is also accumulated in ->tree array during rendering of the tree. 00204 * If 2, then also the icon prefix code (depthData) is stored 00205 */ 00206 var $makeHTML = 1; 00207 00208 /** 00209 * If true, records as selected will be stored internally in the ->recs array 00210 */ 00211 var $setRecs = 0; 00212 00213 /** 00214 * Sets the associative array key which identifies a new sublevel if arrays are used for trees. 00215 * This value has formerly been "subLevel" and "--sublevel--" 00216 */ 00217 var $subLevelID = '_SUB_LEVEL'; 00218 00219 00220 // ********* 00221 // Internal 00222 // ********* 00223 // For record trees: 00224 var $ids = array(); // one-dim array of the uid's selected. 00225 var $ids_hierarchy = array(); // The hierarchy of element uids 00226 var $orig_ids_hierarchy = array(); // The hierarchy of versioned element uids 00227 var $buffer_idH = array(); // Temporary, internal array 00228 00229 // For FOLDER trees: 00230 var $specUIDmap = array(); // Special UIDs for folders (integer-hashes of paths) 00231 00232 // For arrays: 00233 var $data = FALSE; // Holds the input data array 00234 var $dataLookup = FALSE; // Holds an index with references to the data array. 00235 00236 // For both types 00237 var $tree = array(); // Tree is accumulated in this variable 00238 var $stored = array(); // Holds (session stored) information about which items in the tree are unfolded and which are not. 00239 var $bank = 0; // Points to the current mountpoint key 00240 var $recs = array(); // Accumulates the displayed records. 00241 00242 00243 /** 00244 * Initialize the tree class. Needs to be overwritten 00245 * Will set ->fieldsArray, ->backPath and ->clause 00246 * 00247 * @param string record WHERE clause 00248 * @param string record ORDER BY field 00249 * @return void 00250 */ 00251 function init($clause = '', $orderByFields = '') { 00252 $this->BE_USER = $GLOBALS['BE_USER']; // Setting BE_USER by default 00253 $this->titleAttrib = 'title'; // Setting title attribute to use. 00254 $this->backPath = $GLOBALS['BACK_PATH']; // Setting backpath. 00255 00256 if ($clause) { 00257 $this->clause = $clause; 00258 } // Setting clause 00259 if ($orderByFields) { 00260 $this->orderByFields = $orderByFields; 00261 } 00262 00263 if (!is_array($this->MOUNTS)) { 00264 $this->MOUNTS = array(0 => 0); // dummy 00265 } 00266 00267 $this->setTreeName(); 00268 00269 if ($this->table) { 00270 t3lib_div::loadTCA($this->table); 00271 } 00272 00273 // setting this to false disables the use of array-trees by default 00274 $this->data = FALSE; 00275 $this->dataLookup = FALSE; 00276 } 00277 00278 00279 /** 00280 * Sets the tree name which is used to identify the tree 00281 * Used for JavaScript and other things 00282 * 00283 * @param string Default is the table name. Underscores are stripped. 00284 * @return void 00285 */ 00286 function setTreeName($treeName = '') { 00287 $this->treeName = $treeName ? $treeName : $this->treeName; 00288 $this->treeName = $this->treeName ? $this->treeName : $this->table; 00289 $this->treeName = str_replace('_', '', $this->treeName); 00290 } 00291 00292 00293 /** 00294 * Adds a fieldname to the internal array ->fieldArray 00295 * 00296 * @param string Field name to 00297 * @param boolean If set, the fieldname will be set no matter what. Otherwise the field name must either be found as key in $TCA[$table]['columns'] or in the list ->defaultList 00298 * @return void 00299 */ 00300 function addField($field, $noCheck = 0) { 00301 global $TCA; 00302 if ($noCheck || is_array($TCA[$this->table]['columns'][$field]) || t3lib_div::inList($this->defaultList, $field)) { 00303 $this->fieldArray[] = $field; 00304 } 00305 } 00306 00307 00308 /** 00309 * Resets the tree, recs, ids, ids_hierarchy and orig_ids_hierarchy internal variables. Use it if you need it. 00310 * 00311 * @return void 00312 */ 00313 function reset() { 00314 $this->tree = array(); 00315 $this->recs = array(); 00316 $this->ids = array(); 00317 $this->ids_hierarchy = array(); 00318 $this->orig_ids_hierarchy = array(); 00319 } 00320 00321 00322 /******************************************* 00323 * 00324 * output 00325 * 00326 *******************************************/ 00327 00328 /** 00329 * Will create and return the HTML code for a browsable tree 00330 * Is based on the mounts found in the internal array ->MOUNTS (set in the constructor) 00331 * 00332 * @return string HTML code for the browsable tree 00333 */ 00334 function getBrowsableTree() { 00335 00336 // Get stored tree structure AND updating it if needed according to incoming PM GET var. 00337 $this->initializePositionSaving(); 00338 00339 // Init done: 00340 $titleLen = intval($this->BE_USER->uc['titleLen']); 00341 $treeArr = array(); 00342 00343 // Traverse mounts: 00344 foreach ($this->MOUNTS as $idx => $uid) { 00345 00346 // Set first: 00347 $this->bank = $idx; 00348 $isOpen = $this->stored[$idx][$uid] || $this->expandFirst; 00349 00350 // Save ids while resetting everything else. 00351 $curIds = $this->ids; 00352 $this->reset(); 00353 $this->ids = $curIds; 00354 00355 // Set PM icon for root of mount: 00356 $cmd = $this->bank . '_' . ($isOpen ? "0_" : "1_") . $uid . '_' . $this->treeName; 00357 $icon = '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/ol/' . ($isOpen ? 'minus' : 'plus') . 'only.gif', 'width="18" height="16"') . ' alt="" />'; 00358 $firstHtml = $this->PM_ATagWrap($icon, $cmd); 00359 00360 // Preparing rootRec for the mount 00361 if ($uid) { 00362 $rootRec = $this->getRecord($uid); 00363 $firstHtml .= $this->getIcon($rootRec); 00364 } else { 00365 // Artificial record for the tree root, id=0 00366 $rootRec = $this->getRootRecord($uid); 00367 $firstHtml .= $this->getRootIcon($rootRec); 00368 } 00369 00370 if (is_array($rootRec)) { 00371 $uid = $rootRec['uid']; // In case it was swapped inside getRecord due to workspaces. 00372 00373 // Add the root of the mount to ->tree 00374 $this->tree[] = array('HTML' => $firstHtml, 'row' => $rootRec, 'bank' => $this->bank); 00375 00376 // If the mount is expanded, go down: 00377 if ($isOpen) { 00378 // Set depth: 00379 $depthD = '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/ol/blank.gif', 'width="18" height="16"') . ' alt="" />'; 00380 if ($this->addSelfId) { 00381 $this->ids[] = $uid; 00382 } 00383 $this->getTree($uid, 999, $depthD, '', $rootRec['_SUBCSSCLASS']); 00384 } 00385 00386 // Add tree: 00387 $treeArr = array_merge($treeArr, $this->tree); 00388 } 00389 } 00390 return $this->printTree($treeArr); 00391 } 00392 00393 /** 00394 * Compiles the HTML code for displaying the structure found inside the ->tree array 00395 * 00396 * @param array "tree-array" - if blank string, the internal ->tree array is used. 00397 * @return string The HTML code for the tree 00398 */ 00399 function printTree($treeArr = '') { 00400 $titleLen = intval($this->BE_USER->uc['titleLen']); 00401 if (!is_array($treeArr)) { 00402 $treeArr = $this->tree; 00403 } 00404 $out = ''; 00405 00406 // put a table around it with IDs to access the rows from JS 00407 // not a problem if you don't need it 00408 // In XHTML there is no "name" attribute of <td> elements - but Mozilla will not be able to highlight rows if the name attribute is NOT there. 00409 $out .= ' 00410 00411 <!-- 00412 TYPO3 tree structure. 00413 --> 00414 <table cellpadding="0" cellspacing="0" border="0" id="typo3-tree">'; 00415 00416 foreach ($treeArr as $k => $v) { 00417 $idAttr = htmlspecialchars($this->domIdPrefix . $this->getId($v['row']) . '_' . $v['bank']); 00418 00419 $out .= ' 00420 <tr> 00421 <td id="' . $idAttr . '"' . 00422 ($v['row']['_CSSCLASS'] ? ' class="' . $v['row']['_CSSCLASS'] . '"' : '') . '>' . 00423 $v['HTML'] . 00424 $this->wrapTitle($this->getTitleStr($v['row'], $titleLen), $v['row'], $v['bank']) . 00425 '</td> 00426 </tr> 00427 '; 00428 } 00429 $out .= ' 00430 </table>'; 00431 return $out; 00432 } 00433 00434 00435 /******************************************* 00436 * 00437 * rendering parts 00438 * 00439 *******************************************/ 00440 00441 00442 /** 00443 * Generate the plus/minus icon for the browsable tree. 00444 * 00445 * @param array record for the entry 00446 * @param integer The current entry number 00447 * @param integer The total number of entries. If equal to $a, a "bottom" element is returned. 00448 * @param integer The number of sub-elements to the current element. 00449 * @param boolean The element was expanded to render subelements if this flag is set. 00450 * @return string Image tag with the plus/minus icon. 00451 * @access private 00452 * @see t3lib_pageTree::PMicon() 00453 */ 00454 function PMicon($row, $a, $c, $nextCount, $exp) { 00455 $PM = $nextCount ? ($exp ? 'minus' : 'plus') : 'join'; 00456 $BTM = ($a == $c) ? 'bottom' : ''; 00457 $icon = '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/ol/' . $PM . $BTM . '.gif', 'width="18" height="16"') . ' alt="" />'; 00458 00459 if ($nextCount) { 00460 $cmd = $this->bank . '_' . ($exp ? '0_' : '1_') . $row['uid'] . '_' . $this->treeName; 00461 $bMark = ($this->bank . '_' . $row['uid']); 00462 $icon = $this->PM_ATagWrap($icon, $cmd, $bMark); 00463 } 00464 return $icon; 00465 } 00466 00467 /** 00468 * Wrap the plus/minus icon in a link 00469 * 00470 * @param string HTML string to wrap, probably an image tag. 00471 * @param string Command for 'PM' get var 00472 * @param boolean If set, the link will have a anchor point (=$bMark) and a name attribute (=$bMark) 00473 * @return string Link-wrapped input string 00474 * @access private 00475 */ 00476 function PM_ATagWrap($icon, $cmd, $bMark = '') { 00477 if ($this->thisScript) { 00478 if ($bMark) { 00479 $anchor = '#' . $bMark; 00480 $name = ' name="' . $bMark . '"'; 00481 } 00482 $aUrl = $this->thisScript . '?PM=' . $cmd . $anchor; 00483 return '<a href="' . htmlspecialchars($aUrl) . '"' . $name . '>' . $icon . '</a>'; 00484 } else { 00485 return $icon; 00486 } 00487 } 00488 00489 /** 00490 * Wrapping $title in a-tags. 00491 * 00492 * @param string Title string 00493 * @param string Item record 00494 * @param integer Bank pointer (which mount point number) 00495 * @return string 00496 * @access private 00497 */ 00498 function wrapTitle($title, $row, $bank = 0) { 00499 $aOnClick = 'return jumpTo(\'' . $this->getJumpToParam($row) . '\',this,\'' . $this->domIdPrefix . $this->getId($row) . '\',' . $bank . ');'; 00500 return '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . $title . '</a>'; 00501 } 00502 00503 /** 00504 * Wrapping the image tag, $icon, for the row, $row (except for mount points) 00505 * 00506 * @param string The image tag for the icon 00507 * @param array The row for the current element 00508 * @return string The processed icon input value. 00509 * @access private 00510 */ 00511 function wrapIcon($icon, $row) { 00512 return $icon; 00513 } 00514 00515 /** 00516 * Adds attributes to image tag. 00517 * 00518 * @param string Icon image tag 00519 * @param string Attributes to add, eg. ' border="0"' 00520 * @return string Image tag, modified with $attr attributes added. 00521 */ 00522 function addTagAttributes($icon, $attr) { 00523 return preg_replace('/ ?\/?>$/', '', $icon) . ' ' . $attr . ' />'; 00524 } 00525 00526 /** 00527 * Adds a red "+" to the input string, $str, if the field "php_tree_stop" in the $row (pages) is set 00528 * 00529 * @param string Input string, like a page title for the tree 00530 * @param array record row with "php_tree_stop" field 00531 * @return string Modified string 00532 * @access private 00533 */ 00534 function wrapStop($str, $row) { 00535 if ($row['php_tree_stop']) { 00536 $str .= '<span class="typo3-red"><a href="' . htmlspecialchars(t3lib_div::linkThisScript(array('setTempDBmount' => $row['uid']))) . '" class="typo3-red">+</a> </span>'; 00537 } 00538 return $str; 00539 } 00540 00541 00542 /******************************************* 00543 * 00544 * tree handling 00545 * 00546 *******************************************/ 00547 00548 00549 /** 00550 * Returns true/false if the next level for $id should be expanded - based on data in $this->stored[][] and ->expandAll flag. 00551 * Extending parent function 00552 * 00553 * @param integer record id/key 00554 * @return boolean 00555 * @access private 00556 * @see t3lib_pageTree::expandNext() 00557 */ 00558 function expandNext($id) { 00559 return ($this->stored[$this->bank][$id] || $this->expandAll) ? 1 : 0; 00560 } 00561 00562 /** 00563 * Get stored tree structure AND updating it if needed according to incoming PM GET var. 00564 * 00565 * @return void 00566 * @access private 00567 */ 00568 function initializePositionSaving() { 00569 // Get stored tree structure: 00570 $this->stored = unserialize($this->BE_USER->uc['browseTrees'][$this->treeName]); 00571 00572 // PM action 00573 // (If an plus/minus icon has been clicked, the PM GET var is sent and we must update the stored positions in the tree): 00574 $PM = explode('_', t3lib_div::_GP('PM')); // 0: mount key, 1: set/clear boolean, 2: item ID (cannot contain "_"), 3: treeName 00575 if (count($PM) == 4 && $PM[3] == $this->treeName) { 00576 if (isset($this->MOUNTS[$PM[0]])) { 00577 if ($PM[1]) { // set 00578 $this->stored[$PM[0]][$PM[2]] = 1; 00579 $this->savePosition(); 00580 } else { // clear 00581 unset($this->stored[$PM[0]][$PM[2]]); 00582 $this->savePosition(); 00583 } 00584 } 00585 } 00586 } 00587 00588 /** 00589 * Saves the content of ->stored (keeps track of expanded positions in the tree) 00590 * $this->treeName will be used as key for BE_USER->uc[] to store it in 00591 * 00592 * @return void 00593 * @access private 00594 */ 00595 function savePosition() { 00596 $this->BE_USER->uc['browseTrees'][$this->treeName] = serialize($this->stored); 00597 $this->BE_USER->writeUC(); 00598 } 00599 00600 00601 /****************************** 00602 * 00603 * Functions that might be overwritten by extended classes 00604 * 00605 ********************************/ 00606 00607 /** 00608 * Returns the root icon for a tree/mountpoint (defaults to the globe) 00609 * 00610 * @param array Record for root. 00611 * @return string Icon image tag. 00612 */ 00613 function getRootIcon($rec) { 00614 return $this->wrapIcon(t3lib_iconWorks::getSpriteIcon('apps-pagetree-root'), $rec); 00615 } 00616 00617 00618 /** 00619 * Get icon for the row. 00620 * If $this->iconPath and $this->iconName is set, try to get icon based on those values. 00621 * 00622 * @param array Item row. 00623 * @return string Image tag. 00624 */ 00625 function getIcon($row) { 00626 if ($this->iconPath && $this->iconName) { 00627 $icon = '<img' . t3lib_iconWorks::skinImg('', $this->iconPath . $this->iconName, 'width="18" height="16"') . ' alt=""' . ($this->showDefaultTitleAttribute ? ' title="UID: ' . $row['uid'] . '"' : '') . ' />'; 00628 } else { 00629 00630 $icon = t3lib_iconWorks::getSpriteIconForRecord($this->table, $row, array( 00631 'title' => ($this->showDefaultTitleAttribute ? 'UID: ' . $row['uid'] : $this->getTitleAttrib($row)), 00632 'class' => 'c-recIcon' 00633 )); 00634 00635 } 00636 00637 return $this->wrapIcon($icon, $row); 00638 } 00639 00640 00641 /** 00642 * Returns the title for the input record. If blank, a "no title" label (localized) will be returned. 00643 * Do NOT htmlspecialchar the string from this function - has already been done. 00644 * 00645 * @param array The input row array (where the key "title" is used for the title) 00646 * @param integer Title length (30) 00647 * @return string The title. 00648 */ 00649 function getTitleStr($row, $titleLen = 30) { 00650 if ($this->ext_showNavTitle && strlen(trim($row['nav_title'])) > 0) { 00651 $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>'; 00652 } else { 00653 $title = htmlspecialchars(t3lib_div::fixed_lgd_cs($row['title'], $titleLen)); 00654 if (strlen(trim($row['nav_title'])) > 0) { 00655 $title = '<span title="' . $GLOBALS['LANG']->sL('LLL:EXT:cms/locallang_tca.xml:pages.nav_title', 1) . ' ' . htmlspecialchars(trim($row['nav_title'])) . '">' . $title . '</span>'; 00656 } 00657 $title = (strlen(trim($row['title'])) == 0) ? '<em>[' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title', 1) . ']</em>' : $title; 00658 } 00659 00660 return $title; 00661 } 00662 00663 /** 00664 * Returns the value for the image "title" attribute 00665 * 00666 * @param array The input row array (where the key "title" is used for the title) 00667 * @return string The attribute value (is htmlspecialchared() already) 00668 * @see wrapIcon() 00669 */ 00670 function getTitleAttrib($row) { 00671 return htmlspecialchars($row['title']); 00672 } 00673 00674 /** 00675 * Returns the id from the record (typ. uid) 00676 * 00677 * @param array Record array 00678 * @return integer The "uid" field value. 00679 */ 00680 function getId($row) { 00681 return $row['uid']; 00682 } 00683 00684 /** 00685 * Returns jump-url parameter value. 00686 * 00687 * @param array The record array. 00688 * @return string The jump-url parameter. 00689 */ 00690 function getJumpToParam($row) { 00691 return $this->getId($row); 00692 } 00693 00694 00695 /******************************** 00696 * 00697 * tree data buidling 00698 * 00699 ********************************/ 00700 00701 /** 00702 * Fetches the data for the tree 00703 * 00704 * @param integer item id for which to select subitems (parent id) 00705 * @param integer Max depth (recursivity limit) 00706 * @param string HTML-code prefix for recursive calls. 00707 * @param string ? (internal) 00708 * @param string CSS class to use for <td> sub-elements 00709 * @return integer The count of items on the level 00710 */ 00711 function getTree($uid, $depth = 999, $depthData = '', $blankLineCode = '', $subCSSclass = '') { 00712 00713 // Buffer for id hierarchy is reset: 00714 $this->buffer_idH = array(); 00715 00716 // Init vars 00717 $depth = intval($depth); 00718 $HTML = ''; 00719 $a = 0; 00720 00721 $res = $this->getDataInit($uid, $subCSSclass); 00722 $c = $this->getDataCount($res); 00723 $crazyRecursionLimiter = 999; 00724 00725 $idH = array(); 00726 00727 // Traverse the records: 00728 while ($crazyRecursionLimiter > 0 && $row = $this->getDataNext($res, $subCSSclass)) { 00729 $a++; 00730 $crazyRecursionLimiter--; 00731 00732 $newID = $row['uid']; 00733 00734 if ($newID == 0) { 00735 throw new RuntimeException('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.'); 00736 } 00737 00738 $this->tree[] = array(); // Reserve space. 00739 end($this->tree); 00740 $treeKey = key($this->tree); // Get the key for this space 00741 $LN = ($a == $c) ? 'blank' : 'line'; 00742 00743 // If records should be accumulated, do so 00744 if ($this->setRecs) { 00745 $this->recs[$row['uid']] = $row; 00746 } 00747 00748 // Accumulate the id of the element in the internal arrays 00749 $this->ids[] = $idH[$row['uid']]['uid'] = $row['uid']; 00750 $this->ids_hierarchy[$depth][] = $row['uid']; 00751 $this->orig_ids_hierarchy[$depth][] = $row['_ORIG_uid'] ? $row['_ORIG_uid'] : $row['uid']; 00752 00753 // Make a recursive call to the next level 00754 $HTML_depthData = $depthData . '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/ol/' . $LN . '.gif', 'width="18" height="16"') . ' alt="" />'; 00755 if ($depth > 1 && $this->expandNext($newID) && !$row['php_tree_stop']) { 00756 $nextCount = $this->getTree( 00757 $newID, 00758 $depth - 1, 00759 $this->makeHTML ? $HTML_depthData : '', 00760 $blankLineCode . ',' . $LN, 00761 $row['_SUBCSSCLASS'] 00762 ); 00763 if (count($this->buffer_idH)) { 00764 $idH[$row['uid']]['subrow'] = $this->buffer_idH; 00765 } 00766 $exp = 1; // Set "did expand" flag 00767 } else { 00768 $nextCount = $this->getCount($newID); 00769 $exp = 0; // Clear "did expand" flag 00770 } 00771 00772 // Set HTML-icons, if any: 00773 if ($this->makeHTML) { 00774 $HTML = $depthData . $this->PMicon($row, $a, $c, $nextCount, $exp); 00775 $HTML .= $this->wrapStop($this->getIcon($row), $row); 00776 # $HTML.=$this->wrapStop($this->wrapIcon($this->getIcon($row),$row),$row); 00777 } 00778 00779 // Finally, add the row/HTML content to the ->tree array in the reserved key. 00780 $this->tree[$treeKey] = array( 00781 'row' => $row, 00782 'HTML' => $HTML, 00783 'HTML_depthData' => $this->makeHTML == 2 ? $HTML_depthData : '', 00784 'invertedDepth' => $depth, 00785 'blankLineCode' => $blankLineCode, 00786 'bank' => $this->bank 00787 ); 00788 } 00789 00790 $this->getDataFree($res); 00791 $this->buffer_idH = $idH; 00792 return $c; 00793 } 00794 00795 00796 /******************************** 00797 * 00798 * Data handling 00799 * Works with records and arrays 00800 * 00801 ********************************/ 00802 00803 /** 00804 * Returns the number of records having the parent id, $uid 00805 * 00806 * @param integer id to count subitems for 00807 * @return integer 00808 * @access private 00809 */ 00810 function getCount($uid) { 00811 if (is_array($this->data)) { 00812 $res = $this->getDataInit($uid); 00813 return $this->getDataCount($res); 00814 } else { 00815 return $GLOBALS['TYPO3_DB']->exec_SELECTcountRows( 00816 'uid', 00817 $this->table, 00818 $this->parentField . '=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($uid, $this->table) . 00819 t3lib_BEfunc::deleteClause($this->table) . 00820 t3lib_BEfunc::versioningPlaceholderClause($this->table) . 00821 $this->clause // whereClauseMightContainGroupOrderBy 00822 ); 00823 } 00824 } 00825 00826 00827 /** 00828 * Returns root record for uid (<=0) 00829 * 00830 * @param integer uid, <= 0 (normally, this does not matter) 00831 * @return array Array with title/uid keys with values of $this->title/0 (zero) 00832 */ 00833 function getRootRecord($uid) { 00834 return array('title' => $this->title, 'uid' => 0); 00835 } 00836 00837 00838 /** 00839 * Returns the record for a uid. 00840 * For tables: Looks up the record in the database. 00841 * For arrays: Returns the fake record for uid id. 00842 * 00843 * @param integer UID to look up 00844 * @return array The record 00845 */ 00846 function getRecord($uid) { 00847 if (is_array($this->data)) { 00848 return $this->dataLookup[$uid]; 00849 } else { 00850 return t3lib_BEfunc::getRecordWSOL($this->table, $uid); 00851 } 00852 } 00853 00854 /** 00855 * Getting the tree data: Selecting/Initializing data pointer to items for a certain parent id. 00856 * For tables: This will make a database query to select all children to "parent" 00857 * For arrays: This will return key to the ->dataLookup array 00858 * 00859 * @param integer parent item id 00860 * @param string Class for sub-elements. 00861 * @return mixed data handle (Tables: An sql-resource, arrays: A parentId integer. -1 is returned if there were NO subLevel.) 00862 * @access private 00863 */ 00864 function getDataInit($parentId, $subCSSclass = '') { 00865 if (is_array($this->data)) { 00866 if (!is_array($this->dataLookup[$parentId][$this->subLevelID])) { 00867 $parentId = -1; 00868 } else { 00869 reset($this->dataLookup[$parentId][$this->subLevelID]); 00870 } 00871 return $parentId; 00872 } else { 00873 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 00874 implode(',', $this->fieldArray), 00875 $this->table, 00876 $this->parentField . '=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($parentId, $this->table) . 00877 t3lib_BEfunc::deleteClause($this->table) . 00878 t3lib_BEfunc::versioningPlaceholderClause($this->table) . 00879 $this->clause, // whereClauseMightContainGroupOrderBy 00880 '', 00881 $this->orderByFields 00882 ); 00883 return $res; 00884 } 00885 } 00886 00887 /** 00888 * Getting the tree data: Counting elements in resource 00889 * 00890 * @param mixed data handle 00891 * @return integer number of items 00892 * @access private 00893 * @see getDataInit() 00894 */ 00895 function getDataCount(&$res) { 00896 if (is_array($this->data)) { 00897 return count($this->dataLookup[$res][$this->subLevelID]); 00898 } else { 00899 $c = $GLOBALS['TYPO3_DB']->sql_num_rows($res); 00900 return $c; 00901 } 00902 } 00903 00904 /** 00905 * Getting the tree data: next entry 00906 * 00907 * @param mixed data handle 00908 * @param string CSS class for sub elements (workspace related) 00909 * @return array item data array OR FALSE if end of elements. 00910 * @access private 00911 * @see getDataInit() 00912 */ 00913 function getDataNext(&$res, $subCSSclass = '') { 00914 if (is_array($this->data)) { 00915 if ($res < 0) { 00916 $row = FALSE; 00917 } else { 00918 list(, $row) = each($this->dataLookup[$res][$this->subLevelID]); 00919 00920 // Passing on default <td> class for subelements: 00921 if (is_array($row) && $subCSSclass !== '') { 00922 $row['_CSSCLASS'] = $row['_SUBCSSCLASS'] = $subCSSclass; 00923 } 00924 } 00925 return $row; 00926 } else { 00927 while ($row = @$GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00928 t3lib_BEfunc::workspaceOL($this->table, $row, $this->BE_USER->workspace, TRUE); 00929 if (is_array($row)) { 00930 break; 00931 } 00932 } 00933 00934 // Passing on default <td> class for subelements: 00935 if (is_array($row) && $subCSSclass !== '') { 00936 00937 if ($this->table === 'pages' && $this->highlightPagesWithVersions && !isset($row['_CSSCLASS']) && count(t3lib_BEfunc::countVersionsOfRecordsOnPage($this->BE_USER->workspace, $row['uid'], TRUE))) { 00938 $row['_CSSCLASS'] = 'ver-versions'; 00939 } 00940 00941 if (!isset($row['_CSSCLASS'])) { 00942 $row['_CSSCLASS'] = $subCSSclass; 00943 } 00944 if (!isset($row['_SUBCSSCLASS'])) { 00945 $row['_SUBCSSCLASS'] = $subCSSclass; 00946 } 00947 } 00948 00949 return $row; 00950 } 00951 } 00952 00953 /** 00954 * Getting the tree data: frees data handle 00955 * 00956 * @param mixed data handle 00957 * @return void 00958 * @access private 00959 */ 00960 function getDataFree(&$res) { 00961 if (!is_array($this->data)) { 00962 $GLOBALS['TYPO3_DB']->sql_free_result($res); 00963 } 00964 } 00965 00966 /** 00967 * Used to initialize class with an array to browse. 00968 * The array inputted will be traversed and an internal index for lookup is created. 00969 * The keys of the input array are perceived as "uid"s of records which means that keys GLOBALLY must be unique like uids are. 00970 * "uid" and "pid" "fakefields" are also set in each record. 00971 * All other fields are optional. 00972 * 00973 * @param array The input array, see examples below in this script. 00974 * @param boolean Internal, for recursion. 00975 * @param integer Internal, for recursion. 00976 * @return void 00977 */ 00978 function setDataFromArray(&$dataArr, $traverse = FALSE, $pid = 0) { 00979 if (!$traverse) { 00980 $this->data = &$dataArr; 00981 $this->dataLookup = array(); 00982 // add root 00983 $this->dataLookup[0][$this->subLevelID] =& $dataArr; 00984 } 00985 00986 foreach ($dataArr as $uid => $val) { 00987 00988 $dataArr[$uid]['uid'] = $uid; 00989 $dataArr[$uid]['pid'] = $pid; 00990 00991 // gives quick access to id's 00992 $this->dataLookup[$uid] = &$dataArr[$uid]; 00993 00994 if (is_array($val[$this->subLevelID])) { 00995 $this->setDataFromArray($dataArr[$uid][$this->subLevelID], TRUE, $uid); 00996 } 00997 } 00998 } 00999 01000 /** 01001 * Sets the internal data arrays 01002 * 01003 * @param array Content for $this->data 01004 * @param array Content for $this->dataLookup 01005 * @return void 01006 */ 01007 function setDataFromTreeArray(&$treeArr, &$treeLookupArr) { 01008 $this->data = &$treeArr; 01009 $this->dataLookup =& $treeLookupArr; 01010 } 01011 01012 01013 /* 01014 array( 01015 [id1] => array( 01016 'title'=>'title...', 01017 'id' => 'id1', 01018 'icon' => 'icon ref, relative to typo3/ folder...' 01019 ), 01020 [id2] => array( 01021 'title'=>'title...', 01022 'id' => 'id2', 01023 'icon' => 'icon ref, relative to typo3/ folder...' 01024 ), 01025 [id3] => array( 01026 'title'=>'title...', 01027 'id' => 'id3', 01028 'icon' => 'icon ref, relative to typo3/ folder...' 01029 $this->subLevelID => array( 01030 [id3_asdf#1] => array( 01031 'title'=>'title...', 01032 'id' => 'asdf#1', 01033 'icon' => 'icon ref, relative to typo3/ folder...' 01034 ), 01035 [5] => array( 01036 'title'=>'title...', 01037 'id' => 'id...', 01038 'icon' => 'icon ref, relative to typo3/ folder...' 01039 ), 01040 [6] => array( 01041 'title'=>'title...', 01042 'id' => 'id...', 01043 'icon' => 'icon ref, relative to typo3/ folder...' 01044 ), 01045 ) 01046 ), 01047 ) 01048 */ 01049 } 01050 01051 01052 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_treeview.php'])) { 01053 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_treeview.php']); 01054 } 01055 01056 ?>
1.8.0