You are here

function og_session_context_get_context in OG Session Context 7

return the current group context

1 call to og_session_context_get_context()
og_session_context_og_context_handler_sessions in ./og_session_context.module
Callback to pass the og context value based on the last space or space content page visited.

File

./og_session_context.module, line 34
Provides hook implementations and functionality for og_session_context.

Code

function og_session_context_get_context() {
  $item = menu_get_item();
  $nid = NULL;

  // Special support for /comment/reply/%.
  if ($item['path'] == 'comment/reply/%') {
    if (isset($item['original_map'][2]) && is_numeric($item['original_map'][2])) {
      $nid = $item['original_map'][2];
    }
  }
  elseif ($item['path'] == 'comment/%') {
    if (isset($item['original_map'][1]) && is_numeric($item['original_map'][1])) {
      if ($comment = comment_load($item['original_map'][1])) {
        $nid = $comment->nid;
      }
    }
  }
  else {
    $menu = menu_get_object();
    if (isset($menu->nid)) {
      $nid = $menu->nid;
    }
  }
  if (!$nid) {
    return 0;
  }
  $node = node_load($nid);
  if (empty($node)) {
    return 0;
  }
  if (og_is_group('node', $node)) {

    // get space id directly from space nodes
    return $nid;
  }
  elseif (!empty($node->{OG_AUDIENCE_FIELD}[LANGUAGE_NONE][0]['target_id'])) {

    // otherwise get space id from space field reference
    return $node->{OG_AUDIENCE_FIELD}[LANGUAGE_NONE][0]['target_id'];
  }
  return 0;
}