Index: cck_blocks.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck_blocks/Attic/cck_blocks.install,v
retrieving revision 1.1.2.5
diff -u -p -r1.1.2.5 cck_blocks.install
--- cck_blocks.install	4 Nov 2009 21:32:51 -0000	1.1.2.5
+++ cck_blocks.install	22 Jan 2010 16:22:00 -0000
@@ -9,3 +9,26 @@ function cck_blocks_update_6000() {
   $ret[] = update_sql("UPDATE {blocks} SET cache = -1 WHERE module = 'cck_blocks' AND cache = 1");
   return $ret;
 }
+
+/**
+ * Implementation of hook_update_N().
+ *
+ * In previous versions, all fields were exposed as blocks. In this version, fields
+ * are not exposed by default, but can be added manually in the field configuration 
+ * page. This update sets globabl preferences to retain the availability of all
+ * custom fields as blocks.
+ */
+function cck_blocks_update_6101() {
+  $ret = array();
+  $fields = module_invoke('content', 'fields');
+
+	if (count($fields)) {
+	  foreach($fields as $field_name => $field_info) {
+	    variable_set('cck_blocks_' . $field_info['field_name'] . '_block_availability', '2');
+	  }
+  }
+  
+  return $ret;
+}
+
+
Index: cck_blocks.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck_blocks/cck_blocks.module,v
retrieving revision 1.2.2.9
diff -u -p -r1.2.2.9 cck_blocks.module
--- cck_blocks.module	19 Jan 2010 12:19:03 -0000	1.2.2.9
+++ cck_blocks.module	22 Jan 2010 16:22:00 -0000
@@ -1,20 +1,24 @@
 <?php
 // $Id: cck_blocks.module,v 1.2.2.9 2010/01/19 12:19:03 forschi Exp $
 
+define('CCK_BLOCKS_FIELD_BLOCK_DISABLED', 1);
+define('CCK_BLOCKS_FIELD_BLOCK_ENABLED', 2);
+define('CCK_BLOCKS_FIELD_BLOCK_INHERIT', 3);
+
 /**
  * Implementation of hook_content_build_modes().
  */
