function tac_lite_node_access_records in Taxonomy Access Control Lite 6
Same name and namespace in other branches
- 8 tac_lite.module \tac_lite_node_access_records()
- 5 tac_lite.module \tac_lite_node_access_records()
- 7 tac_lite.module \tac_lite_node_access_records()
Implements hook_node_access_records().
We are given a node and we return records for the node_access table. In our case, we inpect the node's taxonomy and grant permissions based on the terms.
File
- ./
tac_lite.module, line 357 - Control access to site content based on taxonomy, roles and users.
Code
function tac_lite_node_access_records($node) {
// all terms from all vocabs
$all_tids = _tac_lite_get_terms($node);
// just the vocabs we're interested in
$vids = variable_get('tac_lite_categories', NULL);
// now find just the terms we're interested in.
$tids = array();
if (count($all_tids) && count($vids)) {
$result = db_query("SELECT DISTINCT td.tid FROM {term_data} td WHERE td.vid IN (%s) AND td.tid IN (%s)", implode(',', $vids), implode(',', $all_tids));
while ($term = db_fetch_object($result)) {
$tids[] = $term->tid;
}
}
if (!count($tids)) {
// no relevant terms found.
// in drupal 4-7 we had to write a row into the database. In drupal 5 and later, it should be safe to do nothing.
}
else {
// if we're here, the node has terms associated with it which restrict
// access to the node.
$grants = array();
for ($i = 1; $i <= variable_get('tac_lite_schemes', 1); $i++) {
$config = _tac_lite_config($i);
foreach ($tids as $tid) {
$grant = array(
'realm' => $config['realm'],
'gid' => $tid,
);
foreach ($config['perms'] as $perm) {
$grant[$perm] = TRUE;
}
$grants[] = $grant;
}
}
return $grants;
}
}