MENU_CALLBACK, 'file' => 'og_ui.pages.inc', 'page callback' => 'og_ui_subscribe', 'page arguments' => array(1, 2), // Function will take care of permissions, as we want to show "you are // already a member of the group" to group members, however it is not // possible to give authenticated group members the "subscribe" permissions. 'access callback' => 'user_is_logged_in', // We don't add the group name, as it might be private. 'title' => 'Join group' ); $items['group/%/%/unsubscribe'] = array( 'type' => MENU_CALLBACK, 'file' => 'og_ui.pages.inc', 'page callback' => 'og_ui_unsubscribe', 'page arguments' => array(1, 2), 'access callback' => 'og_user_access_by_entity', 'access arguments' => array('unsubscribe', 1, 2), 'title' => 'Leave group', ); $items['group/%/%/invite'] = array( 'page callback' => 'drupal_get_form', 'page arguments' => array('og_ui_invite_form', 1, 2), 'access callback' => 'og_user_access_by_entity', 'access arguments' => array('invite', 1, 2), 'title' => 'Send invitation', 'type' => MENU_CALLBACK, 'file' => 'og_ui.pages.inc', ); $items['group/%/%/admin/people/add-user'] = array( 'page callback' => 'drupal_get_form', 'title' => 'Add members', 'page arguments' => array('og_ui_add_users', 1, 2), 'type' => MENU_LOCAL_TASK, 'file' => 'og_ui.admin.inc', 'weight' => 5, 'access callback' => 'og_user_access_by_entity', 'access arguments' => array('add user', 1, 2), ); // User listing pages. $items['group/%/%/admin/people'] = array( 'title arguments' => array('People in group @group', 1, 2), 'title callback' => 'og_ui_menu_title_callback', 'description' => 'Find and manage group members.', 'page callback' => 'drupal_get_form', 'page arguments' => array('og_ui_user_admin_account', 1, 2), 'access callback' => 'og_user_access_by_entity', 'access arguments' => array('administer group', 1, 2), 'weight' => -4, 'file' => 'og_ui.admin.inc', ); // Permission administration pages. $items['group/%/%/admin/people/roles'] = array( 'title arguments' => array('Roles for group @group', 1, 2), 'title callback' => 'og_ui_menu_title_callback', 'description' => 'List, edit, or add user roles.', 'page callback' => 'drupal_get_form', 'page arguments' => array('og_ui_user_admin_new_role', 1, 2), 'access callback' => 'og_user_access_by_entity', 'access arguments' => array('administer group', 1, 2), 'file' => 'og_ui.admin.inc', 'weight' => -9, ); $items['group/%/%/admin/people/roles/edit'] = array( 'title' => 'Edit role', 'page arguments' => array('og_ui_user_admin_role', 1, 2), 'access callback' => 'og_user_access_by_entity', 'access arguments' => array('administer group', 1, 2), 'type' => MENU_CALLBACK, ); $items['group/%/%/admin/people/permissions'] = array( 'title arguments' => array('Permissions for group @group', 1, 2), 'title callback' => 'og_ui_menu_title_callback', 'description' => 'Determine access to features by selecting permissions for roles.', 'page callback' => 'drupal_get_form', 'page arguments' => array('og_ui_user_admin_permissions', 1, 2), 'access callback' => 'og_user_access_by_entity', 'access arguments' => array('administer group', 1, 2), 'file' => 'og_ui.admin.inc', 'weight' => -8, ); foreach (entity_get_info() as $entity => $value) { if ($value['fieldable']) { $items["$entity/%/group"] = array( 'title' => 'Group', 'page callback' => 'og_ui_group_admin_overview', 'page arguments' => array($entity, 1), 'access callback' => 'og_user_access_by_entity', 'access arguments' => array('administer group', $entity, 1), 'type' => MENU_LOCAL_TASK, 'file' => 'og_ui.admin.inc', 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, ); } } $items['admin/config/group'] = array( 'title' => 'Group', 'description' => 'Administer the suite of Group modules.', 'position' => 'right', 'weight' => -5, 'page callback' => 'system_admin_menu_block_page', 'access arguments' => array('administer group'), 'file' => 'system.admin.inc', 'file path' => drupal_get_path('module', 'system'), ); $items['admin/config/group/permissions'] = array( 'page callback' => 'drupal_get_form', 'page arguments' => array('og_ui_user_admin_global_permissions'), 'title' => 'Group global permissions', 'access arguments' => array('administer group'), 'description' => 'Configure Group global permissions.', 'file' => 'og_ui.admin.inc', ); $items['admin/config/group/fields'] = array( 'page callback' => 'drupal_get_form', 'page arguments' => array('og_ui_field_settings'), 'title' => 'Group field settings', 'access arguments' => array('administer group'), 'description' => 'Configure Group fields in bundles.', 'file' => 'og_ui.admin.inc', 'type' => MENU_NORMAL_ITEM, ); $items['admin/config/group/fields/%/%/%field_ui_menu/delete'] = array( 'page callback' => 'drupal_get_form', 'page arguments' => array('og_ui_field_delete_form', 6), 'load arguments' => array(4, 5, 5, '%map'), 'title' => 'Delete', 'access arguments' => array('administer group'), 'description' => 'Delete a group field from a bundle.', 'file' => 'og_ui.admin.inc', 'type' => MENU_LOCAL_TASK, ); return $items; } /** * Menu callback; Return the title of a menu item based on the group title. */ function og_ui_menu_title_callback($title, $entity_type, $etid) { $group = og_get_group($entity_type, $etid); $label = og_label($group->gid); return str_replace('@group', $label, $title); } /** * Implement hook_theme(). */ function og_ui_theme() { return array( 'og_ui_user_admin_permissions' => array( 'render element' => 'form', 'file' => 'og_ui.admin.inc', ), 'og_ui_user_admin_new_role' => array( 'render element' => 'form', 'file' => 'og_ui.admin.inc', ), ); } /** * Implement hook_field_formatter_info(). */ function og_ui_field_formatter_info() { return array( 'og_group_subscribe' => array( 'label' => t('Group subscription'), 'field types' => array('list_boolean'), ), ); } /** * Implements hook_field_formatter_view(). */ function og_ui_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array(); if ($field['field_name'] == OG_GROUP_FIELD && $links = og_ui_subscribe_link($entity_type, $entity)) { $element[0] = $links; } return $element; } /** * Return a subscribe link according to user's permissions. * * @param $entity_type * @param $entity * @param $account * @return unknown_type */ function og_ui_subscribe_link($entity_type, $entity, $account = NULL) { $return = array(); if (empty($account)) { global $user; $account = clone($user); } list($id) = entity_extract_ids($entity_type, $entity); if (($group = og_get_group($entity_type, $id))) { if (!empty($entity->uid) && ($entity->uid == $user->uid)) { // User is the group manager. $return = array( '#type' => 'item', '#markup' => t('You are the group manager'), ); } else { // check the user state. if ($state = og_get_entity_state($group->gid, 'user', $account)) { if ($state == OG_STATE_PENDING && og_user_access($group->gid, 'subscribe')) { $links['title'] = t('Re-request group membership'); $links['href'] = "group/$entity_type/$id/subscribe"; } elseif ($state == OG_STATE_ACTIVE && og_user_access($group->gid, 'unsubscribe', $account)) { $links['title'] = t('Unsubscribe from group'); $links['href'] = "group/$entity_type/$id/unsubscribe"; } } else { if (og_user_access($group->gid, 'subscribe without approval', $account)) { $links['title'] = t('Subscribe to group'); $url = "group/$entity_type/$id/subscribe"; if ($account->uid) { $links['href'] = $url; } else { $links['href'] = 'user/login'; $links['options'] = array('query' => array('destination' => $url)); } } elseif (og_user_access($group->gid, 'subscribe')) { $links['title'] = t('Request group membership'); $url = "group/$entity_type/$id/subscribe"; if ($account->uid) { $links['href'] = $url; } else { $links['href'] = 'user/login'; $links['options'] = array('query' => array('destination' => $url)); } } else { $return = array( '#type' => 'item', '#markup' => t('This is a closed group. Only a group administrator can add you.'), ); } } if (!empty($links['title'])) { $links += array('options' => array()); $return = array( '#type' => 'link', '#title' => $links['title'], '#href' => $links['href'], '#options' => $links['options'], ); } } } return $return; } /** * Implement hook_forms(). */ function og_ui_forms() { $forms['og_ui_user_admin_new_role']['callback'] = 'og_ui_user_admin_role'; // Form to define the default permissions state for new groups. $forms['og_ui_user_admin_global_permissions']['callback'] = 'og_ui_user_admin_permissions'; return $forms; } /** * Implement hook_form_FORM_ID_alter(). */ function og_ui_form_node_type_form_alter(&$form, &$form_state) { $node_type = $form['#node_type']->type; $form['group'] = array( '#type' => 'fieldset', '#title' => t('Group'), '#collapsible' => TRUE, '#group' => 'additional_settings', '#description' => t('Specify how Group should treat content of this type. Content may behave as a group, as group content, or may not participate in Group at all.'), ); $form['group']['og_group_type'] = array( '#type' => 'radios', '#title' => t('Group'), '#default_value' => og_is_group_type('node', $node_type) ? 'group' : 'omitted', '#options' => array('omitted' => t('Not a group type'), 'group' => t('Group type')), ); $form['group']['og_group_content_type'] = array( '#type' => 'radios', '#title' => t('Group content'), '#default_value' => og_is_group_content_type('node', $node_type) ? 'og_content' : 'omitted', '#options' => array('omitted' => t('Not a group content type'), 'og_content' => t('Group content type')), ); } /** * Implement hook_og_permission(). */ function og_ui_og_permission() { $items = array(); $items['subscribe'] = array( 'title' => t('Subscribe user to group'), 'description' => t("Allow user to be a member of a group (approval required)."), 'roles' => array(OG_ANONYMOUS_ROLE), 'default role' => array(OG_ANONYMOUS_ROLE), ); $items['subscribe without approval'] = array( 'title' => t('Subscribe user to group (no approval required).'), 'description' => t("Allow user to be a member of a group without an approval of the group administrator."), 'roles' => array(OG_ANONYMOUS_ROLE), ); $items['unsubscribe'] = array( 'title' => t('Unsubscribe user from group'), 'description' => t("Allow user to be remove membership from a group."), 'roles' => array(OG_AUTHENTICATED_ROLE), 'default role' => array(OG_AUTHENTICATED_ROLE), ); $items['approve and deny subscription'] = array( 'title' => t('Approve and deny subscription'), 'description' => t("Allow user to allow or deny another user's subscription request."), 'default role' => array(OG_ADMINISTRATOR_ROLE), ); $items['add user'] = array( 'title' => t('Add user'), 'description' => t("Add a new user to the group."), 'default role' => array(OG_ADMINISTRATOR_ROLE), ); return $items; } /** * Implement hook_og_user_operations(). */ function og_ui_og_user_operations($form = array(), $form_state = array()) { $gid = $form_state['group']->gid; $operations = array( 'unblock' => array( 'label' => t('Approve membership of the selected users'), 'callback' => 'og_ui_user_operations_approve', ), 'deny' => array( 'label' => t('Deny membership from the selected users'), 'callback' => 'og_ui_user_operations_deny', ), 'block' => array( 'label' => t('Block membership from the selected users'), 'callback' => 'og_ui_user_operations_block', ), ); if (og_user_access($gid, 'administer group')) { $roles = og_user_roles($gid); $add_roles = array(); foreach ($roles as $rid => $name) { if (!in_array($name, array(OG_ANONYMOUS_ROLE, OG_AUTHENTICATED_ROLE))) { $add_roles['add_role-' . $rid] = strip_tags($name); } } $remove_roles = array(); foreach ($roles as $rid => $name) { if (!in_array($name, array(OG_ANONYMOUS_ROLE, OG_AUTHENTICATED_ROLE))) { $remove_roles['remove_role-' . $rid] = strip_tags($name); } } if ($add_roles) { $role_operations = array( t('Add a role to the selected users') => array( 'label' => $add_roles, ), t('Remove a role from the selected users') => array( 'label' => $remove_roles, ), ); $operations += $role_operations; } } // If the form has been posted, we need to insert the proper data for // role editing if necessary. if (!empty($form_state['submitted'])) { $operation_rid = explode('-', $form_state['values']['operation']); $operation = $operation_rid[0]; if ($operation == 'add_role' || $operation == 'remove_role') { $rid = $operation_rid[1]; if (og_user_access($gid, 'administer group')) { $operations[$form_state['values']['operation']] = array( 'callback' => 'og_ui_user_multiple_role_edit', 'callback arguments' => array($operation, $rid), ); } else { watchdog('security', 'Detected malicious attempt to alter protected user fields.', array(), WATCHDOG_WARNING); return; } } } return $operations; } /** * Callback function for admin mass approving users. */ function og_ui_user_operations_approve($gid, $uids) { _group_ui_user_operations_set_state($gid, $uids, OG_STATE_ACTIVE); } /** * Callback function for admin mass blocking users. */ function og_ui_user_operations_block($gid, $uids) { _group_ui_user_operations_set_state($gid, $uids, OG_STATE_BLOCKED); } /** * Set the state of a user in a group. * * @param $gid * Group ID * @param $uids * Uset IDs * @param $state * The state to set the user in the group. */ function _group_ui_user_operations_set_state($gid, $uids, $state) { $accounts = user_load_multiple($uids); foreach ($accounts as $account) { og_group($gid, 'user', $account, $state); } } /** * Callback function for admin mass denying users. */ function og_ui_user_operations_deny($gid, $uids) { $accounts = user_load_multiple($uids); foreach ($accounts as $account) { og_ungroup($gid, 'user', $account); } } /** * Callback function for admin mass adding/ deleting a user role. */ function og_ui_user_multiple_role_edit($gid, $accounts, $operation, $rid) { switch ($operation) { case 'add_role': $accounts = user_load_multiple($accounts); foreach ($accounts as $account) { og_users_roles_grant($gid, $account->uid, $rid); } break; case 'remove_role': $accounts = user_load_multiple($accounts); foreach ($accounts as $account) { og_users_roles_revoke($gid, $account->uid, $rid); } break; } } /** * Implementation of hook_og_ui_get_group_admin() */ function og_ui_og_ui_get_group_admin($gid) { $items = array(); $default_access = og_is_group_default_access($gid); $items['add_people'] = array( 'title' => t('Add people'), 'description' => t('Add group members.'), // The final URL will be "group/$entity_type/$etid/admin/people/add-user". // @see og_ui_group_admin_overview(). 'href' => 'admin/people/add-user', ); $items['people'] = array( 'title' => t('People'), 'description' => t('Manage the group members.'), 'href' => "admin/people", ); $items['roles'] = array( 'title' => !$default_access ? t('Roles') : t('Roles (read-only)'), 'description' => !$default_access ? t('Manage the group roles.') : t('View the group roles.'), 'href' => "admin/people/roles", ); $items['permissions'] = array( 'title' => !$default_access ? t('Permissions') : t('Permissions (read-only)'), 'description' => !$default_access ? t('Manage the group permissions.') : t('View the group permissions.'), 'href' => "admin/people/permissions", ); return $items; } /** * Get all the group admin menu items. */ function og_ui_get_group_admin($gid) { $data = module_invoke_all('og_ui_get_group_admin', $gid); // Allow other modules to alter the menu items. drupal_alter('og_ui_get_group_admin', $data, $gid); return $data; }