function domain_nodeapi in Domain Access 5
Same name and namespace in other branches
- 6.2 domain.module \domain_nodeapi()
Implement hook_nodeapi().
This function is used to provide debugging information and to prep values from the {domain_access} table when editing nodes. Since not all users can see the domain access editing checkboxes, we pass some node_access values as hidden elements.
1 call to domain_nodeapi()
- domain_content_form in domain_content/
domain_content.module - Rewrites node_admin_nodes() to use db_rewrite_sql().
File
- ./
domain.module, line 663 - Core module functions for the Domain Access suite.
Code
function domain_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'prepare':
case 'load':
// Append the domain grants to the node for editing.
$node->domains = array();
$node->editors = array();
$node->domain_site = FALSE;
$result = db_query("SELECT gid, realm FROM {domain_access} WHERE nid = %d AND (realm = '%s' OR realm = '%s' OR realm = '%s')", $node->nid, 'domain_id', 'domain_site', 'domain_editor');
while ($data = db_fetch_object($result)) {
// Transform the 0 to -1, since {domain_access} is unsigned.
$data->gid == 0 ? $gid = -1 : ($gid = $data->gid);
if ($data->realm == 'domain_id') {
$node->domains[$gid] = $gid;
if ($gid > 0) {
$domain = domain_lookup($gid);
$node->subdomains[] = $domain['sitename'];
}
else {
$node->subdomains[] = variable_get('domain_sitename', variable_get('site_name', 'Drupal'));
}
}
else {
if ($data->realm == 'domain_site') {
$node->domain_site = TRUE;
$node->subdomains[] = t('All affiliates');
}
else {
if ($data->realm == 'domain_editor') {
$node->domain_editor = TRUE;
if ($gid > 0) {
$domain = domain_lookup($gid);
$node->editors[] = $domain['sitename'];
}
else {
$node->editors[] = variable_get('domain_sitename', variable_get('site_name', 'Drupal'));
}
}
}
}
}
break;
case 'view':
// Search module casts both $a3 and $a4 as FALSE, not NULL.
// We check that to hide this data from search and other nodeapi
// calls that are neither a teaser nor a page view.
if ($a3 !== FALSE || $a4 !== FALSE) {
$output = '';
$debug = variable_get('domain_debug', 0);
if ($debug && user_access('set domain access')) {
if (!empty($node->subdomains)) {
$output .= '<p><b>Subdomains</b></p><ul>';
foreach ($node->subdomains as $name) {
$output .= '<li>' . check_plain($name) . '</li>';
}
$output .= '</ul>';
$node->content['subdomains'] = array(
'#value' => $output,
'#weight' => 20,
);
}
if (!empty($node->editors)) {
$output = '<p><b>Editors</b></p><ul>';
foreach ($node->editors as $name) {
$output .= '<li>' . check_plain($name) . '</li>';
}
$output .= '</ul>';
$node->content['editors'] = array(
'#value' => $output,
'#weight' => 21,
);
}
if (empty($output)) {
$node->content['domain'] = array(
'#value' => t('This node is not assigned to a domain.'),
'#weight' => 22,
);
}
}
}
break;
case 'insert':
case 'update':
// Store these records in our own table as well.
$grants = domain_node_access_records($node);
_domain_write_records($node->nid, $grants);
break;
case 'delete':
// Remove records from the {domain_access} table.
db_query("DELETE FROM {domain_access} WHERE nid = %d", $node->nid);
break;
}
}