* Mount Points (Mount pages) reworking. See change log
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / class.tslib_menu.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Generating navigation / menus from TypoScript
29 *
30 * This file contains five classes, four of which are extensions to the main class, tslib_menu.
31 * 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.
32 * Notice that extension classes (like "tslib_tmenu") must have their suffix (here "tmenu") listed in $this->tmpl->menuclasses - otherwise they cannot be instantiated.
33 *
34 * $Id$
35 * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
36 * XHTML compliant
37 *
38 * @author Kasper Skaarhoj <kasper@typo3.com>
39 */
40 /**
41 * [CLASS/FUNCTION INDEX of SCRIPT]
42 *
43 *
44 *
45 * 141: class tslib_menu
46 * 183: function start(&$tmpl,&$sys_page,$id,$conf,$menuNumber)
47 * 294: function makeMenu()
48 * 774: function includeMakeMenu($conf,$altSortField)
49 * 791: function procesItemStates($splitCount)
50 * 978: function link($key,$altTarget='',$typeOverride='')
51 * 1032: function subMenu($uid)
52 * 1074: function isNext($uid, $MPvar='')
53 * 1089: function isActive($uid, $MPvar='')
54 * 1104: function isCurrent($uid, $MPvar='')
55 * 1119: function isSubMenu($uid)
56 * 1144: function isItemState($kind,$key)
57 * 1181: function accessKey($title)
58 * 1207: function userProcess($mConfKey,$passVar)
59 * 1222: function setATagParts()
60 * 1235: function getPageTitle($title,$nav_title)
61 * 1247: function getMPvar($key)
62 *
63 *
64 * 1283: class tslib_tmenu extends tslib_menu
65 * 1292: function generate()
66 * 1308: function writeMenu()
67 * 1438: function getBeforeAfter($pref)
68 * 1468: function addJScolorShiftFunction()
69 * 1490: function extProc_init()
70 * 1501: function extProc_RO($key)
71 * 1512: function extProc_beforeLinking($key)
72 * 1524: function extProc_afterLinking($key)
73 * 1541: function extProc_beforeAllWrap($item,$key)
74 * 1552: function extProc_finish()
75 *
76 *
77 * 1588: class tslib_gmenu extends tslib_menu
78 * 1597: function generate()
79 * 1635: function makeGifs($conf, $resKey)
80 * 1832: function findLargestDims($conf,$items,$Hobjs,$Wobjs,$minDim,$maxDim)
81 * 1904: function writeMenu()
82 * 2002: function extProc_init()
83 * 2013: function extProc_RO($key)
84 * 2024: function extProc_beforeLinking($key)
85 * 2037: function extProc_afterLinking($key)
86 * 2053: function extProc_beforeAllWrap($item,$key)
87 * 2064: function extProc_finish()
88 *
89 *
90 * 2098: class tslib_imgmenu extends tslib_menu
91 * 2107: function generate()
92 * 2125: function makeImageMap($conf)
93 * 2294: function writeMenu()
94 *
95 *
96 * 2337: class tslib_jsmenu extends tslib_menu
97 * 2344: function generate()
98 * 2352: function writeMenu()
99 * 2413: function generate_level($levels,$count,$pid,$menuItemArray='',$MP_array=array())
100 *
101 * TOTAL FUNCTIONS: 42
102 * (This index is automatically created/updated by the extension "extdeveval")
103 *
104 */
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 /**
124 * Base class. The HMENU content object uses this (or more precisely one of the extension classes).
125 * Amoung others the class generates an array of menuitems. Thereafter functions from the subclasses are called.
126 * The class is ALWAYS used through extension classes (like tslib_gmenu or tslib_tmenu which are classics) and
127 *
128 * Example of usage (from tslib_cObj):
129 *
130 * $menu = t3lib_div::makeInstance('tslib_'.$cls);
131 * $menu->parent_cObj = $this;
132 * $menu->start($GLOBALS['TSFE']->tmpl,$GLOBALS['TSFE']->sys_page,'',$conf,1);
133 * $menu->makeMenu();
134 * $content.=$menu->writeMenu();
135 *
136 * @author Kasper Skaarhoj <kasper@typo3.com>
137 * @package TYPO3
138 * @subpackage tslib
139 * @see tslib_cObj::HMENU()
140 */
141 class tslib_menu {
142 var $menuNumber = 1; // tells you which menu-number this is. This is important when getting data from the setup
143 var $entryLevel = 0; // 0 = rootFolder
144 var $subLevelClass = ''; // Points to the menu-class, that should be used for the next level
145 var $spacerIDList = '199'; // The doktype-number that defines a spacer
146 var $imgNamePrefix = 'img';
147 var $imgNameNotRandom=0;
148 var $debug = 0;
149 var $parent_cObj =''; // Loaded with the parent cObj-object when a new HMENU is made
150 var $GMENU_fixKey = 'gmenu';
151 var $MP_array = array(); // accumulation of mount point data
152
153 // internal
154 var $conf = Array(); // HMENU configuration
155 var $mconf = Array(); // xMENU configuration (TMENU, GMENU etc)
156 var $tmpl; // template-object
157 var $sys_page; // sys_page-object
158 var $id; // The base page-id of the menu.
159 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.
160 var $menuArr; // The array of menuItems which is built
161 var $hash;
162 var $result = Array();
163 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)
164 var $INPfixMD5;
165 var $I;
166 var $WMresult;
167 var $WMfreezePrefix;
168 var $WMmenuItems;
169 var $WMextraScript;
170 var $alternativeMenuTempArray=''; // Can be set to contain menu item arrays for sub-levels.
171
172 /**
173 * The initialization of the object. This just sets some internal variables.
174 *
175 * @param object The $GLOBALS['TSFE']->tmpl object
176 * @param object The $GLOBALS['TSFE']->sys_page object
177 * @param integer A starting point page id. This should probably be blank since the 'entryLevel' value will be used then.
178 * @param array The TypoScript configuration for the HMENU cObject
179 * @param integer Menu number; 1,2,3. Should probably be '1'
180 * @return boolean Returns true on success
181 * @see tslib_cObj::HMENU()
182 */
183 function start(&$tmpl,&$sys_page,$id,$conf,$menuNumber) {
184
185 // Init:
186 $this->conf = $conf;
187 $this->menuNumber = $menuNumber;
188 $this->mconf = $conf[$this->menuNumber.'.'];
189 $this->debug = $GLOBALS['TSFE']->debug;
190
191 // Sets the internal vars. $tmpl MUST be the template-object. $sys_page MUST be the sys_page object
192 if ($this->conf[$this->menuNumber] && is_object($tmpl) && is_object($sys_page)) {
193 $this->tmpl = &$tmpl;
194 $this->sys_page = &$sys_page;
195
196 // EntryLevel
197 $this->entryLevel = tslib_cObj::getKey($conf['entryLevel'],$this->tmpl->rootLine);
198
199 // Set parent page: If $id not stated with start() then the base-id will be found from rootLine[$this->entryLevel]
200 if ($id) { // Called as the next level in a menu. It is assumed that $this->MP_array is set from parent menu.
201 $this->id = intval($id);
202 } else { // This is a BRAND NEW menu, first level. So we take ID from rootline and also find MP_array (mount points)
203 $this->id = intval($this->tmpl->rootLine[$this->entryLevel]['uid']);
204
205 // Traverse rootline to build MP_array of pages BEFORE the entryLevel
206 // (MP var for ->id is picked up in the next part of the code...)
207 foreach($this->tmpl->rootLine as $entryLevel => $levelRec) {
208 // For overlaid mount points, set the variable right now:
209 if ($levelRec['_MP_PARAM'] && $levelRec['_MOUNT_OL']) {
210 $this->MP_array[] = $levelRec['_MP_PARAM'];
211 }
212 // Break when entry level is reached:
213 if ($entryLevel>=$this->entryLevel) break;
214
215 // For normal mount points, set the variable for next level.
216 if ($levelRec['_MP_PARAM'] && !$levelRec['_MOUNT_OL']) {
217 $this->MP_array[] = $levelRec['_MP_PARAM'];
218 }
219 }
220 }
221
222 // Return false if no page ID was set (thus no menu of subpages can be made).
223 if ($this->id<=0) {
224 return FALSE;
225 }
226
227 // Check if page is a mount point, and if so set id and MP_array
228 // (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...)
229 $mount_info = $this->sys_page->getMountPointInfo($this->id);
230 if (is_array($mount_info)) {
231 $this->MP_array[] = $mount_info['MPvar'];
232 $this->id = $mount_info['mount_pid'];
233 }
234
235 // Gather list of page uids in root line (for "isActive" evaluation). Also adds the MP params in the path so Mount Points are respected.
236 // (List is specific for this rootline, so it may be supplied from parent menus for speed...)
237 if (!is_array($this->rL_uidRegister)) {
238 $rl_MParray = array();
239 foreach($this->tmpl->rootLine as $v_rl) {
240 // For overlaid mount points, set the variable right now:
241 if ($v_rl['_MP_PARAM'] && $v_rl['_MOUNT_OL']) {
242 $rl_MParray[] = $v_rl['_MP_PARAM'];
243 }
244
245 // Add to register:
246 $this->rL_uidRegister[] = 'ITEM:'.$v_rl['uid'].(count($rl_MParray) ? ':'.implode(',',$rl_MParray) : '');
247
248 // For normal mount points, set the variable for next level.
249 if ($v_rl['_MP_PARAM'] && !$v_rl['_MOUNT_OL']) {
250 $rl_MParray[] = $v_rl['_MP_PARAM'];
251 }
252 }
253 }
254
255 // 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
256 // Notice: The automatic expansion of a menu is designed to work only when no "special" modes are used.
257 if (is_array($this->tmpl->rootLine[$this->entryLevel+$this->menuNumber])) {
258 $nextMParray = $this->MP_array;
259 if ($this->tmpl->rootLine[$this->entryLevel+$this->menuNumber]['_MOUNT_OL']) { // In overlay mode, add next level MPvars as well:
260 $nextMParray[] = $this->tmpl->rootLine[$this->entryLevel+$this->menuNumber]['_MP_PARAM'];
261 }
262 $this->nextActive = $this->tmpl->rootLine[$this->entryLevel+$this->menuNumber]['uid'].
263 (count($nextMParray)?':'.implode(',',$nextMParray):'');
264 } else {
265 $this->nextActive = '';
266 }
267
268 // imgNamePrefix
269 if ($this->mconf['imgNamePrefix']) {
270 $this->imgNamePrefix=$this->mconf['imgNamePrefix'];
271 }
272 $this->imgNameNotRandom = $this->mconf['imgNameNotRandom'];
273
274 // subLevelClass
275 $cls = strtolower($this->conf[$this->menuNumber+1]);
276 if ($cls && t3lib_div::inList($this->tmpl->menuclasses,$cls)) {
277 $this->subLevelClass = $cls;
278 }
279 $retVal = TRUE;
280 } else {
281 $GLOBALS['TT']->setTSlogMessage('ERROR in menu',3);
282 $retVal = FALSE;
283 }
284 return $retVal;
285 }
286
287 /**
288 * Creates the menu in the internal variables, ready for output.
289 * Basically this will read the page records needed and fill in the internal $this->menuArr
290 * Based on a hash of this array and some other variables the $this->result variable will be loaded either from cache OR by calling the generate() method of the class to create the menu for real.
291 *
292 * @return void
293 */
294 function makeMenu() {
295 if ($this->id) {
296 $temp = array();
297 $altSortFieldValue = trim($this->mconf['alternativeSortingField']);
298 $altSortField = $altSortFieldValue ? $altSortFieldValue : 'sorting';
299 if ($this->menuNumber==1 && $this->conf['special']) { // ... only for the FIRST level of a HMENU
300 $value = $this->conf['special.']['value'];
301
302 switch($this->conf['special']) {
303 case 'userdefined':
304 $temp = $this->includeMakeMenu($this->conf['special.'],$altSortField);
305 break;
306 case 'userfunction':
307 $temp = $this->parent_cObj->callUserFunction(
308 $this->conf['special.']['userFunc'],
309 array_merge($this->conf['special.'],array('_altSortField'=>$altSortField)),
310 ''
311 );
312 if (!is_array($temp)) $temp=array();
313 break;
314 case 'directory':
315 if ($value=='') {
316 $value = $GLOBALS['TSFE']->page['uid'];
317 }
318 $items = t3lib_div::intExplode(',',$value);
319
320 foreach($items as $id) {
321 $MP = $this->tmpl->getFromMPmap($id);
322
323 // Checking if a page is a mount page and if so, change the ID and set the MP var properly.
324 $mount_info = $this->sys_page->getMountPointInfo($id);
325 if (is_array($mount_info)) {
326 if ($mount_info['overlay']) { // Overlays should already have their full MPvars calculated:
327 $MP = $this->tmpl->getFromMPmap($mount_info['mount_pid']);
328 $MP = $MP ? $MP : $mount_info['MPvar'];
329 } else {
330 $MP = ($MP ? $MP.',' : '').$mount_info['MPvar'];
331 }
332 $id = $mount_info['mount_pid'];
333 }
334
335 // Get sub-pages:
336 $res = $GLOBALS['TSFE']->cObj->exec_getQuery('pages',Array('pidInList'=>$id,'orderBy'=>$altSortField));
337 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
338
339 // Keep mount point?
340 $mount_info = $this->sys_page->getMountPointInfo($row['uid'], $row);
341 if (is_array($mount_info) && $mount_info['overlay']) { // There is a valid mount point.
342 $mp_row = $this->sys_page->getPage($mount_info['mount_pid']); // Using "getPage" is OK since we need the check for enableFields AND for type 2 of mount pids we DO require a doktype < 200!
343 if (count($mp_row)) {
344 $row = $mp_row;
345 $row['_MP_PARAM'] = $mount_info['MPvar'];
346 } else unset($row); // If the mount point could not be fetched with respect to enableFields, unset the row so it does not become a part of the menu!
347 }
348
349 // Add external MP params, then the row:
350 if (is_array($row)) {
351 if ($MP) $row['_MP_PARAM'] = $MP.($row['_MP_PARAM'] ? ','.$row['_MP_PARAM'] : '');
352 $temp[$row['uid']] = $this->sys_page->getPageOverlay($row);
353 }
354 }
355 }
356 break;
357 case 'list':
358 if ($value=='') {
359 $value = $this->id;
360 }
361 $loadDB = t3lib_div::makeInstance('FE_loadDBGroup');
362 $loadDB->start($value, 'pages');
363 $loadDB->additionalWhere['pages'] = tslib_cObj::enableFields('pages');
364 $loadDB->getFromDB();
365
366 foreach($loadDB->itemArray as $val) {
367 $MP = $this->tmpl->getFromMPmap($val['id']);
368
369 // Keep mount point?
370 $mount_info = $this->sys_page->getMountPointInfo($val['id']);
371 if (is_array($mount_info) && $mount_info['overlay']) { // There is a valid mount point.
372 $mp_row = $this->sys_page->getPage($mount_info['mount_pid']); // Using "getPage" is OK since we need the check for enableFields AND for type 2 of mount pids we DO require a doktype < 200!
373 if (count($mp_row)) {
374 $row = $mp_row;
375 $row['_MP_PARAM'] = $mount_info['MPvar'];
376
377 if ($mount_info['overlay']) { // Overlays should already have their full MPvars calculated:
378 $MP = $this->tmpl->getFromMPmap($mount_info['mount_pid']);
379 if ($MP) unset($row['_MP_PARAM']);
380 }
381
382 } else unset($row); // If the mount point could not be fetched with respect to enableFields, unset the row so it does not become a part of the menu!
383 } else {
384 $row = $loadDB->results['pages'][$val['id']];
385 }
386
387 // Add external MP params, then the row:
388 if (is_array($row)) {
389 if ($MP) $row['_MP_PARAM'] = $MP.($row['_MP_PARAM'] ? ','.$row['_MP_PARAM'] : '');
390 $temp[] = $this->sys_page->getPageOverlay($row);
391 }
392 }
393 break;
394 case 'updated':
395 if ($value=='') {
396 $value = $GLOBALS['TSFE']->page['uid'];
397 }
398 $items = t3lib_div::intExplode(',',$value);
399 if (t3lib_div::testInt($this->conf['special.']['depth'])) {
400 $depth = t3lib_div::intInRange($this->conf['special.']['depth'],1,20); // Tree depth
401 } else {
402 $depth=20;
403 }
404 $limit = t3lib_div::intInRange($this->conf['special.']['limit'],0,100); // max number of items
405 $maxAge = intval(tslib_cObj::calc($this->conf['special.']['maxAge']));
406 if (!$limit) $limit=10;
407 $mode = $this->conf['special.']['mode']; // *'auto', 'manual', 'tstamp'
408 // Get id's
409 $id_list_arr = Array();
410
411 foreach($items as $id) {
412 $bA = t3lib_div::intInRange($this->conf['special.']['beginAtLevel'], 0, 100);
413 $id_list_arr[] = tslib_cObj::getTreeList(-1*$id,$depth-1+$bA,$bA-1);
414 }
415 $id_list = implode($id_list_arr, ',');
416 // Get sortField (mode)
417 switch($mode) {
418 case 'starttime':
419 $sortField = 'starttime';
420 break;
421 case 'lastUpdated':
422 case 'manual':
423 $sortField = 'lastUpdated';
424 break;
425 case 'tstamp':
426 $sortField = 'tstamp';
427 break;
428 case 'crdate':
429 $sortField = 'crdate';
430 break;
431 default:
432 $sortField = 'SYS_LASTCHANGED';
433 break;
434 }
435 // Get
436 $extraWhere = ' AND pages.doktype NOT IN (5,6)';
437
438 if ($this->conf['special.']['excludeNoSearchPages']) {
439 $extraWhere.= ' AND pages.no_search=0';
440 }
441 if ($maxAge>0) {
442 $extraWhere.=' AND '.$sortField.'>'.($GLOBALS['SIM_EXEC_TIME']-$maxAge);
443 }
444
445 $res = $GLOBALS['TSFE']->cObj->exec_getQuery('pages',Array('pidInList'=>'0', 'uidInList'=>$id_list, 'where'=>$sortField.'>=0'.$extraWhere, 'orderBy'=>($altSortFieldValue ? $altSortFieldValue : $sortField.' desc'),'max'=>$limit));
446 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
447 $temp[$row['uid']]=$this->sys_page->getPageOverlay($row);
448 }
449 break;
450 case 'keywords':
451 list($value) = t3lib_div::intExplode(',',$value);
452 if (!$value) {
453 $value = $GLOBALS['TSFE']->page['uid'];
454 }
455 if ($this->conf['special.']['setKeywords'] || $this->conf['special.']['setKeywords.']) {
456 $kw = $this->parent_cObj->stdWrap($this->conf['special.']['setKeywords'], $this->conf['special.']['setKeywords.']);
457 } else {
458 $value_rec = $this->sys_page->getPage($value); // The page record of the 'value'.
459
460 $kfieldSrc = $this->conf['special.']['keywordsField.']['sourceField'] ? $this->conf['special.']['keywordsField.']['sourceField'] : 'keywords';
461 $kw = trim(tslib_cObj::keywords($value_rec[$kfieldSrc])); // keywords.
462 }
463
464 $mode = $this->conf['special.']['mode']; // *'auto', 'manual', 'tstamp'
465 switch($mode) {
466 case 'starttime':
467 $sortField = 'starttime';
468 break;
469 case 'lastUpdated':
470 case 'manual':
471 $sortField = 'lastUpdated';
472 break;
473 case 'tstamp':
474 $sortField = 'tstamp';
475 break;
476 case 'crdate':
477 $sortField = 'crdate';
478 break;
479 default:
480 $sortField = 'SYS_LASTCHANGED';
481 break;
482 }
483
484 // depth, limit, extra where
485 if (t3lib_div::testInt($this->conf['special.']['depth'])) {
486 $depth = t3lib_div::intInRange($this->conf['special.']['depth'],0,20); // Tree depth
487 } else {
488 $depth=20;
489 }
490 $limit = t3lib_div::intInRange($this->conf['special.']['limit'],0,100); // max number of items
491 $extraWhere = ' AND pages.uid!='.$value.' AND pages.doktype NOT IN (5,6)';
492 if ($this->conf['special.']['excludeNoSearchPages']) {
493 $extraWhere.= ' AND pages.no_search=0';
494 }
495 // start point
496 $eLevel = tslib_cObj::getKey(intval($this->conf['special.']['entryLevel']),$this->tmpl->rootLine);
497 $startUid = intval($this->tmpl->rootLine[$eLevel]['uid']);
498
499 // which field is for keywords
500 $kfield = 'keywords';
501 if ( $this->conf['special.']['keywordsField'] ) {
502 list($kfield) = explode(' ',trim ($this->conf['special.']['keywordsField']));
503 }
504
505 // If there are keywords and the startuid is present.
506 if ($kw && $startUid) {
507 $bA = t3lib_div::intInRange($this->conf['special.']['beginAtLevel'],0,100);
508 $id_list=tslib_cObj::getTreeList(-1*$startUid,$depth-1+$bA,$bA-1);
509
510 $kwArr = explode(',',$kw);
511 foreach($kwArr as $word) {
512 $word = trim($word);
513 if ($word) {
514 $keyWordsWhereArr[] = $kfield.' LIKE "%'.$GLOBALS['TYPO3_DB']->quoteStr($word, 'pages').'%"';
515 }
516 }
517 $res = $GLOBALS['TSFE']->cObj->exec_getQuery('pages',Array('pidInList'=>'0', 'uidInList'=>$id_list, 'where'=>'('.implode($keyWordsWhereArr,' OR ').')'.$extraWhere, 'orderBy'=>($altSortFieldValue ? $altSortFieldValue : $sortField.' desc'),'max'=>$limit));
518 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
519 $temp[$row['uid']]=$this->sys_page->getPageOverlay($row);
520 }
521 }
522 break;
523 case 'rootline':
524 $begin_end = explode('|',$this->conf['special.']['range']);
525 if (!t3lib_div::testInt($begin_end[0])) {intval($begin_end[0]);}
526 if (!t3lib_div::testInt($begin_end[1])) {$begin_end[1]=-1;}
527
528 $beginKey = tslib_cObj::getKey($begin_end[0],$this->tmpl->rootLine);
529 $endKey = tslib_cObj::getKey($begin_end[1],$this->tmpl->rootLine);
530 if ($endKey<$beginKey) {$endKey=$beginKey;}
531
532 $rl_MParray = array();
533 foreach($this->tmpl->rootLine as $k_rl => $v_rl) {
534 // For overlaid mount points, set the variable right now:
535 if ($v_rl['_MP_PARAM'] && $v_rl['_MOUNT_OL']) {
536 $rl_MParray[] = $v_rl['_MP_PARAM'];
537 }
538 // Traverse rootline:
539 if ($k_rl>=$beginKey && $k_rl<=$endKey) {
540 $temp_key = $k_rl;
541 $temp[$temp_key] = $this->sys_page->getPage($v_rl['uid']);
542 if (count($temp[$temp_key])) {
543 if (!$temp[$temp_key]['target']) { // If there are no specific target for the page, put the level specific target on.
544 $temp[$temp_key]['target'] = $this->conf['special.']['targets.'][$k_rl];
545 $temp[$temp_key]['_MP_PARAM'] = implode(',',$rl_MParray);
546 }
547 } else unset($temp[$temp_key]);
548 }
549 // For normal mount points, set the variable for next level.
550 if ($v_rl['_MP_PARAM'] && !$v_rl['_MOUNT_OL']) {
551 $rl_MParray[] = $v_rl['_MP_PARAM'];
552 }
553 }
554 break;
555 case 'browse':
556 list($value)=t3lib_div::intExplode(',',$value);
557 if (!$value) {
558 $value = $GLOBALS['TSFE']->page['uid'];
559 }
560 if ($value!=$this->tmpl->rootLine[0]['uid']) { // Will not work out of rootline
561 $recArr = array();
562 $value_rec = $this->sys_page->getPage($value); // The page record of the 'value'.
563 if ($value_rec['pid']) { // 'up' page cannot be outside rootline
564 $recArr['up'] = $this->sys_page->getPage($value_rec['pid']); // The page record of 'up'.
565 }
566 if ($recArr['up']['pid'] && $value_rec['pid']!=$this->tmpl->rootLine[0]['uid']) { // If the 'up' item was NOT level 0 in rootline...
567 $recArr['index'] = $this->sys_page->getPage($recArr['up']['pid']); // The page record of "index".
568 }
569
570 // prev / next is found
571 $prevnext_menu = $this->sys_page->getMenu($value_rec['pid'],'*',$altSortField);
572 $lastKey=0;
573 $nextActive=0;
574 reset($prevnext_menu);
575 while(list($k_b,$v_b)=each($prevnext_menu)) {
576 if ($nextActive) {
577 $recArr['next']=$v_b;
578 $nextActive=0;
579 }
580 if ($v_b['uid']==$value) {
581 if ($lastKey) {
582 $recArr['prev']=$prevnext_menu[$lastKey];
583 }
584 $nextActive=1;
585 }
586 $lastKey=$k_b;
587 }
588 reset($prevnext_menu);
589 $recArr['first']=pos($prevnext_menu);
590 end($prevnext_menu);
591 $recArr['last']=pos($prevnext_menu);
592
593 // prevsection / nextsection is found
594 if (is_array($recArr['index'])) { // You can only do this, if there is a valid page two levels up!
595 $prevnextsection_menu = $this->sys_page->getMenu($recArr['index']['uid'],'*',$altSortField);
596 $lastKey=0;
597 $nextActive=0;
598 reset($prevnextsection_menu);
599 while(list($k_b,$v_b)=each($prevnextsection_menu)) {
600 if ($nextActive) {
601 $sectionRec_temp = $this->sys_page->getMenu($v_b['uid'],'*',$altSortField);
602 if (count($sectionRec_temp)) {
603 reset($sectionRec_temp);
604 $recArr['nextsection']=pos($sectionRec_temp);
605 end ($sectionRec_temp);
606 $recArr['nextsection_last']=pos($sectionRec_temp);
607 $nextActive=0;
608 }
609 }
610 if ($v_b['uid']==$value_rec['pid']) {
611 if ($lastKey) {
612 $sectionRec_temp = $this->sys_page->getMenu($prevnextsection_menu[$lastKey]['uid'],'*',$altSortField);
613 if (count($sectionRec_temp)) {
614 reset($sectionRec_temp);
615 $recArr['prevsection']=pos($sectionRec_temp);
616 end ($sectionRec_temp);
617 $recArr['prevsection_last']=pos($sectionRec_temp);
618 }
619 }
620 $nextActive=1;
621 }
622 $lastKey=$k_b;
623 }
624 }
625 if ($this->conf['special.']['items.']['prevnextToSection']) {
626 if (!is_array($recArr['prev']) && is_array($recArr['prevsection_last'])) {
627 $recArr['prev']=$recArr['prevsection_last'];
628 }
629 if (!is_array($recArr['next']) && is_array($recArr['nextsection'])) {
630 $recArr['next']=$recArr['nextsection'];
631 }
632 }
633
634 $items = explode('|',$this->conf['special.']['items']);
635 $c=0;
636 while(list($k_b,$v_b)=each($items)) {
637 $v_b=strtolower(trim($v_b));
638 if (intval($this->conf['special.'][$v_b.'.']['uid'])) {
639 $recArr[$v_b] = $this->sys_page->getPage(intval($this->conf['special.'][$v_b.'.']['uid'])); // fetches the page in case of a hardcoded pid in template
640 }
641 if (is_array($recArr[$v_b])) {
642 $temp[$c]=$recArr[$v_b];
643 if ($this->conf['special.'][$v_b.'.']['target']) {
644 $temp[$c]['target']=$this->conf['special.'][$v_b.'.']['target'];
645 }
646 if (is_array($this->conf['special.'][$v_b.'.']['fields.'])) {
647 reset($this->conf['special.'][$v_b.'.']['fields.']);
648 while(list($fk,$val)=each($this->conf['special.'][$v_b.'.']['fields.'])) {
649 $temp[$c][$fk]=$val;
650 }
651 }
652 $c++;
653 }
654 }
655 }
656 break;
657 }
658 } elseif (is_array($this->alternativeMenuTempArray)) { // Setting $temp array if not level 1.
659 $temp = $this->alternativeMenuTempArray;
660 } elseif ($this->mconf['sectionIndex']) {
661 if ($GLOBALS['TSFE']->sys_language_uid && count($this->sys_page->getPageOverlay($this->id))) {
662 $sys_language_uid = intval($GLOBALS['TSFE']->sys_language_uid);
663 } else $sys_language_uid=0;
664
665 $selectSetup = Array(
666 'pidInList' => $this->id,
667 'orderBy' => $altSortField,
668 'where' => 'colPos=0 AND sys_language_uid='.$sys_language_uid,
669 'andWhere' => 'sectionIndex!=0'
670 );
671 switch($this->mconf['sectionIndex.']['type']) {
672 case 'all':
673 unset($selectSetup['andWhere']);
674 break;
675 case 'header':
676 $selectSetup['andWhere']='header_layout!=100 AND header!=""';
677 break;
678 }
679 $basePageRow = $this->sys_page->getPage($this->id);
680 if (is_array($basePageRow)) {
681 $res = $GLOBALS['TSFE']->cObj->exec_getQuery('tt_content', $selectSetup);
682 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
683 $temp[$row['uid']]=$basePageRow;
684 $temp[$row['uid']]['title']=$row['header'];
685 $temp[$row['uid']]['subtitle']=$row['subheader'];
686 $temp[$row['uid']]['starttime']=$row['starttime'];
687 $temp[$row['uid']]['endtime']=$row['endtime'];
688 $temp[$row['uid']]['fe_group']=$row['fe_group'];
689 $temp[$row['uid']]['media']=$row['media'];
690
691 $temp[$row['uid']]['header_layout']=$row['header_layout'];
692 $temp[$row['uid']]['bodytext']=$row['bodytext'];
693 $temp[$row['uid']]['image']=$row['image'];
694
695 $temp[$row['uid']]['sectionIndex_uid']=$row['uid'];
696 }
697 }
698 } else { // Default:
699 $temp = $this->sys_page->getMenu($this->id,'*',$altSortField); // gets the menu
700 }
701
702 $c = 0;
703 $c_b = 0;
704 $minItems = intval($this->conf['minItems']);
705 $maxItems = intval($this->conf['maxItems']);
706 $begin = tslib_cObj::calc($this->conf['begin']);
707
708 $banUidArray = array();
709 if (trim($this->conf['excludeUidList'])) {
710 $banUidArray = t3lib_div::intExplode(',', $this->conf['excludeUidList']);
711 }
712
713 // Fill in the menuArr with elements that should go into the menu:
714 $this->menuArr = Array();
715 foreach($temp as $data) {
716 $uid = $data['uid'];
717 $spacer = (t3lib_div::inList($this->spacerIDList,$data['doktype'])?1:0); // if item is a spacer, $spacer is set
718 if ($this->mconf['SPC'] || !$spacer) { // If the spacer-function is not enabled, spacers will not enter the $menuArr
719 if (!t3lib_div::inList('5,6',$data['doktype']) && !t3lib_div::inArray($banUidArray,$uid)) { // Page may not be 'not_in_menu' or 'Backend User Section' + not in banned uid's
720 $c_b++;
721 if ($begin<=$c_b) { // If the beginning item has been reached.
722 $this->menuArr[$c] = $data;
723 $this->menuArr[$c]['isSpacer'] = $spacer;
724 $c++;
725 if ($maxItems && $c>=$maxItems) {
726 break;
727 }
728 }
729 }
730 }
731 }
732
733 // Fill in fake items, if min-items is set.
734 if ($minItems) {
735 while($c<$minItems) {
736 $this->menuArr[$c] = Array(
737 'title' => '...',
738 'uid' => $GLOBALS['TSFE']->id
739 );
740 $c++;
741 }
742 }
743
744 // Setting number of menu items
745 $GLOBALS['TSFE']->register['count_menuItems'] = count($this->menuArr);
746
747 // Passing the menuArr through a user defined function:
748 if ($this->mconf['itemArrayProcFunc']) {
749 if (!is_array($this->parentMenuArr)) { $this->parentMenuArr=array();}
750 $this->menuArr = $this->userProcess('itemArrayProcFunc',$this->menuArr);
751 }
752 $this->hash = md5(serialize($this->menuArr).serialize($this->mconf).serialize($this->tmpl->rootLine).serialize($this->MP_array));
753
754 $serData = $this->sys_page->getHash($this->hash, 60*60*24);
755 if (!$serData) {
756 $this->generate();
757 $this->sys_page->storeHash($this->hash, serialize($this->result),'MENUDATA');
758 } else {
759 $this->result=unserialize($serData);
760 }
761 }
762 }
763
764 /**
765 * Includes the PHP script defined for the HMENU special type "userdefined".
766 * This script is supposed to populate the array $menuItemsArray with a set of page records comprising the menu.
767 * The "userdefined" type is depreciated since "userfunction" has arrived since and is a better choice for many reasons (like using classes/functions for rendering the menu)
768 *
769 * @param array TypoScript parameters for "special.". In particular the property "file" is reserved and specifies the file to include. Seems like any other property can be used freely by the script.
770 * @param string The sorting field. Can be used from the script in the $incFile.
771 * @return array An array with the menu items
772 * @access private
773 */
774 function includeMakeMenu($conf,$altSortField) {
775 $incFile = $GLOBALS['TSFE']->tmpl->getFileName($conf['file']);
776 if ($incFile && $GLOBALS['TSFE']->checkFileInclude($incFile)) {
777 include($incFile);
778 }
779 return is_array($menuItemsArray) ? $menuItemsArray : array();
780 }
781
782 /**
783 * Generating the per-menu-item configuration arrays based on the settings for item states (NO, RO, ACT, CUR etc) set in ->mconf (config for the current menu object)
784 * Basically it will produce an individual array for each menu item based on the item states. BUT in addition the "optionSplit" syntax for the values is ALSO evaluated here so that all property-values are "option-splitted" and the output will thus be resolved.
785 * Is called from the "generate" functions in the extension classes. The function is processor intensive due to the option split feature in particular. But since the generate function is not always called (since the ->result array may be cached, see makeMenu) it doesn't hurt so badly.
786 *
787 * @param integer Number of menu items in the menu
788 * @return array An array with two keys: array($NOconf,$ROconf) - where $NOconf contains the resolved configuration for each item when NOT rolled-over and $ROconf contains the ditto for the mouseover state (if any)
789 * @access private
790 */
791 function procesItemStates($splitCount) {
792
793 // Prepare normal settings
794 if (!is_array($this->mconf['NO.']) && $this->mconf['NO']) $this->mconf['NO.']=array(); // Setting a blank array if NO=1 and there are no properties.
795 $NOconf = $this->tmpl->splitConfArray($this->mconf['NO.'],$splitCount);
796
797 // Prepare rollOver settings, overriding normal settings
798 $ROconf=array();
799 if ($this->mconf['RO']) {
800 $ROconf = $this->tmpl->splitConfArray($this->mconf['RO.'],$splitCount);
801 }
802
803 // Prepare IFSUB settings, overriding normal settings
804 // IFSUB is true if there exist submenu items to the current item
805 if ($this->mconf['IFSUB']) {
806 $IFSUBinit = 0; // Flag: If $IFSUB is generated
807 reset($NOconf);
808 while (list($key,$val)=each($NOconf)) {
809 if ($this->isItemState('IFSUB',$key)) {
810 if (!$IFSUBinit) { // if this is the first IFSUB element, we must generate IFSUB.
811 $IFSUBconf = $this->tmpl->splitConfArray($this->mconf['IFSUB.'],$splitCount);
812 if ($this->mconf['IFSUBRO']) {
813 $IFSUBROconf = $this->tmpl->splitConfArray($this->mconf['IFSUBRO.'],$splitCount);
814 }
815 $IFSUBinit = 1;
816 }
817 $NOconf[$key] = $IFSUBconf[$key]; // Substitute normal with ifsub
818 if ($ROconf) { // If rollOver on normal, we must apply a state for rollOver on the active
819 $ROconf[$key] = $IFSUBROconf[$key] ? $IFSUBROconf[$key] : $IFSUBconf[$key]; // If RollOver on active then apply this
820 }
821 }
822 }
823 }
824 // Prepare active settings, overriding normal settings
825 if ($this->mconf['ACT']) {
826 $ACTinit = 0; // Flag: If $ACT is generated
827 reset($NOconf);
828 while (list($key,$val)=each($NOconf)) { // Find active
829 if ($this->isItemState('ACT',$key)) {
830 if (!$ACTinit) { // if this is the first active, we must generate ACT.
831 $ACTconf = $this->tmpl->splitConfArray($this->mconf['ACT.'],$splitCount);
832 // Prepare active rollOver settings, overriding normal active settings
833 if ($this->mconf['ACTRO']) {
834 $ACTROconf = $this->tmpl->splitConfArray($this->mconf['ACTRO.'],$splitCount);
835 }
836 $ACTinit = 1;
837 }
838 $NOconf[$key] = $ACTconf[$key]; // Substitute normal with active
839 if ($ROconf) { // If rollOver on normal, we must apply a state for rollOver on the active
840 $ROconf[$key] = $ACTROconf[$key] ? $ACTROconf[$key] : $ACTconf[$key]; // If RollOver on active then apply this
841 }
842 }
843 }
844 }
845 // Prepare active/IFSUB settings, overriding normal settings
846 // ACTIFSUB is true if there exist submenu items to the current item and the current item is active
847 if ($this->mconf['ACTIFSUB']) {
848 $ACTIFSUBinit = 0; // Flag: If $ACTIFSUB is generated
849 reset($NOconf);
850 while (list($key,$val)=each($NOconf)) { // Find active
851 if ($this->isItemState('ACTIFSUB',$key)) {
852 if (!$ACTIFSUBinit) { // if this is the first active, we must generate ACTIFSUB.
853 $ACTIFSUBconf = $this->tmpl->splitConfArray($this->mconf['ACTIFSUB.'],$splitCount);
854 // Prepare active rollOver settings, overriding normal active settings
855 if ($this->mconf['ACTIFSUBRO']) {
856 $ACTIFSUBROconf = $this->tmpl->splitConfArray($this->mconf['ACTIFSUBRO.'],$splitCount);
857 }
858 $ACTIFSUBinit = 1;
859 }
860 $NOconf[$key] = $ACTIFSUBconf[$key]; // Substitute normal with active
861 if ($ROconf) { // If rollOver on normal, we must apply a state for rollOver on the active
862 $ROconf[$key] = $ACTIFSUBROconf[$key] ? $ACTIFSUBROconf[$key] : $ACTIFSUBconf[$key]; // If RollOver on active then apply this
863 }
864 }
865 }
866 }
867 // Prepare CUR (current) settings, overriding normal settings
868 // CUR is true if the current page equals the item here!
869 if ($this->mconf['CUR']) {
870 $CURinit = 0; // Flag: If $CUR is generated
871 reset($NOconf);
872 while (list($key,$val)=each($NOconf)) {
873 if ($this->isItemState('CUR',$key)) {
874 if (!$CURinit) { // if this is the first 'current', we must generate CUR. Basically this control is just inherited from the other implementations as current would only exist one time and thats it (unless you use special-features of HMENU)
875 $CURconf = $this->tmpl->splitConfArray($this->mconf['CUR.'],$splitCount);
876 if ($this->mconf['CURRO']) {
877 $CURROconf = $this->tmpl->splitConfArray($this->mconf['CURRO.'],$splitCount);
878 }
879 $CURinit = 1;
880 }
881 $NOconf[$key] = $CURconf[$key]; // Substitute normal with current
882 if ($ROconf) { // If rollOver on normal, we must apply a state for rollOver on the active
883 $ROconf[$key] = $CURROconf[$key] ? $CURROconf[$key] : $CURconf[$key]; // If RollOver on active then apply this
884 }
885 }
886 }
887 }
888 // Prepare active settings, overriding normal settings
889 if ($this->mconf['USR']) {
890 $USRinit = 0; // Flag: If $USR is generated
891 reset($NOconf);
892 while (list($key,$val)=each($NOconf)) { // Find active
893 if ($this->isItemState('USR',$key)) {
894 if (!$USRinit) { // if this is the first active, we must generate USR.
895 $USRconf = $this->tmpl->splitConfArray($this->mconf['USR.'],$splitCount);
896 // Prepare active rollOver settings, overriding normal active settings
897 if ($this->mconf['USRRO']) {
898 $USRROconf = $this->tmpl->splitConfArray($this->mconf['USRRO.'],$splitCount);
899 }
900 $USRinit = 1;
901 }
902 $NOconf[$key] = $USRconf[$key]; // Substitute normal with active
903 if ($ROconf) { // If rollOver on normal, we must apply a state for rollOver on the active
904 $ROconf[$key] = $USRROconf[$key] ? $USRROconf[$key] : $USRconf[$key]; // If RollOver on active then apply this
905 }
906 }
907 }
908 }
909 // Prepare spacer settings, overriding normal settings
910 if ($this->mconf['SPC']) {
911 $SPCinit = 0; // Flag: If $SPC is generated
912 reset($NOconf);
913 while (list($key,$val)=each($NOconf)) { // Find spacers
914 if ($this->isItemState('SPC',$key)) {
915 if (!$SPCinit) { // if this is the first spacer, we must generate SPC.
916 $SPCconf = $this->tmpl->splitConfArray($this->mconf['SPC.'],$splitCount);
917 $SPCinit = 1;
918 }
919 $NOconf[$key] = $SPCconf[$key]; // Substitute normal with spacer
920 }
921 }
922 }
923 // Prepare Userdefined settings
924 if ($this->mconf['USERDEF1']) {
925 $USERDEF1init = 0; // Flag: If $USERDEF1 is generated
926 reset($NOconf);
927 while (list($key,$val)=each($NOconf)) { // Find active
928 if ($this->isItemState('USERDEF1',$key)) {
929 if (!$USERDEF1init) { // if this is the first active, we must generate USERDEF1.
930 $USERDEF1conf = $this->tmpl->splitConfArray($this->mconf['USERDEF1.'],$splitCount);
931 // Prepare active rollOver settings, overriding normal active settings
932 if ($this->mconf['USERDEF1RO']) {
933 $USERDEF1ROconf = $this->tmpl->splitConfArray($this->mconf['USERDEF1RO.'],$splitCount);
934 }
935 $USERDEF1init = 1;
936 }
937 $NOconf[$key] = $USERDEF1conf[$key]; // Substitute normal with active
938 if ($ROconf) { // If rollOver on normal, we must apply a state for rollOver on the active
939 $ROconf[$key] = $USERDEF1ROconf[$key] ? $USERDEF1ROconf[$key] : $USERDEF1conf[$key]; // If RollOver on active then apply this
940 }
941 }
942 }
943 }
944 // Prepare Userdefined settings
945 if ($this->mconf['USERDEF2']) {
946 $USERDEF2init = 0; // Flag: If $USERDEF2 is generated
947 reset($NOconf);
948 while (list($key,$val)=each($NOconf)) { // Find active
949 if ($this->isItemState('USERDEF2',$key)) {
950 if (!$USERDEF2init) { // if this is the first active, we must generate USERDEF2.
951 $USERDEF2conf = $this->tmpl->splitConfArray($this->mconf['USERDEF2.'],$splitCount);
952 // Prepare active rollOver settings, overriding normal active settings
953 if ($this->mconf['USERDEF2RO']) {
954 $USERDEF2ROconf = $this->tmpl->splitConfArray($this->mconf['USERDEF2RO.'],$splitCount);
955 }
956 $USERDEF2init = 1;
957 }
958 $NOconf[$key] = $USERDEF2conf[$key]; // Substitute normal with active
959 if ($ROconf) { // If rollOver on normal, we must apply a state for rollOver on the active
960 $ROconf[$key] = $USERDEF2ROconf[$key] ? $USERDEF2ROconf[$key] : $USERDEF2conf[$key]; // If RollOver on active then apply this
961 }
962 }
963 }
964 }
965
966 return array($NOconf,$ROconf);
967 }
968
969 /**
970 * Creates the URL, target and onclick values for the menu item link. Returns them in an array as key/value pairs for <A>-tag attributes
971 *
972 * @param integer Pointer to a key in the $this->menuArr array where the value for that key represents the menu item we are linking to (page record)
973 * @param string Alternative target
974 * @param integer Alternative type
975 * @return array Returns an array with A-tag attributes as key/value pairs (HREF, TARGET and onClick)
976 * @access private
977 */
978 function link($key,$altTarget='',$typeOverride='') {
979 // this function doesn't care about the url, because if we let the url be redirected, it will be logged in the stat!!!
980 if ($this->mconf['overrideId'] || $this->menuArr[$key]['overrideId']) { // RF 22/10
981 $overrideArray = array();
982 // if a user script returned the value overrideId in the menu array we use that as page id
983 $overrideArray['uid'] = $this->mconf['overrideId']?$this->mconf['overrideId']:$this->menuArr[$key]['overrideId']; // RF 22/10
984 $overrideArray['alias'] = '';
985 } else {
986 $overrideArray='';
987 }
988 $mainTarget = $altTarget ? $altTarget : $this->mconf['target'];
989
990 // Mount points:
991 $MP_var = $this->getMPvar($key);
992 $MP_params = $MP_var ? '&MP='.rawurlencode($MP_var) : '';
993
994 if ($this->mconf['collapse'] && $this->isActive($this->menuArr[$key]['uid'], $this->getMPvar($key))) {
995 $thePage = $this->sys_page->getPage($this->menuArr[$key]['pid']);
996 $LD = $this->tmpl->linkData($thePage,$mainTarget,'','',$overrideArray, $this->mconf['addParams'].$MP_params, $typeOverride);
997 } else {
998 $LD = $this->tmpl->linkData($this->menuArr[$key],$mainTarget,'','',$overrideArray, $this->mconf['addParams'].$MP_params, $typeOverride);
999 }
1000
1001 // Overriding URL / Target if set to do so:
1002 if ($this->menuArr[$key]['_OVERRIDE_HREF']) {
1003 $LD['totalURL'] = $this->menuArr[$key]['_OVERRIDE_HREF'];
1004 if ($this->menuArr[$key]['_OVERRIDE_TARGET']) $LD['target'] = $this->menuArr[$key]['_OVERRIDE_TARGET'];
1005 }
1006
1007 // OnClick open in windows.
1008 $onClick='';
1009 if ($this->mconf['JSWindow']) {
1010 $conf=$this->mconf['JSWindow.'];
1011 $url=$LD['totalURL'];
1012 $LD['totalURL'] = '#';
1013 $onClick= 'openPic(\''.$url.'\',\''.($conf['newWindow']?md5($url):'theNewPage').'\',\''.$conf['params'].'\'); return false;';
1014 $GLOBALS['TSFE']->setJS('openPic');
1015 }
1016 // out:
1017 $list = array();
1018 $list['HREF']=$LD['totalURL'];
1019 $list['TARGET']=$LD['target'];
1020 $list['onClick']=$onClick;
1021
1022 return $list;
1023 }
1024
1025 /**
1026 * Creates a submenu level to the current level - if configured for.
1027 *
1028 * @param integer Page id of the current page for which a submenu MAY be produced (if conditions are met)
1029 * @return string HTML content of the submenu
1030 * @access private
1031 */
1032 function subMenu($uid) {
1033
1034 // Setting alternative menu item array if _SUB_MENU has been defined in the current ->menuArr
1035 $altArray = '';
1036 if (is_array($this->menuArr[$this->I['key']]['_SUB_MENU']) && count($this->menuArr[$this->I['key']]['_SUB_MENU'])) {
1037 $altArray = $this->menuArr[$this->I['key']]['_SUB_MENU'];
1038 }
1039
1040 // Make submenu if the page is the next active
1041 if ($this->subLevelClass && ($this->mconf['expAll'] || $this->isNext($uid, $this->getMPvar($this->I['key'])) || is_array($altArray)) && !$this->mconf['sectionIndex']) {
1042 $submenu = t3lib_div::makeInstance('tslib_'.$this->subLevelClass);
1043 $submenu->entryLevel = $this->entryLevel+1;
1044 $submenu->rL_uidRegister = $this->rL_uidRegister;
1045 $submenu->MP_array = $this->MP_array;
1046 if ($this->menuArr[$this->I['key']]['_MP_PARAM']) {
1047 $submenu->MP_array[] = $this->menuArr[$this->I['key']]['_MP_PARAM'];
1048 }
1049
1050 // especially scripts that build the submenu needs the parent data
1051 $submenu->parentMenuArr = $this->menuArr;
1052
1053 // Setting alternativeMenuTempArray (will be effective only if an array)
1054 if (is_array($altArray)) {
1055 $submenu->alternativeMenuTempArray = $altArray;
1056 }
1057
1058 if ($submenu->start($this->tmpl, $this->sys_page, $uid, $this->conf, $this->menuNumber+1)) {
1059 $submenu->makeMenu();
1060 return $submenu->writeMenu();
1061 }
1062 }
1063 }
1064
1065 /**
1066 * Returns true if the page with UID $uid is the NEXT page in root line (which means a submenu should be drawn)
1067 *
1068 * @param integer Page uid to evaluate.
1069 * @param string MPvar for the current position of item.
1070 * @return boolean True if page with $uid is active
1071 * @access private
1072 * @see subMenu()
1073 */
1074 function isNext($uid, $MPvar='') {
1075 $testUid = $uid.($MPvar?':'.$MPvar:'');
1076 if ($uid && $testUid==$this->nextActive) {
1077 return TRUE;
1078 }
1079 }
1080
1081 /**
1082 * Returns true if the page with UID $uid is active (in the current rootline)
1083 *
1084 * @param integer Page uid to evaluate.
1085 * @param string MPvar for the current position of item.
1086 * @return boolean True if page with $uid is active
1087 * @access private
1088 */
1089 function isActive($uid, $MPvar='') {
1090 $testUid = $uid.($MPvar?':'.$MPvar:'');
1091 if ($uid && in_array('ITEM:'.$testUid, $this->rL_uidRegister)) {
1092 return TRUE;
1093 }
1094 }
1095
1096 /**
1097 * Returns true if the page with UID $uid is the CURRENT page (equals $GLOBALS['TSFE']->id)
1098 *
1099 * @param integer Page uid to evaluate.
1100 * @param string MPvar for the current position of item.
1101 * @return boolean True if page $uid = $GLOBALS['TSFE']->id
1102 * @access private
1103 */
1104 function isCurrent($uid, $MPvar='') {
1105 $testUid = $uid.($MPvar?':'.$MPvar:'');
1106 if ($uid && !strcmp(end($this->rL_uidRegister),'ITEM:'.$testUid)) {
1107 return TRUE;
1108 }
1109 }
1110
1111 /**
1112 * Returns true if there is a submenu with items for the page id, $uid
1113 * Used by the item states "IFSUB" and "ACTIFSUB" to check if there is a submenu
1114 *
1115 * @param integer Page uid for which to search for a submenu
1116 * @return boolean Returns true if there was a submenu with items found
1117 * @access private
1118 */
1119 function isSubMenu($uid) {
1120
1121 // Looking for a mount-pid for this UID since if that exists we should look for a subpages THERE and not in the input $uid;
1122 $mount_info = $this->sys_page->getMountPointInfo($uid);
1123 if (is_array($mount_info)) {
1124 $uid = $mount_info['mount_pid'];
1125 }
1126
1127 $recs = $this->sys_page->getMenu($uid,'uid,pid,doktype,mount_pid,mount_pid_ol');
1128 foreach($recs as $theRec) {
1129 if (!t3lib_div::inList('5,6',$theRec['doktype'])) { // If a menu item seems to be another type than 'Not in menu', then return true (there were items!)
1130 return TRUE;
1131 }
1132 }
1133 }
1134
1135 /**
1136 * Used by procesItemStates() to evaluate if a menu item (identified by $key) is in a certain state.
1137 *
1138 * @param string The item state to evaluate (SPC, IFSUB, ACT etc... but no xxxRO states of course)
1139 * @param integer Key pointing to menu item from ->menuArr
1140 * @return boolean True (integer!=0) if match, otherwise false (=0, zero)
1141 * @access private
1142 * @see procesItemStates()
1143 */
1144 function isItemState($kind,$key) {
1145 $natVal=0;
1146 if ($this->menuArr[$key]['ITEM_STATE']) { // If any value is set for ITEM_STATE the normal evaluation is discarded
1147 if (!strcmp($this->menuArr[$key]['ITEM_STATE'],$kind)) { $natVal=1; }
1148 } else {
1149 switch($kind) {
1150 case 'SPC':
1151 $natVal = $this->menuArr[$key]['isSpacer'];
1152 break;
1153 case 'IFSUB':
1154 $natVal = $this->isSubMenu($this->menuArr[$key]['uid']);
1155 break;
1156 case 'ACT':
1157 $natVal = $this->isActive($this->menuArr[$key]['uid'], $this->getMPvar($key));
1158 break;
1159 case 'ACTIFSUB':
1160 $natVal = $this->isActive($this->menuArr[$key]['uid'], $this->getMPvar($key)) && $this->isSubMenu($this->menuArr[$key]['uid']);
1161 break;
1162 case 'CUR':
1163 $natVal = $this->isCurrent($this->menuArr[$key]['uid'], $this->getMPvar($key));
1164 break;
1165 case 'USR':
1166 $natVal = $this->menuArr[$key]['fe_group'];
1167 break;
1168 }
1169 }
1170
1171 return $natVal;
1172 }
1173
1174 /**
1175 * Creates an access-key for a GMENU menu item based on the menu item titles first letter
1176 *
1177 * @param string Menu item title.
1178 * @return array Returns an array with keys "code" ("accesskey" attribute for the img-tag) and "alt" (text-addition to the "alt" attribute) if an access key was defined. Otherwise array was empty
1179 * @access private
1180 */
1181 function accessKey($title) {
1182 // The global array ACCESSKEY is used to globally control if letters are already used!!
1183 $result = Array();
1184
1185 $titleLen = strlen($title);
1186 for ($a=0;$a<$titleLen;$a++) {
1187 $key = strtoupper(trim(substr($title,$a,1)));
1188 if ($key && !isset($GLOBALS['TSFE']->accessKey[$key])) {
1189 $GLOBALS['TSFE']->accessKey[$key]=1;
1190 $result['code'] = ' accesskey="'.$key.'"';
1191 $result['alt'] = ' (ALT+'.$key.')';
1192 break;
1193 }
1194 }
1195 return $result;
1196 }
1197
1198 /**
1199 * Calls a user function for processing of internal data.
1200 * Used for the properties "IProcFunc" and "itemArrayProcFunc"
1201 *
1202 * @param string Key pointing for the property in the current ->mconf array holding possibly parameters to pass along to the function/method. Currently the keys used are "IProcFunc" and "itemArrayProcFunc".
1203 * @param mixed A variable to pass to the user function and which should be returned again from the user function. The idea is that the user function modifies this variable according to what you want to achieve and then returns it. For "itemArrayProcFunc" this variable is $this->menuArr, for "IProcFunc" it is $this->I
1204 * @return mixed The processed $passVar
1205 * @access private
1206 */
1207 function userProcess($mConfKey,$passVar) {
1208 if ($this->mconf[$mConfKey]) {
1209 $funcConf = $this->mconf[$mConfKey.'.'];
1210 $funcConf['parentObj']=&$this;
1211 $passVar = $GLOBALS['TSFE']->cObj->callUserFunction($this->mconf[$mConfKey], $funcConf, $passVar);
1212 }
1213 return $passVar;
1214 }
1215
1216 /**
1217 * Creates the <A> tag parts for the current item (in $this->I, [A1] and [A2]) based on other information in this array (like $this->I['linkHREF'])
1218 *
1219 * @return void
1220 * @access private
1221 */
1222 function setATagParts() {
1223 $this->I['A1'] = '<a '.t3lib_div::implodeParams($this->I['linkHREF'],1).$this->I['val']['ATagParams'].$this->I['addATagParams'].$this->I['accessKey']['code'].'>';
1224 $this->I['A2'] = '</a>';
1225 }
1226
1227 /**
1228 * Returns the title for the navigation
1229 *
1230 * @param string The current page title
1231 * @param string The current value of the naviation title
1232 * @return string Returns the navigation title if it is NOT blank, otherwise the page title.
1233 * @access private
1234 */
1235 function getPageTitle($title,$nav_title) {
1236 return strcmp(trim($nav_title),'') ? $nav_title : $title;
1237 }
1238
1239 /**
1240 * Return MPvar string for entry $key in ->menuArr
1241 *
1242 * @param integer Pointer to element in ->menuArr
1243 * @param string Implode token.
1244 * @return string MP vars for element.
1245 * @see link()
1246 */
1247 function getMPvar($key) {
1248 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['enable_mount_pids']) {
1249 $localMP_array = $this->MP_array;
1250 if ($this->menuArr[$key]['_MP_PARAM']) $localMP_array[] = $this->menuArr[$key]['_MP_PARAM']; // NOTICE: "_MP_PARAM" is allowed to be a commalist of PID pairs!
1251 $MP_params = count($localMP_array) ? implode(',',$localMP_array) : '';
1252 return $MP_params;
1253 }
1254 }
1255 }
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275 /**
1276 * Extension class creating text based menus
1277 *
1278 * @author Kasper Skaarhoj <kasper@typo3.com>
1279 * @package TYPO3
1280 * @subpackage tslib
1281 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=387&cHash=73a3116ab8
1282 */
1283 class tslib_tmenu extends tslib_menu {
1284
1285 /**
1286 * Calls procesItemStates() so that the common configuration for the menu items are resolved into individual configuration per item.
1287 * Sets the result for the new "normal state" in $this->result
1288 *
1289 * @return void
1290 * @see tslib_menu::procesItemStates()
1291 */
1292 function generate() {
1293 $splitCount = count($this->menuArr);
1294 if ($splitCount) {
1295 list($NOconf) = $this->procesItemStates($splitCount);
1296 }
1297 if ($this->mconf['debugItemConf']) {echo '<h3>$NOconf:</h3>'; debug($NOconf); }
1298 $this->result = $NOconf;
1299 }
1300
1301 /**
1302 * Traverses the ->result array of menu items configuration (made by ->generate()) and renders each item.
1303 * During the execution of this function many internal methods prefixed "extProc_" from this class is called and many of these are for now dummy functions. But they can be used for processing as they are used by the TMENU_LAYERS
1304 * An instance of tslib_cObj is also made and for each menu item rendered it is loaded with the record for that page so that any stdWrap properties that applies will have the current menu items record available.
1305 *
1306 * @return string The HTML for the menu (returns result through $this->extProc_finish(); )
1307 */
1308 function writeMenu() {
1309 if (is_array($this->result) && count($this->result)) {
1310 $this->WMcObj =t3lib_div::makeInstance('tslib_cObj'); // Create new tslib_cObj for our use
1311 $this->WMresult='';
1312 $this->INPfixMD5 = substr(md5(microtime().'tmenu'),0,4);
1313 $this->WMmenuItems = count($this->result);
1314 $this->extProc_init();
1315 reset($this->result);
1316 while (list($key,$val)=each($this->result)) {
1317 $GLOBALS['TSFE']->register['count_HMENU_MENUOBJ']++;
1318 $GLOBALS['TSFE']->register['count_MENUOBJ']++;
1319
1320 $this->I=array();
1321 $this->WMcObj->start($this->menuArr[$key],'pages'); // Initialize the cObj with the page record of the menu item
1322 $this->I['key'] = $key;
1323 $this->I['INPfix']= $this->imgNameNotRandom?'':'_'.$this->INPfixMD5.'_'.$key;
1324 $this->I['val'] = $val;
1325 $this->I['title'] = $this->WMcObj->stdWrap($this->getPageTitle($this->menuArr[$key]['title'],$this->menuArr[$key]['nav_title']),$this->I['val']['stdWrap.']);
1326 $this->I['uid'] = $this->menuArr[$key]['uid'];
1327 $this->I['mount_pid'] = $this->menuArr[$key]['mount_pid'];
1328 $this->I['pid'] = $this->menuArr[$key]['pid'];
1329 $this->I['spacer'] = $this->menuArr[$key]['isSpacer'];
1330
1331 // Make link tag
1332 $this->I['val']['ATagParams'] = $this->I['val']['ATagParams'] ? ' '.$this->I['val']['ATagParams'] : '';
1333 $this->I['linkHREF'] = $this->link($key,$this->I['val']['altTarget'],$this->mconf['forceTypeValue']);
1334
1335 if (!$this->mconf['noBlur']) {
1336 $this->I['linkHREF']['onFocus']='blurLink(this);';
1337 }
1338
1339 // Make link:
1340 if ($this->I['val']['RO']) {
1341 $this->I['theName'] = $this->imgNamePrefix.$this->I['uid'].$this->I['INPfix'];
1342 $over='';
1343 $out ='';
1344 if ($this->I['val']['beforeROImg']) {
1345 $over.= $this->WMfreezePrefix."over('".$this->I['theName']."before');";
1346 $out.= $this->WMfreezePrefix."out('".$this->I['theName']."before');";
1347 }
1348 if ($this->I['val']['afterROImg']) {
1349 $over.= $this->WMfreezePrefix."over('".$this->I['theName']."after');";
1350 $out.= $this->WMfreezePrefix."out('".$this->I['theName']."after');";
1351 }
1352 $this->I['linkHREF']['onMouseover']=$over;
1353 $this->I['linkHREF']['onMouseout']=$out;
1354 if ($over || $out) $GLOBALS['TSFE']->setJS('mouseOver');
1355
1356 // Change background color:
1357 if ($this->I['val']['RO_chBgColor']) {
1358 $this->addJScolorShiftFunction();
1359 $chBgP = t3lib_div::trimExplode('|',$this->I['val']['RO_chBgColor']);
1360 $this->I['linkHREF']['onMouseover'].="changeBGcolor('".$chBgP[2].$this->I['uid']."','".$chBgP[0]."');";
1361 $this->I['linkHREF']['onMouseout'].="changeBGcolor('".$chBgP[2].$this->I['uid']."','".$chBgP[1]."');";
1362 }
1363
1364 $this->extProc_RO($key);
1365 }
1366
1367
1368
1369 // Calling extra processing function
1370 $this->extProc_beforeLinking($key);
1371
1372 // Compile link tag
1373 if (!$this->I['val']['doNotLinkIt']) {$this->I['val']['doNotLinkIt']=0;}
1374 if (!$this->I['val']['isSpacer'] && $this->I['val']['doNotLinkIt']!=1) {
1375 $this->setATagParts();
1376 } else {
1377 $this->I['A1'] = '';
1378 $this->I['A2'] = '';
1379 }
1380
1381 // ATAGBeforeWrap processing:
1382 if ($this->I['val']['ATagBeforeWrap']) {
1383 $wrapPartsBefore = explode('|',$this->I['val']['linkWrap']);
1384 $wrapPartsAfter = array('','');
1385 } else {
1386 $wrapPartsBefore = array('','');
1387 $wrapPartsAfter = explode('|',$this->I['val']['linkWrap']);
1388 }
1389 if ($this->I['val']['stdWrap2'] || isset($this->I['val']['stdWrap2.'])) {
1390 $wrapPartsStdWrap = explode($this->I['val']['stdWrap2']?$this->I['val']['stdWrap2']:'|',$this->WMcObj->stdWrap('|',$this->I['val']['stdWrap2.']));
1391 } else {$wrapPartsStdWrap = array('','');}
1392
1393 // Make before, middle and after parts
1394 $this->I['parts'] = array();
1395 $this->I['parts']['before']=$this->getBeforeAfter('before');
1396 $this->I['parts']['stdWrap2_begin']=$wrapPartsStdWrap[0];
1397 if (!$this->I['val']['doNotShowLink']) {
1398 $this->I['parts']['notATagBeforeWrap_begin'] = $wrapPartsAfter[0];
1399 $this->I['parts']['ATag_begin'] = $this->I['A1'];
1400 $this->I['parts']['ATagBeforeWrap_begin'] = $wrapPartsBefore[0];
1401 $this->I['parts']['title'] = $this->I['title'];
1402 $this->I['parts']['ATagBeforeWrap_end'] = $wrapPartsBefore[1];
1403 $this->I['parts']['ATag_end'] = $this->I['A2'];
1404 $this->I['parts']['notATagBeforeWrap_end'] = $wrapPartsAfter[1];
1405 }
1406 $this->I['parts']['stdWrap2_end']=$wrapPartsStdWrap[1];
1407 $this->I['parts']['after']=$this->getBeforeAfter('after');
1408
1409 // Passing I to a user function
1410 if ($this->mconf['IProcFunc']) {
1411 $this->I = $this->userProcess('IProcFunc',$this->I);
1412 }
1413
1414 // Merge parts + beforeAllWrap
1415 $this->I['theItem']= implode('',$this->I['parts']);
1416 $this->I['theItem']= $this->extProc_beforeAllWrap($this->I['theItem'],$key);
1417
1418 // allWrap:
1419 $allWrap = $this->WMcObj->stdWrap($this->I['val']['allWrap'],$this->I['val']['allWrap.']);
1420 $this->I['theItem'] = $this->tmpl->wrap($this->I['theItem'],$allWrap);
1421
1422 if ($this->I['val']['subst_elementUid']) $this->I['theItem'] = str_replace('{elementUid}',$this->I['uid'],$this->I['theItem']);
1423
1424 // Calling extra processing function
1425 $this->extProc_afterLinking($key);
1426 }
1427 return $this->extProc_finish();
1428 }
1429 }
1430
1431 /**
1432 * Generates the before* and after* images for TMENUs
1433 *
1434 * @param string Can be "before" or "after" and determines which kind of image to create (basically this is the prefix of the TypoScript properties that are read from the ->I['val'] array
1435 * @return string The resulting HTML of the image, if any.
1436 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=388&cHash=a7486044cd
1437 */
1438 function getBeforeAfter($pref) {
1439 $res = '';
1440 if ($imgInfo = $this->WMcObj->getImgResource($this->I['val'][$pref.'Img'],$this->I['val'][$pref.'Img.'])) {
1441 $imgInfo[3] = t3lib_div::png_to_gif_by_imagemagick($imgInfo[3]);
1442 if ($this->I['val']['RO'] && $this->I['val'][$pref.'ROImg'] && !$this->I['val']['isSpacer']) {
1443 $imgROInfo = $this->WMcObj->getImgResource($this->I['val'][$pref.'ROImg'],$this->I['val'][$pref.'ROImg.']);
1444 $imgROInfo[3] = t3lib_div::png_to_gif_by_imagemagick($imgROInfo[3]);
1445 if ($imgROInfo) {
1446 $theName = $this->imgNamePrefix.$this->I['uid'].$this->I['INPfix'].$pref;
1447 $name = ' name="'.$theName.'"';
1448 $GLOBALS['TSFE']->JSImgCode.= chr(10).$theName.'_n=new Image(); '.$theName.'_n.src = "'.$GLOBALS['TSFE']->absRefPrefix.$imgInfo[3].'"; ';
1449 $GLOBALS['TSFE']->JSImgCode.= chr(10).$theName.'_h=new Image(); '.$theName.'_h.src = "'.$GLOBALS['TSFE']->absRefPrefix.$imgROInfo[3].'"; ';
1450 }
1451 }
1452 $GLOBALS['TSFE']->imagesOnPage[]=$imgInfo[3];
1453 $res='<img src="'.$GLOBALS['TSFE']->absRefPrefix.$imgInfo[3].'" width="'.$imgInfo[0].'" height="'.$imgInfo[1].'"'.$name.($this->I['val'][$pref.'ImgTagParams']?" ".$this->I['val'][$pref.'ImgTagParams']:'').' border="0"';
1454 if (!strstr($res,'alt="')) $res.=' alt=""'; // Adding alt attribute if not set.
1455 $res.=' />';
1456 if ($this->I['val'][$pref.'ImgLink']) {$res=$this->I['A1'].$res.$this->I['A2'];}
1457 }
1458 return $this->tmpl->wrap($res.$this->WMcObj->stdWrap($this->I['val'][$pref],$this->I['val'][$pref.'.']), $this->I['val'][$pref.'Wrap']);
1459 }
1460
1461 /**
1462 * Adds a JavaScript function to the $GLOBALS['TSFE']->additionalJavaScript array
1463 *
1464 * @return void
1465 * @access private
1466 * @see writeMenu()
1467 */
1468 function addJScolorShiftFunction() {
1469 $GLOBALS['TSFE']->additionalJavaScript['TMENU:changeBGcolor()']='
1470 function changeBGcolor(id,color) { //
1471 if (document.getElementById && document.getElementById(id)) {
1472 document.getElementById(id).style.background = color;
1473 return true;
1474 } else if (document.layers && document.layers[id]) {
1475 document.layers[id].bgColor = color;
1476 return true;
1477 }
1478 }
1479 ';
1480 }
1481
1482 /**
1483 * Called right before the traversing of $this->result begins.
1484 * Can be used for various initialization
1485 *
1486 * @return void
1487 * @access private
1488 * @see writeMenu(), tslib_tmenu_layers::extProc_init()
1489 */
1490 function extProc_init() {
1491 }
1492
1493 /**
1494 * Called after all processing for RollOver of an element has been done.
1495 *
1496 * @param integer Pointer to $this->menuArr[$key] where the current menu element record is found
1497 * @return void
1498 * @access private
1499 * @see writeMenu(), tslib_tmenu_layers::extProc_RO()
1500 */
1501 function extProc_RO($key) {
1502 }
1503
1504 /**
1505 * Called right before the creation of the link for the menu item
1506 *
1507 * @param integer Pointer to $this->menuArr[$key] where the current menu element record is found
1508 * @return void
1509 * @access private
1510 * @see writeMenu(), tslib_tmenu_layers::extProc_beforeLinking()
1511 */
1512 function extProc_beforeLinking($key) {
1513 }
1514
1515 /**
1516 * Called right after the creation of links for the menu item. This is also the last function call before the while-loop traversing menu items goes to the next item.
1517 * This function MUST set $this->WMresult.=[HTML for menu item] to add the generated menu item to the internal accumulation of items.
1518 *
1519 * @param integer Pointer to $this->menuArr[$key] where the current menu element record is found
1520 * @return void
1521 * @access private
1522 * @see writeMenu(), tslib_tmenu_layers::extProc_afterLinking()
1523 */
1524 function extProc_afterLinking($key) {
1525 // Add part to the accumulated result + fetch submenus
1526 if (!$this->I['spacer']) {
1527 $this->I['theItem'].= $this->subMenu($this->I['uid']);
1528 }
1529 $this->WMresult.= $this->I['val']['wrapItemAndSub'] ? $this->tmpl->wrap($this->I['theItem'],$this->I['val']['wrapItemAndSub']) : $this->I['theItem'];
1530 }
1531
1532 /**
1533 * Called before the "allWrap" happens on the menu item.
1534 *
1535 * @param string The current content of the menu item, $this->I['theItem'], passed along.
1536 * @param integer Pointer to $this->menuArr[$key] where the current menu element record is found
1537 * @return string The modified version of $item, going back into $this->I['theItem']
1538 * @access private
1539 * @see writeMenu(), tslib_tmenu_layers::extProc_beforeAllWrap()
1540 */
1541 function extProc_beforeAllWrap($item,$key) {
1542 return $item;
1543 }
1544
1545 /**
1546 * Called before the writeMenu() function returns (only if a menu was generated)
1547 *
1548 * @return string The total menu content should be returned by this function
1549 * @access private
1550 * @see writeMenu(), tslib_tmenu_layers::extProc_finish()
1551 */
1552 function extProc_finish() {
1553 return $this->tmpl->wrap($this->WMresult,$this->mconf['wrap']).$this->WMextraScript;
1554 }
1555 }
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580 /**
1581 * Extension class creating graphic based menus (PNG or GIF files)
1582 *
1583 * @author Kasper Skaarhoj <kasper@typo3.com>
1584 * @package TYPO3
1585 * @subpackage tslib
1586 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=384&cHash=93a7644cba
1587 */
1588 class tslib_gmenu extends tslib_menu {
1589
1590 /**
1591 * Calls procesItemStates() so that the common configuration for the menu items are resolved into individual configuration per item.
1592 * Calls makeGifs() for all "normal" items and if configured for, also the "rollover" items.
1593 *
1594 * @return void
1595 * @see tslib_menu::procesItemStates(), makeGifs()
1596 */
1597 function generate() {
1598 $splitCount = count($this->menuArr);
1599 if ($splitCount) {
1600 list($NOconf,$ROconf) = $this->procesItemStates($splitCount);
1601
1602 //store initial count value
1603 $temp_HMENU_MENUOBJ = $GLOBALS['TSFE']->register['count_HMENU_MENUOBJ'];
1604 $temp_MENUOBJ = $GLOBALS['TSFE']->register['count_MENUOBJ'];
1605 // Now we generate the giffiles:
1606 $this->makeGifs($NOconf,'NO');
1607 // store count from NO obj
1608 $tempcnt_HMENU_MENUOBJ = $GLOBALS['TSFE']->register['count_HMENU_MENUOBJ'];
1609 $tempcnt_MENUOBJ = $GLOBALS['TSFE']->register['count_MENUOBJ'];
1610
1611 if ($this->mconf['debugItemConf']) {echo '<h3>$NOconf:</h3>'; debug($NOconf); }
1612 if ($ROconf) { // RollOver
1613 //start recount for rollover with initial values
1614 $GLOBALS['TSFE']->register['count_HMENU_MENUOBJ']= $temp_HMENU_MENUOBJ;
1615 $GLOBALS['TSFE']->register['count_MENUOBJ']= $temp_MENUOBJ;
1616 $this->makeGifs($ROconf,'RO');
1617 if ($this->mconf['debugItemConf']) {echo '<h3>$ROconf:</h3>'; debug($ROconf); }
1618 }
1619 // use count from NO obj
1620 $GLOBALS['TSFE']->register['count_HMENU_MENUOBJ'] = $tempcnt_HMENU_MENUOBJ;
1621 $GLOBALS['TSFE']->register['count_MENUOBJ'] = $tempcnt_MENUOBJ;
1622 }
1623 }
1624
1625 /**
1626 * Will traverse input array with configuratoin per-item and create corresponding GIF files for the menu.
1627 * The data of the files are stored in $this->result
1628 *
1629 * @param array Array with configuration for each item.
1630 * @param string Type of images: normal ("NO") or rollover ("RO"). Valid values are "NO" and "RO"
1631 * @return void
1632 * @access private
1633 * @see generate()
1634 */
1635 function makeGifs($conf, $resKey) {
1636 $isGD = $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib'];
1637
1638 if (!is_array($conf)) {
1639 $conf = Array();
1640 }
1641
1642 $totalWH=array();
1643 $items = count($conf);
1644 if ($isGD) {
1645 // generate the gif-files. the $menuArr is filled with some values like output_w, output_h, output_file
1646 $Hcounter = 0;
1647 $Wcounter = 0;
1648 $Hobjs = $this->mconf['applyTotalH'];
1649 if ($Hobjs) {$Hobjs = t3lib_div::intExplode(',',$Hobjs);}
1650 $Wobjs = $this->mconf['applyTotalW'];
1651 if ($Wobjs) {$Wobjs = t3lib_div::intExplode(',',$Wobjs);}
1652 $minDim = $this->mconf['min'];
1653 if ($minDim) {$minDim = tslib_cObj::calcIntExplode(',',$minDim.',');}
1654 $maxDim = $this->mconf['max'];
1655 if ($maxDim) {$maxDim = tslib_cObj::calcIntExplode(',',$maxDim.',');}
1656
1657 if ($minDim) {
1658 $conf[$items]=$conf[$items-1];
1659 $this->menuArr[$items]=Array();
1660 $items = count($conf);
1661 }
1662
1663 // TOTAL width
1664 if ($this->mconf['useLargestItemX'] || $this->mconf['useLargestItemY'] || $this->mconf['distributeX'] || $this->mconf['distributeY']) {
1665 $totalWH = $this->findLargestDims($conf,$items,$Hobjs,$Wobjs,$minDim,$maxDim);
1666 }
1667 }
1668
1669 $c=0;
1670 $maxFlag=0;
1671 $distributeAccu=array('H'=>0,'W'=>0);
1672 reset($conf);
1673 while (list($key,$val)=each($conf)) {
1674 $GLOBALS['TSFE']->register['count_HMENU_MENUOBJ']++;
1675 $GLOBALS['TSFE']->register['count_MENUOBJ']++;
1676
1677 if ($items==($c+1) && $minDim) {
1678 $Lobjs = $this->mconf['removeObjectsOfDummy'];
1679 if ($Lobjs) {
1680 $Lobjs = t3lib_div::intExplode(',',$Lobjs);
1681 reset($Lobjs);
1682 while(list(,$remItem)=each($Lobjs)) {
1683 unset($val[$remItem]);
1684 unset($val[$remItem.'.']);
1685 }
1686 }
1687
1688 $flag =0;
1689 $tempXY = explode(',',$val['XY']);
1690 if ($Wcounter<$minDim[0]) {$tempXY[0]=$minDim[0]-$Wcounter; $flag=1;}
1691 if ($Hcounter<$minDim[1]) {$tempXY[1]=$minDim[1]-$Hcounter; $flag=1;}
1692 $val['XY'] = implode($tempXY,',');
1693 if (!$flag){break;}
1694 }
1695 $c++;
1696
1697
1698 if ($isGD) {
1699 // Pre-working the item
1700 $gifCreator = t3lib_div::makeInstance('tslib_gifBuilder');
1701 $gifCreator->init();
1702 $gifCreator->start($val,$this->menuArr[$key]);
1703
1704 // If useLargestItemH/W is specified
1705 if (count($totalWH) && ($this->mconf['useLargestItemX'] || $this->mconf['useLargestItemY'])) {
1706 $tempXY = explode(',',$gifCreator->setup['XY']);
1707 if ($this->mconf['useLargestItemX']) {$tempXY[0] = max($totalWH['W']);}
1708 if ($this->mconf['useLargestItemY']) {$tempXY[1] = max($totalWH['H']);}
1709 // regenerate the new values...
1710 $val['XY'] = implode($tempXY,',');
1711 $gifCreator = t3lib_div::makeInstance('tslib_gifBuilder');
1712 $gifCreator->init();
1713 $gifCreator->start($val,$this->menuArr[$key]);
1714 }
1715
1716 // If distributeH/W is specified
1717 if (count($totalWH) && ($this->mconf['distributeX'] || $this->mconf['distributeY'])) {
1718 $tempXY = explode(',',$gifCreator->setup['XY']);
1719
1720 if ($this->mconf['distributeX']) {
1721 $diff = $this->mconf['distributeX']-$totalWH['W_total']-$distributeAccu['W'];
1722 $compensate = round($diff /($items-$c+1));
1723 $distributeAccu['W']+=$compensate;
1724 $tempXY[0] = $totalWH['W'][$key]+$compensate;
1725 }
1726 if ($this->mconf['distributeY']) {
1727 $diff = $this->mconf['distributeY']-$totalWH['H_total']-$distributeAccu['H'];
1728 $compensate = round($diff /($items-$c+1));
1729 $distributeAccu['H']+=$compensate;
1730 $tempXY[1] = $totalWH['H'][$key]+$compensate;
1731 }
1732 // regenerate the new values...
1733 $val['XY'] = implode($tempXY,',');
1734 $gifCreator = t3lib_div::makeInstance('tslib_gifBuilder');
1735 $gifCreator->init();
1736 $gifCreator->start($val,$this->menuArr[$key]);
1737 }
1738
1739 // If max dimensions are specified
1740 if ($maxDim) {
1741 $tempXY = explode(',',$val['XY']);
1742 if ($maxDim[0] && $Wcounter+$gifCreator->XY[0]>=$maxDim[0]) {$tempXY[0]==$maxDim[0]-$Wcounter; $maxFlag=1;}
1743 if ($maxDim[1] && $Hcounter+$gifCreator->XY[1]>=$maxDim[1]) {$tempXY[1]=$maxDim[1]-$Hcounter; $maxFlag=1;}
1744 if ($maxFlag) {
1745 $val['XY'] = implode($tempXY,',');
1746 $gifCreator = t3lib_div::makeInstance('tslib_gifBuilder');
1747 $gifCreator->init();
1748 $gifCreator->start($val,$this->menuArr[$key]);
1749 }
1750 }
1751
1752
1753
1754
1755 // displace
1756 if ($Hobjs) {
1757 reset($Hobjs);
1758 while(list(,$index)=each($Hobjs)) {
1759 if ($gifCreator->setup[$index] && $gifCreator->setup[$index.'.']) {
1760 $oldOffset = explode(',',$gifCreator->setup[$index.'.']['offset']);
1761 $gifCreator->setup[$index.'.']['offset'] = implode($gifCreator->applyOffset($oldOffset,Array(0,-$Hcounter)), ',');
1762 }
1763 }
1764 }
1765
1766 if ($Wobjs) {
1767 reset($Wobjs);
1768 while(list(,$index)=each($Wobjs)) {
1769 if ($gifCreator->setup[$index] && $gifCreator->setup[$index.'.']) {
1770 $oldOffset = explode(',',$gifCreator->setup[$index.'.']['offset']);
1771 $gifCreator->setup[$index.'.']['offset'] = implode($gifCreator->applyOffset($oldOffset,Array(-$Wcounter,0)), ',');
1772 }
1773 }
1774 }
1775 }
1776
1777 // Finding alternative GIF names if any (by altImgResource)
1778 $gifFileName='';
1779 if ($conf[$key]['altImgResource'] || is_array($conf[$key]['altImgResource.'])) {
1780 if (!is_object($cObj)) {$cObj=t3lib_div::makeInstance('tslib_cObj');}
1781 $cObj->start($this->menuArr[$key],'pages');
1782 $altImgInfo = $cObj->getImgResource($conf[$key]['altImgResource'],$conf[$key]['altImgResource.']);
1783 $gifFileName=$altImgInfo[3];
1784 }
1785
1786 // If an alternative names was NOT given, find the GIFBUILDER name.
1787 if (!$gifFileName && $isGD) {
1788 $gifFileName = $gifCreator->fileName('m_');
1789 }
1790 // generation
1791 if (@file_exists($gifFileName)) { // File exists
1792 $info = @getimagesize($gifFileName);
1793 $this->result[$resKey][$key]['output_w']=intval($info[0]);
1794 $this->result[$resKey][$key]['output_h']=intval($info[1]);
1795 $this->result[$resKey][$key]['output_file']=$gifFileName;
1796 } elseif ($isGD) { // file is generated
1797 $gifCreator->make();
1798 $this->result[$resKey][$key]['output_w']=$gifCreator->w;
1799 $this->result[$resKey][$key]['output_h']=$gifCreator->h;
1800 $this->result[$resKey][$key]['output_file'] = $gifFileName;
1801 $gifCreator->output($this->result[$resKey][$key]['output_file']);
1802 $gifCreator->destroy();
1803 }
1804 $this->result[$resKey][$key]['output_file'] = t3lib_div::png_to_gif_by_imagemagick($this->result[$resKey][$key]['output_file']);
1805 $this->result[$resKey][$key]['wrap']=$conf[$key]['wrap'];
1806 $this->result[$resKey][$key]['noLink']=$conf[$key]['noLink'];
1807 $this->result[$resKey][$key]['altTarget']=$conf[$key]['altTarget'];
1808 $this->result[$resKey][$key]['imgParams']=$conf[$key]['imgParams'];
1809
1810 $Hcounter+=$this->result[$resKey][$key]['output_h']; // counter is increased
1811 $Wcounter+=$this->result[$resKey][$key]['output_w']; // counter is increased
1812
1813 if ($maxFlag){break;}
1814 }
1815 }
1816
1817 /**
1818 * Function searching for the largest width and height of the menu items to be generated.
1819 * Uses some of the same code as makeGifs and even instantiates some gifbuilder objects BUT does not render the images - only reading out which width they would have.
1820 * Remember to upgrade the code in here if the makeGifs function is updated.
1821 *
1822 * @param array Same configuration array as passed to makeGifs()
1823 * @param integer The number of menu items
1824 * @param array Array with "applyTotalH" numbers
1825 * @param array Array with "applyTotalW" numbers
1826 * @param array Array with "min" x/y
1827 * @param array Array with "max" x/y
1828 * @return array Array with keys "H" and "W" which are in themselves arrays with the heights and widths of menu items inside. This can be used to find the max/min size of the menu items.
1829 * @access private
1830 * @see makeGifs()
1831 */
1832 function findLargestDims($conf,$items,$Hobjs,$Wobjs,$minDim,$maxDim) {
1833 $totalWH = array(
1834 'W' => array(),
1835 'H' => array(),
1836 'W_total' => 0,
1837 'H_total' => 0
1838 );
1839
1840 $Hcounter = 0;
1841 $Wcounter = 0;
1842 $c=0;
1843 $maxFlag=0;
1844 reset($conf);
1845 while (list($key,$val)=each($conf)) {
1846 // SAME CODE AS makeGifs()! BEGIN
1847 if ($items==($c+1) && $minDim) {
1848 $Lobjs = $this->mconf['removeObjectsOfDummy'];
1849 if ($Lobjs) {
1850 $Lobjs = t3lib_div::intExplode(',',$Lobjs);
1851 reset($Lobjs);
1852 while(list(,$remItem)=each($Lobjs)) {
1853 unset($val[$remItem]);
1854 unset($val[$remItem.'.']);
1855 }
1856 }
1857
1858 $flag =0;
1859 $tempXY = explode(',',$val['XY']);
1860 if ($Wcounter<$minDim[0]) {$tempXY[0]=$minDim[0]-$Wcounter; $flag=1;}
1861 if ($Hcounter<$minDim[1]) {$tempXY[1]=$minDim[1]-$Hcounter; $flag=1;}
1862 $val['XY'] = implode($tempXY,',');
1863 if (!$flag){break;}
1864 }
1865 $c++;
1866
1867 $gifCreator = t3lib_div::makeInstance('tslib_gifBuilder');
1868 $gifCreator->init();
1869 $gifCreator->start($val,$this->menuArr[$key]);
1870 if ($maxDim) {
1871 $tempXY = explode(',',$val['XY']);
1872 if ($maxDim[0] && $Wcounter+$gifCreator->XY[0]>=$maxDim[0]) {$tempXY[0]==$maxDim[0]-$Wcounter; $maxFlag=1;}
1873 if ($maxDim[1] && $Hcounter+$gifCreator->XY[1]>=$maxDim[1]) {$tempXY[1]=$maxDim[1]-$Hcounter; $maxFlag=1;}
1874 if ($maxFlag) {
1875 $val['XY'] = implode($tempXY,',');
1876 $gifCreator = t3lib_div::makeInstance('tslib_gifBuilder');
1877 $gifCreator->init();
1878 $gifCreator->start($val,$this->menuArr[$key]);
1879 }
1880 }
1881 // SAME CODE AS makeGifs()! END
1882
1883 // Setting the width/height
1884 $totalWH['W'][$key]=$gifCreator->XY[0];
1885 $totalWH['H'][$key]=$gifCreator->XY[1];
1886 $totalWH['W_total']+=$gifCreator->XY[0];
1887 $totalWH['H_total']+=$gifCreator->XY[1];
1888 // ---- //
1889
1890 $Hcounter+=$gifCreator->XY[1]; // counter is increased
1891 $Wcounter+=$gifCreator->XY[0]; // counter is increased
1892
1893 if ($maxFlag){break;}
1894 }
1895 return $totalWH;
1896 }
1897
1898 /**
1899 * Traverses the ->result['NO'] array of menu items configuration (made by ->generate()) and renders the HTML of each item (the images themselves was made with makeGifs() before this. See ->generate())
1900 * During the execution of this function many internal methods prefixed "extProc_" from this class is called and many of these are for now dummy functions. But they can be used for processing as they are used by the GMENU_LAYERS
1901 *
1902 * @return string The HTML for the menu (returns result through $this->extProc_finish(); )
1903 */
1904 function writeMenu() {
1905 if (is_array($this->menuArr) && is_array($this->result) && count($this->result) && is_array($this->result['NO'])) {
1906 $this->WMresult='';
1907 $this->INPfixMD5 = substr(md5(microtime().$this->GMENU_fixKey),0,4);
1908 $this->WMmenuItems = count($this->result['NO']);
1909 $this->extProc_init();
1910 for ($key=0;$key<$this->WMmenuItems;$key++) {
1911 if ($this->result['NO'][$key]['output_file']) {
1912 $this->I =array();
1913 $this->I['key'] = $key;
1914 $this->I['INPfix']= $this->imgNameNotRandom?'':'_'.$this->INPfixMD5.'_'.$key;
1915 $this->I['val'] = $this->result['NO'][$key];
1916 $this->I['title'] = $this->getPageTitle($this->menuArr[$key]['title'],$this->menuArr[$key]['nav_title']);
1917 $this->I['uid'] = $this->menuArr[$key]['uid'];
1918 $this->I['mount_pid'] = $this->menuArr[$key]['mount_pid'];
1919 $this->I['pid'] = $this->menuArr[$key]['pid'];
1920 $this->I['spacer'] = $this->menuArr[$key]['isSpacer'];
1921 if (!$this->I['uid'] && !$this->menuArr[$key]['_OVERRIDE_HREF']) {$this->I['spacer']=1;}
1922 $this->I['noLink'] = ($this->I['spacer'] || $this->I['val']['noLink'] || !count($this->menuArr[$key])); // !count($this->menuArr[$key]) means that this item is a dummyItem
1923 $this->I['name']='';
1924
1925 // Get link.
1926 $this->I['linkHREF'] = $this->link($key,$this->I['val']['altTarget'],$this->mconf['forceTypeValue']);
1927
1928 // Set noBlur
1929 if (!$this->mconf['noBlur']) {
1930 $this->I['linkHREF']['onFocus']='blurLink(this);';
1931 }
1932
1933 // Set rollover
1934 if ($this->result['RO'][$key] && !$this->I['noLink']) {
1935 $this->I['theName'] = $this->imgNamePrefix.$this->I['uid'].$this->I['INPfix'];
1936 $this->I['name'] = ' name="'.$this->I["theName"].'"';
1937 $this->I['linkHREF']['onMouseover']=$this->WMfreezePrefix.'over(\''.$this->I['theName'].'\');';
1938 $this->I['linkHREF']['onMouseout']=$this->WMfreezePrefix.'out(\''.$this->I['theName'].'\');';
1939 $GLOBALS['TSFE']->JSImgCode.= chr(10).$this->I['theName'].'_n=new Image(); '.$this->I['theName'].'_n.src = "'.$GLOBALS['TSFE']->absRefPrefix.$this->I['val']['output_file'].'"; ';
1940 $GLOBALS['TSFE']->JSImgCode.= chr(10).$this->I['theName'].'_h=new Image(); '.$this->I['theName'].'_h.src = "'.$GLOBALS['TSFE']->absRefPrefix.$this->result['RO'][$key]['output_file'].'"; ';
1941 $GLOBALS['TSFE']->imagesOnPage[]=$this->result['RO'][$key]['output_file'];
1942 $GLOBALS['TSFE']->setJS('mouseOver');
1943 $this->extProc_RO($key);
1944 }
1945 // Set access key
1946 if ($this->mconf['accessKey']) {
1947 $this->I['accessKey'] = $this->accessKey($this->I['title']);
1948 } else {
1949 $this->I['accessKey']=Array();
1950 }
1951
1952 // Set altText
1953 $this->I['altText'] = $this->mconf['disableAltText'] ? '' : $this->I['title'].$this->I['accessKey']['alt'];
1954
1955 // Calling extra processing function
1956 $this->extProc_beforeLinking($key);
1957
1958 // Set linking
1959 if (!$this->I['noLink']) {
1960 $this->setATagParts();
1961 } else {
1962 $this->I['A1'] = '';
1963 $this->I['A2'] = '';
1964 }
1965 $this->I['IMG'] = '<img src="'.$GLOBALS['TSFE']->absRefPrefix.$this->I['val']['output_file'].'" width="'.$this->I['val']['output_w'].'" height="'.$this->I['val']['output_h'].'" border="0" alt="'.htmlspecialchars($this->I['altText']).'"'.$this->I['name'].($this->I['val']['imgParams']?' '.$this->I['val']['imgParams']:'').' />';
1966
1967 // Make before, middle and after parts
1968 $this->I['parts'] = array();
1969 $this->I['parts']['ATag_begin'] = $this->I['A1'];
1970 $this->I['parts']['image'] = $this->I['IMG'];
1971 $this->I['parts']['ATag_end'] = $this->I['A2'];
1972
1973 // Passing I to a user function
1974 if ($this->mconf['IProcFunc']) {
1975 $this->I = $this->userProcess('IProcFunc',$this->I);
1976 }
1977
1978 // Putting the item together.
1979 // Merge parts + beforeAllWrap
1980 $this->I['theItem']= implode('',$this->I['parts']);
1981 $this->I['theItem']= $this->extProc_beforeAllWrap($this->I['theItem'],$key);
1982
1983 // 'allWrap' (for GMENU's this is just the 'wrap' property)
1984 $this->I['theItem']= $this->tmpl->wrap($this->I['theItem'],$this->I['val']['wrap']);
1985 $GLOBALS['TSFE']->imagesOnPage[]=$this->I['val']['output_file'];
1986
1987 $this->extProc_afterLinking($key);
1988 }
1989 }
1990 return $this->extProc_finish();
1991 }
1992 }
1993
1994 /**
1995 * Called right before the traversing of $this->result begins.
1996 * Can be used for various initialization
1997 *
1998 * @return void
1999 * @access private
2000 * @see writeMenu(), tslib_gmenu_layers::extProc_init()
2001 */
2002 function extProc_init() {
2003 }
2004
2005 /**
2006 * Called after all processing for RollOver of an element has been done.
2007 *
2008 * @param integer Pointer to $this->menuArr[$key] where the current menu element record is found OR $this->result['RO'][$key] where the configuration for that elements RO version is found!
2009 * @return void
2010 * @access private
2011 * @see writeMenu(), tslib_gmenu_layers::extProc_RO()
2012 */
2013 function extProc_RO($key) {
2014 }
2015
2016 /**
2017 * Called right before the creation of the link for the menu item
2018 *
2019 * @param integer Pointer to $this->menuArr[$key] where the current menu element record is found
2020 * @return void
2021 * @access private
2022 * @see writeMenu(), tslib_gmenu_layers::extProc_beforeLinking()
2023 */
2024 function extProc_beforeLinking($key) {
2025 }
2026
2027 /**
2028 * Called right after the creation of links for the menu item. This is also the last function call before the for-loop traversing menu items goes to the next item.
2029 * This function MUST set $this->WMresult.=[HTML for menu item] to add the generated menu item to the internal accumulation of items.
2030 * Further this calls the subMenu function in the parent class to create any submenu there might be.
2031 *
2032 * @param integer Pointer to $this->menuArr[$key] where the current menu element record is found
2033 * @return void
2034 * @access private
2035 * @see writeMenu(), tslib_gmenu_layers::extProc_afterLinking(), tslib_menu::subMenu()
2036 */
2037 function extProc_afterLinking($key) {
2038 $this->WMresult.=$this->I['theItem'];
2039 if (!$this->I['spacer']) {
2040 $this->WMresult.= $this->subMenu($this->I['uid']);
2041 }
2042 }
2043
2044 /**
2045 * Called before the "wrap" happens on the menu item.
2046 *
2047 * @param string The current content of the menu item, $this->I['theItem'], passed along.
2048 * @param integer Pointer to $this->menuArr[$key] where the current menu element record is found
2049 * @return string The modified version of $item, going back into $this->I['theItem']
2050 * @access private
2051 * @see writeMenu(), tslib_gmenu_layers::extProc_beforeAllWrap()
2052 */
2053 function extProc_beforeAllWrap($item,$key) {
2054 return $item;
2055 }
2056
2057 /**
2058 * Called before the writeMenu() function returns (only if a menu was generated)
2059 *
2060 * @return string The total menu content should be returned by this function
2061 * @access private
2062 * @see writeMenu(), tslib_gmenu_layers::extProc_finish()
2063 */
2064 function extProc_finish() {
2065 return $this->tmpl->wrap($this->WMresult,$this->mconf['wrap']).$this->WMextraScript;
2066 }
2067 }
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090 /**
2091 * ImageMap based menus
2092 *
2093 * @author Kasper Skaarhoj <kasper@typo3.com>
2094 * @package TYPO3
2095 * @subpackage tslib
2096 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=389&cHash=fcf18c5d9f
2097 */
2098 class tslib_imgmenu extends tslib_menu {
2099
2100 /**
2101 * Calls procesItemStates() so that the common configuration for the menu items are resolved into individual configuration per item.
2102 * Calls makeImageMap() to generate the image map image-file
2103 *
2104 * @return void
2105 * @see tslib_menu::procesItemStates(), makeImageMap()
2106 */
2107 function generate() {
2108 $splitCount = count($this->menuArr);
2109 if ($splitCount) {
2110 list($NOconf) = $this->procesItemStates($splitCount);
2111 }
2112 if ($this->mconf['debugItemConf']) {echo '<h3>$NOconf:</h3>'; debug($NOconf); }
2113 $this->makeImageMap($NOconf);
2114 }
2115
2116 /**
2117 * Will traverse input array with configuratoin per-item and create corresponding GIF files for the menu.
2118 * The data of the files are stored in $this->result
2119 *
2120 * @param array Array with configuration for each item.
2121 * @return void
2122 * @access private
2123 * @see generate()
2124 */
2125 function makeImageMap($conf) {
2126 if (!is_array($conf)) {
2127 $conf = Array();
2128 }
2129 if (is_array($this->mconf['main.'])) {
2130 $gifCreator = t3lib_div::makeInstance('tslib_gifBuilder');
2131 $gifCreator->init();
2132
2133 $itemsConf = $conf;
2134 $conf = $this->mconf['main.'];
2135 if (is_array($conf)) {
2136 $gifObjCount = 0;
2137
2138 $sKeyArray=t3lib_TStemplate::sortedKeyList($conf);
2139 $gifObjCount=intval(end($sKeyArray));
2140
2141 $lastOriginal = $gifObjCount;
2142
2143 // Now we add graphical objects to the gifbuilder-setup
2144 reset($itemsConf);
2145 $waArr = Array();
2146 while (list($key,$val)=each($itemsConf)) {
2147 if (is_array($val)) {
2148 $gifObjCount++;
2149 $waArr[$key]['free']=$gifObjCount;
2150
2151 $sKeyArray=t3lib_TStemplate::sortedKeyList($val);
2152 reset($sKeyArray);
2153 while(list(,$theKey)=each($sKeyArray)) {
2154 $theValue=$val[$theKey];
2155
2156
2157 if (intval($theKey) && $theValArr=$val[$theKey.'.']) {
2158 $cObjData = $this->menuArr[$key] ? $this->menuArr[$key] : Array();
2159
2160 $gifObjCount++;
2161 if ($theValue=='TEXT') {
2162 $waArr[$key]['textNum']=$gifObjCount;
2163
2164 $gifCreator->data = $cObjData;
2165 $theValArr = $gifCreator->checkTextObj($theValArr);
2166 unset($theValArr['text.']); // if this is not done it seems that imageMaps will be rendered wrong!!
2167 // check links
2168
2169 $LD = $this->tmpl->linkData($this->menuArr[$key],$this->mconf['target'],'','',array(),'',$this->mconf['forceTypeValue']);
2170
2171 // Overriding URL / Target if set to do so:
2172 if ($this->menuArr[$key]['_OVERRIDE_HREF']) {
2173 $LD['totalURL'] = $this->menuArr[$key]['_OVERRIDE_HREF'];
2174 if ($this->menuArr[$key]['_OVERRIDE_TARGET']) $LD['target'] = $this->menuArr[$key]['_OVERRIDE_TARGET'];
2175 }
2176
2177 // Setting target/url:
2178 if ($theValArr['imgMap.']['url']=='') {
2179 $theValArr['imgMap.']['url'] = $LD['totalURL'];
2180 }
2181 if ($theValArr['imgMap.']['target']=='') {
2182 $theValArr['imgMap.']['target'] = $LD['target'];
2183 }
2184 if ($theValArr['imgMap.']['noBlur']=='') {
2185 $theValArr['imgMap.']['noBlur'] = $this->mconf['noBlur'];
2186 }
2187 }
2188 // This code goes one level in if the object is an image. If 'file' and/or 'mask' appears to be GIFBUILDER-objects, they are both searched for TEXT objects, and if a textobj is found, it's checked with the currently loaded record!!
2189 if ($theValue=='IMAGE') {
2190 if ($theValArr['file']=='GIFBUILDER') {
2191 $temp_sKeyArray=t3lib_TStemplate::sortedKeyList($theValArr['file.']);
2192 reset($temp_sKeyArray);
2193 while(list(,$temp_theKey)=each($temp_sKeyArray)) {
2194 if ($theValArr['mask.'][$temp_theKey]=='TEXT') {
2195 $gifCreator->data = $this->menuArr[$key] ? $this->menuArr[$key] : Array();
2196 $theValArr['mask.'][$temp_theKey.'.'] = $gifCreator->checkTextObj($theValArr['mask.'][$temp_theKey.'.']);
2197 unset($theValArr['mask.'][$temp_theKey.'.']['text.']); // if this is not done it seems that imageMaps will be rendered wrong!!
2198 }
2199 }
2200 }
2201 if ($theValArr['mask']=='GIFBUILDER') {
2202 $temp_sKeyArray=t3lib_TStemplate::sortedKeyList($theValArr['mask.']);
2203 reset($temp_sKeyArray);
2204 while(list(,$temp_theKey)=each($temp_sKeyArray)) {
2205 if ($theValArr['mask.'][$temp_theKey]=='TEXT') {
2206 $gifCreator->data = $this->menuArr[$key] ? $this->menuArr[$key] : Array();
2207 $theValArr['mask.'][$temp_theKey.'.'] = $gifCreator->checkTextObj($theValArr['mask.'][$temp_theKey.'.']);
2208 unset($theValArr['mask.'][$temp_theKey.'.']['text.']); // if this is not done it seems that imageMaps will be rendered wrong!!
2209 }
2210 }
2211 }
2212 }
2213
2214 // Checks if disabled is set...
2215 $setObjFlag=1;
2216 if ($theValArr['if.']) {
2217 $cObj =t3lib_div::makeInstance('tslib_cObj');
2218 $cObj->start($cObjData,'pages');
2219 if (!$cObj->checkIf($theValArr['if.'])) {
2220 $setObjFlag=0;
2221 }
2222 unset($theValArr['if.']);
2223 }
2224 // Set the object!
2225 if ($setObjFlag) {
2226 $conf[$gifObjCount] = $theValue;
2227 $conf[$gifObjCount.'.'] = $theValArr;
2228 }
2229 }
2230 }
2231 }
2232 }
2233
2234 $gifCreator->start($conf,$GLOBALS['TSFE']->page);
2235 // calculations
2236
2237 $sum=Array(0,0,0,0);
2238 reset($waArr);
2239 while (list($key,$val)=each($waArr)) {
2240 if ($dConf[$key] =$itemsConf[$key]['distrib']) {
2241 $textBB = $gifCreator->objBB[$val['textNum']];
2242 $dConf[$key] = str_replace('textX',$textBB[0],$dConf[$key]);
2243 $dConf[$key] = str_replace('textY',$textBB[1],$dConf[$key]);
2244 $dConf[$key] = t3lib_div::intExplode(',',$gifCreator->calcOffset($dConf[$key]));
2245 }
2246 }
2247 $workArea = t3lib_div::intExplode(',',$gifCreator->calcOffset($this->mconf['dWorkArea']));
2248 reset($waArr);
2249 while (list($key,$val)=each($waArr)) {
2250 $index = $val['free'];
2251 $gifCreator->setup[$index] = 'WORKAREA';
2252 $workArea[2] = $dConf[$key][2] ? $dConf[$key][2] : $dConf[$key][0];
2253 $workArea[3] = $dConf[$key][3] ? $dConf[$key][3] : $dConf[$key][1];
2254
2255 $gifCreator->setup[$index.'.']['set'] = implode($workArea,',');
2256 $workArea[0]+=$dConf[$key][0];
2257 $workArea[1]+=$dConf[$key][1];
2258 }
2259
2260 if ($this->mconf['debugRenumberedObject']) {echo '<h3>Renumbered GIFBUILDER object:</h3>'; debug($gifCreator->setup);}
2261
2262 $gifFileName = $gifCreator->fileName('m_');
2263 // Gets the ImageMap from the cache...
2264 $imgHash = md5($gifFileName);
2265 $imgMap = $this->sys_page->getHash($imgHash, 0);
2266
2267 if ($imgMap && @file_exists($gifFileName)) { // File exists
2268 $info = @getimagesize($gifFileName);
2269 $w=$info[0];
2270 $h=$info[1];
2271 } else { // file is generated
2272 $gifCreator->make();
2273 $w=$gifCreator->w;
2274 $h=$gifCreator->h;
2275 $gifCreator->output($gifFileName);
2276 $gifCreator->destroy();
2277 $imgMap=$gifCreator->map;
2278 $this->sys_page->storeHash($imgHash, $imgMap, 'MENU IMAGEMAP');
2279 }
2280 $imgMap.=$this->mconf['imgMapExtras'];
2281
2282 $gifFileName = t3lib_div::png_to_gif_by_imagemagick($gifFileName);
2283 $this->result = Array('output_file'=>$gifFileName, 'output_w'=>$w, 'output_h'=>$h, 'imgMap'=>$imgMap);
2284 }
2285 }
2286 }
2287
2288 /**
2289 * Returns the HTML for the image map menu.
2290 * If ->result is true it will create the HTML for the image map menu.
2291 *
2292 * @return string The HTML for the menu
2293 */
2294 function writeMenu() {
2295 if ($this->result) {
2296 $res = $this->result;
2297 $menuName = 'menu_'.t3lib_div::shortMD5($res['imgMap']); // shortMD5 260900
2298 $result = '<img src="'.$GLOBALS['TSFE']->absRefPrefix.$res['output_file'].'" width="'.$res['output_w'].'" height="'.$res['output_h'].'" usemap="#'.$menuName.'" border="0" '.$this->mconf['params'];
2299 if (!strstr($result,'alt="')) $result.=' alt="Menu Image Map"'; // Adding alt attribute if not set.
2300 $result.= ' /><map name="'.$menuName.'" id="'.$menuName.'">'.$res['imgMap'].'</map>';
2301
2302 $GLOBALS['TSFE']->imagesOnPage[]=$res['output_file'];
2303
2304 return $this->tmpl->wrap($result,$this->mconf['wrap']);
2305 }
2306 }
2307 }
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329 /**
2330 * JavaScript/Selectorbox based menus
2331 *
2332 * @author Kasper Skaarhoj <kasper@typo3.com>
2333 * @package TYPO3
2334 * @subpackage tslib
2335 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=391&cHash=563435abbc
2336 */
2337 class tslib_jsmenu extends tslib_menu {
2338
2339 /**
2340 * Dummy. Should do nothing, because we don't use the result-array here!
2341 *
2342 * @return void
2343 */
2344 function generate() {
2345 }
2346
2347 /**
2348 * Creates the HTML (mixture of a <form> and a JavaScript section) for the JavaScript menu (basically an array of selector boxes with onchange handlers)
2349 *
2350 * @return string The HTML code for the menu
2351 */
2352 function writeMenu() {
2353 if ($this->id) {
2354 // Making levels:
2355 $levels = t3lib_div::intInRange($this->mconf['levels'],1,5);
2356 $this->levels = $levels;
2357 $this->JSVarName='eid';
2358 $this->JSMenuName= $this->mconf['menuName'] ? $this->mconf['menuName'] : 'JSmenu';
2359
2360 $JScode="\n var ".$this->JSMenuName." = new JSmenu(".$levels.",'".$this->JSMenuName."Form');";
2361
2362 for ($a=1;$a<=$levels;$a++) {
2363 $JScode.="\n var ".$this->JSVarName.$a."=0;";
2364 }
2365 $JScode.= $this->generate_level($levels,1,$this->id,$this->menuArr,$this->MP_array)."\n";
2366
2367 $GLOBALS['TSFE']->additionalHeaderData['JSMenuCode']='<script type="text/javascript" src="'.$GLOBALS['TSFE']->absRefPrefix.'t3lib/jsfunc.menu.js"></script>';
2368 $GLOBALS['TSFE']->JSCode.= $JScode;
2369
2370 // Printing:
2371 $allFormCode = "";
2372 for ($a=1; $a<=$this->levels; $a++) {
2373 $formCode = '';
2374 $levelConf = $this->mconf[$a.'.'];
2375 $length = $levelConf['width'] ? $levelConf['width'] : 14;
2376 $lenghtStr = '';
2377 for ($b=0;$b<$length;$b++) {
2378 $lenghtStr.='_';
2379 }
2380 $height = $levelConf['elements'] ? $levelConf['elements'] : 5;
2381
2382 $formCode.= '<select name="selector'.$a.'" onchange="'.$this->JSMenuName.'.act('.$a.');"'.($levelConf['additionalParams']?' '.$levelConf['additionalParams']:'').'>';
2383 for ($b=0;$b<$height;$b++) {
2384 $formCode.= '<option value="0">';
2385 if ($b==0) {
2386 $formCode.= $lenghtStr;
2387 }
2388 $formCode.='</option>';
2389 }
2390 $formCode.= '</select>';
2391 $allFormCode.=$this->tmpl->wrap($formCode,$levelConf['wrap']);
2392 }
2393 $formCode = $this->tmpl->wrap($allFormCode,$this->mconf['wrap']);
2394
2395 $formCode= '<form action="" method="post" style="margin: 0 0 0 0;" name="'.$this->JSMenuName.'Form">'.$formCode.'</form>';
2396 $formCode.='<script type="text/javascript"> /*<![CDATA[*/ '.$this->JSMenuName.'.writeOut(1,'.$this->JSMenuName.'.openID,1); /*]]>*/ </script>';
2397 return $this->tmpl->wrap($formCode,$this->mconf['wrapAfterTags']);
2398 }
2399 }
2400
2401 /**
2402 * Generates a number of lines of JavaScript code for a menu level.
2403 * Calls itself recursively for additional levels.
2404 *
2405 * @param integer Number of levels to generate
2406 * @param integer Current level being generated - and if this number is less than $levels it will call itself recursively with $count incremented
2407 * @param integer Page id of the starting point.
2408 * @param array $this->menuArr passed along
2409 * @param array Previous MP vars
2410 * @return string JavaScript code lines.
2411 * @access private
2412 */
2413 function generate_level($levels,$count,$pid,$menuItemArray='',$MP_array=array()) {
2414 $levelConf = $this->mconf[$count.'.'];
2415
2416 // Translate PID to a mount page, if any:
2417 $mount_info = $this->sys_page->getMountPointInfo($pid);
2418 if (is_array($mount_info)) {
2419 $MP_array[] = $mount_info['MPvar'];
2420 $pid = $mount_info['mount_pid'];
2421 }
2422
2423 // Set "&MP=" var:
2424 $MP_var = implode(',',$MP_array);
2425 $MP_params = $MP_var ? '&MP='.rawurlencode($MP_var) : '';
2426
2427 // UIDs to ban:
2428 $banUidArray=array();
2429 if (trim($this->conf['excludeUidList'])) {
2430 $banUidArray = t3lib_div::intExplode(',', $this->conf['excludeUidList']);
2431 }
2432
2433 // Initializing variables:
2434 $var = $this->JSVarName;
2435 $menuName = $this->JSMenuName;
2436 $parent = $count==1 ? 0 : $var.($count-1);
2437 $prev = 0;
2438 $c = 0;
2439
2440 $menuItems = is_array($menuItemArray) ? $menuItemArray : $this->sys_page->getMenu($pid);
2441 foreach($menuItems as $uid => $data) {
2442 $spacer = (t3lib_div::inList($this->spacerIDList,$data['doktype'])?1:0); // if item is a spacer, $spacer is set
2443 if ($this->mconf['SPC'] || !$spacer) { // If the spacer-function is not enabled, spacers will not enter the $menuArr
2444 if (!t3lib_div::inList('5,6',$data['doktype']) && !t3lib_div::inArray($banUidArray,$uid)) { // Page may not be 'not_in_menu' or 'Backend User Section' + not in banned uid's
2445 if ($count<$levels) {
2446 $addLines = $this->generate_level($levels,$count+1,$data['uid'],'',$MP_array);
2447 } else {
2448 $addLines = '';
2449 }
2450 $title = rawurlencode($data['title']);
2451 $url = '';
2452 $target = '';
2453 if ((!$addLines && !$levelConf['noLink']) || $levelConf['alwaysLink']) {
2454 $LD = $this->tmpl->linkData($data,$this->mconf['target'],'','',array(),$MP_params,$this->mconf['forceTypeValue']);
2455 $url = rawurlencode($LD['totalURL']);
2456 $target = rawurlencode($LD['target']);
2457 }
2458 $codeLines.= "\n".$var.$count."=".$menuName.".add(".$parent.",".$prev.",0,'".$title."','".$url."','".$target."');";
2459 // If the active one should be chosen...
2460 $active = ($levelConf['showActive'] && $data['uid'] == $this->tmpl->rootLine[$count]['uid']);
2461 // If the first item should be shown
2462 $first = (!$c && $levelConf['showFirst']);
2463 // do it...
2464 if ($active || $first) {
2465 if ($count==1) {
2466 $codeLines.= "\n".$menuName.".openID = ".$var.$count.";";
2467 } else {
2468 $codeLines.= "\n".$menuName.".entry[".$parent."].openID = ".$var.$count.";";
2469 }
2470 }
2471 // Add submenu...
2472 $codeLines.= $addLines;
2473
2474 $prev = $var.$count;
2475 $c++;
2476 }
2477 }
2478 }
2479 if ($this->mconf['firstLabelGeneral'] && !$levelConf['firstLabel']) {
2480 $levelConf['firstLabel'] = $this->mconf['firstLabelGeneral'];
2481 }
2482 if ($levelConf['firstLabel'] && $codeLines) {
2483 $codeLines.="\n".$menuName.".defTopTitle[".$count."] = unescape('".rawurlencode($levelConf['firstLabel'])."');";
2484 }
2485 return $codeLines;
2486 }
2487 }
2488
2489
2490 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_menu.php']) {
2491 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_menu.php']);
2492 }
2493
2494 ?>