/** * {@inheritdoc} */ public function post(ParameterBag $params) { $user = elgg_get_logged_in_user_entity(); $group = get_entity($params->guid); // join or request $join = false; if ($group->isPublicMembership() || $group->canEdit($user->guid)) { // anyone can join public groups and admins can join any group $join = true; } else { if (check_entity_relationship($group->guid, 'invited', $user->guid)) { // user has invite to closed group $join = true; } } if ($join) { if (groups_join_group($group, $user)) { $msg = elgg_echo("groups:joined"); } else { throw new GraphException(elgg_echo("groups:cantjoin")); } } else { if (!add_entity_relationship($user->guid, 'membership_request', $group->guid)) { throw new GraphException(elgg_echo("groups:joinrequestnotmade")); } $owner = $group->getOwnerEntity(); $url = elgg_normalize_url("groups/requests/{$group->guid}"); $subject = elgg_echo('groups:request:subject', array($user->name, $group->name), $owner->language); $body = elgg_echo('groups:request:body', array($group->getOwnerEntity()->name, $user->name, $group->name, $user->getURL(), $url), $owner->language); // Notify group owner notify_user($owner->guid, $user->getGUID(), $subject, $body); $msg = elgg_echo("groups:joinrequestmade"); } return array('nodes' => array('member' => check_entity_relationship($user->guid, 'member', $group->guid), 'invited' => check_entity_relationship($group->guid, 'invited', $user->guid), 'membership_request' => check_entity_relationship($user->guid, 'membership_request', $group->guid))); }
function file_tools_object_handler($event, $type, $object) { if (!empty($object) && elgg_instanceof($object, "object", "file")) { $folder_guid = (int) get_input("folder_guid", 0); if (!empty($folder_guid)) { if ($folder = get_entity($folder_guid)) { if (!elgg_instanceof($folder, "object", FILE_TOOLS_SUBTYPE)) { unset($folder_guid); } } else { unset($folder_guid); } } // remove old relationships remove_entity_relationships($object->getGUID(), FILE_TOOLS_RELATIONSHIP, true); if (!empty($folder_guid)) { add_entity_relationship($folder_guid, FILE_TOOLS_RELATIONSHIP, $object->getGUID()); //update parent folders last_action attribute update_entity_last_action($folder_guid); $parent_guid = get_entity($folder_guid)->parent_guid; if ($parent_guid) { update_parent_folder_last_action($parent_guid); } } } }
function group_tools_join_group_event($event, $type, $params) { static $auto_notification; // only load plugin setting once if (!isset($auto_notification)) { $auto_notification = false; if (elgg_get_plugin_setting("auto_notification", "group_tools") == "yes") { $auto_notification = true; } } if (!empty($params) && is_array($params)) { $group = elgg_extract("group", $params); $user = elgg_extract("user", $params); if ($user instanceof ElggUser && $group instanceof ElggGroup) { if ($auto_notification) { // enable email notification add_entity_relationship($user->getGUID(), "notifyemail", $group->getGUID()); if (elgg_is_active_plugin("messages")) { // enable site/messages notification add_entity_relationship($user->getGUID(), "notifysite", $group->getGUID()); } } // cleanup invites if (check_entity_relationship($group->getGUID(), "invited", $user->getGUID())) { remove_entity_relationship($group->getGUID(), "invited", $user->getGUID()); } // and requests if (check_entity_relationship($user->getGUID(), "membership_request", $group->getGUID())) { remove_entity_relationship($user->getGUID(), "membership_request", $group->getGUID()); } } } }
/** * Assigns a role to a particular user * * @param ElggRole $role The role to be assigned * @param ElggUser $user The user the role needs to be assigned to * @return mixed True if the role change was successful, false if could not update user role, and null if there was no change in user role */ function roles_set_role($role, $user = null) { if (!elgg_instanceof($role, 'object', 'role')) { return false; // Couldn't set new role } $user = $user ? $user : elgg_get_logged_in_user_entity(); if (!elgg_instanceof($user, 'user')) { return false; // Couldn't set new role } $current_role = roles_get_role($user); if ($role != $current_role) { remove_entity_relationships($user->guid, 'has_role'); if ($role->name != DEFAULT_ROLE && $role->name != ADMIN_ROLE) { if (!add_entity_relationship($user->guid, 'has_role', $role->guid)) { return false; // Couldn't set new role } } return true; // Role has been changed } return null; // There was no change necessary, old and new role are the same }
/** * Performs action when a widget is created * * @param string $event name of the system event * @param string $object_type type of the event * @param mixed $object object related to the event * * @return void */ function widget_manager_create_object_handler($event, $object_type, $object) { if (elgg_instanceof($object, "object", "widget", "ElggWidget")) { $owner = $object->getOwnerEntity(); // Updates access for privately created widgets in a group or on site if ((int) $object->access_id === ACCESS_PRIVATE) { $old_ia = elgg_set_ignore_access(); if ($owner instanceof ElggGroup) { $object->access_id = $owner->group_acl; $object->save(); } elseif ($owner instanceof ElggSite) { $object->access_id = ACCESS_PUBLIC; $object->save(); } elgg_set_ignore_access($old_ia); } // Adds a relation between a widget and a multidashboard object $dashboard_guid = get_input("multi_dashboard_guid"); if ($dashboard_guid && widget_manager_multi_dashboard_enabled()) { $dashboard = get_entity($dashboard_guid); if (elgg_instanceof($dashboard, "object", MultiDashboard::SUBTYPE, "MultiDashboard")) { add_entity_relationship($object->getGUID(), MultiDashboard::WIDGET_RELATIONSHIP, $dashboard->getGUID()); } } } }
/** * {@inheritdoc} */ public function post(ParameterBag $params) { $user = get_entity($params->guid); $friend = $params->friend_uid ? $this->graph->get($params->friend_uid) : null; if (!$user instanceof ElggUser || !$friend instanceof ElggUser) { throw new GraphException("User or friend not found", HttpResponse::HTTP_NOT_FOUND); } if (!$user->canEdit()) { throw new GraphException("You are not allowed to modify this user's friends list", HttpResponse::HTTP_FORBIDDEN); } if ($user->guid == $friend->guid) { throw new GraphException("You are trying to friend yourself", HttpResponse::HTTP_BAD_REQUEST); } if (check_entity_relationship($user->guid, 'friend', $friend->guid)) { throw new GraphException("Already a friend", HttpResponse::HTTP_BAD_REQUEST); } if (!add_entity_relationship($user->guid, 'friend', $friend->guid)) { throw new GraphException("Unable to create friendship"); } $river_id = elgg_create_river_item(array('view' => 'river/relationship/friend/create', 'action_type' => 'friend', 'subject_guid' => $user->guid, 'object_guid' => $friend->guid)); $return = array('nodes' => array('friend' => check_entity_relationship($user->guid, 'friend', $friend->guid), 'friend_of' => check_entity_relationship($friend->guid, 'friend', $user->guid))); if (!empty($river_id)) { $river = elgg_get_river(array('ids' => $river_id)); $return['nodes']['activity'] = $river ? $river[0] : $river_id; } return $return; }
/** * Mark answer as correct * * @return bool */ public function markCorrect() { if (questions_close_on_marked_answer()) { $this->getQuestion()->setStatus('closed'); } return add_entity_relationship($this->getQuestion()->guid, "correctAnswer", $this->guid); }
/** * Add an object to a site. * * @param int $site_guid Site GUID * @param int $object_guid Object GUID * * @return mixed */ function add_site_object($site_guid, $object_guid) { global $CONFIG; $site_guid = (int) $site_guid; $object_guid = (int) $object_guid; return add_entity_relationship($object_guid, "member_of_site", $site_guid); }
/** * Retrieve ancestry relationships / update if they have changed * * @param int $guid * @param mixed $subtypes * @return boolean|array */ function hj_framework_set_ancestry($guid) { $entity = get_entity($guid); if (!$entity) { return false; } $ia = elgg_set_ignore_access(true); // Build an hierarchy from [0]highest to [X]lowest $ancestry = array(); $ancestry_guids = array(); $container = $entity->getContainerEntity(); while (elgg_instanceof($container)) { array_unshift($ancestry, $container); array_unshift($ancestry_guids, $container->guid); $container = $container->getContainerEntity(); } // Store as a hash so we don't unnecessarily update the hierarchy every time save() is calleed if (!isset($entity->hierarchy_hash) || $entity->hierarchy_hash != sha1(serialize($ancestry_guids))) { remove_entity_relationships($entity->guid, 'descendant', false); foreach ($ancestry as $ancestor) { if (elgg_instanceof($ancestor, 'object')) { update_entity_last_action($ancestor->guid, $entity->time_created); } if (!check_entity_relationship($entity->guid, 'descendant', $ancestor->guid)) { add_entity_relationship($entity->guid, 'descendant', $ancestor->guid); } } $entity->hierarchy_hash = sha1(serialize($ancestry_guids)); } elgg_set_ignore_access($ia); return $ancestry; }
/** * Subscribe a user to notifications about a target entity * * This method will return false if the subscription already exists. * * @param int $userGuid The GUID of the user to subscribe to notifications * @param string $method The delivery method of the notifications * @param int $targetGuid The entity to receive notifications about * @return boolean */ public function addSubscription($userGuid, $method, $targetGuid) { if (!in_array($method, $this->methods)) { return false; } $prefix = self::RELATIONSHIP_PREFIX; return add_entity_relationship($userGuid, "{$prefix}{$method}", $targetGuid); }
/** * When a user joins a group * * @param string $event join * @param string $type group * @param array $params array with the user and the user * * @return void */ function group_tools_join_group_event($event, $type, $params) { global $NOTIFICATION_HANDLERS; static $auto_notification; // only load plugin setting once if (!isset($auto_notification)) { $auto_notification = array(); if (isset($NOTIFICATION_HANDLERS) && is_array($NOTIFICATION_HANDLERS)) { if (elgg_get_plugin_setting("auto_notification", "group_tools") == "yes") { // Backwards compatibility $auto_notification = array("email", "site"); } foreach ($NOTIFICATION_HANDLERS as $method => $foo) { if (elgg_get_plugin_setting("auto_notification_" . $method, "group_tools") == "1") { $auto_notification[] = $method; } } } } if (!empty($params) && is_array($params)) { $group = elgg_extract("group", $params); $user = elgg_extract("user", $params); if ($user instanceof ElggUser && $group instanceof ElggGroup) { // check for the auto notification settings if (!empty($NOTIFICATION_HANDLERS) && is_array($NOTIFICATION_HANDLERS)) { foreach ($NOTIFICATION_HANDLERS as $method => $dummy) { if (in_array($method, $auto_notification)) { add_entity_relationship($user->getGUID(), "notify" . $method, $group->getGUID()); } } } // cleanup invites remove_entity_relationship($group->getGUID(), "invited", $user->getGUID()); // and requests remove_entity_relationship($user->getGUID(), "membership_request", $group->getGUID()); // cleanup email invitations $options = array("annotation_name" => "email_invitation", "annotation_value" => group_tools_generate_email_invite_code($group->getGUID(), $user->email), "limit" => false); if (elgg_is_logged_in()) { elgg_delete_annotations($options); } elseif ($annotations = elgg_get_annotations($options)) { group_tools_delete_annotations($annotations); } // welcome message $welcome_message = $group->getPrivateSetting("group_tools:welcome_message"); $check_message = trim(strip_tags($welcome_message)); if (!empty($check_message)) { // replace the place holders $welcome_message = str_ireplace("[name]", $user->name, $welcome_message); $welcome_message = str_ireplace("[group_name]", $group->name, $welcome_message); $welcome_message = str_ireplace("[group_url]", $group->getURL(), $welcome_message); // notify the user notify_user($user->getGUID(), $group->getGUID(), elgg_echo("group_tools:welcome_message:subject", array($group->name)), $welcome_message); } } } }
/** * Adds a relation between a widget and a multidashboard object * * @param unknown_type $event * @param unknown_type $type * @param unknown_type $object */ function widget_manager_create_object_handler($event, $type, $object) { if (elgg_instanceof($object, "object", "widget", "ElggWidget")) { if ($dashboard_guid = get_input("multi_dashboard_guid")) { if (($dashboard = get_entity($dashboard_guid)) && elgg_instanceof($dashboard, "object", MultiDashboard::SUBTYPE, "MultiDashboard")) { add_entity_relationship($object->getGUID(), MultiDashboard::WIDGET_RELATIONSHIP, $dashboard->getGUID()); } } } }
function save_answer($elgg_question, $answer_body) { $answer = new ElggObject(); $answer->subtype = "answer"; $answer->description = $answer_body; $answer->question_guid = $elgg_question->getGUID(); $answer->save(); add_entity_relationship($elgg_question->getGUID(), "answer", $answer->getGUID()); return $answer; }
/** * Reverses 'attached' relationship for old comments * @return void */ function interactions_20141231a() { $comments = new \ElggBatch('elgg_get_entities', array('types' => 'object', 'subtypes' => 'hjcomment', 'limit' => 0, 'callback' => false)); foreach ($comments as $comment) { $attachments = new \ElggBatch('elgg_get_entities_from_relationship', array('relationship' => 'attached', 'relationship_guid' => $comment->guid, 'inverse_relationship' => true, 'limit' => 0, 'callback' => false)); foreach ($attachments as $attachment) { add_entity_relationship($comment->guid, 'attached', $attachment->guid); } } }
/** * Save the relationship * * @return int the relationship id */ public function save() { if ($this->id > 0) { delete_relationship($this->id); } $this->id = add_entity_relationship($this->guid_one, $this->relationship, $this->guid_two); if (!$this->id) { throw new IOException(elgg_echo('IOException:UnableToSaveNew', array(get_class()))); } return $this->id; }
function entity_admins_manage_admins($event, $object_type, $object) { if (get_input('entity-admins-support') && $object instanceof ElggEntity) { remove_entity_relationships($object->guid, 'entity_admin_for', true); // currently the userpicker name is hardcoded to "members" $members = get_input('members'); if ($members) { foreach ($members as $guid) { add_entity_relationship($guid, 'entity_admin_for', $object->guid); } } } return true; }
/** * Add user as member of the chat. * * @param int $user_guid */ public function addMember($user_guid) { $success = add_entity_relationship($user_guid, 'member', $this->getGUID()); // Send notifications if ($success) { $user = elgg_get_logged_in_user_entity(); if ($user->guid !== $user_guid) { $subject = elgg_echo('chat:notification:subject:newchat'); $body = elgg_echo('chat:notification:newchat', array($user->name, $this->title, $this->getURL())); notify_user($user_guid, elgg_get_site_entity()->getGUID(), $subject, $body); } } return $success; }
public function testCanDelete() { $new_rel = function () { add_entity_relationship($this->user->guid, 'test_self1', $this->user->guid); return check_entity_relationship($this->user->guid, 'test_self1', $this->user->guid); }; $rel = $new_rel(); $res = delete_data("\n\t\t\tDELETE FROM {$this->prefix}entity_relationships\n\t\t\tWHERE id = {$rel->id}\n\t\t"); $this->assertIdentical($res, 1); $this->assertFalse(check_entity_relationship($this->user->guid, 'test_self1', $this->user->guid)); $rel = $new_rel(); $res = delete_data("\n\t\t\tDELETE FROM {$this->prefix}entity_relationships\n\t\t\tWHERE id = :id\n\t\t", [':id' => $rel->id]); $this->assertIdentical($res, 1); $this->assertFalse(check_entity_relationship($this->user->guid, 'test_self1', $this->user->guid)); }
function polls_add_choices($poll, $choices) { $i = 0; if ($choices) { foreach ($choices as $choice) { $poll_choice = new ElggObject(); $poll_choice->subtype = "poll_choice"; $poll_choice->text = $choice; $poll_choice->display_order = $i * 10; $poll_choice->access_id = $poll->access_id; $poll_choice->save(); add_entity_relationship($poll_choice->guid, 'poll_choice', $poll->guid); $i += 1; } } }
/** * Unblocks $blocked_user as blocked by $blocking_user. * * @param ElggUser $blocked_user * @param ElggUser $blocking_user * @return bool */ function block_user(\ElggUser $blocked_user, \ElggUser $blocking_user) { if (!$blocked_user instanceof \ElggUser) { return false; } if ($blocking_user && !$blocking_user instanceof \ElggUser) { return false; } elseif (!$blocking_user) { $blocking_user = elgg_get_logged_in_user_entity(); } // can't block admins if ($blocked_user->isAdmin()) { return false; } return add_entity_relationship($blocking_user->getGUID(), 'blocked', $blocked_user->getGUID()); }
/** * Web service for joining a group * * @param string $username username of author * @param string $groupid GUID of the group * * @return bool */ function group_join($username, $groupid) { $user = get_user_by_username($username); if (!$user) { throw new InvalidParameterException('registration:usernamenotvalid'); } $group = get_entity($groupid); $return['success'] = false; if ($user instanceof ElggUser && $group instanceof ElggGroup) { // join or request $join = false; if ($group->isPublicMembership() || $group->canEdit($user->guid)) { // anyone can join public groups and admins can join any group $join = true; } else { if (check_entity_relationship($group->guid, 'invited', $user->guid)) { // user has invite to closed group $join = true; } } if ($join) { if (groups_join_group($group, $user)) { $return['success'] = true; $return['message'] = elgg_echo("groups:joined"); } else { $return['message'] = elgg_echo("groups:cantjoin"); } } else { add_entity_relationship($user->guid, 'membership_request', $group->guid); // Notify group owner $url = "{$CONFIG->url}mod/groups/membershipreq.php?group_guid={$group->guid}"; $subject = elgg_echo('groups:request:subject', array($user->name, $group->name)); $body = elgg_echo('groups:request:body', array($group->getOwnerEntity()->name, $user->name, $group->name, $user->getURL(), $url)); if (notify_user($group->owner_guid, $user->getGUID(), $subject, $body)) { $return['success'] = true; $return['message'] = elgg_echo("groups:joinrequestmade"); } else { $return['message'] = elgg_echo("groups:joinrequestnotmade"); } } } else { $return['message'] = elgg_echo("groups:cantjoin"); } return $return; }
function group_tools_invite_user(ElggGroup $group, ElggUser $user, $text = "", $resend = false) { $result = false; if (!empty($user) && $user instanceof ElggUser && !empty($group) && $group instanceof ElggGroup && ($loggedin_user = elgg_get_logged_in_user_entity())) { // Create relationship $relationship = add_entity_relationship($group->getGUID(), "invited", $user->getGUID()); if ($relationship || $resend) { // Send email $url = elgg_get_site_url() . "groups/invitations/" . $user->username; $subject = elgg_echo("groups:invite:subject", array($user->name, $group->name)); $msg = elgg_echo("group_tools:groups:invite:body", array($user->name, $loggedin_user->name, $group->name, $text, $url)); if ($res = notify_user($user->getGUID(), $group->getOwnerGUID(), $subject, $msg)) { $result = true; } } } return $result; }
function bookmark_tools_object_handler($event, $type, $object) { if (!empty($object) && elgg_instanceof($object, "object", "bookmarks")) { $folder_guid = (int) get_input("bmfolder_guid", 0); if (!empty($folder_guid)) { if ($folder = get_entity($folder_guid)) { if (!elgg_instanceof($folder, "object", BOOKMARK_TOOLS_SUBTYPE)) { unset($folder_guid); } } else { unset($folder_guid); } } // remove old relationships remove_entity_relationships($object->getGUID(), BOOKMARK_TOOLS_RELATIONSHIP, true); if (!empty($folder_guid)) { add_entity_relationship($folder_guid, BOOKMARK_TOOLS_RELATIONSHIP, $object->getGUID()); } } }
function publication_login_check($event, $object_type, $object) { $user = get_loggedin_user(); if ($user->firstpublication && $user->exauthor_name) { $exauthor_name = $user->exauthor_name; $pub = get_entity($user->firstpublication); add_entity_relationship($user->firstpublication, 'author', $user->guid); remove_metadata($user->guid, 'firstpublication'); remove_metadata($user->guid, 'exauthor_name'); $authors = $pub->authors; $authors = explode(',', $authors); foreach ($authors as $key => $value) { if ($value == $exauthor_name) { $authors[$key] = $user->guid; } } $authors = implode(',', $authors); $pub->authors = $authors; } }
/** * Enable default notification methods when user joins a group * * @param string $event 'join' * @param string $type 'group' * @param array $params Array containing ElggUser and ElggGroup */ function notification_tools_enable_for_new_group_member($event, $type, $params) { $group = $params['group']; $user = $params['user']; $methods = elgg_get_plugin_setting('default_group_methods', 'notification_tools'); if (empty($methods)) { return true; } if (!$group instanceof ElggGroup) { return true; } if (!$user instanceof ElggUser) { return true; } $methods = explode(',', $methods); foreach ($methods as $method) { add_entity_relationship($user->guid, "notify{$method}", $group->guid); } return true; }
/** * Adds or updates poll choices * * @param array $choices */ public function setChoices(array $choices) { if (empty($choices)) { return false; } $this->deleteChoices(); $i = 0; foreach ($choices as $choice) { $poll_choice = new ElggObject(); $poll_choice->owner_guid = $this->owner_guid; $poll_choice->container_guid = $this->container_guid; $poll_choice->subtype = "poll_choice"; $poll_choice->text = $choice; $poll_choice->display_order = $i * 10; $poll_choice->access_id = $this->access_id; $poll_choice->save(); add_entity_relationship($poll_choice->guid, 'poll_choice', $this->guid); $i += 1; } }
/** * Set the folder for the file * * @param \ElggFile $entity the file to edit * * @return void */ protected static function setFolderGUID(\ElggFile $entity) { $folder_guid = get_input('folder_guid', false); if ($folder_guid === false) { // folder_input was not present in form/action // maybe someone else did something with a file return; } $folder_guid = (int) $folder_guid; if (!empty($folder_guid)) { $folder = get_entity($folder_guid); if (!elgg_instanceof($folder, 'object', FILE_TOOLS_SUBTYPE)) { unset($folder_guid); } } // remove old relationships remove_entity_relationships($entity->getGUID(), FILE_TOOLS_RELATIONSHIP, true); if (!empty($folder_guid)) { add_entity_relationship($folder_guid, FILE_TOOLS_RELATIONSHIP, $entity->getGUID()); } }
/** * Invite a user to a group * * @param ElggGroup $group the group to be invited for * @param ElggUser $user the user to be invited * @param string $text (optional) extra text in the invitation * @param bool $resend should existing invitations be resend * * @return bool */ function group_tools_invite_user(ElggGroup $group, ElggUser $user, $text = "", $resend = false) { $loggedin_user = elgg_get_logged_in_user_entity(); $resend = (bool) $resend; if (!$user instanceof ElggUser || !$group instanceof ElggGroup || empty($loggedin_user)) { return false; } // Create relationship $relationship = add_entity_relationship($group->getGUID(), 'invited', $user->getGUID()); if (empty($relationship) && empty($resend)) { return false; } // Send email $url = elgg_normalize_url("groups/invitations/{$user->username}"); $subject = elgg_echo('groups:invite:subject', [$user->name, $group->name]); $msg = elgg_echo('group_tools:groups:invite:body', [$user->name, $loggedin_user->name, $group->name, $text, $url]); $params = ['object' => $group, 'action' => 'invite']; if (notify_user($user->getGUID(), $group->getOwnerGUID(), $subject, $msg, $params, ['email', 'site'])) { return true; } return false; }
public function saveImage($name, $title, $index) { if ($_FILES[$name]['error'] != 0) { return FALSE; } $info = $_FILES[$name]; // delete original image if exists $options = array('relationship_guid' => $this->getGUID(), 'relationship' => 'image', 'metadata_name_value_pair' => array('name' => 'project_image', 'value' => "{$index}")); if ($old_image = elgg_get_entities_from_relationship($options)) { if ($old_image[0] instanceof ElggFile) { $old_image[0]->delete(); } } $image = new ElggFile(); $prefix = "plugins/"; $store_name_base = $prefix . strtolower($this->getGUID() . "_{$name}"); $image->title = $title; $image->access_id = $this->access_id; $image->setFilename($store_name_base . '.jpg'); $image->setMimetype('image/jpeg'); $image->originalfilename = $info['name']; $image->project_image = $index; // used for deletion on replacement $image->save(); $uf = get_uploaded_file($name); if (!$uf) { return FALSE; } $image->open("write"); $image->write($uf); $image->close(); add_entity_relationship($this->guid, 'image', $image->guid); // create a thumbnail if ($this->saveThumbnail($image, $store_name_base . '_thumb.jpg') != TRUE) { $image->delete(); return FALSE; } return TRUE; }
function group_tools_join_group_event($event, $type, $params) { global $NOTIFICATION_HANDLERS; static $auto_notification; // only load plugin setting once if (!isset($auto_notification)) { $auto_notification = false; if (elgg_get_plugin_setting("auto_notification", "group_tools") == "yes") { $auto_notification = true; } } if (!empty($params) && is_array($params)) { $group = elgg_extract("group", $params); $user = elgg_extract("user", $params); if ($user instanceof ElggUser && $group instanceof ElggGroup) { if ($auto_notification && !empty($NOTIFICATION_HANDLERS) && is_array($NOTIFICATION_HANDLERS)) { // only auto subscribe to site and email notifications $auto_notification_handlers = array("site", "email"); foreach ($NOTIFICATION_HANDLERS as $method => $dummy) { if (in_array($method, $auto_notification_handlers)) { add_entity_relationship($user->getGUID(), "notify" . $method, $group->getGUID()); } } } // cleanup invites remove_entity_relationship($group->getGUID(), "invited", $user->getGUID()); // and requests remove_entity_relationship($user->getGUID(), "membership_request", $group->getGUID()); // cleanup email invitations $options = array("annotation_name" => "email_invitation", "annotation_value" => group_tools_generate_email_invite_code($group->getGUID(), $user->email), "limit" => false); if (elgg_is_logged_in()) { elgg_delete_annotations($options); } elseif ($annotations = elgg_get_annotations($options)) { group_tools_delete_annotations($annotations); } } } }