Project

General

Profile

« Previous | Next » 

Revision 845

Added by doc over 16 years ago

Updated show_menu2 to version 4.60 (to avoid disappearing menus)

View differences:

include.php
22 22
    02110-1301, USA.
23 23

  
24 24
    ***********************************************
25
    ** Version 4.5: see README for documentation **
25
    ** Version 4.6: see README for documentation **
26 26
    ***********************************************
27 27
*/
28 28

  
......
149 149
            // not set if false, so existence = true
150 150
            $currClass .= ' menu-expand';
151 151
        }
152
        if ($aPage['page_id'] == PAGE_ID) {
152
        if (array_key_exists('sm2_is_curr', $aPage)) { 
153 153
            $currClass .= ' menu-current';
154 154
        }
155 155
        elseif (array_key_exists('sm2_is_parent', $aPage)) { 
......
424 424
        $aFlags |= SM2_TRIM; // default to TRIM
425 425
    }
426 426
    
427
    // search page results don't have any of the page data loaded by WB, so we load it 
428
    // ourselves using the referrer ID as the current page
429
    $CURR_PAGE_ID = defined('REFERRER_ID') ? REFERRER_ID : PAGE_ID;
430
    if (count($wb->page) == 0 && defined('REFERRER_ID') && REFERRER_ID > 0) {
431
        global $database;
432
        $sql = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '".REFERRER_ID."'";
433
        $result = $database->query($sql);
434
        if ($result->numRows() == 1) {
435
            $wb->page = $result->fetchRow();
436
        }
437
        unset($result);
438
    }
439
    
427 440
    // fix up the menu number to default to the menu number
428 441
    // of the current page if no menu has been supplied
429 442
    if ($aMenu == 0) {
......
431 444
    } 
432 445

  
433 446
    // Set some of the $wb->page[] settings to defaults if not set
434
    $pageLevel = $wb->page['level'] == '' ? 0 : $wb->page['level'];
447
    $pageLevel  = $wb->page['level']  == '' ? 0 : $wb->page['level'];
435 448
    $pageParent = $wb->page['parent'] == '' ? 0 : $wb->page['parent'];
436 449
    
437 450
    // adjust the start level and start page ID as necessary to
......
440 453
    if ($aStart < SM2_ROOT) {   // SM2_CURR+N
441 454
        if ($aStart == SM2_CURR) {
442 455
            $aStartLevel = $pageLevel;
443
            $aStart =  $pageParent;
456
            $aStart = $pageParent;
444 457
        }
445 458
        else {
446 459
            $aStartLevel = $pageLevel + $aStart - SM2_CURR;
447
            $aStart = PAGE_ID; 
460
            $aStart = $CURR_PAGE_ID; 
448 461
        }
449 462
    }
450 463
    elseif ($aStart < 0) {   // SM2_ROOT+N
......
481 494
        // is called (i.e. where the database is loaded) then the info won't
482 495
        // exist anyhow.
483 496
        $fields = 'parent,page_id,menu_title,page_title,link,target,level,visibility,viewing_groups';
484
        if(version_compare(WB_VERSION, '2.7', '>=')) { // WB 2.7+
497
        if (version_compare(WB_VERSION, '2.7', '>=')) { // WB 2.7+
485 498
            $fields .= ',viewing_users';
486 499
        }
487 500
        if ($aFlags & SM2_ALLINFO) {
......
506 519
            // create an in memory array of the database data based on the item's parent. 
507 520
            // The array stores all elements in the correct display order.
508 521
            while ($page = $oRowset->fetchRow()) {
509
				// ignore all pages that the current user is not permitted to view
522
                // ignore all pages that the current user is not permitted to view
510 523
                if(version_compare(WB_VERSION, '2.7', '>=')) { // WB >= 2.7
511 524
                    // 1. all pages with no active sections (unless it is the top page) are ignored
512
                    if(!$wb->page_is_active($page) && $page['link'] != $wb->default_link && !INTRO_PAGE) {
525
                    if (!$wb->page_is_active($page) && $page['link'] != $wb->default_link && !INTRO_PAGE) {
513 526
                      continue; 
514 527
                    }
515 528
                    // 2. all pages not visible to this user (unless always visible to registered users) are ignored
516
                    if(!$wb->page_is_visible($page) && $page['visibility'] != 'registered') {
529
                    if (!$wb->page_is_visible($page) && $page['visibility'] != 'registered') {
517 530
                        continue;
518 531
                    }
519

  
520 532
                }
521 533
                else {  // WB < 2.7
522 534
                    // We can't do this in SQL as the viewing_groups column contains multiple 
......
537 549
                }
538 550

  
539 551
                // mark our current page as being on the current path
540
                if ($page['page_id'] == PAGE_ID) {
552
                if ($page['page_id'] == $CURR_PAGE_ID) {
553
                    $page['sm2_is_curr'] = true;
541 554
                    $page['sm2_on_curr_path'] = true;
542 555
                }
543 556

  
......
573 586
                if (array_key_exists($mark['page_id'], $rgParent)) {
574 587
                    $mark['sm2_has_child'] = true;
575 588
                }
576
                if ($mark['parent'] == $parentId && $mark['page_id'] != PAGE_ID) {
589
                if ($mark['parent'] == $parentId && $mark['page_id'] != $CURR_PAGE_ID) {
577 590
                    $mark['sm2_is_sibling'] = true;
578 591
                }
579 592
                unset($mark);
......
582 595
        }
583 596
        
584 597
        // mark all children of the current page. We don't do this when 
585
        // PAGE_ID is 0, as 0 is the parent of everything. PAGE_ID == 0 
586
        // occurs on special pages like search results.
587
        if (PAGE_ID != 0) {
588
            sm2_mark_children($rgParent, PAGE_ID, 1);
598
        // $CURR_PAGE_ID is 0, as 0 is the parent of everything. 
599
        // $CURR_PAGE_ID == 0 occurs on special pages like search results
600
        // when no referrer is available.s
601
        if ($CURR_PAGE_ID != 0) {
602
            sm2_mark_children($rgParent, $CURR_PAGE_ID, 1);
589 603
        }
590 604
        
591 605
        // store the complete processed menu data as a global. We don't 

Also available in: Unified diff