123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586 |
- <?php
- /**
- * Groups function library
- */
- /**
- * List all groups
- */
- function groups_handle_all_page() {
- $display_subgroups = elgg_get_plugin_setting('display_subgroups', 'au_subgroups');
- $db_prefix = elgg_get_config('dbprefix');
-
- // all groups doesn't get link to self
- elgg_pop_breadcrumb();
- elgg_push_breadcrumb(elgg_echo('groups'));
- if (elgg_get_plugin_setting('limited_groups', 'groups') != 'yes' || elgg_is_admin_logged_in()) {
- elgg_register_title_button();
- }
- $selected_tab = get_input('filter', 'newest');
- switch ($selected_tab) {
- case 'popular':
- $options = array(
- 'type' => 'group',
- 'relationship' => 'member',
- 'inverse_relationship' => false,
- 'full_view' => false,
- );
-
- if ($display_subgroups != 'yes') {
- $options['wheres'] = array("NOT EXISTS ( SELECT 1 FROM {$db_prefix}entity_relationships WHERE guid_one = e.guid AND relationship = '" . AU_SUBGROUPS_RELATIONSHIP . "' )");
- }
-
- $content = elgg_list_entities_from_relationship_count($options);
-
- if (!$content) {
- $content = elgg_echo('groups:none');
- }
- break;
- case 'discussion':
- $content = elgg_list_entities(array(
- 'type' => 'object',
- 'subtype' => 'groupforumtopic',
- 'order_by' => 'e.last_action desc',
- 'limit' => 40,
- 'full_view' => false,
- ));
- if (!$content) {
- $content = elgg_echo('discussion:none');
- }
- break;
- case 'featured':
- $content = elgg_list_entities_from_metadata(array(
- 'type' => 'group',
- 'metadata_name' => 'featured_group',
- 'metadata_value' => 'yes',
- 'full_view' => false,
- ));
- if (!$content) {
- $content = elgg_echo('groups:nofeatured');
- }
- break;
- case 'newest':
- default:
- $options = array(
- 'type' => 'group',
- 'full_view' => false
- );
-
- if ($display_subgroups != 'yes') {
- $options['wheres'] = array("NOT EXISTS ( SELECT 1 FROM {$db_prefix}entity_relationships WHERE guid_one = e.guid AND relationship = '" . AU_SUBGROUPS_RELATIONSHIP . "' )");
- }
-
- $content = elgg_list_entities($options);
- if (!$content) {
- $content = elgg_echo('groups:none');
- }
- break;
- }
- $filter = elgg_view('groups/group_sort_menu', array('selected' => $selected_tab));
-
- // $sidebar = elgg_view('groups/sidebar/find');
- // $sidebar .= elgg_view('groups/sidebar/featured');
- $params = array(
- 'content' => $content,
- 'sidebar' => $sidebar,
- 'filter' => $filter,
- );
- $body = elgg_view_layout('content', $params);
- echo elgg_view_page(elgg_echo('groups:all'), $body);
- }
- function groups_search_page() {
- elgg_push_breadcrumb(elgg_echo('search'));
- $tag = get_input("tag");
- $title = elgg_echo('groups:search:title', array($tag));
- // groups plugin saves tags as "interests" - see groups_fields_setup() in start.php
- $params = array(
- 'metadata_name' => 'interests',
- 'metadata_value' => $tag,
- 'types' => 'group',
- 'full_view' => FALSE,
- );
- $content = elgg_list_entities_from_metadata($params);
- if (!$content) {
- $content = elgg_echo('groups:search:none');
- }
- // $sidebar = elgg_view('groups/sidebar/find');
- // $sidebar .= elgg_view('groups/sidebar/featured');
- $params = array(
- 'content' => $content,
- 'sidebar' => $sidebar,
- 'filter' => false,
- 'title' => $title,
- );
- $body = elgg_view_layout('content', $params);
- echo elgg_view_page($title, $body);
- }
- /**
- * List owned groups
- */
- function groups_handle_owned_page() {
- au_subgroups_handle_owned_page();
- }
- /**
- * List groups the user is memober of
- */
- function groups_handle_mine_page() {
- au_subgroups_handle_mine_page();
- }
- /**
- * Create or edit a group
- *
- * @param string $page
- * @param int $guid
- */
- function groups_handle_edit_page($page, $guid = 0) {
- gatekeeper();
-
- if ($page == 'add') {
- elgg_set_page_owner_guid(elgg_get_logged_in_user_guid());
- $title = elgg_echo('groups:add');
- elgg_push_breadcrumb($title);
- if (elgg_get_plugin_setting('limited_groups', 'groups') != 'yes' || elgg_is_admin_logged_in()) {
- $content = elgg_view('groups/edit');
- } else {
- $content = elgg_echo('groups:cantcreate');
- }
- } else {
- $title = elgg_echo("groups:edit");
- $group = get_entity($guid);
- if ($group && $group->canEdit()) {
- elgg_set_page_owner_guid($group->getGUID());
- elgg_push_breadcrumb($group->name, $group->getURL());
- elgg_push_breadcrumb($title);
- $content = elgg_view("groups/edit", array('entity' => $group));
- //$values=groups_prepare_form_vars($group);
- //$content = elgg_view("groups/edit", array('entity' => $group,'values' => $values));
- } else {
- $content = elgg_echo('groups:noaccess');
- }
- }
-
- $params = array(
- 'content' => $content,
- 'title' => $title,
- 'filter' => '',
- );
- $body = elgg_view_layout('content', $params);
- echo elgg_view_page($title, $body);
- }
- /**
- * Group invitations for a user
- */
- function groups_handle_invitations_page() {
- gatekeeper();
- $user = elgg_get_page_owner_entity();
- $title = elgg_echo('groups:invitations');
- elgg_push_breadcrumb($title);
- // @todo temporary workaround for exts #287.
- $invitations = groups_get_invited_groups(elgg_get_logged_in_user_guid());
- $content = elgg_view('groups/invitationrequests', array('invitations' => $invitations));
- $params = array(
- 'content' => $content,
- 'title' => $title,
- 'filter' => '',
- );
- $body = elgg_view_layout('content', $params);
- echo elgg_view_page($title, $body);
- }
- /**
- * Group profile page
- *
- * @param int $guid Group entity GUID
- */
- function groups_handle_profile_page($guid) {
- elgg_set_page_owner_guid($guid);
- // turn this into a core function
- global $autofeed;
- $autofeed = true;
-
- elgg_push_context('group_profile');
- $group = get_entity($guid);
- if (!$group) {
- forward('groups/all');
- }
-
- elgg_push_breadcrumb($group->name);
- groups_register_profile_buttons($group);
-
- $content = elgg_view('groups/profile/layout', array('entity' => $group));
- if (group_gatekeeper(false)) {
- $sidebar = '';
- if (elgg_is_active_plugin('search')) {
- $sidebar .= elgg_view('groups/sidebar/search', array('entity' => $group));
- }
- $sidebar .= elgg_view('groups/sidebar/members', array('entity' => $group));
- } else {
- $sidebar = '';
- }
- $params = array(
- 'content' => $content,
- 'sidebar' => $sidebar,
- 'title' => $group->name,
- 'filter' => '',
- );
- $body = elgg_view_layout('content', $params);
-
- echo elgg_view_page($group->name, $body);
- }
- /**
- * Group profile page
- *
- * @param int $guid Group entity GUID
- */
- function groups_handle_main_page($guid) {
- elgg_set_page_owner_guid($guid);
- // turn this into a core function
- global $autofeed;
- $autofeed = true;
-
- //elgg_push_context('group_profile');
- $group = get_entity($guid);
- if (!$group) {
- forward('groups/all');
- }
-
- elgg_push_breadcrumb($group->name);
- groups_register_profile_buttons($group);
-
- $content = elgg_view('groups/profile/layout', array('entity' => $group));
- if (group_gatekeeper(false)) {
- $sidebar = '';
- if (elgg_is_active_plugin('search')) {
- $sidebar .= elgg_view('groups/sidebar/search', array('entity' => $group));
- }
- $sidebar .= elgg_view('groups/sidebar/members', array('entity' => $group));
- } else {
- $sidebar = '';
- }
- $params = array(
- 'content' => $content,
- 'sidebar' => $sidebar,
- 'title' => $group->name,
- 'filter' => '',
- );
- $body = elgg_view_layout('content', $params);
-
- echo elgg_view_page($group->name, $body);
- }
- /**
- * Group activity page
- *
- * @param int $guid Group entity GUID
- */
- function groups_handle_activity_page($guid) {
- elgg_set_page_owner_guid($guid);
- $group = get_entity($guid);
- if (!$group || !elgg_instanceof($group, 'group')) {
- forward();
- }
- group_gatekeeper();
- $title = elgg_echo('groups:activity');
- elgg_push_breadcrumb($group->name, $group->getURL());
- elgg_push_breadcrumb($title);
- $db_prefix = elgg_get_config('dbprefix');
- $content = elgg_list_river(array(
- 'joins' => array("JOIN {$db_prefix}entities e ON e.guid = rv.object_guid"),
- 'wheres' => array("e.container_guid = $guid")
- ));
- if (!$content) {
- $content = '<p>' . elgg_echo('groups:activity:none') . '</p>';
- }
-
- $params = array(
- 'content' => $content,
- 'title' => $title,
- 'filter' => '',
- );
- $body = elgg_view_layout('content', $params);
- echo elgg_view_page($title, $body);
- }
- /**
- * Group members page
- *
- * @param int $guid Group entity GUID
- */
- function groups_handle_members_page($guid) {
- elgg_set_page_owner_guid($guid);
- $group = get_entity($guid);
- if (!$group || !elgg_instanceof($group, 'group')) {
- forward();
- }
- group_gatekeeper();
- $title = elgg_echo('groups:members:title', array($group->name));
- elgg_push_breadcrumb($group->name, $group->getURL());
- elgg_push_breadcrumb(elgg_echo('groups:members'));
- $content = elgg_list_entities_from_relationship(array(
- 'relationship' => 'member',
- 'relationship_guid' => $group->guid,
- 'inverse_relationship' => true,
- 'types' => 'user',
- 'limit' => 20,
- ));
- $params = array(
- 'content' => $content,
- 'title' => $title,
- 'filter' => '',
- );
- $body = elgg_view_layout('content', $params);
- echo elgg_view_page($title, $body);
- }
- /**
- * Invite users to a group
- *
- * @param int $guid Group entity GUID
- */
- function groups_handle_invite_page($guid) {
- gatekeeper();
- elgg_set_page_owner_guid($guid);
- $group = get_entity($guid);
- $title = elgg_echo('groups:invite:title');
- elgg_push_breadcrumb($group->name, $group->getURL());
- elgg_push_breadcrumb(elgg_echo('groups:invite'));
- if ($group && $group->canEdit()) {
- $content = elgg_view_form('groups/invite', array(
- 'id' => 'invite_to_group',
- 'class' => 'elgg-form-alt mtm',
- ), array(
- 'entity' => $group,
- ));
- } else {
- $content .= elgg_echo('groups:noaccess');
- }
- $params = array(
- 'content' => $content,
- 'title' => $title,
- 'filter' => '',
- );
- $body = elgg_view_layout('content', $params);
- echo elgg_view_page($title, $body);
- }
- /**
- * Manage requests to join a group
- *
- * @param int $guid Group entity GUID
- */
- function groups_handle_requests_page($guid) {
- gatekeeper();
- elgg_set_page_owner_guid($guid);
- $group = get_entity($guid);
- $title = elgg_echo('groups:membershiprequests');
- if ($group && $group->canEdit()) {
- elgg_push_breadcrumb($group->name, $group->getURL());
- elgg_push_breadcrumb($title);
-
- $requests = elgg_get_entities_from_relationship(array(
- 'type' => 'user',
- 'relationship' => 'membership_request',
- 'relationship_guid' => $guid,
- 'inverse_relationship' => true,
- 'limit' => 0,
- ));
- $content = elgg_view('groups/membershiprequests', array(
- 'requests' => $requests,
- 'entity' => $group,
- ));
- } else {
- $content = elgg_echo("groups:noaccess");
- }
- $params = array(
- 'content' => $content,
- 'title' => $title,
- 'filter' => '',
- );
- $body = elgg_view_layout('content', $params);
- echo elgg_view_page($title, $body);
- }
- /**
- * 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',
- ));
- }
- }
- }
- /**
- * Prepares variables for the group edit form view.
- *
- * @param mixed $group ElggGroup or null. If a group, uses values from the group.
- * @return array
- */
- function groups_prepare_form_vars($group = null) {
- $values = array(
- 'name' => '',
- 'membership' => ACCESS_PUBLIC,
- 'vis' => ACCESS_PUBLIC,
- 'guid' => null,
- 'entity' => null,
- 'owner_guid' => elgg_get_logged_in_user_guid(),
- 'content_access_mode' => ElggGroup::CONTENT_ACCESS_MODE_UNRESTRICTED
- );
-
- // handle customizable profile fields
- $fields = elgg_get_config('group');
- if ($fields) {
- foreach ($fields as $name => $type) {
- $values[$name] = '';
- }
- }
- // handle tool options
- $tools = elgg_get_config('group_tool_options');
- if ($tools) {
- foreach ($tools as $group_option) {
- $option_name = $group_option->name . "_enable";
- $values[$option_name] = $group_option->default_on ? 'yes' : 'no';
- }
- }
- // get current group settings
- if ($group) {
- foreach (array_keys($values) as $field) {
- if (isset($group->$field)) {
- $values[$field] = $group->$field;
- }
- }
- if ($group->access_id != ACCESS_PUBLIC && $group->access_id != ACCESS_LOGGED_IN) {
- // group only access - this is done to handle access not created when group is created
- $values['vis'] = ACCESS_PRIVATE;
- } else {
- $values['vis'] = $group->access_id;
- }
- // The content_access_mode was introduced in 1.9. This method must be
- // used for backwards compatibility with groups created before 1.9.
- $values['content_access_mode'] = $group->getContentAccessMode();
- $values['entity'] = $group;
- }
- // get any sticky form settings
- if (elgg_is_sticky_form('groups')) {
- $sticky_values = elgg_get_sticky_values('groups');
- foreach ($sticky_values as $key => $value) {
- $values[$key] = $value;
- }
- }
- elgg_clear_sticky_form('groups');
- return $values;
- }
|