Example #1
0
/**
 * 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);
            }
        }
    }
}
Example #2
0
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);
            }
        }
    }
}
Example #3
0
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())) {
        // generate invite code
        $invite_code = group_tools_generate_email_invite_code($group->getGUID(), $email);
        if (!($found_group = 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 (empty($found_group)) {
                // 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;
}
Example #4
0
 /**
  * add menu items to the emailinvitation listing
  *
  * @param string          $hook         the name of the hook
  * @param string          $type         the type of the hook
  * @param \ElggMenuItem[] $return_value current return vaue
  * @param array           $params       supplied params
  *
  * @return void|\ElggMenuItem[]
  */
 public static function emailinvitationMenu($hook, $type, $return_value, $params)
 {
     $user = elgg_extract('user', $params);
     $group = elgg_extract('entity', $params);
     if (!$user instanceof \ElggUser || !$user->canEdit()) {
         return;
     }
     if (!$group instanceof \ElggGroup) {
         return;
     }
     $invitecode = group_tools_generate_email_invite_code($group->getGUID(), $user->email);
     $return_value[] = \ElggMenuItem::factory(['name' => 'accept', 'text' => elgg_echo('accept'), 'href' => "action/groups/email_invitation?invitecode={$invitecode}", 'link_class' => 'elgg-button elgg-button-submit', 'is_action' => true]);
     $return_value[] = \ElggMenuItem::factory(['name' => 'decline', 'text' => elgg_echo('delete'), 'href' => "action/groups/decline_email_invitation?invitecode={$invitecode}", 'confirm' => elgg_echo('groups:invite:remove:check'), 'is_action' => true, 'link_class' => 'elgg-button elgg-button-delete mlm']);
     return $return_value;
 }
Example #5
0
                $alt = $accept_button . $delete_button;
                $body .= "<div class='col-xs-3'>" . $alt . "</div>";
                echo "<li class='pvs'>";
                echo elgg_view_image_block($icon, $body, array());
                echo "</li>";
            }
        }
    }
    // auto detected email invitations
    if (!empty($email_invites)) {
        foreach ($email_invites as $group) {
            $icon = elgg_view_entity_icon($group, "medium", array("use_hover" => "true", 'class' => 'img-responsive'));
            $group_title = elgg_view("output/url", array("href" => $group->getURL(), "text" => $group->name, "is_trusted" => true));
            $url = "action/groups/email_invitation?invitecode=" . group_tools_generate_email_invite_code($group->getGUID(), $user->email);
            $accept_button = elgg_view("output/url", array("href" => $url, "text" => elgg_echo("accept"), "class" => "elgg-button elgg-button-submit", "is_trusted" => true, "is_action" => true));
            $url = "action/groups/decline_email_invitation?invitecode=" . group_tools_generate_email_invite_code($group->getGUID(), $user->email);
            $delete_button = elgg_view("output/url", array("href" => $url, "confirm" => elgg_echo("groups:invite:remove:check"), "text" => elgg_echo("delete"), "class" => "elgg-button elgg-button-delete mlm"));
            $body = "<div class='col-xs-9'><h4>{$group_title}</h4>";
            $body .= "<p class='elgg-subtext'>{$group->briefdescription}</p></div>";
            $alt = $accept_button . $delete_button;
            $body .= "<div class='col-xs-3'>" . $alt . "</div>";
            echo "<li class='pvs'>";
            echo elgg_view_image_block($icon, $body, array());
            echo "</li>";
        }
    }
    echo "</ul>";
} else {
    echo "<p class='mtm'>" . elgg_echo("groups:invitations:none") . "</p>";
}
// list membership requests
Example #6
0
/**
 * Invite a new user by email to a group
 *
 * @param ElggGroup $group  the group to be invited for
 * @param string    $email  the email address to be invited
 * @param string    $text   (optional) extra text in the invitation
 * @param bool      $resend should existing invitations be resend
 *
 * @return bool|NULL true is invited, false on failure, null when already send
 */
function group_tools_invite_email(ElggGroup $group, $email, $text = "", $resend = false)
{
    $loggedin_user = elgg_get_logged_in_user_entity();
    $resend = (bool) $resend;
    if (!$group instanceof ElggGroup || empty($email) || !is_email_address($email) || empty($loggedin_user)) {
        return false;
    }
    // generate invite code
    $invite_code = group_tools_generate_email_invite_code($group->getGUID(), $email);
    if (empty($invite_code)) {
        return false;
    }
    $found_group = group_tools_check_group_email_invitation($invite_code, $group->getGUID());
    if (!empty($found_group) && empty($resend)) {
        return null;
    }
    // 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@{$site->getDomain()}>";
        } else {
            $site_from = "noreply@{$site->getDomain()}";
        }
    }
    if (empty($found_group)) {
        // register invite with group
        $group->annotate('email_invitation', "{$invite_code}|{$email}", ACCESS_LOGGED_IN, $group->getGUID());
    }
    // make subject
    $subject = elgg_echo('group_tools:groups:invite:email:subject', [$group->name]);
    // make body
    $body = elgg_echo('group_tools:groups:invite:email:body', [$loggedin_user->name, $group->name, $site->name, $text, $site->name, elgg_normalize_url("register?group_invitecode={$invite_code}"), elgg_normalize_url("groups/invitations/?invitecode={$invite_code}"), $invite_code]);
    $params = ['group' => $group, 'inviter' => $loggedin_user, 'invitee' => $email];
    $body = elgg_trigger_plugin_hook('invite_notification', 'group_tools', $params, $body);
    return elgg_send_email($site_from, $email, $subject, $body);
}