Ejemplo n.º 1
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())) {
        // 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;
}
 /**
  * Ensure that \ElggBatch doesn't go into infinite loop when disabling annotations recursively when show hidden is enabled.
  *
  * https://github.com/Elgg/Elgg/issues/5952
  */
 public function test_disabling_annotations_infinite_loop()
 {
     //let's have some entity
     $group = new \ElggGroup();
     $group->name = 'test_group';
     $group->access_id = ACCESS_PUBLIC;
     $this->assertTrue($group->save() !== false);
     $total = 51;
     //add some annotations
     for ($cnt = 0; $cnt < $total; $cnt++) {
         $group->annotate('test_annotation', 'value_' . $total);
     }
     //disable them
     $show_hidden = access_get_show_hidden_status();
     access_show_hidden_entities(true);
     $options = array('guid' => $group->guid, 'limit' => $total);
     elgg_disable_annotations($options);
     access_show_hidden_entities($show_hidden);
     //confirm all being disabled
     $annotations = $group->getAnnotations(array('limit' => $total));
     foreach ($annotations as $annotation) {
         $this->assertTrue($annotation->enabled == 'no');
     }
     //delete group and annotations
     $group->delete();
 }
Ejemplo n.º 3
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 boolean   $resend should existing invitations be resend
 *
 * @return boolean|NULL true is invited, false on failure, null when already send
 */
function group_tools_invite_email(ElggGroup $group, $email, $text = "", $resend = false)
{
    $result = false;
    $loggedin_user = elgg_get_logged_in_user_entity();
    if (!empty($group) && $group instanceof ElggGroup && !empty($email) && is_email_address($email) && !empty($loggedin_user)) {
        // generate invite code
        $invite_code = group_tools_generate_email_invite_code($group->getGUID(), $email);
        if (!empty($invite_code)) {
            $found_group = group_tools_check_group_email_invitation($invite_code, $group->getGUID());
            if (empty($found_group) || $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 . "|" . $email, 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?group_invitecode=" . $invite_code, elgg_get_site_url() . "groups/invitations/?invitecode=" . $invite_code, $invite_code));
                $params = array("group" => $group, "inviter" => $loggedin_user, "invitee" => $email);
                $body = elgg_trigger_plugin_hook("invite_notification", "group_tools", $params, $body);
                $result = elgg_send_email($site_from, $email, $subject, $body);
            } else {
                $result = null;
            }
        }
    }
    return $result;
}
Ejemplo n.º 4
0
 /**
  * Make sure entity is loaded from cache during save operations
  * See #10612
  */
 public function testNewGroupLoadedFromCacheDuringSaveOperations()
 {
     $group = new \ElggGroup();
     $group->subtype = 'test_group_subtype';
     // Add temporary metadata, annotation and private settings
     // to extend the scope of tests and catch issues with save operations
     $group->test_metadata = 'bar';
     $group->annotate('test_annotation', 'baz');
     $group->setPrivateSetting('test_setting', 'foo');
     $metadata_called = false;
     $metadata_event_handler = function ($event, $type, $metadata) use(&$metadata_called) {
         /* @var $metadata \ElggMetadata */
         $entity = get_entity($metadata->entity_guid);
         $this->assertEqual($metadata->entity_guid, $entity->guid);
         $metadata_called = true;
     };
     $annotation_called = false;
     $annotation_event_handler = function ($event, $type, $annotation) use(&$annotation_called) {
         /* @var $metadata \ElggAnnotation */
         $entity = get_entity($annotation->entity_guid);
         $this->assertEqual($annotation->entity_guid, $entity->guid);
         $annotation_called = true;
     };
     elgg_register_event_handler('create', 'metadata', $metadata_event_handler);
     elgg_register_event_handler('create', 'annotation', $annotation_event_handler);
     $group->save();
     elgg_unregister_event_handler('create', 'metadata', $metadata_event_handler);
     elgg_unregister_event_handler('create', 'annotation', $annotation_event_handler);
     $group->delete();
     $this->assertTrue($metadata_called);
     $this->assertTrue($annotation_called);
 }
Ejemplo n.º 5
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);
}