Revision 20
Added by stefan about 20 years ago
| class.frontend.php | ||
|---|---|---|
| 322 | 322 |
} |
| 323 | 323 |
} |
| 324 | 324 |
|
| 325 |
function menu($menu_number = 1, $start_level=0, $recurse = -1, $collapse = true, $item_template = '<li><span[class]>[a][menu_title][/a]</span>', $item_footer = '</li>', $menu_header = '<ul>', $menu_footer = '</ul>', $default_class = ' class="menu_default"', $current_class = ' class="menu_current"', $parent = 0) {
|
|
| 326 |
global $database; |
|
| 327 |
if ($recurse==0) |
|
| 328 |
return; |
|
| 325 |
function menu() {
|
|
| 326 |
if (!isset($this->menu_number)) {
|
|
| 327 |
$this->menu_number = 1; |
|
| 328 |
} |
|
| 329 |
if (!isset($this->menu_start_level)) {
|
|
| 330 |
$this->menu_start_level = 0; |
|
| 331 |
} |
|
| 332 |
if (!isset($this->menu_recurse)) {
|
|
| 333 |
$this->menu_recurse = -1; |
|
| 334 |
} |
|
| 335 |
if (!isset($this->menu_collapse)) {
|
|
| 336 |
$this->menu_collapse = true; |
|
| 337 |
} |
|
| 338 |
if (!isset($this->menu_item_template)) {
|
|
| 339 |
$this->menu_item_template = '<li><span[class]>[a][menu_title][/a]</span>'; |
|
| 340 |
} |
|
| 341 |
if (!isset($this->menu_item_footer)) {
|
|
| 342 |
$this->menu_item_footer = '</li>'; |
|
| 343 |
} |
|
| 344 |
if (!isset($this->menu_header)) {
|
|
| 345 |
$this->menu_header = '<ul>'; |
|
| 346 |
} |
|
| 347 |
if (!isset($this->menu_footer)) {
|
|
| 348 |
$this->menu_footer = '<ul>'; |
|
| 349 |
} |
|
| 350 |
if (!isset($this->menu_default_class)) {
|
|
| 351 |
$this->menu_default_class = ' class="menu_default"'; |
|
| 352 |
} |
|
| 353 |
if (!isset($this->menu_current_class)) {
|
|
| 354 |
$this->menu_current_class = ' class="menu_current"'; |
|
| 355 |
} |
|
| 356 |
if (!isset($this->menu_parent)) {
|
|
| 357 |
$this->menu_parent = 0; |
|
| 358 |
} |
|
| 359 |
$this->show_menu(); |
|
| 329 | 360 |
if ($start_level>0) {
|
| 330 | 361 |
$key_array=array_keys($this->page_trail); |
| 331 | 362 |
$real_start=$key_array[$start_level-1]; |
| 332 | 363 |
if (isset($real_start)) |
| 333 | 364 |
{
|
| 334 |
menu($menu_number, 0, $recurse,$collapse,$item_template, $item_footer, $menu_header, $menu_footer, $default_class, $current_class, $real_start); |
|
| 335 |
} |
|
| 365 |
$this->menu_parent=$real_start; |
|
| 366 |
$this->show_menu(); |
|
| 367 |
} |
|
| 336 | 368 |
return; |
| 337 | 369 |
} |
| 370 |
|
|
| 371 |
} |
|
| 372 |
|
|
| 373 |
function show_menu() {
|
|
| 374 |
global $database; |
|
| 375 |
if ($this->menu_recurse==0) |
|
| 376 |
return; |
|
| 338 | 377 |
// Check if we should add menu number check to query |
| 339 |
if($parent == 0) {
|
|
| 340 |
$menu_number = "menu = '$menu_number'"; |
|
| 378 |
if($menu_parent == 0) {
|
|
| 379 |
$menu_number = "menu = '$this->menu_number'";
|
|
| 341 | 380 |
} else {
|
| 342 | 381 |
$menu_number = '1'; |
| 343 | 382 |
} |
| 344 | 383 |
// Query pages |
| 345 | 384 |
$query_menu = $database->query("SELECT page_id,menu_title,page_title,link,target,level,visibility$this->extra_sql FROM ".
|
| 346 |
TABLE_PREFIX."pages WHERE parent = '$parent' AND $menu_number AND $this->extra_where_sql ORDER BY position ASC"); |
|
| 385 |
TABLE_PREFIX."pages WHERE parent = '$this->menu_parent' AND $menu_number AND $this->extra_where_sql ORDER BY position ASC");
|
|
| 347 | 386 |
// Check if there are any pages to show |
| 348 | 387 |
if($query_menu->numRows() > 0) {
|
| 349 |
// Print menu header
|
|
| 350 |
echo "\n".$menu_header;
|
|
| 388 |
// Print menu header
|
|
| 389 |
echo "\n".$this->menu_header;
|
|
| 351 | 390 |
// Loop through pages |
| 352 | 391 |
while($page = $query_menu->fetchRow()) {
|
| 353 |
// Check if this page should be shown
|
|
| 392 |
// Check if this page should be shown
|
|
| 354 | 393 |
// Create vars |
| 355 | 394 |
$vars = array('[class]','[a]', '[/a]', '[menu_title]', '[page_title]');
|
| 356 | 395 |
// Work-out class |
| 357 | 396 |
if($page['page_id'] == PAGE_ID) {
|
| 358 |
$class = $current_class; |
|
| 397 |
$class = $this->menu_current_class;
|
|
| 359 | 398 |
} else {
|
| 360 |
$class = $default_class; |
|
| 399 |
$class = $this->menu_default_class;
|
|
| 361 | 400 |
} |
| 362 | 401 |
// Check if link is same as first page link, and if so change to WB URL |
| 363 |
if($page['link'] == $default_link AND !INTRO_PAGE) {
|
|
| 402 |
if($page['link'] == $this->default_link AND !INTRO_PAGE) {
|
|
| 364 | 403 |
$link = WB_URL; |
| 365 | 404 |
} else {
|
| 366 |
$link = page_link($page['link']); |
|
| 405 |
$link = $this->page_link($page['link']);
|
|
| 367 | 406 |
} |
| 368 | 407 |
// Create values |
| 369 | 408 |
$values = array($class,'<a href="'.$link.'" target="'.$page['target'].'" '.$class.'>', '</a>', stripslashes($page['menu_title']), stripslashes($page['page_title'])); |
| 370 | 409 |
// Replace vars with value and print |
| 371 |
echo "\n".str_replace($vars, $values, $item_template); |
|
| 410 |
echo "\n".str_replace($vars, $values, $this->menu_item_template);
|
|
| 372 | 411 |
// Generate sub-menu |
| 373 |
if($collapse==false OR ($collapse==true AND isset($this->page_trail[$page['page_id']]))) {
|
|
| 374 |
$this->menu($menu_number, 0, $recurse-1, $collapse, $item_template, $item_footer, $menu_header, $menu_footer, $default_class, $current_class, $page['page_id']); |
|
| 412 |
if($this->menu_collapse==false OR ($this->menu_collapse==true AND isset($this->page_trail[$page['page_id']]))) {
|
|
| 413 |
$this->menu_recurse--; |
|
| 414 |
$this->menu_parent=$page['page_id']; |
|
| 415 |
$this->show_menu(); |
|
| 375 | 416 |
} |
| 376 |
echo "\n".$item_footer; |
|
| 417 |
echo "\n".$this->menu_item_footer;
|
|
| 377 | 418 |
} |
| 378 | 419 |
// Print menu footer |
| 379 |
echo "\n".$menu_footer; |
|
| 420 |
echo "\n".$this->menu_footer;
|
|
| 380 | 421 |
} |
| 381 | 422 |
} |
| 382 | 423 |
|
Also available in: Unified diff
Rewrote menu function. Parameters are now given as attributes to frontend class.