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 2114 2014-12-01 10:22:07Z darkviper $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/ShowMenu2/legacy.php $
15
 * @lastmodified    $Date: 2014-12-01 11:22:07 +0100 (Mon, 01 Dec 2014) $
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
// Must include code to stop this file being access directly
69
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
70
 
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
        if ($this->flags & SM2::NOBUFFER) {
83
            echo $aString;
84
        } else {
85
            $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
    $start = SM2::ROOT + $aStartLevel;
152
    if ($aParent != 0) {
153
        $start = $aParent;
154
    }
155

    
156
    $maxLevel = 0;
157
    if ($aRecurse == 0) {
158
        return;
159
    }
160
    if ($aRecurse < 0) {
161
        $maxLevel = SM2::ALL;
162
    }
163
    else {
164
        $maxLevel = SM2::START + $aRecurse - 1;
165
    }
166
    
167
    $flags = $aCollapse ? SM2::TRIM : SM2::ALL;
168
    
169
    // special case for default case
170
    if ($aStartLevel == 0 && $aRecurse == -1 && $aCollapse) {
171
        $maxLevel = SM2::CURR + 1;
172
    }
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
?>
(6-6/8)