function _nodesinblock_save in Nodes In Block 6
Same name and namespace in other branches
- 7 nodesinblock.module \_nodesinblock_save()
Function callback: save node settings into nodesinblock table and update block visibility pages.
1 call to _nodesinblock_save()
- nodesinblock_nodeapi in ./
nodesinblock.module - Implementation of hook_nodeapi().
File
- ./
nodesinblock.module, line 344 - Nodes in block makes it possible to add multiple nodes in one block.
Code
function _nodesinblock_save($node, $op) {
// Delete old record.
db_query("DELETE FROM {nodesinblock} WHERE nid = %d", $node->nid);
// Save if node is not deleted
if ($op != 'delete' && $node->nodesinblock_delta != -1) {
$nodeinblock = new stdClass();
$nodeinblock->nid = $node->nid;
$nodeinblock->delta = $node->nodesinblock_delta;
$nodeinblock->weight = $node->nodesinblock_weight;
$nodeinblock->visibility = trim($node->nodesinblock_visibility);
$nodeinblock->render = $node->nodesinblock_render;
drupal_write_record('nodesinblock', $nodeinblock);
}
// Get visibility paths.
$visibility = array();
$result = db_query("SELECT visibility FROM {nodesinblock} nib INNER JOIN {node} n on n.nid = nib.nid WHERE nib.delta = %d AND n.status = 1", $node->nodesinblock_delta);
while ($row = db_fetch_object($result)) {
$node_visibility = explode("\n", $row->visibility);
foreach ($node_visibility as $path) {
$visibility[] = trim($path);
}
}
// Update blocks table.
$visibility = array_unique($visibility);
db_query("UPDATE {blocks} set visibility = %d, pages = '%s' WHERE module = 'nodesinblock' AND delta = %d", variable_get('nodesinblock_visibility_' . $node->nodesinblock_delta, '1'), implode("\n", $visibility), $node->nodesinblock_delta);
}