You are here

function og_subscribe in Organic groups 5.2

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

File

./og.module, line 667

Code

function og_subscribe($gid, $uid = NULL) {
  global $user;
  if (is_null($uid)) {
    if ($user->uid) {
      $account = $user;
    }
    else {
      drupal_set_message(t('In order to subscribe to this group, you must login or register a new account. After you have successfully done so, you will need to follow the <em>subscribe</em> link again.'));
      drupal_goto('user');
    }
  }
  else {
    $account = user_load(array(
      'uid' => $uid,
    ));
  }
  $node = node_load($gid);
  if (!node_access('view', $node)) {

    // if you can't view the group, you can't subscribe either. group homepages can be private with some custom coding.
    drupal_access_denied();
  }

  // only admins can subscribe another person
  if ($account->uid != $user->uid && !node_access('update', $node)) {
    drupal_access_denied();
  }
  else {
    if (isset($account->og_groups[$node->nid])) {
      drupal_set_message(t('@user is already subscribed to the group @group', array(
        '@user' => $account->name,
        '@group' => $node->title,
      )));
      drupal_goto('node/' . $node->nid);
    }
    else {
      return drupal_get_form('og_confirm_subscribe', $gid, $node, $account);
    }
  }
}