-function cck_blocks_content_build_modes() {
+ function cck_blocks_content_build_modes() {
   return array(
+  'cck_blocks' => array(
+    'title' => t('CCK Blocks'),
+    'build modes' => array(
     'cck_blocks' => array(
       'title' => t('CCK Blocks'),
-      'build modes' => array(
-        'cck_blocks' => array(
-          'title' => t('CCK Blocks'),
-          'views style' => FALSE,
-        ),
-      ),
+      'views style' => FALSE,
+    ),
     ),
+  ),
   );
 }
 
@@ -28,94 +32,193 @@ function cck_blocks_block($op = 'list', 
 
   switch ($op) {
 
-    case 'list':
-      $blocks = array();
-    
+  case 'list':
+    $blocks = array();
       if (count($fields)) {
         foreach($fields as $field_name => $field_info) {
-          $blocks[$field_name] = array(
-            'info' => 'CCK: '.($field_info['widget']['label'] ? $field_info['widget']['label'] : $field_name),
-            'cache' => BLOCK_NO_CACHE,
-          );
+          if (_cck_blocks_check_field_settings($field_info)) {
+            $blocks[$field_name] = array(
+              'info' => 'CCK: '.($field_info['widget']['label'] ? $field_info['widget']['label'] : $field_name),
+              'cache' => BLOCK_NO_CACHE,
+            );
+          }
         }
       }
-      return $blocks;
+    return $blocks;
+  
+  case 'configure':
+    // add token help, if token module is installed
+    if (module_exists('token')) {
+    $form = array();
+    $form['view']['token_help'] = array(
+      '#title' => t('Replacement patterns'),
+      '#type' => 'fieldset',
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+      '#description' => t('Prefer raw-text replacements for text to avoid problems with HTML entities!'),
+    );
+
+    $form['view']['token_help']['help'] = array(
+      '#value' => theme('token_help', 'node'),
+    );
+    return $form;
+    }
+
+  case 'view':
+    $block = array();
+  
+    if (arg(0) == 'node' && is_numeric(arg(1)) && !arg(2) && $fields[$delta]) {
+    $nid = arg(1);
+    if (!isset($built_nodes[$nid])) {
+      // Build the node in the cck_blocks mode. This is based on node_build_content().
+      $node = node_load($nid);
+      $node->build_mode = 'cck_blocks';
+
+      // Remove the delimiter (if any) that separates the teaser from the body.
+      $node->body = isset($node->body) ? str_replace('<!--break-->', '', $node->body) : '';
+
+      // The 'view' hook can be implemented to overwrite the default function
+      // to display nodes.
+      if (node_hook($node, 'view')) {
+      $node = node_invoke($node, 'view', $teaser, $page);
+      }
+      else {
+      $node = node_prepare($node, $teaser);
+      }
+
+      // Allow modules to make their own additions to the node.
+      node_invoke_nodeapi($node, 'view', $teaser, $page);
+      $built_nodes[$nid] = $node;
+    }
+    
+    // If the block is disabled globally or specifically for this content type, return (don't display)
+    if (_cck_blocks_display_test($built_nodes[$nid]->type, $delta)) {
+      return;
+    }
     
-    case 'configure':
-      // add token help, if token module is installed
+    // look directly for the cck_field in the content array
+    $cck_field_data = false;
+    if (isset($built_nodes[$nid]->content[$delta])) {
+      $cck_field_data = $built_nodes[$nid]->content[$delta];
+    }
+    else {
+      // cycle through all content data arrays looking for cck groups
+      // the cck_field may be within a group
+      foreach ($built_nodes[$nid]->content as $key => $data) {
+	      if ((strpos($key, 'group_') == 0) && isset($data['group'][$delta])) {
+	        // yay it's a group
+	        $cck_field_data = $data['group'][$delta];
+	      }
+      }
+    }
+
+    if ($cck_field_data) {
+      // evaluate tokens, if token module is installed
       if (module_exists('token')) {
-        $form = array();
-        $form['view']['token_help'] = array(
-          '#title' => t('Replacement patterns'),
-          '#type' => 'fieldset',
-          '#collapsible' => TRUE,
-          '#collapsed' => TRUE,
-          '#description' => t('Prefer raw-text replacements for text to avoid problems with HTML entities!'),
-        );
-
-        $form['view']['token_help']['help'] = array(
-          '#value' => theme('token_help', 'node'),
-        );
-        return $form;
+      $result = db_query("SELECT title FROM {blocks} WHERE delta = '".$delta."' ");
+      $object = db_fetch_object($result);
+      if($object->title){
+        $block['title'] = token_replace($object->title,'node',$node);
       }
+      }      
+      $block['subject'] = t($fields[$delta]['widget']['label'] ? $fields[$delta]['widget']['label'] : $delta);
+      $block['content'] = drupal_render($cck_field_data);
+    }
+    }
+  }
+  return $block;
+}
 
-    case 'view':
-      $block = array();
-    
-      if (arg(0) == 'node' && is_numeric(arg(1)) && !arg(2) && $fields[$delta]) {
-        $nid = arg(1);
-        if (!isset($built_nodes[$nid])) {
-          // Build the node in the cck_blocks mode. This is based on node_build_content().
-          $node = node_load($nid);
-          $node->build_mode = 'cck_blocks';
-
-          // Remove the delimiter (if any) that separates the teaser from the body.
-          $node->body = isset($node->body) ? str_replace('<!--break-->', '', $node->body) : '';
-
-          // The 'view' hook can be implemented to overwrite the default function
-          // to display nodes.
-          if (node_hook($node, 'view')) {
-            $node = node_invoke($node, 'view', $teaser, $page);
-          }
-          else {
-            $node = node_prepare($node, $teaser);
-          }
+/**
+ * Implementation of hook_form_alter().
+ *
+ * Adds options to the field configuration page for making the field available as a
+ * block for this specific content type or for every content type that uses it.
+ */
+function cck_blocks_form_alter(&$form, $form_state, $form_id) {
+  switch ($form_id) {
+    case 'content_field_edit_form':
+      // Instance specific settings form
+      $type_name = $form['#field']['type_name'];
+      $field_name = $form['#field']['field_name'];
+      $form['widget']['block_settings'] = array(
+        '#type' => 'fieldset',
+        '#title' => 'CCK Block settings',
+        '#collapsible' => 'TRUE',
+        '#collapsed' => 'TRUE',
+        '#weight' => 12,
+        'instance_block_settings' => array(
+          '#type' => 'radios',
+          '#description' => t('When enabled, this provides a block for this field, on this content type'),
+          '#default_value' => variable_get('cck_blocks_' . $field_name . '_block_availability_' . $type_name, CCK_BLOCKS_FIELD_BLOCK_INHERIT),
+          '#options' => array(
+            CCK_BLOCKS_FIELD_BLOCK_INHERIT => t('Use global field settings'),
+            CCK_BLOCKS_FIELD_BLOCK_DISABLED => t('Disable block'),
+            CCK_BLOCKS_FIELD_BLOCK_ENABLED => t('Enable block'),            
+          ),
+        ),
+      );
+      // Global settings form
+      $form['field']['global_block_settings'] = array(
+        '#type' => 'radios',
+        '#title' => t('Provide block for this field'),
+        '#default_value' => variable_get('cck_blocks_' . $field_name . '_block_availability', CCK_BLOCKS_FIELD_BLOCK_DISABLED),
+        '#description' => t('When enabled, this field becomes available as a block in the block admin page. Overridden by content-type-specific settings'),
+        '#options' => array(
+          CCK_BLOCKS_FIELD_BLOCK_DISABLED => t('Disabled'),
+          CCK_BLOCKS_FIELD_BLOCK_ENABLED => t('Enabled'), 
+        ),
+      );
+      // Add custom form handler to the submit function
+      $form['#submit'][] = 'cck_blocks_field_settings_submit';
+      break;
+  }
+}
 
-          // Allow modules to make their own additions to the node.
-          node_invoke_nodeapi($node, 'view', $teaser, $page);
-          $built_nodes[$nid] = $node;
-        }
-        
-        // look directly for the cck_field in the content array
-        $cck_field_data = false;
-        if (isset($built_nodes[$nid]->content[$delta])) {
-          $cck_field_data = $built_nodes[$nid]->content[$delta];
-        }
-        else {
-          // cycle through all content data arrays looking for cck groups
-          // the cck_field may be within a group
-          foreach ($built_nodes[$nid]->content as $key => $data) {
-            if ((strpos($key, 'group_') == 0) && isset($data['group'][$delta])) {
-              // yay it's a group
-              $cck_field_data = $data['group'][$delta];
-            }
-          }
-        }
+/**  
+ * Cck_blocks custom form submission handler.
+ */
+function cck_blocks_field_settings_submit($form, $form_state) {
+  $type_name = $form['#field']['type_name'];
+  $field_name = $form['#field']['field_name'];
+  // Retrieve user input
+  $instance_value = $form_state ['values']['instance_block_settings'];
+  $global_value = $form_state ['values']['global_block_settings'];
+  // Set persistent variables
+  variable_set('cck_blocks_' . $field_name . '_block_availability_' . $type_name, $instance_value);  
+  variable_set('cck_blocks_' . $field_name . '_block_availability', $global_value);
+}
 
-        if ($cck_field_data) {
-          // evaluate tokens, if token module is installed
-          if (module_exists('token')) {
-            $result = db_query("SELECT title FROM {blocks} WHERE delta = '".$delta."' ");
-            $object = db_fetch_object($result);
-            if($object->title){
-              $block['title'] = token_replace($object->title,'node',$node);
-            }
-          }          
-          $block['subject'] = t($fields[$delta]['widget']['label'] ? $fields[$delta]['widget']['label'] : $delta);
-          $block['content'] = drupal_render($cck_field_data);
-        }
-      }
+// Function to check prefs for listing fields in block admin page (called in case: list)
+function _cck_blocks_check_field_settings($field_info) {
+  // Create array of content types ($types) that use this field
+  module_load_include('inc', 'content', 'includes/content.crud');
+  $instances = content_field_instance_read(array('field_name' => $field_info['field_name']));
+  foreach($instances as $instance) {
+    $types[] = $instance['type_name'];
   }
+  
+  // Check specific then global prefs for this field within this content type
+  foreach ($types as $type) {
+    switch (variable_get('cck_blocks_' . $field_info['field_name'] . '_block_availability_' . $field_info['type_name'], CCK_BLOCKS_FIELD_BLOCK_INHERIT)) {
+      case CCK_BLOCKS_FIELD_BLOCK_INHERIT:
+        if (variable_get('cck_blocks_' . $field_info['field_name'] . '_block_availability', CCK_BLOCKS_FIELD_BLOCK_DISABLED) == CCK_BLOCKS_FIELD_BLOCK_ENABLED) {
+          return TRUE;
+        }
+        break;
+      case CCK_BLOCKS_FIELD_BLOCK_ENABLED:
+        return TRUE;
+      case CCK_BLOCKS_FIELD_BLOCK_DISABLED:
+        break;
+    }
+  };
+  return FALSE;
+}
 
-  return $block;
+// Function to check pref for displaying blocks in page (called in case: veiw)
+function _cck_blocks_display_test($type, $delta) {
+	$prefix = 'cck_blocks_' . $delta . '_block_availability';
+  return (variable_get($prefix . '_' . $type, CCK_BLOCKS_FIELD_BLOCK_INHERIT) == CCK_BLOCKS_FIELD_BLOCK_DISABLED)
+  || ((variable_get($prefix . '_' . $type, CCK_BLOCKS_FIELD_BLOCK_INHERIT) == CCK_BLOCKS_FIELD_BLOCK_INHERIT)
+  && (variable_get($prefix, CCK_BLOCKS_FIELD_BLOCK_DISABLED) == CCK_BLOCKS_FIELD_BLOCK_DISABLED));
 }
\ No newline at end of file
