Index: profiletabs.info
===================================================================
RCS file: /cvs/drupal/contributions/modules/profiletabs/profiletabs.info,v
retrieving revision 1.1
diff -u -r1.1 profiletabs.info
--- profiletabs.info	4 Aug 2007 09:20:23 -0000	1.1
+++ profiletabs.info	28 Mar 2009 11:57:42 -0000
@@ -1,3 +1,10 @@
 ; $Id: profiletabs.info,v 1.1 2007/08/04 09:20:23 maartenvg Exp $
 name = Profile Tabs
-description = Shows profile categories as tabs when viewing user profiles
\ No newline at end of file
+description = Shows profile categories as tabs when viewing user profiles
+; Information added by drupal.org packaging script on 2008-04-08
+version = "6.x-1.0-dev"
+project = "profiletabs"
+datestamp = "1207667418"
+
+
+core = 6.x
Index: profiletabs.install
===================================================================
RCS file: /cvs/drupal/contributions/modules/profiletabs/profiletabs.install,v
retrieving revision 1.2
diff -u -r1.2 profiletabs.install
--- profiletabs.install	8 Apr 2008 14:49:21 -0000	1.2
+++ profiletabs.install	28 Mar 2009 11:57:48 -0000
@@ -2,9 +2,14 @@
 // $Id: profiletabs.install,v 1.2 2008/04/08 14:49:21 maartenvg Exp $
 
 /**
+ * @file Profile tabs install file.
+ */ 
+
+/**
  * Implementation of hook_uninstall();
  */
 function profiletabs_uninstall() {
+  //remove variables
   variable_del('profiletabs_default');
   variable_del('profiletabs_hidden');
 }
Index: profiletabs.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/profiletabs/profiletabs.module,v
retrieving revision 1.3
diff -u -r1.3 profiletabs.module
--- profiletabs.module	14 Apr 2008 07:20:21 -0000	1.3
+++ profiletabs.module	28 Mar 2009 11:37:10 -0000
@@ -1,68 +1,92 @@
 <?php
-// $Id: profiletabs.module,v 1.3 2008/04/14 07:20:21 maartenvg Exp $
+// $Id: profiletabs.module,v 1.2 2008/04/08 14:49:21 maartenvg Exp $
+
+/**
+ * @file Profile tabs module file.
+ */ 
 
 /**
  * Implementation of hook_menu().
  */
