| 1 |
<?php |
| 2 |
$MENU = [ |
| 3 |
'id' => '', |
| 4 |
'parent' => null, |
| 5 |
'text' => '', |
| 6 |
'root' => '', |
| 7 |
'path' => '', |
| 8 |
'style' => null, |
| 9 |
'file' => '' |
| 10 |
]; |
| 11 |
|
| 12 |
function &find_menu_item($id, &$menu = null) |
| 13 |
{ |
| 14 |
global $MENU; |
| 15 |
|
| 16 |
$result = null; |
| 17 |
if (!isset($id)) { |
| 18 |
return $result; |
| 19 |
} |
| 20 |
if (!isset($menu)) { |
| 21 |
$menu = &$MENU; |
| 22 |
} |
| 23 |
if (!array_key_exists('items', $menu)) { |
| 24 |
return $result; |
| 25 |
} |
| 26 |
|
| 27 |
foreach ($menu['items'] as &$item) |
| 28 |
{ |
| 29 |
if (isset($item['id']) && ($item['id'] == $id)) { |
| 30 |
return $item; |
| 31 |
} |
| 32 |
|
| 33 |
if (array_key_exists('items', $item)) |
| 34 |
{ |
| 35 |
$subitem = &find_menu_item($id, $item); |
| 36 |
if (isset($subitem)) { |
| 37 |
return $subitem; |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
return $result; |
| 43 |
} |
| 44 |
|
| 45 |
function def_menu_item($parent, $id, $text, $css_style, $file = null) |
| 46 |
{ |
| 47 |
global $MENU; |
| 48 |
|
| 49 |
$item = array( |
| 50 |
'id' => $id, |
| 51 |
'parent' => ((isset($parent)) && (strlen($parent) > 0)) ? $parent : null, |
| 52 |
'text' => $text, |
| 53 |
'root' => '', |
| 54 |
'path' => '', |
| 55 |
'style' => $css_style, |
| 56 |
'file' => isset($file) ? $file : $id |
| 57 |
); |
| 58 |
|
| 59 |
if ((!isset($parent)) || (strlen($parent) <= 0)) |
| 60 |
{ |
| 61 |
$item['root'] = '..'; |
| 62 |
$mi = &$MENU; |
| 63 |
} |
| 64 |
else |
| 65 |
{ |
| 66 |
$mi = &find_menu_item($parent); |
| 67 |
$item['path'] .= ((strlen($mi['path']) > 0) ? $mi['path'] . '/' : '') . $mi['id']; |
| 68 |
$item['root'] .= '..' . ((strlen($mi['root']) > 0) ? '/' . $mi['root'] : ''); |
| 69 |
} |
| 70 |
|
| 71 |
if ((!array_key_exists('items', $mi)) || (!isset($mi['items']))) |
| 72 |
$mi['items'] = [ $item ]; |
| 73 |
else |
| 74 |
array_push($mi['items'], $item); |
| 75 |
} |
| 76 |
|
| 77 |
function output_menu(&$menu = null) |
| 78 |
{ |
| 79 |
global $MENU; |
| 80 |
if (!isset($menu)) { |
| 81 |
$menu = &$MENU; |
| 82 |
} |
| 83 |
|
| 84 |
$css_class = "index"; |
| 85 |
if (isset($menu['style'])) { |
| 86 |
$css_class .= " " . $menu['style']; |
| 87 |
} |
| 88 |
|
| 89 |
print "<ul class=\"{$css_class}\">\n"; |
| 90 |
if (array_key_exists('items', $menu)) { |
| 91 |
foreach ($menu['items'] as &$item) |
| 92 |
{ |
| 93 |
if (array_key_exists('items', $item)) |
| 94 |
{ |
| 95 |
print("<li>{$item['text']}</li>\n"); |
| 96 |
output_menu($item); |
| 97 |
} |
| 98 |
else |
| 99 |
{ |
| 100 |
$path = (strlen($item['path']) > 0) ? $item['path'] . '/' : ''; |
| 101 |
print("<li><a href=\"html/{$path}{$item['id']}.html\">{$item['text']}</a></li>\n"); |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
print "</ul>\n"; |
| 106 |
} |
| 107 |
|
| 108 |
function raw_menu_list(&$target, &$menu = null) |
| 109 |
{ |
| 110 |
global $MENU; |
| 111 |
if (!isset($menu)) { |
| 112 |
$menu = &$MENU; |
| 113 |
} |
| 114 |
|
| 115 |
if (!array_key_exists('items', $menu)) { |
| 116 |
array_push($target, $menu); |
| 117 |
return; |
| 118 |
} |
| 119 |
|
| 120 |
foreach ($menu['items'] as &$item) |
| 121 |
{ |
| 122 |
raw_menu_list($target, $item); |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
?> |