summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Wittens <steven@10.no-reply.drupal.org>2007-06-21 04:38:41 +0000
committerSteven Wittens <steven@10.no-reply.drupal.org>2007-06-21 04:38:41 +0000
commite7d31327cf885a1f95fa565053478c09f2184f54 (patch)
tree2b1e3fa37f7fe61183ca63b8c79b94cb7267d920
parentaa308028aa570d15d3abf9c7679d7de16019b78b (diff)
downloadbrdo-e7d31327cf885a1f95fa565053478c09f2184f54.tar.gz
brdo-e7d31327cf885a1f95fa565053478c09f2184f54.tar.bz2
#144397: Use drupal_render for user profiles and convert to themer-friendly .tpl.php files.
-rw-r--r--modules/blog/blog.module9
-rw-r--r--modules/profile/profile.module26
-rw-r--r--modules/user/user.css10
-rw-r--r--modules/user/user.module105
-rw-r--r--modules/user/user_profile.tpl.php25
-rw-r--r--modules/user/user_profile_category.tpl.php7
-rw-r--r--modules/user/user_profile_item.tpl.php5
-rw-r--r--themes/garland/style.css25
-rw-r--r--themes/garland/user_profile_category.tpl.php9
9 files changed, 153 insertions, 68 deletions
diff --git a/modules/blog/blog.module b/modules/blog/blog.module
index 639c3db20..5d511b40e 100644
--- a/modules/blog/blog.module
+++ b/modules/blog/blog.module
@@ -48,11 +48,12 @@ function blog_access($op, $node) {
*/
function blog_user($type, &$edit, &$user) {
if ($type == 'view' && user_access('edit own blog', $user)) {
- $items['blog'] = array('title' => t('Blog'),
- 'value' => l(t('View recent blog entries'), "blog/$user->uid", array('title' => t("Read @username's latest blog entries.", array('@username' => $user->name)))),
- 'class' => 'blog',
+ $user->content['summary']['blog'] = array(
+ '#type' => 'user_profile_item',
+ '#title' => t('Blog'),
+ '#value' => l(t('View recent blog entries'), "blog/$user->uid", array('title' => t("Read @username's latest blog entries.", array('@username' => $user->name)))),
+ '#attributes' => array('class' => 'blog'),
);
- return array(t('History') => $items);
}
}
diff --git a/modules/profile/profile.module b/modules/profile/profile.module
index a216d97f4..098ef9ed7 100644
--- a/modules/profile/profile.module
+++ b/modules/profile/profile.module
@@ -575,7 +575,7 @@ function profile_view_field($user, $field) {
&& (user_access('administer users') || $field->visibility != PROFILE_PRIVATE)
&& !empty($field->page);
- if ($value = $user->{$field->name}) {
+ if (isset($user->{$field->name}) && $value = $user->{$field->name}) {
switch ($field->type) {
case 'textarea':
return check_markup($value);
@@ -612,7 +612,7 @@ function profile_view_field($user, $field) {
}
}
-function profile_view_profile($user) {
+function profile_view_profile(&$user) {
profile_load_profile($user);
@@ -628,14 +628,24 @@ function profile_view_profile($user) {
while ($field = db_fetch_object($result)) {
if ($value = profile_view_field($user, $field)) {
$title = ($field->type != 'checkbox') ? check_plain($field->title) : NULL;
- $item = array('title' => $title,
- 'value' => $value,
- 'class' => $field->name,
+
+ // Create a single fieldset for each category.
+ if (!isset($user->content[$field->category])) {
+ $user->content[$field->category] = array(
+ '#type' => 'user_profile_category',
+ '#title' => check_plain($field->category),
+ );
+ }
+
+ $user->content[$field->category][$field->name] = array(
+ '#type' => 'user_profile_item',
+ '#title' => check_plain($title),
+ '#value' => check_markup($value),
+ '#weight' => $field->weight,
+ '#attributes' => array('class' => 'profile-'. $field->name),
);
- $fields[$field->category][$field->name] = $item;
}
}
- return $fields;
}
function _profile_form_explanation($field) {
@@ -666,7 +676,7 @@ function profile_form_profile($edit, $user, $category, $register = FALSE) {
case 'url':
$fields[$category][$field->name] = array('#type' => 'textfield',
'#title' => check_plain($field->title),
- '#default_value' => $edit[$field->name],
+ '#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '',
'#maxlength' => 255,
'#description' => _profile_form_explanation($field),
'#required' => $field->required,
diff --git a/modules/user/user.css b/modules/user/user.css
index 4416afd36..8e08c778a 100644
--- a/modules/user/user.css
+++ b/modules/user/user.css
@@ -44,10 +44,16 @@
float: right; /* LTR */
margin: 0 1em 1em 0; /* LTR */
}
+.profile h3 {
+ border-bottom: 1px solid #ccc;
+}
+.profile dl {
+ margin: 0 0 1.5em 0;
+}
.profile dt {
- margin: 1em 0 0.2em 0;
+ margin: 0 0 0.2em 0;
font-weight: bold;
}
.profile dd {
- margin:0;
+ margin: 0 0 1em 0;
}
diff --git a/modules/user/user.module b/modules/user/user.module
index cea6bd865..c790bee9b 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -33,7 +33,16 @@ function user_theme() {
'arguments' => array('account' => NULL),
),
'user_profile' => array(
- 'arguments' => array('account' => NULL, 'fields' => NULL),
+ 'arguments' => array('account' => NULL),
+ 'file' => 'user_profile',
+ ),
+ 'user_profile_category' => array(
+ 'arguments' => array('element' => NULL),
+ 'file' => 'user_profile_category',
+ ),
+ 'user_profile_item' => array(
+ 'arguments' => array('element' => NULL),
+ 'file' => 'user_profile_item',
),
'user_list' => array(
'arguments' => array('users' => NULL, 'title' => NULL),
@@ -512,14 +521,26 @@ function user_search($op = 'search', $keys = NULL, $skip_access_check = FALSE) {
/**
* Implementation of hook_user().
*/
-function user_user($type, &$edit, &$user, $category = NULL) {
+function user_user($type, &$edit, &$account, $category = NULL) {
if ($type == 'view') {
- $items['history'] = array('title' => t('Member for'),
- 'value' => format_interval(time() - $user->created),
- 'class' => 'member',
+ $account->content['user_picture'] = array(
+ '#value' => theme('user_picture', $account),
+ '#weight' => -10,
+ );
+ if (!isset($account->content['summary'])) {
+ $account->content['summary'] = array();
+ }
+ $account->content['summary'] += array(
+ '#type' => 'user_profile_category',
+ '#attributes' => array('class' => 'user-member'),
+ '#weight' => -5,
+ '#title' => t('History'),
+ );
+ $account->content['summary']['member_for'] = array(
+ '#type' => 'user_profile_item',
+ '#title' => t('Member for'),
+ '#value' => format_interval(time() - $account->created),
);
-
- return array(t('History') => $items);
}
if ($type == 'form' && $category == 'account') {
$form_state = array();
@@ -702,38 +723,6 @@ function theme_user_picture($account) {
}
/**
- * Theme a user page
- * @param $account the user object
- * @param $fields a multidimensional array for the fields, in the form of array (
- * 'category1' => array(item_array1, item_array2), 'category2' => array(item_array3,
- * .. etc.). Item arrays are formatted as array(array('title' => 'item title',
- * 'value' => 'item value', 'class' => 'class-name'), ... etc.). Module names are incorporated
- * into the CSS class.
- *
- * @ingroup themeable
- */
-function theme_user_profile($account, $fields) {
- $output = '<div class="profile">';
- $output .= theme('user_picture', $account);
- foreach ($fields as $category => $items) {
- if (strlen($category) > 0) {
- $output .= '<h2 class="title">'. $category .'</h2>';
- }
- $output .= '<dl>';
- foreach ($items as $item) {
- if (isset($item['title'])) {
- $output .= '<dt class="'. $item['class'] .'">'. $item['title'] .'</dt>';
- }
- $output .= '<dd class="'. $item['class'] .'">'. $item['value'] .'</dd>';
- }
- $output .= '</dl>';
- }
- $output .= '</div>';
-
- return $output;
-}
-
-/**
* Make a list of users.
* @param $items an array with user objects. Should contain at least the name and uid
*
@@ -1671,24 +1660,32 @@ function user_edit_submit($form, &$form_state) {
function user_view($account) {
global $user;
+ // Retrieve all profile fields and store data in content element.
+ $account->content = user_build_content($account);
drupal_set_title(check_plain($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 => $items) {
- foreach ($items as $key => $item) {
- $item['class'] = "$module-". $item['class'];
- $fields[$category][$key] = $item;
- }
- }
- }
- }
+ /**
+ * To theme user profiles, copy modules/user/user_profile.tpl.php
+ * to your theme directory, and edit it as instructed in that file's comments.
+ */
+ return theme('user_profile', $account);
+}
- drupal_alter('profile', $fields, $account);
+/**
+ * Builds a structured array representing the profile content.
+ *
+ * @param $account
+ * A user object.
+ *
+ * @return
+ * A structured array containing the individual elements of the profile.
+ */
+function user_build_content($account) {
+ $edit = NULL;
+ user_module_invoke('view', $edit, $account);
+ // Allow modules to modify the fully-built profile.
+ drupal_alter('profile', $edit, $account);
- drupal_set_title(check_plain($account->name));
- return theme('user_profile', $account, $fields);
+ return $account->content;
}
/*** Administrative features ***********************************************/
diff --git a/modules/user/user_profile.tpl.php b/modules/user/user_profile.tpl.php
new file mode 100644
index 000000000..2acd78a94
--- /dev/null
+++ b/modules/user/user_profile.tpl.php
@@ -0,0 +1,25 @@
+<?php
+
+/*
+ * In order to customize user profiles, replace the HTML below with your own
+ * wrapper and then sprinkle drupal_render($account->content[foo]) calls
+ * where you need each piece of data to appear. Replace the 'foo' in the
+ * example above with the element that is desired such as
+ * drupal_render($account->content['summary']['member_for']).
+ */
+
+// Uncomment the line below to see what data is available in this template.
+# print '<pre>'. check_plain(print_r($account->content, 1)) .'</pre>';
+
+ ?>
+
+<div class="profile">
+
+<?php
+
+// The following line should always be the last PHP in this file. Do not remove.
+print drupal_render($account->content);
+
+?>
+
+</div> \ No newline at end of file
diff --git a/modules/user/user_profile_category.tpl.php b/modules/user/user_profile_category.tpl.php
new file mode 100644
index 000000000..386cb5833
--- /dev/null
+++ b/modules/user/user_profile_category.tpl.php
@@ -0,0 +1,7 @@
+<?php if ($element['#title']): ?>
+ <h3><?php print $element['#title'] ?></h3>
+<?php endif; ?>
+
+<dl<?php (isset($element['#attributes']) ? print drupal_attributes($element['#attributes']) : '') ?>>
+<?php print $element['#children'] ?>
+</dl>
diff --git a/modules/user/user_profile_item.tpl.php b/modules/user/user_profile_item.tpl.php
new file mode 100644
index 000000000..e234380b8
--- /dev/null
+++ b/modules/user/user_profile_item.tpl.php
@@ -0,0 +1,5 @@
+<?php
+ $attributes = isset($element['#attributes']) ? ' '. drupal_attributes($element['#attributes']) : '';
+?>
+<dt<?php print $attributes ?>><?php print $element['#title'] ?></dt>
+<dd<?php print $attributes ?>><?php print $element['#value'] ?></dd>
diff --git a/themes/garland/style.css b/themes/garland/style.css
index 3ce468cc4..e8b200236 100644
--- a/themes/garland/style.css
+++ b/themes/garland/style.css
@@ -868,6 +868,31 @@ html.js fieldset.collapsed legend a {
}
/**
+ * User profiles.
+ */
+.profile {
+ margin-top: 1.5em;
+}
+.profile h3 {
+ border-bottom: 0;
+ margin-bottom: 1em;
+}
+.profile dl {
+ margin: 0;
+}
+.profile dt {
+ font-weight: normal;
+ color: #898989;
+ font-size: 0.92em;
+ line-height: 1.3em;
+ margin-top: 1.4em;
+ margin-bottom: 0.45em;
+}
+.profile dd {
+ margin-bottom: 1.6em;
+}
+
+/**
* Admin Styles
*/
div.admin-panel,
diff --git a/themes/garland/user_profile_category.tpl.php b/themes/garland/user_profile_category.tpl.php
new file mode 100644
index 000000000..f2325fa99
--- /dev/null
+++ b/themes/garland/user_profile_category.tpl.php
@@ -0,0 +1,9 @@
+<div class="profile-category">
+ <?php if ($element['#title']): ?>
+ <h3><?php print $element['#title'] ?></h3>
+ <?php endif; ?>
+
+ <dl<?php (isset($element['#attributes']) ? print drupal_attributes($element['#attributes']) : '') ?>>
+ <?php print $element['#children'] ?>
+ </dl>
+</div>