diff options
Diffstat (limited to 'includes/menu.inc')
-rw-r--r-- | includes/menu.inc | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/includes/menu.inc b/includes/menu.inc new file mode 100644 index 000000000..0d592714f --- /dev/null +++ b/includes/menu.inc @@ -0,0 +1,127 @@ +<?php + +function menu_trail() { + + global $REQUEST_URI; + static $trail = NULL; + + /* + ** Retrieve the currently active link. + */ + + if (empty($trail)) { + + $path = array(); + $link = substr($REQUEST_URI, strrpos($REQUEST_URI, "/") + 1, strlen($REQUEST_URI)); + $item = db_fetch_object(db_query("SELECT * FROM menu WHERE link = '%s'", $link)); + + /* + ** Compile an array of menu objects that represent the path to + ** the root link. + */ + + if ($item) { + $path[] = $item; + + while ($item->parent) { + $result = db_query("SELECT * FROM menu WHERE name = '%s' ORDER BY weight, name", $item->parent); + if ($item = db_fetch_object($result)) { + $path[] = $item; + } + } + } + + $trail = array_reverse($path); + } + + return $trail; +} + +function menu_item($item) { + global $REQUEST_URI; + + /* + ** If you want to theme your links, or if you want to replace them + ** by an image, this would be the function to customize. + */ + + if (stristr($REQUEST_URI, $item->link) == $item->link) { + return t($item->name); + } + else if ($item->title) { + return "<a href=\"$item->link\" title=\"". t($item->title) ."\">". t($item->name) ."</a>"; + } + else { + return "<a href=\"$item->link\">". t($item->name) ."</a>"; + } +} + +function menu_path() { + + $path = menu_trail(); + + $links = array(); + + foreach ($path as $item) { + $links[] = menu_item($item); + } + + return implode(" > ", $links); +} + +function menu_menu_row($parent = "") { + + $links = array(); + + $result = db_query("SELECT * FROM menu WHERE parent = '%s' ORDER BY weight, name", $parent); + while ($menu = db_fetch_object($result)) { + $links[] = menu_item($menu); + } + + return $links; +} + +function menu_menu() { + $path = menu_trail(); + if ($path) { + $item = array_pop($path); + $output = implode(" · ", menu_menu_row($item->name)); + } + else { + $output = implode( " · ", menu_menu_row()); + } + + return $output; +} + +function menu_help() { + $path = menu_trail(); + if ($path) { + $item = array_pop($path); + $output = $item->help; + } + + return $output; +} + +function menu_tree($parent = "", $overview = 0) { + + $result = db_query("SELECT * FROM menu WHERE parent = '%s' AND overview = '%d' ORDER BY weight, name", $parent, $overview); + + print "<ul>"; + while ($item = db_fetch_object($result)) { + print "<li>". menu_item($item) ."</li>"; + menu_tree($item->name, 1); + } + print "</ul>"; + + return $links; +} + +function menu_add($name, $link, $title = NULL, $help = NULL, $parent = NULL, $weight = 1, $overview = 0) { + if (!db_result(db_query("SELECT name FROM menu WHERE link = '%s'", $link))) { + db_query("INSERT INTO menu (name, link, title, help, parent, weight, overview) VALUES ('%s', '%s', '%s', '%s', '%s', '%d', '%d')", $name, $link, $title, $help, $parent, $weight, $overview); + } +} + +?>
\ No newline at end of file |