Index: block.module =================================================================== RCS file: /cvs/drupal/drupal/modules/block.module,v retrieving revision 1.148 diff -u -F^f -r1.148 block.module --- block.module 6 Jan 2005 01:17:31 -0000 1.148 +++ block.module 27 Jan 2005 17:04:50 -0000 @@ -152,15 +152,16 @@ function _block_rehash($order_by = array $block['pages'] = $old_blocks[$module][$delta]->pages; $block['custom'] = $old_blocks[$module][$delta]->custom; $block['throttle'] = $old_blocks[$module][$delta]->throttle; + $block['types'] = $old_blocks[$module][$delta]->types; } else { $block['status'] = $block['weight'] = $block['region'] = $block['custom'] = 0; - $block['pages'] = ''; + $block['pages'] = $block['types'] = ''; } // 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']); + db_query("INSERT INTO {blocks} (module, delta, status, weight, region, visibility, pages, custom, throttle, types) VALUES ('%s', '%s', %d, %d, %d, %d, '%s', %d, %d, '%s')", + $block['module'], $block['delta'], $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle'], $block['types']); $blocks[] = $block; @@ -191,7 +192,7 @@ function block_admin_display() { foreach ($blocks as $block) { if ($block['module'] == 'block') { - $operation = l(t('delete'), 'admin/block/delete/'. $block['delta']); + $operation = l(t('delete'), 'admin/block/delete/' . $block['delta']); } else { $operation = ''; @@ -226,7 +227,13 @@ function block_admin_configure($module = 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); + if ($edit['types']) { + $types = implode(',', $edit['types']); + } + else { + $types = ''; + } + db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d, types = '%s' WHERE module = '%s' AND delta = '%s'", $edit['visibility'], $edit['pages'], $edit['custom'], $types, $module, $delta); module_invoke($module, 'block', 'save', $delta, $edit); drupal_set_message('The block configuration has been saved.'); cache_clear_all(); @@ -235,7 +242,7 @@ function block_admin_configure($module = 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)); + $edit = db_fetch_array(db_query("SELECT pages, visibility, custom, types FROM {blocks} WHERE module = '%s' AND delta = '%s'", $module, $delta)); } // Module-specific block configurations. @@ -243,17 +250,22 @@ function block_admin_configure($module = $form = form_group(t('Block-specific settings'), $settings); } + foreach (node_list() as $type) { + $content_types[$type] = node_invoke($type, 'node_name'); + } // 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 = form_radios(t('Show on specific pages'), 'visibility', $edit['visibility'], array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'))); - $group .= form_textarea(t('Pages'), 'pages', $edit['pages'], 40, 5, t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are 'blog' for the blog page and 'blog/*' for every personal blog. '<front>' is the front page. ")); - - $group .= 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_1 = 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.'))); + $group_1 .= form_textarea(t('Pages'), 'pages', $edit['pages'], 40, 5, t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are 'blog' for the blog page and 'blog/*' for every personal blog. '<front>' is the front page. ")); + $group_2 = form_checkboxes(t('Restrict block to specific content types'), 'types', explode(',', $edit['types']), $content_types, t('Selecting one or more content types will cause this block to only be shown on pages of the selected types. This featue works alone or in conjunction with page specific visibility settings. For example, you can specify that a block only appear on book pages in the \'FAQ\' path.'), NULL, FALSE); + $group_3 = 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.')); + $form = form_group(t('Page specific visibility settings'), $group_1); + $form .= form_group(t('Content specific visibility settings'), $group_2); + $form .= form_group(t('Other visibility settings'), $group_3); - $form .= form_group(t('Visibility settings'), $group); $form .= form_submit(t('Save block')); @@ -293,12 +305,12 @@ function block_box_delete($bid = 0) { switch ($op) { case t('Delete'): db_query('DELETE FROM {boxes} WHERE bid = %d', $bid); - drupal_set_message(t('The block %name has been deleted.', array('%name' => ''. $box['info'] .''))); + drupal_set_message(t('The block %name has been deleted.', array('%name' => '' . $box['info'] . ''))); cache_clear_all(); drupal_goto('admin/block'); default: - $form = '

'. t('Are you sure you want to delete the block %name?', array('%name' => ''. $box['info'] .'')) ."

\n"; + $form = '

' . t('Are you sure you want to delete the block %name?', array('%name' => '' . $box['info'] . '')) . "

\n"; $form .= form_submit(t('Delete')); $output = form($form); } @@ -415,13 +427,31 @@ function block_list($region) { if ($block['pages']) { $path = drupal_get_path_alias($_GET['q']); $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. variable_get('site_frontpage', 'node') .'\2'), preg_quote($block['pages'], '/')) .')$/'; - $matched = !($block['visibility'] xor preg_match($regexp, $path)); + $page_match = !($block['visibility'] xor preg_match($regexp, $path)); + } + else { + $page_match = TRUE; + } + // Match node type if necessary + $type_match = FALSE; + if ($block['types'] != '') { + if (arg(0) == 'node' && is_numeric(arg(1))) { + $node = node_load(array('nid' => arg(1))); + $types = explode(',', $block['types']); + //Match on any one selected type + foreach ($types as $type) { + if ($node->type == $type) { + $type_match = TRUE; + break; + } + } + } } else { - $matched = TRUE; + $type_match = TRUE; } - if ($enabled && $matched) { + if ($enabled && $page_match && $type_match) { // Check the current throttle status and see if block should be displayed // based on server load. if (!($block['throttle'] && (module_invoke('throttle', 'status') > 0))) { ***** CVS exited normally with code 1 *****