og_unsubscribe

5 og.module og_unsubscribe($gid, $uid = NULL)

File

contributions/og/og.module, line 809

Code

<?php
function og_unsubscribe($gid, $uid = NULL) {
  global $user;
  if (is_null($uid)) {
    $uid = $user->uid;
  }
  $node = node_load($gid);
  $account = user_load(array('uid' => $uid));
  if (!in_array($gid, array_keys(og_get_subscriptions($account->uid, 0))) || ($uid != $user->uid && !og_is_node_admin($node))) {
    // Ubsubscribee must be a member or awaiting approval
    // Only admins can remove another member.
    drupal_access_denied();
    exit();
  }
  if (!og_is_group_type($node->type) || ($node->og_selective == OG_CLOSED && !og_is_node_admin($node)) || $node->uid == $uid) {
    // Regular users may not leave from a closed group
    // Group manager may never leave (TODO: fix), such a link should never be generated
    drupal_access_denied();
    exit();
  }
  else {
    return drupal_get_form('og_confirm_unsubscribe', $gid, $node, $uid);
  }
}
?>