From 754f2ac26a2dbe81fcaa2886d4a8f5030b8e6cda Mon Sep 17 00:00:00 2001 From: Dries Buytaert <dries@buytaert.net> Date: Sun, 21 Mar 2004 14:28:15 +0000 Subject: [PATCH] - More profile module improvements: + Updated the _user() hook's "$type == 'view'" case to match the "$type == 'edit'" case. That is, both have to return an associtive array of the format array('category' => 'fields'). + Updated the profile pages to group fields by category. Made possible thanks to the above change. + Moved logic out of the theme_ functions. --- modules/blog.module | 2 +- modules/blog/blog.module | 2 +- modules/comment.module | 5 ----- modules/comment/comment.module | 5 ----- modules/profile.module | 6 +++--- modules/profile/profile.module | 6 +++--- modules/system.module | 3 +++ modules/system/system.module | 3 +++ modules/tracker.module | 3 ++- modules/tracker/tracker.module | 3 ++- modules/user.module | 37 ++++++++++++++++++++++++++++------ modules/user/user.module | 37 ++++++++++++++++++++++++++++------ 12 files changed, 80 insertions(+), 32 deletions(-) diff --git a/modules/blog.module b/modules/blog.module index 9b18115d4b58..bd1c00fe7253 100644 --- a/modules/blog.module +++ b/modules/blog.module @@ -38,7 +38,7 @@ function blog_access($op, $node) { function blog_user($type, &$edit, &$user) { if ($type == 'view' && user_access("maintain personal blog", $user)) { - return form_item(t("Blog"), l(t("view recent blog entries"), "blog/$user->uid", array("title" => t("Read %username's latest blog entries.", array("%username" => $user->name))))); + return array(t('History') => form_item(t("Blog"), l(t("view recent blog entries"), "blog/$user->uid", array("title" => t("Read %username's latest blog entries.", array("%username" => $user->name)))))); } } diff --git a/modules/blog/blog.module b/modules/blog/blog.module index 9b18115d4b58..bd1c00fe7253 100644 --- a/modules/blog/blog.module +++ b/modules/blog/blog.module @@ -38,7 +38,7 @@ function blog_access($op, $node) { function blog_user($type, &$edit, &$user) { if ($type == 'view' && user_access("maintain personal blog", $user)) { - return form_item(t("Blog"), l(t("view recent blog entries"), "blog/$user->uid", array("title" => t("Read %username's latest blog entries.", array("%username" => $user->name))))); + return array(t('History') => form_item(t("Blog"), l(t("view recent blog entries"), "blog/$user->uid", array("title" => t("Read %username's latest blog entries.", array("%username" => $user->name)))))); } } diff --git a/modules/comment.module b/modules/comment.module index b7676eaaf051..03f6144bd7ec 100644 --- a/modules/comment.module +++ b/modules/comment.module @@ -138,11 +138,6 @@ function comment_settings() { function comment_user($type, $edit, &$user) { switch ($type) { - case "view": - if ($user->signature) { - return form_item(t("Signature"), check_output($user->signature)); - } - break; case "edit": // when user tries to edit his own data return array(t('Personal information') => form_textarea(t("Signature"), "signature", $user->signature, 64, 3, t("Your signature will be publicly displayed at the end of your comments.") ."<br />". filter_tips_short())); diff --git a/modules/comment/comment.module b/modules/comment/comment.module index b7676eaaf051..03f6144bd7ec 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -138,11 +138,6 @@ function comment_settings() { function comment_user($type, $edit, &$user) { switch ($type) { - case "view": - if ($user->signature) { - return form_item(t("Signature"), check_output($user->signature)); - } - break; case "edit": // when user tries to edit his own data return array(t('Personal information') => form_textarea(t("Signature"), "signature", $user->signature, 64, 3, t("Your signature will be publicly displayed at the end of your comments.") ."<br />". filter_tips_short())); diff --git a/modules/profile.module b/modules/profile.module index 4efc5b65653a..7dae358955b9 100644 --- a/modules/profile.module +++ b/modules/profile.module @@ -129,15 +129,15 @@ function profile_view_profile($user) { while ($field = db_fetch_object($result)) { if ($value = profile_view_field($user, $field)) { if ($field->type == 'checkbox') { - $output .= "<p>$value</p>"; + $fields[$field->category] .= "<p>$value</p>"; } else { - $output .= form_item($field->title, check_output($value)); + $fields[$field->category] .= form_item($field->title, check_output($value)); } } } - return $output; + return $fields; } function profile_edit_profile($edit, $user) { diff --git a/modules/profile/profile.module b/modules/profile/profile.module index 4efc5b65653a..7dae358955b9 100644 --- a/modules/profile/profile.module +++ b/modules/profile/profile.module @@ -129,15 +129,15 @@ function profile_view_profile($user) { while ($field = db_fetch_object($result)) { if ($value = profile_view_field($user, $field)) { if ($field->type == 'checkbox') { - $output .= "<p>$value</p>"; + $fields[$field->category] .= "<p>$value</p>"; } else { - $output .= form_item($field->title, check_output($value)); + $fields[$field->category] .= form_item($field->title, check_output($value)); } } } - return $output; + return $fields; } function profile_edit_profile($edit, $user) { diff --git a/modules/system.module b/modules/system.module index ae588c7ddf09..1c5e7b95f20d 100644 --- a/modules/system.module +++ b/modules/system.module @@ -95,6 +95,9 @@ function system_user($type, $edit, &$user) { $data[t('Locale settings')] = form_select(t("Time zone"), "timezone", $edit["timezone"], $zones, t("Select what time you currently have and your time zone settings will be set appropriate.")); return $data; } + else if ($type == 'view') { + // do nothing + } else { return $edit; } diff --git a/modules/system/system.module b/modules/system/system.module index ae588c7ddf09..1c5e7b95f20d 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -95,6 +95,9 @@ function system_user($type, $edit, &$user) { $data[t('Locale settings')] = form_select(t("Time zone"), "timezone", $edit["timezone"], $zones, t("Select what time you currently have and your time zone settings will be set appropriate.")); return $data; } + else if ($type == 'view') { + // do nothing + } else { return $edit; } diff --git a/modules/tracker.module b/modules/tracker.module index fbf587ff60ab..a700f13dc67d 100644 --- a/modules/tracker.module +++ b/modules/tracker.module @@ -76,7 +76,8 @@ function tracker_page() { function tracker_user($type, &$edit, &$user) { if ($type == 'view' && user_access("access content")) { - return form_item(t("Recent posts"), l(t("recent posts"), "tracker/$user->uid")); + return array(t('History') => form_item(t("Recent posts"), l(t("recent posts"), "tracker/$user->uid"))); + return $fields; } } diff --git a/modules/tracker/tracker.module b/modules/tracker/tracker.module index fbf587ff60ab..a700f13dc67d 100644 --- a/modules/tracker/tracker.module +++ b/modules/tracker/tracker.module @@ -76,7 +76,8 @@ function tracker_page() { function tracker_user($type, &$edit, &$user) { if ($type == 'view' && user_access("access content")) { - return form_item(t("Recent posts"), l(t("recent posts"), "tracker/$user->uid")); + return array(t('History') => form_item(t("Recent posts"), l(t("recent posts"), "tracker/$user->uid"))); + return $fields; } } diff --git a/modules/user.module b/modules/user.module index 9fd0a971fe48..7d2b3338027f 100644 --- a/modules/user.module +++ b/modules/user.module @@ -333,6 +333,12 @@ function user_search($keys) { return array(t("Matching users"), $find); } +function user_user($type, &$edit, &$user) { + if ($type == 'view') { + return array(t('History') => form_item(t('Member for'), format_interval(time() - $account->created))); + } +} + function user_block($op = "list", $delta = 0) { global $user; @@ -478,12 +484,12 @@ function theme_user_picture($account) { } } -function theme_user_profile($account) { +function theme_user_profile($account, $fields) { $output = "<div class=\"profile\">\n"; $output .= theme('user_picture', $account); - $output .= form_item(t('Name'), $account->name); - $output .= implode("\n", module_invoke_all('user', 'view', '', $account)); - $output .= form_item(t('Member for'), format_interval(time() - $account->created)); + foreach ($fields as $category => $value) { + $output .= "<h2>$category</h2>$value"; + } if (user_access("administer users")) { $output .= form_item(t("Administration"), l(t("edit account"), "admin/user/edit/$account->uid")); @@ -1077,7 +1083,16 @@ function user_view($uid = 0) { if ($uid == 0) { if ($user->uid) { - print theme('page', theme('user_profile', $user), $user->name); + // Retrieve and merge all profile fields: + $fields = array(); + foreach (module_list() as $module) { + if ($data = module_invoke($module, 'user', 'view', '', $user)) { + foreach ($data as $category => $content) { + $fields[$category] .= $content; + } + } + } + print theme('page', theme('user_profile', $user, $fields), $user->name); } else { $output = user_login(); @@ -1091,7 +1106,17 @@ function user_view($uid = 0) { } else { if ($account = user_load(array('uid' => $uid, "status" => 1))) { - print theme('page', theme('user_profile', $account), $account->name); + // Retrieve and merge all profile fields: + $fields = array(); + foreach (module_list() as $module) { + if ($data = module_invoke($module, 'user', 'view', '', $account)) { + foreach ($data as $category => $content) { + $fields[$category] .= $content; + } + } + } + + print theme('page', theme('user_profile', $account, $fields), $account->name); } else { drupal_not_found(); diff --git a/modules/user/user.module b/modules/user/user.module index 9fd0a971fe48..7d2b3338027f 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -333,6 +333,12 @@ function user_search($keys) { return array(t("Matching users"), $find); } +function user_user($type, &$edit, &$user) { + if ($type == 'view') { + return array(t('History') => form_item(t('Member for'), format_interval(time() - $account->created))); + } +} + function user_block($op = "list", $delta = 0) { global $user; @@ -478,12 +484,12 @@ function theme_user_picture($account) { } } -function theme_user_profile($account) { +function theme_user_profile($account, $fields) { $output = "<div class=\"profile\">\n"; $output .= theme('user_picture', $account); - $output .= form_item(t('Name'), $account->name); - $output .= implode("\n", module_invoke_all('user', 'view', '', $account)); - $output .= form_item(t('Member for'), format_interval(time() - $account->created)); + foreach ($fields as $category => $value) { + $output .= "<h2>$category</h2>$value"; + } if (user_access("administer users")) { $output .= form_item(t("Administration"), l(t("edit account"), "admin/user/edit/$account->uid")); @@ -1077,7 +1083,16 @@ function user_view($uid = 0) { if ($uid == 0) { if ($user->uid) { - print theme('page', theme('user_profile', $user), $user->name); + // Retrieve and merge all profile fields: + $fields = array(); + foreach (module_list() as $module) { + if ($data = module_invoke($module, 'user', 'view', '', $user)) { + foreach ($data as $category => $content) { + $fields[$category] .= $content; + } + } + } + print theme('page', theme('user_profile', $user, $fields), $user->name); } else { $output = user_login(); @@ -1091,7 +1106,17 @@ function user_view($uid = 0) { } else { if ($account = user_load(array('uid' => $uid, "status" => 1))) { - print theme('page', theme('user_profile', $account), $account->name); + // Retrieve and merge all profile fields: + $fields = array(); + foreach (module_list() as $module) { + if ($data = module_invoke($module, 'user', 'view', '', $account)) { + foreach ($data as $category => $content) { + $fields[$category] .= $content; + } + } + } + + print theme('page', theme('user_profile', $account, $fields), $account->name); } else { drupal_not_found(); -- GitLab