- 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.
4.5.x
Dries Buytaert 2004-03-21 14:28:15 +00:00
parent f43cd3bb33
commit 754f2ac26a
12 changed files with 80 additions and 32 deletions

View File

@ -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))))));
}
}

View File

@ -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))))));
}
}

View File

@ -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()));

View File

@ -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()));

View File

@ -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) {

View File

@ -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) {

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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();

View File

@ -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();