Index: modules/block/block.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.admin.inc,v
retrieving revision 1.42
diff -u -p -r1.42 block.admin.inc
--- modules/block/block.admin.inc	7 Jun 2009 02:29:07 -0000	1.42
+++ modules/block/block.admin.inc	9 Jun 2009 14:24:42 -0000
@@ -252,6 +252,25 @@ function block_admin_configure(&$form_st
     '#description' => t('Show this block only for the selected role(s). If you select no roles, the block will be visible to all users.'),
   );
 
+  // Content type specific configuration.
+  $default_type_options = db_query("SELECT type FROM {block_node_type} WHERE module = :module AND delta = :delta", array(
+    ':module' => $module,
+    ':delta' => $delta,
+  ))->fetchCol();
+  $form['content_type_vis_settings'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Content type specific visibility settings'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+  $form['content_type_vis_settings']['types'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Show block for specific content types'),
+    '#default_value' => $default_type_options,
+    '#options' => node_type_get_names(),
+    '#description' => t('Show this block only when on a page displaying a post of the given type(s). If you select no types, there will be no type specific limitation.'),
+  );
+
   // Standard block configurations.
   $form['user_vis_settings'] = array(
     '#type' => 'fieldset',
@@ -303,6 +322,7 @@ function block_admin_configure_submit($f
       ->condition('module', $form_state['values']['module'])
       ->condition('delta', $form_state['values']['delta'])
       ->execute();
+
     db_delete('block_role')
       ->condition('module', $form_state['values']['module'])
       ->condition('delta', $form_state['values']['delta'])
@@ -316,11 +336,25 @@ function block_admin_configure_submit($f
       ));
     }
     $query->execute();
+
+    db_delete('block_node_type')
+      ->condition('module', $form_state['values']['module'])
+      ->condition('delta', $form_state['values']['delta'])
+      ->execute();
+    $query = db_insert('block_node_type')->fields(array('type', 'module', 'delta'));
+    foreach (array_filter($form_state['values']['types']) as $type) {
+      $query->values(array(
+        'type' => $type,
+        'module' => $form_state['values']['module'],
+        'delta' => $form_state['values']['delta'],
+      ));
+    }
+    $query->execute();
+
     module_invoke($form_state['values']['module'], 'block_save', $form_state['values']['delta'], $form_state['values']);
     drupal_set_message(t('The block configuration has been saved.'));
     cache_clear_all();
     $form_state['redirect'] = 'admin/build/block';
-    return;
   }
 }
 
@@ -380,9 +414,18 @@ function block_add_block_form_submit($fo
   }
   $query->execute();
 
+  $query = db_insert('block_node_type')->fields(array('type', 'module', 'delta'));
+  foreach (array_filter($form_state['values']['types']) as $type) {
+    $query->values(array(
+      'type' => $type,
+      'module' => $form_state['values']['module'],
+      'delta' => $delta,
+    ));
+  }
+  $query->execute();
+
   drupal_set_message(t('The block has been created.'));
   cache_clear_all();
-
   $form_state['redirect'] = 'admin/build/block';
 }
 
Index: modules/block/block.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.install,v
retrieving revision 1.27
diff -u -p -r1.27 block.install
--- modules/block/block.install	28 May 2009 11:31:20 -0000	1.27
+++ modules/block/block.install	9 Jun 2009 14:24:42 -0000
@@ -131,6 +131,34 @@ function block_schema() {
     ),
   );
 
+  $schema['block_node_type'] = array(
+    'description' => 'Sets up display criteria for blocks based on content types',
+    'fields' => array(
+      'module' => array(
+        'type' => 'varchar',
+        'length' => 64,
+        'not null' => TRUE,
+        'description' => "The block's origin module, from {block}.module.",
+      ),
+      'delta' => array(
+        'type' => 'varchar',
+        'length' => 32,
+        'not null' => TRUE,
+        'description' => "The block's unique delta within module, from {block}.delta.",
+      ),
+      'type' => array(
+        'type' => 'varchar',
+        'length' => 32,
+        'not null' => TRUE,
+        'description' => "The machine-readable name of this type from {node_type}.type.",
+      ),
+    ),
+    'primary key' => array('module', 'delta', 'type'),
+    'indexes' => array(
+      'type' => array('type'),
+    ),
+  );
+
   $schema['box'] = array(
     'description' => 'Stores contents of custom-made blocks.',
     'fields' => array(
Index: modules/block/block.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.module,v
retrieving revision 1.344
diff -u -p -r1.344 block.module
--- modules/block/block.module	8 Jun 2009 09:23:50 -0000	1.344
+++ modules/block/block.module	9 Jun 2009 14:27:47 -0000
@@ -613,8 +613,8 @@ function _block_load_blocks() {
 /**
  * Implement hook_block_list_alter().
  *
- * Check the page, role and user specific visibilty settings. Remove the block
- * if the visibility conditions are not met.
+ * Check the page, user role, content type and user specific visibilty settings.
+ * Remove the block if the visibility conditions are not met.
  */
 function block_block_list_alter(&$blocks) {
   global $user, $theme_key;
@@ -626,6 +626,13 @@ function block_block_list_alter(&$blocks
     $block_roles[$record->module][$record->delta][] = $record->rid;
   }
 
+  // Build an array of node types for each block.
+  $block_node_types = array();
+  $result = db_query('SELECT module, delta, type FROM {block_node_type}');
+  foreach ($result as $record) {
+    $block_node_types[$record->module][$record->delta][] = $record->type;
+  }
+
   foreach ($blocks as $key => $block) {
     if ($block->theme != $theme_key || $block->status != 1) {
       // This block was added by a contrib module, leave it in the list.
@@ -635,14 +642,39 @@ function block_block_list_alter(&$blocks
     // If a block has no roles associated, it is displayed for every role.
     // For blocks with roles associated, if none of the user's roles matches
     // the settings from this block, remove it from the block list.
-    if (!isset($block_roles[$block->module][$block->delta])) {
-      // No roles associated.
-    }
-    elseif (!array_intersect($block_roles[$block->module][$block->delta], array_keys($user->roles))) {
+    if (isset($block_roles[$block->module][$block->delta]) && !array_intersect($block_roles[$block->module][$block->delta], array_keys($user->roles))) {
       // No match.
       unset($blocks[$key]);
       continue;
-     }
+    }
+
+    // If a block has no node types associated, it is displayed for every type.
+    // For blocks with node types associated, if the node type does not match
+    // the settings from this block, remove it from the block list.
+    if (isset($block_node_types[$block->module][$block->delta])) {
+      $node = menu_get_object();
+      if (!empty($node)) {
+        // This is a node or node edit page.
+        if (!in_array($node->type, $block_node_types[$block->module][$block->delta])) {
+          // This block should not be displayed for this node type.
+          unset($blocks[$key]);
+          continue;
+        }
+      }
+      elseif (arg(0) == 'node' && arg(1) == 'add' && in_array(arg(2), array_keys(node_type_get_types()))) {
+        // This is a node creation page
+        if (!in_array(arg(2), $block_node_types[$block->module][$block->delta])) {
+          // This block should not be displayed for this node type.
+          unset($blocks[$key]);
+          continue;
+        }
+      }
+      else {
+        // This is not a node page, remove the block.
+        unset($blocks[$key]);
+        continue;
+      }
+    }
 
     // Use the user's block visibility setting, if necessary.
     if ($block->custom != 0) {
