og_ui.pages.inc

  1. cis7 sites/all/modules/ulmus/og/og_ui/og_ui.pages.inc
  2. cle7 sites/all/modules/ulmus/og/og_ui/og_ui.pages.inc
  3. ecd7 sites/all/modules/ulmus/og/og_ui/og_ui.pages.inc
  4. elmsmedia7 sites/all/modules/ulmus/og/og_ui/og_ui.pages.inc
  5. harmony7 sites/all/modules/ulmus/og/og_ui/og_ui.pages.inc
  6. icor7 sites/all/modules/ulmus/og/og_ui/og_ui.pages.inc
  7. meedjum_blog7 sites/all/modules/ulmus/og/og_ui/og_ui.pages.inc
  8. mooc7 sites/all/modules/ulmus/og/og_ui/og_ui.pages.inc

Page callbacks for Organic groups module.

Functions

Namesort descending Description
og_ui_confirm_subscribe Confirm subscribe form.
og_ui_confirm_subscribe_submit Submit handler; Confirm OG membership.
og_ui_confirm_subscribe_validate Validate handler; Confirm OG membership.
og_ui_confirm_unsubscribe Confirm unsubscribe form.
og_ui_confirm_unsubscribe_submit Submit handler; Confirm OG unsubscription.
og_ui_subscribe Subscribe the current user to a group.
og_ui_unsubscribe Confirm OG unsubscription form.

File

