theme_superfish

  1. superfish
    1. 7
    2. 6
Versions
7 theme_superfish($variables)
6 theme_superfish($id, $menu_name, $mlid, $sfsettings = NULL)

Theme function to allow any menu tree to be themed as a Superfish menu.

Code

./superfish.module, line 761

<?php
function theme_superfish($variables) {
  global $user, $language;

  $id = $variables['id'];
  $menu_name = $variables['menu_name'];
  $mlid = $variables['mlid'];
  $sfsettings = $variables['sfsettings'];

  $cache_key = 'links:' . $menu_name . ':all-cid:' . $variables['mlid'] . ':' . $user->uid . ':' . $language->language;
  $cache = cache_get($cache_key, 'cache_menu');
  if ($cache && isset($cache->data)) {
    $cache = $cache->data;
  }
  else {
    // Start caching the menu.
    $cache = array();
    $cache['menu'] = menu_tree_all_data($menu_name);

    // 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);
      $cache['title'] = check_plain($item['title']);
      $cache['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'];
          $cache['menu'] = (isset($cache['menu'][$key]['below'])) ? $cache['menu'][$key]['below'] : $cache['menu'];
        }
      }
    }
    else {
      $result = db_query("SELECT title FROM {menu_custom} WHERE menu_name = :a", array(':a' => $menu_name))->fetchField();
      $cache['title'] = check_plain($result);
    }
    cache_set($cache_key, $cache, 'cache_menu');
    $cache = cache_get($cache_key, 'cache_menu')->data;
  }

  $output['content'] = '';
  $output['subject'] = $cache['title'];
  if ($cache['menu']) {
    // Set the total menu depth counting from this parent if we need it.
    $depth = $sfsettings['depth'];
    $depth = ($sfsettings['depth'] > 0 && isset($cache['parent_depth'])) ? $cache['parent_depth'] + $depth : $depth;

    $var = array(
      'id' => $id, 
      'menu' => $cache['menu'], 
      'depth' => $depth, 
      'trail' => superfish_build_page_trail(menu_tree_page_data($menu_name)), 
      'sfsettings' => $sfsettings,
    );
    if ($menu_tree = theme('superfish_build', $var)) {
      if ($menu_tree['content']) {
        // Add custom HTML codes around the main menu.
        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 ' . $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;
}
?>