email_invitation.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Accept an email invitation
  4. */
  5. $invitecode = get_input("invitecode");
  6. $user = elgg_get_logged_in_user_entity();
  7. $forward_url = REFERER;
  8. if (!empty($invitecode)) {
  9. $forward_url = elgg_get_site_url() . "groups/invitations/" . $user->username;
  10. $group = group_tools_check_group_email_invitation($invitecode);
  11. if (!empty($group)) {
  12. if (groups_join_group($group, $user)) {
  13. $invitecode = sanitise_string($invitecode);
  14. $options = array(
  15. "guid" => $group->getGUID(),
  16. "annotation_name" => "email_invitation",
  17. "wheres" => array("(v.string = '" . $invitecode . "' OR v.string LIKE '" . $invitecode . "|%')"),
  18. "annotation_owner_guid" => $group->getGUID(),
  19. "limit" => 1
  20. );
  21. $annotations = elgg_get_annotations($options);
  22. if (!empty($annotations)) {
  23. // ignore access in order to cleanup the invitation
  24. $ia = elgg_set_ignore_access(true);
  25. $annotations[0]->delete();
  26. // restore access
  27. elgg_set_ignore_access($ia);
  28. }
  29. $forward_url = $group->getURL();
  30. system_message(elgg_echo("group_tools:action:groups:email_invitation:success"));
  31. } else {
  32. register_error(elgg_echo("group_tools:action:groups:email_invitation:error:join", array($group->name)));
  33. }
  34. } else {
  35. register_error(elgg_echo("group_tools:action:groups:email_invitation:error:code"));
  36. }
  37. } else {
  38. register_error(elgg_echo("group_tools:action:groups:email_invitation:error:input"));
  39. }
  40. forward($forward_url);