Index: modules/profile.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/profile.module,v
retrieving revision 1.132
diff -u -F^f -r1.132 profile.module
--- modules/profile.module	30 Jan 2006 18:32:24 -0000	1.132
+++ modules/profile.module	16 Feb 2006 01:36:42 -0000
@@ -137,29 +137,37 @@ function profile_menu($may_cache) {
 }
 
 /**
- * Menu callback; display a list of user information.
+ * Returns a list of user which fulfil the required attributes.
+ *
+ * @param $name name of the profile field
+ * @param $value the value of the list, checkbox or selection you are looking at
  */
-function profile_browse() {
-
-  $name = arg(1);
-  list(,,$value) = explode('/', $_GET['q'], 3);
-
+function profile_list_profiles($name = NULL, $value = NULL) {
   $field = db_fetch_object(db_query("SELECT DISTINCT(fid), type, title, page, visibility FROM {profile_fields} WHERE name = '%s'", $name));
 
-  if ($name && $field->fid) {
-    // Do not allow browsing of private fields by non-admins
-    if (!user_access('administer users') && $field->visibility == PROFILE_PRIVATE) {
-       drupal_access_denied();
-       return;
-    }
+  if($name && !$field->fid) {
+    drupal_not_found();
+    return;
+  }
+  // Do not allow browsing of private fields by non-admins
+  if ($name && !user_access('administer users') && $field->visibility == PROFILE_PRIVATE) {
+    drupal_access_denied();
+    return;
+  }
 
-    // Compile a list of fields to show
-    $fields = array();
-    $result = db_query('SELECT name, title, type, weight FROM {profile_fields} WHERE fid != %d AND visibility = %d ORDER BY weight', $field->fid, PROFILE_PUBLIC_LISTINGS);
-    while ($record = db_fetch_object($result)) {
-      $fields[] = $record;
-    }
+  // Compile a list of fields to show
+  $arguments = array(PROFILE_PUBLIC_LISTINGS);
+  $fields = array();
+  if ($name) {
+    $query = ' AND fid != %d';
+    $arguments[] = $field->fid;
+  }
+  $result = db_query('SELECT name, title, type, weight FROM {profile_fields} WHERE visibility = %d'. $query .' ORDER BY weight', $arguments);
+  while ($record = db_fetch_object($result)) {
+    $fields[] = $record;
+  }
 
+  if ($name) {
     // Determine what query to use:
     $arguments = array($field->fid);
     switch ($field->type) {
@@ -178,55 +186,71 @@ function profile_browse() {
         drupal_not_found();
         return;
     }
-
     // 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 ORDER BY u.access DESC", 20, 0, NULL, $arguments);
+  }
+  else {
+    // Extract the affected users:
+    $result = pager_query("SELECT uid, access FROM {users} WHERE uid > 0 AND status != 0 ORDER BY access DESC", 20, 0, NULL);
+  }
+  $accounts = array();
+  while ($record = db_fetch_object($result)) {
+    $accounts[] = $record;
+  }
 
-    $output = '<div id="profile">';
-    while ($account = db_fetch_object($result)) {
-      $account = user_load(array('uid' => $account->uid));
-      $fields = _profile_update_user_fields($fields, $account);
-      $output .= theme('profile_listing', $account, $fields);
-    }
-    $output .= theme('pager', NULL, 20);
-
+  if ($name) {
     if ($field->type == 'selection' || $field->type == 'list') {
       $title = strtr($field->page, array('%value' => theme('placeholder', $value)));
     }
     else {
       $title = $field->page;
     }
-    $output .= '</div>';
-
-    drupal_set_title($title);
-    return $output;
-  }
-  else if ($name && !$field->id) {
-    drupal_not_found();
   }
   else {
-    // Compile a list of fields to show
-    $fields = array();
-    $result = db_query('SELECT name, title, type, weight FROM {profile_fields} WHERE visibility = %d ORDER BY category, weight', PROFILE_PUBLIC_LISTINGS);
-    while ($record = db_fetch_object($result)) {
-      $fields[] = $record;
-    }
+    $title = t('user list');
+  }
 
-    // Extract the affected users:
-    $result = pager_query("SELECT uid, access FROM {users} WHERE uid > 0 AND status != 0 ORDER BY access DESC", 20, 0, NULL);
+  drupal_set_title($title);
 
-    $output = '<div id="profile">';
-    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);
-    }
-    $output .= '</div>';
-    $output .= theme('pager', NULL, 20);
+  return theme('profile_list_profiles', $accounts, $fields);
+}
 
-    drupal_set_title(t('user list'));
-    return $output;
+/**
+ * Returns a themed profile list.
+ *
+ * @param $accounts An array with user objects
+ * @param $fields fields which should be shown
+ *
+ * @ingroup themeable
+ */
+function theme_profile_list_profiles($accounts, $fields) {
+  if (!is_array($accounts)) {
+    if (!is_object($accounts)) {
+      return;
+    }
+    else {
+      $accounts = array($accounts);
+    }
   }
+  $output = '<div id="profile">';
+  foreach ($accounts as $account) {
+    $account = user_load(array('uid' => $account->uid));
+    $profile = _profile_update_user_fields($fields, $account);
+    $output .= theme('profile_listing', $account, $profile);
+  }
+  $output .= theme('pager', NULL, 20);
+  $output .= '</div>';
+  return $output;
+}
+
+/**
+ * Menu callback; display a list of user information.
+ */
+function profile_browse() {
+  $name = arg(1);
+  list(,,$value) = explode('/', $_GET['q'], 3);
+
+  return profile_list_profiles($name, $value);
 }
 
 function profile_load_profile(&$user) {
@@ -300,7 +324,6 @@ function profile_view_field($user, $fiel
 }
 
 function profile_view_profile($user) {
-
   profile_load_profile($user);
 
   // Show private fields to administrators and people viewing their own account.
@@ -646,7 +669,6 @@ function _profile_field_form($type, $edi
  * Menu callback; display a listing of all editable profile fields.
  */
 function profile_admin_overview() {
-
   $result = db_query('SELECT * FROM {profile_fields} ORDER BY category, weight');
   $rows = array();
   while ($field = db_fetch_object($result)) {
@@ -658,43 +680,51 @@ function profile_admin_overview() {
 
   $header = array(t('Title'), t('Name'), t('Type'), t('Category'), array('data' => t('Operations'), 'colspan' => '2'));
 
-  $output  = theme('table', $header, $rows);
-  $output .= '<h2>'. t('Add new field') .'</h2>';
-  $output .= '<ul>';
+  $items = array();
   foreach (_profile_field_types() as $key => $value) {
-    $output .= '<li>'. l($value, "admin/settings/profile/add/$key") .'</li>';
+    $items[] = l($value, "admin/settings/profile/add/$key");
   }
-  $output .= '</ul>';
+
+  $output  = theme('table', $header, $rows);
+  $output .= theme('item_list', $items, t('Add new field'));
 
   return $output;
 }
 
+/**
+ * Themes the profile block
+ *
+ * @ingroup themeable
+ */
 function theme_profile_block($account, $fields = array()) {
-
-  $output .= theme('user_picture', $account);
+  $output = theme('user_picture', $account);
 
   foreach ($fields as $field) {
     if ($field->value) {
-      $output .= "<p><strong>$field->title:</strong><br />$field->value</p>\n";
+      $output .= '<p><strong>'. $field->title .':</strong><br />'. $field->value .'</p>';
     }
   }
 
   return $output;
 }
 
+/**
+ * Themes the user listing in the profile view
+ *
+ * @ingroup themeable
+ */
 function theme_profile_listing($account, $fields = array()) {
-
-  $output  = "<div class=\"profile\">\n";
+  $output  = '<div class="profile">';
   $output .= theme('user_picture', $account);
-  $output .= ' <div class="name">'. theme('username', $account) ."</div>\n";
+  $output .= '<div class="name">'. theme('username', $account) .'</div>';
 
   foreach ($fields as $field) {
     if ($field->value) {
-      $output .= " <div class=\"field\">$field->value</div>\n";
+      $output .= '<div class="field profile-field-'. $field->name .'">'. $field->value .'</div>';
     }
   }
 
-  $output .= "</div>\n";
+  $output .= '</div>';
 
   return $output;
 }
@@ -712,4 +742,4 @@ function _profile_field_types($type = NU
 
 function _profile_field_serialize($type = NULL) {
   return $type == 'date';
-}
+}
\ No newline at end of file
