function theme_superfish in Superfish 6
Same name and namespace in other branches
- 7 superfish.module \theme_superfish()
Theme function to allow any menu tree to be themed as a Superfish menu.
1 theme call to theme_superfish()
- superfish_block in ./
superfish.module - Implements hook_block().
File
- ./
superfish.module, line 1413 - Enables the use of jQuery Superfish plugin for Drupal menus.
Code
function theme_superfish($id, $menu_name, $mlid, $sfsettings = NULL) {
global $user, $language;
$menu = menu_tree_all_data($menu_name);
if (function_exists('i18nmenu_localize_tree')) {
i18nmenu_localize_tree($menu);
}
// For custom $menus and menus built all the way from the top-level we
// don't need to "create" the specific sub-menu and we need to get the title
// from the $menu_name since there is no "parent item" array.
// Create the specific menu if we have a mlid.
if (!empty($mlid)) {
// Load the parent menu item.
$item = menu_link_load($mlid);
$title = check_plain($item['title']);
$parent_depth = $item['depth'];
// Narrow down the full menu to the specific sub-tree we need.
for ($p = 1; $p < 10; $p++) {
if ($sub_mlid = $item["p{$p}"]) {
$subitem = menu_link_load($sub_mlid);
$key = 50000 + $subitem['weight'] . ' ' . $subitem['title'] . ' ' . $subitem['mlid'];
$menu = isset($menu[$key]['below']) ? $menu[$key]['below'] : $menu;
}
}
}
else {
$result = db_result(db_query("SELECT title FROM {menu_custom} WHERE menu_name = '%s'", $menu_name));
$title = check_plain($result);
}
$output['content'] = '';
if ($id == 2 && $user->uid) {
$output['subject'] = check_plain($user->name);
}
else {
$output['subject'] = $title;
}
if ($menu) {
// Set the total menu depth counting from this parent if we need it.
$depth = $sfsettings['depth'];
$depth = $depth > 0 && isset($parent_depth) ? $parent_depth + $depth : $depth;
$trail = superfish_build_page_trail(menu_tree_page_data($menu_name));
if ($menu_tree = theme('superfish_build', $id, $menu, $depth, $trail, FALSE, $sfsettings)) {
if ($menu_tree['content']) {
// Wrapping main UL
if ($sfsettings['wrapmul'] && strpos($sfsettings['wrapmul'], ',') !== FALSE) {
$wmul = explode(',', $sfsettings['wrapmul']);
// In case you just wanted to add something after the element.
if (drupal_substr($sfsettings['wrapmul'], 0) == ',') {
array_unshift($wmul, '');
}
}
else {
$wmul = array();
}
$output['content'] = isset($wmul[0]) ? $wmul[0] : '';
$output['content'] .= '<ul id="superfish-' . $id . '"';
$output['content'] .= ' class="sf-menu sf-' . $menu_name . ' sf-' . $sfsettings['type'] . ' sf-style-' . $sfsettings['style'];
$output['content'] .= $sfsettings['itemcounter'] ? ' sf-total-items-' . $menu_tree['total_children'] : '';
$output['content'] .= $sfsettings['itemcounter'] ? ' sf-parent-items-' . $menu_tree['parent_children'] : '';
$output['content'] .= $sfsettings['itemcounter'] ? ' sf-single-items-' . $menu_tree['single_children'] : '';
$output['content'] .= $sfsettings['ulclass'] ? ' ' . $sfsettings['ulclass'] : '';
$output['content'] .= $language->direction == 1 ? ' rtl' : '';
$output['content'] .= '">' . $menu_tree['content'] . '</ul>';
$output['content'] .= isset($wmul[1]) ? $wmul[1] : '';
}
}
}
return $output;
}