You are here

function og_set_theme in Organic groups 5.3

Same name and namespace in other branches
  1. 5.8 og.module \og_set_theme()
  2. 5 og.module \og_set_theme()
  3. 5.2 og.module \og_set_theme()
  4. 5.7 og.module \og_set_theme()
  5. 6.2 og.module \og_set_theme()
  6. 6 og.module \og_set_theme()
1 call to og_set_theme()
og_theme in ./og.module
Override theme based on what group is being displayed (if any). Be smart about selecting the 'active' group for ambigous urls like node/$nid

File

./og.module, line 264

Code

function og_set_theme($nid) {
  global $custom_theme, $user;
  $node = node_load(intval($nid));
  if (og_is_group_type($node->type)) {
    $custom_theme = $node->og_theme;
    return $node;
  }
  else {
    switch (count($node->og_groups)) {
      case 0:
        return NULL;
      case 1:
        $group_node = node_load($node->og_groups[0]);
        $custom_theme = $group_node->og_theme;
        break;
      default:

        // node is in multiple groups. preference goes to the group we showed on the prior page view (if any),
        // then to a group the current user is a member of
        if (in_array($_SESSION['og_last'], $node->og_groups)) {
          $group_node = node_load($_SESSION['og_last']);
          $custom_theme = $group_node->og_theme;
        }
        else {
          $groups = array();

          // intersect the node's groups with the user's groups
          if ($user->uid) {
            $groups = array_intersect($node->og_groups, array_keys($user->og_groups));
          }

          // no user is logged in, or none of the node's groups are the user's groups
          if (empty($groups)) {
            $groups = $node->og_groups;
          }

          // use array_shift and not [0] because array_intersect preserves keys
          $group_node = node_load(array_shift($groups));
          $custom_theme = $group_node->og_theme;
        }
    }
    return $group_node;
  }
}