function nodeblock_nodeapi in Nodeblock 5
Same name and namespace in other branches
- 6 nodeblock.module \nodeblock_nodeapi()
Implementation of hook_nodeapi().
File
- ./
nodeblock.module, line 62
Code
function nodeblock_nodeapi(&$node, $op, $teaser, $page) {
// do nothing if not enabled
if (!nodeblock_type_enabled($node)) {
return;
}
switch ($op) {
case 'prepare':
// add nodeblock info to the node object in preparation for the form
init_theme();
global $theme_key;
$node->nodeblock = db_fetch_array(db_query("SELECT * FROM {blocks} WHERE theme = '%s' AND module='%s' AND delta='%d'", $theme_key, 'nodeblock', $node->nid));
break;
case 'insert':
case 'update':
// only admins can affect block configuration
if (user_access('administer blocks')) {
init_theme();
global $theme_key;
// rehash blocks which will take care of inserting our new nodeblock into
// the blocks table if necessary
_block_rehash();
// build block array and save
$block = $node->nodeblock;
$block['status'] = $block['region'] != BLOCK_REGION_NONE;
$block['region'] = $block['status'] ? $block['region'] : '';
$block['module'] = 'nodeblock';
$block['delta'] = $node->nid;
$block['theme'] = $theme_key;
db_query("UPDATE {blocks} SET status = %d, weight = %d, region = '%s' WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $block['status'], $block['weight'], $block['region'], $block['module'], $block['delta'], $block['theme']);
}
break;
case 'delete':
_block_rehash();
break;
}
}