You are here

function spaces_features_menu in Spaces 5

Same name and namespace in other branches
  1. 5.2 spaces.module \spaces_features_menu()
  2. 6 spaces.module \spaces_features_menu()

returns a keyed array of features split by public/private/group-agnostic TODO: can this be optimized? maybe if we store our data differently : |

1 call to spaces_features_menu()
_spaces_block_nav in ./spaces_block.inc
Default navigation menu - you may want use customized version in tic.

File

./spaces.module, line 1052

Code

function spaces_features_menu($op, $subnav = false) {
  static $menu;

  // use static cached menu if possible
  if (!$menu) {
    $menu = array(
      'main' => array(),
      'subnav' => array(),
    );
    $all_features = spaces_features();
    $og_features = spaces_features(spaces_gid());

    // iterate through public/private features and categorize accordingly
    foreach ($all_features as $feature => $f) {
      if ($f->menu) {
        $addto = array();
        $item = _spaces_feature_menu_tree($f);
        if ($f->spaces['options']) {
          switch ($og_features[$feature]) {
            case SPACES_PRIVATE:
              if (spaces_is_member()) {
                $addto[] = 'private';
              }
              break;
            case SPACES_PUBLIC:
              $addto[] = 'public';
              break;
          }
        }
        else {
          $addto[] = 'agnostic';
        }
        foreach ($addto as $key) {
          if ($item) {
            $menu['main'][$key][$feature] = $item;
            if ($item['children']) {
              $menu['subnav'][$key][$feature] = $item['children'];
            }
          }
        }
      }
    }

    // Sort items in each of the menu types by weight
    foreach ($menu['main'] as $key => $dummy) {
      uasort($menu['main'][$key], '_element_sort');
    }
  }
  switch ($subnav) {
    case false:
      return isset($menu['main'][$op]) ? $menu['main'][$op] : array();
    case true:
      return isset($menu['subnav'][$op]) ? $menu['subnav'][$op] : array();
  }
}