1 |
827
|
doc
|
<?php
|
2 |
|
|
/*
|
3 |
|
|
show_menu2: show_menu replacement for Website Baker
|
4 |
|
|
Copyright (C) 2006-2008, Brodie Thiesfield
|
5 |
|
|
|
6 |
|
|
This program is free software; you can redistribute it and/or
|
7 |
|
|
modify it under the terms of the GNU General Public License
|
8 |
|
|
as published by the Free Software Foundation; either version 2
|
9 |
|
|
of the License, or (at your option) any later version.
|
10 |
|
|
|
11 |
|
|
This program is distributed in the hope that it will be useful,
|
12 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
|
|
GNU General Public License for more details.
|
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU General Public License
|
17 |
|
|
along with this program; if not, write to the Free Software
|
18 |
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
|
|
02110-1301, USA.
|
20 |
|
|
*/
|
21 |
|
|
|
22 |
|
|
/*
|
23 |
|
|
This file provides backward compatibility between show_menu2 and the
|
24 |
|
|
old functions show_menu() and menu(). Note that it is highly recommended
|
25 |
|
|
for you to update your templates to use show_menu2 directly.
|
26 |
|
|
*/
|
27 |
|
|
|
28 |
|
|
/* ----------------------------------------------------------------------------
|
29 |
|
|
show_menu
|
30 |
|
|
|
31 |
|
|
From: http://forum.websitebaker.org/index.php/topic,2251.msg13978.html#msg13978
|
32 |
|
|
|
33 |
|
|
* By calling it multiple times, you can have one menu just
|
34 |
|
|
* showing the root level, one for the sub-pages, and so on
|
35 |
|
|
* The order of the arguments has been changed compared
|
36 |
|
|
* to the page_menu() function, so read carefully the list
|
37 |
|
|
* of arguments!
|
38 |
|
|
* To just display the standard menu, use
|
39 |
|
|
* <?php show_menu(); ?> within your template's html code.
|
40 |
|
|
* You don't normally need anymore than the first four arguments.
|
41 |
|
|
* Usual calls would be (inside php code!)
|
42 |
|
|
* show_menu(1,0,-1,false); - displays the complete page tree
|
43 |
|
|
* show_menu(1,1,1); - show only first sub level
|
44 |
|
|
* show_menu(1,1,-1); - show an expanding/collapsing menu tree starting at level 1
|
45 |
|
|
* Have fun experimenting!
|
46 |
|
|
*
|
47 |
|
|
* Full list of arguments:
|
48 |
|
|
* 1. $menu_number: With activitated "multiple menu" feature
|
49 |
|
|
* you can choose which menu will be displayed
|
50 |
|
|
* default: 1
|
51 |
|
|
* 2. $start_level: The depth level of the root of the displayed
|
52 |
|
|
* menu tree. Defaults to '0', which is the top level.
|
53 |
|
|
* '1' will show all pages starting from the first sub level.
|
54 |
|
|
* 3. $recurse: Gives the maximum number of levels to be displayed. Default
|
55 |
|
|
* is '-1' which means 'all'.
|
56 |
|
|
* 4. $collapse: Specifies, whether the menu tree shall be
|
57 |
|
|
* expandable/collapsible (if set to 'true')
|
58 |
|
|
* or complete (all pages being displayed) if set to 'false'
|
59 |
|
|
* 5. $item_template: Gives the possibility to specify the html code that is
|
60 |
|
|
* displayed before displaying sub-pages
|
61 |
|
|
* 6. $item_footer: The html code to appear after sub-pages were displayed.
|
62 |
|
|
* 7. $menu_header: The html code to appear before the entire menu code and each
|
63 |
|
|
* sub tree.
|
64 |
|
|
* 8. $menu_footer: The html code to appear after the entire menu code and each
|
65 |
|
|
* sub tree.
|
66 |
|
|
* 9. $default_class: The (CSS) class of every menu item except the currently viewed page
|
67 |
|
|
* 10. $current_class: The class of the currently viewed page
|
68 |
|
|
* 11. $parent: (used internally) The page_id of the menu's root node, defaults is '0' (root level)
|
69 |
|
|
*/
|
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_BUFFER) {
|
83 |
|
|
$this->output .= $aString;
|
84 |
|
|
}
|
85 |
|
|
else {
|
86 |
|
|
echo $aString;
|
87 |
|
|
}
|
88 |
|
|
}
|
89 |
|
|
function initialize() { $this->output = ''; }
|
90 |
|
|
function startList($aPage, $aUrl) {
|
91 |
|
|
echo $this->menuHeader;
|
92 |
|
|
}
|
93 |
|
|
function startItem($aPage, $aUrl, $aCurrSib, $aSibCount) {
|
94 |
|
|
// determine the class string to use
|
95 |
|
|
$thisClass = $this->defaultClass;
|
96 |
|
|
if ($aPage['page_id'] == PAGE_ID) {
|
97 |
|
|
$thisClass = $this->currentClass;
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
// format and display this item
|
101 |
|
|
$item = str_replace(
|
102 |
|
|
array(
|
103 |
|
|
'[a]','[/a]','[menu_title]','[page_title]','[url]',
|
104 |
|
|
'[target]','[class]'
|
105 |
|
|
),
|
106 |
|
|
array(
|
107 |
|
|
"<a href='$aUrl' target='".$aPage['target']."'>", '</a>',
|
108 |
|
|
$aPage['menu_title'], $aPage['page_title'], $aUrl,
|
109 |
|
|
$aPage['target'], $thisClass
|
110 |
|
|
),
|
111 |
|
|
$this->itemTemplate);
|
112 |
|
|
echo $item;
|
113 |
|
|
}
|
114 |
|
|
function finishItem() {
|
115 |
|
|
echo $this->itemFooter;
|
116 |
|
|
}
|
117 |
|
|
function finishList() {
|
118 |
|
|
echo $this->menuFooter;
|
119 |
|
|
}
|
120 |
|
|
function finalize() { }
|
121 |
|
|
function getOutput() {
|
122 |
|
|
return $this->output;
|
123 |
|
|
}
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
function show_menu(
|
127 |
|
|
$aMenu = 1,
|
128 |
|
|
$aStartLevel = 0,
|
129 |
|
|
$aRecurse = -1,
|
130 |
|
|
$aCollapse = true,
|
131 |
|
|
$aItemTemplate = '<li><span[class]>[a][menu_title][/a]</span>',
|
132 |
|
|
$aItemFooter = '</li>',
|
133 |
|
|
$aMenuHeader = '<ul>',
|
134 |
|
|
$aMenuFooter = '</ul>',
|
135 |
|
|
$aDefaultClass = ' class="menu_default"',
|
136 |
|
|
$aCurrentClass = ' class="menu_current"',
|
137 |
|
|
$aParent = 0
|
138 |
|
|
)
|
139 |
|
|
{
|
140 |
|
|
static $formatter;
|
141 |
|
|
if (!isset($formatter)) {
|
142 |
|
|
$formatter = new SM2_ShowMenuFormatter;
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
$formatter->itemTemplate = $aItemTemplate;
|
146 |
|
|
$formatter->itemFooter = $aItemFooter;
|
147 |
|
|
$formatter->menuHeader = $aMenuHeader;
|
148 |
|
|
$formatter->menuFooter = $aMenuFooter;
|
149 |
|
|
$formatter->defaultClass = $aDefaultClass;
|
150 |
|
|
$formatter->currentClass = $aCurrentClass;
|
151 |
|
|
|
152 |
|
|
$start = SM2_ROOT + $aStartLevel;
|
153 |
|
|
if ($aParent != 0) {
|
154 |
|
|
$start = $aParent;
|
155 |
|
|
}
|
156 |
|
|
|
157 |
|
|
$maxLevel = 0;
|
158 |
|
|
if ($aRecurse == 0) {
|
159 |
|
|
return;
|
160 |
|
|
}
|
161 |
|
|
if ($aRecurse < 0) {
|
162 |
|
|
$maxLevel = SM2_ALL;
|
163 |
|
|
}
|
164 |
|
|
else {
|
165 |
|
|
$maxLevel = SM2_START + $aRecurse - 1;
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
$flags = $aCollapse ? SM2_TRIM : SM2_ALL;
|
169 |
|
|
|
170 |
|
|
// special case for default case
|
171 |
|
|
if ($aStartLevel == 0 && $aRecurse == -1 && $aCollapse) {
|
172 |
|
|
$maxLevel = SM2_CURR + 1;
|
173 |
|
|
}
|
174 |
|
|
|
175 |
|
|
show_menu2($aMenu, $start, $maxLevel, $flags, $formatter);
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
function page_menu(
|
179 |
|
|
$aParent = 0,
|
180 |
|
|
$menu_number = 1,
|
181 |
|
|
$item_template = '<li[class]>[a][menu_title][/a]</li>',
|
182 |
|
|
$menu_header = '<ul>',
|
183 |
|
|
$menu_footer = '</ul>',
|
184 |
|
|
$default_class = ' class="menu_default"',
|
185 |
|
|
$current_class = ' class="menu_current"',
|
186 |
|
|
$recurse = LEVEL // page['level']
|
187 |
|
|
)
|
188 |
|
|
{
|
189 |
|
|
show_menu($menu_number, 0, $recurse+2, true, $item_template, '',
|
190 |
|
|
$menu_header, $menu_footer, $default_class, $current_class, $aParent);
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
?>
|