-function profiletabs_menu($may_cache) {
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/settings/profiletabs',
-      'title' => t('Profile Tabs'),
-      'description' => t('Administer the profile tabs. Which are shown and which is the default.'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('profiletabs_admin_settings'),
-      'access' => user_access('administer site configuration'),
-    );
-  }
-  else {
-    // Are we at a profile? Continue
-    if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) > 0) {
-      // Load profile owner
-      $account = user_load(array('uid' => arg(1)));
-    
-      $categories = module_invoke_all('user', 'view', '', $account);
-      $default = variable_get('profiletabs_default', t('History'));
-      $hidden = variable_get('profiletabs_hidden', array());
-
-      // If the current default tab isn't visible (e.g. when you select a tab that
-      // is only visible for admins) default to the History-tab.
-      if (!isset($categories[$default])) {
-        $default = t('History');
-      }
-
-      if ($account !== FALSE) {
-        // Make tabs for all non-hidden categories
-        foreach ($categories as $key => $category) {
-          if (empty($hidden[$key]) && !empty($category)) {
-            $items[] = array(
-              'path' => 'user/'. arg(1) .'/view/'. $key,
-              'title' => $key,
-              'type' => $key == $default ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
-            );
-          }
-        }
+function profiletabs_menu() {
+  global $user;
+  $items = array();
+  
+  // Profile tabs admin settings.
+  $items['admin/settings/profiletabs'] = array(
+      'title' => 'Profile Tabs',
+      'description' => 'Administer the profile tabs. Which are shown and which is the default.',
+      'page callback' => 'drupal_get_form',
+      'page arguments' => array('profiletabs_admin_settings'),
+      'access arguments' => array('administer site configuration')
+  );
+  
+  // Get profile categories
+  $content = _profiletabs_get_categories($user);
+  
+  // Get default tab
+  $default = variable_get('profiletabs_default', t('History'));
+  // Get hidden tabs
+  $hidden = variable_get('profiletabs_hidden', array());
+  
+  // Default tab
+  $items['user/%user/view/'. $default] = array(
+    'title' => $default,
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+    //'access callback' => TRUE,  //TODO access ok ?
+    'weight' => 2,
+  );
+  
+  // Other tabs  
+  foreach ($content AS $key => $field) {
+    $title = $field['#title']; 
+    if ($default != $title && $title != NULL) {
+      if (empty($hidden[$title])) {
+        $items['user/%user/view/'. $title] = array(
+          'title' => $title,
+          'type' => MENU_LOCAL_TASK,
+          'page callback' => 'user_view',
+          'page arguments' => array(1),
+          'access callback' => TRUE,
+          'file' => 'user.pages.inc',
+          'file path' => drupal_get_path('module', 'user'),
+          //'tab_parent' => 'user/%/view',
+          'weight' => 3,
+        );
       }
     }
   }
+  
   return $items;
 }
 
 /**
+ * Get profile categories
+ */ 
+function _profiletabs_get_categories(&$account) {
+  $edit = NULL;
+  user_module_invoke('view', $edit, $account);
+  return $account->content;
+}
+  
+
+/**
  * Generate settings form.
  */
 function profiletabs_admin_settings() {
   global $user;
-  $form = array();
-
+  
   // Get categories
-  $categories = module_invoke_all('user', 'view', '', $user);
+  $categories = _profiletabs_get_categories($user);
+  // Create options
   foreach ($categories as $key => $category) {
-    if (!empty($category)) {
-      $options[$key] = $key;
+    $title = $category['#title'];
+    if ($title != NULL) {
+      $options[$title] = $title;
     }
   }
-
+    
+  //Create form for default tab
   $form['profiletabs_default'] = array(
     '#type' => 'select',
     '#title' => t('Default category'),
@@ -71,6 +95,7 @@
     '#options' => $options,
   );
   
+  //Form for hidden tabs
   $form['profiletabs_hidden'] = array(
     '#type' => 'checkboxes',
     '#title' => t('Hidden tabs'),
@@ -78,14 +103,24 @@
     '#description' => t('Choose which categories should not have a tab on its own, but should be shown on the default tab.'),
     '#options' => $options,
   );
-  return system_settings_form($form);
+  
+  $form = system_settings_form($form);
+  $form['#submit'][] = 'profiletabs_admin_settings_submit';
+  return $form;
+}
+
+/**
+* Rebuild profile tabs on submit
+*/
+function profiletabs_admin_settings_submit($form, $form_state) {
+  menu_rebuild();
 }
 
 
 /**
  *  Implementation of hook_profile_alter().
  */
-function profiletabs_profile_alter(&$account, &$fields) {
+function profiletabs_profile_alter(&$account) {  
   // Which tab are we trying to see?
   $goal = arg(3);
   
@@ -96,7 +131,7 @@
 
   // If the current default tab isn't visible (e.g. when you select a tab that
   // is only visible for admins) default to the History-tab.
-  if (!isset($fields[$default])) {
+  if (!isset($account->content[$default])) {
     $default = t('History');
   }
 
@@ -111,9 +146,10 @@
   
   // Remove all fields that are not to be shown on this tab, i.e. fields that are not
   // the current field and tabs that are hidden and it isn't the default tab.
-  foreach ($fields as $key => $field) {
-    if ($key!=$goal && !(!empty($hidden[$key]) && $default_check)) {
-      unset($fields[$key]);
+  foreach ($account->content AS $key => $field) {
+    $title = $field['#title']; 
+    if ($title != $goal) {
+      unset($account->content[$key]);
     }
   }
 }

