You are here

function footermap_get_menu in footermap: a footer site map 6

Same name and namespace in other branches
  1. 5.2 footermap.module \footermap_get_menu()
  2. 5 footermap.module \footermap_get_menu()
  3. 7 footermap.module \footermap_get_menu()
1 call to footermap_get_menu()
_footermap_render in ./footermap.module

File

./footermap.module, line 233

Code

function footermap_get_menu($mlid, &$mapref, $recurse, $level) {
  global $user;
  if ($recurse != 0 && $level >= $recurse) {
    return;
  }
  $avail_menus = variable_get('avail_menus', array());
  if (variable_get('sys_menus', 0) == 0) {
    $system_menu = " AND ml.module <> 'system' ";
  }
  else {
    $system_menu = ' ';
  }
  $sql = 'SELECT * FROM {menu_links} ml LEFT OUTER JOIN {menu_router} mr ON (ml.router_path = mr.path) WHERE ml.plid = %d AND ml.hidden = 0' . $system_menu . 'ORDER BY ml.plid, ml.weight, ml.link_title, mr.title';
  $res = db_query($sql, $mlid);
  while ($h = db_fetch_object($res)) {

    // available menus check
    if (!_footermap_check_menu_item($avail_menus, $h)) {
      continue;
    }

    // access check for menu router items
    if (isset($h->path)) {
      if (empty($h->access_callback)) {

        // automatic fail
        continue;
      }
      $map = array();
      $args = array();
      $map = explode('/', $h->link_path);
      if (!empty($h->to_arg_functions)) {
        _menu_link_map_translate($map, $h->to_arg_functions);
      }
      $args = menu_unserialize($h->access_arguments, $map);

      // There's no way that I can do access callback stuff for every
      // custom access callback with custom arguments under the sun.
      // It's out of scope of this module, and a non-issue.
      if ($h->access_callback == 'user_access') {
        if (!empty($args[0])) {
          if (!user_access($args[0], $user)) {
            continue;
          }
        }
      }
      else {
        if ($h->access_callback == 'node_access') {
          if (!node_access($args[0], node_load($args[1]))) {
            continue;
          }
        }
      }
    }
    $mapref[$h->menu_name]['menu-' . $h->mlid] = array(
      'href' => $h->link_path,
      'title' => $h->link_title,
    );
    if ($h->has_children == 1) {
      footermap_get_menu($h->mlid, $mapref, $recurse, $level + 1);
    }
  }
}