/** * 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')); } } }
} if ($valuetype == 'tags') { $input[$shortname] = string_to_tag_array($input[$shortname]); } } $input['name'] = htmlspecialchars(get_input('name', '', false), ENT_QUOTES, 'UTF-8'); $user = elgg_get_logged_in_user_entity(); $group_guid = (int) get_input('group_guid'); $is_new_group = $group_guid == 0; if ($is_new_group && elgg_get_plugin_setting('limited_groups', 'groups') == 'yes' && !$user->isAdmin()) { register_error(elgg_echo("groups:cantcreate")); forward(REFERER); } $group = new ElggGroup($group_guid); // load if present, if not create a new group if ($group_guid && !$group->canEdit()) { register_error(elgg_echo("groups:cantedit")); forward(REFERER); } // Assume we can edit or this is a new group if (sizeof($input) > 0) { foreach ($input as $shortname => $value) { // update access collection name if group name changes if (!$is_new_group && $shortname == 'name' && $value != $group->name) { $group_name = html_entity_decode($value, ENT_QUOTES, 'UTF-8'); $ac_name = sanitize_string(elgg_echo('groups:group') . ": " . $group_name); $acl = get_access_collection($group->group_acl); if ($acl) { // @todo Elgg api does not support updating access collection name $db_prefix = elgg_get_config('dbprefix'); $query = "UPDATE {$db_prefix}access_collections SET name = '{$ac_name}' \n\t\t\t\t\tWHERE id = {$group->group_acl}";
if ($valuetype == 'tags') { $input[$shortname] = string_to_tag_array($input[$shortname]); } } $user_guid = get_input('user_guid'); $user = NULL; if (!$user_guid) { $user = $_SESSION['user']; } else { $user = get_entity($user_guid); } $dgroup_guid = get_input('dgroup_guid'); $dgroup = new ElggGroup($dgroup_guid); // load if present, if not create a new dgroup $dgroup->subtype = 'dgroup'; if ($dgroup_guid && !$dgroup->canEdit() && !isadminloggedin()) { register_error(elgg_echo("dgroups:cantedit")); forward($_SERVER['HTTP_REFERER']); exit; } // Assume we can edit or this is a new dgroup if (sizeof($input) > 0) { foreach ($input as $shortname => $value) { $dgroup->{$shortname} = $value; } } // Validate create if (!$dgroup->name) { register_error(elgg_echo("dgroups:notitle")); forward($_SERVER['HTTP_REFERER']); exit;
/** * 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')); } } }
/** * Checks if a certain user can create group events * * @param $group Group to check rights for * @param $user User to check rights for * * @return bool */ function event_manager_can_create_group_events(\ElggGroup $group, $user = null) { if (empty($user)) { $user = elgg_get_logged_in_user_entity(); } if (!$group instanceof \ElggGroup || !$user instanceof \ElggUser) { return false; } $who_create_group_events = elgg_get_plugin_setting('who_create_group_events', 'event_manager'); // group_admin, members switch ($who_create_group_events) { case 'group_admin': return $group->canEdit($user->guid); case 'members': if ($group->isMember($user)) { return true; } else { return $group->canEdit($user->guid); } } return false; }
/** * Check if group mail is enabled for members * * @param ElggGroup $group The group to check (can be empty to check plugin setting) * * @return bool */ function group_tools_group_mail_members_enabled(ElggGroup $group = null) { static $mail_members_enabled; if (!isset($mail_members_enabled)) { $mail_members_enabled = false; $setting = elgg_get_plugin_setting('mail_members', 'group_tools'); if ($setting === 'yes') { $mail_members_enabled = true; } } // quick return if mail members is not allowed if (!group_tools_group_mail_enabled()) { return false; } if (!$mail_members_enabled) { return false; } if (empty($group) || !$group instanceof ElggGroup) { return true; } if ($group->canEdit()) { // group owners and admin can mail return true; } if ($group->isMember() && $group->mail_members_enable === 'yes') { return true; } return false; }