📄 class.tslib_menu.php
字号:
<?php/**************************************************************** Copyright notice** (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)* All rights reserved** This script is part of the TYPO3 project. The TYPO3 project is* free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License as published by* the Free Software Foundation; either version 2 of the License, or* (at your option) any later version.** The GNU General Public License can be found at* http://www.gnu.org/copyleft/gpl.html.* A copy is found in the textfile GPL.txt and important notices to the license* from the author is found in LICENSE.txt distributed with these scripts.*** This script is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the* GNU General Public License for more details.** This copyright notice MUST APPEAR in all copies of the script!***************************************************************//** * Generating navigation / menus from TypoScript * * This file contains five classes, four of which are extensions to the main class, tslib_menu. * The main class, tslib_menu, is also extended by other external PHP scripts such as the GMENU_LAYERS and GMENU_FOLDOUT scripts which creates pop-up menus. * Notice that extension classes (like "tslib_tmenu") must have their suffix (here "tmenu") listed in $this->tmpl->menuclasses - otherwise they cannot be instantiated. * * $Id: class.tslib_menu.php 2543 2007-10-08 20:32:05Z masi $ * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj * XHTML compliant * * @author Kasper Skaarhoj <kasperYYYY@typo3.com> *//** * [CLASS/FUNCTION INDEX of SCRIPT] * * * * 145: class tslib_menu * 191: function start(&$tmpl,&$sys_page,$id,$conf,$menuNumber,$objSuffix='') * 324: function makeMenu() * 865: function includeMakeMenu($conf,$altSortField) * 881: function filterMenuPages(&$data,$banUidArray,$spacer) * 937: function procesItemStates($splitCount) * 1147: function link($key,$altTarget='',$typeOverride='') * 1212: function changeLinksForAccessRestrictedPages(&$LD, $page, $mainTarget, $typeOverride) * 1233: function subMenu($uid, $objSuffix='') * 1278: function isNext($uid, $MPvar='') * 1299: function isActive($uid, $MPvar='') * 1320: function isCurrent($uid, $MPvar='') * 1335: function isSubMenu($uid) * 1360: function isItemState($kind,$key) * 1400: function accessKey($title) * 1426: function userProcess($mConfKey,$passVar) * 1441: function setATagParts() * 1454: function getPageTitle($title,$nav_title) * 1466: function getMPvar($key) * 1481: function getDoktypeExcludeWhere() * 1491: function getBannedUids() * * * 1530: class tslib_tmenu extends tslib_menu * 1539: function generate() * 1555: function writeMenu() * 1699: function getBeforeAfter($pref) * 1729: function addJScolorShiftFunction() * 1751: function extProc_init() * 1762: function extProc_RO($key) * 1773: function extProc_beforeLinking($key) * 1785: function extProc_afterLinking($key) * 1802: function extProc_beforeAllWrap($item,$key) * 1813: function extProc_finish() * * * 1849: class tslib_gmenu extends tslib_menu * 1858: function generate() * 1896: function makeGifs($conf, $resKey) * 2101: function findLargestDims($conf,$items,$Hobjs,$Wobjs,$minDim,$maxDim) * 2173: function writeMenu() * 2294: function extProc_init() * 2305: function extProc_RO($key) * 2316: function extProc_beforeLinking($key) * 2329: function extProc_afterLinking($key) * 2346: function extProc_beforeAllWrap($item,$key) * 2357: function extProc_finish() * * * 2391: class tslib_imgmenu extends tslib_menu * 2400: function generate() * 2418: function makeImageMap($conf) * 2604: function writeMenu() * * * 2647: class tslib_jsmenu extends tslib_menu * 2654: function generate() * 2662: function writeMenu() * 2723: function generate_level($levels,$count,$pid,$menuItemArray='',$MP_array=array()) * * TOTAL FUNCTIONS: 46 * (This index is automatically created/updated by the extension "extdeveval") * *//** * Base class. The HMENU content object uses this (or more precisely one of the extension classes). * Amoung others the class generates an array of menuitems. Thereafter functions from the subclasses are called. * The class is ALWAYS used through extension classes (like tslib_gmenu or tslib_tmenu which are classics) and * * Example of usage (from tslib_cObj): * * $menu = t3lib_div::makeInstance('tslib_'.$cls); * $menu->parent_cObj = $this; * $menu->start($GLOBALS['TSFE']->tmpl,$GLOBALS['TSFE']->sys_page,'',$conf,1); * $menu->makeMenu(); * $content.=$menu->writeMenu(); * * @author Kasper Skaarhoj <kasperYYYY@typo3.com> * @package TYPO3 * @subpackage tslib * @see tslib_cObj::HMENU() */class tslib_menu { var $menuNumber = 1; // tells you which menu-number this is. This is important when getting data from the setup var $entryLevel = 0; // 0 = rootFolder var $spacerIDList = '199'; // The doktype-number that defines a spacer var $doktypeExcludeList = '5,6'; // doktypes that define which should not be included in a menu var $alwaysActivePIDlist=array(); var $imgNamePrefix = 'img'; var $imgNameNotRandom=0; var $debug = 0; var $parent_cObj; // Loaded with the parent cObj-object when a new HMENU is made var $GMENU_fixKey='gmenu'; var $MP_array=array(); // accumulation of mount point data // internal var $conf = Array(); // HMENU configuration var $mconf = Array(); // xMENU configuration (TMENU, GMENU etc) var $tmpl; // template-object var $sys_page; // sys_page-object var $id; // The base page-id of the menu. var $nextActive; // Holds the page uid of the NEXT page in the root line from the page pointed to by entryLevel; Used to expand the menu automatically if in a certain root line. var $menuArr; // The array of menuItems which is built var $hash; var $result = Array(); var $rL_uidRegister = ''; // Array: Is filled with an array of page uid numbers + RL parameters which are in the current root line (used to evaluate whether a menu item is in active state) var $INPfixMD5; var $I; var $WMresult; var $WMfreezePrefix; var $WMmenuItems; var $WMsubmenuObjSuffixes; var $WMextraScript; var $alternativeMenuTempArray=''; // Can be set to contain menu item arrays for sub-levels. var $nameAttribute = 'name'; // Will be 'id' in XHTML-mode /** * The initialization of the object. This just sets some internal variables. * * @param object The $GLOBALS['TSFE']->tmpl object * @param object The $GLOBALS['TSFE']->sys_page object * @param integer A starting point page id. This should probably be blank since the 'entryLevel' value will be used then. * @param array The TypoScript configuration for the HMENU cObject * @param integer Menu number; 1,2,3. Should probably be '1' * @param string Submenu Object suffix. This offers submenus a way to use alternative configuration for specific positions in the menu; By default "1 = TMENU" would use "1." for the TMENU configuration, but if this string is set to eg. "a" then "1a." would be used for configuration instead (while "1 = " is still used for the overall object definition of "TMENU") * @return boolean Returns true on success * @see tslib_cObj::HMENU() */ function start(&$tmpl,&$sys_page,$id,$conf,$menuNumber,$objSuffix='') { // Init: $this->conf = $conf; $this->menuNumber = $menuNumber; $this->mconf = $conf[$this->menuNumber.$objSuffix.'.']; $this->debug=$GLOBALS['TSFE']->debug; // In XHTML there is no "name" attribute anymore switch ($GLOBALS['TSFE']->xhtmlDoctype) { case 'xhtml_strict': case 'xhtml_11': case 'xhtml_2': $this->nameAttribute = 'id'; break; default: $this->nameAttribute = 'name'; break; } // Sets the internal vars. $tmpl MUST be the template-object. $sys_page MUST be the sys_page object if ($this->conf[$this->menuNumber.$objSuffix] && is_object($tmpl) && is_object($sys_page)) { $this->tmpl = &$tmpl; $this->sys_page = &$sys_page; // alwaysActivePIDlist initialized: if (trim($this->conf['alwaysActivePIDlist'])) { $this->alwaysActivePIDlist = t3lib_div::intExplode(',', $this->conf['alwaysActivePIDlist']); } // 'not in menu' doktypes if($this->conf['excludeDoktypes']) { $this->doktypeExcludeList = $GLOBALS['TYPO3_DB']->cleanIntList($this->conf['excludeDoktypes']); } if($this->conf['includeNotInMenu']) { $exclDoktypeArr = t3lib_div::trimExplode(',',$this->doktypeExcludeList,1); $exclDoktypeArr = t3lib_div::removeArrayEntryByValue($exclDoktypeArr,'5'); $this->doktypeExcludeList = implode(',',$exclDoktypeArr); } // EntryLevel $this->entryLevel = tslib_cObj::getKey ($conf['entryLevel'],$this->tmpl->rootLine); // Set parent page: If $id not stated with start() then the base-id will be found from rootLine[$this->entryLevel] if ($id) { // Called as the next level in a menu. It is assumed that $this->MP_array is set from parent menu. $this->id = intval($id); } else { // This is a BRAND NEW menu, first level. So we take ID from rootline and also find MP_array (mount points) $this->id = intval($this->tmpl->rootLine[$this->entryLevel]['uid']); // Traverse rootline to build MP_array of pages BEFORE the entryLevel // (MP var for ->id is picked up in the next part of the code...) foreach($this->tmpl->rootLine as $entryLevel => $levelRec) { // For overlaid mount points, set the variable right now: if ($levelRec['_MP_PARAM'] && $levelRec['_MOUNT_OL']) { $this->MP_array[] = $levelRec['_MP_PARAM']; } // Break when entry level is reached: if ($entryLevel>=$this->entryLevel) break; // For normal mount points, set the variable for next level. if ($levelRec['_MP_PARAM'] && !$levelRec['_MOUNT_OL']) { $this->MP_array[] = $levelRec['_MP_PARAM']; } } } // Return false if no page ID was set (thus no menu of subpages can be made). if ($this->id<=0) { return FALSE; } // Check if page is a mount point, and if so set id and MP_array // (basically this is ONLY for non-overlay mode, but in overlay mode an ID with a mount point should never reach this point anyways, so no harm done...) $mount_info = $this->sys_page->getMountPointInfo($this->id); if (is_array($mount_info)) { $this->MP_array[] = $mount_info['MPvar']; $this->id = $mount_info['mount_pid']; } // Gather list of page uids in root line (for "isActive" evaluation). Also adds the MP params in the path so Mount Points are respected. // (List is specific for this rootline, so it may be supplied from parent menus for speed...) if (!is_array($this->rL_uidRegister)) { $rl_MParray = array(); foreach($this->tmpl->rootLine as $v_rl) { // For overlaid mount points, set the variable right now: if ($v_rl['_MP_PARAM'] && $v_rl['_MOUNT_OL']) { $rl_MParray[] = $v_rl['_MP_PARAM']; } // Add to register: $this->rL_uidRegister[] = 'ITEM:'.$v_rl['uid'].(count($rl_MParray) ? ':'.implode(',',$rl_MParray) : ''); // For normal mount points, set the variable for next level. if ($v_rl['_MP_PARAM'] && !$v_rl['_MOUNT_OL']) { $rl_MParray[] = $v_rl['_MP_PARAM']; } } } // Setting "nextActive": This is the page uid + MPvar of the NEXT page in rootline. Used to expand the menu if we are in the right branch of the tree // Notice: The automatic expansion of a menu is designed to work only when no "special" modes are used. if (is_array($this->tmpl->rootLine[$this->entryLevel+$this->menuNumber])) { $nextMParray = $this->MP_array; if ($this->tmpl->rootLine[$this->entryLevel+$this->menuNumber]['_MOUNT_OL']) { // In overlay mode, add next level MPvars as well: $nextMParray[] = $this->tmpl->rootLine[$this->entryLevel+$this->menuNumber]['_MP_PARAM']; } $this->nextActive = $this->tmpl->rootLine[$this->entryLevel+$this->menuNumber]['uid']. (count($nextMParray)?':'.implode(',',$nextMParray):''); } else { $this->nextActive = ''; } // imgNamePrefix if ($this->mconf['imgNamePrefix']) { $this->imgNamePrefix=$this->mconf['imgNamePrefix']; } $this->imgNameNotRandom = $this->mconf['imgNameNotRandom']; $retVal = TRUE; } else { $GLOBALS['TT']->setTSlogMessage('ERROR in menu',3); $retVal = FALSE; } return $retVal; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -