示例#1
0
文件: functions.php 项目: remy40/gvrs
function group_tools_invite_email(ElggGroup $group, $email, $text = "", $resend = false)
{
    $result = false;
    if (!empty($group) && $group instanceof ElggGroup && !empty($email) && is_email_address($email) && ($loggedin_user = elgg_get_logged_in_user_entity())) {
        // get site secret
        $site_secret = get_site_secret();
        // generate invite code
        $invite_code = md5($site_secret . $email . $group->getGUID());
        if (!group_tools_check_group_email_invitation($invite_code, $group->getGUID()) || $resend) {
            // make site email
            $site = elgg_get_site_entity();
            if (!empty($site->email)) {
                if (!empty($site->name)) {
                    $site_from = $site->name . " <" . $site->email . ">";
                } else {
                    $site_from = $site->email;
                }
            } else {
                // no site email, so make one up
                if (!empty($site->name)) {
                    $site_from = $site->name . " <noreply@" . get_site_domain($site->getGUID()) . ">";
                } else {
                    $site_from = "noreply@" . get_site_domain($site->getGUID());
                }
            }
            if (!$resend) {
                // register invite with group
                $group->annotate("email_invitation", $invite_code, ACCESS_LOGGED_IN, $group->getGUID());
            }
            // make subject
            $subject = elgg_echo("group_tools:groups:invite:email:subject", array($group->name));
            // make body
            $body = elgg_echo("group_tools:groups:invite:email:body", array($loggedin_user->name, $group->name, $site->name, $text, $site->name, elgg_get_site_url() . "register", elgg_get_site_url() . "groups/invitations/?invitecode=" . $invite_code, $invite_code));
            $result = elgg_send_email($site_from, $email, $subject, $body);
        } else {
            $result = null;
        }
    }
    return $result;
}
示例#2
0
<?php

/**
 * Accept an email invitation
 */
$invitecode = get_input("invitecode");
$user = elgg_get_logged_in_user_entity();
$forward_url = REFERER;
if (!empty($invitecode)) {
    $forward_url = elgg_get_site_url() . "groups/invitations/" . $user->username;
    $group = group_tools_check_group_email_invitation($invitecode);
    if (!empty($group)) {
        if (groups_join_group($group, $user)) {
            $invitecode = sanitise_string($invitecode);
            $options = array("guid" => $group->getGUID(), "annotation_name" => "email_invitation", "wheres" => array("(v.string = '" . $invitecode . "' OR v.string LIKE '" . $invitecode . "|%')"), "annotation_owner_guid" => $group->getGUID(), "limit" => 1);
            $annotations = elgg_get_annotations($options);
            if (!empty($annotations)) {
                // ignore access in order to cleanup the invitation
                $ia = elgg_set_ignore_access(true);
                $annotations[0]->delete();
                // restore access
                elgg_set_ignore_access($ia);
            }
            $forward_url = $group->getURL();
            system_message(elgg_echo("group_tools:action:groups:email_invitation:success"));
        } else {
            register_error(elgg_echo("group_tools:action:groups:email_invitation:error:join", array($group->name)));
        }
    } else {
        register_error(elgg_echo("group_tools:action:groups:email_invitation:error:code"));
    }
示例#3
0
/**
 * Enable registration on the site if disabled and a valid group invite code in provided
 *
 * @return void
 */
function group_tools_enable_registration()
{
    $registration_allowed = (bool) elgg_get_config("allow_registration");
    if (!$registration_allowed) {
        // check for a group invite code
        $group_invitecode = get_input("group_invitecode");
        if (!empty($group_invitecode)) {
            // check if the code is valid
            if (group_tools_check_group_email_invitation($group_invitecode)) {
                // we have a valid code, so allow registration
                elgg_set_config("allow_registration", true);
            }
        }
    }
}
示例#4
0
 /**
  * Listen to the create member_of_site relationship event to handle new users
  *
  * @param string            $event        the name of the event
  * @param string            $type         the type of the event
  * @param \ElggRelationship $relationship supplied param
  *
  * @return void
  */
 public static function siteJoinGroupInviteCode($event, $type, $relationship)
 {
     if (!self::validateSiteJoinRelationship($relationship)) {
         return;
     }
     $user_guid = (int) $relationship->guid_one;
     $user = get_user($user_guid);
     // check for manual email invited groups
     $group_invitecode = get_input('group_invitecode');
     if (empty($group_invitecode)) {
         return;
     }
     // ignore access
     $ia = elgg_set_ignore_access(true);
     $group = group_tools_check_group_email_invitation($group_invitecode);
     if (empty($group)) {
         // restore access settings
         elgg_set_ignore_access($ia);
         return;
     }
     // join the group
     $group->join($user);
     // cleanup the invite code
     $group_invitecode = sanitise_string($group_invitecode);
     elgg_delete_annotations(['guid' => $group->getGUID(), 'annotation_name' => 'email_invitation', 'wheres' => ["(v.string = '{$group_invitecode}' OR v.string LIKE '{$group_invitecode}|%')"], 'annotation_owner_guid' => $group->getGUID(), 'limit' => 1]);
     // restore access settings
     elgg_set_ignore_access($ia);
 }
示例#5
0
/**
 * Event when the user joins a site, mostly when registering
 *
 * @param string           $event        create
 * @param string           $type         member_of_site
 * @param ElggRelationship $relationship the membership relation
 *
 * @return void
 */
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;
        $user = get_user($user_guid);
        if (!empty($user)) {
            // ignore access
            $ia = elgg_set_ignore_access(true);
            // add user to the auto join groups
            $auto_joins = elgg_get_plugin_setting("auto_join", "group_tools");
            if (!empty($auto_joins)) {
                $auto_joins = string_to_tag_array($auto_joins);
                foreach ($auto_joins as $group_guid) {
                    $group = get_entity($group_guid);
                    if (!empty($group) && $group instanceof ElggGroup) {
                        if ($group->site_guid == $site_guid) {
                            // join the group
                            $group->join($user);
                        }
                    }
                }
            }
            // auto detect email invited groups
            $groups = group_tools_get_invited_groups_by_email($user->email, $site_guid);
            if (!empty($groups)) {
                foreach ($groups as $group) {
                    // join the group
                    $group->join($user);
                }
            }
            // check for manual email invited groups
            $group_invitecode = get_input("group_invitecode");
            if (!empty($group_invitecode)) {
                $group = group_tools_check_group_email_invitation($group_invitecode);
                if (!empty($group)) {
                    // join the group
                    $group->join($user);
                    // cleanup the invite code
                    $group_invitecode = sanitise_string($group_invitecode);
                    $options = array("guid" => $group->getGUID(), "annotation_name" => "email_invitation", "wheres" => array("(v.string = '" . $group_invitecode . "' OR v.string LIKE '" . $group_invitecode . "|%')"), "annotation_owner_guid" => $group->getGUID(), "limit" => 1);
                    // ignore access in order to cleanup the invitation
                    $ia = elgg_set_ignore_access(true);
                    elgg_delete_annotations($options);
                    // restore access
                    elgg_set_ignore_access($ia);
                }
            }
            // find domain based groups
            $groups = group_tools_get_domain_based_groups($user, $site_guid);
            if (!empty($groups)) {
                foreach ($groups as $group) {
                    // join the group
                    $group->join($user);
                }
            }
            // restore access settings
            elgg_set_ignore_access($ia);
        }
    }
}