From 419c8e0115484c30db5f236a5f420a0e1b4dece4 Mon Sep 17 00:00:00 2001 From: Matt Beckett Date: Wed, 23 Oct 2013 12:16:19 -0700 Subject: [PATCH 1/4] Notify group admins when a user requests membership to a closed group --- lib/events.php | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- start.php | 3 +++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/lib/events.php b/lib/events.php index 787e7a75..78fa072b 100644 --- a/lib/events.php +++ b/lib/events.php @@ -108,4 +108,52 @@ function group_tools_multiple_admin_group_leave($event, $type, $params){ } } } - \ No newline at end of file + + + function group_tools_membership_request($event, $type, $relationship) { + if (!($relationship instanceof ElggRelationship)) { + return; + } + + $group = get_entity($relationship->guid_two); + $user = get_user($relationship->guid_one); + + if (!elgg_instanceof($group, 'group') || !elgg_instanceof($user, 'user')) { + return; + } + + // Notify group owner + $url = elgg_get_site_url() . "groups/requests/$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, + )); + + $options = array( + "relationship" => "group_admin", + "relationship_guid" => $group->getGUID(), + "inverse_relationship" => true, + "type" => "user", + "limit" => false, + "wheres" => array("e.guid <> " . $group->owner_guid), + "callback" => false + ); + + $admins = elgg_get_entities_from_relationship($options); + + $guids = array(); + foreach ($admins as $a) { + $guids[] = $a->guid; + } + + if ($guids) { + notify_user($guids, $user->getGUID(), $subject, $body); + } + } \ No newline at end of file diff --git a/start.php b/start.php index 8a210f6f..91603278 100644 --- a/start.php +++ b/start.php @@ -34,6 +34,9 @@ function group_tools_init(){ // register on group leave elgg_register_event_handler("leave", "group", "group_tools_multiple_admin_group_leave"); + + //notify admin on membership request + elgg_register_event_handler('create', 'membership_request', 'group_tools_membership_request'); } // register group activity widget From f69787a2ab53ff9da5c8da7ee53be1fc9fc7777d Mon Sep 17 00:00:00 2001 From: Matt Beckett Date: Wed, 23 Oct 2013 12:18:45 -0700 Subject: [PATCH 2/4] Notify group admins when a user requests membership to a closed group --- lib/events.php | 305 ++++++++++++++++++++++++------------------------- 1 file changed, 152 insertions(+), 153 deletions(-) diff --git a/lib/events.php b/lib/events.php index 78fa072b..c12543db 100644 --- a/lib/events.php +++ b/lib/events.php @@ -1,159 +1,158 @@ $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); - } - } - } - } - - function group_tools_join_site_handler($event, $type, $relationship){ - - if(!empty($relationship) && ($relationship instanceof ElggRelationship)){ - $user_guid = $relationship->guid_one; - $site_guid = $relationship->guid_two; - - if($user = get_user($user_guid)){ - // ignore access - $ia = elgg_set_ignore_access(true); - - // add user to the auto join groups - if($auto_joins = elgg_get_plugin_setting("auto_join", "group_tools")){ - $auto_joins = string_to_tag_array($auto_joins); - - foreach ($auto_joins as $group_guid) { - if(($group = get_entity($group_guid)) && ($group instanceof ElggGroup)){ - if($group->site_guid == $site_guid){ - // join the group - $group->join($user); - } - } - } - } - - // auto detect email invited groups - if($groups = group_tools_get_invited_groups_by_email($user->email, $site_guid)){ - foreach($groups as $group){ - // join the group - $group->join($user); - } - } - - // restore access settings - elgg_set_ignore_access($ia); - } - } - } - - function group_tools_multiple_admin_group_leave($event, $type, $params){ - - if(!empty($params) && is_array($params)){ - if(array_key_exists("group", $params) && array_key_exists("user", $params)){ - $entity = $params["group"]; - $user = $params["user"]; - - if(($entity instanceof ElggGroup) && ($user instanceof ElggUser)){ - if(check_entity_relationship($user->getGUID(), "group_admin", $entity->getGUID())){ - return remove_entity_relationship($user->getGUID(), "group_admin", $entity->getGUID()); - } - } - } - } - } - - - function group_tools_membership_request($event, $type, $relationship) { - if (!($relationship instanceof ElggRelationship)) { - return; +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; } - - $group = get_entity($relationship->guid_two); - $user = get_user($relationship->guid_one); - - if (!elgg_instanceof($group, 'group') || !elgg_instanceof($user, 'user')) { - return; + } + + 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); + } } - - // Notify group owner - $url = elgg_get_site_url() . "groups/requests/$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, - )); - - $options = array( - "relationship" => "group_admin", - "relationship_guid" => $group->getGUID(), - "inverse_relationship" => true, - "type" => "user", - "limit" => false, - "wheres" => array("e.guid <> " . $group->owner_guid), - "callback" => false - ); - - $admins = elgg_get_entities_from_relationship($options); - - $guids = array(); - foreach ($admins as $a) { - $guids[] = $a->guid; + } +} + +function group_tools_join_site_handler($event, $type, $relationship) { + + if (!empty($relationship) && ($relationship instanceof ElggRelationship)) { + $user_guid = $relationship->guid_one; + $site_guid = $relationship->guid_two; + + if ($user = get_user($user_guid)) { + // ignore access + $ia = elgg_set_ignore_access(true); + + // add user to the auto join groups + if ($auto_joins = elgg_get_plugin_setting("auto_join", "group_tools")) { + $auto_joins = string_to_tag_array($auto_joins); + + foreach ($auto_joins as $group_guid) { + if (($group = get_entity($group_guid)) && ($group instanceof ElggGroup)) { + if ($group->site_guid == $site_guid) { + // join the group + $group->join($user); + } + } + } + } + + // auto detect email invited groups + if ($groups = group_tools_get_invited_groups_by_email($user->email, $site_guid)) { + foreach ($groups as $group) { + // join the group + $group->join($user); + } + } + + // restore access settings + elgg_set_ignore_access($ia); } - - if ($guids) { - notify_user($guids, $user->getGUID(), $subject, $body); + } +} + +function group_tools_multiple_admin_group_leave($event, $type, $params) { + + if (!empty($params) && is_array($params)) { + if (array_key_exists("group", $params) && array_key_exists("user", $params)) { + $entity = $params["group"]; + $user = $params["user"]; + + if (($entity instanceof ElggGroup) && ($user instanceof ElggUser)) { + if (check_entity_relationship($user->getGUID(), "group_admin", $entity->getGUID())) { + return remove_entity_relationship($user->getGUID(), "group_admin", $entity->getGUID()); + } + } } - } \ No newline at end of file + } +} + +function group_tools_membership_request($event, $type, $relationship) { + if (!($relationship instanceof ElggRelationship)) { + return; + } + + $group = get_entity($relationship->guid_two); + $user = get_user($relationship->guid_one); + + if (!elgg_instanceof($group, 'group') || !elgg_instanceof($user, 'user')) { + return; + } + + // Notify group owner + $url = elgg_get_site_url() . "groups/requests/$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, + )); + + $options = array( + "relationship" => "group_admin", + "relationship_guid" => $group->getGUID(), + "inverse_relationship" => true, + "type" => "user", + "limit" => false, + "wheres" => array("e.guid <> " . $group->owner_guid), + "callback" => false + ); + + $admins = elgg_get_entities_from_relationship($options); + + $guids = array(); + foreach ($admins as $a) { + $guids[] = $a->guid; + } + + if ($guids) { + notify_user($guids, $user->getGUID(), $subject, $body); + } +} From f1fb4260b1343b960f9f7fc3090baf62f00ddc0e Mon Sep 17 00:00:00 2001 From: Matt Beckett Date: Wed, 23 Oct 2013 12:19:44 -0700 Subject: [PATCH 3/4] Revert "Notify group admins when a user requests membership to a closed group" This reverts commit f69787a2ab53ff9da5c8da7ee53be1fc9fc7777d. --- lib/events.php | 305 +++++++++++++++++++++++++------------------------ 1 file changed, 153 insertions(+), 152 deletions(-) diff --git a/lib/events.php b/lib/events.php index c12543db..78fa072b 100644 --- a/lib/events.php +++ b/lib/events.php @@ -1,158 +1,159 @@ $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); + } + } + } + } + + function group_tools_join_site_handler($event, $type, $relationship){ + + if(!empty($relationship) && ($relationship instanceof ElggRelationship)){ + $user_guid = $relationship->guid_one; + $site_guid = $relationship->guid_two; + + if($user = get_user($user_guid)){ + // ignore access + $ia = elgg_set_ignore_access(true); + + // add user to the auto join groups + if($auto_joins = elgg_get_plugin_setting("auto_join", "group_tools")){ + $auto_joins = string_to_tag_array($auto_joins); + + foreach ($auto_joins as $group_guid) { + if(($group = get_entity($group_guid)) && ($group instanceof ElggGroup)){ + if($group->site_guid == $site_guid){ + // join the group + $group->join($user); + } + } + } + } + + // auto detect email invited groups + if($groups = group_tools_get_invited_groups_by_email($user->email, $site_guid)){ + foreach($groups as $group){ + // join the group + $group->join($user); + } + } + + // restore access settings + elgg_set_ignore_access($ia); + } + } + } + + function group_tools_multiple_admin_group_leave($event, $type, $params){ + + if(!empty($params) && is_array($params)){ + if(array_key_exists("group", $params) && array_key_exists("user", $params)){ + $entity = $params["group"]; + $user = $params["user"]; + + if(($entity instanceof ElggGroup) && ($user instanceof ElggUser)){ + if(check_entity_relationship($user->getGUID(), "group_admin", $entity->getGUID())){ + return remove_entity_relationship($user->getGUID(), "group_admin", $entity->getGUID()); + } + } + } + } + } + + + function group_tools_membership_request($event, $type, $relationship) { + if (!($relationship instanceof ElggRelationship)) { + return; } - } - - 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); - } + + $group = get_entity($relationship->guid_two); + $user = get_user($relationship->guid_one); + + if (!elgg_instanceof($group, 'group') || !elgg_instanceof($user, 'user')) { + return; } - } -} - -function group_tools_join_site_handler($event, $type, $relationship) { - - if (!empty($relationship) && ($relationship instanceof ElggRelationship)) { - $user_guid = $relationship->guid_one; - $site_guid = $relationship->guid_two; - - if ($user = get_user($user_guid)) { - // ignore access - $ia = elgg_set_ignore_access(true); - - // add user to the auto join groups - if ($auto_joins = elgg_get_plugin_setting("auto_join", "group_tools")) { - $auto_joins = string_to_tag_array($auto_joins); - - foreach ($auto_joins as $group_guid) { - if (($group = get_entity($group_guid)) && ($group instanceof ElggGroup)) { - if ($group->site_guid == $site_guid) { - // join the group - $group->join($user); - } - } - } - } - - // auto detect email invited groups - if ($groups = group_tools_get_invited_groups_by_email($user->email, $site_guid)) { - foreach ($groups as $group) { - // join the group - $group->join($user); - } - } - - // restore access settings - elgg_set_ignore_access($ia); + + // Notify group owner + $url = elgg_get_site_url() . "groups/requests/$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, + )); + + $options = array( + "relationship" => "group_admin", + "relationship_guid" => $group->getGUID(), + "inverse_relationship" => true, + "type" => "user", + "limit" => false, + "wheres" => array("e.guid <> " . $group->owner_guid), + "callback" => false + ); + + $admins = elgg_get_entities_from_relationship($options); + + $guids = array(); + foreach ($admins as $a) { + $guids[] = $a->guid; } - } -} - -function group_tools_multiple_admin_group_leave($event, $type, $params) { - - if (!empty($params) && is_array($params)) { - if (array_key_exists("group", $params) && array_key_exists("user", $params)) { - $entity = $params["group"]; - $user = $params["user"]; - - if (($entity instanceof ElggGroup) && ($user instanceof ElggUser)) { - if (check_entity_relationship($user->getGUID(), "group_admin", $entity->getGUID())) { - return remove_entity_relationship($user->getGUID(), "group_admin", $entity->getGUID()); - } - } + + if ($guids) { + notify_user($guids, $user->getGUID(), $subject, $body); } - } -} - -function group_tools_membership_request($event, $type, $relationship) { - if (!($relationship instanceof ElggRelationship)) { - return; - } - - $group = get_entity($relationship->guid_two); - $user = get_user($relationship->guid_one); - - if (!elgg_instanceof($group, 'group') || !elgg_instanceof($user, 'user')) { - return; - } - - // Notify group owner - $url = elgg_get_site_url() . "groups/requests/$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, - )); - - $options = array( - "relationship" => "group_admin", - "relationship_guid" => $group->getGUID(), - "inverse_relationship" => true, - "type" => "user", - "limit" => false, - "wheres" => array("e.guid <> " . $group->owner_guid), - "callback" => false - ); - - $admins = elgg_get_entities_from_relationship($options); - - $guids = array(); - foreach ($admins as $a) { - $guids[] = $a->guid; - } - - if ($guids) { - notify_user($guids, $user->getGUID(), $subject, $body); - } -} + } \ No newline at end of file From 84cbd976f3e38cb9e8e7fce1d8f040ff767de1cb Mon Sep 17 00:00:00 2001 From: Matt Beckett Date: Wed, 23 Oct 2013 12:38:02 -0700 Subject: [PATCH 4/4] whitespace fix --- lib/events.php | 78 +++++++++++++++++++++++++------------------------- start.php | 4 +-- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/lib/events.php b/lib/events.php index 78fa072b..c9ec5106 100644 --- a/lib/events.php +++ b/lib/events.php @@ -111,49 +111,49 @@ function group_tools_multiple_admin_group_leave($event, $type, $params){ function group_tools_membership_request($event, $type, $relationship) { - if (!($relationship instanceof ElggRelationship)) { - return; - } - - $group = get_entity($relationship->guid_two); - $user = get_user($relationship->guid_one); - - if (!elgg_instanceof($group, 'group') || !elgg_instanceof($user, 'user')) { - return; - } - - // Notify group owner - $url = elgg_get_site_url() . "groups/requests/$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, - )); - - $options = array( + if (!($relationship instanceof ElggRelationship)) { + return; + } + + $group = get_entity($relationship->guid_two); + $user = get_user($relationship->guid_one); + + if (!elgg_instanceof($group, 'group') || !elgg_instanceof($user, 'user')) { + return; + } + + // Notify group owner + $url = elgg_get_site_url() . "groups/requests/$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, + )); + + $options = array( "relationship" => "group_admin", "relationship_guid" => $group->getGUID(), "inverse_relationship" => true, "type" => "user", "limit" => false, "wheres" => array("e.guid <> " . $group->owner_guid), - "callback" => false + "callback" => false ); - - $admins = elgg_get_entities_from_relationship($options); - - $guids = array(); - foreach ($admins as $a) { - $guids[] = $a->guid; - } - - if ($guids) { - notify_user($guids, $user->getGUID(), $subject, $body); - } - } \ No newline at end of file + + $admins = elgg_get_entities_from_relationship($options); + + $guids = array(); + foreach ($admins as $a) { + $guids[] = $a->guid; + } + + if ($guids) { + notify_user($guids, $user->getGUID(), $subject, $body); + } + } diff --git a/start.php b/start.php index 91603278..a7abb717 100644 --- a/start.php +++ b/start.php @@ -35,8 +35,8 @@ function group_tools_init(){ // register on group leave elgg_register_event_handler("leave", "group", "group_tools_multiple_admin_group_leave"); - //notify admin on membership request - elgg_register_event_handler('create', 'membership_request', 'group_tools_membership_request'); + //notify admin on membership request + elgg_register_event_handler('create', 'membership_request', 'group_tools_membership_request'); } // register group activity widget