Revision 859
Added by Matthias about 17 years ago
| include.php | ||
|---|---|---|
| 1 | 1 |
<?php |
| 2 |
|
|
| 3 |
// $Id$ |
|
| 4 |
|
|
| 5 | 2 |
/* |
| 6 | 3 |
show_menu2: show_menu replacement for Website Baker |
| 7 | 4 |
Copyright (C) 2006-2008, Brodie Thiesfield |
| ... | ... | |
| 22 | 19 |
02110-1301, USA. |
| 23 | 20 |
|
| 24 | 21 |
*********************************************** |
| 25 |
** Version 4.6: see README for documentation **
|
|
| 22 |
** Version 4.7: see README for documentation **
|
|
| 26 | 23 |
*********************************************** |
| 27 | 24 |
*/ |
| 28 | 25 |
|
| ... | ... | |
| 406 | 403 |
$aMenu = 0, |
| 407 | 404 |
$aStart = SM2_ROOT, |
| 408 | 405 |
$aMaxLevel = -1999, // SM2_CURR+1 |
| 409 |
$aFlags = SM2_TRIM,
|
|
| 406 |
$aOptions = SM2_TRIM,
|
|
| 410 | 407 |
$aItemOpen = false, |
| 411 | 408 |
$aItemClose = false, |
| 412 | 409 |
$aMenuOpen = false, |
| ... | ... | |
| 417 | 414 |
{
|
| 418 | 415 |
global $wb; |
| 419 | 416 |
|
| 417 |
// extract the flags and set $aOptions to an array |
|
| 418 |
$flags = 0; |
|
| 419 |
if (is_int($aOptions)) {
|
|
| 420 |
$flags = $aOptions; |
|
| 421 |
$aOptions = array(); |
|
| 422 |
} |
|
| 423 |
else if (isset($aOptions['flags'])) {
|
|
| 424 |
$flags = $aOptions['flags']; |
|
| 425 |
} |
|
| 426 |
else {
|
|
| 427 |
$flags = SM2_TRIM; |
|
| 428 |
$aOptions = array(); |
|
| 429 |
error_log('show_menu2 error: $aOptions is invalid. No flags supplied!');
|
|
| 430 |
} |
|
| 431 |
|
|
| 420 | 432 |
// ensure we have our group 1 flag, we don't check for the "exactly 1" part, but |
| 421 | 433 |
// we do ensure that they provide at least one. |
| 422 |
if (0 == ($aFlags & _SM2_GROUP_1)) {
|
|
| 423 |
error_log("show_menu2 error: no flags from group 1 supplied! Exactly one flag is required!");
|
|
| 424 |
$aFlags |= SM2_TRIM; // default to TRIM
|
|
| 434 |
if (0 == ($flags & _SM2_GROUP_1)) {
|
|
| 435 |
error_log('show_menu2 error: $aOptions is invalid. No flags from group 1 supplied!');
|
|
| 436 |
$flags |= SM2_TRIM; // default to TRIM
|
|
| 425 | 437 |
} |
| 426 | 438 |
|
| 427 | 439 |
// search page results don't have any of the page data loaded by WB, so we load it |
| ... | ... | |
| 469 | 481 |
// multiple calls to show_menu2 in a single page with only a single call to |
| 470 | 482 |
// the database. If this variable exists, then we have already retrieved all |
| 471 | 483 |
// of the information and processed it, so we don't need to do it again. |
| 472 |
if (($aFlags & SM2_NOCACHE) != 0
|
|
| 484 |
if (($flags & SM2_NOCACHE) != 0
|
|
| 473 | 485 |
|| !array_key_exists('show_menu2_data', $GLOBALS)
|
| 474 | 486 |
|| !array_key_exists($aMenu, $GLOBALS['show_menu2_data'])) |
| 475 | 487 |
{
|
| ... | ... | |
| 497 | 509 |
if (version_compare(WB_VERSION, '2.7', '>=')) { // WB 2.7+
|
| 498 | 510 |
$fields .= ',viewing_users'; |
| 499 | 511 |
} |
| 500 |
if ($aFlags & SM2_ALLINFO) {
|
|
| 512 |
if ($flags & SM2_ALLINFO) {
|
|
| 501 | 513 |
$fields = '*'; |
| 502 | 514 |
} |
| 503 | 515 |
|
| ... | ... | |
| 640 | 652 |
$sm2formatter = new SM2_Formatter; |
| 641 | 653 |
} |
| 642 | 654 |
$formatter = $sm2formatter; |
| 643 |
$formatter->set($aFlags, $aItemOpen, $aItemClose,
|
|
| 655 |
$formatter->set($flags, $aItemOpen, $aItemClose,
|
|
| 644 | 656 |
$aMenuOpen, $aMenuClose, $aTopItemOpen, $aTopMenuOpen); |
| 645 | 657 |
} |
| 646 | 658 |
|
| 659 |
// adjust the level until we show everything and ignore the SM2_TRIM flag. |
|
| 660 |
// Usually this will be less than the start level to disable it. |
|
| 661 |
$showAllLevel = $aStartLevel - 1; |
|
| 662 |
if (isset($aOptions['notrim'])) {
|
|
| 663 |
$showAllLevel = $aStartLevel + $aOptions['notrim']; |
|
| 664 |
} |
|
| 665 |
|
|
| 647 | 666 |
// display the menu |
| 648 | 667 |
$formatter->initialize(); |
| 649 | 668 |
sm2_recurse( |
| 650 | 669 |
$GLOBALS['show_menu2_data'][$aMenu], |
| 651 | 670 |
$aStart, // parent id to start displaying sub-menus |
| 652 |
$aStartLevel, $aMaxLevel, $aFlags,
|
|
| 671 |
$aStartLevel, $showAllLevel, $aMaxLevel, $flags,
|
|
| 653 | 672 |
$formatter); |
| 654 | 673 |
$formatter->finalize(); |
| 655 | 674 |
|
| 656 | 675 |
// if we are returning something, get the data |
| 657 |
if (($aFlags & SM2_BUFFER) != 0) {
|
|
| 676 |
if (($flags & SM2_BUFFER) != 0) {
|
|
| 658 | 677 |
$retval = $formatter->getOutput(); |
| 659 | 678 |
} |
| 660 | 679 |
} |
| 661 | 680 |
|
| 662 | 681 |
// clear the data if we aren't caching it |
| 663 |
if (($aFlags & SM2_NOCACHE) != 0) {
|
|
| 682 |
if (($flags & SM2_NOCACHE) != 0) {
|
|
| 664 | 683 |
unset($GLOBALS['show_menu2_data'][$aMenu]); |
| 665 | 684 |
} |
| 666 | 685 |
|
| ... | ... | |
| 681 | 700 |
|
| 682 | 701 |
function sm2_recurse( |
| 683 | 702 |
&$rgParent, $aStart, |
| 684 |
$aStartLevel, $aMaxLevel, $aFlags, |
|
| 703 |
$aStartLevel, $aShowAllLevel, $aMaxLevel, $aFlags,
|
|
| 685 | 704 |
&$aFormatter |
| 686 | 705 |
) |
| 687 | 706 |
{
|
| ... | ... | |
| 725 | 744 |
} |
| 726 | 745 |
else if ($aFlags & SM2_TRIM) {
|
| 727 | 746 |
// parents and siblings of parents |
| 728 |
if (!array_key_exists('sm2_on_curr_path', $page) // not set if false, so existence = true
|
|
| 747 |
if ($pageLevel > $aShowAllLevel // permit all levels to be shown |
|
| 748 |
&& !array_key_exists('sm2_on_curr_path', $page) // not set if false, so existence = true
|
|
| 729 | 749 |
&& !array_key_exists('sm2_path_sibling', $page)) { // not set if false, so existence = true
|
| 730 | 750 |
continue; |
| 731 | 751 |
} |
| ... | ... | |
| 765 | 785 |
&& array_key_exists('sm2_has_child', $page)) { // not set if false, so existence = true
|
| 766 | 786 |
sm2_recurse( |
| 767 | 787 |
$rgParent, $nextParent, // parent id to start displaying sub-menus |
| 768 |
$aStartLevel, $aMaxLevel, $aFlags, |
|
| 788 |
$aStartLevel, $aShowAllLevel, $aMaxLevel, $aFlags,
|
|
| 769 | 789 |
$aFormatter); |
| 770 | 790 |
} |
| 771 | 791 |
|
Also available in: Unified diff
updated show_menu2 to version 4.7