Index: cck_blocks.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck_blocks/cck_blocks.module,v
retrieving revision 1.2.2.13
diff -u -p -r1.2.2.13 cck_blocks.module
--- cck_blocks.module	19 Mar 2010 08:37:50 -0000	1.2.2.13
+++ cck_blocks.module	28 May 2010 11:24:18 -0000
@@ -83,55 +83,80 @@ function cck_blocks_block($op = 'list', 
      * to the user and the requested field is available in the fields array
      */
     if (isset($node->nid) && $display_nodecontent && $fields[$delta]) {
-      $nid = $node->nid;
+      $block = cck_blocks_get_block($node, $delta, $fields[$delta]);
+    }
+  }
 
-      // build the node in cck_blocks mode if that hasn't been done yet
-      if (!isset($built_nodes[$nid])) {
-        $node->build_mode = 'cck_blocks';
-        $built_nodes[$nid] = node_build_content($node, FALSE, TRUE);
-      }
+  // return the generated block. Might be an empty array, if the block is not to be displayed.
+  return $block;
+}
 
-      // 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 in a user-defined title, if token module is installed
-        if (module_exists('token')) {
-          $title = db_result(db_query("SELECT title FROM {blocks} WHERE delta = '%s'", $delta));
-          if ($title){
-            $block['title'] = token_replace($title,'node',$built_nodes[$nid]);
-          }
-        }
-
-        /* Use the label of the field as the block's title. Only visible,
-         * if the user did not enter a custom title for the block as $block->subject
-         *  is replaced by $block->title (if set) in block_list().
-         */
-        $block['subject'] = t($fields[$delta]['widget']['label']);
+/**
+ * Wrapper function to allow external modules (or themes) to manually get the block content without being dependant on the URL
+ */
+function cck_blocks_get_block($node, $delta, $field = NULL) {
+  // The $field is optional so any external modules can lazily call this function by passing a node and field name.
+  if (!isset($field)) {
+    // Get fields
+    $fields = module_invoke('content', 'fields');
+
+    // If the field is set, use it otherwise return FALSE
+    if ($fields[$delta]) {
+      $field = $fields[$delta];
+    }
+    else {
+      return FALSE;
+    }
+  }
+  $nid = $node->nid;
+
+  // build the node in cck_blocks mode if that hasn't been done yet
+  if (!isset($built_nodes[$nid])) {
+    $node->build_mode = 'cck_blocks';
+    $built_nodes[$nid] = node_build_content($node, FALSE, TRUE);
+  }
 
-        // Set the field's data as the content of the block
-        $block['content'] = drupal_render($cck_field_data);
+  // 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];
       }
     }
   }
 
-  // return the generated block. Might be an empty array, if the block is not to be displayed.
-  return $block;
+  if ($cck_field_data) {
+    // Evaluate tokens in a user-defined title, if token module is installed
+    if (module_exists('token')) {
+      $title = db_result(db_query("SELECT title FROM {blocks} WHERE delta = '%s'", $delta));
+      if ($title){
+        $block['title'] = token_replace($title,'node',$built_nodes[$nid]);
+      }
+    }
+
+    /* Use the label of the field as the block's title. Only visible,
+     * if the user did not enter a custom title for the block as $block->subject
+     *  is replaced by $block->title (if set) in block_list().
+     */
+    $block['subject'] = t($fields[$delta]['widget']['label']);
+
+    // Set the field's data as the content of the block
+    $block['content'] = drupal_render($cck_field_data);
+
+    return $block;
+  }
+  return FALSE;
 }
 
+
 /**
  * Implementation of hook_form_alter().
  *
@@ -175,4 +200,4 @@ function cck_blocks_field_settings_submi
   $field_name = $form['#field']['field_name'];
   $global_value = $form_state['values']['global_cck_blocks_settings'];
   variable_set('cck_blocks_' . $field_name . '_block_availability', $global_value);
-}
\ No newline at end of file
+}
