Blocks are the boxes visible in the sidebar(s) of your web site. These are usually generated automatically by modules (e.g. recent forum topics), but you can also create your own blocks.
The sidebar each block appears in depends on both which theme you are using (some are left-only, some right, some both), and on the settings in block management.
The block management screen lets you specify the vertical sort-order of the blocks within a sidebar. You do this by assigning a weight to each block. Lighter blocks (smaller weight) "float up" towards the top of the sidebar. Heavier ones "sink down" towards the bottom of it.
A block\'s visibility depends on:
An administrator defined block contains content supplied by you (as opposed to being generated automatically by a module). Each admin-defined block consists of a title, a description, and a body which can be as long as you wish. The Drupal engine will render the content of the block.
'); case 'admin/modules#description': return t('Controls the boxes that are displayed around the main content.'); case 'admin/block': return t("Blocks are the boxes in the left and right side bars of the web site. They are made available by modules or created manually.
Only enabled blocks are shown. You can position the blocks by deciding which side of the page they will show up on (sidebar) and in which order they appear (weight).
If you want certain blocks to disable themselves temporarily during high server loads, check the 'Throttle' box. You can configure the auto-throttle on the throttle configuration page after having enabled the throttle module.
", array('%throttle' => url('admin/settings/throttle'))); case 'admin/block/add': return t('Here you can create a new block. Once you have created this block you must make it active and give it a place on the page using blocks. The title is used when displaying the block. The description is used in the "block" column on the blocks page.
', array('%overview' => url('admin/block'))); } } /** * Implementation of hook_perm(). */ function block_perm() { return array('administer blocks'); } /** * Implementation of hook_menu(). */ function block_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array('path' => 'admin/block', 'title' => t('blocks'), 'access' => user_access('administer blocks'), 'callback' => 'block_admin'); $items[] = array('path' => 'admin/block/list', 'title' => t('list'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); $items[] = array('path' => 'admin/block/configure', 'title' => t('configure block'), 'access' => user_access('administer blocks'), 'callback' => 'block_admin_configure', 'type' => MENU_CALLBACK); $items[] = array('path' => 'admin/block/delete', 'title' => t('delete block'), 'access' => user_access('administer blocks'), 'callback' => 'block_box_delete', 'type' => MENU_CALLBACK); $items[] = array('path' => 'admin/block/add', 'title' => t('add block'), 'access' => user_access('administer blocks'), 'callback' => 'block_box_add', 'type' => MENU_LOCAL_TASK); } return $items; } /** * Implementation of hook_block(). * * Generates the administrator-defined blocks for display. */ function block_block($op = 'list', $delta = 0, $edit = array()) { switch ($op) { case 'list': $result = db_query('SELECT bid, title, info FROM {boxes} ORDER BY title'); while ($block = db_fetch_object($result)) { $blocks[$block->bid]['info'] = $block->info ? check_plain($block->info) : check_plain($block->title); } return $blocks; case 'configure': $box = block_box_get($delta); if (filter_access($box['format'])) { return block_box_form($box); } break; case 'save': block_box_save($edit, $delta); break; case 'view': $block = db_fetch_object(db_query('SELECT * FROM {boxes} WHERE bid = %d', $delta)); $data['subject'] = check_plain($block->title); $data['content'] = check_output($block->body, $block->format); return $data; } } function block_admin_save($edit) { foreach ($edit as $module => $blocks) { foreach ($blocks as $delta => $block) { db_query("UPDATE {blocks} SET region = %d, status = %d, weight = %d, throttle = %d WHERE module = '%s' AND delta = '%s'", $block['region'], $block['status'], $block['weight'], $block['throttle'], $module, $delta); } } } /** * Update the 'blocks' DB table with the blocks currently exported by modules. * * @param $order_by php array_multisort() * style sort ordering, eg. "weight", SORT_ASC, SORT_STRING. * * @return * Blocks currently exported by modules, sorted by $order_by. */ function _block_rehash($order_by = array('weight')) { $result = db_query('SELECT * FROM {blocks} '); while ($old_block = db_fetch_object($result)) { $old_blocks[$old_block->module][$old_block->delta] = $old_block; } db_query('DELETE FROM {blocks} '); 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 ($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; } else { $block['status'] = $block['weight'] = $block['region'] = $block['custom'] = 0; $block['pages'] = ''; } // reinsert blocks into table db_query("INSERT INTO {blocks} (module, delta, status, weight, region, visibility, pages, custom, throttle) VALUES ('%s', '%s', %d, %d, %d, %d, '%s', %d, %d)", $block['module'], $block['delta'], $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle']); $blocks[] = $block; // build array to sort on $order[$order_by[0]][] = $block[$order_by[0]]; } } } // sort array_multisort($order[$order_by[0]], $order_by[1] ? $order_by[1] : SORT_ASC, $order_by[2] ? $order_by[2] : SORT_REGULAR, $blocks); return $blocks; } /** * Prepare the main block administration form. */ function block_admin_display() { $blocks = _block_rehash(); $header = array(t('Block'), t('Enabled'), t('Weight'), t('Sidebar')); if (module_exist('throttle')) { $header[] = t('Throttle'); } $header[] = array('data' => t('Operations'), 'colspan' => 2); $left = array(); $right = array(); $disabled = array(); foreach ($blocks as $block) { if ($block['module'] == 'block') { $delete = l(t('delete'), 'admin/block/delete/'. $block['delta']); } else { $delete = ''; } $row = array(array('data' => $block['info'], 'class' => 'block'), form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][status', 1, $block['status']), form_weight(NULL, $block['module'] .']['. $block['delta'] .'][weight', $block['weight']), form_radios(NULL, $block['module'] .']['. $block['delta'] .'][region', $block['region'], array(t('left'), t('right')))); if (module_exist('throttle')) { $row[] = form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][throttle', 1, $block['throttle']); } $row[] = l(t('configure'), 'admin/block/configure/'. $block['module'] .'/'. $block['delta']); $row[] = $delete; if ($block['status']) { if ($block['region'] == 0) { $left[] = $row; } if ($block['region'] == 1) { $right[] = $row; } } else if ($block['region'] <= 1) { $disabled[] = $row; } } $rows = array(); if (count($left)) { $rows[] = array(array('data' => t('Left sidebar'), 'class' => 'region', 'colspan' => (module_exist('throttle') ? 7 : 6))); $rows = array_merge($rows, $left); } if (count($right)) { $rows[] = array(array('data' => t('Right sidebar'), 'class' => 'region', 'colspan' => (module_exist('throttle') ? 7 : 6))); $rows = array_merge($rows, $right); } if (count($disabled)) { $rows[] = array(array('data' => t('Disabled'), 'class' => 'region', 'colspan' => (module_exist('throttle') ? 7 : 6))); $rows = array_merge($rows, $disabled); } $output = theme('table', $header, $rows, array('id' => 'blocks')); $output .= form_submit(t('Save blocks')); return form($output, 'post', url('admin/block')); } function block_box_get($bid) { return db_fetch_array(db_query('SELECT * FROM {boxes} WHERE bid = %d', $bid)); } /** * Menu callback; displays the block configuration form. */ function block_admin_configure($module = NULL, $delta = 0) { $edit = $_POST['edit']; $op = $_POST['op']; switch ($op) { case t('Save block'): db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d WHERE module = '%s' AND delta = '%s'", $edit['visibility'], $edit['pages'], $edit['custom'], $module, $delta); module_invoke($module, 'block', 'save', $delta, $edit); drupal_set_message(t('The block configuration has been saved.')); cache_clear_all(); drupal_goto('admin/block'); default: // Always evaluates to TRUE, but a validation step may be added later. if (!$edit) { $edit = db_fetch_array(db_query("SELECT pages, visibility, custom FROM {blocks} WHERE module = '%s' AND delta = '%s'", $module, $delta)); } // Module-specific block configurations. if ($settings = module_invoke($module, 'block', 'configure', $delta)) { $form = form_group(t('Block specific settings'), $settings); } // Get the block subject for the page title. $info = module_invoke($module, 'block', 'list'); drupal_set_title(t("'%name' block", array('%name' => $info[$delta]['info']))); // Standard block configurations. $group_1 = form_radios(t('Custom visibility settings'), 'custom', $edit['custom'], array(t('Users cannot control whether or not they see this block.'), t('Show this block by default, but let individual users hide it.'), t('Hide this block by default but let individual users show it.')), t('Allow individual users to customize the visibility of this block in their account settings.')); $group_2 = form_radios(t('Show block on specific pages'), 'visibility', $edit['visibility'], array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'), t('Show if the following PHP code returnsTRUE
(PHP-mode, experts only).')));
$group_2 .= form_textarea(t('Pages'), 'pages', $edit['pages'], 70, 5, t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '%blog' for the blog page and %blog1 for every personal blog. %front is the front page. If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.", array('%blog' => theme('placeholder', 'blog'), '%blog1' => theme('placeholder', 'blog/*'), '%front' => theme('placeholder', '