Only in bio.new: bio.info
diff -up bio/bio.module bio.new/bio.module
--- bio/bio.module	2006-01-23 19:54:11.000000000 -0500
+++ bio.new/bio.module	2007-01-23 17:40:37.000000000 -0500
@@ -19,14 +19,27 @@ function bio_help($section) {
   }
 }
 
+function bio_node_info() {
+  return array(
+    'bio' => array(
+      'name' => t('Bio page'),
+      'module' => 'bio',
+      'description' => t("A biography for a user. A user is only allowed to create one bio."),
+    )
+  );
+}
+
+
 // hook_menu
 function bio_menu($may_cache) {
   $items = array();
-  $bid = bio_for_user();
+  $bid = bio_foruser();
   $access = user_access('create biography');
   if ($may_cache) {
-    $items[] = array('path' => 'node/add/bio', 'title' => (($bid && !user_access('administer nodes')) ? t('edit bio') : t('add bio')),
-      'access' => $access);
+    $items[] = array('path' => 'node/add/bio', 
+      'title' => (($bid && !user_access('administer nodes')) ? t('edit bio') : t('add bio')),
+      'access' => $access
+    );
   }
   if ($_GET['q'] == 'node/add/bio' && $bid && !user_access('administer nodes')){
     drupal_goto('node/'.$bid.'/edit');
@@ -39,7 +52,7 @@ function bio_access($op, $node) {
   global $user;
   if ($op == 'create') {
     // if they can create bios and they don't already have one
-    $access = (user_access('create biography') && !bio_for_user($user->uid));
+    $access = (user_access('create biography') && !bio_foruser($user->uid));
     return $access;
   }
 
@@ -55,15 +68,7 @@ function bio_perm() {
   return array('create biography');
 }
 
-// hook_node_name() - 4.6
-function bio_node_name($node) {
-  return t('biography');
-}
 
-// hook_node_info() - 4.7
-function bio_node_info() {
-  return array('bio' => array('name' => t('biography'), 'base' => 'bio'));
-}
 
 function bio_form_alter($form_id, &$form){
   if (isset($form['type'])) { 
@@ -71,22 +76,38 @@ function bio_form_alter($form_id, &$form
       $form['links'] = array('#type' => 'fieldset', '#title' => t('Links'));
       $form['links']['bio_'. $form['type']['#value']] = array('#type' => 'radios', '#title' => t('Display bio link'), '#default_value' => variable_get('bio_'. $form['type']['#value'], 1), '#options' => array(t('Disabled'), t('Enabled')), '#description' => t('Display a link to author\'s bio if it is available.')); 
     }
-  }
+  } 
 }
 
-function bio_form(&$node) { 
-  $form['title'] = array('#type' => 'textfield', '#title' => t('Title'), 
-    '#size' => 60, '#maxlength' => 128, '#required' => TRUE, 
-    '#default_value' => $node->title); 
-  $form['body'] = array('#type' => 'textarea', '#title' => t('Body'), 
-    '#default_value' => $node->body, '#rows' => 20, '#required' => FALSE ); 
-  return array_merge($form, filter_form($node->format)); 
+/*
+ * Implementation of hook form
+ * returns a form for creating or editing a bio
+ */
+function bio_form($node) { 
+  $form['title'] = array(
+    '#type' => 'textfield', 
+    '#title' => t('Title'), 
+    '#size' => 60, '#maxlength' => 128, 
+    '#required' => TRUE, 
+    '#default_value' => $node->title
+  ); 
+  $form['body'] = array(
+    '#type' => 'textarea', 
+    '#title' => t('Body'), 
+    '#default_value' => $node->body, 
+    '#rows' => 20, 
+    '#required' => FALSE 
+  ); 
+  $form['body_filter']['format'] = filter_form($node->format);
+  return $form;
 }
 
+
+
 function bio_validate(&$node) {
   if ($node) { 
     // if this user already has a bio node and this isn't it
-    $nid = bio_for_user($node->uid);
+    $nid = bio_foruser($node->uid);
     if ($nid && $nid != $node->nid) {
       form_set_error('name', t('This user already has a biography. Edit it <a href="%link">here</a> or assign this entry to another user.', array("%link" => url('node/'.$nid.'/edit'))));
     } 
@@ -100,7 +121,7 @@ function bio_validate(&$node) {
 function bio_link($type, $node = NULL, $teaser = FALSE) { 
   $links = array(); 
   if ($type == 'node' && $node->type != 'bio') {
-    if (variable_get('bio_'.$node->type, 1) && ($nid = bio_for_user($node->uid))){
+    if (variable_get('bio_'.$node->type, 1) && ($nid = bio_foruser($node->uid))){
         $user = user_load(array('uid' => $node->uid));
         $links[] = t('by ') . l($user->name, "node/$nid", 
         array('title' => t('View %user\'s biography.', array('%user' => $user->name))));
@@ -110,7 +131,11 @@ function bio_link($type, $node = NULL, $
   return $links; 
 } 
 
-function bio_for_user($uid = NULL){
+/**
+ * selects the bio data
+ * 
+ */
+function bio_foruser($uid = NULL, $full = false){
   if (is_null($uid)){
     global $user;
     $uid = $user->uid;
@@ -118,4 +143,63 @@ function bio_for_user($uid = NULL){
   return db_result(db_query('SELECT nid FROM {node} WHERE uid = %d AND type = "bio"', $uid));
 }
 
-?>
\ No newline at end of file
+
+
+/**
+ * Implementation of hook_user
+ * Adds the bio data to the user object
+ * Adds the bio to the user page
+ * Adds an edit link on the user/edit screen
+ * 
+ */
+ function bio_user($op, &$edit, &$account, $category = NULL){
+   switch($op){
+     case 'load':
+       $bioid = bio_foruser($account->uid, true);
+       if($bioid) { 
+         $the_bio = node_load($bioid);
+         $account->bio = $the_bio;        
+         $account->bio->comments .= comment_render($the_bio );
+         global $user;
+         if ($user->uid == $account->uid){
+           $the_bio->edit = l("Edit your bio", "node/" . $the_bio->nid . "/edit");
+         }
+         else {
+           $account->bio->comment_write = l("Leave a comment for " . $account->name , "comment/reply/" . $the_bio->nid); 
+         }  
+       }
+       else {
+         if  (user_access("create biography", $account)){
+           $account->bio->body = l("Create your biography", "node/add/bio");
+         } 
+       }  
+     break;
+     
+     case 'categories':
+       return array(array('name' => 'bio', 'title' => 'Biography', 'weight' => 0));
+     break;
+     
+     case 'form':
+       // this should really present the user with 
+       // the form that allows them to edit their page
+       if ($category == 'bio') {
+         $bioid = bio_foruser($account->uid, true);
+         if($bioid){ 
+           $form = bio_form(node_load($bioid));
+           drupal_goto("node/$bioid/edit", "destination=user");
+         }
+         else {
+           drupal_goto("node/add/bio", "destination=user");
+         }
+       }
+     break;
+     
+     case 'view':
+       $items[] = array(
+        'title' => $account->bio->title,
+        'value' => $account->bio->body,
+      );
+       return array(t("Biography") => $items);
+     break;
+   }
+ }
\ No newline at end of file
Only in bio.new: CVS
Only in bio: LICENSE.txt
Only in bio.new: .svn
