You are here

function og_subscribe in Organic groups 6.2

Same name and namespace in other branches
  1. 5.8 og.module \og_subscribe()
  2. 5 og.module \og_subscribe()
  3. 5.2 og.module \og_subscribe()
  4. 5.3 og.module \og_subscribe()
  5. 5.7 og.module \og_subscribe()
  6. 6 og.module \og_subscribe()
1 string reference to 'og_subscribe'
og_menu in ./og.module
Implementation of hook_menu().

File

./og.pages.inc, line 277
Page callbacks for Organic groups.

Code

function og_subscribe($node, $uid = NULL) {
  global $user;
  if (is_null($uid)) {
    if ($user->uid) {
      $account = drupal_clone($user);
    }
    else {
      $dest = drupal_get_destination();
      if (variable_get('user_register', 1) == 0) {
        drupal_set_message(t('In order to join this group, you must <a href="!login">login</a>. After you have successfully done so, you will need to request membership again.', array(
          '!login' => url("user/login", array(
            'query' => $dest,
          )),
        )));
      }
      else {
        drupal_set_message(t('In order to join this group, you must <a href="!login">login</a> or <a href="!register">register</a> a new account. After you have successfully done so, you will need to request membership again.', array(
          '!register' => url("user/register", array(
            'query' => $dest,
          )),
          '!login' => url("user/login", array(
            'query' => $dest,
          )),
        )));
      }
      drupal_goto('user', $dest);
    }
  }
  else {
    $account = user_load(array(
      'uid' => $uid,
    ));
  }
  if ($node->og_selective >= OG_INVITE_ONLY || $node->status == 0 || !og_is_group_type($node->type)) {
    drupal_access_denied();
    exit;
  }

  // Only admins can add another member.
  if ($account->uid != $user->uid && !og_is_group_admin($node)) {
    drupal_access_denied();
    exit;
  }
  else {
    if (isset($account->og_groups[$node->nid])) {
      drupal_set_message(t('@user is already a member of the group @group.', array(
        '@user' => $account->name,
        '@group' => $node->title,
      )));
      drupal_goto('node/' . $node->nid);
    }
    else {
      return drupal_get_form('og_confirm_subscribe', $node->nid, $node, $account);
    }
  }
}