Exemplo n.º 1
0
/**
 * Get the latest activity of this group based on the river
 *
 * @param ElggGroup $entity the group to check
 *
 * @return int the UNIX timestamp of the latest activity
 */
function csv_exporter_get_last_group_activity(ElggGroup $entity)
{
    $result = 0;
    if (!$entity instanceof ElggGroup) {
        return $result;
    }
    $dbprefix = elgg_get_config('dbprefix');
    $query = 'SELECT max(r.posted) as posted';
    $query .= " FROM {$dbprefix}river r";
    $query .= " INNER JOIN {$dbprefix}entities e ON r.object_guid = e.guid";
    $query .= " WHERE (e.container_guid = {$entity->getGUID()})";
    $query .= " OR (r.object_guid = {$entity->getGUID()})";
    $data = get_data($query);
    if (!empty($data)) {
        $result = (int) $data[0]->posted;
    }
    return $result;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
/**
 * Registers the buttons for title area of the group profile page
 *
 * @param ElggGroup $group
 */
function groups_register_profile_buttons($group)
{
    $actions = array();
    // group owners
    if ($group->canEdit()) {
        // edit and invite
        $url = elgg_get_site_url() . "groups/edit/{$group->getGUID()}";
        $actions[$url] = 'groups:edit';
        $url = elgg_get_site_url() . "groups/invite/{$group->getGUID()}";
        $actions[$url] = 'groups:invite';
    }
    // group members
    if ($group->isMember(elgg_get_logged_in_user_entity())) {
        if ($group->getOwnerGUID() != elgg_get_logged_in_user_guid()) {
            // leave
            $url = elgg_get_site_url() . "action/groups/leave?group_guid={$group->getGUID()}";
            $url = elgg_add_action_tokens_to_url($url);
            $actions[$url] = 'groups:leave';
        }
    } elseif (elgg_is_logged_in()) {
        // join - admins can always join.
        $url = elgg_get_site_url() . "action/groups/join?group_guid={$group->getGUID()}";
        $url = elgg_add_action_tokens_to_url($url);
        if ($group->isPublicMembership() || $group->canEdit()) {
            $actions[$url] = 'groups:join';
        } else {
            // request membership
            $actions[$url] = 'groups:joinrequest';
        }
    }
    if ($actions) {
        foreach ($actions as $url => $text) {
            elgg_register_menu_item('title', array('name' => $text, 'href' => $url, 'text' => elgg_echo($text), 'link_class' => 'elgg-button elgg-button-action'));
        }
    }
}
Exemplo n.º 4
0
/**
 * Get the time_created from the group membership relation
 *
 * @param ElggUser  $user  the user to check
 * @param ElggGroup $group the group to check
 *
 * @return int
 */
function group_tools_get_membership_information(ElggUser $user, ElggGroup $group)
{
    $result = 0;
    if (!empty($user) && !empty($group)) {
        $query = "SELECT *";
        $query .= " FROM " . elgg_get_config("dbprefix") . "entity_relationships";
        $query .= " WHERE guid_one = " . $user->getGUID();
        $query .= " AND guid_two = " . $group->getGUID();
        $query .= " AND relationship = 'member'";
        $row = get_data_row($query);
        if (!empty($row)) {
            $result = $row->time_created;
        }
    }
    return $result;
}
Exemplo n.º 5
0
/**
 * Join a user to a group, add river event, clean-up invitations
 *
 * @param ElggGroup $group
 * @param ElggUser  $user
 * @return bool
 */
function groups_join_group($group, $user)
{
    global $NOTIFICATION_HANDLERS;
    // access ignore so user can be added to access collection of invisible group
    $ia = elgg_set_ignore_access(TRUE);
    $result = $group->join($user);
    elgg_set_ignore_access($ia);
    if ($result) {
        // flush user's access info so the collection is added
        get_access_list($user->guid, 0, true);
        // Remove any invite or join request flags
        remove_entity_relationship($group->guid, 'invited', $user->guid);
        remove_entity_relationship($user->guid, 'membership_request', $group->guid);
        //check if notifications are turned off for the group
        if ($group->notifications == "false") {
            //turn users notifications off
            foreach ($NOTIFICATION_HANDLERS as $method => $dummy) {
                error_log("group" . $method);
                remove_entity_relationship($user->getGUID(), "notify" . $method, $group->getGUID());
            }
        }
        add_to_river('river/relationship/member/create', 'join', $user->guid, $group->guid);
        return true;
    }
    return false;
}
Exemplo n.º 6
0
 /**
  * Check if the user is receiving notifications from the group
  *
  * @param \ElggUser  $user  the user to check
  * @param \ElggGroup $group the group to check for
  *
  * @return bool
  */
 public static function notificationsEnabledForGroup(\ElggUser $user, \ElggGroup $group)
 {
     if (!$user instanceof \ElggUser || !$group instanceof \ElggGroup) {
         return false;
     }
     $subscriptions = elgg_get_subscriptions_for_container($group->getGUID());
     if (!is_array($subscriptions)) {
         return false;
     }
     if (!empty($subscriptions[$user->getGUID()])) {
         return true;
     }
     return false;
 }
Exemplo n.º 7
0
 public function testJoinLeaveGroupACL()
 {
     if (!elgg_is_active_plugin('groups')) {
         return;
     }
     $group = new ElggGroup();
     $group->name = 'Test group';
     $group->save();
     $result = $group->join($this->user);
     $this->assertTrue($result);
     // disable security since we run as admin
     $ia = elgg_set_ignore_access(false);
     // need to set the page owner to emulate being in a group context.
     // this is kinda hacky.
     elgg_set_page_owner_guid($group->getGUID());
     if ($result) {
         $can_edit = can_edit_access_collection($group->group_acl, $this->user->guid);
         $this->assertTrue($can_edit);
     }
     $result = $group->leave($this->user);
     $this->assertTrue($result);
     if ($result) {
         $can_edit = can_edit_access_collection($group->group_acl, $this->user->guid);
         $this->assertFalse($can_edit);
     }
     elgg_set_ignore_access($ia);
     $group->delete();
 }
Exemplo n.º 8
0
/**
 * Add a user to a group
 *
 * @param ElggGroup $group the group to add the user to
 * @param ElggUser  $user  the user to be added
 * @param string    $text  (optional) extra text for the notification
 *
 * @return boolean 	true if successfull
 */
function zhgroups_add_user(ElggGroup $group, ElggUser $user, $text = "")
{
    $result = false;
    $loggedin_user = elgg_get_logged_in_user_entity();
    if (!empty($user) && $user instanceof ElggUser && !empty($group) && $group instanceof ElggGroup && !empty($loggedin_user)) {
        // make sure all goes well
        $ia = elgg_set_ignore_access(true);
        if ($group->join($user)) {
            // Remove any invite or join request flags
            remove_entity_relationship($group->getGUID(), "invited", $user->getGUID());
            remove_entity_relationship($user->getGUID(), "membership_request", $group->getGUID());
            // notify user
            $subject = elgg_echo("zhgroups:groups:invite:add:subject", array($group->name));
            $msg = elgg_echo("zhgroups:groups:invite:add:body", array($user->name, $loggedin_user->name, $group->name, $text, $group->getURL()));
            $params = array("group" => $group, "inviter" => $loggedin_user, "invitee" => $user);
            //to do?
            $msg = elgg_trigger_plugin_hook("invite_notification", "zhgroups", $params, $msg);
            if (notify_user($user->getGUID(), $group->getOwnerGUID(), $subject, $msg, null, "email")) {
                $result = true;
            }
        }
        // restore access
        elgg_set_ignore_access($ia);
    }
    return $result;
}
Exemplo n.º 9
0
/**
 * Get the activity count since last action of the previous login of the user
 *
 * @param ElggGroup $group the group to check for
 *
 * @return false|int
 */
function theme_eersel_get_group_activity_count(ElggGroup $group)
{
    if (!$group instanceof ElggGroup) {
        return false;
    }
    if (!elgg_is_logged_in() || empty($_SESSION['theme_eersel_activity_last_action'])) {
        return false;
    }
    if (!is_array($_SESSION['theme_eersel_group_activity_counter'])) {
        $_SESSION['theme_eersel_group_activity_counter'] = [];
    }
    if (isset($_SESSION['theme_eersel_group_activity_counter'][$group->getGUID()])) {
        return $_SESSION['theme_eersel_group_activity_counter'][$group->getGUID()];
    }
    // get river activity since last action of user
    $dbprefix = elgg_get_config('dbprefix');
    $options = ['count' => true, 'joins' => ["JOIN {$dbprefix}entities oe ON rv.object_guid = oe.guid"], 'wheres' => ["(rv.object_guid = {$group->getGUID()} || oe.container_guid = {$group->getGUID()})"], 'posted_time_lower' => (int) $_SESSION['theme_eersel_activity_last_action']];
    $_SESSION['theme_eersel_group_activity_counter'][$group->getGUID()] = elgg_get_river($options);
    return $_SESSION['theme_eersel_group_activity_counter'][$group->getGUID()];
}
Exemplo n.º 10
0
/**
 * Registers the buttons for title area of the group profile page
 *
 * @param ElggGroup $group
 */
function groups_register_profile_buttons($group)
{
    $user = elgg_get_logged_in_user_entity();
    $actions = array();
    // group owners
    if ($group->canEdit()) {
        // local groups except town groups cannot be edited (except by admins)
        if ($group->grouptype != 'local' || $group->grouptype == 'local' && $group->localtype == 'town' || $user->isAdmin()) {
            $url = elgg_get_site_url() . "groups/edit/{$group->getGUID()}";
            $actions[$url] = 'groups:edit';
        }
        // local groups except town groups cannot use invitation system
        if ($group->grouptype != 'local' || $group->grouptype == 'local' && $group->localtype == 'town') {
            $url = elgg_get_site_url() . "groups/invite/{$group->getGUID()}";
            $actions[$url] = 'groups:invite';
        }
    }
    // add a button to allow adding town groups (only for group members)
    if ($group->grouptype == 'local' && $group->localtype == 'departemental' && $group->isMember(elgg_get_logged_in_user_entity())) {
        $url = elgg_get_site_url() . "groups/local/add/{$group->getGUID()}";
        $actions[$url] = 'localgroups:addtown';
    }
    // group members (not for local groups except town group)
    if ($group->grouptype == 'local' && $group->localtype == 'town' || $group->grouptype != 'local') {
        if ($group->isMember(elgg_get_logged_in_user_entity())) {
            if ($group->getOwnerGUID() != elgg_get_logged_in_user_guid()) {
                // leave
                $url = elgg_get_site_url() . "action/groups/leave?group_guid={$group->getGUID()}";
                $url = elgg_add_action_tokens_to_url($url);
                $actions[$url] = 'groups:leave';
            }
        } elseif (elgg_is_logged_in()) {
            // join - admins can always join.
            $url = elgg_get_site_url() . "action/groups/join?group_guid={$group->getGUID()}";
            $url = elgg_add_action_tokens_to_url($url);
            if ($group->isPublicMembership() || $group->canEdit()) {
                $actions[$url] = 'groups:join';
            } else {
                // request membership
                $actions[$url] = 'groups:joinrequest';
            }
        }
    }
    if ($actions) {
        foreach ($actions as $url => $text) {
            elgg_register_menu_item('title', array('name' => $text, 'href' => $url, 'text' => elgg_echo($text), 'link_class' => 'elgg-button elgg-button-action'));
        }
    }
}
Exemplo n.º 11
0
/**
 * Add messageboard post
 *
 * @param ElggUser $user User posting the message
 * @param ElggGroup $group Group who owns the message board
 * @param stdClass $message The posted message
 * @param int $access_id Access level
 * @return bool
 */
function wespot_msg_add_message($user, $group, $message, $access_id = ACCESS_PUBLIC)
{
    if (!isset($message) || empty($message->messageId) || empty($message->threadId) || empty($message->body)) {
        return false;
    }
    $obj = new ElggObject();
    $obj->subtype = 'arlearn_msg';
    $obj->owner_guid = $user->getGUID();
    $obj->container_guid = $group->getGUID();
    $obj->write_access_id = ACCESS_PRIVATE;
    //$access_id;
    $obj->access_id = ACCESS_PUBLIC;
    $obj->messageId = $message->messageId;
    $obj->threadId = $message->threadId;
    $obj->body = $message->body;
    $obj->post_date = $message->date;
    elgg_set_ignore_access(true);
    $result = $obj->save();
    elgg_set_ignore_access(false);
    if (!$result) {
        return false;
    }
    //add_to_river('river/object/arlearn_msg/create', 'create', $user->guid, $group->guid, $access_id, ($obj->post_date / 1000), $result);
    return $result;
}
Exemplo n.º 12
0
/**
 * Get the time_created from the group membership relation
 *
 * @param ElggUser  $user  the user to check
 * @param ElggGroup $group the group to check
 *
 * @return int
 */
function group_tools_get_membership_information(ElggUser $user, ElggGroup $group)
{
    if (!$user instanceof ElggUser || !$group instanceof ElggGroup) {
        return 0;
    }
    $query = 'SELECT *';
    $query .= ' FROM ' . elgg_get_config('dbprefix') . 'entity_relationships';
    $query .= " WHERE guid_one = {$user->getGUID()}";
    $query .= " AND guid_two = {$group->getGUID()}";
    $query .= ' AND relationship = "member"';
    $row = get_data_row($query);
    if (!empty($row)) {
        return (int) $row->time_created;
    }
    return 0;
}
Exemplo n.º 13
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;
}