Index: modules/profile/profile-block.tpl.php
===================================================================
RCS file: modules/profile/profile-block.tpl.php
diff -N modules/profile/profile-block.tpl.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/profile/profile-block.tpl.php	25 Jul 2007 23:17:28 -0000
@@ -0,0 +1,38 @@
+<?php
+// $Id
+/**
+ * @file profile-block.tpl.php
+ * Default theme implementation for displaying the users profile within a
+ * block. It only shows in relation to the current viewing node rendered in as
+ * a full page.
+ *
+ * Available variables:
+ * - $picture: Image of the account rendered through theme_user_profile().
+ * - $profile: Array of profile fields that contain data.
+ * - $account: Array of raw account information.
+ *
+ * Each $item in $profile contains:
+ * - $item->title: Title of the profile item.
+ * - $item->value: Value of the profile item.
+ * - $item->type: Type of teh profile item. i.e. checkbox, textfield,
+ *   textarea, selection, list, url, date.
+ *
+ * Other variables include the name of each item. For example, if there is a
+ * profile field named "profile_full_name" configured for the site, you can
+ * access the item directly by printing $profile_full_name->title or
+ * $profile_full_name->value. It contains the same data as each $item from the
+ * $profile array.
+ *
+ * @see template_preprocess_profile_block()
+ */
+?>
+<?php print $picture; ?>
+
+<?php foreach ($profile as $item) : ?>
+  <p>
+    <?php if ($item->type != 'checkbox') : ?>
+      <strong><?php print $item->title; ?></strong><br />
+    <?php endif; ?>
+    <?php print $item->value; ?>
+  </p>
+<?php endforeach; ?>
Index: modules/profile/profile-listing.tpl.php
===================================================================
RCS file: modules/profile/profile-listing.tpl.php
diff -N modules/profile/profile-listing.tpl.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/profile/profile-listing.tpl.php	25 Jul 2007 23:17:28 -0000
@@ -0,0 +1,44 @@
+<?php
+// $Id
+/**
+ * @file profile-listing.tpl.php
+ * Default theme implementation for browsing lists of users and their profile
+ * data. @see profile-wrapper.tpl.php for its' wrapper markup and options.
+ *
+ * Available variables:
+ * - $picture: User image of the account being viewed. Rendered through
+ *   theme_user_profile().
+ * - $name: User name of the account being viewed. Rendered through
+ *   theme_username().
+ * - $profile: Array of profile fields that contain data.
+ * - $account: Array of raw account information.
+ *
+ * Each $item in $profile contains:
+ * - $item->title: Title of the profile item.
+ * - $item->value: Value of the profile item.
+ * - $item->type: Type of teh profile item. i.e. checkbox, textfield,
+ *   textarea, selection, list, url, date.
+ *
+ * Other variables include the name of each item. For example, if there is a
+ * profile field named "profile_full_name" configured for the site, you can
+ * access the item directly by printing $profile_full_name->title or
+ * $profile_full_name->value. It contains the same data as each $item from the
+ * $profile array.
+ *
+ * @see template_preprocess_profile_listing()
+ */
+?>
+<div class="profile">
+  <?php print $picture; ?>
+
+  <div class="name">
+    <?php print $name; ?>
+  </div>
+
+  <?php foreach ($profile as $item) : ?>
+    <div class="field">
+      <?php print $item->value; ?>
+    </div>
+  <?php endforeach; ?>
+
+</div>
Index: modules/profile/profile-wrapper.tpl.php
===================================================================
RCS file: modules/profile/profile-wrapper.tpl.php
diff -N modules/profile/profile-wrapper.tpl.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/profile/profile-wrapper.tpl.php	25 Jul 2007 23:17:28 -0000
@@ -0,0 +1,20 @@
+<?php
+// $Id
+/**
+ * @file profile_wrapper.tpl.php
+ * Default theme implementation for wrapping profile listings.
+ *
+ * Available variables:
+ * - $content: User account profiles rendered through profile-listing.tpl.php
+ * - $current_field: The named field being browsed. For example:
+ *   "example.com/profile/profile_name/joe" would result in $current_field
+ *   being equal to "profile_name". An alternate template name is also based
+ *   on this. "profile-wrapper-profile_name.tpl.php" would be used when
+ *   viewing the example address and the template existed for the theme.
+ *
+ * @see template_preprocess_profile_wrapper()
+ */
+?>
+<div id="profile">
+  <?php print $content; ?>
+</div>
Index: modules/profile/profile.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/profile/profile.module,v
retrieving revision 1.213
diff -u -p -r1.213 profile.module
--- modules/profile/profile.module	5 Jul 2007 08:38:58 -0000	1.213
+++ modules/profile/profile.module	25 Jul 2007 23:17:28 -0000
@@ -58,10 +58,17 @@ function profile_theme() {
   return array(
     'profile_block' => array(
       'arguments' => array('account' => NULL, 'fields' => array()),
+      'file' => 'profile-block',
     ),
     'profile_listing' => array(
       'arguments' => array('account' => NULL, 'fields' => array()),
-    ),  );
+      'file' => 'profile-listing',
+    ),
+    'profile_wrapper' => array(
+      'arguments' => array('content' => NULL),
+      'file' => 'profile-wrapper',
+    )
+  );
 }
 
 /**
@@ -451,8 +458,8 @@ function profile_admin_overview() {
  * Menu callback; display a list of user information.
  */
 function profile_browse() {
-  $name = arg(1);
-  list(, , $value) = explode('/', $_GET['q'], 3);
+  // Ensure that the path is converted to 3 levels always.
+  list(, $name, $value) = array_pad(explode('/', $_GET['q'], 3), 3, '');
 
   $field = db_fetch_object(db_query("SELECT DISTINCT(fid), type, title, page, visibility FROM {profile_fields} WHERE name = '%s'", $name));
 
@@ -498,12 +505,13 @@ function profile_browse() {
     // Extract the affected users:
     $result = pager_query("SELECT u.uid, u.access FROM {users} u INNER JOIN {profile_values} v ON u.uid = v.uid WHERE v.fid = %d AND $query AND u.access != 0 AND u.status != 0 ORDER BY u.access DESC", 20, 0, NULL, $arguments);
 
-    $output = '<div id="profile">';
+    $content = '';
     while ($account = db_fetch_object($result)) {
       $account = user_load(array('uid' => $account->uid));
       $profile = _profile_update_user_fields($fields, $account);
-      $output .= theme('profile_listing', $account, $profile);
+      $content .= theme('profile_listing', $account, $profile);
     }
+    $output = theme('profile_wrapper', $content);
     $output .= theme('pager', NULL, 20);
 
     if ($field->type == 'selection' || $field->type == 'list' || $field->type == 'textfield') {
@@ -512,7 +520,6 @@ function profile_browse() {
     else {
       $title = check_plain($field->page);
     }
-    $output .= '</div>';
 
     drupal_set_title($title);
     return $output;
@@ -531,13 +538,13 @@ function profile_browse() {
     // Extract the affected users:
     $result = pager_query('SELECT uid, access FROM {users} WHERE uid > 0 AND status != 0 AND access != 0 ORDER BY access DESC', 20, 0, NULL);
 
-    $output = '<div id="profile">';
+    $content = '';
     while ($account = db_fetch_object($result)) {
       $account = user_load(array('uid' => $account->uid));
       $profile = _profile_update_user_fields($fields, $account);
-      $output .= theme('profile_listing', $account, $profile);
+      $content .= theme('profile_listing', $account, $profile);
     }
-    $output .= '</div>';
+    $output = theme('profile_wrapper', $content);
     $output .= theme('pager', NULL, 20);
 
     drupal_set_title(t('User list'));
@@ -790,39 +797,74 @@ function profile_categories() {
   return $data;
 }
 
-function theme_profile_block($account, $fields = array()) {
-
-  $output .= theme('user_picture', $account);
+/**
+ * Process variables for profile-block.tpl.php.
+ *
+ * The $variables array contains the following arguments:
+ * - $account
+ * - $fields
+ *
+ * @see profile-block.tpl.php
+ */
+function template_preprocess_profile_block(&$variables) {
+  
+  $variables['picture'] = theme('user_picture', $variables['account']);
 
-  foreach ($fields as $field) {
+  // Supply filtered version of $fields that have values.
+  foreach ($variables['fields'] as $i => $field) {
     if ($field->value) {
-      if ($field->type == 'checkbox') {
-        $output .= "<p>$field->value</p>\n";
-      }
-      else {
-        $output .= "<p><strong>$field->title</strong><br />$field->value</p>\n";
-      }
+      $variables['profile'][$i]->title = $field->title;
+      $variables['profile'][$i]->value = $field->value;
+      $variables['profile'][$i]->type = $field->type;
+      // Supply named variables for easier access. Make sure it's using an underscore.
+      $variables[str_replace('-', '_', $field->name)] = $variables['fields'][$i];
     }
   }
-
-  return $output;
+  
 }
 
-function theme_profile_listing($account, $fields = array()) {
+/**
+ * Process variables for profile-listing.tpl.php.
+ *
+ * The $variables array contains the following arguments:
+ * - $account
+ * - $fields
+ *
+ * @see profile-listing.tpl.php
+ */
+function template_preprocess_profile_listing(&$variables) {
 
-  $output  = "<div class=\"profile\">\n";
-  $output .= theme('user_picture', $account);
-  $output .= ' <div class="name">'. theme('username', $account) ."</div>\n";
+  $variables['picture'] = theme('user_picture', $variables['account']);
+  $variables['name'] = theme('username', $variables['account']);
 
-  foreach ($fields as $field) {
+  // Supply filtered version of $fields that have values.
+  foreach ($variables['fields'] as $i => $field) {
     if ($field->value) {
-      $output .= " <div class=\"field\">$field->value</div>\n";
+      $variables['profile'][$i]->title = $field->title;
+      $variables['profile'][$i]->value = $field->value;
+      $variables['profile'][$i]->type = $field->type;
+      // Supply named variables for easier access. Make sure it's using an underscore.
+      $variables[str_replace('-', '_', $field->name)] = $variables['fields'][$i];
     }
   }
 
-  $output .= "</div>\n";
+}
 
-  return $output;
+/**
+ * Process variables for profile-wrapper.tpl.php.
+ *
+ * The $variables array contains the following arguments:
+ * - $content
+ *
+ * @see profile-wrapper.tpl.php
+ */
+function template_preprocess_profile_wrapper(&$variables) {
+  $variables['current_field'] = '';
+  if ($field = arg(1)) {
+    $variables['current_field'] = $field;
+    // Supply an alternate template suggestion based on the browsable field. 
+    $variables['template_files'][] = 'profile-wrapper-'. $field;
+  }
 }
 
 function _profile_field_types($type = NULL) {
