Project

General

Profile

1 1360 Luisehahne
<?php
2
/**
3
 *
4
 * @category        module
5
 * @package         show_menu2
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8 1373 Luisehahne
 * @copyright       2009-2011, Website Baker Org. e.V.
9 1360 Luisehahne
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.7.0 | 2.8.x
12 1373 Luisehahne
 * @requirements    PHP 5.2.2 and higher
13 1360 Luisehahne
 * @version         $Id$
14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
16
 *
17
 */
18
19
/*
20
    This file provides backward compatibility between show_menu2 and the
21
    old functions show_menu() and menu(). Note that it is highly recommended
22
    for you to update your templates to use show_menu2 directly.
23
 */
24
25
/* ----------------------------------------------------------------------------
26
   show_menu
27
28
 From: http://forum.websitebaker.org/index.php/topic,2251.msg13978.html#msg13978
29
30
 * By calling it multiple times, you can have one menu just
31
 * showing the root level, one for the sub-pages, and so on
32
 * The order of the arguments has been changed compared
33
 * to the page_menu() function, so read carefully the list
34
 * of arguments!
35
 * To just display the standard menu, use
36
 * <?php show_menu(); ?> within your template's html code.
37
 * You don't normally need anymore than the first four arguments.
38
 * Usual calls would be (inside php code!)
39
 * show_menu(1,0,-1,false); - displays the complete page tree
40
 * show_menu(1,1,1); - show only first sub level
41
 * show_menu(1,1,-1); -    show an expanding/collapsing menu tree starting at level 1
42
 * Have fun experimenting!
43
 *
44
 * Full list of arguments:
45
 * 1. $menu_number:   With activitated "multiple menu" feature
46
 *                  you can choose which menu will be displayed
47
 *                  default: 1
48
 * 2. $start_level: The depth level of the root of the displayed
49
 *               menu tree. Defaults to '0', which is the top level.
50
 *                  '1' will show all pages starting from the first sub level.
51
 * 3. $recurse:     Gives the maximum number of levels to be displayed. Default
52
 *                  is '-1' which means 'all'.
53
 * 4. $collapse:    Specifies, whether the menu tree shall be
54
 *               expandable/collapsible (if set to 'true')
55
 *               or complete (all pages being displayed) if set to 'false'
56
 * 5. $item_template: Gives the possibility to specify the html code that is
57
 *                  displayed before displaying sub-pages
58
 * 6. $item_footer: The html code to appear after sub-pages were displayed.
59
 * 7. $menu_header: The html code to appear before the entire menu code and each
60
 *               sub tree.
61
 * 8. $menu_footer: The html code to appear after the entire menu code and each
62
 *               sub tree.
63
 * 9. $default_class: The (CSS) class of every menu item except the currently viewed page
64
 * 10. $current_class: The class of the currently viewed page
65
 * 11. $parent:    (used internally) The page_id of the menu's root node, defaults is '0' (root level)
66
 */
67 1420 Luisehahne
68
// Must include code to stop this file being access directly
69
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
70 1360 Luisehahne
71
class SM2_ShowMenuFormatter
72
{
73
    var $output;
74
    var $itemTemplate;
75
    var $itemFooter;
76
    var $menuHeader;
77
    var $menuFooter;
78
    var $defaultClass;
79
    var $currentClass;
80
81
    function output($aString) {
82 2114 darkviper
        if ($this->flags & SM2::NOBUFFER) {
83
            echo $aString;
84
        } else {
85 1360 Luisehahne
            $this->output .= $aString;
86
        }
87
    }
88
    function initialize() { $this->output = ''; }
89
    function startList($aPage, $aUrl) {
90
        echo $this->menuHeader;
91
    }
92
    function startItem($aPage, $aUrl, $aCurrSib, $aSibCount) {
93
        // determine the class string to use
94
        $thisClass = $this->defaultClass;
95
        if ($aPage['page_id'] == PAGE_ID) {
96
            $thisClass = $this->currentClass;
97
        }
98
99
        // format and display this item
100
        $item = str_replace(
101
                array(
102
                    '[a]','[/a]','[menu_title]','[page_title]','[url]',
103
                    '[target]','[class]'
104
                    ),
105
                array(
106
                    "<a href='$aUrl' target='".$aPage['target']."'>", '</a>',
107
                    $aPage['menu_title'], $aPage['page_title'], $aUrl,
108
                    $aPage['target'], $thisClass
109
                    ),
110
                $this->itemTemplate);
111
        echo $item;
112
    }
113
    function finishItem() {
114
        echo $this->itemFooter;
115
    }
116
    function finishList() {
117
        echo $this->menuFooter;
118
    }
119
    function finalize() { }
120
    function getOutput() {
121
        return $this->output;
122
    }
123
}
124
125
function show_menu(
126
    $aMenu          = 1,
127
    $aStartLevel    = 0,
128
    $aRecurse       = -1,
129
    $aCollapse      = true,
130
    $aItemTemplate  = '<li><span[class]>[a][menu_title][/a]</span>',
131
    $aItemFooter    = '</li>',
132
    $aMenuHeader    = '<ul>',
133
    $aMenuFooter    = '</ul>',
134
    $aDefaultClass  = ' class="menu_default"',
135
    $aCurrentClass  = ' class="menu_current"',
136
    $aParent        = 0
137
    )
138
{
139
    static $formatter;
140
    if (!isset($formatter)) {
141
        $formatter = new SM2_ShowMenuFormatter;
142
    }
143
144
    $formatter->itemTemplate  = $aItemTemplate;
145
    $formatter->itemFooter    = $aItemFooter;
146
    $formatter->menuHeader    = $aMenuHeader;
147
    $formatter->menuFooter    = $aMenuFooter;
148
    $formatter->defaultClass  = $aDefaultClass;
149
    $formatter->currentClass  = $aCurrentClass;
150
151 2112 darkviper
    $start = SM2::ROOT + $aStartLevel;
152 1360 Luisehahne
    if ($aParent != 0) {
153
        $start = $aParent;
154
    }
155
156
    $maxLevel = 0;
157
    if ($aRecurse == 0) {
158
        return;
159
    }
160
    if ($aRecurse < 0) {
161 2112 darkviper
        $maxLevel = SM2::ALL;
162 1360 Luisehahne
    }
163
    else {
164 2112 darkviper
        $maxLevel = SM2::START + $aRecurse - 1;
165 1360 Luisehahne
    }
166
167 2112 darkviper
    $flags = $aCollapse ? SM2::TRIM : SM2::ALL;
168 1360 Luisehahne
169
    // special case for default case
170
    if ($aStartLevel == 0 && $aRecurse == -1 && $aCollapse) {
171 2112 darkviper
        $maxLevel = SM2::CURR + 1;
172 1360 Luisehahne
    }
173
174
    show_menu2($aMenu, $start, $maxLevel, $flags, $formatter);
175
}
176
177
function page_menu(
178
    $aParent = 0,
179
    $menu_number = 1,
180
    $item_template = '<li[class]>[a][menu_title][/a]</li>',
181
    $menu_header = '<ul>',
182
    $menu_footer = '</ul>',
183
    $default_class = ' class="menu_default"',
184
    $current_class = ' class="menu_current"',
185
    $recurse = LEVEL    // page['level']
186
    )
187
{
188
    show_menu($menu_number, 0, $recurse+2, true, $item_template, '',
189
        $menu_header, $menu_footer, $default_class, $current_class, $aParent);
190
}
191
192
?>