function _block_rehash in Drupal 5
Same name and namespace in other branches
- 4 modules/block.module \_block_rehash()
- 6 modules/block/block.module \_block_rehash()
- 7 modules/block/block.module \_block_rehash()
Update the 'blocks' DB table with the blocks currently exported by modules.
Return value
Blocks currently exported by modules.
1 call to _block_rehash()
- block_admin_display in modules/
block/ block.module - Generate main block administration form.
File
- modules/
block/ block.module, line 145 - Controls the boxes that are displayed around the main content.
Code
function _block_rehash() {
global $theme_key;
init_theme();
$result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $theme_key);
while ($old_block = db_fetch_object($result)) {
$old_blocks[$old_block->module][$old_block->delta] = $old_block;
}
$blocks = array();
foreach (module_list() as $module) {
$module_blocks = module_invoke($module, 'block', 'list');
if ($module_blocks) {
foreach ($module_blocks as $delta => $block) {
$block['module'] = $module;
$block['delta'] = $delta;
// If previously written to database, load values.
if ($old_blocks[$module][$delta]) {
$block['status'] = $old_blocks[$module][$delta]->status;
$block['weight'] = $old_blocks[$module][$delta]->weight;
$block['region'] = $old_blocks[$module][$delta]->region;
$block['visibility'] = $old_blocks[$module][$delta]->visibility;
$block['pages'] = $old_blocks[$module][$delta]->pages;
$block['custom'] = $old_blocks[$module][$delta]->custom;
$block['throttle'] = $old_blocks[$module][$delta]->throttle;
$block['title'] = $old_blocks[$module][$delta]->title;
}
else {
$properties = array(
'status' => 0,
'weight' => 0,
'region' => 'left',
'pages' => '',
'custom' => 0,
'title' => '',
);
foreach ($properties as $property => $default) {
if (!isset($block[$property])) {
$block[$property] = $default;
}
}
}
$blocks[] = $block;
}
}
}
db_lock_table('blocks');
// Remove all blocks from table.
db_query("DELETE FROM {blocks} WHERE theme = '%s'", $theme_key);
// Reinsert new set of blocks into table.
foreach ($blocks as $block) {
db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, visibility, pages, custom, throttle, title) VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d, '%s')", $block['module'], $block['delta'], $theme_key, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle'], $block['title']);
}
db_unlock_tables();
return $blocks;
}