function opigno_og_access_node_access_records in Opigno 7
Implements hook_node_access_records().
File
- modules/
opigno_og_access/ opigno_og_access.module, line 54 - Enable access control for private and public groups and group content.
Code
function opigno_og_access_node_access_records($node) {
if (empty($node->status)) {
// Node is unpublished, so we don't allow every group member to see
// it.
return array();
}
$gids = array();
$wrapper = entity_metadata_wrapper('node', $node);
$hideforanonymous = FALSE;
if (!empty($wrapper->{OG_ACCESS_FIELD}) && og_is_group('node', $node)) {
if (!_opigno_og_access_node_access($wrapper)) {
$gids['node'][] = $node->nid;
}
$hideforanonymous = $wrapper->anomymous_visibility
->value() == 1;
}
if (og_is_group_content_type('node', $node->type)) {
$has_private = FALSE;
$entity_groups = og_get_entity_groups('node', $node);
foreach ($entity_groups as $group_type => $values) {
entity_load($group_type, $values);
foreach ($values as $gid) {
$list_gids[$group_type][] = $gid;
if ($has_private) {
// We already know we have a private group, so we can avoid
// re-checking it.
continue;
}
$group_wrapper = entity_metadata_wrapper($group_type, $gid);
if (!opigno_og_access_node_content_access($group_wrapper)) {
$has_private = TRUE;
}
if (!$hideforanonymous) {
if (!$has_private) {
$hideforanonymous = $group_wrapper->anomymous_visibility
->value() == 1;
}
}
}
}
if ($has_private) {
$gids = array_merge_recursive($gids, $list_gids);
}
}
foreach ($gids as $group_type => $values) {
foreach ($values as $gid) {
$grants[] = array(
'realm' => OG_ACCESS_REALM . ':' . $group_type,
'gid' => $gid,
'grant_view' => 1,
'grant_update' => 0,
'grant_delete' => 0,
'priority' => 1,
);
}
}
if ($hideforanonymous && $wrapper->{OG_ACCESS_FIELD}
->value() != 2) {
$grants[] = array(
'realm' => OG_ACCESS_REALM . ':only_auth',
'gid' => 1,
'grant_view' => 1,
'grant_update' => 0,
'grant_delete' => 0,
'priority' => 1,
);
}
return !empty($grants) ? $grants : array();
}