2 // $Id: block.module,v 1.246.2.6 2007/09/12 07:49:35 drumm Exp $
6 * Controls the boxes that are displayed around the main content.
10 * Denotes that a block is not enabled in any region and should not
13 define('BLOCK_REGION_NONE', -1);
16 * Implementation of hook_help().
18 function block_help($section) {
20 case 'admin/help#block':
21 $output = '<p>'. t('Blocks are boxes of content that may be rendered into certain regions of your web pages, for example, into sidebars. Blocks are usually generated automatically by modules (e.g., Recent Forum Topics), but administrators can also define custom blocks.') .'</p>';
22 $output .= '<p>'. t('The region each block appears in depends on both which theme you are using (some themes allow greater control over block placement than others), and on the settings in the block administration section.') .'</p>';
23 $output .= '<p>'. t('The block administration screen lets you specify the vertical placement of the blocks within a region. You do this by assigning a weight to each block. Lighter blocks (those having a smaller weight) "float up" towards the top of the region; heavier ones "sink".') .'</p>';
24 $output .= t("<p>A block's visibility depends on:</p>
26 <li>Its region placement. Blocks with no region assigned to them are never shown.</li>
27 <li>Its throttle checkbox when throttle module is enabled. Throttled blocks are hidden during high server loads.</li>
28 <li>Its page visibility settings. Blocks can be configured to be visible/hidden on certain pages.</li>
29 <li>Its custom visibility settings. Blocks can be configured to be visible only when specific conditions are true.</li>
30 <li>Its user visibility settings. Administrators can choose to let users decide whether to show/hide certain blocks.</li>
31 <li>Its user-role visibility settings. Administrators can choose to let blocks be visible only for certain user roles.</li>
32 <li>Its function. Some dynamic blocks, such as those generated by modules, will be displayed only on certain pages.</li>
35 $output .= '<h3>'. t('Module blocks') .'</h3>';
36 $output .= '<p>'. t('Some modules generate blocks that become available when the modules are enabled. These blocks can be administered via the <a href="@admin-block">blocks administration page</a>.</p>', array('@admin-block' => url('admin/build/block'))) .'</p>';
37 $output .= '<h3>'. t('Administrator defined blocks') .'</h3>';
38 $output .= '<p>'. t('Administrators can also define custom blocks. These blocks consist of a title, a description, and a body which can be as long as you wish. Block content can be in any of the input formats supported for other content.') .'</p>';
39 $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="@block">Block page</a>.', array('@block' => 'http://drupal.org/handbook/modules/block/')) .'</p>';
41 case 'admin/build/block':
42 return t('<p>Blocks are boxes of content that may be rendered into certain regions of your web pages, for example, into sidebars. They are usually generated automatically by modules, but administrators can create blocks manually.</p>
43 <p>Only enabled blocks are shown. You can position blocks by specifying which area of the page they should appear in (e.g., a sidebar). Highlighted labels on this page show the regions into which blocks can be rendered. You can specify where within a region a block will appear by adjusting its weight.</p>
44 <p>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 <a href="@throttle">throttle configuration page</a> after having enabled the throttle module.</p>
45 <p>You can configure the behaviour of each block (for example, specifying on which pages and for what users it will appear) by clicking the "configure" link for each block.</p>', array('@throttle' => url('admin/settings/throttle')));
46 case 'admin/build/block/add':
47 return '<p>'. 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 <a href="@overview">blocks</a>. The description is used in the "block" column on the <a href="@overview">blocks</a> page.', array('@overview' => url('admin/build/block'))) .'</p>';
52 * Implementation of hook_perm().
54 function block_perm() {
55 return array('administer blocks', 'use PHP for block visibility');
59 * Implementation of hook_menu().
61 function block_menu($may_cache) {
66 'path' => 'admin/build/block',
67 'title' => t('Blocks'),
68 'access' => user_access('administer blocks'),
69 'description' => t('Configure what block content appears in your site\'s sidebars and other regions.'),
70 'callback' => 'drupal_get_form',
71 'callback arguments' => array('block_admin_display'));
72 $items[] = array('path' => 'admin/build/block/list', 'title' => t('List'),
73 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
74 $items[] = array('path' => 'admin/build/block/configure', 'title' => t('Configure block'),
75 'access' => user_access('administer blocks'),
76 'callback' => 'drupal_get_form',
77 'callback arguments' => array('block_admin_configure'),
78 'type' => MENU_CALLBACK);
79 $items[] = array('path' => 'admin/build/block/delete', 'title' => t('Delete block'),
80 'access' => user_access('administer blocks'),
81 'callback' => 'drupal_get_form',
82 'callback arguments' => array('block_box_delete'),
83 'type' => MENU_CALLBACK);
84 $items[] = array('path' => 'admin/build/block/add', 'title' => t('Add block'),
85 'access' => user_access('administer blocks'),
86 'callback' => 'drupal_get_form',
87 'callback arguments' => array('block_box_form'),
88 'type' => MENU_LOCAL_TASK);
89 $default = variable_get('theme_default', 'garland');
90 foreach (list_themes() as $key => $theme) {
92 'path' => 'admin/build/block/list/'. $key,
93 'title' => t('!key settings', array('!key' => $key)),
94 'callback' => 'drupal_get_form',
95 'callback arguments' => array('block_admin_display', $key),
96 'access' => user_access('administer blocks'),
97 'type' => $key == $default ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
98 'weight' => $key == $default ? -10 : 0,
107 * Implementation of hook_block().
109 * Generates the administrator-defined blocks for display.
111 function block_block($op = 'list', $delta = 0, $edit = array()) {
116 $result = db_query('SELECT bid, info FROM {boxes} ORDER BY info');
117 while ($block = db_fetch_object($result)) {
118 $blocks[$block->bid]['info'] = $block->info;
123 $box = block_box_get($delta);
124 if (filter_access($box['format'])) {
125 return block_box_form($box);
130 block_box_save($edit, $delta);
134 $block = db_fetch_object(db_query('SELECT body, format FROM {boxes} WHERE bid = %d', $delta));
135 $data['content'] = check_markup($block->body, $block->format, FALSE);
141 * Update the 'blocks' DB table with the blocks currently exported by modules.
144 * Blocks currently exported by modules.
146 function _block_rehash() {
151 $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $theme_key);
152 while ($old_block = db_fetch_object($result)) {
153 $old_blocks[$old_block->module][$old_block->delta] = $old_block;
158 foreach (module_list() as $module) {
159 $module_blocks = module_invoke($module, 'block', 'list');
160 if ($module_blocks) {
161 foreach ($module_blocks as $delta => $block) {
162 $block['module'] = $module;
163 $block['delta'] = $delta;
164 // If previously written to database, load values.
165 if ($old_blocks[$module][$delta]) {
166 $block['status'] = $old_blocks[$module][$delta]->status;
167 $block['weight'] = $old_blocks[$module][$delta]->weight;
168 $block['region'] = $old_blocks[$module][$delta]->region;
169 $block['visibility'] = $old_blocks[$module][$delta]->visibility;
170 $block['pages'] = $old_blocks[$module][$delta]->pages;
171 $block['custom'] = $old_blocks[$module][$delta]->custom;
172 $block['throttle'] = $old_blocks[$module][$delta]->throttle;
173 $block['title'] = $old_blocks[$module][$delta]->title;
175 // Otherwise, use any set values, or else substitute defaults.
177 $properties = array('status' => 0, 'weight' => 0, 'region' => 'left', 'pages' => '', 'custom' => 0, 'title' => '');
178 foreach ($properties as $property => $default) {
179 if (!isset($block[$property])) {
180 $block[$property] = $default;
190 db_lock_table('blocks');
191 // Remove all blocks from table.
192 db_query("DELETE FROM {blocks} WHERE theme = '%s'", $theme_key);
194 // Reinsert new set of blocks into table.
195 foreach ($blocks as $block) {
196 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']);
204 * Generate main block administration form.
206 function block_admin_display($theme = NULL) {
207 global $theme_key, $custom_theme;
210 drupal_add_css(drupal_get_path('module', 'block') .'/block.css', 'module', 'all', FALSE);
212 // If non-default theme configuration has been selected, set the custom theme.
214 $custom_theme = $theme;
217 $custom_theme = variable_get('theme_default', 'garland');
221 // Fetch and sort blocks
222 $blocks = _block_rehash();
223 usort($blocks, '_block_compare');
225 $throttle = module_exists('throttle');
226 $block_regions = array(BLOCK_REGION_NONE => '<'. t('none') .'>') + system_region_list($theme_key);
229 $form['#action'] = arg(3) ? url('admin/build/block/list/'. $theme_key) : url('admin/build/block');
230 $form['#tree'] = TRUE;
231 foreach ($blocks as $i => $block) {
232 $form[$i]['module'] = array('#type' => 'value', '#value' => $block['module']);
233 $form[$i]['delta'] = array('#type' => 'value', '#value' => $block['delta']);
234 $form[$i]['info'] = array('#value' => check_plain($block['info']));
235 $form[$i]['theme'] = array('#type' => 'hidden', '#value' => $theme_key);
236 $form[$i]['weight'] = array('#type' => 'weight', '#default_value' => $block['weight']);
237 $form[$i]['region'] = array('#type' => 'select',
238 '#default_value' => $block['status'] ? (isset($block['region']) ? $block['region'] : system_default_region($theme_key)) : BLOCK_REGION_NONE,
239 '#options' => $block_regions,
243 $form[$i]['throttle'] = array('#type' => 'checkbox', '#default_value' => $block['throttle']);
245 $form[$i]['configure'] = array('#value' => l(t('configure'), 'admin/build/block/configure/'. $block['module'] .'/'. $block['delta']));
246 if ($block['module'] == 'block') {
247 $form[$i]['delete'] = array('#value' => l(t('delete'), 'admin/build/block/delete/'. $block['delta']));
250 $form['submit'] = array('#type' => 'submit', '#value' => t('Save blocks'));
256 * Helper function for sorting blocks on admin/build/block.
258 * Active blocks are sorted by region, then by weight.
259 * Disabled blocks are sorted by name.
261 function _block_compare($a, $b) {
262 $status = $b['status'] - $a['status'];
263 // Separate enabled from disabled.
269 $place = strcmp($a['region'], $b['region']);
270 return $place ? $place : ($a['weight'] - $b['weight']);
274 return strcmp($a['info'], $b['info']);
279 * Process main block administration form submission.
281 function block_admin_display_submit($form_id, $form_values) {
282 foreach ($form_values as $block) {
283 $block['status'] = $block['region'] != BLOCK_REGION_NONE;
284 $block['region'] = $block['status'] ? $block['region'] : '';
285 db_query("UPDATE {blocks} SET status = %d, weight = %d, region = '%s', throttle = %d WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $block['status'], $block['weight'], $block['region'], isset($block['throttle']) ? $block['throttle'] : 0, $block['module'], $block['delta'], $block['theme']);
287 drupal_set_message(t('The block settings have been updated.'));
292 * Theme main block administration form submission.
294 * Note: the blocks are already sorted in the right order,
295 * grouped by status, region and weight.
297 function theme_block_admin_display($form) {
300 $throttle = module_exists('throttle');
301 $block_regions = system_region_list($theme_key);
303 // Highlight regions on page to provide visual reference.
304 foreach ($block_regions as $key => $value) {
305 drupal_set_content($key, '<div class="block-region">'. $value .'</div>');
312 foreach (element_children($form) as $i) {
314 // Only take form elements that are blocks.
315 if (is_array($block['info'])) {
317 $region = $block['region']['#default_value'];
318 $status = $region != BLOCK_REGION_NONE;
320 // Output region header
321 if ($status && $region != $last_region) {
322 $region_title = t('@region', array('@region' => drupal_ucfirst($block_regions[$region])));
323 $rows[] = array(array('data' => $region_title, 'class' => 'region', 'colspan' => ($throttle ? 7 : 6)));
324 $last_region = $region;
326 // Output disabled header
327 elseif ($status != $last_status) {
328 $rows[] = array(array('data' => t('Disabled'), 'class' => 'region', 'colspan' => ($throttle ? 7 : 6)));
329 $last_status = $status;
332 // Generate block row
334 array('data' => drupal_render($block['info']), 'class' => 'block'),
335 drupal_render($block['region']) . drupal_render($block['theme']),
336 drupal_render($block['weight']),
339 $row[] = drupal_render($block['throttle']);
341 $row[] = drupal_render($block['configure']);
342 $row[] = $block['delete'] ? drupal_render($block['delete']) : '';
348 $header = array(t('Block'), t('Region'), t('Weight'));
350 $header[] = t('Throttle');
352 $header[] = array('data' => t('Operations'), 'colspan' => 2);
354 $output = theme('table', $header, $rows, array('id' => 'blocks'));
356 $output .= drupal_render($form);
361 function block_box_get($bid) {
362 return db_fetch_array(db_query("SELECT bx.*, bl.title FROM {boxes} bx INNER JOIN {blocks} bl ON bx.bid = bl.delta WHERE bl.module = 'block' AND bx.bid = %d", $bid));
366 * Menu callback; displays the block configuration form.
368 function block_admin_configure($module = NULL, $delta = 0) {
370 $form['module'] = array('#type' => 'value', '#value' => $module);
371 $form['delta'] = array('#type' => 'value', '#value' => $delta);
373 $edit = db_fetch_array(db_query("SELECT pages, visibility, custom, title FROM {blocks} WHERE module = '%s' AND delta = '%s'", $module, $delta));
375 $form['block_settings'] = array(
376 '#type' => 'fieldset',
377 '#title' => t('Block specific settings'),
378 '#collapsible' => TRUE,
380 $form['block_settings']['title'] = array(
381 '#type' => 'textfield',
382 '#title' => t('Block title'),
384 '#description' => $module == 'block' ? t('The title of the block as shown to the user.') : t('Override the default title for the block. Use <em><none></em> to display no title, or leave blank to use the default block title.'),
385 '#default_value' => $edit['title'],
390 // Module-specific block configurations.
391 if ($settings = module_invoke($module, 'block', 'configure', $delta)) {
392 foreach ($settings as $k => $v) {
393 $form['block_settings'][$k] = $v;
397 // Get the block subject for the page title.
398 $info = module_invoke($module, 'block', 'list');
399 drupal_set_title(t("'%name' block", array('%name' => $info[$delta]['info'])));
401 // Standard block configurations.
402 $form['user_vis_settings'] = array(
403 '#type' => 'fieldset',
404 '#title' => t('User specific visibility settings'),
405 '#collapsible' => TRUE,
407 $form['user_vis_settings']['custom'] = array(
409 '#title' => t('Custom visibility settings'),
411 t('Users cannot control whether or not they see this block.'),
412 t('Show this block by default, but let individual users hide it.'),
413 t('Hide this block by default but let individual users show it.')
415 '#description' => t('Allow individual users to customize the visibility of this block in their account settings.'),
416 '#default_value' => $edit['custom'],
419 // Role-based visibility settings
420 $default_role_options = array();
421 $result = db_query("SELECT rid FROM {blocks_roles} WHERE module = '%s' AND delta = '%s'", $module, $delta);
422 while ($role = db_fetch_object($result)) {
423 $default_role_options[] = $role->rid;
425 $result = db_query('SELECT rid, name FROM {role} ORDER BY name');
426 $role_options = array();
427 while ($role = db_fetch_object($result)) {
428 $role_options[$role->rid] = $role->name;
430 $form['role_vis_settings'] = array(
431 '#type' => 'fieldset',
432 '#title' => t('Role specific visibility settings'),
433 '#collapsible' => TRUE,
435 $form['role_vis_settings']['roles'] = array(
436 '#type' => 'checkboxes',
437 '#title' => t('Show block for specific roles'),
438 '#default_value' => $default_role_options,
439 '#options' => $role_options,
440 '#description' => t('Show this block only for the selected role(s). If you select no roles, the block will be visible to all users.'),
443 $form['page_vis_settings'] = array(
444 '#type' => 'fieldset',
445 '#title' => t('Page specific visibility settings'),
446 '#collapsible' => TRUE,
448 $access = user_access('use PHP for block visibility');
450 if ($edit['visibility'] == 2 && !$access) {
451 $form['page_vis_settings'] = array();
452 $form['page_vis_settings']['visibility'] = array('#type' => 'value', '#value' => 2);
453 $form['page_vis_settings']['pages'] = array('#type' => 'value', '#value' => $edit['pages']);
456 $options = array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'));
457 $description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>'));
460 $options[] = t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).');
461 $description .= ' '. t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '<?php ?>'));
463 $form['page_vis_settings']['visibility'] = array(
465 '#title' => t('Show block on specific pages'),
466 '#options' => $options,
467 '#default_value' => $edit['visibility'],
469 $form['page_vis_settings']['pages'] = array(
470 '#type' => 'textarea',
471 '#title' => t('Pages'),
472 '#default_value' => $edit['pages'],
473 '#description' => $description,
477 $form['submit'] = array(
479 '#value' => t('Save block'),
485 function block_admin_configure_validate($form_id, $form_values) {
486 if ($form_values['module'] == 'block') {
487 if (empty($form_values['info']) || db_num_rows(db_query("SELECT bid FROM {boxes} WHERE bid != %d AND info = '%s'", $form_values['delta'], $form_values['info']))) {
488 form_set_error('info', t('Please ensure that each block description is unique.'));
493 function block_admin_configure_submit($form_id, $form_values) {
494 if (!form_get_errors()) {
495 db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d, title = '%s' WHERE module = '%s' AND delta = '%s'", $form_values['visibility'], trim($form_values['pages']), $form_values['custom'], $form_values['title'], $form_values['module'], $form_values['delta']);
496 db_query("DELETE FROM {blocks_roles} WHERE module = '%s' AND delta = '%s'", $form_values['module'], $form_values['delta']);
497 foreach (array_filter($form_values['roles']) as $rid) {
498 db_query("INSERT INTO {blocks_roles} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_values['module'], $form_values['delta']);
500 module_invoke($form_values['module'], 'block', 'save', $form_values['delta'], $form_values);
501 drupal_set_message(t('The block configuration has been saved.'));
503 return 'admin/build/block';
507 function block_box_form_validate($form_id, $form_values) {
508 if (empty($form_values['info']) || db_num_rows(db_query("SELECT info FROM {boxes} WHERE info = '%s'", $form_values['info']))) {
509 form_set_error('info', t('Please ensure that each block description is unique.'));
513 function block_box_form_submit($form_id, $form_values) {
514 if (!form_get_errors()) {
515 if (block_box_save($form_values)) {
516 drupal_set_message(t('The block has been created.'));
517 return 'admin/build/block';
523 * Menu callback; confirm deletion of custom blocks.
525 function block_box_delete($bid = 0) {
526 $box = block_box_get($bid);
527 $form['info'] = array('#type' => 'hidden', '#value' => $box['info'] ? $box['info'] : $box['title']);
528 $form['bid'] = array('#type' => 'hidden', '#value' => $bid);
530 return confirm_form($form, t('Are you sure you want to delete the block %name?', array('%name' => $box['info'])), 'admin/build/block', '', t('Delete'), t('Cancel'));
534 * Deletion of custom blocks.
536 function block_box_delete_submit($form_id, $form_values) {
537 db_query('DELETE FROM {boxes} WHERE bid = %d', $form_values['bid']);
538 db_query("DELETE FROM {blocks} WHERE module = 'block' AND delta = %d", $form_values['bid']);
539 drupal_set_message(t('The block %name has been removed.', array('%name' => $form_values['info'])));
541 return 'admin/build/block';
544 function block_box_form($edit = array()) {
545 $form['info'] = array(
546 '#type' => 'textfield',
547 '#title' => t('Block description'),
548 '#default_value' => $edit['info'],
550 '#description' => t('A brief description of your block. Used on the <a href="@overview">block overview page</a>.', array('@overview' => url('admin/build/block'))),
554 $form['body_filter']['#weight'] = -17;
555 $form['body_filter']['body'] = array(
556 '#type' => 'textarea',
557 '#title' => t('Block body'),
558 '#default_value' => $edit['body'],
560 '#description' => t('The content of the block as shown to the user.'),
563 if (!isset($edit['format'])) {
564 $edit['format'] = FILTER_FORMAT_DEFAULT;
566 $form['body_filter']['format'] = filter_form($edit['format'], -16);
567 $form['submit'] = array('#type' => 'submit', '#value' => t('Save block'));
572 function block_box_save($edit, $delta = NULL) {
573 if (!filter_access($edit['format'])) {
574 $edit['format'] = FILTER_FORMAT_DEFAULT;
578 db_query("UPDATE {boxes} SET body = '%s', info = '%s', format = %d WHERE bid = %d", $edit['body'], $edit['info'], $edit['format'], $delta);
581 db_query("INSERT INTO {boxes} (body, info, format) VALUES ('%s', '%s', %d)", $edit['body'], $edit['info'], $edit['format']);
587 * Implementation of hook_user().
589 * Allow users to decide which custom blocks to display when they visit
592 function block_user($type, $edit, &$user, $category = NULL) {
596 if ($category == 'account') {
597 $rids = array_keys($user->roles);
598 $placeholders = implode(',', array_fill(0, count($rids), '%d'));
599 $result = db_query("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.status = 1 AND b.custom != 0 AND (r.rid IN ($placeholders) OR r.rid IS NULL) ORDER BY b.weight, b.module", $rids);
600 $form['block'] = array('#type' => 'fieldset', '#title' => t('Block configuration'), '#weight' => 3, '#collapsible' => TRUE, '#tree' => TRUE);
601 while ($block = db_fetch_object($result)) {
602 $data = module_invoke($block->module, 'block', 'list');
603 if ($data[$block->delta]['info']) {
605 $form['block'][$block->module][$block->delta] = array('#type' => 'checkbox', '#title' => check_plain($data[$block->delta]['info']), '#default_value' => isset($user->block[$block->module][$block->delta]) ? $user->block[$block->module][$block->delta] : ($block->custom == 1));
616 if (!$edit['block']) {
617 $edit['block'] = array();
624 * Return all blocks in the specified region for the current user.
627 * The name of a region.
630 * An array of block objects, indexed with <i>module</i>_<i>delta</i>.
631 * If you are displaying your blocks in one or two sidebars, you may check
632 * whether this array is empty to see how many columns are going to be
636 * Add a proper primary key (bid) to the blocks table so we don't have
637 * to mess around with this <i>module</i>_<i>delta</i> construct.
638 * Currently, the blocks table has no primary key defined!
640 function block_list($region) {
641 global $user, $theme_key;
643 static $blocks = array();
645 if (!count($blocks)) {
646 $rids = array_keys($user->roles);
647 $placeholders = implode(',', array_fill(0, count($rids), '%d'));
648 $result = db_query("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.theme = '%s' AND b.status = 1 AND (r.rid IN ($placeholders) OR r.rid IS NULL) ORDER BY b.region, b.weight, b.module", array_merge(array($theme_key), $rids));
649 while ($block = db_fetch_object($result)) {
650 if (!isset($blocks[$block->region])) {
651 $blocks[$block->region] = array();
653 // Use the user's block visibility setting, if necessary
654 if ($block->custom != 0) {
655 if ($user->uid && isset($user->block[$block->module][$block->delta])) {
656 $enabled = $user->block[$block->module][$block->delta];
659 $enabled = ($block->custom == 1);
666 // Match path if necessary
668 if ($block->visibility < 2) {
669 $path = drupal_get_path_alias($_GET['q']);
670 $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($block->pages, '/')) .')$/';
671 // Compare with the internal and path alias (if any).
672 $page_match = preg_match($regexp, $path);
673 if ($path != $_GET['q']) {
674 $page_match = $page_match || preg_match($regexp, $_GET['q']);
676 // When $block->visibility has a value of 0, the block is displayed on
677 // all pages except those listed in $block->pages. When set to 1, it
678 // is displayed only on those pages listed in $block->pages.
679 $page_match = !($block->visibility xor $page_match);
682 $page_match = drupal_eval($block->pages);
689 if ($enabled && $page_match) {
690 // Check the current throttle status and see if block should be displayed
691 // based on server load.
692 if (!($block->throttle && (module_invoke('throttle', 'status') > 0))) {
693 $array = module_invoke($block->module, 'block', 'view', $block->delta);
694 if (isset($array) && is_array($array)) {
695 foreach ($array as $k => $v) {
700 if (isset($block->content) && $block->content) {
701 // Override default block title if a custom display title is present.
703 // Check plain here to allow module generated titles to keep any markup.
704 $block->subject = $block->title == '<none>' ? '' : check_plain($block->title);
706 $blocks[$block->region]["{$block->module}_{$block->delta}"] = $block;
711 // Create an empty array if there were no entries
712 if (!isset($blocks[$region])) {
713 $blocks[$region] = array();
715 return $blocks[$region];