Index: insert_block.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/insert_block/insert_block.info,v
retrieving revision 1.1
diff -u -p -r1.1 insert_block.info
--- insert_block.info	7 Jun 2007 18:25:50 -0000	1.1
+++ insert_block.info	22 Oct 2008 23:52:49 -0000
@@ -1,3 +1,5 @@
-; $Id: insert_block.info,v 1.1 2007/06/07 18:25:50 mlsamuelson Exp $
+; $Id$
 name = Insert Block
-description = "Inserts the contents of a block into into a node using [block:module=delta] tags"
\ No newline at end of file
+description = "Inserts the contents of a block into into a node using [block:module=delta] tags"
+version = "6.x-1.x-dev"
+core = 6.x
Index: insert_block.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/insert_block/insert_block.module,v
retrieving revision 1.5
diff -u -p -r1.5 insert_block.module
--- insert_block.module	27 Jun 2007 14:51:37 -0000	1.5
+++ insert_block.module	22 Oct 2008 23:52:50 -0000
@@ -1,16 +1,40 @@
 <?php
-// $Id: insert_block.module,v 1.5 2007/06/27 14:51:37 mlsamuelson Exp $
+// $Id$
 
-function insert_block_filter_tips($delta, $format, $long = false) {
+/**
+ * @file
+ * Insert blocks into the body of a node
+ *
+ * Sidebar blocks contain all sorts of nifty stuff, but sometimes you
+ * want to stick that stuff into the body of your node. Instead of using
+ * PHP snippets (a possible security hole on public sites), you can use
+ * this module. When it's activated...
+ *
+ * [block:name of module=delta of block]
+ *
+ * ...will insert the contents of a rendered sidebar block into the body
+ * of your node. If no delta is specified, the default block for that
+ * module will be displayed.
+ */
+
+/**
+ * Implementation of hook_filter_tips().
+ */
+function insert_block_filter_tips($delta, $format, $long = FALSE) {
   if ($long) {
-     return t('You may use <a href="@insert_block_help">[block:<em>module</em>=<em>delta</em>] tags</a> to display the contents of block <em>delta</em> for module <em>module</em>.', array("@insert_block_help" => url("filter/tips/$format", NULL, 'filter-insert_block')));
+    return t('You may use <a href="@insert_block_help">[block:<em>module</em>=<em>delta</em>] tags</a> to display the contents of block <em>delta</em> for module <em>module</em>.',
+    array("@insert_block_help" => url("filter/tips/$format", array('fragment' => 'filter-insert_block'))));
   }
   else {
-     return t('You may use <a href="@insert_block_help">[block:<em>module</em>=<em>delta</em>] tags</a> to display the contents of block <em>delta</em> for module <em>module</em>.', array("@insert_block_help" => url("filter/tips/$format", NULL, 'filter-insert_block')));
+    return t('You may use <a href="@insert_block_help">[block:<em>module</em>=<em>delta</em>] tags</a> to display the contents of block <em>delta</em> for module <em>module</em>.',
+    array("@insert_block_help" => url("filter/tips/$format", array('fragment' => 'filter-insert_block'))));
   }
 }
 
-function insert_block_help($section = 'admin/help#insert_block') {
+/**
+ * Implementation of hook_help().
+ */
+function insert_block_help($section = 'admin/help#insert_block', $args = array()) {
   $output = '';
   switch ($section) {
     case 'admin/help#insert_block':
@@ -18,6 +42,9 @@ function insert_block_help($section = 'a
   }
 }
 
+/**
+ * Implementation of hook_filter().
+ */
 function insert_block_filter($op, $delta = 0, $format = -1, $text = '') {
   // The "list" operation provides the module an opportunity to declare both how
   // many filters it defines and a human-readable name for each filter. Note that
@@ -27,45 +54,65 @@ function insert_block_filter($op, $delta
       0 => t('insert block filter'));
   }
 
-  // All operations besides "list" provide a $delta argument so we know which
-  // filter they refer to. We'll switch on that argument now so that we can
-  // discuss each filter in turn.
-  switch ($op) {
-    case 'description':
-       return t('Inserts the contents of a block into a node using [block:module=delta] tags.');
-    case 'prepare':
-       return $text;
-    case 'process':
-       return $text;
+  // go ahead and set this up for multiple filters, though I doubt we'll use it
+  switch ($delta) {
+    case 0:
+      switch ($op) {
+        case 'description':
+          return t('Inserts the contents of a block into a node using [block:module=delta] tags.');
+        case 'prepare':
+          return $text;
+        case 'process':
+          return _insert_block_substitute_tags($text);
+        }
+      break;
   }
 }
 
-function insert_block_nodeapi(&$node, $op, $arg) {
-  if ($op == 'alter') {
-    $node->body = _insert_block_substitute_tags($node, 'body');
-    $node->teaser = _insert_block_substitute_tags($node, 'teaser');
-  }
-  if ($op == 'print') {
-    $node->content['body']['#value'] = _insert_block_substitute_tags($node, 'body');
+
+function _insert_block_substitute_tags($text) {
+  if (preg_match_all("/\[block:([^=\\]]+)=?([^\\]]*)?\]/i", $text, $match)) {
+    foreach ($match[2] as $key => $value) {
+      $raw_tags[] = $match[0][$key];
+      $module = $match[1][$key];
+      $delta = $match[2][$key];
+
+      $block = module_invoke($module, 'block', 'view', $delta);
+
+      $repl[] = theme('insert_block_block', $block);
+    }
+    return str_replace($raw_tags, $repl, $text);
   }
+  return $text;
 }
 
-function _insert_block_substitute_tags(&$node, $field) {
-    if (preg_match_all("/\[block:([^=\\]]+)=?([^\\]]*)?\]/i", $node->$field, $match)) {
-       foreach ($match[2] as $key => $value) {
-         $module = $match[1][$key];
-         $delta = $match[2][$key];
-
-         $block = module_invoke($module, 'block', 'view', $delta);
-         
-         $mtch[] = $match[0][$key];
-         $repl[] = theme('insert_block_block', $block);
-       }
-       return str_replace($mtch, $repl, $node->$field);
-    }
-    return $node->$field;
+/**
+ * Implementation of hook_theme().
+ */
+function insert_block_theme() {
+  $themes = array(
+    'insert_block_block' => array(
+      'arguments' => array('block'),
+    ),
+  );
+  return $themes;
 }
 
+/**
+ * Format an included block.
+ *
+ * Gets passed the block array to be formatted. By default it includes
+ * the block subject, if any, and the block's content.
+ *
+ * @ingroup themeable
+ */
 function theme_insert_block_block($block) {
-  return $block['content'];
+  $content = '';
+  if (!empty($block['subject'])) {
+    $content .= '<h2>'. $block['subject'] .'</h2>';
+  }
+  if (!empty($block['content'])) {
+    $content .= $block['content'];
+  }
+  return $content;
 }
\ No newline at end of file

