--- relatedcontent.module.bak	2007-05-17 23:50:02.000000000 +0200
+++ relatedcontent.module	2007-05-18 02:58:01.000000000 +0200
@@ -31,6 +31,28 @@
  * Themeable function for displaying the body and the nodes.  
  */
 function theme_relatedcontent($body, $nodes) {
+  if ('0'==variable_get('relatedcontent_display_settings', 0)){
+    if ($nodes) {
+      foreach ($nodes as $node) {
+        $groups[$node->type][] = $node;
+      }
+      foreach ($groups as $type => $group) {
+        $body .= "<div class=\"relatedcontent-nodes $type\">\n";
+        $body .= "<h3>$type</h3>\n";
+        foreach ($group as $node) {
+          $body .= node_view($node, true);
+        }
+        $body .= "</div>\n";
+      }
+    }
+  }
+  return $body;
+}
+
+/**
+ * Themeable function for displaying the nodes in a block.
+ */
+function theme_relatedcontent_asblock ($nodes) {
   if ($nodes) {
     foreach ($nodes as $node) {
       $groups[$node->type][] = $node;
@@ -41,7 +63,7 @@ function theme_relatedcontent($body, $no
       foreach ($group as $node) {
         $body .= node_view($node, true);
       }
-      $body .= "</div>\n";
+     $body .= "</div>\n";
     }
   }
   return $body;
@@ -85,10 +107,22 @@ function theme_relatedcontent_form_alter
  * Implementation of hook_menu().
  */
 function relatedcontent_menu($may_cache) {
-  if (!$may_cache) {
+  $items = array();
+  $access = user_access('administer related content');
+
+  if ($may_cache) {
+    $items[] = array('path' => 'admin/settings/relatedcontent',
+      'title' => t('Related Content'),
+      'description' => t('Configure if related content is added to the node or provides a block.'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => 'relatedcontent_settings',
+      'access' => $access);
+  }
+  else {
     $base = drupal_get_path('module', 'relatedcontent'); 
     drupal_add_css($base .'/relatedcontent.css');
   }
+  return $items;
 }
 
 /**
@@ -126,6 +160,77 @@ function relatedcontent_help($section='a
   }
 }
 
+/**
+ * Implementation of hook_block().
+ */
+function relatedcontent_block($op = 'list', $delta = 0, $edit = array()) {
+  switch ($op) {
+    case 'list':
+      $blocks=array();	
+      if ('1'==variable_get('relatedcontent_display_settings', 0)){
+        $blocks[0]['info'] = t('Related content');
+      }
+      return $blocks;
+    case 'configure':
+      return;
+    case 'save':
+      return;
+    case 'view': default:
+      switch ($delta) {
+        case 0:
+          if ('1'==variable_get('relatedcontent_display_settings', 0)){
+	    $block['subject'] = t('Related content');
+            $block['content'] = _relatedcontent_get_block_content();
+          }
+          break;
+      }
+      return $block;
+  }
+}
+
+/**
+ * Add RelatedContent to the block.
+ */
+function _relatedcontent_get_block_content() {
+  if ( arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2) ) {
+    $node = node_load(arg(1));
+    if (!$teaser) {
+      foreach ($node->nodes as $nid) {
+        $nodes[] = node_load($nid);
+      }
+    return theme(relatedcontent_asblock, $nodes);
+    }
+  }
+}
+
+/**
+ * Implementation of hook_perm().
+ */
+function relatedcontent_perm() {
+  return array('administer related content');
+}
+
+/**
+ * Admin settings form 
+ */
+function relatedcontent_settings() {
+  $form = array();
+  $form['relatedcontent_config'] = array(
+    '#type' => 'fieldset',
+    '#title' => 'Related Content Block Settings',
+  );
+  $form['relatedcontent_config']['relatedcontent_display_settings'] = array(
+   '#type' => 'radios',
+   '#title' => t('Custom visibility settings'),
+   '#options' => array(
+     t('The related content is shown under the node.'),
+     t('The related content is shown in a block.'),
+   ),
+   '#description' =>  t('Allow users to customize the visibility of the related content.'),
+   '#default_value' => variable_get('relatedcontent_display_settings', 0),
+  );
+  return system_settings_form($form);
+}
 
 /******************************************************************************
  * ALTER NODE TYPE FORM
@@ -183,7 +288,7 @@ function _relatedcontent_form_alter_node
 }
 
 /**
- * Returns the aviable views provided by the Views module.
+ * Returns the available views provided by the Views module.
  */
 function _relatedcontent_available_views()
 {
