Tks!

Comments

jvieille’s picture

Issue summary: View changes

I used this module to ensure a consistent experience for anonymous user, in order to associate a predictible context to multiple group posts. I modified this function in og.module to end up with this code:
- the first if in elsif keeps the logged in user in the current group
- the second selects the primary group if the fist if does not get through (this is the case for anonymous users)
- the third one selects a random group as usual if the primary group was not set

This function add $_SESSION['og_last'] = $node->nid; as a tweak to remind the group context because the function og_exit is inoperant with my Pressflow install.

function og_determine_context_get_group($node, $account = NULL) {
  if (empty($account)) {
    global $user;
    $account = drupal_clone($user);
  }
  if (og_is_group_type($node->type)) {
    $group_node = $node;
    $_SESSION['og_last'] = $node->nid;
  }
  elseif (og_is_group_post_type($node->type) && !empty($node->og_groups)) {
    if (isset($_SESSION['og_last']) && in_array($_SESSION['og_last'], $node->og_groups) && !$group) {
      $group = $_SESSION['og_last'];
    }    
    if (module_exists('og_primary') && !$group){
      $group = og_primary_group($node);
    }
    if (!$group) {
      // No user is logged in, or none of the node's groups are the user's groups
      $group = current($node->og_groups);
    }
    if (!empty($group)) {
      $group_node = node_load($group);
    }
  }
  // Make sure user has view access to the group node.
  if (!empty($group_node) && node_access('view', $group_node, $account)) {
    return $group_node;
  }
}