Project

General

Profile

1
<?php
2

    
3
// $Id: legacy.php 860 2008-10-21 14:32:18Z Ruebenwurzel $
4

    
5
/*
6
    show_menu2: show_menu replacement for Website Baker 
7
    Copyright (C) 2006-2008, Brodie Thiesfield
8

    
9
    This program is free software; you can redistribute it and/or
10
    modify it under the terms of the GNU General Public License
11
    as published by the Free Software Foundation; either version 2
12
    of the License, or (at your option) any later version.
13

    
14
    This program is distributed in the hope that it will be useful,
15
    but WITHOUT ANY WARRANTY; without even the implied warranty of
16
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
    GNU General Public License for more details.
18

    
19
    You should have received a copy of the GNU General Public License
20
    along with this program; if not, write to the Free Software
21
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
22
    02110-1301, USA.
23
*/
24

    
25
/*
26
    This file provides backward compatibility between show_menu2 and the
27
    old functions show_menu() and menu(). Note that it is highly recommended 
28
    for you to update your templates to use show_menu2 directly.
29
 */    
30

    
31
/* ----------------------------------------------------------------------------
32
   show_menu
33
   
34
 From: http://forum.websitebaker.org/index.php/topic,2251.msg13978.html#msg13978  
35
 
36
 * By calling it multiple times, you can have one menu just
37
 * showing the root level, one for the sub-pages, and so on
38
 * The order of the arguments has been changed compared
39
 * to the page_menu() function, so read carefully the list
40
 * of arguments!
41
 * To just display the standard menu, use
42
 * <?php show_menu(); ?> within your template's html code.
43
 * You don't normally need anymore than the first four arguments.
44
 * Usual calls would be (inside php code!)
45
 * show_menu(1,0,-1,false); - displays the complete page tree
46
 * show_menu(1,1,1); - show only first sub level
47
 * show_menu(1,1,-1); -    show an expanding/collapsing menu tree starting at level 1
48
 * Have fun experimenting!
49
 *
50
 * Full list of arguments:
51
 * 1. $menu_number:   With activitated "multiple menu" feature
52
 *                  you can choose which menu will be displayed
53
 *                  default: 1
54
 * 2. $start_level: The depth level of the root of the displayed
55
 *               menu tree. Defaults to '0', which is the top level.
56
 *                  '1' will show all pages starting from the first sub level.
57
 * 3. $recurse:     Gives the maximum number of levels to be displayed. Default
58
 *                  is '-1' which means 'all'.
59
 * 4. $collapse:    Specifies, whether the menu tree shall be
60
 *               expandable/collapsible (if set to 'true')
61
 *               or complete (all pages being displayed) if set to 'false'
62
 * 5. $item_template: Gives the possibility to specify the html code that is
63
 *                  displayed before displaying sub-pages
64
 * 6. $item_footer: The html code to appear after sub-pages were displayed.
65
 * 7. $menu_header: The html code to appear before the entire menu code and each
66
 *               sub tree.
67
 * 8. $menu_footer: The html code to appear after the entire menu code and each
68
 *               sub tree.
69
 * 9. $default_class: The (CSS) class of every menu item except the currently viewed page
70
 * 10. $current_class: The class of the currently viewed page
71
 * 11. $parent:    (used internally) The page_id of the menu's root node, defaults is '0' (root level)
72
 */
73
 
74
class SM2_ShowMenuFormatter
75
{
76
    var $output;
77
    var $itemTemplate;
78
    var $itemFooter;
79
    var $menuHeader;
80
    var $menuFooter;
81
    var $defaultClass;
82
    var $currentClass;
83
    
84
    function output($aString) {
85
        if ($this->flags & SM2_BUFFER) {
86
            $this->output .= $aString;
87
        }
88
        else {
89
            echo $aString;
90
        }
91
    }
92
    function initialize() { $this->output = ''; }
93
    function startList($aPage, $aUrl) { 
94
        echo $this->menuHeader;
95
    }
96
    function startItem($aPage, $aUrl, $aCurrSib, $aSibCount) { 
97
        // determine the class string to use
98
        $thisClass = $this->defaultClass;
99
        if ($aPage['page_id'] == PAGE_ID) {
100
            $thisClass = $this->currentClass;
101
        }
102
        
103
        // format and display this item
104
        $item = str_replace( 
105
                array(
106
                    '[a]','[/a]','[menu_title]','[page_title]','[url]',
107
                    '[target]','[class]'
108
                    ),
109
                array(
110
                    "<a href='$aUrl' target='".$aPage['target']."'>", '</a>',
111
                    $aPage['menu_title'], $aPage['page_title'], $aUrl, 
112
                    $aPage['target'], $thisClass
113
                    ),
114
                $this->itemTemplate);
115
        echo $item;
116
    }
117
    function finishItem() { 
118
        echo $this->itemFooter;
119
    }
120
    function finishList() { 
121
        echo $this->menuFooter;
122
    }
123
    function finalize() { }
124
    function getOutput() {
125
        return $this->output;
126
    }
127
}
128

    
129
function show_menu(
130
    $aMenu          = 1, 
131
    $aStartLevel    = 0, 
132
    $aRecurse       = -1, 
133
    $aCollapse      = true,
134
    $aItemTemplate  = '<li><span[class]>[a][menu_title][/a]</span>',
135
    $aItemFooter    = '</li>',
136
    $aMenuHeader    = '<ul>',
137
    $aMenuFooter    = '</ul>',
138
    $aDefaultClass  = ' class="menu_default"',
139
    $aCurrentClass  = ' class="menu_current"',
140
    $aParent        = 0
141
    )
142
{
143
    static $formatter;
144
    if (!isset($formatter)) {
145
        $formatter = new SM2_ShowMenuFormatter;
146
    }
147
    
148
    $formatter->itemTemplate  = $aItemTemplate;
149
    $formatter->itemFooter    = $aItemFooter;  
150
    $formatter->menuHeader    = $aMenuHeader;  
151
    $formatter->menuFooter    = $aMenuFooter;  
152
    $formatter->defaultClass  = $aDefaultClass;
153
    $formatter->currentClass  = $aCurrentClass;
154
    
155
    $start = SM2_ROOT + $aStartLevel;
156
    if ($aParent != 0) {
157
        $start = $aParent;
158
    }
159

    
160
    $maxLevel = 0;
161
    if ($aRecurse == 0) {
162
        return;
163
    }
164
    if ($aRecurse < 0) {
165
        $maxLevel = SM2_ALL;
166
    }
167
    else {
168
        $maxLevel = SM2_START + $aRecurse - 1;
169
    }
170
    
171
    $flags = $aCollapse ? SM2_TRIM : SM2_ALL;
172
    
173
    // special case for default case
174
    if ($aStartLevel == 0 && $aRecurse == -1 && $aCollapse) {
175
        $maxLevel = SM2_CURR + 1;
176
    }
177

    
178
    show_menu2($aMenu, $start, $maxLevel, $flags, $formatter);
179
}
180

    
181
function page_menu(
182
    $aParent = 0, 
183
    $menu_number = 1, 
184
    $item_template = '<li[class]>[a][menu_title][/a]</li>', 
185
    $menu_header = '<ul>', 
186
    $menu_footer = '</ul>', 
187
    $default_class = ' class="menu_default"', 
188
    $current_class = ' class="menu_current"', 
189
    $recurse = LEVEL    // page['level']
190
    ) 
191
{
192
    show_menu($menu_number, 0, $recurse+2, true, $item_template, '', 
193
        $menu_header, $menu_footer, $default_class, $current_class, $aParent);
194
}
195

    
196
?>
(7-7/7)