sites/all/modules/ulmus/og/og_ui/og_ui.pages.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Page callbacks for Organic groups module.
  5. */
  6. /**
  7. * Subscribe the current user to a group.
  8. *
  9. * @param $entity_type
  10. * The group entity type.
  11. * @param $etid
  12. * The group entity ID.
  13. * @param $field_name
  14. * Optional; Group audience field name. Defaults to first best matching field.
  15. */
  16. function og_ui_subscribe($entity_type, $etid, $field_name = NULL) {
  17. global $user;
  18. $entity_info = entity_get_info($entity_type);
  19. if (!$entity_type || !$entity_info) {
  20. // Not a valid entity type.
  21. drupal_not_found();
  22. return;
  23. }
  24. $entity = entity_load_single($entity_type, $etid);
  25. if (!$entity || !og_is_group($entity_type, $entity)) {
  26. // Not a valid entity, or not a group.
  27. drupal_not_found();
  28. return;
  29. }
  30. list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
  31. $account = user_load($user->uid);
  32. if (empty($field_name)) {
  33. $field_name = og_get_best_group_audience_field('user', $account, $entity_type, $bundle);
  34. if (empty($field_name)) {
  35. // User entity has no group audience field.
  36. drupal_not_found();
  37. return;
  38. }
  39. }
  40. $field = field_info_field($field_name);
  41. $instance = field_info_instance('user', $field_name, 'user');
  42. if (empty($instance) || !field_access('view', $field, 'user', $account)) {
  43. // Field name given is incorrect, or user doesn't have access to the field.
  44. drupal_not_found();
  45. return;
  46. }
  47. if (!$user->uid) {
  48. // Anonymous user can't request membership.
  49. $dest = drupal_get_destination();
  50. if (variable_get('user_register', 1)) {
  51. drupal_set_message(t('In order to join any group, you must <a href="!login">login</a>. After you have successfully done so, you will need to request membership again.', array('!login' => url("user/login", array('query' => $dest)))));
  52. }
  53. else {
  54. drupal_set_message(t('In order to join any group, you must <a href="!login">login</a> or <a href="!register">register</a> a new account. After you have successfully done so, you will need to request membership again.', array('!register' => url("user/register", array('query' => $dest)), '!login' => url("user/login", array('query' => $dest)))));
  55. }
  56. drupal_goto('user');
  57. }
  58. $redirect = FALSE;
  59. $message = '';
  60. $params = array();
  61. $params['@user'] = format_username($user);
  62. // Show the group name only if user has access to it.
  63. $params['@group'] = entity_access('view', $entity_type, $entity) ? entity_label($entity_type, $entity) : t('Private group');
  64. if (og_is_member($entity_type, $id, 'user', $user, array(OG_STATE_BLOCKED))) {
  65. // User is blocked, access denied.
  66. drupal_access_denied();
  67. return;
  68. }
  69. if (og_is_member($entity_type, $id, 'user', $user, array(OG_STATE_PENDING))) {
  70. // User is pending, return them back.
  71. $message = $user->uid == $user->uid ? t('You already have a pending membership for the group @group.', $params) : t('@user already has a pending membership for the the group @group.', $params);
  72. $redirect = TRUE;
  73. }
  74. if (og_is_member($entity_type, $id, 'user', $user, array(OG_STATE_ACTIVE))) {
  75. // User is already a member, return them back.
  76. $message = $user->uid == $user->uid ? t('You are already a member of the group @group.', $params) : t('@user is already a member of the group @group.', $params);
  77. $redirect = TRUE;
  78. }
  79. if (!$message && $field['cardinality'] != FIELD_CARDINALITY_UNLIMITED) {
  80. // Check if user is already registered as active or pending in the maximum
  81. // allowed values.
  82. $wrapper = entity_metadata_wrapper('user', $account->uid);
  83. if ($field['cardinality'] == 1) {
  84. $count = $wrapper->{$field_name}->value() ? 1 : 0;
  85. }
  86. else {
  87. $count = $wrapper->{$field_name}->count();
  88. }
  89. if ($count >= $field['cardinality']) {
  90. $message = t('You cannot register to this group, as you have reached your maximum allowed subscriptions.');
  91. $redirect = TRUE;
  92. }
  93. }
  94. if ($redirect) {
  95. drupal_set_message($message, 'warning');
  96. $url = entity_uri($entity_type, $entity);
  97. drupal_goto($url['path'], $url['options']);
  98. }
  99. if (og_user_access($entity_type, $id, 'subscribe', $user) || og_user_access($entity_type, $id, 'subscribe without approval', $user)) {
  100. // Show the user a subscription confirmation.
  101. return drupal_get_form('og_ui_confirm_subscribe', $entity_type, $id, $user, $field_name);
  102. }
  103. drupal_access_denied();
  104. }
  105. /**
  106. * Confirm subscribe form.
  107. */
  108. function og_ui_confirm_subscribe($form, &$form_state, $group_type, $gid, $account, $field_name) {
  109. $wrapper = entity_metadata_wrapper($group_type, $gid);
  110. // Indicate the OG membership state (active or pending).
  111. $state = og_user_access($group_type, $gid, 'subscribe without approval') ? OG_STATE_ACTIVE : OG_STATE_PENDING;
  112. if ($wrapper->access('view')) {
  113. $label = $wrapper->label();
  114. }
  115. else {
  116. $label = t('Private group');
  117. if ($state == OG_STATE_ACTIVE) {
  118. // Determine if a user can subscribe to a private group, when OG-access
  119. // module is enabled, and the group is set to private.
  120. $state = variable_get('og_ui_deny_subscribe_without_approval', TRUE) ? OG_STATE_PENDING : OG_STATE_ACTIVE;
  121. }
  122. }
  123. // Add group membership form.
  124. $og_membership = og_membership_create($group_type, $gid, 'user', $account->uid, $field_name, array('state' => $state));
  125. $form_state['og_membership'] = $og_membership;
  126. field_attach_form('og_membership', $og_membership, $form, $form_state);
  127. if ($state == OG_STATE_ACTIVE && !empty($form[OG_MEMBERSHIP_REQUEST_FIELD])) {
  128. // Hide the user request field.
  129. $form[OG_MEMBERSHIP_REQUEST_FIELD]['#access'] = FALSE;
  130. }
  131. $form['group_type'] = array('#type' => 'value', '#value' => $group_type);
  132. $form['gid'] = array('#type' => 'value', '#value' => $gid);
  133. $form['field_name'] = array('#type' => 'value', '#value' => $field_name);
  134. return confirm_form($form, t('Are you sure you want to join the group %title?', array('%title' => $label)), $wrapper->url->value(), ' ', t('Join'), t('Cancel'));
  135. }
  136. /**
  137. * Validate handler; Confirm OG membership.
  138. */
  139. function og_ui_confirm_subscribe_validate($form, &$form_state) {
  140. // @see entity_form_field_validate().
  141. $og_membership = $form_state['og_membership'];
  142. field_attach_form_validate('og_membership', $og_membership, $form, $form_state);
  143. }
  144. /**
  145. * Submit handler; Confirm OG membership.
  146. */
  147. function og_ui_confirm_subscribe_submit($form, &$form_state) {
  148. global $user;
  149. $og_membership = $form_state['og_membership'];
  150. field_attach_submit('og_membership', $og_membership, $form, $form_state);
  151. $og_membership->save();
  152. $group_type = $form_state['values']['group_type'];
  153. $gid = $form_state['values']['gid'];
  154. $group = entity_load_single($group_type, $gid);
  155. if (entity_access('view', $group_type, $group)) {
  156. $redirect = entity_uri($group_type, $group);
  157. }
  158. else {
  159. // User doesn't have access to the group entity, so redirect to front page,
  160. // with a message.
  161. $redirect = '';
  162. drupal_set_message(t('Your subscription request was sent.'));
  163. }
  164. $form_state['redirect'] = $redirect;
  165. }
  166. /**
  167. * Confirm OG unsubscription form.
  168. *
  169. * The unsubscribing user is always the acting user - like this we make sure
  170. * no malicious user will unsubscribe another user. Administrators can reject or
  171. * ban another group member from the "people" page.
  172. */
  173. function og_ui_unsubscribe($group_type, $gid) {
  174. global $user;
  175. $account = clone $user;
  176. $group = entity_load_single($group_type, $gid);
  177. if (!$group || !og_is_group($group_type, $group)) {
  178. // Not a valid entity, or not a group.
  179. drupal_not_found();
  180. return;
  181. }
  182. // Check the user isn't the manager of the group.
  183. if ($group->uid != $user->uid) {
  184. if (og_is_member($group_type, $gid, 'user', $account, array(OG_STATE_ACTIVE, OG_STATE_PENDING))) {
  185. // Show the user a subscription confirmation.
  186. return drupal_get_form('og_ui_confirm_unsubscribe', $group_type, $group);
  187. }
  188. drupal_access_denied();
  189. return;
  190. }
  191. else {
  192. $label = entity_label($group_type, $group);
  193. drupal_set_message(t('As the manager of %group, you can not leave the group.', array('%group' => $label)));
  194. $url = entity_uri($group_type, $group);
  195. drupal_goto($url['path'], $url['options']);
  196. }
  197. }
  198. /**
  199. * Confirm unsubscribe form.
  200. */
  201. function og_ui_confirm_unsubscribe($form, &$form_state, $group_type, $group) {
  202. $form['group_type'] = array('#type' => 'value', '#value' => $group_type);
  203. $form['group'] = array('#type' => 'value', '#value' => $group);
  204. $label = entity_label($group_type, $group);
  205. $url = entity_uri($group_type, $group);
  206. return confirm_form($form, t('Are you sure you want to unsubscribe from the group %title?', array('%title' => $label)), $url, NULL, t('Remove'), t('Cancel'));
  207. }
  208. /**
  209. * Submit handler; Confirm OG unsubscription.
  210. */
  211. function og_ui_confirm_unsubscribe_submit($form, &$form_state) {
  212. $group_type = $form_state['values']['group_type'];
  213. $group = $form_state['values']['group'];
  214. og_ungroup($group_type, $group);
  215. if (entity_access('view', $group_type, $group)) {
  216. $form_state['redirect'] = entity_uri($group_type, $group);
  217. }
  218. else {
  219. $form_state['redirect'] = '<front>';
  220. }
  221. }
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.