123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <?php
- function au_subgroups_add_parent($event, $type, $object) {
-
- $parent_guid = get_input('au_subgroups_parent_guid', false);
- if ($parent_guid !== false) {
- au_subgroups_set_parent_group($object->guid, $parent_guid);
- }
-
- $parent = get_entity($parent_guid);
-
-
-
-
- if (elgg_instanceof($parent, 'group')) {
- if ($parent->subgroups_enable == 'no') {
- return FALSE;
- }
- if ($parent->subgroups_members_create_enable == 'no') {
-
- if (!$parent->canEdit()) {
- return FALSE;
- }
- }
- }
- }
- function au_subgroups_clone_layout_on_create($event, $type, $object) {
- if (elgg_is_active_plugin('group_custom_layout')) {
- $parent = au_subgroups_get_parent_group($object);
-
- if ($parent) {
- au_subgroups_clone_layout($object, $parent);
- }
- }
- }
- function au_subgroups_group_visibility($event, $type, $object) {
- $parent = au_subgroups_get_parent_group($object);
-
-
- $vis = get_input('vis', false);
-
- if ($vis !== false) {
- switch ($vis) {
- case 'parent_group_acl':
- $access_id = $parent->group_acl;
- break;
-
- case ACCESS_PRIVATE:
- $access_id = $object->group_acl;
- break;
-
- default:
- $access_id = $vis;
- break;
- }
-
-
-
- if (!elgg_get_config('au_subgroups_visupdate')) {
-
- elgg_set_config('au_subgroups_visupdate', true);
- elgg_set_config('au_subgroups_vis_guid', $object->guid);
- }
-
- if (elgg_get_config('au_subgroups_vis_guid') == $object->guid) {
-
- $object->access_id = $access_id;
- $q = "UPDATE " . elgg_get_config('dbprefix') . "entities SET access_id = {$access_id} WHERE guid = {$object->guid}";
- update_data($q);
-
- metadata_update('update', 'group', $object);
- }
-
-
-
- set_time_limit(0);
-
- $children = au_subgroups_get_subgroups($object, 0);
-
- if ($children) {
- foreach($children as $child) {
- switch ($access_id) {
- case ACCESS_PUBLIC:
-
- break;
- case ACCESS_LOGGED_IN:
-
- if ($child->access_id == ACCESS_PUBLIC) {
- $child->access_id = ACCESS_LOGGED_IN;
- $child->save();
- }
- break;
-
- default:
-
-
-
-
- if (!in_array($child->access_id, array($child->group_acl, $object->group_acl))) {
- $child->access_id = $object->group_acl;
- $child->save();
- }
- break;
- }
- }
- }
- }
- }
- function au_subgroups_join_group($event, $type, $object) {
- if ($object instanceof ElggRelationship) {
- $user = get_entity($object->guid_one);
- $group = get_entity($object->guid_two);
- $parent = au_subgroups_get_parent_group($group);
-
-
-
-
- $au_subgroups_ignore_join = elgg_get_config('au_subgroups_ignore_join');
-
- if ($parent && !$au_subgroups_ignore_join) {
-
-
- $invited = check_entity_relationship($group->guid, 'invited', $user->guid);
- $children_to_join = elgg_get_plugin_user_setting('invitation_' . $group->guid, $user->guid, 'au_subgroups');
-
- if (!empty($children_to_join)) {
- $children_to_join = unserialize($children_to_join);
- }
-
- if ($invited) {
- elgg_set_config('au_subgroups_ignore_join', true);
-
-
- if (au_subgroups_join_parents_recursive($group, $user)) {
-
- if (is_array($children_to_join)) {
- $children_guids = au_subgroups_get_all_children_guids($group);
- foreach ($children_to_join as $child) {
- if (in_array($child, $children_guids)) {
- $child_group = get_entity($child);
- $child_group->join($user);
- }
- }
- }
-
-
- elgg_set_plugin_user_setting('invitation_' . $group->guid, '', $user->guid, 'au_subgroups');
- }
- else {
-
-
- return false;
- }
- }
- elseif (!$parent->isMember($user)) {
- register_error(elgg_echo('au_subgroups:error:notparentmember'));
- return false;
- }
- }
- }
- }
- function au_subgroups_leave_group($event, $type, $params) {
- $guids = au_subgroups_get_all_children_guids($params['group']);
-
- foreach ($guids as $guid) {
- leave_group($guid, $params['user']->guid);
- }
- }
- function au_subgroups_pagesetup() {
- if (in_array(elgg_get_context(), array('au_subgroups', 'group_profile'))) {
- $group = elgg_get_page_owner_entity();
- $any_member = ($group->subgroups_members_create_enable != 'no');
- if (elgg_instanceof($group, 'group') && $group->subgroups_enable != 'no') {
-
- if (($any_member && $group->isMember()) || $group->canEdit()) {
-
- elgg_register_menu_item('title', array(
- 'name' => 'add_subgroup',
- 'href' => "groups/subgroups/add/{$group->guid}",
- 'text' => elgg_echo('au_subgroups:add:subgroup'),
- 'link_class' => 'elgg-button elgg-button-action'
- ));
- }
- }
- }
- }
|