Commit 99276849 authored by Dries's avatar Dries

- Patch #162134 by dvessel: tplify profile module.

parent fe7faf76
<?php
// $Id
/**
* @file profile-block.tpl.php
* Default theme implementation for displaying a users profile within a
* block. It only shows in relation to a node displayed as a full page.
*
* Available variables:
* - $picture: Image configured for the account linking to the users page.
* - $profile: Keyed array of all profile fields that have a value.
*
* Each $field in $profile contains:
* - $field->title: Title of the profile field.
* - $field->value: Value of the profile field.
* - $field->type: Type of the profile field, i.e., checkbox, textfield,
* textarea, selection, list, url or date.
*
* Since $profile is keyed, a direct print of the field is possible. Not
* all accounts may have a value for a profile so do a check first. If a field
* of "last_name" was set for the site, the following can be used.
*
* <?php if (isset($profile['last_name'])): ?>
* <div class="field last-name">
* <?php print $profile['last_name']->title; ?>:<br />
* <?php print $profile['last_name']->value; ?>
* </div>
* <?php endif; ?>
*
* @see template_preprocess_profile_block()
*/
?>
<?php print $picture; ?>
<?php foreach ($profile as $field) : ?>
<p>
<?php if ($field->type != 'checkbox') : ?>
<strong><?php print $field->title; ?></strong><br />
<?php endif; ?>
<?php print $field->value; ?>
</p>
<?php endforeach; ?>
<?php
// $Id
/**
* @file profile-listing.tpl.php
* Default theme implementation for displaying a user and their profile data
* for member listing pages.
*
* @see profile-wrapper.tpl.php
* where all the data is collected and printed out.
*
* Available variables:
* - $picture: Image configured for the account linking to the users page.
* - $name: User's account name linking to the users page.
* - $profile: Keyed array of all profile fields that are set as visible
* in member list pages (configured by site administrators). It also needs
* to have a value in order to be present.
*
* Each $field in $profile contains:
* - $field->title: Title of the profile field.
* - $field->value: Value of the profile field.
* - $field->type: Type of the profile field, i.e., checkbox, textfield,
* textarea, selection, list, url or date.
*
* Since $profile is keyed, a direct print of the field is possible. Not
* all accounts may have a value for a profile so do a check first. If a field
* of "last_name" was set for the site, the following can be used.
*
* <?php if (isset($profile['last_name'])): ?>
* <div class="field last-name">
* <?php print $profile['last_name']->title; ?>:<br />
* <?php print $profile['last_name']->value; ?>
* </div>
* <?php endif; ?>
*
* @see template_preprocess_profile_listing()
*/
?>
<div class="profile">
<?php print $picture; ?>
<div class="name">
<?php print $name; ?>
</div>
<?php foreach ($profile as $field) : ?>
<div class="field">
<?php print $field->value; ?>
</div>
<?php endforeach; ?>
</div>
<?php
// $Id
/**
* @file profile-wrapper.tpl.php
* Default theme implementation for wrapping member listings and their
* profiles.
*
* This template is used when viewing a list of users. It can be a general
* list for viewing all users with the url of "example.com/profile" or when
* viewing a set of users who share a specific value for a profile such
* as "example.com/profile/country/belgium".
*
* Available variables:
* - $content: User account profiles iterated through profile-listing.tpl.php.
* - $current_field: The named field being browsed. Provided here for context.
* The above example would result in "last_name". An alternate template name
* is also based on this, e.g., "profile-wrapper-last_name.tpl.php".
*
* @see template_preprocess_profile_wrapper()
*/
?>
<div id="profile">
<?php print $content; ?>
</div>
......@@ -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) = array_pad(explode('/', $_GET['q'], 3), 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,70 @@ 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) {
foreach ($fields as $field) {
$variables['picture'] = theme('user_picture', $variables['account']);
$variables['profile'] = array();
// Supply filtered version of $fields that have values.
foreach ($variables['fields'] as $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'][$field->name]->title = $field->title;
$variables['profile'][$field->name]->value = $field->value;
$variables['profile'][$field->name]->type = $field->type;
}
}
return $output;
}
function theme_profile_listing($account, $fields = array()) {
$output = "<div class=\"profile\">\n";
$output .= theme('user_picture', $account);
$output .= ' <div class="name">'. theme('username', $account) ."</div>\n";
/**
* 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) {
foreach ($fields as $field) {
$variables['picture'] = theme('user_picture', $variables['account']);
$variables['name'] = theme('username', $variables['account']);
$variables['profile'] = array();
// Supply filtered version of $fields that have values.
foreach ($variables['fields'] as $field) {
if ($field->value) {
$output .= " <div class=\"field\">$field->value</div>\n";
$variables['profile'][$field->name]->title = $field->title;
$variables['profile'][$field->name]->value = $field->value;
$variables['profile'][$field->name]->type = $field->type;
}
}
$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) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment