/** * Convert group invites to group invitations and friend requests * * @param string $event "create" * @param string $type "user" * @param ElggUser $user User entity * @return void */ function groups_invite_user_created_event($event, $type, $user) { $email = $user->email; $group_invite = groups_invite_get_group_invite($email, false); if (!$group_invite) { return; } $ia = elgg_set_ignore_access(true); $groups = new ElggBatch('elgg_get_entities_from_relationship', array('types' => 'group', 'relationship' => 'invited_to', 'relationship_guid' => $group_invite->guid, 'inverse_relationship' => false, 'limit' => 0)); foreach ($groups as $group) { add_entity_relationship($group->guid, 'invited', $user->guid); } if (elgg_is_active_plugin('friend_request')) { // We don't want to make people friends automatically // Least we can do is create a friend request, so that the new user can confirm it $inviters = new ElggBatch('elgg_get_entities_from_relationship', array('types' => 'user', 'relationship' => 'invited_by', 'relationship_guid' => $group_invite->guid, 'inverse_relationship' => false, 'limit' => 0)); foreach ($inviters as $inviter) { add_entity_relationship($inviter->guid, 'friendrequest', $user->guid); } } $group_invite->delete(); elgg_set_ignore_access($ia); }
$email = trim($email); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error++; continue; } $users = get_user_by_email($email); if ($users) { $invitee_guids[] = $users[0]->guid; continue; } if (!elgg_get_config('allow_registration')) { $error++; continue; } $new = false; $group_invite = groups_invite_get_group_invite($email); if (!$group_invite) { $new = true; $group_invite = groups_invite_create_group_invite($email); } if (!$new && !$resend) { $skipped++; continue; } add_entity_relationship($group_invite->guid, 'invited_by', $inviter->guid); add_entity_relationship($group_invite->guid, 'invited_to', $group->guid); $link = elgg_trigger_plugin_hook('registration_link', 'site', ['email' => $email, 'friend_guid' => $inviter->guid], elgg_normalize_url('register')); $site = elgg_get_site_entity(); $notification_params = array('inviter' => $inviter->getDisplayName(), 'group' => $group->getDisplayName(), 'site' => $site->getDisplayName(), 'message' => $message ? elgg_echo('groups:invite:notify:message', array($message)) : '', 'link' => $link); $subject = elgg_echo('groups:invite:notify:subject', array($group->getDisplayName())); $body = elgg_echo('groups:invite:notify:body', $notification_params);