function spaces_router in Spaces 5
Same name and namespace in other branches
- 5.2 spaces.module \spaces_router()
- 6.3 spaces.module \spaces_router()
- 6 spaces.module \spaces_router()
- 6.2 spaces.module \spaces_router()
- 7.3 spaces.module \spaces_router()
- 7 spaces.module \spaces_router()
Consolidated group context routing logic.
Parameters
$stage: String, can be 'menu' or 'node view'.
$node: Integer, for the 'menu' stage the group id for the current group. For the 'node view' stage the node id of the node being viewed. For the 'node form' stage it must be the node object from the form array.
Return value
boolean true if access is allowed, false otherwise.
4 calls to spaces_router()
- spaces_menu in ./
spaces.module - spaces_nodeapi in ./
spaces.module - Implentation of hook_nodeapi
- spaces_user in ./
spaces.module - Implementation of hook_user
- _spaces_form_alter_node in ./
spaces.module
File
- ./
spaces.module, line 557
Code
function spaces_router($stage, $node = null) {
switch ($stage) {
case 'menu':
$gid = !$node ? spaces_gid() : $node;
$group = node_load($gid);
// Theming + routing logic
if ($group->og_private != 1 || spaces_is_member($gid)) {
og_set_group_context($group);
// Handle theme switching since OG is not prefix aware
if ($group->og_theme) {
global $custom_theme;
$custom_theme = $group->og_theme;
}
if (drupal_is_front_page()) {
return spaces_goto_grouphome($gid);
}
else {
return true;
}
}
else {
// Give anon users access to login pages.
global $user;
if (!$user->uid) {
if (arg(0) . '/' . arg(1) == 'user/login' || arg(0) == 'openid') {
return true;
}
else {
drupal_goto('user/login');
}
}
}
break;
case 'node view':
$node = node_load($node);
if (og_is_omitted_type($node->type)) {
return true;
}
elseif (og_is_group_type($node->type)) {
// If it's the actual GROUP node, send to group "homepage".
return spaces_goto_grouphome($node->nid);
}
else {
if (is_array($node->og_groups)) {
// redirect to prefix/node/xyz if user lands on node/xyz.
$node_types = spaces_content_types();
// If node type is in the feature list, check for private/public settings.
if (isset($node_types[$node->type])) {
if (!spaces_gid()) {
// Push user to correct group context.
context_prefix_goto('spaces', current($node->og_groups), $_GET['q']);
}
elseif (spaces_gid() && !in_array(spaces_gid(), $node->og_groups)) {
// Push user to correct group context if node is in alien context.
context_prefix_goto('spaces', current($node->og_groups), $_GET['q']);
}
else {
// Node_access() has already handled the real permission check for us
// here, so let the user view the node.
return true;
}
}
}
elseif (user_access('administer nodes')) {
drupal_set_message(t('This content is not assigned to a group and it not visible to non-administrative users.'));
return true;
}
}
break;
case 'node form':
if ($gid = spaces_gid()) {
$features = spaces_features($gid);
$content_types = spaces_content_types();
$feature = $content_types[$node->type];
$privacy = $features[$feature];
// Check that user edit post in this location.
if (isset($node->nid) && !in_array($gid, $node->og_groups)) {
if (!$gid) {
$gid = current($node->og_groups);
}
if (spaces_is_member($gid)) {
$path = spaces_group_path($gid);
if ($dest = $_REQUEST['destination']) {
unset($_REQUEST['destination']);
}
// Path is actually prefix. See above.
context_prefix_goto('spaces', $gid, $_GET['q'], $dest ? "destination={$dest}" : NULL);
}
}
elseif (spaces_feature($feature, $gid)) {
return true;
}
}
elseif (user_access('administer nodes')) {
drupal_set_message(t('This form should only be submitted within a properly configured group. Continue at your own risk.'));
return true;
}
break;
case 'user view':
global $user;
if (user_access('view users outside groups')) {
return true;
}
else {
$account = $node;
// Push user into a group silo if not already there.
if (!spaces_gid() && $account->og_groups && spaces_is_member(key($account->og_groups))) {
context_prefix_goto('spaces', key($account->og_groups), 'user/' . $account->uid);
}
else {
if (spaces_is_member(spaces_gid(), $user->uid) && spaces_is_member(spaces_gid(), $account->uid)) {
return true;
}
}
}
break;
}
// If we fall though access should be denied.
return false;
}