Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        module
5
 * @package         show_menu2
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.7.0 | 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id: legacy.php 1349 2010-12-19 19:04:59Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/show_menu2/legacy.php $
15
 * @lastmodified    $Date: 2010-12-19 20:04:59 +0100 (Sun, 19 Dec 2010) $
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
 
68
class SM2_ShowMenuFormatter
69
{
70
    var $output;
71
    var $itemTemplate;
72
    var $itemFooter;
73
    var $menuHeader;
74
    var $menuFooter;
75
    var $defaultClass;
76
    var $currentClass;
77
    
78
    function output($aString) {
79
        if ($this->flags & SM2_BUFFER) {
80
            $this->output .= $aString;
81
        }
82
        else {
83
            echo $aString;
84
        }
85
    }
86
    function initialize() { $this->output = ''; }
87
    function startList($aPage, $aUrl) { 
88
        echo $this->menuHeader;
89
    }
90
    function startItem($aPage, $aUrl, $aCurrSib, $aSibCount) { 
91
        // determine the class string to use
92
        $thisClass = $this->defaultClass;
93
        if ($aPage['page_id'] == PAGE_ID) {
94
            $thisClass = $this->currentClass;
95
        }
96
        
97
        // format and display this item
98
        $item = str_replace( 
99
                array(
100
                    '[a]','[/a]','[menu_title]','[page_title]','[url]',
101
                    '[target]','[class]'
102
                    ),
103
                array(
104
                    "<a href='$aUrl' target='".$aPage['target']."'>", '</a>',
105
                    $aPage['menu_title'], $aPage['page_title'], $aUrl, 
106
                    $aPage['target'], $thisClass
107
                    ),
108
                $this->itemTemplate);
109
        echo $item;
110
    }
111
    function finishItem() { 
112
        echo $this->itemFooter;
113
    }
114
    function finishList() { 
115
        echo $this->menuFooter;
116
    }
117
    function finalize() { }
118
    function getOutput() {
119
        return $this->output;
120
    }
121
}
122

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

    
154
    $maxLevel = 0;
155
    if ($aRecurse == 0) {
156
        return;
157
    }
158
    if ($aRecurse < 0) {
159
        $maxLevel = SM2_ALL;
160
    }
161
    else {
162
        $maxLevel = SM2_START + $aRecurse - 1;
163
    }
164
    
165
    $flags = $aCollapse ? SM2_TRIM : SM2_ALL;
166
    
167
    // special case for default case
168
    if ($aStartLevel == 0 && $aRecurse == -1 && $aCollapse) {
169
        $maxLevel = SM2_CURR + 1;
170
    }
171

    
172
    show_menu2($aMenu, $start, $maxLevel, $flags, $formatter);
173
}
174

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

    
190
?>
(7-7/7)