Index: nodeprofile.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodeprofile/nodeprofile.module,v
retrieving revision 1.6
diff -u -p -r1.6 nodeprofile.module
--- nodeprofile.module	9 Aug 2006 08:18:22 -0000	1.6
+++ nodeprofile.module	15 Jan 2007 14:59:13 -0000
@@ -99,3 +99,108 @@ function nodeprofile_node_settings_submi
     }
   }
 }
+
+/**
+ * @ingroup hook_block implementation
+ * implementation of hook_block
+ * @todo for nodefamily blocks: make sure we only load lonely nodes
+ */
+function nodeprofile_block($op = 'list', $delta = 0, $edit = array()){
+  // The $op parameter determines what piece of information is being requested.
+  switch ($op) {
+    case 'list':
+      if (module_exist('nodefamily')) { // nodefamily specific blocks
+        foreach (nodefamily_get_parent_types() as $type) {
+          $blocks[$type .'.my']['info'] = t('My nodefamily for %type', array('%type' => node_get_name($type)));
+          $blocks[$type .'.create']['info'] = t('Create new %type pages', array('%type' => node_get_name($type)));
+        }
+      }
+      return $blocks;
+    case 'view':
+      if (module_exist('nodefamily')) { // nodefamily specific blocks
+        list($node_type, $block_type) = explode('.', $delta);
+        if ($block_type == 'my') {
+          $block['subject'] = t('My %type', array('%type' => node_get_name($node_type)));
+          $block['content'] = nodeprofile_my_block_contents($node_type);
+          return $block;
+        }
+        elseif ($block_type == 'create') {
+          $block['subject'] = t('Create %type', array('%type' => node_get_name($node_type)));
+          $block['content'] = nodeprofile_create_block_contents($node_type);
+          return $block;
+        }
+      }
+  }
+}
+
+/**
+ * @ingroup hook_block implementation
+ * Generate the content for the block
+ */
+function nodeprofile_my_block_contents($type) {
+  global $user;
+  $output = '';
+
+  $node = node_load(array('type' => $type, 'uid' => $user->uid));
+  if ($children = nodefamily_relation_load($node)) {
+    foreach ($children as $profile) {
+      $items[] = theme('nodeprofile_block_item', $profile);
+    }
+  }
+
+  if (count($items)) {
+    $output = theme('item_list', $items);
+  }
+  return $output;
+}
+
+/**
+ * @ingroup hook_block implementation
+ * Generate the content for the block
+ */
+function nodeprofile_create_block_contents($type) {
+  global $user;
+  $output = '';
+  foreach (nodefamily_get_child_types($type) as $option) {
+    if (!nodefamily_content_type_is_max($option, $user->uid)) {
+      $profile = new stdClass();
+      $profile->type = $option;
+      $profile->title = node_get_name($option);
+      $items[] = theme('nodeprofile_block_item', $profile, array('create'));
+    }
+  }
+
+  if (count($items)) {
+    $output = theme('item_list', $items);
+  }
+  return $output;
+}
+
+/**
+ * @ingroup themeable
+ * Generate an 'action'-link, like 'edit' or 'create'
+ */
+function theme_nodeprofile_block_item($profile, $actions = array('edit', 'delete')) {
+  $output = '';
+
+  if ($profile->nid) {
+    $output .= l($profile->title, 'node/'. $profile->nid);
+  }
+  else {
+    $output .= $profile->title;
+  }
+
+  if (in_array('edit', $actions)) {
+    $output .= ' ['. l(t('edit'), 'node/'. $profile->nid .'/edit') .']';
+  }
+
+  if (in_array('create', $actions)) {
+    $output .= ' ['. l(t('create'), 'node/add/'. $profile->type) .']';
+  }
+
+  if (in_array('delete', $actions)) {
+    $output .= ' ['. l(t('delete'), 'node/'. $profile->nid .'/delete') .']';
+  }
+
+  return $output;
+}
\ No newline at end of file
